| 1 | import * as Effect from "effect/Effect"; |
| 2 | import { bindGcpHost } from "../Host.ts"; |
| 3 | import { type BindingIam, type GcpHttpOp } from "../HttpBinding.ts"; |
| 4 | import type { Output } from "../../Output.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Shared HTTP scaffolding for Oracle Database@Google Cloud bindings. |
| 8 | * NOT exported from index.ts. |
| 9 | */ |
| 10 | export const makeOracleNameHttpBinding = < |
| 11 | Resource extends { |
| 12 | readonly name: Output<string, never>; |
| 13 | readonly LogicalId: string; |
| 14 | }, |
| 15 | I extends { name?: string }, |
| 16 | A, |
| 17 | E, |
| 18 | >(options: { |
| 19 | tag: string; |
| 20 | /** Oracle Database@Google Cloud has no resource-level IAM: project grant. */ |
| 21 | iam: Pick<BindingIam, "role">; |
| 22 | operation: GcpHttpOp<I, A, E>; |
| 23 | }) => |
| 24 | Effect.gen(function* () { |
| 25 | const run = yield* options.operation; |
| 26 | return Effect.fn(function* (resource: Resource) { |
| 27 | yield* bindGcpHost({ |
| 28 | tag: options.tag, |
| 29 | resource: resource, |
| 30 | iam: [{ role: options.iam.role }], |
| 31 | }); |
| 32 | const name = yield* resource.name; |
| 33 | return Effect.fn(`${options.tag}(${resource.LogicalId})`)(function* ( |
| 34 | request?: Omit<I, "name">, |
| 35 | ) { |
| 36 | return yield* run({ |
| 37 | ...(request as I), |
| 38 | name: yield* name, |
| 39 | } as I); |
| 40 | }); |
| 41 | }); |
| 42 | }); |