@entifix/testing-unit 0.10.1 → 0.11.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.
- package/dist/contracts/flow-engine.contract.d.ts +16 -0
- package/dist/contracts/flow-engine.contract.d.ts.map +1 -0
- package/dist/contracts/flow-engine.contract.js +163 -0
- package/dist/contracts/flow-engine.contract.js.map +1 -0
- package/dist/contracts/idempotency-store.contract.d.ts +17 -0
- package/dist/contracts/idempotency-store.contract.d.ts.map +1 -0
- package/dist/contracts/idempotency-store.contract.js +94 -0
- package/dist/contracts/idempotency-store.contract.js.map +1 -0
- package/dist/contracts/index.d.ts +4 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +4 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/outbox.contract.d.ts +18 -0
- package/dist/contracts/outbox.contract.d.ts.map +1 -0
- package/dist/contracts/outbox.contract.js +117 -0
- package/dist/contracts/outbox.contract.js.map +1 -0
- package/dist/contracts/transaction-ports.contract.d.ts +1 -1
- package/dist/contracts/transaction-ports.contract.d.ts.map +1 -1
- package/dist/contracts/transaction-ports.contract.js +10 -1
- package/dist/contracts/transaction-ports.contract.js.map +1 -1
- package/dist/contracts/unit-of-work.contract.d.ts.map +1 -1
- package/dist/contracts/unit-of-work.contract.js +5 -0
- package/dist/contracts/unit-of-work.contract.js.map +1 -1
- package/dist/contracts/variants.contract.d.ts +15 -0
- package/dist/contracts/variants.contract.d.ts.map +1 -0
- package/dist/contracts/variants.contract.js +39 -0
- package/dist/contracts/variants.contract.js.map +1 -0
- package/dist/doubles/flow-engine.d.ts +22 -0
- package/dist/doubles/flow-engine.d.ts.map +1 -0
- package/dist/doubles/flow-engine.js +137 -0
- package/dist/doubles/flow-engine.js.map +1 -0
- package/dist/doubles/idempotency-store.d.ts +12 -0
- package/dist/doubles/idempotency-store.d.ts.map +1 -0
- package/dist/doubles/idempotency-store.js +40 -0
- package/dist/doubles/idempotency-store.js.map +1 -0
- package/dist/doubles/outbox.d.ts +15 -0
- package/dist/doubles/outbox.d.ts.map +1 -0
- package/dist/doubles/outbox.js +70 -0
- package/dist/doubles/outbox.js.map +1 -0
- package/dist/doubles/unit-of-work.d.ts +2 -3
- package/dist/doubles/unit-of-work.d.ts.map +1 -1
- package/dist/doubles/unit-of-work.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -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) => 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,CAAC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,KAAK,UAAU,KAC3E,IA8EF,CAAC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
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, 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
|
+
const state = async (engine, flowId)=>(await run(engine.status(flowId))).state;
|
|
77
|
+
describe(`FlowEngine contract: ${name}`, ()=>{
|
|
78
|
+
it('answers the slip’s flow id, and the same one for a repeated key', async ()=>{
|
|
79
|
+
const engine = make(flowEngineContractCatalog, succeeding);
|
|
80
|
+
const slip = slipOf('flow-1', [
|
|
81
|
+
hold,
|
|
82
|
+
take,
|
|
83
|
+
settle
|
|
84
|
+
]);
|
|
85
|
+
const first = await run(engine.start(slip, 'key-1'));
|
|
86
|
+
const again = await run(engine.start(slipOf('flow-2', [
|
|
87
|
+
hold
|
|
88
|
+
]), 'key-1'));
|
|
89
|
+
expect(first).toEqual({
|
|
90
|
+
flowId: 'flow-1'
|
|
91
|
+
});
|
|
92
|
+
expect(again).toEqual({
|
|
93
|
+
flowId: 'flow-1'
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
it('completes a flow whose every step succeeds', async ()=>{
|
|
97
|
+
const engine = make(flowEngineContractCatalog, succeeding);
|
|
98
|
+
await run(engine.start(slipOf('flow-1', [
|
|
99
|
+
hold,
|
|
100
|
+
take,
|
|
101
|
+
settle
|
|
102
|
+
]), 'k'));
|
|
103
|
+
expect(await state(engine, 'flow-1')).toBe('completed');
|
|
104
|
+
});
|
|
105
|
+
it('compensates a failure before the commit point', async ()=>{
|
|
106
|
+
const engine = make(flowEngineContractCatalog, failing('take'));
|
|
107
|
+
await run(engine.start(slipOf('flow-1', [
|
|
108
|
+
hold,
|
|
109
|
+
take,
|
|
110
|
+
settle
|
|
111
|
+
]), 'k'));
|
|
112
|
+
expect(await state(engine, 'flow-1')).toBe('compensated');
|
|
113
|
+
});
|
|
114
|
+
it('suspends a failure after the commit point, at that step', async ()=>{
|
|
115
|
+
const engine = make(flowEngineContractCatalog, failing('settle'));
|
|
116
|
+
await run(engine.start(slipOf('flow-1', [
|
|
117
|
+
hold,
|
|
118
|
+
take,
|
|
119
|
+
settle
|
|
120
|
+
]), 'k'));
|
|
121
|
+
expect(await run(engine.status('flow-1'))).toMatchObject({
|
|
122
|
+
state: 'suspended',
|
|
123
|
+
step: 'settle'
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
it('waits for the signal it waits for, and refuses any other', async ()=>{
|
|
127
|
+
const engine = make(flowEngineContractCatalog, succeeding);
|
|
128
|
+
await run(engine.start(slipOf('flow-1', [
|
|
129
|
+
take,
|
|
130
|
+
wait,
|
|
131
|
+
settle
|
|
132
|
+
]), 'k'));
|
|
133
|
+
expect(await state(engine, 'flow-1')).toBe('waiting');
|
|
134
|
+
const wrong = await run(Effect.flip(engine.signal('flow-1', 'elsewhere', {})));
|
|
135
|
+
expect(wrong._tag).toBe('FlowSignalRejected');
|
|
136
|
+
await run(engine.signal('flow-1', 'await', {
|
|
137
|
+
delivered: true
|
|
138
|
+
}));
|
|
139
|
+
expect(await state(engine, 'flow-1')).toBe('completed');
|
|
140
|
+
const late = await run(Effect.flip(engine.signal('flow-1', 'await', {})));
|
|
141
|
+
expect(late._tag).toBe('FlowSignalRejected');
|
|
142
|
+
});
|
|
143
|
+
it('interrupts a waiting flow', async ()=>{
|
|
144
|
+
const engine = make(flowEngineContractCatalog, succeeding);
|
|
145
|
+
await run(engine.start(slipOf('flow-1', [
|
|
146
|
+
take,
|
|
147
|
+
wait
|
|
148
|
+
]), 'k'));
|
|
149
|
+
await run(engine.interrupt('flow-1'));
|
|
150
|
+
expect(await state(engine, 'flow-1')).toBe('interrupted');
|
|
151
|
+
});
|
|
152
|
+
it('answers FlowNotFound for a flow it never started', async ()=>{
|
|
153
|
+
const engine = make(flowEngineContractCatalog, succeeding);
|
|
154
|
+
for (const effect of [
|
|
155
|
+
engine.status('nope'),
|
|
156
|
+
engine.signal('nope', 'await', {}),
|
|
157
|
+
engine.interrupt('nope')
|
|
158
|
+
])expect((await run(Effect.flip(effect)))._tag).toBe('FlowNotFound');
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
//# 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, 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: (catalog: FragmentCatalog, participant: FakeParticipant) => FlowEngine,\n): void => {\n const run = <A, E>(effect: Effect.Effect<A, E>) => Effect.runPromise(effect);\n const state = async (engine: FlowEngine, flowId: string) =>\n (await run(engine.status(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 = 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 = 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 = 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 = make(flowEngineContractCatalog, failing('settle'));\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await run(engine.status('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 = 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('interrupts a waiting flow', async () => {\n const engine = make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [take, wait]), 'k'));\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 = make(flowEngineContractCatalog, succeeding);\n\n for (const effect of [\n engine.status('nope'),\n engine.signal('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","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","state","engine","status","slip","first","start","again","toEqual","toBe","toMatchObject","wrong","flip","signal","_tag","delivered","late","interrupt"],"mappings":";AAAA,SACEA,aAAa,EACbC,cAAc,EAGdC,WAAW,QAGN,yBAAyB;AAChC,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AACxC,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,OAEAf,eAAe;QACbc,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,Q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OAAO,MAAMkD,MAAMC,QAAQ,WAAWO,IAAI,CAAC;YAC3C,MAAME,QAAQ,MAAMb,IAClBlD,OAAOgE,IAAI,CAACV,OAAOW,MAAM,CAAC,UAAU,aAAa,CAAC;YAEpD9D,OAAO4D,MAAMG,IAAI,EAAEL,IAAI,CAAC;YAExB,MAAMX,IAAII,OAAOW,MAAM,CAAC,UAAU,SAAS;gBAAEE,WAAW;YAAK;YAC7DhE,OAAO,MAAMkD,MAAMC,QAAQ,WAAWO,IAAI,CAAC;YAE3C,MAAMO,OAAO,MAAMlB,IAAIlD,OAAOgE,IAAI,CAACV,OAAOW,MAAM,CAAC,UAAU,SAAS,CAAC;YACrE9D,OAAOiE,KAAKF,IAAI,EAAEL,IAAI,CAAC;QACzB;QAEAzD,GAAG,6BAA6B;YAC9B,MAAMkD,SAASL,KAAKxB,2BAA2BsB;YAC/C,MAAMG,IAAII,OAAOI,KAAK,CAAC3B,OAAO,UAAU;gBAACT;gBAAME;aAAK,GAAG;YAEvD,MAAM0B,IAAII,OAAOe,SAAS,CAAC;YAE3BlE,OAAO,MAAMkD,MAAMC,QAAQ,WAAWO,IAAI,CAAC;QAC7C;QAEAzD,GAAG,oDAAoD;YACrD,MAAMkD,SAASL,KAAKxB,2BAA2BsB;YAE/C,KAAK,MAAMI,UAAU;gBACnBG,OAAOC,MAAM,CAAC;gBACdD,OAAOW,MAAM,CAAC,QAAQ,SAAS,CAAC;gBAChCX,OAAOe,SAAS,CAAC;aAClB,CACClE,OAAO,AAAC,CAAA,MAAM+C,IAAIlD,OAAOgE,IAAI,CAACb,QAAO,EAAGe,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,MAAMN,QAAQM,KAAK;YAEjCd,OAAO,MAAMK,IAAIS,MAAMC,KAAK,CAAC,KAAK,SAASC,OAAO,CAAC;gBAAEC,MAAM;YAAU;YACrEjB,OAAO,MAAMK,IAAIS,MAAMC,KAAK,CAAC,KAAK,SAASG,aAAa,CAAC;gBACvDD,MAAM;gBACNE,QAAQ;oBAAEC,UAAU;oBAAKC,aAAa;oBAAOC,OAAO;gBAA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/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,11 @@
|
|
|
1
1
|
export * from './entity-facet-counter.contract.js';
|
|
2
2
|
export * from './entity-repository.contract.js';
|
|
3
3
|
export * from './failure.contract.js';
|
|
4
|
+
export * from './flow-engine.contract.js';
|
|
5
|
+
export * from './idempotency-store.contract.js';
|
|
6
|
+
export * from './outbox.contract.js';
|
|
4
7
|
export * from './saga-store.contract.js';
|
|
5
8
|
export * from './transaction-ports.contract.js';
|
|
6
9
|
export * from './unit-of-work.contract.js';
|
|
10
|
+
export * from './variants.contract.js';
|
|
7
11
|
//# 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,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"}
|
package/dist/contracts/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export * from './entity-facet-counter.contract.js';
|
|
2
2
|
export * from './entity-repository.contract.js';
|
|
3
3
|
export * from './failure.contract.js';
|
|
4
|
+
export * from './flow-engine.contract.js';
|
|
5
|
+
export * from './idempotency-store.contract.js';
|
|
6
|
+
export * from './outbox.contract.js';
|
|
4
7
|
export * from './saga-store.contract.js';
|
|
5
8
|
export * from './transaction-ports.contract.js';
|
|
6
9
|
export * from './unit-of-work.contract.js';
|
|
10
|
+
export * from './variants.contract.js';
|
|
7
11
|
|
|
8
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contracts/index.ts"],"sourcesContent":["export * from './entity-facet-counter.contract.js';\nexport * from './entity-repository.contract.js';\nexport * from './failure.contract.js';\nexport * from './saga-store.contract.js';\nexport * from './transaction-ports.contract.js';\nexport * from './unit-of-work.contract.js';\n"],"names":[],"mappings":"AAAA,cAAc,qCAAqC;AACnD,cAAc,kCAAkC;AAChD,cAAc,wBAAwB;AACtC,cAAc,2BAA2B;AACzC,cAAc,kCAAkC;AAChD,cAAc,6BAA6B"}
|
|
1
|
+
{"version":3,"sources":["../../src/contracts/index.ts"],"sourcesContent":["export * from './entity-facet-counter.contract.js';\nexport * from './entity-repository.contract.js';\nexport * from './failure.contract.js';\nexport * from './flow-engine.contract.js';\nexport * from './idempotency-store.contract.js';\nexport * from './outbox.contract.js';\nexport * from './saga-store.contract.js';\nexport * from './transaction-ports.contract.js';\nexport * from './unit-of-work.contract.js';\nexport * from './variants.contract.js';\n"],"names":[],"mappings":"AAAA,cAAc,qCAAqC;AACnD,cAAc,kCAAkC;AAChD,cAAc,wBAAwB;AACtC,cAAc,4BAA4B;AAC1C,cAAc,kCAAkC;AAChD,cAAc,uBAAuB;AACrC,cAAc,2BAA2B;AACzC,cAAc,kCAAkC;AAChD,cAAc,6BAA6B;AAC3C,cAAc,yBAAyB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type EventBus, type Outbox } from '@entifix/transactions';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
/** What a case needs from an outbox implementation: the port, and its relay's drain. */
|
|
4
|
+
export interface OutboxUnderTest {
|
|
5
|
+
readonly outbox: Outbox;
|
|
6
|
+
/** One relay pass over `outbox`, publishing through `bus`. */
|
|
7
|
+
readonly drain: (bus: EventBus, maxAttempts: number) => Effect.Effect<number, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* What every {@link Outbox} and its relay must guarantee
|
|
11
|
+
* ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)):
|
|
12
|
+
* a duplicate enqueue is recognised, each aggregate publishes in version
|
|
13
|
+
* order, a failing aggregate holds back only itself, a poisoned one is
|
|
14
|
+
* quarantined without blocking another, and a consumer discards a stale
|
|
15
|
+
* version.
|
|
16
|
+
*/
|
|
17
|
+
export declare const describeOutboxContract: (name: string, make: () => Effect.Effect<OutboxUnderTest, unknown>) => void;
|
|
18
|
+
//# sourceMappingURL=outbox.contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/outbox.contract.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,MAAM,EAEZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,wFAAwF;AACxF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,CACd,GAAG,EAAE,QAAQ,EACb,WAAW,EAAE,MAAM,KAChB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAgCD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GACjC,MAAM,MAAM,EACZ,MAAM,MAAM,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,KAClD,IAsEF,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Unavailable } from '@entifix/core';
|
|
2
|
+
import { discardIfStale } from '@entifix/transactions';
|
|
3
|
+
import { Effect } from 'effect';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
let clock = 0;
|
|
6
|
+
const event = (aggregate, version)=>{
|
|
7
|
+
clock += 1;
|
|
8
|
+
return {
|
|
9
|
+
name: 'contract.changed',
|
|
10
|
+
id: `${aggregate}:${String(version)}`,
|
|
11
|
+
source: 'contract',
|
|
12
|
+
at: new Date(Date.UTC(2026, 0, 1, 0, 0, clock)).toISOString(),
|
|
13
|
+
aggregate: {
|
|
14
|
+
type: 'contract',
|
|
15
|
+
id: aggregate
|
|
16
|
+
},
|
|
17
|
+
version,
|
|
18
|
+
data: {}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/** A bus that records what it published and refuses the ids it is told to. */ const recordingBus = (refuse = new Set())=>{
|
|
22
|
+
const published = [];
|
|
23
|
+
const bus = {
|
|
24
|
+
publish: (published_)=>refuse.has(published_.id) ? Effect.fail(new Unavailable({
|
|
25
|
+
dependency: 'contract-bus'
|
|
26
|
+
})) : Effect.sync(()=>{
|
|
27
|
+
published.push(published_);
|
|
28
|
+
}),
|
|
29
|
+
/* v8 ignore next -- the relay only publishes; the bus port asks for both. */ subscribe: ()=>Effect.void
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
bus,
|
|
33
|
+
published
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* What every {@link Outbox} and its relay must guarantee
|
|
38
|
+
* ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)):
|
|
39
|
+
* a duplicate enqueue is recognised, each aggregate publishes in version
|
|
40
|
+
* order, a failing aggregate holds back only itself, a poisoned one is
|
|
41
|
+
* quarantined without blocking another, and a consumer discards a stale
|
|
42
|
+
* version.
|
|
43
|
+
*/ export const describeOutboxContract = (name, make)=>{
|
|
44
|
+
const run = (effect)=>Effect.runPromise(effect);
|
|
45
|
+
describe(`Outbox contract: ${name}`, ()=>{
|
|
46
|
+
it('recognises a duplicate enqueue by event id', async ()=>{
|
|
47
|
+
const { outbox } = await run(make());
|
|
48
|
+
const first = event('a', 1);
|
|
49
|
+
expect(await run(outbox.enqueue(first))).toBe('enqueued');
|
|
50
|
+
expect(await run(outbox.enqueue(first))).toBe('duplicate');
|
|
51
|
+
});
|
|
52
|
+
it('publishes each aggregate in version order', async ()=>{
|
|
53
|
+
const { outbox, drain } = await run(make());
|
|
54
|
+
for (const entry of [
|
|
55
|
+
event('a', 1),
|
|
56
|
+
event('b', 1),
|
|
57
|
+
event('a', 2)
|
|
58
|
+
])await run(outbox.enqueue(entry));
|
|
59
|
+
const { bus, published } = recordingBus();
|
|
60
|
+
expect(await run(drain(bus, 3))).toBe(3);
|
|
61
|
+
expect(published.filter((e)=>{
|
|
62
|
+
var _e_aggregate;
|
|
63
|
+
return ((_e_aggregate = e.aggregate) == null ? void 0 : _e_aggregate.id) === 'a';
|
|
64
|
+
}).map((e)=>e.version)).toEqual([
|
|
65
|
+
1,
|
|
66
|
+
2
|
|
67
|
+
]);
|
|
68
|
+
expect((await run(outbox.stats())).pending).toBe(0);
|
|
69
|
+
});
|
|
70
|
+
// The record's point: a failing head holds back its own aggregate only.
|
|
71
|
+
it('holds back only the aggregate whose head failed', async ()=>{
|
|
72
|
+
const { outbox, drain } = await run(make());
|
|
73
|
+
for (const entry of [
|
|
74
|
+
event('a', 1),
|
|
75
|
+
event('a', 2),
|
|
76
|
+
event('b', 1)
|
|
77
|
+
])await run(outbox.enqueue(entry));
|
|
78
|
+
const { bus, published } = recordingBus(new Set([
|
|
79
|
+
'a:1'
|
|
80
|
+
]));
|
|
81
|
+
await run(drain(bus, 3));
|
|
82
|
+
expect(published.map((e)=>e.id)).toEqual([
|
|
83
|
+
'b:1'
|
|
84
|
+
]);
|
|
85
|
+
expect((await run(outbox.stats())).pending).toBe(2);
|
|
86
|
+
});
|
|
87
|
+
it('quarantines a poisoned aggregate without blocking another', async ()=>{
|
|
88
|
+
const { outbox, drain } = await run(make());
|
|
89
|
+
for (const entry of [
|
|
90
|
+
event('a', 1),
|
|
91
|
+
event('b', 1),
|
|
92
|
+
event('a', 2)
|
|
93
|
+
])await run(outbox.enqueue(entry));
|
|
94
|
+
const { bus, published } = recordingBus(new Set([
|
|
95
|
+
'a:1'
|
|
96
|
+
]));
|
|
97
|
+
await run(drain(bus, 1));
|
|
98
|
+
expect(published.map((e)=>e.id)).toEqual([
|
|
99
|
+
'b:1',
|
|
100
|
+
'a:2'
|
|
101
|
+
]);
|
|
102
|
+
expect(await run(outbox.stats())).toMatchObject({
|
|
103
|
+
pending: 0,
|
|
104
|
+
quarantined: 1
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
it('lets a consumer discard a version it already applied', async ()=>{
|
|
108
|
+
const apply = Effect.succeed('applied');
|
|
109
|
+
expect(await run(discardIfStale(Effect.succeed(2), 1, apply))).toBe('stale');
|
|
110
|
+
expect(await run(discardIfStale(Effect.succeed(2), 2, apply))).toBe('stale');
|
|
111
|
+
expect(await run(discardIfStale(Effect.succeed(2), 3, apply))).toBe('applied');
|
|
112
|
+
expect(await run(discardIfStale(Effect.succeed(undefined), 1, apply))).toBe('applied');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=outbox.contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/contracts/outbox.contract.ts"],"sourcesContent":["import { type DomainEvent, Unavailable } from '@entifix/core';\nimport {\n discardIfStale,\n type EventBus,\n type Outbox,\n type OutboxEvent,\n} from '@entifix/transactions';\nimport { Effect } from 'effect';\nimport { describe, expect, it } from 'vitest';\n\n/** What a case needs from an outbox implementation: the port, and its relay's drain. */\nexport interface OutboxUnderTest {\n readonly outbox: Outbox;\n /** One relay pass over `outbox`, publishing through `bus`. */\n readonly drain: (\n bus: EventBus,\n maxAttempts: number,\n ) => Effect.Effect<number, unknown>;\n}\n\nlet clock = 0;\nconst event = (aggregate: string, version: number): OutboxEvent => {\n clock += 1;\n return {\n name: 'contract.changed',\n id: `${aggregate}:${String(version)}`,\n source: 'contract',\n at: new Date(Date.UTC(2026, 0, 1, 0, 0, clock)).toISOString(),\n aggregate: { type: 'contract', id: aggregate },\n version,\n data: {},\n };\n};\n\n/** A bus that records what it published and refuses the ids it is told to. */\nconst recordingBus = (refuse: ReadonlySet<string> = new Set()) => {\n const published: DomainEvent[] = [];\n const bus: EventBus = {\n publish: published_ =>\n refuse.has(published_.id)\n ? Effect.fail(new Unavailable({ dependency: 'contract-bus' }))\n : Effect.sync(() => {\n published.push(published_);\n }),\n /* v8 ignore next -- the relay only publishes; the bus port asks for both. */\n subscribe: () => Effect.void,\n };\n return { bus, published };\n};\n\n/**\n * What every {@link Outbox} and its relay must guarantee\n * ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)):\n * a duplicate enqueue is recognised, each aggregate publishes in version\n * order, a failing aggregate holds back only itself, a poisoned one is\n * quarantined without blocking another, and a consumer discards a stale\n * version.\n */\nexport const describeOutboxContract = (\n name: string,\n make: () => Effect.Effect<OutboxUnderTest, unknown>,\n): void => {\n const run = <A, E>(effect: Effect.Effect<A, E>) => Effect.runPromise(effect);\n\n describe(`Outbox contract: ${name}`, () => {\n it('recognises a duplicate enqueue by event id', async () => {\n const { outbox } = await run(make());\n const first = event('a', 1);\n\n expect(await run(outbox.enqueue(first))).toBe('enqueued');\n expect(await run(outbox.enqueue(first))).toBe('duplicate');\n });\n\n it('publishes each aggregate in version order', async () => {\n const { outbox, drain } = await run(make());\n for (const entry of [event('a', 1), event('b', 1), event('a', 2)])\n await run(outbox.enqueue(entry));\n const { bus, published } = recordingBus();\n\n expect(await run(drain(bus, 3))).toBe(3);\n expect(\n published.filter(e => e.aggregate?.id === 'a').map(e => e.version),\n ).toEqual([1, 2]);\n expect((await run(outbox.stats())).pending).toBe(0);\n });\n\n // The record's point: a failing head holds back its own aggregate only.\n it('holds back only the aggregate whose head failed', async () => {\n const { outbox, drain } = await run(make());\n for (const entry of [event('a', 1), event('a', 2), event('b', 1)])\n await run(outbox.enqueue(entry));\n const { bus, published } = recordingBus(new Set(['a:1']));\n\n await run(drain(bus, 3));\n\n expect(published.map(e => e.id)).toEqual(['b:1']);\n expect((await run(outbox.stats())).pending).toBe(2);\n });\n\n it('quarantines a poisoned aggregate without blocking another', async () => {\n const { outbox, drain } = await run(make());\n for (const entry of [event('a', 1), event('b', 1), event('a', 2)])\n await run(outbox.enqueue(entry));\n const { bus, published } = recordingBus(new Set(['a:1']));\n\n await run(drain(bus, 1));\n\n expect(published.map(e => e.id)).toEqual(['b:1', 'a:2']);\n expect(await run(outbox.stats())).toMatchObject({\n pending: 0,\n quarantined: 1,\n });\n });\n\n it('lets a consumer discard a version it already applied', async () => {\n const apply = Effect.succeed('applied' as const);\n\n expect(await run(discardIfStale(Effect.succeed(2), 1, apply))).toBe(\n 'stale',\n );\n expect(await run(discardIfStale(Effect.succeed(2), 2, apply))).toBe(\n 'stale',\n );\n expect(await run(discardIfStale(Effect.succeed(2), 3, apply))).toBe(\n 'applied',\n );\n expect(\n await run(discardIfStale(Effect.succeed(undefined), 1, apply)),\n ).toBe('applied');\n });\n });\n};\n"],"names":["Unavailable","discardIfStale","Effect","describe","expect","it","clock","event","aggregate","version","name","id","String","source","at","Date","UTC","toISOString","type","data","recordingBus","refuse","Set","published","bus","publish","published_","has","fail","dependency","sync","push","subscribe","void","describeOutboxContract","make","run","effect","runPromise","outbox","first","enqueue","toBe","drain","entry","filter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D5C,OAAO,AAAC,CAAA,MAAMgC,IAAIG,OAAOU,KAAK,GAAE,EAAGC,OAAO,EAAER,IAAI,CAAC;QACnD;QAEArC,GAAG,6DAA6D;YAC9D,MAAM,EAAEkC,MAAM,EAAEI,KAAK,EAAE,GAAG,MAAMP,IAAID;YACpC,KAAK,MAAMS,SAAS;gBAACrC,MAAM,KAAK;gBAAIA,MAAM,KAAK;gBAAIA,MAAM,KAAK;aAAG,CAC/D,MAAM6B,IAAIG,OAAOE,OAAO,CAACG;YAC3B,MAAM,EAAEpB,GAAG,EAAED,SAAS,EAAE,GAAGH,aAAa,IAAIE,IAAI;gBAAC;aAAM;YAEvD,MAAMc,IAAIO,MAAMnB,KAAK;YAErBpB,OAAOmB,UAAUwB,GAAG,CAACD,CAAAA,IAAKA,EAAEnC,EAAE,GAAGqC,OAAO,CAAC;gBAAC;gBAAO;aAAM;YACvD5C,OAAO,MAAMgC,IAAIG,OAAOU,KAAK,KAAKE,aAAa,CAAC;gBAC9CD,SAAS;gBACTE,aAAa;YACf;QACF;QAEA/C,GAAG,wDAAwD;YACzD,MAAMgD,QAAQnD,OAAOoD,OAAO,CAAC;YAE7BlD,OAAO,MAAMgC,IAAInC,eAAeC,OAAOoD,OAAO,CAAC,IAAI,GAAGD,SAASX,IAAI,CACjE;YAEFtC,OAAO,MAAMgC,IAAInC,eAAeC,OAAOoD,OAAO,CAAC,IAAI,GAAGD,SAASX,IAAI,CACjE;YAEFtC,OAAO,MAAMgC,IAAInC,eAAeC,OAAOoD,OAAO,CAAC,IAAI,GAAGD,SAASX,IAAI,CACjE;YAEFtC,OACE,MAAMgC,IAAInC,eAAeC,OAAOoD,OAAO,CAACC,YAAY,GAAGF,SACvDX,IAAI,CAAC;QACT;IACF;AACF,EAAE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DomainEvent } from '@entifix/core';
|
|
2
2
|
import type { EventBus, LockService, SequenceService, TransactionInbox } from '@entifix/transactions';
|
|
3
3
|
/**
|
|
4
4
|
* What every {@link LockService} must guarantee: exclusivity while held,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-ports.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/transaction-ports.contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"transaction-ports.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/transaction-ports.contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,eAAe,CAAC;AAChE,OAAO,KAAK,EACV,QAAQ,EACR,WAAW,EACX,eAAe,EAEf,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAqB/B;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,GACtC,MAAM,MAAM,EACZ,iBAAiB,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,KACxD,IAqDF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,GAC1C,MAAM,MAAM,EACZ,qBAAqB,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,KACpE,IA6BF,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,QAAQ,CAAC;IACd,oEAAoE;IACpE,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,8DAA8D;IAC9D,SAAS,IAAI,WAAW,EAAE,CAAC;CAC5B;AAiDD;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACnC,MAAM,MAAM,EACZ,aAAa,MAAM,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC,KAC5E,IAkDF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gCAAgC,GAC3C,MAAM,MAAM,EACZ,WAAW,CAAC,QAAQ,EAAE,MAAM,KAAK,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAC5E,IAyCF,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { registerEvent } from '@entifix/core';
|
|
2
|
+
import { Duration, Effect, Exit, Fiber, Schema } from 'effect';
|
|
2
3
|
import { TestClock } from 'effect/testing';
|
|
3
4
|
import { describe, expect, it } from 'vitest';
|
|
4
5
|
/**
|
|
@@ -106,6 +107,14 @@ const run = (effect)=>Effect.runPromise(effect);
|
|
|
106
107
|
*/ const collectInto = (sink)=>(event)=>Effect.sync(()=>{
|
|
107
108
|
sink.push(event);
|
|
108
109
|
});
|
|
110
|
+
// A transport encodes and decodes through the registry, so the suite's own
|
|
111
|
+
// event is registered like any other — audience-free, since nothing here
|
|
112
|
+
// delivers to a person.
|
|
113
|
+
registerEvent('contract.widget.created', Schema.Struct({
|
|
114
|
+
entity: Schema.String
|
|
115
|
+
}), {
|
|
116
|
+
audience: 'none'
|
|
117
|
+
});
|
|
109
118
|
const anEvent = (id, name = 'contract.widget.created')=>({
|
|
110
119
|
name,
|
|
111
120
|
id,
|