@zudojs/cqrs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/dist/command/command.core.d.ts +47 -0
- package/dist/command/command.core.d.ts.map +1 -0
- package/dist/command/command.core.js +58 -0
- package/dist/command/command.core.js.map +1 -0
- package/dist/command/commandBus.core.d.ts +91 -0
- package/dist/command/commandBus.core.d.ts.map +1 -0
- package/dist/command/commandBus.core.js +177 -0
- package/dist/command/commandBus.core.js.map +1 -0
- package/dist/command/commandHandler.core.d.ts +43 -0
- package/dist/command/commandHandler.core.d.ts.map +1 -0
- package/dist/command/commandHandler.core.js +57 -0
- package/dist/command/commandHandler.core.js.map +1 -0
- package/dist/command/commandResult.type.d.ts +57 -0
- package/dist/command/commandResult.type.d.ts.map +1 -0
- package/dist/command/commandResult.type.js +86 -0
- package/dist/command/commandResult.type.js.map +1 -0
- package/dist/command/index.d.ts +10 -0
- package/dist/command/index.d.ts.map +1 -0
- package/dist/command/index.js +10 -0
- package/dist/command/index.js.map +1 -0
- package/dist/cqrsContext/cqrsContext.core.d.ts +97 -0
- package/dist/cqrsContext/cqrsContext.core.d.ts.map +1 -0
- package/dist/cqrsContext/cqrsContext.core.js +171 -0
- package/dist/cqrsContext/cqrsContext.core.js.map +1 -0
- package/dist/cqrsContext/index.d.ts +7 -0
- package/dist/cqrsContext/index.d.ts.map +1 -0
- package/dist/cqrsContext/index.js +7 -0
- package/dist/cqrsContext/index.js.map +1 -0
- package/dist/cqrsDecorators/cqrsDecorators.core.d.ts +108 -0
- package/dist/cqrsDecorators/cqrsDecorators.core.d.ts.map +1 -0
- package/dist/cqrsDecorators/cqrsDecorators.core.js +181 -0
- package/dist/cqrsDecorators/cqrsDecorators.core.js.map +1 -0
- package/dist/cqrsDecorators/index.d.ts +7 -0
- package/dist/cqrsDecorators/index.d.ts.map +1 -0
- package/dist/cqrsDecorators/index.js +7 -0
- package/dist/cqrsDecorators/index.js.map +1 -0
- package/dist/cqrsErrors/cqrsError.base.d.ts +85 -0
- package/dist/cqrsErrors/cqrsError.base.d.ts.map +1 -0
- package/dist/cqrsErrors/cqrsError.base.js +221 -0
- package/dist/cqrsErrors/cqrsError.base.js.map +1 -0
- package/dist/cqrsErrors/index.d.ts +7 -0
- package/dist/cqrsErrors/index.d.ts.map +1 -0
- package/dist/cqrsErrors/index.js +7 -0
- package/dist/cqrsErrors/index.js.map +1 -0
- package/dist/cqrsEvents/cqrsEventBus.core.d.ts +9 -0
- package/dist/cqrsEvents/cqrsEventBus.core.d.ts.map +1 -0
- package/dist/cqrsEvents/cqrsEventBus.core.js +9 -0
- package/dist/cqrsEvents/cqrsEventBus.core.js.map +1 -0
- package/dist/cqrsEvents/cqrsEventResult.type.d.ts +81 -0
- package/dist/cqrsEvents/cqrsEventResult.type.d.ts.map +1 -0
- package/dist/cqrsEvents/cqrsEventResult.type.js +159 -0
- package/dist/cqrsEvents/cqrsEventResult.type.js.map +1 -0
- package/dist/cqrsEvents/cqrsEvents.type.d.ts +102 -0
- package/dist/cqrsEvents/cqrsEvents.type.d.ts.map +1 -0
- package/dist/cqrsEvents/cqrsEvents.type.js +103 -0
- package/dist/cqrsEvents/cqrsEvents.type.js.map +1 -0
- package/dist/cqrsEvents/index.d.ts +12 -0
- package/dist/cqrsEvents/index.d.ts.map +1 -0
- package/dist/cqrsEvents/index.js +12 -0
- package/dist/cqrsEvents/index.js.map +1 -0
- package/dist/cqrsMiddleware/cqrsMiddleware.core.d.ts +65 -0
- package/dist/cqrsMiddleware/cqrsMiddleware.core.d.ts.map +1 -0
- package/dist/cqrsMiddleware/cqrsMiddleware.core.js +185 -0
- package/dist/cqrsMiddleware/cqrsMiddleware.core.js.map +1 -0
- package/dist/cqrsMiddleware/index.d.ts +7 -0
- package/dist/cqrsMiddleware/index.d.ts.map +1 -0
- package/dist/cqrsMiddleware/index.js +7 -0
- package/dist/cqrsMiddleware/index.js.map +1 -0
- package/dist/cqrsTypes/cqrsTypes.type.d.ts +158 -0
- package/dist/cqrsTypes/cqrsTypes.type.d.ts.map +1 -0
- package/dist/cqrsTypes/cqrsTypes.type.js +34 -0
- package/dist/cqrsTypes/cqrsTypes.type.js.map +1 -0
- package/dist/cqrsTypes/index.d.ts +7 -0
- package/dist/cqrsTypes/index.d.ts.map +1 -0
- package/dist/cqrsTypes/index.js +7 -0
- package/dist/cqrsTypes/index.js.map +1 -0
- package/dist/handlerRegistry/handlerRegistry.core.d.ts +135 -0
- package/dist/handlerRegistry/handlerRegistry.core.d.ts.map +1 -0
- package/dist/handlerRegistry/handlerRegistry.core.js +209 -0
- package/dist/handlerRegistry/handlerRegistry.core.js.map +1 -0
- package/dist/handlerRegistry/index.d.ts +7 -0
- package/dist/handlerRegistry/index.d.ts.map +1 -0
- package/dist/handlerRegistry/index.js +7 -0
- package/dist/handlerRegistry/index.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/query/index.d.ts +10 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +10 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/query.core.d.ts +50 -0
- package/dist/query/query.core.d.ts.map +1 -0
- package/dist/query/query.core.js +61 -0
- package/dist/query/query.core.js.map +1 -0
- package/dist/query/queryBus.core.d.ts +91 -0
- package/dist/query/queryBus.core.d.ts.map +1 -0
- package/dist/query/queryBus.core.js +177 -0
- package/dist/query/queryBus.core.js.map +1 -0
- package/dist/query/queryHandler.core.d.ts +43 -0
- package/dist/query/queryHandler.core.d.ts.map +1 -0
- package/dist/query/queryHandler.core.js +57 -0
- package/dist/query/queryHandler.core.js.map +1 -0
- package/dist/query/queryResult.type.d.ts +56 -0
- package/dist/query/queryResult.type.d.ts.map +1 -0
- package/dist/query/queryResult.type.js +86 -0
- package/dist/query/queryResult.type.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a successful command result.
|
|
3
|
+
*/
|
|
4
|
+
export function createCommandResult(result, options) {
|
|
5
|
+
const command = options.command;
|
|
6
|
+
validateCommand(command);
|
|
7
|
+
const commandResult = {
|
|
8
|
+
status: "success",
|
|
9
|
+
result,
|
|
10
|
+
commandType: command.type,
|
|
11
|
+
executedAt: options.executedAt ?? new Date(),
|
|
12
|
+
durationMs: options.durationMs,
|
|
13
|
+
metadata: options.metadata
|
|
14
|
+
? Object.freeze({
|
|
15
|
+
...options.metadata,
|
|
16
|
+
})
|
|
17
|
+
: undefined,
|
|
18
|
+
};
|
|
19
|
+
return Object.freeze(commandResult);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a failed command result.
|
|
23
|
+
*
|
|
24
|
+
* This helper is intended for infrastructure that represents failures
|
|
25
|
+
* as values. Command buses normally throw errors instead.
|
|
26
|
+
*/
|
|
27
|
+
export function createFailedCommandResult(result, options) {
|
|
28
|
+
const command = options.command;
|
|
29
|
+
validateCommand(command);
|
|
30
|
+
const commandResult = {
|
|
31
|
+
status: "failure",
|
|
32
|
+
result,
|
|
33
|
+
commandType: command.type,
|
|
34
|
+
executedAt: options.executedAt ?? new Date(),
|
|
35
|
+
durationMs: options.durationMs,
|
|
36
|
+
metadata: options.metadata
|
|
37
|
+
? Object.freeze({
|
|
38
|
+
...options.metadata,
|
|
39
|
+
})
|
|
40
|
+
: undefined,
|
|
41
|
+
};
|
|
42
|
+
return Object.freeze(commandResult);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Determines whether a command result represents success.
|
|
46
|
+
*/
|
|
47
|
+
export function isSuccessfulCommandResult(result) {
|
|
48
|
+
return result.status === "success";
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Determines whether a command result represents failure.
|
|
52
|
+
*/
|
|
53
|
+
export function isFailedCommandResult(result) {
|
|
54
|
+
return result.status === "failure";
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Maps a command result to its underlying value.
|
|
58
|
+
*/
|
|
59
|
+
export function unwrapCommandResult(result) {
|
|
60
|
+
return result.result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Adds execution metadata to an existing command result.
|
|
64
|
+
*/
|
|
65
|
+
export function withCommandResultMetadata(result, metadata) {
|
|
66
|
+
const merged = {
|
|
67
|
+
...result,
|
|
68
|
+
metadata: Object.freeze({
|
|
69
|
+
...(result.metadata ?? {}),
|
|
70
|
+
...metadata,
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
return Object.freeze(merged);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Validates the command portion of a command result.
|
|
77
|
+
*/
|
|
78
|
+
function validateCommand(command) {
|
|
79
|
+
if (!command || typeof command !== "object") {
|
|
80
|
+
throw new TypeError("A valid command is required to create a command result.");
|
|
81
|
+
}
|
|
82
|
+
if (typeof command.type !== "string" || command.type.trim().length === 0) {
|
|
83
|
+
throw new TypeError("Command type is required to create a command result.");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=commandResult.type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandResult.type.js","sourceRoot":"","sources":["../../src/command/commandResult.type.ts"],"names":[],"mappings":"AAsCA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAe,EACf,OAA6C;IAE7C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAEhC,eAAe,CAAC,OAAO,CAAC,CAAC;IAEzB,MAAM,aAAa,GAAqC;QACtD,MAAM,EAAE,SAAS;QACjB,MAAM;QACN,WAAW,EAAE,OAAO,CAAC,IAAI;QACzB,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,IAAI,IAAI,EAAE;QAC5C,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,QAAQ,EAAE,OAAO,CAAC,QAAQ;YACxB,CAAC,CAAC,MAAM,CA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AAM,CAAC,QAAQ,IAAI,EAAE,CAAC;YAC1B,GAAG,QAAQ;SACZ,CAAC;KACH,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,OAAgB;IACvC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,MAAM,IAAI,SAAS,CACjB,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,SAAS,CAAC,sDAAsD,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/cqrs/command
|
|
3
|
+
*
|
|
4
|
+
* Command implementation: abstract command, handler, bus, and result types.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./command.core.js";
|
|
7
|
+
export * from "./commandHandler.core.js";
|
|
8
|
+
export * from "./commandBus.core.js";
|
|
9
|
+
export * from "./commandResult.type.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/command/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/cqrs/command
|
|
3
|
+
*
|
|
4
|
+
* Command implementation: abstract command, handler, bus, and result types.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./command.core.js";
|
|
7
|
+
export * from "./commandHandler.core.js";
|
|
8
|
+
export * from "./commandBus.core.js";
|
|
9
|
+
export * from "./commandResult.type.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/command/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { CqrsContext } from "../cqrsTypes/cqrsTypes.type.js";
|
|
2
|
+
/**
|
|
3
|
+
* Standard execution context for CQRS operations.
|
|
4
|
+
*
|
|
5
|
+
* The context carries request-scoped information without coupling
|
|
6
|
+
* commands, queries, or events to a specific transport.
|
|
7
|
+
*/
|
|
8
|
+
export interface CqrsExecutionContext extends CqrsContext {
|
|
9
|
+
readonly requestId?: string;
|
|
10
|
+
readonly correlationId?: string;
|
|
11
|
+
readonly causationId?: string;
|
|
12
|
+
readonly userId?: string;
|
|
13
|
+
readonly tenantId?: string;
|
|
14
|
+
readonly source?: string;
|
|
15
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Input used to create an execution context.
|
|
19
|
+
*/
|
|
20
|
+
export interface CreateExecutionContextInput {
|
|
21
|
+
readonly requestId?: string;
|
|
22
|
+
readonly correlationId?: string;
|
|
23
|
+
readonly causationId?: string;
|
|
24
|
+
readonly userId?: string;
|
|
25
|
+
readonly tenantId?: string;
|
|
26
|
+
readonly source?: string;
|
|
27
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a unique request identifier.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createRequestId(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an immutable CQRS execution context.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createExecutionContext(input?: CreateExecutionContextInput): CqrsExecutionContext;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a child execution context while preserving correlation data.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createChildExecutionContext(parent: CqrsExecutionContext, overrides?: CreateExecutionContextInput): CqrsExecutionContext;
|
|
41
|
+
/**
|
|
42
|
+
* Adds metadata to an execution context.
|
|
43
|
+
*/
|
|
44
|
+
export declare function withContextMetadata(context: CqrsExecutionContext, metadata: Readonly<Record<string, unknown>>): CqrsExecutionContext;
|
|
45
|
+
/**
|
|
46
|
+
* Adds or replaces the current user identity.
|
|
47
|
+
*/
|
|
48
|
+
export declare function withUser(context: CqrsExecutionContext, userId: string): CqrsExecutionContext;
|
|
49
|
+
/**
|
|
50
|
+
* Adds or replaces the current tenant identity.
|
|
51
|
+
*/
|
|
52
|
+
export declare function withTenant(context: CqrsExecutionContext, tenantId: string): CqrsExecutionContext;
|
|
53
|
+
/**
|
|
54
|
+
* Adds or replaces the source of the CQRS operation.
|
|
55
|
+
*/
|
|
56
|
+
export declare function withSource(context: CqrsExecutionContext, source: string): CqrsExecutionContext;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the request ID from the context.
|
|
59
|
+
*/
|
|
60
|
+
export declare function getRequestId(context?: CqrsExecutionContext): string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the correlation ID from the context.
|
|
63
|
+
*/
|
|
64
|
+
export declare function getCorrelationId(context?: CqrsExecutionContext): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the causation ID from the context.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getCausationId(context?: CqrsExecutionContext): string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the current user ID.
|
|
71
|
+
*/
|
|
72
|
+
export declare function getUserId(context?: CqrsExecutionContext): string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the current tenant ID.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getTenantId(context?: CqrsExecutionContext): string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Returns a context metadata value.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getContextMetadata<T = unknown>(context: CqrsExecutionContext | undefined, key: string): T | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Determines whether the context has a user identity.
|
|
83
|
+
*/
|
|
84
|
+
export declare function hasUser(context?: CqrsExecutionContext): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Determines whether the context has a tenant identity.
|
|
87
|
+
*/
|
|
88
|
+
export declare function hasTenant(context?: CqrsExecutionContext): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Determines whether two contexts belong to the same correlation chain.
|
|
91
|
+
*/
|
|
92
|
+
export declare function sharesCorrelation(first?: CqrsExecutionContext, second?: CqrsExecutionContext): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Converts an execution context into a plain serializable object.
|
|
95
|
+
*/
|
|
96
|
+
export declare function serializeExecutionContext(context: CqrsExecutionContext): Record<string, unknown>;
|
|
97
|
+
//# sourceMappingURL=cqrsContext.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cqrsContext.core.d.ts","sourceRoot":"","sources":["../../src/cqrsContext/cqrsContext.core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAElE;;;;;GAKG;AACH,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAA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AAoB,CAStB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,MAAM,GAAG,SAAS,CAEpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,MAAM,GAAG,SAAS,CAEpB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,MAAM,GAAG,SAAS,CAEpB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,GAAG,SAAS,CAE5E;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,MAAM,GAAG,SAAS,CAEpB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,OAAO,EAC5C,OAAO,EAAE,oBAAoB,GAAG,SAAS,EACzC,GAAG,EAAE,MAAM,GACV,CAAC,GAAG,SAAS,CAEf;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAE/D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAEjE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,CAAC,EAAE,oBAAoB,EAC5B,MAAM,CAAC,EAAE,oBAAoB,GAC5B,OAAO,CAMT;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAczB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a unique request identifier.
|
|
3
|
+
*/
|
|
4
|
+
export function createRequestId() {
|
|
5
|
+
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
6
|
+
return globalThis.crypto.randomUUID();
|
|
7
|
+
}
|
|
8
|
+
return `${Date.now().toString(36)}-${Math.random()
|
|
9
|
+
.toString(36)
|
|
10
|
+
.slice(2, 15)}`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates an immutable CQRS execution context.
|
|
14
|
+
*/
|
|
15
|
+
export function createExecutionContext(input = {}) {
|
|
16
|
+
const context = {
|
|
17
|
+
requestId: input.requestId ?? createRequestId(),
|
|
18
|
+
correlationId: input.correlationId,
|
|
19
|
+
causationId: input.causationId,
|
|
20
|
+
userId: input.userId,
|
|
21
|
+
tenantId: input.tenantId,
|
|
22
|
+
source: input.source,
|
|
23
|
+
metadata: input.metadata
|
|
24
|
+
? Object.freeze({
|
|
25
|
+
...input.metadata,
|
|
26
|
+
})
|
|
27
|
+
: undefined,
|
|
28
|
+
};
|
|
29
|
+
return Object.freeze(context);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a child execution context while preserving correlation data.
|
|
33
|
+
*/
|
|
34
|
+
export function createChildExecutionContext(parent, overrides = {}) {
|
|
35
|
+
return createExecutionContext({
|
|
36
|
+
requestId: overrides.requestId,
|
|
37
|
+
correlationId: overrides.correlationId ?? parent.correlationId,
|
|
38
|
+
causationId: overrides.causationId ?? parent.requestId ?? parent.causationId,
|
|
39
|
+
userId: overrides.userId ?? parent.userId,
|
|
40
|
+
tenantId: overrides.tenantId ?? parent.tenantId,
|
|
41
|
+
source: overrides.source ?? parent.source,
|
|
42
|
+
metadata: {
|
|
43
|
+
...(parent.metadata ?? {}),
|
|
44
|
+
...(overrides.metadata ?? {}),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Adds metadata to an execution context.
|
|
50
|
+
*/
|
|
51
|
+
export function withContextMetadata(context, metadata) {
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
...context,
|
|
54
|
+
metadata: Object.freeze({
|
|
55
|
+
...(context.metadata ?? {}),
|
|
56
|
+
...metadata,
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Adds or replaces the current user identity.
|
|
62
|
+
*/
|
|
63
|
+
export function withUser(context, userId) {
|
|
64
|
+
if (!userId.trim()) {
|
|
65
|
+
throw new TypeError("User ID cannot be empty.");
|
|
66
|
+
}
|
|
67
|
+
return Object.freeze({
|
|
68
|
+
...context,
|
|
69
|
+
userId,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Adds or replaces the current tenant identity.
|
|
74
|
+
*/
|
|
75
|
+
export function withTenant(context, tenantId) {
|
|
76
|
+
if (!tenantId.trim()) {
|
|
77
|
+
throw new TypeError("Tenant ID cannot be empty.");
|
|
78
|
+
}
|
|
79
|
+
return Object.freeze({
|
|
80
|
+
...context,
|
|
81
|
+
tenantId,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Adds or replaces the source of the CQRS operation.
|
|
86
|
+
*/
|
|
87
|
+
export function withSource(context, source) {
|
|
88
|
+
if (!source.trim()) {
|
|
89
|
+
throw new TypeError("Context source cannot be empty.");
|
|
90
|
+
}
|
|
91
|
+
return Object.freeze({
|
|
92
|
+
...context,
|
|
93
|
+
source,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns the request ID from the context.
|
|
98
|
+
*/
|
|
99
|
+
export function getRequestId(context) {
|
|
100
|
+
return context?.requestId;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the correlation ID from the context.
|
|
104
|
+
*/
|
|
105
|
+
export function getCorrelationId(context) {
|
|
106
|
+
return context?.correlationId;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns the causation ID from the context.
|
|
110
|
+
*/
|
|
111
|
+
export function getCausationId(context) {
|
|
112
|
+
return context?.causationId;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns the current user ID.
|
|
116
|
+
*/
|
|
117
|
+
export function getUserId(context) {
|
|
118
|
+
return context?.userId;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns the current tenant ID.
|
|
122
|
+
*/
|
|
123
|
+
export function getTenantId(context) {
|
|
124
|
+
return context?.tenantId;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns a context metadata value.
|
|
128
|
+
*/
|
|
129
|
+
export function getContextMetadata(context, key) {
|
|
130
|
+
return context?.metadata?.[key];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Determines whether the context has a user identity.
|
|
134
|
+
*/
|
|
135
|
+
export function hasUser(context) {
|
|
136
|
+
return Boolean(context?.userId);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Determines whether the context has a tenant identity.
|
|
140
|
+
*/
|
|
141
|
+
export function hasTenant(context) {
|
|
142
|
+
return Boolean(context?.tenantId);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Determines whether two contexts belong to the same correlation chain.
|
|
146
|
+
*/
|
|
147
|
+
export function sharesCorrelation(first, second) {
|
|
148
|
+
if (!first?.correlationId || !second?.correlationId) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return first.correlationId === second.correlationId;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Converts an execution context into a plain serializable object.
|
|
155
|
+
*/
|
|
156
|
+
export function serializeExecutionContext(context) {
|
|
157
|
+
return {
|
|
158
|
+
requestId: context.requestId,
|
|
159
|
+
correlationId: context.correlationId,
|
|
160
|
+
causationId: context.causationId,
|
|
161
|
+
userId: context.userId,
|
|
162
|
+
tenantId: context.tenantId,
|
|
163
|
+
source: context.source,
|
|
164
|
+
metadata: context.metadata
|
|
165
|
+
? {
|
|
166
|
+
...context.metadata,
|
|
167
|
+
}
|
|
168
|
+
: undefined,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=cqr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AC/B,KAA4B,EAC5B,MAA6B;IAE7B,IAAI,CAAC,KAAK,EAAE,aAAa,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;QACpD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC,aAAa,KAAK,MAAM,CAAC,aAAa,CAAC;AACtD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAA6B;IAE7B,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YACxB,CAAC,CAAC;gBACE,GAAG,OAAO,CAAC,QAAQ;aACpB;YACH,CAAC,CAAC,SAAS;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cqrsContext/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cqrsContext/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Command, Query } from "../cqrsTypes/cqrsTypes.type.js";
|
|
2
|
+
/**
|
|
3
|
+
* Metadata key used to identify CQRS handler configuration.
|
|
4
|
+
*/
|
|
5
|
+
declare const CQRS_HANDLER_METADATA: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Metadata key used to identify command handler configuration.
|
|
8
|
+
*/
|
|
9
|
+
declare const COMMAND_HANDLER_METADATA: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* Metadata key used to identify query handler configuration.
|
|
12
|
+
*/
|
|
13
|
+
declare const QUERY_HANDLER_METADATA: unique symbol;
|
|
14
|
+
/**
|
|
15
|
+
* Metadata key used to identify command/query type information.
|
|
16
|
+
*/
|
|
17
|
+
declare const CQRS_TYPE_METADATA: unique symbol;
|
|
18
|
+
/**
|
|
19
|
+
* Supported CQRS handler kinds.
|
|
20
|
+
*/
|
|
21
|
+
export type CqrsHandlerKind = "command" | "query";
|
|
22
|
+
/**
|
|
23
|
+
* Metadata attached to a CQRS handler class.
|
|
24
|
+
*/
|
|
25
|
+
export interface CqrsHandlerMetadata {
|
|
26
|
+
readonly kind: CqrsHandlerKind;
|
|
27
|
+
readonly type: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Metadata attached to a command handler.
|
|
31
|
+
*/
|
|
32
|
+
export interface CommandHandlerMetadata<TCommand extends Command = Command> extends CqrsHandlerMetadata {
|
|
33
|
+
readonly kind: "command";
|
|
34
|
+
readonly type: TCommand["type"];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Metadata attached to a query handler.
|
|
38
|
+
*/
|
|
39
|
+
export interface QueryHandlerMetadata<TQuery extends Query = Query> extends CqrsHandlerMetadata {
|
|
40
|
+
readonly kind: "query";
|
|
41
|
+
readonly type: TQuery["type"];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Generic constructor type used by decorators.
|
|
45
|
+
*/
|
|
46
|
+
export type CqrsClass<TInstance = object> = new (...args: unknown[]) => TInstance;
|
|
47
|
+
/**
|
|
48
|
+
* Constructor decorated with CQRS metadata.
|
|
49
|
+
*/
|
|
50
|
+
export type DecoratedCqrsClass<TInstance = object> = CqrsClass<TInstance> & {
|
|
51
|
+
readonly [CQRS_HANDLER_METADATA]?: CqrsHandlerMetadata;
|
|
52
|
+
readonly [COMMAND_HANDLER_METADATA]?: CommandHandlerMetadata;
|
|
53
|
+
readonly [QUERY_HANDLER_METADATA]?: QueryHandlerMetadata;
|
|
54
|
+
readonly [CQRS_TYPE_METADATA]?: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Marks a class as a CQRS handler.
|
|
58
|
+
*
|
|
59
|
+
* This decorator is useful when a framework or dependency injection
|
|
60
|
+
* container needs to discover handlers automatically.
|
|
61
|
+
*/
|
|
62
|
+
export declare function CqrsHandler<TType extends string>(kind: CqrsHandlerKind, type: TType): ClassDecorator;
|
|
63
|
+
/**
|
|
64
|
+
* Marks a class as a command handler.
|
|
65
|
+
*/
|
|
66
|
+
export declare function CommandHandler(type: string): ClassDecorator;
|
|
67
|
+
/**
|
|
68
|
+
* Marks a class as a query handler.
|
|
69
|
+
*/
|
|
70
|
+
export declare function QueryHandler(type: string): ClassDecorator;
|
|
71
|
+
/**
|
|
72
|
+
* Reads generic CQRS handler metadata from a class.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getCqrsHandlerMetadata(target: unknown): CqrsHandlerMetadata | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Reads command handler metadata from a class.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getCommandHandlerMetadata(target: unknown): CommandHandlerMetadata | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Reads query handler metadata from a class.
|
|
81
|
+
*/
|
|
82
|
+
export declare function getQueryHandlerMetadata(target: unknown): QueryHandlerMetadata | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Reads the CQRS type discriminator from a class.
|
|
85
|
+
*/
|
|
86
|
+
export declare function getCqrsType(target: unknown): string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Determines whether a class is decorated as a CQRS handler.
|
|
89
|
+
*/
|
|
90
|
+
export declare function isCqrsHandler(target: unknown): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Determines whether a class is decorated as a command handler.
|
|
93
|
+
*/
|
|
94
|
+
export declare function isCommandHandler(target: unknown): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Determines whether a class is decorated as a query handler.
|
|
97
|
+
*/
|
|
98
|
+
export declare function isQueryHandler(target: unknown): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a reusable command handler decorator.
|
|
101
|
+
*/
|
|
102
|
+
export declare function createCommandHandlerDecorator(type: string): ClassDecorator;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a reusable query handler decorator.
|
|
105
|
+
*/
|
|
106
|
+
export declare function createQueryHandlerDecorator(type: string): ClassDecorator;
|
|
107
|
+
export {};
|
|
108
|
+
//# sourceMappingURL=cqrsDecorators.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cqrsDecorators.core.d.ts","sourceRoot":"","sources":["../../src/cqrsDecorators/cqrsDecorators.core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAErE;;GAEG;AACH,QAAA,MAAM,qBAAqB,eAAoC,CAAC;AAEhE;;GAEG;AACH,QAAA,MAAM,wBAAwB,eAA4C,CAAC;AAE3E;;GAEG;AACH,QAAA,MAAM,sBAAsB,eAA0C,CAAC;AAEvE;;GAEG;AACH,QAAA,MAAM,kBAAkB,eAAiC,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,OAAO,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB,CACrC,QAAQ,SAAS,OAAO,GAAG,OAAO,CAClC,SAAQ,mBAAmB;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CACnC,MAAM,SAAS,K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