@auriclabs/events-infra 0.3.0 → 1.0.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,5 @@
1
1
 
2
- > @auriclabs/events-infra@0.3.0 build /home/runner/work/packages/packages/packages/events-infra
2
+ > @auriclabs/events-infra@1.0.1 build /home/runner/work/packages/packages/packages/events-infra
3
3
  > tsdown src/index.ts --format cjs,esm --dts --tsconfig tsconfig.build.json --no-hash
4
4
 
5
5
  [tsdown] Node.js v20.20.1 is deprecated. Support will be removed in the next minor release. Please upgrade to Node.js 22.18.0 or later.
@@ -7,19 +7,19 @@
7
7
  ℹ entry: src/index.ts
8
8
  ℹ tsconfig: tsconfig.build.json
9
9
  ℹ Build start
10
- ℹ [CJS] dist/index.cjs 1.22 kB │ gzip: 0.59 kB
11
- ℹ [CJS] 1 files, total: 1.22 kB
12
- ℹ [CJS] dist/index.d.cts.map 0.52 kB │ gzip: 0.27 kB
13
- ℹ [CJS] dist/index.d.cts 0.77 kB │ gzip: 0.33 kB
14
- ℹ [CJS] 2 files, total: 1.29 kB
10
+ ℹ [CJS] dist/index.cjs 2.07 kB │ gzip: 0.96 kB
11
+ ℹ [CJS] 1 files, total: 2.07 kB
12
+ ℹ [CJS] dist/index.d.cts.map 0.76 kB │ gzip: 0.33 kB
13
+ ℹ [CJS] dist/index.d.cts 1.15 kB │ gzip: 0.43 kB
14
+ ℹ [CJS] 2 files, total: 1.90 kB
15
15
  [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
16
16
 
17
- ✔ Build complete in 10963ms
18
- ℹ [ESM] dist/index.mjs 1.11 kB │ gzip: 0.56 kB
19
- ℹ [ESM] dist/index.mjs.map 2.32 kB │ gzip: 0.99 kB
20
- ℹ [ESM] dist/index.d.mts.map 0.52 kB │ gzip: 0.27 kB
21
- ℹ [ESM] dist/index.d.mts 0.77 kB │ gzip: 0.33 kB
22
- ℹ [ESM] 4 files, total: 4.72 kB
17
+ ✔ Build complete in 4824ms
18
+ ℹ [ESM] dist/index.mjs 1.89 kB │ gzip: 0.90 kB
19
+ ℹ [ESM] dist/index.mjs.map 4.04 kB │ gzip: 1.64 kB
20
+ ℹ [ESM] dist/index.d.mts.map 0.76 kB │ gzip: 0.33 kB
21
+ ℹ [ESM] dist/index.d.mts 1.15 kB │ gzip: 0.43 kB
22
+ ℹ [ESM] 4 files, total: 7.83 kB
23
23
  [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
24
24
 
25
- ✔ Build complete in 10968ms
25
+ ✔ Build complete in 4826ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @auriclabs/events-infra
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - df1699e: Change default dlqRetries from 3 to 1 in createEventQueue to reduce FIFO message group
8
+ blocking time on failures.
9
+ - Updated dependencies [adb821b]
10
+ - @auriclabs/events@0.4.1
11
+
12
+ ## 1.0.0
13
+
14
+ ### Minor Changes
15
+
16
+ - ddd017a: Add createEventQueue helper, make EventBridge bus optional, and bundle a pre-built stream
17
+ handler to eliminate consumer boilerplate.
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [ddd017a]
22
+ - @auriclabs/events@0.4.0
23
+
3
24
  ## 0.3.0
4
25
 
5
26
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let module$1 = require("module");
2
3
  //#region src/event-store.ts
3
4
  function createEventStore(name, options) {
4
5
  return new sst.aws.Dynamo(name, {
@@ -29,15 +30,42 @@ function createEventBus(name) {
29
30
  }
30
31
  //#endregion
31
32
  //#region src/event-listeners.ts
33
+ const require$1 = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
32
34
  function subscribeEventStream(config) {
33
- const { table, bus, listenerQueues, handlerPath } = config;
35
+ const { table, bus, listenerQueues } = config;
36
+ const handler = require$1.resolve("@auriclabs/events/stream-handler").replace(/\.[^.]+$/, "") + ".handler";
37
+ const environment = { QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)) };
38
+ if (bus) environment.EVENT_BUS_NAME = bus.name;
34
39
  table.subscribe("EventStoreTableStream", {
35
- handler: handlerPath,
36
- link: [bus, ...listenerQueues],
37
- environment: { QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)) }
40
+ handler,
41
+ link: [...bus ? [bus] : [], ...listenerQueues],
42
+ environment
38
43
  }, { filters: [{ dynamodb: { NewImage: { itemType: { S: ["event"] } } } }] });
39
44
  }
40
45
  //#endregion
46
+ //#region src/event-queue.ts
47
+ function createEventQueue(name, subscriber, options) {
48
+ const { batchSize = 10, visibilityTimeout = "30 seconds", dlqRetries = 1 } = options ?? {};
49
+ const dlq = new sst.aws.Queue(`${name}DLQ`, { fifo: true });
50
+ const queue = new sst.aws.Queue(name, {
51
+ fifo: true,
52
+ visibilityTimeout,
53
+ dlq: {
54
+ queue: dlq.arn,
55
+ retry: dlqRetries
56
+ }
57
+ });
58
+ queue.subscribe(subscriber, { batch: {
59
+ size: batchSize,
60
+ partialResponses: true
61
+ } });
62
+ return {
63
+ queue,
64
+ dlq
65
+ };
66
+ }
67
+ //#endregion
41
68
  exports.createEventBus = createEventBus;
69
+ exports.createEventQueue = createEventQueue;
42
70
  exports.createEventStore = createEventStore;
43
71
  exports.subscribeEventStream = subscribeEventStream;
package/dist/index.d.cts CHANGED
@@ -12,11 +12,24 @@ declare function createEventBus(name: string): sst.aws.Bus;
12
12
  //#region src/event-listeners.d.ts
13
13
  interface SubscribeEventStreamConfig {
14
14
  table: sst.aws.Dynamo;
15
- bus: sst.aws.Bus;
15
+ bus?: sst.aws.Bus;
16
16
  listenerQueues: sst.aws.Queue[];
17
- handlerPath: string;
18
17
  }
19
18
  declare function subscribeEventStream(config: SubscribeEventStreamConfig): void;
20
19
  //#endregion
21
- export { CreateEventStoreOptions, SubscribeEventStreamConfig, createEventBus, createEventStore, subscribeEventStream };
20
+ //#region src/event-queue.d.ts
21
+ interface CreateEventQueueOptions {
22
+ batchSize?: number;
23
+ visibilityTimeout?: string;
24
+ dlqRetries?: number;
25
+ }
26
+ declare function createEventQueue(name: string, subscriber: {
27
+ handler: string;
28
+ [key: string]: unknown;
29
+ }, options?: CreateEventQueueOptions): {
30
+ queue: sst.aws.Queue;
31
+ dlq: sst.aws.Queue;
32
+ };
33
+ //#endregion
34
+ export { CreateEventQueueOptions, CreateEventStoreOptions, SubscribeEventStreamConfig, createEventBus, createEventQueue, createEventStore, subscribeEventStream };
22
35
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/event-store.ts","../src/event-bus.ts","../src/event-listeners.ts"],"mappings":";UAAiB,uBAAA;EACf,SAAA;IACE,KAAA,GAAQ,MAAA;EAAA;AAAA;AAAA,iBAII,gBAAA,CAAiB,IAAA,UAAc,OAAA,GAAU,uBAAA,GAAuB,GAAA,CAAA,GAAA,CAAA,MAAA;;;iBCNhE,cAAA,CAAe,IAAA,WAAY,GAAA,CAAA,GAAA,CAAA,GAAA;;;UCA1B,0BAAA;EACf,KAAA,EAAO,GAAA,CAAI,GAAA,CAAI,MAAA;EACf,GAAA,EAAK,GAAA,CAAI,GAAA,CAAI,GAAA;EACb,cAAA,EAAgB,GAAA,CAAI,GAAA,CAAI,KAAA;EACxB,WAAA;AAAA;AAAA,iBAGc,oBAAA,CAAqB,MAAA,EAAQ,0BAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/event-store.ts","../src/event-bus.ts","../src/event-listeners.ts","../src/event-queue.ts"],"mappings":";UAAiB,uBAAA;EACf,SAAA;IACE,KAAA,GAAQ,MAAA;EAAA;AAAA;AAAA,iBAII,gBAAA,CAAiB,IAAA,UAAc,OAAA,GAAU,uBAAA,GAAuB,GAAA,CAAA,GAAA,CAAA,MAAA;;;iBCNhE,cAAA,CAAe,IAAA,WAAY,GAAA,CAAA,GAAA,CAAA,GAAA;;;UCI1B,0BAAA;EACf,KAAA,EAAO,GAAA,CAAI,GAAA,CAAI,MAAA;EACf,GAAA,GAAM,GAAA,CAAI,GAAA,CAAI,GAAA;EACd,cAAA,EAAgB,GAAA,CAAI,GAAA,CAAI,KAAA;AAAA;AAAA,iBAGV,oBAAA,CAAqB,MAAA,EAAQ,0BAAA;;;UCV5B,uBAAA;EACf,SAAA;EACA,iBAAA;EACA,UAAA;AAAA;AAAA,iBAGc,gBAAA,CACd,IAAA,UACA,UAAA;EACE,OAAA;EAAA,CACC,GAAA;AAAA,GAEH,OAAA,GAAU,uBAAA;EACP,KAAA,EAAO,GAAA,CAAI,GAAA,CAAI,KAAA;EAAO,GAAA,EAAK,GAAA,CAAI,GAAA,CAAI,KAAA;AAAA"}
package/dist/index.d.mts CHANGED
@@ -12,11 +12,24 @@ declare function createEventBus(name: string): sst.aws.Bus;
12
12
  //#region src/event-listeners.d.ts
13
13
  interface SubscribeEventStreamConfig {
14
14
  table: sst.aws.Dynamo;
15
- bus: sst.aws.Bus;
15
+ bus?: sst.aws.Bus;
16
16
  listenerQueues: sst.aws.Queue[];
17
- handlerPath: string;
18
17
  }
19
18
  declare function subscribeEventStream(config: SubscribeEventStreamConfig): void;
20
19
  //#endregion
21
- export { CreateEventStoreOptions, SubscribeEventStreamConfig, createEventBus, createEventStore, subscribeEventStream };
20
+ //#region src/event-queue.d.ts
21
+ interface CreateEventQueueOptions {
22
+ batchSize?: number;
23
+ visibilityTimeout?: string;
24
+ dlqRetries?: number;
25
+ }
26
+ declare function createEventQueue(name: string, subscriber: {
27
+ handler: string;
28
+ [key: string]: unknown;
29
+ }, options?: CreateEventQueueOptions): {
30
+ queue: sst.aws.Queue;
31
+ dlq: sst.aws.Queue;
32
+ };
33
+ //#endregion
34
+ export { CreateEventQueueOptions, CreateEventStoreOptions, SubscribeEventStreamConfig, createEventBus, createEventQueue, createEventStore, subscribeEventStream };
22
35
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/event-store.ts","../src/event-bus.ts","../src/event-listeners.ts"],"mappings":";UAAiB,uBAAA;EACf,SAAA;IACE,KAAA,GAAQ,MAAA;EAAA;AAAA;AAAA,iBAII,gBAAA,CAAiB,IAAA,UAAc,OAAA,GAAU,uBAAA,GAAuB,GAAA,CAAA,GAAA,CAAA,MAAA;;;iBCNhE,cAAA,CAAe,IAAA,WAAY,GAAA,CAAA,GAAA,CAAA,GAAA;;;UCA1B,0BAAA;EACf,KAAA,EAAO,GAAA,CAAI,GAAA,CAAI,MAAA;EACf,GAAA,EAAK,GAAA,CAAI,GAAA,CAAI,GAAA;EACb,cAAA,EAAgB,GAAA,CAAI,GAAA,CAAI,KAAA;EACxB,WAAA;AAAA;AAAA,iBAGc,oBAAA,CAAqB,MAAA,EAAQ,0BAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/event-store.ts","../src/event-bus.ts","../src/event-listeners.ts","../src/event-queue.ts"],"mappings":";UAAiB,uBAAA;EACf,SAAA;IACE,KAAA,GAAQ,MAAA;EAAA;AAAA;AAAA,iBAII,gBAAA,CAAiB,IAAA,UAAc,OAAA,GAAU,uBAAA,GAAuB,GAAA,CAAA,GAAA,CAAA,MAAA;;;iBCNhE,cAAA,CAAe,IAAA,WAAY,GAAA,CAAA,GAAA,CAAA,GAAA;;;UCI1B,0BAAA;EACf,KAAA,EAAO,GAAA,CAAI,GAAA,CAAI,MAAA;EACf,GAAA,GAAM,GAAA,CAAI,GAAA,CAAI,GAAA;EACd,cAAA,EAAgB,GAAA,CAAI,GAAA,CAAI,KAAA;AAAA;AAAA,iBAGV,oBAAA,CAAqB,MAAA,EAAQ,0BAAA;;;UCV5B,uBAAA;EACf,SAAA;EACA,iBAAA;EACA,UAAA;AAAA;AAAA,iBAGc,gBAAA,CACd,IAAA,UACA,UAAA;EACE,OAAA;EAAA,CACC,GAAA;AAAA,GAEH,OAAA,GAAU,uBAAA;EACP,KAAA,EAAO,GAAA,CAAI,GAAA,CAAI,KAAA;EAAO,GAAA,EAAK,GAAA,CAAI,GAAA,CAAI,KAAA;AAAA"}
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "module";
1
2
  //#region src/event-store.ts
2
3
  function createEventStore(name, options) {
3
4
  return new sst.aws.Dynamo(name, {
@@ -28,15 +29,41 @@ function createEventBus(name) {
28
29
  }
29
30
  //#endregion
30
31
  //#region src/event-listeners.ts
32
+ const require = createRequire(import.meta.url);
31
33
  function subscribeEventStream(config) {
32
- const { table, bus, listenerQueues, handlerPath } = config;
34
+ const { table, bus, listenerQueues } = config;
35
+ const handler = require.resolve("@auriclabs/events/stream-handler").replace(/\.[^.]+$/, "") + ".handler";
36
+ const environment = { QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)) };
37
+ if (bus) environment.EVENT_BUS_NAME = bus.name;
33
38
  table.subscribe("EventStoreTableStream", {
34
- handler: handlerPath,
35
- link: [bus, ...listenerQueues],
36
- environment: { QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)) }
39
+ handler,
40
+ link: [...bus ? [bus] : [], ...listenerQueues],
41
+ environment
37
42
  }, { filters: [{ dynamodb: { NewImage: { itemType: { S: ["event"] } } } }] });
38
43
  }
