@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,100 @@
|
|
|
1
|
+
import { CompiledSchema } from '../../compiled-schema.js';
|
|
2
|
+
import { SchemaError } from '../../errors.js';
|
|
3
|
+
import { SchemaLocation } from "../../schema-location.js";
|
|
4
|
+
import { formatValue } from '../../helpers/format.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ## $metadata
|
|
8
|
+
*
|
|
9
|
+
* Extracts named metadata from a schema, either from the current schema or a parameter.
|
|
10
|
+
*
|
|
11
|
+
* Useful for getting standard metadata like `type` or `description`, or as a way to transport information
|
|
12
|
+
* between schemas that get aggregated together.
|
|
13
|
+
*
|
|
14
|
+
* If a schema value is passed, the metadata is retrieved only from that particular schema.
|
|
15
|
+
* If a schema path is passed, or it is left empty (and thus uses the current schema), $metadata will
|
|
16
|
+
* search from the current schema to the root and return the first value located. To suppress this search,
|
|
17
|
+
* pass `false` to the `inherit` parameter.
|
|
18
|
+
*
|
|
19
|
+
* Returns `undefined` if the referenced schema or metadata key does not exist.
|
|
20
|
+
*
|
|
21
|
+
* ### Parameters
|
|
22
|
+
* - `name` (string, required): The name of the metadata to extract from the schema.
|
|
23
|
+
* - `schema` (CompiledSchema|string, optional): The schema (or a relative path to a schema) to extract metadata from. Defaults to the current schema.
|
|
24
|
+
* - `inherit` (boolean, optional): Whether to search for metadata in a parent if not found in implicit schema.
|
|
25
|
+
*
|
|
26
|
+
* ### Example
|
|
27
|
+
* ```js
|
|
28
|
+
* // Here is an example that will simply propagate the current schema description
|
|
29
|
+
* new Schema('object')
|
|
30
|
+
* .property('description', new Schema('string')
|
|
31
|
+
* .required()
|
|
32
|
+
* .meta('description', 'This will be pulled into the property value')
|
|
33
|
+
* .normalizer({$metadata: 'description'}))
|
|
34
|
+
*
|
|
35
|
+
* // Extract metadata from a sibling property using a relative path.
|
|
36
|
+
* // If 'temperature' lacked a 'unit' meta, $metadata would inherit 'metric' from the parent.
|
|
37
|
+
* const weatherSchema = await resolver.compile(
|
|
38
|
+
* new Schema('object')
|
|
39
|
+
* .meta('unit', 'metric')
|
|
40
|
+
* .property('temperature', new Schema('number').meta('unit', '°C'))
|
|
41
|
+
* .property('unit', new Schema('string')
|
|
42
|
+
* .default('')
|
|
43
|
+
* .transformer({$metadata: {name: 'unit', schema: '^.temperature'}})
|
|
44
|
+
* )
|
|
45
|
+
* );
|
|
46
|
+
* const weather = await weatherSchema.process({temperature: 22});
|
|
47
|
+
* console.log('weather:', weather);
|
|
48
|
+
* // → {temperature: 22, unit: '°C'}
|
|
49
|
+
*
|
|
50
|
+
* // Unlike most other "get a value" operators, $metadata does not use the pipeline input as the source
|
|
51
|
+
* // because it is focused on the current processor calling context rather than values. However, you can
|
|
52
|
+
* // force it to use a compiled schema in the value pipeline by using $input:
|
|
53
|
+
*
|
|
54
|
+
* new Schema('string')
|
|
55
|
+
* .transformer(new Schema('string').meta('greeting', 'hello world'))
|
|
56
|
+
* .transformer({'$metadata': {name: 'greeting', schema: '$input'}})
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
60
|
+
*/
|
|
61
|
+
export const METADATA_OPERATOR = {
|
|
62
|
+
keyword: 'metadata',
|
|
63
|
+
parameters: [{parameter: 'name', required: true, type: 'string'}, {parameter: 'schema', required: false, default: undefined}, {parameter: 'inherit', required: false, default: true}],
|
|
64
|
+
process: (_value, _target, location, options) => {
|
|
65
|
+
|
|
66
|
+
const name = options.args.name;
|
|
67
|
+
const schema = options.args.schema;
|
|
68
|
+
const inherit = options.args.inherit;
|
|
69
|
+
|
|
70
|
+
if (schema !== undefined) {
|
|
71
|
+
if (schema instanceof CompiledSchema) {
|
|
72
|
+
return schema.metadata[name];
|
|
73
|
+
}
|
|
74
|
+
if (typeof schema === 'string') {
|
|
75
|
+
const newLocation = location.relative(schema);
|
|
76
|
+
if (newLocation === undefined) {
|
|
77
|
+
throw new SchemaError(`$metadata was unable to retrieve a schema at ${formatValue(schema)}`);
|
|
78
|
+
}
|
|
79
|
+
location = newLocation;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw new SchemaError(`$metadata expects a valid schema, got ${formatValue(schema)}`, {location});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** @type {SchemaLocation|undefined} */
|
|
87
|
+
let search = location;
|
|
88
|
+
|
|
89
|
+
while (search !== undefined) {
|
|
90
|
+
if (search.schema.metadata[name] !== undefined) {
|
|
91
|
+
return search.schema.metadata[name];
|
|
92
|
+
}
|
|
93
|
+
if (!inherit) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
search = search.parent;
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ## $negative
|
|
5
|
+
*
|
|
6
|
+
* Validates that a numeric value is negative (less than 0).
|
|
7
|
+
* Input must already be a number; use `$number` in a prior normalizer if coercion from string is needed.
|
|
8
|
+
*
|
|
9
|
+
* See also
|
|
10
|
+
* - `$positive` for the opposite constraint
|
|
11
|
+
* - `$range` for more explicit control (e.g. "non-positive, less than or equal to 0")
|
|
12
|
+
*
|
|
13
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
14
|
+
*/
|
|
15
|
+
export const NEGATIVE_CONSTRAINT = {
|
|
16
|
+
keyword: 'negative',
|
|
17
|
+
process: (value) => {
|
|
18
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value >= 0) {
|
|
19
|
+
throw new ConstraintError('Must be a negative number');
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
import { ValueProcessor } from "../../value-processor/value-processor.js";
|
|
3
|
+
import { ComposedValueProcessor } from '../../value-processor/composed-value-processor.js';
|
|
4
|
+
import { ConditionalExecutor } from '../../executor/conditional-executor.js';
|
|
5
|
+
import { Executor } from '../../executor/executor.js';
|
|
6
|
+
import { ConstraintError, SchemaError } from '../../errors.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ## $never
|
|
10
|
+
*
|
|
11
|
+
* Inverts a processor - Returns the input if the wrapped processor throws or returns an undefined value.
|
|
12
|
+
* Throw a constraint error if the wrapped processor returns a defined value.
|
|
13
|
+
*
|
|
14
|
+
* See `$not` to enforce falseyness.
|
|
15
|
+
*
|
|
16
|
+
* ### Parameters
|
|
17
|
+
* - `value` (ProcessorSpec, required): The processor specification to negate (must not return a defined value).
|
|
18
|
+
*
|
|
19
|
+
* ### Example
|
|
20
|
+
* ```js
|
|
21
|
+
* // Blacklist specific values — reject any input that is found in the lookup table
|
|
22
|
+
* new Schema('string').validator({$never: {$lookup: {admin: true, root: true}}})
|
|
23
|
+
*
|
|
24
|
+
* // Ensure a value does not parse as a number (must be a non-numeric string)
|
|
25
|
+
* new Schema('string').validator({$never: '$numeric'})
|
|
26
|
+
*
|
|
27
|
+
* // Reject any value that resolves from $get (path must NOT exist)
|
|
28
|
+
* new Schema('object').validator({$never: {$get: 'deprecated.field'}})
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}*
|
|
32
|
+
*/
|
|
33
|
+
export const NEVER_CONSTRAINT = {
|
|
34
|
+
keyword: 'never',
|
|
35
|
+
|
|
36
|
+
build: (args) => {
|
|
37
|
+
|
|
38
|
+
/** @type {ValueProcessor|undefined} */
|
|
39
|
+
let processor;
|
|
40
|
+
if (Array.isArray(args)) {
|
|
41
|
+
if (args.length === 1) {
|
|
42
|
+
processor = args[0];
|
|
43
|
+
}
|
|
44
|
+
else if (args.length === 0) {
|
|
45
|
+
processor = new ComposedValueProcessor(new Executor(), []);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new SchemaError('$never requires no more than a single value argument');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (typeof args === 'object') {
|
|
52
|
+
processor = args.processor;
|
|
53
|
+
}
|
|
54
|
+
if (!(processor instanceof ValueProcessor)) {
|
|
55
|
+
throw new SchemaError('$never requires a value argument');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const needParens = processor.description && /[|&>∧· ]/.test(processor.description);
|
|
60
|
+
const description = processor.description? (needParens ? `!(${processor.description})` : `!${processor.description}`)
|
|
61
|
+
: undefined
|
|
62
|
+
const spec = {$never: processor.spec};
|
|
63
|
+
|
|
64
|
+
return new ComposedValueProcessor(new ConditionalExecutor(processor, {
|
|
65
|
+
success: () => { throw new ConstraintError('Value must not match the specified condition'); },
|
|
66
|
+
failure: (value) => value
|
|
67
|
+
}, [ConditionalExecutor.CHECK_DEFINED]), spec, description);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ## $non-empty
|
|
5
|
+
*
|
|
6
|
+
* Validates that a string, array, or object is not empty. For strings, the value must contain
|
|
7
|
+
* at least one non-whitespace character. For arrays, the length must be greater than zero.
|
|
8
|
+
* For objects, the number of keys must be greater than zero.
|
|
9
|
+
*
|
|
10
|
+
* ### Example
|
|
11
|
+
* ```js
|
|
12
|
+
* // Require a non-blank username
|
|
13
|
+
* new Schema('string').normalizer('$trim').validator('$non-empty')
|
|
14
|
+
*
|
|
15
|
+
* // Require at least one tag
|
|
16
|
+
* new Schema('array').validator('$non-empty')
|
|
17
|
+
*
|
|
18
|
+
* // Require a non-empty configuration object
|
|
19
|
+
* new Schema('object').validator('$non-empty')
|
|
20
|
+
*
|
|
21
|
+
* // Combine trim + non-empty as a common pattern for required text fields
|
|
22
|
+
* new Schema('object', {
|
|
23
|
+
* name: new Schema('string').normalizer('$trim').validator('$non-empty'),
|
|
24
|
+
* description: new Schema('string').normalizer('$trim').validator('$non-empty'),
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
29
|
+
*/
|
|
30
|
+
export const NON_EMPTY_CONSTRAINT = {
|
|
31
|
+
keyword: 'non-empty',
|
|
32
|
+
process: (value, _target, location) => {
|
|
33
|
+
|
|
34
|
+
if (typeof value === 'string') {
|
|
35
|
+
if (value.trim().length === 0) {
|
|
36
|
+
throw new ConstraintError('String cannot be empty or whitespace only');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (Array.isArray(value)) {
|
|
40
|
+
if (value.length === 0) {
|
|
41
|
+
throw new ConstraintError('Array cannot be empty');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (typeof value === 'object' && value !== null) {
|
|
45
|
+
if (Object.keys(value).length === 0) {
|
|
46
|
+
throw new ConstraintError('Object cannot be empty');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (value === undefined) {
|
|
51
|
+
throw new ConstraintError('Value cannot be undefined');
|
|
52
|
+
}
|
|
53
|
+
else if (value === null) {
|
|
54
|
+
throw new ConstraintError('Value cannot be null');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
|
|
2
|
+
import { ValueProcessor } from "../../value-processor/value-processor.js";
|
|
3
|
+
import { ComposedValueProcessor } from '../../value-processor/composed-value-processor.js';
|
|
4
|
+
import { ConditionalExecutor } from '../../executor/conditional-executor.js';
|
|
5
|
+
import { Executor } from '../../executor/executor.js';
|
|
6
|
+
import { ConstraintError, SchemaError } from '../../errors.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ## $not
|
|
10
|
+
*
|
|
11
|
+
* Inverts a processor result - returns true if the wrapped processor throws or returns a falsey value.
|
|
12
|
+
* Throw a constraint error if the wrapped processor returns a truthy value.
|
|
13
|
+
*
|
|
14
|
+
* This is useful for expressing negative constraints (e.g., "must not be a hostname").
|
|
15
|
+
*
|
|
16
|
+
* See `$never` to require the processor returns undefined or throws an exception.
|
|
17
|
+
*
|
|
18
|
+
* ### Parameters
|
|
19
|
+
* - `value` (ProcessorSpec, required): The processor specification to negate.
|
|
20
|
+
*
|
|
21
|
+
* ### Example
|
|
22
|
+
* ```js
|
|
23
|
+
* // Reject anything that looks like an IP address (accept hostnames only)
|
|
24
|
+
* new Schema('string').validator({$not: '$ipv4'})
|
|
25
|
+
*
|
|
26
|
+
* // Ensure a string is not a reserved word
|
|
27
|
+
* new Schema('string').validator({$not: {$in: ['admin', 'root', 'system']}})
|
|
28
|
+
*
|
|
29
|
+
* // Require a URL that is NOT an HTTP URL (i.e., must be HTTPS or another scheme)
|
|
30
|
+
* new Schema('string').validator({$not: '$http-url'}).validator('$url')
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}*
|
|
34
|
+
*/
|
|
35
|
+
export const NOT_CONSTRAINT = {
|
|
36
|
+
keyword: 'not',
|
|
37
|
+
|
|
38
|
+
build: (args) => {
|
|
39
|
+
|
|
40
|
+
/** @type {ValueProcessor|undefined} */
|
|
41
|
+
let processor;
|
|
42
|
+
if (Array.isArray(args)) {
|
|
43
|
+
if (args.length === 1) {
|
|
44
|
+
processor = args[0];
|
|
45
|
+
}
|
|
46
|
+
else if (args.length === 0) {
|
|
47
|
+
processor = new ComposedValueProcessor(new Executor(), []);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new SchemaError('$not requires no more than a single value argument');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (typeof args === 'object') {
|
|
54
|
+
processor = args.processor;
|
|
55
|
+
}
|
|
56
|
+
if (!(processor instanceof ValueProcessor)) {
|
|
57
|
+
throw new SchemaError('$not requires a value argument');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
const needParens = processor.description && /[|&>∧· ]/.test(processor.description);
|
|
62
|
+
const description = processor.description? (needParens ? `!(${processor.description})` : `!${processor.description}`)
|
|
63
|
+
: undefined
|
|
64
|
+
const spec = {$not: processor.spec};
|
|
65
|
+
|
|
66
|
+
return new ComposedValueProcessor(new ConditionalExecutor(processor, {
|
|
67
|
+
success: () => { throw new ConstraintError('Value must not match the specified condition'); },
|
|
68
|
+
failure: () => true
|
|
69
|
+
}, [ConditionalExecutor.CHECK_TRUTHY]), spec, description);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EMPTY } from '../../constants.js';
|
|
2
|
+
import { ConstraintError } from '../../errors.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ## $number
|
|
6
|
+
*
|
|
7
|
+
* Validates and coerces values to numbers. Accepts numeric strings, integers, and floats.
|
|
8
|
+
* Rejects NaN, Infinity, and non-numeric values.
|
|
9
|
+
*
|
|
10
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
11
|
+
*/
|
|
12
|
+
export const NUMBER_OPERATOR = {
|
|
13
|
+
keyword: 'number',
|
|
14
|
+
process: (value) => {
|
|
15
|
+
if (value === EMPTY) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
const num = Number(value);
|
|
19
|
+
if (Number.isNaN(num) || !Number.isFinite(num)) {
|
|
20
|
+
throw new ConstraintError('Must be a number or convertible to a number');
|
|
21
|
+
}
|
|
22
|
+
return num;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ## $numeric
|
|
5
|
+
*
|
|
6
|
+
* Validates that a string contains only numeric digits (0-9).
|
|
7
|
+
* The value is coerced to a string before validation, so numbers are accepted
|
|
8
|
+
* but must not contain decimal points, signs, or scientific notation.
|
|
9
|
+
*
|
|
10
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
11
|
+
*/
|
|
12
|
+
export const NUMERIC_CONSTRAINT = {
|
|
13
|
+
keyword: 'numeric',
|
|
14
|
+
process: (value) => {
|
|
15
|
+
const v = `${value}`;
|
|
16
|
+
const numericRegex = /^[0-9]+$/;
|
|
17
|
+
if (!numericRegex.test(v)) {
|
|
18
|
+
throw new ConstraintError('Must contain only digits');
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { parse } from '../../helpers/stringify.js';
|
|
2
|
+
import { EMPTY } from '../../constants.js';
|
|
3
|
+
import { ConstraintError } from '../../errors.js';
|
|
4
|
+
import { formatValue } from '../../helpers/format.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ## $object
|
|
8
|
+
*
|
|
9
|
+
* Attempts to normalize the input value as an object.
|
|
10
|
+
*
|
|
11
|
+
* See `$is-object` for strict object validation.
|
|
12
|
+
*
|
|
13
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
14
|
+
*/
|
|
15
|
+
export const OBJECT_OPERATOR = {
|
|
16
|
+
keyword: 'object',
|
|
17
|
+
process: (value) => {
|
|
18
|
+
if (value === EMPTY) {
|
|
19
|
+
value = {};
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
// otherwise, we normalize as an object
|
|
23
|
+
try {
|
|
24
|
+
value = parse(value);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw new ConstraintError(`Invalid input string for object: ${formatValue(value)}`, {cause: error});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value) && value.every(e => Array.isArray(e) && e.length === 2)) {
|
|
31
|
+
return Object.fromEntries(value);
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === 'object') {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
throw new ConstraintError(`Invalid input for object: ${formatValue(value)}`);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
import { ComposedValueProcessor } from '../../value-processor/composed-value-processor.js';
|
|
3
|
+
import { FunctionValueProcessor } from '../../value-processor/function-value-processor.js';
|
|
4
|
+
import { ArrayExecutor } from '../../executor/array-executor.js';
|
|
5
|
+
import { map } from '../../helpers/object.js';
|
|
6
|
+
import { ConstraintError, SchemaError } from '../../errors.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ## $omit
|
|
10
|
+
*
|
|
11
|
+
* Returns a new object or dense array with the specified keys/indices removed.
|
|
12
|
+
* Keys not present in the input are silently ignored.
|
|
13
|
+
* For arrays, numeric indices are excluded and the result is a dense (packed) array.
|
|
14
|
+
*
|
|
15
|
+
* ### Parameters
|
|
16
|
+
* - Array of key names or indices (string[]|number[], required): The keys/indices to exclude.
|
|
17
|
+
*
|
|
18
|
+
* ### Example
|
|
19
|
+
* ```js
|
|
20
|
+
* // Remove internal fields before returning a user object
|
|
21
|
+
* new Schema('object').transformer({$omit: ['password', 'salt', '_internalId']})
|
|
22
|
+
* // {id: 1, name: 'Alice', password: '...', _internalId: 42} → {id: 1, name: 'Alice'}
|
|
23
|
+
*
|
|
24
|
+
* // Remove the first element from an array
|
|
25
|
+
* new Schema('array').transformer({$omit: [0]})
|
|
26
|
+
* // ['header', 'row1', 'row2'] → ['row1', 'row2']
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
30
|
+
*/
|
|
31
|
+
export const OMIT_OPERATOR = {
|
|
32
|
+
keyword: 'omit',
|
|
33
|
+
|
|
34
|
+
build: (args) => {
|
|
35
|
+
if (!Array.isArray(args) || args.length === 0) {
|
|
36
|
+
throw new SchemaError('$omit requires a non-empty array of key names');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const argsSpec = map(args, v => v.spec);
|
|
40
|
+
|
|
41
|
+
return new FunctionValueProcessor(
|
|
42
|
+
(value, _target, location, options) => {
|
|
43
|
+
const keys = Array.isArray(options.args) ? options.args : [];
|
|
44
|
+
if (typeof value !== 'object' || value === null) {
|
|
45
|
+
throw new ConstraintError(`$omit requires an object or array input`, {location});
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
return value.filter((_v, i) => !keys.includes(i));
|
|
49
|
+
}
|
|
50
|
+
return Object.fromEntries(
|
|
51
|
+
Object.entries(value).filter(([k]) => !keys.includes(k))
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
new ComposedValueProcessor(new ArrayExecutor(args), argsSpec)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ParallelExecutor } from '../../executor/parallel-executor.js';
|
|
2
|
+
import { ComposedValueProcessor } from '../../value-processor/composed-value-processor.js';
|
|
3
|
+
import { SchemaError } from '../../errors.js';
|
|
4
|
+
import { map } from '../../helpers/object.js';
|
|
5
|
+
|
|
6
|
+
/** @import {ValueProcessorDefinition} from '../../value-processor/value-processor.js' */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ## $parallel
|
|
10
|
+
*
|
|
11
|
+
* Applies an array of processors concurrently to the same input value, returning an array
|
|
12
|
+
* of all results in the same order as the processors.
|
|
13
|
+
*
|
|
14
|
+
* When all processors are synchronous, execution is sequential and the result is a plain array.
|
|
15
|
+
* When any processor is asynchronous, all are run via `Promise.all`, giving true concurrent
|
|
16
|
+
* execution — useful for I/O-bound processors such as HTTP fetches or secret lookups.
|
|
17
|
+
*
|
|
18
|
+
* Errors propagate immediately (fail-fast). Wrap individual processors in `$gate` or `$try`
|
|
19
|
+
* to trap errors and return a fallback instead.
|
|
20
|
+
*
|
|
21
|
+
* ### Parameters
|
|
22
|
+
* - `processors` (Array, required): Array of processor specifications to run concurrently.
|
|
23
|
+
*
|
|
24
|
+
* ### Example
|
|
25
|
+
* ```js
|
|
26
|
+
* // Fan out to two transforms and collect both results
|
|
27
|
+
* new Schema('string').transformer({$parallel: ['$uppercase', '$trim']})
|
|
28
|
+
* // ' hello ' → ['HELLO', 'hello']
|
|
29
|
+
*
|
|
30
|
+
* // Concurrent async lookups (both execute at the same time via Promise.all)
|
|
31
|
+
* new Schema('string').transformer({$parallel: [fetchUserFlags, fetchUserPermissions]})
|
|
32
|
+
* // → [flagsResult, permissionsResult]
|
|
33
|
+
*
|
|
34
|
+
* // Fan out validation across multiple schemas and collect results
|
|
35
|
+
* new Schema('object').transformer({
|
|
36
|
+
* $parallel: [
|
|
37
|
+
* {$get: 'id'},
|
|
38
|
+
* {$get: 'name'},
|
|
39
|
+
* {$get: 'email'},
|
|
40
|
+
* ]
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @type {ValueProcessorDefinition}
|
|
45
|
+
*/
|
|
46
|
+
export const PARALLEL_OPERATOR = {
|
|
47
|
+
keyword: 'parallel',
|
|
48
|
+
build: (args) => {
|
|
49
|
+
// The resolver's map() utility wraps scalar specs into single-element arrays before
|
|
50
|
+
// reaching build(), so {$parallel: '$trim'} arrives as [compiled_trim] and is valid.
|
|
51
|
+
// Only plain-object args (e.g. {$parallel: {key: spec}}) arrive as non-arrays.
|
|
52
|
+
if (!Array.isArray(args)) {
|
|
53
|
+
throw new SchemaError('$parallel requires an array of processors');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const spec = {$parallel: map(args, arg => arg.spec)};
|
|
57
|
+
const descriptions = args.map(arg => arg.description).filter(d => d !== undefined);
|
|
58
|
+
const description = descriptions.length > 0
|
|
59
|
+
? descriptions.map(d => /[|&>·∧ ]/.test(d) ? `(${d})` : d).join(' ⊗ ')
|
|
60
|
+
: undefined;
|
|
61
|
+
|
|
62
|
+
return new ComposedValueProcessor(new ParallelExecutor(args), spec, description);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { toPascalCase } from '../../helpers/case.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ## $pascal-case
|
|
5
|
+
*
|
|
6
|
+
* Converts a string value to PascalCase format (first letter of each word capitalized, no separators).
|
|
7
|
+
* Safe to use in normalize phase (non-throwing).
|
|
8
|
+
*
|
|
9
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
10
|
+
*/
|
|
11
|
+
export const PASCAL_CASE_OPERATOR = {
|
|
12
|
+
keyword: 'pascal-case',
|
|
13
|
+
process: (value) => {
|
|
14
|
+
return toPascalCase(String(value));
|
|
15
|
+
}
|
|
16
|
+
};
|