@ddd-ts-kit/kernel 0.110.1 → 0.112.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 +81 -17
- package/README.md +76 -13
- package/dist/application/criteria/filter-operator.d.ts +1 -1
- package/dist/application/criteria/filter-operator.d.ts.map +1 -1
- package/dist/application/criteria/filter-violations.d.ts.map +1 -1
- package/dist/application/criteria/filter-violations.js +4 -3
- package/dist/application/criteria/filter-violations.js.map +1 -1
- package/dist/application/criteria/finds-text.d.ts +4 -0
- package/dist/application/criteria/finds-text.d.ts.map +1 -0
- package/dist/application/criteria/finds-text.js +12 -0
- package/dist/application/criteria/finds-text.js.map +1 -0
- package/dist/application/criteria/fold-case.d.ts +14 -0
- package/dist/application/criteria/fold-case.d.ts.map +1 -0
- package/dist/application/criteria/fold-case.js +16 -0
- package/dist/application/criteria/fold-case.js.map +1 -0
- package/dist/application/criteria/holds.d.ts.map +1 -1
- package/dist/application/criteria/holds.js +5 -4
- package/dist/application/criteria/holds.js.map +1 -1
- package/dist/application/criteria/index.d.ts +3 -0
- package/dist/application/criteria/index.d.ts.map +1 -1
- package/dist/application/criteria/index.js +3 -0
- package/dist/application/criteria/index.js.map +1 -1
- package/dist/application/criteria/is-text-search.d.ts +5 -0
- package/dist/application/criteria/is-text-search.d.ts.map +1 -0
- package/dist/application/criteria/is-text-search.js +11 -0
- package/dist/application/criteria/is-text-search.js.map +1 -0
- package/dist/application/criteria/operand-of.d.ts +2 -1
- package/dist/application/criteria/operand-of.d.ts.map +1 -1
- package/dist/application/criteria/operator-of.d.ts +2 -1
- package/dist/application/criteria/operator-of.d.ts.map +1 -1
- package/dist/application/criteria/operators-of-type.js +1 -1
- package/dist/application/criteria/operators-of-type.js.map +1 -1
- package/dist/application/criteria/text-search.d.ts +3 -0
- package/dist/application/criteria/text-search.d.ts.map +1 -0
- package/dist/application/criteria/text-search.js +2 -0
- package/dist/application/criteria/text-search.js.map +1 -0
- package/dist/application/files/content-expectation.d.ts +6 -0
- package/dist/application/files/content-expectation.d.ts.map +1 -1
- package/dist/application/files/content-matches.d.ts +12 -3
- package/dist/application/files/content-matches.d.ts.map +1 -1
- package/dist/application/files/content-matches.js +23 -28
- package/dist/application/files/content-matches.js.map +1 -1
- package/dist/application/files/content-rule-defects.d.ts +9 -0
- package/dist/application/files/content-rule-defects.d.ts.map +1 -0
- package/dist/application/files/content-rule-defects.js +57 -0
- package/dist/application/files/content-rule-defects.js.map +1 -0
- package/dist/application/files/content-rule-of.d.ts +11 -0
- package/dist/application/files/content-rule-of.d.ts.map +1 -0
- package/dist/application/files/content-rule-of.js +28 -0
- package/dist/application/files/content-rule-of.js.map +1 -0
- package/dist/application/files/content-rule.d.ts +4 -0
- package/dist/application/files/content-rule.d.ts.map +1 -0
- package/dist/application/files/content-rule.js +2 -0
- package/dist/application/files/content-rule.js.map +1 -0
- package/dist/application/files/content-rules.d.ts +4 -0
- package/dist/application/files/content-rules.d.ts.map +1 -0
- package/dist/application/files/content-rules.js +2 -0
- package/dist/application/files/content-rules.js.map +1 -0
- package/dist/application/files/index.d.ts +10 -0
- package/dist/application/files/index.d.ts.map +1 -1
- package/dist/application/files/index.js +10 -0
- package/dist/application/files/index.js.map +1 -1
- package/dist/application/files/is-utf8.d.ts +8 -0
- package/dist/application/files/is-utf8.d.ts.map +1 -0
- package/dist/application/files/is-utf8.js +16 -0
- package/dist/application/files/is-utf8.js.map +1 -0
- package/dist/application/files/looks-like-text.d.ts +8 -0
- package/dist/application/files/looks-like-text.d.ts.map +1 -0
- package/dist/application/files/looks-like-text.js +28 -0
- package/dist/application/files/looks-like-text.js.map +1 -0
- package/dist/application/files/named-only-media-types.d.ts +6 -0
- package/dist/application/files/named-only-media-types.d.ts.map +1 -0
- package/dist/application/files/named-only-media-types.js +12 -0
- package/dist/application/files/named-only-media-types.js.map +1 -0
- package/dist/application/files/signed-media-types.d.ts +3 -0
- package/dist/application/files/signed-media-types.d.ts.map +1 -0
- package/dist/application/files/signed-media-types.js +13 -0
- package/dist/application/files/signed-media-types.js.map +1 -0
- package/dist/application/files/stated-content-rule.d.ts +7 -0
- package/dist/application/files/stated-content-rule.d.ts.map +1 -0
- package/dist/application/files/stated-content-rule.js +2 -0
- package/dist/application/files/stated-content-rule.js.map +1 -0
- package/dist/application/files/text-media-types.d.ts +3 -0
- package/dist/application/files/text-media-types.d.ts.map +1 -0
- package/dist/application/files/text-media-types.js +10 -0
- package/dist/application/files/text-media-types.js.map +1 -0
- package/dist/application/files/text-rule.d.ts +17 -0
- package/dist/application/files/text-rule.d.ts.map +1 -0
- package/dist/application/files/text-rule.js +2 -0
- package/dist/application/files/text-rule.js.map +1 -0
- package/dist/application/files/zip-containers.d.ts +3 -0
- package/dist/application/files/zip-containers.d.ts.map +1 -0
- package/dist/application/files/zip-containers.js +10 -0
- package/dist/application/files/zip-containers.js.map +1 -0
- package/dist/application/persistence/advisory-lock-options.d.ts +10 -0
- package/dist/application/persistence/advisory-lock-options.d.ts.map +1 -0
- package/dist/application/persistence/advisory-lock-options.js +2 -0
- package/dist/application/persistence/advisory-lock-options.js.map +1 -0
- package/dist/application/ports/read-model-rows.d.ts +8 -2
- package/dist/application/ports/read-model-rows.d.ts.map +1 -1
- package/dist/application/ports/read-model-rows.js.map +1 -1
- package/dist/application/ports/read-model-store.d.ts +29 -3
- package/dist/application/ports/read-model-store.d.ts.map +1 -1
- package/dist/application/ports/read-model-store.js +8 -1
- package/dist/application/ports/read-model-store.js.map +1 -1
- package/dist/application/ports/read-model-table.d.ts +7 -0
- package/dist/application/ports/read-model-table.d.ts.map +1 -1
- package/dist/application/ports/read-model-table.js.map +1 -1
- package/dist/application/read-model/event-stamp.d.ts +4 -2
- package/dist/application/read-model/event-stamp.d.ts.map +1 -1
- package/dist/application/read-model/is-newer.d.ts +8 -1
- package/dist/application/read-model/is-newer.d.ts.map +1 -1
- package/dist/application/read-model/is-newer.js +8 -1
- package/dist/application/read-model/is-newer.js.map +1 -1
- package/dist/application/read-model/read-model-table-state.d.ts +53 -0
- package/dist/application/read-model/read-model-table-state.d.ts.map +1 -0
- package/dist/application/read-model/read-model-table-state.js +2 -0
- package/dist/application/read-model/read-model-table-state.js.map +1 -0
- package/dist/application/read-model/read-model-write.d.ts +9 -4
- package/dist/application/read-model/read-model-write.d.ts.map +1 -1
- package/dist/application/read-model/same-stamp.d.ts +8 -0
- package/dist/application/read-model/same-stamp.d.ts.map +1 -0
- package/dist/application/read-model/same-stamp.js +11 -0
- package/dist/application/read-model/same-stamp.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts +2 -1
- package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts.map +1 -1
- package/dist/infrastructure/event-sourcing/stored-stamp-of.js +2 -1
- package/dist/infrastructure/event-sourcing/stored-stamp-of.js.map +1 -1
- package/dist/infrastructure/files/file-inspection.js +1 -1
- package/dist/infrastructure/files/file-inspection.js.map +1 -1
- package/dist/infrastructure/files/file-staging.d.ts +4 -2
- package/dist/infrastructure/files/file-staging.d.ts.map +1 -1
- package/dist/infrastructure/files/file-staging.js +14 -6
- package/dist/infrastructure/files/file-staging.js.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-read-model-table.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-read-model-table.js +2 -6
- package/dist/infrastructure/in-memory/in-memory-read-model-table.js.map +1 -1
- package/dist/infrastructure/persistence/advisory-lock-key.d.ts +16 -0
- package/dist/infrastructure/persistence/advisory-lock-key.d.ts.map +1 -0
- package/dist/infrastructure/persistence/advisory-lock-key.js +18 -0
- package/dist/infrastructure/persistence/advisory-lock-key.js.map +1 -0
- package/dist/infrastructure/persistence/advisory-lock-outside-unit-of-work-error.d.ts +9 -0
- package/dist/infrastructure/persistence/advisory-lock-outside-unit-of-work-error.d.ts.map +1 -0
- package/dist/infrastructure/persistence/advisory-lock-outside-unit-of-work-error.js +12 -0
- package/dist/infrastructure/persistence/advisory-lock-outside-unit-of-work-error.js.map +1 -0
- package/dist/infrastructure/read-model/database-failure.d.ts +19 -0
- package/dist/infrastructure/read-model/database-failure.d.ts.map +1 -0
- package/dist/infrastructure/read-model/database-failure.js +71 -0
- package/dist/infrastructure/read-model/database-failure.js.map +1 -0
- package/dist/infrastructure/read-model/live-rows-columns-of.d.ts +7 -0
- package/dist/infrastructure/read-model/live-rows-columns-of.d.ts.map +1 -0
- package/dist/infrastructure/read-model/live-rows-columns-of.js +20 -0
- package/dist/infrastructure/read-model/live-rows-columns-of.js.map +1 -0
- package/dist/infrastructure/read-model/live-rows-constraint-form.d.ts +11 -0
- package/dist/infrastructure/read-model/live-rows-constraint-form.d.ts.map +1 -0
- package/dist/infrastructure/read-model/live-rows-constraint-form.js +13 -0
- package/dist/infrastructure/read-model/live-rows-constraint-form.js.map +1 -0
- package/dist/infrastructure/read-model/live-rows-constraint-of.d.ts +6 -0
- package/dist/infrastructure/read-model/live-rows-constraint-of.d.ts.map +1 -0
- package/dist/infrastructure/read-model/live-rows-constraint-of.js +18 -0
- package/dist/infrastructure/read-model/live-rows-constraint-of.js.map +1 -0
- package/dist/infrastructure/read-model/postgres-trace-columns.d.ts +34 -0
- package/dist/infrastructure/read-model/postgres-trace-columns.d.ts.map +1 -0
- package/dist/infrastructure/read-model/postgres-trace-columns.js +124 -0
- package/dist/infrastructure/read-model/postgres-trace-columns.js.map +1 -0
- package/dist/infrastructure/read-model/projection-rebuild.d.ts +4 -1
- package/dist/infrastructure/read-model/projection-rebuild.d.ts.map +1 -1
- package/dist/infrastructure/read-model/projection-rebuild.js +4 -1
- package/dist/infrastructure/read-model/projection-rebuild.js.map +1 -1
- package/dist/infrastructure/read-model/read-model-key-held-elsewhere-error.d.ts +12 -0
- package/dist/infrastructure/read-model/read-model-key-held-elsewhere-error.d.ts.map +1 -0
- package/dist/infrastructure/read-model/read-model-key-held-elsewhere-error.js +16 -0
- package/dist/infrastructure/read-model/read-model-key-held-elsewhere-error.js.map +1 -0
- package/dist/infrastructure/read-model/read-model-table-migration.d.ts +31 -0
- package/dist/infrastructure/read-model/read-model-table-migration.d.ts.map +1 -0
- package/dist/infrastructure/read-model/read-model-table-migration.js +82 -0
- package/dist/infrastructure/read-model/read-model-table-migration.js.map +1 -0
- package/dist/infrastructure/read-model/read-model-table-not-ready-error.d.ts +28 -0
- package/dist/infrastructure/read-model/read-model-table-not-ready-error.d.ts.map +1 -0
- package/dist/infrastructure/read-model/read-model-table-not-ready-error.js +132 -0
- package/dist/infrastructure/read-model/read-model-table-not-ready-error.js.map +1 -0
- package/dist/infrastructure/read-model/read-model-table-notes.d.ts +9 -0
- package/dist/infrastructure/read-model/read-model-table-notes.d.ts.map +1 -0
- package/dist/infrastructure/read-model/read-model-table-notes.js +36 -0
- package/dist/infrastructure/read-model/read-model-table-notes.js.map +1 -0
- package/dist/infrastructure/read-model/read-model-table-ready.d.ts +4 -0
- package/dist/infrastructure/read-model/read-model-table-ready.d.ts.map +1 -0
- package/dist/infrastructure/read-model/read-model-table-ready.js +5 -0
- package/dist/infrastructure/read-model/read-model-table-ready.js.map +1 -0
- package/dist/infrastructure/read-model/read-model-tables-not-ready-error.d.ts +24 -0
- package/dist/infrastructure/read-model/read-model-tables-not-ready-error.d.ts.map +1 -0
- package/dist/infrastructure/read-model/read-model-tables-not-ready-error.js +40 -0
- package/dist/infrastructure/read-model/read-model-tables-not-ready-error.js.map +1 -0
- package/dist/infrastructure/read-model/read-model-tables.d.ts +82 -0
- package/dist/infrastructure/read-model/read-model-tables.d.ts.map +1 -0
- package/dist/infrastructure/read-model/read-model-tables.js +161 -0
- package/dist/infrastructure/read-model/read-model-tables.js.map +1 -0
- package/dist/infrastructure/read-model/shadow-read-model-store.d.ts +1 -0
- package/dist/infrastructure/read-model/shadow-read-model-store.d.ts.map +1 -1
- package/dist/infrastructure/read-model/shadow-read-model-store.js +3 -0
- package/dist/infrastructure/read-model/shadow-read-model-store.js.map +1 -1
- package/dist/infrastructure/read-model/table-read-model-store.d.ts +8 -0
- package/dist/infrastructure/read-model/table-read-model-store.d.ts.map +1 -1
- package/dist/infrastructure/read-model/table-read-model-store.js +11 -0
- package/dist/infrastructure/read-model/table-read-model-store.js.map +1 -1
- package/dist/infrastructure/read-model/write-if-newer.d.ts +14 -2
- package/dist/infrastructure/read-model/write-if-newer.d.ts.map +1 -1
- package/dist/infrastructure/read-model/write-if-newer.js +35 -5
- package/dist/infrastructure/read-model/write-if-newer.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ReadModelTableNotReadyError } from './read-model-table-not-ready-error.js';
|
|
2
|
+
import type { ReadModelTableState } from '../../application/read-model/read-model-table-state.js';
|
|
3
|
+
/** A listed read model whose table could not be read: its store could not be built, or the database refused the reading. */
|
|
4
|
+
interface UnreadReadModel {
|
|
5
|
+
/** The name the list gives the read model: the class of its store. */
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly cause: unknown;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Read model tables the application lists cannot hold the trace of a deleted row, or could not be
|
|
11
|
+
* read: every one of them, in one error, each table with what keeps it from it and the migration
|
|
12
|
+
* to write, each unread one under its name with what failed, in a few words: the message of the
|
|
13
|
+
* driver, never the statement an ORM wraps it in. Raised when the tables are checked
|
|
14
|
+
* in one pass, at the start of an application or before a deployment, where
|
|
15
|
+
* `ReadModelTableNotReadyError` is the refusal of one store before its first trace. Each entry of
|
|
16
|
+
* `tables` is that very refusal: the verdict and the migration are the ones the store would give.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ReadModelTablesNotReadyError extends Error {
|
|
19
|
+
readonly unread: readonly UnreadReadModel[];
|
|
20
|
+
readonly tables: readonly ReadModelTableNotReadyError[];
|
|
21
|
+
constructor(unready: readonly ReadModelTableState[], unread?: readonly UnreadReadModel[]);
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=read-model-tables-not-ready-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-model-tables-not-ready-error.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/read-model-tables-not-ready-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAE/F,4HAA4H;AAC5H,UAAU,eAAe;IACvB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IAKnD,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE;IAJ7C,QAAQ,CAAC,MAAM,EAAE,SAAS,2BAA2B,EAAE,CAAC;IAExD,YACE,OAAO,EAAE,SAAS,mBAAmB,EAAE,EAC9B,MAAM,GAAE,SAAS,eAAe,EAAO,EAQjD;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { databaseFailure } from './database-failure.js';
|
|
2
|
+
import { ReadModelTableNotReadyError } from './read-model-table-not-ready-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read model tables the application lists cannot hold the trace of a deleted row, or could not be
|
|
5
|
+
* read: every one of them, in one error, each table with what keeps it from it and the migration
|
|
6
|
+
* to write, each unread one under its name with what failed, in a few words: the message of the
|
|
7
|
+
* driver, never the statement an ORM wraps it in. Raised when the tables are checked
|
|
8
|
+
* in one pass, at the start of an application or before a deployment, where
|
|
9
|
+
* `ReadModelTableNotReadyError` is the refusal of one store before its first trace. Each entry of
|
|
10
|
+
* `tables` is that very refusal: the verdict and the migration are the ones the store would give.
|
|
11
|
+
*/
|
|
12
|
+
export class ReadModelTablesNotReadyError extends Error {
|
|
13
|
+
unread;
|
|
14
|
+
tables;
|
|
15
|
+
constructor(unready, unread = []) {
|
|
16
|
+
const tables = unready.map((table) => new ReadModelTableNotReadyError(table));
|
|
17
|
+
super([...notReady(tables), ...notRead(unread), ...tables.map(({ message }) => message)].join('\n\n'));
|
|
18
|
+
this.unread = unread;
|
|
19
|
+
this.name = 'ReadModelTablesNotReadyError';
|
|
20
|
+
this.tables = tables;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function notReady(tables) {
|
|
24
|
+
if (tables.length === 0) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const counted = tables.length === 1 ? '1 read model table is' : `${String(tables.length)} read model tables are`;
|
|
28
|
+
return [
|
|
29
|
+
`${counted} not ready for this version: ${tables.map(({ table }) => table).join(', ')}. Apply the migrations of the project before the application starts; a table they leave as it is takes the migration written under its name.`,
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
function notRead(unread) {
|
|
33
|
+
if (unread.length === 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const counted = unread.length === 1 ? 'The table of 1 read model' : `The tables of ${String(unread.length)} read models`;
|
|
37
|
+
const each = unread.map(({ name, cause }) => `${name} (${databaseFailure(cause).cause})`);
|
|
38
|
+
return [`${counted} could not be read, so nothing says whether a trace is taken: ${each.join('; ')}.`];
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=read-model-tables-not-ready-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-model-tables-not-ready-error.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/read-model-tables-not-ready-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAUjF;;;;;;;;GAQG;AACH,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IAK1C,MAAM;IAJR,MAAM,CAAyC;IAExD,YACE,OAAuC,EAC9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,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,eAAe,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;IAE1F,OAAO,CAAC,GAAG,OAAO,iEAAiE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzG,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Logger } from '../../application/ports/logger.js';
|
|
2
|
+
import type { ReadModelTableState } from '../../application/read-model/read-model-table-state.js';
|
|
3
|
+
/** A read model as an application lists it: its store, or the table under it, which reads what that table can hold. */
|
|
4
|
+
export interface ReadModelInATable {
|
|
5
|
+
/** Absent, or `undefined`, where the rows are not kept in a table: such a read model has nothing to check. */
|
|
6
|
+
tableState?(): Promise<ReadModelTableState | undefined>;
|
|
7
|
+
}
|
|
8
|
+
/** One entry of the list: the name a failure is told under, and how the store is built, as the application binds it. */
|
|
9
|
+
export interface ListedReadModel {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** The bounded context the read model belongs to, when the application hosts several: what `hosting` selects by. */
|
|
12
|
+
readonly context?: string;
|
|
13
|
+
build(): ReadModelInATable;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* What an application does at its start with the listed tables that are not ready or could not
|
|
17
|
+
* be read: `required` refuses to start, `reported` logs them as one error and starts, for a
|
|
18
|
+
* deployment that starts the application before its migrations ran.
|
|
19
|
+
*/
|
|
20
|
+
export type ReadModelTablesAtStart = 'required' | 'reported';
|
|
21
|
+
/** What a check of the listed tables found, as a command says it. */
|
|
22
|
+
export interface ReadModelTablesReport {
|
|
23
|
+
readonly ready: boolean;
|
|
24
|
+
/** `unread` when no listed table could be read and one failed: the database does not answer, or refuses the reading. */
|
|
25
|
+
readonly outcome: 'ready' | 'not-ready' | 'unread';
|
|
26
|
+
readonly text: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The read model tables an application declares, checked in one pass before a request or an
|
|
30
|
+
* event reaches a store, whenever the stores themselves are built. Each entry builds the store of
|
|
31
|
+
* one read model, the class the application binds, with its own options: the table is then read
|
|
32
|
+
* by the code that store runs before its first trace, so the verdict is the store's and the
|
|
33
|
+
* migration names its columns. Every entry is tried: a store whose definition refuses its table
|
|
34
|
+
* is reported like the others, and one that cannot be built or read (a role without the right to
|
|
35
|
+
* read its schema) is told under its name with what failed, the others still read. Nothing is
|
|
36
|
+
* guessed from the database: a table that is not listed is not read, and an empty list checks
|
|
37
|
+
* nothing. `unlisted` names the read model stores the application knows it does not list: they
|
|
38
|
+
* are told as a warning, since nothing checks them. A database that cannot be reached (a refused
|
|
39
|
+
* connection, a host that is not found, a timeout) is no answer about a table: the reading stops
|
|
40
|
+
* there, a start goes on with one warning, since it never depended on the database being up, and
|
|
41
|
+
* a command says the database could not be read.
|
|
42
|
+
*/
|
|
43
|
+
export declare class ReadModelTables {
|
|
44
|
+
private readonly listed;
|
|
45
|
+
private readonly unlisted;
|
|
46
|
+
constructor(listed: readonly ListedReadModel[], unlisted?: readonly string[]);
|
|
47
|
+
/** The contexts the entries belong to, each once, in the order of the list: what a command names when it is asked for one the list does not hold. */
|
|
48
|
+
get contexts(): readonly string[];
|
|
49
|
+
/**
|
|
50
|
+
* The entries of these contexts alone, for an application that hosts some of them; every entry
|
|
51
|
+
* when none is named. A name no entry carries selects nothing, which is right for a root (a
|
|
52
|
+
* context may keep no read model) and wrong for a command: it compares the name with `contexts`.
|
|
53
|
+
*/
|
|
54
|
+
hosting(contexts?: readonly string[]): ReadModelTables;
|
|
55
|
+
/** What each listed table that could be read can hold, in the order of the list. */
|
|
56
|
+
states(): Promise<readonly ReadModelTableState[]>;
|
|
57
|
+
/** The listed tables that cannot hold the trace of a deleted row, every one of them. */
|
|
58
|
+
notReady(): Promise<readonly ReadModelTableState[]>;
|
|
59
|
+
/** Refuses with `ReadModelTablesNotReadyError`, which names every listed table that is not ready, with its migration, and every one that could not be read. */
|
|
60
|
+
require(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* The check an application makes when it starts. `required`, the default, refuses to start;
|
|
63
|
+
* `reported` writes the same message as an error and lets the start go on: each store still
|
|
64
|
+
* refuses by name before its first trace. What the check cannot decide is a warning either
|
|
65
|
+
* way: a check constraint that is not validated or that checks something else, another check
|
|
66
|
+
* on a column of the row, a view, a store nobody lists. A database that could not be reached
|
|
67
|
+
* is one warning too, with its cause in a few words, and never a refusal: the check tells the
|
|
68
|
+
* tables that are not ready, it does not make the start wait for the database.
|
|
69
|
+
*/
|
|
70
|
+
atStart(logger: Logger, unready?: ReadModelTablesAtStart): Promise<void>;
|
|
71
|
+
/** The same check as a command prints it: how many tables it read and their names, the warnings, then every refusal. */
|
|
72
|
+
report(): Promise<ReadModelTablesReport>;
|
|
73
|
+
private nothingRead;
|
|
74
|
+
/**
|
|
75
|
+
* Every entry is tried, in the order of the list: one that fails does not hide the next. The
|
|
76
|
+
* reading stops at the first one that finds the database unreachable: the next would wait for
|
|
77
|
+
* the same refusal.
|
|
78
|
+
*/
|
|
79
|
+
private read;
|
|
80
|
+
private notes;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=read-model-tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-model-tables.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/read-model-tables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAK7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAG/F,uHAAuH;AACvH,MAAM,WAAW,iBAAiB;IAChC,8GAA8G;IAC9G,UAAU,CAAC,IAAI,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAAC;CACzD;AAED,wHAAwH;AACxH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAA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lB,OAAO,CAAC,KAAK;CAUd"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { databaseFailure } from './database-failure.js';
|
|
2
|
+
import { ReadModelTableNotReadyError } from './read-model-table-not-ready-error.js';
|
|
3
|
+
import { readModelTableNotes } from './read-model-table-notes.js';
|
|
4
|
+
import { readModelTableReady } from './read-model-table-ready.js';
|
|
5
|
+
import { ReadModelTablesNotReadyError } from './read-model-tables-not-ready-error.js';
|
|
6
|
+
/**
|
|
7
|
+
* The read model tables an application declares, checked in one pass before a request or an
|
|
8
|
+
* event reaches a store, whenever the stores themselves are built. Each entry builds the store of
|
|
9
|
+
* one read model, the class the application binds, with its own options: the table is then read
|
|
10
|
+
* by the code that store runs before its first trace, so the verdict is the store's and the
|
|
11
|
+
* migration names its columns. Every entry is tried: a store whose definition refuses its table
|
|
12
|
+
* is reported like the others, and one that cannot be built or read (a role without the right to
|
|
13
|
+
* read its schema) is told under its name with what failed, the others still read. Nothing is
|
|
14
|
+
* guessed from the database: a table that is not listed is not read, and an empty list checks
|
|
15
|
+
* nothing. `unlisted` names the read model stores the application knows it does not list: they
|
|
16
|
+
* are told as a warning, since nothing checks them. A database that cannot be reached (a refused
|
|
17
|
+
* connection, a host that is not found, a timeout) is no answer about a table: the reading stops
|
|
18
|
+
* there, a start goes on with one warning, since it never depended on the database being up, and
|
|
19
|
+
* a command says the database could not be read.
|
|
20
|
+
*/
|
|
21
|
+
export class ReadModelTables {
|
|
22
|
+
listed;
|
|
23
|
+
unlisted;
|
|
24
|
+
constructor(listed, unlisted = []) {
|
|
25
|
+
this.listed = listed;
|
|
26
|
+
this.unlisted = unlisted;
|
|
27
|
+
}
|
|
28
|
+
/** The contexts the entries belong to, each once, in the order of the list: what a command names when it is asked for one the list does not hold. */
|
|
29
|
+
get contexts() {
|
|
30
|
+
return [...new Set(this.listed.flatMap(({ context }) => (context === undefined ? [] : [context])))];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The entries of these contexts alone, for an application that hosts some of them; every entry
|
|
34
|
+
* when none is named. A name no entry carries selects nothing, which is right for a root (a
|
|
35
|
+
* context may keep no read model) and wrong for a command: it compares the name with `contexts`.
|
|
36
|
+
*/
|
|
37
|
+
hosting(contexts) {
|
|
38
|
+
return contexts === undefined
|
|
39
|
+
? this
|
|
40
|
+
: new ReadModelTables(this.listed.filter(({ context }) => context !== undefined && contexts.includes(context)), this.unlisted);
|
|
41
|
+
}
|
|
42
|
+
/** What each listed table that could be read can hold, in the order of the list. */
|
|
43
|
+
async states() {
|
|
44
|
+
return (await this.read()).states;
|
|
45
|
+
}
|
|
46
|
+
/** The listed tables that cannot hold the trace of a deleted row, every one of them. */
|
|
47
|
+
async notReady() {
|
|
48
|
+
return (await this.states()).filter((state) => !readModelTableReady(state));
|
|
49
|
+
}
|
|
50
|
+
/** Refuses with `ReadModelTablesNotReadyError`, which names every listed table that is not ready, with its migration, and every one that could not be read. */
|
|
51
|
+
async require() {
|
|
52
|
+
const refusal = refusalOf(await this.read(), 'strict');
|
|
53
|
+
if (refusal !== undefined) {
|
|
54
|
+
throw refusal;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The check an application makes when it starts. `required`, the default, refuses to start;
|
|
59
|
+
* `reported` writes the same message as an error and lets the start go on: each store still
|
|
60
|
+
* refuses by name before its first trace. What the check cannot decide is a warning either
|
|
61
|
+
* way: a check constraint that is not validated or that checks something else, another check
|
|
62
|
+
* on a column of the row, a view, a store nobody lists. A database that could not be reached
|
|
63
|
+
* is one warning too, with its cause in a few words, and never a refusal: the check tells the
|
|
64
|
+
* tables that are not ready, it does not make the start wait for the database.
|
|
65
|
+
*/
|
|
66
|
+
async atStart(logger, unready = 'required') {
|
|
67
|
+
const reading = await this.read();
|
|
68
|
+
const refusal = refusalOf(reading);
|
|
69
|
+
for (const note of [...unreachedNote(reading), ...this.notes(reading)]) {
|
|
70
|
+
logger.warn(note);
|
|
71
|
+
}
|
|
72
|
+
if (refusal === undefined) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (unready === 'required') {
|
|
76
|
+
throw refusal;
|
|
77
|
+
}
|
|
78
|
+
logger.error(refusal.message, {
|
|
79
|
+
tables: refusal.tables.map(({ table }) => table).join(', '),
|
|
80
|
+
unread: refusal.unread.map(({ name }) => name).join(', '),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** The same check as a command prints it: how many tables it read and their names, the warnings, then every refusal. */
|
|
84
|
+
async report() {
|
|
85
|
+
const reading = await this.read();
|
|
86
|
+
const refusal = refusalOf(reading, 'strict');
|
|
87
|
+
const { states } = reading;
|
|
88
|
+
const counted = states.length === 1 ? '1 read model table' : `${String(states.length)} read model tables`;
|
|
89
|
+
const lines = [
|
|
90
|
+
states.length === 0 ? this.nothingRead() : `Checked ${counted}: ${states.map(nameOf).join(', ')}.`,
|
|
91
|
+
...this.notes(reading),
|
|
92
|
+
...(refusal === undefined ? [] : ['', refusal.message]),
|
|
93
|
+
...(refusal === undefined && states.length > 0 ? ['Each can hold the trace of a deleted row.'] : []),
|
|
94
|
+
];
|
|
95
|
+
const unread = reading.unreached !== undefined || (states.length === 0 && reading.unread.length > 0);
|
|
96
|
+
return {
|
|
97
|
+
ready: refusal === undefined,
|
|
98
|
+
outcome: refusal === undefined ? 'ready' : unread ? 'unread' : 'not-ready',
|
|
99
|
+
text: lines.join('\n'),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
nothingRead() {
|
|
103
|
+
return this.listed.length === 0
|
|
104
|
+
? 'No read model table is listed: nothing was checked.'
|
|
105
|
+
: 'No listed read model keeps a table that could be read.';
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Every entry is tried, in the order of the list: one that fails does not hide the next. The
|
|
109
|
+
* reading stops at the first one that finds the database unreachable: the next would wait for
|
|
110
|
+
* the same refusal.
|
|
111
|
+
*/
|
|
112
|
+
async read() {
|
|
113
|
+
const states = [];
|
|
114
|
+
const unread = [];
|
|
115
|
+
for (const entry of this.listed) {
|
|
116
|
+
try {
|
|
117
|
+
states.push(...[await entry.build().tableState?.()].filter((state) => state !== undefined));
|
|
118
|
+
}
|
|
119
|
+
catch (cause) {
|
|
120
|
+
if (cause instanceof ReadModelTableNotReadyError) {
|
|
121
|
+
states.push(cause.state);
|
|
122
|
+
}
|
|
123
|
+
else if (databaseFailure(cause).unreachable) {
|
|
124
|
+
return { states, unread, unreached: { name: entry.name, cause } };
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
unread.push({ name: entry.name, cause });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { states, unread };
|
|
132
|
+
}
|
|
133
|
+
notes({ states }) {
|
|
134
|
+
return [
|
|
135
|
+
...states.flatMap(readModelTableNotes),
|
|
136
|
+
...(this.unlisted.length === 0
|
|
137
|
+
? []
|
|
138
|
+
: [
|
|
139
|
+
`Read model stores of the application are not listed, so nothing checks their tables: ${this.unlisted.join(', ')}. Add each to the list of the read model tables.`,
|
|
140
|
+
]),
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** The refusal of a reading; `strict`, for a command, a database that could not be reached is one too. */
|
|
145
|
+
function refusalOf(reading, strict) {
|
|
146
|
+
const refused = reading.states.filter((state) => !readModelTableReady(state));
|
|
147
|
+
const unreached = strict === undefined || reading.unreached === undefined ? [] : [reading.unreached];
|
|
148
|
+
const unread = [...reading.unread, ...unreached];
|
|
149
|
+
return refused.length + unread.length === 0 ? undefined : new ReadModelTablesNotReadyError(refused, unread);
|
|
150
|
+
}
|
|
151
|
+
function unreachedNote({ unreached }) {
|
|
152
|
+
return unreached === undefined
|
|
153
|
+
? []
|
|
154
|
+
: [
|
|
155
|
+
`The read model tables could not be checked: the database could not be reached (${databaseFailure(unreached.cause).cause}). The start goes on; each store still refuses a table that is not ready before its first trace.`,
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
function nameOf({ schema, table }) {
|
|
159
|
+
return schema === undefined ? table : `${schema}.${table}`;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=read-model-tables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-model-tables.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/read-model-tables.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AAwCnF;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,eAAe;IAEP,MAAM;IACN,QAAQ;IAF3B,YACmB,MAAkC,EAClC,QAAQ,GAAsB,EAAE;sBADhC,MAAM;wBACN,QAAQ;IACxB,CAAC;IAEJ,qJAAqJ;IACrJ,IAAI,QAAQ;QACV,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtG,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,QAA4B;QAClC,OAAO,QAAQ,KAAK,SAAS;YAC3B,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,eAAe,CACjB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,KAAK,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EACxF,IAAI,CAAC,QAAQ,CACd,CA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,CAAC,KAAK,CAAC,CAAC,KAAK,kGAAkG;SAC3N,CAAC;AACR,CAAC;AAED,SAAS,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAuB;IACpD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -14,6 +14,7 @@ export declare class ShadowReadModelStore<Row> implements ReadModelStore<Row> {
|
|
|
14
14
|
constructor(rows: ReadModelRows<Row>);
|
|
15
15
|
get(key: string): Promise<Row | undefined>;
|
|
16
16
|
upsertIfNewer(key: string, stamp: EventStamp, next: (current: Row | undefined) => Row | undefined): Promise<ReadModelWrite>;
|
|
17
|
+
updateIfNewer(key: string, stamp: EventStamp, change: (current: Row) => Row): Promise<ReadModelWrite>;
|
|
17
18
|
delete(key: string, stamp: EventStamp): Promise<ReadModelWrite>;
|
|
18
19
|
search(criteria: ScopedCriteria<Row>): Promise<Page<Row>>;
|
|
19
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadow-read-model-store.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/shadow-read-model-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAGpF;;;;GAIG;AACH,qBAAa,oBAAoB,CAAC,GAAG,CAAE,YAAW,cAAc,CAAC,GAAG,CAAC;IACvD,OAAO,CAAC,QAAQ,CA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,SAAS,CAAC,CAE/C;IAED,aAAa,CACX,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,GAAG,SAAS,KAAK,GAAG,GAAG,SAAS,GAClD,OAAO,CAAC,cAAc,CAAC,CAEzB;IAED,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC,CAEpG;IAED,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAE9D;IAED,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAExD;CACF"}
|
|
@@ -15,6 +15,9 @@ export class ShadowReadModelStore {
|
|
|
15
15
|
upsertIfNewer(key, stamp, next) {
|
|
16
16
|
return writeIfNewer(this.rows, { key, stamp, next });
|
|
17
17
|
}
|
|
18
|
+
updateIfNewer(key, stamp, change) {
|
|
19
|
+
return writeIfNewer(this.rows, { key, stamp, change });
|
|
20
|
+
}
|
|
18
21
|
delete(key, stamp) {
|
|
19
22
|
return writeIfNewer(this.rows, { key, stamp });
|
|
20
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadow-read-model-store.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/shadow-read-model-store.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IACF,IAAI;IAAjC,YAA6B,IAAwB;oBAAxB,IAAI;IAAuB,CAAC;IAEzD,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;IAC1C,CAAC;IAED,aAAa,CACX,GAAW,EACX,KAAiB,EACjB,IAAmD;QAEnD,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,CAAC,GAAW,EAAE,KAAiB;QACnC,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,QAA6B;QAClC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAC,CAAC;IAC5G,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"shadow-read-model-store.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/shadow-read-model-store.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IACF,IAAI;IAAjC,YAA6B,IAAwB;oBAAxB,IAAI;IAAuB,CAAC;IAEzD,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;IAC1C,CAAC;IAED,aAAa,CACX,GAAW,EACX,KAAiB,EACjB,IAAmD;QAEnD,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,aAAa,CAAC,GAAW,EAAE,KAAiB,EAAE,MAA6B;QACzE,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,CAAC,GAAW,EAAE,KAAiB;QACnC,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,QAA6B;QAClC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAC,CAAC;IAC5G,CAAC;CACF"}
|
|
@@ -4,6 +4,7 @@ import type { Page } from '../../application/pagination/page.js';
|
|
|
4
4
|
import type { ReadModelStore } from '../../application/ports/read-model-store.js';
|
|
5
5
|
import type { ReadModelTable } from '../../application/ports/read-model-table.js';
|
|
6
6
|
import type { EventStamp } from '../../application/read-model/event-stamp.js';
|
|
7
|
+
import type { ReadModelTableState } from '../../application/read-model/read-model-table-state.js';
|
|
7
8
|
import type { ReadModelWrite } from '../../application/read-model/read-model-write.js';
|
|
8
9
|
/**
|
|
9
10
|
* A `ReadModelStore` over the table an adapter gives: the same class in memory and on every
|
|
@@ -16,7 +17,14 @@ export declare class TableReadModelStore<Row extends object> implements ReadMode
|
|
|
16
17
|
constructor(table: ReadModelTable<Row>, definition: CriteriaDefinition<Row>);
|
|
17
18
|
get(key: string): Promise<Row | undefined>;
|
|
18
19
|
upsertIfNewer(key: string, stamp: EventStamp, next: (current: Row | undefined) => Row | undefined): Promise<ReadModelWrite>;
|
|
20
|
+
updateIfNewer(key: string, stamp: EventStamp, change: (current: Row) => Row): Promise<ReadModelWrite>;
|
|
19
21
|
delete(key: string, stamp: EventStamp): Promise<ReadModelWrite>;
|
|
22
|
+
/**
|
|
23
|
+
* What the table of the read model can hold, read by the code the adapter runs before its first
|
|
24
|
+
* trace; `undefined` where the rows are not kept in a table (memory, a search engine). What
|
|
25
|
+
* `ReadModelTables` asks of each store an application lists.
|
|
26
|
+
*/
|
|
27
|
+
tableState(): Promise<ReadModelTableState | undefined>;
|
|
20
28
|
search(criteria: ScopedCriteria<Row>): Promise<Page<Row>>;
|
|
21
29
|
private written;
|
|
22
30
|
}
|
|
@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a,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC,CAEpG;IAED,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAE9D;IAED;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAE3D;IAEK,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAU9D;YAEa,OAAO;CAOtB"}
|
|
@@ -19,9 +19,20 @@ export class TableReadModelStore {
|
|
|
19
19
|
upsertIfNewer(key, stamp, next) {
|
|
20
20
|
return this.written({ key, stamp, next });
|
|
21
21
|
}
|
|
22
|
+
updateIfNewer(key, stamp, change) {
|
|
23
|
+
return this.written({ key, stamp, change });
|
|
24
|
+
}
|
|
22
25
|
delete(key, stamp) {
|
|
23
26
|
return this.written({ key, stamp });
|
|
24
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* What the table of the read model can hold, read by the code the adapter runs before its first
|
|
30
|
+
* trace; `undefined` where the rows are not kept in a table (memory, a search engine). What
|
|
31
|
+
* `ReadModelTables` asks of each store an application lists.
|
|
32
|
+
*/
|
|
33
|
+
async tableState() {
|
|
34
|
+
return this.table.tableState?.();
|
|
35
|
+
}
|
|
25
36
|
async search(criteria) {
|
|
26
37
|
const plan = planCriteria(this.definition, criteria);
|
|
27
38
|
if (plan.empty) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-read-model-store.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/table-read-model-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"table-read-model-store.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/table-read-model-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAQxE,OAAO,EAAE,YAAY,EAAsB,MAAM,kBAAkB,CAAC;AAEpE;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAEnB,KAAK;IACL,UAAU;IAFrB,YACW,KAA0B,EAC1B,UAAmC;qBADnC,KAAK;0BACL,UAAU;IAClB,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;IAC3C,CAAC;IAED,aAAa,CACX,GAAW,EACX,KAAiB,EACjB,IAAmD;QAEnD,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,aAAa,CAAC,GAAW,EAAE,KAAiB,EAAE,MAA6B;QACzE,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,GAAW,EAAE,KAAiB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,QAA6B;QACxC,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAErD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QACjC,CAAC;QAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEtD,OAAO,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,MAA0B;QAC9C,IAAI,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC;YAClC,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -4,14 +4,26 @@ import type { ReadModelWrite } from '../../application/read-model/read-model-wri
|
|
|
4
4
|
export interface StampedChange<Row> {
|
|
5
5
|
readonly key: string;
|
|
6
6
|
readonly stamp: EventStamp;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The row to write from the current one. Absent for a deletion, which is written even when the
|
|
9
|
+
* key is not held: the trace it leaves stops the older creation delivered after it.
|
|
10
|
+
*/
|
|
8
11
|
readonly next?: (current: Row | undefined) => Row | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The row to write from the one the key holds, for an event that changes a row and does not
|
|
14
|
+
* create it. Without a live row to hand it, nothing is written and the answer is `missing`.
|
|
15
|
+
*/
|
|
16
|
+
readonly change?: (current: Row) => Row;
|
|
9
17
|
}
|
|
10
18
|
/**
|
|
11
19
|
* "Apply if newer", once for every store. It reads the row, gives up when the row holds this
|
|
12
20
|
* event or a later one, and writes on the condition that the row still holds the stamp it
|
|
13
21
|
* read: a concurrent write makes it read again, so two events of one key never overwrite each
|
|
14
|
-
* other blindly, with or without a transaction.
|
|
22
|
+
* other blindly, with or without a transaction. A `change` that finds no live row, or the trace
|
|
23
|
+
* of a deletion older than its event, writes nothing and answers `missing`: a key another tenant
|
|
24
|
+
* holds reads as absent there too, since nothing of this tenant is there to change. A key that reads as absent, refuses an insert and
|
|
25
|
+
* still reads as absent is held out of the reach of this work, by another tenant: that is settled
|
|
26
|
+
* at once, since no further attempt would change it.
|
|
15
27
|
*/
|
|
16
28
|
export declare function writeIfNewer<Row>(rows: ReadModelRows<Row>, change: StampedChange<Row>): Promise<ReadModelWrite>;
|
|
17
29
|
//# sourceMappingURL=write-if-newer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-if-newer.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/write-if-newer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;
|
|
1
|
+
{"version":3,"file":"write-if-newer.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/write-if-newer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAKpF,MAAM,WAAW,aAAa,CAAC,GAAG;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,GAAG,SAAS,KAAK,GAAG,GAAG,SAAS,CAAC;IAC9D;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,GAAG,CAAC;CACzC;AAID;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CA4BrH"}
|
|
@@ -1,32 +1,62 @@
|
|
|
1
1
|
import { isNewer } from '../../application/read-model/is-newer.js';
|
|
2
2
|
import { ConcurrencyError } from '../../domain/errors/concurrency-error.js';
|
|
3
|
+
import { ReadModelKeyHeldElsewhereError } from './read-model-key-held-elsewhere-error.js';
|
|
3
4
|
const ATTEMPTS = 5;
|
|
4
5
|
/**
|
|
5
6
|
* "Apply if newer", once for every store. It reads the row, gives up when the row holds this
|
|
6
7
|
* event or a later one, and writes on the condition that the row still holds the stamp it
|
|
7
8
|
* read: a concurrent write makes it read again, so two events of one key never overwrite each
|
|
8
|
-
* other blindly, with or without a transaction.
|
|
9
|
+
* other blindly, with or without a transaction. A `change` that finds no live row, or the trace
|
|
10
|
+
* of a deletion older than its event, writes nothing and answers `missing`: a key another tenant
|
|
11
|
+
* holds reads as absent there too, since nothing of this tenant is there to change. A key that reads as absent, refuses an insert and
|
|
12
|
+
* still reads as absent is held out of the reach of this work, by another tenant: that is settled
|
|
13
|
+
* at once, since no further attempt would change it.
|
|
9
14
|
*/
|
|
10
15
|
export async function writeIfNewer(rows, change) {
|
|
16
|
+
let refused = false;
|
|
11
17
|
for (let attempt = 0; attempt < ATTEMPTS; attempt += 1) {
|
|
12
18
|
const held = await rows.find(change.key);
|
|
19
|
+
if (held === undefined && refused) {
|
|
20
|
+
return heldElsewhere(change);
|
|
21
|
+
}
|
|
13
22
|
if (held !== undefined && !isNewer(change.stamp, held.stamp)) {
|
|
14
23
|
return 'stale';
|
|
15
24
|
}
|
|
25
|
+
if (change.change !== undefined && held?.row === undefined) {
|
|
26
|
+
return 'missing';
|
|
27
|
+
}
|
|
16
28
|
const written = await attempted(rows, change, held);
|
|
17
29
|
if (written !== undefined) {
|
|
18
30
|
return written;
|
|
19
31
|
}
|
|
32
|
+
refused = held === undefined;
|
|
20
33
|
}
|
|
21
34
|
throw new ConcurrencyError(change.key);
|
|
22
35
|
}
|
|
36
|
+
/** Nothing of this tenant is there to delete, and its trace cannot be written; an upsert is refused by name. */
|
|
37
|
+
function heldElsewhere({ key, next }) {
|
|
38
|
+
if (next === undefined) {
|
|
39
|
+
return 'ignored';
|
|
40
|
+
}
|
|
41
|
+
throw new ReadModelKeyHeldElsewhereError(key);
|
|
42
|
+
}
|
|
23
43
|
/** `undefined` when another write got there first. */
|
|
24
|
-
async function attempted(rows,
|
|
25
|
-
const
|
|
26
|
-
|
|
44
|
+
async function attempted(rows, change, held) {
|
|
45
|
+
const { key, stamp } = change;
|
|
46
|
+
const deletion = change.next === undefined && change.change === undefined;
|
|
47
|
+
const row = rowOf(change, held);
|
|
48
|
+
if (row === undefined && !deletion) {
|
|
27
49
|
return 'ignored';
|
|
28
50
|
}
|
|
29
51
|
const done = held === undefined ? await rows.insert({ key, row, stamp }) : await rows.replace({ key, row, stamp }, held.stamp);
|
|
30
|
-
|
|
52
|
+
if (!done) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
// A deletion that found no live row removed nothing: it left, or moved forward, a trace.
|
|
56
|
+
return deletion && held?.row === undefined ? 'traced' : 'applied';
|
|
57
|
+
}
|
|
58
|
+
/** What the change writes: nothing for a deletion, or for a `next` that answers nothing. */
|
|
59
|
+
function rowOf({ next, change }, held) {
|
|
60
|
+
return change === undefined || held?.row === undefined ? next?.(held?.row) : change(held.row);
|
|
31
61
|
}
|
|
32
62
|
//# sourceMappingURL=write-if-newer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-if-newer.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/write-if-newer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,uCAAuC,CA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AI,EAAE,MAAM,EAAsB,EAAE,IAAiC;IACzF,OAAO,MAAM,KAAK,SAAS,IAAI,IAAI,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.112.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",
|