ddd-ts-kit 0.8.0 → 0.10.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 (317) hide show
  1. package/README.md +12 -2
  2. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  3. package/dist/check/catalogue/architecture-rules.js +14 -0
  4. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  5. package/dist/check/errors/kit-error-codes.d.ts.map +1 -1
  6. package/dist/check/errors/kit-error-codes.js +5 -0
  7. package/dist/check/errors/kit-error-codes.js.map +1 -1
  8. package/dist/check/event-sourcing/declared-shape.d.ts +13 -0
  9. package/dist/check/event-sourcing/declared-shape.d.ts.map +1 -0
  10. package/dist/check/event-sourcing/declared-shape.js +100 -0
  11. package/dist/check/event-sourcing/declared-shape.js.map +1 -0
  12. package/dist/check/event-sourcing/event-sourced-classes.d.ts +5 -0
  13. package/dist/check/event-sourcing/event-sourced-classes.d.ts.map +1 -0
  14. package/dist/check/event-sourcing/event-sourced-classes.js +13 -0
  15. package/dist/check/event-sourcing/event-sourced-classes.js.map +1 -0
  16. package/dist/check/event-sourcing/fact-words.d.ts +6 -0
  17. package/dist/check/event-sourcing/fact-words.d.ts.map +1 -0
  18. package/dist/check/event-sourcing/fact-words.js +10 -0
  19. package/dist/check/event-sourcing/fact-words.js.map +1 -0
  20. package/dist/check/event-sourcing/is-apply-method.d.ts +3 -0
  21. package/dist/check/event-sourcing/is-apply-method.d.ts.map +1 -0
  22. package/dist/check/event-sourcing/is-apply-method.js +6 -0
  23. package/dist/check/event-sourcing/is-apply-method.js.map +1 -0
  24. package/dist/check/event-sourcing/kernel-names.d.ts +8 -0
  25. package/dist/check/event-sourcing/kernel-names.d.ts.map +1 -0
  26. package/dist/check/event-sourcing/kernel-names.js +7 -0
  27. package/dist/check/event-sourcing/kernel-names.js.map +1 -0
  28. package/dist/check/event-sourcing/read-stored-events-lock.d.ts +5 -0
  29. package/dist/check/event-sourcing/read-stored-events-lock.d.ts.map +1 -0
  30. package/dist/check/event-sourcing/read-stored-events-lock.js +25 -0
  31. package/dist/check/event-sourcing/read-stored-events-lock.js.map +1 -0
  32. package/dist/check/event-sourcing/read-stored-shape.d.ts +12 -0
  33. package/dist/check/event-sourcing/read-stored-shape.d.ts.map +1 -0
  34. package/dist/check/event-sourcing/read-stored-shape.js +46 -0
  35. package/dist/check/event-sourcing/read-stored-shape.js.map +1 -0
  36. package/dist/check/event-sourcing/state-writes.d.ts +3 -0
  37. package/dist/check/event-sourcing/state-writes.d.ts.map +1 -0
  38. package/dist/check/event-sourcing/state-writes.js +11 -0
  39. package/dist/check/event-sourcing/state-writes.js.map +1 -0
  40. package/dist/check/event-sourcing/stored-event-declaration.d.ts +18 -0
  41. package/dist/check/event-sourcing/stored-event-declaration.d.ts.map +1 -0
  42. package/dist/check/event-sourcing/stored-event-declaration.js +2 -0
  43. package/dist/check/event-sourcing/stored-event-declaration.js.map +1 -0
  44. package/dist/check/event-sourcing/stored-event-declarations.d.ts +9 -0
  45. package/dist/check/event-sourcing/stored-event-declarations.d.ts.map +1 -0
  46. package/dist/check/event-sourcing/stored-event-declarations.js +64 -0
  47. package/dist/check/event-sourcing/stored-event-declarations.js.map +1 -0
  48. package/dist/check/event-sourcing/stored-events-lock-file.d.ts +3 -0
  49. package/dist/check/event-sourcing/stored-events-lock-file.d.ts.map +1 -0
  50. package/dist/check/event-sourcing/stored-events-lock-file.js +3 -0
  51. package/dist/check/event-sourcing/stored-events-lock-file.js.map +1 -0
  52. package/dist/check/event-sourcing/stored-shape.d.ts +7 -0
  53. package/dist/check/event-sourcing/stored-shape.d.ts.map +1 -0
  54. package/dist/check/event-sourcing/stored-shape.js +2 -0
  55. package/dist/check/event-sourcing/stored-shape.js.map +1 -0
  56. package/dist/check/event-sourcing/words-of.d.ts +3 -0
  57. package/dist/check/event-sourcing/words-of.d.ts.map +1 -0
  58. package/dist/check/event-sourcing/words-of.js +9 -0
  59. package/dist/check/event-sourcing/words-of.js.map +1 -0
  60. package/dist/check/events/event-name-resolver.d.ts +6 -0
  61. package/dist/check/events/event-name-resolver.d.ts.map +1 -0
  62. package/dist/check/events/event-name-resolver.js +21 -0
  63. package/dist/check/events/event-name-resolver.js.map +1 -0
  64. package/dist/check/explain/errors-docs.js +1 -1
  65. package/dist/check/explain/errors-docs.js.map +1 -1
  66. package/dist/check/explain/event-sourcing-docs.d.ts +3 -0
  67. package/dist/check/explain/event-sourcing-docs.d.ts.map +1 -0
  68. package/dist/check/explain/event-sourcing-docs.js +62 -0
  69. package/dist/check/explain/event-sourcing-docs.js.map +1 -0
  70. package/dist/check/explain/persistence-docs.d.ts.map +1 -1
  71. package/dist/check/explain/persistence-docs.js +26 -0
  72. package/dist/check/explain/persistence-docs.js.map +1 -1
  73. package/dist/check/explain/rule-docs.d.ts.map +1 -1
  74. package/dist/check/explain/rule-docs.js +2 -0
  75. package/dist/check/explain/rule-docs.js.map +1 -1
  76. package/dist/check/files/file-content-findings.d.ts +4 -0
  77. package/dist/check/files/file-content-findings.d.ts.map +1 -0
  78. package/dist/check/files/file-content-findings.js +29 -0
  79. package/dist/check/files/file-content-findings.js.map +1 -0
  80. package/dist/check/files/file-content-pattern.d.ts +7 -0
  81. package/dist/check/files/file-content-pattern.d.ts.map +1 -0
  82. package/dist/check/files/file-content-pattern.js +17 -0
  83. package/dist/check/files/file-content-pattern.js.map +1 -0
  84. package/dist/check/files/schema-sources.d.ts +13 -0
  85. package/dist/check/files/schema-sources.d.ts.map +1 -0
  86. package/dist/check/files/schema-sources.js +37 -0
  87. package/dist/check/files/schema-sources.js.map +1 -0
  88. package/dist/check/fixtures/event-sourcing-fixtures.d.ts +3 -0
  89. package/dist/check/fixtures/event-sourcing-fixtures.d.ts.map +1 -0
  90. package/dist/check/fixtures/event-sourcing-fixtures.js +199 -0
  91. package/dist/check/fixtures/event-sourcing-fixtures.js.map +1 -0
  92. package/dist/check/fixtures/event-sourcing-projection-fixtures.d.ts +3 -0
  93. package/dist/check/fixtures/event-sourcing-projection-fixtures.d.ts.map +1 -0
  94. package/dist/check/fixtures/event-sourcing-projection-fixtures.js +48 -0
  95. package/dist/check/fixtures/event-sourcing-projection-fixtures.js.map +1 -0
  96. package/dist/check/fixtures/files-fixtures.d.ts +3 -0
  97. package/dist/check/fixtures/files-fixtures.d.ts.map +1 -0
  98. package/dist/check/fixtures/files-fixtures.js +92 -0
  99. package/dist/check/fixtures/files-fixtures.js.map +1 -0
  100. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  101. package/dist/check/fixtures/fixtures.js +4 -0
  102. package/dist/check/fixtures/fixtures.js.map +1 -1
  103. package/dist/check/layers/outside-concern.d.ts.map +1 -1
  104. package/dist/check/layers/outside-concern.js +4 -0
  105. package/dist/check/layers/outside-concern.js.map +1 -1
  106. package/dist/check/rules/event-sourcing-past-tense.d.ts +3 -0
  107. package/dist/check/rules/event-sourcing-past-tense.d.ts.map +1 -0
  108. package/dist/check/rules/event-sourcing-past-tense.js +31 -0
  109. package/dist/check/rules/event-sourcing-past-tense.js.map +1 -0
  110. package/dist/check/rules/event-sourcing-projection-never-appends.d.ts +3 -0
  111. package/dist/check/rules/event-sourcing-projection-never-appends.d.ts.map +1 -0
  112. package/dist/check/rules/event-sourcing-projection-never-appends.js +54 -0
  113. package/dist/check/rules/event-sourcing-projection-never-appends.js.map +1 -0
  114. package/dist/check/rules/event-sourcing-state-in-apply.d.ts +3 -0
  115. package/dist/check/rules/event-sourcing-state-in-apply.d.ts.map +1 -0
  116. package/dist/check/rules/event-sourcing-state-in-apply.js +34 -0
  117. package/dist/check/rules/event-sourcing-state-in-apply.js.map +1 -0
  118. package/dist/check/rules/event-sourcing-store-behind-repository.d.ts +3 -0
  119. package/dist/check/rules/event-sourcing-store-behind-repository.d.ts.map +1 -0
  120. package/dist/check/rules/event-sourcing-store-behind-repository.js +34 -0
  121. package/dist/check/rules/event-sourcing-store-behind-repository.js.map +1 -0
  122. package/dist/check/rules/event-sourcing-upcaster-required.d.ts +3 -0
  123. package/dist/check/rules/event-sourcing-upcaster-required.d.ts.map +1 -0
  124. package/dist/check/rules/event-sourcing-upcaster-required.js +79 -0
  125. package/dist/check/rules/event-sourcing-upcaster-required.js.map +1 -0
  126. package/dist/check/rules/files-port-not-connector.d.ts +3 -0
  127. package/dist/check/rules/files-port-not-connector.d.ts.map +1 -0
  128. package/dist/check/rules/files-port-not-connector.js +28 -0
  129. package/dist/check/rules/files-port-not-connector.js.map +1 -0
  130. package/dist/check/rules/persistence-no-file-content.d.ts +3 -0
  131. package/dist/check/rules/persistence-no-file-content.d.ts.map +1 -0
  132. package/dist/check/rules/persistence-no-file-content.js +14 -0
  133. package/dist/check/rules/persistence-no-file-content.js.map +1 -0
  134. package/dist/commands/docs.d.ts.map +1 -1
  135. package/dist/commands/docs.js +44 -11
  136. package/dist/commands/docs.js.map +1 -1
  137. package/dist/commands/format-context.d.ts.map +1 -1
  138. package/dist/commands/format-context.js +1 -1
  139. package/dist/commands/format-context.js.map +1 -1
  140. package/dist/commands/generate.js +2 -0
  141. package/dist/commands/generate.js.map +1 -1
  142. package/dist/commands/init.d.ts.map +1 -1
  143. package/dist/commands/init.js +1 -0
  144. package/dist/commands/init.js.map +1 -1
  145. package/dist/config/index.d.ts +1 -1
  146. package/dist/config/index.d.ts.map +1 -1
  147. package/dist/config/index.js +1 -1
  148. package/dist/config/index.js.map +1 -1
  149. package/dist/config/parse-stack.d.ts.map +1 -1
  150. package/dist/config/parse-stack.js +2 -1
  151. package/dist/config/parse-stack.js.map +1 -1
  152. package/dist/config/stack.d.ts +8 -0
  153. package/dist/config/stack.d.ts.map +1 -1
  154. package/dist/config/stack.js +1 -0
  155. package/dist/config/stack.js.map +1 -1
  156. package/dist/describe/context-description.d.ts +2 -0
  157. package/dist/describe/context-description.d.ts.map +1 -1
  158. package/dist/describe/describe-context.js +1 -0
  159. package/dist/describe/describe-context.js.map +1 -1
  160. package/dist/describe/format-description.d.ts.map +1 -1
  161. package/dist/describe/format-description.js +4 -1
  162. package/dist/describe/format-description.js.map +1 -1
  163. package/dist/docs/context-facts.d.ts +2 -0
  164. package/dist/docs/context-facts.d.ts.map +1 -1
  165. package/dist/docs/declared-stored-events.d.ts +9 -0
  166. package/dist/docs/declared-stored-events.d.ts.map +1 -0
  167. package/dist/docs/declared-stored-events.js +22 -0
  168. package/dist/docs/declared-stored-events.js.map +1 -0
  169. package/dist/docs/read-context.js +10 -0
  170. package/dist/docs/read-context.js.map +1 -1
  171. package/dist/docs/refresh-context-doc.js +1 -1
  172. package/dist/docs/refresh-context-doc.js.map +1 -1
  173. package/dist/docs/unrecorded-stored-events.d.ts +9 -0
  174. package/dist/docs/unrecorded-stored-events.d.ts.map +1 -0
  175. package/dist/docs/unrecorded-stored-events.js +17 -0
  176. package/dist/docs/unrecorded-stored-events.js.map +1 -0
  177. package/dist/docs/write-docs.d.ts +1 -2
  178. package/dist/docs/write-docs.d.ts.map +1 -1
  179. package/dist/docs/write-docs.js +1 -2
  180. package/dist/docs/write-docs.js.map +1 -1
  181. package/dist/docs/write-stored-events-lock.d.ts +12 -0
  182. package/dist/docs/write-stored-events-lock.d.ts.map +1 -0
  183. package/dist/docs/write-stored-events-lock.js +41 -0
  184. package/dist/docs/write-stored-events-lock.js.map +1 -0
  185. package/dist/generate/event-names.d.ts +2 -0
  186. package/dist/generate/event-names.d.ts.map +1 -1
  187. package/dist/generate/event-names.js +1 -0
  188. package/dist/generate/event-names.js.map +1 -1
  189. package/dist/generate/kind.d.ts +2 -0
  190. package/dist/generate/kind.d.ts.map +1 -1
  191. package/dist/generate/kinds/aggregate-kind.d.ts.map +1 -1
  192. package/dist/generate/kinds/aggregate-kind.js +8 -2
  193. package/dist/generate/kinds/aggregate-kind.js.map +1 -1
  194. package/dist/generate/kinds/domain-event-kind.d.ts.map +1 -1
  195. package/dist/generate/kinds/domain-event-kind.js +5 -2
  196. package/dist/generate/kinds/domain-event-kind.js.map +1 -1
  197. package/dist/generate/kinds/event-vars.d.ts.map +1 -1
  198. package/dist/generate/kinds/event-vars.js +6 -1
  199. package/dist/generate/kinds/event-vars.js.map +1 -1
  200. package/dist/generate/kinds/extend-event-sourced-aggregate.d.ts +9 -0
  201. package/dist/generate/kinds/extend-event-sourced-aggregate.d.ts.map +1 -0
  202. package/dist/generate/kinds/extend-event-sourced-aggregate.js +67 -0
  203. package/dist/generate/kinds/extend-event-sourced-aggregate.js.map +1 -0
  204. package/dist/generate/kinds/file-upload/write-upload-controller.d.ts +5 -0
  205. package/dist/generate/kinds/file-upload/write-upload-controller.d.ts.map +1 -0
  206. package/dist/generate/kinds/file-upload/write-upload-controller.js +42 -0
  207. package/dist/generate/kinds/file-upload/write-upload-controller.js.map +1 -0
  208. package/dist/generate/kinds/file-upload-kind.d.ts +3 -0
  209. package/dist/generate/kinds/file-upload-kind.d.ts.map +1 -0
  210. package/dist/generate/kinds/file-upload-kind.js +55 -0
  211. package/dist/generate/kinds/file-upload-kind.js.map +1 -0
  212. package/dist/generate/kinds/write-event-sourced-aggregate.d.ts +8 -0
  213. package/dist/generate/kinds/write-event-sourced-aggregate.d.ts.map +1 -0
  214. package/dist/generate/kinds/write-event-sourced-aggregate.js +24 -0
  215. package/dist/generate/kinds/write-event-sourced-aggregate.js.map +1 -0
  216. package/dist/generate/kinds.d.ts.map +1 -1
  217. package/dist/generate/kinds.js +2 -0
  218. package/dist/generate/kinds.js.map +1 -1
  219. package/dist/help/notes.d.ts +1 -1
  220. package/dist/help/notes.d.ts.map +1 -1
  221. package/dist/help/notes.js +3 -0
  222. package/dist/help/notes.js.map +1 -1
  223. package/dist/help/usage.d.ts +1 -1
  224. package/dist/help/usage.d.ts.map +1 -1
  225. package/dist/help/usage.js +3 -2
  226. package/dist/help/usage.js.map +1 -1
  227. package/dist/init/files/platform-files.d.ts.map +1 -1
  228. package/dist/init/files/platform-files.js +22 -0
  229. package/dist/init/files/platform-files.js.map +1 -1
  230. package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
  231. package/dist/init/manifest/dependencies-for.js +7 -1
  232. package/dist/init/manifest/dependencies-for.js.map +1 -1
  233. package/dist/init/manifest/versions.d.ts.map +1 -1
  234. package/dist/init/manifest/versions.js +28 -23
  235. package/dist/init/manifest/versions.js.map +1 -1
  236. package/dist/init/stack/resolve-stack.d.ts.map +1 -1
  237. package/dist/init/stack/resolve-stack.js +11 -2
  238. package/dist/init/stack/resolve-stack.js.map +1 -1
  239. package/dist/init/stack/stack-options.d.ts +1 -0
  240. package/dist/init/stack/stack-options.d.ts.map +1 -1
  241. package/dist/init/template-vars.d.ts.map +1 -1
  242. package/dist/init/template-vars.js +3 -2
  243. package/dist/init/template-vars.js.map +1 -1
  244. package/dist/naming/index.d.ts +2 -0
  245. package/dist/naming/index.d.ts.map +1 -1
  246. package/dist/naming/index.js +2 -0
  247. package/dist/naming/index.js.map +1 -1
  248. package/dist/naming/is-past-fact.d.ts +7 -0
  249. package/dist/naming/is-past-fact.d.ts.map +1 -0
  250. package/dist/naming/is-past-fact.js +18 -0
  251. package/dist/naming/is-past-fact.js.map +1 -0
  252. package/dist/naming/is-past-word.d.ts +3 -0
  253. package/dist/naming/is-past-word.d.ts.map +1 -0
  254. package/dist/naming/is-past-word.js +113 -0
  255. package/dist/naming/is-past-word.js.map +1 -0
  256. package/dist/naming/looks-like-past-fact.d.ts +1 -1
  257. package/dist/naming/looks-like-past-fact.d.ts.map +1 -1
  258. package/dist/naming/looks-like-past-fact.js +3 -66
  259. package/dist/naming/looks-like-past-fact.js.map +1 -1
  260. package/dist/stack/files-vars.d.ts +5 -0
  261. package/dist/stack/files-vars.d.ts.map +1 -0
  262. package/dist/stack/files-vars.js +11 -0
  263. package/dist/stack/files-vars.js.map +1 -0
  264. package/dist/stack/stack-vars.d.ts.map +1 -1
  265. package/dist/stack/stack-vars.js +13 -4
  266. package/dist/stack/stack-vars.js.map +1 -1
  267. package/dist/version.d.ts +1 -1
  268. package/dist/version.d.ts.map +1 -1
  269. package/dist/version.js +1 -1
  270. package/dist/version.js.map +1 -1
  271. package/package.json +3 -3
  272. package/templates/aggregate/event-sourced.aggregate.spec.ts.tpl +26 -0
  273. package/templates/aggregate/event-sourced.aggregate.ts.tpl +61 -0
  274. package/templates/aggregate/event-sourced.events.mapper.ts.tpl +15 -0
  275. package/templates/builder/event-sourced.builder.ts.tpl +36 -0
  276. package/templates/file-upload/command.ts.tpl +41 -0
  277. package/templates/file-upload/controller.spec.ts.tpl +46 -0
  278. package/templates/file-upload/controller.ts.tpl +23 -0
  279. package/templates/file-upload/handler.declared.ts.tpl +18 -0
  280. package/templates/file-upload/handler.spec.ts.tpl +79 -0
  281. package/templates/file-upload/handler.ts.tpl +16 -0
  282. package/templates/file-upload/wiring.manual.tpl +9 -0
  283. package/templates/file-upload/wiring.tsyringe.tpl +7 -0
  284. package/templates/init/CLAUDE.md.tpl +1 -1
  285. package/templates/init/README.md.tpl +22 -0
  286. package/templates/init/docker/docker-compose.yml.tpl +25 -0
  287. package/templates/init/docker/env.example.tpl +21 -0
  288. package/templates/init/gitignore.tpl +3 -0
  289. package/templates/init/main.ts.tpl +6 -0
  290. package/templates/init/platform/auth/http-boundary.ts.tpl +25 -1
  291. package/templates/init/platform/buses/create-command-bus.ts.tpl +7 -1
  292. package/templates/init/platform/compose-application.manual.ts.tpl +25 -0
  293. package/templates/init/platform/compose-application.tsyringe.ts.tpl +31 -0
  294. package/templates/init/platform/config/app-config.ts.tpl +7 -0
  295. package/templates/init/platform/config/load-config.ts.tpl +9 -0
  296. package/templates/init/platform/config/read-files.local.ts.tpl +39 -0
  297. package/templates/init/platform/config/read-files.s3.ts.tpl +42 -0
  298. package/templates/init/platform/create-platform.manual.ts.tpl +38 -1
  299. package/templates/init/platform/files/bind-files.tsyringe.ts.tpl +32 -0
  300. package/templates/init/platform/files/create-files.ts.tpl +34 -0
  301. package/templates/init/platform/files/file-routes.ts.tpl +10 -0
  302. package/templates/init/platform/files/files.module.tsyringe.ts.tpl +18 -0
  303. package/templates/init/platform/files/open-files.local.ts.tpl +13 -0
  304. package/templates/init/platform/files/open-files.s3.ts.tpl +10 -0
  305. package/templates/init/platform/files/staging-uploads.tsyringe.ts.tpl +11 -0
  306. package/templates/init/platform/http/start-http-server.express.ts.tpl +5 -1
  307. package/templates/init/platform/http/start-http-server.fastify.ts.tpl +4 -1
  308. package/templates/init/platform/http/start-http-server.nest.ts.tpl +12 -1
  309. package/templates/init/platform/platform-test.module.tsyringe.ts.tpl +11 -0
  310. package/templates/init/platform/platform.manual.ts.tpl +7 -0
  311. package/templates/init/rules/application.md.tpl +4 -0
  312. package/templates/init/rules/domain.md.tpl +1 -0
  313. package/templates/init/rules/infrastructure.md.tpl +2 -0
  314. package/templates/init/rules/platform.md.tpl +3 -0
  315. package/templates/pipeline/package-scripts.json +1 -1
  316. package/templates/service/main.ts.tpl +6 -0
  317. package/templates/worker/main.ts.tpl +6 -0