39
44
  //#endregion
40
- export { createEventBus, createEventStore, subscribeEventStream };
45
+ //#region src/event-queue.ts
46
+ function createEventQueue(name, subscriber, options) {
47
+ const { batchSize = 10, visibilityTimeout = "30 seconds", dlqRetries = 1 } = options ?? {};
48
+ const dlq = new sst.aws.Queue(`${name}DLQ`, { fifo: true });
49
+ const queue = new sst.aws.Queue(name, {
50
+ fifo: true,
51
+ visibilityTimeout,
52
+ dlq: {
53
+ queue: dlq.arn,
54
+ retry: dlqRetries
55
+ }
56
+ });
57
+ queue.subscribe(subscriber, { batch: {
58
+ size: batchSize,
59
+ partialResponses: true
60
+ } });
61
+ return {
62
+ queue,
63
+ dlq
64
+ };
65
+ }
66
+ //#endregion
67
+ export { createEventBus, createEventQueue, createEventStore, subscribeEventStream };
41
68
 
42
69
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/event-store.ts","../src/event-bus.ts","../src/event-listeners.ts"],"sourcesContent":["export interface CreateEventStoreOptions {\n transform?: {\n table?: Record<string, unknown>;\n };\n}\n\nexport function createEventStore(name: string, options?: CreateEventStoreOptions) {\n return new sst.aws.Dynamo(name, {\n fields: {\n pk: 'string',\n sk: 'string',\n tenantId: 'string',\n },\n primaryIndex: {\n hashKey: 'pk',\n rangeKey: 'sk',\n },\n globalIndexes: {\n tenantIndex: { hashKey: 'tenantId', rangeKey: 'pk' },\n },\n stream: 'new-and-old-images',\n transform: {\n table: {\n tableClass: 'STANDARD_INFREQUENT_ACCESS',\n ...options?.transform?.table,\n },\n },\n });\n}\n","export function createEventBus(name: string) {\n return new sst.aws.Bus(name);\n}\n","export interface SubscribeEventStreamConfig {\n table: sst.aws.Dynamo;\n bus: sst.aws.Bus;\n listenerQueues: sst.aws.Queue[];\n handlerPath: string;\n}\n\nexport function subscribeEventStream(config: SubscribeEventStreamConfig) {\n const { table, bus, listenerQueues, handlerPath } = config;\n\n table.subscribe(\n 'EventStoreTableStream',\n {\n handler: handlerPath,\n link: [bus, ...listenerQueues],\n environment: {\n QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)),\n },\n },\n {\n filters: [\n {\n dynamodb: {\n NewImage: {\n itemType: { S: ['event'] },\n },\n },\n },\n ],\n },\n );\n}\n"],"mappings":";AAMA,SAAgB,iBAAiB,MAAc,SAAmC;AAChF,QAAO,IAAI,IAAI,IAAI,OAAO,MAAM;EAC9B,QAAQ;GACN,IAAI;GACJ,IAAI;GACJ,UAAU;GACX;EACD,cAAc;GACZ,SAAS;GACT,UAAU;GACX;EACD,eAAe,EACb,aAAa;GAAE,SAAS;GAAY,UAAU;GAAM,EACrD;EACD,QAAQ;EACR,WAAW,EACT,OAAO;GACL,YAAY;GACZ,GAAG,SAAS,WAAW;GACxB,EACF;EACF,CAAC;;;;AC3BJ,SAAgB,eAAe,MAAc;AAC3C,QAAO,IAAI,IAAI,IAAI,IAAI,KAAK;;;;ACM9B,SAAgB,qBAAqB,QAAoC;CACvE,MAAM,EAAE,OAAO,KAAK,gBAAgB,gBAAgB;AAEpD,OAAM,UACJ,yBACA;EACE,SAAS;EACT,MAAM,CAAC,KAAK,GAAG,eAAe;EAC9B,aAAa,EACX,gBAAgB,eAAe,eAAe,KAAK,UAAU,MAAM,IAAI,CAAC,EACzE;EACF,EACD,EACE,SAAS,CACP,EACE,UAAU,EACR,UAAU,EACR,UAAU,EAAE,GAAG,CAAC,QAAQ,EAAE,EAC3B,EACF,EACF,CACF,EACF,CACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/event-store.ts","../src/event-bus.ts","../src/event-listeners.ts","../src/event-queue.ts"],"sourcesContent":["export interface CreateEventStoreOptions {\n transform?: {\n table?: Record<string, unknown>;\n };\n}\n\nexport function createEventStore(name: string, options?: CreateEventStoreOptions) {\n return new sst.aws.Dynamo(name, {\n fields: {\n pk: 'string',\n sk: 'string',\n tenantId: 'string',\n },\n primaryIndex: {\n hashKey: 'pk',\n rangeKey: 'sk',\n },\n globalIndexes: {\n tenantIndex: { hashKey: 'tenantId', rangeKey: 'pk' },\n },\n stream: 'new-and-old-images',\n transform: {\n table: {\n tableClass: 'STANDARD_INFREQUENT_ACCESS',\n ...options?.transform?.table,\n },\n },\n });\n}\n","export function createEventBus(name: string) {\n return new sst.aws.Bus(name);\n}\n","import { createRequire } from 'module';\n\nconst require = createRequire(import.meta.url);\n\nexport interface SubscribeEventStreamConfig {\n table: sst.aws.Dynamo;\n bus?: sst.aws.Bus;\n listenerQueues: sst.aws.Queue[];\n}\n\nexport function subscribeEventStream(config: SubscribeEventStreamConfig) {\n const { table, bus, listenerQueues } = config;\n\n const streamHandlerPath = require.resolve('@auriclabs/events/stream-handler');\n const handler = streamHandlerPath.replace(/\\.[^.]+$/, '') + '.handler';\n\n const environment: Record<string, $util.Input<string>> = {\n QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)),\n };\n\n if (bus) {\n environment.EVENT_BUS_NAME = bus.name;\n }\n\n table.subscribe(\n 'EventStoreTableStream',\n {\n handler,\n link: [...(bus ? [bus] : []), ...listenerQueues],\n environment,\n },\n {\n filters: [\n {\n dynamodb: {\n NewImage: {\n itemType: { S: ['event'] },\n },\n },\n },\n ],\n },\n );\n}\n","export interface CreateEventQueueOptions {\n batchSize?: number;\n visibilityTimeout?: string;\n dlqRetries?: number;\n}\n\nexport function createEventQueue(\n name: string,\n subscriber: {\n handler: string;\n [key: string]: unknown;\n },\n options?: CreateEventQueueOptions,\n): { queue: sst.aws.Queue; dlq: sst.aws.Queue } {\n const { batchSize = 10, visibilityTimeout = '30 seconds', dlqRetries = 1 } = options ?? {};\n\n const dlq = new sst.aws.Queue(`${name}DLQ`, {\n fifo: true,\n });\n\n const queue = new sst.aws.Queue(name, {\n fifo: true,\n visibilityTimeout,\n dlq: {\n queue: dlq.arn,\n retry: dlqRetries,\n },\n });\n\n queue.subscribe(subscriber, {\n batch: {\n size: batchSize,\n partialResponses: true,\n },\n });\n\n return { queue, dlq };\n}\n"],"mappings":";;AAMA,SAAgB,iBAAiB,MAAc,SAAmC;AAChF,QAAO,IAAI,IAAI,IAAI,OAAO,MAAM;EAC9B,QAAQ;GACN,IAAI;GACJ,IAAI;GACJ,UAAU;GACX;EACD,cAAc;GACZ,SAAS;GACT,UAAU;GACX;EACD,eAAe,EACb,aAAa;GAAE,SAAS;GAAY,UAAU;GAAM,EACrD;EACD,QAAQ;EACR,WAAW,EACT,OAAO;GACL,YAAY;GACZ,GAAG,SAAS,WAAW;GACxB,EACF;EACF,CAAC;;;;AC3BJ,SAAgB,eAAe,MAAc;AAC3C,QAAO,IAAI,IAAI,IAAI,IAAI,KAAK;;;;ACC9B,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAQ9C,SAAgB,qBAAqB,QAAoC;CACvE,MAAM,EAAE,OAAO,KAAK,mBAAmB;CAGvC,MAAM,UADoB,QAAQ,QAAQ,mCAAmC,CAC3C,QAAQ,YAAY,GAAG,GAAG;CAE5D,MAAM,cAAmD,EACvD,gBAAgB,eAAe,eAAe,KAAK,UAAU,MAAM,IAAI,CAAC,EACzE;AAED,KAAI,IACF,aAAY,iBAAiB,IAAI;AAGnC,OAAM,UACJ,yBACA;EACE;EACA,MAAM,CAAC,GAAI,MAAM,CAAC,IAAI,GAAG,EAAE,EAAG,GAAG,eAAe;EAChD;EACD,EACD,EACE,SAAS,CACP,EACE,UAAU,EACR,UAAU,EACR,UAAU,EAAE,GAAG,CAAC,QAAQ,EAAE,EAC3B,EACF,EACF,CACF,EACF,CACF;;;;ACpCH,SAAgB,iBACd,MACA,YAIA,SAC8C;CAC9C,MAAM,EAAE,YAAY,IAAI,oBAAoB,cAAc,aAAa,MAAM,WAAW,EAAE;CAE1F,MAAM,MAAM,IAAI,IAAI,IAAI,MAAM,GAAG,KAAK,MAAM,EAC1C,MAAM,MACP,CAAC;CAEF,MAAM,QAAQ,IAAI,IAAI,IAAI,MAAM,MAAM;EACpC,MAAM;EACN;EACA,KAAK;GACH,OAAO,IAAI;GACX,OAAO;GACR;EACF,CAAC;AAEF,OAAM,UAAU,YAAY,EAC1B,OAAO;EACL,MAAM;EACN,kBAAkB;EACnB,EACF,CAAC;AAEF,QAAO;EAAE;EAAO;EAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auriclabs/events-infra",
3
- "version": "0.3.0",
3
+ "version": "1.0.1",
4
4
  "description": "SST infrastructure helpers for DynamoDB event stores",
