1import * as GCP from "@/GCP";
2import * as Effect from "effect/Effect";
3import { serveProbes } from "../../bindingHost.ts";
4
5const location = "us";
6
7/** Document schema GetDocumentSchema reads. */
8export const Note = GCP.ContentWarehouse.DocumentSchema("Note", {
9 location,
10 displayName: "binding-note",
11 propertyDefinitions: [
12 { name: "title", isSearchable: true, textTypeOptions: {} },
13 ],
14});
15
16/** Document GetDocument reads. */
17export const Welcome = Effect.gen(function* () {
18 const schema = yield* Note;
19 return yield* GCP.ContentWarehouse.Document("Welcome", {
20 location,
21 documentSchemaName: schema.name,
22 displayName: "binding-welcome",
23 plainText: "hello binding",
24 });
25});
26
27/** Rule set GetRuleSet reads. */
28export const Checks = GCP.ContentWarehouse.RuleSet("Checks", {
29 location,
30 description: "binding rules",
31 source: "alchemy",
32 rules: [
33 {
34 description: "require title",
35 triggerType: "ON_CREATE",
36 condition: "true",
37 actions: [{ dataValidation: { conditions: { display_name: "true" } } }],
38 },
39 ],
40});
41
42/** Synonym set GetSynonymSet reads. */
43export const Sales = GCP.ContentWarehouse.SynonymSet("Sales", {
44 location,
45 synonyms: [{ words: ["sale", "invoice", "bill"] }],
46});
47
48/**
49 * Effect-native Cloud Run service exercising every Document AI Warehouse
50 * binding as its own runtime service account. Deployed from
51 * {@link ../Bindings.test.ts}.
52 */
53export default class ContentWarehouseBindingsHost extends GCP.Function<ContentWarehouseBindingsHost>()(
54 "ContentWarehouseBindingsHost",
55 { main: import.meta.url, invokerIamDisabled: true },
56 Effect.gen(function* () {
57 const getDocumentSchema =
58 yield* GCP.ContentWarehouse.GetDocumentSchema(Note);
59 const getDocument = yield* GCP.ContentWarehouse.GetDocument(Welcome);
60 const getRuleSet = yield* GCP.ContentWarehouse.GetRuleSet(Checks);
61 const getSynonymSet = yield* GCP.ContentWarehouse.GetSynonymSet(Sales);
62
63 return {
64 fetch: serveProbes({
65 getDocumentSchema: getDocumentSchema(),
66 getDocument: getDocument(),
67 getRuleSet: getRuleSet(),
68 getSynonymSet: getSynonymSet(),
69 }),
70 };
71 }).pipe(
72 Effect.provide(GCP.ContentWarehouse.GetDocumentSchemaHttp),
73 Effect.provide(GCP.ContentWarehouse.GetDocumentHttp),
74 Effect.provide(GCP.ContentWarehouse.GetRuleSetHttp),
75 Effect.provide(GCP.ContentWarehouse.GetSynonymSetHttp),
76 ),
77) {}