ddd-node 5.0.0 → 6.0.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.
Files changed (85) hide show
  1. package/dist/core/aggregate.d.ts +67 -0
  2. package/dist/core/aggregate.js +178 -0
  3. package/dist/core/command.d.ts +13 -0
  4. package/dist/core/command.js +18 -0
  5. package/dist/core/entity.d.ts +17 -0
  6. package/dist/core/entity.js +23 -0
  7. package/dist/core/event.d.ts +27 -0
  8. package/dist/core/event.js +23 -0
  9. package/dist/{base → core}/id.d.ts +2 -1
  10. package/dist/{base → core}/id.js +6 -0
  11. package/dist/{base → core}/index.d.ts +5 -3
  12. package/dist/{base → core}/index.js +5 -3
  13. package/dist/core/message.d.ts +21 -0
  14. package/dist/core/message.js +30 -0
  15. package/dist/core/metadata.d.ts +14 -0
  16. package/dist/core/metadata.js +43 -0
  17. package/dist/core/model-type.d.ts +86 -0
  18. package/dist/core/model-type.js +55 -0
  19. package/dist/core/model.d.ts +14 -0
  20. package/dist/{base/props-envelope.js → core/model.js} +17 -14
  21. package/dist/core/registry.d.ts +12 -0
  22. package/dist/core/registry.js +28 -0
  23. package/dist/core/value-object.d.ts +10 -0
  24. package/dist/{base → core}/value-object.js +3 -11
  25. package/dist/decorators/aggregate.d.ts +6 -7
  26. package/dist/decorators/aggregate.js +16 -19
  27. package/dist/decorators/command.d.ts +2 -2
  28. package/dist/decorators/command.js +7 -11
  29. package/dist/decorators/entity.d.ts +2 -2
  30. package/dist/decorators/entity.js +7 -9
  31. package/dist/decorators/event.d.ts +2 -2
  32. package/dist/decorators/event.js +7 -11
  33. package/dist/decorators/model.d.ts +3 -0
  34. package/dist/decorators/model.js +12 -0
  35. package/dist/decorators/value-object.d.ts +2 -2
  36. package/dist/decorators/value-object.js +7 -9
  37. package/dist/index.d.ts +1 -3
  38. package/dist/index.js +1 -3
  39. package/dist/types/class.d.ts +0 -5
  40. package/dist/utils/index.d.ts +0 -1
  41. package/dist/utils/index.js +0 -1
  42. package/package.json +1 -1
  43. package/tsconfig.json +1 -2
  44. package/dist/base/aggregate.d.ts +0 -68
  45. package/dist/base/aggregate.js +0 -175
  46. package/dist/base/command.d.ts +0 -21
  47. package/dist/base/command.js +0 -22
  48. package/dist/base/entity.d.ts +0 -23
  49. package/dist/base/entity.js +0 -31
  50. package/dist/base/errors/aggregate.error.d.ts +0 -21
  51. package/dist/base/errors/aggregate.error.js +0 -45
  52. package/dist/base/event.d.ts +0 -29
  53. package/dist/base/event.js +0 -26
  54. package/dist/base/message.d.ts +0 -33
  55. package/dist/base/message.js +0 -42
  56. package/dist/base/props-envelope.d.ts +0 -11
  57. package/dist/base/repository.d.ts +0 -6
  58. package/dist/base/repository.js +0 -2
  59. package/dist/base/value-object.d.ts +0 -16
  60. package/dist/decorators/index.d.ts +0 -6
  61. package/dist/decorators/index.js +0 -22
  62. package/dist/decorators/message.d.ts +0 -2
  63. package/dist/decorators/message.js +0 -10
  64. package/dist/metadata/aggregate.d.ts +0 -14
  65. package/dist/metadata/aggregate.js +0 -70
  66. package/dist/metadata/command.d.ts +0 -6
  67. package/dist/metadata/command.js +0 -19
  68. package/dist/metadata/constants.d.ts +0 -8
  69. package/dist/metadata/constants.js +0 -11
  70. package/dist/metadata/entity.d.ts +0 -6
  71. package/dist/metadata/entity.js +0 -19
  72. package/dist/metadata/errors.d.ts +0 -18
  73. package/dist/metadata/errors.js +0 -39
  74. package/dist/metadata/event.d.ts +0 -6
  75. package/dist/metadata/event.js +0 -19
  76. package/dist/metadata/index.d.ts +0 -7
  77. package/dist/metadata/index.js +0 -23
  78. package/dist/metadata/message.d.ts +0 -3
  79. package/dist/metadata/message.js +0 -16
  80. package/dist/metadata/registry.d.ts +0 -9
  81. package/dist/metadata/registry.js +0 -23
  82. package/dist/metadata/value-object.d.ts +0 -6
  83. package/dist/metadata/value-object.js +0 -19
  84. package/dist/utils/id.d.ts +0 -1
  85. package/dist/utils/id.js +0 -8
