@fluojs/cqrs 1.0.0-beta.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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.ko.md +153 -0
  3. package/README.md +153 -0
  4. package/dist/buses/command-bus.d.ts +29 -0
  5. package/dist/buses/command-bus.d.ts.map +1 -0
  6. package/dist/buses/command-bus.js +122 -0
  7. package/dist/buses/event-bus.d.ts +49 -0
  8. package/dist/buses/event-bus.d.ts.map +1 -0
  9. package/dist/buses/event-bus.js +165 -0
  10. package/dist/buses/query-bus.d.ts +29 -0
  11. package/dist/buses/query-bus.d.ts.map +1 -0
  12. package/dist/buses/query-bus.js +122 -0
  13. package/dist/buses/saga-bus.d.ts +46 -0
  14. package/dist/buses/saga-bus.d.ts.map +1 -0
  15. package/dist/buses/saga-bus.js +225 -0
  16. package/dist/decorators.d.ts +48 -0
  17. package/dist/decorators.d.ts.map +1 -0
  18. package/dist/decorators.js +127 -0
  19. package/dist/discovery.d.ts +27 -0
  20. package/dist/discovery.d.ts.map +1 -0
  21. package/dist/discovery.js +84 -0
  22. package/dist/errors.d.ts +65 -0
  23. package/dist/errors.d.ts.map +1 -0
  24. package/dist/errors.js +99 -0
  25. package/dist/event-clone.d.ts +10 -0
  26. package/dist/event-clone.d.ts.map +1 -0
  27. package/dist/event-clone.js +15 -0
  28. package/dist/index.d.ts +11 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +9 -0
  31. package/dist/metadata.d.ts +87 -0
  32. package/dist/metadata.d.ts.map +1 -0
  33. package/dist/metadata.js +235 -0
  34. package/dist/module.d.ts +30 -0
  35. package/dist/module.d.ts.map +1 -0
  36. package/dist/module.js +74 -0
  37. package/dist/status.d.ts +17 -0
  38. package/dist/status.d.ts.map +1 -0
  39. package/dist/status.js +69 -0
  40. package/dist/tokens.d.ts +9 -0
  41. package/dist/tokens.d.ts.map +1 -0
  42. package/dist/tokens.js +6 -0
  43. package/dist/types.d.ts +161 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +1 -0
  46. package/package.json +54 -0
