ddd-ts-kit 0.90.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 (429) hide show
  1. package/CHANGELOG.md +285 -0
  2. package/README.fr.md +39 -7
  3. package/README.md +35 -6
  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/commands/check-command.d.ts.map +1 -1
  73. package/dist/check/commands/check-command.js +46 -1
  74. package/dist/check/commands/check-command.js.map +1 -1
  75. package/dist/check/commands/check-file-command.d.ts +5 -0
  76. package/dist/check/commands/check-file-command.d.ts.map +1 -1
  77. package/dist/check/commands/check-file-command.js +27 -6
  78. package/dist/check/commands/check-file-command.js.map +1 -1
  79. package/dist/check/explain/nest-docs.d.ts +3 -0
  80. package/dist/check/explain/nest-docs.d.ts.map +1 -0
  81. package/dist/check/explain/nest-docs.js +31 -0
  82. package/dist/check/explain/nest-docs.js.map +1 -0
  83. package/dist/check/explain/rule-docs.d.ts.map +1 -1
  84. package/dist/check/explain/rule-docs.js +2 -0
  85. package/dist/check/explain/rule-docs.js.map +1 -1
  86. package/dist/check/fixtures/alias-declared-fixtures.js +1 -1
  87. package/dist/check/fixtures/alias-declared-fixtures.js.map +1 -1
  88. package/dist/check/fixtures/authz-declared-fixtures.js +1 -1
  89. package/dist/check/fixtures/authz-declared-fixtures.js.map +1 -1
  90. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  91. package/dist/check/fixtures/fixtures.js +4 -0
  92. package/dist/check/fixtures/fixtures.js.map +1 -1
  93. package/dist/check/fixtures/nest-controllers-fixtures.d.ts +3 -0
  94. package/dist/check/fixtures/nest-controllers-fixtures.d.ts.map +1 -0
  95. package/dist/check/fixtures/nest-controllers-fixtures.js +86 -0
  96. package/dist/check/fixtures/nest-controllers-fixtures.js.map +1 -0
  97. package/dist/check/fixtures/nest-fixtures.d.ts +3 -0
  98. package/dist/check/fixtures/nest-fixtures.d.ts.map +1 -0
  99. package/dist/check/fixtures/nest-fixtures.js +59 -0
  100. package/dist/check/fixtures/nest-fixtures.js.map +1 -0
  101. package/dist/check/nest/nest-equivalents-of.d.ts +14 -0
  102. package/dist/check/nest/nest-equivalents-of.d.ts.map +1 -0
  103. package/dist/check/nest/nest-equivalents-of.js +119 -0
  104. package/dist/check/nest/nest-equivalents-of.js.map +1 -0
  105. package/dist/check/project/load-project.d.ts +2 -0
  106. package/dist/check/project/load-project.d.ts.map +1 -1
  107. package/dist/check/project/load-project.js +7 -3
  108. package/dist/check/project/load-project.js.map +1 -1
  109. package/dist/check/rules/nest-controllers-current.d.ts +3 -0
  110. package/dist/check/rules/nest-controllers-current.d.ts.map +1 -0
  111. package/dist/check/rules/nest-controllers-current.js +43 -0
  112. package/dist/check/rules/nest-controllers-current.js.map +1 -0
  113. package/dist/check/rules/nest-no-parallel-pipeline.d.ts +3 -0
  114. package/dist/check/rules/nest-no-parallel-pipeline.d.ts.map +1 -0
  115. package/dist/check/rules/nest-no-parallel-pipeline.js +70 -0
  116. package/dist/check/rules/nest-no-parallel-pipeline.js.map +1 -0
  117. package/dist/check/support/is-generated-context-file.d.ts.map +1 -1
  118. package/dist/check/support/is-generated-context-file.js +4 -1
  119. package/dist/check/support/is-generated-context-file.js.map +1 -1
  120. package/dist/commands/init.d.ts.map +1 -1
  121. package/dist/commands/init.js +1 -0
  122. package/dist/commands/init.js.map +1 -1
  123. package/dist/config/config.d.ts +6 -0
  124. package/dist/config/config.d.ts.map +1 -1
  125. package/dist/config/index.d.ts +1 -1
  126. package/dist/config/index.d.ts.map +1 -1
  127. package/dist/config/index.js +1 -1
  128. package/dist/config/index.js.map +1 -1
  129. package/dist/config/parse-config.js +1 -0
  130. package/dist/config/parse-config.js.map +1 -1
  131. package/dist/config/parse-stack.d.ts.map +1 -1
  132. package/dist/config/parse-stack.js +2 -1
  133. package/dist/config/parse-stack.js.map +1 -1
  134. package/dist/config/serialize-config.js +9 -2
  135. package/dist/config/serialize-config.js.map +1 -1
  136. package/dist/config/stack.d.ts +17 -4
  137. package/dist/config/stack.d.ts.map +1 -1
  138. package/dist/config/stack.js +4 -1
  139. package/dist/config/stack.js.map +1 -1
  140. package/dist/dev/refresh-declarations.d.ts.map +1 -1
  141. package/dist/dev/refresh-declarations.js +4 -1
  142. package/dist/dev/refresh-declarations.js.map +1 -1
  143. package/dist/docs/write-docs.d.ts.map +1 -1
  144. package/dist/docs/write-docs.js +2 -0
  145. package/dist/docs/write-docs.js.map +1 -1
  146. package/dist/file-moves/move-files.d.ts.map +1 -1
  147. package/dist/file-moves/move-files.js +10 -0
  148. package/dist/file-moves/move-files.js.map +1 -1
  149. package/dist/generate/kinds/property-kind.d.ts +3 -0
  150. package/dist/generate/kinds/property-kind.d.ts.map +1 -0
  151. package/dist/generate/kinds/property-kind.js +51 -0
  152. package/dist/generate/kinds/property-kind.js.map +1 -0
  153. package/dist/generate/kinds/route/nest-controller-vars.d.ts +11 -0
  154. package/dist/generate/kinds/route/nest-controller-vars.d.ts.map +1 -0
  155. package/dist/generate/kinds/route/nest-controller-vars.js +97 -0
  156. package/dist/generate/kinds/route/nest-controller-vars.js.map +1 -0
  157. package/dist/generate/kinds/route/route-vars.d.ts.map +1 -1
  158. package/dist/generate/kinds/route/route-vars.js +1 -9
  159. package/dist/generate/kinds/route/route-vars.js.map +1 -1
  160. package/dist/generate/kinds/route/success-status.d.ts +5 -0
  161. package/dist/generate/kinds/route/success-status.d.ts.map +1 -0
  162. package/dist/generate/kinds/route/success-status.js +11 -0
  163. package/dist/generate/kinds/route/success-status.js.map +1 -0
  164. package/dist/generate/kinds/route/write-nest-controller.d.ts +8 -0
  165. package/dist/generate/kinds/route/write-nest-controller.d.ts.map +1 -0
  166. package/dist/generate/kinds/route/write-nest-controller.js +52 -0
  167. package/dist/generate/kinds/route/write-nest-controller.js.map +1 -0
  168. package/dist/generate/kinds/route-kind.d.ts.map +1 -1
  169. package/dist/generate/kinds/route-kind.js +6 -1
  170. package/dist/generate/kinds/route-kind.js.map +1 -1
  171. package/dist/generate/kinds.d.ts.map +1 -1
  172. package/dist/generate/kinds.js +2 -0
  173. package/dist/generate/kinds.js.map +1 -1
  174. package/dist/generate/refresh-docs.d.ts.map +1 -1
  175. package/dist/generate/refresh-docs.js +2 -0
  176. package/dist/generate/refresh-docs.js.map +1 -1
  177. package/dist/generate/shared-writes.d.ts.map +1 -1
  178. package/dist/generate/shared-writes.js +5 -0
  179. package/dist/generate/shared-writes.js.map +1 -1
  180. package/dist/help/usage.d.ts +1 -1
  181. package/dist/help/usage.d.ts.map +1 -1
  182. package/dist/help/usage.js +4 -2
  183. package/dist/help/usage.js.map +1 -1
  184. package/dist/init/agent-permissions.js +2 -0
  185. package/dist/init/agent-permissions.js.map +1 -1
  186. package/dist/init/files/audit-files.js +1 -1
  187. package/dist/init/files/audit-files.js.map +1 -1
  188. package/dist/init/files/persistence-files.d.ts.map +1 -1
  189. package/dist/init/files/persistence-files.js +2 -0
  190. package/dist/init/files/persistence-files.js.map +1 -1
  191. package/dist/init/knip-vars.d.ts.map +1 -1
  192. package/dist/init/knip-vars.js +10 -2
  193. package/dist/init/knip-vars.js.map +1 -1
  194. package/dist/init/manifest/dependencies-against-stack.d.ts +18 -0
  195. package/dist/init/manifest/dependencies-against-stack.d.ts.map +1 -0
  196. package/dist/init/manifest/dependencies-against-stack.js +95 -0
  197. package/dist/init/manifest/dependencies-against-stack.js.map +1 -0
  198. package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
  199. package/dist/init/manifest/dependencies-for.js +12 -2
  200. package/dist/init/manifest/dependencies-for.js.map +1 -1
  201. package/dist/init/manifest/scripts-for.js +5 -2
  202. package/dist/init/manifest/scripts-for.js.map +1 -1
  203. package/dist/init/manifest/versions.d.ts.map +1 -1
  204. package/dist/init/manifest/versions.js +30 -24
  205. package/dist/init/manifest/versions.js.map +1 -1
  206. package/dist/init/run-init.d.ts.map +1 -1
  207. package/dist/init/run-init.js +14 -1
  208. package/dist/init/run-init.js.map +1 -1
  209. package/dist/init/stack/resolve-queue.d.ts +4 -10
  210. package/dist/init/stack/resolve-queue.d.ts.map +1 -1
  211. package/dist/init/stack/resolve-queue.js +7 -11
  212. package/dist/init/stack/resolve-queue.js.map +1 -1
  213. package/dist/init/stack/resolve-stack.d.ts.map +1 -1
  214. package/dist/init/stack/resolve-stack.js +23 -4
  215. package/dist/init/stack/resolve-stack.js.map +1 -1
  216. package/dist/init/stack/stack-options.d.ts +2 -0
  217. package/dist/init/stack/stack-options.d.ts.map +1 -1
  218. package/dist/nest-controllers/controllers-file.d.ts +3 -0
  219. package/dist/nest-controllers/controllers-file.d.ts.map +1 -0
  220. package/dist/nest-controllers/controllers-file.js +5 -0
  221. package/dist/nest-controllers/controllers-file.js.map +1 -0
  222. package/dist/nest-controllers/nest-answer.d.ts +16 -0
  223. package/dist/nest-controllers/nest-answer.d.ts.map +1 -0
  224. package/dist/nest-controllers/nest-answer.js +2 -0
  225. package/dist/nest-controllers/nest-answer.js.map +1 -0
  226. package/dist/nest-controllers/nest-controller-entry.d.ts +16 -0
  227. package/dist/nest-controllers/nest-controller-entry.d.ts.map +1 -0
  228. package/dist/nest-controllers/nest-controller-entry.js +2 -0
  229. package/dist/nest-controllers/nest-controller-entry.js.map +1 -0
  230. package/dist/nest-controllers/read-nest-controllers.d.ts +15 -0
  231. package/dist/nest-controllers/read-nest-controllers.d.ts.map +1 -0
  232. package/dist/nest-controllers/read-nest-controllers.js +89 -0
  233. package/dist/nest-controllers/read-nest-controllers.js.map +1 -0
  234. package/dist/nest-controllers/refresh-nest-controllers.d.ts +9 -0
  235. package/dist/nest-controllers/refresh-nest-controllers.d.ts.map +1 -0
  236. package/dist/nest-controllers/refresh-nest-controllers.js +32 -0
  237. package/dist/nest-controllers/refresh-nest-controllers.js.map +1 -0
  238. package/dist/nest-controllers/render-controllers-file.d.ts +8 -0
  239. package/dist/nest-controllers/render-controllers-file.d.ts.map +1 -0
  240. package/dist/nest-controllers/render-controllers-file.js +56 -0
  241. package/dist/nest-controllers/render-controllers-file.js.map +1 -0
  242. package/dist/platform-folders/platform-folders.d.ts.map +1 -1
  243. package/dist/platform-folders/platform-folders.js +10 -0
  244. package/dist/platform-folders/platform-folders.js.map +1 -1
  245. package/dist/presets/apply-preset.d.ts.map +1 -1
  246. package/dist/presets/apply-preset.js +22 -2
  247. package/dist/presets/apply-preset.js.map +1 -1
  248. package/dist/presets/identity-preset.d.ts.map +1 -1
  249. package/dist/presets/identity-preset.js +4 -1
  250. package/dist/presets/identity-preset.js.map +1 -1
  251. package/dist/presets/identity-refusal.d.ts.map +1 -1
  252. package/dist/presets/identity-refusal.js +11 -5
  253. package/dist/presets/identity-refusal.js.map +1 -1
  254. package/dist/presets/lay-out-prisma-models.d.ts +8 -0
  255. package/dist/presets/lay-out-prisma-models.d.ts.map +1 -0
  256. package/dist/presets/lay-out-prisma-models.js +51 -0
  257. package/dist/presets/lay-out-prisma-models.js.map +1 -0
  258. package/dist/presets/preset-files.d.ts.map +1 -1
  259. package/dist/presets/preset-files.js +3 -0
  260. package/dist/presets/preset-files.js.map +1 -1
  261. package/dist/presets/preset.d.ts +11 -0
  262. package/dist/presets/preset.d.ts.map +1 -1
  263. package/dist/sdk/client-files.d.ts +5 -3
  264. package/dist/sdk/client-files.d.ts.map +1 -1
  265. package/dist/sdk/client-files.js +8 -3
  266. package/dist/sdk/client-files.js.map +1 -1
  267. package/dist/sdk/client-manifest.d.ts +3 -0
  268. package/dist/sdk/client-manifest.d.ts.map +1 -1
  269. package/dist/sdk/client-manifest.js +15 -2
  270. package/dist/sdk/client-manifest.js.map +1 -1
  271. package/dist/sdk/client-operation.d.ts +6 -0
  272. package/dist/sdk/client-operation.d.ts.map +1 -1
  273. package/dist/sdk/read-operation.d.ts.map +1 -1
  274. package/dist/sdk/read-operation.js +6 -0
  275. package/dist/sdk/read-operation.js.map +1 -1
  276. package/dist/sdk/render-orpc.d.ts +8 -0
  277. package/dist/sdk/render-orpc.d.ts.map +1 -0
  278. package/dist/sdk/render-orpc.js +42 -0
  279. package/dist/sdk/render-orpc.js.map +1 -0
  280. package/dist/sdk/render-readme.d.ts +3 -0
  281. package/dist/sdk/render-readme.d.ts.map +1 -1
  282. package/dist/sdk/render-readme.js +46 -0
  283. package/dist/sdk/render-readme.js.map +1 -1
  284. package/dist/sdk/render-trpc.d.ts +9 -0
  285. package/dist/sdk/render-trpc.d.ts.map +1 -0
  286. package/dist/sdk/render-trpc.js +36 -0
  287. package/dist/sdk/render-trpc.js.map +1 -0
  288. package/dist/sdk/rpc-packages.d.ts +7 -0
  289. package/dist/sdk/rpc-packages.d.ts.map +1 -0
  290. package/dist/sdk/rpc-packages.js +9 -0
  291. package/dist/sdk/rpc-packages.js.map +1 -0
  292. package/dist/sdk/rpc.d.ts +4 -0
  293. package/dist/sdk/rpc.d.ts.map +1 -0
  294. package/dist/sdk/rpc.js +2 -0
  295. package/dist/sdk/rpc.js.map +1 -0
  296. package/dist/sdk/write-clients.d.ts.map +1 -1
  297. package/dist/sdk/write-clients.js +18 -3
  298. package/dist/sdk/write-clients.js.map +1 -1
  299. package/dist/stack/alias-vars.d.ts.map +1 -1
  300. package/dist/stack/alias-vars.js +2 -2
  301. package/dist/stack/alias-vars.js.map +1 -1
  302. package/dist/stack/audit-vars.js +1 -1
  303. package/dist/stack/audit-vars.js.map +1 -1
  304. package/dist/stack/cache-vars.d.ts +5 -1
  305. package/dist/stack/cache-vars.d.ts.map +1 -1
  306. package/dist/stack/cache-vars.js +9 -3
  307. package/dist/stack/cache-vars.js.map +1 -1
  308. package/dist/stack/stack-vars.d.ts +1 -1
  309. package/dist/stack/stack-vars.d.ts.map +1 -1
  310. package/dist/stack/stack-vars.js +11 -6
  311. package/dist/stack/stack-vars.js.map +1 -1
  312. package/dist/version.d.ts +1 -1
  313. package/dist/version.js +1 -1
  314. package/package.json +4 -4
  315. package/templates/architecture/extractable.declared.spec.ts.tpl +22 -17
  316. package/templates/architecture/extractable.manual.spec.ts.tpl +14 -9
  317. package/templates/architecture/extractable.tsyringe.spec.ts.tpl +19 -14
  318. package/templates/context/module.manual.ts.tpl +11 -0
  319. package/templates/init/jest.config.js.tpl +6 -0
  320. package/templates/init/platform/composition/compose-application.manual.ts.tpl +50 -0
  321. package/templates/init/platform/composition/platform.module.tsyringe.ts.tpl +9 -3
  322. package/templates/init/platform/database/persistence-over.drizzle.ts.tpl +1 -1
  323. package/templates/init/platform/database/persistence-over.knex.ts.tpl +1 -1
  324. package/templates/init/platform/database/persistence-over.prisma.ts.tpl +7 -1
  325. package/templates/init/platform/database/persistence-over.typeorm.ts.tpl +23 -1
  326. package/templates/init/platform/database/persistence.contract.spec.ts.tpl +113 -0
  327. package/templates/init/platform/database/persistence.orm.ts.tpl +8 -3
  328. package/templates/init/platform/database/schema.prisma.tpl +3 -1
  329. package/templates/init/platform/database/schema.typeorm.ts.tpl +17 -3
  330. package/templates/init/platform/database/table-statements.drizzle.ts.tpl +36 -0
  331. package/templates/init/platform/files/bind-files.tsyringe.ts.tpl +1 -1
  332. package/templates/init/platform/files/create-files.ts.tpl +1 -1
  333. package/templates/init/platform/http/create-app-module.ts.tpl +20 -0
  334. package/templates/init/platform/http/start-http-server.express.ts.tpl +48 -1
  335. package/templates/init/platform/http/start-http-server.fastify.ts.tpl +50 -2
  336. package/templates/init/platform/http/start-http-server.hono.ts.tpl +60 -1
  337. package/templates/init/platform/http/start-http-server.nest.ts.tpl +61 -3
  338. package/templates/init/platform/jobs/create-background-work.ts.tpl +2 -2
  339. package/templates/init/rules/infrastructure.md.tpl +3 -0
  340. package/templates/init/rules/presentation.md.tpl +7 -0
  341. package/templates/nest-controller/controller.spec.ts.tpl +57 -0
  342. package/templates/nest-controller/controller.ts.tpl +65 -0
  343. package/templates/pipeline/knip.json.tpl +4 -8
  344. package/templates/pipeline/package-scripts.json +1 -1
  345. package/templates/presets/identity/context/__context__.module.explicit.ts.tpl +254 -0
  346. package/templates/presets/identity/context/application/authorization/change-member-roles.policy.ts.tpl +10 -0
  347. package/templates/presets/identity/context/application/authorization/grant-delegations.policy.ts.tpl +10 -0
  348. package/templates/presets/identity/context/application/authorization/invite-members.policy.ts.tpl +10 -0
  349. package/templates/presets/identity/context/application/authorization/read-members.policy.ts.tpl +10 -0
  350. package/templates/presets/identity/context/application/authorization/remove-members.policy.ts.tpl +10 -0
  351. package/templates/presets/identity/context/application/authorization/revoke-delegations.policy.ts.tpl +10 -0
  352. package/templates/presets/identity/context/application/authorization/revoke-invitations.policy.ts.tpl +10 -0
  353. package/templates/presets/identity/context/application/commands/accept-invitation/accept-invitation.command.ts.tpl +6 -0
  354. package/templates/presets/identity/context/application/commands/accept-invitation/accept-invitation.handler.ts.tpl +12 -0
  355. package/templates/presets/identity/context/application/commands/change-member-role/change-member-role.command.ts.tpl +6 -0
  356. package/templates/presets/identity/context/application/commands/change-member-role/change-member-role.handler.ts.tpl +12 -0
  357. package/templates/presets/identity/context/application/commands/deactivate-account/deactivate-account.command.ts.tpl +6 -0
  358. package/templates/presets/identity/context/application/commands/deactivate-account/deactivate-account.handler.ts.tpl +12 -0
  359. package/templates/presets/identity/context/application/commands/decline-invitation/decline-invitation.command.ts.tpl +6 -0
  360. package/templates/presets/identity/context/application/commands/decline-invitation/decline-invitation.handler.ts.tpl +12 -0
  361. package/templates/presets/identity/context/application/commands/grant-delegation/grant-delegation.command.ts.tpl +6 -0
  362. package/templates/presets/identity/context/application/commands/grant-delegation/grant-delegation.handler.ts.tpl +12 -0
  363. package/templates/presets/identity/context/application/commands/invite-member/invite-member.command.ts.tpl +6 -0
  364. package/templates/presets/identity/context/application/commands/invite-member/invite-member.handler.ts.tpl +12 -0
  365. package/templates/presets/identity/context/application/commands/open-organisation/open-organisation.command.ts.tpl +6 -0
  366. package/templates/presets/identity/context/application/commands/open-organisation/open-organisation.handler.ts.tpl +12 -0
  367. package/templates/presets/identity/context/application/commands/provision-account/provision-account.command.ts.tpl +6 -0
  368. package/templates/presets/identity/context/application/commands/provision-account/provision-account.handler.ts.tpl +12 -0
  369. package/templates/presets/identity/context/application/commands/remove-member/remove-member.command.ts.tpl +6 -0
  370. package/templates/presets/identity/context/application/commands/remove-member/remove-member.handler.ts.tpl +12 -0
  371. package/templates/presets/identity/context/application/commands/revoke-delegation/revoke-delegation.command.ts.tpl +6 -0
  372. package/templates/presets/identity/context/application/commands/revoke-delegation/revoke-delegation.handler.ts.tpl +12 -0
  373. package/templates/presets/identity/context/application/commands/revoke-invitation/revoke-invitation.command.ts.tpl +6 -0
  374. package/templates/presets/identity/context/application/commands/revoke-invitation/revoke-invitation.handler.ts.tpl +12 -0
  375. package/templates/presets/identity/context/application/integration/handlers/account-deactivated.integration-handler.ts.tpl +4 -0
  376. package/templates/presets/identity/context/application/integration/handlers/member-joined.integration-handler.ts.tpl +4 -0
  377. package/templates/presets/identity/context/application/integration/handlers/member-removed.integration-handler.ts.tpl +4 -0
  378. package/templates/presets/identity/context/application/integration/handlers/organisation-opened.integration-handler.ts.tpl +4 -0
  379. package/templates/presets/identity/context/application/integration/publishers/account-deactivated.publisher.ts.tpl +10 -1
  380. package/templates/presets/identity/context/application/integration/publishers/delegation-granted.publisher.ts.tpl +10 -1
  381. package/templates/presets/identity/context/application/integration/publishers/delegation-revoked.publisher.ts.tpl +10 -1
  382. package/templates/presets/identity/context/application/integration/publishers/member-joined.publisher.ts.tpl +10 -1
  383. package/templates/presets/identity/context/application/integration/publishers/member-removed.publisher.ts.tpl +10 -1
  384. package/templates/presets/identity/context/application/integration/publishers/member-role-changed.publisher.ts.tpl +10 -1
  385. package/templates/presets/identity/context/application/integration/publishers/organisation-opened.publisher.ts.tpl +10 -1
  386. package/templates/presets/identity/context/application/queries/search-members/search-members.handler.ts.tpl +12 -0
  387. package/templates/presets/identity/context/application/queries/search-members/search-members.query.ts.tpl +6 -0
  388. package/templates/presets/identity/context/infrastructure/external/crypto-invitation-tokens.adapter.ts.tpl +9 -0
  389. package/templates/presets/identity/context/infrastructure/external/environment-identity-provider-connection.adapter.ts.tpl +9 -0
  390. package/templates/presets/identity/context/infrastructure/external/keycloak-identity-provider-admin.adapter.ts.tpl +9 -0
  391. package/templates/presets/identity/context/infrastructure/persistence/account.mapper.prisma.ts.tpl +36 -0
  392. package/templates/presets/identity/context/infrastructure/persistence/account.personal-fields.privacy.prisma.ts.tpl +19 -0
  393. package/templates/presets/identity/context/infrastructure/persistence/delegation.mapper.prisma.ts.tpl +48 -0
  394. package/templates/presets/identity/context/infrastructure/persistence/drizzle-account.repository.drizzle.ts.tpl +9 -0
  395. package/templates/presets/identity/context/infrastructure/persistence/drizzle-delegation.repository.drizzle.ts.tpl +9 -0
  396. package/templates/presets/identity/context/infrastructure/persistence/drizzle-invitation.repository.drizzle.ts.tpl +9 -0
  397. package/templates/presets/identity/context/infrastructure/persistence/drizzle-member.repository.drizzle.ts.tpl +9 -0
  398. package/templates/presets/identity/context/infrastructure/persistence/drizzle-organisation.repository.drizzle.ts.tpl +9 -0
  399. package/templates/presets/identity/context/infrastructure/persistence/drizzle-search-members-reader.repository.drizzle.ts.tpl +9 -0
  400. package/templates/presets/identity/context/infrastructure/persistence/invitation.mapper.prisma.ts.tpl +43 -0
  401. package/templates/presets/identity/context/infrastructure/persistence/invitation.personal-fields.privacy.prisma.ts.tpl +20 -0
  402. package/templates/presets/identity/context/infrastructure/persistence/knex-account.repository.knex.ts.tpl +9 -0
  403. package/templates/presets/identity/context/infrastructure/persistence/knex-delegation.repository.knex.ts.tpl +9 -0
  404. package/templates/presets/identity/context/infrastructure/persistence/knex-invitation.repository.knex.ts.tpl +9 -0
  405. package/templates/presets/identity/context/infrastructure/persistence/knex-member.repository.knex.ts.tpl +9 -0
  406. package/templates/presets/identity/context/infrastructure/persistence/knex-organisation.repository.knex.ts.tpl +9 -0
  407. package/templates/presets/identity/context/infrastructure/persistence/knex-search-members-reader.repository.knex.ts.tpl +9 -0
  408. package/templates/presets/identity/context/infrastructure/persistence/member.mapper.prisma.ts.tpl +34 -0
  409. package/templates/presets/identity/context/infrastructure/persistence/organisation.mapper.prisma.ts.tpl +26 -0
  410. package/templates/presets/identity/context/infrastructure/persistence/prisma-account.repository.prisma.ts.tpl +63 -0
  411. package/templates/presets/identity/context/infrastructure/persistence/prisma-delegation.repository.prisma.ts.tpl +81 -0
  412. package/templates/presets/identity/context/infrastructure/persistence/prisma-invitation.repository.prisma.ts.tpl +69 -0
  413. package/templates/presets/identity/context/infrastructure/persistence/prisma-member.repository.prisma.ts.tpl +80 -0
  414. package/templates/presets/identity/context/infrastructure/persistence/prisma-organisation.repository.prisma.ts.tpl +63 -0
  415. package/templates/presets/identity/context/infrastructure/persistence/prisma-search-members-reader.repository.prisma.ts.tpl +82 -0
  416. package/templates/presets/identity/context/test/integration/account.repository.contract.spec.ts.tpl +3 -3
  417. package/templates/presets/identity/context/test/integration/delegation.repository.contract.spec.ts.tpl +5 -5
  418. package/templates/presets/identity/context/test/integration/invitation.repository.contract.spec.ts.tpl +5 -5
  419. package/templates/presets/identity/context/test/integration/member.repository.contract.spec.ts.tpl +5 -5
  420. package/templates/presets/identity/context/test/integration/organisation.repository.contract.spec.ts.tpl +3 -3
  421. package/templates/presets/identity/context/test/integration/search-members-reader.spec.ts.tpl +8 -8
  422. package/templates/presets/identity/context/test/unit/__context__.module.spec.explicit.ts.tpl +95 -0
  423. package/templates/presets/identity/context/test/worlds/__context__.world.explicit.ts.tpl +332 -0
  424. package/templates/presets/identity/explicit/access-policies.wiring.tpl +16 -0
  425. package/templates/presets/identity/prisma/models.prisma.tpl +128 -0
  426. package/templates/property/value-object.properties.spec.ts.tpl +38 -0
  427. package/templates/sdk/orpc.ts.tpl +46 -0
  428. package/templates/sdk/trpc.ts.tpl +86 -0
  429. /package/templates/presets/identity/context/test/worlds/{__context__.world.ts.tpl → __context__.world.declared.ts.tpl} +0 -0
