@fluojs/cqrs 1.1.2 → 3.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.
Files changed (58) hide show
  1. package/README.ko.md +29 -9
  2. package/README.md +29 -9
  3. package/dist/buses/command-bus.d.ts +19 -2
  4. package/dist/buses/command-bus.d.ts.map +1 -1
  5. package/dist/buses/command-bus.js +68 -24
  6. package/dist/buses/event-bus.d.ts +16 -8
  7. package/dist/buses/event-bus.d.ts.map +1 -1
  8. package/dist/buses/event-bus.js +84 -74
  9. package/dist/buses/event-handler-discovery.d.ts +12 -0
  10. package/dist/buses/event-handler-discovery.d.ts.map +1 -0
  11. package/dist/buses/event-handler-discovery.js +35 -0
  12. package/dist/buses/publish-drain-tracker.d.ts +38 -0
  13. package/dist/buses/publish-drain-tracker.d.ts.map +1 -0
  14. package/dist/buses/publish-drain-tracker.js +89 -0
  15. package/dist/buses/query-bus.d.ts +19 -2
  16. package/dist/buses/query-bus.d.ts.map +1 -1
  17. package/dist/buses/query-bus.js +68 -24
  18. package/dist/buses/saga-bus.d.ts +21 -9
  19. package/dist/buses/saga-bus.d.ts.map +1 -1
  20. package/dist/buses/saga-bus.js +113 -112
  21. package/dist/buses/saga-continuation.d.ts +14 -0
  22. package/dist/buses/saga-continuation.d.ts.map +1 -0
  23. package/dist/buses/saga-continuation.js +24 -0
  24. package/dist/buses/saga-discovery.d.ts +12 -0
  25. package/dist/buses/saga-discovery.d.ts.map +1 -0
  26. package/dist/buses/saga-discovery.js +39 -0
  27. package/dist/buses/saga-drain.d.ts +9 -0
  28. package/dist/buses/saga-drain.d.ts.map +1 -0
  29. package/dist/buses/saga-drain.js +34 -0
  30. package/dist/buses/saga-topology.d.ts +18 -0
  31. package/dist/buses/saga-topology.d.ts.map +1 -0
  32. package/dist/buses/saga-topology.js +46 -0
  33. package/dist/buses/shutdown-deadline.d.ts +23 -0
  34. package/dist/buses/shutdown-deadline.d.ts.map +1 -0
  35. package/dist/buses/shutdown-deadline.js +31 -0
  36. package/dist/decorators.d.ts.map +1 -1
  37. package/dist/decorators.js +15 -1
  38. package/dist/discovery.d.ts +18 -0
  39. package/dist/discovery.d.ts.map +1 -1
  40. package/dist/discovery.js +95 -12
  41. package/dist/dispatch-context.d.ts +35 -0
  42. package/dist/dispatch-context.d.ts.map +1 -0
  43. package/dist/dispatch-context.js +43 -0
  44. package/dist/errors.d.ts +4 -2
  45. package/dist/errors.d.ts.map +1 -1
  46. package/dist/errors.js +4 -2
  47. package/dist/module.d.ts +4 -1
  48. package/dist/module.d.ts.map +1 -1
  49. package/dist/module.js +24 -4
  50. package/dist/status.d.ts +4 -0
  51. package/dist/status.d.ts.map +1 -1
  52. package/dist/status.js +10 -6
  53. package/dist/test-setup.d.ts +2 -0
  54. package/dist/test-setup.d.ts.map +1 -0
  55. package/dist/test-setup.js +4 -0
  56. package/dist/types.d.ts +3 -1
  57. package/dist/types.d.ts.map +1 -1
  58. package/package.json +7 -7
