@ddd-ts-kit/kernel 0.113.2 → 0.115.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 (319) hide show
  1. package/README.fr.md +70 -62
  2. package/README.md +65 -57
  3. package/dist/application/audit/restamped.d.ts +9 -0
  4. package/dist/application/audit/restamped.d.ts.map +1 -0
  5. package/dist/application/audit/restamped.js +9 -0
  6. package/dist/application/audit/restamped.js.map +1 -0
  7. package/dist/application/audit/stamp-update.d.ts +1 -6
  8. package/dist/application/audit/stamp-update.d.ts.map +1 -1
  9. package/dist/application/audit/stamp-update.js +2 -8
  10. package/dist/application/audit/stamp-update.js.map +1 -1
  11. package/dist/application/background/enqueued-job.d.ts +1 -1
  12. package/dist/application/background/enqueued-job.d.ts.map +1 -1
  13. package/dist/application/error-reporting/report-once.d.ts.map +1 -1
  14. package/dist/application/error-reporting/report-once.js +2 -6
  15. package/dist/application/error-reporting/report-once.js.map +1 -1
  16. package/dist/application/event-sourcing/event-envelope.d.ts +2 -1
  17. package/dist/application/event-sourcing/event-envelope.d.ts.map +1 -1
  18. package/dist/application/event-sourcing/event-to-append.d.ts +1 -1
  19. package/dist/application/event-sourcing/event-to-append.d.ts.map +1 -1
  20. package/dist/application/execution/with-actor.d.ts +2 -2
  21. package/dist/application/execution/with-actor.js +3 -3
  22. package/dist/application/execution/with-actor.js.map +1 -1
  23. package/dist/application/files/stored-file.d.ts +3 -3
  24. package/dist/application/files/stored-file.d.ts.map +1 -1
  25. package/dist/application/hydration/hydration.d.ts.map +1 -1
  26. package/dist/application/hydration/hydration.js +3 -2
  27. package/dist/application/hydration/hydration.js.map +1 -1
  28. package/dist/application/logging/hidden-keys.d.ts +8 -0
  29. package/dist/application/logging/hidden-keys.d.ts.map +1 -0
  30. package/dist/application/logging/hidden-keys.js +10 -0
  31. package/dist/application/logging/hidden-keys.js.map +1 -0
  32. package/dist/application/logging/index.d.ts +1 -0
  33. package/dist/application/logging/index.d.ts.map +1 -1
  34. package/dist/application/logging/index.js +1 -0
  35. package/dist/application/logging/index.js.map +1 -1
  36. package/dist/application/observation/safely.d.ts +6 -0
  37. package/dist/application/observation/safely.d.ts.map +1 -0
  38. package/dist/application/observation/safely.js +13 -0
  39. package/dist/application/observation/safely.js.map +1 -0
  40. package/dist/application/persistence/append-changes.d.ts +1 -0
  41. package/dist/application/persistence/append-changes.d.ts.map +1 -1
  42. package/dist/application/persistence/append-changes.js +7 -6
  43. package/dist/application/persistence/append-changes.js.map +1 -1
  44. package/dist/application/persistence/optimistic-update.d.ts +6 -2
  45. package/dist/application/persistence/optimistic-update.d.ts.map +1 -1
  46. package/dist/application/persistence/optimistic-update.js +11 -3
  47. package/dist/application/persistence/optimistic-update.js.map +1 -1
  48. package/dist/application/ports/domain-event-dispatcher.d.ts +1 -1
  49. package/dist/application/ports/domain-event-dispatcher.js +1 -1
  50. package/dist/application/ports/logger.d.ts +3 -3
  51. package/dist/application/ports/unit-of-work.d.ts +1 -1
  52. package/dist/application/ports/unit-of-work.js +1 -1
  53. package/dist/application/read-model/stamp-of.d.ts +11 -4
  54. package/dist/application/read-model/stamp-of.d.ts.map +1 -1
  55. package/dist/application/read-model/stamp-of.js +10 -8
  56. package/dist/application/read-model/stamp-of.js.map +1 -1
  57. package/dist/application/session/anonymous-session.d.ts.map +1 -1
  58. package/dist/application/session/anonymous-session.js +4 -2
  59. package/dist/application/session/anonymous-session.js.map +1 -1
  60. package/dist/application/session/never-issued.d.ts +2 -1
  61. package/dist/application/session/never-issued.d.ts.map +1 -1
  62. package/dist/application/session/never-issued.js +4 -1
  63. package/dist/application/session/never-issued.js.map +1 -1
  64. package/dist/application/session/system-session.d.ts.map +1 -1
  65. package/dist/application/session/system-session.js +2 -2
  66. package/dist/application/session/system-session.js.map +1 -1
  67. package/dist/application/undecided/index.d.ts +3 -0
  68. package/dist/application/undecided/index.d.ts.map +1 -0
  69. package/dist/application/undecided/index.js +3 -0
  70. package/dist/application/undecided/index.js.map +1 -0
  71. package/dist/application/undecided/undecided-error.d.ts +12 -0
  72. package/dist/application/undecided/undecided-error.d.ts.map +1 -0
  73. package/dist/application/undecided/undecided-error.js +15 -0
  74. package/dist/application/undecided/undecided-error.js.map +1 -0
  75. package/dist/application/undecided/undecided.d.ts +7 -0
  76. package/dist/application/undecided/undecided.d.ts.map +1 -0
  77. package/dist/application/undecided/undecided.js +9 -0
  78. package/dist/application/undecided/undecided.js.map +1 -0
  79. package/dist/domain/aggregate-root.d.ts +6 -13
  80. package/dist/domain/aggregate-root.d.ts.map +1 -1
  81. package/dist/domain/aggregate-root.js +10 -16
  82. package/dist/domain/aggregate-root.js.map +1 -1
  83. package/dist/domain/aggregate-tracking.d.ts +30 -0
  84. package/dist/domain/aggregate-tracking.d.ts.map +1 -0
  85. package/dist/domain/aggregate-tracking.js +48 -0
  86. package/dist/domain/aggregate-tracking.js.map +1 -0
  87. package/dist/domain/domain-event.d.ts +4 -0
  88. package/dist/domain/domain-event.d.ts.map +1 -1
  89. package/dist/domain/domain-event.js.map +1 -1
  90. package/dist/domain/errors/domain-error.d.ts.map +1 -1
  91. package/dist/domain/errors/domain-error.js +2 -1
  92. package/dist/domain/errors/domain-error.js.map +1 -1
  93. package/dist/domain/errors/factual-refusal.d.ts.map +1 -1
  94. package/dist/domain/errors/factual-refusal.js +3 -0
  95. package/dist/domain/errors/factual-refusal.js.map +1 -1
  96. package/dist/domain/errors/kit-codes.d.ts +2 -0
  97. package/dist/domain/errors/kit-codes.d.ts.map +1 -1
  98. package/dist/domain/errors/kit-codes.js +2 -0
  99. package/dist/domain/errors/kit-codes.js.map +1 -1
  100. package/dist/domain/event-id-of.d.ts +8 -0
  101. package/dist/domain/event-id-of.d.ts.map +1 -0
  102. package/dist/domain/event-id-of.js +10 -0
  103. package/dist/domain/event-id-of.js.map +1 -0
  104. package/dist/domain/event-rank.d.ts +8 -0
  105. package/dist/domain/event-rank.d.ts.map +1 -0
  106. package/dist/domain/event-rank.js +8 -0
  107. package/dist/domain/event-rank.js.map +1 -0
  108. package/dist/domain/event-sourcing/event-sourced-aggregate.d.ts +0 -1
  109. package/dist/domain/event-sourcing/event-sourced-aggregate.d.ts.map +1 -1
  110. package/dist/domain/event-sourcing/event-sourced-aggregate.js +4 -8
  111. package/dist/domain/event-sourcing/event-sourced-aggregate.js.map +1 -1
  112. package/dist/domain/named-domain-event.d.ts +11 -4
  113. package/dist/domain/named-domain-event.d.ts.map +1 -1
  114. package/dist/domain/named-domain-event.js +14 -3
  115. package/dist/domain/named-domain-event.js.map +1 -1
  116. package/dist/domain/rank-of.d.ts +8 -0
  117. package/dist/domain/rank-of.d.ts.map +1 -0
  118. package/dist/domain/rank-of.js +14 -0
  119. package/dist/domain/rank-of.js.map +1 -0
  120. package/dist/domain/ranked.d.ts +10 -0
  121. package/dist/domain/ranked.d.ts.map +1 -0
  122. package/dist/domain/ranked.js +19 -0
  123. package/dist/domain/ranked.js.map +1 -0
  124. package/dist/domain/result/unwrap.d.ts +1 -0
  125. package/dist/domain/result/unwrap.d.ts.map +1 -1
  126. package/dist/domain/result/unwrap.js +4 -1
  127. package/dist/domain/result/unwrap.js.map +1 -1
  128. package/dist/domain/state-machine/state-machine.d.ts +4 -0
  129. package/dist/domain/state-machine/state-machine.d.ts.map +1 -1
  130. package/dist/domain/state-machine/state-machine.js +14 -4
  131. package/dist/domain/state-machine/state-machine.js.map +1 -1
  132. package/dist/domain/value-object/frozen-copy.d.ts +8 -0
  133. package/dist/domain/value-object/frozen-copy.d.ts.map +1 -0
  134. package/dist/domain/value-object/frozen-copy.js +34 -0
  135. package/dist/domain/value-object/frozen-copy.js.map +1 -0
  136. package/dist/domain/value-object/index.d.ts +2 -0
  137. package/dist/domain/value-object/index.d.ts.map +1 -0
  138. package/dist/domain/value-object/index.js +2 -0
  139. package/dist/domain/value-object/index.js.map +1 -0
  140. package/dist/domain/value-object/is-plain-record.d.ts +3 -0
  141. package/dist/domain/value-object/is-plain-record.d.ts.map +1 -0
  142. package/dist/domain/value-object/is-plain-record.js +9 -0
  143. package/dist/domain/value-object/is-plain-record.js.map +1 -0
  144. package/dist/domain/value-object/same-value.d.ts +8 -0
  145. package/dist/domain/value-object/same-value.d.ts.map +1 -0
  146. package/dist/domain/value-object/same-value.js +43 -0
  147. package/dist/domain/value-object/same-value.js.map +1 -0
  148. package/dist/domain/value-object/value-object.d.ts +28 -0
  149. package/dist/domain/value-object/value-object.d.ts.map +1 -0
  150. package/dist/domain/value-object/value-object.js +24 -0
  151. package/dist/domain/value-object/value-object.js.map +1 -0
  152. package/dist/index.d.ts +9 -12
  153. package/dist/index.d.ts.map +1 -1
  154. package/dist/index.js +9 -12
  155. package/dist/index.js.map +1 -1
  156. package/dist/infrastructure/aggregates/aggregate-mapper.d.ts +21 -0
  157. package/dist/infrastructure/aggregates/aggregate-mapper.d.ts.map +1 -0
  158. package/dist/infrastructure/aggregates/aggregate-mapper.js +18 -0
  159. package/dist/infrastructure/aggregates/aggregate-mapper.js.map +1 -0
  160. package/dist/infrastructure/aggregates/aggregate-save.d.ts +22 -0
  161. package/dist/infrastructure/aggregates/aggregate-save.d.ts.map +1 -0
  162. package/dist/infrastructure/aggregates/aggregate-save.js +2 -0
  163. package/dist/infrastructure/aggregates/aggregate-save.js.map +1 -0
  164. package/dist/infrastructure/aggregates/as-found.d.ts +8 -0
  165. package/dist/infrastructure/aggregates/as-found.d.ts.map +1 -0
  166. package/dist/infrastructure/aggregates/as-found.js +2 -0
  167. package/dist/infrastructure/aggregates/as-found.js.map +1 -0
  168. package/dist/infrastructure/aggregates/give-back.d.ts +9 -0
  169. package/dist/infrastructure/aggregates/give-back.d.ts.map +1 -0
  170. package/dist/infrastructure/aggregates/give-back.js +13 -0
  171. package/dist/infrastructure/aggregates/give-back.js.map +1 -0
  172. package/dist/infrastructure/aggregates/index.d.ts +7 -0
  173. package/dist/infrastructure/aggregates/index.d.ts.map +1 -0
  174. package/dist/infrastructure/aggregates/index.js +7 -0
  175. package/dist/infrastructure/aggregates/index.js.map +1 -0
  176. package/dist/infrastructure/aggregates/loaded-at.d.ts +8 -0
  177. package/dist/infrastructure/aggregates/loaded-at.d.ts.map +1 -0
  178. package/dist/infrastructure/aggregates/loaded-at.js +12 -0
  179. package/dist/infrastructure/aggregates/loaded-at.js.map +1 -0
  180. package/dist/infrastructure/aggregates/noted-as-found.d.ts +8 -0
  181. package/dist/infrastructure/aggregates/noted-as-found.d.ts.map +1 -0
  182. package/dist/infrastructure/aggregates/noted-as-found.js +15 -0
  183. package/dist/infrastructure/aggregates/noted-as-found.js.map +1 -0
  184. package/dist/infrastructure/aggregates/recorded-events-of.d.ts +4 -0
  185. package/dist/infrastructure/aggregates/recorded-events-of.d.ts.map +1 -0
  186. package/dist/infrastructure/aggregates/recorded-events-of.js +6 -0
  187. package/dist/infrastructure/aggregates/recorded-events-of.js.map +1 -0
  188. package/dist/infrastructure/aggregates/save-aggregate-row.d.ts +23 -0
  189. package/dist/infrastructure/aggregates/save-aggregate-row.d.ts.map +1 -0
  190. package/dist/infrastructure/aggregates/save-aggregate-row.js +17 -0
  191. package/dist/infrastructure/aggregates/save-aggregate-row.js.map +1 -0
  192. package/dist/infrastructure/aggregates/stored-at.d.ts +7 -0
  193. package/dist/infrastructure/aggregates/stored-at.d.ts.map +1 -0
  194. package/dist/infrastructure/aggregates/stored-at.js +14 -0
  195. package/dist/infrastructure/aggregates/stored-at.js.map +1 -0
  196. package/dist/infrastructure/aggregates/take-recorded-events.d.ts +9 -0
  197. package/dist/infrastructure/aggregates/take-recorded-events.d.ts.map +1 -0
  198. package/dist/infrastructure/aggregates/take-recorded-events.js +17 -0
  199. package/dist/infrastructure/aggregates/take-recorded-events.js.map +1 -0
  200. package/dist/infrastructure/aggregates/unstored-events-of.d.ts +4 -0
  201. package/dist/infrastructure/aggregates/unstored-events-of.d.ts.map +1 -0
  202. package/dist/infrastructure/aggregates/unstored-events-of.js +7 -0
  203. package/dist/infrastructure/aggregates/unstored-events-of.js.map +1 -0
  204. package/dist/infrastructure/clock/fixed-clock.d.ts +2 -1
  205. package/dist/infrastructure/clock/fixed-clock.d.ts.map +1 -1
  206. package/dist/infrastructure/clock/fixed-clock.js +5 -4
  207. package/dist/infrastructure/clock/fixed-clock.js.map +1 -1
  208. package/dist/infrastructure/context/scoped-actor-context.d.ts.map +1 -1
  209. package/dist/infrastructure/context/scoped-actor-context.js +2 -6
  210. package/dist/infrastructure/context/scoped-actor-context.js.map +1 -1
  211. package/dist/infrastructure/domain-events/announce-domain-events.d.ts +1 -1
  212. package/dist/infrastructure/domain-events/announce-domain-events.js +1 -1
  213. package/dist/infrastructure/domain-events/dispatching-on-save.d.ts +1 -1
  214. package/dist/infrastructure/domain-events/dispatching-on-save.d.ts.map +1 -1
  215. package/dist/infrastructure/domain-events/dispatching-on-save.js +3 -2
  216. package/dist/infrastructure/domain-events/dispatching-on-save.js.map +1 -1
  217. package/dist/infrastructure/domain-events/index.d.ts +13 -0
  218. package/dist/infrastructure/domain-events/index.d.ts.map +1 -0
  219. package/dist/infrastructure/domain-events/index.js +13 -0
  220. package/dist/infrastructure/domain-events/index.js.map +1 -0
  221. package/dist/infrastructure/domain-events/recorded-aggregates.d.ts +2 -5
  222. package/dist/infrastructure/domain-events/recorded-aggregates.d.ts.map +1 -1
  223. package/dist/infrastructure/domain-events/recorded-aggregates.js +3 -5
  224. package/dist/infrastructure/domain-events/recorded-aggregates.js.map +1 -1
  225. package/dist/infrastructure/domain-events/unit-of-work-aborted-error.d.ts +10 -0
  226. package/dist/infrastructure/domain-events/unit-of-work-aborted-error.d.ts.map +1 -0
  227. package/dist/infrastructure/domain-events/unit-of-work-aborted-error.js +13 -0
  228. package/dist/infrastructure/domain-events/unit-of-work-aborted-error.js.map +1 -0
  229. package/dist/infrastructure/domain-events/unit-of-work-over.d.ts +43 -0
  230. package/dist/infrastructure/domain-events/unit-of-work-over.d.ts.map +1 -0
  231. package/dist/infrastructure/domain-events/unit-of-work-over.js +132 -0
  232. package/dist/infrastructure/domain-events/unit-of-work-over.js.map +1 -0
  233. package/dist/infrastructure/domain-events/unit-of-work-scope.d.ts +9 -1
  234. package/dist/infrastructure/domain-events/unit-of-work-scope.d.ts.map +1 -1
  235. package/dist/infrastructure/domain-events/unit-of-work-scope.js.map +1 -1
  236. package/dist/infrastructure/domain-events/unscoped-unit-of-work-error.d.ts +8 -0
  237. package/dist/infrastructure/domain-events/unscoped-unit-of-work-error.d.ts.map +1 -0
  238. package/dist/infrastructure/domain-events/unscoped-unit-of-work-error.js +11 -0
  239. package/dist/infrastructure/domain-events/unscoped-unit-of-work-error.js.map +1 -0
  240. package/dist/infrastructure/domain-events/when-committed.d.ts.map +1 -1
  241. package/dist/infrastructure/domain-events/when-committed.js +2 -9
  242. package/dist/infrastructure/domain-events/when-committed.js.map +1 -1
  243. package/dist/infrastructure/event-sourcing/aggregate-id-of.d.ts +4 -0
  244. package/dist/infrastructure/event-sourcing/aggregate-id-of.d.ts.map +1 -0
  245. package/dist/infrastructure/event-sourcing/aggregate-id-of.js +6 -0
  246. package/dist/infrastructure/event-sourcing/aggregate-id-of.js.map +1 -0
  247. package/dist/infrastructure/event-sourcing/event-serializer.d.ts +3 -4
  248. package/dist/infrastructure/event-sourcing/event-serializer.d.ts.map +1 -1
  249. package/dist/infrastructure/event-sourcing/event-serializer.js +10 -12
  250. package/dist/infrastructure/event-sourcing/event-serializer.js.map +1 -1
  251. package/dist/infrastructure/event-sourcing/event-store-personal-data-export.d.ts.map +1 -1
  252. package/dist/infrastructure/event-sourcing/event-store-personal-data-export.js +1 -5
  253. package/dist/infrastructure/event-sourcing/event-store-personal-data-export.js.map +1 -1
  254. package/dist/infrastructure/events/idempotent.d.ts.map +1 -1
  255. package/dist/infrastructure/events/idempotent.js +9 -3
  256. package/dist/infrastructure/events/idempotent.js.map +1 -1
  257. package/dist/infrastructure/in-memory/as-json-carries.d.ts +9 -0
  258. package/dist/infrastructure/in-memory/as-json-carries.d.ts.map +1 -0
  259. package/dist/infrastructure/in-memory/as-json-carries.js +12 -0
  260. package/dist/infrastructure/in-memory/as-json-carries.js.map +1 -0
  261. package/dist/infrastructure/in-memory/composite-key.d.ts +6 -0
  262. package/dist/infrastructure/in-memory/composite-key.d.ts.map +1 -0
  263. package/dist/infrastructure/in-memory/composite-key.js +8 -0
  264. package/dist/infrastructure/in-memory/composite-key.js.map +1 -0
  265. package/dist/infrastructure/in-memory/in-memory-cache.d.ts +3 -1
  266. package/dist/infrastructure/in-memory/in-memory-cache.d.ts.map +1 -1
  267. package/dist/infrastructure/in-memory/in-memory-cache.js +7 -3
  268. package/dist/infrastructure/in-memory/in-memory-cache.js.map +1 -1
  269. package/dist/infrastructure/in-memory/in-memory-domain-event-dispatcher.d.ts +0 -1
  270. package/dist/infrastructure/in-memory/in-memory-domain-event-dispatcher.d.ts.map +1 -1
  271. package/dist/infrastructure/in-memory/in-memory-domain-event-dispatcher.js +2 -9
  272. package/dist/infrastructure/in-memory/in-memory-domain-event-dispatcher.js.map +1 -1
  273. package/dist/infrastructure/in-memory/in-memory-event-bus.d.ts +7 -14
  274. package/dist/infrastructure/in-memory/in-memory-event-bus.d.ts.map +1 -1
  275. package/dist/infrastructure/in-memory/in-memory-event-bus.js +17 -9
  276. package/dist/infrastructure/in-memory/in-memory-event-bus.js.map +1 -1
  277. package/dist/infrastructure/in-memory/in-memory-event-store.d.ts +1 -0
  278. package/dist/infrastructure/in-memory/in-memory-event-store.d.ts.map +1 -1
  279. package/dist/infrastructure/in-memory/in-memory-event-store.js +11 -10
  280. package/dist/infrastructure/in-memory/in-memory-event-store.js.map +1 -1
  281. package/dist/infrastructure/in-memory/in-memory-process-store.d.ts.map +1 -1
  282. package/dist/infrastructure/in-memory/in-memory-process-store.js +4 -6
  283. package/dist/infrastructure/in-memory/in-memory-process-store.js.map +1 -1
  284. package/dist/infrastructure/in-memory/in-memory-processed-event-store.d.ts.map +1 -1
  285. package/dist/infrastructure/in-memory/in-memory-processed-event-store.js +3 -6
  286. package/dist/infrastructure/in-memory/in-memory-processed-event-store.js.map +1 -1
  287. package/dist/infrastructure/in-memory/in-memory-unit-of-work.d.ts +4 -2
  288. package/dist/infrastructure/in-memory/in-memory-unit-of-work.d.ts.map +1 -1
  289. package/dist/infrastructure/in-memory/in-memory-unit-of-work.js +6 -4
  290. package/dist/infrastructure/in-memory/in-memory-unit-of-work.js.map +1 -1
  291. package/dist/infrastructure/in-memory/in-process-bus.d.ts +1 -0
  292. package/dist/infrastructure/in-memory/in-process-bus.d.ts.map +1 -1
  293. package/dist/infrastructure/in-memory/in-process-bus.js +4 -3
  294. package/dist/infrastructure/in-memory/in-process-bus.js.map +1 -1
  295. package/dist/infrastructure/in-memory/unit-of-work-middleware.d.ts +5 -5
  296. package/dist/infrastructure/in-memory/unit-of-work-middleware.d.ts.map +1 -1
  297. package/dist/infrastructure/in-memory/unit-of-work-middleware.js +13 -4
  298. package/dist/infrastructure/in-memory/unit-of-work-middleware.js.map +1 -1
  299. package/package.json +4 -4
  300. package/dist/domain/event-sourcing/unstored-events.d.ts +0 -8
  301. package/dist/domain/event-sourcing/unstored-events.d.ts.map +0 -1
  302. package/dist/domain/event-sourcing/unstored-events.js +0 -7
  303. package/dist/domain/event-sourcing/unstored-events.js.map +0 -1
  304. package/dist/domain/value-object.d.ts +0 -12
  305. package/dist/domain/value-object.d.ts.map +0 -1
  306. package/dist/domain/value-object.js +0 -40
  307. package/dist/domain/value-object.js.map +0 -1
  308. package/dist/infrastructure/domain-events/within-unit-of-work.d.ts +0 -25
  309. package/dist/infrastructure/domain-events/within-unit-of-work.d.ts.map +0 -1
  310. package/dist/infrastructure/domain-events/within-unit-of-work.js +0 -85
  311. package/dist/infrastructure/domain-events/within-unit-of-work.js.map +0 -1
  312. package/dist/infrastructure/event-sourcing/stored-origins.d.ts +0 -5
  313. package/dist/infrastructure/event-sourcing/stored-origins.d.ts.map +0 -1
  314. package/dist/infrastructure/event-sourcing/stored-origins.js +0 -3
  315. package/dist/infrastructure/event-sourcing/stored-origins.js.map +0 -1
  316. package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts +0 -11
  317. package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts.map +0 -1
  318. package/dist/infrastructure/event-sourcing/stored-stamp-of.js +0 -15
  319. package/dist/infrastructure/event-sourcing/stored-stamp-of.js.map +0 -1
