@cratis/chronicle 6.53.0 → 6.54.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.
Files changed (21) hide show
  1. package/README.md +1 -1
  2. package/connection/ChronicleConnection.ts +37 -0
  3. package/connection/for_ChronicleConnection/when_warning_about_tls_validation/tls_validation_warning.spec.ts +80 -0
  4. package/dist/connection/ChronicleConnection.d.ts +2 -0
  5. package/dist/connection/ChronicleConnection.d.ts.map +1 -1
  6. package/dist/connection/ChronicleConnection.js +33 -0
  7. package/dist/connection/ChronicleConnection.js.map +1 -1
  8. package/dist/projections/ProjectionDefinitionCompiler.d.ts.map +1 -1
  9. package/dist/projections/ProjectionDefinitionCompiler.js +22 -18
  10. package/dist/projections/ProjectionDefinitionCompiler.js.map +1 -1
  11. package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts +6 -4
  12. package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts.map +1 -1
  13. package/dist/projections/modelBound/childrenAndNestedBuilder.js +14 -12
  14. package/dist/projections/modelBound/childrenAndNestedBuilder.js.map +1 -1
  15. package/jobs/for_Jobs/against_a_kernel/when_managing_a_replay_job.integration.spec.ts +25 -15
  16. package/package.json +1 -1
  17. package/projections/ProjectionDefinitionCompiler.ts +21 -18
  18. package/projections/for_ProjectionDefinitionCompiler/against_a_kernel/when_subscribing_with_from_all_events.integration.spec.ts +52 -48
  19. package/projections/for_ProjectionDefinitionCompiler/when_compiling_from_all_events.spec.ts +52 -25
  20. package/projections/for_ProjectionDefinitionCompiler/when_compiling_from_all_events.standard.spec.ts +49 -9
  21. package/projections/modelBound/childrenAndNestedBuilder.ts +17 -12
@@ -61,26 +61,66 @@ describe('when compiling standard fromAllEvents without explicit event subscript
61
61
  should(getFromAllEventsMetadata(Alias.prototype, 'title') === undefined).be.true;
62
62
  });
63
63
 
