ddd-ts-kit 0.89.0 → 0.91.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 (463) hide show
  1. package/CHANGELOG.md +318 -0
  2. package/README.fr.md +58 -12
  3. package/README.md +54 -11
  4. package/dist/alias/index.d.ts +2 -1
  5. package/dist/alias/index.d.ts.map +1 -1
  6. package/dist/alias/index.js +1 -0
  7. package/dist/alias/index.js.map +1 -1
  8. package/dist/alias/mapper-target-text.d.ts +4 -0
  9. package/dist/alias/mapper-target-text.d.ts.map +1 -0
  10. package/dist/alias/mapper-target-text.js +5 -0
  11. package/dist/alias/mapper-target-text.js.map +1 -0
  12. package/dist/alias/module-name-mapper.d.ts +5 -2
  13. package/dist/alias/module-name-mapper.d.ts.map +1 -1
  14. package/dist/alias/module-name-mapper.js +5 -2
  15. package/dist/alias/module-name-mapper.js.map +1 -1
  16. package/dist/check/alias/test-runners.js +8 -3
  17. package/dist/check/alias/test-runners.js.map +1 -1
  18. package/dist/check/baseline/apply-baseline.d.ts +14 -0
  19. package/dist/check/baseline/apply-baseline.d.ts.map +1 -0
  20. package/dist/check/baseline/apply-baseline.js +30 -0
  21. package/dist/check/baseline/apply-baseline.js.map +1 -0
  22. package/dist/check/baseline/baseline-following-moves.d.ts +9 -0
  23. package/dist/check/baseline/baseline-following-moves.d.ts.map +1 -0
  24. package/dist/check/baseline/baseline-following-moves.js +10 -0
  25. package/dist/check/baseline/baseline-following-moves.js.map +1 -0
  26. package/dist/check/baseline/baseline-move.d.ts +6 -0
  27. package/dist/check/baseline/baseline-move.d.ts.map +1 -0
  28. package/dist/check/baseline/baseline-move.js +2 -0
  29. package/dist/check/baseline/baseline-move.js.map +1 -0
  30. package/dist/check/baseline/baseline-text.d.ts +4 -0
  31. package/dist/check/baseline/baseline-text.d.ts.map +1 -0
  32. package/dist/check/baseline/baseline-text.js +12 -0
  33. package/dist/check/baseline/baseline-text.js.map +1 -0
  34. package/dist/check/baseline/baseline.d.ts +6 -0
  35. package/dist/check/baseline/baseline.d.ts.map +1 -0
  36. package/dist/check/baseline/baseline.js +2 -0
  37. package/dist/check/baseline/baseline.js.map +1 -0
  38. package/dist/check/baseline/moved-baseline-text.d.ts +4 -0
  39. package/dist/check/baseline/moved-baseline-text.d.ts.map +1 -0
  40. package/dist/check/baseline/moved-baseline-text.js +13 -0
  41. package/dist/check/baseline/moved-baseline-text.js.map +1 -0
  42. package/dist/check/baseline/parse-baseline.d.ts +4 -0
  43. package/dist/check/baseline/parse-baseline.d.ts.map +1 -0
  44. package/dist/check/baseline/parse-baseline.js +19 -0
  45. package/dist/check/baseline/parse-baseline.js.map +1 -0
  46. package/dist/check/baseline/pruned-baseline.d.ts +5 -0
  47. package/dist/check/baseline/pruned-baseline.d.ts.map +1 -0
  48. package/dist/check/baseline/pruned-baseline.js +14 -0
  49. package/dist/check/baseline/pruned-baseline.js.map +1 -0
  50. package/dist/check/baseline/read-baseline.d.ts +6 -0
  51. package/dist/check/baseline/read-baseline.d.ts.map +1 -0
  52. package/dist/check/baseline/read-baseline.js +11 -0
  53. package/dist/check/baseline/read-baseline.js.map +1 -0
  54. package/dist/check/baseline/recorded-baseline.d.ts +5 -0
  55. package/dist/check/baseline/recorded-baseline.d.ts.map +1 -0
  56. package/dist/check/baseline/recorded-baseline.js +11 -0
  57. package/dist/check/baseline/recorded-baseline.js.map +1 -0
  58. package/dist/check/baseline/renamed-files.d.ts +8 -0
  59. package/dist/check/baseline/renamed-files.d.ts.map +1 -0
  60. package/dist/check/baseline/renamed-files.js +23 -0
  61. package/dist/check/baseline/renamed-files.js.map +1 -0
  62. package/dist/check/baseline/write-baseline.d.ts +4 -0
  63. package/dist/check/baseline/write-baseline.d.ts.map +1 -0
  64. package/dist/check/baseline/write-baseline.js +9 -0
  65. package/dist/check/baseline/write-baseline.js.map +1 -0
  66. package/dist/check/canonical/stray-entry.d.ts.map +1 -1
  67. package/dist/check/canonical/stray-entry.js +5 -1
  68. package/dist/check/canonical/stray-entry.js.map +1 -1
  69. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  70. package/dist/check/catalogue/architecture-rules.js +4 -0
  71. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  72. package/dist/check/catalogue/default-severities.d.ts.map +1 -1
  73. package/dist/check/catalogue/default-severities.js +0 -4
  74. package/dist/check/catalogue/default-severities.js.map +1 -1
  75. package/dist/check/commands/check-command.d.ts.map +1 -1
  76. package/dist/check/commands/check-command.js +46 -1
  77. package/dist/check/commands/check-command.js.map +1 -1
  78. package/dist/check/commands/check-file-command.d.ts +5 -0
  79. package/dist/check/commands/check-file-command.d.ts.map +1 -1
  80. package/dist/check/commands/check-file-command.js +27 -6
  81. package/dist/check/commands/check-file-command.js.map +1 -1
  82. package/dist/check/explain/nest-docs.d.ts +3 -0
  83. package/dist/check/explain/nest-docs.d.ts.map +1 -0
  84. package/dist/check/explain/nest-docs.js +31 -0
  85. package/dist/check/explain/nest-docs.js.map +1 -0
  86. package/dist/check/explain/rule-docs.d.ts.map +1 -1
  87. package/dist/check/explain/rule-docs.js +2 -0
  88. package/dist/check/explain/rule-docs.js.map +1 -1
  89. package/dist/check/fixtures/alias-declared-fixtures.js +1 -1
  90. package/dist/check/fixtures/alias-declared-fixtures.js.map +1 -1
  91. package/dist/check/fixtures/authz-declared-fixtures.js +1 -1
  92. package/dist/check/fixtures/authz-declared-fixtures.js.map +1 -1
  93. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  94. package/dist/check/fixtures/fixtures.js +4 -0
  95. package/dist/check/fixtures/fixtures.js.map +1 -1
  96. package/dist/check/fixtures/nest-controllers-fixtures.d.ts +3 -0
  97. package/dist/check/fixtures/nest-controllers-fixtures.d.ts.map +1 -0
  98. package/dist/check/fixtures/nest-controllers-fixtures.js +86 -0
  99. package/dist/check/fixtures/nest-controllers-fixtures.js.map +1 -0
  100. package/dist/check/fixtures/nest-fixtures.d.ts +3 -0
  101. package/dist/check/fixtures/nest-fixtures.d.ts.map +1 -0
  102. package/dist/check/fixtures/nest-fixtures.js +59 -0
  103. package/dist/check/fixtures/nest-fixtures.js.map +1 -0
  104. package/dist/check/nest/nest-equivalents-of.d.ts +14 -0
  105. package/dist/check/nest/nest-equivalents-of.d.ts.map +1 -0
  106. package/dist/check/nest/nest-equivalents-of.js +119 -0
  107. package/dist/check/nest/nest-equivalents-of.js.map +1 -0
  108. package/dist/check/project/load-project.d.ts +2 -0
  109. package/dist/check/project/load-project.d.ts.map +1 -1
  110. package/dist/check/project/load-project.js +7 -3
  111. package/dist/check/project/load-project.js.map +1 -1
  112. package/dist/check/rules/nest-controllers-current.d.ts +3 -0
  113. package/dist/check/rules/nest-controllers-current.d.ts.map +1 -0
  114. package/dist/check/rules/nest-controllers-current.js +43 -0
  115. package/dist/check/rules/nest-controllers-current.js.map +1 -0
  116. package/dist/check/rules/nest-no-parallel-pipeline.d.ts +3 -0
  117. package/dist/check/rules/nest-no-parallel-pipeline.d.ts.map +1 -0
  118. package/dist/check/rules/nest-no-parallel-pipeline.js +70 -0
  119. package/dist/check/rules/nest-no-parallel-pipeline.js.map +1 -0
  120. package/dist/check/support/is-generated-context-file.d.ts.map +1 -1
  121. package/dist/check/support/is-generated-context-file.js +4 -1
  122. package/dist/check/support/is-generated-context-file.js.map +1 -1
  123. package/dist/commands/doctor.d.ts.map +1 -1
  124. package/dist/commands/doctor.js +4 -2
  125. package/dist/commands/doctor.js.map +1 -1
  126. package/dist/commands/init.d.ts.map +1 -1
  127. package/dist/commands/init.js +1 -0
  128. package/dist/commands/init.js.map +1 -1
  129. package/dist/config/config.d.ts +6 -0
  130. package/dist/config/config.d.ts.map +1 -1
  131. package/dist/config/index.d.ts +1 -1
  132. package/dist/config/index.d.ts.map +1 -1
  133. package/dist/config/index.js +1 -1
  134. package/dist/config/index.js.map +1 -1
  135. package/dist/config/parse-config.js +1 -0
  136. package/dist/config/parse-config.js.map +1 -1
  137. package/dist/config/parse-stack.d.ts.map +1 -1
  138. package/dist/config/parse-stack.js +2 -1
  139. package/dist/config/parse-stack.js.map +1 -1
  140. package/dist/config/serialize-config.js +9 -2
  141. package/dist/config/serialize-config.js.map +1 -1
  142. package/dist/config/stack.d.ts +17 -4
  143. package/dist/config/stack.d.ts.map +1 -1
  144. package/dist/config/stack.js +4 -1
  145. package/dist/config/stack.js.map +1 -1
  146. package/dist/dev/refresh-declarations.d.ts.map +1 -1
  147. package/dist/dev/refresh-declarations.js +4 -1
  148. package/dist/dev/refresh-declarations.js.map +1 -1
  149. package/dist/docs/write-docs.d.ts.map +1 -1
  150. package/dist/docs/write-docs.js +2 -0
  151. package/dist/docs/write-docs.js.map +1 -1
  152. package/dist/doctor/diagnose.d.ts +2 -1
  153. package/dist/doctor/diagnose.d.ts.map +1 -1
  154. package/dist/doctor/diagnose.js +4 -1
  155. package/dist/doctor/diagnose.js.map +1 -1
  156. package/dist/doctor/doctor-finding.d.ts +3 -2
  157. package/dist/doctor/doctor-finding.d.ts.map +1 -1
  158. package/dist/doctor/format-diagnosis.js +4 -1
  159. package/dist/doctor/format-diagnosis.js.map +1 -1
  160. package/dist/doctor/override-findings.d.ts +10 -0
  161. package/dist/doctor/override-findings.d.ts.map +1 -0
  162. package/dist/doctor/override-findings.js +87 -0
  163. package/dist/doctor/override-findings.js.map +1 -0
  164. package/dist/file-moves/move-files.d.ts.map +1 -1
  165. package/dist/file-moves/move-files.js +10 -0
  166. package/dist/file-moves/move-files.js.map +1 -1
  167. package/dist/generate/kinds/property-kind.d.ts +3 -0
  168. package/dist/generate/kinds/property-kind.d.ts.map +1 -0
  169. package/dist/generate/kinds/property-kind.js +51 -0
  170. package/dist/generate/kinds/property-kind.js.map +1 -0
  171. package/dist/generate/kinds/route/nest-controller-vars.d.ts +11 -0
  172. package/dist/generate/kinds/route/nest-controller-vars.d.ts.map +1 -0
  173. package/dist/generate/kinds/route/nest-controller-vars.js +97 -0
  174. package/dist/generate/kinds/route/nest-controller-vars.js.map +1 -0
  175. package/dist/generate/kinds/route/route-vars.d.ts.map +1 -1
  176. package/dist/generate/kinds/route/route-vars.js +1 -9
  177. package/dist/generate/kinds/route/route-vars.js.map +1 -1
  178. package/dist/generate/kinds/route/success-status.d.ts +5 -0
  179. package/dist/generate/kinds/route/success-status.d.ts.map +1 -0
  180. package/dist/generate/kinds/route/success-status.js +11 -0
  181. package/dist/generate/kinds/route/success-status.js.map +1 -0
  182. package/dist/generate/kinds/route/write-nest-controller.d.ts +8 -0
  183. package/dist/generate/kinds/route/write-nest-controller.d.ts.map +1 -0
  184. package/dist/generate/kinds/route/write-nest-controller.js +52 -0
  185. package/dist/generate/kinds/route/write-nest-controller.js.map +1 -0
  186. package/dist/generate/kinds/route-kind.d.ts.map +1 -1
  187. package/dist/generate/kinds/route-kind.js +6 -1
  188. package/dist/generate/kinds/route-kind.js.map +1 -1
  189. package/dist/generate/kinds.d.ts.map +1 -1
  190. package/dist/generate/kinds.js +2 -0
  191. package/dist/generate/kinds.js.map +1 -1
  192. package/dist/generate/refresh-docs.d.ts.map +1 -1
  193. package/dist/generate/refresh-docs.js +2 -0
  194. package/dist/generate/refresh-docs.js.map +1 -1
  195. package/dist/generate/shared-writes.d.ts.map +1 -1
  196. package/dist/generate/shared-writes.js +5 -0
  197. package/dist/generate/shared-writes.js.map +1 -1
  198. package/dist/help/notes.d.ts +1 -1
  199. package/dist/help/notes.d.ts.map +1 -1
  200. package/dist/help/notes.js +3 -1
  201. package/dist/help/notes.js.map +1 -1
  202. package/dist/help/usage.d.ts +1 -1
  203. package/dist/help/usage.d.ts.map +1 -1
  204. package/dist/help/usage.js +4 -2
  205. package/dist/help/usage.js.map +1 -1
  206. package/dist/init/agent-permissions.js +2 -0
  207. package/dist/init/agent-permissions.js.map +1 -1
  208. package/dist/init/files/audit-files.js +1 -1
  209. package/dist/init/files/audit-files.js.map +1 -1
  210. package/dist/init/files/persistence-files.d.ts.map +1 -1
  211. package/dist/init/files/persistence-files.js +2 -0
  212. package/dist/init/files/persistence-files.js.map +1 -1
  213. package/dist/init/knip-vars.d.ts.map +1 -1
  214. package/dist/init/knip-vars.js +10 -2
  215. package/dist/init/knip-vars.js.map +1 -1
  216. package/dist/init/manifest/dependencies-against-stack.d.ts +18 -0
  217. package/dist/init/manifest/dependencies-against-stack.d.ts.map +1 -0
  218. package/dist/init/manifest/dependencies-against-stack.js +95 -0
  219. package/dist/init/manifest/dependencies-against-stack.js.map +1 -0
  220. package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
  221. package/dist/init/manifest/dependencies-for.js +12 -2
  222. package/dist/init/manifest/dependencies-for.js.map +1 -1
  223. package/dist/init/manifest/overrides-for.d.ts +7 -0
  224. package/dist/init/manifest/overrides-for.d.ts.map +1 -0
  225. package/dist/init/manifest/overrides-for.js +9 -0
  226. package/dist/init/manifest/overrides-for.js.map +1 -0
  227. package/dist/init/manifest/pinned-below-a-fix.d.ts +14 -0
  228. package/dist/init/manifest/pinned-below-a-fix.d.ts.map +1 -0
  229. package/dist/init/manifest/pinned-below-a-fix.js +20 -0
  230. package/dist/init/manifest/pinned-below-a-fix.js.map +1 -0
  231. package/dist/init/manifest/scripts-for.js +5 -2
  232. package/dist/init/manifest/scripts-for.js.map +1 -1
  233. package/dist/init/manifest/versions.d.ts.map +1 -1
  234. package/dist/init/manifest/versions.js +31 -25
  235. package/dist/init/manifest/versions.js.map +1 -1
  236. package/dist/init/manifest/write-overrides.d.ts +9 -0
  237. package/dist/init/manifest/write-overrides.d.ts.map +1 -0
  238. package/dist/init/manifest/write-overrides.js +56 -0
  239. package/dist/init/manifest/write-overrides.js.map +1 -0
  240. package/dist/init/run-init.d.ts.map +1 -1
  241. package/dist/init/run-init.js +19 -3
  242. package/dist/init/run-init.js.map +1 -1
  243. package/dist/init/stack/resolve-queue.d.ts +4 -10
  244. package/dist/init/stack/resolve-queue.d.ts.map +1 -1
  245. package/dist/init/stack/resolve-queue.js +7 -11
  246. package/dist/init/stack/resolve-queue.js.map +1 -1
  247. package/dist/init/stack/resolve-stack.d.ts.map +1 -1
  248. package/dist/init/stack/resolve-stack.js +23 -4
  249. package/dist/init/stack/resolve-stack.js.map +1 -1
  250. package/dist/init/stack/stack-options.d.ts +2 -0
  251. package/dist/init/stack/stack-options.d.ts.map +1 -1
  252. package/dist/nest-controllers/controllers-file.d.ts +3 -0
  253. package/dist/nest-controllers/controllers-file.d.ts.map +1 -0
  254. package/dist/nest-controllers/controllers-file.js +5 -0
  255. package/dist/nest-controllers/controllers-file.js.map +1 -0
  256. package/dist/nest-controllers/nest-answer.d.ts +16 -0
  257. package/dist/nest-controllers/nest-answer.d.ts.map +1 -0
  258. package/dist/nest-controllers/nest-answer.js +2 -0
  259. package/dist/nest-controllers/nest-answer.js.map +1 -0
  260. package/dist/nest-controllers/nest-controller-entry.d.ts +16 -0
  261. package/dist/nest-controllers/nest-controller-entry.d.ts.map +1 -0
  262. package/dist/nest-controllers/nest-controller-entry.js +2 -0
  263. package/dist/nest-controllers/nest-controller-entry.js.map +1 -0
  264. package/dist/nest-controllers/read-nest-controllers.d.ts +15 -0
  265. package/dist/nest-controllers/read-nest-controllers.d.ts.map +1 -0
  266. package/dist/nest-controllers/read-nest-controllers.js +89 -0
  267. package/dist/nest-controllers/read-nest-controllers.js.map +1 -0
  268. package/dist/nest-controllers/refresh-nest-controllers.d.ts +9 -0
  269. package/dist/nest-controllers/refresh-nest-controllers.d.ts.map +1 -0
  270. package/dist/nest-controllers/refresh-nest-controllers.js +32 -0
  271. package/dist/nest-controllers/refresh-nest-controllers.js.map +1 -0
  272. package/dist/nest-controllers/render-controllers-file.d.ts +8 -0
  273. package/dist/nest-controllers/render-controllers-file.d.ts.map +1 -0
  274. package/dist/nest-controllers/render-controllers-file.js +56 -0
  275. package/dist/nest-controllers/render-controllers-file.js.map +1 -0
  276. package/dist/platform-folders/platform-folders.d.ts.map +1 -1
  277. package/dist/platform-folders/platform-folders.js +10 -0
  278. package/dist/platform-folders/platform-folders.js.map +1 -1
  279. package/dist/presets/apply-preset.d.ts.map +1 -1
  280. package/dist/presets/apply-preset.js +22 -2
  281. package/dist/presets/apply-preset.js.map +1 -1
  282. package/dist/presets/identity-preset.d.ts.map +1 -1
  283. package/dist/presets/identity-preset.js +4 -1
  284. package/dist/presets/identity-preset.js.map +1 -1
  285. package/dist/presets/identity-refusal.d.ts.map +1 -1
  286. package/dist/presets/identity-refusal.js +11 -5
  287. package/dist/presets/identity-refusal.js.map +1 -1
  288. package/dist/presets/lay-out-prisma-models.d.ts +8 -0
  289. package/dist/presets/lay-out-prisma-models.d.ts.map +1 -0
  290. package/dist/presets/lay-out-prisma-models.js +51 -0
  291. package/dist/presets/lay-out-prisma-models.js.map +1 -0
  292. package/dist/presets/preset-files.d.ts.map +1 -1
  293. package/dist/presets/preset-files.js +3 -0
  294. package/dist/presets/preset-files.js.map +1 -1
  295. package/dist/presets/preset.d.ts +11 -0
  296. package/dist/presets/preset.d.ts.map +1 -1
  297. package/dist/sdk/client-files.d.ts +5 -3
  298. package/dist/sdk/client-files.d.ts.map +1 -1
  299. package/dist/sdk/client-files.js +8 -3
  300. package/dist/sdk/client-files.js.map +1 -1
  301. package/dist/sdk/client-manifest.d.ts +3 -0
  302. package/dist/sdk/client-manifest.d.ts.map +1 -1
  303. package/dist/sdk/client-manifest.js +15 -2
  304. package/dist/sdk/client-manifest.js.map +1 -1
  305. package/dist/sdk/client-operation.d.ts +6 -0
  306. package/dist/sdk/client-operation.d.ts.map +1 -1
  307. package/dist/sdk/read-operation.d.ts.map +1 -1
  308. package/dist/sdk/read-operation.js +6 -0
  309. package/dist/sdk/read-operation.js.map +1 -1
  310. package/dist/sdk/render-orpc.d.ts +8 -0
  311. package/dist/sdk/render-orpc.d.ts.map +1 -0
  312. package/dist/sdk/render-orpc.js +42 -0
  313. package/dist/sdk/render-orpc.js.map +1 -0
  314. package/dist/sdk/render-readme.d.ts +3 -0
  315. package/dist/sdk/render-readme.d.ts.map +1 -1
  316. package/dist/sdk/render-readme.js +46 -0
  317. package/dist/sdk/render-readme.js.map +1 -1
  318. package/dist/sdk/render-trpc.d.ts +9 -0
  319. package/dist/sdk/render-trpc.d.ts.map +1 -0
  320. package/dist/sdk/render-trpc.js +36 -0
  321. package/dist/sdk/render-trpc.js.map +1 -0
  322. package/dist/sdk/rpc-packages.d.ts +7 -0
  323. package/dist/sdk/rpc-packages.d.ts.map +1 -0
  324. package/dist/sdk/rpc-packages.js +9 -0
  325. package/dist/sdk/rpc-packages.js.map +1 -0
  326. package/dist/sdk/rpc.d.ts +4 -0
  327. package/dist/sdk/rpc.d.ts.map +1 -0
  328. package/dist/sdk/rpc.js +2 -0
  329. package/dist/sdk/rpc.js.map +1 -0
  330. package/dist/sdk/write-clients.d.ts.map +1 -1
  331. package/dist/sdk/write-clients.js +18 -3
  332. package/dist/sdk/write-clients.js.map +1 -1
  333. package/dist/stack/alias-vars.d.ts.map +1 -1
  334. package/dist/stack/alias-vars.js +2 -2
  335. package/dist/stack/alias-vars.js.map +1 -1
  336. package/dist/stack/audit-vars.js +1 -1
  337. package/dist/stack/audit-vars.js.map +1 -1
  338. package/dist/stack/cache-vars.d.ts +5 -1
  339. package/dist/stack/cache-vars.d.ts.map +1 -1
  340. package/dist/stack/cache-vars.js +9 -3
  341. package/dist/stack/cache-vars.js.map +1 -1
  342. package/dist/stack/stack-vars.d.ts +1 -1
  343. package/dist/stack/stack-vars.d.ts.map +1 -1
  344. package/dist/stack/stack-vars.js +11 -6
  345. package/dist/stack/stack-vars.js.map +1 -1
  346. package/dist/version.d.ts +1 -1
  347. package/dist/version.js +1 -1
  348. package/package.json +4 -4
  349. package/templates/architecture/extractable.declared.spec.ts.tpl +22 -17
  350. package/templates/architecture/extractable.manual.spec.ts.tpl +14 -9
  351. package/templates/architecture/extractable.tsyringe.spec.ts.tpl +19 -14
  352. package/templates/context/module.manual.ts.tpl +11 -0
  353. package/templates/init/jest.config.js.tpl +6 -0
  354. package/templates/init/platform/composition/compose-application.manual.ts.tpl +50 -0
  355. package/templates/init/platform/composition/platform.module.tsyringe.ts.tpl +9 -3
  356. package/templates/init/platform/database/persistence-over.drizzle.ts.tpl +1 -1
  357. package/templates/init/platform/database/persistence-over.knex.ts.tpl +1 -1
  358. package/templates/init/platform/database/persistence-over.prisma.ts.tpl +30 -1
  359. package/templates/init/platform/database/persistence-over.typeorm.ts.tpl +23 -1
  360. package/templates/init/platform/database/persistence.contract.spec.ts.tpl +113 -0
  361. package/templates/init/platform/database/persistence.orm.ts.tpl +8 -3
  362. package/templates/init/platform/database/schema.prisma.tpl +53 -0
  363. package/templates/init/platform/database/schema.typeorm.ts.tpl +17 -3
  364. package/templates/init/platform/database/table-statements.drizzle.ts.tpl +36 -0
  365. package/templates/init/platform/files/bind-files.tsyringe.ts.tpl +1 -1
  366. package/templates/init/platform/files/create-files.ts.tpl +1 -1
  367. package/templates/init/platform/http/create-app-module.ts.tpl +20 -0
  368. package/templates/init/platform/http/start-http-server.express.ts.tpl +48 -1
  369. package/templates/init/platform/http/start-http-server.fastify.ts.tpl +50 -2
  370. package/templates/init/platform/http/start-http-server.hono.ts.tpl +60 -1
  371. package/templates/init/platform/http/start-http-server.nest.ts.tpl +61 -3
  372. package/templates/init/platform/jobs/create-background-work.ts.tpl +2 -2
  373. package/templates/init/rules/infrastructure.md.tpl +3 -0
  374. package/templates/init/rules/presentation.md.tpl +7 -0
  375. package/templates/nest-controller/controller.spec.ts.tpl +57 -0
  376. package/templates/nest-controller/controller.ts.tpl +65 -0
  377. package/templates/pipeline/knip.json.tpl +4 -8
  378. package/templates/pipeline/package-scripts.json +1 -1
  379. package/templates/presets/identity/context/__context__.module.explicit.ts.tpl +254 -0
  380. package/templates/presets/identity/context/application/authorization/change-member-roles.policy.ts.tpl +10 -0
  381. package/templates/presets/identity/context/application/authorization/grant-delegations.policy.ts.tpl +10 -0
  382. package/templates/presets/identity/context/application/authorization/invite-members.policy.ts.tpl +10 -0
  383. package/templates/presets/identity/context/application/authorization/read-members.policy.ts.tpl +10 -0
  384. package/templates/presets/identity/context/application/authorization/remove-members.policy.ts.tpl +10 -0
  385. package/templates/presets/identity/context/application/authorization/revoke-delegations.policy.ts.tpl +10 -0
  386. package/templates/presets/identity/context/application/authorization/revoke-invitations.policy.ts.tpl +10 -0
  387. package/templates/presets/identity/context/application/commands/accept-invitation/accept-invitation.command.ts.tpl +6 -0
  388. package/templates/presets/identity/context/application/commands/accept-invitation/accept-invitation.handler.ts.tpl +12 -0
  389. package/templates/presets/identity/context/application/commands/change-member-role/change-member-role.command.ts.tpl +6 -0
  390. package/templates/presets/identity/context/application/commands/change-member-role/change-member-role.handler.ts.tpl +12 -0
  391. package/templates/presets/identity/context/application/commands/deactivate-account/deactivate-account.command.ts.tpl +6 -0
  392. package/templates/presets/identity/context/application/commands/deactivate-account/deactivate-account.handler.ts.tpl +12 -0
  393. package/templates/presets/identity/context/application/commands/decline-invitation/decline-invitation.command.ts.tpl +6 -0
  394. package/templates/presets/identity/context/application/commands/decline-invitation/decline-invitation.handler.ts.tpl +12 -0
  395. package/templates/presets/identity/context/application/commands/grant-delegation/grant-delegation.command.ts.tpl +6 -0
  396. package/templates/presets/identity/context/application/commands/grant-delegation/grant-delegation.handler.ts.tpl +12 -0
  397. package/templates/presets/identity/context/application/commands/invite-member/invite-member.command.ts.tpl +6 -0
  398. package/templates/presets/identity/context/application/commands/invite-member/invite-member.handler.ts.tpl +12 -0
  399. package/templates/presets/identity/context/application/commands/open-organisation/open-organisation.command.ts.tpl +6 -0
  400. package/templates/presets/identity/context/application/commands/open-organisation/open-organisation.handler.ts.tpl +12 -0
  401. package/templates/presets/identity/context/application/commands/provision-account/provision-account.command.ts.tpl +6 -0
  402. package/templates/presets/identity/context/application/commands/provision-account/provision-account.handler.ts.tpl +12 -0
  403. package/templates/presets/identity/context/application/commands/remove-member/remove-member.command.ts.tpl +6 -0
  404. package/templates/presets/identity/context/application/commands/remove-member/remove-member.handler.ts.tpl +12 -0
  405. package/templates/presets/identity/context/application/commands/revoke-delegation/revoke-delegation.command.ts.tpl +6 -0
  406. package/templates/presets/identity/context/application/commands/revoke-delegation/revoke-delegation.handler.ts.tpl +12 -0
  407. package/templates/presets/identity/context/application/commands/revoke-invitation/revoke-invitation.command.ts.tpl +6 -0
  408. package/templates/presets/identity/context/application/commands/revoke-invitation/revoke-invitation.handler.ts.tpl +12 -0
  409. package/templates/presets/identity/context/application/integration/handlers/account-deactivated.integration-handler.ts.tpl +4 -0
  410. package/templates/presets/identity/context/application/integration/handlers/member-joined.integration-handler.ts.tpl +4 -0
  411. package/templates/presets/identity/context/application/integration/handlers/member-removed.integration-handler.ts.tpl +4 -0
  412. package/templates/presets/identity/context/application/integration/handlers/organisation-opened.integration-handler.ts.tpl +4 -0
  413. package/templates/presets/identity/context/application/integration/publishers/account-deactivated.publisher.ts.tpl +10 -1
  414. package/templates/presets/identity/context/application/integration/publishers/delegation-granted.publisher.ts.tpl +10 -1
  415. package/templates/presets/identity/context/application/integration/publishers/delegation-revoked.publisher.ts.tpl +10 -1
  416. package/templates/presets/identity/context/application/integration/publishers/member-joined.publisher.ts.tpl +10 -1
  417. package/templates/presets/identity/context/application/integration/publishers/member-removed.publisher.ts.tpl +10 -1
  418. package/templates/presets/identity/context/application/integration/publishers/member-role-changed.publisher.ts.tpl +10 -1
  419. package/templates/presets/identity/context/application/integration/publishers/organisation-opened.publisher.ts.tpl +10 -1
  420. package/templates/presets/identity/context/application/queries/search-members/search-members.handler.ts.tpl +12 -0
  421. package/templates/presets/identity/context/application/queries/search-members/search-members.query.ts.tpl +6 -0
  422. package/templates/presets/identity/context/infrastructure/external/crypto-invitation-tokens.adapter.ts.tpl +9 -0
  423. package/templates/presets/identity/context/infrastructure/external/environment-identity-provider-connection.adapter.ts.tpl +9 -0
  424. package/templates/presets/identity/context/infrastructure/external/keycloak-identity-provider-admin.adapter.ts.tpl +9 -0
  425. package/templates/presets/identity/context/infrastructure/persistence/account.mapper.prisma.ts.tpl +36 -0
  426. package/templates/presets/identity/context/infrastructure/persistence/account.personal-fields.privacy.prisma.ts.tpl +19 -0
  427. package/templates/presets/identity/context/infrastructure/persistence/delegation.mapper.prisma.ts.tpl +48 -0
  428. package/templates/presets/identity/context/infrastructure/persistence/drizzle-account.repository.drizzle.ts.tpl +9 -0
  429. package/templates/presets/identity/context/infrastructure/persistence/drizzle-delegation.repository.drizzle.ts.tpl +9 -0
  430. package/templates/presets/identity/context/infrastructure/persistence/drizzle-invitation.repository.drizzle.ts.tpl +9 -0
  431. package/templates/presets/identity/context/infrastructure/persistence/drizzle-member.repository.drizzle.ts.tpl +9 -0
  432. package/templates/presets/identity/context/infrastructure/persistence/drizzle-organisation.repository.drizzle.ts.tpl +9 -0
  433. package/templates/presets/identity/context/infrastructure/persistence/drizzle-search-members-reader.repository.drizzle.ts.tpl +9 -0
  434. package/templates/presets/identity/context/infrastructure/persistence/invitation.mapper.prisma.ts.tpl +43 -0
  435. package/templates/presets/identity/context/infrastructure/persistence/invitation.personal-fields.privacy.prisma.ts.tpl +20 -0
  436. package/templates/presets/identity/context/infrastructure/persistence/knex-account.repository.knex.ts.tpl +9 -0
  437. package/templates/presets/identity/context/infrastructure/persistence/knex-delegation.repository.knex.ts.tpl +9 -0
  438. package/templates/presets/identity/context/infrastructure/persistence/knex-invitation.repository.knex.ts.tpl +9 -0
  439. package/templates/presets/identity/context/infrastructure/persistence/knex-member.repository.knex.ts.tpl +9 -0
  440. package/templates/presets/identity/context/infrastructure/persistence/knex-organisation.repository.knex.ts.tpl +9 -0
  441. package/templates/presets/identity/context/infrastructure/persistence/knex-search-members-reader.repository.knex.ts.tpl +9 -0
  442. package/templates/presets/identity/context/infrastructure/persistence/member.mapper.prisma.ts.tpl +34 -0
  443. package/templates/presets/identity/context/infrastructure/persistence/organisation.mapper.prisma.ts.tpl +26 -0
  444. package/templates/presets/identity/context/infrastructure/persistence/prisma-account.repository.prisma.ts.tpl +63 -0
  445. package/templates/presets/identity/context/infrastructure/persistence/prisma-delegation.repository.prisma.ts.tpl +81 -0
  446. package/templates/presets/identity/context/infrastructure/persistence/prisma-invitation.repository.prisma.ts.tpl +69 -0
  447. package/templates/presets/identity/context/infrastructure/persistence/prisma-member.repository.prisma.ts.tpl +80 -0
  448. package/templates/presets/identity/context/infrastructure/persistence/prisma-organisation.repository.prisma.ts.tpl +63 -0
  449. package/templates/presets/identity/context/infrastructure/persistence/prisma-search-members-reader.repository.prisma.ts.tpl +82 -0
  450. package/templates/presets/identity/context/test/integration/account.repository.contract.spec.ts.tpl +3 -3
  451. package/templates/presets/identity/context/test/integration/delegation.repository.contract.spec.ts.tpl +5 -5
  452. package/templates/presets/identity/context/test/integration/invitation.repository.contract.spec.ts.tpl +5 -5
  453. package/templates/presets/identity/context/test/integration/member.repository.contract.spec.ts.tpl +5 -5
  454. package/templates/presets/identity/context/test/integration/organisation.repository.contract.spec.ts.tpl +3 -3
  455. package/templates/presets/identity/context/test/integration/search-members-reader.spec.ts.tpl +8 -8
  456. package/templates/presets/identity/context/test/unit/__context__.module.spec.explicit.ts.tpl +95 -0
  457. package/templates/presets/identity/context/test/worlds/__context__.world.explicit.ts.tpl +332 -0
  458. package/templates/presets/identity/explicit/access-policies.wiring.tpl +16 -0
  459. package/templates/presets/identity/prisma/models.prisma.tpl +128 -0
  460. package/templates/property/value-object.properties.spec.ts.tpl +38 -0
  461. package/templates/sdk/orpc.ts.tpl +46 -0
  462. package/templates/sdk/trpc.ts.tpl +86 -0
  463. /package/templates/presets/identity/context/test/worlds/{__context__.world.ts.tpl → __context__.world.declared.ts.tpl} +0 -0