@@ -3,6 +3,7 @@ export * from './describe-error.js';
3
3
  export * from './describe-error-fields.js';
4
4
  export * from './error-description.js';
5
5
  export * from './error-identity.js';
6
+ export * from './hidden-keys.js';
6
7
  export * from './identify-error.js';
7
8
  export * from './is-credential-key.js';
8
9
  export * from './log-fields.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/logging/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/logging/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
@@ -3,6 +3,7 @@ export * from './describe-error.js';
3
3
  export * from './describe-error-fields.js';
4
4
  export * from './error-description.js';
5
5
  export * from './error-identity.js';
6
+ export * from './hidden-keys.js';
6
7
  export * from './identify-error.js';
7
8
  export * from './is-credential-key.js';
8
9
  export * from './log-fields.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/logging/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/logging/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Runs what observes (a hook, a logger, a meter) and keeps its failure to itself: observation
3
+ * must never break what it observes.
4
+ */
5
+ export declare function safely(observe: () => void): void;
6
+ //# sourceMappingURL=safely.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safely.d.ts","sourceRoot":"","sources":["../../../src/application/observation/safely.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAMhD"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Runs what observes (a hook, a logger, a meter) and keeps its failure to itself: observation
3
+ * must never break what it observes.
4
+ */
5
+ export function safely(observe) {
6
+ try {
7
+ observe();
8
+ }
9
+ catch {
10
+ return;
11
+ }
12
+ }
13
+ //# sourceMappingURL=safely.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safely.js","sourceRoot":"","sources":["../../../src/application/observation/safely.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,OAAmB;IACxC,IAAI,CAAC;QACH,OAAO,EAAE,CAAC;IACZ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;AACH,CAAC"}
@@ -13,6 +13,7 @@ export interface StreamChanges {
13
13
  * rejects (a ConcurrencyError: somebody else appended first), the aggregate is left as it was.
14
14
  * An aggregate that recorded nothing still hands its version over, with no event: the store
15
15
  * refuses it when the stream moved meanwhile, so a stale copy is never taken for a current one.
16
+ * What is no aggregate of the kit, of whichever copy of the kernel, is refused with a `TypeError`.
16
17
  */
17
18
  export declare function appendChanges<E extends DomainEvent, S>(aggregate: EventSourcedAggregate<E, S>, append: (changes: StreamChanges) => Promise<void>): Promise<void>;
18
19
  //# sourceMappingURL=append-changes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"append-changes.d.ts","sourceRoot":"","sources":["../../../src/application/persistence/append-changes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAGjG,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;CACzC;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,EAC1D,SAAS,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,EACtC,MAAM,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,GAChD,OAAO,CAAC,IAAI,CAAC,CAOf"}
1
+ {"version":3,"file":"append-changes.d.ts","sourceRoot":"","sources":["../../../src/application/persistence/append-changes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAIjG,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;CACzC;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,EAC1D,SAAS,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,EACtC,MAAM,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,GAChD,OAAO,CAAC,IAAI,CAAC,CAMf"}
@@ -1,4 +1,5 @@
1
- import { unstoredEvents } from '../../domain/event-sourcing/unstored-events.js';
1
+ import { storedAt } from '../../infrastructure/aggregates/stored-at.js';
2
+ import { unstoredEventsOf } from '../../infrastructure/aggregates/unstored-events-of.js';
2
3
  /**
3
4
  * Optimistic concurrency for an event-sourced aggregate: hands what it recorded since it was
4
5
  * loaded to `append`, with the version its stream must still have. Once `append` resolves, the
@@ -6,12 +7,12 @@ import { unstoredEvents } from '../../domain/event-sourcing/unstored-events.js';
6
7
  * rejects (a ConcurrencyError: somebody else appended first), the aggregate is left as it was.
7
8
  * An aggregate that recorded nothing still hands its version over, with no event: the store
8
9
  * refuses it when the stream moved meanwhile, so a stale copy is never taken for a current one.
10
+ * What is no aggregate of the kit, of whichever copy of the kernel, is refused with a `TypeError`.
9
11
  */
10
12
  export async function appendChanges(aggregate, append) {
11
- const unstored = unstoredEvents.get(aggregate) ?? [];
12
- const events = [...unstored];
13
- await append({ expected: aggregate.version, events });
14
- unstored.splice(0, events.length);
15
- aggregate.version += events.length;
13
+ const expected = aggregate.version;
14
+ const events = unstoredEventsOf(aggregate);
15
+ await append({ expected, events });
16
+ storedAt(aggregate, expected + events.length, events.length);
16
17
  }
17
18
  //# sourceMappingURL=append-changes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"append-changes.js","sourceRoot":"","sources":["../../../src/application/persistence/append-changes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAS7E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,SAAsC,EACtC,MAAiD;IAEjD,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IACrD,MAAM,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IAE7B,MAAM,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACtD,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,SAAS,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC;AACrC,CAAC"}
1
+ {"version":3,"file":"append-changes.js","sourceRoot":"","sources":["../../../src/application/persistence/append-changes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AAStF;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,SAAsC,EACtC,MAAiD;IAEjD,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC;IACnC,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAE3C,MAAM,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/D,CAAC"}
@@ -1,7 +1,7 @@
1
1
  export interface VersionStep {
2
2
  /** The version the row must still have: 0 means the aggregate was never saved. */
3
3
  readonly expected: number;
4
- /** The version to write. */
4
+ /** The version to write: the rank of the last event the aggregate recorded, one more than `expected` when it recorded none. */
5
5
  readonly next: number;
6
6
  }
7
7
  /**
@@ -14,9 +14,13 @@ export interface VersionStep {
14
14
  * database refuses for a value another row holds under a unique constraint (an email) raises a
15
15
  * UniqueViolationError (`CONFLICT`), the error of the driver as its cause: the same save would be
16
16
  * refused again. On success the aggregate carries the new version, so it can be saved again.
17
+ * The version moves to the rank of the last event recorded since the row was read, and by one when
18
+ * nothing was recorded: the next event of the aggregate then ranks after every one before it.
19
+ * The aggregate is one of the kit, of whichever copy of the kernel: anything else is refused with
20
+ * a `TypeError` before anything is written.
17
21
  */
18
22
  export declare function optimisticUpdate(aggregate: {
19
23
  readonly id: string | number;
20
- version: number;
24
+ readonly version: number;
21
25
  }, write: (step: VersionStep) => Promise<number>): Promise<void>;
22
26
  //# sourceMappingURL=optimistic-update.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"optimistic-update.d.ts","sourceRoot":"","sources":["../../../src/application/persistence/optimistic-update.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAC5D,KAAK,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,GAC5C,OAAO,CAAC,IAAI,CAAC,CAaf"}
1
+ {"version":3,"file":"optimistic-update.d.ts","sourceRoot":"","sources":["../../../src/application/persistence/optimistic-update.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,WAAW;IAC1B,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,+HAA+H;IAC/H,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EACrE,KAAK,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,GAC5C,OAAO,CAAC,IAAI,CAAC,CAcf"}
@@ -1,5 +1,8 @@
1
+ import { AggregateTracking } from '../../domain/aggregate-tracking.js';
1
2
  import { ConcurrencyError } from '../../domain/errors/concurrency-error.js';
2
3
  import { UniqueViolationError } from '../../domain/errors/unique-violation-error.js';
4
+ import { storedAt } from '../../infrastructure/aggregates/stored-at.js';
5
+ import { unstoredEventsOf } from '../../infrastructure/aggregates/unstored-events-of.js';
3
6
  import { isUniqueViolation } from '../../infrastructure/persistence/is-unique-violation.js';
4
7
  /**
5
8
  * Optimistic concurrency on the `version` column of an aggregate table.
@@ -11,16 +14,21 @@ import { isUniqueViolation } from '../../infrastructure/persistence/is-unique-vi
11
14
  * database refuses for a value another row holds under a unique constraint (an email) raises a
12
15
  * UniqueViolationError (`CONFLICT`), the error of the driver as its cause: the same save would be
13
16
  * refused again. On success the aggregate carries the new version, so it can be saved again.
17
+ * The version moves to the rank of the last event recorded since the row was read, and by one when
18
+ * nothing was recorded: the next event of the aggregate then ranks after every one before it.
19
+ * The aggregate is one of the kit, of whichever copy of the kernel: anything else is refused with
20
+ * a `TypeError` before anything is written.
14
21
  */
15
22
  export async function optimisticUpdate(aggregate, write) {
16
- const expected = aggregate.version;
17
- const next = expected + 1;
23
+ const expected = AggregateTracking.of(aggregate).version;
24
+ const recorded = unstoredEventsOf(aggregate).length;
25
+ const next = expected + Math.max(recorded, 1);
18
26
  const written = await write({ expected, next }).catch((error) => {
19
27
  throw isUniqueViolation(error) ? new UniqueViolationError(aggregate.id, { cause: error }) : error;
20
28
  });
21
29
  if (written !== 1) {
22
30
  throw new ConcurrencyError(aggregate.id);
23
31
  }
24
- aggregate.version = next;
32
+ storedAt(aggregate, next, recorded);
25
33
  }
26
34
  //# sourceMappingURL=optimistic-update.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"optimistic-update.js","sourceRoot":"","sources":["../../../src/application/persistence/optimistic-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sDAAsD,CAAC;AASzF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAA4D,EAC5D,KAA6C;IAE7C,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC;IACnC,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAC,CAAC;IAE1B,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACvE,MAAM,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACpG,CAAC,CAAC,CAAC;IAEH,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;AAC3B,CAAC"}
1
+ {"version":3,"file":"optimistic-update.js","sourceRoot":"","sources":["../../../src/application/persistence/optimistic-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sDAAsD,CAAC;AASzF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAAqE,EACrE,KAA6C;IAE7C,MAAM,QAAQ,GAAG,iBAAiB,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC;IACzD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;IACpD,MAAM,IAAI,GAAG,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAE9C,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACvE,MAAM,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACpG,CAAC,CAAC,CAAC;IAEH,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC"}
@@ -5,7 +5,7 @@ import type { DomainEventSubscription } from '../events/domain-event-subscriptio
5
5
  /**
6
6
  * In-context reactions to what the aggregates recorded. Cross-context reactions use
7
7
  * IntegrationEvents. Use cases do not depend on it: the save of a repository hands over what the
8
- * aggregate recorded, and the unit of work dispatches it at its end (`withinUnitOfWork`).
8
+ * aggregate recorded, and the unit of work dispatches it at its end (`unitOfWorkOver`).
9
9
  */
10
10
  export declare abstract class DomainEventDispatcher {
11
11
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * In-context reactions to what the aggregates recorded. Cross-context reactions use
3
3
  * IntegrationEvents. Use cases do not depend on it: the save of a repository hands over what the
4
- * aggregate recorded, and the unit of work dispatches it at its end (`withinUnitOfWork`).
4
+ * aggregate recorded, and the unit of work dispatches it at its end (`unitOfWorkOver`).
5
5
  */
6
6
  export class DomainEventDispatcher {
7
7
  static {
@@ -32,9 +32,9 @@ export declare abstract class Logger {
32
32
  abstract isLevelEnabled(level: LogLevel): boolean;
33
33
  /**
34
34
  * Resolves once every entry logged so far, through this logger or a child, was handed to its
35
- * destination. Never rejects. Called once, when the process stops, after the last entry: an
36
- * entry logged afterwards may be written or dropped, depending on the adapter, and never
37
- * throws; a second call resolves too.
35
+ * destination. Never rejects, and ends nothing: an entry logged afterwards is written like the
36
+ * others, and a later call flushes it in turn. The application calls it when it stops, after
37
+ * the last entry of its modules.
38
38
  */
39
39
  abstract flush(): Promise<void>;
40
40
  }
@@ -2,7 +2,7 @@
2
2
  * Runs `work` atomically. The domain events of the aggregates it saves wait until `work` has
3
3
  * returned, then are dispatched inside it, before the commit: what their handlers write, the
4
4
  * outbox included, commits or rolls back with it. The handlers of the `after-commit` phase run
5
- * once it has committed. An implementation gets all of it from `withinUnitOfWork`.
5
+ * once it has committed. An implementation gets all of it from `unitOfWorkOver`.
6
6
  */
7
7
  export declare abstract class UnitOfWork {
8
8
  abstract run<T>(work: () => Promise<T>): Promise<T>;
@@ -2,7 +2,7 @@
2
2
  * Runs `work` atomically. The domain events of the aggregates it saves wait until `work` has
3
3
  * returned, then are dispatched inside it, before the commit: what their handlers write, the
4
4
  * outbox included, commits or rolls back with it. The handlers of the `after-commit` phase run
5
- * once it has committed. An implementation gets all of it from `withinUnitOfWork`.
5
+ * once it has committed. An implementation gets all of it from `unitOfWorkOver`.
6
6
  */
7
7
  export class UnitOfWork {
8
8
  static {
@@ -2,9 +2,16 @@ import type { DomainEvent } from '../../domain/domain-event.js';
2
2
  import type { IntegrationEvent } from '../events/integration-event.js';
3
3
  import type { EventStamp } from './event-stamp.js';
4
4
  /**
5
- * The stamp of an event, for the row it changes. An integration event gives its id and
6
- * instant; a domain event, which has no id, is known by its name and aggregate. Pass the
7
- * per-key `version` when the event carries one: the order then no longer relies on clocks.
5
+ * The stamp of an event, for the row it changes.
6
+ *
7
+ * A domain event gives its identity, its instant and, as `version`, its rank in its aggregate: the
8
+ * rows of one aggregate are ordered by its history and not by clocks, whether the event comes from
9
+ * a save or from its stream. A key that the events of several aggregates write has no single
10
+ * history: stamp it `{ eventId: eventIdOf(event), occurredAt: event.occurredAt }`, and the instants decide.
11
+ *
12
+ * An integration event gives its id and its instant; pass the per-key `version` when its payload
13
+ * carries one, and the order no longer relies on clocks either.
8
14
  */
9
- export declare function stampOf(event: IntegrationEvent | DomainEvent, version?: number): EventStamp;
15
+ export declare function stampOf(event: DomainEvent): EventStamp;
16
+ export declare function stampOf(event: IntegrationEvent, version?: number): EventStamp;
10
17
  //# sourceMappingURL=stamp-of.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stamp-of.d.ts","sourceRoot":"","sources":["../../../src/application/read-model/stamp-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,gBAAgB,GAAG,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAO3F"}
1
+ {"version":3,"file":"stamp-of.d.ts","sourceRoot":"","sources":["../../../src/application/read-model/stamp-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAAC;AACxD,wBAAgB,OAAO,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC"}
@@ -1,12 +1,14 @@
1
- /**
2
- * The stamp of an event, for the row it changes. An integration event gives its id and
3
- * instant; a domain event, which has no id, is known by its name and aggregate. Pass the
4
- * per-key `version` when the event carries one: the order then no longer relies on clocks.
5
- */
1
+ import { eventIdOf } from '../../domain/event-id-of.js';
2
+ import { rankOf } from '../../domain/rank-of.js';
6
3
  export function stampOf(event, version) {
7
- const stamp = typeof event.occurredAt === 'string'
8
- ? { eventId: 'id' in event ? event.id : '', occurredAt: new Date(event.occurredAt) }
9
- : { eventId: 'name' in event ? `${event.name}:${event.aggregateId}` : '', occurredAt: event.occurredAt };
4
+ if (isDomainEvent(event)) {
5
+ return { eventId: eventIdOf(event), occurredAt: event.occurredAt, version: rankOf(event) };
6
+ }
7
+ const stamp = { eventId: event.id, occurredAt: new Date(event.occurredAt) };
10
8
  return version === undefined ? stamp : { ...stamp, version };
11
9
  }
10
+ /** An integration event writes its instant as text, a domain event keeps a `Date`. */
11
+ function isDomainEvent(event) {
12
+ return typeof event.occurredAt !== 'string';
13
+ }
12
14
  //# sourceMappingURL=stamp-of.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stamp-of.js","sourceRoot":"","sources":["../../../src/application/read-model/stamp-of.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAqC,EAAE,OAAgB;IAC7E,MAAM,KAAK,GACT,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ;QAClC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;QACpF,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC;IAE7G,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAC;AAC/D,CAAC"}
1
+ {"version":3,"file":"stamp-of.js","sourceRoot":"","sources":["../../../src/application/read-model/stamp-of.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAkB9C,MAAM,UAAU,OAAO,CAAC,KAAqC,EAAE,OAAgB;IAC7E,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC7F,CAAC;IAED,MAAM,KAAK,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;IAE5E,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAC;AAC/D,CAAC;AAED,sFAAsF;AACtF,SAAS,aAAa,CAAC,KAAqC;IAC1D,OAAO,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ,CAAC;AAC9C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"anonymous-session.d.ts","sourceRoot":"","sources":["../../../src/application/session/anonymous-session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUzC,8EAA8E;AAC9E,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C"}
1
+ {"version":3,"file":"anonymous-session.d.ts","sourceRoot":"","sources":["../../../src/application/session/anonymous-session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYzC,8EAA8E;AAC9E,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C"}
@@ -1,9 +1,11 @@
1
1
  import { anonymousActor } from '../actor/anonymous-actor.js';
2
- import { NEVER_ISSUED } from './never-issued.js';
2
+ import { neverIssued } from './never-issued.js';
3
3
  const ANONYMOUS_SESSION = Object.freeze({
4
4
  id: 'anonymous',
5
5
  actor: anonymousActor(),
6
- issuedAt: NEVER_ISSUED,
6
+ get issuedAt() {
7
+ return neverIssued();
8
+ },
7
9
  authenticationMethod: 'none',
8
10
  extensions: Object.freeze({}),
9
11
  });
@@ -1 +1 @@
1
- {"version":3,"file":"anonymous-session.js","sourceRoot":"","sources":["../../../src/application/session/anonymous-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,iBAAiB,GAAY,MAAM,CAAC,MAAM,CAAC;IAC/C,EAAE,EAAE,WAAW;IACf,KAAK,EAAE,cAAc,EAAE;IACvB,QAAQ,EAAE,YAAY;IACtB,oBAAoB,EAAE,MAAM;IAC5B,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;CAC9B,CAAC,CAAC;AAEH,8EAA8E;AAC9E,MAAM,UAAU,gBAAgB;IAC9B,OAAO,iBAAiB,CAAC;AAC3B,CAAC"}
1
+ {"version":3,"file":"anonymous-session.js","sourceRoot":"","sources":["../../../src/application/session/anonymous-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,MAAM,iBAAiB,GAAY,MAAM,CAAC,MAAM,CAAC;IAC/C,EAAE,EAAE,WAAW;IACf,KAAK,EAAE,cAAc,EAAE;IACvB,IAAI,QAAQ;QACV,OAAO,WAAW,EAAE,CAAC;IACvB,CAAC;IACD,oBAAoB,EAAE,MAAM;IAC5B,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;CAC9B,CAAC,CAAC;AAEH,8EAA8E;AAC9E,MAAM,UAAU,gBAAgB;IAC9B,OAAO,iBAAiB,CAAC;AAC3B,CAAC"}
@@ -1,2 +1,3 @@
1
- export declare const NEVER_ISSUED: Date;
1
+ /** The instant of a session nothing issued. A date of its own each time: a `Date` can be changed by who holds it. */
2
+ export declare function neverIssued(): Date;
2
3
  //# sourceMappingURL=never-issued.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"never-issued.d.ts","sourceRoot":"","sources":["../../../src/application/session/never-issued.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,MAAc,CAAC"}
1
+ {"version":3,"file":"never-issued.d.ts","sourceRoot":"","sources":["../../../src/application/session/never-issued.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
@@ -1,2 +1,5 @@
1
- export const NEVER_ISSUED = new Date(0);
1
+ /** The instant of a session nothing issued. A date of its own each time: a `Date` can be changed by who holds it. */
2
+ export function neverIssued() {
3
+ return new Date(0);
4
+ }
2
5
  //# sourceMappingURL=never-issued.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"never-issued.js","sourceRoot":"","sources":["../../../src/application/session/never-issued.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"never-issued.js","sourceRoot":"","sources":["../../../src/application/session/never-issued.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,MAAM,UAAU,WAAW;IACzB,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"system-session.d.ts","sourceRoot":"","sources":["../../../src/application/session/system-session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,IAAmB,GAAG,OAAO,CAUlF"}
1
+ {"version":3,"file":"system-session.d.ts","sourceRoot":"","sources":["../../../src/application/session/system-session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,IAAoB,GAAG,OAAO,CAUnF"}
@@ -1,7 +1,7 @@
1
1
  import { systemActor } from '../actor/system-actor.js';
2
- import { NEVER_ISSUED } from './never-issued.js';
2
+ import { neverIssued } from './never-issued.js';
3
3
  /** The session of the system acting on its own behalf: a scheduled job, a consumer. */
4
- export function systemSession(name, issuedAt = NEVER_ISSUED) {
4
+ export function systemSession(name, issuedAt = neverIssued()) {
5
5
  const actor = systemActor(name);
6
6
  return Object.freeze({
7
7
  id: actor.id,
@@ -1 +1 @@
1
- {"version":3,"file":"system-session.js","sourceRoot":"","sources":["../../../src/application/session/system-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,QAAQ,GAAS,YAAY;IACvE,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAEhC,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,KAAK;QACL,QAAQ;QACR,oBAAoB,EAAE,SAAS;QAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;KAC9B,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"system-session.js","sourceRoot":"","sources":["../../../src/application/session/system-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,QAAQ,GAAS,WAAW,EAAE;IACxE,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAEhC,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,KAAK;QACL,QAAQ;QACR,oBAAoB,EAAE,SAAS;QAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;KAC9B,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './undecided.js';
2
+ export * from './undecided-error.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/undecided/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './undecided.js';
2
+ export * from './undecided-error.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/undecided/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** The code of what was generated and is not written yet: answered 501. */
2
+ export declare const NOT_IMPLEMENTED = "NOT_IMPLEMENTED";
3
+ /**
4
+ * What a generated stub answers until its decision is written: it refuses by name, where a
5
+ * success that did nothing would pass for the behaviour. A fault of the software, not a business
6
+ * refusal: a route answers it 501, a reaction or a job fails with it, the error reporting sees it.
7
+ */
8
+ export declare class UndecidedError extends Error {
9
+ readonly code = "NOT_IMPLEMENTED";
10
+ constructor(what: string);
11
+ }
12
+ //# sourceMappingURL=undecided-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undecided-error.d.ts","sourceRoot":"","sources":["../../../src/application/undecided/undecided-error.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAEjD;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,qBAAmB;IAEhC,YAAY,IAAI,EAAE,MAAM,EAGvB;CACF"}
@@ -0,0 +1,15 @@
1
+ /** The code of what was generated and is not written yet: answered 501. */
2
+ export const NOT_IMPLEMENTED = 'NOT_IMPLEMENTED';
3
+ /**
4
+ * What a generated stub answers until its decision is written: it refuses by name, where a
5
+ * success that did nothing would pass for the behaviour. A fault of the software, not a business
6
+ * refusal: a route answers it 501, a reaction or a job fails with it, the error reporting sees it.
7
+ */
8
+ export class UndecidedError extends Error {
9
+ code = NOT_IMPLEMENTED;
10
+ constructor(what) {
11
+ super(`${what} is not decided yet: its TODO says what to write`);
12
+ this.name = 'UndecidedError';
13
+ }
14
+ }
15
+ //# sourceMappingURL=undecided-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undecided-error.js","sourceRoot":"","sources":["../../../src/application/undecided/undecided-error.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,GAAG,eAAe,CAAC;IAEhC,YAAY,IAAY;QACtB,KAAK,CAAC,GAAG,IAAI,kDAAkD,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import { UndecidedError } from './undecided-error.js';
2
+ /**
3
+ * The refusal of a stub, named after what is left to decide:
4
+ * `throw undecided('what "confirm order" does')`.
5
+ */
6
+ export declare function undecided(what: string): UndecidedError;
7
+ //# sourceMappingURL=undecided.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undecided.d.ts","sourceRoot":"","sources":["../../../src/application/undecided/undecided.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAEtD"}
@@ -0,0 +1,9 @@
1
+ import { UndecidedError } from './undecided-error.js';
2
+ /**
3
+ * The refusal of a stub, named after what is left to decide:
4
+ * `throw undecided('what "confirm order" does')`.
5
+ */
6
+ export function undecided(what) {
7
+ return new UndecidedError(what);
8
+ }
9
+ //# sourceMappingURL=undecided.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undecided.js","sourceRoot":"","sources":["../../../src/application/undecided/undecided.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
@@ -4,22 +4,15 @@ import { Entity } from './entity.js';
4
4
  * Consistency boundary and transaction boundary. Only the root is reachable from
5
5
  * outside; state changes go through intention-revealing methods that guard the
6
6
  * invariants and record domain events.
7
+ *
8
+ * The model records and reads its version; it moves neither. The repository adapter says at
9
+ * which version it loaded the aggregate (`loadedAt`), the save moves it (`optimisticUpdate`), and
10
+ * the recorded events leave with the save (`dispatchingOnSave`).
7
11
  */
8
12
  export declare abstract class AggregateRoot<Id extends string | number = string> extends Entity<Id> {
9
- /** Optimistic concurrency token, managed by the repository adapter. */
10
- version: number;
11
- private readonly events;
12
- /**
13
- * The recorded events are no part of the state: they are kept out of enumeration, so that
14
- * comparing, spreading or serialising an aggregate never sees what it has yet to announce.
15
- */
16
13
  protected constructor(id: Id);
17
- /**
18
- * Hands over the recorded events and clears them. Called for a handler by the save of the
19
- * repository (`dispatchingOnSave`), and by a spec that asserts what an aggregate recorded;
20
- * never by a use case or a repository adapter.
21
- */
22
- pullEvents(): DomainEvent[];
14
+ /** Optimistic concurrency token: the version the store holds of this aggregate, 0 until its first save. */
15
+ get version(): number;
23
16
  protected record(event: DomainEvent): void;
24
17
  }
25
18
  //# sourceMappingURL=aggregate-root.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate-root.d.ts","sourceRoot":"","sources":["../../src/domain/aggregate-root.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;GAIG;AACH,8BAAsB,aAAa,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,CAAE,SAAQ,MAAM,CAAC,EAAE,CAAC;IACzF,uEAAuE;IACvE,OAAO,SAAK;IAEZ,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAE5C;;;OAGG;IACH,SAAS,aAAa,EAAE,EAAE,EAAE,EAG3B;IAED;;;;OAIG;IACH,UAAU,IAAI,WAAW,EAAE,CAE1B;IAED,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAEzC;CACF"}
1
+ {"version":3,"file":"aggregate-root.d.ts","sourceRoot":"","sources":["../../src/domain/aggregate-root.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;;;GAQG;AACH,8BAAsB,aAAa,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,CAAE,SAAQ,MAAM,CAAC,EAAE,CAAC;IACzF,SAAS,aAAa,EAAE,EAAE,EAAE,EAG3B;IAED,2GAA2G;IAC3G,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAEzC;CACF"}
@@ -1,31 +1,25 @@
1
+ import { AggregateTracking } from './aggregate-tracking.js';
1
2
  import { Entity } from './entity.js';
2
3
  /**
3
4
  * Consistency boundary and transaction boundary. Only the root is reachable from
4
5
  * outside; state changes go through intention-revealing methods that guard the
5
6
  * invariants and record domain events.
7
+ *
8
+ * The model records and reads its version; it moves neither. The repository adapter says at
9
+ * which version it loaded the aggregate (`loadedAt`), the save moves it (`optimisticUpdate`), and
10
+ * the recorded events leave with the save (`dispatchingOnSave`).
6
11
  */
7
12
  export class AggregateRoot extends Entity {
8
- /** Optimistic concurrency token, managed by the repository adapter. */
9
- version = 0;
10
- events = [];
11
- /**
12
- * The recorded events are no part of the state: they are kept out of enumeration, so that
13
- * comparing, spreading or serialising an aggregate never sees what it has yet to announce.
14
- */
15
13
  constructor(id) {
16
14
  super(id);
17
- Object.defineProperty(this, 'events', { enumerable: false });
15
+ AggregateTracking.start(this);
18
16
  }
19
- /**
20
- * Hands over the recorded events and clears them. Called for a handler by the save of the
21
- * repository (`dispatchingOnSave`), and by a spec that asserts what an aggregate recorded;
22
- * never by a use case or a repository adapter.
23
- */
24
- pullEvents() {
25
- return this.events.splice(0);
17
+ /** Optimistic concurrency token: the version the store holds of this aggregate, 0 until its first save. */
18
+ get version() {
19
+ return AggregateTracking.of(this).version;
26
20
  }
27
21
  record(event) {
28
- this.events.push(event);
22
+ AggregateTracking.of(this).record(event);
29
23
  }
30
24
  }
31
25
  //# sourceMappingURL=aggregate-root.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate-root.js","sourceRoot":"","sources":["../../src/domain/aggregate-root.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;GAIG;AACH,MAAM,OAAgB,aAAmD,SAAQ,MAAU;IACzF,uEAAuE;IACvE,OAAO,GAAG,CAAC,CAAC;IAEK,MAAM,GAAkB,EAAE,CAAC;IAE5C;;;OAGG;IACH,YAAsB,EAAM;QAC1B,KAAK,CAAC,EAAE,CAAC,CAAC;QACV,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED;;;;OAIG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC;IAES,MAAM,CAAC,KAAkB;QACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;CACF"}
1
+ {"version":3,"file":"aggregate-root.js","sourceRoot":"","sources":["../../src/domain/aggregate-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;;;GAQG;AACH,MAAM,OAAgB,aAAmD,SAAQ,MAAU;IACzF,YAAsB,EAAM;QAC1B,KAAK,CAAC,EAAE,CAAC,CAAC;QACV,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,2GAA2G;IAC3G,IAAI,OAAO;QACT,OAAO,iBAAiB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;IAC5C,CAAC;IAES,MAAM,CAAC,KAAkB;QACjC,iBAAiB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ import type { DomainEvent } from './domain-event.js';
2
+ /**
3
+ * What an aggregate carries for the infrastructure and never shows to its model: the version its
4
+ * store holds of it and the events it has yet to announce. The aggregate records; the functions of
5
+ * the infrastructure (`loadedAt`, `optimisticUpdate`, `appendChanges`, `takeRecordedEvents`) move
6
+ * the rest.
7
+ */
8
+ export declare class AggregateTracking {
9
+ /** The version the store holds: 0 until the first save. */
10
+ version: number;
11
+ /** Recorded and not announced yet, oldest first. */
12
+ readonly recorded: DomainEvent[];
13
+ /** How many of the recorded events, from the oldest, a save already wrote. */
14
+ appended: number;
15
+ /**
16
+ * Starts tracking an aggregate, out of enumeration: comparing, spreading or serialising it never
17
+ * sees a version nor what it has yet to announce.
18
+ */
19
+ static start(aggregate: object): void;
20
+ /** The tracking of an aggregate, whichever copy of the kernel built it; anything else is refused. */
21
+ static of(aggregate: object): AggregateTracking;
22
+ static follows(value: unknown): value is object;
23
+ /**
24
+ * Keeps an event the aggregate announces, at its rank: one past the last fact the store or the
25
+ * aggregate holds. The version follows the ranks at each save, so a rank is given once in the
26
+ * life of the aggregate.
27
+ */
28
+ record(event: DomainEvent): void;
29
+ }
30
+ //# sourceMappingURL=aggregate-tracking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate-tracking.d.ts","sourceRoot":"","sources":["../../src/domain/aggregate-tracking.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMlD;;;;;GAKG;AACH,qBAAa,iBAAiB;IAC5B,2DAA2D;IAC3D,OAAO,SAAK;IAEZ,oDAAoD;IACpD,QAAQ,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAM;IAEtC,8EAA8E;IAC9E,QAAQ,SAAK;IAEb;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEpC;IAED,qGAAqG;IACrG,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CAU9C;IAED,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9C;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAE/B;CACF"}