64
- it('should collect standard child and nested mappings in the root All without widening the subscription', () => {
64
+ it('should collect standard child and nested mappings on their owning levels without widening the subscription', () => {
65
65
  @eventType('standard-from-all-events-child-added')
66
66
  class Added { @field(String) id = ''; }
67
- class Detail { @field(String) @fromAllEvents(undefined, 'sequenceNumber') sequence = ''; }
67
+ class Detail {
68
+ @field(String) @fromAllEvents(undefined, 'sequenceNumber') sequence = '';
69
+ @field(String) @fromAllEvents() label = '';
70
+ }
68
71
  class Child {
69
72
  @field(String) id = '';
70
73
  @field(String) @fromAllEvents('name') title = '';
74
+ @field(String) @fromEvery('everyName') @fromAll('aliasName') restricted = '';
71
75
  @field(Detail) @nested detail = new Detail();
72
76
  }
73
77
  class Derived extends Child {}
74
- class Parent {
78
+ class Sibling extends Child { @field(String) @fromAllEvents('siblingName') override title = ''; }
79
+ class Group {
75
80
  @field(Array, { genericArguments: [Derived] }) @childrenFrom(Added, 'id') items: Derived[] = [];
76
81
  }
77
- const { definition } = compileModelBound(Parent);
78
- should(definition.All).deep.equal({
79
- Properties: { title: 'name', sequence: '$eventContext(SequenceNumber)' }, IncludeChildren: true, AutoMap: 0
80
- });
82
+ class Parent {
83
+ @field(Array, { genericArguments: [Group] }) @childrenFrom(Added, 'id') groups: Group[] = [];
84
+ @field(Array, { genericArguments: [Sibling] }) @childrenFrom(Added, 'id') siblings: Sibling[] = [];
85
+ @field(Detail) @nested detail = new Detail();
86
+ }
87
+ const { compiled, definition } = compileModelBound(Parent);
88
+ should(definition.All).deep.equal({ Properties: {}, IncludeChildren: false, AutoMap: 0 });
81
89
  should(definition.SubscribesToAllEvents === undefined).be.true;
82
- should(definition.Children.items.All!.Properties).deep.equal({});
83
- should(definition.Children.items.Nested.detail.All!.Properties).deep.equal({});
90
+ should(definition.Children.groups.All!.Properties).deep.equal({});
91
+ should(definition.Children.groups.Children.items.All!.Properties).deep.equal({ title: 'name', restricted: 'everyName' });
92
+ should(definition.Children.siblings.All!.Properties).deep.equal({ title: 'siblingName', restricted: 'everyName' });
93
+ const detailMappings = { sequence: '$eventContext(SequenceNumber)', label: 'label' };
94
+ should(definition.Children.groups.Children.items.Nested.detail.All!.Properties).deep.equal(detailMappings);
95
+ should(definition.Nested.detail.All!.Properties).deep.equal(detailMappings);
96
+ should(compiled.provenance.get(definition)).include.deep.members([
97
+ { contractPath: 'Children.groups.Children.items.All.Properties.restricted', declaration: '@fromEvery' },
98
+ { contractPath: 'Children.groups.Children.items.Nested.detail.All.Properties.sequence', declaration: '@fromAllEvents' }
99
+ ]);
100
+ });
101
+
102
+ it('should preserve independent same-named root and child mappings in either property order', () => {
103
+ @eventType('standard-all-same-name-added')
104
+ class Added { @field(String) id = ''; }
105
+ class Child {
106
+ @field(String) id = '';
107
+ @field(String) @fromEvery('ignored') @fromAllEvents('childName') title = '';
108
+ @field(String) @fromAllEvents('childOther') @fromEvery('ignored') other = '';
109
+ }
110
+ class RootFirst {
111
+ @field(String) @fromAllEvents('rootName') title = '';
112
+ @field(Array, { genericArguments: [Child] }) @childrenFrom(Added, 'id') items: Child[] = [];
113
+ }
114
+ class ChildFirst {
115
+ @field(Array, { genericArguments: [Child] }) @childrenFrom(Added, 'id') items: Child[] = [];
116
+ @field(String) @fromAllEvents('rootName') title = '';
117
+ }
118
+ for (const type of [RootFirst, ChildFirst]) {
119
+ const { definition } = compileModelBound(type);
120
+ should(definition.All!.Properties).deep.equal({ title: 'rootName' });
121
+ should(definition.Children.items.All!.Properties).deep.equal({ title: 'childName', other: 'childOther' });
122
+ should(definition.SubscribesToAllEvents).be.true;
123
+ }
84
124
  });
85
125
 
86
126
  it('should reject all-event scenarios before replay with the standard decorator declaration', () => {
@@ -234,12 +234,14 @@ function discoverIdentifiedBy(childType: Function | undefined, eventKey: string
234
234
  * `@childrenFrom`/`@nested` properties the child/nested type itself declares.
235
235
  * @param definition - The children definition being populated.
236
236
  * @param childType - The resolved child/nested type, when available.
237
- * @param collectSharedMapping - Collects member mappings into the root's shared All definition.
237
+ * @param path - The contract path of this child or nested definition.
238
+ * @param collectSharedMapping - Collects member mappings into their owning All definition.
238
239
  */
239
240
  function populateFromType(
240
241
  definition: ChildrenDefinitionLike,
241
242
  childType: Function | undefined,
242
- collectSharedMapping?: (prototype: object, property: string) => void
243
+ path: string,
244
+ collectSharedMapping?: (prototype: object, property: string, all: ChildrenDefinitionLike['All'], path: string) => void
243
245
  ): void {
244
246
  if (!childType) {
245
247
  return;
@@ -281,8 +283,7 @@ function populateFromType(
281
283
 
282
284
  const prototype = childType.prototype;
283
285
  const properties = TypeIntrospector.getTrackedProperties(childType);
284
- // Like .NET, collect this type's members before descending into its children.
285
- for (const property of properties) collectSharedMapping?.(prototype, property);
286
+ for (const property of properties) collectSharedMapping?.(prototype, property, definition.All, `${path}.All`);
286
287
  for (const property of properties) {
287
288
  applyPropertyMappings(prototype, property, fromByEventType);
288
289
 
@@ -307,11 +308,11 @@ function populateFromType(
307
308
 
308
309
  const childrenFromList = getChildrenFromMetadata(prototype, property);
309
310
  if (childrenFromList.length > 0) {
310
- definition.Children[property] = buildChildrenEntry(childType, property, childrenFromList, collectSharedMapping);
311
+ definition.Children[property] = buildChildrenEntry(childType, property, childrenFromList, collectSharedMapping, `${path}.Children.${property}`);
311
312
  }
312
313
 
313
314
  if (isNested(prototype, property)) {
314
- definition.Nested[property] = buildNestedEntry(childType, property, collectSharedMapping);
315
+ definition.Nested[property] = buildNestedEntry(childType, property, collectSharedMapping, `${path}.Nested.${property}`);
315
316
  }
316
317
  }
317
318
 
@@ -325,14 +326,16 @@ function populateFromType(
325
326
  * @param type - The class declaring the property.
326
327
  * @param property - The property name.
327
328
  * @param metadataList - The `@childrenFrom` metadata entries declared on the property (one per creating event type).
328
- * @param collectSharedMapping - Collects member mappings into the root's shared All definition.
329
+ * @param collectSharedMapping - Collects member mappings into their owning All definition.
330
+ * @param path - The contract path of this children definition.
329
331
  * @returns The wire-shaped children definition.
330
332
  */
331
333
  export function buildChildrenEntry(
332
334
  type: Function,
333
335
  property: string,
334
336
  metadataList: ChildrenFromMetadata[],
335
- collectSharedMapping?: (prototype: object, property: string) => void
337
+ collectSharedMapping?: (prototype: object, property: string, all: ChildrenDefinitionLike['All'], path: string) => void,
338
+ path = `Children.${property}`
336
339
  ): ChildrenDefinitionLike {
337
340
  const childType = resolveChildElementType(type, property);
338
341
  const definition = createEmptyChildrenDefinition(type, childType);
@@ -352,7 +355,7 @@ export function buildChildrenEntry(
352
355
  });
353
356
  }
354
357
 
355
- populateFromType(definition, childType, collectSharedMapping);
358
+ populateFromType(definition, childType, path, collectSharedMapping);
356
359
 
357
360
  // For non-aggregate-only creating events, populate an unmapped child identifier from
358
361
  // the creating event's key. IdentifiedBy selects the child property; it is not itself
@@ -395,13 +398,15 @@ export function buildChildrenEntry(
395
398
  * Builds the `ChildrenDefinition` for a `@nested` single-object property.
396
399
  * @param type - The class declaring the property.
397
400
  * @param property - The property name.
398
- * @param collectSharedMapping - Collects member mappings into the root's shared All definition.
401
+ * @param collectSharedMapping - Collects member mappings into their owning All definition.
402
+ * @param path - The contract path of this nested definition.
399
403
  * @returns The wire-shaped nested definition.
400
404
  */
401
405
  export function buildNestedEntry(
402
406
  type: Function,
403
407
  property: string,
404
- collectSharedMapping?: (prototype: object, property: string) => void
408
+ collectSharedMapping?: (prototype: object, property: string, all: ChildrenDefinitionLike['All'], path: string) => void,
409
+ path = `Nested.${property}`
405
410
  ): ChildrenDefinitionLike {
406
411
  const nestedType = resolveNestedType(type, property);
407
412
  const definition = createEmptyChildrenDefinition(type, nestedType);
@@ -414,6 +419,6 @@ export function buildNestedEntry(
414
419
  definition.RemovedWith.push({ Key: eventType, Value: { Key: '$eventSourceId', ParentKey: '' } });
415
420
  }
416
421
 
417
- populateFromType(definition, nestedType, collectSharedMapping);
422
+ populateFromType(definition, nestedType, path, collectSharedMapping);
418
423
  return definition;
419
424
  }