@sinclair/typebox 0.31.27 → 0.32.0-dev-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/compiler.d.ts +25 -18
- package/compiler/compiler.js +118 -107
- package/errors/errors.d.ts +7 -7
- package/errors/errors.js +48 -44
- package/index.d.ts +71 -0
- package/index.js +205 -0
- package/package.json +8 -19
- package/readme.md +188 -160
- package/system/errors.d.ts +14 -0
- package/system/errors.js +192 -0
- package/system/index.d.ts +3 -1
- package/system/index.js +10 -16
- package/system/policy.d.ts +21 -0
- package/system/policy.js +74 -0
- package/system/system.d.ts +3 -38
- package/system/system.js +15 -218
- package/type/any/any.d.ts +8 -0
- package/type/any/any.js +36 -0
- package/type/any/index.d.ts +1 -0
- package/type/any/index.js +44 -0
- package/type/array/array.d.ts +25 -0
- package/type/array/array.js +42 -0
- package/type/array/index.d.ts +1 -0
- package/type/array/index.js +44 -0
- package/type/async-iterator/async-iterator.d.ts +11 -0
- package/type/async-iterator/async-iterator.js +42 -0
- package/type/async-iterator/index.d.ts +1 -0
- package/type/async-iterator/index.js +44 -0
- package/type/awaited/awaited.d.ts +12 -0
- package/type/awaited/awaited.js +66 -0
- package/type/awaited/index.d.ts +1 -0
- package/type/awaited/index.js +44 -0
- package/type/bigint/bigint.d.ts +16 -0
- package/type/bigint/bigint.js +40 -0
- package/type/bigint/index.d.ts +1 -0
- package/type/bigint/index.js +44 -0
- package/type/boolean/boolean.d.ts +9 -0
- package/type/boolean/boolean.js +40 -0
- package/type/boolean/index.d.ts +1 -0
- package/type/boolean/index.js +44 -0
- package/type/clone/index.d.ts +2 -0
- package/type/clone/index.js +32 -0
- package/type/clone/type.d.ts +5 -0
- package/type/clone/type.js +41 -0
- package/type/clone/value.d.ts +2 -0
- package/type/clone/value.js +58 -0
- package/type/composite/composite.d.ts +15 -0
- package/type/composite/composite.js +47 -0
- package/type/composite/index.d.ts +1 -0
- package/type/composite/index.js +44 -0
- package/type/const/const.d.ts +30 -0
- package/type/const/const.js +84 -0
- package/type/const/index.d.ts +1 -0
- package/type/const/index.js +44 -0
- package/type/constructor/constructor.d.ts +17 -0
- package/type/constructor/constructor.js +43 -0
- package/type/constructor/index.d.ts +1 -0
- package/type/constructor/index.js +44 -0
- package/type/constructor-parameters/constructor-parameters.d.ts +7 -0
- package/type/constructor-parameters/constructor-parameters.js +37 -0
- package/type/constructor-parameters/index.d.ts +1 -0
- package/type/constructor-parameters/index.js +44 -0
- package/type/date/date.d.ts +21 -0
- package/type/date/date.js +40 -0
- package/type/date/index.d.ts +1 -0
- package/type/date/index.js +44 -0
- package/type/deref/deref.d.ts +24 -0
- package/type/deref/deref.js +136 -0
- package/type/deref/index.d.ts +1 -0
- package/type/deref/index.js +44 -0
- package/type/discard/discard.d.ts +1 -0
- package/type/discard/discard.js +38 -0
- package/type/discard/index.d.ts +1 -0
- package/type/discard/index.js +44 -0
- package/type/enum/enum.d.ts +14 -0
- package/type/enum/enum.js +46 -0
- package/type/enum/index.d.ts +1 -0
- package/type/enum/index.js +44 -0
- package/type/exclude/exclude.d.ts +21 -0
- package/type/exclude/exclude.js +54 -0
- package/type/exclude/index.d.ts +1 -0
- package/type/exclude/index.js +44 -0
- package/type/extends/extends-check.d.ts +9 -0
- package/type/extends/extends-check.js +654 -0
- package/type/extends/extends-undefined.d.ts +3 -0
- package/type/extends/extends-undefined.js +51 -0
- package/type/extends/extends.d.ts +9 -0
- package/type/extends/extends.js +47 -0
- package/type/extends/index.d.ts +3 -0
- package/type/extends/index.js +46 -0
- package/type/extract/extract.d.ts +20 -0
- package/type/extract/extract.js +54 -0
- package/type/extract/index.d.ts +1 -0
- package/type/extract/index.js +44 -0
- package/type/function/function.d.ts +17 -0
- package/type/function/function.js +43 -0
- package/type/function/index.d.ts +1 -0
- package/type/function/index.js +44 -0
- package/type/guard/index.d.ts +2 -0
- package/type/guard/index.js +32 -0
- package/type/guard/type.d.ts +130 -0
- package/type/guard/type.js +515 -0
- package/type/guard/value.d.ts +28 -0
- package/type/guard/value.js +100 -0
- package/type/helpers/helpers.d.ts +42 -0
- package/type/helpers/helpers.js +35 -0
- package/type/helpers/index.d.ts +1 -0
- package/type/helpers/index.js +44 -0
- package/type/index.d.ts +70 -0
- package/type/index.js +113 -0
- package/type/indexed/index.d.ts +3 -0
- package/type/indexed/index.js +46 -0
- package/type/indexed/indexed-key.d.ts +17 -0
- package/type/indexed/indexed-key.js +65 -0
- package/type/indexed/indexed-type.d.ts +33 -0
- package/type/indexed/indexed-type.js +106 -0
- package/type/indexed/indexed.d.ts +8 -0
- package/type/indexed/indexed.js +41 -0
- package/type/instance-type/index.d.ts +1 -0
- package/type/instance-type/index.js +44 -0
- package/type/instance-type/instance-type.d.ts +5 -0
- package/type/instance-type/instance-type.js +36 -0
- package/type/integer/index.d.ts +1 -0
- package/type/integer/index.js +44 -0
- package/type/integer/integer.d.ts +16 -0
- package/type/integer/integer.js +40 -0
- package/type/intersect/index.d.ts +1 -0
- package/type/intersect/index.js +44 -0
- package/type/intersect/intersect.d.ts +22 -0
- package/type/intersect/intersect.js +59 -0
- package/type/intrinsic/index.d.ts +1 -0
- package/type/intrinsic/index.js +44 -0
- package/type/intrinsic/intrinsic.d.ts +27 -0
- package/type/intrinsic/intrinsic.js +106 -0
- package/type/iterator/index.d.ts +1 -0
- package/type/iterator/index.js +44 -0
- package/type/iterator/iterator.d.ts +11 -0
- package/type/iterator/iterator.js +42 -0
- package/type/keyof/index.d.ts +3 -0
- package/type/keyof/index.js +46 -0
- package/type/keyof/keyof-string.d.ts +30 -0
- package/type/keyof/keyof-string.js +103 -0
- package/type/keyof/keyof-type.d.ts +11 -0
- package/type/keyof/keyof-type.js +48 -0
- package/type/keyof/keyof.d.ts +5 -0
- package/type/keyof/keyof.js +38 -0
- package/type/literal/index.d.ts +1 -0
- package/type/literal/index.js +44 -0
- package/type/literal/literal.d.ts +10 -0
- package/type/literal/literal.js +41 -0
- package/type/mapped/index.d.ts +1 -0
- package/type/mapped/index.js +44 -0
- package/type/mapped/mapped.d.ts +26 -0
- package/type/mapped/mapped.js +47 -0
- package/type/modifiers/index.d.ts +1 -0
- package/type/modifiers/index.js +44 -0
- package/type/modifiers/modifiers.d.ts +18 -0
- package/type/modifiers/modifiers.js +78 -0
- package/type/never/index.d.ts +1 -0
- package/type/never/index.js +44 -0
- package/type/never/never.d.ts +9 -0
- package/type/never/never.js +40 -0
- package/type/not/index.d.ts +1 -0
- package/type/not/index.js +44 -0
- package/type/not/not.d.ts +10 -0
- package/type/not/not.js +41 -0
- package/type/null/index.d.ts +1 -0
- package/type/null/index.js +44 -0
- package/type/null/null.d.ts +9 -0
- package/type/null/null.js +40 -0
- package/type/number/index.d.ts +1 -0
- package/type/number/index.js +44 -0
- package/type/number/number.d.ts +16 -0
- package/type/number/number.js +40 -0
- package/type/object/index.d.ts +1 -0
- package/type/object/index.js +44 -0
- package/type/object/object.d.ts +44 -0
- package/type/object/object.js +47 -0
- package/type/omit/index.d.ts +1 -0
- package/type/omit/index.js +44 -0
- package/type/omit/omit.d.ts +21 -0
- package/type/omit/omit.js +75 -0
- package/type/operators/index.d.ts +1 -0
- package/type/operators/index.js +44 -0
- package/type/operators/operators.d.ts +24 -0
- package/type/operators/operators.js +119 -0
- package/type/optional/index.d.ts +1 -0
- package/type/optional/index.js +44 -0
- package/type/optional/optional.d.ts +7 -0
- package/type/optional/optional.js +37 -0
- package/type/parameters/index.d.ts +1 -0
- package/type/parameters/index.js +44 -0
- package/type/parameters/parameters.d.ts +7 -0
- package/type/parameters/parameters.js +37 -0
- package/type/partial/index.d.ts +1 -0
- package/type/partial/index.js +44 -0
- package/type/partial/partial.d.ts +23 -0
- package/type/partial/partial.js +73 -0
- package/type/patterns/index.d.ts +1 -0
- package/type/patterns/index.js +44 -0
- package/type/patterns/patterns.d.ts +6 -0
- package/type/patterns/patterns.js +36 -0
- package/type/pick/index.d.ts +1 -0
- package/type/pick/index.js +44 -0
- package/type/pick/pick.d.ts +21 -0
- package/type/pick/pick.js +66 -0
- package/type/promise/index.d.ts +1 -0
- package/type/promise/index.js +44 -0
- package/type/promise/promise.d.ts +11 -0
- package/type/promise/promise.js +42 -0
- package/type/readonly/index.d.ts +1 -0
- package/type/readonly/index.js +44 -0
- package/type/readonly/readonly.d.ts +7 -0
- package/type/readonly/readonly.js +37 -0
- package/type/readonly-optional/index.d.ts +1 -0
- package/type/readonly-optional/index.js +44 -0
- package/type/readonly-optional/readonly-optional.d.ts +6 -0
- package/type/readonly-optional/readonly-optional.js +37 -0
- package/type/record/index.d.ts +1 -0
- package/type/record/index.js +44 -0
- package/type/record/record.d.ts +55 -0
- package/type/record/record.js +97 -0
- package/type/recursive/index.d.ts +1 -0
- package/type/recursive/index.js +44 -0
- package/type/recursive/recursive.d.ts +15 -0
- package/type/recursive/recursive.js +48 -0
- package/type/ref/index.d.ts +1 -0
- package/type/ref/index.js +44 -0
- package/type/ref/ref.d.ts +12 -0
- package/type/ref/ref.js +45 -0
- package/type/regexp/index.d.ts +1 -0
- package/type/regexp/index.js +44 -0
- package/type/regexp/regexp.d.ts +7 -0
- package/type/regexp/regexp.js +38 -0
- package/type/registry/format.d.ts +13 -0
- package/type/registry/format.js +62 -0
- package/type/registry/index.d.ts +2 -0
- package/type/registry/index.js +32 -0
- package/type/registry/type.d.ts +13 -0
- package/type/registry/type.js +62 -0
- package/type/required/index.d.ts +1 -0
- package/type/required/index.js +44 -0
- package/type/required/required.d.ts +23 -0
- package/type/required/required.js +72 -0
- package/type/rest/index.d.ts +1 -0
- package/type/rest/index.js +44 -0
- package/type/rest/rest.d.ts +10 -0
- package/type/rest/rest.js +41 -0
- package/type/return-type/index.d.ts +1 -0
- package/type/return-type/index.js +44 -0
- package/type/return-type/return-type.d.ts +5 -0
- package/type/return-type/return-type.js +36 -0
- package/type/schema/anyschema.d.ts +32 -0
- package/type/schema/anyschema.js +29 -0
- package/type/schema/index.d.ts +2 -0
- package/type/schema/index.js +45 -0
- package/type/schema/schema.d.ts +29 -0
- package/type/schema/schema.js +30 -0
- package/type/static/index.d.ts +1 -0
- package/type/static/index.js +44 -0
- package/type/static/static.d.ts +34 -0
- package/type/static/static.js +29 -0
- package/type/strict/index.d.ts +1 -0
- package/type/strict/index.js +44 -0
- package/type/strict/strict.d.ts +3 -0
- package/type/strict/strict.js +35 -0
- package/type/string/index.d.ts +1 -0
- package/type/string/index.js +44 -0
- package/type/string/string.d.ts +25 -0
- package/type/string/string.js +36 -0
- package/type/symbol/index.d.ts +1 -0
- package/type/symbol/index.js +44 -0
- package/type/symbol/symbol.d.ts +10 -0
- package/type/symbol/symbol.js +36 -0
- package/type/symbols/index.d.ts +1 -0
- package/type/symbols/index.js +44 -0
- package/type/symbols/symbols.d.ts +10 -0
- package/type/symbols/symbols.js +40 -0
- package/type/template-literal/finite.d.ts +16 -0
- package/type/template-literal/finite.js +71 -0
- package/type/template-literal/generate.d.ts +15 -0
- package/type/template-literal/generate.js +74 -0
- package/type/template-literal/index.d.ts +7 -0
- package/type/template-literal/index.js +50 -0
- package/type/template-literal/parser.d.ts +19 -0
- package/type/template-literal/parser.js +175 -0
- package/type/template-literal/pattern.d.ts +4 -0
- package/type/template-literal/pattern.js +61 -0
- package/type/template-literal/syntax.d.ts +20 -0
- package/type/template-literal/syntax.js +87 -0
- package/type/template-literal/template-literal.d.ts +30 -0
- package/type/template-literal/template-literal.js +43 -0
- package/type/template-literal/union.d.ts +7 -0
- package/type/template-literal/union.js +48 -0
- package/type/transform/index.d.ts +1 -0
- package/type/transform/index.js +44 -0
- package/type/transform/transform.d.ts +29 -0
- package/type/transform/transform.js +72 -0
- package/type/tuple/index.d.ts +1 -0
- package/type/tuple/index.js +44 -0
- package/type/tuple/tuple.d.ts +15 -0
- package/type/tuple/tuple.js +42 -0
- package/type/type/index.d.ts +6 -0
- package/type/type/index.js +44 -0
- package/type/type/javascript.d.ts +58 -0
- package/type/type/javascript.js +120 -0
- package/type/type/json.d.ts +139 -0
- package/type/type/json.js +255 -0
- package/type/type/type.d.ts +58 -0
- package/type/type/type.js +153 -0
- package/type/uint8array/index.d.ts +1 -0
- package/type/uint8array/index.js +44 -0
- package/type/uint8array/uint8array.d.ts +13 -0
- package/type/uint8array/uint8array.js +36 -0
- package/type/undefined/index.d.ts +1 -0
- package/type/undefined/index.js +44 -0
- package/type/undefined/undefined.d.ts +9 -0
- package/type/undefined/undefined.js +36 -0
- package/type/union/index.d.ts +1 -0
- package/type/union/index.js +44 -0
- package/type/union/union.d.ts +16 -0
- package/type/union/union.js +50 -0
- package/type/unknown/index.d.ts +1 -0
- package/type/unknown/index.js +44 -0
- package/type/unknown/unknown.d.ts +8 -0
- package/type/unknown/unknown.js +39 -0
- package/type/unsafe/index.d.ts +1 -0
- package/type/unsafe/index.js +44 -0
- package/type/unsafe/unsafe.d.ts +11 -0
- package/type/unsafe/unsafe.js +39 -0
- package/type/void/index.d.ts +1 -0
- package/type/void/index.js +44 -0
- package/type/void/void.d.ts +9 -0
- package/type/void/void.js +40 -0
- package/value/cast/cast.d.ts +23 -0
- package/value/{cast.js → cast/cast.js} +62 -83
- package/value/cast/index.d.ts +1 -0
- package/value/cast/index.js +44 -0
- package/value/check/check.d.ts +10 -0
- package/value/{check.js → check/check.js} +50 -45
- package/value/check/index.d.ts +1 -0
- package/value/check/index.js +44 -0
- package/value/clean/clean.d.ts +5 -0
- package/value/clean/clean.js +167 -0
- package/value/clean/index.d.ts +1 -0
- package/value/clean/index.js +44 -0
- package/value/{clone.js → clone/clone.js} +6 -6
- package/value/clone/index.d.ts +1 -0
- package/value/clone/index.js +44 -0
- package/value/convert/convert.d.ts +9 -0
- package/value/{convert.js → convert/convert.js} +93 -116
- package/value/convert/index.d.ts +1 -0
- package/value/convert/index.js +44 -0
- package/value/create/create.d.ts +31 -0
- package/value/{create.js → create/create.js} +69 -62
- package/value/create/index.d.ts +1 -0
- package/value/create/index.js +44 -0
- package/value/default/default.d.ts +5 -0
- package/value/default/default.js +175 -0
- package/value/default/index.d.ts +1 -0
- package/value/default/index.js +44 -0
- package/value/delta/delta.d.ts +41 -0
- package/value/{delta.js → delta/delta.js} +57 -53
- package/value/delta/index.d.ts +1 -0
- package/value/delta/index.js +44 -0
- package/value/{deref.d.ts → deref/deref.d.ts} +4 -2
- package/value/{deref.js → deref/deref.js} +1 -2
- package/value/deref/index.d.ts +1 -0
- package/value/deref/index.js +44 -0
- package/value/{equal.js → equal/equal.js} +14 -14
- package/value/equal/index.d.ts +1 -0
- package/value/equal/index.js +44 -0
- package/value/guard/index.d.ts +1 -0
- package/value/guard/index.js +44 -0
- package/value/{hash.d.ts → hash/hash.d.ts} +0 -13
- package/value/{hash.js → hash/hash.js} +26 -26
- package/value/hash/index.d.ts +1 -0
- package/value/hash/index.js +44 -0
- package/value/index.d.ts +17 -4
- package/value/index.js +91 -10
- package/value/mutate/index.d.ts +1 -0
- package/value/mutate/index.js +44 -0
- package/value/{mutate.d.ts → mutate/mutate.d.ts} +1 -1
- package/value/{mutate.js → mutate/mutate.js} +25 -25
- package/value/pointer/index.d.ts +1 -0
- package/value/pointer/index.js +31 -0
- package/value/pointer/pointer.d.ts +21 -0
- package/value/pointer/pointer.js +151 -0
- package/value/transform/decode.d.ts +19 -0
- package/value/transform/decode.js +211 -0
- package/value/transform/encode.d.ts +20 -0
- package/value/transform/encode.js +219 -0
- package/value/transform/has.d.ts +3 -0
- package/value/transform/has.js +146 -0
- package/value/transform/index.d.ts +3 -0
- package/value/transform/index.js +46 -0
- package/value/value/index.d.ts +1 -0
- package/value/value/index.js +31 -0
- package/value/value/value.d.ts +53 -0
- package/value/value/value.js +125 -0
- 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/pointer.d.ts +0 -24
- package/value/pointer.js +0 -148
- package/value/transform.d.ts +0 -42
- package/value/transform.js +0 -517
- package/value/value.d.ts +0 -47
- package/value/value.js +0 -117
- /package/value/{clone.d.ts → clone/clone.d.ts} +0 -0
- /package/value/{equal.d.ts → equal/equal.d.ts} +0 -0
- /package/value/{guard.d.ts → guard/guard.d.ts} +0 -0
- /package/value/{guard.js → guard/guard.js} +0 -0
package/value/transform.js
DELETED
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/value
|
|
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
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.EncodeTransform = exports.DecodeTransform = exports.HasTransform = exports.TransformEncodeError = exports.TransformDecodeError = exports.TransformEncodeCheckError = exports.TransformDecodeCheckError = exports.TransformUnknownTypeError = void 0;
|
|
31
|
-
const guard_1 = require("./guard");
|
|
32
|
-
const deref_1 = require("./deref");
|
|
33
|
-
const check_1 = require("./check");
|
|
34
|
-
const Types = require("../typebox");
|
|
35
|
-
// -------------------------------------------------------------------------
|
|
36
|
-
// Errors
|
|
37
|
-
// -------------------------------------------------------------------------
|
|
38
|
-
class TransformUnknownTypeError extends Types.TypeBoxError {
|
|
39
|
-
constructor(schema) {
|
|
40
|
-
super(`Unknown type`);
|
|
41
|
-
this.schema = schema;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.TransformUnknownTypeError = TransformUnknownTypeError;
|
|
45
|
-
class TransformDecodeCheckError extends Types.TypeBoxError {
|
|
46
|
-
constructor(schema, value, error) {
|
|
47
|
-
super(`Unable to decode due to invalid value`);
|
|
48
|
-
this.schema = schema;
|
|
49
|
-
this.value = value;
|
|
50
|
-
this.error = error;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.TransformDecodeCheckError = TransformDecodeCheckError;
|
|
54
|
-
class TransformEncodeCheckError extends Types.TypeBoxError {
|
|
55
|
-
constructor(schema, value, error) {
|
|
56
|
-
super(`Unable to encode due to invalid value`);
|
|
57
|
-
this.schema = schema;
|
|
58
|
-
this.value = value;
|
|
59
|
-
this.error = error;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.TransformEncodeCheckError = TransformEncodeCheckError;
|
|
63
|
-
class TransformDecodeError extends Types.TypeBoxError {
|
|
64
|
-
constructor(schema, value, error) {
|
|
65
|
-
super(`${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
66
|
-
this.schema = schema;
|
|
67
|
-
this.value = value;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.TransformDecodeError = TransformDecodeError;
|
|
71
|
-
class TransformEncodeError extends Types.TypeBoxError {
|
|
72
|
-
constructor(schema, value, error) {
|
|
73
|
-
super(`${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
74
|
-
this.schema = schema;
|
|
75
|
-
this.value = value;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.TransformEncodeError = TransformEncodeError;
|
|
79
|
-
// -------------------------------------------------------------------------
|
|
80
|
-
// HasTransform
|
|
81
|
-
// -------------------------------------------------------------------------
|
|
82
|
-
/** Recursively checks a schema for transform codecs */
|
|
83
|
-
var HasTransform;
|
|
84
|
-
(function (HasTransform) {
|
|
85
|
-
function TArray(schema, references) {
|
|
86
|
-
return Types.TypeGuard.TTransform(schema) || Visit(schema.items, references);
|
|
87
|
-
}
|
|
88
|
-
function TAsyncIterator(schema, references) {
|
|
89
|
-
return Types.TypeGuard.TTransform(schema) || Visit(schema.items, references);
|
|
90
|
-
}
|
|
91
|
-
function TConstructor(schema, references) {
|
|
92
|
-
return Types.TypeGuard.TTransform(schema) || Visit(schema.returns, references) || schema.parameters.some((schema) => Visit(schema, references));
|
|
93
|
-
}
|
|
94
|
-
function TFunction(schema, references) {
|
|
95
|
-
return Types.TypeGuard.TTransform(schema) || Visit(schema.returns, references) || schema.parameters.some((schema) => Visit(schema, references));
|
|
96
|
-
}
|
|
97
|
-
function TIntersect(schema, references) {
|
|
98
|
-
return Types.TypeGuard.TTransform(schema) || Types.TypeGuard.TTransform(schema.unevaluatedProperties) || schema.allOf.some((schema) => Visit(schema, references));
|
|
99
|
-
}
|
|
100
|
-
function TIterator(schema, references) {
|
|
101
|
-
return Types.TypeGuard.TTransform(schema) || Visit(schema.items, references);
|
|
102
|
-
}
|
|
103
|
-
function TNot(schema, references) {
|
|
104
|
-
return Types.TypeGuard.TTransform(schema) || Visit(schema.not, references);
|
|
105
|
-
}
|
|
106
|
-
function TObject(schema, references) {
|
|
107
|
-
// prettier-ignore
|
|
108
|
-
return (Types.TypeGuard.TTransform(schema) || Object.values(schema.properties).some((schema) => Visit(schema, references)) || Types.TypeGuard.TSchema(schema.additionalProperties) && Visit(schema.additionalProperties, references));
|
|
109
|
-
}
|
|
110
|
-
function TPromise(schema, references) {
|
|
111
|
-
return Types.TypeGuard.TTransform(schema) || Visit(schema.item, references);
|
|
112
|
-
}
|
|
113
|
-
function TRecord(schema, references) {
|
|
114
|
-
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
115
|
-
const property = schema.patternProperties[pattern];
|
|
116
|
-
return Types.TypeGuard.TTransform(schema) || Visit(property, references) || (Types.TypeGuard.TSchema(schema.additionalProperties) && Types.TypeGuard.TTransform(schema.additionalProperties));
|
|
117
|
-
}
|
|
118
|
-
function TRef(schema, references) {
|
|
119
|
-
if (Types.TypeGuard.TTransform(schema))
|
|
120
|
-
return true;
|
|
121
|
-
return Visit((0, deref_1.Deref)(schema, references), references);
|
|
122
|
-
}
|
|
123
|
-
function TThis(schema, references) {
|
|
124
|
-
if (Types.TypeGuard.TTransform(schema))
|
|
125
|
-
return true;
|
|
126
|
-
return Visit((0, deref_1.Deref)(schema, references), references);
|
|
127
|
-
}
|
|
128
|
-
function TTuple(schema, references) {
|
|
129
|
-
return Types.TypeGuard.TTransform(schema) || (!(0, guard_1.IsUndefined)(schema.items) && schema.items.some((schema) => Visit(schema, references)));
|
|
130
|
-
}
|
|
131
|
-
function TUnion(schema, references) {
|
|
132
|
-
return Types.TypeGuard.TTransform(schema) || schema.anyOf.some((schema) => Visit(schema, references));
|
|
133
|
-
}
|
|
134
|
-
function Visit(schema, references) {
|
|
135
|
-
const references_ = (0, guard_1.IsString)(schema.$id) ? [...references, schema] : references;
|
|
136
|
-
const schema_ = schema;
|
|
137
|
-
if (schema.$id && visited.has(schema.$id))
|
|
138
|
-
return false;
|
|
139
|
-
if (schema.$id)
|
|
140
|
-
visited.add(schema.$id);
|
|
141
|
-
switch (schema[Types.Kind]) {
|
|
142
|
-
// ------------------------------------------------------
|
|
143
|
-
// Structural
|
|
144
|
-
// ------------------------------------------------------
|
|
145
|
-
case 'Array':
|
|
146
|
-
return TArray(schema_, references_);
|
|
147
|
-
case 'AsyncIterator':
|
|
148
|
-
return TAsyncIterator(schema_, references_);
|
|
149
|
-
case 'Constructor':
|
|
150
|
-
return TConstructor(schema_, references_);
|
|
151
|
-
case 'Function':
|
|
152
|
-
return TFunction(schema_, references_);
|
|
153
|
-
case 'Intersect':
|
|
154
|
-
return TIntersect(schema_, references_);
|
|
155
|
-
case 'Iterator':
|
|
156
|
-
return TIterator(schema_, references_);
|
|
157
|
-
case 'Not':
|
|
158
|
-
return TNot(schema_, references_);
|
|
159
|
-
case 'Object':
|
|
160
|
-
return TObject(schema_, references_);
|
|
161
|
-
case 'Promise':
|
|
162
|
-
return TPromise(schema_, references_);
|
|
163
|
-
case 'Record':
|
|
164
|
-
return TRecord(schema_, references_);
|
|
165
|
-
case 'Ref':
|
|
166
|
-
return TRef(schema_, references_);
|
|
167
|
-
case 'This':
|
|
168
|
-
return TThis(schema_, references_);
|
|
169
|
-
case 'Tuple':
|
|
170
|
-
return TTuple(schema_, references_);
|
|
171
|
-
case 'Union':
|
|
172
|
-
return TUnion(schema_, references_);
|
|
173
|
-
// ------------------------------------------------------
|
|
174
|
-
// Default
|
|
175
|
-
// ------------------------------------------------------
|
|
176
|
-
case 'Any':
|
|
177
|
-
case 'BigInt':
|
|
178
|
-
case 'Boolean':
|
|
179
|
-
case 'Date':
|
|
180
|
-
case 'Integer':
|
|
181
|
-
case 'Literal':
|
|
182
|
-
case 'Never':
|
|
183
|
-
case 'Null':
|
|
184
|
-
case 'Number':
|
|
185
|
-
case 'String':
|
|
186
|
-
case 'Symbol':
|
|
187
|
-
case 'TemplateLiteral':
|
|
188
|
-
case 'Undefined':
|
|
189
|
-
case 'Uint8Array':
|
|
190
|
-
case 'Unknown':
|
|
191
|
-
case 'Void':
|
|
192
|
-
return Types.TypeGuard.TTransform(schema);
|
|
193
|
-
default:
|
|
194
|
-
if (!Types.TypeRegistry.Has(schema_[Types.Kind]))
|
|
195
|
-
throw new TransformUnknownTypeError(schema_);
|
|
196
|
-
return Types.TypeGuard.TTransform(schema);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
const visited = new Set();
|
|
200
|
-
/** Returns true if this schema contains a transform codec */
|
|
201
|
-
function Has(schema, references) {
|
|
202
|
-
visited.clear();
|
|
203
|
-
return Visit(schema, references);
|
|
204
|
-
}
|
|
205
|
-
HasTransform.Has = Has;
|
|
206
|
-
})(HasTransform || (exports.HasTransform = HasTransform = {}));
|
|
207
|
-
// -------------------------------------------------------------------------
|
|
208
|
-
// DecodeTransform
|
|
209
|
-
// -------------------------------------------------------------------------
|
|
210
|
-
/** Decodes a value using transform decoders if available. Does not ensure correct results. */
|
|
211
|
-
var DecodeTransform;
|
|
212
|
-
(function (DecodeTransform) {
|
|
213
|
-
function Default(schema, value) {
|
|
214
|
-
try {
|
|
215
|
-
return Types.TypeGuard.TTransform(schema) ? schema[Types.Transform].Decode(value) : value;
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
throw new TransformDecodeError(schema, value, error);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
function TArray(schema, references, value) {
|
|
222
|
-
const elements1 = value.map((value) => Visit(schema.items, references, value));
|
|
223
|
-
return Default(schema, elements1);
|
|
224
|
-
}
|
|
225
|
-
function TIntersect(schema, references, value) {
|
|
226
|
-
if (!(0, guard_1.IsPlainObject)(value) || (0, guard_1.IsValueType)(value))
|
|
227
|
-
return Default(schema, value);
|
|
228
|
-
const keys = Types.KeyResolver.ResolveKeys(schema, { includePatterns: false });
|
|
229
|
-
const properties1 = Object.entries(value).reduce((acc, [key, value]) => {
|
|
230
|
-
return !keys.includes(key) ? { ...acc, [key]: value } : { ...acc, [key]: Default(Types.IndexedAccessor.Resolve(schema, [key]), value) };
|
|
231
|
-
}, {});
|
|
232
|
-
if (!Types.TypeGuard.TTransform(schema.unevaluatedProperties))
|
|
233
|
-
return Default(schema, properties1);
|
|
234
|
-
const properties2 = Object.entries(properties1).reduce((acc, [key, value]) => {
|
|
235
|
-
return keys.includes(key) ? { ...acc, [key]: value } : { ...acc, [key]: Default(schema.unevaluatedProperties, value) };
|
|
236
|
-
}, {});
|
|
237
|
-
return Default(schema, properties2);
|
|
238
|
-
}
|
|
239
|
-
function TNot(schema, references, value) {
|
|
240
|
-
const value1 = Visit(schema.not, references, value);
|
|
241
|
-
return Default(schema, value1);
|
|
242
|
-
}
|
|
243
|
-
function TObject(schema, references, value) {
|
|
244
|
-
if (!(0, guard_1.IsPlainObject)(value))
|
|
245
|
-
return Default(schema, value);
|
|
246
|
-
const properties1 = Object.entries(value).reduce((acc, [key, value]) => {
|
|
247
|
-
return !(key in schema.properties) ? { ...acc, [key]: value } : { ...acc, [key]: Visit(schema.properties[key], references, value) };
|
|
248
|
-
}, {});
|
|
249
|
-
if (!Types.TypeGuard.TSchema(schema.additionalProperties))
|
|
250
|
-
return Default(schema, properties1);
|
|
251
|
-
const additionalProperties = schema.additionalProperties;
|
|
252
|
-
const properties2 = Object.entries(properties1).reduce((acc, [key, value]) => {
|
|
253
|
-
return key in schema.properties ? { ...acc, [key]: value } : { ...acc, [key]: Visit(additionalProperties, references, value) };
|
|
254
|
-
}, {});
|
|
255
|
-
return Default(schema, properties2);
|
|
256
|
-
}
|
|
257
|
-
function TRecord(schema, references, value) {
|
|
258
|
-
if (!(0, guard_1.IsPlainObject)(value))
|
|
259
|
-
return Default(schema, value);
|
|
260
|
-
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
261
|
-
const property = schema.patternProperties[pattern];
|
|
262
|
-
const regex = new RegExp(pattern);
|
|
263
|
-
const properties1 = Object.entries(value).reduce((acc, [key, value]) => {
|
|
264
|
-
return !regex.test(key) ? { ...acc, [key]: value } : { ...acc, [key]: Visit(property, references, value) };
|
|
265
|
-
}, {});
|
|
266
|
-
if (!Types.TypeGuard.TSchema(schema.additionalProperties))
|
|
267
|
-
return Default(schema, properties1);
|
|
268
|
-
const additionalProperties = schema.additionalProperties;
|
|
269
|
-
const properties2 = Object.entries(properties1).reduce((acc, [key, value]) => {
|
|
270
|
-
return regex.test(key) ? { ...acc, [key]: value } : { ...acc, [key]: Visit(additionalProperties, references, value) };
|
|
271
|
-
}, {});
|
|
272
|
-
return Default(schema, properties2);
|
|
273
|
-
}
|
|
274
|
-
function TRef(schema, references, value) {
|
|
275
|
-
const target = (0, deref_1.Deref)(schema, references);
|
|
276
|
-
const resolved = Visit(target, references, value);
|
|
277
|
-
return Default(schema, resolved);
|
|
278
|
-
}
|
|
279
|
-
function TThis(schema, references, value) {
|
|
280
|
-
const target = (0, deref_1.Deref)(schema, references);
|
|
281
|
-
const resolved = Visit(target, references, value);
|
|
282
|
-
return Default(schema, resolved);
|
|
283
|
-
}
|
|
284
|
-
function TTuple(schema, references, value) {
|
|
285
|
-
const value1 = (0, guard_1.IsArray)(schema.items) ? schema.items.map((schema, index) => Visit(schema, references, value[index])) : [];
|
|
286
|
-
return Default(schema, value1);
|
|
287
|
-
}
|
|
288
|
-
function TUnion(schema, references, value) {
|
|
289
|
-
const value1 = Default(schema, value);
|
|
290
|
-
for (const subschema of schema.anyOf) {
|
|
291
|
-
if (!(0, check_1.Check)(subschema, references, value1))
|
|
292
|
-
continue;
|
|
293
|
-
return Visit(subschema, references, value1);
|
|
294
|
-
}
|
|
295
|
-
return value1;
|
|
296
|
-
}
|
|
297
|
-
function Visit(schema, references, value) {
|
|
298
|
-
const references_ = typeof schema.$id === 'string' ? [...references, schema] : references;
|
|
299
|
-
const schema_ = schema;
|
|
300
|
-
switch (schema[Types.Kind]) {
|
|
301
|
-
// ------------------------------------------------------
|
|
302
|
-
// Structural
|
|
303
|
-
// ------------------------------------------------------
|
|
304
|
-
case 'Array':
|
|
305
|
-
return TArray(schema_, references_, value);
|
|
306
|
-
case 'Intersect':
|
|
307
|
-
return TIntersect(schema_, references_, value);
|
|
308
|
-
case 'Not':
|
|
309
|
-
return TNot(schema_, references_, value);
|
|
310
|
-
case 'Object':
|
|
311
|
-
return TObject(schema_, references_, value);
|
|
312
|
-
case 'Record':
|
|
313
|
-
return TRecord(schema_, references_, value);
|
|
314
|
-
case 'Ref':
|
|
315
|
-
return TRef(schema_, references_, value);
|
|
316
|
-
case 'Symbol':
|
|
317
|
-
return Default(schema_, value);
|
|
318
|
-
case 'This':
|
|
319
|
-
return TThis(schema_, references_, value);
|
|
320
|
-
case 'Tuple':
|
|
321
|
-
return TTuple(schema_, references_, value);
|
|
322
|
-
case 'Union':
|
|
323
|
-
return TUnion(schema_, references_, value);
|
|
324
|
-
// ------------------------------------------------------
|
|
325
|
-
// Default
|
|
326
|
-
// ------------------------------------------------------
|
|
327
|
-
case 'Any':
|
|
328
|
-
case 'AsyncIterator':
|
|
329
|
-
case 'BigInt':
|
|
330
|
-
case 'Boolean':
|
|
331
|
-
case 'Constructor':
|
|
332
|
-
case 'Date':
|
|
333
|
-
case 'Function':
|
|
334
|
-
case 'Integer':
|
|
335
|
-
case 'Iterator':
|
|
336
|
-
case 'Literal':
|
|
337
|
-
case 'Never':
|
|
338
|
-
case 'Null':
|
|
339
|
-
case 'Number':
|
|
340
|
-
case 'Promise':
|
|
341
|
-
case 'String':
|
|
342
|
-
case 'TemplateLiteral':
|
|
343
|
-
case 'Undefined':
|
|
344
|
-
case 'Uint8Array':
|
|
345
|
-
case 'Unknown':
|
|
346
|
-
case 'Void':
|
|
347
|
-
return Default(schema_, value);
|
|
348
|
-
default:
|
|
349
|
-
if (!Types.TypeRegistry.Has(schema_[Types.Kind]))
|
|
350
|
-
throw new TransformUnknownTypeError(schema_);
|
|
351
|
-
return Default(schema_, value);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
function Decode(schema, references, value) {
|
|
355
|
-
return Visit(schema, references, value);
|
|
356
|
-
}
|
|
357
|
-
DecodeTransform.Decode = Decode;
|
|
358
|
-
})(DecodeTransform || (exports.DecodeTransform = DecodeTransform = {}));
|
|
359
|
-
// -------------------------------------------------------------------------
|
|
360
|
-
// DecodeTransform
|
|
361
|
-
// -------------------------------------------------------------------------
|
|
362
|
-
/** Encodes a value using transform encoders if available. Does not ensure correct results. */
|
|
363
|
-
var EncodeTransform;
|
|
364
|
-
(function (EncodeTransform) {
|
|
365
|
-
function Default(schema, value) {
|
|
366
|
-
try {
|
|
367
|
-
return Types.TypeGuard.TTransform(schema) ? schema[Types.Transform].Encode(value) : value;
|
|
368
|
-
}
|
|
369
|
-
catch (error) {
|
|
370
|
-
throw new TransformEncodeError(schema, value, error);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
function TArray(schema, references, value) {
|
|
374
|
-
const elements1 = Default(schema, value);
|
|
375
|
-
return elements1.map((value) => Visit(schema.items, references, value));
|
|
376
|
-
}
|
|
377
|
-
function TIntersect(schema, references, value) {
|
|
378
|
-
const properties1 = Default(schema, value);
|
|
379
|
-
if (!(0, guard_1.IsPlainObject)(value) || (0, guard_1.IsValueType)(value))
|
|
380
|
-
return properties1;
|
|
381
|
-
const keys = Types.KeyResolver.ResolveKeys(schema, { includePatterns: false });
|
|
382
|
-
const properties2 = Object.entries(properties1).reduce((acc, [key, value]) => {
|
|
383
|
-
return !keys.includes(key) ? { ...acc, [key]: value } : { ...acc, [key]: Default(Types.IndexedAccessor.Resolve(schema, [key]), value) };
|
|
384
|
-
}, {});
|
|
385
|
-
if (!Types.TypeGuard.TTransform(schema.unevaluatedProperties))
|
|
386
|
-
return Default(schema, properties2);
|
|
387
|
-
return Object.entries(properties2).reduce((acc, [key, value]) => {
|
|
388
|
-
return keys.includes(key) ? { ...acc, [key]: value } : { ...acc, [key]: Default(schema.unevaluatedProperties, value) };
|
|
389
|
-
}, {});
|
|
390
|
-
}
|
|
391
|
-
function TNot(schema, references, value) {
|
|
392
|
-
const value1 = Default(schema, value);
|
|
393
|
-
return Default(schema.not, value1);
|
|
394
|
-
}
|
|
395
|
-
function TObject(schema, references, value) {
|
|
396
|
-
const properties1 = Default(schema, value);
|
|
397
|
-
if (!(0, guard_1.IsPlainObject)(value))
|
|
398
|
-
return properties1;
|
|
399
|
-
const properties2 = Object.entries(properties1).reduce((acc, [key, value]) => {
|
|
400
|
-
return !(key in schema.properties) ? { ...acc, [key]: value } : { ...acc, [key]: Visit(schema.properties[key], references, value) };
|
|
401
|
-
}, {});
|
|
402
|
-
if (!Types.TypeGuard.TSchema(schema.additionalProperties))
|
|
403
|
-
return properties2;
|
|
404
|
-
const additionalProperties = schema.additionalProperties;
|
|
405
|
-
return Object.entries(properties2).reduce((acc, [key, value]) => {
|
|
406
|
-
return key in schema.properties ? { ...acc, [key]: value } : { ...acc, [key]: Visit(additionalProperties, references, value) };
|
|
407
|
-
}, {});
|
|
408
|
-
}
|
|
409
|
-
function TRecord(schema, references, value) {
|
|
410
|
-
const properties1 = Default(schema, value);
|
|
411
|
-
if (!(0, guard_1.IsPlainObject)(value))
|
|
412
|
-
return properties1;
|
|
413
|
-
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
414
|
-
const property = schema.patternProperties[pattern];
|
|
415
|
-
const regex = new RegExp(pattern);
|
|
416
|
-
const properties2 = Object.entries(properties1).reduce((acc, [key, value]) => {
|
|
417
|
-
return !regex.test(key) ? { ...acc, [key]: value } : { ...acc, [key]: Visit(property, references, value) };
|
|
418
|
-
}, {});
|
|
419
|
-
if (!Types.TypeGuard.TSchema(schema.additionalProperties))
|
|
420
|
-
return Default(schema, properties2);
|
|
421
|
-
const additionalProperties = schema.additionalProperties;
|
|
422
|
-
return Object.entries(properties2).reduce((acc, [key, value]) => {
|
|
423
|
-
return regex.test(key) ? { ...acc, [key]: value } : { ...acc, [key]: Visit(additionalProperties, references, value) };
|
|
424
|
-
}, {});
|
|
425
|
-
}
|
|
426
|
-
function TRef(schema, references, value) {
|
|
427
|
-
const target = (0, deref_1.Deref)(schema, references);
|
|
428
|
-
const resolved = Visit(target, references, value);
|
|
429
|
-
return Default(schema, resolved);
|
|
430
|
-
}
|
|
431
|
-
function TThis(schema, references, value) {
|
|
432
|
-
const target = (0, deref_1.Deref)(schema, references);
|
|
433
|
-
const resolved = Visit(target, references, value);
|
|
434
|
-
return Default(schema, resolved);
|
|
435
|
-
}
|
|
436
|
-
function TTuple(schema, references, value) {
|
|
437
|
-
const value1 = Default(schema, value);
|
|
438
|
-
return (0, guard_1.IsArray)(schema.items) ? schema.items.map((schema, index) => Visit(schema, references, value1[index])) : [];
|
|
439
|
-
}
|
|
440
|
-
function TUnion(schema, references, value) {
|
|
441
|
-
// test value against union variants
|
|
442
|
-
for (const subschema of schema.anyOf) {
|
|
443
|
-
if (!(0, check_1.Check)(subschema, references, value))
|
|
444
|
-
continue;
|
|
445
|
-
const value1 = Visit(subschema, references, value);
|
|
446
|
-
return Default(schema, value1);
|
|
447
|
-
}
|
|
448
|
-
// test transformed value against union variants
|
|
449
|
-
for (const subschema of schema.anyOf) {
|
|
450
|
-
const value1 = Visit(subschema, references, value);
|
|
451
|
-
if (!(0, check_1.Check)(schema, references, value1))
|
|
452
|
-
continue;
|
|
453
|
-
return Default(schema, value1);
|
|
454
|
-
}
|
|
455
|
-
return Default(schema, value);
|
|
456
|
-
}
|
|
457
|
-
function Visit(schema, references, value) {
|
|
458
|
-
const references_ = typeof schema.$id === 'string' ? [...references, schema] : references;
|
|
459
|
-
const schema_ = schema;
|
|
460
|
-
switch (schema[Types.Kind]) {
|
|
461
|
-
// ------------------------------------------------------
|
|
462
|
-
// Structural
|
|
463
|
-
// ------------------------------------------------------
|
|
464
|
-
case 'Array':
|
|
465
|
-
return TArray(schema_, references_, value);
|
|
466
|
-
case 'Intersect':
|
|
467
|
-
return TIntersect(schema_, references_, value);
|
|
468
|
-
case 'Not':
|
|
469
|
-
return TNot(schema_, references_, value);
|
|
470
|
-
case 'Object':
|
|
471
|
-
return TObject(schema_, references_, value);
|
|
472
|
-
case 'Record':
|
|
473
|
-
return TRecord(schema_, references_, value);
|
|
474
|
-
case 'Ref':
|
|
475
|
-
return TRef(schema_, references_, value);
|
|
476
|
-
case 'This':
|
|
477
|
-
return TThis(schema_, references_, value);
|
|
478
|
-
case 'Tuple':
|
|
479
|
-
return TTuple(schema_, references_, value);
|
|
480
|
-
case 'Union':
|
|
481
|
-
return TUnion(schema_, references_, value);
|
|
482
|
-
// ------------------------------------------------------
|
|
483
|
-
// Apply
|
|
484
|
-
// ------------------------------------------------------
|
|
485
|
-
case 'Any':
|
|
486
|
-
case 'AsyncIterator':
|
|
487
|
-
case 'BigInt':
|
|
488
|
-
case 'Boolean':
|
|
489
|
-
case 'Constructor':
|
|
490
|
-
case 'Date':
|
|
491
|
-
case 'Function':
|
|
492
|
-
case 'Integer':
|
|
493
|
-
case 'Iterator':
|
|
494
|
-
case 'Literal':
|
|
495
|
-
case 'Never':
|
|
496
|
-
case 'Null':
|
|
497
|
-
case 'Number':
|
|
498
|
-
case 'Promise':
|
|
499
|
-
case 'String':
|
|
500
|
-
case 'Symbol':
|
|
501
|
-
case 'TemplateLiteral':
|
|
502
|
-
case 'Undefined':
|
|
503
|
-
case 'Uint8Array':
|
|
504
|
-
case 'Unknown':
|
|
505
|
-
case 'Void':
|
|
506
|
-
return Default(schema_, value);
|
|
507
|
-
default:
|
|
508
|
-
if (!Types.TypeRegistry.Has(schema_[Types.Kind]))
|
|
509
|
-
throw new TransformUnknownTypeError(schema_);
|
|
510
|
-
return Default(schema_, value);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
function Encode(schema, references, value) {
|
|
514
|
-
return Visit(schema, references, value);
|
|
515
|
-
}
|
|
516
|
-
EncodeTransform.Encode = Encode;
|
|
517
|
-
})(EncodeTransform || (exports.EncodeTransform = EncodeTransform = {}));
|
package/value/value.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as ValueErrors from '../errors/index';
|
|
2
|
-
import * as ValueMutate from './mutate';
|
|
3
|
-
import * as ValueDelta from './delta';
|
|
4
|
-
import * as Types from '../typebox';
|
|
5
|
-
/** Functions to perform structural operations on JavaScript values */
|
|
6
|
-
export declare namespace Value {
|
|
7
|
-
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
|
|
8
|
-
function Cast<T extends Types.TSchema>(schema: T, references: Types.TSchema[], value: unknown): Types.Static<T>;
|
|
9
|
-
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
|
|
10
|
-
function Cast<T extends Types.TSchema>(schema: T, value: unknown): Types.Static<T>;
|
|
11
|
-
/** Creates a value from the given type and references */
|
|
12
|
-
function Create<T extends Types.TSchema>(schema: T, references: Types.TSchema[]): Types.Static<T>;
|
|
13
|
-
/** Creates a value from the given type */
|
|
14
|
-
function Create<T extends Types.TSchema>(schema: T): Types.Static<T>;
|
|
15
|
-
/** Returns true if the value matches the given type and references */
|
|
16
|
-
function Check<T extends Types.TSchema>(schema: T, references: Types.TSchema[], value: unknown): value is Types.Static<T>;
|
|
17
|
-
/** Returns true if the value matches the given type */
|
|
18
|
-
function Check<T extends Types.TSchema>(schema: T, value: unknown): value is Types.Static<T>;
|
|
19
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
20
|
-
function Convert<T extends Types.TSchema>(schema: T, references: Types.TSchema[], value: unknown): unknown;
|
|
21
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possibl. */
|
|
22
|
-
function Convert<T extends Types.TSchema>(schema: T, value: unknown): unknown;
|
|
23
|
-
/** Returns a structural clone of the given value */
|
|
24
|
-
function Clone<T>(value: T): T;
|
|
25
|
-
/** Decodes a value or throws if error */
|
|
26
|
-
function Decode<T extends Types.TSchema, R = Types.StaticDecode<T>>(schema: T, references: Types.TSchema[], value: unknown): R;
|
|
27
|
-
/** Decodes a value or throws if error */
|
|
28
|
-
function Decode<T extends Types.TSchema, R = Types.StaticDecode<T>>(schema: T, value: unknown): R;
|
|
29
|
-
/** Encodes a value or throws if error */
|
|
30
|
-
function Encode<T extends Types.TSchema, R = Types.StaticEncode<T>>(schema: T, references: Types.TSchema[], value: unknown): R;
|
|
31
|
-
/** Encodes a value or throws if error */
|
|
32
|
-
function Encode<T extends Types.TSchema, R = Types.StaticEncode<T>>(schema: T, value: unknown): R;
|
|
33
|
-
/** Returns an iterator for each error in this value. */
|
|
34
|
-
function Errors<T extends Types.TSchema>(schema: T, references: Types.TSchema[], value: unknown): ValueErrors.ValueErrorIterator;
|
|
35
|
-
/** Returns an iterator for each error in this value. */
|
|
36
|
-
function Errors<T extends Types.TSchema>(schema: T, value: unknown): ValueErrors.ValueErrorIterator;
|
|
37
|
-
/** Returns true if left and right values are structurally equal */
|
|
38
|
-
function Equal<T>(left: T, right: unknown): right is T;
|
|
39
|
-
/** Returns edits to transform the current value into the next value */
|
|
40
|
-
function Diff(current: unknown, next: unknown): ValueDelta.Edit[];
|
|
41
|
-
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
42
|
-
function Hash(value: unknown): bigint;
|
|
43
|
-
/** Returns a new value with edits applied to the given value */
|
|
44
|
-
function Patch<T = any>(current: unknown, edits: ValueDelta.Edit[]): T;
|
|
45
|
-
/** Performs a deep mutable value assignment while retaining internal references. */
|
|
46
|
-
function Mutate(current: ValueMutate.Mutable, next: ValueMutate.Mutable): void;
|
|
47
|
-
}
|
package/value/value.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/value
|
|
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
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Value = void 0;
|
|
31
|
-
const ValueErrors = require("../errors/index");
|
|
32
|
-
const ValueMutate = require("./mutate");
|
|
33
|
-
const ValueHash = require("./hash");
|
|
34
|
-
const ValueEqual = require("./equal");
|
|
35
|
-
const ValueCast = require("./cast");
|
|
36
|
-
const ValueClone = require("./clone");
|
|
37
|
-
const ValueConvert = require("./convert");
|
|
38
|
-
const ValueCreate = require("./create");
|
|
39
|
-
const ValueCheck = require("./check");
|
|
40
|
-
const ValueDelta = require("./delta");
|
|
41
|
-
const ValueTransform = require("./transform");
|
|
42
|
-
/** Functions to perform structural operations on JavaScript values */
|
|
43
|
-
var Value;
|
|
44
|
-
(function (Value) {
|
|
45
|
-
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
|
|
46
|
-
function Cast(...args) {
|
|
47
|
-
return ValueCast.Cast.apply(ValueCast, args);
|
|
48
|
-
}
|
|
49
|
-
Value.Cast = Cast;
|
|
50
|
-
/** Creates a value from the given type */
|
|
51
|
-
function Create(...args) {
|
|
52
|
-
return ValueCreate.Create.apply(ValueCreate, args);
|
|
53
|
-
}
|
|
54
|
-
Value.Create = Create;
|
|
55
|
-
/** Returns true if the value matches the given type */
|
|
56
|
-
function Check(...args) {
|
|
57
|
-
return ValueCheck.Check.apply(ValueCheck, args);
|
|
58
|
-
}
|
|
59
|
-
Value.Check = Check;
|
|
60
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
61
|
-
function Convert(...args) {
|
|
62
|
-
return ValueConvert.Convert.apply(ValueConvert, args);
|
|
63
|
-
}
|
|
64
|
-
Value.Convert = Convert;
|
|
65
|
-
/** Returns a structural clone of the given value */
|
|
66
|
-
function Clone(value) {
|
|
67
|
-
return ValueClone.Clone(value);
|
|
68
|
-
}
|
|
69
|
-
Value.Clone = Clone;
|
|
70
|
-
/** Decodes a value or throws if error */
|
|
71
|
-
function Decode(...args) {
|
|
72
|
-
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
73
|
-
if (!Check(schema, references, value))
|
|
74
|
-
throw new ValueTransform.TransformDecodeCheckError(schema, value, Errors(schema, references, value).First());
|
|
75
|
-
return ValueTransform.DecodeTransform.Decode(schema, references, value);
|
|
76
|
-
}
|
|
77
|
-
Value.Decode = Decode;
|
|
78
|
-
/** Encodes a value or throws if error */
|
|
79
|
-
function Encode(...args) {
|
|
80
|
-
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
81
|
-
const encoded = ValueTransform.EncodeTransform.Encode(schema, references, value);
|
|
82
|
-
if (!Check(schema, references, encoded))
|
|
83
|
-
throw new ValueTransform.TransformEncodeCheckError(schema, value, Errors(schema, references, value).First());
|
|
84
|
-
return encoded;
|
|
85
|
-
}
|
|
86
|
-
Value.Encode = Encode;
|
|
87
|
-
/** Returns an iterator for each error in this value. */
|
|
88
|
-
function Errors(...args) {
|
|
89
|
-
return ValueErrors.Errors.apply(ValueErrors, args);
|
|
90
|
-
}
|
|
91
|
-
Value.Errors = Errors;
|
|
92
|
-
/** Returns true if left and right values are structurally equal */
|
|
93
|
-
function Equal(left, right) {
|
|
94
|
-
return ValueEqual.Equal(left, right);
|
|
95
|
-
}
|
|
96
|
-
Value.Equal = Equal;
|
|
97
|
-
/** Returns edits to transform the current value into the next value */
|
|
98
|
-
function Diff(current, next) {
|
|
99
|
-
return ValueDelta.Diff(current, next);
|
|
100
|
-
}
|
|
101
|
-
Value.Diff = Diff;
|
|
102
|
-
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
103
|
-
function Hash(value) {
|
|
104
|
-
return ValueHash.Hash(value);
|
|
105
|
-
}
|
|
106
|
-
Value.Hash = Hash;
|
|
107
|
-
/** Returns a new value with edits applied to the given value */
|
|
108
|
-
function Patch(current, edits) {
|
|
109
|
-
return ValueDelta.Patch(current, edits);
|
|
110
|
-
}
|
|
111
|
-
Value.Patch = Patch;
|
|
112
|
-
/** Performs a deep mutable value assignment while retaining internal references. */
|
|
113
|
-
function Mutate(current, next) {
|
|
114
|
-
ValueMutate.Mutate(current, next);
|
|
115
|
-
}
|
|
116
|
-
Value.Mutate = Mutate;
|
|
117
|
-
})(Value || (exports.Value = Value = {}));
|
|
File without changes
|