@ddd-ts-kit/kernel 0.9.0 → 0.10.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.md +138 -2
- package/dist/application/criteria/index.d.ts +33 -0
- package/dist/application/criteria/index.d.ts.map +1 -0
- package/dist/application/criteria/index.js +33 -0
- package/dist/application/criteria/index.js.map +1 -0
- package/dist/application/event-sourcing/appended.d.ts +8 -0
- package/dist/application/event-sourcing/appended.d.ts.map +1 -0
- package/dist/application/event-sourcing/appended.js +2 -0
- package/dist/application/event-sourcing/appended.js.map +1 -0
- package/dist/application/event-sourcing/define-stored-event.d.ts +10 -0
- package/dist/application/event-sourcing/define-stored-event.d.ts.map +1 -0
- package/dist/application/event-sourcing/define-stored-event.js +22 -0
- package/dist/application/event-sourcing/define-stored-event.js.map +1 -0
- package/dist/application/event-sourcing/erased-personal-data.d.ts +3 -0
- package/dist/application/event-sourcing/erased-personal-data.d.ts.map +1 -0
- package/dist/application/event-sourcing/erased-personal-data.js +3 -0
- package/dist/application/event-sourcing/erased-personal-data.js.map +1 -0
- package/dist/application/event-sourcing/event-envelope.d.ts +9 -0
- package/dist/application/event-sourcing/event-envelope.d.ts.map +1 -0
- package/dist/application/event-sourcing/event-envelope.js +2 -0
- package/dist/application/event-sourcing/event-envelope.js.map +1 -0
- package/dist/application/event-sourcing/event-to-append.d.ts +15 -0
- package/dist/application/event-sourcing/event-to-append.d.ts.map +1 -0
- package/dist/application/event-sourcing/event-to-append.js +2 -0
- package/dist/application/event-sourcing/event-to-append.js.map +1 -0
- package/dist/application/event-sourcing/index.d.ts +21 -0
- package/dist/application/event-sourcing/index.d.ts.map +1 -0
- package/dist/application/event-sourcing/index.js +21 -0
- package/dist/application/event-sourcing/index.js.map +1 -0
- package/dist/application/event-sourcing/is-stored-data.d.ts +5 -0
- package/dist/application/event-sourcing/is-stored-data.d.ts.map +1 -0
- package/dist/application/event-sourcing/is-stored-data.js +5 -0
- package/dist/application/event-sourcing/is-stored-data.js.map +1 -0
- package/dist/application/event-sourcing/is-stored-list.d.ts +4 -0
- package/dist/application/event-sourcing/is-stored-list.d.ts.map +1 -0
- package/dist/application/event-sourcing/is-stored-list.js +5 -0
- package/dist/application/event-sourcing/is-stored-list.js.map +1 -0
- package/dist/application/event-sourcing/personal-data.d.ts +14 -0
- package/dist/application/event-sourcing/personal-data.d.ts.map +1 -0
- package/dist/application/event-sourcing/personal-data.js +9 -0
- package/dist/application/event-sourcing/personal-data.js.map +1 -0
- package/dist/application/event-sourcing/stored-data-of.d.ts +9 -0
- package/dist/application/event-sourcing/stored-data-of.d.ts.map +1 -0
- package/dist/application/event-sourcing/stored-data-of.js +40 -0
- package/dist/application/event-sourcing/stored-data-of.js.map +1 -0
- package/dist/application/event-sourcing/stored-data.d.ts +6 -0
- package/dist/application/event-sourcing/stored-data.d.ts.map +1 -0
- package/dist/application/event-sourcing/stored-data.js +2 -0
- package/dist/application/event-sourcing/stored-data.js.map +1 -0
- package/dist/application/event-sourcing/stored-event-data.d.ts +25 -0
- package/dist/application/event-sourcing/stored-event-data.d.ts.map +1 -0
- package/dist/application/event-sourcing/stored-event-data.js +82 -0
- package/dist/application/event-sourcing/stored-event-data.js.map +1 -0
- package/dist/application/event-sourcing/stored-event-spec.d.ts +20 -0
- package/dist/application/event-sourcing/stored-event-spec.d.ts.map +1 -0
- package/dist/application/event-sourcing/stored-event-spec.js +2 -0
- package/dist/application/event-sourcing/stored-event-spec.js.map +1 -0
- package/dist/application/event-sourcing/stored-event-type.d.ts +14 -0
- package/dist/application/event-sourcing/stored-event-type.d.ts.map +1 -0
- package/dist/application/event-sourcing/stored-event-type.js +2 -0
- package/dist/application/event-sourcing/stored-event-type.js.map +1 -0
- package/dist/application/event-sourcing/stored-event-types.d.ts +9 -0
- package/dist/application/event-sourcing/stored-event-types.d.ts.map +1 -0
- package/dist/application/event-sourcing/stored-event-types.js +2 -0
- package/dist/application/event-sourcing/stored-event-types.js.map +1 -0
- package/dist/application/event-sourcing/stored-event.d.ts +12 -0
- package/dist/application/event-sourcing/stored-event.d.ts.map +1 -0
- package/dist/application/event-sourcing/stored-event.js +2 -0
- package/dist/application/event-sourcing/stored-event.js.map +1 -0
- package/dist/application/event-sourcing/stored-json.d.ts +5 -0
- package/dist/application/event-sourcing/stored-json.d.ts.map +1 -0
- package/dist/application/event-sourcing/stored-json.js +2 -0
- package/dist/application/event-sourcing/stored-json.js.map +1 -0
- package/dist/application/event-sourcing/stored-snapshot.d.ts +11 -0
- package/dist/application/event-sourcing/stored-snapshot.d.ts.map +1 -0
- package/dist/application/event-sourcing/stored-snapshot.js +2 -0
- package/dist/application/event-sourcing/stored-snapshot.js.map +1 -0
- package/dist/application/event-sourcing/subject-key.d.ts +10 -0
- package/dist/application/event-sourcing/subject-key.d.ts.map +1 -0
- package/dist/application/event-sourcing/subject-key.js +2 -0
- package/dist/application/event-sourcing/subject-key.js.map +1 -0
- package/dist/application/event-sourcing/unreadable-event-error.d.ts +5 -0
- package/dist/application/event-sourcing/unreadable-event-error.d.ts.map +1 -0
- package/dist/application/event-sourcing/unreadable-event-error.js +8 -0
- package/dist/application/event-sourcing/unreadable-event-error.js.map +1 -0
- package/dist/application/event-sourcing/upcaster.d.ts +4 -0
- package/dist/application/event-sourcing/upcaster.d.ts.map +1 -0
- package/dist/application/event-sourcing/upcaster.js +2 -0
- package/dist/application/event-sourcing/upcaster.js.map +1 -0
- package/dist/application/persistence/append-changes.d.ts +18 -0
- package/dist/application/persistence/append-changes.d.ts.map +1 -0
- package/dist/application/persistence/append-changes.js +17 -0
- package/dist/application/persistence/append-changes.js.map +1 -0
- package/dist/application/ports/checkpoint-store.d.ts +14 -0
- package/dist/application/ports/checkpoint-store.d.ts.map +1 -0
- package/dist/application/ports/checkpoint-store.js +10 -0
- package/dist/application/ports/checkpoint-store.js.map +1 -0
- package/dist/application/ports/event-store.d.ts +24 -0
- package/dist/application/ports/event-store.d.ts.map +1 -0
- package/dist/application/ports/event-store.js +12 -0
- package/dist/application/ports/event-store.js.map +1 -0
- package/dist/application/ports/snapshot-store.d.ts +8 -0
- package/dist/application/ports/snapshot-store.d.ts.map +1 -0
- package/dist/application/ports/snapshot-store.js +7 -0
- package/dist/application/ports/snapshot-store.js.map +1 -0
- package/dist/application/ports/subject-key-store.d.ts +17 -0
- package/dist/application/ports/subject-key-store.d.ts.map +1 -0
- package/dist/application/ports/subject-key-store.js +13 -0
- package/dist/application/ports/subject-key-store.js.map +1 -0
- package/dist/declarations/decorators/projection-options.d.ts +5 -0
- package/dist/declarations/decorators/projection-options.d.ts.map +1 -0
- package/dist/declarations/decorators/projection-options.js +2 -0
- package/dist/declarations/decorators/projection-options.js.map +1 -0
- package/dist/declarations/decorators/projection.d.ts +4 -0
- package/dist/declarations/decorators/projection.d.ts.map +1 -1
- package/dist/declarations/decorators/projection.js +16 -8
- package/dist/declarations/decorators/projection.js.map +1 -1
- package/dist/declarations/model/projection-declaration.d.ts +3 -0
- package/dist/declarations/model/projection-declaration.d.ts.map +1 -1
- package/dist/declarations/model/projection-feed.d.ts +8 -0
- package/dist/declarations/model/projection-feed.d.ts.map +1 -0
- package/dist/declarations/model/projection-feed.js +2 -0
- package/dist/declarations/model/projection-feed.js.map +1 -0
- package/dist/declarations/projection/applying-projection.d.ts +14 -0
- package/dist/declarations/projection/applying-projection.d.ts.map +1 -0
- package/dist/declarations/projection/applying-projection.js +32 -0
- package/dist/declarations/projection/applying-projection.js.map +1 -0
- package/dist/declarations.d.ts +3 -0
- package/dist/declarations.d.ts.map +1 -1
- package/dist/declarations.js +1 -0
- package/dist/declarations.js.map +1 -1
- package/dist/domain/event-sourcing/aggregate-history.d.ts +10 -0
- package/dist/domain/event-sourcing/aggregate-history.d.ts.map +1 -0
- package/dist/domain/event-sourcing/aggregate-history.js +2 -0
- package/dist/domain/event-sourcing/aggregate-history.js.map +1 -0
- package/dist/domain/event-sourcing/aggregate-snapshot.d.ts +6 -0
- package/dist/domain/event-sourcing/aggregate-snapshot.d.ts.map +1 -0
- package/dist/domain/event-sourcing/aggregate-snapshot.js +2 -0
- package/dist/domain/event-sourcing/aggregate-snapshot.js.map +1 -0
- package/dist/domain/event-sourcing/appliers.d.ts +12 -0
- package/dist/domain/event-sourcing/appliers.d.ts.map +1 -0
- package/dist/domain/event-sourcing/appliers.js +2 -0
- package/dist/domain/event-sourcing/appliers.js.map +1 -0
- package/dist/domain/event-sourcing/event-sourced-aggregate.d.ts +28 -0
- package/dist/domain/event-sourcing/event-sourced-aggregate.d.ts.map +1 -0
- package/dist/domain/event-sourcing/event-sourced-aggregate.js +51 -0
- package/dist/domain/event-sourcing/event-sourced-aggregate.js.map +1 -0
- package/dist/domain/event-sourcing/unstored-events.d.ts +8 -0
- package/dist/domain/event-sourcing/unstored-events.d.ts.map +1 -0
- package/dist/domain/event-sourcing/unstored-events.js +7 -0
- package/dist/domain/event-sourcing/unstored-events.js.map +1 -0
- package/dist/index.d.ts +32 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -32
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/event-sourcing/catch-up-subscription.d.ts +33 -0
- package/dist/infrastructure/event-sourcing/catch-up-subscription.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/catch-up-subscription.js +39 -0
- package/dist/infrastructure/event-sourcing/catch-up-subscription.js.map +1 -0
- package/dist/infrastructure/event-sourcing/event-serializer.d.ts +35 -0
- package/dist/infrastructure/event-sourcing/event-serializer.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/event-serializer.js +104 -0
- package/dist/infrastructure/event-sourcing/event-serializer.js.map +1 -0
- package/dist/infrastructure/event-sourcing/event-sourced-repository.d.ts +32 -0
- package/dist/infrastructure/event-sourcing/event-sourced-repository.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/event-sourced-repository.js +68 -0
- package/dist/infrastructure/event-sourcing/event-sourced-repository.js.map +1 -0
- package/dist/infrastructure/event-sourcing/event-sourcing-stores.d.ts +12 -0
- package/dist/infrastructure/event-sourcing/event-sourcing-stores.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/event-sourcing-stores.js +2 -0
- package/dist/infrastructure/event-sourcing/event-sourcing-stores.js.map +1 -0
- package/dist/infrastructure/event-sourcing/event-store-projection-rebuild.d.ts +34 -0
- package/dist/infrastructure/event-sourcing/event-store-projection-rebuild.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/event-store-projection-rebuild.js +48 -0
- package/dist/infrastructure/event-sourcing/event-store-projection-rebuild.js.map +1 -0
- package/dist/infrastructure/event-sourcing/personal-data-cipher.d.ts +19 -0
- package/dist/infrastructure/event-sourcing/personal-data-cipher.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/personal-data-cipher.js +84 -0
- package/dist/infrastructure/event-sourcing/personal-data-cipher.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables-options.d.ts +6 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables-options.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables-options.js +2 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables-options.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables-sql.d.ts +9 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables-sql.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables-sql.js +32 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables-sql.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables.d.ts +9 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables.js +9 -0
- package/dist/infrastructure/event-sourcing/postgres/event-store-tables.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/is-append-conflict.d.ts +3 -0
- package/dist/infrastructure/event-sourcing/postgres/is-append-conflict.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/is-append-conflict.js +22 -0
- package/dist/infrastructure/event-sourcing/postgres/is-append-conflict.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-checkpoint-store.d.ts +12 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-checkpoint-store.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-checkpoint-store.js +26 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-checkpoint-store.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-event-sourcing.d.ts +6 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-event-sourcing.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-event-sourcing.js +14 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-event-sourcing.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-event-store.d.ts +31 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-event-store.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-event-store.js +120 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-event-store.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-snapshot-store.d.ts +13 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-snapshot-store.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-snapshot-store.js +28 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-snapshot-store.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-subject-key-store.d.ts +21 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-subject-key-store.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-subject-key-store.js +48 -0
- package/dist/infrastructure/event-sourcing/postgres/postgres-subject-key-store.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/qualified-table.d.ts +4 -0
- package/dist/infrastructure/event-sourcing/postgres/qualified-table.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/qualified-table.js +10 -0
- package/dist/infrastructure/event-sourcing/postgres/qualified-table.js.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/stored-data-from.d.ts +4 -0
- package/dist/infrastructure/event-sourcing/postgres/stored-data-from.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/postgres/stored-data-from.js +23 -0
- package/dist/infrastructure/event-sourcing/postgres/stored-data-from.js.map +1 -0
- package/dist/infrastructure/event-sourcing/rewrite-objects.d.ts +8 -0
- package/dist/infrastructure/event-sourcing/rewrite-objects.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/rewrite-objects.js +16 -0
- package/dist/infrastructure/event-sourcing/rewrite-objects.js.map +1 -0
- package/dist/infrastructure/event-sourcing/snapshot-policy.d.ts +14 -0
- package/dist/infrastructure/event-sourcing/snapshot-policy.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/snapshot-policy.js +2 -0
- package/dist/infrastructure/event-sourcing/snapshot-policy.js.map +1 -0
- package/dist/infrastructure/event-sourcing/stored-origins.d.ts +5 -0
- package/dist/infrastructure/event-sourcing/stored-origins.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/stored-origins.js +3 -0
- package/dist/infrastructure/event-sourcing/stored-origins.js.map +1 -0
- package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts +10 -0
- package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/stored-stamp-of.js +14 -0
- package/dist/infrastructure/event-sourcing/stored-stamp-of.js.map +1 -0
- package/dist/infrastructure/in-memory/in-memory-checkpoint-store.d.ts +8 -0
- package/dist/infrastructure/in-memory/in-memory-checkpoint-store.d.ts.map +1 -0
- package/dist/infrastructure/in-memory/in-memory-checkpoint-store.js +15 -0
- package/dist/infrastructure/in-memory/in-memory-checkpoint-store.js.map +1 -0
- package/dist/infrastructure/in-memory/in-memory-event-store.d.ts +14 -0
- package/dist/infrastructure/in-memory/in-memory-event-store.d.ts.map +1 -0
- package/dist/infrastructure/in-memory/in-memory-event-store.js +37 -0
- package/dist/infrastructure/in-memory/in-memory-event-store.js.map +1 -0
- package/dist/infrastructure/in-memory/in-memory-snapshot-store.d.ts +9 -0
- package/dist/infrastructure/in-memory/in-memory-snapshot-store.d.ts.map +1 -0
- package/dist/infrastructure/in-memory/in-memory-snapshot-store.js +15 -0
- package/dist/infrastructure/in-memory/in-memory-snapshot-store.js.map +1 -0
- package/dist/infrastructure/in-memory/in-memory-subject-key-store.d.ts +10 -0
- package/dist/infrastructure/in-memory/in-memory-subject-key-store.d.ts.map +1 -0
- package/dist/infrastructure/in-memory/in-memory-subject-key-store.js +21 -0
- package/dist/infrastructure/in-memory/in-memory-subject-key-store.js.map +1 -0
- package/dist/infrastructure/read-model/shadow-read-model-store.d.ts +20 -0
- package/dist/infrastructure/read-model/shadow-read-model-store.d.ts.map +1 -0
- package/dist/infrastructure/read-model/shadow-read-model-store.js +25 -0
- package/dist/infrastructure/read-model/shadow-read-model-store.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isStoredData } from './is-stored-data.js';
|
|
2
|
+
import { isStoredList } from './is-stored-list.js';
|
|
3
|
+
import { UnreadableEventError } from './unreadable-event-error.js';
|
|
4
|
+
/**
|
|
5
|
+
* The data of a stored event as `decode` reads it. Each read names the field and the type it
|
|
6
|
+
* expects, and refuses a field that is absent or of another type with an UnreadableEventError:
|
|
7
|
+
* a corrupt row or a forgotten upcaster stops the load instead of building a wrong aggregate.
|
|
8
|
+
*/
|
|
9
|
+
export class StoredEventData {
|
|
10
|
+
data;
|
|
11
|
+
where;
|
|
12
|
+
constructor(data, where) {
|
|
13
|
+
this.data = data;
|
|
14
|
+
this.where = where;
|
|
15
|
+
}
|
|
16
|
+
text(field) {
|
|
17
|
+
const value = this.data[field];
|
|
18
|
+
if (typeof value !== 'string') {
|
|
19
|
+
throw this.unreadable(field, 'a text');
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
optionalText(field) {
|
|
24
|
+
return this.data[field] === undefined || this.data[field] === null ? undefined : this.text(field);
|
|
25
|
+
}
|
|
26
|
+
number(field) {
|
|
27
|
+
const value = this.data[field];
|
|
28
|
+
if (typeof value !== 'number') {
|
|
29
|
+
throw this.unreadable(field, 'a number');
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
flag(field) {
|
|
34
|
+
const value = this.data[field];
|
|
35
|
+
if (typeof value !== 'boolean') {
|
|
36
|
+
throw this.unreadable(field, 'a boolean');
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
/** A date, kept as its ISO text. */
|
|
41
|
+
instant(field) {
|
|
42
|
+
const date = new Date(this.text(field));
|
|
43
|
+
if (Number.isNaN(date.getTime())) {
|
|
44
|
+
throw this.unreadable(field, 'an instant');
|
|
45
|
+
}
|
|
46
|
+
return date;
|
|
47
|
+
}
|
|
48
|
+
optionalInstant(field) {
|
|
49
|
+
return this.optionalText(field) === undefined ? undefined : this.instant(field);
|
|
50
|
+
}
|
|
51
|
+
texts(field) {
|
|
52
|
+
return this.list(field).map((item, index) => {
|
|
53
|
+
if (typeof item !== 'string') {
|
|
54
|
+
throw this.unreadable(`${field}[${index}]`, 'a text');
|
|
55
|
+
}
|
|
56
|
+
return item;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
record(field) {
|
|
60
|
+
return this.nested(this.data[field], field);
|
|
61
|
+
}
|
|
62
|
+
records(field) {
|
|
63
|
+
return this.list(field).map((item, index) => this.nested(item, `${field}[${index}]`));
|
|
64
|
+
}
|
|
65
|
+
list(field) {
|
|
66
|
+
const value = this.data[field];
|
|
67
|
+
if (!isStoredList(value)) {
|
|
68
|
+
throw this.unreadable(field, 'a list');
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
nested(value, field) {
|
|
73
|
+
if (!isStoredData(value)) {
|
|
74
|
+
throw this.unreadable(field, 'an object');
|
|
75
|
+
}
|
|
76
|
+
return new StoredEventData(value, `${this.where}, ${field}`);
|
|
77
|
+
}
|
|
78
|
+
unreadable(field, expected) {
|
|
79
|
+
return new UnreadableEventError(`${this.where}: "${field}" is not ${expected}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=stored-event-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-event-data.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-event-data.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DomainEvent } from '../../domain/domain-event.js';
|
|
2
|
+
import type { EventEnvelope } from './event-envelope.js';
|
|
3
|
+
import type { StoredEventData } from './stored-event-data.js';
|
|
4
|
+
import type { Upcaster } from './upcaster.js';
|
|
5
|
+
/**
|
|
6
|
+
* How one domain event is kept in a stream. `encode` answers the data of the current `version`
|
|
7
|
+
* under a named type (`NoShowNotedData`): that type is the stored shape, and a stored shape never
|
|
8
|
+
* changes. A change of shape is a new version, with the upcaster from the previous one:
|
|
9
|
+
* `upcasters: { 1: (data) => ({ ...data, reason: '' }) }` reads a version 1 as a version 2.
|
|
10
|
+
*/
|
|
11
|
+
export interface StoredEventSpec<E extends DomainEvent, Data extends object> {
|
|
12
|
+
/** The version of the shape `encode` writes, from 1. */
|
|
13
|
+
readonly version: number;
|
|
14
|
+
encode(event: E): Data;
|
|
15
|
+
/** Builds the event back from data of the current version: older data is upcast first. */
|
|
16
|
+
decode(data: StoredEventData, envelope: EventEnvelope): E;
|
|
17
|
+
/** By the version each one reads: one upcaster from every version below `version`. */
|
|
18
|
+
readonly upcasters?: Readonly<Record<number, Upcaster>>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=stored-event-spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-event-spec.d.ts","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-event-spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,SAAS,MAAM;IACzE,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACvB,0FAA0F;IAC1F,MAAM,CAAC,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,GAAG,CAAC,CAAC;IAC1D,sFAAsF;IACtF,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;CACzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-event-spec.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-event-spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DomainEvent } from '../../domain/domain-event.js';
|
|
2
|
+
import type { EventEnvelope } from './event-envelope.js';
|
|
3
|
+
import type { StoredData } from './stored-data.js';
|
|
4
|
+
import type { StoredEventData } from './stored-event-data.js';
|
|
5
|
+
import type { Upcaster } from './upcaster.js';
|
|
6
|
+
/** One stored event as `defineStoredEvent` declared it, ready for the serializer. */
|
|
7
|
+
export interface StoredEventType<E extends DomainEvent> {
|
|
8
|
+
readonly version: number;
|
|
9
|
+
readonly upcasters: Readonly<Record<number, Upcaster>>;
|
|
10
|
+
/** Refuses an event of another class than the declared one. */
|
|
11
|
+
encode(event: DomainEvent): StoredData;
|
|
12
|
+
decode(data: StoredEventData, envelope: EventEnvelope): E;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=stored-event-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-event-type.d.ts","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-event-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,qFAAqF;AACrF,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,WAAW;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvD,+DAA+D;IAC/D,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAAC;IACvC,MAAM,CAAC,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,GAAG,CAAC,CAAC;CAC3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-event-type.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-event-type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DomainEvent } from '../../domain/domain-event.js';
|
|
2
|
+
import type { StoredEventType } from './stored-event-type.js';
|
|
3
|
+
/** The stored events of one aggregate, by the name each carries: every event of the union is declared. */
|
|
4
|
+
export type StoredEventTypes<E extends DomainEvent> = {
|
|
5
|
+
readonly [Name in E['name']]: StoredEventType<Extract<E, {
|
|
6
|
+
readonly name: Name;
|
|
7
|
+
}>>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=stored-event-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-event-types.d.ts","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-event-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,0GAA0G;AAC1G,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,WAAW,IAAI;IACpD,QAAQ,EAAE,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,CAAC;CACnF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-event-types.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-event-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EventToAppend } from './event-to-append.js';
|
|
2
|
+
import type { StoredData } from './stored-data.js';
|
|
3
|
+
/** An event as the store gives it back, placed in its stream and in the whole store. */
|
|
4
|
+
export interface StoredEvent extends EventToAppend {
|
|
5
|
+
readonly stream: string;
|
|
6
|
+
/** Its rank in its stream, from 1: the stream reads in this order. */
|
|
7
|
+
readonly version: number;
|
|
8
|
+
/** Its rank in the store, from 1, in the order the appends committed: what a subscription remembers. */
|
|
9
|
+
readonly position: number;
|
|
10
|
+
readonly metadata: StoredData;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=stored-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-event.d.ts","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,wFAAwF;AACxF,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wGAAwG;IACxG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-event.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-event.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-json.d.ts","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-json.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,UAAU,EAAE,GACrB;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-json.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-json.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StoredData } from './stored-data.js';
|
|
2
|
+
/** The state of a stream at a version, kept to shorten its replay. A snapshot can always be thrown away. */
|
|
3
|
+
export interface StoredSnapshot {
|
|
4
|
+
readonly stream: string;
|
|
5
|
+
/** The number of events of the stream the state reflects. */
|
|
6
|
+
readonly version: number;
|
|
7
|
+
/** The version of the shape of `data`: a snapshot of another shape is ignored and the stream replayed. */
|
|
8
|
+
readonly schemaVersion: number;
|
|
9
|
+
readonly data: StoredData;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=stored-snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-snapshot.d.ts","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,4GAA4G;AAC5G,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,0GAA0G;IAC1G,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-snapshot.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/stored-snapshot.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The key the personal data of one data subject is sealed with. Destroying it erases that data everywhere it was sealed. */
|
|
2
|
+
export interface SubjectKey {
|
|
3
|
+
/** Written next to every value sealed with it, so a later key of the same subject never opens an older value. */
|
|
4
|
+
readonly id: string;
|
|
5
|
+
/** The data subject: whose personal data the key seals. */
|
|
6
|
+
readonly subject: string;
|
|
7
|
+
/** 32 bytes, base64. */
|
|
8
|
+
readonly material: string;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=subject-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subject-key.d.ts","sourceRoot":"","sources":["../../../src/application/event-sourcing/subject-key.ts"],"names":[],"mappings":"AAAA,6HAA6H;AAC7H,MAAM,WAAW,UAAU;IACzB,iHAAiH;IACjH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wBAAwB;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subject-key.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/subject-key.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** A stored event, or a snapshot, that cannot be read as its declaration says: a field missing or of another type, a version without upcaster. */
|
|
2
|
+
export declare class UnreadableEventError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=unreadable-event-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unreadable-event-error.d.ts","sourceRoot":"","sources":["../../../src/application/event-sourcing/unreadable-event-error.ts"],"names":[],"mappings":"AAAA,kJAAkJ;AAClJ,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A stored event, or a snapshot, that cannot be read as its declaration says: a field missing or of another type, a version without upcaster. */
|
|
2
|
+
export class UnreadableEventError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'UnreadableEventError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=unreadable-event-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unreadable-event-error.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/unreadable-event-error.ts"],"names":[],"mappings":"AAAA,kJAAkJ;AAClJ,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { StoredData } from './stored-data.js';
|
|
2
|
+
/** Turns the data of a stored event from one version of its shape into the next one. Pure: the stored event is never rewritten. */
|
|
3
|
+
export type Upcaster = (data: StoredData) => StoredData;
|
|
4
|
+
//# sourceMappingURL=upcaster.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upcaster.d.ts","sourceRoot":"","sources":["../../../src/application/event-sourcing/upcaster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,mIAAmI;AACnI,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upcaster.js","sourceRoot":"","sources":["../../../src/application/event-sourcing/upcaster.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DomainEvent } from '../../domain/domain-event.js';
|
|
2
|
+
import type { EventSourcedAggregate } from '../../domain/event-sourcing/event-sourced-aggregate.js';
|
|
3
|
+
export interface StreamChanges {
|
|
4
|
+
/** The version the stream must still have. */
|
|
5
|
+
readonly expected: number;
|
|
6
|
+
/** What the aggregate recorded since it was loaded, in order. */
|
|
7
|
+
readonly events: readonly DomainEvent[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Optimistic concurrency for an event-sourced aggregate: hands what it recorded since it was
|
|
11
|
+
* loaded to `append`, with the version its stream must still have. Once `append` resolves, the
|
|
12
|
+
* aggregate is at the new version with nothing left to store, and can be saved again; when it
|
|
13
|
+
* rejects (a ConcurrencyError: somebody else appended first), the aggregate is left as it was.
|
|
14
|
+
* An aggregate that recorded nothing still hands its version over, with no event: the store
|
|
15
|
+
* refuses it when the stream moved meanwhile, so a stale copy is never taken for a current one.
|
|
16
|
+
*/
|
|
17
|
+
export declare function appendChanges<E extends DomainEvent, S>(aggregate: EventSourcedAggregate<E, S>, append: (changes: StreamChanges) => Promise<void>): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=append-changes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append-changes.d.ts","sourceRoot":"","sources":["../../../src/application/persistence/append-changes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wDAAwD,CAAC;AAGpG,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;CACzC;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,EAC1D,SAAS,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,EACtC,MAAM,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,GAChD,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { unstoredEvents } from '../../domain/event-sourcing/unstored-events.js';
|
|
2
|
+
/**
|
|
3
|
+
* Optimistic concurrency for an event-sourced aggregate: hands what it recorded since it was
|
|
4
|
+
* loaded to `append`, with the version its stream must still have. Once `append` resolves, the
|
|
5
|
+
* aggregate is at the new version with nothing left to store, and can be saved again; when it
|
|
6
|
+
* rejects (a ConcurrencyError: somebody else appended first), the aggregate is left as it was.
|
|
7
|
+
* An aggregate that recorded nothing still hands its version over, with no event: the store
|
|
8
|
+
* refuses it when the stream moved meanwhile, so a stale copy is never taken for a current one.
|
|
9
|
+
*/
|
|
10
|
+
export async function appendChanges(aggregate, append) {
|
|
11
|
+
const unstored = unstoredEvents.get(aggregate) ?? [];
|
|
12
|
+
const events = [...unstored];
|
|
13
|
+
await append({ expected: aggregate.version, events });
|
|
14
|
+
unstored.splice(0, events.length);
|
|
15
|
+
aggregate.version += events.length;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=append-changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append-changes.js","sourceRoot":"","sources":["../../../src/application/persistence/append-changes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAShF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,SAAsC,EACtC,MAAiD;IAEjD,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IACrD,MAAM,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IAE7B,MAAM,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACtD,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,SAAS,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How far each subscription to an event store has applied the store. Kept in the database of what
|
|
3
|
+
* the subscription writes, a checkpoint commits with what it applied.
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class CheckpointStore {
|
|
6
|
+
/** The last position the subscriber applied, 0 when it applied nothing yet. */
|
|
7
|
+
abstract position(subscriber: string): Promise<number>;
|
|
8
|
+
/**
|
|
9
|
+
* Moves the checkpoint from `from` to `to`, and refuses with a ConcurrencyError when it is no
|
|
10
|
+
* longer at `from`: another run of the same subscriber applied the same events first.
|
|
11
|
+
*/
|
|
12
|
+
abstract advance(subscriber: string, from: number, to: number): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=checkpoint-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint-store.d.ts","sourceRoot":"","sources":["../../../src/application/ports/checkpoint-store.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,8BAAsB,eAAe;IAKnC,+EAA+E;IAC/E,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvD;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How far each subscription to an event store has applied the store. Kept in the database of what
|
|
3
|
+
* the subscription writes, a checkpoint commits with what it applied.
|
|
4
|
+
*/
|
|
5
|
+
export class CheckpointStore {
|
|
6
|
+
static {
|
|
7
|
+
Object.defineProperty(this, 'tokenKey', { value: 'kernel.CheckpointStore' });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=checkpoint-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint-store.js","sourceRoot":"","sources":["../../../src/application/ports/checkpoint-store.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAgB,eAAe;IACnC;QACE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,CAAC;IAC/E,CAAC;CAUF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Appended } from '../event-sourcing/appended.js';
|
|
2
|
+
import type { EventToAppend } from '../event-sourcing/event-to-append.js';
|
|
3
|
+
import type { StoredEvent } from '../event-sourcing/stored-event.js';
|
|
4
|
+
/**
|
|
5
|
+
* Where event-sourced aggregates keep their streams: one stream per aggregate, read in order,
|
|
6
|
+
* and the whole store read in the order the appends committed, for the subscriptions. Stored
|
|
7
|
+
* events are never changed. Only repository adapters and subscriptions use it: the domain and the
|
|
8
|
+
* use cases never read a stream.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class EventStore {
|
|
11
|
+
/**
|
|
12
|
+
* Appends the events to the stream if it still has `expectedVersion` events (0: the stream does
|
|
13
|
+
* not exist yet), and refuses with a ConcurrencyError otherwise: somebody else appended since it
|
|
14
|
+
* was read. Joins the transaction of the current unit of work when the store is transactional.
|
|
15
|
+
*/
|
|
16
|
+
abstract append(stream: string, expectedVersion: number, events: readonly EventToAppend[]): Promise<Appended>;
|
|
17
|
+
/** The events of the stream after version `after` (default 0: all of them), in their order. */
|
|
18
|
+
abstract readStream(stream: string, after?: number): Promise<readonly StoredEvent[]>;
|
|
19
|
+
/** Up to `limit` events of the whole store after position `after`, in the order of their positions. */
|
|
20
|
+
abstract readAll(after: number, limit: number): Promise<readonly StoredEvent[]>;
|
|
21
|
+
/** The position of the last event stored, 0 when there is none. */
|
|
22
|
+
abstract head(): Promise<number>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=event-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-store.d.ts","sourceRoot":"","sources":["../../../src/application/ports/event-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAErE;;;;;GAKG;AACH,8BAAsB,UAAU;IAK9B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9G,+FAA+F;IAC/F,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,WAAW,EAAE,CAAC,CAAC;IAErF,uGAAuG;IACvG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,WAAW,EAAE,CAAC,CAAC;IAEhF,mEAAmE;IACnE,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAClC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where event-sourced aggregates keep their streams: one stream per aggregate, read in order,
|
|
3
|
+
* and the whole store read in the order the appends committed, for the subscriptions. Stored
|
|
4
|
+
* events are never changed. Only repository adapters and subscriptions use it: the domain and the
|
|
5
|
+
* use cases never read a stream.
|
|
6
|
+
*/
|
|
7
|
+
export class EventStore {
|
|
8
|
+
static {
|
|
9
|
+
Object.defineProperty(this, 'tokenKey', { value: 'kernel.EventStore' });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=event-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-store.js","sourceRoot":"","sources":["../../../src/application/ports/event-store.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,OAAgB,UAAU;IAC9B;QACE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAC1E,CAAC;CAiBF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StoredSnapshot } from '../event-sourcing/stored-snapshot.js';
|
|
2
|
+
/** The last snapshot of each stream. Only the event-sourced repository uses it. */
|
|
3
|
+
export declare abstract class SnapshotStore {
|
|
4
|
+
abstract find(stream: string): Promise<StoredSnapshot | undefined>;
|
|
5
|
+
/** Keeps the snapshot unless the stream already has one of a later version. */
|
|
6
|
+
abstract save(snapshot: StoredSnapshot): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=snapshot-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-store.d.ts","sourceRoot":"","sources":["../../../src/application/ports/snapshot-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAE3E,mFAAmF;AACnF,8BAAsB,aAAa;IAKjC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC;IAEnE,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-store.js","sourceRoot":"","sources":["../../../src/application/ports/snapshot-store.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,MAAM,OAAgB,aAAa;IACjC;QACE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAAC,CAAC;IAC7E,CAAC;CAMF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SubjectKey } from '../event-sourcing/subject-key.js';
|
|
2
|
+
/**
|
|
3
|
+
* The keys personal data is sealed with, one per data subject (crypto-shredding). Erasing a
|
|
4
|
+
* subject destroys its key: every value sealed with it can no longer be read from the live
|
|
5
|
+
* events and snapshots, nor from a backup of them that does not hold the key. A backup that
|
|
6
|
+
* holds the events and the keys together still opens them until it expires, so keep the keys
|
|
7
|
+
* apart from the events in production, with a shorter backup retention.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class SubjectKeyStore {
|
|
10
|
+
/** The current key of the subject, created when it has none, a first time or after an erasure. */
|
|
11
|
+
abstract keyFor(subject: string): Promise<SubjectKey>;
|
|
12
|
+
/** The key of this id, `undefined` once its subject was erased. */
|
|
13
|
+
abstract find(keyId: string): Promise<SubjectKey | undefined>;
|
|
14
|
+
/** Destroys the keys of the subject. Answers whether there was one. */
|
|
15
|
+
abstract erase(subject: string): Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=subject-key-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subject-key-store.d.ts","sourceRoot":"","sources":["../../../src/application/ports/subject-key-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAEnE;;;;;;GAMG;AACH,8BAAsB,eAAe;IAKnC,kGAAkG;IAClG,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEtD,mEAAmE;IACnE,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAE9D,uEAAuE;IACvE,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys personal data is sealed with, one per data subject (crypto-shredding). Erasing a
|
|
3
|
+
* subject destroys its key: every value sealed with it can no longer be read from the live
|
|
4
|
+
* events and snapshots, nor from a backup of them that does not hold the key. A backup that
|
|
5
|
+
* holds the events and the keys together still opens them until it expires, so keep the keys
|
|
6
|
+
* apart from the events in production, with a shorter backup retention.
|
|
7
|
+
*/
|
|
8
|
+
export class SubjectKeyStore {
|
|
9
|
+
static {
|
|
10
|
+
Object.defineProperty(this, 'tokenKey', { value: 'kernel.SubjectKeyStore' });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=subject-key-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subject-key-store.js","sourceRoot":"","sources":["../../../src/application/ports/subject-key-store.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,OAAgB,eAAe;IACnC;QACE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,CAAC;IAC/E,CAAC;CAUF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection-options.d.ts","sourceRoot":"","sources":["../../../src/declarations/decorators/projection-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection-options.js","sourceRoot":"","sources":["../../../src/declarations/decorators/projection-options.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { ClassDeclarator } from '../dependencies/class-declarator.js';
|
|
2
2
|
import type { DeclaredDependencies } from '../dependencies/declared-dependencies.js';
|
|
3
3
|
import type { DependenciesFromSignature } from '../dependencies/dependencies-from-signature.js';
|
|
4
|
+
import type { ProjectionOptions } from './projection-options.js';
|
|
4
5
|
/**
|
|
5
6
|
* A projector: the class that keeps one read model up to date, each of its `@On` methods
|
|
6
7
|
* applying one event through a port of its own read model:
|
|
7
8
|
* `@Projection('scheduling.appointment-list')`. The name is the consumer
|
|
8
9
|
* it is subscribed as: stable, `<context>.<name>`, unique in the application.
|
|
10
|
+
* `@Projection('scheduling.attendance-history', { feed: 'event-store' })` is fed from the event
|
|
11
|
+
* store by a catch-up subscription instead of where the domain events are dispatched.
|
|
9
12
|
*/
|
|
10
13
|
export declare function Projection<const D extends DeclaredDependencies = DependenciesFromSignature>(name: `${string}.${string}`, dependencies?: D): ClassDeclarator<object, D>;
|
|
14
|
+
export declare function Projection<const D extends DeclaredDependencies = DependenciesFromSignature>(name: `${string}.${string}`, options: ProjectionOptions, dependencies?: D): ClassDeclarator<object, D>;
|
|
11
15
|
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/declarations/decorators/projection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAOhG
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/declarations/decorators/projection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAOhG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,oBAAoB,GAAG,yBAAyB,EACzF,IAAI,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,EAC3B,YAAY,CAAC,EAAE,CAAC,GACf,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAC9B,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,oBAAoB,GAAG,yBAAyB,EACzF,IAAI,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,EAC3B,OAAO,EAAE,iBAAiB,EAC1B,YAAY,CAAC,EAAE,CAAC,GACf,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -2,24 +2,32 @@ import { isJobName } from '../../application/scheduling/is-job-name.js';
|
|
|
2
2
|
import { DeclarationError } from '../registry/declaration-error.js';
|
|
3
3
|
import { record } from '../registry/record.js';
|
|
4
4
|
import { pendingApplications } from './pending-applications.js';
|
|
5
|
-
|
|
6
|
-
* A projector: the class that keeps one read model up to date, each of its `@On` methods
|
|
7
|
-
* applying one event through a port of its own read model:
|
|
8
|
-
* `@Projection('scheduling.appointment-list')`. The name is the consumer
|
|
9
|
-
* it is subscribed as: stable, `<context>.<name>`, unique in the application.
|
|
10
|
-
*/
|
|
11
|
-
export function Projection(name, dependencies) {
|
|
5
|
+
export function Projection(name, second, third) {
|
|
12
6
|
if (!isJobName(name)) {
|
|
13
7
|
throw new DeclarationError(`"${name}" is not a projection name: write <context>.<name> in lower case, words separated by dashes, as in 'scheduling.appointment-list'.`);
|
|
14
8
|
}
|
|
9
|
+
const options = isOptions(second) ? second : undefined;
|
|
10
|
+
const dependencies = isOptions(second) ? third : second;
|
|
11
|
+
const feed = options?.feed ?? 'dispatch';
|
|
15
12
|
return (target) => {
|
|
16
13
|
const applies = claimed(target);
|
|
17
14
|
if (applies.length === 0) {
|
|
18
15
|
throw new DeclarationError(`Projection ${target.name} applies no event: write @On(...) on the methods that do.`);
|
|
19
16
|
}
|
|
20
|
-
|
|
17
|
+
assertFedBy(feed, target, applies);
|
|
18
|
+
record(target, { role: 'projection', name, implementation: target, dependencies, feed, applies });
|
|
21
19
|
};
|
|
22
20
|
}
|
|
21
|
+
function isOptions(value) {
|
|
22
|
+
return typeof value === 'object' && 'feed' in value;
|
|
23
|
+
}
|
|
24
|
+
/** A projection fed by the event store applies the domain events of its context, nothing else. */
|
|
25
|
+
function assertFedBy(feed, target, applies) {
|
|
26
|
+
const integration = applies.find((application) => application.kind === 'integration');
|
|
27
|
+
if (feed === 'event-store' && integration !== undefined) {
|
|
28
|
+
throw new DeclarationError(`Projection ${target.name} is fed by the event store and applies the integration event of its method "${integration.method}": an integration event reaches a projection fed where it is consumed.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
23
31
|
/** The `@On` of the methods of the class: they ran just before its `@Projection`. */
|
|
24
32
|
function claimed(target) {
|
|
25
33
|
const pending = pendingApplications().splice(0);
|