@cratis/chronicle 6.65.0 → 6.67.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 (137) hide show
  1. package/ArtifactRegistrationResult.ts +31 -0
  2. package/ChronicleClient.ts +4 -3
  3. package/ChronicleOptions.ts +76 -24
  4. package/EventStore.ts +31 -6
  5. package/IEventStore.ts +7 -0
  6. package/artifacts/ArtifactRegistrationAttempt.ts +50 -0
  7. package/connection/ChronicleConnection.auth.spec.ts +3 -3
  8. package/connection/ChronicleConnection.ts +7 -0
  9. package/connection/CompatibilityPreflight.ts +22 -4
  10. package/connection/for_ChronicleConnection/when_checking_compatibility/before_append.spec.ts +12 -1
  11. package/connection/for_ChronicleConnection/when_creating_clients/with_correlated_multi_host_callers.spec.ts +1 -1
  12. package/connection/for_ChronicleConnection/when_deferring_client_creation/and_connecting.spec.ts +1 -1
  13. package/connection/for_CompatibilityPreflight/when_verifying/with_concurrent_calls.spec.ts +2 -2
  14. package/connection/for_CompatibilityPreflight/when_verifying/with_kernel_versions.spec.ts +38 -0
  15. package/connection/for_TraceContextMiddleware/when_calling/with_active_context.spec.ts +1 -1
  16. package/connection/for_TraceContextMiddleware/when_calling/with_grpc_instrumentation.spec.ts +1 -1
  17. package/dist/ArtifactRegistrationResult.d.ts +35 -0
  18. package/dist/ArtifactRegistrationResult.d.ts.map +1 -0
  19. package/dist/ArtifactRegistrationResult.js +4 -0
  20. package/dist/ArtifactRegistrationResult.js.map +1 -0
  21. package/dist/ChronicleClient.d.ts.map +1 -1
  22. package/dist/ChronicleClient.js +4 -3
  23. package/dist/ChronicleClient.js.map +1 -1
  24. package/dist/ChronicleOptions.d.ts +22 -0
  25. package/dist/ChronicleOptions.d.ts.map +1 -1
  26. package/dist/ChronicleOptions.js +62 -24
  27. package/dist/ChronicleOptions.js.map +1 -1
  28. package/dist/EventStore.d.ts +11 -2
  29. package/dist/EventStore.d.ts.map +1 -1
  30. package/dist/EventStore.js +29 -6
  31. package/dist/EventStore.js.map +1 -1
  32. package/dist/IEventStore.d.ts +6 -0
  33. package/dist/IEventStore.d.ts.map +1 -1
  34. package/dist/artifacts/ArtifactRegistrationAttempt.d.ts +20 -0
  35. package/dist/artifacts/ArtifactRegistrationAttempt.d.ts.map +1 -0
  36. package/dist/artifacts/ArtifactRegistrationAttempt.js +47 -0
  37. package/dist/artifacts/ArtifactRegistrationAttempt.js.map +1 -0
  38. package/dist/connection/ChronicleConnection.d.ts +2 -0
  39. package/dist/connection/ChronicleConnection.d.ts.map +1 -1
  40. package/dist/connection/ChronicleConnection.js +6 -0
  41. package/dist/connection/ChronicleConnection.js.map +1 -1
  42. package/dist/connection/CompatibilityPreflight.d.ts +5 -0
  43. package/dist/connection/CompatibilityPreflight.d.ts.map +1 -1
  44. package/dist/connection/CompatibilityPreflight.js +18 -3
  45. package/dist/connection/CompatibilityPreflight.js.map +1 -1
  46. package/dist/eventSequences/EventEnrichmentContext.d.ts +15 -0
  47. package/dist/eventSequences/EventEnrichmentContext.d.ts.map +1 -0
  48. package/dist/eventSequences/EventEnrichmentContext.js +4 -0
  49. package/dist/eventSequences/EventEnrichmentContext.js.map +1 -0
  50. package/dist/eventSequences/EventEnrichmentProvider.d.ts +10 -0
  51. package/dist/eventSequences/EventEnrichmentProvider.d.ts.map +1 -0
  52. package/dist/eventSequences/EventEnrichmentProvider.js +4 -0
  53. package/dist/eventSequences/EventEnrichmentProvider.js.map +1 -0
  54. package/dist/eventSequences/EventLog.d.ts +2 -1
  55. package/dist/eventSequences/EventLog.d.ts.map +1 -1
  56. package/dist/eventSequences/EventLog.js +2 -2
  57. package/dist/eventSequences/EventLog.js.map +1 -1
  58. package/dist/eventSequences/EventSequence.d.ts +7 -1
  59. package/dist/eventSequences/EventSequence.d.ts.map +1 -1
  60. package/dist/eventSequences/EventSequence.js +40 -11
  61. package/dist/eventSequences/EventSequence.js.map +1 -1
  62. package/dist/eventSequences/IEventSequence.d.ts +2 -0
  63. package/dist/eventSequences/IEventSequence.d.ts.map +1 -1
  64. package/dist/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.d.ts +1 -1
  65. package/dist/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.d.ts.map +1 -1
  66. package/dist/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.js +3 -3
  67. package/dist/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.js.map +1 -1
  68. package/dist/eventSequences/enrichEventContent.d.ts +5 -0
  69. package/dist/eventSequences/enrichEventContent.d.ts.map +1 -0
  70. package/dist/eventSequences/enrichEventContent.js +16 -0
  71. package/dist/eventSequences/enrichEventContent.js.map +1 -0
  72. package/dist/eventSequences/ensureNamedTagBatchIsSupported.d.ts +2 -2
  73. package/dist/eventSequences/ensureNamedTagBatchIsSupported.d.ts.map +1 -1
  74. package/dist/eventSequences/ensureNamedTagBatchIsSupported.js +10 -3
  75. package/dist/eventSequences/ensureNamedTagBatchIsSupported.js.map +1 -1
  76. package/dist/eventSequences/index.d.ts +2 -0
  77. package/dist/eventSequences/index.d.ts.map +1 -1
  78. package/dist/eventSequences/index.js.map +1 -1
  79. package/dist/for_EventStore/when_inspecting_registration/given/an_event_store.d.ts +13 -0
  80. package/dist/for_EventStore/when_inspecting_registration/given/an_event_store.d.ts.map +1 -0
  81. package/dist/for_EventStore/when_inspecting_registration/given/an_event_store.js +79 -0
  82. package/dist/for_EventStore/when_inspecting_registration/given/an_event_store.js.map +1 -0
  83. package/dist/index.d.ts +2 -0
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +1 -0
  86. package/dist/index.js.map +1 -1
  87. package/dist/projections/Projections.d.ts +2 -1
  88. package/dist/projections/Projections.d.ts.map +1 -1
  89. package/dist/projections/Projections.js +7 -4
  90. package/dist/projections/Projections.js.map +1 -1
  91. package/dist/projections/registerProjectionWithRetry.d.ts +4 -2
  92. package/dist/projections/registerProjectionWithRetry.d.ts.map +1 -1
  93. package/dist/projections/registerProjectionWithRetry.js +8 -4
  94. package/dist/projections/registerProjectionWithRetry.js.map +1 -1
  95. package/dist/testing/ReactorScenario.d.ts.map +1 -1
  96. package/dist/testing/ReactorScenario.js +0 -2
  97. package/dist/testing/ReactorScenario.js.map +1 -1
  98. package/dist/transactions/UnitOfWork.d.ts +1 -0
  99. package/dist/transactions/UnitOfWork.d.ts.map +1 -1
  100. package/dist/transactions/UnitOfWork.js +17 -11
  101. package/dist/transactions/UnitOfWork.js.map +1 -1
  102. package/dist/tsconfig.tsbuildinfo +1 -1
  103. package/eventSequences/EventEnrichmentContext.ts +18 -0
  104. package/eventSequences/EventEnrichmentProvider.ts +16 -0
  105. package/eventSequences/EventLog.ts +4 -2
  106. package/eventSequences/EventSequence.ts +47 -13
  107. package/eventSequences/IEventSequence.ts +3 -0
  108. package/eventSequences/NamedTagsWithRegisteredEventSourceNotSupported.ts +3 -3
  109. package/eventSequences/enrichEventContent.ts +22 -0
  110. package/eventSequences/ensureNamedTagBatchIsSupported.ts +11 -3
  111. package/eventSequences/for_EventSequence/when_appending_named_tags/given.fixture.ts +3 -2
  112. package/eventSequences/for_EventSequence/when_appending_named_tags/with_kernel_versions.spec.ts +92 -0
  113. package/eventSequences/for_EventSequence/when_appending_named_tags/with_registered_sources.spec.ts +28 -22
  114. package/eventSequences/for_EventSequence/when_enriching_appends/from_client_options.spec.ts +64 -0
  115. package/eventSequences/for_EventSequence/when_enriching_appends/given.fixture.ts +53 -0
  116. package/eventSequences/for_EventSequence/when_enriching_appends/with_a_failing_provider.spec.ts +57 -0
  117. package/eventSequences/for_EventSequence/when_enriching_appends/with_a_pending_provider.spec.ts +58 -0
  118. package/eventSequences/for_EventSequence/when_enriching_appends/with_providers.spec.ts +66 -0
  119. package/eventSequences/for_EventSequence/when_enriching_appends/without_providers.spec.ts +25 -0
  120. package/eventSequences/index.ts +2 -0
  121. package/for_ChronicleClient/connectTimeout.spec.ts +29 -0
  122. package/for_ChronicleClient/when_starting_background_work/with_a_correlated_caller.spec.ts +1 -1
  123. package/for_ChronicleOptions/when_configuring_the_connect_timeout/with_connect_timeout.spec.ts +23 -0
  124. package/for_EventStore/when_inspecting_registration/given/an_event_store.ts +59 -0
  125. package/for_EventStore/when_inspecting_registration/with_new_attempts.spec.ts +104 -0
  126. package/for_EventStore/when_inspecting_registration/with_projection_outcomes.spec.ts +80 -0
  127. package/for_index/when_importing_connection_helpers.spec.ts +13 -0
  128. package/index.ts +2 -0
  129. package/package.json +1 -1
  130. package/patterns/for_Patterns/when_querying_through_the_connection/after_resetting_the_channel.spec.ts +1 -1
  131. package/projections/Projections.ts +10 -4
  132. package/projections/for_registerProjectionWithRetry/when_reporting_outcomes.spec.ts +71 -0
  133. package/projections/registerProjectionWithRetry.ts +11 -5
  134. package/testing/ReactorScenario.ts +0 -3
  135. package/testing/for_ReactorScenario/when_recording_side_effects/with_named_tags.spec.ts +11 -13
  136. package/transactions/UnitOfWork.ts +18 -14
  137. package/transactions/for_UnitOfWork/when_committing_events_with_named_tags.spec.ts +87 -29
