@auriclabs/events-infra 0.2.0 → 1.0.0

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.2.0 build /home/runner/work/packages/packages/packages/events-infra
2
+ > @auriclabs/events-infra@1.0.0 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,22 @@
7
7
  ℹ entry: src/index.ts
8
8
  ℹ tsconfig: tsconfig.build.json
9
9
  ℹ Build start
10
- ℹ [CJS] dist/index.cjs 1.14 kB │ gzip: 0.57 kB
11
- ℹ [CJS] 1 files, total: 1.14 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
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.
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
+ [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugins. Here is a breakdown:
16
+ - rolldown-plugin-dts:generate (51%)
17
+ - tsdown:external (43%)
18
+ See https://rolldown.rs/options/checks#plugintimings for more details.
16
19
 
17
- ✔ Build complete in 11356ms
18
- ℹ [ESM] dist/index.mjs 1.03 kB │ gzip: 0.54 kB
19
- ℹ [ESM] dist/index.mjs.map 2.18 kB │ gzip: 0.95 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.50 kB
20
+ ✔ Build complete in 6241ms
21
+ ℹ [ESM] dist/index.mjs 1.89 kB │ gzip: 0.90 kB
22
+ ℹ [ESM] dist/index.mjs.map 4.04 kB │ gzip: 1.65 kB
23
+ ℹ [ESM] dist/index.d.mts.map 0.76 kB │ gzip: 0.33 kB
24
+ ℹ [ESM] dist/index.d.mts 1.15 kB │ gzip: 0.43 kB
25
+ ℹ [ESM] 4 files, total: 7.83 kB
23
26
  [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
27
 
25
- ✔ Build complete in 11366ms
28
+ ✔ Build complete in 6242ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @auriclabs/events-infra
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ddd017a: Add createEventQueue helper, make EventBridge bus optional, and bundle a pre-built stream
8
+ handler to eliminate consumer boilerplate.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [ddd017a]
13
+ - @auriclabs/events@0.4.0
14
+
15
+ ## 0.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 9614859: Add tenantId to EventRecord and a tenantIndex GSI on the event store for tenant-scoped
20
+ queries.
21
+
3
22
  ## 0.2.0
4
23
 
5
24
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1,16 +1,21 @@
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, {
5
6
  fields: {
6
7
  pk: "string",
7
- sk: "string"
8
+ sk: "string",
9
+ tenantId: "string"
8
10
  },
9
11
  primaryIndex: {
10
12
  hashKey: "pk",
11
13
  rangeKey: "sk"
12
14
  },
13
- globalIndexes: {},
15
+ globalIndexes: { tenantIndex: {
16
+ hashKey: "tenantId",
17
+ rangeKey: "pk"
18
+ } },
14
19
  stream: "new-and-old-images",
15
20
  transform: { table: {
16
21
  tableClass: "STANDARD_INFREQUENT_ACCESS",
@@ -25,15 +30,42 @@ function createEventBus(name) {
25
30
  }
26
31
  //#endregion
27
32
  //#region src/event-listeners.ts
33
+ const require$1 = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
28
34
  function subscribeEventStream(config) {
29
- 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;
30
39
  table.subscribe("EventStoreTableStream", {
31
- handler: handlerPath,
32
- link: [bus, ...listenerQueues],
33
- environment: { QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)) }
40
+ handler,
41
+ link: [...bus ? [bus] : [], ...listenerQueues],
42
+ environment
34
43
  }, { filters: [{ dynamodb: { NewImage: { itemType: { S: ["event"] } } } }] });
35
44
  }
36
45
  //#endregion
46
+ //#region src/event-queue.ts
47
+ function createEventQueue(name, subscriber, options) {
48
+ const { batchSize = 10, visibilityTimeout = "30 seconds", dlqRetries = 3 } = 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
37
68
  exports.createEventBus = createEventBus;
69
+ exports.createEventQueue = createEventQueue;
38
70
  exports.createEventStore = createEventStore;
39
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,15 +1,20 @@
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, {
4
5
  fields: {
5
6
  pk: "string",
6
- sk: "string"
7
+ sk: "string",
8
+ tenantId: "string"
7
9
  },
8
10
  primaryIndex: {
9
11
  hashKey: "pk",
10
12
  rangeKey: "sk"
11
13
  },
12
- globalIndexes: {},
14
+ globalIndexes: { tenantIndex: {
15
+ hashKey: "tenantId",
16
+ rangeKey: "pk"
17
+ } },
13
18
  stream: "new-and-old-images",
14
19
  transform: { table: {
15
20
  tableClass: "STANDARD_INFREQUENT_ACCESS",
@@ -24,15 +29,41 @@ function createEventBus(name) {
24
29
  }
25
30
  //#endregion
26
31
  //#region src/event-listeners.ts
32
+ const require = createRequire(import.meta.url);
27
33
  function subscribeEventStream(config) {
28
- 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;
29
38
  table.subscribe("EventStoreTableStream", {
30
- handler: handlerPath,
31
- link: [bus, ...listenerQueues],
32
- environment: { QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)) }
39
+ handler,
40
+ link: [...bus ? [bus] : [], ...listenerQueues],
41
+ environment
33
42
  }, { filters: [{ dynamodb: { NewImage: { itemType: { S: ["event"] } } } }] });
34
43
  }
35
44
  //#endregion
36
- export { createEventBus, createEventStore, subscribeEventStream };
45
+ //#region src/event-queue.ts
46
+ function createEventQueue(name, subscriber, options) {
47
+ const { batchSize = 10, visibilityTimeout = "30 seconds", dlqRetries = 3 } = 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 };
37
68
 
38
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 },\n primaryIndex: {\n hashKey: 'pk',\n rangeKey: 'sk',\n },\n globalIndexes: {},\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;GACL;EACD,cAAc;GACZ,SAAS;GACT,UAAU;GACX;EACD,eAAe,EAAE;EACjB,QAAQ;EACR,WAAW,EACT,OAAO;GACL,YAAY;GACZ,GAAG,SAAS,WAAW;GACxB,EACF;EACF,CAAC;;;;ACxBJ,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 = 3 } = 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.2.0",
3
+ "version": "1.0.0",
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.0",
21
22
  "@auriclabs/sst-types": "0.1.0"
22
23
  },
23
24
  "peerDependencies": {
25
+ "@auriclabs/events": "^0.4.0",
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 = 3 } = 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
+ }
@@ -9,12 +9,15 @@ export function createEventStore(name: string, options?: CreateEventStoreOptions
9
9
  fields: {
10
10
  pk: 'string',
11
11
  sk: 'string',
12
+ tenantId: 'string',
12
13
  },
13
14
  primaryIndex: {
14
15
  hashKey: 'pk',
15
16
  rangeKey: 'sk',
16
17
  },
17
- globalIndexes: {},
18
+ globalIndexes: {
19
+ tenantIndex: { hashKey: 'tenantId', rangeKey: 'pk' },
20
+ },
18
21
  stream: 'new-and-old-images',
19
22
  transform: {
20
23
  table: {
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';