@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 86 lines 2.83 KB
Raw
1 import type * as pubsub from "@distilled.cloud/gcp/pubsub_v1";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import type * as Effect from "effect/Effect";
5 import type { Subscription } from "./Subscription.ts";
6
7 export interface PullSubscriptionOptions {
8 /**
9 * Maximum messages to return.
10 * @default 10
11 */
12 maxMessages?: number;
13 /**
14 * Return immediately when no messages are available instead of waiting
15 * briefly for some to arrive.
16 * @default false
17 */
18 returnImmediately?: boolean;
19 }
20
21 /** A pulled message with its payload decoded. */
22 export interface PulledMessage extends pubsub.ReceivedMessage {
23 /** Ack id for `acknowledge` / `modifyAckDeadline`. */
24 ackId: string;
25 /** Server-assigned message id. */
26 messageId: string;
27 /** Decoded message body. */
28 data: Uint8Array;
29 /** `data` decoded as UTF-8. */
30 text: string;
31 /** Message attributes (empty when none were set). */
32 attributes: Record<string, string>;
33 }
34
35 /** Consumer client for one Pub/Sub subscription. */
36 export interface ReadSubscriptionClient {
37 /** Pull up to `maxMessages` messages; an empty array when none arrived. */
38 pull(
39 options?: PullSubscriptionOptions,
40 ): Effect.Effect<PulledMessage[], pubsub.PullProjectsSubscriptionsError, RuntimeContext>;
41 /** Acknowledge messages by ack id. An empty list is a no-op. */
42 acknowledge(
43 ackIds: ReadonlyArray<string>,
44 ): Effect.Effect<void, pubsub.AcknowledgeProjectsSubscriptionsError, RuntimeContext>;
45 /**
46 * Extend (or, with `0`, release for redelivery) the ack deadline of
47 * messages. An empty list is a no-op.
48 */
49 modifyAckDeadline(
50 ackIds: ReadonlyArray<string>,
51 seconds: number,
52 ): Effect.Effect<void, pubsub.ModifyAckDeadlineProjectsSubscriptionsError, RuntimeContext>;
53 }
54
55 /**
56 * Consume access to a Pub/Sub {@link Subscription}: `pull`, `acknowledge`,
57 * `modifyAckDeadline`. Grants `roles/pubsub.subscriber` on the subscription
58 * only.
59 *
60 * ### Consuming messages
61 * **Example:** Pull and acknowledge
62 * ```typescript
63 * const inbox = yield* GCP.PubSub.ReadSubscription(subscription);
64 * const messages = yield* inbox.pull({ maxMessages: 10 });
65 * for (const message of messages) {
66 * yield* Effect.log(message.text, message.attributes);
67 * }
68 * yield* inbox.acknowledge(messages.map((m) => m.ackId));
69 * // …provided with Effect.provide(GCP.PubSub.ReadSubscriptionHttp)
70 * ```
71 *
72 * **Example:** Release a message for redelivery
73 * ```typescript
74 * yield* inbox.modifyAckDeadline([message.ackId], 0);
75 * ```
76 *
77 * @binding
78 * @category PubSub
79 */
80 export interface ReadSubscription extends Binding.Service<
81 ReadSubscription,
82 "GCP.PubSub.ReadSubscription",
83 (subscription: Subscription) => Effect.Effect<ReadSubscriptionClient>
84 > {}
85
86 export const ReadSubscription = Binding.Service<ReadSubscription>("GCP.PubSub.ReadSubscription");