@@ -38,11 +38,17 @@ import {
38
38
  {{#if http.any}}
39
39
  ExecutionScope,
40
40
  {{/if}}
41
+ {{#if files.http}}
42
+ FileStorage,
43
+ {{/if}}
41
44
  {{#if audit.on}}
42
45
  {{#if http.any}}
43
46
  IdGenerator,
44
47
  {{/if}}
45
48
  {{/if}}
49
+ {{#if files.any}}
50
+ InMemoryFileStorage,
51
+ {{/if}}
46
52
  {{#unless broker.external}}
47
53
  IntegrationEventSubscriber,
48
54
  {{/unless}}
@@ -55,6 +61,11 @@ import {
55
61
  RateLimiter,
56
62
  {{/if}}
57
63
  scopedPublisher,
64
+ {{#if files.any}}
65
+ {{#unless files.http}}
66
+ type FileStorage,
67
+ {{/unless}}
68
+ {{/if}}
58
69
  type IntegrationEventPublisher,
59
70
  {{#if broker.external}}
60
71
  type IntegrationEventSubscriber,
@@ -86,6 +97,12 @@ import { relateSystemActors } from '{{alias.platform}}/auth/relate-system-actors
86
97
  import { createCommandBus } from '{{alias.platform}}/buses/create-command-bus{{alias.ext}}';
87
98
  import { createQueryBus } from '{{alias.platform}}/buses/create-query-bus{{alias.ext}}';
88
99
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
100
+ {{#if files.http}}
101
+ import { fileRoutes } from '{{alias.platform}}/files/file-routes{{alias.ext}}';
102
+ {{/if}}
103
+ {{#if files.any}}
104
+ import { filesModule } from '{{alias.platform}}/files/files.module{{alias.ext}}';
105
+ {{/if}}
89
106
  import { layFoundations, type Foundations } from '{{alias.platform}}/lay-foundations{{alias.ext}}';
90
107
  import { platformModule, type PlatformOptions } from '{{alias.platform}}/platform.module{{alias.ext}}';
91
108
  // ddd-ts-kit:imports
@@ -94,6 +111,10 @@ import { platformModule, type PlatformOptions } from '{{alias.platform}}/platfor
94
111
  export interface ApplicationOptions extends PlatformOptions {
95
112
  /** Whether this process runs the scheduled jobs, and their settings; left out (the tools, the tests), no job runs by time. */
96
113
  readonly jobs?: JobsOptions;
114
+ {{#if files.any}}
115
+ /** Where the content of files lives: the storage of `main.ts`; left out (the tools, the tests), the memory of the process. */
116
+ readonly files?: FileStorage;
117
+ {{/if}}
97
118
  }
98
119
 
99
120
  export interface Application {
@@ -102,6 +123,10 @@ export interface Application {
102
123
  /** Authenticates every request and runs it inside the execution scope. */
103
124
  readonly boundary: HttpBoundary;
104
125
  {{/if}}
126
+ {{#if files.http}}
127
+ /** The routes that answer the signed links of a storage the application serves itself; mounted before any body parser. */
128
+ readonly fileRoutes: readonly Route[];
129
+ {{/if}}
105
130
  {{#unless http.any}}
106
131
  readonly routes: readonly never[];
107
132
  {{/unless}}
@@ -170,6 +195,9 @@ export function composeApplication(
170
195
  guard,
171
196
  {{#if audit.on}}
172
197
  auditModule(foundations.audit),
198
+ {{/if}}
199
+ {{#if files.any}}
200
+ filesModule(options.files ?? new InMemoryFileStorage()),
173
201
  {{/if}}
174
202
  ...contexts.modules,
175
203
  ],
@@ -254,6 +282,9 @@ function running(container: Container, options: ApplicationOptions, contexts: Co
254
282
  {{#unless http.any}}
255
283
  routes: [],
256
284
  {{/unless}}
285
+ {{#if files.http}}
286
+ fileRoutes: fileRoutes(container.resolve(FileStorage)),
287
+ {{/if}}
257
288
  // What the outbox relay delivers with: each publication continues the trace stored with its event.
258
289
  eventBus: tracedPublisher(container.resolve(EventBus)),
259
290
  {{#if broker.external}}
@@ -5,6 +5,9 @@ import type { LogLevel, RateLimit } from '@ddd-ts-kit/kernel';
5
5
  import type { LogLevel } from '@ddd-ts-kit/kernel';
6
6
  {{/unless}}
7
7
  import type { ResilienceSettings } from '{{alias.platform}}/resilience/resilience-settings{{alias.ext}}';
8
+ {{#if files.any}}
9
+ import type { FilesConfig } from '{{alias.platform}}/config/read-files{{alias.ext}}';
10
+ {{/if}}
8
11
  import type { TracingConfig } from '{{alias.platform}}/config/read-tracing{{alias.ext}}';
9
12
 
10
13
  /** The validated configuration of the process: `loadConfig` is the only reader of the environment. */
@@ -49,6 +52,10 @@ export interface AppConfig {
49
52
  /** Where unexpected failures are reported: a Sentry or a GlitchTip project. Without a DSN nothing is reported. */
50
53
  readonly errorReporting: ErrorReportingConfig;
51
54
  {{/if}}
55
+ {{#if files.any}}
56
+ /** Where the content of files lives (`files/open-files.ts`), never in the database. */
57
+ readonly files: FilesConfig;
58
+ {{/if}}
52
59
  }
53
60
 
54
61
  /** `LOG_LEVEL`, `LOG_FORMAT` and `LOG_SCRUB_MESSAGES`. */
@@ -1,6 +1,9 @@
1
1
  import { LOG_LEVELS, type LogLevel } from '@ddd-ts-kit/kernel';
2
2
  import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
3
3
  import { ConfigError } from '{{alias.platform}}/config/config-error{{alias.ext}}';
4
+ {{#if files.any}}
5
+ import { readFiles } from '{{alias.platform}}/config/read-files{{alias.ext}}';
6
+ {{/if}}
4
7
  import { readTracing } from '{{alias.platform}}/config/read-tracing{{alias.ext}}';
5
8
 
6
9
  const environments = ['development', 'test', 'production'] as const;
@@ -65,6 +68,12 @@ export function loadConfig(env: Variables): AppConfig {
65
68
  {{#if errors.sentry}}
66
69
  errorReporting: readErrorReporting(env, environment, problems),
67
70
  {{/if}}
71
+ {{#if files.local}}
72
+ files: readFiles(env, environment, problems),
73
+ {{/if}}
74
+ {{#if files.s3}}
75
+ files: readFiles(env, problems),
76
+ {{/if}}
68
77
  };
69
78
 
70
79
  if (problems.length > 0) {
@@ -0,0 +1,39 @@
1
+ type Variables = Readonly<Record<string, string | undefined>>;
2
+
3
+ /** Where the local storage keeps the content of files, and how a client reaches its signed links. */
4
+ export interface FilesConfig {
5
+ /** `FILES_DIRECTORY`: a directory out of version control. Default `.data/files`. */
6
+ readonly directory: string;
7
+ /** `FILES_PUBLIC_URL`: where the routes that answer the signed links are reached. Required in production; elsewhere `http://localhost:<PORT>/files` by default. */
8
+ readonly publicUrl: string;
9
+ /** `FILES_SIGNING_SECRET`: signs the links, 32 characters at least. Required in production; left out elsewhere, one is drawn at each start. */
10
+ readonly signingSecret?: string;
11
+ }
12
+
13
+ /** The settings of the local file storage; a problem is reported by variable name only, never by value. */
14
+ export function readFiles(env: Variables, environment: string, problems: string[]): FilesConfig {
15
+ const production = environment === 'production';
16
+ const signingSecret = (env['FILES_SIGNING_SECRET'] ?? '').trim();
17
+
18
+ if (signingSecret.length < 32 && (signingSecret !== '' || production)) {
19
+ problems.push('FILES_SIGNING_SECRET must hold 32 characters at least, and is required in production');
20
+ }
21
+
22
+ return {
23
+ directory: env['FILES_DIRECTORY'] ?? '.data/files',
24
+ publicUrl: publicUrlOf(env, production, problems),
25
+ ...(signingSecret === '' ? {} : { signingSecret }),
26
+ };
27
+ }
28
+
29
+ /** Left to its default in production, every signed link would point at localhost. */
30
+ function publicUrlOf(env: Variables, production: boolean, problems: string[]): string {
31
+ const given = env['FILES_PUBLIC_URL'];
32
+ const publicUrl = given ?? `http://localhost:${env['PORT'] ?? '3000'}/files`;
33
+
34
+ if (!URL.canParse(publicUrl) || (production && given === undefined)) {
35
+ problems.push('FILES_PUBLIC_URL must be a URL, and is required in production');
36
+ }
37
+
38
+ return publicUrl;
39
+ }
@@ -0,0 +1,42 @@
1
+ type Variables = Readonly<Record<string, string | undefined>>;
2
+
3
+ /** The bucket that holds the content of files, on any provider of the S3 protocol. */
4
+ export interface FilesConfig {
5
+ /** `S3_ENDPOINT`: empty for AWS; MinIO of the compose stack `http://localhost:9000`; OVHcloud, Scaleway or R2 their own. */
6
+ readonly endpoint?: string;
7
+ /** `S3_REGION`: `us-east-1` by default, `auto` for Cloudflare R2. */
8
+ readonly region: string;
9
+ /** `S3_BUCKET`: created by the infrastructure code of the deployment, by the compose stack in development. */
10
+ readonly bucket: string;
11
+ /** `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY`: an access key allowed on this bucket only. */
12
+ readonly accessKeyId: string;
13
+ readonly secretAccessKey: string;
14
+ }
15
+
16
+ /** The settings of the S3 file storage; a problem is reported by variable name only, never by value. */
17
+ export function readFiles(env: Variables, problems: string[]): FilesConfig {
18
+ const endpoint = (env['S3_ENDPOINT'] ?? '').trim();
19
+ const region = (env['S3_REGION'] ?? '').trim();
20
+
21
+ if (endpoint !== '' && !URL.canParse(endpoint)) {
22
+ problems.push('S3_ENDPOINT must be a URL, or empty for AWS');
23
+ }
24
+
25
+ return {
26
+ ...(endpoint === '' ? {} : { endpoint }),
27
+ region: region === '' ? 'us-east-1' : region,
28
+ bucket: requiredText(env, 'S3_BUCKET', problems),
29
+ accessKeyId: requiredText(env, 'S3_ACCESS_KEY_ID', problems),
30
+ secretAccessKey: requiredText(env, 'S3_SECRET_ACCESS_KEY', problems),
31
+ };
32
+ }
33
+
34
+ function requiredText(env: Variables, name: string, problems: string[]): string {
35
+ const value = (env[name] ?? '').trim();
36
+
37
+ if (value === '') {
38
+ problems.push(name + ' must be set');
39
+ }
40
+
41
+ return value;
42
+ }
@@ -8,6 +8,9 @@ import {
8
8
  InMemoryCache,
9
9
  InMemoryCommandBus,
10
10
  InMemoryDomainEventDispatcher,
11
+ {{#if files.any}}
12
+ InMemoryFileStorage,
13
+ {{/if}}
11
14
  InMemoryLock,
12
15
  InMemoryQueryBus,
13
16
  {{#if cache.rateLimit}}
@@ -19,6 +22,9 @@ import {
19
22
  UuidGenerator,
20
23
  {{#if errors.sentry}}
21
24
  errorReportingMiddleware,
25
+ {{/if}}
26
+ {{#if files.any}}
27
+ fileUploadsMiddleware,
22
28
  {{/if}}
23
29
  scopedPublisher,
24
30
  dispatchingOnSave,
@@ -28,6 +34,9 @@ import {
28
34
  type DomainEventDispatcher,
29
35
  {{#if errors.sentry}}
30
36
  type ErrorReporter,
37
+ {{/if}}
38
+ {{#if files.any}}
39
+ type FileStorage,
31
40
  {{/if}}
32
41
  type JobSettings,
33
42
  } from '@ddd-ts-kit/kernel';
@@ -58,6 +67,9 @@ import { logDecisions } from '{{alias.platform}}/auth/log-decisions{{alias.ext}}
58
67
  import { UseCaseProtection } from '{{alias.platform}}/auth/use-case-protection{{alias.ext}}';
59
68
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
60
69
  import type { EventProvider } from '{{alias.platform}}/events/event-provider{{alias.ext}}';
70
+ {{#if files.any}}
71
+ import { createFiles, type Files } from '{{alias.platform}}/files/create-files{{alias.ext}}';
72
+ {{/if}}
61
73
  import { ConfiguredJobScheduler } from '{{alias.platform}}/jobs/configured-job-scheduler{{alias.ext}}';
62
74
  import { createLogger, type LogSettings } from '{{alias.platform}}/observability/create-logger{{alias.ext}}';
63
75
  import { createMetrics } from '{{alias.platform}}/observability/create-metrics{{alias.ext}}';
@@ -96,6 +108,10 @@ export interface PlatformOptions {
96
108
  /** The Redis protocol server; left out, the cache, the lock and the limiter stay in the memory of the process. */
97
109
  readonly redis?: RedisServices;
98
110
  {{/if}}
111
+ {{#if files.any}}
112
+ /** Where the content of files lives: the storage of `main.ts`; left out (the tools, the tests), the memory of the process. */
113
+ readonly files?: FileStorage;
114
+ {{/if}}
99
115
  }
100
116
 
101
117
  /** Replacing a provider (another broker, another clock) happens here and nowhere else. */
@@ -121,13 +137,19 @@ export function createPlatform(persistence: Persistence, options: PlatformOption
121
137
  const protection = new UseCaseProtection(authorizer, onDecision);
122
138
  const adapter = adapterOf(options.resilience ?? defaultResilience, { traced, domainEvents });
123
139
  const observed = observing(foundations, protection.guard, traced.useCase);
140
+ {{#if files.any}}
141
+ const files = filesOf(options, foundations);
142
+ {{/if}}
124
143
 
125
144
  return {
126
145
  ...foundations,
127
146
  ...eventsOn(persistence, options, { scope, traced }),
128
- // Around every use case, outermost first: {{#if errors.sentry}}the report of an unexpected failure, {{/if}}its log entry, its measure, the permission, its span; a command then runs in the unit of work.
147
+ // Around every use case, outermost first: {{#if errors.sentry}}the report of an unexpected failure, {{/if}}its log entry, its measure, the permission, its span; a command then {{#if files.any}}has the file it carries staged, out of any transaction, and {{/if}}runs in the unit of work.
129
148
  commands: chain(new InMemoryCommandBus(), [
130
149
  ...observed,
150
+ {{#if files.any}}
151
+ fileUploadsMiddleware(() => files),
152
+ {{/if}}
131
153
  ...beforeTheTransaction(foundations, options),
132
154
  unitOfWorkMiddleware(persistence.unitOfWork),
133
155
  ]),
@@ -139,9 +161,24 @@ export function createPlatform(persistence: Persistence, options: PlatformOption
139
161
  adapter,
140
162
  selfGoverned: (instance, info) => adapter(ownPolicy()(instance, info), info),
141
163
  protection,
164
+ {{#if files.any}}
165
+ files,
166
+ {{/if}}
142
167
  };
143
168
  }
144
169
 
170
+ {{#if files.any}}
171
+ /** Where the content of files lives: the storage of `main.ts`; left out (the tools, the tests), the memory of the process. */
172
+ function filesOf(options: PlatformOptions, foundations: Foundations): Files {
173
+ {{#if errors.none}}
174
+ return createFiles(options.files ?? new InMemoryFileStorage(), { ...foundations, errors: new NoopErrorReporter() });
175
+ {{/if}}
176
+ {{#if errors.sentry}}
177
+ return createFiles(options.files ?? new InMemoryFileStorage(), foundations);
178
+ {{/if}}
179
+ }
180
+
181
+ {{/if}}
145
182
  /** What surrounds every use case on both buses, outermost first, before what each bus adds. */
146
183
  function observing(foundations: Foundations, guard: BusMiddleware, span: BusMiddleware): readonly BusMiddleware[] {
147
184
  {{#if errors.none}}
@@ -0,0 +1,32 @@
1
+ import type { ModuleBuilder } from '@ddd-ts-kit/di';
2
+ import {
3
+ AcceptEveryFileScanner,
4
+ Clock,
5
+ ErrorReporter,
6
+ ExecutionScope,
7
+ FileKeys,
8
+ FileScanner,
9
+ FileStaging,
10
+ FileStorage,
11
+ IdGenerator,
12
+ TenantFileKeys,
13
+ } from '@ddd-ts-kit/kernel';
14
+
15
+ /**
16
+ * The ports of files on a storage: the keys generated on the server, under the tenant when there
17
+ * is one, the scanner a file passes before it is accepted, and the staging that keeps the storage
18
+ * consistent with the database. The application and the handler specs bind them alike.
19
+ */
20
+ export function bindFiles(builder: ModuleBuilder, storage: FileStorage): void {
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.
23
+ builder.bind(FileScanner).toValue(new AcceptEveryFileScanner());
24
+
25
+ builder
26
+ .bind(FileKeys)
27
+ .toFactory((resolve) => new TenantFileKeys(resolve(IdGenerator), resolve(Clock), resolve(ExecutionScope)));
28
+
29
+ builder
30
+ .bind(FileStaging)
31
+ .toFactory((resolve) => new FileStaging(resolve(FileStorage), resolve(FileScanner), resolve(ErrorReporter)));
32
+ }
@@ -0,0 +1,34 @@
1
+ import {
2
+ AcceptEveryFileScanner,
3
+ FileStaging,
4
+ TenantFileKeys,
5
+ type Clock,
6
+ type ErrorReporter,
7
+ type ExecutionScope,
8
+ type FileKeys,
9
+ type FileStorage,
10
+ type IdGenerator,
11
+ } from '@ddd-ts-kit/kernel';
12
+
13
+ /** Where files live, the keys they are stored under and the staging that keeps them consistent with the database. */
14
+ export interface Files {
15
+ readonly storage: FileStorage;
16
+ readonly keys: FileKeys;
17
+ readonly staging: FileStaging;
18
+ }
19
+
20
+ /** What files are built on: the foundations of the platform. */
21
+ interface Grounds {
22
+ readonly clock: Clock;
23
+ readonly ids: IdGenerator;
24
+ readonly scope: ExecutionScope;
25
+ readonly errors: ErrorReporter;
26
+ }
27
+
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
+ 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.
31
+ const staging = new FileStaging(storage, new AcceptEveryFileScanner(), errors);
32
+
33
+ return { storage, keys: new TenantFileKeys(ids, clock, scope), staging };
34
+ }
@@ -0,0 +1,10 @@
1
+ import { signedFileRoutes, type Route } from '@ddd-ts-kit/http';
2
+ import { ServedFileStorage, type FileStorage } from '@ddd-ts-kit/kernel';
3
+
4
+ /**
5
+ * The routes that answer the signed links of a storage the application serves itself: the local
6
+ * directory, or the memory of the tests. None for an object store, which answers its own links.
7
+ */
8
+ export function fileRoutes(storage: FileStorage): readonly Route[] {
9
+ return storage instanceof ServedFileStorage ? signedFileRoutes(storage) : [];
10
+ }
@@ -0,0 +1,18 @@
1
+ import { defineContextModule, type ContextModule } from '@ddd-ts-kit/di';
2
+ import { Clock, FileStaging, PurgeStagedFiles, type FileStorage } from '@ddd-ts-kit/kernel';
3
+ import { bindFiles } from '{{alias.platform}}/files/bind-files{{alias.ext}}';
4
+
5
+ /**
6
+ * Files as a capability of the platform: the storage `main.ts` opened (the memory of the process
7
+ * for the tools and the tests), its ports, and the hourly purge of what rolled-back commands left
8
+ * in `staging/`.
9
+ */
10
+ export function filesModule(storage: FileStorage): ContextModule {
11
+ return defineContextModule({
12
+ name: 'files',
13
+ register(builder) {
14
+ bindFiles(builder, storage);
15
+ builder.job('files.purge-staged', { every: '1h' }).handledBy(PurgeStagedFiles, [FileStaging, Clock]);
16
+ },
17
+ });
18
+ }
@@ -0,0 +1,13 @@
1
+ import { LocalFileStorage, type FileStorage } from '@ddd-ts-kit/kernel';
2
+ import type { FilesConfig } from '{{alias.platform}}/config/read-files{{alias.ext}}';
3
+
4
+ /**
5
+ * Where the content of files lives: a directory of this machine, never the database. The
6
+ * application answers its signed links itself, under `/files`. One machine only: before running
7
+ * several instances, move to an object store (`ddd-ts-kit init --force --storage s3`).
8
+ */
9
+ export function openFiles(config: FilesConfig): FileStorage {
10
+ const { directory, publicUrl, signingSecret } = config;
11
+
12
+ return new LocalFileStorage({ directory, baseUrl: publicUrl, ...(signingSecret === undefined ? {} : { secret: signingSecret }) });
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { FileStorage } from '@ddd-ts-kit/kernel';
2
+ import { S3FileStorage, s3ClientOf } from '@ddd-ts-kit/s3';
3
+ import type { FilesConfig } from '{{alias.platform}}/config/read-files{{alias.ext}}';
4
+
5
+ /** Where the content of files lives: a bucket of the S3 protocol, MinIO in the compose stack, never the database. */
6
+ export function openFiles(config: FilesConfig): FileStorage {
7
+ const { bucket, ...settings } = config;
8
+
9
+ return new S3FileStorage({ client: s3ClientOf(settings), bucket });
10
+ }
@@ -0,0 +1,11 @@
1
+ import type { Resolve } from '@ddd-ts-kit/di';
2
+ import { FileKeys, FileStaging, fileUploadsMiddleware, type BusMiddleware } from '@ddd-ts-kit/kernel';
3
+
4
+ /**
5
+ * Stages the file a command carries (a `FileUpload`), after the permission and before the
6
+ * transaction, so that no transaction waits while a client uploads. Resolved at each command
7
+ * that carries a file: building the bus opens nothing.
8
+ */
9
+ export function stagingUploads(resolve: Resolve): BusMiddleware {
10
+ return fileUploadsMiddleware(() => ({ keys: resolve(FileKeys), staging: resolve(FileStaging) }));
11
+ }
@@ -19,7 +19,7 @@ export interface HttpServer {
19
19
  }
20
20
 
21
21
  /** 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}}>;
22
+ type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}{{#if files.http}} | 'fileRoutes'{{/if}}>;
23
23
 
24
24
  export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
25
25
  const app = express();
@@ -27,6 +27,10 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
27
27
  app.disable('x-powered-by');
28
28
  {{#if cache.rateLimit}}
29
29
  guardTheDoor(app, served, config);
30
+ {{/if}}
31
+ {{#if files.http}}
32
+ // Before the JSON parser, which would read first a JSON file sent through a signed link.
33
+ mountExpress(app, served.fileRoutes, served.boundary);
30
34
  {{/if}}
31
35
  app.use(express.json());
32
36
  {{#if docs.any}}
@@ -17,7 +17,7 @@ export interface HttpServer {
17
17
  }
18
18
 
19
19
  /** What the server needs of the application: its routes and what stands at its edge. */
20
- type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}>;
20
+ type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}{{#if files.http}} | 'fileRoutes'{{/if}}>;
21
21
 
22
22
  export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
23
23
  const app = Fastify();
@@ -25,6 +25,9 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
25
25
  {{#if cache.rateLimit}}
26
26
  guardTheDoor(app, served, config);
27
27
  {{/if}}
28
+ {{#if files.http}}
29
+ mountFastify(app, served.fileRoutes, served.boundary);
30
+ {{/if}}
28
31
  {{#if docs.any}}
29
32
  mountFastify(app, withDocumentation(served.routes, config), served.boundary);
30
33
  {{/if}}
@@ -19,7 +19,7 @@ export interface HttpServer {
19
19
  }
20
20
 
21
21
  /** 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}}>;
22
+ type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}{{#if files.http}} | 'fileRoutes'{{/if}}>;
23
23
  {{#if cache.rateLimit}}
24
24
 
25
25
  /** The part of the incoming request and of its response the limiter and the probe need, whatever Nest runs on. */
@@ -36,6 +36,16 @@ interface Outgoing {
36
36
  {{/if}}
37
37
 
38
38
  export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
39
+ {{#if files.http}}
40
+ {{#if docs.any}}
41
+ const routes = [...withDocumentation(served.routes, config), ...served.fileRoutes];
42
+ {{/if}}
43
+ {{#unless docs.any}}
44
+ const routes = [...served.routes, ...served.fileRoutes];
45
+ {{/unless}}
46
+ const app = await NestFactory.create(createAppModule(routes, served.boundary), { logger: ['error', 'warn'] });
47
+ {{/if}}
48
+ {{#unless files.http}}
39
49
  {{#if docs.any}}
40
50
  const app = await NestFactory.create(createAppModule(withDocumentation(served.routes, config), served.boundary), {
41
51
  logger: ['error', 'warn'],
@@ -44,6 +54,7 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
44
54
  {{#unless docs.any}}
45
55
  const app = await NestFactory.create(createAppModule(served.routes, served.boundary), { logger: ['error', 'warn'] });
46
56
  {{/unless}}
57
+ {{/unless}}
47
58
 
48
59
  {{#if cache.rateLimit}}
49
60
  app.use(
@@ -1,10 +1,16 @@
1
1
  import { defineContextModule } from '@ddd-ts-kit/di';
2
+ {{#if files.any}}
3
+ import { InMemoryFileStorage } from '@ddd-ts-kit/kernel';
4
+ {{/if}}
2
5
  {{#if persistence.packagedToken}}
3
6
  import { {{persistence.token}} } from '{{persistence.tokenPackage}}';
4
7
  {{/if}}
5
8
  {{#if persistence.ownDatabase}}
6
9
  import { Database } from '{{alias.platform}}/database/database{{alias.ext}}';
7
10
  {{/if}}
11
+ {{#if files.any}}
12
+ import { bindFiles } from '{{alias.platform}}/files/bind-files{{alias.ext}}';
13
+ {{/if}}
8
14
  // ddd-ts-kit:imports
9
15
  // /ddd-ts-kit:imports
10
16
 
@@ -17,6 +23,11 @@ export const platformTestModule = defineContextModule({
17
23
  throw new Error('A handler spec has no database: give a fake for the repository it uses.');
18
24
  });
19
25
 
26
+ {{/if}}
27
+ {{#if files.any}}
28
+ // The files a handler spec stores stay in the memory of the test.
29
+ bindFiles(builder, new InMemoryFileStorage());
30
+
20
31
  {{/if}}
21
32
  // ddd-ts-kit:test-bindings
22
33
  // /ddd-ts-kit:test-bindings
@@ -26,6 +26,9 @@ import type { Audit } from '{{alias.platform}}/audit/create-audit{{alias.ext}}';
26
26
  {{/if}}
27
27
  import type { UseCaseProtection } from '{{alias.platform}}/auth/use-case-protection{{alias.ext}}';
28
28
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
29
+ {{#if files.any}}
30
+ import type { Files } from '{{alias.platform}}/files/create-files{{alias.ext}}';
31
+ {{/if}}
29
32
 
30
33
  /** Wraps an adapter from outside: a span for its kind and, for what leaves the process, the default policy unless it states its own. */
31
34
  type Adapt = <T extends object>(instance: T, info: AspectInfo) => T;
@@ -78,4 +81,8 @@ export interface Platform {
78
81
  {{#if audit.on}}
79
82
  readonly audit: Audit;
80
83
  {{/if}}
84
+ {{#if files.any}}
85
+ /** Where files live, the keys they are stored under and the staging that keeps them consistent with the database: never their content in a table. */
86
+ readonly files: Files;
87
+ {{/if}}
81
88
  }
@@ -8,6 +8,7 @@ paths:
8
8
  - Imports `domain/`, `application/`, published languages, `@ddd-ts-kit/kernel` and `@ddd-ts-kit/auth` only (`layer/application-inward`): never `infrastructure/`, `presentation/`, a framework or a driver.
9
9
  - One use case per folder, `commands/<use-case>/` or `queries/<use-case>/`: the message, its handler, a `*.result.ts` when the answer has a shape of its own. The handler has one public method, `execute` (`application/handler-shape`): it loads or builds, calls ONE intention method, `await repository.save(aggregate)`, and returns at most an identifier.
10
10
  - Events leave with the save: never `pullEvents()`, never a `DomainEventDispatcher` here (`domain-events/dispatched-on-save`). A reaction is a class of `event-handlers/` or a publisher of `integration/publishers/`. It runs at the end of the unit of work, before the commit, and depends only on what the transaction covers (`domain-events/transactional-before-commit`): repositories, the integration event publisher, the command bus. An effect outside the database is a handler of the `after-commit` phase (`generate event-handler ... --phase after-commit`: at most once, never saves, sends a command) or, when it must not be lost, the handler of an integration event.
11
+ - Nothing here reads the event store: an event-sourced aggregate is loaded and saved through its repository port like any other (`event-sourcing/store-behind-repository`). A projection writes its read model and never a stream (`event-sourcing/projection-never-appends`); one fed by the store is declared `@Projection(name, { feed: 'event-store' })`.
11
12
  {{#if style.declared}}
12
13
  - Every command and query carries `@Requires(permission)` or `@Public()` (`authz/declared`), and the actor is in the message (`authz/actor-explicit`). Permissions live in `authorization/<context>.permissions.ts`, rules that need loaded state in `authorization/*.policy.ts`.
13
14
  - The decorator is the registration (`declarations/role-declared`): `@CommandHandler(Message)`, `@QueryHandler(Message)`, `@DomainEventHandler(Event, { name })`, `@IntegrationEventHandler(definition, { consumer })`, `@Scheduled('<context>.<job>', schedule)`, `@Projection('<context>.<name>')`, `@Policy(permission, { name })`. Names are string literals.
@@ -25,6 +26,9 @@ paths:
25
26
  - A dependency list names port classes, imported as values, in the order of the constructor: never an adapter or a fake (`ports/value-import`, `ports/no-concrete-dependency`).
26
27
  {{/if}}
27
28
  - A job (`scheduling/*.job.ts`) and an integration event handler (`integration/handlers/`) only build one command and send it as a system actor; both are safe to repeat (`scheduling/job-triggers-use-case`, `events/consumer-idempotent`).
29
+ {{#if files.any}}
30
+ - A file arrives in the command as a `FileUpload` of its area, which the bus stages before the transaction under a key of `FileKeys` (never a name or a path from the user) and scans; the handler records `upload.file`, its `StoredFile`, on the aggregate and calls `FileStaging.promoteOnCommit`, which moves it to its key with the commit. A direct upload is confirmed from the `PendingUpload` the aggregate kept, never from a key the client sends. The ports are named here, never a connector (`files/port-not-connector`); `npx ddd-ts-kit generate file-upload` writes the slice.
31
+ {{/if}}
28
32
  - A query never saves, deletes or publishes (`application/command-query-separation`); it hands the access scope of the actor to its read port and never filters after loading.
29
33
  - A read that takes criteria, a scope or a page is a search, never a list (`naming/search-not-list`): `Search<Things>Query` in `queries/search-<things>/` (`generate query ... --search`), `search...` on the port, its adapters and its fakes; one element or none stays `findById` or `findBy...`.
30
34
  {{#if literals.named}}
@@ -28,6 +28,7 @@ paths:
28
28
  - A value object returns its refusals in the `Result` of `create`{{#if refusals.factories}}: `err(PersonError.invalidEmail(raw))`{{/if}}; the caller unwraps it with `unwrap(..)` of the kernel. `npx ddd-ts-kit value-objects` moves the project to factories that throw.
29
29
  {{/if}}
30
30
  - Domain events are named in the past tense, `<context>.<aggregate>.<fact>` (`events/name-format`), and recorded by the aggregate (`this.record(...)`). They leave with the save: nothing here dispatches them.
31
+ - An aggregate whose history is the business can be event-sourced, chosen per aggregate (`generate aggregate <context> <Name> --event-sourced`): it extends `EventSourcedAggregate`, a command checks the invariants then `this.record(...)`, and only its `apply<Fact>` methods (and `restore`, for a snapshot) change the state (`event-sourcing/state-in-apply`). Its events are named in the past tense (`event-sourcing/past-tense`). The other aggregates keep their state in tables.
31
32
  - A repository here is a port: an abstract class extending the kernel `Repository<Aggregate>`, abstract members only (`ports/abstract-class`). A domain service is stateless.
32
33
  - Time and identifiers come in as parameters (`purity/*`); nothing here knows the acting user or its rights (`authz/in-application`).
33
34
  - One concept per file, with the suffix of its role: `.aggregate.ts`, `.entity.ts`, `.vo.ts`, `.vocabulary.ts`, `.event.ts`, `.error.ts`, `.repository.ts`, `.service.ts` (`naming/suffix`, `naming/one-concept-per-file`).
@@ -8,6 +8,7 @@ paths:
8
8
  - An adapter `implements` a port of `application/ports/` or a repository port of `domain/repositories/`, and never `extends` it (`ports/implements-never-extends`). It never imports `presentation/` (`layer/infrastructure-no-presentation`).
9
9
  - `persistence/` holds repository adapters, mappers and rows, `external/` the adapters of outside systems, `anti-corruption/` the translators of another model.
10
10
  - 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`).
11
+ - 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`.
11
12
  - Own tables, in the schema of the context: no join, foreign key or transaction across contexts (`context/extractable`).
12
13
  - Audit columns and the tenant column are stamped from the execution scope with the kernel helpers (`stampCreation`, `stampUpdate`, `tenantScopeOf`), never handed over by a use case.
13
14
  {{#if tenancy.any}}
@@ -22,6 +23,7 @@ paths:
22
23
  - Retry, timeout and cache go on the binding (`ownPolicy(retry(...), timeout(...))`) or, when the policy is part of what the adapter is, as decorators of `@ddd-ts-kit/aspects/decorators` (`aspects/outside-in`). Kinds `external` and `gateway` get the default policy of the platform otherwise. `ownPolicy` is the helper of `{{alias.platform}}/resilience/own-policy{{alias.ext}}`, which `generate adapter` writes when the platform does not have it yet.
23
24
  {{/if}}
24
25
  - A repository only persists: no `pullEvents()`, no dispatcher (`domain-events/dispatched-on-save`). A removal that announces an event takes the aggregate, not its id.
26
+ - The repository adapter of an event-sourced aggregate delegates to `EventSourcedRepository` of the kernel. Its stored events are declared in `persistence/<aggregate>-events.mapper.ts` with `defineStoredEvent` and a named type of their data; a change of that type is a new version with its upcaster, never an edit (`event-sourcing/upcaster-required`, against `stored-events.lock.json`, which `ddd-ts-kit docs --stored-events` writes once the shape of a version is final; `docs --check` fails while a version is unrecorded). Every named type the data reaches is declared in the codec file too.
25
27
  - Infrastructure faults are plain errors (a 5xx, reported from outside); business refusals are `DomainError`s raised by the domain.
26
28
  - Every adapter passes the contract suite of the fake of its port (`test/integration/*.contract.spec.ts`).
27
29
  - Method: `/ddd-ts-kit:persistence`. Create with `npx ddd-ts-kit generate repository|adapter|gateway|acl ... --json`.
@@ -20,6 +20,9 @@ paths:
20
20
  - One `Platform` is built in `create-platform.ts` and handed to each context; a port or a value is typed by an abstract class. No token helper, no injection constant; one exported class, interface or function per file.
21
21
  - Cross-cutting behaviour lives here: spans through the members of `traceApplication()` (`create-platform.ts`), `around: tracedRoutes()` at the HTTP boundary and `tracedPublisher` for the outbox relay; logs, measures, permissions and audit as bus middlewares; the policy of outbound adapters in `resilience/`.
22
22
  {{/unless}}
23
+ {{#if files.any}}
24
+ - Files: `files/open-files.ts` opens the connector of `stack.storage` from `config/read-files.ts`{{#if di.tsyringe}}, `files/files.module.ts` binds the ports and the hourly purge of staged files, `files/staging-uploads.ts` stages the file a command carries on the command bus, before the transaction{{/if}}{{#unless di.tsyringe}}, `files/create-files.ts` builds them, `compose-application.ts` registers the hourly purge of staged files and `create-platform.ts` stages the file a command carries on the command bus, before the transaction{{/unless}}; the tools and the tests keep files in memory. A scanner of your own (an antivirus) is bound here, never called from a use case.
25
+ {{/if}}
23
26
  - `@ddd-ts-kit/tracing` and `@opentelemetry/*` are imported here and nowhere else (`tracing/platform-only`).
24
27
  - Logs, spans and error reports carry identifiers and codes only: never arguments, payloads, error messages, nor anything personal beyond the id of the actor.
25
28
  - Configuration is read here only, by `config/load-config.ts`: validated, fail fast, every problem named by its variable. A new variable joins `AppConfig` and `.env.example`. `RUN_JOBS` says whether a process runs the jobs, `job-settings.ts` what configuration changes of each.
@@ -23,7 +23,7 @@
23
23
  "@biomejs/biome": "2.5.15",
24
24
  "@commitlint/cli": "^21.2.3",
25
25
  "@commitlint/config-conventional": "^21.2.3",
26
- "@ddd-ts-kit/eslint-plugin": "^0.8.0",
26
+ "@ddd-ts-kit/eslint-plugin": "^0.10.0",
27
27
  "@eslint/js": "^10.0.1",
28
28
  "@typescript/native": "npm:typescript@~7.0.2",
29
29
  "@vitest/coverage-v8": "5.0.3",