@cratis/chronicle 6.71.2 → 6.72.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/dist/reactors/AsyncQueue.d.ts +10 -0
- package/dist/reactors/AsyncQueue.d.ts.map +1 -0
- package/dist/reactors/AsyncQueue.js +42 -0
- package/dist/reactors/AsyncQueue.js.map +1 -0
- package/dist/reactors/IReactorBuilder.d.ts +12 -0
- package/dist/reactors/IReactorBuilder.d.ts.map +1 -0
- package/dist/reactors/IReactorBuilder.js +4 -0
- package/dist/reactors/IReactorBuilder.js.map +1 -0
- package/dist/reactors/IReactorDefinition.d.ts +14 -0
- package/dist/reactors/IReactorDefinition.d.ts.map +1 -0
- package/dist/reactors/IReactorDefinition.js +4 -0
- package/dist/reactors/IReactorDefinition.js.map +1 -0
- package/dist/reactors/IReactorDefinitionBuilder.d.ts +9 -0
- package/dist/reactors/IReactorDefinitionBuilder.d.ts.map +1 -0
- package/dist/reactors/IReactorDefinitionBuilder.js +4 -0
- package/dist/reactors/IReactorDefinitionBuilder.js.map +1 -0
- package/dist/reactors/IReactors.d.ts +21 -10
- package/dist/reactors/IReactors.d.ts.map +1 -1
- package/dist/reactors/ReactorBuilder.d.ts +32 -0
- package/dist/reactors/ReactorBuilder.d.ts.map +1 -0
- package/dist/reactors/ReactorBuilder.js +91 -0
- package/dist/reactors/ReactorBuilder.js.map +1 -0
- package/dist/reactors/ReactorCallback.d.ts +4 -0
- package/dist/reactors/ReactorCallback.d.ts.map +1 -0
- package/dist/reactors/ReactorCallback.js +4 -0
- package/dist/reactors/ReactorCallback.js.map +1 -0
- package/dist/reactors/ReactorEvent.d.ts +7 -0
- package/dist/reactors/ReactorEvent.d.ts.map +1 -0
- package/dist/reactors/ReactorEvent.js +4 -0
- package/dist/reactors/ReactorEvent.js.map +1 -0
- package/dist/reactors/ReactorObservation.d.ts +21 -0
- package/dist/reactors/ReactorObservation.d.ts.map +1 -0
- package/dist/reactors/ReactorObservation.js +43 -0
- package/dist/reactors/ReactorObservation.js.map +1 -0
- package/dist/reactors/ReactorObservationTarget.d.ts +4 -1
- package/dist/reactors/ReactorObservationTarget.d.ts.map +1 -1
- package/dist/reactors/ReactorPageDispatcher.d.ts +6 -0
- package/dist/reactors/ReactorPageDispatcher.d.ts.map +1 -1
- package/dist/reactors/ReactorPageDispatcher.js +96 -51
- package/dist/reactors/ReactorPageDispatcher.js.map +1 -1
- package/dist/reactors/ReactorRegistration.d.ts +14 -0
- package/dist/reactors/ReactorRegistration.d.ts.map +1 -0
- package/dist/reactors/ReactorRegistration.js +4 -0
- package/dist/reactors/ReactorRegistration.js.map +1 -0
- package/dist/reactors/ReactorRegistrationKind.d.ts +7 -0
- package/dist/reactors/ReactorRegistrationKind.d.ts.map +1 -0
- package/dist/reactors/ReactorRegistrationKind.js +10 -0
- package/dist/reactors/ReactorRegistrationKind.js.map +1 -0
- package/dist/reactors/ReactorRegistrations.d.ts +17 -0
- package/dist/reactors/ReactorRegistrations.d.ts.map +1 -0
- package/dist/reactors/ReactorRegistrations.js +42 -0
- package/dist/reactors/ReactorRegistrations.js.map +1 -0
- package/dist/reactors/ReactorSubscription.d.ts +4 -0
- package/dist/reactors/ReactorSubscription.d.ts.map +1 -0
- package/dist/reactors/ReactorSubscription.js +4 -0
- package/dist/reactors/ReactorSubscription.js.map +1 -0
- package/dist/reactors/Reactors.d.ts +31 -38
- package/dist/reactors/Reactors.d.ts.map +1 -1
- package/dist/reactors/Reactors.js +143 -274
- package/dist/reactors/Reactors.js.map +1 -1
- package/dist/reactors/WaitTillSubscribedOptions.d.ts +7 -0
- package/dist/reactors/WaitTillSubscribedOptions.d.ts.map +1 -0
- package/dist/reactors/WaitTillSubscribedOptions.js +4 -0
- package/dist/reactors/WaitTillSubscribedOptions.js.map +1 -0
- package/dist/reactors/index.d.ts +5 -0
- package/dist/reactors/index.d.ts.map +1 -1
- package/dist/reactors/index.js.map +1 -1
- package/dist/reactors/prepareReactor.d.ts +34 -0
- package/dist/reactors/prepareReactor.d.ts.map +1 -0
- package/dist/reactors/prepareReactor.js +75 -0
- package/dist/reactors/prepareReactor.js.map +1 -0
- package/dist/reactors/waitTillSubscribed.d.ts +5 -0
- package/dist/reactors/waitTillSubscribed.d.ts.map +1 -0
- package/dist/reactors/waitTillSubscribed.js +29 -0
- package/dist/reactors/waitTillSubscribed.js.map +1 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/compiled_projection.d.ts +145 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/compiled_projection.d.ts.map +1 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/compiled_projection.js +142 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/compiled_projection.js.map +1 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/lifecycle.d.ts +24 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/lifecycle.d.ts.map +1 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/lifecycle.js +34 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/lifecycle.js.map +1 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/oracle_input.d.ts +7 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/oracle_input.d.ts.map +1 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/oracle_input.js +33 -0
- package/dist/testing/for_ReadModelScenario/when_subtracting_with_children/given/oracle_input.js.map +1 -0
- package/dist/testing/projections/ProjectionArithmeticChildrenCapabilities.js +1 -1
- package/dist/testing/projections/ProjectionArithmeticChildrenCapabilities.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/reactors/AsyncQueue.ts +41 -0
- package/reactors/IReactorBuilder.ts +15 -0
- package/reactors/IReactorDefinition.ts +17 -0
- package/reactors/IReactorDefinitionBuilder.ts +12 -0
- package/reactors/IReactors.ts +25 -10
- package/reactors/ReactorBuilder.ts +98 -0
- package/reactors/ReactorCallback.ts +7 -0
- package/reactors/ReactorEvent.ts +10 -0
- package/reactors/ReactorObservation.ts +45 -0
- package/reactors/ReactorObservationTarget.ts +4 -1
- package/reactors/ReactorPageDispatcher.ts +98 -54
- package/reactors/ReactorRegistration.ts +11 -0
- package/reactors/ReactorRegistrationKind.ts +9 -0
- package/reactors/ReactorRegistrations.ts +45 -0
- package/reactors/ReactorSubscription.ts +7 -0
- package/reactors/Reactors.ts +156 -310
- package/reactors/WaitTillSubscribedOptions.ts +9 -0
- package/reactors/for_Reactors/given/runtime_reactors.fixture.ts +50 -0
- package/reactors/for_Reactors/when_a_class_reactor_fails_to_restart.spec.ts +67 -0
- package/reactors/for_Reactors/when_a_class_reactor_fails_to_start.spec.ts +80 -0
- package/reactors/for_Reactors/when_class_delivery_is_unregistered.spec.ts +62 -0
- package/reactors/for_Reactors/when_defining_runtime_reactors.spec.ts +77 -0
- package/reactors/for_Reactors/when_dispatching_runtime_reactors.spec.ts +94 -0
- package/reactors/for_Reactors/when_registering_runtime_reactors.spec.ts +102 -0
- package/reactors/for_Reactors/when_stopping_runtime_reactors.spec.ts +160 -0
- package/reactors/for_Reactors/when_using_the_default_artifacts_provider.spec.ts +80 -0
- package/reactors/for_Reactors/when_waiting_till_subscribed.spec.ts +65 -0
- package/reactors/index.ts +5 -0
- package/reactors/prepareReactor.ts +79 -0
- package/reactors/waitTillSubscribed.ts +29 -0
- package/testing/for_ReadModelScenario/when_subtracting_with_children/given/compiled_projection.ts +71 -0
- package/testing/for_ReadModelScenario/when_subtracting_with_children/given/lifecycle.ts +38 -0
- package/testing/for_ReadModelScenario/when_subtracting_with_children/given/oracle_input.ts +36 -0
- package/testing/for_ReadModelScenario/when_subtracting_with_children/with_a_fluent_projection.spec.ts +40 -0
- package/testing/for_ReadModelScenario/when_subtracting_with_children/with_legacy_decorators.legacy.spec.ts +50 -0
- package/testing/for_ReadModelScenario/when_subtracting_with_children/with_standard_decorators.standard.spec.ts +51 -0
- package/testing/projections/ProjectionArithmeticChildrenCapabilities.ts +1 -1
- package/testing/projections/for_ProjectionCapabilities/when_validating_add_with_children.spec.ts +1 -1
- package/testing/projections/for_ProjectionCapabilities/when_validating_count_with_children.spec.ts +11 -9
- package/testing/projections/for_ProjectionCapabilities/when_validating_subtract_with_children.spec.ts +105 -0
|
@@ -0,0 +1,105 @@
|
|
|
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 { ProjectionDefinition } from '@cratis/chronicle.contracts';
|
|
6
|
+
import { EventType } from '../../../events/EventType.js';
|
|
7
|
+
import type { JsonSchema } from '../../../schemas/JsonSchema.js';
|
|
8
|
+
import { compile, Totals } from '../../for_ReadModelScenario/when_subtracting_with_children/given/compiled_projection.js';
|
|
9
|
+
import type { ScenarioEvent } from '../../ScenarioEvent.js';
|
|
10
|
+
import { ProjectionReadModelProcessor } from '../ProjectionReadModelProcessor.js';
|
|
11
|
+
import { UnsupportedProjectionOperation } from '../UnsupportedProjectionOperation.js';
|
|
12
|
+
|
|
13
|
+
chai.should();
|
|
14
|
+
type Candidate = { compiled: ReturnType<typeof compile>; definition: ProjectionDefinition; schema: JsonSchema; operand: JsonSchema };
|
|
15
|
+
type Mutation = (candidate: Candidate) => void;
|
|
16
|
+
const boundaries: Array<[string, Mutation]> = [
|
|
17
|
+
...['$increment', '$decrement', '$subtract()', '$subtract(amount + 1)', '$subtract(nested.amount)', '$subtract($eventSourceId)',
|
|
18
|
+
'$subtract(1)', '$subtract(true)', '$subtract(snake_case)', '$subtract(missing)', '$subtract(amount', '$subtract(_snake_case)'].map(expression =>
|
|
19
|
+
[expression, ({ definition }: Candidate) => { definition.From[0].Value.Properties.total = expression; }] as [string, Mutation]),
|
|
20
|
+
...['int32', 'uint32', 'float', 'double', ''].flatMap(format => [
|
|
21
|
+
[`${format || 'empty'} operand format`, ({ operand }: Candidate) => { operand.format = format; }],
|
|
22
|
+
[`${format || 'empty'} target format`, ({ schema }: Candidate) => { schema.properties!.total.format = format; }]
|
|
23
|
+
] as Array<[string, Mutation]>),
|
|
24
|
+
['integer operand', ({ operand }) => { operand.type = 'integer'; operand.format = 'int32'; }],
|
|
25
|
+
['integer target', ({ schema }) => { schema.properties!.total = { type: 'integer', format: 'int32' }; }],
|
|
26
|
+
['non-numeric operand', ({ operand }) => { operand.type = 'string'; }],
|
|
27
|
+
['non-numeric target', ({ schema }) => { schema.properties!.total = { type: 'string' }; }],
|
|
28
|
+
['nullable operand', ({ operand }) => { Object.assign(operand, { type: ['number', 'null'] }); }],
|
|
29
|
+
['nullable target', ({ schema }) => { Object.assign(schema.properties!.total, { type: ['number', 'null'] }); }],
|
|
30
|
+
['protected operand', ({ operand }) => { operand.security = [{ metadataType: 'EncryptedSubject', details: '' }]; }],
|
|
31
|
+
['compliance operand', ({ operand }) => { operand.compliance = [{ metadataType: 'PII', details: '' }]; }],
|
|
32
|
+
['protected target', ({ schema }) => { schema.properties!.total.security = [{ metadataType: 'EncryptedSubject', details: '' }]; }],
|
|
33
|
+
['compliance target', ({ schema }) => { schema.properties!.total.compliance = [{ metadataType: 'PII', details: '' }]; }],
|
|
34
|
+
['GUID root identifier', ({ schema }) => { schema.properties!.id.format = 'uuid'; }],
|
|
35
|
+
['extra root property', ({ schema }) => { schema.properties!.name = { type: 'string' }; }],
|
|
36
|
+
['extra root mapping', ({ definition }) => { definition.From[0].Value.Properties.id = '$eventSourceId'; }],
|
|
37
|
+
['multiple root subscriptions', ({ definition }) => { definition.From.push(structuredClone(definition.From[0])); }],
|
|
38
|
+
...['add-first', 'subtract-first'].flatMap(order => [
|
|
39
|
+
[`mixed add/subtract subscriptions, ${order}`, ({ definition }: Candidate) => {
|
|
40
|
+
const added = structuredClone(definition.From[0]);
|
|
41
|
+
added.Value.Properties.total = '$add(amount)';
|
|
42
|
+
if (order === 'add-first') definition.From.unshift(added);
|
|
43
|
+
else definition.From.push(added);
|
|
44
|
+
}],
|
|
45
|
+
[`mixed add/subtract targets, ${order}`, ({ definition, schema }: Candidate) => {
|
|
46
|
+
schema.properties!.other = { type: 'number' };
|
|
47
|
+
definition.From[0].Value.Properties = order === 'add-first'
|
|
48
|
+
? { other: '$add(amount)', total: '$subtract(amount)' }
|
|
49
|
+
: { total: '$subtract(amount)', other: '$add(amount)' };
|
|
50
|
+
}]
|
|
51
|
+
] as Array<[string, Mutation]>),
|
|
52
|
+
['initial values', ({ definition }) => { definition.InitialModelState = '{"total":0}'; }],
|
|
53
|
+
['root join', ({ definition }) => { definition.Join.push({ Key: definition.From[0].Key, Value: { On: 'id', Properties: {}, Key: '$eventSourceId' } }); }],
|
|
54
|
+
['multiple child collections', ({ definition }) => { definition.Children.other = structuredClone(definition.Children.items); }],
|
|
55
|
+
['untyped children', ({ schema }) => { delete schema.properties!.items.items!.properties; }],
|
|
56
|
+
['numeric child property', ({ schema }) => { schema.properties!.items.items!.properties!.name = { type: 'number' }; }],
|
|
57
|
+
['missing child identifier', ({ schema }) => { delete schema.properties!.items.items!.properties!.itemId; }],
|
|
58
|
+
['child From without event Key', ({ definition }) => { delete definition.Children.items.From[0].Key; }],
|
|
59
|
+
['child removal without event Key', ({ definition }) => { delete definition.Children.items.RemovedWith[0].Key; }],
|
|
60
|
+
['shared root and child From', ({ definition }) => { definition.Children.items.From[0].Key = definition.From[0].Key; }],
|
|
61
|
+
['shared root From and child removal', ({ definition }) => { definition.Children.items.RemovedWith[0].Key = definition.From[0].Key; }],
|
|
62
|
+
['shared root removal and child From', ({ definition }) => { definition.Children.items.From[0].Key = definition.RemovedWith[0].Key; }],
|
|
63
|
+
['shared root and child removal', ({ definition }) => { definition.Children.items.RemovedWith[0].Key = definition.RemovedWith[0].Key; }],
|
|
64
|
+
['shared root From and removal', ({ definition }) => { definition.RemovedWith[0].Key = definition.From[0].Key; }],
|
|
65
|
+
['custom root key', ({ definition }) => { definition.From[0].Value.Key = 'amount'; }],
|
|
66
|
+
['custom root parent key', ({ definition }) => { definition.From[0].Value.ParentKey = 'amount'; }],
|
|
67
|
+
['custom child parent key', ({ definition }) => { definition.Children.items.From[0].Value.ParentKey = 'itemId'; }],
|
|
68
|
+
['child join', ({ definition }) => { definition.Children.items.Join.push({}); }],
|
|
69
|
+
['nested children', ({ definition }) => { definition.Children.items.Children.nested = structuredClone(definition.Children.items); }],
|
|
70
|
+
['value children', ({ definition }) => { definition.Children.items.FromEventProperty = 'items'; }],
|
|
71
|
+
['unknown child expression', ({ definition }) => { definition.Children.items.From[0].Value.Properties.name = '$unknown(name)'; }],
|
|
72
|
+
['unknown root expression', ({ definition }) => { definition.From[0].Value.Properties.total = '$unknown(amount)'; }]
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
function candidate(): Candidate {
|
|
76
|
+
const compiled = compile();
|
|
77
|
+
const definition = compiled.definitions[0];
|
|
78
|
+
const operand = [...compiled.eventSchemas.get(definition)!.values()].find(entry => entry.eventType.Id === 'Subtracted')!.schema.properties!.amount;
|
|
79
|
+
return { compiled, definition, schema: JSON.parse(compiled.readModels[0].Schema), operand };
|
|
80
|
+
}
|
|
81
|
+
const seeded: ScenarioEvent = {
|
|
82
|
+
sourceId: 'A', content: { amount: 2.5 },
|
|
83
|
+
context: {
|
|
84
|
+
eventSourceId: 'A', eventType: EventType.parse('Subtracted+1'), sequenceNumber: 0n,
|
|
85
|
+
occurred: new Date('2025-01-01T00:00:00Z'), correlationId: '00000000-0000-0000-0000-000000000000',
|
|
86
|
+
causation: [], tags: []
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
for (const [name, mutate] of boundaries) {
|
|
90
|
+
for (const [historyName, history] of [['empty', []], ['seeded', [seeded]]] as const) {
|
|
91
|
+
describe(`when rejecting subtraction with children: ${name}, ${historyName} history`, () => {
|
|
92
|
+
let act: () => Promise<unknown>;
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
const value = candidate();
|
|
95
|
+
mutate(value);
|
|
96
|
+
value.compiled.readModels[0].Schema = JSON.stringify(value.schema);
|
|
97
|
+
act = () => new ProjectionReadModelProcessor(Totals, value.compiled, value.definition).process(history);
|
|
98
|
+
});
|
|
99
|
+
it('should reject before replay with the model and contract path', () => {
|
|
100
|
+
act.should.throw(UnsupportedProjectionOperation).and.satisfy((error: Error) =>
|
|
101
|
+
error.message.includes('Totals') && /Children|From|Join|Schema|Definition/.test(error.message));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|