@kronos-ts/messaging 0.1.1 → 0.3.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/dist/command-handler.d.ts +15 -15
- package/dist/command-handler.d.ts.map +1 -1
- package/dist/command-handler.js.map +1 -1
- package/dist/command-handling-module.js +2 -2
- package/dist/command-handling-module.js.map +1 -1
- package/dist/dead-lettering-handler.js +1 -1
- package/dist/dead-lettering-handler.js.map +1 -1
- package/dist/emit-update.d.ts +2 -1
- package/dist/emit-update.d.ts.map +1 -1
- package/dist/emit-update.js.map +1 -1
- package/dist/event-handler.d.ts +5 -5
- package/dist/event-handler.d.ts.map +1 -1
- package/dist/event-handler.js +2 -2
- package/dist/event-handler.js.map +1 -1
- package/dist/event-processor-builder.d.ts +3 -3
- package/dist/event-processor-builder.js +3 -3
- package/dist/event-scheduler.d.ts +95 -0
- package/dist/event-scheduler.d.ts.map +1 -0
- package/dist/event-scheduler.js +47 -0
- package/dist/event-scheduler.js.map +1 -0
- package/dist/gateway.d.ts +7 -5
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +9 -12
- package/dist/gateway.js.map +1 -1
- package/dist/handler.d.ts +13 -13
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js.map +1 -1
- package/dist/in-memory-event-scheduler.d.ts +45 -0
- package/dist/in-memory-event-scheduler.d.ts.map +1 -0
- package/dist/in-memory-event-scheduler.js +112 -0
- package/dist/in-memory-event-scheduler.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/intercepting-command-bus.d.ts +1 -1
- package/dist/intercepting-command-bus.d.ts.map +1 -1
- package/dist/intercepting-command-bus.js +3 -4
- package/dist/intercepting-command-bus.js.map +1 -1
- package/dist/intercepting-query-bus.d.ts +1 -1
- package/dist/intercepting-query-bus.d.ts.map +1 -1
- package/dist/intercepting-query-bus.js +3 -4
- package/dist/intercepting-query-bus.js.map +1 -1
- package/dist/interceptor.d.ts +18 -3
- package/dist/interceptor.d.ts.map +1 -1
- package/dist/message.d.ts +4 -0
- package/dist/message.d.ts.map +1 -1
- package/dist/query-bus.d.ts +8 -3
- package/dist/query-bus.d.ts.map +1 -1
- package/dist/query-handler.d.ts +5 -5
- package/dist/query-handler.d.ts.map +1 -1
- package/dist/query-handler.js +2 -2
- package/dist/query-handler.js.map +1 -1
- package/dist/query-handling-module.js +1 -1
- package/dist/query-handling-module.js.map +1 -1
- package/dist/simple-command-bus.d.ts +11 -4
- package/dist/simple-command-bus.d.ts.map +1 -1
- package/dist/simple-command-bus.js +16 -10
- package/dist/simple-command-bus.js.map +1 -1
- package/dist/simple-query-bus.d.ts.map +1 -1
- package/dist/simple-query-bus.js +4 -3
- package/dist/simple-query-bus.js.map +1 -1
- package/dist/streaming-event-processor.js +1 -1
- package/dist/streaming-event-processor.js.map +1 -1
- package/dist/subscribing-event-processor.js +1 -1
- package/dist/subscribing-event-processor.js.map +1 -1
- package/dist/subscription-filter.d.ts +43 -0
- package/dist/subscription-filter.d.ts.map +1 -0
- package/dist/subscription-filter.js +71 -0
- package/dist/subscription-filter.js.map +1 -0
- package/dist/tracking-event-processor.js +1 -1
- package/dist/tracking-event-processor.js.map +1 -1
- package/dist/transaction.d.ts +31 -0
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +80 -0
- package/dist/transaction.js.map +1 -1
- package/package.json +1 -1
- package/src/command-handler.ts +15 -28
- package/src/command-handling-module.ts +2 -2
- package/src/dead-lettering-handler.ts +1 -1
- package/src/emit-update.ts +3 -2
- package/src/event-handler.ts +5 -8
- package/src/event-processor-builder.ts +3 -3
- package/src/event-scheduler.ts +96 -0
- package/src/gateway.ts +14 -22
- package/src/handler.ts +13 -22
- package/src/in-memory-event-scheduler.ts +150 -0
- package/src/index.ts +23 -1
- package/src/intercepting-command-bus.ts +7 -6
- package/src/intercepting-query-bus.ts +11 -9
- package/src/interceptor.ts +21 -4
- package/src/message.ts +5 -0
- package/src/query-bus.ts +8 -3
- package/src/query-handler.ts +5 -5
- package/src/query-handling-module.ts +1 -1
- package/src/simple-command-bus.ts +17 -11
- package/src/simple-query-bus.ts +8 -6
- package/src/streaming-event-processor.ts +1 -1
- package/src/subscribing-event-processor.ts +1 -1
- package/src/subscription-filter.ts +85 -0
- package/src/tracking-event-processor.ts +1 -1
- package/src/transaction.ts +84 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
-
import type { Metadata } from "@kronos-ts/common";
|
|
3
2
|
import type { CommandDescriptor } from "./descriptor.js";
|
|
4
3
|
import type { EventCriteria } from "./event-criteria.js";
|
|
4
|
+
import type { CommandMessage } from "./message.js";
|
|
5
5
|
/**
|
|
6
6
|
* A registered command handler — pairs a command descriptor with its handler function.
|
|
7
7
|
* When the descriptor has a result schema, the handler must return that type.
|
|
@@ -9,17 +9,17 @@ import type { EventCriteria } from "./event-criteria.js";
|
|
|
9
9
|
export interface CommandHandlerDefinition<P extends z.ZodType = z.ZodType, R extends z.ZodType | undefined = undefined> {
|
|
10
10
|
readonly kind: "command-handler";
|
|
11
11
|
readonly descriptor: CommandDescriptor<P, R>;
|
|
12
|
-
readonly handler: (
|
|
13
|
-
readonly appendCondition?: (
|
|
12
|
+
readonly handler: (message: CommandMessage<z.infer<P>>) => R extends z.ZodType ? Promise<z.infer<R>> | z.infer<R> : Promise<void> | void;
|
|
13
|
+
readonly appendCondition?: (message: CommandMessage<z.infer<P>>, sourcedCriteria: EventCriteria) => EventCriteria;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Defines a command handler.
|
|
17
17
|
*
|
|
18
18
|
* Void command (no result on descriptor):
|
|
19
19
|
* ```
|
|
20
|
-
* commandHandler(ChangeCourseCapacity, async (
|
|
21
|
-
* const course = await load(Course,
|
|
22
|
-
* append(CourseCapacityChanged, { courseId:
|
|
20
|
+
* commandHandler(ChangeCourseCapacity, async ({ payload, metadata }) => {
|
|
21
|
+
* const course = await load(Course, { courseId: payload.courseId })
|
|
22
|
+
* append(CourseCapacityChanged, { courseId: payload.courseId, capacity: payload.capacity })
|
|
23
23
|
* })
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
@@ -31,28 +31,28 @@ export interface CommandHandlerDefinition<P extends z.ZodType = z.ZodType, R ext
|
|
|
31
31
|
* result: z.object({ courseId: z.string() }),
|
|
32
32
|
* })
|
|
33
33
|
*
|
|
34
|
-
* commandHandler(CreateCourse, async (
|
|
34
|
+
* commandHandler(CreateCourse, async ({ payload, metadata }) => {
|
|
35
35
|
* append(CourseCreated, { ... })
|
|
36
|
-
* return { courseId:
|
|
36
|
+
* return { courseId: payload.courseId } // ← must match descriptor's result schema
|
|
37
37
|
* })
|
|
38
38
|
* ```
|
|
39
39
|
*
|
|
40
40
|
* With append condition override:
|
|
41
41
|
* ```
|
|
42
42
|
* commandHandler(CreateCourse, {
|
|
43
|
-
* handler: async (
|
|
43
|
+
* handler: async ({ payload, metadata }) => { ... },
|
|
44
44
|
* appendCondition: (command, criteria) => criteria,
|
|
45
45
|
* })
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
|
-
export declare function commandHandler<P extends z.ZodType>(descriptor: CommandDescriptor<P, undefined>, handler: (
|
|
49
|
-
export declare function commandHandler<P extends z.ZodType, R extends z.ZodType>(descriptor: CommandDescriptor<P, R>, handler: (
|
|
48
|
+
export declare function commandHandler<P extends z.ZodType>(descriptor: CommandDescriptor<P, undefined>, handler: (message: CommandMessage<z.infer<P>>) => Promise<void> | void): CommandHandlerDefinition<P, undefined>;
|
|
49
|
+
export declare function commandHandler<P extends z.ZodType, R extends z.ZodType>(descriptor: CommandDescriptor<P, R>, handler: (message: CommandMessage<z.infer<P>>) => Promise<z.infer<R>> | z.infer<R>): CommandHandlerDefinition<P, R>;
|
|
50
50
|
export declare function commandHandler<P extends z.ZodType>(descriptor: CommandDescriptor<P, undefined>, options: {
|
|
51
|
-
handler: (
|
|
52
|
-
appendCondition?: (
|
|
51
|
+
handler: (message: CommandMessage<z.infer<P>>) => Promise<void> | void;
|
|
52
|
+
appendCondition?: (message: CommandMessage<z.infer<P>>, sourcedCriteria: EventCriteria) => EventCriteria;
|
|
53
53
|
}): CommandHandlerDefinition<P, undefined>;
|
|
54
54
|
export declare function commandHandler<P extends z.ZodType, R extends z.ZodType>(descriptor: CommandDescriptor<P, R>, options: {
|
|
55
|
-
handler: (
|
|
56
|
-
appendCondition?: (
|
|
55
|
+
handler: (message: CommandMessage<z.infer<P>>) => Promise<z.infer<R>> | z.infer<R>;
|
|
56
|
+
appendCondition?: (message: CommandMessage<z.infer<P>>, sourcedCriteria: EventCriteria) => EventCriteria;
|
|
57
57
|
}): CommandHandlerDefinition<P, R>;
|
|
58
58
|
//# sourceMappingURL=command-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-handler.d.ts","sourceRoot":"","sources":["../src/command-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"command-handler.d.ts","sourceRoot":"","sources":["../src/command-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD;;;GAGG;AACH,MAAM,WAAW,wBAAwB,CACvC,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,EAC/B,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS;IAE3C,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAA;IAChC,QAAQ,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,CAAC,CAAC,CAAA;AAEjC,wBAAgB,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAChD,UAAU,EAAE,iBAAiB,CAAC,CAAC,EAAE,SAAS,CAAC,EAC3C,OAAO,EAAE;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACtE,eAAe,CAAC,EAAE,CAChB,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACnC,eAAe,EAAE,aAAa,KAC3B,aAAa,CAAA;CACnB,GACA,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;AAEzC,wBAAgB,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,OAAO,EACrE,UAAU,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,EACnC,OAAO,EAAE;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAClF,eAAe,CAAC,EAAE,CAChB,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACnC,eAAe,EAAE,aAAa,KAC3B,aAAa,CAAA;CACnB,GACA,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-handler.js","sourceRoot":"","sources":["../src/command-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"command-handler.js","sourceRoot":"","sources":["../src/command-handler.ts"],"names":[],"mappings":"AAyFA,MAAM,UAAU,cAAc,CAC5B,UAA6B,EAC7B,gBAAqB;IAErB,IAAI,OAAO,gBAAgB,KAAK,UAAU,EAAE,CAAC;QAC3C,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAA;IAC3E,CAAC;IACD,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,UAAU;QACV,OAAO,EAAE,gBAAgB,CAAC,OAAO;QACjC,eAAe,EAAE,gBAAgB,CAAC,eAAe;KAClD,CAAA;AACH,CAAC"}
|
|
@@ -82,7 +82,7 @@ export function createCommandInvocation(handler, config) {
|
|
|
82
82
|
: { kind: "either", criteria: sourcingInfos.map((s) => s.criteria) };
|
|
83
83
|
const maxMarker = sourcingInfos.reduce((max, s) => s.markerPosition > max ? s.markerPosition : max, -1n);
|
|
84
84
|
const finalCriteria = handler.appendCondition
|
|
85
|
-
? handler.appendCondition(message
|
|
85
|
+
? handler.appendCondition(message, combinedCriteria)
|
|
86
86
|
: combinedCriteria;
|
|
87
87
|
appendCondition = {
|
|
88
88
|
criteria: finalCriteria,
|
|
@@ -92,7 +92,7 @@ export function createCommandInvocation(handler, config) {
|
|
|
92
92
|
await eventStore.append(resolvedEvents, appendCondition);
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
return handler.handler(message
|
|
95
|
+
return handler.handler(message);
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-handling-module.js","sourceRoot":"","sources":["../src/command-handling-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAmBtE;;;;GAIG;AACH,MAAM,uBAAuB,GAAG;IAC9B,aAAa,EAAE,cAAc;IAC7B,WAAW,EAAE,YAAY;IACzB,SAAS,EAAE,UAAU;IACrB,WAAW,EAAE,YAAY;IACzB,YAAY,EAAE,aAAa;C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AAW,CAAC,UAAU,EAAE;gBACxD,WAAW,EAAE,SAAS;gBACtB,WAAW,EAAE,WAAW;gBACxB,YAAY,EAAE,UAAU;aACzB,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;IACpD,CAAC;AACH,CAAC"}
|
|
@@ -32,7 +32,7 @@ export function createDeadLetteringDelivery(options) {
|
|
|
32
32
|
// Try to deliver to all handlers
|
|
33
33
|
for (const reg of handlers) {
|
|
34
34
|
try {
|
|
35
|
-
await reg.handler(event
|
|
35
|
+
await reg.handler({ ...event, sequence: sequencedEvent.sequence });
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
|
38
38
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dead-lettering-handler.js","sourceRoot":"","sources":["../src/dead-lettering-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAIzD,OAAO,EAGL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,wBAAwB,CAAA;AAkB/B;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAA6B;IACvE,MAAM,EACJ,KAAK,EACL,MAAM,GAAG,mBAAmB,EAAE,EAC9B,kBAAkB,GAAG,yBAAyB,GAC/C,GAAG,OAAO,CAAA;IAEX,OAAO;QACL;;;;;;WAMG;QACH,KAAK,CAAC,OAAO,CACX,cAA8B,EAC9B,QAA8C;YAE9C,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAA;YAClC,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAA;YAEvC,kEAAkE;YAClE,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,gBAAgB,CAC1C,KAAK,EACL,GAAG,EAAE,CAAC,gBAAgB,CACpB,KAAK,EACL,IAAI,KAAK,CAAC,4CAA4C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AAC,CAAC,CAAE,CAAC,KAAK,CAAA;IAC7B,CAAC;IACD,OAAO,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC1C,CAAC"}
|
package/dist/emit-update.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ import type { z } from "zod";
|
|
|
2
2
|
import { type ResourceKey } from "@kronos-ts/common";
|
|
3
3
|
import type { QueryBus } from "./query-bus.js";
|
|
4
4
|
import type { QueryDescriptor } from "./descriptor.js";
|
|
5
|
+
import type { SubscriptionFilter } from "./subscription-filter.js";
|
|
5
6
|
/** Emit a subscription-query update from within the current processing context. */
|
|
6
7
|
export interface EmitUpdateFunction {
|
|
7
|
-
<Q extends z.ZodType>(query: QueryDescriptor<Q>, filter:
|
|
8
|
+
<Q extends z.ZodType>(query: QueryDescriptor<Q>, filter: SubscriptionFilter<z.infer<Q>>, update: unknown): void;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Resource key for the query bus component.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-update.d.ts","sourceRoot":"","sources":["../src/emit-update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,EAAsC,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAExF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"emit-update.d.ts","sourceRoot":"","sources":["../src/emit-update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,EAAsC,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAExF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,mFAAmF;AACnF,MAAM,WAAW,kBAAkB;IACjC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAClB,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACtC,MAAM,EAAE,OAAO,GACd,IAAI,CAAA;CACR;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,QAAQ,CAA2B,CAAA;AAE3E;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,kBAMxB,CAAA"}
|
package/dist/emit-update.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-update.js","sourceRoot":"","sources":["../src/emit-update.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAoB,MAAM,mBAAmB,CAAA;AACxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"emit-update.js","sourceRoot":"","sources":["../src/emit-update.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAoB,MAAM,mBAAmB,CAAA;AACxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAc9D;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAA0B,WAAW,CAAC,UAAU,CAAC,CAAA;AAE3E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAuB,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;IAChF,MAAM,KAAK,GAAG,sBAAsB,EAAE,CAAA,CAAC,qBAAqB;IAC5D,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAyB,CAAA;IAC7E,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IACpD,MAAM,SAAS,GAAG,qBAAqB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;IAC7D,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE,MAA4B,EAAE,MAAM,CAAC,CAAA;AACjE,CAAC,CAAA"}
|
package/dist/event-handler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
-
import type { Metadata } from "@kronos-ts/common";
|
|
3
2
|
import type { EventDescriptor } from "./descriptor.js";
|
|
3
|
+
import type { SequencedEventMessage } from "./message.js";
|
|
4
4
|
/**
|
|
5
5
|
* A registered singular event handler — pairs an event descriptor with its handler
|
|
6
6
|
* function. Mirrors {@link import("./command-handler.js").CommandHandlerDefinition}
|
|
@@ -10,14 +10,14 @@ import type { EventDescriptor } from "./descriptor.js";
|
|
|
10
10
|
export interface EventHandlerDefinition<P extends z.ZodType = z.ZodType> {
|
|
11
11
|
readonly kind: "event-handler";
|
|
12
12
|
readonly descriptor: EventDescriptor<P>;
|
|
13
|
-
readonly handler: (
|
|
13
|
+
readonly handler: (message: SequencedEventMessage<z.infer<P>>) => Promise<void> | void;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Defines a singular event handler.
|
|
17
17
|
*
|
|
18
18
|
* ```
|
|
19
|
-
* const onCourseCreated = eventHandler(CourseCreated, async (
|
|
20
|
-
* await db.courses.insert({ id:
|
|
19
|
+
* const onCourseCreated = eventHandler(CourseCreated, async ({ payload, metadata, timestamp }) => {
|
|
20
|
+
* await db.courses.insert({ id: payload.courseId, name: payload.name, createdAt: timestamp })
|
|
21
21
|
* })
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
@@ -26,5 +26,5 @@ export interface EventHandlerDefinition<P extends z.ZodType = z.ZodType> {
|
|
|
26
26
|
* {@link import("./command-handler.js").commandHandler} and
|
|
27
27
|
* {@link import("./query-handler.js").queryHandler}.
|
|
28
28
|
*/
|
|
29
|
-
export declare function eventHandler<P extends z.ZodType>(descriptor: EventDescriptor<P>, handler: (
|
|
29
|
+
export declare function eventHandler<P extends z.ZodType>(descriptor: EventDescriptor<P>, handler: (message: SequencedEventMessage<z.infer<P>>) => Promise<void> | void): EventHandlerDefinition<P>;
|
|
30
30
|
//# sourceMappingURL=event-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handler.d.ts","sourceRoot":"","sources":["../src/event-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"event-handler.d.ts","sourceRoot":"","sources":["../src/event-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAOzD;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO;IACrE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;IAC9B,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,CAAA;IACvC,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACvF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAC9C,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,EAC9B,OAAO,EAAE,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAC5E,sBAAsB,CAAC,CAAC,CAAC,CAE3B"}
|
package/dist/event-handler.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Defines a singular event handler.
|
|
3
3
|
*
|
|
4
4
|
* ```
|
|
5
|
-
* const onCourseCreated = eventHandler(CourseCreated, async (
|
|
6
|
-
* await db.courses.insert({ id:
|
|
5
|
+
* const onCourseCreated = eventHandler(CourseCreated, async ({ payload, metadata, timestamp }) => {
|
|
6
|
+
* await db.courses.insert({ id: payload.courseId, name: payload.name, createdAt: timestamp })
|
|
7
7
|
* })
|
|
8
8
|
* ```
|
|
9
9
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handler.js","sourceRoot":"","sources":["../src/event-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-handler.js","sourceRoot":"","sources":["../src/event-handler.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAC1B,UAA8B,EAC9B,OAA6E;IAE7E,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,OAAO,EAAE,CAAA;AACvD,CAAC"}
|
|
@@ -51,8 +51,8 @@ export type EventProcessorModule = TrackingProcessorModule | SubscribingProcesso
|
|
|
51
51
|
* position via a token store, and support replay/reset.
|
|
52
52
|
*
|
|
53
53
|
* ```typescript
|
|
54
|
-
* const onCreated = eventHandler(CourseCreated, async (e) => { ... })
|
|
55
|
-
* const onCapChanged = eventHandler(CourseCapacityChanged, async (e) => { ... })
|
|
54
|
+
* const onCreated = eventHandler(CourseCreated, async ({ payload: e }) => { ... })
|
|
55
|
+
* const onCapChanged = eventHandler(CourseCapacityChanged, async ({ payload: e }) => { ... })
|
|
56
56
|
*
|
|
57
57
|
* trackingProcessor("course-projection")
|
|
58
58
|
* .eventHandlers(onCreated, onCapChanged)
|
|
@@ -113,7 +113,7 @@ export declare class TrackingProcessorBuilder {
|
|
|
113
113
|
* as they are appended. No token store, no position tracking, no replay.
|
|
114
114
|
*
|
|
115
115
|
* ```typescript
|
|
116
|
-
* const onNotification = eventHandler(NotificationRaised, async (e) => { ... })
|
|
116
|
+
* const onNotification = eventHandler(NotificationRaised, async ({ payload: e }) => { ... })
|
|
117
117
|
*
|
|
118
118
|
* subscribingProcessor("notifications")
|
|
119
119
|
* .eventHandlers(onNotification)
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* position via a token store, and support replay/reset.
|
|
9
9
|
*
|
|
10
10
|
* ```typescript
|
|
11
|
-
* const onCreated = eventHandler(CourseCreated, async (e) => { ... })
|
|
12
|
-
* const onCapChanged = eventHandler(CourseCapacityChanged, async (e) => { ... })
|
|
11
|
+
* const onCreated = eventHandler(CourseCreated, async ({ payload: e }) => { ... })
|
|
12
|
+
* const onCapChanged = eventHandler(CourseCapacityChanged, async ({ payload: e }) => { ... })
|
|
13
13
|
*
|
|
14
14
|
* trackingProcessor("course-projection")
|
|
15
15
|
* .eventHandlers(onCreated, onCapChanged)
|
|
@@ -120,7 +120,7 @@ export class TrackingProcessorBuilder {
|
|
|
120
120
|
* as they are appended. No token store, no position tracking, no replay.
|
|
121
121
|
*
|
|
122
122
|
* ```typescript
|
|
123
|
-
* const onNotification = eventHandler(NotificationRaised, async (e) => { ... })
|
|
123
|
+
* const onNotification = eventHandler(NotificationRaised, async ({ payload: e }) => { ... })
|
|
124
124
|
*
|
|
125
125
|
* subscribingProcessor("notifications")
|
|
126
126
|
* .eventHandlers(onNotification)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventScheduler — schedule an event to be appended to the event store at
|
|
3
|
+
* a future time, with the option to cancel before the fire-time.
|
|
4
|
+
*
|
|
5
|
+
* # Semantics
|
|
6
|
+
*
|
|
7
|
+
* - `schedule(event, at)` MUST be called from inside a UnitOfWork (i.e.,
|
|
8
|
+
* from a command/event/query handler, or any code that opened a UoW
|
|
9
|
+
* via `runInNewUoW`). The scheduled record participates in the active
|
|
10
|
+
* UoW transaction: if the UoW rolls back, the schedule is not persisted;
|
|
11
|
+
* if the UoW commits, the schedule is durably stored.
|
|
12
|
+
*
|
|
13
|
+
* - Once the schedule is committed, the implementation guarantees that the
|
|
14
|
+
* event WILL be appended to the event store at or after `at`, unless
|
|
15
|
+
* {@link EventScheduler.cancel} is called and succeeds before the
|
|
16
|
+
* fire-time. "At or after" because workers poll on an interval — fire
|
|
17
|
+
* times are not real-time deadlines.
|
|
18
|
+
*
|
|
19
|
+
* - `cancel(token)` returns a {@link CancelResult} discriminated union so
|
|
20
|
+
* callers can branch on three distinct outcomes: the schedule was
|
|
21
|
+
* cancelled before firing, the event had already been appended (too
|
|
22
|
+
* late), or no such schedule exists (already-cancelled, never-existed,
|
|
23
|
+
* or token from a different deployment).
|
|
24
|
+
*
|
|
25
|
+
* - Cancel is also UoW-aware: when called inside a UoW, it participates
|
|
26
|
+
* in the active tx so a handler that cancels and then throws does NOT
|
|
27
|
+
* leave the schedule cancelled. When called outside any UoW (rare —
|
|
28
|
+
* typically an ops/admin path), it commits standalone.
|
|
29
|
+
*
|
|
30
|
+
* # Calling from handlers
|
|
31
|
+
*
|
|
32
|
+
* Implementations resolve themselves from the active UoW's resources
|
|
33
|
+
* (similar to {@link send} and {@link emitUpdate}), so handler code uses
|
|
34
|
+
* the scheduler the framework configured for it. The interface itself
|
|
35
|
+
* is transport-agnostic — postgres and in-memory implementations live
|
|
36
|
+
* in their respective packages.
|
|
37
|
+
*
|
|
38
|
+
* # NOT what this is
|
|
39
|
+
*
|
|
40
|
+
* - This is NOT a command scheduler. AF5 schedules events, not commands;
|
|
41
|
+
* if you want a command to run later, schedule an event and run an
|
|
42
|
+
* automation processor that turns the event into a command on receipt.
|
|
43
|
+
* - This is NOT a cron / recurring scheduler. Each `schedule()` produces
|
|
44
|
+
* a single one-shot fire.
|
|
45
|
+
*/
|
|
46
|
+
import type { EventMessage } from "./message.js";
|
|
47
|
+
/**
|
|
48
|
+
* Opaque handle returned by {@link EventScheduler.schedule}. Pass back to
|
|
49
|
+
* {@link EventScheduler.cancel} to attempt cancellation. Tokens are
|
|
50
|
+
* implementation-specific (postgres uses the row PK; in-memory uses a
|
|
51
|
+
* UUID) but always carry a stable `id`.
|
|
52
|
+
*/
|
|
53
|
+
export interface ScheduleToken {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Outcome of {@link EventScheduler.cancel}.
|
|
58
|
+
*
|
|
59
|
+
* - `cancelled` — the schedule existed in `pending` state and was
|
|
60
|
+
* successfully marked `cancelled`. Event will NOT
|
|
61
|
+
* be appended.
|
|
62
|
+
* - `already-appended` — a worker already fired this schedule; the event
|
|
63
|
+
* is in the event store. Caller decides whether
|
|
64
|
+
* compensation is needed.
|
|
65
|
+
* - `not-found` — no row matches the token. Could mean: already
|
|
66
|
+
* cancelled, never existed, or wrong store. Caller
|
|
67
|
+
* usually treats this as a no-op.
|
|
68
|
+
*/
|
|
69
|
+
export type CancelResult = {
|
|
70
|
+
readonly kind: "cancelled";
|
|
71
|
+
} | {
|
|
72
|
+
readonly kind: "already-appended";
|
|
73
|
+
} | {
|
|
74
|
+
readonly kind: "not-found";
|
|
75
|
+
};
|
|
76
|
+
export interface EventScheduler {
|
|
77
|
+
/**
|
|
78
|
+
* Schedule {@link event} for append at {@link at}. Must be called inside
|
|
79
|
+
* a UoW; throws otherwise. The schedule participates in the active UoW
|
|
80
|
+
* tx and is only durable once the UoW commits.
|
|
81
|
+
*
|
|
82
|
+
* `at` is the wall-clock fire-time. Past dates are valid — they cause
|
|
83
|
+
* the worker to fire the schedule on its next poll.
|
|
84
|
+
*/
|
|
85
|
+
schedule(event: EventMessage, at: Date): Promise<ScheduleToken>;
|
|
86
|
+
/**
|
|
87
|
+
* Attempt to cancel a pending schedule. See {@link CancelResult} for
|
|
88
|
+
* the three possible outcomes.
|
|
89
|
+
*
|
|
90
|
+
* Safe to call from inside a UoW (joins the active tx) or outside
|
|
91
|
+
* (commits standalone).
|
|
92
|
+
*/
|
|
93
|
+
cancel(token: ScheduleToken): Promise<CancelResult>;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=event-scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-scheduler.d.ts","sourceRoot":"","sources":["../src/event-scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEhD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,GACrC;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAAA;AAElC,MAAM,WAAW,cAAc;IAC7B;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IAE/D;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;CACpD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventScheduler — schedule an event to be appended to the event store at
|
|
3
|
+
* a future time, with the option to cancel before the fire-time.
|
|
4
|
+
*
|
|
5
|
+
* # Semantics
|
|
6
|
+
*
|
|
7
|
+
* - `schedule(event, at)` MUST be called from inside a UnitOfWork (i.e.,
|
|
8
|
+
* from a command/event/query handler, or any code that opened a UoW
|
|
9
|
+
* via `runInNewUoW`). The scheduled record participates in the active
|
|
10
|
+
* UoW transaction: if the UoW rolls back, the schedule is not persisted;
|
|
11
|
+
* if the UoW commits, the schedule is durably stored.
|
|
12
|
+
*
|
|
13
|
+
* - Once the schedule is committed, the implementation guarantees that the
|
|
14
|
+
* event WILL be appended to the event store at or after `at`, unless
|
|
15
|
+
* {@link EventScheduler.cancel} is called and succeeds before the
|
|
16
|
+
* fire-time. "At or after" because workers poll on an interval — fire
|
|
17
|
+
* times are not real-time deadlines.
|
|
18
|
+
*
|
|
19
|
+
* - `cancel(token)` returns a {@link CancelResult} discriminated union so
|
|
20
|
+
* callers can branch on three distinct outcomes: the schedule was
|
|
21
|
+
* cancelled before firing, the event had already been appended (too
|
|
22
|
+
* late), or no such schedule exists (already-cancelled, never-existed,
|
|
23
|
+
* or token from a different deployment).
|
|
24
|
+
*
|
|
25
|
+
* - Cancel is also UoW-aware: when called inside a UoW, it participates
|
|
26
|
+
* in the active tx so a handler that cancels and then throws does NOT
|
|
27
|
+
* leave the schedule cancelled. When called outside any UoW (rare —
|
|
28
|
+
* typically an ops/admin path), it commits standalone.
|
|
29
|
+
*
|
|
30
|
+
* # Calling from handlers
|
|
31
|
+
*
|
|
32
|
+
* Implementations resolve themselves from the active UoW's resources
|
|
33
|
+
* (similar to {@link send} and {@link emitUpdate}), so handler code uses
|
|
34
|
+
* the scheduler the framework configured for it. The interface itself
|
|
35
|
+
* is transport-agnostic — postgres and in-memory implementations live
|
|
36
|
+
* in their respective packages.
|
|
37
|
+
*
|
|
38
|
+
* # NOT what this is
|
|
39
|
+
*
|
|
40
|
+
* - This is NOT a command scheduler. AF5 schedules events, not commands;
|
|
41
|
+
* if you want a command to run later, schedule an event and run an
|
|
42
|
+
* automation processor that turns the event into a command on receipt.
|
|
43
|
+
* - This is NOT a cron / recurring scheduler. Each `schedule()` produces
|
|
44
|
+
* a single one-shot fire.
|
|
45
|
+
*/
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=event-scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-scheduler.js","sourceRoot":"","sources":["../src/event-scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG"}
|
package/dist/gateway.d.ts
CHANGED
|
@@ -52,12 +52,14 @@ export interface QueryGateway {
|
|
|
52
52
|
/**
|
|
53
53
|
* Creates a command gateway backed by a command bus.
|
|
54
54
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
55
|
+
* AF5-aligned (CLAUDE.md command model): the gateway is a thin message-builder
|
|
56
|
+
* and does NOT establish a UnitOfWork. The command bus owns the single
|
|
57
|
+
* per-command UoW (and, via the configured `unitOfWorkFactory`, its
|
|
58
|
+
* transaction) — see `createSimpleCommandBus`. Dispatch interceptors run on
|
|
59
|
+
* the message before it crosses into that UoW; the dispatch-side hook channel
|
|
60
|
+
* is ALS, not a threaded ProcessingContext.
|
|
59
61
|
*/
|
|
60
|
-
export declare function createCommandGateway(bus: CommandBus
|
|
62
|
+
export declare function createCommandGateway(bus: CommandBus): CommandGateway;
|
|
61
63
|
/**
|
|
62
64
|
* Creates a query gateway backed by a query bus.
|
|
63
65
|
*
|
package/dist/gateway.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,KAAK,EAAE,uBAAuB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AE,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EACpE,UAAU,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EACjC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EACnB,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;IAE1B,iBAAiB,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EAChF,UAAU,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EACjC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EACnB,QAAQ,CAAC,EAAE,QAAQ,GAClB,uBAAuB,CAAA;CAC3B;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,UAAU,GAAG,cAAc,CAapE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,QAAQ,EACb,gBAAgB,GAAE,SAAuB,GACxC,YAAY,CA6Bd"}
|
package/dist/gateway.js
CHANGED
|
@@ -3,27 +3,24 @@ import { runInNewUoW } from "./unit-of-work.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a command gateway backed by a command bus.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* AF5-aligned (CLAUDE.md command model): the gateway is a thin message-builder
|
|
7
|
+
* and does NOT establish a UnitOfWork. The command bus owns the single
|
|
8
|
+
* per-command UoW (and, via the configured `unitOfWorkFactory`, its
|
|
9
|
+
* transaction) — see `createSimpleCommandBus`. Dispatch interceptors run on
|
|
10
|
+
* the message before it crosses into that UoW; the dispatch-side hook channel
|
|
11
|
+
* is ALS, not a threaded ProcessingContext.
|
|
10
12
|
*/
|
|
11
|
-
export function createCommandGateway(bus
|
|
13
|
+
export function createCommandGateway(bus) {
|
|
12
14
|
return {
|
|
13
15
|
async send(descriptor, payload, metadata) {
|
|
14
16
|
const resolvedMetadata = metadata ?? emptyMetadata();
|
|
15
|
-
|
|
16
|
-
// UoW. The bus.dispatch call below will detect the ALS state we just
|
|
17
|
-
// established (via runInUoW in simple-command-bus) and reuse it — so
|
|
18
|
-
// this is the single UoW boundary for the dispatch chain. No
|
|
19
|
-
// ProcessingContext parameter is threaded.
|
|
20
|
-
return unitOfWorkRunner(resolvedMetadata, () => bus.dispatch({
|
|
17
|
+
return bus.dispatch({
|
|
21
18
|
identifier: generateIdentifier(),
|
|
22
19
|
name: descriptor.name,
|
|
23
20
|
payload,
|
|
24
21
|
metadata: resolvedMetadata,
|
|
25
22
|
timestamp: Date.now(),
|
|
26
|
-
})
|
|
23
|
+
});
|
|
27
24
|
},
|
|
28
25
|
};
|
|
29
26
|
}
|
package/dist/gateway.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,aAAa,GAEd,MAAM,mBAAmB,CAAA;AAK1B,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAA;AAgE/D
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,aAAa,GAEd,MAAM,mBAAmB,CAAA;AAK1B,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAA;AAgE/D;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAe;IAClD,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ;YACtC,MAAM,gBAAgB,GAAG,QAAQ,IAAI,aAAa,EAAE,CAAA;YACpD,OAAO,GAAG,CAAC,QAAQ,CAAC;gBAClB,UAAU,EAAE,kBAAkB,EAAE;gBAChC,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,OAAO;gBACP,QAAQ,EAAE,gBAAgB;gBAC1B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAQ,CAAA;QACX,CAAC;KACF,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,GAAa,EACb,mBAA8B,WAAW;IAEzC,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ;YACvC,MAAM,gBAAgB,GAAG,QAAQ,IAAI,aAAa,EAAE,CAAA;YACpD,uEAAuE;YACvE,8DAA8D;YAC9D,uEAAuE;YACvE,wCAAwC;YACxC,OAAO,gBAAgB,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAC7C,GAAG,CAAC,KAAK,CAAC;gBACR,UAAU,EAAE,kBAAkB,EAAE;gBAChC,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,OAAO;gBACP,QAAQ,EAAE,gBAAgB;gBAC1B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAiB,CACZ,CAAA;QACV,CAAC;QAED,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ;YAC7C,OAAO,GAAG,CAAC,iBAAiB,CAAC;gBAC3B,UAAU,EAAE,kBAAkB,EAAE;gBAChC,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,OAAO;gBACP,QAAQ,EAAE,QAAQ,IAAI,aAAa,EAAE;gBACrC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/dist/handler.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
-
import type { Metadata } from "@kronos-ts/common";
|
|
3
2
|
import type { EventDescriptor, QueryDescriptor } from "./descriptor.js";
|
|
3
|
+
import type { EventMessage, QueryMessage, SequencedEventMessage } from "./message.js";
|
|
4
4
|
/** A paired event descriptor + handler function, used in handler arrays. */
|
|
5
5
|
export interface EventHandlerRegistration<P extends z.ZodType = z.ZodType> {
|
|
6
6
|
readonly kind: "event-handler";
|
|
7
7
|
readonly descriptor: EventDescriptor<P>;
|
|
8
|
-
readonly handler: (
|
|
8
|
+
readonly handler: (message: SequencedEventMessage<z.infer<P>>) => Promise<void> | void;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* A paired event descriptor + evolver function, used in entity evolve arrays.
|
|
@@ -16,36 +16,36 @@ export interface EventHandlerRegistration<P extends z.ZodType = z.ZodType> {
|
|
|
16
16
|
export interface EvolverRegistration<S = unknown, P extends z.ZodType = z.ZodType> {
|
|
17
17
|
readonly kind: "evolver";
|
|
18
18
|
readonly descriptor: EventDescriptor<P>;
|
|
19
|
-
readonly evolve: (state: S,
|
|
19
|
+
readonly evolve: (state: S, message: EventMessage<z.infer<P>>) => S | Promise<S>;
|
|
20
20
|
}
|
|
21
21
|
/** A paired query descriptor + handler function, with result type on the handler. */
|
|
22
22
|
export interface QueryHandlerRegistration<Q extends z.ZodType = z.ZodType, R = unknown> {
|
|
23
23
|
readonly kind: "query-handler";
|
|
24
24
|
readonly descriptor: QueryDescriptor<Q>;
|
|
25
|
-
readonly handler: (
|
|
25
|
+
readonly handler: (message: QueryMessage<z.infer<Q>>) => Promise<R> | R;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Universal registration function.
|
|
29
29
|
* Pairs a descriptor with its handler for use in handler/evolve arrays.
|
|
30
30
|
*
|
|
31
31
|
* Usage:
|
|
32
|
-
* - Event handlers: `on(CourseCreated, async (
|
|
33
|
-
* - Query handlers: `on(GetCourse, async (
|
|
34
|
-
* - Evolvers: `on(CourseCreated, (state,
|
|
32
|
+
* - Event handlers: `on(CourseCreated, async ({ payload, metadata }) => { ... })`
|
|
33
|
+
* - Query handlers: `on(GetCourse, async ({ payload, metadata }) => { return { ... } })`
|
|
34
|
+
* - Evolvers: `on(CourseCreated, (state, { payload }) => ({ ...state, name: payload.name }))`
|
|
35
35
|
*
|
|
36
36
|
* The overload is resolved by the descriptor kind and how many arguments
|
|
37
|
-
* the callback declares.
|
|
38
|
-
*
|
|
37
|
+
* the callback declares. Event and query handlers receive the full typed message.
|
|
38
|
+
* Evolvers receive the current state plus the full typed event message.
|
|
39
39
|
*
|
|
40
40
|
* In practice the distinction is enforced by the array type:
|
|
41
41
|
* - `evolve: [on(...)]` expects `EvolverRegistration`
|
|
42
42
|
* - `handlers: [on(...)]` expects `EventHandlerRegistration`
|
|
43
43
|
*/
|
|
44
|
-
export declare function on<S, P extends z.ZodType>(descriptor: EventDescriptor<P>, evolve: (state: S,
|
|
45
|
-
export declare function on<P extends z.ZodType>(descriptor: EventDescriptor<P>, handler: (
|
|
46
|
-
export declare function on<Q extends z.ZodType, R>(descriptor: QueryDescriptor<Q>, handler: (
|
|
44
|
+
export declare function on<S, P extends z.ZodType>(descriptor: EventDescriptor<P>, evolve: (state: S, message: EventMessage<z.infer<P>>) => S | Promise<S>): EvolverRegistration<S, P>;
|
|
45
|
+
export declare function on<P extends z.ZodType>(descriptor: EventDescriptor<P>, handler: (message: SequencedEventMessage<z.infer<P>>) => Promise<void> | void): EventHandlerRegistration<P>;
|
|
46
|
+
export declare function on<Q extends z.ZodType, R>(descriptor: QueryDescriptor<Q>, handler: (message: QueryMessage<z.infer<Q>>) => Promise<R> | R): QueryHandlerRegistration<Q, R>;
|
|
47
47
|
/**
|
|
48
48
|
* @deprecated Use `on()` instead. `onEvent` is kept for backward compatibility.
|
|
49
49
|
*/
|
|
50
|
-
export declare function onEvent<S, P extends z.ZodType>(descriptor: EventDescriptor<P>, evolve: (state: S,
|
|
50
|
+
export declare function onEvent<S, P extends z.ZodType>(descriptor: EventDescriptor<P>, evolve: (state: S, message: EventMessage<z.infer<P>>) => S | Promise<S>): EvolverRegistration<S, P>;
|
|
51
51
|
//# sourceMappingURL=handler.d.ts.map
|
package/dist/handler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAEV,eAAe,EACf,eAAe,EAChB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAcrF,4EAA4E;AAC5E,MAAM,WAAW,wBAAwB,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO;IACvE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;IAC9B,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,CAAA;IACvC,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACvF;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB,CAClC,CAAC,GAAG,OAAO,EACX,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO;IAE/B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,CAAA;IACvC,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GA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,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAC7D,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAyBjC;;GAEG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,OAAO,EAC5C,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,EAC9B,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACtE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAE3B"}
|
package/dist/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AA4FA,MAAM,UAAU,EAAE,CAChB,UAA6C,EAC7C,OAAgC;IAEhC,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAChC,8EAA8E;QAC9E,yEAAyE;QACzE,gGAAgG;QAChG,0CAA0C;QAC1C,OAAO;YACL,IAAI,EAAE,eAAsB;YAC5B,UAAU,EAAE,UAA6B;YACzC,OAAO;YACP,MAAM,EAAE,OAAO;SAChB,CAAA;IACH,CAAC;IACD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,UAAU,EAAE,UAA6B;QACzC,OAAO;KACR,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CACrB,UAA8B,EAC9B,MAAuE;IAEvE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;AAChD,CAAC"}
|