@sinclair/typebox 0.31.27 → 0.32.0-dev-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 (417) hide show
  1. package/compiler/compiler.d.ts +25 -18
  2. package/compiler/compiler.js +118 -107
  3. package/errors/errors.d.ts +7 -7
  4. package/errors/errors.js +48 -44
  5. package/index.d.ts +71 -0
  6. package/index.js +205 -0
  7. package/package.json +8 -19
  8. package/readme.md +188 -160
  9. package/system/errors.d.ts +14 -0
  10. package/system/errors.js +192 -0
  11. package/system/index.d.ts +3 -1
  12. package/system/index.js +10 -16
  13. package/system/policy.d.ts +21 -0
  14. package/system/policy.js +74 -0
  15. package/system/system.d.ts +3 -38
  16. package/system/system.js +15 -218
  17. package/type/any/any.d.ts +8 -0
  18. package/type/any/any.js +36 -0
  19. package/type/any/index.d.ts +1 -0
  20. package/type/any/index.js +44 -0
  21. package/type/array/array.d.ts +25 -0
  22. package/type/array/array.js +42 -0
  23. package/type/array/index.d.ts +1 -0
  24. package/type/array/index.js +44 -0
  25. package/type/async-iterator/async-iterator.d.ts +11 -0
  26. package/type/async-iterator/async-iterator.js +42 -0
  27. package/type/async-iterator/index.d.ts +1 -0
  28. package/type/async-iterator/index.js +44 -0
  29. package/type/awaited/awaited.d.ts +12 -0
  30. package/type/awaited/awaited.js +66 -0
  31. package/type/awaited/index.d.ts +1 -0
  32. package/type/awaited/index.js +44 -0
  33. package/type/bigint/bigint.d.ts +16 -0
  34. package/type/bigint/bigint.js +40 -0
  35. package/type/bigint/index.d.ts +1 -0
  36. package/type/bigint/index.js +44 -0
  37. package/type/boolean/boolean.d.ts +9 -0
  38. package/type/boolean/boolean.js +40 -0
  39. package/type/boolean/index.d.ts +1 -0
  40. package/type/boolean/index.js +44 -0
  41. package/type/clone/index.d.ts +2 -0
  42. package/type/clone/index.js +32 -0
  43. package/type/clone/type.d.ts +5 -0
  44. package/type/clone/type.js +41 -0
  45. package/type/clone/value.d.ts +2 -0
  46. package/type/clone/value.js +58 -0
  47. package/type/composite/composite.d.ts +15 -0
  48. package/type/composite/composite.js +47 -0
  49. package/type/composite/index.d.ts +1 -0
  50. package/type/composite/index.js +44 -0
  51. package/type/const/const.d.ts +30 -0
  52. package/type/const/const.js +84 -0
  53. package/type/const/index.d.ts +1 -0
  54. package/type/const/index.js +44 -0
  55. package/type/constructor/constructor.d.ts +17 -0
  56. package/type/constructor/constructor.js +43 -0
  57. package/type/constructor/index.d.ts +1 -0
  58. package/type/constructor/index.js +44 -0
  59. package/type/constructor-parameters/constructor-parameters.d.ts +7 -0
  60. package/type/constructor-parameters/constructor-parameters.js +37 -0
  61. package/type/constructor-parameters/index.d.ts +1 -0
  62. package/type/constructor-parameters/index.js +44 -0
  63. package/type/date/date.d.ts +21 -0
  64. package/type/date/date.js +40 -0
  65. package/type/date/index.d.ts +1 -0
  66. package/type/date/index.js +44 -0
  67. package/type/deref/deref.d.ts +24 -0
  68. package/type/deref/deref.js +136 -0
  69. package/type/deref/index.d.ts +1 -0
  70. package/type/deref/index.js +44 -0
  71. package/type/discard/discard.d.ts +1 -0
  72. package/type/discard/discard.js +38 -0
  73. package/type/discard/index.d.ts +1 -0
  74. package/type/discard/index.js +44 -0
  75. package/type/enum/enum.d.ts +14 -0
  76. package/type/enum/enum.js +46 -0
  77. package/type/enum/index.d.ts +1 -0
  78. package/type/enum/index.js +44 -0
  79. package/type/exclude/exclude.d.ts +21 -0
  80. package/type/exclude/exclude.js +54 -0
  81. package/type/exclude/index.d.ts +1 -0
  82. package/type/exclude/index.js +44 -0
  83. package/type/extends/extends-check.d.ts +9 -0
  84. package/type/extends/extends-check.js +654 -0
  85. package/type/extends/extends-undefined.d.ts +3 -0
  86. package/type/extends/extends-undefined.js +51 -0
  87. package/type/extends/extends.d.ts +9 -0
  88. package/type/extends/extends.js +47 -0
  89. package/type/extends/index.d.ts +3 -0
  90. package/type/extends/index.js +46 -0
  91. package/type/extract/extract.d.ts +20 -0
  92. package/type/extract/extract.js +54 -0
  93. package/type/extract/index.d.ts +1 -0
  94. package/type/extract/index.js +44 -0
  95. package/type/function/function.d.ts +17 -0
  96. package/type/function/function.js +43 -0
  97. package/type/function/index.d.ts +1 -0
  98. package/type/function/index.js +44 -0
  99. package/type/guard/index.d.ts +2 -0
  100. package/type/guard/index.js +32 -0
  101. package/type/guard/type.d.ts +130 -0
  102. package/type/guard/type.js +515 -0
  103. package/type/guard/value.d.ts +28 -0
  104. package/type/guard/value.js +100 -0
  105. package/type/helpers/helpers.d.ts +42 -0
  106. package/type/helpers/helpers.js +35 -0
  107. package/type/helpers/index.d.ts +1 -0
  108. package/type/helpers/index.js +44 -0
  109. package/type/index.d.ts +70 -0
  110. package/type/index.js +113 -0
  111. package/type/indexed/index.d.ts +3 -0
  112. package/type/indexed/index.js +46 -0
  113. package/type/indexed/indexed-key.d.ts +17 -0
  114. package/type/indexed/indexed-key.js +65 -0
  115. package/type/indexed/indexed-type.d.ts +33 -0
  116. package/type/indexed/indexed-type.js +106 -0
  117. package/type/indexed/indexed.d.ts +8 -0
  118. package/type/indexed/indexed.js +41 -0
  119. package/type/instance-type/index.d.ts +1 -0
  120. package/type/instance-type/index.js +44 -0
  121. package/type/instance-type/instance-type.d.ts +5 -0
  122. package/type/instance-type/instance-type.js +36 -0
  123. package/type/integer/index.d.ts +1 -0
  124. package/type/integer/index.js +44 -0
  125. package/type/integer/integer.d.ts +16 -0
  126. package/type/integer/integer.js +40 -0
  127. package/type/intersect/index.d.ts +1 -0
  128. package/type/intersect/index.js +44 -0
  129. package/type/intersect/intersect.d.ts +22 -0
  130. package/type/intersect/intersect.js +59 -0
  131. package/type/intrinsic/index.d.ts +1 -0
  132. package/type/intrinsic/index.js +44 -0
  133. package/type/intrinsic/intrinsic.d.ts +27 -0
  134. package/type/intrinsic/intrinsic.js +106 -0
  135. package/type/iterator/index.d.ts +1 -0
  136. package/type/iterator/index.js +44 -0
  137. package/type/iterator/iterator.d.ts +11 -0
  138. package/type/iterator/iterator.js +42 -0
  139. package/type/keyof/index.d.ts +3 -0
  140. package/type/keyof/index.js +46 -0
  141. package/type/keyof/keyof-string.d.ts +30 -0
  142. package/type/keyof/keyof-string.js +103 -0
  143. package/type/keyof/keyof-type.d.ts +11 -0
  144. package/type/keyof/keyof-type.js +48 -0
  145. package/type/keyof/keyof.d.ts +5 -0
  146. package/type/keyof/keyof.js +38 -0
  147. package/type/literal/index.d.ts +1 -0
  148. package/type/literal/index.js +44 -0
  149. package/type/literal/literal.d.ts +10 -0
  150. package/type/literal/literal.js +41 -0
  151. package/type/mapped/index.d.ts +1 -0
  152. package/type/mapped/index.js +44 -0
  153. package/type/mapped/mapped.d.ts +26 -0
  154. package/type/mapped/mapped.js +47 -0
  155. package/type/modifiers/index.d.ts +1 -0
  156. package/type/modifiers/index.js +44 -0
  157. package/type/modifiers/modifiers.d.ts +18 -0
  158. package/type/modifiers/modifiers.js +78 -0
  159. package/type/never/index.d.ts +1 -0
  160. package/type/never/index.js +44 -0
  161. package/type/never/never.d.ts +9 -0
  162. package/type/never/never.js +40 -0
  163. package/type/not/index.d.ts +1 -0
  164. package/type/not/index.js +44 -0
  165. package/type/not/not.d.ts +10 -0
  166. package/type/not/not.js +41 -0
  167. package/type/null/index.d.ts +1 -0
  168. package/type/null/index.js +44 -0
  169. package/type/null/null.d.ts +9 -0
  170. package/type/null/null.js +40 -0
  171. package/type/number/index.d.ts +1 -0
  172. package/type/number/index.js +44 -0
  173. package/type/number/number.d.ts +16 -0
  174. package/type/number/number.js +40 -0
  175. package/type/object/index.d.ts +1 -0
  176. package/type/object/index.js +44 -0
  177. package/type/object/object.d.ts +44 -0
  178. package/type/object/object.js +47 -0
  179. package/type/omit/index.d.ts +1 -0
  180. package/type/omit/index.js +44 -0
  181. package/type/omit/omit.d.ts +21 -0
  182. package/type/omit/omit.js +75 -0
  183. package/type/operators/index.d.ts +1 -0
  184. package/type/operators/index.js +44 -0
  185. package/type/operators/operators.d.ts +24 -0
  186. package/type/operators/operators.js +119 -0
  187. package/type/optional/index.d.ts +1 -0
  188. package/type/optional/index.js +44 -0
  189. package/type/optional/optional.d.ts +7 -0
  190. package/type/optional/optional.js +37 -0
  191. package/type/parameters/index.d.ts +1 -0
  192. package/type/parameters/index.js +44 -0
  193. package/type/parameters/parameters.d.ts +7 -0
  194. package/type/parameters/parameters.js +37 -0
  195. package/type/partial/index.d.ts +1 -0
  196. package/type/partial/index.js +44 -0
  197. package/type/partial/partial.d.ts +23 -0
  198. package/type/partial/partial.js +73 -0
  199. package/type/patterns/index.d.ts +1 -0
  200. package/type/patterns/index.js +44 -0
  201. package/type/patterns/patterns.d.ts +6 -0
  202. package/type/patterns/patterns.js +36 -0
  203. package/type/pick/index.d.ts +1 -0
  204. package/type/pick/index.js +44 -0
  205. package/type/pick/pick.d.ts +21 -0
  206. package/type/pick/pick.js +66 -0
  207. package/type/promise/index.d.ts +1 -0
  208. package/type/promise/index.js +44 -0
  209. package/type/promise/promise.d.ts +11 -0
  210. package/type/promise/promise.js +42 -0
  211. package/type/readonly/index.d.ts +1 -0
  212. package/type/readonly/index.js +44 -0
  213. package/type/readonly/readonly.d.ts +7 -0
  214. package/type/readonly/readonly.js +37 -0
  215. package/type/readonly-optional/index.d.ts +1 -0
  216. package/type/readonly-optional/index.js +44 -0
  217. package/type/readonly-optional/readonly-optional.d.ts +6 -0
  218. package/type/readonly-optional/readonly-optional.js +37 -0
  219. package/type/record/index.d.ts +1 -0
  220. package/type/record/index.js +44 -0
  221. package/type/record/record.d.ts +55 -0
  222. package/type/record/record.js +97 -0
  223. package/type/recursive/index.d.ts +1 -0
  224. package/type/recursive/index.js +44 -0
  225. package/type/recursive/recursive.d.ts +15 -0
  226. package/type/recursive/recursive.js +48 -0
  227. package/type/ref/index.d.ts +1 -0
  228. package/type/ref/index.js +44 -0
  229. package/type/ref/ref.d.ts +12 -0
  230. package/type/ref/ref.js +45 -0
  231. package/type/regexp/index.d.ts +1 -0
  232. package/type/regexp/index.js +44 -0
  233. package/type/regexp/regexp.d.ts +7 -0
  234. package/type/regexp/regexp.js +38 -0
  235. package/type/registry/format.d.ts +13 -0
  236. package/type/registry/format.js +62 -0
  237. package/type/registry/index.d.ts +2 -0
  238. package/type/registry/index.js +32 -0
  239. package/type/registry/type.d.ts +13 -0
  240. package/type/registry/type.js +62 -0
  241. package/type/required/index.d.ts +1 -0
  242. package/type/required/index.js +44 -0
  243. package/type/required/required.d.ts +23 -0
  244. package/type/required/required.js +72 -0
  245. package/type/rest/index.d.ts +1 -0
  246. package/type/rest/index.js +44 -0
  247. package/type/rest/rest.d.ts +10 -0
  248. package/type/rest/rest.js +41 -0
  249. package/type/return-type/index.d.ts +1 -0
  250. package/type/return-type/index.js +44 -0
  251. package/type/return-type/return-type.d.ts +5 -0
  252. package/type/return-type/return-type.js +36 -0
  253. package/type/schema/anyschema.d.ts +32 -0
  254. package/type/schema/anyschema.js +29 -0
  255. package/type/schema/index.d.ts +2 -0
  256. package/type/schema/index.js +45 -0
  257. package/type/schema/schema.d.ts +29 -0
  258. package/type/schema/schema.js +30 -0
  259. package/type/static/index.d.ts +1 -0
  260. package/type/static/index.js +44 -0
  261. package/type/static/static.d.ts +34 -0
  262. package/type/static/static.js +29 -0
  263. package/type/strict/index.d.ts +1 -0
  264. package/type/strict/index.js +44 -0
  265. package/type/strict/strict.d.ts +3 -0
  266. package/type/strict/strict.js +35 -0
  267. package/type/string/index.d.ts +1 -0
  268. package/type/string/index.js +44 -0
  269. package/type/string/string.d.ts +25 -0
  270. package/type/string/string.js +36 -0
  271. package/type/symbol/index.d.ts +1 -0
  272. package/type/symbol/index.js +44 -0
  273. package/type/symbol/symbol.d.ts +10 -0
  274. package/type/symbol/symbol.js +36 -0
  275. package/type/symbols/index.d.ts +1 -0
  276. package/type/symbols/index.js +44 -0
  277. package/type/symbols/symbols.d.ts +10 -0
  278. package/type/symbols/symbols.js +40 -0
  279. package/type/template-literal/finite.d.ts +16 -0
  280. package/type/template-literal/finite.js +71 -0
  281. package/type/template-literal/generate.d.ts +15 -0
  282. package/type/template-literal/generate.js +74 -0
  283. package/type/template-literal/index.d.ts +7 -0
  284. package/type/template-literal/index.js +50 -0
  285. package/type/template-literal/parser.d.ts +19 -0
  286. package/type/template-literal/parser.js +175 -0
  287. package/type/template-literal/pattern.d.ts +4 -0
  288. package/type/template-literal/pattern.js +61 -0
  289. package/type/template-literal/syntax.d.ts +20 -0
  290. package/type/template-literal/syntax.js +87 -0
  291. package/type/template-literal/template-literal.d.ts +30 -0
  292. package/type/template-literal/template-literal.js +43 -0
  293. package/type/template-literal/union.d.ts +7 -0
  294. package/type/template-literal/union.js +48 -0
  295. package/type/transform/index.d.ts +1 -0
  296. package/type/transform/index.js +44 -0
  297. package/type/transform/transform.d.ts +29 -0
  298. package/type/transform/transform.js +72 -0
  299. package/type/tuple/index.d.ts +1 -0
  300. package/type/tuple/index.js +44 -0
  301. package/type/tuple/tuple.d.ts +15 -0
  302. package/type/tuple/tuple.js +42 -0
  303. package/type/type/index.d.ts +6 -0
  304. package/type/type/index.js +44 -0
  305. package/type/type/javascript.d.ts +58 -0
  306. package/type/type/javascript.js +120 -0
  307. package/type/type/json.d.ts +139 -0
  308. package/type/type/json.js +255 -0
  309. package/type/type/type.d.ts +58 -0
  310. package/type/type/type.js +153 -0
  311. package/type/uint8array/index.d.ts +1 -0
  312. package/type/uint8array/index.js +44 -0
  313. package/type/uint8array/uint8array.d.ts +13 -0
  314. package/type/uint8array/uint8array.js +36 -0
  315. package/type/undefined/index.d.ts +1 -0
  316. package/type/undefined/index.js +44 -0
  317. package/type/undefined/undefined.d.ts +9 -0
  318. package/type/undefined/undefined.js +36 -0
  319. package/type/union/index.d.ts +1 -0
  320. package/type/union/index.js +44 -0
  321. package/type/union/union.d.ts +16 -0
  322. package/type/union/union.js +50 -0
  323. package/type/unknown/index.d.ts +1 -0
  324. package/type/unknown/index.js +44 -0
  325. package/type/unknown/unknown.d.ts +8 -0
  326. package/type/unknown/unknown.js +39 -0
  327. package/type/unsafe/index.d.ts +1 -0
  328. package/type/unsafe/index.js +44 -0
  329. package/type/unsafe/unsafe.d.ts +11 -0
  330. package/type/unsafe/unsafe.js +39 -0
  331. package/type/void/index.d.ts +1 -0
  332. package/type/void/index.js +44 -0
  333. package/type/void/void.d.ts +9 -0
  334. package/type/void/void.js +40 -0
  335. package/value/cast/cast.d.ts +23 -0
  336. package/value/{cast.js → cast/cast.js} +62 -83
  337. package/value/cast/index.d.ts +1 -0
  338. package/value/cast/index.js +44 -0
  339. package/value/check/check.d.ts +10 -0
  340. package/value/{check.js → check/check.js} +50 -45
  341. package/value/check/index.d.ts +1 -0
  342. package/value/check/index.js +44 -0
  343. package/value/clean/clean.d.ts +5 -0
  344. package/value/clean/clean.js +167 -0
  345. package/value/clean/index.d.ts +1 -0
  346. package/value/clean/index.js +44 -0
  347. package/value/{clone.js → clone/clone.js} +6 -6
  348. package/value/clone/index.d.ts +1 -0
  349. package/value/clone/index.js +44 -0
  350. package/value/convert/convert.d.ts +9 -0
  351. package/value/{convert.js → convert/convert.js} +93 -116
  352. package/value/convert/index.d.ts +1 -0
  353. package/value/convert/index.js +44 -0
  354. package/value/create/create.d.ts +31 -0
  355. package/value/{create.js → create/create.js} +69 -62
  356. package/value/create/index.d.ts +1 -0
  357. package/value/create/index.js +44 -0
  358. package/value/default/default.d.ts +5 -0
  359. package/value/default/default.js +175 -0
  360. package/value/default/index.d.ts +1 -0
  361. package/value/default/index.js +44 -0
  362. package/value/delta/delta.d.ts +41 -0
  363. package/value/{delta.js → delta/delta.js} +57 -53
  364. package/value/delta/index.d.ts +1 -0
  365. package/value/delta/index.js +44 -0
  366. package/value/{deref.d.ts → deref/deref.d.ts} +4 -2
  367. package/value/{deref.js → deref/deref.js} +1 -2
  368. package/value/deref/index.d.ts +1 -0
  369. package/value/deref/index.js +44 -0
  370. package/value/{equal.js → equal/equal.js} +14 -14
  371. package/value/equal/index.d.ts +1 -0
  372. package/value/equal/index.js +44 -0
  373. package/value/guard/index.d.ts +1 -0
  374. package/value/guard/index.js +44 -0
  375. package/value/{hash.d.ts → hash/hash.d.ts} +0 -13
  376. package/value/{hash.js → hash/hash.js} +26 -26
  377. package/value/hash/index.d.ts +1 -0
  378. package/value/hash/index.js +44 -0
  379. package/value/index.d.ts +17 -4
  380. package/value/index.js +91 -10
  381. package/value/mutate/index.d.ts +1 -0
  382. package/value/mutate/index.js +44 -0
  383. package/value/{mutate.d.ts → mutate/mutate.d.ts} +1 -1
  384. package/value/{mutate.js → mutate/mutate.js} +25 -25
  385. package/value/pointer/index.d.ts +1 -0
  386. package/value/pointer/index.js +31 -0
  387. package/value/pointer/pointer.d.ts +21 -0
  388. package/value/pointer/pointer.js +151 -0
  389. package/value/transform/decode.d.ts +19 -0
  390. package/value/transform/decode.js +211 -0
  391. package/value/transform/encode.d.ts +20 -0
  392. package/value/transform/encode.js +219 -0
  393. package/value/transform/has.d.ts +3 -0
  394. package/value/transform/has.js +146 -0
  395. package/value/transform/index.d.ts +3 -0
  396. package/value/transform/index.js +46 -0
  397. package/value/value/index.d.ts +1 -0
  398. package/value/value/index.js +31 -0
  399. package/value/value/value.d.ts +53 -0
  400. package/value/value/value.js +125 -0
  401. package/typebox.d.ts +0 -962
  402. package/typebox.js +0 -2364
  403. package/value/cast.d.ts +0 -24
  404. package/value/check.d.ts +0 -9
  405. package/value/convert.d.ts +0 -10
  406. package/value/create.d.ts +0 -30
  407. package/value/delta.d.ts +0 -41
  408. package/value/pointer.d.ts +0 -24
  409. package/value/pointer.js +0 -148
  410. package/value/transform.d.ts +0 -42
  411. package/value/transform.js +0 -517
  412. package/value/value.d.ts +0 -47
  413. package/value/value.js +0 -117
  414. /package/value/{clone.d.ts → clone/clone.d.ts} +0 -0
  415. /package/value/{equal.d.ts → equal/equal.d.ts} +0 -0
  416. /package/value/{guard.d.ts → guard/guard.d.ts} +0 -0
  417. /package/value/{guard.js → guard/guard.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.31.27",
3
+ "version": "0.32.0-dev-1",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
@@ -16,27 +16,19 @@
16
16
  "./compiler": "./compiler/index.js",
17
17
  "./errors": "./errors/index.js",
18
18
  "./system": "./system/index.js",
19
- "./value/cast": "./value/cast.js",
20
- "./value/check": "./value/check.js",
21
- "./value/clone": "./value/clone.js",
22
- "./value/convert": "./value/convert.js",
23
- "./value/create": "./value/create.js",
24
- "./value/delta": "./value/delta.js",
25
- "./value/deref": "./value/deref.js",
26
- "./value/equal": "./value/equal.js",
27
- "./value/guard": "./value/guard.js",
28
- "./value/hash": "./value/hash.js",
29
- "./value/mutate": "./value/mutate.js",
30
- "./value/pointer": "./value/pointer.js",
31
- "./value/transform": "./value/transform.js",
19
+ "./type": "./type/index.js",
32
20
  "./value": "./value/index.js",
33
- ".": "./typebox.js"
21
+ ".": "./index.js"
34
22
  },
