@zlink-systems/stream-wire 0.31.0 → 0.32.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.
|
@@ -2,6 +2,7 @@ import type { ZLinkJsonSchema } from './json-contract';
|
|
|
2
2
|
export declare const FRAMEWORK_JSON_V1_PROFILE = "framework-json-v1";
|
|
3
3
|
export interface FrameworkJsonParseOptions {
|
|
4
4
|
readonly rejectPropertyName?: (name: string) => boolean;
|
|
5
|
+
readonly onDuplicateProperty?: (name: string, path: readonly string[]) => void;
|
|
5
6
|
}
|
|
6
7
|
export declare function stringifyFrameworkJsonV1(value: unknown, schema?: ZLinkJsonSchema, replacer?: (this: unknown, key: string, value: unknown) => unknown): string;
|
|
7
8
|
export declare function parseFrameworkJsonV1(text: string, options?: FrameworkJsonParseOptions, schema?: ZLinkJsonSchema, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown;
|
|
@@ -2,6 +2,7 @@ import type { ZLinkJsonSchema } from './json-contract';
|
|
|
2
2
|
export declare const FRAMEWORK_JSON_V1_PROFILE = "framework-json-v1";
|
|
3
3
|
export interface FrameworkJsonParseOptions {
|
|
4
4
|
readonly rejectPropertyName?: (name: string) => boolean;
|
|
5
|
+
readonly onDuplicateProperty?: (name: string, path: readonly string[]) => void;
|
|
5
6
|
}
|
|
6
7
|
export declare function stringifyFrameworkJsonV1(value: unknown, schema?: ZLinkJsonSchema, replacer?: (this: unknown, key: string, value: unknown) => unknown): string;
|
|
7
8
|
export declare function parseFrameworkJsonV1(text: string, options?: FrameworkJsonParseOptions, schema?: ZLinkJsonSchema, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown;
|
|
@@ -184,18 +184,18 @@ class JsonPropertyScanner {
|
|
|
184
184
|
}
|
|
185
185
|
scan() {
|
|
186
186
|
this.skipWhitespace();
|
|
187
|
-
this.scanValue();
|
|
187
|
+
this.scanValue([]);
|
|
188
188
|
this.skipWhitespace();
|
|
189
189
|
if (this.index !== this.text.length)
|
|
190
190
|
this.fail('trailing data');
|
|
191
191
|
}
|
|
192
|
-
scanValue() {
|
|
192
|
+
scanValue(path) {
|
|
193
193
|
this.skipWhitespace();
|
|
194
194
|
const token = this.text[this.index];
|
|
195
195
|
if (token === '{')
|
|
196
|
-
return this.scanObject();
|
|
196
|
+
return this.scanObject(path);
|
|
197
197
|
if (token === '[')
|
|
198
|
-
return this.scanArray();
|
|
198
|
+
return this.scanArray(path);
|
|
199
199
|
if (token === '"') {
|
|
200
200
|
this.scanString();
|
|
201
201
|
return;
|
|
@@ -208,7 +208,7 @@ class JsonPropertyScanner {
|
|
|
208
208
|
return this.scanLiteral('null');
|
|
209
209
|
this.scanNumber();
|
|
210
210
|
}
|
|
211
|
-
scanObject() {
|
|
211
|
+
scanObject(path) {
|
|
212
212
|
this.index++;
|
|
213
213
|
this.skipWhitespace();
|
|
214
214
|
if (this.text[this.index] === '}') {
|
|
@@ -222,7 +222,12 @@ class JsonPropertyScanner {
|
|
|
222
222
|
this.fail('object property name');
|
|
223
223
|
const property = this.scanString();
|
|
224
224
|
if (properties.has(property)) {
|
|
225
|
-
|
|
225
|
+
if (this.options.onDuplicateProperty !== undefined) {
|
|
226
|
+
this.options.onDuplicateProperty(property, path);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
throw new SyntaxError(`framework-json-v1 duplicate property '${property}'.`);
|
|
230
|
+
}
|
|
226
231
|
}
|
|
227
232
|
properties.add(property);
|
|
228
233
|
if (this.options.rejectPropertyName?.(property) === true) {
|
|
@@ -232,7 +237,7 @@ class JsonPropertyScanner {
|
|
|
232
237
|
if (this.text[this.index] !== ':')
|
|
233
238
|
this.fail("':' after object property");
|
|
234
239
|
this.index++;
|
|
235
|
-
this.scanValue();
|
|
240
|
+
this.scanValue(this.options.onDuplicateProperty === undefined ? path : [...path, property]);
|
|
236
241
|
this.skipWhitespace();
|
|
237
242
|
const delimiter = this.text[this.index++];
|
|
238
243
|
if (delimiter === '}')
|
|
@@ -241,7 +246,7 @@ class JsonPropertyScanner {
|
|
|
241
246
|
this.fail("',' or '}' after object property");
|
|
242
247
|
}
|
|
243
248
|
}
|
|
244
|
-
scanArray() {
|
|
249
|
+
scanArray(path) {
|
|
245
250
|
this.index++;
|
|
246
251
|
this.skipWhitespace();
|
|
247
252
|
if (this.text[this.index] === ']') {
|
|
@@ -249,7 +254,7 @@ class JsonPropertyScanner {
|
|
|
249
254
|
return;
|
|
250
255
|
}
|
|
251
256
|
for (;;) {
|
|
252
|
-
this.scanValue();
|
|
257
|
+
this.scanValue(this.options.onDuplicateProperty === undefined ? path : [...path, '[]']);
|
|
253
258
|
this.skipWhitespace();
|
|
254
259
|
const delimiter = this.text[this.index++];
|
|
255
260
|
if (delimiter === ']')
|