@versionzero/schema 1.0.0
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/LICENSE +177 -0
- package/README.md +246 -0
- package/package.json +84 -0
- package/src/compilation/handler-compilation.js +28 -0
- package/src/compilation/metadata-compilation.js +35 -0
- package/src/compilation/schema-compilation.js +142 -0
- package/src/compilation/selection-compilation.js +84 -0
- package/src/compilation/union-compilation.js +510 -0
- package/src/compilation/values-compilation.js +35 -0
- package/src/compiled-schema.js +1709 -0
- package/src/constants.js +1 -0
- package/src/core-library/index.js +32 -0
- package/src/core-library/processors/aggregation-operators.js +75 -0
- package/src/core-library/processors/alpha-constraint.js +20 -0
- package/src/core-library/processors/alphanum-constraint.js +20 -0
- package/src/core-library/processors/array-operator.js +51 -0
- package/src/core-library/processors/assert-constraint.js +75 -0
- package/src/core-library/processors/base64-constraint.js +26 -0
- package/src/core-library/processors/camel-case-operator.js +24 -0
- package/src/core-library/processors/capitalize-operator.js +16 -0
- package/src/core-library/processors/cardnum-constraint.js +193 -0
- package/src/core-library/processors/ceil-operator.js +44 -0
- package/src/core-library/processors/collapse-operator.js +29 -0
- package/src/core-library/processors/compact-operator.js +34 -0
- package/src/core-library/processors/compile-operator.js +65 -0
- package/src/core-library/processors/concat-operator.js +51 -0
- package/src/core-library/processors/conditional-operators.js +301 -0
- package/src/core-library/processors/constant-case-operator.js +16 -0
- package/src/core-library/processors/data-size-operator.js +86 -0
- package/src/core-library/processors/date-object-operator.js +54 -0
- package/src/core-library/processors/date-operator.js +67 -0
- package/src/core-library/processors/date-range-constraint.js +76 -0
- package/src/core-library/processors/defined-constraint.js +30 -0
- package/src/core-library/processors/each-operator.js +57 -0
- package/src/core-library/processors/email-constraint.js +112 -0
- package/src/core-library/processors/entries-operator.js +25 -0
- package/src/core-library/processors/eq-constraint.js +37 -0
- package/src/core-library/processors/filter-operator.js +74 -0
- package/src/core-library/processors/find-schema-operator.js +45 -0
- package/src/core-library/processors/flatten-operator.js +40 -0
- package/src/core-library/processors/floor-operator.js +47 -0
- package/src/core-library/processors/get-operator.js +44 -0
- package/src/core-library/processors/group-by-operator.js +84 -0
- package/src/core-library/processors/has-prefix-constraint.js +37 -0
- package/src/core-library/processors/has-suffix-constraint.js +35 -0
- package/src/core-library/processors/hex-constraint.js +20 -0
- package/src/core-library/processors/hostname-constraint.js +22 -0
- package/src/core-library/processors/http-url-constraint.js +27 -0
- package/src/core-library/processors/in-constraint.js +66 -0
- package/src/core-library/processors/index-by-operator.js +98 -0
- package/src/core-library/processors/index.js +131 -0
- package/src/core-library/processors/input-operator.js +23 -0
- package/src/core-library/processors/instanceof-constraint.js +38 -0
- package/src/core-library/processors/integer-constraint.js +22 -0
- package/src/core-library/processors/invoke-operator.js +33 -0
- package/src/core-library/processors/ipv4-constraint.js +188 -0
- package/src/core-library/processors/ipv6-constraint.js +205 -0
- package/src/core-library/processors/is-array-constraint.js +21 -0
- package/src/core-library/processors/is-date-constraint.js +22 -0
- package/src/core-library/processors/is-number-constraint.js +21 -0
- package/src/core-library/processors/is-object-constraint.js +21 -0
- package/src/core-library/processors/is-string-constraint.js +21 -0
- package/src/core-library/processors/join-operator.js +41 -0
- package/src/core-library/processors/json-constraint.js +22 -0
- package/src/core-library/processors/json-decode-operator.js +25 -0
- package/src/core-library/processors/json-encode-operator.js +35 -0
- package/src/core-library/processors/kebab-case-operator.js +23 -0
- package/src/core-library/processors/keys-operator.js +20 -0
- package/src/core-library/processors/length-constraint.js +85 -0
- package/src/core-library/processors/lookup-operator.js +84 -0
- package/src/core-library/processors/lowercase-operator.js +14 -0
- package/src/core-library/processors/map-operator.js +84 -0
- package/src/core-library/processors/match-operator.js +64 -0
- package/src/core-library/processors/matches-constraint.js +54 -0
- package/src/core-library/processors/math-operators.js +151 -0
- package/src/core-library/processors/merge-deep-operator.js +61 -0
- package/src/core-library/processors/merge-operator.js +54 -0
- package/src/core-library/processors/metadata-operator.js +100 -0
- package/src/core-library/processors/negative-constraint.js +23 -0
- package/src/core-library/processors/never-constraint.js +69 -0
- package/src/core-library/processors/non-empty-constraint.js +59 -0
- package/src/core-library/processors/not-constraint.js +71 -0
- package/src/core-library/processors/number-operator.js +24 -0
- package/src/core-library/processors/numeric-constraint.js +22 -0
- package/src/core-library/processors/object-operator.js +38 -0
- package/src/core-library/processors/omit-operator.js +57 -0
- package/src/core-library/processors/parallel-operator.js +64 -0
- package/src/core-library/processors/pascal-case-operator.js +16 -0
- package/src/core-library/processors/phone-constraint.js +235 -0
- package/src/core-library/processors/pick-operator.js +62 -0
- package/src/core-library/processors/pipeline-operator.js +63 -0
- package/src/core-library/processors/port-constraint.js +22 -0
- package/src/core-library/processors/positive-constraint.js +23 -0
- package/src/core-library/processors/process-operator.js +55 -0
- package/src/core-library/processors/property-operator.js +49 -0
- package/src/core-library/processors/range-constraint.js +72 -0
- package/src/core-library/processors/reference-operator.js +79 -0
- package/src/core-library/processors/require-constraint.js +74 -0
- package/src/core-library/processors/reverse-operator.js +20 -0
- package/src/core-library/processors/round-operator.js +53 -0
- package/src/core-library/processors/schema-handler-operators.js +54 -0
- package/src/core-library/processors/semver-constraint.js +282 -0
- package/src/core-library/processors/sequence-processors.js +406 -0
- package/src/core-library/processors/sort-operator.js +52 -0
- package/src/core-library/processors/split-operator.js +43 -0
- package/src/core-library/processors/string-extra-operators.js +141 -0
- package/src/core-library/processors/string-operator.js +34 -0
- package/src/core-library/processors/target-operator.js +30 -0
- package/src/core-library/processors/template-operator.js +60 -0
- package/src/core-library/processors/title-case-operator.js +17 -0
- package/src/core-library/processors/trim-operator.js +14 -0
- package/src/core-library/processors/truthy-constraint.js +35 -0
- package/src/core-library/processors/type-operator.js +24 -0
- package/src/core-library/processors/unique-operator.js +21 -0
- package/src/core-library/processors/uppercase-operator.js +14 -0
- package/src/core-library/processors/url-constraint.js +31 -0
- package/src/core-library/processors/url-decode-operator.js +50 -0
- package/src/core-library/processors/url-encode-operator.js +44 -0
- package/src/core-library/processors/uuid-constraint.js +31 -0
- package/src/core-library/processors/values-operator.js +20 -0
- package/src/core-library/schemas/any-schema.js +23 -0
- package/src/core-library/schemas/array-schema.js +8 -0
- package/src/core-library/schemas/boolean-schema.js +10 -0
- package/src/core-library/schemas/date-schema.js +12 -0
- package/src/core-library/schemas/function-schema.js +40 -0
- package/src/core-library/schemas/number-schema.js +9 -0
- package/src/core-library/schemas/object-schema.js +10 -0
- package/src/core-library/schemas/root-schema.js +21 -0
- package/src/core-library/schemas/string-schema.js +9 -0
- package/src/core-library-node/index.js +47 -0
- package/src/core-library-node/processors/base64-decode-operator.js +20 -0
- package/src/core-library-node/processors/base64-encode-operator.js +20 -0
- package/src/core-library-node/processors/buffer-operator.js +39 -0
- package/src/core-library-node/processors/directory-constraint.js +35 -0
- package/src/core-library-node/processors/executable-constraint.js +34 -0
- package/src/core-library-node/processors/file-constraint.js +34 -0
- package/src/core-library-node/processors/file-size-constraint.js +94 -0
- package/src/core-library-node/processors/is-buffer-constraint.js +21 -0
- package/src/core-library-node/processors/reachable-constraint.js +28 -0
- package/src/core-library-node/processors/readable-constraint.js +34 -0
- package/src/core-library-node/processors/writable-constraint.js +59 -0
- package/src/core-library-node/schemas/buffer-schema.js +10 -0
- package/src/errors.js +209 -0
- package/src/executor/array-executor.js +78 -0
- package/src/executor/conditional-executor.js +134 -0
- package/src/executor/each-executor.js +68 -0
- package/src/executor/executor.js +123 -0
- package/src/executor/object-executor.js +98 -0
- package/src/executor/parallel-executor.js +43 -0
- package/src/executor/pipeline-executor.js +65 -0
- package/src/executor/sequence-executor.js +206 -0
- package/src/executor/serial-executor.js +24 -0
- package/src/executor/step-executor.js +68 -0
- package/src/helpers/case.js +124 -0
- package/src/helpers/data-size.js +144 -0
- package/src/helpers/debug-sink.js +15 -0
- package/src/helpers/deep.js +280 -0
- package/src/helpers/format.js +121 -0
- package/src/helpers/has-string-properties.js +30 -0
- package/src/helpers/index.js +16 -0
- package/src/helpers/object.js +115 -0
- package/src/helpers/parse-date.js +75 -0
- package/src/helpers/path.js +28 -0
- package/src/helpers/regex.js +18 -0
- package/src/helpers/stringify.js +309 -0
- package/src/helpers/to-data.js +64 -0
- package/src/helpers/truthy.js +55 -0
- package/src/index.js +29 -0
- package/src/schema-compiler.js +531 -0
- package/src/schema-location.js +200 -0
- package/src/schema-resolver.js +546 -0
- package/src/schema.js +1182 -0
- package/src/traversal/executors/check-condition.js +42 -0
- package/src/traversal/executors/check-input.js +27 -0
- package/src/traversal/executors/check-required.js +19 -0
- package/src/traversal/executors/check-schema.js +45 -0
- package/src/traversal/executors/defaults.js +21 -0
- package/src/traversal/executors/enter-existing.js +25 -0
- package/src/traversal/executors/enter-input.js +25 -0
- package/src/traversal/executors/enter.js +37 -0
- package/src/traversal/executors/exit.js +74 -0
- package/src/traversal/executors/finalize.js +64 -0
- package/src/traversal/executors/index.js +42 -0
- package/src/traversal/executors/normalize.js +38 -0
- package/src/traversal/executors/prepare-existing.js +27 -0
- package/src/traversal/executors/prepare-pending.js +54 -0
- package/src/traversal/executors/resolve-union.js +50 -0
- package/src/traversal/executors/serialize.js +48 -0
- package/src/traversal/executors/transform-early.js +51 -0
- package/src/traversal/executors/transform.js +68 -0
- package/src/traversal/executors/traversal-state-executor.js +46 -0
- package/src/traversal/executors/validate.js +63 -0
- package/src/traversal/traversal-context.js +231 -0
- package/src/traversal/traversal-state.js +809 -0
- package/src/types.js +102 -0
- package/src/value-processor/composed-value-processor.js +43 -0
- package/src/value-processor/defined-value-processor.js +72 -0
- package/src/value-processor/function-value-processor.js +68 -0
- package/src/value-processor/parameterized-value-processor.js +45 -0
- package/src/value-processor/parameters-value-processor.js +178 -0
- package/src/value-processor/spec.js +89 -0
- package/src/value-processor/value-processor.js +105 -0
- package/types/compilation/handler-compilation.d.ts +13 -0
- package/types/compilation/metadata-compilation.d.ts +6 -0
- package/types/compilation/schema-compilation.d.ts +32 -0
- package/types/compilation/selection-compilation.d.ts +9 -0
- package/types/compilation/union-compilation.d.ts +42 -0
- package/types/compilation/values-compilation.d.ts +12 -0
- package/types/compiled-schema.d.ts +883 -0
- package/types/constants.d.ts +1 -0
- package/types/core-library/index.d.ts +7 -0
- package/types/core-library/processors/aggregation-operators.d.ts +24 -0
- package/types/core-library/processors/alpha-constraint.d.ts +9 -0
- package/types/core-library/processors/alphanum-constraint.d.ts +9 -0
- package/types/core-library/processors/array-operator.d.ts +12 -0
- package/types/core-library/processors/assert-constraint.d.ts +30 -0
- package/types/core-library/processors/base64-constraint.d.ts +11 -0
- package/types/core-library/processors/camel-case-operator.d.ts +17 -0
- package/types/core-library/processors/capitalize-operator.d.ts +11 -0
- package/types/core-library/processors/cardnum-constraint.d.ts +51 -0
- package/types/core-library/processors/ceil-operator.d.ts +30 -0
- package/types/core-library/processors/collapse-operator.d.ts +24 -0
- package/types/core-library/processors/compact-operator.d.ts +29 -0
- package/types/core-library/processors/compile-operator.d.ts +34 -0
- package/types/core-library/processors/concat-operator.d.ts +23 -0
- package/types/core-library/processors/conditional-operators.d.ts +219 -0
- package/types/core-library/processors/constant-case-operator.d.ts +9 -0
- package/types/core-library/processors/data-size-operator.d.ts +31 -0
- package/types/core-library/processors/date-object-operator.d.ts +16 -0
- package/types/core-library/processors/date-operator.d.ts +21 -0
- package/types/core-library/processors/date-range-constraint.d.ts +26 -0
- package/types/core-library/processors/defined-constraint.d.ts +20 -0
- package/types/core-library/processors/each-operator.d.ts +34 -0
- package/types/core-library/processors/email-constraint.d.ts +54 -0
- package/types/core-library/processors/entries-operator.d.ts +13 -0
- package/types/core-library/processors/eq-constraint.d.ts +20 -0
- package/types/core-library/processors/filter-operator.d.ts +35 -0
- package/types/core-library/processors/find-schema-operator.d.ts +28 -0
- package/types/core-library/processors/flatten-operator.d.ts +26 -0
- package/types/core-library/processors/floor-operator.d.ts +33 -0
- package/types/core-library/processors/get-operator.d.ts +31 -0
- package/types/core-library/processors/group-by-operator.d.ts +36 -0
- package/types/core-library/processors/has-prefix-constraint.d.ts +22 -0
- package/types/core-library/processors/has-suffix-constraint.d.ts +20 -0
- package/types/core-library/processors/hex-constraint.d.ts +9 -0
- package/types/core-library/processors/hostname-constraint.d.ts +11 -0
- package/types/core-library/processors/http-url-constraint.d.ts +9 -0
- package/types/core-library/processors/in-constraint.d.ts +27 -0
- package/types/core-library/processors/index-by-operator.d.ts +26 -0
- package/types/core-library/processors/index.d.ts +8 -0
- package/types/core-library/processors/input-operator.d.ts +20 -0
- package/types/core-library/processors/instanceof-constraint.d.ts +23 -0
- package/types/core-library/processors/integer-constraint.d.ts +9 -0
- package/types/core-library/processors/invoke-operator.d.ts +12 -0
- package/types/core-library/processors/ipv4-constraint.d.ts +37 -0
- package/types/core-library/processors/ipv6-constraint.d.ts +34 -0
- package/types/core-library/processors/is-array-constraint.d.ts +10 -0
- package/types/core-library/processors/is-date-constraint.d.ts +10 -0
- package/types/core-library/processors/is-number-constraint.d.ts +10 -0
- package/types/core-library/processors/is-object-constraint.d.ts +10 -0
- package/types/core-library/processors/is-string-constraint.d.ts +10 -0
- package/types/core-library/processors/join-operator.d.ts +29 -0
- package/types/core-library/processors/json-constraint.d.ts +10 -0
- package/types/core-library/processors/json-decode-operator.d.ts +9 -0
- package/types/core-library/processors/json-encode-operator.d.ts +27 -0
- package/types/core-library/processors/kebab-case-operator.d.ts +16 -0
- package/types/core-library/processors/keys-operator.d.ts +9 -0
- package/types/core-library/processors/length-constraint.d.ts +34 -0
- package/types/core-library/processors/lookup-operator.d.ts +36 -0
- package/types/core-library/processors/lowercase-operator.d.ts +9 -0
- package/types/core-library/processors/map-operator.d.ts +38 -0
- package/types/core-library/processors/match-operator.d.ts +34 -0
- package/types/core-library/processors/matches-constraint.d.ts +29 -0
- package/types/core-library/processors/math-operators.d.ts +91 -0
- package/types/core-library/processors/merge-deep-operator.d.ts +32 -0
- package/types/core-library/processors/merge-operator.d.ts +26 -0
- package/types/core-library/processors/metadata-operator.d.ts +56 -0
- package/types/core-library/processors/negative-constraint.d.ts +13 -0
- package/types/core-library/processors/never-constraint.d.ts +26 -0
- package/types/core-library/processors/non-empty-constraint.d.ts +28 -0
- package/types/core-library/processors/not-constraint.d.ts +28 -0
- package/types/core-library/processors/number-operator.d.ts +9 -0
- package/types/core-library/processors/numeric-constraint.d.ts +10 -0
- package/types/core-library/processors/object-operator.d.ts +10 -0
- package/types/core-library/processors/omit-operator.d.ts +24 -0
- package/types/core-library/processors/parallel-operator.d.ts +41 -0
- package/types/core-library/processors/pascal-case-operator.d.ts +9 -0
- package/types/core-library/processors/phone-constraint.d.ts +65 -0
- package/types/core-library/processors/pick-operator.d.ts +27 -0
- package/types/core-library/processors/pipeline-operator.d.ts +40 -0
- package/types/core-library/processors/port-constraint.d.ts +11 -0
- package/types/core-library/processors/positive-constraint.d.ts +13 -0
- package/types/core-library/processors/process-operator.d.ts +37 -0
- package/types/core-library/processors/property-operator.d.ts +34 -0
- package/types/core-library/processors/range-constraint.d.ts +30 -0
- package/types/core-library/processors/reference-operator.d.ts +38 -0
- package/types/core-library/processors/require-constraint.d.ts +29 -0
- package/types/core-library/processors/reverse-operator.d.ts +9 -0
- package/types/core-library/processors/round-operator.d.ts +34 -0
- package/types/core-library/processors/schema-handler-operators.d.ts +28 -0
- package/types/core-library/processors/semver-constraint.d.ts +43 -0
- package/types/core-library/processors/sequence-processors.d.ts +213 -0
- package/types/core-library/processors/sort-operator.d.ts +31 -0
- package/types/core-library/processors/split-operator.d.ts +33 -0
- package/types/core-library/processors/string-extra-operators.d.ts +83 -0
- package/types/core-library/processors/string-operator.d.ts +10 -0
- package/types/core-library/processors/target-operator.d.ts +27 -0
- package/types/core-library/processors/template-operator.d.ts +31 -0
- package/types/core-library/processors/title-case-operator.d.ts +12 -0
- package/types/core-library/processors/trim-operator.d.ts +9 -0
- package/types/core-library/processors/truthy-constraint.d.ts +23 -0
- package/types/core-library/processors/type-operator.d.ts +11 -0
- package/types/core-library/processors/unique-operator.d.ts +10 -0
- package/types/core-library/processors/uppercase-operator.d.ts +9 -0
- package/types/core-library/processors/url-constraint.d.ts +20 -0
- package/types/core-library/processors/url-decode-operator.d.ts +31 -0
- package/types/core-library/processors/url-encode-operator.d.ts +36 -0
- package/types/core-library/processors/uuid-constraint.d.ts +20 -0
- package/types/core-library/processors/values-operator.d.ts +9 -0
- package/types/core-library/schemas/any-schema.d.ts +2 -0
- package/types/core-library/schemas/array-schema.d.ts +2 -0
- package/types/core-library/schemas/boolean-schema.d.ts +2 -0
- package/types/core-library/schemas/date-schema.d.ts +2 -0
- package/types/core-library/schemas/function-schema.d.ts +2 -0
- package/types/core-library/schemas/number-schema.d.ts +2 -0
- package/types/core-library/schemas/object-schema.d.ts +2 -0
- package/types/core-library/schemas/root-schema.d.ts +2 -0
- package/types/core-library/schemas/string-schema.d.ts +2 -0
- package/types/core-library-node/index.d.ts +12 -0
- package/types/core-library-node/processors/base64-decode-operator.d.ts +9 -0
- package/types/core-library-node/processors/base64-encode-operator.d.ts +9 -0
- package/types/core-library-node/processors/buffer-operator.d.ts +15 -0
- package/types/core-library-node/processors/directory-constraint.d.ts +14 -0
- package/types/core-library-node/processors/executable-constraint.d.ts +17 -0
- package/types/core-library-node/processors/file-constraint.d.ts +13 -0
- package/types/core-library-node/processors/file-size-constraint.d.ts +43 -0
- package/types/core-library-node/processors/is-buffer-constraint.d.ts +10 -0
- package/types/core-library-node/processors/reachable-constraint.d.ts +13 -0
- package/types/core-library-node/processors/readable-constraint.d.ts +17 -0
- package/types/core-library-node/processors/writable-constraint.d.ts +18 -0
- package/types/core-library-node/schemas/buffer-schema.d.ts +2 -0
- package/types/errors.d.ts +58 -0
- package/types/executor/array-executor.d.ts +17 -0
- package/types/executor/conditional-executor.d.ts +45 -0
- package/types/executor/each-executor.d.ts +15 -0
- package/types/executor/executor.d.ts +84 -0
- package/types/executor/object-executor.d.ts +14 -0
- package/types/executor/parallel-executor.d.ts +27 -0
- package/types/executor/pipeline-executor.d.ts +11 -0
- package/types/executor/sequence-executor.d.ts +32 -0
- package/types/executor/serial-executor.d.ts +16 -0
- package/types/executor/step-executor.d.ts +14 -0
- package/types/helpers/case.d.ts +30 -0
- package/types/helpers/data-size.d.ts +25 -0
- package/types/helpers/debug-sink.d.ts +9 -0
- package/types/helpers/deep.d.ts +33 -0
- package/types/helpers/format.d.ts +14 -0
- package/types/helpers/has-string-properties.d.ts +5 -0
- package/types/helpers/index.d.ts +13 -0
- package/types/helpers/object.d.ts +46 -0
- package/types/helpers/parse-date.d.ts +6 -0
- package/types/helpers/path.d.ts +13 -0
- package/types/helpers/regex.d.ts +7 -0
- package/types/helpers/stringify.d.ts +33 -0
- package/types/helpers/to-data.d.ts +13 -0
- package/types/helpers/truthy.d.ts +26 -0
- package/types/index.d.ts +6 -0
- package/types/schema-compiler.d.ts +49 -0
- package/types/schema-location.d.ts +64 -0
- package/types/schema-resolver.d.ts +145 -0
- package/types/schema.d.ts +586 -0
- package/types/traversal/executors/check-condition.d.ts +8 -0
- package/types/traversal/executors/check-input.d.ts +6 -0
- package/types/traversal/executors/check-required.d.ts +6 -0
- package/types/traversal/executors/check-schema.d.ts +7 -0
- package/types/traversal/executors/defaults.d.ts +8 -0
- package/types/traversal/executors/enter-existing.d.ts +6 -0
- package/types/traversal/executors/enter-input.d.ts +8 -0
- package/types/traversal/executors/enter.d.ts +7 -0
- package/types/traversal/executors/exit.d.ts +6 -0
- package/types/traversal/executors/finalize.d.ts +6 -0
- package/types/traversal/executors/index.d.ts +15 -0
- package/types/traversal/executors/normalize.d.ts +7 -0
- package/types/traversal/executors/prepare-existing.d.ts +6 -0
- package/types/traversal/executors/prepare-pending.d.ts +6 -0
- package/types/traversal/executors/resolve-union.d.ts +6 -0
- package/types/traversal/executors/serialize.d.ts +11 -0
- package/types/traversal/executors/transform-early.d.ts +6 -0
- package/types/traversal/executors/transform.d.ts +6 -0
- package/types/traversal/executors/traversal-state-executor.d.ts +19 -0
- package/types/traversal/executors/validate.d.ts +6 -0
- package/types/traversal/traversal-context.d.ts +67 -0
- package/types/traversal/traversal-state.d.ts +97 -0
- package/types/types.d.ts +218 -0
- package/types/value-processor/composed-value-processor.d.ts +17 -0
- package/types/value-processor/defined-value-processor.d.ts +16 -0
- package/types/value-processor/function-value-processor.d.ts +15 -0
- package/types/value-processor/parameterized-value-processor.d.ts +14 -0
- package/types/value-processor/parameters-value-processor.d.ts +28 -0
- package/types/value-processor/spec.d.ts +22 -0
- package/types/value-processor/value-processor.d.ts +92 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check whether we have a passing condition.
|
|
5
|
+
*
|
|
6
|
+
* @param {TraversalState} state
|
|
7
|
+
* @returns {TraversalState|null|undefined|Promise<TraversalState|null|undefined>}
|
|
8
|
+
*/
|
|
9
|
+
export function checkCondition(state) {
|
|
10
|
+
// once we have passed the condition check, it's locked in
|
|
11
|
+
if (state.condition === true) {
|
|
12
|
+
return state;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (state.schema === undefined) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//const value = state.pending ?? state.input ?? state.value;
|
|
20
|
+
// todo - think about this:
|
|
21
|
+
// resolve-union uses pending/input/value like the snippet I extracted above, why is condition just using input?
|
|
22
|
+
// hmm, pending will never contain any children before the condition returns true...
|
|
23
|
+
// possibility: allow pending to build up but never be transformed?
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const result = state.schema._checkCondition(state.input, state.context.getValue(), state.location, state.options);
|
|
27
|
+
|
|
28
|
+
const handleConditionResult = (result) => {
|
|
29
|
+
state.condition = result;
|
|
30
|
+
if (!result && state.context.final) {
|
|
31
|
+
state.value = null;
|
|
32
|
+
}
|
|
33
|
+
return result ? state : (state.context.final ? null : undefined);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (result instanceof Promise) {
|
|
37
|
+
return result.then(resolved => {
|
|
38
|
+
return handleConditionResult(resolved);
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
return handleConditionResult(result);
|
|
42
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {TraversalState} state
|
|
5
|
+
* @returns {TraversalState|null|undefined}
|
|
6
|
+
*/
|
|
7
|
+
export function checkInput(state) {
|
|
8
|
+
|
|
9
|
+
if (state.input === null) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (state.schema === undefined) { //} || state.schema.isImplicit) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if (state.schema.isImplicit) {
|
|
16
|
+
return state;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// we can't check whether undefined is accepted
|
|
20
|
+
if (state.input === undefined) {
|
|
21
|
+
return state;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
state.schema.ensureAccepts(state.input);
|
|
25
|
+
|
|
26
|
+
return state;
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
|
|
3
|
+
import { ValidationError } from '../../errors.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {TraversalState} state
|
|
7
|
+
* @returns {TraversalState}
|
|
8
|
+
*/
|
|
9
|
+
export function checkRequired(state) {
|
|
10
|
+
|
|
11
|
+
if (!state.condition) {
|
|
12
|
+
return state;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (state.context.final && state.isRequired && (state.value === undefined)) {
|
|
16
|
+
throw new ValidationError('Undefined required value', {path: state.path})
|
|
17
|
+
}
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
|
|
3
|
+
import { ValidationError } from '../../errors.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {TraversalState} state
|
|
8
|
+
* @returns {TraversalState|undefined|null}
|
|
9
|
+
*/
|
|
10
|
+
export function checkSchema(state) {
|
|
11
|
+
|
|
12
|
+
if (state.schema !== undefined) {
|
|
13
|
+
// If we have a schema, we're good to go.
|
|
14
|
+
return state;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parentState = state.parent;
|
|
18
|
+
|
|
19
|
+
if (parentState === undefined) {
|
|
20
|
+
throw new ValidationError('invariant: root path schema must be defined');
|
|
21
|
+
}
|
|
22
|
+
if (parentState.schema === undefined) {
|
|
23
|
+
throw new ValidationError('invariant: cannot process a child if parent schema is undefined');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!parentState.schema.isUnion || state.context.final) {
|
|
27
|
+
// invalid property detected
|
|
28
|
+
const strict = parentState?.schema?.strict ?? parentState?.context.strict;
|
|
29
|
+
if (strict) {
|
|
30
|
+
// current schema may not be a union because we resolved successfully; check the path from the root.
|
|
31
|
+
const pathExists = state.context.root.schema?.isValidPath(state.path);
|
|
32
|
+
const message = pathExists ? 'Unexpected property' : 'Unknown property';
|
|
33
|
+
throw new ValidationError(message, {path: state.path});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// prune
|
|
37
|
+
state.value = null;
|
|
38
|
+
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TraversalState } from "../traversal-state.js";
|
|
2
|
+
import { EMPTY } from '../../constants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* If the input is undefined but the schema defines a default, use that value
|
|
6
|
+
*
|
|
7
|
+
* @param {TraversalState} state
|
|
8
|
+
* @returns {TraversalState}
|
|
9
|
+
*/
|
|
10
|
+
export function defaults(state) {
|
|
11
|
+
if (state.assignedInput === undefined && state.pending === undefined && state.value === undefined) {
|
|
12
|
+
if (state.schema?.default !== undefined) {
|
|
13
|
+
state.assignedInput = state.schema.default;
|
|
14
|
+
state.mandatory = true; // does this need to be earlier?
|
|
15
|
+
}
|
|
16
|
+
else if (state.isDeep && state.isContainer) {
|
|
17
|
+
state.assignedInput = EMPTY;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return state;
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TraversalState } from "../traversal-state.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {TraversalState} state
|
|
5
|
+
* @returns {TraversalState|null|undefined}
|
|
6
|
+
*/
|
|
7
|
+
export function enterExisting(state) {
|
|
8
|
+
if (state.assignedInput === undefined && state.parent) {
|
|
9
|
+
state.assignedInput = state.parent.input?.[state.key];
|
|
10
|
+
}
|
|
11
|
+
if (state.isPruned) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
if (state.completed) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
state.input = state.assignedInput;
|
|
19
|
+
|
|
20
|
+
if (state.schema !== undefined) {
|
|
21
|
+
state.pending = state.input;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* @param {TraversalState} state
|
|
7
|
+
* @returns {TraversalState|null|undefined}
|
|
8
|
+
*/
|
|
9
|
+
export function enterInput(state) {
|
|
10
|
+
const parentState = state.parent;
|
|
11
|
+
|
|
12
|
+
if (parentState) {
|
|
13
|
+
state.assignedInput ??= parentState.input?.[state.key];
|
|
14
|
+
}
|
|
15
|
+
state.input ??= state.assignedInput;
|
|
16
|
+
|
|
17
|
+
if (state.isPruned) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
if (state.completed) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
import { EMPTY } from '../../constants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {TraversalState} state
|
|
7
|
+
* @returns {TraversalState|undefined|null}
|
|
8
|
+
*/
|
|
9
|
+
export function enter(state) {
|
|
10
|
+
|
|
11
|
+
const parentState = state.parent;
|
|
12
|
+
|
|
13
|
+
if (parentState) {
|
|
14
|
+
if (state.assignedInput === undefined || state.assignedInput === EMPTY) {
|
|
15
|
+
// we generally have our assigned input pushed down
|
|
16
|
+
const input = parentState.input?.[state.key];
|
|
17
|
+
|
|
18
|
+
if (input !== undefined) {
|
|
19
|
+
state.assignedInput = input;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (state.schema?.isImplicit && !state.isPruned ) {
|
|
23
|
+
state.value ??= parentState.value?.[state.key]; // fixme ?
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (state.isPruned) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (state.completed) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
// if (state.isComplete) {
|
|
33
|
+
// return undefined;
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
return state;
|
|
37
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
import { SchemaError } from '../../errors.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {TraversalState} state
|
|
6
|
+
* @returns {TraversalState|null|undefined|Promise<TraversalState|null|undefined>}
|
|
7
|
+
*/
|
|
8
|
+
export function exit(state) {
|
|
9
|
+
if (state.value === null) {
|
|
10
|
+
return state;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (state.value === undefined) {
|
|
14
|
+
if (state.input !== undefined) {
|
|
15
|
+
return state;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (state.completed) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const parentState = state.parent;
|
|
24
|
+
|
|
25
|
+
// todo - should we fast-out if previously completed?
|
|
26
|
+
state.completed = state.isComplete;
|
|
27
|
+
|
|
28
|
+
if (parentState === undefined) {
|
|
29
|
+
// We're processing the root, so we don't need to copy our value anywhere.
|
|
30
|
+
// As long as we are not a union, mark outselves as processed.
|
|
31
|
+
if (!state.isUnion) {
|
|
32
|
+
state.processed = true;
|
|
33
|
+
}
|
|
34
|
+
return state;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const parentContainer = parentState.pending ?? parentState.value;
|
|
38
|
+
|
|
39
|
+
if (parentContainer === null) {
|
|
40
|
+
// oops, we shouldn't even be here!
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (parentContainer === undefined || (typeof parentContainer !== 'object')) {
|
|
45
|
+
// try to be helpful
|
|
46
|
+
let stringifiedParentContainer = `${parentContainer}`;
|
|
47
|
+
if (stringifiedParentContainer.length > 20) {
|
|
48
|
+
stringifiedParentContainer = stringifiedParentContainer.slice(0, 20) + '...'
|
|
49
|
+
}
|
|
50
|
+
const message = stringifiedParentContainer.length?
|
|
51
|
+
`«${stringifiedParentContainer}» is not a valid container (set opaque option?)`
|
|
52
|
+
: 'Not a valid container (set opaque option?)'
|
|
53
|
+
|
|
54
|
+
throw new SchemaError(message, {path: parentState.path});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const key = state.key;
|
|
58
|
+
|
|
59
|
+
if (state.schema?.isImplicit) {
|
|
60
|
+
state.value ??= parentContainer[key]; // set this so that children can use this as a container
|
|
61
|
+
state.processed = true;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (parentContainer[key] !== state.value) {
|
|
65
|
+
parentContainer[key] = state.value;
|
|
66
|
+
state.context.update(); // todo - monitor whether this triggers too many extra passes for complex deps!
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!state.isUnion) {
|
|
70
|
+
state.processed = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return state;
|
|
74
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
import { FinalizeError } from '../../errors.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {TraversalState} state
|
|
6
|
+
* @returns {TraversalState|undefined|Promise<TraversalState|undefined>}
|
|
7
|
+
*/
|
|
8
|
+
export function finalize(state) {
|
|
9
|
+
if (state.completed) {
|
|
10
|
+
return state;
|
|
11
|
+
}
|
|
12
|
+
if (state.schema === undefined) {
|
|
13
|
+
if (state.allowUnknown) {
|
|
14
|
+
return state;
|
|
15
|
+
}
|
|
16
|
+
throw new FinalizeError('Unknown value', {path: state.path});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!state.schema.requiresFinalization) {
|
|
20
|
+
return state;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const doFinalization = state.context.final || state.isComplete;
|
|
24
|
+
|
|
25
|
+
if (!doFinalization) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (state.schema.isUnion) {
|
|
30
|
+
throw new FinalizeError('Unable to resolve union', {path: state.path})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// todo - block reference schemas from having finalizers
|
|
34
|
+
if (state.value === undefined && state.schema.isReference && !state.isRequired) {
|
|
35
|
+
return state;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (state.hasWorkInProgress) {
|
|
39
|
+
if (state.value === undefined && !state.isRequired) {
|
|
40
|
+
return state;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const foo = state.hasWorkInProgress;
|
|
44
|
+
throw new FinalizeError(`Incomplete assignment`, {value: state.pending, path: state.path});
|
|
45
|
+
}
|
|
46
|
+
if (state.value === undefined) {
|
|
47
|
+
return state;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const result = state.schema._finalizeValue(state.value, state.target, state.location, state.options);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {any} finalized
|
|
54
|
+
* @returns {TraversalState}
|
|
55
|
+
*/
|
|
56
|
+
const updateState = (finalized) => {
|
|
57
|
+
if (finalized !== state.value) {
|
|
58
|
+
state.value = finalized;
|
|
59
|
+
}
|
|
60
|
+
return state;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (result instanceof Promise)? result.then(updateState) : updateState(result);
|
|
64
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { StepExecutor } from '../../executor/step-executor.js';
|
|
2
|
+
import { Executor } from "../../executor/executor.js";
|
|
3
|
+
import { TraversalState } from "../traversal-state.js";
|
|
4
|
+
import { enter } from './enter.js';
|
|
5
|
+
import { checkSchema } from './check-schema.js';
|
|
6
|
+
import { defaults } from './defaults.js';
|
|
7
|
+
import { normalize } from './normalize.js';
|
|
8
|
+
import { checkInput } from './check-input.js';
|
|
9
|
+
import { resolveUnion } from './resolve-union.js';
|
|
10
|
+
import { checkCondition } from './check-condition.js';
|
|
11
|
+
import { preparePending } from './prepare-pending.js';
|
|
12
|
+
import { transformEarly } from './transform-early.js';
|
|
13
|
+
import { transform } from './transform.js';
|
|
14
|
+
import { checkRequired } from './check-required.js';
|
|
15
|
+
import { validate } from './validate.js';
|
|
16
|
+
import { exit } from './exit.js';
|
|
17
|
+
|
|
18
|
+
import { enterInput } from './enter-input.js';
|
|
19
|
+
import { enterExisting } from './enter-existing.js';
|
|
20
|
+
import { prepareExisting } from './prepare-existing.js';
|
|
21
|
+
import { serialize } from './serialize.js';
|
|
22
|
+
import { finalize } from './finalize.js';
|
|
23
|
+
import { TraversalStateExecutor } from './traversal-state-executor.js';
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export const PROCESS_ENTER = /** @type {Executor<TraversalState>} */ (new StepExecutor([enter, checkSchema, defaults, normalize, checkInput, resolveUnion, checkCondition, preparePending, transformEarly]));
|
|
27
|
+
export const PROCESS_EXIT = /** @type {Executor<TraversalState>} */ (new StepExecutor([transform, finalize, checkRequired, validate, exit]));
|
|
28
|
+
export const PROCESS_EXECUTOR = new TraversalStateExecutor(PROCESS_ENTER, PROCESS_EXIT);
|
|
29
|
+
|
|
30
|
+
export const VALIDATE_ENTER = /** @type {Executor<TraversalState>} */ (new StepExecutor([enterExisting, resolveUnion, checkCondition, prepareExisting]));
|
|
31
|
+
export const VALIDATE_EXIT = /** @type {Executor<TraversalState>} */ (new StepExecutor([checkRequired, validate, exit]));
|
|
32
|
+
export const VALIDATE_EXECUTOR = new TraversalStateExecutor(VALIDATE_ENTER, VALIDATE_EXIT);
|
|
33
|
+
|
|
34
|
+
export const SERIALIZE_ENTER = /** @type {Executor<TraversalState>} */ (new StepExecutor([enter, checkSchema, serialize, resolveUnion, checkCondition ]));
|
|
35
|
+
export const SERIALIZE_EXIT = /** @type {Executor<TraversalState>} */ (new StepExecutor([exit]));
|
|
36
|
+
export const SERIALIZE_EXECUTOR = new TraversalStateExecutor(SERIALIZE_ENTER, SERIALIZE_EXIT);
|
|
37
|
+
|
|
38
|
+
export const PRELOAD_ENTER = /** @type {Executor<TraversalState>} */ (new StepExecutor([enterExisting, prepareExisting]));
|
|
39
|
+
export const PRELOAD_EXIT = /** @type {Executor<TraversalState>} */ (new StepExecutor([exit]));
|
|
40
|
+
export const PRELOAD_EXECUTOR = new TraversalStateExecutor(PRELOAD_ENTER, PRELOAD_EXIT);
|
|
41
|
+
|
|
42
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalize the assigned input value
|
|
5
|
+
* @param {TraversalState} state
|
|
6
|
+
* @returns {TraversalState|null|undefined|Promise<TraversalState|null|undefined>}
|
|
7
|
+
*/
|
|
8
|
+
export function normalize(state) {
|
|
9
|
+
if (state.processed && state.hasProcessedInput) {
|
|
10
|
+
// fast-out to avoid renormalization if possible
|
|
11
|
+
return state;
|
|
12
|
+
}
|
|
13
|
+
if (state.assignedInput === null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (state.assignedInput === undefined) {
|
|
17
|
+
return state;
|
|
18
|
+
}
|
|
19
|
+
if (state.location === undefined) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const schema = state.location.schema;
|
|
23
|
+
const normalized = schema._normalizeValue(state.assignedInput, state.target, state.location, state.options);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {any} normalized
|
|
27
|
+
* @returns {TraversalState|null}
|
|
28
|
+
*/
|
|
29
|
+
const updateState = (normalized) => {
|
|
30
|
+
state.input = normalized;
|
|
31
|
+
|
|
32
|
+
if (normalized === null) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return state;
|
|
36
|
+
}
|
|
37
|
+
return (normalized instanceof Promise)? normalized.then(updateState) : updateState(normalized);
|
|
38
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {TraversalState} state
|
|
5
|
+
* @returns {TraversalState|undefined}
|
|
6
|
+
*/
|
|
7
|
+
export function prepareExisting(state) {
|
|
8
|
+
if (state.schema === undefined) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (state.input === undefined) {
|
|
13
|
+
if (!state.schema.options.allowUndefined) {
|
|
14
|
+
return state;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (state.isUnion) {
|
|
19
|
+
state.pending ??= state.input;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
state.value = state.pending ?? state.input;
|
|
23
|
+
state.pending = undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return state;
|
|
27
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
import { EMPTY } from '../../constants.js';
|
|
3
|
+
import { SchemaError } from '../../errors.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {TraversalState} state
|
|
8
|
+
* @returns {TraversalState|undefined|null|Promise<TraversalState|undefined|null>}
|
|
9
|
+
*/
|
|
10
|
+
export function preparePending(state) {
|
|
11
|
+
|
|
12
|
+
if (state.location === undefined) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const schema = state.location.schema;
|
|
16
|
+
|
|
17
|
+
if (state.input === undefined) {
|
|
18
|
+
if (!schema.options.allowUndefined) {
|
|
19
|
+
return state;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (state.hasChildren) {
|
|
24
|
+
if (state.pending !== undefined) {
|
|
25
|
+
return state; // use existing
|
|
26
|
+
}
|
|
27
|
+
if (state.value !== undefined) {
|
|
28
|
+
if (state.isIncremental) {
|
|
29
|
+
state.pending = state.value;
|
|
30
|
+
return state;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new SchemaError('Value already processed', {location: state.location});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// create an empty container
|
|
38
|
+
const normalized = schema._normalizeValue(EMPTY, state.target, state.location, state.options);
|
|
39
|
+
|
|
40
|
+
if (normalized instanceof Promise) {
|
|
41
|
+
return normalized.then(normalized => {
|
|
42
|
+
state.pending = normalized;
|
|
43
|
+
return state;
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
state.pending = normalized;
|
|
47
|
+
return state;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
state.pending = state.input;
|
|
51
|
+
return state;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
|
|
3
|
+
import { CompiledSchema } from "../../compiled-schema.js";
|
|
4
|
+
import { UnionResolutionError } from '../../errors.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {TraversalState} state
|
|
8
|
+
* @returns {TraversalState|null|undefined|Promise<TraversalState|null|undefined>}
|
|
9
|
+
*/
|
|
10
|
+
export function resolveUnion(state) {
|
|
11
|
+
|
|
12
|
+
if (!state.schema?.isUnion || !state.location) {
|
|
13
|
+
return state;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// todo - think about this, it's pretty weird (a union should never have .value, I think!)
|
|
17
|
+
// counterpoint: what about pre-existing data being validated?
|
|
18
|
+
|
|
19
|
+
const value = state.pending ?? state.input ?? state.value;
|
|
20
|
+
const result = state.schema._discriminateUnion(value, state.target, state.location, {...state.options, strict: state.context.final});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {CompiledSchema|undefined} unionSchema
|
|
24
|
+
* @returns {TraversalState|undefined|null|Promise<TraversalState|null|undefined>}
|
|
25
|
+
*/
|
|
26
|
+
const handleUnionSchema = (unionSchema) => {
|
|
27
|
+
if (unionSchema) {
|
|
28
|
+
state.schema = unionSchema;
|
|
29
|
+
|
|
30
|
+
if (unionSchema.isUnion) {
|
|
31
|
+
// whoa, multiple layers!
|
|
32
|
+
return resolveUnion(state);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
//return undefined; // consider forcing a loop so that we re-normalize with the new schema?
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (state.context.final) {
|
|
40
|
+
throw new UnionResolutionError('Unable to resolve union', {location: state.location});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return state;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (result instanceof Promise)
|
|
47
|
+
? result.then(resolved => handleUnionSchema(resolved))
|
|
48
|
+
: handleUnionSchema(result);
|
|
49
|
+
}
|
|
50
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TraversalState } from '../traversal-state.js';
|
|
2
|
+
import { isPlainObject } from '../../helpers/object.js';
|
|
3
|
+
import { isTruthy } from '../../helpers/truthy.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Serialize the pending/input and save as output state value
|
|
7
|
+
*
|
|
8
|
+
* Runs pre-child-traversal; acts in the same way that normalize does.
|
|
9
|
+
* Setting the input will propagate down to assigned values in the child states.
|
|
10
|
+
*
|
|
11
|
+
* @param {TraversalState} state
|
|
12
|
+
* @returns {TraversalState|null|undefined|Promise<TraversalState|null|undefined>}
|
|
13
|
+
*/
|
|
14
|
+
export function serialize(state) {
|
|
15
|
+
if (state.schema === undefined) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const schema = state.schema;
|
|
19
|
+
|
|
20
|
+
if (state.assignedInput === null || schema.isImplicit || isTruthy(schema.metadata['omitFromSerialize'])) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (state.assignedInput === undefined) {
|
|
25
|
+
return state;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const result = schema._serializeValue(state.assignedInput, state.target, state.location, state.options);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {any} serialized
|
|
32
|
+
* @returns {null|TraversalState}
|
|
33
|
+
*/
|
|
34
|
+
const updateState = (serialized) => {
|
|
35
|
+
if (serialized === null) {
|
|
36
|
+
state.value = null;
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
state.pending ??= state.hasChildren? ((schema.isArray || Array.isArray(result))? [] : {}) : serialized;
|
|
40
|
+
if (!state.isUnion) {
|
|
41
|
+
state.value = state.pending;
|
|
42
|
+
}
|
|
43
|
+
state.input = serialized;
|
|
44
|
+
return state;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (result instanceof Promise)? result.then(updateState) : updateState(result);
|
|
48
|
+
}
|