@entifix/testing-unit 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 (65) hide show
  1. package/dist/contracts/breaker.contract.d.ts +25 -0
  2. package/dist/contracts/breaker.contract.d.ts.map +1 -0
  3. package/dist/contracts/breaker.contract.js +159 -0
  4. package/dist/contracts/breaker.contract.js.map +1 -0
  5. package/dist/contracts/flow-engine.contract.d.ts +16 -0
  6. package/dist/contracts/flow-engine.contract.d.ts.map +1 -0
  7. package/dist/contracts/flow-engine.contract.js +199 -0
  8. package/dist/contracts/flow-engine.contract.js.map +1 -0
  9. package/dist/contracts/idempotency-store.contract.d.ts +17 -0
  10. package/dist/contracts/idempotency-store.contract.d.ts.map +1 -0
  11. package/dist/contracts/idempotency-store.contract.js +94 -0
  12. package/dist/contracts/idempotency-store.contract.js.map +1 -0
  13. package/dist/contracts/index.d.ts +5 -0
  14. package/dist/contracts/index.d.ts.map +1 -1
  15. package/dist/contracts/index.js +5 -0
  16. package/dist/contracts/index.js.map +1 -1
  17. package/dist/contracts/outbox.contract.d.ts +18 -0
  18. package/dist/contracts/outbox.contract.d.ts.map +1 -0
  19. package/dist/contracts/outbox.contract.js +117 -0
  20. package/dist/contracts/outbox.contract.js.map +1 -0
  21. package/dist/contracts/transaction-ports.contract.d.ts +1 -1
  22. package/dist/contracts/transaction-ports.contract.d.ts.map +1 -1
  23. package/dist/contracts/transaction-ports.contract.js +10 -1
  24. package/dist/contracts/transaction-ports.contract.js.map +1 -1
  25. package/dist/contracts/unit-of-work.contract.d.ts.map +1 -1
  26. package/dist/contracts/unit-of-work.contract.js +5 -0
  27. package/dist/contracts/unit-of-work.contract.js.map +1 -1
  28. package/dist/contracts/variants.contract.d.ts +15 -0
  29. package/dist/contracts/variants.contract.d.ts.map +1 -0
  30. package/dist/contracts/variants.contract.js +39 -0
  31. package/dist/contracts/variants.contract.js.map +1 -0
  32. package/dist/doubles/entity-repository.d.ts +3 -3
  33. package/dist/doubles/entity-repository.d.ts.map +1 -1
  34. package/dist/doubles/entity-repository.js +2 -4
  35. package/dist/doubles/entity-repository.js.map +1 -1
  36. package/dist/doubles/flow-engine.d.ts +22 -0
  37. package/dist/doubles/flow-engine.d.ts.map +1 -0
  38. package/dist/doubles/flow-engine.js +148 -0
  39. package/dist/doubles/flow-engine.js.map +1 -0
  40. package/dist/doubles/idempotency-store.d.ts +12 -0
  41. package/dist/doubles/idempotency-store.d.ts.map +1 -0
  42. package/dist/doubles/idempotency-store.js +40 -0
  43. package/dist/doubles/idempotency-store.js.map +1 -0
  44. package/dist/doubles/link-resolver.d.ts.map +1 -1
  45. package/dist/doubles/link-resolver.js +3 -4
  46. package/dist/doubles/link-resolver.js.map +1 -1
  47. package/dist/doubles/outbox.d.ts +15 -0
  48. package/dist/doubles/outbox.d.ts.map +1 -0
  49. package/dist/doubles/outbox.js +70 -0
  50. package/dist/doubles/outbox.js.map +1 -0
  51. package/dist/doubles/unit-of-work.d.ts +2 -3
  52. package/dist/doubles/unit-of-work.d.ts.map +1 -1
  53. package/dist/doubles/unit-of-work.js.map +1 -1
  54. package/dist/drivers/fake-amqp.d.ts +2 -0
  55. package/dist/drivers/fake-amqp.d.ts.map +1 -1
  56. package/dist/drivers/fake-amqp.js +8 -0
  57. package/dist/drivers/fake-amqp.js.map +1 -1
  58. package/dist/drivers/fake-sql.d.ts.map +1 -1
  59. package/dist/drivers/fake-sql.js +16 -1
  60. package/dist/drivers/fake-sql.js.map +1 -1
  61. package/dist/index.d.ts +3 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +3 -0
  64. package/dist/index.js.map +1 -1
  65. package/package.json +5 -5