@@ -1,175 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AggregateES = exports.Aggregate = void 0;
4
- const aggregate_1 = require("../metadata/aggregate");
5
- const to_array_1 = require("../utils/to-array");
6
- const entity_1 = require("./entity");
7
- const aggregate_error_1 = require("./errors/aggregate.error");
8
- const id_1 = require("./id");
9
- class Aggregate extends entity_1.Entity {
10
- constructor(metadata, props) {
11
- super({ id: metadata.id }, props);
12
- this.events = [];
13
- this._aggregateType = metadata.aggregateType;
14
- this._version = metadata.version;
15
- }
16
- static aggregateType() {
17
- return (0, aggregate_1.getAggregateType)(this.prototype);
18
- }
19
- static newAggregate(props, metadata) {
20
- return new this(Object.assign({ aggregateType: this.aggregateType(), id: id_1.Id.unique(), version: 0 }, metadata), props);
21
- }
22
- get version() {
23
- return this._version;
24
- }
25
- get aggregateType() {
26
- return this._aggregateType;
27
- }
28
- getEvents() {
29
- return this.events;
30
- }
31
- hasEvents() {
32
- return Boolean(this.events.length);
33
- }
34
- nextVersion() {
35
- return this.version + 1;
36
- }
37
- newEvent(eventClass, props, metadata) {
38
- return eventClass.newEvent({
39
- id: this.id,
40
- version: this.nextVersion(),
41
- }, props, metadata);
42
- }
43
- addEvent(event) {
44
- this.events.push(event);
45
- }
46
- addNewEvent(eventClass, props, metadata) {
47
- const event = this.newEvent(eventClass, props, metadata);
48
- this.addEvent(event);
49
- }
50
- }
51
- exports.Aggregate = Aggregate;
52
- class AggregateES extends Aggregate {
53
- constructor() {
54
- super(...arguments);
55
- this.handledCommands = [];
56
- this.pastEvents = [];
57
- }
58
- static stream(id, events) {
59
- const aggregate = this.newAggregate(undefined, { id });
60
- aggregate.applyEvents(events, true);
61
- return aggregate;
62
- }
63
- static snapshot(snapshot, eventsAfterSnapshot) {
64
- const { metadata, props } = snapshot;
65
- const aggregate = new this(metadata, props);
66
- aggregate.applyEvents(eventsAfterSnapshot, true);
67
- return aggregate;
68
- }
69
- getHandledCommands() {
70
- return this.handledCommands;
71
- }
72
- getPastEvents() {
73
- return this.pastEvents;
74
- }
75
- lastEvent() {
76
- return this.hasEvents() ? this.events.at(-1) : this.pastEvents.at(-1);
77
- }
78
- currentVersion() {
79
- const lastEvent = this.lastEvent();
80
- if (lastEvent)
81
- return lastEvent.aggregate.version;
82
- return this.version;
83
- }
84
- nextVersion() {
85
- return this.currentVersion() + 1;
86
- }
87
- addPastEvent(event) {
88
- if (this.hasEvents())
89
- throw new aggregate_error_1.PastEventCannotBeAddedError();
90
- this.pastEvents.push(event);
91
- }
92
- validateEventBeforeApply(event) {
93
- const { aggregateType } = event;
94
- const { id, version } = event.aggregate;
95
- if (aggregateType !== this.aggregateType)
96
- throw new aggregate_error_1.InvalidEventAggregateTypeError();
97
- if (!id.equals(this.id))
98
- throw new aggregate_error_1.InvalidEventAggregateIdError();
99
- if (version !== this.nextVersion())
100
- throw new aggregate_error_1.InvalidEventAggregateVersionError();
101
- }
102
- getEventApplierSafe(eventType) {
103
- const prototype = Object.getPrototypeOf(this);
104
- const eventApplier = (0, aggregate_1.getAggregateEventApplier)(prototype, eventType);
105
- if (eventApplier)
106
- return eventApplier.bind(this);
107
- return null;
108
- }
109
- getEventApplier(eventType) {
110
- const applier = this.getEventApplierSafe(eventType);
111
- if (!applier)
112
- throw new aggregate_error_1.EventApplierNotFoundError(eventType);
113
- return applier;
114
- }
115
- applyEvent(event, fromHistory = false) {
116
- const { eventType } = event;
117
- const applier = this.getEventApplier(eventType);
118
- this.validateEventBeforeApply(event);
119
- if (fromHistory)
120
- this.addPastEvent(event);
121
- else
122
- this.addEvent(event);
123
- applier(event);
124
- }
125
- applyEvents(events, fromHistory = false) {
126
- events.forEach((event) => {
127
- this.applyEvent(event, fromHistory);
128
- });
129
- }
130
- getCommandHandlerSafe(commandType) {
131
- const prototype = Object.getPrototypeOf(this);
132
- const commandHandler = (0, aggregate_1.getAggregateCommandHandler)(prototype, commandType);
133
- if (commandHandler)
134
- return commandHandler.bind(this);
135
- return null;
136
- }
137
- getCommandHandler(commandType) {
138
- const handler = this.getCommandHandlerSafe(commandType);
139
- if (!handler)
140
- throw new aggregate_error_1.CommandHandlerNotFoundError(commandType);
141
- return handler;
142
- }
143
- validateCommandBeforeProcess(command) {
144
- const { aggregateType } = command;
145
- if (aggregateType !== this.aggregateType)
146
- throw new aggregate_error_1.InvalidCommandAggregateTypeError();
147
- }
148
- processCommand(command) {
149
- const { commandType } = command;
150
- const handler = this.getCommandHandler(commandType);
151
- this.validateCommandBeforeProcess(command);
152
- const events = (0, to_array_1.toArray)(handler(command));
153
- const { correlationId, causationId } = command;
154
- events.forEach((event) => {
155
- if (correlationId)
156
- event.setCorrelationId(correlationId);
157
- if (causationId)
158
- event.setCausationId(causationId);
159
- this.applyEvent(event);
160
- });
161
- this.handledCommands.push(command);
162
- return events;
163
- }
164
- snap() {
165
- return {
166
- metadata: {
167
- id: this.id,
168
- aggregateType: this.aggregateType,
169
- version: this.version,
170
- },
171
- props: this.getProps(),
172
- };
173
- }
174
- }
175
- exports.AggregateES = AggregateES;
@@ -1,21 +0,0 @@
1
- import { Class } from "../types/class";
2
- import { ClassStatic } from "../types/class-static";
3
- import { IMessageMetadata, Message } from "./message";
4
- import { PropsOf } from "./props-envelope";
5
- export interface ICommandMetadata extends IMessageMetadata {
6
- readonly commandType: string;
7
- }
8
- export type NewCommandMetadataOptions = Omit<ICommandMetadata, "aggregateType" | "timestamp">;
9
- export declare class Command<P extends object> extends Message<P> implements ICommandMetadata {
10
- private readonly _commandType;
11
- constructor(metadata: ICommandMetadata, props: P);
12
- static commandType(): string;
13
- static newCommand<T extends AnyCommand>(this: CommandClass<T>, props: PropsOf<T>, metadata?: NewCommandMetadataOptions): T;
14
- get commandType(): string;
15
- }
16
- export type AnyCommand = Command<any>;
17
- export type CommandConstructorParamsWithProps<P extends object> = ConstructorParameters<typeof Command<P>>;
18
- export type CommandClassWithProps<P extends object> = Class<Command<P>, CommandConstructorParamsWithProps<P>> & ClassStatic<typeof Command<P>>;
19
- export type CommandConstructorParams<T extends AnyCommand> = CommandConstructorParamsWithProps<PropsOf<T>>;
20
- export type CommandClass<T extends AnyCommand> = Class<T, CommandConstructorParams<T>> & ClassStatic<typeof Command<PropsOf<T>>>;
21
- export type AnyCommandClass = Class<AnyCommand>;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Command = void 0;
4
- const command_1 = require("../metadata/command");
5
- const id_1 = require("./id");
6
- const message_1 = require("./message");
7
- class Command extends message_1.Message {
8
- constructor(metadata, props) {
9
- super(metadata, props);
10
- this._commandType = metadata.commandType;
11
- }
12
- static commandType() {
13
- return (0, command_1.getCommandType)(this.prototype);
14
- }
15
- static newCommand(props, metadata) {
16
- return new this(Object.assign({ commandType: this.commandType(), id: id_1.Id.unique(), timestamp: Date.now(), aggregateType: this.aggregateType() }, metadata), props);
17
- }
18
- get commandType() {
19
- return this._commandType;
20
- }
21
- }
22
- exports.Command = Command;
@@ -1,23 +0,0 @@
1
- import { Class } from "../types/class";
2
- import { ClassStatic } from "../types/class-static";
3
- import { Id } from "./id";
4
- import { PropsEnvelope, PropsOf } from "./props-envelope";
5
- export interface IEntityMetadata {
6
- readonly id: Id;
7
- }
8
- export type NewEntityMetadataOptions = Partial<IEntityMetadata>;
9
- export declare class Entity<P extends object> extends PropsEnvelope<P> implements IEntityMetadata {
10
- private readonly _id;
11
- constructor(metadata: IEntityMetadata, props?: P);
12
- static entityType(): string;
13
- static newEntity<T extends AnyEntity>(this: EntityClass<T>, props?: PropsOf<T>, metadata?: NewEntityMetadataOptions): T;
14
- get id(): Id;
15
- entityType(): string;
16
- equals<E extends AnyEntity>(entity: E): boolean;
17
- }
18
- export type AnyEntity = Entity<any>;
19
- export type EntityConstructorParamsWithProps<P extends object> = ConstructorParameters<typeof Entity<P>>;
20
- export type EntityClassWithProps<P extends object> = Class<Entity<P>, EntityConstructorParamsWithProps<P>> & ClassStatic<typeof Entity<P>>;
21
- export type EntityConstructorParams<T extends AnyEntity> = EntityConstructorParamsWithProps<PropsOf<T>>;
22
- export type EntityClass<T extends AnyEntity> = Class<T, EntityConstructorParams<T>> & ClassStatic<typeof Entity<PropsOf<T>>>;
23
- export type AnyEntityClass = Class<AnyEntity>;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Entity = void 0;
4
- const entity_1 = require("../metadata/entity");
5
- const id_1 = require("./id");
6
- const props_envelope_1 = require("./props-envelope");
7
- class Entity extends props_envelope_1.PropsEnvelope {
8
- constructor(metadata, props) {
9
- super(props);
10
- this._id = metadata.id;
11
- }
12
- static entityType() {
13
- return (0, entity_1.getEntityType)(this.prototype);
14
- }
15
- static newEntity(props, metadata) {
16
- return new this(Object.assign({ id: id_1.Id.unique() }, metadata), props);
17
- }
18
- get id() {
19
- return this._id;
20
- }
21
- entityType() {
22
- const prototype = Object.getPrototypeOf(this);
23
- return (0, entity_1.getEntityType)(prototype);
24
- }
25
- equals(entity) {
26
- const equalsType = entity instanceof this.constructor;
27
- const equalsId = entity.id.equals(entity.id);
28
- return equalsType && equalsId;
29
- }
30
- }
31
- exports.Entity = Entity;
@@ -1,21 +0,0 @@
1
- export declare class PastEventCannotBeAddedError extends Error {
2
- constructor();
3
- }
4
- export declare class EventApplierNotFoundError extends Error {
5
- constructor(eventType: string);
6
- }
7
- export declare class CommandHandlerNotFoundError extends Error {
8
- constructor(commandType: string);
9
- }
10
- export declare class InvalidEventAggregateTypeError extends Error {
11
- constructor();
12
- }
13
- export declare class InvalidEventAggregateIdError extends Error {
14
- constructor();
15
- }
16
- export declare class InvalidEventAggregateVersionError extends Error {
17
- constructor();
18
- }
19
- export declare class InvalidCommandAggregateTypeError extends Error {
20
- constructor();
21
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidCommandAggregateTypeError = exports.InvalidEventAggregateVersionError = exports.InvalidEventAggregateIdError = exports.InvalidEventAggregateTypeError = exports.CommandHandlerNotFoundError = exports.EventApplierNotFoundError = exports.PastEventCannotBeAddedError = void 0;
4
- class PastEventCannotBeAddedError extends Error {
5
- constructor() {
6
- super("Past event cannot be added once a new event has been added");
7
- }
8
- }
9
- exports.PastEventCannotBeAddedError = PastEventCannotBeAddedError;
10
- class EventApplierNotFoundError extends Error {
11
- constructor(eventType) {
12
- super(`Not found event applier for event with type ${eventType}`);
13
- }
14
- }
15
- exports.EventApplierNotFoundError = EventApplierNotFoundError;
16
- class CommandHandlerNotFoundError extends Error {
17
- constructor(commandType) {
18
- super(`Not found command handler for command with type ${commandType}`);
19
- }
20
- }
21
- exports.CommandHandlerNotFoundError = CommandHandlerNotFoundError;
22
- class InvalidEventAggregateTypeError extends Error {
23
- constructor() {
24
- super("The event must have the aggregate type equal to the type of the aggregate instance");
25
- }
26
- }
27
- exports.InvalidEventAggregateTypeError = InvalidEventAggregateTypeError;
28
- class InvalidEventAggregateIdError extends Error {
29
- constructor() {
30
- super("The event must have the aggregate id equal to the id of the aggregate instance");
31
- }
32
- }
33
- exports.InvalidEventAggregateIdError = InvalidEventAggregateIdError;
34
- class InvalidEventAggregateVersionError extends Error {
35
- constructor() {
36
- super("The event must have the aggregate version equal to the next version of the aggregate instance");
37
- }
38
- }
39
- exports.InvalidEventAggregateVersionError = InvalidEventAggregateVersionError;
40
- class InvalidCommandAggregateTypeError extends Error {
41
- constructor() {
42
- super("The command must have the aggregate type equal to the type of the aggregate instance");
43
- }
44
- }
45
- exports.InvalidCommandAggregateTypeError = InvalidCommandAggregateTypeError;
@@ -1,29 +0,0 @@
1
- import { Class } from "../types/class";
2
- import { ClassStatic } from "../types/class-static";
3
- import { Id } from "./id";
4
- import { IMessageMetadata, Message } from "./message";
5
- import { PropsOf } from "./props-envelope";
6
- export interface IEventAggregate {
7
- readonly id: Id;
8
- readonly version: number;
9
- }
10
- export interface IEventMetadata extends IMessageMetadata {
11
- readonly eventType: string;
12
- readonly aggregate: IEventAggregate;
13
- }
14
- export type NewEventMetadataOptions = Omit<IEventMetadata, "aggregateType" | "aggregate" | "timestamp">;
15
- export declare class Event<P extends object> extends Message<P> implements IEventMetadata {
16
- private readonly _eventType;
17
- private readonly _aggregate;
18
- constructor(metadata: IEventMetadata, props: P);
19
- static eventType(): string;
20
- static newEvent<T extends AnyEvent>(this: EventClass<T>, aggregate: IEventAggregate, props: PropsOf<T>, metadata?: NewEventMetadataOptions): T;
21
- get eventType(): string;
22
- get aggregate(): IEventAggregate;
23
- }
24
- export type AnyEvent = Event<any>;
25
- export type EventConstructorParamsWithProps<P extends object> = ConstructorParameters<typeof Event<P>>;
26
- export type EventClassWithProps<P extends object> = Class<Event<P>, EventConstructorParamsWithProps<P>> & ClassStatic<typeof Event<P>>;
27
- export type EventConstructorParams<T extends AnyEvent> = EventConstructorParamsWithProps<PropsOf<T>>;
28
- export type EventClass<T extends AnyEvent> = Class<T, EventConstructorParams<T>> & ClassStatic<typeof Event<PropsOf<T>>>;
29
- export type AnyEventClass = Class<AnyEvent>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Event = void 0;
4
- const event_1 = require("../metadata/event");
5
- const id_1 = require("./id");
6
- const message_1 = require("./message");
7
- class Event extends message_1.Message {
8
- constructor(metadata, props) {
9
- super(metadata, props);
10
- this._eventType = metadata.eventType;
11
- this._aggregate = metadata.aggregate;
12
- }
13
- static eventType() {
14
- return (0, event_1.getEventType)(this.prototype);
15
- }
16
- static newEvent(aggregate, props, metadata) {
17
- return new this(Object.assign({ eventType: this.eventType(), id: id_1.Id.unique(), timestamp: Date.now(), aggregateType: this.aggregateType(), aggregate }, metadata), props);
18
- }
19
- get eventType() {
20
- return this._eventType;
21
- }
22
- get aggregate() {
23
- return this._aggregate;
24
- }
25
- }
26
- exports.Event = Event;
@@ -1,33 +0,0 @@
1
- import { Class } from "../types/class";
2
- import { ClassStatic } from "../types/class-static";
3
- import { Id } from "./id";
4
- import { PropsEnvelope, PropsOf } from "./props-envelope";
5
- export interface IMessageMetadata {
6
- readonly id: Id;
7
- readonly timestamp: number;
8
- readonly aggregateType: string;
9
- correlationId?: string;
10
- causationId?: string;
11
- }
12
- export declare class Message<P extends object> extends PropsEnvelope<P> implements IMessageMetadata {
13
- private readonly _id;
14
- private readonly _timestamp;
15
- private readonly _aggregateType;
16
- private _correlationId?;
17
- private _causationId?;
18
- constructor(metadata: IMessageMetadata, props: P);
19
- static aggregateType(): string;
20
- get id(): Id;
21
- get timestamp(): number;
22
- get aggregateType(): string;
23
- get correlationId(): string | undefined;
24
- get causationId(): string | undefined;
25
- setCorrelationId(correlationId: string): void;
26
- setCausationId(causationId: string): void;
27
- }
28
- export type AnyMessage = Message<any>;
29
- export type MessageConstructorParamsWithProps<P extends object> = ConstructorParameters<typeof Message<P>>;
30
- export type MessageClassWithProps<P extends object> = Class<Message<P>, MessageConstructorParamsWithProps<P>> & ClassStatic<typeof Message<P>>;
31
- export type MessageConstructorParams<T extends AnyMessage> = MessageConstructorParamsWithProps<PropsOf<T>>;
32
- export type MessageClass<T extends AnyMessage> = Class<T, MessageConstructorParams<T>> & ClassStatic<typeof Message<PropsOf<T>>>;
33
- export type AnyMessageClass = Class<AnyMessage>;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Message = void 0;
4
- const message_1 = require("../metadata/message");
5
- const props_envelope_1 = require("./props-envelope");
6
- class Message extends props_envelope_1.PropsEnvelope {
7
- constructor(metadata, props) {
8
- super(props);
9
- this._id = metadata.id;
10
- this._timestamp = metadata.timestamp;
11
- this._aggregateType = metadata.aggregateType;
12
- this._correlationId = metadata === null || metadata === void 0 ? void 0 : metadata.correlationId;
13
- this._causationId = metadata === null || metadata === void 0 ? void 0 : metadata.causationId;
14
- }
15
- static aggregateType() {
16
- return (0, message_1.getMessageAggregateType)(this.prototype);
17
- }
18
- get id() {
19
- return this._id;
20
- }
21
- get timestamp() {
22
- return this._timestamp;
23
- }
24
- get aggregateType() {
25
- return this._aggregateType;
26
- }
27
- get correlationId() {
28
- return this._correlationId;
29
- }
30
- get causationId() {
31
- return this._causationId;
32
- }
33
- setCorrelationId(correlationId) {
34
- if (!this.correlationId)
35
- this._correlationId = correlationId;
36
- }
37
- setCausationId(causationId) {
38
- if (!this.causationId)
39
- this._causationId = causationId;
40
- }
41
- }
42
- exports.Message = Message;
@@ -1,11 +0,0 @@
1
- export declare class PropsEnvelope<P extends object> {
2
- private _props;
3
- constructor(props?: P);
4
- validate(): void;
5
- initProps(props: P): void;
6
- protected get props(): P;
7
- getProps(): P;
8
- }
9
- export type AnyPropsEnvelope = PropsEnvelope<any>;
10
- export type PropsOf<T extends AnyPropsEnvelope> = T extends PropsEnvelope<infer P> ? P : never;
11
- export type EmptyProps = {};
@@ -1,6 +0,0 @@
1
- import { AnyAggregate } from "./aggregate";
2
- import { Id } from "./id";
3
- export interface Repository<T extends AnyAggregate> {
4
- findById(id: Id): Promise<T | undefined>;
5
- save(aggregate: T): Promise<void>;
6
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +0,0 @@
1
- import { Class } from "../types/class";
2
- import { ClassStatic } from "../types/class-static";
3
- import { PropsEnvelope, PropsOf } from "./props-envelope";
4
- export declare class ValueObject<P extends object> extends PropsEnvelope<P> {
5
- constructor(props: P);
6
- static valueObjectType(): string;
7
- valueObjectType(): string;
8
- equals<V extends AnyValueObject>(vo: V): boolean;
9
- with(props: Partial<P>): this;
10
- }
11
- export type AnyValueObject = ValueObject<any>;
12
- export type ValueObjectConstructorParamsWithProps<P extends object> = ConstructorParameters<typeof ValueObject<P>>;
13
- export type ValueObjectClassWithProps<P extends object> = Class<ValueObject<P>, ValueObjectConstructorParamsWithProps<P>> & ClassStatic<typeof ValueObject<P>>;
14
- export type ValueObjectConstructorParams<T extends AnyValueObject> = ValueObjectConstructorParamsWithProps<PropsOf<T>>;
15
- export type ValueObjectClass<T extends AnyValueObject> = Class<T, ValueObjectConstructorParams<T>> & ClassStatic<typeof ValueObject<PropsOf<T>>>;
16
- export type AnyValueObjectClass = Class<AnyValueObject>;
@@ -1,6 +0,0 @@
1
- export * from "./aggregate";
2
- export * from "./message";
3
- export * from "./entity";
4
- export * from "./command";
5
- export * from "./event";
6
- export * from "./value-object";
@@ -1,22 +0,0 @@
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("./message"), exports);
19
- __exportStar(require("./entity"), exports);
20
- __exportStar(require("./command"), exports);
21
- __exportStar(require("./event"), exports);
22
- __exportStar(require("./value-object"), exports);
@@ -1,2 +0,0 @@
1
- import { AnyMessageClass } from "../base/message";
2
- export declare const TypeMessage: (aggregateType: string) => <U extends AnyMessageClass>(target: U) => void;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeMessage = void 0;
4
- const message_1 = require("../metadata/message");
5
- const TypeMessage = (aggregateType) => {
6
- return (target) => {
7
- (0, message_1.defineMessageAggregateType)(target.prototype, aggregateType);
8
- };
9
- };
10
- exports.TypeMessage = TypeMessage;
@@ -1,14 +0,0 @@
1
- import { AggregateCommandHandler, AggregateEventApplier, AnyAggregateClass } from "../base/aggregate";
2
- import { AnyCommand } from "../base/command";
3
- import { AnyEvent } from "../base/event";
4
- import "reflect-metadata";
5
- import { Registry } from "./registry";
6
- export declare const AggregateRegistry: Registry<AnyAggregateClass>;
7
- export declare const defineAggregateType: (target: object, aggregateType: string) => void;
8
- export declare const getAggregateType: (target: object) => string;
9
- export declare const getAggregateEventAppliersMap: <T extends AnyEvent>(target: object) => Map<string, AggregateEventApplier<T>>;
10
- export declare const defineAggregateEventApplier: <T extends AnyEvent>(target: object, eventType: string, applier: AggregateEventApplier<T>) => void;
11
- export declare const getAggregateEventApplier: (target: object | null, eventType: string) => AggregateEventApplier<AnyEvent> | null;
12
- export declare const getAggregateCommandHandlersMap: <T extends AnyCommand>(target: object) => Map<string, AggregateCommandHandler<T>>;
13
- export declare const defineAggregateCommandHandler: <T extends AnyCommand>(target: object, commandType: string, handler: AggregateCommandHandler<T>) => void;
14
- export declare const getAggregateCommandHandler: (target: object | null, commandType: string) => AggregateCommandHandler<AnyCommand> | null;
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAggregateCommandHandler = exports.defineAggregateCommandHandler = exports.getAggregateCommandHandlersMap = exports.getAggregateEventApplier = exports.defineAggregateEventApplier = exports.getAggregateEventAppliersMap = exports.getAggregateType = exports.defineAggregateType = exports.AggregateRegistry = void 0;
4
- require("reflect-metadata");
5
- const constants_1 = require("./constants");
6
- const errors_1 = require("./errors");
7
- const registry_1 = require("./registry");
8
- exports.AggregateRegistry = new registry_1.Registry();
9
- // Aggregate Type
10
- const defineAggregateType = (target, aggregateType) => {
11
- Reflect.defineMetadata(constants_1.AGGREGATE_TYPE, aggregateType, target);
12
- };
13
- exports.defineAggregateType = defineAggregateType;
14
- const getAggregateType = (target) => {
15
- const aggregateType = Reflect.getMetadata(constants_1.AGGREGATE_TYPE, target);
16
- if (!aggregateType)
17
- throw new errors_1.AggregateTypeHasNotBeenSetError();
18
- return aggregateType;
19
- };
20
- exports.getAggregateType = getAggregateType;
21
- // Aggregate Event Applier
22
- const getAggregateEventAppliersMap = (target) => {
23
- return (Reflect.getMetadata(constants_1.AGGREGATE_EVENTS_APPLIERS, target) ||
24
- new Map());
25
- };
26
- exports.getAggregateEventAppliersMap = getAggregateEventAppliersMap;
27
- const defineAggregateEventApplier = (target, eventType, applier) => {
28
- const eventAppliersMap = (0, exports.getAggregateEventAppliersMap)(target);
29
- eventAppliersMap.set(eventType, applier);
30
- Reflect.defineMetadata(constants_1.AGGREGATE_EVENTS_APPLIERS, eventAppliersMap, target);
31
- };
32
- exports.defineAggregateEventApplier = defineAggregateEventApplier;
33
- const getAggregateEventApplier = (target, eventType) => {
34
- if (!target)
35
- return null;
36
- do {
37
- const eventAppliersMap = (0, exports.getAggregateEventAppliersMap)(target);
38
- const eventApplier = eventAppliersMap.get(eventType);
39
- if (eventApplier)
40
- return eventApplier;
41
- } while ((target = Reflect.getPrototypeOf(target)) &&
42
- target !== Object.prototype);
43
- return null;
44
- };
45
- exports.getAggregateEventApplier = getAggregateEventApplier;
46
- // Aggregate Command Handler
47
- const getAggregateCommandHandlersMap = (target) => {
48
- return (Reflect.getMetadata(constants_1.AGGREGATE_COMMANDS_HANDLERS, target) ||
49
- new Map());
50
- };
51
- exports.getAggregateCommandHandlersMap = getAggregateCommandHandlersMap;
52
- const defineAggregateCommandHandler = (target, commandType, handler) => {
53
- const commandHandlersMap = (0, exports.getAggregateCommandHandlersMap)(target);
54
- commandHandlersMap.set(commandType, handler);
55
- Reflect.defineMetadata(constants_1.AGGREGATE_COMMANDS_HANDLERS, commandHandlersMap, target);
56
- };
57
- exports.defineAggregateCommandHandler = defineAggregateCommandHandler;
58
- const getAggregateCommandHandler = (target, commandType) => {
59
- if (!target)
60
- return null;
61
- do {
62
- const commandHandlersMap = (0, exports.getAggregateCommandHandlersMap)(target);
63
- const commandHandler = commandHandlersMap.get(commandType);
64
- if (commandHandler)
65
- return commandHandler;
66
- } while ((target = Reflect.getPrototypeOf(target)) &&
67
- target !== Object.prototype);
68
- return null;
69
- };
70
- exports.getAggregateCommandHandler = getAggregateCommandHandler;
@@ -1,6 +0,0 @@
1
- import { AnyCommandClass } from "../base/command";
2
- import "reflect-metadata";
3
- import { Registry } from "./registry";
4
- export declare const CommandRegistry: Registry<AnyCommandClass>;
5
- export declare const defineCommandType: (target: object, commandType: string) => void;
6
- export declare const getCommandType: (target: object) => string;