@sinclair/typebox 0.32.35 → 0.33.0

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.
Files changed (209) hide show
  1. package/build/cjs/index.d.ts +1 -0
  2. package/build/cjs/index.js +1 -0
  3. package/build/cjs/system/policy.d.ts +9 -1
  4. package/build/cjs/system/policy.js +13 -2
  5. package/build/cjs/type/any/any.js +4 -3
  6. package/build/cjs/type/array/array.d.ts +1 -1
  7. package/build/cjs/type/array/array.js +3 -8
  8. package/build/cjs/type/async-iterator/async-iterator.js +3 -8
  9. package/build/cjs/type/awaited/awaited.js +3 -3
  10. package/build/cjs/type/bigint/bigint.js +3 -6
  11. package/build/cjs/type/boolean/boolean.js +3 -6
  12. package/build/cjs/type/clone/type.d.ts +1 -1
  13. package/build/cjs/type/clone/type.js +2 -2
  14. package/build/cjs/type/composite/composite.js +1 -1
  15. package/build/cjs/type/const/const.js +3 -3
  16. package/build/cjs/type/constructor/constructor.js +2 -8
  17. package/build/cjs/type/constructor-parameters/constructor-parameters.js +2 -3
  18. package/build/cjs/type/create/immutable.d.ts +2 -0
  19. package/build/cjs/type/create/immutable.js +41 -0
  20. package/build/cjs/type/create/index.d.ts +1 -0
  21. package/build/cjs/type/create/index.js +18 -0
  22. package/build/cjs/type/create/type.d.ts +3 -0
  23. package/build/cjs/type/create/type.js +19 -0
  24. package/build/cjs/type/date/date.js +3 -6
  25. package/build/cjs/type/discard/discard.d.ts +1 -0
  26. package/build/cjs/type/discard/discard.js +1 -0
  27. package/build/cjs/type/enum/enum.js +1 -1
  28. package/build/cjs/type/exclude/exclude.js +4 -4
  29. package/build/cjs/type/extends/extends-from-mapped-key.d.ts +1 -1
  30. package/build/cjs/type/extends/extends-from-mapped-key.js +2 -1
  31. package/build/cjs/type/extends/extends-from-mapped-result.d.ts +1 -1
  32. package/build/cjs/type/extends/extends-from-mapped-result.js +2 -1
  33. package/build/cjs/type/extends/extends.js +4 -4
  34. package/build/cjs/type/extract/extract.js +5 -5
  35. package/build/cjs/type/function/function.js +2 -8
  36. package/build/cjs/type/guard/value.js +3 -0
  37. package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +1 -1
  38. package/build/cjs/type/indexed/indexed-from-mapped-key.js +2 -1
  39. package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +1 -1
  40. package/build/cjs/type/indexed/indexed.js +10 -6
  41. package/build/cjs/type/instance-type/instance-type.js +3 -3
  42. package/build/cjs/type/integer/integer.js +3 -6
  43. package/build/cjs/type/intersect/intersect-create.d.ts +1 -1
  44. package/build/cjs/type/intersect/intersect-create.js +6 -6
  45. package/build/cjs/type/intersect/intersect-evaluated.js +2 -2
  46. package/build/cjs/type/intersect/intersect.js +3 -3
  47. package/build/cjs/type/intrinsic/intrinsic-from-mapped-key.js +4 -2
  48. package/build/cjs/type/intrinsic/intrinsic.js +3 -1
  49. package/build/cjs/type/iterator/iterator.js +3 -8
  50. package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +1 -1
  51. package/build/cjs/type/keyof/keyof-from-mapped-result.js +2 -1
  52. package/build/cjs/type/keyof/keyof.js +3 -3
  53. package/build/cjs/type/literal/literal.js +4 -4
  54. package/build/cjs/type/mapped/mapped-key.js +3 -2
  55. package/build/cjs/type/mapped/mapped-result.js +3 -2
  56. package/build/cjs/type/mapped/mapped.js +2 -3
  57. package/build/cjs/type/never/never.js +3 -6
  58. package/build/cjs/type/not/not.d.ts +1 -1
  59. package/build/cjs/type/not/not.js +3 -7
  60. package/build/cjs/type/null/null.js +3 -6
  61. package/build/cjs/type/number/number.js +3 -6
  62. package/build/cjs/type/object/object.js +13 -12
  63. package/build/cjs/type/omit/omit-from-mapped-key.d.ts +1 -1
  64. package/build/cjs/type/omit/omit-from-mapped-key.js +2 -1
  65. package/build/cjs/type/omit/omit-from-mapped-result.d.ts +1 -1
  66. package/build/cjs/type/omit/omit-from-mapped-result.js +2 -1
  67. package/build/cjs/type/omit/omit.js +4 -4
  68. package/build/cjs/type/optional/optional.js +3 -3
  69. package/build/cjs/type/parameters/parameters.js +2 -3
  70. package/build/cjs/type/partial/partial-from-mapped-result.d.ts +1 -1
  71. package/build/cjs/type/partial/partial-from-mapped-result.js +2 -1
  72. package/build/cjs/type/partial/partial.js +4 -4
  73. package/build/cjs/type/pick/pick-from-mapped-key.d.ts +1 -1
  74. package/build/cjs/type/pick/pick-from-mapped-key.js +2 -1
  75. package/build/cjs/type/pick/pick-from-mapped-result.d.ts +1 -1
  76. package/build/cjs/type/pick/pick-from-mapped-result.js +2 -1
  77. package/build/cjs/type/pick/pick.js +4 -4
  78. package/build/cjs/type/promise/promise.js +3 -8
  79. package/build/cjs/type/readonly/readonly.js +3 -3
  80. package/build/cjs/type/record/record.js +5 -6
  81. package/build/cjs/type/recursive/recursive.js +3 -2
  82. package/build/cjs/type/ref/ref.js +4 -7
  83. package/build/cjs/type/regexp/regexp.js +3 -2
  84. package/build/cjs/type/required/required-from-mapped-result.d.ts +1 -1
  85. package/build/cjs/type/required/required.js +4 -4
  86. package/build/cjs/type/rest/rest.d.ts +1 -1
  87. package/build/cjs/type/rest/rest.js +4 -5
  88. package/build/cjs/type/return-type/return-type.js +3 -3
  89. package/build/cjs/type/string/string.js +3 -2
  90. package/build/cjs/type/symbol/symbol.js +2 -1
  91. package/build/cjs/type/template-literal/template-literal.js +3 -2
  92. package/build/cjs/type/transform/transform.js +1 -3
  93. package/build/cjs/type/tuple/tuple.js +5 -7
  94. package/build/cjs/type/type/javascript.js +13 -13
  95. package/build/cjs/type/type/json.js +35 -35
  96. package/build/cjs/type/uint8array/uint8array.js +3 -2
  97. package/build/cjs/type/undefined/undefined.js +3 -2
  98. package/build/cjs/type/union/union-create.d.ts +1 -1
  99. package/build/cjs/type/union/union-create.js +2 -2
  100. package/build/cjs/type/union/union-evaluated.js +3 -3
  101. package/build/cjs/type/union/union.js +3 -3
  102. package/build/cjs/type/unknown/unknown.js +3 -5
  103. package/build/cjs/type/unsafe/unsafe.js +2 -4
  104. package/build/cjs/type/void/void.js +3 -6
  105. package/build/esm/index.d.mts +1 -0
  106. package/build/esm/index.mjs +1 -0
  107. package/build/esm/system/policy.d.mts +9 -1
  108. package/build/esm/system/policy.mjs +13 -2
  109. package/build/esm/type/any/any.mjs +3 -2
  110. package/build/esm/type/array/array.d.mts +1 -1
  111. package/build/esm/type/array/array.mjs +3 -8
  112. package/build/esm/type/async-iterator/async-iterator.mjs +3 -8
  113. package/build/esm/type/awaited/awaited.mjs +3 -3
  114. package/build/esm/type/bigint/bigint.mjs +3 -6
  115. package/build/esm/type/boolean/boolean.mjs +3 -6
  116. package/build/esm/type/clone/type.d.mts +1 -1
  117. package/build/esm/type/clone/type.mjs +2 -2
  118. package/build/esm/type/composite/composite.mjs +1 -1
  119. package/build/esm/type/const/const.mjs +3 -3
  120. package/build/esm/type/constructor/constructor.mjs +2 -8
  121. package/build/esm/type/constructor-parameters/constructor-parameters.mjs +2 -3
  122. package/build/esm/type/create/immutable.d.mts +2 -0
  123. package/build/esm/type/create/immutable.mjs +37 -0
  124. package/build/esm/type/create/index.d.mts +1 -0
  125. package/build/esm/type/create/index.mjs +1 -0
  126. package/build/esm/type/create/type.d.mts +3 -0
  127. package/build/esm/type/create/type.mjs +15 -0
  128. package/build/esm/type/date/date.mjs +3 -6
  129. package/build/esm/type/discard/discard.d.mts +1 -0
  130. package/build/esm/type/discard/discard.mjs +1 -0
  131. package/build/esm/type/enum/enum.mjs +1 -1
  132. package/build/esm/type/exclude/exclude.mjs +4 -4
  133. package/build/esm/type/extends/extends-from-mapped-key.d.mts +1 -1
  134. package/build/esm/type/extends/extends-from-mapped-key.mjs +2 -1
  135. package/build/esm/type/extends/extends-from-mapped-result.d.mts +1 -1
  136. package/build/esm/type/extends/extends-from-mapped-result.mjs +2 -1
  137. package/build/esm/type/extends/extends.mjs +4 -4
  138. package/build/esm/type/extract/extract.mjs +5 -5
  139. package/build/esm/type/function/function.mjs +2 -8
  140. package/build/esm/type/guard/value.mjs +3 -0
  141. package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +1 -1
  142. package/build/esm/type/indexed/indexed-from-mapped-key.mjs +2 -1
  143. package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +1 -1
  144. package/build/esm/type/indexed/indexed.mjs +10 -6
  145. package/build/esm/type/instance-type/instance-type.mjs +3 -3
  146. package/build/esm/type/integer/integer.mjs +3 -6
  147. package/build/esm/type/intersect/intersect-create.d.mts +1 -1
  148. package/build/esm/type/intersect/intersect-create.mjs +6 -6
  149. package/build/esm/type/intersect/intersect-evaluated.mjs +2 -2
  150. package/build/esm/type/intersect/intersect.mjs +3 -3
  151. package/build/esm/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -2
  152. package/build/esm/type/intrinsic/intrinsic.mjs +3 -1
  153. package/build/esm/type/iterator/iterator.mjs +3 -8
  154. package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +1 -1
  155. package/build/esm/type/keyof/keyof-from-mapped-result.mjs +2 -1
  156. package/build/esm/type/keyof/keyof.mjs +3 -3
  157. package/build/esm/type/literal/literal.mjs +4 -4
  158. package/build/esm/type/mapped/mapped-key.mjs +3 -2
  159. package/build/esm/type/mapped/mapped-result.mjs +3 -2
  160. package/build/esm/type/mapped/mapped.mjs +2 -3
  161. package/build/esm/type/never/never.mjs +3 -6
  162. package/build/esm/type/not/not.d.mts +1 -1
  163. package/build/esm/type/not/not.mjs +3 -7
  164. package/build/esm/type/null/null.mjs +3 -6
  165. package/build/esm/type/number/number.mjs +3 -6
  166. package/build/esm/type/object/object.mjs +14 -13
  167. package/build/esm/type/omit/omit-from-mapped-key.d.mts +1 -1
  168. package/build/esm/type/omit/omit-from-mapped-key.mjs +2 -1
  169. package/build/esm/type/omit/omit-from-mapped-result.d.mts +1 -1
  170. package/build/esm/type/omit/omit-from-mapped-result.mjs +2 -1
  171. package/build/esm/type/omit/omit.mjs +4 -4
  172. package/build/esm/type/optional/optional.mjs +3 -3
  173. package/build/esm/type/parameters/parameters.mjs +2 -3
  174. package/build/esm/type/partial/partial-from-mapped-result.d.mts +1 -1
  175. package/build/esm/type/partial/partial-from-mapped-result.mjs +2 -1
  176. package/build/esm/type/partial/partial.mjs +4 -4
  177. package/build/esm/type/pick/pick-from-mapped-key.d.mts +1 -1
  178. package/build/esm/type/pick/pick-from-mapped-key.mjs +2 -1
  179. package/build/esm/type/pick/pick-from-mapped-result.d.mts +1 -1
  180. package/build/esm/type/pick/pick-from-mapped-result.mjs +2 -1
  181. package/build/esm/type/pick/pick.mjs +4 -4
  182. package/build/esm/type/promise/promise.mjs +3 -8
  183. package/build/esm/type/readonly/readonly.mjs +3 -3
  184. package/build/esm/type/record/record.mjs +5 -6
  185. package/build/esm/type/recursive/recursive.mjs +3 -2
  186. package/build/esm/type/ref/ref.mjs +4 -7
  187. package/build/esm/type/regexp/regexp.mjs +3 -2
  188. package/build/esm/type/required/required-from-mapped-result.d.mts +1 -1
  189. package/build/esm/type/required/required.mjs +4 -4
  190. package/build/esm/type/rest/rest.d.mts +1 -1
  191. package/build/esm/type/rest/rest.mjs +4 -5
  192. package/build/esm/type/return-type/return-type.mjs +3 -3
  193. package/build/esm/type/string/string.mjs +3 -2
  194. package/build/esm/type/symbol/symbol.mjs +2 -1
  195. package/build/esm/type/template-literal/template-literal.mjs +3 -2
  196. package/build/esm/type/transform/transform.mjs +1 -3
  197. package/build/esm/type/tuple/tuple.mjs +5 -7
  198. package/build/esm/type/type/javascript.mjs +13 -13
  199. package/build/esm/type/type/json.mjs +35 -35
  200. package/build/esm/type/uint8array/uint8array.mjs +3 -2
  201. package/build/esm/type/undefined/undefined.mjs +3 -2
  202. package/build/esm/type/union/union-create.d.mts +1 -1
  203. package/build/esm/type/union/union-create.mjs +2 -2
  204. package/build/esm/type/union/union-evaluated.mjs +3 -3
  205. package/build/esm/type/union/union.mjs +3 -3
  206. package/build/esm/type/unknown/unknown.mjs +3 -5
  207. package/build/esm/type/unsafe/unsafe.mjs +2 -4
  208. package/build/esm/type/void/void.mjs +3 -6
  209. package/package.json +1 -1
