@sinclair/typebox 0.32.0-dev-16 → 0.32.0-dev-17
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/build/import/compiler/compiler.d.mts +9 -0
- package/build/import/compiler/compiler.mjs +87 -6
- package/build/import/compiler/index.mjs +27 -0
- package/build/import/errors/errors.d.mts +3 -0
- package/build/import/errors/errors.mjs +55 -3
- package/build/import/errors/function.d.mts +3 -0
- package/build/import/errors/function.mjs +31 -0
- package/build/import/errors/index.mjs +27 -0
- package/build/import/index.mjs +36 -0
- package/build/import/system/index.mjs +27 -0
- package/build/import/system/policy.d.mts +10 -0
- package/build/import/system/policy.mjs +40 -0
- package/build/import/system/system.d.mts +3 -0
- package/build/import/system/system.mjs +36 -0
- package/build/import/type/any/any.d.mts +1 -0
- package/build/import/type/any/any.mjs +28 -0
- package/build/import/type/any/index.mjs +27 -0
- package/build/import/type/array/array.d.mts +7 -0
- package/build/import/type/array/array.mjs +28 -0
- package/build/import/type/array/index.mjs +27 -0
- package/build/import/type/async-iterator/async-iterator.d.mts +1 -0
- package/build/import/type/async-iterator/async-iterator.mjs +28 -0
- package/build/import/type/async-iterator/index.mjs +27 -0
- package/build/import/type/awaited/awaited.d.mts +1 -0
- package/build/import/type/awaited/awaited.mjs +37 -0
- package/build/import/type/awaited/index.mjs +27 -0
- package/build/import/type/bigint/bigint.d.mts +1 -0
- package/build/import/type/bigint/bigint.mjs +28 -0
- package/build/import/type/bigint/index.mjs +27 -0
- package/build/import/type/boolean/boolean.d.mts +1 -0
- package/build/import/type/boolean/boolean.mjs +28 -0
- package/build/import/type/boolean/index.mjs +27 -0
- package/build/import/type/clone/index.mjs +27 -0
- package/build/import/type/clone/type.d.mts +2 -0
- package/build/import/type/clone/type.mjs +29 -0
- package/build/import/type/clone/value.d.mts +1 -0
- package/build/import/type/clone/value.mjs +29 -0
- package/build/import/type/composite/composite.d.mts +1 -0
- package/build/import/type/composite/composite.mjs +28 -0
- package/build/import/type/composite/index.mjs +27 -0
- package/build/import/type/const/const.d.mts +2 -1
- package/build/import/type/const/const.mjs +32 -1
- package/build/import/type/const/index.mjs +27 -0
- package/build/import/type/constructor/constructor.d.mts +1 -0
- package/build/import/type/constructor/constructor.mjs +28 -0
- package/build/import/type/constructor/index.mjs +27 -0
- package/build/import/type/constructor-parameters/constructor-parameters.d.mts +1 -0
- package/build/import/type/constructor-parameters/constructor-parameters.mjs +28 -0
- package/build/import/type/constructor-parameters/index.mjs +27 -0
- package/build/import/type/date/date.d.mts +6 -0
- package/build/import/type/date/date.mjs +28 -0
- package/build/import/type/date/index.mjs +27 -0
- package/build/import/type/deref/deref.d.mts +1 -0
- package/build/import/type/deref/deref.mjs +45 -0
- package/build/import/type/deref/index.mjs +27 -0
- package/build/import/type/discard/discard.mjs +27 -0
- package/build/import/type/discard/index.mjs +27 -0
- package/build/import/type/enum/enum.d.mts +1 -0
- package/build/import/type/enum/enum.mjs +28 -0
- package/build/import/type/enum/index.mjs +27 -0
- package/build/import/type/exclude/exclude-from-mapped-result.mjs +30 -0
- package/build/import/type/exclude/exclude.d.mts +2 -0
- package/build/import/type/exclude/exclude.mjs +30 -0
- package/build/import/type/exclude/index.mjs +27 -0
- package/build/import/type/extends/extends-check.mjs +200 -1
- package/build/import/type/extends/extends-from-mapped-key.mjs +31 -0
- package/build/import/type/extends/extends-from-mapped-result.mjs +30 -0
- package/build/import/type/extends/extends-undefined.d.mts +1 -0
- package/build/import/type/extends/extends-undefined.mjs +30 -0
- package/build/import/type/extends/extends.d.mts +3 -0
- package/build/import/type/extends/extends.mjs +34 -0
- package/build/import/type/extends/index.mjs +27 -0
- package/build/import/type/extract/extract-from-mapped-result.mjs +30 -0
- package/build/import/type/extract/extract.d.mts +2 -0
- package/build/import/type/extract/extract.mjs +30 -0
- package/build/import/type/extract/index.mjs +27 -0
- package/build/import/type/function/function.d.mts +1 -0
- package/build/import/type/function/function.mjs +28 -0
- package/build/import/type/function/index.mjs +27 -0
- package/build/import/type/guard/index.mjs +27 -0
- package/build/import/type/guard/type.d.mts +46 -0
- package/build/import/type/guard/type.mjs +111 -1
- package/build/import/type/guard/value.d.mts +14 -0
- package/build/import/type/guard/value.mjs +41 -0
- package/build/import/type/helpers/helpers.d.mts +1 -0
- package/build/import/type/helpers/helpers.mjs +28 -0
- package/build/import/type/helpers/index.mjs +27 -0
- package/build/import/type/index.mjs +27 -0
- package/build/import/type/indexed/index.mjs +27 -0
- package/build/import/type/indexed/indexed-from-mapped-key.mjs +35 -1
- package/build/import/type/indexed/indexed-property-keys.d.mts +1 -0
- package/build/import/type/indexed/indexed-property-keys.mjs +36 -0
- package/build/import/type/indexed/indexed-result.mjs +42 -0
- package/build/import/type/indexed/indexed.d.mts +3 -0
- package/build/import/type/indexed/indexed.mjs +33 -0
- package/build/import/type/instance-type/index.mjs +27 -0
- package/build/import/type/instance-type/instance-type.d.mts +1 -0
- package/build/import/type/instance-type/instance-type.mjs +28 -0
- package/build/import/type/integer/index.mjs +27 -0
- package/build/import/type/integer/integer.d.mts +1 -0
- package/build/import/type/integer/integer.mjs +28 -0
- package/build/import/type/intersect/index.mjs +27 -0
- package/build/import/type/intersect/intersect-create.mjs +35 -0
- package/build/import/type/intersect/intersect-evaluated.d.mts +1 -0
- package/build/import/type/intersect/intersect-evaluated.mjs +36 -0
- package/build/import/type/intersect/intersect-type.mjs +27 -0
- package/build/import/type/intersect/intersect.d.mts +1 -0
- package/build/import/type/intersect/intersect.mjs +32 -0
- package/build/import/type/intrinsic/capitalize.d.mts +1 -0
- package/build/import/type/intrinsic/capitalize.mjs +28 -0
- package/build/import/type/intrinsic/index.mjs +27 -0
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +31 -0
- package/build/import/type/intrinsic/intrinsic.d.mts +2 -0
- package/build/import/type/intrinsic/intrinsic.mjs +43 -1
- package/build/import/type/intrinsic/lowercase.d.mts +1 -0
- package/build/import/type/intrinsic/lowercase.mjs +28 -0
- package/build/import/type/intrinsic/uncapitalize.d.mts +1 -0
- package/build/import/type/intrinsic/uncapitalize.mjs +28 -0
- package/build/import/type/intrinsic/uppercase.d.mts +1 -0
- package/build/import/type/intrinsic/uppercase.mjs +28 -0
- package/build/import/type/iterator/index.mjs +27 -0
- package/build/import/type/iterator/iterator.d.mts +1 -0
- package/build/import/type/iterator/iterator.mjs +28 -0
- package/build/import/type/keyof/index.mjs +27 -0
- package/build/import/type/keyof/keyof-from-mapped-result.mjs +30 -0
- package/build/import/type/keyof/keyof-property-keys.d.mts +2 -0
- package/build/import/type/keyof/keyof-property-keys.mjs +47 -0
- package/build/import/type/keyof/keyof.d.mts +2 -0
- package/build/import/type/keyof/keyof.mjs +33 -0
- package/build/import/type/literal/index.mjs +27 -0
- package/build/import/type/literal/literal.d.mts +1 -0
- package/build/import/type/literal/literal.mjs +28 -0
- package/build/import/type/mapped/index.mjs +27 -0
- package/build/import/type/mapped/mapped-key.mjs +28 -0
- package/build/import/type/mapped/mapped-result.mjs +28 -0
- package/build/import/type/mapped/mapped.d.mts +2 -0
- package/build/import/type/mapped/mapped.mjs +46 -1
- package/build/import/type/modifiers/index.mjs +27 -0
- package/build/import/type/modifiers/modifiers.mjs +37 -0
- package/build/import/type/never/index.mjs +27 -0
- package/build/import/type/never/never.d.mts +1 -0
- package/build/import/type/never/never.mjs +28 -0
- package/build/import/type/not/index.mjs +27 -0
- package/build/import/type/not/not.d.mts +1 -0
- package/build/import/type/not/not.mjs +28 -0
- package/build/import/type/null/index.mjs +27 -0
- package/build/import/type/null/null.d.mts +1 -0
- package/build/import/type/null/null.mjs +28 -0
- package/build/import/type/number/index.mjs +27 -0
- package/build/import/type/number/number.d.mts +1 -0
- package/build/import/type/number/number.mjs +28 -0
- package/build/import/type/object/index.mjs +27 -0
- package/build/import/type/object/object.d.mts +5 -0
- package/build/import/type/object/object.mjs +33 -0
- package/build/import/type/omit/index.mjs +27 -0
- package/build/import/type/omit/omit-from-mapped-key.mjs +31 -0
- package/build/import/type/omit/omit.d.mts +3 -0
- package/build/import/type/omit/omit.mjs +39 -0
- package/build/import/type/operators/index.mjs +27 -0
- package/build/import/type/operators/operators.d.mts +8 -0
- package/build/import/type/operators/operators.mjs +42 -0
- package/build/import/type/optional/index.mjs +27 -0
- package/build/import/type/optional/optional.d.mts +1 -0
- package/build/import/type/optional/optional.mjs +28 -0
- package/build/import/type/parameters/index.mjs +27 -0
- package/build/import/type/parameters/parameters.d.mts +1 -0
- package/build/import/type/parameters/parameters.mjs +28 -0
- package/build/import/type/partial/index.mjs +27 -0
- package/build/import/type/partial/partial-from-mapped-result.mjs +30 -0
- package/build/import/type/partial/partial.d.mts +2 -0
- package/build/import/type/partial/partial.mjs +36 -0
- package/build/import/type/patterns/index.mjs +27 -0
- package/build/import/type/patterns/patterns.mjs +27 -0
- package/build/import/type/pick/index.mjs +27 -0
- package/build/import/type/pick/pick-from-mapped-key.mjs +31 -0
- package/build/import/type/pick/pick.d.mts +3 -0
- package/build/import/type/pick/pick.mjs +34 -0
- package/build/import/type/promise/index.mjs +27 -0
- package/build/import/type/promise/promise.d.mts +1 -0
- package/build/import/type/promise/promise.mjs +28 -0
- package/build/import/type/readonly/index.mjs +27 -0
- package/build/import/type/readonly/readonly.d.mts +1 -0
- package/build/import/type/readonly/readonly.mjs +28 -0
- package/build/import/type/readonly-optional/index.mjs +27 -0
- package/build/import/type/readonly-optional/readonly-optional.d.mts +1 -0
- package/build/import/type/readonly-optional/readonly-optional.mjs +28 -0
- package/build/import/type/record/index.mjs +27 -0
- package/build/import/type/record/record.d.mts +1 -0
- package/build/import/type/record/record.mjs +48 -0
- package/build/import/type/recursive/index.mjs +27 -0
- package/build/import/type/recursive/recursive.d.mts +1 -0
- package/build/import/type/recursive/recursive.mjs +30 -0
- package/build/import/type/ref/index.mjs +27 -0
- package/build/import/type/ref/ref.d.mts +2 -0
- package/build/import/type/ref/ref.mjs +28 -0
- package/build/import/type/regexp/index.mjs +27 -0
- package/build/import/type/regexp/regexp.d.mts +2 -0
- package/build/import/type/regexp/regexp.mjs +28 -0
- package/build/import/type/registry/format.d.mts +6 -0
- package/build/import/type/registry/format.mjs +34 -0
- package/build/import/type/registry/index.mjs +27 -0
- package/build/import/type/registry/type.d.mts +6 -0
- package/build/import/type/registry/type.mjs +34 -0
- package/build/import/type/required/index.mjs +27 -0
- package/build/import/type/required/required-from-mapped-result.mjs +30 -0
- package/build/import/type/required/required.d.mts +2 -0
- package/build/import/type/required/required.mjs +36 -0
- package/build/import/type/rest/index.mjs +27 -0
- package/build/import/type/rest/rest.d.mts +1 -0
- package/build/import/type/rest/rest.mjs +32 -0
- package/build/import/type/return-type/index.mjs +27 -0
- package/build/import/type/return-type/return-type.d.mts +1 -0
- package/build/import/type/return-type/return-type.mjs +28 -0
- package/build/import/type/schema/anyschema.mjs +27 -0
- package/build/import/type/schema/index.mjs +27 -0
- package/build/import/type/schema/schema.d.mts +7 -0
- package/build/import/type/schema/schema.mjs +27 -0
- package/build/import/type/static/index.mjs +27 -0
- package/build/import/type/static/static.d.mts +3 -0
- package/build/import/type/static/static.mjs +27 -0
- package/build/import/type/strict/index.mjs +27 -0
- package/build/import/type/strict/strict.d.mts +1 -0
- package/build/import/type/strict/strict.mjs +28 -0
- package/build/import/type/string/index.mjs +27 -0
- package/build/import/type/string/string.d.mts +7 -0
- package/build/import/type/string/string.mjs +28 -0
- package/build/import/type/symbol/index.mjs +27 -0
- package/build/import/type/symbol/symbol.d.mts +1 -0
- package/build/import/type/symbol/symbol.mjs +28 -0
- package/build/import/type/symbols/index.mjs +27 -0
- package/build/import/type/symbols/symbols.d.mts +5 -0
- package/build/import/type/symbols/symbols.mjs +32 -0
- package/build/import/type/template-literal/finite.mjs +37 -0
- package/build/import/type/template-literal/generate.mjs +37 -0
- package/build/import/type/template-literal/index.mjs +27 -0
- package/build/import/type/template-literal/parser.d.mts +2 -0
- package/build/import/type/template-literal/parser.mjs +44 -0
- package/build/import/type/template-literal/pattern.mjs +38 -0
- package/build/import/type/template-literal/syntax.d.mts +1 -0
- package/build/import/type/template-literal/syntax.mjs +35 -0
- package/build/import/type/template-literal/template-literal.d.mts +2 -0
- package/build/import/type/template-literal/template-literal.mjs +29 -0
- package/build/import/type/template-literal/union.d.mts +1 -0
- package/build/import/type/template-literal/union.mjs +31 -0
- package/build/import/type/transform/index.mjs +27 -0
- package/build/import/type/transform/transform.d.mts +1 -0
- package/build/import/type/transform/transform.mjs +36 -0
- package/build/import/type/tuple/index.mjs +27 -0
- package/build/import/type/tuple/tuple.d.mts +1 -0
- package/build/import/type/tuple/tuple.mjs +30 -0
- package/build/import/type/type/index.d.mts +1 -0
- package/build/import/type/type/index.mjs +34 -0
- package/build/import/type/type/javascript.d.mts +19 -0
- package/build/import/type/type/javascript.mjs +45 -0
- package/build/import/type/type/json.d.mts +62 -1
- package/build/import/type/type/json.mjs +82 -1
- package/build/import/type/type/type.mjs +30 -0
- package/build/import/type/uint8array/index.mjs +27 -0
- package/build/import/type/uint8array/uint8array.d.mts +1 -0
- package/build/import/type/uint8array/uint8array.mjs +28 -0
- package/build/import/type/undefined/index.mjs +27 -0
- package/build/import/type/undefined/undefined.d.mts +1 -0
- package/build/import/type/undefined/undefined.mjs +28 -0
- package/build/import/type/union/index.mjs +27 -0
- package/build/import/type/union/union-create.mjs +27 -0
- package/build/import/type/union/union-evaluated.d.mts +1 -0
- package/build/import/type/union/union-evaluated.mjs +37 -0
- package/build/import/type/union/union-type.mjs +27 -0
- package/build/import/type/union/union.d.mts +1 -0
- package/build/import/type/union/union.mjs +29 -0
- package/build/import/type/unknown/index.mjs +27 -0
- package/build/import/type/unknown/unknown.d.mts +1 -0
- package/build/import/type/unknown/unknown.mjs +28 -0
- package/build/import/type/unsafe/index.mjs +27 -0
- package/build/import/type/unsafe/unsafe.d.mts +1 -0
- package/build/import/type/unsafe/unsafe.mjs +28 -0
- package/build/import/type/void/index.mjs +27 -0
- package/build/import/type/void/void.d.mts +1 -0
- package/build/import/type/void/void.mjs +28 -0
- package/build/import/value/cast/cast.d.mts +2 -0
- package/build/import/value/cast/cast.mjs +55 -0
- package/build/import/value/cast/index.mjs +27 -0
- package/build/import/value/check/check.d.mts +2 -0
- package/build/import/value/check/check.mjs +46 -1
- package/build/import/value/check/index.mjs +27 -0
- package/build/import/value/clean/clean.d.mts +2 -0
- package/build/import/value/clean/clean.mjs +39 -1
- package/build/import/value/clean/index.mjs +27 -0
- package/build/import/value/clone/clone.d.mts +1 -0
- package/build/import/value/clone/clone.mjs +34 -0
- package/build/import/value/clone/index.mjs +27 -0
- package/build/import/value/convert/convert.d.mts +2 -0
- package/build/import/value/convert/convert.mjs +57 -1
- package/build/import/value/convert/index.mjs +27 -0
- package/build/import/value/create/create.d.mts +2 -0
- package/build/import/value/create/create.mjs +44 -0
- package/build/import/value/create/index.mjs +27 -0
- package/build/import/value/default/default.d.mts +2 -0
- package/build/import/value/default/default.mjs +46 -0
- package/build/import/value/default/index.mjs +27 -0
- package/build/import/value/delta/delta.mjs +42 -0
- package/build/import/value/delta/index.mjs +27 -0
- package/build/import/value/deref/deref.d.mts +1 -0
- package/build/import/value/deref/deref.mjs +28 -0
- package/build/import/value/deref/index.mjs +27 -0
- package/build/import/value/equal/equal.d.mts +1 -0
- package/build/import/value/equal/equal.mjs +34 -0
- package/build/import/value/equal/index.mjs +27 -0
- package/build/import/value/guard/guard.d.mts +20 -0
- package/build/import/value/guard/guard.mjs +57 -0
- package/build/import/value/guard/index.mjs +27 -0
- package/build/import/value/hash/hash.d.mts +1 -0
- package/build/import/value/hash/hash.mjs +46 -0
- package/build/import/value/hash/index.mjs +27 -0
- package/build/import/value/index.mjs +39 -0
- package/build/import/value/mutate/index.mjs +27 -0
- package/build/import/value/mutate/mutate.d.mts +1 -0
- package/build/import/value/mutate/mutate.mjs +38 -0
- package/build/import/value/pointer/index.mjs +27 -0
- package/build/import/value/pointer/pointer.d.mts +5 -0
- package/build/import/value/pointer/pointer.mjs +45 -0
- package/build/import/value/transform/decode.d.mts +5 -0
- package/build/import/value/transform/decode.mjs +50 -0
- package/build/import/value/transform/encode.d.mts +6 -0
- package/build/import/value/transform/encode.mjs +52 -0
- package/build/import/value/transform/has.d.mts +1 -0
- package/build/import/value/transform/has.mjs +43 -0
- package/build/import/value/transform/index.mjs +27 -0
- package/build/import/value/value/index.mjs +27 -0
- package/build/import/value/value/value.d.mts +24 -0
- package/build/import/value/value/value.mjs +42 -0
- package/build/require/compiler/compiler.d.ts +9 -0
- package/build/require/compiler/compiler.js +87 -6
- package/build/require/compiler/index.js +27 -0
- package/build/require/errors/errors.d.ts +3 -0
- package/build/require/errors/errors.js +55 -3
- package/build/require/errors/function.d.ts +3 -0
- package/build/require/errors/function.js +31 -0
- package/build/require/errors/index.js +27 -0
- package/build/require/index.js +36 -0
- package/build/require/system/index.js +27 -0
- package/build/require/system/policy.d.ts +10 -0
- package/build/require/system/policy.js +40 -0
- package/build/require/system/system.d.ts +3 -0
- package/build/require/system/system.js +36 -0
- package/build/require/type/any/any.d.ts +1 -0
- package/build/require/type/any/any.js +28 -0
- package/build/require/type/any/index.js +27 -0
- package/build/require/type/array/array.d.ts +7 -0
- package/build/require/type/array/array.js +28 -0
- package/build/require/type/array/index.js +27 -0
- package/build/require/type/async-iterator/async-iterator.d.ts +1 -0
- package/build/require/type/async-iterator/async-iterator.js +28 -0
- package/build/require/type/async-iterator/index.js +27 -0
- package/build/require/type/awaited/awaited.d.ts +1 -0
- package/build/require/type/awaited/awaited.js +37 -0
- package/build/require/type/awaited/index.js +27 -0
- package/build/require/type/bigint/bigint.d.ts +1 -0
- package/build/require/type/bigint/bigint.js +28 -0
- package/build/require/type/bigint/index.js +27 -0
- package/build/require/type/boolean/boolean.d.ts +1 -0
- package/build/require/type/boolean/boolean.js +28 -0
- package/build/require/type/boolean/index.js +27 -0
- package/build/require/type/clone/index.js +27 -0
- package/build/require/type/clone/type.d.ts +2 -0
- package/build/require/type/clone/type.js +29 -0
- package/build/require/type/clone/value.d.ts +1 -0
- package/build/require/type/clone/value.js +29 -0
- package/build/require/type/composite/composite.d.ts +1 -0
- package/build/require/type/composite/composite.js +28 -0
- package/build/require/type/composite/index.js +27 -0
- package/build/require/type/const/const.d.ts +2 -1
- package/build/require/type/const/const.js +32 -1
- package/build/require/type/const/index.js +27 -0
- package/build/require/type/constructor/constructor.d.ts +1 -0
- package/build/require/type/constructor/constructor.js +28 -0
- package/build/require/type/constructor/index.js +27 -0
- package/build/require/type/constructor-parameters/constructor-parameters.d.ts +1 -0
- package/build/require/type/constructor-parameters/constructor-parameters.js +28 -0
- package/build/require/type/constructor-parameters/index.js +27 -0
- package/build/require/type/date/date.d.ts +6 -0
- package/build/require/type/date/date.js +28 -0
- package/build/require/type/date/index.js +27 -0
- package/build/require/type/deref/deref.d.ts +1 -0
- package/build/require/type/deref/deref.js +45 -0
- package/build/require/type/deref/index.js +27 -0
- package/build/require/type/discard/discard.js +27 -0
- package/build/require/type/discard/index.js +27 -0
- package/build/require/type/enum/enum.d.ts +1 -0
- package/build/require/type/enum/enum.js +28 -0
- package/build/require/type/enum/index.js +27 -0
- package/build/require/type/exclude/exclude-from-mapped-result.js +30 -0
- package/build/require/type/exclude/exclude.d.ts +2 -0
- package/build/require/type/exclude/exclude.js +30 -0
- package/build/require/type/exclude/index.js +27 -0
- package/build/require/type/extends/extends-check.js +200 -1
- package/build/require/type/extends/extends-from-mapped-key.js +31 -0
- package/build/require/type/extends/extends-from-mapped-result.js +30 -0
- package/build/require/type/extends/extends-undefined.d.ts +1 -0
- package/build/require/type/extends/extends-undefined.js +30 -0
- package/build/require/type/extends/extends.d.ts +3 -0
- package/build/require/type/extends/extends.js +34 -0
- package/build/require/type/extends/index.js +27 -0
- package/build/require/type/extract/extract-from-mapped-result.js +30 -0
- package/build/require/type/extract/extract.d.ts +2 -0
- package/build/require/type/extract/extract.js +30 -0
- package/build/require/type/extract/index.js +27 -0
- package/build/require/type/function/function.d.ts +1 -0
- package/build/require/type/function/function.js +28 -0
- package/build/require/type/function/index.js +27 -0
- package/build/require/type/guard/index.js +27 -0
- package/build/require/type/guard/type.d.ts +46 -0
- package/build/require/type/guard/type.js +111 -1
- package/build/require/type/guard/value.d.ts +14 -0
- package/build/require/type/guard/value.js +41 -0
- package/build/require/type/helpers/helpers.d.ts +1 -0
- package/build/require/type/helpers/helpers.js +28 -0
- package/build/require/type/helpers/index.js +27 -0
- package/build/require/type/index.js +27 -0
- package/build/require/type/indexed/index.js +27 -0
- package/build/require/type/indexed/indexed-from-mapped-key.js +35 -1
- package/build/require/type/indexed/indexed-property-keys.d.ts +1 -0
- package/build/require/type/indexed/indexed-property-keys.js +36 -0
- package/build/require/type/indexed/indexed-result.js +42 -0
- package/build/require/type/indexed/indexed.d.ts +3 -0
- package/build/require/type/indexed/indexed.js +33 -0
- package/build/require/type/instance-type/index.js +27 -0
- package/build/require/type/instance-type/instance-type.d.ts +1 -0
- package/build/require/type/instance-type/instance-type.js +28 -0
- package/build/require/type/integer/index.js +27 -0
- package/build/require/type/integer/integer.d.ts +1 -0
- package/build/require/type/integer/integer.js +28 -0
- package/build/require/type/intersect/index.js +27 -0
- package/build/require/type/intersect/intersect-create.js +35 -0
- package/build/require/type/intersect/intersect-evaluated.d.ts +1 -0
- package/build/require/type/intersect/intersect-evaluated.js +36 -0
- package/build/require/type/intersect/intersect-type.js +27 -0
- package/build/require/type/intersect/intersect.d.ts +1 -0
- package/build/require/type/intersect/intersect.js +32 -0
- package/build/require/type/intrinsic/capitalize.d.ts +1 -0
- package/build/require/type/intrinsic/capitalize.js +28 -0
- package/build/require/type/intrinsic/index.js +27 -0
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +31 -0
- package/build/require/type/intrinsic/intrinsic.d.ts +2 -0
- package/build/require/type/intrinsic/intrinsic.js +43 -1
- package/build/require/type/intrinsic/lowercase.d.ts +1 -0
- package/build/require/type/intrinsic/lowercase.js +28 -0
- package/build/require/type/intrinsic/uncapitalize.d.ts +1 -0
- package/build/require/type/intrinsic/uncapitalize.js +28 -0
- package/build/require/type/intrinsic/uppercase.d.ts +1 -0
- package/build/require/type/intrinsic/uppercase.js +28 -0
- package/build/require/type/iterator/index.js +27 -0
- package/build/require/type/iterator/iterator.d.ts +1 -0
- package/build/require/type/iterator/iterator.js +28 -0
- package/build/require/type/keyof/index.js +27 -0
- package/build/require/type/keyof/keyof-from-mapped-result.js +30 -0
- package/build/require/type/keyof/keyof-property-keys.d.ts +2 -0
- package/build/require/type/keyof/keyof-property-keys.js +47 -0
- package/build/require/type/keyof/keyof.d.ts +2 -0
- package/build/require/type/keyof/keyof.js +33 -0
- package/build/require/type/literal/index.js +27 -0
- package/build/require/type/literal/literal.d.ts +1 -0
- package/build/require/type/literal/literal.js +28 -0
- package/build/require/type/mapped/index.js +27 -0
- package/build/require/type/mapped/mapped-key.js +28 -0
- package/build/require/type/mapped/mapped-result.js +28 -0
- package/build/require/type/mapped/mapped.d.ts +2 -0
- package/build/require/type/mapped/mapped.js +46 -1
- package/build/require/type/modifiers/index.js +27 -0
- package/build/require/type/modifiers/modifiers.js +37 -0
- package/build/require/type/never/index.js +27 -0
- package/build/require/type/never/never.d.ts +1 -0
- package/build/require/type/never/never.js +28 -0
- package/build/require/type/not/index.js +27 -0
- package/build/require/type/not/not.d.ts +1 -0
- package/build/require/type/not/not.js +28 -0
- package/build/require/type/null/index.js +27 -0
- package/build/require/type/null/null.d.ts +1 -0
- package/build/require/type/null/null.js +28 -0
- package/build/require/type/number/index.js +27 -0
- package/build/require/type/number/number.d.ts +1 -0
- package/build/require/type/number/number.js +28 -0
- package/build/require/type/object/index.js +27 -0
- package/build/require/type/object/object.d.ts +5 -0
- package/build/require/type/object/object.js +33 -0
- package/build/require/type/omit/index.js +27 -0
- package/build/require/type/omit/omit-from-mapped-key.js +31 -0
- package/build/require/type/omit/omit.d.ts +3 -0
- package/build/require/type/omit/omit.js +39 -0
- package/build/require/type/operators/index.js +27 -0
- package/build/require/type/operators/operators.d.ts +8 -0
- package/build/require/type/operators/operators.js +42 -0
- package/build/require/type/optional/index.js +27 -0
- package/build/require/type/optional/optional.d.ts +1 -0
- package/build/require/type/optional/optional.js +28 -0
- package/build/require/type/parameters/index.js +27 -0
- package/build/require/type/parameters/parameters.d.ts +1 -0
- package/build/require/type/parameters/parameters.js +28 -0
- package/build/require/type/partial/index.js +27 -0
- package/build/require/type/partial/partial-from-mapped-result.js +30 -0
- package/build/require/type/partial/partial.d.ts +2 -0
- package/build/require/type/partial/partial.js +36 -0
- package/build/require/type/patterns/index.js +27 -0
- package/build/require/type/patterns/patterns.js +27 -0
- package/build/require/type/pick/index.js +27 -0
- package/build/require/type/pick/pick-from-mapped-key.js +31 -0
- package/build/require/type/pick/pick.d.ts +3 -0
- package/build/require/type/pick/pick.js +34 -0
- package/build/require/type/promise/index.js +27 -0
- package/build/require/type/promise/promise.d.ts +1 -0
- package/build/require/type/promise/promise.js +28 -0
- package/build/require/type/readonly/index.js +27 -0
- package/build/require/type/readonly/readonly.d.ts +1 -0
- package/build/require/type/readonly/readonly.js +28 -0
- package/build/require/type/readonly-optional/index.js +27 -0
- package/build/require/type/readonly-optional/readonly-optional.d.ts +1 -0
- package/build/require/type/readonly-optional/readonly-optional.js +28 -0
- package/build/require/type/record/index.js +27 -0
- package/build/require/type/record/record.d.ts +1 -0
- package/build/require/type/record/record.js +48 -0
- package/build/require/type/recursive/index.js +27 -0
- package/build/require/type/recursive/recursive.d.ts +1 -0
- package/build/require/type/recursive/recursive.js +30 -0
- package/build/require/type/ref/index.js +27 -0
- package/build/require/type/ref/ref.d.ts +2 -0
- package/build/require/type/ref/ref.js +28 -0
- package/build/require/type/regexp/index.js +27 -0
- package/build/require/type/regexp/regexp.d.ts +2 -0
- package/build/require/type/regexp/regexp.js +28 -0
- package/build/require/type/registry/format.d.ts +6 -0
- package/build/require/type/registry/format.js +34 -0
- package/build/require/type/registry/index.js +27 -0
- package/build/require/type/registry/type.d.ts +6 -0
- package/build/require/type/registry/type.js +34 -0
- package/build/require/type/required/index.js +27 -0
- package/build/require/type/required/required-from-mapped-result.js +30 -0
- package/build/require/type/required/required.d.ts +2 -0
- package/build/require/type/required/required.js +36 -0
- package/build/require/type/rest/index.js +27 -0
- package/build/require/type/rest/rest.d.ts +1 -0
- package/build/require/type/rest/rest.js +32 -0
- package/build/require/type/return-type/index.js +27 -0
- package/build/require/type/return-type/return-type.d.ts +1 -0
- package/build/require/type/return-type/return-type.js +28 -0
- package/build/require/type/schema/anyschema.js +27 -0
- package/build/require/type/schema/index.js +27 -0
- package/build/require/type/schema/schema.d.ts +7 -0
- package/build/require/type/schema/schema.js +27 -0
- package/build/require/type/static/index.js +27 -0
- package/build/require/type/static/static.d.ts +3 -0
- package/build/require/type/static/static.js +27 -0
- package/build/require/type/strict/index.js +27 -0
- package/build/require/type/strict/strict.d.ts +1 -0
- package/build/require/type/strict/strict.js +28 -0
- package/build/require/type/string/index.js +27 -0
- package/build/require/type/string/string.d.ts +7 -0
- package/build/require/type/string/string.js +28 -0
- package/build/require/type/symbol/index.js +27 -0
- package/build/require/type/symbol/symbol.d.ts +1 -0
- package/build/require/type/symbol/symbol.js +28 -0
- package/build/require/type/symbols/index.js +27 -0
- package/build/require/type/symbols/symbols.d.ts +5 -0
- package/build/require/type/symbols/symbols.js +32 -0
- package/build/require/type/template-literal/finite.js +37 -0
- package/build/require/type/template-literal/generate.js +37 -0
- package/build/require/type/template-literal/index.js +27 -0
- package/build/require/type/template-literal/parser.d.ts +2 -0
- package/build/require/type/template-literal/parser.js +44 -0
- package/build/require/type/template-literal/pattern.js +38 -0
- package/build/require/type/template-literal/syntax.d.ts +1 -0
- package/build/require/type/template-literal/syntax.js +35 -0
- package/build/require/type/template-literal/template-literal.d.ts +2 -0
- package/build/require/type/template-literal/template-literal.js +29 -0
- package/build/require/type/template-literal/union.d.ts +1 -0
- package/build/require/type/template-literal/union.js +31 -0
- package/build/require/type/transform/index.js +27 -0
- package/build/require/type/transform/transform.d.ts +1 -0
- package/build/require/type/transform/transform.js +36 -0
- package/build/require/type/tuple/index.js +27 -0
- package/build/require/type/tuple/tuple.d.ts +1 -0
- package/build/require/type/tuple/tuple.js +30 -0
- package/build/require/type/type/index.d.ts +1 -0
- package/build/require/type/type/index.js +34 -0
- package/build/require/type/type/javascript.d.ts +19 -0
- package/build/require/type/type/javascript.js +45 -0
- package/build/require/type/type/json.d.ts +62 -1
- package/build/require/type/type/json.js +82 -1
- package/build/require/type/type/type.js +30 -0
- package/build/require/type/uint8array/index.js +27 -0
- package/build/require/type/uint8array/uint8array.d.ts +1 -0
- package/build/require/type/uint8array/uint8array.js +28 -0
- package/build/require/type/undefined/index.js +27 -0
- package/build/require/type/undefined/undefined.d.ts +1 -0
- package/build/require/type/undefined/undefined.js +28 -0
- package/build/require/type/union/index.js +27 -0
- package/build/require/type/union/union-create.js +27 -0
- package/build/require/type/union/union-evaluated.d.ts +1 -0
- package/build/require/type/union/union-evaluated.js +37 -0
- package/build/require/type/union/union-type.js +27 -0
- package/build/require/type/union/union.d.ts +1 -0
- package/build/require/type/union/union.js +29 -0
- package/build/require/type/unknown/index.js +27 -0
- package/build/require/type/unknown/unknown.d.ts +1 -0
- package/build/require/type/unknown/unknown.js +28 -0
- package/build/require/type/unsafe/index.js +27 -0
- package/build/require/type/unsafe/unsafe.d.ts +1 -0
- package/build/require/type/unsafe/unsafe.js +28 -0
- package/build/require/type/void/index.js +27 -0
- package/build/require/type/void/void.d.ts +1 -0
- package/build/require/type/void/void.js +28 -0
- package/build/require/value/cast/cast.d.ts +2 -0
- package/build/require/value/cast/cast.js +55 -0
- package/build/require/value/cast/index.js +27 -0
- package/build/require/value/check/check.d.ts +2 -0
- package/build/require/value/check/check.js +46 -1
- package/build/require/value/check/index.js +27 -0
- package/build/require/value/clean/clean.d.ts +2 -0
- package/build/require/value/clean/clean.js +39 -1
- package/build/require/value/clean/index.js +27 -0
- package/build/require/value/clone/clone.d.ts +1 -0
- package/build/require/value/clone/clone.js +34 -0
- package/build/require/value/clone/index.js +27 -0
- package/build/require/value/convert/convert.d.ts +2 -0
- package/build/require/value/convert/convert.js +57 -1
- package/build/require/value/convert/index.js +27 -0
- package/build/require/value/create/create.d.ts +2 -0
- package/build/require/value/create/create.js +44 -0
- package/build/require/value/create/index.js +27 -0
- package/build/require/value/default/default.d.ts +2 -0
- package/build/require/value/default/default.js +46 -0
- package/build/require/value/default/index.js +27 -0
- package/build/require/value/delta/delta.js +42 -0
- package/build/require/value/delta/index.js +27 -0
- package/build/require/value/deref/deref.d.ts +1 -0
- package/build/require/value/deref/deref.js +28 -0
- package/build/require/value/deref/index.js +27 -0
- package/build/require/value/equal/equal.d.ts +1 -0
- package/build/require/value/equal/equal.js +34 -0
- package/build/require/value/equal/index.js +27 -0
- package/build/require/value/guard/guard.d.ts +20 -0
- package/build/require/value/guard/guard.js +57 -0
- package/build/require/value/guard/index.js +27 -0
- package/build/require/value/hash/hash.d.ts +1 -0
- package/build/require/value/hash/hash.js +46 -0
- package/build/require/value/hash/index.js +27 -0
- package/build/require/value/index.js +39 -0
- package/build/require/value/mutate/index.js +27 -0
- package/build/require/value/mutate/mutate.d.ts +1 -0
- package/build/require/value/mutate/mutate.js +38 -0
- package/build/require/value/pointer/index.js +27 -0
- package/build/require/value/pointer/pointer.d.ts +5 -0
- package/build/require/value/pointer/pointer.js +45 -0
- package/build/require/value/transform/decode.d.ts +5 -0
- package/build/require/value/transform/decode.js +50 -0
- package/build/require/value/transform/encode.d.ts +6 -0
- package/build/require/value/transform/encode.js +52 -0
- package/build/require/value/transform/has.d.ts +1 -0
- package/build/require/value/transform/has.js +43 -0
- package/build/require/value/transform/index.js +27 -0
- package/build/require/value/value/index.js +27 -0
- package/build/require/value/value/value.d.ts +24 -0
- package/build/require/value/value/value.js +42 -0
- package/package.json +1 -1
- package/readme.md +2 -3
|
@@ -3,27 +3,51 @@ import { Edit } from '../delta/index.mjs';
|
|
|
3
3
|
import { ValueErrorIterator } from '../../errors/index.mjs';
|
|
4
4
|
import type { TSchema } from '../../type/schema/index.mjs';
|
|
5
5
|
import type { Static, StaticDecode, StaticEncode } from '../../type/static/index.mjs';
|
|
6
|
+
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
|
|
6
7
|
export declare function Cast<T extends TSchema>(schema: T, references: TSchema[], value: unknown): Static<T>;
|
|
8
|
+
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
|
|
7
9
|
export declare function Cast<T extends TSchema>(schema: T, value: unknown): Static<T>;
|
|
10
|
+
/** Creates a value from the given type and references */
|
|
8
11
|
export declare function Create<T extends TSchema>(schema: T, references: TSchema[]): Static<T>;
|
|
12
|
+
/** Creates a value from the given type */
|
|
9
13
|
export declare function Create<T extends TSchema>(schema: T): Static<T>;
|
|
14
|
+
/** Returns true if the value matches the given type and references */
|
|
10
15
|
export declare function Check<T extends TSchema>(schema: T, references: TSchema[], value: unknown): value is Static<T>;
|
|
16
|
+
/** Returns true if the value matches the given type */
|
|
11
17
|
export declare function Check<T extends TSchema>(schema: T, value: unknown): value is Static<T>;
|
|
18
|
+
/** `[Mutable]` 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. */
|
|
12
19
|
export declare function Clean<T extends TSchema>(schema: T, references: TSchema[], value: unknown): unknown;
|
|
20
|
+
/** `[Mutable]` 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. */
|
|
13
21
|
export declare function Clean<T extends TSchema>(schema: T, value: unknown): unknown;
|
|
22
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
14
23
|
export declare function Convert<T extends TSchema>(schema: T, references: TSchema[], value: unknown): unknown;
|
|
24
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possibl. */
|
|
15
25
|
export declare function Convert<T extends TSchema>(schema: T, value: unknown): unknown;
|
|
26
|
+
/** Returns a structural clone of the given value */
|
|
16
27
|
export declare function Clone<T>(value: T): T;
|
|
28
|
+
/** Decodes a value or throws if error */
|
|
17
29
|
export declare function Decode<T extends TSchema, R = StaticDecode<T>>(schema: T, references: TSchema[], value: unknown): R;
|
|
30
|
+
/** Decodes a value or throws if error */
|
|
18
31
|
export declare function Decode<T extends TSchema, R = StaticDecode<T>>(schema: T, value: unknown): R;
|
|
32
|
+
/** `[Mutable]` 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. */
|
|
19
33
|
export declare function Default<T extends TSchema>(schema: T, references: TSchema[], value: unknown): unknown;
|
|
34
|
+
/** `[Mutable]` 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. */
|
|
20
35
|
export declare function Default<T extends TSchema>(schema: T, value: unknown): unknown;
|
|
36
|
+
/** Encodes a value or throws if error */
|
|
21
37
|
export declare function Encode<T extends TSchema, R = StaticEncode<T>>(schema: T, references: TSchema[], value: unknown): R;
|
|
38
|
+
/** Encodes a value or throws if error */
|
|
22
39
|
export declare function Encode<T extends TSchema, R = StaticEncode<T>>(schema: T, value: unknown): R;
|
|
40
|
+
/** Returns an iterator for each error in this value. */
|
|
23
41
|
export declare function Errors<T extends TSchema>(schema: T, references: TSchema[], value: unknown): ValueErrorIterator;
|
|
42
|
+
/** Returns an iterator for each error in this value. */
|
|
24
43
|
export declare function Errors<T extends TSchema>(schema: T, value: unknown): ValueErrorIterator;
|
|
44
|
+
/** Returns true if left and right values are structurally equal */
|
|
25
45
|
export declare function Equal<T>(left: T, right: unknown): right is T;
|
|
46
|
+
/** Returns edits to transform the current value into the next value */
|
|
26
47
|
export declare function Diff(current: unknown, next: unknown): Edit[];
|
|
48
|
+
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
27
49
|
export declare function Hash(value: unknown): bigint;
|
|
50
|
+
/** Returns a new value with edits applied to the given value */
|
|
28
51
|
export declare function Patch<T = any>(current: unknown, edits: Edit[]): T;
|
|
52
|
+
/** `[Mutable]` Performs a deep mutable value assignment while retaining internal references. */
|
|
29
53
|
export declare function Mutate(current: Mutable, next: Mutable): void;
|
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
/*--------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
@sinclair/typebox/value
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
|
26
|
+
|
|
27
|
+
---------------------------------------------------------------------------*/
|
|
1
28
|
import { TransformDecode, TransformEncode, TransformDecodeCheckError, TransformEncodeCheckError } from '../transform/index.mjs';
|
|
2
29
|
import { Mutate as MutateValue } from '../mutate/index.mjs';
|
|
3
30
|
import { Hash as HashValue } from '../hash/index.mjs';
|
|
@@ -11,33 +38,42 @@ import { Check as CheckValue } from '../check/index.mjs';
|
|
|
11
38
|
import { Default as DefaultValue } from '../default/index.mjs';
|
|
12
39
|
import { Diff as DiffValue, Patch as PatchValue } from '../delta/index.mjs';
|
|
13
40
|
import { Errors as ValueErrors } from '../../errors/index.mjs';
|
|
41
|
+
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
|
|
14
42
|
export function Cast(...args) {
|
|
15
43
|
return CastValue.apply(CastValue, args);
|
|
16
44
|
}
|
|
45
|
+
/** Creates a value from the given type */
|
|
17
46
|
export function Create(...args) {
|
|
18
47
|
return CreateValue.apply(CreateValue, args);
|
|
19
48
|
}
|
|
49
|
+
/** Returns true if the value matches the given type */
|
|
20
50
|
export function Check(...args) {
|
|
21
51
|
return CheckValue.apply(CheckValue, args);
|
|
22
52
|
}
|
|
53
|
+
/** `[Mutable]` 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. */
|
|
23
54
|
export function Clean(...args) {
|
|
24
55
|
return CleanValue.apply(CleanValue, args);
|
|
25
56
|
}
|
|
57
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
26
58
|
export function Convert(...args) {
|
|
27
59
|
return ConvertValue.apply(ConvertValue, args);
|
|
28
60
|
}
|
|
61
|
+
/** Returns a structural clone of the given value */
|
|
29
62
|
export function Clone(value) {
|
|
30
63
|
return CloneValue(value);
|
|
31
64
|
}
|
|
65
|
+
/** Decodes a value or throws if error */
|
|
32
66
|
export function Decode(...args) {
|
|
33
67
|
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
34
68
|
if (!Check(schema, references, value))
|
|
35
69
|
throw new TransformDecodeCheckError(schema, value, Errors(schema, references, value).First());
|
|
36
70
|
return TransformDecode(schema, references, value);
|
|
37
71
|
}
|
|
72
|
+
/** `[Mutable]` 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. */
|
|
38
73
|
export function Default(...args) {
|
|
39
74
|
return DefaultValue.apply(DefaultValue, args);
|
|
40
75
|
}
|
|
76
|
+
/** Encodes a value or throws if error */
|
|
41
77
|
export function Encode(...args) {
|
|
42
78
|
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
43
79
|
const encoded = TransformEncode(schema, references, value);
|
|
@@ -45,21 +81,27 @@ export function Encode(...args) {
|
|
|
45
81
|
throw new TransformEncodeCheckError(schema, value, Errors(schema, references, value).First());
|
|
46
82
|
return encoded;
|
|
47
83
|
}
|
|
84
|
+
/** Returns an iterator for each error in this value. */
|
|
48
85
|
export function Errors(...args) {
|
|
49
86
|
return ValueErrors.apply(ValueErrors, args);
|
|
50
87
|
}
|
|
88
|
+
/** Returns true if left and right values are structurally equal */
|
|
51
89
|
export function Equal(left, right) {
|
|
52
90
|
return EqualValue(left, right);
|
|
53
91
|
}
|
|
92
|
+
/** Returns edits to transform the current value into the next value */
|
|
54
93
|
export function Diff(current, next) {
|
|
55
94
|
return DiffValue(current, next);
|
|
56
95
|
}
|
|
96
|
+
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
57
97
|
export function Hash(value) {
|
|
58
98
|
return HashValue(value);
|
|
59
99
|
}
|
|
100
|
+
/** Returns a new value with edits applied to the given value */
|
|
60
101
|
export function Patch(current, edits) {
|
|
61
102
|
return PatchValue(current, edits);
|
|
62
103
|
}
|
|
104
|
+
/** `[Mutable]` Performs a deep mutable value assignment while retaining internal references. */
|
|
63
105
|
export function Mutate(current, next) {
|
|
64
106
|
MutateValue(current, next);
|
|
65
107
|
}
|
|
@@ -9,10 +9,15 @@ export declare class TypeCheck<T extends TSchema> {
|
|
|
9
9
|
private readonly code;
|
|
10
10
|
private readonly hasTransform;
|
|
11
11
|
constructor(schema: T, references: TSchema[], checkFunc: CheckFunction, code: string);
|
|
12
|
+
/** Returns the generated assertion code used to validate this type. */
|
|
12
13
|
Code(): string;
|
|
14
|
+
/** Returns an iterator for each error in this value. */
|
|
13
15
|
Errors(value: unknown): ValueErrorIterator;
|
|
16
|
+
/** Returns true if the value matches the compiled type. */
|
|
14
17
|
Check(value: unknown): value is Static<T>;
|
|
18
|
+
/** Decodes a value or throws if error */
|
|
15
19
|
Decode(value: unknown): StaticDecode<T>;
|
|
20
|
+
/** Encodes a value or throws if error */
|
|
16
21
|
Encode(value: unknown): StaticEncode<T>;
|
|
17
22
|
}
|
|
18
23
|
export declare class TypeCompilerUnknownTypeError extends Error {
|
|
@@ -34,8 +39,12 @@ export type TypeCompilerLanguageOption = 'typescript' | 'javascript';
|
|
|
34
39
|
export interface TypeCompilerCodegenOptions {
|
|
35
40
|
language?: TypeCompilerLanguageOption;
|
|
36
41
|
}
|
|
42
|
+
/** Compiles Types for Runtime Type Checking */
|
|
37
43
|
export declare namespace TypeCompiler {
|
|
44
|
+
/** Generates the code used to assert this type and returns it as a string */
|
|
38
45
|
function Code<T extends TSchema>(schema: T, references: TSchema[], options?: TypeCompilerCodegenOptions): string;
|
|
46
|
+
/** Generates the code used to assert this type and returns it as a string */
|
|
39
47
|
function Code<T extends TSchema>(schema: T, options?: TypeCompilerCodegenOptions): string;
|
|
48
|
+
/** Compiles a TypeBox type for optimal runtime type checking. Types must be valid TypeBox types of TSchema */
|
|
40
49
|
function Compile<T extends TSchema>(schema: T, references?: TSchema[]): TypeCheck<T>;
|
|
41
50
|
}
|
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/compiler
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
2
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
30
|
exports.TypeCompiler = exports.Policy = exports.TypeCompilerTypeGuardError = exports.TypeCompilerUnknownTypeError = exports.TypeCheck = void 0;
|
|
4
31
|
const index_1 = require("../value/transform/index");
|
|
@@ -13,6 +40,9 @@ const index_8 = require("../type/registry/index");
|
|
|
13
40
|
const index_9 = require("../type/keyof/index");
|
|
14
41
|
const extends_undefined_1 = require("../type/extends/extends-undefined");
|
|
15
42
|
const index_10 = require("../type/never/index");
|
|
43
|
+
// ------------------------------------------------------------------
|
|
44
|
+
// TypeCheck
|
|
45
|
+
// ------------------------------------------------------------------
|
|
16
46
|
class TypeCheck {
|
|
17
47
|
constructor(schema, references, checkFunc, code) {
|
|
18
48
|
this.schema = schema;
|
|
@@ -21,20 +51,25 @@ class TypeCheck {
|
|
|
21
51
|
this.code = code;
|
|
22
52
|
this.hasTransform = (0, index_1.HasTransform)(schema, references);
|
|
23
53
|
}
|
|
54
|
+
/** Returns the generated assertion code used to validate this type. */
|
|
24
55
|
Code() {
|
|
25
56
|
return this.code;
|
|
26
57
|
}
|
|
58
|
+
/** Returns an iterator for each error in this value. */
|
|
27
59
|
Errors(value) {
|
|
28
60
|
return (0, index_3.Errors)(this.schema, this.references, value);
|
|
29
61
|
}
|
|
62
|
+
/** Returns true if the value matches the compiled type. */
|
|
30
63
|
Check(value) {
|
|
31
64
|
return this.checkFunc(value);
|
|
32
65
|
}
|
|
66
|
+
/** Decodes a value or throws if error */
|
|
33
67
|
Decode(value) {
|
|
34
68
|
if (!this.checkFunc(value))
|
|
35
69
|
throw new index_1.TransformDecodeCheckError(this.schema, value, this.Errors(value).First());
|
|
36
70
|
return this.hasTransform ? (0, index_1.TransformDecode)(this.schema, this.references, value) : value;
|
|
37
71
|
}
|
|
72
|
+
/** Encodes a value or throws if error */
|
|
38
73
|
Encode(value) {
|
|
39
74
|
const encoded = this.hasTransform ? (0, index_1.TransformEncode)(this.schema, this.references, value) : value;
|
|
40
75
|
if (!this.checkFunc(encoded))
|
|
@@ -43,6 +78,9 @@ class TypeCheck {
|
|
|
43
78
|
}
|
|
44
79
|
}
|
|
45
80
|
exports.TypeCheck = TypeCheck;
|
|
81
|
+
// ------------------------------------------------------------------
|
|
82
|
+
// Character
|
|
83
|
+
// ------------------------------------------------------------------
|
|
46
84
|
var Character;
|
|
47
85
|
(function (Character) {
|
|
48
86
|
function DollarSign(code) {
|
|
@@ -62,6 +100,9 @@ var Character;
|
|
|
62
100
|
}
|
|
63
101
|
Character.IsNumeric = IsNumeric;
|
|
64
102
|
})(Character || (Character = {}));
|
|
103
|
+
// ------------------------------------------------------------------
|
|
104
|
+
// MemberExpression
|
|
105
|
+
// ------------------------------------------------------------------
|
|
65
106
|
var MemberExpression;
|
|
66
107
|
(function (MemberExpression) {
|
|
67
108
|
function IsFirstCharacterNumeric(value) {
|
|
@@ -88,6 +129,9 @@ var MemberExpression;
|
|
|
88
129
|
}
|
|
89
130
|
MemberExpression.Encode = Encode;
|
|
90
131
|
})(MemberExpression || (MemberExpression = {}));
|
|
132
|
+
// ------------------------------------------------------------------
|
|
133
|
+
// Identifier
|
|
134
|
+
// ------------------------------------------------------------------
|
|
91
135
|
var Identifier;
|
|
92
136
|
(function (Identifier) {
|
|
93
137
|
function Encode($id) {
|
|
@@ -105,6 +149,9 @@ var Identifier;
|
|
|
105
149
|
}
|
|
106
150
|
Identifier.Encode = Encode;
|
|
107
151
|
})(Identifier || (Identifier = {}));
|
|
152
|
+
// ------------------------------------------------------------------
|
|
153
|
+
// LiteralString
|
|
154
|
+
// ------------------------------------------------------------------
|
|
108
155
|
var LiteralString;
|
|
109
156
|
(function (LiteralString) {
|
|
110
157
|
function Escape(content) {
|
|
@@ -112,6 +159,9 @@ var LiteralString;
|
|
|
112
159
|
}
|
|
113
160
|
LiteralString.Escape = Escape;
|
|
114
161
|
})(LiteralString || (LiteralString = {}));
|
|
162
|
+
// ------------------------------------------------------------------
|
|
163
|
+
// Errors
|
|
164
|
+
// ------------------------------------------------------------------
|
|
115
165
|
class TypeCompilerUnknownTypeError extends Error {
|
|
116
166
|
constructor(schema) {
|
|
117
167
|
super('Unknown type');
|
|
@@ -126,6 +176,9 @@ class TypeCompilerTypeGuardError extends Error {
|
|
|
126
176
|
}
|
|
127
177
|
}
|
|
128
178
|
exports.TypeCompilerTypeGuardError = TypeCompilerTypeGuardError;
|
|
179
|
+
// ------------------------------------------------------------------
|
|
180
|
+
// Policy
|
|
181
|
+
// ------------------------------------------------------------------
|
|
129
182
|
var Policy;
|
|
130
183
|
(function (Policy) {
|
|
131
184
|
function IsExactOptionalProperty(value, key, expression) {
|
|
@@ -151,11 +204,18 @@ var Policy;
|
|
|
151
204
|
}
|
|
152
205
|
Policy.IsVoidLike = IsVoidLike;
|
|
153
206
|
})(Policy || (exports.Policy = Policy = {}));
|
|
207
|
+
/** Compiles Types for Runtime Type Checking */
|
|
154
208
|
var TypeCompiler;
|
|
155
209
|
(function (TypeCompiler) {
|
|
210
|
+
// ----------------------------------------------------------------
|
|
211
|
+
// Guards
|
|
212
|
+
// ----------------------------------------------------------------
|
|
156
213
|
function IsAnyOrUnknown(schema) {
|
|
157
214
|
return schema[index_7.Kind] === 'Any' || schema[index_7.Kind] === 'Unknown';
|
|
158
215
|
}
|
|
216
|
+
// ----------------------------------------------------------------
|
|
217
|
+
// Types
|
|
218
|
+
// ----------------------------------------------------------------
|
|
159
219
|
function* TAny(schema, references, value) {
|
|
160
220
|
yield 'true';
|
|
161
221
|
}
|
|
@@ -337,6 +397,8 @@ var TypeCompiler;
|
|
|
337
397
|
}
|
|
338
398
|
function* TRef(schema, references, value) {
|
|
339
399
|
const target = (0, index_5.Deref)(schema, references);
|
|
400
|
+
// Reference: If we have seen this reference before we can just yield and return the function call.
|
|
401
|
+
// If this isn't the case we defer to visit to generate and set the function for subsequent passes.
|
|
340
402
|
if (state.functions.has(schema.$ref))
|
|
341
403
|
return yield `${CreateFunctionName(schema.$ref)}(${value})`;
|
|
342
404
|
yield* Visit(target, references, value);
|
|
@@ -364,6 +426,7 @@ var TypeCompiler;
|
|
|
364
426
|
yield `${variable}.test(${value})`;
|
|
365
427
|
}
|
|
366
428
|
function* TThis(schema, references, value) {
|
|
429
|
+
// Note: This types are assured to be hoisted prior to this call. Just yield the function.
|
|
367
430
|
yield `${CreateFunctionName(schema.$ref)}(${value})`;
|
|
368
431
|
}
|
|
369
432
|
function* TTuple(schema, references, value) {
|
|
@@ -404,6 +467,9 @@ var TypeCompiler;
|
|
|
404
467
|
function* Visit(schema, references, value, useHoisting = true) {
|
|
405
468
|
const references_ = (0, index_2.IsString)(schema.$id) ? [...references, schema] : references;
|
|
406
469
|
const schema_ = schema;
|
|
470
|
+
// --------------------------------------------------------------
|
|
471
|
+
// Hoisting
|
|
472
|
+
// --------------------------------------------------------------
|
|
407
473
|
if (useHoisting && (0, index_2.IsString)(schema.$id)) {
|
|
408
474
|
const functionName = CreateFunctionName(schema.$id);
|
|
409
475
|
if (state.functions.has(functionName)) {
|
|
@@ -482,12 +548,19 @@ var TypeCompiler;
|
|
|
482
548
|
return yield* TKind(schema_, references_, value);
|
|
483
549
|
}
|
|
484
550
|
}
|
|
551
|
+
// ----------------------------------------------------------------
|
|
552
|
+
// Compiler State
|
|
553
|
+
// ----------------------------------------------------------------
|
|
554
|
+
// prettier-ignore
|
|
485
555
|
const state = {
|
|
486
|
-
language: 'javascript',
|
|
487
|
-
functions: new Map(),
|
|
488
|
-
variables: new Map(),
|
|
489
|
-
instances: new Map()
|
|
556
|
+
language: 'javascript', // target language
|
|
557
|
+
functions: new Map(), // local functions
|
|
558
|
+
variables: new Map(), // local variables
|
|
559
|
+
instances: new Map() // exterior kind instances
|
|
490
560
|
};
|
|
561
|
+
// ----------------------------------------------------------------
|
|
562
|
+
// Compiler Factory
|
|
563
|
+
// ----------------------------------------------------------------
|
|
491
564
|
function CreateExpression(schema, references, value, useHoisting = true) {
|
|
492
565
|
return `(${[...Visit(schema, references, value, useHoisting)].join(' && ')})`;
|
|
493
566
|
}
|
|
@@ -513,24 +586,31 @@ var TypeCompiler;
|
|
|
513
586
|
function CreateReturns(type) {
|
|
514
587
|
return state.language === 'typescript' ? `: ${type}` : '';
|
|
515
588
|
}
|
|
589
|
+
// ----------------------------------------------------------------
|
|
590
|
+
// Compile
|
|
591
|
+
// ----------------------------------------------------------------
|
|
516
592
|
function Build(schema, references, options) {
|
|
517
|
-
const functionCode = CreateFunction('check', schema, references, 'value');
|
|
593
|
+
const functionCode = CreateFunction('check', schema, references, 'value'); // will populate functions and variables
|
|
518
594
|
const parameter = CreateParameter('value', 'any');
|
|
519
595
|
const returns = CreateReturns('boolean');
|
|
520
596
|
const functions = [...state.functions.values()];
|
|
521
597
|
const variables = [...state.variables.values()];
|
|
522
|
-
|
|
598
|
+
// prettier-ignore
|
|
599
|
+
const checkFunction = (0, index_2.IsString)(schema.$id) // ensure top level schemas with $id's are hoisted
|
|
523
600
|
? `return function check(${parameter})${returns} {\n return ${CreateFunctionName(schema.$id)}(value)\n}`
|
|
524
601
|
: `return ${functionCode}`;
|
|
525
602
|
return [...variables, ...functions, checkFunction].join('\n');
|
|
526
603
|
}
|
|
604
|
+
/** Generates the code used to assert this type and returns it as a string */
|
|
527
605
|
function Code(...args) {
|
|
528
606
|
const defaults = { language: 'javascript' };
|
|
607
|
+
// prettier-ignore
|
|
529
608
|
const [schema, references, options] = (args.length === 2 && (0, index_2.IsArray)(args[1]) ? [args[0], args[1], defaults] :
|
|
530
609
|
args.length === 2 && !(0, index_2.IsArray)(args[1]) ? [args[0], [], args[1]] :
|
|
531
610
|
args.length === 3 ? [args[0], args[1], args[2]] :
|
|
532
611
|
args.length === 1 ? [args[0], [], defaults] :
|
|
533
612
|
[null, [], defaults]);
|
|
613
|
+
// compiler-reset
|
|
534
614
|
state.language = options.language;
|
|
535
615
|
state.variables.clear();
|
|
536
616
|
state.functions.clear();
|
|
@@ -543,6 +623,7 @@ var TypeCompiler;
|
|
|
543
623
|
return Build(schema, references, options);
|
|
544
624
|
}
|
|
545
625
|
TypeCompiler.Code = Code;
|
|
626
|
+
/** Compiles a TypeBox type for optimal runtime type checking. Types must be valid TypeBox types of TSchema */
|
|
546
627
|
function Compile(schema, references = []) {
|
|
547
628
|
const generatedCode = Code(schema, references, { language: 'javascript' });
|
|
548
629
|
const compiledFunction = globalThis.Function('kind', 'format', 'hash', generatedCode);
|
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/compiler
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
2
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
30
|
exports.TypeCompilerUnknownTypeError = exports.TypeCompilerTypeGuardError = exports.TypeCheck = exports.TypeCompiler = exports.ValueErrorIterator = exports.ValueErrorType = void 0;
|
|
4
31
|
var index_1 = require("../errors/index");
|
|
@@ -79,7 +79,10 @@ export declare class ValueErrorIterator {
|
|
|
79
79
|
private readonly iterator;
|
|
80
80
|
constructor(iterator: IterableIterator<ValueError>);
|
|
81
81
|
[Symbol.iterator](): IterableIterator<ValueError>;
|
|
82
|
+
/** Returns the first value error or undefined if no errors */
|
|
82
83
|
First(): ValueError | undefined;
|
|
83
84
|
}
|
|
85
|
+
/** Returns an iterator for each error in this value. */
|
|
84
86
|
export declare function Errors<T extends TSchema>(schema: T, references: TSchema[], value: unknown): ValueErrorIterator;
|
|
87
|
+
/** Returns an iterator for each error in this value. */
|
|
85
88
|
export declare function Errors<T extends TSchema>(schema: T, value: unknown): ValueErrorIterator;
|
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/errors
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
2
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
30
|
exports.Errors = exports.ValueErrorIterator = exports.ValueErrorsUnknownTypeError = exports.ValueErrorType = void 0;
|
|
4
31
|
const index_1 = require("../value/guard/index");
|
|
@@ -11,6 +38,9 @@ const index_5 = require("../value/deref/index");
|
|
|
11
38
|
const index_6 = require("../value/hash/index");
|
|
12
39
|
const index_7 = require("../type/symbols/index");
|
|
13
40
|
const index_8 = require("../type/never/index");
|
|
41
|
+
// --------------------------------------------------------------------------
|
|
42
|
+
// ValueErrorType
|
|
43
|
+
// --------------------------------------------------------------------------
|
|
14
44
|
var ValueErrorType;
|
|
15
45
|
(function (ValueErrorType) {
|
|
16
46
|
ValueErrorType[ValueErrorType["ArrayContains"] = 0] = "ArrayContains";
|
|
@@ -77,6 +107,9 @@ var ValueErrorType;
|
|
|
77
107
|
ValueErrorType[ValueErrorType["Union"] = 61] = "Union";
|
|
78
108
|
ValueErrorType[ValueErrorType["Void"] = 62] = "Void";
|
|
79
109
|
})(ValueErrorType || (exports.ValueErrorType = ValueErrorType = {}));
|
|
110
|
+
// --------------------------------------------------------------------------
|
|
111
|
+
// ValueErrors
|
|
112
|
+
// --------------------------------------------------------------------------
|
|
80
113
|
class ValueErrorsUnknownTypeError extends Error {
|
|
81
114
|
constructor(schema) {
|
|
82
115
|
super('Unknown type');
|
|
@@ -84,12 +117,21 @@ class ValueErrorsUnknownTypeError extends Error {
|
|
|
84
117
|
}
|
|
85
118
|
}
|
|
86
119
|
exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
|
|
120
|
+
// --------------------------------------------------------------------------
|
|
121
|
+
// EscapeKey
|
|
122
|
+
// --------------------------------------------------------------------------
|
|
87
123
|
function EscapeKey(key) {
|
|
88
|
-
return key.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
124
|
+
return key.replace(/~/g, '~0').replace(/\//g, '~1'); // RFC6901 Path
|
|
89
125
|
}
|
|
126
|
+
// --------------------------------------------------------------------------
|
|
127
|
+
// Guards
|
|
128
|
+
// --------------------------------------------------------------------------
|
|
90
129
|
function IsDefined(value) {
|
|
91
130
|
return value !== undefined;
|
|
92
131
|
}
|
|
132
|
+
// --------------------------------------------------------------------------
|
|
133
|
+
// ValueErrorIterator
|
|
134
|
+
// --------------------------------------------------------------------------
|
|
93
135
|
class ValueErrorIterator {
|
|
94
136
|
constructor(iterator) {
|
|
95
137
|
this.iterator = iterator;
|
|
@@ -97,15 +139,22 @@ class ValueErrorIterator {
|
|
|
97
139
|
[Symbol.iterator]() {
|
|
98
140
|
return this.iterator;
|
|
99
141
|
}
|
|
142
|
+
/** Returns the first value error or undefined if no errors */
|
|
100
143
|
First() {
|
|
101
144
|
const next = this.iterator.next();
|
|
102
145
|
return next.done ? undefined : next.value;
|
|
103
146
|
}
|
|
104
147
|
}
|
|
105
148
|
exports.ValueErrorIterator = ValueErrorIterator;
|
|
149
|
+
// --------------------------------------------------------------------------
|
|
150
|
+
// Create
|
|
151
|
+
// --------------------------------------------------------------------------
|
|
106
152
|
function Create(type, schema, path, value) {
|
|
107
153
|
return { type, schema, path, value, message: (0, function_1.GetErrorFunction)()(schema, type) };
|
|
108
154
|
}
|
|
155
|
+
// --------------------------------------------------------------------------
|
|
156
|
+
// Types
|
|
157
|
+
// --------------------------------------------------------------------------
|
|
109
158
|
function* TAny(schema, references, path, value) { }
|
|
110
159
|
function* TArray(schema, references, path, value) {
|
|
111
160
|
if (!(0, index_1.IsArray)(value)) {
|
|
@@ -120,6 +169,7 @@ function* TArray(schema, references, path, value) {
|
|
|
120
169
|
for (let i = 0; i < value.length; i++) {
|
|
121
170
|
yield* Visit(schema.items, references, `${path}/${i}`, value[i]);
|
|
122
171
|
}
|
|
172
|
+
// prettier-ignore
|
|
123
173
|
if (schema.uniqueItems === true && !((function () { const set = new Set(); for (const element of value) {
|
|
124
174
|
const hashed = (0, index_6.Hash)(element);
|
|
125
175
|
if (set.has(hashed)) {
|
|
@@ -131,6 +181,7 @@ function* TArray(schema, references, path, value) {
|
|
|
131
181
|
} return true; })())) {
|
|
132
182
|
yield Create(ValueErrorType.ArrayUniqueItems, schema, path, value);
|
|
133
183
|
}
|
|
184
|
+
// contains
|
|
134
185
|
if (!(IsDefined(schema.contains) || IsDefined(schema.minContains) || IsDefined(schema.maxContains))) {
|
|
135
186
|
return;
|
|
136
187
|
}
|
|
@@ -240,7 +291,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
240
291
|
if (!keyCheck.test(valueKey)) {
|
|
241
292
|
const next = Visit(schema.unevaluatedProperties, references, `${path}/${valueKey}`, value[valueKey]).next();
|
|
242
293
|
if (!next.done)
|
|
243
|
-
yield next.value;
|
|
294
|
+
yield next.value; // yield interior
|
|
244
295
|
}
|
|
245
296
|
}
|
|
246
297
|
}
|
|
@@ -432,7 +483,7 @@ function* TUnion(schema, references, path, value) {
|
|
|
432
483
|
for (const subschema of schema.anyOf) {
|
|
433
484
|
const errors = [...Visit(subschema, references, path, value)];
|
|
434
485
|
if (errors.length === 0)
|
|
435
|
-
return;
|
|
486
|
+
return; // matched
|
|
436
487
|
count += errors.length;
|
|
437
488
|
}
|
|
438
489
|
if (count > 0) {
|
|
@@ -529,6 +580,7 @@ function* Visit(schema, references, path, value) {
|
|
|
529
580
|
return yield* TKind(schema_, references_, path, value);
|
|
530
581
|
}
|
|
531
582
|
}
|
|
583
|
+
/** Returns an iterator for each error in this value. */
|
|
532
584
|
function Errors(...args) {
|
|
533
585
|
const iterator = args.length === 3 ? Visit(args[0], args[1], '', args[2]) : Visit(args[0], [], '', args[1]);
|
|
534
586
|
return new ValueErrorIterator(iterator);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { TSchema } from '../type/schema/index';
|
|
2
2
|
import { ValueErrorType } from './errors';
|
|
3
|
+
/** Creates an error message using en-US as the default locale */
|
|
3
4
|
export declare function DefaultErrorFunction(schema: TSchema, errorType: ValueErrorType): string;
|
|
4
5
|
export type ErrorFunction = (schema: TSchema, type: ValueErrorType) => string;
|
|
6
|
+
/** Sets the error function used to generate error messages */
|
|
5
7
|
export declare function SetErrorFunction(callback: ErrorFunction): void;
|
|
8
|
+
/** Gets the error function used to generate error messages */
|
|
6
9
|
export declare function GetErrorFunction(): ErrorFunction;
|
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/system
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
2
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
30
|
exports.GetErrorFunction = exports.SetErrorFunction = exports.DefaultErrorFunction = void 0;
|
|
4
31
|
const index_1 = require("../type/symbols/index");
|
|
5
32
|
const errors_1 = require("./errors");
|
|
33
|
+
/** Creates an error message using en-US as the default locale */
|
|
6
34
|
function DefaultErrorFunction(schema, errorType) {
|
|
7
35
|
switch (errorType) {
|
|
8
36
|
case errors_1.ValueErrorType.ArrayContains:
|
|
@@ -136,11 +164,14 @@ function DefaultErrorFunction(schema, errorType) {
|
|
|
136
164
|
}
|
|
137
165
|
}
|
|
138
166
|
exports.DefaultErrorFunction = DefaultErrorFunction;
|
|
167
|
+
/** Manages error message providers */
|
|
139
168
|
let errorFunction = DefaultErrorFunction;
|
|
169
|
+
/** Sets the error function used to generate error messages */
|
|
140
170
|
function SetErrorFunction(callback) {
|
|
141
171
|
errorFunction = callback;
|
|
142
172
|
}
|
|
143
173
|
exports.SetErrorFunction = SetErrorFunction;
|
|
174
|
+
/** Gets the error function used to generate error messages */
|
|
144
175
|
function GetErrorFunction() {
|
|
145
176
|
return errorFunction;
|
|
146
177
|
}
|