@ddd-ts-kit/kernel 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (499) hide show
  1. package/README.md +207 -2
  2. package/dist/application/criteria/index.d.ts +33 -0
  3. package/dist/application/criteria/index.d.ts.map +1 -0
  4. package/dist/application/criteria/index.js +33 -0
  5. package/dist/application/criteria/index.js.map +1 -0
  6. package/dist/application/event-sourcing/appended.d.ts +8 -0
  7. package/dist/application/event-sourcing/appended.d.ts.map +1 -0
  8. package/dist/application/event-sourcing/appended.js +2 -0
  9. package/dist/application/event-sourcing/appended.js.map +1 -0
  10. package/dist/application/event-sourcing/define-stored-event.d.ts +10 -0
  11. package/dist/application/event-sourcing/define-stored-event.d.ts.map +1 -0
  12. package/dist/application/event-sourcing/define-stored-event.js +22 -0
  13. package/dist/application/event-sourcing/define-stored-event.js.map +1 -0
  14. package/dist/application/event-sourcing/erased-personal-data.d.ts +3 -0
  15. package/dist/application/event-sourcing/erased-personal-data.d.ts.map +1 -0
  16. package/dist/application/event-sourcing/erased-personal-data.js +3 -0
  17. package/dist/application/event-sourcing/erased-personal-data.js.map +1 -0
  18. package/dist/application/event-sourcing/event-envelope.d.ts +9 -0
  19. package/dist/application/event-sourcing/event-envelope.d.ts.map +1 -0
  20. package/dist/application/event-sourcing/event-envelope.js +2 -0
  21. package/dist/application/event-sourcing/event-envelope.js.map +1 -0
  22. package/dist/application/event-sourcing/event-to-append.d.ts +15 -0
  23. package/dist/application/event-sourcing/event-to-append.d.ts.map +1 -0
  24. package/dist/application/event-sourcing/event-to-append.js +2 -0
  25. package/dist/application/event-sourcing/event-to-append.js.map +1 -0
  26. package/dist/application/event-sourcing/index.d.ts +21 -0
  27. package/dist/application/event-sourcing/index.d.ts.map +1 -0
  28. package/dist/application/event-sourcing/index.js +21 -0
  29. package/dist/application/event-sourcing/index.js.map +1 -0
  30. package/dist/application/event-sourcing/is-stored-data.d.ts +5 -0
  31. package/dist/application/event-sourcing/is-stored-data.d.ts.map +1 -0
  32. package/dist/application/event-sourcing/is-stored-data.js +5 -0
  33. package/dist/application/event-sourcing/is-stored-data.js.map +1 -0
  34. package/dist/application/event-sourcing/is-stored-list.d.ts +4 -0
  35. package/dist/application/event-sourcing/is-stored-list.d.ts.map +1 -0
  36. package/dist/application/event-sourcing/is-stored-list.js +5 -0
  37. package/dist/application/event-sourcing/is-stored-list.js.map +1 -0
  38. package/dist/application/event-sourcing/personal-data.d.ts +14 -0
  39. package/dist/application/event-sourcing/personal-data.d.ts.map +1 -0
  40. package/dist/application/event-sourcing/personal-data.js +9 -0
  41. package/dist/application/event-sourcing/personal-data.js.map +1 -0
  42. package/dist/application/event-sourcing/stored-data-of.d.ts +9 -0
  43. package/dist/application/event-sourcing/stored-data-of.d.ts.map +1 -0
  44. package/dist/application/event-sourcing/stored-data-of.js +40 -0
  45. package/dist/application/event-sourcing/stored-data-of.js.map +1 -0
  46. package/dist/application/event-sourcing/stored-data.d.ts +6 -0
  47. package/dist/application/event-sourcing/stored-data.d.ts.map +1 -0
  48. package/dist/application/event-sourcing/stored-data.js +2 -0
  49. package/dist/application/event-sourcing/stored-data.js.map +1 -0
  50. package/dist/application/event-sourcing/stored-event-data.d.ts +25 -0
  51. package/dist/application/event-sourcing/stored-event-data.d.ts.map +1 -0
  52. package/dist/application/event-sourcing/stored-event-data.js +82 -0
  53. package/dist/application/event-sourcing/stored-event-data.js.map +1 -0
  54. package/dist/application/event-sourcing/stored-event-spec.d.ts +20 -0
  55. package/dist/application/event-sourcing/stored-event-spec.d.ts.map +1 -0
  56. package/dist/application/event-sourcing/stored-event-spec.js +2 -0
  57. package/dist/application/event-sourcing/stored-event-spec.js.map +1 -0
  58. package/dist/application/event-sourcing/stored-event-type.d.ts +14 -0
  59. package/dist/application/event-sourcing/stored-event-type.d.ts.map +1 -0
  60. package/dist/application/event-sourcing/stored-event-type.js +2 -0
  61. package/dist/application/event-sourcing/stored-event-type.js.map +1 -0
  62. package/dist/application/event-sourcing/stored-event-types.d.ts +9 -0
  63. package/dist/application/event-sourcing/stored-event-types.d.ts.map +1 -0
  64. package/dist/application/event-sourcing/stored-event-types.js +2 -0
  65. package/dist/application/event-sourcing/stored-event-types.js.map +1 -0
  66. package/dist/application/event-sourcing/stored-event.d.ts +12 -0
  67. package/dist/application/event-sourcing/stored-event.d.ts.map +1 -0
  68. package/dist/application/event-sourcing/stored-event.js +2 -0
  69. package/dist/application/event-sourcing/stored-event.js.map +1 -0
  70. package/dist/application/event-sourcing/stored-json.d.ts +5 -0
  71. package/dist/application/event-sourcing/stored-json.d.ts.map +1 -0
  72. package/dist/application/event-sourcing/stored-json.js +2 -0
  73. package/dist/application/event-sourcing/stored-json.js.map +1 -0
  74. package/dist/application/event-sourcing/stored-snapshot.d.ts +11 -0
  75. package/dist/application/event-sourcing/stored-snapshot.d.ts.map +1 -0
  76. package/dist/application/event-sourcing/stored-snapshot.js +2 -0
  77. package/dist/application/event-sourcing/stored-snapshot.js.map +1 -0
  78. package/dist/application/event-sourcing/subject-key.d.ts +10 -0
  79. package/dist/application/event-sourcing/subject-key.d.ts.map +1 -0
  80. package/dist/application/event-sourcing/subject-key.js +2 -0
  81. package/dist/application/event-sourcing/subject-key.js.map +1 -0
  82. package/dist/application/event-sourcing/unreadable-event-error.d.ts +5 -0
  83. package/dist/application/event-sourcing/unreadable-event-error.d.ts.map +1 -0
  84. package/dist/application/event-sourcing/unreadable-event-error.js +8 -0
  85. package/dist/application/event-sourcing/unreadable-event-error.js.map +1 -0
  86. package/dist/application/event-sourcing/upcaster.d.ts +4 -0
  87. package/dist/application/event-sourcing/upcaster.d.ts.map +1 -0
  88. package/dist/application/event-sourcing/upcaster.js +2 -0
  89. package/dist/application/event-sourcing/upcaster.js.map +1 -0
  90. package/dist/application/files/accepts-media-type.d.ts +3 -0
  91. package/dist/application/files/accepts-media-type.d.ts.map +1 -0
  92. package/dist/application/files/accepts-media-type.js +11 -0
  93. package/dist/application/files/accepts-media-type.js.map +1 -0
  94. package/dist/application/files/assert-expiry.d.ts +3 -0
  95. package/dist/application/files/assert-expiry.d.ts.map +1 -0
  96. package/dist/application/files/assert-expiry.js +10 -0
  97. package/dist/application/files/assert-expiry.js.map +1 -0
  98. package/dist/application/files/assert-file-key.d.ts +3 -0
  99. package/dist/application/files/assert-file-key.d.ts.map +1 -0
  100. package/dist/application/files/assert-file-key.js +10 -0
  101. package/dist/application/files/assert-file-key.js.map +1 -0
  102. package/dist/application/files/assert-final-key.d.ts +3 -0
  103. package/dist/application/files/assert-final-key.d.ts.map +1 -0
  104. package/dist/application/files/assert-final-key.js +11 -0
  105. package/dist/application/files/assert-final-key.js.map +1 -0
  106. package/dist/application/files/content-disposition.d.ts +3 -0
  107. package/dist/application/files/content-disposition.d.ts.map +1 -0
  108. package/dist/application/files/content-disposition.js +9 -0
  109. package/dist/application/files/content-disposition.js.map +1 -0
  110. package/dist/application/files/content-expectation.d.ts +6 -0
  111. package/dist/application/files/content-expectation.d.ts.map +1 -0
  112. package/dist/application/files/content-expectation.js +2 -0
  113. package/dist/application/files/content-expectation.js.map +1 -0
  114. package/dist/application/files/content-matches.d.ts +7 -0
  115. package/dist/application/files/content-matches.d.ts.map +1 -0
  116. package/dist/application/files/content-matches.js +39 -0
  117. package/dist/application/files/content-matches.js.map +1 -0
  118. package/dist/application/files/download-url-options.d.ts +7 -0
  119. package/dist/application/files/download-url-options.d.ts.map +1 -0
  120. package/dist/application/files/download-url-options.js +2 -0
  121. package/dist/application/files/download-url-options.js.map +1 -0
  122. package/dist/application/files/file-content.d.ts +8 -0
  123. package/dist/application/files/file-content.d.ts.map +1 -0
  124. package/dist/application/files/file-content.js +2 -0
  125. package/dist/application/files/file-content.js.map +1 -0
  126. package/dist/application/files/file-error.d.ts +28 -0
  127. package/dist/application/files/file-error.d.ts.map +1 -0
  128. package/dist/application/files/file-error.js +29 -0
  129. package/dist/application/files/file-error.js.map +1 -0
  130. package/dist/application/files/file-metadata.d.ts +10 -0
  131. package/dist/application/files/file-metadata.d.ts.map +1 -0
  132. package/dist/application/files/file-metadata.js +2 -0
  133. package/dist/application/files/file-metadata.js.map +1 -0
  134. package/dist/application/files/file-source.d.ts +4 -0
  135. package/dist/application/files/file-source.d.ts.map +1 -0
  136. package/dist/application/files/file-source.js +2 -0
  137. package/dist/application/files/file-source.js.map +1 -0
  138. package/dist/application/files/file-upload.d.ts +25 -0
  139. package/dist/application/files/file-upload.d.ts.map +1 -0
  140. package/dist/application/files/file-upload.js +36 -0
  141. package/dist/application/files/file-upload.js.map +1 -0
  142. package/dist/application/files/index.d.ts +31 -0
  143. package/dist/application/files/index.d.ts.map +1 -0
  144. package/dist/application/files/index.js +31 -0
  145. package/dist/application/files/index.js.map +1 -0
  146. package/dist/application/files/inspection-limits.d.ts +8 -0
  147. package/dist/application/files/inspection-limits.d.ts.map +1 -0
  148. package/dist/application/files/inspection-limits.js +2 -0
  149. package/dist/application/files/inspection-limits.js.map +1 -0
  150. package/dist/application/files/is-file-key.d.ts +7 -0
  151. package/dist/application/files/is-file-key.d.ts.map +1 -0
  152. package/dist/application/files/is-file-key.js +11 -0
  153. package/dist/application/files/is-file-key.js.map +1 -0
  154. package/dist/application/files/listed-file.d.ts +7 -0
  155. package/dist/application/files/listed-file.d.ts.map +1 -0
  156. package/dist/application/files/listed-file.js +2 -0
  157. package/dist/application/files/listed-file.js.map +1 -0
  158. package/dist/application/files/max-signed-url-seconds.d.ts +3 -0
  159. package/dist/application/files/max-signed-url-seconds.d.ts.map +1 -0
  160. package/dist/application/files/max-signed-url-seconds.js +3 -0
  161. package/dist/application/files/max-signed-url-seconds.js.map +1 -0
  162. package/dist/application/files/media-type-of.d.ts +3 -0
  163. package/dist/application/files/media-type-of.d.ts.map +1 -0
  164. package/dist/application/files/media-type-of.js +5 -0
  165. package/dist/application/files/media-type-of.js.map +1 -0
  166. package/dist/application/files/pending-upload-link.d.ts +10 -0
  167. package/dist/application/files/pending-upload-link.d.ts.map +1 -0
  168. package/dist/application/files/pending-upload-link.js +2 -0
  169. package/dist/application/files/pending-upload-link.js.map +1 -0
  170. package/dist/application/files/pending-upload.d.ts +15 -0
  171. package/dist/application/files/pending-upload.d.ts.map +1 -0
  172. package/dist/application/files/pending-upload.js +2 -0
  173. package/dist/application/files/pending-upload.js.map +1 -0
  174. package/dist/application/files/put-options.d.ts +7 -0
  175. package/dist/application/files/put-options.d.ts.map +1 -0
  176. package/dist/application/files/put-options.js +2 -0
  177. package/dist/application/files/put-options.js.map +1 -0
  178. package/dist/application/files/received-file.d.ts +15 -0
  179. package/dist/application/files/received-file.d.ts.map +1 -0
  180. package/dist/application/files/received-file.js +2 -0
  181. package/dist/application/files/received-file.js.map +1 -0
  182. package/dist/application/files/scan-verdict.d.ts +8 -0
  183. package/dist/application/files/scan-verdict.d.ts.map +1 -0
  184. package/dist/application/files/scan-verdict.js +2 -0
  185. package/dist/application/files/scan-verdict.js.map +1 -0
  186. package/dist/application/files/signature-of.d.ts +3 -0
  187. package/dist/application/files/signature-of.d.ts.map +1 -0
  188. package/dist/application/files/signature-of.js +28 -0
  189. package/dist/application/files/signature-of.js.map +1 -0
  190. package/dist/application/files/signed-download.d.ts +6 -0
  191. package/dist/application/files/signed-download.d.ts.map +1 -0
  192. package/dist/application/files/signed-download.js +2 -0
  193. package/dist/application/files/signed-download.js.map +1 -0
  194. package/dist/application/files/signed-upload.d.ts +9 -0
  195. package/dist/application/files/signed-upload.d.ts.map +1 -0
  196. package/dist/application/files/signed-upload.js +2 -0
  197. package/dist/application/files/signed-upload.js.map +1 -0
  198. package/dist/application/files/signed-url.d.ts +6 -0
  199. package/dist/application/files/signed-url.d.ts.map +1 -0
  200. package/dist/application/files/signed-url.js +2 -0
  201. package/dist/application/files/signed-url.js.map +1 -0
  202. package/dist/application/files/staged-key-of.d.ts +5 -0
  203. package/dist/application/files/staged-key-of.d.ts.map +1 -0
  204. package/dist/application/files/staged-key-of.js +7 -0
  205. package/dist/application/files/staged-key-of.js.map +1 -0
  206. package/dist/application/files/stored-file.d.ts +16 -0
  207. package/dist/application/files/stored-file.d.ts.map +1 -0
  208. package/dist/application/files/stored-file.js +2 -0
  209. package/dist/application/files/stored-file.js.map +1 -0
  210. package/dist/application/files/upload-url-options.d.ts +12 -0
  211. package/dist/application/files/upload-url-options.d.ts.map +1 -0
  212. package/dist/application/files/upload-url-options.js +2 -0
  213. package/dist/application/files/upload-url-options.js.map +1 -0
  214. package/dist/application/persistence/append-changes.d.ts +18 -0
  215. package/dist/application/persistence/append-changes.d.ts.map +1 -0
  216. package/dist/application/persistence/append-changes.js +17 -0
  217. package/dist/application/persistence/append-changes.js.map +1 -0
  218. package/dist/application/ports/checkpoint-store.d.ts +14 -0
  219. package/dist/application/ports/checkpoint-store.d.ts.map +1 -0
  220. package/dist/application/ports/checkpoint-store.js +10 -0
  221. package/dist/application/ports/checkpoint-store.js.map +1 -0
  222. package/dist/application/ports/event-store.d.ts +24 -0
  223. package/dist/application/ports/event-store.d.ts.map +1 -0
  224. package/dist/application/ports/event-store.js +12 -0
  225. package/dist/application/ports/event-store.js.map +1 -0
  226. package/dist/application/ports/file-keys.d.ts +9 -0
  227. package/dist/application/ports/file-keys.d.ts.map +1 -0
  228. package/dist/application/ports/file-keys.js +10 -0
  229. package/dist/application/ports/file-keys.js.map +1 -0
  230. package/dist/application/ports/file-scanner.d.ts +13 -0
  231. package/dist/application/ports/file-scanner.d.ts.map +1 -0
  232. package/dist/application/ports/file-scanner.js +12 -0
  233. package/dist/application/ports/file-scanner.js.map +1 -0
  234. package/dist/application/ports/file-storage.d.ts +40 -0
  235. package/dist/application/ports/file-storage.d.ts.map +1 -0
  236. package/dist/application/ports/file-storage.js +15 -0
  237. package/dist/application/ports/file-storage.js.map +1 -0
  238. package/dist/application/ports/served-file-storage.d.ts +16 -0
  239. package/dist/application/ports/served-file-storage.d.ts.map +1 -0
  240. package/dist/application/ports/served-file-storage.js +12 -0
  241. package/dist/application/ports/served-file-storage.js.map +1 -0
  242. package/dist/application/ports/snapshot-store.d.ts +8 -0
  243. package/dist/application/ports/snapshot-store.d.ts.map +1 -0
  244. package/dist/application/ports/snapshot-store.js +7 -0
  245. package/dist/application/ports/snapshot-store.js.map +1 -0
  246. package/dist/application/ports/subject-key-store.d.ts +17 -0
  247. package/dist/application/ports/subject-key-store.d.ts.map +1 -0
  248. package/dist/application/ports/subject-key-store.js +13 -0
  249. package/dist/application/ports/subject-key-store.js.map +1 -0
  250. package/dist/declarations/decorators/projection-options.d.ts +5 -0
  251. package/dist/declarations/decorators/projection-options.d.ts.map +1 -0
  252. package/dist/declarations/decorators/projection-options.js +2 -0
  253. package/dist/declarations/decorators/projection-options.js.map +1 -0
  254. package/dist/declarations/decorators/projection.d.ts +4 -0
  255. package/dist/declarations/decorators/projection.d.ts.map +1 -1
  256. package/dist/declarations/decorators/projection.js +16 -8
  257. package/dist/declarations/decorators/projection.js.map +1 -1
  258. package/dist/declarations/model/projection-declaration.d.ts +3 -0
  259. package/dist/declarations/model/projection-declaration.d.ts.map +1 -1
  260. package/dist/declarations/model/projection-feed.d.ts +8 -0
  261. package/dist/declarations/model/projection-feed.d.ts.map +1 -0
  262. package/dist/declarations/model/projection-feed.js +2 -0
  263. package/dist/declarations/model/projection-feed.js.map +1 -0
  264. package/dist/declarations/projection/applying-projection.d.ts +14 -0
  265. package/dist/declarations/projection/applying-projection.d.ts.map +1 -0
  266. package/dist/declarations/projection/applying-projection.js +32 -0
  267. package/dist/declarations/projection/applying-projection.js.map +1 -0
  268. package/dist/declarations.d.ts +3 -0
  269. package/dist/declarations.d.ts.map +1 -1
  270. package/dist/declarations.js +1 -0
  271. package/dist/declarations.js.map +1 -1
  272. package/dist/domain/event-sourcing/aggregate-history.d.ts +10 -0
  273. package/dist/domain/event-sourcing/aggregate-history.d.ts.map +1 -0
  274. package/dist/domain/event-sourcing/aggregate-history.js +2 -0
  275. package/dist/domain/event-sourcing/aggregate-history.js.map +1 -0
  276. package/dist/domain/event-sourcing/aggregate-snapshot.d.ts +6 -0
  277. package/dist/domain/event-sourcing/aggregate-snapshot.d.ts.map +1 -0
  278. package/dist/domain/event-sourcing/aggregate-snapshot.js +2 -0
  279. package/dist/domain/event-sourcing/aggregate-snapshot.js.map +1 -0
  280. package/dist/domain/event-sourcing/appliers.d.ts +12 -0
  281. package/dist/domain/event-sourcing/appliers.d.ts.map +1 -0
  282. package/dist/domain/event-sourcing/appliers.js +2 -0
  283. package/dist/domain/event-sourcing/appliers.js.map +1 -0
  284. package/dist/domain/event-sourcing/event-sourced-aggregate.d.ts +28 -0
  285. package/dist/domain/event-sourcing/event-sourced-aggregate.d.ts.map +1 -0
  286. package/dist/domain/event-sourcing/event-sourced-aggregate.js +51 -0
  287. package/dist/domain/event-sourcing/event-sourced-aggregate.js.map +1 -0
  288. package/dist/domain/event-sourcing/unstored-events.d.ts +8 -0
  289. package/dist/domain/event-sourcing/unstored-events.d.ts.map +1 -0
  290. package/dist/domain/event-sourcing/unstored-events.js +7 -0
  291. package/dist/domain/event-sourcing/unstored-events.js.map +1 -0
  292. package/dist/index.d.ts +52 -32
  293. package/dist/index.d.ts.map +1 -1
  294. package/dist/index.js +52 -32
  295. package/dist/index.js.map +1 -1
  296. package/dist/infrastructure/domain-events/after-commit.d.ts +10 -0
  297. package/dist/infrastructure/domain-events/after-commit.d.ts.map +1 -0
  298. package/dist/infrastructure/domain-events/after-commit.js +19 -0
  299. package/dist/infrastructure/domain-events/after-commit.js.map +1 -0
  300. package/dist/infrastructure/domain-events/at-commit.d.ts +11 -0
  301. package/dist/infrastructure/domain-events/at-commit.d.ts.map +1 -0
  302. package/dist/infrastructure/domain-events/at-commit.js +19 -0
  303. package/dist/infrastructure/domain-events/at-commit.js.map +1 -0
  304. package/dist/infrastructure/domain-events/commit-step.d.ts +10 -0
  305. package/dist/infrastructure/domain-events/commit-step.d.ts.map +1 -0
  306. package/dist/infrastructure/domain-events/commit-step.js +2 -0
  307. package/dist/infrastructure/domain-events/commit-step.js.map +1 -0
  308. package/dist/infrastructure/domain-events/unit-of-work-scope.d.ts +5 -0
  309. package/dist/infrastructure/domain-events/unit-of-work-scope.d.ts.map +1 -1
  310. package/dist/infrastructure/domain-events/unit-of-work-scope.js.map +1 -1
  311. package/dist/infrastructure/domain-events/within-unit-of-work.d.ts +3 -1
  312. package/dist/infrastructure/domain-events/within-unit-of-work.d.ts.map +1 -1
  313. package/dist/infrastructure/domain-events/within-unit-of-work.js +32 -5
  314. package/dist/infrastructure/domain-events/within-unit-of-work.js.map +1 -1
  315. package/dist/infrastructure/event-sourcing/catch-up-subscription.d.ts +33 -0
  316. package/dist/infrastructure/event-sourcing/catch-up-subscription.d.ts.map +1 -0
  317. package/dist/infrastructure/event-sourcing/catch-up-subscription.js +39 -0
  318. package/dist/infrastructure/event-sourcing/catch-up-subscription.js.map +1 -0
  319. package/dist/infrastructure/event-sourcing/event-serializer.d.ts +35 -0
  320. package/dist/infrastructure/event-sourcing/event-serializer.d.ts.map +1 -0
  321. package/dist/infrastructure/event-sourcing/event-serializer.js +104 -0
  322. package/dist/infrastructure/event-sourcing/event-serializer.js.map +1 -0
  323. package/dist/infrastructure/event-sourcing/event-sourced-repository.d.ts +32 -0
  324. package/dist/infrastructure/event-sourcing/event-sourced-repository.d.ts.map +1 -0
  325. package/dist/infrastructure/event-sourcing/event-sourced-repository.js +68 -0
  326. package/dist/infrastructure/event-sourcing/event-sourced-repository.js.map +1 -0
  327. package/dist/infrastructure/event-sourcing/event-sourcing-stores.d.ts +12 -0
  328. package/dist/infrastructure/event-sourcing/event-sourcing-stores.d.ts.map +1 -0
  329. package/dist/infrastructure/event-sourcing/event-sourcing-stores.js +2 -0
  330. package/dist/infrastructure/event-sourcing/event-sourcing-stores.js.map +1 -0
  331. package/dist/infrastructure/event-sourcing/event-store-projection-rebuild.d.ts +34 -0
  332. package/dist/infrastructure/event-sourcing/event-store-projection-rebuild.d.ts.map +1 -0
  333. package/dist/infrastructure/event-sourcing/event-store-projection-rebuild.js +48 -0
  334. package/dist/infrastructure/event-sourcing/event-store-projection-rebuild.js.map +1 -0
  335. package/dist/infrastructure/event-sourcing/personal-data-cipher.d.ts +19 -0
  336. package/dist/infrastructure/event-sourcing/personal-data-cipher.d.ts.map +1 -0
  337. package/dist/infrastructure/event-sourcing/personal-data-cipher.js +84 -0
  338. package/dist/infrastructure/event-sourcing/personal-data-cipher.js.map +1 -0
  339. package/dist/infrastructure/event-sourcing/postgres/event-store-tables-options.d.ts +6 -0
  340. package/dist/infrastructure/event-sourcing/postgres/event-store-tables-options.d.ts.map +1 -0
  341. package/dist/infrastructure/event-sourcing/postgres/event-store-tables-options.js +2 -0
  342. package/dist/infrastructure/event-sourcing/postgres/event-store-tables-options.js.map +1 -0
  343. package/dist/infrastructure/event-sourcing/postgres/event-store-tables-sql.d.ts +9 -0
  344. package/dist/infrastructure/event-sourcing/postgres/event-store-tables-sql.d.ts.map +1 -0
  345. package/dist/infrastructure/event-sourcing/postgres/event-store-tables-sql.js +32 -0
  346. package/dist/infrastructure/event-sourcing/postgres/event-store-tables-sql.js.map +1 -0
  347. package/dist/infrastructure/event-sourcing/postgres/event-store-tables.d.ts +9 -0
  348. package/dist/infrastructure/event-sourcing/postgres/event-store-tables.d.ts.map +1 -0
  349. package/dist/infrastructure/event-sourcing/postgres/event-store-tables.js +9 -0
  350. package/dist/infrastructure/event-sourcing/postgres/event-store-tables.js.map +1 -0
  351. package/dist/infrastructure/event-sourcing/postgres/is-append-conflict.d.ts +3 -0
  352. package/dist/infrastructure/event-sourcing/postgres/is-append-conflict.d.ts.map +1 -0
  353. package/dist/infrastructure/event-sourcing/postgres/is-append-conflict.js +22 -0
  354. package/dist/infrastructure/event-sourcing/postgres/is-append-conflict.js.map +1 -0
  355. package/dist/infrastructure/event-sourcing/postgres/postgres-checkpoint-store.d.ts +12 -0
  356. package/dist/infrastructure/event-sourcing/postgres/postgres-checkpoint-store.d.ts.map +1 -0
  357. package/dist/infrastructure/event-sourcing/postgres/postgres-checkpoint-store.js +26 -0
  358. package/dist/infrastructure/event-sourcing/postgres/postgres-checkpoint-store.js.map +1 -0
  359. package/dist/infrastructure/event-sourcing/postgres/postgres-event-sourcing.d.ts +6 -0
  360. package/dist/infrastructure/event-sourcing/postgres/postgres-event-sourcing.d.ts.map +1 -0
  361. package/dist/infrastructure/event-sourcing/postgres/postgres-event-sourcing.js +14 -0
  362. package/dist/infrastructure/event-sourcing/postgres/postgres-event-sourcing.js.map +1 -0
  363. package/dist/infrastructure/event-sourcing/postgres/postgres-event-store.d.ts +31 -0
  364. package/dist/infrastructure/event-sourcing/postgres/postgres-event-store.d.ts.map +1 -0
  365. package/dist/infrastructure/event-sourcing/postgres/postgres-event-store.js +120 -0
  366. package/dist/infrastructure/event-sourcing/postgres/postgres-event-store.js.map +1 -0
  367. package/dist/infrastructure/event-sourcing/postgres/postgres-snapshot-store.d.ts +13 -0
  368. package/dist/infrastructure/event-sourcing/postgres/postgres-snapshot-store.d.ts.map +1 -0
  369. package/dist/infrastructure/event-sourcing/postgres/postgres-snapshot-store.js +28 -0
  370. package/dist/infrastructure/event-sourcing/postgres/postgres-snapshot-store.js.map +1 -0
  371. package/dist/infrastructure/event-sourcing/postgres/postgres-subject-key-store.d.ts +21 -0
  372. package/dist/infrastructure/event-sourcing/postgres/postgres-subject-key-store.d.ts.map +1 -0
  373. package/dist/infrastructure/event-sourcing/postgres/postgres-subject-key-store.js +48 -0
  374. package/dist/infrastructure/event-sourcing/postgres/postgres-subject-key-store.js.map +1 -0
  375. package/dist/infrastructure/event-sourcing/postgres/qualified-table.d.ts +4 -0
  376. package/dist/infrastructure/event-sourcing/postgres/qualified-table.d.ts.map +1 -0
  377. package/dist/infrastructure/event-sourcing/postgres/qualified-table.js +10 -0
  378. package/dist/infrastructure/event-sourcing/postgres/qualified-table.js.map +1 -0
  379. package/dist/infrastructure/event-sourcing/postgres/stored-data-from.d.ts +4 -0
  380. package/dist/infrastructure/event-sourcing/postgres/stored-data-from.d.ts.map +1 -0
  381. package/dist/infrastructure/event-sourcing/postgres/stored-data-from.js +23 -0
  382. package/dist/infrastructure/event-sourcing/postgres/stored-data-from.js.map +1 -0
  383. package/dist/infrastructure/event-sourcing/rewrite-objects.d.ts +8 -0
  384. package/dist/infrastructure/event-sourcing/rewrite-objects.d.ts.map +1 -0
  385. package/dist/infrastructure/event-sourcing/rewrite-objects.js +16 -0
  386. package/dist/infrastructure/event-sourcing/rewrite-objects.js.map +1 -0
  387. package/dist/infrastructure/event-sourcing/snapshot-policy.d.ts +14 -0
  388. package/dist/infrastructure/event-sourcing/snapshot-policy.d.ts.map +1 -0
  389. package/dist/infrastructure/event-sourcing/snapshot-policy.js +2 -0
  390. package/dist/infrastructure/event-sourcing/snapshot-policy.js.map +1 -0
  391. package/dist/infrastructure/event-sourcing/stored-origins.d.ts +5 -0
  392. package/dist/infrastructure/event-sourcing/stored-origins.d.ts.map +1 -0
  393. package/dist/infrastructure/event-sourcing/stored-origins.js +3 -0
  394. package/dist/infrastructure/event-sourcing/stored-origins.js.map +1 -0
  395. package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts +10 -0
  396. package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts.map +1 -0
  397. package/dist/infrastructure/event-sourcing/stored-stamp-of.js +14 -0
  398. package/dist/infrastructure/event-sourcing/stored-stamp-of.js.map +1 -0
  399. package/dist/infrastructure/files/accept-every-file-scanner.d.ts +7 -0
  400. package/dist/infrastructure/files/accept-every-file-scanner.d.ts.map +1 -0
  401. package/dist/infrastructure/files/accept-every-file-scanner.js +7 -0
  402. package/dist/infrastructure/files/accept-every-file-scanner.js.map +1 -0
  403. package/dist/infrastructure/files/collect.d.ts +4 -0
  404. package/dist/infrastructure/files/collect.d.ts.map +1 -0
  405. package/dist/infrastructure/files/collect.js +11 -0
  406. package/dist/infrastructure/files/collect.js.map +1 -0
  407. package/dist/infrastructure/files/file-grant.d.ts +11 -0
  408. package/dist/infrastructure/files/file-grant.d.ts.map +1 -0
  409. package/dist/infrastructure/files/file-grant.js +2 -0
  410. package/dist/infrastructure/files/file-grant.js.map +1 -0
  411. package/dist/infrastructure/files/file-inspection.d.ts +22 -0
  412. package/dist/infrastructure/files/file-inspection.d.ts.map +1 -0
  413. package/dist/infrastructure/files/file-inspection.js +66 -0
  414. package/dist/infrastructure/files/file-inspection.js.map +1 -0
  415. package/dist/infrastructure/files/file-staging.d.ts +59 -0
  416. package/dist/infrastructure/files/file-staging.d.ts.map +1 -0
  417. package/dist/infrastructure/files/file-staging.js +142 -0
  418. package/dist/infrastructure/files/file-staging.js.map +1 -0
  419. package/dist/infrastructure/files/file-uploads-middleware.d.ts +11 -0
  420. package/dist/infrastructure/files/file-uploads-middleware.d.ts.map +1 -0
  421. package/dist/infrastructure/files/file-uploads-middleware.js +25 -0
  422. package/dist/infrastructure/files/file-uploads-middleware.js.map +1 -0
  423. package/dist/infrastructure/files/in-memory-file-storage.d.ts +25 -0
  424. package/dist/infrastructure/files/in-memory-file-storage.d.ts.map +1 -0
  425. package/dist/infrastructure/files/in-memory-file-storage.js +73 -0
  426. package/dist/infrastructure/files/in-memory-file-storage.js.map +1 -0
  427. package/dist/infrastructure/files/is-file-grant.d.ts +3 -0
  428. package/dist/infrastructure/files/is-file-grant.d.ts.map +1 -0
  429. package/dist/infrastructure/files/is-file-grant.js +16 -0
  430. package/dist/infrastructure/files/is-file-grant.js.map +1 -0
  431. package/dist/infrastructure/files/is-stored-metadata.d.ts +3 -0
  432. package/dist/infrastructure/files/is-stored-metadata.d.ts.map +1 -0
  433. package/dist/infrastructure/files/is-stored-metadata.js +8 -0
  434. package/dist/infrastructure/files/is-stored-metadata.js.map +1 -0
  435. package/dist/infrastructure/files/local-file-storage-options.d.ts +6 -0
  436. package/dist/infrastructure/files/local-file-storage-options.d.ts.map +1 -0
  437. package/dist/infrastructure/files/local-file-storage-options.js +2 -0
  438. package/dist/infrastructure/files/local-file-storage-options.js.map +1 -0
  439. package/dist/infrastructure/files/local-file-storage.d.ts +29 -0
  440. package/dist/infrastructure/files/local-file-storage.d.ts.map +1 -0
  441. package/dist/infrastructure/files/local-file-storage.js +103 -0
  442. package/dist/infrastructure/files/local-file-storage.js.map +1 -0
  443. package/dist/infrastructure/files/local-paths.d.ts +12 -0
  444. package/dist/infrastructure/files/local-paths.d.ts.map +1 -0
  445. package/dist/infrastructure/files/local-paths.js +33 -0
  446. package/dist/infrastructure/files/local-paths.js.map +1 -0
  447. package/dist/infrastructure/files/purge-staged-files.d.ts +16 -0
  448. package/dist/infrastructure/files/purge-staged-files.d.ts.map +1 -0
  449. package/dist/infrastructure/files/purge-staged-files.js +21 -0
  450. package/dist/infrastructure/files/purge-staged-files.js.map +1 -0
  451. package/dist/infrastructure/files/self-signed-file-storage.d.ts +23 -0
  452. package/dist/infrastructure/files/self-signed-file-storage.d.ts.map +1 -0
  453. package/dist/infrastructure/files/self-signed-file-storage.js +57 -0
  454. package/dist/infrastructure/files/self-signed-file-storage.js.map +1 -0
  455. package/dist/infrastructure/files/signed-file-tokens.d.ts +20 -0
  456. package/dist/infrastructure/files/signed-file-tokens.d.ts.map +1 -0
  457. package/dist/infrastructure/files/signed-file-tokens.js +45 -0
  458. package/dist/infrastructure/files/signed-file-tokens.js.map +1 -0
  459. package/dist/infrastructure/files/signed-link-options.d.ts +10 -0
  460. package/dist/infrastructure/files/signed-link-options.d.ts.map +1 -0
  461. package/dist/infrastructure/files/signed-link-options.js +2 -0
  462. package/dist/infrastructure/files/signed-link-options.js.map +1 -0
  463. package/dist/infrastructure/files/stored-metadata.d.ts +6 -0
  464. package/dist/infrastructure/files/stored-metadata.d.ts.map +1 -0
  465. package/dist/infrastructure/files/stored-metadata.js +2 -0
  466. package/dist/infrastructure/files/stored-metadata.js.map +1 -0
  467. package/dist/infrastructure/files/tenant-file-keys.d.ts +20 -0
  468. package/dist/infrastructure/files/tenant-file-keys.d.ts.map +1 -0
  469. package/dist/infrastructure/files/tenant-file-keys.js +27 -0
  470. package/dist/infrastructure/files/tenant-file-keys.js.map +1 -0
  471. package/dist/infrastructure/files/upload-desk.d.ts +8 -0
  472. package/dist/infrastructure/files/upload-desk.d.ts.map +1 -0
  473. package/dist/infrastructure/files/upload-desk.js +2 -0
  474. package/dist/infrastructure/files/upload-desk.js.map +1 -0
  475. package/dist/infrastructure/files/without-trailing-slashes.d.ts +3 -0
  476. package/dist/infrastructure/files/without-trailing-slashes.d.ts.map +1 -0
  477. package/dist/infrastructure/files/without-trailing-slashes.js +9 -0
  478. package/dist/infrastructure/files/without-trailing-slashes.js.map +1 -0
  479. package/dist/infrastructure/in-memory/in-memory-checkpoint-store.d.ts +8 -0
  480. package/dist/infrastructure/in-memory/in-memory-checkpoint-store.d.ts.map +1 -0
  481. package/dist/infrastructure/in-memory/in-memory-checkpoint-store.js +15 -0
  482. package/dist/infrastructure/in-memory/in-memory-checkpoint-store.js.map +1 -0
  483. package/dist/infrastructure/in-memory/in-memory-event-store.d.ts +14 -0
  484. package/dist/infrastructure/in-memory/in-memory-event-store.d.ts.map +1 -0
  485. package/dist/infrastructure/in-memory/in-memory-event-store.js +37 -0
  486. package/dist/infrastructure/in-memory/in-memory-event-store.js.map +1 -0
  487. package/dist/infrastructure/in-memory/in-memory-snapshot-store.d.ts +9 -0
  488. package/dist/infrastructure/in-memory/in-memory-snapshot-store.d.ts.map +1 -0
  489. package/dist/infrastructure/in-memory/in-memory-snapshot-store.js +15 -0
  490. package/dist/infrastructure/in-memory/in-memory-snapshot-store.js.map +1 -0
  491. package/dist/infrastructure/in-memory/in-memory-subject-key-store.d.ts +10 -0
  492. package/dist/infrastructure/in-memory/in-memory-subject-key-store.d.ts.map +1 -0
  493. package/dist/infrastructure/in-memory/in-memory-subject-key-store.js +21 -0
  494. package/dist/infrastructure/in-memory/in-memory-subject-key-store.js.map +1 -0
  495. package/dist/infrastructure/read-model/shadow-read-model-store.d.ts +20 -0
  496. package/dist/infrastructure/read-model/shadow-read-model-store.d.ts.map +1 -0
  497. package/dist/infrastructure/read-model/shadow-read-model-store.js +25 -0
  498. package/dist/infrastructure/read-model/shadow-read-model-store.js.map +1 -0
  499. package/package.json +1 -1
