@celljs/cqrs 0.0.0-stage → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -2
- package/esm/node/aggregate/aggregate-root.d.ts +24 -0
- package/esm/node/aggregate/aggregate-root.js +69 -0
- package/esm/node/aggregate/aggregate-root.js.map +1 -0
- package/esm/node/aggregate/event-publisher.d.ts +16 -0
- package/esm/node/aggregate/event-publisher.js +42 -0
- package/esm/node/aggregate/event-publisher.js.map +1 -0
- package/esm/node/aggregate/index.d.ts +2 -0
- package/esm/node/aggregate/index.js +3 -0
- package/esm/node/aggregate/index.js.map +1 -0
- package/esm/node/command/command-bus.d.ts +11 -0
- package/esm/node/command/command-bus.js +36 -0
- package/esm/node/command/command-bus.js.map +1 -0
- package/esm/node/command/command-protocol.d.ts +30 -0
- package/esm/node/command/command-protocol.js +17 -0
- package/esm/node/command/command-protocol.js.map +1 -0
- package/esm/node/command/index.d.ts +2 -0
- package/esm/node/command/index.js +3 -0
- package/esm/node/command/index.js.map +1 -0
- package/esm/node/error/cqrs-error.d.ts +18 -0
- package/esm/node/error/cqrs-error.js +19 -0
- package/esm/node/error/cqrs-error.js.map +1 -0
- package/esm/node/error/index.d.ts +1 -0
- package/esm/node/error/index.js +2 -0
- package/esm/node/error/index.js.map +1 -0
- package/esm/node/event/event-bus.d.ts +17 -0
- package/esm/node/event/event-bus.js +81 -0
- package/esm/node/event/event-bus.js.map +1 -0
- package/esm/node/event/event-protocol.d.ts +42 -0
- package/esm/node/event/event-protocol.js +17 -0
- package/esm/node/event/event-protocol.js.map +1 -0
- package/esm/node/event/index.d.ts +3 -0
- package/esm/node/event/index.js +4 -0
- package/esm/node/event/index.js.map +1 -0
- package/esm/node/event/unhandled-exception-bus.d.ts +8 -0
- package/esm/node/event/unhandled-exception-bus.js +35 -0
- package/esm/node/event/unhandled-exception-bus.js.map +1 -0
- package/esm/node/index.d.ts +6 -0
- package/esm/node/index.js +7 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/module.d.ts +3 -0
- package/esm/node/module.js +4 -0
- package/esm/node/module.js.map +1 -0
- package/esm/node/query/index.d.ts +2 -0
- package/esm/node/query/index.js +3 -0
- package/esm/node/query/index.js.map +1 -0
- package/esm/node/query/query-bus.d.ts +11 -0
- package/esm/node/query/query-bus.js +36 -0
- package/esm/node/query/query-bus.js.map +1 -0
- package/esm/node/query/query-protocol.d.ts +31 -0
- package/esm/node/query/query-protocol.js +18 -0
- package/esm/node/query/query-protocol.js.map +1 -0
- package/esm/node/utils/cqrs-util.d.ts +25 -0
- package/esm/node/utils/cqrs-util.js +85 -0
- package/esm/node/utils/cqrs-util.js.map +1 -0
- package/esm/node/utils/index.d.ts +1 -0
- package/esm/node/utils/index.js +2 -0
- package/esm/node/utils/index.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/node/aggregate/aggregate-root.d.ts +25 -0
- package/lib/node/aggregate/aggregate-root.d.ts.map +1 -0
- package/lib/node/aggregate/aggregate-root.js +73 -0
- package/lib/node/aggregate/aggregate-root.js.map +1 -0
- package/lib/node/aggregate/event-publisher.d.ts +17 -0
- package/lib/node/aggregate/event-publisher.d.ts.map +1 -0
- package/lib/node/aggregate/event-publisher.js +45 -0
- package/lib/node/aggregate/event-publisher.js.map +1 -0
- package/lib/node/aggregate/index.d.ts +3 -0
- package/lib/node/aggregate/index.d.ts.map +1 -0
- package/lib/node/aggregate/index.js +19 -0
- package/lib/node/aggregate/index.js.map +1 -0
- package/lib/node/command/command-bus.d.ts +12 -0
- package/lib/node/command/command-bus.d.ts.map +1 -0
- package/lib/node/command/command-bus.js +39 -0
- package/lib/node/command/command-bus.js.map +1 -0
- package/lib/node/command/command-protocol.d.ts +31 -0
- package/lib/node/command/command-protocol.d.ts.map +1 -0
- package/lib/node/command/command-protocol.js +22 -0
- package/lib/node/command/command-protocol.js.map +1 -0
- package/lib/node/command/index.d.ts +3 -0
- package/lib/node/command/index.d.ts.map +1 -0
- package/lib/node/command/index.js +19 -0
- package/lib/node/command/index.js.map +1 -0
- package/lib/node/cqrs.spec.d.ts +76 -0
- package/lib/node/cqrs.spec.d.ts.map +1 -0
- package/lib/node/cqrs.spec.js +319 -0
- package/lib/node/cqrs.spec.js.map +1 -0
- package/lib/node/error/cqrs-error.d.ts +19 -0
- package/lib/node/error/cqrs-error.d.ts.map +1 -0
- package/lib/node/error/cqrs-error.js +23 -0
- package/lib/node/error/cqrs-error.js.map +1 -0
- package/lib/node/error/index.d.ts +2 -0
- package/lib/node/error/index.d.ts.map +1 -0
- package/lib/node/error/index.js +18 -0
- package/lib/node/error/index.js.map +1 -0
- package/lib/node/event/event-bus.d.ts +18 -0
- package/lib/node/event/event-bus.d.ts.map +1 -0
- package/lib/node/event/event-bus.js +84 -0
- package/lib/node/event/event-bus.js.map +1 -0
- package/lib/node/event/event-protocol.d.ts +43 -0
- package/lib/node/event/event-protocol.d.ts.map +1 -0
- package/lib/node/event/event-protocol.js +22 -0
- package/lib/node/event/event-protocol.js.map +1 -0
- package/lib/node/event/index.d.ts +4 -0
- package/lib/node/event/index.d.ts.map +1 -0
- package/lib/node/event/index.js +20 -0
- package/lib/node/event/index.js.map +1 -0
- package/lib/node/event/unhandled-exception-bus.d.ts +9 -0
- package/lib/node/event/unhandled-exception-bus.d.ts.map +1 -0
- package/lib/node/event/unhandled-exception-bus.js +38 -0
- package/lib/node/event/unhandled-exception-bus.js.map +1 -0
- package/lib/node/index.d.ts +7 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +23 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +6 -0
- package/lib/node/module.js.map +1 -0
- package/lib/node/query/index.d.ts +3 -0
- package/lib/node/query/index.d.ts.map +1 -0
- package/lib/node/query/index.js +19 -0
- package/lib/node/query/index.js.map +1 -0
- package/lib/node/query/query-bus.d.ts +12 -0
- package/lib/node/query/query-bus.d.ts.map +1 -0
- package/lib/node/query/query-bus.js +39 -0
- package/lib/node/query/query-bus.js.map +1 -0
- package/lib/node/query/query-protocol.d.ts +32 -0
- package/lib/node/query/query-protocol.d.ts.map +1 -0
- package/lib/node/query/query-protocol.js +23 -0
- package/lib/node/query/query-protocol.js.map +1 -0
- package/lib/node/utils/cqrs-util.d.ts +26 -0
- package/lib/node/utils/cqrs-util.d.ts.map +1 -0
- package/lib/node/utils/cqrs-util.js +88 -0
- package/lib/node/utils/cqrs-util.js.map +1 -0
- package/lib/node/utils/index.d.ts +2 -0
- package/lib/node/utils/index.d.ts.map +1 -0
- package/lib/node/utils/index.js +18 -0
- package/lib/node/utils/index.js.map +1 -0
- package/package.json +88 -4
- package/src/node/aggregate/aggregate-root.ts +78 -0
- package/src/node/aggregate/event-publisher.ts +43 -0
- package/src/node/aggregate/index.ts +2 -0
- package/src/node/command/command-bus.ts +28 -0
- package/src/node/command/command-protocol.ts +39 -0
- package/src/node/command/index.ts +2 -0
- package/src/node/cqrs.spec.ts +316 -0
- package/src/node/error/cqrs-error.ts +23 -0
- package/src/node/error/index.ts +1 -0
- package/src/node/event/event-bus.ts +70 -0
- package/src/node/event/event-protocol.ts +60 -0
- package/src/node/event/index.ts +3 -0
- package/src/node/event/unhandled-exception-bus.ts +21 -0
- package/src/node/index.ts +6 -0
- package/src/node/module.ts +4 -0
- package/src/node/query/index.ts +2 -0
- package/src/node/query/query-bus.ts +28 -0
- package/src/node/query/query-protocol.ts +40 -0
- package/src/node/utils/cqrs-util.ts +90 -0
- package/src/node/utils/index.ts +1 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CqrsError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A command, query or event that cannot be dispatched. `code` is stable and `hint` says how to fix it
|
|
6
|
+
* in one sentence (docs/design/agent-first.md R5).
|
|
7
|
+
*/
|
|
8
|
+
class CqrsError extends Error {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options.message);
|
|
11
|
+
this.name = 'CqrsError';
|
|
12
|
+
this.code = options.code;
|
|
13
|
+
this.hint = options.hint;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.CqrsError = CqrsError;
|
|
17
|
+
(function (CqrsError) {
|
|
18
|
+
function is(error, code) {
|
|
19
|
+
return error instanceof CqrsError && (code === undefined || error.code === code);
|
|
20
|
+
}
|
|
21
|
+
CqrsError.is = is;
|
|
22
|
+
})(CqrsError || (exports.CqrsError = CqrsError = {}));
|
|
23
|
+
//# sourceMappingURL=cqrs-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cqrs-error.js","sourceRoot":"","sources":["../../../src/node/error/cqrs-error.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,eAAuB,SAAQ,KAAK;IAKhC,YAAY,OAAgE;QACxE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QALT,SAAI,GAAG,WAAW,CAAC;QAMjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC7B,CAAC;CACJ;;AAED,WAAiB,SAAS;IAGtB,SAAgB,EAAE,CAAC,KAAc,EAAE,IAAW;QAC1C,OAAO,KAAK,YAAY,SAAS,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACrF,CAAC;IAFe,UAAA,EAAE,KAEjB,CAAA;AACL,CAAC,EANgB,SAAS,aAZb,SAAS,GAYL,SAAS,QAMzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cqrs-error"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/error/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Provider } from '@celljs/core';
|
|
2
|
+
import { CommandBus } from '../command/command-protocol';
|
|
3
|
+
import { type MessageType } from '../utils';
|
|
4
|
+
import { EventBus, type EventHandler, type Saga, UnhandledExceptionBus } from './event-protocol';
|
|
5
|
+
export declare class EventBusImpl implements EventBus {
|
|
6
|
+
/** Providers: the handlers and sagas are created when the first event is published, so they can inject the buses. */
|
|
7
|
+
protected readonly handlerProvider: Provider<EventHandler>;
|
|
8
|
+
protected readonly sagaProvider: Provider<Saga>;
|
|
9
|
+
protected readonly commandBus: CommandBus;
|
|
10
|
+
protected readonly unhandledExceptionBus: UnhandledExceptionBus;
|
|
11
|
+
protected handlers?: Map<MessageType, EventHandler[]>;
|
|
12
|
+
protected sagas?: Map<MessageType, Saga[]>;
|
|
13
|
+
publish(event: object): Promise<void>;
|
|
14
|
+
publishAll(events: object[]): Promise<void>;
|
|
15
|
+
protected handle(handler: EventHandler, event: object): Promise<void>;
|
|
16
|
+
protected runSaga(saga: Saga, event: object): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=event-bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../../src/node/event/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAiB,QAAQ,EAAE,KAAK,YAAY,EAAQ,KAAK,IAAI,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAItH,qBACa,YAAa,YAAW,QAAQ;IACzC,qHAAqH;IAErH,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAG3D,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAGhD,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAG1C,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAEhE,SAAS,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,CAAC,CAAC;IACtD,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IAErC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB1C;IAEK,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAIhD;IAED,UAAgB,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM1E;IAED,UAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhE;CACJ"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EventBusImpl = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const command_protocol_1 = require("../command/command-protocol");
|
|
15
|
+
const utils_1 = require("../utils");
|
|
16
|
+
const event_protocol_1 = require("./event-protocol");
|
|
17
|
+
const NONE = [];
|
|
18
|
+
let EventBusImpl = class EventBusImpl {
|
|
19
|
+
async publish(event) {
|
|
20
|
+
var _a, _b, _c, _d;
|
|
21
|
+
const type = utils_1.CqrsUtil.typeOf(event, 'event');
|
|
22
|
+
(_a = this.handlers) !== null && _a !== void 0 ? _a : (this.handlers = utils_1.CqrsUtil.index(this.handlerProvider.get(), utils_1.METADATA_KEY.eventHandler));
|
|
23
|
+
(_b = this.sagas) !== null && _b !== void 0 ? _b : (this.sagas = utils_1.CqrsUtil.index(this.sagaProvider.get(), utils_1.METADATA_KEY.saga));
|
|
24
|
+
const handlers = (_c = this.handlers.get(type)) !== null && _c !== void 0 ? _c : NONE;
|
|
25
|
+
const sagas = (_d = this.sagas.get(type)) !== null && _d !== void 0 ? _d : NONE;
|
|
26
|
+
if (handlers.length === 1 && sagas.length === 0) {
|
|
27
|
+
return this.handle(handlers[0], event);
|
|
28
|
+
}
|
|
29
|
+
const tasks = [];
|
|
30
|
+
for (const handler of handlers) {
|
|
31
|
+
tasks.push(this.handle(handler, event));
|
|
32
|
+
}
|
|
33
|
+
for (const saga of sagas) {
|
|
34
|
+
tasks.push(this.runSaga(saga, event));
|
|
35
|
+
}
|
|
36
|
+
await Promise.all(tasks);
|
|
37
|
+
}
|
|
38
|
+
async publishAll(events) {
|
|
39
|
+
for (const event of events) {
|
|
40
|
+
await this.publish(event);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async handle(handler, event) {
|
|
44
|
+
try {
|
|
45
|
+
await handler.handle(event);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
this.unhandledExceptionBus.publish({ error, event, handler });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async runSaga(saga, event) {
|
|
52
|
+
try {
|
|
53
|
+
const result = await saga.handle(event);
|
|
54
|
+
const commands = result === undefined || result === null ? NONE : Array.isArray(result) ? result : [result];
|
|
55
|
+
for (const command of commands) {
|
|
56
|
+
await this.commandBus.execute(command);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
this.unhandledExceptionBus.publish({ error, event, handler: saga });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.EventBusImpl = EventBusImpl;
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, core_1.AutowiredProvider)(event_protocol_1.EVENT_HANDLER),
|
|
67
|
+
__metadata("design:type", Object)
|
|
68
|
+
], EventBusImpl.prototype, "handlerProvider", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, core_1.AutowiredProvider)(event_protocol_1.SAGA),
|
|
71
|
+
__metadata("design:type", Object)
|
|
72
|
+
], EventBusImpl.prototype, "sagaProvider", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, core_1.Autowired)(command_protocol_1.CommandBus),
|
|
75
|
+
__metadata("design:type", Object)
|
|
76
|
+
], EventBusImpl.prototype, "commandBus", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, core_1.Autowired)(event_protocol_1.UnhandledExceptionBus),
|
|
79
|
+
__metadata("design:type", Object)
|
|
80
|
+
], EventBusImpl.prototype, "unhandledExceptionBus", void 0);
|
|
81
|
+
exports.EventBusImpl = EventBusImpl = __decorate([
|
|
82
|
+
(0, core_1.Component)(event_protocol_1.EventBus)
|
|
83
|
+
], EventBusImpl);
|
|
84
|
+
//# sourceMappingURL=event-bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../../src/node/event/event-bus.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ComponentOption, Event, MaybePromise, Newable } from '@celljs/core';
|
|
2
|
+
export declare const EventBus: unique symbol;
|
|
3
|
+
export declare const UnhandledExceptionBus: unique symbol;
|
|
4
|
+
export declare const EVENT_HANDLER: unique symbol;
|
|
5
|
+
export declare const SAGA: unique symbol;
|
|
6
|
+
/** Reacts to events that happened; an event class can have any number of handlers. */
|
|
7
|
+
export interface EventHandler<E extends object = any> {
|
|
8
|
+
handle(event: E): MaybePromise<void>;
|
|
9
|
+
}
|
|
10
|
+
/** Makes the class a component that handles the events of the given classes. */
|
|
11
|
+
export declare function EventHandler(events: Newable<object> | Newable<object>[], option?: ComponentOption): ClassDecorator;
|
|
12
|
+
/**
|
|
13
|
+
* Turns an event into the commands that follow from it: the event bus runs what `handle` returns
|
|
14
|
+
* (a command, an array of commands or nothing) with the command bus, in order.
|
|
15
|
+
*/
|
|
16
|
+
export interface Saga<E extends object = any> {
|
|
17
|
+
handle(event: E): MaybePromise<object | object[] | undefined | void>;
|
|
18
|
+
}
|
|
19
|
+
/** Makes the class a component that turns the events of the given classes into commands. */
|
|
20
|
+
export declare function Saga(events: Newable<object> | Newable<object>[], option?: ComponentOption): ClassDecorator;
|
|
21
|
+
/** Hands events to their handlers and sagas. */
|
|
22
|
+
export interface EventBus {
|
|
23
|
+
/**
|
|
24
|
+
* Runs the handlers and sagas of the event concurrently and resolves when they are all done.
|
|
25
|
+
* What they throw does not reject it: it goes to the `UnhandledExceptionBus`.
|
|
26
|
+
* Rejects with a `CqrsError` when the event is not an instance of a class.
|
|
27
|
+
*/
|
|
28
|
+
publish(event: object): Promise<void>;
|
|
29
|
+
/** Publishes the events one after the other. */
|
|
30
|
+
publishAll(events: object[]): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/** What an event handler or a saga (`handler`) threw while handling `event`. */
|
|
33
|
+
export interface UnhandledException {
|
|
34
|
+
error: unknown;
|
|
35
|
+
event: object;
|
|
36
|
+
handler: object;
|
|
37
|
+
}
|
|
38
|
+
/** Where the errors of event handlers and sagas go; they are logged too. */
|
|
39
|
+
export interface UnhandledExceptionBus {
|
|
40
|
+
readonly onException: Event<UnhandledException>;
|
|
41
|
+
publish(exception: UnhandledException): void;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=event-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/event/event-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGlF,eAAO,MAAM,QAAQ,eAAqB,CAAC;AAC3C,eAAO,MAAM,qBAAqB,eAAkC,CAAC;AACrE,eAAO,MAAM,aAAa,eAAyB,CAAC;AACpD,eAAO,MAAM,IAAI,eAAiB,CAAC;AAEnC,sFAAsF;AACtF,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG;IAChD,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,gFAAgF;AAChF,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,cAAc,CAElH;AAED;;;GAGG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG;IAExC,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;CACxE;AAED,4FAA4F;AAC5F,wBAAgB,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,cAAc,CAE1G;AAED,gDAAgD;AAChD,MAAM,WAAW,QAAQ;IACrB;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,gDAAgD;IAChD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED,gFAAgF;AAChF,MAAM,WAAW,kBAAkB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,4EAA4E;AAC5E,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAChD,OAAO,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAChD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SAGA = exports.EVENT_HANDLER = exports.UnhandledExceptionBus = exports.EventBus = void 0;
|
|
4
|
+
exports.EventHandler = EventHandler;
|
|
5
|
+
exports.Saga = Saga;
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
exports.EventBus = Symbol('EventBus');
|
|
8
|
+
exports.UnhandledExceptionBus = Symbol('UnhandledExceptionBus');
|
|
9
|
+
exports.EVENT_HANDLER = Symbol('EventHandler');
|
|
10
|
+
exports.SAGA = Symbol('Saga');
|
|
11
|
+
/** Makes the class a component that handles the events of the given classes. */
|
|
12
|
+
function EventHandler(events, option) {
|
|
13
|
+
return target => utils_1.CqrsUtil.applyHandlerDecorator(target, exports.EVENT_HANDLER, utils_1.METADATA_KEY.eventHandler, toArray(events), option);
|
|
14
|
+
}
|
|
15
|
+
/** Makes the class a component that turns the events of the given classes into commands. */
|
|
16
|
+
function Saga(events, option) {
|
|
17
|
+
return target => utils_1.CqrsUtil.applyHandlerDecorator(target, exports.SAGA, utils_1.METADATA_KEY.saga, toArray(events), option);
|
|
18
|
+
}
|
|
19
|
+
function toArray(value) {
|
|
20
|
+
return Array.isArray(value) ? value : [value];
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=event-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-protocol.js","sourceRoot":"","sources":["../../../src/node/event/event-protocol.ts"],"names":[],"mappings":";;;;;AACA,oCAAkD;AAErC,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9B,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AACxD,QAAA,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACvC,QAAA,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAOnC,gFAAgF;AAChF,sBAA6B,MAA2C,EAAE,MAAwB;IAC9F,OAAO,MAAM,CAAC,EAAE,CAAC,gBAAQ,CAAC,qBAAqB,CAAC,MAAM,EAAE,QAAA,aAAa,EAAE,oBAAY,CAAC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;AAC/H,CAAC;AAWD,4FAA4F;AAC5F,cAAqB,MAA2C,EAAE,MAAwB;IACtF,OAAO,MAAM,CAAC,EAAE,CAAC,gBAAQ,CAAC,qBAAqB,CAAC,MAAM,EAAE,QAAA,IAAI,EAAE,oBAAY,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;AAC9G,CAAC;AA2BD,SAAS,OAAO,CAAI,KAAc;IAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/event/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./event-bus"), exports);
|
|
18
|
+
__exportStar(require("./event-protocol"), exports);
|
|
19
|
+
__exportStar(require("./unhandled-exception-bus"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/event/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,mDAAiC;AACjC,4DAA0C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Emitter, Logger } from '@celljs/core';
|
|
2
|
+
import { type UnhandledException, UnhandledExceptionBus } from './event-protocol';
|
|
3
|
+
export declare class UnhandledExceptionBusImpl implements UnhandledExceptionBus {
|
|
4
|
+
protected readonly logger: Logger;
|
|
5
|
+
protected readonly onExceptionEmitter: Emitter<UnhandledException>;
|
|
6
|
+
get onException(): import("@celljs/core").Event<UnhandledException>;
|
|
7
|
+
publish(exception: UnhandledException): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=unhandled-exception-bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unhandled-exception-bus.d.ts","sourceRoot":"","sources":["../../../src/node/event/unhandled-exception-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,OAAO,EAAkB,MAAM,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,KAAK,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAElF,qBACa,yBAA0B,YAAW,qBAAqB;IAEnE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAElC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,8BAAqC;IAE1E,IAAI,WAAW,qDAEd;IAED,OAAO,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAK3C;CACJ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UnhandledExceptionBusImpl = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const event_protocol_1 = require("./event-protocol");
|
|
15
|
+
let UnhandledExceptionBusImpl = class UnhandledExceptionBusImpl {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.onExceptionEmitter = new core_1.Emitter();
|
|
18
|
+
}
|
|
19
|
+
get onException() {
|
|
20
|
+
return this.onExceptionEmitter.event;
|
|
21
|
+
}
|
|
22
|
+
publish(exception) {
|
|
23
|
+
var _a;
|
|
24
|
+
const { error, event, handler } = exception;
|
|
25
|
+
const reason = error instanceof Error ? ((_a = error.stack) !== null && _a !== void 0 ? _a : error.message) : String(error);
|
|
26
|
+
this.logger.error(`${(0, core_1.getTargetClass)(handler).name} failed on the event ${event.constructor.name}: ${reason}`);
|
|
27
|
+
this.onExceptionEmitter.fire(exception);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.UnhandledExceptionBusImpl = UnhandledExceptionBusImpl;
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, core_1.Autowired)(core_1.Logger),
|
|
33
|
+
__metadata("design:type", Object)
|
|
34
|
+
], UnhandledExceptionBusImpl.prototype, "logger", void 0);
|
|
35
|
+
exports.UnhandledExceptionBusImpl = UnhandledExceptionBusImpl = __decorate([
|
|
36
|
+
(0, core_1.Component)(event_protocol_1.UnhandledExceptionBus)
|
|
37
|
+
], UnhandledExceptionBusImpl);
|
|
38
|
+
//# sourceMappingURL=unhandled-exception-bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unhandled-exception-bus.js","sourceRoot":"","sources":["../../../src/node/event/unhandled-exception-bus.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAqF;AACrF,qDAAkF;AAG3E,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAA/B;QAIgB,uBAAkB,GAAG,IAAI,cAAO,EAAsB,CAAC;IAY9E,CAAC;IAVG,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,SAA6B;;QACjC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;QAC5C,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,OAAC,KAAK,CAAC,KAAK,mCAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,qBAAc,EAAC,OAAO,CAAC,CAAC,IAAI,wBAAwB,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC,CAAC;QAC9G,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;CACJ,CAAA;;AAdsB;IADlB,IAAA,gBAAS,EAAC,aAAM,CAAC;;yDACgB;oCAFzB,yBAAyB;IADrC,IAAA,gBAAS,EAAC,sCAAqB,CAAC;GACpB,yBAAyB,CAgBrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./aggregate"), exports);
|
|
18
|
+
__exportStar(require("./command"), exports);
|
|
19
|
+
__exportStar(require("./error"), exports);
|
|
20
|
+
__exportStar(require("./event"), exports);
|
|
21
|
+
__exportStar(require("./query"), exports);
|
|
22
|
+
__exportStar(require("./utils"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,0CAAwB;AACxB,0CAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,mBAAiB;kBAEF,IAAA,eAAQ,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/query/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./query-bus"), exports);
|
|
18
|
+
__exportStar(require("./query-protocol"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/query/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,mDAAiC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Provider } from '@celljs/core';
|
|
2
|
+
import { type MessageType } from '../utils';
|
|
3
|
+
import { QueryBus, type QueryHandler, type QueryMessage } from './query-protocol';
|
|
4
|
+
export declare class QueryBusImpl implements QueryBus {
|
|
5
|
+
/** A provider: the handlers are created when the first query runs, so they can inject the buses. */
|
|
6
|
+
protected readonly handlerProvider: Provider<QueryHandler>;
|
|
7
|
+
protected handlers?: Map<MessageType, QueryHandler>;
|
|
8
|
+
execute<R>(query: QueryMessage<R>): Promise<R>;
|
|
9
|
+
execute<R = any>(query: object): Promise<R>;
|
|
10
|
+
protected getHandler(query: object): QueryHandler;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=query-bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-bus.d.ts","sourceRoot":"","sources":["../../../src/node/query/query-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAiB,QAAQ,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEjG,qBACa,YAAa,YAAW,QAAQ;IACzC,oGAAoG;IAEpG,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAE3D,SAAS,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAEpD,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAK5C,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAQhD;CACJ"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.QueryBusImpl = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
const query_protocol_1 = require("./query-protocol");
|
|
16
|
+
let QueryBusImpl = class QueryBusImpl {
|
|
17
|
+
async execute(query) {
|
|
18
|
+
return this.getHandler(query).execute(query);
|
|
19
|
+
}
|
|
20
|
+
getHandler(query) {
|
|
21
|
+
var _a;
|
|
22
|
+
const type = utils_1.CqrsUtil.typeOf(query, 'query');
|
|
23
|
+
(_a = this.handlers) !== null && _a !== void 0 ? _a : (this.handlers = utils_1.CqrsUtil.single(this.handlerProvider.get(), utils_1.METADATA_KEY.queryHandler, 'query'));
|
|
24
|
+
const handler = this.handlers.get(type);
|
|
25
|
+
if (!handler) {
|
|
26
|
+
throw utils_1.CqrsUtil.noHandler(type, 'query');
|
|
27
|
+
}
|
|
28
|
+
return handler;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.QueryBusImpl = QueryBusImpl;
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, core_1.AutowiredProvider)(query_protocol_1.QUERY_HANDLER),
|
|
34
|
+
__metadata("design:type", Object)
|
|
35
|
+
], QueryBusImpl.prototype, "handlerProvider", void 0);
|
|
36
|
+
exports.QueryBusImpl = QueryBusImpl = __decorate([
|
|
37
|
+
(0, core_1.Component)(query_protocol_1.QueryBus)
|
|
38
|
+
], QueryBusImpl);
|
|
39
|
+
//# sourceMappingURL=query-bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-bus.js","sourceRoot":"","sources":["../../../src/node/query/query-bus.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA2E;AAC3E,oCAAoE;AACpE,qDAAiG;AAG1F,IAAM,YAAY,GAAlB,MAAM,YAAY;IASrB,KAAK,CAAC,OAAO,CAAC,KAAa;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;IAES,UAAU,CAAC,KAAa;;QAC9B,MAAM,IAAI,GAAG,gBAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC7C,MAAA,IAAI,CAAC,QAAQ,oCAAb,IAAI,CAAC,QAAQ,GAAK,gBAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,oBAAY,CAAC,YAAY,EAAE,OAAO,CAAC,EAAC;QAClG,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,gBAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ,CAAA;;AAnBsB;IADlB,IAAA,wBAAiB,EAAC,8BAAa,CAAC;;qDAC0B;uBAHlD,YAAY;IADxB,IAAA,gBAAS,EAAC,yBAAQ,CAAC;GACP,YAAY,CAsBxB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ComponentOption, MaybePromise, Newable } from '@celljs/core';
|
|
2
|
+
export declare const QueryBus: unique symbol;
|
|
3
|
+
export declare const QUERY_HANDLER: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* Optional base class of a query that gives `QueryBus.execute` its result type:
|
|
6
|
+
* `class GetUser extends QueryMessage<User> { ... }` makes `execute(new GetUser(...))` a `Promise<User>`.
|
|
7
|
+
* (Not named `Query`: `@celljs/mvc` has a `@Query` parameter decorator.)
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class QueryMessage<R = any> {
|
|
10
|
+
/** Carries the result type only; never set. */
|
|
11
|
+
readonly __result: R;
|
|
12
|
+
}
|
|
13
|
+
export type QueryResult<Q> = Q extends QueryMessage<infer R> ? R : any;
|
|
14
|
+
/** Reads the state of the application without changing it; the one handler of a query class is selected by the class of the query. */
|
|
15
|
+
export interface QueryHandler<Q extends object = any, R = QueryResult<Q>> {
|
|
16
|
+
execute(query: Q): MaybePromise<R>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Makes the class a component that answers the queries of the given class.
|
|
20
|
+
* Each query class has exactly one handler.
|
|
21
|
+
*/
|
|
22
|
+
export declare function QueryHandler(query: Newable<object>, option?: ComponentOption): ClassDecorator;
|
|
23
|
+
/** Answers a query with its handler. */
|
|
24
|
+
export interface QueryBus {
|
|
25
|
+
/**
|
|
26
|
+
* Runs the handler of the query and resolves to what it returns.
|
|
27
|
+
* Rejects with what the handler throws, or a `CqrsError` when no handler handles the query.
|
|
28
|
+
*/
|
|
29
|
+
execute<R>(query: QueryMessage<R>): Promise<R>;
|
|
30
|
+
execute<R = any>(query: object): Promise<R>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=query-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/query/query-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG3E,eAAO,MAAM,QAAQ,eAAqB,CAAC;AAC3C,eAAO,MAAM,aAAa,eAAyB,CAAC;AAEpD;;;;GAIG;AACH,8BAAsB,YAAY,CAAC,CAAC,GAAG,GAAG;IACtC,+CAA+C;IAC/C,SAAiB,QAAQ,EAAE,CAAC,CAAC;CAChC;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AAEvE,sIAAsI;AACtI,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;IACpE,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,cAAc,CAE7F;AAED,wCAAwC;AACxC,MAAM,WAAW,QAAQ;IACrB;;;OAGG;IACH,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryMessage = exports.QUERY_HANDLER = exports.QueryBus = void 0;
|
|
4
|
+
exports.QueryHandler = QueryHandler;
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
exports.QueryBus = Symbol('QueryBus');
|
|
7
|
+
exports.QUERY_HANDLER = Symbol('QueryHandler');
|
|
8
|
+
/**
|
|
9
|
+
* Optional base class of a query that gives `QueryBus.execute` its result type:
|
|
10
|
+
* `class GetUser extends QueryMessage<User> { ... }` makes `execute(new GetUser(...))` a `Promise<User>`.
|
|
11
|
+
* (Not named `Query`: `@celljs/mvc` has a `@Query` parameter decorator.)
|
|
12
|
+
*/
|
|
13
|
+
class QueryMessage {
|
|
14
|
+
}
|
|
15
|
+
exports.QueryMessage = QueryMessage;
|
|
16
|
+
/**
|
|
17
|
+
* Makes the class a component that answers the queries of the given class.
|
|
18
|
+
* Each query class has exactly one handler.
|
|
19
|
+
*/
|
|
20
|
+
function QueryHandler(query, option) {
|
|
21
|
+
return target => utils_1.CqrsUtil.applyHandlerDecorator(target, exports.QUERY_HANDLER, utils_1.METADATA_KEY.queryHandler, [query], option);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=query-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-protocol.js","sourceRoot":"","sources":["../../../src/node/query/query-protocol.ts"],"names":[],"mappings":";;;;AACA,oCAAkD;AAErC,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9B,QAAA,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAEpD;;;;GAIG;AACH;CAGC;;AASD;;;GAGG;AACH,sBAA6B,KAAsB,EAAE,MAAwB;IACzE,OAAO,MAAM,CAAC,EAAE,CAAC,gBAAQ,CAAC,qBAAqB,CAAC,MAAM,EAAE,QAAA,aAAa,EAAE,oBAAY,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;AACvH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ComponentId, type ComponentOption } from '@celljs/core';
|
|
2
|
+
import { CqrsError } from '../error';
|
|
3
|
+
export type MessageKind = 'command' | 'query' | 'event';
|
|
4
|
+
/** The class of a command, query or event. */
|
|
5
|
+
export type MessageType = new (...args: any[]) => object;
|
|
6
|
+
export declare const METADATA_KEY: {
|
|
7
|
+
commandHandler: string;
|
|
8
|
+
queryHandler: string;
|
|
9
|
+
eventHandler: string;
|
|
10
|
+
saga: string;
|
|
11
|
+
};
|
|
12
|
+
export declare namespace CqrsUtil {
|
|
13
|
+
/**
|
|
14
|
+
* Registers the class as a component that is also bound to `id` and records the message classes it handles,
|
|
15
|
+
* for the bus that collects the components of `id`.
|
|
16
|
+
*/
|
|
17
|
+
function applyHandlerDecorator(target: any, id: ComponentId, metadataKey: string, types: MessageType[], option?: ComponentOption): void;
|
|
18
|
+
/** The class of a command, query or event: what selects its handlers. */
|
|
19
|
+
function typeOf(message: unknown, kind: MessageKind): MessageType;
|
|
20
|
+
/** The handlers by the message class they handle, in the order the container gives them. */
|
|
21
|
+
function index<H extends object>(handlers: H[], metadataKey: string): Map<MessageType, H[]>;
|
|
22
|
+
/** The one handler of each message class; commands and queries have exactly one. */
|
|
23
|
+
function single<H extends object>(handlers: H[], metadataKey: string, kind: MessageKind): Map<MessageType, H>;
|
|
24
|
+
function noHandler(type: MessageType, kind: MessageKind): CqrsError;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=cqrs-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cqrs-util.d.ts","sourceRoot":"","sources":["../../../src/node/utils/cqrs-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,eAAe,EAAwC,MAAM,cAAc,CAAC;AACvH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAExD,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;AAEzD,eAAO,MAAM,YAAY;IACrB,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,IAAI;CACP,CAAC;AAIF,yBAAiB,QAAQ,CAAC;IACtB;;;OAGG;IACH,SAAgB,qBAAqB,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAK7I;IAED,yEAAyE;IACzE,SAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,WAAW,CAUvE;IAED,4FAA4F;IAC5F,SAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAcjG;IAED,oFAAoF;IACpF,SAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAanH;IAED,SAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,GAAG,SAAS,CAMzE;CAQJ"}
|