1import type * as pubsub from "@distilled.cloud/gcp/pubsub_v1";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { RuntimeContext } from "../../RuntimeContext.ts";
5import type { Topic } from "./Topic.ts";
6
7export interface PublishRequest extends Omit<
8 pubsub.PublishProjectsTopicsRequest,
9 "topic"
10> {}
11
12/**
13 * Runtime binding for Pub/Sub `topics.publish`.
14 *
15 * Bind this operation to a {@link Topic} in a Function/Action init phase.
16 * Provide {@link PublishHttp}.
17 *
18 * ### Publishing Messages
19 * **Example:** Publish a message
20 * ```typescript
21 * const publish = yield* GCP.PubSub.Publish(topic);
22 * const { messageIds } = yield* publish({
23 * body: { messages: [{ data: btoa("hello") }] },
24 * });
25 * ```
26 *
27 * @binding
28 * @category PubSub
29 */
30export interface Publish extends Binding.Service<
31 Publish,
32 "GCP.PubSub.Publish",
33 (
34 topic: Topic,
35 ) => Effect.Effect<
36 (
37 request: PublishRequest,
38 ) => Effect.Effect<
39 pubsub.PublishResponse,
40 pubsub.PublishProjectsTopicsError,
41 RuntimeContext
42 >
43 >
44> {}
45
46export const Publish = Binding.Service<Publish>("GCP.PubSub.Publish");