@cratis/chronicle 6.67.6 → 6.68.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 (61) hide show
  1. package/ChronicleClient.ts +14 -1
  2. package/ChronicleOptions.ts +12 -0
  3. package/EventStoreNamespaceResolver.ts +19 -0
  4. package/dist/ChronicleClient.d.ts +1 -0
  5. package/dist/ChronicleClient.d.ts.map +1 -1
  6. package/dist/ChronicleClient.js +14 -1
  7. package/dist/ChronicleClient.js.map +1 -1
  8. package/dist/ChronicleOptions.d.ts +8 -0
  9. package/dist/ChronicleOptions.d.ts.map +1 -1
  10. package/dist/ChronicleOptions.js +8 -0
  11. package/dist/ChronicleOptions.js.map +1 -1
  12. package/dist/EventStoreNamespaceResolver.d.ts +16 -0
  13. package/dist/EventStoreNamespaceResolver.d.ts.map +1 -0
  14. package/dist/EventStoreNamespaceResolver.js +4 -0
  15. package/dist/EventStoreNamespaceResolver.js.map +1 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/testing/ConstraintKey.d.ts.map +1 -1
  20. package/dist/testing/ConstraintKey.js +24 -14
  21. package/dist/testing/ConstraintKey.js.map +1 -1
  22. package/dist/testing/EventScenario.d.ts.map +1 -1
  23. package/dist/testing/EventScenario.js +100 -67
  24. package/dist/testing/EventScenario.js.map +1 -1
  25. package/dist/testing/EventTypeConstraintClaims.d.ts +15 -0
  26. package/dist/testing/EventTypeConstraintClaims.d.ts.map +1 -0
  27. package/dist/testing/EventTypeConstraintClaims.js +66 -0
  28. package/dist/testing/EventTypeConstraintClaims.js.map +1 -0
  29. package/dist/testing/InProcessConstraints.d.ts.map +1 -1
  30. package/dist/testing/InProcessConstraints.js +8 -91
  31. package/dist/testing/InProcessConstraints.js.map +1 -1
  32. package/dist/testing/InProcessEventPayload.d.ts.map +1 -1
  33. package/dist/testing/InProcessEventPayload.js +2 -1
  34. package/dist/testing/InProcessEventPayload.js.map +1 -1
  35. package/dist/testing/KernelTextHash.d.ts +7 -0
  36. package/dist/testing/KernelTextHash.d.ts.map +1 -0
  37. package/dist/testing/KernelTextHash.js +15 -0
  38. package/dist/testing/KernelTextHash.js.map +1 -0
  39. package/dist/testing/MeasuredConstraintKeys.d.ts.map +1 -1
  40. package/dist/testing/MeasuredConstraintKeys.js +3 -2
  41. package/dist/testing/MeasuredConstraintKeys.js.map +1 -1
  42. package/dist/testing/PropertyConstraintClaims.d.ts +17 -0
  43. package/dist/testing/PropertyConstraintClaims.d.ts.map +1 -0
  44. package/dist/testing/PropertyConstraintClaims.js +69 -0
  45. package/dist/testing/PropertyConstraintClaims.js.map +1 -0
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/for_ChronicleClient/when_resolving_a_namespace.spec.ts +198 -0
  48. package/index.ts +1 -0
  49. package/package.json +1 -1
  50. package/testing/ConstraintKey.ts +26 -11
  51. package/testing/EventScenario.rejections.spec.ts +1 -1
  52. package/testing/EventScenario.ts +120 -66
  53. package/testing/EventTypeConstraintClaims.ts +68 -0
  54. package/testing/InProcessConstraints.ts +7 -86
  55. package/testing/InProcessEventPayload.ts +2 -1
  56. package/testing/KernelTextHash.ts +17 -0
  57. package/testing/MeasuredConstraintKeys.ts +3 -2
  58. package/testing/PropertyConstraintClaims.ts +75 -0
  59. package/testing/for_EventScenario/when_appending_astral_text/with_plain_text.spec.ts +34 -0
  60. package/testing/for_EventScenario/when_appending_field_types/field_key_measurements.fixture.ts +4 -5
  61. package/testing/for_KernelTextHash/when_escaping_json/with_supplementary_characters.spec.ts +28 -0
