@sinclair/typebox 0.30.0-dev-2 → 0.30.0-dev-4

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.
@@ -140,7 +140,7 @@ class TypeCompilerUnknownTypeError extends Error {
140
140
  exports.TypeCompilerUnknownTypeError = TypeCompilerUnknownTypeError;
141
141
  class TypeCompilerDereferenceError extends Error {
142
142
  constructor(schema) {
143
- super(`TypeCompiler: Unable to dereference schema with $id '${schema.$ref}'`);
143
+ super(`TypeCompiler: Unable to dereference type with $id '${schema.$ref}'`);
144
144
  this.schema = schema;
145
145
  }
146
146
  }
package/errors/errors.js CHANGED
@@ -131,7 +131,7 @@ class ValueErrorsUnknownTypeError extends Error {
131
131
  exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
132
132
  class ValueErrorsDereferenceError extends Error {
133
133
  constructor(schema) {
134
- super(`ValueErrors: Unable to dereference schema with $id '${schema.$ref}'`);
134
+ super(`ValueErrors: Unable to dereference type with $id '${schema.$ref}'`);
135
135
  this.schema = schema;
136
136
  }
137
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.30.0-dev-2",
3
+ "version": "0.30.0-dev-4",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -198,13 +198,13 @@ function receive(value: T) { // ... as a Static Type
198
198
 
199
199
  ## Types
200
200
 
201
- TypeBox types are JSON schema fragments that can be composed into more complex types. Each fragment is structured such that a JSON schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox provides a set of Standard types which are used create JSON schema compliant schematics as well as an Extended type set used to create schematics for constructs native to JavaScript.
201
+ TypeBox types are JSON schema fragments that compose into complex types. Each fragment is structured such that a JSON schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox provides a set of Standard types which are used create JSON schema compliant schematics as well as an Extended type set used to create schematics for constructs native to JavaScript.
202
202
 
203
203
  <a name='types-standard'></a>
204
204
 
205
205
  ### Standard Types
206
206
 
207
- The following table lists the Standard TypeBox types. These types are fully compatible with the JSON Schema Draft 6 specification.
207
+ The following table lists the Standard TypeBox types. These types are fully compatible with the JSON Schema Draft 7 specification.
208
208
 
209
209
  ```typescript
210
210
  ┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
@@ -668,7 +668,7 @@ Object properties can be modified with `readonly` or `optional`. The following t
668
668
 
669
669
  ### Generic Types
670
670
 
671
- Generic types can be created with generic functions constrained to type `TSchema`. The following creates a generic `Vector<T>` type.
671
+ Generic types are created with generic functions. All TypeBox types extend the sub type `TSchema` so it is common to constrain function arguments to this type. The following creates a generic `Vector<T>` type.
672
672
 
673
673
  ```typescript
674
674
  import { Type, Static, TSchema } from '@sinclair/typebox'
@@ -692,7 +692,7 @@ type NumberVector = Static<typeof NumberVector> // type NumberVector = {
692
692
  // }
693
693
  ```
694
694
 
695
- The following creates a generic `Nullable<T>` type.
695
+ Generic types can be used to create aliases for more complex types. The following creates a `Nullable<T>` type.
696
696
 
697
697
  ```typescript
698
698
  const Nullable = <T extends TSchema>(schema: T) => Type.Union([schema, Type.Null()])
@@ -711,24 +711,26 @@ type T = Static<typeof T> // type T = string | null
711
711
 
712
712
  ### Reference Types
713
713
 
714
- Reference types are supported with `Type.Ref`. The target type must specify a valid `$id`.
714
+ Reference types are supported with `Ref`.
715
715
 
716
716
  ```typescript
717
717
  const T = Type.String({ $id: 'T' }) // const T = {
718
- // $id: 'T',
719
- // type: 'string'
718
+ // $id: 'T',
719
+ // type: 'string'
720
720
  // }
721
721
 
722
- const R = Type.Ref(T) // const R = {
723
- // $ref: 'T'
722
+ const R = Type.Ref<typeof T>('T') // const R = {
723
+ // $ref: 'T'
724
724
  // }
725
+
726
+ type R = Static<typeof R> // type R = string
725
727
  ```
726
728
 
727
729
  <a name='types-recursive'></a>
728
730
 
729
731
  ### Recursive Types
730
732
 
731
- Recursive types are supported with `Type.Recursive`.
733
+ Recursive types are supported with `Recursive`. Recursive type inference is also supported.
732
734
 
733
735
  ```typescript
734
736
  const Node = Type.Recursive(This => Type.Object({ // const Node = {
@@ -765,7 +767,7 @@ function test(node: Node) {
765
767
 
766
768
  ### Conditional Types
767
769
 
768
- TypeBox supports conditional types with `Type.Extends`. This type will perform a structural assignment check for the first two parameters and return a `true` or `false` type from the second two parameters. The types `Type.Exclude` and `Type.Extract` are also supported.
770
+ TypeBox supports conditional types with `Extends`. This type performs a structural assignment check against the first two parameters and returns either the `true` or `false` type as given from the second two parameters. The conditional types `Exclude` and `Extract` are also supported.
769
771
 
770
772
  ```typescript
771
773
  // TypeScript
@@ -778,17 +780,17 @@ type T2 = Exclude<(1 | 2 | 3), 1> // type T2 = 2 | 3
778
780
 
779
781
  // TypeBox
780
782
 
781
- const T0 = Type.Extends( // const T0: TLiteral<false>
782
- Type.String(),
783
- Type.Number(),
784
- Type.Literal(true),
783
+ const T0 = Type.Extends( // const T0: TLiteral<false> = {
784
+ Type.String(), // type: 'boolean',
785
+ Type.Number(), // const: false
786
+ Type.Literal(true), // }
785
787
  Type.Literal(false)
786
788
  )
787
789
 
788
- const T1 = Type.Extract( // const T1: TLiteral<1>
789
- Type.Union([
790
- Type.Literal(1),
791
- Type.Literal(2),
790
+ const T1 = Type.Extract( // const T1: TLiteral<1> = {
791
+ Type.Union([ // type: 'number',
792
+ Type.Literal(1), // const: 1
793
+ Type.Literal(2), // }
792
794
  Type.Literal(3)
793
795
  ]),
794
796
  Type.Literal(1)
@@ -797,42 +799,38 @@ const T1 = Type.Extract( // const T1: TLiteral<1>
797
799
  const T2 = Type.Exclude( // const T2: TUnion<[
798
800
  Type.Union([ // TLiteral<2>,
799
801
  Type.Literal(1), // TLiteral<3>
800
- Type.Literal(2), // ]>
801
- Type.Literal(3)
802
- ]),
803
- Type.Literal(1)
804
- )
802
+ Type.Literal(2), // ]> = {
803
+ Type.Literal(3) // anyOf: [{
804
+ ]), // type: 'number',
805
+ Type.Literal(1) // const: 2
806
+ ) // }, {
807
+ // type: 'number',
808
+ // const: 3
809
+ // }]
810
+ // }
805
811
  ```
806
812
 
807
813
  <a name='types-template-literal'></a>
808
814
 
809
815
  ### Template Literal Types
810
816
 
811
- TypeBox supports template literal types with `Type.TemplateLiteral`. This type implements an embedded DSL syntax to match the TypeScript template literal syntax. This type can also be composed by passing an array of union and literal types as parameters. The following example shows the DSL syntax.
817
+ TypeBox supports template literal types with `TemplateLiteral`. This type provides an embedded DSL syntax that is similar to the TypeScript template literal syntax. These type can also be composed by passing a tuple of exterior union and literal types. The following example shows the DSL syntax.
812
818
 
813
819
  ```typescript
814
820
  // TypeScript
815
821
 
816
- type P = `/post/${string}/user/${number}` // type P = `/post/${string}/user/${number}`
817
-
818
- type T = `option${'A'|'B'}` // type T = 'optionA' | 'optionB'
822
+ type T = `option${'A'|'B'|'C'}` // type T = 'optionA' | 'optionB' | 'optionC'
819
823
 
820
824
  type R = Record<T, string> // type R = {
821
825
  // optionA: string
822
826
  // optionB: string
827
+ // optionC: string
823
828
  // }
824
829
 
825
830
  // TypeBox
826
831
 
827
- const P = Type.TemplateLiteral('/post/${string}/user/${number}')
828
-
829
- // const P = {
830
- // type: 'string',
831
- // pattern: '^/post/(.*)/user/(0|[1-9][0-9]*)$'
832
- // }
833
-
834
- const T = Type.TemplateLiteral('option${A|B}') // const T = {
835
- // pattern: '^option(A|B)$',
832
+ const T = Type.TemplateLiteral('option${A|B|C}') // const T = {
833
+ // pattern: '^option(A|B|C)$',
836
834
  // type: 'string'
837
835
  // }
838
836
 
@@ -846,6 +844,9 @@ const R = Type.Record(T, Type.String()) // const R = {
846
844
  // optionB: {
847
845
  // type: 'string'
848
846
  // }
847
+ // optionC: {
848
+ // type: 'string'
849
+ // }
849
850
  // }
850
851
  // }
851
852
  ```
@@ -854,7 +855,7 @@ const R = Type.Record(T, Type.String()) // const R = {
854
855
 
855
856
  ### Indexed Access Types
856
857
 
857
- TypeBox supports indexed access types using `Type.Index`. This type provides a consistent way to access interior property and array element types without having to extract them from the underlying schema representation. Indexed access types are supported for object, array, tuple, union and intersect types.
858
+ TypeBox supports indexed access types using `Index`. This type provides a consistent way of accessing interior property and array element types without having to extract them from the underlying schema representation. Indexed access types are supported for object, array, tuple, union and intersect types.
858
859
 
859
860
  ```typescript
860
861
  const T = Type.Object({ // const T = {
@@ -889,7 +890,7 @@ const C = Type.Index(T, Type.KeyOf(T)) // const C = {
889
890
 
890
891
  ### Negated Types
891
892
 
892
- TypeBox has support for type negation with `Type.Not`. This type will always infer as `unknown`.
893
+ TypeBox has support for type negation with `Not`. This type will always infer as `unknown`.
893
894
 
894
895
  ```typescript
895
896
  const T = Type.Not(Type.String()) // const T = {
@@ -900,7 +901,7 @@ type T = Static<typeof T> // type T = unknown
900
901
  //
901
902
  // where T could be any type other than string
902
903
  ```
903
- This type can be useful for certain forms of type narrowing. For example, consider a type that represents a `number` but not the values `1, 2, 3`. The example below shows an imaginary TypeScript syntax to express such a type followed by the TypeBox representation.
904
+ Type negation can be useful for certain forms of type narrowing. For example, consider a type that represents a `number` but not the numbers `1, 2, 3`. The example below shows an imaginary TypeScript syntax to express such a type followed by the TypeBox representation.
904
905
 
905
906
  ```typescript
906
907
  // TypeScript
@@ -926,7 +927,6 @@ const T = Type.Intersect([ // const T = {
926
927
 
927
928
  type T = Static<typeof T> // type T = number
928
929
  ```
929
-
930
930
  This type can be used with constraints to create schematics that would otherwise be difficult to express.
931
931
  ```typescript
932
932
  const Even = Type.Number({ multipleOf: 2 })
@@ -937,7 +937,7 @@ const Odd = Type.Intersect([Type.Number(), Type.Not(Even)])
937
937
 
938
938
  ### Rest Types
939
939
 
940
- Rest parameters are supported with `Type.Rest`. This function is used to extract interior type elements from tuples which enables them to compose with the JavaScript spread operator `...`. This type can be used for tuple concatenation as well as for variadic functions.
940
+ Rest parameters are supported with `Rest`. This function is used to extract interior type elements from tuples which enables them to compose with the JavaScript spread operator `...`. This type can be used for tuple concatenation as well function parameter assignment.
941
941
 
942
942
  ```typescript
943
943
  // TypeScript
@@ -975,7 +975,7 @@ const F = Type.Function(Type.Rest(C), Type.Void()) // const F: TFunction<[
975
975
 
976
976
  ### Unsafe Types
977
977
 
978
- Use `Type.Unsafe` to create custom schematics with user defined inference rules.
978
+ TypeBox supports the creation of user defined schematics with user defined inference rules using the Unsafe type.
979
979
 
980
980
  ```typescript
981
981
  const T = Type.Unsafe<string>({ type: 'number' }) // const T = {
@@ -985,7 +985,7 @@ const T = Type.Unsafe<string>({ type: 'number' }) // const T = {
985
985
  type T = Static<typeof T> // type T = string
986
986
  ```
987
987
 
988
- The `Type.Unsafe` type can be useful to express specific OpenAPI schema representations.
988
+ This type can be useful to create various extended schematics, such as those used by OpenAPI.
989
989
 
990
990
  ```typescript
991
991
  import { Type, Static, TSchema } from '@sinclair/typebox'
@@ -1020,12 +1020,12 @@ type T = Static<typeof T> // type T = 'A' | 'B' | 'C'
1020
1020
 
1021
1021
  ### Type Guards
1022
1022
 
1023
- TypeBox provides a `TypeGuard` module that can be used for reflection and asserting values as types.
1023
+ TypeBox provides a TypeGuard module to assert JavaScript values are valid TypeBox types.
1024
1024
 
1025
1025
  ```typescript
1026
- import { Type, TypeGuard } from '@sinclair/typebox'
1026
+ import { Type, Kind, TypeGuard } from '@sinclair/typebox'
1027
1027
 
1028
- const T = Type.String()
1028
+ const T = { [Kind]: 'String', type: 'string' }
1029
1029
 
1030
1030
  if(TypeGuard.TString(T)) {
1031
1031
 
@@ -1037,7 +1037,7 @@ if(TypeGuard.TString(T)) {
1037
1037
 
1038
1038
  ### Strict
1039
1039
 
1040
- TypeBox types contain various symbol properties that are used for reflection, composition and compilation. These properties are not strictly valid JSON schema; so in some cases it may be desirable to omit them. TypeBox provides a `Type.Strict` function that will omit these properties if necessary.
1040
+ TypeBox types contain various symbol properties that are used for reflection, composition and compilation. These properties are not strictly valid JSON schema; so in some cases it may be desirable to omit them. TypeBox provides a `Strict` function that will omit these properties if necessary.
1041
1041
 
1042
1042
  ```typescript
1043
1043
  const T = Type.Object({ // const T = {
@@ -1110,7 +1110,7 @@ const R = Value.Check(T, { x: 1 }) // const R = true
1110
1110
 
1111
1111
  ### Convert
1112
1112
 
1113
- Use the Convert function to convert a value into its target type if a reasonable conversion is possible.
1113
+ Use the Convert function to convert a value into its target type if a reasonable conversion is possible. This function may return an invalid value and should be checked before use. It's return type is `unknown`.
1114
1114
 
1115
1115
  ```typescript
1116
1116
  const T = Type.Object({ x: Type.Number() })
@@ -1262,7 +1262,7 @@ ValuePointer.Set(A, '/z', 1) // const A' = { x: 1, y: 1,
1262
1262
 
1263
1263
  ## TypeCheck
1264
1264
 
1265
- TypeBox types target JSON Schema draft 6 so are compatible with any validator that supports this specification. TypeBox also provides a built in type checking compiler designed specifically for high performance compilation and value assertion.
1265
+ TypeBox types target JSON Schema draft 7 so are compatible with any validator that supports this specification. TypeBox also provides a built in type checking compiler designed specifically for high performance compilation and value assertion.
1266
1266
 
1267
1267
  The following sections detail using Ajv and TypeBox's compiler infrastructure.
1268
1268
 
@@ -1586,11 +1586,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
1586
1586
  ┌──────────────────────┬────────────┬────────────┬─────────────┐
1587
1587
  │ (index) │ Compiled │ Minified │ Compression │
1588
1588
  ├──────────────────────┼────────────┼────────────┼─────────────┤
1589
- │ typebox/compiler │ '128.2 kb' │ ' 58.2 kb' │ '2.20 x' │
1590
- │ typebox/errors │ '110.4 kb' │ ' 49.5 kb' │ '2.23 x' │
1591
- │ typebox/system │ ' 75.2 kb' │ ' 31.1 kb' │ '2.42 x' │
1592
- │ typebox/value │ '179.6 kb' │ ' 78.7 kb' │ '2.28 x' │
1593
- │ typebox │ ' 74.1 kb' │ ' 30.6 kb' │ '2.42 x' │
1589
+ │ typebox/compiler │ '128.3 kb' │ ' 58.0 kb' │ '2.21 x' │
1590
+ │ typebox/errors │ '110.5 kb' │ ' 49.5 kb' │ '2.23 x' │
1591
+ │ typebox/system │ ' 75.4 kb' │ ' 31.2 kb' │ '2.42 x' │
1592
+ │ typebox/value │ '179.7 kb' │ ' 78.7 kb' │ '2.28 x' │
1593
+ │ typebox │ ' 74.3 kb' │ ' 30.7 kb' │ '2.42 x' │
1594
1594
  └──────────────────────┴────────────┴────────────┴─────────────┘
1595
1595
  ```
1596
1596
 
package/typebox.d.ts CHANGED
@@ -601,7 +601,7 @@ export declare namespace TypeExtends {
601
601
  /** Specialized Clone for Types */
602
602
  export declare namespace TypeClone {
603
603
  /** Clones a type. */
604
- function Clone<T extends TSchema>(schema: T, options: SchemaOptions): T;
604
+ function Clone<T extends TSchema>(schema: T, options?: SchemaOptions): T;
605
605
  }
606
606
  export declare namespace IndexedAccessor {
607
607
  function Resolve(schema: TSchema, keys: Key[], options?: SchemaOptions): TSchema;
package/typebox.js CHANGED
@@ -1369,7 +1369,7 @@ var TypeClone;
1369
1369
  return value;
1370
1370
  }
1371
1371
  /** Clones a type. */
1372
- function Clone(schema, options) {
1372
+ function Clone(schema, options = {}) {
1373
1373
  return { ...Visit(schema), ...options };
1374
1374
  }
1375
1375
  TypeClone.Clone = Clone;
@@ -1381,7 +1381,7 @@ var IndexedAccessor;
1381
1381
  (function (IndexedAccessor) {
1382
1382
  function OptionalUnwrap(schema) {
1383
1383
  return schema.map((schema) => {
1384
- const { [exports.Optional]: _, ...clone } = TypeClone.Clone(schema, {});
1384
+ const { [exports.Optional]: _, ...clone } = TypeClone.Clone(schema);
1385
1385
  return clone;
1386
1386
  });
1387
1387
  }
@@ -1477,7 +1477,7 @@ var ObjectMap;
1477
1477
  return schema;
1478
1478
  }
1479
1479
  function Map(schema, callback, options) {
1480
- return { ...Visit(TypeClone.Clone(schema, {}), callback), ...options };
1480
+ return { ...Visit(TypeClone.Clone(schema), callback), ...options };
1481
1481
  }
1482
1482
  ObjectMap.Map = Map;
1483
1483
  })(ObjectMap || (exports.ObjectMap = ObjectMap = {}));
@@ -1931,11 +1931,11 @@ class StandardTypeBuilder extends TypeBuilder {
1931
1931
  }
1932
1932
  /** `[Standard]` Creates a Readonly property */
1933
1933
  Readonly(schema) {
1934
- return { ...TypeClone.Clone(schema, {}), [exports.Readonly]: 'Readonly' };
1934
+ return { ...TypeClone.Clone(schema), [exports.Readonly]: 'Readonly' };
1935
1935
  }
1936
1936
  /** `[Standard]` Creates an Optional property */
1937
1937
  Optional(schema) {
1938
- return { ...TypeClone.Clone(schema, {}), [exports.Optional]: 'Optional' };
1938
+ return { ...TypeClone.Clone(schema), [exports.Optional]: 'Optional' };
1939
1939
  }
1940
1940
  // ------------------------------------------------------------------------
1941
1941
  // Types
@@ -1946,7 +1946,7 @@ class StandardTypeBuilder extends TypeBuilder {
1946
1946
  }
1947
1947
  /** `[Standard]` Creates an Array type */
1948
1948
  Array(items, options = {}) {
1949
- return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items: TypeClone.Clone(items, {}) });
1949
+ return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items: TypeClone.Clone(items) });
1950
1950
  }
1951
1951
  /** `[Standard]` Creates a Boolean type */
1952
1952
  Boolean(options = {}) {
@@ -2012,12 +2012,12 @@ class StandardTypeBuilder extends TypeBuilder {
2012
2012
  }
2013
2013
  else if (TypeGuard.TTuple(schema) && TypeGuard.TNumber(unresolved)) {
2014
2014
  const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
2015
- const cloned = items.map((schema) => TypeClone.Clone(schema, {}));
2015
+ const cloned = items.map((schema) => TypeClone.Clone(schema));
2016
2016
  return this.Union(cloned, options);
2017
2017
  }
2018
2018
  else {
2019
2019
  const keys = KeyArrayResolver.Resolve(unresolved);
2020
- const clone = TypeClone.Clone(schema, {});
2020
+ const clone = TypeClone.Clone(schema);
2021
2021
  return IndexedAccessor.Resolve(clone, keys, options);
2022
2022
  }
2023
2023
  }
@@ -2031,8 +2031,8 @@ class StandardTypeBuilder extends TypeBuilder {
2031
2031
  if (allOf.length === 1)
2032
2032
  return TypeClone.Clone(allOf[0], options);
2033
2033
  const objects = allOf.every((schema) => TypeGuard.TObject(schema));
2034
- const cloned = allOf.map((schema) => TypeClone.Clone(schema, {}));
2035
- const clonedUnevaluatedProperties = TypeGuard.TSchema(options.unevaluatedProperties) ? { unevaluatedProperties: TypeClone.Clone(options.unevaluatedProperties, {}) } : {};
2034
+ const cloned = allOf.map((schema) => TypeClone.Clone(schema));
2035
+ const clonedUnevaluatedProperties = TypeGuard.TSchema(options.unevaluatedProperties) ? { unevaluatedProperties: TypeClone.Clone(options.unevaluatedProperties) } : {};
2036
2036
  if (options.unevaluatedProperties === false || TypeGuard.TSchema(options.unevaluatedProperties) || objects) {
2037
2037
  return this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: 'Intersect', type: 'object', allOf: cloned });
2038
2038
  }
@@ -2091,8 +2091,8 @@ class StandardTypeBuilder extends TypeBuilder {
2091
2091
  const propertyKeys = Object.getOwnPropertyNames(properties);
2092
2092
  const optionalKeys = propertyKeys.filter((key) => TypeGuard.TOptional(properties[key]));
2093
2093
  const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
2094
- const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Clone(options.additionalProperties, {}) } : {};
2095
- const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(properties[key], {}) }), {});
2094
+ const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Clone(options.additionalProperties) } : {};
2095
+ const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(properties[key]) }), {});
2096
2096
  if (requiredKeys.length > 0) {
2097
2097
  return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys });
2098
2098
  }
@@ -2103,17 +2103,17 @@ class StandardTypeBuilder extends TypeBuilder {
2103
2103
  Omit(schema, unresolved, options = {}) {
2104
2104
  const keys = KeyArrayResolver.Resolve(unresolved);
2105
2105
  // prettier-ignore
2106
- return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
2107
- if (schema.required) {
2108
- schema.required = schema.required.filter((key) => !keys.includes(key));
2109
- if (schema.required.length === 0)
2110
- delete schema.required;
2106
+ return ObjectMap.Map(TypeClone.Clone(schema), (object) => {
2107
+ if (ValueGuard.IsArray(object.required)) {
2108
+ object.required = object.required.filter((key) => !keys.includes(key));
2109
+ if (object.required.length === 0)
2110
+ delete object.required;
2111
2111
  }
2112
- for (const key of Object.getOwnPropertyNames(schema.properties)) {
2112
+ for (const key of Object.getOwnPropertyNames(object.properties)) {
2113
2113
  if (keys.includes(key))
2114
- delete schema.properties[key];
2114
+ delete object.properties[key];
2115
2115
  }
2116
- return this.Create(schema);
2116
+ return this.Create(object);
2117
2117
  }, options);
2118
2118
  }
2119
2119
  /** `[Standard]` Creates a mapped type where all properties are Optional */
@@ -2129,17 +2129,17 @@ class StandardTypeBuilder extends TypeBuilder {
2129
2129
  Pick(schema, unresolved, options = {}) {
2130
2130
  const keys = KeyArrayResolver.Resolve(unresolved);
2131
2131
  // prettier-ignore
2132
- return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
2133
- if (schema.required) {
2134
- schema.required = schema.required.filter((key) => keys.includes(key));
2135
- if (schema.required.length === 0)
2136
- delete schema.required;
2132
+ return ObjectMap.Map(TypeClone.Clone(schema), (object) => {
2133
+ if (ValueGuard.IsArray(object.required)) {
2134
+ object.required = object.required.filter((key) => keys.includes(key));
2135
+ if (object.required.length === 0)
2136
+ delete object.required;
2137
2137
  }
2138
- for (const key of Object.getOwnPropertyNames(schema.properties)) {
2138
+ for (const key of Object.getOwnPropertyNames(object.properties)) {
2139
2139
  if (!keys.includes(key))
2140
- delete schema.properties[key];
2140
+ delete object.properties[key];
2141
2141
  }
2142
- return this.Create(schema);
2142
+ return this.Create(object);
2143
2143
  }, options);
2144
2144
  }
2145
2145
  /** `[Standard]` Creates a Record type */
@@ -2148,13 +2148,13 @@ class StandardTypeBuilder extends TypeBuilder {
2148
2148
  const expression = TemplateLiteralParser.ParseExact(key.pattern);
2149
2149
  // prettier-ignore
2150
2150
  return TemplateLiteralFinite.Check(expression)
2151
- ? (this.Object([...TemplateLiteralGenerator.Generate(expression)].reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(schema, {}) }), {}), options))
2152
- : this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [key.pattern]: TypeClone.Clone(schema, {}) } });
2151
+ ? (this.Object([...TemplateLiteralGenerator.Generate(expression)].reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(schema) }), {}), options))
2152
+ : this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [key.pattern]: TypeClone.Clone(schema) } });
2153
2153
  }
2154
2154
  else if (TypeGuard.TUnion(key)) {
2155
2155
  const union = UnionResolver.Resolve(key);
2156
2156
  if (TypeGuard.TUnionLiteral(union)) {
2157
- const properties = union.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Clone(schema, {}) }), {});
2157
+ const properties = union.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Clone(schema) }), {});
2158
2158
  return this.Object(properties, { ...options, [exports.Hint]: 'Record' });
2159
2159
  }
2160
2160
  else
@@ -2162,17 +2162,17 @@ class StandardTypeBuilder extends TypeBuilder {
2162
2162
  }
2163
2163
  else if (TypeGuard.TLiteral(key)) {
2164
2164
  if (ValueGuard.IsString(key.const) || ValueGuard.IsNumber(key.const)) {
2165
- return this.Object({ [key.const]: TypeClone.Clone(schema, {}) }, options);
2165
+ return this.Object({ [key.const]: TypeClone.Clone(schema) }, options);
2166
2166
  }
2167
2167
  else
2168
2168
  throw Error('StandardTypeBuilder: Record key of type literal is not of type string or number');
2169
2169
  }
2170
2170
  else if (TypeGuard.TInteger(key) || TypeGuard.TNumber(key)) {
2171
- return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [exports.PatternNumberExact]: TypeClone.Clone(schema, {}) } });
2171
+ return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [exports.PatternNumberExact]: TypeClone.Clone(schema) } });
2172
2172
  }
2173
2173
  else if (TypeGuard.TString(key)) {
2174
2174
  const pattern = ValueGuard.IsUndefined(key.pattern) ? exports.PatternStringExact : key.pattern;
2175
- return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Clone(schema, {}) } });
2175
+ return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Clone(schema) } });
2176
2176
  }
2177
2177
  else {
2178
2178
  throw Error(`StandardTypeBuilder: Record key is an invalid type`);
@@ -2209,10 +2209,10 @@ class StandardTypeBuilder extends TypeBuilder {
2209
2209
  if (TypeGuard.TTuple(schema)) {
2210
2210
  if (ValueGuard.IsUndefined(schema.items))
2211
2211
  return [];
2212
- return schema.items.map((schema) => TypeClone.Clone(schema, {}));
2212
+ return schema.items.map((schema) => TypeClone.Clone(schema));
2213
2213
  }
2214
2214
  else {
2215
- return [TypeClone.Clone(schema, {})];
2215
+ return [TypeClone.Clone(schema)];
2216
2216
  }
2217
2217
  }
2218
2218
  /** `[Standard]` Creates a String type */
@@ -2230,7 +2230,7 @@ class StandardTypeBuilder extends TypeBuilder {
2230
2230
  /** `[Standard]` Creates a Tuple type */
2231
2231
  Tuple(items, options = {}) {
2232
2232
  const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
2233
- const clonedItems = items.map((item) => TypeClone.Clone(item, {}));
2233
+ const clonedItems = items.map((item) => TypeClone.Clone(item));
2234
2234
  // prettier-ignore
2235
2235
  const schema = (items.length > 0 ?
2236
2236
  { ...options, [exports.Kind]: 'Tuple', type: 'array', items: clonedItems, additionalItems, minItems, maxItems } :
@@ -2247,7 +2247,7 @@ class StandardTypeBuilder extends TypeBuilder {
2247
2247
  return this.Never(options);
2248
2248
  if (anyOf.length === 1)
2249
2249
  return this.Create(TypeClone.Clone(anyOf[0], options));
2250
- const clonedAnyOf = anyOf.map((schema) => TypeClone.Clone(schema, {}));
2250
+ const clonedAnyOf = anyOf.map((schema) => TypeClone.Clone(schema));
2251
2251
  return this.Create({ ...options, [exports.Kind]: 'Union', anyOf: clonedAnyOf });
2252
2252
  }
2253
2253
  }
@@ -2267,7 +2267,7 @@ exports.StandardTypeBuilder = StandardTypeBuilder;
2267
2267
  class ExtendedTypeBuilder extends StandardTypeBuilder {
2268
2268
  /** `[Extended]` Creates a AsyncIterator type */
2269
2269
  AsyncIterator(items, options = {}) {
2270
- return this.Create({ ...options, [exports.Kind]: 'AsyncIterator', type: 'AsyncIterator', items: TypeClone.Clone(items, {}) });
2270
+ return this.Create({ ...options, [exports.Kind]: 'AsyncIterator', type: 'AsyncIterator', items: TypeClone.Clone(items) });
2271
2271
  }
2272
2272
  /** `[Extended]` Creates a BigInt type */
2273
2273
  BigInt(options = {}) {
@@ -2279,8 +2279,8 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
2279
2279
  }
2280
2280
  /** `[Extended]` Creates a Constructor type */
2281
2281
  Constructor(parameters, returns, options) {
2282
- const clonedReturns = TypeClone.Clone(returns, {});
2283
- const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter, {}));
2282
+ const clonedReturns = TypeClone.Clone(returns);
2283
+ const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter));
2284
2284
  return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'constructor', parameters: clonedParameters, returns: clonedReturns });
2285
2285
  }
2286
2286
  /** `[Extended]` Creates a Date type */
@@ -2290,7 +2290,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
2290
2290
  /** `[Extended]` Creates a Function type */
2291
2291
  Function(parameters, returns, options) {
2292
2292
  const clonedReturns = TypeClone.Clone(returns, {});
2293
- const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter, {}));
2293
+ const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter));
2294
2294
  return this.Create({ ...options, [exports.Kind]: 'Function', type: 'function', parameters: clonedParameters, returns: clonedReturns });
2295
2295
  }
2296
2296
  /** `[Extended]` Extracts the InstanceType from the given Constructor */
@@ -2299,7 +2299,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
2299
2299
  }
2300
2300
  /** `[Extended]` Creates an Iterator type */
2301
2301
  Iterator(items, options = {}) {
2302
- return this.Create({ ...options, [exports.Kind]: 'Iterator', type: 'Iterator', items: TypeClone.Clone(items, {}) });
2302
+ return this.Create({ ...options, [exports.Kind]: 'Iterator', type: 'Iterator', items: TypeClone.Clone(items) });
2303
2303
  }
2304
2304
  /** `[Extended]` Extracts the Parameters from the given Function type */
2305
2305
  Parameters(schema, options = {}) {
@@ -2307,7 +2307,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
2307
2307
  }
2308
2308
  /** `[Extended]` Creates a Promise type */
2309
2309
  Promise(item, options = {}) {
2310
- return this.Create({ ...options, [exports.Kind]: 'Promise', type: 'Promise', item: TypeClone.Clone(item, {}) });
2310
+ return this.Create({ ...options, [exports.Kind]: 'Promise', type: 'Promise', item: TypeClone.Clone(item) });
2311
2311
  }
2312
2312
  /** `[Extended]` Creates a String pattern type from Regular Expression */
2313
2313
  RegExp(unresolved, options = {}) {
package/value/cast.js CHANGED
@@ -74,7 +74,7 @@ class ValueCastUnknownTypeError extends Error {
74
74
  exports.ValueCastUnknownTypeError = ValueCastUnknownTypeError;
75
75
  class ValueCastDereferenceError extends Error {
76
76
  constructor(schema) {
77
- super(`ValueCast: Unable to dereference schema with $id '${schema.$ref}'`);
77
+ super(`ValueCast: Unable to dereference type with $id '${schema.$ref}'`);
78
78
  this.schema = schema;
79
79
  }
80
80
  }
package/value/check.js CHANGED
@@ -44,7 +44,7 @@ class ValueCheckUnknownTypeError extends Error {
44
44
  exports.ValueCheckUnknownTypeError = ValueCheckUnknownTypeError;
45
45
  class ValueCheckDereferenceError extends Error {
46
46
  constructor(schema) {
47
- super(`ValueCheck: Unable to dereference schema with $id '${schema.$ref}'`);
47
+ super(`ValueCheck: Unable to dereference type with $id '${schema.$ref}'`);
48
48
  this.schema = schema;
49
49
  }
50
50
  }
package/value/convert.js CHANGED
@@ -44,7 +44,7 @@ class ValueConvertUnknownTypeError extends Error {
44
44
  exports.ValueConvertUnknownTypeError = ValueConvertUnknownTypeError;
45
45
  class ValueConvertDereferenceError extends Error {
46
46
  constructor(schema) {
47
- super(`ValueConvert: Unable to dereference schema with $id '${schema.$ref}'`);
47
+ super(`ValueConvert: Unable to dereference type with $id '${schema.$ref}'`);
48
48
  this.schema = schema;
49
49
  }
50
50
  }
package/value/create.js CHANGED
@@ -71,7 +71,7 @@ class ValueCreateTempateLiteralTypeError extends Error {
71
71
  exports.ValueCreateTempateLiteralTypeError = ValueCreateTempateLiteralTypeError;
72
72
  class ValueCreateDereferenceError extends Error {
73
73
  constructor(schema) {
74
- super(`ValueCreate: Unable to dereference schema with $id '${schema.$ref}'`);
74
+ super(`ValueCreate: Unable to dereference type with $id '${schema.$ref}'`);
75
75
  this.schema = schema;
76
76
  }
77
77
  }