@ddd-ts-kit/kernel 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.fr.md +13 -17
- package/README.md +11 -15
- package/dist/domain/domain-event.d.ts +1 -0
- package/dist/domain/domain-event.d.ts.map +1 -1
- package/dist/domain/domain-event.js +1 -1
- package/dist/domain/domain-event.js.map +1 -1
- package/dist/domain/named-domain-event.d.ts +12 -0
- package/dist/domain/named-domain-event.d.ts.map +1 -0
- package/dist/domain/named-domain-event.js +14 -0
- package/dist/domain/named-domain-event.js.map +1 -0
- package/package.json +1 -1
package/README.fr.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[English](README.md) · **Français**
|
|
2
|
-
<!-- translation-of: README.md sha256:
|
|
2
|
+
<!-- translation-of: README.md sha256:6ee16358ceb29b58 -->
|
|
3
3
|
|
|
4
4
|
# @ddd-ts-kit/kernel
|
|
5
5
|
|
|
@@ -60,7 +60,7 @@ chacun son propre fichier, et `ddd-ts-kit generate` les écrit) :
|
|
|
60
60
|
|
|
61
61
|
<!-- checked sample -->
|
|
62
62
|
```ts
|
|
63
|
-
import { AggregateRoot, ConceptError, Entity, ValueObject,
|
|
63
|
+
import { AggregateRoot, ConceptError, Entity, ValueObject, NamedDomainEvent } from '@ddd-ts-kit/kernel';
|
|
64
64
|
|
|
65
65
|
// Les refus du concept, chacun une fabrique statique (voir « Erreurs du domaine »).
|
|
66
66
|
export class OrderError extends ConceptError {
|
|
@@ -107,16 +107,14 @@ export class OrderLine extends Entity {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// Un événement du domaine : un fait passé, nommé <contexte>.<agrégat>.<fait>.
|
|
110
|
-
export class OrderPlaced
|
|
111
|
-
static readonly eventName = 'ordering.order.placed';
|
|
112
|
-
|
|
113
|
-
readonly name = OrderPlaced.eventName;
|
|
114
|
-
|
|
110
|
+
export class OrderPlaced extends NamedDomainEvent('ordering.order.placed') {
|
|
115
111
|
constructor(
|
|
116
112
|
readonly aggregateId: string,
|
|
117
113
|
readonly occurredAt: Date,
|
|
118
114
|
readonly lineCount: number,
|
|
119
|
-
) {
|
|
115
|
+
) {
|
|
116
|
+
super();
|
|
117
|
+
}
|
|
120
118
|
}
|
|
121
119
|
|
|
122
120
|
// La racine d'agrégat : la seule entrée, chaque règle vérifiée par une méthode d'intention.
|
|
@@ -433,7 +431,7 @@ en place :
|
|
|
433
431
|
|
|
434
432
|
<!-- checked sample -->
|
|
435
433
|
```ts
|
|
436
|
-
import {
|
|
434
|
+
import { NamedDomainEvent,
|
|
437
435
|
AggregateRoot,
|
|
438
436
|
InMemoryDomainEventDispatcher,
|
|
439
437
|
InMemoryUnitOfWork,
|
|
@@ -441,15 +439,13 @@ import {
|
|
|
441
439
|
type DomainEvent,
|
|
442
440
|
} from '@ddd-ts-kit/kernel';
|
|
443
441
|
|
|
444
|
-
class CartOpened
|
|
445
|
-
static readonly eventName = 'shop.cart.opened';
|
|
446
|
-
|
|
447
|
-
readonly name = CartOpened.eventName;
|
|
448
|
-
|
|
442
|
+
class CartOpened extends NamedDomainEvent('shop.cart.opened') {
|
|
449
443
|
constructor(
|
|
450
444
|
readonly aggregateId: string,
|
|
451
445
|
readonly occurredAt: Date,
|
|
452
|
-
) {
|
|
446
|
+
) {
|
|
447
|
+
super();
|
|
448
|
+
}
|
|
453
449
|
}
|
|
454
450
|
|
|
455
451
|
class Cart extends AggregateRoot {
|
|
@@ -894,8 +890,8 @@ port et n'est pas vérifiée.
|
|
|
894
890
|
`implements IntegrationEventHandler<OrderPlacedPayload>`. Un *job* implémente `ScheduledJob`.
|
|
895
891
|
- **Les noms sont écrits, pas déduits** : le nom du consommateur, celui de la politique, celui du
|
|
896
892
|
*job* et celui de l'événement du domaine survivent au renommage d'une classe, et la chaîne
|
|
897
|
-
vide est refusée. Le nom d'un événement du domaine s'écrit une fois
|
|
898
|
-
`static readonly eventName`
|
|
893
|
+
vide est refusée. Le nom d'un événement du domaine s'écrit une fois sur
|
|
894
|
+
sa classe, `extends NamedDomainEvent('..')` ou `static readonly eventName` : ses gestionnaires et ses projections l'y lisent
|
|
899
895
|
(`NamedDomainEventType`), et une classe qui ne le déclare pas est refusée par le compilateur.
|
|
900
896
|
- **Une classe déclarée est son propre jeton** : `@ddd-ts-kit/di` lie un gestionnaire, un *job*
|
|
901
897
|
ou une politique sous sa classe.
|
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ file, and `ddd-ts-kit generate` writes them):
|
|
|
57
57
|
|
|
58
58
|
<!-- checked sample -->
|
|
59
59
|
```ts
|
|
60
|
-
import { AggregateRoot, ConceptError, Entity, ValueObject,
|
|
60
|
+
import { AggregateRoot, ConceptError, Entity, ValueObject, NamedDomainEvent } from '@ddd-ts-kit/kernel';
|
|
61
61
|
|
|
62
62
|
// The refusals of the concept, each a static factory (see "Domain errors").
|
|
63
63
|
export class OrderError extends ConceptError {
|
|
@@ -104,16 +104,14 @@ export class OrderLine extends Entity {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// A domain event: a fact of the past, named <context>.<aggregate>.<fact>.
|
|
107
|
-
export class OrderPlaced
|
|
108
|
-
static readonly eventName = 'ordering.order.placed';
|
|
109
|
-
|
|
110
|
-
readonly name = OrderPlaced.eventName;
|
|
111
|
-
|
|
107
|
+
export class OrderPlaced extends NamedDomainEvent('ordering.order.placed') {
|
|
112
108
|
constructor(
|
|
113
109
|
readonly aggregateId: string,
|
|
114
110
|
readonly occurredAt: Date,
|
|
115
111
|
readonly lineCount: number,
|
|
116
|
-
) {
|
|
112
|
+
) {
|
|
113
|
+
super();
|
|
114
|
+
}
|
|
117
115
|
}
|
|
118
116
|
|
|
119
117
|
// The aggregate root: the only way in, every rule checked by an intention method.
|
|
@@ -424,7 +422,7 @@ The whole timeline, with the doubles of the kernel and nothing else, as a spec w
|
|
|
424
422
|
|
|
425
423
|
<!-- checked sample -->
|
|
426
424
|
```ts
|
|
427
|
-
import {
|
|
425
|
+
import { NamedDomainEvent,
|
|
428
426
|
AggregateRoot,
|
|
429
427
|
InMemoryDomainEventDispatcher,
|
|
430
428
|
InMemoryUnitOfWork,
|
|
@@ -432,15 +430,13 @@ import {
|
|
|
432
430
|
type DomainEvent,
|
|
433
431
|
} from '@ddd-ts-kit/kernel';
|
|
434
432
|
|
|
435
|
-
class CartOpened
|
|
436
|
-
static readonly eventName = 'shop.cart.opened';
|
|
437
|
-
|
|
438
|
-
readonly name = CartOpened.eventName;
|
|
439
|
-
|
|
433
|
+
class CartOpened extends NamedDomainEvent('shop.cart.opened') {
|
|
440
434
|
constructor(
|
|
441
435
|
readonly aggregateId: string,
|
|
442
436
|
readonly occurredAt: Date,
|
|
443
|
-
) {
|
|
437
|
+
) {
|
|
438
|
+
super();
|
|
439
|
+
}
|
|
444
440
|
}
|
|
445
441
|
|
|
446
442
|
class Cart extends AggregateRoot {
|
|
@@ -866,7 +862,7 @@ left alone.
|
|
|
866
862
|
`implements IntegrationEventHandler<OrderPlacedPayload>`. A job implements `ScheduledJob`.
|
|
867
863
|
- **Names are written, not derived**: the consumer name, the policy name, the job name and the
|
|
868
864
|
name of the domain event survive the renaming of a class, and the empty string is refused.
|
|
869
|
-
The name of a domain event is written once,
|
|
865
|
+
The name of a domain event is written once on its class, `extends NamedDomainEvent('..')` or `static readonly eventName`: its
|
|
870
866
|
handlers and projections read it there (`NamedDomainEventType`), and a class without it is
|
|
871
867
|
refused by the compiler.
|
|
872
868
|
- **A declared class is its own token**: `@ddd-ts-kit/di` binds a handler, a job or a policy
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain-event.d.ts","sourceRoot":"","sources":["../../src/domain/domain-event.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B"}
|
|
1
|
+
{"version":3,"file":"domain-event.d.ts","sourceRoot":"","sources":["../../src/domain/domain-event.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { NamedDomainEvent } from './named-domain-event.js';
|
|
2
2
|
//# sourceMappingURL=domain-event.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain-event.js","sourceRoot":"","sources":["../../src/domain/domain-event.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"domain-event.js","sourceRoot":"","sources":["../../src/domain/domain-event.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class of a domain event, which gives it its name once:
|
|
3
|
+
* `class InvoiceIssued extends NamedDomainEvent('billing.invoice.issued')`. The class carries it as
|
|
4
|
+
* `InvoiceIssued.eventName`, what handlers and projections are attached under, and every event as
|
|
5
|
+
* `name`, both typed with the literal. The event itself brings its `aggregateId` and `occurredAt`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function NamedDomainEvent<const Name extends string>(eventName: Name): (abstract new () => {
|
|
8
|
+
readonly name: Name;
|
|
9
|
+
}) & {
|
|
10
|
+
readonly eventName: Name;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=named-domain-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named-domain-event.d.ts","sourceRoot":"","sources":["../../src/domain/named-domain-event.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,SAAS,EAAE,IAAI;mBAIxD,IAAI;;wBAFQ,IAAI;EAMlC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class of a domain event, which gives it its name once:
|
|
3
|
+
* `class InvoiceIssued extends NamedDomainEvent('billing.invoice.issued')`. The class carries it as
|
|
4
|
+
* `InvoiceIssued.eventName`, what handlers and projections are attached under, and every event as
|
|
5
|
+
* `name`, both typed with the literal. The event itself brings its `aggregateId` and `occurredAt`.
|
|
6
|
+
*/
|
|
7
|
+
export function NamedDomainEvent(eventName) {
|
|
8
|
+
class Named {
|
|
9
|
+
static eventName = eventName;
|
|
10
|
+
name = eventName;
|
|
11
|
+
}
|
|
12
|
+
return Named;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=named-domain-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named-domain-event.js","sourceRoot":"","sources":["../../src/domain/named-domain-event.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAA4B,SAAe;IACzE,MAAe,KAAK;QAClB,MAAM,CAAU,SAAS,GAAS,SAAS,CAAC;QAEnC,IAAI,GAAS,SAAS,CAAC;KACjC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Framework-agnostic Domain-Driven Design (DDD) building blocks for TypeScript: aggregates, entities, value objects, domain events, CQRS command and query buses, unit of work and application ports, with an in-memory event bus.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ddd",
|