@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,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $is-array
|
|
3
|
+
*
|
|
4
|
+
* Validates that the input is a valid array.
|
|
5
|
+
*
|
|
6
|
+
* See `$array` for looser array handling that accepts values that can be normalized as arrays.
|
|
7
|
+
*
|
|
8
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
9
|
+
*/
|
|
10
|
+
export const IS_ARRAY_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $is-date
|
|
3
|
+
*
|
|
4
|
+
* Validates that the input is a valid date.
|
|
5
|
+
*
|
|
6
|
+
* See `$date` for looser date handling that accepts values that can be normalized as dates.
|
|
7
|
+
*
|
|
8
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
9
|
+
*/
|
|
10
|
+
export const IS_DATE_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $is-number
|
|
3
|
+
*
|
|
4
|
+
* Validates that the input is a valid number.
|
|
5
|
+
*
|
|
6
|
+
* See `$number` for looser number validation that accepts values that can be normalized as numbers.
|
|
7
|
+
*
|
|
8
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
9
|
+
*/
|
|
10
|
+
export const IS_NUMBER_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $is-object
|
|
3
|
+
*
|
|
4
|
+
* Validates that the input is a valid object (and not null!)
|
|
5
|
+
*
|
|
6
|
+
* See `$object` for looser object handling that accepts values that can be normalized as objects.
|
|
7
|
+
*
|
|
8
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
9
|
+
*/
|
|
10
|
+
export const IS_OBJECT_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $is-string
|
|
3
|
+
*
|
|
4
|
+
* Validates that the input is a valid string.
|
|
5
|
+
*
|
|
6
|
+
* See `$string` for looser validation that accepts values that can be normalized as strings.
|
|
7
|
+
*
|
|
8
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
9
|
+
*/
|
|
10
|
+
export const IS_STRING_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $join
|
|
3
|
+
*
|
|
4
|
+
* Join the input array elements into a string using the provided separator.
|
|
5
|
+
*
|
|
6
|
+
* ### Parameters
|
|
7
|
+
* - `separator` (string, required): The value to use for joining
|
|
8
|
+
*
|
|
9
|
+
* If the input is not an array, it is treated as a single element.
|
|
10
|
+
* Follows the behavior of JavaScript's Array.prototype.join()
|
|
11
|
+
*
|
|
12
|
+
* ### Example
|
|
13
|
+
* ```js
|
|
14
|
+
* // Join array elements with a comma (default)
|
|
15
|
+
* new Schema('array').transformer('$join')
|
|
16
|
+
* // ['a', 'b', 'c'] → 'a,b,c'
|
|
17
|
+
*
|
|
18
|
+
* // Join with a custom separator
|
|
19
|
+
* new Schema('array').transformer({$join: {separator: ' | '}})
|
|
20
|
+
* // ['admin', 'read', 'write'] → 'admin | read | write'
|
|
21
|
+
*
|
|
22
|
+
* // Split then rejoin with normalized separators
|
|
23
|
+
* new Schema('string').normalizer([{$split: {separator: /[,;]/}}, {$each: '$trim'}])
|
|
24
|
+
* .transformer({$join: {separator: ', '}})
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}*
|
|
28
|
+
*/
|
|
29
|
+
export const JOIN_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $json
|
|
3
|
+
*
|
|
4
|
+
* Validates that a string contains valid JSON that can be parsed by `JSON.parse()`.
|
|
5
|
+
* The processor does not modify the input - it only validates that the string is
|
|
6
|
+
* syntactically correct JSON.
|
|
7
|
+
*
|
|
8
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
9
|
+
*/
|
|
10
|
+
export const JSON_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $json-decode
|
|
3
|
+
*
|
|
4
|
+
* Parses a JSON string into a value.
|
|
5
|
+
* Throws if the input is not a string or is not valid JSON.
|
|
6
|
+
*
|
|
7
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
8
|
+
*/
|
|
9
|
+
export const JSON_DECODE_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $json-encode
|
|
3
|
+
*
|
|
4
|
+
* Serializes any value to a JSON string.
|
|
5
|
+
*
|
|
6
|
+
* ### Parameters
|
|
7
|
+
* - `indent` (number, optional, default `0`): Indentation spaces for pretty-printing. `0` produces compact output.
|
|
8
|
+
*
|
|
9
|
+
* ### Example
|
|
10
|
+
* ```js
|
|
11
|
+
* // Serialize an object to a compact JSON string
|
|
12
|
+
* new Schema('object').transformer('$json-encode')
|
|
13
|
+
* // {a: 1} → '{"a":1}'
|
|
14
|
+
*
|
|
15
|
+
* // Pretty-print with 2-space indentation
|
|
16
|
+
* new Schema('object').transformer({'$json-encode': {indent: 2}})
|
|
17
|
+
* // {a: 1} → '{\n "a": 1\n}'
|
|
18
|
+
*
|
|
19
|
+
* // Encode a nested payload field for storage
|
|
20
|
+
* new Schema('object', {
|
|
21
|
+
* payload: new Schema('object').transformer('$json-encode'),
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
26
|
+
*/
|
|
27
|
+
export const JSON_ENCODE_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $kebab-case
|
|
3
|
+
*
|
|
4
|
+
* Converts a string to kebab-case format (lowercase words separated by hyphens).
|
|
5
|
+
* Safe to use in normalize phase (non-throwing).
|
|
6
|
+
*
|
|
7
|
+
* **Input/Output Examples**:
|
|
8
|
+
* - `"HelloWorld"` → `"hello-world"`
|
|
9
|
+
* - `"API_KEY_NAME"` → `"api-key-name"`
|
|
10
|
+
* - `"some text here"` → `"some-text-here"`
|
|
11
|
+
* - `"camelCase"` → `"camel-case"`
|
|
12
|
+
* - `"already-kebab"` → `"already-kebab"`
|
|
13
|
+
*
|
|
14
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
15
|
+
*/
|
|
16
|
+
export const KEBAB_CASE_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $keys
|
|
3
|
+
*
|
|
4
|
+
* Returns the enumerable own property keys of an object as an array of strings.
|
|
5
|
+
* Throws if the input is not a plain object.
|
|
6
|
+
*
|
|
7
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
8
|
+
*/
|
|
9
|
+
export const KEYS_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $length
|
|
3
|
+
*
|
|
4
|
+
* Validates that the length of a string or array falls within specified bounds (inclusive).
|
|
5
|
+
* Can specify minimum, maximum, exact length, or any combination of min/max.
|
|
6
|
+
*
|
|
7
|
+
* For strings, length is measured in characters. For arrays, length is measured in elements.
|
|
8
|
+
*
|
|
9
|
+
* ### Parameters
|
|
10
|
+
* - `exact` (number, optional): Exact required length. If specified, min/max are ignored.
|
|
11
|
+
* - `min` (number, optional): Minimum length (inclusive). If omitted, no lower bound.
|
|
12
|
+
* - `max` (number, optional): Maximum length (inclusive). If omitted, no upper bound.
|
|
13
|
+
*
|
|
14
|
+
* - With `{min: 3, max: 10}`: strings "abc" to "abcdefghij", arrays with 3-10 elements
|
|
15
|
+
* - With `{exact: 5}`: string "hello", array [1,2,3,4,5]
|
|
16
|
+
*
|
|
17
|
+
* - With `{min: 3, max: 10}`: string "ab" (too short), array with 11 elements (too long)
|
|
18
|
+
* - With `{exact: 5}`: string "hi" (wrong length), array [1,2,3] (wrong length)
|
|
19
|
+
*
|
|
20
|
+
* ### Example
|
|
21
|
+
* ```js
|
|
22
|
+
* // Validate a username is between 3 and 32 characters
|
|
23
|
+
* new Schema('string').validator({$length: {min: 3, max: 32}})
|
|
24
|
+
*
|
|
25
|
+
* // Require an exact number of elements in an array
|
|
26
|
+
* new Schema('array').validator({$length: 3})
|
|
27
|
+
*
|
|
28
|
+
* // Validate a fixed-length code (e.g., ISO country code)
|
|
29
|
+
* new Schema('string').normalizer('$uppercase').validator({$length: {exact: 2}})
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
33
|
+
*/
|
|
34
|
+
export const LENGTH_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $lookup
|
|
3
|
+
*
|
|
4
|
+
* Uses the pipeline value as a key to look up a corresponding value from the argument
|
|
5
|
+
* collection. This is the inverse of `$get`: the input value is the key, the argument is the
|
|
6
|
+
* collection.
|
|
7
|
+
*
|
|
8
|
+
* Returns `undefined` if the key is not found in the collection.
|
|
9
|
+
*
|
|
10
|
+
* ### Parameters
|
|
11
|
+
* - Object collection (object, required): The key/value lookup table.
|
|
12
|
+
*
|
|
13
|
+
* ### Example
|
|
14
|
+
* ```js
|
|
15
|
+
* // Map a string value to a numeric code
|
|
16
|
+
* new Schema('string').transformer({$lookup: {low: 1, medium: 2, high: 3}})
|
|
17
|
+
* // 'medium' → 2
|
|
18
|
+
*
|
|
19
|
+
* // Use a role name to look up its permission set
|
|
20
|
+
* new Schema('string').transformer({
|
|
21
|
+
* $lookup: {$literal: {
|
|
22
|
+
* admin: ['read', 'write', 'delete'],
|
|
23
|
+
* editor: ['read', 'write'],
|
|
24
|
+
* viewer: ['read'],
|
|
25
|
+
* }}
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // Validate that a key exists in the table (require a defined result)
|
|
29
|
+
* new Schema('string').validator({
|
|
30
|
+
* $require: {$lookup: {$literal: {us: 'United States', uk: 'United Kingdom', ca: 'Canada'}}}
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
35
|
+
*/
|
|
36
|
+
export const LOOKUP_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $lowercase
|
|
3
|
+
*
|
|
4
|
+
* Converts a string value to lowercase.
|
|
5
|
+
* Safe to use in normalize phase (non-throwing).
|
|
6
|
+
*
|
|
7
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
8
|
+
*/
|
|
9
|
+
export const LOWERCASE_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @import { ValueProcessorDefinition } from '../../value-processor/value-processor.js' */
|
|
2
|
+
/**
|
|
3
|
+
* ## $map
|
|
4
|
+
*
|
|
5
|
+
* Polymorphic map operator. Applies a processor to each element of an array, or to each
|
|
6
|
+
* value of a plain object. Returns a new collection of the same shape with transformed values.
|
|
7
|
+
*
|
|
8
|
+
* - **Array input**: maps over elements; `undefined` results from the processor appear as `undefined` in output.
|
|
9
|
+
* - **Object input**: maps over values; keys are always preserved in the output.
|
|
10
|
+
* - **Non-collection input**: throws a `ConstraintError`.
|
|
11
|
+
*
|
|
12
|
+
* Note that `null` returned by the processor is the standard prune signal and will remove
|
|
13
|
+
* the element/entry from the output.
|
|
14
|
+
*
|
|
15
|
+
* ### Parameters
|
|
16
|
+
* - `processor` (any valid processor spec, required): Applied to each element or value.
|
|
17
|
+
*
|
|
18
|
+
* ### Example
|
|
19
|
+
* ```js
|
|
20
|
+
* // Uppercase every string in an array
|
|
21
|
+
* new Schema('array').transformer({$map: '$uppercase'})
|
|
22
|
+
*
|
|
23
|
+
* // Parse every element as a number
|
|
24
|
+
* new Schema('array').transformer({$map: '$number'})
|
|
25
|
+
*
|
|
26
|
+
* // Apply a pipeline to every value in an object
|
|
27
|
+
* new Schema('object').transformer({$map: ['$trim', '$lowercase']})
|
|
28
|
+
* // {name: ' Alice ', city: ' NYC '} → {name: 'alice', city: 'nyc'}
|
|
29
|
+
*
|
|
30
|
+
* // Extract a nested field from each element
|
|
31
|
+
* new Schema('array').transformer({$map: {$get: 'id'}})
|
|
32
|
+
* // [{id: 1, name: 'a'}, {id: 2, name: 'b'}] → [1, 2]
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @type {ValueProcessorDefinition}
|
|
36
|
+
*/
|
|
37
|
+
export const MAP_OPERATOR: ValueProcessorDefinition;
|
|
38
|
+
import type { ValueProcessorDefinition } from '../../value-processor/value-processor.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $match
|
|
3
|
+
*
|
|
4
|
+
* Operator that executes a RegExp match against a string input and returns the extracted result.
|
|
5
|
+
* Non-string values are passed through unchanged. Returns `undefined` if the string does not match.
|
|
6
|
+
*
|
|
7
|
+
* - If the RegExp contains named capture groups (`(?<name>...)`), returns the `groups`
|
|
8
|
+
* object (ES2018 named captures) as a plain object.
|
|
9
|
+
* - Otherwise, returns a plain array of the full match and positional capture groups.
|
|
10
|
+
*
|
|
11
|
+
* ### Parameters
|
|
12
|
+
* - `pattern` (RegExp, required): The pattern to match against.
|
|
13
|
+
*
|
|
14
|
+
* ### Example
|
|
15
|
+
* ```js
|
|
16
|
+
* // Extract named capture groups from a date string
|
|
17
|
+
* new Schema('string').transformer({$match: /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/})
|
|
18
|
+
* // '2026-03-21' → {year: '2026', month: '03', day: '21'}
|
|
19
|
+
*
|
|
20
|
+
* // Extract positional captures from a version string
|
|
21
|
+
* new Schema('string').transformer({$match: /^(\d+)\.(\d+)\.(\d+)$/})
|
|
22
|
+
* // '1.2.3' → ['1.2.3', '1', '2', '3']
|
|
23
|
+
*
|
|
24
|
+
* // Use with $when to only proceed when the pattern matched
|
|
25
|
+
* new Schema('string').transformer({
|
|
26
|
+
* $when: [{$match: /^Bearer (.+)$/}]
|
|
27
|
+
* })
|
|
28
|
+
* // 'Bearer abc123' → ['Bearer abc123', 'abc123']
|
|
29
|
+
* // 'Basic xyz' → undefined (no match)
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
33
|
+
*/
|
|
34
|
+
export const MATCH_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $matches
|
|
3
|
+
*
|
|
4
|
+
* Constraint that tests the string representation of the input against a RegExp.
|
|
5
|
+
* Throws a `ConstraintError` if the input does not match. Returns the original value unchanged.
|
|
6
|
+
*
|
|
7
|
+
* This is the explicit constraint form; bare RegExp values in processor specs are no longer
|
|
8
|
+
* treated as implicit constraints and must be wrapped with `$matches`.
|
|
9
|
+
*
|
|
10
|
+
* ### Parameters
|
|
11
|
+
* - `pattern` (RegExp, required): The pattern to test against.
|
|
12
|
+
*
|
|
13
|
+
* ### Example
|
|
14
|
+
* ```js
|
|
15
|
+
* // Validate a semantic version string
|
|
16
|
+
* new Schema('string').validator({$matches: /^\d+\.\d+\.\d+$/})
|
|
17
|
+
*
|
|
18
|
+
* // Validate a slug (lowercase letters, numbers, hyphens only)
|
|
19
|
+
* new Schema('string').validator({$matches: /^[a-z0-9]+(?:-[a-z0-9]+)*$/})
|
|
20
|
+
*
|
|
21
|
+
* // Validate a hex color code
|
|
22
|
+
* new Schema('object', {
|
|
23
|
+
* color: new Schema('string').validator({$matches: /^#[0-9a-fA-F]{6}$/}),
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
28
|
+
*/
|
|
29
|
+
export const MATCHES_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $abs
|
|
3
|
+
*
|
|
4
|
+
* Returns the absolute value of a number.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
* ```js
|
|
8
|
+
* // Normalize a signed offset to always be non-negative
|
|
9
|
+
* new Schema('number').transformer('$abs')
|
|
10
|
+
*
|
|
11
|
+
* // Ensure a distance value is always positive
|
|
12
|
+
* new Schema('object', {
|
|
13
|
+
* distance: new Schema('number').transformer('$abs'),
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
18
|
+
*/
|
|
19
|
+
export const ABS_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
20
|
+
/**
|
|
21
|
+
* ## $pow
|
|
22
|
+
*
|
|
23
|
+
* Raises a number to a power.
|
|
24
|
+
*
|
|
25
|
+
* - `{$pow: exponent}` — raises the input value to the given exponent
|
|
26
|
+
* - `{$pow: {exponent, base}}` — raises `base` to `exponent`, ignoring the input value
|
|
27
|
+
*
|
|
28
|
+
* ### Parameters
|
|
29
|
+
* - `exponent` (number, required): The exponent.
|
|
30
|
+
* - `base` (number, optional): Override the base. Defaults to the input value.
|
|
31
|
+
*
|
|
32
|
+
* ### Example
|
|
33
|
+
* ```js
|
|
34
|
+
* // Square the input value
|
|
35
|
+
* new Schema('number').transformer({$pow: {exponent: 2}})
|
|
36
|
+
* // 4 → 16, 3 → 9
|
|
37
|
+
*
|
|
38
|
+
* // Compute 2^n where n is the input
|
|
39
|
+
* new Schema('number').transformer({$pow: {exponent: '$number', base: 2}})
|
|
40
|
+
*
|
|
41
|
+
* // Convert bytes to kilobytes using inverse power
|
|
42
|
+
* new Schema('number').transformer({$pow: {exponent: -1}})
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
46
|
+
*/
|
|
47
|
+
export const POW_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
48
|
+
/**
|
|
49
|
+
* ## $sqrt
|
|
50
|
+
*
|
|
51
|
+
* Returns the square root of a number.
|
|
52
|
+
*
|
|
53
|
+
* ### Example
|
|
54
|
+
* ```js
|
|
55
|
+
* // Compute the magnitude of a value
|
|
56
|
+
* new Schema('number').transformer('$sqrt')
|
|
57
|
+
*
|
|
58
|
+
* // Validate then take the square root
|
|
59
|
+
* new Schema('number').validator('$positive').transformer('$sqrt')
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
63
|
+
*/
|
|
64
|
+
export const SQRT_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
65
|
+
/**
|
|
66
|
+
* ## $clamp
|
|
67
|
+
*
|
|
68
|
+
* Constrains a number to a `[min, max]` range by returning the nearest boundary when the value
|
|
69
|
+
* falls outside. Unlike `$range` (which throws), `$clamp` transforms.
|
|
70
|
+
*
|
|
71
|
+
* Both `min` and `max` are optional; omitting either leaves that end unclamped.
|
|
72
|
+
*
|
|
73
|
+
* ### Parameters
|
|
74
|
+
* - `min` (number, optional): Lower bound.
|
|
75
|
+
* - `max` (number, optional): Upper bound.
|
|
76
|
+
*
|
|
77
|
+
* ### Example
|
|
78
|
+
* ```js
|
|
79
|
+
* // Clamp a volume setting to [0, 100]
|
|
80
|
+
* new Schema('number').transformer({$clamp: {min: 0, max: 100}})
|
|
81
|
+
*
|
|
82
|
+
* // Clamp retry count to at most 10 (no lower bound)
|
|
83
|
+
* new Schema('number').transformer({$clamp: {max: 10}})
|
|
84
|
+
*
|
|
85
|
+
* // Ensure a timeout is at least 100ms
|
|
86
|
+
* new Schema('number').transformer({$clamp: {min: 100}})
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
90
|
+
*/
|
|
91
|
+
export const CLAMP_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $merge-deep
|
|
3
|
+
*
|
|
4
|
+
* Recursively deep-merges the argument object into the input object, returning
|
|
5
|
+
* a new object. Nested plain objects are merged rather than replaced; arrays
|
|
6
|
+
* and primitive values are overwritten. The input is not mutated.
|
|
7
|
+
*
|
|
8
|
+
* Use `$merge` for shallow (one-level) merging.
|
|
9
|
+
*
|
|
10
|
+
* ### Parameters
|
|
11
|
+
* - Object of fields to deep-merge (object, required): Key/value pairs to apply over the input.
|
|
12
|
+
*
|
|
13
|
+
* ### Example
|
|
14
|
+
* ```js
|
|
15
|
+
* // Deep-merge default nested config into the user-supplied object
|
|
16
|
+
* new Schema('object').transformer({
|
|
17
|
+
* '$merge-deep': {
|
|
18
|
+
* logging: {level: 'info', format: 'json'},
|
|
19
|
+
* server: {port: 3000},
|
|
20
|
+
* }
|
|
21
|
+
* })
|
|
22
|
+
* // {logging: {level: 'debug'}, server: {host: 'localhost'}}
|
|
23
|
+
* // → {logging: {level: 'debug', format: 'json'}, server: {host: 'localhost', port: 3000}}
|
|
24
|
+
*
|
|
25
|
+
* // Inject a nested metadata field without overwriting sibling keys
|
|
26
|
+
* new Schema('object').transformer({'$merge-deep': {meta: {version: 1}}})
|
|
27
|
+
* // {meta: {author: 'rg'}} → {meta: {author: 'rg', version: 1}}
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
31
|
+
*/
|
|
32
|
+
export const MERGE_DEEP_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $merge
|
|
3
|
+
*
|
|
4
|
+
* Merges the argument object into the input object (shallow). The argument fields take
|
|
5
|
+
* precedence over same-named fields in the input, consistent with the "apply to the
|
|
6
|
+
* value being passed through" pattern.
|
|
7
|
+
*
|
|
8
|
+
* The input object is not mutated; a new object is returned.
|
|
9
|
+
*
|
|
10
|
+
* ### Parameters
|
|
11
|
+
* - Object of fields to merge (object, required): Key/value pairs to apply over the input.
|
|
12
|
+
*
|
|
13
|
+
* ### Example
|
|
14
|
+
* ```js
|
|
15
|
+
* // Inject default fields into every output object
|
|
16
|
+
* new Schema('object').transformer({$merge: {version: 1, active: true}})
|
|
17
|
+
* // {id: 42} → {id: 42, version: 1, active: true}
|
|
18
|
+
*
|
|
19
|
+
* // Overwrite a specific field in the result
|
|
20
|
+
* new Schema('object').transformer({$merge: {status: 'normalized'}})
|
|
21
|
+
* // {id: 1, status: 'raw'} → {id: 1, status: 'normalized'}
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
25
|
+
*/
|
|
26
|
+
export const MERGE_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $metadata
|
|
3
|
+
*
|
|
4
|
+
* Extracts named metadata from a schema, either from the current schema or a parameter.
|
|
5
|
+
*
|
|
6
|
+
* Useful for getting standard metadata like `type` or `description`, or as a way to transport information
|
|
7
|
+
* between schemas that get aggregated together.
|
|
8
|
+
*
|
|
9
|
+
* If a schema value is passed, the metadata is retrieved only from that particular schema.
|
|
10
|
+
* If a schema path is passed, or it is left empty (and thus uses the current schema), $metadata will
|
|
11
|
+
* search from the current schema to the root and return the first value located. To suppress this search,
|
|
12
|
+
* pass `false` to the `inherit` parameter.
|
|
13
|
+
*
|
|
14
|
+
* Returns `undefined` if the referenced schema or metadata key does not exist.
|
|
15
|
+
*
|
|
16
|
+
* ### Parameters
|
|
17
|
+
* - `name` (string, required): The name of the metadata to extract from the schema.
|
|
18
|
+
* - `schema` (CompiledSchema|string, optional): The schema (or a relative path to a schema) to extract metadata from. Defaults to the current schema.
|
|
19
|
+
* - `inherit` (boolean, optional): Whether to search for metadata in a parent if not found in implicit schema.
|
|
20
|
+
*
|
|
21
|
+
* ### Example
|
|
22
|
+
* ```js
|
|
23
|
+
* // Here is an example that will simply propagate the current schema description
|
|
24
|
+
* new Schema('object')
|
|
25
|
+
* .property('description', new Schema('string')
|
|
26
|
+
* .required()
|
|
27
|
+
* .meta('description', 'This will be pulled into the property value')
|
|
28
|
+
* .normalizer({$metadata: 'description'}))
|
|
29
|
+
*
|
|
30
|
+
* // Extract metadata from a sibling property using a relative path.
|
|
31
|
+
* // If 'temperature' lacked a 'unit' meta, $metadata would inherit 'metric' from the parent.
|
|
32
|
+
* const weatherSchema = await resolver.compile(
|
|
33
|
+
* new Schema('object')
|
|
34
|
+
* .meta('unit', 'metric')
|
|
35
|
+
* .property('temperature', new Schema('number').meta('unit', '°C'))
|
|
36
|
+
* .property('unit', new Schema('string')
|
|
37
|
+
* .default('')
|
|
38
|
+
* .transformer({$metadata: {name: 'unit', schema: '^.temperature'}})
|
|
39
|
+
* )
|
|
40
|
+
* );
|
|
41
|
+
* const weather = await weatherSchema.process({temperature: 22});
|
|
42
|
+
* console.log('weather:', weather);
|
|
43
|
+
* // → {temperature: 22, unit: '°C'}
|
|
44
|
+
*
|
|
45
|
+
* // Unlike most other "get a value" operators, $metadata does not use the pipeline input as the source
|
|
46
|
+
* // because it is focused on the current processor calling context rather than values. However, you can
|
|
47
|
+
* // force it to use a compiled schema in the value pipeline by using $input:
|
|
48
|
+
*
|
|
49
|
+
* new Schema('string')
|
|
50
|
+
* .transformer(new Schema('string').meta('greeting', 'hello world'))
|
|
51
|
+
* .transformer({'$metadata': {name: 'greeting', schema: '$input'}})
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
55
|
+
*/
|
|
56
|
+
export const METADATA_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $negative
|
|
3
|
+
*
|
|
4
|
+
* Validates that a numeric value is negative (less than 0).
|
|
5
|
+
* Input must already be a number; use `$number` in a prior normalizer if coercion from string is needed.
|
|
6
|
+
*
|
|
7
|
+
* See also
|
|
8
|
+
* - `$positive` for the opposite constraint
|
|
9
|
+
* - `$range` for more explicit control (e.g. "non-positive, less than or equal to 0")
|
|
10
|
+
*
|
|
11
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
12
|
+
*/
|
|
13
|
+
export const NEGATIVE_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $never
|
|
3
|
+
*
|
|
4
|
+
* Inverts a processor - Returns the input if the wrapped processor throws or returns an undefined value.
|
|
5
|
+
* Throw a constraint error if the wrapped processor returns a defined value.
|
|
6
|
+
*
|
|
7
|
+
* See `$not` to enforce falseyness.
|
|
8
|
+
*
|
|
9
|
+
* ### Parameters
|
|
10
|
+
* - `value` (ProcessorSpec, required): The processor specification to negate (must not return a defined value).
|
|
11
|
+
*
|
|
12
|
+
* ### Example
|
|
13
|
+
* ```js
|
|
14
|
+
* // Blacklist specific values — reject any input that is found in the lookup table
|
|
15
|
+
* new Schema('string').validator({$never: {$lookup: {admin: true, root: true}}})
|
|
16
|
+
*
|
|
17
|
+
* // Ensure a value does not parse as a number (must be a non-numeric string)
|
|
18
|
+
* new Schema('string').validator({$never: '$numeric'})
|
|
19
|
+
*
|
|
20
|
+
* // Reject any value that resolves from $get (path must NOT exist)
|
|
21
|
+
* new Schema('object').validator({$never: {$get: 'deprecated.field'}})
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}*
|
|
25
|
+
*/
|
|
26
|
+
export const NEVER_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $non-empty
|
|
3
|
+
*
|
|
4
|
+
* Validates that a string, array, or object is not empty. For strings, the value must contain
|
|
5
|
+
* at least one non-whitespace character. For arrays, the length must be greater than zero.
|
|
6
|
+
* For objects, the number of keys must be greater than zero.
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
* ```js
|
|
10
|
+
* // Require a non-blank username
|
|
11
|
+
* new Schema('string').normalizer('$trim').validator('$non-empty')
|
|
12
|
+
*
|
|
13
|
+
* // Require at least one tag
|
|
14
|
+
* new Schema('array').validator('$non-empty')
|
|
15
|
+
*
|
|
16
|
+
* // Require a non-empty configuration object
|
|
17
|
+
* new Schema('object').validator('$non-empty')
|
|
18
|
+
*
|
|
19
|
+
* // Combine trim + non-empty as a common pattern for required text fields
|
|
20
|
+
* new Schema('object', {
|
|
21
|
+
* name: new Schema('string').normalizer('$trim').validator('$non-empty'),
|
|
22
|
+
* description: new Schema('string').normalizer('$trim').validator('$non-empty'),
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
27
|
+
*/
|
|
28
|
+
export const NON_EMPTY_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|