@cratis/chronicle 6.16.1 → 6.17.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/artifacts/ActivatedArtifact.ts +5 -1
- package/artifacts/ArtifactCompletionFailed.ts +20 -0
- package/artifacts/ArtifactInvocationContext.ts +21 -0
- package/artifacts/for_withActivatedArtifact/when_completing/after_processing_failure.spec.ts +34 -0
- package/artifacts/index.ts +2 -0
- package/artifacts/withActivatedArtifact.ts +20 -3
- package/dist/artifacts/ActivatedArtifact.d.ts +4 -1
- package/dist/artifacts/ActivatedArtifact.d.ts.map +1 -1
- package/dist/artifacts/ArtifactCompletionFailed.d.ts +9 -0
- package/dist/artifacts/ArtifactCompletionFailed.d.ts.map +1 -0
- package/dist/artifacts/ArtifactCompletionFailed.js +19 -0
- package/dist/artifacts/ArtifactCompletionFailed.js.map +1 -0
- package/dist/artifacts/ArtifactInvocationContext.d.ts +18 -0
- package/dist/artifacts/ArtifactInvocationContext.d.ts.map +1 -0
- package/dist/artifacts/ArtifactInvocationContext.js +4 -0
- package/dist/artifacts/ArtifactInvocationContext.js.map +1 -0
- package/dist/artifacts/index.d.ts +2 -0
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +1 -0
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/withActivatedArtifact.d.ts +2 -1
- package/dist/artifacts/withActivatedArtifact.d.ts.map +1 -1
- package/dist/artifacts/withActivatedArtifact.js +22 -3
- package/dist/artifacts/withActivatedArtifact.js.map +1 -1
- package/dist/projections/CompiledProjectionDefinitions.d.ts +6 -0
- package/dist/projections/CompiledProjectionDefinitions.d.ts.map +1 -1
- package/dist/projections/ProjectionCapabilityProvenance.d.ts +8 -0
- package/dist/projections/ProjectionCapabilityProvenance.d.ts.map +1 -0
- package/dist/projections/ProjectionCapabilityProvenance.js +4 -0
- package/dist/projections/ProjectionCapabilityProvenance.js.map +1 -0
- package/dist/projections/ProjectionDefinitionCompiler.d.ts +1 -0
- package/dist/projections/ProjectionDefinitionCompiler.d.ts.map +1 -1
- package/dist/projections/ProjectionDefinitionCompiler.js +130 -4
- package/dist/projections/ProjectionDefinitionCompiler.js.map +1 -1
- package/dist/projections/ProjectionEventSchema.d.ts +10 -0
- package/dist/projections/ProjectionEventSchema.d.ts.map +1 -0
- package/dist/projections/ProjectionEventSchema.js +4 -0
- package/dist/projections/ProjectionEventSchema.js.map +1 -0
- package/dist/projections/VariantReclassifier.d.ts +2 -0
- package/dist/projections/VariantReclassifier.d.ts.map +1 -1
- package/dist/projections/VariantReclassifier.js.map +1 -1
- package/dist/projections/captureProjectionProvenance.d.ts +4 -0
- package/dist/projections/captureProjectionProvenance.d.ts.map +1 -0
- package/dist/projections/captureProjectionProvenance.js +56 -0
- package/dist/projections/captureProjectionProvenance.js.map +1 -0
- package/dist/projections/declarative/FromBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/FromBuilder.js +9 -0
- package/dist/projections/declarative/FromBuilder.js.map +1 -1
- package/dist/projections/declarative/ProjectionBuilderCore.d.ts.map +1 -1
- package/dist/projections/declarative/ProjectionBuilderCore.js +8 -0
- package/dist/projections/declarative/ProjectionBuilderCore.js.map +1 -1
- package/dist/projections/declarative/projectionBuilderProvenance.d.ts +16 -0
- package/dist/projections/declarative/projectionBuilderProvenance.d.ts.map +1 -0
- package/dist/projections/declarative/projectionBuilderProvenance.js +28 -0
- package/dist/projections/declarative/projectionBuilderProvenance.js.map +1 -0
- package/dist/projections/eventContractPath.d.ts +4 -0
- package/dist/projections/eventContractPath.d.ts.map +1 -0
- package/dist/projections/eventContractPath.js +7 -0
- package/dist/projections/eventContractPath.js.map +1 -0
- package/dist/reactors/Reactors.d.ts.map +1 -1
- package/dist/reactors/Reactors.js +12 -3
- package/dist/reactors/Reactors.js.map +1 -1
- package/dist/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +12 -3
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/testing/projections/ProjectionCapabilities.d.ts +17 -0
- package/dist/testing/projections/ProjectionCapabilities.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionCapabilities.js +233 -0
- package/dist/testing/projections/ProjectionCapabilities.js.map +1 -0
- package/dist/testing/projections/UnsupportedProjectionOperation.d.ts +11 -0
- package/dist/testing/projections/UnsupportedProjectionOperation.d.ts.map +1 -0
- package/dist/testing/projections/UnsupportedProjectionOperation.js +16 -0
- package/dist/testing/projections/UnsupportedProjectionOperation.js.map +1 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Changed.d.ts +7 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Changed.d.ts.map +1 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Changed.js +16 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Changed.js.map +1 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Model.d.ts +10 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Model.d.ts.map +1 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Model.js +20 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Model.js.map +1 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Removed.d.ts +3 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Removed.d.ts.map +1 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Removed.js +7 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/Removed.js.map +1 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/compile.d.ts +12 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/compile.d.ts.map +1 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/compile.js +34 -0
- package/dist/testing/projections/for_ProjectionCapabilities/given/compile.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/projections/CompiledProjectionDefinitions.ts +6 -0
- package/projections/ProjectionCapabilityProvenance.ts +10 -0
- package/projections/ProjectionDefinitionCompiler.ts +127 -4
- package/projections/ProjectionEventSchema.ts +13 -0
- package/projections/VariantReclassifier.ts +2 -0
- package/projections/captureProjectionProvenance.ts +50 -0
- package/projections/declarative/FromBuilder.ts +9 -0
- package/projections/declarative/ProjectionBuilderCore.ts +7 -0
- package/projections/declarative/projectionBuilderProvenance.ts +40 -0
- package/projections/eventContractPath.ts +9 -0
- package/reactors/Reactors.ts +13 -3
- package/reactors/for_Reactors/when_delivering/with_activation.spec.ts +93 -2
- package/reducers/Reducers.ts +14 -3
- package/reducers/for_Reducers/when_delivering/with_activation.spec.ts +67 -1
- package/testing/projections/ProjectionCapabilities.ts +213 -0
- package/testing/projections/UnsupportedProjectionOperation.ts +16 -0
- package/testing/projections/for_ProjectionCapabilities/given/Changed.ts +12 -0
- package/testing/projections/for_ProjectionCapabilities/given/Model.ts +13 -0
- package/testing/projections/for_ProjectionCapabilities/given/Removed.ts +7 -0
- package/testing/projections/for_ProjectionCapabilities/given/compile.ts +39 -0
- package/testing/projections/for_ProjectionCapabilities/when_compiling_capability_evidence.spec.ts +68 -0
- package/testing/projections/for_ProjectionCapabilities/when_rejecting_unsupported_operations.spec.ts +230 -0
- package/testing/projections/for_ProjectionCapabilities/when_validating_numeric_schemas.spec.ts +73 -0
- package/testing/projections/for_ProjectionCapabilities/when_validating_schema_boundaries.spec.ts +118 -0
- package/testing/projections/for_ProjectionCapabilities/when_validating_supported_operations.spec.ts +103 -0
package/testing/projections/for_ProjectionCapabilities/when_validating_supported_operations.spec.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
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 'reflect-metadata';
|
|
5
|
+
import { chai, describe, it } from 'vitest';
|
|
6
|
+
import { addFrom } from '../../../projections/modelBound/addFrom.js';
|
|
7
|
+
import { clearWith } from '../../../projections/modelBound/clearWith.js';
|
|
8
|
+
import { count } from '../../../projections/modelBound/count.js';
|
|
9
|
+
import { decrement } from '../../../projections/modelBound/decrement.js';
|
|
10
|
+
import { increment } from '../../../projections/modelBound/increment.js';
|
|
11
|
+
import { noAutoMap } from '../../../projections/modelBound/noAutoMap.js';
|
|
12
|
+
import { removedWith } from '../../../projections/modelBound/removedWith.js';
|
|
13
|
+
import { setFrom } from '../../../projections/modelBound/setFrom.js';
|
|
14
|
+
import { setFromContext } from '../../../projections/modelBound/setFromContext.js';
|
|
15
|
+
import { setValue } from '../../../projections/modelBound/setValue.js';
|
|
16
|
+
import { subtractFrom } from '../../../projections/modelBound/subtractFrom.js';
|
|
17
|
+
import { ProjectionCapabilities } from '../ProjectionCapabilities.js';
|
|
18
|
+
import { Changed } from './given/Changed.js';
|
|
19
|
+
import { Removed } from './given/Removed.js';
|
|
20
|
+
import { compileDeclarative, compileModelBound } from './given/compile.js';
|
|
21
|
+
|
|
22
|
+
chai.should();
|
|
23
|
+
|
|
24
|
+
describe('when validating the phase-one projection subset', () => {
|
|
25
|
+
const modelBound = [
|
|
26
|
+
{ name: 'root From and schema-inferred AutoMap', configure: () => {} },
|
|
27
|
+
{ name: 'setFrom and event source identity', configure: (model: Function) => setFrom(Changed, 'name')(model.prototype, 'name') },
|
|
28
|
+
{ name: 'setFromContext maps eventType without needing it in the event schema', configure: (model: Function) => setFromContext(Changed, 'eventType')(model.prototype, 'state') },
|
|
29
|
+
{ name: 'setFromContext maps the event source identity', configure: (model: Function) => setFromContext(Changed, 'eventSourceId')(model.prototype, 'state') },
|
|
30
|
+
{ name: 'setFromContext maps a nested identity member', configure: (model: Function) => setFromContext(Changed, 'causedBy.subject')(model.prototype, 'state') },
|
|
31
|
+
{ name: 'constant text', configure: (model: Function) => setValue(Changed, 'ready')(model.prototype, 'state') },
|
|
32
|
+
{ name: 'scalar clearing', configure: (model: Function) => clearWith(Removed)(model.prototype, 'state') },
|
|
33
|
+
{ name: 'addition', configure: (model: Function) => addFrom(Changed, 'quantity')(model.prototype, 'total') },
|
|
34
|
+
{ name: 'subtraction', configure: (model: Function) => subtractFrom(Changed, 'quantity')(model.prototype, 'total') },
|
|
35
|
+
{ name: 'count', configure: (model: Function) => count(Changed)(model.prototype, 'total') },
|
|
36
|
+
{ name: 'increment', configure: (model: Function) => increment(Changed)(model.prototype, 'total') },
|
|
37
|
+
{ name: 'decrement', configure: (model: Function) => decrement(Changed)(model.prototype, 'total') },
|
|
38
|
+
{ name: 'root removal', configure: (model: Function) => removedWith(Removed)(model) },
|
|
39
|
+
{ name: 'AutoMap exclusions', configure: (model: Function) => noAutoMap(model.prototype, 'quantity') }
|
|
40
|
+
];
|
|
41
|
+
for (const testCase of modelBound) {
|
|
42
|
+
it(`should accept model-bound ${testCase.name} before any events are seeded`, () => {
|
|
43
|
+
const { compiled, definition } = compileModelBound(testCase.configure);
|
|
44
|
+
(() => ProjectionCapabilities.validate(compiled, definition)).should.not.throw();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
it('should accept declarative multiple root sources, explicit mappings, constants, arithmetic, and removal', () => {
|
|
49
|
+
const { compiled, definition } = compileDeclarative(builder => builder
|
|
50
|
+
.from(Changed, from => from.set(model => model.name).to(event => event.name)
|
|
51
|
+
.set(model => model.id).toEventSourceId()
|
|
52
|
+
.set(model => model.state).toValue('ready')
|
|
53
|
+
.add(model => model.total).with(event => event.quantity)
|
|
54
|
+
.subtract(model => model.total).with(event => event.quantity)
|
|
55
|
+
.increment(model => model.total).decrement(model => model.total).count(model => model.total))
|
|
56
|
+
.from(Removed).removedWith(Removed).withInitialValues(() => ({ id: '', name: '', quantity: 0, total: 0, state: 'new', labels: [], details: {} })));
|
|
57
|
+
(() => ProjectionCapabilities.validate(compiled, definition)).should.not.throw();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
for (const [property, expression] of [
|
|
61
|
+
['sequenceNumber', '$eventContext(SequenceNumber)'],
|
|
62
|
+
['eventSourceId', '$eventContext(EventSourceId)'],
|
|
63
|
+
['eventStore', '$eventContext(EventStore)'],
|
|
64
|
+
['namespace', '$eventContext(Namespace)'],
|
|
65
|
+
['eventSourceType', '$eventContext(EventSourceType)'],
|
|
66
|
+
['eventStreamType', '$eventContext(EventStreamType)'],
|
|
67
|
+
['eventStreamId', '$eventContext(EventStreamId)'],
|
|
68
|
+
['subject', '$eventContext(Subject)'],
|
|
69
|
+
['hash', '$eventContext(Hash)'],
|
|
70
|
+
['causedBy', '$eventContext(CausedBy)'],
|
|
71
|
+
['observationState', '$eventContext(ObservationState)'],
|
|
72
|
+
['eventType', '$eventContext(EventType)'],
|
|
73
|
+
['occurred', '$eventContext(Occurred)'],
|
|
74
|
+
['correlationId', '$eventContext(CorrelationId)'],
|
|
75
|
+
['causation', '$eventContext(Causation)'],
|
|
76
|
+
['tags', '$eventContext(Tags)'],
|
|
77
|
+
['causedBy.subject', '$eventContext(CausedBy.Subject)'],
|
|
78
|
+
['causedBy.name', '$eventContext(CausedBy.Name)'],
|
|
79
|
+
['causedBy.userName', '$eventContext(CausedBy.UserName)'],
|
|
80
|
+
['causedBy.onBehalfOf', '$eventContext(CausedBy.OnBehalfOf)']
|
|
81
|
+
]) {
|
|
82
|
+
it(`should accept the client's emitted context expression ${expression}`, () => {
|
|
83
|
+
const { compiled, definition } = compileDeclarative(builder => builder.from(Changed, from =>
|
|
84
|
+
from.set(model => model.state).toEventContextProperty(property)));
|
|
85
|
+
definition.From[0].Value.Properties.state.should.equal(expression);
|
|
86
|
+
(() => ProjectionCapabilities.validate(compiled, definition)).should.not.throw();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
it('should accept declarative null clearing and an explicit null initial accumulator', () => {
|
|
91
|
+
const { compiled, definition } = compileDeclarative(builder => builder
|
|
92
|
+
.from(Changed, from => from.set(model => model.state).toValue(null).count(model => model.total))
|
|
93
|
+
.withInitialValues(() => ({ id: '', name: '', quantity: 0, total: null as unknown as number, state: '', labels: [], details: {} })));
|
|
94
|
+
(() => ProjectionCapabilities.validate(compiled, definition)).should.not.throw();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should accept an ordinary object or array value without mistaking it for a child projection', () => {
|
|
98
|
+
const { compiled, definition } = compileDeclarative(builder => builder.from(Changed, from => from
|
|
99
|
+
.set(model => model.labels).to(event => event.labels)
|
|
100
|
+
.set(model => model.details).to(event => event.details)));
|
|
101
|
+
(() => ProjectionCapabilities.validate(compiled, definition)).should.not.throw();
|
|
102
|
+
});
|
|
103
|
+
});
|