ddd-ts-kit 0.110.0 → 0.111.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 (226) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.fr.md +7 -5
  3. package/README.md +6 -4
  4. package/dist/check/explain/tenancy-docs.d.ts.map +1 -1
  5. package/dist/check/explain/tenancy-docs.js +3 -1
  6. package/dist/check/explain/tenancy-docs.js.map +1 -1
  7. package/dist/check/fixtures/tenancy-advisory-lock-fixtures.d.ts +9 -0
  8. package/dist/check/fixtures/tenancy-advisory-lock-fixtures.d.ts.map +1 -0
  9. package/dist/check/fixtures/tenancy-advisory-lock-fixtures.js +45 -0
  10. package/dist/check/fixtures/tenancy-advisory-lock-fixtures.js.map +1 -0
  11. package/dist/check/fixtures/tenancy-fixtures.d.ts.map +1 -1
  12. package/dist/check/fixtures/tenancy-fixtures.js +2 -0
  13. package/dist/check/fixtures/tenancy-fixtures.js.map +1 -1
  14. package/dist/check/rules/privacy-declared-field.js +1 -1
  15. package/dist/check/rules/privacy-declared-field.js.map +1 -1
  16. package/dist/check/rules/tenancy-scoped-statement.d.ts.map +1 -1
  17. package/dist/check/rules/tenancy-scoped-statement.js +11 -3
  18. package/dist/check/rules/tenancy-scoped-statement.js.map +1 -1
  19. package/dist/commands/generate.js +2 -0
  20. package/dist/commands/generate.js.map +1 -1
  21. package/dist/context-layout/context-layout.d.ts.map +1 -1
  22. package/dist/context-layout/context-layout.js +6 -0
  23. package/dist/context-layout/context-layout.js.map +1 -1
  24. package/dist/context-layout/module-moves.d.ts +8 -0
  25. package/dist/context-layout/module-moves.d.ts.map +1 -1
  26. package/dist/context-layout/module-moves.js +14 -3
  27. package/dist/context-layout/module-moves.js.map +1 -1
  28. package/dist/context-layout/runner-configs-by-hand.d.ts.map +1 -1
  29. package/dist/context-layout/runner-configs-by-hand.js +12 -0
  30. package/dist/context-layout/runner-configs-by-hand.js.map +1 -1
  31. package/dist/context-layout/settle.d.ts +9 -0
  32. package/dist/context-layout/settle.d.ts.map +1 -1
  33. package/dist/context-layout/settle.js +25 -3
  34. package/dist/context-layout/settle.js.map +1 -1
  35. package/dist/describe/read-adapters.d.ts.map +1 -1
  36. package/dist/describe/read-adapters.js +5 -1
  37. package/dist/describe/read-adapters.js.map +1 -1
  38. package/dist/describe/read-ports.js +8 -1
  39. package/dist/describe/read-ports.js.map +1 -1
  40. package/dist/generate/generate-options.d.ts +7 -0
  41. package/dist/generate/generate-options.d.ts.map +1 -1
  42. package/dist/generate/generate-options.js +2 -0
  43. package/dist/generate/generate-options.js.map +1 -1
  44. package/dist/generate/kind.d.ts +4 -0
  45. package/dist/generate/kind.d.ts.map +1 -1
  46. package/dist/generate/kinds/adapter-kind.d.ts.map +1 -1
  47. package/dist/generate/kinds/adapter-kind.js +12 -0
  48. package/dist/generate/kinds/adapter-kind.js.map +1 -1
  49. package/dist/generate/kinds/declare-storage.d.ts.map +1 -1
  50. package/dist/generate/kinds/declare-storage.js +3 -57
  51. package/dist/generate/kinds/declare-storage.js.map +1 -1
  52. package/dist/generate/kinds/declare-table.d.ts +14 -0
  53. package/dist/generate/kinds/declare-table.d.ts.map +1 -0
  54. package/dist/generate/kinds/declare-table.js +72 -0
  55. package/dist/generate/kinds/declare-table.js.map +1 -0
  56. package/dist/generate/kinds/e2e/job-slug.d.ts +3 -0
  57. package/dist/generate/kinds/e2e/job-slug.d.ts.map +1 -0
  58. package/dist/generate/kinds/e2e/job-slug.js +8 -0
  59. package/dist/generate/kinds/e2e/job-slug.js.map +1 -0
  60. package/dist/generate/kinds/e2e/job-spec.d.ts +16 -0
  61. package/dist/generate/kinds/e2e/job-spec.d.ts.map +1 -0
  62. package/dist/generate/kinds/e2e/job-spec.js +54 -0
  63. package/dist/generate/kinds/e2e/job-spec.js.map +1 -0
  64. package/dist/generate/kinds/e2e/jobs-sending.d.ts +17 -5
  65. package/dist/generate/kinds/e2e/jobs-sending.d.ts.map +1 -1
  66. package/dist/generate/kinds/e2e/jobs-sending.js +15 -6
  67. package/dist/generate/kinds/e2e/jobs-sending.js.map +1 -1
  68. package/dist/generate/kinds/e2e/reaction-of.d.ts +5 -5
  69. package/dist/generate/kinds/e2e/reaction-of.d.ts.map +1 -1
  70. package/dist/generate/kinds/e2e/reaction-of.js +15 -8
  71. package/dist/generate/kinds/e2e/reaction-of.js.map +1 -1
  72. package/dist/generate/kinds/e2e/starting-jobs.d.ts +10 -0
  73. package/dist/generate/kinds/e2e/starting-jobs.d.ts.map +1 -0
  74. package/dist/generate/kinds/e2e/starting-jobs.js +33 -0
  75. package/dist/generate/kinds/e2e/starting-jobs.js.map +1 -0
  76. package/dist/generate/kinds/e2e-kind.d.ts.map +1 -1
  77. package/dist/generate/kinds/e2e-kind.js +47 -35
  78. package/dist/generate/kinds/e2e-kind.js.map +1 -1
  79. package/dist/generate/kinds/generate-repository.d.ts +8 -0
  80. package/dist/generate/kinds/generate-repository.d.ts.map +1 -1
  81. package/dist/generate/kinds/generate-repository.js +2 -13
  82. package/dist/generate/kinds/generate-repository.js.map +1 -1
  83. package/dist/generate/kinds/note-the-migration.d.ts +4 -0
  84. package/dist/generate/kinds/note-the-migration.d.ts.map +1 -0
  85. package/dist/generate/kinds/note-the-migration.js +13 -0
  86. package/dist/generate/kinds/note-the-migration.js.map +1 -0
  87. package/dist/generate/kinds/personal-data/columns-of-table.d.ts +18 -0
  88. package/dist/generate/kinds/personal-data/columns-of-table.d.ts.map +1 -0
  89. package/dist/generate/kinds/personal-data/columns-of-table.js +31 -0
  90. package/dist/generate/kinds/personal-data/columns-of-table.js.map +1 -0
  91. package/dist/generate/kinds/personal-data/declare-personal-data.d.ts.map +1 -1
  92. package/dist/generate/kinds/personal-data/declare-personal-data.js +7 -52
  93. package/dist/generate/kinds/personal-data/declare-personal-data.js.map +1 -1
  94. package/dist/generate/kinds/personal-data/declare-table-personal-fields.d.ts +11 -0
  95. package/dist/generate/kinds/personal-data/declare-table-personal-fields.d.ts.map +1 -0
  96. package/dist/generate/kinds/personal-data/declare-table-personal-fields.js +71 -0
  97. package/dist/generate/kinds/personal-data/declare-table-personal-fields.js.map +1 -0
  98. package/dist/generate/kinds/personal-data/personal-request-of-table.d.ts +11 -0
  99. package/dist/generate/kinds/personal-data/personal-request-of-table.d.ts.map +1 -0
  100. package/dist/generate/kinds/personal-data/personal-request-of-table.js +20 -0
  101. package/dist/generate/kinds/personal-data/personal-request-of-table.js.map +1 -0
  102. package/dist/generate/kinds/personal-data/personal-vars.d.ts +7 -0
  103. package/dist/generate/kinds/personal-data/personal-vars.d.ts.map +1 -1
  104. package/dist/generate/kinds/personal-data/personal-vars.js +14 -11
  105. package/dist/generate/kinds/personal-data/personal-vars.js.map +1 -1
  106. package/dist/generate/kinds/personal-data/schema-table.d.ts +13 -0
  107. package/dist/generate/kinds/personal-data/schema-table.d.ts.map +1 -0
  108. package/dist/generate/kinds/personal-data/schema-table.js +2 -0
  109. package/dist/generate/kinds/personal-data/schema-table.js.map +1 -0
  110. package/dist/generate/kinds/personal-data/schema-tables-of.d.ts +9 -0
  111. package/dist/generate/kinds/personal-data/schema-tables-of.d.ts.map +1 -0
  112. package/dist/generate/kinds/personal-data/schema-tables-of.js +78 -0
  113. package/dist/generate/kinds/personal-data/schema-tables-of.js.map +1 -0
  114. package/dist/generate/kinds/personal-data/table-of-schema.d.ts +15 -0
  115. package/dist/generate/kinds/personal-data/table-of-schema.d.ts.map +1 -0
  116. package/dist/generate/kinds/personal-data/table-of-schema.js +39 -0
  117. package/dist/generate/kinds/personal-data/table-of-schema.js.map +1 -0
  118. package/dist/generate/kinds/personal-data/write-personal-declaration.d.ts +20 -0
  119. package/dist/generate/kinds/personal-data/write-personal-declaration.d.ts.map +1 -0
  120. package/dist/generate/kinds/personal-data/write-personal-declaration.js +63 -0
  121. package/dist/generate/kinds/personal-data/write-personal-declaration.js.map +1 -0
  122. package/dist/generate/kinds/personal-fields-kind.d.ts +3 -0
  123. package/dist/generate/kinds/personal-fields-kind.d.ts.map +1 -0
  124. package/dist/generate/kinds/personal-fields-kind.js +15 -0
  125. package/dist/generate/kinds/personal-fields-kind.js.map +1 -0
  126. package/dist/generate/kinds/projection-kind.d.ts.map +1 -1
  127. package/dist/generate/kinds/projection-kind.js +2 -1
  128. package/dist/generate/kinds/projection-kind.js.map +1 -1
  129. package/dist/generate/kinds/read-model/field-lines.d.ts +11 -0
  130. package/dist/generate/kinds/read-model/field-lines.d.ts.map +1 -0
  131. package/dist/generate/kinds/read-model/field-lines.js +85 -0
  132. package/dist/generate/kinds/read-model/field-lines.js.map +1 -0
  133. package/dist/generate/kinds/read-model/live-rows-check.d.ts +22 -0
  134. package/dist/generate/kinds/read-model/live-rows-check.d.ts.map +1 -0
  135. package/dist/generate/kinds/read-model/live-rows-check.js +47 -0
  136. package/dist/generate/kinds/read-model/live-rows-check.js.map +1 -0
  137. package/dist/generate/kinds/read-model/read-model-fields.d.ts +19 -0
  138. package/dist/generate/kinds/read-model/read-model-fields.d.ts.map +1 -0
  139. package/dist/generate/kinds/read-model/read-model-fields.js +31 -0
  140. package/dist/generate/kinds/read-model/read-model-fields.js.map +1 -0
  141. package/dist/generate/kinds/read-model/read-model-store.d.ts +24 -0
  142. package/dist/generate/kinds/read-model/read-model-store.d.ts.map +1 -0
  143. package/dist/generate/kinds/read-model/read-model-store.js +39 -0
  144. package/dist/generate/kinds/read-model/read-model-store.js.map +1 -0
  145. package/dist/generate/kinds/read-model/read-model-table.d.ts +11 -0
  146. package/dist/generate/kinds/read-model/read-model-table.d.ts.map +1 -0
  147. package/dist/generate/kinds/read-model/read-model-table.js +2 -0
  148. package/dist/generate/kinds/read-model/read-model-table.js.map +1 -0
  149. package/dist/generate/kinds/read-model-kind.d.ts +3 -0
  150. package/dist/generate/kinds/read-model-kind.d.ts.map +1 -0
  151. package/dist/generate/kinds/read-model-kind.js +84 -0
  152. package/dist/generate/kinds/read-model-kind.js.map +1 -0
  153. package/dist/generate/kinds.d.ts.map +1 -1
  154. package/dist/generate/kinds.js +4 -0
  155. package/dist/generate/kinds.js.map +1 -1
  156. package/dist/generate/shared-writes.d.ts.map +1 -1
  157. package/dist/generate/shared-writes.js +8 -0
  158. package/dist/generate/shared-writes.js.map +1 -1
  159. package/dist/help/tool-notes.d.ts.map +1 -1
  160. package/dist/help/tool-notes.js +2 -1
  161. package/dist/help/tool-notes.js.map +1 -1
  162. package/dist/init/files/persistence-files.d.ts.map +1 -1
  163. package/dist/init/files/persistence-files.js +2 -0
  164. package/dist/init/files/persistence-files.js.map +1 -1
  165. package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
  166. package/dist/init/manifest/dependencies-for.js +10 -7
  167. package/dist/init/manifest/dependencies-for.js.map +1 -1
  168. package/dist/init/manifest/versions.js +25 -25
  169. package/dist/layout/fit-block.js +4 -0
  170. package/dist/layout/fit-block.js.map +1 -1
  171. package/dist/presets/no-flags.d.ts.map +1 -1
  172. package/dist/presets/no-flags.js +1 -0
  173. package/dist/presets/no-flags.js.map +1 -1
  174. package/dist/stack/end-to-end-vars.d.ts +9 -0
  175. package/dist/stack/end-to-end-vars.d.ts.map +1 -0
  176. package/dist/stack/end-to-end-vars.js +32 -0
  177. package/dist/stack/end-to-end-vars.js.map +1 -0
  178. package/dist/stack/stack-vars.d.ts.map +1 -1
  179. package/dist/stack/stack-vars.js +2 -0
  180. package/dist/stack/stack-vars.js.map +1 -1
  181. package/dist/version.d.ts +1 -1
  182. package/dist/version.js +1 -1
  183. package/dist/worker/briefing-of.js +2 -2
  184. package/dist/worker/briefing-of.js.map +1 -1
  185. package/package.json +6 -6
  186. package/templates/e2e/e2e-background-job-case.ts.tpl +12 -0
  187. package/templates/e2e/e2e-job.spec.ts.tpl +3 -3
  188. package/templates/init/README.md.tpl +1 -1
  189. package/templates/init/e2e/jest.e2e.config.js.tpl +24 -5
  190. package/templates/init/e2e/start-application.database.ts.tpl +40 -2
  191. package/templates/init/e2e/start-application.memory.ts.tpl +36 -0
  192. package/templates/init/e2e/vitest.e2e.config.ts.tpl +12 -3
  193. package/templates/init/platform/database/open-test-database.drizzle.ts.tpl +22 -4
  194. package/templates/init/platform/database/open-test-database.knex.ts.tpl +21 -3
  195. package/templates/init/platform/database/open-test-database.prisma.ts.tpl +22 -3
  196. package/templates/init/platform/database/open-test-database.typeorm.ts.tpl +22 -3
  197. package/templates/init/platform/database/test-database-clone.ts.tpl +184 -0
  198. package/templates/init/platform/jobs/background-jobs.ts.tpl +4 -0
  199. package/templates/init/platform/jobs/create-background-work.ts.tpl +1 -0
  200. package/templates/init/rules/infrastructure.md.tpl +1 -1
  201. package/templates/personal-data/declaration.drizzle.ts.tpl +6 -1
  202. package/templates/personal-data/declaration.knex.ts.tpl +14 -1
  203. package/templates/personal-data/declaration.prisma.ts.tpl +6 -1
  204. package/templates/personal-data/declaration.typeorm.ts.tpl +21 -1
  205. package/templates/personal-data/spec.table.ts.tpl +39 -0
  206. package/templates/pipeline/package-scripts.json +1 -1
  207. package/templates/projection/projection.manual.ts.tpl +2 -2
  208. package/templates/projection/projection.ts.tpl +2 -2
  209. package/templates/read-model/contract.spec.ts.tpl +95 -0
  210. package/templates/read-model/drizzle/schema.ts.tpl +8 -0
  211. package/templates/read-model/drizzle/store.ts.tpl +41 -0
  212. package/templates/read-model/drizzle/table.tpl +38 -0
  213. package/templates/read-model/fake.ts.tpl +8 -0
  214. package/templates/read-model/knex/store.ts.tpl +41 -0
  215. package/templates/read-model/knex/table.tpl +26 -0
  216. package/templates/read-model/none/store.ts.tpl +17 -0
  217. package/templates/read-model/port.ts.tpl +24 -0
  218. package/templates/read-model/prisma/model.tpl +25 -0
  219. package/templates/read-model/prisma/store.ts.tpl +43 -0
  220. package/templates/read-model/typeorm/schema-export.tpl +4 -0
  221. package/templates/read-model/typeorm/schema.ts.tpl +9 -0
  222. package/templates/read-model/typeorm/store.ts.tpl +30 -0
  223. package/templates/read-model/typeorm/table.tpl +54 -0
  224. package/templates/read-model/wiring.container.tpl +21 -0
  225. package/templates/repository/drizzle/table.tpl +1 -0
  226. package/templates/repository/typeorm/table.tpl +1 -0
