@sinclair/typebox 0.31.17 → 0.31.19
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.
- package/errors/errors.d.ts +1 -0
- package/errors/errors.js +17 -10
- package/package.json +2 -2
- package/value/transform.js +8 -0
package/errors/errors.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export declare class ValueErrorsUnknownTypeError extends Types.TypeBoxError {
|
|
|
75
75
|
readonly schema: Types.TSchema;
|
|
76
76
|
constructor(schema: Types.TSchema);
|
|
77
77
|
}
|
|
78
|
+
export declare function EscapeKey(key: string): string;
|
|
78
79
|
export declare class ValueErrorIterator {
|
|
79
80
|
private readonly iterator;
|
|
80
81
|
constructor(iterator: IterableIterator<ValueError>);
|
package/errors/errors.js
CHANGED
|
@@ -27,7 +27,7 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Errors = exports.ValueErrorIterator = exports.ValueErrorsUnknownTypeError = exports.ValueErrorType = void 0;
|
|
30
|
+
exports.Errors = exports.ValueErrorIterator = exports.EscapeKey = exports.ValueErrorsUnknownTypeError = exports.ValueErrorType = void 0;
|
|
31
31
|
const guard_1 = require("../value/guard");
|
|
32
32
|
const system_1 = require("../system/system");
|
|
33
33
|
const deref_1 = require("../value/deref");
|
|
@@ -113,6 +113,13 @@ class ValueErrorsUnknownTypeError extends Types.TypeBoxError {
|
|
|
113
113
|
}
|
|
114
114
|
exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
|
|
115
115
|
// --------------------------------------------------------------------------
|
|
116
|
+
// EscapeKey
|
|
117
|
+
// --------------------------------------------------------------------------
|
|
118
|
+
function EscapeKey(key) {
|
|
119
|
+
return key.replace(/~/g, '~0').replace(/\//g, '~1'); // RFC6901 Path
|
|
120
|
+
}
|
|
121
|
+
exports.EscapeKey = EscapeKey;
|
|
122
|
+
// --------------------------------------------------------------------------
|
|
116
123
|
// Guards
|
|
117
124
|
// --------------------------------------------------------------------------
|
|
118
125
|
function IsDefined(value) {
|
|
@@ -338,12 +345,12 @@ function* TObject(schema, references, path, value) {
|
|
|
338
345
|
for (const requiredKey of requiredKeys) {
|
|
339
346
|
if (unknownKeys.includes(requiredKey))
|
|
340
347
|
continue;
|
|
341
|
-
yield Create(ValueErrorType.ObjectRequiredProperty, schema.properties[requiredKey], `${path}/${requiredKey}`, undefined);
|
|
348
|
+
yield Create(ValueErrorType.ObjectRequiredProperty, schema.properties[requiredKey], `${path}/${EscapeKey(requiredKey)}`, undefined);
|
|
342
349
|
}
|
|
343
350
|
if (schema.additionalProperties === false) {
|
|
344
351
|
for (const valueKey of unknownKeys) {
|
|
345
352
|
if (!knownKeys.includes(valueKey)) {
|
|
346
|
-
yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${valueKey}`, value[valueKey]);
|
|
353
|
+
yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${EscapeKey(valueKey)}`, value[valueKey]);
|
|
347
354
|
}
|
|
348
355
|
}
|
|
349
356
|
}
|
|
@@ -351,20 +358,20 @@ function* TObject(schema, references, path, value) {
|
|
|
351
358
|
for (const valueKey of unknownKeys) {
|
|
352
359
|
if (knownKeys.includes(valueKey))
|
|
353
360
|
continue;
|
|
354
|
-
yield* Visit(schema.additionalProperties, references, `${path}/${valueKey}`, value[valueKey]);
|
|
361
|
+
yield* Visit(schema.additionalProperties, references, `${path}/${EscapeKey(valueKey)}`, value[valueKey]);
|
|
355
362
|
}
|
|
356
363
|
}
|
|
357
364
|
for (const knownKey of knownKeys) {
|
|
358
365
|
const property = schema.properties[knownKey];
|
|
359
366
|
if (schema.required && schema.required.includes(knownKey)) {
|
|
360
|
-
yield* Visit(property, references, `${path}/${knownKey}`, value[knownKey]);
|
|
367
|
+
yield* Visit(property, references, `${path}/${EscapeKey(knownKey)}`, value[knownKey]);
|
|
361
368
|
if (Types.ExtendsUndefined.Check(schema) && !(knownKey in value)) {
|
|
362
|
-
yield Create(ValueErrorType.ObjectRequiredProperty, property, `${path}/${knownKey}`, undefined);
|
|
369
|
+
yield Create(ValueErrorType.ObjectRequiredProperty, property, `${path}/${EscapeKey(knownKey)}`, undefined);
|
|
363
370
|
}
|
|
364
371
|
}
|
|
365
372
|
else {
|
|
366
373
|
if (system_1.TypeSystemPolicy.IsExactOptionalProperty(value, knownKey)) {
|
|
367
|
-
yield* Visit(property, references, `${path}/${knownKey}`, value[knownKey]);
|
|
374
|
+
yield* Visit(property, references, `${path}/${EscapeKey(knownKey)}`, value[knownKey]);
|
|
368
375
|
}
|
|
369
376
|
}
|
|
370
377
|
}
|
|
@@ -386,19 +393,19 @@ function* TRecord(schema, references, path, value) {
|
|
|
386
393
|
const regex = new RegExp(patternKey);
|
|
387
394
|
for (const [propertyKey, propertyValue] of Object.entries(value)) {
|
|
388
395
|
if (regex.test(propertyKey))
|
|
389
|
-
yield* Visit(patternSchema, references, `${path}/${propertyKey}`, propertyValue);
|
|
396
|
+
yield* Visit(patternSchema, references, `${path}/${EscapeKey(propertyKey)}`, propertyValue);
|
|
390
397
|
}
|
|
391
398
|
if (typeof schema.additionalProperties === 'object') {
|
|
392
399
|
for (const [propertyKey, propertyValue] of Object.entries(value)) {
|
|
393
400
|
if (!regex.test(propertyKey))
|
|
394
|
-
yield* Visit(schema.additionalProperties, references, `${path}/${propertyKey}`, propertyValue);
|
|
401
|
+
yield* Visit(schema.additionalProperties, references, `${path}/${EscapeKey(propertyKey)}`, propertyValue);
|
|
395
402
|
}
|
|
396
403
|
}
|
|
397
404
|
if (schema.additionalProperties === false) {
|
|
398
405
|
for (const [propertyKey, propertyValue] of Object.entries(value)) {
|
|
399
406
|
if (regex.test(propertyKey))
|
|
400
407
|
continue;
|
|
401
|
-
return yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${propertyKey}`, propertyValue);
|
|
408
|
+
return yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${EscapeKey(propertyKey)}`, propertyValue);
|
|
402
409
|
}
|
|
403
410
|
}
|
|
404
411
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinclair/typebox",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.19",
|
|
4
4
|
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"publish:dev": "hammer task publish_dev"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@sinclair/hammer": "^0.
|
|
55
|
+
"@sinclair/hammer": "^0.18.0",
|
|
56
56
|
"@types/mocha": "^9.1.1",
|
|
57
57
|
"@types/node": "^18.11.9",
|
|
58
58
|
"ajv": "^8.12.0",
|
package/value/transform.js
CHANGED
|
@@ -439,12 +439,20 @@ var EncodeTransform;
|
|
|
439
439
|
return (0, guard_1.IsArray)(schema.items) ? schema.items.map((schema, index) => Visit(schema, references, value1[index])) : [];
|
|
440
440
|
}
|
|
441
441
|
function TUnion(schema, references, value) {
|
|
442
|
+
// test value against union variants
|
|
442
443
|
for (const subschema of schema.anyOf) {
|
|
443
444
|
if (!checkFunction(subschema, references, value))
|
|
444
445
|
continue;
|
|
445
446
|
const value1 = Visit(subschema, references, value);
|
|
446
447
|
return Default(schema, value1);
|
|
447
448
|
}
|
|
449
|
+
// test transformed value against union variants
|
|
450
|
+
for (const subschema of schema.anyOf) {
|
|
451
|
+
const value1 = Visit(subschema, references, value);
|
|
452
|
+
if (!checkFunction(schema, references, value1))
|
|
453
|
+
continue;
|
|
454
|
+
return Default(schema, value1);
|
|
455
|
+
}
|
|
448
456
|
return Default(schema, value);
|
|
449
457
|
}
|
|
450
458
|
function Visit(schema, references, value) {
|