@entifix/transactions 0.14.0 → 0.16.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 (101) hide show
  1. package/README.md +6 -6
  2. package/dist/contracts/flow-messages.d.ts +3 -3
  3. package/dist/contracts/flow-messages.d.ts.map +1 -1
  4. package/dist/contracts/flow-messages.js +7 -3
  5. package/dist/contracts/flow-messages.js.map +1 -1
  6. package/dist/engine/index.d.ts +2 -9
  7. package/dist/engine/index.d.ts.map +1 -1
  8. package/dist/engine/index.js +3 -10
  9. package/dist/engine/index.js.map +1 -1
  10. package/dist/index.d.ts +0 -14
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +0 -14
  13. package/dist/index.js.map +1 -1
  14. package/dist/ports/flow-engine.d.ts +17 -8
  15. package/dist/ports/flow-engine.d.ts.map +1 -1
  16. package/dist/ports/flow-engine.js +2 -2
  17. package/dist/ports/flow-engine.js.map +1 -1
  18. package/dist/ports/participant-client.d.ts +7 -2
  19. package/dist/ports/participant-client.d.ts.map +1 -1
  20. package/dist/ports/participant-client.js.map +1 -1
  21. package/package.json +4 -4
  22. package/dist/contracts/command.d.ts +0 -59
  23. package/dist/contracts/command.d.ts.map +0 -1
  24. package/dist/contracts/command.js +0 -46
  25. package/dist/contracts/command.js.map +0 -1
  26. package/dist/contracts/event.d.ts +0 -85
  27. package/dist/contracts/event.d.ts.map +0 -1
  28. package/dist/contracts/event.js +0 -81
  29. package/dist/contracts/event.js.map +0 -1
  30. package/dist/contracts/messages.d.ts +0 -37
  31. package/dist/contracts/messages.d.ts.map +0 -1
  32. package/dist/contracts/messages.js +0 -68
  33. package/dist/contracts/messages.js.map +0 -1
  34. package/dist/contracts/record.d.ts +0 -106
  35. package/dist/contracts/record.d.ts.map +0 -1
  36. package/dist/contracts/record.js +0 -27
  37. package/dist/contracts/record.js.map +0 -1
  38. package/dist/contracts/saga-definition.d.ts +0 -181
  39. package/dist/contracts/saga-definition.d.ts.map +0 -1
  40. package/dist/contracts/saga-definition.js +0 -101
  41. package/dist/contracts/saga-definition.js.map +0 -1
  42. package/dist/engine/local-saga-dispatcher.d.ts +0 -35
  43. package/dist/engine/local-saga-dispatcher.d.ts.map +0 -1
  44. package/dist/engine/local-saga-dispatcher.js +0 -28
  45. package/dist/engine/local-saga-dispatcher.js.map +0 -1
  46. package/dist/engine/resolve-template.d.ts +0 -48
  47. package/dist/engine/resolve-template.d.ts.map +0 -1
  48. package/dist/engine/resolve-template.js +0 -95
  49. package/dist/engine/resolve-template.js.map +0 -1
  50. package/dist/engine/resume-sweep.d.ts +0 -46
  51. package/dist/engine/resume-sweep.d.ts.map +0 -1
  52. package/dist/engine/resume-sweep.js +0 -74
  53. package/dist/engine/resume-sweep.js.map +0 -1
  54. package/dist/engine/run-saga.d.ts +0 -54
  55. package/dist/engine/run-saga.d.ts.map +0 -1
  56. package/dist/engine/run-saga.js +0 -463
  57. package/dist/engine/run-saga.js.map +0 -1
  58. package/dist/engine/run-transaction.d.ts +0 -55
  59. package/dist/engine/run-transaction.d.ts.map +0 -1
  60. package/dist/engine/run-transaction.js +0 -101
  61. package/dist/engine/run-transaction.js.map +0 -1
  62. package/dist/mixins/transaction-mixins.d.ts +0 -20
  63. package/dist/mixins/transaction-mixins.d.ts.map +0 -1
  64. package/dist/mixins/transaction-mixins.js +0 -13
  65. package/dist/mixins/transaction-mixins.js.map +0 -1
  66. package/dist/ports/lock-service.d.ts +0 -24
  67. package/dist/ports/lock-service.d.ts.map +0 -1
  68. package/dist/ports/lock-service.js +0 -5
  69. package/dist/ports/lock-service.js.map +0 -1
  70. package/dist/ports/saga-dispatcher.d.ts +0 -46
  71. package/dist/ports/saga-dispatcher.d.ts.map +0 -1
  72. package/dist/ports/saga-dispatcher.js +0 -5
  73. package/dist/ports/saga-dispatcher.js.map +0 -1
  74. package/dist/ports/saga-store.d.ts +0 -96
  75. package/dist/ports/saga-store.d.ts.map +0 -1
  76. package/dist/ports/saga-store.js +0 -19
  77. package/dist/ports/saga-store.js.map +0 -1
  78. package/dist/ports/sequence-service.d.ts +0 -17
  79. package/dist/ports/sequence-service.d.ts.map +0 -1
  80. package/dist/ports/sequence-service.js +0 -5
  81. package/dist/ports/sequence-service.js.map +0 -1
  82. package/dist/ports/transaction-handler.d.ts +0 -66
  83. package/dist/ports/transaction-handler.d.ts.map +0 -1
  84. package/dist/ports/transaction-handler.js +0 -5
  85. package/dist/ports/transaction-handler.js.map +0 -1
  86. package/dist/ports/transaction-sink.d.ts +0 -120
  87. package/dist/ports/transaction-sink.d.ts.map +0 -1
  88. package/dist/ports/transaction-sink.js +0 -28
  89. package/dist/ports/transaction-sink.js.map +0 -1
  90. package/dist/ports/transaction-stream-hub.d.ts +0 -28
  91. package/dist/ports/transaction-stream-hub.d.ts.map +0 -1
  92. package/dist/ports/transaction-stream-hub.js +0 -5
  93. package/dist/ports/transaction-stream-hub.js.map +0 -1
  94. package/dist/stream/transaction-stream-hub.d.ts +0 -18
  95. package/dist/stream/transaction-stream-hub.d.ts.map +0 -1
  96. package/dist/stream/transaction-stream-hub.js +0 -50
  97. package/dist/stream/transaction-stream-hub.js.map +0 -1
  98. package/dist/use-case/facade.uc.d.ts +0 -22
  99. package/dist/use-case/facade.uc.d.ts.map +0 -1
  100. package/dist/use-case/facade.uc.js +0 -55
  101. package/dist/use-case/facade.uc.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"saga-definition.d.ts","sourceRoot":"","sources":["../../src/contracts/saga-definition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,OAAO,GAAG,WAAW,CAAC;AAEnE,oDAAoD;AACpD,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,0BAA0B;AAC1B,MAAM,WAAW,QAAQ;IACvB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,yEAAyE;IACzE,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;CACrC;AAED,+EAA+E;AAC/E,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAC,CAAC,CAAC;AAE5E,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,CAAC;IAC3C;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAMD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,cAAc,GAAG,cAAc,CAoGrE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,QAAQ,MAAM,KACb,MAGyC,CAAC"}
