@cratis/chronicle 6.65.0 → 6.67.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/ArtifactRegistrationResult.ts +31 -0
- package/ChronicleClient.ts +4 -3
- package/ChronicleOptions.ts +76 -24
- package/EventStore.ts +31 -6
- package/IEventStore.ts +7 -0
- package/artifacts/ArtifactRegistrationAttempt.ts +50 -0
- package/connection/ChronicleConnection.auth.spec.ts +3 -3
- package/connection/ChronicleConnection.ts +7 -0
- package/connection/CompatibilityPreflight.ts +22 -4
- package/connection/for_ChronicleConnection/when_checking_compatibility/before_append.spec.ts +12 -1
- package/connection/for_ChronicleConnection/when_creating_clients/with_correlated_multi_host_callers.spec.ts +1 -1
- package/connection/for_ChronicleConnection/when_deferring_client_creation/and_connecting.spec.ts +1 -1
- package/connection/for_CompatibilityPreflight/when_verifying/with_concurrent_calls.spec.ts +2 -2
- package/connection/for_CompatibilityPreflight/when_verifying/with_kernel_versions.spec.ts +38 -0
- package/connection/for_TraceContextMiddleware/when_calling/with_active_context.spec.ts +1 -1
- package/connection/for_TraceContextMiddleware/when_calling/with_grpc_instrumentation.spec.ts +1 -1
- package/dist/ArtifactRegistrationResult.d.ts +35 -0
- package/dist/ArtifactRegistrationResult.d.ts.map +1 -0
- package/dist/ArtifactRegistrationResult.js +4 -0
- package/dist/ArtifactRegistrationResult.js.map +1 -0
- package/dist/ChronicleClient.d.ts.map +1 -1
- package/dist/ChronicleClient.js +4 -3
- package/dist/ChronicleClient.js.map +1 -1
- package/dist/ChronicleOptions.d.ts +22 -0
- package/dist/ChronicleOptions.d.ts.map +1 -1
- package/dist/ChronicleOptions.js +62 -24
- package/dist/ChronicleOptions.js.map +1 -1
- package/dist/EventStore.d.ts +11 -2
- package/dist/EventStore.d.ts.map +1 -1
- package/dist/EventStore.js +29 -6
- package/dist/EventStore.js.map +1 -1
- package/dist/IEventStore.d.ts +6 -0
- package/dist/IEventStore.d.ts.map +1 -1
- package/dist/artifacts/ArtifactRegistrationAttempt.d.ts +20 -0
- package/dist/artifacts/ArtifactRegistrationAttempt.d.ts.map +1 -0
- package/dist/artifacts/ArtifactRegistrationAttempt.js +47 -0
- package/dist/artifacts/ArtifactRegistrationAttempt.js.map +1 -0
- package/dist/connection/ChronicleConnection.d.ts +2 -0
- package/dist/connection/ChronicleConnection.d.ts.map +1 -1
- package/dist/connection/ChronicleConnection.js +6 -0
- package/dist/connection/ChronicleConnection.js.map +1 -1
- package/dist/connection/CompatibilityPreflight.d.ts +5 -0
- package/dist/connection/CompatibilityPreflight.d.ts.map +1 -1
- package/dist/connection/CompatibilityPreflight.js +18 -3
- package/dist/connection/CompatibilityPreflight.js.map +1 -1
- package/dist/eventSequences/EventEnrichmentContext.d.ts +15 -0
- package/dist/eventSequences/EventEnrichmentContext.d.ts.map +1 -0
- package/dist/eventSequences/EventEnrichmentContext.js +4 -0
- package/dist/eventSequences/EventEnrichmentContext.js.map +1 -0
- package/dist/eventSequences/EventEnrichmentProvider.d.ts +10 -0
- package/dist/eventSequences/EventEnrichmentProvider.d.ts.map +1 -0
- package/dist/eventSequences/EventEnrichmentProvider.js +4 -0
- package/dist/eventSequences/EventEnrichmentProvider.js.map +1 -0
- package/dist/eventSequences/EventLog.d.ts +2 -1
- package/dist/eventSequences/EventLog.d.ts.map +1 -1
- package/dist/eventSequences/EventLog.js +2 -2
- package/dist/eventSequences/EventLog.js.map +1 -1
- package/dist/eventSequences/EventSequence.d.ts +7 -1
- package/dist/eventSequences/EventSequence.d.ts.map +1 -1
- package/dist/eventSequences/EventSequence.js +40 -11
- package/dist/eventSequences/EventSequence.js.map +1 -1
- package/dist/eventSequences/IEventSequence.d.ts +2 -0
- package/dist/eventSequences/IEventSequence.d.ts.map +1 -1
- package/dist/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.d.ts +1 -1
- package/dist/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.d.ts.map +1 -1
- package/dist/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.js +3 -3
- package/dist/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.js.map +1 -1
- package/dist/eventSequences/enrichEventContent.d.ts +5 -0
- package/dist/eventSequences/enrichEventContent.d.ts.map +1 -0
- package/dist/eventSequences/enrichEventContent.js +16 -0
- package/dist/eventSequences/enrichEventContent.js.map +1 -0
- package/dist/eventSequences/ensureNamedTagBatchIsSupported.d.ts +2 -2
- package/dist/eventSequences/ensureNamedTagBatchIsSupported.d.ts.map +1 -1
- package/dist/eventSequences/ensureNamedTagBatchIsSupported.js +10 -3
- package/dist/eventSequences/ensureNamedTagBatchIsSupported.js.map +1 -1
- package/dist/eventSequences/index.d.ts +2 -0
- package/dist/eventSequences/index.d.ts.map +1 -1
- package/dist/eventSequences/index.js.map +1 -1
- package/dist/for_EventStore/when_inspecting_registration/given/an_event_store.d.ts +13 -0
- package/dist/for_EventStore/when_inspecting_registration/given/an_event_store.d.ts.map +1 -0
- package/dist/for_EventStore/when_inspecting_registration/given/an_event_store.js +79 -0
- package/dist/for_EventStore/when_inspecting_registration/given/an_event_store.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/projections/Projections.d.ts +2 -1
- package/dist/projections/Projections.d.ts.map +1 -1
- package/dist/projections/Projections.js +7 -4
- package/dist/projections/Projections.js.map +1 -1
- package/dist/projections/registerProjectionWithRetry.d.ts +4 -2
- package/dist/projections/registerProjectionWithRetry.d.ts.map +1 -1
- package/dist/projections/registerProjectionWithRetry.js +8 -4
- package/dist/projections/registerProjectionWithRetry.js.map +1 -1
- package/dist/testing/ReactorScenario.d.ts.map +1 -1
- package/dist/testing/ReactorScenario.js +0 -2
- package/dist/testing/ReactorScenario.js.map +1 -1
- package/dist/transactions/UnitOfWork.d.ts +1 -0
- package/dist/transactions/UnitOfWork.d.ts.map +1 -1
- package/dist/transactions/UnitOfWork.js +17 -11
- package/dist/transactions/UnitOfWork.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eventSequences/EventEnrichmentContext.ts +18 -0
- package/eventSequences/EventEnrichmentProvider.ts +16 -0
- package/eventSequences/EventLog.ts +4 -2
- package/eventSequences/EventSequence.ts +47 -13
- package/eventSequences/IEventSequence.ts +3 -0
- package/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.ts +3 -3
- package/eventSequences/enrichEventContent.ts +22 -0
- package/eventSequences/ensureNamedTagBatchIsSupported.ts +11 -3
- package/eventSequences/for_EventSequence/when_appending_named_tags/given.fixture.ts +3 -2
- package/eventSequences/for_EventSequence/when_appending_named_tags/with_kernel_versions.spec.ts +92 -0
- package/eventSequences/for_EventSequence/when_appending_named_tags/with_registered_sources.spec.ts +28 -22
- package/eventSequences/for_EventSequence/when_enriching_appends/from_client_options.spec.ts +64 -0
- package/eventSequences/for_EventSequence/when_enriching_appends/given.fixture.ts +53 -0
- package/eventSequences/for_EventSequence/when_enriching_appends/with_a_failing_provider.spec.ts +57 -0
- package/eventSequences/for_EventSequence/when_enriching_appends/with_a_pending_provider.spec.ts +58 -0
- package/eventSequences/for_EventSequence/when_enriching_appends/with_providers.spec.ts +66 -0
- package/eventSequences/for_EventSequence/when_enriching_appends/without_providers.spec.ts +25 -0
- package/eventSequences/index.ts +2 -0
- package/for_ChronicleClient/connectTimeout.spec.ts +29 -0
- package/for_ChronicleClient/when_starting_background_work/with_a_correlated_caller.spec.ts +1 -1
- package/for_ChronicleOptions/when_configuring_the_connect_timeout/with_connect_timeout.spec.ts +23 -0
- package/for_EventStore/when_inspecting_registration/given/an_event_store.ts +59 -0
- package/for_EventStore/when_inspecting_registration/with_new_attempts.spec.ts +104 -0
- package/for_EventStore/when_inspecting_registration/with_projection_outcomes.spec.ts +80 -0
- package/for_index/when_importing_connection_helpers.spec.ts +13 -0
- package/index.ts +2 -0
- package/package.json +1 -1
- package/patterns/for_Patterns/when_querying_through_the_connection/after_resetting_the_channel.spec.ts +1 -1
- package/projections/Projections.ts +10 -4
- package/projections/for_registerProjectionWithRetry/when_reporting_outcomes.spec.ts +71 -0
- package/projections/registerProjectionWithRetry.ts +11 -5
- package/testing/ReactorScenario.ts +0 -3
- package/testing/for_ReactorScenario/when_recording_side_effects/with_named_tags.spec.ts +11 -13
- package/transactions/UnitOfWork.ts +18 -14
- package/transactions/for_UnitOfWork/when_committing_events_with_named_tags.spec.ts +87 -29
|
@@ -30,9 +30,10 @@ export function a_sequence(eventSources?: IEventSources) {
|
|
|
30
30
|
const appendManyForEventSources = vi.fn().mockImplementation(batch);
|
|
31
31
|
const appendManyForEventSourcesWithNamedTags = vi.fn().mockImplementation(batch);
|
|
32
32
|
const tailSequenceNumber = vi.fn().mockResolvedValue({ Data: { SequenceNumber: 0n } });
|
|
33
|
-
const
|
|
33
|
+
const getKernelVersion = vi.fn().mockResolvedValue('19.37.4');
|
|
34
|
+
const connection = { getKernelVersion, eventSequences: { append, appendWithNamedTags, appendManyForEventSources, appendManyForEventSourcesWithNamedTags, tailSequenceNumber } } as unknown as ChronicleConnection;
|
|
34
35
|
return {
|
|
35
36
|
sequence: new EventSequence(EventSequenceId.eventLog, 'store', 'tenant', connection, {} as IUnitOfWorkManager, undefined, undefined, eventSources),
|
|
36
|
-
append, appendWithNamedTags, appendManyForEventSources, appendManyForEventSourcesWithNamedTags, tailSequenceNumber
|
|
37
|
+
append, appendWithNamedTags, appendManyForEventSources, appendManyForEventSourcesWithNamedTags, tailSequenceNumber, getKernelVersion
|
|
37
38
|
};
|
|
38
39
|
}
|
package/eventSequences/for_EventSequence/when_appending_named_tags/with_kernel_versions.spec.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
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 { describe, it, beforeEach } from 'vitest';
|
|
5
|
+
import { should } from 'chai';
|
|
6
|
+
import { NamedTag } from '../../../events/index.js';
|
|
7
|
+
import { NamedTagsWithRegisteredEventSourceNotSupported } from '../../NamedTagsWithRegisteredEventSourceNotSupported.js';
|
|
8
|
+
import { Account, a_sequence, NamedTagRecorded, registered_sources } from './given.fixture.js';
|
|
9
|
+
|
|
10
|
+
should();
|
|
11
|
+
|
|
12
|
+
const namedTags = [new NamedTag('tenant', 'alpha')];
|
|
13
|
+
const entry = () => ({ eventSourceId: 'source-1', event: new NamedTagRecorded(), eventSource: Account, namedTags });
|
|
14
|
+
|
|
15
|
+
for (const version of ['19.37.4', '19.37.4-development', '19.38.0', '20.0.0']) {
|
|
16
|
+
describe(`when appending named tags with a registered source on kernel ${version}`, () => {
|
|
17
|
+
let calls: ReturnType<typeof a_sequence>;
|
|
18
|
+
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
calls = a_sequence(registered_sources());
|
|
21
|
+
calls.getKernelVersion.mockResolvedValue(version);
|
|
22
|
+
await calls.sequence.appendMany([entry()]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should send the named-tag batch', () => calls.appendManyForEventSourcesWithNamedTags.mock.calls.should.have.lengthOf(1));
|
|
26
|
+
it('should preserve the registered source', () => calls.appendManyForEventSourcesWithNamedTags.mock.calls[0][0].Events[0].EventSource.should.equal('Account'));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (const version of ['19.37.3', '19.36.99', '1.0.0', undefined, '', 'unknown']) {
|
|
31
|
+
describe(`when appending named tags with a registered source on kernel ${version ?? 'unknown'}`, () => {
|
|
32
|
+
let calls: ReturnType<typeof a_sequence>;
|
|
33
|
+
let error: unknown;
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
calls = a_sequence(registered_sources());
|
|
37
|
+
calls.getKernelVersion.mockResolvedValue(version);
|
|
38
|
+
try {
|
|
39
|
+
await calls.sequence.appendMany([entry()]);
|
|
40
|
+
} catch (caught) {
|
|
41
|
+
error = caught;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should throw the public operation-specific error', () => (error instanceof NamedTagsWithRegisteredEventSourceNotSupported).should.equal(true));
|
|
46
|
+
it('should mention the required kernel', () => (error as Error).message.should.contain('19.37.4'));
|
|
47
|
+
it('should not send the batch', () => calls.appendManyForEventSourcesWithNamedTags.mock.calls.should.have.lengthOf(0));
|
|
48
|
+
it('should not send a legacy batch', () => calls.appendManyForEventSources.mock.calls.should.have.lengthOf(0));
|
|
49
|
+
it('should not read a concurrency tail', () => calls.tailSequenceNumber.mock.calls.should.have.lengthOf(0));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe(`when appending unaffected batches on kernel ${version ?? 'unknown'}`, () => {
|
|
53
|
+
let calls: ReturnType<typeof a_sequence>;
|
|
54
|
+
|
|
55
|
+
beforeEach(async () => {
|
|
56
|
+
calls = a_sequence(registered_sources());
|
|
57
|
+
calls.getKernelVersion.mockResolvedValue(version);
|
|
58
|
+
await calls.sequence.appendMany([{ ...entry(), namedTags: [] }]);
|
|
59
|
+
await calls.sequence.appendMany([{ ...entry(), eventSource: undefined }]);
|
|
60
|
+
await calls.sequence.append('source-1', new NamedTagRecorded(), { eventSource: Account, namedTags });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should send the registered batch without tags', () => calls.appendManyForEventSources.mock.calls.should.have.lengthOf(1));
|
|
64
|
+
it('should send the named-tag batch without a registered source', () => calls.appendManyForEventSourcesWithNamedTags.mock.calls.should.have.lengthOf(1));
|
|
65
|
+
it('should send a single append with both', () => calls.appendWithNamedTags.mock.calls.should.have.lengthOf(1));
|
|
66
|
+
it('should not need the kernel version', () => calls.getKernelVersion.mock.calls.should.have.lengthOf(0));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (const sharedSource of [false, true]) {
|
|
71
|
+
describe(`when appending named tags and a ${sharedSource ? 'shared' : 'separate'} registered source on an older kernel`, () => {
|
|
72
|
+
let calls: ReturnType<typeof a_sequence>;
|
|
73
|
+
let error: unknown;
|
|
74
|
+
|
|
75
|
+
beforeEach(async () => {
|
|
76
|
+
calls = a_sequence(registered_sources());
|
|
77
|
+
calls.getKernelVersion.mockResolvedValue('19.37.3');
|
|
78
|
+
try {
|
|
79
|
+
if (sharedSource) {
|
|
80
|
+
await calls.sequence.appendMany('source-1', [new NamedTagRecorded()], { eventSource: Account, namedTags });
|
|
81
|
+
} else {
|
|
82
|
+
await calls.sequence.appendMany([{ ...entry(), eventSource: undefined }, { ...entry(), namedTags: [] }]);
|
|
83
|
+
}
|
|
84
|
+
} catch (caught) {
|
|
85
|
+
error = caught;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should reject the combination', () => (error instanceof NamedTagsWithRegisteredEventSourceNotSupported).should.equal(true));
|
|
90
|
+
it('should not send', () => calls.appendManyForEventSourcesWithNamedTags.mock.calls.should.have.lengthOf(0));
|
|
91
|
+
});
|
|
92
|
+
}
|
package/eventSequences/for_EventSequence/when_appending_named_tags/with_registered_sources.spec.ts
CHANGED
|
@@ -4,50 +4,56 @@
|
|
|
4
4
|
import { beforeEach, chai, describe, it } from 'vitest';
|
|
5
5
|
import { ConcurrencyDimensions } from '../../../eventSources/index.js';
|
|
6
6
|
import { NamedTag } from '../../../events/index.js';
|
|
7
|
-
import {
|
|
7
|
+
import type { AppendOptions, EventForEventSourceId } from '../../index.js';
|
|
8
8
|
import { Account, a_sequence, NamedTagRecorded, registered_sources } from './given.fixture.js';
|
|
9
9
|
|
|
10
10
|
chai.should();
|
|
11
11
|
const namedTags = [new NamedTag('batch', 'b-1')];
|
|
12
|
+
const tagged = [{ Name: 'batch', Value: 'b-1' }];
|
|
12
13
|
const entry = (options: Partial<EventForEventSourceId> = {}): EventForEventSourceId =>
|
|
13
14
|
({ eventSourceId: 'source', event: new NamedTagRecorded(), ...options });
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{ description: '
|
|
20
|
-
{ description: '
|
|
16
|
+
type WireEvent = { EventSource: string; EventSourceType: string; NamedTags: Array<{ Name: string; Value: string }> };
|
|
17
|
+
type Batch = { description: string; events: EventForEventSourceId[]; options?: AppendOptions; registered: boolean[]; tags: Array<typeof tagged> };
|
|
18
|
+
|
|
19
|
+
const batches: Batch[] = [
|
|
20
|
+
{ description: 'tags and a registered source on the same entry', events: [entry({ eventSource: Account, namedTags })], registered: [true], tags: [tagged] },
|
|
21
|
+
{ description: 'a tagged entry before an untagged registered entry', events: [entry({ namedTags }), entry({ eventSource: 'Account' })], registered: [false, true], tags: [tagged, []] },
|
|
22
|
+
{ description: 'an untagged registered entry before a tagged entry', events: [entry({ eventSource: 'Account' }), entry({ namedTags })], registered: [true, false], tags: [[], tagged] },
|
|
23
|
+
{ description: 'shared tags and a registered entry', events: [entry({ eventSource: 'Account' })], options: { namedTags }, registered: [true], tags: [tagged] },
|
|
24
|
+
{ description: 'per-entry tags and a shared registered source', events: [entry({ namedTags })], options: { eventSource: Account }, registered: [true], tags: [tagged] }
|
|
21
25
|
];
|
|
22
26
|
|
|
23
27
|
for (const batch of batches) {
|
|
24
28
|
describe(`when appending a batch with ${batch.description}`, () => {
|
|
25
29
|
let calls: ReturnType<typeof a_sequence>;
|
|
26
|
-
let
|
|
30
|
+
let wireEvents: WireEvent[];
|
|
27
31
|
beforeEach(async () => {
|
|
28
32
|
calls = a_sequence(registered_sources(ConcurrencyDimensions.eventSourceId));
|
|
29
|
-
|
|
33
|
+
await calls.sequence.appendMany(batch.events, batch.options);
|
|
34
|
+
wireEvents = calls.appendManyForEventSourcesWithNamedTags.mock.calls[0][0].Events;
|
|
30
35
|
});
|
|
31
|
-
it('should
|
|
32
|
-
(error as Error).should.be.instanceOf(NamedTagsWithRegisteredEventSourceNotSupported));
|
|
33
|
-
it('should explain the kernel limitation', () => (error as Error).message.should.contain('drops registered event source routing'));
|
|
34
|
-
it('should link to the kernel issue', () => (error as Error).message.should.contain('https://github.com/Cratis/Chronicle/issues/4603'));
|
|
36
|
+
it('should send one named-tag batch', () => calls.appendManyForEventSourcesWithNamedTags.mock.calls.should.have.lengthOf(1));
|
|
35
37
|
it('should not send a plain batch', () => calls.appendManyForEventSources.mock.calls.should.have.lengthOf(0));
|
|
36
|
-
it('should
|
|
37
|
-
|
|
38
|
-
it('should
|
|
39
|
-
|
|
38
|
+
it('should keep the registered event source on every registered event', () =>
|
|
39
|
+
wireEvents.map(wireEvent => wireEvent.EventSource === 'Account').should.deep.equal(batch.registered));
|
|
40
|
+
it('should keep the registered event source type on every registered event', () =>
|
|
41
|
+
wireEvents.filter((_, index) => batch.registered[index]).every(wireEvent => wireEvent.EventSourceType === 'Account').should.be.true);
|
|
42
|
+
it('should carry the named tags of each event', () => wireEvents.map(wireEvent => wireEvent.NamedTags).should.deep.equal(batch.tags));
|
|
40
43
|
});
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
describe('when appending a same-source batch with shared named tags and registered routing', () => {
|
|
44
|
-
let
|
|
47
|
+
let calls: ReturnType<typeof a_sequence>;
|
|
48
|
+
let wireEvents: WireEvent[];
|
|
45
49
|
beforeEach(async () => {
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
calls = a_sequence(registered_sources());
|
|
51
|
+
await calls.sequence.appendMany('source', [new NamedTagRecorded(), new NamedTagRecorded()], { eventSource: Account, namedTags });
|
|
52
|
+
wireEvents = calls.appendManyForEventSourcesWithNamedTags.mock.calls[0][0].Events;
|
|
48
53
|
});
|
|
49
|
-
it('should
|
|
50
|
-
(
|
|
54
|
+
it('should keep the registered event source on every event', () =>
|
|
55
|
+
wireEvents.map(wireEvent => wireEvent.EventSource).should.deep.equal(['Account', 'Account']));
|
|
56
|
+
it('should carry the shared named tags on every event', () => wireEvents.map(wireEvent => wireEvent.NamedTags).should.deep.equal([tagged, tagged]));
|
|
51
57
|
});
|
|
52
58
|
|
|
53
59
|
describe('when appending a registered-source batch with empty named tags', () => {
|
|
@@ -0,0 +1,64 @@
|
|
|
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 { afterEach, beforeEach, chai, describe, it, vi } from 'vitest';
|
|
5
|
+
import { ChronicleClient, ChronicleOptions, EventSequenceId, type EventEnrichmentProvider } from '../../../index.js';
|
|
6
|
+
import { EnrichedEvent } from './given.fixture.js';
|
|
7
|
+
|
|
8
|
+
chai.should();
|
|
9
|
+
const transport = vi.hoisted(() => ({
|
|
10
|
+
register: vi.fn().mockResolvedValue({}),
|
|
11
|
+
append: vi.fn().mockResolvedValue({ Response: { SequenceNumber: 0n, ConstraintViolations: [], Errors: [] } })
|
|
12
|
+
}));
|
|
13
|
+
vi.mock('../../../connection/ChronicleConnection.js', () => ({
|
|
14
|
+
ChronicleConnection: class {
|
|
15
|
+
async resetChannel() {}
|
|
16
|
+
async connect() {}
|
|
17
|
+
async disconnect() {}
|
|
18
|
+
server = { getVersionInfo: transport.register };
|
|
19
|
+
eventStores = { ensureEventStore: transport.register };
|
|
20
|
+
eventTypes = { register: transport.register };
|
|
21
|
+
eventSources = { register: transport.register };
|
|
22
|
+
constraints = { register: transport.register };
|
|
23
|
+
projections = { register: transport.register };
|
|
24
|
+
readModels = { registerMany: transport.register };
|
|
25
|
+
webhooks = { register: transport.register };
|
|
26
|
+
eventSeeding = { seed: transport.register };
|
|
27
|
+
eventSequences = { append: transport.append };
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
for (const factory of [true, false]) {
|
|
32
|
+
describe(`when configuring enrichment through the ${factory ? 'options factory' : 'options constructor'}`, () => {
|
|
33
|
+
let client: ChronicleClient;
|
|
34
|
+
beforeEach(async () => {
|
|
35
|
+
vi.clearAllMocks();
|
|
36
|
+
const providers: EventEnrichmentProvider[] = [content => { content.configured = true; }];
|
|
37
|
+
const base = ChronicleOptions.fromConnectionString('chronicle://localhost:35000', {
|
|
38
|
+
skipKeepAlive: true, discoveryPatterns: [], eventEnrichmentProviders: providers,
|
|
39
|
+
clientArtifactsProvider: {
|
|
40
|
+
eventTypes: [], readModels: [], reactors: [], reducers: [], seeders: [],
|
|
41
|
+
constraints: [], projections: [], webhooks: [], eventTypeMigrations: [], globalForHandlers: []
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const options = factory ? base : new ChronicleOptions({
|
|
45
|
+
connectionString: base.connectionString, skipKeepAlive: true, discoveryPatterns: [],
|
|
46
|
+
clientArtifactsProvider: base.clientArtifactsProvider, eventEnrichmentProviders: providers
|
|
47
|
+
});
|
|
48
|
+
// Registration order belongs to the options, not the caller's mutable array.
|
|
49
|
+
providers.reverse();
|
|
50
|
+
providers.push(() => { throw new Error('must not be installed after configuration'); });
|
|
51
|
+
client = new ChronicleClient(options);
|
|
52
|
+
const store = await client.getEventStore('store', 'tenant');
|
|
53
|
+
await store.eventLog.append('source', new EnrichedEvent());
|
|
54
|
+
await store.getEventSequence(new EventSequenceId('custom')).append('source', new EnrichedEvent());
|
|
55
|
+
});
|
|
56
|
+
afterEach(() => client?.dispose());
|
|
57
|
+
it('should enrich the event log and subsequently created event sequences', () => {
|
|
58
|
+
transport.append.mock.calls.map(([request]) => JSON.parse(request.Content).configured).should.deep.equal([true, true]);
|
|
59
|
+
});
|
|
60
|
+
it('should retain each sequence identity', () => {
|
|
61
|
+
transport.append.mock.calls.map(([request]) => request.EventSequenceId).should.deep.equal(['event-log', 'custom']);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { vi } from 'vitest';
|
|
5
|
+
import { EventSequence, EventSequenceId, type EventEnrichmentProvider } from '../../index.js';
|
|
6
|
+
import { eventType, NamedTag } from '../../../events/index.js';
|
|
7
|
+
import type { ChronicleConnection } from '../../../connection/index.js';
|
|
8
|
+
import type { IUnitOfWorkManager } from '../../../transactions/index.js';
|
|
9
|
+
|
|
10
|
+
export class EnrichedEvent {
|
|
11
|
+
readonly removable = true;
|
|
12
|
+
readonly recordedAt = new Date('2026-01-01T00:00:00.000Z');
|
|
13
|
+
constructor(readonly value = 'original', readonly nested = { value: 'original' }) {}
|
|
14
|
+
}
|
|
15
|
+
eventType('enrichment-event')(EnrichedEvent);
|
|
16
|
+
|
|
17
|
+
export enum AppendMode { single, namedSingle, batch, batchForOneSource, namedBatch }
|
|
18
|
+
export const modes = [AppendMode.single, AppendMode.namedSingle, AppendMode.batch, AppendMode.batchForOneSource, AppendMode.namedBatch];
|
|
19
|
+
|
|
20
|
+
export function a_sequence(providers: readonly EventEnrichmentProvider[] = []) {
|
|
21
|
+
const single = { Response: { SequenceNumber: 0n, ConstraintViolations: [], Errors: [] } };
|
|
22
|
+
const batch = async (request: { Events: unknown[] }) =>
|
|
23
|
+
({ Response: { SequenceNumbers: request.Events.map((_, index) => BigInt(index)), ConstraintViolations: [], Errors: [] } });
|
|
24
|
+
const append = vi.fn().mockResolvedValue(single);
|
|
25
|
+
const appendWithNamedTags = vi.fn().mockResolvedValue(single);
|
|
26
|
+
const appendManyForEventSources = vi.fn().mockImplementation(batch);
|
|
27
|
+
const appendManyForEventSourcesWithNamedTags = vi.fn().mockImplementation(batch);
|
|
28
|
+
const connection = { eventSequences: { append, appendWithNamedTags, appendManyForEventSources, appendManyForEventSourcesWithNamedTags } } as unknown as ChronicleConnection;
|
|
29
|
+
return {
|
|
30
|
+
sequence: new EventSequence(EventSequenceId.eventLog, 'store', 'tenant', connection, {} as IUnitOfWorkManager, undefined, undefined, undefined, providers),
|
|
31
|
+
calls: [append, appendWithNamedTags, appendManyForEventSources, appendManyForEventSourcesWithNamedTags]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const correlationId = '00000000-0000-0000-0000-000000000211';
|
|
36
|
+
|
|
37
|
+
export async function append_events(sequence: EventSequence, mode: AppendMode, events = [new EnrichedEvent()]) {
|
|
38
|
+
const options = { correlationId, tags: ['kept'], streamType: 'orders', streamId: 'stream' };
|
|
39
|
+
const namedOptions = { ...options, namedTags: [new NamedTag('tenant', 'one')] };
|
|
40
|
+
switch (mode) {
|
|
41
|
+
case AppendMode.single: return sequence.append('source', events[0], options);
|
|
42
|
+
case AppendMode.namedSingle: return sequence.append('source', events[0], namedOptions);
|
|
43
|
+
case AppendMode.batch: return sequence.appendMany(events.map(event => ({ eventSourceId: 'source', event })), options);
|
|
44
|
+
case AppendMode.batchForOneSource: return sequence.appendMany('source', events, options);
|
|
45
|
+
case AppendMode.namedBatch: return sequence.appendMany(events.map(event => ({ eventSourceId: 'source', event })), namedOptions);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function transmitted(calls: ReturnType<typeof a_sequence>['calls']) {
|
|
50
|
+
const request = calls.flatMap(call => call.mock.calls)[0][0];
|
|
51
|
+
const events: { Content: string; Tags: string[]; EventSourceId: string; EventType: { Id: string }; EventStreamId: string }[] = request.Events ?? [request];
|
|
52
|
+
return { request, events, contents: events.map(event => JSON.parse(event.Content) as Record<string, unknown>) };
|
|
53
|
+
}
|
package/eventSequences/for_EventSequence/when_enriching_appends/with_a_failing_provider.spec.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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 { beforeEach, chai, describe, it, vi } from 'vitest';
|
|
5
|
+
import { a_sequence, append_events, AppendMode, EnrichedEvent, modes } from './given.fixture.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
for (const mode of modes) {
|
|
10
|
+
for (const asynchronous of [false, true]) {
|
|
11
|
+
describe(`when a provider ${asynchronous ? 'rejects' : 'throws'} during ${AppendMode[mode]}`, () => {
|
|
12
|
+
let calls: ReturnType<typeof a_sequence>['calls'];
|
|
13
|
+
let result: PromiseSettledResult<unknown>;
|
|
14
|
+
let failure: Error;
|
|
15
|
+
let later: ReturnType<typeof vi.fn>;
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
failure = new Error('enrichment failed');
|
|
18
|
+
later = vi.fn();
|
|
19
|
+
const fixture = a_sequence([
|
|
20
|
+
content => { content.enriched = true; },
|
|
21
|
+
() => { if (asynchronous) return Promise.reject(failure); throw failure; },
|
|
22
|
+
later
|
|
23
|
+
]);
|
|
24
|
+
calls = fixture.calls;
|
|
25
|
+
[result] = await Promise.allSettled([append_events(fixture.sequence, mode)]);
|
|
26
|
+
});
|
|
27
|
+
it('should surface the original provider failure', () => {
|
|
28
|
+
result.status.should.equal('rejected');
|
|
29
|
+
if (result.status === 'rejected') result.reason.should.equal(failure);
|
|
30
|
+
});
|
|
31
|
+
it('should transmit nothing', () => calls.flatMap(call => call.mock.calls).should.have.lengthOf(0));
|
|
32
|
+
it('should not invoke later providers', () => later.mock.calls.should.have.lengthOf(0));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('when enrichment rejects on a later batch event', () => {
|
|
38
|
+
let calls: ReturnType<typeof a_sequence>['calls'];
|
|
39
|
+
let visited: string[];
|
|
40
|
+
let result: PromiseSettledResult<unknown>;
|
|
41
|
+
beforeEach(async () => {
|
|
42
|
+
visited = [];
|
|
43
|
+
const fixture = a_sequence([async content => {
|
|
44
|
+
visited.push(String(content.value));
|
|
45
|
+
await Promise.resolve();
|
|
46
|
+
if (content.value === 'two') throw new Error('second event failed');
|
|
47
|
+
content.enriched = true;
|
|
48
|
+
}]);
|
|
49
|
+
calls = fixture.calls;
|
|
50
|
+
[result] = await Promise.allSettled([append_events(fixture.sequence, AppendMode.batch, [
|
|
51
|
+
new EnrichedEvent('one'), new EnrichedEvent('two'), new EnrichedEvent('three')
|
|
52
|
+
])]);
|
|
53
|
+
});
|
|
54
|
+
it('should have enriched the first event before the failure', () => visited.should.deep.equal(['one', 'two']));
|
|
55
|
+
it('should reject the entire append', () => result.status.should.equal('rejected'));
|
|
56
|
+
it('should not transmit even the successfully enriched event', () => calls.flatMap(call => call.mock.calls).should.have.lengthOf(0));
|
|
57
|
+
});
|
package/eventSequences/for_EventSequence/when_enriching_appends/with_a_pending_provider.spec.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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 { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { a_sequence, append_events, AppendMode, EnrichedEvent, modes, transmitted } from './given.fixture.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
for (const mode of modes) {
|
|
10
|
+
describe(`when a provider is pending during ${AppendMode[mode]}`, () => {
|
|
11
|
+
let calls: ReturnType<typeof a_sequence>['calls'];
|
|
12
|
+
let pending: Promise<unknown>;
|
|
13
|
+
let release: () => void;
|
|
14
|
+
let order: string[];
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
order = [];
|
|
17
|
+
let started!: () => void;
|
|
18
|
+
const entered = new Promise<void>(resolve => { started = resolve; });
|
|
19
|
+
const gate = new Promise<void>(resolve => { release = resolve; });
|
|
20
|
+
const fixture = a_sequence([
|
|
21
|
+
async content => { started(); await gate; content.ready = true; order.push('first'); },
|
|
22
|
+
() => { order.push('second'); }
|
|
23
|
+
]);
|
|
24
|
+
calls = fixture.calls;
|
|
25
|
+
pending = append_events(fixture.sequence, mode);
|
|
26
|
+
await entered;
|
|
27
|
+
});
|
|
28
|
+
it('should not send a request or invoke the next provider until completion', async () => {
|
|
29
|
+
try {
|
|
30
|
+
calls.flatMap(call => call.mock.calls).should.have.lengthOf(0);
|
|
31
|
+
order.should.have.lengthOf(0);
|
|
32
|
+
} finally { release(); await pending; }
|
|
33
|
+
});
|
|
34
|
+
it('should send enriched content only after completion', async () => {
|
|
35
|
+
release();
|
|
36
|
+
await pending;
|
|
37
|
+
transmitted(calls).contents[0].ready.should.equal(true);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('when enriching multiple batch events', () => {
|
|
43
|
+
let calls: ReturnType<typeof a_sequence>['calls'];
|
|
44
|
+
let order: string[];
|
|
45
|
+
beforeEach(async () => {
|
|
46
|
+
order = [];
|
|
47
|
+
const fixture = a_sequence([
|
|
48
|
+
async content => { await Promise.resolve(); order.push(`first ${content.value}`); content.enriched = true; },
|
|
49
|
+
content => { order.push(`second ${content.value}`); }
|
|
50
|
+
]);
|
|
51
|
+
calls = fixture.calls;
|
|
52
|
+
await append_events(fixture.sequence, AppendMode.batch, [new EnrichedEvent('one'), new EnrichedEvent('two')]);
|
|
53
|
+
});
|
|
54
|
+
it('should run every provider in order for each event in input order', () => order.should.deep.equal([
|
|
55
|
+
'first one', 'second one', 'first two', 'second two'
|
|
56
|
+
]));
|
|
57
|
+
it('should send all enriched events together', () => transmitted(calls).contents.map(content => content.enriched).should.deep.equal([true, true]));
|
|
58
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { EventSequenceId, type EventEnrichmentContext, type EventEnrichmentProvider } from '../../index.js';
|
|
6
|
+
import { a_sequence, append_events, AppendMode, correlationId, EnrichedEvent, modes, transmitted } from './given.fixture.js';
|
|
7
|
+
|
|
8
|
+
chai.should();
|
|
9
|
+
|
|
10
|
+
for (const mode of modes) {
|
|
11
|
+
describe(`when enriching ${AppendMode[mode]} after serialization`, () => {
|
|
12
|
+
let calls: ReturnType<typeof a_sequence>['calls'];
|
|
13
|
+
let event: EnrichedEvent;
|
|
14
|
+
let contexts: EventEnrichmentContext[];
|
|
15
|
+
let observed: Record<string, unknown>[];
|
|
16
|
+
let order: string[];
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
event = new EnrichedEvent();
|
|
19
|
+
contexts = [];
|
|
20
|
+
observed = [];
|
|
21
|
+
order = [];
|
|
22
|
+
const first: EventEnrichmentProvider = async (content, context) => {
|
|
23
|
+
observed.push(structuredClone(content));
|
|
24
|
+
contexts.push(context);
|
|
25
|
+
order.push('first started');
|
|
26
|
+
await Promise.resolve();
|
|
27
|
+
content.added = 'from first';
|
|
28
|
+
(content.nested as Record<string, unknown>).value = 'changed';
|
|
29
|
+
delete content.removable;
|
|
30
|
+
order.push('first finished');
|
|
31
|
+
};
|
|
32
|
+
const second: EventEnrichmentProvider = content => {
|
|
33
|
+
order.push('second');
|
|
34
|
+
content.value = content.added;
|
|
35
|
+
};
|
|
36
|
+
const fixture = a_sequence([first, second]);
|
|
37
|
+
calls = fixture.calls;
|
|
38
|
+
await append_events(fixture.sequence, mode, [event]);
|
|
39
|
+
});
|
|
40
|
+
it('should await providers in configured order', () => order.should.deep.equal(['first started', 'first finished', 'second']));
|
|
41
|
+
it('should provide the serialized object rather than the event instance', () => observed.should.deep.equal([
|
|
42
|
+
{ value: 'original', nested: { value: 'original' }, recordedAt: '2026-01-01T00:00:00.000Z', removable: true }
|
|
43
|
+
]));
|
|
44
|
+
it('should transmit additions replacements deletions and nested mutations', () => transmitted(calls).contents.should.deep.equal([
|
|
45
|
+
{ value: 'from first', nested: { value: 'changed' }, recordedAt: '2026-01-01T00:00:00.000Z', added: 'from first' }
|
|
46
|
+
]));
|
|
47
|
+
it('should leave the original event unchanged', () => event.should.deep.equal(new EnrichedEvent()));
|
|
48
|
+
it('should provide event and append context without a wire request', () => {
|
|
49
|
+
const context = contexts[0];
|
|
50
|
+
context.event.should.equal(event);
|
|
51
|
+
context.eventType.id.value.should.equal('enrichment-event');
|
|
52
|
+
context.eventStore.should.equal('store');
|
|
53
|
+
context.namespace.should.equal('tenant');
|
|
54
|
+
context.eventSequenceId.should.equal(EventSequenceId.eventLog);
|
|
55
|
+
context.eventSourceId.should.equal('source');
|
|
56
|
+
context.correlationId.toString().should.equal(correlationId);
|
|
57
|
+
});
|
|
58
|
+
it('should preserve append metadata', () => {
|
|
59
|
+
const { events } = transmitted(calls);
|
|
60
|
+
events[0].Tags.should.deep.equal(['kept']);
|
|
61
|
+
events[0].EventSourceId.should.equal('source');
|
|
62
|
+
events[0].EventType.Id.should.equal('enrichment-event');
|
|
63
|
+
events[0].EventStreamId.should.equal('stream');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { JsonSerializer } from '@cratis/fundamentals';
|
|
6
|
+
import { a_sequence, append_events, AppendMode, EnrichedEvent, modes, transmitted } from './given.fixture.js';
|
|
7
|
+
|
|
8
|
+
chai.should();
|
|
9
|
+
|
|
10
|
+
for (const mode of modes) {
|
|
11
|
+
describe(`when appending ${AppendMode[mode]} without enrichment providers`, () => {
|
|
12
|
+
let calls: ReturnType<typeof a_sequence>['calls'];
|
|
13
|
+
let event: EnrichedEvent;
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
event = new EnrichedEvent();
|
|
16
|
+
const fixture = a_sequence();
|
|
17
|
+
calls = fixture.calls;
|
|
18
|
+
await append_events(fixture.sequence, mode, [event]);
|
|
19
|
+
});
|
|
20
|
+
it('should preserve serialized content unchanged', () => {
|
|
21
|
+
transmitted(calls).events[0].Content.should.equal(JsonSerializer.serialize(event));
|
|
22
|
+
});
|
|
23
|
+
it('should transmit exactly one request', () => calls.flatMap(call => call.mock.calls).should.have.lengthOf(1));
|
|
24
|
+
});
|
|
25
|
+
}
|
package/eventSequences/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type { ConstraintViolation } from './ConstraintViolation.js';
|
|
|
9
9
|
export type { AppendResult } from './AppendResult.js';
|
|
10
10
|
export type { AppendedEventWithResult } from './AppendedEventWithResult.js';
|
|
11
11
|
export type { AppendOptions } from './AppendOptions.js';
|
|
12
|
+
export type { EventEnrichmentProvider } from './EventEnrichmentProvider.js';
|
|
13
|
+
export type { EventEnrichmentContext } from './EventEnrichmentContext.js';
|
|
12
14
|
export type { CompensateOptions } from './CompensateOptions.js';
|
|
13
15
|
export { CompleteStreamError } from './CompleteStreamError.js';
|
|
14
16
|
export { NamedTagsWithRegisteredEventSourceNotSupported } from './NamedTagsWithRegisteredEventSourceNotSupported.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { ChronicleClient } from '../ChronicleClient.js';
|
|
6
|
+
import { ChronicleOptions } from '../ChronicleOptions.js';
|
|
7
|
+
|
|
8
|
+
const connections = vi.hoisted(() => [] as Record<string, unknown>[]);
|
|
9
|
+
vi.mock('../connection/ChronicleConnection.js', () => ({
|
|
10
|
+
ChronicleConnection: class {
|
|
11
|
+
constructor(options: Record<string, unknown>) { connections.push(options); }
|
|
12
|
+
disconnect() {}
|
|
13
|
+
}
|
|
14
|
+
}));
|
|
15
|
+
vi.mock('../connection/KernelKeepAlive.js', () => ({ KernelKeepAlive: class { async start() {} } }));
|
|
16
|
+
|
|
17
|
+
describe('when creating a client with a connect timeout', () => {
|
|
18
|
+
it('should give the connection the default connect timeout', () => {
|
|
19
|
+
const client = new ChronicleClient(ChronicleOptions.fromConnectionString('chronicle://localhost:35000', { discoveryPatterns: [] }));
|
|
20
|
+
client.dispose();
|
|
21
|
+
expect(connections.at(-1)?.connectTimeout).toBe(10_000);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should give the connection the configured connect timeout', () => {
|
|
25
|
+
const client = new ChronicleClient(ChronicleOptions.fromConnectionString('chronicle://localhost:35000', { discoveryPatterns: [], connectTimeout: 1_234 }));
|
|
26
|
+
client.dispose();
|
|
27
|
+
expect(connections.at(-1)?.connectTimeout).toBe(1_234);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -60,7 +60,7 @@ beforeEach(async () => {
|
|
|
60
60
|
let connections = 0;
|
|
61
61
|
server.add(ConnectionServiceDefinition, {
|
|
62
62
|
...Object.fromEntries(Object.keys(ConnectionServiceDefinition.methods).map(name => [name, unused])),
|
|
63
|
-
checkCompatibility: async () => ({ IsCompatible: true, Incompatibilities: [], ServerVersion: '
|
|
63
|
+
checkCompatibility: async () => ({ IsCompatible: true, Incompatibilities: [], ServerVersion: '19.37.4' }),
|
|
64
64
|
connectionKeepAlive: async () => ({}),
|
|
65
65
|
connect: async function* (request, callContext) {
|
|
66
66
|
const first = ++connections === 1;
|
package/for_ChronicleOptions/when_configuring_the_connect_timeout/with_connect_timeout.spec.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 { chai, describe, it } from 'vitest';
|
|
5
|
+
import { ChronicleOptions } from '../../ChronicleOptions.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when configuring the connect timeout', () => {
|
|
10
|
+
it('should wait 10 seconds by default', () =>
|
|
11
|
+
ChronicleOptions.fromConnectionString('chronicle://localhost:35000').connectTimeout.should.equal(10_000));
|
|
12
|
+
|
|
13
|
+
it('should use the configured timeout', () =>
|
|
14
|
+
ChronicleOptions.development({ connectTimeout: 2_500 }).connectTimeout.should.equal(2_500));
|
|
15
|
+
|
|
16
|
+
it('should accept the largest supported timeout', () =>
|
|
17
|
+
ChronicleOptions.development({ connectTimeout: 4_294_967_295 }).connectTimeout.should.equal(4_294_967_295));
|
|
18
|
+
|
|
19
|
+
for (const connectTimeout of [0, -1, 0.5, 4_294_967_296, Number.NaN, Number.POSITIVE_INFINITY]) {
|
|
20
|
+
it(`should reject ${connectTimeout}`, () =>
|
|
21
|
+
(() => ChronicleOptions.development({ connectTimeout })).should.throw(TypeError, 'connectTimeout'));
|
|
22
|
+
}
|
|
23
|
+
});
|