@sinclair/typebox 0.33.22 → 0.34.1

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 (202) hide show
  1. package/build/cjs/compiler/compiler.d.ts +2 -2
  2. package/build/cjs/compiler/compiler.js +13 -2
  3. package/build/cjs/errors/errors.js +7 -0
  4. package/build/cjs/index.d.ts +1 -2
  5. package/build/cjs/index.js +1 -2
  6. package/build/cjs/syntax/parse.d.ts +14 -15
  7. package/build/cjs/syntax/parse.js +6 -5
  8. package/build/cjs/syntax/runtime.d.ts +20 -4
  9. package/build/cjs/syntax/runtime.js +183 -28
  10. package/build/cjs/syntax/static.d.ts +107 -23
  11. package/build/cjs/type/array/array.d.ts +1 -1
  12. package/build/cjs/type/awaited/awaited.d.ts +8 -3
  13. package/build/cjs/type/awaited/awaited.js +20 -20
  14. package/build/cjs/type/computed/computed.d.ts +9 -0
  15. package/build/cjs/type/computed/computed.js +10 -0
  16. package/build/cjs/type/computed/index.d.ts +1 -0
  17. package/build/cjs/type/{deref → computed}/index.js +1 -1
  18. package/build/cjs/type/guard/kind.d.ts +12 -4
  19. package/build/cjs/type/guard/kind.js +15 -0
  20. package/build/cjs/type/guard/type.d.ts +9 -3
  21. package/build/cjs/type/guard/type.js +19 -0
  22. package/build/cjs/type/index.d.ts +1 -2
  23. package/build/cjs/type/index.js +1 -2
  24. package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +6 -6
  25. package/build/cjs/type/indexed/indexed-from-mapped-key.js +10 -10
  26. package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +5 -5
  27. package/build/cjs/type/indexed/indexed-from-mapped-result.js +11 -10
  28. package/build/cjs/type/indexed/indexed-property-keys.d.ts +6 -6
  29. package/build/cjs/type/indexed/indexed-property-keys.js +14 -14
  30. package/build/cjs/type/indexed/indexed.d.ts +34 -20
  31. package/build/cjs/type/indexed/indexed.js +59 -46
  32. package/build/cjs/type/intersect/intersect-evaluated.d.ts +6 -6
  33. package/build/cjs/type/intersect/intersect-evaluated.js +16 -16
  34. package/build/cjs/type/intersect/intersect.d.ts +2 -2
  35. package/build/cjs/type/intersect/intersect.js +6 -6
  36. package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +6 -6
  37. package/build/cjs/type/keyof/keyof-from-mapped-result.js +10 -10
  38. package/build/cjs/type/keyof/keyof-property-keys.d.ts +7 -7
  39. package/build/cjs/type/keyof/keyof-property-keys.js +22 -22
  40. package/build/cjs/type/keyof/keyof.d.ts +11 -6
  41. package/build/cjs/type/keyof/keyof.js +22 -13
  42. package/build/cjs/type/module/compute.d.ts +54 -0
  43. package/build/cjs/type/module/compute.js +154 -0
  44. package/build/cjs/type/module/index.d.ts +1 -0
  45. package/build/cjs/type/{strict → module}/index.js +1 -1
  46. package/build/cjs/type/module/infer.d.ts +43 -0
  47. package/build/cjs/type/module/infer.js +3 -0
  48. package/build/cjs/type/module/module.d.ts +27 -0
  49. package/build/cjs/type/module/module.js +37 -0
  50. package/build/cjs/type/not/not.d.ts +1 -1
  51. package/build/cjs/type/not/not.js +2 -2
  52. package/build/cjs/type/omit/omit-from-mapped-key.d.ts +6 -6
  53. package/build/cjs/type/omit/omit-from-mapped-key.js +10 -12
  54. package/build/cjs/type/omit/omit-from-mapped-result.d.ts +5 -5
  55. package/build/cjs/type/omit/omit-from-mapped-result.js +10 -10
  56. package/build/cjs/type/omit/omit.d.ts +26 -14
  57. package/build/cjs/type/omit/omit.js +46 -35
  58. package/build/cjs/type/partial/partial.d.ts +11 -7
  59. package/build/cjs/type/partial/partial.js +36 -24
  60. package/build/cjs/type/pick/pick-from-mapped-key.d.ts +6 -6
  61. package/build/cjs/type/pick/pick-from-mapped-key.js +10 -10
  62. package/build/cjs/type/pick/pick-from-mapped-result.d.ts +5 -5
  63. package/build/cjs/type/pick/pick-from-mapped-result.js +10 -10
  64. package/build/cjs/type/pick/pick.d.ts +25 -15
  65. package/build/cjs/type/pick/pick.js +47 -36
  66. package/build/cjs/type/record/record.d.ts +4 -2
  67. package/build/cjs/type/record/record.js +31 -28
  68. package/build/cjs/type/ref/ref.d.ts +4 -7
  69. package/build/cjs/type/ref/ref.js +3 -11
  70. package/build/cjs/type/required/required.d.ts +12 -8
  71. package/build/cjs/type/required/required.js +37 -25
  72. package/build/cjs/type/static/static.d.ts +1 -1
  73. package/build/cjs/type/tuple/tuple.d.ts +1 -1
  74. package/build/cjs/type/tuple/tuple.js +4 -4
  75. package/build/cjs/type/type/javascript.d.ts +10 -10
  76. package/build/cjs/type/type/javascript.js +6 -6
  77. package/build/cjs/type/type/json.d.ts +45 -68
  78. package/build/cjs/type/type/json.js +82 -98
  79. package/build/cjs/type/type/type.d.ts +1 -2
  80. package/build/cjs/type/type/type.js +55 -57
  81. package/build/cjs/type/union/union-evaluated.d.ts +6 -6
  82. package/build/cjs/type/union/union-evaluated.js +11 -10
  83. package/build/cjs/type/union/union.d.ts +1 -1
  84. package/build/cjs/type/union/union.js +4 -4
  85. package/build/cjs/value/cast/cast.js +8 -1
  86. package/build/cjs/value/check/check.js +11 -4
  87. package/build/cjs/value/clean/clean.js +8 -1
  88. package/build/cjs/value/convert/convert.js +7 -0
  89. package/build/cjs/value/create/create.js +7 -0
  90. package/build/cjs/value/default/default.js +7 -0
  91. package/build/cjs/value/transform/decode.js +18 -7
  92. package/build/cjs/value/transform/encode.js +18 -7
  93. package/build/cjs/value/transform/has.js +18 -18
  94. package/build/esm/compiler/compiler.d.mts +2 -2
  95. package/build/esm/compiler/compiler.mjs +13 -2
  96. package/build/esm/errors/errors.mjs +7 -0
  97. package/build/esm/index.d.mts +1 -2
  98. package/build/esm/index.mjs +1 -2
  99. package/build/esm/syntax/parse.d.mts +14 -15
  100. package/build/esm/syntax/parse.mjs +6 -5
  101. package/build/esm/syntax/runtime.d.mts +20 -4
  102. package/build/esm/syntax/runtime.mjs +183 -28
  103. package/build/esm/syntax/static.d.mts +107 -23
  104. package/build/esm/type/array/array.d.mts +1 -1
  105. package/build/esm/type/awaited/awaited.d.mts +8 -3
  106. package/build/esm/type/awaited/awaited.mjs +20 -20
  107. package/build/esm/type/computed/computed.d.mts +9 -0
  108. package/build/esm/type/computed/computed.mjs +6 -0
  109. package/build/esm/type/computed/index.d.mts +1 -0
  110. package/build/esm/type/computed/index.mjs +1 -0
  111. package/build/esm/type/guard/kind.d.mts +12 -4
  112. package/build/esm/type/guard/kind.mjs +12 -0
  113. package/build/esm/type/guard/type.d.mts +9 -3
  114. package/build/esm/type/guard/type.mjs +17 -0
  115. package/build/esm/type/index.d.mts +1 -2
  116. package/build/esm/type/index.mjs +1 -2
  117. package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +6 -6
  118. package/build/esm/type/indexed/indexed-from-mapped-key.mjs +10 -10
  119. package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +5 -5
  120. package/build/esm/type/indexed/indexed-from-mapped-result.mjs +11 -10
  121. package/build/esm/type/indexed/indexed-property-keys.d.mts +6 -6
  122. package/build/esm/type/indexed/indexed-property-keys.mjs +14 -14
  123. package/build/esm/type/indexed/indexed.d.mts +34 -20
  124. package/build/esm/type/indexed/indexed.mjs +55 -42
  125. package/build/esm/type/intersect/intersect-evaluated.d.mts +6 -6
  126. package/build/esm/type/intersect/intersect-evaluated.mjs +16 -16
  127. package/build/esm/type/intersect/intersect.d.mts +2 -2
  128. package/build/esm/type/intersect/intersect.mjs +6 -6
  129. package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +6 -6
  130. package/build/esm/type/keyof/keyof-from-mapped-result.mjs +10 -10
  131. package/build/esm/type/keyof/keyof-property-keys.d.mts +7 -7
  132. package/build/esm/type/keyof/keyof-property-keys.mjs +22 -22
  133. package/build/esm/type/keyof/keyof.d.mts +11 -6
  134. package/build/esm/type/keyof/keyof.mjs +22 -13
  135. package/build/esm/type/module/compute.d.mts +54 -0
  136. package/build/esm/type/module/compute.mjs +148 -0
  137. package/build/esm/type/module/index.d.mts +1 -0
  138. package/build/esm/type/module/index.mjs +1 -0
  139. package/build/esm/type/module/infer.d.mts +43 -0
  140. package/build/esm/type/module/infer.mjs +1 -0
  141. package/build/esm/type/module/module.d.mts +27 -0
  142. package/build/esm/type/module/module.mjs +31 -0
  143. package/build/esm/type/not/not.d.mts +1 -1
  144. package/build/esm/type/not/not.mjs +2 -2
  145. package/build/esm/type/omit/omit-from-mapped-key.d.mts +6 -6
  146. package/build/esm/type/omit/omit-from-mapped-key.mjs +10 -12
  147. package/build/esm/type/omit/omit-from-mapped-result.d.mts +5 -5
  148. package/build/esm/type/omit/omit-from-mapped-result.mjs +10 -10
  149. package/build/esm/type/omit/omit.d.mts +26 -14
  150. package/build/esm/type/omit/omit.mjs +43 -32
  151. package/build/esm/type/partial/partial.d.mts +11 -7
  152. package/build/esm/type/partial/partial.mjs +29 -17
  153. package/build/esm/type/pick/pick-from-mapped-key.d.mts +6 -6
  154. package/build/esm/type/pick/pick-from-mapped-key.mjs +10 -10
  155. package/build/esm/type/pick/pick-from-mapped-result.d.mts +5 -5
  156. package/build/esm/type/pick/pick-from-mapped-result.mjs +10 -10
  157. package/build/esm/type/pick/pick.d.mts +25 -15
  158. package/build/esm/type/pick/pick.mjs +43 -32
  159. package/build/esm/type/record/record.d.mts +4 -2
  160. package/build/esm/type/record/record.mjs +15 -12
  161. package/build/esm/type/ref/ref.d.mts +4 -7
  162. package/build/esm/type/ref/ref.mjs +3 -11
  163. package/build/esm/type/required/required.d.mts +12 -8
  164. package/build/esm/type/required/required.mjs +33 -21
  165. package/build/esm/type/static/static.d.mts +1 -1
  166. package/build/esm/type/tuple/tuple.d.mts +1 -1
  167. package/build/esm/type/tuple/tuple.mjs +4 -4
  168. package/build/esm/type/type/javascript.d.mts +10 -10
  169. package/build/esm/type/type/javascript.mjs +6 -6
  170. package/build/esm/type/type/json.d.mts +45 -68
  171. package/build/esm/type/type/json.mjs +47 -63
  172. package/build/esm/type/type/type.d.mts +1 -2
  173. package/build/esm/type/type/type.mjs +1 -2
  174. package/build/esm/type/union/union-evaluated.d.mts +6 -6
  175. package/build/esm/type/union/union-evaluated.mjs +11 -10
  176. package/build/esm/type/union/union.d.mts +1 -1
  177. package/build/esm/type/union/union.mjs +4 -4
  178. package/build/esm/value/cast/cast.mjs +9 -2
  179. package/build/esm/value/check/check.mjs +11 -4
  180. package/build/esm/value/clean/clean.mjs +9 -2
  181. package/build/esm/value/convert/convert.mjs +7 -0
  182. package/build/esm/value/create/create.mjs +7 -0
  183. package/build/esm/value/default/default.mjs +7 -0
  184. package/build/esm/value/transform/decode.mjs +13 -2
  185. package/build/esm/value/transform/encode.mjs +13 -2
  186. package/build/esm/value/transform/has.mjs +2 -2
  187. package/package.json +1 -1
  188. package/readme.md +230 -97
  189. package/build/cjs/type/deref/deref.d.ts +0 -22
  190. package/build/cjs/type/deref/deref.js +0 -106
  191. package/build/cjs/type/deref/index.d.ts +0 -1
  192. package/build/cjs/type/strict/index.d.ts +0 -1
  193. package/build/cjs/type/strict/strict.d.ts +0 -12
  194. package/build/cjs/type/strict/strict.js +0 -16
  195. package/build/esm/type/deref/deref.d.mts +0 -22
  196. package/build/esm/type/deref/deref.mjs +0 -102
  197. package/build/esm/type/deref/index.d.mts +0 -1
  198. package/build/esm/type/deref/index.mjs +0 -1
  199. package/build/esm/type/strict/index.d.mts +0 -1
  200. package/build/esm/type/strict/index.mjs +0 -1
  201. package/build/esm/type/strict/strict.d.mts +0 -12
  202. package/build/esm/type/strict/strict.mjs +0 -12
