@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,531 @@
|
|
|
1
|
+
import { CompiledSchema } from './compiled-schema.js';
|
|
2
|
+
import { Schema } from './schema.js';
|
|
3
|
+
import { SchemaLocation } from "./schema-location.js";
|
|
4
|
+
import { SchemaResolver } from './schema-resolver.js';
|
|
5
|
+
import { TraversalContext } from './traversal/traversal-context.js';
|
|
6
|
+
import { ValueProcessor } from './value-processor/value-processor.js';
|
|
7
|
+
import {
|
|
8
|
+
FinalizeError,
|
|
9
|
+
NormalizeError,
|
|
10
|
+
SchemaCompilationError,
|
|
11
|
+
SchemaError,
|
|
12
|
+
TransformError,
|
|
13
|
+
ValidationError
|
|
14
|
+
} from './errors.js';
|
|
15
|
+
import { isKeywordValueProcessorSpec } from './value-processor/spec.js';
|
|
16
|
+
import {
|
|
17
|
+
copyUnionOptions, synthesizeKeyDiscrimination, synthesizeAutoDiscrimination, synthesizeUnionValues,
|
|
18
|
+
} from './compilation/union-compilation.js';
|
|
19
|
+
|
|
20
|
+
import { populateChildSelectorValues } from './compilation/selection-compilation.js';
|
|
21
|
+
import { populateMetadata } from './compilation/metadata-compilation.js';
|
|
22
|
+
import { normalizeSchema, transformSchema, validateSchema } from './compilation/schema-compilation.js';
|
|
23
|
+
import { compileHandlers } from './compilation/handler-compilation.js';
|
|
24
|
+
import { normalizeValues } from './compilation/values-compilation.js';
|
|
25
|
+
import { isEmpty, isPlainObject } from './helpers/object.js';
|
|
26
|
+
|
|
27
|
+
/** @typedef {(inputSchema:CompiledSchema|Schema, targetSchema:CompiledSchema, location:SchemaLocation, options?:object) => Promise<Schema|CompiledSchema|import("./types.js").SchemaData|undefined>} InputSchemaProcessor */
|
|
28
|
+
/** @typedef {(inputSchema:CompiledSchema, targetSchema:CompiledSchema, location:SchemaLocation, options?:object) => Promise<CompiledSchema|undefined>} OutputSchemaProcessor */
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// TODO - idea: broaden the concept of discriminators to "schemaResolvers" that can produce any replacement schema on demand.
|
|
32
|
+
// then, make circular schema references be a dynamic resolver concept?
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This is a marker class for type safety that is replaced before the schema is used.
|
|
36
|
+
*/
|
|
37
|
+
export class CachedSchemaReference extends CompiledSchema {
|
|
38
|
+
/**
|
|
39
|
+
* @param {Schema} schema
|
|
40
|
+
*/
|
|
41
|
+
constructor(schema) {
|
|
42
|
+
super(CompiledSchema.__TOKEN);
|
|
43
|
+
this.schema = schema;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Top-level "Schema Schema" - takes a Schema as input, emits a CompiledSchema as output
|
|
49
|
+
*/
|
|
50
|
+
export class SchemaCompiler extends CompiledSchema {
|
|
51
|
+
/**
|
|
52
|
+
* @param {SchemaResolver} resolver
|
|
53
|
+
*/
|
|
54
|
+
constructor(resolver) {
|
|
55
|
+
super(CompiledSchema.__TOKEN);
|
|
56
|
+
|
|
57
|
+
this.resolver = resolver;
|
|
58
|
+
|
|
59
|
+
this.normalizeCache = new Map();
|
|
60
|
+
|
|
61
|
+
this.compileSeen = new Map();
|
|
62
|
+
this.compileCache = new Map();
|
|
63
|
+
|
|
64
|
+
const compiler = this;
|
|
65
|
+
|
|
66
|
+
// We'll use Schema's fluent setters to carefully define a "Schema Schema", and then extract its guts.
|
|
67
|
+
|
|
68
|
+
const valueProcessorSchema = new Schema('any')
|
|
69
|
+
.option('dynamic', false)
|
|
70
|
+
.opaque()
|
|
71
|
+
.validator((p, _target, location) => {
|
|
72
|
+
if (!(p instanceof ValueProcessor)) {
|
|
73
|
+
throw new SchemaCompilationError('Failed to compile to a value processor', {location});
|
|
74
|
+
}
|
|
75
|
+
return p;
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const simpleKeywordSpecSchema = new Schema(valueProcessorSchema)
|
|
79
|
+
.transformer(spec => {
|
|
80
|
+
return resolver.compileKeywordValueProcessorSpec(this, spec)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const verboseKeywordSpecSchema = new Schema(valueProcessorSchema)
|
|
84
|
+
.property('$literal', new Schema('any'))
|
|
85
|
+
.transformer(spec => {
|
|
86
|
+
return resolver.compileKeywordValueProcessorSpec(this, spec)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const generalSpecSchema = new Schema(valueProcessorSchema)
|
|
90
|
+
.transformer(spec => {
|
|
91
|
+
return resolver.compileValueProcessorSpec(this, spec)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
const specSchema = new Schema(valueProcessorSchema)
|
|
95
|
+
.normalizer((spec) => {
|
|
96
|
+
if (spec === null) {
|
|
97
|
+
return '$null';
|
|
98
|
+
}
|
|
99
|
+
return spec;
|
|
100
|
+
})
|
|
101
|
+
// union - never transformed
|
|
102
|
+
// .transformer(spec => {
|
|
103
|
+
// return resolver.compileKeywordValueProcessorSpec(spec)
|
|
104
|
+
// })
|
|
105
|
+
.unionDiscriminator(spec => {
|
|
106
|
+
if (spec instanceof ValueProcessor) {
|
|
107
|
+
return 'general';
|
|
108
|
+
}
|
|
109
|
+
if (spec === null || spec === undefined) {
|
|
110
|
+
return 'general';
|
|
111
|
+
}
|
|
112
|
+
if (isEmpty(spec)) {
|
|
113
|
+
// todo - can $literal be used to allow deliberately empty specs?
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
if (isKeywordValueProcessorSpec(spec)) {
|
|
117
|
+
return typeof spec === 'string' ? 'keyword' : 'keyword+args';
|
|
118
|
+
}
|
|
119
|
+
return 'general';
|
|
120
|
+
})
|
|
121
|
+
.unionSchema('keyword', simpleKeywordSpecSchema)
|
|
122
|
+
.unionSchema('keyword+args', verboseKeywordSpecSchema)
|
|
123
|
+
.unionSchema('general', generalSpecSchema)
|
|
124
|
+
|
|
125
|
+
const keywordArgumentsSchema = new Schema('any')
|
|
126
|
+
.option('dynamic', false)
|
|
127
|
+
.unionDiscriminator(spec => {
|
|
128
|
+
if (Array.isArray(spec)) { return 'array'} // array for arguments is always parameters
|
|
129
|
+
|
|
130
|
+
if (isKeywordValueProcessorSpec(spec)) { return 'spec' }
|
|
131
|
+
if (isEmpty(spec)) { return undefined; } // might be a keyword once filled in
|
|
132
|
+
if (isPlainObject(spec)) { return 'object'}
|
|
133
|
+
return 'spec';
|
|
134
|
+
})
|
|
135
|
+
.unionSchema('spec', specSchema)
|
|
136
|
+
.unionSchema('array', new Schema('array')
|
|
137
|
+
.allowEmpty()
|
|
138
|
+
//.opaque()
|
|
139
|
+
.transformer(pa => {
|
|
140
|
+
return pa; // todo - verify parameters
|
|
141
|
+
})
|
|
142
|
+
.property('*', specSchema))
|
|
143
|
+
.unionSchema('object', new Schema('object')
|
|
144
|
+
.allowEmpty()
|
|
145
|
+
//.opaque()
|
|
146
|
+
.transformer(po => {
|
|
147
|
+
return po; // todo - verify parameters
|
|
148
|
+
})
|
|
149
|
+
.property('*', specSchema))
|
|
150
|
+
|
|
151
|
+
verboseKeywordSpecSchema.property('*', keywordArgumentsSchema)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
const pipelineSchema = new Schema('array')
|
|
155
|
+
.property('*', specSchema)
|
|
156
|
+
// .transformer(speclist => {
|
|
157
|
+
// return resolver.compileProcessorPipeline(speclist);
|
|
158
|
+
// })
|
|
159
|
+
|
|
160
|
+
// fixme - well, mostly fixed now, but here's the former comment:
|
|
161
|
+
// the problem is that this schema is an "any", so it doesn't normalize the input schema at all,
|
|
162
|
+
// ...it makes it all the way to the resolver phase, gets resolved, but then it won't iterate
|
|
163
|
+
// the children because it isn't a "simple object".
|
|
164
|
+
//
|
|
165
|
+
// the old compiler presumably fixed this by doing a full restart of the traversal with the new schema.
|
|
166
|
+
// we don't have a good mechanism for that yet. :-/
|
|
167
|
+
//
|
|
168
|
+
// otherwise we need a compatible normalizer, which I'm not sure is possible.
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
const schemaCompilerSchema = new Schema()
|
|
172
|
+
.meta('compiler', 'root')
|
|
173
|
+
.required()
|
|
174
|
+
/*
|
|
175
|
+
.normalizer(
|
|
176
|
+
async (inputSchema) => {
|
|
177
|
+
if (inputSchema instanceof CompiledSchema) {
|
|
178
|
+
return inputSchema;
|
|
179
|
+
}
|
|
180
|
+
else if (typeof inputSchema === 'object') {
|
|
181
|
+
return resolver.resolve(inputSchema, false);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
throw new SchemaError('not a schema');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
*/
|
|
189
|
+
.normalizer((inputSchema, _, location) => {
|
|
190
|
+
if (this.compileSeen.has(inputSchema) && this.compileSeen.get(inputSchema) !== location.path) {
|
|
191
|
+
return new CachedSchemaReference(inputSchema);
|
|
192
|
+
}
|
|
193
|
+
if (inputSchema instanceof CompiledSchema) {
|
|
194
|
+
return inputSchema;
|
|
195
|
+
}
|
|
196
|
+
this.compileSeen.set(inputSchema, location.path);
|
|
197
|
+
return inputSchema
|
|
198
|
+
})
|
|
199
|
+
.normalizer(normalizeSchema.bind(this))
|
|
200
|
+
|
|
201
|
+
// note: we must only return strings while compiling to prevent dogfood confusion about union schemas!
|
|
202
|
+
.unionDiscriminator((s, _, location, options) => {
|
|
203
|
+
if (s instanceof CachedSchemaReference) {
|
|
204
|
+
return 'cache';
|
|
205
|
+
}
|
|
206
|
+
if (this.compileSeen.has(s)) {
|
|
207
|
+
return 'cache';
|
|
208
|
+
}
|
|
209
|
+
else if (s instanceof CompiledSchema) {
|
|
210
|
+
return 'reference';
|
|
211
|
+
}
|
|
212
|
+
else if (typeof s === 'object') {
|
|
213
|
+
return 'schema';
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
.unionSchema('reference', new Schema()
|
|
221
|
+
.meta('compiler', 'reference')
|
|
222
|
+
.required()
|
|
223
|
+
.normalizer(s => {
|
|
224
|
+
if (!(s instanceof CompiledSchema)) {
|
|
225
|
+
throw new SchemaCompilationError('Not a CompiledSchema reference!');
|
|
226
|
+
}
|
|
227
|
+
return s;
|
|
228
|
+
})
|
|
229
|
+
)
|
|
230
|
+
.unionSchema('cache', new Schema()
|
|
231
|
+
.meta('compiler', 'cache')
|
|
232
|
+
.required()
|
|
233
|
+
.normalizer(s => {
|
|
234
|
+
if (s instanceof CachedSchemaReference) {
|
|
235
|
+
return s;
|
|
236
|
+
}
|
|
237
|
+
if (!(s instanceof Schema)) {
|
|
238
|
+
throw new SchemaCompilationError('Can only cache references to schemas')
|
|
239
|
+
}
|
|
240
|
+
return new CachedSchemaReference(s); // fixme gahhhhhh we never get here, only normalized via main union
|
|
241
|
+
})
|
|
242
|
+
/* note to self: can't have a transformer find the completed schema in the cache because
|
|
243
|
+
there's a chicken and egg problem; opaque schema won't transform without all properties complete,
|
|
244
|
+
but a property that depends on the parent schema can't complete! revisit if we ever make the schema incremental.
|
|
245
|
+
.transformer(s => {
|
|
246
|
+
if (!(s instanceof CachedSchemaReference)) {
|
|
247
|
+
throw new SchemaCompilationError('not a cached schema');
|
|
248
|
+
}
|
|
249
|
+
const compiledSchema = this.compileCache.get(s.schema);
|
|
250
|
+
return compiledSchema;
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
*/
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
// The schema needs to be opaque right now because it contains internals that have a complex
|
|
257
|
+
// resolution dependency chain that cannot (yet) be expressed in the schema itself:
|
|
258
|
+
//
|
|
259
|
+
// values depends on normalizers
|
|
260
|
+
// discriminators is a default, but depends on checking values
|
|
261
|
+
// selector and selection depend on condition and values
|
|
262
|
+
//
|
|
263
|
+
// validation depends on everything being configured properly as it checks options/children
|
|
264
|
+
//
|
|
265
|
+
// note that by the time this schema has been resolved, we're beyond normalizing inputs, and only
|
|
266
|
+
// normalizing a new empty schema data being built
|
|
267
|
+
|
|
268
|
+
const schemaSchema = new Schema('object')
|
|
269
|
+
.meta('compiler', 'schema')
|
|
270
|
+
.opaque()
|
|
271
|
+
.required()
|
|
272
|
+
.normalizer(normalizeSchema.bind(this)) // if we traverse again, we should get the cached version
|
|
273
|
+
|
|
274
|
+
.normalizer(
|
|
275
|
+
(inputSchema, _target, _location, _options) => {
|
|
276
|
+
if (inputSchema instanceof CompiledSchema) {
|
|
277
|
+
return inputSchema;
|
|
278
|
+
}
|
|
279
|
+
else if (typeof inputSchema === 'object') {
|
|
280
|
+
if (inputSchema instanceof Schema) {
|
|
281
|
+
throw new SchemaCompilationError('Internal compiler error');
|
|
282
|
+
//return resolver.resolve(inputSchema, false); // this should never happen! should have been normalized to {}
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
return inputSchema;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
throw new SchemaError('not a schema');
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
)
|
|
293
|
+
// .normalizer(normalizeSchema.bind(this))
|
|
294
|
+
.transformer(transformSchema.bind(this))
|
|
295
|
+
|
|
296
|
+
.finalizer({$if: [
|
|
297
|
+
(inputSchema => inputSchema.isUnion),
|
|
298
|
+
{$pipeline: [synthesizeUnionValues, synthesizeKeyDiscrimination, synthesizeAutoDiscrimination, copyUnionOptions].map(p => p.bind(this))},
|
|
299
|
+
'$input'
|
|
300
|
+
]
|
|
301
|
+
})
|
|
302
|
+
.finalizer(compileHandlers.bind(this)) // needs to be after discriminator synthesis
|
|
303
|
+
|
|
304
|
+
.finalizer({$if: [
|
|
305
|
+
(compiledSchema => !isEmpty(compiledSchema.options.values)),
|
|
306
|
+
normalizeValues.bind(this), // requires handlers; conditional to avoid async when not needed
|
|
307
|
+
'$defined'
|
|
308
|
+
]
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
/*
|
|
312
|
+
.finalizer({$if: [
|
|
313
|
+
(compiledSchema => compiledSchema.hasValues),
|
|
314
|
+
{
|
|
315
|
+
$gate: [
|
|
316
|
+
{
|
|
317
|
+
$invoke: {
|
|
318
|
+
processor: {
|
|
319
|
+
$pipeline: [
|
|
320
|
+
(compiledSchema => compiledSchema.options.values),
|
|
321
|
+
{
|
|
322
|
+
$each: (value, _target, _location, options) => {
|
|
323
|
+
return options.args.schema._normalizeValue(value);
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
(values, _target, _location, options) => {
|
|
327
|
+
options.args.schema.options.values = values;
|
|
328
|
+
return options.args.schema;
|
|
329
|
+
}
|
|
330
|
+
]
|
|
331
|
+
},
|
|
332
|
+
arguments: {schema: '$input'}
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
'$input',
|
|
336
|
+
'$input'
|
|
337
|
+
]
|
|
338
|
+
},
|
|
339
|
+
'$input'
|
|
340
|
+
|
|
341
|
+
]
|
|
342
|
+
})
|
|
343
|
+
*/
|
|
344
|
+
.finalizer( {$if: [
|
|
345
|
+
(inputSchema => inputSchema.hasChildSelector || inputSchema.hasChildSelection),
|
|
346
|
+
populateChildSelectorValues,
|
|
347
|
+
'$defined'
|
|
348
|
+
]})
|
|
349
|
+
.finalizer(populateMetadata)
|
|
350
|
+
.finalizer((compiledSchema, _rootSchema, location) => {
|
|
351
|
+
if (location.path !== '') {
|
|
352
|
+
return compiledSchema;
|
|
353
|
+
}
|
|
354
|
+
if (!(compiledSchema instanceof CompiledSchema)) {
|
|
355
|
+
throw new SchemaCompilationError('Schema failed to compile!');
|
|
356
|
+
}
|
|
357
|
+
// Replace placeholders (marking circular references) with their final compiled versions.
|
|
358
|
+
this._replaceCachedReferences(compiledSchema);
|
|
359
|
+
|
|
360
|
+
compiledSchema._freeze();
|
|
361
|
+
return compiledSchema;
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
.validator(validateSchema.bind(this))
|
|
365
|
+
.property('properties',
|
|
366
|
+
new Schema('object')
|
|
367
|
+
// .implicit()
|
|
368
|
+
.property('*', schemaCompilerSchema)
|
|
369
|
+
)
|
|
370
|
+
.property('unionSchemas',
|
|
371
|
+
new Schema('object')
|
|
372
|
+
// .implicit()
|
|
373
|
+
.property('*', schemaCompilerSchema)
|
|
374
|
+
)
|
|
375
|
+
.property('metadata',
|
|
376
|
+
new Schema('object')
|
|
377
|
+
// .implicit()
|
|
378
|
+
.property('*', new Schema('string'))
|
|
379
|
+
)
|
|
380
|
+
.property('options',
|
|
381
|
+
new Schema('object')
|
|
382
|
+
.property('compileHook', new Schema('function'))
|
|
383
|
+
.property('default', new Schema('any').option('dynamic', false))
|
|
384
|
+
// .implicit()
|
|
385
|
+
.property('values', new Schema('array'))
|
|
386
|
+
.property('*', new Schema('any'))
|
|
387
|
+
)
|
|
388
|
+
.property('handlers',
|
|
389
|
+
new Schema('object')
|
|
390
|
+
// .implicit()
|
|
391
|
+
.property('normalizers', pipelineSchema)
|
|
392
|
+
.property('transformers', pipelineSchema)
|
|
393
|
+
.property('finalizers', pipelineSchema)
|
|
394
|
+
.property('validators', pipelineSchema)
|
|
395
|
+
.property('serializers', pipelineSchema)
|
|
396
|
+
.property('conditions', pipelineSchema)
|
|
397
|
+
.property('discriminators', pipelineSchema)
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
schemaCompilerSchema.unionSchema('schema', schemaSchema)
|
|
401
|
+
|
|
402
|
+
const convertCache = new Map();
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* This function acts as the primordial "compiler" that builds the actual SchemaCompiler.
|
|
406
|
+
*
|
|
407
|
+
* The Schema that defines Schemas is deliberately constrained in the features it uses.
|
|
408
|
+
* This allows us to "compile it" without requiring the full complexity of the full compilation process.
|
|
409
|
+
*
|
|
410
|
+
* @param {Schema|CompiledSchema} src
|
|
411
|
+
* @param {CompiledSchema} [dst]
|
|
412
|
+
* @returns {CompiledSchema}
|
|
413
|
+
*/
|
|
414
|
+
function compileSchemaCompiler(src, dst) {
|
|
415
|
+
if (convertCache.has(src)) {
|
|
416
|
+
return convertCache.get(src);
|
|
417
|
+
}
|
|
418
|
+
if (src instanceof CompiledSchema) {
|
|
419
|
+
return src;
|
|
420
|
+
}
|
|
421
|
+
if (dst === undefined) {
|
|
422
|
+
dst = new CompiledSchema(CompiledSchema.__TOKEN);
|
|
423
|
+
}
|
|
424
|
+
convertCache.set(src, dst);
|
|
425
|
+
convertCache.set(dst, dst); // I don't think this is necessary anymore?
|
|
426
|
+
|
|
427
|
+
Object.assign(dst.options, src.options);
|
|
428
|
+
Object.assign(dst.metadata, src.metadata);
|
|
429
|
+
for (const [handler, processorSpecList] of Object.entries(src.handlers)) {
|
|
430
|
+
// dst.handlers[handler] = [resolver.compileProcessorSpec(processorSpecList)];
|
|
431
|
+
dst.handlers[handler] = processorSpecList.map(spec => resolver.compileValueProcessorSpec(compiler, spec, true));
|
|
432
|
+
dst._setValueProcessor(handler, resolver.compileValueProcessorSpec(compiler,{$pipeline: dst.handlers[handler]}));
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
for (const [pk, pv] of Object.entries(src.properties)) {
|
|
436
|
+
if (!(pv instanceof Schema || pv instanceof CompiledSchema)) {
|
|
437
|
+
continue; // impossible
|
|
438
|
+
}
|
|
439
|
+
dst._setPropertySchema(pk, compileSchemaCompiler(pv));
|
|
440
|
+
}
|
|
441
|
+
for (const [uk, uv] of Object.entries(src.unionSchemas)) {
|
|
442
|
+
if (!(uv instanceof Schema || uv instanceof CompiledSchema)) {
|
|
443
|
+
continue; // impossible
|
|
444
|
+
}
|
|
445
|
+
dst._setUnionSchema(uk, compileSchemaCompiler(uv));
|
|
446
|
+
}
|
|
447
|
+
return dst;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
compileSchemaCompiler(resolver.resolve(schemaCompilerSchema), this);
|
|
451
|
+
}
|
|
452
|
+
get hasChildren() {
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
*
|
|
457
|
+
* @param {CompiledSchema} cs
|
|
458
|
+
* @param {string} [path]
|
|
459
|
+
* @param {Set<CompiledSchema>} [seen]
|
|
460
|
+
* @private
|
|
461
|
+
*/
|
|
462
|
+
_replaceCachedReferences(cs, path = '', seen = new Set()) {
|
|
463
|
+
if (seen.has(cs)) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
seen.add(cs);
|
|
467
|
+
|
|
468
|
+
for (const [pk, pvr] of cs.propertyEntries) {
|
|
469
|
+
const propertyPath = path? `${path}.${pk}` : pk;
|
|
470
|
+
const pv = (pvr instanceof CachedSchemaReference)? this.compileCache.get(pvr.schema) : pvr;
|
|
471
|
+
if (pv === undefined) {
|
|
472
|
+
throw new SchemaCompilationError('Unable to find cached CompiledSchema', {path: propertyPath})
|
|
473
|
+
}
|
|
474
|
+
if (pv !== pvr) {
|
|
475
|
+
pv.metadata.references ??= '';
|
|
476
|
+
pv.metadata.references += `[${propertyPath}]`
|
|
477
|
+
cs._setPropertySchema(pk, pv);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
this._replaceCachedReferences(pv, propertyPath, seen);
|
|
481
|
+
}
|
|
482
|
+
for (const [uk, uvr] of cs.unionSchemaEntries) {
|
|
483
|
+
const uv = (uvr instanceof CachedSchemaReference)? this.compileCache.get(uvr.schema) : uvr;
|
|
484
|
+
if (uv === undefined) {
|
|
485
|
+
throw new SchemaCompilationError(`Unable to find cached CompiledSchema for unionSchema "${uk}"`, {path})
|
|
486
|
+
}
|
|
487
|
+
if (uv !== uvr) {
|
|
488
|
+
uv.metadata.references ??= '';
|
|
489
|
+
uv.metadata.references += `[${path}:${uk}]`;
|
|
490
|
+
cs._setUnionSchema(uk, uv);
|
|
491
|
+
}
|
|
492
|
+
this._replaceCachedReferences(uv, path, seen);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Compile a Schema to a CompiledSchema
|
|
498
|
+
*
|
|
499
|
+
* Schemas are compiled using a schema that defines schemas! This method is a convenience facade over the regular
|
|
500
|
+
* "process" flow.
|
|
501
|
+
*
|
|
502
|
+
* @param {Schema|CompiledSchema|import("./types.js").SchemaData} inputSchema
|
|
503
|
+
* @returns {CompiledSchema}
|
|
504
|
+
*/
|
|
505
|
+
compile(inputSchema) {
|
|
506
|
+
try {
|
|
507
|
+
const context = new TraversalContext(new SchemaLocation(this));
|
|
508
|
+
context.compiling = true;
|
|
509
|
+
const result = this._process(inputSchema, undefined, {context});
|
|
510
|
+
if (result instanceof Promise) {
|
|
511
|
+
throw new SchemaCompilationError('Encountered an async processor during compilation');
|
|
512
|
+
}
|
|
513
|
+
return result;
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
if (error instanceof SchemaCompilationError) {
|
|
517
|
+
throw error;
|
|
518
|
+
}
|
|
519
|
+
else if ((error instanceof NormalizeError || error instanceof TransformError || error instanceof FinalizeError || error instanceof ValidationError) && error.cause) {
|
|
520
|
+
// these aren't interesting, but their internals are...
|
|
521
|
+
throw new SchemaCompilationError(error.cause.message, {...error.data, ...error.cause.data, cause: error.cause});
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
throw new SchemaCompilationError('Error during compilation', {cause: error});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|