@ddd-ts-kit/kernel 0.111.0 → 0.113.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.fr.md +52 -3
  2. package/README.md +48 -1
  3. package/dist/application/files/content-expectation.d.ts +6 -0
  4. package/dist/application/files/content-expectation.d.ts.map +1 -1
  5. package/dist/application/files/content-matches.d.ts +12 -3
  6. package/dist/application/files/content-matches.d.ts.map +1 -1
  7. package/dist/application/files/content-matches.js +23 -28
  8. package/dist/application/files/content-matches.js.map +1 -1
  9. package/dist/application/files/content-rule-defects.d.ts +9 -0
  10. package/dist/application/files/content-rule-defects.d.ts.map +1 -0
  11. package/dist/application/files/content-rule-defects.js +57 -0
  12. package/dist/application/files/content-rule-defects.js.map +1 -0
  13. package/dist/application/files/content-rule-of.d.ts +11 -0
  14. package/dist/application/files/content-rule-of.d.ts.map +1 -0
  15. package/dist/application/files/content-rule-of.js +28 -0
  16. package/dist/application/files/content-rule-of.js.map +1 -0
  17. package/dist/application/files/content-rule.d.ts +4 -0
  18. package/dist/application/files/content-rule.d.ts.map +1 -0
  19. package/dist/application/files/content-rule.js +2 -0
  20. package/dist/application/files/content-rule.js.map +1 -0
  21. package/dist/application/files/content-rules.d.ts +4 -0
  22. package/dist/application/files/content-rules.d.ts.map +1 -0
  23. package/dist/application/files/content-rules.js +2 -0
  24. package/dist/application/files/content-rules.js.map +1 -0
  25. package/dist/application/files/index.d.ts +10 -0
  26. package/dist/application/files/index.d.ts.map +1 -1
  27. package/dist/application/files/index.js +10 -0
  28. package/dist/application/files/index.js.map +1 -1
  29. package/dist/application/files/is-utf8.d.ts +8 -0
  30. package/dist/application/files/is-utf8.d.ts.map +1 -0
  31. package/dist/application/files/is-utf8.js +16 -0
  32. package/dist/application/files/is-utf8.js.map +1 -0
  33. package/dist/application/files/looks-like-text.d.ts +8 -0
  34. package/dist/application/files/looks-like-text.d.ts.map +1 -0
  35. package/dist/application/files/looks-like-text.js +28 -0
  36. package/dist/application/files/looks-like-text.js.map +1 -0
  37. package/dist/application/files/named-only-media-types.d.ts +6 -0
  38. package/dist/application/files/named-only-media-types.d.ts.map +1 -0
  39. package/dist/application/files/named-only-media-types.js +12 -0
  40. package/dist/application/files/named-only-media-types.js.map +1 -0
  41. package/dist/application/files/signed-media-types.d.ts +3 -0
  42. package/dist/application/files/signed-media-types.d.ts.map +1 -0
  43. package/dist/application/files/signed-media-types.js +13 -0
  44. package/dist/application/files/signed-media-types.js.map +1 -0
  45. package/dist/application/files/stated-content-rule.d.ts +7 -0
  46. package/dist/application/files/stated-content-rule.d.ts.map +1 -0
  47. package/dist/application/files/stated-content-rule.js +2 -0
  48. package/dist/application/files/stated-content-rule.js.map +1 -0
  49. package/dist/application/files/text-media-types.d.ts +3 -0
  50. package/dist/application/files/text-media-types.d.ts.map +1 -0
  51. package/dist/application/files/text-media-types.js +10 -0
  52. package/dist/application/files/text-media-types.js.map +1 -0
  53. package/dist/application/files/text-rule.d.ts +17 -0
  54. package/dist/application/files/text-rule.d.ts.map +1 -0
  55. package/dist/application/files/text-rule.js +2 -0
  56. package/dist/application/files/text-rule.js.map +1 -0
  57. package/dist/application/files/zip-containers.d.ts +3 -0
  58. package/dist/application/files/zip-containers.d.ts.map +1 -0
  59. package/dist/application/files/zip-containers.js +10 -0
  60. package/dist/application/files/zip-containers.js.map +1 -0
  61. package/dist/application/ports/read-model-table.d.ts +7 -0
  62. package/dist/application/ports/read-model-table.d.ts.map +1 -1
  63. package/dist/application/ports/read-model-table.js.map +1 -1
  64. package/dist/application/read-model/read-model-table-state.d.ts +53 -0
  65. package/dist/application/read-model/read-model-table-state.d.ts.map +1 -0
  66. package/dist/application/read-model/read-model-table-state.js +2 -0
  67. package/dist/application/read-model/read-model-table-state.js.map +1 -0
  68. package/dist/index.d.ts +3 -0
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +3 -0
  71. package/dist/index.js.map +1 -1
  72. package/dist/infrastructure/files/file-inspection.js +1 -1
  73. package/dist/infrastructure/files/file-inspection.js.map +1 -1
  74. package/dist/infrastructure/files/file-staging.d.ts +4 -2
  75. package/dist/infrastructure/files/file-staging.d.ts.map +1 -1
  76. package/dist/infrastructure/files/file-staging.js +14 -6
  77. package/dist/infrastructure/files/file-staging.js.map +1 -1
  78. package/dist/infrastructure/read-model/database-failure.d.ts +19 -0
  79. package/dist/infrastructure/read-model/database-failure.d.ts.map +1 -0
  80. package/dist/infrastructure/read-model/database-failure.js +71 -0
  81. package/dist/infrastructure/read-model/database-failure.js.map +1 -0
  82. package/dist/infrastructure/read-model/live-rows-columns-of.d.ts +7 -0
  83. package/dist/infrastructure/read-model/live-rows-columns-of.d.ts.map +1 -0
  84. package/dist/infrastructure/read-model/live-rows-columns-of.js +20 -0
  85. package/dist/infrastructure/read-model/live-rows-columns-of.js.map +1 -0
  86. package/dist/infrastructure/read-model/live-rows-constraint-form.d.ts +11 -0
  87. package/dist/infrastructure/read-model/live-rows-constraint-form.d.ts.map +1 -0
  88. package/dist/infrastructure/read-model/live-rows-constraint-form.js +13 -0
  89. package/dist/infrastructure/read-model/live-rows-constraint-form.js.map +1 -0
  90. package/dist/infrastructure/read-model/live-rows-constraint-of.d.ts +6 -0
  91. package/dist/infrastructure/read-model/live-rows-constraint-of.d.ts.map +1 -0
  92. package/dist/infrastructure/read-model/live-rows-constraint-of.js +18 -0
  93. package/dist/infrastructure/read-model/live-rows-constraint-of.js.map +1 -0
  94. package/dist/infrastructure/read-model/postgres-trace-columns.d.ts +17 -7
  95. package/dist/infrastructure/read-model/postgres-trace-columns.d.ts.map +1 -1
  96. package/dist/infrastructure/read-model/postgres-trace-columns.js +101 -14
  97. package/dist/infrastructure/read-model/postgres-trace-columns.js.map +1 -1
  98. package/dist/infrastructure/read-model/read-model-table-migration.d.ts +31 -0
  99. package/dist/infrastructure/read-model/read-model-table-migration.d.ts.map +1 -0
  100. package/dist/infrastructure/read-model/read-model-table-migration.js +82 -0
  101. package/dist/infrastructure/read-model/read-model-table-migration.js.map +1 -0
  102. package/dist/infrastructure/read-model/read-model-table-not-ready-error.d.ts +21 -5
  103. package/dist/infrastructure/read-model/read-model-table-not-ready-error.d.ts.map +1 -1
  104. package/dist/infrastructure/read-model/read-model-table-not-ready-error.js +123 -10
  105. package/dist/infrastructure/read-model/read-model-table-not-ready-error.js.map +1 -1
  106. package/dist/infrastructure/read-model/read-model-table-notes.d.ts +9 -0
  107. package/dist/infrastructure/read-model/read-model-table-notes.d.ts.map +1 -0
  108. package/dist/infrastructure/read-model/read-model-table-notes.js +36 -0
  109. package/dist/infrastructure/read-model/read-model-table-notes.js.map +1 -0
  110. package/dist/infrastructure/read-model/read-model-table-ready.d.ts +4 -0
  111. package/dist/infrastructure/read-model/read-model-table-ready.d.ts.map +1 -0
  112. package/dist/infrastructure/read-model/read-model-table-ready.js +5 -0
  113. package/dist/infrastructure/read-model/read-model-table-ready.js.map +1 -0
  114. package/dist/infrastructure/read-model/read-model-tables-not-ready-error.d.ts +24 -0
  115. package/dist/infrastructure/read-model/read-model-tables-not-ready-error.d.ts.map +1 -0
  116. package/dist/infrastructure/read-model/read-model-tables-not-ready-error.js +40 -0
  117. package/dist/infrastructure/read-model/read-model-tables-not-ready-error.js.map +1 -0
  118. package/dist/infrastructure/read-model/read-model-tables.d.ts +82 -0
  119. package/dist/infrastructure/read-model/read-model-tables.d.ts.map +1 -0
  120. package/dist/infrastructure/read-model/read-model-tables.js +161 -0
  121. package/dist/infrastructure/read-model/read-model-tables.js.map +1 -0
  122. package/dist/infrastructure/read-model/table-read-model-store.d.ts +7 -0
  123. package/dist/infrastructure/read-model/table-read-model-store.d.ts.map +1 -1
  124. package/dist/infrastructure/read-model/table-read-model-store.js +8 -0
  125. package/dist/infrastructure/read-model/table-read-model-store.js.map +1 -1
  126. package/package.json +1 -1