@@ -8,13 +8,12 @@ import { resolveConstraintMessage } from '../events/constraints/Constraints.js';
8
8
  import type { ConstraintViolation } from '../eventSequences/ConstraintViolation.js';
9
9
  import type { JsonSchema } from '../schemas/JsonSchema.js';
10
10
  import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
11
- import { eventTypeScopeKey, propertyScopeKey, scopeIndex } from './ConstraintScope.js';
12
11
  import { supportsPropertyOverlap } from './PropertyDefinitionSupport.js';
13
- import { claimOf } from './ConstraintKey.js';
12
+ import { PropertyConstraintClaims } from './PropertyConstraintClaims.js';
13
+ import { EventTypeConstraintClaims } from './EventTypeConstraintClaims.js';
14
14
 
15
15
  export type WireConstraintViolation = ContractsConstraintViolation;
16
16
 
17
- const unavailable = '18446744073709551615';
18
17
  /** Narrow, fixture-backed constraint validation over serialized event snapshots. */
19
18
  export class InProcessConstraints {
20
19
  private readonly _constrainedProperties = new Map<string, Set<string>>();
@@ -124,95 +123,17 @@ export class InProcessConstraints {
124
123
  /** Validate against committed history and all earlier entries of this append, without changing state. */
125
124
  validate(history: readonly AppendedEvent[], incoming: readonly AppendedEvent[]): WireConstraintViolation[] {
126
125
  const violations: WireConstraintViolation[] = [];
127
- // Durable ownership is one claim per source, not one entry per historical value.
128
- // Rebuild it from committed history; batch claims below remain independent and are never released.
129
- const owners = new Map<string, Map<string, Map<string, { key: string; sequence: string }>>>();
130
- for (const [name, definition] of this._definitions) {
131
- if (!definition.uniqueConstraint) continue;
132
- const unique = definition.uniqueConstraint;
133
- const removals = new Set([unique.removedWithEventTypeId, ...(unique.removedWithEventTypeIds ?? [])]);
134
- for (const prior of history) {
135
- const type = prior.eventType.id.value;
136
- const source = prior.context.eventSourceId;
137
- const claims = scopeIndex(owners, name, propertyScopeKey(definition.scope, prior.context),
138
- () => new Map<string, { key: string; sequence: string }>());
139
- if (removals.has(type)) {
140
- claims.delete(source);
141
- continue;
142
- }
143
- const properties = unique.eventDefinitions.find(entry => entry.eventTypeId === type)?.properties;
144
- if (properties === undefined) continue;
145
- claims.set(source, { key: claimOf(name, definition, prior, { schema: this._schemas.get(type), isolated: this._definitions.size === 1 })!.key,
146
- sequence: prior.context.sequenceNumber.toString() });
147
- }
148
- }
149
- const stagedKeys = new Map<string, Map<string, Map<string, string>>>();
150
- const stagedCycles = new Map<string, Map<string, Map<string, 'open' | 'released'>>>();
126
+ const propertyClaims = new PropertyConstraintClaims(this._definitions, this._schemas, history);
127
+ const eventTypeClaims = new EventTypeConstraintClaims(this._definitions, history);
151
128
  for (const event of incoming) {
152
- const type = event.eventType.id.value;
153
- const source = event.context.eventSourceId;
154
129
  const violationCount = violations.length;
155
130
  for (const [name, definition] of this._definitions) {
156
- const claim = definition.uniqueConstraint && claimOf(name, definition, event, { schema: this._schemas.get(type), isolated: this._definitions.size === 1 });
157
- if (claim) {
158
- const key = claim.key;
159
- const scope = propertyScopeKey(definition.scope, event.context);
160
- const durableClaims = owners.get(name)?.get(scope);
161
- const existing = [...(durableClaims?.entries() ?? [])].find(([, claim]) => claim.key === key);
162
- const batchClaims = scopeIndex(stagedKeys, name, scope, () => new Map<string, string>());
163
- const batchOwner = batchClaims.get(key);
164
- if (existing && existing[0] !== source || batchOwner !== undefined && batchOwner !== source) {
165
- // One violation per declared property, in declared order, each with its own original value.
166
- const sequence = existing?.[1].sequence ?? unavailable;
167
- for (const { property, raw } of claim.parts) {
168
- violations.push({ EventTypeId: type, SequenceNumber: BigInt(sequence), ConstraintType: 1,
169
- ConstraintName: name,
170
- Message: `Event '${type}' on member '${property}' violated a unique constraint on sequence number ${sequence}`,
171
- Details: { PropertyName: property, PropertyValue: raw } });
172
- }
173
- } else {
174
- batchClaims.set(key, source);
175
- }
176
- }
177
- const uniqueType = definition.uniqueEventType;
178
- if (uniqueType && (uniqueType.eventTypeIds ?? [uniqueType.eventTypeId]).includes(type)) {
179
- const covered = uniqueType.eventTypeIds ?? [uniqueType.eventTypeId];
180
- const removals = uniqueType.removedWithEventTypeIds ?? [];
181
- // Durable answer: the earliest covered event after the latest removal for this source.
182
- const scope = eventTypeScopeKey(definition.scope, event.context);
183
- let first: AppendedEvent | undefined;
184
- for (const prior of history) {
185
- if (prior.context.eventSourceId !== source || eventTypeScopeKey(definition.scope, prior.context) !== scope) continue;
186
- const priorType = prior.eventType.id.value;
187
- if (removals.includes(priorType)) first = undefined;
188
- else if (!first && covered.includes(priorType)) first = prior;
189
- }
190
- const cycles = scopeIndex(stagedCycles, name, scope, () => new Map<string, 'open' | 'released'>());
191
- const state = cycles.get(source);
192
- // A cycle state recorded earlier in this append overrides durable history.
193
- if (state === 'open' || state === undefined && first) {
194
- // Durable storage supplies the sequence even when a staged claim causes rejection.
195
- const sequence = first?.context.sequenceNumber.toString() ?? unavailable;
196
- violations.push({ EventTypeId: type, SequenceNumber: BigInt(sequence), ConstraintType: 2,
197
- ConstraintName: name,
198
- Message: `Event '${type}' violated a unique event type constraint on sequence number ${sequence}`,
199
- Details: {} });
200
- } else {
201
- cycles.set(source, 'open');
202
- }
203
- }
131
+ violations.push(...propertyClaims.validate(name, definition, event));
132
+ violations.push(...eventTypeClaims.validate(name, definition, event));
204
133
  }
205
134
  // Kernel batch observers release a cycle only after the entire event validates.
206
135
  // A covered-and-removal event first attempts its claim, then releases it.
207
- if (violations.length === violationCount) {
208
- for (const [name, definition] of this._definitions) {
209
- if (definition.uniqueEventType?.removedWithEventTypeIds?.includes(type)) {
210
- const cycles = scopeIndex(stagedCycles, name, eventTypeScopeKey(definition.scope, event.context),
211
- () => new Map<string, 'open' | 'released'>());
212
- cycles.set(source, 'released');
213
- }
214
- }
215
- }
136
+ if (violations.length === violationCount) eventTypeClaims.release(event);
216
137
  }
217
138
  return violations;
218
139
  }
@@ -11,6 +11,7 @@ import { Tag } from '../events/Tag.js';
11
11
  import { Identity } from '../identity/Identity.js';
12
12
  import type { JsonSchema } from '../schemas/JsonSchema.js';
13
13
  import { matchesEventField } from './EventFieldSchema.js';
14
+ import { kernelEscapedJson } from './KernelTextHash.js';
14
15
  import { isMeasuredText } from './MeasuredConstraintKeys.js';
15
16
  import type { InProcessConstraints } from './InProcessConstraints.js';
16
17
  import type { InProcessEventSequenceEnvironment } from './InProcessEventSequenceEnvironment.js';
@@ -32,7 +33,7 @@ export class InProcessEventPayload {
32
33
 
33
34
  hash(typeId: string, source: string, content: Record<string, unknown>): string {
34
35
  const canonical = Object.fromEntries(Object.entries(content).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
35
- return createHash('sha256').update(`${typeId}|${source}|${JSON.stringify(canonical)}`).digest('base64');
36
+ return createHash('sha256').update(`${typeId}|${source}|${kernelEscapedJson(JSON.stringify(canonical))}`).digest('base64');
36
37
  }
37
38
 
38
39
  snapshot(event: AppendedEvent): AppendedEvent {
@@ -0,0 +1,17 @@
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
+ const surrogatePair = /[\ud800-\udbff][\udc00-\udfff]/g;
5
+
6
+ function escapeUnit(unit: string): string {
7
+ return `\\u${unit.charCodeAt(0).toString(16).toUpperCase().padStart(4, '0')}`;
8
+ }
9
+
10
+ /**
11
+ * The kernel hashes JSON written with the relaxed encoder, which escapes every supplementary-plane character
12
+ * as two uppercase UTF-16 escapes while keeping measured BMP characters literal. Only actual surrogate pairs are
13
+ * rewritten, so literal backslash-u text and the stored content are untouched.
14
+ */
15
+ export function kernelEscapedJson(json: string): string {
16
+ return json.replace(surrogatePair, pair => escapeUnit(pair[0]) + escapeUnit(pair[1]));
17
+ }
@@ -3,8 +3,9 @@
3
3
 
4
4
  import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
5
5
 
6
- // constraints-field-key-measurements.json: exact characters, not a general Unicode/control range.
7
- const measuredText = /^[\x00\x01\x08-\x0a\x0c\x0d\x20-\x7e\u00c9\u00df\u00e9\u00f8\u0301\u4eac\u6771]*$/;
6
+ // constraints-field-key-measurements.json: exact characters and scalars, not a general Unicode/control range.
7
+ // 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;
8
9
  const numericValues: Readonly<Record<string, readonly number[]>> = {
9
10
  decimal: [0.1, -1.2345, 1.2345678901234567, 0.000001],
10
11
  float: [0.1, -1.2345, 1.2345679]
@@ -0,0 +1,75 @@
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 { ConstraintViolation } from '@cratis/chronicle.contracts';
5
+ import type { AppendedEvent } from '../events/AppendedEvent.js';
6
+ import type { ConstraintCapture } from '../events/constraints/ConstraintBuilder.js';
7
+ import type { JsonSchema } from '../schemas/JsonSchema.js';
8
+ import { claimOf } from './ConstraintKey.js';
9
+ import { propertyScopeKey, scopeIndex } from './ConstraintScope.js';
10
+
11
+ const unavailable = '18446744073709551615';
12
+
13
+ /** Rebuilds durable property ownership and keeps append-local claims independent. */
14
+ export class PropertyConstraintClaims {
15
+ private readonly _owners = new Map<string, Map<string, Map<string, { key: string; sequence: string }>>>();
16
+ private readonly _stagedKeys = new Map<string, Map<string, Map<string, string>>>();
17
+
18
+ constructor(private readonly _definitions: ReadonlyMap<string, ConstraintCapture>,
19
+ private readonly _schemas: ReadonlyMap<string, JsonSchema>, history: readonly AppendedEvent[]) {
20
+ // Durable ownership is one claim per source, not one entry per historical value.
21
+ // Batch claims remain independent and are never released.
22
+ for (const [name, definition] of _definitions) {
23
+ if (definition.uniqueConstraint) this.replay(name, definition, history);
24
+ }
25
+ }
26
+
27
+ validate(name: string, definition: ConstraintCapture, event: AppendedEvent): ConstraintViolation[] {
28
+ const type = event.eventType.id.value;
29
+ const source = event.context.eventSourceId;
30
+ const claim = definition.uniqueConstraint && claimOf(name, definition, event, this.keyOptions(type));
31
+ if (!claim) return [];
32
+ const key = claim.key;
33
+ const scope = propertyScopeKey(definition.scope, event.context);
34
+ const durableClaims = this._owners.get(name)?.get(scope);
35
+ const existing = [...(durableClaims?.entries() ?? [])].find(([, claim]) => claim.key === key);
36
+ const batchClaims = scopeIndex(this._stagedKeys, name, scope, () => new Map<string, string>());
37
+ if (this.isOtherOwner(existing?.[0], source) || this.isOtherOwner(batchClaims.get(key), source)) {
38
+ // One violation per declared property, in declared order, each with its own original value.
39
+ const sequence = existing?.[1].sequence ?? unavailable;
40
+ return claim.parts.map(({ property, raw }) => ({ EventTypeId: type, SequenceNumber: BigInt(sequence), ConstraintType: 1,
41
+ ConstraintName: name,
42
+ Message: `Event '${type}' on member '${property}' violated a unique constraint on sequence number ${sequence}`,
43
+ Details: { PropertyName: property, PropertyValue: raw } }));
44
+ }
45
+ batchClaims.set(key, source);
46
+ return [];
47
+ }
48
+
49
+ private replay(name: string, definition: ConstraintCapture, history: readonly AppendedEvent[]): void {
50
+ const unique = definition.uniqueConstraint!;
51
+ const removals = new Set([unique.removedWithEventTypeId, ...(unique.removedWithEventTypeIds ?? [])]);
52
+ for (const prior of history) {
53
+ const type = prior.eventType.id.value;
54
+ const source = prior.context.eventSourceId;
55
+ const claims = scopeIndex(this._owners, name, propertyScopeKey(definition.scope, prior.context),
56
+ () => new Map<string, { key: string; sequence: string }>());
57
+ if (removals.has(type)) {
58
+ claims.delete(source);
59
+ continue;
60
+ }
61
+ const properties = unique.eventDefinitions.find(entry => entry.eventTypeId === type)?.properties;
62
+ if (properties === undefined) continue;
63
+ claims.set(source, { key: claimOf(name, definition, prior, this.keyOptions(type))!.key,
64
+ sequence: prior.context.sequenceNumber.toString() });
65
+ }
66
+ }
67
+
68
+ private keyOptions(type: string) {
69
+ return { schema: this._schemas.get(type), isolated: this._definitions.size === 1 };
70
+ }
71
+
72
+ private isOtherOwner(owner: string | undefined, source: string): boolean {
73
+ return owner !== undefined && owner !== source;
74
+ }
75
+ }
@@ -0,0 +1,34 @@
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 { createHash } from 'node:crypto';
6
+ import { chai, describe, it } from 'vitest';
7
+ import { field } from '@cratis/fundamentals';
8
+ import { eventType } from '../../../events/eventTypeDecorator.js';
9
+ import { EventScenario } from '../../index.js';
10
+
11
+ chai.should();
12
+
13
+ class Noted {
14
+ @field(String) name = '';
15
+ }
16
+ eventType('AstralNoted')(Noted);
17
+
18
+ describe('when appending a plain string with a supplementary character', () => {
19
+ it('should keep the content literal and hash the kernel-escaped JSON', async () => {
20
+ const scenario = new EventScenario({ artifacts: { eventTypes: [Noted] }, constraints: 'disabled' });
21
+ const result = await scenario.append('A', Object.assign(new Noted(), { name: 'a\u{1f600}\u{10ffff}' }));
22
+ result.isSuccess.should.equal(true);
23
+ scenario.appendedEvents[0].content.should.deep.equal({ name: 'a\u{1f600}\u{10ffff}' });
24
+ scenario.appendedEvents[0].context.hash.should.equal(createHash('sha256')
25
+ .update('AstralNoted|A|{"name":"a\\uD83D\\uDE00\\uDBFF\\uDFFF"}').digest('base64'));
26
+ });
27
+
28
+ it('should reject an unmeasured supplementary character', async () => {
29
+ const scenario = new EventScenario({ artifacts: { eventTypes: [Noted] }, constraints: 'disabled' });
30
+ const error = await scenario.append('A', Object.assign(new Noted(), { name: '\u{1f601}' })).then(() => undefined, caught => caught);
31
+ (error !== undefined).should.equal(true);
32
+ scenario.appendedEvents.should.have.lengthOf(0);
33
+ });
34
+ });
@@ -93,7 +93,7 @@ export function fieldKeyMeasurements(types: Types): void {
93
93
  const metadata = getEventTypeMetadata(type)!;
94
94
  metadata.schema.properties!.key = fixture.fieldSchemas[metadata.eventType.id.value];
95
95
  }
96
- // Replay complete supported prefixes; later numeric and emoji vectors remain kernel-only measurements.
96
+ // Replay complete supported prefixes; later numeric vectors remain kernel-only measurements.
97
97
  replay(types.text, 0);
98
98
  replay(types.decimal, 1);
99
99
  replay(types.float, 2);
@@ -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, ['😀', 'λ', '\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) {
@@ -147,12 +147,11 @@ function rejectUnmeasured(types: Types): void {
147
147
 
148
148
  function rejectShapes(types: Types): void {
149
149
  for (const mode of ['scoped', 'removable', 'ignoreCasing', 'overlapping']) {
150
- for (const type of Object.values(types)) {
151
- it(`should keep new ${type.name} keys rejected for ${mode} definitions`, async () => {
150
+ for (const [type, value] of [[types.text, '東京'], [types.text, '\u{1f600}'], [types.decimal, 0.1], [types.float, 0.1]] as const) {
151
+ it(`should keep new ${type.name} key ${JSON.stringify(value)} rejected for ${mode} definitions`, async () => {
152
152
  const constraints = mode === 'overlapping'
153
153
  ? [definition(type), definition(type, 'plain', 'OtherKey')]
154
154
  : [definition(type, mode)];
155
- const value = type === types.text ? '東京' : 0.1;
156
155
  const error = await Promise.resolve().then(() => scenarioFor(type, constraints))
157
156
  .then(scenario => scenario.append('A', Object.assign(new type(), { key: value }))).then(() => undefined, error => error);
158
157
  should(error).instanceOf(UnsupportedEventSequenceOperation);
@@ -0,0 +1,28 @@
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 { kernelEscapedJson } from '../../KernelTextHash.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when escaping JSON with supplementary characters', () => {
10
+ it('should write each surrogate as an uppercase escape', () => {
11
+ kernelEscapedJson(JSON.stringify({ key: '\u{1f600}' })).should.equal('{"key":"\\uD83D\\uDE00"}');
12
+ });
13
+
14
+ it('should escape the highest scalar and adjacent pairs', () => {
15
+ kernelEscapedJson('"\u{10ffff}\u{10000}\u{1f600}\u{1f642}"').should.equal('"\\uDBFF\\uDFFF\\uD800\\uDC00\\uD83D\\uDE00\\uD83D\\uDE42"');
16
+ });
17
+
18
+ it('should keep BMP characters, quotes and escapes literal', () => {
19
+ const json = JSON.stringify({ key: '\u00e9\u4eac\u0301"\\\n\u0000' });
20
+ kernelEscapedJson(json).should.equal(json);
21
+ });
22
+
23
+ it('should not touch literal backslash-u text or escape it twice', () => {
24
+ const json = JSON.stringify({ key: '\\uD83D\\uDE00' });
25
+ kernelEscapedJson(json).should.equal(json);
26
+ kernelEscapedJson(kernelEscapedJson(JSON.stringify('\u{1f600}'))).should.equal('"\\uD83D\\uDE00"');
27
+ });
28
+ });