@arki/event-sourcing 0.1.0 → 0.1.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.
- package/dist/dot.d.ts +14 -8
- package/dist/dot.d.ts.map +1 -1
- package/dist/dot.js +29 -7
- package/dist/dot.js.map +1 -1
- package/package.json +2 -2
- package/dist/package.json +0 -5
package/dist/dot.d.ts
CHANGED
|
@@ -37,9 +37,20 @@
|
|
|
37
37
|
* load — that is intentional: the adapter only makes sense in a DOT app.
|
|
38
38
|
*/
|
|
39
39
|
import type { EventStore, MessageBus } from '@event-driven-io/emmett';
|
|
40
|
-
import type {
|
|
40
|
+
import type { EmptyShape, Pip } from '@arki/dot/pip';
|
|
41
41
|
import type { CommandHandlerRegistration } from './command.js';
|
|
42
42
|
import type { PostgreSQLProjectionInput } from './event-sourcing-features.js';
|
|
43
|
+
/**
|
|
44
|
+
* Stable error codes thrown by the event-sourcing pip. Exported so consumers
|
|
45
|
+
* and coding agents can match against them — never parse the message.
|
|
46
|
+
*
|
|
47
|
+
* @see packages/dot/docs/principles.md — principle 1.3 ("errors are part
|
|
48
|
+
* of the API") and principle 4 ("agent-discoverable everywhere").
|
|
49
|
+
*/
|
|
50
|
+
export declare const EVENT_SOURCING_PIP_ERROR_CODES: {
|
|
51
|
+
/** boot was called without a configured event-store URL. */
|
|
52
|
+
readonly dbUrlNotConfigured: "EVENT_SOURCING_PIP_E001";
|
|
53
|
+
};
|
|
43
54
|
/**
|
|
44
55
|
* Options for the event-sourcing DOT adapter.
|
|
45
56
|
*/
|
|
@@ -64,11 +75,6 @@ export type EventSourcingDotOptions = {
|
|
|
64
75
|
* `process.env`. If none are set, `boot` throws.
|
|
65
76
|
*/
|
|
66
77
|
readonly dbUrl?: string;
|
|
67
|
-
/**
|
|
68
|
-
* Pip name override. Defaults to `'event-sourcing'`. Use this only
|
|
69
|
-
* when composing multiple event-sourcing scopes inside the same app.
|
|
70
|
-
*/
|
|
71
|
-
readonly name?: string;
|
|
72
78
|
};
|
|
73
79
|
/** Services published by the event-sourcing adapter. */
|
|
74
80
|
export type EventSourcingServices = {
|
|
@@ -83,8 +89,8 @@ export type EventSourcingServices = {
|
|
|
83
89
|
/**
|
|
84
90
|
* Build a DOT pip that opens the event store, wires command handlers
|
|
85
91
|
* into an in-memory message bus, and publishes both as services. The
|
|
86
|
-
* kernel calls `dispose` in reverse
|
|
92
|
+
* kernel calls `dispose` in reverse declaration order to release the
|
|
87
93
|
* underlying PG pool.
|
|
88
94
|
*/
|
|
89
|
-
export declare function eventSourcing(options: EventSourcingDotOptions):
|
|
95
|
+
export declare function eventSourcing(options: EventSourcingDotOptions): Pip<EmptyShape, EventSourcingServices>;
|
|
90
96
|
//# sourceMappingURL=dot.d.ts.map
|
package/dist/dot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dot.d.ts","sourceRoot":"","sources":["../src/dot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"dot.d.ts","sourceRoot":"","sources":["../src/dot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAG9E;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B;IACzC,4DAA4D;;CAEpD,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,yBAAyB,EAAE,CAAC;IAC3D;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,0BAA0B,EAAE,CAAC;IACjE;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,wDAAwD;AACxD,MAAM,MAAM,qBAAqB,GAAG;IAClC,mEAAmE;IACnE,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CACjC,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,uBAAuB,GAAG,GAAG,CAAC,UAAU,EAAE,qBAAqB,CAAC,CA2CtG"}
|
package/dist/dot.js
CHANGED
|
@@ -36,8 +36,19 @@
|
|
|
36
36
|
* Importing this adapter without `@arki/dot` installed will fail at module
|
|
37
37
|
* load — that is intentional: the adapter only makes sense in a DOT app.
|
|
38
38
|
*/
|
|
39
|
-
import {
|
|
39
|
+
import { pip, DotPipError } from '@arki/dot/pip';
|
|
40
40
|
import { EVENT_STORE_URL_VARIANTS, eventSourcingFeatures } from './event-sourcing-features.js';
|
|
41
|
+
/**
|
|
42
|
+
* Stable error codes thrown by the event-sourcing pip. Exported so consumers
|
|
43
|
+
* and coding agents can match against them — never parse the message.
|
|
44
|
+
*
|
|
45
|
+
* @see packages/dot/docs/principles.md — principle 1.3 ("errors are part
|
|
46
|
+
* of the API") and principle 4 ("agent-discoverable everywhere").
|
|
47
|
+
*/
|
|
48
|
+
export const EVENT_SOURCING_PIP_ERROR_CODES = {
|
|
49
|
+
/** boot was called without a configured event-store URL. */
|
|
50
|
+
dbUrlNotConfigured: 'EVENT_SOURCING_PIP_E001',
|
|
51
|
+
};
|
|
41
52
|
/**
|
|
42
53
|
* Resolve the event-store connection URL from explicit options first, then
|
|
43
54
|
* from the recognised env vars in priority order. Returns `undefined` when
|
|
@@ -56,29 +67,40 @@ function resolveDbUrl(explicit) {
|
|
|
56
67
|
/**
|
|
57
68
|
* Build a DOT pip that opens the event store, wires command handlers
|
|
58
69
|
* into an in-memory message bus, and publishes both as services. The
|
|
59
|
-
* kernel calls `dispose` in reverse
|
|
70
|
+
* kernel calls `dispose` in reverse declaration order to release the
|
|
60
71
|
* underlying PG pool.
|
|
61
72
|
*/
|
|
62
73
|
export function eventSourcing(options) {
|
|
63
|
-
const name = options.name ?? 'event-sourcing';
|
|
64
74
|
const commandHandlers = options.commandHandlers ?? [];
|
|
65
75
|
// Captured at boot so dispose can call it without re-reading services
|
|
66
76
|
// (dispose is allowed to run even when services failed to publish).
|
|
67
77
|
let closeStore;
|
|
68
|
-
return
|
|
69
|
-
name,
|
|
78
|
+
return pip({
|
|
79
|
+
name: 'event-sourcing',
|
|
70
80
|
version: '0.1.0',
|
|
71
|
-
provides: ['event-store', 'message-bus'],
|
|
72
81
|
configure(ctx) {
|
|
73
82
|
ctx.registerService('eventStore', 'event-store');
|
|
74
83
|
ctx.registerService('messageBus', 'message-bus');
|
|
84
|
+
ctx.declareProvides('event-store', 'message-bus');
|
|
75
85
|
},
|
|
76
86
|
boot() {
|
|
87
|
+
// Validate at the pip boundary so the DOT lifecycle gets a coded
|
|
88
|
+
// error. `eventSourcingFeatures.initEventSourcing` still throws raw
|
|
89
|
+
// `Error` for non-DOT consumers (its public contract is unchanged);
|
|
90
|
+
// the check here makes sure we never reach it without a URL.
|
|
77
91
|
const dbUrl = resolveDbUrl(options.dbUrl);
|
|
92
|
+
if (dbUrl === undefined) {
|
|
93
|
+
throw new DotPipError({
|
|
94
|
+
code: EVENT_SOURCING_PIP_ERROR_CODES.dbUrlNotConfigured,
|
|
95
|
+
message: '[event-sourcing] Event Store database URL is not configured.',
|
|
96
|
+
remediation: `Pass options.dbUrl to eventSourcing(...) or set one of ${EVENT_STORE_URL_VARIANTS.join(', ')} in the environment before booting the app.`,
|
|
97
|
+
docsUrl: 'https://arki.dev/dot/errors/event-sourcing-pip-e001',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
78
100
|
const { eventStore, close } = eventSourcingFeatures.initEventSourcing(options.projections, dbUrl);
|
|
79
101
|
closeStore = close;
|
|
80
102
|
const messageBus = eventSourcingFeatures.initMessageBus(eventStore, [...commandHandlers]);
|
|
81
|
-
return {
|
|
103
|
+
return { eventStore, messageBus };
|
|
82
104
|
},
|
|
83
105
|
async dispose() {
|
|
84
106
|
if (closeStore !== undefined) {
|
package/dist/dot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dot.js","sourceRoot":"","sources":["../src/dot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAKH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"dot.js","sourceRoot":"","sources":["../src/dot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAKH,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAIjD,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE/F;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,4DAA4D;IAC5D,kBAAkB,EAAE,yBAAyB;CACrC,CAAC;AAuCX;;;;GAIG;AACH,SAAS,YAAY,CAAC,QAA4B;IAChD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,EAAE;QAAE,OAAO,QAAQ,CAAC;IAC/D,KAAK,MAAM,IAAI,IAAI,wBAAwB,EAAE,CAAC;QAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;YAAE,OAAO,KAAK,CA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,KAAK,CAAC,OAAO;YACX,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,MAAM,UAAU,EAAE,CAAC;gBACnB,UAAU,GAAG,SAAS,CAAC;YACzB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arki/event-sourcing",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Event sourcing primitives — event store, message bus, projections, process managers — built on Emmett for ARKI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"drizzle-orm": "1.0.0-rc.1"
|
|
88
88
|
},
|
|
89
89
|
"peerDependencies": {
|
|
90
|
-
"@arki/dot": "^0.1.
|
|
90
|
+
"@arki/dot": "^0.1.1"
|
|
91
91
|
},
|
|
92
92
|
"peerDependenciesMeta": {
|
|
93
93
|
"@arki/dot": {
|