@cratis/chronicle 6.70.0 → 6.70.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.
@@ -1 +1 @@
1
- {"version":3,"file":"MeasuredConstraintKeys.d.ts","sourceRoot":"","sources":["../../testing/MeasuredConstraintKeys.ts"],"names":[],"mappings":"AAaA,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAqC;AAG3F,KAAK,eAAe,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAAC;AAM1G,gFAAgF;AAChF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,EAC5F,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED,6FAA6F;AAC7F,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAE3E;AAED,uGAAuG;AACvG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAKzG"}
1
+ {"version":3,"file":"MeasuredConstraintKeys.d.ts","sourceRoot":"","sources":["../../testing/MeasuredConstraintKeys.ts"],"names":[],"mappings":"AAcA,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAqC;AAG3F,KAAK,eAAe,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAAC;AAM1G,gFAAgF;AAChF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,EAC5F,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED,6FAA6F;AAC7F,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAE3E;AAED,uGAAuG;AACvG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAKzG"}
@@ -1,9 +1,10 @@
1
1
  // Copyright (c) Cratis. All rights reserved.
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
  import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
4
- // constraints-field-key-measurements.json: exact characters and scalars, not a general Unicode/control range.
4
+ // constraints-field-key-measurements.json and constraints-case-sensitive-unicode.json: exact measured scalars,
5
+ // not general Unicode/control ranges; the latter adds only U+039B, U+03BB, U+0416, U+0436 and U+4E2D.
5
6
  // The unicode flag matches whole scalars, so lone or unmeasured surrogate combinations never match.