@@ -0,0 +1,31 @@
1
+ /** Coordinates one absolute CQRS shutdown deadline across lifecycle drain hooks. */
2
+ export class CqrsShutdownDeadline {
3
+ deadlineMs;
4
+
5
+ /**
6
+ * Starts the shared deadline once.
7
+ *
8
+ * @param timeoutMs Configured CQRS shutdown drain duration.
9
+ */
10
+ start(timeoutMs) {
11
+ this.deadlineMs ??= Date.now() + timeoutMs;
12
+ }
13
+
14
+ /**
15
+ * Returns the remaining duration from the shared deadline.
16
+ *
17
+ * @returns Remaining duration in milliseconds, or `undefined` before shutdown starts.
18
+ */
19
+ remainingTimeoutMs() {
20
+ return this.deadlineMs === undefined ? undefined : Math.max(0, this.deadlineMs - Date.now());
21
+ }
22
+
23
+ /**
24
+ * Returns the absolute timestamp for the shared deadline.
25
+ *
26
+ * @returns Absolute deadline in milliseconds, or `undefined` before shutdown starts.
27
+ */
28
+ deadlineAtMs() {
29
+ return this.deadlineMs;
30
+ }
31
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAEV,WAAW,EACX,aAAa,EAGb,SAAS,EAEV,MAAM,YAAY,CAAC;AAEpB,KAAK,kBAAkB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAC;AA0DpF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,kBAAkB,CAU3E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB,CAUrE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,aAAa,GAAG,kBAAkB,CAUzE;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,gBAAgB,EAAE,aAAa,GAAG,SAAS,aAAa,EAAE,GAAG,kBAAkB,CAYnG"}
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAEV,WAAW,EACX,aAAa,EAGb,SAAS,EAEV,MAAM,YAAY,CAAC;AAEpB,KAAK,kBAAkB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAC;AA2EpF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,kBAAkB,CAU3E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB,CAUrE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,aAAa,GAAG,kBAAkB,CAUzE;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,gBAAgB,EAAE,aAAa,GAAG,SAAS,aAAa,EAAE,GAAG,kBAAkB,CAYnG"}
@@ -31,6 +31,20 @@ function defineStandardSagaMetadata(metadata, sagaMetadata) {
31
31
  eventTypes: [...sagaMetadata.eventTypes]
32
32
  };
33
33
  }