@@ -0,0 +1,25 @@
1
+ import type { BreakerDials, Bulkhead, CircuitBreaker } from '@entifix/transactions';
2
+ import { Effect } from 'effect';
3
+ import type { ContractClock } from './idempotency-store.contract.js';
4
+ /** What a case is handed: a breaker and a bulkhead over its clock. */
5
+ export interface BreakerUnderTest {
6
+ readonly breaker: CircuitBreaker;
7
+ readonly bulkhead: Bulkhead;
8
+ }
9
+ /** The dials the cases are written against. */
10
+ export declare const BREAKER_CONTRACT_DIALS: BreakerDials;
11
+ /**
12
+ * What every breaker and bulkhead must guarantee
13
+ * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)):
14
+ * a window that opens at its failure or slow-call rate and not before its
15
+ * minimum; an open breaker that refuses without calling, and lets probes
16
+ * through once its wait has passed; probes that close it or reopen it; a
17
+ * `Retry-After` that opens it at once and for as long as was asked; business
18
+ * and protocol failures that never move it; the forced states; and a full
19
+ * bulkhead that refuses rather than queues.
20
+ *
21
+ * `make` builds a fresh pair over the case's clock, with
22
+ * {@link BREAKER_CONTRACT_DIALS} and two bulkhead permits.
23
+ */
24
+ export declare const describeBreakerContract: (name: string, make: (clock: ContractClock) => Effect.Effect<BreakerUnderTest, unknown>) => void;
25
+ //# sourceMappingURL=breaker.contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breaker.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/breaker.contract.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAC;AAG7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED,+CAA+C;AAC/C,eAAO,MAAM,sBAAsB,EAAE,YASpC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GAClC,MAAM,MAAM,EACZ,MAAM,CAAC,KAAK,EAAE,aAAa,KAAK,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,OAAO,CAAC,KACvE,IAqKF,CAAC"}
@@ -0,0 +1,159 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { Declined, Overloaded, ProtocolFailure, Unavailable } from '@entifix/core';
3
+ import { Effect, Exit, Fiber } from 'effect';
4
+ import { describe, expect, it } from 'vitest';
5
+ /** The dials the cases are written against. */ export const BREAKER_CONTRACT_DIALS = {
6
+ windowType: 'count',
7
+ windowSize: 4,
8
+ failureRateThreshold: 0.5,
9
+ slowCallRateThreshold: 1,
10
+ slowCallDurationMs: 100,
11
+ minimumCalls: 4,
12
+ waitInOpenMs: 1000,
13
+ halfOpenPermits: 2
14
+ };
15
+ /**
16
+ * What every breaker and bulkhead must guarantee
17
+ * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)):
18
+ * a window that opens at its failure or slow-call rate and not before its
19
+ * minimum; an open breaker that refuses without calling, and lets probes
20
+ * through once its wait has passed; probes that close it or reopen it; a
21
+ * `Retry-After` that opens it at once and for as long as was asked; business
22
+ * and protocol failures that never move it; the forced states; and a full
23
+ * bulkhead that refuses rather than queues.
24
+ *
25
+ * `make` builds a fresh pair over the case's clock, with
26
+ * {@link BREAKER_CONTRACT_DIALS} and two bulkhead permits.
27
+ */ export const describeBreakerContract = (name, make)=>{
28
+ const run = (effect)=>Effect.runPromise(effect);
29
+ const fresh = async ()=>{
30
+ let time = Date.UTC(2026, 0, 1);
31
+ const clock = {
32
+ now: ()=>time
33
+ };
34
+ const subject = await run(make(clock));
35
+ return _extends({}, subject, {
36
+ advance: (ms)=>{
37
+ time += ms;
38
+ }
39
+ });
40
+ };
41
+ const down = Effect.fail(new Unavailable({
42
+ dependency: 'stock'
43
+ }));
44
+ const fine = Effect.succeed('ok');
45
+ const call = (breaker, effect)=>run(Effect.exit(breaker.guard('stock')(effect)));
46
+ const tagOf = (exit)=>{
47
+ var _Exit_findErrorOption_value;
48
+ return Exit.isFailure(exit) ? (_Exit_findErrorOption_value = Exit.findErrorOption(exit).value) == null ? void 0 : _Exit_findErrorOption_value._tag : 'success';
49
+ };
50
+ describe(`CircuitBreaker contract: ${name}`, ()=>{
51
+ it('stays closed below the minimum number of calls', async ()=>{
52
+ const { breaker } = await fresh();
53
+ for(let index = 0; index < 3; index += 1)await call(breaker, down);
54
+ expect(await run(breaker.state('stock'))).toBe('closed');
55
+ });
56
+ it('opens at the failure rate and refuses without calling', async ()=>{
57
+ const { breaker } = await fresh();
58
+ await call(breaker, fine);
59
+ await call(breaker, fine);
60
+ await call(breaker, down);
61
+ await call(breaker, down);
62
+ // A call that ran would end in this defect, not in `BreakerOpen`.
63
+ const refused = await call(breaker, Effect.die('the call was made'));
64
+ expect(await run(breaker.state('stock'))).toBe('open');
65
+ expect(tagOf(refused)).toBe('BreakerOpen');
66
+ });
67
+ it('opens on slow calls even when every call succeeded', async ()=>{
68
+ const subject = await fresh();
69
+ const slow = Effect.sync(()=>subject.advance(150));
70
+ for(let index = 0; index < 4; index += 1)await call(subject.breaker, slow);
71
+ expect(await run(subject.breaker.state('stock'))).toBe('open');
72
+ });
73
+ it('goes half-open after its wait, and closes when the probes succeed', async ()=>{
74
+ const subject = await fresh();
75
+ for(let index = 0; index < 4; index += 1)await call(subject.breaker, down);
76
+ subject.advance(1000);
77
+ expect(await run(subject.breaker.state('stock'))).toBe('halfOpen');
78
+ await call(subject.breaker, fine);
79
+ await call(subject.breaker, fine);
80
+ expect(await run(subject.breaker.state('stock'))).toBe('closed');
81
+ });
82
+ it('reopens when the probes fail, and admits no more probes than its permits', async ()=>{
83
+ const subject = await fresh();
84
+ for(let index = 0; index < 4; index += 1)await call(subject.breaker, down);
85
+ subject.advance(1000);
86
+ const gate = Effect.never;
87
+ const first = Effect.runFork(subject.breaker.guard('stock')(gate));
88
+ const second = Effect.runFork(subject.breaker.guard('stock')(gate));
89
+ await new Promise((resolve)=>setTimeout(resolve, 0));
90
+ expect(tagOf(await call(subject.breaker, fine))).toBe('BreakerOpen');
91
+ await run(Fiber.interrupt(first));
92
+ await run(Fiber.interrupt(second));
93
+ const reprobe = await fresh();
94
+ for(let index = 0; index < 4; index += 1)await call(reprobe.breaker, down);
95
+ reprobe.advance(1000);
96
+ await call(reprobe.breaker, down);
97
+ await call(reprobe.breaker, fine);
98
+ expect(await run(reprobe.breaker.state('stock'))).toBe('open');
99
+ });
100
+ it('opens at once on Retry-After, for at least as long as was asked', async ()=>{
101
+ const subject = await fresh();
102
+ await call(subject.breaker, Effect.fail(new Overloaded({
103
+ retryAfterSeconds: 5
104
+ })));
105
+ expect(await run(subject.breaker.state('stock'))).toBe('open');
106
+ subject.advance(1000);
107
+ expect(await run(subject.breaker.state('stock'))).toBe('open');
108
+ subject.advance(4000);
109
+ expect(await run(subject.breaker.state('stock'))).toBe('halfOpen');
110
+ });
111
+ it('is never moved by a business answer or a protocol failure', async ()=>{
112
+ const { breaker } = await fresh();
113
+ for(let index = 0; index < 4; index += 1){
114
+ await call(breaker, Effect.fail(new Declined({})));
115
+ await call(breaker, Effect.fail(new ProtocolFailure({
116
+ reason: 'x'
117
+ })));
118
+ }
119
+ expect(await run(breaker.state('stock'))).toBe('closed');
120
+ });
121
+ it('obeys an operator: forced open refuses, disabled lets all through', async ()=>{
122
+ const { breaker } = await fresh();
123
+ await run(breaker.force('stock', 'forcedOpen'));
124
+ expect(tagOf(await call(breaker, fine))).toBe('BreakerOpen');
125
+ await run(breaker.force('stock', 'disabled'));
126
+ for(let index = 0; index < 8; index += 1)await call(breaker, down);
127
+ expect(await run(breaker.state('stock'))).toBe('disabled');
128
+ await run(breaker.force('stock', 'closed'));
129
+ expect(tagOf(await call(breaker, fine))).toBe('success');
130
+ });
131
+ it('keeps one key’s failures off another key', async ()=>{
132
+ const { breaker } = await fresh();
133
+ for(let index = 0; index < 4; index += 1)await call(breaker, down);
134
+ expect(await run(breaker.state('order'))).toBe('closed');
135
+ });
136
+ });
137
+ describe(`Bulkhead contract: ${name}`, ()=>{
138
+ it('refuses a call past its permits at once, and frees a permit however a call ends', async ()=>{
139
+ const { bulkhead } = await fresh();
140
+ const held = [
141
+ Effect.runFork(bulkhead.withPermit('stock')(Effect.never)),
142
+ Effect.runFork(bulkhead.withPermit('stock')(Effect.never))
143
+ ];
144
+ await new Promise((resolve)=>setTimeout(resolve, 0));
145
+ expect(await run(bulkhead.inUse('stock'))).toBe(2);
146
+ const refused = await run(Effect.exit(bulkhead.withPermit('stock')(Effect.succeed('late'))));
147
+ expect(tagOf(refused)).toBe('BulkheadFull');
148
+ await run(Fiber.interrupt(held[0]));
149
+ await run(Effect.exit(bulkhead.withPermit('stock')(Effect.fail(new Unavailable({
150
+ dependency: 'stock'
151
+ })))));
152
+ expect(await run(bulkhead.inUse('stock'))).toBe(1);
153
+ await run(Fiber.interrupt(held[1]));
154
+ expect(await run(bulkhead.inUse('stock'))).toBe(0);
155
+ });
156
+ });
157
+ };
158
+
159
+ //# sourceMappingURL=breaker.contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/contracts/breaker.contract.ts"],"sourcesContent":["import {\n Declined,\n Overloaded,\n ProtocolFailure,\n Unavailable,\n} from '@entifix/core';\nimport type {\n BreakerDials,\n Bulkhead,\n CircuitBreaker,\n} from '@entifix/transactions';\nimport { Effect, Exit, Fiber } from 'effect';\nimport { describe, expect, it } from 'vitest';\n\nimport type { ContractClock } from './idempotency-store.contract.js';\n\n/** What a case is handed: a breaker and a bulkhead over its clock. */\nexport interface BreakerUnderTest {\n readonly breaker: CircuitBreaker;\n readonly bulkhead: Bulkhead;\n}\n\n/** The dials the cases are written against. */\nexport const BREAKER_CONTRACT_DIALS: BreakerDials = {\n windowType: 'count',\n windowSize: 4,\n failureRateThreshold: 0.5,\n slowCallRateThreshold: 1,\n slowCallDurationMs: 100,\n minimumCalls: 4,\n waitInOpenMs: 1_000,\n halfOpenPermits: 2,\n};\n\n/**\n * What every breaker and bulkhead must guarantee\n * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)):\n * a window that opens at its failure or slow-call rate and not before its\n * minimum; an open breaker that refuses without calling, and lets probes\n * through once its wait has passed; probes that close it or reopen it; a\n * `Retry-After` that opens it at once and for as long as was asked; business\n * and protocol failures that never move it; the forced states; and a full\n * bulkhead that refuses rather than queues.\n *\n * `make` builds a fresh pair over the case's clock, with\n * {@link BREAKER_CONTRACT_DIALS} and two bulkhead permits.\n */\nexport const describeBreakerContract = (\n name: string,\n make: (clock: ContractClock) => Effect.Effect<BreakerUnderTest, unknown>,\n): void => {\n const run = <A, E>(effect: Effect.Effect<A, E>) => Effect.runPromise(effect);\n const fresh = async () => {\n let time = Date.UTC(2026, 0, 1);\n const clock: ContractClock = { now: () => time };\n const subject = await run(make(clock));\n return {\n ...subject,\n advance: (ms: number) => {\n time += ms;\n },\n };\n };\n\n const down = Effect.fail(new Unavailable({ dependency: 'stock' }));\n const fine = Effect.succeed('ok');\n\n const call = <A, E>(breaker: CircuitBreaker, effect: Effect.Effect<A, E>) =>\n run(Effect.exit(breaker.guard('stock')(effect)));\n\n const tagOf = (exit: Exit.Exit<unknown, unknown>) =>\n Exit.isFailure(exit)\n ? (Exit.findErrorOption(exit) as { value?: { _tag?: string } }).value\n ?._tag\n : 'success';\n\n describe(`CircuitBreaker contract: ${name}`, () => {\n it('stays closed below the minimum number of calls', async () => {\n const { breaker } = await fresh();\n for (let index = 0; index < 3; index += 1) await call(breaker, down);\n\n expect(await run(breaker.state('stock'))).toBe('closed');\n });\n\n it('opens at the failure rate and refuses without calling', async () => {\n const { breaker } = await fresh();\n await call(breaker, fine);\n await call(breaker, fine);\n await call(breaker, down);\n await call(breaker, down);\n // A call that ran would end in this defect, not in `BreakerOpen`.\n const refused = await call(breaker, Effect.die('the call was made'));\n\n expect(await run(breaker.state('stock'))).toBe('open');\n expect(tagOf(refused)).toBe('BreakerOpen');\n });\n\n it('opens on slow calls even when every call succeeded', async () => {\n const subject = await fresh();\n const slow = Effect.sync(() => subject.advance(150));\n for (let index = 0; index < 4; index += 1)\n await call(subject.breaker, slow);\n\n expect(await run(subject.breaker.state('stock'))).toBe('open');\n });\n\n it('goes half-open after its wait, and closes when the probes succeed', async () => {\n const subject = await fresh();\n for (let index = 0; index < 4; index += 1)\n await call(subject.breaker, down);\n subject.advance(1_000);\n\n expect(await run(subject.breaker.state('stock'))).toBe('halfOpen');\n await call(subject.breaker, fine);\n await call(subject.breaker, fine);\n expect(await run(subject.breaker.state('stock'))).toBe('closed');\n });\n\n it('reopens when the probes fail, and admits no more probes than its permits', async () => {\n const subject = await fresh();\n for (let index = 0; index < 4; index += 1)\n await call(subject.breaker, down);\n subject.advance(1_000);\n\n const gate = Effect.never;\n const first = Effect.runFork(subject.breaker.guard('stock')(gate));\n const second = Effect.runFork(subject.breaker.guard('stock')(gate));\n await new Promise(resolve => setTimeout(resolve, 0));\n expect(tagOf(await call(subject.breaker, fine))).toBe('BreakerOpen');\n await run(Fiber.interrupt(first));\n await run(Fiber.interrupt(second));\n\n const reprobe = await fresh();\n for (let index = 0; index < 4; index += 1)\n await call(reprobe.breaker, down);\n reprobe.advance(1_000);\n await call(reprobe.breaker, down);\n await call(reprobe.breaker, fine);\n expect(await run(reprobe.breaker.state('stock'))).toBe('open');\n });\n\n it('opens at once on Retry-After, for at least as long as was asked', async () => {\n const subject = await fresh();\n\n await call(\n subject.breaker,\n Effect.fail(new Overloaded({ retryAfterSeconds: 5 })),\n );\n expect(await run(subject.breaker.state('stock'))).toBe('open');\n subject.advance(1_000);\n expect(await run(subject.breaker.state('stock'))).toBe('open');\n subject.advance(4_000);\n expect(await run(subject.breaker.state('stock'))).toBe('halfOpen');\n });\n\n it('is never moved by a business answer or a protocol failure', async () => {\n const { breaker } = await fresh();\n for (let index = 0; index < 4; index += 1) {\n await call(breaker, Effect.fail(new Declined({})));\n await call(breaker, Effect.fail(new ProtocolFailure({ reason: 'x' })));\n }\n\n expect(await run(breaker.state('stock'))).toBe('closed');\n });\n\n it('obeys an operator: forced open refuses, disabled lets all through', async () => {\n const { breaker } = await fresh();\n\n await run(breaker.force('stock', 'forcedOpen'));\n expect(tagOf(await call(breaker, fine))).toBe('BreakerOpen');\n\n await run(breaker.force('stock', 'disabled'));\n for (let index = 0; index < 8; index += 1) await call(breaker, down);\n expect(await run(breaker.state('stock'))).toBe('disabled');\n\n await run(breaker.force('stock', 'closed'));\n expect(tagOf(await call(breaker, fine))).toBe('success');\n });\n\n it('keeps one key’s failures off another key', async () => {\n const { breaker } = await fresh();\n for (let index = 0; index < 4; index += 1) await call(breaker, down);\n\n expect(await run(breaker.state('order'))).toBe('closed');\n });\n });\n\n describe(`Bulkhead contract: ${name}`, () => {\n it('refuses a call past its permits at once, and frees a permit however a call ends', async () => {\n const { bulkhead } = await fresh();\n const held = [\n Effect.runFork(bulkhead.withPermit('stock')(Effect.never)),\n Effect.runFork(bulkhead.withPermit('stock')(Effect.never)),\n ];\n await new Promise(resolve => setTimeout(resolve, 0));\n\n expect(await run(bulkhead.inUse('stock'))).toBe(2);\n const refused = await run(\n Effect.exit(bulkhead.withPermit('stock')(Effect.succeed('late'))),\n );\n expect(tagOf(refused)).toBe('BulkheadFull');\n\n await run(Fiber.interrupt(held[0] as Fiber.Fiber<unknown, unknown>));\n await run(\n Effect.exit(\n bulkhead.withPermit('stock')(\n Effect.fail(new Unavailable({ dependency: 'stock' })),\n ),\n ),\n );\n expect(await run(bulkhead.inUse('stock'))).toBe(1);\n await run(Fiber.interrupt(held[1] as Fiber.Fiber<unknown, unknown>));\n expect(await run(bulkhead.inUse('stock'))).toBe(0);\n });\n });\n};\n"],"names":["Declined","Overloaded","ProtocolFailure","Unavailable","Effect","Exit","Fiber","describe","expect","it","BREAKER_CONTRACT_DIALS","windowType","windowSize","failureRateThreshold","slowCallRateThreshold","slowCallDurationMs","minimumCalls","waitInOpenMs","halfOpenPermits","describeBreakerContract","name","make","run","effect","runPromise","fresh","time","Date","UTC","clock","now","subject","advance","ms","down","fail","dependency","fine","succeed","call","breaker","exit","guard","tagOf","isFailure","findErrorOption","value","_tag","index","state","toBe","refused","die","slow","sync","gate","never","first","runFork","second","Promise","resolve","setTimeout","interrupt","reprobe","retryAfterSeconds","reason","force","bulkhead","held","withPermit","inUse"],"mappings":";AAAA,SACEA,QAAQ,EACRC,UAAU,EACVC,eAAe,EACfC,WAAW,QACN,gBAAgB;AAMvB,SAASC,MAAM,EAAEC,IAAI,EAAEC,KAAK,QAAQ,SAAS;AAC7C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAU9C,6CAA6C,GAC7C,OAAO,MAAMC,yBAAuC;IAClDC,YAAY;IACZC,YAAY;IACZC,sBAAsB;IACtBC,uBAAuB;IACvBC,oBAAoB;IACpBC,cAAc;IACdC,cAAc;IACdC,iBAAiB;AACnB,EAAE;AAEF;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,0BAA0B,CACrCC,MACAC;IAEA,MAAMC,MAAM,CAAOC,SAAgCnB,OAAOoB,UAAU,CAACD;IACrE,MAAME,QAAQ;QACZ,IAAIC,OAAOC,KAAKC,GAAG,CAAC,MAAM,GAAG;QAC7B,MAAMC,QAAuB;YAAEC,KAAK,IAAMJ;QAAK;QAC/C,MAAMK,UAAU,MAAMT,IAAID,KAAKQ;QAC/B,OAAO,aACFE;YACHC,SAAS,CAACC;gBACRP,QAAQO;YACV;;IAEJ;IAEA,MAAMC,OAAO9B,OAAO+B,IAAI,CAAC,IAAIhC,YAAY;QAAEiC,YAAY;IAAQ;IAC/D,MAAMC,OAAOjC,OAAOkC,OAAO,CAAC;IAE5B,MAAMC,OAAO,CAAOC,SAAyBjB,SAC3CD,IAAIlB,OAAOqC,IAAI,CAACD,QAAQE,KAAK,CAAC,SAASnB;IAEzC,MAAMoB,QAAQ,CAACF;YAET;eADJpC,KAAKuC,SAAS,CAACH,SACX,8BAAA,AAACpC,KAAKwC,eAAe,CAACJ,MAAwCK,KAAK,qBAAnE,4BACIC,IAAI,GACR;;IAENxC,SAAS,CAAC,yBAAyB,EAAEa,MAAM,EAAE;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,GAAGA,QAAQ,GAAGA,SAAS,EAAG,MAAMT,KAAKC,SAASN;YAE/D1B,OAAO,MAAMc,IAAIkB,QAAQS,KAAK,CAAC,WAAWC,IAAI,CAAC;QACjD;IACF;IAEA3C,SAAS,CAAC,mBAAmB,EAAEa,MAAM,EAAE;QACrCX,GAAG,mFAAmF;YACpF,MAAM,EAAE2D,QAAQ,EAAE,GAAG,MAAM3C;YAC3B,MAAM4C,OAAO;gBACXjE,OAAOsD,OAAO,CAACU,SAASE,UAAU,CAAC,SAASlE,OAAOoD,KAAK;gBACxDpD,OAAOsD,OAAO,CAACU,SAASE,UAAU,CAAC,SAASlE,OAAOoD,KAAK;aACzD;YACD,MAAM,IAAII,QAAQC,CAAAA,UAAWC,WAAWD,SAAS;YAEjDrD,OAAO,MAAMc,IAAI8C,SAASG,KAAK,CAAC,WAAWrB,IAAI,CAAC;YAChD,MAAMC,UAAU,MAAM7B,IACpBlB,OAAOqC,IAAI,CAAC2B,SAASE,UAAU,CAAC,SAASlE,OAAOkC,OAAO,CAAC;YAE1D9B,OAAOmC,MAAMQ,UAAUD,IAAI,CAAC;YAE5B,MAAM5B,IAAIhB,MAAMyD,SAAS,CAACM,IAAI,CAAC,EAAE;YACjC,MAAM/C,IACJlB,OAAOqC,IAAI,CACT2B,SAASE,UAAU,CAAC,SAClBlE,OAAO+B,IAAI,CAAC,IAAIhC,YAAY;gBAAEiC,YAAY;YAAQ;YAIxD5B,OAAO,MAAMc,IAAI8C,SAASG,KAAK,CAAC,WAAWrB,IAAI,CAAC;YAChD,MAAM5B,IAAIhB,MAAMyD,SAAS,CAACM,IAAI,CAAC,EAAE;YACjC7D,OAAO,MAAMc,IAAI8C,SAASG,KAAK,CAAC,WAAWrB,IAAI,CAAC;QAClD;IACF;AACF,EAAE"}
@@ -0,0 +1,16 @@
1
+ import { type FragmentCatalog } from '@entifix/business/flow';
2
+ import type { FlowEngine } from '@entifix/transactions';
3
+ import type { FakeParticipant } from '../doubles/flow-engine.js';
4
+ /** The catalog every case composes its slips from. */
5
+ export declare const flowEngineContractCatalog: FragmentCatalog;
6
+ /**
7
+ * What every {@link FlowEngine} must guarantee, whatever runs it: a start is
8
+ * idempotent on its key, a failure before the commit point compensates and one
9
+ * after it suspends, a wait takes the signal it waits for and no other, and an
10
+ * unknown flow is a typed `FlowNotFound`.
11
+ *
12
+ * `make` builds a fresh engine over the contract's catalog and the participant
13
+ * a case supplies.
14
+ */
15
+ export declare const describeFlowEngineContract: (name: string, make: (catalog: FragmentCatalog, participant: FakeParticipant) => FlowEngine | Promise<FlowEngine>) => void;
16
+ //# sourceMappingURL=flow-engine.contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-engine.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/flow-engine.contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EAKrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AA+BjE,sDAAsD;AACtD,eAAO,MAAM,yBAAyB,EAAE,eAKtC,CAAC;AA6BH;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,GACrC,MAAM,MAAM,EACZ,MAAM,CACJ,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,eAAe,KACzB,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,KACpC,IA2HF,CAAC"}
@@ -0,0 +1,199 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { defineCatalog, defineFragment, fragmentRef } from '@entifix/business/flow';
3
+ import { Declined } from '@entifix/core';
4
+ import { Effect, Schedule, Schema } from 'effect';
5
+ import { describe, expect, it } from 'vitest';
6
+ const contract = {
7
+ input: Schema.Unknown,
8
+ output: Schema.Unknown,
9
+ failure: Schema.Unknown
10
+ };
11
+ const fragment = (id, kind)=>defineFragment(_extends({
12
+ id: `contract.${id}`,
13
+ version: 1,
14
+ module: 'contract',
15
+ kind,
16
+ participant: 'contract',
17
+ call: {
18
+ method: 'POST',
19
+ path: `/api/${id}`
20
+ }
21
+ }, kind === 'compensatable' ? {
22
+ compensation: {
23
+ method: 'DELETE',
24
+ path: `/api/${id}/:id`
25
+ }
26
+ } : {}, {
27
+ cardinality: 'one',
28
+ contract
29
+ }));
30
+ const hold = fragment('hold', 'compensatable');
31
+ const take = fragment('take', 'pivot');
32
+ const settle = fragment('settle', 'retriable');
33
+ const wait = fragment('await', 'wait');
34
+ /** The catalog every case composes its slips from. */ export const flowEngineContractCatalog = defineCatalog([
35
+ hold,
36
+ take,
37
+ settle,
38
+ wait
39
+ ]);
40
+ const stepOf = (descriptor)=>({
41
+ ref: fragmentRef(descriptor),
42
+ step: descriptor.id.replace('contract.', ''),
43
+ cardinality: 'one'
44
+ });
45
+ const slipOf = (flowId, steps)=>({
46
+ slipVersion: 1,
47
+ flowId,
48
+ recipe: 'contract',
49
+ stages: [
50
+ {
51
+ name: 'main',
52
+ steps: steps.map(stepOf)
53
+ }
54
+ ],
55
+ resolution: [],
56
+ composedAt: '2026-01-01T00:00:00.000Z'
57
+ });
58
+ const failing = (failAt)=>(step)=>step.step === failAt ? Effect.fail(new Declined({
59
+ reason: 'refused'
60
+ })) : Effect.succeed({
61
+ ok: true
62
+ });
63
+ const succeeding = ()=>Effect.succeed({
64
+ ok: true
65
+ });
66
+ /**
67
+ * What every {@link FlowEngine} must guarantee, whatever runs it: a start is
68
+ * idempotent on its key, a failure before the commit point compensates and one
69
+ * after it suspends, a wait takes the signal it waits for and no other, and an
70
+ * unknown flow is a typed `FlowNotFound`.
71
+ *
72
+ * `make` builds a fresh engine over the contract's catalog and the participant
73
+ * a case supplies.
74
+ */ export const describeFlowEngineContract = (name, make)=>{
75
+ const run = (effect)=>Effect.runPromise(effect);
76
+ /**
77
+ * The flow's status once it has stopped moving. A start answers the flow id,
78
+ * never the outcome — a durable engine runs the slip detached — so a case
79
+ * reads the state the flow comes to rest in, a wait included.
80
+ */ const settled = (engine, flowId)=>run(engine.status(flowId).pipe(Effect.repeat({
81
+ until: (status)=>status.state !== 'running',
82
+ schedule: Schedule.spaced('10 millis'),
83
+ times: 200
84
+ })));
85
+ const state = async (engine, flowId)=>(await settled(engine, flowId)).state;
86
+ describe(`FlowEngine contract: ${name}`, ()=>{
87
+ it('answers the slip’s flow id, and the same one for a repeated key', async ()=>{
88
+ const engine = await make(flowEngineContractCatalog, succeeding);
89
+ const slip = slipOf('flow-1', [
90
+ hold,
91
+ take,
92
+ settle
93
+ ]);
94
+ const first = await run(engine.start(slip, 'key-1'));
95
+ const again = await run(engine.start(slipOf('flow-2', [
96
+ hold
97
+ ]), 'key-1'));
98
+ expect(first).toEqual({
99
+ flowId: 'flow-1'
100
+ });
101
+ expect(again).toEqual({
102
+ flowId: 'flow-1'
103
+ });
104
+ });
105
+ it('completes a flow whose every step succeeds', async ()=>{
106
+ const engine = await make(flowEngineContractCatalog, succeeding);
107
+ await run(engine.start(slipOf('flow-1', [
108
+ hold,
109
+ take,
110
+ settle
111
+ ]), 'k'));
112
+ expect(await state(engine, 'flow-1')).toBe('completed');
113
+ });
114
+ it('compensates a failure before the commit point', async ()=>{
115
+ const engine = await make(flowEngineContractCatalog, failing('take'));
116
+ await run(engine.start(slipOf('flow-1', [
117
+ hold,
118
+ take,
119
+ settle
120
+ ]), 'k'));
121
+ expect(await state(engine, 'flow-1')).toBe('compensated');
122
+ });
123
+ it('suspends a failure after the commit point, at that step', async ()=>{
124
+ const engine = await make(flowEngineContractCatalog, failing('settle'));
125
+ await run(engine.start(slipOf('flow-1', [
126
+ hold,
127
+ take,
128
+ settle
129
+ ]), 'k'));
130
+ expect(await settled(engine, 'flow-1')).toMatchObject({
131
+ state: 'suspended',
132
+ step: 'settle'
133
+ });
134
+ });
135
+ it('waits for the signal it waits for, and refuses any other', async ()=>{
136
+ const engine = await make(flowEngineContractCatalog, succeeding);
137
+ await run(engine.start(slipOf('flow-1', [
138
+ take,
139
+ wait,
140
+ settle
141
+ ]), 'k'));
142
+ expect(await state(engine, 'flow-1')).toBe('waiting');
143
+ const wrong = await run(Effect.flip(engine.signal('flow-1', 'elsewhere', {})));
144
+ expect(wrong._tag).toBe('FlowSignalRejected');
145
+ await run(engine.signal('flow-1', 'await', {
146
+ delivered: true
147
+ }));
148
+ expect(await state(engine, 'flow-1')).toBe('completed');
149
+ const late = await run(Effect.flip(engine.signal('flow-1', 'await', {})));
150
+ expect(late._tag).toBe('FlowSignalRejected');
151
+ });
152
+ it('completes a wait by what it is correlated with', async ()=>{
153
+ const engine = await make(flowEngineContractCatalog, succeeding);
154
+ const slip = slipOf('flow-1', [
155
+ take,
156
+ wait,
157
+ settle
158
+ ]);
159
+ const correlated = _extends({}, slip, {
160
+ stages: slip.stages.map((stage)=>_extends({}, stage, {
161
+ steps: stage.steps.map((step)=>step.step === 'await' ? _extends({}, step, {
162
+ parameters: {
163
+ correlation: 'order-7'
164
+ }
165
+ }) : step)
166
+ }))
167
+ });
168
+ await run(engine.start(correlated, 'k'));
169
+ expect(await state(engine, 'flow-1')).toBe('waiting');
170
+ const stranger = await run(Effect.flip(engine.signalCorrelated('order-8', 'await', {})));
171
+ expect(stranger._tag).toBe('FlowNotFound');
172
+ await run(engine.signalCorrelated('order-7', 'await', {
173
+ delivered: true
174
+ }));
175
+ expect(await state(engine, 'flow-1')).toBe('completed');
176
+ });
177
+ it('interrupts a waiting flow', async ()=>{
178
+ const engine = await make(flowEngineContractCatalog, succeeding);
179
+ await run(engine.start(slipOf('flow-1', [
180
+ take,
181
+ wait
182
+ ]), 'k'));
183
+ expect(await state(engine, 'flow-1')).toBe('waiting');
184
+ await run(engine.interrupt('flow-1'));
185
+ expect(await state(engine, 'flow-1')).toBe('interrupted');
186
+ });
187
+ it('answers FlowNotFound for a flow it never started', async ()=>{
188
+ const engine = await make(flowEngineContractCatalog, succeeding);
189
+ for (const effect of [
190
+ engine.status('nope'),
191
+ engine.signal('nope', 'await', {}),
192
+ engine.signalCorrelated('nope', 'await', {}),
193
+ engine.interrupt('nope')
194
+ ])expect((await run(Effect.flip(effect)))._tag).toBe('FlowNotFound');
195
+ });
196
+ });
197
+ };
198
+
199
+ //# sourceMappingURL=flow-engine.contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/contracts/flow-engine.contract.ts"],"sourcesContent":["import {\n defineCatalog,\n defineFragment,\n type FragmentCatalog,\n type FragmentDescriptor,\n fragmentRef,\n type Slip,\n type SlipStep,\n} from '@entifix/business/flow';\nimport { Declined } from '@entifix/core';\nimport type { FlowEngine } from '@entifix/transactions';\nimport { Effect, Schedule, Schema } from 'effect';\nimport { describe, expect, it } from 'vitest';\n\nimport type { FakeParticipant } from '../doubles/flow-engine.js';\n\nconst contract = {\n input: Schema.Unknown,\n output: Schema.Unknown,\n failure: Schema.Unknown,\n};\n\nconst fragment = (\n id: string,\n kind: FragmentDescriptor['kind'],\n): FragmentDescriptor =>\n defineFragment({\n id: `contract.${id}`,\n version: 1,\n module: 'contract',\n kind,\n participant: 'contract',\n call: { method: 'POST', path: `/api/${id}` },\n ...(kind === 'compensatable'\n ? { compensation: { method: 'DELETE', path: `/api/${id}/:id` } as const }\n : {}),\n cardinality: 'one',\n contract,\n });\n\nconst hold = fragment('hold', 'compensatable');\nconst take = fragment('take', 'pivot');\nconst settle = fragment('settle', 'retriable');\nconst wait = fragment('await', 'wait');\n\n/** The catalog every case composes its slips from. */\nexport const flowEngineContractCatalog: FragmentCatalog = defineCatalog([\n hold,\n take,\n settle,\n wait,\n]);\n\nconst stepOf = (descriptor: FragmentDescriptor): SlipStep => ({\n ref: fragmentRef(descriptor),\n step: descriptor.id.replace('contract.', ''),\n cardinality: 'one',\n});\n\nconst slipOf = (\n flowId: string,\n steps: readonly FragmentDescriptor[],\n): Slip => ({\n slipVersion: 1,\n flowId,\n recipe: 'contract',\n stages: [{ name: 'main', steps: steps.map(stepOf) }],\n resolution: [],\n composedAt: '2026-01-01T00:00:00.000Z',\n});\n\nconst failing =\n (failAt: string): FakeParticipant =>\n step =>\n step.step === failAt\n ? Effect.fail(new Declined({ reason: 'refused' }))\n : Effect.succeed({ ok: true });\n\nconst succeeding: FakeParticipant = () => Effect.succeed({ ok: true });\n\n/**\n * What every {@link FlowEngine} must guarantee, whatever runs it: a start is\n * idempotent on its key, a failure before the commit point compensates and one\n * after it suspends, a wait takes the signal it waits for and no other, and an\n * unknown flow is a typed `FlowNotFound`.\n *\n * `make` builds a fresh engine over the contract's catalog and the participant\n * a case supplies.\n */\nexport const describeFlowEngineContract = (\n name: string,\n make: (\n catalog: FragmentCatalog,\n participant: FakeParticipant,\n ) => FlowEngine | Promise<FlowEngine>,\n): void => {\n const run = <A, E>(effect: Effect.Effect<A, E>) => Effect.runPromise(effect);\n /**\n * The flow's status once it has stopped moving. A start answers the flow id,\n * never the outcome — a durable engine runs the slip detached — so a case\n * reads the state the flow comes to rest in, a wait included.\n */\n const settled = (engine: FlowEngine, flowId: string) =>\n run(\n engine.status(flowId).pipe(\n Effect.repeat({\n until: status => status.state !== 'running',\n schedule: Schedule.spaced('10 millis'),\n times: 200,\n }),\n ),\n );\n const state = async (engine: FlowEngine, flowId: string) =>\n (await settled(engine, flowId)).state;\n\n describe(`FlowEngine contract: ${name}`, () => {\n it('answers the slip’s flow id, and the same one for a repeated key', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n const slip = slipOf('flow-1', [hold, take, settle]);\n\n const first = await run(engine.start(slip, 'key-1'));\n const again = await run(engine.start(slipOf('flow-2', [hold]), 'key-1'));\n\n expect(first).toEqual({ flowId: 'flow-1' });\n expect(again).toEqual({ flowId: 'flow-1' });\n });\n\n it('completes a flow whose every step succeeds', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await state(engine, 'flow-1')).toBe('completed');\n });\n\n it('compensates a failure before the commit point', async () => {\n const engine = await make(flowEngineContractCatalog, failing('take'));\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await state(engine, 'flow-1')).toBe('compensated');\n });\n\n it('suspends a failure after the commit point, at that step', async () => {\n const engine = await make(flowEngineContractCatalog, failing('settle'));\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await settled(engine, 'flow-1')).toMatchObject({\n state: 'suspended',\n step: 'settle',\n });\n });\n\n it('waits for the signal it waits for, and refuses any other', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [take, wait, settle]), 'k'));\n\n expect(await state(engine, 'flow-1')).toBe('waiting');\n const wrong = await run(\n Effect.flip(engine.signal('flow-1', 'elsewhere', {})),\n );\n expect(wrong._tag).toBe('FlowSignalRejected');\n\n await run(engine.signal('flow-1', 'await', { delivered: true }));\n expect(await state(engine, 'flow-1')).toBe('completed');\n\n const late = await run(Effect.flip(engine.signal('flow-1', 'await', {})));\n expect(late._tag).toBe('FlowSignalRejected');\n });\n\n it('completes a wait by what it is correlated with', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n const slip = slipOf('flow-1', [take, wait, settle]);\n const correlated: Slip = {\n ...slip,\n stages: slip.stages.map(stage => ({\n ...stage,\n steps: stage.steps.map(step =>\n step.step === 'await'\n ? { ...step, parameters: { correlation: 'order-7' } }\n : step,\n ),\n })),\n };\n await run(engine.start(correlated, 'k'));\n expect(await state(engine, 'flow-1')).toBe('waiting');\n\n const stranger = await run(\n Effect.flip(engine.signalCorrelated('order-8', 'await', {})),\n );\n expect(stranger._tag).toBe('FlowNotFound');\n\n await run(\n engine.signalCorrelated('order-7', 'await', { delivered: true }),\n );\n expect(await state(engine, 'flow-1')).toBe('completed');\n });\n\n it('interrupts a waiting flow', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [take, wait]), 'k'));\n expect(await state(engine, 'flow-1')).toBe('waiting');\n\n await run(engine.interrupt('flow-1'));\n\n expect(await state(engine, 'flow-1')).toBe('interrupted');\n });\n\n it('answers FlowNotFound for a flow it never started', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n\n for (const effect of [\n engine.status('nope'),\n engine.signal('nope', 'await', {}),\n engine.signalCorrelated('nope', 'await', {}),\n engine.interrupt('nope'),\n ])\n expect((await run(Effect.flip(effect)))._tag).toBe('FlowNotFound');\n });\n });\n};\n"],"names":["defineCatalog","defineFragment","fragmentRef","Declined","Effect","Schedule","Schema","describe","expect","it","contract","input","Unknown","output","failure","fragment","id","kind","version","module","participant","call","method","path","compensation","cardinality","hold","take","settle","wait","flowEngineContractCatalog","stepOf","descriptor","ref","step","replace","slipOf","flowId","steps","slipVersion","recipe","stages","name","map","resolution","composedAt","failing","failAt","fail","reason","succeed","ok","succeeding","describeFlowEngineContract","make","run","effect","runPromise","settled","engine","status","pipe","repeat","until","state","schedule","spaced","times","slip","first","start","again","toEqual","toBe","toMatchObject","wrong","flip","signal","_tag","delivered","late","correlated","stage","parameters","correlation","stranger","signalCorrelated","interrupt"],"mappings":";AAAA,SACEA,aAAa,EACbC,cAAc,EAGdC,WAAW,QAGN,yBAAyB;AAChC,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,SAASC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,QAAQ,SAAS;AAClD,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAI9C,MAAMC,WAAW;IACfC,OAAOL,OAAOM,OAAO;IACrBC,QAAQP,OAAOM,OAAO;IACtBE,SAASR,OAAOM,OAAO;AACzB;AAEA,MAAMG,WAAW,CACfC,IACAC,OAEAhB,eAAe;QACbe,IAAI,CAAC,SAAS,EAAEA,IAAI;QACpBE,SAAS;QACTC,QAAQ;QACRF;QACAG,aAAa;QACbC,MAAM;YAAEC,QAAQ;YAAQC,MAAM,CAAC,KAAK,EAAEP,IAAI;QAAC;OACvCC,SAAS,kBACT;QAAEO,cAAc;YAAEF,QAAQ;YAAUC,MAAM,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B,gBAAgB,CAAC,WAAW,SAAS,CAAC;YAE3D9E,OAAO6E,SAASP,IAAI,EAAEL,IAAI,CAAC;YAE3B,MAAMlB,IACJI,OAAO2B,gBAAgB,CAAC,WAAW,SAAS;gBAAEP,WAAW;YAAK;YAEhEvE,OAAO,MAAMwD,MAAML,QAAQ,WAAWc,IAAI,CAAC;QAC7C;QAEAhE,GAAG,6BAA6B;YAC9B,MAAMkD,SAAS,MAAML,KAAKxB,2BAA2BsB;YACrD,MAAMG,IAAII,OAAOW,KAAK,CAAClC,OAAO,UAAU;gBAACT;gBAAME;aAAK,GAAG;YACvDrB,OAAO,MAAMwD,MAAML,QAAQ,WAAWc,IAAI,CAAC;YAE3C,MAAMlB,IAAII,OAAO4B,SAAS,CAAC;YAE3B/E,OAAO,MAAMwD,MAAML,QAAQ,WAAWc,IAAI,CAAC;QAC7C;QAEAhE,GAAG,oDAAoD;YACrD,MAAMkD,SAAS,MAAML,KAAKxB,2BAA2BsB;YAErD,KAAK,MAAMI,UAAU;gBACnBG,OAAOC,MAAM,CAAC;gBACdD,OAAOkB,MAAM,CAAC,QAAQ,SAAS,CAAC;gBAChClB,OAAO2B,gBAAgB,CAAC,QAAQ,SAAS,CAAC;gBAC1C3B,OAAO4B,SAAS,CAAC;aAClB,CACC/E,OAAO,AAAC,CAAA,MAAM+C,IAAInD,OAAOwE,IAAI,CAACpB,QAAO,EAAGsB,IAAI,EAAEL,IAAI,CAAC;QACvD;IACF;AACF,EAAE"}
@@ -0,0 +1,17 @@
1
+ import type { IdempotencyStore } from '@entifix/business';
2
+ import { Effect } from 'effect';
3
+ /** A clock a case can move. */
4
+ export interface ContractClock {
5
+ now: () => number;
6
+ }
7
+ /**
8
+ * What every {@link IdempotencyStore} must guarantee: one claim per dedup key
9
+ * even under a concurrent burst, a duplicate that sees the first request's
10
+ * fingerprint and state, a completed answer kept for replay, a released key
11
+ * free again, and an expired record treated as never written.
12
+ *
13
+ * `make` builds a fresh store over the case's clock and a retention of
14
+ * `retentionMs`.
15
+ */
16
+ export declare const describeIdempotencyStoreContract: (name: string, make: (clock: ContractClock, retentionMs: number) => Effect.Effect<IdempotencyStore, unknown>) => void;
17
+ //# sourceMappingURL=idempotency-store.contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency-store.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/idempotency-store.contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,+BAA+B;AAC/B,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,MAAM,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,gCAAgC,GAC3C,MAAM,MAAM,EACZ,MAAM,CACJ,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,MAAM,KAChB,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,OAAO,CAAC,KAC5C,IA+EF,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { Effect } from 'effect';
2
+ import { describe, expect, it } from 'vitest';
3
+ /**
4
+ * What every {@link IdempotencyStore} must guarantee: one claim per dedup key
5
+ * even under a concurrent burst, a duplicate that sees the first request's
6
+ * fingerprint and state, a completed answer kept for replay, a released key
7
+ * free again, and an expired record treated as never written.
8
+ *
9
+ * `make` builds a fresh store over the case's clock and a retention of
10
+ * `retentionMs`.
11
+ */ export const describeIdempotencyStoreContract = (name, make)=>{
12
+ const run = (effect)=>Effect.runPromise(effect);
13
+ const fresh = (start = Date.UTC(2026, 0, 1))=>{
14
+ const clock = {
15
+ now: ()=>start
16
+ };
17
+ return {
18
+ clock,
19
+ store: run(make(clock, 60000))
20
+ };
21
+ };
22
+ describe(`IdempotencyStore contract: ${name}`, ()=>{
23
+ it('claims a key once, and shows a duplicate the request in flight', async ()=>{
24
+ const store = await fresh().store;
25
+ expect(await run(store.claim('k', 'f-1'))).toEqual({
26
+ _tag: 'claimed'
27
+ });
28
+ expect(await run(store.claim('k', 'f-2'))).toMatchObject({
29
+ _tag: 'existing',
30
+ record: {
31
+ dedupKey: 'k',
32
+ fingerprint: 'f-1',
33
+ state: 'inFlight'
34
+ }
35
+ });
36
+ });
37
+ it('keeps a completed answer for a duplicate to replay', async ()=>{
38
+ const store = await fresh().store;
39
+ await run(store.claim('k', 'f-1'));
40
+ await run(store.complete('k', {
41
+ status: 201,
42
+ contentType: 'application/json',
43
+ body: '{"ok":true}'
44
+ }));
45
+ expect(await run(store.claim('k', 'f-1'))).toMatchObject({
46
+ _tag: 'existing',
47
+ record: {
48
+ state: 'completed',
49
+ response: {
50
+ status: 201,
51
+ body: '{"ok":true}'
52
+ }
53
+ }
54
+ });
55
+ });
56
+ it('frees a released key', async ()=>{
57
+ const store = await fresh().store;
58
+ await run(store.claim('k', 'f-1'));
59
+ await run(store.release('k'));
60
+ expect(await run(store.claim('k', 'f-1'))).toEqual({
61
+ _tag: 'claimed'
62
+ });
63
+ });
64
+ it('treats an expired record as never written', async ()=>{
65
+ const { clock, store: made } = fresh();
66
+ const store = await made;
67
+ await run(store.claim('k', 'f-1'));
68
+ const later = clock.now() + 60001;
69
+ clock.now = ()=>later;
70
+ expect(await run(store.claim('k', 'f-2'))).toEqual({
71
+ _tag: 'claimed'
72
+ });
73
+ });
74
+ // A sequential pass proves nothing about a race: fire the burst.
75
+ it('gives exactly one of a concurrent burst the claim', async ()=>{
76
+ const store = await fresh().store;
77
+ const claims = await run(Effect.all(Array.from({
78
+ length: 8
79
+ }, ()=>store.claim('k', 'f-1')), {
80
+ concurrency: 'unbounded'
81
+ }));
82
+ expect(claims.filter((claim)=>claim._tag === 'claimed')).toHaveLength(1);
83
+ });
84
+ it('keeps two dedup keys apart', async ()=>{
85
+ const store = await fresh().store;
86
+ await run(store.claim('caller-a|route|k', 'f-1'));
87
+ expect(await run(store.claim('caller-b|route|k', 'f-1'))).toEqual({
88
+ _tag: 'claimed'
89
+ });
90
+ });
91
+ });
92
+ };
93
+
94
+ //# sourceMappingURL=idempotency-store.contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/contracts/idempotency-store.contract.ts"],"sourcesContent":["import type { IdempotencyStore } from '@entifix/business';\nimport { Effect } from 'effect';\nimport { describe, expect, it } from 'vitest';\n\n/** A clock a case can move. */\nexport interface ContractClock {\n now: () => number;\n}\n\n/**\n * What every {@link IdempotencyStore} must guarantee: one claim per dedup key\n * even under a concurrent burst, a duplicate that sees the first request's\n * fingerprint and state, a completed answer kept for replay, a released key\n * free again, and an expired record treated as never written.\n *\n * `make` builds a fresh store over the case's clock and a retention of\n * `retentionMs`.\n */\nexport const describeIdempotencyStoreContract = (\n name: string,\n make: (\n clock: ContractClock,\n retentionMs: number,\n ) => Effect.Effect<IdempotencyStore, unknown>,\n): void => {\n const run = <A, E>(effect: Effect.Effect<A, E>) => Effect.runPromise(effect);\n const fresh = (start = Date.UTC(2026, 0, 1)) => {\n const clock: ContractClock = { now: () => start };\n return { clock, store: run(make(clock, 60_000)) };\n };\n\n describe(`IdempotencyStore contract: ${name}`, () => {\n it('claims a key once, and shows a duplicate the request in flight', async () => {\n const store = await fresh().store;\n\n expect(await run(store.claim('k', 'f-1'))).toEqual({ _tag: 'claimed' });\n expect(await run(store.claim('k', 'f-2'))).toMatchObject({\n _tag: 'existing',\n record: { dedupKey: 'k', fingerprint: 'f-1', state: 'inFlight' },\n });\n });\n\n it('keeps a completed answer for a duplicate to replay', async () => {\n const store = await fresh().store;\n await run(store.claim('k', 'f-1'));\n await run(\n store.complete('k', {\n status: 201,\n contentType: 'application/json',\n body: '{\"ok\":true}',\n }),\n );\n\n expect(await run(store.claim('k', 'f-1'))).toMatchObject({\n _tag: 'existing',\n record: {\n state: 'completed',\n response: { status: 201, body: '{\"ok\":true}' },\n },\n });\n });\n\n it('frees a released key', async () => {\n const store = await fresh().store;\n await run(store.claim('k', 'f-1'));\n await run(store.release('k'));\n\n expect(await run(store.claim('k', 'f-1'))).toEqual({ _tag: 'claimed' });\n });\n\n it('treats an expired record as never written', async () => {\n const { clock, store: made } = fresh();\n const store = await made;\n await run(store.claim('k', 'f-1'));\n const later = clock.now() + 60_001;\n clock.now = () => later;\n\n expect(await run(store.claim('k', 'f-2'))).toEqual({ _tag: 'claimed' });\n });\n\n // A sequential pass proves nothing about a race: fire the burst.\n it('gives exactly one of a concurrent burst the claim', async () => {\n const store = await fresh().store;\n\n const claims = await run(\n Effect.all(\n Array.from({ length: 8 }, () => store.claim('k', 'f-1')),\n { concurrency: 'unbounded' },\n ),\n );\n\n expect(claims.filter(claim => claim._tag === 'claimed')).toHaveLength(1);\n });\n\n it('keeps two dedup keys apart', async () => {\n const store = await fresh().store;\n await run(store.claim('caller-a|route|k', 'f-1'));\n\n expect(await run(store.claim('caller-b|route|k', 'f-1'))).toEqual({\n _tag: 'claimed',\n });\n });\n });\n};\n"],"names":["Effect","describe","expect","it","describeIdempotencyStoreContract","name","make","run","effect","runPromise","fresh","start","Date","UTC","clock","now","store","claim","toEqual","_tag","toMatchObject","record","dedupKey","fingerprint","state","complete","status","contentType","body","response","release","made","later","claims","all","Array","from","length","concurrency","filter","toHaveLength"],"mappings":"AACA,SAASA,MAAM,QAAQ,SAAS;AAChC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAO9C;;;;;;;;CAQC,GACD,OAAO,MAAMC,mCAAmC,CAC9CC,MACAC;IAKA,MAAMC,MAAM,CAAOC,SAAgCR,OAAOS,UAAU,CAACD;IACrE,MAAME,QAAQ,CAACC,QAAQC,KAAKC,GAAG,CAAC,MAAM,GAAG,EAAE;QACzC,MAAMC,QAAuB;YAAEC,KAAK,IAAMJ;QAAM;QAChD,OAAO;YAAEG;YAAOE,OAAOT,IAAID,KAAKQ,OAAO;QAAS;IAClD;IAEAb,SAAS,CAAC,2BAA2B,EAAEI,MAAM,EAAE;QAC7CF,GAAG,kEAAkE;YACnE,MAAMa,QAAQ,MA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YAAU;QACvE;QAEA,iEAAiE;QACjEhB,GAAG,qDAAqD;YACtD,MAAMa,QAAQ,MAAMN,QAAQM,KAAK;YAEjC,MAAMiB,SAAS,MAAM1B,IACnBP,OAAOkC,GAAG,CACRC,MAAMC,IAAI,CAAC;gBAAEC,QAAQ;YAAE,GAAG,IAAMrB,MAAMC,KAAK,CAAC,KAAK,SACjD;gBAAEqB,aAAa;YAAY;YAI/BpC,OAAO+B,OAAOM,MAAM,CAACtB,CAAAA,QAASA,MAAME,IAAI,KAAK,YAAYqB,YAAY,CAAC;QACxE;QAEArC,GAAG,8BAA8B;YAC/B,MAAMa,QAAQ,MAAMN,QAAQM,KAAK;YACjC,MAAMT,IAAIS,MAAMC,KAAK,CAAC,oBAAoB;YAE1Cf,OAAO,MAAMK,IAAIS,MAAMC,KAAK,CAAC,oBAAoB,SAASC,OAAO,CAAC;gBAChEC,MAAM;YACR;QACF;IACF;AACF,EAAE"}
@@ -1,7 +1,12 @@
1
+ export * from './breaker.contract.js';
1
2
  export * from './entity-facet-counter.contract.js';
2
3
  export * from './entity-repository.contract.js';
3
4
  export * from './failure.contract.js';
5
+ export * from './flow-engine.contract.js';
6
+ export * from './idempotency-store.contract.js';
7
+ export * from './outbox.contract.js';
4
8
  export * from './saga-store.contract.js';
5
9
  export * from './transaction-ports.contract.js';
6
10
  export * from './unit-of-work.contract.js';
11
+ export * from './variants.contract.js';
7
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC"}