@cratis/chronicle 6.6.0 → 6.7.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/README.md +3 -1
- package/artifacts/DefaultClientArtifactsProvider.ts +12 -1
- package/artifacts/validateArtifactSchemas.spec.ts +3 -3
- package/compliance/pii.ts +2 -2
- package/compliance/subject.ts +1 -1
- package/confidentiality/encrypted.ts +1 -1
- package/dist/artifacts/DefaultClientArtifactsProvider.d.ts.map +1 -1
- package/dist/artifacts/DefaultClientArtifactsProvider.js +14 -1
- package/dist/artifacts/DefaultClientArtifactsProvider.js.map +1 -1
- package/dist/compliance/pii.d.ts +2 -2
- package/dist/compliance/pii.js +2 -2
- package/dist/compliance/subject.d.ts +1 -1
- package/dist/compliance/subject.js +1 -1
- package/dist/confidentiality/encrypted.d.ts +1 -1
- package/dist/confidentiality/encrypted.js +1 -1
- package/dist/events/eventTypeDecorator.d.ts +6 -1
- package/dist/events/eventTypeDecorator.d.ts.map +1 -1
- package/dist/events/eventTypeDecorator.js.map +1 -1
- package/dist/projections/Projections.d.ts.map +1 -1
- package/dist/projections/Projections.js +32 -15
- package/dist/projections/Projections.js.map +1 -1
- package/dist/projections/modelBound/fromEvent.d.ts.map +1 -1
- package/dist/projections/modelBound/fromEvent.js +2 -0
- package/dist/projections/modelBound/fromEvent.js.map +1 -1
- package/dist/readModels/ReadModels.d.ts +1 -0
- package/dist/readModels/ReadModels.d.ts.map +1 -1
- package/dist/readModels/ReadModels.js +23 -17
- package/dist/readModels/ReadModels.js.map +1 -1
- package/dist/readModels/assertUniqueReadModelIds.d.ts +4 -0
- package/dist/readModels/assertUniqueReadModelIds.d.ts.map +1 -0
- package/dist/readModels/assertUniqueReadModelIds.js +16 -0
- package/dist/readModels/assertUniqueReadModelIds.js.map +1 -0
- package/dist/readModels/readModel.d.ts +5 -0
- package/dist/readModels/readModel.d.ts.map +1 -1
- package/dist/readModels/readModel.js +14 -0
- package/dist/readModels/readModel.js.map +1 -1
- package/dist/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +12 -2
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/TypeDiscoverer.d.ts +2 -0
- package/dist/types/TypeDiscoverer.d.ts.map +1 -1
- package/dist/types/TypeDiscoverer.js +39 -2
- package/dist/types/TypeDiscoverer.js.map +1 -1
- package/events/constructorRoundTrip.legacy.spec.ts +47 -0
- package/events/constructorRoundTrip.standard.spec.ts +47 -0
- package/events/eventTypeDecorator.ts +6 -1
- package/package.json +1 -1
- package/projections/Projections.childrenAndNested.spec.ts +0 -2
- package/projections/Projections.modelBoundCompleteness.spec.ts +0 -7
- package/projections/Projections.operationalSurface.spec.ts +0 -4
- package/projections/Projections.spec.ts +0 -2
- package/projections/Projections.ts +32 -17
- package/projections/Projections.variants.spec.ts +0 -5
- package/projections/modelBound/fromEvent.ts +3 -0
- package/readModels/MaterializedReadModels.spec.ts +0 -5
- package/readModels/ReadModels.spec.ts +0 -9
- package/readModels/ReadModels.ts +24 -18
- package/readModels/assertUniqueReadModelIds.ts +18 -0
- package/readModels/discovery.spec.ts +113 -0
- package/readModels/readModel.ts +14 -0
- package/readModels/standardFallbacks.standard.spec.ts +1 -1
- package/reducers/Reducers.spec.ts +18 -0
- package/reducers/Reducers.ts +11 -2
- package/schemas/JsonSchemaGenerator.confidentiality.spec.ts +5 -14
- package/schemas/JsonSchemaGenerator.spec.ts +3 -13
- package/schemas/decorators.legacy.spec.ts +2 -3
- package/schemas/decorators.standard.spec.ts +12 -10
- package/types/TypeDiscoverer.ts +38 -2
package/types/TypeDiscoverer.ts
CHANGED
|
@@ -4,10 +4,23 @@
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { DecoratorType } from './DecoratorType.js';
|
|
6
6
|
import { Constructor } from '@cratis/fundamentals';
|
|
7
|
+
import { TypeIntrospector } from './TypeIntrospector.js';
|
|
8
|
+
import { hasPropertyMetadata } from './propertyDecoratorMetadata.js';
|
|
7
9
|
|
|
8
10
|
type GlobFunction = (pattern: string | string[]) => Promise<string[]>;
|
|
9
11
|
type FileImporter = (filePath: string) => Promise<unknown>;
|
|
10
12
|
|
|
13
|
+
const modelBoundPropertyKeys = [
|
|
14
|
+
'setFrom', 'setFromContext', 'setValue', 'addFrom', 'subtractFrom',
|
|
15
|
+
'increment', 'decrement', 'count', 'childrenFrom', 'join', 'fromEvery', 'fromAll'
|
|
16
|
+
].map(name => `chronicle:projection:${name}`);
|
|
17
|
+
|
|
18
|
+
/** Identifies models whose event mappings live on their properties rather than on @fromEvent. */
|
|
19
|
+
export function hasModelBoundProperties(type: Function): boolean {
|
|
20
|
+
return TypeIntrospector.getTrackedProperties(type).some(property =>
|
|
21
|
+
modelBoundPropertyKeys.some(key => hasPropertyMetadata(key, type.prototype, property)));
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
/**
|
|
12
25
|
* Encapsulates discovery and registry operations for decorator-based artifacts.
|
|
13
26
|
*/
|
|
@@ -38,7 +51,15 @@ export class TypeDiscoverer {
|
|
|
38
51
|
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
39
52
|
const files = await this._glob(patterns);
|
|
40
53
|
for (const file of files) {
|
|
41
|
-
await this._importFile(path.resolve(file));
|
|
54
|
+
const module = await this._importFile(path.resolve(file));
|
|
55
|
+
if (module && typeof module === 'object') {
|
|
56
|
+
for (const type of Object.values(module)) {
|
|
57
|
+
if (typeof type !== 'function' || !type.prototype) continue;
|
|
58
|
+
if (hasModelBoundProperties(type)) {
|
|
59
|
+
this.register(DecoratorType.ReadModel, type as Constructor);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
42
63
|
}
|
|
43
64
|
}
|
|
44
65
|
|
|
@@ -51,7 +72,22 @@ export class TypeDiscoverer {
|
|
|
51
72
|
register(decoratorType: DecoratorType, type: Constructor, name?: string): void {
|
|
52
73
|
const discoveredName = name ?? type.name;
|
|
53
74
|
const typesForDecorator = TypeDiscoverer._registeredTypes.get(decoratorType) ?? new Map<string, Constructor>();
|
|
54
|
-
|
|
75
|
+
if (decoratorType === DecoratorType.ReadModel) {
|
|
76
|
+
const previous = Array.from(typesForDecorator).find(([, registered]) => registered === type);
|
|
77
|
+
if (previous && previous[0] !== discoveredName) {
|
|
78
|
+
// An explicit legacy registration overrides the type-name alias registered by an observer.
|
|
79
|
+
if (previous[0] !== type.name) return;
|
|
80
|
+
typesForDecorator.delete(previous[0]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let key = discoveredName;
|
|
84
|
+
if (decoratorType === DecoratorType.ReadModel && typesForDecorator.has(key) && typesForDecorator.get(key) !== type &&
|
|
85
|
+
!(type.prototype instanceof typesForDecorator.get(key)!)) {
|
|
86
|
+
let suffix = 2;
|
|
87
|
+
while (typesForDecorator.has(`${discoveredName}#${suffix}`)) suffix++;
|
|
88
|
+
key = `${discoveredName}#${suffix}`;
|
|
89
|
+
}
|
|
90
|
+
typesForDecorator.set(key, type);
|
|
55
91
|
TypeDiscoverer._registeredTypes.set(decoratorType, typesForDecorator);
|
|
56
92
|
}
|
|
57
93
|
|