@cratis/chronicle 6.40.0 → 6.41.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.
Files changed (100) hide show
  1. package/compliance/for_PIIManager/against_a_kernel/when_erasing_a_subject.integration.spec.ts +4 -4
  2. package/compliance/resolveEventSubject.ts +19 -0
  3. package/compliance/subject.ts +2 -2
  4. package/dist/compliance/resolveEventSubject.d.ts +3 -0
  5. package/dist/compliance/resolveEventSubject.d.ts.map +1 -0
  6. package/dist/compliance/resolveEventSubject.js +21 -0
  7. package/dist/compliance/resolveEventSubject.js.map +1 -0
  8. package/dist/compliance/subject.d.ts +2 -2
  9. package/dist/compliance/subject.js +2 -2
  10. package/dist/eventSequences/AppendOptions.d.ts +1 -1
  11. package/dist/eventSequences/AppendOptions.d.ts.map +1 -1
  12. package/dist/eventSequences/EventForEventSourceId.d.ts +1 -1
  13. package/dist/eventSequences/EventForEventSourceId.d.ts.map +1 -1
  14. package/dist/eventSequences/EventSequence.js +2 -2
  15. package/dist/eventSequences/EventSequence.js.map +1 -1
  16. package/dist/eventSequences/prepareBatchAppend.d.ts.map +1 -1
  17. package/dist/eventSequences/prepareBatchAppend.js +2 -1
  18. package/dist/eventSequences/prepareBatchAppend.js.map +1 -1
  19. package/dist/eventSequences/prepareSingleAppend.d.ts +1 -0
  20. package/dist/eventSequences/prepareSingleAppend.d.ts.map +1 -1
  21. package/dist/eventSequences/prepareSingleAppend.js +3 -1
  22. package/dist/eventSequences/prepareSingleAppend.js.map +1 -1
  23. package/dist/testing/EventScenario.js +1 -1
  24. package/dist/testing/EventScenario.js.map +1 -1
  25. package/dist/testing/EventScenarioGiven.d.ts +3 -1
  26. package/dist/testing/EventScenarioGiven.d.ts.map +1 -1
  27. package/dist/testing/EventScenarioGiven.js +4 -2
  28. package/dist/testing/EventScenarioGiven.js.map +1 -1
  29. package/dist/testing/EventScenarioGivenBuilder.d.ts +2 -1
  30. package/dist/testing/EventScenarioGivenBuilder.d.ts.map +1 -1
  31. package/dist/testing/EventScenarioGivenBuilder.js +1 -1
  32. package/dist/testing/EventScenarioGivenBuilder.js.map +1 -1
  33. package/dist/testing/EventScenarioSeed.d.ts +3 -2
  34. package/dist/testing/EventScenarioSeed.d.ts.map +1 -1
  35. package/dist/testing/EventScenarioSeed.js +2 -2
  36. package/dist/testing/EventScenarioSeed.js.map +1 -1
  37. package/dist/testing/EventScenarioWhen.d.ts +3 -1
  38. package/dist/testing/EventScenarioWhen.d.ts.map +1 -1
  39. package/dist/testing/EventScenarioWhen.js +5 -3
  40. package/dist/testing/EventScenarioWhen.js.map +1 -1
  41. package/dist/testing/EventScenarioWhenBuilder.d.ts +2 -1
  42. package/dist/testing/EventScenarioWhenBuilder.d.ts.map +1 -1
  43. package/dist/testing/EventScenarioWhenBuilder.js +1 -1
  44. package/dist/testing/EventScenarioWhenBuilder.js.map +1 -1
  45. package/dist/testing/InProcessEventSequence.d.ts +1 -2
  46. package/dist/testing/InProcessEventSequence.d.ts.map +1 -1
  47. package/dist/testing/InProcessEventSequence.js +19 -27
  48. package/dist/testing/InProcessEventSequence.js.map +1 -1
  49. package/dist/testing/ReactorScenario.d.ts +3 -2
  50. package/dist/testing/ReactorScenario.d.ts.map +1 -1
  51. package/dist/testing/ReactorScenario.js +5 -5
  52. package/dist/testing/ReactorScenario.js.map +1 -1
  53. package/dist/testing/ReadModelScenario.d.ts +2 -1
  54. package/dist/testing/ReadModelScenario.d.ts.map +1 -1
  55. package/dist/testing/ReadModelScenario.js +10 -1
  56. package/dist/testing/ReadModelScenario.js.map +1 -1
  57. package/dist/testing/ReadModelScenarioGiven.d.ts +3 -1
  58. package/dist/testing/ReadModelScenarioGiven.d.ts.map +1 -1
  59. package/dist/testing/ReadModelScenarioGiven.js +4 -2
  60. package/dist/testing/ReadModelScenarioGiven.js.map +1 -1
  61. package/dist/testing/ReadModelScenarioGivenBuilder.d.ts +2 -1
  62. package/dist/testing/ReadModelScenarioGivenBuilder.d.ts.map +1 -1
  63. package/dist/testing/ReadModelScenarioGivenBuilder.js +2 -2
  64. package/dist/testing/ReadModelScenarioGivenBuilder.js.map +1 -1
  65. package/dist/testing/singleAppendRoute.d.ts +9 -0
  66. package/dist/testing/singleAppendRoute.d.ts.map +1 -0
  67. package/dist/testing/singleAppendRoute.js +28 -0
  68. package/dist/testing/singleAppendRoute.js.map +1 -0
  69. package/dist/tsconfig.tsbuildinfo +1 -1
  70. package/eventSequences/AppendOptions.ts +1 -1
  71. package/eventSequences/EventForEventSourceId.ts +1 -1
  72. package/eventSequences/EventSequence.ts +2 -2
  73. package/eventSequences/for_EventSequence/when_appending/subject_behaviors.fixture.ts +239 -0
  74. package/eventSequences/for_EventSequence/when_appending/with_subject_annotations.spec.ts +34 -0
  75. package/eventSequences/for_EventSequence/when_appending/with_subject_annotations.standard.spec.ts +38 -0
  76. package/eventSequences/prepareBatchAppend.ts +2 -1
  77. package/eventSequences/prepareSingleAppend.ts +3 -1
  78. package/package.json +2 -2
  79. package/testing/EventScenario.batches.spec.ts +2 -2
  80. package/testing/EventScenario.fixtures.spec.ts +2 -2
  81. package/testing/EventScenario.rejections.spec.ts +2 -2
  82. package/testing/EventScenario.ts +1 -1
  83. package/testing/EventScenarioGiven.ts +3 -2
  84. package/testing/EventScenarioGivenBuilder.ts +2 -1
  85. package/testing/EventScenarioSeed.ts +5 -4
  86. package/testing/EventScenarioWhen.ts +4 -3
  87. package/testing/EventScenarioWhenBuilder.ts +2 -1
  88. package/testing/InProcessEventSequence.ts +20 -28
  89. package/testing/ReactorScenario.ts +7 -7
  90. package/testing/ReadModelScenario.spec.ts +31 -0
  91. package/testing/ReadModelScenario.ts +12 -1
  92. package/testing/ReadModelScenarioGiven.ts +4 -2
  93. package/testing/ReadModelScenarioGivenBuilder.ts +3 -2
  94. package/testing/for_EventScenario/given/routed_scenario.fixture.ts +39 -0
  95. package/testing/for_EventScenario/when_appending_scoped_constraints/with_unproven_operations.spec.ts +1 -1
  96. package/testing/for_EventScenario/when_using_routed_builders/with_routing_options.spec.ts +116 -0
  97. package/testing/for_ReactorScenario/when_using_routed_builders/with_routing_options.spec.ts +88 -0
  98. package/testing/for_ReadModelScenario/when_seeding_with_options/with_route_validation.spec.ts +52 -0
  99. package/testing/singleAppendRoute.spec.ts +19 -0
  100. package/testing/singleAppendRoute.ts +33 -0
