@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 104 lines 3.86 KB
Raw
1 import type * as Effect from "effect/Effect";
2 import type * as Stream from "effect/Stream";
3 import {
4 consumeBusEvents,
5 type EventRecord,
6 type EventRouteProps,
7 } from "../EventBridge/EventSource.ts";
8
9 /**
10 * The `detail` payload Redshift Serverless delivers to EventBridge. Every
11 * field is optional (the schema grows over time and varies by event kind).
12 */
13 export interface RedshiftServerlessEventDetail {
14 /** Categories the event belongs to (e.g. `configuration`, `monitoring`). */
15 eventCategories?: string[];
16 /** Severity of the event (e.g. `INFO`, `ERROR`). */
17 severity?: string;
18 /** Human-readable description of what happened. */
19 eventMessage?: string;
20 /** Identifier of the namespace/workgroup/snapshot the event is about. */
21 sourceId?: string;
22 /** The kind of resource the event is about (e.g. `NAMESPACE`, `WORKGROUP`). */
23 sourceType?: string;
24 /** Additional event fields (the schema grows over time). */
25 [key: string]: unknown;
26 }
27
28 /** A Redshift Serverless EventBridge event delivered to the handler. */
29 export type RedshiftServerlessEvent = EventRecord<RedshiftServerlessEventDetail>;
30
31 export interface RedshiftServerlessEventSourceProps extends EventRouteProps {
32 /**
33 * Logical id for the backing EventBridge rule.
34 * @default "RedshiftServerlessEvents"
35 */
36 id?: string;
37 /**
38 * Restrict to specific EventBridge `detail-type`s (e.g.
39 * `"Redshift Serverless Snapshot Event"`). Omit to receive every
40 * detail-type the `aws.redshift-serverless` source publishes.
41 */
42 detailTypes?: readonly string[];
43 /**
44 * Restrict to events about specific namespaces, workgroups, or snapshots
45 * (matched against the event's top-level `resources`, which carries the
46 * resource ARNs). Recommended when the account hosts more than one
47 * data warehouse.
48 */
49 resourceArns?: readonly string[];
50 }
51
52 /**
53 * Event source connecting Redshift Serverless notifications to the hosting
54 * compute. Redshift Serverless publishes namespace, workgroup, and snapshot
55 * lifecycle events — capacity changes, completed snapshots, configuration
56 * updates — to the account's default EventBridge bus (source
57 * `aws.redshift-serverless`); this subscribes the host Function to those
58 * events so it can react to completed snapshots or alert on workgroup
59 * status changes.
60 *
61 * Redshift Serverless publishes to EventBridge automatically — no
62 * additional resource is created besides the EventBridge rule targeting the
63 * host. Provide the host-specific implementation layer (e.g.
64 * `AWS.Lambda.EventSource`) on the Function effect.
65 *
66 * ### Consuming Redshift Serverless Events
67 * **Example:** React to Data Warehouse Events
68 * ```typescript
69 * import * as AWS from "@alchemy.run/aws";
70 *
71 * export default AlertFunction.make(
72 * { main: import.meta.url },
73 * Effect.gen(function* () {
74 * const namespaceArn = yield* namespace.namespaceArn;
75 * yield* AWS.RedshiftServerless.consumeRedshiftServerlessEvents(
76 * { resourceArns: [namespaceArn] },
77 * (events) =>
78 * Stream.runForEach(events, (event) =>
79 * Effect.logInfo(
80 * `${event["detail-type"]}: ${event.detail.eventMessage}`,
81 * ),
82 * ),
83 * );
84 * return {};
85 * }).pipe(Effect.provide(AWS.Lambda.EventSource)),
86 * );
87 * ```
88 */
89 export const consumeRedshiftServerlessEvents = <StreamReq = never, Req = never>(
90 props: RedshiftServerlessEventSourceProps,
91 process: (
92 events: Stream.Stream<RedshiftServerlessEvent, never, StreamReq>,
93 ) => Effect.Effect<void, never, Req>,
94 ) =>
95 consumeBusEvents(
96 props.id ?? "RedshiftServerlessEvents",
97 {
98 source: ["aws.redshift-serverless"],
99 ...(props.detailTypes !== undefined ? { "detail-type": [...props.detailTypes] } : {}),
100 ...(props.resourceArns !== undefined ? { resources: [...props.resourceArns] } : {}),
101 },
102 { description: props.description, state: props.state },
103 process,
104 );