@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
package/dist/index.js 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';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './contracts/command.js';\nexport * from './contracts/event.js';\nexport * from './contracts/inbox.js';\nexport * from './contracts/outbox.js';\nexport * from './contracts/record.js';\nexport * from './contracts/saga-definition.js';\nexport * from './contracts/unit-of-work.js';\nexport * from './mixins/transaction-mixins.js';\nexport * from './ports/event-bus.js';\nexport * from './ports/event-source.js';\nexport * from './ports/lock-service.js';\nexport * from './ports/retry-budget.js';\nexport * from './ports/saga-dispatcher.js';\nexport * from './ports/saga-store.js';\nexport * from './ports/sequence-service.js';\nexport * from './ports/transaction-handler.js';\nexport * from './ports/transaction-sink.js';\nexport * from './ports/transaction-stream-hub.js';\nexport * from './reactions/on.js';\nexport * from './use-case/facade.uc.js';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB;AACvC,cAAc,uBAAuB;AACrC,cAAc,uBAAuB;AACrC,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,oCAAoC;AAClD,cAAc,oBAAoB;AAClC,cAAc,0BAA0B"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './contracts/command.js';\nexport * from './contracts/event.js';\nexport * from './contracts/flow-capability.js';\nexport * from './contracts/flow-messages.js';\nexport * from './contracts/inbox.js';\nexport * from './contracts/messages.js';\nexport * from './contracts/outbox.js';\nexport * from './contracts/record.js';\nexport * from './contracts/saga-definition.js';\nexport * from './contracts/unit-of-work.js';\nexport * from './mixins/transaction-mixins.js';\nexport * from './ports/bulkhead.js';\nexport * from './ports/circuit-breaker.js';\nexport * from './ports/event-bus.js';\nexport * from './ports/event-source.js';\nexport * from './ports/flow-engine.js';\nexport * from './ports/lock-service.js';\nexport * from './ports/participant-client.js';\nexport * from './ports/retry-budget.js';\nexport * from './ports/saga-dispatcher.js';\nexport * from './ports/saga-store.js';\nexport * from './ports/sequence-service.js';\nexport * from './ports/transaction-handler.js';\nexport * from './ports/transaction-sink.js';\nexport * from './ports/transaction-stream-hub.js';\nexport * from './reactions/on.js';\nexport * from './use-case/facade.uc.js';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB;AACvC,cAAc,uBAAuB;AACrC,cAAc,iCAAiC;AAC/C,cAAc,+BAA+B;AAC7C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,sBAAsB;AACpC,cAAc,6BAA6B;AAC3C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,gCAAgC;AAC9C,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,oCAAoC;AAClD,cAAc,oBAAoB;AAClC,cAAc,0BAA0B"}
@@ -0,0 +1,28 @@
1
+ import { Context, type Effect, Metric, Schema } from 'effect';
2
+ declare const BulkheadFull_base: Schema.Class<BulkheadFull, Schema.TaggedStruct<"BulkheadFull", {
3
+ readonly dependency: Schema.String;
4
+ }>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"bulkheadFull", "exhausted">>;
5
+ /**
6
+ * The bulkhead for a key had no permit free. `exhausted`, and it stops every
7
+ * retry above it: the calls already in flight are the ones to wait for.
8
+ */
9
+ export declare class BulkheadFull extends BulkheadFull_base {
10
+ }
11
+ /**
12
+ * Bounds how many calls to one dependency run at once, per key
13
+ * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)),
14
+ * so a slow participant holds a bounded share of the process rather than all
15
+ * of it. A call that finds no permit is refused at once, never queued.
16
+ */
17
+ export interface Bulkhead {
18
+ readonly withPermit: (key: string) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | BulkheadFull, R>;
19
+ /** Permits taken now. */
20
+ readonly inUse: (key: string) => Effect.Effect<number>;
21
+ }
22
+ declare const BulkheadTag_base: Context.ServiceClass<BulkheadTag, "@entifix/transactions/Bulkhead", Bulkhead>;
23
+ export declare class BulkheadTag extends BulkheadTag_base {
24
+ }
25
+ /** Permits in use, by key. */
26
+ export declare const bulkheadInUse: Metric.Gauge<number>;
27
+ export {};
28
+ //# sourceMappingURL=bulkhead.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bulkhead.d.ts","sourceRoot":"","sources":["../../src/ports/bulkhead.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;AAE9D;;;GAGG;AACH,qBAAa,YAAa,SAAQ,iBAQjC;CAAG;AAEJ;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,UAAU,EAAE,CACnB,GAAG,EAAE,MAAM,KACR,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACX,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC;IAC3C,yBAAyB;IACzB,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CACxD;;AAED,qBAAa,WAAY,SAAQ,gBAEhC;CAAG;AAEJ,8BAA8B;AAC9B,eAAO,MAAM,aAAa,sBAExB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { Failure } from '@entifix/core';
2
+ import { Context, Metric, Schema } from 'effect';
3
+ /**
4
+ * The bulkhead for a key had no permit free. `exhausted`, and it stops every
5
+ * retry above it: the calls already in flight are the ones to wait for.
6
+ */ export class BulkheadFull extends Failure.exhausted()('BulkheadFull', 'bulkheadFull', {
7
+ dependency: Schema.String
8
+ }, {
9
+ message: ({ dependency })=>`every permit to '${dependency}' is taken; the call was not made`
10
+ }) {
11
+ }
12
+ export class BulkheadTag extends Context.Service()('@entifix/transactions/Bulkhead') {
13
+ }
14
+ /** Permits in use, by key. */ export const bulkheadInUse = Metric.gauge('entifix_bulkhead_in_use', {
15
+ description: 'Bulkhead permits in use, by key.'
16
+ });
17
+
18
+ //# sourceMappingURL=bulkhead.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/bulkhead.ts"],"sourcesContent":["import { Failure } from '@entifix/core';\nimport { Context, type Effect, Metric, Schema } from 'effect';\n\n/**\n * The bulkhead for a key had no permit free. `exhausted`, and it stops every\n * retry above it: the calls already in flight are the ones to wait for.\n */\nexport class BulkheadFull extends Failure.exhausted<BulkheadFull>()(\n 'BulkheadFull',\n 'bulkheadFull',\n { dependency: Schema.String },\n {\n message: ({ dependency }) =>\n `every permit to '${dependency}' is taken; the call was not made`,\n },\n) {}\n\n/**\n * Bounds how many calls to one dependency run at once, per key\n * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)),\n * so a slow participant holds a bounded share of the process rather than all\n * of it. A call that finds no permit is refused at once, never queued.\n */\nexport interface Bulkhead {\n readonly withPermit: (\n key: string,\n ) => <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | BulkheadFull, R>;\n /** Permits taken now. */\n readonly inUse: (key: string) => Effect.Effect<number>;\n}\n\nexport class BulkheadTag extends Context.Service<BulkheadTag, Bulkhead>()(\n '@entifix/transactions/Bulkhead',\n) {}\n\n/** Permits in use, by key. */\nexport const bulkheadInUse = Metric.gauge('entifix_bulkhead_in_use', {\n description: 'Bulkhead permits in use, by key.',\n});\n"],"names":["Failure","Context","Metric","Schema","BulkheadFull","exhausted","dependency","String","message","BulkheadTag","Service","bulkheadInUse","gauge","description"],"mappings":"AAAA,SAASA,OAAO,QAAQ,gBAAgB;AACxC,SAASC,OAAO,EAAeC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAE9D;;;CAGC,GACD,OAAO,MAAMC,qBAAqBJ,QAAQK,SAAS,GACjD,gBACA,gBACA;IAAEC,YAAYH,OAAOI,MAAM;AAAC,GAC5B;IACEC,SAAS,CAAC,EAAEF,UAAU,EAAE,GACtB,CAAC,iBAAiB,EAAEA,WAAW,iCAAiC,CAAC;AACrE;AACC;AAkBH,OAAO,MAAMG,oBAAoBR,QAAQS,OAAO,GAC9C;AACC;AAEH,4BAA4B,GAC5B,OAAO,MAAMC,gBAAgBT,OAAOU,KAAK,CAAC,2BAA2B;IACnEC,aAAa;AACf,GAAG"}
@@ -0,0 +1,62 @@
1
+ import { Context, type Effect, Metric, Schema } from 'effect';
2
+ /**
3
+ * Where a breaker stands
4
+ * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).
5
+ * `forcedOpen` and `disabled` are an operator's: the first refuses every call,
6
+ * the second lets every call through and records none.
7
+ */
8
+ export type BreakerState = 'closed' | 'open' | 'halfOpen' | 'forcedOpen' | 'disabled';
9
+ /** The dials of one breaker, Resilience4j's names for Resilience4j's model. */
10
+ export interface BreakerDials {
11
+ /** `count` keeps the last `windowSize` calls; `time` the last `windowSize` seconds. */
12
+ readonly windowType: 'count' | 'time';
13
+ readonly windowSize: number;
14
+ /** Fraction of recorded calls that failed, at or above which the breaker opens. */
15
+ readonly failureRateThreshold: number;
16
+ /** Fraction of calls slower than `slowCallDurationMs`, at or above which it opens. */
17
+ readonly slowCallRateThreshold: number;
18
+ readonly slowCallDurationMs: number;
19
+ /** Calls the window must hold before either rate is read into it. */
20
+ readonly minimumCalls: number;
21
+ /** How long it stays open before letting probes through. */
22
+ readonly waitInOpenMs: number;
23
+ /** Calls let through half-open; their outcome closes or reopens it. */
24
+ readonly halfOpenPermits: number;
25
+ }
26
+ export declare const DEFAULT_BREAKER_DIALS: BreakerDials;
27
+ declare const BreakerOpen_base: Schema.Class<BreakerOpen, Schema.TaggedStruct<"BreakerOpen", {
28
+ readonly dependency: Schema.String;
29
+ }>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"breakerOpen", "unavailable">>;
30
+ /**
31
+ * The breaker for a key refused the call. `unavailable`, because the
32
+ * dependency is, and it stops every retry above it: retrying into an open
33
+ * breaker is what the breaker exists to prevent.
34
+ */
35
+ export declare class BreakerOpen extends BreakerOpen_base {
36
+ }
37
+ /**
38
+ * Stops calls to a dependency that is failing, per key — a participant, or a
39
+ * participant and a route. Records only technical failures other than
40
+ * `protocol`: a business failure is an answer and never trips it, and a
41
+ * protocol failure is a bug that waiting does not fix.
42
+ */
43
+ export interface CircuitBreaker {
44
+ readonly guard: (key: string) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | BreakerOpen, R>;
45
+ /** The state now — an elapsed wait in open reads as half-open. */
46
+ readonly state: (key: string) => Effect.Effect<BreakerState>;
47
+ /** An operator's override; `closed` hands the breaker back to its window. */
48
+ readonly force: (key: string, state: 'forcedOpen' | 'disabled' | 'closed') => Effect.Effect<void>;
49
+ }
50
+ declare const CircuitBreakerTag_base: Context.ServiceClass<CircuitBreakerTag, "@entifix/transactions/CircuitBreaker", CircuitBreaker>;
51
+ export declare class CircuitBreakerTag extends CircuitBreakerTag_base {
52
+ }
53
+ /** A breaker's state per key: 0 closed, 1 open, 2 half-open, 3 forced open, 4 disabled. */
54
+ export declare const breakerState: Metric.Gauge<number>;
55
+ /** Transitions, by key, source and target state. */
56
+ export declare const breakerTransitions: Metric.Counter<number>;
57
+ /** Calls an open breaker refused, by key. */
58
+ export declare const breakerRejections: Metric.Counter<number>;
59
+ /** The number each state reports on {@link breakerState}. */
60
+ export declare const BREAKER_STATE_VALUE: Readonly<Record<BreakerState, number>>;
61
+ export {};
62
+ //# sourceMappingURL=circuit-breaker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../src/ports/circuit-breaker.ts"],"names":[],"mappings":"AAC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AA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,CACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,GAAG,UAAU,GAAG,QAAQ,KACxC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CAC1B;;AAED,qBAAa,iBAAkB,SAAQ,sBAGI;CAAG;AAE9C,2FAA2F;AAC3F,eAAO,MAAM,YAAY,sBAEvB,CAAC;AAEH,oDAAoD;AACpD,eAAO,MAAM,kBAAkB,wBAG9B,CAAC;AAEF,6CAA6C;AAC7C,eAAO,MAAM,iBAAiB,wBAG7B,CAAC;AAEF,6DAA6D;AAC7D,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAMtE,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { Failure } from '@entifix/core';
2
+ import { Context, Metric, Schema } from 'effect';
3
+ export const DEFAULT_BREAKER_DIALS = {
4
+ windowType: 'count',
5
+ windowSize: 20,
6
+ failureRateThreshold: 0.5,
7
+ slowCallRateThreshold: 1,
8
+ slowCallDurationMs: 2000,
9
+ minimumCalls: 5,
10
+ waitInOpenMs: 10000,
11
+ halfOpenPermits: 2
12
+ };
13
+ /**
14
+ * The breaker for a key refused the call. `unavailable`, because the
15
+ * dependency is, and it stops every retry above it: retrying into an open
16
+ * breaker is what the breaker exists to prevent.
17
+ */ export class BreakerOpen extends Failure.unavailable()('BreakerOpen', 'breakerOpen', {
18
+ dependency: Schema.String
19
+ }, {
20
+ message: ({ dependency })=>`the circuit to '${dependency}' is open; the call was not made`
21
+ }) {
22
+ }
23
+ export class CircuitBreakerTag extends Context.Service()('@entifix/transactions/CircuitBreaker') {
24
+ }
25
+ /** A breaker's state per key: 0 closed, 1 open, 2 half-open, 3 forced open, 4 disabled. */ export const breakerState = Metric.gauge('entifix_breaker_state', {
26
+ description: 'Circuit breaker state, by key.'
27
+ });
28
+ /** Transitions, by key, source and target state. */ export const breakerTransitions = Metric.counter('entifix_breaker_transitions_total', {
29
+ description: 'Circuit breaker state transitions, by key and states.'
30
+ });
31
+ /** Calls an open breaker refused, by key. */ export const breakerRejections = Metric.counter('entifix_breaker_rejected_total', {
32
+ description: 'Calls refused by an open circuit breaker, by key.'
33
+ });
34
+ /** The number each state reports on {@link breakerState}. */ export const BREAKER_STATE_VALUE = {
35
+ closed: 0,
36
+ open: 1,
37
+ halfOpen: 2,
38
+ forcedOpen: 3,
39
+ disabled: 4
40
+ };
41
+
42
+ //# sourceMappingURL=circuit-breaker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/circuit-breaker.ts"],"sourcesContent":["import { Failure } from '@entifix/core';\nimport { Context, type Effect, Metric, Schema } from 'effect';\n\n/**\n * Where a breaker stands\n * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).\n * `forcedOpen` and `disabled` are an operator's: the first refuses every call,\n * the second lets every call through and records none.\n */\nexport type BreakerState =\n 'closed' | 'open' | 'halfOpen' | 'forcedOpen' | 'disabled';\n\n/** The dials of one breaker, Resilience4j's names for Resilience4j's model. */\nexport interface BreakerDials {\n /** `count` keeps the last `windowSize` calls; `time` the last `windowSize` seconds. */\n readonly windowType: 'count' | 'time';\n readonly windowSize: number;\n /** Fraction of recorded calls that failed, at or above which the breaker opens. */\n readonly failureRateThreshold: number;\n /** Fraction of calls slower than `slowCallDurationMs`, at or above which it opens. */\n readonly slowCallRateThreshold: number;\n readonly slowCallDurationMs: number;\n /** Calls the window must hold before either rate is read into it. */\n readonly minimumCalls: number;\n /** How long it stays open before letting probes through. */\n readonly waitInOpenMs: number;\n /** Calls let through half-open; their outcome closes or reopens it. */\n readonly halfOpenPermits: number;\n}\n\nexport const DEFAULT_BREAKER_DIALS: BreakerDials = {\n windowType: 'count',\n windowSize: 20,\n failureRateThreshold: 0.5,\n slowCallRateThreshold: 1,\n slowCallDurationMs: 2_000,\n minimumCalls: 5,\n waitInOpenMs: 10_000,\n halfOpenPermits: 2,\n};\n\n/**\n * The breaker for a key refused the call. `unavailable`, because the\n * dependency is, and it stops every retry above it: retrying into an open\n * breaker is what the breaker exists to prevent.\n */\nexport class BreakerOpen extends Failure.unavailable<BreakerOpen>()(\n 'BreakerOpen',\n 'breakerOpen',\n { dependency: Schema.String },\n {\n message: ({ dependency }) =>\n `the circuit to '${dependency}' is open; the call was not made`,\n },\n) {}\n\n/**\n * Stops calls to a dependency that is failing, per key — a participant, or a\n * participant and a route. Records only technical failures other than\n * `protocol`: a business failure is an answer and never trips it, and a\n * protocol failure is a bug that waiting does not fix.\n */\nexport interface CircuitBreaker {\n readonly guard: (\n key: string,\n ) => <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | BreakerOpen, R>;\n /** The state now — an elapsed wait in open reads as half-open. */\n readonly state: (key: string) => Effect.Effect<BreakerState>;\n /** An operator's override; `closed` hands the breaker back to its window. */\n readonly force: (\n key: string,\n state: 'forcedOpen' | 'disabled' | 'closed',\n ) => Effect.Effect<void>;\n}\n\nexport class CircuitBreakerTag extends Context.Service<\n CircuitBreakerTag,\n CircuitBreaker\n>()('@entifix/transactions/CircuitBreaker') {}\n\n/** A breaker's state per key: 0 closed, 1 open, 2 half-open, 3 forced open, 4 disabled. */\nexport const breakerState = Metric.gauge('entifix_breaker_state', {\n description: 'Circuit breaker state, by key.',\n});\n\n/** Transitions, by key, source and target state. */\nexport const breakerTransitions = Metric.counter(\n 'entifix_breaker_transitions_total',\n { description: 'Circuit breaker state transitions, by key and states.' },\n);\n\n/** Calls an open breaker refused, by key. */\nexport const breakerRejections = Metric.counter(\n 'entifix_breaker_rejected_total',\n { description: 'Calls refused by an open circuit breaker, by key.' },\n);\n\n/** The number each state reports on {@link breakerState}. */\nexport const BREAKER_STATE_VALUE: Readonly<Record<BreakerState, number>> = {\n closed: 0,\n open: 1,\n halfOpen: 2,\n forcedOpen: 3,\n disabled: 4,\n};\n"],"names":["Failure","Context","Metric","Schema","DEFAULT_BREAKER_DIALS","windowType","windowSize","failureRateThreshold","slowCallRateThreshold","slowCallDurationMs","minimumCalls","waitInOpenMs","halfOpenPermits","BreakerOpen","unavailable","dependency","String","message","CircuitBreakerTag","Service","breakerState","gauge","description","breakerTransitions","counter","breakerRejections","BREAKER_STATE_VALUE","closed","open","halfOpen","forcedOpen","disabled"],"mappings":"AAAA,SAASA,OAAO,QAAQ,gBAAgB;AACxC,SAASC,OAAO,EAAeC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AA6B9D,OAAO,MAAMC,wBAAsC;IACjDC,YAAY;IACZC,YAAY;IACZC,sBAAsB;IACtBC,uBAAuB;IACvBC,oBAAoB;IACpBC,cAAc;IACdC,cAAc;IACdC,iBAAiB;AACnB,EAAE;AAEF;;;;CAIC,GACD,OAAO,MAAMC,oBAAoBb,QAAQc,WAAW,GAClD,eACA,eACA;IAAEC,YAAYZ,OAAOa,MAAM;AAAC,GAC5B;IACEC,SAAS,CAAC,EAAEF,UAAU,EAAE,GACtB,CAAC,gBAAgB,EAAEA,WAAW,gCAAgC,CAAC;AACnE;AACC;AAuBH,OAAO,MAAMG,0BAA0BjB,QAAQkB,OAAO,GAGlD;AAAyC;AAE7C,yFAAyF,GACzF,OAAO,MAAMC,eAAelB,OAAOmB,KAAK,CAAC,yBAAyB;IAChEC,aAAa;AACf,GAAG;AAEH,kDAAkD,GAClD,OAAO,MAAMC,qBAAqBrB,OAAOsB,OAAO,CAC9C,qCACA;IAAEF,aAAa;AAAwD,GACvE;AAEF,2CAA2C,GAC3C,OAAO,MAAMG,oBAAoBvB,OAAOsB,OAAO,CAC7C,kCACA;IAAEF,aAAa;AAAoD,GACnE;AAEF,2DAA2D,GAC3D,OAAO,MAAMI,sBAA8D;IACzEC,QAAQ;IACRC,MAAM;IACNC,UAAU;IACVC,YAAY;IACZC,UAAU;AACZ,EAAE"}
@@ -57,6 +57,16 @@ export interface Subscription {
57
57
  * carried but unenforced there.
58
58
  */
59
59
  readonly maxAttempts: number;
60
+ /**
61
+ * The breaker keys whose dependency this consumer cannot work without
62
+ * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).
63
+ * While any of them is open — or forced open — the adapter stops consuming,
64
+ * and it resumes once all are closed or half-open, so an outage leaves the
65
+ * messages waiting on the queue rather than spending their attempts into
66
+ * quarantine. A delivery refused mid-flight by an open breaker goes back
67
+ * without counting as an attempt.
68
+ */
69
+ readonly pauseWhileOpen?: readonly string[];
60
70
  }
