@auriclabs/events 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,189 @@
1
- import { r as DynamoDBStreamEvent } from "./index.mjs";
1
+ import { Writable } from "node:stream";
2
2
 
3
+ //#region ../../node_modules/.pnpm/@types+aws-lambda@8.10.152/node_modules/@types/aws-lambda/handler.d.ts
4
+ /**
5
+ * {@link Handler} context parameter.
6
+ * See {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html AWS documentation}.
7
+ */
8
+ interface Context {
9
+ callbackWaitsForEmptyEventLoop: boolean;
10
+ functionName: string;
11
+ functionVersion: string;
12
+ invokedFunctionArn: string;
13
+ memoryLimitInMB: string;
14
+ awsRequestId: string;
15
+ logGroupName: string;
16
+ logStreamName: string;
17
+ identity?: CognitoIdentity | undefined;
18
+ clientContext?: ClientContext | undefined;
19
+ tenantId?: string | undefined;
20
+ getRemainingTimeInMillis(): number; // Functions for compatibility with earlier Node.js Runtime v0.10.42
21
+ // No longer documented, so they are deprecated, but they still work
22
+ // as of the 12.x runtime, so they are not removed from the types.
23
+ /** @deprecated Use handler callback or promise result */
24
+ done(error?: Error, result?: any): void;
25
+ /** @deprecated Use handler callback with first argument or reject a promise result */
26
+ fail(error: Error | string): void;
27
+ /** @deprecated Use handler callback with second argument or resolve a promise result */
28
+ succeed(messageOrObject: any): void; // Unclear what behavior this is supposed to have, I couldn't find any still extant reference,
29
+ // and it behaves like the above, ignoring the object parameter.
30
+ /** @deprecated Use handler callback or promise result */
31
+ succeed(message: string, object: any): void;
32
+ }
33
+ interface CognitoIdentity {
34
+ cognitoIdentityId: string;
35
+ cognitoIdentityPoolId: string;
36
+ }
37
+ interface ClientContext {
38
+ client: ClientContextClient;
39
+ Custom?: any;
40
+ env: ClientContextEnv;
41
+ }
42
+ interface ClientContextClient {
43
+ installationId: string;
44
+ appTitle: string;
45
+ appVersionName: string;
46
+ appVersionCode: string;
47
+ appPackageName: string;
48
+ }
49
+ interface ClientContextEnv {
50
+ platformVersion: string;
51
+ platform: string;
52
+ make: string;
53
+ model: string;
54
+ locale: string;
55
+ }
56
+ /**
57
+ * Interface for using response streaming from AWS Lambda.
58
+ * To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator.
59
+ *
60
+ * The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`.
61
+ * The new `responseStream` object provides a stream object that your function can write data to. Data written to this stream is sent immediately to the client. You can optionally set the Content-Type header of the response to pass additional metadata to your client about the contents of the stream.
62
+ *
63
+ * {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post}
64
+ * {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation}
65
+ *
66
+ * @example <caption>Writing to the response stream</caption>
67
+ * import 'aws-lambda';
68
+ *
69
+ * export const handler = awslambda.streamifyResponse(
70
+ * async (event, responseStream, context) => {
71
+ * responseStream.setContentType("text/plain");
72
+ * responseStream.write("Hello, world!");
73
+ * responseStream.end();
74
+ * }
75
+ * );
76
+ *
77
+ * @example <caption>Using pipeline</caption>
78
+ * import 'aws-lambda';
79
+ * import { Readable } from 'stream';
80
+ * import { pipeline } from 'stream/promises';
81
+ * import zlib from 'zlib';
82
+ *
83
+ * export const handler = awslambda.streamifyResponse(
84
+ * async (event, responseStream, context) => {
85
+ * // As an example, convert event to a readable stream.
86
+ * const requestStream = Readable.from(Buffer.from(JSON.stringify(event)));
87
+ *
88
+ * await pipeline(requestStream, zlib.createGzip(), responseStream);
89
+ * }
90
+ * );
91
+ */
92
+ type StreamifyHandler<TEvent = any, TResult = any> = (event: TEvent, responseStream: awslambda.HttpResponseStream, context: Context) => TResult | Promise<TResult>;
93
+ declare global {
94
+ namespace awslambda {
95
+ class HttpResponseStream extends Writable {
96
+ static from(writable: Writable, metadata: Record<string, unknown>): HttpResponseStream;
97
+ setContentType: (contentType: string) => void;
98
+ }
99
+ /**
100
+ * Decorator for using response streaming from AWS Lambda.
101
+ * To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator.
102
+ *
103
+ * The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`.
104
+ * The new `responseStream` object provides a stream object that your function can write data to. Data written to this stream is sent immediately to the client. You can optionally set the Content-Type header of the response to pass additional metadata to your client about the contents of the stream.
105
+ *
106
+ * {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post}
107
+ * {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation}
108
+ *
109
+ * @example <caption>Writing to the response stream</caption>
110
+ * import 'aws-lambda';
111
+ *
112
+ * export const handler = awslambda.streamifyResponse(
113
+ * async (event, responseStream, context) => {
114
+ * responseStream.setContentType("text/plain");
115
+ * responseStream.write("Hello, world!");
116
+ * responseStream.end();
117
+ * }
118
+ * );
119
+ *
120
+ * @example <caption>Using pipeline</caption>
121
+ * import 'aws-lambda';
122
+ * import { Readable } from 'stream';
123
+ * import { pipeline } from 'stream/promises';
124
+ * import zlib from 'zlib';
125
+ *
126
+ * export const handler = awslambda.streamifyResponse(
127
+ * async (event, responseStream, context) => {
128
+ * // As an example, convert event to a readable stream.
129
+ * const requestStream = Readable.from(Buffer.from(JSON.stringify(event)));
130
+ *
131
+ * await pipeline(requestStream, zlib.createGzip(), responseStream);
132
+ * }
133
+ * );
134
+ */
135
+ function streamifyResponse<TEvent = any, TResult = void>(handler: StreamifyHandler<TEvent, TResult>): StreamifyHandler<TEvent, TResult>;
136
+ }
137
+ }
138
+ //#endregion
139
+ //#region ../../node_modules/.pnpm/@types+aws-lambda@8.10.152/node_modules/@types/aws-lambda/trigger/dynamodb-stream.d.ts
140
+ // http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_AttributeValue.html
141
+ interface AttributeValue {
142
+ B?: string | undefined;
143
+ BS?: string[] | undefined;
144
+ BOOL?: boolean | undefined;
145
+ L?: AttributeValue[] | undefined;
146
+ M?: {
147
+ [id: string]: AttributeValue;
148
+ } | undefined;
149
+ N?: string | undefined;
150
+ NS?: string[] | undefined;
151
+ NULL?: boolean | undefined;
152
+ S?: string | undefined;
153
+ SS?: string[] | undefined;
154
+ }
155
+ // http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_StreamRecord.html
156
+ interface StreamRecord {
157
+ ApproximateCreationDateTime?: number | undefined;
158
+ Keys?: {
159
+ [key: string]: AttributeValue;
160
+ } | undefined;
161
+ NewImage?: {
162
+ [key: string]: AttributeValue;
163
+ } | undefined;
164
+ OldImage?: {
165
+ [key: string]: AttributeValue;
166
+ } | undefined;
167
+ SequenceNumber?: string | undefined;
168
+ SizeBytes?: number | undefined;
169
+ StreamViewType?: "KEYS_ONLY" | "NEW_IMAGE" | "OLD_IMAGE" | "NEW_AND_OLD_IMAGES" | undefined;
170
+ }
171
+ // http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_Record.html
172
+ interface DynamoDBRecord {
173
+ awsRegion?: string | undefined;
174
+ dynamodb?: StreamRecord | undefined;
175
+ eventID?: string | undefined;
176
+ eventName?: "INSERT" | "MODIFY" | "REMOVE" | undefined;
177
+ eventSource?: string | undefined;
178
+ eventSourceARN?: string | undefined;
179
+ eventVersion?: string | undefined;
180
+ userIdentity?: any;
181
+ }
182
+ // http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-ddb-update
183
+ interface DynamoDBStreamEvent {
184
+ Records: DynamoDBRecord[];
185
+ }
186
+ //#endregion
3
187
  //#region src/stream-handler.entry.d.ts
