@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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $target
|
|
3
|
+
*
|
|
4
|
+
* Returns the target value passed to the processor (value being built relative to the root).
|
|
5
|
+
* (Note: may return undefined or partial results, depending on the schema!)
|
|
6
|
+
*
|
|
7
|
+
* ### Example
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* // Uses $target to provide an object for $get to access
|
|
11
|
+
* new Schema('object')
|
|
12
|
+
* .property('level-one', new Schema('object')
|
|
13
|
+
* .property('enable-level-3', new Schema('boolean').default(false))
|
|
14
|
+
* .property('level-two', new Schema('object')
|
|
15
|
+
* .property('level-three', new Schema('object')
|
|
16
|
+
* .condition(['$target', {get: 'level-one.enable-level-3'}])
|
|
17
|
+
* .property('child', new Schema('string'))
|
|
18
|
+
* )
|
|
19
|
+
* )
|
|
20
|
+
* )
|
|
21
|
+
* // { "level-one": { "level-two": { "level-three": { "child": "ignored" } } } }
|
|
22
|
+
* // { "level-one": { "enable-level-3": true, "level-two": { "level-three": { "child": "is set" } } } }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
26
|
+
*/
|
|
27
|
+
export const TARGET_OPERATOR = {
|
|
28
|
+
keyword: 'target',
|
|
29
|
+
process: (_input, target) => target
|
|
30
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
|
|
2
|
+
import { FunctionValueProcessor } from '../../value-processor/function-value-processor.js';
|
|
3
|
+
import { ComposedValueProcessor } from '../../value-processor/composed-value-processor.js';
|
|
4
|
+
import { ConstraintError, SchemaError } from '../../errors.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ## $template
|
|
8
|
+
*
|
|
9
|
+
* Operator that interpolates a template string using properties from the input object.
|
|
10
|
+
* Placeholders use `{key}` syntax; double braces `{{` and `}}` are literal brace escapes.
|
|
11
|
+
*
|
|
12
|
+
* The input must be a plain object. Unknown keys resolve to an empty string.
|
|
13
|
+
*
|
|
14
|
+
* ### Parameters
|
|
15
|
+
* - `template` (string, required): The template string to interpolate.
|
|
16
|
+
*
|
|
17
|
+
* ### Example
|
|
18
|
+
* ```js
|
|
19
|
+
* // Build a connection string from object properties
|
|
20
|
+
* new Schema('object', {
|
|
21
|
+
* host: new Schema('string'),
|
|
22
|
+
* port: new Schema('number'),
|
|
23
|
+
* database: new Schema('string'),
|
|
24
|
+
* }).transformer({$template: 'postgresql://{host}:{port}/{database}'})
|
|
25
|
+
*
|
|
26
|
+
* // Format a greeting from a user object
|
|
27
|
+
* new Schema('object').transformer({$template: 'Hello, {firstName} {lastName}!'})
|
|
28
|
+
*
|
|
29
|
+
* // Use double-braces to produce literal curly braces
|
|
30
|
+
* new Schema('object').transformer({$template: 'Value: {{literal}}'})
|
|
31
|
+
* // {} → 'Value: {literal}'
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
35
|
+
*/
|
|
36
|
+
export const TEMPLATE_OPERATOR = {
|
|
37
|
+
keyword: 'template',
|
|
38
|
+
build: (args) => {
|
|
39
|
+
const template = (Array.isArray(args) ? args[0] : args)?.spec;
|
|
40
|
+
if (typeof template !== 'string') {
|
|
41
|
+
throw new SchemaError('$template requires a string argument');
|
|
42
|
+
}
|
|
43
|
+
const fn = new FunctionValueProcessor((value, _target, location) => {
|
|
44
|
+
if (typeof value !== 'object' || value === null) {
|
|
45
|
+
throw new ConstraintError('$template requires an object input', {location});
|
|
46
|
+
}
|
|
47
|
+
return template
|
|
48
|
+
.replace(/\{\{/g, '\x00')
|
|
49
|
+
.replace(/\}\}/g, '\x01')
|
|
50
|
+
.replace(/\{([^}]+)\}/g, (_, key) => {
|
|
51
|
+
const v = value[key];
|
|
52
|
+
return v === undefined ? '' : String(v);
|
|
53
|
+
})
|
|
54
|
+
.replace(/\x00/g, '{')
|
|
55
|
+
.replace(/\x01/g, '}');
|
|
56
|
+
});
|
|
57
|
+
fn.description = template;
|
|
58
|
+
return new ComposedValueProcessor(fn, {$template: template});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { toTitleCase } from '../../helpers/case.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ## $title-case
|
|
5
|
+
*
|
|
6
|
+
* Converts a string to title case, capitalizing the first letter of each significant word
|
|
7
|
+
* and leaving articles, coordinating conjunctions, and short prepositions lowercase when
|
|
8
|
+
* they appear in the middle of the phrase. The first and last words are always capitalized.
|
|
9
|
+
*
|
|
10
|
+
* Lowercase words: a, an, the, and, but, or, nor, for, so, yet, at, by, in, of, on, to, up, as, via
|
|
11
|
+
*
|
|
12
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
13
|
+
*/
|
|
14
|
+
export const TITLE_CASE_OPERATOR = {
|
|
15
|
+
keyword: 'title-case',
|
|
16
|
+
process: (value) => toTitleCase(String(value))
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $trim
|
|
3
|
+
*
|
|
4
|
+
* Removes leading and trailing whitespace from a string value.
|
|
5
|
+
* Safe to use in normalize phase (non-throwing operator).
|
|
6
|
+
*
|
|
7
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
8
|
+
*/
|
|
9
|
+
export const TRIM_OPERATOR = {
|
|
10
|
+
keyword: 'trim',
|
|
11
|
+
process: (value) => {
|
|
12
|
+
return String(value).trim();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isTruthy } from '../../helpers/truthy.js';
|
|
2
|
+
import { ConstraintError } from '../../errors.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ## $truthy
|
|
6
|
+
*
|
|
7
|
+
* Validates that the value is "truthy". Note that the definition of what values are "truthy"
|
|
8
|
+
* mirrors the boolean schema normalization of special strings like "true" and "no".
|
|
9
|
+
*
|
|
10
|
+
* ### Example
|
|
11
|
+
* ```js
|
|
12
|
+
* // Require a feature flag to be truthy before processing a value
|
|
13
|
+
* new Schema('object', {
|
|
14
|
+
* enabled: new Schema('boolean'),
|
|
15
|
+
* config: new Schema('string').validator({$assert: {$property: 'enabled'}}),
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Use $truthy inside a conditional to branch on truthiness
|
|
19
|
+
* new Schema('any').transformer({
|
|
20
|
+
* $if: ['$truthy', '$uppercase']
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
25
|
+
*/
|
|
26
|
+
export const TRUTHY_CONSTRAINT = {
|
|
27
|
+
keyword: 'truthy',
|
|
28
|
+
process: (value) => {
|
|
29
|
+
if (isTruthy(value)) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
throw new ConstraintError('Must be truthy');
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CompiledSchema } from '../../compiled-schema.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ## $type
|
|
5
|
+
*
|
|
6
|
+
* Returns the type name of the input value as a string. Unlike the `$is-*` constraint family,
|
|
7
|
+
* this operator produces the type name as a value usable in pipelines and templates.
|
|
8
|
+
*
|
|
9
|
+
* **Return values**: `'string'`, `'number'`, `'boolean'`, `'array'`, `'object'`, `'date'`, `'schema'`, `'null'`, `'undefined'`
|
|
10
|
+
*
|
|
11
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
12
|
+
*/
|
|
13
|
+
export const TYPE_OPERATOR = {
|
|
14
|
+
keyword: 'type',
|
|
15
|
+
|
|
16
|
+
process: (value) => {
|
|
17
|
+
if (value === null) return 'null';
|
|
18
|
+
if (value === undefined) return 'undefined';
|
|
19
|
+
if (value instanceof Date) return 'date';
|
|
20
|
+
if (Array.isArray(value)) return 'array';
|
|
21
|
+
if (value instanceof CompiledSchema) return 'schema';
|
|
22
|
+
return typeof value;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
import { formatValue } from '../../helpers/format.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ## $unique
|
|
6
|
+
*
|
|
7
|
+
* Returns a new array with duplicate values removed, preserving insertion order
|
|
8
|
+
* of first occurrences. Uses identity-based (`Set`) deduplication.
|
|
9
|
+
* Throws if the input is not an array.
|
|
10
|
+
*
|
|
11
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
12
|
+
*/
|
|
13
|
+
export const UNIQUE_OPERATOR = {
|
|
14
|
+
keyword: 'unique',
|
|
15
|
+
process: (value, _target, location) => {
|
|
16
|
+
if (!Array.isArray(value)) {
|
|
17
|
+
throw new ConstraintError(`$unique requires an array, got ${formatValue(value)}`, {location});
|
|
18
|
+
}
|
|
19
|
+
return [...new Set(value)];
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $uppercase
|
|
3
|
+
*
|
|
4
|
+
* Converts a string value to uppercase. Safe to use in normalize phase (non-throwing).
|
|
5
|
+
* Non-string values are coerced to strings before conversion.
|
|
6
|
+
*
|
|
7
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
8
|
+
*/
|
|
9
|
+
export const UPPERCASE_OPERATOR = {
|
|
10
|
+
keyword: 'uppercase',
|
|
11
|
+
process: (value) => {
|
|
12
|
+
return String(value).toUpperCase();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ## $url
|
|
5
|
+
*
|
|
6
|
+
* Validates that a string is a valid URL and normalizes it to canonical form.
|
|
7
|
+
* Uses the WHATWG URL Standard for validation and normalization. The normalized
|
|
8
|
+
* URL includes explicit protocol, properly encoded characters, and standardized formatting.
|
|
9
|
+
*
|
|
10
|
+
* - `https://example.com` → `https://example.com/`
|
|
11
|
+
* - `http://localhost:8080/api` → `http://localhost:8080/api`
|
|
12
|
+
* - `https://example.com/path?query=value` → `https://example.com/path?query=value`
|
|
13
|
+
* - `ftp://files.example.com/` → `ftp://files.example.com/`
|
|
14
|
+
*
|
|
15
|
+
* - `not-a-url` (missing protocol)
|
|
16
|
+
* - `//example.com` (missing protocol)
|
|
17
|
+
* - `example.com` (missing protocol)
|
|
18
|
+
* - `http://` (missing host)
|
|
19
|
+
*
|
|
20
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
21
|
+
*/
|
|
22
|
+
export const URL_CONSTRAINT = {
|
|
23
|
+
keyword: 'url',
|
|
24
|
+
process: (value) => {
|
|
25
|
+
try {
|
|
26
|
+
return new URL(value).toString();
|
|
27
|
+
} catch {
|
|
28
|
+
throw new ConstraintError('Invalid URL format');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
import { formatValue } from '../../helpers/format.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ## $url-decode
|
|
6
|
+
*
|
|
7
|
+
* Decodes a percent-encoded URL string.
|
|
8
|
+
*
|
|
9
|
+
* Use `{$url-decode: {full: true}}` to decode a complete URL (`decodeURI`)
|
|
10
|
+
* rather than a component (`decodeURIComponent`). Full-URL decoding preserves
|
|
11
|
+
* sequences that are valid structural URL characters (`%2F` etc.) undecoded.
|
|
12
|
+
*
|
|
13
|
+
* Throws if the input is not a string or contains a malformed escape sequence.
|
|
14
|
+
*
|
|
15
|
+
* ### Parameters
|
|
16
|
+
* - `full` (boolean, optional, default `false`): Use full-URL decoding (`decodeURI`) rather than component decoding (`decodeURIComponent`).
|
|
17
|
+
*
|
|
18
|
+
* ### Example
|
|
19
|
+
* ```js
|
|
20
|
+
* // Decode a percent-encoded query parameter
|
|
21
|
+
* new Schema('string').normalizer('$url-decode')
|
|
22
|
+
* // 'hello%20world%20%26%20more' → 'hello world & more'
|
|
23
|
+
*
|
|
24
|
+
* // Decode a full URL without decoding structural characters
|
|
25
|
+
* new Schema('string').normalizer({'$url-decode': {full: true}})
|
|
26
|
+
* // 'https://example.com/path%20with%20spaces' → 'https://example.com/path with spaces'
|
|
27
|
+
*
|
|
28
|
+
* // Decode then validate the result
|
|
29
|
+
* new Schema('string').normalizer('$url-decode').validator('$non-empty')
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
33
|
+
*/
|
|
34
|
+
export const URL_DECODE_OPERATOR = {
|
|
35
|
+
keyword: 'url-decode',
|
|
36
|
+
parameters: [ { parameter: 'full', default: false } ],
|
|
37
|
+
|
|
38
|
+
process: (value, _target, location, options) => {
|
|
39
|
+
if (typeof value !== 'string') {
|
|
40
|
+
throw new ConstraintError(`$url-decode requires a string, got ${formatValue(value)}`, {location});
|
|
41
|
+
}
|
|
42
|
+
const full = options.args?.['full'] ?? false;
|
|
43
|
+
try {
|
|
44
|
+
return full ? decodeURI(value) : decodeURIComponent(value);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new ConstraintError(`$url-decode: malformed URI sequence — ${error.message}`, {location, cause: error});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## $url-encode
|
|
3
|
+
*
|
|
4
|
+
* Percent-encodes a string for safe use as a URL component (query param value,
|
|
5
|
+
* path segment, etc.). Encodes all characters except unreserved URI characters
|
|
6
|
+
* (`A–Z a–z 0–9 - _ . ! ~ * ' ( )`).
|
|
7
|
+
*
|
|
8
|
+
* Use `{$url-encode: {full: true}}` to encode a complete URL instead of a
|
|
9
|
+
* component — this preserves `://`, `/`, `?`, `&`, `=`, and other structural
|
|
10
|
+
* characters rather than encoding them.
|
|
11
|
+
*
|
|
12
|
+
* Non-string inputs are coerced to string before encoding.
|
|
13
|
+
*
|
|
14
|
+
* ### Parameters
|
|
15
|
+
* - `full` (boolean, optional, default `false`): Use full-URL encoding (`encodeURI`) rather than component encoding (`encodeURIComponent`).
|
|
16
|
+
*
|
|
17
|
+
* ### Example
|
|
18
|
+
* ```js
|
|
19
|
+
* // Encode a query parameter value
|
|
20
|
+
* new Schema('string').transformer('$url-encode')
|
|
21
|
+
* // 'hello world & more' → 'hello%20world%20%26%20more'
|
|
22
|
+
*
|
|
23
|
+
* // Encode a full URL, preserving structural characters
|
|
24
|
+
* new Schema('string').transformer({'$url-encode': {full: true}})
|
|
25
|
+
* // 'https://example.com/path with spaces' → 'https://example.com/path%20with%20spaces'
|
|
26
|
+
*
|
|
27
|
+
* // Build an encoded query string from an object
|
|
28
|
+
* new Schema('object', {
|
|
29
|
+
* q: new Schema('string').transformer('$url-encode'),
|
|
30
|
+
* page: new Schema('number'),
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
35
|
+
*/
|
|
36
|
+
export const URL_ENCODE_OPERATOR = {
|
|
37
|
+
keyword: 'url-encode',
|
|
38
|
+
parameters: [ { parameter: 'full', default: false } ],
|
|
39
|
+
|
|
40
|
+
process: (value, _target, _location, options) => {
|
|
41
|
+
const full = options.args?.['full'] ?? false;
|
|
42
|
+
return full ? encodeURI(`${value}`) : encodeURIComponent(`${value}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ## $uuid
|
|
5
|
+
*
|
|
6
|
+
* Validates that a string matches valid UUID format (versions 1-5).
|
|
7
|
+
* UUIDs must follow RFC 4122 format: 8-4-4-4-12 hexadecimal digits
|
|
8
|
+
* separated by hyphens.
|
|
9
|
+
*
|
|
10
|
+
* - `550e8400-e29b-41d4-a716-446655440000` (v4)
|
|
11
|
+
* - `6ba7b810-9dad-11d1-80b4-00c04fd430c8` (v1)
|
|
12
|
+
* - `3d813cbb-47fb-32ba-91df-831e1593ac29` (v3)
|
|
13
|
+
* - `A6EAFB30-E49B-51D4-9B1D-8F6C0F89E8B3` (case-insensitive)
|
|
14
|
+
*
|
|
15
|
+
* - `550e8400-e29b-41d4-a716` (too short)
|
|
16
|
+
* - `550e8400e29b41d4a716446655440000` (missing hyphens)
|
|
17
|
+
* - `550e8400-e29b-61d4-a716-446655440000` (invalid version digit)
|
|
18
|
+
* - `not-a-valid-uuid-string`
|
|
19
|
+
*
|
|
20
|
+
* @type {import("../../value-processor/value-processor.js").ValueProcessorDefinition}
|
|
21
|
+
*/
|
|
22
|
+
export const UUID_CONSTRAINT = {
|
|
23
|
+
keyword: 'uuid',
|
|
24
|
+
process: (value) => {
|
|
25
|
+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
26
|
+
if (!uuidRegex.test(value)) {
|
|
27
|
+
throw new ConstraintError('Invalid UUID format');
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
import { formatValue } from '../../helpers/format.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ## $values
|
|
6
|
+
*
|
|
7
|
+
* Returns the enumerable own property values of an object as an array.
|
|
8
|
+
* Throws if the input is not a plain object.
|
|
9
|
+
*
|
|
10
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
11
|
+
*/
|
|
12
|
+
export const VALUES_OPERATOR = {
|
|
13
|
+
keyword: 'values',
|
|
14
|
+
process: (value, _target, location) => {
|
|
15
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
16
|
+
throw new ConstraintError(`$values requires a plain object, got ${formatValue(value)}`, {location});
|
|
17
|
+
}
|
|
18
|
+
return Object.values(value);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SchemaLocation } from "../../schema-location.js";
|
|
2
|
+
import { Schema } from '../../schema.js';
|
|
3
|
+
import { hasStringProperties } from '../../helpers/has-string-properties.js';
|
|
4
|
+
import { EMPTY } from '../../constants.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {any} value
|
|
8
|
+
* @param {any} _
|
|
9
|
+
* @param {SchemaLocation} location
|
|
10
|
+
* @returns {any}
|
|
11
|
+
*/
|
|
12
|
+
function anyValueProcessor(value, _, location) {
|
|
13
|
+
const schema = location.schema;
|
|
14
|
+
if (value === EMPTY && schema.isContainer) {
|
|
15
|
+
return (!schema.isArray && hasStringProperties(schema))? {} : [];
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ANY_SCHEMA = new Schema()
|
|
21
|
+
.option('type', 'any')
|
|
22
|
+
.normalizer(anyValueProcessor)
|
|
23
|
+
.transformer(anyValueProcessor)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schema } from '../../schema.js';
|
|
2
|
+
import { isTruthy } from '../../helpers/truthy.js';
|
|
3
|
+
|
|
4
|
+
export const BOOLEAN_SCHEMA = new Schema()
|
|
5
|
+
.option('type', 'boolean')
|
|
6
|
+
.meta('valueName', 'boolean')
|
|
7
|
+
.normalizer(isTruthy)
|
|
8
|
+
.validator({$in: [true, false]})
|
|
9
|
+
|
|
10
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Schema } from '../../schema.js';
|
|
2
|
+
|
|
3
|
+
export const DATE_SCHEMA = new Schema()
|
|
4
|
+
.option('type', 'date')
|
|
5
|
+
.meta('parserTypeHint', 'string')
|
|
6
|
+
.meta('valueName', 'date')
|
|
7
|
+
.meta('valueDescription', 'ms|iso date|"now"|[+|-]offset[d|h|m|s|ms]')
|
|
8
|
+
.normalizer('$date')
|
|
9
|
+
.transformer('$date')
|
|
10
|
+
.validator('$is-date')
|
|
11
|
+
.serializer('$is-date')
|
|
12
|
+
.serializer('$string')
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Schema } from '../../schema.js';
|
|
2
|
+
import { deepValue } from '../../helpers/deep.js';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { ConstraintError } from '../../errors.js';
|
|
6
|
+
|
|
7
|
+
export const FUNCTION_SCHEMA = new Schema()
|
|
8
|
+
.option('type', 'function')
|
|
9
|
+
.meta('parserTypeHint', 'string')
|
|
10
|
+
.meta('hidden')
|
|
11
|
+
.meta('internal')
|
|
12
|
+
.meta('omitFromSerialize')
|
|
13
|
+
.option('dynamic', false)
|
|
14
|
+
.normalizer((value) => {
|
|
15
|
+
if (typeof value === 'function' || typeof value === 'string') {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
throw new ConstraintError('Invalid function', {value})
|
|
19
|
+
})
|
|
20
|
+
.transformer((value, result) => {
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
value = deepValue(result, value); // look up the string as a reference in the current target
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === 'function') {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
throw new ConstraintError('Invalid function', {value});
|
|
28
|
+
})
|
|
29
|
+
.validator(value => {
|
|
30
|
+
if (typeof value === 'function') {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
throw new ConstraintError('Invalid function', {value});
|
|
34
|
+
})
|
|
35
|
+
.serializer((value) => {
|
|
36
|
+
if (typeof value === 'function') {
|
|
37
|
+
return value.name;
|
|
38
|
+
}
|
|
39
|
+
throw new ConstraintError('Invalid function', {value})
|
|
40
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Schema } from '../../schema.js';
|
|
2
|
+
|
|
3
|
+
export const ROOT_SCHEMA = new Schema()
|
|
4
|
+
.default(true)
|
|
5
|
+
.meta('hidden')
|
|
6
|
+
.meta('internal')
|
|
7
|
+
.meta('omitFromSerialize')
|
|
8
|
+
.normalizer(() => 'root-schema')
|
|
9
|
+
.transformer((_v, _c, location) => {
|
|
10
|
+
while (location?.parent) {
|
|
11
|
+
location = location.parent;
|
|
12
|
+
}
|
|
13
|
+
return location?.schema;
|
|
14
|
+
})
|
|
15
|
+
.serializer((_v, _c, location) => {
|
|
16
|
+
while (location?.parent) {
|
|
17
|
+
location = location.parent;
|
|
18
|
+
}
|
|
19
|
+
return location?.schema.toData();
|
|
20
|
+
})
|
|
21
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BUFFER_SCHEMA } from './schemas/buffer-schema.js';
|
|
2
|
+
|
|
3
|
+
/** @import { ValueProcessorDefinition } from '../value-processor/value-processor.js' */
|
|
4
|
+
/** @import { SchemaResolver } from '../schema-resolver.js' */
|
|
5
|
+
|
|
6
|
+
let modules;
|
|
7
|
+
try {
|
|
8
|
+
modules ??= await Promise.all([
|
|
9
|
+
import('./processors/base64-decode-operator.js'),
|
|
10
|
+
import('./processors/base64-encode-operator.js'),
|
|
11
|
+
import('./processors/buffer-operator.js'),
|
|
12
|
+
import('./processors/directory-constraint.js'),
|
|
13
|
+
import('./processors/executable-constraint.js'),
|
|
14
|
+
import('./processors/file-constraint.js'),
|
|
15
|
+
import('./processors/file-size-constraint.js'),
|
|
16
|
+
import('./processors/is-buffer-constraint.js'),
|
|
17
|
+
import('./processors/readable-constraint.js'),
|
|
18
|
+
import('./processors/reachable-constraint.js'),
|
|
19
|
+
import('./processors/writable-constraint.js'),
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw new Error('Failed to load Node.js processors', { cause: error });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @type {ValueProcessorDefinition[]} */
|
|
27
|
+
const NODE_PROCESSORS = modules.flatMap(
|
|
28
|
+
ns => Object.values(ns).filter(v => v && typeof v.keyword === 'string')
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Node.js-specific schemas and processors.
|
|
33
|
+
*
|
|
34
|
+
* Loaded automatically when running under Node.js. Registers the `buffer`
|
|
35
|
+
* schema type and processors that depend on `node:fs`, `node:dns`, or the
|
|
36
|
+
* Node.js `Buffer` global.
|
|
37
|
+
*
|
|
38
|
+
* @param {SchemaResolver} resolver
|
|
39
|
+
* @param {object} options
|
|
40
|
+
*/
|
|
41
|
+
export default function coreLibraryNode(resolver, options) {
|
|
42
|
+
resolver.registerSchema('buffer', BUFFER_SCHEMA);
|
|
43
|
+
|
|
44
|
+
for (const definition of NODE_PROCESSORS) {
|
|
45
|
+
resolver.registerValueProcessorDefinition(definition);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
import { formatValue } from '../../helpers/format.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ## $base64-decode
|
|
6
|
+
*
|
|
7
|
+
* Decodes a Base64-encoded string to a Buffer.
|
|
8
|
+
* Throws if the input is not a string.
|
|
9
|
+
*
|
|
10
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
11
|
+
*/
|
|
12
|
+
export const BASE64_DECODE_OPERATOR = {
|
|
13
|
+
keyword: 'base64-decode',
|
|
14
|
+
process: (value, _target, location) => {
|
|
15
|
+
if (typeof value !== 'string') {
|
|
16
|
+
throw new ConstraintError(`$base64-decode requires a string, got ${formatValue(value)}`, {location});
|
|
17
|
+
}
|
|
18
|
+
return Buffer.from(value, 'base64');
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConstraintError } from '../../errors.js';
|
|
2
|
+
import { formatValue } from '../../helpers/format.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ## $base64-encode
|
|
6
|
+
*
|
|
7
|
+
* Encodes a Buffer to a Base64 string.
|
|
8
|
+
* Throws if the input is not a Buffer.
|
|
9
|
+
*
|
|
10
|
+
* @type {import('../../value-processor/value-processor.js').ValueProcessorDefinition}
|
|
11
|
+
*/
|
|
12
|
+
export const BASE64_ENCODE_OPERATOR = {
|
|
13
|
+
keyword: 'base64-encode',
|
|
14
|
+
process: (value, _target, location) => {
|
|
15
|
+
if (!Buffer.isBuffer(value)) {
|
|
16
|
+
throw new ConstraintError(`$base64-encode requires a Buffer, got ${formatValue(value)}`, {location});
|
|
17
|
+
}
|
|
18
|
+
return value.toString('base64');
|
|
19
|
+
}
|
|
20
|
+
};
|