34
+ function isConstructableClass(value) {
35
+ if (typeof value !== 'function') {
36
+ return false;
37
+ }
38
+ try {
39
+ Reflect.construct(Object, [], value);
40
+ return true;
41
+ } catch (error) {
42
+ if (error instanceof TypeError) {
43
+ return false;
44
+ }
45
+ throw error;
46
+ }
47
+ }
34
48
  function normalizeSagaEventTypes(eventTypeOrTypes) {
35
49
  const eventTypes = Array.isArray(eventTypeOrTypes) ? eventTypeOrTypes : [eventTypeOrTypes];
36
50
  const uniqueEventTypes = Array.from(new Set(eventTypes));
@@ -38,7 +52,7 @@ function normalizeSagaEventTypes(eventTypeOrTypes) {
38
52
  throw new Error('@Saga() requires at least one event type.');
39
53
  }
40
54
  for (const eventType of uniqueEventTypes) {
41
- if (typeof eventType !== 'function') {
55
+ if (!isConstructableClass(eventType)) {
42
56
  throw new Error('@Saga() event types must be class constructors.');
43
57
  }
44
58
  }
@@ -22,10 +22,26 @@ export interface DiscoveryCandidate {
22
22
  export declare function createDuplicateHandlerMessage(kind: 'command' | 'query' | 'event', messageType: Function, first: {
23
23
  moduleName: string;
24
24
  targetType: Function;
25
+ token: Token;
25
26
  }, second: {
26
27
  moduleName: string;
27
28
  targetType: Function;
29
+ token: Token;
28
30
  }): string;
31
+ /**
32
+ * Checks whether two discovered handler candidates refer to the same provider registration.
33
+ *
34
+ * @param first The first handler registration.
35
+ * @param second The second handler registration.
36
+ * @returns Whether both target type and provider token match.
37
+ */
38
+ export declare function isSameHandlerRegistration(first: {
39
+ targetType: Function;
40
+ token: Token;
41
+ }, second: {
42
+ targetType: Function;
43
+ token: Token;
44
+ }): boolean;
29
45
  /**
30
46
  * Represents the cqrs bus base.
31
47
  */
@@ -36,6 +52,8 @@ export declare abstract class CqrsBusBase {
36
52
  protected readonly handlerInstances: Map<Token, Promise<unknown>>;
37
53
  constructor(runtimeContainer: Container, compiledModules: readonly CompiledModule[], logger: ApplicationLogger);
38
54
  protected discoveryCandidates(): DiscoveryCandidate[];
55
+ private resolveProviderDiscoveryCandidate;
56
+ private createUnresolvedProviderDiscoveryCandidate;
39
57
  protected preloadHandlerInstance(token: Token): Promise<void>;
40
58
  protected resolveHandlerInstance(token: Token): Promise<unknown>;
41
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;IAC7C,UAAU,EAAE,QAAQ,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;CACd;AAkBD;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,OAAO,EACnC,WAAW,EAAE,QAAQ,EACrB,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,QAAQ,CAAA;CAAE,EACnD,MAAM,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,QAAQ,CAAA;CAAE,GACnD,MAAM,CAER;AAED;;GAEG;AACH,8BAAsB,WAAW;IAI7B,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,SAAS;IAC9C,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,SAAS,cAAc,EAAE;IAC7D,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,iBAAiB;IAL9C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,+BAAsC;gBAGpD,gBAAgB,EAAE,SA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U,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC7C,OAAO,CAET;AAED;;GAEG;AACH,8BAAsB,WAAW;IAI7B,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,SAAS;IAC9C,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,SAAS,cAAc,EAAE;IAC7D,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,iBAAiB;IAL9C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,+BAAsC;gBAGpD,gBAAgB,EAAE,SAAS,EAC3B,eAAe,EAAE,SAAS,cAAc,EAAE,EAC1C,MAAM,EAAE,iBAAiB;IAG9C,SAAS,CAAC,mBAAmB,IAAI,kBAAkB,EAAE;IA2CrD,OAAO,CAAC,iCAAiC;IA+CzC,OAAO,CAAC,0CAA0C;cAmBlC,sBAAsB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;cAgBnD,sBAAsB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;CAiBvE"}
package/dist/discovery.js CHANGED
@@ -1,4 +1,9 @@
1
- import { getClassDiMetadata } from '@fluojs/core/internal';
1
+ import { formatTokenName } from '@fluojs/core';
2
+ import { getRuntimeClassDiMetadata } from '@fluojs/runtime/internal';
3
+ import { getCommandHandlerMetadata } from './metadata.js';
4
+ import { getEventHandlerMetadata } from './metadata.js';
5
+ import { getQueryHandlerMetadata } from './metadata.js';
6
+ import { getSagaMetadata } from './metadata.js';
2
7
 
3
8
  /**
4
9
  * Describes the discovery candidate contract.
@@ -6,16 +11,26 @@ import { getClassDiMetadata } from '@fluojs/core/internal';
6
11
 
7
12
  function scopeFromProvider(provider) {
8
13
  if (typeof provider === 'function') {
9
- return getClassDiMetadata(provider)?.scope ?? 'singleton';
14
+ return getRuntimeClassDiMetadata(provider)?.scope ?? 'singleton';
10
15
  }
11
16
  if ('useClass' in provider) {
12
- return provider.scope ?? getClassDiMetadata(provider.useClass)?.scope ?? 'singleton';
17
+ return provider.scope ?? getRuntimeClassDiMetadata(provider.useClass)?.scope ?? 'singleton';
13
18
  }
14
- return 'scope' in provider ? provider.scope ?? 'singleton' : 'singleton';
19
+ if ('useFactory' in provider) {
20
+ const resolverClass = provider.resolverClass;
21
+ return provider.scope ?? (resolverClass ? getRuntimeClassDiMetadata(resolverClass)?.scope : undefined) ?? 'singleton';
22
+ }
23
+ return 'singleton';
15
24
  }
16
25
  function isClassProvider(provider) {
17
26
  return typeof provider === 'object' && provider !== null && 'useClass' in provider;
18
27
  }
28
+ function isFactoryOrValueProvider(provider) {
29
+ return typeof provider === 'object' && provider !== null && ('useFactory' in provider || 'useValue' in provider);
30
+ }
31
+ function hasCqrsMetadata(targetType) {
32
+ return getCommandHandlerMetadata(targetType) !== undefined || getQueryHandlerMetadata(targetType) !== undefined || getEventHandlerMetadata(targetType) !== undefined || getSagaMetadata(targetType) !== undefined;
33
+ }
19
34
 
20
35
  /**
21
36
  * Create duplicate handler message.
@@ -27,7 +42,21 @@ function isClassProvider(provider) {
27
42
  * @returns The create duplicate handler message result.
28
43
  */
29
44
  export function createDuplicateHandlerMessage(kind, messageType, first, second) {
30
- return `Duplicate ${kind} handler for ${messageType.name} was discovered in ${first.moduleName}.${first.targetType.name} and ${second.moduleName}.${second.targetType.name}.`;
45
+ return `Duplicate ${kind} handler for ${messageType.name} was discovered in ${describeHandlerRegistration(first)} and ${describeHandlerRegistration(second)}.`;
46
+ }
47
+ function describeHandlerRegistration(registration) {
48
+ return `${registration.moduleName}.${registration.targetType.name} [token: ${formatTokenName(registration.token)}]`;
49
+ }
50
+
51
+ /**
52
+ * Checks whether two discovered handler candidates refer to the same provider registration.
53
+ *
54
+ * @param first The first handler registration.
55
+ * @param second The second handler registration.
56
+ * @returns Whether both target type and provider token match.
57
+ */
58
+ export function isSameHandlerRegistration(first, second) {
59
+ return first.targetType === second.targetType && first.token === second.token;
31
60
  }
32
61
 
33
62
  /**
@@ -42,6 +71,7 @@ export class CqrsBusBase {
42
71
  }
43
72
  discoveryCandidates() {
44
73
  const candidates = [];
74
+ const providerCandidates = [];
45
75
  for (const compiledModule of this.compiledModules) {
46
76
  for (const provider of compiledModule.definition.providers ?? []) {
47
77
  if (typeof provider === 'function') {
@@ -60,19 +90,72 @@ export class CqrsBusBase {
60
90
  targetType: provider.useClass,
61
91
  token: provider.provide
62
92
  });
93
+ continue;
94
+ }
95
+ if (isFactoryOrValueProvider(provider)) {
96
+ providerCandidates.push({
97
+ moduleName: compiledModule.type.name,
98
+ provider
99
+ });
63
100
  }
64
101
  }
65
- for (const controller of compiledModule.definition.controllers ?? []) {
66
- candidates.push({
67
- moduleName: compiledModule.type.name,
68
- scope: scopeFromProvider(controller),
69
- targetType: controller,
70
- token: controller
71
- });
102
+ }
103
+ for (const candidate of providerCandidates) {
104
+ const resolvedCandidate = this.resolveProviderDiscoveryCandidate(candidate);
105
+ if (resolvedCandidate) {
106
+ candidates.push(resolvedCandidate);
72
107
  }
73
108
  }
74
109
  return candidates;
75
110
  }
111
+ resolveProviderDiscoveryCandidate(candidate) {
112
+ const provider = candidate.provider;
113
+ if (!('provide' in provider)) {
114
+ return undefined;
115
+ }
116
+ const scope = scopeFromProvider(provider);
117
+ const token = provider.provide;
118
+ if (scope !== 'singleton') {
119
+ return this.createUnresolvedProviderDiscoveryCandidate(candidate.moduleName, token, scope);
120
+ }
121
+ if ('useValue' in provider) {
122
+ const instance = provider.useValue;
123
+ if (typeof instance !== 'object' || instance === null) {
124
+ return undefined;
125
+ }
126
+ const targetType = instance.constructor;
127
+ if (typeof targetType !== 'function' || !hasCqrsMetadata(targetType)) {
128
+ return undefined;
129
+ }
130
+ return {
131
+ moduleName: candidate.moduleName,
132
+ scope,
133
+ targetType,
134
+ token
135
+ };
136
+ }
137
+ if (typeof token !== 'function' || !hasCqrsMetadata(token)) {
138
+ return undefined;
139
+ }
140
+ return {
141
+ moduleName: candidate.moduleName,
142
+ scope,
143
+ targetType: token,
144
+ token
145
+ };
146
+ }
147
+ createUnresolvedProviderDiscoveryCandidate(moduleName, token, scope) {
148
+ const tokenType = typeof token === 'function' ? token : undefined;
149
+ if (!tokenType) {
150
+ return undefined;
151
+ }
152
+ return {
153
+ moduleName,
154
+ scope,
155
+ targetType: tokenType,
156
+ token
157
+ };
158
+ }
76
159
  async preloadHandlerInstance(token) {
77
160
  if (this.handlerInstances.has(token)) {
78
161
  return;
@@ -0,0 +1,35 @@
1
+ import type { Token } from '@fluojs/core';
2
+ import type { SagaContinuationScope } from './buses/saga-continuation.js';
3
+ import type { CqrsDispatchContext, CqrsEventType } from './types.js';
4
+ /** One active saga route retained in private CQRS dispatch state. */
5
+ export interface CqrsDispatchRoute {
6
+ readonly eventType: CqrsEventType;
7
+ readonly token: Token;
8
+ }
9
+ /** Private saga topology state associated with an opaque dispatch context. */
10
+ export interface CqrsSagaTopologyState {
11
+ readonly activeRoutes: readonly CqrsDispatchRoute[];
12
+ readonly depth: number;
13
+ readonly path: readonly string[];
14
+ }
15
+ /** Private state carried by an internally created dispatch context. */
16
+ export interface InternalCqrsDispatchContextState {
17
+ readonly publishDrainToken: symbol | undefined;
18
+ readonly sagaContinuationScope: SagaContinuationScope | undefined;
19
+ readonly sagaTopology: CqrsSagaTopologyState | undefined;
20
+ }
21
+ /**
22
+ * Creates an opaque immutable dispatch context and retains its state in a private weak map.
23
+ *
24
+ * @param state Internal publish-drain and saga-topology state.
25
+ * @returns A frozen fieldless context safe to pass through application handlers.
26
+ */
27
+ export declare function createInternalCqrsDispatchContext(state: InternalCqrsDispatchContextState): CqrsDispatchContext;
28
+ /**
29
+ * Reads private state only for context values created by CQRS internals.
30
+ *
31
+ * @param context Optional public dispatch context received from a handler or saga.
32
+ * @returns The immutable internal state, or `undefined` for caller-created values.
33
+ */
34
+ export declare function getInternalCqrsDispatchContextState(context: CqrsDispatchContext | undefined): InternalCqrsDispatchContextState | undefined;
35
+ //# sourceMappingURL=dispatch-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch-context.d.ts","sourceRoot":"","sources":["../src/dispatch-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAErE,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAED,8EAA8E;AAC9E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,YAAY,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AAED,uEAAuE;AACvE,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAClE,QAAQ,CAAC,YAAY,EAAE,qBAAqB,GAAG,SAAS,CAAC;CAC1D;AAcD;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,gCAAgC,GAAG,mBAAmB,CAW9G;AAED;;;;;GAKG;AACH,wBAAgB,mCAAmC,CACjD,OAAO,EAAE,mBAAmB,GAAG,SAAS,GACvC,gCAAgC,GAAG,SAAS,CAE9C"}
@@ -0,0 +1,43 @@
1
+ /** One active saga route retained in private CQRS dispatch state. */
2
+
3
+ /** Private saga topology state associated with an opaque dispatch context. */
4
+
5
+ /** Private state carried by an internally created dispatch context. */
6
+
7
+ const internalContextStates = new WeakMap();
8
+ function freezeSagaTopology(state) {
9
+ return Object.freeze({
10
+ activeRoutes: Object.freeze(state.activeRoutes.map(route => Object.freeze({
11
+ eventType: route.eventType,
12
+ token: route.token
13
+ }))),
14
+ depth: state.depth,
15
+ path: Object.freeze([...state.path])
16
+ });
17
+ }
18
+
19
+ /**
20
+ * Creates an opaque immutable dispatch context and retains its state in a private weak map.
21
+ *
22
+ * @param state Internal publish-drain and saga-topology state.
23
+ * @returns A frozen fieldless context safe to pass through application handlers.
24
+ */
25
+ export function createInternalCqrsDispatchContext(state) {
26
+ const context = Object.freeze({});
27
+ internalContextStates.set(context, Object.freeze({
28
+ publishDrainToken: state.publishDrainToken,
29
+ sagaContinuationScope: state.sagaContinuationScope,
30
+ sagaTopology: state.sagaTopology ? freezeSagaTopology(state.sagaTopology) : undefined
31
+ }));
32
+ return context;
33
+ }
34
+
35
+ /**
36
+ * Reads private state only for context values created by CQRS internals.
37
+ *
38
+ * @param context Optional public dispatch context received from a handler or saga.
39
+ * @returns The immutable internal state, or `undefined` for caller-created values.
40
+ */
41
+ export function getInternalCqrsDispatchContextState(context) {
42
+ return context ? internalContextStates.get(context) : undefined;
43
+ }
package/dist/errors.d.ts CHANGED
@@ -36,9 +36,11 @@ export declare class DuplicateQueryHandlerError extends FluoError {
36
36
  constructor(message: string);
37
37
  }
38
38
  /**
39
- * Raised when conflicting event-handler registrations break CQRS discovery invariants.
39
+ * Compatibility error type retained for existing imports.
40
40
  *
41
- * Ordinary multiple `@EventHandler(...)` providers for the same event are valid and fan out.
41
+ * Event-handler discovery does not throw this error. Repeated discovery of the same singleton provider token and event
42
+ * type is silently deduplicated, while distinct singleton provider tokens remain valid fan-out routes in discovery
43
+ * order.
42
44
  */
43
45
  export declare class DuplicateEventHandlerError extends FluoError {
44
46
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,wFAAwF;AACxF,qBAAa,+BAAgC,SAAQ,SAAS;IA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AA0E;AAC1E,qBAAa,kBAAmB,SAAQ,SAAS;IAC/C;;;;OAIG;gBACS,OAAO,EAAE,MAAM;CAG5B;AAED,8EAA8E;AAC9E,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C;;;;OAIG;gBACS,OAAO,EAAE,MAAM;CAG5B"}
package/dist/errors.js CHANGED
@@ -57,9 +57,11 @@ export class DuplicateQueryHandlerError extends FluoError {
57
57
  }
58
58
 
59
59
  /**
60
- * Raised when conflicting event-handler registrations break CQRS discovery invariants.
60
+ * Compatibility error type retained for existing imports.
61
61
  *
62
- * Ordinary multiple `@EventHandler(...)` providers for the same event are valid and fan out.
62
+ * Event-handler discovery does not throw this error. Repeated discovery of the same singleton provider token and event
63
+ * type is silently deduplicated, while distinct singleton provider tokens remain valid fan-out routes in discovery
64
+ * order.
63
65
  */
64
66
  export class DuplicateEventHandlerError extends FluoError {
65
67
  /**
package/dist/module.d.ts CHANGED
@@ -18,7 +18,10 @@ export interface CqrsModuleOptions {
18
18
  /** Runtime module entrypoint for CQRS bus registration and handler discovery. */
19
19
  export declare class CqrsModule {
20
20
  /**
21
- * Registers the CQRS buses globally and wires them to the event-bus integration.
21
+ * Registers CQRS buses and wires them to the event-bus integration.
22
+ *
23
+ * The exported buses are global by default. Set {@link CqrsModuleOptions.global} to `false` to
24
+ * keep them visible only through modules that import this module definition.
22
25
  *
23
26
  * @param options CQRS module options including explicit handler classes and event-bus settings.
24
27
  * @returns A module definition that exports the lifecycle services and compatibility tokens.
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAOhE,OAAO,KAAK,EACV,mBAAmB,EAEnB,iBAAiB,EAIjB,iBAAiB,EACjB,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,4FAA4F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;KACzB,CAAC;CACH;AAkHD,iFAAiF;AACjF,qBAAa,UAAU;IACrB;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU;CAkB5D"}
package/dist/module.js CHANGED
@@ -4,6 +4,7 @@ import { CommandBusLifecycleService } from './buses/command-bus.js';
4
4
  import { CqrsEventBusService } from './buses/event-bus.js';
5
5
  import { QueryBusLifecycleService } from './buses/query-bus.js';
6
6
  import { CqrsSagaLifecycleService } from './buses/saga-bus.js';
7
+ import { CqrsShutdownDeadline } from './buses/shutdown-deadline.js';
7
8
  import { COMMAND_BUS, CQRS_MODULE_OPTIONS, EVENT_BUS, QUERY_BUS } from './tokens.js';
8
9
 
9
10
  /** Module options for registering first-party handler classes and event-bus integration. */
@@ -24,6 +25,18 @@ function collectOptionHandlerProviders(options) {
24
25
  }
25
26
  return providers;
26
27
  }
28
+ function resolveDelegatedEventBusOptions(options) {
29
+ const eventBusOptions = options.eventBus ?? {};
30
+ const eventBusShutdown = eventBusOptions.shutdown;
31
+ return {
32
+ ...eventBusOptions,
33
+ global: eventBusOptions.global ?? options.global ?? true,
34
+ shutdown: {
35
+ ...eventBusShutdown,
36
+ drainTimeoutMs: eventBusShutdown?.drainTimeoutMs ?? options.shutdown?.drainTimeoutMs
37
+ }
38
+ };
39
+ }
27
40
  function assertCommandBusService(service) {
28
41
  if (!(service instanceof CommandBusLifecycleService)) {
29
42
  throw new TypeError('CQRS command bus alias expected CommandBusLifecycleService.');
@@ -46,10 +59,13 @@ function assertCqrsEventBusService(service) {
46
59
  * @param options CQRS module options including eager handler classes and event-bus configuration.
47
60
  * @returns Providers for the command, query, event, and saga runtimes plus compatibility tokens.
48
61
  */
49
- function createCqrsProviders(options = {}) {
62
+ function createCqrsProviders(options, shutdownDeadline) {
50
63
  return [{
51
64
  provide: CQRS_MODULE_OPTIONS,
52
65
  useValue: options
66
+ }, {
67
+ provide: CqrsShutdownDeadline,
68
+ useValue: shutdownDeadline
53
69
  }, CommandBusLifecycleService, {
54
70
  inject: [CommandBusLifecycleService],
55
71
  provide: COMMAND_BUS,
@@ -84,18 +100,22 @@ function createCqrsProviders(options = {}) {
84
100
  /** Runtime module entrypoint for CQRS bus registration and handler discovery. */
85
101
  export class CqrsModule {
86
102
  /**
87
- * Registers the CQRS buses globally and wires them to the event-bus integration.
103
+ * Registers CQRS buses and wires them to the event-bus integration.
104
+ *
105
+ * The exported buses are global by default. Set {@link CqrsModuleOptions.global} to `false` to
106
+ * keep them visible only through modules that import this module definition.
88
107
  *
89
108
  * @param options CQRS module options including explicit handler classes and event-bus settings.
90
109
  * @returns A module definition that exports the lifecycle services and compatibility tokens.
91
110
  */
92
111
  static forRoot(options = {}) {
93
112
  class CqrsModuleDefinition {}
113
+ const shutdownDeadline = new CqrsShutdownDeadline();
94
114
  return defineModule(CqrsModuleDefinition, {
95
115
  exports: [CommandBusLifecycleService, QueryBusLifecycleService, CqrsEventBusService, COMMAND_BUS, QUERY_BUS, EVENT_BUS],
96
116
  global: options.global ?? true,
97
- imports: [EventBusModule.forRoot(options.eventBus)],
98
- providers: createCqrsProviders(options)
117
+ imports: [EventBusModule.forRoot(resolveDelegatedEventBusOptions(options))],
118
+ providers: createCqrsProviders(options, shutdownDeadline)
99
119
  });
100
120
  }
101
121
  }
package/dist/status.d.ts CHANGED
@@ -7,9 +7,13 @@ export type CqrsLifecycleState = 'created' | 'discovering' | 'ready' | 'stopping
7
7
  * Describes the cqrs status adapter input contract.
8
8
  */
9
9
  export interface CqrsStatusAdapterInput {
10
+ commandHandlersDiscovered?: number;
11
+ commandLifecycleState?: CqrsLifecycleState;
10
12
  eventHandlersDiscovered: number;
11
13
  inFlightSagaExecutions: number;
12
14
  lifecycleState: CqrsLifecycleState;
15
+ queryHandlersDiscovered?: number;
16
+ queryLifecycleState?: CqrsLifecycleState;
13
17
  sagaLifecycleState: CqrsLifecycleState;
14
18
  sagaShutdownDrainTimeouts: number;
15
19
  sagasDiscovered: number;
@@ -1 +1 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEvG;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEzG;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,uBAAuB,EAAE,MAAM,CAAC;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,cAAc,EAAE,kBAAkB,CAAC;IACnC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,yBAAyB,EAAE,MAAM,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,uBAAuB,CAAC;IACnC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAmFD;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,sBAAsB,GAAG,0BAA0B,CAoB1G"}
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEvG;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEzG;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,qBAAqB,CAAC,EAAE,kBAAkB,CAAC;IAC3C,uBAAuB,EAAE,MAAM,CAAC;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,cAAc,EAAE,kBAAkB,CAAC;IACnC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,mBAAmB,CAAC,EAAE,kBAAkB,CAAC;IACzC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,yBAAyB,EAAE,MAAM,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,uBAAuB,CAAC;IACnC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAmFD;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,sBAAsB,GAAG,0BAA0B,CAwB1G"}
package/dist/status.js CHANGED
@@ -45,6 +45,12 @@ function createReadiness(input) {
45
45
  };
46
46
  }
47
47
  function createHealth(input) {
48
+ if (input.shutdownDrainTimeouts > 0 || input.sagaShutdownDrainTimeouts > 0) {
49
+ return {
50
+ reason: 'CQRS event/saga pipeline reported bounded shutdown drain timeouts.',
51
+ status: 'degraded'
52
+ };
53
+ }
48
54
  if (input.lifecycleState === 'failed' || input.sagaLifecycleState === 'failed' || input.lifecycleState === 'stopped' || input.sagaLifecycleState === 'stopped') {
49
55
  return {
50
56
  reason: 'CQRS event/saga pipeline is unavailable.',
@@ -57,12 +63,6 @@ function createHealth(input) {
57
63
  status: 'degraded'
58
64
  };
59
65
  }
60
- if (input.shutdownDrainTimeouts > 0 || input.sagaShutdownDrainTimeouts > 0) {
61
- return {
62
- reason: 'CQRS event/saga pipeline reported bounded shutdown drain timeouts.',
63
- status: 'degraded'
64
- };
65
- }
66
66
  return {
67
67
  status: 'healthy'
68
68
  };
@@ -77,10 +77,14 @@ function createHealth(input) {
77
77
  export function createCqrsPlatformStatusSnapshot(input) {
78
78
  return {
79
79
  details: {
80
+ commandHandlersDiscovered: input.commandHandlersDiscovered ?? 0,
81
+ commandLifecycleState: input.commandLifecycleState ?? input.lifecycleState,
80
82
  dependencies: ['event-bus.default'],
81
83
  eventHandlersDiscovered: input.eventHandlersDiscovered,
82
84
  inFlightSagaExecutions: input.inFlightSagaExecutions,
83
85
  lifecycleState: input.lifecycleState,
86
+ queryHandlersDiscovered: input.queryHandlersDiscovered ?? 0,
87
+ queryLifecycleState: input.queryLifecycleState ?? input.lifecycleState,
84
88
  sagaLifecycleState: input.sagaLifecycleState,
85
89
  sagaShutdownDrainTimeouts: input.sagaShutdownDrainTimeouts,
86
90
  sagasDiscovered: input.sagasDiscovered,
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-setup.d.ts","sourceRoot":"","sources":["../src/test-setup.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { afterEach, vi } from 'vitest';
2
+ afterEach(() => {
3
+ vi.useRealTimers();
4
+ });
package/dist/types.d.ts CHANGED
@@ -59,7 +59,7 @@ export interface ISaga<TEvent extends IEvent = IEvent> {
59
59
  * CQRS passes this value to command handlers, query handlers, event handlers, and sagas when a
60
60
  * nested dispatch chain is active. Application code should pass the value through unchanged to
61
61
  * nested `execute(...)`, `publish(...)`, or `publishAll(...)` calls. The context intentionally
62
- * exposes no public topology fields and should not be inspected or constructed by callers.
62
+ * exposes no public topology fields, and caller-shaped objects cannot supply trusted runtime state.
63
63
  */
64
64
  export interface CqrsDispatchContext {
65
65
  }
@@ -141,6 +141,7 @@ export interface CommandBus {
141
141
  * Executes one command by resolving its discovered singleton handler.
142
142
  *
143
143
  * @param command Command instance to dispatch.
144
+ * @param context Optional CQRS dispatch context to pass through a nested dispatch.
144
145
  * @returns The handler result.
145
146
  */
146
147
  execute<TCommand extends ICommand, TResult = void>(command: TCommand, context?: CqrsDispatchContext): Promise<TResult>;
@@ -151,6 +152,7 @@ export interface QueryBus {
151
152
  * Executes one query by resolving its discovered singleton handler.
152
153
  *
153
154
  * @param query Query instance to dispatch.
155
+ * @param context Optional CQRS dispatch context to pass through a nested dispatch.
154
156
  * @returns The handler result.
155
157
  */
156
158
  execute<TQuery extends IQuery<TResult>, TResult = unknown>(query: TQuery, context?: CqrsDispatchContext): Promise<TResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,2EAA2E;AAC3E,MAAM,WAAW,QAAQ;CAAG;AAE5B,mGAAmG;AACnG,MAAM,WAAW,MAAM,CAAC,OAAO,GAAG,OAAO;IACvC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACxC;AAED,yFAAyF;AACzF,MAAM,WAAW,MAAM;CAAG;AAE1B,6EAA6E;AAC7E,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,QAAQ,EAAE,OAAO,GAAG,IAAI;IACxE;;;;;;OAMG;IACH,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvF;AAED,2EAA2E;AAC3E,MAAM,WAAW,aAAa,CAAC,MAAM,SAAS,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO;IAC9E;;;;;;OAMG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnF;AAED,2EAA2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Q,CAAC;CACtB;AAED,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,QAAQ,CAAC;CACtB;AAED,0DAA0D;AAC1D,MAAM,WAAW,UAAU;IACzB;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,SAAS,QAAQ,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxH;AAED,wDAAwD;AACxD,MAAM,WAAW,QAAQ;IACvB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,SAAS,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5H;AAED,0DAA0D;AAC1D,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5F;;;;;;OAMG;IACH,UAAU,CAAC,MAAM,SAAS,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5G"}
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "saga",
10
10
  "event-sourcing"
11
11
  ],
12
- "version": "1.1.2",
12
+ "version": "3.0.0",
13
13
  "private": false,
14
14
  "license": "MIT",
15
15
  "repository": {
@@ -18,7 +18,7 @@
18
18
  "directory": "packages/cqrs"
19
19
  },
20
20
  "engines": {
21
- "node": ">=20.0.0"
21
+ "node": ">=24.0.0 <27"
22
22
  },
23
23
  "publishConfig": {
24
24
  "access": "public"
@@ -36,13 +36,13 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@fluojs/core": "^1.0.3",
40
- "@fluojs/di": "^1.1.0",
41
- "@fluojs/event-bus": "^1.0.1",
42
- "@fluojs/runtime": "^1.1.8"
39
+ "@fluojs/core": "^2.0.0",
40
+ "@fluojs/di": "^3.0.0",
41
+ "@fluojs/event-bus": "^3.0.0",
42
+ "@fluojs/runtime": "^3.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "vitest": "^3.2.4"
45
+ "vitest": "^4.1.11"
46
46
  },
47
47
  "scripts": {
48
48
  "prebuild": "node ../../tooling/scripts/clean-dist.mjs",