@@ -0,0 +1,71 @@
1
+ /** The errors of the network a connection ends with before the server answers. */
2
+ const NETWORK = new Set([
3
+ 'ECONNREFUSED',
4
+ 'ECONNRESET',
5
+ 'ENOTFOUND',
6
+ 'EAI_AGAIN',
7
+ 'ETIMEDOUT',
8
+ 'EHOSTUNREACH',
9
+ 'ENETUNREACH',
10
+ 'EPIPE',
11
+ ]);
12
+ /** What a driver or an ORM names an attempt that found no connection: TypeORM before its data source is open, the pool of Knex. */
13
+ const NOT_CONNECTED = /^(CannotExecuteNotConnectedError|CannotConnectAlreadyConnectedError|KnexTimeoutError)$/;
14
+ /** Prisma: the server cannot be reached, timed out, or closed the connection. */
15
+ const PRISMA = /^P10(01|02|08|17)$/;
16
+ /** What a driver adapter of Prisma says under `meta.driverAdapterError`, when it found no server. */
17
+ const ADAPTER = /^(DatabaseNotReachable|SocketTimeout|ConnectionClosed)$/;
18
+ /**
19
+ * Reads the failure of a statement through what wraps it: the `cause` of each error, the errors
20
+ * an `AggregateError` gathers (Node tries every address of a host) and the error a driver adapter
21
+ * of Prisma hands under `meta`, as Drizzle, Knex, Prisma and TypeORM each wrap the error of the
22
+ * driver. The database is unreachable when one of them is an error of the network, an error of
23
+ * connection of PostgreSQL (class 08, or 57P03 while the server starts), or what an ORM raises
24
+ * when it holds no connection. The short cause is the one of that error, else of the innermost
25
+ * one: the message of a wrapper often is the statement.
26
+ */
27
+ export function databaseFailure(failure) {
28
+ const chain = opened(failure);
29
+ const unreached = chain.find(isUnreachable);
30
+ const told = unreached ?? chain.at(-1);
31
+ return { unreachable: unreached !== undefined, cause: told === undefined ? String(failure) : shortly(told) };
32
+ }
33
+ /** The error and everything under it, outermost first; a loop of causes is read once. */
34
+ function opened(failure, seen = []) {
35
+ if (typeof failure !== 'object' || failure === null || seen.includes(failure)) {
36
+ return [];
37
+ }
38
+ return [failure, ...under(failure).flatMap((inner) => opened(inner, [...seen, failure]))];
39
+ }
40
+ /** What an error wraps: the errors it gathers, the error of a driver adapter of Prisma, its cause. */
41
+ function under(failure) {
42
+ const gathered = held(failure, 'errors');
43
+ const several = Array.isArray(gathered) ? gathered : [];
44
+ const meta = held(failure, 'meta');
45
+ const adapter = typeof meta === 'object' && meta !== null ? held(meta, 'driverAdapterError') : undefined;
46
+ return [...several, adapter, held(failure, 'cause')];
47
+ }
48
+ function isUnreachable(error) {
49
+ const code = text(held(error, 'code')) ?? '';
50
+ const ofPostgres = code.startsWith('08') || code === '57P03';
51
+ const named = NOT_CONNECTED.test(text(held(error, 'name')) ?? '') || ADAPTER.test(text(held(error, 'kind')) ?? '');
52
+ return NETWORK.has(code) || ofPostgres || PRISMA.test(code) || named;
53
+ }
54
+ function shortly(error) {
55
+ const code = text(held(error, 'code')) ?? text(held(error, 'kind'));
56
+ const host = text(held(error, 'address')) ?? text(held(error, 'host'));
57
+ const port = text(held(error, 'port'));
58
+ const said = (text(held(error, 'message')) ?? '').split('\n').find((line) => line.trim() !== '');
59
+ // Knex writes the statement before the message of an error of the server: what follows the last dash is the driver's.
60
+ const message = 'severity' in error ? said?.split(' - ').at(-1) : said;
61
+ const address = host === undefined || port === undefined ? undefined : `${host}:${port}`;
62
+ return [code, address ?? message].filter((part) => part !== undefined && part !== '').join(' ');
63
+ }
64
+ function held(value, key) {
65
+ return key in value ? Reflect.get(value, key) : undefined;
66
+ }
67
+ /** A text or a number as text: what a code, a name, a host or a port is. */
68
+ function text(value) {
69
+ return typeof value === 'string' || typeof value === 'number' ? String(value) : undefined;
70
+ }
71
+ //# sourceMappingURL=database-failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-failure.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/database-failure.ts"],"names":[],"mappings":"AAQA,kFAAkF;AAClF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC;IACtB,cAAc;IACd,YAAY;IACZ,WAAW;IACX,WAAW;IACX,WAAW;IACX,cAAc;IACd,aAAa;IACb,OAAO;CACR,CAAC,CAAC;AAEH,mIAAmI;AACnI,MAAM,aAAa,GAAG,wFAAwF,CAAC;AAE/G,iFAAiF;AACjF,MAAM,MAAM,GAAG,oBAAoB,CAAC;AAEpC,qGAAqG;A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of a deleted row; `undefined` for any other check, one
4
+ * that only looks like it included (`(deleted OR title IS NOT NULL) AND ..`, `NOT (..)`).
5
+ */
6
+ export declare function liveRowsColumnsOf(definition: string, deleted: string): string[] | undefined;
7
+ //# sourceMappingURL=live-rows-columns-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-rows-columns-of.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/live-rows-columns-of.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAQ3F"}
@@ -0,0 +1,20 @@
1
+ import { LIVE_ROWS_CONSTRAINT_FORM } from './live-rows-constraint-form.js';
2
+ const FORM = new RegExp(LIVE_ROWS_CONSTRAINT_FORM);
3
+ /** A name as PostgreSQL prints it in a definition: quoted, or plain in lower case; its keywords are in upper case. */
4
+ const NAMES = /"(?:[^"]|"")+"|[a-z_][a-z0-9_]*/g;
5
+ /**
6
+ * The columns a check constraint keeps whole in the live rows, when it is written as the kit
7
+ * writes it with this column as the mark of a deleted row; `undefined` for any other check, one
8
+ * that only looks like it included (`(deleted OR title IS NOT NULL) AND ..`, `NOT (..)`).
9
+ */
10
+ export function liveRowsColumnsOf(definition, deleted) {
11
+ if (!FORM.test(definition)) {
12
+ return undefined;
13
+ }
14
+ const [marked, ...columns] = [...definition.matchAll(NAMES)].map(([name]) => unquoted(name));
15
+ return marked === deleted ? columns : undefined;
16
+ }
17
+ function unquoted(name) {
18
+ return name.startsWith('"') ? name.slice(1, -1).replaceAll('""', '"') : name;
19
+ }
20
+ //# sourceMappingURL=live-rows-columns-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-rows-columns-of.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/live-rows-columns-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAEnD,sHAAsH;AACtH,MAAM,KAAK,GAAG,kCAAkC,CAAC;AAEjD;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB,EAAE,OAAe;IACnE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7F,OAAO,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The check constraint of the live rows as the kit writes it and as PostgreSQL prints it back
3
+ * (`pg_get_constraintdef`), a regular expression both JavaScript and PostgreSQL read:
4
+ * `CHECK ((deleted OR (title IS NOT NULL)))`, or `((a IS NOT NULL) AND (b IS NOT NULL))` after
5
+ * the `OR` when it keeps several columns whole, `NOT VALID` at the end when it is not validated.
6
+ * Nothing else is the kit's: a constraint of that name written otherwise is never read as holding
7
+ * a column, and never dropped. It holds no backslash and no question mark, so a migration that
8
+ * carries it in a string of JavaScript or in a statement with placeholders keeps it as it is.
9
+ */
10
+ export declare const LIVE_ROWS_CONSTRAINT_FORM = "^CHECK [(][(](\"([^\"]|\"\")+\"|[a-z_][a-z0-9_]*) OR ([(](\"([^\"]|\"\")+\"|[a-z_][a-z0-9_]*) IS NOT NULL[)]|[(][(](\"([^\"]|\"\")+\"|[a-z_][a-z0-9_]*) IS NOT NULL[)]( AND [(](\"([^\"]|\"\")+\"|[a-z_][a-z0-9_]*) IS NOT NULL[)])+[)])[)][)]( NOT VALID|)$";
11
+ //# sourceMappingURL=live-rows-constraint-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-rows-constraint-form.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/live-rows-constraint-form.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,iQAAgG,CAAC"}
@@ -0,0 +1,13 @@
1
+ const IDENTIFIER = '("([^"]|"")+"|[a-z_][a-z0-9_]*)';
2
+ const WHOLE = `[(]${IDENTIFIER} IS NOT NULL[)]`;
3
+ /**
4
+ * The check constraint of the live rows as the kit writes it and as PostgreSQL prints it back
5
+ * (`pg_get_constraintdef`), a regular expression both JavaScript and PostgreSQL read:
6
+ * `CHECK ((deleted OR (title IS NOT NULL)))`, or `((a IS NOT NULL) AND (b IS NOT NULL))` after
7
+ * the `OR` when it keeps several columns whole, `NOT VALID` at the end when it is not validated.
8
+ * Nothing else is the kit's: a constraint of that name written otherwise is never read as holding
9
+ * a column, and never dropped. It holds no backslash and no question mark, so a migration that
10
+ * carries it in a string of JavaScript or in a statement with placeholders keeps it as it is.
11
+ */
12
+ export const LIVE_ROWS_CONSTRAINT_FORM = `^CHECK [(][(]${IDENTIFIER} OR (${WHOLE}|[(]${WHOLE}( AND ${WHOLE})+[)])[)][)]( NOT VALID|)$`;
13
+ //# sourceMappingURL=live-rows-constraint-form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-rows-constraint-form.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/live-rows-constraint-form.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,iCAAiC,CAAC;AACrD,MAAM,KAAK,GAAG,MAAM,UAAU,iBAAiB,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,UAAU,QAAQ,KAAK,OAAO,KAAK,SAAS,KAAK,4BAA4B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The name of the check constraint that keeps the live rows of a read model table whole, in place
3
+ * of the NOT NULL its columns lose: `<table>_live_rows_whole`, as PostgreSQL keeps it.
4
+ */
5
+ export declare function liveRowsConstraintOf(table: string): string;
6
+ //# sourceMappingURL=live-rows-constraint-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-rows-constraint-of.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/live-rows-constraint-of.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAa1D"}
@@ -0,0 +1,18 @@
1
+ /** PostgreSQL keeps 63 bytes of an identifier, cut at a character. */
2
+ const IDENTIFIER_BYTES = 63;
3
+ /**
4
+ * The name of the check constraint that keeps the live rows of a read model table whole, in place
5
+ * of the NOT NULL its columns lose: `<table>_live_rows_whole`, as PostgreSQL keeps it.
6
+ */
7
+ export function liveRowsConstraintOf(table) {
8
+ const encoder = new TextEncoder();
9
+ let kept = '';
10
+ for (const character of `${table}_live_rows_whole`) {
11
+ if (encoder.encode(kept + character).length > IDENTIFIER_BYTES) {
12
+ break;
13
+ }
14
+ kept += character;
15
+ }
16
+ return kept;
17
+ }
18
+ //# sourceMappingURL=live-rows-constraint-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-rows-constraint-of.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/live-rows-constraint-of.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,KAAK,MAAM,SAAS,IAAI,GAAG,KAAK,kBAAkB,EAAE,CAAC;QACnD,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC,MAAM,GAAG,gBAAgB,EAAE,CAAC;YAC/D,MAAM;QACR,CAAC;QAED,IAAI,IAAI,SAAS,CAAC;IACpB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,18 +1,24 @@
1
+ import type { ReadModelTableState } from '../../application/read-model/read-model-table-state.js';
1
2
  import type { SqlRun } from './sql-run.js';
