@sinclair/typebox 0.24.26 → 0.24.27
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/compiler/compiler.d.ts +1 -1
- package/compiler/compiler.js +53 -73
- package/conditional/conditional.js +2 -2
- package/errors/errors.d.ts +1 -1
- package/errors/errors.js +52 -71
- package/guard/guard.d.ts +28 -22
- package/guard/guard.js +59 -19
- package/package.json +1 -1
- package/readme.md +106 -91
- package/value/cast.d.ts +1 -1
- package/value/cast.js +55 -71
- package/value/check.d.ts +1 -1
- package/value/check.js +52 -71
- package/value/create.d.ts +1 -1
- package/value/create.js +56 -71
package/value/create.d.ts
CHANGED
package/value/create.js
CHANGED
|
@@ -27,15 +27,15 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.ValueCreate = exports.
|
|
31
|
-
const
|
|
32
|
-
class
|
|
30
|
+
exports.ValueCreate = exports.ValueCreateUnknownTypeError = void 0;
|
|
31
|
+
const Types = require("../typebox");
|
|
32
|
+
class ValueCreateUnknownTypeError extends Error {
|
|
33
33
|
constructor(schema) {
|
|
34
|
-
super('ValueCreate:
|
|
34
|
+
super('ValueCreate: Unknown type');
|
|
35
35
|
this.schema = schema;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
exports.
|
|
38
|
+
exports.ValueCreateUnknownTypeError = ValueCreateUnknownTypeError;
|
|
39
39
|
var ValueCreate;
|
|
40
40
|
(function (ValueCreate) {
|
|
41
41
|
function Any(schema, references) {
|
|
@@ -276,72 +276,57 @@ var ValueCreate;
|
|
|
276
276
|
}
|
|
277
277
|
/** Creates a value from the given schema. If the schema specifies a default value, then that value is returned. */
|
|
278
278
|
function Visit(schema, references) {
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
else if (index_1.TypeGuard.TUnion(schema)) {
|
|
332
|
-
return Union(schema, refs);
|
|
333
|
-
}
|
|
334
|
-
else if (index_1.TypeGuard.TUint8Array(schema)) {
|
|
335
|
-
return Uint8Array(schema, refs);
|
|
336
|
-
}
|
|
337
|
-
else if (index_1.TypeGuard.TUnknown(schema)) {
|
|
338
|
-
return Unknown(schema, refs);
|
|
339
|
-
}
|
|
340
|
-
else if (index_1.TypeGuard.TVoid(schema)) {
|
|
341
|
-
return Void(schema, refs);
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
throw new ValueCreateInvalidTypeError(schema);
|
|
279
|
+
const anyReferences = schema.$id === undefined ? references : [schema, ...references];
|
|
280
|
+
const anySchema = schema;
|
|
281
|
+
switch (anySchema[Types.Kind]) {
|
|
282
|
+
case 'Any':
|
|
283
|
+
return Any(anySchema, anyReferences);
|
|
284
|
+
case 'Array':
|
|
285
|
+
return Array(anySchema, anyReferences);
|
|
286
|
+
case 'Boolean':
|
|
287
|
+
return Boolean(anySchema, anyReferences);
|
|
288
|
+
case 'Constructor':
|
|
289
|
+
return Constructor(anySchema, anyReferences);
|
|
290
|
+
case 'Enum':
|
|
291
|
+
return Enum(anySchema, anyReferences);
|
|
292
|
+
case 'Function':
|
|
293
|
+
return Function(anySchema, anyReferences);
|
|
294
|
+
case 'Integer':
|
|
295
|
+
return Integer(anySchema, anyReferences);
|
|
296
|
+
case 'Literal':
|
|
297
|
+
return Literal(anySchema, anyReferences);
|
|
298
|
+
case 'Null':
|
|
299
|
+
return Null(anySchema, anyReferences);
|
|
300
|
+
case 'Number':
|
|
301
|
+
return Number(anySchema, anyReferences);
|
|
302
|
+
case 'Object':
|
|
303
|
+
return Object(anySchema, anyReferences);
|
|
304
|
+
case 'Promise':
|
|
305
|
+
return Promise(anySchema, anyReferences);
|
|
306
|
+
case 'Record':
|
|
307
|
+
return Record(anySchema, anyReferences);
|
|
308
|
+
case 'Rec':
|
|
309
|
+
return Recursive(anySchema, anyReferences);
|
|
310
|
+
case 'Ref':
|
|
311
|
+
return Ref(anySchema, anyReferences);
|
|
312
|
+
case 'Self':
|
|
313
|
+
return Self(anySchema, anyReferences);
|
|
314
|
+
case 'String':
|
|
315
|
+
return String(anySchema, anyReferences);
|
|
316
|
+
case 'Tuple':
|
|
317
|
+
return Tuple(anySchema, anyReferences);
|
|
318
|
+
case 'Undefined':
|
|
319
|
+
return Undefined(anySchema, anyReferences);
|
|
320
|
+
case 'Union':
|
|
321
|
+
return Union(anySchema, anyReferences);
|
|
322
|
+
case 'Uint8Array':
|
|
323
|
+
return Uint8Array(anySchema, anyReferences);
|
|
324
|
+
case 'Unknown':
|
|
325
|
+
return Unknown(anySchema, anyReferences);
|
|
326
|
+
case 'Void':
|
|
327
|
+
return Void(anySchema, anyReferences);
|
|
328
|
+
default:
|
|
329
|
+
throw new ValueCreateUnknownTypeError(anySchema);
|
|
345
330
|
}
|
|
346
331
|
}
|
|
347
332
|
ValueCreate.Visit = Visit;
|