@@ -20,8 +20,9 @@ const eventSources = {
20
20
  function a_unit_of_work() {
21
21
  const appendMany = vi.fn().mockImplementation(async (events: EventForEventSourceId[]) => events.map(() => success));
22
22
  const completed = vi.fn();
23
- const unitOfWork = new UnitOfWork(Guid.create(), completed, { eventSources, getEventSequence: () => ({ appendMany }) } as unknown as IEventStore);
24
- return { unitOfWork, appendMany, completed };
23
+ const getKernelVersion = vi.fn().mockResolvedValue('19.37.4');
24
+ const unitOfWork = new UnitOfWork(Guid.create(), completed, { eventSources, eventLog: { getKernelVersion }, getEventSequence: () => ({ appendMany }) } as unknown as IEventStore);
25
+ return { unitOfWork, appendMany, completed, getKernelVersion };
25
26
  }
26
27
 
27
28
  describe('when committing events with named tags in a unit of work', () => {
@@ -57,47 +58,37 @@ describe('when adding an event with an invalid named tag to a unit of work', ()
57
58
  for (const separateSequences of [false, true]) {
58
59
  describe(`when committing named tags and a registered source in ${separateSequences ? 'different event sequences' : 'one batch'}`, () => {
59
60
  let calls: ReturnType<typeof a_unit_of_work>;
60
- let error: unknown;
61
+ let appended: EventForEventSourceId[];
61
62
  beforeEach(async () => {
62
63
  calls = a_unit_of_work();
63
- // An otherwise valid group must not be written before a later unsupported combination is found.
64
64
  calls.unitOfWork.addEvent(EventSequenceId.eventLog, 'plain', { first: 1 });
65
65
  const sequenceId = separateSequences ? new EventSequenceId('other') : EventSequenceId.eventLog;
66
66
  calls.unitOfWork.addEvent(sequenceId, 'tagged', { second: 2 }, { namedTags: [new NamedTag('batch', 'b-1')] });
67
67
  calls.unitOfWork.addEvent(sequenceId, 'registered', { third: 3 }, { eventSource: Account });
68
- error = await calls.unitOfWork.commit().catch(caught => caught);
68
+ await calls.unitOfWork.commit();
69
+ appended = calls.appendMany.mock.calls.flatMap(call => call[0] as EventForEventSourceId[]);
69
70
  });
70
- it('should reject with the typed unsupported combination error', () =>
71
- (error as Error).should.be.instanceOf(NamedTagsWithRegisteredEventSourceNotSupported));
72
- it('should not write any group', () => calls.appendMany.mock.calls.should.have.lengthOf(0));
73
- it('should leave the unit of work uncompleted', () => calls.unitOfWork.isCompleted.should.be.false);
74
- it('should not invoke completion callbacks', () => calls.completed.mock.calls.should.have.lengthOf(0));
75
- it('should retain the buffered events for rollback', () => calls.unitOfWork.getEvents().should.have.lengthOf(3));
71
+ it('should write every group', () => calls.appendMany.mock.calls.should.have.lengthOf(separateSequences ? 2 : 1));
72
+ it('should append every event', () => appended.map(event => event.eventSourceId).should.deep.equal(['plain', 'tagged', 'registered']));
73
+ it('should keep the named tags on the tagged event', () =>
74
+ appended[1].namedTags!.map(tag => `${tag.name}=${tag.value}`).should.deep.equal(['batch=b-1']));
75
+ it('should keep the registered source on the registered event', () => appended[2].eventSource!.should.equal(Account));
76
+ it('should complete the unit of work', () => calls.unitOfWork.isCompleted.should.be.true);
77
+ it('should invoke completion callbacks', () => calls.completed.mock.calls.should.have.lengthOf(1));
76
78
  });
77
79
  }
78
80
 
79
- describe('when committing tags and registered sources on different event sequences', () => {
81
+ describe('when committing a registered source and named tags on one event', () => {
80
82
  let calls: ReturnType<typeof a_unit_of_work>;
81
- let error: unknown;
82
83
  beforeEach(async () => {
83
84
  calls = a_unit_of_work();
84
- calls.unitOfWork.addEvent(EventSequenceId.eventLog, 'tagged', {}, { namedTags: [new NamedTag('batch', 'b-1')] });
85
- calls.unitOfWork.addEvent(new EventSequenceId('other'), 'registered', {}, { eventSource: 'Account' });
86
- error = await calls.unitOfWork.commit().catch(caught => caught);
87
- });
88
- it('should reject the entire commit', () => (error as Error).should.be.instanceOf(NamedTagsWithRegisteredEventSourceNotSupported));
89
- it('should not append the first event sequence', () => calls.appendMany.mock.calls.should.have.lengthOf(0));
90
- });
91
-
92
- describe('when committing a registered source and named tags on one event', () => {
93
- let error: unknown;
94
- beforeEach(async () => {
95
- const { unitOfWork } = a_unit_of_work();
96
- unitOfWork.addEvent(EventSequenceId.eventLog, 'registered', {}, { eventSource: 'Account', namedTags: [new NamedTag('batch', 'b-1')] });
97
- error = await unitOfWork.commit().catch(caught => caught);
85
+ calls.unitOfWork.addEvent(EventSequenceId.eventLog, 'registered', {}, { eventSource: 'Account', namedTags: [new NamedTag('batch', 'b-1')] });
86
+ await calls.unitOfWork.commit();
98
87
  });
99
- it('should reject with the typed unsupported combination error', () =>
100
- (error as Error).should.be.instanceOf(NamedTagsWithRegisteredEventSourceNotSupported));
88
+ it('should append the registered source', () => calls.appendMany.mock.calls[0][0][0].eventSource.should.equal('Account'));
89
+ it('should append the named tags', () =>
90
+ calls.appendMany.mock.calls[0][0][0].namedTags.map((tag: NamedTag) => `${tag.name}=${tag.value}`).should.deep.equal(['batch=b-1']));
91
+ it('should complete the unit of work', () => calls.unitOfWork.isCompleted.should.be.true);
101
92
  });
102
93
 
103
94
  describe('when committing a registered source with an empty named tag array', () => {
@@ -110,3 +101,70 @@ describe('when committing a registered source with an empty named tag array', ()
110
101
  it('should append the registered source', () => calls.appendMany.mock.calls[0][0][0].eventSource.should.equal('Account'));
111
102
  it('should complete the unit of work', () => calls.unitOfWork.isCompleted.should.be.true);
112
103
  });
104
+
105
+ for (const version of ['19.37.4', '19.37.4-development', '19.38.0']) {
106
+ describe(`when committing named tags and a registered source on kernel ${version}`, () => {
107
+ let calls: ReturnType<typeof a_unit_of_work>;
108
+
109
+ beforeEach(async () => {
110
+ calls = a_unit_of_work();
111
+ calls.getKernelVersion.mockResolvedValue(version);
112
+ calls.unitOfWork.addEvent(EventSequenceId.eventLog, 'registered', {}, { eventSource: Account, namedTags: [new NamedTag('batch', 'b-1')] });
113
+ await calls.unitOfWork.commit();
114
+ });
115
+
116
+ it('should send the batch', () => calls.appendMany.mock.calls.should.have.lengthOf(1));
117
+ it('should preserve the registered source', () => calls.appendMany.mock.calls[0][0][0].eventSource.should.equal(Account));
118
+ it('should complete', () => calls.completed.mock.calls.should.have.lengthOf(1));
119
+ });
120
+ }
121
+
122
+ for (const version of ['19.37.3', '1.0.0', undefined, '', 'unknown']) {
123
+ for (const separateSequences of [false, true]) {
124
+ describe(`when committing named tags and a registered source in ${separateSequences ? 'different sequences' : 'one batch'} on kernel ${version ?? 'unknown'}`, () => {
125
+ let calls: ReturnType<typeof a_unit_of_work>;
126
+ let error: unknown;
127
+
128
+ beforeEach(async () => {
129
+ calls = a_unit_of_work();
130
+ calls.getKernelVersion.mockResolvedValue(version);
131
+ calls.unitOfWork.addEvent(EventSequenceId.eventLog, 'registered', {}, { eventSource: Account });
132
+ const sequenceId = separateSequences ? new EventSequenceId('other') : EventSequenceId.eventLog;
133
+ calls.unitOfWork.addEvent(sequenceId, 'tagged', {}, { namedTags: [new NamedTag('batch', 'b-1')] });
134
+ try {
135
+ await calls.unitOfWork.commit();
136
+ } catch (caught) {
137
+ error = caught;
138
+ }
139
+ });
140
+
141
+ it('should throw the public operation-specific error', () => (error instanceof NamedTagsWithRegisteredEventSourceNotSupported).should.equal(true));
142
+ it('should not write even the first group', () => calls.appendMany.mock.calls.should.have.lengthOf(0));
143
+ it('should retain all pending events', () => calls.unitOfWork.getEvents().should.have.lengthOf(2));
144
+ it('should not complete', () => calls.completed.mock.calls.should.have.lengthOf(0));
145
+ });
146
+ }
147
+
148
+ describe(`when committing unaffected batches on kernel ${version ?? 'unknown'}`, () => {
149
+ let tagged: ReturnType<typeof a_unit_of_work>;
150
+ let registered: ReturnType<typeof a_unit_of_work>;
151
+
152
+ beforeEach(async () => {
153
+ tagged = a_unit_of_work();
154
+ registered = a_unit_of_work();
155
+ tagged.getKernelVersion.mockResolvedValue(version);
156
+ registered.getKernelVersion.mockResolvedValue(version);
157
+ tagged.unitOfWork.addEvent(EventSequenceId.eventLog, 'tagged', {}, { namedTags: [new NamedTag('batch', 'b-1')] });
158
+ registered.unitOfWork.addEvent(EventSequenceId.eventLog, 'registered', {}, { eventSource: Account, namedTags: [] });
159
+ await tagged.unitOfWork.commit();
160
+ await registered.unitOfWork.commit();
161
+ });
162
+
163
+ it('should send named tags without registered sources', () => tagged.appendMany.mock.calls.should.have.lengthOf(1));
164
+ it('should send registered sources without tags', () => registered.appendMany.mock.calls.should.have.lengthOf(1));
165
+ it('should not need the kernel version for either', () => {
166
+ tagged.getKernelVersion.mock.calls.should.have.lengthOf(0);
167
+ registered.getKernelVersion.mock.calls.should.have.lengthOf(0);
168
+ });
169
+ });
170
+ }