@@ -1,13 +1,13 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { ReadonlyKind } from '../symbols/index.mjs';
2
- import { CloneType } from '../clone/type.mjs';
3
3
  import { Discard } from '../discard/index.mjs';
4
4
  import { ReadonlyFromMappedResult } from './readonly-from-mapped-result.mjs';
5
5
  import { IsMappedResult } from '../guard/kind.mjs';
6
6
  function RemoveReadonly(schema) {
7
- return Discard(CloneType(schema), [ReadonlyKind]);
7
+ return CreateType(Discard(schema, [ReadonlyKind]));
8
8
  }
9
9
  function AddReadonly(schema) {
10
- return { ...CloneType(schema), [ReadonlyKind]: 'Readonly' };
10
+ return CreateType({ ...schema, [ReadonlyKind]: 'Readonly' });
11
11
  }
12
12
  // prettier-ignore
13
13
  function ReadonlyWithFlag(schema, F) {
@@ -1,3 +1,4 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Object } from '../object/index.mjs';
2
3
  import { Never } from '../never/index.mjs';
3
4
  import { Union } from '../union/index.mjs';
@@ -5,7 +6,6 @@ import { IsTemplateLiteralFinite } from '../template-literal/index.mjs';
5
6
  import { PatternStringExact, PatternNumberExact, PatternNeverExact } from '../patterns/index.mjs';
