1import * as Effect from "effect/Effect";
2import type { Note } from "./Note.ts";
3import type { Occurrence } from "./Occurrence.ts";
4import { bindGcpHost } from "../Host.ts";
5import { grantFor, type BindingIam, type GcpHttpOp } from "../HttpBinding.ts";
6
7/**
8 * Shared HTTP scaffolding for Container Analysis get bindings.
9 * NOT exported from index.ts.
10 */
11export const makeNoteHttpBinding = <
12 I extends { name?: string },
13 A,
14 E,
15>(options: {
16 tag: string;
17 iam: BindingIam;
18 operation: GcpHttpOp<I, A, E>;
19}) =>
20 Effect.gen(function* () {
21 const run = yield* options.operation;
22 return Effect.fn(function* (note: Note) {
23 yield* bindGcpHost({
24 tag: options.tag,
25 resource: note,
26 iam: [grantFor(options.iam, note.name)],
27 });
28 const name = yield* note.name;
29 return Effect.fn(`${options.tag}(${note.LogicalId})`)(function* (
30 request?: Omit<I, "name">,
31 ) {
32 return yield* run({
33 ...(request as I),
34 name: yield* name,
35 } as I);
36 });
37 });
38 });
39
40export const makeOccurrenceHttpBinding = <
41 I extends { name?: string },
42 A,
43 E,
44>(options: {
45 tag: string;
46 iam: BindingIam;
47 operation: GcpHttpOp<I, A, E>;
48}) =>
49 Effect.gen(function* () {
50 const run = yield* options.operation;
51 return Effect.fn(function* (occurrence: Occurrence) {
52 yield* bindGcpHost({
53 tag: options.tag,
54 resource: occurrence,
55 iam: [grantFor(options.iam, occurrence.name)],
56 });
57 const name = yield* occurrence.name;
58 return Effect.fn(`${options.tag}(${occurrence.LogicalId})`)(function* (
59 request?: Omit<I, "name">,
60 ) {
61 return yield* run({
62 ...(request as I),
63 name: yield* name,
64 } as I);
65 });
66 });
67 });