@entifix/testing-unit 0.12.1 → 0.14.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.map +1 -1
- package/dist/contracts/flow-engine.contract.js +22 -0
- package/dist/contracts/flow-engine.contract.js.map +1 -1
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/push-channel.contract.d.ts +45 -0
- package/dist/contracts/push-channel.contract.d.ts.map +1 -0
- package/dist/contracts/push-channel.contract.js +135 -0
- package/dist/contracts/push-channel.contract.js.map +1 -0
- package/dist/contracts/server-push.contract.d.ts +44 -0
- package/dist/contracts/server-push.contract.d.ts.map +1 -0
- package/dist/contracts/server-push.contract.js +273 -0
- package/dist/contracts/server-push.contract.js.map +1 -0
- package/dist/doubles/entity-facet-counter.d.ts +2 -2
- package/dist/doubles/entity-facet-counter.d.ts.map +1 -1
- package/dist/doubles/entity-facet-counter.js.map +1 -1
- package/dist/doubles/entity-repository.js.map +1 -1
- package/dist/doubles/server-push.d.ts +16 -0
- package/dist/doubles/server-push.d.ts.map +1 -0
- package/dist/doubles/server-push.js +38 -0
- package/dist/doubles/server-push.js.map +1 -0
- package/dist/doubles/transaction-ports.d.ts +2 -2
- package/dist/doubles/transaction-ports.d.ts.map +1 -1
- package/dist/doubles/transaction-ports.js.map +1 -1
- package/dist/drivers/fake-mongo.d.ts +1 -1
- package/dist/drivers/fake-mongo.js.map +1 -1
- package/dist/drivers/fake-sql.d.ts +1 -1
- package/dist/drivers/fake-sql.js.map +1 -1
- package/dist/effect/run.d.ts +1 -1
- package/dist/effect/run.js +1 -1
- package/dist/effect/run.js.map +1 -1
- package/dist/http/entity-handlers.d.ts +1 -1
- package/dist/http/entity-handlers.js +1 -1
- package/dist/http/entity-handlers.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
import { Effect, Fiber, Stream } from 'effect';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
const event = (id, topic, audience)=>_extends({
|
|
5
|
+
name: 'thing.changed',
|
|
6
|
+
id,
|
|
7
|
+
source: 'contract',
|
|
8
|
+
at: '2026-11-02T00:00:00.000Z',
|
|
9
|
+
correlationId: id
|
|
10
|
+
}, audience === undefined ? {} : {
|
|
11
|
+
audience
|
|
12
|
+
}, {
|
|
13
|
+
data: {
|
|
14
|
+
topic
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const org = (id)=>[
|
|
18
|
+
{
|
|
19
|
+
kind: 'organization',
|
|
20
|
+
id
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
const topicsOf = (e)=>[
|
|
24
|
+
e.data.topic
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* What every server-push adapter must guarantee
|
|
28
|
+
* ([ADR 0021](../../../../../docs/adr/0021-server-push-and-the-multiplexed-channel.md)):
|
|
29
|
+
* a connection receives only the topics it asked for and only what its
|
|
30
|
+
* audience admits, each event naming which of its topics it matched; an event naming no audience reaches nobody; a flow event
|
|
31
|
+
* reaches only the holder of its capability; a host filter replaces the
|
|
32
|
+
* default; and a reconnect is answered by the resume hook before anything
|
|
33
|
+
* live, or by a resync when the host has none.
|
|
34
|
+
*
|
|
35
|
+
* `make` builds a fresh port with the given options inside the case's scope.
|
|
36
|
+
*/ export const describeServerPushContract = (name, make)=>{
|
|
37
|
+
/**
|
|
38
|
+
* Opens `connection`, publishes `events` once it is reading, and returns the
|
|
39
|
+
* first `count` messages it received.
|
|
40
|
+
*/ const receive = (options, connection, events, count)=>Effect.runPromise(Effect.scoped(Effect.gen(function*() {
|
|
41
|
+
const push = yield* make(options);
|
|
42
|
+
const reading = yield* Effect.forkChild(Stream.runCollect(Stream.take(push.open(connection), count)));
|
|
43
|
+
// Let the connection subscribe before anything is published.
|
|
44
|
+
yield* Effect.sleep('10 millis');
|
|
45
|
+
yield* Effect.forEach(events, push.publish, {
|
|
46
|
+
discard: true
|
|
47
|
+
});
|
|
48
|
+
return Array.from((yield* Fiber.join(reading)));
|
|
49
|
+
})));
|
|
50
|
+
const ids = (messages)=>messages.map((m)=>m._tag === 'event' ? m.event.id : `resync:${m.topics}`);
|
|
51
|
+
describe(`${name} — the server-push contract`, ()=>{
|
|
52
|
+
it('delivers an event in a subscribed topic that its audience admits', async ()=>{
|
|
53
|
+
const got = await receive({
|
|
54
|
+
topicsOf
|
|
55
|
+
}, {
|
|
56
|
+
recipient: {
|
|
57
|
+
organizationId: 'a'
|
|
58
|
+
},
|
|
59
|
+
topics: [
|
|
60
|
+
'entity:x'
|
|
61
|
+
]
|
|
62
|
+
}, [
|
|
63
|
+
event('e1', 'entity:x', org('a'))
|
|
64
|
+
], 1);
|
|
65
|
+
expect(ids(got)).toEqual([
|
|
66
|
+
'e1'
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
it('names the topics of the connection an event matched, and only those', async ()=>{
|
|
70
|
+
const got = await receive({
|
|
71
|
+
topicsOf: ()=>[
|
|
72
|
+
'entity:x',
|
|
73
|
+
'record:x:1',
|
|
74
|
+
'entity:y'
|
|
75
|
+
]
|
|
76
|
+
}, {
|
|
77
|
+
recipient: {
|
|
78
|
+
organizationId: 'a'
|
|
79
|
+
},
|
|
80
|
+
topics: [
|
|
81
|
+
'record:x:1',
|
|
82
|
+
'entity:x'
|
|
83
|
+
]
|
|
84
|
+
}, [
|
|
85
|
+
event('e1', 'entity:x', org('a'))
|
|
86
|
+
], 1);
|
|
87
|
+
expect(got[0]).toMatchObject({
|
|
88
|
+
_tag: 'event',
|
|
89
|
+
topics: [
|
|
90
|
+
'entity:x',
|
|
91
|
+
'record:x:1'
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
it('withholds an event in a topic the connection did not ask for', async ()=>{
|
|
96
|
+
const got = await receive({
|
|
97
|
+
topicsOf
|
|
98
|
+
}, {
|
|
99
|
+
recipient: {
|
|
100
|
+
organizationId: 'a'
|
|
101
|
+
},
|
|
102
|
+
topics: [
|
|
103
|
+
'entity:x'
|
|
104
|
+
]
|
|
105
|
+
}, [
|
|
106
|
+
event('e1', 'entity:y', org('a')),
|
|
107
|
+
event('e2', 'entity:x', org('a'))
|
|
108
|
+
], 1);
|
|
109
|
+
expect(ids(got)).toEqual([
|
|
110
|
+
'e2'
|
|
111
|
+
]);
|
|
112
|
+
});
|
|
113
|
+
it('reaches nobody with an event that names no audience', async ()=>{
|
|
114
|
+
const got = await receive({
|
|
115
|
+
topicsOf
|
|
116
|
+
}, {
|
|
117
|
+
recipient: {
|
|
118
|
+
organizationId: 'a'
|
|
119
|
+
},
|
|
120
|
+
topics: [
|
|
121
|
+
'entity:x'
|
|
122
|
+
]
|
|
123
|
+
}, [
|
|
124
|
+
event('e1', 'entity:x'),
|
|
125
|
+
event('e2', 'entity:x', []),
|
|
126
|
+
event('e3', 'entity:x', org('a'))
|
|
127
|
+
], 1);
|
|
128
|
+
expect(ids(got)).toEqual([
|
|
129
|
+
'e3'
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
it("never delivers one organization's event to another", async ()=>{
|
|
133
|
+
const got = await receive({
|
|
134
|
+
topicsOf
|
|
135
|
+
}, {
|
|
136
|
+
recipient: {
|
|
137
|
+
organizationId: 'b'
|
|
138
|
+
},
|
|
139
|
+
topics: [
|
|
140
|
+
'entity:x'
|
|
141
|
+
]
|
|
142
|
+
}, [
|
|
143
|
+
event('e1', 'entity:x', org('a')),
|
|
144
|
+
event('e2', 'entity:x', org('b'))
|
|
145
|
+
], 1);
|
|
146
|
+
expect(ids(got)).toEqual([
|
|
147
|
+
'e2'
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
it('delivers a flow event only to the holder of its capability digest', async ()=>{
|
|
151
|
+
const flow = [
|
|
152
|
+
{
|
|
153
|
+
kind: 'flow',
|
|
154
|
+
id: 'f-1',
|
|
155
|
+
digest: 'd-1'
|
|
156
|
+
}
|
|
157
|
+
];
|
|
158
|
+
const stranger = await receive({
|
|
159
|
+
topicsOf
|
|
160
|
+
}, {
|
|
161
|
+
recipient: {
|
|
162
|
+
flowDigests: [
|
|
163
|
+
'd-2'
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
topics: [
|
|
167
|
+
'flow:f-1'
|
|
168
|
+
]
|
|
169
|
+
}, [
|
|
170
|
+
event('e1', 'flow:f-1', flow),
|
|
171
|
+
event('e2', 'flow:f-1', [
|
|
172
|
+
{
|
|
173
|
+
kind: 'flow',
|
|
174
|
+
id: 'f-1',
|
|
175
|
+
digest: 'd-2'
|
|
176
|
+
}
|
|
177
|
+
])
|
|
178
|
+
], 1);
|
|
179
|
+
expect(ids(stranger)).toEqual([
|
|
180
|
+
'e2'
|
|
181
|
+
]);
|
|
182
|
+
const holder = await receive({
|
|
183
|
+
topicsOf
|
|
184
|
+
}, {
|
|
185
|
+
recipient: {
|
|
186
|
+
flowDigests: [
|
|
187
|
+
'd-1'
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
topics: [
|
|
191
|
+
'flow:f-1'
|
|
192
|
+
]
|
|
193
|
+
}, [
|
|
194
|
+
event('e1', 'flow:f-1', flow)
|
|
195
|
+
], 1);
|
|
196
|
+
expect(ids(holder)).toEqual([
|
|
197
|
+
'e1'
|
|
198
|
+
]);
|
|
199
|
+
});
|
|
200
|
+
it("replaces the default with the host's filter", async ()=>{
|
|
201
|
+
const got = await receive({
|
|
202
|
+
topicsOf,
|
|
203
|
+
admits: (e)=>e.id !== 'e1'
|
|
204
|
+
}, {
|
|
205
|
+
recipient: {},
|
|
206
|
+
topics: [
|
|
207
|
+
'entity:x'
|
|
208
|
+
]
|
|
209
|
+
}, [
|
|
210
|
+
event('e1', 'entity:x', org('a')),
|
|
211
|
+
event('e2', 'entity:x')
|
|
212
|
+
], 1);
|
|
213
|
+
expect(ids(got)).toEqual([
|
|
214
|
+
'e2'
|
|
215
|
+
]);
|
|
216
|
+
});
|
|
217
|
+
it('answers a reconnect from the resume hook before anything live', async ()=>{
|
|
218
|
+
const got = await receive({
|
|
219
|
+
topicsOf,
|
|
220
|
+
resume: (cursor, topics)=>Stream.make({
|
|
221
|
+
_tag: 'resync',
|
|
222
|
+
topics: [
|
|
223
|
+
`${cursor}>${topics}`
|
|
224
|
+
]
|
|
225
|
+
})
|
|
226
|
+
}, {
|
|
227
|
+
recipient: {
|
|
228
|
+
organizationId: 'a'
|
|
229
|
+
},
|
|
230
|
+
topics: [
|
|
231
|
+
'flow:f'
|
|
232
|
+
],
|
|
233
|
+
cursor: 'c-9'
|
|
234
|
+
}, [
|
|
235
|
+
event('e1', 'flow:f', org('a'))
|
|
236
|
+
], 2);
|
|
237
|
+
expect(ids(got)).toEqual([
|
|
238
|
+
'resync:c-9>flow:f',
|
|
239
|
+
'e1'
|
|
240
|
+
]);
|
|
241
|
+
});
|
|
242
|
+
it('asks a reconnect to re-read every topic when the host has no resume hook', async ()=>{
|
|
243
|
+
const got = await receive({
|
|
244
|
+
topicsOf
|
|
245
|
+
}, {
|
|
246
|
+
recipient: {
|
|
247
|
+
organizationId: 'a'
|
|
248
|
+
},
|
|
249
|
+
topics: [
|
|
250
|
+
'entity:x',
|
|
251
|
+
'record:x:1'
|
|
252
|
+
],
|
|
253
|
+
cursor: 'c-1'
|
|
254
|
+
}, [], 1);
|
|
255
|
+
expect(got).toEqual([
|
|
256
|
+
{
|
|
257
|
+
_tag: 'resync',
|
|
258
|
+
topics: [
|
|
259
|
+
'entity:x',
|
|
260
|
+
'record:x:1'
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
]);
|
|
264
|
+
});
|
|
265
|
+
it('accepts a publish with no connection open', async ()=>{
|
|
266
|
+
await Effect.runPromise(Effect.scoped(Effect.flatMap(make({
|
|
267
|
+
topicsOf
|
|
268
|
+
}), (push)=>push.publish(event('e1', 'entity:x', org('a'))))));
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
//# sourceMappingURL=server-push.contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/contracts/server-push.contract.ts"],"sourcesContent":["import type { AudienceRecipient, DomainEvent } from '@entifix/core';\nimport { Effect, Fiber, type Scope, Stream } from 'effect';\nimport { describe, expect, it } from 'vitest';\n\n/**\n * The push port as a case exercises it.\n *\n * Declared here structurally rather than imported, because the service shell\n * that owns the port depends on this package for its own specs; any\n * `ServerPush` satisfies it.\n */\nexport interface PushConnectionUnderTest {\n readonly recipient: AudienceRecipient;\n readonly topics: readonly string[];\n readonly cursor?: string;\n}\n\nexport type PushMessageUnderTest =\n | {\n readonly _tag: 'event';\n readonly event: DomainEvent;\n readonly topics: readonly string[];\n }\n | { readonly _tag: 'resync'; readonly topics: readonly string[] };\n\nexport interface ServerPushUnderTest {\n readonly publish: (event: DomainEvent) => Effect.Effect<void>;\n readonly open: (\n connection: PushConnectionUnderTest,\n ) => Stream.Stream<PushMessageUnderTest>;\n}\n\nexport interface ServerPushContractOptions {\n readonly topicsOf: (event: DomainEvent) => readonly string[];\n readonly admits?: (\n event: DomainEvent,\n connection: PushConnectionUnderTest,\n ) => boolean;\n readonly resume?: (\n cursor: string,\n topics: readonly string[],\n ) => Stream.Stream<PushMessageUnderTest>;\n}\n\nconst event = (\n id: string,\n topic: string,\n audience?: DomainEvent['audience'],\n): DomainEvent => ({\n name: 'thing.changed',\n id,\n source: 'contract',\n at: '2026-11-02T00:00:00.000Z',\n correlationId: id,\n ...(audience === undefined ? {} : { audience }),\n data: { topic },\n});\n\nconst org = (id: string) => [{ kind: 'organization' as const, id }];\n\nconst topicsOf = (e: DomainEvent) => [(e.data as { topic: string }).topic];\n\n/**\n * What every server-push adapter must guarantee\n * ([ADR 0021](../../../../../docs/adr/0021-server-push-and-the-multiplexed-channel.md)):\n * a connection receives only the topics it asked for and only what its\n * audience admits, each event naming which of its topics it matched; an event naming no audience reaches nobody; a flow event\n * reaches only the holder of its capability; a host filter replaces the\n * default; and a reconnect is answered by the resume hook before anything\n * live, or by a resync when the host has none.\n *\n * `make` builds a fresh port with the given options inside the case's scope.\n */\nexport const describeServerPushContract = (\n name: string,\n make: (\n options: ServerPushContractOptions,\n ) => Effect.Effect<ServerPushUnderTest, never, Scope.Scope>,\n): void => {\n /**\n * Opens `connection`, publishes `events` once it is reading, and returns the\n * first `count` messages it received.\n */\n const receive = (\n options: ServerPushContractOptions,\n connection: PushConnectionUnderTest,\n events: readonly DomainEvent[],\n count: number,\n ) =>\n Effect.runPromise(\n Effect.scoped(\n Effect.gen(function* () {\n const push = yield* make(options);\n const reading = yield* Effect.forkChild(\n Stream.runCollect(Stream.take(push.open(connection), count)),\n );\n // Let the connection subscribe before anything is published.\n yield* Effect.sleep('10 millis');\n yield* Effect.forEach(events, push.publish, { discard: true });\n return Array.from(yield* Fiber.join(reading));\n }),\n ),\n );\n\n const ids = (messages: readonly PushMessageUnderTest[]) =>\n messages.map(m => (m._tag === 'event' ? m.event.id : `resync:${m.topics}`));\n\n describe(`${name} — the server-push contract`, () => {\n it('delivers an event in a subscribed topic that its audience admits', async () => {\n const got = await receive(\n { topicsOf },\n { recipient: { organizationId: 'a' }, topics: ['entity:x'] },\n [event('e1', 'entity:x', org('a'))],\n 1,\n );\n expect(ids(got)).toEqual(['e1']);\n });\n\n it('names the topics of the connection an event matched, and only those', async () => {\n const got = await receive(\n { topicsOf: () => ['entity:x', 'record:x:1', 'entity:y'] },\n {\n recipient: { organizationId: 'a' },\n topics: ['record:x:1', 'entity:x'],\n },\n [event('e1', 'entity:x', org('a'))],\n 1,\n );\n expect(got[0]).toMatchObject({\n _tag: 'event',\n topics: ['entity:x', 'record:x:1'],\n });\n });\n\n it('withholds an event in a topic the connection did not ask for', async () => {\n const got = await receive(\n { topicsOf },\n { recipient: { organizationId: 'a' }, topics: ['entity:x'] },\n [event('e1', 'entity:y', org('a')), event('e2', 'entity:x', org('a'))],\n 1,\n );\n expect(ids(got)).toEqual(['e2']);\n });\n\n it('reaches nobody with an event that names no audience', async () => {\n const got = await receive(\n { topicsOf },\n { recipient: { organizationId: 'a' }, topics: ['entity:x'] },\n [\n event('e1', 'entity:x'),\n event('e2', 'entity:x', []),\n event('e3', 'entity:x', org('a')),\n ],\n 1,\n );\n expect(ids(got)).toEqual(['e3']);\n });\n\n it(\"never delivers one organization's event to another\", async () => {\n const got = await receive(\n { topicsOf },\n { recipient: { organizationId: 'b' }, topics: ['entity:x'] },\n [event('e1', 'entity:x', org('a')), event('e2', 'entity:x', org('b'))],\n 1,\n );\n expect(ids(got)).toEqual(['e2']);\n });\n\n it('delivers a flow event only to the holder of its capability digest', async () => {\n const flow = [{ kind: 'flow' as const, id: 'f-1', digest: 'd-1' }];\n const stranger = await receive(\n { topicsOf },\n { recipient: { flowDigests: ['d-2'] }, topics: ['flow:f-1'] },\n [\n event('e1', 'flow:f-1', flow),\n event('e2', 'flow:f-1', [{ kind: 'flow', id: 'f-1', digest: 'd-2' }]),\n ],\n 1,\n );\n expect(ids(stranger)).toEqual(['e2']);\n const holder = await receive(\n { topicsOf },\n { recipient: { flowDigests: ['d-1'] }, topics: ['flow:f-1'] },\n [event('e1', 'flow:f-1', flow)],\n 1,\n );\n expect(ids(holder)).toEqual(['e1']);\n });\n\n it(\"replaces the default with the host's filter\", async () => {\n const got = await receive(\n { topicsOf, admits: e => e.id !== 'e1' },\n { recipient: {}, topics: ['entity:x'] },\n [event('e1', 'entity:x', org('a')), event('e2', 'entity:x')],\n 1,\n );\n expect(ids(got)).toEqual(['e2']);\n });\n\n it('answers a reconnect from the resume hook before anything live', async () => {\n const got = await receive(\n {\n topicsOf,\n resume: (cursor, topics) =>\n Stream.make({ _tag: 'resync', topics: [`${cursor}>${topics}`] }),\n },\n {\n recipient: { organizationId: 'a' },\n topics: ['flow:f'],\n cursor: 'c-9',\n },\n [event('e1', 'flow:f', org('a'))],\n 2,\n );\n expect(ids(got)).toEqual(['resync:c-9>flow:f', 'e1']);\n });\n\n it('asks a reconnect to re-read every topic when the host has no resume hook', async () => {\n const got = await receive(\n { topicsOf },\n {\n recipient: { organizationId: 'a' },\n topics: ['entity:x', 'record:x:1'],\n cursor: 'c-1',\n },\n [],\n 1,\n );\n expect(got).toEqual([\n { _tag: 'resync', topics: ['entity:x', 'record:x:1'] },\n ]);\n });\n\n it('accepts a publish with no connection open', async () => {\n await Effect.runPromise(\n Effect.scoped(\n Effect.flatMap(make({ topicsOf }), push =>\n push.publish(event('e1', 'entity:x', org('a'))),\n ),\n ),\n );\n });\n });\n};\n"],"names":["Effect","Fiber","Stream","describe","expect","it","event","id","topic","audience","name","source","at","correlationId","undefined","data","org","kind","topicsOf","e","describeServerPushContract","make","receive","options","connection","events","count","runPromise","scoped","gen","push","reading","forkChild","runCollect","take","open","sleep","forEach","publish","discard","Array","from","join","ids","messages","map","m","_tag","topics","got","recipient","organizationId","toEqual","toMatchObject","flow","digest","stranger","flowDigests","holder","admits","resume","cursor","flatMap"],"mappings":";AACA,SAASA,MAAM,EAAEC,KAAK,EAAcC,MAAM,QAAQ,SAAS;AAC3D,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AA0C9C,MAAMC,QAAQ,CACZC,IACAC,OACAC,WACiB;QACjBC,MAAM;QACNH;QACAI,QAAQ;QACRC,IAAI;QACJC,eAAeN;OACXE,aAAaK,YAAY,CAAC,IAAI;QAAEL;IAAS;QAC7CM,MAAM;YAAEP;QAAM;;AAGhB,MAAMQ,MAAM,CAACT,KAAe;QAAC;YAAEU,MAAM;YAAyBV;QAAG;KAAE;AAEnE,MAAMW,WAAW,CAACC,IAAmB;QAAEA,EAAEJ,IAAI,CAAuBP,KAAK;KAAC;AAE1E;;;;;;;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AM,UAAUU,IAAI;aAAM,EACjC;YAEFZ,OAAOuC,IAAIM,MAAMG,OAAO,CAAC;gBAAC;gBAAqB;aAAK;QACtD;QAEA/C,GAAG,4EAA4E;YAC7E,MAAM4C,MAAM,MAAM3B,QAChB;gBAAEJ;YAAS,GACX;gBACEgC,WAAW;oBAAEC,gBAAgB;gBAAI;gBACjCH,QAAQ;oBAAC;oBAAY;iBAAa;gBAClCa,QAAQ;YACV,GACA,EAAE,EACF;YAEFzD,OAAO6C,KAAKG,OAAO,CAAC;gBAClB;oBAAEL,MAAM;oBAAUC,QAAQ;wBAAC;wBAAY;qBAAa;gBAAC;aACtD;QACH;QAEA3C,GAAG,6CAA6C;YAC9C,MAAML,OAAO2B,UAAU,CACrB3B,OAAO4B,MAAM,CACX5B,OAAO8D,OAAO,CAACzC,KAAK;gBAAEH;YAAS,IAAIY,CAAAA,OACjCA,KAAKQ,OAAO,CAAChC,MAAM,MAAM,YAAYU,IAAI;QAIjD;IACF;AACF,EAAE"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { EntityFacetCounter } from '@entifix/business';
|
|
2
|
-
import { type
|
|
2
|
+
import { type EntifixFailure, type Entity } from '@entifix/core';
|
|
3
3
|
export interface InMemoryEntityFacetCounter extends EntityFacetCounter {
|
|
4
4
|
/**
|
|
5
5
|
* Makes the next count fail with `error`, so a caller's degraded path is
|
|
6
6
|
* reachable without reaching for a mocking library.
|
|
7
7
|
*/
|
|
8
|
-
failNext(error:
|
|
8
|
+
failNext(error: EntifixFailure): void;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* An {@link EntityFacetCounter} over records held in memory, counted by the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-facet-counter.d.ts","sourceRoot":"","sources":["../../src/doubles/entity-facet-counter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAEL,KAAK,
|
|
1
|
+
{"version":3,"file":"entity-facet-counter.d.ts","sourceRoot":"","sources":["../../src/doubles/entity-facet-counter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,MAAM,EAEZ,MAAM,eAAe,CAAC;AAGvB,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CACvC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GACnC,QAAQ,SAAS,MAAM,EAAE,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,KAChE,0BAsBF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/doubles/entity-facet-counter.ts"],"sourcesContent":["import type { EntityFacetCounter } from '@entifix/business';\nimport {\n countFacets,\n type
|
|
1
|
+
{"version":3,"sources":["../../src/doubles/entity-facet-counter.ts"],"sourcesContent":["import type { EntityFacetCounter } from '@entifix/business';\nimport {\n countFacets,\n type EntifixFailure,\n type Entity,\n type EntityFacetQuery,\n} from '@entifix/core';\nimport { Effect } from 'effect';\n\nexport interface InMemoryEntityFacetCounter extends EntityFacetCounter {\n /**\n * Makes the next count fail with `error`, so a caller's degraded path is\n * reachable without reaching for a mocking library.\n */\n failNext(error: EntifixFailure): void;\n}\n\n/**\n * An {@link EntityFacetCounter} over records held in memory, counted by the\n * same rules as every other in-memory query.\n *\n * `source` is either the records themselves or anything holding them — an\n * `InMemoryEntityRepository` — read on every count, so a spec that saves\n * through the repository sees the counts move.\n */\nexport const makeInMemoryFacetCounter = (\n source: readonly Entity[] | { readonly items: readonly Entity[] },\n): InMemoryEntityFacetCounter => {\n let pendingFailure: EntifixFailure | undefined;\n const records = () => ('items' in source ? source.items : source);\n\n return {\n count: <TEntity extends Entity>(\n queries: readonly EntityFacetQuery<TEntity>[],\n ) =>\n Effect.suspend(() => {\n if (pendingFailure !== undefined) {\n const error = pendingFailure;\n pendingFailure = undefined;\n return Effect.fail(error);\n }\n return Effect.succeed(\n countFacets(records() as readonly TEntity[], queries),\n );\n }),\n failNext: error => {\n pendingFailure = error;\n },\n };\n};\n"],"names":["countFacets","Effect","makeInMemoryFacetCounter","source","pendingFailure","records","items","count","queries","suspend","undefined","error","fail","succeed","failNext"],"mappings":"AACA,SACEA,WAAW,QAIN,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAUhC;;;;;;;CAOC,GACD,OAAO,MAAMC,2BAA2B,CACtCC;IAEA,IAAIC;IACJ,MAAMC,UAAU,IAAO,WAAWF,SAASA,OAAOG,KAAK,GAAGH;IAE1D,OAAO;QACLI,OAAO,CACLC,UAEAP,OAAOQ,OAAO,CAAC;gBACb,IAAIL,mBAAmBM,WAAW;oBAChC,MAAMC,QAAQP;oBACdA,iBAAiBM;oBACjB,OAAOT,OAAOW,IAAI,CAACD;gBACrB;gBACA,OAAOV,OAAOY,OAAO,CACnBb,YAAYK,WAAiCG;YAEjD;QACFM,UAAUH,CAAAA;YACRP,iBAAiBO;QACnB;IACF;AACF,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/doubles/entity-repository.ts"],"sourcesContent":["import type { EntityRepository, RepositoryFailure } from '@entifix/business';\nimport {\n applyFiltering,\n applySorting,\n deserializeSingleEntity,\n type
|
|
1
|
+
{"version":3,"sources":["../../src/doubles/entity-repository.ts"],"sourcesContent":["import type { EntityRepository, RepositoryFailure } from '@entifix/business';\nimport {\n applyFiltering,\n applySorting,\n deserializeSingleEntity,\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityId,\n type EntityLoadRequest,\n type EntityPage,\n extractMetaAccessors,\n NotFound,\n serializeEntity,\n} from '@entifix/core';\nimport { Effect } from 'effect';\n\n/**\n * A copy of `entity` that shares no state with it.\n *\n * Through the entity's own mapping — serialize, then deserialize — because that\n * is what a real adapter does to every record on the way in and out: a caller\n * can never hold the instance the store keeps, and a member the mapping drops\n * (`hidden`, `readonly`) does not survive a save here either. A class that\n * declares no accessors has no mapping to go through, so it is copied member by\n * member instead; plain spec fixtures are the case this keeps working.\n */\nconst copyOf = <TEntity extends Entity>(\n entity: TEntity,\n): Effect.Effect<TEntity, EntifixFailure> => {\n const entityConstructor = entity.constructor as EntityConstructor<TEntity>;\n if (extractMetaAccessors(entityConstructor).length === 0) {\n return Effect.succeed(\n Object.assign(\n Object.create(Object.getPrototypeOf(entity) as object) as TEntity,\n entity,\n ),\n );\n }\n // `undefined` only comes back for `null`/`undefined` input, and\n // `serializeEntity` always hands over an object.\n return deserializeSingleEntity(\n entityConstructor,\n serializeEntity(entityConstructor, entity),\n ) as Effect.Effect<TEntity, EntifixFailure>;\n};\n\nexport interface InMemoryEntityRepository extends EntityRepository {\n /** Everything currently stored, in insertion order. */\n readonly items: Entity[];\n /** Replaces the contents, discarding whatever was there. */\n seed(items: Entity[]): void;\n /**\n * Makes the next call to any method fail with `error`, so error branches are\n * reachable without reaching for a mocking library.\n */\n failNext(error: RepositoryFailure): void;\n}\n\n/**\n * In-memory {@link EntityRepository}: the default double for anything that\n * depends on persistence.\n *\n * Its semantics deliberately mirror `makeMongoRepository` — the same filtering\n * and sorting rules, which it takes from core's in-memory query evaluation\n * rather than keeping a copy of its own, same 1-based paging with a default page size of 10, same\n * \"entity not found\" failure, same id minting on create — and\n * `describeEntityRepositoryContract` holds both to that shared contract.\n */\nexport const makeInMemoryEntityRepository = (\n seed: Entity[] = [],\n): InMemoryEntityRepository => {\n let items = [...seed];\n let pendingFailure: RepositoryFailure | undefined;\n\n /** Consumes a queued failure, if one was armed. */\n const guard = <TValue>(\n run: () => Effect.Effect<TValue, RepositoryFailure>,\n ): Effect.Effect<TValue, RepositoryFailure> => {\n if (pendingFailure !== undefined) {\n const failure = pendingFailure;\n pendingFailure = undefined;\n return Effect.fail(failure);\n }\n return run();\n };\n\n const load = <TEntity extends Entity>(request: EntityLoadRequest<TEntity>) =>\n guard(() => {\n const matched = applySorting(\n applyFiltering(items as TEntity[], request.filtering),\n request.sorting,\n );\n const page = request.page ?? 1;\n const pageSize = request.pageSize ?? 10;\n const start = (page - 1) * pageSize;\n\n return Effect.forEach(\n matched.slice(start, start + pageSize),\n copyOf,\n ).pipe(\n Effect.map(\n copies =>\n ({\n items: copies,\n total: matched.length,\n request,\n }) satisfies EntityPage<TEntity>,\n ),\n );\n });\n\n const get = <TEntity extends Entity>(id: EntityId) =>\n guard(() => {\n const found = items.find(item => item.id === id);\n return found === undefined\n ? Effect.fail(new NotFound({}))\n : copyOf(found as TEntity);\n });\n\n const save = <TEntity extends Entity>(entity: TEntity) =>\n guard(() => {\n // A create arrives without an id, so the store mints one — same rule the\n // Mongo adapter follows. The Web Crypto global rather than `node:crypto`,\n // because a browser bundle cannot resolve a `node:` import and an example\n // with no backend runs this repository in the page.\n entity.id = entity.id ?? globalThis.crypto.randomUUID();\n // The store keeps its own copy and hands back another, so neither the\n // caller's instance nor the returned one can change the record without a\n // second save — which a real adapter guarantees by construction.\n return copyOf(entity).pipe(\n Effect.tap(stored =>\n Effect.sync(() => {\n const index = items.findIndex(item => item.id === stored.id);\n if (index === -1) {\n items.push(stored);\n } else {\n items[index] = stored;\n }\n }),\n ),\n Effect.flatMap(copyOf),\n );\n });\n\n const remove = <TEntity extends Entity>(entityOrId: EntityId | TEntity) =>\n guard(() => {\n const id =\n entityOrId != null && typeof entityOrId === 'object'\n ? entityOrId.id\n : entityOrId;\n items = items.filter(item => item.id !== id);\n return Effect.succeed(undefined);\n });\n\n return {\n load,\n get,\n save,\n delete: remove,\n get items() {\n return items;\n },\n seed: (next: Entity[]) => {\n items = [...next];\n },\n failNext: (error: RepositoryFailure) => {\n pendingFailure = error;\n },\n // Each method closes over its own state, so nothing is required from the\n // Effect environment; that is assignable to the interface's channel.\n } as unknown as InMemoryEntityRepository;\n};\n"],"names":["applyFiltering","applySorting","deserializeSingleEntity","extractMetaAccessors","NotFound","serializeEntity","Effect","copyOf","entity","entityConstructor","length","succeed","Object","assign","create","getPrototypeOf","makeInMemoryEntityRepository","seed","items","pendingFailure","guard","run","undefined","failure","fail","load","request","matched","filtering","sorting","page","pageSize","start","forEach","slice","pipe","map","copies","total","get","id","found","find","item","save","globalThis","crypto","randomUUID","tap","stored","sync","index","findIndex","push","flatMap","remove","entityOrId","filter","delete","next","failNext","error"],"mappings":"AACA,SACEA,cAAc,EACdC,YAAY,EACZC,uBAAuB,EAOvBC,oBAAoB,EACpBC,QAAQ,EACRC,eAAe,QACV,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAEhC;;;;;;;;;CASC,GACD,MAAMC,SAAS,CACbC;IAEA,MAAMC,oBAAoBD,OAAO,WAAW;IAC5C,IAAIL,qBAAqBM,mBAAmBC,MAAM,KAAK,GAAG;QACxD,OAAOJ,OAAOK,OAAO,CACnBC,OAAOC,MAAM,CACXD,OAAOE,MAAM,CAACF,OAAOG,cAAc,CAACP,UACpCA;IAGN;IACA,gEAAgE;IAChE,iDAAiD;IACjD,OAAON,wBACLO,mBACAJ,gBAAgBI,mBAAmBD;AAEvC;AAcA;;;;;;;;;CASC,GACD,OAAO,MAAMQ,+BAA+B,CAC1CC,OAAiB,EAAE;IAEnB,IAAIC,QAAQ;WAAID;KAAK;IACrB,IAAIE;IAEJ,iDAAiD,GACjD,MAAMC,QAAQ,CACZC;QAEA,IAAIF,mBAAmBG,WAAW;YAChC,MAAMC,UAAUJ;YAChBA,iBAAiBG;YACjB,OAAOhB,OAAOkB,IAAI,CAACD;QACrB;QACA,OAAOF;IACT;IAEA,MAAMI,OAAO,CAAyBC,UACpCN,MAAM;gBAKSM,eACIA;YALjB,MAAMC,UAAU1B,aACdD,eAAekB,OAAoBQ,QAAQE,SAAS,GACpDF,QAAQG,OAAO;YAEjB,MAAMC,QAAOJ,gBAAAA,QAAQI,IAAI,YAAZ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Q,OAAOA,eAAe,WACxCA,WAAWhB,EAAE,GACbgB;YACNtC,QAAQA,MAAMuC,MAAM,CAACd,CAAAA,OAAQA,KAAKH,EAAE,KAAKA;YACzC,OAAOlC,OAAOK,OAAO,CAACW;QACxB;IAEF,OAAO;QACLG;QACAc;QACAK;QACAc,QAAQH;QACR,IAAIrC;YACF,OAAOA;QACT;QACAD,MAAM,CAAC0C;YACLzC,QAAQ;mBAAIyC;aAAK;QACnB;QACAC,UAAU,CAACC;YACT1C,iBAAiB0C;QACnB;IAGF;AACF,EAAE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type DomainEvent } from '@entifix/core';
|
|
2
|
+
import { Effect, type Scope } from 'effect';
|
|
3
|
+
import type { ServerPushContractOptions, ServerPushUnderTest } from '../contracts/server-push.contract.js';
|
|
4
|
+
/** An in-memory push port that also remembers everything published to it. */
|
|
5
|
+
export interface InMemoryServerPush extends ServerPushUnderTest {
|
|
6
|
+
/** Every event published, in order, whether or not anyone received it. */
|
|
7
|
+
readonly published: () => readonly DomainEvent[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A push port for a host's specs: each open connection gets its own queue,
|
|
11
|
+
* filtered by topic and audience exactly as the real hub does, and every
|
|
12
|
+
* publish is recorded so a spec can assert what a projection pushed without
|
|
13
|
+
* opening a stream.
|
|
14
|
+
*/
|
|
15
|
+
export declare const makeInMemoryServerPush: ({ topicsOf, admits, resume, }: ServerPushContractOptions) => Effect.Effect<InMemoryServerPush, never, Scope.Scope>;
|
|
16
|
+
//# sourceMappingURL=server-push.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-push.d.ts","sourceRoot":"","sources":["../../src/doubles/server-push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,MAAM,EAAS,KAAK,KAAK,EAAU,MAAM,QAAQ,CAAC;AAE3D,OAAO,KAAK,EAGV,yBAAyB,EACzB,mBAAmB,EACpB,MAAM,sCAAsC,CAAC;AAE9C,6EAA6E;AAC7E,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,EAAE,MAAM,SAAS,WAAW,EAAE,CAAC;CAClD;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,+BAKpC,yBAAyB,KAAG,MAAM,CAAC,MAAM,CAC1C,kBAAkB,EAClB,KAAK,EACL,KAAK,CAAC,KAAK,CAgDT,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { audienceAdmits } from '@entifix/core';
|
|
2
|
+
import { Effect, Queue, Stream } from 'effect';
|
|
3
|
+
/**
|
|
4
|
+
* A push port for a host's specs: each open connection gets its own queue,
|
|
5
|
+
* filtered by topic and audience exactly as the real hub does, and every
|
|
6
|
+
* publish is recorded so a spec can assert what a projection pushed without
|
|
7
|
+
* opening a stream.
|
|
8
|
+
*/ export const makeInMemoryServerPush = ({ topicsOf, admits = (event, connection)=>audienceAdmits(event.audience, connection.recipient), resume = (_cursor, topics)=>Stream.make({
|
|
9
|
+
_tag: 'resync',
|
|
10
|
+
topics
|
|
11
|
+
}) })=>Effect.sync(()=>{
|
|
12
|
+
const published = [];
|
|
13
|
+
const open = new Map();
|
|
14
|
+
return {
|
|
15
|
+
published: ()=>[
|
|
16
|
+
...published
|
|
17
|
+
],
|
|
18
|
+
publish: (event)=>Effect.suspend(()=>{
|
|
19
|
+
published.push(event);
|
|
20
|
+
return Effect.forEach(Array.from(open), ([queue, connection])=>{
|
|
21
|
+
const topics = topicsOf(event).filter((topic)=>connection.topics.includes(topic));
|
|
22
|
+
return topics.length > 0 && admits(event, connection) ? Queue.offer(queue, {
|
|
23
|
+
_tag: 'event',
|
|
24
|
+
event,
|
|
25
|
+
topics
|
|
26
|
+
}) : Effect.void;
|
|
27
|
+
}, {
|
|
28
|
+
discard: true
|
|
29
|
+
});
|
|
30
|
+
}),
|
|
31
|
+
open: (connection)=>Stream.unwrap(Effect.map(Effect.acquireRelease(Effect.tap(Queue.unbounded(), (queue)=>Effect.sync(()=>open.set(queue, connection))), (queue)=>Effect.sync(()=>open.delete(queue))), (queue)=>{
|
|
32
|
+
const live = Stream.fromQueue(queue);
|
|
33
|
+
return connection.cursor === undefined ? live : Stream.concat(resume(connection.cursor, connection.topics), live);
|
|
34
|
+
}))
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=server-push.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/doubles/server-push.ts"],"sourcesContent":["import { audienceAdmits, type DomainEvent } from '@entifix/core';\nimport { Effect, Queue, type Scope, Stream } from 'effect';\n\nimport type {\n PushConnectionUnderTest,\n PushMessageUnderTest,\n ServerPushContractOptions,\n ServerPushUnderTest,\n} from '../contracts/server-push.contract.js';\n\n/** An in-memory push port that also remembers everything published to it. */\nexport interface InMemoryServerPush extends ServerPushUnderTest {\n /** Every event published, in order, whether or not anyone received it. */\n readonly published: () => readonly DomainEvent[];\n}\n\n/**\n * A push port for a host's specs: each open connection gets its own queue,\n * filtered by topic and audience exactly as the real hub does, and every\n * publish is recorded so a spec can assert what a projection pushed without\n * opening a stream.\n */\nexport const makeInMemoryServerPush = ({\n topicsOf,\n admits = (event, connection) =>\n audienceAdmits(event.audience, connection.recipient),\n resume = (_cursor, topics) => Stream.make({ _tag: 'resync', topics }),\n}: ServerPushContractOptions): Effect.Effect<\n InMemoryServerPush,\n never,\n Scope.Scope\n> =>\n Effect.sync(() => {\n const published: DomainEvent[] = [];\n const open = new Map<\n Queue.Queue<PushMessageUnderTest>,\n PushConnectionUnderTest\n >();\n\n return {\n published: () => [...published],\n publish: event =>\n Effect.suspend(() => {\n published.push(event);\n return Effect.forEach(\n Array.from(open),\n ([queue, connection]) => {\n const topics = topicsOf(event).filter(topic =>\n connection.topics.includes(topic),\n );\n return topics.length > 0 && admits(event, connection)\n ? Queue.offer(queue, { _tag: 'event', event, topics })\n : Effect.void;\n },\n { discard: true },\n );\n }),\n open: connection =>\n Stream.unwrap(\n Effect.map(\n Effect.acquireRelease(\n Effect.tap(Queue.unbounded<PushMessageUnderTest>(), queue =>\n Effect.sync(() => open.set(queue, connection)),\n ),\n queue => Effect.sync(() => open.delete(queue)),\n ),\n queue => {\n const live = Stream.fromQueue(queue);\n return connection.cursor === undefined\n ? live\n : Stream.concat(\n resume(connection.cursor, connection.topics),\n live,\n );\n },\n ),\n ),\n };\n });\n"],"names":["audienceAdmits","Effect","Queue","Stream","makeInMemoryServerPush","topicsOf","admits","event","connection","audience","recipient","resume","_cursor","topics","make","_tag","sync","published","open","Map","publish","suspend","push","forEach","Array","from","queue","filter","topic","includes","length","offer","void","discard","unwrap","map","acquireRelease","tap","unbounded","set","delete","live","fromQueue","cursor","undefined","concat"],"mappings":"AAAA,SAASA,cAAc,QAA0B,gBAAgB;AACjE,SAASC,MAAM,EAAEC,KAAK,EAAcC,MAAM,QAAQ,SAAS;AAe3D;;;;;CAKC,GACD,OAAO,MAAMC,yBAAyB,CAAC,EACrCC,QAAQ,EACRC,SAAS,CAACC,OAAOC,aACfR,eAAeO,MAAME,QAAQ,EAAED,WAAWE,SAAS,CAAC,EACtDC,SAAS,CAACC,SAASC,SAAWV,OAAOW,IAAI,CAAC;QAAEC,MAAM;QAAUF;IAAO,EAAE,EAC3C,GAK1BZ,OAAOe,IAAI,CAAC;QACV,MAAMC,YAA2B,EAAE;QACnC,MAAMC,OAAO,IAAIC;QAKjB,OAAO;YACLF,WAAW,IAAM;uBAAIA;iBAAU;YAC/BG,SAASb,CAAAA,QACPN,OAAOoB,OAAO,CAAC;oBACbJ,UAAUK,IAAI,CAACf;oBACf,OAAON,OAAOsB,OAAO,CACnBC,MAAMC,IAAI,CAACP,OACX,CAAC,CAACQ,OAAOlB,WAAW;wBAClB,MAAMK,SAASR,SAASE,OAAOoB,MAAM,CAACC,CAAAA,QACpCpB,WAAWK,MAAM,CAACgB,QAAQ,CAACD;wBAE7B,OAAOf,OAAOiB,MAAM,GAAG,KAAKxB,OAAOC,OAAOC,cACtCN,MAAM6B,KAAK,CAACL,OAAO;4BAAEX,MAAM;4BAASR;4BAAOM;wBAAO,KAClDZ,OAAO+B,IAAI;oBACjB,GACA;wBAAEC,SAAS;oBAAK;gBAEpB;YACFf,MAAMV,CAAAA,aACJL,OAAO+B,MAAM,CACXjC,OAAOkC,GAAG,CACRlC,OAAOmC,cAAc,CACnBnC,OAAOoC,GAAG,CAACnC,MAAMoC,SAAS,IAA0BZ,CAAAA,QAClDzB,OAAOe,IAAI,CAAC,IAAME,KAAKqB,GAAG,CAACb,OAAOlB,eAEpCkB,CAAAA,QAASzB,OAAOe,IAAI,CAAC,IAAME,KAAKsB,MAAM,CAACd,UAEzCA,CAAAA;oBACE,MAAMe,OAAOtC,OAAOuC,SAAS,CAAChB;oBAC9B,OAAOlB,WAAWmC,MAAM,KAAKC,YACzBH,OACAtC,OAAO0C,MAAM,CACXlC,OAAOH,WAAWmC,MAAM,EAAEnC,WAAWK,MAAM,GAC3C4B;gBAER;QAGR;IACF,GAAG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DomainEvent, type
|
|
1
|
+
import { type DomainEvent, type EntifixFailure } from '@entifix/core';
|
|
2
2
|
import type { EventBus, LockService, SagaInstance, SagaStore, SequenceService, TransactionInbox } from '@entifix/transactions';
|
|
3
3
|
import { Effect } from 'effect';
|
|
4
4
|
export interface InMemoryLockService extends LockService {
|
|
@@ -40,7 +40,7 @@ export interface RecordingEventBus extends EventBus {
|
|
|
40
40
|
* broker's job in production, so a double that ignored it would let a
|
|
41
41
|
* consumer pass its tests while receiving traffic it never bound to.
|
|
42
42
|
*/
|
|
43
|
-
deliver(event: DomainEvent): Effect.Effect<void,
|
|
43
|
+
deliver(event: DomainEvent): Effect.Effect<void, EntifixFailure>;
|
|
44
44
|
/** Makes the next `publish` fail, for the broker-unavailable branch. */
|
|
45
45
|
failNextPublish(): void;
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-ports.d.ts","sourceRoot":"","sources":["../../src/doubles/transaction-ports.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"transaction-ports.d.ts","sourceRoot":"","sources":["../../src/doubles/transaction-ports.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,cAAc,EAGpB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,QAAQ,EAER,WAAW,EACX,YAAY,EACZ,SAAS,EACT,eAAe,EACf,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IACxB,sDAAsD;IACtD,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;QAAE,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5E;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAAO,mBAkC1C,CAAC;AAEF,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACnD;AAED;;;GAGG;AACH,eAAO,MAAM,2BAA2B,QAAO,uBAc9C,CAAC;AAEF,MAAM,WAAW,iBAAkB,SAAQ,QAAQ;IACjD,uCAAuC;IACvC,QAAQ,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC;IAClC;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACjE,wEAAwE;IACxE,eAAe,IAAI,IAAI,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAO,iBAwCxC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB;IAI5B,0DAA0D;oBAC1C,MAAM,KAAG,gBAAgB;qBAS3B,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE;CAOjE,CAAC;AAEF,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,SAAS,YAAY,EAAE,CAAC;CAC7C;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,QAAO,iBAwExC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/doubles/transaction-ports.ts"],"sourcesContent":["import {\n Contention,\n type DomainEvent,\n matchesEventPattern,\n type TransitionalFailure,\n Unavailable,\n} from '@entifix/core';\nimport type {\n EventBus,\n LockHandle,\n LockService,\n SagaInstance,\n SagaStore,\n SequenceService,\n TransactionInbox,\n} from '@entifix/transactions';\nimport { Effect } from 'effect';\n\nexport interface InMemoryLockService extends LockService {\n /** Keys currently held, in acquisition order. */\n readonly held: string[];\n /** Every acquire/release in the order it happened. */\n readonly log: ReadonlyArray<{ action: 'acquire' | 'release'; key: string }>;\n /**\n * Marks `key` as already taken by someone else, so the next `acquire` fails\n * with {@link Contention} — the 409 path of the transaction facade.\n */\n contendOn(key: string): void;\n}\n\n/**\n * In-memory {@link LockService}. Acquisition is immediate and uncontended\n * unless {@link InMemoryLockService.contendOn} says otherwise, and `release`\n * only frees a lock whose token matches — the compare-and-delete rule the Redis\n * adapter enforces with a Lua script.\n */\nexport const makeInMemoryLockService = (): InMemoryLockService => {\n const tokens = new Map<string, string>();\n const contended = new Set<string>();\n const log: Array<{ action: 'acquire' | 'release'; key: string }> = [];\n let counter = 0;\n\n return {\n acquire: key =>\n Effect.suspend(() => {\n if (contended.has(key) || tokens.has(key)) {\n return Effect.fail(new Contention());\n }\n const token = `token-${(counter += 1)}`;\n tokens.set(key, token);\n log.push({ action: 'acquire', key });\n return Effect.succeed({ key, token });\n }),\n release: (handle: LockHandle) =>\n Effect.sync(() => {\n if (tokens.get(handle.key) === handle.token) {\n tokens.delete(handle.key);\n log.push({ action: 'release', key: handle.key });\n }\n }),\n get held() {\n return [...tokens.keys()];\n },\n get log() {\n return log;\n },\n contendOn: key => {\n contended.add(key);\n },\n };\n};\n\nexport interface InMemorySequenceService extends SequenceService {\n /** The current value of every sequence drawn from so far. */\n readonly values: Readonly<Record<string, number>>;\n}\n\n/**\n * In-memory {@link SequenceService} — a plain counter per name. Atomicity is\n * what the Redis `INCR` adapter buys; single-threaded JS gives it for free here.\n */\nexport const makeInMemorySequenceService = (): InMemorySequenceService => {\n const sequences = new Map<string, number>();\n\n return {\n next: name =>\n Effect.sync(() => {\n const next = (sequences.get(name) ?? 0) + 1;\n sequences.set(name, next);\n return next;\n }),\n get values() {\n return Object.fromEntries(sequences);\n },\n };\n};\n\nexport interface RecordingEventBus extends EventBus {\n /** Every event published, in order. */\n readonly published: DomainEvent[];\n /**\n * Pushes an event to the subscribers whose pattern matches it, as a topic\n * exchange would. Deliberately not \"to all subscribers\": routing is the\n * broker's job in production, so a double that ignored it would let a\n * consumer pass its tests while receiving traffic it never bound to.\n */\n deliver(event: DomainEvent): Effect.Effect<void, TransitionalFailure>;\n /** Makes the next `publish` fail, for the broker-unavailable branch. */\n failNextPublish(): void;\n}\n\n/**\n * In-memory {@link EventBus} that records what was published rather than\n * asserting on it. Prefer reading `bus.published` in a test over a mock's call\n * assertions: the expectation then reads as state, not as a spy protocol.\n */\nexport const makeRecordingEventBus = (): RecordingEventBus => {\n const published: DomainEvent[] = [];\n const handlers: Array<{\n pattern: string;\n handle: (event: DomainEvent) => Effect.Effect<void, TransitionalFailure>;\n }> = [];\n let failNext = false;\n\n return {\n publish: event =>\n Effect.suspend(() => {\n if (failNext) {\n failNext = false;\n return Effect.fail(new Unavailable({ dependency: 'bus' }));\n }\n published.push(event);\n return Effect.void;\n }),\n subscribe: (subscription, handle) =>\n Effect.sync(() => {\n // Only the pattern is retained: queue durability and the delivery\n // ceiling are broker facts with no in-memory analogue, and faking them\n // would assert against the double rather than against a broker.\n handlers.push({ pattern: subscription.pattern, handle });\n }),\n deliver: event =>\n Effect.forEach(\n handlers.filter(({ pattern }) =>\n matchesEventPattern(pattern, event.name),\n ),\n ({ handle }) => handle(event),\n { discard: true },\n ),\n get published() {\n return published;\n },\n failNextPublish: () => {\n failNext = true;\n },\n };\n};\n\n/**\n * An in-memory {@link TransactionInbox}, one per consumer, over a shared claim\n * set.\n *\n * Sharing the set across the inboxes one factory hands out is what makes the\n * contract's \"one consumer cannot consume another's claim\" case a real\n * assertion, rather than one the double satisfies by only ever having seen a\n * single consumer.\n */\nexport const makeInMemoryInboxes = () => {\n const claimed = new Set<string>();\n\n return {\n /** An inbox for `consumer`, over the shared claim set. */\n for: (consumer: string): TransactionInbox => ({\n claim: eventId =>\n Effect.sync(() => {\n const key = JSON.stringify([consumer, eventId]);\n if (claimed.has(key)) return 'duplicate' as const;\n claimed.add(key);\n return 'claimed' as const;\n }),\n }),\n get claims(): readonly { consumer: string; eventId: string }[] {\n return [...claimed].map(key => {\n const [consumer, eventId] = JSON.parse(key) as [string, string];\n return { consumer, eventId };\n });\n },\n };\n};\n\nexport interface InMemorySagaStore extends SagaStore {\n /** Every instance, as stored — for a spec to assert on state, not calls. */\n readonly instances: readonly SagaInstance[];\n}\n\n/**\n * In-memory {@link SagaStore}, with the Mongo adapter's semantics: `start`\n * never overwrites, outcomes append, and a resume claim only takes an\n * unfinished instance whose `updatedAt` is past the deadline — counting the\n * attempt and re-stamping it, so the next sweep does not find it again.\n */\nexport const makeInMemorySagaStore = (): InMemorySagaStore => {\n const instances = new Map<string, SagaInstance>();\n const stamp = () => new Date().toISOString();\n const unfinished = (entry: SagaInstance) =>\n entry.state === 'RUNNING' || entry.state === 'COMPENSATING';\n const pastDeadline = (entry: SagaInstance, olderThanMs: number) =>\n entry.updatedAt < new Date(Date.now() - olderThanMs).toISOString();\n const update = (\n sagaId: string,\n change: (entry: SagaInstance) => SagaInstance,\n ) =>\n Effect.sync(() => {\n const current = instances.get(sagaId);\n if (current !== undefined) {\n instances.set(sagaId, { ...change(current), updatedAt: stamp() });\n }\n });\n\n return {\n start: started =>\n Effect.sync(() => {\n if (!instances.has(started.sagaId)) {\n instances.set(started.sagaId, { ...started, updatedAt: stamp() });\n }\n }),\n beginStep: (sagaId, stepIndex) =>\n update(sagaId, entry => ({ ...entry, stepIndex })),\n recordOutcome: (sagaId, outcome) =>\n update(sagaId, entry => ({\n ...entry,\n outcomes: [...entry.outcomes, outcome],\n })),\n settle: (sagaId, state, error) =>\n update(sagaId, entry => ({ ...entry, state, error })),\n markCompensated: (sagaId, stepId) =>\n update(sagaId, entry => ({\n ...entry,\n outcomes: entry.outcomes.map(outcome =>\n outcome.stepId === stepId\n ? { ...outcome, compensated: true }\n : outcome,\n ),\n })),\n get: sagaId => Effect.sync(() => instances.get(sagaId)),\n findStale: olderThanMs =>\n Effect.sync(() =>\n [...instances.values()].filter(\n entry => unfinished(entry) && pastDeadline(entry, olderThanMs),\n ),\n ),\n claimForResume: (sagaId, olderThanMs) =>\n Effect.sync(() => {\n const current = instances.get(sagaId);\n if (\n current === undefined ||\n !unfinished(current) ||\n !pastDeadline(current, olderThanMs)\n ) {\n return undefined;\n }\n const claimed = {\n ...current,\n resumeAttempts: current.resumeAttempts + 1,\n updatedAt: stamp(),\n };\n instances.set(sagaId, claimed);\n return claimed;\n }),\n get instances() {\n return [...instances.values()];\n },\n };\n};\n"],"names":["Contention","matchesEventPattern","Unavailable","Effect","makeInMemoryLockService","tokens","Map","contended","Set","log","counter","acquire","key","suspend","has","fail","token","set","push","action","succeed","release","handle","sync","get","delete","held","keys","contendOn","add","makeInMemorySequenceService","sequences","next","name","values","Object","fromEntries","makeRecordingEventBus","published","handlers","failNext","publish","event","dependency","void","subscribe","subscription","pattern","deliver","forEach","filter","discard","failNextPublish","makeInMemoryInboxes","claimed","for","consumer","claim","eventId","JSON","stringify","claims","map","parse","makeInMemorySagaStore","instances","stamp","Date","toISOString","unfinished","entry","state","pastDeadline","olderThanMs","updatedAt","now","update","sagaId","change","current","undefined","start","started","beginStep","stepIndex","recordOutcome","outcome","outcomes","settle","error","markCompensated","stepId","compensated","findStale","claimForResume","resumeAttempts"],"mappings":";AAAA,SACEA,UAAU,EAEVC,mBAAmB,EAEnBC,WAAW,QACN,gBAAgB;AAUvB,SAASC,MAAM,QAAQ,SAAS;AAchC;;;;;CAKC,GACD,OAAO,MAAMC,0BAA0B;IACrC,MAAMC,SAAS,IAAIC;IACnB,MAAMC,YAAY,IAAIC;IACtB,MAAMC,MAA6D,EAAE;IACrE,IAAIC,UAAU;IAEd,OAAO;QACLC,SAASC,CAAAA,MACPT,OAAOU,OAAO,CAAC;gBACb,IAAIN,UAAUO,GAAG,CAACF,QAAQP,OAAOS,GAAG,CAACF,MAAM;oBACzC,OAAOT,OAAOY,IAAI,CAAC,IAAIf;gBACzB;gBACA,MAAMgB,QAAQ,CAAC,MAAM,EAAGN,WAAW,GAAI;gBACvCL,OAAOY,GAAG,CAACL,KAAKI;gBAChBP,IAAIS,IAAI,CAAC;oBAAEC,QAAQ;oBAAWP;gBAAI;gBAClC,OAAOT,OAAOiB,OAAO,CAAC;oBAAER;oBAAKI;gBAAM;YACrC;QACFK,SAAS,CAACC,SACRnB,OAAOoB,IAAI,CAAC;gBACV,IAAIlB,OAAOmB,GAAG,CAACF,OAAOV,GAAG,MAAMU,OAAON,KAAK,EAAE;oBAC3CX,OAAOoB,MAAM,CAACH,OAAOV,GAAG;oBACxB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ACzCrB,WAAWR;;gBAEbD,UAAUhD,GAAG,CAAC4D,QAAQvB;gBACtB,OAAOA;YACT;QACF,IAAIW;YACF,OAAO;mBAAIA,UAAU/B,MAAM;aAAG;QAChC;IACF;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/doubles/transaction-ports.ts"],"sourcesContent":["import {\n Contention,\n type DomainEvent,\n type EntifixFailure,\n matchesEventPattern,\n Unavailable,\n} from '@entifix/core';\nimport type {\n EventBus,\n LockHandle,\n LockService,\n SagaInstance,\n SagaStore,\n SequenceService,\n TransactionInbox,\n} from '@entifix/transactions';\nimport { Effect } from 'effect';\n\nexport interface InMemoryLockService extends LockService {\n /** Keys currently held, in acquisition order. */\n readonly held: string[];\n /** Every acquire/release in the order it happened. */\n readonly log: ReadonlyArray<{ action: 'acquire' | 'release'; key: string }>;\n /**\n * Marks `key` as already taken by someone else, so the next `acquire` fails\n * with {@link Contention} — the 409 path of the transaction facade.\n */\n contendOn(key: string): void;\n}\n\n/**\n * In-memory {@link LockService}. Acquisition is immediate and uncontended\n * unless {@link InMemoryLockService.contendOn} says otherwise, and `release`\n * only frees a lock whose token matches — the compare-and-delete rule the Redis\n * adapter enforces with a Lua script.\n */\nexport const makeInMemoryLockService = (): InMemoryLockService => {\n const tokens = new Map<string, string>();\n const contended = new Set<string>();\n const log: Array<{ action: 'acquire' | 'release'; key: string }> = [];\n let counter = 0;\n\n return {\n acquire: key =>\n Effect.suspend(() => {\n if (contended.has(key) || tokens.has(key)) {\n return Effect.fail(new Contention());\n }\n const token = `token-${(counter += 1)}`;\n tokens.set(key, token);\n log.push({ action: 'acquire', key });\n return Effect.succeed({ key, token });\n }),\n release: (handle: LockHandle) =>\n Effect.sync(() => {\n if (tokens.get(handle.key) === handle.token) {\n tokens.delete(handle.key);\n log.push({ action: 'release', key: handle.key });\n }\n }),\n get held() {\n return [...tokens.keys()];\n },\n get log() {\n return log;\n },\n contendOn: key => {\n contended.add(key);\n },\n };\n};\n\nexport interface InMemorySequenceService extends SequenceService {\n /** The current value of every sequence drawn from so far. */\n readonly values: Readonly<Record<string, number>>;\n}\n\n/**\n * In-memory {@link SequenceService} — a plain counter per name. Atomicity is\n * what the Redis `INCR` adapter buys; single-threaded JS gives it for free here.\n */\nexport const makeInMemorySequenceService = (): InMemorySequenceService => {\n const sequences = new Map<string, number>();\n\n return {\n next: name =>\n Effect.sync(() => {\n const next = (sequences.get(name) ?? 0) + 1;\n sequences.set(name, next);\n return next;\n }),\n get values() {\n return Object.fromEntries(sequences);\n },\n };\n};\n\nexport interface RecordingEventBus extends EventBus {\n /** Every event published, in order. */\n readonly published: DomainEvent[];\n /**\n * Pushes an event to the subscribers whose pattern matches it, as a topic\n * exchange would. Deliberately not \"to all subscribers\": routing is the\n * broker's job in production, so a double that ignored it would let a\n * consumer pass its tests while receiving traffic it never bound to.\n */\n deliver(event: DomainEvent): Effect.Effect<void, EntifixFailure>;\n /** Makes the next `publish` fail, for the broker-unavailable branch. */\n failNextPublish(): void;\n}\n\n/**\n * In-memory {@link EventBus} that records what was published rather than\n * asserting on it. Prefer reading `bus.published` in a test over a mock's call\n * assertions: the expectation then reads as state, not as a spy protocol.\n */\nexport const makeRecordingEventBus = (): RecordingEventBus => {\n const published: DomainEvent[] = [];\n const handlers: Array<{\n pattern: string;\n handle: (event: DomainEvent) => Effect.Effect<void, EntifixFailure>;\n }> = [];\n let failNext = false;\n\n return {\n publish: event =>\n Effect.suspend(() => {\n if (failNext) {\n failNext = false;\n return Effect.fail(new Unavailable({ dependency: 'bus' }));\n }\n published.push(event);\n return Effect.void;\n }),\n subscribe: (subscription, handle) =>\n Effect.sync(() => {\n // Only the pattern is retained: queue durability and the delivery\n // ceiling are broker facts with no in-memory analogue, and faking them\n // would assert against the double rather than against a broker.\n handlers.push({ pattern: subscription.pattern, handle });\n }),\n deliver: event =>\n Effect.forEach(\n handlers.filter(({ pattern }) =>\n matchesEventPattern(pattern, event.name),\n ),\n ({ handle }) => handle(event),\n { discard: true },\n ),\n get published() {\n return published;\n },\n failNextPublish: () => {\n failNext = true;\n },\n };\n};\n\n/**\n * An in-memory {@link TransactionInbox}, one per consumer, over a shared claim\n * set.\n *\n * Sharing the set across the inboxes one factory hands out is what makes the\n * contract's \"one consumer cannot consume another's claim\" case a real\n * assertion, rather than one the double satisfies by only ever having seen a\n * single consumer.\n */\nexport const makeInMemoryInboxes = () => {\n const claimed = new Set<string>();\n\n return {\n /** An inbox for `consumer`, over the shared claim set. */\n for: (consumer: string): TransactionInbox => ({\n claim: eventId =>\n Effect.sync(() => {\n const key = JSON.stringify([consumer, eventId]);\n if (claimed.has(key)) return 'duplicate' as const;\n claimed.add(key);\n return 'claimed' as const;\n }),\n }),\n get claims(): readonly { consumer: string; eventId: string }[] {\n return [...claimed].map(key => {\n const [consumer, eventId] = JSON.parse(key) as [string, string];\n return { consumer, eventId };\n });\n },\n };\n};\n\nexport interface InMemorySagaStore extends SagaStore {\n /** Every instance, as stored — for a spec to assert on state, not calls. */\n readonly instances: readonly SagaInstance[];\n}\n\n/**\n * In-memory {@link SagaStore}, with the Mongo adapter's semantics: `start`\n * never overwrites, outcomes append, and a resume claim only takes an\n * unfinished instance whose `updatedAt` is past the deadline — counting the\n * attempt and re-stamping it, so the next sweep does not find it again.\n */\nexport const makeInMemorySagaStore = (): InMemorySagaStore => {\n const instances = new Map<string, SagaInstance>();\n const stamp = () => new Date().toISOString();\n const unfinished = (entry: SagaInstance) =>\n entry.state === 'RUNNING' || entry.state === 'COMPENSATING';\n const pastDeadline = (entry: SagaInstance, olderThanMs: number) =>\n entry.updatedAt < new Date(Date.now() - olderThanMs).toISOString();\n const update = (\n sagaId: string,\n change: (entry: SagaInstance) => SagaInstance,\n ) =>\n Effect.sync(() => {\n const current = instances.get(sagaId);\n if (current !== undefined) {\n instances.set(sagaId, { ...change(current), updatedAt: stamp() });\n }\n });\n\n return {\n start: started =>\n Effect.sync(() => {\n if (!instances.has(started.sagaId)) {\n instances.set(started.sagaId, { ...started, updatedAt: stamp() });\n }\n }),\n beginStep: (sagaId, stepIndex) =>\n update(sagaId, entry => ({ ...entry, stepIndex })),\n recordOutcome: (sagaId, outcome) =>\n update(sagaId, entry => ({\n ...entry,\n outcomes: [...entry.outcomes, outcome],\n })),\n settle: (sagaId, state, error) =>\n update(sagaId, entry => ({ ...entry, state, error })),\n markCompensated: (sagaId, stepId) =>\n update(sagaId, entry => ({\n ...entry,\n outcomes: entry.outcomes.map(outcome =>\n outcome.stepId === stepId\n ? { ...outcome, compensated: true }\n : outcome,\n ),\n })),\n get: sagaId => Effect.sync(() => instances.get(sagaId)),\n findStale: olderThanMs =>\n Effect.sync(() =>\n [...instances.values()].filter(\n entry => unfinished(entry) && pastDeadline(entry, olderThanMs),\n ),\n ),\n claimForResume: (sagaId, olderThanMs) =>\n Effect.sync(() => {\n const current = instances.get(sagaId);\n if (\n current === undefined ||\n !unfinished(current) ||\n !pastDeadline(current, olderThanMs)\n ) {\n return undefined;\n }\n const claimed = {\n ...current,\n resumeAttempts: current.resumeAttempts + 1,\n updatedAt: stamp(),\n };\n instances.set(sagaId, claimed);\n return claimed;\n }),\n get instances() {\n return [...instances.values()];\n },\n };\n};\n"],"names":["Contention","matchesEventPattern","Unavailable","Effect","makeInMemoryLockService","tokens","Map","contended","Set","log","counter","acquire","key","suspend","has","fail","token","set","push","action","succeed","release","handle","sync","get","delete","held","keys","contendOn","add","makeInMemorySequenceService","sequences","next","name","values","Object","fromEntries","makeRecordingEventBus","published","handlers","failNext","publish","event","dependency","void","subscribe","subscription","pattern","deliver","forEach","filter","discard","failNextPublish","makeInMemoryInboxes","claimed","for","consumer","claim","eventId","JSON","stringify","claims","map","parse","makeInMemorySagaStore","instances","stamp","Date","toISOString","unfinished","entry","state","pastDeadline","olderThanMs","updatedAt","now","update","sagaId","change","current","undefined","start","started","beginStep","stepIndex","recordOutcome","outcome","outcomes","settle","error","markCompensated","stepId","compensated","findStale","claimForResume","resumeAttempts"],"mappings":";AAAA,SACEA,UAAU,EAGVC,mBA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AAOC,QAAQP,CAAAA,QAAU,aAAKA;oBAAOC;oBAAOkB;;QAC9CC,iBAAiB,CAACb,QAAQc,SACxBf,OAAOC,QAAQP,CAAAA,QAAU,aACpBA;oBACHiB,UAAUjB,MAAMiB,QAAQ,CAACzB,GAAG,CAACwB,CAAAA,UAC3BA,QAAQK,MAAM,KAAKA,SACf,aAAKL;4BAASM,aAAa;6BAC3BN;;QAGV9D,KAAKqD,CAAAA,SAAU1E,OAAOoB,IAAI,CAAC,IAAM0C,UAAUzC,GAAG,CAACqD;QAC/CgB,WAAWpB,CAAAA,cACTtE,OAAOoB,IAAI,CAAC,IACV;uBAAI0C,UAAU/B,MAAM;iBAAG,CAACgB,MAAM,CAC5BoB,CAAAA,QAASD,WAAWC,UAAUE,aAAaF,OAAOG;QAGxDqB,gBAAgB,CAACjB,QAAQJ,cACvBtE,OAAOoB,IAAI,CAAC;gBACV,MAAMwD,UAAUd,UAAUzC,GAAG,CAACqD;gBAC9B,IACEE,YAAYC,aACZ,CAACX,WAAWU,YACZ,CAACP,aAAaO,SAASN,cACvB;oBACA,OAAOO;gBACT;gBACA,MAAM1B,UAAU,aACXyB;oBACHgB,gBAAgBhB,QAAQgB,cAAc,GAAG;oBACzCrB,WAAWR;;gBAEbD,UAAUhD,GAAG,CAAC4D,QAAQvB;gBACtB,OAAOA;YACT;QACF,IAAIW;YACF,OAAO;mBAAIA,UAAU/B,MAAM;aAAG;QAChC;IACF;AACF,EAAE"}
|
|
@@ -21,7 +21,7 @@ export interface FakeMongoDb {
|
|
|
21
21
|
read(collection: string): Document[];
|
|
22
22
|
/**
|
|
23
23
|
* Makes every subsequent driver call reject with `error`, so the adapter's
|
|
24
|
-
* `
|
|
24
|
+
* `Unavailable` mapping is reachable. Pass `undefined` to restore.
|
|
25
25
|
*/
|
|
26
26
|
failWith(error: unknown): void;
|
|
27
27
|
/**
|