@cqrs-ddd/core 0.3.0 → 0.4.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.
Files changed (174) hide show
  1. package/README.md +2 -705
  2. package/dist/application/base.command.js +5 -9
  3. package/dist/application/base.command.js.map +1 -1
  4. package/dist/application/base.query.d.ts +1 -1
  5. package/dist/application/base.query.d.ts.map +1 -1
  6. package/dist/application/base.query.js +7 -11
  7. package/dist/application/base.query.js.map +1 -1
  8. package/dist/application/command-base.handler.d.ts +2 -2
  9. package/dist/application/command-base.handler.d.ts.map +1 -1
  10. package/dist/application/command-base.handler.js +3 -7
  11. package/dist/application/command-base.handler.js.map +1 -1
  12. package/dist/application/index.d.ts +10 -10
  13. package/dist/application/index.d.ts.map +1 -1
  14. package/dist/application/index.js +10 -26
  15. package/dist/application/index.js.map +1 -1
  16. package/dist/application/ports/cache.port.js +1 -4
  17. package/dist/application/ports/cache.port.js.map +1 -1
  18. package/dist/application/ports/command-repository.port.js +1 -2
  19. package/dist/application/ports/command-repository.port.js.map +1 -1
  20. package/dist/application/ports/domain-event-publisher.port.d.ts +1 -1
  21. package/dist/application/ports/domain-event-publisher.port.d.ts.map +1 -1
  22. package/dist/application/ports/domain-event-publisher.port.js +1 -2
  23. package/dist/application/ports/domain-event-publisher.port.js.map +1 -1
  24. package/dist/application/ports/query-repository.port.d.ts +1 -1
  25. package/dist/application/ports/query-repository.port.d.ts.map +1 -1
  26. package/dist/application/ports/query-repository.port.js +1 -2
  27. package/dist/application/ports/query-repository.port.js.map +1 -1
  28. package/dist/application/ports/write-side-aggregate-repository.port.d.ts +1 -1
  29. package/dist/application/ports/write-side-aggregate-repository.port.d.ts.map +1 -1
  30. package/dist/application/ports/write-side-aggregate-repository.port.js +1 -2
  31. package/dist/application/ports/write-side-aggregate-repository.port.js.map +1 -1
  32. package/dist/application/query.options.js +1 -2
  33. package/dist/application/query.options.js.map +1 -1
  34. package/dist/application/request-fields.helper.js +2 -6
  35. package/dist/application/request-fields.helper.js.map +1 -1
  36. package/dist/application/tenant-resolver.js +5 -10
  37. package/dist/application/tenant-resolver.js.map +1 -1
  38. package/dist/domain/decorators/apply-mutation.decorator.d.ts +1 -1
  39. package/dist/domain/decorators/apply-mutation.decorator.d.ts.map +1 -1
  40. package/dist/domain/decorators/apply-mutation.decorator.js +1 -4
  41. package/dist/domain/decorators/apply-mutation.decorator.js.map +1 -1
  42. package/dist/domain/decorators/mutable.decorator.js +2 -6
  43. package/dist/domain/decorators/mutable.decorator.js.map +1 -1
  44. package/dist/domain/events/domain.event.d.ts +1 -1
  45. package/dist/domain/events/domain.event.d.ts.map +1 -1
  46. package/dist/domain/events/domain.event.js +3 -7
  47. package/dist/domain/events/domain.event.js.map +1 -1
  48. package/dist/domain/events/event.interface.js +1 -2
  49. package/dist/domain/events/event.interface.js.map +1 -1
  50. package/dist/domain/events/root-domain.event.d.ts +3 -3
  51. package/dist/domain/events/root-domain.event.d.ts.map +1 -1
  52. package/dist/domain/events/root-domain.event.js +3 -8
  53. package/dist/domain/events/root-domain.event.js.map +1 -1
  54. package/dist/domain/exceptions/concurrency-conflict.error.d.ts +1 -1
  55. package/dist/domain/exceptions/concurrency-conflict.error.d.ts.map +1 -1
  56. package/dist/domain/exceptions/concurrency-conflict.error.js +2 -6
  57. package/dist/domain/exceptions/concurrency-conflict.error.js.map +1 -1
  58. package/dist/domain/exceptions/domain.exception.js +1 -5
  59. package/dist/domain/exceptions/domain.exception.js.map +1 -1
  60. package/dist/domain/exceptions/entity-not-found.exception.d.ts +1 -1
  61. package/dist/domain/exceptions/entity-not-found.exception.d.ts.map +1 -1
  62. package/dist/domain/exceptions/entity-not-found.exception.js +2 -6
  63. package/dist/domain/exceptions/entity-not-found.exception.js.map +1 -1
  64. package/dist/domain/exceptions/invalid-value.exception.d.ts +2 -2
  65. package/dist/domain/exceptions/invalid-value.exception.d.ts.map +1 -1
  66. package/dist/domain/exceptions/invalid-value.exception.js +2 -6
  67. package/dist/domain/exceptions/invalid-value.exception.js.map +1 -1
  68. package/dist/domain/exceptions/missing-tenant-context.exception.d.ts +1 -1
  69. package/dist/domain/exceptions/missing-tenant-context.exception.d.ts.map +1 -1
  70. package/dist/domain/exceptions/missing-tenant-context.exception.js +2 -6
  71. package/dist/domain/exceptions/missing-tenant-context.exception.js.map +1 -1
  72. package/dist/domain/exceptions/transient-operation.error.js +2 -7
  73. package/dist/domain/exceptions/transient-operation.error.js.map +1 -1
  74. package/dist/domain/exceptions/unknown-mutable-field.error.js +1 -5
  75. package/dist/domain/exceptions/unknown-mutable-field.error.js.map +1 -1
  76. package/dist/domain/index.d.ts +19 -19
  77. package/dist/domain/index.d.ts.map +1 -1
  78. package/dist/domain/index.js +19 -35
  79. package/dist/domain/index.js.map +1 -1
  80. package/dist/domain/interfaces/aggregate-root.interface.d.ts +1 -1
  81. package/dist/domain/interfaces/aggregate-root.interface.d.ts.map +1 -1
  82. package/dist/domain/interfaces/aggregate-root.interface.js +1 -2
  83. package/dist/domain/interfaces/aggregate-root.interface.js.map +1 -1
  84. package/dist/domain/interfaces/root-entity-snapshot.interface.js +1 -2
  85. package/dist/domain/interfaces/root-entity-snapshot.interface.js.map +1 -1
  86. package/dist/domain/models/aggregate-root.d.ts +2 -2
  87. package/dist/domain/models/aggregate-root.d.ts.map +1 -1
  88. package/dist/domain/models/aggregate-root.js +1 -5
  89. package/dist/domain/models/aggregate-root.js.map +1 -1
  90. package/dist/domain/models/root.entity.d.ts +4 -4
  91. package/dist/domain/models/root.entity.d.ts.map +1 -1
  92. package/dist/domain/models/root.entity.js +10 -14
  93. package/dist/domain/models/root.entity.js.map +1 -1
  94. package/dist/domain/rules/number.rule.d.ts +1 -1
  95. package/dist/domain/rules/number.rule.d.ts.map +1 -1
  96. package/dist/domain/rules/number.rule.js +4 -7
  97. package/dist/domain/rules/number.rule.js.map +1 -1
  98. package/dist/domain/rules/rule-support.d.ts +1 -1
  99. package/dist/domain/rules/rule-support.d.ts.map +1 -1
  100. package/dist/domain/rules/rule-support.js +3 -7
  101. package/dist/domain/rules/rule-support.js.map +1 -1
  102. package/dist/domain/rules/text.rule.d.ts +1 -1
  103. package/dist/domain/rules/text.rule.d.ts.map +1 -1
  104. package/dist/domain/rules/text.rule.js +4 -7
  105. package/dist/domain/rules/text.rule.js.map +1 -1
  106. package/dist/domain/rules/value-violation.js +1 -2
  107. package/dist/domain/rules/value-violation.js.map +1 -1
  108. package/dist/http/domain-error-http-status.d.ts +1 -1
  109. package/dist/http/domain-error-http-status.d.ts.map +1 -1
  110. package/dist/http/domain-error-http-status.js +9 -12
  111. package/dist/http/domain-error-http-status.js.map +1 -1
  112. package/dist/http/index.d.ts +1 -1
  113. package/dist/http/index.d.ts.map +1 -1
  114. package/dist/http/index.js +1 -17
  115. package/dist/http/index.js.map +1 -1
  116. package/dist/index.d.ts +5 -5
  117. package/dist/index.d.ts.map +1 -1
  118. package/dist/index.js +5 -21
  119. package/dist/index.js.map +1 -1
  120. package/dist/persistence/cache/cache-logger.js +2 -6
  121. package/dist/persistence/cache/cache-logger.js.map +1 -1
  122. package/dist/persistence/cache/memory.cache.d.ts +1 -1
  123. package/dist/persistence/cache/memory.cache.d.ts.map +1 -1
  124. package/dist/persistence/cache/memory.cache.js +4 -8
  125. package/dist/persistence/cache/memory.cache.js.map +1 -1
  126. package/dist/persistence/command-repository.abstract.d.ts +3 -3
  127. package/dist/persistence/command-repository.abstract.d.ts.map +1 -1
  128. package/dist/persistence/command-repository.abstract.js +2 -6
  129. package/dist/persistence/command-repository.abstract.js.map +1 -1
  130. package/dist/persistence/decorators/acknowledge-persisted.decorator.js +1 -4
  131. package/dist/persistence/decorators/acknowledge-persisted.decorator.js.map +1 -1
  132. package/dist/persistence/decorators/cache.decorator.d.ts +1 -1
  133. package/dist/persistence/decorators/cache.decorator.d.ts.map +1 -1
  134. package/dist/persistence/decorators/cache.decorator.js +22 -26
  135. package/dist/persistence/decorators/cache.decorator.js.map +1 -1
  136. package/dist/persistence/decorators/from-cache.decorator.d.ts +3 -3
  137. package/dist/persistence/decorators/from-cache.decorator.d.ts.map +1 -1
  138. package/dist/persistence/decorators/from-cache.decorator.js +16 -20
  139. package/dist/persistence/decorators/from-cache.decorator.js.map +1 -1
  140. package/dist/persistence/decorators/map-persistence-errors.decorator.d.ts +2 -2
  141. package/dist/persistence/decorators/map-persistence-errors.decorator.d.ts.map +1 -1
  142. package/dist/persistence/decorators/map-persistence-errors.decorator.js +3 -6
  143. package/dist/persistence/decorators/map-persistence-errors.decorator.js.map +1 -1
  144. package/dist/persistence/decorators/persisted-write.decorator.d.ts +4 -4
  145. package/dist/persistence/decorators/persisted-write.decorator.d.ts.map +1 -1
  146. package/dist/persistence/decorators/persisted-write.decorator.js +7 -10
  147. package/dist/persistence/decorators/persisted-write.decorator.js.map +1 -1
  148. package/dist/persistence/helpers/cache-barrier.helper.js +4 -8
  149. package/dist/persistence/helpers/cache-barrier.helper.js.map +1 -1
  150. package/dist/persistence/helpers/cache-key.helper.d.ts +1 -1
  151. package/dist/persistence/helpers/cache-key.helper.d.ts.map +1 -1
  152. package/dist/persistence/helpers/cache-key.helper.js +11 -15
  153. package/dist/persistence/helpers/cache-key.helper.js.map +1 -1
  154. package/dist/persistence/helpers/cache-owner.helper.d.ts +1 -1
  155. package/dist/persistence/helpers/cache-owner.helper.d.ts.map +1 -1
  156. package/dist/persistence/helpers/cache-owner.helper.js +4 -7
  157. package/dist/persistence/helpers/cache-owner.helper.js.map +1 -1
  158. package/dist/persistence/helpers/cache-snapshot.helper.js +1 -4
  159. package/dist/persistence/helpers/cache-snapshot.helper.js.map +1 -1
  160. package/dist/persistence/helpers/cache-version.helper.js +5 -8
  161. package/dist/persistence/helpers/cache-version.helper.js.map +1 -1
  162. package/dist/persistence/index.d.ts +14 -14
  163. package/dist/persistence/index.d.ts.map +1 -1
  164. package/dist/persistence/index.js +14 -30
  165. package/dist/persistence/index.js.map +1 -1
  166. package/dist/persistence/persistence-dialect.js +2 -6
  167. package/dist/persistence/persistence-dialect.js.map +1 -1
  168. package/dist/persistence/query-repository.abstract.d.ts +4 -4
  169. package/dist/persistence/query-repository.abstract.d.ts.map +1 -1
  170. package/dist/persistence/query-repository.abstract.js +2 -6
  171. package/dist/persistence/query-repository.abstract.js.map +1 -1
  172. package/dist/types/Method.type.js +1 -2
  173. package/dist/types/Method.type.js.map +1 -1
  174. package/package.json +6 -4
