@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,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $date-range
|
|
3
|
+
*
|
|
4
|
+
* Validates that a date value falls within the specified range (inclusive).
|
|
5
|
+
* Can specify minimum, maximum, or both bounds. Bounds are parsed using
|
|
6
|
+
* the same rules as the `date` schema normalizer, so strings, numbers,
|
|
7
|
+
* and Date objects are all accepted.
|
|
8
|
+
*
|
|
9
|
+
* ### Parameters
|
|
10
|
+
* - `min` (optional): Minimum date (inclusive). If omitted, no lower bound.
|
|
11
|
+
* - `max` (optional): Maximum date (inclusive). If omitted, no upper bound.
|
|
12
|
+
*
|
|
13
|
+
* ### Example
|
|
14
|
+
* ```js
|
|
15
|
+
* // Object form with named parameters
|
|
16
|
+
* new Schema('date').validator({'$date-range': {min: '2024-01-01', max: '2024-12-31'}})
|
|
17
|
+
*
|
|
18
|
+
* // Cross-reference: end date must be >= start date
|
|
19
|
+
* new Schema('object')
|
|
20
|
+
* .property('start', new Schema('date'))
|
|
21
|
+
* .property('end', new Schema('date').validator({'$date-range': {min: {$reference: '^start'}}}))
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
25
|
+
*/
|
|
26
|
+
export const DATE_RANGE_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $defined
|
|
3
|
+
*
|
|
4
|
+
* Allow any value, as long as it's defined.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
* ```js
|
|
8
|
+
* // Ensure an optional field, when supplied, is not undefined
|
|
9
|
+
* new Schema('any').validator('$defined')
|
|
10
|
+
*
|
|
11
|
+
* // Gate a sub-pipeline: only run if the value is defined
|
|
12
|
+
* new Schema('any').normalizer({$gate: ['$defined', '$trim']})
|
|
13
|
+
*
|
|
14
|
+
* // Require a computed result to be defined
|
|
15
|
+
* new Schema('string').validator({$require: {$get: {path: 'nested.key'}}})
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
19
|
+
*/
|
|
20
|
+
export const DEFINED_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $each
|
|
3
|
+
*
|
|
4
|
+
* Applies a processor to each element of an array. The processor can be any valid
|
|
5
|
+
* processor specification (RegExp, function, keyword, or parameterized processor).
|
|
6
|
+
* If any element fails validation, the entire array is rejected.
|
|
7
|
+
*
|
|
8
|
+
* This operator is useful for applying consistent validation or transformation rules
|
|
9
|
+
* across all array elements without requiring explicit array element schemas.
|
|
10
|
+
*
|
|
11
|
+
* ### Parameters
|
|
12
|
+
* - `processor` (any valid processor spec, required): The processor to apply to each element.
|
|
13
|
+
* Can be a RegExp, function, string keyword (e.g., `'$numeric'`), or parameterized processor object.
|
|
14
|
+
*
|
|
15
|
+
* ### Example
|
|
16
|
+
* ```js
|
|
17
|
+
* // Trim whitespace from every string in an array
|
|
18
|
+
* new Schema('array').transformer({$each: '$trim'})
|
|
19
|
+
*
|
|
20
|
+
* // Validate that every element is numeric
|
|
21
|
+
* new Schema('array').validator({$each: '$numeric'})
|
|
22
|
+
*
|
|
23
|
+
* // Validate that each element is within a range
|
|
24
|
+
* new Schema('array').validator({$each: {$range: {min: 0, max: 100}}})
|
|
25
|
+
*
|
|
26
|
+
* // Normalize every tag: trim and lowercase
|
|
27
|
+
* new Schema('object', {
|
|
28
|
+
* tags: new Schema('array').transformer({$each: ['$trim', '$lowercase']}),
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
33
|
+
*/
|
|
34
|
+
export const EACH_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $email
|
|
3
|
+
*
|
|
4
|
+
* Validates that a string matches a practical email address format (local-part@domain.tld).
|
|
5
|
+
*
|
|
6
|
+
* **Username (local part):**
|
|
7
|
+
* - Allowed characters: letters, digits, `.`, `_`, `%`, `+`, `-`
|
|
8
|
+
* - Must not start or end with a dot
|
|
9
|
+
* - Must not contain consecutive dots
|
|
10
|
+
*
|
|
11
|
+
* **Domain:**
|
|
12
|
+
* - Must consist of at least two dot-separated labels (e.g. `example.com`)
|
|
13
|
+
* - Labels may contain letters, digits, and hyphens (no leading/trailing hyphens)
|
|
14
|
+
* - Must not contain consecutive dots
|
|
15
|
+
* - Must end in a TLD of 2+ letters
|
|
16
|
+
*
|
|
17
|
+
* **Not supported (by design):** quoted local parts, comments, IP address literals, emoji,
|
|
18
|
+
* non-ASCII characters. This processor is intended to handle addresses as they are typically
|
|
19
|
+
* used. If you need to support all the madness that the official RFC allows, you'll need to
|
|
20
|
+
* write your own version.
|
|
21
|
+
*
|
|
22
|
+
* The default behavior is to convert the address to lower case for consistency, but this
|
|
23
|
+
* can be overridden.
|
|
24
|
+
*
|
|
25
|
+
* ### Parameters
|
|
26
|
+
* - `case` (string, default `'lower'`): Case conversion applied to the domain portion,
|
|
27
|
+
* and (unless overridden by `case-sensitive`) to the username portion as well.
|
|
28
|
+
* Accepts `'lower'` or `'upper'`, or if falsey, doesn't do any conversion.
|
|
29
|
+
* - `case-sensitive` (boolean, default `false`): When `true`, preserve the original case of
|
|
30
|
+
* the username portion. When `false`, the username is converted using the `case` parameter.
|
|
31
|
+
* (Rationale: RFC 5321 technically allows case-sensitive local parts, but virtually all
|
|
32
|
+
* providers treat them as case-insensitive.)
|
|
33
|
+
* - `filter` (boolean, default `false`): When `true`, strip plus-addressing
|
|
34
|
+
* (e.g. `user+tag@` becomes `user@`), and for `gmail.com` domains, additionally remove
|
|
35
|
+
* all dots from the username (since Gmail ignores them).
|
|
36
|
+
*
|
|
37
|
+
* ### Example
|
|
38
|
+
* ```js
|
|
39
|
+
* // Basic validation only
|
|
40
|
+
* new Schema('string').validator('$email')
|
|
41
|
+
*
|
|
42
|
+
* // Normalize to lowercase, strip plus-addressing
|
|
43
|
+
* new Schema('string').validator({'$email': {filter: true}})
|
|
44
|
+
*
|
|
45
|
+
* // Preserve username case
|
|
46
|
+
* new Schema('string').validator({'$email': {'case-sensitive': true}})
|
|
47
|
+
*
|
|
48
|
+
* // Work for the government and like to shout at people?
|
|
49
|
+
* new Schema('string').validator({'$email': {'case': 'upper'}}
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
53
|
+
*/
|
|
54
|
+
export const EMAIL_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $entries
|
|
3
|
+
*
|
|
4
|
+
* Returns the enumerable own properties of an object as an array of `[key, value]` pairs,
|
|
5
|
+
* matching the output of `Object.entries()`.
|
|
6
|
+
*
|
|
7
|
+
* The resulting array can be reconstructed back into an object with `$object`.
|
|
8
|
+
*
|
|
9
|
+
* Throws if the input is not a plain object.
|
|
10
|
+
*
|
|
11
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
12
|
+
*/
|
|
13
|
+
export const ENTRIES_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $eq
|
|
3
|
+
*
|
|
4
|
+
* Do a deep equality check between the value and the provided constraint value.
|
|
5
|
+
*
|
|
6
|
+
* ### Parameters
|
|
7
|
+
* - `value` (any, required): The value to compare against using deep equality.
|
|
8
|
+
*
|
|
9
|
+
* ### Example
|
|
10
|
+
* ```js
|
|
11
|
+
* // Ensure a status field can only be 'active'
|
|
12
|
+
* new Schema('string').validator({$eq: 'active'})
|
|
13
|
+
*
|
|
14
|
+
* // Ensure an object matches an exact structure
|
|
15
|
+
* new Schema('object').validator({$eq: {type: 'config', version: 1}})
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}*
|
|
19
|
+
*/
|
|
20
|
+
export const EQ_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $filter
|
|
3
|
+
*
|
|
4
|
+
* Runs a processor on each element of the input array, keeping elements for which the processor
|
|
5
|
+
* succeeds and returning the processor's output value (consistent with standard processor semantics).
|
|
6
|
+
* Elements are filtered out if the processor throws or returns undefined.
|
|
7
|
+
* (Note that processor results are not checked for truthiness — only for definedness.)
|
|
8
|
+
*
|
|
9
|
+
* Non-arrays are "filtered" as an empty array.
|
|
10
|
+
*
|
|
11
|
+
* ### Parameters
|
|
12
|
+
* - `processor` (any valid processor spec, optional): The processor to apply to each element.
|
|
13
|
+
* Elements where the processor returns undefined or throws are excluded from the result.
|
|
14
|
+
* If omitted, null/undefined elements are removed.
|
|
15
|
+
*
|
|
16
|
+
* ### Example
|
|
17
|
+
* ```js
|
|
18
|
+
* // Remove null and undefined values from an array
|
|
19
|
+
* new Schema('array').transformer('$filter')
|
|
20
|
+
*
|
|
21
|
+
* // Keep only numeric strings
|
|
22
|
+
* new Schema('array').transformer({$filter: '$numeric'})
|
|
23
|
+
*
|
|
24
|
+
* // Keep only values within range
|
|
25
|
+
* new Schema('array').transformer({$filter: {$range: {min: 0, max: 100}}})
|
|
26
|
+
*
|
|
27
|
+
* // Filter out non-email strings from a list
|
|
28
|
+
* new Schema('object', {
|
|
29
|
+
* recipients: new Schema('array').transformer({$filter: '$email'}),
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
34
|
+
*/
|
|
35
|
+
export const FILTER_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $find-schema
|
|
3
|
+
*
|
|
4
|
+
* Find a schema in the schema hierarchy based on a dotted path. Returns the current schema by default.
|
|
5
|
+
* The provided path is interpreted relative to the currently active schema but supports navigation
|
|
6
|
+
* to the root schema using '/' and parent schema using '^'.
|
|
7
|
+
*
|
|
8
|
+
* ### Parameters
|
|
9
|
+
* - `path` (string | number, required): Dot-separated property path or array index.
|
|
10
|
+
*
|
|
11
|
+
* Example paths:
|
|
12
|
+
* - '': The current schema.
|
|
13
|
+
* - '/': The root schema.
|
|
14
|
+
* - 'xyzzy': Find the 'xyzzy' child of the current schema.
|
|
15
|
+
* - 'xyzzy.plugh': Find the 'plugh' child of the 'xyzzy' child of the current schema.
|
|
16
|
+
* - 'child.^': The current schema if and only if the child exists.
|
|
17
|
+
* - `/.foo.bar`: Find the 'bar' property in the 'foo' child of the root.
|
|
18
|
+
* - `^`: Return the parent schema
|
|
19
|
+
* - `^^jim`: Get the grandparent schema's child named 'jim' (uncle jim)
|
|
20
|
+
* - `^.^.jim`: Same thing (extra dots are ignored.)
|
|
21
|
+
*
|
|
22
|
+
* ```js
|
|
23
|
+
* new Schema('any').transformer({'$metadata': {name: 'description', schema: {'$find-schema': '^'}}})
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
27
|
+
*/
|
|
28
|
+
export const FIND_SCHEMA_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $flatten
|
|
3
|
+
*
|
|
4
|
+
* Returns a new array with sub-array elements flattened to the specified depth.
|
|
5
|
+
* Throws if the input is not an array.
|
|
6
|
+
*
|
|
7
|
+
* ### Parameters
|
|
8
|
+
* - `depth` (number, optional, default `1`): The depth to flatten. Use `Infinity` to flatten completely.
|
|
9
|
+
*
|
|
10
|
+
* ### Example
|
|
11
|
+
* ```js
|
|
12
|
+
* // Flatten one level of nesting
|
|
13
|
+
* new Schema('array').transformer('$flatten')
|
|
14
|
+
* // [[1, 2], [3, 4]] → [1, 2, 3, 4]
|
|
15
|
+
*
|
|
16
|
+
* // Flatten all levels
|
|
17
|
+
* new Schema('array').transformer({$flatten: {depth: Infinity}})
|
|
18
|
+
* // [1, [2, [3, [4]]]] → [1, 2, 3, 4]
|
|
19
|
+
*
|
|
20
|
+
* // Flatten exactly 2 levels
|
|
21
|
+
* new Schema('array').transformer({$flatten: {depth: 2}})
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
25
|
+
*/
|
|
26
|
+
export const FLATTEN_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $floor
|
|
3
|
+
*
|
|
4
|
+
* Rounds a numeric value down to the specified number of decimal places.
|
|
5
|
+
* Non-numeric values are passed through unchanged. Safe to use in normalize phase (non-throwing).
|
|
6
|
+
*
|
|
7
|
+
* ### Parameters
|
|
8
|
+
* - `precision` (number, optional): Number of decimal places to preserve. Defaults to 0 (round to integer).
|
|
9
|
+
*
|
|
10
|
+
* **Input/Output Examples**:
|
|
11
|
+
* - `$floor`: `3.7` → `3`, `9.99` → `9`, `-2.3` → `-3`
|
|
12
|
+
* - `{$floor: 2}`: `3.14159` → `3.14`, `99.999` → `99.99`, `5.1` → `5.1`
|
|
13
|
+
* - `{$floor: 1}`: `3.76` → `3.7`, `9.01` → `9.0`
|
|
14
|
+
*
|
|
15
|
+
* ### Example
|
|
16
|
+
* ```js
|
|
17
|
+
* // Truncate to integer (floor toward zero for positive numbers)
|
|
18
|
+
* new Schema('number').transformer('$floor')
|
|
19
|
+
* // 9.99 → 9
|
|
20
|
+
*
|
|
21
|
+
* // Preserve 2 decimal places, discarding extra precision
|
|
22
|
+
* new Schema('number').transformer({$floor: {precision: 2}})
|
|
23
|
+
* // 3.14159 → 3.14
|
|
24
|
+
*
|
|
25
|
+
* // Strip sub-cent precision from a price field
|
|
26
|
+
* new Schema('object', {
|
|
27
|
+
* price: new Schema('number').transformer({$floor: {precision: 2}}),
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
32
|
+
*/
|
|
33
|
+
export const FLOOR_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $get
|
|
3
|
+
*
|
|
4
|
+
* Extracts a value from the input using a dot-separated path (for objects) or a numeric
|
|
5
|
+
* index (for arrays). Does not require the path to be declared as a schema property —
|
|
6
|
+
* use `$property` when schema-awareness is needed.
|
|
7
|
+
*
|
|
8
|
+
* Returns `undefined` if the path does not resolve.
|
|
9
|
+
*
|
|
10
|
+
* ### Parameters
|
|
11
|
+
* - `path` (string | number, required): Dot-separated property path or array index.
|
|
12
|
+
*
|
|
13
|
+
* ### Example
|
|
14
|
+
* ```js
|
|
15
|
+
* // Extract a nested property from an object
|
|
16
|
+
* new Schema('object').transformer({$get: {path: 'database.host'}})
|
|
17
|
+
* // {database: {host: 'localhost'}} → 'localhost'
|
|
18
|
+
*
|
|
19
|
+
* // Extract an array element by index
|
|
20
|
+
* new Schema('array').transformer({$get: {path: 0}})
|
|
21
|
+
* // ['first', 'second'] → 'first'
|
|
22
|
+
*
|
|
23
|
+
* // Use as a conditional predicate — only proceed if the path exists
|
|
24
|
+
* new Schema('object').transformer({
|
|
25
|
+
* $when: [{$get: {path: 'config.timeout'}}]
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
30
|
+
*/
|
|
31
|
+
export const GET_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $group-by
|
|
3
|
+
*
|
|
4
|
+
* Groups an array of objects by a key, returning an object whose values are arrays of elements
|
|
5
|
+
* that share that key value.
|
|
6
|
+
*
|
|
7
|
+
* - `{'$group-by': 'key'}` — groups by the named property on each element
|
|
8
|
+
* - `{'$group-by': processor}` — groups by the result of executing the processor against each element
|
|
9
|
+
* (any compiled processor spec, e.g. `'$type'`, `{$get: 'field'}`, or a function)
|
|
10
|
+
*
|
|
11
|
+
* Elements where the extracted key is `undefined` are omitted from the result.
|
|
12
|
+
* Insertion order is preserved within each group.
|
|
13
|
+
*
|
|
14
|
+
* ### Parameters
|
|
15
|
+
* - `key` (string or processor, required): Property name to group by, or a processor that extracts
|
|
16
|
+
* the grouping key from each element. Plain strings (no leading `$`) are treated as property names;
|
|
17
|
+
* all other processor specs are executed as extractors.
|
|
18
|
+
*
|
|
19
|
+
* ### Example
|
|
20
|
+
* ```js
|
|
21
|
+
* // Group an array of log entries by their severity level
|
|
22
|
+
* new Schema('array').transformer({'$group-by': 'level'})
|
|
23
|
+
* // [{level:'error', msg:'...'}, {level:'info', msg:'...'}]
|
|
24
|
+
* // → {error: [{level:'error', ...}], info: [{level:'info', ...}]}
|
|
25
|
+
*
|
|
26
|
+
* // Group by a computed key (the JS type of each element)
|
|
27
|
+
* new Schema('array').transformer({'$group-by': '$type'})
|
|
28
|
+
* // [1, 'a', 2, 'b'] → {number: [1, 2], string: ['a', 'b']}
|
|
29
|
+
*
|
|
30
|
+
* // Group by a nested property using $get
|
|
31
|
+
* new Schema('array').transformer({'$group-by': {$get: 'meta.region'}})
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
35
|
+
*/
|
|
36
|
+
export const GROUP_BY_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $has-prefix
|
|
3
|
+
*
|
|
4
|
+
* Check that the provided string value starts with the prefix value
|
|
5
|
+
*
|
|
6
|
+
* ### Parameters
|
|
7
|
+
* - `match` (string, required): The required prefix string.
|
|
8
|
+
*
|
|
9
|
+
* ### Example
|
|
10
|
+
* ```js
|
|
11
|
+
* // Require all feature flag names to start with 'ff_'
|
|
12
|
+
* new Schema('string').validator({'$has-prefix': 'ff_'})
|
|
13
|
+
*
|
|
14
|
+
* // Require environment variables to start with 'APP_'
|
|
15
|
+
* new Schema('object', {
|
|
16
|
+
* envKey: new Schema('string').validator({'$has-prefix': 'APP_'}),
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}*
|
|
21
|
+
*/
|
|
22
|
+
export const HAS_PREFIX_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $has-suffix
|
|
3
|
+
*
|
|
4
|
+
* Check that the provided string value ends with the suffix value
|
|
5
|
+
*
|
|
6
|
+
* ### Parameters
|
|
7
|
+
* - `match` (string, required): The required suffix string.
|
|
8
|
+
*
|
|
9
|
+
* ### Example
|
|
10
|
+
* ```js
|
|
11
|
+
* // Require file paths to end with '.json'
|
|
12
|
+
* new Schema('string').validator({'$has-suffix': '.json'})
|
|
13
|
+
*
|
|
14
|
+
* // Require callback URLs to end with '/callback'
|
|
15
|
+
* new Schema('string').validator({'$has-suffix': '/callback'})
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}*
|
|
19
|
+
*/
|
|
20
|
+
export const HAS_SUFFIX_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $hex
|
|
3
|
+
*
|
|
4
|
+
* Validates that a string contains only valid hexadecimal characters (0-9, a-f, A-F).
|
|
5
|
+
* Does not require or validate a "0x" prefix - the value should be the raw hex digits.
|
|
6
|
+
*
|
|
7
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
8
|
+
*/
|
|
9
|
+
export const HEX_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $hostname
|
|
3
|
+
*
|
|
4
|
+
* Validates that a string matches valid hostname format according to RFC 1123.
|
|
5
|
+
* Hostnames must start and end with alphanumeric characters and may contain
|
|
6
|
+
* hyphens between labels. Each label (section between dots) can be up to 63
|
|
7
|
+
* characters long.
|
|
8
|
+
*
|
|
9
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
10
|
+
*/
|
|
11
|
+
export const HOSTNAME_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $http-url
|
|
3
|
+
*
|
|
4
|
+
* Validates that a string is a valid HTTP or HTTPS URL. Uses the URL Web API for
|
|
5
|
+
* validation and specifically requires the protocol to be either `http:` or `https:`.
|
|
6
|
+
*
|
|
7
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
8
|
+
*/
|
|
9
|
+
export const HTTP_URL_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** @import {ValueProcessor, ValueProcessorDefinition} from '../../value-processor/value-processor.js' */
|
|
2
|
+
/**
|
|
3
|
+
* ## $in
|
|
4
|
+
*
|
|
5
|
+
* Validates that a value is included in an allowed list of values.
|
|
6
|
+
* Uses strict equality (===) for comparison.
|
|
7
|
+
*
|
|
8
|
+
* ### Parameters
|
|
9
|
+
* The parameter is an array (not an object) of allowed values passed directly to the processor.
|
|
10
|
+
* - Array of values (array, required): The allowed values to match against using strict equality
|
|
11
|
+
*
|
|
12
|
+
* ### Example
|
|
13
|
+
* ```js
|
|
14
|
+
* // Restrict a log level to known values
|
|
15
|
+
* new Schema('string').validator({$in: ['debug', 'info', 'warn', 'error']})
|
|
16
|
+
*
|
|
17
|
+
* // Accept only specific HTTP methods
|
|
18
|
+
* new Schema('string').normalizer('$uppercase').validator({$in: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']})
|
|
19
|
+
*
|
|
20
|
+
* // Restrict a numeric status code to expected values
|
|
21
|
+
* new Schema('number').validator({$in: [200, 201, 204, 400, 401, 403, 404, 500]})
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @type {ValueProcessorDefinition}
|
|
25
|
+
*/
|
|
26
|
+
export const IN_CONSTRAINT: ValueProcessorDefinition;
|
|
27
|
+
import type { ValueProcessorDefinition } from '../../value-processor/value-processor.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $index-by
|
|
3
|
+
*
|
|
4
|
+
* Groups an array of objects by a unique key, returning an object whose value is the single array element value
|
|
5
|
+
* that has that key. If the keys are not unique, throws an error.
|
|
6
|
+
*
|
|
7
|
+
* - `{'$index-by': 'key'}` — indexes by the named property on each element
|
|
8
|
+
* - `{'$index-by': processor}` — indexes by the result of executing the processor against each element
|
|
9
|
+
*
|
|
10
|
+
* Elements where the extracted key is `undefined` are omitted from the result.
|
|
11
|
+
*
|
|
12
|
+
* ### Parameters
|
|
13
|
+
* - `key` (string): Property name to group by, or a processor that extracts
|
|
14
|
+
* the grouping key from each element. If you use a bare argument or a single element array,
|
|
15
|
+
* it is assumed to be the key.
|
|
16
|
+
* - `processor`: Must be passed via object parameter. Must be a processor that will parse the provided
|
|
17
|
+
* element and return the index key. The outer collection is passed to the processor as `options.input`.
|
|
18
|
+
*
|
|
19
|
+
* ### Example
|
|
20
|
+
* ```js
|
|
21
|
+
* // TODO
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
25
|
+
*/
|
|
26
|
+
export const INDEX_BY_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get all built-in value processor definitions
|
|
3
|
+
* @returns {ValueProcessorDefinition[]}
|
|
4
|
+
*/
|
|
5
|
+
export function getBuiltinProcessors(): ValueProcessorDefinition[];
|
|
6
|
+
/** @type {ValueProcessorDefinition[]} */
|
|
7
|
+
export const BUILTIN_PROCESSORS: ValueProcessorDefinition[];
|
|
8
|
+
import type { ValueProcessorDefinition } from '../../value-processor/value-processor.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $input
|
|
3
|
+
*
|
|
4
|
+
* Returns the input value passed to the processor. Acts as a declarative "pass-through".
|
|
5
|
+
* Useful for passing the input to processor arguments that don't normally use the input as a default,
|
|
6
|
+
* or as a placeholder in array arguments.
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
* ```js
|
|
10
|
+
* //
|
|
11
|
+
* new Schema('string')
|
|
12
|
+
* .transformer([['{', '$input', '}']])
|
|
13
|
+
* .transformer({'$join': ''})
|
|
14
|
+
*
|
|
15
|
+
* "hello" -> "{hello}"
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
19
|
+
*/
|
|
20
|
+
export const INPUT_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $instanceof
|
|
3
|
+
*
|
|
4
|
+
* Validates that the input is an instance of the specified constructor.
|
|
5
|
+
*
|
|
6
|
+
* ### Parameters
|
|
7
|
+
* - `clazz` (Function, required): The constructor function to test against.
|
|
8
|
+
*
|
|
9
|
+
* ### Example
|
|
10
|
+
* ```js
|
|
11
|
+
* // Validate that a value is an instance of a custom class
|
|
12
|
+
* new Schema('any').validator({$instanceof: MyClass})
|
|
13
|
+
*
|
|
14
|
+
* // Validate that a value is a Map
|
|
15
|
+
* new Schema('any').validator({$instanceof: Map})
|
|
16
|
+
*
|
|
17
|
+
* // Validate that a value is an Error
|
|
18
|
+
* new Schema('any').validator({$instanceof: Error})
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
22
|
+
*/
|
|
23
|
+
export const INSTANCEOF_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $integer
|
|
3
|
+
*
|
|
4
|
+
* Validates that a numeric value is an integer (no fractional part).
|
|
5
|
+
* Input must already be a number; use `$number` in a prior normalizer if coercion from string is needed.
|
|
6
|
+
*
|
|
7
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
8
|
+
*/
|
|
9
|
+
export const INTEGER_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $invoke
|
|
3
|
+
*
|
|
4
|
+
* Calls a provided processor and passes it arguments (if any).
|
|
5
|
+
*
|
|
6
|
+
* ### Parameters
|
|
7
|
+
* - `processor` (any valid processor spec, required): The processor to invoke.
|
|
8
|
+
* - `arguments` (optional; any extra values to pass to the processor in `options.args`)
|
|
9
|
+
*
|
|
10
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
11
|
+
*/
|
|
12
|
+
export const INVOKE_OPERATOR: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $ipv4
|
|
3
|
+
*
|
|
4
|
+
* Validates that a string is a valid IPv4 address in dotted-decimal notation.
|
|
5
|
+
*
|
|
6
|
+
* ### Parameters
|
|
7
|
+
* - `in` (string, optional): Network range to validate against. Accepts CIDR
|
|
8
|
+
* notation (e.g. `'192.168.1.0/24'`) or a named range: `rfc1918`, `loopback`,
|
|
9
|
+
* `link-local`, `rfc6598`, `multicast`, `non-routable`.
|
|
10
|
+
* - `min` (string, optional): Minimum IPv4 address (inclusive).
|
|
11
|
+
* - `max` (string, optional): Maximum IPv4 address (inclusive).
|
|
12
|
+
* - `format` (string, optional): Output format — `'integer'` emits the address
|
|
13
|
+
* as a uint32. Default passes through the original dotted-decimal string.
|
|
14
|
+
*
|
|
15
|
+
* Use either `in` OR `min`/`max`, not both.
|
|
16
|
+
*
|
|
17
|
+
* ### Example
|
|
18
|
+
* ```js
|
|
19
|
+
* // Format-only validation
|
|
20
|
+
* new Schema('string').validator('$ipv4')
|
|
21
|
+
*
|
|
22
|
+
* // CIDR range (positional `in`)
|
|
23
|
+
* new Schema('string').validator({$ipv4: '192.168.1.0/24'})
|
|
24
|
+
*
|
|
25
|
+
* // Named range
|
|
26
|
+
* new Schema('string').validator({$ipv4: 'rfc1918'})
|
|
27
|
+
*
|
|
28
|
+
* // Explicit min/max
|
|
29
|
+
* new Schema('string').validator({$ipv4: {min: '192.168.1.1', max: '192.168.1.254'}})
|
|
30
|
+
*
|
|
31
|
+
* // Output as uint32
|
|
32
|
+
* new Schema('string').validator({$ipv4: {in: 'rfc1918', format: 'integer'}})
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
36
|
+
*/
|
|
37
|
+
export const IPV4_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $ipv6
|
|
3
|
+
*
|
|
4
|
+
* Validates that a string is a properly formatted IPv6 address. Supports all standard
|
|
5
|
+
* notation formats including full, compressed (::), link-local with zone identifiers,
|
|
6
|
+
* and IPv4-mapped addresses.
|
|
7
|
+
*
|
|
8
|
+
* ### Parameters
|
|
9
|
+
* - `in` (string, optional): Network range to validate against. Accepts CIDR
|
|
10
|
+
* notation (e.g. `'fe80::/10'`) or a named range: `loopback`, `link-local`,
|
|
11
|
+
* `unique-local`, `multicast`, `non-routable`.
|
|
12
|
+
* - `min` (string, optional): Minimum IPv6 address (inclusive).
|
|
13
|
+
* - `max` (string, optional): Maximum IPv6 address (inclusive).
|
|
14
|
+
*
|
|
15
|
+
* Use either `in` OR `min`/`max`, not both.
|
|
16
|
+
*
|
|
17
|
+
* ### Example
|
|
18
|
+
* ```js
|
|
19
|
+
* // Format-only validation
|
|
20
|
+
* new Schema('string').validator('$ipv6')
|
|
21
|
+
*
|
|
22
|
+
* // CIDR range (positional `in`)
|
|
23
|
+
* new Schema('string').validator({$ipv6: '2001:db8::/32'})
|
|
24
|
+
*
|
|
25
|
+
* // Named range
|
|
26
|
+
* new Schema('string').validator({$ipv6: 'unique-local'})
|
|
27
|
+
*
|
|
28
|
+
* // Explicit min/max
|
|
29
|
+
* new Schema('string').validator({$ipv6: {min: '2001:db8::1', max: '2001:db8::ffff'}})
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
33
|
+
*/
|
|
34
|
+
export const IPV6_CONSTRAINT: import("../../value-processor/value-processor.js").ValueProcessorDefinition;
|