@@ -0,0 +1,19 @@
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 { chai, describe, it } from 'vitest';
5
+ import { singleAppendRoute } from './singleAppendRoute.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when single-append routing rejects unsupported options', () => {
10
+ it('should list only routing options when subject is not allowed', () => {
11
+ (() => singleAppendRoute({ subject: 'person-a' }, 'SeededEvent'))
12
+ .should.throw('Only sourceType, streamType, streamId options are supported for single append.');
13
+ });
14
+
15
+ it('should include subject in the allowed options for single append', () => {
16
+ (() => singleAppendRoute({ tags: [] }, 'AppendedEvent', undefined, true))
17
+ .should.throw('Only sourceType, streamType, streamId, subject options are supported for single append.');
18
+ });
19
+ });
@@ -0,0 +1,33 @@
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 type { AppendOptions } from '../eventSequences/AppendOptions.js';
5
+ import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
6
+
7
+ /** The fixture-proven single-append route boundary, shared with read-model setup. */
8
+ export function singleAppendRoute(options: AppendOptions | undefined, artifact: string,
9
+ unsupported = (operation: string, artifact: string, reason: string) => new UnsupportedEventSequenceOperation(operation, artifact, reason),
10
+ allowSubject = false
11
+ ): { sourceType: string; streamType: string; streamId: string } {
12
+ if (options !== undefined && (!options || typeof options !== 'object' || Array.isArray(options))) {
13
+ throw unsupported('append.options', artifact, 'Append options must be an object.');
14
+ }
15
+ const allowed = ['sourceType', 'streamType', 'streamId', ...(allowSubject ? ['subject'] : [])];
16
+ if (options && (Reflect.ownKeys(options).some(key => !allowed.includes(String(key))) ||
17
+ options.correlationId !== undefined || (!allowSubject && options.subject !== undefined) || options.occurred !== undefined ||
18
+ options.eventSourceId !== undefined || options.concurrencyScope !== undefined || options.tags !== undefined ||
19
+ options.concurrencyScopes !== undefined)) {
20
+ throw unsupported('append.options', artifact, `Only ${allowed.join(', ')} options are supported for single append.`);
21
+ }
22
+ if (options?.subject !== undefined && options.subject !== null && typeof options.subject !== 'string') {
23
+ throw unsupported('append.subject', artifact, 'Subject must be a string.');
24
+ }
25
+ const route = { sourceType: options?.sourceType, streamType: options?.streamType, streamId: options?.streamId };
26
+ for (const [name, value] of Object.entries(route)) {
27
+ if (value !== undefined && (typeof value !== 'string' || !/^[A-Za-z0-9_-]*$/.test(value))) {
28
+ throw unsupported(`append.${name}`, String(value), 'Only simple routing identifiers or empty defaults are fixture-backed.');
29
+ }
30
+ }
31
+ // ts-proto omits empty strings; the append pipeline resolves omissions to these exact values.
32
+ return { sourceType: route.sourceType || 'Default', streamType: route.streamType || 'All', streamId: route.streamId || 'Default' };
33
+ }