@entifix/transactions 0.10.2 → 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 (86) hide show
  1. package/dist/contracts/command.d.ts +1 -0
  2. package/dist/contracts/command.d.ts.map +1 -1
  3. package/dist/contracts/command.js +7 -3
  4. package/dist/contracts/command.js.map +1 -1
  5. package/dist/contracts/event.d.ts +5 -4
  6. package/dist/contracts/event.d.ts.map +1 -1
  7. package/dist/contracts/event.js +14 -1
  8. package/dist/contracts/event.js.map +1 -1
  9. package/dist/contracts/flow-capability.d.ts +22 -0
  10. package/dist/contracts/flow-capability.d.ts.map +1 -0
  11. package/dist/contracts/flow-capability.js +26 -0
  12. package/dist/contracts/flow-capability.js.map +1 -0
  13. package/dist/contracts/flow-messages.d.ts +52 -0
  14. package/dist/contracts/flow-messages.d.ts.map +1 -0
  15. package/dist/contracts/flow-messages.js +65 -0
  16. package/dist/contracts/flow-messages.js.map +1 -0
  17. package/dist/contracts/inbox.d.ts +19 -2
  18. package/dist/contracts/inbox.d.ts.map +1 -1
  19. package/dist/contracts/inbox.js +16 -1
  20. package/dist/contracts/inbox.js.map +1 -1
  21. package/dist/contracts/messages.d.ts +37 -0
  22. package/dist/contracts/messages.d.ts.map +1 -0
  23. package/dist/contracts/messages.js +68 -0
  24. package/dist/contracts/messages.js.map +1 -0
  25. package/dist/contracts/outbox.d.ts +50 -12
  26. package/dist/contracts/outbox.d.ts.map +1 -1
  27. package/dist/contracts/outbox.js +18 -1
  28. package/dist/contracts/outbox.js.map +1 -1
  29. package/dist/contracts/record.d.ts +7 -8
  30. package/dist/contracts/record.d.ts.map +1 -1
  31. package/dist/contracts/record.js +8 -8
  32. package/dist/contracts/record.js.map +1 -1
  33. package/dist/contracts/unit-of-work.d.ts +3 -2
  34. package/dist/contracts/unit-of-work.d.ts.map +1 -1
  35. package/dist/contracts/unit-of-work.js.map +1 -1
  36. package/dist/engine/in-memory-bulkhead.d.ts +20 -0
  37. package/dist/engine/in-memory-bulkhead.d.ts.map +1 -0
  38. package/dist/engine/in-memory-bulkhead.js +38 -0
  39. package/dist/engine/in-memory-bulkhead.js.map +1 -0
  40. package/dist/engine/in-memory-circuit-breaker.d.ts +28 -0
  41. package/dist/engine/in-memory-circuit-breaker.d.ts.map +1 -0
  42. package/dist/engine/in-memory-circuit-breaker.js +151 -0
  43. package/dist/engine/in-memory-circuit-breaker.js.map +1 -0
  44. package/dist/engine/index.d.ts +4 -0
  45. package/dist/engine/index.d.ts.map +1 -1
  46. package/dist/engine/index.js +4 -0
  47. package/dist/engine/index.js.map +1 -1
  48. package/dist/engine/outbox-metrics.d.ts +47 -0
  49. package/dist/engine/outbox-metrics.d.ts.map +1 -0
  50. package/dist/engine/outbox-metrics.js +68 -0
  51. package/dist/engine/outbox-metrics.js.map +1 -0
  52. package/dist/engine/outbox-relay.d.ts +102 -0
  53. package/dist/engine/outbox-relay.d.ts.map +1 -0
  54. package/dist/engine/outbox-relay.js +111 -0
  55. package/dist/engine/outbox-relay.js.map +1 -0
  56. package/dist/engine/run-transaction.d.ts +4 -4
  57. package/dist/engine/run-transaction.d.ts.map +1 -1
  58. package/dist/engine/run-transaction.js +4 -4
  59. package/dist/engine/run-transaction.js.map +1 -1
  60. package/dist/index.d.ts +7 -0
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +7 -0
  63. package/dist/index.js.map +1 -1
  64. package/dist/ports/bulkhead.d.ts +28 -0
  65. package/dist/ports/bulkhead.d.ts.map +1 -0
  66. package/dist/ports/bulkhead.js +18 -0
  67. package/dist/ports/bulkhead.js.map +1 -0
  68. package/dist/ports/circuit-breaker.d.ts +62 -0
  69. package/dist/ports/circuit-breaker.d.ts.map +1 -0
  70. package/dist/ports/circuit-breaker.js +42 -0
  71. package/dist/ports/circuit-breaker.js.map +1 -0
  72. package/dist/ports/event-bus.d.ts +10 -0
  73. package/dist/ports/event-bus.d.ts.map +1 -1
  74. package/dist/ports/event-bus.js.map +1 -1
  75. package/dist/ports/flow-engine.d.ts +60 -0
  76. package/dist/ports/flow-engine.d.ts.map +1 -0
  77. package/dist/ports/flow-engine.js +19 -0
  78. package/dist/ports/flow-engine.js.map +1 -0
  79. package/dist/ports/participant-client.d.ts +32 -0
  80. package/dist/ports/participant-client.d.ts.map +1 -0
  81. package/dist/ports/participant-client.js +5 -0
  82. package/dist/ports/participant-client.js.map +1 -0
  83. package/dist/reactions/on.d.ts.map +1 -1
  84. package/dist/reactions/on.js +2 -1
  85. package/dist/reactions/on.js.map +1 -1
  86. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/engine/in-memory-circuit-breaker.ts"],"sourcesContent":["import { isFailure } from '@entifix/core';\nimport { Cause, Effect, Exit, Layer, Metric } from 'effect';\n\nimport {\n BREAKER_STATE_VALUE,\n type BreakerDials,\n BreakerOpen,\n breakerRejections,\n type BreakerState,\n breakerState,\n breakerTransitions,\n type CircuitBreaker,\n CircuitBreakerTag,\n DEFAULT_BREAKER_DIALS,\n} from '../ports/circuit-breaker.js';\n\n/** One call's outcome, as the window holds it. */\ninterface Recorded {\n readonly at: number;\n readonly failed: boolean;\n readonly slow: boolean;\n}\n\ninterface Circuit {\n state: BreakerState;\n /** When it opened, and how long it waits — a `Retry-After` may lengthen it. */\n openedAt: number;\n waitMs: number;\n window: Recorded[];\n /** Half-open: probes let through, and their outcomes. */\n admitted: number;\n probes: Recorded[];\n}\n\nexport interface InMemoryCircuitBreakerOptions {\n /** Dials for every key, over the defaults. */\n readonly dials?: Partial<BreakerDials>;\n /** Dials for one key, over `dials` — a participant's own row. */\n readonly dialsFor?: (key: string) => Partial<BreakerDials> | undefined;\n /** The clock, in epoch milliseconds. Injected so a spec can move time. */\n readonly now?: () => number;\n}\n\n/** What a call's exit means to the window: a failure, a success, or neither. */\nconst verdictOf = (exit: Exit.Exit<unknown, unknown>) => {\n if (Exit.isSuccess(exit)) return { recorded: true, failed: false } as const;\n const failure = Cause.findErrorOption(exit.cause);\n if (failure._tag === 'None') return { recorded: false } as const;\n const error = failure.value;\n // An answer is not a failure of the dependency, and a protocol failure is a\n // bug that waiting does not fix: neither moves the breaker.\n if (!isFailure(error)) return { recorded: false } as const;\n if (error.family === 'business')\n return { recorded: true, failed: false } as const;\n if (error.category === 'protocol') return { recorded: false } as const;\n return { recorded: true, failed: true, failure: error } as const;\n};\n\n/** Seconds a dependency asked to be left alone for, when it said so. */\nconst retryAfterOf = (failure: unknown): number | undefined => {\n const seconds = (failure as { readonly retryAfterSeconds?: unknown })\n .retryAfterSeconds;\n return typeof seconds === 'number' && seconds > 0 ? seconds : undefined;\n};\n\nconst rates = (calls: readonly Recorded[]) => ({\n failure: calls.filter(call => call.failed).length / calls.length,\n slow: calls.filter(call => call.slow).length / calls.length,\n});\n\n/**\n * Per-process breakers, one per key, on Resilience4j's state machine\n * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).\n *\n * Closed, every call is recorded in a count- or time-based window; once the\n * window holds `minimumCalls` and the failure or slow-call rate reaches its\n * threshold, the breaker opens. A dependency answering with `Retry-After` opens\n * it at once, for at least as long as it asked. Open, every call is refused\n * until `waitInOpenMs` has passed; then `halfOpenPermits` probes go through, and\n * their outcome closes or reopens it.\n *\n * Per process on purpose: a fleet-wide breaker would put a shared store on the\n * hot path, and per-process state converges within a window.\n */\nexport const makeInMemoryCircuitBreaker = (\n options: InMemoryCircuitBreakerOptions = {},\n): CircuitBreaker => {\n const now = options.now ?? Date.now;\n const circuits = new Map<string, Circuit>();\n const dialsOf = (key: string): BreakerDials => ({\n ...DEFAULT_BREAKER_DIALS,\n ...options.dials,\n ...options.dialsFor?.(key),\n });\n\n const circuitOf = (key: string): Circuit => {\n let circuit = circuits.get(key);\n if (circuit === undefined) {\n circuit = {\n state: 'closed',\n openedAt: 0,\n waitMs: 0,\n window: [],\n admitted: 0,\n probes: [],\n };\n circuits.set(key, circuit);\n }\n return circuit;\n };\n\n const report = (key: string, circuit: Circuit) =>\n Metric.update(\n Metric.withAttributes(breakerState, { key }),\n BREAKER_STATE_VALUE[circuit.state],\n );\n\n const move = (key: string, circuit: Circuit, to: BreakerState) => {\n const from = circuit.state;\n circuit.state = to;\n circuit.admitted = 0;\n circuit.probes = [];\n if (to === 'closed') circuit.window = [];\n return Metric.update(\n Metric.withAttributes(breakerTransitions, { key, from, to }),\n 1,\n ).pipe(Effect.andThen(report(key, circuit)));\n };\n\n const open = (key: string, circuit: Circuit, waitMs: number) => {\n circuit.openedAt = now();\n circuit.waitMs = waitMs;\n return move(key, circuit, 'open');\n };\n\n /** An open breaker whose wait has passed is half-open, read lazily. */\n const settle = (key: string, circuit: Circuit) =>\n circuit.state === 'open' && now() - circuit.openedAt >= circuit.waitMs\n ? move(key, circuit, 'halfOpen')\n : Effect.void;\n\n const trimmed = (window: Recorded[], dials: BreakerDials): Recorded[] =>\n dials.windowType === 'count'\n ? window.slice(-dials.windowSize)\n : window.filter(call => now() - call.at < dials.windowSize * 1_000);\n\n const record = (\n key: string,\n circuit: Circuit,\n call: Recorded,\n failure: unknown,\n ) =>\n Effect.suspend(() => {\n const dials = dialsOf(key);\n const retryAfter = call.failed ? retryAfterOf(failure) : undefined;\n if (retryAfter !== undefined && circuit.state !== 'disabled')\n return open(\n key,\n circuit,\n Math.max(dials.waitInOpenMs, retryAfter * 1_000),\n );\n\n if (circuit.state === 'halfOpen') {\n circuit.probes.push(call);\n if (circuit.probes.length < dials.halfOpenPermits) return Effect.void;\n const probed = rates(circuit.probes);\n return probed.failure >= dials.failureRateThreshold ||\n probed.slow >= dials.slowCallRateThreshold\n ? open(key, circuit, dials.waitInOpenMs)\n : move(key, circuit, 'closed');\n }\n\n if (circuit.state !== 'closed') return Effect.void;\n circuit.window = trimmed([...circuit.window, call], dials);\n if (circuit.window.length < dials.minimumCalls) return Effect.void;\n const windowed = rates(circuit.window);\n return windowed.failure >= dials.failureRateThreshold ||\n windowed.slow >= dials.slowCallRateThreshold\n ? open(key, circuit, dials.waitInOpenMs)\n : Effect.void;\n });\n\n const refuse = (key: string) =>\n Metric.update(Metric.withAttributes(breakerRejections, { key }), 1).pipe(\n Effect.andThen(Effect.fail(new BreakerOpen({ dependency: key }))),\n );\n\n return {\n guard:\n key =>\n <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n Effect.gen(function* () {\n const circuit = circuitOf(key);\n yield* settle(key, circuit);\n if (circuit.state === 'disabled') return yield* effect;\n if (circuit.state === 'open' || circuit.state === 'forcedOpen')\n return yield* refuse(key);\n if (circuit.state === 'halfOpen') {\n const dials = dialsOf(key);\n if (circuit.admitted >= dials.halfOpenPermits)\n return yield* refuse(key);\n circuit.admitted += 1;\n }\n\n const startedAt = now();\n const exit = yield* Effect.exit(effect);\n const verdict = verdictOf(exit);\n if (verdict.recorded)\n yield* record(\n key,\n circuit,\n {\n at: startedAt,\n failed: verdict.failed,\n slow: now() - startedAt > dialsOf(key).slowCallDurationMs,\n },\n verdict.failed ? verdict.failure : undefined,\n );\n return yield* exit;\n }),\n\n state: key =>\n Effect.gen(function* () {\n const circuit = circuitOf(key);\n yield* settle(key, circuit);\n return circuit.state;\n }),\n\n force: (key, state) =>\n Effect.suspend(() => move(key, circuitOf(key), state)),\n };\n};\n\n/** One breaker set for the process, for the composition root. */\nexport const InMemoryCircuitBreakerLayer = (\n options: InMemoryCircuitBreakerOptions = {},\n) => Layer.sync(CircuitBreakerTag, () => makeInMemoryCircuitBreaker(options));\n"],"names":["isFailure","Cause","Effect","Exit","Layer","Metric","BREAKER_STATE_VALUE","BreakerOpen","breakerRejections","breakerState","breakerTransitions","CircuitBreakerTag","DEFAULT_BREAKER_DIALS","verdictOf","exit","isSuccess","recorded","failed","failure","findErrorOption","cause","_tag","error","value","family","category","retryAfterOf","seconds","retryAfterSeconds","undefined","rates","calls","filter","call","length","slow","makeInMemoryCircuitBreaker","options","now","Date","circuits","Map","dialsOf","key","dials","dialsFor","circuitOf","circuit","get","state","openedAt","waitMs","window","admitted","probes","set","report","update","withAttributes","move","to","from","pipe","andThen","open","settle","void","trimmed","windowType","slice","windowSize","at","record","suspend","retryAfter","Math","max","waitInOpenMs","push","halfOpenPermits","probed","failureRateThreshold","slowCallRateThreshold","minimumCalls","windowed","refuse","fail","dependency","guard","effect","gen","startedAt","verdict","slowCallDurationMs","force","InMemoryCircuitBreakerLayer","sync"],"mappings":";AAAA,SAASA,SAAS,QAAQ,gBAAgB;AAC1C,SAASC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,MAAM,QAAQ,SAAS;AAE5D,SACEC,mBAAmB,EAEnBC,WAAW,EACXC,iBAAiB,EAEjBC,YAAY,EACZC,kBAAkB,EAElBC,iBAAiB,EACjBC,qBAAqB,QAChB,8BAA8B;AA6BrC,8EAA8E,GAC9E,MAAMC,YAAY,CAACC;IACjB,IAAIX,KAAKY,SAAS,CAACD,OAAO,OAAO;QAAEE,UAAU;QAAMC,QAAQ;IAAM;IACjE,MAAMC,UAAUjB,MAAMkB,eAAe,CAACL,KAAKM,KAAK;IAChD,IAAIF,QAAQG,IAAI,KAAK,QAAQ,OAAO;QAAEL,UAAU;IAAM;IACtD,MAAMM,QAAQJ,QAAQK,KAAK;IAC3B,4EAA4E;IAC5E,4DAA4D;IAC5D,IAAI,CAACvB,UAAUsB,QAAQ,OAAO;QAAEN,UAAU;IAAM;IAChD,IAAIM,MAAME,MAAM,KAAK,YACnB,OAAO;QAAER,UAAU;QAAMC,QAAQ;IAAM;IACzC,IAAIK,MAAMG,QAAQ,KAAK,YAAY,OAAO;QAAET,UAAU;IAAM;IAC5D,OAAO;QAAEA,UAAU;QAAMC,QAAQ;QAAMC,SAASI;IAAM;AACxD;AAEA,sEAAsE,GACtE,MAAMI,eAAe,CAACR;IACpB,MAAMS,UAAU,AAACT,QACdU,iBAAiB;IACpB,OAAO,OAAOD,YAAY,YAAYA,UAAU,IAAIA,UAAUE;AAChE;AAEA,MAAMC,QAAQ,CAACC,QAAgC,CAAA;QAC7Cb,SAASa,M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,OAAOY,IAAI,CAAC2E;oBAChC,MAAMG,UAAU/E,UAAUC;oBAC1B,IAAI8E,QAAQ5E,QAAQ,EAClB,OAAOwD,OACL7B,KACAI,SACA;wBACEwB,IAAIoB;wBACJ1E,QAAQ2E,QAAQ3E,MAAM;wBACtBkB,MAAMG,QAAQqD,YAAYjD,QAAQC,KAAKkD,kBAAkB;oBAC3D,GACAD,QAAQ3E,MAAM,GAAG2E,QAAQ1E,OAAO,GAAGW;oBAEvC,OAAO,OAAOf;gBAChB;QAEJmC,OAAON,CAAAA,MACLzC,OAAOwF,GAAG,CAAC;gBACT,MAAM3C,UAAUD,UAAUH;gBAC1B,OAAOsB,OAAOtB,KAAKI;gBACnB,OAAOA,QAAQE,KAAK;YACtB;QAEF6C,OAAO,CAACnD,KAAKM,QACX/C,OAAOuE,OAAO,CAAC,IAAMd,KAAKhB,KAAKG,UAAUH,MAAMM;IACnD;AACF,EAAE;AAEF,+DAA+D,GAC/D,OAAO,MAAM8C,8BAA8B,CACzC1D,UAAyC,CAAC,CAAC,GACxCjC,MAAM4F,IAAI,CAACrF,mBAAmB,IAAMyB,2BAA2BC,UAAU"}
@@ -9,8 +9,12 @@
9
9
  * specifier (ADR 0006).
10
10
  */
11
11
  export * from '../stream/transaction-stream-hub.js';
12
+ export * from './in-memory-bulkhead.js';
13
+ export * from './in-memory-circuit-breaker.js';
12
14
  export * from './in-memory-retry-budget.js';
13
15
  export * from './local-saga-dispatcher.js';
16
+ export * from './outbox-metrics.js';
17
+ export * from './outbox-relay.js';
14
18
  export * from './resolve-template.js';
15
19
  export * from './resume-sweep.js';
16
20
  export * from './run-saga.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,qCAAqC,CAAC;AACpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,qCAAqC,CAAC;AACpD,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
@@ -8,8 +8,12 @@
8
8
  * participant — must be able to ban the engine by name, and a ban matches a
9
9
  * specifier (ADR 0006).
10
10
  */ export * from '../stream/transaction-stream-hub.js';
11
+ export * from './in-memory-bulkhead.js';
12
+ export * from './in-memory-circuit-breaker.js';
11
13
  export * from './in-memory-retry-budget.js';
12
14
  export * from './local-saga-dispatcher.js';
15
+ export * from './outbox-metrics.js';
16
+ export * from './outbox-relay.js';
13
17
  export * from './resolve-template.js';
14
18
  export * from './resume-sweep.js';
15
19
  export * from './run-saga.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/engine/index.ts"],"sourcesContent":["/**\n * The mechanism behind `@entifix/transactions`' ports: the saga runner and its\n * resume sweep, the single-step transaction engine, the in-process dispatcher\n * and the stream hub.\n *\n * A subpath rather than part of `.` although it installs nothing `.` does not,\n * because a consumer that writes against the contracts — a cell, a route, a\n * participant — must be able to ban the engine by name, and a ban matches a\n * specifier (ADR 0006).\n */\nexport * from '../stream/transaction-stream-hub.js';\nexport * from './in-memory-retry-budget.js';\nexport * from './local-saga-dispatcher.js';\nexport * from './resolve-template.js';\nexport * from './resume-sweep.js';\nexport * from './run-saga.js';\nexport * from './run-transaction.js';\n"],"names":[],"mappings":"AAAA;;;;;;;;;CASC,GACD,cAAc,sCAAsC;AACpD,cAAc,8BAA8B;AAC5C,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,uBAAuB"}
1
+ {"version":3,"sources":["../../src/engine/index.ts"],"sourcesContent":["/**\n * The mechanism behind `@entifix/transactions`' ports: the saga runner and its\n * resume sweep, the single-step transaction engine, the in-process dispatcher\n * and the stream hub.\n *\n * A subpath rather than part of `.` although it installs nothing `.` does not,\n * because a consumer that writes against the contracts — a cell, a route, a\n * participant — must be able to ban the engine by name, and a ban matches a\n * specifier (ADR 0006).\n */\nexport * from '../stream/transaction-stream-hub.js';\nexport * from './in-memory-bulkhead.js';\nexport * from './in-memory-circuit-breaker.js';\nexport * from './in-memory-retry-budget.js';\nexport * from './local-saga-dispatcher.js';\nexport * from './outbox-metrics.js';\nexport * from './outbox-relay.js';\nexport * from './resolve-template.js';\nexport * from './resume-sweep.js';\nexport * from './run-saga.js';\nexport * from './run-transaction.js';\n"],"names":[],"mappings":"AAAA;;;;;;;;;CASC,GACD,cAAc,sCAAsC;AACpD,cAAc,0BAA0B;AACxC,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,6BAA6B;AAC3C,cAAc,sBAAsB;AACpC,cAAc,oBAAoB;AAClC,cAAc,wBAAwB;AACtC,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,uBAAuB"}
@@ -0,0 +1,47 @@
1
+ import { Effect, Metric } from 'effect';
2
+ import type { OutboxStats } from '../contracts/outbox.js';
3
+ /**
4
+ * The outbox half of the framework's first metric set; the bus half is in
5
+ * `@entifix/amqp`.
6
+ *
7
+ * It lives beside the relay that samples it rather than in any one service,
8
+ * because three slices now own an outbox — `catalog`, `order` and `payment` —
9
+ * and the warning below is exactly why a copy per service is not an option: an
10
+ * Effect metric is keyed on its **description**, so three hand-maintained
11
+ * definitions of `outbox_pending_entries` are three series the moment one
12
+ * wording drifts, and a dashboard would go quiet without failing anything.
13
+ *
14
+ * ⚠️ The metric objects are **exported so a reader uses the same instance**. An
15
+ * Effect metric's registry key includes its description, so rebuilding one by
16
+ * name without the description addresses a different series that is permanently
17
+ * zero — a silent way to write a query against nothing.
18
+ *
19
+ * These are gauges rather than counters because they describe a *backlog*: the
20
+ * question is how many are waiting right now, not how many there have ever
21
+ * been. They are sampled by the two daemons that already run on an interval, so
22
+ * nothing new is scheduled to produce them.
23
+ *
24
+ * ⚠️ **A dimensionless gauge reaches Prometheus with a `_ratio` suffix.** That
25
+ * is the OTel exporter's convention for unit `1`, not a mistake here, so
26
+ * `outbox_pending_entries` is queried as `outbox_pending_entries_ratio`.
27
+ * Counters are unaffected. Where a metric has a real unit, tag it — see
28
+ * {@link outboxOldestPendingAge}.
29
+ */
30
+ /** Unsent, un-quarantined entries, per database. */
31
+ export declare const outboxPending: Metric.Gauge<number>;
32
+ /**
33
+ * Age in seconds of the oldest unsent entry, per database.
34
+ *
35
+ * **The metric that makes a stuck relay visible.** Quarantine gave the relay a
36
+ * ceiling, so an entry that can never publish is quarantined and skipped rather
37
+ * than blocking the head of the line forever — but that is reported only as a
38
+ * log line, so how far behind the outbox has fallen is otherwise unanswerable.
39
+ * A depth that is flat and an age that climbs is the signature of a relay whose
40
+ * head has stopped moving.
41
+ */
42
+ export declare const outboxOldestPendingAge: Metric.Gauge<number>;
43
+ /** Entries past the ceiling, which nothing retries and nothing deletes. */
44
+ export declare const outboxQuarantined: Metric.Gauge<number>;
45
+ /** Record one outbox's depth and age. */
46
+ export declare const recordOutboxStats: (database: string, stats: OutboxStats) => Effect.Effect<void, never, never>;
47
+ //# sourceMappingURL=outbox-metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbox-metrics.d.ts","sourceRoot":"","sources":["../../src/engine/outbox-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,oDAAoD;AACpD,eAAO,MAAM,aAAa,sBAExB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAkBvD,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,sBAE5B,CAAC;AAEH,yCAAyC;AACzC,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,EAAE,OAAO,WAAW,sCAgBrE,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { Effect, Metric } from 'effect';
2
+ /**
3
+ * The outbox half of the framework's first metric set; the bus half is in
4
+ * `@entifix/amqp`.
5
+ *
6
+ * It lives beside the relay that samples it rather than in any one service,
7
+ * because three slices now own an outbox — `catalog`, `order` and `payment` —
8
+ * and the warning below is exactly why a copy per service is not an option: an
9
+ * Effect metric is keyed on its **description**, so three hand-maintained
10
+ * definitions of `outbox_pending_entries` are three series the moment one
11
+ * wording drifts, and a dashboard would go quiet without failing anything.
12
+ *
13
+ * ⚠️ The metric objects are **exported so a reader uses the same instance**. An
14
+ * Effect metric's registry key includes its description, so rebuilding one by
15
+ * name without the description addresses a different series that is permanently
16
+ * zero — a silent way to write a query against nothing.
17
+ *
18
+ * These are gauges rather than counters because they describe a *backlog*: the
19
+ * question is how many are waiting right now, not how many there have ever
20
+ * been. They are sampled by the two daemons that already run on an interval, so
21
+ * nothing new is scheduled to produce them.
22
+ *
23
+ * ⚠️ **A dimensionless gauge reaches Prometheus with a `_ratio` suffix.** That
24
+ * is the OTel exporter's convention for unit `1`, not a mistake here, so
25
+ * `outbox_pending_entries` is queried as `outbox_pending_entries_ratio`.
26
+ * Counters are unaffected. Where a metric has a real unit, tag it — see
27
+ * {@link outboxOldestPendingAge}.
28
+ */ /** Unsent, un-quarantined entries, per database. */ export const outboxPending = Metric.gauge('outbox_pending_entries', {
29
+ description: 'Unsent, un-quarantined outbox entries, by database.'
30
+ });
31
+ /**
32
+ * Age in seconds of the oldest unsent entry, per database.
33
+ *
34
+ * **The metric that makes a stuck relay visible.** Quarantine gave the relay a
35
+ * ceiling, so an entry that can never publish is quarantined and skipped rather
36
+ * than blocking the head of the line forever — but that is reported only as a
37
+ * log line, so how far behind the outbox has fallen is otherwise unanswerable.
38
+ * A depth that is flat and an age that climbs is the signature of a relay whose
39
+ * head has stopped moving.
40
+ */ export const outboxOldestPendingAge = Metric.gauge('outbox_oldest_pending_age', {
41
+ description: 'Age of the oldest unsent outbox entry, by database. Zero when ' + 'the outbox is empty.'
42
+ }).pipe(// ⚠️ **The unit is carried as a tag, and that is the only way to set it.**
43
+ // `@effect/opentelemetry`'s producer reads `tags.unit ?? tags.time_unit ??
44
+ // '1'`, so a gauge with no `unit` tag is exported as dimensionless — and the
45
+ // Prometheus exporter then appends `_ratio` to a dimensionless gauge's name.
46
+ // Measured: this series arrived as `outbox_oldest_pending_age_seconds_ratio`,
47
+ // a duration announcing itself as a ratio. Tagging it makes the exporter name
48
+ // it `_seconds`, which is why the name above no longer carries that suffix
49
+ // itself. The cost is a constant `unit` label, because the producer builds the
50
+ // datapoint attributes from the same tag set it reads the unit from.
51
+ Metric.withAttributes({
52
+ unit: 's'
53
+ }));
54
+ /** Entries past the ceiling, which nothing retries and nothing deletes. */ export const outboxQuarantined = Metric.gauge('outbox_quarantined_entries', {
55
+ description: 'Quarantined outbox entries, by database.'
56
+ });
57
+ /** Record one outbox's depth and age. */ export const recordOutboxStats = (database, stats)=>{
58
+ const tagged = (metric)=>Metric.withAttributes(metric, {
59
+ database
60
+ });
61
+ // Zero when nothing is waiting. The alternative — not reporting the series —
62
+ // reads on most dashboards as "no data", which is indistinguishable from the
63
+ // exporter having broken at exactly the moment a healthy relay looks idle.
64
+ const ageSeconds = stats.oldestPendingAt === undefined ? 0 : Math.max(0, (Date.now() - Date.parse(stats.oldestPendingAt)) / 1000);
65
+ return Metric.update(tagged(outboxPending), stats.pending).pipe(Effect.andThen(Metric.update(tagged(outboxOldestPendingAge), ageSeconds)), Effect.andThen(Metric.update(tagged(outboxQuarantined), stats.quarantined)));
66
+ };
67
+
68
+ //# sourceMappingURL=outbox-metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/engine/outbox-metrics.ts"],"sourcesContent":["import { Effect, Metric } from 'effect';\n\nimport type { OutboxStats } from '../contracts/outbox.js';\n\n/**\n * The outbox half of the framework's first metric set; the bus half is in\n * `@entifix/amqp`.\n *\n * It lives beside the relay that samples it rather than in any one service,\n * because three slices now own an outbox — `catalog`, `order` and `payment` —\n * and the warning below is exactly why a copy per service is not an option: an\n * Effect metric is keyed on its **description**, so three hand-maintained\n * definitions of `outbox_pending_entries` are three series the moment one\n * wording drifts, and a dashboard would go quiet without failing anything.\n *\n * ⚠️ The metric objects are **exported so a reader uses the same instance**. An\n * Effect metric's registry key includes its description, so rebuilding one by\n * name without the description addresses a different series that is permanently\n * zero — a silent way to write a query against nothing.\n *\n * These are gauges rather than counters because they describe a *backlog*: the\n * question is how many are waiting right now, not how many there have ever\n * been. They are sampled by the two daemons that already run on an interval, so\n * nothing new is scheduled to produce them.\n *\n * ⚠️ **A dimensionless gauge reaches Prometheus with a `_ratio` suffix.** That\n * is the OTel exporter's convention for unit `1`, not a mistake here, so\n * `outbox_pending_entries` is queried as `outbox_pending_entries_ratio`.\n * Counters are unaffected. Where a metric has a real unit, tag it — see\n * {@link outboxOldestPendingAge}.\n */\n\n/** Unsent, un-quarantined entries, per database. */\nexport const outboxPending = Metric.gauge('outbox_pending_entries', {\n description: 'Unsent, un-quarantined outbox entries, by database.',\n});\n\n/**\n * Age in seconds of the oldest unsent entry, per database.\n *\n * **The metric that makes a stuck relay visible.** Quarantine gave the relay a\n * ceiling, so an entry that can never publish is quarantined and skipped rather\n * than blocking the head of the line forever — but that is reported only as a\n * log line, so how far behind the outbox has fallen is otherwise unanswerable.\n * A depth that is flat and an age that climbs is the signature of a relay whose\n * head has stopped moving.\n */\nexport const outboxOldestPendingAge: Metric.Gauge<number> = Metric.gauge(\n 'outbox_oldest_pending_age',\n {\n description:\n 'Age of the oldest unsent outbox entry, by database. Zero when ' +\n 'the outbox is empty.',\n },\n).pipe(\n // ⚠️ **The unit is carried as a tag, and that is the only way to set it.**\n // `@effect/opentelemetry`'s producer reads `tags.unit ?? tags.time_unit ??\n // '1'`, so a gauge with no `unit` tag is exported as dimensionless — and the\n // Prometheus exporter then appends `_ratio` to a dimensionless gauge's name.\n // Measured: this series arrived as `outbox_oldest_pending_age_seconds_ratio`,\n // a duration announcing itself as a ratio. Tagging it makes the exporter name\n // it `_seconds`, which is why the name above no longer carries that suffix\n // itself. The cost is a constant `unit` label, because the producer builds the\n // datapoint attributes from the same tag set it reads the unit from.\n Metric.withAttributes({ unit: 's' }),\n);\n\n/** Entries past the ceiling, which nothing retries and nothing deletes. */\nexport const outboxQuarantined = Metric.gauge('outbox_quarantined_entries', {\n description: 'Quarantined outbox entries, by database.',\n});\n\n/** Record one outbox's depth and age. */\nexport const recordOutboxStats = (database: string, stats: OutboxStats) => {\n const tagged = (metric: Metric.Gauge<number>) =>\n Metric.withAttributes(metric, { database });\n\n // Zero when nothing is waiting. The alternative — not reporting the series —\n // reads on most dashboards as \"no data\", which is indistinguishable from the\n // exporter having broken at exactly the moment a healthy relay looks idle.\n const ageSeconds =\n stats.oldestPendingAt === undefined\n ? 0\n : Math.max(0, (Date.now() - Date.parse(stats.oldestPendingAt)) / 1000);\n\n return Metric.update(tagged(outboxPending), stats.pending).pipe(\n Effect.andThen(Metric.update(tagged(outboxOldestPendingAge), ageSeconds)),\n Effect.andThen(Metric.update(tagged(outboxQuarantined), stats.quarantined)),\n );\n};\n"],"names":["Effect","Metric","outboxPending","gauge","description","outboxOldestPendingAge","pipe","withAttributes","unit","outboxQuarantined","recordOutboxStats","database","stats","tagged","metric","ageSeconds","oldestPendingAt","undefined","Math","max","Date","now","parse","update","pending","andTh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ration, Effect } from 'effect';
3
+ import { type Outbox, type OutboxStats } from '../contracts/outbox.js';
4
+ import type { EventBus } from '../ports/event-bus.js';
5
+ export declare const SWEEP_INTERVAL: Duration.Duration;
6
+ /** Entries drained per pass, per database. */
7
+ export declare const BATCH = 100;
8
+ /**
9
+ * What a relay pass did, for the host to log
10
+ * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).
11
+ *
12
+ * The relay decides nothing about level or sink: it says what happened and the
13
+ * fork site that started it — the slice's shell — decides how loud that is. A
14
+ * `failure` is whatever the store or the bus failed with; a typed one carries
15
+ * its code and category for the log line.
16
+ */
17
+ export type RelayOutcome = {
18
+ readonly _tag: 'drained';
19
+ readonly database: string;
20
+ readonly sent: number;
21
+ } | {
22
+ readonly _tag: 'quarantined';
23
+ readonly database: string;
24
+ readonly eventId: string;
25
+ readonly eventName: string;
26
+ readonly attempts: number;
27
+ readonly code: string;
28
+ readonly reason: string;
29
+ } | {
30
+ readonly _tag: 'sweepFailed';
31
+ readonly database?: string;
32
+ readonly failure: unknown;
33
+ } | {
34
+ readonly _tag: 'drainFailed';
35
+ readonly database: string;
36
+ readonly failure: unknown;
37
+ };
38
+ /** Where a relay's outcomes go. The host's fork site supplies it. */
39
+ export type RelayOutcomeSink = (outcome: RelayOutcome) => Effect.Effect<void>;
40
+ /**
41
+ * Hears nothing. The default only so a spec can start a relay without one —
42
+ * a host that passes no sink has a relay nobody can watch.
43
+ */
44
+ export declare const ignoreRelayOutcome: RelayOutcomeSink;
45
+ /** What {@link drainOutbox} needs beyond the ports it publishes through. */
46
+ export interface DrainOptions {
47
+ readonly maxAttempts: number;
48
+ /** The database being drained; carried so a quarantine log names it. */
49
+ readonly database: string;
50
+ /** Where the pass reports what it did; see {@link RelayOutcome}. */
51
+ readonly onOutcome?: RelayOutcomeSink;
52
+ }
53
+ /**
54
+ * Publish one batch of pending entries, oldest first, **in order within each
55
+ * aggregate** ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)),
56
+ * and answer how many went.
57
+ *
58
+ * - A **still-deliverable** failure holds back the rest of its own aggregate
59
+ * for this pass, which is what stops a terminal event overtaking the
60
+ * `accepted` of the same transaction — and only its own: every other
61
+ * aggregate keeps draining.
62
+ * - A **quarantined** failure moves on. An entry that can never publish must
63
+ * not hold its aggregate forever, and a consumer discards whatever older
64
+ * version arrives after a newer one anyway.
65
+ */
66
+ export declare const drainOutbox: (outbox: Outbox, bus: EventBus, options: DrainOptions) => Effect.Effect<number, import("@entifix/core").StoreFailure, never>;
67
+ /**
68
+ * Sample a sweep's depth and age.
69
+ *
70
+ * Defaults to {@link recordOutboxStats}, and a caller overrides it only to
71
+ * assert what was sampled. There is no "no sink" option on purpose: an outbox
72
+ * whose depth nothing reports is the failure the gauges exist to make visible.
73
+ */
74
+ export type OutboxStatsSink = (database: string, stats: OutboxStats) => Effect.Effect<void>;
75
+ /**
76
+ * Drain the one database this service owns, then sample its depth.
77
+ *
78
+ * The single-database counterpart to `startTenantOutboxRelay`. A
79
+ * platform-plane store is one named database, so there is nothing to enumerate
80
+ * and `listDatabases` — which needs a `MongoClient` and cluster-wide rights —
81
+ * never comes into it.
82
+ *
83
+ * Stats are sampled **after** the drain, so the gauge reports what is still
84
+ * waiting rather than what was waiting when the pass began.
85
+ *
86
+ * Every failure is caught and reported as `sweepFailed`. This runs inside
87
+ * `Effect.forever`, and an error that escapes ends the daemon silently — a
88
+ * relay that stopped is indistinguishable from a relay with nothing to do.
89
+ */
90
+ export declare const sweepOutbox: (outbox: Outbox, bus: EventBus, options: DrainOptions & {
91
+ readonly onStats?: OutboxStatsSink;
92
+ }) => Effect.Effect<void, never, never>;
93
+ /**
94
+ * Runs `sweepOnce` every {@link SWEEP_INTERVAL}, and once more on the way out.
95
+ *
96
+ * Interrupting the daemon before that last pass is what stops two sweeps
97
+ * publishing the same entry; running the pass is what the hook is for — an
98
+ * event committed a moment before shutdown would otherwise wait out the next
99
+ * process's whole interval.
100
+ */
101
+ export declare const runRelayDaemon: (sweepOnce: Effect.Effect<void>) => Effect.Effect<void, never, ShutdownRegistryTag>;
102
+ //# sourceMappingURL=outbox-relay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbox-relay.d.ts","sourceRoot":"","sources":["../../src/engine/outbox-relay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAiB,MAAM,QAAQ,CAAC;AAEzD,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,WAAW,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AActD,eAAO,MAAM,cAAc,mBAAuB,CAAC;AACnD,8CAA8C;AAC9C,eAAO,MAAM,KAAK,MAAM,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GACpB;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEN,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAAoC,CAAC;AAEtE,4EAA4E;AAC5E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;CACvC;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,KAAK,QAAQ,EACb,SAAS,YAAY,uEA6CnB,CAAC;AAEL;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,WAAW,KACf,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAEzB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,KAAK,QAAQ,EACb,SAAS,YAAY,GAAG;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,CAAA;CAAE,sCAc7D,CAAC;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,oDAazD,CAAC"}
@@ -0,0 +1,111 @@
1
+ import { ShutdownRegistryTag } from '@entifix/business';
2
+ import { Duration, Effect, Fiber, Result } from 'effect';
3
+ import { aggregateKey } from '../contracts/outbox.js';
4
+ import { recordOutboxStats } from './outbox-metrics.js';
5
+ /** How often the sweep looks for entries the fast path did not carry. */ /**
6
+ * What an outbox entry records as the reason its publish failed: the failure's
7
+ * own message, or its code when it carries none — never empty, because an
8
+ * operator reading a quarantined entry has nothing else to go on.
9
+ */ const failureText = (failure)=>failure.message === '' ? failure.code : failure.message;
10
+ export const SWEEP_INTERVAL = Duration.seconds(15);
11
+ /** Entries drained per pass, per database. */ export const BATCH = 100;
12
+ /**
13
+ * Hears nothing. The default only so a spec can start a relay without one —
14
+ * a host that passes no sink has a relay nobody can watch.
15
+ */ export const ignoreRelayOutcome = ()=>Effect.void;
16
+ /**
17
+ * Publish one batch of pending entries, oldest first, **in order within each
18
+ * aggregate** ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)),
19
+ * and answer how many went.
20
+ *
21
+ * - A **still-deliverable** failure holds back the rest of its own aggregate
22
+ * for this pass, which is what stops a terminal event overtaking the
23
+ * `accepted` of the same transaction — and only its own: every other
24
+ * aggregate keeps draining.
25
+ * - A **quarantined** failure moves on. An entry that can never publish must
26
+ * not hold its aggregate forever, and a consumer discards whatever older
27
+ * version arrives after a newer one anyway.
28
+ */ export const drainOutbox = (outbox, bus, options)=>Effect.gen(function*() {
29
+ var _options_onOutcome;
30
+ const entries = yield* outbox.pending(BATCH);
31
+ const held = new Set();
32
+ let sent = 0;
33
+ const report = (_options_onOutcome = options.onOutcome) != null ? _options_onOutcome : ignoreRelayOutcome;
34
+ for (const entry of entries){
35
+ const key = aggregateKey(entry.aggregate);
36
+ if (held.has(key)) continue;
37
+ const outcome = yield* Effect.result(bus.publish(entry.event));
38
+ if (Result.isFailure(outcome)) {
39
+ const attempts = entry.attempts + 1;
40
+ const quarantine = attempts >= options.maxAttempts;
41
+ yield* outbox.recordFailure(entry, failureText(outcome.failure), quarantine);
42
+ if (!quarantine) {
43
+ held.add(key);
44
+ continue;
45
+ }
46
+ yield* report({
47
+ _tag: 'quarantined',
48
+ database: options.database,
49
+ eventId: entry.eventId,
50
+ eventName: entry.event.name,
51
+ attempts,
52
+ code: outcome.failure.code,
53
+ reason: failureText(outcome.failure)
54
+ });
55
+ continue;
56
+ }
57
+ yield* outbox.markSent(entry);
58
+ sent += 1;
59
+ }
60
+ yield* report({
61
+ _tag: 'drained',
62
+ database: options.database,
63
+ sent
64
+ });
65
+ return sent;
66
+ });
67
+ /**
68
+ * Drain the one database this service owns, then sample its depth.
69
+ *
70
+ * The single-database counterpart to `startTenantOutboxRelay`. A
71
+ * platform-plane store is one named database, so there is nothing to enumerate
72
+ * and `listDatabases` — which needs a `MongoClient` and cluster-wide rights —
73
+ * never comes into it.
74
+ *
75
+ * Stats are sampled **after** the drain, so the gauge reports what is still
76
+ * waiting rather than what was waiting when the pass began.
77
+ *
78
+ * Every failure is caught and reported as `sweepFailed`. This runs inside
79
+ * `Effect.forever`, and an error that escapes ends the daemon silently — a
80
+ * relay that stopped is indistinguishable from a relay with nothing to do.
81
+ */ export const sweepOutbox = (outbox, bus, options)=>Effect.gen(function*() {
82
+ var _options_onStats;
83
+ yield* drainOutbox(outbox, bus, options);
84
+ const sink = (_options_onStats = options.onStats) != null ? _options_onStats : recordOutboxStats;
85
+ yield* sink(options.database, (yield* outbox.stats()));
86
+ }).pipe(Effect.catch((failure)=>{
87
+ var _options_onOutcome;
88
+ return ((_options_onOutcome = options.onOutcome) != null ? _options_onOutcome : ignoreRelayOutcome)({
89
+ _tag: 'sweepFailed',
90
+ database: options.database,
91
+ failure
92
+ });
93
+ }));
94
+ /**
95
+ * Runs `sweepOnce` every {@link SWEEP_INTERVAL}, and once more on the way out.
96
+ *
97
+ * Interrupting the daemon before that last pass is what stops two sweeps
98
+ * publishing the same entry; running the pass is what the hook is for — an
99
+ * event committed a moment before shutdown would otherwise wait out the next
100
+ * process's whole interval.
101
+ */ export const runRelayDaemon = (sweepOnce)=>Effect.gen(function*() {
102
+ const shutdown = yield* ShutdownRegistryTag;
103
+ const daemon = yield* Effect.forkDetach(sweepOnce.pipe(Effect.delay(SWEEP_INTERVAL), Effect.forever));
104
+ yield* shutdown.register({
105
+ name: 'outbox-relay',
106
+ phase: 'flush',
107
+ run: Fiber.interrupt(daemon).pipe(Effect.andThen(sweepOnce))
108
+ });
109
+ });
110
+
111
+ //# sourceMappingURL=outbox-relay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/engine/outbox-relay.ts"],"sourcesContent":["import { ShutdownRegistryTag } from '@entifix/business';\nimport { Duration, Effect, Fiber, Result } from 'effect';\n\nimport {\n aggregateKey,\n type Outbox,\n type OutboxStats,\n} from '../contracts/outbox.js';\nimport type { EventBus } from '../ports/event-bus.js';\nimport { recordOutboxStats } from './outbox-metrics.js';\n\n/** How often the sweep looks for entries the fast path did not carry. */\n/**\n * What an outbox entry records as the reason its publish failed: the failure's\n * own message, or its code when it carries none — never empty, because an\n * operator reading a quarantined entry has nothing else to go on.\n */\nconst failureText = (failure: {\n readonly message: string;\n readonly code: string;\n}) => (failure.message === '' ? failure.code : failure.message);\n\nexport const SWEEP_INTERVAL = Duration.seconds(15);\n/** Entries drained per pass, per database. */\nexport const BATCH = 100;\n\n/**\n * What a relay pass did, for the host to log\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n *\n * The relay decides nothing about level or sink: it says what happened and the\n * fork site that started it — the slice's shell — decides how loud that is. A\n * `failure` is whatever the store or the bus failed with; a typed one carries\n * its code and category for the log line.\n */\nexport type RelayOutcome =\n | {\n readonly _tag: 'drained';\n readonly database: string;\n readonly sent: number;\n }\n | {\n readonly _tag: 'quarantined';\n readonly database: string;\n readonly eventId: string;\n readonly eventName: string;\n readonly attempts: number;\n readonly code: string;\n readonly reason: string;\n }\n | {\n readonly _tag: 'sweepFailed';\n readonly database?: string;\n readonly failure: unknown;\n }\n | {\n readonly _tag: 'drainFailed';\n readonly database: string;\n readonly failure: unknown;\n };\n\n/** Where a relay's outcomes go. The host's fork site supplies it. */\nexport type RelayOutcomeSink = (outcome: RelayOutcome) => Effect.Effect<void>;\n\n/**\n * Hears nothing. The default only so a spec can start a relay without one —\n * a host that passes no sink has a relay nobody can watch.\n */\nexport const ignoreRelayOutcome: RelayOutcomeSink = () => Effect.void;\n\n/** What {@link drainOutbox} needs beyond the ports it publishes through. */\nexport interface DrainOptions {\n readonly maxAttempts: number;\n /** The database being drained; carried so a quarantine log names it. */\n readonly database: string;\n /** Where the pass reports what it did; see {@link RelayOutcome}. */\n readonly onOutcome?: RelayOutcomeSink;\n}\n\n/**\n * Publish one batch of pending entries, oldest first, **in order within each\n * aggregate** ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)),\n * and answer how many went.\n *\n * - A **still-deliverable** failure holds back the rest of its own aggregate\n * for this pass, which is what stops a terminal event overtaking the\n * `accepted` of the same transaction — and only its own: every other\n * aggregate keeps draining.\n * - A **quarantined** failure moves on. An entry that can never publish must\n * not hold its aggregate forever, and a consumer discards whatever older\n * version arrives after a newer one anyway.\n */\nexport const drainOutbox = (\n outbox: Outbox,\n bus: EventBus,\n options: DrainOptions,\n) =>\n Effect.gen(function* () {\n const entries = yield* outbox.pending(BATCH);\n const held = new Set<string>();\n let sent = 0;\n const report = options.onOutcome ?? ignoreRelayOutcome;\n for (const entry of entries) {\n const key = aggregateKey(entry.aggregate);\n if (held.has(key)) continue;\n\n const outcome = yield* Effect.result(bus.publish(entry.event));\n\n if (Result.isFailure(outcome)) {\n const attempts = entry.attempts + 1;\n const quarantine = attempts >= options.maxAttempts;\n\n yield* outbox.recordFailure(\n entry,\n failureText(outcome.failure),\n quarantine,\n );\n\n if (!quarantine) {\n held.add(key);\n continue;\n }\n\n yield* report({\n _tag: 'quarantined',\n database: options.database,\n eventId: entry.eventId,\n eventName: entry.event.name,\n attempts,\n code: outcome.failure.code,\n reason: failureText(outcome.failure),\n });\n continue;\n }\n\n yield* outbox.markSent(entry);\n sent += 1;\n }\n yield* report({ _tag: 'drained', database: options.database, sent });\n return sent;\n });\n\n/**\n * Sample a sweep's depth and age.\n *\n * Defaults to {@link recordOutboxStats}, and a caller overrides it only to\n * assert what was sampled. There is no \"no sink\" option on purpose: an outbox\n * whose depth nothing reports is the failure the gauges exist to make visible.\n */\nexport type OutboxStatsSink = (\n database: string,\n stats: OutboxStats,\n) => Effect.Effect<void>;\n\n/**\n * Drain the one database this service owns, then sample its depth.\n *\n * The single-database counterpart to `startTenantOutboxRelay`. A\n * platform-plane store is one named database, so there is nothing to enumerate\n * and `listDatabases` — which needs a `MongoClient` and cluster-wide rights —\n * never comes into it.\n *\n * Stats are sampled **after** the drain, so the gauge reports what is still\n * waiting rather than what was waiting when the pass began.\n *\n * Every failure is caught and reported as `sweepFailed`. This runs inside\n * `Effect.forever`, and an error that escapes ends the daemon silently — a\n * relay that stopped is indistinguishable from a relay with nothing to do.\n */\nexport const sweepOutbox = (\n outbox: Outbox,\n bus: EventBus,\n options: DrainOptions & { readonly onStats?: OutboxStatsSink },\n) =>\n Effect.gen(function* () {\n yield* drainOutbox(outbox, bus, options);\n const sink = options.onStats ?? recordOutboxStats;\n yield* sink(options.database, yield* outbox.stats());\n }).pipe(\n Effect.catch(failure =>\n (options.onOutcome ?? ignoreRelayOutcome)({\n _tag: 'sweepFailed',\n database: options.database,\n failure,\n }),\n ),\n );\n\n/**\n * Runs `sweepOnce` every {@link SWEEP_INTERVAL}, and once more on the way out.\n *\n * Interrupting the daemon before that last pass is what stops two sweeps\n * publishing the same entry; running the pass is what the hook is for — an\n * event committed a moment before shutdown would otherwise wait out the next\n * process's whole interval.\n */\nexport const runRelayDaemon = (sweepOnce: Effect.Effect<void>) =>\n Effect.gen(function* () {\n const shutdown = yield* ShutdownRegistryTag;\n\n const daemon = yield* Effect.forkDetach(\n sweepOnce.pipe(Effect.delay(SWEEP_INTERVAL), Effect.forever),\n );\n\n yield* shutdown.register({\n name: 'outbox-relay',\n phase: 'flush',\n run: Fiber.interrupt(daemon).pipe(Effect.andThen(sweepOnce)),\n });\n });\n"],"names":["ShutdownRegistryTag","Duration","Effect","Fiber","Result","aggregateKey","recordOutboxStats","failureText","failure","message","code","SWEEP_INTERVAL","seconds","BATCH","ignoreRelayOutcome","void","drainOutbox","outbox","bus","options","gen","entries","pending","held","Set","sent","report","onOutcome","entry","key","aggregate","has","outcome","result","publish","event","isFailure","attempts","quarantine","maxAttempts","recordFailure","add","_tag","database","eventId","eventName","name","reason","markSent","sweepOutbox","sink","onStats","stats","pipe","catch","runRelayDaemon","sweepOnce","shutdown","daemon","forkDetach","delay","forever","register","phase","run","interrupt","andThen"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,oBAAoB;AACxD,SAASC,QAAQ,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,QAAQ,SAAS;AAEzD,SACEC,YAAY,QAGP,yBAAyB;AAEhC,SAASC,iBAAiB,QAAQ,sBAAsB;AAExD,uEAAuE,GACvE;;;;CAIC,GACD,MAAMC,cAAc,CAACC,UAGdA,QAAQC,OAAO,KAAK,KAAKD,QAAQE,IAAI,GAAGF,QAAQC,OAAO;AAE9D,OAAO,MAAME,iBAAiBV,SAASW,OAAO,CAAC,IAAI;AACnD,4CAA4C,GAC5C,OAAO,MAAMC,QAAQ,IAAI;AAwCzB;;;CAGC,GACD,OAAO,MAAMC,qBAAuC,IAAMZ,OAAOa,IAAI,CAAC;AAWtE;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,cAAc,CACzBC,QACAC,KACAC,UAEAjB,OAAOkB,GAAG,CAAC;YAIMD;QAHf,MAAME,UAAU,OAAOJ,OAAOK,OAAO,CAACT;QACtC,MAAMU,OAAO,IAAIC;QACjB,IAAIC,OAAO;QACX,MAAMC,UAASP,qBAAAA,QAAQQ,SAAS,YAAjBR,qBAAqBL;QACpC,KAAK,MAAMc,SAASP,QAAS;YAC3B,MAAMQ,MAAMxB,aAAauB,MAAME,SAAS;YACxC,IAAIP,KAAKQ,GAAG,CAACF,MAAM;YAEnB,MAAMG,UAAU,OAAO9B,OAAO+B,MAAM,CAACf,IAAIgB,OAAO,CAACN,MAAM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OkB,GAAG,CAAC;QACT,MAAMqC,WAAW,OAAOzD;QAExB,MAAM0D,SAAS,OAAOxD,OAAOyD,UAAU,CACrCH,UAAUH,IAAI,CAACnD,OAAO0D,KAAK,CAACjD,iBAAiBT,OAAO2D,OAAO;QAG7D,OAAOJ,SAASK,QAAQ,CAAC;YACvBhB,MAAM;YACNiB,OAAO;YACPC,KAAK7D,MAAM8D,SAAS,CAACP,QAAQL,IAAI,CAACnD,OAAOgE,OAAO,CAACV;QACnD;IACF,GAAG"}
@@ -1,5 +1,5 @@
1
1
  import { Effect } from 'effect';
2
- import { TransactionOutboxTag } from '../contracts/outbox.js';
2
+ import { OutboxTag } from '../contracts/outbox.js';
3
3
  import { CommandTag } from '../mixins/transaction-mixins.js';
4
4
  import { EventSourceTag } from '../ports/event-source.js';
5
5
  import type { LockHandle } from '../ports/lock-service.js';
@@ -14,7 +14,7 @@ import type { LockHandle } from '../ports/lock-service.js';
14
14
  * locks never leak on a rollback path.
15
15
  *
16
16
  * **The engine never publishes.** Every event it produces goes to the
17
- * {@link TransactionOutbox}, and a relay carries the outbox to the broker. That
17
+ * {@link Outbox}, and a relay carries the outbox to the broker. That
18
18
  * is the whole fix for the dual write: an event that only ever existed in a
19
19
  * `bus.publish` call between two Mongo writes is lost when the broker is down,
20
20
  * and the transaction is then mislabelled `STALE` despite having succeeded.
@@ -35,7 +35,7 @@ export declare function acceptTransaction(): Effect.Effect<{
35
35
  } | {
36
36
  readonly status: "accepted";
37
37
  readonly handles: readonly LockHandle[];
38
- }, import("@entifix/core").EntifixError | import("@entifix/core").StoreFailure, import("../index.js").TransactionHandlerTag | TransactionOutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
38
+ }, import("@entifix/core").EntifixError | import("@entifix/core").StoreFailure, import("../index.js").TransactionHandlerTag | OutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
39
39
  /** What {@link acceptTransaction} decided — a fresh command, or a replay. */