6
7
  import { IndexPropertyKeys } from '../indexed/index.mjs';
7
8
  import { Kind, Hint } from '../symbols/index.mjs';
8
- import { CloneType } from '../clone/type.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  // ValueGuard
11
11
  // ------------------------------------------------------------------
@@ -19,12 +19,11 @@ import { IsInteger, IsLiteral, IsAny, IsNever, IsNumber, IsString, IsRegExp, IsT
19
19
  // ------------------------------------------------------------------
20
20
  // prettier-ignore
21
21
  function RecordCreateFromPattern(pattern, T, options) {
22
- return {
23
- ...options,
22
+ return CreateType({
24
23
  [Kind]: 'Record',
25
24
  type: 'object',
26
- patternProperties: { [pattern]: CloneType(T) }
27
- };
25
+ patternProperties: { [pattern]: T }
26
+ }, options);
28
27
  }
29
28
  // ------------------------------------------------------------------
30
29
  // RecordCreateFromKeys
@@ -33,7 +32,7 @@ function RecordCreateFromPattern(pattern, T, options) {
33
32
  function RecordCreateFromKeys(K, T, options) {
34
33
  const Acc = {};
35
34
  for (const K2 of K)
36
- Acc[K2] = CloneType(T);
35
+ Acc[K2] = T;
37
36
  return Object(Acc, { ...options, [Hint]: 'Record' });
38
37
  }
39
38
  // prettier-ignore
@@ -1,4 +1,5 @@
1
1
  import { CloneType } from '../clone/type.mjs';
2
+ import { CreateType } from '../create/type.mjs';
2
3
  import { IsUndefined } from '../guard/value.mjs';
3
4
  import { Kind, Hint } from '../symbols/index.mjs';
4
5
  // Auto Tracked For Recursive Types without ID's
@@ -7,8 +8,8 @@ let Ordinal = 0;
7
8
  export function Recursive(callback, options = {}) {
8
9
  if (IsUndefined(options.$id))
9
10
  options.$id = `T${Ordinal++}`;
10
- const thisType = callback({ [Kind]: 'This', $ref: `${options.$id}` });
11
+ const thisType = CloneType(callback({ [Kind]: 'This', $ref: `${options.$id}` }));
11
12
  thisType.$id = options.$id;
12
13
  // prettier-ignore
13
- return CloneType({ ...options, [Hint]: 'Recursive', ...thisType });
14
+ return CreateType({ [Hint]: 'Recursive', ...thisType }, options);
14
15
  }
@@ -1,17 +1,14 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Kind } from '../symbols/index.mjs';
2
3
  // ------------------------------------------------------------------
3
4
  // ValueGuard
4
5
  // ------------------------------------------------------------------
5
6
  import { IsString, IsUndefined } from '../guard/value.mjs';
6
7
  /** `[Json]` Creates a Ref type. */
7
- export function Ref(unresolved, options = {}) {
8
+ export function Ref(unresolved, options) {
8
9
  if (IsString(unresolved))
9
- return { ...options, [Kind]: 'Ref', $ref: unresolved };
10
+ return CreateType({ [Kind]: 'Ref', $ref: unresolved }, options);
10
11
  if (IsUndefined(unresolved.$id))
11
12
  throw new Error('Reference target type must specify an $id');
12
- return {
13
- ...options,
14
- [Kind]: 'Ref',
15
- $ref: unresolved.$id,
16
- };
13
+ return CreateType({ [Kind]: 'Ref', $ref: unresolved.$id }, options);
17
14
  }
@@ -1,7 +1,8 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { IsString } from '../guard/value.mjs';
2
3
  import { Kind } from '../symbols/index.mjs';
3
4
  /** `[JavaScript]` Creates a RegExp type */
4
- export function RegExp(unresolved, options = {}) {
5
+ export function RegExp(unresolved, options) {
5
6
  const expr = IsString(unresolved) ? new globalThis.RegExp(unresolved) : unresolved;
6
- return { ...options, [Kind]: 'RegExp', type: 'RegExp', source: expr.source, flags: expr.flags };
7
+ return CreateType({ [Kind]: 'RegExp', type: 'RegExp', source: expr.source, flags: expr.flags }, options);
7
8
  }
@@ -8,5 +8,5 @@ type TFromProperties<P extends TProperties> = ({
8
8
  });
9
9
  type TFromMappedResult<R extends TMappedResult> = (Evaluate<TFromProperties<R['properties']>>);
10
10
  export type TRequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (Ensure<TMappedResult<P>>);
11
- export declare function RequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options: SchemaOptions): TMappedResult<P>;
11
+ export declare function RequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options?: SchemaOptions): TMappedResult<P>;
12
12
  export {};
@@ -1,8 +1,8 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Intersect } from '../intersect/index.mjs';
2
3
  import { Union } from '../union/index.mjs';
