ddd-ts-kit 0.111.0 → 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 (444) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/README.fr.md +35 -6
  3. package/README.md +32 -5
  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/files/kit-content-types.d.ts +12 -0
  62. package/dist/check/files/kit-content-types.d.ts.map +1 -0
  63. package/dist/check/files/kit-content-types.js +38 -0
  64. package/dist/check/files/kit-content-types.js.map +1 -0
  65. package/dist/check/files/upload-content-defect.d.ts +7 -0
  66. package/dist/check/files/upload-content-defect.d.ts.map +1 -0
  67. package/dist/check/files/upload-content-defect.js +2 -0
  68. package/dist/check/files/upload-content-defect.js.map +1 -0
  69. package/dist/check/files/upload-content-defects.d.ts +9 -0
  70. package/dist/check/files/upload-content-defects.d.ts.map +1 -0
  71. package/dist/check/files/upload-content-defects.js +54 -0
  72. package/dist/check/files/upload-content-defects.js.map +1 -0
  73. package/dist/check/files/upload-declaration.d.ts +7 -0
  74. package/dist/check/files/upload-declaration.d.ts.map +1 -0
  75. package/dist/check/files/upload-declaration.js +2 -0
  76. package/dist/check/files/upload-declaration.js.map +1 -0
  77. package/dist/check/files/upload-declarations.d.ts +9 -0
  78. package/dist/check/files/upload-declarations.d.ts.map +1 -0
  79. package/dist/check/files/upload-declarations.js +41 -0
  80. package/dist/check/files/upload-declarations.js.map +1 -0
  81. package/dist/check/fixtures/alias-declared-fixtures.d.ts.map +1 -1
  82. package/dist/check/fixtures/alias-declared-fixtures.js +95 -1
  83. package/dist/check/fixtures/alias-declared-fixtures.js.map +1 -1
  84. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  85. package/dist/check/fixtures/fixtures.js +2 -0
  86. package/dist/check/fixtures/fixtures.js.map +1 -1
  87. package/dist/check/fixtures/imports-fixtures.d.ts.map +1 -1
  88. package/dist/check/fixtures/imports-fixtures.js +97 -0
  89. package/dist/check/fixtures/imports-fixtures.js.map +1 -1
  90. package/dist/check/fixtures/standard-fixtures.d.ts.map +1 -1
  91. package/dist/check/fixtures/standard-fixtures.js +42 -0
  92. package/dist/check/fixtures/standard-fixtures.js.map +1 -1
  93. package/dist/check/fixtures/upload-fixtures.d.ts +3 -0
  94. package/dist/check/fixtures/upload-fixtures.d.ts.map +1 -0
  95. package/dist/check/fixtures/upload-fixtures.js +94 -0
  96. package/dist/check/fixtures/upload-fixtures.js.map +1 -0
  97. package/dist/check/migrations/is-working-migration.d.ts +6 -0
  98. package/dist/check/migrations/is-working-migration.d.ts.map +1 -0
  99. package/dist/check/migrations/is-working-migration.js +8 -0
  100. package/dist/check/migrations/is-working-migration.js.map +1 -0
  101. package/dist/check/migrations/journal-entries.d.ts +4 -0
  102. package/dist/check/migrations/journal-entries.d.ts.map +1 -0
  103. package/dist/check/migrations/journal-entries.js +21 -0
  104. package/dist/check/migrations/journal-entries.js.map +1 -0
  105. package/dist/check/migrations/read-drizzle-migrations.d.ts.map +1 -1
  106. package/dist/check/migrations/read-drizzle-migrations.js +4 -9
  107. package/dist/check/migrations/read-drizzle-migrations.js.map +1 -1
  108. package/dist/check/modules/imported-modules.d.ts +4 -0
  109. package/dist/check/modules/imported-modules.d.ts.map +1 -0
  110. package/dist/check/modules/imported-modules.js +5 -0
  111. package/dist/check/modules/imported-modules.js.map +1 -0
  112. package/dist/check/modules/module-imports.d.ts +17 -0
  113. package/dist/check/modules/module-imports.d.ts.map +1 -0
  114. package/dist/check/modules/module-imports.js +23 -0
  115. package/dist/check/modules/module-imports.js.map +1 -0
  116. package/dist/check/project/assemble-project.d.ts.map +1 -1
  117. package/dist/check/project/assemble-project.js +1 -8
  118. package/dist/check/project/assemble-project.js.map +1 -1
  119. package/dist/check/project/file-severity.d.ts +4 -0
  120. package/dist/check/project/file-severity.d.ts.map +1 -0
  121. package/dist/check/project/file-severity.js +11 -0
  122. package/dist/check/project/file-severity.js.map +1 -0
  123. package/dist/check/project/load-project.js +1 -10
  124. package/dist/check/project/load-project.js.map +1 -1
  125. package/dist/check/project/not-in-the-tree.d.ts +10 -0
  126. package/dist/check/project/not-in-the-tree.d.ts.map +1 -0
  127. package/dist/check/project/not-in-the-tree.js +17 -0
  128. package/dist/check/project/not-in-the-tree.js.map +1 -0
  129. package/dist/check/project/skipped-directories.d.ts +3 -0
  130. package/dist/check/project/skipped-directories.d.ts.map +1 -0
  131. package/dist/check/project/skipped-directories.js +3 -0
  132. package/dist/check/project/skipped-directories.js.map +1 -0
  133. package/dist/check/project/walk-directory.d.ts.map +1 -1
  134. package/dist/check/project/walk-directory.js +1 -1
  135. package/dist/check/project/walk-directory.js.map +1 -1
  136. package/dist/check/rules/aspects-timeout-covers-delegate.d.ts +3 -0
  137. package/dist/check/rules/aspects-timeout-covers-delegate.d.ts.map +1 -0
  138. package/dist/check/rules/aspects-timeout-covers-delegate.js +179 -0
  139. package/dist/check/rules/aspects-timeout-covers-delegate.js.map +1 -0
  140. package/dist/check/rules/files-upload-content-rule.d.ts +3 -0
  141. package/dist/check/rules/files-upload-content-rule.d.ts.map +1 -0
  142. package/dist/check/rules/files-upload-content-rule.js +25 -0
  143. package/dist/check/rules/files-upload-content-rule.js.map +1 -0
  144. package/dist/check/rules/imports-alias-declared.d.ts.map +1 -1
  145. package/dist/check/rules/imports-alias-declared.js +3 -1
  146. package/dist/check/rules/imports-alias-declared.js.map +1 -1
  147. package/dist/check/rules/imports-alias-only.d.ts.map +1 -1
  148. package/dist/check/rules/imports-alias-only.js +86 -7
  149. package/dist/check/rules/imports-alias-only.js.map +1 -1
  150. package/dist/check/rules/module-no-cycle.d.ts.map +1 -1
  151. package/dist/check/rules/module-no-cycle.js +12 -34
  152. package/dist/check/rules/module-no-cycle.js.map +1 -1
  153. package/dist/cli-error.d.ts +7 -2
  154. package/dist/cli-error.d.ts.map +1 -1
  155. package/dist/cli-error.js +8 -2
  156. package/dist/cli-error.js.map +1 -1
  157. package/dist/commands/generate.js +1 -0
  158. package/dist/commands/generate.js.map +1 -1
  159. package/dist/commands/knex-generate.d.ts.map +1 -1
  160. package/dist/commands/knex-generate.js +2 -1
  161. package/dist/commands/knex-generate.js.map +1 -1
  162. package/dist/commands/move-to-module.d.ts +6 -1
  163. package/dist/commands/move-to-module.d.ts.map +1 -1
  164. package/dist/commands/move-to-module.js +28 -3
  165. package/dist/commands/move-to-module.js.map +1 -1
  166. package/dist/commands/prisma-generate.d.ts.map +1 -1
  167. package/dist/commands/prisma-generate.js +2 -1
  168. package/dist/commands/prisma-generate.js.map +1 -1
  169. package/dist/commands/typeorm-generate.d.ts.map +1 -1
  170. package/dist/commands/typeorm-generate.js +2 -1
  171. package/dist/commands/typeorm-generate.js.map +1 -1
  172. package/dist/commands/verify-merge.d.ts +4 -2
  173. package/dist/commands/verify-merge.d.ts.map +1 -1
  174. package/dist/commands/verify-merge.js +8 -5
  175. package/dist/commands/verify-merge.js.map +1 -1
  176. package/dist/generate/generate-options.d.ts +3 -0
  177. package/dist/generate/generate-options.d.ts.map +1 -1
  178. package/dist/generate/generate-options.js +1 -0
  179. package/dist/generate/generate-options.js.map +1 -1
  180. package/dist/generate/kind.d.ts +2 -0
  181. package/dist/generate/kind.d.ts.map +1 -1
  182. package/dist/generate/kinds/file-upload/upload-file-vars.d.ts +9 -0
  183. package/dist/generate/kinds/file-upload/upload-file-vars.d.ts.map +1 -0
  184. package/dist/generate/kinds/file-upload/upload-file-vars.js +39 -0
  185. package/dist/generate/kinds/file-upload/upload-file-vars.js.map +1 -0
  186. package/dist/generate/kinds/file-upload/write-nest-upload-controller.d.ts.map +1 -1
  187. package/dist/generate/kinds/file-upload/write-nest-upload-controller.js +2 -1
  188. package/dist/generate/kinds/file-upload/write-nest-upload-controller.js.map +1 -1
  189. package/dist/generate/kinds/file-upload/write-upload-controller.d.ts.map +1 -1
  190. package/dist/generate/kinds/file-upload/write-upload-controller.js +2 -1
  191. package/dist/generate/kinds/file-upload/write-upload-controller.js.map +1 -1
  192. package/dist/generate/kinds/file-upload-kind.d.ts.map +1 -1
  193. package/dist/generate/kinds/file-upload-kind.js +5 -3
  194. package/dist/generate/kinds/file-upload-kind.js.map +1 -1
  195. package/dist/generate/kinds/read-model/list-read-model.d.ts +17 -0
  196. package/dist/generate/kinds/read-model/list-read-model.d.ts.map +1 -0
  197. package/dist/generate/kinds/read-model/list-read-model.js +22 -0
  198. package/dist/generate/kinds/read-model/list-read-model.js.map +1 -0
  199. package/dist/generate/kinds/read-model-kind.d.ts.map +1 -1
  200. package/dist/generate/kinds/read-model-kind.js +19 -0
  201. package/dist/generate/kinds/read-model-kind.js.map +1 -1
  202. package/dist/generate/kinds/service-kind.d.ts.map +1 -1
  203. package/dist/generate/kinds/service-kind.js +8 -0
  204. package/dist/generate/kinds/service-kind.js.map +1 -1
  205. package/dist/generate/kinds/wire-context.d.ts.map +1 -1
  206. package/dist/generate/kinds/wire-context.js +4 -0
  207. package/dist/generate/kinds/wire-context.js.map +1 -1
  208. package/dist/generate/shared-writes.d.ts.map +1 -1
  209. package/dist/generate/shared-writes.js +3 -2
  210. package/dist/generate/shared-writes.js.map +1 -1
  211. package/dist/help/tool-notes.d.ts.map +1 -1
  212. package/dist/help/tool-notes.js +5 -1
  213. package/dist/help/tool-notes.js.map +1 -1
  214. package/dist/help/usage.js +1 -1
  215. package/dist/help/work-notes.d.ts.map +1 -1
  216. package/dist/help/work-notes.js +9 -2
  217. package/dist/help/work-notes.js.map +1 -1
  218. package/dist/init/files/end-to-end-files.d.ts.map +1 -1
  219. package/dist/init/files/end-to-end-files.js +3 -0
  220. package/dist/init/files/end-to-end-files.js.map +1 -1
  221. package/dist/init/files/persistence-files.d.ts.map +1 -1
  222. package/dist/init/files/persistence-files.js +8 -2
  223. package/dist/init/files/persistence-files.js.map +1 -1
  224. package/dist/init/files/script-files.d.ts +2 -1
  225. package/dist/init/files/script-files.d.ts.map +1 -1
  226. package/dist/init/files/script-files.js +6 -1
  227. package/dist/init/files/script-files.js.map +1 -1
  228. package/dist/init/is-team-file.d.ts +2 -2
  229. package/dist/init/is-team-file.d.ts.map +1 -1
  230. package/dist/init/is-team-file.js +5 -4
  231. package/dist/init/is-team-file.js.map +1 -1
  232. package/dist/init/list-read-models.d.ts +17 -0
  233. package/dist/init/list-read-models.d.ts.map +1 -0
  234. package/dist/init/list-read-models.js +74 -0
  235. package/dist/init/list-read-models.js.map +1 -0
  236. package/dist/init/manifest/database-scripts.d.ts.map +1 -1
  237. package/dist/init/manifest/database-scripts.js +8 -0
  238. package/dist/init/manifest/database-scripts.js.map +1 -1
  239. package/dist/init/manifest/versions.js +25 -25
  240. package/dist/init/rewire-contexts.d.ts +4 -2
  241. package/dist/init/rewire-contexts.d.ts.map +1 -1
  242. package/dist/init/rewire-contexts.js +10 -2
  243. package/dist/init/rewire-contexts.js.map +1 -1
  244. package/dist/init/run-init.js +1 -1
  245. package/dist/init/run-init.js.map +1 -1
  246. package/dist/init/wiring-notes.js +1 -1
  247. package/dist/init/wiring-notes.js.map +1 -1
  248. package/dist/init/write-type-script-configs.d.ts +3 -1
  249. package/dist/init/write-type-script-configs.d.ts.map +1 -1
  250. package/dist/init/write-type-script-configs.js +14 -2
  251. package/dist/init/write-type-script-configs.js.map +1 -1
  252. package/dist/merge/format-merge-report.js +5 -2
  253. package/dist/merge/format-merge-report.js.map +1 -1
  254. package/dist/merge/land-drizzle.d.ts +4 -0
  255. package/dist/merge/land-drizzle.d.ts.map +1 -1
  256. package/dist/merge/land-drizzle.js +6 -1
  257. package/dist/merge/land-drizzle.js.map +1 -1
  258. package/dist/merge/land-up-to-date.d.ts +15 -0
  259. package/dist/merge/land-up-to-date.d.ts.map +1 -0
  260. package/dist/merge/land-up-to-date.js +76 -0
  261. package/dist/merge/land-up-to-date.js.map +1 -0
  262. package/dist/merge/lost/format-merge-verification.d.ts +2 -1
  263. package/dist/merge/lost/format-merge-verification.d.ts.map +1 -1
  264. package/dist/merge/lost/format-merge-verification.js +13 -2
  265. package/dist/merge/lost/format-merge-verification.js.map +1 -1
  266. package/dist/merge/lost/merge-verification.d.ts +4 -0
  267. package/dist/merge/lost/merge-verification.d.ts.map +1 -1
  268. package/dist/merge/lost/verify-merges.d.ts +2 -1
  269. package/dist/merge/lost/verify-merges.d.ts.map +1 -1
  270. package/dist/merge/lost/verify-merges.js +10 -4
  271. package/dist/merge/lost/verify-merges.js.map +1 -1
  272. package/dist/merge/merge-trunk.d.ts +2 -1
  273. package/dist/merge/merge-trunk.d.ts.map +1 -1
  274. package/dist/merge/merge-trunk.js +5 -2
  275. package/dist/merge/merge-trunk.js.map +1 -1
  276. package/dist/merge/next-steps.d.ts +3 -0
  277. package/dist/merge/next-steps.d.ts.map +1 -1
  278. package/dist/merge/next-steps.js +3 -0
  279. package/dist/merge/next-steps.js.map +1 -1
  280. package/dist/merge/order/applied-under-old-name.d.ts +13 -0
  281. package/dist/merge/order/applied-under-old-name.d.ts.map +1 -0
  282. package/dist/merge/order/applied-under-old-name.js +14 -0
  283. package/dist/merge/order/applied-under-old-name.js.map +1 -0
  284. package/dist/merge/order/comes-after.d.ts +8 -0
  285. package/dist/merge/order/comes-after.d.ts.map +1 -0
  286. package/dist/merge/order/comes-after.js +9 -0
  287. package/dist/merge/order/comes-after.js.map +1 -0
  288. package/dist/merge/order/drizzle-order.d.ts +11 -0
  289. package/dist/merge/order/drizzle-order.d.ts.map +1 -0
  290. package/dist/merge/order/drizzle-order.js +64 -0
  291. package/dist/merge/order/drizzle-order.js.map +1 -0
  292. package/dist/merge/order/in-order.d.ts +4 -0
  293. package/dist/merge/order/in-order.d.ts.map +1 -0
  294. package/dist/merge/order/in-order.js +6 -0
  295. package/dist/merge/order/in-order.js.map +1 -0
  296. package/dist/merge/order/migration-order-finding.d.ts +18 -0
  297. package/dist/merge/order/migration-order-finding.d.ts.map +1 -0
  298. package/dist/merge/order/migration-order-finding.js +2 -0
  299. package/dist/merge/order/migration-order-finding.js.map +1 -0
  300. package/dist/merge/order/migration-order.d.ts +12 -0
  301. package/dist/merge/order/migration-order.d.ts.map +1 -0
  302. package/dist/merge/order/migration-order.js +21 -0
  303. package/dist/merge/order/migration-order.js.map +1 -0
  304. package/dist/merge/order/migrations-of-commit.d.ts +7 -0
  305. package/dist/merge/order/migrations-of-commit.d.ts.map +1 -0
  306. package/dist/merge/order/migrations-of-commit.js +43 -0
  307. package/dist/merge/order/migrations-of-commit.js.map +1 -0
  308. package/dist/merge/order/migrations-of-tree.d.ts +9 -0
  309. package/dist/merge/order/migrations-of-tree.d.ts.map +1 -0
  310. package/dist/merge/order/migrations-of-tree.js +25 -0
  311. package/dist/merge/order/migrations-of-tree.js.map +1 -0
  312. package/dist/merge/order/named-order.d.ts +11 -0
  313. package/dist/merge/order/named-order.d.ts.map +1 -0
  314. package/dist/merge/order/named-order.js +36 -0
  315. package/dist/merge/order/named-order.js.map +1 -0
  316. package/dist/merge/order/ordered-migration.d.ts +12 -0
  317. package/dist/merge/order/ordered-migration.d.ts.map +1 -0
  318. package/dist/merge/order/ordered-migration.js +2 -0
  319. package/dist/merge/order/ordered-migration.js.map +1 -0
  320. package/dist/merge/order/trunk-to-follow.d.ts +9 -0
  321. package/dist/merge/order/trunk-to-follow.d.ts.map +1 -0
  322. package/dist/merge/order/trunk-to-follow.js +2 -0
  323. package/dist/merge/order/trunk-to-follow.js.map +1 -0
  324. package/dist/merge/renumber-migrations.d.ts +14 -5
  325. package/dist/merge/renumber-migrations.d.ts.map +1 -1
  326. package/dist/merge/renumber-migrations.js +141 -60
  327. package/dist/merge/renumber-migrations.js.map +1 -1
  328. package/dist/merge/restamp-class.d.ts +9 -0
  329. package/dist/merge/restamp-class.d.ts.map +1 -0
  330. package/dist/merge/restamp-class.js +30 -0
  331. package/dist/merge/restamp-class.js.map +1 -0
  332. package/dist/migration/index.d.ts +1 -0
  333. package/dist/migration/index.d.ts.map +1 -1
  334. package/dist/migration/index.js +1 -0
  335. package/dist/migration/index.js.map +1 -1
  336. package/dist/migration/plan-replay.d.ts.map +1 -1
  337. package/dist/migration/plan-replay.js +2 -1
  338. package/dist/migration/plan-replay.js.map +1 -1
  339. package/dist/migration/refuse-taken-migration-name.d.ts +8 -0
  340. package/dist/migration/refuse-taken-migration-name.d.ts.map +1 -0
  341. package/dist/migration/refuse-taken-migration-name.js +22 -0
  342. package/dist/migration/refuse-taken-migration-name.js.map +1 -0
  343. package/dist/migration/replay-drizzle-migrations.d.ts +5 -0
  344. package/dist/migration/replay-drizzle-migrations.d.ts.map +1 -1
  345. package/dist/migration/replay-drizzle-migrations.js +10 -2
  346. package/dist/migration/replay-drizzle-migrations.js.map +1 -1
  347. package/dist/migration/replay-plan.d.ts +2 -2
  348. package/dist/migration/replay-plan.d.ts.map +1 -1
  349. package/dist/migration/restore-migration-folder.d.ts +6 -2
  350. package/dist/migration/restore-migration-folder.d.ts.map +1 -1
  351. package/dist/migration/restore-migration-folder.js +14 -7
  352. package/dist/migration/restore-migration-folder.js.map +1 -1
  353. package/dist/migration/snapshot-migration-folder.d.ts +7 -0
  354. package/dist/migration/snapshot-migration-folder.d.ts.map +1 -0
  355. package/dist/migration/snapshot-migration-folder.js +12 -0
  356. package/dist/migration/snapshot-migration-folder.js.map +1 -0
  357. package/dist/move-to-module/before-the-move.d.ts +5 -0
  358. package/dist/move-to-module/before-the-move.d.ts.map +1 -0
  359. package/dist/move-to-module/before-the-move.js +13 -0
  360. package/dist/move-to-module/before-the-move.js.map +1 -0
  361. package/dist/move-to-module/closed-cycles.d.ts +21 -0
  362. package/dist/move-to-module/closed-cycles.d.ts.map +1 -0
  363. package/dist/move-to-module/closed-cycles.js +66 -0
  364. package/dist/move-to-module/closed-cycles.js.map +1 -0
  365. package/dist/move-to-module/cycle-lines.d.ts +7 -0
  366. package/dist/move-to-module/cycle-lines.d.ts.map +1 -0
  367. package/dist/move-to-module/cycle-lines.js +22 -0
  368. package/dist/move-to-module/cycle-lines.js.map +1 -0
  369. package/dist/move-to-module/cycle-refusal.d.ts +17 -0
  370. package/dist/move-to-module/cycle-refusal.d.ts.map +1 -0
  371. package/dist/move-to-module/cycle-refusal.js +25 -0
  372. package/dist/move-to-module/cycle-refusal.js.map +1 -0
  373. package/dist/move-to-module/index.d.ts +5 -0
  374. package/dist/move-to-module/index.d.ts.map +1 -1
  375. package/dist/move-to-module/index.js +4 -0
  376. package/dist/move-to-module/index.js.map +1 -1
  377. package/dist/move-to-module/module-imports-in.d.ts +11 -0
  378. package/dist/move-to-module/module-imports-in.d.ts.map +1 -0
  379. package/dist/move-to-module/module-imports-in.js +32 -0
  380. package/dist/move-to-module/module-imports-in.js.map +1 -0
  381. package/dist/move-to-module/moves-into-module.d.ts.map +1 -1
  382. package/dist/move-to-module/moves-into-module.js +6 -18
  383. package/dist/move-to-module/moves-into-module.js.map +1 -1
  384. package/dist/move-to-module/place-in-module.d.ts +13 -0
  385. package/dist/move-to-module/place-in-module.d.ts.map +1 -0
  386. package/dist/move-to-module/place-in-module.js +24 -0
  387. package/dist/move-to-module/place-in-module.js.map +1 -0
  388. package/dist/move-to-module/watch-cycles.d.ts +19 -0
  389. package/dist/move-to-module/watch-cycles.d.ts.map +1 -0
  390. package/dist/move-to-module/watch-cycles.js +51 -0
  391. package/dist/move-to-module/watch-cycles.js.map +1 -0
  392. package/dist/run.js +1 -1
  393. package/dist/run.js.map +1 -1
  394. package/dist/slice/format-slice-verification.d.ts.map +1 -1
  395. package/dist/slice/format-slice-verification.js +11 -5
  396. package/dist/slice/format-slice-verification.js.map +1 -1
  397. package/dist/stack/alias-vars.d.ts +3 -1
  398. package/dist/stack/alias-vars.d.ts.map +1 -1
  399. package/dist/stack/alias-vars.js +5 -2
  400. package/dist/stack/alias-vars.js.map +1 -1
  401. package/dist/version.d.ts +1 -1
  402. package/dist/version.js +1 -1
  403. package/package.json +6 -6
  404. package/templates/file-upload/controller.spec.ts.tpl +66 -2
  405. package/templates/file-upload/controller.ts.tpl +12 -0
  406. package/templates/file-upload/handler.spec.ts.tpl +3 -3
  407. package/templates/init/README.md.tpl +20 -1
  408. package/templates/init/e2e/jest.e2e.config.js.tpl +5 -0
  409. package/templates/init/e2e/test-database-setup.ts.tpl +120 -0
  410. package/templates/init/e2e/vitest.e2e.config.ts.tpl +2 -1
  411. package/templates/init/platform/composition/compose-application.container.ts.tpl +5 -0
  412. package/templates/init/platform/composition/compose-application.manual.ts.tpl +20 -3
  413. package/templates/init/platform/composition/create-platform.manual.ts.tpl +6 -0
  414. package/templates/init/platform/composition/platform-options.manual.ts.tpl +11 -0
  415. package/templates/init/platform/composition/platform.manual.ts.tpl +7 -0
  416. package/templates/init/platform/composition/platform.module.container.ts.tpl +34 -0
  417. package/templates/init/platform/database/connect-to-database.drizzle.ts.tpl +7 -2
  418. package/templates/init/platform/database/open-test-database.drizzle.ts.tpl +8 -3
  419. package/templates/init/platform/database/open-test-database.knex.ts.tpl +8 -3
  420. package/templates/init/platform/database/open-test-database.prisma.ts.tpl +8 -3
  421. package/templates/init/platform/database/open-test-database.typeorm.ts.tpl +8 -3
  422. package/templates/init/platform/database/read-model-tables.ts.tpl +67 -0
  423. package/templates/init/platform/database/test-database-budget.ts.tpl +108 -0
  424. package/templates/init/platform/database/test-database-clone.ts.tpl +52 -161
  425. package/templates/init/platform/database/test-database-copy.ts.tpl +76 -0
  426. package/templates/init/platform/database/test-database-emptying.ts.tpl +209 -0
  427. package/templates/init/platform/database/test-database-kept.ts.tpl +32 -0
  428. package/templates/init/platform/database/test-database-leftovers.ts.tpl +52 -0
  429. package/templates/init/platform/database/test-database-run.ts.tpl +99 -0
  430. package/templates/init/platform/database/test-database-server.ts.tpl +140 -0
  431. package/templates/init/platform/database/test-database-session.ts.tpl +141 -0
  432. package/templates/init/platform/database/test-database-teardown.ts.tpl +11 -1
  433. package/templates/init/platform/resilience/default-policy.ts.tpl +8 -1
  434. package/templates/init/rules/infrastructure.md.tpl +2 -2
  435. package/templates/init/scripts/read-model-tables.ts.tpl +83 -0
  436. package/templates/nest-controller/upload.spec.ts.tpl +67 -2
  437. package/templates/nest-controller/upload.ts.tpl +12 -0
  438. package/templates/pipeline/package-scripts.json +1 -1
  439. package/templates/presets/identity/context/infrastructure/persistence/drizzle-account.repository.drizzle.ts.tpl +5 -9
  440. package/templates/presets/identity/context/infrastructure/persistence/drizzle-delegation.repository.drizzle.ts.tpl +5 -9
  441. package/templates/presets/identity/context/infrastructure/persistence/drizzle-invitation.repository.drizzle.ts.tpl +5 -9
  442. package/templates/presets/identity/context/infrastructure/persistence/drizzle-member.repository.drizzle.ts.tpl +5 -9
  443. package/templates/presets/identity/context/infrastructure/persistence/drizzle-organisation.repository.drizzle.ts.tpl +5 -9
  444. package/templates/repository/drizzle/repository.ts.tpl +6 -9