5
5
  "prettier": "@auriclabs/prettier-config",
6
6
  "main": "src/index.ts",
@@ -18,9 +18,11 @@
18
18
  "dependencies": {},
19
19
  "devDependencies": {
20
20
  "sst": "^4.3.7",
21
+ "@auriclabs/events": "0.4.1",
21
22
  "@auriclabs/sst-types": "0.1.0"
22
23
  },
23
24
  "peerDependencies": {
25
+ "@auriclabs/events": "^0.4.1",
24
26
  "@auriclabs/sst-types": "^0.1.0",
25
27
  "sst": "^4.3.7"
26
28
  },
@@ -1,21 +1,33 @@
1
+ import { createRequire } from 'module';
2
+
3
+ const require = createRequire(import.meta.url);
4
+
1
5
  export interface SubscribeEventStreamConfig {
2
6
  table: sst.aws.Dynamo;
3
- bus: sst.aws.Bus;
7
+ bus?: sst.aws.Bus;
4
8
  listenerQueues: sst.aws.Queue[];
5
- handlerPath: string;
6
9
  }
7
10
 
8
11
  export function subscribeEventStream(config: SubscribeEventStreamConfig) {
9
- const { table, bus, listenerQueues, handlerPath } = config;
12
+ const { table, bus, listenerQueues } = config;
13
+
14
+ const streamHandlerPath = require.resolve('@auriclabs/events/stream-handler');
15
+ const handler = streamHandlerPath.replace(/\.[^.]+$/, '') + '.handler';
16
+
17
+ const environment: Record<string, $util.Input<string>> = {
18
+ QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)),
19
+ };
20
+
21
+ if (bus) {
22
+ environment.EVENT_BUS_NAME = bus.name;
23
+ }
10
24
 