@@ -3,13 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Record = Record;
5
5
  const type_1 = require("../create/type");
6
- const index_1 = require("../object/index");
7
- const index_2 = require("../never/index");
8
- const index_3 = require("../union/index");
9
- const index_4 = require("../template-literal/index");
10
- const index_5 = require("../patterns/index");
11
- const index_6 = require("../indexed/index");
12
- const index_7 = require("../symbols/index");
6
+ const index_1 = require("../computed/index");
7
+ const index_2 = require("../object/index");
8
+ const index_3 = require("../never/index");
9
+ const index_4 = require("../union/index");
10
+ const index_5 = require("../template-literal/index");
11
+ const index_6 = require("../patterns/index");
12
+ const index_7 = require("../indexed/index");
13
+ const index_8 = require("../symbols/index");
13
14
  // ------------------------------------------------------------------
14
15
  // ValueGuard
15
16
  // ------------------------------------------------------------------
@@ -24,7 +25,7 @@ const kind_1 = require("../guard/kind");
24
25
  // prettier-ignore
25
26
  function RecordCreateFromPattern(pattern, T, options) {
26
27
  return (0, type_1.CreateType)({
27
- [index_7.Kind]: 'Record',
28
+ [index_8.Kind]: 'Record',
28
29
  type: 'object',
29
30
  patternProperties: { [pattern]: T }
30
31
  }, options);
@@ -37,17 +38,17 @@ function RecordCreateFromKeys(K, T, options) {
37
38
  const Acc = {};
38
39
  for (const K2 of K)
39
40
  Acc[K2] = T;
40
- return (0, index_1.Object)(Acc, { ...options, [index_7.Hint]: 'Record' });
41
+ return (0, index_2.Object)(Acc, { ...options, [index_8.Hint]: 'Record' });
41
42
  }
42
43
  // prettier-ignore
43
44
  function FromTemplateLiteralKey(K, T, options) {
44
- return ((0, index_4.IsTemplateLiteralFinite)(K)
45
- ? RecordCreateFromKeys((0, index_6.IndexPropertyKeys)(K), T, options)
45
+ return ((0, index_5.IsTemplateLiteralFinite)(K)
46
+ ? RecordCreateFromKeys((0, index_7.IndexPropertyKeys)(K), T, options)
46
47
  : RecordCreateFromPattern(K.pattern, T, options));
47
48
  }
48
49
  // prettier-ignore
49
50
  function FromUnionKey(K, T, options) {
50
- return RecordCreateFromKeys((0, index_6.IndexPropertyKeys)((0, index_3.Union)(K)), T, options);
51
+ return RecordCreateFromKeys((0, index_7.IndexPropertyKeys)((0, index_4.Union)(K)), T, options);
51
52
  }
52
53
  // prettier-ignore
53
54
  function FromLiteralKey(K, T, options) {
@@ -59,39 +60,41 @@ function FromRegExpKey(K, T, options) {
59
60
  }
60
61
  // prettier-ignore
61
62
  function FromStringKey(K, T, options) {
62
- const pattern = (0, value_1.IsUndefined)(K.pattern) ? index_5.PatternStringExact : K.pattern;
63
+ const pattern = (0, value_1.IsUndefined)(K.pattern) ? index_6.PatternStringExact : K.pattern;
63
64
  return RecordCreateFromPattern(pattern, T, options);
64
65
  }
65
66
  // prettier-ignore
66
67
  function FromAnyKey(K, T, options) {
67
- return RecordCreateFromPattern(index_5.PatternStringExact, T, options);
68
+ return RecordCreateFromPattern(index_6.PatternStringExact, T, options);
68
69
  }
69
70
  // prettier-ignore
70
71
  function FromNeverKey(K, T, options) {
71
- return RecordCreateFromPattern(index_5.PatternNeverExact, T, options);
72
+ return RecordCreateFromPattern(index_6.PatternNeverExact, T, options);
72
73
  }
73
74
  // prettier-ignore
74
75
  function FromIntegerKey(_, T, options) {
75
- return RecordCreateFromPattern(index_5.PatternNumberExact, T, options);
76
+ return RecordCreateFromPattern(index_6.PatternNumberExact, T, options);
76
77
  }
77
78
  // prettier-ignore
78
79
  function FromNumberKey(_, T, options) {
79
- return RecordCreateFromPattern(index_5.PatternNumberExact, T, options);
80
+ return RecordCreateFromPattern(index_6.PatternNumberExact, T, options);
80
81
  }
81
82
  // ------------------------------------------------------------------
82
83
  // TRecordOrObject
83
84
  // ------------------------------------------------------------------
84
85
  /** `[Json]` Creates a Record type */
85
- function Record(K, T, options = {}) {
86
+ function Record(key, type, options = {}) {
86
87
  // prettier-ignore
87
- return ((0, kind_1.IsUnion)(K) ? FromUnionKey(K.anyOf, T, options) :
88
- (0, kind_1.IsTemplateLiteral)(K) ? FromTemplateLiteralKey(K, T, options) :
89
- (0, kind_1.IsLiteral)(K) ? FromLiteralKey(K.const, T, options) :
90
- (0, kind_1.IsInteger)(K) ? FromIntegerKey(K, T, options) :
91
- (0, kind_1.IsNumber)(K) ? FromNumberKey(K, T, options) :
92
- (0, kind_1.IsRegExp)(K) ? FromRegExpKey(K, T, options) :
93
- (0, kind_1.IsString)(K) ? FromStringKey(K, T, options) :
94
- (0, kind_1.IsAny)(K) ? FromAnyKey(K, T, options) :
95
- (0, kind_1.IsNever)(K) ? FromNeverKey(K, T, options) :
96
- (0, index_2.Never)(options));
88
+ return ((0, kind_1.IsRef)(type) ? (0, index_1.Computed)('Record', [key, type]) :
89
+ (0, kind_1.IsRef)(key) ? (0, index_1.Computed)('Record', [key, type]) :
90
+ (0, kind_1.IsUnion)(key) ? FromUnionKey(key.anyOf, type, options) :
91
+ (0, kind_1.IsTemplateLiteral)(key) ? FromTemplateLiteralKey(key, type, options) :
92
+ (0, kind_1.IsLiteral)(key) ? FromLiteralKey(key.const, type, options) :
93
+ (0, kind_1.IsInteger)(key) ? FromIntegerKey(key, type, options) :
94
+ (0, kind_1.IsNumber)(key) ? FromNumberKey(key, type, options) :
95
+ (0, kind_1.IsRegExp)(key) ? FromRegExpKey(key, type, options) :
96
+ (0, kind_1.IsString)(key) ? FromStringKey(key, type, options) :
97
+ (0, kind_1.IsAny)(key) ? FromAnyKey(key, type, options) :
98
+ (0, kind_1.IsNever)(key) ? FromNeverKey(key, type, options) :
99
+ (0, index_3.Never)(options));
97
100
  }
@@ -1,12 +1,9 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index';
2
- import type { Static } from '../static/index';
3
2
  import { Kind } from '../symbols/index';
4
- export interface TRef<T extends TSchema = TSchema> extends TSchema {
3
+ export interface TRef<Ref extends string = string> extends TSchema {
5
4
  [Kind]: 'Ref';
6
- static: Static<T, this['params']>;
7
- $ref: string;
5
+ static: unknown;
6
+ $ref: Ref;
8
7
  }
9
8
  /** `[Json]` Creates a Ref type. The referenced type must contain a $id */
10
- export declare function Ref<T extends TSchema>(schema: T, options?: SchemaOptions): TRef<T>;
11
- /** `[Json]` Creates a Ref type. */
12
- export declare function Ref<T extends TSchema>($ref: string, options?: SchemaOptions): TRef<T>;
9
+ export declare function Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
@@ -4,15 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Ref = Ref;
5
5
  const type_1 = require("../create/type");
6
6
  const index_1 = require("../symbols/index");
7
- // ------------------------------------------------------------------
8
- // ValueGuard
9
- // ------------------------------------------------------------------
10
- const value_1 = require("../guard/value");
11
- /** `[Json]` Creates a Ref type. */
12
- function Ref(unresolved, options) {
13
- if ((0, value_1.IsString)(unresolved))
14
- return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref: unresolved }, options);
15
- if ((0, value_1.IsUndefined)(unresolved.$id))
16
- throw new Error('Reference target type must specify an $id');
17
- return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref: unresolved.$id }, options);
7
+ /** `[Json]` Creates a Ref type. The referenced type must contain a $id */
8
+ function Ref($ref, options) {
9
+ return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref }, options);
18
10
  }
