ddd-ts-kit 0.110.1 → 0.112.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (633) hide show
  1. package/CHANGELOG.md +164 -0
  2. package/README.fr.md +39 -8
  3. package/README.md +36 -7
  4. package/dist/alias/index.d.ts +2 -0
  5. package/dist/alias/index.d.ts.map +1 -1
  6. package/dist/alias/index.js +2 -0
  7. package/dist/alias/index.js.map +1 -1
  8. package/dist/alias/neighbour-sources.d.ts +17 -0
  9. package/dist/alias/neighbour-sources.d.ts.map +1 -0
  10. package/dist/alias/neighbour-sources.js +11 -0
  11. package/dist/alias/neighbour-sources.js.map +1 -0
  12. package/dist/alias/neighbour-suffix.d.ts +8 -0
  13. package/dist/alias/neighbour-suffix.d.ts.map +1 -0
  14. package/dist/alias/neighbour-suffix.js +10 -0
  15. package/dist/alias/neighbour-suffix.js.map +1 -0
  16. package/dist/build/rewrite-aliases.d.ts.map +1 -1
  17. package/dist/build/rewrite-aliases.js +11 -0
  18. package/dist/build/rewrite-aliases.js.map +1 -1
  19. package/dist/check/alias/build-scripts.d.ts.map +1 -1
  20. package/dist/check/alias/build-scripts.js +4 -8
  21. package/dist/check/alias/build-scripts.js.map +1 -1
  22. package/dist/check/alias/compiler-options-of.d.ts +3 -3
  23. package/dist/check/alias/compiler-options-of.js +17 -6
  24. package/dist/check/alias/compiler-options-of.js.map +1 -1
  25. package/dist/check/alias/neighbour-sources.d.ts +12 -0
  26. package/dist/check/alias/neighbour-sources.d.ts.map +1 -0
  27. package/dist/check/alias/neighbour-sources.js +80 -0
  28. package/dist/check/alias/neighbour-sources.js.map +1 -0
  29. package/dist/check/alias/script-steps.d.ts +11 -0
  30. package/dist/check/alias/script-steps.d.ts.map +1 -0
  31. package/dist/check/alias/script-steps.js +22 -0
  32. package/dist/check/alias/script-steps.js.map +1 -0
  33. package/dist/check/aspects/adapter-policies.d.ts +10 -0
  34. package/dist/check/aspects/adapter-policies.d.ts.map +1 -0
  35. package/dist/check/aspects/adapter-policies.js +104 -0
  36. package/dist/check/aspects/adapter-policies.js.map +1 -0
  37. package/dist/check/aspects/adapter-policy.d.ts +18 -0
  38. package/dist/check/aspects/adapter-policy.d.ts.map +1 -0
  39. package/dist/check/aspects/adapter-policy.js +2 -0
  40. package/dist/check/aspects/adapter-policy.js.map +1 -0
  41. package/dist/check/aspects/is-under-condition.d.ts +7 -0
  42. package/dist/check/aspects/is-under-condition.d.ts.map +1 -0
  43. package/dist/check/aspects/is-under-condition.js +50 -0
  44. package/dist/check/aspects/is-under-condition.js.map +1 -0
  45. package/dist/check/aspects/stated-policy.d.ts +18 -0
  46. package/dist/check/aspects/stated-policy.d.ts.map +1 -0
  47. package/dist/check/aspects/stated-policy.js +39 -0
  48. package/dist/check/aspects/stated-policy.js.map +1 -0
  49. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  50. package/dist/check/catalogue/architecture-rules.js +4 -0
  51. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  52. package/dist/check/explain/imports-docs.d.ts.map +1 -1
  53. package/dist/check/explain/imports-docs.js +5 -3
  54. package/dist/check/explain/imports-docs.js.map +1 -1
  55. package/dist/check/explain/persistence-docs.d.ts.map +1 -1
  56. package/dist/check/explain/persistence-docs.js +21 -0
  57. package/dist/check/explain/persistence-docs.js.map +1 -1
  58. package/dist/check/explain/standard-docs.d.ts.map +1 -1
  59. package/dist/check/explain/standard-docs.js +16 -0
  60. package/dist/check/explain/standard-docs.js.map +1 -1
  61. package/dist/check/explain/tenancy-docs.d.ts.map +1 -1
  62. package/dist/check/explain/tenancy-docs.js +3 -1
  63. package/dist/check/explain/tenancy-docs.js.map +1 -1
  64. package/dist/check/files/kit-content-types.d.ts +12 -0
  65. package/dist/check/files/kit-content-types.d.ts.map +1 -0
  66. package/dist/check/files/kit-content-types.js +38 -0
  67. package/dist/check/files/kit-content-types.js.map +1 -0
  68. package/dist/check/files/upload-content-defect.d.ts +7 -0
  69. package/dist/check/files/upload-content-defect.d.ts.map +1 -0
  70. package/dist/check/files/upload-content-defect.js +2 -0
  71. package/dist/check/files/upload-content-defect.js.map +1 -0
  72. package/dist/check/files/upload-content-defects.d.ts +9 -0
  73. package/dist/check/files/upload-content-defects.d.ts.map +1 -0
  74. package/dist/check/files/upload-content-defects.js +54 -0
  75. package/dist/check/files/upload-content-defects.js.map +1 -0
  76. package/dist/check/files/upload-declaration.d.ts +7 -0
  77. package/dist/check/files/upload-declaration.d.ts.map +1 -0
  78. package/dist/check/files/upload-declaration.js +2 -0
  79. package/dist/check/files/upload-declaration.js.map +1 -0
  80. package/dist/check/files/upload-declarations.d.ts +9 -0
  81. package/dist/check/files/upload-declarations.d.ts.map +1 -0
  82. package/dist/check/files/upload-declarations.js +41 -0
  83. package/dist/check/files/upload-declarations.js.map +1 -0
  84. package/dist/check/fixtures/alias-declared-fixtures.d.ts.map +1 -1
  85. package/dist/check/fixtures/alias-declared-fixtures.js +95 -1
  86. package/dist/check/fixtures/alias-declared-fixtures.js.map +1 -1
  87. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  88. package/dist/check/fixtures/fixtures.js +2 -0
  89. package/dist/check/fixtures/fixtures.js.map +1 -1
  90. package/dist/check/fixtures/imports-fixtures.d.ts.map +1 -1
  91. package/dist/check/fixtures/imports-fixtures.js +97 -0
  92. package/dist/check/fixtures/imports-fixtures.js.map +1 -1
  93. package/dist/check/fixtures/standard-fixtures.d.ts.map +1 -1
  94. package/dist/check/fixtures/standard-fixtures.js +42 -0
  95. package/dist/check/fixtures/standard-fixtures.js.map +1 -1
  96. package/dist/check/fixtures/tenancy-advisory-lock-fixtures.d.ts +9 -0
  97. package/dist/check/fixtures/tenancy-advisory-lock-fixtures.d.ts.map +1 -0
  98. package/dist/check/fixtures/tenancy-advisory-lock-fixtures.js +45 -0
  99. package/dist/check/fixtures/tenancy-advisory-lock-fixtures.js.map +1 -0
  100. package/dist/check/fixtures/tenancy-fixtures.d.ts.map +1 -1
  101. package/dist/check/fixtures/tenancy-fixtures.js +2 -0
  102. package/dist/check/fixtures/tenancy-fixtures.js.map +1 -1
  103. package/dist/check/fixtures/upload-fixtures.d.ts +3 -0
  104. package/dist/check/fixtures/upload-fixtures.d.ts.map +1 -0
  105. package/dist/check/fixtures/upload-fixtures.js +94 -0
  106. package/dist/check/fixtures/upload-fixtures.js.map +1 -0
  107. package/dist/check/migrations/is-working-migration.d.ts +6 -0
  108. package/dist/check/migrations/is-working-migration.d.ts.map +1 -0
  109. package/dist/check/migrations/is-working-migration.js +8 -0
  110. package/dist/check/migrations/is-working-migration.js.map +1 -0
  111. package/dist/check/migrations/journal-entries.d.ts +4 -0
  112. package/dist/check/migrations/journal-entries.d.ts.map +1 -0
  113. package/dist/check/migrations/journal-entries.js +21 -0
  114. package/dist/check/migrations/journal-entries.js.map +1 -0
  115. package/dist/check/migrations/read-drizzle-migrations.d.ts.map +1 -1
  116. package/dist/check/migrations/read-drizzle-migrations.js +4 -9
  117. package/dist/check/migrations/read-drizzle-migrations.js.map +1 -1
  118. package/dist/check/modules/imported-modules.d.ts +4 -0
  119. package/dist/check/modules/imported-modules.d.ts.map +1 -0
  120. package/dist/check/modules/imported-modules.js +5 -0
  121. package/dist/check/modules/imported-modules.js.map +1 -0
  122. package/dist/check/modules/module-imports.d.ts +17 -0
  123. package/dist/check/modules/module-imports.d.ts.map +1 -0
  124. package/dist/check/modules/module-imports.js +23 -0
  125. package/dist/check/modules/module-imports.js.map +1 -0
  126. package/dist/check/project/assemble-project.d.ts.map +1 -1
  127. package/dist/check/project/assemble-project.js +1 -8
  128. package/dist/check/project/assemble-project.js.map +1 -1
  129. package/dist/check/project/file-severity.d.ts +4 -0
  130. package/dist/check/project/file-severity.d.ts.map +1 -0
  131. package/dist/check/project/file-severity.js +11 -0
  132. package/dist/check/project/file-severity.js.map +1 -0
  133. package/dist/check/project/load-project.js +1 -10
  134. package/dist/check/project/load-project.js.map +1 -1
  135. package/dist/check/project/not-in-the-tree.d.ts +10 -0
  136. package/dist/check/project/not-in-the-tree.d.ts.map +1 -0
  137. package/dist/check/project/not-in-the-tree.js +17 -0
  138. package/dist/check/project/not-in-the-tree.js.map +1 -0
  139. package/dist/check/project/skipped-directories.d.ts +3 -0
  140. package/dist/check/project/skipped-directories.d.ts.map +1 -0
  141. package/dist/check/project/skipped-directories.js +3 -0
  142. package/dist/check/project/skipped-directories.js.map +1 -0
  143. package/dist/check/project/walk-directory.d.ts.map +1 -1
  144. package/dist/check/project/walk-directory.js +1 -1
  145. package/dist/check/project/walk-directory.js.map +1 -1
  146. package/dist/check/rules/aspects-timeout-covers-delegate.d.ts +3 -0
  147. package/dist/check/rules/aspects-timeout-covers-delegate.d.ts.map +1 -0
  148. package/dist/check/rules/aspects-timeout-covers-delegate.js +179 -0
  149. package/dist/check/rules/aspects-timeout-covers-delegate.js.map +1 -0
  150. package/dist/check/rules/files-upload-content-rule.d.ts +3 -0
  151. package/dist/check/rules/files-upload-content-rule.d.ts.map +1 -0
  152. package/dist/check/rules/files-upload-content-rule.js +25 -0
  153. package/dist/check/rules/files-upload-content-rule.js.map +1 -0
  154. package/dist/check/rules/imports-alias-declared.d.ts.map +1 -1
  155. package/dist/check/rules/imports-alias-declared.js +3 -1
  156. package/dist/check/rules/imports-alias-declared.js.map +1 -1
  157. package/dist/check/rules/imports-alias-only.d.ts.map +1 -1
  158. package/dist/check/rules/imports-alias-only.js +86 -7
  159. package/dist/check/rules/imports-alias-only.js.map +1 -1
  160. package/dist/check/rules/module-no-cycle.d.ts.map +1 -1
  161. package/dist/check/rules/module-no-cycle.js +12 -34
  162. package/dist/check/rules/module-no-cycle.js.map +1 -1
  163. package/dist/check/rules/privacy-declared-field.js +1 -1
  164. package/dist/check/rules/privacy-declared-field.js.map +1 -1
  165. package/dist/check/rules/tenancy-scoped-statement.d.ts.map +1 -1
  166. package/dist/check/rules/tenancy-scoped-statement.js +11 -3
  167. package/dist/check/rules/tenancy-scoped-statement.js.map +1 -1
  168. package/dist/cli-error.d.ts +7 -2
  169. package/dist/cli-error.d.ts.map +1 -1
  170. package/dist/cli-error.js +8 -2
  171. package/dist/cli-error.js.map +1 -1
  172. package/dist/commands/generate.js +3 -0
  173. package/dist/commands/generate.js.map +1 -1
  174. package/dist/commands/knex-generate.d.ts.map +1 -1
  175. package/dist/commands/knex-generate.js +2 -1
  176. package/dist/commands/knex-generate.js.map +1 -1
  177. package/dist/commands/move-to-module.d.ts +6 -1
  178. package/dist/commands/move-to-module.d.ts.map +1 -1
  179. package/dist/commands/move-to-module.js +28 -3
  180. package/dist/commands/move-to-module.js.map +1 -1
  181. package/dist/commands/prisma-generate.d.ts.map +1 -1
  182. package/dist/commands/prisma-generate.js +2 -1
  183. package/dist/commands/prisma-generate.js.map +1 -1
  184. package/dist/commands/typeorm-generate.d.ts.map +1 -1
  185. package/dist/commands/typeorm-generate.js +2 -1
  186. package/dist/commands/typeorm-generate.js.map +1 -1
  187. package/dist/commands/verify-merge.d.ts +4 -2
  188. package/dist/commands/verify-merge.d.ts.map +1 -1
  189. package/dist/commands/verify-merge.js +8 -5
  190. package/dist/commands/verify-merge.js.map +1 -1
  191. package/dist/context-layout/context-layout.d.ts.map +1 -1
  192. package/dist/context-layout/context-layout.js +6 -0
  193. package/dist/context-layout/context-layout.js.map +1 -1
  194. package/dist/context-layout/module-moves.d.ts +8 -0
  195. package/dist/context-layout/module-moves.d.ts.map +1 -1
  196. package/dist/context-layout/module-moves.js +14 -3
  197. package/dist/context-layout/module-moves.js.map +1 -1
  198. package/dist/context-layout/runner-configs-by-hand.d.ts.map +1 -1
  199. package/dist/context-layout/runner-configs-by-hand.js +12 -0
  200. package/dist/context-layout/runner-configs-by-hand.js.map +1 -1
  201. package/dist/context-layout/settle.d.ts +9 -0
  202. package/dist/context-layout/settle.d.ts.map +1 -1
  203. package/dist/context-layout/settle.js +25 -3
  204. package/dist/context-layout/settle.js.map +1 -1
  205. package/dist/describe/read-adapters.d.ts.map +1 -1
  206. package/dist/describe/read-adapters.js +5 -1
  207. package/dist/describe/read-adapters.js.map +1 -1
  208. package/dist/describe/read-ports.js +8 -1
  209. package/dist/describe/read-ports.js.map +1 -1
  210. package/dist/generate/generate-options.d.ts +10 -0
  211. package/dist/generate/generate-options.d.ts.map +1 -1
  212. package/dist/generate/generate-options.js +3 -0
  213. package/dist/generate/generate-options.js.map +1 -1
  214. package/dist/generate/kind.d.ts +6 -0
  215. package/dist/generate/kind.d.ts.map +1 -1
  216. package/dist/generate/kinds/adapter-kind.d.ts.map +1 -1
  217. package/dist/generate/kinds/adapter-kind.js +12 -0
  218. package/dist/generate/kinds/adapter-kind.js.map +1 -1
  219. package/dist/generate/kinds/declare-storage.d.ts.map +1 -1
  220. package/dist/generate/kinds/declare-storage.js +3 -57
  221. package/dist/generate/kinds/declare-storage.js.map +1 -1
  222. package/dist/generate/kinds/declare-table.d.ts +14 -0
  223. package/dist/generate/kinds/declare-table.d.ts.map +1 -0
  224. package/dist/generate/kinds/declare-table.js +72 -0
  225. package/dist/generate/kinds/declare-table.js.map +1 -0
  226. package/dist/generate/kinds/e2e/job-slug.d.ts +3 -0
  227. package/dist/generate/kinds/e2e/job-slug.d.ts.map +1 -0
  228. package/dist/generate/kinds/e2e/job-slug.js +8 -0
  229. package/dist/generate/kinds/e2e/job-slug.js.map +1 -0
  230. package/dist/generate/kinds/e2e/job-spec.d.ts +16 -0
  231. package/dist/generate/kinds/e2e/job-spec.d.ts.map +1 -0
  232. package/dist/generate/kinds/e2e/job-spec.js +54 -0
  233. package/dist/generate/kinds/e2e/job-spec.js.map +1 -0
  234. package/dist/generate/kinds/e2e/jobs-sending.d.ts +17 -5
  235. package/dist/generate/kinds/e2e/jobs-sending.d.ts.map +1 -1
  236. package/dist/generate/kinds/e2e/jobs-sending.js +15 -6
  237. package/dist/generate/kinds/e2e/jobs-sending.js.map +1 -1
  238. package/dist/generate/kinds/e2e/reaction-of.d.ts +5 -5
  239. package/dist/generate/kinds/e2e/reaction-of.d.ts.map +1 -1
  240. package/dist/generate/kinds/e2e/reaction-of.js +15 -8
  241. package/dist/generate/kinds/e2e/reaction-of.js.map +1 -1
  242. package/dist/generate/kinds/e2e/starting-jobs.d.ts +10 -0
  243. package/dist/generate/kinds/e2e/starting-jobs.d.ts.map +1 -0
  244. package/dist/generate/kinds/e2e/starting-jobs.js +33 -0
  245. package/dist/generate/kinds/e2e/starting-jobs.js.map +1 -0
  246. package/dist/generate/kinds/e2e-kind.d.ts.map +1 -1
  247. package/dist/generate/kinds/e2e-kind.js +47 -35
  248. package/dist/generate/kinds/e2e-kind.js.map +1 -1
  249. package/dist/generate/kinds/file-upload/upload-file-vars.d.ts +9 -0
  250. package/dist/generate/kinds/file-upload/upload-file-vars.d.ts.map +1 -0
  251. package/dist/generate/kinds/file-upload/upload-file-vars.js +39 -0
  252. package/dist/generate/kinds/file-upload/upload-file-vars.js.map +1 -0
  253. package/dist/generate/kinds/file-upload/write-nest-upload-controller.d.ts.map +1 -1
  254. package/dist/generate/kinds/file-upload/write-nest-upload-controller.js +2 -1
  255. package/dist/generate/kinds/file-upload/write-nest-upload-controller.js.map +1 -1
  256. package/dist/generate/kinds/file-upload/write-upload-controller.d.ts.map +1 -1
  257. package/dist/generate/kinds/file-upload/write-upload-controller.js +2 -1
  258. package/dist/generate/kinds/file-upload/write-upload-controller.js.map +1 -1
  259. package/dist/generate/kinds/file-upload-kind.d.ts.map +1 -1
  260. package/dist/generate/kinds/file-upload-kind.js +5 -3
  261. package/dist/generate/kinds/file-upload-kind.js.map +1 -1
  262. package/dist/generate/kinds/generate-repository.d.ts +8 -0
  263. package/dist/generate/kinds/generate-repository.d.ts.map +1 -1
  264. package/dist/generate/kinds/generate-repository.js +2 -13
  265. package/dist/generate/kinds/generate-repository.js.map +1 -1
  266. package/dist/generate/kinds/note-the-migration.d.ts +4 -0
  267. package/dist/generate/kinds/note-the-migration.d.ts.map +1 -0
  268. package/dist/generate/kinds/note-the-migration.js +13 -0
  269. package/dist/generate/kinds/note-the-migration.js.map +1 -0
  270. package/dist/generate/kinds/personal-data/columns-of-table.d.ts +18 -0
  271. package/dist/generate/kinds/personal-data/columns-of-table.d.ts.map +1 -0
  272. package/dist/generate/kinds/personal-data/columns-of-table.js +31 -0
  273. package/dist/generate/kinds/personal-data/columns-of-table.js.map +1 -0
  274. package/dist/generate/kinds/personal-data/declare-personal-data.d.ts.map +1 -1
  275. package/dist/generate/kinds/personal-data/declare-personal-data.js +7 -52
  276. package/dist/generate/kinds/personal-data/declare-personal-data.js.map +1 -1
  277. package/dist/generate/kinds/personal-data/declare-table-personal-fields.d.ts +11 -0
  278. package/dist/generate/kinds/personal-data/declare-table-personal-fields.d.ts.map +1 -0
  279. package/dist/generate/kinds/personal-data/declare-table-personal-fields.js +71 -0
  280. package/dist/generate/kinds/personal-data/declare-table-personal-fields.js.map +1 -0
  281. package/dist/generate/kinds/personal-data/personal-request-of-table.d.ts +11 -0
  282. package/dist/generate/kinds/personal-data/personal-request-of-table.d.ts.map +1 -0
  283. package/dist/generate/kinds/personal-data/personal-request-of-table.js +20 -0
  284. package/dist/generate/kinds/personal-data/personal-request-of-table.js.map +1 -0
  285. package/dist/generate/kinds/personal-data/personal-vars.d.ts +7 -0
  286. package/dist/generate/kinds/personal-data/personal-vars.d.ts.map +1 -1
  287. package/dist/generate/kinds/personal-data/personal-vars.js +14 -11
  288. package/dist/generate/kinds/personal-data/personal-vars.js.map +1 -1
  289. package/dist/generate/kinds/personal-data/schema-table.d.ts +13 -0
  290. package/dist/generate/kinds/personal-data/schema-table.d.ts.map +1 -0
  291. package/dist/generate/kinds/personal-data/schema-table.js +2 -0
  292. package/dist/generate/kinds/personal-data/schema-table.js.map +1 -0
  293. package/dist/generate/kinds/personal-data/schema-tables-of.d.ts +9 -0
  294. package/dist/generate/kinds/personal-data/schema-tables-of.d.ts.map +1 -0
  295. package/dist/generate/kinds/personal-data/schema-tables-of.js +78 -0
  296. package/dist/generate/kinds/personal-data/schema-tables-of.js.map +1 -0
  297. package/dist/generate/kinds/personal-data/table-of-schema.d.ts +15 -0
  298. package/dist/generate/kinds/personal-data/table-of-schema.d.ts.map +1 -0
  299. package/dist/generate/kinds/personal-data/table-of-schema.js +39 -0
  300. package/dist/generate/kinds/personal-data/table-of-schema.js.map +1 -0
  301. package/dist/generate/kinds/personal-data/write-personal-declaration.d.ts +20 -0
  302. package/dist/generate/kinds/personal-data/write-personal-declaration.d.ts.map +1 -0
  303. package/dist/generate/kinds/personal-data/write-personal-declaration.js +63 -0
  304. package/dist/generate/kinds/personal-data/write-personal-declaration.js.map +1 -0
  305. package/dist/generate/kinds/personal-fields-kind.d.ts +3 -0
  306. package/dist/generate/kinds/personal-fields-kind.d.ts.map +1 -0
  307. package/dist/generate/kinds/personal-fields-kind.js +15 -0
  308. package/dist/generate/kinds/personal-fields-kind.js.map +1 -0
  309. package/dist/generate/kinds/projection-kind.d.ts.map +1 -1
  310. package/dist/generate/kinds/projection-kind.js +2 -1
  311. package/dist/generate/kinds/projection-kind.js.map +1 -1
  312. package/dist/generate/kinds/read-model/field-lines.d.ts +11 -0
  313. package/dist/generate/kinds/read-model/field-lines.d.ts.map +1 -0
  314. package/dist/generate/kinds/read-model/field-lines.js +85 -0
  315. package/dist/generate/kinds/read-model/field-lines.js.map +1 -0
  316. package/dist/generate/kinds/read-model/list-read-model.d.ts +17 -0
  317. package/dist/generate/kinds/read-model/list-read-model.d.ts.map +1 -0
  318. package/dist/generate/kinds/read-model/list-read-model.js +22 -0
  319. package/dist/generate/kinds/read-model/list-read-model.js.map +1 -0
  320. package/dist/generate/kinds/read-model/live-rows-check.d.ts +22 -0
  321. package/dist/generate/kinds/read-model/live-rows-check.d.ts.map +1 -0
  322. package/dist/generate/kinds/read-model/live-rows-check.js +47 -0
  323. package/dist/generate/kinds/read-model/live-rows-check.js.map +1 -0
  324. package/dist/generate/kinds/read-model/read-model-fields.d.ts +19 -0
  325. package/dist/generate/kinds/read-model/read-model-fields.d.ts.map +1 -0
  326. package/dist/generate/kinds/read-model/read-model-fields.js +31 -0
  327. package/dist/generate/kinds/read-model/read-model-fields.js.map +1 -0
  328. package/dist/generate/kinds/read-model/read-model-store.d.ts +24 -0
  329. package/dist/generate/kinds/read-model/read-model-store.d.ts.map +1 -0
  330. package/dist/generate/kinds/read-model/read-model-store.js +39 -0
  331. package/dist/generate/kinds/read-model/read-model-store.js.map +1 -0
  332. package/dist/generate/kinds/read-model/read-model-table.d.ts +11 -0
  333. package/dist/generate/kinds/read-model/read-model-table.d.ts.map +1 -0
  334. package/dist/generate/kinds/read-model/read-model-table.js +2 -0
  335. package/dist/generate/kinds/read-model/read-model-table.js.map +1 -0
  336. package/dist/generate/kinds/read-model-kind.d.ts +3 -0
  337. package/dist/generate/kinds/read-model-kind.d.ts.map +1 -0
  338. package/dist/generate/kinds/read-model-kind.js +103 -0
  339. package/dist/generate/kinds/read-model-kind.js.map +1 -0
  340. package/dist/generate/kinds/service-kind.d.ts.map +1 -1
  341. package/dist/generate/kinds/service-kind.js +8 -0
  342. package/dist/generate/kinds/service-kind.js.map +1 -1
  343. package/dist/generate/kinds/wire-context.d.ts.map +1 -1
  344. package/dist/generate/kinds/wire-context.js +4 -0
  345. package/dist/generate/kinds/wire-context.js.map +1 -1
  346. package/dist/generate/kinds.d.ts.map +1 -1
  347. package/dist/generate/kinds.js +4 -0
  348. package/dist/generate/kinds.js.map +1 -1
  349. package/dist/generate/shared-writes.d.ts.map +1 -1
  350. package/dist/generate/shared-writes.js +9 -0
  351. package/dist/generate/shared-writes.js.map +1 -1
  352. package/dist/help/tool-notes.d.ts.map +1 -1
  353. package/dist/help/tool-notes.js +7 -2
  354. package/dist/help/tool-notes.js.map +1 -1
  355. package/dist/help/usage.js +1 -1
  356. package/dist/help/work-notes.d.ts.map +1 -1
  357. package/dist/help/work-notes.js +9 -2
  358. package/dist/help/work-notes.js.map +1 -1
  359. package/dist/init/files/end-to-end-files.d.ts.map +1 -1
  360. package/dist/init/files/end-to-end-files.js +3 -0
  361. package/dist/init/files/end-to-end-files.js.map +1 -1
  362. package/dist/init/files/persistence-files.d.ts.map +1 -1
  363. package/dist/init/files/persistence-files.js +8 -0
  364. package/dist/init/files/persistence-files.js.map +1 -1
  365. package/dist/init/files/script-files.d.ts +2 -1
  366. package/dist/init/files/script-files.d.ts.map +1 -1
  367. package/dist/init/files/script-files.js +6 -1
  368. package/dist/init/files/script-files.js.map +1 -1
  369. package/dist/init/is-team-file.d.ts +2 -2
  370. package/dist/init/is-team-file.d.ts.map +1 -1
  371. package/dist/init/is-team-file.js +5 -4
  372. package/dist/init/is-team-file.js.map +1 -1
  373. package/dist/init/list-read-models.d.ts +17 -0
  374. package/dist/init/list-read-models.d.ts.map +1 -0
  375. package/dist/init/list-read-models.js +74 -0
  376. package/dist/init/list-read-models.js.map +1 -0
  377. package/dist/init/manifest/database-scripts.d.ts.map +1 -1
  378. package/dist/init/manifest/database-scripts.js +8 -0
  379. package/dist/init/manifest/database-scripts.js.map +1 -1
  380. package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
  381. package/dist/init/manifest/dependencies-for.js +10 -7
  382. package/dist/init/manifest/dependencies-for.js.map +1 -1
  383. package/dist/init/manifest/versions.js +25 -25
  384. package/dist/init/rewire-contexts.d.ts +4 -2
  385. package/dist/init/rewire-contexts.d.ts.map +1 -1
  386. package/dist/init/rewire-contexts.js +10 -2
  387. package/dist/init/rewire-contexts.js.map +1 -1
  388. package/dist/init/run-init.js +1 -1
  389. package/dist/init/run-init.js.map +1 -1
  390. package/dist/init/wiring-notes.js +1 -1
  391. package/dist/init/wiring-notes.js.map +1 -1
  392. package/dist/init/write-type-script-configs.d.ts +3 -1
  393. package/dist/init/write-type-script-configs.d.ts.map +1 -1
  394. package/dist/init/write-type-script-configs.js +14 -2
  395. package/dist/init/write-type-script-configs.js.map +1 -1
  396. package/dist/layout/fit-block.js +4 -0
  397. package/dist/layout/fit-block.js.map +1 -1
  398. package/dist/merge/format-merge-report.js +5 -2
  399. package/dist/merge/format-merge-report.js.map +1 -1
  400. package/dist/merge/land-drizzle.d.ts +4 -0
  401. package/dist/merge/land-drizzle.d.ts.map +1 -1
  402. package/dist/merge/land-drizzle.js +6 -1
  403. package/dist/merge/land-drizzle.js.map +1 -1
  404. package/dist/merge/land-up-to-date.d.ts +15 -0
  405. package/dist/merge/land-up-to-date.d.ts.map +1 -0
  406. package/dist/merge/land-up-to-date.js +76 -0
  407. package/dist/merge/land-up-to-date.js.map +1 -0
  408. package/dist/merge/lost/format-merge-verification.d.ts +2 -1
  409. package/dist/merge/lost/format-merge-verification.d.ts.map +1 -1
  410. package/dist/merge/lost/format-merge-verification.js +13 -2
  411. package/dist/merge/lost/format-merge-verification.js.map +1 -1
  412. package/dist/merge/lost/merge-verification.d.ts +4 -0
  413. package/dist/merge/lost/merge-verification.d.ts.map +1 -1
  414. package/dist/merge/lost/verify-merges.d.ts +2 -1
  415. package/dist/merge/lost/verify-merges.d.ts.map +1 -1
  416. package/dist/merge/lost/verify-merges.js +10 -4
  417. package/dist/merge/lost/verify-merges.js.map +1 -1
  418. package/dist/merge/merge-trunk.d.ts +2 -1
  419. package/dist/merge/merge-trunk.d.ts.map +1 -1
  420. package/dist/merge/merge-trunk.js +5 -2
  421. package/dist/merge/merge-trunk.js.map +1 -1
  422. package/dist/merge/next-steps.d.ts +3 -0
  423. package/dist/merge/next-steps.d.ts.map +1 -1
  424. package/dist/merge/next-steps.js +3 -0
  425. package/dist/merge/next-steps.js.map +1 -1
  426. package/dist/merge/order/applied-under-old-name.d.ts +13 -0
  427. package/dist/merge/order/applied-under-old-name.d.ts.map +1 -0
  428. package/dist/merge/order/applied-under-old-name.js +14 -0
  429. package/dist/merge/order/applied-under-old-name.js.map +1 -0
  430. package/dist/merge/order/comes-after.d.ts +8 -0
  431. package/dist/merge/order/comes-after.d.ts.map +1 -0
  432. package/dist/merge/order/comes-after.js +9 -0
  433. package/dist/merge/order/comes-after.js.map +1 -0
  434. package/dist/merge/order/drizzle-order.d.ts +11 -0
  435. package/dist/merge/order/drizzle-order.d.ts.map +1 -0
  436. package/dist/merge/order/drizzle-order.js +64 -0
  437. package/dist/merge/order/drizzle-order.js.map +1 -0
  438. package/dist/merge/order/in-order.d.ts +4 -0
  439. package/dist/merge/order/in-order.d.ts.map +1 -0
  440. package/dist/merge/order/in-order.js +6 -0
  441. package/dist/merge/order/in-order.js.map +1 -0
  442. package/dist/merge/order/migration-order-finding.d.ts +18 -0
  443. package/dist/merge/order/migration-order-finding.d.ts.map +1 -0
  444. package/dist/merge/order/migration-order-finding.js +2 -0
  445. package/dist/merge/order/migration-order-finding.js.map +1 -0
  446. package/dist/merge/order/migration-order.d.ts +12 -0
  447. package/dist/merge/order/migration-order.d.ts.map +1 -0
  448. package/dist/merge/order/migration-order.js +21 -0
  449. package/dist/merge/order/migration-order.js.map +1 -0
  450. package/dist/merge/order/migrations-of-commit.d.ts +7 -0
  451. package/dist/merge/order/migrations-of-commit.d.ts.map +1 -0
  452. package/dist/merge/order/migrations-of-commit.js +43 -0
  453. package/dist/merge/order/migrations-of-commit.js.map +1 -0
  454. package/dist/merge/order/migrations-of-tree.d.ts +9 -0
  455. package/dist/merge/order/migrations-of-tree.d.ts.map +1 -0
  456. package/dist/merge/order/migrations-of-tree.js +25 -0
  457. package/dist/merge/order/migrations-of-tree.js.map +1 -0
  458. package/dist/merge/order/named-order.d.ts +11 -0
  459. package/dist/merge/order/named-order.d.ts.map +1 -0
  460. package/dist/merge/order/named-order.js +36 -0
  461. package/dist/merge/order/named-order.js.map +1 -0
  462. package/dist/merge/order/ordered-migration.d.ts +12 -0
  463. package/dist/merge/order/ordered-migration.d.ts.map +1 -0
  464. package/dist/merge/order/ordered-migration.js +2 -0
  465. package/dist/merge/order/ordered-migration.js.map +1 -0
  466. package/dist/merge/order/trunk-to-follow.d.ts +9 -0
  467. package/dist/merge/order/trunk-to-follow.d.ts.map +1 -0
  468. package/dist/merge/order/trunk-to-follow.js +2 -0
  469. package/dist/merge/order/trunk-to-follow.js.map +1 -0
  470. package/dist/merge/renumber-migrations.d.ts +14 -5
  471. package/dist/merge/renumber-migrations.d.ts.map +1 -1
  472. package/dist/merge/renumber-migrations.js +141 -60
  473. package/dist/merge/renumber-migrations.js.map +1 -1
  474. package/dist/merge/restamp-class.d.ts +9 -0
  475. package/dist/merge/restamp-class.d.ts.map +1 -0
  476. package/dist/merge/restamp-class.js +30 -0
  477. package/dist/merge/restamp-class.js.map +1 -0
  478. package/dist/migration/index.d.ts +1 -0
  479. package/dist/migration/index.d.ts.map +1 -1
  480. package/dist/migration/index.js +1 -0
  481. package/dist/migration/index.js.map +1 -1
  482. package/dist/migration/plan-replay.d.ts.map +1 -1
  483. package/dist/migration/plan-replay.js +2 -1
  484. package/dist/migration/plan-replay.js.map +1 -1
  485. package/dist/migration/refuse-taken-migration-name.d.ts +8 -0
  486. package/dist/migration/refuse-taken-migration-name.d.ts.map +1 -0
  487. package/dist/migration/refuse-taken-migration-name.js +22 -0
  488. package/dist/migration/refuse-taken-migration-name.js.map +1 -0
  489. package/dist/migration/replay-drizzle-migrations.d.ts +5 -0
  490. package/dist/migration/replay-drizzle-migrations.d.ts.map +1 -1
  491. package/dist/migration/replay-drizzle-migrations.js +10 -2
  492. package/dist/migration/replay-drizzle-migrations.js.map +1 -1
  493. package/dist/migration/replay-plan.d.ts +2 -2
  494. package/dist/migration/replay-plan.d.ts.map +1 -1
  495. package/dist/migration/restore-migration-folder.d.ts +6 -2
  496. package/dist/migration/restore-migration-folder.d.ts.map +1 -1
  497. package/dist/migration/restore-migration-folder.js +14 -7
  498. package/dist/migration/restore-migration-folder.js.map +1 -1
  499. package/dist/migration/snapshot-migration-folder.d.ts +7 -0
  500. package/dist/migration/snapshot-migration-folder.d.ts.map +1 -0
  501. package/dist/migration/snapshot-migration-folder.js +12 -0
  502. package/dist/migration/snapshot-migration-folder.js.map +1 -0
  503. package/dist/move-to-module/before-the-move.d.ts +5 -0
  504. package/dist/move-to-module/before-the-move.d.ts.map +1 -0
  505. package/dist/move-to-module/before-the-move.js +13 -0
  506. package/dist/move-to-module/before-the-move.js.map +1 -0
  507. package/dist/move-to-module/closed-cycles.d.ts +21 -0
  508. package/dist/move-to-module/closed-cycles.d.ts.map +1 -0
  509. package/dist/move-to-module/closed-cycles.js +66 -0
  510. package/dist/move-to-module/closed-cycles.js.map +1 -0
  511. package/dist/move-to-module/cycle-lines.d.ts +7 -0
  512. package/dist/move-to-module/cycle-lines.d.ts.map +1 -0
  513. package/dist/move-to-module/cycle-lines.js +22 -0
  514. package/dist/move-to-module/cycle-lines.js.map +1 -0
  515. package/dist/move-to-module/cycle-refusal.d.ts +17 -0
  516. package/dist/move-to-module/cycle-refusal.d.ts.map +1 -0
  517. package/dist/move-to-module/cycle-refusal.js +25 -0
  518. package/dist/move-to-module/cycle-refusal.js.map +1 -0
  519. package/dist/move-to-module/index.d.ts +5 -0
  520. package/dist/move-to-module/index.d.ts.map +1 -1
  521. package/dist/move-to-module/index.js +4 -0
  522. package/dist/move-to-module/index.js.map +1 -1
  523. package/dist/move-to-module/module-imports-in.d.ts +11 -0
  524. package/dist/move-to-module/module-imports-in.d.ts.map +1 -0
  525. package/dist/move-to-module/module-imports-in.js +32 -0
  526. package/dist/move-to-module/module-imports-in.js.map +1 -0
  527. package/dist/move-to-module/moves-into-module.d.ts.map +1 -1
  528. package/dist/move-to-module/moves-into-module.js +6 -18
  529. package/dist/move-to-module/moves-into-module.js.map +1 -1
  530. package/dist/move-to-module/place-in-module.d.ts +13 -0
  531. package/dist/move-to-module/place-in-module.d.ts.map +1 -0
  532. package/dist/move-to-module/place-in-module.js +24 -0
  533. package/dist/move-to-module/place-in-module.js.map +1 -0
  534. package/dist/move-to-module/watch-cycles.d.ts +19 -0
  535. package/dist/move-to-module/watch-cycles.d.ts.map +1 -0
  536. package/dist/move-to-module/watch-cycles.js +51 -0
  537. package/dist/move-to-module/watch-cycles.js.map +1 -0
  538. package/dist/presets/no-flags.d.ts.map +1 -1
  539. package/dist/presets/no-flags.js +1 -0
  540. package/dist/presets/no-flags.js.map +1 -1
  541. package/dist/run.js +1 -1
  542. package/dist/run.js.map +1 -1
  543. package/dist/slice/format-slice-verification.d.ts.map +1 -1
  544. package/dist/slice/format-slice-verification.js +11 -5
  545. package/dist/slice/format-slice-verification.js.map +1 -1
  546. package/dist/stack/alias-vars.d.ts +3 -1
  547. package/dist/stack/alias-vars.d.ts.map +1 -1
  548. package/dist/stack/alias-vars.js +5 -2
  549. package/dist/stack/alias-vars.js.map +1 -1
  550. package/dist/stack/end-to-end-vars.d.ts +9 -0
  551. package/dist/stack/end-to-end-vars.d.ts.map +1 -0
  552. package/dist/stack/end-to-end-vars.js +32 -0
  553. package/dist/stack/end-to-end-vars.js.map +1 -0
  554. package/dist/stack/stack-vars.d.ts.map +1 -1
  555. package/dist/stack/stack-vars.js +2 -0
  556. package/dist/stack/stack-vars.js.map +1 -1
  557. package/dist/version.d.ts +1 -1
  558. package/dist/version.js +1 -1
  559. package/dist/worker/briefing-of.js +2 -2
  560. package/dist/worker/briefing-of.js.map +1 -1
  561. package/package.json +6 -6
  562. package/templates/e2e/e2e-background-job-case.ts.tpl +12 -0
  563. package/templates/e2e/e2e-job.spec.ts.tpl +3 -3
  564. package/templates/file-upload/controller.spec.ts.tpl +66 -2
  565. package/templates/file-upload/controller.ts.tpl +12 -0
  566. package/templates/file-upload/handler.spec.ts.tpl +3 -3
  567. package/templates/init/README.md.tpl +20 -1
  568. package/templates/init/e2e/jest.e2e.config.js.tpl +29 -5
  569. package/templates/init/e2e/start-application.database.ts.tpl +40 -2
  570. package/templates/init/e2e/start-application.memory.ts.tpl +36 -0
  571. package/templates/init/e2e/test-database-setup.ts.tpl +120 -0
  572. package/templates/init/e2e/vitest.e2e.config.ts.tpl +14 -4
  573. package/templates/init/platform/composition/compose-application.container.ts.tpl +5 -0
  574. package/templates/init/platform/composition/compose-application.manual.ts.tpl +20 -3
  575. package/templates/init/platform/composition/create-platform.manual.ts.tpl +6 -0
  576. package/templates/init/platform/composition/platform-options.manual.ts.tpl +11 -0
  577. package/templates/init/platform/composition/platform.manual.ts.tpl +7 -0
  578. package/templates/init/platform/composition/platform.module.container.ts.tpl +34 -0
  579. package/templates/init/platform/database/connect-to-database.drizzle.ts.tpl +7 -2
  580. package/templates/init/platform/database/open-test-database.drizzle.ts.tpl +27 -4
  581. package/templates/init/platform/database/open-test-database.knex.ts.tpl +26 -3
  582. package/templates/init/platform/database/open-test-database.prisma.ts.tpl +27 -3
  583. package/templates/init/platform/database/open-test-database.typeorm.ts.tpl +27 -3
  584. package/templates/init/platform/database/read-model-tables.ts.tpl +67 -0
  585. package/templates/init/platform/database/test-database-budget.ts.tpl +108 -0
  586. package/templates/init/platform/database/test-database-clone.ts.tpl +75 -0
  587. package/templates/init/platform/database/test-database-copy.ts.tpl +76 -0
  588. package/templates/init/platform/database/test-database-emptying.ts.tpl +209 -0
  589. package/templates/init/platform/database/test-database-kept.ts.tpl +32 -0
  590. package/templates/init/platform/database/test-database-leftovers.ts.tpl +52 -0
  591. package/templates/init/platform/database/test-database-run.ts.tpl +99 -0
  592. package/templates/init/platform/database/test-database-server.ts.tpl +140 -0
  593. package/templates/init/platform/database/test-database-session.ts.tpl +141 -0
  594. package/templates/init/platform/database/test-database-teardown.ts.tpl +11 -1
  595. package/templates/init/platform/jobs/background-jobs.ts.tpl +4 -0
  596. package/templates/init/platform/jobs/create-background-work.ts.tpl +1 -0
  597. package/templates/init/platform/resilience/default-policy.ts.tpl +8 -1
  598. package/templates/init/rules/infrastructure.md.tpl +3 -3
  599. package/templates/init/scripts/read-model-tables.ts.tpl +83 -0
  600. package/templates/nest-controller/upload.spec.ts.tpl +67 -2
  601. package/templates/nest-controller/upload.ts.tpl +12 -0
  602. package/templates/personal-data/declaration.drizzle.ts.tpl +6 -1
  603. package/templates/personal-data/declaration.knex.ts.tpl +14 -1
  604. package/templates/personal-data/declaration.prisma.ts.tpl +6 -1
  605. package/templates/personal-data/declaration.typeorm.ts.tpl +21 -1
  606. package/templates/personal-data/spec.table.ts.tpl +39 -0
  607. package/templates/pipeline/package-scripts.json +1 -1
  608. package/templates/presets/identity/context/infrastructure/persistence/drizzle-account.repository.drizzle.ts.tpl +5 -9
  609. package/templates/presets/identity/context/infrastructure/persistence/drizzle-delegation.repository.drizzle.ts.tpl +5 -9
  610. package/templates/presets/identity/context/infrastructure/persistence/drizzle-invitation.repository.drizzle.ts.tpl +5 -9
  611. package/templates/presets/identity/context/infrastructure/persistence/drizzle-member.repository.drizzle.ts.tpl +5 -9
  612. package/templates/presets/identity/context/infrastructure/persistence/drizzle-organisation.repository.drizzle.ts.tpl +5 -9
  613. package/templates/projection/projection.manual.ts.tpl +2 -2
  614. package/templates/projection/projection.ts.tpl +2 -2
  615. package/templates/read-model/contract.spec.ts.tpl +95 -0
  616. package/templates/read-model/drizzle/schema.ts.tpl +8 -0
  617. package/templates/read-model/drizzle/store.ts.tpl +41 -0
  618. package/templates/read-model/drizzle/table.tpl +38 -0
  619. package/templates/read-model/fake.ts.tpl +8 -0
  620. package/templates/read-model/knex/store.ts.tpl +41 -0
  621. package/templates/read-model/knex/table.tpl +26 -0
  622. package/templates/read-model/none/store.ts.tpl +17 -0
  623. package/templates/read-model/port.ts.tpl +24 -0
  624. package/templates/read-model/prisma/model.tpl +25 -0
  625. package/templates/read-model/prisma/store.ts.tpl +43 -0
  626. package/templates/read-model/typeorm/schema-export.tpl +4 -0
  627. package/templates/read-model/typeorm/schema.ts.tpl +9 -0
  628. package/templates/read-model/typeorm/store.ts.tpl +30 -0
  629. package/templates/read-model/typeorm/table.tpl +54 -0
  630. package/templates/read-model/wiring.container.tpl +21 -0
  631. package/templates/repository/drizzle/repository.ts.tpl +6 -9
  632. package/templates/repository/drizzle/table.tpl +1 -0
  633. package/templates/repository/typeorm/table.tpl +1 -0