@@ -0,0 +1,141 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { setTimeout as later } from 'node:timers/promises';
3
+ import type pg from 'pg';
4
+ import { connectedTo, keyOf, LIVE, locked, lostDatabases } from './test-database-server{{alias.sibling}}';
5
+
6
+ /** A run says that it lives every 15 seconds, and is held dead a minute after it last did (test-database-leftovers.ts). */
7
+ const BEAT_SECONDS = 15;
8
+
9
+ export const DEAD_AFTER_SECONDS = 60;
10
+ /** What the comment of a run starts with, on the database that carries it, before the seconds of the clock of the server. */
11
+ export const BEAT = 'ddd-ts-kit run ';
12
+
13
+ /** How many times, a second apart, a run tries to take a session again before it says that it could not. */
14
+ const ATTEMPTS = 5;
15
+
16
+ /** What says that a run lives: its lock, held by one session, and the comment it refreshes on its template. */
17
+ export interface RunSession {
18
+ readonly id: string;
19
+
20
+ /** The session that holds the lock now: another one once the server ended the first. */
21
+ server(): pg.Client;
22
+
23
+ /** Says on `database`, now and every 15 seconds from now, that the run lives. */
24
+ beatOn(database: string): Promise<void>;
25
+
26
+ /** Lets the lock go. Never throws: a session the server ended is ended. */
27
+ end(): Promise<void>;
28
+ }
29
+
30
+ interface Held {
31
+ readonly url: string;
32
+ readonly tell: (line: string) => void;
33
+ id: string;
34
+ client: pg.Client;
35
+ retaking: boolean;
36
+ ended: boolean;
37
+ /** The database that carries the comment of the run, once it has one. */
38
+ database?: string;
39
+ beating?: NodeJS.Timeout;
40
+ }
41
+
42
+ /**
43
+ * Opens the session of a run and takes the lock of a name no living run has, before any database
44
+ * carries it. A session can end while the run lives (the server restarts or fails over, an
45
+ * administrator ends it, sessions idle too long are ended, the machine slept): the run then takes
46
+ * another one and its lock again, at once, and says so when it could not. The lock is one of a
47
+ * session: the address is a direct one, never a pooler that hands a session to others.
48
+ */
49
+ export async function openSession(url: string, tell: (line: string) => void): Promise<RunSession> {
50
+ const held: Held = { url, tell, id: '', client: await connectedTo(url), retaking: false, ended: false };
51
+
52
+ held.id = await lockedRun(held.client);
53
+ watch(held, held.client);
54
+
55
+ return {
56
+ id: held.id,
57
+ server: () => held.client,
58
+ beatOn: (database) => beatingOn(held, database),
59
+ end: () => ended(held),
60
+ };
61
+ }
62
+
63
+ async function lockedRun(client: pg.Client): Promise<string> {
64
+ const id = randomBytes(4).toString('hex');
65
+
66
+ return (await locked(client, `pg_try_advisory_lock(${LIVE}, ${keyOf(id)})`)) ? id : lockedRun(client);
67
+ }
68
+
69
+ /** A client whose session the server ended emits an error, more than once: with nobody listening, it would end the runner. */
70
+ function watch(held: Held, client: pg.Client): void {
71
+ client.on('error', () => {
72
+ if (held.client === client && !held.retaking && !held.ended) {
73
+ held.retaking = true;
74
+
75
+ void retaken(held, ATTEMPTS).finally(() => {
76
+ held.retaking = false;
77
+ });
78
+ }
79
+ });
80
+ }
81
+
82
+ async function retaken(held: Held, attempts: number): Promise<void> {
83
+ try {
84
+ const client = await connectedTo(held.url);
85
+
86
+ watch(held, client);
87
+
88
+ if (!(await locked(client, `pg_try_advisory_lock(${LIVE}, ${keyOf(held.id)})`))) {
89
+ await client.end();
90
+
91
+ throw new Error('another session holds the lock of the run');
92
+ }
93
+
94
+ held.client = client;
95
+ await sayDatabasesLost(held);
96
+ } catch (error) {
97
+ if (attempts > 1 && !held.ended) {
98
+ await later(1000);
99
+ await retaken(held, attempts - 1);
100
+ } else if (!held.ended) {
101
+ // Nothing is left to say that the run lives: the comment is not asked of a session that is gone.
102
+ clearInterval(held.beating);
103
+
104
+ held.tell(
105
+ `The run lost its session on the server and could not take it again (${String(error)}): a minute from now nothing says that its databases are in use, and another run may drop them. A spec file that finds its database gone failed for that reason: run again.\n`,
106
+ );
107
+ }
108
+ }
109
+ }
110
+
111
+ /** While the run had no session, nothing held its databases: a later run may have dropped them, and the files to come would fail one by one. */
112
+ async function sayDatabasesLost(held: Held): Promise<void> {
113
+ const { database, client } = held;
114
+
115
+ if (database === undefined) {
116
+ return;
117
+ }
118
+
119
+ const found = await client.query('select 1 from pg_database where datname = $1', [database]).catch(() => undefined);
120
+
121
+ if (found?.rowCount === 0) {
122
+ held.tell(lostDatabases(database) + '\n');
123
+ }
124
+ }
125
+
126
+ async function beatingOn(held: Held, database: string): Promise<void> {
127
+ const name = "'" + database.replaceAll("'", "''") + "'";
128
+ const beat = `do $$ begin execute format('comment on database %I is %L', ${name}, '${BEAT}' || extract(epoch from now())::bigint); end $$`;
129
+
130
+ await held.client.query(beat);
131
+ held.database = database;
132
+ // Between two sessions a beat is lost: the next one says it, well before the run is held dead.
133
+ held.beating = setInterval(() => void held.client.query(beat).catch(() => undefined), BEAT_SECONDS * 1000);
134
+ held.beating.unref();
135
+ }
136
+
137
+ async function ended(held: Held): Promise<void> {
138
+ held.ended = true;
139
+ clearInterval(held.beating);
140
+ await held.client.end().catch(() => undefined);
141
+ }
@@ -1,11 +1,21 @@
1
1
  import { rm } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