@@ -1,101 +0,0 @@
1
- /**
2
- * Richardson's classification, and adopting the vocabulary is most of the answer
3
- * to "which steps are compensable at all".
4
- *
5
- * - `compensatable` — before the point of no return; a failure downstream
6
- * reverses it.
7
- * - `pivot` — the point of no return. Once it commits, the saga goes forward.
8
- * - `retriable` — after the pivot; no compensation exists, so the only path is
9
- * to retry until it succeeds.
10
- */ const fail = (definition, detail)=>{
11
- throw new Error(`saga definition '${definition}' is invalid: ${detail}`);
12
- };
13
- /**
14
- * Validate a definition and return it, or throw.
15
- *
16
- * ⚠️ **At load, not at the step.** A fault that only appears on the unlucky path
17
- * is a fault that ships — the same reasoning that makes an unrenderable action
18
- * cell throw at render. Every definition is therefore constructed through this
19
- * function at module scope, and loaded in a spec: a definition that never loads
20
- * is a definition that never fails.
21
- */ export function defineSaga(definition) {
22
- const { name, steps } = definition;
23
- if (steps.length === 0) {
24
- fail(name, 'it declares no steps');
25
- }
26
- const seen = new Set();
27
- for (const step of steps){
28
- if (seen.has(step.id)) {
29
- // The command id is `<sagaId>:<stepId>`, so a duplicate id is two steps
30
- // sharing one idempotency key — the second would be dropped as a
31
- // redelivery of the first and never run at all.
32
- fail(name, `two steps share the id '${step.id}'`);
33
- }
34
- seen.add(step.id);
35
- }
36
- // `fanOutFrom` must name a step that has already run, or the outcomes it fans
37
- // out over do not exist yet. A forward reference would silently produce zero
38
- // calls — a step that looks like it ran and did nothing, which is exactly how
39
- // a conversion gets skipped while a saga reports COMPLETED.
40
- const before = new Set();
41
- for (const step of steps){
42
- if (step.fanOutFrom !== undefined && !before.has(step.fanOutFrom)) {
43
- fail(name, `step '${step.id}' fans out from '${step.fanOutFrom}', which is not a ` + 'step before it');
44
- }
45
- before.add(step.id);
46
- }
47
- const pivots = steps.filter((step)=>step.kind === 'pivot');
48
- if (pivots.length > 1) {
49
- // A flow with two points of no return is a flow that has not been designed
50
- // yet, and the engine says so out loud.
51
- fail(name, `it declares ${String(pivots.length)} pivots (${pivots.map((step)=>step.id).join(', ')}); a flow has at most one point of no return`);
52
- }
53
- // ⚠️ **Zero pivots is legal**, and checkout is the case that forced saying so.
54
- // Payment capture is M4; until it lands every step of checkout reverses. A
55
- // validator demanding exactly one would push the order write into a role it
56
- // would have to be removed from later — a wrong answer that passes
57
- //. A definition with no pivot means the whole saga can be unwound,
58
- // which is a stronger property than a pivot rather than a missing one.
59
- const pivot = pivots[0];
60
- const pivotAt = pivot ? steps.indexOf(pivot) : -1;
61
- const afterPivot = (index)=>pivot !== undefined && index > pivotAt;
62
- for (const [index, step] of steps.entries()){
63
- switch(step.kind){
64
- case 'compensatable':
65
- {
66
- if (afterPivot(index)) {
67
- fail(name, `step '${step.id}' is compensatable but sits after the pivot ` + `'${String(pivot == null ? void 0 : pivot.id)}', where nothing can be reversed`);
68
- }
69
- if (!step.compensation) {
70
- fail(name, `step '${step.id}' is compensatable but declares no compensation`);
71
- }
72
- break;
73
- }
74
- case 'pivot':
75
- case 'retriable':
76
- {
77
- if (step.compensation) {
78
- // Not dead code — a *false assurance*. Such a compensation could
79
- // never run, so writing one says the step is reversible when it is
80
- // not.
81
- fail(name, `step '${step.id}' is ${step.kind} and declares a compensation, ` + 'which could never run');
82
- }
83
- if (step.kind === 'retriable' && !afterPivot(index)) {
84
- fail(name, `step '${step.id}' is retriable but sits before the pivot; a step ` + 'that cannot be reversed must not run while the saga can still ' + 'be unwound');
85
- }
86
- break;
87
- }
88
- }
89
- }
90
- return definition;
91
- }
92
- /**
93
- * The command id one call is dispatched under.
94
- *
95
- * `<sagaId>:<stepId>` — the shape `transactionEventId` already uses for events,
96
- * so the `TransactionInbox` serves saga steps with no second dedup store and
97
- * no second key. A fan-out step appends the element index, because its calls are
98
- * separate side effects that must each be claimed on their own.
99
- */ export const sagaCommandId = (sagaId, stepId, index)=>index === undefined ? `${sagaId}:${stepId}` : `${sagaId}:${stepId}:${String(index)}`;
100
-
101
- //# sourceMappingURL=saga-definition.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/contracts/saga-definition.ts"],"sourcesContent":["/**\n * Richardson's classification, and adopting the vocabulary is most of the answer\n * to \"which steps are compensable at all\".\n *\n * - `compensatable` — before the point of no return; a failure downstream\n * reverses it.\n * - `pivot` — the point of no return. Once it commits, the saga goes forward.\n * - `retriable` — after the pivot; no compensation exists, so the only path is\n * to retry until it succeeds.\n */\nexport type SagaStepKind = 'compensatable' | 'pivot' | 'retriable';\n\n/** The HTTP verbs a step may be dispatched with. */\nexport type SagaMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/**\n * One call a step makes, as a template rather than a closure.\n *\n * `path` may carry `{…}` placeholders resolved by field path against the step's\n * recorded outcome — `/api/reservation/{outcome.data.id}`.\n *\n * ⚠️ **A template rather than a callback, and that is the constraint that\n * shaped the whole type.** A callback would have to name the participant's\n * types, and one domain package may not import another — which is exactly the\n * import that has no legal home and the reason a definition is **data** in the\n * first place.\n */\nexport interface SagaCall {\n readonly method: SagaMethod;\n readonly path: string;\n}\n\n/** One step of a flow. */\nexport interface SagaStep {\n /** Unique within the definition; half of the command id `<sagaId>:<stepId>`. */\n readonly id: string;\n /**\n * Which service answers it, as a **configuration key** — never a URI.\n *\n * A URI in a definition is a deployment fact written into a business\n * artifact, and it is what makes a definition untestable and un-relocatable.\n * The same lookup yields the crossing token for that participant, so a\n * definition carries no secret and never could.\n */\n readonly participant: string;\n readonly command: SagaCall;\n /** Required on a `compensatable` step, forbidden on every other kind. */\n readonly compensation?: SagaCall;\n readonly kind: SagaStepKind;\n /**\n * Dispatch one call per element of this step's input, rather than one call.\n *\n * ⚠️ **Cardinality is data, because it has to be.** Checkout reserves once per\n * vendor and how many vendors is known only from the cart, so writing that as\n * N steps would mean generating a definition per request — at which point it\n * is no longer data, and the whole construction collapses back into the class\n * that has no legal home.\n *\n * The consequence carried by {@link SagaStepOutcome}: **the unit of\n * compensation is the call, not the step.** Five lines with three holds taken\n * and the fourth refused must release exactly three.\n */\n readonly fanOut?: boolean;\n /**\n * Fan out over an **earlier step's successful calls** instead of over an\n * input the caller supplied.\n *\n * ⚠️ **Without this a later step cannot address what an earlier one created**,\n * and checkout is the case that proves it. `convert-reservation` needs one\n * call per hold, addressed by the reservation id — which stock-service mints,\n * so the caller cannot know it when it starts the flow. Supplying the ids as\n * input is impossible, and generating a definition per request is the thing\n * a definition-as-data exists to avoid.\n *\n * Each element inherits that call's `organizationId`, so a tenant-plane\n * participant reaches the same tenant it did the first time, and the `path`\n * template resolves against `{outcome.…}` — the same scope a compensation\n * gets, for the same reason: the id being addressed is in the response body.\n *\n * Implies {@link fanOut}. It names a step that must appear **before** this one,\n * and `defineSaga` refuses a forward or self reference at module load.\n */\n readonly fanOutFrom?: string;\n}\n\n/** A flow, as the data a generic engine walks. */\nexport interface SagaDefinition {\n readonly name: string;\n /**\n * What a caller must hold to run this flow, as a `<domain>:<entity>:<action>`\n * string.\n *\n * ⚠️ **On the definition rather than on the route**, so the route that runs a\n * flow stays generic. The alternative was one permission for every saga, which\n * would make \"may run a flow\" a single capability regardless of what the flow\n * does — and checkout writes an order.\n *\n * It is a plain string here rather than authz's `Permission`: this package is\n * T2, and `@entifix/authz` sits above it at T4. The service that\n * mounts the route resolves the string against\n * `SERVICE_CROSSING_PERMISSIONS`, which is where the closed list belongs.\n */\n readonly permission: string;\n readonly steps: readonly SagaStep[];\n}\n\n/** What one dispatched call returned, kept so its compensation can read it. */\nexport interface SagaCallOutcome {\n /** The fan-out element this call was made for; `0` on a single-call step. */\n readonly index: number;\n readonly status: number;\n readonly body: unknown;\n /**\n * The organization this call acted for, carried so its compensation acts on\n * the same one.\n *\n * ⚠️ **Not derivable from the outcome, and its absence is silent.** A\n * tenant-plane participant resolves its storage handle from\n * `x-organization-id`, so a compensation dispatched without it is refused\n * `400` — and the saga strands with every hold still in place while the\n * engine reports it tried. Measured on the live lab: two holds taken, a third\n * line refused, and both releases rejected for a missing header.\n */\n readonly organizationId?: string;\n}\n\n/**\n * What one step is given to work with — one element per call on a `fanOut` step,\n * exactly one otherwise.\n */\nexport interface SagaStepInput {\n /** The body to send. */\n readonly body?: unknown;\n /** The explicit organization, for a tenant-plane participant. */\n readonly organizationId?: string;\n}\n\n/**\n * The inputs each step needs, keyed by step id, supplied by the caller.\n *\n * ⚠️ **Here rather than in the engine**, because the durable instance carries\n * it: a resumed walk is a different process reading this off the store, so the\n * port that persists it may not reach up into the engine to name its type.\n */\nexport type SagaInputs = Readonly<Record<string, readonly SagaStepInput[]>>;\n\n/** Every call one step made, in dispatch order. */\nexport interface SagaStepOutcome {\n readonly stepId: string;\n readonly calls: readonly SagaCallOutcome[];\n /**\n * Why this step stopped, when it did — absent on a step that succeeded.\n *\n * ⚠️ **Without it a resumed walk cannot tell a finished step from a refused\n * one.** `calls` holds what succeeded either way, so the two are\n * indistinguishable on the stored document, and the distinction is what\n * decides whether the pivot committed. Guessing it either compensates behind\n * a capture or walks past a refusal.\n */\n readonly error?: string;\n /**\n * Whether this step's calls have already been given back.\n *\n * ⚠️ **What keeps a resumed unwind from compensating twice.** A second\n * `DELETE` of an order already deleted answers `404`, which the dispatcher\n * classifies as a refusal, which strands a flow that was in fact reversed.\n */\n readonly compensated?: boolean;\n}\n\nconst fail = (definition: string, detail: string): never => {\n throw new Error(`saga definition '${definition}' is invalid: ${detail}`);\n};\n\n/**\n * Validate a definition and return it, or throw.\n *\n * ⚠️ **At load, not at the step.** A fault that only appears on the unlucky path\n * is a fault that ships — the same reasoning that makes an unrenderable action\n * cell throw at render. Every definition is therefore constructed through this\n * function at module scope, and loaded in a spec: a definition that never loads\n * is a definition that never fails.\n */\nexport function defineSaga(definition: SagaDefinition): SagaDefinition {\n const { name, steps } = definition;\n\n if (steps.length === 0) {\n fail(name, 'it declares no steps');\n }\n\n const seen = new Set<string>();\n for (const step of steps) {\n if (seen.has(step.id)) {\n // The command id is `<sagaId>:<stepId>`, so a duplicate id is two steps\n // sharing one idempotency key — the second would be dropped as a\n // redelivery of the first and never run at all.\n fail(name, `two steps share the id '${step.id}'`);\n }\n seen.add(step.id);\n }\n\n // `fanOutFrom` must name a step that has already run, or the outcomes it fans\n // out over do not exist yet. A forward reference would silently produce zero\n // calls — a step that looks like it ran and did nothing, which is exactly how\n // a conversion gets skipped while a saga reports COMPLETED.\n const before = new Set<string>();\n for (const step of steps) {\n if (step.fanOutFrom !== undefined && !before.has(step.fanOutFrom)) {\n fail(\n name,\n `step '${step.id}' fans out from '${step.fanOutFrom}', which is not a ` +\n 'step before it',\n );\n }\n before.add(step.id);\n }\n\n const pivots = steps.filter(step => step.kind === 'pivot');\n if (pivots.length > 1) {\n // A flow with two points of no return is a flow that has not been designed\n // yet, and the engine says so out loud.\n fail(\n name,\n `it declares ${String(pivots.length)} pivots (${pivots\n .map(step => step.id)\n .join(', ')}); a flow has at most one point of no return`,\n );\n }\n\n // ⚠️ **Zero pivots is legal**, and checkout is the case that forced saying so.\n // Payment capture is M4; until it lands every step of checkout reverses. A\n // validator demanding exactly one would push the order write into a role it\n // would have to be removed from later — a wrong answer that passes\n //. A definition with no pivot means the whole saga can be unwound,\n // which is a stronger property than a pivot rather than a missing one.\n const pivot = pivots[0];\n const pivotAt = pivot ? steps.indexOf(pivot) : -1;\n const afterPivot = (index: number) => pivot !== undefined && index > pivotAt;\n\n for (const [index, step] of steps.entries()) {\n switch (step.kind) {\n case 'compensatable': {\n if (afterPivot(index)) {\n fail(\n name,\n `step '${step.id}' is compensatable but sits after the pivot ` +\n `'${String(pivot?.id)}', where nothing can be reversed`,\n );\n }\n if (!step.compensation) {\n fail(\n name,\n `step '${step.id}' is compensatable but declares no compensation`,\n );\n }\n break;\n }\n case 'pivot':\n case 'retriable': {\n if (step.compensation) {\n // Not dead code — a *false assurance*. Such a compensation could\n // never run, so writing one says the step is reversible when it is\n // not.\n fail(\n name,\n `step '${step.id}' is ${step.kind} and declares a compensation, ` +\n 'which could never run',\n );\n }\n if (step.kind === 'retriable' && !afterPivot(index)) {\n fail(\n name,\n `step '${step.id}' is retriable but sits before the pivot; a step ` +\n 'that cannot be reversed must not run while the saga can still ' +\n 'be unwound',\n );\n }\n break;\n }\n }\n }\n\n return definition;\n}\n\n/**\n * The command id one call is dispatched under.\n *\n * `<sagaId>:<stepId>` — the shape `transactionEventId` already uses for events,\n * so the `TransactionInbox` serves saga steps with no second dedup store and\n * no second key. A fan-out step appends the element index, because its calls are\n * separate side effects that must each be claimed on their own.\n */\nexport const sagaCommandId = (\n sagaId: string,\n stepId: string,\n index?: number,\n): string =>\n index === undefined\n ? `${sagaId}:${stepId}`\n : `${sagaId}:${stepId}:${String(index)}`;\n"],"names":["fail","definition","detail","Error","defineSaga","name","steps","length","seen","Set","step","has","id","add","before","fanOutFrom","undefined","pivots","filter","kind","String","map","join","pivot","pivotAt","indexOf","afterPivot","index","entries","compensation","sagaCommandId","sagaId","stepId"],"mappings":"AAAA;;;;;;;;;CASC,GAiKD,MAAMA,OAAO,CAACC,YAAoBC;IAChC,MAAM,IAAIC,MAAM,CAAC,iBAAiB,EAAEF,WAAW,cAAc,EAAEC,QAAQ;AACzE;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASE,WAAWH,UAA0B;IACnD,MAAM,EAAEI,IAAI,EAAEC,KAAK,EAAE,GAAGL;IAExB,IAAIK,MAAMC,MAAM,KAAK,GAAG;QACtBP,KAAKK,MAAM;IACb;IAEA,MAAMG,OAAO,IAAIC;IACjB,KAAK,MAAMC,QAAQJ,MAAO;QACxB,IAAIE,KAAKG,GAAG,CAACD,KAAKE,EAAE,GAAG;YACrB,wEAAwE;YACxE,iEAAiE;YACjE,gDAAgD;YAChDZ,KAAKK,MAAM,CAAC,wBAAwB,EAAEK,KAAKE,EAAE,CAAC,CAAC,CAAC;QAClD;QACAJ,KAAKK,GAAG,CAACH,KAAKE,EAAE;IAClB;IAEA,8EAA8E;IAC9E,6EAA6E;IAC7E,8EAA8E;IAC9E,4DAA4D;IAC5D,MAAME,SAAS,IAAIL;IACnB,KAAK,MAAMC,QAAQJ,MAAO;QACxB,IAAII,KAAKK,UAAU,KAAKC,aAAa,CAACF,OAAOH,GAAG,CAACD,KAAKK,UAAU,GAAG;YACjEf,KACEK,MACA,CAAC,MAAM,EAAEK,KAAKE,EAAE,CAAC,iBAAiB,EAAEF,KAAKK,UAAU,CAAC,kBAAkB,CAAC,GACrE;QAEN;QACAD,OAAOD,GAAG,CAACH,KAAKE,EAAE;IACpB;IAEA,MAAMK,SAASX,MAAMY,MAAM,CAACR,CAAAA,OAAQA,KAAKS,IAAI,KAAK;IAClD,IAAIF,OAAOV,MAAM,GAAG,GAAG;QACrB,2EAA2E;QAC3E,wCAAwC;QACxCP,KACEK,MACA,CAAC,YAAY,EAAEe,OAAOH,OAAOV,MAAM,EAAE,SAAS,EAAEU,OAC7CI,GAAG,CAACX,CAAAA,OAAQA,KAAKE,EAAE,EACnBU,IAAI,CAAC,MAAM,4CAA4C,CAAC;IAE/D;IAEA,+EAA+E;IAC/E,2EAA2E;IAC3E,4EAA4E;IAC5E,mEAAmE;IACnE,mEAAmE;IACnE,uEAAuE;IACvE,MAAMC,QAAQN,MAAM,CAAC,EAAE;IACvB,MAAMO,UAAUD,QAAQjB,MAAMmB,OAAO,CAACF,SAAS,CAAC;IAChD,MAAMG,aAAa,CAACC,QAAkBJ,UAAUP,aAAaW,QAAQH;IAErE,KAAK,MAAM,CAACG,OAAOjB,KAAK,IAAIJ,MAAMsB,OAAO,GAAI;QAC3C,OAAQlB,KAAKS,IAAI;YACf,KAAK;gBAAiB;oBACpB,IAAIO,WAAWC,QAAQ;wBACrB3B,KACEK,MACA,CAAC,MAAM,EAAEK,KAAKE,EAAE,CAAC,4CAA4C,CAAC,GAC5D,CAAC,CAAC,EAAEQ,OAAOG,yBAAAA,MAAOX,EAAE,EAAE,gCAAgC,CAAC;oBAE7D;oBACA,IAAI,CAACF,KAAKmB,YAAY,EAAE;wBACtB7B,KACEK,MACA,CAAC,MAAM,EAAEK,KAAKE,EAAE,CAAC,+CAA+C,CAAC;oBAErE;oBACA;gBACF;YACA,KAAK;YACL,KAAK;gBAAa;oBAChB,IAAIF,KAAKmB,YAAY,EAAE;wBACrB,iEAAiE;wBACjE,mEAAmE;wBACnE,OAAO;wBACP7B,KACEK,MACA,CAAC,MAAM,EAAEK,KAAKE,EAAE,CAAC,KAAK,EAAEF,KAAKS,IAAI,CAAC,8BAA8B,CAAC,GAC/D;oBAEN;oBACA,IAAIT,KAAKS,IAAI,KAAK,eAAe,CAACO,WAAWC,QAAQ;wBACnD3B,KACEK,MACA,CAAC,MAAM,EAAEK,KAAKE,EAAE,CAAC,iDAAiD,CAAC,GACjE,mEACA;oBAEN;oBACA;gBACF;QACF;IACF;IAEA,OAAOX;AACT;AAEA;;;;;;;CAOC,GACD,OAAO,MAAM6B,gBAAgB,CAC3BC,QACAC,QACAL,QAEAA,UAAUX,YACN,GAAGe,OAAO,CAAC,EAAEC,QAAQ,GACrB,GAAGD,OAAO,CAAC,EAAEC,OAAO,CAAC,EAAEZ,OAAOO,QAAQ,CAAC"}
@@ -1,35 +0,0 @@
1
- import type { Unavailable } from '@entifix/core';
2
- import { Effect, Layer } from 'effect';
3
- import type { SagaCall } from '../contracts/saga-definition.js';
4
- import { type SagaDispatch, type SagaDispatcher, SagaDispatcherTag, type SagaResponse } from '../ports/saga-dispatcher.js';
5
- /** What a local participant is handed: the dispatch, minus whom it is for. */
6
- export type LocalSagaRequest = Omit<SagaDispatch, 'participant'>;
7
- /**
8
- * One participant answered in-process.
9
- *
10
- * The same contract an HTTP participant keeps: a business refusal is a response
11
- * with `ok: false` — the engine compensates on it — and only a failure to reach
12
- * the participant at all is an {@link Unavailable}. Key the side effect on
13
- * `commandId` (an inbox), because a resumed flow dispatches the same command
14
- * again.
15
- */
16
- export type LocalSagaParticipant = (request: LocalSagaRequest) => Effect.Effect<SagaResponse, Unavailable>;
17
- /**
18
- * A {@link SagaDispatcher} that calls participants in this process.
19
- *
20
- * The saga engine never does HTTP itself: a step is a `{ method, path }` handed
21
- * to the dispatcher port. So a flow whose every step belongs to one service needs
22
- * no transport, no crossing token and no second process — only this, with each
23
- * participant name mapped to the Effect that performs its commands. A handler
24
- * that serves several commands routes on `request.call`.
25
- *
26
- * ⚠️ A participant the definition names and this map lacks is a **defect**, not
27
- * a failed step: it is a wiring mistake the flow cannot recover from, and
28
- * reporting it as a refusal would compensate a flow for a bug.
29
- */
30
- export declare const makeLocalSagaDispatcher: (participants: Readonly<Record<string, LocalSagaParticipant>>) => SagaDispatcher;
31
- /** Provides {@link SagaDispatcherTag} from local participants. */
32
- export declare const LocalSagaDispatcherLayer: (participants: Readonly<Record<string, LocalSagaParticipant>>) => Layer.Layer<SagaDispatcherTag>;
33
- /** True when a request is the given command, for a participant routing on it. */
34
- export declare const isSagaCall: (request: LocalSagaRequest, call: SagaCall) => boolean;
35
- //# sourceMappingURL=local-saga-dispatcher.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"local-saga-dispatcher.d.ts","sourceRoot":"","sources":["../../src/engine/local-saga-dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,iBAAiB,EACjB,KAAK,YAAY,EAClB,MAAM,6BAA6B,CAAC;AAErC,8EAA8E;AAC9E,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,GAAG,CACjC,OAAO,EAAE,gBAAgB,KACtB,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;AAE9C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GAClC,cAAc,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,KAC3D,cAWD,CAAC;AAEH,kEAAkE;AAClE,eAAO,MAAM,wBAAwB,GACnC,cAAc,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,KAC3D,KAAK,CAAC,KAAK,CAAC,iBAAiB,CACyC,CAAC;AAE1E,iFAAiF;AACjF,eAAO,MAAM,UAAU,GACrB,SAAS,gBAAgB,EACzB,MAAM,QAAQ,KACb,OACqE,CAAC"}
@@ -1,28 +0,0 @@
1
- import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
2
- import { Effect, Layer } from 'effect';
3
- import { SagaDispatcherTag } from '../ports/saga-dispatcher.js';
4
- /**
5
- * A {@link SagaDispatcher} that calls participants in this process.
6
- *
7
- * The saga engine never does HTTP itself: a step is a `{ method, path }` handed
8
- * to the dispatcher port. So a flow whose every step belongs to one service needs
9
- * no transport, no crossing token and no second process — only this, with each
10
- * participant name mapped to the Effect that performs its commands. A handler
11
- * that serves several commands routes on `request.call`.
12
- *
13
- * ⚠️ A participant the definition names and this map lacks is a **defect**, not
14
- * a failed step: it is a wiring mistake the flow cannot recover from, and
15
- * reporting it as a refusal would compensate a flow for a bug.
16
- */ export const makeLocalSagaDispatcher = (participants)=>({
17
- dispatch: (_0)=>{
18
- let { participant } = _0, request = _object_without_properties_loose(_0, [
19
- "participant"
20
- ]);
21
- const handle = participants[participant];
22
- return handle === undefined ? Effect.die(new Error(`The saga dispatched to participant "${participant}", which this service registered no local handler for.`)) : handle(request);
23
- }
24
- });
25
- /** Provides {@link SagaDispatcherTag} from local participants. */ export const LocalSagaDispatcherLayer = (participants)=>Layer.succeed(SagaDispatcherTag, makeLocalSagaDispatcher(participants));
26
- /** True when a request is the given command, for a participant routing on it. */ export const isSagaCall = (request, call)=>request.call.method === call.method && request.call.path === call.path;
27
-
28
- //# sourceMappingURL=local-saga-dispatcher.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/engine/local-saga-dispatcher.ts"],"sourcesContent":["import type { Unavailable } from '@entifix/core';\nimport { Effect, Layer } from 'effect';\n\nimport type { SagaCall } from '../contracts/saga-definition.js';\nimport {\n type SagaDispatch,\n type SagaDispatcher,\n SagaDispatcherTag,\n type SagaResponse,\n} from '../ports/saga-dispatcher.js';\n\n/** What a local participant is handed: the dispatch, minus whom it is for. */\nexport type LocalSagaRequest = Omit<SagaDispatch, 'participant'>;\n\n/**\n * One participant answered in-process.\n *\n * The same contract an HTTP participant keeps: a business refusal is a response\n * with `ok: false` — the engine compensates on it — and only a failure to reach\n * the participant at all is an {@link Unavailable}. Key the side effect on\n * `commandId` (an inbox), because a resumed flow dispatches the same command\n * again.\n */\nexport type LocalSagaParticipant = (\n request: LocalSagaRequest,\n) => Effect.Effect<SagaResponse, Unavailable>;\n\n/**\n * A {@link SagaDispatcher} that calls participants in this process.\n *\n * The saga engine never does HTTP itself: a step is a `{ method, path }` handed\n * to the dispatcher port. So a flow whose every step belongs to one service needs\n * no transport, no crossing token and no second process — only this, with each\n * participant name mapped to the Effect that performs its commands. A handler\n * that serves several commands routes on `request.call`.\n *\n * ⚠️ A participant the definition names and this map lacks is a **defect**, not\n * a failed step: it is a wiring mistake the flow cannot recover from, and\n * reporting it as a refusal would compensate a flow for a bug.\n */\nexport const makeLocalSagaDispatcher = (\n participants: Readonly<Record<string, LocalSagaParticipant>>,\n): SagaDispatcher => ({\n dispatch: ({ participant, ...request }) => {\n const handle = participants[participant];\n return handle === undefined\n ? Effect.die(\n new Error(\n `The saga dispatched to participant \"${participant}\", which this service registered no local handler for.`,\n ),\n )\n : handle(request);\n },\n});\n\n/** Provides {@link SagaDispatcherTag} from local participants. */\nexport const LocalSagaDispatcherLayer = (\n participants: Readonly<Record<string, LocalSagaParticipant>>,\n): Layer.Layer<SagaDispatcherTag> =>\n Layer.succeed(SagaDispatcherTag, makeLocalSagaDispatcher(participants));\n\n/** True when a request is the given command, for a participant routing on it. */\nexport const isSagaCall = (\n request: LocalSagaRequest,\n call: SagaCall,\n): boolean =>\n request.call.method === call.method && request.call.path === call.path;\n"],"names":["Effect","Layer","SagaDispatcherTag","makeLocalSagaDispatcher","participants","dispatch","participant","request","handle","undefined","die","Error","LocalSagaDispatcherLayer","succeed","isSagaCall","call","method","path"],"mappings":";AACA,SAASA,MAAM,EAAEC,KAAK,QAAQ,SAAS;AAGvC,SAGEC,iBAAiB,QAEZ,8BAA8B;AAkBrC;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,0BAA0B,CACrCC,eACoB,CAAA;QACpBC,UAAU;gBAAC,EAAEC,WAAW,EAAc,OAATC;;;YAC3B,MAAMC,SAASJ,YAAY,CAACE,YAAY;YACxC,OAAOE,WAAWC,YACdT,OAAOU,GAAG,CACR,IAAIC,MACF,CAAC,oCAAoC,EAAEL,YAAY,sDAAsD,CAAC,KAG9GE,OAAOD;QACb;IACF,CAAA,EAAG;AAEH,gEAAgE,GAChE,OAAO,MAAMK,2BAA2B,CACtCR,eAEAH,MAAMY,OAAO,CAACX,mBAAmBC,wBAAwBC,eAAe;AAE1E,+EAA+E,GAC/E,OAAO,MAAMU,aAAa,CACxBP,SACAQ,OAEAR,QAAQQ,IAAI,CAACC,MAAM,KAAKD,KAAKC,MAAM,IAAIT,QAAQQ,IAAI,CAACE,IAAI,KAAKF,KAAKE,IAAI,CAAC"}
@@ -1,48 +0,0 @@
1
- /**
2
- * Resolve a path template against a scope.
3
- *
4
- * `/api/reservation/{outcome.data.id}` with
5
- * `{ outcome: { data: { id: 'r-1' } } }` becomes `/api/reservation/r-1`.
6
- *
7
- * ⚠️ **An unresolved placeholder throws rather than interpolating `undefined`.**
8
- * The failure this prevents is specific and silent: a compensation whose
9
- * template no longer matches its participant's response shape would otherwise
10
- * `DELETE /api/reservation/undefined`, get a `404`, and be recorded as a
11
- * compensation that ran — leaving the hold in place and the saga reporting that
12
- * it was reversed. That is the "failed and stranded" state nobody plans for, arrived at by string interpolation.
13
- *
14
- * Values are URI-encoded: a participant's id is data, and a path segment is not
15
- * the place to discover it contained a slash.
16
- */
17
- export declare function resolveTemplate(template: string, scope: Record<string, unknown>): string;
18
- /**
19
- * Resolve the placeholders inside a **request body**, recursively.
20
- *
21
- * ⚠️ **Why a body needs this at all.** A step's payload can depend on what an
22
- * earlier step created: checkout's capture has to name the order that was just
23
- * written, and the order id is minted by order-service — so a caller cannot put
24
- * it in the body it sends when it starts the flow. Without this, the capture
25
- * carries a placeholder string and the order it names never advances, which is
26
- * precisely the defect measured on the live lab: a saga reporting `COMPLETED`
27
- * with a payment attached to nothing.
28
- *
29
- * ⚠️ **The template lives in the caller's `inputs`, never in the definition.**
30
- * That is a constraint, not an accident: a definition that carried
31
- * domain payloads would be importing the shape of another domain's entity, which
32
- * is the class of thing that has no legal home. The definition stays a list of
33
- * verbs and addresses; what to send is the caller's, and this only lets the
34
- * caller point at a value it could not have known yet.
35
- *
36
- * Two behaviours, and the difference is load-bearing:
37
- *
38
- * - A string that is **exactly** one placeholder resolves to the raw value, so
39
- * a number stays a number and an object stays an object. `"{steps.x.data.qty}"`
40
- * becoming the string `"3"` would reach a validator expecting a number.
41
- * - A string that merely **contains** placeholders is interpolated textually,
42
- * and — unlike {@link resolveTemplate} — **not** URI-encoded. A body is JSON,
43
- * not a path segment; encoding here would put `%20` in a customer's name.
44
- *
45
- * An unresolved placeholder throws, for the same reason it does in a path.
46
- */
47
- export declare function resolveBodyTemplate(value: unknown, scope: Record<string, unknown>): unknown;
48
- //# sourceMappingURL=resolve-template.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-template.d.ts","sourceRoot":"","sources":["../../src/engine/resolve-template.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAUR;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAqCT"}
@@ -1,95 +0,0 @@
1
- /** The `{a.b.c}` placeholders a {@link SagaCall}'s path may carry. */ const PLACEHOLDER = /\{([^{}]+)\}/g;
2
- const readPath = (root, path)=>{
3
- let value = root;
4
- for (const segment of path.split('.')){
5
- if (value === null || typeof value !== 'object') {
6
- return undefined;
7
- }
8
- value = value[segment];
9
- }
10
- return value;
11
- };
12
- /**
13
- * Resolve a path template against a scope.
14
- *
15
- * `/api/reservation/{outcome.data.id}` with
16
- * `{ outcome: { data: { id: 'r-1' } } }` becomes `/api/reservation/r-1`.
17
- *
18
- * ⚠️ **An unresolved placeholder throws rather than interpolating `undefined`.**
19
- * The failure this prevents is specific and silent: a compensation whose
20
- * template no longer matches its participant's response shape would otherwise
21
- * `DELETE /api/reservation/undefined`, get a `404`, and be recorded as a
22
- * compensation that ran — leaving the hold in place and the saga reporting that
23
- * it was reversed. That is the "failed and stranded" state nobody plans for, arrived at by string interpolation.
24
- *
25
- * Values are URI-encoded: a participant's id is data, and a path segment is not
26
- * the place to discover it contained a slash.
27
- */ export function resolveTemplate(template, scope) {
28
- return template.replaceAll(PLACEHOLDER, (_match, path)=>{
29
- const value = readPath(scope, path);
30
- if (value === undefined || value === null) {
31
- throw new Error(`saga path template '${template}' has no value for '{${path}}'`);
32
- }
33
- return encodeURIComponent(String(value));
34
- });
35
- }
36
- /** A string that is nothing but one placeholder, so its type can be preserved. */ const WHOLE_PLACEHOLDER = /^\{([^{}]+)\}$/;
37
- /**
38
- * Resolve the placeholders inside a **request body**, recursively.
39
- *
40
- * ⚠️ **Why a body needs this at all.** A step's payload can depend on what an
41
- * earlier step created: checkout's capture has to name the order that was just
42
- * written, and the order id is minted by order-service — so a caller cannot put
43
- * it in the body it sends when it starts the flow. Without this, the capture
44
- * carries a placeholder string and the order it names never advances, which is
45
- * precisely the defect measured on the live lab: a saga reporting `COMPLETED`
46
- * with a payment attached to nothing.
47
- *
48
- * ⚠️ **The template lives in the caller's `inputs`, never in the definition.**
49
- * That is a constraint, not an accident: a definition that carried
50
- * domain payloads would be importing the shape of another domain's entity, which
51
- * is the class of thing that has no legal home. The definition stays a list of
52
- * verbs and addresses; what to send is the caller's, and this only lets the
53
- * caller point at a value it could not have known yet.
54
- *
55
- * Two behaviours, and the difference is load-bearing:
56
- *
57
- * - A string that is **exactly** one placeholder resolves to the raw value, so
58
- * a number stays a number and an object stays an object. `"{steps.x.data.qty}"`
59
- * becoming the string `"3"` would reach a validator expecting a number.
60
- * - A string that merely **contains** placeholders is interpolated textually,
61
- * and — unlike {@link resolveTemplate} — **not** URI-encoded. A body is JSON,
62
- * not a path segment; encoding here would put `%20` in a customer's name.
63
- *
64
- * An unresolved placeholder throws, for the same reason it does in a path.
65
- */ export function resolveBodyTemplate(value, scope) {
66
- if (typeof value === 'string') {
67
- const whole = WHOLE_PLACEHOLDER.exec(value);
68
- if ((whole == null ? void 0 : whole[1]) !== undefined) {
69
- const resolved = readPath(scope, whole[1]);
70
- if (resolved === undefined || resolved === null) {
71
- throw new Error(`saga body template '${value}' has no value for '{${whole[1]}}'`);
72
- }
73
- return resolved;
74
- }
75
- return value.replaceAll(PLACEHOLDER, (_match, path)=>{
76
- const resolved = readPath(scope, path);
77
- if (resolved === undefined || resolved === null) {
78
- throw new Error(`saga body template '${value}' has no value for '{${path}}'`);
79
- }
80
- return String(resolved);
81
- });
82
- }
83
- if (Array.isArray(value)) {
84
- return value.map((element)=>resolveBodyTemplate(element, scope));
85
- }
86
- if (value !== null && typeof value === 'object') {
87
- return Object.fromEntries(Object.entries(value).map(([key, entry])=>[
88
- key,
89
- resolveBodyTemplate(entry, scope)
90
- ]));
91
- }
92
- return value;
93
- }
94
-
95
- //# sourceMappingURL=resolve-template.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/engine/resolve-template.ts"],"sourcesContent":["/** The `{a.b.c}` placeholders a {@link SagaCall}'s path may carry. */\nconst PLACEHOLDER = /\\{([^{}]+)\\}/g;\n\nconst readPath = (root: unknown, path: string): unknown => {\n let value = root;\n for (const segment of path.split('.')) {\n if (value === null || typeof value !== 'object') {\n return undefined;\n }\n value = (value as Record<string, unknown>)[segment];\n }\n return value;\n};\n\n/**\n * Resolve a path template against a scope.\n *\n * `/api/reservation/{outcome.data.id}` with\n * `{ outcome: { data: { id: 'r-1' } } }` becomes `/api/reservation/r-1`.\n *\n * ⚠️ **An unresolved placeholder throws rather than interpolating `undefined`.**\n * The failure this prevents is specific and silent: a compensation whose\n * template no longer matches its participant's response shape would otherwise\n * `DELETE /api/reservation/undefined`, get a `404`, and be recorded as a\n * compensation that ran — leaving the hold in place and the saga reporting that\n * it was reversed. That is the \"failed and stranded\" state nobody plans for, arrived at by string interpolation.\n *\n * Values are URI-encoded: a participant's id is data, and a path segment is not\n * the place to discover it contained a slash.\n */\nexport function resolveTemplate(\n template: string,\n scope: Record<string, unknown>,\n): string {\n return template.replaceAll(PLACEHOLDER, (_match, path: string) => {\n const value = readPath(scope, path);\n if (value === undefined || value === null) {\n throw new Error(\n `saga path template '${template}' has no value for '{${path}}'`,\n );\n }\n return encodeURIComponent(String(value));\n });\n}\n\n/** A string that is nothing but one placeholder, so its type can be preserved. */\nconst WHOLE_PLACEHOLDER = /^\\{([^{}]+)\\}$/;\n\n/**\n * Resolve the placeholders inside a **request body**, recursively.\n *\n * ⚠️ **Why a body needs this at all.** A step's payload can depend on what an\n * earlier step created: checkout's capture has to name the order that was just\n * written, and the order id is minted by order-service — so a caller cannot put\n * it in the body it sends when it starts the flow. Without this, the capture\n * carries a placeholder string and the order it names never advances, which is\n * precisely the defect measured on the live lab: a saga reporting `COMPLETED`\n * with a payment attached to nothing.\n *\n * ⚠️ **The template lives in the caller's `inputs`, never in the definition.**\n * That is a constraint, not an accident: a definition that carried\n * domain payloads would be importing the shape of another domain's entity, which\n * is the class of thing that has no legal home. The definition stays a list of\n * verbs and addresses; what to send is the caller's, and this only lets the\n * caller point at a value it could not have known yet.\n *\n * Two behaviours, and the difference is load-bearing:\n *\n * - A string that is **exactly** one placeholder resolves to the raw value, so\n * a number stays a number and an object stays an object. `\"{steps.x.data.qty}\"`\n * becoming the string `\"3\"` would reach a validator expecting a number.\n * - A string that merely **contains** placeholders is interpolated textually,\n * and — unlike {@link resolveTemplate} — **not** URI-encoded. A body is JSON,\n * not a path segment; encoding here would put `%20` in a customer's name.\n *\n * An unresolved placeholder throws, for the same reason it does in a path.\n */\nexport function resolveBodyTemplate(\n value: unknown,\n scope: Record<string, unknown>,\n): unknown {\n if (typeof value === 'string') {\n const whole = WHOLE_PLACEHOLDER.exec(value);\n if (whole?.[1] !== undefined) {\n const resolved = readPath(scope, whole[1]);\n if (resolved === undefined || resolved === null) {\n throw new Error(\n `saga body template '${value}' has no value for '{${whole[1]}}'`,\n );\n }\n return resolved;\n }\n return value.replaceAll(PLACEHOLDER, (_match, path: string) => {\n const resolved = readPath(scope, path);\n if (resolved === undefined || resolved === null) {\n throw new Error(\n `saga body template '${value}' has no value for '{${path}}'`,\n );\n }\n return String(resolved);\n });\n }\n\n if (Array.isArray(value)) {\n return value.map(element => resolveBodyTemplate(element, scope));\n }\n\n if (value !== null && typeof value === 'object') {\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).map(([key, entry]) => [\n key,\n resolveBodyTemplate(entry, scope),\n ]),\n );\n }\n\n return value;\n}\n"],"names":["PLACEHOLDER","readPath","root","path","value","segment","split","undefined","resolveTemplate","template","scope","replaceAll","_match","Error","encodeURIComponent","String","WHOLE_PLACEHOLDER","resolveBodyTemplate","whole","exec","resolved","Array","isArray","map","element","Object","fromEntries","entries","key","entry"],"mappings":"AAAA,oEAAoE,GACpE,MAAMA,cAAc;AAEpB,MAAMC,WAAW,CAACC,MAAeC;IAC/B,IAAIC,QAAQF;IACZ,KAAK,MAAMG,WAAWF,KAAKG,KAAK,CAAC,KAAM;QACrC,IAAIF,UAAU,QAAQ,OAAOA,UAAU,UAAU;YAC/C,OAAOG;QACT;QACAH,QAAQ,AAACA,KAAiC,CAACC,QAAQ;IACrD;IACA,OAAOD;AACT;AAEA;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASI,gBACdC,QAAgB,EAChBC,KAA8B;IAE9B,OAAOD,SAASE,UAAU,CAACX,aAAa,CAACY,QAAQT;QAC/C,MAAMC,QAAQH,SAASS,OAAOP;QAC9B,IAAIC,UAAUG,aAAaH,UAAU,MAAM;YACzC,MAAM,IAAIS,MACR,CAAC,oBAAoB,EAAEJ,SAAS,qBAAqB,EAAEN,KAAK,EAAE,CAAC;QAEnE;QACA,OAAOW,mBAAmBC,OAAOX;IACnC;AACF;AAEA,gFAAgF,GAChF,MAAMY,oBAAoB;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC,GACD,OAAO,SAASC,oBACdb,KAAc,EACdM,KAA8B;IAE9B,IAAI,OAAON,UAAU,UAAU;QAC7B,MAAMc,QAAQF,kBAAkBG,IAAI,CAACf;QACrC,IAAIc,CAAAA,yBAAAA,KAAO,CAAC,EAAE,MAAKX,WAAW;YAC5B,MAAMa,WAAWnB,SAASS,OAAOQ,KAAK,CAAC,EAAE;YACzC,IAAIE,aAAab,aAAaa,aAAa,MAAM;gBAC/C,MAAM,IAAIP,MACR,CAAC,oBAAoB,EAAET,MAAM,qBAAqB,EAAEc,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YAEpE;YACA,OAAOE;QACT;QACA,OAAOhB,MAAMO,UAAU,CAACX,aAAa,CAACY,QAAQT;YAC5C,MAAMiB,WAAWnB,SAASS,OAAOP;YACjC,IAAIiB,aAAab,aAAaa,aAAa,MAAM;gBAC/C,MAAM,IAAIP,MACR,CAAC,oBAAoB,EAAET,MAAM,qBAAqB,EAAED,KAAK,EAAE,CAAC;YAEhE;YACA,OAAOY,OAAOK;QAChB;IACF;IAEA,IAAIC,MAAMC,OAAO,CAAClB,QAAQ;QACxB,OAAOA,MAAMmB,GAAG,CAACC,CAAAA,UAAWP,oBAAoBO,SAASd;IAC3D;IAEA,IAAIN,UAAU,QAAQ,OAAOA,UAAU,UAAU;QAC/C,OAAOqB,OAAOC,WAAW,CACvBD,OAAOE,OAAO,CAACvB,OAAkCmB,GAAG,CAAC,CAAC,CAACK,KAAKC,MAAM,GAAK;gBACrED;gBACAX,oBAAoBY,OAAOnB;aAC5B;IAEL;IAEA,OAAON;AACT"}
@@ -1,46 +0,0 @@
1
- import { ShutdownRegistryTag } from '@entifix/business';
2
- import { Effect } from 'effect';
3
- import type { SagaDefinition } from '../contracts/saga-definition.js';
4
- import { SagaDispatcherTag } from '../ports/saga-dispatcher.js';
5
- import { SagaStoreTag } from '../ports/saga-store.js';
6
- export interface ResumeSweepOptions {
7
- /** Every flow this process can finish, by `definition.name`. */
8
- readonly definitions: readonly SagaDefinition[];
9
- /**
10
- * How long an instance may sit untouched before its coordinator is presumed
11
- * gone.
12
- *
13
- * ⚠️ **Must stay above the longest a step legitimately takes.** `updatedAt`
14
- * is re-stamped before every dispatch, so a slow participant keeps an instance
15
- * fresh — but a step slower than this window is resumed underneath the
16
- * coordinator still waiting on it, and only the participants' inboxes stop
17
- * that from being two side effects.
18
- */
19
- readonly staleAfterMs: number;
20
- /** Past this many sweeps, an instance settles `STRANDED` instead. */
21
- readonly maxResumeAttempts: number;
22
- }
23
- /**
24
- * One pass: find the instances nobody finished, claim each, and finish it.
25
- *
26
- * ⚠️ **`findStale` then `claimForResume`, never `findStale` then resume.** The
27
- * claim is a conditional write, so an instance another replica already took no
28
- * longer matches and is skipped. Without it two sweepers would walk one flow
29
- * together, and the attempt ceiling would count two attempts per tick.
30
- *
31
- * Failures are logged, per instance and around the pass, never raised: one flow
32
- * that cannot be resumed must not abandon the flows behind it, and a store that
33
- * is briefly unreachable must not kill the daemon that calls this.
34
- */
35
- export declare const resumeStaleSagas: ({ definitions, staleAfterMs, maxResumeAttempts, }: ResumeSweepOptions) => Effect.Effect<void, never, SagaStoreTag | SagaDispatcherTag>;
36
- /**
37
- * Runs {@link resumeStaleSagas} every `intervalMs` as a daemon, and stops it on
38
- * shutdown.
39
- *
40
- * `stop-intake`, not `flush`: the sweep writes the store and dispatches, so it
41
- * has to stop before the clients it goes through do.
42
- */
43
- export declare const startSagaResume: (options: ResumeSweepOptions & {
44
- readonly intervalMs: number;
45
- }) => Effect.Effect<void, never, SagaStoreTag | SagaDispatcherTag | ShutdownRegistryTag>;
46
- //# sourceMappingURL=resume-sweep.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resume-sweep.d.ts","sourceRoot":"","sources":["../../src/engine/resume-sweep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAY,MAAM,EAAS,MAAM,QAAQ,CAAC;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,MAAM,WAAW,kBAAkB;IACjC,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IAChD;;;;;;;;;OASG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,GAAI,mDAI9B,kBAAkB,KAAG,MAAM,CAAC,MAAM,CACnC,IAAI,EACJ,KAAK,EACL,YAAY,GAAG,iBAAiB,CAwD/B,CAAC;AAEJ;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,kBAAkB,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,KAC5D,MAAM,CAAC,MAAM,CACd,IAAI,EACJ,KAAK,EACL,YAAY,GAAG,iBAAiB,GAAG,mBAAmB,CA0BpD,CAAC"}
@@ -1,74 +0,0 @@
1
- import { ShutdownRegistryTag } from '@entifix/business';
2
- import { Duration, Effect, Fiber } from 'effect';
3
- import { SagaDispatcherTag } from '../ports/saga-dispatcher.js';
4
- import { SagaStoreTag } from '../ports/saga-store.js';
5
- import { resumeSaga } from './run-saga.js';
6
- /**
7
- * One pass: find the instances nobody finished, claim each, and finish it.
8
- *
9
- * ⚠️ **`findStale` then `claimForResume`, never `findStale` then resume.** The
10
- * claim is a conditional write, so an instance another replica already took no
11
- * longer matches and is skipped. Without it two sweepers would walk one flow
12
- * together, and the attempt ceiling would count two attempts per tick.
13
- *
14
- * Failures are logged, per instance and around the pass, never raised: one flow
15
- * that cannot be resumed must not abandon the flows behind it, and a store that
16
- * is briefly unreachable must not kill the daemon that calls this.
17
- */ export const resumeStaleSagas = ({ definitions, staleAfterMs, maxResumeAttempts })=>Effect.gen(function*() {
18
- const store = yield* SagaStoreTag;
19
- const byName = new Map(definitions.map((definition)=>[
20
- definition.name,
21
- definition
22
- ]));
23
- for (const found of yield* store.findStale(staleAfterMs)){
24
- const definition = byName.get(found.definition);
25
- if (definition === undefined) {
26
- // Nothing here can finish a flow it cannot read, and settling it would
27
- // be a guess about its steps — so it is surfaced and left alone.
28
- yield* Effect.logError('stale saga names an unknown definition').pipe(Effect.annotateLogs({
29
- sagaId: found.sagaId,
30
- definition: found.definition
31
- }));
32
- continue;
33
- }
34
- const claimed = yield* store.claimForResume(found.sagaId, staleAfterMs);
35
- if (claimed === undefined) continue;
36
- yield* resumeSaga({
37
- instance: claimed,
38
- definition,
39
- maxResumeAttempts
40
- }).pipe(Effect.tap((result)=>Effect.logInfo('resumed a saga instance').pipe(Effect.annotateLogs({
41
- sagaId: claimed.sagaId,
42
- definition: claimed.definition,
43
- resumedFrom: claimed.state,
44
- settled: result.state
45
- }))), Effect.catch((error)=>Effect.logError('resuming a saga instance failed').pipe(Effect.annotateLogs({
46
- sagaId: claimed.sagaId,
47
- error: String(error)
48
- }))));
49
- }
50
- }).pipe(Effect.catch((error)=>Effect.logError('saga resume sweep failed').pipe(Effect.annotateLogs({
51
- error: String(error)
52
- }))));
53
- /**
54
- * Runs {@link resumeStaleSagas} every `intervalMs` as a daemon, and stops it on
55
- * shutdown.
56
- *
57
- * `stop-intake`, not `flush`: the sweep writes the store and dispatches, so it
58
- * has to stop before the clients it goes through do.
59
- */ export const startSagaResume = (options)=>Effect.gen(function*() {
60
- const store = yield* SagaStoreTag;
61
- const dispatcher = yield* SagaDispatcherTag;
62
- const shutdown = yield* ShutdownRegistryTag;
63
- // Resolved once at boot and provided to every pass, so the daemon needs
64
- // nothing from the context it outlives.
65
- const pass = resumeStaleSagas(options).pipe(Effect.provideService(SagaStoreTag, store), Effect.provideService(SagaDispatcherTag, dispatcher));
66
- const daemon = yield* Effect.forkDetach(pass.pipe(Effect.delay(Duration.millis(options.intervalMs)), Effect.forever));
67
- yield* shutdown.register({
68
- name: 'saga-resume-sweep',
69
- phase: 'stop-intake',
70
- run: Fiber.interrupt(daemon).pipe(Effect.asVoid)
71
- });
72
- });
73
-
74
- //# sourceMappingURL=resume-sweep.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/engine/resume-sweep.ts"],"sourcesContent":["import { ShutdownRegistryTag } from '@entifix/business';\nimport { Duration, Effect, Fiber } from 'effect';\n\nimport type { SagaDefinition } from '../contracts/saga-definition.js';\nimport { SagaDispatcherTag } from '../ports/saga-dispatcher.js';\nimport { SagaStoreTag } from '../ports/saga-store.js';\nimport { resumeSaga } from './run-saga.js';\n\nexport interface ResumeSweepOptions {\n /** Every flow this process can finish, by `definition.name`. */\n readonly definitions: readonly SagaDefinition[];\n /**\n * How long an instance may sit untouched before its coordinator is presumed\n * gone.\n *\n * ⚠️ **Must stay above the longest a step legitimately takes.** `updatedAt`\n * is re-stamped before every dispatch, so a slow participant keeps an instance\n * fresh — but a step slower than this window is resumed underneath the\n * coordinator still waiting on it, and only the participants' inboxes stop\n * that from being two side effects.\n */\n readonly staleAfterMs: number;\n /** Past this many sweeps, an instance settles `STRANDED` instead. */\n readonly maxResumeAttempts: number;\n}\n\n/**\n * One pass: find the instances nobody finished, claim each, and finish it.\n *\n * ⚠️ **`findStale` then `claimForResume`, never `findStale` then resume.** The\n * claim is a conditional write, so an instance another replica already took no\n * longer matches and is skipped. Without it two sweepers would walk one flow\n * together, and the attempt ceiling would count two attempts per tick.\n *\n * Failures are logged, per instance and around the pass, never raised: one flow\n * that cannot be resumed must not abandon the flows behind it, and a store that\n * is briefly unreachable must not kill the daemon that calls this.\n */\nexport const resumeStaleSagas = ({\n definitions,\n staleAfterMs,\n maxResumeAttempts,\n}: ResumeSweepOptions): Effect.Effect<\n void,\n never,\n SagaStoreTag | SagaDispatcherTag\n> =>\n Effect.gen(function* () {\n const store = yield* SagaStoreTag;\n const byName = new Map(\n definitions.map(definition => [definition.name, definition]),\n );\n\n for (const found of yield* store.findStale(staleAfterMs)) {\n const definition = byName.get(found.definition);\n if (definition === undefined) {\n // Nothing here can finish a flow it cannot read, and settling it would\n // be a guess about its steps — so it is surfaced and left alone.\n yield* Effect.logError('stale saga names an unknown definition').pipe(\n Effect.annotateLogs({\n sagaId: found.sagaId,\n definition: found.definition,\n }),\n );\n continue;\n }\n\n const claimed = yield* store.claimForResume(found.sagaId, staleAfterMs);\n if (claimed === undefined) continue;\n\n yield* resumeSaga({\n instance: claimed,\n definition,\n maxResumeAttempts,\n }).pipe(\n Effect.tap(result =>\n Effect.logInfo('resumed a saga instance').pipe(\n Effect.annotateLogs({\n sagaId: claimed.sagaId,\n definition: claimed.definition,\n resumedFrom: claimed.state,\n settled: result.state,\n }),\n ),\n ),\n Effect.catch(error =>\n Effect.logError('resuming a saga instance failed').pipe(\n Effect.annotateLogs({\n sagaId: claimed.sagaId,\n error: String(error),\n }),\n ),\n ),\n );\n }\n }).pipe(\n Effect.catch(error =>\n Effect.logError('saga resume sweep failed').pipe(\n Effect.annotateLogs({ error: String(error) }),\n ),\n ),\n );\n\n/**\n * Runs {@link resumeStaleSagas} every `intervalMs` as a daemon, and stops it on\n * shutdown.\n *\n * `stop-intake`, not `flush`: the sweep writes the store and dispatches, so it\n * has to stop before the clients it goes through do.\n */\nexport const startSagaResume = (\n options: ResumeSweepOptions & { readonly intervalMs: number },\n): Effect.Effect<\n void,\n never,\n SagaStoreTag | SagaDispatcherTag | ShutdownRegistryTag\n> =>\n Effect.gen(function* () {\n const store = yield* SagaStoreTag;\n const dispatcher = yield* SagaDispatcherTag;\n const shutdown = yield* ShutdownRegistryTag;\n\n // Resolved once at boot and provided to every pass, so the daemon needs\n // nothing from the context it outlives.\n const pass = resumeStaleSagas(options).pipe(\n Effect.provideService(SagaStoreTag, store),\n Effect.provideService(SagaDispatcherTag, dispatcher),\n );\n\n const daemon = yield* Effect.forkDetach(\n pass.pipe(\n Effect.delay(Duration.millis(options.intervalMs)),\n Effect.forever,\n ),\n );\n\n yield* shutdown.register({\n name: 'saga-resume-sweep',\n phase: 'stop-intake',\n run: Fiber.interrupt(daemon).pipe(Effect.asVoid),\n });\n });\n"],"names":["ShutdownRegistryTag","Duration","Effect","Fiber","SagaDispatcherTag","SagaStoreTag","resumeSaga","resumeStaleSagas","definitions","staleAfterMs","maxResumeAttempts","gen","store","byName","Map","map","definition","name","found","findStale","get","undefined","logError","pipe","annotateLogs","sagaId","claimed","claimForResume","instance","tap","result","logInfo","resumedFrom","state","settled","catch","error","String","startSagaResume","options","dispatcher","shutdown","pass","provideService","daemon","forkDetach","delay","millis","intervalMs","forever","register","phase","run","interrupt","asVoid"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,oBAAoB;AACxD,SAASC,QAAQ,EAAEC,MAAM,EAAEC,KAAK,QAAQ,SAAS;AAGjD,SAASC,iBAAiB,QAAQ,8BAA8B;AAChE,SAASC,YAAY,QAAQ,yBAAyB;AACtD,SAASC,UAAU,QAAQ,gBAAgB;AAoB3C;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,mBAAmB,CAAC,EAC/BC,WAAW,EACXC,YAAY,EACZC,iBAAiB,EACE,GAKnBR,OAAOS,GAAG,CAAC;QACT,MAAMC,QAAQ,OAAOP;QACrB,MAAMQ,SAAS,IAAIC,IACjBN,YAAYO,GAAG,CAACC,CAAAA,aAAc;gBAACA,WAAWC,IAAI;gBAAED;aAAW;QAG7D,KAAK,MAAME,SAAS,OAAON,MAAMO,SAAS,CAACV,cAAe;YACxD,MAAMO,aAAaH,OAAOO,GAAG,CAACF,MAAMF,UAAU;YAC9C,IAAIA,eAAeK,WAAW;gBAC5B,uEAAuE;gBACvE,iEAAiE;gBACjE,OAAOnB,OAAOoB,QAAQ,CAAC,0CAA0CC,IAAI,CACnErB,OAAOsB,YAAY,CAAC;oBAClBC,QAAQP,MAAMO,MAAM;oBACpBT,YAAYE,MAAMF,UAAU;gBAC9B;gBAEF;YACF;YAEA,MAAMU,UAAU,OAAOd,MAAMe,cAAc,CAACT,MAAMO,MAAM,EAAEhB;YAC1D,IAAIiB,YAAYL,WAAW;YAE3B,OAAOf,WAAW;gBAChBsB,UAAUF;gBACVV;gBACAN;YACF,GAAGa,IAAI,CACLrB,OAAO2B,GAAG,CAACC,CAAAA,SACT5B,OAAO6B,OAAO,CAAC,2BAA2BR,IAAI,CAC5CrB,OAAOsB,YAAY,CAAC;oBAClBC,QAAQC,QAAQD,MAAM;oBACtBT,YAAYU,QAAQV,UAAU;oBAC9BgB,aAAaN,QAAQO,KAAK;oBAC1BC,SAASJ,OAAOG,KAAK;gBACvB,MAGJ/B,OAAOiC,KAAK,CAACC,CAAAA,QACXlC,OAAOoB,QAAQ,CAAC,mCAAmCC,IAAI,CACrDrB,OAAOsB,YAAY,CAAC;oBAClBC,QAAQC,QAAQD,MAAM;oBACtBW,OAAOC,OAAOD;gBAChB;QAIR;IACF,GAAGb,IAAI,CACLrB,OAAOiC,KAAK,CAACC,CAAAA,QACXlC,OAAOoB,QAAQ,CAAC,4BAA4BC,IAAI,CAC9CrB,OAAOsB,YAAY,CAAC;YAAEY,OAAOC,OAAOD;QAAO,MAG/C;AAEJ;;;;;;CAMC,GACD,OAAO,MAAME,kBAAkB,CAC7BC,UAMArC,OAAOS,GAAG,CAAC;QACT,MAAMC,QAAQ,OAAOP;QACrB,MAAMmC,aAAa,OAAOpC;QAC1B,MAAMqC,WAAW,OAAOzC;QAExB,wEAAwE;QACxE,wCAAwC;QACxC,MAAM0C,OAAOnC,iBAAiBgC,SAAShB,IAAI,CACzCrB,OAAOyC,cAAc,CAACtC,cAAcO,QACpCV,OAAOyC,cAAc,CAACvC,mBAAmBoC;QAG3C,MAAMI,SAAS,OAAO1C,OAAO2C,UAAU,CACrCH,KAAKnB,IAAI,CACPrB,OAAO4C,KAAK,CAAC7C,SAAS8C,MAAM,CAACR,QAAQS,UAAU,IAC/C9C,OAAO+C,OAAO;QAIlB,OAAOR,SAASS,QAAQ,CAAC;YACvBjC,MAAM;YACNkC,OAAO;YACPC,KAAKjD,MAAMkD,SAAS,CAACT,QAAQrB,IAAI,CAACrB,OAAOoD,MAAM;QACjD;IACF,GAAG"}
@@ -1,54 +0,0 @@
1
- import type { StoreFailure } from '@entifix/core';
2
- import { Effect } from 'effect';
3
- import { type SagaDefinition, type SagaInputs, type SagaStepInput, type SagaStepOutcome } from '../contracts/saga-definition.js';
4
- import { SagaDispatcherTag } from '../ports/saga-dispatcher.js';
5
- import { type SagaInstance, SagaStoreTag } from '../ports/saga-store.js';
6
- export type { SagaInputs, SagaStepInput };
7
- export interface RunSagaOptions {
8
- readonly sagaId: string;
9
- readonly definition: SagaDefinition;
10
- readonly inputs: SagaInputs;
11
- }
12
- /** How a run ended. */
13
- export interface SagaResult {
14
- readonly state: 'COMPLETED' | 'COMPENSATED' | 'STRANDED';
15
- readonly outcomes: readonly SagaStepOutcome[];
16
- readonly error?: string;
17
- }
18
- /**
19
- * Start a flow and walk it to a terminal state.
20
- *
21
- * ⚠️ **Synchronous, and that is the buyer's requirement.** A checkout needs a
22
- * yes/no now, so this answers the settled result. What {@link resumeSaga} adds
23
- * is durability *behind* that answer: if this process dies mid-walk, the record
24
- * it has been writing all along is enough for another one to finish the flow.
25
- */
26
- export declare const runSaga: (options: RunSagaOptions) => Effect.Effect<SagaResult, StoreFailure, SagaDispatcherTag | SagaStoreTag>;
27
- export interface ResumeSagaOptions {
28
- readonly instance: SagaInstance;
29
- readonly definition: SagaDefinition;
30
- /** Past this many sweeps, the instance is surfaced instead of retried. */
31
- readonly maxResumeAttempts: number;
32
- }
33
- /**
34
- * Finish a flow another coordinator abandoned.
35
- *
36
- * ⚠️ **Where to re-enter is derived, never stored.** A resume point written
37
- * beside the outcomes would be a second record of the same fact, free to
38
- * disagree with them; the outcomes already say what happened, and
39
- * `beginStep`-before-dispatch means `stepIndex` says what was attempted. The
40
- * four cases are exhaustive:
41
- *
42
- * - the step at `stepIndex` recorded no outcome — the process died during the
43
- * dispatch, so **re-dispatch it**. Safe because `sagaCommandId` is stable
44
- * across attempts and every participant claims it in its own command inbox,
45
- * so calls that did land are recognised as replays rather than repeated.
46
- * - it recorded a successful outcome — the process died between
47
- * `recordOutcome` and the next `beginStep`, so **start at the one after**.
48
- * - it recorded a refusal — the process died deciding what to do about it, so
49
- * **re-enter that decision**: unwind, or strand if the pivot had committed.
50
- * - the instance is `COMPENSATING` — it died mid-unwind, so **continue the
51
- * unwind**, skipping steps already marked `compensated`.
52
- */
53
- export declare const resumeSaga: (options: ResumeSagaOptions) => Effect.Effect<SagaResult, StoreFailure, SagaDispatcherTag | SagaStoreTag>;
54
- //# sourceMappingURL=run-saga.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-saga.d.ts","sourceRoot":"","sources":["../../src/engine/run-saga.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,UAAU,EAEf,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,YAAY,EAEjB,YAAY,EACb,MAAM,wBAAwB,CAAC;AAGhC,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AAa1C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC7B;AAED,uBAAuB;AACvB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,GAAG,UAAU,CAAC;IACzD,QAAQ,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,CAAC;IAC9C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAseD;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,GAClB,SAAS,cAAc,KACtB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,iBAAiB,GAAG,YAAY,CAmBvE,CAAC;AAEL,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,0EAA0E;IAC1E,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,UAAU,GACrB,SAAS,iBAAiB,KACzB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,iBAAiB,GAAG,YAAY,CA6FvE,CAAC"}