@@ -83,6 +83,8 @@ model BackgroundJob {
83
83
 
84
84
  // The instances of the process managers, from @ddd-ts-kit/prisma, saved in the transaction of each step.
85
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")
86
88
  name String
87
89
  id String
88
90
  /// JSON as text: a state may be null.
@@ -92,7 +94,7 @@ model ProcessInstance {
92
94
  timeouts Json
93
95
  updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz(3)
94
96
 
95
- @@id([name, id])
97
+ @@id([tenantId, name, id])
96
98
  @@map("process_instances")
97
99
  @@schema("messaging")
98
100
  }
@@ -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}}
@@ -2,6 +2,14 @@ import type { Server } from 'node:http';
2
2
  import type { AddressInfo } from 'node:net';
3
3
  import express from 'express';
4
4
  import { mountExpress } from '@ddd-ts-kit/http/express';
5
+ {{#if rpc.orpc}}
6
+ import { orpcRouter } from '@ddd-ts-kit/http/orpc';
7
+ import { RPCHandler } from '@orpc/server/node';
8
+ {{/if}}
9
+ {{#if rpc.trpc}}
10
+ import { trpcRouter } from '@ddd-ts-kit/http/trpc';
11
+ import { createExpressMiddleware } from '@trpc/server/adapters/express';
12
+ {{/if}}
5
13
  import type { Application } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
6
14
  import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
7
15
  {{#if cache.rateLimit}}
@@ -24,7 +32,9 @@ type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | '
24
32
  /**
25
33
  * Serves, in this order: the readiness probe and the limit of each caller (with a Redis protocol
26
34
  * server), the signed file links before any body parser (with a storage the application serves),
27
- * the routes of the contexts, then the pages of the contract (with documentation on).
35
+ * the routes of the contexts, then the pages of the contract (with documentation on).{{#if rpc.orpc}} The same
36
+ * routes are served as oRPC procedures under /rpc, for the typed client of the contract.{{/if}}{{#if rpc.trpc}} The same
37
+ * routes are served as tRPC procedures under /trpc, for the typed client of the contract.{{/if}}
28
38
  */
29
39
  export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
30
40
  const app = express();
@@ -39,6 +49,9 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
39
49
  mountExpress(app, served.fileRoutes, served.boundary);
40
50
  {{/if}}
41
51
  app.use(express.json());
52
+ {{#unless rpc.none}}
53
+ serveProcedures(app, served);
54
+ {{/unless}}
42
55
  {{#if docs.any}}
43
56
  mountExpress(app, withDocumentation(served.routes, config, served.boundary), served.boundary);
44
57
  {{/if}}
@@ -74,6 +87,40 @@ function limitEachCaller(app: express.Express, served: Served, config: AppConfig
74
87
  });
75
88
  }
76
89
  {{/if}}
90
+ {{#if rpc.orpc}}
91
+
92
+ const RPC_PREFIX = '/rpc';
93
+
94
+ /** Each route as the procedure named by its operationId: the same pipeline, the JSON body already read. */
95
+ function serveProcedures(app: express.Express, served: Served): void {
96
+ const handler = new RPCHandler(orpcRouter(served.routes, served.boundary));
97
+
98
+ app.use(RPC_PREFIX, (request, response, next) => {
99
+ const context = { headers: request.headers, raw: request };
100
+
101
+ void handler.handle(request, response, { prefix: RPC_PREFIX, context }).then(({ matched }) => {
102
+ if (!matched) {
103
+ next();
104
+ }
105
+ }, next);
106
+ });
107
+ }
108
+ {{/if}}
109
+ {{#if rpc.trpc}}
110
+
111
+ const TRPC_ENDPOINT = '/trpc';
112
+
113
+ /** Each route as the procedure named by its operationId: the same pipeline, the JSON body already read. */
114
+ function serveProcedures(app: express.Express, served: Served): void {
115
+ app.use(
116
+ TRPC_ENDPOINT,
117
+ createExpressMiddleware({
118
+ router: trpcRouter(served.routes, served.boundary),
119
+ createContext: ({ req }) => ({ headers: req.headers, raw: req }),
120
+ }),
121
+ );
122
+ }
123
+ {{/if}}
77
124
 
78
125
  function listen(app: express.Express, port: number): Promise<Server> {
79
126
  return new Promise<Server>((resolve) => {
@@ -1,5 +1,13 @@
1
- import Fastify{{#if cache.rateLimit}}, { type FastifyInstance }{{/if}} from 'fastify';
1
+ import Fastify{{#if cache.rateLimit}}, { type FastifyInstance }{{/if}}{{#unless cache.rateLimit}}{{#unless rpc.none}}, { type FastifyInstance }{{/unless}}{{/unless}} from 'fastify';
2
2
  import { mountFastify } from '@ddd-ts-kit/http/fastify';
3
+ {{#if rpc.orpc}}
4
+ import { orpcRouter } from '@ddd-ts-kit/http/orpc';
5
+ import { RPCHandler } from '@orpc/server/fastify';
6
+ {{/if}}
7
+ {{#if rpc.trpc}}
8
+ import { type TrpcRouter, trpcRouter } from '@ddd-ts-kit/http/trpc';
9
+ import { type FastifyTRPCPluginOptions, fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';
10
+ {{/if}}
3
11
  import type { Application } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
4
12
  import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
5
13
  {{#if cache.rateLimit}}
@@ -22,7 +30,9 @@ type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | '
22
30
  /**
23
31
  * Serves, in this order: the readiness probe and the limit of each caller (with a Redis protocol
24
32
  * server), the signed file links (with a storage the application serves), the routes of the
25
- * contexts, then the pages of the contract (with documentation on).
33
+ * contexts, then the pages of the contract (with documentation on).{{#if rpc.orpc}} The same routes are served
34
+ * as oRPC procedures under /rpc, for the typed client of the contract.{{/if}}{{#if rpc.trpc}} The same routes are served
35
+ * as tRPC procedures under /trpc, for the typed client of the contract.{{/if}}
26
36
  */
27
37
  export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
28
38
  const app = Fastify();
@@ -40,6 +50,12 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
40
50
  {{#unless docs.any}}
41
51
  mountFastify(app, served.routes, served.boundary);
42
52
  {{/unless}}
53
+ {{#if rpc.orpc}}
54
+ serveProcedures(app, served);
55
+ {{/if}}
56
+ {{#if rpc.trpc}}
57
+ await serveProcedures(app, served);
58
+ {{/if}}
43
59
  await app.listen({ port: config.port, host: '0.0.0.0' });
44
60
 
45
61
  const [address] = app.addresses();
@@ -72,3 +88,35 @@ function limitEachCaller(app: FastifyInstance, served: Served, config: AppConfig
72
88
  });
73
89
  }
74
90
  {{/if}}
91
+ {{#if rpc.orpc}}
92
+
93
+ const RPC_PREFIX = '/rpc';
94
+
95
+ /** Each route as the procedure named by its operationId: the same pipeline, the JSON body already read by Fastify. */
96
+ function serveProcedures(app: FastifyInstance, served: Served): void {
97
+ const handler = new RPCHandler(orpcRouter(served.routes, served.boundary));
98
+
99
+ app.all(`${RPC_PREFIX}/*`, async (request, reply) => {
100
+ const context = { headers: request.headers, raw: request };
101
+ const { matched } = await handler.handle(request, reply, { prefix: RPC_PREFIX, context });
102
+
103
+ if (!matched) {
104
+ reply.callNotFound();
105
+ }
106
+ });
107
+ }
108
+ {{/if}}
109
+ {{#if rpc.trpc}}
110
+
111
+ const TRPC_ENDPOINT = '/trpc';
112
+
113
+ /** Each route as the procedure named by its operationId: the same pipeline, the JSON body already read by Fastify. */
114
+ async function serveProcedures(app: FastifyInstance, served: Served): Promise<void> {
115
+ const trpcOptions: FastifyTRPCPluginOptions<TrpcRouter>['trpcOptions'] = {
116
+ router: trpcRouter(served.routes, served.boundary),
117
+ createContext: ({ req }) => ({ headers: req.headers, raw: req }),
118
+ };
119
+
120
+ await app.register(fastifyTRPCPlugin, { prefix: TRPC_ENDPOINT, trpcOptions });
121
+ }
122
+ {{/if}}
@@ -5,6 +5,14 @@ import { getConnInfo } from '@hono/node-server/conninfo';
5
5
  {{/if}}
6
6
  import { Hono } from 'hono';
7
7
  import { mountHono } from '@ddd-ts-kit/http/hono';
8
+ {{#if rpc.orpc}}
9
+ import { orpcRouter } from '@ddd-ts-kit/http/orpc';
10
+ import { RPCHandler } from '@orpc/server/fetch';
11
+ {{/if}}
12
+ {{#if rpc.trpc}}
13
+ import { trpcRouter } from '@ddd-ts-kit/http/trpc';
14
+ import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
15
+ {{/if}}
8
16
  import type { Application } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
9
17
  import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
10
18
  {{#if cache.rateLimit}}
@@ -27,7 +35,9 @@ type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | '
27
35
  /**
28
36
  * Serves, in this order: the readiness probe and the limit of each caller (with a Redis protocol
29
37
  * server), the signed file links (with a storage the application serves), the routes of the
30
- * contexts, then the pages of the contract (with documentation on).
38
+ * contexts, then the pages of the contract (with documentation on).{{#if rpc.orpc}} The same routes are served
39
+ * as oRPC procedures under /rpc, for the typed client of the contract.{{/if}}{{#if rpc.trpc}} The same routes are served
40
+ * as tRPC procedures under /trpc, for the typed client of the contract.{{/if}}
31
41
  */
32
42
  export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
33
43
  const app = new Hono();
@@ -39,6 +49,9 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
39
49
  {{#if files.http}}
40
50
  mountHono(app, served.fileRoutes, served.boundary);
41
51
  {{/if}}
52
+ {{#unless rpc.none}}
53
+ serveProcedures(app, served);
54
+ {{/unless}}
42
55
  {{#if docs.any}}
43
56
  mountHono(app, withDocumentation(served.routes, config, served.boundary), served.boundary);
44
57
  {{/if}}
@@ -77,6 +90,52 @@ function limitEachCaller(app: Hono, served: Served, config: AppConfig): void {
77
90
  });
78
91
  }
79
92
  {{/if}}
93
+ {{#if rpc.orpc}}
94
+
95
+ const RPC_PREFIX = '/rpc';
96
+
97
+ /** Each route as the procedure named by its operationId: the same pipeline, the raw request what the routes read. */
98
+ function serveProcedures(app: Hono, served: Served): void {
99
+ const handler = new RPCHandler(orpcRouter(served.routes, served.boundary));
100
+
101
+ app.use(`${RPC_PREFIX}/*`, async (context, next) => {
102
+ const headers = context.req.header();
103
+
104
+ const { matched, response } = await handler.handle(context.req.raw, {
105
+ prefix: RPC_PREFIX,
106
+ context: { headers, raw: { headers, context } },
107
+ });
108
+
109
+ if (matched) {
110
+ return context.newResponse(response.body, response);
111
+ }
112
+
113
+ await next();
114
+
115
+ return undefined;
116
+ });
117
+ }
118
+ {{/if}}
119
+ {{#if rpc.trpc}}
120
+
121
+ const TRPC_ENDPOINT = '/trpc';
122
+
123
+ /** Each route as the procedure named by its operationId: the same pipeline, the raw request what the routes read. */
124
+ function serveProcedures(app: Hono, served: Served): void {
125
+ const router = trpcRouter(served.routes, served.boundary);
126
+
127
+ app.all(`${TRPC_ENDPOINT}/*`, (context) => {
128
+ const headers = context.req.header();
129
+
130
+ return fetchRequestHandler({
131
+ endpoint: TRPC_ENDPOINT,
132
+ req: context.req.raw,
133
+ router,
134
+ createContext: () => ({ headers, raw: { headers, context } }),
135
+ });
136
+ });
137
+ }
138
+ {{/if}}
80
139
 
81
140
  function listen(app: Hono, port: number): Promise<ServerType> {
82
141
  return new Promise<ServerType>((resolve) => {
@@ -1,6 +1,14 @@
1
1
  import 'reflect-metadata';
2
- import { Server } from 'node:http';
2
+ import { {{#if rpc.orpc}}type IncomingMessage, {{/if}}{{#if rpc.trpc}}type RequestListener, {{/if}}Server{{#if rpc.orpc}}, type ServerResponse{{/if}} } from 'node:http';
3
3
  import { NestFactory } from '@nestjs/core';
4
+ {{#if rpc.orpc}}
5
+ import { orpcRouter } from '@ddd-ts-kit/http/orpc';
6
+ import { RPCHandler } from '@orpc/server/node';
7
+ {{/if}}
8
+ {{#if rpc.trpc}}
9
+ import { trpcRouter } from '@ddd-ts-kit/http/trpc';
10
+ import { createHTTPHandler } from '@trpc/server/adapters/standalone';
11
+ {{/if}}
4
12
  import type { Application } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
5
13
  import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
6
14
  import { createAppModule } from '{{alias.platform}}/http/create-app-module{{alias.ext}}';
@@ -19,7 +27,7 @@ export interface HttpServer {
19
27
  }
20
28
 
21
29
  /** What the server needs of the application: its routes and what stands at its edge. */
22
- type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}{{#if files.http}} | 'fileRoutes'{{/if}}>;
30
+ type Served = Pick<Application, 'routes' | 'boundary'{{#if routes.nest}} | 'controllers'{{/if}}{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}{{#if files.http}} | 'fileRoutes'{{/if}}>;
23
31
  {{#if cache.rateLimit}}
24
32
 
25
33
  /** The part of the incoming request and of its response the limiter and the probe need, whatever Nest runs on. */
@@ -40,7 +48,9 @@ type Middleware = (request: Incoming, response: Outgoing, next: () => void) => v
40
48
  /**
41
49
  * Serves, in this order: the readiness probe and the limit of each caller (with a Redis protocol
42
50
  * server), then the routes of the contexts, the pages of the contract (with documentation on) and
43
- * the signed file links (with a storage the application serves), all in one Nest module.
51
+ * the signed file links (with a storage the application serves), all in one Nest module.{{#if rpc.orpc}} The
52
+ * routes of the contexts are served as oRPC procedures under /rpc too, for the typed client of the contract.{{/if}}{{#if rpc.trpc}} The
53
+ * routes of the contexts are served as tRPC procedures under /trpc too, for the typed client of the contract.{{/if}}
44
54
  */
45
55
  export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
46
56
  {{#if files.http}}
@@ -60,12 +70,27 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
60
70
  {{/unless}}
61
71
  {{/unless}}
62
72
 
73
+ {{#if routes.nest}}
74
+ const app = await NestFactory.create(createAppModule(routes, served.boundary, served.controllers), {
75
+ logger: ['error', 'warn'],
76
+ });
77
+ {{/if}}
78
+ {{#unless routes.nest}}
63
79
  const app = await NestFactory.create(createAppModule(routes, served.boundary), { logger: ['error', 'warn'] });
80
+ {{/unless}}
64
81
 
65
82
  {{#if cache.rateLimit}}
66
83
  app.use(answeringReadiness(served));
67
84
  app.use(limitingEachCaller(served, config));
68
85
 
86
+ {{/if}}
87
+ {{#if rpc.orpc}}
88
+ app.use(RPC_PREFIX, servingProcedures(served));
89
+
90
+ {{/if}}
91
+ {{#if rpc.trpc}}
92
+ app.use(TRPC_ENDPOINT, servingProcedures(served));
93
+
69
94
  {{/if}}
70
95
  await app.listen(config.port);
71
96
 
@@ -103,6 +128,39 @@ function limitingEachCaller(served: Served, config: AppConfig): Middleware {
103
128
  };
104
129
  }
105
130
  {{/if}}
131
+ {{#if rpc.orpc}}
132
+
133
+ const RPC_PREFIX = '/rpc';
134
+
135
+ /** Each route as the procedure named by its operationId: the same pipeline, the JSON body already read by Nest. */
136
+ function servingProcedures(
137
+ served: Served,
138
+ ): (request: IncomingMessage, response: ServerResponse, next: (error?: unknown) => void) => void {
139
+ const handler = new RPCHandler(orpcRouter(served.routes, served.boundary));
140
+
141
+ return (request, response, next) => {
142
+ const context = { headers: request.headers, raw: request };
143
+
144
+ void handler.handle(request, response, { prefix: RPC_PREFIX, context }).then(({ matched }) => {
145
+ if (!matched) {
146
+ next();
147
+ }
148
+ }, next);
149
+ };
150
+ }
151
+ {{/if}}
152
+ {{#if rpc.trpc}}
153
+
154
+ const TRPC_ENDPOINT = '/trpc';
155
+
156
+ /** Each route as the procedure named by its operationId, its path what Nest leaves of the URL: the JSON body already read by Nest. */
157
+ function servingProcedures(served: Served): RequestListener {
158
+ return createHTTPHandler({
159
+ router: trpcRouter(served.routes, served.boundary),
160
+ createContext: ({ req }) => ({ headers: req.headers, raw: req }),
161
+ });
162
+ }
163
+ {{/if}}
106
164
 
107
165
  // Nest types its HTTP server loosely: the port is read only from what proves to be a Node server.
108
166
  function boundPort(server: unknown): number {
@@ -90,10 +90,10 @@ export function createBackgroundWork({
90
90
  processes: new StoredProcessRunner({
91
91
  {{#if queue.processTable}}
92
92
  // The instances of the process managers, saved in the transaction of each step.
93
- store: persistence.processes,
93
+ store: persistence.processes(scope),
94
94
  {{/if}}
95
95
  {{#unless queue.processTable}}
96
- // The instances of the process managers, in the memory of the process: `KnexProcessStore`, `DrizzleProcessStore` or `PrismaProcessStore` keeps them with the steps.
96
+ // The instances of the process managers, in the memory of the process: the process store of the ORM package keeps them with the steps.
97
97
  store: new InMemoryProcessStore(),
98
98
  {{/unless}}
99
99
  jobs: jobQueue,
@@ -11,6 +11,9 @@ paths:
11
11
  {{#if literals.named}}
12
12
  - A word of the other model stays its word: a translator keys its tables by the type of that model, `Record<TheirRecord['code'], InvoiceStatus>` (an annotation or `satisfies`), and compares with `'code' satisfies TheirRecord['code']`, so that the compiler holds its spelling; the value of the context it produces is read from its vocabulary (`language/declared-vocabulary`).
13
13
  {{/if}}
14
+ {{#if http.nest}}
15
+ - An adapter throws no `HttpException` of Nest and logs through the `Logger` of the kernel, not the one of Nest; `@nestjs/config`, `@nestjs/typeorm` and the other modules of Nest whose work the kit does stay out of a context (`nest/no-parallel-pipeline`). `@Injectable()` and `@Inject()` are allowed here, for an adapter bound as a Nest provider.
16
+ {{/if}}
14
17
  - Rows never leave `persistence/`: a mapper translates to and from the aggregate, and is the only place for a type assertion (`clean/no-escape-hatch`).
15
18
  - The content of a file never goes in a table: no binary or base64 column (`persistence/no-file-content`). The file lives in the `FileStorage` port; a row keeps the key, size, media type and checksum of its `StoredFile`.
16
19
  - Own tables, in the schema of the context: no join, foreign key or transaction across contexts (`context/extractable`).
@@ -17,9 +17,16 @@ paths:
17
17
  - A route group (`<resource>.routes.ts`, `@RouteGroup`) gives its controllers a prefix, a tag and guards. A controller names its group, or says `guards: [Public]`: nothing is open by omission (`authz/declared`).
18
18
  - A guard is a control at the edge (authenticated, a role, the tenant of the path); a permission stays on the use case (`@Requires`), where a job and an event handler meet it too. A guard of the project is a declared class in `presentation/http/guards/*.guard.ts` and never imports `domain/`, `infrastructure/`, a repository or the command bus (`presentation/guard-at-the-edge`).
19
19
  {{/if}}
20
+ {{#if routes.nest}}
21
+ - A route is a Nest controller the kit serves: `<use-case>.controller.ts` in `presentation/http/<resource>/<use-case>/`, `@Controller()` and `@KitRoutes({ group: <Resource>Routes })` on the class, `@Post`, `@Get`... of Nest on its method, which names the route (its `operationId`) after the method, and `@KitRoute({ request, response, errors })` of `@ddd-ts-kit/http/nest` for what Nest does not say. The method reads `@Param()`, `@Query()`, `@Headers()`, `@Body()` typed by the DTO classes beside it, and the caller with `@CurrentActor()`; it builds the command or the query and sends it through the bus the constructor injects (`@Inject(CommandBus)`), nothing else: the buses are the only providers the platform gives Nest for the controllers. Nest builds the controller (the module of the context lists it under `controllers`), the kit serves it: guards of the group, validation by `request`, problem documents, the contract.
22
+ - A method answers what its signature says: a DTO class (`Promise<<UseCase>Answer>`), `Accepted` or `void`, which `ddd-ts-kit` reads into the generated `<context>.controllers.ts` the module lists (`nest/controllers-current` keeps it current); any other answer is said in `response` of `@KitRoute`. The raw request and answer of Nest (`@Req`, `@Res`, `@Header`), its guards, pipes, interceptors and filters are refused (`nest/no-parallel-pipeline`): the kit would not run them.
23
+ {{/if}}
20
24
  {{#if routes.functions}}
21
25
  - A route validates the shape of the input, builds a command or a query with the actor, executes it through `CommandBus` or `QueryBus` (never a handler class) and maps the answer. Nothing else.
22
26
  {{/if}}
27
+ {{#if http.nest}}
28
+ - Nothing of Nest's request pipeline in a context: no controller Nest serves, guard, pipe, exception filter, interceptor, raw request or `HttpException` of Nest, no `@nestjs/swagger`, `@nestjs/cqrs` or `@nestjs/passport` (`nest/no-parallel-pipeline`). The routes of the kit do not go through that pipeline, and a Nest controller is a route the kit does not see: no declared security, no problem codes, missing from the contract. A route is the kit's, a right is the permission of the use case, a refusal comes from the code list; each finding names the tool of the kit to use. A Nest controller stays a Nest controller once the kit serves it: `@KitRoute` of `@ddd-ts-kit/http/nest` on each method (its `operationId`, `summary`, `guards`, `errors`), `@CurrentActor()` for the caller, served by `createControllersModule`. Nest stays in the platform, for what reaches no use case.
29
+ {{/if}}
23
30
  - Imports `application/` (and domain types for mapping), never `infrastructure/` (`layer/presentation-no-infrastructure`).
24
31
  - Input shape is validated here with the schema library of the project, behind the `Schema` port. Business rules are not validated here.
25
32
  {{#if refusals.named}}
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it } from '{{tests.module}}';
2
+ import { executeRoute } from '@ddd-ts-kit/http';
3
+ import { nestControllerRoute } from '@ddd-ts-kit/http/nest';
4
+ import { classSchema } from '@ddd-ts-kit/validation/class-validator';
5
+ import { {{route.busClass}}{{#if route.protected}}, type Actor{{/if}} } from '@ddd-ts-kit/kernel';
6
+ {{route.messageImport}}
7
+ {{route.specImports}}
8
+ import { {{context.camel}}Controllers } from '{{alias.context}}/{{context.kebab}}.controllers{{alias.ext}}';
9
+
10
+ {{#if route.protected}}
11
+ const caller: Actor = { id: 'user-1', type: 'user', roles: [], attributes: {} };
12
+
13
+ {{/if}}
14
+ describe('{{route.method}} {{route.path}}', () => {
15
+ it('answers {{route.status}} when the use case succeeds', async () => {
16
+ {{#if route.isPlainQuery}}
17
+ const {{route.bus}} = new {{route.busClass}}().register({{route.input}}, {
18
+ execute: async () => ({}),
19
+ });
20
+ {{/if}}
21
+ {{#if route.isSearch}}
22
+ const {{route.bus}} = new {{route.busClass}}().register({{route.input}}, {
23
+ execute: async () => ({ items: [{ id: '{{name.kebab}}-1' }], total: 1 }),
24
+ });
25
+ {{/if}}
26
+ {{#if route.returnsId}}
27
+ const {{route.bus}} = new {{route.busClass}}().register({{route.input}}, {
28
+ execute: async () => '{{name.kebab}}-1',
29
+ });
30
+ {{/if}}
31
+ {{#if route.returnsNothing}}
32
+ const {{route.bus}} = new {{route.busClass}}().register({{route.input}}, {
33
+ execute: async () => undefined,
34
+ });
35
+ {{/if}}
36
+
37
+ const route = nestControllerRoute({{name.pascal}}Controller, {
38
+ instanceOf: () => new {{name.pascal}}Controller({{route.specArguments}}),
39
+ // A DTO without a decorated field yet accepts the empty object alone: whitelist and forbidNonWhitelisted refuse any field.
40
+ schemaOfClass: (dto) => classSchema(dto, { validator: { forbidUnknownValues: false } }),
41
+ });
42
+
43
+ const response = await executeRoute(
44
+ route,
45
+ { params: {{route.sampleParams}}, query: {}, headers: {}, body: {}, raw: undefined },
46
+ { validateResponses: true{{#if route.protected}}, resolvePrincipal: () => caller{{/if}} },
47
+ );
48
+
49
+ expect(response.status).toBe({{route.status}});
50
+ expect(route.path).toBe('{{route.path}}');
51
+ expect({{context.camel}}Controllers).toContain({{name.pascal}}Controller);
52
+ });
53
+
54
+ // TODO(domain): replace each entry below by a test of the contract a client relies on.
55
+ it.todo('refuses an input that does not have the expected shape with 422');
56
+ it.todo('answers the documented status for each error code of the use case');
57
+ });