2
3
  export interface TracedTable {
3
4
  readonly schema?: string;
4
5
  readonly table: string;
5
6
  /** The columns of the row, in which a trace holds NULL: the key, the tenant and the stamp are not among them. */
6
7
  readonly data: readonly string[];
8
+ /** The column that marks a deleted row, as the definition of the table names it. Default `deleted`. */
9
+ readonly deleted?: string;
7
10
  }
8
11
  /**
9
- * Whether the table of a read model on PostgreSQL can hold the trace of a deleted row: every
10
- * column of the row accepts NULL in the database, whatever its definition in the code says. The
11
- * columns are read once, before the first write of a trace, on the table as a statement would
12
- * resolve it (the search path when no schema is named), so a table that is not ready is refused
13
- * by name and not by a statement that would abort the transaction of the event. The copy of a
14
- * rebuild is made like the table. Shared by the ORM adapters, which differ only in how they run
15
- * a statement.
12
+ * Whether the table of a read model on PostgreSQL can hold the trace of a deleted row, read from
13
+ * the database for the columns the store maps and for no other: each accepts NULL, and none is a
14
+ * part of the primary key, an identity or a generated column, nor of a domain that refuses NULL,
15
+ * which nothing can open. The table is read as a statement would resolve it (the search path
16
+ * when no schema is named). `require` is the refusal of a store before its first trace, by name
17
+ * and not by a statement that would abort the transaction of the event; it reads once, and the
18
+ * check constraints only for a table it refuses. `state` is the same reading with the
19
+ * constraints, for the tables an application lists and checks when it starts
20
+ * (`ReadModelTables`): one code, so one verdict. The copy of a rebuild is made like the table.
21
+ * Shared by the ORM adapters, which differ only in how they run a statement.
16
22
  */
