@cratis/chronicle 6.53.1 → 6.55.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/ChronicleClient.ts +16 -3
- package/ChronicleOptions.ts +11 -0
- package/EventStore.ts +8 -3
- package/README.md +1 -1
- package/artifacts/refuseClientHostedObservers.ts +16 -0
- package/connection/ChronicleConnection.ts +58 -9
- package/connection/ChronicleConnectionString.ts +26 -1
- package/connection/ClientObserversRequireKeepAlive.ts +10 -0
- package/connection/for_ChronicleConnection/when_deferring_client_creation/and_connecting.spec.ts +83 -0
- package/connection/for_ChronicleConnection/when_warning_about_tls_validation/tls_validation_warning.spec.ts +80 -0
- package/dist/ChronicleClient.d.ts +1 -0
- package/dist/ChronicleClient.d.ts.map +1 -1
- package/dist/ChronicleClient.js +16 -3
- package/dist/ChronicleClient.js.map +1 -1
- package/dist/ChronicleOptions.d.ts +4 -0
- package/dist/ChronicleOptions.d.ts.map +1 -1
- package/dist/ChronicleOptions.js +7 -0
- package/dist/ChronicleOptions.js.map +1 -1
- package/dist/EventStore.d.ts +2 -1
- package/dist/EventStore.d.ts.map +1 -1
- package/dist/EventStore.js +10 -3
- package/dist/EventStore.js.map +1 -1
- package/dist/artifacts/refuseClientHostedObservers.d.ts +4 -0
- package/dist/artifacts/refuseClientHostedObservers.d.ts.map +1 -0
- package/dist/artifacts/refuseClientHostedObservers.js +15 -0
- package/dist/artifacts/refuseClientHostedObservers.js.map +1 -0
- package/dist/connection/ChronicleConnection.d.ts +9 -1
- package/dist/connection/ChronicleConnection.d.ts.map +1 -1
- package/dist/connection/ChronicleConnection.js +46 -8
- package/dist/connection/ChronicleConnection.js.map +1 -1
- package/dist/connection/ChronicleConnectionString.d.ts +8 -0
- package/dist/connection/ChronicleConnectionString.d.ts.map +1 -1
- package/dist/connection/ChronicleConnectionString.js +21 -1
- package/dist/connection/ChronicleConnectionString.js.map +1 -1
- package/dist/connection/ClientObserversRequireKeepAlive.d.ts +7 -0
- package/dist/connection/ClientObserversRequireKeepAlive.d.ts.map +1 -0
- package/dist/connection/ClientObserversRequireKeepAlive.js +14 -0
- package/dist/connection/ClientObserversRequireKeepAlive.js.map +1 -0
- package/dist/eventSequences/ITransactionalEventSequence.d.ts +6 -0
- package/dist/eventSequences/ITransactionalEventSequence.d.ts.map +1 -1
- package/dist/eventSequences/TransactionalEventSequence.d.ts.map +1 -1
- package/dist/eventSequences/TransactionalEventSequence.js +3 -1
- package/dist/eventSequences/TransactionalEventSequence.js.map +1 -1
- package/dist/for_ChronicleClient/when_skipping_keep_alive/native-exit-probe.d.ts +2 -0
- package/dist/for_ChronicleClient/when_skipping_keep_alive/native-exit-probe.d.ts.map +1 -0
- package/dist/for_ChronicleClient/when_skipping_keep_alive/native-exit-probe.js +107 -0
- package/dist/for_ChronicleClient/when_skipping_keep_alive/native-exit-probe.js.map +1 -0
- 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/dist/reactors/Reactors.d.ts +2 -1
- package/dist/reactors/Reactors.d.ts.map +1 -1
- package/dist/reactors/Reactors.js +6 -1
- package/dist/reactors/Reactors.js.map +1 -1
- package/dist/reducers/Reducers.d.ts +2 -1
- package/dist/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +6 -1
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/transactions/AppendOptionNotSupportedInUnitOfWork.d.ts +13 -0
- package/dist/transactions/AppendOptionNotSupportedInUnitOfWork.d.ts.map +1 -0
- package/dist/transactions/AppendOptionNotSupportedInUnitOfWork.js +19 -0
- package/dist/transactions/AppendOptionNotSupportedInUnitOfWork.js.map +1 -0
- package/dist/transactions/ConflictingAppendOptionNamesInUnitOfWork.d.ts +14 -0
- package/dist/transactions/ConflictingAppendOptionNamesInUnitOfWork.d.ts.map +1 -0
- package/dist/transactions/ConflictingAppendOptionNamesInUnitOfWork.js +21 -0
- package/dist/transactions/ConflictingAppendOptionNamesInUnitOfWork.js.map +1 -0
- package/dist/transactions/IUnitOfWork.d.ts +3 -0
- package/dist/transactions/IUnitOfWork.d.ts.map +1 -1
- package/dist/transactions/TransactionalAppendOptions.d.ts +8 -0
- package/dist/transactions/TransactionalAppendOptions.d.ts.map +1 -1
- package/dist/transactions/UnitOfWork.d.ts.map +1 -1
- package/dist/transactions/UnitOfWork.js +4 -2
- package/dist/transactions/UnitOfWork.js.map +1 -1
- package/dist/transactions/concurrencyScopesAreEqual.d.ts.map +1 -1
- package/dist/transactions/concurrencyScopesAreEqual.js +4 -3
- package/dist/transactions/concurrencyScopesAreEqual.js.map +1 -1
- package/dist/transactions/index.d.ts +2 -0
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/index.js +2 -0
- package/dist/transactions/index.js.map +1 -1
- package/dist/transactions/resolveTransactionalAppendOptions.d.ts +8 -0
- package/dist/transactions/resolveTransactionalAppendOptions.d.ts.map +1 -0
- package/dist/transactions/resolveTransactionalAppendOptions.js +58 -0
- package/dist/transactions/resolveTransactionalAppendOptions.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eventSequences/ITransactionalEventSequence.ts +6 -0
- package/eventSequences/TransactionalEventSequence.ts +3 -1
- package/eventSequences/for_TransactionalEventSequence/when_appending_many_with_append_option_names.spec.ts +26 -0
- package/eventSequences/for_TransactionalEventSequence/when_appending_many_with_unsupported_options.spec.ts +35 -0
- package/for_ChronicleClient/against_a_kernel/when_skipping_keep_alive.integration.spec.ts +80 -0
- package/for_ChronicleClient/when_skipping_keep_alive/and_connecting.spec.ts +158 -0
- package/for_ChronicleClient/when_skipping_keep_alive/native-exit-probe.ts +84 -0
- package/for_ChronicleOptions/when_configuring_keep_alive/with_skip_keep_alive.spec.ts +35 -0
- package/for_EventStore/when_skipping_keep_alive/when_registering_artifacts.spec.ts +51 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/reactors/Reactors.ts +4 -1
- package/reactors/for_Reactors/when_skipping_keep_alive/with_a_reactor.spec.ts +48 -0
- package/reducers/Reducers.ts +4 -1
- package/reducers/for_Reducers/when_skipping_keep_alive/with_a_reducer.spec.ts +53 -0
- package/transactions/AppendOptionNotSupportedInUnitOfWork.ts +17 -0
- package/transactions/ConflictingAppendOptionNamesInUnitOfWork.ts +17 -0
- package/transactions/IUnitOfWork.ts +3 -0
- package/transactions/TransactionalAppendOptions.ts +11 -0
- package/transactions/UnitOfWork.ts +4 -2
- package/transactions/concurrencyScopesAreEqual.ts +4 -3
- package/transactions/for_UnitOfWork/when_adding_events_with_append_option_names/and_both_names_have_different_values.spec.ts +65 -0
- package/transactions/for_UnitOfWork/when_adding_events_with_append_option_names/and_both_names_have_the_same_value.spec.ts +22 -0
- package/transactions/for_UnitOfWork/when_adding_events_with_append_option_names/and_the_append_option_names_are_used.spec.ts +25 -0
- package/transactions/for_UnitOfWork/when_adding_events_with_concurrency_scopes/and_a_routing_field_is_empty_versus_named.spec.ts +40 -0
- package/transactions/for_UnitOfWork/when_adding_events_with_concurrency_scopes/and_routing_fields_are_undefined_or_empty.spec.ts +39 -0
- package/transactions/for_UnitOfWork/when_adding_events_with_unsupported_append_options/and_a_correlation_id_is_given.spec.ts +38 -0
- package/transactions/for_UnitOfWork/when_adding_events_with_unsupported_append_options/and_an_event_source_id_is_given.spec.ts +38 -0
- package/transactions/for_UnitOfWork/when_adding_events_with_unsupported_append_options/and_concurrency_scopes_are_given.spec.ts +38 -0
- package/transactions/for_UnitOfWork/when_adding_events_with_unsupported_append_options/and_the_option_is_undefined.spec.ts +24 -0
- package/transactions/index.ts +2 -0
- package/transactions/resolveTransactionalAppendOptions.ts +68 -0
|
@@ -0,0 +1,39 @@
|
|
|
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 } from '../../../eventSequences/EventSequenceId.js';
|
|
6
|
+
import type { ConcurrencyScope } from '../../../eventSequences/ConcurrencyScope.js';
|
|
7
|
+
import { a_unit_of_work_with_a_recording_store, type RecordedAppend } from '../given/a_unit_of_work_with_a_recording_store.js';
|
|
8
|
+
|
|
9
|
+
chai.should();
|
|
10
|
+
|
|
11
|
+
describe('when adding events with concurrency scopes and the routing fields are undefined or empty', () => {
|
|
12
|
+
let appends: RecordedAppend[];
|
|
13
|
+
let errors: unknown[];
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
const recording = a_unit_of_work_with_a_recording_store();
|
|
17
|
+
errors = [];
|
|
18
|
+
const fields = ['eventStreamType', 'eventStreamId', 'eventSourceType'] as const;
|
|
19
|
+
for (const field of fields) {
|
|
20
|
+
const undefinedScope: ConcurrencyScope = { sequenceNumber: 1n };
|
|
21
|
+
const emptyScope: ConcurrencyScope = { sequenceNumber: 1n, [field]: '' };
|
|
22
|
+
const pairs = [[undefinedScope, emptyScope], [emptyScope, undefinedScope]];
|
|
23
|
+
pairs.forEach(([first, second], index) => {
|
|
24
|
+
const source = `${field}-${index}`;
|
|
25
|
+
try {
|
|
26
|
+
recording.unitOfWork.addEvent(EventSequenceId.eventLog, source, { order: 0 }, { concurrencyScope: first });
|
|
27
|
+
recording.unitOfWork.addEvent(EventSequenceId.eventLog, source, { order: 1 }, { concurrencyScope: second });
|
|
28
|
+
} catch (caught) {
|
|
29
|
+
errors.push(caught);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
await recording.unitOfWork.commit();
|
|
34
|
+
appends = recording.appends;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should not reject any event', () => errors.should.be.empty);
|
|
38
|
+
it('should append every event', () => appends[0].events.should.have.lengthOf(12));
|
|
39
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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 type { AppendOptions } from '../../../eventSequences/AppendOptions.js';
|
|
6
|
+
import { EventSequenceId } from '../../../eventSequences/EventSequenceId.js';
|
|
7
|
+
import { AppendOptionNotSupportedInUnitOfWork } from '../../AppendOptionNotSupportedInUnitOfWork.js';
|
|
8
|
+
import { a_unit_of_work_with_a_recording_store, type RecordingUnitOfWork } from '../given/a_unit_of_work_with_a_recording_store.js';
|
|
9
|
+
|
|
10
|
+
chai.should();
|
|
11
|
+
|
|
12
|
+
describe('when adding events and a correlation identifier is given', () => {
|
|
13
|
+
let recording: RecordingUnitOfWork;
|
|
14
|
+
let error: unknown;
|
|
15
|
+
let buffered: ReadonlyArray<object>;
|
|
16
|
+
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
recording = a_unit_of_work_with_a_recording_store();
|
|
19
|
+
const { unitOfWork } = recording;
|
|
20
|
+
unitOfWork.addEvent(EventSequenceId.eventLog, 'a-1', { order: 0 });
|
|
21
|
+
const options: AppendOptions = { correlationId: 'private-correlation-id', subject: 's', concurrencyScope: { sequenceNumber: 2n } };
|
|
22
|
+
error = undefined;
|
|
23
|
+
try {
|
|
24
|
+
unitOfWork.addEvent(EventSequenceId.eventLog, 'a-1', { order: 1 }, options);
|
|
25
|
+
} catch (caught) {
|
|
26
|
+
error = caught;
|
|
27
|
+
}
|
|
28
|
+
buffered = unitOfWork.getEvents();
|
|
29
|
+
await unitOfWork.commit();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should reject the unsupported option', () => error!.should.be.instanceOf(AppendOptionNotSupportedInUnitOfWork));
|
|
33
|
+
it('should name the option', () => (error as AppendOptionNotSupportedInUnitOfWork).optionName.should.equal('correlationId'));
|
|
34
|
+
it('should not disclose the value', () => (error as Error).message.should.not.contain('private-correlation-id'));
|
|
35
|
+
it('should keep only the first event', () => buffered.should.deep.equal([{ order: 0 }]));
|
|
36
|
+
it('should commit only the first event', () => recording.appends[0].events.should.deep.equal([{ eventSourceId: 'a-1', event: { order: 0 } }]));
|
|
37
|
+
it('should not enroll the refused scope', () => recording.appends[0].options.should.not.have.property('concurrencyScopes'));
|
|
38
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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 type { AppendOptions } from '../../../eventSequences/AppendOptions.js';
|
|
6
|
+
import { EventSequenceId } from '../../../eventSequences/EventSequenceId.js';
|
|
7
|
+
import { AppendOptionNotSupportedInUnitOfWork } from '../../AppendOptionNotSupportedInUnitOfWork.js';
|
|
8
|
+
import { a_unit_of_work_with_a_recording_store, type RecordingUnitOfWork } from '../given/a_unit_of_work_with_a_recording_store.js';
|
|
9
|
+
|
|
10
|
+
chai.should();
|
|
11
|
+
|
|
12
|
+
describe('when adding events and an event source identifier is given', () => {
|
|
13
|
+
let recording: RecordingUnitOfWork;
|
|
14
|
+
let error: unknown;
|
|
15
|
+
let buffered: ReadonlyArray<object>;
|
|
16
|
+
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
recording = a_unit_of_work_with_a_recording_store();
|
|
19
|
+
const { unitOfWork } = recording;
|
|
20
|
+
unitOfWork.addEvent(EventSequenceId.eventLog, 'a-1', { order: 0 });
|
|
21
|
+
const options: AppendOptions = { eventSourceId: 'private-source-id', subject: 's', concurrencyScope: { sequenceNumber: 2n } };
|
|
22
|
+
error = undefined;
|
|
23
|
+
try {
|
|
24
|
+
unitOfWork.addEvent(EventSequenceId.eventLog, 'a-1', { order: 1 }, options);
|
|
25
|
+
} catch (caught) {
|
|
26
|
+
error = caught;
|
|
27
|
+
}
|
|
28
|
+
buffered = unitOfWork.getEvents();
|
|
29
|
+
await unitOfWork.commit();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should reject the unsupported option', () => error!.should.be.instanceOf(AppendOptionNotSupportedInUnitOfWork));
|
|
33
|
+
it('should name the option', () => (error as AppendOptionNotSupportedInUnitOfWork).optionName.should.equal('eventSourceId'));
|
|
34
|
+
it('should not disclose the value', () => (error as Error).message.should.not.contain('private-source-id'));
|
|
35
|
+
it('should keep only the first event', () => buffered.should.deep.equal([{ order: 0 }]));
|
|
36
|
+
it('should commit only the first event', () => recording.appends[0].events.should.deep.equal([{ eventSourceId: 'a-1', event: { order: 0 } }]));
|
|
37
|
+
it('should not enroll the refused scope', () => recording.appends[0].options.should.not.have.property('concurrencyScopes'));
|
|
38
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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 type { AppendOptions } from '../../../eventSequences/AppendOptions.js';
|
|
6
|
+
import { EventSequenceId } from '../../../eventSequences/EventSequenceId.js';
|
|
7
|
+
import { AppendOptionNotSupportedInUnitOfWork } from '../../AppendOptionNotSupportedInUnitOfWork.js';
|
|
8
|
+
import { a_unit_of_work_with_a_recording_store, type RecordingUnitOfWork } from '../given/a_unit_of_work_with_a_recording_store.js';
|
|
9
|
+
|
|
10
|
+
chai.should();
|
|
11
|
+
|
|
12
|
+
describe('when adding events and concurrency scopes are given', () => {
|
|
13
|
+
let recording: RecordingUnitOfWork;
|
|
14
|
+
let error: unknown;
|
|
15
|
+
let buffered: ReadonlyArray<object>;
|
|
16
|
+
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
recording = a_unit_of_work_with_a_recording_store();
|
|
19
|
+
const { unitOfWork } = recording;
|
|
20
|
+
unitOfWork.addEvent(EventSequenceId.eventLog, 'a-1', { order: 0 });
|
|
21
|
+
const options: AppendOptions = { concurrencyScopes: { 'private-source-id': { sequenceNumber: 7n } }, subject: 's', concurrencyScope: { sequenceNumber: 2n } };
|
|
22
|
+
error = undefined;
|
|
23
|
+
try {
|
|
24
|
+
unitOfWork.addEvent(EventSequenceId.eventLog, 'a-1', { order: 1 }, options);
|
|
25
|
+
} catch (caught) {
|
|
26
|
+
error = caught;
|
|
27
|
+
}
|
|
28
|
+
buffered = unitOfWork.getEvents();
|
|
29
|
+
await unitOfWork.commit();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should reject the unsupported option', () => error!.should.be.instanceOf(AppendOptionNotSupportedInUnitOfWork));
|
|
33
|
+
it('should name the option', () => (error as AppendOptionNotSupportedInUnitOfWork).optionName.should.equal('concurrencyScopes'));
|
|
34
|
+
it('should not disclose the value', () => (error as Error).message.should.not.contain('private-source-id'));
|
|
35
|
+
it('should keep only the first event', () => buffered.should.deep.equal([{ order: 0 }]));
|
|
36
|
+
it('should commit only the first event', () => recording.appends[0].events.should.deep.equal([{ eventSourceId: 'a-1', event: { order: 0 } }]));
|
|
37
|
+
it('should not enroll the refused scope', () => recording.appends[0].options.should.not.have.property('concurrencyScopes'));
|
|
38
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
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 type { AppendOptions } from '../../../eventSequences/AppendOptions.js';
|
|
6
|
+
import type { EventForEventSourceId } from '../../../eventSequences/EventForEventSourceId.js';
|
|
7
|
+
import { EventSequenceId } from '../../../eventSequences/EventSequenceId.js';
|
|
8
|
+
import { a_unit_of_work_with_a_recording_store } from '../given/a_unit_of_work_with_a_recording_store.js';
|
|
9
|
+
|
|
10
|
+
chai.should();
|
|
11
|
+
|
|
12
|
+
describe('when adding events and unsupported options are undefined', () => {
|
|
13
|
+
let entry: EventForEventSourceId;
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
const { unitOfWork, appends } = a_unit_of_work_with_a_recording_store();
|
|
17
|
+
const options: AppendOptions = { correlationId: undefined, concurrencyScopes: undefined, eventSourceId: undefined, subject: 's' };
|
|
18
|
+
unitOfWork.addEvent(EventSequenceId.eventLog, 'a-1', {}, options);
|
|
19
|
+
await unitOfWork.commit();
|
|
20
|
+
entry = appends[0].events[0];
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should keep the subject', () => entry.subject!.should.equal('s'));
|
|
24
|
+
});
|
package/transactions/index.ts
CHANGED
|
@@ -9,3 +9,5 @@ export { UnitOfWorkManager } from './UnitOfWorkManager.js';
|
|
|
9
9
|
export type { TransactionalEventRouting } from './TransactionalEventRouting.js';
|
|
10
10
|
export type { TransactionalAppendOptions } from './TransactionalAppendOptions.js';
|
|
11
11
|
export { ConflictingConcurrencyScopesInUnitOfWork } from './ConflictingConcurrencyScopesInUnitOfWork.js';
|
|
12
|
+
export { ConflictingAppendOptionNamesInUnitOfWork } from './ConflictingAppendOptionNamesInUnitOfWork.js';
|
|
13
|
+
export { AppendOptionNotSupportedInUnitOfWork } from './AppendOptionNotSupportedInUnitOfWork.js';
|
|
@@ -0,0 +1,68 @@
|
|
|
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 type { TransactionalAppendOptions } from './TransactionalAppendOptions.js';
|
|
5
|
+
import { AppendOptionNotSupportedInUnitOfWork } from './AppendOptionNotSupportedInUnitOfWork.js';
|
|
6
|
+
import { ConflictingAppendOptionNamesInUnitOfWork } from './ConflictingAppendOptionNamesInUnitOfWork.js';
|
|
7
|
+
|
|
8
|
+
const unsupportedOptions = [
|
|
9
|
+
['correlationId', 'The unit of work appends with its own correlation identifier; begin the unit of work with it instead: unitOfWorkManager.begin(correlationId).'],
|
|
10
|
+
['concurrencyScopes', 'Give each event its own concurrencyScope; the unit of work combines them per event source identifier.'],
|
|
11
|
+
['eventSourceId', 'The event source identifier is the append argument.']
|
|
12
|
+
] as const;
|
|
13
|
+
|
|
14
|
+
const aliases = [
|
|
15
|
+
['streamType', 'eventStreamType'],
|
|
16
|
+
['streamId', 'eventStreamId'],
|
|
17
|
+
['sourceType', 'eventSourceType']
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
type OptionValues = Record<string, unknown>;
|
|
21
|
+
|
|
22
|
+
function throwIfUnsupported(values: Readonly<OptionValues>): void {
|
|
23
|
+
const unsupported = unsupportedOptions.find(([optionName]) => values[optionName] !== undefined);
|
|
24
|
+
if (unsupported) {
|
|
25
|
+
throw new AppendOptionNotSupportedInUnitOfWork(unsupported[0], unsupported[1]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isConflicting(values: Readonly<OptionValues>, appendOptionName: string, transactionalOptionName: string): boolean {
|
|
30
|
+
const appendValue = values[appendOptionName];
|
|
31
|
+
const transactionalValue = values[transactionalOptionName];
|
|
32
|
+
return appendValue !== undefined && transactionalValue !== undefined && appendValue !== transactionalValue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function throwIfConflicting(values: Readonly<OptionValues>): void {
|
|
36
|
+
const conflict = aliases.find(([appendOptionName, transactionalOptionName]) => isConflicting(values, appendOptionName, transactionalOptionName));
|
|
37
|
+
if (conflict) {
|
|
38
|
+
throw new ConflictingAppendOptionNamesInUnitOfWork(conflict[0], conflict[1]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function normalizeAliases(values: Readonly<OptionValues>): OptionValues {
|
|
43
|
+
const normalized: OptionValues = { ...values };
|
|
44
|
+
for (const [appendOptionName, transactionalOptionName] of aliases) {
|
|
45
|
+
const value = values[transactionalOptionName] ?? values[appendOptionName];
|
|
46
|
+
delete normalized[appendOptionName];
|
|
47
|
+
delete normalized[transactionalOptionName];
|
|
48
|
+
if (value !== undefined) {
|
|
49
|
+
normalized[transactionalOptionName] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return normalized;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Validates transactional append options and normalizes ordinary append option aliases.
|
|
57
|
+
* @param options - Optional metadata for an event added to a unit of work.
|
|
58
|
+
* @returns The options with aliases replaced by their transactional names.
|
|
59
|
+
*/
|
|
60
|
+
export function resolveTransactionalAppendOptions(options?: TransactionalAppendOptions): TransactionalAppendOptions | undefined {
|
|
61
|
+
if (options === undefined) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const values = options as Readonly<OptionValues>;
|
|
65
|
+
throwIfUnsupported(values);
|
|
66
|
+
throwIfConflicting(values);
|
|
67
|
+
return normalizeAliases(values) as TransactionalAppendOptions;
|
|
68
|
+
}
|