@@ -28,6 +28,9 @@ import { layFoundations } from '{{alias.platform}}/composition/lay-foundations{{
28
28
  import type { Platform } from '{{alias.platform}}/composition/platform{{alias.ext}}';
29
29
  import type { PlatformOptions } from '{{alias.platform}}/composition/platform-options{{alias.ext}}';
30
30
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
31
+ {{#if persistence.hasDatabase}}
32
+ import { readModelTables } from '{{alias.platform}}/database/read-model-tables{{alias.ext}}';
33
+ {{/if}}
31
34
  import { platformEvents } from '{{alias.platform}}/events/platform-events{{alias.ext}}';
32
35
  {{#if files.any}}
33
36
  import { createFiles, type Files } from '{{alias.platform}}/files/create-files{{alias.ext}}';
@@ -78,6 +81,9 @@ export function createPlatform(persistence: Persistence, options: PlatformOption
78
81
  queries: createQueryBus(foundations, protection.guard),
79
82
  domainEvents,
80
83
  persistence,
84
+ {{#if persistence.hasDatabase}}
85
+ readModelTables: (contexts) => readModelTables(persistence, contexts),
86
+ {{/if}}
81
87
  access: new PolicyAccess({ authorizer, clock, policies: accessPolicies, onDecision }),
82
88
  actors: new ScopedActorContext(scope, foundations.ids),
83
89
  adapter,
@@ -14,6 +14,9 @@ import type { FileStorage, JobSettings } from '@ddd-ts-kit/kernel';
14
14
  import type { JobSettings } from '@ddd-ts-kit/kernel';
15
15
  {{/unless}}
16
16
  {{/unless}}
17
+ {{#if persistence.hasDatabase}}
18
+ import type { ReadModelTablesAtStart } from '@ddd-ts-kit/kernel';
19
+ {{/if}}
17
20
  import type { QueueWorkerOptions } from '@ddd-ts-kit/scheduling';
18
21
  import type { ConsumerTrace } from '@ddd-ts-kit/tracing';
19
22
  {{#if search.opensearch}}
@@ -66,6 +69,14 @@ export interface PlatformOptions {
66
69
  readonly queues?: Pick<QueueWorkerOptions, 'concurrency' | 'pollIntervalMs' | 'graceMs'>;
67
70
  /** Whether a consumed event continues the trace of its publication (the default) or starts one linked to it. */
68
71
  readonly traceConsumers?: ConsumerTrace;
72
+ {{#if persistence.hasDatabase}}
73
+ /**
74
+ * What the start does with a listed read model table that cannot hold the trace of a deleted row. Left out, it
75
+ * refuses to start, with every such table and the migration to write; `'reported'` logs them as one error
76
+ * and starts, for a deployment that starts the application before its migrations ran.
77
+ */
78
+ readonly readModelTables?: ReadModelTablesAtStart;
79
+ {{/if}}
69
80
  {{#if cache.redis}}
70
81
  /** The Redis protocol server; left out, the cache, the lock and the limiter stay in the memory of the process. */
71
82
  readonly redis?: RedisServices;
@@ -26,6 +26,9 @@ import type {
26
26
  RateLimiter,
27
27
  {{/if}}
28
28
  } from '@ddd-ts-kit/kernel';
29
+ {{#if persistence.hasDatabase}}
30
+ import type { ReadModelTables } from '@ddd-ts-kit/kernel';
31
+ {{/if}}
29
32
  {{#if queue.stored}}
30
33
  import type { JobStore } from '@ddd-ts-kit/scheduling';
31
34
  {{/if}}
@@ -68,6 +71,10 @@ export interface Platform {
68
71
  /** The provider itself: what the outbox relay delivers to. */
69
72
  readonly eventBus: IntegrationEventPublisher;
70
73
  readonly persistence: Persistence;
74
+ {{#if persistence.hasDatabase}}
75
+ /** The listed read model tables of these contexts, which an application checks in one pass when it starts, before an event reaches a store. */
76
+ readModelTables(contexts: readonly string[]): ReadModelTables;
77
+ {{/if}}
71
78
  /** Asks the policies about one element, then the authorizer: for the rules that need loaded state. */
72
79
  readonly access: Access;
73
80
  /**
@@ -65,9 +65,14 @@ import { {{#if broker.external}}EventSubscribers, {{/if}}ProcessedEventStore, Un
65
65
  import { ExecutionScope, ProcessStore } from '@ddd-ts-kit/kernel';
66
66
  {{/if}}
67
67
  {{/unless}}
68
+ {{#if persistence.hasDatabase}}
69
+ import { Logger, type ReadModelTablesAtStart } from '@ddd-ts-kit/kernel';
70
+ {{/if}}
71
+ {{#unless persistence.hasDatabase}}
68
72
  {{#if queue.redis}}
69
73
  import { Logger } from '@ddd-ts-kit/kernel';
70
74
  {{/if}}
75
+ {{/unless}}
71
76
  {{#if queue.stored}}
72
77
  import { JobStore } from '@ddd-ts-kit/scheduling';
73
78
  {{/if}}
@@ -79,6 +84,9 @@ import { Database } from '{{alias.platform}}/database/database{{alias.ext}}';
79
84
  {{/if}}
80
85
  import type { ConsumerTrace } from '@ddd-ts-kit/tracing';
81
86
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
87
+ {{#if persistence.hasDatabase}}
88
+ import { readModelTables } from '{{alias.platform}}/database/read-model-tables{{alias.ext}}';
89
+ {{/if}}
82
90
  {{#if http.any}}
83
91
  import { platformErrorMapper } from '{{alias.platform}}/composition/platform-error-mapper{{alias.ext}}';
84
92
  {{/if}}
@@ -116,6 +124,14 @@ export interface PlatformOptions {
116
124
  readonly resilience?: ResilienceSettings;
117
125
  /** Whether a consumed event continues the trace of its publication (the default) or starts one linked to it. */
118
126
  readonly traceConsumers?: ConsumerTrace;
127
+ {{#if persistence.hasDatabase}}
128
+ /**
129
+ * What the start does with a listed read model table that cannot hold the trace of a deleted row. Left out, it
130
+ * refuses to start, with every such table and the migration to write; `'reported'` logs them as one error
131
+ * and starts, for a deployment that starts the application before its migrations ran.
132
+ */
133
+ readonly readModelTables?: ReadModelTablesAtStart;
134
+ {{/if}}
119
135
  {{#if errors.sentry}}
120
136
  /** Where unexpected failures are reported: the reporter of `errors.ts` in `main.ts`; left out (the tools, the tests), nowhere. */
121
137
  readonly errors?: ErrorReporter;
@@ -138,10 +154,28 @@ export interface PlatformOptions {
138
154
  /**
139
155
  * What this platform puts in place of the in-process defaults of the kernel module: the storage
140
156
  * and whatever else `main.ts` opened for it. Replacing a provider happens here and nowhere else.
157
+ {{#if persistence.hasDatabase}}
158
+ * `hosted` holds the contexts this application hosts: it checks their read model tables and no other.
159
+ {{/if}}
141
160
  */
161
+ {{#if persistence.hasDatabase}}
162
+ export function platformModule(
163
+ persistence: Persistence,
164
+ options: PlatformOptions,
165
+ hosted?: readonly ContextModule[],
166
+ ): ContextModule {
167
+ const contexts = hosted?.map(({ name }) => name);
168
+
169
+ {{/if}}
170
+ {{#unless persistence.hasDatabase}}
142
171
  export function platformModule(persistence: Persistence, options: PlatformOptions): ContextModule {
172
+ {{/unless}}
143
173
  return defineContextModule({
144
174
  name: 'platform',
175
+ {{#if persistence.hasDatabase}}
176
+ // Before a consumer is subscribed or a request served, whenever a store is built: each listed read model table of the hosted contexts, read by its own store.
177
+ onStart: ({ resolve }) => readModelTables(persistence, contexts).atStart(resolve(Logger), options.readModelTables),
178
+ {{/if}}
145
179
  // Closed inside `stop()` of the application, after the jobs and the consumers and before the logger is flushed.
146
180
  onStop: () => options.events.close(),
147
181
  register(builder) {
@@ -7,8 +7,13 @@ export interface DatabaseConnection {
7
7
  close(): Promise<void>;
8
8
  }
9
9
 
10
- export function connectToDatabase(url: string): DatabaseConnection {
11
- const db = drizzle(url);
10
+ export interface ConnectionOptions {
11
+ /** Default 10. The tests on a server share its connections between the files that run at once. */
12
+ readonly poolSize?: number;
13
+ }
14
+
15
+ export function connectToDatabase(url: string, options: ConnectionOptions = {}): DatabaseConnection {
16
+ const db = drizzle({ connection: { connectionString: url, max: options.poolSize ?? 10 } });
12
17
 
13
18
  return { db, close: () => db.$client.end() };
14
19
  }
@@ -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,12 @@ 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.
33
+ * The copy holds the tables and no row, but for the tables test/support/test-database-kept.ts
34
+ * lists: an end-to-end run makes it from the template of its global setup, any other caller
35
+ * copies the migrated database itself.
24
36
  */
25
37
  export function openTestDatabase(url?: string): Promise<TestDatabase> {
26
38
  return url === undefined ? openInProcess() : openServer(url);
@@ -54,15 +66,26 @@ async function inProcessPostgres(): Promise<PGlite> {
54
66
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
55
67
  }
56
68
 
69
+ /**
70
+ * A database of its own on the server, dropped at close (test/support/test-database-clone.ts): the
71
+ * tables of the migrated one, emptied but for those test/support/test-database-kept.ts lists. No
72
+ * other file, and no other run, reads or empties its rows. Its pool is the share this file has of
73
+ * the connections of the server.
74
+ */
57
75
  async function openServer(url: string): Promise<TestDatabase> {
58
- const connection = connectToDatabase(url);
76
+ const clone = await cloneDatabase(url);
77
+ const connection = connectToDatabase(clone.url, { poolSize: clone.poolSize });
59
78
  const statements = new TableStatements();
60
79
 
61
80
  return {
81
+ url: clone.url,
62
82
  persistence: persistenceOver(connection),
63
83
  reset: async () => {
64
84
  await connection.db.execute(sql.raw(statements.emptying()));
65
85
  },
66
- close: () => connection.close(),
86
+ close: async () => {
87
+ await connection.close();
88
+ await clone.drop();
89
+ },
67
90
  };
68
91
  }
@@ -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,11 @@ 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`).
37
+ * The copy holds the tables and no row, but for the tables test/support/test-database-kept.ts
38
+ * lists: an end-to-end run makes it from the template of its global setup, any other caller
39
+ * copies the migrated database itself.
28
40
  */
29
41
  export function openTestDatabase(url?: string): Promise<TestDatabase> {
30
42
  return url === undefined ? openInProcess() : openServer(url);
@@ -63,13 +75,24 @@ async function inProcessPostgres(): Promise<PGlite> {
63
75
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
64
76
  }
65
77
 
78
+ /**
79
+ * A database of its own on the server, dropped at close (test/support/test-database-clone.ts): the
80
+ * tables of the migrated one, emptied but for those test/support/test-database-kept.ts lists. No
81
+ * other file, and no other run, reads or empties its rows. Its pool is the share this file has of
82
+ * the connections of the server.
83
+ */
66
84
  async function openServer(url: string): Promise<TestDatabase> {
67
- const connection = connectToDatabase(url);
85
+ const clone = await cloneDatabase(url);
86
+ const connection = connectToDatabase(clone.url, { poolSize: clone.poolSize });
68
87
 
69
88
  return {
89
+ url: clone.url,
70
90
  persistence: persistenceOver(connection),
71
91
  reset: () => emptyTables(connection.db),
72
- close: () => connection.close(),
92
+ close: async () => {
93
+ await connection.close();
94
+ await clone.drop();
95
+ },
73
96
  };
74
97
  }
75
98
 
@@ -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,11 @@ 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`).
37
+ * The copy holds the tables and no row, but for the tables test/support/test-database-kept.ts
38
+ * lists: an end-to-end run makes it from the template of its global setup, any other caller
39
+ * copies the migrated database itself.
28
40
  */
29
41
  export function openTestDatabase(url?: string): Promise<TestDatabase> {
30
42
  return url === undefined ? openInProcess() : openServer(url);
@@ -63,10 +75,22 @@ async function inProcessPostgres(): Promise<PGlite> {
63
75
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
64
76
  }
65
77
 
78
+ /**
79
+ * A database of its own on the server, dropped at close (test/support/test-database-clone.ts): the
80
+ * tables of the migrated one, emptied but for those test/support/test-database-kept.ts lists. No
81
+ * other file, and no other run, reads or empties its rows. Its pool is the share this file has of
82
+ * the connections of the server.
83
+ */
66
84
  async function openServer(url: string): Promise<TestDatabase> {
67
- const client = createClient(url);
85
+ const clone = await cloneDatabase(url);
86
+ const client = createClient(clone.url, { poolSize: clone.poolSize });
87
+
88
+ const close = async (): Promise<void> => {
89
+ await client.$disconnect();
90
+ await clone.drop();
91
+ };
68
92
 
69
- return { persistence: persistenceOver(client), reset: () => emptyTables(client), close: () => client.$disconnect() };
93
+ return { url: clone.url, persistence: persistenceOver(client), reset: () => emptyTables(client), close };
70
94
  }
71
95
 
72
96
  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,11 @@ 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`).
37
+ * The copy holds the tables and no row, but for the tables test/support/test-database-kept.ts
38
+ * lists: an end-to-end run makes it from the template of its global setup, any other caller
39
+ * copies the migrated database itself.
28
40
  */
29
41
  export function openTestDatabase(url?: string): Promise<TestDatabase> {
30
42
  return url === undefined ? openInProcess() : openServer(url);
@@ -66,14 +78,26 @@ async function inProcessPostgres(): Promise<PGlite> {
66
78
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
67
79
  }
68
80
 
81
+ /**
82
+ * A database of its own on the server, dropped at close (test/support/test-database-clone.ts): the
83
+ * tables of the migrated one, emptied but for those test/support/test-database-kept.ts lists. No
84
+ * other file, and no other run, reads or empties its rows. Its pool is the share this file has of
85
+ * the connections of the server.
86
+ */
69
87
  async function openServer(url: string): Promise<TestDatabase> {
70
- const dataSource = createDataSource(url);
88
+ const clone = await cloneDatabase(url);
89
+ const dataSource = createDataSource(clone.url, { poolSize: clone.poolSize });
71
90
 
72
91
  await dataSource.initialize();
73
92
 
74
93
  const persistence = persistenceOver(dataSource);
75
94
 
76
- return { persistence, reset: () => emptyTables(dataSource), close: () => persistence.close() };
95
+ const close = async (): Promise<void> => {
96
+ await persistence.close();
97
+ await clone.drop();
98
+ };
99
+
100
+ return { url: clone.url, persistence, reset: () => emptyTables(dataSource), close };
77
101
  }
78
102
 
79
103
  // TypeORM creates tables, not schemas.
@@ -0,0 +1,67 @@
1
+ import {
2
+ AsyncLocalStorageExecutionScope,
3
+ ReadModelTables,
4
+ type ExecutionScope,
5
+ type ReadModelInATable,
6
+ } from '@ddd-ts-kit/kernel';
7
+ import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
8
+ // ddd-ts-kit:imports
9
+ // /ddd-ts-kit:imports
10
+
11
+ /**
12
+ * The class of a read model store, built as the application binds it: on the storage, with the
13
+ * scope of the work when it keeps tenant data.
14
+ */
15
+ type Store = new (database: Persistence['database'], scope: ExecutionScope) => ReadModelInATable;
16
+
17
+ /**
18
+ * The bounded contexts of the project: `generate context` adds each. An entry of the list names
19
+ * one of them, or does not compile.
20
+ */
21
+ type Contexts = [
22
+ // ddd-ts-kit:contexts
23
+ // /ddd-ts-kit:contexts
24
+ ];
25
+
26
+ /**
27
+ * The read models the application keeps in a table: the context each belongs to and the class of
28
+ * its store. `generate read-model` adds its store here, and `init` those it finds in the tree; a
29
+ * store written by hand is added by hand. A table that is not listed is never read. A store left
30
+ * out on purpose is a comment here that holds `<context>: <Store>` and the reason: `init` then
31
+ * leaves it out, and the check says nothing of it.
32
+ */
33
+ const LISTED: readonly (readonly [context: Contexts[number], store: Store])[] = [
34
+ // ddd-ts-kit:read-model-tables
35
+ // /ddd-ts-kit:read-model-tables
36
+ ];
37
+
38
+ /**
39
+ * The read model stores of the tree `init` could not list, `<context>: <Store>`, since their
40
+ * constructor takes something else: the check says at each start that nothing checks their
41
+ * tables, until each is listed through a class of its own that builds it.
42
+ */
43
+ const NOT_LISTED: readonly string[] = [
44
+ // ddd-ts-kit:read-models-not-listed
45
+ // /ddd-ts-kit:read-models-not-listed
46
+ ];
47
+
48
+ /**
49
+ * The listed tables of these contexts, every context when none is named, checked in one pass:
50
+ * each is read by its own store, with the code that store runs before its first trace, so the
51
+ * verdict is the store's and the migration of a table that is not ready names the columns the
52
+ * store maps and no other. An application asks it when it starts, of the contexts it hosts: a
53
+ * context run as a service of its own checks its tables, on its database, and no other.
54
+ * `npm run db:read-models` asks it of the database a deployment is about to reach. The scope a
55
+ * store of tenant data is given is never read by the check.
56
+ */
57
+ export function readModelTables(persistence: Persistence, contexts?: readonly string[]): ReadModelTables {
58
+ const scope = new AsyncLocalStorageExecutionScope();
59
+
60
+ const listed = LISTED.map(([context, Store]) => ({
61
+ context,
62
+ name: Store.name,
63
+ build: () => new Store(persistence.database, scope),
64
+ }));
65
+
66
+ return new ReadModelTables(listed, NOT_LISTED).hosting(contexts);
67
+ }
@@ -0,0 +1,108 @@
1
+ import type pg from 'pg';
2
+
3
+ /** Stated by whoever starts the run: the connections it may take, when that is less than what the server has left. */
4
+ const STATED = 'TEST_DATABASE_CONNECTIONS';
5
+ /** The pool an application opens when nothing bounds it, and the one under which a request that waits for another never ends. */
6
+ const LARGEST_POOL = 10;
7
+ const SMALLEST_POOL = 2;
8
+ /** Beside its pool a file has one connection to spare: the one that copies and drops its database, a client a spec opens itself. */
9
+ const SPARE = 1;
10
+
11
+ /** One thing that bounds the connections of a run. */
12
+ interface Bound {
13
+ readonly left: number;
14
+ /** How a refusal says it. */
15
+ readonly counted: string;
16
+ /** What raises it. */
17
+ readonly remedy: string;
18
+ }
19
+
20
+ type Counts = Record<'max' | 'reserved' | 'open' | 'limit' | 'openOfRole', number> & { readonly role: string };
21
+
22
+ /**
23
+ * The pool of each file of a run in which `atOnce` files run at the same time: what the tightest
24
+ * bound leaves, shared between them, less the connection each has to spare, 10 at most. A run that
25
+ * does not fit is refused here with its numbers and what raises that bound, before any file
26
+ * starts, instead of `too many clients` from the driver in the middle of a spec. The count is
27
+ * taken once, on the session `server` of the run, itself among the connections open: a run that
28
+ * starts later sees what this one has open, not what it will open.
29
+ */
30
+ export async function poolSizeFor(server: pg.Client, atOnce: number): Promise<number> {
31
+ const { left, counted, remedy } = tightest(await bounds(server));
32
+ const each = SMALLEST_POOL + SPARE;
33
+ const fitting = Math.floor(left / each);
34
+ const fewer = fitting > 0 ? `run at most ${fitting} at once (npm run test:e2e -- --maxWorkers=${fitting}), or ` : '';
35
+
36
+ if (fitting < atOnce) {
37
+ throw new Error(
38
+ `${atOnce} spec files at once need ${atOnce * each} connections (${SMALLEST_POOL} for each application at least and ${SPARE} to spare), and ${counted}: ${fewer}${remedy}.`,
39
+ );
40
+ }
41
+
42
+ return Math.min(LARGEST_POOL, Math.floor(left / atOnce) - SPARE);
43
+ }
44
+
45
+ function tightest(all: readonly Bound[]): Bound {
46
+ return all.reduce((least, bound) => (bound.left < least.left ? bound : least));
47
+ }
48
+
49
+ /** The server, the role when it has a limit of its own, and what TEST_DATABASE_CONNECTIONS states. */
50
+ async function bounds(server: pg.Client): Promise<Bound[]> {
51
+ const { rows } = await server.query<Counts>(
52
+ `select current_setting('max_connections')::int as max,
53
+ current_setting('superuser_reserved_connections')::int + coalesce(current_setting('reserved_connections', true)::int, 0) as reserved,
54
+ (select count(*)::int from pg_stat_activity where usesysid is not null and coalesce(backend_type, 'client backend') = 'client backend') as "open",
55
+ (select case when rolsuper then -1 else rolconnlimit end from pg_roles where rolname = current_user) as "limit",
56
+ (select count(*)::int from pg_stat_activity where usename = current_user) as "openOfRole",
57
+ current_user::text as "role"`,
58
+ );
59
+
60
+ const [counts = { max: 0, reserved: 0, open: 0, limit: -1, openOfRole: 0, role: '' }] = rows;
61
+ const ofTheServer = [boundOfTheServer(counts), ...(counts.limit < 0 ? [] : [boundOfTheRole(counts)])];
62
+
63
+ return [...ofTheServer, ...stated(tightest(ofTheServer))];
64
+ }
65
+
66
+ function boundOfTheServer({ max, reserved, open }: Counts): Bound {
67
+ return {
68
+ left: max - reserved - open,
69
+ counted: `the server leaves ${max - reserved - open} (max_connections ${max}, ${reserved} reserved, ${open} open)`,
70
+ remedy: 'raise max_connections',
71
+ };
72
+ }
73
+
74
+ function boundOfTheRole({ role, limit, openOfRole }: Counts): Bound {
75
+ return {
76
+ left: limit - openOfRole,
77
+ counted: `the role ${role} has ${limit - openOfRole} left (connection limit ${limit}, ${openOfRole} open)`,
78
+ remedy: `raise the limit of the role (alter role ${role} connection limit <more>)`,
79
+ };
80
+ }
81
+
82
+ /** What the variable states, when it is set: a whole number of connections, no more than the server leaves. */
83
+ function stated(ofTheServer: Bound): Bound[] {
84
+ const text = process.env[STATED] ?? '';
85
+ const connections = Number(text);
86
+
87
+ if (text === '') {
88
+ return [];
89
+ }
90
+
91
+ if (!Number.isInteger(connections) || connections < 1) {
92
+ throw new Error(`${STATED} is "${text}": state a whole number of connections, 1 or more, or leave it unset.`);
93
+ }
94
+
95
+ if (connections > ofTheServer.left) {
96
+ throw new Error(
97
+ `${STATED} states ${connections} connections, and ${ofTheServer.counted}: state ${ofTheServer.left} at most, or leave it unset.`,
98
+ );
99
+ }
100
+
101
+ return [
102
+ {
103
+ left: connections,
104
+ counted: `${STATED} allows ${connections}`,
105
+ remedy: `state more in ${STATED} (${ofTheServer.left} at most)`,
106
+ },
107
+ ];
108
+ }
@@ -0,0 +1,75 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { openRun } from './test-database-run{{alias.sibling}}';
3
+ import {
4
+ codeOf,
5
+ copying,
6
+ dropping,
7
+ lostDatabases,
8
+ nameOf,
9
+ NO_SUCH_DATABASE,
10
+ oneAtATime,
11
+ onServer,
12
+ POOL_SIZE,
13
+ RUN_TEMPLATE,
14
+ runOf,
15
+ urlOf,
16
+ } from './test-database-server{{alias.sibling}}';
17
+
18
+ /** A database of its own for one caller, on the server it was given. */
19
+ export interface DatabaseClone {
20
+ readonly url: string;
21
+
22
+ /** The connections the application of the caller may open: its share of what the server has left, so that every file of a run fits. */
23
+ readonly poolSize: number;
24
+
25
+ /** Drops the database, whoever is still connected to it. */
26
+ drop(): Promise<void>;
27
+ }
28
+
29
+ /** The pool of a file that is a run of its own: nothing shares the connections of the server between such runs, so each takes few. */
30
+ const POOL_OF_ITS_OWN = 4;
31
+
32
+ /**
33
+ * A database of its own on the server `url` names: the tables of the migrated database and none
34
+ * of the rows a run empties (test-database-emptying.ts). In an end-to-end run the global setup
35
+ * copied and emptied the migrated database once (test-database-setup.ts), and this copies that
36
+ * template (`create database ... template`), one copy at a time in the run, in a fraction of a
37
+ * second whatever the migrated database holds. Anywhere else (a spec of the unit run, a project
38
+ * with no end-to-end run) nothing started a run: the call is a run of its own, which copies the
39
+ * migrated database itself, in the time that takes. Either way spec files run at the same time on
40
+ * one server and nothing one stores reaches another. The copy is dropped when its caller closes
41
+ * it, at the end of its run, or by a later run when its own was killed.
42
+ */
43
+ export async function cloneDatabase(url: string): Promise<DatabaseClone> {
44
+ const template = process.env[RUN_TEMPLATE] ?? '';
45
+ const run = runOf(template, url);
46
+
47
+ if (run === undefined) {
48
+ return runOfItsOwn(url);
49
+ }
50
+
51
+ const name = nameOf(url, run, randomBytes(4).toString('hex'));
52
+
53
+ await onServer(url, (server) => oneAtATime(server, run, () => server.query(copying(template, name)))).catch(
54
+ (error: unknown) => {
55
+ throw codeOf(error) === NO_SUCH_DATABASE ? new Error(lostDatabases(template), { cause: error }) : error;
56
+ },
57
+ );
58
+
59
+ return {
60
+ url: urlOf(url, name),
61
+ poolSize: Number(process.env[POOL_SIZE]),
62
+ drop: () => onServer(url, (server) => server.query(dropping(name))),
63
+ };
64
+ }
65
+
66
+ /**
67
+ * The template of a run of one file is the database of that file. Nothing counts the files that
68
+ * do this at the same time, each one a run that sees the connections left when it starts: each
69
+ * takes a small pool, and the session of its lock.
70
+ */
71
+ async function runOfItsOwn(url: string): Promise<DatabaseClone> {
72
+ const run = await openRun(url, 1);
73
+
74
+ return { url: urlOf(url, run.template), poolSize: Math.min(run.poolSize, POOL_OF_ITS_OWN), drop: run.end };
75
+ }