@hexaijs/core 0.9.0 → 0.9.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/dist/domain/aggregate-root.d.ts +12 -0
- package/dist/domain/aggregate-root.d.ts.map +1 -0
- package/dist/domain/aggregate-root.js +22 -0
- package/dist/domain/aggregate-root.js.map +1 -0
- package/dist/domain/domain-error.d.ts +11 -0
- package/dist/domain/domain-error.d.ts.map +1 -0
- package/dist/domain/domain-error.js +19 -0
- package/dist/domain/domain-error.js.map +1 -0
- package/dist/domain/domain-event.d.ts +5 -0
- package/dist/domain/domain-event.d.ts.map +1 -0
- package/dist/domain/domain-event.js +7 -0
- package/dist/domain/domain-event.js.map +1 -0
- package/dist/domain/identifiable.d.ts +11 -0
- package/dist/domain/identifiable.d.ts.map +1 -0
- package/dist/domain/identifiable.js +14 -0
- package/dist/domain/identifiable.js.map +1 -0
- package/dist/domain/index.d.ts +6 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +6 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/domain/repository.d.ts +16 -0
- package/dist/domain/repository.d.ts.map +1 -0
- package/dist/domain/repository.js +19 -0
- package/dist/domain/repository.js.map +1 -0
- package/dist/event-store.d.ts +13 -0
- package/dist/event-store.d.ts.map +1 -0
- package/dist/event-store.js +2 -0
- package/dist/event-store.js.map +1 -0
- package/dist/index.d.ts +6 -86
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -280
- package/dist/index.js.map +1 -1
- package/dist/{event-store-UbTJSE4H.d.ts → message.d.ts} +9 -21
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +144 -0
- package/dist/message.js.map +1 -0
- package/dist/test/dummy-message.d.ts +8 -0
- package/dist/test/dummy-message.d.ts.map +1 -0
- package/dist/test/dummy-message.js +15 -0
- package/dist/test/dummy-message.js.map +1 -0
- package/dist/test/in-memory-event-store.d.ts +11 -0
- package/dist/test/in-memory-event-store.d.ts.map +1 -0
- package/dist/test/in-memory-event-store.js +34 -0
- package/dist/test/in-memory-event-store.js.map +1 -0
- package/dist/test/index.d.ts +6 -36
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +5 -326
- package/dist/test/index.js.map +1 -1
- package/dist/test/matchers.d.ts +5 -0
- package/dist/test/matchers.d.ts.map +1 -0
- package/dist/test/matchers.js +69 -0
- package/dist/test/matchers.js.map +1 -0
- package/dist/test/partial-match.d.ts +4 -0
- package/dist/test/partial-match.d.ts.map +1 -0
- package/dist/test/partial-match.js +26 -0
- package/dist/test/partial-match.js.map +1 -0
- package/dist/test/utils.d.ts +5 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +18 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/transaction-hooks.d.ts +13 -0
- package/dist/transaction-hooks.d.ts.map +1 -0
- package/dist/transaction-hooks.js +47 -0
- package/dist/transaction-hooks.js.map +1 -0
- package/dist/unit-of-work.d.ts +19 -0
- package/dist/unit-of-work.d.ts.map +1 -0
- package/dist/unit-of-work.js +7 -0
- package/dist/unit-of-work.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DomainEvent } from "./domain-event.js";
|
|
2
|
+
import { Id, Identifiable } from "./identifiable.js";
|
|
3
|
+
export declare class AggregateRoot<T extends Id<string | number>> implements Identifiable<T> {
|
|
4
|
+
protected readonly id: T;
|
|
5
|
+
protected events: DomainEvent[];
|
|
6
|
+
constructor(id: T);
|
|
7
|
+
getId(): T;
|
|
8
|
+
protected raise(event: DomainEvent): void;
|
|
9
|
+
getEventsOccurred(): DomainEvent[];
|
|
10
|
+
flushEvents(): DomainEvent[];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=aggregate-root.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate-root.d.ts","sourceRoot":"","sources":["../../src/domain/aggregate-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAErD,qBAAa,aAAa,CAAC,CAAC,SAAS,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,CACpD,YAAW,YAAY,CAAC,CAAC,CAAC;IAId,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;IAFpC,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,CAAM;IAErC,YAA+B,EAAE,EAAE,CAAC,EAAI;IAEjC,KAAK,IAAI,CAAC,CAEhB;IAED,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAExC;IAEM,iBAAiB,IAAI,WAAW,EAAE,CAExC;IAEM,WAAW,IAAI,WAAW,EAAE,CAIlC;CACJ"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class AggregateRoot {
|
|
2
|
+
id;
|
|
3
|
+
events = [];
|
|
4
|
+
constructor(id) {
|
|
5
|
+
this.id = id;
|
|
6
|
+
}
|
|
7
|
+
getId() {
|
|
8
|
+
return this.id;
|
|
9
|
+
}
|
|
10
|
+
raise(event) {
|
|
11
|
+
this.events.push(event);
|
|
12
|
+
}
|
|
13
|
+
getEventsOccurred() {
|
|
14
|
+
return [...this.events];
|
|
15
|
+
}
|
|
16
|
+
flushEvents() {
|
|
17
|
+
const flushed = [...this.events];
|
|
18
|
+
this.events = [];
|
|
19
|
+
return flushed;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=aggregate-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate-root.js","sourceRoot":"","sources":["../../src/domain/aggregate-root.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,aAAa;IAKS,EAAE;IAFvB,MAAM,GAAkB,EAAE,CAAC;IAErC,YAA+B,EAAK;kBAAL,EAAE;IAAM,CAAC;IAEjC,KAAK;QACR,OAAO,IAAI,CAAC,EAAE,CAAC;IACnB,CAAC;IAES,KAAK,CAAC,KAAkB;QAC9B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEM,iBAAiB;QACpB,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAEM,WAAW;QACd,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class DomainError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class InvariantNotSatisfiedError extends DomainError {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
constructor(code: string, message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class ValidationError extends InvariantNotSatisfiedError {
|
|
8
|
+
readonly field: string;
|
|
9
|
+
constructor(field: string, code: string, message?: string);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=domain-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-error.d.ts","sourceRoot":"","sources":["../../src/domain/domain-error.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;CAAG;AAEzC,qBAAa,0BAA2B,SAAQ,WAAW;aAEnC,IAAI,EAAE,MAAM;IADhC,YACoB,IAAI,EAAE,MAAM,EAC5B,OAAO,GAAE,MAAW,EAIvB;CACJ;AAED,qBAAa,eAAgB,SAAQ,0BAA0B;aAEvC,KAAK,EAAE,MAAM;IADjC,YACoB,KAAK,EAAE,MAAM,EAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAW,EAKvB;CACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class DomainError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export class InvariantNotSatisfiedError extends DomainError {
|
|
4
|
+
code;
|
|
5
|
+
constructor(code, message = "") {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.name = "InvariantNotSatisfiedError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class ValidationError extends InvariantNotSatisfiedError {
|
|
12
|
+
field;
|
|
13
|
+
constructor(field, code, message = "") {
|
|
14
|
+
super(code, message);
|
|
15
|
+
this.field = field;
|
|
16
|
+
this.name = "ValidationError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=domain-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-error.js","sourceRoot":"","sources":["../../src/domain/domain-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;CAAG;AAEzC,MAAM,OAAO,0BAA2B,SAAQ,WAAW;IAEnC,IAAI;IADxB,YACoB,IAAY,EAC5B,OAAO,GAAW,EAAE;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAC;oBAHC,IAAI;QAIpB,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC7C,CAAC;CACJ;AAED,MAAM,OAAO,eAAgB,SAAQ,0BAA0B;IAEvC,KAAK;IADzB,YACoB,KAAa,EAC7B,IAAY,EACZ,OAAO,GAAW,EAAE;QAEpB,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;qBAJL,KAAK;QAMrB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAClC,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-event.d.ts","sourceRoot":"","sources":["../../src/domain/domain-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,qBAAa,WAAW,CACpB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACzD,SAAQ,OAAO,CAAC,CAAC,CAAC;IAChB,OAAgB,SAAS,WAExB;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-event.js","sourceRoot":"","sources":["../../src/domain/domain-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,OAAO,WAEX,SAAQ,OAAU;IAChB,MAAM,CAAU,SAAS;QACrB,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class Id<T extends string | number> {
|
|
2
|
+
private readonly value;
|
|
3
|
+
constructor(value: T);
|
|
4
|
+
getValue(): T;
|
|
5
|
+
equals(other: Id<T>): boolean;
|
|
6
|
+
}
|
|
7
|
+
export type IdOf<T> = T extends Identifiable<infer Id> ? Id : never;
|
|
8
|
+
export interface Identifiable<T extends Id<string | number> = Id<string>> {
|
|
9
|
+
getId(): T;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=identifiable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifiable.d.ts","sourceRoot":"","sources":["../../src/domain/identifiable.ts"],"names":[],"mappings":"AAAA,qBAAa,EAAE,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAClB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAzC,YAAoC,KAAK,EAAE,CAAC,EAAI;IAEzC,QAAQ,IAAI,CAAC,CAEnB;IAEM,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAKnC;CACJ;AAED,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,YAAY,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;AAEpE,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IACpE,KAAK,IAAI,CAAC,CAAC;CACd"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class Id {
|
|
2
|
+
value;
|
|
3
|
+
constructor(value) {
|
|
4
|
+
this.value = value;
|
|
5
|
+
}
|
|
6
|
+
getValue() {
|
|
7
|
+
return this.value;
|
|
8
|
+
}
|
|
9
|
+
equals(other) {
|
|
10
|
+
return (this.constructor === other.constructor &&
|
|
11
|
+
this.getValue() === other.getValue());
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=identifiable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifiable.js","sourceRoot":"","sources":["../../src/domain/identifiable.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,EAAE;IACyB,KAAK;IAAzC,YAAoC,KAAQ;qBAAR,KAAK;IAAM,CAAC;IAEzC,QAAQ;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,KAAY;QACtB,OAAO,CACH,IAAI,CAAC,WAAW,KAAK,KAAK,CAAC,WAAW;YACtC,IAAI,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,QAAQ,EAAE,CACvC,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/domain/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/domain/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Identifiable, IdOf } from "./identifiable.js";
|
|
2
|
+
export interface Repository<T extends Identifiable<any>> {
|
|
3
|
+
get(id: IdOf<T>): Promise<T>;
|
|
4
|
+
add(entity: T): Promise<void>;
|
|
5
|
+
update(entity: T): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export declare class RepositoryError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class DuplicateObjectError extends RepositoryError {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class ObjectNotFoundError extends RepositoryError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/domain/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC;IACnD,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7B,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACtC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACJ;AAED,qBAAa,oBAAqB,SAAQ,eAAe;IACrD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACJ;AAED,qBAAa,mBAAoB,SAAQ,eAAe;IACpD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class RepositoryError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = "RepositoryError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class DuplicateObjectError extends RepositoryError {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "DuplicateObjectError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class ObjectNotFoundError extends RepositoryError {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "ObjectNotFoundError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/domain/repository.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACtC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAClC,CAAC;CACJ;AAED,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IACrD,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACvC,CAAC;CACJ;AAED,MAAM,OAAO,mBAAoB,SAAQ,eAAe;IACpD,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACtC,CAAC;CACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Message } from "./message.js";
|
|
2
|
+
export interface StoredEvent {
|
|
3
|
+
position: number;
|
|
4
|
+
event: Message;
|
|
5
|
+
}
|
|
6
|
+
export interface EventStoreFetchResult {
|
|
7
|
+
events: StoredEvent[];
|
|
8
|
+
lastPosition: number;
|
|
9
|
+
}
|
|
10
|
+
export interface EventStore {
|
|
11
|
+
fetch(afterPosition: number, limit?: number): Promise<EventStoreFetchResult>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=event-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-store.d.ts","sourceRoot":"","sources":["../src/event-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,WAAW,WAAW;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACvB,KAAK,CACD,aAAa,EAAE,MAAM,EACrB,KAAK,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-store.js","sourceRoot":"","sources":["../src/event-store.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,86 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
declare class Id<T extends string | number> {
|
|
9
|
-
private readonly value;
|
|
10
|
-
constructor(value: T);
|
|
11
|
-
getValue(): T;
|
|
12
|
-
equals(other: Id<T>): boolean;
|
|
13
|
-
}
|
|
14
|
-
type IdOf<T> = T extends Identifiable<infer Id> ? Id : never;
|
|
15
|
-
interface Identifiable<T extends Id<string | number> = Id<string>> {
|
|
16
|
-
getId(): T;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare class AggregateRoot<T extends Id<string | number>> implements Identifiable<T> {
|
|
20
|
-
protected readonly id: T;
|
|
21
|
-
protected events: DomainEvent[];
|
|
22
|
-
constructor(id: T);
|
|
23
|
-
getId(): T;
|
|
24
|
-
protected raise(event: DomainEvent): void;
|
|
25
|
-
getEventsOccurred(): DomainEvent[];
|
|
26
|
-
flushEvents(): DomainEvent[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare class DomainError extends Error {
|
|
30
|
-
}
|
|
31
|
-
declare class InvariantNotSatisfiedError extends DomainError {
|
|
32
|
-
readonly code: string;
|
|
33
|
-
constructor(code: string, message?: string);
|
|
34
|
-
}
|
|
35
|
-
declare class ValidationError extends InvariantNotSatisfiedError {
|
|
36
|
-
readonly field: string;
|
|
37
|
-
constructor(field: string, code: string, message?: string);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface Repository<T extends Identifiable<any>> {
|
|
41
|
-
get(id: IdOf<T>): Promise<T>;
|
|
42
|
-
add(entity: T): Promise<void>;
|
|
43
|
-
update(entity: T): Promise<void>;
|
|
44
|
-
}
|
|
45
|
-
declare class RepositoryError extends Error {
|
|
46
|
-
constructor(message: string);
|
|
47
|
-
}
|
|
48
|
-
declare class DuplicateObjectError extends RepositoryError {
|
|
49
|
-
constructor(message: string);
|
|
50
|
-
}
|
|
51
|
-
declare class ObjectNotFoundError extends RepositoryError {
|
|
52
|
-
constructor(message: string);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
declare enum Propagation {
|
|
56
|
-
NEW = "new",
|
|
57
|
-
EXISTING = "existing",
|
|
58
|
-
NESTED = "nested"
|
|
59
|
-
}
|
|
60
|
-
type TransactionHook = () => void | Promise<void>;
|
|
61
|
-
interface BaseUnitOfWorkOptions {
|
|
62
|
-
propagation: Propagation;
|
|
63
|
-
}
|
|
64
|
-
interface UnitOfWork<Client = unknown, Options extends BaseUnitOfWorkOptions = BaseUnitOfWorkOptions> {
|
|
65
|
-
getClient(): Client;
|
|
66
|
-
scope<T>(fn: () => Promise<T>, options?: Partial<Options>): Promise<T>;
|
|
67
|
-
/** @deprecated Use scope() for transaction boundaries and withClient() for client access. */
|
|
68
|
-
wrap<T>(fn: (client: Client) => Promise<T>, options?: Partial<Options>): Promise<T>;
|
|
69
|
-
beforeCommit(hook: TransactionHook): void;
|
|
70
|
-
afterCommit(hook: TransactionHook): void;
|
|
71
|
-
afterRollback(hook: TransactionHook): void;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
declare class TransactionHooks {
|
|
75
|
-
private beforeCommitHooks;
|
|
76
|
-
private afterCommitHooks;
|
|
77
|
-
private afterRollbackHooks;
|
|
78
|
-
addBeforeCommit(hook: TransactionHook): void;
|
|
79
|
-
addAfterCommit(hook: TransactionHook): void;
|
|
80
|
-
addAfterRollback(hook: TransactionHook): void;
|
|
81
|
-
executeCommit(commitFn: () => Promise<void>, rollbackFn: () => Promise<void>): Promise<void>;
|
|
82
|
-
executeRollback(rollbackFn: () => Promise<void>, cause?: unknown): Promise<void>;
|
|
83
|
-
private runBestEffort;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { AggregateRoot, type BaseUnitOfWorkOptions, DomainError, DomainEvent, DuplicateObjectError, Id, type IdOf, type Identifiable, InvariantNotSatisfiedError, Message, ObjectNotFoundError, Propagation, type Repository, RepositoryError, type TransactionHook, TransactionHooks, type UnitOfWork, ValidationError };
|
|
1
|
+
export * from "./domain/index.js";
|
|
2
|
+
export * from "./unit-of-work.js";
|
|
3
|
+
export * from "./transaction-hooks.js";
|
|
4
|
+
export * from "./message.js";
|
|
5
|
+
export * from "./event-store.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,281 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.id = id;
|
|
7
|
-
}
|
|
8
|
-
events = [];
|
|
9
|
-
getId() {
|
|
10
|
-
return this.id;
|
|
11
|
-
}
|
|
12
|
-
raise(event) {
|
|
13
|
-
this.events.push(event);
|
|
14
|
-
}
|
|
15
|
-
getEventsOccurred() {
|
|
16
|
-
return [...this.events];
|
|
17
|
-
}
|
|
18
|
-
flushEvents() {
|
|
19
|
-
const flushed = [...this.events];
|
|
20
|
-
this.events = [];
|
|
21
|
-
return flushed;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// src/domain/domain-error.ts
|
|
26
|
-
var DomainError = class extends Error {
|
|
27
|
-
};
|
|
28
|
-
var InvariantNotSatisfiedError = class extends DomainError {
|
|
29
|
-
constructor(code, message = "") {
|
|
30
|
-
super(message);
|
|
31
|
-
this.code = code;
|
|
32
|
-
this.name = "InvariantNotSatisfiedError";
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var ValidationError = class extends InvariantNotSatisfiedError {
|
|
36
|
-
constructor(field, code, message = "") {
|
|
37
|
-
super(code, message);
|
|
38
|
-
this.field = field;
|
|
39
|
-
this.name = "ValidationError";
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var Message = class {
|
|
43
|
-
constructor(payload, options) {
|
|
44
|
-
this.payload = payload;
|
|
45
|
-
this.headers = Object.freeze(
|
|
46
|
-
this.constructor.mergeHeaders(options?.headers ?? {})
|
|
47
|
-
);
|
|
48
|
-
if (payload && typeof payload === "object") {
|
|
49
|
-
Object.freeze(payload);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
headers;
|
|
53
|
-
static getSchemaVersion() {
|
|
54
|
-
return this.schemaVersion ?? void 0;
|
|
55
|
-
}
|
|
56
|
-
static getType() {
|
|
57
|
-
return this.type ?? this.name;
|
|
58
|
-
}
|
|
59
|
-
static getIntent() {
|
|
60
|
-
return this.intent ?? void 0;
|
|
61
|
-
}
|
|
62
|
-
static newHeaders(...excludes) {
|
|
63
|
-
return generateHeaderFor(this, ...excludes);
|
|
64
|
-
}
|
|
65
|
-
static from(rawPayload, headers) {
|
|
66
|
-
const payload = this.deserializeRawPayload(rawPayload);
|
|
67
|
-
return new this(payload, {
|
|
68
|
-
headers: headers ? this.deserializeRawHeaders(headers) : this.newHeaders()
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
static deserializeRawPayload(rawPayload) {
|
|
72
|
-
return rawPayload;
|
|
73
|
-
}
|
|
74
|
-
static deserializeRawHeaders(headers) {
|
|
75
|
-
headers.createdAt = new Date(headers.createdAt);
|
|
76
|
-
return headers;
|
|
77
|
-
}
|
|
78
|
-
static mergeHeaders(headers) {
|
|
79
|
-
return {
|
|
80
|
-
...this.newHeaders(...Object.keys(headers)),
|
|
81
|
-
...headers
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
withHeader(field, value) {
|
|
85
|
-
const newHeaders = { ...this.headers, [field]: value };
|
|
86
|
-
return this.cloneWithHeaders(newHeaders);
|
|
87
|
-
}
|
|
88
|
-
clone() {
|
|
89
|
-
const cloned = Object.create(Object.getPrototypeOf(this));
|
|
90
|
-
Object.assign(cloned, this);
|
|
91
|
-
return cloned;
|
|
92
|
-
}
|
|
93
|
-
cloneWithHeaders(headers) {
|
|
94
|
-
const cloned = this.clone();
|
|
95
|
-
Object.defineProperty(cloned, "headers", {
|
|
96
|
-
value: Object.freeze(headers),
|
|
97
|
-
writable: false,
|
|
98
|
-
configurable: true
|
|
99
|
-
});
|
|
100
|
-
return cloned;
|
|
101
|
-
}
|
|
102
|
-
getHeader(field) {
|
|
103
|
-
return this.headers[field];
|
|
104
|
-
}
|
|
105
|
-
getHeaders() {
|
|
106
|
-
return Object.freeze({ ...this.headers });
|
|
107
|
-
}
|
|
108
|
-
getPayload() {
|
|
109
|
-
return this.payload;
|
|
110
|
-
}
|
|
111
|
-
getMessageId() {
|
|
112
|
-
return this.headers.id;
|
|
113
|
-
}
|
|
114
|
-
getMessageType() {
|
|
115
|
-
return this.headers.type;
|
|
116
|
-
}
|
|
117
|
-
getSchemaVersion() {
|
|
118
|
-
return this.headers.schemaVersion;
|
|
119
|
-
}
|
|
120
|
-
getTimestamp() {
|
|
121
|
-
return this.headers.createdAt;
|
|
122
|
-
}
|
|
123
|
-
getIntent() {
|
|
124
|
-
return this.constructor.getIntent();
|
|
125
|
-
}
|
|
126
|
-
toJSON() {
|
|
127
|
-
return {
|
|
128
|
-
headers: { ...this.headers },
|
|
129
|
-
payload: this.serializePayload(this.payload)
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
serialize() {
|
|
133
|
-
return JSON.parse(JSON.stringify(this.toJSON()));
|
|
134
|
-
}
|
|
135
|
-
serializePayload(payload) {
|
|
136
|
-
return payload;
|
|
137
|
-
}
|
|
138
|
-
asType(cls) {
|
|
139
|
-
const { headers, payload } = this.serialize();
|
|
140
|
-
return cls.from(payload, headers);
|
|
141
|
-
}
|
|
142
|
-
asTrace() {
|
|
143
|
-
return { id: this.getMessageId(), type: this.getMessageType() };
|
|
144
|
-
}
|
|
145
|
-
getCausation() {
|
|
146
|
-
return this.getHeader("causation");
|
|
147
|
-
}
|
|
148
|
-
getCorrelation() {
|
|
149
|
-
return this.getHeader("correlation");
|
|
150
|
-
}
|
|
151
|
-
withCausation(trace) {
|
|
152
|
-
return this.withHeader("causation", trace);
|
|
153
|
-
}
|
|
154
|
-
withCorrelation(trace) {
|
|
155
|
-
return this.withHeader("correlation", trace);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
function generateHeaderFor(cls, ...excludes) {
|
|
159
|
-
const headers = {};
|
|
160
|
-
if (!excludes.includes("id")) {
|
|
161
|
-
headers.id = v4();
|
|
162
|
-
}
|
|
163
|
-
if (!excludes.includes("type")) {
|
|
164
|
-
headers.type = cls.getType();
|
|
165
|
-
}
|
|
166
|
-
if (!excludes.includes("intent")) {
|
|
167
|
-
const intent = cls.getIntent();
|
|
168
|
-
if (intent !== void 0) {
|
|
169
|
-
headers.intent = intent;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (!excludes.includes("schemaVersion")) {
|
|
173
|
-
const schemaVersion = cls.getSchemaVersion();
|
|
174
|
-
if (schemaVersion !== void 0) {
|
|
175
|
-
headers.schemaVersion = schemaVersion;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (!excludes.includes("createdAt")) {
|
|
179
|
-
headers.createdAt = /* @__PURE__ */ new Date();
|
|
180
|
-
}
|
|
181
|
-
return headers;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// src/domain/domain-event.ts
|
|
185
|
-
var DomainEvent = class extends Message {
|
|
186
|
-
static getIntent() {
|
|
187
|
-
return "event";
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// src/domain/identifiable.ts
|
|
192
|
-
var Id = class {
|
|
193
|
-
constructor(value) {
|
|
194
|
-
this.value = value;
|
|
195
|
-
}
|
|
196
|
-
getValue() {
|
|
197
|
-
return this.value;
|
|
198
|
-
}
|
|
199
|
-
equals(other) {
|
|
200
|
-
return this.constructor === other.constructor && this.getValue() === other.getValue();
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
// src/domain/repository.ts
|
|
205
|
-
var RepositoryError = class extends Error {
|
|
206
|
-
constructor(message) {
|
|
207
|
-
super(message);
|
|
208
|
-
this.name = "RepositoryError";
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
var DuplicateObjectError = class extends RepositoryError {
|
|
212
|
-
constructor(message) {
|
|
213
|
-
super(message);
|
|
214
|
-
this.name = "DuplicateObjectError";
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
var ObjectNotFoundError = class extends RepositoryError {
|
|
218
|
-
constructor(message) {
|
|
219
|
-
super(message);
|
|
220
|
-
this.name = "ObjectNotFoundError";
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
// src/unit-of-work.ts
|
|
225
|
-
var Propagation = /* @__PURE__ */ ((Propagation2) => {
|
|
226
|
-
Propagation2["NEW"] = "new";
|
|
227
|
-
Propagation2["EXISTING"] = "existing";
|
|
228
|
-
Propagation2["NESTED"] = "nested";
|
|
229
|
-
return Propagation2;
|
|
230
|
-
})(Propagation || {});
|
|
231
|
-
|
|
232
|
-
// src/transaction-hooks.ts
|
|
233
|
-
var TransactionHooks = class {
|
|
234
|
-
beforeCommitHooks = [];
|
|
235
|
-
afterCommitHooks = [];
|
|
236
|
-
afterRollbackHooks = [];
|
|
237
|
-
addBeforeCommit(hook) {
|
|
238
|
-
this.beforeCommitHooks.push(hook);
|
|
239
|
-
}
|
|
240
|
-
addAfterCommit(hook) {
|
|
241
|
-
this.afterCommitHooks.push(hook);
|
|
242
|
-
}
|
|
243
|
-
addAfterRollback(hook) {
|
|
244
|
-
this.afterRollbackHooks.push(hook);
|
|
245
|
-
}
|
|
246
|
-
async executeCommit(commitFn, rollbackFn) {
|
|
247
|
-
try {
|
|
248
|
-
for (const hook of this.beforeCommitHooks) await hook();
|
|
249
|
-
} catch (e) {
|
|
250
|
-
await this.executeRollback(rollbackFn, e);
|
|
251
|
-
throw e;
|
|
252
|
-
}
|
|
253
|
-
await commitFn();
|
|
254
|
-
await this.runBestEffort(this.afterCommitHooks);
|
|
255
|
-
}
|
|
256
|
-
async executeRollback(rollbackFn, cause) {
|
|
257
|
-
await rollbackFn();
|
|
258
|
-
await this.runBestEffort(this.afterRollbackHooks, cause);
|
|
259
|
-
}
|
|
260
|
-
async runBestEffort(hooks, cause) {
|
|
261
|
-
const errors = [];
|
|
262
|
-
for (const hook of hooks) {
|
|
263
|
-
try {
|
|
264
|
-
await hook();
|
|
265
|
-
} catch (e) {
|
|
266
|
-
errors.push(e);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
if (errors.length > 0) {
|
|
270
|
-
throw cause !== void 0 ? new AggregateError(
|
|
271
|
-
errors,
|
|
272
|
-
"Transaction hook(s) failed",
|
|
273
|
-
{ cause }
|
|
274
|
-
) : new AggregateError(errors);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
export { AggregateRoot, DomainError, DomainEvent, DuplicateObjectError, Id, InvariantNotSatisfiedError, Message, ObjectNotFoundError, Propagation, RepositoryError, TransactionHooks, ValidationError };
|
|
280
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./domain/index.js";
|
|
2
|
+
export * from "./unit-of-work.js";
|
|
3
|
+
export * from "./transaction-hooks.js";
|
|
4
|
+
export * from "./message.js";
|
|
5
|
+
export * from "./event-store.js";
|
|
281
6
|
//# sourceMappingURL=index.js.map
|