- /** The global teardown of the test runs (`globalTeardown` of jest.config.js): deletes the cluster test-database-template.ts saved. */
4
+ /**
5
+ * The global teardown of the test runs (`globalTeardown` of jest.config.js): deletes the cluster
6
+ * test-database-template.ts saved, or ends the run test-database-setup.ts started on a server,
7
+ * which left its end where this file finds it. It imports nothing of the project: the unit run
8
+ * loads it too, with the resolution of Node, which knows no alias.
9
+ */
5
10
  export default async function teardown(): Promise<void> {
6
11
  const file = process.env['TEST_DATABASE_TEMPLATE'];
12
+ const end: unknown = Reflect.get(globalThis, Symbol.for('ddd-ts-kit.test-database-run'));
7
13
 
8
14
  if (file !== undefined) {
9
15
  await rm(path.dirname(file), { recursive: true, force: true });
10
16
  }
17
+
18
+ if (typeof end === 'function') {
19
+ await Reflect.apply(end, undefined, []);
20
+ }
11
21
  }
@@ -2,6 +2,13 @@ import { forKinds, retry, timeout, when, type Aspect } from '@ddd-ts-kit/aspects
2
2
  import { adaptersWithOwnPolicy } from '{{alias.platform}}/resilience/adapters-with-own-policy{{alias.ext}}';