package/README.md CHANGED
@@ -8,27 +8,7 @@ versioned mutations, detached domain events, a command handler that publishes th
8
8
  events, repository contracts, persistence lifecycle decorators, a revision-fenced
9
9
  repository cache, tenant-scoped cache keys and HTTP status mapping for its errors.
10
10
 
11
- It depends on no framework and no ORM. MikroORM adapters are in
12
- [`@cqrs-ddd/mikro-orm`](https://www.npmjs.com/package/@cqrs-ddd/mikro-orm). It works in a plain Node service, and in a NestJS
13
- application through structural compatibility: see [Using it from NestJS](#using-it-from-nestjs).
14
-
15
- ## Contents
16
-
17
- - [Installation](#installation)
18
- - [Entry points](#entry-points)
19
- - [Aggregates](#aggregates)
20
- - [Value rules](#value-rules)
21
- - [Domain events](#domain-events)
22
- - [Commands and event publication](#commands-and-event-publication)
23
- - [Write-side repositories](#write-side-repositories)
24
- - [Read-side repositories](#read-side-repositories)
25
- - [The repository cache](#the-repository-cache)
26
- - [Tenant-scoped cache keys](#tenant-scoped-cache-keys)
27
- - [HTTP status mapping](#http-status-mapping)
28
- - [Using it from NestJS](#using-it-from-nestjs)
29
- - [Moving from ddd/core](#moving-from-dddcore)
30
- - [Known limits](#known-limits)
31
- - [License](#license)
11
+ **Documentation:** [guide](https://aristoteliss.github.io/nestjs-pipeline/packages/cqrs-ddd/core/) · [API reference](https://aristoteliss.github.io/nestjs-pipeline/api/cqrs-ddd/core/) · [all packages](https://aristoteliss.github.io/nestjs-pipeline/)
32
12
 
33
13
  ## Installation
34
14
 
@@ -42,690 +22,7 @@ Requires Node.js 22.12 or later. It installs `@cqrs-ddd/uuidv7` and
42
22
  `@cqrs-ddd/safe-stringify`, which have no dependencies. To persist with MikroORM, add
43
23
  `@cqrs-ddd/mikro-orm` and `@mikro-orm/core` 7.
44
24
 
45
- ## Entry points
46
-
47
- Import from the entry point for the layer you are writing. Each one loads only what it
48
- needs.
49
-
50
- | Entry | Holds |
51
- | --- | --- |
52
- | `@cqrs-ddd/core/domain` | `AggregateRoot`, `IAggregateRoot`, `ApplyEventOptions`, `RootEntity`, `RootEntitySnapshot`, `@Mutable`, `getMutableFields`, `@ApplyMutation`, `IEvent`, `DomainEvent`, `RootDomainEvent`, `deepCloneAndFreeze`, `textRule`, `numberRule`, `ValueViolation`, and the errors `DomainException`, `InvalidValueException`, `EntityNotFoundException`, `ConcurrencyConflictError`, `TransientOperationError` (with `isTransientOperationError`), `MissingTenantContextError`, `UnknownMutableFieldError` |
53
- | `@cqrs-ddd/core/application` | `BaseCommand`, `BaseQuery`, `IQueryOptions`, `CommandBaseHandler`, the ports (`IDomainEventPublisher`, `ICommandRepository`, `IQueryRepository`, `IWriteSideAggregateRepository`, `ICache`, `IVersionedCache`, `isVersionedCache`), `requireTenant`, `setTenantResolver`, and the deprecated `requireTenantId` |
54
- | `@cqrs-ddd/core/persistence` | the lifecycle decorators (`@PersistedWrite`, `@Cache`, `@AcknowledgePersisted`, `@MapPersistenceErrors`, `@FromCache`), `QueryRepository`, `CommandRepository`, `MemoryCache` and its injection token `CACHE_TOKEN`, `cacheKey`, `cacheKeyTemplate`, `isCacheNewer`, `toCacheSnapshot`, the mutation-barrier helpers, `consoleCacheLogger`, `safeWarn`, and the persistence dialect contract (`IPersistenceDialect`, `setPersistenceDialect`, `persistenceDialect`) |
55
- | `@cqrs-ddd/core/http` | `domainErrorHttpStatus` |
56
- | `@cqrs-ddd/core` | all of the above, plus the `Method` type |
57
-
58
- No entry point loads an ORM or NestJS.
59
-
60
- ## Aggregates
61
-
62
- An aggregate extends `RootEntity<TSnapshot>`. It gets a UUIDv7 `id`, `createdAt` and
63
- `updatedAt`, an optimistic-concurrency `version`, and an event buffer. State changes go
64
- through domain methods decorated with `@ApplyMutation`, which write only the fields
65
- declared `@Mutable`:
66
-
67
- ```typescript
68
- import {
69
- ApplyMutation,
70
- DomainException,
71
- InvalidValueException,
72
- Mutable,
73
- RootEntity,
74
- type RootEntitySnapshot,
75
- textRule,
76
- } from '@cqrs-ddd/core/domain';
77
-
78
- export class InvalidUsernameException extends InvalidValueException {}
79
- export class InvalidDepartmentException extends InvalidValueException {}
80
- export class EmptyUserUpdateException extends DomainException {
81
- constructor() {
82
- super('A user update needs at least one field.');
83
- }
84
- }
85
-
86
- export interface UserSnapshot extends Partial<RootEntitySnapshot> {
87
- readonly username: string;
88
- readonly email: string;
89
- readonly department?: string | null;
90
- }
91
-
92
- export class User extends RootEntity<UserSnapshot> {
93
- static readonly aggregateName = 'user';
94
- static readonly rules = {
95
- username: textRule({
96
- field: 'username',
97
- minLength: 3,
98
- maxLength: 255,
99
- error: (violation) => new InvalidUsernameException(violation),
100
- }),
101
- department: textRule({
102
- field: 'department',
103
- required: false,
104
- maxLength: 255,
105
- error: (violation) => new InvalidDepartmentException(violation),
106
- }),
107
- } as const;
108
-
109
- @Mutable<string>({ normalize: (value) => User.rules.username.parse(value) })
110
- private _username: string;
111
-
112
- @Mutable<string | null>({ normalize: (value) => User.rules.department.parse(value) })
113
- private _department: string | null;
114
-
115
- readonly email: string;
116
-
117
- private constructor(snapshot: UserSnapshot) {
118
- super(snapshot);
119
- this._username = User.rules.username.parse(snapshot.username);
120
- this._department = User.rules.department.parse(snapshot.department);
121
- this.email = snapshot.email;
122
- }
123
-
124
- static create(username: string, email: string, department?: string | null): User {
125
- const user = new User({ username, email, department });
126
- user.apply(new UserCreatedEvent(user));
127
- return user;
128
- }
129
-
130
- static fromJSON(snapshot: UserSnapshot): User {
131
- return new User(snapshot);
132
- }
133
-
134
- get username(): string {
135
- return this._username;
136
- }
137
-
138
- private set username(value: string) {
139
- this._username = User.rules.username.parse(value);
140
- }
141
-
142
- get department(): string | null {
143
- return this._department;
144
- }
145
-
146
- private set department(value: string | null) {
147
- this._department = User.rules.department.parse(value);
148
- }
149
-
150
- @ApplyMutation<User>({ event: (user) => new UserUpdatedEvent(user) })
151
- update(fields: { username?: string; department?: string | null }): this {
152
- if (fields.username === undefined && fields.department === undefined) {
153
- throw new EmptyUserUpdateException();
154
- }
155
- this.applyPatch({ username: fields.username, department: fields.department });
156
- return this;
157
- }
158
-
159
- @ApplyMutation<User>({ event: (user) => new UserDeletedEvent(user) })
160
- delete(): this {
161
- return this;
162
- }
163
-
164
- toJSON(): UserSnapshot & RootEntitySnapshot {
165
- return this.freezeState({
166
- id: this.id,
167
- username: this._username,
168
- department: this._department,
169
- email: this.email,
170
- createdAt: this.createdAt,
171
- updatedAt: this.updatedAt,
172
- version: this.version,
173
- });
174
- }
175
- }
176
- ```
177
-
178
- The events are declared in [Domain events](#domain-events). Using the aggregate:
179
-
180
- ```typescript
181
- const user = User.create('alice', 'alice@example.test');
182
- user.version; // 1
183
- user.getUncommittedEvents(); // [UserCreatedEvent]
184
-
185
- user.update({ department: 'Research' });
186
- user.version; // 2
187
- user.getExpectedVersion(); // 1: the version the next write must find in storage
188
-
189
- user.update({}); // throws EmptyUserUpdateException; nothing is recorded
190
- user.update({ username: 'a' }); // throws InvalidUsernameException before any field is written
191
- ```
192
-
193
- - `@Mutable` registers a field for `applyPatch` under its property name without a
194
- leading underscore (`_username` is patched as `username`); `as: 'name'` sets another
195
- key, and `normalize` validates and converts each value.
196
-
197
- - `applyPatch(patch)` validates and normalizes every supplied field before writing any
198
- of them, and ignores `undefined` values. An unknown key throws `UnknownMutableFieldError`.
199
- - After a successful method, `@ApplyMutation` advances `version` and `updatedAt` and
200
- records the event. A method that throws records nothing.
201
- - Validate before patching: a failure after the fields are written (later method code,
202
- a lifecycle hook, event creation) does not roll them back. Discard or reload the
203
- instance.
204
- - `RootEntity.from(value)` rehydrates an instance, a snapshot or a nullish database
205
- result, and throws a `TypeError` for an incompatible aggregate.
206
- - `id`, `createdAt` and `updatedAt` have public getters and private setters. The ORM
207
- hydrates through the setters (see below); application code cannot assign them and
208
- changes state through domain methods and factories. Give a subclass's own persisted
209
- fields private setters too, as `username` and `department` above.
210
- - `version` is the in-memory version; `getExpectedVersion()` is the version last read
211
- from or written to storage, which a version-conditioned write compares against.
212
- `acknowledgePersisted()` moves it forward after a successful write; `@PersistedWrite`
213
- calls it for you.
214
-
215
- ## Value rules
216
-
217
- `textRule(options)` and `numberRule(options)` define the rule for one field once. The
218
- aggregate uses the rule's `parse(value)` to normalize the value, and other layers read
219
- the rule's limits, so a request schema cannot drift from the domain:
220
-
221
- ```typescript
222
- z.string().trim().min(User.rules.username.minLength).max(User.rules.username.maxLength);
223
- ```
224
-
225
- `parse(value)` returns the normalized value or throws the rule's error. It is a
226
- standalone function, and the rule is frozen.
227
-
228
- | `textRule` option | Effect |
229
- | --- | --- |
230
- | `field` | Name reported in the violation and in the default message |
231
- | `required` | `false` normalizes `null`, `undefined` and blank text to `null`; by default they are rejected |
232
- | `minLength`, `maxLength` | Length after normalization, in UTF-16 code units like Zod's `.min()` and `.max()` |
233
- | `pattern` | Regular expression the text must match; a `g` or `y` flag is rejected |
234
- | `multiline` | `true` accepts tab, line feed and carriage return inside the text |
235
- | `error` | Builds the error for a violation; defaults to `InvalidValueException` |
236
-
237
- Text is checked for type and unpaired surrogates, then put in Unicode NFC form and
238
- trimmed. Control characters are always rejected, and so are tabs and line breaks unless
239
- `multiline` is set.
240
-
241
- | `numberRule` option | Effect |
242
- | --- | --- |
243
- | `field`, `required`, `error` | As for `textRule` (`required: false` accepts `null` and `undefined`) |
244
- | `integer` | Accepts safe integers only |
245
- | `min`, `max` | Inclusive bounds |
246
-
247
- A number must be of type `number` and finite; a numeric string is rejected, not
248
- converted. An invalid option, such as `minLength` above `maxLength`, throws a
249
- `TypeError` when the rule is defined.
250
-
251
- A broken rule throws `error(violation)`. `violation` is a frozen `ValueViolation`:
252
- `{ field, rule }`, plus `limit` for a length or range rule and `expected` for a type
253
- rule. `InvalidValueException` carries it, builds the message (`username must be at
254
- least 3 characters.`), and does not keep the rejected value. Extend it for your own
255
- exceptions, as in the example above, so every one shares that shape.
256
-
257
- ## Domain events
258
-
259
- A domain event extends `RootDomainEvent<TEntity, TPayload>`. It carries a UUIDv7 `id`,
260
- the event-time `aggregateId` and `aggregateVersion`, and `payload`: a deep clone of the
261
- aggregate's `toJSON()`, recursively frozen.
262
-
263
- ```typescript
264
- import { RootDomainEvent } from '@cqrs-ddd/core/domain';
265
-
266
- export class UserCreatedEvent extends RootDomainEvent<User, UserSnapshot> {
267
- constructor(user: User) {
268
- super(user);
269
- }
270
- }
271
- ```
272
-
273
- `UserUpdatedEvent` and `UserDeletedEvent` are declared the same way.
274
-
275
- - **Detached:** later changes to the aggregate never reach `payload`.
276
- - **Read-only for ordinary access:** own properties are frozen, and the mutating methods
277
- of cloned `Date`, `Map` and `Set` values throw.
278
- - **Not a security boundary:** `Object.freeze` does not cover built-in internal state,
279
- so `Date.prototype.setTime.call(payload.at, 0)` still changes it, and every consumer
280
- of one event shares the same `payload`. `event.clonePayload()` returns a fresh frozen
281
- copy per call when a consumer needs its own.
282
- - **Not a transport format:** send an explicit, serializable message built from the
283
- fields you need.
284
-
285
- `deepCloneAndFreeze(value)` is the function behind `payload`, also usable on its own. It
286
- handles objects, arrays, `Date`, `Map`, `Set`, `RegExp` and circular references.
287
-
288
- ## Commands and event publication
289
-
290
- `BaseCommand` and `BaseQuery` are plain base classes for command and query objects.
291
- `BaseCommand` keeps an optional `sessionPrincipal` (or `sessionUser`) out of enumeration and `toJSON()`, so it
292
- never reaches a fingerprint or a log. `getUpdateFields(fields)` returns the listed
293
- fields the command carries (`null` counts, `undefined` does not), for field-level
294
- authorization.
295
-
296
- `CommandBaseHandler` runs a command and publishes the events of the aggregate it
297
- returns:
298
-
299
- ```typescript
300
- import {
301
- BaseCommand,
302
- CommandBaseHandler,
303
- type IDomainEventPublisher,
304
- type IWriteSideAggregateRepository,
305
- } from '@cqrs-ddd/core/application';
306
- import { EntityNotFoundException } from '@cqrs-ddd/core/domain';
307
-
308
- export class UpdateUserCommand extends BaseCommand {
309
- constructor(
310
- readonly id: string,
311
- readonly username?: string,
312
- readonly department?: string | null,
313
- ) {
314
- super();
315
- }
316
- }
317
-
318
- export class UpdateUserHandler extends CommandBaseHandler<UpdateUserCommand, User> {
319
- constructor(
320
- private readonly users: IWriteSideAggregateRepository<User>,
321
- eventBus: IDomainEventPublisher,
322
- ) {
323
- super(eventBus);
324
- }
325
-
326
- async handle(command: UpdateUserCommand): Promise<User> {
327
- const user = await this.users.findById(command.id);
328
- if (!user) throw new EntityNotFoundException('User', command.id);
329
- user.update({ username: command.username, department: command.department });
330
- await this.users.save(user);
331
- return user;
332
- }
333
- }
334
-
335
- const handler = new UpdateUserHandler(users, {
336
- publishAll: async (events) => events.forEach((event) => emitter.emit('event', event)),
337
- });
338
- await handler.execute(new UpdateUserCommand(id, 'bob'));
339
- ```
340
-
341
- - `handle()` returns the aggregate, or a result carrying it as `aggregate`; any
342
- `IAggregateRoot` qualifies. `execute()` calls it, publishes the buffered events once
343
- with `eventBus.publishAll(events, aggregate)` (the aggregate is the dispatcher context),
344
- clears the buffer and returns the result unchanged.
345
- - A rejected `handle()` publishes nothing. If `publishAll()` throws, the error
346
- propagates and the events stay buffered.
347
- - If `publishAll()` returns a promise, `execute()` waits for it after clearing the buffer.
348
- Its rejection rejects the command, although the aggregate is already persisted; the
349
- events are not published a second time.
350
- - Any object with `publishAll(events)` is an `IDomainEventPublisher`.
351
-
352
- **`AggregateRoot.commit()` publishes nothing by default.** It hands a copy of the
353
- buffer to the aggregate's own `publishAll` hook (`apply()` calls `publish` while
354
- `autoCommit` is on), which does nothing until a publisher is connected, then clears the
355
- buffer. Calling `commit()` without a connected publisher therefore drops the events; so
356
- does `autoCommit`. Let `CommandBaseHandler` publish, or read `getUncommittedEvents()` and
357
- call `uncommit()` yourself.
358
-
359
- `commit(dispatcherContext?)` passes the context, such as `{ transaction }`, to
360
- `publishAll` and returns what it returns. The buffer is cleared once `publishAll`
361
- returns, before an asynchronous publisher settles, so `await aggregate.commit()` waits
362
- for the publisher and receives its error without risking a second publication; if
363
- `publishAll` throws, the events stay buffered.
364
-
365
- ## Write-side repositories
366
-
367
- A command handler loads the authoritative aggregate through
368
- `IWriteSideAggregateRepository<TEntity>.findById(id)`: it must read primary storage, never
369
- a cache. `@cqrs-ddd/mikro-orm`'s `AggregateRepository` implements it for MikroORM.
370
-
371
- `save()` declares its lifecycle with `@PersistedWrite`. With `@cqrs-ddd/mikro-orm`, where
372
- `AggregateRepository` provides `findById()` and `this.store`:
373
-
374
- ```typescript
375
- import type { ICache } from '@cqrs-ddd/core/application';
376
- import { DomainException } from '@cqrs-ddd/core/domain';
377
- import { cacheKey, PersistedWrite } from '@cqrs-ddd/core/persistence';
378
- import {
379
- AggregateRepository,
380
- type IEntityManagerSource,
381
- mapPersistenceError,
382
- optimisticUpdate,
383
- } from '@cqrs-ddd/mikro-orm';
384
-
385
- export class UniqueEmailException extends DomainException {
386
- constructor(readonly user: User) {
387
- super('This email is already registered.');
388
- }
389
- }
390
-
391
- export class UpdateUserRepository extends AggregateRepository<UserSnapshot, User, UserSnapshot> {
392
- constructor(cache: ICache<UserSnapshot>, store: IEntityManagerSource) {
393
- super(cache, store, User, User.aggregateName, User.fromJSON);
394
- }
395
-
396
- @PersistedWrite<User>({
397
- cache: {
398
- setKey: (user) => cacheKey(User.aggregateName, { id: user.id }),
399
- invalidateKeys: (user) => [cacheKey(User.aggregateName, { email: user.email })],
400
- },
401
- unique: { email: (user) => new UniqueEmailException(user) },
402
- otherwise: (error, user) => mapPersistenceError(error, `updating User ${user.id}`),
403
- })
404
- async save(user: User): Promise<UserSnapshot> {
405
- const snapshot = user.toJSON();
406
- await optimisticUpdate(
407
- this.store.em,
408
- User,
409
- user,
410
- {
411
- username: snapshot.username,
412
- department: snapshot.department ?? null,
413
- updatedAt: snapshot.updatedAt,
414
- },
415
- 'User',
416
- );
417
- return snapshot;
418
- }
419
- }
420
- ```
421
-
422
- `optimisticUpdate` adds `version` to the written fields; every other changed column,
423
- `updatedAt` included, is listed explicitly.
424
-
425
- `@PersistedWrite` applies three decorators. Stacked by hand, the order is fixed,
426
- outermost first:
427
-
428
- 1. `@Cache(options)`: after a successful write, writes the returned snapshot through
429
- with a compare-and-set (`isCacheNewer` unless `isNewer` says otherwise), and
430
- installs barriers for `invalidateKeys`.
431
- When `save()` resolves `null` or `undefined`, it installs barriers for `deleteKeys`.
432
- Cache errors are logged and never turn a committed write into a failure.
433
- 2. `@AcknowledgePersisted({ entity: ([aggregate]) => aggregate })`: advances the
434
- selected aggregate's persisted version only after the write succeeded.
435
- 3. `@MapPersistenceErrors({ entity, unique, dialect, otherwise })`: translates a unique
436
- violation into your domain error. `unique` is keyed by the entity property the
437
- constraint covers (`{ email: ... }`), or by the declared name of a multi-column
438
- constraint (`MapPersistenceErrors<Args, Entity, typeof NAME>`), so a repository never
439
- names a database constraint or column. Which constraint an error violated is read by
440
- the persistence dialect: `options.dialect`, else the one registered with
441
- `setPersistenceDialect()` at the composition root. Core knows no database; an adapter
442
- such as `MikroOrmDialect` of `@cqrs-ddd/mikro-orm` implements `IPersistenceDialect`.
443
- A method that declares `unique` with no dialect available throws a `TypeError` before
444
- it runs. `otherwise` translates the rest, for example with `mapPersistenceError` of
445
- `@cqrs-ddd/mikro-orm`, which turns retryable driver and network failures into
446
- `TransientOperationError` and keeps every other error unchanged.
447
-
448
- Deletes do not acknowledge, so they stack `@Cache` and `@MapPersistenceErrors` alone,
449
- and resolve `null` so `@Cache` installs barriers for `deleteKeys`:
450
-
451
- ```typescript
452
- import { Cache, cacheKey, MapPersistenceErrors } from '@cqrs-ddd/core/persistence';
453
- import { mapPersistenceError, optimisticDelete } from '@cqrs-ddd/mikro-orm';
454
-
455
- export class DeleteUserRepository extends AggregateRepository<UserSnapshot, User, null> {
456
- constructor(cache: ICache<UserSnapshot>, store: IEntityManagerSource) {
457
- super(cache, store, User, User.aggregateName, User.fromJSON);
458
- }
459
-
460
- @Cache<User, null>({
461
- deleteKeys: (user) => [
462
- cacheKey(User.aggregateName, { id: user.id }),
463
- cacheKey(User.aggregateName, { email: user.email }),
464
- ],
465
- })
466
- @MapPersistenceErrors<[User], User>({
467
- entity: ([user]) => user,
468
- otherwise: (error, user) => mapPersistenceError(error, `deleting User ${user.id}`),
469
- })
470
- async save(user: User): Promise<null> {
471
- await optimisticDelete(this.store.em, User, user, 'User');
472
- return null;
473
- }
474
- }
475
- ```
476
-
477
- The write itself must be version-conditioned (`WHERE id = ? AND version = expected`) and
478
- must not run inside an outer transaction, whose success would not mean durable
479
- persistence. `@cqrs-ddd/mikro-orm` provides `optimisticUpdate` and `optimisticDelete`
480
- for this.
481
-
482
- ## Read-side repositories
483
-
484
- A query repository extends `QueryRepository` and decorates `find()` with `@FromCache`. The
485
- constructor takes the cache (any `ICache`; see [The repository cache](#the-repository-cache)
486
- for why `@FromCache` needs an `IVersionedCache`) and the repository's default hydration:
487
-
488
- ```typescript
489
- import { BaseQuery, type ICache, type IQueryOptions } from '@cqrs-ddd/core/application';
490
- import { cacheKey, FromCache, QueryRepository } from '@cqrs-ddd/core/persistence';
491
- import type { IEntityManagerSource } from '@cqrs-ddd/mikro-orm';
492
-
493
- export class GetUserQuery extends BaseQuery {
494
- constructor(
495
- readonly id: string,
496
- options?: IQueryOptions,
497
- ) {
498
- super(options);
499
- }
500
- }
501
-
502
- export class GetUserRepository extends QueryRepository<GetUserQuery, User | null> {
503
- constructor(
504
- cache: ICache<UserSnapshot>,
505
- private readonly store: IEntityManagerSource,
506
- ) {
507
- super(cache, { hydrateFn: (cached) => User.fromJSON(cached as UserSnapshot) });
508
- }
509
-
510
- @FromCache<GetUserQuery, User | null>({
511
- keyFn: (query) => cacheKey(User.aggregateName, { id: query.id }),
512
- })
513
- async find(query: GetUserQuery): Promise<User | null> {
514
- return this.store.em.findOne(User, { id: query.id }, query.refresh ? { refresh: true } : undefined);
515
- }
516
- }
517
-
518
- await users.find(new GetUserQuery(id)); // may be served from the cache
519
- await users.find(new GetUserQuery(id, { refresh: true })); // always reads the database
520
- ```
521
-
522
- `@FromCache` options: `keyFn` (return `null` to skip the cache for that call),
523
- `hydrateFn`, `serializeFn`, `ttl` in milliseconds, `isNewer` and `logger`.
524
-
525
- - Every hit is rehydrated whenever a hydrator applies, so a hit and a miss return the
526
- same type. A method's own `hydrateFn` (or `hydrateFn: null`) overrides the
527
- repository's; `serializeFn` follows the same rule.
528
- - Without a hydrator, only plain data is cached; a class instance is returned uncached.
529
- - Only non-nullish results are stored. A barrier or a stored `null` counts as a miss.
530
- - A query with `refresh: true` bypasses the cache.
531
- - Cache errors propagate from reads: a query fails rather than guessing.
532
-
533
- ## The repository cache
534
-
535
- `@Cache` works with any `ICache` (`get`, `set`, `delete`). `@FromCache` requires an
536
- `IVersionedCache`, which adds a revision fence:
537
-
538
- | Method | Contract |
539
- | --- | --- |
540
- | `readState(key)` | the entry's status (`hit`, `miss`, `expired`), value and opaque revision |
541
- | `invalidate(key)` | evicts the value and advances the revision |
542
- | `tryFill(key, observedRevision, value, options?)` | writes only if the revision is still `observedRevision`; `false` otherwise |
543
-
544
- `@FromCache` observes the revision before the database read and fills with `tryFill`, so
545
- a read that raced an invalidation or a delete cannot write a stale snapshot back. A
546
- rejected fill re-reads the key, returns a strictly newer snapshot if one is there, and
547
- otherwise retries a bounded number of times before returning the database result
548
- uncached. **An adapter that implements only `ICache` is bypassed by `@FromCache` for
549
- both reads and fills**, with a warning logged once: it cannot fence a fill.
550
-
551
- Two adapters implement `IVersionedCache`:
552
-
553
- - `MemoryCache({ defaultTtlMs = 60_000, maxEntries = 10_000 })`: in process, entries
554
- JSON-cloned on write and read, for tests and a single process.
555
- - `MikroOrmCache`, in `@cqrs-ddd/mikro-orm`: one database row per key, every write a
556
- compare-and-set in its own transaction.
557
-
558
- `CacheSetOptions.isNewer(cached, incoming)` returns `true` when the cached value is
559
- newer and must not be overwritten; `isCacheNewer` compares `version`, then `__gen`, then
560
- `updatedAt`. `toCacheSnapshot` turns a result into a detached snapshot: the cache never
561
- stores a live aggregate.
562
-
563
- Mutation barriers (`CacheMutationBarrier`) mark a deleted or invalidated key for
564
- `barrierTtl`, 60 seconds by default. Size it above your longest in-flight read.
565
-
566
- **The `logger` option.** `@Cache` and `@FromCache` accept `logger: { warn(message) }`
567
- for their operational warnings, such as a failed cache write, a bypassed adapter or a
568
- miswired repository. A NestJS `Logger` or `console` fits. Without one, warnings go to
569
- `console.warn`. A logger that throws never changes a result. An adapter reports its own
570
- warnings the same way through `consoleCacheLogger(context)` and `safeWarn(logger, message)`.
571
-
572
- ## Tenant-scoped cache keys
573
-
574
- `cacheKey(resource, conditions, tenant?)` and `cacheKeyTemplate(template, tenant?)`
575
- namespace every key by tenant. The tenant comes from, in order:
576
-
577
- 1. the explicit `tenant` argument: a tenant id string, or an object carrying `tenantId`,
578
- such as a request context;
579
- 2. for `cacheKeyTemplate`, a context source's `tenantId`;
580
- 3. the resolver the application registers once at startup with `setTenantResolver(fn)`,
581
- a function that returns the tenant of the running request or job;
582
- 4. otherwise, `MissingTenantContextError`.
583
-
584
- ```typescript
585
- import { AsyncLocalStorage } from 'node:async_hooks';
586
- import { setTenantResolver } from '@cqrs-ddd/core/application';
587
-
588
- const requestTenant = new AsyncLocalStorage<string>();
589
- setTenantResolver(() => requestTenant.getStore());
590
-
591
- // Per request or job:
592
- requestTenant.run(tenantId, () => handle(request));
593
- ```
594
-
595
- There is no shared namespace: a missing or empty tenant, or a resolver that returns
596
- nothing, throws. A single-tenant deployment passes a fixed id or registers
597
- `setTenantResolver(() => 'single')`. The same resolution is public as
598
- `requireTenant(purpose, source?)`, for any other key that must be partitioned by
599
- tenant, such as an idempotency or rate-limit key, and for any code that needs the
600
- current tenant and must fail when there is none:
601
-
602
- ```typescript
603
- import { requireTenant } from '@cqrs-ddd/core/application';
604
-
605
- requireTenant('access token issuance'); // the resolver's tenant
606
- requireTenant('users.create idempotency key', ctx); // ctx.tenantId, else the resolver's
607
- ```
608
-
609
- `requireTenantId(source, purpose)` is deprecated: it takes the same arguments in the
610
- reverse order and calls `requireTenant`.
611
-
612
- `cacheKey` keys have the form `${tenant}:${resource}:v1:${sha256}`, hashed over a
613
- key-sorted serialization of `[tenant, resource, conditions]`. The format is frozen, so
614
- stored entries stay addressable across releases.
615
-
616
- ## HTTP status mapping
617
-
618
- `domainErrorHttpStatus(error)` from `/http` maps this package's errors to plain
619
- `{ statusCode, error, message }` values, for any HTTP framework:
620
-
621
- | Error | Status |
622
- | --- | --- |
623
- | `ConcurrencyConflictError` | 409 |
624
- | `EntityNotFoundException` | 404 |
625
- | `MissingTenantContextError` | 500, with a generic message: a request without a tenant is a server fault |
626
- | any other `DomainException`, `InvalidValueException` included | 400 |
627
-
628
- It returns `undefined` for anything else. Map your own exceptions first, then pass the
629
- rest to it.
630
-
631
- ## Using it from NestJS
632
-
633
- Nothing in this package imports NestJS; the fit is structural.
634
-
635
- - The NestJS CQRS `EventBus` has `publishAll(events, dispatcherContext)`, so it is an
636
- `IDomainEventPublisher`: a handler passes its injected bus to `super(eventBus)`, and
637
- the bus hands the aggregate to its configured publisher as the dispatcher context.
638
- - `AggregateRoot` satisfies NestJS's `IAggregateRoot`, and a NestJS `AggregateRoot`
639
- satisfies this package's `IAggregateRoot`. `EventPublisher.mergeObjectContext(aggregate)`
640
- connects an aggregate to the `EventBus`: `commit()` then publishes with the aggregate as
641
- the context, `commit({ transaction })` with that context, and both return the bus's
642
- result.
643
- - `CommandBaseHandler.execute(command)` is the method the NestJS command bus calls, so a
644
- class decorated with `@CommandHandler` extends it directly.
645
- - `BaseCommand`, `BaseQuery` and the domain events are plain classes that NestJS
646
- dispatches like any other.
647
-
648
- ```typescript
649
- @CommandHandler(UpdateUserCommand)
650
- export class UpdateUserHandler extends CommandBaseHandler<UpdateUserCommand, User> {
651
- constructor(
652
- @Inject(USER_WRITE_REPOSITORY) private readonly users: IWriteSideAggregateRepository<User>,
653
- eventBus: EventBus,
654
- ) {
655
- super(eventBus);
656
- }
657
- // handle() as above
658
- }
659
- ```
660
-
661
- The application writes the rest of the glue:
662
-
663
- - providers for the repositories and the cache, for example a `useFactory` provider
664
- that builds a `MikroOrmCache` from `@cqrs-ddd/mikro-orm` under `CACHE_TOKEN`:
665
-
666
- ```typescript
667
- { provide: CACHE_TOKEN, useValue: new MemoryCache({ defaultTtlMs: 30_000 }) }
668
- ```
669
-
670
- - the tenant resolver, registered once before any lifecycle hook can start work that
671
- reads it, for example in a module constructor;
672
- - an exception filter that maps its own errors, then calls `domainErrorHttpStatus`;
673
- - a `logger` for the cache decorators, such as `new Logger('UserCache')`.
674
-
675
- ## Moving from ddd/core
676
-
677
- The unpublished workspace package `@nestjs-pipeline/ddd-core` (directory `ddd/core`) maps
678
- onto this package as follows. It depended on NestJS and MikroORM; this package depends on
679
- neither, and the MikroORM parts are in `@cqrs-ddd/mikro-orm`.
680
-
681
- | `ddd/core` | `@cqrs-ddd/core` |
682
- | --- | --- |
683
- | `import { … } from '@nestjs-pipeline/ddd-core'` | the layer entry points: `@cqrs-ddd/core/domain`, `/application`, `/persistence`, `/http` |
684
- | `@Mutate()` on a mutation method, which called `onUpdate()` | `@ApplyMutation({ event })`, which also records the event, plus `@Mutable` fields written through `applyPatch()` |
685
- | `DomainOutcome`, `RootDomainOutcome` returned by `handle()` | `handle()` returns the aggregate, or a result with an `aggregate` property; its buffered events are published |
686
- | `CommandBaseHandler(eventBus: EventBus)` from `@nestjs/cqrs` | `CommandBaseHandler(eventBus: IDomainEventPublisher)`; a NestJS `EventBus` still fits |
687
- | `CacheableEntity`, `ICacheKey`, `entity.cacheKey` (`prefix + id`) | `RootEntity` with a static `aggregateName`, keys built with `cacheKey(User.aggregateName, { id })`, always tenant-scoped |
688
- | `CacheableEntity.fromStringify(data, fromJSON)` | `RootEntity.from(value)` or the aggregate's own `fromJSON` |
689
- | `ICommandRepository.save(domainOutcome)` | `ICommandRepository.save(entity)`, and `IWriteSideAggregateRepository.findById(id)` for loading |
690
- | `@Cache(setKeyFn, deleteKeysFn)` | `@Cache({ setKey, deleteKeys, invalidateKeys, ttl, isNewer, barrierTtl, logger })`, usually through `@PersistedWrite` |
691
- | `@FromCache(keyFn, hydrateFn)`, hydrating when `query.hydrate` is set | `@FromCache({ keyFn, hydrateFn, … })` with an `IVersionedCache`; hits are always rehydrated when a hydrator applies |
692
- | `QueryRepository(cache)` | `QueryRepository(cache, { hydrateFn, serializeFn? })` |
693
- | `ICache` in `persistence/cache.interface` | `ICache` and `IVersionedCache` in `@cqrs-ddd/core/application` |
694
- | `UnixTimestampType` | `UnixTimestampType` in `@cqrs-ddd/mikro-orm` |
695
- | `RootEntity` with an abstract `afterUpdate()` | `afterUpdate()` is an optional hook; `RootEntity` extends `AggregateRoot` and adds `version`, `getExpectedVersion()`, the event buffer and private hydration setters |
696
-
697
- The old imports and the new ones side by side:
698
-
699
- ```typescript
700
- // ddd/core
701
- import { CacheableEntity, CommandBaseHandler, Mutate, RootDomainOutcome } from '@nestjs-pipeline/ddd-core';
702
-
703
- // @cqrs-ddd/core
704
- import { ApplyMutation, Mutable, RootEntity } from '@cqrs-ddd/core/domain';
705
- import { CommandBaseHandler } from '@cqrs-ddd/core/application';
706
- import { cacheKey, PersistedWrite } from '@cqrs-ddd/core/persistence';
707
- import { AggregateRepository, optimisticUpdate, UnixTimestampType } from '@cqrs-ddd/mikro-orm';
708
- ```
709
-
710
- ## Known limits
711
-
712
- - Persistence and event publication are not atomic. A crash between the write and
713
- `publishAll()` loses the events; durable delivery needs an outbox.
714
- - Cache maintenance after a commit is best-effort. If an invalidation fails, the
715
- previous entry stays until it expires: the revision fence coordinates the cache with
716
- itself, not with the database. Read with `{ refresh: true }` where a decision must
717
- not rest on a cached value.
718
- - A mutation barrier protects only for `barrierTtl`. It is a bounded race window, not a
719
- tombstone.
720
- - The persistence helpers reject outer transactions; decorators cannot make several
721
- writes atomic. A row that must commit with the aggregate, such as an audit record or
722
- an outbox message, therefore cannot share its transaction yet: that needs commit
723
- hooks that run acknowledgment and cache work after the commit.
724
- - `@MapPersistenceErrors` maps a unique violation only as well as the registered
725
- persistence dialect reads it; `MikroOrmDialect` reads PostgreSQL and SQLite errors.
726
- - The tenant resolver is process-wide: one per process, for each installed copy of this
727
- package.
728
- - Event payloads are frozen for ordinary access only; see [Domain events](#domain-events).
25
+ Published as an ES module; a CommonJS application loads it with `require()`. Coming from 0.3.x, see [Upgrading from 0.3.x](https://aristoteliss.github.io/nestjs-pipeline/upgrading/from-0-3/).
729
26
 
730
27
  ## License
731
28