ddd-ts-kit 0.100.0 → 0.102.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.fr.md +17 -10
  3. package/README.md +16 -9
  4. package/dist/build/emitted-place.d.ts +1 -2
  5. package/dist/build/emitted-place.d.ts.map +1 -1
  6. package/dist/build/emitted-specifier.d.ts +7 -1
  7. package/dist/build/emitted-specifier.d.ts.map +1 -1
  8. package/dist/build/emitted-specifier.js +5 -6
  9. package/dist/build/emitted-specifier.js.map +1 -1
  10. package/dist/build/emitted-target.d.ts +6 -5
  11. package/dist/build/emitted-target.d.ts.map +1 -1
  12. package/dist/build/emitted-target.js +5 -9
  13. package/dist/build/emitted-target.js.map +1 -1
  14. package/dist/build/rewrite-aliases.d.ts.map +1 -1
  15. package/dist/build/rewrite-aliases.js +4 -5
  16. package/dist/build/rewrite-aliases.js.map +1 -1
  17. package/dist/build/rewrite-specifiers.d.ts +7 -6
  18. package/dist/build/rewrite-specifiers.d.ts.map +1 -1
  19. package/dist/build/rewrite-specifiers.js +6 -4
  20. package/dist/build/rewrite-specifiers.js.map +1 -1
  21. package/dist/build/unresolved-problem.d.ts +2 -1
  22. package/dist/build/unresolved-problem.d.ts.map +1 -1
  23. package/dist/build/unresolved-problem.js +2 -2
  24. package/dist/build/unresolved-problem.js.map +1 -1
  25. package/dist/check/business-names/parameter-lists.js +1 -3
  26. package/dist/check/business-names/parameter-lists.js.map +1 -1
  27. package/dist/check/engine/run-check.d.ts +3 -0
  28. package/dist/check/engine/run-check.d.ts.map +1 -1
  29. package/dist/check/engine/run-check.js +1 -1
  30. package/dist/check/engine/run-check.js.map +1 -1
  31. package/dist/check/explain/tenancy-docs.d.ts.map +1 -1
  32. package/dist/check/explain/tenancy-docs.js +13 -3
  33. package/dist/check/explain/tenancy-docs.js.map +1 -1
  34. package/dist/check/fixtures/conjunct-cases.d.ts +11 -0
  35. package/dist/check/fixtures/conjunct-cases.d.ts.map +1 -0
  36. package/dist/check/fixtures/conjunct-cases.js +19 -0
  37. package/dist/check/fixtures/conjunct-cases.js.map +1 -0
  38. package/dist/check/fixtures/privacy-fixtures.d.ts.map +1 -1
  39. package/dist/check/fixtures/privacy-fixtures.js +22 -0
  40. package/dist/check/fixtures/privacy-fixtures.js.map +1 -1
  41. package/dist/check/fixtures/run-fixture.d.ts +3 -2
  42. package/dist/check/fixtures/run-fixture.d.ts.map +1 -1
  43. package/dist/check/fixtures/run-fixture.js +3 -3
  44. package/dist/check/fixtures/run-fixture.js.map +1 -1
  45. package/dist/check/fixtures/run-self-check.js +1 -1
  46. package/dist/check/fixtures/run-self-check.js.map +1 -1
  47. package/dist/check/fixtures/tenancy-conjunct-drizzle-fixtures.d.ts +3 -0
  48. package/dist/check/fixtures/tenancy-conjunct-drizzle-fixtures.d.ts.map +1 -0
  49. package/dist/check/fixtures/tenancy-conjunct-drizzle-fixtures.js +33 -0
  50. package/dist/check/fixtures/tenancy-conjunct-drizzle-fixtures.js.map +1 -0
  51. package/dist/check/fixtures/tenancy-conjunct-fixtures.d.ts +4 -0
  52. package/dist/check/fixtures/tenancy-conjunct-fixtures.d.ts.map +1 -0
  53. package/dist/check/fixtures/tenancy-conjunct-fixtures.js +12 -0
  54. package/dist/check/fixtures/tenancy-conjunct-fixtures.js.map +1 -0
  55. package/dist/check/fixtures/tenancy-conjunct-knex-fixtures.d.ts +3 -0
  56. package/dist/check/fixtures/tenancy-conjunct-knex-fixtures.d.ts.map +1 -0
  57. package/dist/check/fixtures/tenancy-conjunct-knex-fixtures.js +49 -0
  58. package/dist/check/fixtures/tenancy-conjunct-knex-fixtures.js.map +1 -0
  59. package/dist/check/fixtures/tenancy-conjunct-prisma-fixtures.d.ts +3 -0
  60. package/dist/check/fixtures/tenancy-conjunct-prisma-fixtures.d.ts.map +1 -0
  61. package/dist/check/fixtures/tenancy-conjunct-prisma-fixtures.js +32 -0
  62. package/dist/check/fixtures/tenancy-conjunct-prisma-fixtures.js.map +1 -0
  63. package/dist/check/fixtures/tenancy-conjunct-typeorm-fixtures.d.ts +3 -0
  64. package/dist/check/fixtures/tenancy-conjunct-typeorm-fixtures.d.ts.map +1 -0
  65. package/dist/check/fixtures/tenancy-conjunct-typeorm-fixtures.js +34 -0
  66. package/dist/check/fixtures/tenancy-conjunct-typeorm-fixtures.js.map +1 -0
  67. package/dist/check/fixtures/tenancy-fixtures.d.ts.map +1 -1
  68. package/dist/check/fixtures/tenancy-fixtures.js +2 -0
  69. package/dist/check/fixtures/tenancy-fixtures.js.map +1 -1
  70. package/dist/check/privacy/published-events-of.d.ts.map +1 -1
  71. package/dist/check/privacy/published-events-of.js +4 -2
  72. package/dist/check/privacy/published-events-of.js.map +1 -1
  73. package/dist/check/rules/clean-one-export-per-file.js +1 -0
  74. package/dist/check/rules/clean-one-export-per-file.js.map +1 -1
  75. package/dist/check/rules/schema-no-duplicate-shape.js +1 -3
  76. package/dist/check/rules/schema-no-duplicate-shape.js.map +1 -1
  77. package/dist/check/rules/tenancy-scoped-statement.js +2 -2
  78. package/dist/check/rules/tenancy-scoped-statement.js.map +1 -1
  79. package/dist/check/schemas/class-shapes.d.ts.map +1 -1
  80. package/dist/check/schemas/class-shapes.js +5 -26
  81. package/dist/check/schemas/class-shapes.js.map +1 -1
  82. package/dist/check/structure/class-statements.d.ts +13 -0
  83. package/dist/check/structure/class-statements.d.ts.map +1 -0
  84. package/dist/check/structure/class-statements.js +34 -0
  85. package/dist/check/structure/class-statements.js.map +1 -0
  86. package/dist/check/structure/property-of.d.ts +13 -0
  87. package/dist/check/structure/property-of.d.ts.map +1 -0
  88. package/dist/check/structure/property-of.js +23 -0
  89. package/dist/check/structure/property-of.js.map +1 -0
  90. package/dist/check/tenancy/arguments-of-call.d.ts +3 -0
  91. package/dist/check/tenancy/arguments-of-call.d.ts.map +1 -0
  92. package/dist/check/tenancy/arguments-of-call.js +11 -0
  93. package/dist/check/tenancy/arguments-of-call.js.map +1 -0
  94. package/dist/check/tenancy/bare-expression.d.ts +3 -0
  95. package/dist/check/tenancy/bare-expression.d.ts.map +1 -0
  96. package/dist/check/tenancy/bare-expression.js +9 -0
  97. package/dist/check/tenancy/bare-expression.js.map +1 -0
  98. package/dist/check/tenancy/bracket-depth.d.ts +3 -0
  99. package/dist/check/tenancy/bracket-depth.d.ts.map +1 -0
  100. package/dist/check/tenancy/bracket-depth.js +10 -0
  101. package/dist/check/tenancy/bracket-depth.js.map +1 -0
  102. package/dist/check/tenancy/chain-links.d.ts +17 -0
  103. package/dist/check/tenancy/chain-links.d.ts.map +1 -0
  104. package/dist/check/tenancy/chain-links.js +24 -0
  105. package/dist/check/tenancy/chain-links.js.map +1 -0
  106. package/dist/check/tenancy/choice-branches.d.ts +3 -0
  107. package/dist/check/tenancy/choice-branches.d.ts.map +1 -0
  108. package/dist/check/tenancy/choice-branches.js +39 -0
  109. package/dist/check/tenancy/choice-branches.js.map +1 -0
  110. package/dist/check/tenancy/declaration-before.d.ts +12 -0
  111. package/dist/check/tenancy/declaration-before.d.ts.map +1 -0
  112. package/dist/check/tenancy/declaration-before.js +11 -0
  113. package/dist/check/tenancy/declaration-before.js.map +1 -0
  114. package/dist/check/tenancy/declaration-of.d.ts +1 -5
  115. package/dist/check/tenancy/declaration-of.d.ts.map +1 -1
  116. package/dist/check/tenancy/declaration-of.js +3 -8
  117. package/dist/check/tenancy/declaration-of.js.map +1 -1
  118. package/dist/check/tenancy/drizzle-unscoped.d.ts.map +1 -1
  119. package/dist/check/tenancy/drizzle-unscoped.js +16 -3
  120. package/dist/check/tenancy/drizzle-unscoped.js.map +1 -1
  121. package/dist/check/tenancy/enclosed-by.d.ts +3 -0
  122. package/dist/check/tenancy/enclosed-by.d.ts.map +1 -0
  123. package/dist/check/tenancy/enclosed-by.js +6 -0
  124. package/dist/check/tenancy/enclosed-by.js.map +1 -0
  125. package/dist/check/tenancy/end-of-enclosing.d.ts +7 -0
  126. package/dist/check/tenancy/end-of-enclosing.d.ts.map +1 -0
  127. package/dist/check/tenancy/end-of-enclosing.js +18 -0
  128. package/dist/check/tenancy/end-of-enclosing.js.map +1 -0
  129. package/dist/check/tenancy/holds-condition.d.ts +14 -0
  130. package/dist/check/tenancy/holds-condition.d.ts.map +1 -0
  131. package/dist/check/tenancy/holds-condition.js +26 -0
  132. package/dist/check/tenancy/holds-condition.js.map +1 -0
  133. package/dist/check/tenancy/is-conjunct.d.ts +8 -0
  134. package/dist/check/tenancy/is-conjunct.d.ts.map +1 -0
  135. package/dist/check/tenancy/is-conjunct.js +17 -0
  136. package/dist/check/tenancy/is-conjunct.js.map +1 -0
  137. package/dist/check/tenancy/is-or-link.d.ts +4 -0
  138. package/dist/check/tenancy/is-or-link.d.ts.map +1 -0
  139. package/dist/check/tenancy/is-or-link.js +7 -0
  140. package/dist/check/tenancy/is-or-link.js.map +1 -0
  141. package/dist/check/tenancy/knex-links-outside-condition.d.ts +11 -0
  142. package/dist/check/tenancy/knex-links-outside-condition.d.ts.map +1 -0
  143. package/dist/check/tenancy/knex-links-outside-condition.js +108 -0
  144. package/dist/check/tenancy/knex-links-outside-condition.js.map +1 -0
  145. package/dist/check/tenancy/knex-unscoped.d.ts +3 -1
  146. package/dist/check/tenancy/knex-unscoped.d.ts.map +1 -1
  147. package/dist/check/tenancy/knex-unscoped.js +12 -2
  148. package/dist/check/tenancy/knex-unscoped.js.map +1 -1
  149. package/dist/check/tenancy/prisma-unscoped.d.ts.map +1 -1
  150. package/dist/check/tenancy/prisma-unscoped.js +15 -10
  151. package/dist/check/tenancy/prisma-unscoped.js.map +1 -1
  152. package/dist/check/tenancy/spreads-at-top.d.ts +9 -0
  153. package/dist/check/tenancy/spreads-at-top.d.ts.map +1 -0
  154. package/dist/check/tenancy/spreads-at-top.js +49 -0
  155. package/dist/check/tenancy/spreads-at-top.js.map +1 -0
  156. package/dist/check/tenancy/top-level-parts.d.ts +3 -0
  157. package/dist/check/tenancy/top-level-parts.d.ts.map +1 -0
  158. package/dist/check/tenancy/top-level-parts.js +13 -0
  159. package/dist/check/tenancy/top-level-parts.js.map +1 -0
  160. package/dist/check/tenancy/typeorm-unscoped.d.ts.map +1 -1
  161. package/dist/check/tenancy/typeorm-unscoped.js +30 -16
  162. package/dist/check/tenancy/typeorm-unscoped.js.map +1 -1
  163. package/dist/check/tenancy/unconfined-where.d.ts +11 -0
  164. package/dist/check/tenancy/unconfined-where.d.ts.map +1 -0
  165. package/dist/check/tenancy/unconfined-where.js +18 -0
  166. package/dist/check/tenancy/unconfined-where.js.map +1 -0
  167. package/dist/config/read-config.d.ts.map +1 -1
  168. package/dist/config/read-config.js +20 -0
  169. package/dist/config/read-config.js.map +1 -1
  170. package/dist/declared/render-declarations.js +1 -3
  171. package/dist/declared/render-declarations.js.map +1 -1
  172. package/dist/describe/read-controllers.d.ts.map +1 -1
  173. package/dist/describe/read-controllers.js +18 -2
  174. package/dist/describe/read-controllers.js.map +1 -1
  175. package/dist/describe/read-event-definitions.d.ts +2 -0
  176. package/dist/describe/read-event-definitions.d.ts.map +1 -1
  177. package/dist/describe/read-event-definitions.js +1 -0
  178. package/dist/describe/read-event-definitions.js.map +1 -1
  179. package/dist/describe/schema-class-of.js +8 -1
  180. package/dist/describe/schema-class-of.js.map +1 -1
  181. package/dist/digest/tree-at.d.ts.map +1 -1
  182. package/dist/digest/tree-at.js +2 -0
  183. package/dist/digest/tree-at.js.map +1 -1
  184. package/dist/docs/context-sections.js +3 -7
  185. package/dist/docs/context-sections.js.map +1 -1
  186. package/dist/docs/personal-event-lines.d.ts +7 -0
  187. package/dist/docs/personal-event-lines.d.ts.map +1 -0
  188. package/dist/docs/personal-event-lines.js +34 -0
  189. package/dist/docs/personal-event-lines.js.map +1 -0
  190. package/dist/docs/write-docs.d.ts.map +1 -1
  191. package/dist/docs/write-docs.js +2 -0
  192. package/dist/docs/write-docs.js.map +1 -1
  193. package/dist/docs/write-personal-events.d.ts +11 -0
  194. package/dist/docs/write-personal-events.d.ts.map +1 -0
  195. package/dist/docs/write-personal-events.js +28 -0
  196. package/dist/docs/write-personal-events.js.map +1 -0
  197. package/dist/generate/flags-of.d.ts +4 -0
  198. package/dist/generate/flags-of.d.ts.map +1 -0
  199. package/dist/generate/flags-of.js +6 -0
  200. package/dist/generate/flags-of.js.map +1 -0
  201. package/dist/generate/held-to-glossary.d.ts +9 -0
  202. package/dist/generate/held-to-glossary.d.ts.map +1 -0
  203. package/dist/generate/held-to-glossary.js +11 -0
  204. package/dist/generate/held-to-glossary.js.map +1 -0
  205. package/dist/generate/kind-help.d.ts +2 -0
  206. package/dist/generate/kind-help.d.ts.map +1 -1
  207. package/dist/generate/kind-help.js +2 -0
  208. package/dist/generate/kind-help.js.map +1 -1
  209. package/dist/generate/kinds/adapter-kind.js +1 -1
  210. package/dist/generate/kinds/adapter-kind.js.map +1 -1
  211. package/dist/generate/kinds/assert-event-store.d.ts +5 -1
  212. package/dist/generate/kinds/assert-event-store.d.ts.map +1 -1
  213. package/dist/generate/kinds/assert-event-store.js +11 -5
  214. package/dist/generate/kinds/assert-event-store.js.map +1 -1
  215. package/dist/generate/kinds/background/background-job-vars.js +4 -2
  216. package/dist/generate/kinds/background/background-job-vars.js.map +1 -1
  217. package/dist/generate/kinds/background/class-payload-schema.js +3 -3
  218. package/dist/generate/kinds/background/class-payload-schema.js.map +1 -1
  219. package/dist/generate/kinds/background-job-kind.js +1 -1
  220. package/dist/generate/kinds/background-job-kind.js.map +1 -1
  221. package/dist/generate/kinds/builder-kind.js +1 -1
  222. package/dist/generate/kinds/builder-kind.js.map +1 -1
  223. package/dist/generate/kinds/command-kind.js +1 -1
  224. package/dist/generate/kinds/command-kind.js.map +1 -1
  225. package/dist/generate/kinds/declarations-of.d.ts +11 -0
  226. package/dist/generate/kinds/declarations-of.d.ts.map +1 -0
  227. package/dist/generate/kinds/declarations-of.js +17 -0
  228. package/dist/generate/kinds/declarations-of.js.map +1 -0
  229. package/dist/generate/kinds/e2e-kind.js +1 -1
  230. package/dist/generate/kinds/e2e-kind.js.map +1 -1
  231. package/dist/generate/kinds/erasure-handler-kind.js +1 -1
  232. package/dist/generate/kinds/erasure-handler-kind.js.map +1 -1
  233. package/dist/generate/kinds/event-type-as-published.d.ts +11 -0
  234. package/dist/generate/kinds/event-type-as-published.d.ts.map +1 -0
  235. package/dist/generate/kinds/event-type-as-published.js +17 -0
  236. package/dist/generate/kinds/event-type-as-published.js.map +1 -0
  237. package/dist/generate/kinds/form-kind.js +1 -1
  238. package/dist/generate/kinds/form-kind.js.map +1 -1
  239. package/dist/generate/kinds/generate-event-sourced-repository.js +8 -1
  240. package/dist/generate/kinds/generate-event-sourced-repository.js.map +1 -1
  241. package/dist/generate/kinds/integration-event-kind.d.ts.map +1 -1
  242. package/dist/generate/kinds/integration-event-kind.js +2 -9
  243. package/dist/generate/kinds/integration-event-kind.js.map +1 -1
  244. package/dist/generate/kinds/integration-handler-kind.d.ts.map +1 -1
  245. package/dist/generate/kinds/integration-handler-kind.js +30 -14
  246. package/dist/generate/kinds/integration-handler-kind.js.map +1 -1
  247. package/dist/generate/kinds/job-kind.js +1 -1
  248. package/dist/generate/kinds/job-kind.js.map +1 -1
  249. package/dist/generate/kinds/module-kind.js +1 -1
  250. package/dist/generate/kinds/module-kind.js.map +1 -1
  251. package/dist/generate/kinds/parse-version.d.ts +3 -0
  252. package/dist/generate/kinds/parse-version.d.ts.map +1 -0
  253. package/dist/generate/kinds/parse-version.js +9 -0
  254. package/dist/generate/kinds/parse-version.js.map +1 -0
  255. package/dist/generate/kinds/pick-declaration.d.ts +9 -0
  256. package/dist/generate/kinds/pick-declaration.d.ts.map +1 -0
  257. package/dist/generate/kinds/pick-declaration.js +14 -0
  258. package/dist/generate/kinds/pick-declaration.js.map +1 -0
  259. package/dist/generate/kinds/presentation/controller-of.d.ts.map +1 -1
  260. package/dist/generate/kinds/presentation/controller-of.js +15 -5
  261. package/dist/generate/kinds/presentation/controller-of.js.map +1 -1
  262. package/dist/generate/kinds/projection-kind.d.ts.map +1 -1
  263. package/dist/generate/kinds/projection-kind.js +21 -12
  264. package/dist/generate/kinds/projection-kind.js.map +1 -1
  265. package/dist/generate/kinds/property-kind.js +1 -1
  266. package/dist/generate/kinds/property-kind.js.map +1 -1
  267. package/dist/generate/kinds/refuse-unpublished-version.d.ts +7 -0
  268. package/dist/generate/kinds/refuse-unpublished-version.d.ts.map +1 -0
  269. package/dist/generate/kinds/refuse-unpublished-version.js +15 -0
  270. package/dist/generate/kinds/refuse-unpublished-version.js.map +1 -0
  271. package/dist/generate/kinds/repository-kind.js +1 -1
  272. package/dist/generate/kinds/repository-kind.js.map +1 -1
  273. package/dist/generate/kinds/representation-kind.js +1 -1
  274. package/dist/generate/kinds/representation-kind.js.map +1 -1
  275. package/dist/generate/kinds/route/controller-vars.js +1 -1
  276. package/dist/generate/kinds/route/controller-vars.js.map +1 -1
  277. package/dist/generate/kinds/route/message-call.d.ts +6 -2
  278. package/dist/generate/kinds/route/message-call.d.ts.map +1 -1
  279. package/dist/generate/kinds/route/message-call.js +2 -1
  280. package/dist/generate/kinds/route/message-call.js.map +1 -1
  281. package/dist/generate/kinds/route/message-vars.d.ts.map +1 -1
  282. package/dist/generate/kinds/route/message-vars.js +5 -2
  283. package/dist/generate/kinds/route/message-vars.js.map +1 -1
  284. package/dist/generate/kinds/route/route-vars.js +1 -1
  285. package/dist/generate/kinds/route/route-vars.js.map +1 -1
  286. package/dist/generate/kinds/route/spec-vars.d.ts +2 -1
  287. package/dist/generate/kinds/route/spec-vars.d.ts.map +1 -1
  288. package/dist/generate/kinds/route/spec-vars.js +26 -7
  289. package/dist/generate/kinds/route/spec-vars.js.map +1 -1
  290. package/dist/generate/kinds/route/standard-schema-of.d.ts +2 -1
  291. package/dist/generate/kinds/route/standard-schema-of.d.ts.map +1 -1
  292. package/dist/generate/kinds/route/standard-schema-of.js +2 -4
  293. package/dist/generate/kinds/route/standard-schema-of.js.map +1 -1
  294. package/dist/generate/kinds/route-group-kind.js +1 -1
  295. package/dist/generate/kinds/route-group-kind.js.map +1 -1
  296. package/dist/generate/kinds/route-kind.js +2 -2
  297. package/dist/generate/kinds/route-kind.js.map +1 -1
  298. package/dist/generate/kinds/service-kind.js +1 -1
  299. package/dist/generate/kinds/service-kind.js.map +1 -1
  300. package/dist/generate/kinds/state-machine-kind.js +1 -1
  301. package/dist/generate/kinds/state-machine-kind.js.map +1 -1
  302. package/dist/generate/kinds/wanted-event.d.ts +6 -0
  303. package/dist/generate/kinds/wanted-event.d.ts.map +1 -0
  304. package/dist/generate/kinds/wanted-event.js +2 -0
  305. package/dist/generate/kinds/wanted-event.js.map +1 -0
  306. package/dist/generate/refuse-undeclared-flags.d.ts.map +1 -1
  307. package/dist/generate/refuse-undeclared-flags.js +9 -2
  308. package/dist/generate/refuse-undeclared-flags.js.map +1 -1
  309. package/dist/generator-lock/unreadable-lock-refusal.d.ts +4 -0
  310. package/dist/generator-lock/unreadable-lock-refusal.d.ts.map +1 -0
  311. package/dist/generator-lock/unreadable-lock-refusal.js +7 -0
  312. package/dist/generator-lock/unreadable-lock-refusal.js.map +1 -0
  313. package/dist/generator-lock/with-generator-lock.d.ts.map +1 -1
  314. package/dist/generator-lock/with-generator-lock.js +8 -7
  315. package/dist/generator-lock/with-generator-lock.js.map +1 -1
  316. package/dist/help/kind-help-text.d.ts.map +1 -1
  317. package/dist/help/kind-help-text.js +24 -13
  318. package/dist/help/kind-help-text.js.map +1 -1
  319. package/dist/init/files/platform-files.d.ts.map +1 -1
  320. package/dist/init/files/platform-files.js +14 -0
  321. package/dist/init/files/platform-files.js.map +1 -1
  322. package/dist/init/files/privacy-files.d.ts +2 -2
  323. package/dist/init/files/privacy-files.d.ts.map +1 -1
  324. package/dist/init/files/privacy-files.js +3 -2
  325. package/dist/init/files/privacy-files.js.map +1 -1
  326. package/dist/init/manifest/versions.js +24 -24
  327. package/dist/init/stack/http-cache-misfit.d.ts +4 -0
  328. package/dist/init/stack/http-cache-misfit.d.ts.map +1 -0
  329. package/dist/init/stack/http-cache-misfit.js +21 -0
  330. package/dist/init/stack/http-cache-misfit.js.map +1 -0
  331. package/dist/init/stack/resolve-stack.d.ts.map +1 -1
  332. package/dist/init/stack/resolve-stack.js +2 -1
  333. package/dist/init/stack/resolve-stack.js.map +1 -1
  334. package/dist/measures/timeline-of.js +1 -0
  335. package/dist/measures/timeline-of.js.map +1 -1
  336. package/dist/progress/format-progress.js +1 -0
  337. package/dist/progress/format-progress.js.map +1 -1
  338. package/dist/sdk/planned-clients.d.ts +2 -2
  339. package/dist/sdk/planned-clients.d.ts.map +1 -1
  340. package/dist/sdk/planned-clients.js +2 -6
  341. package/dist/sdk/planned-clients.js.map +1 -1
  342. package/dist/sdk/set-up-sdk.d.ts.map +1 -1
  343. package/dist/sdk/set-up-sdk.js +3 -2
  344. package/dist/sdk/set-up-sdk.js.map +1 -1
  345. package/dist/stack/stack-vars.js +12 -3
  346. package/dist/stack/stack-vars.js.map +1 -1
  347. package/dist/stories/forecast-merge.js +1 -0
  348. package/dist/stories/forecast-merge.js.map +1 -1
  349. package/dist/version.d.ts +1 -1
  350. package/dist/version.js +1 -1
  351. package/dist/worker/format-resume.d.ts.map +1 -1
  352. package/dist/worker/format-resume.js +5 -0
  353. package/dist/worker/format-resume.js.map +1 -1
  354. package/dist/worker/format-workers.js +5 -0
  355. package/dist/worker/format-workers.js.map +1 -1
  356. package/dist/worker/progress-of.d.ts +8 -3
  357. package/dist/worker/progress-of.d.ts.map +1 -1
  358. package/dist/worker/progress-of.js +2 -16
  359. package/dist/worker/progress-of.js.map +1 -1
  360. package/dist/worker/read-agent-record.d.ts.map +1 -1
  361. package/dist/worker/read-agent-record.js +15 -3
  362. package/dist/worker/read-agent-record.js.map +1 -1
  363. package/dist/worker/read-workers.js +2 -2
  364. package/dist/worker/read-workers.js.map +1 -1
  365. package/dist/worker/readable-progress.d.ts +5 -0
  366. package/dist/worker/readable-progress.d.ts.map +1 -0
  367. package/dist/worker/readable-progress.js +16 -0
  368. package/dist/worker/readable-progress.js.map +1 -0
  369. package/dist/worker/resume-worker.d.ts.map +1 -1
  370. package/dist/worker/resume-worker.js +4 -5
  371. package/dist/worker/resume-worker.js.map +1 -1
  372. package/dist/worker/worker-progress.d.ts +2 -1
  373. package/dist/worker/worker-progress.d.ts.map +1 -1
  374. package/dist/workspace/real-path-of.d.ts +2 -2
  375. package/dist/workspace/real-path-of.d.ts.map +1 -1
  376. package/dist/workspace/real-path-of.js +15 -10
  377. package/dist/workspace/real-path-of.js.map +1 -1
  378. package/package.json +5 -5
  379. package/templates/controller/controller.spec.ts.tpl +19 -0
  380. package/templates/docs/privacy-register.md.tpl +2 -0
  381. package/templates/init/README.md.tpl +13 -4
  382. package/templates/init/docker/env.example.tpl +8 -0
  383. package/templates/init/main.ts.tpl +3 -0
  384. package/templates/init/platform/audit/create-audit.ts.tpl +12 -6
  385. package/templates/init/platform/composition/compose-application.manual.ts.tpl +36 -0
  386. package/templates/init/platform/composition/compose-application.tsyringe.ts.tpl +7 -0
  387. package/templates/init/platform/composition/lay-foundations.manual.ts.tpl +1 -1
  388. package/templates/init/platform/composition/lay-foundations.tsyringe.ts.tpl +1 -1
  389. package/templates/init/platform/composition/platform-options.manual.ts.tpl +7 -0
  390. package/templates/init/platform/composition/platform.manual.ts.tpl +7 -0
  391. package/templates/init/platform/composition/platform.module.tsyringe.ts.tpl +7 -0
  392. package/templates/init/platform/config/app-config.ts.tpl +7 -0
  393. package/templates/init/platform/config/load-config.ts.tpl +22 -0
  394. package/templates/init/platform/database/persistence.contract.spec.ts.tpl +14 -3
  395. package/templates/init/platform/event-sourcing/create-event-sourcing.ts.tpl +5 -1
  396. package/templates/init/platform/jobs/create-background-work.ts.tpl +12 -0
  397. package/templates/init/platform/jobs/days-before.ts.tpl +8 -0
  398. package/templates/init/platform/jobs/housekeeping.module.tsyringe.ts.tpl +46 -0
  399. package/templates/init/platform/jobs/housekeeping.ts.tpl +24 -0
  400. package/templates/init/platform/jobs/job-settings.ts.tpl +6 -0
  401. package/templates/init/platform/privacy/personal-events.ts.tpl +11 -0
  402. package/templates/init/platform/privacy/run-erasure.manual.ts.tpl +69 -19
  403. package/templates/init/platform/privacy/run-erasure.tsyringe.ts.tpl +69 -8
  404. package/templates/init/platform/privacy/run-export.manual.ts.tpl +2 -2
  405. package/templates/init/platform/privacy/run-export.tsyringe.ts.tpl +4 -2
  406. package/templates/init/platform/privacy/run-purge.manual.ts.tpl +3 -2
  407. package/templates/init/platform/privacy/run-purge.tsyringe.ts.tpl +4 -2
  408. package/templates/init/rules/infrastructure.md.tpl +1 -1
  409. package/templates/init/scripts/privacy-erase.manual.ts.tpl +52 -7
  410. package/templates/init/scripts/privacy-erase.tsyringe.ts.tpl +52 -7
  411. package/templates/init/scripts/privacy-export.manual.ts.tpl +4 -0
  412. package/templates/init/scripts/privacy-export.tsyringe.ts.tpl +4 -0
  413. package/templates/init/scripts/privacy-purge.manual.ts.tpl +4 -0
  414. package/templates/init/scripts/privacy-purge.tsyringe.ts.tpl +4 -0
  415. package/templates/integration-event/payload.class-validator.ts.tpl +2 -2
  416. package/templates/nest-controller/controller.spec.ts.tpl +25 -0
  417. package/templates/pipeline/package-scripts.json +1 -1
  418. package/templates/pipeline/stryker.config.mjs.tpl +4 -0
  419. package/templates/presets/identity/context/presentation/http/accounts/deactivate-account/deactivate-account.accepted.class-validator.per-route.ts.tpl +1 -1
  420. package/templates/presets/identity/context/presentation/http/accounts/provision-account/provision-account.accepted.class-validator.per-route.ts.tpl +1 -1
  421. package/templates/presets/identity/context/presentation/http/accounts/provision-account/provision-account.body.class-validator.ts.tpl +1 -1
  422. package/templates/presets/identity/context/presentation/http/invitations/accept-invitation/accept-invitation.accepted.class-validator.per-route.ts.tpl +1 -1
  423. package/templates/presets/identity/context/presentation/http/invitations/accept-invitation/accept-invitation.body.class-validator.per-route.ts.tpl +1 -1
  424. package/templates/presets/identity/context/presentation/http/invitations/decline-invitation/decline-invitation.accepted.class-validator.per-route.ts.tpl +1 -1
  425. package/templates/presets/identity/context/presentation/http/invitations/decline-invitation/decline-invitation.body.class-validator.per-route.ts.tpl +1 -1
  426. package/templates/presets/identity/context/presentation/http/organisations/change-member-role/change-member-role.accepted.class-validator.per-route.ts.tpl +1 -1
  427. package/templates/presets/identity/context/presentation/http/organisations/change-member-role/change-member-role.body.class-validator.ts.tpl +1 -1
  428. package/templates/presets/identity/context/presentation/http/organisations/change-member-role/change-member-role.params.class-validator.ts.tpl +2 -2
  429. package/templates/presets/identity/context/presentation/http/organisations/grant-delegation/grant-delegation.accepted.class-validator.per-route.ts.tpl +1 -1
  430. package/templates/presets/identity/context/presentation/http/organisations/grant-delegation/grant-delegation.body.class-validator.ts.tpl +4 -4
  431. package/templates/presets/identity/context/presentation/http/organisations/grant-delegation/grant-delegation.params.class-validator.ts.tpl +1 -1
  432. package/templates/presets/identity/context/presentation/http/organisations/invite-member/invite-member.accepted.class-validator.ts.tpl +2 -2
  433. package/templates/presets/identity/context/presentation/http/organisations/invite-member/invite-member.body.class-validator.ts.tpl +2 -2
  434. package/templates/presets/identity/context/presentation/http/organisations/invite-member/invite-member.params.class-validator.ts.tpl +1 -1
  435. package/templates/presets/identity/context/presentation/http/organisations/open-organisation/open-organisation.accepted.class-validator.per-route.ts.tpl +1 -1
  436. package/templates/presets/identity/context/presentation/http/organisations/open-organisation/open-organisation.body.class-validator.ts.tpl +2 -2
  437. package/templates/presets/identity/context/presentation/http/organisations/remove-member/remove-member.accepted.class-validator.per-route.ts.tpl +1 -1
  438. package/templates/presets/identity/context/presentation/http/organisations/remove-member/remove-member.params.class-validator.ts.tpl +2 -2
  439. package/templates/presets/identity/context/presentation/http/organisations/revoke-delegation/revoke-delegation.accepted.class-validator.per-route.ts.tpl +1 -1
  440. package/templates/presets/identity/context/presentation/http/organisations/revoke-delegation/revoke-delegation.params.class-validator.ts.tpl +2 -2
  441. package/templates/presets/identity/context/presentation/http/organisations/revoke-invitation/revoke-invitation.accepted.class-validator.per-route.ts.tpl +1 -1
  442. package/templates/presets/identity/context/presentation/http/organisations/revoke-invitation/revoke-invitation.params.class-validator.ts.tpl +2 -2
  443. package/templates/presets/identity/context/presentation/http/organisations/search-members/search-members.line.class-validator.ts.tpl +6 -6
  444. package/templates/presets/identity/context/presentation/http/organisations/search-members/search-members.params.class-validator.ts.tpl +1 -1
  445. package/templates/presets/identity/context/presentation/http/shared/invitation-token.schema.class-validator.shared.ts.tpl +1 -1
  446. package/templates/presets/identity/context/published-language/account-deactivated.v1.payload.class-validator.ts.tpl +1 -1
  447. package/templates/presets/identity/context/published-language/delegation-granted.v1.payload.class-validator.ts.tpl +7 -7
  448. package/templates/presets/identity/context/published-language/delegation-revoked.v1.payload.class-validator.ts.tpl +4 -4
  449. package/templates/presets/identity/context/published-language/member-joined.v1.payload.class-validator.ts.tpl +4 -4
  450. package/templates/presets/identity/context/published-language/member-removed.v1.payload.class-validator.ts.tpl +4 -4
  451. package/templates/presets/identity/context/published-language/member-role-changed.v1.payload.class-validator.ts.tpl +6 -6
  452. package/templates/presets/identity/context/published-language/organisation-opened.v1.payload.class-validator.ts.tpl +3 -3
  453. package/templates/route/dto.accepted.ts.tpl +1 -1
  454. package/templates/route/dto.answer.ts.tpl +1 -1
  455. package/templates/route/dto.body.ts.tpl +1 -1
  456. package/templates/route/dto.line.ts.tpl +2 -2
  457. package/templates/route/route.spec.ts.tpl +19 -0
  458. package/templates/schema/schema.class-validator.ts.tpl +1 -1
  459. package/templates/worker/main.ts.tpl +3 -0
  460. package/dist/generate/kinds/find-event-declaration.d.ts +0 -8
  461. package/dist/generate/kinds/find-event-declaration.d.ts.map +0 -1
  462. package/dist/generate/kinds/find-event-declaration.js +0 -27
  463. package/dist/generate/kinds/find-event-declaration.js.map +0 -1
