@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
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Schema
|
|
2
|
+
|
|
3
|
+
A composition-oriented schema system for processing, extracting, and validating data.
|
|
4
|
+
|
|
5
|
+
- Focused on enabling decoupled contracts between systems.
|
|
6
|
+
- All behavior is composed rather than hard-coded, even fundamental types.
|
|
7
|
+
- Supports unions, conditionals, cross-references, recursion, async value processing,
|
|
8
|
+
dynamic resolution, and more.
|
|
9
|
+
|
|
10
|
+
For full documentation, see <https://docs.v0.net/schema>.
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
- Node.js 19+ or any modern browser
|
|
15
|
+
- ESM only
|
|
16
|
+
|
|
17
|
+
## Basic Usage
|
|
18
|
+
|
|
19
|
+
Core schema and value processor availability vary by platform.
|
|
20
|
+
|
|
21
|
+
### Node
|
|
22
|
+
```bash
|
|
23
|
+
npm install --save @versionzero/schema
|
|
24
|
+
```
|
|
25
|
+
Includes support for `Buffer` and processors for file system access.
|
|
26
|
+
### Browsers
|
|
27
|
+
```html
|
|
28
|
+
<script type="module">
|
|
29
|
+
import { Schema, SchemaResolver } from '@versionzero/schema';
|
|
30
|
+
// ...
|
|
31
|
+
</script>
|
|
32
|
+
```
|
|
33
|
+
Works in browsers as raw ESM — no build step required.
|
|
34
|
+
|
|
35
|
+
### Examples
|
|
36
|
+
(Source can be found in the [examples directory](https://github.com/argh/schema/tree/main/examples))
|
|
37
|
+
|
|
38
|
+
#### Simple String Schema
|
|
39
|
+
Here's a trivial schema that just enforces a capitalized greeting:
|
|
40
|
+
```javascript title="basics.js"
|
|
41
|
+
import { Schema, SchemaResolver } from '@versionzero/schema';
|
|
42
|
+
|
|
43
|
+
const resolver = new SchemaResolver();
|
|
44
|
+
|
|
45
|
+
const helloSchema = resolver.compile(
|
|
46
|
+
new Schema('string')
|
|
47
|
+
.normalizer('$title-case')
|
|
48
|
+
.validator({$matches: /^Hello.+/})
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// Value processing runs all handlers, so this will be normalized:
|
|
52
|
+
const greeting = await helloSchema.process('hello world');
|
|
53
|
+
console.log(greeting); // Hello World
|
|
54
|
+
|
|
55
|
+
// Validation requires the input to already be correct. This is valid...
|
|
56
|
+
await helloSchema.validate('Hello Friend');
|
|
57
|
+
|
|
58
|
+
// but this will throw a ValidationError (wrong case)
|
|
59
|
+
await helloSchema.validate('hello world');
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### More complex...
|
|
63
|
+
This schema defines the data structure of a meeting. (Note how `ends` depends on `starts`!)
|
|
64
|
+
```javascript title="basics.js"
|
|
65
|
+
import crypto from 'node:crypto';
|
|
66
|
+
import { Schema, SchemaResolver } from '@versionzero/schema';
|
|
67
|
+
|
|
68
|
+
const resolver = new SchemaResolver();
|
|
69
|
+
|
|
70
|
+
// you can define a schema to reference inline in multiple places...
|
|
71
|
+
const meetingTextFieldSchema = new Schema('string')
|
|
72
|
+
.normalizer('$trim')
|
|
73
|
+
.validator({$length: {min: 1, max: 1024}});
|
|
74
|
+
|
|
75
|
+
// or you can register it to the resolver to reference by name
|
|
76
|
+
resolver.registerSchema('meeting-text', meetingTextFieldSchema);
|
|
77
|
+
|
|
78
|
+
const meetingSchema = resolver.compile(
|
|
79
|
+
new Schema('object')
|
|
80
|
+
.property('id', new Schema('string')
|
|
81
|
+
.required()
|
|
82
|
+
.default(() => crypto.randomUUID())
|
|
83
|
+
.normalizer(['$trim', '$lowercase'])
|
|
84
|
+
.validator('$uuid')
|
|
85
|
+
)
|
|
86
|
+
.property('title', new Schema(meetingTextFieldSchema) // extend a schema instance
|
|
87
|
+
.required()
|
|
88
|
+
.default('Untitled Meeting')
|
|
89
|
+
)
|
|
90
|
+
.property('description', new Schema('meeting-text')) // or extend a named schema
|
|
91
|
+
.property('starts', new Schema('date').required())
|
|
92
|
+
.property('ends', new Schema('date')
|
|
93
|
+
.required()
|
|
94
|
+
.validator({'$date-range': {min: {$reference: '^starts'}}})
|
|
95
|
+
)
|
|
96
|
+
.property('attendees', new Schema('array')
|
|
97
|
+
.required()
|
|
98
|
+
.validator({$length: {min: 1}})
|
|
99
|
+
.property('*', new Schema('object')
|
|
100
|
+
.property('email', new Schema('string')
|
|
101
|
+
.required()
|
|
102
|
+
.validator('$email')
|
|
103
|
+
)
|
|
104
|
+
.property('response', new Schema('string')
|
|
105
|
+
.default('pending')
|
|
106
|
+
.validator({$in: ['accepted', 'declined', 'tentative', 'pending']})
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
The meeting schema is usable both for validation (checking if data matches the schema rules):
|
|
113
|
+
```javascript
|
|
114
|
+
const meeting = {
|
|
115
|
+
id: '123e4567-e89b-12d3-a456-426614174000',
|
|
116
|
+
title: 'Weekly Team Meeting',
|
|
117
|
+
description: 'Weekly team meeting to discuss progress and upcoming projects.',
|
|
118
|
+
starts: new Date('2026-09-01T10:00:00'),
|
|
119
|
+
ends: new Date('2026-09-01T11:00:00'),
|
|
120
|
+
attendees: [
|
|
121
|
+
{ email: 'john.doe@example.com', response: 'accepted' },
|
|
122
|
+
{ email: 'jane.smith@example.com', response: 'declined' },
|
|
123
|
+
{ email: 'ted.richards@example.com' },
|
|
124
|
+
{ email: 'alice.johnson@example.com', response: 'tentative' }
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const validatedMeeting = await meetingSchema.validate(meeting); // valid!
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
as well as processing (attempt to convert input data to the valid format):
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
const minimal = {
|
|
135
|
+
starts: '2027-01-01T10:00:00',
|
|
136
|
+
ends: '2027-01-01T11:00:00',
|
|
137
|
+
attendees: [ { email: 'john.doe@example.com' } ]
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// would not validate as-is, but...
|
|
141
|
+
const processedMeeting = await meetingSchema.process(minimal);
|
|
142
|
+
|
|
143
|
+
/* Result is now valid - populated with defaults, date strings converted to Dates:
|
|
144
|
+
{
|
|
145
|
+
id: '1f721f55-c075-485c-994c-96dbb30b035d',
|
|
146
|
+
title: 'Untitled Meeting',
|
|
147
|
+
starts: 2027-01-01T18:00:00.000Z,
|
|
148
|
+
ends: 2027-01-01T19:00:00.000Z,
|
|
149
|
+
attendees: [ { email: 'john.doe@example.com', response: 'pending' } ]
|
|
150
|
+
}
|
|
151
|
+
*/
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
See the full [documentation](https://docs.v0.net/schema) for details.
|
|
155
|
+
|
|
156
|
+
Also see the [examples directory](https://github.com/argh/schema/tree/main/examples) for more advanced usage patterns.
|
|
157
|
+
|
|
158
|
+
## Key Features
|
|
159
|
+
|
|
160
|
+
### Definition via Fluent API (or Data)
|
|
161
|
+
|
|
162
|
+
Define your data structure declaratively using composable `Schema` objects. The fluent API makes
|
|
163
|
+
complex nested and variant structures intuitive to build. Or use a simple object definition, enabling
|
|
164
|
+
schemas to be exported by data consumers without introducing dependencies.
|
|
165
|
+
|
|
166
|
+
### "Batteries Included"
|
|
167
|
+
|
|
168
|
+
Get started quickly with pre-built schemas corresponding to fundamental types, and a rich processor
|
|
169
|
+
library of operators and constraints (`$positive`, `$alphanum`, `$directory`, etc.).
|
|
170
|
+
As your needs grow, create or import libraries of reusable custom schemas and value processors to compose
|
|
171
|
+
complex processing pipelines. You have complete control over all phases of processing; normalization,
|
|
172
|
+
transformation, finalization, validation.
|
|
173
|
+
|
|
174
|
+
(The system is expressive enough that it self-hosts - schemas are defined by a "schema schema"!)
|
|
175
|
+
|
|
176
|
+
### Union Types, Selectors, and Conditionals
|
|
177
|
+
|
|
178
|
+
Easily handle scenarios where your output data structure varies at runtime. Union schemas let you define
|
|
179
|
+
alternative schemas and multiple discrimination strategies. Selectors and Conditionals provide
|
|
180
|
+
different approaches to activating or deactivating schemas within a schema hierarchy.
|
|
181
|
+
|
|
182
|
+
### Dynamic/Late Resolution
|
|
183
|
+
|
|
184
|
+
Compose without coupling, verify without sharing types. Schemas can be built declaratively with only
|
|
185
|
+
named references to other schemas or processors. Or provide dynamic values to ensure the validation process
|
|
186
|
+
calls back to your code. You can even add async processors without special fanfare; the library automatically
|
|
187
|
+
handles deferred results, while optimizing any synchronous call graphs to incur no async overhead.
|
|
188
|
+
Multi-pass processing enables complex mixtures of dynamic resolution and cross-referenced values.
|
|
189
|
+
|
|
190
|
+
### Schema as a Decoupled Contract
|
|
191
|
+
|
|
192
|
+
Use schemas as an impartial bridge between data producers and data consumers. This prevents the
|
|
193
|
+
architectural and maintenance headaches of validation logic being split across tiers, or implementation
|
|
194
|
+
details leaking between subsystems. The data consumer uses the schema to advertise its requirements
|
|
195
|
+
in a way that upstream producers can enforce, enabling a decoupled contract.
|
|
196
|
+
|
|
197
|
+
In modular applications, you can aggregate schemas exported from multiple subsystems to create a composite
|
|
198
|
+
schema that acts as a canonical definition for configuration. This application schema can then be
|
|
199
|
+
introspected, enabling automatic construction of interfaces for loading inputs (CLIs, editors, etc.)
|
|
200
|
+
|
|
201
|
+
### Designed for Extension and Integration
|
|
202
|
+
|
|
203
|
+
The pre-built schema types and value processors that are provided with the library are deliberately
|
|
204
|
+
not "special", and are all built using the public developer APIs. This empowers you to easily
|
|
205
|
+
create your own libraries, where your custom definitions participate as first-class citizens,
|
|
206
|
+
indistinguishable from the "fundamental" behaviors.
|
|
207
|
+
|
|
208
|
+
This library was originally created as the core of the [`Configurator`](https://github.com/argh/configurator) (`@versionzero/configurator`)
|
|
209
|
+
system, which focuses on configuring applications using composed lists of configuration data sources
|
|
210
|
+
(command line, environment, files, etc). The `Configurator` is then embedded inside the
|
|
211
|
+
[`ModuleManager`](https://github.com/argh/module-manager) (`@versionzero/module-manager`) package, which extends application configuration
|
|
212
|
+
with dependency injection and lifecycle management.
|
|
213
|
+
|
|
214
|
+
**This project does not have a cute name, because you don't name your plumbing.**
|
|
215
|
+
|
|
216
|
+
## Rationale
|
|
217
|
+
|
|
218
|
+
Most schema libraries optimize for one of two things: runtime validation (Joi, Ajv)
|
|
219
|
+
or compile-time type integration (Zod, Valibot). Both are useful, and if you're
|
|
220
|
+
building a single application in TypeScript with a shared type definition between
|
|
221
|
+
producer and consumer, Zod is probably what you want.
|
|
222
|
+
|
|
223
|
+
This library optimizes for something different: **expressive runtime contracts between
|
|
224
|
+
subsystems that don't know about each other.**
|
|
225
|
+
|
|
226
|
+
You can think of it like having a toolkit for composing rich runtime-enforced interfaces
|
|
227
|
+
with reflection; embracing the dynamic nature of JavaScript, rather than pretending it has
|
|
228
|
+
static types.
|
|
229
|
+
|
|
230
|
+
_Read more about this [in the full documentation](https://docs.v0.net/schema/rationale)._
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
Copyright 2026 Version Zero | github.com/argh
|
|
235
|
+
|
|
236
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
237
|
+
you may not use this library except in compliance with the License.
|
|
238
|
+
You may obtain a copy of the License at
|
|
239
|
+
|
|
240
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
241
|
+
|
|
242
|
+
Unless required by applicable law or agreed to in writing, software
|
|
243
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
244
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
245
|
+
See the License for the specific language governing permissions and
|
|
246
|
+
limitations under the License.
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@versionzero/schema",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A composable schema library that supports asynchronous processing",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"registry": "https://registry.npmjs.org",
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"author": "Jolly Roger <argh@v0.net> (https://github.com/argh)",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/argh/schema.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"schema",
|
|
17
|
+
"argh",
|
|
18
|
+
"versionzero",
|
|
19
|
+
"v0"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=19",
|
|
24
|
+
"tsc": ">=5.5"
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": [
|
|
27
|
+
"./src/core-library/**",
|
|
28
|
+
"./src/core-library-node/**"
|
|
29
|
+
],
|
|
30
|
+
"main": "./src/index.js",
|
|
31
|
+
"files": [
|
|
32
|
+
"src/**",
|
|
33
|
+
"types/**",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"default": "./src/index.js",
|
|
40
|
+
"types": "./types/index.d.ts"
|
|
41
|
+
},
|
|
42
|
+
"./helpers": {
|
|
43
|
+
"default": "./src/helpers/index.js",
|
|
44
|
+
"types": "./types/helpers/index.d.ts"
|
|
45
|
+
},
|
|
46
|
+
"./errors": {
|
|
47
|
+
"default": "./src/errors.js",
|
|
48
|
+
"types": "./types/errors/index.d.ts"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build:types": "tsc --declaration --emitDeclarationOnly",
|
|
53
|
+
"test": "mocha",
|
|
54
|
+
"test:bail": "mocha -b",
|
|
55
|
+
"test:coverage": "c8 mocha --ignore 'test/99-*.test.js'",
|
|
56
|
+
"docs:api": "typedoc",
|
|
57
|
+
"docs:api:json": "typedoc --json docs-output/api.json",
|
|
58
|
+
"docs:api:contributors": "typedoc --excludeInternal false --excludePrivate false --out docs-output-contributors",
|
|
59
|
+
"docs:api:contributors:json": "typedoc --excludeInternal false --excludePrivate false --json docs-output-contributors/api.json",
|
|
60
|
+
"docs:api:md": "typedoc --options typedoc-md.json",
|
|
61
|
+
"docs:api:md:contributors": "typedoc --options typedoc-md.json --excludeInternal false --excludePrivate false --out docs-output-md-contributors",
|
|
62
|
+
"docs:processors": "node scripts/extract-processor-docs.js",
|
|
63
|
+
"test:browser": "playwright test",
|
|
64
|
+
"test:all": "npm test && npm run test:browser",
|
|
65
|
+
"clean": "rm -rf types docs-output* processors-output* .mdrun .c8 .nyc_output",
|
|
66
|
+
"release:dry": "npx -p semantic-release@24 -p @semantic-release/exec@7 semantic-release --dry-run --no-ci"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@playwright/test": "^1.60.0",
|
|
70
|
+
"@stylistic/eslint-plugin": "^5.6.1",
|
|
71
|
+
"@types/mocha": "^10.0.10",
|
|
72
|
+
"@types/node": "^22.19.10",
|
|
73
|
+
"c8": "^8.0.1",
|
|
74
|
+
"eslint": "^9.39.1",
|
|
75
|
+
"eslint-config-prettier": "^10.1.8",
|
|
76
|
+
"eslint-plugin-jsdoc": "^62.5.4",
|
|
77
|
+
"mocha": "^11.7.4",
|
|
78
|
+
"serve": "^14.2.6",
|
|
79
|
+
"typedoc": "^0.28.16",
|
|
80
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
81
|
+
"typedoc-plugin-missing-exports": "^4.1.2",
|
|
82
|
+
"typescript": "~5.8"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CompiledSchema } from "../compiled-schema.js";
|
|
2
|
+
import { SchemaCompiler } from "../schema-compiler.js";
|
|
3
|
+
import { SchemaLocation } from "../schema-location.js";
|
|
4
|
+
import { isEmpty } from '../helpers/object.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {CompiledSchema} cs
|
|
9
|
+
* @param {any} _
|
|
10
|
+
* @param {SchemaLocation} location
|
|
11
|
+
* @param {object} transformOptions
|
|
12
|
+
* @returns {CompiledSchema}
|
|
13
|
+
* @this {SchemaCompiler}
|
|
14
|
+
*/
|
|
15
|
+
export function compileHandlers(cs, _, location, transformOptions) {
|
|
16
|
+
const compiler = this;
|
|
17
|
+
for (const handler of Object.keys(cs.handlers)) {
|
|
18
|
+
const h = cs.handlers[handler];
|
|
19
|
+
if (!isEmpty(h)) {
|
|
20
|
+
cs._setValueProcessor(handler,
|
|
21
|
+
this.resolver.compileValueProcessorSpec(
|
|
22
|
+
compiler,
|
|
23
|
+
h.length === 1? h[0] : {$pipeline: h},
|
|
24
|
+
true));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return cs;
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CompiledSchema } from "../compiled-schema.js";
|
|
2
|
+
import { formatArgumentType, formatValue } from '../helpers/format.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {CompiledSchema} schema
|
|
6
|
+
* @returns {CompiledSchema}
|
|
7
|
+
*/
|
|
8
|
+
export function populateMetadata(schema) {
|
|
9
|
+
if (!schema.metadata.validatorDescription && schema.handlers.validators?.length) {
|
|
10
|
+
const descriptions = schema.handlers.validators.map(vd => vd.description ?? '').filter(Boolean);
|
|
11
|
+
// this is used below in formatArgumentType...
|
|
12
|
+
schema.metadata.validatorDescription = descriptions.length > 1
|
|
13
|
+
? descriptions.map(d => (d.includes('|') || d.includes('&')) ? `(${d})` : d).join(' >> ')
|
|
14
|
+
: descriptions[0];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!schema.metadata.valueDescription) {
|
|
18
|
+
const valueDescription = formatArgumentType(schema);
|
|
19
|
+
schema.metadata.valueDescription = schema.required ? `<${valueDescription}>` : `[${valueDescription}]`;
|
|
20
|
+
}
|
|
21
|
+
if (!schema.metadata.valueName) {
|
|
22
|
+
schema.metadata.valueName = schema.metadata.parserTypeHint ?? 'value';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (schema.options.default !== undefined && schema.metadata.defaultValueDescription === undefined) {
|
|
26
|
+
if (typeof schema.options.default === 'function') {
|
|
27
|
+
// by default, suppress this.
|
|
28
|
+
schema.metadata.defaultValueDescription = '';
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
schema.metadata.defaultValueDescription = formatValue(schema.options.default);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return schema;
|
|
35
|
+
}
|