@@ -0,0 +1,235 @@
1
+ import { metadataSymbol } from '@fluojs/core/internal';
2
+ const commandHandlerMetadataStore = new WeakMap();
3
+ const queryHandlerMetadataStore = new WeakMap();
4
+ const eventHandlerMetadataStore = new WeakMap();
5
+ const sagaMetadataStore = new WeakMap();
6
+ const standardCommandHandlerMetadataKey = Symbol.for('fluo.cqrs.standard.command-handler');
7
+ const standardQueryHandlerMetadataKey = Symbol.for('fluo.cqrs.standard.query-handler');
8
+ const standardEventHandlerMetadataKey = Symbol.for('fluo.cqrs.standard.event-handler');
9
+ const standardSagaMetadataKey = Symbol.for('fluo.cqrs.standard.saga');
10
+ function isObjectRecord(value) {
11
+ return typeof value === 'object' && value !== null;
12
+ }
13
+ function isCommandType(value) {
14
+ return typeof value === 'function';
15
+ }
16
+ function isQueryType(value) {
17
+ return typeof value === 'function';
18
+ }
19
+ function isEventType(value) {
20
+ return typeof value === 'function';
21
+ }
22
+ function isEventTypeList(value) {
23
+ return Array.isArray(value) && value.every(eventType => isEventType(eventType));
24
+ }
25
+ function getStandardMetadataBag(target) {
26
+ const metadata = target[metadataSymbol];
27
+ return isObjectRecord(metadata) ? metadata : undefined;
28
+ }
29
+ function cloneCommandHandlerMetadata(metadata) {
30
+ return {
31
+ commandType: metadata.commandType
32
+ };
33
+ }
34
+ function cloneQueryHandlerMetadata(metadata) {
35
+ return {
36
+ queryType: metadata.queryType
37
+ };
38
+ }
39
+ function cloneEventHandlerMetadata(metadata) {
40
+ return {
41
+ eventType: metadata.eventType
42
+ };
43
+ }
44
+ function cloneSagaMetadata(metadata) {
45
+ return {
46
+ eventTypes: [...metadata.eventTypes]
47
+ };
48
+ }
49
+ function getStandardCommandHandlerMetadata(target) {
50
+ const raw = getStandardMetadataBag(target)?.[standardCommandHandlerMetadataKey];
51
+ if (!isObjectRecord(raw) || !isCommandType(raw.commandType)) {
52
+ return undefined;
53
+ }
54
+ return {
55
+ commandType: raw.commandType
56
+ };
57
+ }
58
+ function getStandardQueryHandlerMetadata(target) {
59
+ const raw = getStandardMetadataBag(target)?.[standardQueryHandlerMetadataKey];
60
+ if (!isObjectRecord(raw) || !isQueryType(raw.queryType)) {
61
+ return undefined;
62
+ }
63
+ return {
64
+ queryType: raw.queryType
65
+ };
66
+ }
67
+ function getStandardEventHandlerMetadata(target) {
68
+ const raw = getStandardMetadataBag(target)?.[standardEventHandlerMetadataKey];
69
+ if (!isObjectRecord(raw) || !isEventType(raw.eventType)) {
70
+ return undefined;
71
+ }
72
+ return {
73
+ eventType: raw.eventType
74
+ };
75
+ }
76
+ function getStandardSagaMetadata(target) {
77
+ const raw = getStandardMetadataBag(target)?.[standardSagaMetadataKey];
78
+ if (!isObjectRecord(raw) || !isEventTypeList(raw.eventTypes)) {
79
+ return undefined;
80
+ }
81
+ return {
82
+ eventTypes: [...raw.eventTypes]
83
+ };
84
+ }
85
+
86
+ /**
87
+ * Stores command-handler metadata on a class for compatibility with manual metadata registration.
88
+ *
89
+ * @param target Handler class constructor receiving the metadata.
90
+ * @param metadata Command-handler metadata to store.
91
+ */
92
+ export function defineCommandHandlerMetadata(target, metadata) {
93
+ commandHandlerMetadataStore.set(target, cloneCommandHandlerMetadata(metadata));
94
+ }
95
+
96
+ /**
97
+ * Reads command-handler metadata from either the compatibility store or standard decorator metadata.
98
+ *
99
+ * @param target Handler class constructor to inspect.
100
+ * @returns The resolved command-handler metadata, if present.
101
+ */
102
+ export function getCommandHandlerMetadata(target) {
103
+ const stored = commandHandlerMetadataStore.get(target);
104
+ const standard = getStandardCommandHandlerMetadata(target);
105
+ if (!stored && !standard) {
106
+ return undefined;
107
+ }
108
+ return cloneCommandHandlerMetadata(stored ?? standard);
109
+ }
110
+
111
+ /**
112
+ * Stores query-handler metadata on a class for compatibility with manual metadata registration.
113
+ *
114
+ * @param target Handler class constructor receiving the metadata.
115
+ * @param metadata Query-handler metadata to store.
116
+ */
117
+ export function defineQueryHandlerMetadata(target, metadata) {
118
+ queryHandlerMetadataStore.set(target, cloneQueryHandlerMetadata(metadata));
119
+ }
120
+
121
+ /**
122
+ * Reads query-handler metadata from either the compatibility store or standard decorator metadata.
123
+ *
124
+ * @param target Handler class constructor to inspect.
125
+ * @returns The resolved query-handler metadata, if present.
126
+ */
127
+ export function getQueryHandlerMetadata(target) {
128
+ const stored = queryHandlerMetadataStore.get(target);
129
+ const standard = getStandardQueryHandlerMetadata(target);
130
+ if (!stored && !standard) {
131
+ return undefined;
132
+ }
133
+ return cloneQueryHandlerMetadata(stored ?? standard);
134
+ }
135
+
136
+ /**
137
+ * Stores event-handler metadata on a class for compatibility with manual metadata registration.
138
+ *
139
+ * @param target Handler class constructor receiving the metadata.
140
+ * @param metadata Event-handler metadata to store.
141
+ */
142
+ export function defineEventHandlerMetadata(target, metadata) {
143
+ eventHandlerMetadataStore.set(target, cloneEventHandlerMetadata(metadata));
144
+ }
145
+
146
+ /**
147
+ * Reads event-handler metadata from either the compatibility store or standard decorator metadata.
148
+ *
149
+ * @param target Handler class constructor to inspect.
150
+ * @returns The resolved event-handler metadata, if present.
151
+ */
152
+ export function getEventHandlerMetadata(target) {
153
+ const stored = eventHandlerMetadataStore.get(target);
154
+ const standard = getStandardEventHandlerMetadata(target);
155
+ if (!stored && !standard) {
156
+ return undefined;
157
+ }
158
+ return cloneEventHandlerMetadata(stored ?? standard);
159
+ }
160
+
161
+ /**
162
+ * Stores saga metadata on a class for compatibility with manual metadata registration.
163
+ *
164
+ * @param target Saga class constructor receiving the metadata.
165
+ * @param metadata Saga metadata to store.
166
+ */
167
+ export function defineSagaMetadata(target, metadata) {
168
+ sagaMetadataStore.set(target, cloneSagaMetadata(metadata));
169
+ }
170
+
171
+ /**
172
+ * Reads saga metadata from either the compatibility store or standard decorator metadata.
173
+ *
174
+ * @param target Saga class constructor to inspect.
175
+ * @returns The resolved saga metadata, if present.
176
+ */
177
+ export function getSagaMetadata(target) {
178
+ const stored = sagaMetadataStore.get(target);
179
+ const standard = getStandardSagaMetadata(target);
180
+ if (!stored && !standard) {
181
+ return undefined;
182
+ }
183
+ return cloneSagaMetadata(stored ?? standard);
184
+ }
185
+
186
+ /**
187
+ * Returns the normalized command-handler metadata entry used by public-surface tests and tooling.
188
+ *
189
+ * @param target Handler instance or prototype whose constructor should be inspected.
190
+ * @returns The command-handler metadata entry for the canonical `execute` method, if present.
191
+ */
192
+ export function getCommandHandlerMetadataEntry(target) {
193
+ const constructor = target.constructor;
194
+ if (!constructor) {
195
+ return undefined;
196
+ }
197
+ const metadata = getCommandHandlerMetadata(constructor);
198
+ if (!metadata) {
199
+ return undefined;
200
+ }
201
+ return {
202
+ metadata,
203
+ propertyKey: 'execute'
204
+ };
205
+ }
206
+
207
+ /**
208
+ * Returns the normalized query-handler metadata entry used by public-surface tests and tooling.
209
+ *
210
+ * @param target Handler instance or prototype whose constructor should be inspected.
211
+ * @returns The query-handler metadata entry for the canonical `execute` method, if present.
212
+ */
213
+ export function getQueryHandlerMetadataEntry(target) {
214
+ const constructor = target.constructor;
215
+ if (!constructor) {
216
+ return undefined;
217
+ }
218
+ const metadata = getQueryHandlerMetadata(constructor);
219
+ if (!metadata) {
220
+ return undefined;
221
+ }
222
+ return {
223
+ metadata,
224
+ propertyKey: 'execute'
225
+ };
226
+ }
227
+
228
+ /** Standard decorator metadata key used to store command-handler metadata. */
229
+ export const commandHandlerMetadataSymbol = standardCommandHandlerMetadataKey;
230
+ /** Standard decorator metadata key used to store query-handler metadata. */
231
+ export const queryHandlerMetadataSymbol = standardQueryHandlerMetadataKey;
232
+ /** Standard decorator metadata key used to store event-handler metadata. */
233
+ export const eventHandlerMetadataSymbol = standardEventHandlerMetadataKey;
234
+ /** Standard decorator metadata key used to store saga metadata. */
235
+ export const sagaMetadataSymbol = standardSagaMetadataKey;
@@ -0,0 +1,30 @@
1
+ import type { Provider } from '@fluojs/di';
2
+ import { type EventBusModuleOptions } from '@fluojs/event-bus';
3
+ import { type ModuleType } from '@fluojs/runtime';
4
+ import type { CommandHandlerClass, EventHandlerClass, QueryHandlerClass, SagaClass } from './types.js';
5
+ /** Module options for registering first-party handler classes and event-bus integration. */
6
+ export interface CqrsModuleOptions {
7
+ commandHandlers?: readonly CommandHandlerClass[];
8
+ eventBus?: EventBusModuleOptions;
9
+ eventHandlers?: readonly EventHandlerClass[];
10
+ queryHandlers?: readonly QueryHandlerClass[];
11
+ sagas?: readonly SagaClass[];
12
+ }
13
+ /**
14
+ * Creates the providers required for CQRS buses, compatibility aliases, and optional handler registration.
15
+ *
16
+ * @param options CQRS module options including eager handler classes and event-bus configuration.
17
+ * @returns Providers for the command, query, event, and saga runtimes plus compatibility tokens.
18
+ */
19
+ export declare function createCqrsProviders(options?: CqrsModuleOptions): Provider[];
20
+ /** Runtime module entrypoint for CQRS bus registration and handler discovery. */
21
+ export declare class CqrsModule {
22
+ /**
23
+ * Registers the CQRS buses globally and wires them to the event-bus integration.
24
+ *
25
+ * @param options CQRS module options including explicit handler classes and event-bus settings.
26
+ * @returns A module definition that exports the lifecycle services and compatibility tokens.
27
+ */
28
+ static forRoot(options?: CqrsModuleOptions): ModuleType;
29
+ }
30
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAOhE,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EAIjB,iBAAiB,EACjB,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,4FAA4F;AAC5F,MAAM,WAAW,iBAAiB;IAChC,eAAe,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACjD,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,aAAa,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC7C,aAAa,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC7C,KAAK,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;CAC9B;AAwBD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,iBAAsB,GAAG,QAAQ,EAAE,CA8B/E;AAED,iFAAiF;AACjF,qBAAa,UAAU;IACrB;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU;CAiB5D"}
package/dist/module.js ADDED
@@ -0,0 +1,74 @@
1
+ import { EventBusModule } from '@fluojs/event-bus';
2
+ import { defineModule } from '@fluojs/runtime';
3
+ import { CommandBusLifecycleService } from './buses/command-bus.js';
4
+ import { CqrsEventBusService } from './buses/event-bus.js';
5
+ import { QueryBusLifecycleService } from './buses/query-bus.js';
6
+ import { CqrsSagaLifecycleService } from './buses/saga-bus.js';
7
+ import { COMMAND_BUS, EVENT_BUS, QUERY_BUS } from './tokens.js';
8
+
9
+ /** Module options for registering first-party handler classes and event-bus integration. */
10
+
11
+ function collectOptionHandlerProviders(options) {
12
+ const providers = [];
13
+ for (const commandHandler of options.commandHandlers ?? []) {
14
+ providers.push(commandHandler);
15
+ }
16
+ for (const queryHandler of options.queryHandlers ?? []) {
17
+ providers.push(queryHandler);
18
+ }
19
+ for (const eventHandler of options.eventHandlers ?? []) {
20
+ providers.push(eventHandler);
21
+ }
22
+ for (const saga of options.sagas ?? []) {
23
+ providers.push(saga);
24
+ }
25
+ return providers;
26
+ }
27
+
28
+ /**
29
+ * Creates the providers required for CQRS buses, compatibility aliases, and optional handler registration.
30
+ *
31
+ * @param options CQRS module options including eager handler classes and event-bus configuration.
32
+ * @returns Providers for the command, query, event, and saga runtimes plus compatibility tokens.
33
+ */
34
+ export function createCqrsProviders(options = {}) {
35
+ return [CommandBusLifecycleService, {
36
+ inject: [CommandBusLifecycleService],
37
+ provide: COMMAND_BUS,
38
+ useFactory: service => ({
39
+ execute: command => service.execute(command)
40
+ })
41
+ }, QueryBusLifecycleService, {
42
+ inject: [QueryBusLifecycleService],
43
+ provide: QUERY_BUS,
44
+ useFactory: service => ({
45
+ execute: query => service.execute(query)
46
+ })
47
+ }, CqrsSagaLifecycleService, CqrsEventBusService, {
48
+ inject: [CqrsEventBusService],
49
+ provide: EVENT_BUS,
50
+ useFactory: service => ({
51
+ publish: event => service.publish(event),
52
+ publishAll: events => service.publishAll(events)
53
+ })
54
+ }, ...collectOptionHandlerProviders(options)];
55
+ }
56
+
57
+ /** Runtime module entrypoint for CQRS bus registration and handler discovery. */
58
+ export class CqrsModule {
59
+ /**
60
+ * Registers the CQRS buses globally and wires them to the event-bus integration.
61
+ *
62
+ * @param options CQRS module options including explicit handler classes and event-bus settings.
63
+ * @returns A module definition that exports the lifecycle services and compatibility tokens.
64
+ */
65
+ static forRoot(options = {}) {
66
+ class CqrsModuleDefinition {}
67
+ return defineModule(CqrsModuleDefinition, {
68
+ exports: [CommandBusLifecycleService, QueryBusLifecycleService, CqrsEventBusService, COMMAND_BUS, QUERY_BUS, EVENT_BUS],
69
+ global: true,
70
+ imports: [EventBusModule.forRoot(options.eventBus)],
71
+ providers: createCqrsProviders(options)
72
+ });
73
+ }
74
+ }
@@ -0,0 +1,17 @@
1
+ import type { PlatformHealthReport, PlatformReadinessReport, PlatformSnapshot } from '@fluojs/runtime';
2
+ export type CqrsLifecycleState = 'created' | 'discovering' | 'ready' | 'stopping' | 'stopped' | 'failed';
3
+ export interface CqrsStatusAdapterInput {
4
+ eventHandlersDiscovered: number;
5
+ inFlightSagaExecutions: number;
6
+ lifecycleState: CqrsLifecycleState;
7
+ sagaLifecycleState: CqrsLifecycleState;
8
+ sagasDiscovered: number;
9
+ }
10
+ export interface CqrsPlatformStatusSnapshot {
11
+ readiness: PlatformReadinessReport;
12
+ health: PlatformHealthReport;
13
+ ownership: PlatformSnapshot['ownership'];
14
+ details: Record<string, unknown>;
15
+ }
16
+ export declare function createCqrsPlatformStatusSnapshot(input: CqrsStatusAdapterInput): CqrsPlatformStatusSnapshot;
17
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +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,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEzG,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,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,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;AA4ED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,sBAAsB,GAAG,0BAA0B,CAiB1G"}
package/dist/status.js ADDED
@@ -0,0 +1,69 @@
1
+ function createReadiness(input) {
2
+ if (input.lifecycleState === 'ready' && input.sagaLifecycleState === 'ready') {
3
+ return {
4
+ critical: true,
5
+ status: 'ready'
6
+ };
7
+ }
8
+ if (input.lifecycleState === 'discovering' || input.sagaLifecycleState === 'discovering') {
9
+ return {
10
+ critical: true,
11
+ reason: 'CQRS handlers are still being discovered.',
12
+ status: 'degraded'
13
+ };
14
+ }
15
+ if (input.lifecycleState === 'stopping' || input.sagaLifecycleState === 'stopping') {
16
+ return {
17
+ critical: true,
18
+ reason: 'CQRS event/saga pipeline is draining.',
19
+ status: 'not-ready'
20
+ };
21
+ }
22
+ if (input.lifecycleState === 'failed' || input.sagaLifecycleState === 'failed' || input.lifecycleState === 'stopped' || input.sagaLifecycleState === 'stopped') {
23
+ return {
24
+ critical: true,
25
+ reason: 'CQRS event/saga pipeline is unavailable.',
26
+ status: 'not-ready'
27
+ };
28
+ }
29
+ return {
30
+ critical: true,
31
+ reason: 'CQRS event/saga pipeline has not started yet.',
32
+ status: 'not-ready'
33
+ };
34
+ }
35
+ function createHealth(input) {
36
+ if (input.lifecycleState === 'failed' || input.sagaLifecycleState === 'failed' || input.lifecycleState === 'stopped' || input.sagaLifecycleState === 'stopped') {
37
+ return {
38
+ reason: 'CQRS event/saga pipeline is unavailable.',
39
+ status: 'unhealthy'
40
+ };
41
+ }
42
+ if (input.lifecycleState === 'discovering' || input.sagaLifecycleState === 'discovering' || input.lifecycleState === 'stopping' || input.sagaLifecycleState === 'stopping') {
43
+ return {
44
+ reason: 'CQRS event/saga pipeline is transitioning lifecycle state.',
45
+ status: 'degraded'
46
+ };
47
+ }
48
+ return {
49
+ status: 'healthy'
50
+ };
51
+ }
52
+ export function createCqrsPlatformStatusSnapshot(input) {
53
+ return {
54
+ details: {
55
+ dependencies: ['event-bus.default'],
56
+ eventHandlersDiscovered: input.eventHandlersDiscovered,
57
+ inFlightSagaExecutions: input.inFlightSagaExecutions,
58
+ lifecycleState: input.lifecycleState,
59
+ sagaLifecycleState: input.sagaLifecycleState,
60
+ sagasDiscovered: input.sagasDiscovered
61
+ },
62
+ health: createHealth(input),
63
+ ownership: {
64
+ externallyManaged: false,
65
+ ownsResources: false
66
+ },
67
+ readiness: createReadiness(input)
68
+ };
69
+ }
@@ -0,0 +1,9 @@
1
+ import type { Token } from '@fluojs/core';
2
+ import type { CommandBus, CqrsEventBus, QueryBus } from './types.js';
3
+ /** Compatibility injection token for the command bus facade. */
4
+ export declare const COMMAND_BUS: Token<CommandBus>;
5
+ /** Compatibility injection token for the query bus facade. */
6
+ export declare const QUERY_BUS: Token<QueryBus>;
7
+ /** Compatibility injection token for the CQRS event bus facade. */
8
+ export declare const EVENT_BUS: Token<CqrsEventBus>;
9
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAErE,gEAAgE;AAChE,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,UAAU,CAAuC,CAAC;AAClF,8DAA8D;AAC9D,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAqC,CAAC;AAC5E,mEAAmE;AACnE,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,YAAY,CAAqC,CAAC"}
package/dist/tokens.js ADDED
@@ -0,0 +1,6 @@
1
+ /** Compatibility injection token for the command bus facade. */
2
+ export const COMMAND_BUS = Symbol.for('fluo.cqrs.command-bus');
3
+ /** Compatibility injection token for the query bus facade. */
4
+ export const QUERY_BUS = Symbol.for('fluo.cqrs.query-bus');
5
+ /** Compatibility injection token for the CQRS event bus facade. */
6
+ export const EVENT_BUS = Symbol.for('fluo.cqrs.event-bus');
@@ -0,0 +1,161 @@
1
+ import type { Token } from '@fluojs/core';
2
+ /** Marker interface for command messages handled by {@link CommandBus}. */
3
+ export interface ICommand {
4
+ }
5
+ /** Marker interface for query messages whose response type is carried in the generic parameter. */
6
+ export interface IQuery<TResult = unknown> {
7
+ readonly __queryResultType__?: TResult;
8
+ }
9
+ /** Marker interface for events published through the CQRS event bus. */
10
+ export interface IEvent {
11
+ }
12
+ /** Contract implemented by classes decorated with {@link CommandHandler}. */
13
+ export interface ICommandHandler<TCommand extends ICommand, TResult = void> {
14
+ /**
15
+ * Executes one command instance.
16
+ *
17
+ * @param command Command payload to handle.
18
+ * @returns The handler result returned to the command bus caller.
19
+ */
20
+ execute(command: TCommand): TResult | Promise<TResult>;
21
+ }
22
+ /** Contract implemented by classes decorated with {@link QueryHandler}. */
23
+ export interface IQueryHandler<TQuery extends IQuery<TResult>, TResult = unknown> {
24
+ /**
25
+ * Executes one query instance.
26
+ *
27
+ * @param query Query payload to handle.
28
+ * @returns The query result returned to the caller.
29
+ */
30
+ execute(query: TQuery): TResult | Promise<TResult>;
31
+ }
32
+ /** Contract implemented by classes decorated with {@link EventHandler}. */
33
+ export interface IEventHandler<TEvent extends IEvent> {
34
+ /**
35
+ * Reacts to one published event instance.
36
+ *
37
+ * @param event Event payload dispatched by the event bus.
38
+ * @returns A promise or void once side effects complete.
39
+ */
40
+ handle(event: TEvent): void | Promise<void>;
41
+ }
42
+ /** Contract implemented by classes decorated with {@link Saga}. */
43
+ export interface ISaga<TEvent extends IEvent = IEvent> {
44
+ /**
45
+ * Reacts to one event and typically emits follow-up commands.
46
+ *
47
+ * @param event Event payload that triggered the saga.
48
+ * @returns A promise or void once orchestration side effects complete.
49
+ */
50
+ handle(event: TEvent): void | Promise<void>;
51
+ }
52
+ /** Constructor type used to identify a command message class. */
53
+ export interface CommandType<TCommand extends ICommand = ICommand> {
54
+ new (...args: never[]): TCommand;
55
+ }
56
+ /** Constructor type used to identify a query message class. */
57
+ export interface QueryType<TResult = unknown, TQuery extends IQuery<TResult> = IQuery<TResult>> {
58
+ new (...args: never[]): TQuery;
59
+ }
60
+ /** Constructor type used to identify an event message class. */
61
+ export interface CqrsEventType<TEvent extends IEvent = IEvent> {
62
+ new (...args: never[]): TEvent;
63
+ }
64
+ /** Class constructor accepted in {@link CqrsModuleOptions.commandHandlers}. */
65
+ export interface CommandHandlerClass {
66
+ new (...args: never[]): object;
67
+ }
68
+ /** Class constructor accepted in {@link CqrsModuleOptions.queryHandlers}. */
69
+ export interface QueryHandlerClass {
70
+ new (...args: never[]): object;
71
+ }
72
+ /** Class constructor accepted in {@link CqrsModuleOptions.eventHandlers}. */
73
+ export interface EventHandlerClass {
74
+ new (...args: never[]): object;
75
+ }
76
+ /** Class constructor accepted in {@link CqrsModuleOptions.sagas}. */
77
+ export interface SagaClass {
78
+ new (...args: never[]): object;
79
+ }
80
+ /** Metadata stored by {@link CommandHandler}. */
81
+ export interface CommandHandlerMetadata {
82
+ commandType: CommandType;
83
+ }
84
+ /** Metadata stored by {@link QueryHandler}. */
85
+ export interface QueryHandlerMetadata {
86
+ queryType: QueryType;
87
+ }
88
+ /** Metadata stored by {@link EventHandler}. */
89
+ export interface EventHandlerMetadata {
90
+ eventType: CqrsEventType;
91
+ }
92
+ /** Metadata stored by {@link Saga}. */
93
+ export interface SagaMetadata {
94
+ eventTypes: readonly CqrsEventType[];
95
+ }
96
+ /** Runtime descriptor for one discovered command handler. */
97
+ export interface CommandHandlerDescriptor {
98
+ commandType: CommandType;
99
+ moduleName: string;
100
+ token: Token;
101
+ targetType: Function;
102
+ }
103
+ /** Runtime descriptor for one discovered query handler. */
104
+ export interface QueryHandlerDescriptor {
105
+ moduleName: string;
106
+ queryType: QueryType;
107
+ token: Token;
108
+ targetType: Function;
109
+ }
110
+ /** Runtime descriptor for one discovered event handler. */
111
+ export interface EventHandlerDescriptor {
112
+ eventType: CqrsEventType;
113
+ moduleName: string;
114
+ token: Token;
115
+ targetType: Function;
116
+ }
117
+ /** Runtime descriptor for one discovered saga listener. */
118
+ export interface SagaDescriptor {
119
+ eventType: CqrsEventType;
120
+ moduleName: string;
121
+ token: Token;
122
+ targetType: Function;
123
+ }
124
+ /** Command dispatch facade exposed by the CQRS module. */
125
+ export interface CommandBus {
126
+ /**
127
+ * Executes one command by resolving its discovered singleton handler.
128
+ *
129
+ * @param command Command instance to dispatch.
130
+ * @returns The handler result.
131
+ */
132
+ execute<TCommand extends ICommand, TResult = void>(command: TCommand): Promise<TResult>;
133
+ }
134
+ /** Query dispatch facade exposed by the CQRS module. */
135
+ export interface QueryBus {
136
+ /**
137
+ * Executes one query by resolving its discovered singleton handler.
138
+ *
139
+ * @param query Query instance to dispatch.
140
+ * @returns The handler result.
141
+ */
142
+ execute<TQuery extends IQuery<TResult>, TResult = unknown>(query: TQuery): Promise<TResult>;
143
+ }
144
+ /** Event publishing facade exposed by the CQRS module. */
145
+ export interface CqrsEventBus {
146
+ /**
147
+ * Publishes one event to the underlying event bus.
148
+ *
149
+ * @param event Event instance to publish.
150
+ * @returns A promise that resolves once publication completes.
151
+ */
152
+ publish<TEvent extends IEvent>(event: TEvent): Promise<void>;
153
+ /**
154
+ * Publishes a batch of events in order.
155
+ *
156
+ * @param events Event instances to publish.
157
+ * @returns A promise that resolves once all events are published.
158
+ */
159
+ publishAll<TEvent extends IEvent>(events: readonly TEvent[]): Promise<void>;
160
+ }
161
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,wEAAwE;AACxE,MAAM,WAAW,MAAM;CAAG;AAE1B,6EAA6E;AAC7E,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,QAAQ,EAAE,OAAO,GAAG,IAAI;IACxE;;;;;OAKG;IACH,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxD;AAED,2EAA2E;AAC3E,MAAM,WAAW,aAAa,CAAC,MAAM,SAAS,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO;IAC9E;;;;;OAKG;IACH,OAAO,CAAC,KAAK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