@@ -11,6 +11,12 @@ import { subscribeAll } from '@ddd-ts-kit/events';
11
11
  {{#if http.any}}
12
12
  import { createErrorMapper, defineRoutes, type Route } from '@ddd-ts-kit/http';
13
13
  {{/if}}
14
+ {{#if routes.nest}}
15
+ import type { Type } from '@nestjs/common';
16
+ import { type NestControllers, nestControllers } from '@ddd-ts-kit/http/nest';
17
+ import { CommandBus, QueryBus } from '@ddd-ts-kit/kernel';
18
+ import { classSchema } from '@ddd-ts-kit/validation/class-validator';
19
+ {{/if}}
14
20
  {{#if audit.archive}}
15
21
  import { ArchiveAuditEntries } from '@ddd-ts-kit/audit';
16
22
  {{/if}}
@@ -58,6 +64,10 @@ interface ContextWiring {
58
64
  {{#if http.any}}
59
65
  readonly routes: readonly Route[];
60
66
  {{/if}}
67
+ {{#if routes.nest}}
68
+ /** Its Nest controllers, which Nest builds and the kit serves. */
69
+ readonly controllers?: readonly Type<unknown>[];
70
+ {{/if}}
61
71
  }
62
72
 
63
73
  {{#if http.any}}
@@ -84,6 +94,10 @@ export interface Application {
84
94
  /** Authenticates every request and runs it inside the execution scope. */
85
95
  readonly boundary: HttpBoundary;
86
96
  {{/if}}
97
+ {{#if routes.nest}}
98
+ /** The Nest controllers of the contexts: their routes are among `routes`, Nest builds them with the buses they inject. */
99
+ readonly controllers: NestControllers;
100
+ {{/if}}
87
101
  {{#if files.http}}
88
102
  /** The routes that answer the signed links of a storage the application serves itself; mounted before any body parser. */
89
103
  readonly fileRoutes: readonly Route[];
@@ -136,6 +150,9 @@ export function composeApplication(
136
150
  {{/unless}}
137
151
 
138
152
  platform.protection.declare(contexts.flatMap((context) => context.useCases));
153
+ {{#if routes.nest}}
154
+ const controllers = controllersOf(contexts, platform);
155
+ {{/if}}
139
156
  {{#if presentation.any}}
140
157
  // What the server answers in and which fields each caller sees: the forms and the contract are given the same.
141
158
  const presentation = presentationOf(platform.access, clock);
@@ -144,11 +161,24 @@ export function composeApplication(
144
161
  return {
145
162
  {{#if http.any}}
146
163
  {{#if presentation.forms}}
164
+ {{#if routes.nest}}
165
+ routes: withForms(defineRoutes(...contexts.map((context) => context.routes), controllers.routes), presentation),
166
+ {{/if}}
167
+ {{#unless routes.nest}}
147
168
  routes: withForms(defineRoutes(...contexts.map((context) => context.routes)), presentation),
169
+ {{/unless}}
148
170
  {{/if}}
149
171
  {{#unless presentation.forms}}
172
+ {{#if routes.nest}}
173
+ routes: defineRoutes(...contexts.map((context) => context.routes), controllers.routes),
174
+ {{/if}}
175
+ {{#unless routes.nest}}
150
176
  routes: defineRoutes(...contexts.map((context) => context.routes)),
151
177
  {{/unless}}
178
+ {{/unless}}
179
+ {{#if routes.nest}}
180
+ controllers,
181
+ {{/if}}
152
182
  boundary: httpBoundary({
153
183
  authenticator: options.authenticator,
154
184
  executionScope: platform.scope,
@@ -290,3 +320,23 @@ function purgeExpiredEveryNight(platform: Platform): void {
290
320
  });
291
321
  }
292
322
  {{/if}}
323
+ {{#if routes.nest}}
324
+
325
+ /** The Nest controllers of the contexts: their routes now, their instances built by Nest when the server starts, with the buses of the platform. */
326
+ function controllersOf(contexts: readonly ContextWiring[], platform: Platform): NestControllers {
327
+ return nestControllers(
328
+ contexts.flatMap((context) => context.controllers ?? []),
329
+ {
330
+ providers: [
331
+ { provide: CommandBus, useValue: platform.commands },
332
+ { provide: QueryBus, useValue: platform.queries },
333
+ ],
334
+ // A DTO without a decorated field yet accepts the empty object alone: whitelist and forbidNonWhitelisted refuse any field.
335
+ schemaOfClass: (dto) => classSchema(dto, { validator: { forbidUnknownValues: false } }),
336
+ {{#if authn.none}}
337
+ security: ['developmentActor'],
338
+ {{/if}}
339
+ },
340
+ );
341
+ }
342
+ {{/if}}
@@ -18,6 +18,9 @@ import { ErrorMapper, createErrorMapper } from '@ddd-ts-kit/http';
18
18
  import {
19
19
  Cache,
20
20
  EventSubscribers,
21
+ {{#if queue.processTable}}
22
+ ExecutionScope,
23
+ {{/if}}
21
24
  Lock,
22
25
  Metrics,
23
26
  ProcessedEventStore,
@@ -35,6 +38,9 @@ import {
35
38
  {{#if errors.sentry}}
36
39
  import {
37
40
  Cache,
41
+ {{#if queue.processTable}}
42
+ ExecutionScope,
43
+ {{/if}}
38
44
  Lock,
39
45
  Metrics,
40
46
  ProcessedEventStore,
@@ -47,7 +53,7 @@ import {
47
53
  } from '@ddd-ts-kit/kernel';
48
54
  {{/if}}
49
55
  {{#unless errors.sentry}}
50
- import { Cache, Lock, Metrics, ProcessedEventStore, {{#if queue.processTable}}ProcessStore, {{/if}}RateLimiter, UnitOfWork } from '@ddd-ts-kit/kernel';
56
+ import { Cache, {{#if queue.processTable}}ExecutionScope, {{/if}}Lock, Metrics, ProcessedEventStore, {{#if queue.processTable}}ProcessStore, {{/if}}RateLimiter, UnitOfWork } from '@ddd-ts-kit/kernel';
51
57
  {{/unless}}
52
58
  {{/unless}}
53
59
  {{/if}}
@@ -56,7 +62,7 @@ import { {{#if broker.external}}EventSubscribers, {{/if}}ProcessedEventStore, Un
56
62
  {{/unless}}
57
63
  {{#unless cache.redis}}
58
64
  {{#if queue.processTable}}
59
- import { ProcessStore } from '@ddd-ts-kit/kernel';
65
+ import { ExecutionScope, ProcessStore } from '@ddd-ts-kit/kernel';
60
66
  {{/if}}
61
67
  {{/unless}}
62
68
  {{#if queue.redis}}
@@ -141,7 +147,7 @@ export function platformModule(persistence: Persistence, options: PlatformOption
141
147
  builder.rebind(JobStore).toValue(persistence.jobs);
142
148
  {{/if}}
143
149
  {{#if queue.processTable}}
144
- builder.rebind(ProcessStore).toValue(persistence.processes);
150
+ builder.rebind(ProcessStore).toFactory((resolve) => persistence.processes(resolve(ExecutionScope)));
145
151
  {{/if}}
146
152
  {{#if broker.external}}
147
153
  builder.rebind(EventSubscribers).toValue({ forContext: (name) => options.events.forConsumer(name) });
@@ -42,7 +42,7 @@ export function persistenceOver(connection: DatabaseConnection): Persistence {
42
42
  jobs: new DrizzleJobStore(unitOfWork, jobs),
43
43
  {{/if}}
44
44
  {{#if queue.processTable}}
45
- processes: new DrizzleProcessStore(unitOfWork, processes),
45
+ processes: ({{#if tenancy.any}}tenant{{/if}}) => new DrizzleProcessStore(unitOfWork, { table: processes{{#if tenancy.any}}, tenant{{/if}} }),
46
46
  {{/if}}
47
47
  {{#if eventSourcing.on}}
48
48
  eventSourcing: createDrizzleEventSourcing(unitOfWork, { schema: EVENT_STORE_SCHEMA }),
@@ -48,7 +48,7 @@ export function persistenceOver(connection: DatabaseConnection): Persistence {
48
48
  jobs: new KnexJobStore(unitOfWork, { schema: MESSAGING_SCHEMA }),
49
49
  {{/if}}
50
50
  {{#if queue.processTable}}
51
- processes: new KnexProcessStore(unitOfWork, { schema: MESSAGING_SCHEMA }),
51
+ processes: ({{#if tenancy.any}}tenant{{/if}}) => new KnexProcessStore(unitOfWork, { schema: MESSAGING_SCHEMA{{#if tenancy.any}}, tenant{{/if}} }),
52
52
  {{/if}}
53
53
  {{#if eventSourcing.on}}
54
54
  eventSourcing: createKnexEventSourcing(unitOfWork, { schema: EVENT_STORE_SCHEMA }),
@@ -1,3 +1,18 @@
1
+ {{#if queue.processTable}}
2
+ import {
3
+ {{#if eventSourcing.on}}
4
+ createPrismaEventSourcing,
5
+ {{/if}}
6
+ createPrismaUnitOfWork,
7
+ {{#if queue.database}}
8
+ PrismaJobStore,
9
+ {{/if}}
10
+ PrismaOutboxStore,
11
+ PrismaProcessedEventStore,
12
+ PrismaProcessStore,
13
+ } from '@ddd-ts-kit/prisma';
14
+ {{/if}}
15
+ {{#unless queue.processTable}}
1
16
  {{#if eventSourcing.on}}
2
17
  import {
3
18
  createPrismaEventSourcing,
@@ -9,10 +24,11 @@ import {
9
24
  {{#unless eventSourcing.on}}
10
25
  import { createPrismaUnitOfWork, PrismaOutboxStore, PrismaProcessedEventStore } from '@ddd-ts-kit/prisma';
11
26
  {{/unless}}
27
+ {{/unless}}
12
28
  import type { PrismaClient } from '{{alias.generated}}/prisma/client{{alias.ext}}';
13
29
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
14
30
 
15
- /** The schema of the outbox and the processed events, as prisma/schema.prisma names it. */
31
+ /** The schema of the messaging tables{{#if queue.processTable}} and of the background work{{/if}}, as prisma/schema.prisma names it. */
16
32
  const MESSAGING_SCHEMA = 'messaging';
17
33
  {{#if eventSourcing.on}}
18
34
  /** The schema of the event store, as prisma/schema.prisma names it. */
@@ -36,6 +52,19 @@ export function persistenceOver(client: PrismaClient): Persistence {
36
52
  {{/if}}
37
53
  }),
38
54
  processedEvents: new PrismaProcessedEventStore(unitOfWork, { delegate: (current) => current.processedEvent }),
55
+ {{#if queue.database}}
56
+ // The claim of the jobs is a raw statement: it names the schema of the table.
57
+ jobs: new PrismaJobStore(unitOfWork, { delegate: (current) => current.backgroundJob, schema: MESSAGING_SCHEMA }),
58
+ {{/if}}
59
+ {{#if queue.processTable}}
60
+ {{#if tenancy.any}}
61
+ processes: (tenant) =>
62
+ new PrismaProcessStore(unitOfWork, { delegate: (current) => current.processInstance, tenant }),
63
+ {{/if}}
64
+ {{#unless tenancy.any}}
65
+ processes: () => new PrismaProcessStore(unitOfWork, { delegate: (current) => current.processInstance }),
66
+ {{/unless}}
67
+ {{/if}}
39
68
  {{#if eventSourcing.on}}
40
69
  eventSourcing: createPrismaEventSourcing(unitOfWork, { schema: EVENT_STORE_SCHEMA }),
41
70
  {{/if}}
@@ -1,4 +1,19 @@
1
1
  import type { DataSource } from 'typeorm';
2
+ {{#if queue.processTable}}
3
+ import {
4
+ {{#if eventSourcing.on}}
5
+ createTypeOrmEventSourcing,
6
+ {{/if}}
7
+ createTypeOrmUnitOfWork,
8
+ {{#if queue.database}}
9
+ TypeOrmJobStore,
10
+ {{/if}}
11
+ TypeOrmOutboxStore,
12
+ TypeOrmProcessedEventStore,
13
+ TypeOrmProcessStore,
14
+ } from '@ddd-ts-kit/typeorm';
15
+ {{/if}}
16
+ {{#unless queue.processTable}}
2
17
  {{#if eventSourcing.on}}
3
18
  import {
4
19
  createTypeOrmEventSourcing,
@@ -10,8 +25,9 @@ import {
10
25
  {{#unless eventSourcing.on}}
11
26
  import { createTypeOrmUnitOfWork, TypeOrmOutboxStore, TypeOrmProcessedEventStore } from '@ddd-ts-kit/typeorm';
12
27
  {{/unless}}
28
+ {{/unless}}
13
29
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
14
- import { {{#if eventSourcing.on}}EVENT_STORE_SCHEMA, {{/if}}outbox, processedEvents } from '{{alias.platform}}/database/schema{{alias.ext}}';
30
+ import { {{#if eventSourcing.on}}EVENT_STORE_SCHEMA, {{/if}}{{#if queue.database}}jobs, {{/if}}outbox, processedEvents{{#if queue.processTable}}, processes{{/if}} } from '{{alias.platform}}/database/schema{{alias.ext}}';
15
31
 
16
32
  /** One object is the unit of work and what repositories query through; the stores write through its manager. */
17
33
  export function persistenceOver(dataSource: DataSource): Persistence {
@@ -22,6 +38,12 @@ export function persistenceOver(dataSource: DataSource): Persistence {
22
38
  database: unitOfWork,
23
39
  outbox: new TypeOrmOutboxStore(unitOfWork, { entity: outbox }),
24
40
  processedEvents: new TypeOrmProcessedEventStore(unitOfWork, { entity: processedEvents }),
41
+ {{#if queue.database}}
42
+ jobs: new TypeOrmJobStore(unitOfWork, { entity: jobs }),
43
+ {{/if}}
44
+ {{#if queue.processTable}}
45
+ processes: ({{#if tenancy.any}}tenant{{/if}}) => new TypeOrmProcessStore(unitOfWork, { entity: processes{{#if tenancy.any}}, tenant{{/if}} }),
46
+ {{/if}}
25
47
  {{#if eventSourcing.on}}
26
48
  eventSourcing: createTypeOrmEventSourcing(unitOfWork, { schema: EVENT_STORE_SCHEMA }),
27
49
  {{/if}}
@@ -0,0 +1,113 @@
1
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '{{tests.module}}';
2
+ {{#if queue.processTable}}
3
+ import { FixedExecutionScope, executionContext, systemActor } from '@ddd-ts-kit/kernel';
4
+ {{/if}}
5
+ {{#if queue.database}}
6
+ import {
7
+ {{#if eventSourcing.on}}
8
+ eventStoreContract,
9
+ {{/if}}
10
+ jobStoreContract,
11
+ outboxStoreContract,
12
+ processedEventStoreContract,
13
+ processStoreContract,
14
+ } from '@ddd-ts-kit/testing/contracts';
15
+ {{/if}}
16
+ {{#unless queue.database}}
17
+ {{#if queue.processTable}}
18
+ {{#if eventSourcing.on}}
19
+ import {
20
+ eventStoreContract,
21
+ outboxStoreContract,
22
+ processedEventStoreContract,
23
+ processStoreContract,
24
+ } from '@ddd-ts-kit/testing/contracts';
25
+ {{/if}}
26
+ {{#unless eventSourcing.on}}
27
+ import { outboxStoreContract, processedEventStoreContract, processStoreContract } from '@ddd-ts-kit/testing/contracts';
28
+ {{/unless}}
29
+ {{/if}}
30
+ {{#unless queue.processTable}}
31
+ import { {{#if eventSourcing.on}}eventStoreContract, {{/if}}outboxStoreContract, processedEventStoreContract } from '@ddd-ts-kit/testing/contracts';
32
+ {{/unless}}
33
+ {{/unless}}
34
+ import { openTestDatabase, type TestDatabase } from '{{alias.platform}}/database/open-test-database{{alias.ext}}';
35
+ import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
36
+
37
+ // The stores of the kit as this platform wires them, held to the contracts of their ports with the
38
+ // capabilities the stack turns on: a store bound without what the stack asks for fails here.
39
+
40
+ const runner = { describe, it, expect, beforeEach, afterEach };
41
+
42
+ let database: TestDatabase;
43
+
44
+ beforeAll(async () => {
45
+ database = await openTestDatabase();
46
+ });
47
+
48
+ afterAll(async () => {
49
+ await database.close();
50
+ });
51
+
52
+ outboxStoreContract(runner, {
53
+ name: 'The outbox store of the platform',
54
+ createStore: async () => (await emptied()).outbox,
55
+ leaseMs: 30_000,
56
+ {{#if tenancy.any}}
57
+ carriesTenant: true,
58
+ {{/if}}
59
+ });
60
+
61
+ processedEventStoreContract(runner, {
62
+ name: 'The processed-event store of the platform',
63
+ createStore: async () => (await emptied()).processedEvents,
64
+ });
65
+ {{#if eventSourcing.on}}
66
+
67
+ eventStoreContract(runner, {
68
+ name: 'The event store of the platform',
69
+ createStore: async () => (await emptied()).eventSourcing.events,
70
+ createCompanions: async () => (await emptied()).eventSourcing,
71
+ });
72
+ {{/if}}
73
+ {{#if queue.database}}
74
+
75
+ jobStoreContract(runner, {
76
+ name: 'The job store of the platform',
77
+ createStore: async () => (await emptied()).jobs,
78
+ unitOfWork: () => database.persistence.unitOfWork,
79
+ });
80
+ {{/if}}
81
+ {{#if queue.processTable}}
82
+
83
+ {{#if tenancy.any}}
84
+ /** The work of a tenant of its own, beside the two of the contract. */
85
+ {{/if}}
86
+ {{#unless tenancy.any}}
87
+ /** The work of the platform. */
88
+ {{/unless}}
89
+ const work = new FixedExecutionScope(
90
+ {{#if tenancy.any}}
91
+ executionContext({ correlationId: 'contract', actor: systemActor('contract'), origin: 'test', tenantId: 'initech' }),
92
+ {{/if}}
93
+ {{#unless tenancy.any}}
94
+ executionContext({ correlationId: 'contract', actor: systemActor('contract'), origin: 'test' }),
95
+ {{/unless}}
96
+ );
97
+
98
+ processStoreContract(runner, {
99
+ name: 'The process store of the platform',
100
+ createStore: async () => (await emptied()).processes(work),
101
+ unitOfWork: () => database.persistence.unitOfWork,
102
+ {{#if tenancy.any}}
103
+ storeInTenant: (scope) => database.persistence.processes(scope),
104
+ {{/if}}
105
+ });
106
+ {{/if}}
107
+
108
+ /** The persistence of the platform, on a database emptied before each test. */
109
+ async function emptied(): Promise<Persistence> {
110
+ await database.reset();
111
+
112
+ return database.persistence;
113
+ }
@@ -1,5 +1,5 @@
1
1
  import type { OutboxStore } from '@ddd-ts-kit/events';
2
- import type { {{#if eventSourcing.on}}EventSourcingStores, {{/if}}ProcessedEventStore, {{#if queue.processTable}}ProcessStore, {{/if}}UnitOfWork } from '@ddd-ts-kit/kernel';
2
+ import type { {{#if eventSourcing.on}}EventSourcingStores, {{/if}}{{#if queue.processTable}}ExecutionScope, {{/if}}ProcessedEventStore, {{#if queue.processTable}}ProcessStore, {{/if}}UnitOfWork } from '@ddd-ts-kit/kernel';
3
3
  {{#if queue.database}}
4
4
  import type { JobStore } from '@ddd-ts-kit/scheduling';
5
5
  {{/if}}
@@ -20,8 +20,13 @@ export interface Persistence {
20
20
  readonly jobs: JobStore;
21
21
  {{/if}}
22
22
  {{#if queue.processTable}}
23
- /** The instances of the process managers, saved in the transaction of each step. */
24
- readonly processes: ProcessStore;
23
+ {{#if tenancy.any}}
24
+ /** The instances of the process managers, saved in the transaction of each step, each in the tenant of the work `scope` runs. */
25
+ {{/if}}
26
+ {{#unless tenancy.any}}
27
+ /** The instances of the process managers, saved in the transaction of each step; `scope` serves a multi-tenant project. */
28
+ {{/unless}}
29
+ readonly processes: (scope: ExecutionScope) => ProcessStore;
25
30
  {{/if}}
26
31
  /** What repositories query through: the transaction of the current unit of work, or the database. */
27
32
  readonly database: {{persistence.token}};
@@ -46,6 +46,59 @@ model ProcessedEvent {
46
46
  @@map("processed_events")
47
47
  @@schema("messaging")
48
48
  }
49
+ {{#if queue.database}}
50
+
51
+ // The background jobs, from @ddd-ts-kit/prisma, enqueued in the transaction of the command. Keep
52
+ // the field, table and column names: the claim selects the due rows by name.
53
+ model BackgroundJob {
54
+ id String @id
55
+ /// Insertion order, the tie-breaker of the claim.
56
+ sequence BigInt @unique @default(autoincrement())
57
+ name String
58
+ queue String
59
+ payload Json?
60
+ enqueuedBy Json @map("enqueued_by")
61
+ idempotencyKey String? @map("idempotency_key")
62
+ /// The empty text outside any tenant: a null would make every such key distinct.
63
+ tenantId String @default("") @map("tenant_id")
64
+ subject String?
65
+ status String @default("waiting")
66
+ attempts Int @default(0)
67
+ runAt DateTime @map("run_at") @db.Timestamptz(3)
68
+ leaseUntil DateTime? @map("lease_until") @db.Timestamptz(3)
69
+ progress Json?
70
+ /// JSON as text: a worker may clear it.
71
+ checkpoint String?
72
+ lastErrorCode String? @map("last_error_code")
73
+ enqueuedAt DateTime @map("enqueued_at") @db.Timestamptz(3)
74
+ finishedAt DateTime? @map("finished_at") @db.Timestamptz(3)
75
+
76
+ @@unique([name, tenantId, idempotencyKey], map: "background_jobs_idempotency_key")
77
+ @@index([queue, runAt, sequence], map: "background_jobs_due_idx")
78
+ @@map("background_jobs")
79
+ @@schema("messaging")
80
+ }
81
+ {{/if}}
82
+ {{#if queue.processTable}}
83
+
84
+ // The instances of the process managers, from @ddd-ts-kit/prisma, saved in the transaction of each step.
85
+ model ProcessInstance {
86
+ /// The empty text outside any tenant: two tenants may use the same correlation key.
87
+ tenantId String @default("") @map("tenant_id")
88
+ name String
89
+ id String
90
+ /// JSON as text: a state may be null.
91
+ state String
92
+ version Int
93
+ ended Boolean @default(false)
94
+ timeouts Json
95
+ updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz(3)
96
+
97
+ @@id([tenantId, name, id])
98
+ @@map("process_instances")
99
+ @@schema("messaging")
100
+ }
101
+ {{/if}}
49
102
 
50
103
  // One schema per bounded context, no relation across contexts.
51
104
  // ddd-ts-kit:models
@@ -2,11 +2,11 @@
2
2
  import { auditEntities } from '@ddd-ts-kit/audit/typeorm';
3
3
  {{/if}}
4
4
  import type { EntitySchema } from 'typeorm';
5
- import { {{#if eventSourcing.on}}eventStoreEntities, {{/if}}outboxEntity, processedEventEntity } from '@ddd-ts-kit/typeorm';
5
+ import { {{#if eventSourcing.on}}eventStoreEntities, {{/if}}{{#if queue.database}}jobEntity, {{/if}}outboxEntity, processedEventEntity{{#if queue.processTable}}, processEntity{{/if}} } from '@ddd-ts-kit/typeorm';
6
6
  // ddd-ts-kit:imports
7
7
  // /ddd-ts-kit:imports
8
8
 
9
- /** The schema of what the kit stores for the application: the outbox and the processed events. */
9
+ /** The schema of what the kit stores for the application: the outbox and the processed events{{#if queue.processTable}}, the background work{{/if}}. */
10
10
  export const MESSAGING_SCHEMA = 'messaging';
11
11
 
12
12
  {{#if tenancy.any}}
@@ -17,6 +17,14 @@ export const outbox = outboxEntity({ schema: MESSAGING_SCHEMA, tenant: true });
17
17
  export const outbox = outboxEntity({ schema: MESSAGING_SCHEMA });
18
18
  {{/unless}}
19
19
  export const processedEvents = processedEventEntity({ schema: MESSAGING_SCHEMA });
20
+ {{#if queue.database}}
21
+ /** The background jobs, enqueued in the transaction of the command that asks for them. */
22
+ export const jobs = jobEntity({ schema: MESSAGING_SCHEMA });
23
+ {{/if}}
24
+ {{#if queue.processTable}}
25
+ /** The instances of the process managers, saved in the transaction of each step. */
26
+ export const processes = processEntity({ schema: MESSAGING_SCHEMA });
27
+ {{/if}}
20
28
 
21
29
  {{#if eventSourcing.on}}
22
30
  /** The schema of the event store: the events, the snapshots, the checkpoints and the keys of the data subjects. It records no tenant. */
@@ -30,7 +38,7 @@ export const eventStore = eventStoreEntities({ schema: EVENT_STORE_SCHEMA });
30
38
  /** The schema of the audit trail. */
31
39
  export const AUDIT_SCHEMA = 'audit';
32
40
 
33
- // TODO(platform): TypeORM generates no trigger. After the first `npm run db:generate migrations/<name>`, add a migration of your own that runs the statements `npm run db:audit-guard` prints: they make the entries refuse UPDATE, DELETE and TRUNCATE.
41
+ // TODO(platform): TypeORM writes no trigger. After the first `npm run db:generate migrations/<name>`, add a migration of your own that runs the statements `npm run db:audit-guard` prints: they make the entries refuse UPDATE, DELETE and TRUNCATE.
34
42
  export const auditTrail = auditEntities({ schema: AUDIT_SCHEMA });
35
43
 
36
44
  {{/if}}
@@ -38,6 +46,12 @@ export const auditTrail = auditEntities({ schema: AUDIT_SCHEMA });
38
46
  export const entities: readonly EntitySchema[] = [
39
47
  outbox,
40
48
  processedEvents,
49
+ {{#if queue.database}}
50
+ jobs,
51
+ {{/if}}
52
+ {{#if queue.processTable}}
53
+ processes,
54
+ {{/if}}
41
55
  {{#if eventSourcing.on}}
42
56
  ...eventStore,
43
57
  {{/if}}
@@ -58,9 +58,44 @@ function createStatements(table: PgTable): string[] {
58
58
  return [
59
59
  ...(owner === undefined ? [] : ['create schema if not exists ' + quote(owner)]),
60
60
  'create table if not exists ' + qualifiedName(table) + ' (' + body + ')',
61
+ ...uniqueIndexStatements(table),
61
62
  ];
62
63
  }
63
64
 
65
+ /** The unique indexes and constraints, which change what a statement does (an insert `on conflict`); the other indexes only change its speed. */
66
+ function uniqueIndexStatements(table: PgTable): string[] {
67
+ const { indexes, uniqueConstraints } = getTableConfig(table);
68
+
69
+ const unique = indexes
70
+ .filter((index) => index.config.unique)
71
+ .map(({ config: { name, columns, where } }) => {
72
+ const on = columns.map((column) => (is(column, SQL) ? inline(column) : quote(nameOf(column)))).join(', ');
73
+
74
+ return uniqueIndex(name ?? '', table, on) + (where === undefined ? '' : ' where ' + inline(where));
75
+ });
76
+
77
+ const constraints = uniqueConstraints.map((constraint) =>
78
+ uniqueIndex(constraint.getName() ?? '', table, constraint.columns.map((column) => quote(column.name)).join(', ')),
79
+ );
80
+
81
+ return [...unique, ...constraints];
82
+ }
83
+
84
+ function uniqueIndex(name: string, table: PgTable, on: string): string {
85
+ return 'create unique index if not exists ' + quote(name) + ' on ' + qualifiedName(table) + ' (' + on + ')';
86
+ }
87
+
88
+ function inline(fragment: SQL): string {
89
+ return dialect.sqlToQuery(fragment).sql;
90
+ }
91
+
92
+ /** The name of an indexed column, which drizzle types loosely. */
93
+ function nameOf(column: object): string {
94
+ const name: unknown = Reflect.get(column, 'name');
95
+
96
+ return typeof name === 'string' ? name : '';
97
+ }
98
+
64
99
  function columnDefinition(column: Column): string {
65
100
  const identity = column.generatedIdentity === undefined ? '' : ' generated always as identity';
66
101
 
@@ -69,6 +104,7 @@ function columnDefinition(column: Column): string {
69
104
  column.notNull ? ' not null' : '',
70
105
  defaultClause(column),
71
106
  column.primary ? ' primary key' : '',
107
+ column.isUnique ? ' unique' : '',
72
108
  ].join('');
73
109
  }
74
110
 
@@ -19,7 +19,7 @@ import {
19
19
  */
20
20
  export function bindFiles(builder: ModuleBuilder, storage: FileStorage): void {
21
21
  builder.bind(FileStorage).toValue(storage);
22
- // TODO(platform): bind a scanner of your own (an antivirus, a content check) before accepting files from people you do not know.
22
+ // TODO(platform): plug in a scanner of your own (an antivirus, a content check) before accepting files from people you do not know.
23
23
  builder.bind(FileScanner).toValue(new AcceptEveryFileScanner());
24
24
 
25
25
  builder
@@ -27,7 +27,7 @@ interface Grounds {
27
27
 
28
28
  /** Files as a capability of the platform: the keys generated on the server, under the tenant when there is one, and the staging. */
29
29
  export function createFiles(storage: FileStorage, { clock, ids, scope, errors }: Grounds): Files {
30
- // TODO(platform): give a scanner of your own (an antivirus, a content check) before accepting files from people you do not know.
30
+ // TODO(platform): plug in a scanner of your own (an antivirus, a content check) before accepting files from people you do not know.
31
31
  const staging = new FileStaging(storage, new AcceptEveryFileScanner(), errors);
32
32
 
33
33
  return { storage, keys: new TenantFileKeys(ids, clock, scope), staging };
@@ -1,12 +1,32 @@
1
1
  import { Module, type DynamicModule } from '@nestjs/common';
2
2
  import type { Route } from '@ddd-ts-kit/http';
3
+ {{#if routes.nest}}
4
+ import { createRoutesModule, type NestControllers, provideControllers } from '@ddd-ts-kit/http/nest';
5
+ {{/if}}
6
+ {{#unless routes.nest}}
3
7
  import { createRoutesModule } from '@ddd-ts-kit/http/nest';
8
+ {{/unless}}
4
9
  import type { HttpBoundary } from '{{alias.platform}}/auth/authentication/http-boundary{{alias.ext}}';
5
10
 
6
11
  @Module({})
7
12
  class AppModule {}
8
13
 
14
+ {{#if routes.nest}}
15
+ /**
16
+ * The Nest application: the routes mounted on its HTTP server by the `RoutesMounter` of their
17
+ * module, and the Nest controllers of the contexts built by its container with what they inject.
18
+ */
19
+ export function createAppModule(
20
+ routes: readonly Route[],
21
+ boundary: HttpBoundary,
22
+ controllers: NestControllers,
23
+ ): DynamicModule {
24
+ return { module: AppModule, imports: [createRoutesModule(routes, boundary), provideControllers(controllers)] };
25
+ }
26
+ {{/if}}
27
+ {{#unless routes.nest}}
9
28
  /** The Nest application: the framework-free routes mounted on its HTTP server by the `RoutesMounter` of their module. */
10
29
  export function createAppModule(routes: readonly Route[], boundary: HttpBoundary): DynamicModule {
11
30
  return { module: AppModule, imports: [createRoutesModule(routes, boundary)] };
12
31
  }
32
+ {{/unless}}