1import * as Effect from "effect/Effect";
2import type { ParametersVersion } from "./ParametersVersion.ts";
3import { bindGcpHost } from "../Host.ts";
4import { grantFor, type BindingIam, type GcpHttpOp } from "../HttpBinding.ts";
5
6/**
7 * Shared HTTP scaffolding for Parameter Manager version bindings.
8 * NOT exported from index.ts.
9 */
10export const makeParameterVersionHttpBinding = <I, A, E, Req = void>(options: {
11 tag: string;
12 iam: BindingIam;
13 operation: GcpHttpOp<I, A, E>;
14 toInput: (versionName: string, request: Req | undefined) => I;
15}) =>
16 Effect.gen(function* () {
17 const run = yield* options.operation;
18 return Effect.fn(function* (version: ParametersVersion) {
19 yield* bindGcpHost({
20 tag: options.tag,
21 resource: version,
22 iam: [grantFor(options.iam, version.name)],
23 });
24 const name = yield* version.name;
25 return Effect.fn(`${options.tag}(${version.LogicalId})`)(function* (
26 request?: Req,
27 ) {
28 return yield* run(options.toInput(yield* name, request));
29 });
30 });
31 });