6
- const measuredText = /^[\x00\x01\x08-\x0a\x0c\x0d\x20-\x7e\u00c9\u00df\u00e9\u00f8\u0301\u4eac\u6771\u{10000}\u{10400}\u{1d11e}\u{1f600}\u{1f642}\u{20000}\u{10ffff}]*$/u;
7
+ const measuredText = /^[\x00\x01\x08-\x0a\x0c\x0d\x20-\x7e\u00c9\u00df\u00e9\u00f8\u0301\u039b\u03bb\u0416\u0436\u4e2d\u4eac\u6771\u{10000}\u{10400}\u{1d11e}\u{1f600}\u{1f642}\u{20000}\u{10ffff}]*$/u;
7
8
  const numericValues = {
8
9
  decimal: [0.1, -1.2345, 1.2345678901234567, 0.000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,IAAI,EACrE,4BAA4B,MAAM,2FAA2F,CAAC,CAAC;AACvI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/chronicle",
3
- "version": "6.70.0",
3
+ "version": "6.70.1",
4
4
  "description": "Event sourcing for TypeScript and Node.js — the idiomatic client for Cratis Chronicle, the open-source event-sourcing database",
5
5
  "author": "Cratis",
6
6
  "license": "MIT",
@@ -61,7 +61,7 @@ const fixtures = readdirSync(directory).filter(name => name.endsWith('.json') &&
61
61
  'constraints-event-type-siblings.json', 'constraints-composite.json',
62
62
  'constraints-ignore-casing.json', 'constraints-scopes.json', 'constraints-field-types.json', 'constraints-event-sequences.json',
63
63
  'constraints-field-combinations.json', 'constraints-removal-combinations.json', 'constraints-overlapping-definitions.json',
64
- 'constraints-fractional-field-types.json', 'constraints-fractional-collisions.json', 'constraints-field-key-measurements.json', 'constraints-ignore-casing-measurements.json'].includes(name)).map(name => ({
64
+ 'constraints-fractional-field-types.json', 'constraints-fractional-collisions.json', 'constraints-field-key-measurements.json', 'constraints-ignore-casing-measurements.json', 'constraints-case-sensitive-unicode.json'].includes(name)).map(name => ({
65
65
  name, fixture: JSON.parse(readFileSync(new URL(name, directory), 'utf8')) as Fixture
66
66
  }));
67
67
  const artifacts = { eventTypes: [OracleEventRecorded, AlternateRecorded, BoundaryRecorded], constraints: [] };
@@ -196,7 +196,7 @@ describe('when the fixture-bounded event sequence encounters unproven operations
196
196
  }
197
197
  for (const [name, value] of [
198
198
  ['DEL', '\u007f'], ['Japanese outside measured characters', '日本'], ['unmeasured control', '\u0002'],
199
- ['unmeasured emoji', '\u{1f601}'], ['lone high surrogate', '\ud83d'], ['reversed surrogate pair', '\ude00\ud83d'], ['Greek outside measured letters', 'λ']
199
+ ['unmeasured emoji', '\u{1f601}'], ['lone high surrogate', '\ud83d'], ['reversed surrogate pair', '\ude00\ud83d'], ['Greek outside measured letters', 'Ω']
200
200
  ] as const) {
201
201
  it(`should reject ${name} outside the fixture-backed content domain`, async () => {
202
202
  const subject = scenario();
@@ -3,9 +3,10 @@
3
3
 
4
4
  import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
5
5
 
6
- // constraints-field-key-measurements.json: exact characters and scalars, not a general Unicode/control range.
6
+ // constraints-field-key-measurements.json and constraints-case-sensitive-unicode.json: exact measured scalars,
7
+ // not general Unicode/control ranges; the latter adds only U+039B, U+03BB, U+0416, U+0436 and U+4E2D.
7
8
  // The unicode flag matches whole scalars, so lone or unmeasured surrogate combinations never match.
8
- const measuredText = /^[\x00\x01\x08-\x0a\x0c\x0d\x20-\x7e\u00c9\u00df\u00e9\u00f8\u0301\u4eac\u6771\u{10000}\u{10400}\u{1d11e}\u{1f600}\u{1f642}\u{20000}\u{10ffff}]*$/u;
9
+ const measuredText = /^[\x00\x01\x08-\x0a\x0c\x0d\x20-\x7e\u00c9\u00df\u00e9\u00f8\u0301\u039b\u03bb\u0416\u0436\u4e2d\u4eac\u6771\u{10000}\u{10400}\u{1d11e}\u{1f600}\u{1f642}\u{20000}\u{10ffff}]*$/u;
9
10
  const numericValues: Readonly<Record<string, readonly number[]>> = {
10
11
  decimal: [0.1, -1.2345, 1.2345678901234567, 0.000001],
11
12
  float: [0.1, -1.2345, 1.2345679]
@@ -0,0 +1,188 @@
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 { readFileSync } from 'node:fs';
5
+ import type { Constructor } from '@cratis/fundamentals';
6
+ import { chai, describe, it, vi, type Assertion } from 'vitest';
7
+ import type { AppendResult } from '../../../eventSequences/AppendResult.js';
8
+ import { constraint } from '../../../events/constraints/constraint.js';
9
+ import { ConstraintBuilder } from '../../../events/constraints/ConstraintBuilder.js';
10
+ import type { IConstraintBuilder } from '../../../events/constraints/IConstraintBuilder.js';
11
+ import { EventScenario, UnsupportedEventSequenceOperation } from '../../index.js';
12
+ import { InProcessConstraints } from '../../InProcessConstraints.js';
13
+ import { claimOf } from '../../ConstraintKey.js';
14
+
15
+ chai.should();
16
+ const should = (value: unknown): Assertion => (value as { should: Assertion }).should;
17
+ type TextEvent = { key: string };
18
+ type PairEvent = TextEvent & { other: string };
19
+ type Types = { text: Constructor<TextEvent>; pair: Constructor<PairEvent>; sibling: Constructor<TextEvent> };
20
+ type Shape = 'plain' | 'scoped' | 'ignoreCasing' | 'composite' | 'removable' | 'overlapping' | 'shared' | 'multiple';
21
+ type Operation = { mode: string; events: Array<{ source: string; content: string }> };
22
+ type History = { source: string; sequence: string; content: Record<string, unknown>; hash: string | undefined };
23
+ type WireViolation = { ConstraintName: string; Message: string; Details: Record<string, string> };
24
+ type Outcome = { success: boolean; sequences: string[]; wireViolations: WireViolation[]; history: History[]; next: string };
25
+ type Observation = { input: string; utf8Sha256: string; scalars: number[] };
26
+ const fixture = JSON.parse(readFileSync(new URL('../../fixtures/constraints-case-sensitive-unicode.json', import.meta.url), 'utf8')) as {
27
+ fieldConstraintCases: Array<{ name: string; localSteps: number; operations: Operation[] }>;
28
+ expected: Array<{ steps: Outcome[]; textObservations: Observation[] }>;
29
+ };
30
+ const candidates = ['Λ', 'λ', 'Ж', 'ж', '中'];
31
+ // Exact neighbours, never ranges. Ω also remains outside the measured payload allowlist.
32
+ const unmeasured = ['Κ', 'μ', 'З', 'з', '丮', 'Ω', '\u{1f601}', '\u{10001}', '\u0002', '\ud83d', '\ude00', '\ude00\ud83d'];
33
+
34
+ function define(builder: IConstraintBuilder, types: Types, shape: Shape, secondary = false): void {
35
+ if (shape === 'scoped') builder.perEventSourceType();
36
+ builder.unique(key => {
37
+ if (shape === 'composite') key.on(types.pair, event => event.key, event => event.other);
38
+ else if (shape === 'overlapping' && secondary) key.on(types.pair, event => event.other);
39
+ else if (shape === 'overlapping') key.on(types.pair, event => event.key);
40
+ else key.on(types.text, event => event.key);
41
+ if (shape === 'shared') key.on(types.sibling, event => event.key);
42
+ if (shape === 'ignoreCasing') key.ignoreCasing();
43
+ if (shape === 'removable') key.removedWith(types.sibling);
44
+ });
45
+ }
46
+
47
+ function definition(types: Types, shape: Shape, name = 'OracleFieldKey'): Constructor {
48
+ class Definition { define(builder: IConstraintBuilder) { define(builder, types, shape, name === 'OtherKey'); } }
49
+ constraint(name)(Definition);
50
+ return Definition;
51
+ }
52
+
53
+ function scenarioFor(types: Types, shape: Shape = 'plain'): EventScenario {
54
+ const constraints = [definition(types, shape)];
55
+ if (shape === 'overlapping') constraints.push(definition(types, shape, 'OtherKey'));
56
+ if (shape === 'multiple') constraints.push(definition({ ...types, text: types.sibling }, 'plain', 'OtherKey'));
57
+ return new EventScenario({ artifacts: { eventTypes: Object.values(types), constraints } });
58
+ }
59
+
60
+ function eventFor(types: Types, key: string, shape: Shape = 'plain'): TextEvent {
61
+ if (shape === 'composite') return Object.assign(new types.pair(), { key, other: 'x' });
62
+ if (shape === 'overlapping') return Object.assign(new types.pair(), { key, other: key });
63
+ return Object.assign(new types.text(), { key });
64
+ }
65
+
66
+ function historyOf(scenario: EventScenario): History[] {
67
+ return scenario.appendedEvents.map(event => ({ source: event.context.eventSourceId,
68
+ sequence: event.context.sequenceNumber.toString(), content: event.content, hash: event.context.hash }));
69
+ }
70
+
71
+ async function append(scenario: EventScenario, types: Types, operation: Operation): Promise<AppendResult[]> {
72
+ const events = operation.events.map(entry => ({ eventSourceId: entry.source, event: Object.assign(new types.text(), JSON.parse(entry.content)) }));
73
+ return operation.mode === 'single' ? [await scenario.append(events[0].eventSourceId, events[0].event)] : scenario.appendMany(events);
74
+ }
75
+
76
+ function replay(types: Types, index: number): void {
77
+ const test = fixture.fieldConstraintCases[index];
78
+ it(`should replay every ${test.name} operation with content, hashes, raw and public violations and rollback`, async () => {
79
+ const validate = vi.spyOn(InProcessConstraints.prototype, 'validate');
80
+ try {
81
+ const scenario = scenarioFor(types);
82
+ should(test.localSteps).equal(test.operations.length);
83
+ should(fixture.expected[index].steps).have.lengthOf(test.operations.length);
84
+ for (const [step, operation] of test.operations.entries()) {
85
+ const results = await append(scenario, types, operation);
86
+ const expected = fixture.expected[index].steps[step];
87
+ should(results.every(result => result.isSuccess === expected.success)).equal(true);
88
+ should(results.map(result => result.sequenceNumber.value.toString())).deep.equal(
89
+ expected.success ? expected.sequences : results.map(() => '0'));
90
+ const raw = validate.mock.results.at(-1)!.value as ReturnType<InProcessConstraints['validate']>;
91
+ should(raw.map(violation => ({ ...violation, SequenceNumber: violation.SequenceNumber.toString() }))).deep.equal(expected.wireViolations);
92
+ for (const result of results) {
93
+ should(result.constraintViolations.map(item => ({ id: item.constraintId, message: item.message, details: item.details })))
94
+ .deep.equal(expected.wireViolations.map(item => ({ id: item.ConstraintName, message: item.Message, details: item.Details })));
95
+ }
96
+ should(historyOf(scenario)).deep.equal(expected.history);
97
+ should((await scenario.eventSequence.getNextSequenceNumber()).value.toString()).equal(expected.next);
98
+ }
99
+ } finally { validate.mockRestore(); }
100
+ });
101
+ it(`should preserve each ${test.name} input's exact scalar sequence and kernel UTF-8 key hash`, async () => {
102
+ const observations = fixture.expected[index].textObservations;
103
+ should(observations.length).greaterThan(0);
104
+ const builder = new ConstraintBuilder('OracleFieldKey');
105
+ define(builder, types, 'plain');
106
+ for (const observation of observations) {
107
+ const scenario = scenarioFor(types);
108
+ await scenario.append('A', eventFor(types, observation.input));
109
+ const event = scenario.appendedEvents[0];
110
+ should(Array.from(event.content.key as string, scalar => scalar.codePointAt(0)!)).deep.equal(observation.scalars);
111
+ should(claimOf('OracleFieldKey', builder.capture, event, {
112
+ isolated: true, schema: { type: 'object', properties: { key: { type: 'string' } } }
113
+ })!.key).equal(observation.utf8Sha256);
114
+ }
115
+ });
116
+ }
117
+
118
+ async function rejected(pending: Promise<unknown>): Promise<void> {
119
+ const error: unknown = await pending.then(() => undefined, error => error);
120
+ should(error).instanceOf(UnsupportedEventSequenceOperation);
121
+ should(String(error)).match(/append(?:Many)?\.content|artifacts\.constraints/);
122
+ }
123
+
124
+ function rejectText(types: Types, value: string, shape: Shape = 'plain'): void {
125
+ const good = (key: string): TextEvent => eventFor(types, key, shape);
126
+ for (const mode of ['single', 'batch']) {
127
+ it(`should reject ${JSON.stringify(value)} atomically in a ${shape} ${mode} append without leaking claims`, async () => {
128
+ const scenario = scenarioFor(types, shape);
129
+ await scenario.append('A', good('safe'));
130
+ const history = historyOf(scenario);
131
+ const results = [...scenario.results];
132
+ await rejected(mode === 'single' ? scenario.append('C', good(value))
133
+ : scenario.appendMany([{ eventSourceId: 'B', event: good('fresh') }, { eventSourceId: 'C', event: good(value) }]));
134
+ should(historyOf(scenario)).deep.equal(history);
135
+ should(scenario.results).deep.equal(results);
136
+ should((await scenario.eventSequence.getNextSequenceNumber()).value).equal(1n);
137
+ should((await scenario.append('B', good('fresh'))).isSuccess).equal(true);
138
+ should((await scenario.append('C', good('safe'))).constraintViolations.length).greaterThan(0);
139
+ });
140
+ }
141
+ it(`should reject ${JSON.stringify(value)} atomically in ${shape} given setup and leave its valid key claimable`, async () => {
142
+ const scenario = scenarioFor(types, shape);
143
+ await rejected(scenario.given.forEventSource('A').events(good('safe'), good(value)));
144
+ should(scenario.appendedEvents).have.lengthOf(0);
145
+ should(scenario.results).have.lengthOf(0);
146
+ should((await scenario.eventSequence.getNextSequenceNumber()).value).equal(0n);
147
+ should((await scenario.append('B', good('safe'))).isSuccess).equal(true);
148
+ });
149
+ }
150
+
151
+ function payloads(types: Types): void {
152
+ for (const [index, value] of candidates.entries()) {
153
+ it(`should round-trip unconstrained ${value} payload content and its oracle-measured hash`, async () => {
154
+ const scenario = new EventScenario({ artifacts: { eventTypes: [types.text] }, constraints: 'disabled' });
155
+ await scenario.append('A', eventFor(types, value));
156
+ should(historyOf(scenario)).deep.equal(fixture.expected[index].steps[0].history);
157
+ });
158
+ }
159
+ for (const value of unmeasured) {
160
+ it(`should still reject unconstrained unmeasured ${JSON.stringify(value)} payloads`, async () => {
161
+ const scenario = new EventScenario({ artifacts: { eventTypes: [types.text] }, constraints: 'disabled' });
162
+ await rejected(scenario.append('A', eventFor(types, value)));
163
+ should(scenario.appendedEvents).have.lengthOf(0);
164
+ should(scenario.results).have.lengthOf(0);
165
+ should((await scenario.eventSequence.getNextSequenceNumber()).value).equal(0n);
166
+ });
167
+ }
168
+ }
169
+
170
+ export function caseSensitiveUnicode(types: Types): void {
171
+ describe('when replaying case-sensitive Unicode measurements', () => {
172
+ should(fixture.fieldConstraintCases.length).greaterThan(0);
173
+ should(fixture.expected).have.lengthOf(fixture.fieldConstraintCases.length);
174
+ for (const index of fixture.fieldConstraintCases.keys()) replay(types, index);
175
+ });
176
+ describe('when keys contain unmeasured scalars or malformed surrogates', () => {
177
+ for (const value of unmeasured) {
178
+ rejectText(types, value);
179
+ rejectText(types, `Aλ${value}中z`);
180
+ }
181
+ });
182
+ describe('when measured scalars are used outside the isolated case-sensitive single-property shape', () => {
183
+ for (const shape of ['ignoreCasing', 'scoped', 'composite', 'removable', 'overlapping', 'shared', 'multiple'] as const) {
184
+ for (const value of candidates) rejectText(types, value, shape);
185
+ }
186
+ });
187
+ describe('when plain-string payloads use the shared measured alphabet', () => payloads(types));
188
+ }
@@ -0,0 +1,16 @@
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 { field } from '@cratis/fundamentals';
6
+ import { eventType } from '../../../events/eventTypeDecorator.js';
7
+ import { caseSensitiveUnicode } from './case_sensitive_unicode.fixture.js';
8
+
9
+ class TextClaimed { @field(String) key = ''; }
10
+ eventType('OracleFieldText')(TextClaimed);
11
+ class PairClaimed { @field(String) key = ''; @field(String) other = ''; }
12
+ eventType('OracleUnicodePair')(PairClaimed);
13
+ class SiblingClaimed { @field(String) key = ''; }
14
+ eventType('OracleUnicodeSibling')(SiblingClaimed);
15
+
16
+ caseSensitiveUnicode({ text: TextClaimed, pair: PairClaimed, sibling: SiblingClaimed });
@@ -0,0 +1,15 @@
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 { field } from '@cratis/fundamentals';
5
+ import { eventType } from '../../../events/eventTypeDecorator.js';
6
+ import { caseSensitiveUnicode } from './case_sensitive_unicode.fixture.js';
7
+
8
+ @eventType('OracleFieldText')
9
+ class TextClaimed { @field(String) key = ''; }
10
+ @eventType('OracleUnicodePair')
11
+ class PairClaimed { @field(String) key = ''; @field(String) other = ''; }
12
+ @eventType('OracleUnicodeSibling')
13
+ class SiblingClaimed { @field(String) key = ''; }
14
+
15
+ caseSensitiveUnicode({ text: TextClaimed, pair: PairClaimed, sibling: SiblingClaimed });
@@ -104,7 +104,7 @@ export function fieldKeyMeasurements(types: Types): void {
104
104
 
105
105
  function rejectUnmeasured(types: Types): void {
106
106
  for (const [type, values] of [
107
- [types.text, ['\u{1f601}', '\u{10001}', '\ud83d', '\ude00', '\ude00\ud83d', '\ud83dx', 'λ', '\u0002']],
107
+ [types.text, ['\u{1f601}', '\u{10001}', '\ud83d', '\ude00', '\ude00\ud83d', '\ud83dx', 'μ', '\u0002']],
108
108
  [types.decimal, [1e-7, 1e21, 1.5]],
109
109
  [types.float, [1.23456789, 1e-7, 1e21, 0.000001, 1.5]]
110
110
  ] as const) {