@ddd-ts-kit/kernel 0.10.0 → 0.12.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 (226) hide show
  1. package/README.md +129 -4
  2. package/dist/application/background/background-job-execution.d.ts +27 -0
  3. package/dist/application/background/background-job-execution.d.ts.map +1 -0
  4. package/dist/application/background/background-job-execution.js +2 -0
  5. package/dist/application/background/background-job-execution.js.map +1 -0
  6. package/dist/application/background/background-job-options.d.ts +16 -0
  7. package/dist/application/background/background-job-options.d.ts.map +1 -0
  8. package/dist/application/background/background-job-options.js +2 -0
  9. package/dist/application/background/background-job-options.js.map +1 -0
  10. package/dist/application/background/background-job-policy.d.ts +12 -0
  11. package/dist/application/background/background-job-policy.d.ts.map +1 -0
  12. package/dist/application/background/background-job-policy.js +24 -0
  13. package/dist/application/background/background-job-policy.js.map +1 -0
  14. package/dist/application/background/background-job-type.d.ts +10 -0
  15. package/dist/application/background/background-job-type.d.ts.map +1 -0
  16. package/dist/application/background/background-job-type.js +2 -0
  17. package/dist/application/background/background-job-type.js.map +1 -0
  18. package/dist/application/background/background-job.d.ts +14 -0
  19. package/dist/application/background/background-job.d.ts.map +1 -0
  20. package/dist/application/background/background-job.js +2 -0
  21. package/dist/application/background/background-job.js.map +1 -0
  22. package/dist/application/background/enqueue-options.d.ts +20 -0
  23. package/dist/application/background/enqueue-options.d.ts.map +1 -0
  24. package/dist/application/background/enqueue-options.js +2 -0
  25. package/dist/application/background/enqueue-options.js.map +1 -0
  26. package/dist/application/background/enqueued-by.d.ts +13 -0
  27. package/dist/application/background/enqueued-by.d.ts.map +1 -0
  28. package/dist/application/background/enqueued-by.js +2 -0
  29. package/dist/application/background/enqueued-by.js.map +1 -0
  30. package/dist/application/background/enqueued-job.d.ts +7 -0
  31. package/dist/application/background/enqueued-job.d.ts.map +1 -0
  32. package/dist/application/background/enqueued-job.js +2 -0
  33. package/dist/application/background/enqueued-job.js.map +1 -0
  34. package/dist/application/background/execution-context-of-background-job.d.ts +14 -0
  35. package/dist/application/background/execution-context-of-background-job.d.ts.map +1 -0
  36. package/dist/application/background/execution-context-of-background-job.js +18 -0
  37. package/dist/application/background/execution-context-of-background-job.js.map +1 -0
  38. package/dist/application/background/index.d.ts +15 -0
  39. package/dist/application/background/index.d.ts.map +1 -0
  40. package/dist/application/background/index.js +15 -0
  41. package/dist/application/background/index.js.map +1 -0
  42. package/dist/application/background/job-backoff.d.ts +10 -0
  43. package/dist/application/background/job-backoff.d.ts.map +1 -0
  44. package/dist/application/background/job-backoff.js +2 -0
  45. package/dist/application/background/job-backoff.js.map +1 -0
  46. package/dist/application/background/job-progress.d.ts +7 -0
  47. package/dist/application/background/job-progress.d.ts.map +1 -0
  48. package/dist/application/background/job-progress.js +2 -0
  49. package/dist/application/background/job-progress.js.map +1 -0
  50. package/dist/application/background/queued-job-status.d.ts +18 -0
  51. package/dist/application/background/queued-job-status.d.ts.map +1 -0
  52. package/dist/application/background/queued-job-status.js +17 -0
  53. package/dist/application/background/queued-job-status.js.map +1 -0
  54. package/dist/application/background/queued-job.d.ts +25 -0
  55. package/dist/application/background/queued-job.d.ts.map +1 -0
  56. package/dist/application/background/queued-job.js +2 -0
  57. package/dist/application/background/queued-job.js.map +1 -0
  58. package/dist/application/background/retry-delay-ms.d.ts +4 -0
  59. package/dist/application/background/retry-delay-ms.d.ts.map +1 -0
  60. package/dist/application/background/retry-delay-ms.js +6 -0
  61. package/dist/application/background/retry-delay-ms.js.map +1 -0
  62. package/dist/application/cache/cache-purge-payload.d.ts +5 -0
  63. package/dist/application/cache/cache-purge-payload.d.ts.map +1 -0
  64. package/dist/application/cache/cache-purge-payload.js +2 -0
  65. package/dist/application/cache/cache-purge-payload.js.map +1 -0
  66. package/dist/application/cache/cache-purge-request.d.ts +19 -0
  67. package/dist/application/cache/cache-purge-request.d.ts.map +1 -0
  68. package/dist/application/cache/cache-purge-request.js +24 -0
  69. package/dist/application/cache/cache-purge-request.js.map +1 -0
  70. package/dist/application/cache/cache-tag.d.ts +8 -0
  71. package/dist/application/cache/cache-tag.d.ts.map +1 -0
  72. package/dist/application/cache/cache-tag.js +10 -0
  73. package/dist/application/cache/cache-tag.js.map +1 -0
  74. package/dist/application/cache/tenant-cache-tags.d.ts +7 -0
  75. package/dist/application/cache/tenant-cache-tags.d.ts.map +1 -0
  76. package/dist/application/cache/tenant-cache-tags.js +13 -0
  77. package/dist/application/cache/tenant-cache-tags.js.map +1 -0
  78. package/dist/application/execution/execution-origin.d.ts +1 -1
  79. package/dist/application/execution/execution-origin.d.ts.map +1 -1
  80. package/dist/application/persistence/expect-version.d.ts +13 -0
  81. package/dist/application/persistence/expect-version.d.ts.map +1 -0
  82. package/dist/application/persistence/expect-version.js +16 -0
  83. package/dist/application/persistence/expect-version.js.map +1 -0
  84. package/dist/application/ports/cache-invalidation.d.ts +11 -0
  85. package/dist/application/ports/cache-invalidation.d.ts.map +1 -0
  86. package/dist/application/ports/cache-invalidation.js +13 -0
  87. package/dist/application/ports/cache-invalidation.js.map +1 -0
  88. package/dist/application/ports/cache-purger.d.ts +9 -0
  89. package/dist/application/ports/cache-purger.d.ts.map +1 -0
  90. package/dist/application/ports/cache-purger.js +11 -0
  91. package/dist/application/ports/cache-purger.js.map +1 -0
  92. package/dist/application/ports/job-queue.d.ts +26 -0
  93. package/dist/application/ports/job-queue.d.ts.map +1 -0
  94. package/dist/application/ports/job-queue.js +16 -0
  95. package/dist/application/ports/job-queue.js.map +1 -0
  96. package/dist/application/ports/process-runner.d.ts +25 -0
  97. package/dist/application/ports/process-runner.d.ts.map +1 -0
  98. package/dist/application/ports/process-runner.js +11 -0
  99. package/dist/application/ports/process-runner.js.map +1 -0
  100. package/dist/application/ports/process-store.d.ts +12 -0
  101. package/dist/application/ports/process-store.d.ts.map +1 -0
  102. package/dist/application/ports/process-store.js +7 -0
  103. package/dist/application/ports/process-store.js.map +1 -0
  104. package/dist/application/process/index.d.ts +8 -0
  105. package/dist/application/process/index.d.ts.map +1 -0
  106. package/dist/application/process/index.js +8 -0
  107. package/dist/application/process/index.js.map +1 -0
  108. package/dist/application/process/process-decision.d.ts +18 -0
  109. package/dist/application/process/process-decision.d.ts.map +1 -0
  110. package/dist/application/process/process-decision.js +2 -0
  111. package/dist/application/process/process-decision.js.map +1 -0
  112. package/dist/application/process/process-manager.d.ts +13 -0
  113. package/dist/application/process/process-manager.d.ts.map +1 -0
  114. package/dist/application/process/process-manager.js +2 -0
  115. package/dist/application/process/process-manager.js.map +1 -0
  116. package/dist/application/process/process-timeout-due.d.ts +6 -0
  117. package/dist/application/process/process-timeout-due.d.ts.map +1 -0
  118. package/dist/application/process/process-timeout-due.js +2 -0
  119. package/dist/application/process/process-timeout-due.js.map +1 -0
  120. package/dist/application/process/process-timeout.d.ts +6 -0
  121. package/dist/application/process/process-timeout.d.ts.map +1 -0
  122. package/dist/application/process/process-timeout.js +2 -0
  123. package/dist/application/process/process-timeout.js.map +1 -0
  124. package/dist/application/process/process-type.d.ts +12 -0
  125. package/dist/application/process/process-type.d.ts.map +1 -0
  126. package/dist/application/process/process-type.js +2 -0
  127. package/dist/application/process/process-type.js.map +1 -0
  128. package/dist/application/process/stored-process.d.ts +15 -0
  129. package/dist/application/process/stored-process.d.ts.map +1 -0
  130. package/dist/application/process/stored-process.js +2 -0
  131. package/dist/application/process/stored-process.js.map +1 -0
  132. package/dist/application/process/unreadable-process-state-error.d.ts +6 -0
  133. package/dist/application/process/unreadable-process-state-error.d.ts.map +1 -0
  134. package/dist/application/process/unreadable-process-state-error.js +9 -0
  135. package/dist/application/process/unreadable-process-state-error.js.map +1 -0
  136. package/dist/declarations/decorators/background.d.ts +13 -0
  137. package/dist/declarations/decorators/background.d.ts.map +1 -0
  138. package/dist/declarations/decorators/background.js +41 -0
  139. package/dist/declarations/decorators/background.js.map +1 -0
  140. package/dist/declarations/model/background-job-declaration.d.ts +14 -0
  141. package/dist/declarations/model/background-job-declaration.d.ts.map +1 -0
  142. package/dist/declarations/model/background-job-declaration.js +2 -0
  143. package/dist/declarations/model/background-job-declaration.js.map +1 -0
  144. package/dist/declarations/model/declaration.d.ts +2 -1
  145. package/dist/declarations/model/declaration.d.ts.map +1 -1
  146. package/dist/declarations.d.ts +5 -0
  147. package/dist/declarations.d.ts.map +1 -1
  148. package/dist/declarations.js +1 -0
  149. package/dist/declarations.js.map +1 -1
  150. package/dist/domain/errors/precondition-failed-error.d.ts +12 -0
  151. package/dist/domain/errors/precondition-failed-error.d.ts.map +1 -0
  152. package/dist/domain/errors/precondition-failed-error.js +12 -0
  153. package/dist/domain/errors/precondition-failed-error.js.map +1 -0
  154. package/dist/domain/state-machine/define-state-machine.d.ts +22 -0
  155. package/dist/domain/state-machine/define-state-machine.d.ts.map +1 -0
  156. package/dist/domain/state-machine/define-state-machine.js +23 -0
  157. package/dist/domain/state-machine/define-state-machine.js.map +1 -0
  158. package/dist/domain/state-machine/forbidden-transition.d.ts +6 -0
  159. package/dist/domain/state-machine/forbidden-transition.d.ts.map +1 -0
  160. package/dist/domain/state-machine/forbidden-transition.js +2 -0
  161. package/dist/domain/state-machine/forbidden-transition.js.map +1 -0
  162. package/dist/domain/state-machine/index.d.ts +10 -0
  163. package/dist/domain/state-machine/index.d.ts.map +1 -0
  164. package/dist/domain/state-machine/index.js +10 -0
  165. package/dist/domain/state-machine/index.js.map +1 -0
  166. package/dist/domain/state-machine/invalid-state-machine-error.d.ts +6 -0
  167. package/dist/domain/state-machine/invalid-state-machine-error.d.ts.map +1 -0
  168. package/dist/domain/state-machine/invalid-state-machine-error.js +9 -0
  169. package/dist/domain/state-machine/invalid-state-machine-error.js.map +1 -0
  170. package/dist/domain/state-machine/mermaid-of-state-machine.d.ts +4 -0
  171. package/dist/domain/state-machine/mermaid-of-state-machine.d.ts.map +1 -0
  172. package/dist/domain/state-machine/mermaid-of-state-machine.js +16 -0
  173. package/dist/domain/state-machine/mermaid-of-state-machine.js.map +1 -0
  174. package/dist/domain/state-machine/state-machine-declaration.d.ts +22 -0
  175. package/dist/domain/state-machine/state-machine-declaration.d.ts.map +1 -0
  176. package/dist/domain/state-machine/state-machine-declaration.js +2 -0
  177. package/dist/domain/state-machine/state-machine-declaration.js.map +1 -0
  178. package/dist/domain/state-machine/state-machine-description.d.ts +15 -0
  179. package/dist/domain/state-machine/state-machine-description.d.ts.map +1 -0
  180. package/dist/domain/state-machine/state-machine-description.js +2 -0
  181. package/dist/domain/state-machine/state-machine-description.js.map +1 -0
  182. package/dist/domain/state-machine/state-machine.d.ts +33 -0
  183. package/dist/domain/state-machine/state-machine.d.ts.map +1 -0
  184. package/dist/domain/state-machine/state-machine.js +90 -0
  185. package/dist/domain/state-machine/state-machine.js.map +1 -0
  186. package/dist/domain/state-machine/transition-declaration.d.ts +13 -0
  187. package/dist/domain/state-machine/transition-declaration.d.ts.map +1 -0
  188. package/dist/domain/state-machine/transition-declaration.js +2 -0
  189. package/dist/domain/state-machine/transition-declaration.js.map +1 -0
  190. package/dist/domain/state-machine/transition-error.d.ts +13 -0
  191. package/dist/domain/state-machine/transition-error.d.ts.map +1 -0
  192. package/dist/domain/state-machine/transition-error.js +12 -0
  193. package/dist/domain/state-machine/transition-error.js.map +1 -0
  194. package/dist/index.d.ts +21 -0
  195. package/dist/index.d.ts.map +1 -1
  196. package/dist/index.js +21 -0
  197. package/dist/index.js.map +1 -1
  198. package/dist/infrastructure/cache/published-cache-invalidation.d.ts +33 -0
  199. package/dist/infrastructure/cache/published-cache-invalidation.d.ts.map +1 -0
  200. package/dist/infrastructure/cache/published-cache-invalidation.js +35 -0
  201. package/dist/infrastructure/cache/published-cache-invalidation.js.map +1 -0
  202. package/dist/infrastructure/cache/purging-publisher.d.ts +18 -0
  203. package/dist/infrastructure/cache/purging-publisher.d.ts.map +1 -0
  204. package/dist/infrastructure/cache/purging-publisher.js +33 -0
  205. package/dist/infrastructure/cache/purging-publisher.js.map +1 -0
  206. package/dist/infrastructure/cache/repeated-cache-purger.d.ts +25 -0
  207. package/dist/infrastructure/cache/repeated-cache-purger.d.ts.map +1 -0
  208. package/dist/infrastructure/cache/repeated-cache-purger.js +37 -0
  209. package/dist/infrastructure/cache/repeated-cache-purger.js.map +1 -0
  210. package/dist/infrastructure/domain-events/when-committed.d.ts +10 -0
  211. package/dist/infrastructure/domain-events/when-committed.d.ts.map +1 -0
  212. package/dist/infrastructure/domain-events/when-committed.js +30 -0
  213. package/dist/infrastructure/domain-events/when-committed.js.map +1 -0
  214. package/dist/infrastructure/in-memory/in-memory-cache-invalidation.d.ts +7 -0
  215. package/dist/infrastructure/in-memory/in-memory-cache-invalidation.d.ts.map +1 -0
  216. package/dist/infrastructure/in-memory/in-memory-cache-invalidation.js +8 -0
  217. package/dist/infrastructure/in-memory/in-memory-cache-invalidation.js.map +1 -0
  218. package/dist/infrastructure/in-memory/in-memory-cache-purger.d.ts +13 -0
  219. package/dist/infrastructure/in-memory/in-memory-cache-purger.d.ts.map +1 -0
  220. package/dist/infrastructure/in-memory/in-memory-cache-purger.js +23 -0
  221. package/dist/infrastructure/in-memory/in-memory-cache-purger.js.map +1 -0
  222. package/dist/infrastructure/in-memory/in-memory-process-store.d.ts +11 -0
  223. package/dist/infrastructure/in-memory/in-memory-process-store.d.ts.map +1 -0
  224. package/dist/infrastructure/in-memory/in-memory-process-store.js +29 -0
  225. package/dist/infrastructure/in-memory/in-memory-process-store.js.map +1 -0
  226. package/package.json +1 -1