@@ -6,10 +6,18 @@ import { connectToDatabase } from '{{alias.platform}}/database/connect-to-databa
6
6
  import { persistenceOver } from '{{alias.platform}}/database/persistence-over{{alias.ext}}';
7
7
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
8
8
  import { TableStatements } from '{{alias.platform}}/database/table-statements{{alias.ext}}';
9
+ import { cloneDatabase } from '{{alias.test}}/support/test-database-clone{{alias.ext}}';
9
10
 
10
11
  export interface TestDatabase {
11
12
  readonly persistence: Persistence;
12
13
 
14
+ /**
15
+ * On a server, the address of the copy this database is: what the configuration of an application
16
+ * under test names, so that nothing it opens from that address reaches the migrated database.
17
+ * Absent in process.
18
+ */
19
+ readonly url?: string;
20
+
13
21
  /** Empties every table{{#if audit.on}} but the audit trail, which is append-only whoever asks{{/if}}: call it before each test. */
14
22
  reset(): Promise<void>;
15
23
 
@@ -19,8 +27,9 @@ export interface TestDatabase {
19
27
  /**
20
28
  * PostgreSQL in process (PGlite) by default, with the tables of ./schema.ts created from their
21
29
  * Drizzle definitions (table-statements.ts): adapter and end-to-end specs need no container and
22
- * no migration run. With a URL, the tests run on that server instead, which must already be
23
- * migrated (`npm run db:migrate`); the migrations remain what production applies.
30
+ * no migration run. With a URL, the tests run on that server instead, each call on a copy of the
31
+ * database the URL names, which must already be migrated (`npm run db:migrate`); the migrations
32
+ * remain what production applies.
24
33
  */
25
34
  export function openTestDatabase(url?: string): Promise<TestDatabase> {
26
35
  return url === undefined ? openInProcess() : openServer(url);
@@ -54,15 +63,24 @@ async function inProcessPostgres(): Promise<PGlite> {
54
63
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
55
64
  }
56
65
 
66
+ /**
67
+ * A database of its own on the server, copied from the migrated one and dropped at close
68
+ * (test/support/test-database-clone.ts): no other file, and no other run, reads or empties its rows.
69
+ */
57
70
  async function openServer(url: string): Promise<TestDatabase> {
58
- const connection = connectToDatabase(url);
71
+ const clone = await cloneDatabase(url);
72
+ const connection = connectToDatabase(clone.url);
59
73
  const statements = new TableStatements();
60
74
 
61
75
  return {
76
+ url: clone.url,
62
77
  persistence: persistenceOver(connection),
63
78
  reset: async () => {
64
79
  await connection.db.execute(sql.raw(statements.emptying()));
65
80
  },
66
- close: () => connection.close(),
81
+ close: async () => {
82
+ await connection.close();
83
+ await clone.drop();
84
+ },
67
85
  };
68
86
  }
@@ -11,10 +11,18 @@ import { AUDIT_SCHEMA, createTables } from '{{alias.platform}}/database/schema{{
11
11
  {{#unless audit.on}}
12
12
  import { createTables } from '{{alias.platform}}/database/schema{{alias.ext}}';
13
13
  {{/unless}}
14
+ import { cloneDatabase } from '{{alias.test}}/support/test-database-clone{{alias.ext}}';
14
15
 
15
16
  export interface TestDatabase {
16
17
  readonly persistence: Persistence;
17
18
 
19
+ /**
20
+ * On a server, the address of the copy this database is: what the configuration of an application
21
+ * under test names, so that nothing it opens from that address reaches the migrated database.
22
+ * Absent in process.
23
+ */
24
+ readonly url?: string;
25
+
18
26
  /** Empties every table{{#if audit.on}} but the audit trail, which is append-only whoever asks{{/if}}: call it before each test. */
19
27
  reset(): Promise<void>;
20
28
 
@@ -24,7 +32,8 @@ export interface TestDatabase {
24
32
  /**
25
33
  * PostgreSQL in process (PGlite, served over the wire protocol) by default, with the tables of
26
34
  * ./schema.ts: adapter and end-to-end specs need no container. With a URL, the tests run on
27
- * that server instead, which must already be migrated (`npm run db:migrate`).
35
+ * that server instead, each call on a copy of the database the URL names, which must already be
36
+ * migrated (`npm run db:migrate`).
28
37
  */
29
38
  export function openTestDatabase(url?: string): Promise<TestDatabase> {
30
39
  return url === undefined ? openInProcess() : openServer(url);
@@ -63,13 +72,22 @@ async function inProcessPostgres(): Promise<PGlite> {
63
72
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
64
73
  }
65
74
 
75
+ /**
76
+ * A database of its own on the server, copied from the migrated one and dropped at close
77
+ * (test/support/test-database-clone.ts): no other file, and no other run, reads or empties its rows.
78
+ */
66
79
  async function openServer(url: string): Promise<TestDatabase> {
67
- const connection = connectToDatabase(url);
80
+ const clone = await cloneDatabase(url);
81
+ const connection = connectToDatabase(clone.url);
68
82
 
69
83
  return {
84
+ url: clone.url,
70
85
  persistence: persistenceOver(connection),
71
86
  reset: () => emptyTables(connection.db),
72
- close: () => connection.close(),
87
+ close: async () => {
88
+ await connection.close();
89
+ await clone.drop();
90
+ },
73
91
  };
74
92
  }
75
93
 
@@ -10,10 +10,18 @@ import type { PrismaClient } from '{{alias.generated}}/prisma/client{{alias.ext}
10
10
  import { createClient } from '{{alias.platform}}/database/create-client{{alias.ext}}';
11
11
  import { persistenceOver } from '{{alias.platform}}/database/persistence-over{{alias.ext}}';
12
12
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
13
+ import { cloneDatabase } from '{{alias.test}}/support/test-database-clone{{alias.ext}}';
13
14
 
14
15
  export interface TestDatabase {
15
16
  readonly persistence: Persistence;
16
17
 
18
+ /**
19
+ * On a server, the address of the copy this database is: what the configuration of an application
20
+ * under test names, so that nothing it opens from that address reaches the migrated database.
21
+ * Absent in process.
22
+ */
23
+ readonly url?: string;
24
+
17
25
  /** Empties every table{{#if audit.on}} but the audit trail, which is append-only whoever asks{{/if}}: call it before each test. */
18
26
  reset(): Promise<void>;
19
27
 
@@ -24,7 +32,8 @@ export interface TestDatabase {
24
32
  * PostgreSQL in process (PGlite, served over the wire protocol) by default, with the tables of
25
33
  * generated/schema.sql, which `npm run db:client` derives from prisma/schema/: adapter
26
34
  * and end-to-end specs need no container. With a URL, the tests run on that server instead,
27
- * which must already be migrated (`npm run db:migrate`).
35
+ * each call on a copy of the database the URL names, which must already be migrated
36
+ * (`npm run db:migrate`).
28
37
  */
29
38
  export function openTestDatabase(url?: string): Promise<TestDatabase> {
30
39
  return url === undefined ? openInProcess() : openServer(url);
@@ -63,10 +72,20 @@ async function inProcessPostgres(): Promise<PGlite> {
63
72
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
64
73
  }
65
74
 
75
+ /**
76
+ * A database of its own on the server, copied from the migrated one and dropped at close
77
+ * (test/support/test-database-clone.ts): no other file, and no other run, reads or empties its rows.
78
+ */
66
79
  async function openServer(url: string): Promise<TestDatabase> {
67
- const client = createClient(url);
80
+ const clone = await cloneDatabase(url);
81
+ const client = createClient(clone.url);
82
+
83
+ const close = async (): Promise<void> => {
84
+ await client.$disconnect();
85
+ await clone.drop();
86
+ };
68
87
 
69
- return { persistence: persistenceOver(client), reset: () => emptyTables(client), close: () => client.$disconnect() };
88
+ return { url: clone.url, persistence: persistenceOver(client), reset: () => emptyTables(client), close };
70
89
  }
71
90
 
72
91
  async function createTables(url: string): Promise<void> {
@@ -11,10 +11,18 @@ import type { Persistence } from '{{alias.platform}}/database/persistence{{alias
11
11
  {{#if audit.on}}
12
12
  import { AUDIT_SCHEMA } from '{{alias.platform}}/database/schema{{alias.ext}}';
13
13
  {{/if}}
14
+ import { cloneDatabase } from '{{alias.test}}/support/test-database-clone{{alias.ext}}';
14
15
 
15
16
  export interface TestDatabase {
16
17
  readonly persistence: Persistence;
17
18
 
19
+ /**
20
+ * On a server, the address of the copy this database is: what the configuration of an application
21
+ * under test names, so that nothing it opens from that address reaches the migrated database.
22
+ * Absent in process.
23
+ */
24
+ readonly url?: string;
25
+
18
26
  /** Empties every table{{#if audit.on}} but the audit trail, which is append-only whoever asks{{/if}}: call it before each test. */
19
27
  reset(): Promise<void>;
20
28
 
@@ -24,7 +32,8 @@ export interface TestDatabase {
24
32
  /**
25
33
  * PostgreSQL in process (PGlite, served over the wire protocol) by default, with the tables
26
34
  * created from the entity schemas: adapter and end-to-end specs need no container. With a URL,
27
- * the tests run on that server instead, which must already be migrated (`npm run db:migrate`).
35
+ * the tests run on that server instead, each call on a copy of the database the URL names, which
36
+ * must already be migrated (`npm run db:migrate`).
28
37
  */
29
38
  export function openTestDatabase(url?: string): Promise<TestDatabase> {
30
39
  return url === undefined ? openInProcess() : openServer(url);
@@ -66,14 +75,24 @@ async function inProcessPostgres(): Promise<PGlite> {
66
75
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
67
76
  }
68
77
 
78
+ /**
79
+ * A database of its own on the server, copied from the migrated one and dropped at close
80
+ * (test/support/test-database-clone.ts): no other file, and no other run, reads or empties its rows.
81
+ */
69
82
  async function openServer(url: string): Promise<TestDatabase> {
70
- const dataSource = createDataSource(url);
83
+ const clone = await cloneDatabase(url);
84
+ const dataSource = createDataSource(clone.url);
71
85
 
72
86
  await dataSource.initialize();
73
87
 
74
88
  const persistence = persistenceOver(dataSource);
75
89
 
76
- return { persistence, reset: () => emptyTables(dataSource), close: () => persistence.close() };
90
+ const close = async (): Promise<void> => {
91
+ await persistence.close();
92
+ await clone.drop();
93
+ };
94
+
95
+ return { url: clone.url, persistence, reset: () => emptyTables(dataSource), close };
77
96
  }
78
97
 
79
98
  // TypeORM creates tables, not schemas.
@@ -0,0 +1,184 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import pg from 'pg';
3
+
4
+ /** The database of one spec file, on the server the run was given. */
5
+ export interface DatabaseClone {
6
+ readonly url: string;
7
+
8
+ /** Drops the database, whoever is still connected to it. */
9
+ drop(): Promise<void>;
10
+ }
11
+
12
+ /** What follows the name of the migrated database in the name of a copy: `<database>_test_<seconds of its date>_<random>`. */
13
+ const MARKER = '_test_';
14
+ /** PostgreSQL keeps 63 bytes of a name: the migrated one is cut so that what follows it always fits. */
15
+ const KEPT_OF_THE_NAME = 38;
16
+ /** No spec file runs for an hour: a copy that old was left by a run that was killed. */
17
+ const LEFTOVER_AFTER_SECONDS = 3600;
18
+ /** The SQLSTATE of a server that refuses to copy a database other sessions are connected to. */
19
+ const OTHER_SESSIONS = '55006';
20
+
21
+ const REFUSALS: Readonly<Record<string, (database: string) => string>> = {
22
+ [OTHER_SESSIONS]: (database) =>
23
+ `The database "${database}" has other sessions (an application that runs, a console, a migration): PostgreSQL copies a database only while nobody else is connected to it. Close them, or give the tests a database of their own.`,
24
+ '42501': (database) =>
25
+ `The role of DATABASE_URL may not copy the database "${database}", and each spec file runs on a copy of it: the role creates databases (alter role <role> createdb) and owns that one (alter database "${database}" owner to <role>).`,
26
+ '3D000': (database) =>
27
+ `The server of DATABASE_URL has no database "${database}": create it, then migrate it (npm run db:migrate).`,
28
+ };
29
+
30
+ /**
31
+ * A copy of the migrated database `url` names (`create database ... template`), for one spec file:
32
+ * files then run at the same time on one server, two runs at once never wait for each other, and
33
+ * nothing a file stores reaches another. The migrated database itself is only read. A copy is
34
+ * dropped when its file closes it; the ones a killed run left are dropped here, an hour later.
35
+ */
36
+ export async function cloneDatabase(url: string): Promise<DatabaseClone> {
37
+ const database = databaseOf(url);
38
+ const name = copyName(database, secondsNow());
39
+
40
+ await onServer(url, async (server) => {
41
+ await dropLeftovers(server, database);
42
+ await copy(server, database, name);
43
+ });
44
+
45
+ const clone = { url: urlOf(url, name), drop: () => onServer(url, (server) => drop(server, name)) };
46
+
47
+ await refuseWithoutTable(clone, database);
48
+
49
+ return clone;
50
+ }
51
+
52
+ /**
53
+ * Runs `work` on a connection of its own to the maintenance database of the server, never to the
54
+ * migrated one: PostgreSQL refuses to copy a database another session is connected to, and the
55
+ * files that start together would be those sessions for one another.
56
+ */
57
+ async function onServer(url: string, work: (server: pg.Client) => Promise<void>): Promise<void> {
58
+ const server = new pg.Client({ connectionString: urlOf(url, maintenanceDatabaseOf(url)) });
59
+
60
+ await server.connect();
61
+
62
+ try {
63
+ await work(server);
64
+ } finally {
65
+ await server.end();
66
+ }
67
+ }
68
+
69
+ /** Only what carries the name the kit gives a copy of this database, with a date an hour old, is ever dropped. */
70
+ async function dropLeftovers(server: pg.Client, database: string): Promise<void> {
71
+ const { rows } = await server.query<{ datname: string }>('select datname from pg_database');
72
+ const oldest = secondsNow() - LEFTOVER_AFTER_SECONDS;
73
+
74
+ for (const { datname } of rows) {
75
+ const created = createdAt(datname, database);
76
+
77
+ if (created !== undefined && created < oldest) {
78
+ // Another file of the run may be dropping the same one.
79
+ await drop(server, datname).catch(() => undefined);
80
+ }
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Another session on the migrated database makes the server wait 5 seconds for it to leave, then
86
+ * refuse: asked once more, since a migration or a console that was ending has ended by then.
87
+ */
88
+ async function copy(server: pg.Client, database: string, name: string): Promise<void> {
89
+ const statement = 'create database ' + quoted(name) + ' template ' + quoted(database);
90
+
91
+ try {
92
+ await server.query(statement).catch((error: unknown) => {
93
+ if (codeOf(error) !== OTHER_SESSIONS) {
94
+ throw error;
95
+ }
96
+
97
+ return server.query(statement);
98
+ });
99
+ } catch (error) {
100
+ throw refusalOf(error, database);
101
+ }
102
+ }
103
+
104
+ async function drop(server: pg.Client, name: string): Promise<void> {
105
+ await server.query('drop database if exists ' + quoted(name) + ' with (force)');
106
+ }
107
+
108
+ /** A server nobody migrated answers `relation does not exist` at the first statement of a spec: said here, with the command. */
109
+ async function refuseWithoutTable(clone: DatabaseClone, database: string): Promise<void> {
110
+ const connection = new pg.Client({ connectionString: clone.url });
111
+
112
+ await connection.connect();
113
+
114
+ const { rows } = await connection.query(
115
+ "select 1 from information_schema.tables where table_schema not in ('pg_catalog', 'information_schema') limit 1",
116
+ );
117
+
118
+ await connection.end();
119
+
120
+ if (rows.length === 0) {
121
+ await clone.drop();
122
+
123
+ throw new Error(`The database "${database}" holds no table: migrate it first (npm run db:migrate).`);
124
+ }
125
+ }
126
+
127
+ function refusalOf(error: unknown, database: string): unknown {
128
+ const refusal = REFUSALS[codeOf(error)];
129
+
130
+ return refusal === undefined ? error : new Error(refusal(database), { cause: error });
131
+ }
132
+
133
+ /** The SQLSTATE of an error of the server, empty for any other error. */
134
+ function codeOf(error: unknown): string {
135
+ const code: unknown = error instanceof Error ? Reflect.get(error, 'code') : undefined;
136
+
137
+ return typeof code === 'string' ? code : '';
138
+ }
139
+
140
+ function copyName(database: string, seconds: number): string {
141
+ return prefixOf(database) + String(seconds) + '_' + randomBytes(4).toString('hex');
142
+ }
143
+
144
+ /** When the copy named `name` was made, in seconds; undefined for a database that is not a copy of `database`. */
145
+ function createdAt(name: string, database: string): number | undefined {
146
+ const prefix = prefixOf(database);
147
+ const [seconds, random, ...rest] = name.slice(prefix.length).split('_');
148
+
149
+ if (!name.startsWith(prefix) || seconds === undefined || random === undefined || rest.length > 0) {
150
+ return undefined;
151
+ }
152
+
153
+ return /^\d{10}$/.test(seconds) && /^[0-9a-f]{8}$/.test(random) ? Number(seconds) : undefined;
154
+ }
155
+
156
+ function prefixOf(database: string): string {
157
+ return database.slice(0, KEPT_OF_THE_NAME) + MARKER;
158
+ }
159
+
160
+ function secondsNow(): number {
161
+ return Math.floor(Date.now() / 1000);
162
+ }
163
+
164
+ function databaseOf(url: string): string {
165
+ return decodeURIComponent(new URL(url).pathname.slice(1));
166
+ }
167
+
168
+ /** `postgres`, which every server has; `template1` when the migrated database is that one. */
169
+ function maintenanceDatabaseOf(url: string): string {
170
+ return databaseOf(url) === 'postgres' ? 'template1' : 'postgres';
171
+ }
172
+
173
+ /** The same server, role and parameters, another database. */
174
+ function urlOf(url: string, database: string): string {
175
+ const address = new URL(url);
176
+
177
+ address.pathname = '/' + encodeURIComponent(database);
178
+
179
+ return address.toString();
180
+ }
181
+
182
+ function quoted(name: string): string {
183
+ return '"' + name.replaceAll('"', '""') + '"';
184
+ }
@@ -1,4 +1,5 @@
1
1
  import type { BackgroundJob, BackgroundJobOptions, BackgroundJobPayloadSchema } from '@ddd-ts-kit/kernel';
2
+ import type { BackgroundJobRun } from '@ddd-ts-kit/scheduling';
2
3
 
3
4
  /** A background job class: named by its static `jobName`, built from what its constructor takes, its stored payload read with its static `payload`. */
4
5
  export interface BackgroundJobClass<Deps extends readonly unknown[]> {
@@ -19,4 +20,7 @@ export interface BackgroundJobs {
19
20
  start(): Promise<void>;
20
21
 
21
22
  stop(): Promise<void>;
23
+
24
+ /** Runs every job due now until none is left and answers the attempts: for a test, or a command run once. Not while the worker runs. */
25
+ runDue(): Promise<BackgroundJobRun[]>;
22
26
  }
@@ -151,6 +151,7 @@ function backgroundJobsOn(worker: QueueWorker, traced: TracedApplication): Backg
151
151
  },
152
152
  start: () => worker.start(),
153
153
  stop: () => worker.stop(),
154
+ runDue: () => worker.runDue(),
154
155
  };
155
156
  }
156
157
 
@@ -35,7 +35,7 @@ paths:
35
35
  - The repository adapter of an event-sourced aggregate delegates to `EventSourcedRepository` of the kernel. Its stored events are declared in `persistence/<aggregate>-events.mapper.ts` with `defineStoredEvent` and a named type of their data; a change of that type is a new version with its upcaster, never an edit (`event-sourcing/upcaster-required`, against `stored-events.lock.json`, which `ddd-ts-kit docs --stored-events` writes once the shape of a version is final; `docs --check` fails while a version is unrecorded). Every named type the data reaches is declared in the codec file too.
36
36
  {{/if}}
37
37
  {{#if search.opensearch}}
38
- - A read model kept in OpenSearch is written by hand, no generator yet: `class SearchInvoiceList extends OpenSearchReadModelStore<InvoiceRow> implements InvoiceList`, whose constructor takes `SearchIndexes` of the platform and calls `super(search.options('billing_invoices', invoiceCriteria))`; its name starts with the context, and nothing else of `@ddd-ts-kit/opensearch` is named here (`search/store-from-platform`). It is a copy for reading, written by its projection (`upsertIfNewer` with the stamp of the event, `delete` that keeps a tombstone) and rebuilt from the events: never read to decide an invariant or a right. It passes `readModelRowsContract` and `criteriaContract` of `@ddd-ts-kit/testing/contracts`, on a node the run names (`OPENSEARCH_URL`); the specs of the context bind its port to `InMemoryReadModelStore` of the kernel.
38
+ - A read model kept in OpenSearch is written by hand, no generator yet: `class SearchInvoiceList extends OpenSearchReadModelStore<InvoiceRow> implements InvoiceList`, whose constructor takes `SearchIndexes` of the platform and calls `super(search.options('billing_invoices', invoiceCriteria))`; its name starts with the context, and nothing else of `@ddd-ts-kit/opensearch` is named here (`search/store-from-platform`). It is a copy for reading, written by its projection (`upsertIfNewer` with the stamp of the event, `updateIfNewer` for an event that changes a row another event created, `delete` that keeps a tombstone) and rebuilt from the events: never read to decide an invariant or a right. It passes `readModelRowsContract` and `criteriaContract` of `@ddd-ts-kit/testing/contracts`, on a node the run names (`OPENSEARCH_URL`); the specs of the context bind its port to `InMemoryReadModelStore` of the kernel.
39
39
  {{/if}}
40
40
  - Infrastructure faults are plain errors (a 5xx, reported from outside); business refusals are `DomainError`s raised by the domain.
41
41
  - Every adapter passes the contract suite of the fake of its port (`test/integration/*.contract.spec.ts`).
@@ -7,14 +7,19 @@ type {{aggregate.pascal}}Row = typeof {{aggregate.tableCamel}}.$inferSelect;
7
7
  * What `{{aggregate.table}}` keeps of a person in clear, and whose it is: the columns below belong to the person
8
8
  * `{{personal.subject}}` names{{#if personal.pseudonymise}}, and each reads `[erased]` once that person is erased{{/if}}{{#if personal.row}}, and their row is deleted once that person is erased{{/if}}.
9
9
  * Read by {{personal.names.adapter}}, which `npm run privacy:erase` runs; a column added later that holds
10
- * personal data is declared here too, and its mapper writes it.
10
+ * personal data is declared here too{{#unless personal.ofTable}}, and its mapper writes it{{/unless}}.
11
11
  */
12
12
  const declaration: PersonalFieldsOptions<{{aggregate.pascal}}Row> = {
13
13
  subject: '{{personal.subject}}',
14
14
  {{personal.fields}}
15
15
  erasure: '{{personal.erasure}}',
16
16
  {{#if personal.retains}}
17
+ {{#unless personal.ofTable}}
17
18
  // TODO(domain): the mapper writes {{personal.retentionColumn}} empty: write the date the relation with the person ended (the contract closed, the account deleted), or these rows never expire. Never count from the registration.
19
+ {{/unless}}
20
+ {{#if personal.ofTable}}
21
+ // TODO(domain): what writes {{aggregate.table}} writes in {{personal.retentionColumn}} the date the relation with the person ended (the contract closed, the account deleted), or these rows never expire. Never count from the registration.
22
+ {{/if}}
18
23
  retention: {{personal.retention}},
19
24
  {{/if}}
20
25
  };
@@ -1,6 +1,8 @@
1
1
  import { personalFields, type PersonalFieldsOptions } from '@ddd-ts-kit/kernel';
2
2
  import { {{context.constant}}_SCHEMA } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
3
+ {{#unless personal.ofTable}}
3
4
  import type { {{aggregate.pascal}}Row } from '{{alias.context}}/infrastructure/persistence/{{aggregate.kebab}}-row.schema{{alias.ext}}';
5
+ {{/unless}}
4
6
 
5
7
  /** The table as the erasure reaches it: its statements are written on the table{{#if tenant.scoped}}, confined to the tenant of the work{{/if}}. */
6
8
  const TABLE = { schema: {{context.constant}}_SCHEMA, table: '{{aggregate.table}}' };
@@ -9,14 +11,25 @@ const TABLE = { schema: {{context.constant}}_SCHEMA, table: '{{aggregate.table}}
9
11
  * What `{{aggregate.table}}` keeps of a person in clear, and whose it is: the columns below belong to the person
10
12
  * `{{personal.subject}}` names{{#if personal.pseudonymise}}, and each reads `[erased]` once that person is erased{{/if}}{{#if personal.row}}, and their row is deleted once that person is erased{{/if}}.
11
13
  * Read by {{personal.names.adapter}}, which `npm run privacy:erase` runs; a column added later that holds
12
- * personal data is declared here too, and its mapper writes it.
14
+ * personal data is declared here too{{#unless personal.ofTable}}, and its mapper writes it{{/unless}}.
13
15
  */
16
+ {{#if personal.ofTable}}
17
+ // The columns are named as the database spells them: no row type of the project describes this table.
18
+ const declaration: PersonalFieldsOptions<Record<string, unknown>> = {
19
+ {{/if}}
20
+ {{#unless personal.ofTable}}
14
21
  const declaration: PersonalFieldsOptions<{{aggregate.pascal}}Row> = {
22
+ {{/unless}}
15
23
  subject: '{{personal.subject}}',
16
24
  {{personal.fields}}
17
25
  erasure: '{{personal.erasure}}',
18
26
  {{#if personal.retains}}
27
+ {{#unless personal.ofTable}}
19
28
  // TODO(domain): the mapper writes {{personal.retentionColumn}} empty: write the date the relation with the person ended (the contract closed, the account deleted), or these rows never expire. Never count from the registration.
29
+ {{/unless}}
30
+ {{#if personal.ofTable}}
31
+ // TODO(domain): what writes {{aggregate.table}} writes in {{personal.retentionColumn}} the date the relation with the person ended (the contract closed, the account deleted), or these rows never expire. Never count from the registration.
32
+ {{/if}}
20
33
  retention: {{personal.retention}},
21
34
  {{/if}}
22
35
  };
@@ -8,7 +8,7 @@ const TABLE: PrismaPersonalTable = { schema: '{{context.schema}}', table: '{{agg
8
8
  * What `{{aggregate.table}}` keeps of a person in clear, and whose it is: the columns below belong to the person
9
9
  * `{{personal.subject}}` names{{#if personal.pseudonymise}}, and each reads `[erased]` once that person is erased{{/if}}{{#if personal.row}}, and their row is deleted once that person is erased{{/if}}.
10
10
  * Read by {{personal.names.adapter}}, which `npm run privacy:erase` runs; a column added later that holds
11
- * personal data is declared here too, and its mapper writes it.
11
+ * personal data is declared here too{{#unless personal.ofTable}}, and its mapper writes it{{/unless}}.
12
12
  */
13
13
  // The columns are named as the database spells them (`@map`), since the erasure writes SQL on the table.
14
14
  const declaration: PersonalFieldsOptions<Record<string, unknown>> = {
@@ -16,7 +16,12 @@ const declaration: PersonalFieldsOptions<Record<string, unknown>> = {
16
16
  {{personal.fields}}
17
17
  erasure: '{{personal.erasure}}',
18
18
  {{#if personal.retains}}
19
+ {{#unless personal.ofTable}}
19
20
  // TODO(domain): the mapper writes {{personal.retentionColumn}} empty: write the date the relation with the person ended (the contract closed, the account deleted), or these rows never expire. Never count from the registration.
21
+ {{/unless}}
22
+ {{#if personal.ofTable}}
23
+ // TODO(domain): what writes {{aggregate.table}} writes in {{personal.retentionColumn}} the date the relation with the person ended (the contract closed, the account deleted), or these rows never expire. Never count from the registration.
24
+ {{/if}}
20
25
  retention: {{personal.retention}},
21
26
  {{/if}}
22
27
  };
@@ -1,19 +1,39 @@
1
+ {{#if personal.ofTable}}
2
+ import type { EntitySchema } from 'typeorm';
3
+ {{/if}}
1
4
  import { personalFields, type PersonalFieldsOptions } from '@ddd-ts-kit/kernel';
2
5
  import { {{aggregate.tableCamel}} } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
6
+ {{#unless personal.ofTable}}
3
7
  import type { {{aggregate.pascal}}Row } from '{{alias.context}}/infrastructure/persistence/{{aggregate.kebab}}-row.schema{{alias.ext}}';
8
+ {{/unless}}
9
+ {{#if personal.ofTable}}
10
+
11
+ /** The row an entity schema types. */
12
+ type RowOf<Schema> = Schema extends EntitySchema<infer Row> ? Row : never;
13
+ {{/if}}
4
14
 
5
15
  /**
6
16
  * What `{{aggregate.table}}` keeps of a person in clear, and whose it is: the columns below belong to the person
7
17
  * `{{personal.subject}}` names{{#if personal.pseudonymise}}, and each reads `[erased]` once that person is erased{{/if}}{{#if personal.row}}, and their row is deleted once that person is erased{{/if}}.
8
18
  * Read by {{personal.names.adapter}}, which `npm run privacy:erase` runs; a column added later that holds
9
- * personal data is declared here too, and its mapper writes it.
19
+ * personal data is declared here too{{#unless personal.ofTable}}, and its mapper writes it{{/unless}}.
10
20
  */
21
+ {{#if personal.ofTable}}
22
+ const declaration: PersonalFieldsOptions<RowOf<typeof {{aggregate.tableCamel}}>> = {
23
+ {{/if}}
24
+ {{#unless personal.ofTable}}
11
25
  const declaration: PersonalFieldsOptions<{{aggregate.pascal}}Row> = {
26
+ {{/unless}}
12
27
  subject: '{{personal.subject}}',
13
28
  {{personal.fields}}
14
29
  erasure: '{{personal.erasure}}',
15
30
  {{#if personal.retains}}
31
+ {{#unless personal.ofTable}}
16
32
  // TODO(domain): the mapper writes {{personal.retentionColumn}} empty: write the date the relation with the person ended (the contract closed, the account deleted), or these rows never expire. Never count from the registration.
33
+ {{/unless}}
34
+ {{#if personal.ofTable}}
35
+ // TODO(domain): what writes {{aggregate.table}} writes in {{personal.retentionColumn}} the date the relation with the person ended (the contract closed, the account deleted), or these rows never expire. Never count from the registration.
36
+ {{/if}}
17
37
  retention: {{personal.retention}},
18
38
  {{/if}}
19
39
  };
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it } from '{{tests.module}}';
2
+ import { {{personal.names.fake}} } from '{{alias.context}}/test/fakes/{{personal.names.portKebab}}.fake{{alias.ext}}';
3
+ import { {{personal.names.exportFake}} } from '{{alias.context}}/test/fakes/{{personal.names.exportPortKebab}}.fake{{alias.ext}}';
4
+
5
+ /** The source every record of `{{aggregate.table}}` names: the context, then the table. */
6
+ const SOURCE = '{{context.kebab}}.{{aggregate.table}}';
7
+
8
+ // TODO(domain): no aggregate owns {{aggregate.table}}, so no repository nor builder writes its rows here. Open the test database (openTestDatabase of the platform), insert the rows of two people as the project writes that table, build {{personal.names.adapter}} and {{personal.names.exportAdapter}} on it, and replace each entry below by its test.
9
+ describe('{{personal.names.adapter}}, on {{aggregate.table}}', () => {
10
+ it.todo('erases what the table keeps of the subject, as the declaration says, and leaves the others');
11
+ it.todo('reaches nothing the second time: an erasure run again completes one that failed half way');
12
+ {{#if personal.retains}}
13
+ it.todo('erases the rows whose retention ended, as the declaration says, and leaves the others');
14
+ {{/if}}
15
+ });
16
+
17
+ describe('{{personal.names.exportAdapter}}, on {{aggregate.table}}', () => {
18
+ it.todo('hands over the columns of the subject as plain data, under its source, and nothing of the others');
19
+ it.todo('answers what the row reads once the subject is erased');
20
+ });
21
+
22
+ describe('{{personal.names.fake}} and {{personal.names.exportFake}}', () => {
23
+ it('counts the rows it holds of a person, and forgets them at the first erasure', async () => {
24
+ const fake = new {{personal.names.fake}}().holds('ada', 2);
25
+
26
+ expect(await fake.erase('ada')).toBe(2);
27
+ expect(await fake.erase('ada')).toBe(0);
28
+ expect(fake.erased).toEqual(['ada', 'ada']);
29
+ });
30
+
31
+ it('hands over the records it holds of a person, and remembers who was asked', async () => {
32
+ const record = { source: SOURCE, values: { kept: 'of ada' } };
33
+ const fake = new {{personal.names.exportFake}}().holds('ada', record);
34
+
35
+ expect(await fake.exportOf('ada')).toEqual([record]);
36
+ expect(await fake.exportOf('bob')).toEqual([]);
37
+ expect(fake.asked).toEqual(['ada', 'bob']);
38
+ });
39
+ });
@@ -23,7 +23,7 @@
23
23
  "@biomejs/biome": "2.6.4",
24
24
  "@commitlint/cli": "^21.2.3",
25
25
  "@commitlint/config-conventional": "^21.2.3",
26
- "@ddd-ts-kit/eslint-plugin": "^0.110.0",
26
+ "@ddd-ts-kit/eslint-plugin": "^0.111.0",
27
27
  "@eslint/js": "^10.0.1",
28
28
  "@typescript/native": "npm:typescript@~7.0.2",
29
29
  "@vitest/coverage-v8": "^5.0.3",
@@ -1,8 +1,8 @@
1
1
  import { type {{event.typeName}} } from '{{alias.contexts}}/{{publisher.kebab}}/published-language{{alias.index}}';
2
2
 
3
- // TODO(domain): receive the port of the read model "{{name.words}}" keeps in the constructor, typed by that port (an abstract class of application/ports that extends `ReadModelStore<Row>` of the kernel: `ddd-ts-kit generate port {{context.kebab}} <Name>`), and pass the adapter (or its fake) where the module file of the context builds the projection.
3
+ // TODO(domain): receive the port of the read model "{{name.words}}" keeps in the constructor, typed by that port (`ddd-ts-kit generate read-model {{context.kebab}} <Name> --field <name>:<type>` writes it with its table, its store adapter and its fake), and pass the adapter (or its fake) where the module file of the context builds the projection.
4
4
  export class {{name.pascal}}Projection {
5
5
  async {{event.method}}(event: {{event.typeName}}): Promise<void> {
6
- // TODO(domain): write what {{event.type}} says into the read model through its port and answer what the store answers, `return this.<port>.upsertIfNewer(<id>, stampOf(event), () => ({ ... }))` with `stampOf` of the kernel: the stamp keeps a replay or a late delivery from undoing a newer line, and the answer is how the application counts what was applied.
6
+ // TODO(domain): write what {{event.type}} says into the read model through its port and answer what the store answers, `return this.<port>.upsertIfNewer(<id>, stampOf(event), () => ({ ... }))` with `stampOf` of the kernel when the event says the whole line (right in any order of delivery), or `this.<port>.updateIfNewer(<id>, stampOf(event), (line) => ({ ...line, ... }))` when it changes part of a line another event created, which answers `'missing'` when that line is not there. The stamp keeps a replay or a late delivery from undoing a newer line, and the answer is how the application counts what was applied.
7
7
  }
8
8
  }
@@ -1,11 +1,11 @@
1
1
  import { On, Projection } from '@ddd-ts-kit/kernel/declarations';
2
2
  import { {{event.definition}}, type {{event.typeName}} } from '{{alias.contexts}}/{{publisher.kebab}}/published-language{{alias.index}}';
3
3
 
4
- // TODO(domain): receive the port of the read model "{{name.words}}" keeps in the constructor, typed by that port (an abstract class of application/ports that extends `ReadModelStore<Row>` of the kernel: `ddd-ts-kit generate port {{context.kebab}} <Name>`); its adapter and its fake are bound to it like any other port.
4
+ // TODO(domain): receive the port of the read model "{{name.words}}" keeps in the constructor, typed by that port (`ddd-ts-kit generate read-model {{context.kebab}} <Name> --field <name>:<type>` writes it with its table, its store adapter and its fake); its adapter and its fake are bound to it like any other port.
5
5
  @Projection('{{context.kebab}}.{{name.kebab}}')
6
6
  export class {{name.pascal}}Projection {
7
7
  @On({{event.definition}})
8
8
  async {{event.method}}(event: {{event.typeName}}): Promise<void> {
9
- // TODO(domain): write what {{event.type}} says into the read model through its port and answer what the store answers, `return this.<port>.upsertIfNewer(<id>, stampOf(event), () => ({ ... }))` with `stampOf` of the kernel: the stamp keeps a replay or a late delivery from undoing a newer line, and the answer is how the application counts what was applied.
9
+ // TODO(domain): write what {{event.type}} says into the read model through its port and answer what the store answers, `return this.<port>.upsertIfNewer(<id>, stampOf(event), () => ({ ... }))` with `stampOf` of the kernel when the event says the whole line (right in any order of delivery), or `this.<port>.updateIfNewer(<id>, stampOf(event), (line) => ({ ...line, ... }))` when it changes part of a line another event created, which answers `'missing'` when that line is not there. The stamp keeps a replay or a late delivery from undoing a newer line, and the answer is how the application counts what was applied.
10
10
  }
11
11
  }