@sinclair/typebox 0.32.0-dev-4 → 0.32.0-dev-5
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.mjs +571 -0
- package/build/import/compiler/index.mjs +2 -0
- package/build/import/errors/errors.mjs +531 -0
- package/build/import/errors/index.mjs +1 -0
- package/build/import/index.mjs +69 -0
- package/build/import/system/errors.mjs +150 -0
- package/build/import/system/index.mjs +4 -0
- package/build/import/system/policy.mjs +31 -0
- package/build/import/system/system.mjs +30 -0
- package/build/import/type/any/any.mjs +4 -0
- package/build/import/type/any/index.mjs +1 -0
- package/build/import/type/array/array.mjs +10 -0
- package/build/import/type/array/index.mjs +1 -0
- package/build/import/type/async-iterator/async-iterator.mjs +10 -0
- package/build/import/type/async-iterator/index.mjs +1 -0
- package/build/import/type/awaited/awaited.mjs +28 -0
- package/build/import/type/awaited/index.mjs +1 -0
- package/build/import/type/bigint/bigint.mjs +8 -0
- package/build/import/type/bigint/index.mjs +1 -0
- package/build/import/type/boolean/boolean.mjs +8 -0
- package/build/import/type/boolean/index.mjs +1 -0
- package/build/import/type/clone/index.mjs +2 -0
- package/build/import/type/clone/type.mjs +7 -0
- package/build/import/type/clone/value.mjs +25 -0
- package/build/import/type/composite/composite.mjs +14 -0
- package/build/import/type/composite/index.mjs +1 -0
- package/build/import/type/const/const.mjs +49 -0
- package/build/import/type/const/index.mjs +1 -0
- package/build/import/type/constructor/constructor.mjs +11 -0
- package/build/import/type/constructor/index.mjs +1 -0
- package/build/import/type/constructor-parameters/constructor-parameters.mjs +5 -0
- package/build/import/type/constructor-parameters/index.mjs +1 -0
- package/build/import/type/date/date.mjs +8 -0
- package/build/import/type/date/index.mjs +1 -0
- package/build/import/type/deref/deref.mjs +90 -0
- package/build/import/type/deref/index.mjs +1 -0
- package/build/import/type/discard/discard.mjs +7 -0
- package/build/import/type/discard/index.mjs +1 -0
- package/build/import/type/enum/enum.mjs +14 -0
- package/build/import/type/enum/index.mjs +1 -0
- package/build/import/type/exclude/exclude.mjs +20 -0
- package/build/import/type/exclude/index.mjs +1 -0
- package/build/import/type/extends/extends-check.mjs +450 -0
- package/build/import/type/extends/extends-undefined.mjs +17 -0
- package/build/import/type/extends/extends.mjs +13 -0
- package/build/import/type/extends/index.mjs +3 -0
- package/build/import/type/extract/extract.mjs +20 -0
- package/build/import/type/extract/index.mjs +1 -0
- package/build/import/type/function/function.mjs +11 -0
- package/build/import/type/function/index.mjs +1 -0
- package/build/import/type/guard/index.mjs +2 -0
- package/build/import/type/guard/type.mjs +366 -0
- package/build/import/type/guard/value.mjs +42 -0
- package/build/import/type/helpers/helpers.mjs +3 -0
- package/build/import/type/helpers/index.mjs +1 -0
- package/build/import/type/index.mjs +70 -0
- package/build/import/type/indexed/index.mjs +3 -0
- package/build/import/type/indexed/indexed-key.mjs +29 -0
- package/build/import/type/indexed/indexed-type.mjs +64 -0
- package/build/import/type/indexed/indexed.mjs +9 -0
- package/build/import/type/instance-type/index.mjs +1 -0
- package/build/import/type/instance-type/instance-type.mjs +4 -0
- package/build/import/type/integer/index.mjs +1 -0
- package/build/import/type/integer/integer.mjs +8 -0
- package/build/import/type/intersect/index.mjs +1 -0
- package/build/import/type/intersect/intersect.mjs +25 -0
- package/build/import/type/intrinsic/index.mjs +1 -0
- package/build/import/type/intrinsic/intrinsic.mjs +59 -0
- package/build/import/type/iterator/index.mjs +1 -0
- package/build/import/type/iterator/iterator.mjs +10 -0
- package/build/import/type/keyof/index.mjs +3 -0
- package/build/import/type/keyof/keyof-string.mjs +55 -0
- package/build/import/type/keyof/keyof-type.mjs +15 -0
- package/build/import/type/keyof/keyof.mjs +6 -0
- package/build/import/type/literal/index.mjs +1 -0
- package/build/import/type/literal/literal.mjs +9 -0
- package/build/import/type/mapped/index.mjs +1 -0
- package/build/import/type/mapped/mapped.mjs +14 -0
- package/build/import/type/modifiers/index.mjs +1 -0
- package/build/import/type/modifiers/modifiers.mjs +40 -0
- package/build/import/type/never/index.mjs +1 -0
- package/build/import/type/never/never.mjs +8 -0
- package/build/import/type/not/index.mjs +1 -0
- package/build/import/type/not/not.mjs +9 -0
- package/build/import/type/null/index.mjs +1 -0
- package/build/import/type/null/null.mjs +8 -0
- package/build/import/type/number/index.mjs +1 -0
- package/build/import/type/number/number.mjs +8 -0
- package/build/import/type/object/index.mjs +1 -0
- package/build/import/type/object/object.mjs +14 -0
- package/build/import/type/omit/index.mjs +1 -0
- package/build/import/type/omit/omit.mjs +35 -0
- package/build/import/type/operators/index.mjs +1 -0
- package/build/import/type/operators/operators.mjs +66 -0
- package/build/import/type/optional/index.mjs +1 -0
- package/build/import/type/optional/optional.mjs +5 -0
- package/build/import/type/parameters/index.mjs +1 -0
- package/build/import/type/parameters/parameters.mjs +5 -0
- package/build/import/type/partial/index.mjs +1 -0
- package/build/import/type/partial/partial.mjs +36 -0
- package/build/import/type/patterns/index.mjs +1 -0
- package/build/import/type/patterns/patterns.mjs +6 -0
- package/build/import/type/pick/index.mjs +1 -0
- package/build/import/type/pick/pick.mjs +31 -0
- package/build/import/type/promise/index.mjs +1 -0
- package/build/import/type/promise/promise.mjs +10 -0
- package/build/import/type/readonly/index.mjs +1 -0
- package/build/import/type/readonly/readonly.mjs +5 -0
- package/build/import/type/readonly-optional/index.mjs +1 -0
- package/build/import/type/readonly-optional/readonly-optional.mjs +5 -0
- package/build/import/type/record/index.mjs +1 -0
- package/build/import/type/record/record.mjs +51 -0
- package/build/import/type/recursive/index.mjs +1 -0
- package/build/import/type/recursive/recursive.mjs +15 -0
- package/build/import/type/ref/index.mjs +1 -0
- package/build/import/type/ref/ref.mjs +13 -0
- package/build/import/type/regexp/index.mjs +1 -0
- package/build/import/type/regexp/regexp.mjs +6 -0
- package/build/import/type/registry/format.mjs +19 -0
- package/build/import/type/registry/index.mjs +2 -0
- package/build/import/type/registry/type.mjs +19 -0
- package/build/import/type/required/index.mjs +1 -0
- package/build/import/type/required/required.mjs +35 -0
- package/build/import/type/rest/index.mjs +1 -0
- package/build/import/type/rest/rest.mjs +8 -0
- package/build/import/type/return-type/index.mjs +1 -0
- package/build/import/type/return-type/return-type.mjs +4 -0
- package/build/import/type/schema/anyschema.mjs +1 -0
- package/build/import/type/schema/index.mjs +2 -0
- package/build/import/type/schema/schema.mjs +1 -0
- package/build/import/type/static/index.mjs +1 -0
- package/build/import/type/static/static.mjs +1 -0
- package/build/import/type/strict/index.mjs +1 -0
- package/build/import/type/strict/strict.mjs +3 -0
- package/build/import/type/string/index.mjs +1 -0
- package/build/import/type/string/string.mjs +4 -0
- package/build/import/type/symbol/index.mjs +1 -0
- package/build/import/type/symbol/symbol.mjs +4 -0
- package/build/import/type/symbols/index.mjs +1 -0
- package/build/import/type/symbols/symbols.mjs +5 -0
- package/build/import/type/template-literal/finite.mjs +29 -0
- package/build/import/type/template-literal/generate.mjs +32 -0
- package/build/import/type/template-literal/index.mjs +7 -0
- package/build/import/type/template-literal/parser.mjs +125 -0
- package/build/import/type/template-literal/pattern.mjs +22 -0
- package/build/import/type/template-literal/syntax.mjs +48 -0
- package/build/import/type/template-literal/template-literal.mjs +10 -0
- package/build/import/type/template-literal/union.mjs +13 -0
- package/build/import/type/transform/index.mjs +1 -0
- package/build/import/type/transform/transform.mjs +37 -0
- package/build/import/type/tuple/index.mjs +1 -0
- package/build/import/type/tuple/tuple.mjs +8 -0
- package/build/import/type/type/index.mjs +6 -0
- package/build/import/type/type/javascript.mjs +71 -0
- package/build/import/type/type/json.mjs +171 -0
- package/build/import/type/type/type.mjs +58 -0
- package/build/import/type/uint8array/index.mjs +1 -0
- package/build/import/type/uint8array/uint8array.mjs +4 -0
- package/build/import/type/undefined/index.mjs +1 -0
- package/build/import/type/undefined/undefined.mjs +4 -0
- package/build/import/type/union/index.mjs +1 -0
- package/build/import/type/union/union.mjs +15 -0
- package/build/import/type/unknown/index.mjs +1 -0
- package/build/import/type/unknown/unknown.mjs +7 -0
- package/build/import/type/unsafe/index.mjs +1 -0
- package/build/import/type/unsafe/unsafe.mjs +7 -0
- package/build/import/type/void/index.mjs +1 -0
- package/build/import/type/void/void.mjs +8 -0
- package/build/import/value/cast/cast.mjs +205 -0
- package/build/import/value/cast/index.mjs +1 -0
- package/build/import/value/check/check.mjs +419 -0
- package/build/import/value/check/index.mjs +1 -0
- package/build/import/value/clean/clean.mjs +125 -0
- package/build/import/value/clean/index.mjs +1 -0
- package/build/import/value/clone/clone.mjs +30 -0
- package/build/import/value/clone/index.mjs +1 -0
- package/build/import/value/convert/convert.mjs +231 -0
- package/build/import/value/convert/index.mjs +1 -0
- package/build/import/value/create/create.mjs +460 -0
- package/build/import/value/create/index.mjs +1 -0
- package/build/import/value/default/default.mjs +125 -0
- package/build/import/value/default/index.mjs +1 -0
- package/build/import/value/delta/delta.mjs +152 -0
- package/build/import/value/delta/index.mjs +1 -0
- package/build/import/value/deref/deref.mjs +13 -0
- package/build/import/value/deref/index.mjs +1 -0
- package/build/import/value/equal/equal.mjs +39 -0
- package/build/import/value/equal/index.mjs +1 -0
- package/build/import/value/guard/guard.mjs +66 -0
- package/build/import/value/guard/index.mjs +1 -0
- package/build/import/value/hash/hash.mjs +127 -0
- package/build/import/value/hash/index.mjs +1 -0
- package/build/import/value/index.mjs +18 -0
- package/build/import/value/mutate/index.mjs +1 -0
- package/build/import/value/mutate/mutate.mjs +85 -0
- package/build/import/value/pointer/index.mjs +1 -0
- package/build/import/value/pointer/pointer.mjs +101 -0
- package/build/import/value/transform/decode.mjs +160 -0
- package/build/import/value/transform/encode.mjs +166 -0
- package/build/import/value/transform/has.mjs +99 -0
- package/build/import/value/transform/index.mjs +3 -0
- package/build/import/value/value/index.mjs +1 -0
- package/build/import/value/value/value.mjs +65 -0
- package/compiler/package.json +4 -0
- package/errors/package.json +4 -0
- package/package.json +52 -53
- package/system/package.json +4 -0
- package/type/package.json +4 -0
- package/value/package.json +4 -0
- /package/{compiler → build/default/compiler}/compiler.js +0 -0
- /package/{compiler → build/default/compiler}/index.js +0 -0
- /package/{errors → build/default/errors}/errors.js +0 -0
- /package/{errors → build/default/errors}/index.js +0 -0
- /package/{index.js → build/default/index.js} +0 -0
- /package/{system → build/default/system}/errors.js +0 -0
- /package/{system → build/default/system}/index.js +0 -0
- /package/{system → build/default/system}/policy.js +0 -0
- /package/{system → build/default/system}/system.js +0 -0
- /package/{type → build/default/type}/any/any.js +0 -0
- /package/{type → build/default/type}/any/index.js +0 -0
- /package/{type → build/default/type}/array/array.js +0 -0
- /package/{type → build/default/type}/array/index.js +0 -0
- /package/{type → build/default/type}/async-iterator/async-iterator.js +0 -0
- /package/{type → build/default/type}/async-iterator/index.js +0 -0
- /package/{type → build/default/type}/awaited/awaited.js +0 -0
- /package/{type → build/default/type}/awaited/index.js +0 -0
- /package/{type → build/default/type}/bigint/bigint.js +0 -0
- /package/{type → build/default/type}/bigint/index.js +0 -0
- /package/{type → build/default/type}/boolean/boolean.js +0 -0
- /package/{type → build/default/type}/boolean/index.js +0 -0
- /package/{type → build/default/type}/clone/index.js +0 -0
- /package/{type → build/default/type}/clone/type.js +0 -0
- /package/{type → build/default/type}/clone/value.js +0 -0
- /package/{type → build/default/type}/composite/composite.js +0 -0
- /package/{type → build/default/type}/composite/index.js +0 -0
- /package/{type → build/default/type}/const/const.js +0 -0
- /package/{type → build/default/type}/const/index.js +0 -0
- /package/{type → build/default/type}/constructor/constructor.js +0 -0
- /package/{type → build/default/type}/constructor/index.js +0 -0
- /package/{type → build/default/type}/constructor-parameters/constructor-parameters.js +0 -0
- /package/{type → build/default/type}/constructor-parameters/index.js +0 -0
- /package/{type → build/default/type}/date/date.js +0 -0
- /package/{type → build/default/type}/date/index.js +0 -0
- /package/{type → build/default/type}/deref/deref.js +0 -0
- /package/{type → build/default/type}/deref/index.js +0 -0
- /package/{type → build/default/type}/discard/discard.js +0 -0
- /package/{type → build/default/type}/discard/index.js +0 -0
- /package/{type → build/default/type}/enum/enum.js +0 -0
- /package/{type → build/default/type}/enum/index.js +0 -0
- /package/{type → build/default/type}/exclude/exclude.js +0 -0
- /package/{type → build/default/type}/exclude/index.js +0 -0
- /package/{type → build/default/type}/extends/extends-check.js +0 -0
- /package/{type → build/default/type}/extends/extends-undefined.js +0 -0
- /package/{type → build/default/type}/extends/extends.js +0 -0
- /package/{type → build/default/type}/extends/index.js +0 -0
- /package/{type → build/default/type}/extract/extract.js +0 -0
- /package/{type → build/default/type}/extract/index.js +0 -0
- /package/{type → build/default/type}/function/function.js +0 -0
- /package/{type → build/default/type}/function/index.js +0 -0
- /package/{type → build/default/type}/guard/index.js +0 -0
- /package/{type → build/default/type}/guard/type.js +0 -0
- /package/{type → build/default/type}/guard/value.js +0 -0
- /package/{type → build/default/type}/helpers/helpers.js +0 -0
- /package/{type → build/default/type}/helpers/index.js +0 -0
- /package/{type → build/default/type}/index.js +0 -0
- /package/{type → build/default/type}/indexed/index.js +0 -0
- /package/{type → build/default/type}/indexed/indexed-key.js +0 -0
- /package/{type → build/default/type}/indexed/indexed-type.js +0 -0
- /package/{type → build/default/type}/indexed/indexed.js +0 -0
- /package/{type → build/default/type}/instance-type/index.js +0 -0
- /package/{type → build/default/type}/instance-type/instance-type.js +0 -0
- /package/{type → build/default/type}/integer/index.js +0 -0
- /package/{type → build/default/type}/integer/integer.js +0 -0
- /package/{type → build/default/type}/intersect/index.js +0 -0
- /package/{type → build/default/type}/intersect/intersect.js +0 -0
- /package/{type → build/default/type}/intrinsic/index.js +0 -0
- /package/{type → build/default/type}/intrinsic/intrinsic.js +0 -0
- /package/{type → build/default/type}/iterator/index.js +0 -0
- /package/{type → build/default/type}/iterator/iterator.js +0 -0
- /package/{type → build/default/type}/keyof/index.js +0 -0
- /package/{type → build/default/type}/keyof/keyof-string.js +0 -0
- /package/{type → build/default/type}/keyof/keyof-type.js +0 -0
- /package/{type → build/default/type}/keyof/keyof.js +0 -0
- /package/{type → build/default/type}/literal/index.js +0 -0
- /package/{type → build/default/type}/literal/literal.js +0 -0
- /package/{type → build/default/type}/mapped/index.js +0 -0
- /package/{type → build/default/type}/mapped/mapped.js +0 -0
- /package/{type → build/default/type}/modifiers/index.js +0 -0
- /package/{type → build/default/type}/modifiers/modifiers.js +0 -0
- /package/{type → build/default/type}/never/index.js +0 -0
- /package/{type → build/default/type}/never/never.js +0 -0
- /package/{type → build/default/type}/not/index.js +0 -0
- /package/{type → build/default/type}/not/not.js +0 -0
- /package/{type → build/default/type}/null/index.js +0 -0
- /package/{type → build/default/type}/null/null.js +0 -0
- /package/{type → build/default/type}/number/index.js +0 -0
- /package/{type → build/default/type}/number/number.js +0 -0
- /package/{type → build/default/type}/object/index.js +0 -0
- /package/{type → build/default/type}/object/object.js +0 -0
- /package/{type → build/default/type}/omit/index.js +0 -0
- /package/{type → build/default/type}/omit/omit.js +0 -0
- /package/{type → build/default/type}/operators/index.js +0 -0
- /package/{type → build/default/type}/operators/operators.js +0 -0
- /package/{type → build/default/type}/optional/index.js +0 -0
- /package/{type → build/default/type}/optional/optional.js +0 -0
- /package/{type → build/default/type}/parameters/index.js +0 -0
- /package/{type → build/default/type}/parameters/parameters.js +0 -0
- /package/{type → build/default/type}/partial/index.js +0 -0
- /package/{type → build/default/type}/partial/partial.js +0 -0
- /package/{type → build/default/type}/patterns/index.js +0 -0
- /package/{type → build/default/type}/patterns/patterns.js +0 -0
- /package/{type → build/default/type}/pick/index.js +0 -0
- /package/{type → build/default/type}/pick/pick.js +0 -0
- /package/{type → build/default/type}/promise/index.js +0 -0
- /package/{type → build/default/type}/promise/promise.js +0 -0
- /package/{type → build/default/type}/readonly/index.js +0 -0
- /package/{type → build/default/type}/readonly/readonly.js +0 -0
- /package/{type → build/default/type}/readonly-optional/index.js +0 -0
- /package/{type → build/default/type}/readonly-optional/readonly-optional.js +0 -0
- /package/{type → build/default/type}/record/index.js +0 -0
- /package/{type → build/default/type}/record/record.js +0 -0
- /package/{type → build/default/type}/recursive/index.js +0 -0
- /package/{type → build/default/type}/recursive/recursive.js +0 -0
- /package/{type → build/default/type}/ref/index.js +0 -0
- /package/{type → build/default/type}/ref/ref.js +0 -0
- /package/{type → build/default/type}/regexp/index.js +0 -0
- /package/{type → build/default/type}/regexp/regexp.js +0 -0
- /package/{type → build/default/type}/registry/format.js +0 -0
- /package/{type → build/default/type}/registry/index.js +0 -0
- /package/{type → build/default/type}/registry/type.js +0 -0
- /package/{type → build/default/type}/required/index.js +0 -0
- /package/{type → build/default/type}/required/required.js +0 -0
- /package/{type → build/default/type}/rest/index.js +0 -0
- /package/{type → build/default/type}/rest/rest.js +0 -0
- /package/{type → build/default/type}/return-type/index.js +0 -0
- /package/{type → build/default/type}/return-type/return-type.js +0 -0
- /package/{type → build/default/type}/schema/anyschema.js +0 -0
- /package/{type → build/default/type}/schema/index.js +0 -0
- /package/{type → build/default/type}/schema/schema.js +0 -0
- /package/{type → build/default/type}/static/index.js +0 -0
- /package/{type → build/default/type}/static/static.js +0 -0
- /package/{type → build/default/type}/strict/index.js +0 -0
- /package/{type → build/default/type}/strict/strict.js +0 -0
- /package/{type → build/default/type}/string/index.js +0 -0
- /package/{type → build/default/type}/string/string.js +0 -0
- /package/{type → build/default/type}/symbol/index.js +0 -0
- /package/{type → build/default/type}/symbol/symbol.js +0 -0
- /package/{type → build/default/type}/symbols/index.js +0 -0
- /package/{type → build/default/type}/symbols/symbols.js +0 -0
- /package/{type → build/default/type}/template-literal/finite.js +0 -0
- /package/{type → build/default/type}/template-literal/generate.js +0 -0
- /package/{type → build/default/type}/template-literal/index.js +0 -0
- /package/{type → build/default/type}/template-literal/parser.js +0 -0
- /package/{type → build/default/type}/template-literal/pattern.js +0 -0
- /package/{type → build/default/type}/template-literal/syntax.js +0 -0
- /package/{type → build/default/type}/template-literal/template-literal.js +0 -0
- /package/{type → build/default/type}/template-literal/union.js +0 -0
- /package/{type → build/default/type}/transform/index.js +0 -0
- /package/{type → build/default/type}/transform/transform.js +0 -0
- /package/{type → build/default/type}/tuple/index.js +0 -0
- /package/{type → build/default/type}/tuple/tuple.js +0 -0
- /package/{type → build/default/type}/type/index.js +0 -0
- /package/{type → build/default/type}/type/javascript.js +0 -0
- /package/{type → build/default/type}/type/json.js +0 -0
- /package/{type → build/default/type}/type/type.js +0 -0
- /package/{type → build/default/type}/uint8array/index.js +0 -0
- /package/{type → build/default/type}/uint8array/uint8array.js +0 -0
- /package/{type → build/default/type}/undefined/index.js +0 -0
- /package/{type → build/default/type}/undefined/undefined.js +0 -0
- /package/{type → build/default/type}/union/index.js +0 -0
- /package/{type → build/default/type}/union/union.js +0 -0
- /package/{type → build/default/type}/unknown/index.js +0 -0
- /package/{type → build/default/type}/unknown/unknown.js +0 -0
- /package/{type → build/default/type}/unsafe/index.js +0 -0
- /package/{type → build/default/type}/unsafe/unsafe.js +0 -0
- /package/{type → build/default/type}/void/index.js +0 -0
- /package/{type → build/default/type}/void/void.js +0 -0
- /package/{value → build/default/value}/cast/cast.js +0 -0
- /package/{value → build/default/value}/cast/index.js +0 -0
- /package/{value → build/default/value}/check/check.js +0 -0
- /package/{value → build/default/value}/check/index.js +0 -0
- /package/{value → build/default/value}/clean/clean.js +0 -0
- /package/{value → build/default/value}/clean/index.js +0 -0
- /package/{value → build/default/value}/clone/clone.js +0 -0
- /package/{value → build/default/value}/clone/index.js +0 -0
- /package/{value → build/default/value}/convert/convert.js +0 -0
- /package/{value → build/default/value}/convert/index.js +0 -0
- /package/{value → build/default/value}/create/create.js +0 -0
- /package/{value → build/default/value}/create/index.js +0 -0
- /package/{value → build/default/value}/default/default.js +0 -0
- /package/{value → build/default/value}/default/index.js +0 -0
- /package/{value → build/default/value}/delta/delta.js +0 -0
- /package/{value → build/default/value}/delta/index.js +0 -0
- /package/{value → build/default/value}/deref/deref.js +0 -0
- /package/{value → build/default/value}/deref/index.js +0 -0
- /package/{value → build/default/value}/equal/equal.js +0 -0
- /package/{value → build/default/value}/equal/index.js +0 -0
- /package/{value → build/default/value}/guard/guard.js +0 -0
- /package/{value → build/default/value}/guard/index.js +0 -0
- /package/{value → build/default/value}/hash/hash.js +0 -0
- /package/{value → build/default/value}/hash/index.js +0 -0
- /package/{value → build/default/value}/index.js +0 -0
- /package/{value → build/default/value}/mutate/index.js +0 -0
- /package/{value → build/default/value}/mutate/mutate.js +0 -0
- /package/{value → build/default/value}/pointer/index.js +0 -0
- /package/{value → build/default/value}/pointer/pointer.js +0 -0
- /package/{value → build/default/value}/transform/decode.js +0 -0
- /package/{value → build/default/value}/transform/encode.js +0 -0
- /package/{value → build/default/value}/transform/has.js +0 -0
- /package/{value → build/default/value}/transform/index.js +0 -0
- /package/{value → build/default/value}/value/index.js +0 -0
- /package/{value → build/default/value}/value/value.js +0 -0
- /package/{compiler → build/types/compiler}/compiler.d.ts +0 -0
- /package/{compiler → build/types/compiler}/index.d.ts +0 -0
- /package/{errors → build/types/errors}/errors.d.ts +0 -0
- /package/{errors → build/types/errors}/index.d.ts +0 -0
- /package/{index.d.ts → build/types/index.d.ts} +0 -0
- /package/{system → build/types/system}/errors.d.ts +0 -0
- /package/{system → build/types/system}/index.d.ts +0 -0
- /package/{system → build/types/system}/policy.d.ts +0 -0
- /package/{system → build/types/system}/system.d.ts +0 -0
- /package/{type → build/types/type}/any/any.d.ts +0 -0
- /package/{type → build/types/type}/any/index.d.ts +0 -0
- /package/{type → build/types/type}/array/array.d.ts +0 -0
- /package/{type → build/types/type}/array/index.d.ts +0 -0
- /package/{type → build/types/type}/async-iterator/async-iterator.d.ts +0 -0
- /package/{type → build/types/type}/async-iterator/index.d.ts +0 -0
- /package/{type → build/types/type}/awaited/awaited.d.ts +0 -0
- /package/{type → build/types/type}/awaited/index.d.ts +0 -0
- /package/{type → build/types/type}/bigint/bigint.d.ts +0 -0
- /package/{type → build/types/type}/bigint/index.d.ts +0 -0
- /package/{type → build/types/type}/boolean/boolean.d.ts +0 -0
- /package/{type → build/types/type}/boolean/index.d.ts +0 -0
- /package/{type → build/types/type}/clone/index.d.ts +0 -0
- /package/{type → build/types/type}/clone/type.d.ts +0 -0
- /package/{type → build/types/type}/clone/value.d.ts +0 -0
- /package/{type → build/types/type}/composite/composite.d.ts +0 -0
- /package/{type → build/types/type}/composite/index.d.ts +0 -0
- /package/{type → build/types/type}/const/const.d.ts +0 -0
- /package/{type → build/types/type}/const/index.d.ts +0 -0
- /package/{type → build/types/type}/constructor/constructor.d.ts +0 -0
- /package/{type → build/types/type}/constructor/index.d.ts +0 -0
- /package/{type → build/types/type}/constructor-parameters/constructor-parameters.d.ts +0 -0
- /package/{type → build/types/type}/constructor-parameters/index.d.ts +0 -0
- /package/{type → build/types/type}/date/date.d.ts +0 -0
- /package/{type → build/types/type}/date/index.d.ts +0 -0
- /package/{type → build/types/type}/deref/deref.d.ts +0 -0
- /package/{type → build/types/type}/deref/index.d.ts +0 -0
- /package/{type → build/types/type}/discard/discard.d.ts +0 -0
- /package/{type → build/types/type}/discard/index.d.ts +0 -0
- /package/{type → build/types/type}/enum/enum.d.ts +0 -0
- /package/{type → build/types/type}/enum/index.d.ts +0 -0
- /package/{type → build/types/type}/exclude/exclude.d.ts +0 -0
- /package/{type → build/types/type}/exclude/index.d.ts +0 -0
- /package/{type → build/types/type}/extends/extends-check.d.ts +0 -0
- /package/{type → build/types/type}/extends/extends-undefined.d.ts +0 -0
- /package/{type → build/types/type}/extends/extends.d.ts +0 -0
- /package/{type → build/types/type}/extends/index.d.ts +0 -0
- /package/{type → build/types/type}/extract/extract.d.ts +0 -0
- /package/{type → build/types/type}/extract/index.d.ts +0 -0
- /package/{type → build/types/type}/function/function.d.ts +0 -0
- /package/{type → build/types/type}/function/index.d.ts +0 -0
- /package/{type → build/types/type}/guard/index.d.ts +0 -0
- /package/{type → build/types/type}/guard/type.d.ts +0 -0
- /package/{type → build/types/type}/guard/value.d.ts +0 -0
- /package/{type → build/types/type}/helpers/helpers.d.ts +0 -0
- /package/{type → build/types/type}/helpers/index.d.ts +0 -0
- /package/{type → build/types/type}/index.d.ts +0 -0
- /package/{type → build/types/type}/indexed/index.d.ts +0 -0
- /package/{type → build/types/type}/indexed/indexed-key.d.ts +0 -0
- /package/{type → build/types/type}/indexed/indexed-type.d.ts +0 -0
- /package/{type → build/types/type}/indexed/indexed.d.ts +0 -0
- /package/{type → build/types/type}/instance-type/index.d.ts +0 -0
- /package/{type → build/types/type}/instance-type/instance-type.d.ts +0 -0
- /package/{type → build/types/type}/integer/index.d.ts +0 -0
- /package/{type → build/types/type}/integer/integer.d.ts +0 -0
- /package/{type → build/types/type}/intersect/index.d.ts +0 -0
- /package/{type → build/types/type}/intersect/intersect.d.ts +0 -0
- /package/{type → build/types/type}/intrinsic/index.d.ts +0 -0
- /package/{type → build/types/type}/intrinsic/intrinsic.d.ts +0 -0
- /package/{type → build/types/type}/iterator/index.d.ts +0 -0
- /package/{type → build/types/type}/iterator/iterator.d.ts +0 -0
- /package/{type → build/types/type}/keyof/index.d.ts +0 -0
- /package/{type → build/types/type}/keyof/keyof-string.d.ts +0 -0
- /package/{type → build/types/type}/keyof/keyof-type.d.ts +0 -0
- /package/{type → build/types/type}/keyof/keyof.d.ts +0 -0
- /package/{type → build/types/type}/literal/index.d.ts +0 -0
- /package/{type → build/types/type}/literal/literal.d.ts +0 -0
- /package/{type → build/types/type}/mapped/index.d.ts +0 -0
- /package/{type → build/types/type}/mapped/mapped.d.ts +0 -0
- /package/{type → build/types/type}/modifiers/index.d.ts +0 -0
- /package/{type → build/types/type}/modifiers/modifiers.d.ts +0 -0
- /package/{type → build/types/type}/never/index.d.ts +0 -0
- /package/{type → build/types/type}/never/never.d.ts +0 -0
- /package/{type → build/types/type}/not/index.d.ts +0 -0
- /package/{type → build/types/type}/not/not.d.ts +0 -0
- /package/{type → build/types/type}/null/index.d.ts +0 -0
- /package/{type → build/types/type}/null/null.d.ts +0 -0
- /package/{type → build/types/type}/number/index.d.ts +0 -0
- /package/{type → build/types/type}/number/number.d.ts +0 -0
- /package/{type → build/types/type}/object/index.d.ts +0 -0
- /package/{type → build/types/type}/object/object.d.ts +0 -0
- /package/{type → build/types/type}/omit/index.d.ts +0 -0
- /package/{type → build/types/type}/omit/omit.d.ts +0 -0
- /package/{type → build/types/type}/operators/index.d.ts +0 -0
- /package/{type → build/types/type}/operators/operators.d.ts +0 -0
- /package/{type → build/types/type}/optional/index.d.ts +0 -0
- /package/{type → build/types/type}/optional/optional.d.ts +0 -0
- /package/{type → build/types/type}/parameters/index.d.ts +0 -0
- /package/{type → build/types/type}/parameters/parameters.d.ts +0 -0
- /package/{type → build/types/type}/partial/index.d.ts +0 -0
- /package/{type → build/types/type}/partial/partial.d.ts +0 -0
- /package/{type → build/types/type}/patterns/index.d.ts +0 -0
- /package/{type → build/types/type}/patterns/patterns.d.ts +0 -0
- /package/{type → build/types/type}/pick/index.d.ts +0 -0
- /package/{type → build/types/type}/pick/pick.d.ts +0 -0
- /package/{type → build/types/type}/promise/index.d.ts +0 -0
- /package/{type → build/types/type}/promise/promise.d.ts +0 -0
- /package/{type → build/types/type}/readonly/index.d.ts +0 -0
- /package/{type → build/types/type}/readonly/readonly.d.ts +0 -0
- /package/{type → build/types/type}/readonly-optional/index.d.ts +0 -0
- /package/{type → build/types/type}/readonly-optional/readonly-optional.d.ts +0 -0
- /package/{type → build/types/type}/record/index.d.ts +0 -0
- /package/{type → build/types/type}/record/record.d.ts +0 -0
- /package/{type → build/types/type}/recursive/index.d.ts +0 -0
- /package/{type → build/types/type}/recursive/recursive.d.ts +0 -0
- /package/{type → build/types/type}/ref/index.d.ts +0 -0
- /package/{type → build/types/type}/ref/ref.d.ts +0 -0
- /package/{type → build/types/type}/regexp/index.d.ts +0 -0
- /package/{type → build/types/type}/regexp/regexp.d.ts +0 -0
- /package/{type → build/types/type}/registry/format.d.ts +0 -0
- /package/{type → build/types/type}/registry/index.d.ts +0 -0
- /package/{type → build/types/type}/registry/type.d.ts +0 -0
- /package/{type → build/types/type}/required/index.d.ts +0 -0
- /package/{type → build/types/type}/required/required.d.ts +0 -0
- /package/{type → build/types/type}/rest/index.d.ts +0 -0
- /package/{type → build/types/type}/rest/rest.d.ts +0 -0
- /package/{type → build/types/type}/return-type/index.d.ts +0 -0
- /package/{type → build/types/type}/return-type/return-type.d.ts +0 -0
- /package/{type → build/types/type}/schema/anyschema.d.ts +0 -0
- /package/{type → build/types/type}/schema/index.d.ts +0 -0
- /package/{type → build/types/type}/schema/schema.d.ts +0 -0
- /package/{type → build/types/type}/static/index.d.ts +0 -0
- /package/{type → build/types/type}/static/static.d.ts +0 -0
- /package/{type → build/types/type}/strict/index.d.ts +0 -0
- /package/{type → build/types/type}/strict/strict.d.ts +0 -0
- /package/{type → build/types/type}/string/index.d.ts +0 -0
- /package/{type → build/types/type}/string/string.d.ts +0 -0
- /package/{type → build/types/type}/symbol/index.d.ts +0 -0
- /package/{type → build/types/type}/symbol/symbol.d.ts +0 -0
- /package/{type → build/types/type}/symbols/index.d.ts +0 -0
- /package/{type → build/types/type}/symbols/symbols.d.ts +0 -0
- /package/{type → build/types/type}/template-literal/finite.d.ts +0 -0
- /package/{type → build/types/type}/template-literal/generate.d.ts +0 -0
- /package/{type → build/types/type}/template-literal/index.d.ts +0 -0
- /package/{type → build/types/type}/template-literal/parser.d.ts +0 -0
- /package/{type → build/types/type}/template-literal/pattern.d.ts +0 -0
- /package/{type → build/types/type}/template-literal/syntax.d.ts +0 -0
- /package/{type → build/types/type}/template-literal/template-literal.d.ts +0 -0
- /package/{type → build/types/type}/template-literal/union.d.ts +0 -0
- /package/{type → build/types/type}/transform/index.d.ts +0 -0
- /package/{type → build/types/type}/transform/transform.d.ts +0 -0
- /package/{type → build/types/type}/tuple/index.d.ts +0 -0
- /package/{type → build/types/type}/tuple/tuple.d.ts +0 -0
- /package/{type → build/types/type}/type/index.d.ts +0 -0
- /package/{type → build/types/type}/type/javascript.d.ts +0 -0
- /package/{type → build/types/type}/type/json.d.ts +0 -0
- /package/{type → build/types/type}/type/type.d.ts +0 -0
- /package/{type → build/types/type}/uint8array/index.d.ts +0 -0
- /package/{type → build/types/type}/uint8array/uint8array.d.ts +0 -0
- /package/{type → build/types/type}/undefined/index.d.ts +0 -0
- /package/{type → build/types/type}/undefined/undefined.d.ts +0 -0
- /package/{type → build/types/type}/union/index.d.ts +0 -0
- /package/{type → build/types/type}/union/union.d.ts +0 -0
- /package/{type → build/types/type}/unknown/index.d.ts +0 -0
- /package/{type → build/types/type}/unknown/unknown.d.ts +0 -0
- /package/{type → build/types/type}/unsafe/index.d.ts +0 -0
- /package/{type → build/types/type}/unsafe/unsafe.d.ts +0 -0
- /package/{type → build/types/type}/void/index.d.ts +0 -0
- /package/{type → build/types/type}/void/void.d.ts +0 -0
- /package/{value → build/types/value}/cast/cast.d.ts +0 -0
- /package/{value → build/types/value}/cast/index.d.ts +0 -0
- /package/{value → build/types/value}/check/check.d.ts +0 -0
- /package/{value → build/types/value}/check/index.d.ts +0 -0
- /package/{value → build/types/value}/clean/clean.d.ts +0 -0
- /package/{value → build/types/value}/clean/index.d.ts +0 -0
- /package/{value → build/types/value}/clone/clone.d.ts +0 -0
- /package/{value → build/types/value}/clone/index.d.ts +0 -0
- /package/{value → build/types/value}/convert/convert.d.ts +0 -0
- /package/{value → build/types/value}/convert/index.d.ts +0 -0
- /package/{value → build/types/value}/create/create.d.ts +0 -0
- /package/{value → build/types/value}/create/index.d.ts +0 -0
- /package/{value → build/types/value}/default/default.d.ts +0 -0
- /package/{value → build/types/value}/default/index.d.ts +0 -0
- /package/{value → build/types/value}/delta/delta.d.ts +0 -0
- /package/{value → build/types/value}/delta/index.d.ts +0 -0
- /package/{value → build/types/value}/deref/deref.d.ts +0 -0
- /package/{value → build/types/value}/deref/index.d.ts +0 -0
- /package/{value → build/types/value}/equal/equal.d.ts +0 -0
- /package/{value → build/types/value}/equal/index.d.ts +0 -0
- /package/{value → build/types/value}/guard/guard.d.ts +0 -0
- /package/{value → build/types/value}/guard/index.d.ts +0 -0
- /package/{value → build/types/value}/hash/hash.d.ts +0 -0
- /package/{value → build/types/value}/hash/index.d.ts +0 -0
- /package/{value → build/types/value}/index.d.ts +0 -0
- /package/{value → build/types/value}/mutate/index.d.ts +0 -0
- /package/{value → build/types/value}/mutate/mutate.d.ts +0 -0
- /package/{value → build/types/value}/pointer/index.d.ts +0 -0
- /package/{value → build/types/value}/pointer/pointer.d.ts +0 -0
- /package/{value → build/types/value}/transform/decode.d.ts +0 -0
- /package/{value → build/types/value}/transform/encode.d.ts +0 -0
- /package/{value → build/types/value}/transform/has.d.ts +0 -0
- /package/{value → build/types/value}/transform/index.d.ts +0 -0
- /package/{value → build/types/value}/value/index.d.ts +0 -0
- /package/{value → build/types/value}/value/value.d.ts +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { IsString, IsObject, IsArray, IsUndefined } from '../guard/index.mjs';
|
|
2
|
+
import { TSchema as IsSchemaType } from '../../type/guard/type.mjs';
|
|
3
|
+
import { Check } from '../check/index.mjs';
|
|
4
|
+
import { Deref } from '../deref/index.mjs';
|
|
5
|
+
import { Kind } from '../../type/symbols/index.mjs';
|
|
6
|
+
function ValueOrDefault(schema, value) {
|
|
7
|
+
return !(value === undefined) || !('default' in schema) ? value : schema.default;
|
|
8
|
+
}
|
|
9
|
+
function IsCheckable(schema) {
|
|
10
|
+
return IsSchemaType(schema) && schema[Kind] !== 'Unsafe';
|
|
11
|
+
}
|
|
12
|
+
function IsDefaultSchema(value) {
|
|
13
|
+
return IsSchemaType(value) && 'default' in value;
|
|
14
|
+
}
|
|
15
|
+
function TArray(schema, references, value) {
|
|
16
|
+
const defaulted = ValueOrDefault(schema, value);
|
|
17
|
+
if (!IsArray(defaulted))
|
|
18
|
+
return defaulted;
|
|
19
|
+
for (let i = 0; i < defaulted.length; i++) {
|
|
20
|
+
defaulted[i] = Visit(schema.items, references, defaulted[i]);
|
|
21
|
+
}
|
|
22
|
+
return defaulted;
|
|
23
|
+
}
|
|
24
|
+
function TIntersect(schema, references, value) {
|
|
25
|
+
const defaulted = ValueOrDefault(schema, value);
|
|
26
|
+
return schema.allOf.reduce((acc, schema) => {
|
|
27
|
+
const next = Visit(schema, references, defaulted);
|
|
28
|
+
return IsObject(next) ? { ...acc, ...next } : next;
|
|
29
|
+
}, {});
|
|
30
|
+
}
|
|
31
|
+
function TObject(schema, references, value) {
|
|
32
|
+
const defaulted = ValueOrDefault(schema, value);
|
|
33
|
+
if (!IsObject(defaulted))
|
|
34
|
+
return defaulted;
|
|
35
|
+
const additionalPropertiesSchema = schema.additionalProperties;
|
|
36
|
+
const knownPropertyKeys = Object.getOwnPropertyNames(schema.properties);
|
|
37
|
+
for (const key of knownPropertyKeys) {
|
|
38
|
+
if (!IsDefaultSchema(schema.properties[key]))
|
|
39
|
+
continue;
|
|
40
|
+
defaulted[key] = Visit(schema.properties[key], references, defaulted[key]);
|
|
41
|
+
}
|
|
42
|
+
if (!IsDefaultSchema(additionalPropertiesSchema))
|
|
43
|
+
return defaulted;
|
|
44
|
+
for (const key of Object.getOwnPropertyNames(defaulted)) {
|
|
45
|
+
if (knownPropertyKeys.includes(key))
|
|
46
|
+
continue;
|
|
47
|
+
defaulted[key] = Visit(additionalPropertiesSchema, references, defaulted[key]);
|
|
48
|
+
}
|
|
49
|
+
return defaulted;
|
|
50
|
+
}
|
|
51
|
+
function TRecord(schema, references, value) {
|
|
52
|
+
const defaulted = ValueOrDefault(schema, value);
|
|
53
|
+
if (!IsObject(defaulted))
|
|
54
|
+
return defaulted;
|
|
55
|
+
const additionalPropertiesSchema = schema.additionalProperties;
|
|
56
|
+
const [propertyKeyPattern, propertySchema] = Object.entries(schema.patternProperties)[0];
|
|
57
|
+
const knownPropertyKey = new RegExp(propertyKeyPattern);
|
|
58
|
+
for (const key of Object.getOwnPropertyNames(defaulted)) {
|
|
59
|
+
if (!(knownPropertyKey.test(key) && IsDefaultSchema(propertySchema)))
|
|
60
|
+
continue;
|
|
61
|
+
defaulted[key] = Visit(propertySchema, references, defaulted[key]);
|
|
62
|
+
}
|
|
63
|
+
if (!IsDefaultSchema(additionalPropertiesSchema))
|
|
64
|
+
return defaulted;
|
|
65
|
+
for (const key of Object.getOwnPropertyNames(defaulted)) {
|
|
66
|
+
if (knownPropertyKey.test(key))
|
|
67
|
+
continue;
|
|
68
|
+
defaulted[key] = Visit(additionalPropertiesSchema, references, defaulted[key]);
|
|
69
|
+
}
|
|
70
|
+
return defaulted;
|
|
71
|
+
}
|
|
72
|
+
function TRef(schema, references, value) {
|
|
73
|
+
return Visit(Deref(schema, references), references, ValueOrDefault(schema, value));
|
|
74
|
+
}
|
|
75
|
+
function TThis(schema, references, value) {
|
|
76
|
+
return Visit(Deref(schema, references), references, value);
|
|
77
|
+
}
|
|
78
|
+
function TTuple(schema, references, value) {
|
|
79
|
+
const defaulted = ValueOrDefault(schema, value);
|
|
80
|
+
if (!IsArray(defaulted) || IsUndefined(schema.items))
|
|
81
|
+
return defaulted;
|
|
82
|
+
const [items, max] = [schema.items, Math.max(schema.items.length, defaulted.length)];
|
|
83
|
+
for (let i = 0; i < max; i++) {
|
|
84
|
+
if (i < items.length)
|
|
85
|
+
defaulted[i] = Visit(items[i], references, defaulted[i]);
|
|
86
|
+
}
|
|
87
|
+
return defaulted;
|
|
88
|
+
}
|
|
89
|
+
function TUnion(schema, references, value) {
|
|
90
|
+
const defaulted = ValueOrDefault(schema, value);
|
|
91
|
+
for (const inner of schema.anyOf) {
|
|
92
|
+
const result = Visit(inner, references, defaulted);
|
|
93
|
+
if (IsCheckable(inner) && Check(inner, result)) {
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return defaulted;
|
|
98
|
+
}
|
|
99
|
+
function Visit(schema, references, value) {
|
|
100
|
+
const references_ = IsString(schema.$id) ? [...references, schema] : references;
|
|
101
|
+
const schema_ = schema;
|
|
102
|
+
switch (schema_[Kind]) {
|
|
103
|
+
case 'Array':
|
|
104
|
+
return TArray(schema_, references_, value);
|
|
105
|
+
case 'Intersect':
|
|
106
|
+
return TIntersect(schema_, references_, value);
|
|
107
|
+
case 'Object':
|
|
108
|
+
return TObject(schema_, references_, value);
|
|
109
|
+
case 'Record':
|
|
110
|
+
return TRecord(schema_, references_, value);
|
|
111
|
+
case 'Ref':
|
|
112
|
+
return TRef(schema_, references_, value);
|
|
113
|
+
case 'This':
|
|
114
|
+
return TThis(schema_, references_, value);
|
|
115
|
+
case 'Tuple':
|
|
116
|
+
return TTuple(schema_, references_, value);
|
|
117
|
+
case 'Union':
|
|
118
|
+
return TUnion(schema_, references_, value);
|
|
119
|
+
default:
|
|
120
|
+
return ValueOrDefault(schema_, value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export function Default(...args) {
|
|
124
|
+
return args.length === 3 ? Visit(args[0], args[1], args[2]) : Visit(args[0], [], args[1]);
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './default.mjs';
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { IsPlainObject, IsArray, IsTypedArray, IsValueType, IsSymbol, IsUndefined } from '../guard/index.mjs';
|
|
2
|
+
import { ValuePointer } from '../pointer/index.mjs';
|
|
3
|
+
import { Clone } from '../clone/index.mjs';
|
|
4
|
+
import { Literal as CreateLiteral } from '../../type/literal/index.mjs';
|
|
5
|
+
import { Object as CreateObject } from '../../type/object/index.mjs';
|
|
6
|
+
import { String as CreateString } from '../../type/string/index.mjs';
|
|
7
|
+
import { Unknown as CreateUnknown } from '../../type/unknown/index.mjs';
|
|
8
|
+
import { Union as CreateUnion } from '../../type/union/index.mjs';
|
|
9
|
+
export const Insert = CreateObject({
|
|
10
|
+
type: CreateLiteral('insert'),
|
|
11
|
+
path: CreateString(),
|
|
12
|
+
value: CreateUnknown(),
|
|
13
|
+
});
|
|
14
|
+
export const Update = CreateObject({
|
|
15
|
+
type: CreateLiteral('update'),
|
|
16
|
+
path: CreateString(),
|
|
17
|
+
value: CreateUnknown(),
|
|
18
|
+
});
|
|
19
|
+
export const Delete = CreateObject({
|
|
20
|
+
type: CreateLiteral('delete'),
|
|
21
|
+
path: CreateString(),
|
|
22
|
+
});
|
|
23
|
+
export const Edit = CreateUnion([Insert, Update, Delete]);
|
|
24
|
+
export class ValueDeltaObjectWithSymbolKeyError extends Error {
|
|
25
|
+
key;
|
|
26
|
+
constructor(key) {
|
|
27
|
+
super('Cannot diff objects with symbol keys');
|
|
28
|
+
this.key = key;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class ValueDeltaUnableToDiffUnknownValue extends Error {
|
|
32
|
+
value;
|
|
33
|
+
constructor(value) {
|
|
34
|
+
super('Unable to create diff edits for unknown value');
|
|
35
|
+
this.value = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function CreateUpdate(path, value) {
|
|
39
|
+
return { type: 'update', path, value };
|
|
40
|
+
}
|
|
41
|
+
function CreateInsert(path, value) {
|
|
42
|
+
return { type: 'insert', path, value };
|
|
43
|
+
}
|
|
44
|
+
function CreateDelete(path) {
|
|
45
|
+
return { type: 'delete', path };
|
|
46
|
+
}
|
|
47
|
+
function* ObjectType(path, current, next) {
|
|
48
|
+
if (!IsPlainObject(next))
|
|
49
|
+
return yield CreateUpdate(path, next);
|
|
50
|
+
const currentKeys = [...globalThis.Object.keys(current), ...globalThis.Object.getOwnPropertySymbols(current)];
|
|
51
|
+
const nextKeys = [...globalThis.Object.keys(next), ...globalThis.Object.getOwnPropertySymbols(next)];
|
|
52
|
+
for (const key of currentKeys) {
|
|
53
|
+
if (IsSymbol(key))
|
|
54
|
+
throw new ValueDeltaObjectWithSymbolKeyError(key);
|
|
55
|
+
if (IsUndefined(next[key]) && nextKeys.includes(key))
|
|
56
|
+
yield CreateUpdate(`${path}/${globalThis.String(key)}`, undefined);
|
|
57
|
+
}
|
|
58
|
+
for (const key of nextKeys) {
|
|
59
|
+
if (IsUndefined(current[key]) || IsUndefined(next[key]))
|
|
60
|
+
continue;
|
|
61
|
+
if (IsSymbol(key))
|
|
62
|
+
throw new ValueDeltaObjectWithSymbolKeyError(key);
|
|
63
|
+
yield* Visit(`${path}/${globalThis.String(key)}`, current[key], next[key]);
|
|
64
|
+
}
|
|
65
|
+
for (const key of nextKeys) {
|
|
66
|
+
if (IsSymbol(key))
|
|
67
|
+
throw new ValueDeltaObjectWithSymbolKeyError(key);
|
|
68
|
+
if (IsUndefined(current[key]))
|
|
69
|
+
yield CreateInsert(`${path}/${globalThis.String(key)}`, next[key]);
|
|
70
|
+
}
|
|
71
|
+
for (const key of currentKeys.reverse()) {
|
|
72
|
+
if (IsSymbol(key))
|
|
73
|
+
throw new ValueDeltaObjectWithSymbolKeyError(key);
|
|
74
|
+
if (IsUndefined(next[key]) && !nextKeys.includes(key))
|
|
75
|
+
yield CreateDelete(`${path}/${globalThis.String(key)}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function* ArrayType(path, current, next) {
|
|
79
|
+
if (!IsArray(next))
|
|
80
|
+
return yield CreateUpdate(path, next);
|
|
81
|
+
for (let i = 0; i < Math.min(current.length, next.length); i++) {
|
|
82
|
+
yield* Visit(`${path}/${i}`, current[i], next[i]);
|
|
83
|
+
}
|
|
84
|
+
for (let i = 0; i < next.length; i++) {
|
|
85
|
+
if (i < current.length)
|
|
86
|
+
continue;
|
|
87
|
+
yield CreateInsert(`${path}/${i}`, next[i]);
|
|
88
|
+
}
|
|
89
|
+
for (let i = current.length - 1; i >= 0; i--) {
|
|
90
|
+
if (i < next.length)
|
|
91
|
+
continue;
|
|
92
|
+
yield CreateDelete(`${path}/${i}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function* TypedArrayType(path, current, next) {
|
|
96
|
+
if (!IsTypedArray(next) || current.length !== next.length || globalThis.Object.getPrototypeOf(current).constructor.name !== globalThis.Object.getPrototypeOf(next).constructor.name)
|
|
97
|
+
return yield CreateUpdate(path, next);
|
|
98
|
+
for (let i = 0; i < Math.min(current.length, next.length); i++) {
|
|
99
|
+
yield* Visit(`${path}/${i}`, current[i], next[i]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function* ValueType(path, current, next) {
|
|
103
|
+
if (current === next)
|
|
104
|
+
return;
|
|
105
|
+
yield CreateUpdate(path, next);
|
|
106
|
+
}
|
|
107
|
+
function* Visit(path, current, next) {
|
|
108
|
+
if (IsPlainObject(current))
|
|
109
|
+
return yield* ObjectType(path, current, next);
|
|
110
|
+
if (IsArray(current))
|
|
111
|
+
return yield* ArrayType(path, current, next);
|
|
112
|
+
if (IsTypedArray(current))
|
|
113
|
+
return yield* TypedArrayType(path, current, next);
|
|
114
|
+
if (IsValueType(current))
|
|
115
|
+
return yield* ValueType(path, current, next);
|
|
116
|
+
throw new ValueDeltaUnableToDiffUnknownValue(current);
|
|
117
|
+
}
|
|
118
|
+
export function Diff(current, next) {
|
|
119
|
+
return [...Visit('', current, next)];
|
|
120
|
+
}
|
|
121
|
+
function IsRootUpdate(edits) {
|
|
122
|
+
return edits.length > 0 && edits[0].path === '' && edits[0].type === 'update';
|
|
123
|
+
}
|
|
124
|
+
function IsIdentity(edits) {
|
|
125
|
+
return edits.length === 0;
|
|
126
|
+
}
|
|
127
|
+
export function Patch(current, edits) {
|
|
128
|
+
if (IsRootUpdate(edits)) {
|
|
129
|
+
return Clone(edits[0].value);
|
|
130
|
+
}
|
|
131
|
+
if (IsIdentity(edits)) {
|
|
132
|
+
return Clone(current);
|
|
133
|
+
}
|
|
134
|
+
const clone = Clone(current);
|
|
135
|
+
for (const edit of edits) {
|
|
136
|
+
switch (edit.type) {
|
|
137
|
+
case 'insert': {
|
|
138
|
+
ValuePointer.Set(clone, edit.path, edit.value);
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
case 'update': {
|
|
142
|
+
ValuePointer.Set(clone, edit.path, edit.value);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case 'delete': {
|
|
146
|
+
ValuePointer.Delete(clone, edit.path);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return clone;
|
|
152
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './delta.mjs';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class TypeDereferenceError extends Error {
|
|
2
|
+
schema;
|
|
3
|
+
constructor(schema) {
|
|
4
|
+
super(`Unable to dereference schema with $id '${schema.$id}'`);
|
|
5
|
+
this.schema = schema;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function Deref(schema, references) {
|
|
9
|
+
const index = references.findIndex((target) => target.$id === schema.$ref);
|
|
10
|
+
if (index === -1)
|
|
11
|
+
throw new TypeDereferenceError(schema);
|
|
12
|
+
return references[index];
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './deref.mjs';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IsPlainObject, IsDate, IsArray, IsTypedArray, IsValueType } from '../guard/index.mjs';
|
|
2
|
+
function ObjectType(left, right) {
|
|
3
|
+
if (!IsPlainObject(right))
|
|
4
|
+
return false;
|
|
5
|
+
const leftKeys = [...Object.keys(left), ...Object.getOwnPropertySymbols(left)];
|
|
6
|
+
const rightKeys = [...Object.keys(right), ...Object.getOwnPropertySymbols(right)];
|
|
7
|
+
if (leftKeys.length !== rightKeys.length)
|
|
8
|
+
return false;
|
|
9
|
+
return leftKeys.every((key) => Equal(left[key], right[key]));
|
|
10
|
+
}
|
|
11
|
+
function DateType(left, right) {
|
|
12
|
+
return IsDate(right) && left.getTime() === right.getTime();
|
|
13
|
+
}
|
|
14
|
+
function ArrayType(left, right) {
|
|
15
|
+
if (!IsArray(right) || left.length !== right.length)
|
|
16
|
+
return false;
|
|
17
|
+
return left.every((value, index) => Equal(value, right[index]));
|
|
18
|
+
}
|
|
19
|
+
function TypedArrayType(left, right) {
|
|
20
|
+
if (!IsTypedArray(right) || left.length !== right.length || Object.getPrototypeOf(left).constructor.name !== Object.getPrototypeOf(right).constructor.name)
|
|
21
|
+
return false;
|
|
22
|
+
return left.every((value, index) => Equal(value, right[index]));
|
|
23
|
+
}
|
|
24
|
+
function ValueType(left, right) {
|
|
25
|
+
return left === right;
|
|
26
|
+
}
|
|
27
|
+
export function Equal(left, right) {
|
|
28
|
+
if (IsPlainObject(left))
|
|
29
|
+
return ObjectType(left, right);
|
|
30
|
+
if (IsDate(left))
|
|
31
|
+
return DateType(left, right);
|
|
32
|
+
if (IsTypedArray(left))
|
|
33
|
+
return TypedArrayType(left, right);
|
|
34
|
+
if (IsArray(left))
|
|
35
|
+
return ArrayType(left, right);
|
|
36
|
+
if (IsValueType(left))
|
|
37
|
+
return ValueType(left, right);
|
|
38
|
+
throw new Error('ValueEquals: Unable to compare value');
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './equal.mjs';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function IsAsyncIterator(value) {
|
|
2
|
+
return IsObject(value) && Symbol.asyncIterator in value;
|
|
3
|
+
}
|
|
4
|
+
export function IsIterator(value) {
|
|
5
|
+
return IsObject(value) && Symbol.iterator in value;
|
|
6
|
+
}
|
|
7
|
+
export function IsTypedArray(value) {
|
|
8
|
+
return ArrayBuffer.isView(value);
|
|
9
|
+
}
|
|
10
|
+
export function IsPromise(value) {
|
|
11
|
+
return value instanceof Promise;
|
|
12
|
+
}
|
|
13
|
+
export function IsUint8Array(value) {
|
|
14
|
+
return value instanceof Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
export function IsDate(value) {
|
|
17
|
+
return value instanceof Date && Number.isFinite(value.getTime());
|
|
18
|
+
}
|
|
19
|
+
export function HasPropertyKey(value, key) {
|
|
20
|
+
return key in value;
|
|
21
|
+
}
|
|
22
|
+
export function IsPlainObject(value) {
|
|
23
|
+
return IsObject(value) && IsFunction(value.constructor) && value.constructor.name === 'Object';
|
|
24
|
+
}
|
|
25
|
+
export function IsObject(value) {
|
|
26
|
+
return value !== null && typeof value === 'object';
|
|
27
|
+
}
|
|
28
|
+
export function IsArray(value) {
|
|
29
|
+
return Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
30
|
+
}
|
|
31
|
+
export function IsUndefined(value) {
|
|
32
|
+
return value === undefined;
|
|
33
|
+
}
|
|
34
|
+
export function IsNull(value) {
|
|
35
|
+
return value === null;
|
|
36
|
+
}
|
|
37
|
+
export function IsBoolean(value) {
|
|
38
|
+
return typeof value === 'boolean';
|
|
39
|
+
}
|
|
40
|
+
export function IsNumber(value) {
|
|
41
|
+
return typeof value === 'number';
|
|
42
|
+
}
|
|
43
|
+
export function IsInteger(value) {
|
|
44
|
+
return IsNumber(value) && Number.isInteger(value);
|
|
45
|
+
}
|
|
46
|
+
export function IsBigInt(value) {
|
|
47
|
+
return typeof value === 'bigint';
|
|
48
|
+
}
|
|
49
|
+
export function IsString(value) {
|
|
50
|
+
return typeof value === 'string';
|
|
51
|
+
}
|
|
52
|
+
export function IsFunction(value) {
|
|
53
|
+
return typeof value === 'function';
|
|
54
|
+
}
|
|
55
|
+
export function IsSymbol(value) {
|
|
56
|
+
return typeof value === 'symbol';
|
|
57
|
+
}
|
|
58
|
+
export function IsValueType(value) {
|
|
59
|
+
return (IsBigInt(value) ||
|
|
60
|
+
IsBoolean(value) ||
|
|
61
|
+
IsNull(value) ||
|
|
62
|
+
IsNumber(value) ||
|
|
63
|
+
IsString(value) ||
|
|
64
|
+
IsSymbol(value) ||
|
|
65
|
+
IsUndefined(value));
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './guard.mjs';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { IsArray, IsBoolean, IsBigInt, IsDate, IsNull, IsNumber, IsPlainObject, IsString, IsSymbol, IsUint8Array, IsUndefined } from '../guard/index.mjs';
|
|
2
|
+
export class ValueHashError extends Error {
|
|
3
|
+
value;
|
|
4
|
+
constructor(value) {
|
|
5
|
+
super(`Unable to hash value`);
|
|
6
|
+
this.value = value;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
var ByteMarker;
|
|
10
|
+
(function (ByteMarker) {
|
|
11
|
+
ByteMarker[ByteMarker["Undefined"] = 0] = "Undefined";
|
|
12
|
+
ByteMarker[ByteMarker["Null"] = 1] = "Null";
|
|
13
|
+
ByteMarker[ByteMarker["Boolean"] = 2] = "Boolean";
|
|
14
|
+
ByteMarker[ByteMarker["Number"] = 3] = "Number";
|
|
15
|
+
ByteMarker[ByteMarker["String"] = 4] = "String";
|
|
16
|
+
ByteMarker[ByteMarker["Object"] = 5] = "Object";
|
|
17
|
+
ByteMarker[ByteMarker["Array"] = 6] = "Array";
|
|
18
|
+
ByteMarker[ByteMarker["Date"] = 7] = "Date";
|
|
19
|
+
ByteMarker[ByteMarker["Uint8Array"] = 8] = "Uint8Array";
|
|
20
|
+
ByteMarker[ByteMarker["Symbol"] = 9] = "Symbol";
|
|
21
|
+
ByteMarker[ByteMarker["BigInt"] = 10] = "BigInt";
|
|
22
|
+
})(ByteMarker || (ByteMarker = {}));
|
|
23
|
+
let Accumulator = BigInt('14695981039346656037');
|
|
24
|
+
const [Prime, Size] = [BigInt('1099511628211'), BigInt('2') ** BigInt('64')];
|
|
25
|
+
const Bytes = Array.from({ length: 256 }).map((_, i) => BigInt(i));
|
|
26
|
+
const F64 = new Float64Array(1);
|
|
27
|
+
const F64In = new DataView(F64.buffer);
|
|
28
|
+
const F64Out = new Uint8Array(F64.buffer);
|
|
29
|
+
function* NumberToBytes(value) {
|
|
30
|
+
const byteCount = value === 0 ? 1 : Math.ceil(Math.floor(Math.log2(value) + 1) / 8);
|
|
31
|
+
for (let i = 0; i < byteCount; i++) {
|
|
32
|
+
yield (value >> (8 * (byteCount - 1 - i))) & 0xff;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function ArrayType(value) {
|
|
36
|
+
FNV1A64(ByteMarker.Array);
|
|
37
|
+
for (const item of value) {
|
|
38
|
+
Visit(item);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function BooleanType(value) {
|
|
42
|
+
FNV1A64(ByteMarker.Boolean);
|
|
43
|
+
FNV1A64(value ? 1 : 0);
|
|
44
|
+
}
|
|
45
|
+
function BigIntType(value) {
|
|
46
|
+
FNV1A64(ByteMarker.BigInt);
|
|
47
|
+
F64In.setBigInt64(0, value);
|
|
48
|
+
for (const byte of F64Out) {
|
|
49
|
+
FNV1A64(byte);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function DateType(value) {
|
|
53
|
+
FNV1A64(ByteMarker.Date);
|
|
54
|
+
Visit(value.getTime());
|
|
55
|
+
}
|
|
56
|
+
function NullType(value) {
|
|
57
|
+
FNV1A64(ByteMarker.Null);
|
|
58
|
+
}
|
|
59
|
+
function NumberType(value) {
|
|
60
|
+
FNV1A64(ByteMarker.Number);
|
|
61
|
+
F64In.setFloat64(0, value);
|
|
62
|
+
for (const byte of F64Out) {
|
|
63
|
+
FNV1A64(byte);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function ObjectType(value) {
|
|
67
|
+
FNV1A64(ByteMarker.Object);
|
|
68
|
+
for (const key of globalThis.Object.keys(value).sort()) {
|
|
69
|
+
Visit(key);
|
|
70
|
+
Visit(value[key]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function StringType(value) {
|
|
74
|
+
FNV1A64(ByteMarker.String);
|
|
75
|
+
for (let i = 0; i < value.length; i++) {
|
|
76
|
+
for (const byte of NumberToBytes(value.charCodeAt(i))) {
|
|
77
|
+
FNV1A64(byte);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function SymbolType(value) {
|
|
82
|
+
FNV1A64(ByteMarker.Symbol);
|
|
83
|
+
Visit(value.description);
|
|
84
|
+
}
|
|
85
|
+
function Uint8ArrayType(value) {
|
|
86
|
+
FNV1A64(ByteMarker.Uint8Array);
|
|
87
|
+
for (let i = 0; i < value.length; i++) {
|
|
88
|
+
FNV1A64(value[i]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function UndefinedType(value) {
|
|
92
|
+
return FNV1A64(ByteMarker.Undefined);
|
|
93
|
+
}
|
|
94
|
+
function Visit(value) {
|
|
95
|
+
if (IsArray(value))
|
|
96
|
+
return ArrayType(value);
|
|
97
|
+
if (IsBoolean(value))
|
|
98
|
+
return BooleanType(value);
|
|
99
|
+
if (IsBigInt(value))
|
|
100
|
+
return BigIntType(value);
|
|
101
|
+
if (IsDate(value))
|
|
102
|
+
return DateType(value);
|
|
103
|
+
if (IsNull(value))
|
|
104
|
+
return NullType(value);
|
|
105
|
+
if (IsNumber(value))
|
|
106
|
+
return NumberType(value);
|
|
107
|
+
if (IsPlainObject(value))
|
|
108
|
+
return ObjectType(value);
|
|
109
|
+
if (IsString(value))
|
|
110
|
+
return StringType(value);
|
|
111
|
+
if (IsSymbol(value))
|
|
112
|
+
return SymbolType(value);
|
|
113
|
+
if (IsUint8Array(value))
|
|
114
|
+
return Uint8ArrayType(value);
|
|
115
|
+
if (IsUndefined(value))
|
|
116
|
+
return UndefinedType(value);
|
|
117
|
+
throw new ValueHashError(value);
|
|
118
|
+
}
|
|
119
|
+
function FNV1A64(byte) {
|
|
120
|
+
Accumulator = Accumulator ^ Bytes[byte];
|
|
121
|
+
Accumulator = (Accumulator * Prime) % Size;
|
|
122
|
+
}
|
|
123
|
+
export function Hash(value) {
|
|
124
|
+
Accumulator = BigInt('14695981039346656037');
|
|
125
|
+
Visit(value);
|
|
126
|
+
return Accumulator;
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hash.mjs';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
|
|
2
|
+
export { Cast, ValueCastArrayUniqueItemsTypeError, ValueCastNeverTypeError, ValueCastRecursiveTypeError, ValueCastUnknownTypeError } from './cast/index.mjs';
|
|
3
|
+
export { Check } from './check/index.mjs';
|
|
4
|
+
export { Clean } from './clean/index.mjs';
|
|
5
|
+
export { Clone } from './clone/index.mjs';
|
|
6
|
+
export { Convert, ValueConvertUnknownTypeError } from './convert/index.mjs';
|
|
7
|
+
export { Create, ValueCreateIntersectTypeError, ValueCreateNeverTypeError, ValueCreateNotTypeError, ValueCreateRecursiveInstantiationError, ValueCreateTempateLiteralTypeError, ValueCreateUnknownTypeError } from './create/index.mjs';
|
|
8
|
+
export { Default } from './default/index.mjs';
|
|
9
|
+
export { Diff, Patch, Edit, Delete, Insert, Update, ValueDeltaObjectWithSymbolKeyError, ValueDeltaUnableToDiffUnknownValue } from './delta/index.mjs';
|
|
10
|
+
export { Equal } from './equal/index.mjs';
|
|
11
|
+
export { Hash, ValueHashError } from './hash/index.mjs';
|
|
12
|
+
export { Mutate, ValueMutateInvalidRootMutationError, ValueMutateTypeMismatchError } from './mutate/index.mjs';
|
|
13
|
+
export { ValuePointer } from './pointer/index.mjs';
|
|
14
|
+
export { Decode, Encode, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index.mjs';
|
|
15
|
+
export { HasPropertyKey, IsArray, IsAsyncIterator, IsBigInt, IsBoolean, IsDate, IsFunction, IsInteger, IsIterator, IsNull, IsNumber, IsObject, IsPlainObject, IsPromise, IsString, IsSymbol, IsTypedArray, IsUint8Array, IsUndefined, IsValueType, } from './guard/index.mjs';
|
|
16
|
+
import { Value } from './value/index.mjs';
|
|
17
|
+
export { Value };
|
|
18
|
+
export default Value;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mutate.mjs';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { IsPlainObject, IsArray, IsTypedArray, IsValueType } from '../guard/index.mjs';
|
|
2
|
+
import { ValuePointer } from '../pointer/index.mjs';
|
|
3
|
+
import { Clone } from '../clone/index.mjs';
|
|
4
|
+
export class ValueMutateTypeMismatchError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super('Cannot assign due type mismatch of assignable values');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class ValueMutateInvalidRootMutationError extends Error {
|
|
10
|
+
constructor() {
|
|
11
|
+
super('Only object and array types can be mutated at the root level');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function ObjectType(root, path, current, next) {
|
|
15
|
+
if (!IsPlainObject(current)) {
|
|
16
|
+
ValuePointer.Set(root, path, Clone(next));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const currentKeys = Object.keys(current);
|
|
20
|
+
const nextKeys = Object.keys(next);
|
|
21
|
+
for (const currentKey of currentKeys) {
|
|
22
|
+
if (!nextKeys.includes(currentKey)) {
|
|
23
|
+
delete current[currentKey];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const nextKey of nextKeys) {
|
|
27
|
+
if (!currentKeys.includes(nextKey)) {
|
|
28
|
+
current[nextKey] = null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const nextKey of nextKeys) {
|
|
32
|
+
Visit(root, `${path}/${nextKey}`, current[nextKey], next[nextKey]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function ArrayType(root, path, current, next) {
|
|
37
|
+
if (!IsArray(current)) {
|
|
38
|
+
ValuePointer.Set(root, path, Clone(next));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
for (let index = 0; index < next.length; index++) {
|
|
42
|
+
Visit(root, `${path}/${index}`, current[index], next[index]);
|
|
43
|
+
}
|
|
44
|
+
current.splice(next.length);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function TypedArrayType(root, path, current, next) {
|
|
48
|
+
if (IsTypedArray(current) && current.length === next.length) {
|
|
49
|
+
for (let i = 0; i < current.length; i++) {
|
|
50
|
+
current[i] = next[i];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
ValuePointer.Set(root, path, Clone(next));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function ValueType(root, path, current, next) {
|
|
58
|
+
if (current === next)
|
|
59
|
+
return;
|
|
60
|
+
ValuePointer.Set(root, path, next);
|
|
61
|
+
}
|
|
62
|
+
function Visit(root, path, current, next) {
|
|
63
|
+
if (IsArray(next))
|
|
64
|
+
return ArrayType(root, path, current, next);
|
|
65
|
+
if (IsTypedArray(next))
|
|
66
|
+
return TypedArrayType(root, path, current, next);
|
|
67
|
+
if (IsPlainObject(next))
|
|
68
|
+
return ObjectType(root, path, current, next);
|
|
69
|
+
if (IsValueType(next))
|
|
70
|
+
return ValueType(root, path, current, next);
|
|
71
|
+
}
|
|
72
|
+
function IsNonMutableValue(value) {
|
|
73
|
+
return IsTypedArray(value) || IsValueType(value);
|
|
74
|
+
}
|
|
75
|
+
function IsMismatchedValue(current, next) {
|
|
76
|
+
return ((IsPlainObject(current) && IsArray(next)) ||
|
|
77
|
+
(IsArray(current) && IsPlainObject(next)));
|
|
78
|
+
}
|
|
79
|
+
export function Mutate(current, next) {
|
|
80
|
+
if (IsNonMutableValue(current) || IsNonMutableValue(next))
|
|
81
|
+
throw new ValueMutateInvalidRootMutationError();
|
|
82
|
+
if (IsMismatchedValue(current, next))
|
|
83
|
+
throw new ValueMutateTypeMismatchError();
|
|
84
|
+
Visit(current, '', current, next);
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as ValuePointer from './pointer.mjs';
|