3
3
  import type { ResilienceSettings } from '{{alias.platform}}/resilience/resilience-settings{{alias.ext}}';
4
4
 
5
+ /**
6
+ * What a call cut by the default limit says after its duration: the adapter never chose that limit, and
7
+ * one that only hands the call to a slower adapter is cut before the answer, under its own name.
8
+ */
9
+ const STATED_BY =
10
+ 'the default policy of the external and gateway adapters, OUTBOUND_TIMEOUT_MS: `ownPolicy(timeout(<ms>))` on the declaration or the binding of this adapter states another, at least as long as the adapter it calls';
11
+
5
12
  /**
6
13
  * What goes around every adapter that leaves the process (`external`, `gateway`) and states no
7
14
  * policy of its own: retries with backoff, and a time limit for each attempt. `forKinds` is the
@@ -11,7 +18,7 @@ export function defaultPolicy(settings: ResilienceSettings): Aspect {
11
18
  const policy = when(
12
19
  forKinds('external', 'gateway'),
13
20
  retry({ attempts: settings.retryAttempts, backoff: { baseMs: settings.retryBaseDelayMs } }),
14
- timeout(settings.timeoutMs),
21
+ timeout(settings.timeoutMs, { statedBy: STATED_BY }),
15
22
  );
16
23
 
17
24
  return (instance, info) => (adaptersWithOwnPolicy.has(instance) ? instance : policy(instance, info));
@@ -24,11 +24,11 @@ paths:
24
24
  {{/if}}
25
25
  {{#if style.declared}}
26
26
  - An adapter declares itself on its class, one per file (`declarations/role-declared`): `@Repository(InvoiceRepository)`, `@Gateway(Port)` or `@Adapter(Port, { kind })`. What it is given is what its constructor takes, each parameter typed by one class (`{{persistence.tokenOrNone}}`, `ExecutionScope`, `Clock`, a port, an abstract class the platform binds to a value) and nothing listed in the decorator (`declarations/constructor-injection`); an adapter that extends a class of a package writes its own constructor.
27
- - Retry, timeout and cache go on the declaration (`aspects: [ownPolicy(retry(...), timeout(...))]`) or, when the policy is part of what the adapter is, as decorators of `@ddd-ts-kit/aspects/decorators` (`aspects/outside-in`). Kinds `external` and `gateway` get the default policy of the platform otherwise. `ownPolicy` is the helper of `{{alias.platform}}/resilience/own-policy{{alias.ext}}`, which `generate adapter` writes when the platform does not have it yet.
27
+ - Retry, timeout and cache go on the declaration (`aspects: [ownPolicy(retry(...), timeout(...))]`) or, when the policy is part of what the adapter is, as decorators of `@ddd-ts-kit/aspects/decorators` (`aspects/outside-in`). Kinds `external` and `gateway` get the default policy of the platform otherwise. One left to that default and given the port of an adapter that states a longer limit is cut first: state its policy, or `ownPolicy()` alone when it only hands the call over (`aspects/timeout-covers-delegate`). `ownPolicy` is the helper of `{{alias.platform}}/resilience/own-policy{{alias.ext}}`, which `generate adapter` writes when the platform does not have it yet.
28
28
  {{/if}}
29
29
  {{#if style.explicit}}
30
30
  - An adapter is bound to its port in `<context>.module.ts` only (`composition/only-in-module`), with its kind (`repository`, `gateway`, `external`).
31
- - Retry, timeout and cache go on the binding (`ownPolicy(retry(...), timeout(...))`) or, when the policy is part of what the adapter is, as decorators of `@ddd-ts-kit/aspects/decorators` (`aspects/outside-in`). Kinds `external` and `gateway` get the default policy of the platform otherwise. `ownPolicy` is the helper of `{{alias.platform}}/resilience/own-policy{{alias.ext}}`, which `generate adapter` writes when the platform does not have it yet.
31
+ - Retry, timeout and cache go on the binding (`ownPolicy(retry(...), timeout(...))`) or, when the policy is part of what the adapter is, as decorators of `@ddd-ts-kit/aspects/decorators` (`aspects/outside-in`). Kinds `external` and `gateway` get the default policy of the platform otherwise. One left to that default and given the port of an adapter that states a longer limit is cut first, under its own name: when you bind an adapter that is given a port, compare the two limits yourself and state its policy, or `ownPolicy()` alone when it only hands the call over. `ownPolicy` is the helper of `{{alias.platform}}/resilience/own-policy{{alias.ext}}`, which `generate adapter` writes when the platform does not have it yet.
32
32
  {{/if}}
33
33
  - A repository only persists: no `pullEvents()`, no dispatcher (`domain-events/dispatched-on-save`). A removal that announces an event takes the aggregate, not its id.
34
34
  {{#if eventSourcing.on}}
@@ -0,0 +1,83 @@
1
+ import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
2
+ import { readModelTables } from '{{alias.platform}}/database/read-model-tables{{alias.ext}}';
3
+
4
+ // The read model tables the application lists ({{config.platformDir}}/database/read-model-tables.ts),
5
+ // checked from the command line as the application checks them when it starts:
6
+ // DATABASE_URL=<the database of the deployment> npm run db:read-models
7
+ // DATABASE_URL=<the database of a service> npm run db:read-models -- --context <context>
8
+ // Every listed table without `--context`; with it, given once per context, the tables of those
9
+ // contexts alone, as a context run as a service of its own checks them on its database.
10
+ // Before a deployment, on the database it is about to reach, once its migrations ran; after
11
+ // `npm run db:migrate` on an empty database, it says the same of the migrations of the project.
12
+ // It needs DATABASE_URL and no other variable of the application; a `.env` file gives it when the
13
+ // command line does not, so it prints the database it read, never its credentials. Then the
14
+ // tables it read and each one that cannot hold the trace of a deleted row, or that it could not
15
+ // read, with what keeps it from it and the migration to write. Exit code: 0 when every listed
16
+ // table is ready, 1 when one is not, 2 when DATABASE_URL names no database, 3 when no table
17
+ // could be read (the database does not answer, or refuses the reading), 4 when `--context` names
18
+ // a context no listed read model belongs to: a misspelt name would otherwise check nothing.
19
+ const NOT_READY = 1;
20
+ const NO_DATABASE = 2;
21
+ const UNREAD = 3;
22
+ const NO_SUCH_CONTEXT = 4;
23
+
24
+ process.exitCode = await checked(process.env['DATABASE_URL'], contextsOf(process.argv));
25
+
26
+ /** The contexts named after `--context`; none, every context. */
27
+ function contextsOf(args: readonly string[]): readonly string[] | undefined {
28
+ const named = args.filter((_, index) => args[index - 1] === '--context');
29
+
30
+ return named.length === 0 ? undefined : named;
31
+ }
32
+
33
+ async function checked(databaseUrl = '', contexts?: readonly string[]): Promise<number> {
34
+ if (!URL.canParse(databaseUrl)) {
35
+ console.error('DATABASE_URL names no database: set it to the address of the database to check.');
36
+
37
+ return NO_DATABASE;
38
+ }
39
+
40
+ try {
41
+ return await read(databaseUrl, contexts);
42
+ } catch (error) {
43
+ console.error(`The database could not be read: ${error instanceof Error ? error.message : String(error)}`);
44
+
45
+ return UNREAD;
46
+ }
47
+ }
48
+
49
+ async function read(databaseUrl: string, contexts?: readonly string[]): Promise<number> {
50
+ const { host, pathname } = new URL(databaseUrl);
51
+ const scope = contexts === undefined ? 'every context' : contexts.join(', ');
52
+
53
+ console.log(`Database ${pathname.slice(1)} on ${host}, ${scope}.`);
54
+
55
+ {{#if orm.prisma}}
56
+ // The bounds of a transaction are those of Prisma: the check opens none.
57
+ const persistence = await openPersistence({ databaseUrl, databaseTransaction: { waitMs: 2_000, timeoutMs: 5_000 } });
58
+ {{/if}}
59
+ {{#unless orm.prisma}}
60
+ const persistence = {{persistence.await}}openPersistence({ databaseUrl });
61
+ {{/unless}}
62
+
63
+ try {
64
+ const tables = readModelTables(persistence);
65
+ const unknown = (contexts ?? []).filter((context) => !tables.contexts.includes(context));
66
+
67
+ if (unknown.length > 0) {
68
+ const held = tables.contexts.length === 0 ? 'no read model' : `those of ${tables.contexts.join(', ')}`;
69
+
70
+ console.error(`No listed read model belongs to ${unknown.join(', ')}: the list holds ${held}.`);
71
+
72
+ return NO_SUCH_CONTEXT;
73
+ }
74
+
75
+ const { outcome, text } = await tables.hosting(contexts).report();
76
+
77
+ console.log(text);
78
+
79
+ return { ready: 0, 'not-ready': NOT_READY, unread: UNREAD }[outcome];
80
+ } finally {
81
+ await persistence.close();
82
+ }
83
+ }
@@ -1,26 +1,91 @@
1
1
  import { Readable } from 'node:stream';
2
+ {{#if upload.isText}}
3
+ import { buffer } from 'node:stream/consumers';
4
+ {{/if}}
2
5
  import { describe, expect, it } from '{{tests.module}}';
3
6
  import { nestControllerRoute } from '@ddd-ts-kit/http/nest';
4
7
  import { routeOf } from '@ddd-ts-kit/http/testing';
8
+ {{#if upload.isText}}
9
+ import { multipartUploads } from '@ddd-ts-kit/http/uploads';
10
+ import { KitCodes } from '@ddd-ts-kit/kernel';
11
+ {{/if}}
5
12
  import { RecordingCommandBus } from '@ddd-ts-kit/kernel/testing';
6
13
  {{route.messageImport}}
7
14
  {{route.specImports}}
15
+ {{#if upload.isText}}
16
+
17
+ const BOUNDARY = 'boundary';
18
+ /** An export as a spreadsheet on Windows writes it: the accented letter is one byte, not UTF-8. */
19
+ const WINDOWS_1252 = Buffer.from('label;amount\r\ncaf\xe9;3,50\r\n', 'latin1');
20
+ {{#unless upload.singleByte}}
21
+ const UTF_8 = Buffer.from('label;amount\r\ncafé;3,50\r\n', 'utf8');
22
+ {{/unless}}
23
+ /** The first bytes of an Excel workbook: a binary file, whatever its name and its declared type say. */
24
+ const WORKBOOK = Buffer.from([0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]);
25
+ {{/if}}
8
26
 
9
27
  describe('{{route.method}} {{route.path}}', () => {
10
28
  it('declares the file it receives, and hands it to the command as it streams', async () => {
11
29
  const commands = new RecordingCommandBus().answering({{route.input}}, () => 'file-1');
12
30
  const served = nestControllerRoute({{name.pascal}}Controller, { instanceOf: () => new {{name.pascal}}Controller(commands) });
13
- const file = { fileName: 'scan.pdf', mediaType: 'application/pdf', stream: Readable.from([Buffer.from('%PDF-')]) };
31
+ const file = { fileName: '{{upload.fileName}}', mediaType: '{{upload.mediaType}}', stream: Readable.from([Buffer.from({{upload.head}})]) };
14
32
  const uploads = async () => ({ fields: {}, file });
15
33
  const { route{{#if route.protected}}, caller{{/if}}, send } = routeOf(served, { uploads });
16
34
 
17
35
  const response = await send({{route.sentRequest}});
18
36
 
19
37
  expect(response.status).toBe(201);
20
- expect(commands.executed).toMatchObject([{ {{#if route.protected}}actor: caller, {{/if}}upload: { area: '{{name.kebab}}', received: { fileName: 'scan.pdf' } } }]);
38
+ expect(commands.executed).toMatchObject([{ {{#if route.protected}}actor: caller, {{/if}}upload: { area: '{{name.kebab}}', received: { fileName: '{{upload.fileName}}' } } }]);
21
39
  expect(route.upload?.field).toBe('file');
22
40
  });
41
+ {{#if upload.isText}}
42
+
43
+ {{#if upload.singleByte}}
44
+ it('receives byte for byte a text file that is not UTF-8, and refuses a workbook under the name of a CSV', async () => {
45
+ {{/if}}
46
+ {{#unless upload.singleByte}}
47
+ it('receives a text file in UTF-8, and refuses one in another encoding or a workbook under the name of a CSV', async () => {
48
+ {{/unless}}
49
+ let received: Buffer = Buffer.alloc(0);
50
+
51
+ const commands = new RecordingCommandBus().answering({{route.input}}, async (command) => {
52
+ received = await buffer(command.upload.received.stream);
53
+
54
+ return 'file-1';
55
+ });
56
+
57
+ const served = nestControllerRoute({{name.pascal}}Controller, { instanceOf: () => new {{name.pascal}}Controller(commands) });
58
+ const { send } = routeOf(served, { uploads: multipartUploads() });
59
+ const sent = {{route.sentRequest}};
60
+
61
+ const taken = await send({ ...sent, ...aForm({{upload.taken}}) });
62
+ {{#unless upload.singleByte}}
63
+ const inAnotherEncoding = await send({ ...sent, ...aForm(WINDOWS_1252) });
64
+ {{/unless}}
65
+ const binary = await send({ ...sent, ...aForm(WORKBOOK) });
66
+
67
+ expect(taken.status).toBe(201);
68
+ expect(received).toEqual({{upload.taken}});
69
+ {{#unless upload.singleByte}}
70
+ expect(inAnotherEncoding).toMatchObject({ status: 415, body: { code: KitCodes.UnsupportedMediaType } });
71
+ {{/unless}}
72
+ expect(binary).toMatchObject({ status: 415, body: { code: KitCodes.UnsupportedMediaType } });
73
+ });
74
+ {{/if}}
23
75
 
24
76
  // TODO(domain): replace each entry below by a test of the same shape, through the same `routeOf` (`{ caller }` names another one, `anonymousActor()` of the kernel nobody).
25
77
  it.todo('answers the documented status for each error code of the use case');
26
78
  });
79
+ {{#if upload.isText}}
80
+
81
+ /** A multipart form as a browser sends it: the file under the field the route declares, its bytes as they are. */
82
+ function aForm(content: Buffer) {
83
+ const head = `--${BOUNDARY}\r\nContent-Disposition: form-data; name="file"; filename="export.csv"\r\nContent-Type: text/csv\r\n\r\n`;
84
+ const body = Buffer.concat([Buffer.from(head), content, Buffer.from(`\r\n--${BOUNDARY}--\r\n`)]);
85
+
86
+ return {
87
+ headers: { 'content-type': `multipart/form-data; boundary=${BOUNDARY}` },
88
+ stream: Readable.from([body]),
89
+ };
90
+ }
91
+ {{/if}}
@@ -13,7 +13,19 @@ export class {{name.pascal}}Controller {
13
13
  @{{route.nestMethod}}({{route.nestPath}})
14
14
  @KitRoute({
15
15
  // TODO(domain): the largest file and the media types "{{name.words}}" accepts: both are part of the contract, and the content is checked against them as it streams.
16
+ {{#unless upload.isText}}
16
17
  upload: { field: 'file', maxBytes: 10_485_760, mediaTypes: ['application/pdf', 'image/png', 'image/jpeg'] },
18
+ {{/unless}}
19
+ {{#if upload.isText}}
20
+ upload: {
21
+ field: 'file',
22
+ maxBytes: 10_485_760,
23
+ // A browser on Windows names a CSV `application/vnd.ms-excel`: the kit has no content rule for it, so the route states one.
24
+ mediaTypes: ['text/csv', 'application/csv', 'application/vnd.ms-excel'],
25
+ text: '{{upload.text}}',
26
+ contentRules: { 'application/vnd.ms-excel': 'text' },
27
+ },
28
+ {{/if}}
17
29
  response: { status: 201, description: 'Stored; the file is visible once the command has committed.' },
18
30
  // TODO(domain): list the codes of the refusals "{{name.words}}" can raise, as their factories set them, so that they appear in the contract with their status (`errors/known-code`).
19
31
  errors: [],
@@ -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.111.0",
26
+ "@ddd-ts-kit/eslint-plugin": "^0.112.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,5 +1,5 @@
1
1
  import { and, eq } from 'drizzle-orm';
2
- import { optimisticUpdate, primaryKeyOf } from '@ddd-ts-kit/drizzle/postgres';
2
+ import { insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/drizzle/postgres';
3
3
  import { stampCreation, stampUpdate, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
4
4
  {{#if style.declared}}
5
5
  import { Repository } from '@ddd-ts-kit/kernel/declarations';
@@ -36,20 +36,16 @@ export class DrizzleAccountRepository implements AccountRepository {
36
36
  async save(saved: Account): Promise<void> {
37
37
  await optimisticUpdate(saved, async ({ expected, next }) => {
38
38
  const state = { ...AccountMapper.toRow(saved), version: next };
39
- const written = expected === 0 ? await this.insert(state) : await this.update(state, expected);
40
39
 
41
- return written.length;
40
+ return expected === 0 ? this.insert(state) : (await this.update(state, expected)).length;
42
41
  });
43
42
  }
44
43
 
45
- private insert(state: VersionedAccount) {
44
+ private async insert(state: VersionedAccount): Promise<number> {
46
45
  const row = { ...state, ...stampCreation(this.scope, this.clock) };
46
+ const insertion = () => executorOf(this.database).insert(accounts).values(row);
47
47
 
48
- return executorOf(this.database)
49
- .insert(accounts)
50
- .values(row)
51
- .onConflictDoNothing({ target: primaryKeyOf(accounts) })
52
- .returning({ id: accounts.id });
48
+ return (await insertIgnoringConflict(insertion, accounts)) ? 1 : 0;
53
49
  }
54
50
 
55
51
  private update(state: VersionedAccount, expected: number) {
@@ -1,5 +1,5 @@
1
1
  import { and, eq, isNull, or } from 'drizzle-orm';
2
- import { optimisticUpdate, primaryKeyOf } from '@ddd-ts-kit/drizzle/postgres';
2
+ import { insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/drizzle/postgres';
3
3
  import { stampCreation, stampUpdate, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
4
4
  {{#if style.declared}}
5
5
  import { Repository } from '@ddd-ts-kit/kernel/declarations';
@@ -50,20 +50,16 @@ export class DrizzleDelegationRepository implements DelegationRepository {
50
50
  async save(saved: Delegation): Promise<void> {
51
51
  await optimisticUpdate(saved, async ({ expected, next }) => {
52
52
  const state = { ...DelegationMapper.toRow(saved), version: next };
53
- const written = expected === 0 ? await this.insert(state) : await this.update(state, expected);
54
53
 
55
- return written.length;
54
+ return expected === 0 ? this.insert(state) : (await this.update(state, expected)).length;
56
55
  });
57
56
  }
58
57
 
59
- private insert(state: VersionedDelegation) {
58
+ private async insert(state: VersionedDelegation): Promise<number> {
60
59
  const row = { ...state, ...stampCreation(this.scope, this.clock) };
60
+ const insertion = () => executorOf(this.database).insert(delegations).values(row);
61
61
 
62
- return executorOf(this.database)
63
- .insert(delegations)
64
- .values(row)
65
- .onConflictDoNothing({ target: primaryKeyOf(delegations) })
66
- .returning({ id: delegations.id });
62
+ return (await insertIgnoringConflict(insertion, delegations)) ? 1 : 0;
67
63
  }
68
64
 
69
65
  private update(state: VersionedDelegation, expected: number) {
@@ -1,5 +1,5 @@
1
1
  import { and, eq } from 'drizzle-orm';
2
- import { optimisticUpdate, primaryKeyOf } from '@ddd-ts-kit/drizzle/postgres';
2
+ import { insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/drizzle/postgres';
3
3
  import { stampCreation, stampUpdate, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
4
4
  {{#if style.declared}}
5
5
  import { Repository } from '@ddd-ts-kit/kernel/declarations';
@@ -42,20 +42,16 @@ export class DrizzleInvitationRepository implements InvitationRepository {
42
42
  async save(saved: Invitation): Promise<void> {
43
43
  await optimisticUpdate(saved, async ({ expected, next }) => {
44
44
  const state = { ...InvitationMapper.toRow(saved), version: next };
45
- const written = expected === 0 ? await this.insert(state) : await this.update(state, expected);
46
45
 
47
- return written.length;
46
+ return expected === 0 ? this.insert(state) : (await this.update(state, expected)).length;
48
47
  });
49
48
  }
50
49
 
51
- private insert(state: VersionedInvitation) {
50
+ private async insert(state: VersionedInvitation): Promise<number> {
52
51
  const row = { ...state, ...stampCreation(this.scope, this.clock) };
52
+ const insertion = () => executorOf(this.database).insert(invitations).values(row);
53
53
 
54
- return executorOf(this.database)
55
- .insert(invitations)
56
- .values(row)
57
- .onConflictDoNothing({ target: primaryKeyOf(invitations) })
58
- .returning({ id: invitations.id });
54
+ return (await insertIgnoringConflict(insertion, invitations)) ? 1 : 0;
59
55
  }
60
56
 
61
57
  private update(state: VersionedInvitation, expected: number) {
@@ -1,5 +1,5 @@
1
1
  import { and, count, eq, isNull } from 'drizzle-orm';
2
- import { optimisticUpdate, primaryKeyOf } from '@ddd-ts-kit/drizzle/postgres';
2
+ import { insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/drizzle/postgres';
3
3
  import { stampCreation, stampUpdate, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
4
4
  {{#if style.declared}}
5
5
  import { Repository } from '@ddd-ts-kit/kernel/declarations';
@@ -57,20 +57,16 @@ export class DrizzleMemberRepository implements MemberRepository {
57
57
  async save(saved: Member): Promise<void> {
58
58
  await optimisticUpdate(saved, async ({ expected, next }) => {
59
59
  const state = { ...MemberMapper.toRow(saved), version: next };
60
- const written = expected === 0 ? await this.insert(state) : await this.update(state, expected);
61
60
 
62
- return written.length;
61
+ return expected === 0 ? this.insert(state) : (await this.update(state, expected)).length;
63
62
  });
64
63
  }
65
64
 
66
- private insert(state: VersionedMember) {
65
+ private async insert(state: VersionedMember): Promise<number> {
67
66
  const row = { ...state, ...stampCreation(this.scope, this.clock) };
67
+ const insertion = () => executorOf(this.database).insert(members).values(row);
68
68
 
69
- return executorOf(this.database)
70
- .insert(members)
71
- .values(row)
72
- .onConflictDoNothing({ target: primaryKeyOf(members) })
73
- .returning({ id: members.id });
69
+ return (await insertIgnoringConflict(insertion, members)) ? 1 : 0;
74
70
  }
75
71
 
76
72
  private update(state: VersionedMember, expected: number) {
@@ -1,5 +1,5 @@
1
1
  import { and, eq } from 'drizzle-orm';
2
- import { optimisticUpdate, primaryKeyOf } from '@ddd-ts-kit/drizzle/postgres';
2
+ import { insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/drizzle/postgres';
3
3
  import { stampCreation, stampUpdate, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
4
4
  {{#if style.declared}}
5
5
  import { Repository } from '@ddd-ts-kit/kernel/declarations';
@@ -36,20 +36,16 @@ export class DrizzleOrganisationRepository implements OrganisationRepository {
36
36
  async save(saved: Organisation): Promise<void> {
37
37
  await optimisticUpdate(saved, async ({ expected, next }) => {
38
38
  const state = { ...OrganisationMapper.toRow(saved), version: next };
39
- const written = expected === 0 ? await this.insert(state) : await this.update(state, expected);
40
39
 
41
- return written.length;
40
+ return expected === 0 ? this.insert(state) : (await this.update(state, expected)).length;
42
41
  });
43
42
  }
44
43
 
45
- private insert(state: VersionedOrganisation) {
44
+ private async insert(state: VersionedOrganisation): Promise<number> {
46
45
  const row = { ...state, ...stampCreation(this.scope, this.clock) };
46
+ const insertion = () => executorOf(this.database).insert(organisations).values(row);
47
47
 
48
- return executorOf(this.database)
49
- .insert(organisations)
50
- .values(row)
51
- .onConflictDoNothing({ target: primaryKeyOf(organisations) })
52
- .returning({ id: organisations.id });
48
+ return (await insertIgnoringConflict(insertion, organisations)) ? 1 : 0;
53
49
  }
54
50
 
55
51
  private update(state: VersionedOrganisation, expected: number) {
@@ -1,9 +1,9 @@
1
1
  import { and, eq } from 'drizzle-orm';
2
2
  {{#if tenant.scoped}}
3
- import { optimisticUpdate, ownTenantCondition, primaryKeyOf, tenantCondition } from '@ddd-ts-kit/drizzle/postgres';
3
+ import { insertIgnoringConflict, optimisticUpdate, ownTenantCondition, tenantCondition } from '@ddd-ts-kit/drizzle/postgres';
4
4
  {{/if}}
5
5
  {{#unless tenant.scoped}}
6
- import { optimisticUpdate, primaryKeyOf } from '@ddd-ts-kit/drizzle/postgres';
6
+ import { insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/drizzle/postgres';
7
7
  {{/unless}}
8
8
  {{#if tenant.scoped}}
9
9
  import { stampCreation, stampUpdate, tenantScopeOf, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
@@ -53,19 +53,16 @@ export class Drizzle{{aggregate.pascal}}Repository implements {{aggregate.pascal
53
53
  async save(saved: {{aggregate.pascal}}): Promise<void> {
54
54
  await optimisticUpdate(saved, async ({ expected, next }) => {
55
55
  const state = { ...{{aggregate.pascal}}Mapper.toRow(saved), version: next };
56
- const written = expected === 0 ? await this.insert(state) : await this.update(state, expected);
57
56
 
58
- return written.length;
57
+ return expected === 0 ? this.insert(state) : (await this.update(state, expected)).length;
59
58
  });
60
59
  }
61
60
 
62
- private insert(state: Versioned{{aggregate.pascal}}) {
61
+ private async insert(state: Versioned{{aggregate.pascal}}): Promise<number> {
63
62
  const row = { ...state, {{#if tenant.scoped}}...tenantScopeOf(this.scope), {{/if}}...stampCreation(this.scope, this.clock) };
63
+ const insertion = () => this.database.executor().insert({{aggregate.tableCamel}}).values(row);
64
64
 
65
- const insertion = this.database.executor().insert({{aggregate.tableCamel}}).values(row);
66
- const ignoringTheKey = insertion.onConflictDoNothing({ target: primaryKeyOf({{aggregate.tableCamel}}) });
67
-
68
- return ignoringTheKey.returning({ id: {{aggregate.tableCamel}}.id });
65
+ return (await insertIgnoringConflict(insertion, {{aggregate.tableCamel}})) ? 1 : 0;
69
66
  }
70
67
 
71
68
  private update(state: Versioned{{aggregate.pascal}}, expected: number) {