@@ -0,0 +1,104 @@
1
+ import { StoredEventData } from '../../application/event-sourcing/stored-event-data.js';
2
+ import { UnreadableEventError } from '../../application/event-sourcing/unreadable-event-error.js';
3
+ import { UuidGenerator } from '../id/uuid-generator.js';
4
+ import { PersonalDataCipher } from './personal-data-cipher.js';
5
+ import { storedOrigins } from './stored-origins.js';
6
+ /**
7
+ * Turns the domain events of one aggregate into stored events and back, as `defineStoredEvent`
8
+ * declared them: the current version of their shape on the way in, and on the way out the
9
+ * upcasters from the version they were stored with, then `decode`. Stored events are never
10
+ * rewritten. Personal values are sealed on the way in and opened on the way out.
11
+ */
12
+ export class EventSerializer {
13
+ options;
14
+ types = new Map();
15
+ ids;
16
+ constructor(types, options = {}) {
17
+ this.options = options;
18
+ for (const name of Object.keys(types)) {
19
+ const declared = Reflect.get(types, name);
20
+ if (isStoredEventType(declared)) {
21
+ this.types.set(name, declared);
22
+ }
23
+ }
24
+ this.ids = options.ids ?? new UuidGenerator();
25
+ }
26
+ /** Whether events of this name are declared here: what a subscription skips otherwise. */
27
+ declares(type) {
28
+ return this.types.has(type);
29
+ }
30
+ async serialize(event) {
31
+ const declared = this.typeOf(event.name);
32
+ return {
33
+ id: this.ids.next(),
34
+ type: event.name,
35
+ schemaVersion: declared.version,
36
+ data: await this.seal(declared.encode(event)),
37
+ metadata: { aggregateId: event.aggregateId },
38
+ occurredAt: event.occurredAt,
39
+ };
40
+ }
41
+ async deserialize(stored) {
42
+ const declared = this.typeOf(stored.type);
43
+ const where = `${stored.type} ${stored.id}`;
44
+ const data = upcast(declared, await this.open(stored.data), stored);
45
+ const event = declared.decode(new StoredEventData(data, where), {
46
+ id: stored.id,
47
+ aggregateId: aggregateIdOf(stored),
48
+ occurredAt: stored.occurredAt,
49
+ version: stored.version,
50
+ });
51
+ storedOrigins.set(event, stored);
52
+ return event;
53
+ }
54
+ /** Seals the personal values of the data, for an event or a snapshot. */
55
+ async seal(data) {
56
+ if (!PersonalDataCipher.holdsPersonalData(data)) {
57
+ return data;
58
+ }
59
+ if (this.options.cipher === undefined) {
60
+ throw new TypeError('Personal data is stored sealed: give the serializer a PersonalDataCipher');
61
+ }
62
+ return this.options.cipher.seal(data);
63
+ }
64
+ /** Opens the sealed values of the data; an erased one reads `ERASED_PERSONAL_DATA`. */
65
+ async open(data) {
66
+ if (!PersonalDataCipher.holdsPersonalData(data)) {
67
+ return data;
68
+ }
69
+ if (this.options.cipher === undefined) {
70
+ throw new UnreadableEventError('Stored data holds sealed values: give the serializer a PersonalDataCipher');
71
+ }
72
+ return this.options.cipher.open(data);
73
+ }
74
+ typeOf(type) {
75
+ const declared = this.types.get(type);
76
+ if (declared === undefined) {
77
+ throw new UnreadableEventError(`"${type}" is not a stored event of this serializer: declare it with defineStoredEvent`);
78
+ }
79
+ return declared;
80
+ }
81
+ }
82
+ /** What `defineStoredEvent` answers, told apart from anything else a record of declarations could hold. */
83
+ function isStoredEventType(value) {
84
+ return typeof value === 'object' && value !== null && 'decode' in value && 'encode' in value && 'version' in value;
85
+ }
86
+ function upcast(declared, data, stored) {
87
+ if (stored.schemaVersion > declared.version) {
88
+ throw new UnreadableEventError(`${stored.type} ${stored.id} is stored in version ${stored.schemaVersion}, and this release reads up to ${declared.version}`);
89
+ }
90
+ let current = data;
91
+ for (let version = stored.schemaVersion; version < declared.version; version += 1) {
92
+ const upcaster = declared.upcasters[version];
93
+ if (upcaster === undefined) {
94
+ throw new UnreadableEventError(`${stored.type} has no upcaster from version ${version}`);
95
+ }
96
+ current = upcaster(current);
97
+ }
98
+ return current;
99
+ }
100
+ function aggregateIdOf(stored) {
101
+ const declared = stored.metadata['aggregateId'];
102
+ return typeof declared === 'string' ? declared : stored.stream;
103
+ }
104
+ //# sourceMappingURL=event-serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-serializer.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-serializer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,M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G,QAAQ,CAAC,OAAO,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;QAClF,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,oBAAoB,CAAC,GAAG,MAAM,CAAC,IAAI,iCAAiC,OAAO,EAAE,CAAC,CAAC;QAC3F,CAAC;QAED,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,aAAa,CAAC,MAAmB;IACxC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAEhD,OAAO,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;AACjE,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { EventStore } from '../../application/ports/event-store.js';
2
+ import type { DomainEvent } from '../../domain/domain-event.js';
3
+ import type { AggregateHistory } from '../../domain/event-sourcing/aggregate-history.js';
4
+ import type { EventSourcedAggregate } from '../../domain/event-sourcing/event-sourced-aggregate.js';
5
+ import type { EventSerializer } from './event-serializer.js';
6
+ import type { SnapshotPolicy } from './snapshot-policy.js';
7
+ export interface EventSourcedRepositoryParts<A extends EventSourcedAggregate<E, S>, E extends DomainEvent, S> {
8
+ readonly store: EventStore;
9
+ readonly serializer: EventSerializer<E>;
10
+ /** `<context>.<aggregate>`: the stream of an aggregate is `<category>-<id>`. */
11
+ readonly category: string;
12
+ /** The static `rehydrate` of the aggregate: `(id, history) => AttendanceRecord.rehydrate(id, history)`. */
13
+ rehydrate(id: string, history: AggregateHistory<E, S>): A;
14
+ readonly snapshots?: SnapshotPolicy<A, S>;
15
+ }
16
+ /**
17
+ * What the repository adapter of an event-sourced aggregate delegates to: `findById` replays the
18
+ * stream, from the last snapshot when the aggregate takes them; `save` appends what the aggregate
19
+ * recorded, at the version it was loaded at, in the transaction of the unit of work, and takes a
20
+ * snapshot when one is due. The events then leave with the save like any other (`dispatchingOnSave`).
21
+ */
22
+ export declare class EventSourcedRepository<A extends EventSourcedAggregate<E, S>, E extends DomainEvent, S = never> {
23
+ private readonly parts;
24
+ constructor(parts: EventSourcedRepositoryParts<A, E, S>);
25
+ static streamOf(category: string, id: string): string;
26
+ findById(id: string): Promise<A | undefined>;
27
+ save(aggregate: A): Promise<void>;
28
+ private serialized;
29
+ private snapshotIfDue;
30
+ private snapshotOf;
31
+ }
32
+ //# sourceMappingURL=event-sourced-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourced-repository.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-sourced-repository.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kDAAkD,CAAC;AAEzF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wDAAwD,CAAC;AACpG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,WAAW,2BAA2B,CAAC,CAAC,SAAS,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAAE,CAAC;IAC1G,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACxC,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2GAA2G;IAC3G,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IAC1D,QAAQ,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC3C;AAED;;;;;GAKG;AACH,qBAAa,sBAAsB,CAAC,CAAC,SAAS,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAAE,CAAC,GAAG,KAAK;IAC7F,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAlC,YAA6B,KAAK,EAAE,2BAA2B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAI;IAE5E,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAEpD;IAEK,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAgBjD;IAEK,IAAI,CAAC,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAStC;YAEa,UAAU;YAUV,aAAa;YAeb,UAAU;CAYzB"}
@@ -0,0 +1,68 @@
1
+ import { storedDataOf } from '../../application/event-sourcing/stored-data-of.js';
2
+ import { StoredEventData } from '../../application/event-sourcing/stored-event-data.js';
3
+ import { appendChanges } from '../../application/persistence/append-changes.js';
4
+ /**
5
+ * What the repository adapter of an event-sourced aggregate delegates to: `findById` replays the
6
+ * stream, from the last snapshot when the aggregate takes them; `save` appends what the aggregate
7
+ * recorded, at the version it was loaded at, in the transaction of the unit of work, and takes a
8
+ * snapshot when one is due. The events then leave with the save like any other (`dispatchingOnSave`).
9
+ */
10
+ export class EventSourcedRepository {
11
+ parts;
12
+ constructor(parts) {
13
+ this.parts = parts;
14
+ }
15
+ static streamOf(category, id) {
16
+ return `${category}-${id}`;
17
+ }
18
+ async findById(id) {
19
+ const stream = EventSourcedRepository.streamOf(this.parts.category, id);
20
+ const snapshot = await this.snapshotOf(stream);
21
+ const stored = await this.parts.store.readStream(stream, snapshot?.version ?? 0);
22
+ if (snapshot === undefined && stored.length === 0) {
23
+ return undefined;
24
+ }
25
+ const events = [];
26
+ for (const event of stored) {
27
+ events.push(await this.parts.serializer.deserialize(event));
28
+ }
29
+ return this.parts.rehydrate(id, snapshot === undefined ? { events } : { snapshot, events });
30
+ }
31
+ async save(aggregate) {
32
+ const before = aggregate.version;
33
+ const stream = EventSourcedRepository.streamOf(this.parts.category, aggregate.id);
34
+ await appendChanges(aggregate, async ({ expected, events }) => {
35
+ await this.parts.store.append(stream, expected, await this.serialized(events));
36
+ });
37
+ await this.snapshotIfDue(aggregate, stream, before);
38
+ }
39
+ async serialized(events) {
40
+ const serialized = [];
41
+ for (const event of events) {
42
+ serialized.push(await this.parts.serializer.serialize(event));
43
+ }
44
+ return serialized;
45
+ }
46
+ async snapshotIfDue(aggregate, stream, before) {
47
+ const policy = this.parts.snapshots;
48
+ if (policy === undefined || Math.floor(aggregate.version / policy.every) === Math.floor(before / policy.every)) {
49
+ return;
50
+ }
51
+ await policy.store.save({
52
+ stream,
53
+ version: aggregate.version,
54
+ schemaVersion: policy.version,
55
+ data: await this.parts.serializer.seal(storedDataOf(policy.encode(aggregate))),
56
+ });
57
+ }
58
+ async snapshotOf(stream) {
59
+ const policy = this.parts.snapshots;
60
+ const found = await policy?.store.find(stream);
61
+ if (policy === undefined || found === undefined || found.schemaVersion !== policy.version) {
62
+ return undefined;
63
+ }
64
+ const data = await this.parts.serializer.open(found.data);
65
+ return { version: found.version, state: policy.decode(new StoredEventData(data, `the snapshot of ${stream}`)) };
66
+ }
67
+ }
68
+ //# sourceMappingURL=event-sourced-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourced-repository.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-sourced-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAC;AAClF,OAAO,EAAE,eAAe,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AAI,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;SAC/E,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,MAAc;QACrC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;QACpC,MAAM,KAAK,GAAG,MAAM,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE/C,IAAI,MAAM,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,aAAa,KAAK,MAAM,CAAC,OAAO,EAAE,CAAC;YAC1F,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE1D,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,eAAe,CAAC,IAAI,EAAE,mBAAmB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC;IAClH,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import type { CheckpointStore } from '../../application/ports/checkpoint-store.js';
2
+ import type { EventStore } from '../../application/ports/event-store.js';
3
+ import type { SnapshotStore } from '../../application/ports/snapshot-store.js';
4
+ import type { SubjectKeyStore } from '../../application/ports/subject-key-store.js';
5
+ /** The stores event sourcing needs in one database, to bind to their ports in the composition root. */
6
+ export interface EventSourcingStores {
7
+ readonly events: EventStore;
8
+ readonly snapshots: SnapshotStore;
9
+ readonly checkpoints: CheckpointStore;
10
+ readonly subjectKeys: SubjectKeyStore;
11
+ }
12
+ //# sourceMappingURL=event-sourcing-stores.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-stores.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-sourcing-stores.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAEpF,uGAAuG;AACvG,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC;CACvC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=event-sourcing-stores.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-stores.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-sourcing-stores.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import type { StoredEvent } from '../../application/event-sourcing/stored-event.js';
2
+ import type { EventStore } from '../../application/ports/event-store.js';
3
+ import type { ReadModelStore } from '../../application/ports/read-model-store.js';
4
+ import type { ReadModelTable } from '../../application/ports/read-model-table.js';
5
+ import type { UnitOfWork } from '../../application/ports/unit-of-work.js';
6
+ export interface EventStoreProjectionRebuildParts<Row> {
7
+ readonly table: ReadModelTable<Row>;
8
+ readonly store: EventStore;
9
+ /** The unit of work of the table's database: the end of the replay and the swap are one transaction. */
10
+ readonly unitOfWork: UnitOfWork;
11
+ /** How the projection applies an event to the store it is given: the same projection, built over the copy. */
12
+ applierOn(copy: ReadModelStore<Row>): (event: StoredEvent) => Promise<void>;
13
+ /** Events read per round. Default 500. */
14
+ readonly batchSize?: number;
15
+ }
16
+ /** What a rebuild from the event store did. */
17
+ export interface EventStoreRebuildReport {
18
+ /** Events read from the store, from position zero to its head at the swap. */
19
+ readonly replayed: number;
20
+ }
21
+ /**
22
+ * Rebuilds a read model fed by the event store from position zero, without stopping its catch-up
23
+ * subscription. An empty copy of the table is filled by replaying the whole store through the
24
+ * projection; then, in one transaction, the writers are held, the events appended meanwhile are
25
+ * replayed, and the copy takes the place of the table. The subscription goes on from its
26
+ * checkpoint: what it applies again is stale against the stamps of the copy.
27
+ */
28
+ export declare class EventStoreProjectionRebuild<Row> {
29
+ private readonly parts;
30
+ constructor(parts: EventStoreProjectionRebuildParts<Row>);
31
+ run(): Promise<EventStoreRebuildReport>;
32
+ private replay;
33
+ }
34
+ //# sourceMappingURL=event-store-projection-rebuild.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-store-projection-rebuild.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-store-projection-rebuild.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAC;AACpF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAG1E,MAAM,WAAW,gCAAgC,CAAC,GAAG;IACnD,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,wGAAwG;IACxG,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,8GAA8G;IAC9G,SAAS,CAAC,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,+CAA+C;AAC/C,MAAM,WAAW,uBAAuB;IACtC,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,qBAAa,2BAA2B,CAAC,GAAG;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAlC,YAA6B,KAAK,EAAE,gCAAgC,CAAC,GAAG,CAAC,EAAI;IAEvE,GAAG,IAAI,OAAO,CAAC,uBAAuB,CAAC,CA0B5C;YAEa,MAAM;CAuBrB"}
@@ -0,0 +1,48 @@
1
+ import { ShadowReadModelStore } from '../read-model/shadow-read-model-store.js';
2
+ /**
3
+ * Rebuilds a read model fed by the event store from position zero, without stopping its catch-up
4
+ * subscription. An empty copy of the table is filled by replaying the whole store through the
5
+ * projection; then, in one transaction, the writers are held, the events appended meanwhile are
6
+ * replayed, and the copy takes the place of the table. The subscription goes on from its
7
+ * checkpoint: what it applies again is stale against the stamps of the copy.
8
+ */
9
+ export class EventStoreProjectionRebuild {
10
+ parts;
11
+ constructor(parts) {
12
+ this.parts = parts;
13
+ }
14
+ async run() {
15
+ const { table, unitOfWork } = this.parts;
16
+ await table.abandonRebuild();
17
+ await table.beginRebuild();
18
+ try {
19
+ const apply = this.parts.applierOn(new ShadowReadModelStore(table.shadow()));
20
+ const copied = await this.replay(apply, 0);
21
+ const replayed = await unitOfWork.run(async () => {
22
+ await table.holdWriters();
23
+ const caughtUp = await this.replay(apply, copied.position);
24
+ await table.promote();
25
+ return copied.read + caughtUp.read;
26
+ });
27
+ return { replayed };
28
+ }
29
+ catch (error) {
30
+ await table.abandonRebuild();
31
+ throw error;
32
+ }
33
+ }
34
+ async replay(apply, from) {
35
+ const { store, batchSize = 500 } = this.parts;
36
+ let position = from;
37
+ let read = 0;
38
+ for (let events = await store.readAll(position, batchSize); events.length > 0; events = await store.readAll(position, batchSize)) {
39
+ for (const event of events) {
40
+ await apply(event);
41
+ position = event.position;
42
+ }
43
+ read += events.length;
44
+ }
45
+ return { position, read };
46
+ }
47
+ }
48
+ //# sourceMappingURL=event-store-projection-rebuild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-store-projection-rebuild.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-store-projection-rebuild.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAmBhF;;;;;;GAMG;AACH,MAAM,OAAO,2BAA2B;IACT,KAAK;IAAlC,YAA6B,KAA4C;qBAA5C,KAAK;IAA0C,CAAC;IAE7E,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAEzC,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;QAC7B,MAAM,KAAK,CAAC,YAAY,EAAE,CAAC;QAE3B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YAC7E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YAE3C,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;gBAC/C,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;gBAE1B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAE3D,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;gBAEtB,OAAO,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;YACrC,CAAC,CAAC,CAAC;YAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;YAE7B,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,MAAM,CAClB,KAA4C,EAC5C,IAAY;QAEZ,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC9C,IAAI,QAAQ,GAAG,IAAI,CAAC;QACpB,IAAI,IAAI,GAAG,CAAC,CAAC;QAEb,KACE,IAAI,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,EACrD,MAAM,CAAC,MAAM,GAAG,CAAC,EACjB,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,EACjD,CAAC;YACD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;gBACnB,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;YAC5B,CAAC;YAED,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC;QACxB,CAAC;QAED,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ import type { StoredData } from '../../application/event-sourcing/stored-data.js';
2
+ import type { SubjectKeyStore } from '../../application/ports/subject-key-store.js';
3
+ /**
4
+ * Crypto-shredding of the personal values of stored data. `seal` replaces each value marked with
5
+ * `personalData(subject, value)` by its encryption under the current key of its subject (AES-256-GCM,
6
+ * a fresh nonce per value, the key id written next to it); `open` gives the values back, and
7
+ * `ERASED_PERSONAL_DATA` for those whose key was destroyed by `SubjectKeyStore.erase`.
8
+ */
9
+ export declare class PersonalDataCipher {
10
+ private readonly keys;
11
+ constructor(keys: SubjectKeyStore);
12
+ /** Whether the data holds a personal value, sealed or not. */
13
+ static holdsPersonalData(data: StoredData): boolean;
14
+ seal(data: StoredData): Promise<StoredData>;
15
+ open(data: StoredData): Promise<StoredData>;
16
+ private sealed;
17
+ private opened;
18
+ }
19
+ //# sourceMappingURL=personal-data-cipher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"personal-data-cipher.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/personal-data-cipher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iDAAiD,CAAC;AAGlF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAOpF;;;;;GAKG;AACH,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAjC,YAA6B,IAAI,EAAE,eAAe,EAAI;IAEtD,8DAA8D;IAC9D,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAElD;IAED,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAM1C;IAED,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAM1C;YAEa,MAAM;YAYN,MAAM;CAiBrB"}
@@ -0,0 +1,84 @@
1
+ import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
2
+ import { ERASED_PERSONAL_DATA } from '../../application/event-sourcing/erased-personal-data.js';
3
+ import { isStoredData } from '../../application/event-sourcing/is-stored-data.js';
4
+ import { rewriteObjects } from './rewrite-objects.js';
5
+ const ALGORITHM = 'aes-256-gcm';
6
+ const IV_BYTES = 12;
7
+ const TAG_BYTES = 16;
8
+ /**
9
+ * Crypto-shredding of the personal values of stored data. `seal` replaces each value marked with
10
+ * `personalData(subject, value)` by its encryption under the current key of its subject (AES-256-GCM,
11
+ * a fresh nonce per value, the key id written next to it); `open` gives the values back, and
12
+ * `ERASED_PERSONAL_DATA` for those whose key was destroyed by `SubjectKeyStore.erase`.
13
+ */
14
+ export class PersonalDataCipher {
15
+ keys;
16
+ constructor(keys) {
17
+ this.keys = keys;
18
+ }
19
+ /** Whether the data holds a personal value, sealed or not. */
20
+ static holdsPersonalData(data) {
21
+ return holdsIn(data);
22
+ }
23
+ seal(data) {
24
+ return rewriteObjects(data, (object) => {
25
+ const personal = personalOf(object);
26
+ return personal === undefined ? undefined : this.sealed(personal.subject, personal.value);
27
+ });
28
+ }
29
+ open(data) {
30
+ return rewriteObjects(data, (object) => {
31
+ const sealed = sealedOf(object);
32
+ return sealed === undefined ? undefined : this.opened(sealed);
33
+ });
34
+ }
35
+ async sealed(subject, value) {
36
+ const key = await this.keys.keyFor(subject);
37
+ const iv = randomBytes(IV_BYTES);
38
+ const cipher = createCipheriv(ALGORITHM, materialOf(key), iv);
39
+ cipher.setAAD(Buffer.from(key.id));
40
+ const encrypted = Buffer.concat([cipher.update(value, 'utf8'), cipher.final(), cipher.getAuthTag()]);
41
+ return { $sealed: { key: key.id, iv: iv.toString('base64'), data: encrypted.toString('base64') } };
42
+ }
43
+ async opened(sealed) {
44
+ const key = await this.keys.find(sealed.key);
45
+ if (key === undefined) {
46
+ return ERASED_PERSONAL_DATA;
47
+ }
48
+ const bytes = Buffer.from(sealed.data, 'base64');
49
+ const decipher = createDecipheriv(ALGORITHM, materialOf(key), Buffer.from(sealed.iv, 'base64'));
50
+ decipher.setAAD(Buffer.from(key.id));
51
+ decipher.setAuthTag(bytes.subarray(bytes.length - TAG_BYTES));
52
+ return Buffer.concat([decipher.update(bytes.subarray(0, bytes.length - TAG_BYTES)), decipher.final()]).toString('utf8');
53
+ }
54
+ }
55
+ function materialOf(key) {
56
+ return Buffer.from(key.material, 'base64');
57
+ }
58
+ function holdsIn(value) {
59
+ if (isStoredData(value)) {
60
+ return isMarked(value) || Object.values(value).some(holdsIn);
61
+ }
62
+ return Array.isArray(value) && value.some((item) => holdsIn(item));
63
+ }
64
+ function isMarked(value) {
65
+ return personalOf(value) !== undefined || sealedOf(value) !== undefined;
66
+ }
67
+ function personalOf(object) {
68
+ const marked = onlyField(object, '$personal');
69
+ const subject = marked?.['subject'];
70
+ const value = marked?.['value'];
71
+ return typeof subject === 'string' && typeof value === 'string' ? { subject, value } : undefined;
72
+ }
73
+ function sealedOf(object) {
74
+ const marked = onlyField(object, '$sealed');
75
+ const key = marked?.['key'];
76
+ const iv = marked?.['iv'];
77
+ const data = marked?.['data'];
78
+ return typeof key === 'string' && typeof iv === 'string' && typeof data === 'string' ? { key, iv, data } : undefined;
79
+ }
80
+ function onlyField(object, field) {
81
+ const value = object[field];
82
+ return Object.keys(object).length === 1 && isStoredData(value) ? value : undefined;
83
+ }
84
+ //# sourceMappingURL=personal-data-cipher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"personal-data-cipher.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/personal-data-cipher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,0DAA0D,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAC;AAKlF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,SAAS,GAAG,aAAa,CAAC;AAChC,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IACA,IAAI;IAAjC,YAA6B,IAAqB;oBAArB,IAAI;IAAoB,CAAC;IAEtD,8DAA8D;IAC9D,MAAM,CAAC,iBAAiB,CAAC,IAAgB;QACvC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,CAAC,IAAgB;QACnB,OAAO,cAAc,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;YACrC,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;YAEpC,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CA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E5B,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACrF,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Where the tables of an event store live in PostgreSQL. */
2
+ export interface EventStoreTablesOptions {
3
+ /** The schema of the bounded context; created when missing. Without it, the default schema of the connection. */
4
+ readonly schema?: string;
5
+ }
6
+ //# sourceMappingURL=event-store-tables-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-store-tables-options.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/event-sourcing/postgres/event-store-tables-options.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,MAAM,WAAW,uBAAuB;IACtC,iHAAiH;IACjH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=event-store-tables-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-store-tables-options.js","sourceRoot":"","sources":["../../../../src/infrastructure/event-sourcing/postgres/event-store-tables-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import type { EventStoreTablesOptions } from './event-store-tables-options.js';
2
+ /**
3
+ * The statements that create the tables of an event store on PostgreSQL, for a migration of the
4
+ * project: the events, the head of the store (the position the next append starts after), the
5
+ * snapshots, the checkpoints of the subscriptions and the keys of the data subjects. Each one
6
+ * can run again.
7
+ */
8
+ export declare function eventStoreTablesSql(options?: EventStoreTablesOptions): readonly string[];
9
+ //# sourceMappingURL=event-store-tables-sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-store-tables-sql.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/event-sourcing/postgres/event-store-tables-sql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAG/E;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,uBAA4B,GAAG,SAAS,MAAM,EAAE,CAwB5F"}
@@ -0,0 +1,32 @@
1
+ import { qualifiedTable } from './qualified-table.js';
2
+ /**
3
+ * The statements that create the tables of an event store on PostgreSQL, for a migration of the
4
+ * project: the events, the head of the store (the position the next append starts after), the
5
+ * snapshots, the checkpoints of the subscriptions and the keys of the data subjects. Each one
6
+ * can run again.
7
+ */
8
+ export function eventStoreTablesSql(options = {}) {
9
+ const { schema } = options;
10
+ const table = (name) => qualifiedTable(schema, name);
11
+ return [
12
+ ...(schema === undefined ? [] : [`create schema if not exists "${schema.replaceAll('"', '""')}"`]),
13
+ `create table if not exists ${table('head')} (id smallint primary key, position bigint not null)`,
14
+ `create table if not exists ${table('events')} (
15
+ position bigint primary key,
16
+ stream text not null,
17
+ version integer not null,
18
+ event_id text not null unique,
19
+ type text not null,
20
+ schema_version integer not null,
21
+ data jsonb not null,
22
+ metadata jsonb not null,
23
+ occurred_at timestamptz(3) not null,
24
+ recorded_at timestamptz(3) not null default now(),
25
+ unique (stream, version)
26
+ )`,
27
+ `create table if not exists ${table('snapshots')} (stream text primary key, version integer not null, schema_version integer not null, data jsonb not null, taken_at timestamptz(3) not null default now())`,
28
+ `create table if not exists ${table('checkpoints')} (subscriber text primary key, position bigint not null, updated_at timestamptz(3) not null default now())`,
29
+ `create table if not exists ${table('subjectKeys')} (subject text primary key, key_id text not null unique, material text not null, created_at timestamptz(3) not null default now())`,
30
+ ];
31
+ }
32
+ //# sourceMappingURL=event-store-tables-sql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-store-tables-sql.js","sourceRoot":"","sources":["../../../../src/infrastructure/event-sourcing/postgres/event-store-tables-sql.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAO,GAA4B,EAAE;IACvE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,KAAK,GAAG,CAAC,IAA0C,EAAU,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEnG,OAAO;QACL,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,gCAAgC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAClG,8BAA8B,KAAK,CAAC,MAAM,CAAC,sDAAsD;QACjG,8BAA8B,KAAK,CAAC,QAAQ,CAAC;;;;;;;;;;;;EAY/C;QACE,8BAA8B,KAAK,CAAC,WAAW,CAAC,4JAA4J;QAC5M,8BAA8B,KAAK,CAAC,aAAa,CAAC,4GAA4G;QAC9J,8BAA8B,KAAK,CAAC,aAAa,CAAC,oIAAoI;KACvL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ /** The names of the tables of an event store, fixed: a context that keeps one gives it a schema of its own. */
2
+ export declare const EVENT_STORE_TABLES: {
3
+ readonly events: 'stored_events';
4
+ readonly head: 'stored_events_head';
5
+ readonly snapshots: 'stream_snapshots';
6
+ readonly checkpoints: 'subscription_checkpoints';
7
+ readonly subjectKeys: 'subject_keys';
8
+ };
9
+ //# sourceMappingURL=event-store-tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-store-tables.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/event-sourcing/postgres/event-store-tables.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,eAAO,MAAM,kBAAkB;aAC7B,MAAM,EAAE,eAAe;aACvB,IAAI,EAAE,oBAAoB;aAC1B,SAAS,EAAE,kBAAkB;aAC7B,WAAW,EAAE,0BAA0B;aACvC,WAAW,EAAE,cAAc;CACnB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /** The names of the tables of an event store, fixed: a context that keeps one gives it a schema of its own. */
2
+ export const EVENT_STORE_TABLES = {
3
+ events: 'stored_events',
4
+ head: 'stored_events_head',
5
+ snapshots: 'stream_snapshots',
6
+ checkpoints: 'subscription_checkpoints',
7
+ subjectKeys: 'subject_keys',
8
+ };
9
+ //# sourceMappingURL=event-store-tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-store-tables.js","sourceRoot":"","sources":["../../../../src/infrastructure/event-sourcing/postgres/event-store-tables.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,MAAM,EAAE,eAAe;IACvB,IAAI,EAAE,oBAAoB;IAC1B,SAAS,EAAE,kBAAkB;IAC7B,WAAW,EAAE,0BAA0B;IACvC,WAAW,EAAE,cAAc;CACnB,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Whether an append lost to a concurrent one, whatever wraps the error of the driver: the driver alone (knex), `cause` (drizzle), `driverError` (TypeORM) or `meta` (Prisma). */
2
+ export declare function isAppendConflict(error: unknown, depth?: number): boolean;
3
+ //# sourceMappingURL=is-append-conflict.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-append-conflict.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/event-sourcing/postgres/is-append-conflict.ts"],"names":[],"mappings":"AAWA,kLAAkL;AAClL,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAQ,GAAG,OAAO,CAYvE"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * What PostgreSQL answers when another transaction appended first: a duplicate (stream, version)
3
+ * (23505); a serialization failure (40001) when the unit of work runs at REPEATABLE READ or
4
+ * SERIALIZABLE and the head of the store moved since it began; a deadlock (40P01) when the same
5
+ * transaction took other row locks in another order than a concurrent one. Each is a conflict the
6
+ * caller retries, never a fault of the store.
7
+ */
8
+ const CONFLICTS = new Set(['23505', '40001', '40P01']);
9
+ const WRAPPERS = ['cause', 'driverError', 'meta', 'originalError'];
10
+ const DEPTH = 4;
11
+ /** Whether an append lost to a concurrent one, whatever wraps the error of the driver: the driver alone (knex), `cause` (drizzle), `driverError` (TypeORM) or `meta` (Prisma). */
12
+ export function isAppendConflict(error, depth = DEPTH) {
13
+ if (typeof error !== 'object' || error === null || depth === 0) {
14
+ return false;
15
+ }
16
+ const code = Reflect.get(error, 'code');
17
+ if (typeof code === 'string' && CONFLICTS.has(code)) {
18
+ return true;
19
+ }
20
+ return WRAPPERS.some((key) => isAppendConflict(Reflect.get(error, key), depth - 1));
21
+ }
22
+ //# sourceMappingURL=is-append-conflict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-append-conflict.js","sourceRoot":"","sources":["../../../../src/infrastructure/event-sourcing/postgres/is-append-conflict.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AACvD,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AACnE,MAAM,KAAK,GAAG,CAAC,CAAC;AAEhB,kLAAkL;AAClL,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,KAAK,GAAG,KAAK;IAC5D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAC/D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,IAAI,GAAY,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAEjD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { CheckpointStore } from '../../../application/ports/checkpoint-store.js';
2
+ import type { SqlRun } from '../../read-model/sql-run.js';
3
+ import type { EventStoreTablesOptions } from './event-store-tables-options.js';
4
+ /** The checkpoints of the subscriptions on PostgreSQL, moved by a statement guarded by the position it starts from. */
5
+ export declare class PostgresCheckpointStore implements CheckpointStore {
6
+ private readonly run;
7
+ private readonly table;
8
+ constructor(run: SqlRun, options?: EventStoreTablesOptions);
9
+ position(subscriber: string): Promise<number>;
10
+ advance(subscriber: string, from: number, to: number): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=postgres-checkpoint-store.d.ts.map