@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.
- package/.turbo/turbo-build.log +17 -14
- package/CHANGELOG.md +19 -0
- package/dist/index.cjs +38 -6
- package/dist/index.d.cts +16 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +16 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +38 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
- package/src/event-listeners.ts +20 -8
- package/src/event-queue.ts +38 -0
- package/src/event-store.ts +4 -1
- package/src/index.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @auriclabs/events-infra@0.
|
|
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
|
[33m[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.[39m
|
|
@@ -7,19 +7,22 @@
|
|
|
7
7
|
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
8
8
|
[34mℹ[39m tsconfig: [34mtsconfig.build.json[39m
|
|
9
9
|
[34mℹ[39m Build start
|
|
10
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.cjs[22m [
|
|
11
|
-
[34mℹ[39m [33m[CJS][39m 1 files, total:
|
|
12
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mindex.d.cts.map [2m0.
|
|
13
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [
|
|
14
|
-
[34mℹ[39m [33m[CJS][39m 2 files, total: 1.
|
|
15
|
-
[33m[PLUGIN_TIMINGS] Warning:[0m Your build spent significant time in
|
|
10
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.cjs[22m [2m2.07 kB[22m [2m│ gzip: 0.96 kB[22m
|
|
11
|
+
[34mℹ[39m [33m[CJS][39m 1 files, total: 2.07 kB
|
|
12
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mindex.d.cts.map [2m0.76 kB[22m [2m│ gzip: 0.33 kB[22m
|
|
13
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [2m1.15 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
14
|
+
[34mℹ[39m [33m[CJS][39m 2 files, total: 1.90 kB
|
|
15
|
+
[33m[PLUGIN_TIMINGS] Warning:[0m 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
|
-
[32m✔[39m Build complete in [
|
|
18
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m1.
|
|
19
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.mjs.map [
|
|
20
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.d.mts.map [2m0.
|
|
21
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [
|
|
22
|
-
[34mℹ[39m [34m[ESM][39m 4 files, total:
|
|
20
|
+
[32m✔[39m Build complete in [32m6241ms[39m
|
|
21
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m1.89 kB[22m [2m│ gzip: 0.90 kB[22m
|
|
22
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.mjs.map [2m4.04 kB[22m [2m│ gzip: 1.65 kB[22m
|
|
23
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.d.mts.map [2m0.76 kB[22m [2m│ gzip: 0.33 kB[22m
|
|
24
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m1.15 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
25
|
+
[34mℹ[39m [34m[ESM][39m 4 files, total: 7.83 kB
|
|
23
26
|
[33m[PLUGIN_TIMINGS] Warning:[0m Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
|
|
24
27
|
|
|
25
|
-
[32m✔[39m Build complete in [
|
|
28
|
+
[32m✔[39m Build complete in [32m6242ms[39m
|
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
|
|
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
|
|
32
|
-
link: [bus, ...listenerQueues],
|
|
33
|
-
environment
|
|
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
|
|
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
|
-
|
|
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
|
package/dist/index.d.cts.map
CHANGED
|
@@ -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;;;
|
|
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
|
|
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
|
-
|
|
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
|
package/dist/index.d.mts.map
CHANGED
|
@@ -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;;;
|
|
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
|
|
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
|
|
31
|
-
link: [bus, ...listenerQueues],
|
|
32
|
-
environment
|
|
39
|
+
handler,
|
|
40
|
+
link: [...bus ? [bus] : [], ...listenerQueues],
|
|
41
|
+
environment
|
|
33
42
|
}, { filters: [{ dynamodb: { NewImage: { itemType: { S: ["event"] } } } }] });
|
|
34
43
|
}
|
|
35
44
|
//#endregion
|
|
36
|
-
|
|
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
|
package/dist/index.mjs.map
CHANGED
|
@@ -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","
|
|
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.
|
|
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
|
},
|
package/src/event-listeners.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
+
}
|
package/src/event-store.ts
CHANGED
|
@@ -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