3
4
  import { Object } from '../object/index.mjs';
4
5
  import { OptionalKind, TransformKind } from '../symbols/index.mjs';
5
- import { CloneType } from '../clone/type.mjs';
6
6
  import { Discard } from '../discard/index.mjs';
7
7
  import { RequiredFromMappedResult } from './required-from-mapped-result.mjs';
8
8
  // ------------------------------------------------------------------
@@ -31,13 +31,13 @@ function RequiredResolve(T) {
31
31
  Object({}));
32
32
  }
33
33
  /** `[Json]` Constructs a type where all properties are required */
34
- export function Required(T, options = {}) {
34
+ export function Required(T, options) {
35
35
  if (IsMappedResult(T)) {
36
36
  return RequiredFromMappedResult(T, options);
37
37
  }
38
38
  else {
39
39
  const D = Discard(T, [TransformKind, '$id', 'required']);
40
- const R = CloneType(RequiredResolve(T), options);
41
- return { ...D, ...R };
40
+ const R = RequiredResolve(T);
41
+ return CreateType({ ...D, ...R }, options);
42
42
  }
43
43
  }
@@ -2,7 +2,7 @@ import type { TSchema } from '../schema/index.mjs';
2
2
  import type { TIntersect } from '../intersect/index.mjs';
3
3
  import type { TUnion } from '../union/index.mjs';
4
4
  import type { TTuple } from '../tuple/index.mjs';
5
- type TRestResolve<T extends TSchema> = T extends TIntersect<infer S> ? [...S] : T extends TUnion<infer S> ? [...S] : T extends TTuple<infer S> ? [...S] : [
5
+ type TRestResolve<T extends TSchema> = T extends TIntersect<infer S extends TSchema[]> ? S : T extends TUnion<infer S extends TSchema[]> ? S : T extends TTuple<infer S extends TSchema[]> ? S : [
6
6
  ];
7
7
  export type TRest<T extends TSchema> = TRestResolve<T>;
8
8
  /** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
@@ -1,16 +1,15 @@
1
- import { CloneRest } from '../clone/type.mjs';
2
1
  // ------------------------------------------------------------------
3
2
  // TypeGuard
4
3
  // ------------------------------------------------------------------
5
4
  import { IsIntersect, IsUnion, IsTuple } from '../guard/kind.mjs';
6
5
  // prettier-ignore
7
6
  function RestResolve(T) {
8
- return (IsIntersect(T) ? CloneRest(T.allOf) :
9
- IsUnion(T) ? CloneRest(T.anyOf) :
10
- IsTuple(T) ? CloneRest(T.items ?? []) :
7
+ return (IsIntersect(T) ? T.allOf :
8
+ IsUnion(T) ? T.anyOf :
9
+ IsTuple(T) ? T.items ?? [] :
11
10
  []);
12
11
  }
13
12
  /** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
14
13
  export function Rest(T) {
15
- return CloneRest(RestResolve(T));
14
+ return RestResolve(T);
16
15
  }
@@ -1,5 +1,5 @@
1
- import { CloneType } from '../clone/type.mjs';
1
+ import { CreateType } from '../create/type.mjs';
2
2
  /** `[JavaScript]` Extracts the ReturnType from the given Function type */
3
- export function ReturnType(schema, options = {}) {
4
- return CloneType(schema.returns, options);
3
+ export function ReturnType(schema, options) {
4
+ return CreateType(schema.returns, options);
5
5
  }
@@ -1,5 +1,6 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Kind } from '../symbols/index.mjs';
2
3
  /** `[Json]` Creates a String type */
3
- export function String(options = {}) {
4
- return { ...options, [Kind]: 'String', type: 'string' };
4
+ export function String(options) {
5
+ return CreateType({ [Kind]: 'String', type: 'string' }, options);
5
6
  }
@@ -1,5 +1,6 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Kind } from '../symbols/index.mjs';
2
3
  /** `[JavaScript]` Creates a Symbol type */
3
4
  export function Symbol(options) {
4
- return { ...options, [Kind]: 'Symbol', type: 'symbol' };
5
+ return CreateType({ [Kind]: 'Symbol', type: 'symbol' }, options);
5
6
  }
@@ -1,12 +1,13 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { TemplateLiteralSyntax } from './syntax.mjs';
2
3
  import { TemplateLiteralPattern } from './pattern.mjs';
3
4
  import { IsString } from '../guard/value.mjs';
4
5
  import { Kind } from '../symbols/index.mjs';
5
6
  /** `[Json]` Creates a TemplateLiteral type */
6
7
  // prettier-ignore
7
- export function TemplateLiteral(unresolved, options = {}) {
8
+ export function TemplateLiteral(unresolved, options) {
8
9
  const pattern = IsString(unresolved)
9
10
  ? TemplateLiteralPattern(TemplateLiteralSyntax(unresolved))
10
11
  : TemplateLiteralPattern(unresolved);
11
- return { ...options, [Kind]: 'TemplateLiteral', type: 'string', pattern };
12
+ return CreateType({ [Kind]: 'TemplateLiteral', type: 'string', pattern }, options);
12
13
  }
@@ -1,5 +1,4 @@
1
1
  import { TransformKind } from '../symbols/index.mjs';
2
- import { CloneType } from '../clone/type.mjs';
3
2
  // ------------------------------------------------------------------
4
3
  // TypeGuard
5
4
  // ------------------------------------------------------------------
@@ -32,8 +31,7 @@ export class TransformEncodeBuilder {
32
31
  return { ...schema, [TransformKind]: Codec };
33
32
  }
34
33
  Encode(encode) {
35
- const schema = CloneType(this.schema);
36
- return (IsTransform(schema) ? this.EncodeTransform(encode, schema) : this.EncodeSchema(encode, schema));
34
+ return (IsTransform(this.schema) ? this.EncodeTransform(encode, this.schema) : this.EncodeSchema(encode, this.schema));
37
35
  }
38
36
  }
39
37
  /** `[Json]` Creates a Transform type */
@@ -1,11 +1,9 @@
1
- import { CloneRest } from '../clone/type.mjs';
1
+ import { CreateType } from '../create/type.mjs';
2
2
  import { Kind } from '../symbols/index.mjs';
3
3
  /** `[Json]` Creates a Tuple type */
4
- export function Tuple(items, options = {}) {
5
- // return TupleResolver.Resolve(T)
6
- const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
4
+ export function Tuple(items, options) {
7
5
  // prettier-ignore
8
- return (items.length > 0 ?
9
- { ...options, [Kind]: 'Tuple', type: 'array', items: CloneRest(items), additionalItems, minItems, maxItems } :
10
- { ...options, [Kind]: 'Tuple', type: 'array', minItems, maxItems });
6
+ return CreateType(items.length > 0 ?
7
+ { [Kind]: 'Tuple', type: 'array', items, additionalItems: false, minItems: items.length, maxItems: items.length } :
8
+ { [Kind]: 'Tuple', type: 'array', minItems: items.length, maxItems: items.length }, options);
11
9
  }
@@ -19,19 +19,19 @@ import { Void } from '../void/index.mjs';
19
19
  /** JavaScript Type Builder with Static Resolution for TypeScript */
20
20
  export class JavaScriptTypeBuilder extends JsonTypeBuilder {
21
21
  /** `[JavaScript]` Creates a AsyncIterator type */
22
- AsyncIterator(items, options = {}) {
22
+ AsyncIterator(items, options) {
23
23
  return AsyncIterator(items, options);
24
24
  }
25
25
  /** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
26
- Awaited(schema, options = {}) {
26
+ Awaited(schema, options) {
27
27
  return Awaited(schema, options);
28
28
  }
29
29
  /** `[JavaScript]` Creates a BigInt type */
30
- BigInt(options = {}) {
30
+ BigInt(options) {
31
31
  return BigInt(options);
32
32
  }
33
33
  /** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
34
- ConstructorParameters(schema, options = {}) {
34
+ ConstructorParameters(schema, options) {
35
35
  return ConstructorParameters(schema, options);
36
36
  }
37
37
  /** `[JavaScript]` Creates a Constructor type */
@@ -47,27 +47,27 @@ export class JavaScriptTypeBuilder extends JsonTypeBuilder {
47
47
  return FunctionType(parameters, returns, options);
48
48
  }
49
49
  /** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
50
- InstanceType(schema, options = {}) {
50
+ InstanceType(schema, options) {
51
51
  return InstanceType(schema, options);
52
52
  }
53
53
  /** `[JavaScript]` Creates an Iterator type */
54
- Iterator(items, options = {}) {
54
+ Iterator(items, options) {
55
55
  return Iterator(items, options);
56
56
  }
57
57
  /** `[JavaScript]` Extracts the Parameters from the given Function type */
58
- Parameters(schema, options = {}) {
58
+ Parameters(schema, options) {
59
59
  return Parameters(schema, options);
60
60
  }
61
61
  /** `[JavaScript]` Creates a Promise type */
62
- Promise(item, options = {}) {
62
+ Promise(item, options) {
63
63
  return Promise(item, options);
64
64
  }
65
65
  /** `[JavaScript]` Creates a RegExp type */
66
- RegExp(unresolved, options = {}) {
66
+ RegExp(unresolved, options) {
67
67
  return RegExp(unresolved, options);
68
68
  }
69
69
  /** `[JavaScript]` Extracts the ReturnType from the given Function type */
70
- ReturnType(schema, options = {}) {
70
+ ReturnType(schema, options) {
71
71
  return ReturnType(schema, options);
72
72
  }
73
73
  /** `[JavaScript]` Creates a Symbol type */
@@ -75,15 +75,15 @@ export class JavaScriptTypeBuilder extends JsonTypeBuilder {
75
75
  return Symbol(options);
76
76
  }
77
77
  /** `[JavaScript]` Creates a Undefined type */
78
- Undefined(options = {}) {
78
+ Undefined(options) {
79
79
  return Undefined(options);
80
80
  }
81
81
  /** `[JavaScript]` Creates a Uint8Array type */
82
- Uint8Array(options = {}) {
82
+ Uint8Array(options) {
83
83
  return Uint8Array(options);
84
84
  }
85
85
  /** `[JavaScript]` Creates a Void type */
86
- Void(options = {}) {
86
+ Void(options) {
87
87
  return Void(options);
88
88
  }
89
89
  }
@@ -67,19 +67,19 @@ export class JsonTypeBuilder {
67
67
  // Types
68
68
  // ------------------------------------------------------------------------
69
69
  /** `[Json]` Creates an Any type */
70
- Any(options = {}) {
70
+ Any(options) {
71
71
  return Any(options);
72
72
  }
73
73
  /** `[Json]` Creates an Array type */
74
- Array(schema, options = {}) {
74
+ Array(schema, options) {
75
75
  return Array(schema, options);
76
76
  }
77
77
  /** `[Json]` Creates a Boolean type */
78
- Boolean(options = {}) {
78
+ Boolean(options) {
79
79
  return Boolean(options);
80
80
  }
81
81
  /** `[Json]` Intrinsic function to Capitalize LiteralString types */
82
- Capitalize(schema, options = {}) {
82
+ Capitalize(schema, options) {
83
83
  return Capitalize(schema, options);
84
84
  }
85
85
  /** `[Json]` Creates a Composite object type */
@@ -87,7 +87,7 @@ export class JsonTypeBuilder {
87
87
  return Composite(schemas, options); // (error) TS 5.4.0-dev - review TComposite implementation
88
88
  }
89
89
  /** `[JavaScript]` Creates a readonly const type from the given value. */
90
- Const(value, options = {}) {
90
+ Const(value, options) {
91
91
  return Const(value, options);
92
92
  }
93
93
  /** `[Json]` Creates a dereferenced type */
@@ -95,51 +95,51 @@ export class JsonTypeBuilder {
95
95
  return Deref(schema, references);
96
96
  }
97
97
  /** `[Json]` Creates a Enum type */
98
- Enum(item, options = {}) {
98
+ Enum(item, options) {
99
99
  return Enum(item, options);
100
100
  }
101
101
  /** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
102
- Exclude(unionType, excludedMembers, options = {}) {
102
+ Exclude(unionType, excludedMembers, options) {
103
103
  return Exclude(unionType, excludedMembers, options);
104
104
  }
105
105
  /** `[Json]` Creates a Conditional type */
106
- Extends(L, R, T, F, options = {}) {
106
+ Extends(L, R, T, F, options) {
107
107
  return Extends(L, R, T, F, options);
108
108
  }
109
109
  /** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
110
- Extract(type, union, options = {}) {
110
+ Extract(type, union, options) {
111
111
  return Extract(type, union, options);
112
112
  }
113
113
  /** `[Json]` Returns an Indexed property type for the given keys */
114
- Index(schema, unresolved, options = {}) {
114
+ Index(schema, unresolved, options) {
115
115
  return Index(schema, unresolved, options);
116
116
  }
117
117
  /** `[Json]` Creates an Integer type */
118
- Integer(options = {}) {
118
+ Integer(options) {
119
119
  return Integer(options);
120
120
  }
121
121
  /** `[Json]` Creates an Intersect type */
122
- Intersect(T, options = {}) {
122
+ Intersect(T, options) {
123
123
  return Intersect(T, options);
124
124
  }
125
125
  /** `[Json]` Creates a KeyOf type */
126
- KeyOf(schema, options = {}) {
126
+ KeyOf(schema, options) {
127
127
  return KeyOf(schema, options);
128
128
  }
129
129
  /** `[Json]` Creates a Literal type */
130
- Literal(value, options = {}) {
130
+ Literal(value, options) {
131
131
  return Literal(value, options);
132
132
  }
133
133
  /** `[Json]` Intrinsic function to Lowercase LiteralString types */
134
- Lowercase(schema, options = {}) {
134
+ Lowercase(schema, options) {
135
135
  return Lowercase(schema, options);
136
136
  }
137
137
  /** `[Json]` Creates a Mapped object type */
138
- Mapped(key, map, options = {}) {
138
+ Mapped(key, map, options) {
139
139
  return Mapped(key, map, options);
140
140
  }
141
141
  /** `[Json]` Creates a Never type */
142
- Never(options = {}) {
142
+ Never(options) {
143
143
  return Never(options);
144
144
  }
145
145
  /** `[Json]` Creates a Not type */
@@ -147,43 +147,43 @@ export class JsonTypeBuilder {
147
147
  return Not(schema, options);
148
148
  }
149
149
  /** `[Json]` Creates a Null type */
150
- Null(options = {}) {
150
+ Null(options) {
151
151
  return Null(options);
152
152
  }
153
153
  /** `[Json]` Creates a Number type */
154
- Number(options = {}) {
154
+ Number(options) {
155
155
  return Number(options);
156
156
  }
157
157
  /** `[Json]` Creates an Object type */
158
- Object(properties, options = {}) {
158
+ Object(properties, options) {
159
159
  return Object(properties, options);
160
160
  }
161
161
  /** `[Json]` Constructs a type whose keys are omitted from the given type */
162
- Omit(schema, unresolved, options = {}) {
162
+ Omit(schema, unresolved, options) {
163
163
  return Omit(schema, unresolved, options);
164
164
  }
165
165
  /** `[Json]` Constructs a type where all properties are optional */
166
- Partial(schema, options = {}) {
166
+ Partial(schema, options) {
167
167
  return Partial(schema, options);
168
168
  }
169
169
  /** `[Json]` Constructs a type whose keys are picked from the given type */
170
- Pick(schema, unresolved, options = {}) {
170
+ Pick(schema, unresolved, options) {
171
171
  return Pick(schema, unresolved, options);
172
172
  }
173
173
  /** `[Json]` Creates a Record type */
174
- Record(key, schema, options = {}) {
174
+ Record(key, schema, options) {
175
175
  return Record(key, schema, options);
176
176
  }
177
177
  /** `[Json]` Creates a Recursive type */
178
- Recursive(callback, options = {}) {
178
+ Recursive(callback, options) {
179
179
  return Recursive(callback, options);
180
180
  }
181
181
  /** `[Json]` Creates a Ref type. */
182
- Ref(unresolved, options = {}) {
182
+ Ref(unresolved, options) {
183
183
  return Ref(unresolved, options);
184
184
  }
185
185
  /** `[Json]` Constructs a type where all properties are required */
186
- Required(schema, options = {}) {
186
+ Required(schema, options) {
187
187
  return Required(schema, options);
188
188
  }
189
189
  /** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
@@ -191,11 +191,11 @@ export class JsonTypeBuilder {
191
191
  return Rest(schema);
192
192
  }
193
193
  /** `[Json]` Creates a String type */
194
- String(options = {}) {
194
+ String(options) {
195
195
  return String(options);
196
196
  }
197
197
  /** `[Json]` Creates a TemplateLiteral type */
198
- TemplateLiteral(unresolved, options = {}) {
198
+ TemplateLiteral(unresolved, options) {
199
199
  return TemplateLiteral(unresolved, options);
200
200
  }
201
201
  /** `[Json]` Creates a Transform type */
@@ -203,27 +203,27 @@ export class JsonTypeBuilder {
203
203
  return Transform(schema);
204
204
  }
205
205
  /** `[Json]` Creates a Tuple type */
206
- Tuple(items, options = {}) {
206
+ Tuple(items, options) {
207
207
  return Tuple(items, options);
208
208
  }
209
209
  /** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
210
- Uncapitalize(schema, options = {}) {
210
+ Uncapitalize(schema, options) {
211
211
  return Uncapitalize(schema, options);
212
212
  }
213
213
  /** `[Json]` Creates a Union type */
214
- Union(schemas, options = {}) {
214
+ Union(schemas, options) {
215
215
  return Union(schemas, options);
216
216
  }
217
217
  /** `[Json]` Creates an Unknown type */
218
- Unknown(options = {}) {
218
+ Unknown(options) {
219
219
  return Unknown(options);
220
220
  }
221
221
  /** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
222
- Unsafe(options = {}) {
222
+ Unsafe(options) {
223
223
  return Unsafe(options);
224
224
  }
225
225
  /** `[Json]` Intrinsic function to Uppercase LiteralString types */
226
- Uppercase(schema, options = {}) {
226
+ Uppercase(schema, options) {
227
227
  return Uppercase(schema, options);
228
228
  }
229
229
  }
@@ -1,5 +1,6 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Kind } from '../symbols/index.mjs';
2
3
  /** `[JavaScript]` Creates a Uint8Array type */
3
- export function Uint8Array(options = {}) {
4
- return { ...options, [Kind]: 'Uint8Array', type: 'Uint8Array' };
4
+ export function Uint8Array(options) {
5
+ return CreateType({ [Kind]: 'Uint8Array', type: 'Uint8Array' }, options);
5
6
  }
@@ -1,5 +1,6 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Kind } from '../symbols/index.mjs';
2
3
  /** `[JavaScript]` Creates a Undefined type */
3
- export function Undefined(options = {}) {
4
- return { ...options, [Kind]: 'Undefined', type: 'undefined' };
4
+ export function Undefined(options) {
5
+ return CreateType({ [Kind]: 'Undefined', type: 'undefined' }, options);
5
6
  }
@@ -1,3 +1,3 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index.mjs';
2
2
  import { TUnion } from './union-type.mjs';
3
- export declare function UnionCreate<T extends TSchema[]>(T: [...T], options: SchemaOptions): TUnion<T>;
3
+ export declare function UnionCreate<T extends TSchema[]>(T: [...T], options?: SchemaOptions): TUnion<T>;
@@ -1,5 +1,5 @@
1
- import { CloneRest } from '../clone/type.mjs';
1
+ import { CreateType } from '../create/type.mjs';
2
2
  import { Kind } from '../symbols/index.mjs';
3
3
  export function UnionCreate(T, options) {
4
- return { ...options, [Kind]: 'Union', anyOf: CloneRest(T) };
4
+ return CreateType({ [Kind]: 'Union', anyOf: T }, options);
5
5
  }
@@ -1,5 +1,5 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { OptionalKind } from '../symbols/index.mjs';
2
- import { CloneType } from '../clone/type.mjs';
3
3
  import { Discard } from '../discard/index.mjs';
4
4
  import { Never } from '../never/index.mjs';
5
5
  import { Optional } from '../optional/index.mjs';
@@ -27,9 +27,9 @@ function ResolveUnion(T, options) {
27
27
  : UnionCreate(RemoveOptionalFromRest(T), options));
28
28
  }
29
29
  /** `[Json]` Creates an evaluated Union type */
30
- export function UnionEvaluated(T, options = {}) {
30
+ export function UnionEvaluated(T, options) {
31
31
  // prettier-ignore
32
32
  return (T.length === 0 ? Never(options) :
33
- T.length === 1 ? CloneType(T[0], options) :
33
+ T.length === 1 ? CreateType(T[0], options) :
34
34
  ResolveUnion(T, options));
35
35
  }
@@ -1,10 +1,10 @@
1
1
  import { Never } from '../never/index.mjs';
2
- import { CloneType } from '../clone/type.mjs';
2
+ import { CreateType } from '../create/type.mjs';
3
3
  import { UnionCreate } from './union-create.mjs';
4
4
  /** `[Json]` Creates a Union type */
5
- export function Union(T, options = {}) {
5
+ export function Union(T, options) {
6
6
  // prettier-ignore
7
7
  return (T.length === 0 ? Never(options) :
8
- T.length === 1 ? CloneType(T[0], options) :
8
+ T.length === 1 ? CreateType(T[0], options) :
9
9
  UnionCreate(T, options));
10
10
  }
@@ -1,8 +1,6 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Kind } from '../symbols/index.mjs';
2
3
  /** `[Json]` Creates an Unknown type */
3
- export function Unknown(options = {}) {
4
- return {
5
- ...options,
6
- [Kind]: 'Unknown',
7
- };
4
+ export function Unknown(options) {
5
+ return CreateType({ [Kind]: 'Unknown' }, options);
8
6
  }
@@ -1,8 +1,6 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Kind } from '../symbols/index.mjs';
2
3
  /** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
3
4
  export function Unsafe(options = {}) {
4
- return {
5
- ...options,
6
- [Kind]: options[Kind] ?? 'Unsafe',
7
- };
5
+ return CreateType({ [Kind]: options[Kind] ?? 'Unsafe' }, options);
8
6
  }
@@ -1,9 +1,6 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Kind } from '../symbols/index.mjs';
2
3
  /** `[JavaScript]` Creates a Void type */
3
- export function Void(options = {}) {
4
- return {
5
- ...options,
6
- [Kind]: 'Void',
7
- type: 'void',
8
- };
4
+ export function Void(options) {
5
+ return CreateType({ [Kind]: 'Void', type: 'void' }, options);
9
6
  }