@@ -29,6 +29,12 @@ export function jobSettings(environment: Environment, context?: string): Readonl
29
29
  {{/if}}
30
30
  {{#if privacy.on}}
31
31
  'privacy.purge-expired': { enabled: environment['JOB_PRIVACY_PURGE_EXPIRED_ENABLED'] !== 'false' },
32
+ {{/if}}
33
+ {{#if events.outbox}}
34
+ 'events.purge-published': { enabled: environment['JOB_EVENTS_PURGE_PUBLISHED_ENABLED'] !== 'false' },
35
+ {{/if}}
36
+ {{#if queue.stored}}
37
+ 'jobs.purge-finished': { enabled: environment['JOB_JOBS_PURGE_FINISHED_ENABLED'] !== 'false' },
32
38
  {{/if}}
33
39
  // ddd-ts-kit:jobs
34
40
  // /ddd-ts-kit:jobs
@@ -0,0 +1,11 @@
1
+ import type { PersonalEvent } from '@ddd-ts-kit/events';
2
+
3
+ /**
4
+ * The integration events that carry personal data, as the `personal` option of each one declares it:
5
+ * what an erasure looks for in the records of the outbox. Written by `ddd-ts-kit docs`, like the
6
+ * register, and held to the declarations by `docs --check`.
7
+ */
8
+ export const personalEvents: readonly PersonalEvent[] = [
9
+ // ddd-ts-kit:personal-events
10
+ // /ddd-ts-kit:personal-events
11
+ ];
@@ -1,33 +1,48 @@
1
- {{#if tenancy.any}}
1
+ {{#if audit.on}}
2
+ import { auditedPersonalDataErasure } from '@ddd-ts-kit/audit';
3
+ {{/if}}
4
+ {{#if events.outbox}}
5
+ import { personalEventsInOutbox } from '@ddd-ts-kit/events';
6
+ {{/if}}
2
7
  import {
3
8
  dataSubjectErasedV1,
9
+ {{#if tenancy.any}}
4
10
  eachTenant,
11
+ {{/if}}
5
12
  eraseDataSubject,
6
13
  executionContext,
14
+ {{#if tenancy.any}}
7
15
  inEachTenant,
8
- type Actor,
9
- type DataSubjectErasureReport,
10
- } from '@ddd-ts-kit/kernel';
11
16
  {{/if}}
12
- {{#unless tenancy.any}}
13
- import {
14
- dataSubjectErasedV1,
15
- eraseDataSubject,
16
- executionContext,
17
17
  type Actor,
18
18
  type DataSubjectErasureReport,
19
- } from '@ddd-ts-kit/kernel';
19
+ {{#if housekeeping.any}}
20
+ type PersonalDataCopy,
21
+ {{/if}}
22
+ {{#unless housekeeping.any}}
23
+ {{#if audit.on}}
24
+ type PersonalDataCopy,
25
+ {{/if}}
20
26
  {{/unless}}
27
+ } from '@ddd-ts-kit/kernel';
28
+ {{#if queue.stored}}
29
+ import { jobsOfSubject } from '@ddd-ts-kit/scheduling';
30
+ {{/if}}
21
31
  import type { Platform } from '{{alias.platform}}/composition/platform{{alias.ext}}';
22
32
  import { dataSubjectCopies } from '{{alias.platform}}/privacy/data-subject-copies{{alias.ext}}';
33
+ {{#if events.outbox}}
34
+ import { personalEvents } from '{{alias.platform}}/privacy/personal-events{{alias.ext}}';
35
+ {{/if}}
23
36
 
24
37
  export interface ErasureRequest {
25
- /** The assembled platform: the {{#if eventSourcing.on}}keys, the {{/if}}scope and the copies come from it. */
38
+ /** The assembled platform: the {{#if eventSourcing.on}}keys, the {{/if}}scope{{#if audit.on}}, the trail{{/if}} and the copies come from it. */
26
39
  readonly platform: Platform;
27
- /** Who asks for the erasure, as typed: the actor of the work{{#if eventSourcing.on}}{{#if audit.on}}, named by the entry the audited keys write{{/if}}{{/if}}. */
40
+ /** Who asks for the erasure, as typed: the actor of the work{{#if audit.on}}, named by the entry each copy writes{{/if}}. */
28
41
  readonly operator: string;
29
42
  /** The correlation of the work: one per erasure. */
30
43
  readonly correlationId: string;
44
+ /** This subject was erased before: reaching nothing is expected, and the erasure is announced again, which completes one that failed before its announcement. */
45
+ readonly rerun?: boolean;
31
46
  {{#if tenancy.any}}
32
47
  /** The tenants the deployment serves: the copies are erased in each one, in an execution context of that tenant, since a write of tenant data is never widened. */
33
48
  readonly tenants: readonly string[];
@@ -37,8 +52,9 @@ export interface ErasureRequest {
37
52
  {{#if eventSourcing.on}}
38
53
  /**
39
54
  * The right to erasure of one data subject, in an execution context of its own (origin `cli`): the
40
- * key first{{#if audit.on}}, with its audit entry{{/if}}, then every copy a context declared in `data-subject-copies.ts`{{#if tenancy.any}}, in
41
- * every tenant{{/if}}. Running it again completes an erasure whose entry or copy failed; a subject that is
55
+ * key first, then every copy a context declared in `data-subject-copies.ts`{{#if tenancy.any}}, in every tenant{{/if}}{{#if audit.on}}; the key and every
56
+ * copy write their entry to the audit trail, the operator, the subject and the number of rows, never
57
+ * the values{{/if}}. Running it again completes an erasure whose entry or copy failed; a subject that is
42
58
  * not an opaque identifier is refused before any key is touched.
43
59
  */
44
60
  {{/if}}
@@ -47,13 +63,19 @@ export interface ErasureRequest {
47
63
  * The right to erasure of one data subject, in an execution context of its own (origin `cli`):
48
64
  * every copy a context declared in `data-subject-copies.ts`{{#if tenancy.any}}, in every tenant{{/if}}. The aggregates
49
65
  * of this project are rows, so no key is destroyed: a copy is erased or pseudonymised where it
50
- * lies. Running it again completes an erasure whose copy failed; a subject that is not an opaque
51
- * identifier is refused before anything is touched.
66
+ * lies{{#if audit.on}}, and writes its entry to the audit trail, the operator, the subject and the number of
67
+ * rows, never the values{{/if}}. Running it again completes an erasure whose copy failed; a subject that is not an
68
+ * opaque identifier is refused before anything is touched.
52
69
  */
53
70
  {{/unless}}
54
71
  export function runErasure(subject: string, request: ErasureRequest): Promise<DataSubjectErasureReport> {
55
72
  const { platform, operator, correlationId } = request;
56
73
  const context = executionContext({ correlationId, actor: operatorActor(operator), origin: 'cli' });
74
+ {{#if audit.on}}
75
+ const { trail, onLostRecord } = platform.audit;
76
+ const source = { scope: platform.scope, clock: platform.clock, ids: platform.ids, onLostRecord };
77
+ const audited = (copy: PersonalDataCopy): PersonalDataCopy => auditedPersonalDataErasure(copy, trail, source);
78
+ {{/if}}
57
79
 
58
80
  return platform.scope.run(context, async () => {
59
81
  const report = await eraseDataSubject(subject, {
@@ -61,7 +83,19 @@ export function runErasure(subject: string, request: ErasureRequest): Promise<Da
61
83
  // TODO(platform): once a projection is fed by the event store, give `rebuilds` the rebuild of each one: a projection keeps a clear copy of the person until it is rebuilt.
62
84
  keys: platform.eventSourcing.subjectKeys,
63
85
  {{/if}}
86
+ {{#if audit.on}}
87
+ copies: dataSubjectCopies.map((copy) => audited(copy(platform))),
88
+ {{#if housekeeping.any}}
89
+ shared: platformCopies(platform).map(audited),
90
+ {{/if}}
91
+ {{/if}}
92
+ {{#unless audit.on}}
64
93
  copies: dataSubjectCopies.map((copy) => copy(platform)),
94
+ {{#if housekeeping.any}}
95
+ shared: platformCopies(platform),
96
+ {{/if}}
97
+ {{/unless}}
98
+ isKnown: () => Promise.resolve(request.rerun === true),
65
99
  {{#if tenancy.any}}
66
100
  inEveryTenant: inEachTenant(platform.scope, request.tenants),
67
101
  {{/if}}
@@ -73,12 +107,28 @@ export function runErasure(subject: string, request: ErasureRequest): Promise<Da
73
107
  });
74
108
  }
75
109
 
110
+ {{#if housekeeping.any}}
111
+ /** What the platform keeps of a person in tables no tenant confines{{#if events.outbox}}: the records of the outbox, by what `personal-events.ts` lists{{/if}}{{#if queue.stored}}{{#if events.outbox}},{{/if}}{{#unless events.outbox}}:{{/unless}} the jobs enqueued with the person as `subject`{{/if}}. */
112
+ function platformCopies(platform: Platform): readonly PersonalDataCopy[] {
113
+ {{#if events.outbox}}
114
+ const outbox = personalEventsInOutbox(platform.persistence.outbox, personalEvents);
115
+ {{/if}}
116
+ {{#if queue.stored}}
117
+ const jobs = jobsOfSubject(platform.jobStore);
118
+ {{/if}}
119
+
120
+ return [{{#if events.outbox}}outbox{{/if}}{{#if events.outbox}}{{#if queue.stored}}, {{/if}}{{/if}}{{#if queue.stored}}jobs{{/if}}];
121
+ }
122
+
123
+ {{/if}}
76
124
  /**
77
125
  * Once every copy is erased, `privacy.data-subject.erased` goes to the outbox{{#if tenancy.any}}, once per tenant{{/if}}: a context that
78
126
  * runs as a service of its own, or a system that copied the person from an integration event, erases
79
- * its copy on its side (GDPR article 19). It names the person by id and nobody else: who asked is in
80
- * the audit trail, under the correlation id the event carries. The relay of the application delivers it; an erasure that
81
- * failed publishes nothing, and running it again does.
127
+ * its copy on its side (GDPR article 19). It names the person by id and nobody else{{#if audit.on}}: who asked is in
128
+ * the audit trail, under the correlation id the event carries{{/if}}. The relay of the application delivers it; an erasure that
129
+ * failed publishes nothing, and running it again does. Neither does an erasure that reached nothing:
130
+ * `eraseDataSubject` refuses it (`UnknownDataSubjectError`), a mistyped id or a tenant left out of the
131
+ * list must not tell the others that a person is gone; `rerun` says it is expected.
82
132
  */
83
133
  async function announceErasure(subject: string, { platform{{#if tenancy.any}}, tenants{{/if}} }: ErasureRequest): Promise<void> {
84
134
  const erasedAt = platform.clock.now();
@@ -1,9 +1,18 @@
1
+ {{#if audit.on}}
2
+ import { AuditTrail, auditedPersonalDataErasure, logLostRecords } from '@ddd-ts-kit/audit';
3
+ {{/if}}
1
4
  import type { Application as Container } from '@ddd-ts-kit/di';
5
+ {{#if events.outbox}}
6
+ import { OutboxStore, personalEventsInOutbox } from '@ddd-ts-kit/events';
7
+ {{/if}}
2
8
  import {
3
9
  Clock,
4
10
  ExecutionScope,
5
11
  IdGenerator,
6
12
  IntegrationEventPublisher,
13
+ {{#if audit.on}}
14
+ Logger,
15
+ {{/if}}
7
16
  {{#if eventSourcing.on}}
8
17
  SubjectKeyStore,
9
18
  {{/if}}
@@ -18,16 +27,32 @@ import {
18
27
  {{/if}}
19
28
  type Actor,
20
29
  type DataSubjectErasureReport,
30
+ {{#if housekeeping.any}}
31
+ type PersonalDataCopy,
32
+ {{/if}}
33
+ {{#unless housekeeping.any}}
34
+ {{#if audit.on}}
35
+ type PersonalDataCopy,
36
+ {{/if}}
37
+ {{/unless}}
21
38
  } from '@ddd-ts-kit/kernel';
39
+ {{#if queue.stored}}
40
+ import { JobStore, jobsOfSubject } from '@ddd-ts-kit/scheduling';
41
+ {{/if}}
22
42
  import { dataSubjectCopies } from '{{alias.platform}}/privacy/data-subject-copies{{alias.ext}}';
43
+ {{#if events.outbox}}
44
+ import { personalEvents } from '{{alias.platform}}/privacy/personal-events{{alias.ext}}';
45
+ {{/if}}
23
46
 
24
47
  export interface ErasureRequest {
25
48
  /** The composed application: the {{#if eventSourcing.on}}keys and the {{/if}}copies are resolved from it. */
26
49
  readonly container: Container;
27
- /** Who asks for the erasure, as typed: the actor of the work{{#if eventSourcing.on}}{{#if audit.on}}, named by the entry the audited keys write{{/if}}{{/if}}. */
50
+ /** Who asks for the erasure, as typed: the actor of the work{{#if audit.on}}, named by the entry each copy writes{{/if}}. */
28
51
  readonly operator: string;
29
52
  /** The correlation of the work: one per erasure. */
30
53
  readonly correlationId: string;
54
+ /** This subject was erased before: reaching nothing is expected, and the erasure is announced again, which completes one that failed before its announcement. */
55
+ readonly rerun?: boolean;
31
56
  {{#if tenancy.any}}
32
57
  /** The tenants the deployment serves: the copies are erased in each one, in an execution context of that tenant, since a write of tenant data is never widened. */
33
58
  readonly tenants: readonly string[];
@@ -37,8 +62,9 @@ export interface ErasureRequest {
37
62
  {{#if eventSourcing.on}}
38
63
  /**
39
64
  * The right to erasure of one data subject, in an execution context of its own (origin `cli`): the
40
- * key first{{#if audit.on}}, with its audit entry{{/if}}, then every copy a context declared in `data-subject-copies.ts`{{#if tenancy.any}}, in
41
- * every tenant{{/if}}. Running it again completes an erasure whose entry or copy failed; a subject that is
65
+ * key first, then every copy a context declared in `data-subject-copies.ts`{{#if tenancy.any}}, in every tenant{{/if}}{{#if audit.on}}; the key and every
66
+ * copy write their entry to the audit trail, the operator, the subject and the number of rows, never
67
+ * the values{{/if}}. Running it again completes an erasure whose entry or copy failed; a subject that is
42
68
  * not an opaque identifier is refused before any key is touched.
43
69
  */
44
70
  {{/if}}
@@ -47,14 +73,21 @@ export interface ErasureRequest {
47
73
  * The right to erasure of one data subject, in an execution context of its own (origin `cli`):
48
74
  * every copy a context declared in `data-subject-copies.ts`{{#if tenancy.any}}, in every tenant{{/if}}. The aggregates
49
75
  * of this project are rows, so no key is destroyed: a copy is erased or pseudonymised where it
50
- * lies. Running it again completes an erasure whose copy failed; a subject that is not an opaque
51
- * identifier is refused before anything is touched.
76
+ * lies{{#if audit.on}}, and writes its entry to the audit trail, the operator, the subject and the number of
77
+ * rows, never the values{{/if}}. Running it again completes an erasure whose copy failed; a subject that is not an
78
+ * opaque identifier is refused before anything is touched.
52
79
  */
53
80
  {{/unless}}
54
81
  export function runErasure(subject: string, request: ErasureRequest): Promise<DataSubjectErasureReport> {
55
82
  const { container, operator, correlationId } = request;
56
83
  const scope = container.resolve(ExecutionScope);
57
84
  const context = executionContext({ correlationId, actor: operatorActor(operator), origin: 'cli' });
85
+ {{#if audit.on}}
86
+ const trail = container.resolve(AuditTrail);
87
+ const onLostRecord = logLostRecords(container.resolve(Logger));
88
+ const source = { scope, clock: container.resolve(Clock), ids: container.resolve(IdGenerator), onLostRecord };
89
+ const audited = (copy: PersonalDataCopy): PersonalDataCopy => auditedPersonalDataErasure(copy, trail, source);
90
+ {{/if}}
58
91
 
59
92
  return scope.run(context, async () => {
60
93
  const report = await eraseDataSubject(subject, {
@@ -62,7 +95,19 @@ export function runErasure(subject: string, request: ErasureRequest): Promise<Da
62
95
  // TODO(platform): once a projection is fed by the event store, give `rebuilds` the rebuild of each one: a projection keeps a clear copy of the person until it is rebuilt.
63
96
  keys: container.resolve(SubjectKeyStore),
64
97
  {{/if}}
98
+ {{#if audit.on}}
99
+ copies: dataSubjectCopies.map((copy) => audited(container.resolve(copy))),
100
+ {{#if housekeeping.any}}
101
+ shared: platformCopies(container).map(audited),
102
+ {{/if}}
103
+ {{/if}}
104
+ {{#unless audit.on}}
65
105
  copies: dataSubjectCopies.map((copy) => container.resolve(copy)),
106
+ {{#if housekeeping.any}}
107
+ shared: platformCopies(container),
108
+ {{/if}}
109
+ {{/unless}}
110
+ isKnown: () => Promise.resolve(request.rerun === true),
66
111
  {{#if tenancy.any}}
67
112
  inEveryTenant: inEachTenant(scope, request.tenants),
68
113
  {{/if}}
@@ -74,12 +119,28 @@ export function runErasure(subject: string, request: ErasureRequest): Promise<Da
74
119
  });
75
120
  }
76
121
 
122
+ {{#if housekeeping.any}}
123
+ /** What the platform keeps of a person in tables no tenant confines{{#if events.outbox}}: the records of the outbox, by what `personal-events.ts` lists{{/if}}{{#if queue.stored}}{{#if events.outbox}},{{/if}}{{#unless events.outbox}}:{{/unless}} the jobs enqueued with the person as `subject`{{/if}}. */
124
+ function platformCopies(container: Container): readonly PersonalDataCopy[] {
125
+ {{#if events.outbox}}
126
+ const outbox = personalEventsInOutbox(container.resolve(OutboxStore), personalEvents);
127
+ {{/if}}
128
+ {{#if queue.stored}}
129
+ const jobs = jobsOfSubject(container.resolve(JobStore));
130
+ {{/if}}
131
+
132
+ return [{{#if events.outbox}}outbox{{/if}}{{#if events.outbox}}{{#if queue.stored}}, {{/if}}{{/if}}{{#if queue.stored}}jobs{{/if}}];
133
+ }
134
+
135
+ {{/if}}
77
136
  /**
78
137
  * Once every copy is erased, `privacy.data-subject.erased` goes to the outbox{{#if tenancy.any}}, once per tenant{{/if}}: a context that
79
138
  * runs as a service of its own, or a system that copied the person from an integration event, erases
80
- * its copy on its side (GDPR article 19). It names the person by id and nobody else: who asked is in
81
- * the audit trail, under the correlation id the event carries. The relay of the application delivers it; an erasure that
82
- * failed publishes nothing, and running it again does.
139
+ * its copy on its side (GDPR article 19). It names the person by id and nobody else{{#if audit.on}}: who asked is in
140
+ * the audit trail, under the correlation id the event carries{{/if}}. The relay of the application delivers it; an erasure that
141
+ * failed publishes nothing, and running it again does. Neither does an erasure that reached nothing:
142
+ * `eraseDataSubject` refuses it (`UnknownDataSubjectError`), a mistyped id or a tenant left out of the
143
+ * list must not tell the others that a person is gone; `rerun` says it is expected.
83
144
  */
84
145
  async function announceErasure(subject: string, request: ErasureRequest): Promise<void> {
85
146
  const { container } = request;
@@ -39,8 +39,8 @@ export function runExport(subject: string, request: ExportRequest): Promise<Pers
39
39
  const { platform, operator, correlationId } = request;
40
40
  const context = executionContext({ correlationId, actor: operatorActor(operator), origin: 'cli' });
41
41
  {{#if audit.on}}
42
- const { trail } = platform.audit;
43
- const source = { scope: platform.scope, clock: platform.clock, ids: platform.ids };
42
+ const { trail, onLostRecord } = platform.audit;
43
+ const source = { scope: platform.scope, clock: platform.clock, ids: platform.ids, onLostRecord };
44
44
  const audited = (port: PersonalDataExport): PersonalDataExport => auditedPersonalDataExport(port, trail, source);
45
45
  const exports = dataSubjectExports.map((exported) => audited(exported(platform)));
46
46
  {{/if}}
@@ -1,5 +1,5 @@
1
1
  {{#if audit.on}}
2
- import { AuditTrail, auditedPersonalDataExport } from '@ddd-ts-kit/audit';
2
+ import { AuditTrail, auditedPersonalDataExport, logLostRecords } from '@ddd-ts-kit/audit';
3
3
  {{/if}}
4
4
  import type { Application as Container } from '@ddd-ts-kit/di';
5
5
  import {
@@ -7,6 +7,7 @@ import {
7
7
  ExecutionScope,
8
8
  {{#if audit.on}}
9
9
  IdGenerator,
10
+ Logger,
10
11
  {{/if}}
11
12
  executionContext,
12
13
  exportDataSubject,
@@ -47,7 +48,8 @@ export function runExport(subject: string, request: ExportRequest): Promise<Pers
47
48
  const context = executionContext({ correlationId, actor: operatorActor(operator), origin: 'cli' });
48
49
  {{#if audit.on}}
49
50
  const trail = container.resolve(AuditTrail);
50
- const source = { scope, clock, ids: container.resolve(IdGenerator) };
51
+ const onLostRecord = logLostRecords(container.resolve(Logger));
52
+ const source = { scope, clock, ids: container.resolve(IdGenerator), onLostRecord };
51
53
  const audited = (port: PersonalDataExport): PersonalDataExport => auditedPersonalDataExport(port, trail, source);
52
54
  const exports = dataSubjectExports.map((port) => audited(container.resolve(port)));
53
55
  {{/if}}
@@ -25,10 +25,11 @@ import { dataSubjectCopies } from '{{alias.platform}}/privacy/data-subject-copie
25
25
  export function runPurge(platform: Platform): Promise<PersonalDataPurgeReport> {
26
26
  const retentions = dataSubjectCopies.map((copy) => copy(platform)).filter(isPersonalDataRetention);
27
27
  {{#if audit.on}}
28
- const source = { scope: platform.scope, clock: platform.clock, ids: platform.ids };
28
+ const { trail, onLostRecord } = platform.audit;
29
+ const source = { scope: platform.scope, clock: platform.clock, ids: platform.ids, onLostRecord };
29
30
 
30
31
  const audited = (port: PersonalDataRetention): PersonalDataRetention =>
31
- auditedPersonalDataRetention(port, platform.audit.trail, source);
32
+ auditedPersonalDataRetention(port, trail, source);
32
33
 
33
34
  return purgeExpiredPersonalData(platform.clock.now(), retentions.map(audited));
34
35
  {{/if}}
@@ -1,5 +1,5 @@
1
1
  {{#if audit.on}}
2
- import { AuditTrail, auditedPersonalDataRetention } from '@ddd-ts-kit/audit';
2
+ import { AuditTrail, auditedPersonalDataRetention, logLostRecords } from '@ddd-ts-kit/audit';
3
3
  {{/if}}
4
4
  import type { Resolve } from '@ddd-ts-kit/di';
5
5
  import {
@@ -7,6 +7,7 @@ import {
7
7
  {{#if audit.on}}
8
8
  ExecutionScope,
9
9
  IdGenerator,
10
+ Logger,
10
11
  {{/if}}
11
12
  isPersonalDataRetention,
12
13
  purgeExpiredPersonalData,
@@ -31,7 +32,8 @@ export function runPurge(resolve: Resolve): Promise<PersonalDataPurgeReport> {
31
32
  const retentions = dataSubjectCopies.map((copy) => resolve(copy)).filter(isPersonalDataRetention);
32
33
  {{#if audit.on}}
33
34
  const trail = resolve(AuditTrail);
34
- const source = { scope: resolve(ExecutionScope), clock, ids: resolve(IdGenerator) };
35
+ const onLostRecord = logLostRecords(resolve(Logger));
36
+ const source = { scope: resolve(ExecutionScope), clock, ids: resolve(IdGenerator), onLostRecord };
35
37
 
36
38
  const audited = (port: PersonalDataRetention): PersonalDataRetention =>
37
39
  auditedPersonalDataRetention(port, trail, source);
@@ -20,7 +20,7 @@ paths:
20
20
  - Own tables, in the schema of the context: no join, foreign key or transaction across contexts (`context/extractable`).
21
21
  - 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.
22
22
  {{#if tenancy.any}}
23
- - Tenant data is reached through the helpers of the ORM package, never straight from the executor: {{#if orm.knex}}`tenantTable` to read, `ownTenantTable` to update or delete{{/if}}{{#if orm.drizzle}}`tenantCondition` in the condition of a read, `ownTenantCondition` in that of an update or a delete{{/if}}{{#if orm.prisma}}`tenantWhere` spread into the where of a read (`findFirst`, never `findUnique`: the tenant is not part of the key), `ownTenantWhere` into that of an update or a delete{{/if}}{{#if orm.typeorm}}`tenantWhere` spread into the where of a read, `ownTenantWhere` into the criteria of an update or a delete, never `save` or `upsert`{{/if}}, the tenant named on every insert, a read model store built with its `tenant` (`tenancy/scoped-statement`). A table of no tenant is a recorded deviation; a context none of whose tables belongs to a tenant, since it decides who belongs to which, is declared `"tenancy": "control-plane"` in its entry of `contexts`, with its deviation, never suppressed statement by statement. See `docs/concepts/multitenancy.md` of the kit.
23
+ - Tenant data is reached through the helpers of the ORM package, never straight from the executor: {{#if orm.knex}}`tenantTable` to read, `ownTenantTable` to update or delete{{/if}}{{#if orm.drizzle}}`tenantCondition` in the condition of a read, `ownTenantCondition` in that of an update or a delete{{/if}}{{#if orm.prisma}}`tenantWhere` spread into the where of a read (`findFirst`, never `findUnique`: the tenant is not part of the key), `ownTenantWhere` into that of an update or a delete{{/if}}{{#if orm.typeorm}}`tenantWhere` spread into the where of a read, `ownTenantWhere` into the criteria of an update or a delete, never `save` or `upsert`{{/if}}, the tenant named on every insert, a read model store built with its `tenant` (`tenancy/scoped-statement`). The tenant condition is a conjunct of the statement, since SQL binds `and` before `or`: {{#if orm.knex}}no `.orWhere*` at the top of a statement of `tenantTable` or `ownTenantTable`, alternatives grouped in `.where((either) => either.where(a).orWhere(b))`, no `clearWhere()` or `clear('where')`{{/if}}{{#if orm.drizzle}}a direct argument of `where` or of `and`, never under `or`, `not` or a `sql` template, alternatives beside it in `and(tenantCondition(...), or(a, b))`{{/if}}{{#if orm.prisma}}the spread at the top of the `where`, never under `OR` or `NOT`, an `OR` beside it{{/if}}{{#if orm.typeorm}}the spread at the top of the where and in each entry of a where array, no `orWhere` at the top of a query builder, the condition in its last `where` or an `andWhere` after it, alternatives in `new Brackets(...)` in an `andWhere`{{/if}}. A table of no tenant is a recorded deviation; a context none of whose tables belongs to a tenant, since it decides who belongs to which, is declared `"tenancy": "control-plane"` in its entry of `contexts`, with its deviation, never suppressed statement by statement. See `docs/concepts/multitenancy.md` of the kit.
24
24
  {{/if}}
25
25
  {{#if style.declared}}
26
26
  - An adapter declares itself on its class, one per file (`declarations/role-declared`): `@Repository(InvoiceRepository)`, `@Gateway(Port)` or `@Adapter(Port, { kind })`. What it is given is what its constructor takes, each parameter typed by one class (`{{persistence.tokenOrNone}}`, `ExecutionScope`, `Clock`, a port, an abstract class the platform binds to a value) and nothing listed in the decorator (`declarations/constructor-injection`); an adapter that extends a class of a package writes its own constructor.
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import os from 'node:os';
3
3
  import { parseArgs } from 'node:util';
4
+ import { UnknownDataSubjectError } from '@ddd-ts-kit/kernel';
4
5
  {{#if http.any}}
5
6
  import { offlineAuthenticator } from '{{alias.platform}}/auth/authentication/offline-authenticator{{alias.ext}}';
6
7
  {{/if}}
@@ -8,36 +9,55 @@ import { composeApplication } from '{{alias.platform}}/composition/compose-appli
8
9
  {{#if persistence.needsUrl}}
9
10
  import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
10
11
  {{/if}}
12
+ {{#unless persistence.needsUrl}}
13
+ {{#if queue.redis}}
14
+ import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
15
+ {{/if}}
16
+ {{/unless}}
11
17
  import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
12
18
  {{#if tenancy.any}}
13
19
  import { tenantDirectory } from '{{alias.platform}}/composition/tenant-directory{{alias.ext}}';
14
20
  {{/if}}
15
21
  import { inProcessEvents } from '{{alias.platform}}/events/in-process-events{{alias.ext}}';
16
22
  import { runErasure } from '{{alias.platform}}/privacy/run-erasure{{alias.ext}}';
23
+ {{#if queue.redis}}
24
+ import { openRedis } from '{{alias.platform}}/redis/open-redis{{alias.ext}}';
25
+ {{/if}}
17
26
 
18
27
  // The right to erasure of one data subject (GDPR, article 17), from the command line:
19
- // npm run privacy:erase -- <subject-id> [--operator <who-asks>]
28
+ // npm run privacy:erase -- <subject-id> [--operator <who-asks>] [--rerun]
20
29
  {{#if eventSourcing.on}}
21
30
  // The key of the subject is destroyed first, so every personal value of its stored events reads as
22
- // erased{{#if audit.on}}, and the erasure leaves a dated entry in the audit trail{{/if}}; then every copy a context declared in
23
- // src/platform/privacy/data-subject-copies.ts is erased{{#if tenancy.any}}, in each tenant the tenant directory lists (TENANTS, or the organisations of the identity context){{/if}}.
31
+ // erased; then every copy a context declared in src/platform/privacy/data-subject-copies.ts is
32
+ // erased{{#if tenancy.any}}, in each tenant the tenant directory lists (TENANTS, or the organisations of the identity context){{/if}}{{#if audit.on}}. The key and each copy leave a dated
33
+ // entry in the audit trail, with the operator{{/if}}.
24
34
  {{/if}}
25
35
  {{#unless eventSourcing.on}}
26
36
  // Every copy a context declared in src/platform/privacy/data-subject-copies.ts is erased or
27
37
  // pseudonymised where it lies{{#if tenancy.any}}, in each tenant the tenant directory lists (TENANTS, or the organisations of the identity context){{/if}}: the aggregates of
28
- // this project are rows, so there is no key to destroy.
38
+ // this project are rows, so there is no key to destroy{{#if audit.on}}. Each copy leaves a dated entry in the audit
39
+ // trail, with the operator{{/if}}.
29
40
  {{/unless}}
30
- // The report says what was reached. Running it again completes an erasure that failed half way.
41
+ {{#if housekeeping.any}}
42
+ // {{#if events.outbox}}What the outbox keeps of the person, by the fields src/platform/privacy/personal-events.ts lists{{#if queue.stored}}, and{{/if}}{{/if}}{{#unless events.outbox}}{{#if queue.stored}}And{{/if}}{{/unless}}{{#if queue.stored}} the jobs
43
+ // enqueued with the person as `subject`{{/if}} are erased too.
44
+ {{/if}}
45
+ // The report says what was reached. An id that reached nothing is refused, exit code 1, and announced
46
+ // to nobody: a mistyped id{{#if tenancy.any}}, a tenant missing from the directory{{/if}} or an erasure already complete. --rerun says
47
+ // it is expected, and announces the erasure again: running it completes one that failed half way.
31
48
  // What this script cannot reach: backups, logs, exports and the copies no context declared.
32
49
  const { positionals, values } = parseArgs({
33
50
  allowPositionals: true,
34
- options: { operator: { type: 'string', default: os.userInfo().username } },
51
+ options: {
52
+ operator: { type: 'string', default: os.userInfo().username },
53
+ rerun: { type: 'boolean', default: false },
54
+ },
35
55
  });
36
56
 
37
57
  const [subject] = positionals;
38
58
 
39
59
  if (subject === undefined || positionals.length > 1) {
40
- console.error('Usage: npm run privacy:erase -- <subject-id> [--operator <who-asks>]');
60
+ console.error('Usage: npm run privacy:erase -- <subject-id> [--operator <who-asks>] [--rerun]');
41
61
  process.exit(2);
42
62
  }
43
63
  {{#if tenancy.any}}
@@ -53,11 +73,22 @@ const persistence = {{persistence.await}}openPersistence(loadConfig(process.env)
53
73
  const persistence = openPersistence();
54
74
  {{/unless}}
55
75
 
76
+ {{#if queue.redis}}
77
+ const redis = openRedis(loadConfig(process.env));
78
+
79
+ {{/if}}
56
80
  const application = composeApplication(persistence, {
57
81
  events: inProcessEvents(),
82
+ {{#if audit.on}}
83
+ // Errors alone are logged: a failure whose audit entry could not be written says so, and what the script prints stays clean.
84
+ log: { level: 'error', format: 'json', service: 'privacy-erase', environment: process.env['NODE_ENV'] ?? 'development', scrubMessages: true },
85
+ {{/if}}
58
86
  {{#if http.any}}
59
87
  authenticator: offlineAuthenticator,
60
88
  {{/if}}
89
+ {{#if queue.redis}}
90
+ redis,
91
+ {{/if}}
61
92
  });
62
93
 
63
94
  {{#if tenancy.any}}
@@ -66,6 +97,9 @@ const tenants = await tenantDirectory(persistence, fixedTenants).tenants();
66
97
  if (tenants.length === 0) {
67
98
  console.error('The tenant directory lists no tenant: a write of tenant data is never widened. Name them in TENANTS, comma separated, or open an organisation first.');
68
99
  await application.stop();
100
+ {{#if queue.redis}}
101
+ await redis.close();
102
+ {{/if}}
69
103
  await persistence.close();
70
104
  process.exit(2);
71
105
  }
@@ -76,13 +110,24 @@ try {
76
110
  platform: application.platform,
77
111
  operator: values.operator,
78
112
  correlationId: randomUUID(),
113
+ rerun: values.rerun,
79
114
  {{#if tenancy.any}}
80
115
  tenants,
81
116
  {{/if}}
82
117
  });
83
118
 
84
119
  console.log(JSON.stringify(report, null, 2));
120
+ } catch (error) {
121
+ if (!(error instanceof UnknownDataSubjectError)) {
122
+ throw error;
123
+ }
124
+
125
+ console.error(`${error.message}.{{#if tenancy.any}} Or a tenant the directory does not list.{{/if}} Nothing was announced; --rerun says this person was erased before.`);
126
+ process.exitCode = 1;
85
127
  } finally {
86
128
  await application.stop();
129
+ {{#if queue.redis}}
130
+ await redis.close();
131
+ {{/if}}
87
132
  await persistence.close();
88
133
  }