node-cqrs 0.16.1 → 0.16.4
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/CHANGELOG.md +25 -0
- package/package.json +12 -14
- package/src/CqrsContainerBuilder.js +2 -5
- package/src/infrastructure/InMemoryView.js +1 -3
- package/src/utils/index.js +0 -1
- package/types/index.d.ts +16 -0
- package/types/interfaces/IEventStore.d.ts +0 -1
- package/index.d.ts +0 -43
- package/index.js +0 -3
- package/src/utils/sizeOf.js +0 -63
- package/types/classes/AbstractAggregate.d.ts +0 -64
- package/types/classes/AbstractProjection.d.ts +0 -46
- package/types/classes/AbstractSaga.d.ts +0 -39
- package/types/classes/AggregateCommandHandler.d.ts +0 -21
- package/types/classes/CommandBus.d.ts +0 -17
- package/types/classes/CqrsContainerBuilder.d.ts +0 -26
- package/types/classes/EventStore.d.ts +0 -53
- package/types/classes/EventStream.d.ts +0 -18
- package/types/classes/InMemoryEventStorage.d.ts +0 -21
- package/types/classes/InMemoryMessageBus.d.ts +0 -30
- package/types/classes/InMemorySnapshotStorage.d.ts +0 -18
- package/types/classes/InMemoryView.d.ts +0 -57
- package/types/classes/SagaEventHandler.d.ts +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
## [0.16.4](https://github.com/snatalenko/node-cqrs/compare/v0.16.3...v0.16.4) (2022-08-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Refactoring
|
|
5
|
+
|
|
6
|
+
* Use di package from npm ([0e8db91](https://github.com/snatalenko/node-cqrs/commit/0e8db91636541e95f804e2c266e2d8bbf0f49a8b))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [0.16.3](https://github.com/snatalenko/node-cqrs/compare/v0.16.2...v0.16.3) (2022-01-28)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
|
|
14
|
+
* Update dev dependencies ([e76db7b](https://github.com/snatalenko/node-cqrs/commit/e76db7be66b53afeb619bda459686e490530556f))
|
|
15
|
+
* Remove InMemoryView data size calculation ([fb4260b](https://github.com/snatalenko/node-cqrs/commit/fb4260b94170e371c02be5b6867ba5b1cf7e428f))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## [0.16.2](https://github.com/snatalenko/node-cqrs/compare/v0.16.1...v0.16.2) (2021-07-06)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Fixes
|
|
22
|
+
|
|
23
|
+
* Vulnerabilities in dependencies ([1bdd491](https://github.com/snatalenko/node-cqrs/commit/1bdd4916e3080bd96b15d87c947f6b85e44d6d40))
|
|
24
|
+
|
|
25
|
+
|
|
1
26
|
## [0.16.1](https://github.com/snatalenko/node-cqrs/compare/v0.16.0...v0.16.1) (2021-05-28)
|
|
2
27
|
|
|
3
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-cqrs",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
4
|
"description": "Basic ES6 backbone for CQRS app development",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"domain",
|
|
19
19
|
"eventstore"
|
|
20
20
|
],
|
|
21
|
-
"main": "index.js",
|
|
22
|
-
"types": "index.d.ts",
|
|
21
|
+
"main": "src/index.js",
|
|
22
|
+
"types": "types/index.d.ts",
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">=10.3.0"
|
|
25
25
|
},
|
|
@@ -32,22 +32,20 @@
|
|
|
32
32
|
"posttest:coveralls": "rm -rf ./coverage",
|
|
33
33
|
"changelog": "conventional-changelog -n ./scripts/changelog -i CHANGELOG.md -s",
|
|
34
34
|
"preversion": "npm run lint && npm test",
|
|
35
|
-
"version": "npm run changelog && git add CHANGELOG.md"
|
|
36
|
-
"definitions": "jsdoc -X ./src/ ./src/infrastructure/ | ./scripts/jsdoc-to-dts.js --output ./types/classes/ --namespace NodeCqrs"
|
|
35
|
+
"version": "npm run changelog && git add CHANGELOG.md"
|
|
37
36
|
},
|
|
38
|
-
"author": "@
|
|
37
|
+
"author": "@snatalenko",
|
|
39
38
|
"license": "MIT",
|
|
40
39
|
"homepage": "https://github.com/snatalenko/node-cqrs#readme",
|
|
41
40
|
"dependencies": {
|
|
42
|
-
"
|
|
41
|
+
"di0": "^1.0.0"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"chai": "^4.
|
|
46
|
-
"coveralls": "^3.
|
|
47
|
-
"eslint": "^
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"sinon": "^9.0.1"
|
|
44
|
+
"chai": "^4.3.6",
|
|
45
|
+
"coveralls": "^3.1.1",
|
|
46
|
+
"eslint": "^8.7.0",
|
|
47
|
+
"mocha": "^9.2.0",
|
|
48
|
+
"nyc": "^15.1.0",
|
|
49
|
+
"sinon": "^12.0.1"
|
|
52
50
|
}
|
|
53
51
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { ContainerBuilder } = require('
|
|
3
|
+
const { ContainerBuilder } = require('di0');
|
|
4
4
|
|
|
5
5
|
const AggregateCommandHandler = require('./AggregateCommandHandler');
|
|
6
6
|
const SagaEventHandler = require('./SagaEventHandler');
|
|
@@ -13,16 +13,13 @@ function isClass(func) {
|
|
|
13
13
|
&& Function.prototype.toString.call(func).startsWith('class');
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* @extends {DI6.ContainerBuilder}
|
|
18
|
-
*/
|
|
19
16
|
class CqrsContainerBuilder extends ContainerBuilder {
|
|
20
17
|
|
|
21
18
|
/**
|
|
22
19
|
* Creates an instance of CqrsContainerBuilder
|
|
23
20
|
*
|
|
24
21
|
* @param {object} [options]
|
|
25
|
-
* @param {Readonly<
|
|
22
|
+
* @param {Readonly<import('di0').TypeConfig[]>} options.types
|
|
26
23
|
* @param {object} options.singletones
|
|
27
24
|
*/
|
|
28
25
|
constructor(options) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { sizeOf } = require('../utils');
|
|
4
|
-
|
|
5
3
|
const nextCycle = () => new Promise(setImmediate);
|
|
6
4
|
|
|
7
5
|
/**
|
|
@@ -260,7 +258,7 @@ class InMemoryView {
|
|
|
260
258
|
* @returns {string}
|
|
261
259
|
*/
|
|
262
260
|
toString() {
|
|
263
|
-
return `${this.size} record${this.size !== 1 ? 's' : ''}
|
|
261
|
+
return `${this.size} record${this.size !== 1 ? 's' : ''}`;
|
|
264
262
|
}
|
|
265
263
|
}
|
|
266
264
|
|
package/src/utils/index.js
CHANGED
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "../src";
|
|
2
|
+
export * from "./interfaces/IAggregate";
|
|
3
|
+
export * from "./interfaces/IAggregateSnapshotStorage";
|
|
4
|
+
export * from "./interfaces/ICommandBus";
|
|
5
|
+
export * from "./interfaces/ICommandHandler";
|
|
6
|
+
export * from "./interfaces/IConcurrentView";
|
|
7
|
+
export * from "./interfaces/Identifier";
|
|
8
|
+
export * from "./interfaces/IEventReceptor";
|
|
9
|
+
export * from "./interfaces/IEventStorage";
|
|
10
|
+
export * from "./interfaces/IEventStore";
|
|
11
|
+
export * from "./interfaces/IEventStream";
|
|
12
|
+
export * from "./interfaces/ILogger";
|
|
13
|
+
export * from "./interfaces/IMessageBus";
|
|
14
|
+
export * from "./interfaces/IObserver";
|
|
15
|
+
export * from "./interfaces/IProjection";
|
|
16
|
+
export * from "./interfaces/ISaga";
|
package/index.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export * from "./types/interfaces/IAggregate";
|
|
2
|
-
export * from "./types/interfaces/IAggregateSnapshotStorage";
|
|
3
|
-
export * from "./types/interfaces/ICommandBus";
|
|
4
|
-
export * from "./types/interfaces/ICommandHandler";
|
|
5
|
-
export * from "./types/interfaces/IConcurrentView";
|
|
6
|
-
export * from "./types/interfaces/Identifier";
|
|
7
|
-
export * from "./types/interfaces/IEventReceptor";
|
|
8
|
-
export * from "./types/interfaces/IEventStorage";
|
|
9
|
-
export * from "./types/interfaces/IEventStore";
|
|
10
|
-
export * from "./types/interfaces/IEventStream";
|
|
11
|
-
export * from "./types/interfaces/ILogger";
|
|
12
|
-
export * from "./types/interfaces/IMessageBus";
|
|
13
|
-
export * from "./types/interfaces/IObserver";
|
|
14
|
-
export * from "./types/interfaces/IProjection";
|
|
15
|
-
export * from "./types/interfaces/ISaga";
|
|
16
|
-
export * from "./types/classes/AbstractAggregate";
|
|
17
|
-
export * from "./types/classes/AbstractProjection";
|
|
18
|
-
export * from "./types/classes/AbstractSaga";
|
|
19
|
-
export * from "./types/classes/AggregateCommandHandler";
|
|
20
|
-
export * from "./types/classes/CommandBus";
|
|
21
|
-
export * from "./types/classes/CqrsContainerBuilder";
|
|
22
|
-
export * from "./types/classes/EventStore";
|
|
23
|
-
export * from "./types/classes/EventStream";
|
|
24
|
-
export * from "./types/classes/SagaEventHandler";
|
|
25
|
-
|
|
26
|
-
export var AbstractAggregate: typeof NodeCqrs.AbstractAggregate;
|
|
27
|
-
export var AbstractProjection: typeof NodeCqrs.AbstractProjection;
|
|
28
|
-
export var AbstractSaga: typeof NodeCqrs.AbstractSaga;
|
|
29
|
-
export var AggregateCommandHandler: typeof NodeCqrs.AggregateCommandHandler;
|
|
30
|
-
export var CommandBus: typeof NodeCqrs.CommandBus;
|
|
31
|
-
export var ContainerBuilder: typeof NodeCqrs.CqrsContainerBuilder;
|
|
32
|
-
export var EventStore: typeof NodeCqrs.EventStore;
|
|
33
|
-
export var EventStream: typeof NodeCqrs.EventStream;
|
|
34
|
-
export var InMemoryEventStorage: typeof NodeCqrs.InMemoryEventStorage;
|
|
35
|
-
export var InMemoryMessageBus: typeof NodeCqrs.InMemoryMessageBus;
|
|
36
|
-
export var InMemorySnapshotStorage: typeof NodeCqrs.InMemorySnapshotStorage;
|
|
37
|
-
export var InMemoryView: typeof NodeCqrs.InMemoryView;
|
|
38
|
-
export var SagaEventHandler: typeof NodeCqrs.SagaEventHandler;
|
|
39
|
-
|
|
40
|
-
export {
|
|
41
|
-
getMessageHandlerNames,
|
|
42
|
-
subscribe
|
|
43
|
-
} from "./src";
|
package/index.js
DELETED
package/src/utils/sizeOf.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Calculates an approximate object size in bytes
|
|
5
|
-
* @param {Object} object
|
|
6
|
-
* @return {Number} object size
|
|
7
|
-
*/
|
|
8
|
-
module.exports = function sizeOf(object) {
|
|
9
|
-
if (!object) throw new TypeError('object argument required');
|
|
10
|
-
|
|
11
|
-
const queue = [object];
|
|
12
|
-
let size = 0;
|
|
13
|
-
|
|
14
|
-
for (let i = 0; i < queue.length; i++) {
|
|
15
|
-
|
|
16
|
-
const obj = queue[i];
|
|
17
|
-
|
|
18
|
-
if (typeof obj === 'boolean') {
|
|
19
|
-
size += 4;
|
|
20
|
-
}
|
|
21
|
-
else if (typeof obj === 'number') {
|
|
22
|
-
size += 8;
|
|
23
|
-
}
|
|
24
|
-
else if (typeof obj === 'string') {
|
|
25
|
-
size += Buffer.byteLength(obj, 'utf-8');
|
|
26
|
-
}
|
|
27
|
-
else if (typeof obj === 'symbol') {
|
|
28
|
-
size += 32;
|
|
29
|
-
}
|
|
30
|
-
else if (obj instanceof Date) {
|
|
31
|
-
size += 40; // Buffer.byteLength(obj.toString(), 'utf-8');
|
|
32
|
-
}
|
|
33
|
-
else if (obj instanceof Buffer) {
|
|
34
|
-
size += obj.length;
|
|
35
|
-
}
|
|
36
|
-
else if (obj instanceof Map) {
|
|
37
|
-
for (const [key, innerObj] of obj) {
|
|
38
|
-
queue.push(key);
|
|
39
|
-
if (typeof innerObj !== 'object' || !queue.includes(innerObj))
|
|
40
|
-
queue.push(innerObj);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else if (obj instanceof Set) {
|
|
44
|
-
for (const innerObj of obj) {
|
|
45
|
-
if (typeof innerObj !== 'object' || !queue.includes(innerObj))
|
|
46
|
-
queue.push(innerObj);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else if (obj) {
|
|
50
|
-
if (!Array.isArray(obj)) {
|
|
51
|
-
for (const key of Object.keys(obj))
|
|
52
|
-
size += Buffer.byteLength(key, 'utf-8');
|
|
53
|
-
}
|
|
54
|
-
for (const key of Object.keys(obj)) {
|
|
55
|
-
const innerObj = obj[key];
|
|
56
|
-
if (typeof innerObj !== 'object' || !queue.includes(innerObj))
|
|
57
|
-
queue.push(innerObj);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return size;
|
|
63
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/** Base class for Aggregate definition */
|
|
4
|
-
declare abstract class AbstractAggregate implements IAggregate {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Optional list of commands handled by Aggregate.
|
|
8
|
-
* Can be overridden in the aggregate implementation
|
|
9
|
-
*/
|
|
10
|
-
static readonly handles: Array<string>;
|
|
11
|
-
|
|
12
|
-
/** Aggregate ID */
|
|
13
|
-
readonly id: string | number;
|
|
14
|
-
|
|
15
|
-
/** Aggregate Version */
|
|
16
|
-
readonly version: number;
|
|
17
|
-
|
|
18
|
-
/** Aggregate Snapshot Version */
|
|
19
|
-
readonly snapshotVersion: number | undefined;
|
|
20
|
-
|
|
21
|
-
/** Events emitted by Aggregate */
|
|
22
|
-
readonly changes: IEventStream;
|
|
23
|
-
|
|
24
|
-
/** Override to define whether an aggregate state snapshot should be taken */
|
|
25
|
-
readonly shouldTakeSnapshot: boolean;
|
|
26
|
-
|
|
27
|
-
state;
|
|
28
|
-
|
|
29
|
-
command;
|
|
30
|
-
|
|
31
|
-
/** Creates an instance of AbstractAggregate. */
|
|
32
|
-
constructor(options: TAggregateConstructorParams): void;
|
|
33
|
-
|
|
34
|
-
/** Pass command to command handler */
|
|
35
|
-
handle(command: ICommand): any;
|
|
36
|
-
|
|
37
|
-
/** Mutate aggregate state and increment aggregate version */
|
|
38
|
-
protected mutate(event: IEvent): void;
|
|
39
|
-
|
|
40
|
-
/** Format and register aggregate event and mutate aggregate state */
|
|
41
|
-
protected emit(type: string, payload?: object): void;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Format event based on a current aggregate state
|
|
45
|
-
* and a command being executed
|
|
46
|
-
*/
|
|
47
|
-
protected makeEvent(type: string, payload?: any, sourceCommand?: ICommand): IEvent;
|
|
48
|
-
|
|
49
|
-
/** Register aggregate event and mutate aggregate state */
|
|
50
|
-
protected emitRaw(event: IEvent): void;
|
|
51
|
-
|
|
52
|
-
/** Take an aggregate state snapshot and add it to the changes queue */
|
|
53
|
-
takeSnapshot(): void;
|
|
54
|
-
|
|
55
|
-
/** Create an aggregate state snapshot */
|
|
56
|
-
protected makeSnapshot(): object;
|
|
57
|
-
|
|
58
|
-
/** Restore aggregate state from a snapshot */
|
|
59
|
-
protected restoreSnapshot(snapshotEvent: IEvent): void;
|
|
60
|
-
|
|
61
|
-
/** Get human-readable aggregate identifier */
|
|
62
|
-
toString(): string;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/** Base class for Projection definition */
|
|
4
|
-
declare abstract class AbstractProjection implements IProjection {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Optional list of event types being handled by projection.
|
|
8
|
-
* Can be overridden in projection implementation.
|
|
9
|
-
* If not overridden, will detect event types from event handlers declared on the Projection class
|
|
10
|
-
*/
|
|
11
|
-
static readonly handles: Array<string>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Default view associated with projection.
|
|
15
|
-
* If not defined, an instance of `NodeCqrs.InMemoryView` is created on first access.
|
|
16
|
-
*/
|
|
17
|
-
readonly view;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Indicates if view should be restored from EventStore on start.
|
|
21
|
-
* Override for custom behavior.
|
|
22
|
-
*/
|
|
23
|
-
readonly shouldRestoreView: boolean | Promise<boolean>;
|
|
24
|
-
|
|
25
|
-
/** Creates an instance of AbstractProjection */
|
|
26
|
-
constructor(options?: { view?: any, logger?: ILogger }): void;
|
|
27
|
-
|
|
28
|
-
/** Subscribe to event store */
|
|
29
|
-
subscribe(eventStore: IEventStore): Promise<void>;
|
|
30
|
-
|
|
31
|
-
/** Pass event to projection event handler */
|
|
32
|
-
project(event: IEvent): Promise<void>;
|
|
33
|
-
|
|
34
|
-
/** Pass event to projection event handler, without awaiting for restore operation to complete */
|
|
35
|
-
protected _project(event: IEvent): Promise<void>;
|
|
36
|
-
|
|
37
|
-
/** Restore projection view from event store */
|
|
38
|
-
restore(eventStore: IEventStore): Promise<void>;
|
|
39
|
-
|
|
40
|
-
/** Restore projection view from event store */
|
|
41
|
-
protected _restore(eventStore: IEventStore): Promise<void>;
|
|
42
|
-
|
|
43
|
-
/** Handle error on restoring */
|
|
44
|
-
protected _onRestoringError(error: Error, event: IEvent): void;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/** Base class for Saga definition */
|
|
4
|
-
declare abstract class AbstractSaga implements ISaga {
|
|
5
|
-
|
|
6
|
-
/** List of events that start new saga, must be overridden in Saga implementation */
|
|
7
|
-
static readonly startsWith: Array<string>;
|
|
8
|
-
|
|
9
|
-
/** List of event types being handled by Saga, must be overridden in Saga implementation */
|
|
10
|
-
static readonly handles: Array<string>;
|
|
11
|
-
|
|
12
|
-
/** Saga ID */
|
|
13
|
-
readonly id: string | number;
|
|
14
|
-
|
|
15
|
-
/** Saga version */
|
|
16
|
-
readonly version: number;
|
|
17
|
-
|
|
18
|
-
/** Command execution queue */
|
|
19
|
-
readonly uncommittedMessages: Array<ICommand>;
|
|
20
|
-
|
|
21
|
-
/** Creates an instance of AbstractSaga */
|
|
22
|
-
constructor(options: TSagaConstructorParams): void;
|
|
23
|
-
|
|
24
|
-
/** Modify saga state by applying an event */
|
|
25
|
-
apply(event: IEvent): void | Promise<void>;
|
|
26
|
-
|
|
27
|
-
/** Format a command and put it to the execution queue */
|
|
28
|
-
protected enqueue(commandType: string, aggregateId: string | number, payload: object): void;
|
|
29
|
-
|
|
30
|
-
/** Put a command to the execution queue */
|
|
31
|
-
protected enqueueRaw(command: ICommand): void;
|
|
32
|
-
|
|
33
|
-
/** Clear the execution queue */
|
|
34
|
-
resetUncommittedMessages(): void;
|
|
35
|
-
|
|
36
|
-
/** Get human-readable Saga name */
|
|
37
|
-
toString(): string;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Aggregate command handler.
|
|
5
|
-
*
|
|
6
|
-
* Subscribes to event store and awaits aggregate commands.
|
|
7
|
-
* Upon command receiving creates an instance of aggregate,
|
|
8
|
-
* restores its state, passes command and commits emitted events to event store.
|
|
9
|
-
*/
|
|
10
|
-
declare class AggregateCommandHandler implements ICommandHandler {
|
|
11
|
-
|
|
12
|
-
/** Creates an instance of AggregateCommandHandler. */
|
|
13
|
-
constructor(options: { eventStore: IEventStore, aggregateType: IAggregateConstructor | IAggregateFactory, handles?: Array<string>, logger?: ILogger }): void;
|
|
14
|
-
|
|
15
|
-
/** Subscribe to all command types handled by aggregateType */
|
|
16
|
-
subscribe(commandBus: ICommandBus): any;
|
|
17
|
-
|
|
18
|
-
/** Pass a command to corresponding aggregate */
|
|
19
|
-
execute(cmd: ICommand): Promise<IEventStream>;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
declare class CommandBus implements ICommandBus {
|
|
4
|
-
|
|
5
|
-
/** Creates an instance of CommandBus. */
|
|
6
|
-
constructor(options?: { messageBus?: IMessageBus, logger?: ILogger }): void;
|
|
7
|
-
|
|
8
|
-
/** Set up a command handler */
|
|
9
|
-
on(commandType: string, handler: IMessageHandler): any;
|
|
10
|
-
|
|
11
|
-
/** Format and send a command for execution */
|
|
12
|
-
send(type: string, aggregateId?: string, options?: { payload?: any, context?: object }, otherArgs?: object): Promise<IEventStream>;
|
|
13
|
-
|
|
14
|
-
/** Send a command for execution */
|
|
15
|
-
sendRaw(command: ICommand): Promise<IEventStream>;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
declare class CqrsContainerBuilder extends DI6.ContainerBuilder {
|
|
4
|
-
|
|
5
|
-
/** Creates an instance of CqrsContainerBuilder */
|
|
6
|
-
constructor(options?: { types: Readonly<Array<DI6.TypeConfig>>, singletones: object }): void;
|
|
7
|
-
|
|
8
|
-
/** Register command handler, which will be subscribed to commandBus upon instance creation */
|
|
9
|
-
registerCommandHandler(typeOrFactory: function): void;
|
|
10
|
-
|
|
11
|
-
/** Register event receptor, which will be subscribed to eventStore upon instance creation */
|
|
12
|
-
registerEventReceptor(typeOrFactory: function): void;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Register projection, which will expose view and will be subscribed
|
|
16
|
-
* to eventStore and will restore its state upon instance creation
|
|
17
|
-
*/
|
|
18
|
-
registerProjection(ProjectionType: IProjectionConstructor, exposedViewAlias?: string): void;
|
|
19
|
-
|
|
20
|
-
/** Register aggregate type in the container */
|
|
21
|
-
registerAggregate(AggregateType: IAggregateConstructor): void;
|
|
22
|
-
|
|
23
|
-
/** Register saga type in the container */
|
|
24
|
-
registerSaga(SagaType: ISagaConstructor): void;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
declare class EventStore implements IEventStore {
|
|
4
|
-
|
|
5
|
-
/** Default configuration */
|
|
6
|
-
static defaults: EventStoreConfig;
|
|
7
|
-
|
|
8
|
-
/** Configuration */
|
|
9
|
-
readonly config: EventStoreConfig;
|
|
10
|
-
|
|
11
|
-
/** Whether storage supports aggregate snapshots */
|
|
12
|
-
readonly snapshotsSupported: boolean;
|
|
13
|
-
|
|
14
|
-
/** Creates an instance of EventStore. */
|
|
15
|
-
constructor(options: { storage: IEventStorage, snapshotStorage?: IAggregateSnapshotStorage, messageBus?: IMessageBus, eventValidator?: function, eventStoreConfig?: EventStoreConfig, logger?: ILogger }): void;
|
|
16
|
-
|
|
17
|
-
/** Retrieve new ID from the storage */
|
|
18
|
-
getNewId(): Promise<Identifier>;
|
|
19
|
-
|
|
20
|
-
/** Retrieve all events of specific types */
|
|
21
|
-
getAllEvents(eventTypes: Array<string>): AsyncIterableIterator<IEvent>;
|
|
22
|
-
|
|
23
|
-
/** Retrieve all events of specific Aggregate */
|
|
24
|
-
getAggregateEvents(aggregateId: Identifier): Promise<IEventStream>;
|
|
25
|
-
|
|
26
|
-
/** Retrieve events of specific Saga */
|
|
27
|
-
getSagaEvents(sagaId: Identifier, filter: { beforeEvent: IEvent }): Promise<IEventStream>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Register event types that start sagas.
|
|
31
|
-
* Upon such event commit a new sagaId will be assigned
|
|
32
|
-
*/
|
|
33
|
-
registerSagaStarters(eventTypes: Array<string>): void;
|
|
34
|
-
|
|
35
|
-
/** Validate events, commit to storage and publish to messageBus, if needed */
|
|
36
|
-
commit(events: IEventStream): Promise<IEventStream>;
|
|
37
|
-
|
|
38
|
-
/** Save events to the persistent storage(s) */
|
|
39
|
-
save(events: IEventStream): Promise<IEventStream>;
|
|
40
|
-
|
|
41
|
-
/** After events are */
|
|
42
|
-
publish(eventStream: IEventStream): void;
|
|
43
|
-
|
|
44
|
-
/** Setup a listener for a specific event type */
|
|
45
|
-
on(messageType: string, handler: function): void;
|
|
46
|
-
|
|
47
|
-
/** Get or create a named queue, which delivers events to a single handler only */
|
|
48
|
-
queue(name: string): void;
|
|
49
|
-
|
|
50
|
-
/** Creates one-time subscription for one or multiple events that match a filter */
|
|
51
|
-
once(messageTypes: string | Array<string>, handler?: function, filter?: function): Promise<IEvent>;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/** An immutable collection of events */
|
|
4
|
-
declare class EventStream extends Array implements IEventStream {
|
|
5
|
-
|
|
6
|
-
/** Creates an instance of EventStream */
|
|
7
|
-
constructor(args: IEvent | Array<IEvent> | ReadonlyArray<IEvent>): void;
|
|
8
|
-
|
|
9
|
-
/** Create new EventStream with events that match certain condition */
|
|
10
|
-
filter(condition: function): EventStream;
|
|
11
|
-
|
|
12
|
-
/** Map stream events to another collection */
|
|
13
|
-
map<TResult>(mapFn: function): Array<TResult>;
|
|
14
|
-
|
|
15
|
-
/** Returns a string description of event stream */
|
|
16
|
-
toString(): string;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A simple event storage implementation intended to use for tests only.
|
|
5
|
-
* Storage content resets on each app restart.
|
|
6
|
-
*/
|
|
7
|
-
declare class InMemoryEventStorage implements IEventStorage {
|
|
8
|
-
|
|
9
|
-
constructor(): void;
|
|
10
|
-
|
|
11
|
-
commitEvents(events: Array<IEvent>): Promise<void>;
|
|
12
|
-
|
|
13
|
-
getAggregateEvents(aggregateId: Identifier, options?: { snapshot?: IEvent }): Promise<IEventStream>;
|
|
14
|
-
|
|
15
|
-
getSagaEvents(sagaId: Identifier, options?: { beforeEvent?: IEvent }): Promise<IEventStream>;
|
|
16
|
-
|
|
17
|
-
getEvents(eventTypes: Array<string>): Promise<IEventStream>;
|
|
18
|
-
|
|
19
|
-
getNewId(): number;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/** Default implementation of the message bus. Keeps all subscriptions and messages in memory. */
|
|
4
|
-
declare class InMemoryMessageBus implements IMessageBus {
|
|
5
|
-
|
|
6
|
-
/** Indicates that message bus supports named queue subscriptions */
|
|
7
|
-
static readonly supportsQueues: boolean;
|
|
8
|
-
|
|
9
|
-
/** Creates an instance of InMemoryMessageBus */
|
|
10
|
-
constructor(options?: { name?: string, uniqueEventHandlers?: boolean }): void;
|
|
11
|
-
|
|
12
|
-
/** Subscribe to message type */
|
|
13
|
-
on(messageType: string, handler: IMessageHandler): void;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get or create a named queue.
|
|
17
|
-
* Named queues support only one handler per event type.
|
|
18
|
-
*/
|
|
19
|
-
queue(name: string): IObservable;
|
|
20
|
-
|
|
21
|
-
/** Remove subscription */
|
|
22
|
-
off(messageType: string, handler: IMessageHandler): void;
|
|
23
|
-
|
|
24
|
-
/** Send command to exactly 1 command handler */
|
|
25
|
-
send(command: ICommand): Promise<any>;
|
|
26
|
-
|
|
27
|
-
/** Publish event to all subscribers (if any) */
|
|
28
|
-
publish(event: IEvent): Promise<any>;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* In-memory storage for aggregate snapshots.
|
|
5
|
-
* Storage content resets on app restart
|
|
6
|
-
*/
|
|
7
|
-
declare class InMemorySnapshotStorage implements IAggregateSnapshotStorage {
|
|
8
|
-
|
|
9
|
-
/** Creates an instance of InMemorySnapshotStorage */
|
|
10
|
-
constructor(): void;
|
|
11
|
-
|
|
12
|
-
/** Get latest aggregate snapshot */
|
|
13
|
-
getAggregateSnapshot(aggregateId: Identifier): Promise<IEvent>;
|
|
14
|
-
|
|
15
|
-
/** Save new aggregate snapshot */
|
|
16
|
-
saveAggregateSnapshot(snapshotEvent: IEvent): void;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/** In-memory Projection View, which suspends get()'s until it is ready */
|
|
4
|
-
declare class InMemoryView<TRecord> {
|
|
5
|
-
|
|
6
|
-
/** Whether the view is restored */
|
|
7
|
-
ready: boolean;
|
|
8
|
-
|
|
9
|
-
/** Number of records in the View */
|
|
10
|
-
readonly size: number;
|
|
11
|
-
|
|
12
|
-
/** Creates an instance of InMemoryView */
|
|
13
|
-
constructor(): void;
|
|
14
|
-
|
|
15
|
-
/** Lock the view to prevent concurrent modifications */
|
|
16
|
-
lock(): Promise<void>;
|
|
17
|
-
|
|
18
|
-
/** Release the lock */
|
|
19
|
-
unlock(): void;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Check if view contains a record with a given key.
|
|
23
|
-
* This is the only synchronous method, so make sure to check the `ready` flag, if necessary
|
|
24
|
-
*/
|
|
25
|
-
has(key: Identifier): boolean;
|
|
26
|
-
|
|
27
|
-
/** Get record with a given key; await until the view is restored */
|
|
28
|
-
get(key: Identifier, options?: { nowait?: boolean }): Promise<TRecord>;
|
|
29
|
-
|
|
30
|
-
/** Get all records matching an optional filter */
|
|
31
|
-
getAll(filter?: function): void;
|
|
32
|
-
|
|
33
|
-
/** Create record with a given key and value */
|
|
34
|
-
create(key: Identifier, value?: TRecord): void;
|
|
35
|
-
|
|
36
|
-
/** Update existing view record */
|
|
37
|
-
update(key: Identifier, update: function): void;
|
|
38
|
-
|
|
39
|
-
/** Update existing view record or create new */
|
|
40
|
-
updateEnforcingNew(key: Identifier, update: function): void;
|
|
41
|
-
|
|
42
|
-
/** Update all records that match filter criteria */
|
|
43
|
-
updateAll(filter?: function, update: function): void;
|
|
44
|
-
|
|
45
|
-
/** Delete record */
|
|
46
|
-
delete(key: Identifier): void;
|
|
47
|
-
|
|
48
|
-
/** Delete all records that match filter criteria */
|
|
49
|
-
deleteAll(filter?: function): void;
|
|
50
|
-
|
|
51
|
-
/** Create a Promise which will resolve to a first emitted event of a given type */
|
|
52
|
-
once(eventType: "ready"): Promise<any>;
|
|
53
|
-
|
|
54
|
-
/** Get view summary as string */
|
|
55
|
-
toString(): string;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
namespace NodeCqrs {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Listens to Saga events,
|
|
5
|
-
* creates new saga or restores it from event store,
|
|
6
|
-
* applies new events
|
|
7
|
-
* and passes command(s) to command bus
|
|
8
|
-
*/
|
|
9
|
-
declare class SagaEventHandler implements IEventReceptor {
|
|
10
|
-
|
|
11
|
-
/** Creates an instance of SagaEventHandler */
|
|
12
|
-
constructor(options: { sagaType: ISagaConstructor | ISagaFactory, eventStore: IEventStore, commandBus: ICommandBus, logger?: ILogger, queueName?: string, startsWith?: Array<string>, handles?: Array<string> }): void;
|
|
13
|
-
|
|
14
|
-
/** Overrides observer subscribe method */
|
|
15
|
-
subscribe(): void;
|
|
16
|
-
|
|
17
|
-
/** Handle saga event */
|
|
18
|
-
handle(event: IEvent): Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
}
|