35
23
  "repository": {
36
24
  "type": "git",
37
25
  "url": "https://github.com/sinclairzx81/typebox"
38
26
  },
39
27
  "scripts": {
28
+ "benchmark:compression": "hammer task benchmark_compression",
29
+ "benchmark:measurement": "hammer task benchmark_measurement",
30
+ "benchmark": "hammer task benchmark",
31
+ "install:local": "hammer task install_local",
40
32
  "test:typescript": "hammer task test_typescript",
41
33
  "test:static": "hammer task test_static",
42
34
  "test:runtime": "hammer task test_runtime",
@@ -44,9 +36,6 @@
44
36
  "clean": "hammer task clean",
45
37
  "format": "hammer task format",
46
38
  "start": "hammer task start",
47
- "benchmark:compression": "hammer task benchmark_compression",
48
- "benchmark:measurement": "hammer task benchmark_measurement",
49
- "benchmark": "hammer task benchmark",
50
39
  "build": "hammer task build",
51
40
  "publish": "hammer task publish",
52
41
  "publish:dev": "hammer task publish_dev"
@@ -59,6 +48,6 @@
59
48
  "ajv-formats": "^2.1.1",
60
49
  "mocha": "^9.2.2",
61
50
  "prettier": "^2.7.1",
62
- "typescript": "^5.2.2"
51
+ "typescript": "^5.3.2"
63
52
  }
