1import * as pubsub from "@distilled.cloud/gcp/pubsub_v1";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import { GetSchema, type GetSchemaRequest } from "./GetSchema.ts";
5import type { Schema } from "./Schema.ts";
6import { bindGcpHost } from "../Host.ts";
7import { grantFor } from "../HttpBinding.ts";
8
9/**
10 * HTTP implementation of {@link GetSchema}.
11 *
12 * @layer
13 * @provides GCP.PubSub.GetSchema
14 */
15export const GetSchemaHttp = Layer.effect(
16 GetSchema,
17 Effect.gen(function* () {
18 const getSchema = yield* pubsub.getProjectsSchemas;
19 return Effect.fn(function* (schema: Schema) {
20 yield* bindGcpHost({
21 tag: "GCP.PubSub.GetSchema",
22 resource: schema,
23 iam: [
24 grantFor(
25 { role: "roles/pubsub.viewer", on: "pubsub.schema" },
26 schema.name,
27 ),
28 ],
29 });
30 const name = yield* schema.name;
31 return Effect.fn(`GCP.PubSub.GetSchema(${schema.LogicalId})`)(function* (
32 request?: GetSchemaRequest,
33 ) {
34 return yield* getSchema({
35 view: "FULL",
36 ...request,
37 name: yield* name,
38 });
39 });
40 });
41 }),
42);