17
23
  export declare class PostgresTraceColumns {
18
24
  private readonly run;
@@ -20,5 +26,9 @@ export declare class PostgresTraceColumns {
20
26
  private ready;
21
27
  constructor(run: SqlRun, target: () => TracedTable);
22
28
  require(): Promise<void>;
29
+ /** What the table can hold, what its check constraint keeps whole and what else checks its row. */
30
+ state(): Promise<ReadModelTableState>;
31
+ private columns;
32
+ private withChecks;
23
33
  }
24
34
  //# sourceMappingURL=postgres-trace-columns.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-trace-columns.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/postgres-trace-columns.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iHAAiH;IACjH,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AAED;;;;;;;;GAQG;AACH,qBAAa,oBAAoB;IAI7B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,KAAK,CAAS;IAEtB,YACmB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,WAAW,EACxC;IAEE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAqB7B;CACF"}
1
+ {"version":3,"file":"postgres-trace-columns.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/postgres-trace-columns.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAC/F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iHAAiH;IACjH,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,uGAAuG;IACvG,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAgBD;;;;;;;;;;;GAWG;AACH,qBAAa,oBAAoB;IAI7B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,KAAK,CAAS;IAEtB,YACmB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,WAAW,EACxC;IAEE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAY7B;IAED,mGAAmG;IAC7F,KAAK,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAI1C;YAEa,OAAO;YAqBP,UAAU;CAezB"}
@@ -1,12 +1,27 @@
1
+ import { liveRowsColumnsOf } from './live-rows-columns-of.js';
2
+ import { liveRowsConstraintOf } from './live-rows-constraint-of.js';
1
3
  import { ReadModelTableNotReadyError } from './read-model-table-not-ready-error.js';
4
+ import { readModelTableReady } from './read-model-table-ready.js';
5
+ /** Every column of the table, as a statement resolves it: what a trace needs to know of each, and what kind of relation holds them. */
6
+ const COLUMNS = `select col.attname as "column", col.attnotnull as "refusing", col.attidentity <> '' as "identity", col.attgenerated <> '' as "generated", exists (select 1 from pg_index as pk where pk.indrelid = col.attrelid and pk.indisprimary and col.attnum = any (pk.indkey)) as "key", exists (select 1 from pg_type as typ where typ.oid = col.atttypid and typ.typtype = 'd' and typ.typnotnull) as "domain", (select rel.relkind::text from pg_class as rel where rel.oid = col.attrelid) as "relation" from pg_attribute as col where col.attrelid = to_regclass($1) and col.attnum > 0 and not col.attisdropped`;
7
+ /** Every check constraint of the table, as PostgreSQL writes it, with the columns it names. */
8
+ const CHECKS = `select con.conname as "name", con.convalidated as "valid", pg_get_constraintdef(con.oid) as "definition", array_to_json(array(select att.attname from pg_attribute as att where att.attrelid = con.conrelid and att.attnum = any (con.conkey)))::text as "columns" from pg_constraint as con where con.conrelid = to_regclass($1) and con.contype = 'c' order by con.conname`;
9
+ const RELATIONS = {
10
+ v: 'view',
11
+ m: 'materialized-view',
12
+ f: 'foreign-table',
13
+ };
2
14
  /**
3
- * Whether the table of a read model on PostgreSQL can hold the trace of a deleted row: every
4
- * column of the row accepts NULL in the database, whatever its definition in the code says. The
5
- * columns are read once, before the first write of a trace, on the table as a statement would
6
- * resolve it (the search path when no schema is named), so a table that is not ready is refused
7
- * by name and not by a statement that would abort the transaction of the event. The copy of a
8
- * rebuild is made like the table. Shared by the ORM adapters, which differ only in how they run
9
- * a statement.
15
+ * Whether the table of a read model on PostgreSQL can hold the trace of a deleted row, read from
16
+ * the database for the columns the store maps and for no other: each accepts NULL, and none is a
17
+ * part of the primary key, an identity or a generated column, nor of a domain that refuses NULL,
18
+ * which nothing can open. The table is read as a statement would resolve it (the search path
19
+ * when no schema is named). `require` is the refusal of a store before its first trace, by name
20
+ * and not by a statement that would abort the transaction of the event; it reads once, and the
21
+ * check constraints only for a table it refuses. `state` is the same reading with the
22
+ * constraints, for the tables an application lists and checks when it starts
23
+ * (`ReadModelTables`): one code, so one verdict. The copy of a rebuild is made like the table.
24
+ * Shared by the ORM adapters, which differ only in how they run a statement.
10
25
  */
11
26
  export class PostgresTraceColumns {
12
27
  run;
@@ -20,16 +35,88 @@ export class PostgresTraceColumns {
20
35
  if (this.ready) {
21
36
  return;
22
37
  }
23
- const { schema, table, data } = this.target();
24
- const path = schema === undefined ? quoted(table) : `${quoted(schema)}.${quoted(table)}`;
25
- const refusing = await this.run('select attname as "column" from pg_attribute where attrelid = to_regclass($1) and attnotnull and attnum > 0 and not attisdropped', [path]);
26
- const named = new Set(refusing.map((row) => row['column']));
27
- const columns = data.filter((column) => named.has(column));
28
- if (columns.length > 0) {
29
- throw new ReadModelTableNotReadyError(schema === undefined ? table : `${schema}.${table}`, columns);
38
+ const columns = await this.columns();
39
+ if (!readModelTableReady(columns)) {
40
+ throw new ReadModelTableNotReadyError(columns.exists ? await this.withChecks(columns) : columns);
30
41
  }
31
42
  this.ready = true;
32
43
  }
44
+ /** What the table can hold, what its check constraint keeps whole and what else checks its row. */
45
+ async state() {
46
+ const columns = await this.columns();
47
+ return columns.exists ? this.withChecks(columns) : columns;
48
+ }
49
+ async columns() {
50
+ const { schema, table, data, deleted = 'deleted' } = this.target();
51
+ const read = await this.run(COLUMNS, [pathOf(schema, table)]);
52
+ const held = new Map(read.map((row) => [row['column'], row]));
53
+ const kinds = data.map((column) => ({ column, because: kindOf(held.get(column)) }));
54
+ const unfit = kinds.flatMap(({ column, because }) => (because === undefined ? [] : [{ column, because }]));
55
+ const row = data.filter((column) => !unfit.some((left) => left.column === column));
56
+ const relation = RELATIONS[String(read[0]?.['relation'])];
57
+ return {
58
+ table,
59
+ exists: held.size > 0,
60
+ refusing: held.size === 0 ? [] : row.filter((column) => held.get(column)?.['refusing'] === true),
61
+ unfit: held.size === 0 ? [] : unfit,
62
+ row,
63
+ deleted,
64
+ ...(schema === undefined ? {} : { schema }),
65
+ ...(relation === undefined ? {} : { relation }),
66
+ };
67
+ }
68
+ async withChecks(columns) {
69
+ const { schema, table } = columns;
70
+ const name = liveRowsConstraintOf(table);
71
+ const checks = await this.run(CHECKS, [pathOf(schema, table)]);
72
+ const others = checks.filter((check) => check['name'] !== name).flatMap((check) => namingTheRow(check, columns));
73
+ return {
74
+ ...columns,
75
+ constraint: constraintOf(checks.find((check) => check['name'] === name), columns.deleted),
76
+ ...(others.length === 0 ? {} : { checks: others }),
77
+ };
78
+ }
79
+ }
80
+ /** The constraint of the live rows as the table holds it: the kit's form and what it keeps whole, or another check under its name. */
81
+ function constraintOf(held, deleted) {
82
+ if (held === undefined) {
83
+ return { state: 'missing', columns: [] };
84
+ }
85
+ const definition = String(held['definition']);
86
+ const whole = liveRowsColumnsOf(definition, deleted);
87
+ if (whole === undefined) {
88
+ return { state: 'unexpected', columns: [], definition };
89
+ }
90
+ return { state: held['valid'] === true ? 'held' : 'not-valid', columns: whole };
91
+ }
92
+ /**
93
+ * Another check constraint, when it names a column of the row: it may refuse the NULL of a trace
94
+ * there. One that holds for the live rows only, written `deleted or ..` as PostgreSQL prints it,
95
+ * lets every trace in and is not named.
96
+ */
97
+ function namingTheRow(check, { row, deleted }) {
98
+ const named = JSON.parse(String(check['columns']));
99
+ const definition = String(check['definition']);
100
+ const live = [deleted, quoted(deleted)].some((mark) => definition.startsWith(`CHECK ((${mark} OR `));
101
+ return !live && Array.isArray(named) && named.some((column) => row.includes(String(column)))
102
+ ? [{ name: String(check['name']), definition }]
103
+ : [];
104
+ }
105
+ const KINDS = [
106
+ ['key', 'primary-key'],
107
+ ['identity', 'identity'],
108
+ ['generated', 'generated'],
109
+ ['domain', 'domain'],
110
+ ];
111
+ /** Why a trace can never hold NULL in the column, when it cannot. */
112
+ function kindOf(column) {
113
+ if (column === undefined) {
114
+ return 'absent';
115
+ }
116
+ return KINDS.find(([flag]) => column[flag] === true)?.[1];
117
+ }
118
+ function pathOf(schema, table) {
119
+ return schema === undefined ? quoted(table) : `${quoted(schema)}.${quoted(table)}`;
33
120
  }
34
121
  function quoted(identifier) {
35
122
  return `"${identifier.replaceAll('"', '""')}"`;
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-trace-columns.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/postgres-trace-columns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAUjF;;;;;;;;GAQG;AACH,MAAM,OAAO,oBAAoB;IAIZ,GAAG;IACH,MAAM;IAJjB,KAAK,GAAG,KAAK,CAAC;IAEtB,YACmB,GAAW,EACX,MAAyB;mBADzB,GAAG;sBACH,MAAM;IACtB,CAAC;IAEJ,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,CAAC,KAAK,EAAE,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AAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1F,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC;QAC/C,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAID,MAAM,KAAK,GAAyD;IAClE,CAAC,KAAK,EAAE,aAAa,CAAC;IACtB,CAAC,UAAU,EAAE,UAAU,CAAC;IACxB,CAAC,WAAW,EAAE,WAAW,CAAC;IAC1B,CAAC,QAAQ,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,qEAAqE;AACrE,SAAS,MAAM,CAAC,MAAuB;IACrC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,MAAM,CAAC,MAA0B,EAAE,KAAa;IACvD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACrF,CAAC;AAED,SAAS,MAAM,CAAC,UAAkB;IAChC,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AACjD,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { ReadModelTableState } from '../../application/read-model/read-model-table-state.js';
2
+ /** The migration of a read model table, in the two steps a large table runs apart. */
3
+ interface ReadModelTableMigration {
4
+ /**
5
+ * The change of definition: NOT NULL dropped and the check constraint written, `not valid`, in
6
+ * one statement. Brief, under the lock that stops the readers and the writers of the table.
7
+ */
8
+ readonly definition: readonly string[];
9
+ /**
10
+ * The validation of the constraint and the cleaning of the rows deleted before: both read the
11
+ * whole table under a lock that lets readers and writers through, when they run outside the
12
+ * transaction of the first step.
13
+ */
14
+ readonly validation: readonly string[];
15
+ }
16
+ /**
17
+ * The migration that makes a read model table ready, PostgreSQL statements written from the
18
+ * columns the store maps and from nothing else. NOT NULL is dropped on the columns of the row
19
+ * that refuse it and, in the same statement, the check constraint that keeps the live rows whole
20
+ * is written again when it is missing or does not hold those columns, `not valid`: no row can be
21
+ * written between the two, whatever commits each statement. A constraint of that name that is
22
+ * not written as the kit writes it is never dropped: the statement reads its definition first and
23
+ * fails on it, on the database it runs against. Then the constraint is validated and the rows
24
+ * deleted before are emptied, those that still hold data alone. Run twice, it ends where it ended
25
+ * the first time and fails on nothing. It never names the key, the tenant, the stamp, a column
26
+ * the store does not map, nor one that is unfit. Nothing is written while the definition alone
27
+ * was read.
28
+ */
29
+ export declare function readModelTableMigration(state: ReadModelTableState): ReadModelTableMigration;
30
+ export {};
31
+ //# sourceMappingURL=read-model-table-migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-model-table-migration.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/read-model-table-migration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAE/F,sFAAsF;AACtF,UAAU,uBAAuB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,mBAAmB,GAAG,uBAAuB,CAwB3F"}
@@ -0,0 +1,82 @@
1
+ import { LIVE_ROWS_CONSTRAINT_FORM } from './live-rows-constraint-form.js';
2
+ import { liveRowsConstraintOf } from './live-rows-constraint-of.js';
3
+ /**
4
+ * The migration that makes a read model table ready, PostgreSQL statements written from the
5
+ * columns the store maps and from nothing else. NOT NULL is dropped on the columns of the row
6
+ * that refuse it and, in the same statement, the check constraint that keeps the live rows whole
7
+ * is written again when it is missing or does not hold those columns, `not valid`: no row can be
8
+ * written between the two, whatever commits each statement. A constraint of that name that is
9
+ * not written as the kit writes it is never dropped: the statement reads its definition first and
10
+ * fails on it, on the database it runs against. Then the constraint is validated and the rows
11
+ * deleted before are emptied, those that still hold data alone. Run twice, it ends where it ended
12
+ * the first time and fails on nothing. It never names the key, the tenant, the stamp, a column
13
+ * the store does not map, nor one that is unfit. Nothing is written while the definition alone
14
+ * was read.
15
+ */
16
+ export function readModelTableMigration(state) {
17
+ const { refusing, row, constraint } = state;
18
+ if (constraint === undefined || refusing.length === 0) {
19
+ return { definition: [], validation: constraint?.state === 'not-valid' ? [validated(state)] : [] };
20
+ }
21
+ const whole = [...new Set([...constraint.columns, ...refusing])];
22
+ const held = row.map((column) => `${quoted(column)} is not null`).join(' or ');
23
+ const emptied = row.map((column) => `${quoted(column)} = null`).join(', ');
24
+ const cleaned = `update ${pathOf(state)} set ${emptied} where ${quoted(state.deleted)} and (${held});`;
25
+ if (constraint.state === 'unexpected') {
26
+ return { definition: [`alter table ${pathOf(state)} ${opened(state)};`], validation: [cleaned] };
27
+ }
28
+ if (constraint.state !== 'missing' && whole.length === constraint.columns.length) {
29
+ return {
30
+ definition: [`alter table ${pathOf(state)} ${opened(state)};`],
31
+ validation: [...(constraint.state === 'not-valid' ? [validated(state)] : []), cleaned],
32
+ };
33
+ }
34
+ return { definition: [rewritten(state, whole)], validation: [validated(state), cleaned] };
35
+ }
36
+ function opened({ refusing }) {
37
+ return refusing.map((column) => `alter column ${quoted(column)} drop not null`).join(', ');
38
+ }
39
+ /**
40
+ * NOT NULL dropped and the constraint written again in one statement, once the constraint the
41
+ * database holds under that name, if any, is known to be the kit's.
42
+ */
43
+ function rewritten(state, whole) {
44
+ const path = pathOf(state);
45
+ const name = liveRowsConstraintOf(state.table);
46
+ const checked = whole.map((column) => `${quoted(column)} is not null`).join(' and ');
47
+ const table = state.schema === undefined ? state.table : `${state.schema}.${state.table}`;
48
+ const refused = `The constraint ${name} of ${table} is not written as ddd-ts-kit writes the one that keeps the live rows of a read model whole: it is left as it is, and nothing was changed.`;
49
+ const body = [
50
+ 'begin',
51
+ ` if exists (select 1 from pg_constraint where conrelid = to_regclass(${literal(path)}) and conname = ${literal(name)} and pg_get_constraintdef(oid) !~ ${literal(LIVE_ROWS_CONSTRAINT_FORM)}) then`,
52
+ ` raise exception ${literal(refused.replaceAll('%', '%%'))};`,
53
+ ' end if;',
54
+ ` alter table ${path} ${opened(state)}, drop constraint if exists ${quoted(name)}, add constraint ${quoted(name)} check (${quoted(state.deleted)} or (${checked})) not valid;`,
55
+ 'end',
56
+ ].join('\n');
57
+ const tag = dollarTagFor(body);
58
+ return `do ${tag}\n${body}\n${tag};`;
59
+ }
60
+ /** A dollar quote no name of the statement can close: `$kit$`, lengthened while the body holds it. */
61
+ function dollarTagFor(body) {
62
+ let tag = 'kit';
63
+ while (body.includes(`$${tag}$`)) {
64
+ tag += '_';
65
+ }
66
+ return `$${tag}$`;
67
+ }
68
+ function validated(state) {
69
+ return `alter table ${pathOf(state)} validate constraint ${quoted(liveRowsConstraintOf(state.table))};`;
70
+ }
71
+ /** The table as a statement names it: its schema first when it has one. */
72
+ function pathOf({ schema, table }) {
73
+ return schema === undefined ? quoted(table) : `${quoted(schema)}.${quoted(table)}`;
74
+ }
75
+ /** Every identifier is quoted: a reserved word, a capital or a hyphen is then written as the database holds it. */
76
+ function quoted(identifier) {
77
+ return `"${identifier.replaceAll('"', '""')}"`;
78
+ }
79
+ function literal(text) {
80
+ return `'${text.replaceAll("'", "''")}'`;
81
+ }
82
+ //# sourceMappingURL=read-model-table-migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-model-table-migration.js","sourceRoot":"","sources":["../../../src/infrastructure/read-model/read-model-table-migration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAkBjE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAA0B;IAChE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAE5C,IAAI,UAAU,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACrG,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACjE,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/E,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3E,MAAM,OAAO,GAAG,UAAU,MAAM,CAAC,KAAK,CAAC,QAAQ,OAAO,UAAU,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;IAEvG,IAAI,UAAU,CAAC,KAAK,KAAK,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AAC,wBAAwB,MAAM,CAAC,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC;AAC1G,CAAC;AAED,2EAA2E;AAC3E,SAAS,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAuB;IACpD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACrF,CAAC;AAED,mHAAmH;AACnH,SAAS,MAAM,CAAC,UAAkB;IAChC,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AACjD,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AAC3C,CAAC"}
@@ -1,12 +1,28 @@
1
+ import { readModelTableMigration } from './read-model-table-migration.js';
2
+ import type { ReadModelTableState } from '../../application/read-model/read-model-table-state.js';
1
3
  /**
2
- * The table of a read model has columns that refuse NULL, so it cannot hold the trace of a
3
- * deleted row: its key, its stamp and `deleted`, NULL in every other column. An adapter raises it
4
- * from the definition of the table or from one read of its columns, before any statement the
5
- * database would refuse, since on PostgreSQL that refusal aborts the transaction of the event.
4
+ * The table of a read model cannot hold the trace of a deleted row: its key, its tenant and its
5
+ * stamp, NULL in every other column the store maps. An adapter raises it from the definition of
6
+ * the table when the store is built, or from one read of its columns before the first trace,
7
+ * never from a statement the database would refuse, since on PostgreSQL that refusal aborts the
8
+ * transaction of the event. Its message names the table, what keeps it from holding a trace,
9
+ * what is known of the check constraint of the live rows, and the migration to write, which
10
+ * names the columns the store maps and no other.
6
11
  */
7
12
  export declare class ReadModelTableNotReadyError extends Error {
13
+ readonly state: ReadModelTableState;
14
+ /** The table as it is said: `scheduling.agenda`. */
8
15
  readonly table: string;
16
+ /** The columns of the row that refuse NULL. */
9
17
  readonly columns: readonly string[];
10
- constructor(table: string, columns: readonly string[]);
18
+ /**
19
+ * The migration to write, in the two steps a large table runs apart: the change of definition,
20
+ * then the validation of the constraint and the cleaning of the rows deleted before. Both empty
21
+ * when no migration makes the table ready.
22
+ */
23
+ readonly steps: ReturnType<typeof readModelTableMigration>;
24
+ /** The statements of both steps, in order. */
25
+ readonly statements: readonly string[];
26
+ constructor(state: ReadModelTableState);
11
27
  }
12
28
  //# sourceMappingURL=read-model-table-not-ready-error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"read-model-table-not-ready-error.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/read-model-table-not-ready-error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IAElD,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE;IAFrC,YACW,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,MAAM,EAAE,EAUpC;CACF"}
1
+ {"version":3,"file":"read-model-table-not-ready-error.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/read-model/read-model-table-not-ready-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAE/F;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IAiBxC,QAAQ,CAAC,KAAK,EAAE,mBAAmB;IAhB/C,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAEpC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC;IAE3D,8CAA8C;IAC9C,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAEvC,YAAqB,KAAK,EAAE,mBAAmB,EAiB9C;CACF"}