40
40
  export type AcceptOutcome = Effect.Success<ReturnType<typeof acceptTransaction>>;
41
41
  /**
@@ -51,5 +51,5 @@ export type AcceptOutcome = Effect.Success<ReturnType<typeof acceptTransaction>>
51
51
  * The failure arm does record, because there is no state change left to be
52
52
  * atomic with: the rollback has already undone it.
53
53
  */
54
- export declare function completeTransaction(handles: readonly LockHandle[]): Effect.Effect<void, never, import("../index.js").TransactionHandlerTag | TransactionOutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
54
+ export declare function completeTransaction(handles: readonly LockHandle[]): Effect.Effect<void, never, import("../index.js").TransactionHandlerTag | OutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
55
55
  //# sourceMappingURL=run-transaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-transaction.d.ts","sourceRoot":"","sources":["../../src/engine/run-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACL,UAAU,EAGX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAS3D;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB;;;;;;yNAgBhC;AAED,6EAA6E;AAC7E,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CACxC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CACrC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,uKA2DjE"}
1
+ {"version":3,"file":"run-transaction.d.ts","sourceRoot":"","sources":["../../src/engine/run-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACL,UAAU,EAGX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAS3D;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB;;;;;;8MAgBhC;AAED,6EAA6E;AAC7E,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CACxC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CACrC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,4JA2DjE"}
@@ -1,6 +1,6 @@
1
1
  import { Effect } from 'effect';
2
2
  import { acceptedEvent, failedEvent } from '../contracts/event.js';
3
- import { TransactionOutboxTag } from '../contracts/outbox.js';
3
+ import { OutboxTag } from '../contracts/outbox.js';
4
4
  import { CommandTag, LockHandlesTag, OutcomeTag } from '../mixins/transaction-mixins.js';
5
5
  import { EventSourceTag } from '../ports/event-source.js';
6
6
  import { executeUCFactory, freeUCFactory, lockUCFactory, rollbackUCFactory, validateUCFactory } from '../use-case/facade.uc.js';
@@ -15,7 +15,7 @@ import { executeUCFactory, freeUCFactory, lockUCFactory, rollbackUCFactory, vali
15
15
  * locks never leak on a rollback path.
16
16
  *
17
17
  * **The engine never publishes.** Every event it produces goes to the
18
- * {@link TransactionOutbox}, and a relay carries the outbox to the broker. That
18
+ * {@link Outbox}, and a relay carries the outbox to the broker. That
19
19
  * is the whole fix for the dual write: an event that only ever existed in a
20
20
  * `bus.publish` call between two Mongo writes is lost when the broker is down,
21
21
  * and the transaction is then mislabelled `STALE` despite having succeeded.
@@ -31,7 +31,7 @@ import { executeUCFactory, freeUCFactory, lockUCFactory, rollbackUCFactory, vali
31
31
  */ export function acceptTransaction() {
32
32
  return Effect.gen(function*() {
33
33
  const command = yield* CommandTag;
34
- const outbox = yield* TransactionOutboxTag;
34
+ const outbox = yield* OutboxTag;
35
35
  const source = yield* EventSourceTag;
36
36
  yield* validateUCFactory();
37
37
  const claim = yield* outbox.enqueue(acceptedEvent(command, source));
@@ -62,7 +62,7 @@ import { executeUCFactory, freeUCFactory, lockUCFactory, rollbackUCFactory, vali
62
62
  */ export function completeTransaction(handles) {
63
63
  return Effect.gen(function*() {
64
64
  const command = yield* CommandTag;
65
- const outbox = yield* TransactionOutboxTag;
65
+ const outbox = yield* OutboxTag;
66
66
  const source = yield* EventSourceTag;
67
67
  const free = freeUCFactory().pipe(Effect.provideService(LockHandlesTag, handles), Effect.ignore);
68
68
  yield* executeUCFactory().pipe(Effect.matchEffect({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/engine/run-transaction.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport { acceptedEvent, failedEvent } from '../contracts/event.js';\nimport { TransactionOutboxTag } from '../contracts/outbox.js';\nimport {\n CommandTag,\n LockHandlesTag,\n OutcomeTag,\n} from '../mixins/transaction-mixins.js';\nimport { EventSourceTag } from '../ports/event-source.js';\nimport type { LockHandle } from '../ports/lock-service.js';\nimport {\n executeUCFactory,\n freeUCFactory,\n lockUCFactory,\n rollbackUCFactory,\n validateUCFactory,\n} from '../use-case/facade.uc.js';\n\n/**\n * The saga engine, split at the 202 boundary so validation/lock failures are\n * synchronous (mapped to `400`/`409`) while the write runs asynchronously:\n *\n * - {@link acceptTransaction} — validate -> claim -> lock. Runs before the\n * service answers `202`; its failures are the client's answer.\n * - {@link completeTransaction} — execute -> free, or rollback -> record\n * `failed` -> free. Forked after `202`; `free` always runs via `ensuring`, so\n * locks never leak on a rollback path.\n *\n * **The engine never publishes.** Every event it produces goes to the\n * {@link TransactionOutbox}, and a relay carries the outbox to the broker. That\n * is the whole fix for the dual write: an event that only ever existed in a\n * `bus.publish` call between two Mongo writes is lost when the broker is down,\n * and the transaction is then mislabelled `STALE` despite having succeeded.\n */\n\n/**\n * Accept phase (synchronous).\n *\n * The order is deliberate: validate, then **claim, then lock**. The claim is the\n * outbox insert for the `accepted` event, and its uniqueness on\n * the message id (`<transactionId>:<step>`) is what makes the client-generated\n * id an idempotency key — a replayed command is recognised here, before a lock is taken and\n * before any work is forked. Locking first would make a retry queue behind its\n * own original.\n */\nexport function acceptTransaction() {\n return Effect.gen(function* () {\n const command = yield* CommandTag;\n const outbox = yield* TransactionOutboxTag;\n const source = yield* EventSourceTag;\n\n yield* validateUCFactory();\n\n const claim = yield* outbox.enqueue(acceptedEvent(command, source));\n if (claim === 'duplicate') {\n return { status: 'duplicate' } as const;\n }\n\n const handles = yield* lockUCFactory();\n return { status: 'accepted', handles } as const;\n });\n}\n\n/** What {@link acceptTransaction} decided — a fresh command, or a replay. */\nexport type AcceptOutcome = Effect.Success<\n ReturnType<typeof acceptTransaction>\n>;\n\n/**\n * Execute phase (asynchronous continuation). Never leaks locks.\n *\n * The success arm records **nothing**: `execute` is contractually required to\n * have written the `completed` entry in the same storage transaction as its\n * state change, because only the handler holds the session that can make those\n * two writes one. Recording it here as well would reintroduce the dual write in\n * the opposite direction — an event announcing a write that may have rolled\n * back.\n *\n * The failure arm does record, because there is no state change left to be\n * atomic with: the rollback has already undone it.\n */\nexport function completeTransaction(handles: readonly LockHandle[]) {\n return Effect.gen(function* () {\n const command = yield* CommandTag;\n const outbox = yield* TransactionOutboxTag;\n const source = yield* EventSourceTag;\n\n const free = freeUCFactory().pipe(\n Effect.provideService(LockHandlesTag, handles),\n Effect.ignore,\n );\n\n yield* executeUCFactory().pipe(\n Effect.matchEffect({\n onSuccess: () => Effect.void,\n onFailure: error =>\n rollbackUCFactory().pipe(\n Effect.provideService(OutcomeTag, undefined),\n // The compensation's own failure is reported before it is\n // discarded. Discarding it is right — the client is polling for a\n // terminal state and must still get one, so the `failed` record\n // below is written either way — but until this line the error\n // reached nothing: not the record, whose `error` is `execute`'s,\n // and not the log. An operator reading `FAILED` then reasonably\n // concluded the write had been undone when it had not.\n //\n // Annotations rather than message arguments, matching the outbox\n // relay: they reach a sink as structured fields, so a stranded\n // transaction is queryable by its id instead of being parsed out of\n // a rendered string.\n //\n // That is true as of this change and was not before it. A service's\n // Effect→tooling logger bridge (`observability.ts`) dropped\n // `annotations` outright and matched Effect's level labels with the\n // wrong casing, so every annotated field was discarded and every\n // level arrived as INFO — measured in Loki while verifying this log.\n Effect.tapError(rollbackError =>\n Effect.logError('transaction rollback failed').pipe(\n Effect.annotateLogs({\n transactionId: command.transactionId,\n entity: command.entity,\n executeError: String(error),\n rollbackError: String(rollbackError),\n }),\n ),\n ),\n Effect.ignore,\n Effect.andThen(\n // Best-effort: the transaction already failed, and a store that\n // cannot take the failure record must not turn into an unhandled\n // defect in a forked daemon. The recovery sweep is what notices.\n Effect.ignore(\n outbox.enqueue(failedEvent(command, error, source)),\n ),\n ),\n ),\n }),\n Effect.ensuring(free),\n );\n });\n}\n"],"names":["Effect","acceptedEvent","failedEvent","TransactionOutboxTag","CommandTag","LockHandlesTag","OutcomeTag","EventSourceTag","executeUCFactory","freeUCFactory","lockUCFactory","rollbackUCFactory","validateUCFactory","acceptTransaction","gen","command","outbox","source","claim","enqueue","status","handles","completeTransaction","free","pipe","provideService","ignore","matchEffect","onSuccess","void","onFailure","error","undefined","tapError","rollbackError","logError","annotateLogs","transactionId","entity","executeError","String","andThen","ensuring"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,EAAEC,WAAW,QAAQ,wBAAwB;AACnE,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SACEC,UAAU,EACVC,cAAc,EACdC,UAAU,QACL,kCAAkC;AACzC,SAASC,cAAc,QAAQ,2BAA2B;AAE1D,SACEC,gBAAgB,EAChBC,aAAa,EACbC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QACZ,2BAA2B;AAElC;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;CASC,GACD,OAAO,SAAS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AQuB,MAAM;wBACtBC,cAAcC,OAAOT;wBACrBG,eAAeM,OAAON;oBACxB,MAGJlC,OAAO0B,MAAM,EACb1B,OAAOyC,OAAO,CACZ,gEAAgE;gBAChE,iEAAiE;gBACjE,iEAAiE;gBACjEzC,OAAO0B,MAAM,CACXV,OAAOG,OAAO,CAACjB,YAAYa,SAASgB,OAAOd;QAIrD,IACAjB,OAAO0C,QAAQ,CAACnB;IAEpB;AACF"}
1
+ {"version":3,"sources":["../../src/engine/run-transaction.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport { acceptedEvent, failedEvent } from '../contracts/event.js';\nimport { OutboxTag } from '../contracts/outbox.js';\nimport {\n CommandTag,\n LockHandlesTag,\n OutcomeTag,\n} from '../mixins/transaction-mixins.js';\nimport { EventSourceTag } from '../ports/event-source.js';\nimport type { LockHandle } from '../ports/lock-service.js';\nimport {\n executeUCFactory,\n freeUCFactory,\n lockUCFactory,\n rollbackUCFactory,\n validateUCFactory,\n} from '../use-case/facade.uc.js';\n\n/**\n * The saga engine, split at the 202 boundary so validation/lock failures are\n * synchronous (mapped to `400`/`409`) while the write runs asynchronously:\n *\n * - {@link acceptTransaction} — validate -> claim -> lock. Runs before the\n * service answers `202`; its failures are the client's answer.\n * - {@link completeTransaction} — execute -> free, or rollback -> record\n * `failed` -> free. Forked after `202`; `free` always runs via `ensuring`, so\n * locks never leak on a rollback path.\n *\n * **The engine never publishes.** Every event it produces goes to the\n * {@link Outbox}, and a relay carries the outbox to the broker. That\n * is the whole fix for the dual write: an event that only ever existed in a\n * `bus.publish` call between two Mongo writes is lost when the broker is down,\n * and the transaction is then mislabelled `STALE` despite having succeeded.\n */\n\n/**\n * Accept phase (synchronous).\n *\n * The order is deliberate: validate, then **claim, then lock**. The claim is the\n * outbox insert for the `accepted` event, and its uniqueness on\n * the message id (`<transactionId>:<step>`) is what makes the client-generated\n * id an idempotency key — a replayed command is recognised here, before a lock is taken and\n * before any work is forked. Locking first would make a retry queue behind its\n * own original.\n */\nexport function acceptTransaction() {\n return Effect.gen(function* () {\n const command = yield* CommandTag;\n const outbox = yield* OutboxTag;\n const source = yield* EventSourceTag;\n\n yield* validateUCFactory();\n\n const claim = yield* outbox.enqueue(acceptedEvent(command, source));\n if (claim === 'duplicate') {\n return { status: 'duplicate' } as const;\n }\n\n const handles = yield* lockUCFactory();\n return { status: 'accepted', handles } as const;\n });\n}\n\n/** What {@link acceptTransaction} decided — a fresh command, or a replay. */\nexport type AcceptOutcome = Effect.Success<\n ReturnType<typeof acceptTransaction>\n>;\n\n/**\n * Execute phase (asynchronous continuation). Never leaks locks.\n *\n * The success arm records **nothing**: `execute` is contractually required to\n * have written the `completed` entry in the same storage transaction as its\n * state change, because only the handler holds the session that can make those\n * two writes one. Recording it here as well would reintroduce the dual write in\n * the opposite direction — an event announcing a write that may have rolled\n * back.\n *\n * The failure arm does record, because there is no state change left to be\n * atomic with: the rollback has already undone it.\n */\nexport function completeTransaction(handles: readonly LockHandle[]) {\n return Effect.gen(function* () {\n const command = yield* CommandTag;\n const outbox = yield* OutboxTag;\n const source = yield* EventSourceTag;\n\n const free = freeUCFactory().pipe(\n Effect.provideService(LockHandlesTag, handles),\n Effect.ignore,\n );\n\n yield* executeUCFactory().pipe(\n Effect.matchEffect({\n onSuccess: () => Effect.void,\n onFailure: error =>\n rollbackUCFactory().pipe(\n Effect.provideService(OutcomeTag, undefined),\n // The compensation's own failure is reported before it is\n // discarded. Discarding it is right — the client is polling for a\n // terminal state and must still get one, so the `failed` record\n // below is written either way — but until this line the error\n // reached nothing: not the record, whose `error` is `execute`'s,\n // and not the log. An operator reading `FAILED` then reasonably\n // concluded the write had been undone when it had not.\n //\n // Annotations rather than message arguments, matching the outbox\n // relay: they reach a sink as structured fields, so a stranded\n // transaction is queryable by its id instead of being parsed out of\n // a rendered string.\n //\n // That is true as of this change and was not before it. A service's\n // Effect→tooling logger bridge (`observability.ts`) dropped\n // `annotations` outright and matched Effect's level labels with the\n // wrong casing, so every annotated field was discarded and every\n // level arrived as INFO — measured in Loki while verifying this log.\n Effect.tapError(rollbackError =>\n Effect.logError('transaction rollback failed').pipe(\n Effect.annotateLogs({\n transactionId: command.transactionId,\n entity: command.entity,\n executeError: String(error),\n rollbackError: String(rollbackError),\n }),\n ),\n ),\n Effect.ignore,\n Effect.andThen(\n // Best-effort: the transaction already failed, and a store that\n // cannot take the failure record must not turn into an unhandled\n // defect in a forked daemon. The recovery sweep is what notices.\n Effect.ignore(\n outbox.enqueue(failedEvent(command, error, source)),\n ),\n ),\n ),\n }),\n Effect.ensuring(free),\n );\n });\n}\n"],"names":["Effect","acceptedEvent","failedEvent","OutboxTag","CommandTag","LockHandlesTag","OutcomeTag","EventSourceTag","executeUCFactory","freeUCFactory","lockUCFactory","rollbackUCFactory","validateUCFactory","acceptTransaction","gen","command","outbox","source","claim","enqueue","status","handles","completeTransaction","free","pipe","provideService","ignore","matchEffect","onSuccess","void","onFailure","error","undefined","tapError","rollbackError","logError","annotateLogs","transactionId","entity","executeError","String","andThen","ensuring"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,EAAEC,WAAW,QAAQ,wBAAwB;AACnE,SAASC,SAAS,QAAQ,yBAAyB;AACnD,SACEC,UAAU,EACVC,cAAc,EACdC,UAAU,QACL,kCAAkC;AACzC,SAASC,cAAc,QAAQ,2BAA2B;AAE1D,SACEC,gBAAgB,EAChBC,aAAa,EACbC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QACZ,2BAA2B;AAElC;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;CASC,GACD,OAAO,SAASC;IACd,OAAOb,OAAOc,GAAG,CAAC;QAChB,MAAMC,UAAU,OAAOX;QACvB,MAAMY,SAAS,OAAOb;QACtB,MAAMc,SAAS,OAAOV;QAEtB,OAAOK;QAEP,MAAMM,QAAQ,OAAOF,OAAOG,OAAO,CAAClB,cAAcc,SAASE;QAC3D,IAAIC,UAAU,aAAa;YACzB,OAAO;gBAAEE,Q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jB,OAAO0C,QAAQ,CAACnB;IAEpB;AACF"}
package/dist/index.d.ts CHANGED
@@ -1,14 +1,21 @@
1
1
  export * from './contracts/command.js';
2
2
  export * from './contracts/event.js';
3
+ export * from './contracts/flow-capability.js';
4
+ export * from './contracts/flow-messages.js';
3
5
  export * from './contracts/inbox.js';
6
+ export * from './contracts/messages.js';
4
7
  export * from './contracts/outbox.js';
5
8
  export * from './contracts/record.js';
6
9
  export * from './contracts/saga-definition.js';
7
10
  export * from './contracts/unit-of-work.js';
8
11
  export * from './mixins/transaction-mixins.js';
12
+ export * from './ports/bulkhead.js';
13
+ export * from './ports/circuit-breaker.js';
9
14
  export * from './ports/event-bus.js';
10
15
  export * from './ports/event-source.js';
16
+ export * from './ports/flow-engine.js';
11
17
  export * from './ports/lock-service.js';
18
+ export * from './ports/participant-client.js';
12
19
  export * from './ports/retry-budget.js';
13
20
  export * from './ports/saga-dispatcher.js';
14
21
  export * from './ports/saga-store.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index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