@sinclair/typebox 0.31.28 → 0.32.0-dev-2
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.
- package/{compiler → cjs/compiler}/compiler.js +118 -107
- package/{compiler → cjs/compiler}/index.js +3 -3
- package/{errors → cjs/errors}/errors.js +48 -44
- package/cjs/index.js +205 -0
- package/cjs/system/errors.js +192 -0
- package/{value → cjs/system}/index.js +13 -14
- package/cjs/system/policy.js +74 -0
- package/cjs/system/system.js +71 -0
- package/cjs/type/any/any.js +36 -0
- package/{system → cjs/type/any}/index.js +2 -5
- package/cjs/type/array/array.js +42 -0
- package/cjs/type/array/index.js +44 -0
- package/cjs/type/async-iterator/async-iterator.js +42 -0
- package/cjs/type/async-iterator/index.js +44 -0
- package/cjs/type/awaited/awaited.js +66 -0
- package/cjs/type/awaited/index.js +44 -0
- package/cjs/type/bigint/bigint.js +40 -0
- package/cjs/type/bigint/index.js +44 -0
- package/cjs/type/boolean/boolean.js +40 -0
- package/cjs/type/boolean/index.js +44 -0
- package/cjs/type/clone/index.js +32 -0
- package/cjs/type/clone/type.js +41 -0
- package/cjs/type/clone/value.js +58 -0
- package/cjs/type/composite/composite.js +47 -0
- package/cjs/type/composite/index.js +44 -0
- package/cjs/type/const/const.js +84 -0
- package/cjs/type/const/index.js +44 -0
- package/cjs/type/constructor/constructor.js +43 -0
- package/cjs/type/constructor/index.js +44 -0
- package/cjs/type/constructor-parameters/constructor-parameters.js +37 -0
- package/cjs/type/constructor-parameters/index.js +44 -0
- package/cjs/type/date/date.js +40 -0
- package/cjs/type/date/index.js +44 -0
- package/cjs/type/deref/deref.js +136 -0
- package/cjs/type/deref/index.js +44 -0
- package/cjs/type/discard/discard.js +38 -0
- package/cjs/type/discard/index.js +44 -0
- package/cjs/type/enum/enum.js +46 -0
- package/cjs/type/enum/index.js +44 -0
- package/cjs/type/exclude/exclude.js +54 -0
- package/cjs/type/exclude/index.js +44 -0
- package/cjs/type/extends/extends-check.js +654 -0
- package/cjs/type/extends/extends-undefined.js +51 -0
- package/cjs/type/extends/extends.js +47 -0
- package/cjs/type/extends/index.js +46 -0
- package/cjs/type/extract/extract.js +54 -0
- package/cjs/type/extract/index.js +44 -0
- package/cjs/type/function/function.js +43 -0
- package/cjs/type/function/index.js +44 -0
- package/cjs/type/guard/index.js +32 -0
- package/cjs/type/guard/type.js +515 -0
- package/cjs/type/guard/value.js +100 -0
- package/cjs/type/helpers/helpers.js +35 -0
- package/cjs/type/helpers/index.js +44 -0
- package/cjs/type/index.js +113 -0
- package/cjs/type/indexed/index.js +46 -0
- package/cjs/type/indexed/indexed-key.js +65 -0
- package/cjs/type/indexed/indexed-type.js +106 -0
- package/cjs/type/indexed/indexed.js +41 -0
- package/cjs/type/instance-type/index.js +44 -0
- package/cjs/type/instance-type/instance-type.js +36 -0
- package/cjs/type/integer/index.js +44 -0
- package/cjs/type/integer/integer.js +40 -0
- package/cjs/type/intersect/index.js +44 -0
- package/cjs/type/intersect/intersect.js +59 -0
- package/cjs/type/intrinsic/index.js +44 -0
- package/cjs/type/intrinsic/intrinsic.js +106 -0
- package/cjs/type/iterator/index.js +44 -0
- package/cjs/type/iterator/iterator.js +42 -0
- package/cjs/type/keyof/index.js +46 -0
- package/cjs/type/keyof/keyof-string.js +103 -0
- package/cjs/type/keyof/keyof-type.js +48 -0
- package/cjs/type/keyof/keyof.js +38 -0
- package/cjs/type/literal/index.js +44 -0
- package/cjs/type/literal/literal.js +41 -0
- package/cjs/type/mapped/index.js +44 -0
- package/cjs/type/mapped/mapped.js +47 -0
- package/cjs/type/modifiers/index.js +44 -0
- package/cjs/type/modifiers/modifiers.js +78 -0
- package/cjs/type/never/index.js +44 -0
- package/cjs/type/never/never.js +40 -0
- package/cjs/type/not/index.js +44 -0
- package/cjs/type/not/not.js +41 -0
- package/cjs/type/null/index.js +44 -0
- package/cjs/type/null/null.js +40 -0
- package/cjs/type/number/index.js +44 -0
- package/cjs/type/number/number.js +40 -0
- package/cjs/type/object/index.js +44 -0
- package/cjs/type/object/object.js +47 -0
- package/cjs/type/omit/index.js +44 -0
- package/cjs/type/omit/omit.js +75 -0
- package/cjs/type/operators/index.js +44 -0
- package/cjs/type/operators/operators.js +119 -0
- package/cjs/type/optional/index.js +44 -0
- package/cjs/type/optional/optional.js +37 -0
- package/cjs/type/parameters/index.js +44 -0
- package/cjs/type/parameters/parameters.js +37 -0
- package/cjs/type/partial/index.js +44 -0
- package/cjs/type/partial/partial.js +73 -0
- package/cjs/type/patterns/index.js +44 -0
- package/cjs/type/patterns/patterns.js +36 -0
- package/cjs/type/pick/index.js +44 -0
- package/cjs/type/pick/pick.js +66 -0
- package/cjs/type/promise/index.js +44 -0
- package/cjs/type/promise/promise.js +42 -0
- package/cjs/type/readonly/index.js +44 -0
- package/cjs/type/readonly/readonly.js +37 -0
- package/cjs/type/readonly-optional/index.js +44 -0
- package/cjs/type/readonly-optional/readonly-optional.js +37 -0
- package/cjs/type/record/index.js +44 -0
- package/cjs/type/record/record.js +97 -0
- package/cjs/type/recursive/index.js +44 -0
- package/cjs/type/recursive/recursive.js +48 -0
- package/cjs/type/ref/index.js +44 -0
- package/cjs/type/ref/ref.js +45 -0
- package/cjs/type/regexp/index.js +44 -0
- package/cjs/type/regexp/regexp.js +38 -0
- package/cjs/type/registry/format.js +62 -0
- package/cjs/type/registry/index.js +32 -0
- package/cjs/type/registry/type.js +62 -0
- package/cjs/type/required/index.js +44 -0
- package/cjs/type/required/required.js +72 -0
- package/cjs/type/rest/index.js +44 -0
- package/cjs/type/rest/rest.js +41 -0
- package/cjs/type/return-type/index.js +44 -0
- package/cjs/type/return-type/return-type.js +36 -0
- package/cjs/type/schema/anyschema.js +29 -0
- package/cjs/type/schema/index.js +45 -0
- package/cjs/type/schema/schema.js +30 -0
- package/cjs/type/static/index.js +44 -0
- package/cjs/type/static/static.js +29 -0
- package/cjs/type/strict/index.js +44 -0
- package/cjs/type/strict/strict.js +35 -0
- package/cjs/type/string/index.js +44 -0
- package/cjs/type/string/string.js +36 -0
- package/cjs/type/symbol/index.js +44 -0
- package/cjs/type/symbol/symbol.js +36 -0
- package/cjs/type/symbols/index.js +44 -0
- package/cjs/type/symbols/symbols.js +40 -0
- package/cjs/type/template-literal/finite.js +71 -0
- package/cjs/type/template-literal/generate.js +74 -0
- package/cjs/type/template-literal/index.js +50 -0
- package/cjs/type/template-literal/parser.js +175 -0
- package/cjs/type/template-literal/pattern.js +61 -0
- package/cjs/type/template-literal/syntax.js +87 -0
- package/cjs/type/template-literal/template-literal.js +43 -0
- package/cjs/type/template-literal/union.js +48 -0
- package/cjs/type/transform/index.js +44 -0
- package/cjs/type/transform/transform.js +72 -0
- package/cjs/type/tuple/index.js +44 -0
- package/cjs/type/tuple/tuple.js +42 -0
- package/cjs/type/type/index.js +44 -0
- package/cjs/type/type/javascript.js +120 -0
- package/cjs/type/type/json.js +255 -0
- package/cjs/type/type/type.js +153 -0
- package/cjs/type/uint8array/index.js +44 -0
- package/cjs/type/uint8array/uint8array.js +36 -0
- package/cjs/type/undefined/index.js +44 -0
- package/cjs/type/undefined/undefined.js +36 -0
- package/cjs/type/union/index.js +44 -0
- package/cjs/type/union/union.js +50 -0
- package/cjs/type/unknown/index.js +44 -0
- package/cjs/type/unknown/unknown.js +39 -0
- package/cjs/type/unsafe/index.js +44 -0
- package/cjs/type/unsafe/unsafe.js +39 -0
- package/cjs/type/void/index.js +44 -0
- package/cjs/type/void/void.js +40 -0
- package/{value → cjs/value/cast}/cast.js +62 -83
- package/cjs/value/cast/index.js +44 -0
- package/cjs/value/check/check.js +468 -0
- package/cjs/value/check/index.js +44 -0
- package/cjs/value/clean/clean.js +167 -0
- package/cjs/value/clean/index.js +44 -0
- package/{value → cjs/value/clone}/clone.js +6 -6
- package/cjs/value/clone/index.js +44 -0
- package/{value → cjs/value/convert}/convert.js +93 -116
- package/cjs/value/convert/index.js +44 -0
- package/{value → cjs/value/create}/create.js +69 -62
- package/cjs/value/create/index.js +44 -0
- package/cjs/value/default/default.js +175 -0
- package/cjs/value/default/index.js +44 -0
- package/{value → cjs/value/delta}/delta.js +57 -53
- package/cjs/value/delta/index.js +44 -0
- package/{value → cjs/value/deref}/deref.js +1 -2
- package/cjs/value/deref/index.js +44 -0
- package/{value → cjs/value/equal}/equal.js +14 -14
- package/cjs/value/equal/index.js +44 -0
- package/cjs/value/guard/index.js +44 -0
- package/{value → cjs/value/hash}/hash.js +26 -26
- package/cjs/value/hash/index.js +44 -0
- package/cjs/value/index.js +123 -0
- package/cjs/value/mutate/index.js +44 -0
- package/{value → cjs/value/mutate}/mutate.js +25 -25
- package/cjs/value/pointer/index.js +31 -0
- package/cjs/value/pointer/pointer.js +151 -0
- package/cjs/value/transform/decode.js +211 -0
- package/cjs/value/transform/encode.js +219 -0
- package/cjs/value/transform/has.js +146 -0
- package/cjs/value/transform/index.js +46 -0
- package/cjs/value/value/index.js +31 -0
- package/cjs/value/value/value.js +125 -0
- package/{compiler/compiler.d.ts → esm/compiler/compiler.d.mts} +25 -18
- package/esm/compiler/compiler.mjs +658 -0
- package/{compiler/index.d.ts → esm/compiler/index.d.mts} +2 -2
- package/esm/compiler/index.mjs +29 -0
- package/{errors/errors.d.ts → esm/errors/errors.d.mts} +7 -7
- package/esm/errors/errors.mjs +583 -0
- package/esm/errors/index.d.mts +1 -0
- package/esm/errors/index.mjs +28 -0
- package/esm/index.d.mts +71 -0
- package/esm/index.mjs +105 -0
- package/esm/system/errors.d.mts +14 -0
- package/esm/system/errors.mjs +188 -0
- package/esm/system/index.d.mts +4 -0
- package/esm/system/index.mjs +31 -0
- package/esm/system/policy.d.mts +21 -0
- package/esm/system/policy.mjs +71 -0
- package/esm/system/system.d.mts +13 -0
- package/esm/system/system.mjs +66 -0
- package/esm/type/any/any.d.mts +8 -0
- package/esm/type/any/any.mjs +32 -0
- package/esm/type/any/index.d.mts +1 -0
- package/esm/type/any/index.mjs +28 -0
- package/esm/type/array/array.d.mts +25 -0
- package/esm/type/array/array.mjs +38 -0
- package/esm/type/array/index.d.mts +1 -0
- package/esm/type/array/index.mjs +28 -0
- package/esm/type/async-iterator/async-iterator.d.mts +11 -0
- package/esm/type/async-iterator/async-iterator.mjs +38 -0
- package/esm/type/async-iterator/index.d.mts +1 -0
- package/esm/type/async-iterator/index.mjs +28 -0
- package/esm/type/awaited/awaited.d.mts +12 -0
- package/esm/type/awaited/awaited.mjs +61 -0
- package/esm/type/awaited/index.d.mts +1 -0
- package/esm/type/awaited/index.mjs +28 -0
- package/esm/type/bigint/bigint.d.mts +16 -0
- package/esm/type/bigint/bigint.mjs +36 -0
- package/esm/type/bigint/index.d.mts +1 -0
- package/esm/type/bigint/index.mjs +28 -0
- package/esm/type/boolean/boolean.d.mts +9 -0
- package/esm/type/boolean/boolean.mjs +36 -0
- package/esm/type/boolean/index.d.mts +1 -0
- package/esm/type/boolean/index.mjs +28 -0
- package/esm/type/clone/index.d.mts +2 -0
- package/esm/type/clone/index.mjs +29 -0
- package/esm/type/clone/type.d.mts +5 -0
- package/esm/type/clone/type.mjs +36 -0
- package/esm/type/clone/value.d.mts +2 -0
- package/esm/type/clone/value.mjs +54 -0
- package/esm/type/composite/composite.d.mts +15 -0
- package/esm/type/composite/composite.mjs +42 -0
- package/esm/type/composite/index.d.mts +1 -0
- package/esm/type/composite/index.mjs +28 -0
- package/esm/type/const/const.d.mts +30 -0
- package/esm/type/const/const.mjs +80 -0
- package/esm/type/const/index.d.mts +1 -0
- package/esm/type/const/index.mjs +28 -0
- package/esm/type/constructor/constructor.d.mts +17 -0
- package/esm/type/constructor/constructor.mjs +39 -0
- package/esm/type/constructor/index.d.mts +1 -0
- package/esm/type/constructor/index.mjs +28 -0
- package/esm/type/constructor-parameters/constructor-parameters.d.mts +7 -0
- package/esm/type/constructor-parameters/constructor-parameters.mjs +33 -0
- package/esm/type/constructor-parameters/index.d.mts +1 -0
- package/esm/type/constructor-parameters/index.mjs +28 -0
- package/esm/type/date/date.d.mts +21 -0
- package/esm/type/date/date.mjs +36 -0
- package/esm/type/date/index.d.mts +1 -0
- package/esm/type/date/index.mjs +28 -0
- package/esm/type/deref/deref.d.mts +24 -0
- package/esm/type/deref/deref.mjs +131 -0
- package/esm/type/deref/index.d.mts +1 -0
- package/esm/type/deref/index.mjs +28 -0
- package/esm/type/discard/discard.d.mts +1 -0
- package/esm/type/discard/discard.mjs +34 -0
- package/esm/type/discard/index.d.mts +1 -0
- package/esm/type/discard/index.mjs +28 -0
- package/esm/type/enum/enum.d.mts +14 -0
- package/esm/type/enum/enum.mjs +42 -0
- package/esm/type/enum/index.d.mts +1 -0
- package/esm/type/enum/index.mjs +28 -0
- package/esm/type/exclude/exclude.d.mts +21 -0
- package/esm/type/exclude/exclude.mjs +49 -0
- package/esm/type/exclude/index.d.mts +1 -0
- package/esm/type/exclude/index.mjs +28 -0
- package/esm/type/extends/extends-check.d.mts +9 -0
- package/esm/type/extends/extends-check.mjs +649 -0
- package/esm/type/extends/extends-undefined.d.mts +3 -0
- package/esm/type/extends/extends-undefined.mjs +47 -0
- package/esm/type/extends/extends.d.mts +9 -0
- package/esm/type/extends/extends.mjs +42 -0
- package/esm/type/extends/index.d.mts +3 -0
- package/esm/type/extends/index.mjs +30 -0
- package/esm/type/extract/extract.d.mts +20 -0
- package/esm/type/extract/extract.mjs +49 -0
- package/esm/type/extract/index.d.mts +1 -0
- package/esm/type/extract/index.mjs +28 -0
- package/esm/type/function/function.d.mts +17 -0
- package/esm/type/function/function.mjs +39 -0
- package/esm/type/function/index.d.mts +1 -0
- package/esm/type/function/index.mjs +28 -0
- package/esm/type/guard/index.d.mts +2 -0
- package/esm/type/guard/index.mjs +29 -0
- package/esm/type/guard/type.d.mts +130 -0
- package/esm/type/guard/type.mjs +469 -0
- package/esm/type/guard/value.d.mts +28 -0
- package/esm/type/guard/value.mjs +83 -0
- package/esm/type/helpers/helpers.d.mts +42 -0
- package/esm/type/helpers/helpers.mjs +31 -0
- package/esm/type/helpers/index.d.mts +1 -0
- package/esm/type/helpers/index.mjs +28 -0
- package/esm/type/index.d.mts +70 -0
- package/esm/type/index.mjs +97 -0
- package/esm/type/indexed/index.d.mts +3 -0
- package/esm/type/indexed/index.mjs +30 -0
- package/esm/type/indexed/indexed-key.d.mts +17 -0
- package/esm/type/indexed/indexed-key.mjs +61 -0
- package/esm/type/indexed/indexed-type.d.mts +33 -0
- package/esm/type/indexed/indexed-type.mjs +102 -0
- package/esm/type/indexed/indexed.d.mts +8 -0
- package/esm/type/indexed/indexed.mjs +37 -0
- package/esm/type/instance-type/index.d.mts +1 -0
- package/esm/type/instance-type/index.mjs +28 -0
- package/esm/type/instance-type/instance-type.d.mts +5 -0
- package/esm/type/instance-type/instance-type.mjs +32 -0
- package/esm/type/integer/index.d.mts +1 -0
- package/esm/type/integer/index.mjs +28 -0
- package/esm/type/integer/integer.d.mts +16 -0
- package/esm/type/integer/integer.mjs +36 -0
- package/esm/type/intersect/index.d.mts +1 -0
- package/esm/type/intersect/index.mjs +28 -0
- package/esm/type/intersect/intersect.d.mts +22 -0
- package/esm/type/intersect/intersect.mjs +54 -0
- package/esm/type/intrinsic/index.d.mts +1 -0
- package/esm/type/intrinsic/index.mjs +28 -0
- package/esm/type/intrinsic/intrinsic.d.mts +27 -0
- package/esm/type/intrinsic/intrinsic.mjs +98 -0
- package/esm/type/iterator/index.d.mts +1 -0
- package/esm/type/iterator/index.mjs +28 -0
- package/esm/type/iterator/iterator.d.mts +11 -0
- package/esm/type/iterator/iterator.mjs +38 -0
- package/esm/type/keyof/index.d.mts +3 -0
- package/esm/type/keyof/index.mjs +30 -0
- package/esm/type/keyof/keyof-string.d.mts +30 -0
- package/esm/type/keyof/keyof-string.mjs +98 -0
- package/esm/type/keyof/keyof-type.d.mts +11 -0
- package/esm/type/keyof/keyof-type.mjs +44 -0
- package/esm/type/keyof/keyof.d.mts +5 -0
- package/esm/type/keyof/keyof.mjs +34 -0
- package/esm/type/literal/index.d.mts +1 -0
- package/esm/type/literal/index.mjs +28 -0
- package/esm/type/literal/literal.d.mts +10 -0
- package/esm/type/literal/literal.mjs +37 -0
- package/esm/type/mapped/index.d.mts +1 -0
- package/esm/type/mapped/index.mjs +28 -0
- package/esm/type/mapped/mapped.d.mts +26 -0
- package/esm/type/mapped/mapped.mjs +43 -0
- package/esm/type/modifiers/index.d.mts +1 -0
- package/esm/type/modifiers/index.mjs +28 -0
- package/esm/type/modifiers/modifiers.d.mts +18 -0
- package/esm/type/modifiers/modifiers.mjs +73 -0
- package/esm/type/never/index.d.mts +1 -0
- package/esm/type/never/index.mjs +28 -0
- package/esm/type/never/never.d.mts +9 -0
- package/esm/type/never/never.mjs +36 -0
- package/esm/type/not/index.d.mts +1 -0
- package/esm/type/not/index.mjs +28 -0
- package/esm/type/not/not.d.mts +10 -0
- package/esm/type/not/not.mjs +37 -0
- package/esm/type/null/index.d.mts +1 -0
- package/esm/type/null/index.mjs +28 -0
- package/esm/type/null/null.d.mts +9 -0
- package/esm/type/null/null.mjs +36 -0
- package/esm/type/number/index.d.mts +1 -0
- package/esm/type/number/index.mjs +28 -0
- package/esm/type/number/number.d.mts +16 -0
- package/esm/type/number/number.mjs +36 -0
- package/esm/type/object/index.d.mts +1 -0
- package/esm/type/object/index.mjs +28 -0
- package/esm/type/object/object.d.mts +44 -0
- package/esm/type/object/object.mjs +43 -0
- package/esm/type/omit/index.d.mts +1 -0
- package/esm/type/omit/index.mjs +28 -0
- package/esm/type/omit/omit.d.mts +21 -0
- package/esm/type/omit/omit.mjs +70 -0
- package/esm/type/operators/index.d.mts +1 -0
- package/esm/type/operators/index.mjs +28 -0
- package/esm/type/operators/operators.d.mts +24 -0
- package/esm/type/operators/operators.mjs +108 -0
- package/esm/type/optional/index.d.mts +1 -0
- package/esm/type/optional/index.mjs +28 -0
- package/esm/type/optional/optional.d.mts +7 -0
- package/esm/type/optional/optional.mjs +33 -0
- package/esm/type/parameters/index.d.mts +1 -0
- package/esm/type/parameters/index.mjs +28 -0
- package/esm/type/parameters/parameters.d.mts +7 -0
- package/esm/type/parameters/parameters.mjs +33 -0
- package/esm/type/partial/index.d.mts +1 -0
- package/esm/type/partial/index.mjs +28 -0
- package/esm/type/partial/partial.d.mts +23 -0
- package/esm/type/partial/partial.mjs +68 -0
- package/esm/type/patterns/index.d.mts +1 -0
- package/esm/type/patterns/index.mjs +28 -0
- package/esm/type/patterns/patterns.d.mts +6 -0
- package/esm/type/patterns/patterns.mjs +33 -0
- package/esm/type/pick/index.d.mts +1 -0
- package/esm/type/pick/index.mjs +28 -0
- package/esm/type/pick/pick.d.mts +21 -0
- package/esm/type/pick/pick.mjs +61 -0
- package/esm/type/promise/index.d.mts +1 -0
- package/esm/type/promise/index.mjs +28 -0
- package/esm/type/promise/promise.d.mts +11 -0
- package/esm/type/promise/promise.mjs +38 -0
- package/esm/type/readonly/index.d.mts +1 -0
- package/esm/type/readonly/index.mjs +28 -0
- package/esm/type/readonly/readonly.d.mts +7 -0
- package/esm/type/readonly/readonly.mjs +33 -0
- package/esm/type/readonly-optional/index.d.mts +1 -0
- package/esm/type/readonly-optional/index.mjs +28 -0
- package/esm/type/readonly-optional/readonly-optional.d.mts +6 -0
- package/esm/type/readonly-optional/readonly-optional.mjs +33 -0
- package/esm/type/record/index.d.mts +1 -0
- package/esm/type/record/index.mjs +28 -0
- package/esm/type/record/record.d.mts +55 -0
- package/esm/type/record/record.mjs +92 -0
- package/esm/type/recursive/index.d.mts +1 -0
- package/esm/type/recursive/index.mjs +28 -0
- package/esm/type/recursive/recursive.d.mts +15 -0
- package/esm/type/recursive/recursive.mjs +44 -0
- package/esm/type/ref/index.d.mts +1 -0
- package/esm/type/ref/index.mjs +28 -0
- package/esm/type/ref/ref.d.mts +12 -0
- package/esm/type/ref/ref.mjs +41 -0
- package/esm/type/regexp/index.d.mts +1 -0
- package/esm/type/regexp/index.mjs +28 -0
- package/esm/type/regexp/regexp.d.mts +7 -0
- package/esm/type/regexp/regexp.mjs +34 -0
- package/esm/type/registry/format.d.mts +13 -0
- package/esm/type/registry/format.mjs +53 -0
- package/esm/type/registry/index.d.mts +2 -0
- package/esm/type/registry/index.mjs +29 -0
- package/esm/type/registry/type.d.mts +13 -0
- package/esm/type/registry/type.mjs +53 -0
- package/esm/type/required/index.d.mts +1 -0
- package/esm/type/required/index.mjs +28 -0
- package/esm/type/required/required.d.mts +23 -0
- package/esm/type/required/required.mjs +67 -0
- package/esm/type/rest/index.d.mts +1 -0
- package/esm/type/rest/index.mjs +28 -0
- package/esm/type/rest/rest.d.mts +10 -0
- package/esm/type/rest/rest.mjs +36 -0
- package/esm/type/return-type/index.d.mts +1 -0
- package/esm/type/return-type/index.mjs +28 -0
- package/esm/type/return-type/return-type.d.mts +5 -0
- package/esm/type/return-type/return-type.mjs +32 -0
- package/esm/type/schema/anyschema.d.mts +32 -0
- package/esm/type/schema/anyschema.mjs +28 -0
- package/esm/type/schema/index.d.mts +2 -0
- package/esm/type/schema/index.mjs +29 -0
- package/esm/type/schema/schema.d.mts +29 -0
- package/esm/type/schema/schema.mjs +28 -0
- package/esm/type/static/index.d.mts +1 -0
- package/esm/type/static/index.mjs +28 -0
- package/esm/type/static/static.d.mts +34 -0
- package/esm/type/static/static.mjs +28 -0
- package/esm/type/strict/index.d.mts +1 -0
- package/esm/type/strict/index.mjs +28 -0
- package/esm/type/strict/strict.d.mts +3 -0
- package/esm/type/strict/strict.mjs +31 -0
- package/esm/type/string/index.d.mts +1 -0
- package/esm/type/string/index.mjs +28 -0
- package/esm/type/string/string.d.mts +25 -0
- package/esm/type/string/string.mjs +32 -0
- package/esm/type/symbol/index.d.mts +1 -0
- package/esm/type/symbol/index.mjs +28 -0
- package/esm/type/symbol/symbol.d.mts +10 -0
- package/esm/type/symbol/symbol.mjs +32 -0
- package/esm/type/symbols/index.d.mts +1 -0
- package/esm/type/symbols/index.mjs +28 -0
- package/esm/type/symbols/symbols.d.mts +10 -0
- package/esm/type/symbols/symbols.mjs +37 -0
- package/esm/type/template-literal/finite.d.mts +16 -0
- package/esm/type/template-literal/finite.mjs +66 -0
- package/esm/type/template-literal/generate.d.mts +15 -0
- package/esm/type/template-literal/generate.mjs +69 -0
- package/esm/type/template-literal/index.d.mts +7 -0
- package/esm/type/template-literal/index.mjs +34 -0
- package/esm/type/template-literal/parser.d.mts +19 -0
- package/esm/type/template-literal/parser.mjs +169 -0
- package/esm/type/template-literal/pattern.d.mts +4 -0
- package/esm/type/template-literal/pattern.mjs +56 -0
- package/esm/type/template-literal/syntax.d.mts +20 -0
- package/esm/type/template-literal/syntax.mjs +83 -0
- package/esm/type/template-literal/template-literal.d.mts +30 -0
- package/esm/type/template-literal/template-literal.mjs +39 -0
- package/esm/type/template-literal/union.d.mts +7 -0
- package/esm/type/template-literal/union.mjs +44 -0
- package/esm/type/transform/index.d.mts +1 -0
- package/esm/type/transform/index.mjs +28 -0
- package/esm/type/transform/transform.d.mts +29 -0
- package/esm/type/transform/transform.mjs +69 -0
- package/esm/type/tuple/index.d.mts +1 -0
- package/esm/type/tuple/index.mjs +28 -0
- package/esm/type/tuple/tuple.d.mts +15 -0
- package/esm/type/tuple/tuple.mjs +38 -0
- package/esm/type/type/index.d.mts +6 -0
- package/esm/type/type/index.mjs +40 -0
- package/esm/type/type/javascript.d.mts +58 -0
- package/esm/type/type/javascript.mjs +116 -0
- package/esm/type/type/json.d.mts +139 -0
- package/esm/type/type/json.mjs +251 -0
- package/esm/type/type/type.d.mts +58 -0
- package/esm/type/type/type.mjs +88 -0
- package/esm/type/uint8array/index.d.mts +1 -0
- package/esm/type/uint8array/index.mjs +28 -0
- package/esm/type/uint8array/uint8array.d.mts +13 -0
- package/esm/type/uint8array/uint8array.mjs +32 -0
- package/esm/type/undefined/index.d.mts +1 -0
- package/esm/type/undefined/index.mjs +28 -0
- package/esm/type/undefined/undefined.d.mts +9 -0
- package/esm/type/undefined/undefined.mjs +32 -0
- package/esm/type/union/index.d.mts +1 -0
- package/esm/type/union/index.mjs +28 -0
- package/esm/type/union/union.d.mts +16 -0
- package/esm/type/union/union.mjs +45 -0
- package/esm/type/unknown/index.d.mts +1 -0
- package/esm/type/unknown/index.mjs +28 -0
- package/esm/type/unknown/unknown.d.mts +8 -0
- package/esm/type/unknown/unknown.mjs +35 -0
- package/esm/type/unsafe/index.d.mts +1 -0
- package/esm/type/unsafe/index.mjs +28 -0
- package/esm/type/unsafe/unsafe.d.mts +11 -0
- package/esm/type/unsafe/unsafe.mjs +35 -0
- package/esm/type/void/index.d.mts +1 -0
- package/esm/type/void/index.mjs +28 -0
- package/esm/type/void/void.d.mts +9 -0
- package/esm/type/void/void.mjs +36 -0
- package/esm/value/cast/cast.d.mts +23 -0
- package/esm/value/cast/cast.mjs +260 -0
- package/esm/value/cast/index.d.mts +1 -0
- package/esm/value/cast/index.mjs +28 -0
- package/esm/value/check/check.d.mts +10 -0
- package/{value/check.js → esm/value/check/check.mjs} +52 -51
- package/esm/value/check/index.d.mts +1 -0
- package/esm/value/check/index.mjs +28 -0
- package/esm/value/clean/clean.d.mts +5 -0
- package/esm/value/clean/clean.mjs +163 -0
- package/esm/value/clean/index.d.mts +1 -0
- package/esm/value/clean/index.mjs +28 -0
- package/esm/value/clone/clone.mjs +64 -0
- package/esm/value/clone/index.d.mts +1 -0
- package/esm/value/clone/index.mjs +28 -0
- package/esm/value/convert/convert.d.mts +9 -0
- package/esm/value/convert/convert.mjs +287 -0
- package/esm/value/convert/index.d.mts +1 -0
- package/esm/value/convert/index.mjs +28 -0
- package/esm/value/create/create.d.mts +31 -0
- package/esm/value/create/create.mjs +504 -0
- package/esm/value/create/index.d.mts +1 -0
- package/esm/value/create/index.mjs +28 -0
- package/esm/value/default/default.d.mts +5 -0
- package/esm/value/default/default.mjs +171 -0
- package/esm/value/default/index.d.mts +1 -0
- package/esm/value/default/index.mjs +28 -0
- package/esm/value/delta/delta.d.mts +41 -0
- package/esm/value/delta/delta.mjs +194 -0
- package/esm/value/delta/index.d.mts +1 -0
- package/esm/value/delta/index.mjs +28 -0
- package/{value/deref.d.ts → esm/value/deref/deref.d.mts} +4 -2
- package/esm/value/deref/deref.mjs +41 -0
- package/esm/value/deref/index.d.mts +1 -0
- package/esm/value/deref/index.mjs +28 -0
- package/esm/value/equal/equal.mjs +73 -0
- package/esm/value/equal/index.d.mts +1 -0
- package/esm/value/equal/index.mjs +28 -0
- package/esm/value/guard/guard.mjs +123 -0
- package/esm/value/guard/index.d.mts +1 -0
- package/esm/value/guard/index.mjs +28 -0
- package/{value/hash.d.ts → esm/value/hash/hash.d.mts} +0 -13
- package/esm/value/hash/hash.mjs +173 -0
- package/esm/value/hash/index.d.mts +1 -0
- package/esm/value/hash/index.mjs +28 -0
- package/esm/value/index.d.mts +18 -0
- package/esm/value/index.mjs +57 -0
- package/esm/value/mutate/index.d.mts +1 -0
- package/esm/value/mutate/index.mjs +28 -0
- package/{value/mutate.d.ts → esm/value/mutate/mutate.d.mts} +1 -1
- package/esm/value/mutate/mutate.mjs +123 -0
- package/esm/value/pointer/index.d.mts +1 -0
- package/esm/value/pointer/index.mjs +28 -0
- package/esm/value/pointer/pointer.d.mts +21 -0
- package/esm/value/pointer/pointer.mjs +146 -0
- package/esm/value/transform/decode.d.mts +19 -0
- package/esm/value/transform/decode.mjs +210 -0
- package/esm/value/transform/encode.d.mts +20 -0
- package/esm/value/transform/encode.mjs +218 -0
- package/esm/value/transform/has.d.mts +3 -0
- package/esm/value/transform/has.mjs +142 -0
- package/esm/value/transform/index.d.mts +3 -0
- package/esm/value/transform/index.mjs +30 -0
- package/esm/value/value/index.d.mts +1 -0
- package/esm/value/value/index.mjs +28 -0
- package/esm/value/value/value.d.mts +53 -0
- package/esm/value/value/value.mjs +107 -0
- package/package.json +37 -27
- package/readme.md +183 -155
- package/errors/index.d.ts +0 -1
- package/system/index.d.ts +0 -2
- package/system/system.d.ts +0 -48
- package/system/system.js +0 -274
- package/typebox.d.ts +0 -962
- package/typebox.js +0 -2364
- package/value/cast.d.ts +0 -24
- package/value/check.d.ts +0 -9
- package/value/convert.d.ts +0 -10
- package/value/create.d.ts +0 -30
- package/value/delta.d.ts +0 -41
- package/value/index.d.ts +0 -5
- package/value/pointer.d.ts +0 -24
- package/value/pointer.js +0 -148
- package/value/transform.d.ts +0 -37
- package/value/transform.js +0 -473
- package/value/value.d.ts +0 -47
- package/value/value.js +0 -117
- /package/{errors → cjs/errors}/index.js +0 -0
- /package/{value → cjs/value/guard}/guard.js +0 -0
- /package/{value/clone.d.ts → esm/value/clone/clone.d.mts} +0 -0
- /package/{value/equal.d.ts → esm/value/equal/equal.d.mts} +0 -0
- /package/{value/guard.d.ts → esm/value/guard/guard.d.mts} +0 -0
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
|
|
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
|
|
744
|
-
|
|
745
|
-
|
|
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
|
|
749
|
-
// $ref: '
|
|
763
|
+
const VectorRef = Type.Ref(Vector) // const VectorRef = {
|
|
764
|
+
// $ref: 'Vector'
|
|
750
765
|
// }
|
|
751
766
|
|
|
752
|
-
type
|
|
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
|
|
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
|
-
//
|
|
800
|
-
|
|
801
|
-
type T0 = string extends number ? true : false // type T0 = false
|
|
854
|
+
// Extends
|
|
802
855
|
|
|
803
|
-
type
|
|
856
|
+
type T = string extends number ? true : false // type T = false
|
|
804
857
|
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
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
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
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
|
-
|
|
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)
|
|
830
|
-
]),
|
|
831
|
-
Type.Literal(1)
|
|
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
|
|
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
|
|
901
|
+
type K = `prop${'A'|'B'|'C'}` // type T = 'propA' | 'propB' | 'propC'
|
|
849
902
|
|
|
850
|
-
type R = Record<
|
|
851
|
-
//
|
|
852
|
-
//
|
|
853
|
-
//
|
|
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
|
|
859
|
-
//
|
|
860
|
-
//
|
|
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(
|
|
864
|
-
//
|
|
865
|
-
//
|
|
866
|
-
//
|
|
867
|
-
//
|
|
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(), //
|
|
889
|
-
y: Type.String(), //
|
|
890
|
-
z: Type.Boolean() //
|
|
891
|
-
}) //
|
|
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
|
|
940
|
+
const A = Type.Index(T, ['x']) // const A: TNumber
|
|
898
941
|
|
|
899
|
-
const B = Type.Index(T, ['x', 'y']) // const B
|
|
900
|
-
//
|
|
901
|
-
//
|
|
902
|
-
//
|
|
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
|
-
//
|
|
908
|
-
//
|
|
909
|
-
//
|
|
910
|
-
//
|
|
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(), //
|
|
924
|
-
Type.Number() //
|
|
925
|
-
]) //
|
|
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
|
|
939
|
-
//
|
|
940
|
-
//
|
|
941
|
-
//
|
|
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
|
-
###
|
|
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,
|
|
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,
|
|
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
|
package/errors/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './errors';
|
package/system/index.d.ts
DELETED
package/system/system.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ValueErrorType } from '../errors/errors';
|
|
2
|
-
import * as Types from '../typebox';
|
|
3
|
-
export declare class TypeSystemDuplicateTypeKind extends Types.TypeBoxError {
|
|
4
|
-
constructor(kind: string);
|
|
5
|
-
}
|
|
6
|
-
export declare class TypeSystemDuplicateFormat extends Types.TypeBoxError {
|
|
7
|
-
constructor(kind: string);
|
|
8
|
-
}
|
|
9
|
-
/** Creates user defined types and formats and provides overrides for value checking behaviours */
|
|
10
|
-
export declare namespace TypeSystem {
|
|
11
|
-
/** Creates a new type */
|
|
12
|
-
function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => Types.TUnsafe<Type>;
|
|
13
|
-
/** Creates a new string format */
|
|
14
|
-
function Format<F extends string>(format: F, check: (value: string) => boolean): F;
|
|
15
|
-
}
|
|
16
|
-
/** Manages error message providers */
|
|
17
|
-
export declare namespace TypeSystemErrorFunction {
|
|
18
|
-
/** Resets the error message function to en-us */
|
|
19
|
-
function Reset(): void;
|
|
20
|
-
/** Sets the error message function used to generate error messages */
|
|
21
|
-
function Set(callback: ErrorFunction): void;
|
|
22
|
-
/** Gets the error message function */
|
|
23
|
-
function Get(): ErrorFunction;
|
|
24
|
-
}
|
|
25
|
-
/** Shared assertion routines used by the value and errors modules */
|
|
26
|
-
export declare namespace TypeSystemPolicy {
|
|
27
|
-
/** Sets whether TypeBox should assert optional properties using the TypeScript `exactOptionalPropertyTypes` assertion policy. The default is `false` */
|
|
28
|
-
let ExactOptionalPropertyTypes: boolean;
|
|
29
|
-
/** Sets whether arrays should be treated as a kind of objects. The default is `false` */
|
|
30
|
-
let AllowArrayObject: boolean;
|
|
31
|
-
/** Sets whether `NaN` or `Infinity` should be treated as valid numeric values. The default is `false` */
|
|
32
|
-
let AllowNaN: boolean;
|
|
33
|
-
/** Sets whether `null` should validate for void types. The default is `false` */
|
|
34
|
-
let AllowNullVoid: boolean;
|
|
35
|
-
/** Asserts this value using the ExactOptionalPropertyTypes policy */
|
|
36
|
-
function IsExactOptionalProperty(value: Record<keyof any, unknown>, key: string): boolean;
|
|
37
|
-
/** Asserts this value using the AllowArrayObjects policy */
|
|
38
|
-
function IsObjectLike(value: unknown): value is Record<keyof any, unknown>;
|
|
39
|
-
/** Asserts this value as a record using the AllowArrayObjects policy */
|
|
40
|
-
function IsRecordLike(value: unknown): value is Record<keyof any, unknown>;
|
|
41
|
-
/** Asserts this value using the AllowNaN policy */
|
|
42
|
-
function IsNumberLike(value: unknown): value is number;
|
|
43
|
-
/** Asserts this value using the AllowVoidNull policy */
|
|
44
|
-
function IsVoidLike(value: unknown): value is void;
|
|
45
|
-
}
|
|
46
|
-
export type ErrorFunction = (schema: Types.TSchema, type: ValueErrorType) => string;
|
|
47
|
-
/** Creates an error message using en-US as the default locale */
|
|
48
|
-
export declare function DefaultErrorFunction(schema: Types.TSchema, errorType: ValueErrorType): string;
|