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
| 1 | import * as eventbridge from "@distilled.cloud/aws/eventbridge"; |
| 2 | import * as Binding from "alchemy/Binding"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import type { Endpoint } from "./Endpoint.ts"; |
| 5 | import type { EventBus } from "./EventBus.ts"; |
| 6 | |
| 7 | export interface PutEventsRequest extends Omit<eventbridge.PutEventsRequest, "Entries"> { |
| 8 | Entries: Array<Omit<eventbridge.PutEventsRequestEntry, "EventBusName">>; |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * Publishes events to an EventBridge event bus (`events:PutEvents`). |
| 13 | * |
| 14 | * Bind this operation to an {@link EventBus} inside a function runtime to get |
| 15 | * a callable that automatically injects the bus name into every entry. Omit |
| 16 | * the bus argument to publish to the account's default event bus, or bind a |
| 17 | * global {@link Endpoint} to publish through it (EventBridge routes each |
| 18 | * event to the healthy region's bus). Provide the `PutEventsHttp` layer on |
| 19 | * the Function to satisfy the binding. |
| 20 | * ### Publishing Events |
| 21 | * **Example:** Publish an Event from a Handler |
| 22 | * ```typescript |
| 23 | * // init — bind the bus (provide AWS.EventBridge.PutEventsHttp on the Function) |
| 24 | * const putEvents = yield* AWS.EventBridge.PutEvents(bus); |
| 25 | * |
| 26 | * return { |
| 27 | * fetch: Effect.gen(function* () { |
| 28 | * // runtime — publish an event |
| 29 | * const result = yield* putEvents({ |
| 30 | * Entries: [ |
| 31 | * { |
| 32 | * Source: "my.app", |
| 33 | * DetailType: "OrderCreated", |
| 34 | * Detail: JSON.stringify({ orderId: "123" }), |
| 35 | * }, |
| 36 | * ], |
| 37 | * }); |
| 38 | * return HttpServerResponse.json({ |
| 39 | * failedEntryCount: result.FailedEntryCount ?? 0, |
| 40 | * }); |
| 41 | * }), |
| 42 | * }; |
| 43 | * ``` |
| 44 | * |
| 45 | * **Example:** Publish to the Default Event Bus |
| 46 | * ```typescript |
| 47 | * // omit the bus argument to target the account's default bus |
| 48 | * const putEvents = yield* AWS.EventBridge.PutEvents(); |
| 49 | * |
| 50 | * yield* putEvents({ |
| 51 | * Entries: [ |
| 52 | * { |
| 53 | * Source: "my.app", |
| 54 | * DetailType: "Heartbeat", |
| 55 | * Detail: JSON.stringify({ at: new Date().toISOString() }), |
| 56 | * }, |
| 57 | * ], |
| 58 | * }); |
| 59 | * ``` |
| 60 | * |
| 61 | * ### Publishing Through a Global Endpoint |
| 62 | * **Example:** Publish to a Multi-Region Endpoint |
| 63 | * ```typescript |
| 64 | * const putEvents = yield* AWS.EventBridge.PutEvents(endpoint); |
| 65 | * |
| 66 | * yield* putEvents({ |
| 67 | * Entries: [ |
| 68 | * { |
| 69 | * Source: "my.app", |
| 70 | * DetailType: "OrderCreated", |
| 71 | * Detail: JSON.stringify({ orderId: "123" }), |
| 72 | * }, |
| 73 | * ], |
| 74 | * }); |
| 75 | * ``` |
| 76 | * |
| 77 | * @binding |
| 78 | */ |
| 79 | export interface PutEvents extends Binding.Service< |
| 80 | PutEvents, |
| 81 | "AWS.EventBridge.PutEvents", |
| 82 | ( |
| 83 | target?: EventBus | Endpoint, |
| 84 | ) => Effect.Effect< |
| 85 | ( |
| 86 | request: PutEventsRequest, |
| 87 | ) => Effect.Effect<eventbridge.PutEventsResponse, eventbridge.PutEventsError> |
| 88 | > |
| 89 | > {} |
| 90 | export const PutEvents = Binding.Service<PutEvents>("AWS.EventBridge.PutEvents"); |