1import * as GCP from "@/GCP";
2import * as Effect from "effect/Effect";
3import { serveProbes } from "../../bindingHost.ts";
4
5export const Events = GCP.PubSubLite.AdminTopic("Events", {
6 location: "us-central1-a",
7});
8
9export const Inbox = Effect.gen(function* () {
10 const topic = yield* Events;
11 return yield* GCP.PubSubLite.AdminSubscription("Inbox", {
12 location: "us-central1-a",
13 topic: topic.name,
14 });
15});
16
17export const Capacity = GCP.PubSubLite.AdminReservation("Capacity", {
18 location: "us-central1",
19 throughputCapacity: "4",
20});
21
22export const COMMITTED_OFFSET = "0";
23
24/**
25 * Effect-native Cloud Run service exercising every Pub/Sub Lite binding as
26 * its own runtime service account. Deployed from {@link ../Bindings.test.ts}.
27 */
28export default class PubSubLiteBindingsHost extends GCP.Function<PubSubLiteBindingsHost>()(
29 "PubSubLiteBindingsHost",
30 { main: import.meta.url, invokerIamDisabled: true },
31 Effect.gen(function* () {
32 const getTopic = yield* GCP.PubSubLite.GetTopic(Events);
33 const getPartitions = yield* GCP.PubSubLite.GetPartitions(Events);
34 const computeHead = yield* GCP.PubSubLite.ComputeHeadCursor(Events);
35 const getSubscription = yield* GCP.PubSubLite.GetSubscription(Inbox);
36 const commitCursor = yield* GCP.PubSubLite.CommitCursor(Inbox);
37 const getReservation = yield* GCP.PubSubLite.GetReservation(Capacity);
38
39 return {
40 fetch: serveProbes({
41 getTopic: getTopic(),
42 getPartitions: getPartitions(),
43 computeHeadCursor: computeHead({ body: { partition: "0" } }),
44 getSubscription: getSubscription(),
45 commitCursor: commitCursor({
46 body: { partition: "0", cursor: { offset: COMMITTED_OFFSET } },
47 }),
48 getReservation: getReservation(),
49 }),
50 };
51 }).pipe(
52 Effect.provide(GCP.PubSubLite.GetTopicHttp),
53 Effect.provide(GCP.PubSubLite.GetPartitionsHttp),
54 Effect.provide(GCP.PubSubLite.ComputeHeadCursorHttp),
55 Effect.provide(GCP.PubSubLite.GetSubscriptionHttp),
56 Effect.provide(GCP.PubSubLite.CommitCursorHttp),
57 Effect.provide(GCP.PubSubLite.GetReservationHttp),
58 ),
59) {}