@auriclabs/events-infra 0.1.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.
@@ -0,0 +1,25 @@
1
+
2
+ > @auriclabs/events-infra@0.1.0 build /home/runner/work/packages/packages/packages/events-infra
3
+ > tsdown src/index.ts --format cjs,esm --dts --tsconfig tsconfig.build.json --no-hash
4
+
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.
6
+ ℹ tsdown v0.21.4 powered by rolldown v1.0.0-rc.9
7
+ ℹ entry: src/index.ts
8
+ ℹ tsconfig: tsconfig.build.json
9
+ ℹ Build start
10
+ ℹ [CJS] dist/index.cjs 1.14 kB │ gzip: 0.57 kB
11
+ ℹ [CJS] 1 files, total: 1.14 kB
12
+ ℹ [ESM] dist/index.mjs 1.03 kB │ gzip: 0.54 kB
13
+ ℹ [ESM] dist/index.mjs.map 2.18 kB │ gzip: 0.95 kB
14
+ ℹ [ESM] dist/index.d.mts.map 0.52 kB │ gzip: 0.27 kB
15
+ ℹ [ESM] dist/index.d.mts 0.77 kB │ gzip: 0.33 kB
16
+ ℹ [ESM] 4 files, total: 4.50 kB
17
+ [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
18
+
19
+ ℹ [CJS] dist/index.d.cts.map 0.52 kB │ gzip: 0.27 kB
20
+ ℹ [CJS] dist/index.d.cts 0.77 kB │ gzip: 0.33 kB
21
+ ℹ [CJS] 2 files, total: 1.29 kB
22
+ ✔ Build complete in 11027ms
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
+
25
+ ✔ Build complete in 11028ms
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # @auriclabs/events-infra
2
+
3
+ SST infrastructure helpers for provisioning DynamoDB event stores, EventBridge buses, and DynamoDB stream subscriptions.
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ pnpm add @auriclabs/events-infra
9
+ ```
10
+
11
+ ### Peer dependencies
12
+
13
+ ```bash
14
+ pnpm add sst @auriclabs/sst-types
15
+ ```
16
+
17
+ ## API Reference
18
+
19
+ ### `createEventStore(name, options?)`
20
+
21
+ Creates a DynamoDB table configured for event sourcing with `pk`/`sk` keys, DynamoDB Streams enabled, and `STANDARD_INFREQUENT_ACCESS` storage class.
22
+
23
+ ```typescript
24
+ import { createEventStore } from '@auriclabs/events-infra';
25
+
26
+ export const table = createEventStore('EventStoreTable');
27
+ ```
28
+
29
+ Options:
30
+
31
+ ```typescript
32
+ interface CreateEventStoreOptions {
33
+ transform?: {
34
+ table?: Record<string, unknown>; // Override default table transform
35
+ };
36
+ }
37
+ ```
38
+
39
+ Returns: `sst.aws.Dynamo`
40
+
41
+ ### `createEventBus(name)`
42
+
43
+ Creates an EventBridge bus.
44
+
45
+ ```typescript
46
+ import { createEventBus } from '@auriclabs/events-infra';
47
+
48
+ export const bus = createEventBus('EventBus');
49
+ ```
50
+
51
+ Returns: `sst.aws.Bus`
52
+
53
+ ### `subscribeEventStream(config)`
54
+
55
+ Subscribes a Lambda handler to the DynamoDB event store stream. Filters for `itemType: 'event'` records only (skips HEAD updates). Links the EventBridge bus and all listener queues, and sets the `QUEUE_URL_LIST` environment variable.
56
+
57
+ ```typescript
58
+ import { subscribeEventStream } from '@auriclabs/events-infra';
59
+
60
+ subscribeEventStream({
61
+ table: eventTable,
62
+ bus: eventBus,
63
+ listenerQueues: [crawlerQueue, indexerQueue],
64
+ handlerPath: 'services/event/handlers/event-store-table-stream.handler',
65
+ });
66
+ ```
67
+
68
+ Config:
69
+
70
+ ```typescript
71
+ interface SubscribeEventStreamConfig {
72
+ table: sst.aws.Dynamo;
73
+ bus: sst.aws.Bus;
74
+ listenerQueues: sst.aws.Queue[];
75
+ handlerPath: string; // Lambda handler path
76
+ }
77
+ ```
78
+
79
+ ## Full Example
80
+
81
+ ```typescript
82
+ // infra/event.ts
83
+ import { createEventStore, createEventBus, subscribeEventStream } from '@auriclabs/events-infra';
84
+ import * as services from './services';
85
+
86
+ export const table = createEventStore('EventStoreTable');
87
+ export const bus = createEventBus('EventBus');
88
+
89
+ subscribeEventStream({
90
+ table,
91
+ bus,
92
+ listenerQueues: [
93
+ services.crawler.eventListenerQueue,
94
+ services.indexer.eventListenerQueue,
95
+ ],
96
+ handlerPath: 'services/event/handlers/event-store-table-stream.handler',
97
+ });
98
+ ```
99
+
100
+ The stream handler should use `createStreamHandler()` from `@auriclabs/events`:
101
+
102
+ ```typescript
103
+ // services/event/handlers/event-store-table-stream.ts
104
+ import { createStreamHandler } from '@auriclabs/events';
105
+ import { Resource } from 'sst';
106
+
107
+ export const handler = createStreamHandler({
108
+ busName: Resource.EventBus.name,
109
+ queueUrls: JSON.parse(process.env.QUEUE_URL_LIST ?? '[]'),
110
+ });
111
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,39 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/event-store.ts
3
+ function createEventStore(name, options) {
4
+ return new sst.aws.Dynamo(name, {
5
+ fields: {
6
+ pk: "string",
7
+ sk: "string"
8
+ },
9
+ primaryIndex: {
10
+ hashKey: "pk",
11
+ rangeKey: "sk"
12
+ },
13
+ globalIndexes: {},
14
+ stream: "new-and-old-images",
15
+ transform: { table: {
16
+ tableClass: "STANDARD_INFREQUENT_ACCESS",
17
+ ...options?.transform?.table
18
+ } }
19
+ });
20
+ }
21
+ //#endregion
22
+ //#region src/event-bus.ts
23
+ function createEventBus(name) {
24
+ return new sst.aws.Bus(name);
25
+ }
26
+ //#endregion
27
+ //#region src/event-listeners.ts
28
+ function subscribeEventStream(config) {
29
+ const { table, bus, listenerQueues, handlerPath } = config;
30
+ table.subscribe("EventStoreTableStream", {
31
+ handler: handlerPath,
32
+ link: [bus, ...listenerQueues],
33
+ environment: { QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)) }
34
+ }, { filters: [{ dynamodb: { NewImage: { itemType: { S: ["event"] } } } }] });
35
+ }
36
+ //#endregion
37
+ exports.createEventBus = createEventBus;
38
+ exports.createEventStore = createEventStore;
39
+ exports.subscribeEventStream = subscribeEventStream;
@@ -0,0 +1,22 @@
1
+ //#region src/event-store.d.ts
2
+ interface CreateEventStoreOptions {
3
+ transform?: {
4
+ table?: Record<string, unknown>;
5
+ };
6
+ }
7
+ declare function createEventStore(name: string, options?: CreateEventStoreOptions): sst.aws.Dynamo;
8
+ //#endregion
9
+ //#region src/event-bus.d.ts
10
+ declare function createEventBus(name: string): sst.aws.Bus;
11
+ //#endregion
12
+ //#region src/event-listeners.d.ts
13
+ interface SubscribeEventStreamConfig {
14
+ table: sst.aws.Dynamo;
15
+ bus: sst.aws.Bus;
16
+ listenerQueues: sst.aws.Queue[];
17
+ handlerPath: string;
18
+ }
19
+ declare function subscribeEventStream(config: SubscribeEventStreamConfig): void;
20
+ //#endregion
21
+ export { CreateEventStoreOptions, SubscribeEventStreamConfig, createEventBus, createEventStore, subscribeEventStream };
22
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +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"}
@@ -0,0 +1,22 @@
1
+ //#region src/event-store.d.ts
2
+ interface CreateEventStoreOptions {
3
+ transform?: {
4
+ table?: Record<string, unknown>;
5
+ };
6
+ }
7
+ declare function createEventStore(name: string, options?: CreateEventStoreOptions): sst.aws.Dynamo;
8
+ //#endregion
9
+ //#region src/event-bus.d.ts
10
+ declare function createEventBus(name: string): sst.aws.Bus;
11
+ //#endregion
12
+ //#region src/event-listeners.d.ts
13
+ interface SubscribeEventStreamConfig {
14
+ table: sst.aws.Dynamo;
15
+ bus: sst.aws.Bus;
16
+ listenerQueues: sst.aws.Queue[];
17
+ handlerPath: string;
18
+ }
19
+ declare function subscribeEventStream(config: SubscribeEventStreamConfig): void;
20
+ //#endregion
21
+ export { CreateEventStoreOptions, SubscribeEventStreamConfig, createEventBus, createEventStore, subscribeEventStream };
22
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +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"}
package/dist/index.mjs ADDED
@@ -0,0 +1,38 @@
1
+ //#region src/event-store.ts
2
+ function createEventStore(name, options) {
3
+ return new sst.aws.Dynamo(name, {
4
+ fields: {
5
+ pk: "string",
6
+ sk: "string"
7
+ },
8
+ primaryIndex: {
9
+ hashKey: "pk",
10
+ rangeKey: "sk"
11
+ },
12
+ globalIndexes: {},
13
+ stream: "new-and-old-images",
14
+ transform: { table: {
15
+ tableClass: "STANDARD_INFREQUENT_ACCESS",
16
+ ...options?.transform?.table
17
+ } }
18
+ });
19
+ }
20
+ //#endregion
21
+ //#region src/event-bus.ts
22
+ function createEventBus(name) {
23
+ return new sst.aws.Bus(name);
24
+ }
25
+ //#endregion
26
+ //#region src/event-listeners.ts
27
+ function subscribeEventStream(config) {
28
+ const { table, bus, listenerQueues, handlerPath } = config;
29
+ table.subscribe("EventStoreTableStream", {
30
+ handler: handlerPath,
31
+ link: [bus, ...listenerQueues],
32
+ environment: { QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)) }
33
+ }, { filters: [{ dynamodb: { NewImage: { itemType: { S: ["event"] } } } }] });
34
+ }
35
+ //#endregion
36
+ export { createEventBus, createEventStore, subscribeEventStream };
37
+
38
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@auriclabs/events-infra",
3
+ "version": "0.1.0",
4
+ "description": "SST infrastructure helpers for DynamoDB event stores",
5
+ "prettier": "@auriclabs/prettier-config",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.mts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.mts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "keywords": [],
17
+ "author": "",
18
+ "type": "module",
19
+ "license": "ISC",
20
+ "dependencies": {},
21
+ "devDependencies": {
22
+ "sst": "^4.3.7",
23
+ "@auriclabs/sst-types": "0.1.0"
24
+ },
25
+ "peerDependencies": {
26
+ "@auriclabs/sst-types": "^0.1.0",
27
+ "sst": "^4.3.7"
28
+ },
29
+ "publishConfig": {
30
+ "registry": "https://registry.npmjs.org/"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/auriclabs/packages.git",
35
+ "directory": "packages/events-infra"
36
+ },
37
+ "scripts": {
38
+ "build": "tsdown src/index.ts --format cjs,esm --dts --tsconfig tsconfig.build.json --no-hash",
39
+ "dev": "concurrently \"pnpm build --watch\" \"pnpm:y:watch\"",
40
+ "y:watch": "chokidar dist --initial --silent -c \"yalc publish --push\"",
41
+ "lint": "eslint .",
42
+ "lint:fix": "eslint . --fix",
43
+ "typecheck": "ts-config-typecheck",
44
+ "test": "vitest run --passWithNoTests",
45
+ "test:watch": "vitest"
46
+ }
47
+ }
@@ -0,0 +1,3 @@
1
+ export function createEventBus(name: string) {
2
+ return new sst.aws.Bus(name);
3
+ }
@@ -0,0 +1,32 @@
1
+ export interface SubscribeEventStreamConfig {
2
+ table: sst.aws.Dynamo;
3
+ bus: sst.aws.Bus;
4
+ listenerQueues: sst.aws.Queue[];
5
+ handlerPath: string;
6
+ }
7
+
8
+ export function subscribeEventStream(config: SubscribeEventStreamConfig) {
9
+ const { table, bus, listenerQueues, handlerPath } = config;
10
+
11
+ table.subscribe(
12
+ 'EventStoreTableStream',
13
+ {
14
+ handler: handlerPath,
15
+ link: [bus, ...listenerQueues],
16
+ environment: {
17
+ QUEUE_URL_LIST: $jsonStringify(listenerQueues.map((queue) => queue.url)),
18
+ },
19
+ },
20
+ {
21
+ filters: [
22
+ {
23
+ dynamodb: {
24
+ NewImage: {
25
+ itemType: { S: ['event'] },
26
+ },
27
+ },
28
+ },
29
+ ],
30
+ },
31
+ );
32
+ }
@@ -0,0 +1,26 @@
1
+ export interface CreateEventStoreOptions {
2
+ transform?: {
3
+ table?: Record<string, unknown>;
4
+ };
5
+ }
6
+
7
+ export function createEventStore(name: string, options?: CreateEventStoreOptions) {
8
+ return new sst.aws.Dynamo(name, {
9
+ fields: {
10
+ pk: 'string',
11
+ sk: 'string',
12
+ },
13
+ primaryIndex: {
14
+ hashKey: 'pk',
15
+ rangeKey: 'sk',
16
+ },
17
+ globalIndexes: {},
18
+ stream: 'new-and-old-images',
19
+ transform: {
20
+ table: {
21
+ tableClass: 'STANDARD_INFREQUENT_ACCESS',
22
+ ...options?.transform?.table,
23
+ },
24
+ },
25
+ });
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './event-store';
2
+ export * from './event-bus';
3
+ export * from './event-listeners';
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "@auriclabs/ts-config/node-package",
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "outDir": "dist",
6
+ "composite": true,
7
+ "types": ["@auriclabs/sst-types"]
8
+ },
9
+ "include": ["src/**/*"],
10
+ "exclude": [
11
+ "dist",
12
+ "node_modules",
13
+ "**/*.test.ts",
14
+ "**/*.spec.ts",
15
+ "**/__tests__/**",
16
+ "**/__mocks__/**",
17
+ "vitest.config.ts"
18
+ ]
19
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "files": [],
3
+ "references": [{ "path": "./tsconfig.build.json" }]
4
+ }