11
25
  table.subscribe(
12
26
  'EventStoreTableStream',
13
27
  {
14
- handler: handlerPath,
15
- link: [bus, ...listenerQueues],
16
- environment: {
17
- QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)),
18
- },
28
+ handler,
29
+ link: [...(bus ? [bus] : []), ...listenerQueues],
30
+ environment,
19
31
  },
20
32
  {
21
33
  filters: [
@@ -0,0 +1,38 @@
1
+ export interface CreateEventQueueOptions {
2
+ batchSize?: number;
3
+ visibilityTimeout?: string;
4
+ dlqRetries?: number;
5
+ }
6
+
7
+ export function createEventQueue(
8
+ name: string,
9
+ subscriber: {
10
+ handler: string;
11
+ [key: string]: unknown;
12
+ },
13
+ options?: CreateEventQueueOptions,
14
+ ): { queue: sst.aws.Queue; dlq: sst.aws.Queue } {
15
+ const { batchSize = 10, visibilityTimeout = '30 seconds', dlqRetries = 1 } = options ?? {};
16
+
17
+ const dlq = new sst.aws.Queue(`${name}DLQ`, {
18
+ fifo: true,
19
+ });
20
+
21
+ const queue = new sst.aws.Queue(name, {
22
+ fifo: true,
23
+ visibilityTimeout,
24
+ dlq: {
25
+ queue: dlq.arn,
26
+ retry: dlqRetries,
27
+ },
28
+ });
29
+
30
+ queue.subscribe(subscriber, {
31
+ batch: {
32
+ size: batchSize,
33
+ partialResponses: true,
34
+ },
35
+ });
36
+
37
+ return { queue, dlq };
38
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './event-store';
2
2
  export * from './event-bus';
3
3
  export * from './event-listeners';
4
+ export * from './event-queue';