@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,7 +3,6 @@ import { Array } from '../array/index.mjs';
3
3
  import { Boolean } from '../boolean/index.mjs';
4
4
  import { Composite } from '../composite/index.mjs';
5
5
  import { Const } from '../const/index.mjs';
6
- import { Deref } from '../deref/index.mjs';
7
6
  import { Enum } from '../enum/index.mjs';
8
7
  import { Exclude } from '../exclude/index.mjs';
9
8
  import { Extends } from '../extends/index.mjs';
@@ -18,6 +17,7 @@ import { Mapped } from '../mapped/index.mjs';
18
17
  import { Never } from '../never/index.mjs';
19
18
  import { Not } from '../not/index.mjs';
20
19
  import { Null } from '../null/index.mjs';
20
+ import { Module } from '../module/index.mjs';
21
21
  import { Number } from '../number/index.mjs';
22
22
  import { Object } from '../object/index.mjs';
23
23
  import { Omit } from '../omit/index.mjs';
@@ -31,7 +31,6 @@ import { Recursive } from '../recursive/index.mjs';
31
31
  import { Ref } from '../ref/index.mjs';
32
32
  import { Required } from '../required/index.mjs';
33
33
  import { Rest } from '../rest/index.mjs';
34
- import { Strict } from '../strict/index.mjs';
35
34
  import { String } from '../string/index.mjs';
36
35
  import { TemplateLiteral } from '../template-literal/index.mjs';
37
36
  import { Transform } from '../transform/index.mjs';
@@ -41,35 +40,20 @@ import { Unknown } from '../unknown/index.mjs';
41
40
  import { Unsafe } from '../unsafe/index.mjs';
42
41
  /** Json Type Builder with Static Resolution for TypeScript */