64
53
  }
package/readme.md CHANGED
@@ -25,16 +25,10 @@
25
25
  $ npm install @sinclair/typebox --save
26
26
  ```
27
27
 
28
- #### Esm + Deno
29
-
30
- ```typescript
31
- import { Type, Static } from 'https://esm.sh/@sinclair/typebox'
32
- ```
33
-
34
28
  ## Example
35
29
 
36
30
  ```typescript
37
- import { Type, Static } from '@sinclair/typebox'
31
+ import { Type, type Static } from '@sinclair/typebox'
38
32
 
39
33
  const T = Type.Object({ // const T = {
40
34
  x: Type.Number(), // type: 'object',
@@ -90,6 +84,8 @@ License MIT
90
84
  - [Clone](#values-clone)
91
85
  - [Check](#values-check)
92
86
  - [Convert](#values-convert)
87
+ - [Default](#values-default)
88
+ - [Clean](#values-clean)
93
89
  - [Cast](#values-cast)
94
90
  - [Decode](#values-decode)
95
91
  - [Encode](#values-decode)
@@ -107,8 +103,6 @@ License MIT
107
103
  - [Ajv](#typecheck-ajv)
108
104
  - [TypeCompiler](#typecheck-typecompiler)
109
105
  - [TypeSystem](#typesystem)
110
- - [Types](#typesystem-types)
111
- - [Formats](#typesystem-formats)
112
106
  - [Errors](#typesystem-errors)
113
107
  - [Policies](#typesystem-policies)
114
108
  - [Workbench](#workbench)
@@ -127,7 +121,7 @@ License MIT
127
121
  The following shows general usage.
128
122
 
129
123
  ```typescript
130
- import { Type, Static } from '@sinclair/typebox'
124
+ import { Type, type Static } from '@sinclair/typebox'
131
125
 
132
126
  //--------------------------------------------------------------------------------------------
133
127
  //
@@ -297,6 +291,22 @@ The following table lists the supported Json types. These types are fully compat
297
291
  │ │ │ } │
298
292
  │ │ │ │
299
293
  ├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
294
+ │ const T = Type.Const({ │ type T = { │ const T = { │
295
+ │ x: 1, │ readonly x: 1, │ type: 'object', │
296
+ │ y: 2, │ readonly y: 2 │ required: ['x', 'y'], │
297
+ │ } as const) │ } │ properties: { │
298
+ │ │ │ x: { │
299
+ │ │ │ type: 'number', │
300
+ │ │ │ const: 1 │
301
+ │ │ │ }, │
302
+ │ │ │ y: { │
303
+ │ │ │ type: 'number', │
304
+ │ │ │ const: 2 │
305
+ │ │ │ } │
306
+ │ │ │ } │
307
+ │ │ │ } │
308
+ │ │ │ │
309
+ ├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
300
310
  │ const T = Type.KeyOf( │ type T = keyof { │ const T = { │
301
311
  │ Type.Object({ │ x: number, │ anyOf: [{ │
302
312
  │ x: Type.Number(), │ y: number │ type: 'string', │
@@ -697,7 +707,7 @@ Object properties can be modified with Readonly and Optional. The following tabl
697
707
  Generic types can be created with generic functions. All types extend the base type TSchema. It is common to constrain generic function arguments to this type. The following creates a generic Vector type.
698
708
 
699
709
  ```typescript
700
- import { Type, Static, TSchema } from '@sinclair/typebox'
710
+ import { Type, type Static, type TSchema } from '@sinclair/typebox'
701
711
 
702
712
  const Vector = <T extends TSchema>(t: T) => Type.Object({ x: t, y: t, z: t })
703
713
 
@@ -737,20 +747,65 @@ type T = Static<typeof T> // type T = string | null
737
747
 
738
748
  ### Reference Types
739
749
 
740
- Reference types are supported with Ref.
750
+ Reference types can be created with Type.Ref. These types infer the same as the target type.
741
751
 
742
752
  ```typescript
743
- const T = Type.String({ $id: 'T' }) // const T = {
744
- // $id: 'T',
745
- // type: 'string'
746
- // }
753
+ const Vector = Type.Object({ // const Vector = {
754
+ x: Type.Number(), // type: 'object',
755
+ y: Type.Number(), // required: ['x', 'y', 'z'],
756
+ }, { $id: 'Vector' }) // properties: {
757
+ // x: { type: 'number' },
758
+ // y: { type: 'number' }
759
+ // },
760
+ // $id: 'Vector'
761
+ // }
747
762
 
748
- const R = Type.Ref<typeof T>('T') // const R = {
749
- // $ref: 'T'
763
+ const VectorRef = Type.Ref(Vector) // const VectorRef = {
764
+ // $ref: 'Vector'
750
765
  // }
751
766
 
752
- type R = Static<typeof R> // type R = string
767
+ type VectorRef = Static<typeof VectorRef> // type VectorRef = {
768
+ // x: number,
769
+ // y: number
770
+ // }
753
771
  ```
772
+ Use Type.Deref to dereference a type. This type will recursively reconstruct interior referenced types.
773
+ ```typescript
774
+ const Vertex = Type.Object({ // const Vertex = {
775
+ position: VectorRef, // type: 'object',
776
+ texcoord: VectorRef, // required: ['position', 'texcoord'],
777
+ }) // properties: {
778
+ // position: { $ref: 'Vector' },
779
+ // texcoord: { $ref: 'Vector' }
780
+ // }
781
+ // }
782
+
783
+ const VertexDeref = Type.Deref(Vertex, [Vector]) // const VertexDeref = {
784
+ // type: 'object',
785
+ // required: ['position', 'texcoord'],
786
+ // properties: {
787
+ // position: {
788
+ // type: 'object',
789
+ // required: ['x', 'y', 'z'],
790
+ // properties: {
791
+ // x: { type: 'number' },
792
+ // y: { type: 'number' }
793
+ // }
794
+ // },
795
+ // texcoord: {
796
+ // type: 'object',
797
+ // required: ['x', 'y', 'z'],
798
+ // properties: {
799
+ // x: { type: 'number' },
800
+ // y: { type: 'number' }
801
+ // }
802
+ // }
803
+ // }
804
+ // }
805
+
806
+
807
+ ```
808
+ Note that reference types do not contain structural information about the type they're referencing. This means they cannot be used directly with some type mapping types (such as Partial) that require structural information to operate. For applications that need mapping on references, use Type.Deref to dereference the type first.
754
809
 
755
810
  <a name='types-recursive'></a>
756
811
 
@@ -793,88 +848,80 @@ function test(node: Node) {
793
848
 
794
849
  ### Conditional Types
795
850
 
796
- TypeBox supports runtime conditional types with Extends. This type will perform a structural assignability check for the first two arguments and returns one of the second two arguments based on the result. The Extends type is modelled after TypeScript conditional types. The Exclude and Extract conditional types are also supported.
851
+ TypeBox supports runtime conditional types with Extends. This type performs a structural assignability check for the first two arguments and will infer one of the second two arguments based on the result. The Extends type is designed to match the assignability rules of TypeScript conditional types. The conditional derived types Exclude and Extract are also supported.
797
852
 
798
853
  ```typescript
799
- // TypeScript
800
-
801
- type T0 = string extends number ? true : false // type T0 = false
854
+ // Extends
802
855
 
803
- type T1 = Extract<(1 | 2 | 3), 1> // type T1 = 1
856
+ type T = string extends number ? true : false // type T = false
804
857
 
805
- type T2 = Exclude<(1 | 2 | 3), 1> // type T2 = 2 | 3
806
-
807
- // TypeBox
808
-
809
- const T0 = Type.Extends( // const T0: TLiteral<false> = {
810
- Type.String(), // type: 'boolean',
811
- Type.Number(), // const: false
812
- Type.Literal(true), // }
858
+ const T = Type.Extends( // const T: TLiteral<false>
859
+ Type.String(),
860
+ Type.Number(),
861
+ Type.Literal(true),
813
862
  Type.Literal(false)
814
863
  )
815
864
 
816
- const T1 = Type.Extract( // const T1: TLiteral<1> = {
817
- Type.Union([ // type: 'number',
818
- Type.Literal(1), // const: 1
819
- Type.Literal(2), // }
865
+ // Extract
866
+
867
+ type T = Extract<1 | 2 | 3, 1> // type T = 1
868
+
869
+ const T = Type.Extract( // const T: TLiteral<1>
870
+ Type.Union([
871
+ Type.Literal(1),
872
+ Type.Literal(2),
820
873
  Type.Literal(3)
821
874
  ]),
822
875
  Type.Literal(1)
823
876
  )
824
877
 
825
- const T2 = Type.Exclude( // const T2: TUnion<[
878
+ // Exclude
879
+
880
+ type T = Exclude<1 | 2 | 3, 1> // type T = 2 | 3
881
+
882
+ const T = Type.Exclude( // const T: TUnion<[
826
883
  Type.Union([ // TLiteral<2>,
827
884
  Type.Literal(1), // TLiteral<3>
828
- Type.Literal(2), // ]> = {
829
- Type.Literal(3) // anyOf: [{
830
- ]), // type: 'number',
831
- Type.Literal(1) // const: 2
832
- ) // }, {
833
- // type: 'number',
834
- // const: 3
835
- // }]
836
- // }
885
+ Type.Literal(2), // ]>
886
+ Type.Literal(3)
887
+ ]),
888
+ Type.Literal(1)
889
+ )
837
890
  ```
838
891
 
839
892
  <a name='types-templateliteral'></a>
840
893
 
841
894
  ### Template Literal Types
842
895
 
843
- TypeBox supports template literal types with TemplateLiteral. This type can be created using a string syntax that is similar to the TypeScript template literal syntax. This type can also be constructed by passing an array of Union and Literal types in sequence. The following example shows the string syntax.
896
+ TypeBox supports template literal types with TemplateLiteral. This type can be created using a syntax similar to the TypeScript template literal syntax. TypeBox encodes template literals as regular expression string patterns which enable the template be checked via Json Schema. It also supports regular expression parsing, enabling template patterns to be used for generative types. The following shows both TypeScript and TypeBox usage.
844
897
 
845
898
  ```typescript
846
899
  // TypeScript
847
900
 
848
- type T = `option${'A'|'B'|'C'}` // type T = 'optionA' | 'optionB' | 'optionC'
901
+ type K = `prop${'A'|'B'|'C'}` // type T = 'propA' | 'propB' | 'propC'
849
902
 
850
- type R = Record<T, string> // type R = {
851
- // optionA: string
852
- // optionB: string
853
- // optionC: string
903
+ type R = Record<K, string> // type R = {
904
+ // propA: string
905
+ // propB: string
906
+ // propC: string
854
907
  // }
855
908
 
856
909
  // TypeBox
857
910
 
858
- const T = Type.TemplateLiteral('option${A|B|C}') // const T = {
859
- // pattern: '^option(A|B|C)$',
860
- // type: 'string'
861
- // }
911
+ const K = Type.TemplateLiteral('prop${A|B|C}') // const K: TTemplateLiteral<[
912
+ // TLiteral<'prop'>,
913
+ // TUnion<[
914
+ // TLiteral<'A'>,
915
+ // TLiteral<'B'>,
916
+ // TLiteral<'C'>,
917
+ // ]>
918
+ // ]>
862
919
 
863
- const R = Type.Record(T, Type.String()) // const R = {
864
- // type: 'object',
865
- // required: ['optionA', 'optionB'],
866
- // properties: {
867
- // optionA: {
868
- // type: 'string'
869
- // },
870
- // optionB: {
871
- // type: 'string'
872
- // }
873
- // optionC: {
874
- // type: 'string'
875
- // }
876
- // }
877
- // }
920
+ const R = Type.Record(K, Type.String()) // const R: TObject<{
921
+ // hello1: TString,
922
+ // hello2: TString,
923
+ // hello3: TString,
924
+ // }>
878
925
  ```
879
926
 
880
927
  <a name='types-indexed'></a>
@@ -884,32 +931,24 @@ const R = Type.Record(T, Type.String()) // const R = {
884
931
  TypeBox supports Indexed Access Types with Index. This type enables uniform access to interior property and array element types without having to extract them from the underlying schema representation. This type is supported for Object, Array, Tuple, Union and Intersect types.
885
932
 
886
933
  ```typescript
887
- const T = Type.Object({ // const T = {
888
- x: Type.Number(), // type: 'object',
889
- y: Type.String(), // required: ['x', 'y', 'z'],
890
- z: Type.Boolean() // properties: {
891
- }) // x: { type: 'number' },
892
- // y: { type: 'string' },
893
- // z: { type: 'string' }
894
- // }
895
- // }
934
+ const T = Type.Object({ // const T: TObject<{
935
+ x: Type.Number(), // x: TNumber,
936
+ y: Type.String(), // y: TString,
937
+ z: Type.Boolean() // z: TBoolean
938
+ }) // }>
896
939
 
897
- const A = Type.Index(T, ['x']) // const A = { type: 'number' }
940
+ const A = Type.Index(T, ['x']) // const A: TNumber
898
941
 
899
- const B = Type.Index(T, ['x', 'y']) // const B = {
900
- // anyOf: [
901
- // { type: 'number' },
902
- // { type: 'string' }
903
- // ]
904
- // }
942
+ const B = Type.Index(T, ['x', 'y']) // const B: TUnion<[
943
+ // TNumber,
944
+ // TString,
945
+ // ]>
905
946
 
906
- const C = Type.Index(T, Type.KeyOf(T)) // const C = {
907
- // anyOf: [
908
- // { type: 'number' },
909
- // { type: 'string' },
910
- // { type: 'boolean' }
911
- // ]
912
- // }
947
+ const C = Type.Index(T, Type.KeyOf(T)) // const C: TUnion<[
948
+ // TNumber,
949
+ // TString,
950
+ // TBoolean
951
+ // ]>
913
952
  ```
914
953
 
915
954
  <a name='types-rest'></a>
@@ -919,28 +958,17 @@ const C = Type.Index(T, Type.KeyOf(T)) // const C = {
919
958
  TypeBox provides the Rest type to uniformly extract variadic tuples from Intersect, Union and Tuple types. This type can be useful to remap variadic types into different forms. The following uses Rest to remap a Tuple into a Union.
920
959
 
921
960
  ```typescript
922
- const T = Type.Tuple([ // const T = {
923
- Type.String(), // type: 'array',
924
- Type.Number() // items: [
925
- ]) // { type: 'string' },
926
- // { type: 'number' }
927
- // ],
928
- // additionalItems: false,
929
- // minItems: 2,
930
- // maxItems: 2,
931
- // }
961
+ const T = Type.Tuple([ // const T: TTuple<[
962
+ Type.String(), // TString,
963
+ Type.Number() // TNumber
964
+ ]) // ]>
932
965
 
933
- const R = Type.Rest(T) // const R = [
934
- // { type: 'string' },
935
- // { type: 'number' }
936
- // ]
966
+ const R = Type.Rest(T) // const R: [TString, TNumber]
937
967
 
938
- const U = Type.Union(R) // const U = {
939
- // anyOf: [
940
- // { type: 'string' },
941
- // { type: 'number' }
942
- // ]
943
- // }
968
+ const U = Type.Union(R) // const T: TUnion<[
969
+ // TString,
970
+ // TNumber
971
+ // ]>
944
972
  ```
945
973
 
946
974
  <a name='types-transform'></a>
@@ -1042,12 +1070,12 @@ type S = Static<typeof T> // type S = 'A' | 'B' | 'C'
1042
1070
  ```
1043
1071
  <a name='types-guard'></a>
1044
1072
 
1045
- ### Type Guard
1073
+ ### TypeGuard
1046
1074
 
1047
1075
  TypeBox can type check its own types with the TypeGuard module. This module is written for reflection and provides structural tests for every TypeBox type. Functions of this module return `is` guards which can be used with TypeScript control flow assertions to obtain schema inference. The following guards that the value A is TString.
1048
1076
 
1049
1077
  ```typescript
1050
- import { Type, Kind, TypeGuard } from '@sinclair/typebox'
1078
+ import { Type, TypeGuard } from '@sinclair/typebox'
1051
1079
 
1052
1080
  const A: unknown = { ... }
1053
1081
 
@@ -1144,6 +1172,44 @@ const R1 = Value.Convert(T, { x: '3.14' }) // const R1 = { x: 3.14 }
1144
1172
  const R2 = Value.Convert(T, { x: 'not a number' }) // const R2 = { x: 'not a number' }
1145
1173
  ```
1146
1174
 
1175
+ <a name='values-clean'></a>
1176
+
1177
+ ### Clean
1178
+
1179
+ Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first.
1180
+
1181
+ ```typescript
1182
+ const T = Type.Object({
1183
+ x: Type.Number(),
1184
+ y: Type.Number()
1185
+ })
1186
+
1187
+ const X = Value.Clean(T, null) // const 'X = null
1188
+
1189
+ const Y = Value.Clean(T, { x: 1 }) // const 'Y = { x: 1 }
1190
+
1191
+ const Z = Value.Clean(T, { x: 1, y: 2, z: 3 }) // const 'Z = { x: 1, y: 2 }
1192
+ ```
1193
+
1194
+ <a name='values-default'></a>
1195
+
1196
+ ### Default
1197
+
1198
+ Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first.
1199
+
1200
+ ```typescript
1201
+ const T = Type.Object({
1202
+ x: Type.Number({ default: 0 }),
1203
+ y: Type.Number({ default: 0 })
1204
+ })
1205
+
1206
+ const X = Value.Default(T, null) // const 'X = null - non-enumerable
1207
+
1208
+ const Y = Value.Default(T, { }) // const 'Y = { x: 0, y: 0 }
1209
+
1210
+ const Z = Value.Default(T, { x: 1 }) // const 'Z = { x: 1, y: 0 }
1211
+ ```
1212
+
1147
1213
  <a name='values-cast'></a>
1148
1214
 
1149
1215
  ### Cast
@@ -1311,7 +1377,7 @@ The TypeBox type system can be extended with additional types and formats using
1311
1377
  Use the TypeRegistry to register a new type. The Kind must match the registered type name.
1312
1378
 
1313
1379
  ```typescript
1314
- import { TypeRegistry, Kind } from '@sinclair/typebox'
1380
+ import { TypeRegistry, Symbols } from '@sinclair/typebox'
1315
1381
 
1316
1382
  TypeRegistry.Set('Foo', (schema, value) => value === 'foo')
1317
1383
 
@@ -1461,44 +1527,6 @@ const C = TypeCompiler.Code(Type.String()) // const C = `return functi
1461
1527
 
1462
1528
  The TypeBox TypeSystem module provides functionality to define types above and beyond the built-in Json and JavaScript type sets. They also manage TypeBox's localization options (i18n) for error message generation and can control various assertion policies used when type checking. Configurations made to the TypeSystem module are observed by the TypeCompiler, Value and Error modules.
1463
1529
 
1464
- <a name='typesystem-types'></a>
1465
-
1466
- ### Types
1467
-
1468
- Use the TypeSystem Type function to register a user defined type.
1469
-
1470
- ```typescript
1471
- import { TypeSystem } from '@sinclair/typebox/system'
1472
-
1473
- const StringSet = TypeSystem.Type<Set<string>>('StringSet', (options, value) => {
1474
- return value instanceof Set && [...value].every(value => typeof value === 'string')
1475
- })
1476
-
1477
- const T = StringSet({}) // Pass options if any
1478
-
1479
- const A = Value.Check(T, new Set()) // const A = true
1480
- const B = Value.Check(T, new Set(['hello'])) // const B = true
1481
- const C = Value.Check(T, new Set([1])) // const C = false
1482
-
1483
- ```
1484
-
1485
- <a name='typesystem-formats'></a>
1486
-
1487
- ### Formats
1488
-
1489
- Use the TypeSystem Format function to register a string format.
1490
-
1491
- ```typescript
1492
- import { TypeSystem } from '@sinclair/typebox/system'
1493
-
1494
- const F = TypeSystem.Format('foo', value => value === 'Foo')
1495
-
1496
- const T = Type.String({ format: F })
1497
-
1498
- const A = Value.Check(T, 'foo') // const A = true
1499
- const B = Value.Check(T, 'bar') // const B = false
1500
- ```
1501
-
1502
1530
  <a name='typesystem-errors'></a>
1503
1531
 
1504
1532
  ### Errors
@@ -1719,11 +1747,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
1719
1747
  ┌──────────────────────┬────────────┬────────────┬─────────────┐
1720
1748
  │ (index) │ Compiled │ Minified │ Compression │
1721
1749
  ├──────────────────────┼────────────┼────────────┼─────────────┤
1722
- │ typebox/compiler │ '148.9 kb' │ ' 65.8 kb' │ '2.26 x' │
1723
- │ typebox/errors │ '111.5 kb' │ ' 49.1 kb' │ '2.27 x' │
1724
- │ typebox/system │ ' 82.6 kb' │ ' 36.8 kb' │ '2.24 x' │
1725
- │ typebox/value │ '190.5 kb' │ ' 82.4 kb' │ '2.31 x' │
1726
- │ typebox │ ' 72.4 kb' │ ' 31.6 kb' │ '2.29 x' │
1750
+ │ typebox/compiler │ '163.6 kb' │ ' 71.6 kb' │ '2.28 x' │
1751
+ │ typebox/errors │ '113.3 kb' │ ' 50.1 kb' │ '2.26 x' │
1752
+ │ typebox/system │ ' 83.9 kb' │ ' 37.5 kb' │ '2.24 x' │
1753
+ │ typebox/value │ '191.1 kb' │ ' 82.3 kb' │ '2.32 x' │
1754
+ │ typebox │ ' 73.8 kb' │ ' 32.3 kb' │ '2.29 x' │
1727
1755
  └──────────────────────┴────────────┴────────────┴─────────────┘
1728
1756
  ```
1729
1757
 
@@ -0,0 +1,14 @@
1
+ import { ValueErrorType } from '../errors/errors';
2
+ import { TSchema } from '../type/schema/index';
3
+ export type ErrorFunction = (schema: TSchema, type: ValueErrorType) => string;
4
+ /** Manages error message providers */
5
+ export declare namespace TypeSystemErrorFunction {
6
+ /** Resets the error message function to en-us */
7
+ function Reset(): void;
8
+ /** Sets the error message function used to generate error messages */
9
+ function Set(callback: ErrorFunction): void;
10
+ /** Gets the error message function */
11
+ function Get(): ErrorFunction;
12
+ }
13
+ /** Creates an error message using en-US as the default locale */
14
+ export declare function DefaultErrorFunction(schema: TSchema, errorType: ValueErrorType): string;