4
188
  declare const handler: (event: DynamoDBStreamEvent) => Promise<void>;
5
189
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"stream-handler.entry.d.mts","names":[],"sources":["../src/stream-handler.entry.ts"],"mappings":";;;cAEa,OAAA,GAAO,KAAA,EAGlB,mBAAA,KAHkB,OAAA"}
1
+ {"version":3,"file":"stream-handler.entry.d.mts","names":["Writable","Handler","TEvent","TResult","Context","Callback","Promise","event","context","callback","CognitoIdentity","ClientContext","Error","callbackWaitsForEmptyEventLoop","functionName","functionVersion","invokedFunctionArn","memoryLimitInMB","awsRequestId","logGroupName","logStreamName","identity","clientContext","tenantId","getRemainingTimeInMillis","done","error","result","fail","succeed","messageOrObject","message","object","cognitoIdentityId","cognitoIdentityPoolId","ClientContextClient","ClientContextEnv","client","Custom","env","installationId","appTitle","appVersionName","appVersionCode","appPackageName","platformVersion","platform","make","model","locale","StreamifyHandler","awslambda","HttpResponseStream","responseStream","_0","Record","global","from","writable","metadata","setContentType","contentType","streamifyResponse","handler","sideEffect","Handler","DynamoDBStreamHandler","DynamoDBStreamEvent","DynamoDBBatchResponse","AttributeValue","B","BS","BOOL","L","M","id","N","NS","NULL","S","SS","StreamRecord","ApproximateCreationDateTime","Keys","key","NewImage","OldImage","SequenceNumber","SizeBytes","StreamViewType","DynamoDBRecord","awsRegion","dynamodb","eventID","eventName","eventSource","eventSourceARN","eventVersion","userIdentity","Records","DynamoDBBatchItemFailure","batchItemFailures","itemIdentifier"],"sources":["../../../node_modules/.pnpm/@types+aws-lambda@8.10.152/node_modules/@types/aws-lambda/handler.d.ts","../../../node_modules/.pnpm/@types+aws-lambda@8.10.152/node_modules/@types/aws-lambda/trigger/dynamodb-stream.d.ts","../src/stream-handler.entry.ts"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;UA+FiBI,OAAAA;EACbS,8BAAAA;EACAC,YAAAA;EACAC,eAAAA;EACAC,kBAAAA;EACAC,eAAAA;EACAC,YAAAA;EACAC,YAAAA;EACAC,aAAAA;EACAC,QAAAA,GAAWX,eAAAA;EACXY,aAAAA,GAAgBX,aAAAA;EAChBY,QAAAA;EAEAC,wBAAAA;EAAAA;EAAAA;EA6JgCrB;EAtJhCsB,IAAAA,CAAKC,KAAAA,GAAQd,KAAAA,EAAOe,MA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cAAAA;EACJK,CAAAA;IAAAA,CAAOC,EAAAA,WAAaN,cAAAA;EAAAA;EACpBO,CAAAA;EACAC,EAAAA;EACAC,IAAAA;EACAC,CAAAA;EACAC,EAAAA;AAAAA;AAAAA;AAAAA,UAIaC,YAAAA;EACbC,2BAAAA;EACAC,IAAAA;IAAAA,CAAUC,GAAAA,WAAcf,cAAAA;EAAAA;EACxBgB,QAAAA;IAAAA,CAAcD,GAAAA,WAAcf,cAAAA;EAAAA;EAC5BiB,QAAAA;IAAAA,CAAcF,GAAAA,WAAcf,cAAAA;EAAAA;EAC5BkB,cAAAA;EACAC,SAAAA;EACAC,cAAAA;AAAAA;AAAAA;AAAAA,UAIaC,cAAAA;EACbC,SAAAA;EACAC,QAAAA,GAAWX,YAAAA;EACXY,OAAAA;EACAC,SAAAA;EACAC,WAAAA;EACAC,cAAAA;EACAC,YAAAA;EACAC,YAAAA;AAAAA;AAAAA;AAAAA,UAIa/B,mBAAAA;EACbgC,OAAAA,EAAST,cAAAA;AAAAA;;;cC1CA,OAAA,GAAO,KAAA,EAGlB,mBAAA,KAHkB,OAAA"}
@@ -1,4 +1,88 @@
1
- import { t as createStreamHandler } from "./stream-handler.mjs";
1
+ import { logger } from "@auriclabs/logger";
2
+ import { EventBridgeClient, PutEventsCommand } from "@aws-sdk/client-eventbridge";
3
+ import { SQSClient, SendMessageBatchCommand } from "@aws-sdk/client-sqs";
4
+ import { unmarshall } from "@aws-sdk/util-dynamodb";
5
+ import { kebabCase } from "lodash-es";
6
+ //#region src/stream-handler.ts
7
+ const BATCH_SIZE = 10;
8
+ /**
9
+ * Creates a Lambda handler for DynamoDB stream events.
10
+ * Processes INSERT events from the event store table and forwards them to SQS queues and EventBridge.
11
+ */
12
+ function createStreamHandler(config) {
13
+ const sqsClient = new SQSClient();
14
+ const eventBridge = new EventBridgeClient({});
15
+ function chunkArray(array, chunkSize) {
16
+ const chunks = [];
17
+ for (let i = 0; i < array.length; i += chunkSize) chunks.push(array.slice(i, i + chunkSize));
18
+ return chunks;
19
+ }
20
+ async function sendToQueuesBatch(eventRecords) {
21
+ await Promise.all(config.queueUrls.map((queue) => sendToQueueBatch(eventRecords, queue)));
22
+ }
23
+ async function sendToQueueBatch(eventRecords, queue) {
24
+ const batches = chunkArray(eventRecords, BATCH_SIZE);
25
+ for (const batch of batches) try {
26
+ const entries = batch.map((eventRecord, index) => ({
27
+ Id: `${eventRecord.eventId}-${index}`,
28
+ MessageBody: JSON.stringify(eventRecord),
29
+ MessageGroupId: eventRecord.aggregateId,
30
+ MessageDeduplicationId: eventRecord.eventId
31
+ }));
32
+ await sqsClient.send(new SendMessageBatchCommand({
33
+ QueueUrl: queue,
34
+ Entries: entries
35
+ }));
36
+ } catch (error) {
37
+ logger.error({
38
+ error,
39
+ batch,
40
+ queue
41
+ }, "Error sending batch to queue");
42
+ throw error;
43
+ }
44
+ }
45
+ async function sendToBusBatch(eventRecords) {
46
+ const batches = chunkArray(eventRecords, BATCH_SIZE);
47
+ for (const batch of batches) try {
48
+ const entries = batch.map((eventRecord) => {
49
+ return {
50
+ Source: eventRecord.source ?? kebabCase(eventRecord.aggregateType.split(".")[0]),
51
+ DetailType: eventRecord.eventType,
52
+ Detail: JSON.stringify(eventRecord),
53
+ EventBusName: config.busName
54
+ };
55
+ });
56
+ await eventBridge.send(new PutEventsCommand({ Entries: entries }));
57
+ } catch (error) {
58
+ logger.error({
59
+ error,
60
+ batch
61
+ }, "Error sending batch to bus");
62
+ throw error;
63
+ }
64
+ }
65
+ return async (event) => {
66
+ const eventRecords = event.Records.filter((record) => record.eventName === "INSERT").map((record) => {
67
+ try {
68
+ const data = record.dynamodb?.NewImage;
69
+ return unmarshall(data);
70
+ } catch (error) {
71
+ logger.error({
72
+ error,
73
+ record
74
+ }, "Error unmarshalling event record");
75
+ return;
76
+ }
77
+ }).filter((eventRecord) => eventRecord?.itemType === "event");
78
+ if (eventRecords.length > 0) {
79
+ const tasks = [sendToQueuesBatch(eventRecords)];
80
+ if (config.busName) tasks.push(sendToBusBatch(eventRecords));
81
+ await Promise.all(tasks);
82
+ }
83
+ };
84
+ }
85
+ //#endregion
2
86
  //#region src/stream-handler.entry.ts
3
87
  const handler = createStreamHandler({
4
88
  busName: process.env.EVENT_BUS_NAME,
@@ -1 +1 @@
1
- {"version":3,"file":"stream-handler.entry.mjs","names":[],"sources":["../src/stream-handler.entry.ts"],"sourcesContent":["import { createStreamHandler } from './stream-handler';\n\nexport const handler = createStreamHandler({\n busName: process.env.EVENT_BUS_NAME,\n queueUrls: JSON.parse(process.env.QUEUE_URL_LIST ?? '[]') as string[],\n});\n"],"mappings":";;AAEA,MAAa,UAAU,oBAAoB;CACzC,SAAS,QAAQ,IAAI;CACrB,WAAW,KAAK,MAAM,QAAQ,IAAI,kBAAkB,KAAK;CAC1D,CAAC"}
1
+ {"version":3,"file":"stream-handler.entry.mjs","names":[],"sources":["../src/stream-handler.ts","../src/stream-handler.entry.ts"],"sourcesContent":["import { logger } from '@auriclabs/logger';\nimport { AttributeValue } from '@aws-sdk/client-dynamodb';\nimport { EventBridgeClient, PutEventsCommand } from '@aws-sdk/client-eventbridge';\nimport { SendMessageBatchCommand, SQSClient } from '@aws-sdk/client-sqs';\nimport { unmarshall } from '@aws-sdk/util-dynamodb';\nimport { DynamoDBStreamEvent } from 'aws-lambda';\nimport { kebabCase } from 'lodash-es';\n\nimport { AggregateHead, EventRecord } from './types';\n\nconst BATCH_SIZE = 10;\n\nexport interface CreateStreamHandlerConfig {\n busName?: string;\n queueUrls: string[];\n}\n\n/**\n * Creates a Lambda handler for DynamoDB stream events.\n * Processes INSERT events from the event store table and forwards them to SQS queues and EventBridge.\n */\nexport function createStreamHandler(config: CreateStreamHandlerConfig) {\n const sqsClient = new SQSClient();\n const eventBridge = new EventBridgeClient({});\n\n function chunkArray<T>(array: T[], chunkSize: number): T[][] {\n const chunks: T[][] = [];\n for (let i = 0; i < array.length; i += chunkSize) {\n chunks.push(array.slice(i, i + chunkSize));\n }\n return chunks;\n }\n\n async function sendToQueuesBatch(eventRecords: EventRecord[]) {\n await Promise.all(config.queueUrls.map((queue) => sendToQueueBatch(eventRecords, queue)));\n }\n\n async function sendToQueueBatch(eventRecords: EventRecord[], queue: string) {\n const batches = chunkArray(eventRecords, BATCH_SIZE);\n\n for (const batch of batches) {\n try {\n const entries = batch.map((eventRecord, index) => ({\n Id: `${eventRecord.eventId}-${index}`,\n MessageBody: JSON.stringify(eventRecord),\n MessageGroupId: eventRecord.aggregateId,\n MessageDeduplicationId: eventRecord.eventId,\n }));\n\n await sqsClient.send(\n new SendMessageBatchCommand({\n QueueUrl: queue,\n Entries: entries,\n }),\n );\n } catch (error) {\n logger.error({ error, batch, queue }, 'Error sending batch to queue');\n throw error;\n }\n }\n }\n\n async function sendToBusBatch(eventRecords: EventRecord[]) {\n const batches = chunkArray(eventRecords, BATCH_SIZE);\n\n for (const batch of batches) {\n try {\n const entries = batch.map((eventRecord) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const source = eventRecord.source ?? kebabCase(eventRecord.aggregateType.split('.')[0]);\n return {\n Source: source,\n DetailType: eventRecord.eventType,\n Detail: JSON.stringify(eventRecord),\n EventBusName: config.busName,\n };\n });\n\n await eventBridge.send(\n new PutEventsCommand({\n Entries: entries,\n }),\n );\n } catch (error) {\n logger.error({ error, batch }, 'Error sending batch to bus');\n throw error;\n }\n }\n }\n\n return async (event: DynamoDBStreamEvent): Promise<void> => {\n const eventRecords = event.Records.filter((record) => record.eventName === 'INSERT')\n .map((record) => {\n try {\n const data = record.dynamodb?.NewImage;\n return unmarshall(data as Record<string, AttributeValue>) as EventRecord | AggregateHead;\n } catch (error) {\n logger.error({ error, record }, 'Error unmarshalling event record');\n return undefined;\n }\n })\n .filter((eventRecord): eventRecord is EventRecord => eventRecord?.itemType === 'event');\n\n if (eventRecords.length > 0) {\n const tasks: Promise<void>[] = [sendToQueuesBatch(eventRecords)];\n if (config.busName) {\n tasks.push(sendToBusBatch(eventRecords));\n }\n await Promise.all(tasks);\n }\n };\n}\n","import { createStreamHandler } from './stream-handler';\n\nexport const handler = createStreamHandler({\n busName: process.env.EVENT_BUS_NAME,\n queueUrls: JSON.parse(process.env.QUEUE_URL_LIST ?? '[]') as string[],\n});\n"],"mappings":";;;;;;AAUA,MAAM,aAAa;;;;;AAWnB,SAAgB,oBAAoB,QAAmC;CACrE,MAAM,YAAY,IAAI,WAAW;CACjC,MAAM,cAAc,IAAI,kBAAkB,EAAE,CAAC;CAE7C,SAAS,WAAc,OAAY,WAA0B;EAC3D,MAAM,SAAgB,EAAE;AACxB,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,UACrC,QAAO,KAAK,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC;AAE5C,SAAO;;CAGT,eAAe,kBAAkB,cAA6B;AAC5D,QAAM,QAAQ,IAAI,OAAO,UAAU,KAAK,UAAU,iBAAiB,cAAc,MAAM,CAAC,CAAC;;CAG3F,eAAe,iBAAiB,cAA6B,OAAe;EAC1E,MAAM,UAAU,WAAW,cAAc,WAAW;AAEpD,OAAK,MAAM,SAAS,QAClB,KAAI;GACF,MAAM,UAAU,MAAM,KAAK,aAAa,WAAW;IACjD,IAAI,GAAG,YAAY,QAAQ,GAAG;IAC9B,aAAa,KAAK,UAAU,YAAY;IACxC,gBAAgB,YAAY;IAC5B,wBAAwB,YAAY;IACrC,EAAE;AAEH,SAAM,UAAU,KACd,IAAI,wBAAwB;IAC1B,UAAU;IACV,SAAS;IACV,CAAC,CACH;WACM,OAAO;AACd,UAAO,MAAM;IAAE;IAAO;IAAO;IAAO,EAAE,+BAA+B;AACrE,SAAM;;;CAKZ,eAAe,eAAe,cAA6B;EACzD,MAAM,UAAU,WAAW,cAAc,WAAW;AAEpD,OAAK,MAAM,SAAS,QAClB,KAAI;GACF,MAAM,UAAU,MAAM,KAAK,gBAAgB;AAGzC,WAAO;KACL,QAFa,YAAY,UAAU,UAAU,YAAY,cAAc,MAAM,IAAI,CAAC,GAAG;KAGrF,YAAY,YAAY;KACxB,QAAQ,KAAK,UAAU,YAAY;KACnC,cAAc,OAAO;KACtB;KACD;AAEF,SAAM,YAAY,KAChB,IAAI,iBAAiB,EACnB,SAAS,SACV,CAAC,CACH;WACM,OAAO;AACd,UAAO,MAAM;IAAE;IAAO;IAAO,EAAE,6BAA6B;AAC5D,SAAM;;;AAKZ,QAAO,OAAO,UAA8C;EAC1D,MAAM,eAAe,MAAM,QAAQ,QAAQ,WAAW,OAAO,cAAc,SAAS,CACjF,KAAK,WAAW;AACf,OAAI;IACF,MAAM,OAAO,OAAO,UAAU;AAC9B,WAAO,WAAW,KAAuC;YAClD,OAAO;AACd,WAAO,MAAM;KAAE;KAAO;KAAQ,EAAE,mCAAmC;AACnE;;IAEF,CACD,QAAQ,gBAA4C,aAAa,aAAa,QAAQ;AAEzF,MAAI,aAAa,SAAS,GAAG;GAC3B,MAAM,QAAyB,CAAC,kBAAkB,aAAa,CAAC;AAChE,OAAI,OAAO,QACT,OAAM,KAAK,eAAe,aAAa,CAAC;AAE1C,SAAM,QAAQ,IAAI,MAAM;;;;;;AC1G9B,MAAa,UAAU,oBAAoB;CACzC,SAAS,QAAQ,IAAI;CACrB,WAAW,KAAK,MAAM,QAAQ,IAAI,kBAAkB,KAAK;CAC1D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auriclabs/events",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Event sourcing runtime utilities for DynamoDB-backed event stores",
5
5
  "prettier": "@auriclabs/prettier-config",
6
6
  "main": "dist/index.cjs",
@@ -52,7 +52,7 @@
52
52
  "directory": "packages/events"
53
53
  },
54
54
  "scripts": {
55
- "build": "tsdown src/index.ts src/stream-handler.entry.ts --format cjs,esm --dts --no-hash",
55
+ "build": "tsdown src/index.ts --format cjs,esm --dts --no-hash && tsdown src/stream-handler.entry.ts --format cjs,esm --dts --no-hash --no-clean",
56
56
  "dev": "concurrently \"pnpm build --watch\" \"pnpm:y:watch\"",
57
57
  "y:watch": "chokidar dist --initial --silent -c \"yalc publish --push\"",
58
58
  "lint": "eslint .",
package/dist/index2.d.cts DELETED
@@ -1,148 +0,0 @@
1
- import { n as SQSEvent, r as DynamoDBStreamEvent, t as SQSBatchResponse } from "./index.cjs";
2
- import { PaginationResponse } from "@auriclabs/pagination";
3
-
4
- //#region src/types.d.ts
5
- type Brand<T, B extends string> = T & {
6
- readonly __brand: B;
7
- };
8
- type Source = Brand<string, 'Source'>;
9
- type AggregateId = Brand<string, 'AggregateId'>;
10
- type AggregateType = Brand<string, 'AggregateType'>;
11
- type EventId = Brand<string, 'EventId'>;
12
- type AggregatePK = `AGG#${string}#${string}`;
13
- type EventSK = `EVT#${string}` | 'HEAD';
14
- type ItemType = 'event' | 'head';
15
- interface EventRecord<P = unknown> {
16
- /** DynamoDB keys */
17
- pk: AggregatePK;
18
- sk: EventSK;
19
- itemType: Extract<ItemType, 'event'>;
20
- /** Aggregate routing */
21
- source: Source;
22
- aggregateId: AggregateId;
23
- aggregateType: AggregateType;
24
- version: number;
25
- /** Tenant isolation */
26
- tenantId: string;
27
- /** Event identity & semantics */
28
- eventId: EventId;
29
- eventType: string;
30
- schemaVersion?: number;
31
- occurredAt: string;
32
- /** Tracing (optional) */
33
- correlationId?: string;
34
- causationId?: string;
35
- actorId?: string;
36
- /** Domain payload */
37
- payload: Readonly<P>;
38
- }
39
- interface AggregateHead {
40
- /** DynamoDB keys */
41
- pk: AggregatePK;
42
- sk: 'HEAD';
43
- itemType: Extract<ItemType, 'head'>;
44
- /** Aggregate identity */
45
- aggregateId: AggregateId;
46
- aggregateType: AggregateType;
47
- /** Version tracking */
48
- currentVersion: number;
49
- /** Idempotency/debug */
50
- lastEventId?: EventId;
51
- lastIdemKey?: string;
52
- updatedAt: string;
53
- }
54
- type EventHandlers = Record<string, ((event: EventRecord<any>) => Promise<void> | void) | string>;
55
- //#endregion
56
- //#region src/event-service.d.ts
57
- interface AppendArgs<P = unknown> {
58
- tenantId: string;
59
- aggregateType: string;
60
- aggregateId: string;
61
- source: string;
62
- /** Version you observed before appending (0 for brand new) */
63
- expectedVersion: number;
64
- /** Required for idempotent retries (e.g., the command id) */
65
- idempotencyKey: string;
66
- eventId: string;
67
- eventType: string;
68
- occurredAt?: string;
69
- payload?: Readonly<P>;
70
- schemaVersion?: number;
71
- correlationId?: string;
72
- causationId?: string;
73
- actorId?: string;
74
- }
75
- interface AppendEventResult {
76
- pk: string;
77
- sk: string;
78
- version: number;
79
- }
80
- interface EventService {
81
- appendEvent<P = unknown>(args: AppendArgs<P>): Promise<AppendEventResult>;
82
- getHead(aggregateType: string, aggregateId: string): Promise<AggregateHead | undefined>;
83
- getEvent(aggregateType: string, aggregateId: string, version: number): Promise<EventRecord | undefined>;
84
- listEvents(params: {
85
- aggregateType: string;
86
- aggregateId: string;
87
- fromVersionExclusive?: number;
88
- toVersionInclusive?: number;
89
- limit?: number;
90
- }): Promise<PaginationResponse<EventRecord>>;
91
- }
92
- declare function createEventService(tableName: string): EventService;
93
- //#endregion
94
- //#region src/init.d.ts
95
- declare function initEvents(config: {
96
- tableName: string;
97
- }): void;
98
- declare function getEventService(): EventService;
99
- //#endregion
100
- //#region src/context.d.ts
101
- type EventContext = Partial<AppendArgs>;
102
- declare const setEventContext: (newContext: EventContext) => void;
103
- declare const getEventContext: () => Partial<AppendArgs<unknown>>;
104
- declare const resetEventContext: () => void;
105
- declare const appendEventContext: (event: EventContext) => void;
106
- //#endregion
107
- //#region src/dispatch-event.d.ts
108
- type DispatchEventArgs = Omit<AppendArgs, 'eventId' | 'expectedVersion' | 'schemaVersion' | 'occurredAt' | 'idempotencyKey'> & Partial<Pick<AppendArgs, 'idempotencyKey' | 'eventId'>>;
109
- declare const dispatchEvent: (event: DispatchEventArgs) => Promise<AppendEventResult>;
110
- //#endregion
111
- //#region src/dispatch-events.d.ts
112
- interface DispatchEventsArgs {
113
- inOrder?: boolean;
114
- }
115
- declare const dispatchEvents: (events: DispatchEventArgs[], {
116
- inOrder
117
- }?: DispatchEventsArgs) => Promise<void>;
118
- //#endregion
119
- //#region src/create-dispatch.d.ts
120
- type MakePartial<T, O> = Omit<T, keyof O> & Partial<O>;
121
- type DispatchRecord<Options extends Partial<DispatchEventArgs> = Partial<DispatchEventArgs>> = Record<string, (...args: any[]) => ValueOrFactoryRecord<MakePartial<DispatchEventArgs, Options>> | DispatchEventArgsFactory<Options>>;
122
- type ValueOrFactory<T> = T | ((context: EventContext) => T);
123
- type ValueOrFactoryRecord<T> = { [K in keyof T]: ValueOrFactory<T[K]> };
124
- type DispatchEventArgsFactory<Options extends Partial<DispatchEventArgs>> = (context: EventContext) => MakePartial<DispatchEventArgs, Options>;
125
- type DispatchRecordResponse<R extends DispatchRecord<O>, O extends Partial<DispatchEventArgs>> = { [K in keyof R]: (...args: Parameters<R[K]>) => Promise<AppendEventResult> };
126
- declare function createDispatch<DR extends DispatchRecord<O>, O extends Partial<DispatchEventArgs>>(record: DR, optionsOrFactory?: ValueOrFactoryRecord<O> | ((context: EventContext) => O)): DispatchRecordResponse<DR, O>;
127
- //#endregion
128
- //#region src/create-event-listener.d.ts
129
- interface CreateEventListenerOptions {
130
- debug?: boolean;
131
- }
132
- declare const createEventListener: (eventHandlers: EventHandlers, {
133
- debug
134
- }?: CreateEventListenerOptions) => (sqsEvent: SQSEvent) => Promise<SQSBatchResponse>;
135
- //#endregion
136
- //#region src/stream-handler.d.ts
137
- interface CreateStreamHandlerConfig {
138
- busName?: string;
139
- queueUrls: string[];
140
- }
141
- /**
142
- * Creates a Lambda handler for DynamoDB stream events.
143
- * Processes INSERT events from the event store table and forwards them to SQS queues and EventBridge.
144
- */
145
- declare function createStreamHandler(config: CreateStreamHandlerConfig): (event: DynamoDBStreamEvent) => Promise<void>;
146
- //#endregion
147
- export { AggregateHead, AggregateId, AggregatePK, AggregateType, AppendArgs, AppendEventResult, Brand, CreateEventListenerOptions, CreateStreamHandlerConfig, DispatchEventArgs, DispatchEventArgsFactory, DispatchEventsArgs, DispatchRecord, DispatchRecordResponse, EventContext, EventHandlers, EventId, EventRecord, EventSK, EventService, ItemType, MakePartial, Source, ValueOrFactory, ValueOrFactoryRecord, appendEventContext, createDispatch, createEventListener, createEventService, createStreamHandler, dispatchEvent, dispatchEvents, getEventContext, getEventService, initEvents, resetEventContext, setEventContext };
148
- //# sourceMappingURL=index2.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index2.d.cts","names":[],"sources":["../src/types.ts","../src/event-service.ts","../src/init.ts","../src/context.ts","../src/dispatch-event.ts","../src/dispatch-events.ts","../src/create-dispatch.ts","../src/create-event-listener.ts","../src/stream-handler.ts"],"mappings":";;;;KACY,KAAA,wBAA6B,CAAA;EAAA,SAAe,OAAA,EAAS,CAAA;AAAA;AAAA,KACrD,MAAA,GAAS,KAAA;AAAA,KACT,WAAA,GAAc,KAAA;AAAA,KACd,aAAA,GAAgB,KAAA;AAAA,KAChB,OAAA,GAAU,KAAA;AAAA,KAGV,WAAA;AAAA,KACA,OAAA;AAAA,KACA,QAAA;AAAA,UAGK,WAAA;EAZuC;EActD,EAAA,EAAI,WAAA;EACJ,EAAA,EAAI,OAAA;EACJ,QAAA,EAAU,OAAA,CAAQ,QAAA;EAfR;EAkBV,MAAA,EAAQ,MAAA;EACR,WAAA,EAAa,WAAA;EACb,aAAA,EAAe,aAAA;EACf,OAAA;EApBU;EAuBV,QAAA;;EAGA,OAAA,EAAS,OAAA;EACT,SAAA;EACA,aAAA;EACA,UAAA;;EAGA,aAAA;EACA,WAAA;EACA,OAAA;EAhCiB;EAmCjB,OAAA,EAAS,QAAA,CAAS,CAAA;AAAA;AAAA,UAIH,aAAA;EApCL;EAsCV,EAAA,EAAI,WAAA;EACJ,EAAA;EACA,QAAA,EAAU,OAAA,CAAQ,QAAA;EAxCG;EA2CrB,WAAA,EAAa,WAAA;EACb,aAAA,EAAe,aAAA;;EAGf,cAAA;EA9CiB;EAiDjB,WAAA,GAAc,OAAA;EACd,WAAA;EACA,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AAA,KAAsB,OAAA"}
package/dist/index2.d.mts DELETED
@@ -1,148 +0,0 @@
1
- import { n as SQSEvent, r as DynamoDBStreamEvent, t as SQSBatchResponse } from "./index.mjs";
2
- import { PaginationResponse } from "@auriclabs/pagination";
3
-
4
- //#region src/types.d.ts
5
- type Brand<T, B extends string> = T & {
6
- readonly __brand: B;
7
- };
8
- type Source = Brand<string, 'Source'>;
9
- type AggregateId = Brand<string, 'AggregateId'>;
10
- type AggregateType = Brand<string, 'AggregateType'>;
11
- type EventId = Brand<string, 'EventId'>;
12
- type AggregatePK = `AGG#${string}#${string}`;
13
- type EventSK = `EVT#${string}` | 'HEAD';
14
- type ItemType = 'event' | 'head';
15
- interface EventRecord<P = unknown> {
16
- /** DynamoDB keys */
17
- pk: AggregatePK;
18
- sk: EventSK;
19
- itemType: Extract<ItemType, 'event'>;
20
- /** Aggregate routing */
21
- source: Source;
22
- aggregateId: AggregateId;
23
- aggregateType: AggregateType;
24
- version: number;
25
- /** Tenant isolation */
26
- tenantId: string;
27
- /** Event identity & semantics */
28
- eventId: EventId;
29
- eventType: string;
30
- schemaVersion?: number;
31
- occurredAt: string;
32
- /** Tracing (optional) */
33
- correlationId?: string;
34
- causationId?: string;
35
- actorId?: string;
36
- /** Domain payload */
37
- payload: Readonly<P>;
38
- }
39
- interface AggregateHead {
40
- /** DynamoDB keys */
41
- pk: AggregatePK;
42
- sk: 'HEAD';
43
- itemType: Extract<ItemType, 'head'>;
44
- /** Aggregate identity */
45
- aggregateId: AggregateId;
46
- aggregateType: AggregateType;
47
- /** Version tracking */
48
- currentVersion: number;
49
- /** Idempotency/debug */
50
- lastEventId?: EventId;
51
- lastIdemKey?: string;
52
- updatedAt: string;
53
- }
54
- type EventHandlers = Record<string, ((event: EventRecord<any>) => Promise<void> | void) | string>;
55
- //#endregion
56
- //#region src/event-service.d.ts
57
- interface AppendArgs<P = unknown> {
58
- tenantId: string;
59
- aggregateType: string;
60
- aggregateId: string;
61
- source: string;
62
- /** Version you observed before appending (0 for brand new) */
63
- expectedVersion: number;
64
- /** Required for idempotent retries (e.g., the command id) */
65
- idempotencyKey: string;
66
- eventId: string;
67
- eventType: string;
68
- occurredAt?: string;
69
- payload?: Readonly<P>;
70
- schemaVersion?: number;
71
- correlationId?: string;
72
- causationId?: string;
73
- actorId?: string;
74
- }
75
- interface AppendEventResult {
76
- pk: string;
77
- sk: string;
78
- version: number;
79
- }
80
- interface EventService {
81
- appendEvent<P = unknown>(args: AppendArgs<P>): Promise<AppendEventResult>;
82
- getHead(aggregateType: string, aggregateId: string): Promise<AggregateHead | undefined>;
83
- getEvent(aggregateType: string, aggregateId: string, version: number): Promise<EventRecord | undefined>;
84
- listEvents(params: {
85
- aggregateType: string;
86
- aggregateId: string;
87
- fromVersionExclusive?: number;
88
- toVersionInclusive?: number;
89
- limit?: number;
90
- }): Promise<PaginationResponse<EventRecord>>;
91
- }
92
- declare function createEventService(tableName: string): EventService;
93
- //#endregion
94
- //#region src/init.d.ts
95
- declare function initEvents(config: {
96
- tableName: string;
97
- }): void;
98
- declare function getEventService(): EventService;
99
- //#endregion
100
- //#region src/context.d.ts
101
- type EventContext = Partial<AppendArgs>;
102
- declare const setEventContext: (newContext: EventContext) => void;
103
- declare const getEventContext: () => Partial<AppendArgs<unknown>>;
104
- declare const resetEventContext: () => void;
105
- declare const appendEventContext: (event: EventContext) => void;
106
- //#endregion
107
- //#region src/dispatch-event.d.ts
108
- type DispatchEventArgs = Omit<AppendArgs, 'eventId' | 'expectedVersion' | 'schemaVersion' | 'occurredAt' | 'idempotencyKey'> & Partial<Pick<AppendArgs, 'idempotencyKey' | 'eventId'>>;
109
- declare const dispatchEvent: (event: DispatchEventArgs) => Promise<AppendEventResult>;
110
- //#endregion
111
- //#region src/dispatch-events.d.ts
112
- interface DispatchEventsArgs {
113
- inOrder?: boolean;
114
- }
115
- declare const dispatchEvents: (events: DispatchEventArgs[], {
116
- inOrder
117
- }?: DispatchEventsArgs) => Promise<void>;
118
- //#endregion
119
- //#region src/create-dispatch.d.ts
120
- type MakePartial<T, O> = Omit<T, keyof O> & Partial<O>;
121
- type DispatchRecord<Options extends Partial<DispatchEventArgs> = Partial<DispatchEventArgs>> = Record<string, (...args: any[]) => ValueOrFactoryRecord<MakePartial<DispatchEventArgs, Options>> | DispatchEventArgsFactory<Options>>;
122
- type ValueOrFactory<T> = T | ((context: EventContext) => T);
123
- type ValueOrFactoryRecord<T> = { [K in keyof T]: ValueOrFactory<T[K]> };
124
- type DispatchEventArgsFactory<Options extends Partial<DispatchEventArgs>> = (context: EventContext) => MakePartial<DispatchEventArgs, Options>;
125
- type DispatchRecordResponse<R extends DispatchRecord<O>, O extends Partial<DispatchEventArgs>> = { [K in keyof R]: (...args: Parameters<R[K]>) => Promise<AppendEventResult> };
126
- declare function createDispatch<DR extends DispatchRecord<O>, O extends Partial<DispatchEventArgs>>(record: DR, optionsOrFactory?: ValueOrFactoryRecord<O> | ((context: EventContext) => O)): DispatchRecordResponse<DR, O>;
127
- //#endregion
128
- //#region src/create-event-listener.d.ts
129
- interface CreateEventListenerOptions {
130
- debug?: boolean;
131
- }
132
- declare const createEventListener: (eventHandlers: EventHandlers, {
133
- debug
134
- }?: CreateEventListenerOptions) => (sqsEvent: SQSEvent) => Promise<SQSBatchResponse>;
135
- //#endregion
136
- //#region src/stream-handler.d.ts
137
- interface CreateStreamHandlerConfig {
138
- busName?: string;
139
- queueUrls: string[];
140
- }
141
- /**
142
- * Creates a Lambda handler for DynamoDB stream events.
143
- * Processes INSERT events from the event store table and forwards them to SQS queues and EventBridge.
144
- */
145
- declare function createStreamHandler(config: CreateStreamHandlerConfig): (event: DynamoDBStreamEvent) => Promise<void>;
146
- //#endregion
147
- export { AggregateHead, AggregateId, AggregatePK, AggregateType, AppendArgs, AppendEventResult, Brand, CreateEventListenerOptions, CreateStreamHandlerConfig, DispatchEventArgs, DispatchEventArgsFactory, DispatchEventsArgs, DispatchRecord, DispatchRecordResponse, EventContext, EventHandlers, EventId, EventRecord, EventSK, EventService, ItemType, MakePartial, Source, ValueOrFactory, ValueOrFactoryRecord, appendEventContext, createDispatch, createEventListener, createEventService, createStreamHandler, dispatchEvent, dispatchEvents, getEventContext, getEventService, initEvents, resetEventContext, setEventContext };
148
- //# sourceMappingURL=index2.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index2.d.mts","names":[],"sources":["../src/types.ts","../src/event-service.ts","../src/init.ts","../src/context.ts","../src/dispatch-event.ts","../src/dispatch-events.ts","../src/create-dispatch.ts","../src/create-event-listener.ts","../src/stream-handler.ts"],"mappings":";;;;KACY,KAAA,wBAA6B,CAAA;EAAA,SAAe,OAAA,EAAS,CAAA;AAAA;AAAA,KACrD,MAAA,GAAS,KAAA;AAAA,KACT,WAAA,GAAc,KAAA;AAAA,KACd,aAAA,GAAgB,KAAA;AAAA,KAChB,OAAA,GAAU,KAAA;AAAA,KAGV,WAAA;AAAA,KACA,OAAA;AAAA,KACA,QAAA;AAAA,UAGK,WAAA;EAZuC;EActD,EAAA,EAAI,WAAA;EACJ,EAAA,EAAI,OAAA;EACJ,QAAA,EAAU,OAAA,CAAQ,QAAA;EAfR;EAkBV,MAAA,EAAQ,MAAA;EACR,WAAA,EAAa,WAAA;EACb,aAAA,EAAe,aAAA;EACf,OAAA;EApBU;EAuBV,QAAA;;EAGA,OAAA,EAAS,OAAA;EACT,SAAA;EACA,aAAA;EACA,UAAA;;EAGA,aAAA;EACA,WAAA;EACA,OAAA;EAhCiB;EAmCjB,OAAA,EAAS,QAAA,CAAS,CAAA;AAAA;AAAA,UAIH,aAAA;EApCL;EAsCV,EAAA,EAAI,WAAA;EACJ,EAAA;EACA,QAAA,EAAU,OAAA,CAAQ,QAAA;EAxCG;EA2CrB,WAAA,EAAa,WAAA;EACb,aAAA,EAAe,aAAA;;EAGf,cAAA;EA9CiB;EAiDjB,WAAA,GAAc,OAAA;EACd,WAAA;EACA,SAAA;AAAA;AAAA,KAGU,aAAA,GAAgB,MAAA,WAGxB,KAAA,EAAO,WAA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