61
71
  /**
62
72
  * The domain event bus (RabbitMQ in `@entifix/amqp`). Services publish
@@ -1 +1 @@
1
- {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../src/ports/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,mBAAmB,EACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC/D;;;;;;;;;;;;;;OAcG;IACH,SAAS,CACP,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC,MAAM,CA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@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ports/event-bus.ts"],"sourcesContent":["import type {\n DomainEvent,\n StoreFailure,\n TransitionalFailure,\n} from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/**\n * How a subscriber's queue is shaped, which is a property of the *workload*\n * rather than of the transport.\n *\n * - `work` — a named, durable queue that survives the consumer's restart and\n * accumulates while it is gone. Replicas share it, so each message reaches\n * exactly one of them. A projection writer, a fold and a settlement consumer\n * all want this.\n * - `broadcast` — a connection-scoped exclusive queue, so every replica\n * receives every message and nothing is retained across a restart. Correct\n * only when the replicas differ from one another — a socket push holding\n * different clients per process.\n *\n * The bus first built the exclusive queue for every subscriber, with a stated\n * reason: a shared queue delivers each event to one replica, \"which reads as\n * flakiness rather than as a design\". That reasoning is right for `broadcast`\n * and wrong for `work`; it picked broadcast semantics for a workload that is\n * work, at a time when the only subscriber made the difference invisible.\n */\nexport type SubscriptionMode = 'work' | 'broadcast';\n\n/**\n * A subscriber's declared interest, together with the delivery policy the\n * broker enforces for it.\n *\n * The shape mirrors `subscriptions` in `tools/slices/*.slice.ts`, so \"how does\n * this fail\" is answered where it can be checked rather than in a review\n * comment.\n */\nexport interface Subscription {\n /**\n * The **subscribing** slice — the `tools/slices/` key, and half of the queue\n * name.\n *\n * Deliberately not `EventSourceTag`, which is the *emitting* slice: one\n * deployment may host several slices, so a process-wide \"my slice\" would attribute a\n * consumer's queue to whichever slice happened to publish from the same\n * process.\n */\n readonly slice: string;\n /**\n * The event name pattern, used verbatim as the broker's binding —\n * `transaction.*`, `catalog.published`. Filtering in the handler instead is\n * what this exists to prevent: it makes every consumer pay for every\n * publisher's traffic, and it puts the routing rule where no register can\n * check it.\n */\n readonly pattern: string;\n readonly mode: SubscriptionMode;\n /**\n * How many times the broker may deliver a message before dead-lettering it.\n *\n * Enforced by the queue itself rather than by logic each consumer\n * reimplements, so it applies to a redelivery after a crash as well as to one\n * after a nack. `broadcast` queues have no dead-letter path, so the value is\n * carried but unenforced there.\n */\n readonly maxAttempts: number;\n}\n\n/**\n * The domain event bus (RabbitMQ in `@entifix/amqp`). Services publish\n * what happened; interested slices subscribe to the names they declared.\n *\n * Typed on {@link DomainEvent} rather than on any one publisher's payload: a bus\n * that only knew `TransactionEvent` had nothing for a publication event to\n * travel in, which would have meant a second framing and a second\n * transport for the same job.\n *\n * The port stays event-typed rather than envelope-typed — the adapter owns the\n * wire framing — so a handler receives the message and its metadata without\n * ever seeing the envelope that carried them.\n */\nexport interface EventBus {\n publish(event: DomainEvent): Effect.Effect<void, StoreFailure>;\n /**\n * Register a consumer for the events matching `subscription.pattern`.\n *\n * The returned Effect completes once the subscription is established; the\n * handler then runs per delivered event. Delivery is at-least-once, so a\n * handler that is not idempotent must deduplicate on `event.id`.\n *\n * A handler failure is **transient**: the adapter requeues it and the broker\n * counts the redelivery against `maxAttempts`, dead-lettering at the limit. A\n * payload the adapter cannot read is **poison** and is quarantined with zero\n * retries — a message that cannot be deserialized never becomes\n * deserializable, and retrying it only spends the budget of the messages\n * behind it. A *business* failure is neither: that message was processed\n * successfully and already produced its own event.\n */\n subscribe(\n subscription: Subscription,\n handler: (event: DomainEvent) => Effect.Effect<void, TransitionalFailure>,\n ): Effect.Effect<void, StoreFailure>;\n}\n\nexport class EventBusTag extends Context.Service<EventBusTag, EventBus>()(\n 'EventBusTag',\n) {}\n"],"names":["Context","EventBusTag","Service"],"mappings":"AAKA,SAASA,OAAO,QAAqB,SAAS;AAkG9C,OAAO,MAAMC,oBAAoBD,QAAQE,OAAO,GAC9C;AACC"}
1
+ {"version":3,"sources":["../../src/ports/event-bus.ts"],"sourcesContent":["import type {\n DomainEvent,\n StoreFailure,\n TransitionalFailure,\n} from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/**\n * How a subscriber's queue is shaped, which is a property of the *workload*\n * rather than of the transport.\n *\n * - `work` — a named, durable queue that survives the consumer's restart and\n * accumulates while it is gone. Replicas share it, so each message reaches\n * exactly one of them. A projection writer, a fold and a settlement consumer\n * all want this.\n * - `broadcast` — a connection-scoped exclusive queue, so every replica\n * receives every message and nothing is retained across a restart. Correct\n * only when the replicas differ from one another — a socket push holding\n * different clients per process.\n *\n * The bus first built the exclusive queue for every subscriber, with a stated\n * reason: a shared queue delivers each event to one replica, \"which reads as\n * flakiness rather than as a design\". That reasoning is right for `broadcast`\n * and wrong for `work`; it picked broadcast semantics for a workload that is\n * work, at a time when the only subscriber made the difference invisible.\n */\nexport type SubscriptionMode = 'work' | 'broadcast';\n\n/**\n * A subscriber's declared interest, together with the delivery policy the\n * broker enforces for it.\n *\n * The shape mirrors `subscriptions` in `tools/slices/*.slice.ts`, so \"how does\n * this fail\" is answered where it can be checked rather than in a review\n * comment.\n */\nexport interface Subscription {\n /**\n * The **subscribing** slice — the `tools/slices/` key, and half of the queue\n * name.\n *\n * Deliberately not `EventSourceTag`, which is the *emitting* slice: one\n * deployment may host several slices, so a process-wide \"my slice\" would attribute a\n * consumer's queue to whichever slice happened to publish from the same\n * process.\n */\n readonly slice: string;\n /**\n * The event name pattern, used verbatim as the broker's binding —\n * `transaction.*`, `catalog.published`. Filtering in the handler instead is\n * what this exists to prevent: it makes every consumer pay for every\n * publisher's traffic, and it puts the routing rule where no register can\n * check it.\n */\n readonly pattern: string;\n readonly mode: SubscriptionMode;\n /**\n * How many times the broker may deliver a message before dead-lettering it.\n *\n * Enforced by the queue itself rather than by logic each consumer\n * reimplements, so it applies to a redelivery after a crash as well as to one\n * after a nack. `broadcast` queues have no dead-letter path, so the value is\n * carried but unenforced there.\n */\n readonly maxAttempts: number;\n /**\n * The breaker keys whose dependency this consumer cannot work without\n * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).\n * While any of them is open — or forced open — the adapter stops consuming,\n * and it resumes once all are closed or half-open, so an outage leaves the\n * messages waiting on the queue rather than spending their attempts into\n * quarantine. A delivery refused mid-flight by an open breaker goes back\n * without counting as an attempt.\n */\n readonly pauseWhileOpen?: readonly string[];\n}\n\n/**\n * The domain event bus (RabbitMQ in `@entifix/amqp`). Services publish\n * what happened; interested slices subscribe to the names they declared.\n *\n * Typed on {@link DomainEvent} rather than on any one publisher's payload: a bus\n * that only knew `TransactionEvent` had nothing for a publication event to\n * travel in, which would have meant a second framing and a second\n * transport for the same job.\n *\n * The port stays event-typed rather than envelope-typed — the adapter owns the\n * wire framing — so a handler receives the message and its metadata without\n * ever seeing the envelope that carried them.\n */\nexport interface EventBus {\n publish(event: DomainEvent): Effect.Effect<void, StoreFailure>;\n /**\n * Register a consumer for the events matching `subscription.pattern`.\n *\n * The returned Effect completes once the subscription is established; the\n * handler then runs per delivered event. Delivery is at-least-once, so a\n * handler that is not idempotent must deduplicate on `event.id`.\n *\n * A handler failure is **transient**: the adapter requeues it and the broker\n * counts the redelivery against `maxAttempts`, dead-lettering at the limit. A\n * payload the adapter cannot read is **poison** and is quarantined with zero\n * retries — a message that cannot be deserialized never becomes\n * deserializable, and retrying it only spends the budget of the messages\n * behind it. A *business* failure is neither: that message was processed\n * successfully and already produced its own event.\n */\n subscribe(\n subscription: Subscription,\n handler: (event: DomainEvent) => Effect.Effect<void, TransitionalFailure>,\n ): Effect.Effect<void, StoreFailure>;\n}\n\nexport class EventBusTag extends Context.Service<EventBusTag, EventBus>()(\n 'EventBusTag',\n) {}\n"],"names":["Context","EventBusTag","Service"],"mappings":"AAKA,SAASA,OAAO,QAAqB,SAAS;AA4G9C,OAAO,MAAMC,oBAAoBD,QAAQE,OAAO,GAC9C;AACC"}
@@ -0,0 +1,60 @@
1
+ import type { Slip } from '@entifix/business/flow';
2
+ import { type StoreFailure } from '@entifix/core';
3
+ import { Context, type Effect, Schema } from 'effect';
4
+ /**
5
+ * Where a flow stands. `suspended` is a flow past its commit point whose step
6
+ * keeps failing — it is waiting for retries or an operator, never compensated;
7
+ * `waiting` is a flow parked at a durable wait for a signal.
8
+ */
9
+ export type FlowState = 'running' | 'waiting' | 'suspended' | 'completed' | 'compensated' | 'failed' | 'interrupted';
10
+ export interface FlowStatus {
11
+ readonly flowId: string;
12
+ readonly state: FlowState;
13
+ /** The step in progress, or the one the flow stopped at. */
14
+ readonly step?: string;
15
+ }
16
+ declare const FlowNotFound_base: Schema.Class<FlowNotFound, Schema.TaggedStruct<"FlowNotFound", {
17
+ readonly flowId: Schema.String;
18
+ }>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"flowNotFound", "notFound">>;
19
+ /** No flow is known by this id. */
20
+ export declare class FlowNotFound extends FlowNotFound_base {
21
+ }
22
+ declare const FlowSignalRejected_base: Schema.Class<FlowSignalRejected, Schema.TaggedStruct<"FlowSignalRejected", {
23
+ readonly flowId: Schema.String;
24
+ readonly token: Schema.String;
25
+ }>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"flowSignalRejected", "conflict">>;
26
+ /**
27
+ * A signal the flow will not take: it is not waiting, it waits for another
28
+ * token, or the wait already timed out. A late signal is an answer, not an
29
+ * outage.
30
+ */
31
+ export declare class FlowSignalRejected extends FlowSignalRejected_base {
32
+ }
33
+ /**
34
+ * Runs pinned slips durably
35
+ * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).
36
+ *
37
+ * There is deliberately no `await`: a caller learns how a flow ended from its
38
+ * `flow.*` events, pushed, never by holding a request open on it.
39
+ */
40
+ export interface FlowEngine {
41
+ /** Starts a flow, idempotently: the same key answers the same `flowId`. */
42
+ readonly start: (slip: Slip, idempotencyKey: string) => Effect.Effect<{
43
+ readonly flowId: string;
44
+ }, StoreFailure>;
45
+ readonly status: (flowId: string) => Effect.Effect<FlowStatus, FlowNotFound | StoreFailure>;
46
+ /** Completes a durable wait the flow is parked at. */
47
+ readonly signal: (flowId: string, token: string, outcome: unknown) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;
48
+ /**
49
+ * Completes a durable wait by what the waiting flow is correlated with —
50
+ * the order a delivery flow follows, say — for a sender that knows that and
51
+ * not the flow's id.
52
+ */
53
+ readonly signalCorrelated: (correlation: string, token: string, outcome: unknown) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;
54
+ readonly interrupt: (flowId: string) => Effect.Effect<void, FlowNotFound | StoreFailure>;
55
+ }
56
+ declare const FlowEngineTag_base: Context.ServiceClass<FlowEngineTag, "@entifix/transactions/FlowEngine", FlowEngine>;
57
+ export declare class FlowEngineTag extends FlowEngineTag_base {
58
+ }
59
+ export {};
60
+ //# sourceMappingURL=flow-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-engine.d.ts","sourceRoot":"","sources":["../../src/ports/flow-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,SAAS,GACT,WAAW,GACX,WAAW,GACX,aAAa,GACb,QAAQ,GACR,aAAa,CAAC;AAElB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;;;;AAED,mCAAmC;AACnC,qBAAa,YAAa,SAAQ,iBAIjC;CAAG;;;;;AAEJ;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,uBAIvC;CAAG;AAEJ;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,CACd,IAAI,EAAE,IAAI,EACV,cAAc,EAAE,MAAM,KACnB,MAAM,CAAC,MAAM,CAAC;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,YAAY,CAAC,CAAC;IAC9D,QAAQ,CAAC,MAAM,EAAE,CACf,MAAM,EAAE,MAAM,KACX,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC;IAC5D,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,CACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,KACb,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,GAAG,YAAY,CAAC,CAAC;IAC3E;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,EAAE,CACzB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,KACb,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,GAAG,YAAY,CAAC,CAAC;IAC3E,QAAQ,CAAC,SAAS,EAAE,CAClB,MAAM,EAAE,MAAM,KACX,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC;CACvD;;AAED,qBAAa,aAAc,SAAQ,kBAElC;CAAG"}
@@ -0,0 +1,19 @@
1
+ import { Failure } from '@entifix/core';
2
+ import { Context, Schema } from 'effect';
3
+ /** No flow is known by this id. */ export class FlowNotFound extends Failure.notFound()('FlowNotFound', 'flowNotFound', {
4
+ flowId: Schema.String
5
+ }) {
6
+ }
7
+ /**
8
+ * A signal the flow will not take: it is not waiting, it waits for another
9
+ * token, or the wait already timed out. A late signal is an answer, not an
10
+ * outage.
11
+ */ export class FlowSignalRejected extends Failure.conflict()('FlowSignalRejected', 'flowSignalRejected', {
12
+ flowId: Schema.String,
13
+ token: Schema.String
14
+ }) {
15
+ }
16
+ export class FlowEngineTag extends Context.Service()('@entifix/transactions/FlowEngine') {
17
+ }
18
+
19
+ //# sourceMappingURL=flow-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/flow-engine.ts"],"sourcesContent":["import type { Slip } from '@entifix/business/flow';\nimport { Failure, type StoreFailure } from '@entifix/core';\nimport { Context, type Effect, Schema } from 'effect';\n\n/**\n * Where a flow stands. `suspended` is a flow past its commit point whose step\n * keeps failing — it is waiting for retries or an operator, never compensated;\n * `waiting` is a flow parked at a durable wait for a signal.\n */\nexport type FlowState =\n | 'running'\n | 'waiting'\n | 'suspended'\n | 'completed'\n | 'compensated'\n | 'failed'\n | 'interrupted';\n\nexport interface FlowStatus {\n readonly flowId: string;\n readonly state: FlowState;\n /** The step in progress, or the one the flow stopped at. */\n readonly step?: string;\n}\n\n/** No flow is known by this id. */\nexport class FlowNotFound extends Failure.notFound<FlowNotFound>()(\n 'FlowNotFound',\n 'flowNotFound',\n { flowId: Schema.String },\n) {}\n\n/**\n * A signal the flow will not take: it is not waiting, it waits for another\n * token, or the wait already timed out. A late signal is an answer, not an\n * outage.\n */\nexport class FlowSignalRejected extends Failure.conflict<FlowSignalRejected>()(\n 'FlowSignalRejected',\n 'flowSignalRejected',\n { flowId: Schema.String, token: Schema.String },\n) {}\n\n/**\n * Runs pinned slips durably\n * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).\n *\n * There is deliberately no `await`: a caller learns how a flow ended from its\n * `flow.*` events, pushed, never by holding a request open on it.\n */\nexport interface FlowEngine {\n /** Starts a flow, idempotently: the same key answers the same `flowId`. */\n readonly start: (\n slip: Slip,\n idempotencyKey: string,\n ) => Effect.Effect<{ readonly flowId: string }, StoreFailure>;\n readonly status: (\n flowId: string,\n ) => Effect.Effect<FlowStatus, FlowNotFound | StoreFailure>;\n /** Completes a durable wait the flow is parked at. */\n readonly signal: (\n flowId: string,\n token: string,\n outcome: unknown,\n ) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;\n /**\n * Completes a durable wait by what the waiting flow is correlated with —\n * the order a delivery flow follows, say — for a sender that knows that and\n * not the flow's id.\n */\n readonly signalCorrelated: (\n correlation: string,\n token: string,\n outcome: unknown,\n ) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;\n readonly interrupt: (\n flowId: string,\n ) => Effect.Effect<void, FlowNotFound | StoreFailure>;\n}\n\nexport class FlowEngineTag extends Context.Service<FlowEngineTag, FlowEngine>()(\n '@entifix/transactions/FlowEngine',\n) {}\n"],"names":["Failure","Context","Schema","FlowNotFound","notFound","flowId","String","FlowSignalRejected","conflict","token","FlowEngineTag","Service"],"mappings":"AACA,SAASA,OAAO,QAA2B,gBAAgB;AAC3D,SAASC,OAAO,EAAeC,MAAM,QAAQ,SAAS;AAuBtD,iCAAiC,GACjC,OAAO,MAAMC,qBAAqBH,QAAQI,QAAQ,GAChD,gBACA,gBACA;IAAEC,QAAQH,OAAOI,MAAM;AAAC;AACvB;AAEH;;;;CAIC,GACD,OAAO,MAAMC,2BAA2BP,QAAQQ,QAAQ,GACtD,sBACA,sBACA;IAAEH,QAAQH,OAAOI,MAAM;IAAEG,OAAOP,OAAOI,MAAM;AAAC;AAC7C;AAuCH,OAAO,MAAMI,sBAAsBT,QAAQU,OAAO,GAChD;AACC"}
@@ -0,0 +1,32 @@
1
+ import type { SlipStep } from '@entifix/business/flow';
2
+ import type { EntifixFailure } from '@entifix/core';
3
+ import { Context, type Effect } from 'effect';
4
+ /** One call a flow makes to a participant, for a step or for its undoing. */
5
+ export interface ParticipantCall {
6
+ readonly step: SlipStep;
7
+ /** `action` runs the step's call, `compensation` the call that undoes it. */
8
+ readonly kind: 'action' | 'compensation';
9
+ /**
10
+ * `<flowId>:<step>`, with `:compensation` for an undoing — the participant's
11
+ * `Idempotency-Key`, stable across every redelivery and resume.
12
+ */
13
+ readonly idempotencyKey: string;
14
+ /** What earlier steps answered, by step — the inputs a step may name. */
15
+ readonly outputs: Readonly<Record<string, unknown>>;
16
+ }
17
+ /**
18
+ * How a flow reaches its participants
19
+ * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).
20
+ * The interpreter calls this and nothing else, so the transport — HTTP with a
21
+ * crossing token, or an in-process double — is the composition root's choice.
22
+ * A refusal is the participant's typed failure; anything that kept the call
23
+ * from being answered is a technical one.
24
+ */
25
+ export interface ParticipantClient {
26
+ readonly call: (request: ParticipantCall) => Effect.Effect<unknown, EntifixFailure>;
27
+ }
28
+ declare const ParticipantClientTag_base: Context.ServiceClass<ParticipantClientTag, "@entifix/transactions/ParticipantClient", ParticipantClient>;
29
+ export declare class ParticipantClientTag extends ParticipantClientTag_base {
30
+ }
31
+ export {};
32
+ //# sourceMappingURL=participant-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"participant-client.d.ts","sourceRoot":"","sources":["../../src/ports/participant-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,CACb,OAAO,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;CAC7C;;AAED,qBAAa,oBAAqB,SAAQ,yBAGI;CAAG"}
@@ -0,0 +1,5 @@
1
+ import { Context } from 'effect';
2
+ export class ParticipantClientTag extends Context.Service()('@entifix/transactions/ParticipantClient') {
3
+ }
4
+
5
+ //# sourceMappingURL=participant-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/participant-client.ts"],"sourcesContent":["import type { SlipStep } from '@entifix/business/flow';\nimport type { EntifixFailure } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/** One call a flow makes to a participant, for a step or for its undoing. */\nexport interface ParticipantCall {\n readonly step: SlipStep;\n /** `action` runs the step's call, `compensation` the call that undoes it. */\n readonly kind: 'action' | 'compensation';\n /**\n * `<flowId>:<step>`, with `:compensation` for an undoing — the participant's\n * `Idempotency-Key`, stable across every redelivery and resume.\n */\n readonly idempotencyKey: string;\n /** What earlier steps answered, by step — the inputs a step may name. */\n readonly outputs: Readonly<Record<string, unknown>>;\n}\n\n/**\n * How a flow reaches its participants\n * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).\n * The interpreter calls this and nothing else, so the transport — HTTP with a\n * crossing token, or an in-process double — is the composition root's choice.\n * A refusal is the participant's typed failure; anything that kept the call\n * from being answered is a technical one.\n */\nexport interface ParticipantClient {\n readonly call: (\n request: ParticipantCall,\n ) => Effect.Effect<unknown, EntifixFailure>;\n}\n\nexport class ParticipantClientTag extends Context.Service<\n ParticipantClientTag,\n ParticipantClient\n>()('@entifix/transactions/ParticipantClient') {}\n"],"names":["Context","ParticipantClientTag","Service"],"mappings":"AAEA,SAASA,OAAO,QAAqB,SAAS;AA8B9C,OAAO,MAAMC,6BAA6BD,QAAQE,OAAO,GAGrD;AAA4C"}
@@ -1 +1 @@
1
- {"version":3,"file":"on.d.ts","sourceRoot":"","sources":["../../src/reactions/on.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,yBAAyB,EAC9B,KAAK,YAAY,EAEjB,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,QAAQ,EAAE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B,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AACzE,wBAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,EACtB,SAAS,EAAE,yBAAyB,CAAC,CAAC,EAAE,EAAE,CAAC,GAC1C,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC"}
@@ -3,7 +3,8 @@ import { Effect, Metric } from 'effect';
3
3
  import { retryAttempts, retryBudgetRejections, RetryBudgetTag, retryThrottled } from '../ports/retry-budget.js';
4
4
  /** Tags that stop retries wherever they appear: the dependency asked for less. */ const STOPS_RETRIES = new Set([
5
5
  'Overloaded',
6
- 'BreakerOpen'
6
+ 'BreakerOpen',
7
+ 'BulkheadFull'
7
8
  ]);
8
9
  const fullJitter = (attempt, base, cap)=>Math.random() * Math.min(cap, base * 2 ** (attempt - 1));
9
10
  const count = (counter, key)=>Metric.update(Metric.withAttributes(counter, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/reactions/on.ts"],"sourcesContent":["import {\n type BusinessCategory,\n currentRemainingMs,\n type EffectfulFailurePredicate,\n type FailureGuard,\n isFailure,\n Overloaded,\n} from '@entifix/core';\nimport { type Duration, Effect, Metric } from 'effect';\n\nimport {\n retryAttempts,\n type RetryBudget,\n retryBudgetRejections,\n RetryBudgetTag,\n type RetryKey,\n retryThrottled,\n} from '../ports/retry-budget.js';\n\n/**\n * A retry is legal on a call only when repeating it cannot do the thing twice:\n * a read, or a write carrying an `Idempotency-Key`. The caller states it; the\n * reaction refuses to be built when it is false, so the mistake is a boot\n * failure rather than a second charge.\n */\nexport interface RetryOptions {\n readonly key: RetryKey;\n readonly idempotent: boolean;\n}\n\n/** Tags that stop retries wherever they appear: the dependency asked for less. */\nconst STOPS_RETRIES: ReadonlySet<string> = new Set([\n 'Overloaded',\n 'BreakerOpen',\n]);\n\ntype AdmitsBusiness<S> = S extends { readonly family: 'business' }\n ? true\n : S extends { readonly category: BusinessCategory }\n ? true\n : false;\n\ntype Remaining<E, S, Narrows extends boolean> = Narrows extends true\n ? Exclude<E, S>\n : E;\n\n/**\n * The reactions a shell composes onto an effect, each a plain\n * `(self) => Effect` transform — no rule language, because a reaction is an\n * Effect function and the compiler already checks those\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n */\nexport interface Reactions<S, RP, Narrows extends boolean> {\n /**\n * Retry the matching failures, once per attempt the budget admits, with full\n * jitter, never past the request's deadline\n * ([ADR 0014](../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n *\n * Not available on a predicate that admits a business failure: an answer\n * retried is the same answer, and the type says so before anything runs.\n */\n readonly retry: AdmitsBusiness<S> extends true\n ? never\n : (\n options: RetryOptions,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | Overloaded, R | RP | RetryBudgetTag>;\n /** Wait before letting a matching failure through — pacing, not a retry. */\n readonly delay: (\n duration: Duration.Input,\n ) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | RP>;\n /** Run another effect in place of a matching failure. */\n readonly fallback: <B, E2, R2>(\n other: (failure: S) => Effect.Effect<B, E2, R2>,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A | B, Remaining<E, S, Narrows> | E2, R | R2 | RP>;\n /** Answer a matching failure with an outcome. */\n readonly recover: <B>(\n toOutcome: (failure: S) => B,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A | B, Remaining<E, S, Narrows>, R | RP>;\n}\n\nconst fullJitter = (attempt: number, base: number, cap: number) =>\n Math.random() * Math.min(cap, base * 2 ** (attempt - 1));\n\nconst count = (counter: Metric.Counter<number>, key: RetryKey) =>\n Metric.update(\n Metric.withAttributes(counter, { dependency: key.dependency }),\n 1,\n );\n\n/**\n * Reactions to the failures `predicate` admits.\n *\n * Given a guard, the reactions that consume a failure narrow `E`; given a\n * guard with a condition (`Failure.when`), they cannot — the condition may say\n * no at run time — and `E` is left as it was.\n */\nexport function On<S>(guard: FailureGuard<S>): Reactions<S, never, true>;\nexport function On<S, RP>(\n predicate: EffectfulFailurePredicate<S, RP>,\n): Reactions<S, RP, false>;\nexport function On<S, RP>(\n predicate: FailureGuard<S> | EffectfulFailurePredicate<S, RP>,\n): Reactions<S, RP, boolean> {\n const guard = typeof predicate === 'function' ? predicate : predicate.guard;\n const matches = (failure: unknown): Effect.Effect<boolean, never, RP> =>\n !guard(failure)\n ? Effect.succeed(false)\n : typeof predicate === 'function'\n ? Effect.succeed(true)\n : predicate.condition(failure);\n\n const retry = (options: RetryOptions) => {\n if (!options.idempotent)\n throw new Error(\n `On(…).retry on '${options.key.dependency}' is refused: the call is ` +\n 'not idempotent, so a retry could do it twice. Make it a read or ' +\n 'give it an Idempotency-Key.',\n );\n\n return <A, E, R>(self: Effect.Effect<A, E, R>) =>\n Effect.gen(function* () {\n const budget = yield* RetryBudgetTag;\n if (!(yield* budget.admitAttempt(options.key))) {\n yield* count(retryThrottled, options.key);\n return yield* Effect.fail(new Overloaded({}));\n }\n return yield* attempt(self, budget, 1);\n });\n\n function attempt<A, E, R>(\n self: Effect.Effect<A, E, R>,\n budget: RetryBudget,\n n: number,\n ): Effect.Effect<A, E | Overloaded, R | RP> {\n return self.pipe(\n Effect.tap(() => budget.recordAccepted(options.key)),\n Effect.catch(error =>\n Effect.gen(function* () {\n // An answer, even a refusal, is the dependency working.\n if (isFailure(error) && error.family === 'business') {\n yield* budget.recordAccepted(options.key);\n return yield* Effect.fail(error);\n }\n const stop =\n !(yield* matches(error)) ||\n (isFailure(error) && STOPS_RETRIES.has(error._tag)) ||\n n >= budget.dials.maxAttempts;\n if (stop) return yield* Effect.fail(error);\n\n const wait = fullJitter(\n n,\n budget.dials.backoffBaseMs,\n budget.dials.backoffCapMs,\n );\n const remaining = yield* currentRemainingMs;\n if (remaining !== undefined && remaining <= wait)\n return yield* Effect.fail(error);\n\n if (!(yield* budget.admitRetry(options.key))) {\n yield* count(retryBudgetRejections, options.key);\n return yield* Effect.fail(error);\n }\n yield* count(retryAttempts, options.key);\n yield* Effect.sleep(wait);\n return yield* attempt(self, budget, n + 1);\n }),\n ),\n );\n }\n };\n\n return {\n retry: retry as Reactions<S, RP, boolean>['retry'],\n delay: duration => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? Effect.sleep(duration).pipe(Effect.andThen(Effect.fail(error)))\n : Effect.fail(error),\n ),\n ),\n ),\n fallback: other => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? (other(error as unknown as S) as Effect.Effect<\n unknown,\n unknown,\n unknown\n >)\n : Effect.fail(error),\n ),\n ),\n ) as never,\n recover: toOutcome => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? Effect.succeed(toOutcome(error as unknown as S))\n : Effect.fail(error),\n ),\n ),\n ) as never,\n };\n}\n"],"names":["currentRemainingMs","isFailure","Overloaded","Effect","Metric","retryAttempts","retryBudgetRejections","RetryBudgetTag","retryThrottled","STOPS_RETRIES","Set","fullJitter","attempt","base","cap","Math","random","min","count","counter","key","update","withAttributes","dependency","On","predicate","guard","matches","failure","succeed","condition","retry","options","idempotent","Error","self","gen","budget","admitAttempt","fail","n","pipe","tap","recordAccepted","catch","error","family","stop","has","_tag","dials","maxAttempts","wait","backoffBaseMs","backoffCapMs","remaining","undefined","admitRetry","sleep","delay","duration","flatMap","matched","andThen","fallback","other","recover","toOutcome"],"mappings":"AAAA,SAEEA,kBAAkB,EAGlBC,SAAS,EACTC,UAAU,QACL,gBAAgB;AACvB,SAAwBC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAEvD,SACEC,aAAa,EAEbC,qBAAqB,EACrBC,cAAc,EAEdC,cAAc,QACT,2BAA2B;AAalC,g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AAI,CAACM;QAIxBmB,UAAUC,CAAAA,QAAS9B,CAAAA,OACjBA,KAAKM,IAAI,CACPtC,OAAOyC,KAAK,CAACC,CAAAA,QACX1C,OAAO0D,OAAO,CAAClC,QAAQkB,QAAQiB,CAAAA,UAC7BA,UACKG,MAAMpB,SAKP1C,OAAOoC,IAAI,CAACM;QAIxBqB,SAASC,CAAAA,YAAahC,CAAAA,OACpBA,KAAKM,IAAI,CACPtC,OAAOyC,KAAK,CAACC,CAAAA,QACX1C,OAAO0D,OAAO,CAAClC,QAAQkB,QAAQiB,CAAAA,UAC7BA,UACI3D,OAAO0B,OAAO,CAACsC,UAAUtB,UACzB1C,OAAOoC,IAAI,CAACM;IAI1B;AACF"}
1
+ {"version":3,"sources":["../../src/reactions/on.ts"],"sourcesContent":["import {\n type BusinessCategory,\n currentRemainingMs,\n type EffectfulFailurePredicate,\n type FailureGuard,\n isFailure,\n Overloaded,\n} from '@entifix/core';\nimport { type Duration, Effect, Metric } from 'effect';\n\nimport {\n retryAttempts,\n type RetryBudget,\n retryBudgetRejections,\n RetryBudgetTag,\n type RetryKey,\n retryThrottled,\n} from '../ports/retry-budget.js';\n\n/**\n * A retry is legal on a call only when repeating it cannot do the thing twice:\n * a read, or a write carrying an `Idempotency-Key`. The caller states it; the\n * reaction refuses to be built when it is false, so the mistake is a boot\n * failure rather than a second charge.\n */\nexport interface RetryOptions {\n readonly key: RetryKey;\n readonly idempotent: boolean;\n}\n\n/** Tags that stop retries wherever they appear: the dependency asked for less. */\nconst STOPS_RETRIES: ReadonlySet<string> = new Set([\n 'Overloaded',\n 'BreakerOpen',\n 'BulkheadFull',\n]);\n\ntype AdmitsBusiness<S> = S extends { readonly family: 'business' }\n ? true\n : S extends { readonly category: BusinessCategory }\n ? true\n : false;\n\ntype Remaining<E, S, Narrows extends boolean> = Narrows extends true\n ? Exclude<E, S>\n : E;\n\n/**\n * The reactions a shell composes onto an effect, each a plain\n * `(self) => Effect` transform — no rule language, because a reaction is an\n * Effect function and the compiler already checks those\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n */\nexport interface Reactions<S, RP, Narrows extends boolean> {\n /**\n * Retry the matching failures, once per attempt the budget admits, with full\n * jitter, never past the request's deadline\n * ([ADR 0014](../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n *\n * Not available on a predicate that admits a business failure: an answer\n * retried is the same answer, and the type says so before anything runs.\n */\n readonly retry: AdmitsBusiness<S> extends true\n ? never\n : (\n options: RetryOptions,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | Overloaded, R | RP | RetryBudgetTag>;\n /** Wait before letting a matching failure through — pacing, not a retry. */\n readonly delay: (\n duration: Duration.Input,\n ) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | RP>;\n /** Run another effect in place of a matching failure. */\n readonly fallback: <B, E2, R2>(\n other: (failure: S) => Effect.Effect<B, E2, R2>,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A | B, Remaining<E, S, Narrows> | E2, R | R2 | RP>;\n /** Answer a matching failure with an outcome. */\n readonly recover: <B>(\n toOutcome: (failure: S) => B,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A | B, Remaining<E, S, Narrows>, R | RP>;\n}\n\nconst fullJitter = (attempt: number, base: number, cap: number) =>\n Math.random() * Math.min(cap, base * 2 ** (attempt - 1));\n\nconst count = (counter: Metric.Counter<number>, key: RetryKey) =>\n Metric.update(\n Metric.withAttributes(counter, { dependency: key.dependency }),\n 1,\n );\n\n/**\n * Reactions to the failures `predicate` admits.\n *\n * Given a guard, the reactions that consume a failure narrow `E`; given a\n * guard with a condition (`Failure.when`), they cannot — the condition may say\n * no at run time — and `E` is left as it was.\n */\nexport function On<S>(guard: FailureGuard<S>): Reactions<S, never, true>;\nexport function On<S, RP>(\n predicate: EffectfulFailurePredicate<S, RP>,\n): Reactions<S, RP, false>;\nexport function On<S, RP>(\n predicate: FailureGuard<S> | EffectfulFailurePredicate<S, RP>,\n): Reactions<S, RP, boolean> {\n const guard = typeof predicate === 'function' ? predicate : predicate.guard;\n const matches = (failure: unknown): Effect.Effect<boolean, never, RP> =>\n !guard(failure)\n ? Effect.succeed(false)\n : typeof predicate === 'function'\n ? Effect.succeed(true)\n : predicate.condition(failure);\n\n const retry = (options: RetryOptions) => {\n if (!options.idempotent)\n throw new Error(\n `On(…).retry on '${options.key.dependency}' is refused: the call is ` +\n 'not idempotent, so a retry could do it twice. Make it a read or ' +\n 'give it an Idempotency-Key.',\n );\n\n return <A, E, R>(self: Effect.Effect<A, E, R>) =>\n Effect.gen(function* () {\n const budget = yield* RetryBudgetTag;\n if (!(yield* budget.admitAttempt(options.key))) {\n yield* count(retryThrottled, options.key);\n return yield* Effect.fail(new Overloaded({}));\n }\n return yield* attempt(self, budget, 1);\n });\n\n function attempt<A, E, R>(\n self: Effect.Effect<A, E, R>,\n budget: RetryBudget,\n n: number,\n ): Effect.Effect<A, E | Overloaded, R | RP> {\n return self.pipe(\n Effect.tap(() => budget.recordAccepted(options.key)),\n Effect.catch(error =>\n Effect.gen(function* () {\n // An answer, even a refusal, is the dependency working.\n if (isFailure(error) && error.family === 'business') {\n yield* budget.recordAccepted(options.key);\n return yield* Effect.fail(error);\n }\n const stop =\n !(yield* matches(error)) ||\n (isFailure(error) && STOPS_RETRIES.has(error._tag)) ||\n n >= budget.dials.maxAttempts;\n if (stop) return yield* Effect.fail(error);\n\n const wait = fullJitter(\n n,\n budget.dials.backoffBaseMs,\n budget.dials.backoffCapMs,\n );\n const remaining = yield* currentRemainingMs;\n if (remaining !== undefined && remaining <= wait)\n return yield* Effect.fail(error);\n\n if (!(yield* budget.admitRetry(options.key))) {\n yield* count(retryBudgetRejections, options.key);\n return yield* Effect.fail(error);\n }\n yield* count(retryAttempts, options.key);\n yield* Effect.sleep(wait);\n return yield* attempt(self, budget, n + 1);\n }),\n ),\n );\n }\n };\n\n return {\n retry: retry as Reactions<S, RP, boolean>['retry'],\n delay: duration => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? Effect.sleep(duration).pipe(Effect.andThen(Effect.fail(error)))\n : Effect.fail(error),\n ),\n ),\n ),\n fallback: other => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? (other(error as unknown as S) as Effect.Effect<\n unknown,\n unknown,\n unknown\n >)\n : Effect.fail(error),\n ),\n ),\n ) as never,\n recover: toOutcome => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? Effect.succeed(toOutcome(error as unknown as S))\n : Effect.fail(error),\n ),\n ),\n ) as never,\n };\n}\n"],"names":["currentRemainingMs","isFailure","Overloaded","Effect","Metric","retryAttempts","retryBudgetRejections","RetryBudgetTag","retryThrottled","STOPS_RETRIES","Set","fullJitter","attempt","base","cap","Math","random","min","count","counter","key","update","withAttributes","dependency","On","predicate","guard","matches","failure","succeed","condition","retry","options","idempotent","Error","self","gen","budget","admitAttempt","fail","n","pipe","tap","recordAccepted","catch","error","family","stop","has","_tag","dials","maxAttempts","wait","backoffBaseMs","backoffCapMs","remaining","undefined","admitRetry","sleep","delay","duration","flatMap","matched","andThen","fallback","other","recover","toOutcome"],"mappings":"AAAA,SAEEA,kBAAkB,EAGlBC,SAAS,EACTC,UAAU,QACL,gBAAgB;AACvB,SAAwBC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAEvD,SACEC,aAAa,EAEbC,qBAAqB,EACrBC,cAAc,EAEdC,cAAc,QACT,2BAA2B;AAalC,gFAAgF,GAChF,MAAMC,gBAAqC,IAAIC,IAAI;IACjD;IACA;IACA;CACD;AAoDD,MAAMC,aAAa,CAACC,SAAiBC,MAAcC,MACjDC,KAAKC,MAAM,KAAKD,KAAKE,GAAG,CAACH,KAAKD,OAAO,KAAMD,CAAAA,UAAU,CAAA;AAEvD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AOoC,IAAI,CAACM;QAIxBqB,SAASC,CAAAA,YAAahC,CAAAA,OACpBA,KAAKM,IAAI,CACPtC,OAAOyC,KAAK,CAACC,CAAAA,QACX1C,OAAO0D,OAAO,CAAClC,QAAQkB,QAAQiB,CAAAA,UAC7BA,UACI3D,OAAO0B,OAAO,CAACsC,UAAUtB,UACzB1C,OAAOoC,IAAI,CAACM;IAI1B;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/transactions",
3
- "version": "0.10.2",
3
+ "version": "0.12.0",
4
4
  "description": "Commands, transactions and sagas: inbox and outbox ports, an event bus, locks, and a declarative saga runner.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -56,8 +56,8 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@swc/helpers": "0.5.23",
59
- "@entifix/core": "0.10.2",
60
- "@entifix/business": "0.10.2"
59
+ "@entifix/business": "0.12.0",
60
+ "@entifix/core": "0.12.0"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "effect": "^4.0.6"