@@ -0,0 +1,25 @@
1
+ import type { JobProgress } from './job-progress.js';
2
+ import type { QueuedJobStatus } from './queued-job-status.js';
3
+ /** A background job as the queue holds it, for a screen or an operator. Never its payload. */
4
+ export interface QueuedJob {
5
+ readonly id: string;
6
+ readonly name: string;
7
+ /** The context the job belongs to: the first part of its name. */
8
+ readonly queue: string;
9
+ readonly status: QueuedJobStatus;
10
+ /** Attempts started, the one in progress included. */
11
+ readonly attempts: number;
12
+ readonly enqueuedAt: Date;
13
+ /** Not claimed before this instant. */
14
+ readonly runAt: Date;
15
+ /** The tenant of the work that enqueued it, when that work had one. */
16
+ readonly tenantId?: string;
17
+ /** What the job works on, as `enqueue` named it (`EnqueueOptions.subject`). */
18
+ readonly subject?: string;
19
+ readonly progress?: JobProgress;
20
+ /** The `code` of the last failure, never a message. */
21
+ readonly lastErrorCode?: string;
22
+ /** When it succeeded, was cancelled or died. */
23
+ readonly finishedAt?: Date;
24
+ }
25
+ //# sourceMappingURL=queued-job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queued-job.d.ts","sourceRoot":"","sources":["../../../src/application/background/queued-job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,8FAA8F;AAC9F,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC;IAChC,uDAAuD;IACvD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,gDAAgD;IAChD,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC;CAC5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=queued-job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queued-job.js","sourceRoot":"","sources":["../../../src/application/background/queued-job.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { BackgroundJobPolicy } from './background-job-policy.js';
2
+ /** How long to wait before the attempt that follows `attempt`: exponential, capped. */
3
+ export declare function retryDelayMs({ backoff }: BackgroundJobPolicy, attempt: number): number;
4
+ //# sourceMappingURL=retry-delay-ms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry-delay-ms.d.ts","sourceRoot":"","sources":["../../../src/application/background/retry-delay-ms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAItF"}
@@ -0,0 +1,6 @@
1
+ /** How long to wait before the attempt that follows `attempt`: exponential, capped. */
2
+ export function retryDelayMs({ backoff }, attempt) {
3
+ const { baseMs, factor, maxMs } = backoff;
4
+ return Math.min(maxMs, baseMs * factor ** Math.max(0, attempt - 1));
5
+ }
6
+ //# sourceMappingURL=retry-delay-ms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry-delay-ms.js","sourceRoot":"","sources":["../../../src/application/background/retry-delay-ms.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,MAAM,UAAU,YAAY,CAAC,EAAE,OAAO,EAAuB,EAAE,OAAe;IAC5E,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAE1C,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** What a purge request carries: the tags to purge, already filed under their tenant. */
2
+ export interface CachePurgePayload {
3
+ readonly tags: readonly string[];
4
+ }
5
+ //# sourceMappingURL=cache-purge-payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-purge-payload.d.ts","sourceRoot":"","sources":["../../../src/application/cache/cache-purge-payload.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cache-purge-payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-purge-payload.js","sourceRoot":"","sources":["../../../src/application/cache/cache-purge-payload.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import type { IntegrationEvent } from '../events/integration-event.js';
2
+ import type { CachePurgePayload } from './cache-purge-payload.js';
3
+ /**
4
+ * The message that asks for tags to be purged once the work that asked has committed. It
5
+ * travels as an integration event on the outbox of the application, so it commits or rolls back
6
+ * with that work, and the relay hands it to a `CachePurger` instead of the broker. It is a
7
+ * message of the kit, never part of the published language of a context.
8
+ */
9
+ export declare const CachePurgeRequest: {
10
+ readonly type: "kit.cache.purge-requested";
11
+ readonly version: 1;
12
+ readonly of: (tags: readonly string[], meta: {
13
+ readonly id: string;
14
+ readonly occurredAt: string;
15
+ }) => IntegrationEvent<CachePurgePayload>;
16
+ /** The tags a purge request names; `undefined` for any other event. */
17
+ readonly tagsOf: (event: IntegrationEvent) => readonly string[] | undefined;
18
+ };
19
+ //# sourceMappingURL=cache-purge-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-purge-request.d.ts","sourceRoot":"","sources":["../../../src/application/cache/cache-purge-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAKlE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB;aAC5B,IAAI;aACJ,OAAO;aAEP,EAAE,SACM,SAAS,MAAM,EAAE,QACjB;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,KACzD,gBAAgB,CAAC,iBAAiB,CAAC;IAItC,uEAAuE;aACvE,MAAM,UAAQ,gBAAgB,KAAG,SAAS,MAAM,EAAE,GAAG,SAAS;CAStD,CAAC"}
@@ -0,0 +1,24 @@
1
+ const TYPE = 'kit.cache.purge-requested';
2
+ const VERSION = 1;
3
+ /**
4
+ * The message that asks for tags to be purged once the work that asked has committed. It
5
+ * travels as an integration event on the outbox of the application, so it commits or rolls back
6
+ * with that work, and the relay hands it to a `CachePurger` instead of the broker. It is a
7
+ * message of the kit, never part of the published language of a context.
8
+ */
9
+ export const CachePurgeRequest = {
10
+ type: TYPE,
11
+ version: VERSION,
12
+ of(tags, meta) {
13
+ return { id: meta.id, type: TYPE, version: VERSION, occurredAt: meta.occurredAt, payload: { tags: [...tags] } };
14
+ },
15
+ /** The tags a purge request names; `undefined` for any other event. */
16
+ tagsOf(event) {
17
+ if (event.type !== TYPE || typeof event.payload !== 'object' || event.payload === null) {
18
+ return undefined;
19
+ }
20
+ const tags = Reflect.get(event.payload, 'tags');
21
+ return Array.isArray(tags) ? tags.filter((tag) => typeof tag === 'string') : undefined;
22
+ },
23
+ };
24
+ //# sourceMappingURL=cache-purge-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-purge-request.js","sourceRoot":"","sources":["../../../src/application/cache/cache-purge-request.ts"],"names":[],"mappings":"AAGA,MAAM,IAAI,GAAG,2BAA2B,CAAC;AACzC,MAAM,OAAO,GAAG,CAAC,CAAC;AAElB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,OAAO;IAEhB,EAAE,CACA,IAAuB,EACvB,IAA0D;QAE1D,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;IAClH,CAAC;IAED,uEAAuE;IACvE,MAAM,CAAC,KAAuB;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YACvF,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,IAAI,GAAY,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAEzD,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAiB,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACxG,CAAC;CACO,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The tag a shared cache files an answer under, for the resource it shows: `cacheTag('calendar',
3
+ * 'c-1')` is `calendar:c-1`, `cacheTag('calendar')` names every calendar. The answer and the purge
4
+ * name a resource with the same function, so they always meet. The identifier is percent-encoded:
5
+ * a tag holds no space and no comma, which separate tags in the headers of the caches.
6
+ */
7
+ export declare function cacheTag(resource: string, id?: string | number): string;
8
+ //# sourceMappingURL=cache-tag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-tag.d.ts","sourceRoot":"","sources":["../../../src/application/cache/cache-tag.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAEvE"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The tag a shared cache files an answer under, for the resource it shows: `cacheTag('calendar',
3
+ * 'c-1')` is `calendar:c-1`, `cacheTag('calendar')` names every calendar. The answer and the purge
4
+ * name a resource with the same function, so they always meet. The identifier is percent-encoded:
5
+ * a tag holds no space and no comma, which separate tags in the headers of the caches.
6
+ */
7
+ export function cacheTag(resource, id) {
8
+ return id === undefined ? resource : `${resource}:${encodeURIComponent(String(id))}`;
9
+ }
10
+ //# sourceMappingURL=cache-tag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-tag.js","sourceRoot":"","sources":["../../../src/application/cache/cache-tag.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,EAAoB;IAC7D,OAAO,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AACvF,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The tags of a tenant: each one under the identifier of the tenant, `acme/calendar:c-1`, so
3
+ * that a purge for one tenant never reaches the answers of another, and a kind (`calendar`) is
4
+ * purged tenant by tenant. Without a tenant, the tags as they are.
5
+ */
6
+ export declare function tenantCacheTags(tags: readonly string[], tenantId: string | undefined): readonly string[];
7
+ //# sourceMappingURL=tenant-cache-tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-cache-tags.d.ts","sourceRoot":"","sources":["../../../src/application/cache/tenant-cache-tags.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,MAAM,EAAE,CAQxG"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The tags of a tenant: each one under the identifier of the tenant, `acme/calendar:c-1`, so
3
+ * that a purge for one tenant never reaches the answers of another, and a kind (`calendar`) is
4
+ * purged tenant by tenant. Without a tenant, the tags as they are.
5
+ */
6
+ export function tenantCacheTags(tags, tenantId) {
7
+ if (tenantId === undefined) {
8
+ return tags;
9
+ }
10
+ const prefix = `${encodeURIComponent(tenantId)}/`;
11
+ return tags.map((tag) => `${prefix}${tag}`);
12
+ }
13
+ //# sourceMappingURL=tenant-cache-tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-cache-tags.js","sourceRoot":"","sources":["../../../src/application/cache/tenant-cache-tags.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAuB,EAAE,QAA4B;IACnF,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,kBAAkB,CAAC,QAAQ,CAAC,GAAG,CAAC;IAElD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC;AAC9C,CAAC"}
@@ -1,3 +1,3 @@
1
1
  /** The standard origins come first; any other string names an origin of the project. */
2
- export type ExecutionOrigin = 'http' | 'event' | 'schedule' | 'cli' | (string & Record<never, never>);
2
+ export type ExecutionOrigin = 'http' | 'event' | 'schedule' | 'queue' | 'cli' | (string & Record<never, never>);
3
3
  //# sourceMappingURL=execution-origin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"execution-origin.d.ts","sourceRoot":"","sources":["../../../src/application/execution/execution-origin.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,KAAK,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"execution-origin.d.ts","sourceRoot":"","sources":["../../../src/application/execution/execution-origin.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,KAAK,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Refuses to change an element whose version is not the one the caller read: the version an
3
+ * HTTP client sent in `If-Match`, handed over in the command. Nothing is checked when the caller
4
+ * named none.
5
+ *
6
+ * const calendar = await this.calendars.findById(command.calendarId);
7
+ * expectVersion(calendar, command.expectedVersion);
8
+ */
9
+ export declare function expectVersion(element: {
10
+ readonly id: string | number;
11
+ readonly version: number;
12
+ }, expected: number | undefined): void;
13
+ //# sourceMappingURL=expect-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-version.d.ts","sourceRoot":"","sources":["../../../src/application/persistence/expect-version.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EACnE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,IAAI,CAQN"}
@@ -0,0 +1,16 @@
1
+ import { PreconditionFailedError } from '../../domain/errors/precondition-failed-error.js';
2
+ /**
3
+ * Refuses to change an element whose version is not the one the caller read: the version an
4
+ * HTTP client sent in `If-Match`, handed over in the command. Nothing is checked when the caller
5
+ * named none.
6
+ *
7
+ * const calendar = await this.calendars.findById(command.calendarId);
8
+ * expectVersion(calendar, command.expectedVersion);
9
+ */
10
+ export function expectVersion(element, expected) {
11
+ if (expected === undefined || element.version === expected) {
12
+ return;
13
+ }
14
+ throw new PreconditionFailedError(`${element.id} is at version ${element.version}, and the change was made on version ${expected}.`);
15
+ }
16
+ //# sourceMappingURL=expect-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-version.js","sourceRoot":"","sources":["../../../src/application/persistence/expect-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAE3F;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAmE,EACnE,QAA4B;IAE5B,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC3D,OAAO;IACT,CAAC;IAED,MAAM,IAAI,uBAAuB,CAC/B,GAAG,OAAO,CAAC,EAAE,kBAAkB,OAAO,CAAC,OAAO,wCAAwC,QAAQ,GAAG,CAClG,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Asks for the answers filed under the tags (`cacheTag('calendar', id)`) to be purged from the
3
+ * shared caches once the work in progress has committed: never when it rolls back, and even when
4
+ * the process stops right after the commit. Called by a `before-commit` handler of the domain
5
+ * event that changed what those answers show. A multi-tenant application files them under the
6
+ * tenant of the work.
7
+ */
8
+ export declare abstract class CacheInvalidation {
9
+ abstract invalidate(tags: readonly string[]): Promise<void>;
10
+ }
11
+ //# sourceMappingURL=cache-invalidation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-invalidation.d.ts","sourceRoot":"","sources":["../../../src/application/ports/cache-invalidation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,8BAAsB,iBAAiB;IAKrC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Asks for the answers filed under the tags (`cacheTag('calendar', id)`) to be purged from the
3
+ * shared caches once the work in progress has committed: never when it rolls back, and even when
4
+ * the process stops right after the commit. Called by a `before-commit` handler of the domain
5
+ * event that changed what those answers show. A multi-tenant application files them under the
6
+ * tenant of the work.
7
+ */
8
+ export class CacheInvalidation {
9
+ static {
10
+ Object.defineProperty(this, 'tokenKey', { value: 'kernel.CacheInvalidation' });
11
+ }
12
+ }
13
+ //# sourceMappingURL=cache-invalidation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-invalidation.js","sourceRoot":"","sources":["../../../src/application/ports/cache-invalidation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAgB,iBAAiB;IACrC;QACE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,0BAA0B,EAAE,CAAC,CAAC;IACjF,CAAC;CAGF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Removes from a shared cache (Varnish, a CDN) every answer filed under one of the tags, now.
3
+ * Idempotent: a tag nothing is filed under purges nothing, and purging twice is purging once.
4
+ * A use case never calls it: it asks `CacheInvalidation`, which purges after its commit.
5
+ */
6
+ export declare abstract class CachePurger {
7
+ abstract purge(tags: readonly string[]): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=cache-purger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-purger.d.ts","sourceRoot":"","sources":["../../../src/application/ports/cache-purger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,8BAAsB,WAAW;IAK/B,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Removes from a shared cache (Varnish, a CDN) every answer filed under one of the tags, now.
3
+ * Idempotent: a tag nothing is filed under purges nothing, and purging twice is purging once.
4
+ * A use case never calls it: it asks `CacheInvalidation`, which purges after its commit.
5
+ */
6
+ export class CachePurger {
7
+ static {
8
+ Object.defineProperty(this, 'tokenKey', { value: 'kernel.CachePurger' });
9
+ }
10
+ }
11
+ //# sourceMappingURL=cache-purger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-purger.js","sourceRoot":"","sources":["../../../src/application/ports/cache-purger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAgB,WAAW;IAC/B;QACE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC,CAAC;IAC3E,CAAC;CAGF"}
@@ -0,0 +1,26 @@
1
+ import type { BackgroundJobType } from '../background/background-job-type.js';
2
+ import type { EnqueueOptions } from '../background/enqueue-options.js';
3
+ import type { EnqueuedJob } from '../background/enqueued-job.js';
4
+ import type { QueuedJob } from '../background/queued-job.js';
5
+ /**
6
+ * Hands work to a worker. Called inside the unit of work of a command, the job is added with
7
+ * the business change: a command that rolls back leaves no job, and one that commits loses none
8
+ * (a queue sharing the transaction, such as the jobs table of the ORM packages; a queue that
9
+ * cannot share it, such as Redis, adds the job once the transaction committed and says what it
10
+ * risks). A cancellation inside a unit of work shares its fate the same way.
11
+ *
12
+ * Work done for a tenant only sees and cancels the jobs of that tenant (an elevation, the
13
+ * tenants it names); work without a tenant sees every job.
14
+ */
15
+ export declare abstract class JobQueue {
16
+ /** The payload is plain JSON data: a date travels as its ISO text. */
17
+ abstract enqueue<Payload>(job: BackgroundJobType<Payload>, payload: NoInfer<Payload>, options?: EnqueueOptions): Promise<EnqueuedJob>;
18
+ /**
19
+ * Answers false when the job is unknown, out of reach or already over. A running job sees its
20
+ * signal aborted at its next heartbeat.
21
+ */
22
+ abstract cancel(id: string): Promise<boolean>;
23
+ /** Where a job stands: status, attempts, progress. Undefined when unknown or out of reach. */
24
+ abstract find(id: string): Promise<QueuedJob | undefined>;
25
+ }
26
+ //# sourceMappingURL=job-queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-queue.d.ts","sourceRoot":"","sources":["../../../src/application/ports/job-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;;;;;;;;GASG;AACH,8BAAsB,QAAQ;IAK5B,sEAAsE;IACtE,QAAQ,CAAC,OAAO,CAAC,OAAO,EACtB,GAAG,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC/B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EACzB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,WAAW,CAAC,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9C,8FAA8F;IAC9F,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;CAC3D"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Hands work to a worker. Called inside the unit of work of a command, the job is added with
3
+ * the business change: a command that rolls back leaves no job, and one that commits loses none
4
+ * (a queue sharing the transaction, such as the jobs table of the ORM packages; a queue that
5
+ * cannot share it, such as Redis, adds the job once the transaction committed and says what it
6
+ * risks). A cancellation inside a unit of work shares its fate the same way.
7
+ *
8
+ * Work done for a tenant only sees and cancels the jobs of that tenant (an elevation, the
9
+ * tenants it names); work without a tenant sees every job.
10
+ */
11
+ export class JobQueue {
12
+ static {
13
+ Object.defineProperty(this, 'tokenKey', { value: 'kernel.JobQueue' });
14
+ }
15
+ }
16
+ //# sourceMappingURL=job-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-queue.js","sourceRoot":"","sources":["../../../src/application/ports/job-queue.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,MAAM,OAAgB,QAAQ;IAC5B;QACE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC,CAAC;IACxE,CAAC;CAiBF"}
@@ -0,0 +1,25 @@
1
+ import type { ProcessDecision } from '../process/process-decision.js';
2
+ import type { ProcessTimeoutDue } from '../process/process-timeout-due.js';
3
+ import type { ProcessType } from '../process/process-type.js';
4
+ /**
5
+ * Runs the steps of the process managers: in one unit of work, it loads the instance a key
6
+ * correlates, asks the step its decision, saves the state with optimistic concurrency, arms
7
+ * and disarms the timeouts as delayed background jobs, and sends the commands.
8
+ */
9
+ export declare abstract class ProcessRunner {
10
+ /**
11
+ * The step of an event: `current` is undefined while the instance does not exist. An ended
12
+ * instance ignores it. A step decided concurrently fails with `ConcurrencyError`: the
13
+ * redelivery of an integration event runs it again on the new state, and the caller of the
14
+ * command that raised a domain event retries that command.
15
+ */
16
+ abstract run<State>(process: ProcessType<State>, id: string, step: (current: State | undefined) => ProcessDecision<State> | undefined): Promise<void>;
17
+ /**
18
+ * The step of a timeout, called by the timeout job of the process with `execution.jobId`:
19
+ * run only while that very job is the armed one, never after it was disarmed or the process ended.
20
+ */
21
+ abstract timeout<State>(process: ProcessType<State>, due: ProcessTimeoutDue & {
22
+ readonly jobId: string;
23
+ }, step: (current: State) => ProcessDecision<State> | undefined): Promise<void>;
24
+ }
25
+ //# sourceMappingURL=process-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-runner.d.ts","sourceRoot":"","sources":["../../../src/application/ports/process-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;;GAIG;AACH,8BAAsB,aAAa;IAKjC;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,CAAC,KAAK,EAChB,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,EAC3B,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,CAAC,OAAO,EAAE,KAAK,GAAG,SAAS,KAAK,eAAe,CAAC,KAAK,CAAC,GAAG,SAAS,GACvE,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,KAAK,EACpB,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,EAC3B,GAAG,EAAE,iBAAiB,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EACnD,IAAI,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,eAAe,CAAC,KAAK,CAAC,GAAG,SAAS,GAC3D,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Runs the steps of the process managers: in one unit of work, it loads the instance a key
3
+ * correlates, asks the step its decision, saves the state with optimistic concurrency, arms
4
+ * and disarms the timeouts as delayed background jobs, and sends the commands.
5
+ */
6
+ export class ProcessRunner {
7
+ static {
8
+ Object.defineProperty(this, 'tokenKey', { value: 'kernel.ProcessRunner' });
9
+ }
10
+ }
11
+ //# sourceMappingURL=process-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-runner.js","sourceRoot":"","sources":["../../../src/application/ports/process-runner.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,OAAgB,aAAa;IACjC;QACE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAAC,CAAC;IAC7E,CAAC;CAuBF"}
@@ -0,0 +1,12 @@
1
+ import type { StoredProcess } from '../process/stored-process.js';
2
+ /** Where the instances of the process managers keep their state between two steps. */
3
+ export declare abstract class ProcessStore {
4
+ abstract load(name: string, id: string): Promise<StoredProcess | undefined>;
5
+ /**
6
+ * Saves the instance at `version`, in the transaction of the caller when the store is
7
+ * transactional. Throws `ConcurrencyError` when the stored version is not `version - 1`
8
+ * (none stored for a version of 1): another step saved it in between.
9
+ */
10
+ abstract save(process: StoredProcess): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=process-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-store.d.ts","sourceRoot":"","sources":["../../../src/application/ports/process-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,sFAAsF;AACtF,8BAAsB,YAAY;IAKhC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IAE5E;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtD"}
@@ -0,0 +1,7 @@
1
+ /** Where the instances of the process managers keep their state between two steps. */
2
+ export class ProcessStore {
3
+ static {
4
+ Object.defineProperty(this, 'tokenKey', { value: 'kernel.ProcessStore' });
5
+ }
6
+ }
7
+ //# sourceMappingURL=process-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-store.js","sourceRoot":"","sources":["../../../src/application/ports/process-store.ts"],"names":[],"mappings":"AAEA,sFAAsF;AACtF,MAAM,OAAgB,YAAY;IAChC;QACE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC;IAC5E,CAAC;CAUF"}
@@ -0,0 +1,8 @@
1
+ export * from './process-decision.js';
2
+ export * from './process-manager.js';
3
+ export * from './process-timeout-due.js';
4
+ export * from './process-timeout.js';
5
+ export * from './process-type.js';
6
+ export * from './stored-process.js';
7
+ export * from './unreadable-process-state-error.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/process/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qCAAqC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export * from './process-decision.js';
2
+ export * from './process-manager.js';
3
+ export * from './process-timeout-due.js';
4
+ export * from './process-timeout.js';
5
+ export * from './process-type.js';
6
+ export * from './stored-process.js';
7
+ export * from './unreadable-process-state-error.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/process/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qCAAqC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Command } from '../messaging/command.js';
2
+ import type { ProcessTimeout } from './process-timeout.js';
3
+ /**
4
+ * What one step of a process decides, as data: its next state, the commands it sends, the
5
+ * timeouts it arms or disarms, and whether it is over. A step that answers `undefined` ignores
6
+ * what it was given.
7
+ */
8
+ export interface ProcessDecision<State> {
9
+ readonly state: State;
10
+ /** Sent in order, in the unit of work of the step: their changes commit with the state of the process. */
11
+ readonly commands?: readonly Command<unknown>[];
12
+ readonly timeouts?: readonly ProcessTimeout[];
13
+ /** The names of armed timeouts the step disarms. */
14
+ readonly cancel?: readonly string[];
15
+ /** An ended process ignores every later event and timeout. */
16
+ readonly ended?: boolean;
17
+ }
18
+ //# sourceMappingURL=process-decision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-decision.d.ts","sourceRoot":"","sources":["../../../src/application/process/process-decision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,KAAK;IACpC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,0GAA0G;IAC1G,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAC9C,oDAAoD;IACpD,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=process-decision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-decision.js","sourceRoot":"","sources":["../../../src/application/process/process-decision.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { ProcessDecision } from './process-decision.js';
2
+ /**
3
+ * A class of `application/processes/`: a long-running process that reacts to events, keeps a
4
+ * state of its own and sends commands. Its steps are plain functions of the current state and
5
+ * what happened, answering a `ProcessDecision`: it holds no repository and writes no aggregate,
6
+ * the commands do (`process/sends-commands-only`). Its timeouts are the one step every process
7
+ * has; the other steps are methods named after what they react to.
8
+ */
9
+ export interface ProcessManager<State> {
10
+ /** The step run when the timeout `name` is due. */
11
+ timedOut(name: string, current: State): ProcessDecision<State> | undefined;
12
+ }
13
+ //# sourceMappingURL=process-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../../src/application/process/process-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK;IACnC,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;CAC5E"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=process-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-manager.js","sourceRoot":"","sources":["../../../src/application/process/process-manager.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ /** What the timeout job of a process is enqueued with, and runs the step with. */
2
+ export interface ProcessTimeoutDue {
3
+ readonly id: string;
4
+ readonly timeout: string;
5
+ }
6
+ //# sourceMappingURL=process-timeout-due.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-timeout-due.d.ts","sourceRoot":"","sources":["../../../src/application/process/process-timeout-due.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=process-timeout-due.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-timeout-due.js","sourceRoot":"","sources":["../../../src/application/process/process-timeout-due.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ /** A deadline of a process: at `at`, its timeout job runs the step of that name, unless disarmed or the process ended. */
2
+ export interface ProcessTimeout {
3
+ readonly name: string;
4
+ readonly at: Date;
5
+ }
6
+ //# sourceMappingURL=process-timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-timeout.d.ts","sourceRoot":"","sources":["../../../src/application/process/process-timeout.ts"],"names":[],"mappings":"AAAA,0HAA0H;AAC1H,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;CACnB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=process-timeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-timeout.js","sourceRoot":"","sources":["../../../src/application/process/process-timeout.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The class of a process manager, as the runner takes it: a static `processName`,
3
+ * `<context>.<process-name>`; the static `timeoutJob`, the name of the background job of the
4
+ * context that delivers its timeouts, when it arms any; and a static `isState`, which recognises
5
+ * a state this process saved, so that a state written by another version is refused, not misread.
6
+ */
7
+ export interface ProcessType<State> {
8
+ readonly processName: string;
9
+ readonly timeoutJob?: string | undefined;
10
+ isState(value: unknown): value is State;
11
+ }
12
+ //# sourceMappingURL=process-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-type.d.ts","sourceRoot":"","sources":["../../../src/application/process/process-type.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,WAAW,CAAC,KAAK;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC;CACzC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=process-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-type.js","sourceRoot":"","sources":["../../../src/application/process/process-type.ts"],"names":[],"mappings":""}