| 1 | import type * as pubsub from "@distilled.cloud/gcp/pubsub_v1"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { RuntimeContext } from "../../RuntimeContext.ts"; |
| 5 | import type { Schema } from "./Schema.ts"; |
| 6 | |
| 7 | export interface ValidateMessageRequest extends Omit< |
| 8 | pubsub.ValidateMessageRequest, |
| 9 | "name" | "schema" |
| 10 | > {} |
| 11 | |
| 12 | /** |
| 13 | * Runtime binding for Pub/Sub `schemas.validateMessage`. |
| 14 | * |
| 15 | * Bind this operation to a {@link Schema} in a Function/Action init phase. |
| 16 | * Provide {@link ValidateMessageHttp}. |
| 17 | * |
| 18 | * Grants `roles/pubsub.viewer` on the project: `schemas.validateMessage` is |
| 19 | * authorized on the parent project, and a grant on the schema's own IAM |
| 20 | * policy is not enough. |
| 21 | * |
| 22 | * ### Validating Messages |
| 23 | * **Example:** Validate a JSON-encoded Avro payload |
| 24 | * ```typescript |
| 25 | * const validate = yield* GCP.PubSub.ValidateMessage(schema); |
| 26 | * yield* validate({ |
| 27 | * encoding: "JSON", |
| 28 | * message: btoa(JSON.stringify({ id: "abc" })), |
| 29 | * }); |
| 30 | * ``` |
| 31 | * |
| 32 | * @binding |
| 33 | * @category PubSub |
| 34 | */ |
| 35 | export interface ValidateMessage extends Binding.Service< |
| 36 | ValidateMessage, |
| 37 | "GCP.PubSub.ValidateMessage", |
| 38 | ( |
| 39 | schema: Schema, |
| 40 | ) => Effect.Effect< |
| 41 | ( |
| 42 | request: ValidateMessageRequest, |
| 43 | ) => Effect.Effect< |
| 44 | pubsub.ValidateMessageResponse, |
| 45 | pubsub.ValidateMessageProjectsSchemasError, |
| 46 | RuntimeContext |
| 47 | > |
| 48 | > |
| 49 | > {} |
| 50 | |
| 51 | export const ValidateMessage = Binding.Service<ValidateMessage>( |
| 52 | "GCP.PubSub.ValidateMessage", |
| 53 | ); |