@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/value/create.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as Types from '../typebox';
2
- export declare class ValueCreateInvalidTypeError extends Error {
2
+ export declare class ValueCreateUnknownTypeError extends Error {
3
3
  readonly schema: Types.TSchema;
4
4
  constructor(schema: Types.TSchema);
5
5
  }
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.ValueCreateInvalidTypeError = void 0;
31
- const index_1 = require("../guard/index");
32
- class ValueCreateInvalidTypeError extends Error {
30
+ exports.ValueCreate = exports.ValueCreateUnknownTypeError = void 0;
31
+ const Types = require("../typebox");
32
+ class ValueCreateUnknownTypeError extends Error {
33
33
  constructor(schema) {
34
- super('ValueCreate: Invalid type');
34
+ super('ValueCreate: Unknown type');
35
35
  this.schema = schema;
36
36
  }
37
37
  }
38
- exports.ValueCreateInvalidTypeError = ValueCreateInvalidTypeError;
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 refs = schema.$id === undefined ? references : [schema, ...references];
280
- if (index_1.TypeGuard.TAny(schema)) {
281
- return Any(schema, refs);
282
- }
283
- else if (index_1.TypeGuard.TArray(schema)) {
284
- return Array(schema, refs);
285
- }
286
- else if (index_1.TypeGuard.TBoolean(schema)) {
287
- return Boolean(schema, refs);
288
- }
289
- else if (index_1.TypeGuard.TConstructor(schema)) {
290
- return Constructor(schema, refs);
291
- }
292
- else if (index_1.TypeGuard.TFunction(schema)) {
293
- return Function(schema, refs);
294
- }
295
- else if (index_1.TypeGuard.TInteger(schema)) {
296
- return Integer(schema, refs);
297
- }
298
- else if (index_1.TypeGuard.TLiteral(schema)) {
299
- return Literal(schema, refs);
300
- }
301
- else if (index_1.TypeGuard.TNull(schema)) {
302
- return Null(schema, refs);
303
- }
304
- else if (index_1.TypeGuard.TNumber(schema)) {
305
- return Number(schema, refs);
306
- }
307
- else if (index_1.TypeGuard.TObject(schema)) {
308
- return Object(schema, refs);
309
- }
310
- else if (index_1.TypeGuard.TPromise(schema)) {
311
- return Promise(schema, refs);
312
- }
313
- else if (index_1.TypeGuard.TRecord(schema)) {
314
- return Record(schema, refs);
315
- }
316
- else if (index_1.TypeGuard.TRef(schema)) {
317
- return Ref(schema, refs);
318
- }
319
- else if (index_1.TypeGuard.TSelf(schema)) {
320
- return Self(schema, refs);
321
- }
322
- else if (index_1.TypeGuard.TString(schema)) {
323
- return String(schema, refs);
324
- }
325
- else if (index_1.TypeGuard.TTuple(schema)) {
326
- return Tuple(schema, refs);
327
- }
328
- else if (index_1.TypeGuard.TUndefined(schema)) {
329
- return Undefined(schema, refs);
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;