@cratis/chronicle 6.66.0 → 6.67.1
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 +2 -2
- package/ChronicleOptions.ts +12 -2
- package/EventStore.ts +31 -6
- package/IEventStore.ts +7 -0
- package/artifacts/ArtifactRegistrationAttempt.ts +50 -0
- 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.js +2 -2
- 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 +8 -2
- 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/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 +4 -1
- package/dist/eventSequences/EventSequence.d.ts.map +1 -1
- package/dist/eventSequences/EventSequence.js +28 -8
- package/dist/eventSequences/EventSequence.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/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 +1 -0
- package/dist/index.d.ts.map +1 -1
- 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/InProcessConstraints.d.ts.map +1 -1
- package/dist/testing/InProcessConstraints.js +0 -3
- package/dist/testing/InProcessConstraints.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 +33 -10
- package/eventSequences/enrichEventContent.ts +22 -0
- 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_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/index.ts +1 -0
- package/package.json +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/InProcessConstraints.ts +0 -3
- package/testing/for_EventScenario/when_appending_scoped_constraints/scope_scenario_behaviors.fixture.ts +32 -22
- package/testing/for_EventScenario/when_appending_scoped_constraints/with_legacy_decorators.legacy.spec.ts +27 -1
- package/testing/for_EventScenario/when_appending_scoped_constraints/with_standard_decorators.standard.spec.ts +27 -1
- package/testing/for_EventScenario/when_appending_scoped_constraints/with_unproven_operations.spec.ts +32 -2
|
@@ -0,0 +1,71 @@
|
|
|
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 { ProjectionDefinition } from '@cratis/chronicle.contracts';
|
|
5
|
+
import { afterEach, beforeEach, chai, describe, it, vi } from 'vitest';
|
|
6
|
+
import type { ProjectionRegistrationOutcome } from '../../ArtifactRegistrationResult.js';
|
|
7
|
+
import type { ChronicleConnection } from '../../connection/ChronicleConnection.js';
|
|
8
|
+
import { createLogger } from '../../logging/createLogger.js';
|
|
9
|
+
import { registerProjectionWithRetry } from '../registerProjectionWithRetry.js';
|
|
10
|
+
|
|
11
|
+
chai.should();
|
|
12
|
+
|
|
13
|
+
describe('when reporting projection registration outcomes', () => {
|
|
14
|
+
let register: ReturnType<typeof vi.fn>;
|
|
15
|
+
let record: ReturnType<typeof vi.fn<(outcome: ProjectionRegistrationOutcome) => void>>;
|
|
16
|
+
let connection: ChronicleConnection;
|
|
17
|
+
const projection = { Identifier: 'projection' } as ProjectionDefinition;
|
|
18
|
+
const logger = createLogger('registration-spec');
|
|
19
|
+
const run = (maxAttempts?: number) => registerProjectionWithRetry(connection, 'store', logger, projection, 'projection', maxAttempts, record);
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.useFakeTimers();
|
|
23
|
+
register = vi.fn().mockResolvedValue({});
|
|
24
|
+
record = vi.fn();
|
|
25
|
+
connection = { projections: { register } } as unknown as ChronicleConnection;
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => { vi.useRealTimers(); });
|
|
28
|
+
|
|
29
|
+
it('should retain the actual response only after a transient failure recovers', async () => {
|
|
30
|
+
const response = {};
|
|
31
|
+
register.mockRejectedValueOnce(new Error('UNAVAILABLE')).mockResolvedValueOnce(response);
|
|
32
|
+
const registration = run();
|
|
33
|
+
await vi.advanceTimersByTimeAsync(1999);
|
|
34
|
+
register.mock.calls.should.have.lengthOf(1);
|
|
35
|
+
record.mock.calls.should.have.lengthOf(0);
|
|
36
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
37
|
+
(await registration)!.should.equal(response);
|
|
38
|
+
record.mock.calls.should.deep.equal([[{ identifier: 'projection', state: 'successful', response }]]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should preserve all five attempts and the growing delays before reporting the underlying failure', async () => {
|
|
42
|
+
const failure = Object.assign(new Error('UNAVAILABLE'), { code: 14 });
|
|
43
|
+
register.mockRejectedValue(failure);
|
|
44
|
+
const registration = run().catch(error => error);
|
|
45
|
+
for (const delay of [2000, 4000, 8000, 15000]) {
|
|
46
|
+
await vi.advanceTimersByTimeAsync(delay - 1);
|
|
47
|
+
record.mock.calls.should.have.lengthOf(0);
|
|
48
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
49
|
+
}
|
|
50
|
+
const thrown = await registration;
|
|
51
|
+
thrown.message.should.equal("Failed to register projection 'projection' after 5 attempt(s): Error: UNAVAILABLE");
|
|
52
|
+
register.mock.calls.should.have.lengthOf(5);
|
|
53
|
+
record.mock.calls.should.deep.equal([[{ identifier: 'projection', state: 'failed', error: failure }]]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should preserve immediate non-transient rejection without retrying', async () => {
|
|
57
|
+
const failure = new Error('Invalid declaration');
|
|
58
|
+
register.mockRejectedValue(failure);
|
|
59
|
+
const thrown = await run().catch(error => error);
|
|
60
|
+
thrown.message.should.equal("Failed to register projection 'projection' after 1 attempt(s): Error: Invalid declaration");
|
|
61
|
+
register.mock.calls.should.have.lengthOf(1);
|
|
62
|
+
record.mock.calls.should.deep.equal([[{ identifier: 'projection', state: 'failed', error: failure }]]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should retain the no-attempt behavior without inventing an acknowledgment', async () => {
|
|
66
|
+
const response = await run(0);
|
|
67
|
+
(response === undefined).should.be.true;
|
|
68
|
+
register.mock.calls.should.have.lengthOf(0);
|
|
69
|
+
record.mock.calls.should.have.lengthOf(0);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { ProjectionOwner, type ProjectionDefinition } from '@cratis/chronicle.contracts';
|
|
5
5
|
import type { ChronicleConnection } from '../connection/index.js';
|
|
6
|
+
import type { ProjectionRegistrationOutcome, ProjectionRegistrationResponse } from '../ArtifactRegistrationResult.js';
|
|
6
7
|
import type { createLogger } from '../logging/createLogger.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -13,7 +14,8 @@ import type { createLogger } from '../logging/createLogger.js';
|
|
|
13
14
|
* @param projection - The projection definition to register.
|
|
14
15
|
* @param identifier - The identifier of the projection, for reporting.
|
|
15
16
|
* @param maxAttempts - The number of attempts before giving up.
|
|
16
|
-
* @
|
|
17
|
+
* @param record - Receives the actual kernel response or final underlying failure.
|
|
18
|
+
* @returns The kernel acknowledgment, or undefined if no attempts were requested.
|
|
17
19
|
*/
|
|
18
20
|
export async function registerProjectionWithRetry(
|
|
19
21
|
connection: ChronicleConnection,
|
|
@@ -21,23 +23,26 @@ export async function registerProjectionWithRetry(
|
|
|
21
23
|
logger: ReturnType<typeof createLogger>,
|
|
22
24
|
projection: ProjectionDefinition,
|
|
23
25
|
identifier: string,
|
|
24
|
-
maxAttempts = 5
|
|
25
|
-
|
|
26
|
+
maxAttempts = 5,
|
|
27
|
+
record: (outcome: ProjectionRegistrationOutcome) => void = () => {}
|
|
28
|
+
): Promise<ProjectionRegistrationResponse | undefined> {
|
|
26
29
|
let delay = 2000;
|
|
27
30
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
28
31
|
try {
|
|
29
32
|
logger.info('Registering projection', { identifier, readModel: projection.ReadModel, attempt });
|
|
30
|
-
await connection.projections.register({
|
|
33
|
+
const response = await connection.projections.register({
|
|
31
34
|
EventStore: eventStore,
|
|
32
35
|
Owner: ProjectionOwner.PROJECTION_OWNER_Client,
|
|
33
36
|
Projections: [projection]
|
|
34
37
|
});
|
|
35
38
|
logger.info('Projection registered successfully', { identifier });
|
|
36
|
-
|
|
39
|
+
record({ identifier, state: 'successful', response });
|
|
40
|
+
return response;
|
|
37
41
|
} catch (error) {
|
|
38
42
|
const msg = String(error);
|
|
39
43
|
const isTransient = msg.includes('UNKNOWN') || msg.includes('UNAVAILABLE') || msg.includes('INTERNAL');
|
|
40
44
|
if (!isTransient || attempt === maxAttempts) {
|
|
45
|
+
record({ identifier, state: 'failed', error });
|
|
41
46
|
throw new Error(`Failed to register projection '${identifier}' after ${attempt} attempt(s): ${msg}`);
|
|
42
47
|
}
|
|
43
48
|
logger.warn('Projection registration failed with transient error, retrying', {
|
|
@@ -50,4 +55,5 @@ export async function registerProjectionWithRetry(
|
|
|
50
55
|
delay = Math.min(delay * 2, 15000);
|
|
51
56
|
}
|
|
52
57
|
}
|
|
58
|
+
return undefined;
|
|
53
59
|
}
|
|
@@ -83,9 +83,6 @@ export class InProcessConstraints {
|
|
|
83
83
|
}
|
|
84
84
|
if (capture.uniqueConstraint) {
|
|
85
85
|
const unique = capture.uniqueConstraint;
|
|
86
|
-
if (scoped && (unique.ignoreCasing || unique.eventDefinitions.some(entry => entry.properties.length !== 1))) {
|
|
87
|
-
throw this.unsupported(name, 'Scoped composite or case-insensitive property keys are not fixture-backed.');
|
|
88
|
-
}
|
|
89
86
|
// constraints-composite.json installs one, two and three flat properties per event type.
|
|
90
87
|
// The kernel keys properties by path with ToDictionary, so duplicate paths are not a key shape.
|
|
91
88
|
if (unique.eventDefinitions.length === 0 || unique.eventDefinitions.some(entry =>
|
|
@@ -15,7 +15,8 @@ import { InProcessConstraints } from '../../InProcessConstraints.js';
|
|
|
15
15
|
chai.should();
|
|
16
16
|
function should(value: unknown): Assertion { return (value as { should: Assertion }).should; }
|
|
17
17
|
|
|
18
|
-
type Entry = { source: string; type: string; value
|
|
18
|
+
type Entry = { source: string; type: string; value?: string; values?: Record<string, string>; sourceType?: string; streamType?: string; streamId?: string };
|
|
19
|
+
type ScopeEvents = Record<string, new (value: string) => object>;
|
|
19
20
|
type Definition = { kind: string; name: string; scope: ConstraintScopeCapture; events?: Array<{ type: string; properties: string[] }>;
|
|
20
21
|
eventTypes?: string[]; ignoreCasing?: boolean; removedWithEventTypeIds: string[]; message: string };
|
|
21
22
|
type History = { sequence: string; source: string; sourceType?: string; streamType?: string; streamId?: string;
|
|
@@ -28,8 +29,31 @@ type ScopeCase = { name: string; kind: string; eventSchemas: Record<string, { ev
|
|
|
28
29
|
isolatedConstraintOperations: Array<{ label: string; mode: string; overload?: string; options?: AppendOptions; events: Entry[] }> };
|
|
29
30
|
type Fixture = { scopeCases: ScopeCase[]; expected: { cases: Array<{ name: string; result: { outcomes: Outcome[] } }> } };
|
|
30
31
|
|
|
32
|
+
function assertArtifacts(types: ScopeEvents, constraints: Constructor[], test: ScopeCase): void {
|
|
33
|
+
const aliases = Object.fromEntries(Object.entries(types).map(([alias, type]) => [getEventTypeMetadata(type)!.eventType.id.value, alias]));
|
|
34
|
+
const compiled = compileConstraints({ eventTypes: Object.keys(test.eventSchemas).map(alias => types[alias]), constraints });
|
|
35
|
+
should(Object.fromEntries(Object.entries(test.eventSchemas).map(([alias]) => {
|
|
36
|
+
const metadata = getEventTypeMetadata(types[alias])!;
|
|
37
|
+
return [alias, { eventTypeId: metadata.eventType.id.value,
|
|
38
|
+
properties: Object.fromEntries(Object.entries(metadata.schema.properties!).map(([key, property]) => [key, property.type])) }];
|
|
39
|
+
}))).deep.equal(test.eventSchemas);
|
|
40
|
+
should([...compiled].map(([name, capture]) => ({
|
|
41
|
+
kind: capture.uniqueConstraint ? 'uniqueProperty' : 'uniqueEventType', name,
|
|
42
|
+
...(capture.uniqueConstraint ? {
|
|
43
|
+
events: capture.uniqueConstraint.eventDefinitions.map(entry => ({ type: aliases[entry.eventTypeId], properties: entry.properties })),
|
|
44
|
+
ignoreCasing: capture.uniqueConstraint.ignoreCasing
|
|
45
|
+
} : { eventTypes: (capture.uniqueEventType!.eventTypeIds ?? [capture.uniqueEventType!.eventTypeId]).map(id => aliases[id]) }),
|
|
46
|
+
removedWithEventTypeIds: (capture.uniqueConstraint?.removedWithEventTypeIds ?? capture.uniqueEventType?.removedWithEventTypeIds ?? []).map(id => aliases[id]),
|
|
47
|
+
message: capture.uniqueConstraint?.message ?? capture.uniqueEventType?.message ?? '', scope: capture.scope
|
|
48
|
+
}))).deep.equal(test.constraintDefinitions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function eventOf(types: ScopeEvents, entry: Entry): object {
|
|
52
|
+
return Object.assign(new types[entry.type](entry.value ?? ''), entry.values);
|
|
53
|
+
}
|
|
54
|
+
|
|
31
55
|
export function scopeScenarioBehaviors(
|
|
32
|
-
types:
|
|
56
|
+
types: ScopeEvents,
|
|
33
57
|
constraints: (scope: ConstraintScopeCapture, kind: string) => Constructor[]
|
|
34
58
|
): void {
|
|
35
59
|
const fixture = JSON.parse(readFileSync(new URL('../../fixtures/constraints-scopes.json', import.meta.url), 'utf8')) as Fixture;
|
|
@@ -38,10 +62,10 @@ export function scopeScenarioBehaviors(
|
|
|
38
62
|
sourceType: event.context.eventSourceType, streamType: event.context.eventStreamType, streamId: event.context.eventStreamId,
|
|
39
63
|
type: event.eventType.id.value, content: event.content, hash: event.context.hash
|
|
40
64
|
}));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
it('should retain all seven scope combinations for both constraint kinds and the alias guards', () => {
|
|
65
|
+
it('should retain all seven scope combinations for property shapes, both constraint kinds and the alias guards', () => {
|
|
44
66
|
should(fixture.scopeCases.map(test => test.name)).deep.equal([
|
|
67
|
+
...Array.from({ length: 7 }, (_, index) => `composite-${index + 1}`),
|
|
68
|
+
...Array.from({ length: 7 }, (_, index) => `folded-${index + 1}`),
|
|
45
69
|
...Array.from({ length: 7 }, (_, index) => ['property', 'cycle', 'once'].map(kind => `${kind}-${index + 1}`)).flat(),
|
|
46
70
|
'property-delimiter-alias', 'cycle-delimiter-alias'
|
|
47
71
|
]);
|
|
@@ -55,21 +79,7 @@ export function scopeScenarioBehaviors(
|
|
|
55
79
|
const definition = test.constraintDefinitions[0];
|
|
56
80
|
const selected = Object.keys(test.eventSchemas).map(alias => types[alias]);
|
|
57
81
|
const selectedConstraints = constraints(definition.scope, test.name.split('-')[0]);
|
|
58
|
-
|
|
59
|
-
should(Object.fromEntries(Object.entries(test.eventSchemas).map(([alias]) => {
|
|
60
|
-
const metadata = getEventTypeMetadata(types[alias])!;
|
|
61
|
-
return [alias, { eventTypeId: metadata.eventType.id.value,
|
|
62
|
-
properties: Object.fromEntries(Object.entries(metadata.schema.properties!).map(([key, property]) => [key, property.type])) }];
|
|
63
|
-
}))).deep.equal(test.eventSchemas);
|
|
64
|
-
should([...compiled].map(([name, capture]) => ({
|
|
65
|
-
kind: capture.uniqueConstraint ? 'uniqueProperty' : 'uniqueEventType', name,
|
|
66
|
-
...(capture.uniqueConstraint ? {
|
|
67
|
-
events: capture.uniqueConstraint.eventDefinitions.map(entry => ({ type: aliases[entry.eventTypeId], properties: entry.properties })),
|
|
68
|
-
ignoreCasing: capture.uniqueConstraint.ignoreCasing
|
|
69
|
-
} : { eventTypes: (capture.uniqueEventType!.eventTypeIds ?? [capture.uniqueEventType!.eventTypeId]).map(id => aliases[id]) }),
|
|
70
|
-
removedWithEventTypeIds: (capture.uniqueConstraint?.removedWithEventTypeIds ?? capture.uniqueEventType?.removedWithEventTypeIds ?? []).map(id => aliases[id]),
|
|
71
|
-
message: capture.uniqueConstraint?.message ?? capture.uniqueEventType?.message ?? '', scope: capture.scope
|
|
72
|
-
}))).deep.equal(test.constraintDefinitions);
|
|
82
|
+
assertArtifacts(types, selectedConstraints, test);
|
|
73
83
|
const scenario = new EventScenario({ artifacts: { eventTypes: selected, constraints: selectedConstraints } });
|
|
74
84
|
const notifications = scenario.eventLog.appendOperations[Symbol.asyncIterator]();
|
|
75
85
|
if (test.kind === 'oracleGuard') {
|
|
@@ -77,7 +87,7 @@ export function scopeScenarioBehaviors(
|
|
|
77
87
|
try {
|
|
78
88
|
for (const operation of test.isolatedConstraintOperations) {
|
|
79
89
|
const entry = operation.events[0];
|
|
80
|
-
await scenario.append(entry.source,
|
|
90
|
+
await scenario.append(entry.source, eventOf(types, entry), operation.options)
|
|
81
91
|
.then(() => { throw new Error('Unsupported route succeeded'); }, error => {
|
|
82
92
|
should(error instanceof UnsupportedEventSequenceOperation).be.true;
|
|
83
93
|
should((error as Error).message).include('Only simple routing identifiers');
|
|
@@ -101,7 +111,7 @@ export function scopeScenarioBehaviors(
|
|
|
101
111
|
for (const [index, operation] of test.isolatedConstraintOperations.entries()) {
|
|
102
112
|
const before = historyOf(scenario);
|
|
103
113
|
const nextNotification = notifications.next();
|
|
104
|
-
const entries = operation.events.map(entry => ({ eventSourceId: entry.source, event:
|
|
114
|
+
const entries = operation.events.map(entry => ({ eventSourceId: entry.source, event: eventOf(types, entry),
|
|
105
115
|
eventSourceType: entry.sourceType, eventStreamType: entry.streamType, eventStreamId: entry.streamId }));
|
|
106
116
|
const results = operation.mode === 'single'
|
|
107
117
|
? [await scenario.append(entries[0].eventSourceId, entries[0].event, operation.options)]
|
|
@@ -13,6 +13,12 @@ import { scopeScenarioBehaviors } from './scope_scenario_behaviors.fixture.js';
|
|
|
13
13
|
|
|
14
14
|
@eventType('OracleDomainText')
|
|
15
15
|
class Text { @field(String) key: string; constructor(key: string) { this.key = key; } }
|
|
16
|
+
@eventType('OracleCompositeName')
|
|
17
|
+
class Name { @field(String) first: string; @field(String) last = ''; constructor(first: string) { this.first = first; } }
|
|
18
|
+
@eventType('OracleCompositeAlias')
|
|
19
|
+
class Alias { @field(String) given: string; @field(String) family = ''; constructor(given: string) { this.given = given; } }
|
|
20
|
+
@eventType('OracleCompositeTriple')
|
|
21
|
+
class Triple { @field(String) first: string; @field(String) middle = ''; @field(String) last = ''; constructor(first: string) { this.first = first; } }
|
|
16
22
|
@eventType('OracleDomainShared')
|
|
17
23
|
class Shared { @field(String) key: string; constructor(key: string) { this.key = key; } }
|
|
18
24
|
@eventType('OracleDomainRemoved')
|
|
@@ -44,14 +50,34 @@ function constraints(scope: ConstraintScopeCapture, kind: string): Constructor[]
|
|
|
44
50
|
.removedWith(Removed).removedWith(Expired).withMessage('Taken: {PropertyValue}'));
|
|
45
51
|
}
|
|
46
52
|
}
|
|
53
|
+
@constraint('OracleScopedName')
|
|
54
|
+
class Composite {
|
|
55
|
+
define(builder: IConstraintBuilder) {
|
|
56
|
+
apply(builder).unique(key => key.on(Text, event => event.key)
|
|
57
|
+
.on(Name, event => event.first, event => event.last)
|
|
58
|
+
.on(Alias, event => event.family, event => event.given)
|
|
59
|
+
.on(Triple, event => event.first, event => event.middle, event => event.last)
|
|
60
|
+
.removedWith(Removed).withMessage('Taken: {PropertyName}={PropertyValue}'));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
@constraint('OracleScopedHandle')
|
|
64
|
+
class Folded {
|
|
65
|
+
define(builder: IConstraintBuilder) {
|
|
66
|
+
apply(builder).unique(key => key.on(Text, event => event.key)
|
|
67
|
+
.on(Name, event => event.first, event => event.last).ignoreCasing()
|
|
68
|
+
.removedWith(Removed).withMessage('Taken: {PropertyName}={PropertyValue}'));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
47
71
|
@constraint('OracleScopedFirst')
|
|
48
72
|
class FirstCycle { define(builder: IConstraintBuilder) { apply(builder).uniqueFor(First, 'Cycle occupied', 'OracleScopedCycle'); } }
|
|
49
73
|
@constraint('OracleScopedSibling')
|
|
50
74
|
class SiblingCycle { define(builder: IConstraintBuilder) { apply(builder).uniqueFor(Sibling, 'Cycle occupied', 'OracleScopedCycle'); } }
|
|
75
|
+
if (kind === 'composite') return [Composite];
|
|
76
|
+
if (kind === 'folded') return [Folded];
|
|
51
77
|
return kind === 'property' ? [Key] : kind === 'once' ? [FirstCycle] : [FirstCycle, SiblingCycle];
|
|
52
78
|
}
|
|
53
79
|
|
|
54
80
|
describe('when appending scoped constraints with legacy decorators', () => {
|
|
55
|
-
scopeScenarioBehaviors({ string: Text, shared: Shared, removed: Removed, expired: Expired,
|
|
81
|
+
scopeScenarioBehaviors({ string: Text, name: Name, alias: Alias, triple: Triple, shared: Shared, removed: Removed, expired: Expired,
|
|
56
82
|
first: First, sibling: Sibling, cycleRemoved: CycleRemoved, cycleExpired: CycleExpired }, constraints);
|
|
57
83
|
});
|
|
@@ -12,6 +12,12 @@ import { scopeScenarioBehaviors } from './scope_scenario_behaviors.fixture.js';
|
|
|
12
12
|
|
|
13
13
|
@eventType('OracleDomainText')
|
|
14
14
|
class Text { @field(String) key: string; constructor(key: string) { this.key = key; } }
|
|
15
|
+
@eventType('OracleCompositeName')
|
|
16
|
+
class Name { @field(String) first: string; @field(String) last = ''; constructor(first: string) { this.first = first; } }
|
|
17
|
+
@eventType('OracleCompositeAlias')
|
|
18
|
+
class Alias { @field(String) given: string; @field(String) family = ''; constructor(given: string) { this.given = given; } }
|
|
19
|
+
@eventType('OracleCompositeTriple')
|
|
20
|
+
class Triple { @field(String) first: string; @field(String) middle = ''; @field(String) last = ''; constructor(first: string) { this.first = first; } }
|
|
15
21
|
@eventType('OracleDomainShared')
|
|
16
22
|
class Shared { @field(String) key: string; constructor(key: string) { this.key = key; } }
|
|
17
23
|
@eventType('OracleDomainRemoved')
|
|
@@ -43,14 +49,34 @@ function constraints(scope: ConstraintScopeCapture, kind: string): Constructor[]
|
|
|
43
49
|
.removedWith(Removed).removedWith(Expired).withMessage('Taken: {PropertyValue}'));
|
|
44
50
|
}
|
|
45
51
|
}
|
|
52
|
+
@constraint('OracleScopedName')
|
|
53
|
+
class Composite {
|
|
54
|
+
define(builder: IConstraintBuilder) {
|
|
55
|
+
apply(builder).unique(key => key.on(Text, event => event.key)
|
|
56
|
+
.on(Name, event => event.first, event => event.last)
|
|
57
|
+
.on(Alias, event => event.family, event => event.given)
|
|
58
|
+
.on(Triple, event => event.first, event => event.middle, event => event.last)
|
|
59
|
+
.removedWith(Removed).withMessage('Taken: {PropertyName}={PropertyValue}'));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
@constraint('OracleScopedHandle')
|
|
63
|
+
class Folded {
|
|
64
|
+
define(builder: IConstraintBuilder) {
|
|
65
|
+
apply(builder).unique(key => key.on(Text, event => event.key)
|
|
66
|
+
.on(Name, event => event.first, event => event.last).ignoreCasing()
|
|
67
|
+
.removedWith(Removed).withMessage('Taken: {PropertyName}={PropertyValue}'));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
46
70
|
@constraint('OracleScopedFirst')
|
|
47
71
|
class FirstCycle { define(builder: IConstraintBuilder) { apply(builder).uniqueFor(First, 'Cycle occupied', 'OracleScopedCycle'); } }
|
|
48
72
|
@constraint('OracleScopedSibling')
|
|
49
73
|
class SiblingCycle { define(builder: IConstraintBuilder) { apply(builder).uniqueFor(Sibling, 'Cycle occupied', 'OracleScopedCycle'); } }
|
|
74
|
+
if (kind === 'composite') return [Composite];
|
|
75
|
+
if (kind === 'folded') return [Folded];
|
|
50
76
|
return kind === 'property' ? [Key] : kind === 'once' ? [FirstCycle] : [FirstCycle, SiblingCycle];
|
|
51
77
|
}
|
|
52
78
|
|
|
53
79
|
describe('when appending scoped constraints with standard decorators', () => {
|
|
54
|
-
scopeScenarioBehaviors({ string: Text, shared: Shared, removed: Removed, expired: Expired,
|
|
80
|
+
scopeScenarioBehaviors({ string: Text, name: Name, alias: Alias, triple: Triple, shared: Shared, removed: Removed, expired: Expired,
|
|
55
81
|
first: First, sibling: Sibling, cycleRemoved: CycleRemoved, cycleExpired: CycleExpired }, constraints);
|
|
56
82
|
});
|
package/testing/for_EventScenario/when_appending_scoped_constraints/with_unproven_operations.spec.ts
CHANGED
|
@@ -38,8 +38,6 @@ async function unsupported(action: () => unknown, reason: string): Promise<void>
|
|
|
38
38
|
|
|
39
39
|
describe('when configuring unproven scoped property shapes', () => {
|
|
40
40
|
for (const [name, configure, reason] of [
|
|
41
|
-
['composite', (builder: IConstraintBuilder) => builder.unique(value => value.on(Claim, event => event.key, event => event.other)), 'Scoped composite or case-insensitive property keys'],
|
|
42
|
-
['casing', (builder: IConstraintBuilder) => builder.unique(value => value.on(Claim, event => event.key).ignoreCasing()), 'Scoped composite or case-insensitive property keys'],
|
|
43
41
|
['boolean', (builder: IConstraintBuilder) => builder.unique(value => value.on(Flag, event => event.key)), 'Scoped property keys must be schema-backed strings'],
|
|
44
42
|
['covered removal', (builder: IConstraintBuilder) => builder.unique(value => value.on(Claim, event => event.key).removedWith(Claim)), 'Scoped covered-and-removal property events'],
|
|
45
43
|
['fieldless removal', (builder: IConstraintBuilder) => builder.unique(value => value.on(Claim, event => event.key).removedWith(Fieldless)), 'Scoped fieldless removal events']
|
|
@@ -67,6 +65,38 @@ describe('when configuring unproven scoped property shapes', () => {
|
|
|
67
65
|
});
|
|
68
66
|
});
|
|
69
67
|
|
|
68
|
+
describe('when a scoped case-insensitive append uses non-ASCII keys', () => {
|
|
69
|
+
for (const composite of [false, true]) {
|
|
70
|
+
it(`should preserve state and notifications after rejecting a ${composite ? 'composite' : 'single'} key`, async () => {
|
|
71
|
+
const folded = definition(builder => builder.perEventStreamId().unique(value =>
|
|
72
|
+
(composite ? value.on(Claim, event => event.key, event => event.other) : value.on(Claim, event => event.key))
|
|
73
|
+
.ignoreCasing().removedWith(Removed)));
|
|
74
|
+
const scenario = new EventScenario({ artifacts: { eventTypes: [Claim, Removed], constraints: [folded] } });
|
|
75
|
+
(await scenario.append('A', new Claim('Alpha'), { streamId: 'West' })).isSuccess.should.be.true;
|
|
76
|
+
const before = scenario.appendedEvents;
|
|
77
|
+
const results = scenario.results;
|
|
78
|
+
const notifications = scenario.eventLog.appendOperations[Symbol.asyncIterator]();
|
|
79
|
+
const pending = notifications.next();
|
|
80
|
+
try {
|
|
81
|
+
await unsupported(() => scenario.append('A', new Claim('é'), { streamId: 'West' }), 'ASCII key domain');
|
|
82
|
+
await unsupported(() => scenario.appendMany('A', [new Claim('Temp'), new Claim('é')], { streamId: 'West' }),
|
|
83
|
+
'ASCII key domain');
|
|
84
|
+
await unsupported(() => scenario.appendMany([
|
|
85
|
+
{ eventSourceId: 'B', event: new Claim('Temp'), eventStreamId: 'West' },
|
|
86
|
+
{ eventSourceId: 'A', event: new Claim('é'), eventStreamId: 'West' }
|
|
87
|
+
]), 'ASCII key domain');
|
|
88
|
+
scenario.appendedEvents.should.deep.equal(before);
|
|
89
|
+
scenario.results.should.deep.equal(results);
|
|
90
|
+
(await scenario.eventLog.getNextSequenceNumber()).value.should.equal(1n);
|
|
91
|
+
const duplicate = await scenario.append('B', new Claim('ALPHA'), { streamId: 'West' });
|
|
92
|
+
duplicate.isSuccess.should.be.false;
|
|
93
|
+
(await pending).value![0].result.should.equal(duplicate);
|
|
94
|
+
(await scenario.append('B', new Claim('TEMP'), { streamId: 'West' })).sequenceNumber.value.should.equal(1n);
|
|
95
|
+
} finally { await notifications.return?.(); }
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
70
100
|
describe('when a scoped append uses unsupported routes or metadata', () => {
|
|
71
101
|
it('should preserve claims, history, results, notifications and sequence after unsupported input', async () => {
|
|
72
102
|
const scenario = create();
|