@cratis/chronicle 6.31.1 → 6.31.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cratis/chronicle",
|
|
3
|
-
"version": "6.31.
|
|
3
|
+
"version": "6.31.2",
|
|
4
4
|
"description": "Event sourcing for TypeScript and Node.js — the idiomatic client for Cratis Chronicle, the open-source event-sourcing database",
|
|
5
5
|
"author": "Cratis",
|
|
6
6
|
"license": "MIT",
|
|
@@ -173,25 +173,25 @@
|
|
|
173
173
|
},
|
|
174
174
|
"dependencies": {
|
|
175
175
|
"@bufbuild/protobuf": "^2.15.0",
|
|
176
|
-
"@cratis/chronicle.contracts": "19.
|
|
177
|
-
"@grpc/grpc-js": "^1.14.
|
|
176
|
+
"@cratis/chronicle.contracts": "19.8.1",
|
|
177
|
+
"@grpc/grpc-js": "^1.14.5",
|
|
178
178
|
"@opentelemetry/api": "^1.9.1",
|
|
179
179
|
"glob": "^13.0.6",
|
|
180
180
|
"nice-grpc": "^2.1.17",
|
|
181
181
|
"nice-grpc-common": "^2.0.4",
|
|
182
182
|
"reflect-metadata": "^0.2.2",
|
|
183
|
-
"undici": "^8.
|
|
183
|
+
"undici": "^8.11.2"
|
|
184
184
|
},
|
|
185
185
|
"devDependencies": {
|
|
186
|
-
"@cratis/fundamentals": "7.19.
|
|
187
|
-
"@types/node": "^26.
|
|
186
|
+
"@cratis/fundamentals": "7.19.6",
|
|
187
|
+
"@types/node": "^26.6.3",
|
|
188
188
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
189
189
|
"esbuild": "^0.28.2",
|
|
190
190
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
191
|
-
"vite": "^8.3.
|
|
192
|
-
"vitest": "^5.0.
|
|
191
|
+
"vite": "^8.3.1",
|
|
192
|
+
"vitest": "^5.0.2"
|
|
193
193
|
},
|
|
194
194
|
"peerDependencies": {
|
|
195
|
-
"@cratis/fundamentals": "^7.19.
|
|
195
|
+
"@cratis/fundamentals": "^7.19.6"
|
|
196
196
|
}
|
|
197
197
|
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { afterAll, beforeAll, chai, describe, it } from 'vitest';
|
|
6
|
+
import { field } from '@cratis/fundamentals';
|
|
7
|
+
import { ChronicleClient } from '../../../ChronicleClient.js';
|
|
8
|
+
import { ChronicleOptions } from '../../../ChronicleOptions.js';
|
|
9
|
+
import type { IClientArtifactsProvider } from '../../../artifacts/index.js';
|
|
10
|
+
import type { ChronicleConnection } from '../../../connection/index.js';
|
|
11
|
+
import { eventType } from '../../../events/index.js';
|
|
12
|
+
import type { IEventStore } from '../../../IEventStore.js';
|
|
13
|
+
import { onceOnly } from '../../onceOnly.js';
|
|
14
|
+
import { reactor } from '../../reactor.js';
|
|
15
|
+
import { replay } from '../../replay.js';
|
|
16
|
+
|
|
17
|
+
chai.should();
|
|
18
|
+
|
|
19
|
+
// Runs against a real Chronicle kernel; skipped locally unless the connection string is set (see vitest.integration.config.ts).
|
|
20
|
+
// In CI it never skips, so a missing connection string or unreachable kernel fails instead of passing vacuously.
|
|
21
|
+
const connectionString = process.env.CHRONICLE_INTEGRATION_CONNECTION_STRING;
|
|
22
|
+
|
|
23
|
+
@eventType()
|
|
24
|
+
class MethodOnceOnlyHappened {
|
|
25
|
+
@field(String) name = '';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@eventType()
|
|
29
|
+
class MethodReplayableHappened {
|
|
30
|
+
@field(String) name = '';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@eventType()
|
|
34
|
+
class MethodReplayOnceOnlyHappened {
|
|
35
|
+
@field(String) name = '';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The client constructs reactor instances; share a sink for assertions across that boundary.
|
|
39
|
+
const invocations: string[] = [];
|
|
40
|
+
|
|
41
|
+
@reactor()
|
|
42
|
+
class MixedOnceOnlyReactor {
|
|
43
|
+
@onceOnly()
|
|
44
|
+
methodOnceOnlyHappened(event: MethodOnceOnlyHappened) { invocations.push(`once-only:${event.name}`); }
|
|
45
|
+
|
|
46
|
+
methodReplayableHappened(event: MethodReplayableHappened) { invocations.push(`replayable:${event.name}`); }
|
|
47
|
+
|
|
48
|
+
methodReplayOnceOnlyHappened(event: MethodReplayOnceOnlyHappened) { invocations.push(`live:${event.name}`); }
|
|
49
|
+
|
|
50
|
+
@replay()
|
|
51
|
+
@onceOnly()
|
|
52
|
+
replayMethodReplayOnceOnlyHappened(event: MethodReplayOnceOnlyHappened) { invocations.push(`replay:${event.name}`); }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const artifacts: IClientArtifactsProvider = {
|
|
56
|
+
eventTypes: [MethodOnceOnlyHappened, MethodReplayableHappened, MethodReplayOnceOnlyHappened],
|
|
57
|
+
readModels: [],
|
|
58
|
+
reactors: [MixedOnceOnlyReactor],
|
|
59
|
+
reducers: [],
|
|
60
|
+
seeders: [],
|
|
61
|
+
constraints: [],
|
|
62
|
+
projections: [],
|
|
63
|
+
webhooks: [],
|
|
64
|
+
eventTypeMigrations: [],
|
|
65
|
+
globalForHandlers: []
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
async function eventually(accept: () => boolean, timeoutMs = 30_000): Promise<void> {
|
|
69
|
+
const deadline = Date.now() + timeoutMs;
|
|
70
|
+
while (!accept()) {
|
|
71
|
+
if (Date.now() > deadline) throw new Error('Timed out waiting for the kernel');
|
|
72
|
+
await new Promise(resolve => setTimeout(resolve, 250));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const isEmptyJobId = (jobId: string | undefined) => /^[0-]*$/.test(jobId ?? '');
|
|
77
|
+
|
|
78
|
+
describe.skipIf(!connectionString && !process.env.CI)('when replaying a reactor with once-only handlers against a kernel', () => {
|
|
79
|
+
const storeName = `Method${randomUUID().replaceAll('-', '').slice(0, 12)}`;
|
|
80
|
+
let client: ChronicleClient;
|
|
81
|
+
let store: IEventStore;
|
|
82
|
+
let connection: ChronicleConnection;
|
|
83
|
+
let jobId: string | undefined;
|
|
84
|
+
let invocationsBeforeReplay: string[];
|
|
85
|
+
|
|
86
|
+
beforeAll(async () => {
|
|
87
|
+
client = new ChronicleClient(ChronicleOptions.fromConnectionString(connectionString!, {
|
|
88
|
+
discoveryPatterns: [],
|
|
89
|
+
clientArtifactsProvider: artifacts
|
|
90
|
+
}));
|
|
91
|
+
store = await client.getEventStore(storeName);
|
|
92
|
+
connection = (store as unknown as { _connection: ChronicleConnection })._connection;
|
|
93
|
+
|
|
94
|
+
(await store.eventLog.append(randomUUID(), Object.assign(new MethodOnceOnlyHappened(), { name: 'a' }))).isSuccess.should.be.true;
|
|
95
|
+
(await store.eventLog.append(randomUUID(), Object.assign(new MethodReplayableHappened(), { name: 'b' }))).isSuccess.should.be.true;
|
|
96
|
+
(await store.eventLog.append(randomUUID(), Object.assign(new MethodReplayOnceOnlyHappened(), { name: 'c' }))).isSuccess.should.be.true;
|
|
97
|
+
await eventually(() => invocations.length === 3);
|
|
98
|
+
invocationsBeforeReplay = [...invocations];
|
|
99
|
+
|
|
100
|
+
jobId = (await connection.observers.replay({
|
|
101
|
+
EventStore: storeName,
|
|
102
|
+
Namespace: 'Default',
|
|
103
|
+
ObserverId: 'MixedOnceOnlyReactor',
|
|
104
|
+
EventSequenceId: 'event-log'
|
|
105
|
+
})).JobId;
|
|
106
|
+
await eventually(() => invocations.includes('replayable:b') && invocations.filter(_ => _ === 'replayable:b').length === 2);
|
|
107
|
+
await new Promise(resolve => setTimeout(resolve, 3_000));
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
afterAll(() => client?.dispose());
|
|
111
|
+
|
|
112
|
+
it('should run every handler once before the replay', () => {
|
|
113
|
+
invocationsBeforeReplay.sort().should.deep.equal(['live:c', 'once-only:a', 'replayable:b']);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should start the replay', () => {
|
|
117
|
+
isEmptyJobId(jobId).should.be.false;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should run the handler that is not once-only again', () => {
|
|
121
|
+
invocations.filter(_ => _ === 'replayable:b').length.should.equal(2);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should not run the once-only handler again', () => {
|
|
125
|
+
invocations.filter(_ => _ === 'once-only:a').length.should.equal(1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should run neither the live nor the once-only replay handler again', () => {
|
|
129
|
+
invocations.filter(_ => _.endsWith(':c')).sort().should.deep.equal(['live:c']);
|
|
130
|
+
});
|
|
131
|
+
});
|