@@ -2,21 +2,25 @@ import type { TSchema, SchemaOptions } from '../schema/index';
2
2
  import type { Evaluate, Ensure } from '../helpers/index';
3
3
  import type { TMappedResult } from '../mapped/index';
4
4
  import { type TReadonlyOptional } from '../readonly-optional/index';
5
+ import { type TComputed } from '../computed/index';
5
6
  import { type TOptional } from '../optional/index';
6
7
  import { type TReadonly } from '../readonly/index';
7
8
  import { type TRecursive } from '../recursive/index';
9
+ import { type TObject, type TProperties } from '../object/index';
8
10
  import { type TIntersect } from '../intersect/index';
9
11
  import { type TUnion } from '../union/index';
10
- import { type TObject, type TProperties } from '../object/index';
12
+ import { type TRef } from '../ref/index';
11
13
  import { type TRequiredFromMappedResult } from './required-from-mapped-result';
12
- type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TRequired<L>]> : Acc);
13
- type TFromProperties<T extends TProperties> = Evaluate<{
14
- [K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : T[K] extends (TReadonly<infer S>) ? TReadonly<S> : T[K] extends (TOptional<infer S>) ? S : T[K];
14
+ type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Required', [TComputed<Target, Parameters>]>>;
15
+ type TFromRef<Ref extends string> = Ensure<TComputed<'Required', [TRef<Ref>]>>;
16
+ type TFromProperties<Properties extends TProperties> = Evaluate<{
17
+ [K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonly<S> : Properties[K] extends (TOptional<infer S>) ? S : Properties[K];
15
18
  }>;
16
- type TFromObject<T extends TObject, Properties extends TProperties = T['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
17
- export type TRequired<T extends TSchema> = (T extends TRecursive<infer S extends TSchema> ? TRecursive<TRequired<S>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TFromRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TFromRest<S>> : T extends TObject<infer S extends TProperties> ? TFromObject<TObject<S>> : TObject<{}>);
19
+ type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
20
+ type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TRequired<L>]> : Result);
21
+ export type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject<Properties>> : TObject<{}>);
18
22
  /** `[Json]` Constructs a type where all properties are required */
19
- export declare function Required<T extends TMappedResult>(T: T, options?: SchemaOptions): TRequiredFromMappedResult<T>;
23
+ export declare function Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
20
24
  /** `[Json]` Constructs a type where all properties are required */
21
- export declare function Required<T extends TSchema>(T: T, options?: SchemaOptions): TRequired<T>;
25
+ export declare function Required<Type extends TSchema>(type: Type, options?: SchemaOptions): TRequired<Type>;
22
26
  export {};
@@ -3,50 +3,62 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Required = Required;
5
5
  const type_1 = require("../create/type");
6
- const index_1 = require("../intersect/index");
7
- const index_2 = require("../union/index");
8
- const index_3 = require("../object/index");
9
- const index_4 = require("../symbols/index");
10
- const index_5 = require("../discard/index");
6
+ const index_1 = require("../computed/index");
7
+ const index_2 = require("../object/index");
8
+ const index_3 = require("../intersect/index");
9
+ const index_4 = require("../union/index");
10
+ const index_5 = require("../ref/index");
11
+ const index_6 = require("../symbols/index");
12
+ const index_7 = require("../discard/index");
11
13
  const required_from_mapped_result_1 = require("./required-from-mapped-result");
12
14
  // ------------------------------------------------------------------
13
15
  // TypeGuard
14
16
  // ------------------------------------------------------------------
15
17
  const kind_1 = require("../guard/kind");
16
18
  // prettier-ignore
17
- function FromRest(T) {
18
- return T.map(L => RequiredResolve(L));
19
+ function FromComputed(target, parameters) {
20
+ return (0, index_1.Computed)('Required', [(0, index_1.Computed)(target, parameters)]);
19
21
  }
20
22
  // prettier-ignore
21
- function FromProperties(T) {
22
- const Acc = {};
23
- for (const K of globalThis.Object.getOwnPropertyNames(T))
24
- Acc[K] = (0, index_5.Discard)(T[K], [index_4.OptionalKind]);
25
- return Acc;
23
+ function FromRef($ref) {
24
+ return (0, index_1.Computed)('Required', [(0, index_5.Ref)($ref)]);
26
25
  }
27
26
  // prettier-ignore
28
- function FromObject(T) {
29
- const options = (0, index_5.Discard)(T, [index_4.TransformKind, '$id', 'required', 'properties']);
30
- const properties = FromProperties(T['properties']);
31
- return (0, index_3.Object)(properties, options);
27
+ function FromProperties(properties) {
28
+ const requiredProperties = {};
29
+ for (const K of globalThis.Object.getOwnPropertyNames(properties))
30
+ requiredProperties[K] = (0, index_7.Discard)(properties[K], [index_6.OptionalKind]);
31
+ return requiredProperties;
32
+ }
33
+ // prettier-ignore
34
+ function FromObject(type) {
35
+ const options = (0, index_7.Discard)(type, [index_6.TransformKind, '$id', 'required', 'properties']);
36
+ const properties = FromProperties(type['properties']);
37
+ return (0, index_2.Object)(properties, options);
38
+ }
39
+ // prettier-ignore
40
+ function FromRest(types) {
41
+ return types.map(type => RequiredResolve(type));
32
42
  }
33
43
  // ------------------------------------------------------------------
34
44
  // RequiredResolve
35
45
  // ------------------------------------------------------------------
36
46
  // prettier-ignore
37
- function RequiredResolve(T) {
38
- return ((0, kind_1.IsIntersect)(T) ? (0, index_1.Intersect)(FromRest(T.allOf)) :
39
- (0, kind_1.IsUnion)(T) ? (0, index_2.Union)(FromRest(T.anyOf)) :
40
- (0, kind_1.IsObject)(T) ? FromObject(T) :
41
- (0, index_3.Object)({}));
47
+ function RequiredResolve(type) {
48
+ return ((0, kind_1.IsComputed)(type) ? FromComputed(type.target, type.parameters) :
49
+ (0, kind_1.IsRef)(type) ? FromRef(type.$ref) :
50
+ (0, kind_1.IsIntersect)(type) ? (0, index_3.Intersect)(FromRest(type.allOf)) :
51
+ (0, kind_1.IsUnion)(type) ? (0, index_4.Union)(FromRest(type.anyOf)) :
52
+ (0, kind_1.IsObject)(type) ? FromObject(type) :
53
+ (0, index_2.Object)({}));
42
54
  }
43
55
  /** `[Json]` Constructs a type where all properties are required */
44
- function Required(T, options) {
45
- if ((0, kind_1.IsMappedResult)(T)) {
46
- return (0, required_from_mapped_result_1.RequiredFromMappedResult)(T, options);
56
+ function Required(type, options) {
57
+ if ((0, kind_1.IsMappedResult)(type)) {
58
+ return (0, required_from_mapped_result_1.RequiredFromMappedResult)(type, options);
47
59
  }
48
60
  else {
49
61
  // special: mapping types require overridable options
50
- return (0, type_1.CreateType)({ ...RequiredResolve(T), ...options });
62
+ return (0, type_1.CreateType)({ ...RequiredResolve(type), ...options });
51
63
  }
52
64
  }
@@ -23,7 +23,7 @@ export type TDecodeProperties<T extends TProperties> = {
23
23
  [K in keyof T]: TDecodeType<T[K]>;
24
24
  };
25
25
  export type TDecodeRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TDecodeRest<R, [...Acc, TDecodeType<L>]> : Acc;
26
- export type TDecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<TDecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<TDecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<TDecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<TDecodeRest<P>, TDecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<TDecodeRest<P>, TDecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TDecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<TDecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<TDecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, TDecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<TDecodeType<S>> : T extends TRef<infer S extends TSchema> ? TRef<TDecodeType<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TDecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TDecodeRest<S>> : T);
26
+ export type TDecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<TDecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<TDecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<TDecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<TDecodeRest<P>, TDecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<TDecodeRest<P>, TDecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TDecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<TDecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<TDecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, TDecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<TDecodeType<S>> : T extends TRef<infer S extends string> ? TRef<S> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TDecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TDecodeRest<S>> : T);
27
27
  export type StaticDecodeIsAny<T> = boolean extends (T extends TSchema ? true : false) ? true : false;
28
28
  /** Creates an decoded static type from a TypeBox type */
29
29
  export type StaticDecode<T extends TSchema, P extends unknown[] = []> = StaticDecodeIsAny<T> extends true ? unknown : Static<TDecodeType<T>, P>;
@@ -12,5 +12,5 @@ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
12
12
  maxItems: number;
13
13
  }
14
14
  /** `[Json]` Creates a Tuple type */
15
- export declare function Tuple<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TTuple<T>;
15
+ export declare function Tuple<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): TTuple<Types>;
16
16
  export {};
@@ -5,9 +5,9 @@ exports.Tuple = Tuple;
5
5
  const type_1 = require("../create/type");
6
6
  const index_1 = require("../symbols/index");
7
7
  /** `[Json]` Creates a Tuple type */
8
- function Tuple(items, options) {
8
+ function Tuple(types, options) {
9
9
  // prettier-ignore
10
- return (0, type_1.CreateType)(items.length > 0 ?
11
- { [index_1.Kind]: 'Tuple', type: 'array', items, additionalItems: false, minItems: items.length, maxItems: items.length } :
12
- { [index_1.Kind]: 'Tuple', type: 'array', minItems: items.length, maxItems: items.length }, options);
10
+ return (0, type_1.CreateType)(types.length > 0 ?
11
+ { [index_1.Kind]: 'Tuple', type: 'array', items: types, additionalItems: false, minItems: types.length, maxItems: types.length } :
12
+ { [index_1.Kind]: 'Tuple', type: 'array', minItems: types.length, maxItems: types.length }, options);
13
13
  }
@@ -20,33 +20,33 @@ import { type TVoid } from '../void/index';
20
20
  /** JavaScript Type Builder with Static Resolution for TypeScript */
21
21
  export declare class JavaScriptTypeBuilder extends JsonTypeBuilder {
22
22
  /** `[JavaScript]` Creates a AsyncIterator type */
23
- AsyncIterator<T extends TSchema>(items: T, options?: SchemaOptions): TAsyncIterator<T>;
23
+ AsyncIterator<Type extends TSchema>(items: Type, options?: SchemaOptions): TAsyncIterator<Type>;
24
24
  /** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
25
- Awaited<T extends TSchema>(schema: T, options?: SchemaOptions): TAwaited<T>;
25
+ Awaited<Type extends TSchema>(schema: Type, options?: SchemaOptions): TAwaited<Type>;
26
26
  /** `[JavaScript]` Creates a BigInt type */
27
27
  BigInt(options?: BigIntOptions): TBigInt;
28
28
  /** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
29
- ConstructorParameters<T extends TConstructor<TSchema[], TSchema>>(schema: T, options?: SchemaOptions): TConstructorParameters<T>;
29
+ ConstructorParameters<Type extends TConstructor>(schema: Type, options?: SchemaOptions): TConstructorParameters<Type>;
30
30
  /** `[JavaScript]` Creates a Constructor type */
31
- Constructor<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TConstructor<T, U>;
31
+ Constructor<Parameters extends TSchema[], InstanceType extends TSchema>(parameters: [...Parameters], instanceType: InstanceType, options?: SchemaOptions): TConstructor<Parameters, InstanceType>;
32
32
  /** `[JavaScript]` Creates a Date type */
33
33
  Date(options?: DateOptions): TDate;
34
34
  /** `[JavaScript]` Creates a Function type */
35
- Function<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TFunction<T, U>;
35
+ Function<Parameters extends TSchema[], ReturnType extends TSchema>(parameters: [...Parameters], returnType: ReturnType, options?: SchemaOptions): TFunction<Parameters, ReturnType>;
36
36
  /** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
37
- InstanceType<T extends TConstructor<any[], any>>(schema: T, options?: SchemaOptions): TInstanceType<T>;
37
+ InstanceType<Type extends TConstructor>(schema: Type, options?: SchemaOptions): TInstanceType<Type>;
38
38
  /** `[JavaScript]` Creates an Iterator type */
39
- Iterator<T extends TSchema>(items: T, options?: SchemaOptions): TIterator<T>;
39
+ Iterator<Type extends TSchema>(items: Type, options?: SchemaOptions): TIterator<Type>;
40
40
  /** `[JavaScript]` Extracts the Parameters from the given Function type */
41
- Parameters<T extends TFunction<TSchema[], TSchema>>(schema: T, options?: SchemaOptions): TParameters<T>;
41
+ Parameters<Type extends TFunction>(schema: Type, options?: SchemaOptions): TParameters<Type>;
42
42
  /** `[JavaScript]` Creates a Promise type */
43
- Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
43
+ Promise<Type extends TSchema>(item: Type, options?: SchemaOptions): TPromise<Type>;
44
44
  /** `[JavaScript]` Creates a RegExp type */
45
45
  RegExp(pattern: string, options?: RegExpOptions): TRegExp;
46
46
  /** `[JavaScript]` Creates a RegExp type */
47
47
  RegExp(regex: RegExp, options?: RegExpOptions): TRegExp;
48
48
  /** `[JavaScript]` Extracts the ReturnType from the given Function type */
49
- ReturnType<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TReturnType<T>;
49
+ ReturnType<Type extends TFunction>(type: Type, options?: SchemaOptions): TReturnType<Type>;
50
50
  /** `[JavaScript]` Creates a Symbol type */
51
51
  Symbol(options?: SchemaOptions): TSymbol;
52
52
  /** `[JavaScript]` Creates a Undefined type */
@@ -39,16 +39,16 @@ class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
39
39
  return (0, index_5.ConstructorParameters)(schema, options);
40
40
  }
41
41
  /** `[JavaScript]` Creates a Constructor type */
42
- Constructor(parameters, returns, options) {
43
- return (0, index_4.Constructor)(parameters, returns, options);
42
+ Constructor(parameters, instanceType, options) {
43
+ return (0, index_4.Constructor)(parameters, instanceType, options);
44
44
  }
45
45
  /** `[JavaScript]` Creates a Date type */
46
46
  Date(options = {}) {
47
47
  return (0, index_6.Date)(options);
48
48
  }
49
49
  /** `[JavaScript]` Creates a Function type */
50
- Function(parameters, returns, options) {
51
- return (0, index_7.Function)(parameters, returns, options);
50
+ Function(parameters, returnType, options) {
51
+ return (0, index_7.Function)(parameters, returnType, options);
52
52
  }
53
53
  /** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
54
54
  InstanceType(schema, options) {
@@ -71,8 +71,8 @@ class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
71
71
  return (0, index_12.RegExp)(unresolved, options);
72
72
  }
73
73
  /** `[JavaScript]` Extracts the ReturnType from the given Function type */
74
- ReturnType(schema, options) {
75
- return (0, index_13.ReturnType)(schema, options);
74
+ ReturnType(type, options) {
75
+ return (0, index_13.ReturnType)(type, options);
76
76
  }
77
77
  /** `[JavaScript]` Creates a Symbol type */
78
78
  Symbol(options) {