43
42
  export class JsonTypeBuilder {
44
- // ------------------------------------------------------------------------
45
- // Strict
46
- // ------------------------------------------------------------------------
47
- /**
48
- * @deprecated `[Json]` Omits compositing symbols from this schema. It is recommended
49
- * to use the JSON parse/stringify to remove compositing symbols if needed. This
50
- * is how Strict works internally.
51
- *
52
- * ```typescript
53
- * JSON.parse(JSON.stringify(Type.String()))
54
- * ```
55
- */
56
- Strict(schema) {
57
- return Strict(schema);
58
- }
59
43
  // ------------------------------------------------------------------------
60
44
  // Modifiers
61
45
  // ------------------------------------------------------------------------
62
46
  /** `[Json]` Creates a Readonly and Optional property */
63
- ReadonlyOptional(schema) {
64
- return ReadonlyOptional(schema);
47
+ ReadonlyOptional(type) {
48
+ return ReadonlyOptional(type);
65
49
  }
66
50
  /** `[Json]` Creates a Readonly property */
67
- Readonly(schema, enable) {
68
- return Readonly(schema, enable ?? true);
51
+ Readonly(type, enable) {
52
+ return Readonly(type, enable ?? true);
69
53
  }
70
54
  /** `[Json]` Creates a Optional property */
71
- Optional(schema, enable) {
72
- return Optional(schema, enable ?? true);
55
+ Optional(type, enable) {
56
+ return Optional(type, enable ?? true);
73
57
  }
74
58
  // ------------------------------------------------------------------------
75
59
  // Types
@@ -79,8 +63,8 @@ export class JsonTypeBuilder {
79
63
  return Any(options);
80
64
  }
81
65
  /** `[Json]` Creates an Array type */
82
- Array(schema, options) {
83
- return Array(schema, options);
66
+ Array(items, options) {
67
+ return Array(items, options);
84
68
  }
85
69
  /** `[Json]` Creates a Boolean type */
86
70
  Boolean(options) {
@@ -98,10 +82,6 @@ export class JsonTypeBuilder {
98
82
  Const(value, options) {
99
83
  return Const(value, options);
100
84
  }
101
- /** `[Json]` Creates a dereferenced type */
102
- Deref(schema, references) {
103
- return Deref(schema, references);
104
- }
105
85
  /** `[Json]` Creates a Enum type */
106
86
  Enum(item, options) {
107
87
  return Enum(item, options);
@@ -119,40 +99,44 @@ export class JsonTypeBuilder {
119
99
  return Extract(type, union, options);
120
100
  }
121
101
  /** `[Json]` Returns an Indexed property type for the given keys */
122
- Index(schema, unresolved, options) {
123
- return Index(schema, unresolved, options);
102
+ Index(type, key, options) {
103
+ return Index(type, key, options);
124
104
  }
125
105
  /** `[Json]` Creates an Integer type */
126
106
  Integer(options) {
127
107
  return Integer(options);
128
108
  }
129
109
  /** `[Json]` Creates an Intersect type */
130
- Intersect(T, options) {
131
- return Intersect(T, options);
110
+ Intersect(types, options) {
111
+ return Intersect(types, options);
132
112
  }
133
113
  /** `[Json]` Creates a KeyOf type */
134
- KeyOf(schema, options) {
135
- return KeyOf(schema, options);
114
+ KeyOf(type, options) {
115
+ return KeyOf(type, options);
136
116
  }
137
117
  /** `[Json]` Creates a Literal type */
138
- Literal(value, options) {
139
- return Literal(value, options);
118
+ Literal(literalValue, options) {
119
+ return Literal(literalValue, options);
140
120
  }
141
121
  /** `[Json]` Intrinsic function to Lowercase LiteralString types */
142
- Lowercase(schema, options) {
143
- return Lowercase(schema, options);
122
+ Lowercase(type, options) {
123
+ return Lowercase(type, options);
144
124
  }
145
125
  /** `[Json]` Creates a Mapped object type */
146
126
  Mapped(key, map, options) {
147
127
  return Mapped(key, map, options);
148
128
  }
129
+ /** `[Json]` Creates a Type Definition Module. */
130
+ Module(properties) {
131
+ return Module(properties);
132
+ }
149
133
  /** `[Json]` Creates a Never type */
150
134
  Never(options) {
151
135
  return Never(options);
152
136
  }
153
137
  /** `[Json]` Creates a Not type */
154
- Not(schema, options) {
155
- return Not(schema, options);
138
+ Not(type, options) {
139
+ return Not(type, options);
156
140
  }
157
141
  /** `[Json]` Creates a Null type */
158
142
  Null(options) {
@@ -167,36 +151,36 @@ export class JsonTypeBuilder {
167
151
  return Object(properties, options);
168
152
  }
169
153
  /** `[Json]` Constructs a type whose keys are omitted from the given type */
170
- Omit(schema, unresolved, options) {
171
- return Omit(schema, unresolved, options);
154
+ Omit(schema, selector, options) {
155
+ return Omit(schema, selector, options);
172
156
  }
173
157
  /** `[Json]` Constructs a type where all properties are optional */
174
- Partial(schema, options) {
175
- return Partial(schema, options);
158
+ Partial(type, options) {
159
+ return Partial(type, options);
176
160
  }
177
161
  /** `[Json]` Constructs a type whose keys are picked from the given type */
178
- Pick(schema, unresolved, options) {
179
- return Pick(schema, unresolved, options);
162
+ Pick(type, key, options) {
163
+ return Pick(type, key, options);
180
164
  }
181
165
  /** `[Json]` Creates a Record type */
182
- Record(key, schema, options) {
183
- return Record(key, schema, options);
166
+ Record(key, value, options) {
167
+ return Record(key, value, options);
184
168
  }
185
169
  /** `[Json]` Creates a Recursive type */
186
170
  Recursive(callback, options) {
187
171
  return Recursive(callback, options);
188
172
  }
189
173
  /** `[Json]` Creates a Ref type. */
190
- Ref(unresolved, options) {
191
- return Ref(unresolved, options);
174
+ Ref($ref, options) {
175
+ return Ref($ref, options);
192
176
  }
193
177
  /** `[Json]` Constructs a type where all properties are required */
194
- Required(schema, options) {
195
- return Required(schema, options);
178
+ Required(type, options) {
179
+ return Required(type, options);
196
180
  }
197
181
  /** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
198
- Rest(schema) {
199
- return Rest(schema);
182
+ Rest(type) {
183
+ return Rest(type);
200
184
  }
201
185
  /** `[Json]` Creates a String type */
202
186
  String(options) {
@@ -207,20 +191,20 @@ export class JsonTypeBuilder {
207
191
  return TemplateLiteral(unresolved, options);
208
192
  }
209
193
  /** `[Json]` Creates a Transform type */
210
- Transform(schema) {
211
- return Transform(schema);
194
+ Transform(type) {
195
+ return Transform(type);
212
196
  }
213
197
  /** `[Json]` Creates a Tuple type */
214
- Tuple(items, options) {
215
- return Tuple(items, options);
198
+ Tuple(types, options) {
199
+ return Tuple(types, options);
216
200
  }
217
201
  /** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
218
- Uncapitalize(schema, options) {
219
- return Uncapitalize(schema, options);
202
+ Uncapitalize(type, options) {
203
+ return Uncapitalize(type, options);
220
204
  }
221
205
  /** `[Json]` Creates a Union type */
222
- Union(schemas, options) {
223
- return Union(schemas, options);
206
+ Union(types, options) {
207
+ return Union(types, options);
224
208
  }
225
209
  /** `[Json]` Creates an Unknown type */
226
210
  Unknown(options) {
@@ -9,7 +9,6 @@ export { Const } from '../const/index.mjs';
9
9
  export { Constructor } from '../constructor/index.mjs';
10
10
  export { ConstructorParameters } from '../constructor-parameters/index.mjs';
11
11
  export { Date } from '../date/index.mjs';
12
- export { Deref } from '../deref/index.mjs';
13
12
  export { Enum } from '../enum/index.mjs';
14
13
  export { Exclude } from '../exclude/index.mjs';
15
14
  export { Extends } from '../extends/index.mjs';
@@ -24,6 +23,7 @@ export { Iterator } from '../iterator/index.mjs';
24
23
  export { KeyOf } from '../keyof/index.mjs';
25
24
  export { Literal } from '../literal/index.mjs';
26
25
  export { Mapped } from '../mapped/index.mjs';
26
+ export { Module } from '../module/index.mjs';
27
27
  export { Never } from '../never/index.mjs';
28
28
  export { Not } from '../not/index.mjs';
29
29
  export { Null } from '../null/index.mjs';
@@ -45,7 +45,6 @@ export { Required } from '../required/index.mjs';
45
45
  export { Rest } from '../rest/index.mjs';
46
46
  export { ReturnType } from '../return-type/index.mjs';
47
47
  export { String } from '../string/index.mjs';
48
- export { Strict } from '../strict/index.mjs';
49
48
  export { Symbol } from '../symbol/index.mjs';
50
49
  export { TemplateLiteral } from '../template-literal/index.mjs';
51
50
  export { Transform } from '../transform/index.mjs';
@@ -12,7 +12,6 @@ export { Const } from '../const/index.mjs';
12
12
  export { Constructor } from '../constructor/index.mjs';
13
13
  export { ConstructorParameters } from '../constructor-parameters/index.mjs';
14
14
  export { Date } from '../date/index.mjs';
15
- export { Deref } from '../deref/index.mjs';
16
15
  export { Enum } from '../enum/index.mjs';
17
16
  export { Exclude } from '../exclude/index.mjs';
18
17
  export { Extends } from '../extends/index.mjs';
@@ -27,6 +26,7 @@ export { Iterator } from '../iterator/index.mjs';
27
26
  export { KeyOf } from '../keyof/index.mjs';
28
27
  export { Literal } from '../literal/index.mjs';
29
28
  export { Mapped } from '../mapped/index.mjs';
29
+ export { Module } from '../module/index.mjs';
30
30
  export { Never } from '../never/index.mjs';
31
31
  export { Not } from '../not/index.mjs';
32
32
  export { Null } from '../null/index.mjs';
@@ -48,7 +48,6 @@ export { Required } from '../required/index.mjs';
48
48
  export { Rest } from '../rest/index.mjs';
49
49
  export { ReturnType } from '../return-type/index.mjs';
50
50
  export { String } from '../string/index.mjs';
51
- export { Strict } from '../strict/index.mjs';
52
51
  export { Symbol } from '../symbol/index.mjs';
53
52
  export { TemplateLiteral } from '../template-literal/index.mjs';
54
53
  export { Transform } from '../transform/index.mjs';
@@ -3,11 +3,11 @@ import { type TNever } from '../never/index.mjs';
3
3
  import { type TOptional } from '../optional/index.mjs';
4
4
  import type { TReadonly } from '../readonly/index.mjs';
5
5
  import type { TUnion } from './union-type.mjs';
6
- type TIsUnionOptional<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TOptional<TSchema> ? true : TIsUnionOptional<R> : false);
7
- type TRemoveOptionalFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromRest<R, [...Acc, TRemoveOptionalFromType<S>]> : TRemoveOptionalFromRest<R, [...Acc, L]> : Acc);
8
- type TRemoveOptionalFromType<T extends TSchema> = (T extends TReadonly<infer S extends TSchema> ? TReadonly<TRemoveOptionalFromType<S>> : T extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromType<S> : T);
9
- type TResolveUnion<T extends TSchema[], R extends TSchema[] = TRemoveOptionalFromRest<T>> = (TIsUnionOptional<T> extends true ? TOptional<TUnion<R>> : TUnion<R>);
10
- export type TUnionEvaluated<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : TResolveUnion<T>);
6
+ type TIsUnionOptional<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<TSchema> ? true : TIsUnionOptional<Right> : false);
7
+ type TRemoveOptionalFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromRest<Right, [...Result, TRemoveOptionalFromType<S>]> : TRemoveOptionalFromRest<Right, [...Result, Left]> : Result);
8
+ type TRemoveOptionalFromType<Type extends TSchema> = (Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TRemoveOptionalFromType<Type>> : Type extends TOptional<infer Type extends TSchema> ? TRemoveOptionalFromType<Type> : Type);
9
+ type TResolveUnion<Types extends TSchema[], Result extends TSchema[] = TRemoveOptionalFromRest<Types>, IsOptional extends boolean = TIsUnionOptional<Types>> = (IsOptional extends true ? TOptional<TUnion<Result>> : TUnion<Result>);
10
+ export type TUnionEvaluated<Types extends TSchema[]> = (Types extends [TSchema] ? Types[0] : Types extends [] ? TNever : TResolveUnion<Types>);
11
11
  /** `[Json]` Creates an evaluated Union type */
12
- export declare function UnionEvaluated<T extends TSchema[], R = TUnionEvaluated<T>>(T: [...T], options?: SchemaOptions): R;
12
+ export declare function UnionEvaluated<Types extends TSchema[], Result = TUnionEvaluated<Types>>(T: [...Types], options?: SchemaOptions): Result;
13
13
  export {};
@@ -9,27 +9,28 @@ import { UnionCreate } from './union-create.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  import { IsOptional } from '../guard/kind.mjs';
11
11
  // prettier-ignore
12
- function IsUnionOptional(T) {
13
- return T.some(L => IsOptional(L));
12
+ function IsUnionOptional(types) {
13
+ return types.some(type => IsOptional(type));
14
14
  }
15
15
  // prettier-ignore
16
- function RemoveOptionalFromRest(T) {
17
- return T.map(L => IsOptional(L) ? RemoveOptionalFromType(L) : L);
16
+ function RemoveOptionalFromRest(types) {
17
+ return types.map(left => IsOptional(left) ? RemoveOptionalFromType(left) : left);
18
18
  }
19
19
  // prettier-ignore
20
20
  function RemoveOptionalFromType(T) {
21
21
  return (Discard(T, [OptionalKind]));
22
22
  }
23
23
  // prettier-ignore
24
- function ResolveUnion(T, options) {
25
- return (IsUnionOptional(T)
26
- ? Optional(UnionCreate(RemoveOptionalFromRest(T), options))
27
- : UnionCreate(RemoveOptionalFromRest(T), options));
24
+ function ResolveUnion(types, options) {
25
+ const isOptional = IsUnionOptional(types);
26
+ return (isOptional
27
+ ? Optional(UnionCreate(RemoveOptionalFromRest(types), options))
28
+ : UnionCreate(RemoveOptionalFromRest(types), options));
28
29
  }
29
30
  /** `[Json]` Creates an evaluated Union type */
30
31
  export function UnionEvaluated(T, options) {
31
32
  // prettier-ignore
32
- return (T.length === 0 ? Never(options) :
33
- T.length === 1 ? CreateType(T[0], options) :
33
+ return (T.length === 1 ? CreateType(T[0], options) :
34
+ T.length === 0 ? Never(options) :
34
35
  ResolveUnion(T, options));
35
36
  }
@@ -3,4 +3,4 @@ import { type TNever } from '../never/index.mjs';
3
3
  import type { TUnion } from './union-type.mjs';
4
4
  export type Union<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : TUnion<T>);
5
5
  /** `[Json]` Creates a Union type */
6
- export declare function Union<T extends TSchema[]>(T: [...T], options?: SchemaOptions): Union<T>;
6
+ export declare function Union<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): Union<Types>;
@@ -2,9 +2,9 @@ import { Never } from '../never/index.mjs';
2
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(types, options) {
6
6
  // prettier-ignore
7
- return (T.length === 0 ? Never(options) :
8
- T.length === 1 ? CreateType(T[0], options) :
9
- UnionCreate(T, options));
7
+ return (types.length === 0 ? Never(options) :
8
+ types.length === 1 ? CreateType(types[0], options) :
9
+ UnionCreate(types, options));
10
10
  }
@@ -4,7 +4,7 @@ import { Kind } from '../../type/symbols/index.mjs';
4
4
  import { Create } from '../create/index.mjs';
5
5
  import { Check } from '../check/index.mjs';
6
6
  import { Clone } from '../clone/index.mjs';
7
- import { Deref } from '../deref/index.mjs';
7
+ import { Deref, Pushref } from '../deref/index.mjs';
8
8
  // ------------------------------------------------------------------
9
9
  // Errors
10
10
  // ------------------------------------------------------------------
@@ -98,6 +98,11 @@ function FromConstructor(schema, references, value) {
98
98
  }
99
99
  return result;
100
100
  }
101
+ function FromImport(schema, references, value) {
102
+ const definitions = globalThis.Object.values(schema.$defs);
103
+ const target = schema.$defs[schema.$ref];
104
+ return Visit(target, [...references, ...definitions], value);
105
+ }
101
106
  function FromIntersect(schema, references, value) {
102
107
  const created = Create(schema, references);
103
108
  const mapped = IsObject(created) && IsObject(value) ? { ...created, ...value } : value;
@@ -161,7 +166,7 @@ function FromUnion(schema, references, value) {
161
166
  return Check(schema, references, value) ? Clone(value) : CastUnion(schema, references, value);
162
167
  }
163
168
  function Visit(schema, references, value) {
164
- const references_ = IsString(schema.$id) ? [...references, schema] : references;
169
+ const references_ = IsString(schema.$id) ? Pushref(schema, references) : references;
165
170
  const schema_ = schema;
166
171
  switch (schema[Kind]) {
167
172
  // --------------------------------------------------------------
@@ -171,6 +176,8 @@ function Visit(schema, references, value) {
171
176
  return FromArray(schema_, references_, value);
172
177
  case 'Constructor':
173
178
  return FromConstructor(schema_, references_, value);
179
+ case 'Import':
180
+ return FromImport(schema_, references_, value);
174
181
  case 'Intersect':
175
182
  return FromIntersect(schema_, references_, value);
176
183
  case 'Never':
@@ -1,5 +1,5 @@
1
1
  import { TypeSystemPolicy } from '../../system/index.mjs';
2
- import { Deref } from '../deref/index.mjs';
2
+ import { Deref, Pushref } from '../deref/index.mjs';
3
3
  import { Hash } from '../hash/index.mjs';
4
4
  import { Kind } from '../../type/symbols/index.mjs';
5
5
  import { KeyOfPattern } from '../../type/keyof/index.mjs';
@@ -12,9 +12,9 @@ import { Never } from '../../type/never/index.mjs';
12
12
  // ------------------------------------------------------------------
13
13
  import { IsArray, IsUint8Array, IsDate, IsPromise, IsFunction, IsAsyncIterator, IsIterator, IsBoolean, IsNumber, IsBigInt, IsString, IsSymbol, IsInteger, IsNull, IsUndefined } from '../guard/index.mjs';
14
14
  // ------------------------------------------------------------------
15
- // TypeGuard
15
+ // KindGuard
16
16
  // ------------------------------------------------------------------
17
- import { IsSchema } from '../../type/guard/type.mjs';
17
+ import { IsSchema } from '../../type/guard/kind.mjs';
18
18
  // ------------------------------------------------------------------
19
19
  // Errors
20
20
  // ------------------------------------------------------------------
@@ -135,6 +135,11 @@ function FromDate(schema, references, value) {
135
135
  function FromFunction(schema, references, value) {
136
136
  return IsFunction(value);
137
137
  }
138
+ function FromImport(schema, references, value) {
139
+ const definitions = globalThis.Object.values(schema.$defs);
140
+ const target = schema.$defs[schema.$ref];
141
+ return Visit(target, [...references, ...definitions], value);
142
+ }
138
143
  function FromInteger(schema, references, value) {
139
144
  if (!IsInteger(value)) {
140
145
  return false;
@@ -380,7 +385,7 @@ function FromKind(schema, references, value) {
380
385
  return func(schema, value);
381
386
  }
382
387
  function Visit(schema, references, value) {
383
- const references_ = IsDefined(schema.$id) ? [...references, schema] : references;
388
+ const references_ = IsDefined(schema.$id) ? Pushref(schema, references) : references;
384
389
  const schema_ = schema;
385
390
  switch (schema_[Kind]) {
386
391
  case 'Any':
@@ -399,6 +404,8 @@ function Visit(schema, references, value) {
399
404
  return FromDate(schema_, references_, value);
400
405
  case 'Function':
401
406
  return FromFunction(schema_, references_, value);
407
+ case 'Import':
408
+ return FromImport(schema_, references_, value);
402
409
  case 'Integer':
403
410
  return FromInteger(schema_, references_, value);
404
411
  case 'Intersect':
@@ -1,7 +1,7 @@
1
1
  import { KeyOfPropertyKeys } from '../../type/keyof/index.mjs';
2
2
  import { Check } from '../check/index.mjs';
3
3
  import { Clone } from '../clone/index.mjs';
4
- import { Deref } from '../deref/index.mjs';
4
+ import { Deref, Pushref } from '../deref/index.mjs';
5
5
  import { Kind } from '../../type/symbols/index.mjs';
6
6
  // ------------------------------------------------------------------
7
7
  // ValueGuard
@@ -27,6 +27,11 @@ function FromArray(schema, references, value) {
27
27
  return value;
28
28
  return value.map((value) => Visit(schema.items, references, value));
29
29
  }
30
+ function FromImport(schema, references, value) {
31
+ const definitions = globalThis.Object.values(schema.$defs);
32
+ const target = schema.$defs[schema.$ref];
33
+ return Visit(target, [...references, ...definitions], value);
34
+ }
30
35
  function FromIntersect(schema, references, value) {
31
36
  const unevaluatedProperties = schema.unevaluatedProperties;
32
37
  const intersections = schema.allOf.map((schema) => Visit(schema, references, Clone(value)));
@@ -109,11 +114,13 @@ function FromUnion(schema, references, value) {
109
114
  return value;
110
115
  }
111
116
  function Visit(schema, references, value) {
112
- const references_ = IsString(schema.$id) ? [...references, schema] : references;
117
+ const references_ = IsString(schema.$id) ? Pushref(schema, references) : references;
113
118
  const schema_ = schema;
114
119
  switch (schema_[Kind]) {
115
120
  case 'Array':
116
121
  return FromArray(schema_, references_, value);
122
+ case 'Import':
123
+ return FromImport(schema_, references_, value);
117
124
  case 'Intersect':
118
125
  return FromIntersect(schema_, references_, value);
119
126
  case 'Object':
@@ -123,6 +123,11 @@ function FromBoolean(schema, references, value) {
123
123
  function FromDate(schema, references, value) {
124
124
  return TryConvertDate(value);
125
125
  }
126
+ function FromImport(schema, references, value) {
127
+ const definitions = globalThis.Object.values(schema.$defs);
128
+ const target = schema.$defs[schema.$ref];
129
+ return Visit(target, [...references, ...definitions], value);
130
+ }
126
131
  function FromInteger(schema, references, value) {
127
132
  return TryConvertInteger(value);
128
133
  }
@@ -207,6 +212,8 @@ function Visit(schema, references, value) {
207
212
  return FromBoolean(schema_, references_, value);
208
213
  case 'Date':
209
214
  return FromDate(schema_, references_, value);
215
+ case 'Import':
216
+ return FromImport(schema_, references_, value);
210
217
  case 'Integer':
211
218
  return FromInteger(schema_, references_, value);
212
219
  case 'Intersect':
@@ -118,6 +118,11 @@ function FromFunction(schema, references) {
118
118
  return () => Visit(schema.returns, references);
119
119
  }
120
120
  }
121
+ function FromImport(schema, references) {
122
+ const definitions = globalThis.Object.values(schema.$defs);
123
+ const target = schema.$defs[schema.$ref];
124
+ return Visit(target, [...references, ...definitions]);
125
+ }
121
126
  function FromInteger(schema, references) {
122
127
  if (HasPropertyKey(schema, 'default')) {
123
128
  return FromDefault(schema.default);
@@ -401,6 +406,8 @@ function Visit(schema, references) {
401
406
  return FromDate(schema_, references_);
402
407
  case 'Function':
403
408
  return FromFunction(schema_, references_);
409
+ case 'Import':
410
+ return FromImport(schema_, references_);
404
411
  case 'Integer':
405
412
  return FromInteger(schema_, references_);
406
413
  case 'Intersect':
@@ -40,6 +40,11 @@ function FromDate(schema, references, value) {
40
40
  // special case intercept for dates
41
41
  return IsDate(value) ? value : ValueOrDefault(schema, value);
42
42
  }
43
+ function FromImport(schema, references, value) {
44
+ const definitions = globalThis.Object.values(schema.$defs);
45
+ const target = schema.$defs[schema.$ref];
46
+ return Visit(target, [...references, ...definitions], value);
47
+ }
43
48
  function FromIntersect(schema, references, value) {
44
49
  const defaulted = ValueOrDefault(schema, value);
45
50
  return schema.allOf.reduce((acc, schema) => {
@@ -133,6 +138,8 @@ function Visit(schema, references, value) {
133
138
  return FromArray(schema_, references_, value);
134
139
  case 'Date':
135
140
  return FromDate(schema_, references_, value);
141
+ case 'Import':
142
+ return FromImport(schema_, references_, value);
136
143
  case 'Intersect':
137
144
  return FromIntersect(schema_, references_, value);
138
145
  case 'Object':
@@ -9,9 +9,9 @@ import { Check } from '../check/index.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  import { HasPropertyKey, IsObject, IsArray, IsValueType, IsUndefined as IsUndefinedValue } from '../guard/index.mjs';
11
11
  // ------------------------------------------------------------------
12
- // TypeGuard
12
+ // KindGuard
13
13
  // ------------------------------------------------------------------
14
- import { IsTransform, IsSchema, IsUndefined } from '../../type/guard/type.mjs';
14
+ import { IsTransform, IsSchema, IsUndefined } from '../../type/guard/kind.mjs';
15
15
  // ------------------------------------------------------------------
16
16
  // Errors
17
17
  // ------------------------------------------------------------------
@@ -76,6 +76,15 @@ function FromIntersect(schema, references, path, value) {
76
76
  }
77
77
  return Default(schema, path, unknownProperties);
78
78
  }
79
+ // prettier-ignore
80
+ function FromImport(schema, references, path, value) {
81
+ const definitions = globalThis.Object.values(schema.$defs);
82
+ const target = schema.$defs[schema.$ref];
83
+ const transform = schema[TransformKind];
84
+ // Note: we need to re-spec the target as TSchema + [TransformKind]
85
+ const transformTarget = { [TransformKind]: transform, ...target };
86
+ return Visit(transformTarget, [...references, ...definitions], path, value);
87
+ }
79
88
  function FromNot(schema, references, path, value) {
80
89
  return Default(schema, path, Visit(schema.not, references, path, value));
81
90
  }
@@ -166,6 +175,8 @@ function Visit(schema, references, path, value) {
166
175
  switch (schema[Kind]) {
167
176
  case 'Array':
168
177
  return FromArray(schema_, references_, path, value);
178
+ case 'Import':
179
+ return FromImport(schema_, references_, path, value);
169
180
  case 'Intersect':
170
181
  return FromIntersect(schema_, references_, path, value);
171
182
  case 'Not':
@@ -9,9 +9,9 @@ import { Check } from '../check/index.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  import { HasPropertyKey, IsObject, IsArray, IsValueType, IsUndefined as IsUndefinedValue } from '../guard/index.mjs';
11
11
  // ------------------------------------------------------------------
12
- // TypeGuard
12
+ // KindGuard
13
13
  // ------------------------------------------------------------------
14
- import { IsTransform, IsSchema, IsUndefined } from '../../type/guard/type.mjs';
14
+ import { IsTransform, IsSchema, IsUndefined } from '../../type/guard/kind.mjs';
15
15
  // ------------------------------------------------------------------
16
16
  // Errors
17
17
  // ------------------------------------------------------------------
@@ -54,6 +54,15 @@ function FromArray(schema, references, path, value) {
54
54
  : defaulted;
55
55
  }
56
56
  // prettier-ignore
57
+ function FromImport(schema, references, path, value) {
58
+ const definitions = globalThis.Object.values(schema.$defs);
59
+ const target = schema.$defs[schema.$ref];
60
+ const transform = schema[TransformKind];
61
+ // Note: we need to re-spec the target as TSchema + [TransformKind]
62
+ const transformTarget = { [TransformKind]: transform, ...target };
63
+ return Visit(transformTarget, [...references, ...definitions], path, value);
64
+ }
65
+ // prettier-ignore
57
66
  function FromIntersect(schema, references, path, value) {
58
67
  const defaulted = Default(schema, path, value);
59
68
  if (!IsObject(value) || IsValueType(value))
@@ -178,6 +187,8 @@ function Visit(schema, references, path, value) {
178
187
  switch (schema[Kind]) {
179
188
  case 'Array':
180
189
  return FromArray(schema_, references_, path, value);
190
+ case 'Import':
191
+ return FromImport(schema_, references_, path, value);
181
192
  case 'Intersect':
182
193
  return FromIntersect(schema_, references_, path, value);
183
194
  case 'Not':
@@ -1,9 +1,9 @@
1
1
  import { Deref, Pushref } from '../deref/index.mjs';
2
2
  import { Kind } from '../../type/symbols/index.mjs';
3
3
  // ------------------------------------------------------------------
4
- // TypeGuard
4
+ // KindGuard
5
5
  // ------------------------------------------------------------------
6
- import { IsTransform, IsSchema } from '../../type/guard/type.mjs';
6
+ import { IsTransform, IsSchema } from '../../type/guard/kind.mjs';
7
7
  // ------------------------------------------------------------------
8
8
  // ValueGuard
9
9
  // ------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.33.22",
3
+ "version": "0.34.1",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",