@aws-amplify/graphql-model-transformer 1.3.5-agqlac.0 → 1.3.5
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/CHANGELOG.md +6 -7
- package/lib/rds-lambda.zip +0 -0
- package/lib/resources/dynamo-model-resource-generator.d.ts.map +1 -1
- package/lib/resources/dynamo-model-resource-generator.js.map +1 -1
- package/package.json +6 -6
- package/rds-lambda/node_modules/.package-lock.json +1511 -1502
- package/rds-lambda/node_modules/@aws-sdk/client-ssm/README.md +1 -1
- package/rds-lambda/node_modules/@aws-sdk/client-ssm/package.json +32 -31
- package/rds-lambda/node_modules/@aws-sdk/client-sso/package.json +28 -27
- package/rds-lambda/node_modules/@aws-sdk/client-sso-oidc/package.json +28 -27
- package/rds-lambda/node_modules/@aws-sdk/client-sts/package.json +33 -32
- package/rds-lambda/node_modules/@aws-sdk/credential-provider-env/package.json +3 -2
- package/rds-lambda/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -8
- package/rds-lambda/node_modules/@aws-sdk/credential-provider-node/package.json +10 -9
- package/rds-lambda/node_modules/@aws-sdk/credential-provider-process/package.json +4 -3
- package/rds-lambda/node_modules/@aws-sdk/credential-provider-sso/package.json +6 -5
- package/rds-lambda/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -2
- package/rds-lambda/node_modules/@aws-sdk/middleware-host-header/package.json +3 -2
- package/rds-lambda/node_modules/@aws-sdk/middleware-logger/package.json +2 -1
- package/rds-lambda/node_modules/@aws-sdk/middleware-recursion-detection/package.json +3 -2
- package/rds-lambda/node_modules/@aws-sdk/middleware-sdk-sts/package.json +3 -2
- package/rds-lambda/node_modules/@aws-sdk/middleware-signing/package.json +6 -5
- package/rds-lambda/node_modules/@aws-sdk/middleware-user-agent/package.json +3 -2
- package/rds-lambda/node_modules/@aws-sdk/token-providers/package.json +5 -4
- package/rds-lambda/node_modules/@aws-sdk/util-user-agent-browser/package.json +2 -1
- package/rds-lambda/node_modules/@aws-sdk/util-user-agent-node/package.json +3 -2
- package/rds-lambda/node_modules/@babel/compat-data/README.md +1 -1
- package/rds-lambda/node_modules/@babel/compat-data/data/corejs2-built-ins.json +146 -0
- package/rds-lambda/node_modules/@babel/compat-data/data/native-modules.json +1 -1
- package/rds-lambda/node_modules/@babel/compat-data/data/plugin-bugfixes.json +15 -0
- package/rds-lambda/node_modules/@babel/compat-data/data/plugins.json +68 -9
- package/rds-lambda/node_modules/@babel/compat-data/package.json +4 -4
- package/rds-lambda/node_modules/@babel/core/README.md +1 -1
- package/rds-lambda/node_modules/@babel/core/package.json +10 -10
- package/rds-lambda/node_modules/@babel/generator/README.md +1 -1
- package/rds-lambda/node_modules/@babel/generator/package.json +4 -3
- package/rds-lambda/node_modules/@babel/helper-compilation-targets/README.md +1 -1
- package/rds-lambda/node_modules/@babel/helper-compilation-targets/package.json +6 -6
- package/rds-lambda/node_modules/@babel/helper-split-export-declaration/README.md +1 -1
- package/rds-lambda/node_modules/@babel/helper-split-export-declaration/package.json +1 -1
- package/rds-lambda/node_modules/@babel/helpers/README.md +1 -1
- package/rds-lambda/node_modules/@babel/helpers/package.json +3 -3
- package/rds-lambda/node_modules/@babel/parser/README.md +1 -1
- package/rds-lambda/node_modules/@babel/parser/package.json +2 -2
- package/rds-lambda/node_modules/@babel/traverse/README.md +1 -1
- package/rds-lambda/node_modules/@babel/traverse/package.json +4 -4
- package/rds-lambda/node_modules/@jest/console/package.json +6 -6
- package/rds-lambda/node_modules/@jest/core/package.json +21 -21
- package/rds-lambda/node_modules/@jest/environment/package.json +5 -5
- package/rds-lambda/node_modules/@jest/expect/package.json +6 -6
- package/rds-lambda/node_modules/@jest/expect-utils/package.json +5 -5
- package/rds-lambda/node_modules/@jest/fake-timers/package.json +7 -7
- package/rds-lambda/node_modules/@jest/globals/package.json +6 -6
- package/rds-lambda/node_modules/@jest/reporters/package.json +14 -14
- package/rds-lambda/node_modules/@jest/schemas/package.json +3 -3
- package/rds-lambda/node_modules/@jest/source-map/package.json +3 -3
- package/rds-lambda/node_modules/@jest/test-result/package.json +6 -6
- package/rds-lambda/node_modules/@jest/test-sequencer/package.json +5 -5
- package/rds-lambda/node_modules/@jest/transform/package.json +7 -7
- package/rds-lambda/node_modules/@jest/types/package.json +5 -5
- package/rds-lambda/node_modules/@nicolo-ribaudo/semver-v6/CHANGELOG.md +70 -0
- package/rds-lambda/node_modules/@nicolo-ribaudo/semver-v6/LICENSE +15 -0
- package/rds-lambda/node_modules/@nicolo-ribaudo/semver-v6/README.md +454 -0
- package/rds-lambda/node_modules/@nicolo-ribaudo/semver-v6/package.json +28 -0
- package/rds-lambda/node_modules/@nicolo-ribaudo/semver-v6/range.bnf +16 -0
- package/rds-lambda/node_modules/@sinclair/typebox/package.json +3 -8
- package/rds-lambda/node_modules/@sinclair/typebox/readme.md +487 -300
- package/rds-lambda/node_modules/@smithy/abort-controller/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/abort-controller/package.json +14 -8
- package/rds-lambda/node_modules/@smithy/config-resolver/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/config-resolver/package.json +17 -11
- package/rds-lambda/node_modules/@smithy/credential-provider-imds/README.md +11 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/credential-provider-imds/package.json +17 -11
- package/rds-lambda/node_modules/@smithy/eventstream-codec/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/eventstream-codec/package.json +16 -10
- package/rds-lambda/node_modules/@smithy/fetch-http-handler/README.md +4 -0
- package/rds-lambda/node_modules/@smithy/fetch-http-handler/package.json +81 -0
- package/rds-lambda/node_modules/@smithy/hash-node/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/hash-node/package.json +16 -10
- package/rds-lambda/node_modules/@smithy/invalid-dependency/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/invalid-dependency/package.json +14 -8
- package/rds-lambda/node_modules/@smithy/is-array-buffer/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/is-array-buffer/package.json +13 -7
- package/rds-lambda/node_modules/@smithy/middleware-content-length/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-content-length/package.json +16 -11
- package/rds-lambda/node_modules/@smithy/middleware-endpoint/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-endpoint/package.json +18 -13
- package/rds-lambda/node_modules/@smithy/middleware-retry/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-retry/package.json +20 -15
- package/rds-lambda/node_modules/@smithy/middleware-serde/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-serde/package.json +15 -10
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-stack/README.md +3 -3
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-stack/package.json +15 -10
- package/rds-lambda/node_modules/@smithy/node-config-provider/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/node-config-provider/package.json +16 -10
- package/rds-lambda/node_modules/@smithy/node-http-handler/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/node-http-handler/package.json +18 -12
- package/rds-lambda/node_modules/@smithy/property-provider/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/property-provider/package.json +14 -8
- package/rds-lambda/node_modules/@smithy/protocol-http/package.json +3 -3
- package/rds-lambda/node_modules/@smithy/querystring-builder/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/querystring-builder/package.json +15 -9
- package/rds-lambda/node_modules/@smithy/querystring-parser/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/querystring-parser/package.json +14 -8
- package/rds-lambda/node_modules/@smithy/service-error-classification/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/service-error-classification/package.json +14 -8
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/shared-ini-file-loader/README.md +3 -3
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/shared-ini-file-loader/package.json +14 -8
- package/rds-lambda/node_modules/@smithy/signature-v4/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/signature-v4/package.json +21 -15
- package/rds-lambda/node_modules/@smithy/smithy-client/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/smithy-client/package.json +16 -11
- package/rds-lambda/node_modules/@smithy/types/package.json +2 -2
- package/rds-lambda/node_modules/@smithy/url-parser/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/url-parser/package.json +15 -9
- package/rds-lambda/node_modules/@smithy/util-base64/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-base64/package.json +14 -8
- package/rds-lambda/node_modules/@smithy/util-body-length-browser/README.md +12 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-body-length-browser/package.json +13 -7
- package/rds-lambda/node_modules/@smithy/util-body-length-node/README.md +12 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-body-length-node/package.json +13 -7
- package/rds-lambda/node_modules/@smithy/util-buffer-from/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-buffer-from/package.json +14 -8
- package/rds-lambda/node_modules/@smithy/util-config-provider/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-config-provider/package.json +13 -7
- package/rds-lambda/node_modules/@smithy/util-defaults-mode-browser/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-defaults-mode-browser/package.json +17 -10
- package/rds-lambda/node_modules/@smithy/util-defaults-mode-node/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-defaults-mode-node/package.json +20 -13
- package/rds-lambda/node_modules/@smithy/util-hex-encoding/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-hex-encoding/package.json +13 -7
- package/rds-lambda/node_modules/@smithy/util-middleware/README.md +12 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-middleware/package.json +14 -8
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-retry/README.md +7 -7
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-retry/package.json +15 -9
- package/rds-lambda/node_modules/@smithy/util-stream/README.md +12 -0
- package/rds-lambda/node_modules/@smithy/util-stream/package.json +92 -0
- package/rds-lambda/node_modules/@smithy/util-uri-escape/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-uri-escape/package.json +13 -7
- package/rds-lambda/node_modules/@smithy/util-utf8/README.md +4 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-utf8/package.json +14 -8
- package/rds-lambda/node_modules/@smithy/util-waiter/README.md +10 -0
- package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-waiter/package.json +15 -9
- package/rds-lambda/node_modules/@types/node/README.md +1 -1
- package/rds-lambda/node_modules/@types/node/package.json +2 -2
- package/rds-lambda/node_modules/babel-jest/package.json +4 -4
- package/rds-lambda/node_modules/caniuse-lite/package.json +1 -1
- package/rds-lambda/node_modules/collect-v8-coverage/CHANGELOG.md +7 -0
- package/rds-lambda/node_modules/collect-v8-coverage/package.json +18 -20
- package/rds-lambda/node_modules/electron-to-chromium/full-chromium-versions.json +1 -1
- package/rds-lambda/node_modules/electron-to-chromium/full-versions.json +1 -1
- package/rds-lambda/node_modules/electron-to-chromium/package.json +1 -1
- package/rds-lambda/node_modules/expect/package.json +10 -9
- package/rds-lambda/node_modules/jest/package.json +7 -7
- package/rds-lambda/node_modules/jest-circus/package.json +15 -14
- package/rds-lambda/node_modules/jest-cli/package.json +10 -9
- package/rds-lambda/node_modules/jest-config/package.json +14 -14
- package/rds-lambda/node_modules/jest-diff/package.json +4 -4
- package/rds-lambda/node_modules/jest-each/package.json +5 -5
- package/rds-lambda/node_modules/jest-environment-node/package.json +8 -8
- package/rds-lambda/node_modules/jest-haste-map/package.json +5 -5
- package/rds-lambda/node_modules/jest-leak-detector/package.json +3 -3
- package/rds-lambda/node_modules/jest-matcher-utils/package.json +5 -5
- package/rds-lambda/node_modules/jest-message-util/package.json +4 -4
- package/rds-lambda/node_modules/jest-mock/package.json +6 -6
- package/rds-lambda/node_modules/jest-resolve/package.json +7 -7
- package/rds-lambda/node_modules/jest-resolve-dependencies/package.json +8 -8
- package/rds-lambda/node_modules/jest-runner/package.json +20 -20
- package/rds-lambda/node_modules/jest-runtime/package.json +17 -17
- package/rds-lambda/node_modules/jest-snapshot/package.json +15 -17
- package/rds-lambda/node_modules/jest-util/package.json +3 -3
- package/rds-lambda/node_modules/jest-validate/package.json +4 -4
- package/rds-lambda/node_modules/jest-watcher/package.json +5 -5
- package/rds-lambda/node_modules/jest-worker/package.json +6 -6
- package/rds-lambda/node_modules/pretty-format/package.json +5 -5
- package/rds-lambda/node_modules/ts-jest/.ts-jest-digest +1 -1
- package/rds-lambda/node_modules/ts-jest/CHANGELOG.md +9 -0
- package/rds-lambda/node_modules/ts-jest/package.json +12 -12
- package/rds-lambda/package-lock.json +1511 -1502
- package/src/resources/dynamo-model-resource-generator.ts +0 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/rds-lambda/node_modules/@aws-sdk/abort-controller/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/config-resolver/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/credential-provider-imds/README.md +0 -11
- package/rds-lambda/node_modules/@aws-sdk/eventstream-codec/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/fetch-http-handler/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/fetch-http-handler/package.json +0 -59
- package/rds-lambda/node_modules/@aws-sdk/hash-node/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/invalid-dependency/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/is-array-buffer/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/middleware-content-length/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/middleware-endpoint/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/middleware-retry/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/middleware-serde/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/node-config-provider/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/node-http-handler/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/property-provider/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/protocol-http/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/protocol-http/package.json +0 -57
- package/rds-lambda/node_modules/@aws-sdk/querystring-builder/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/querystring-parser/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/service-error-classification/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/signature-v4/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/smithy-client/LICENSE +0 -201
- package/rds-lambda/node_modules/@aws-sdk/smithy-client/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/url-parser/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/util-base64/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/util-body-length-browser/README.md +0 -12
- package/rds-lambda/node_modules/@aws-sdk/util-body-length-node/README.md +0 -12
- package/rds-lambda/node_modules/@aws-sdk/util-buffer-from/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/util-config-provider/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/util-defaults-mode-browser/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/util-defaults-mode-node/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/util-hex-encoding/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/util-middleware/README.md +0 -12
- package/rds-lambda/node_modules/@aws-sdk/util-stream/README.md +0 -12
- package/rds-lambda/node_modules/@aws-sdk/util-stream/package.json +0 -71
- package/rds-lambda/node_modules/@aws-sdk/util-uri-escape/README.md +0 -10
- package/rds-lambda/node_modules/@aws-sdk/util-utf8/README.md +0 -4
- package/rds-lambda/node_modules/@aws-sdk/util-waiter/README.md +0 -10
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/abort-controller/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/config-resolver/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/credential-provider-imds/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/eventstream-codec/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/fetch-http-handler/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/hash-node/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/invalid-dependency/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/is-array-buffer/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-content-length/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-endpoint/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-retry/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-retry/node_modules/uuid/CHANGELOG.md +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-retry/node_modules/uuid/CONTRIBUTING.md +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-retry/node_modules/uuid/LICENSE.md +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-retry/node_modules/uuid/README.md +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-retry/node_modules/uuid/dist/bin/uuid +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-retry/node_modules/uuid/package.json +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-retry/node_modules/uuid/wrapper.mjs +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-serde/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/middleware-stack/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/node-config-provider/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/node-http-handler/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/property-provider/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/querystring-builder/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/querystring-parser/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/service-error-classification/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/shared-ini-file-loader/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/signature-v4/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk/protocol-http → @smithy/smithy-client}/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/url-parser/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-base64/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-body-length-browser/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-body-length-node/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-buffer-from/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-config-provider/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-defaults-mode-browser/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-defaults-mode-node/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-hex-encoding/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-middleware/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-retry/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-stream/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-uri-escape/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-utf8/LICENSE +0 -0
- /package/rds-lambda/node_modules/{@aws-sdk → @smithy}/util-waiter/LICENSE +0 -0
|
@@ -35,7 +35,7 @@ import { Static, Type } from 'npm:@sinclair/typebox'
|
|
|
35
35
|
import { Static, Type } from 'https://esm.sh/@sinclair/typebox'
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
##
|
|
38
|
+
## Example
|
|
39
39
|
|
|
40
40
|
```typescript
|
|
41
41
|
import { Static, Type } from '@sinclair/typebox'
|
|
@@ -62,59 +62,62 @@ type T = Static<typeof T> // type T = {
|
|
|
62
62
|
|
|
63
63
|
## Overview
|
|
64
64
|
|
|
65
|
-
TypeBox is a type builder
|
|
65
|
+
TypeBox is a runtime type builder that creates in-memory JSON Schema objects that can be statically inferred as TypeScript types. The schemas produced by this library are designed to match the static type assertion rules of the TypeScript compiler. TypeBox enables one to create a unified type that can be statically checked by TypeScript and runtime asserted using standard JSON Schema validation.
|
|
66
66
|
|
|
67
|
-
This library is designed to enable JSON schema to compose with the same flexibility as TypeScript's type system. It can be used
|
|
67
|
+
This library is designed to enable JSON schema to compose with the same flexibility as TypeScript's type system. It can be used as a simple tool to build up complex schemas or integrated into REST or RPC services to help validate data received over the wire.
|
|
68
68
|
|
|
69
69
|
License MIT
|
|
70
70
|
|
|
71
71
|
## Contents
|
|
72
72
|
- [Install](#install)
|
|
73
73
|
- [Overview](#overview)
|
|
74
|
-
- [
|
|
74
|
+
- [Usage](#usage)
|
|
75
75
|
- [Types](#types)
|
|
76
76
|
- [Standard](#types-standard)
|
|
77
77
|
- [Extended](#types-extended)
|
|
78
78
|
- [Modifiers](#types-modifiers)
|
|
79
79
|
- [Options](#types-options)
|
|
80
|
-
- [
|
|
80
|
+
- [Generics](#types-generics)
|
|
81
|
+
- [References](#types-references)
|
|
81
82
|
- [Recursive](#types-recursive)
|
|
82
|
-
- [Generic](#types-generic)
|
|
83
83
|
- [Conditional](#types-conditional)
|
|
84
|
-
- [
|
|
84
|
+
- [Template Literal](#types-template-literal)
|
|
85
85
|
- [Guards](#types-guards)
|
|
86
|
+
- [Unsafe](#types-unsafe)
|
|
86
87
|
- [Strict](#types-strict)
|
|
87
88
|
- [Values](#values)
|
|
88
89
|
- [Create](#values-create)
|
|
89
90
|
- [Clone](#values-clone)
|
|
90
91
|
- [Check](#values-check)
|
|
92
|
+
- [Convert](#values-convert)
|
|
91
93
|
- [Cast](#values-cast)
|
|
92
94
|
- [Equal](#values-equal)
|
|
93
95
|
- [Hash](#values-hash)
|
|
94
96
|
- [Diff](#values-diff)
|
|
95
97
|
- [Patch](#values-patch)
|
|
96
98
|
- [Errors](#values-errors)
|
|
99
|
+
- [Mutate](#values-mutate)
|
|
97
100
|
- [Pointer](#values-pointer)
|
|
98
101
|
- [TypeCheck](#typecheck)
|
|
99
102
|
- [Ajv](#typecheck-ajv)
|
|
100
103
|
- [TypeCompiler](#typecheck-typecompiler)
|
|
101
|
-
- [TypeSystem](#
|
|
104
|
+
- [TypeSystem](#typesystem)
|
|
102
105
|
- [Types](#typesystem-types)
|
|
103
106
|
- [Formats](#typesystem-formats)
|
|
107
|
+
- [Policies](#typesystem-policies)
|
|
104
108
|
- [Benchmark](#benchmark)
|
|
105
109
|
- [Compile](#benchmark-compile)
|
|
106
110
|
- [Validate](#benchmark-validate)
|
|
107
111
|
- [Compression](#benchmark-compression)
|
|
108
112
|
- [Contribute](#contribute)
|
|
109
113
|
|
|
110
|
-
<a name="
|
|
114
|
+
<a name="usage"></a>
|
|
111
115
|
|
|
112
|
-
##
|
|
116
|
+
## Usage
|
|
113
117
|
|
|
114
|
-
The following
|
|
118
|
+
The following shows general usage.
|
|
115
119
|
|
|
116
120
|
```typescript
|
|
117
|
-
|
|
118
121
|
import { Static, Type } from '@sinclair/typebox'
|
|
119
122
|
|
|
120
123
|
//--------------------------------------------------------------------------------------------
|
|
@@ -173,9 +176,11 @@ type T = Static<typeof T> // type T = {
|
|
|
173
176
|
//
|
|
174
177
|
//--------------------------------------------------------------------------------------------
|
|
175
178
|
|
|
176
|
-
|
|
179
|
+
import { Value } from '@sinclair/typebox/value'
|
|
177
180
|
|
|
178
|
-
|
|
181
|
+
function receive(value: T) { // ... as a Static Type
|
|
182
|
+
|
|
183
|
+
if(Value.Check(T, value)) { // ... as a JSON Schema
|
|
179
184
|
|
|
180
185
|
// ok...
|
|
181
186
|
}
|
|
@@ -186,13 +191,13 @@ function receive(value: T) { // ... as a Type
|
|
|
186
191
|
|
|
187
192
|
## Types
|
|
188
193
|
|
|
189
|
-
TypeBox
|
|
194
|
+
TypeBox types are JSON schema fragments that can be composed into more complex types. Each fragment is structured such that a JSON schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox provides a set of Standard types which are used create JSON schema compliant schematics as well as an Extended type set used to create schematics for constructs native to JavaScript.
|
|
190
195
|
|
|
191
196
|
<a name='types-standard'></a>
|
|
192
197
|
|
|
193
|
-
### Standard
|
|
198
|
+
### Standard Types
|
|
194
199
|
|
|
195
|
-
The following table lists the Standard TypeBox types.
|
|
200
|
+
The following table lists the Standard TypeBox types. These types are fully compatible with the JSON Schema Draft 6 specification.
|
|
196
201
|
|
|
197
202
|
```typescript
|
|
198
203
|
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
@@ -226,19 +231,13 @@ The following table lists the Standard TypeBox types.
|
|
|
226
231
|
│ │ │ │
|
|
227
232
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
228
233
|
│ const T = Type.Null() │ type T = null │ const T = { │
|
|
229
|
-
│ │ │
|
|
230
|
-
│ │ │ } │
|
|
231
|
-
│ │ │ │
|
|
232
|
-
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
233
|
-
│ const T = Type.RegEx(/foo/) │ type T = string │ const T = { │
|
|
234
|
-
│ │ │ type: 'string', │
|
|
235
|
-
│ │ │ pattern: 'foo' │
|
|
234
|
+
│ │ │ type: 'null' │
|
|
236
235
|
│ │ │ } │
|
|
237
236
|
│ │ │ │
|
|
238
237
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
239
238
|
│ const T = Type.Literal(42) │ type T = 42 │ const T = { │
|
|
240
|
-
│ │ │
|
|
241
|
-
│ │ │
|
|
239
|
+
│ │ │ const: 42, │
|
|
240
|
+
│ │ │ type: 'number' │
|
|
242
241
|
│ │ │ } │
|
|
243
242
|
│ │ │ │
|
|
244
243
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
@@ -252,15 +251,14 @@ The following table lists the Standard TypeBox types.
|
|
|
252
251
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
253
252
|
│ const T = Type.Object({ │ type T = { │ const T = { │
|
|
254
253
|
│ x: Type.Number(), │ x: number, │ type: 'object', │
|
|
255
|
-
│ y: Type.Number() │ y: number │
|
|
256
|
-
│ }) │ } │
|
|
257
|
-
│ │ │
|
|
258
|
-
│ │ │
|
|
259
|
-
│ │ │
|
|
260
|
-
│ │ │
|
|
261
|
-
│ │ │
|
|
262
|
-
│ │ │ }
|
|
263
|
-
│ │ │ required: ['x', 'y'] │
|
|
254
|
+
│ y: Type.Number() │ y: number │ required: ['x', 'y'], │
|
|
255
|
+
│ }) │ } │ properties: { │
|
|
256
|
+
│ │ │ x: { │
|
|
257
|
+
│ │ │ type: 'number' │
|
|
258
|
+
│ │ │ }, { │
|
|
259
|
+
│ │ │ type: 'number' │
|
|
260
|
+
│ │ │ } │
|
|
261
|
+
│ │ │ } │
|
|
264
262
|
│ │ │ } │
|
|
265
263
|
│ │ │ │
|
|
266
264
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
@@ -268,12 +266,12 @@ The following table lists the Standard TypeBox types.
|
|
|
268
266
|
│ Type.Number(), │ │ type: 'array', │
|
|
269
267
|
│ Type.Number() │ │ items: [{ │
|
|
270
268
|
│ ]) │ │ type: 'number' │
|
|
271
|
-
│ │ │
|
|
272
|
-
│ │ │
|
|
273
|
-
│ │ │
|
|
274
|
-
│ │ │
|
|
275
|
-
│ │ │
|
|
276
|
-
│ │ │
|
|
269
|
+
│ │ │ }, { │
|
|
270
|
+
│ │ │ type: 'number' │
|
|
271
|
+
│ │ │ }], │
|
|
272
|
+
│ │ │ additionalItems: false, │
|
|
273
|
+
│ │ │ minItems: 2, │
|
|
274
|
+
│ │ │ maxItems: 2 │
|
|
277
275
|
│ │ │ } │
|
|
278
276
|
│ │ │ │
|
|
279
277
|
│ │ │ │
|
|
@@ -310,33 +308,101 @@ The following table lists the Standard TypeBox types.
|
|
|
310
308
|
│ │ │ │
|
|
311
309
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
312
310
|
│ const T = Type.Intersect([ │ type T = { │ const T = { │
|
|
311
|
+
│ Type.Object({ │ x: number │ allOf: [{ │
|
|
312
|
+
│ x: Type.Number() │ } & { │ type: 'object', │
|
|
313
|
+
│ }), │ y: number │ required: ['x'], │
|
|
314
|
+
│ Type.Object({ │ } │ properties: { │
|
|
315
|
+
│ y: Type.Number() │ │ x: { │
|
|
316
|
+
│ ]) │ │ type: 'number' │
|
|
317
|
+
│ ]) │ │ } │
|
|
318
|
+
│ │ │ } │
|
|
319
|
+
│ │ │ }, { │
|
|
320
|
+
│ │ │ type: 'object', |
|
|
321
|
+
│ │ │ required: ['y'], │
|
|
322
|
+
│ │ │ properties: { │
|
|
323
|
+
│ │ │ y: { │
|
|
324
|
+
│ │ │ type: 'number' │
|
|
325
|
+
│ │ │ } │
|
|
326
|
+
│ │ │ } │
|
|
327
|
+
│ │ │ }] │
|
|
328
|
+
│ │ │ } │
|
|
329
|
+
│ │ │ │
|
|
330
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
331
|
+
│ const T = Type.Composite([ │ type I = { │ const T = { │
|
|
313
332
|
│ Type.Object({ │ x: number │ type: 'object', │
|
|
314
|
-
│ x: Type.Number() │ } & { │
|
|
315
|
-
│ }), │ y: number │
|
|
316
|
-
│ Type.Object({ │ } │
|
|
317
|
-
│ y: Type.Number() │ │
|
|
318
|
-
│ }) │
|
|
319
|
-
│ ]) │
|
|
333
|
+
│ x: Type.Number() │ } & { │ required: ['x', 'y'], │
|
|
334
|
+
│ }), │ y: number │ properties: { │
|
|
335
|
+
│ Type.Object({ │ } │ x: { │
|
|
336
|
+
│ y: Type.Number() │ │ type: 'number' │
|
|
337
|
+
│ }) │ type T = { │ }, │
|
|
338
|
+
│ ]) │ [K in keyof I]: I[K] │ y: { │
|
|
339
|
+
│ │ } │ type: 'number' │
|
|
320
340
|
│ │ │ } │
|
|
321
|
-
│ │ │ }
|
|
322
|
-
│ │ │ required: ['x', 'y'] │
|
|
341
|
+
│ │ │ } │
|
|
323
342
|
│ │ │ } │
|
|
324
343
|
│ │ │ │
|
|
325
344
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
326
345
|
│ const T = Type.Never() │ type T = never │ const T = { │
|
|
327
|
-
│ │ │
|
|
328
|
-
│ │ │
|
|
329
|
-
│ │ │
|
|
346
|
+
│ │ │ not: {} │
|
|
347
|
+
│ │ │ } │
|
|
348
|
+
│ │ │ │
|
|
349
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
350
|
+
│ const T = Type.Not( | type T = string │ const T = { │
|
|
351
|
+
| Type.Union([ │ │ allOf: [{ │
|
|
352
|
+
│ Type.Literal('x'), │ │ not: { │
|
|
353
|
+
│ Type.Literal('y'), │ │ anyOf: [ │
|
|
354
|
+
│ Type.Literal('z') │ │ { const: 'x' }, │
|
|
355
|
+
│ ]), │ │ { const: 'y' }, │
|
|
356
|
+
│ Type.String() │ │ { const: 'z' } │
|
|
357
|
+
│ ) │ │ ] │
|
|
358
|
+
│ │ │ } │
|
|
330
359
|
│ │ │ }, { │
|
|
331
|
-
│ │ │ type: '
|
|
332
|
-
│ │ │ const: true │
|
|
360
|
+
│ │ │ type: 'string' │
|
|
333
361
|
│ │ │ }] │
|
|
334
362
|
│ │ │ } │
|
|
335
363
|
│ │ │ │
|
|
336
364
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
365
|
+
│ const T = Type.Extends( │ type T = │ const T = { │
|
|
366
|
+
│ Type.String(), │ string extends number │ const: false, │
|
|
367
|
+
│ Type.Number(), │ true : false │ type: 'boolean' │
|
|
368
|
+
│ Type.Literal(true), │ │ } │
|
|
369
|
+
│ Type.Literal(false) │ │ │
|
|
370
|
+
│ ) │ │ │
|
|
371
|
+
│ │ │ │
|
|
372
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
373
|
+
│ const T = Type.Extract( │ type T = Extract< │ const T = { │
|
|
374
|
+
│ Type.Union([ │ string | number, │ type: 'string' │
|
|
375
|
+
│ Type.String(), │ string │ } │
|
|
376
|
+
│ Type.Number(), │ > │ │
|
|
377
|
+
│ ]), │ │ │
|
|
378
|
+
│ Type.String() │ │ │
|
|
379
|
+
│ ) │ │ │
|
|
380
|
+
│ │ │ │
|
|
381
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
382
|
+
│ const T = Type.Exclude( │ type T = Exclude< │ const T = { │
|
|
383
|
+
│ Type.Union([ │ string | number, │ type: 'number' │
|
|
384
|
+
│ Type.String(), │ string │ } │
|
|
385
|
+
│ Type.Number(), │ > │ │
|
|
386
|
+
│ ]), │ │ │
|
|
387
|
+
│ Type.String() │ │ │
|
|
388
|
+
│ ) │ │ │
|
|
389
|
+
│ │ │ │
|
|
390
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
391
|
+
│ const U = Type.Union([ │ type U = 'open' | 'close' │ const T = { │
|
|
392
|
+
│ Type.Literal('open'), │ │ type: 'string', │
|
|
393
|
+
│ Type.Literal('close') │ type T = `on${U}` │ pattern: '^on(open|close)$' │
|
|
394
|
+
│ ]) │ │ } │
|
|
395
|
+
│ │ │ │
|
|
396
|
+
│ const T = Type │ │ │
|
|
397
|
+
│ .TemplateLiteral([ │ │ │
|
|
398
|
+
│ Type.Literal('on'), │ │ │
|
|
399
|
+
│ U │ │ │
|
|
400
|
+
│ ]) │ │ │
|
|
401
|
+
│ │ │ │
|
|
402
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
337
403
|
│ const T = Type.Record( │ type T = Record< │ const T = { │
|
|
338
404
|
│ Type.String(), │ string, │ type: 'object', │
|
|
339
|
-
│ Type.Number() │ number
|
|
405
|
+
│ Type.Number() │ number │ patternProperties: { │
|
|
340
406
|
│ ) │ > │ '^.*$': { │
|
|
341
407
|
│ │ │ type: 'number' │
|
|
342
408
|
│ │ │ } │
|
|
@@ -359,47 +425,58 @@ The following table lists the Standard TypeBox types.
|
|
|
359
425
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
360
426
|
│ const T = Type.Required( │ type T = Required<{ │ const T = { │
|
|
361
427
|
│ Type.Object({ │ x?: number, │ type: 'object', │
|
|
362
|
-
│ x: Type.Optional( │ y?: number │
|
|
363
|
-
│ Type.Number() | }> │
|
|
364
|
-
│ ), │ │
|
|
365
|
-
│ y: Type.Optional( │ │
|
|
366
|
-
│ Type.Number() │ │
|
|
367
|
-
│ ) │ │
|
|
368
|
-
│ }) │ │
|
|
369
|
-
│ ) │ │
|
|
370
|
-
│ │ │
|
|
428
|
+
│ x: Type.Optional( │ y?: number │ required: ['x', 'y'], │
|
|
429
|
+
│ Type.Number() | }> │ properties: { │
|
|
430
|
+
│ ), │ │ x: { │
|
|
431
|
+
│ y: Type.Optional( │ │ type: 'number' │
|
|
432
|
+
│ Type.Number() │ │ }, │
|
|
433
|
+
│ ) │ │ y: { │
|
|
434
|
+
│ }) │ │ type: 'number' │
|
|
435
|
+
│ ) │ │ } │
|
|
436
|
+
│ │ │ } │
|
|
371
437
|
│ │ │ } │
|
|
372
438
|
│ │ │ │
|
|
373
439
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
374
440
|
│ const T = Type.Pick( │ type T = Pick<{ │ const T = { │
|
|
375
441
|
│ Type.Object({ │ x: number, │ type: 'object', │
|
|
376
|
-
│ x: Type.Number(), │ y: number │
|
|
377
|
-
│ y: Type.Number()
|
|
378
|
-
│ }), ['x']
|
|
379
|
-
│ ) │ │
|
|
380
|
-
│ │ │
|
|
381
|
-
│ │ │
|
|
442
|
+
│ x: Type.Number(), │ y: number │ required: ['x'], │
|
|
443
|
+
│ y: Type.Number() │ }, 'x'> │ properties: { │
|
|
444
|
+
│ }), ['x'] | │ x: { │
|
|
445
|
+
│ ) │ │ type: 'number' │
|
|
446
|
+
│ │ │ } │
|
|
447
|
+
│ │ │ } │
|
|
382
448
|
│ │ │ } │
|
|
383
449
|
│ │ │ │
|
|
384
450
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
385
451
|
│ const T = Type.Omit( │ type T = Omit<{ │ const T = { │
|
|
386
452
|
│ Type.Object({ │ x: number, │ type: 'object', │
|
|
387
|
-
│ x: Type.Number(), │ y: number │
|
|
388
|
-
│ y: Type.Number()
|
|
389
|
-
│ }), ['x']
|
|
390
|
-
│ ) │ │
|
|
391
|
-
│ │ │
|
|
392
|
-
│ │ │
|
|
453
|
+
│ x: Type.Number(), │ y: number │ required: ['y'], │
|
|
454
|
+
│ y: Type.Number() │ }, 'x'> │ properties: { │
|
|
455
|
+
│ }), ['x'] | │ y: { │
|
|
456
|
+
│ ) │ │ type: 'number' │
|
|
457
|
+
│ │ │ } │
|
|
458
|
+
│ │ │ } │
|
|
393
459
|
│ │ │ } │
|
|
394
460
|
│ │ │ │
|
|
461
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
462
|
+
│ const T = Type.Object({ │ type T = { │ const R = { │
|
|
463
|
+
│ x: Type.Number(), │ x: number, │ $ref: 'T' │
|
|
464
|
+
│ y: Type.Number() │ y: number │ } │
|
|
465
|
+
│ }, { $id: 'T' }) | } │ │
|
|
466
|
+
│ │ │ │
|
|
467
|
+
│ const R = Type.Ref(T) │ type R = T │ │
|
|
468
|
+
│ │ │ │
|
|
469
|
+
│ │ │ │
|
|
470
|
+
│ │ │ │
|
|
471
|
+
│ │ │ │
|
|
395
472
|
└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘
|
|
396
473
|
```
|
|
397
474
|
|
|
398
475
|
<a name='types-extended'></a>
|
|
399
476
|
|
|
400
|
-
### Extended
|
|
477
|
+
### Extended Types
|
|
401
478
|
|
|
402
|
-
TypeBox provides
|
|
479
|
+
TypeBox provides several extended types that can be used to produce schematics for common JavaScript constructs. These types can not be used with standard JSON schema validators; but are useful to help frame schematics for RPC interfaces that may receive JSON validated data. Extended types are prefixed with the `[Extended]` doc comment for convenience. The following table lists the supported types.
|
|
403
480
|
|
|
404
481
|
```typescript
|
|
405
482
|
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
@@ -462,6 +539,24 @@ TypeBox provides a set of extended types that can be used to express schematics
|
|
|
462
539
|
│ │ │ } │
|
|
463
540
|
│ │ │ │
|
|
464
541
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
542
|
+
│ const T = Type.RegEx(/foo/) │ type T = string │ const T = { │
|
|
543
|
+
│ │ │ type: 'string', │
|
|
544
|
+
│ │ │ pattern: 'foo' │
|
|
545
|
+
│ │ │ } │
|
|
546
|
+
│ │ │ │
|
|
547
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
548
|
+
│ const T = Type.Symbol() │ type T = symbol │ const T = { │
|
|
549
|
+
│ │ │ type: 'null', │
|
|
550
|
+
│ │ │ typeOf: 'Symbol' │
|
|
551
|
+
│ │ │ } │
|
|
552
|
+
│ │ │ │
|
|
553
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
554
|
+
│ const T = Type.BigInt() │ type T = bigint │ const T = { │
|
|
555
|
+
│ │ │ type: 'null', │
|
|
556
|
+
│ │ │ typeOf: 'BigInt' │
|
|
557
|
+
│ │ │ } │
|
|
558
|
+
│ │ │ │
|
|
559
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
465
560
|
│ const T = Type.Void() │ type T = void │ const T = { │
|
|
466
561
|
│ │ │ type: 'null' │
|
|
467
562
|
│ │ │ typeOf: 'Void' │
|
|
@@ -474,7 +569,7 @@ TypeBox provides a set of extended types that can be used to express schematics
|
|
|
474
569
|
|
|
475
570
|
### Modifiers
|
|
476
571
|
|
|
477
|
-
TypeBox provides modifiers that
|
|
572
|
+
TypeBox provides modifiers that allow schema properties to be statically inferred as `readonly` or `optional`. The following table shows the supported modifiers and how they map between TypeScript and JSON Schema.
|
|
478
573
|
|
|
479
574
|
```typescript
|
|
480
575
|
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
@@ -484,9 +579,9 @@ TypeBox provides modifiers that can be applied to an objects properties. This al
|
|
|
484
579
|
│ const T = Type.Object({ │ type T = { │ const T = { │
|
|
485
580
|
│ name: Type.Optional( │ name?: string │ type: 'object', │
|
|
486
581
|
│ Type.String() │ } │ properties: { │
|
|
487
|
-
│ ) │ │
|
|
488
|
-
│ }) │ │
|
|
489
|
-
│ │ │
|
|
582
|
+
│ ) │ │ name: { │
|
|
583
|
+
│ }) │ │ type: 'string' │
|
|
584
|
+
│ │ │ } │
|
|
490
585
|
│ │ │ } │
|
|
491
586
|
│ │ │ } │
|
|
492
587
|
│ │ │ │
|
|
@@ -518,24 +613,96 @@ TypeBox provides modifiers that can be applied to an objects properties. This al
|
|
|
518
613
|
|
|
519
614
|
### Options
|
|
520
615
|
|
|
521
|
-
You can pass
|
|
616
|
+
You can pass JSON Schema options on the last argument of any type. Option hints specific to each type are provided for convenience.
|
|
617
|
+
|
|
618
|
+
```typescript
|
|
619
|
+
// String must be an email
|
|
620
|
+
const T = Type.String({ // const T = {
|
|
621
|
+
format: 'email' // type: 'string',
|
|
622
|
+
}) // format: 'email'
|
|
623
|
+
// }
|
|
624
|
+
|
|
625
|
+
// Mumber must be a multiple of 2
|
|
626
|
+
const T = Type.Number({ // const T = {
|
|
627
|
+
multipleOf: 2 // type: 'number',
|
|
628
|
+
}) // multipleOf: 2
|
|
629
|
+
// }
|
|
630
|
+
|
|
631
|
+
// Array must have at least 5 integer values
|
|
632
|
+
const T = Type.Array(Type.Integer(), { // const T = {
|
|
633
|
+
minItems: 5 // type: 'array',
|
|
634
|
+
}) // minItems: 5,
|
|
635
|
+
// items: {
|
|
636
|
+
// type: 'integer'
|
|
637
|
+
// }
|
|
638
|
+
// }
|
|
639
|
+
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
<a name='types-generics'></a>
|
|
643
|
+
|
|
644
|
+
### Generic Types
|
|
645
|
+
|
|
646
|
+
Generic types can be created with generic functions constrained to type `TSchema`. The following creates a generic `Vector<T>` type.
|
|
647
|
+
|
|
648
|
+
```typescript
|
|
649
|
+
import { Type, Static, TSchema } from '@sinclair/typebox'
|
|
650
|
+
|
|
651
|
+
const Vector = <T extends TSchema>(t: T) => Type.Object({ x: t, y: t, z: t })
|
|
652
|
+
|
|
653
|
+
const NumberVector = Vector(Type.Number()) // const NumberVector = {
|
|
654
|
+
// type: 'object',
|
|
655
|
+
// required: ['x', 'y', 'z'],
|
|
656
|
+
// properties: {
|
|
657
|
+
// x: { type: 'number' },
|
|
658
|
+
// y: { type: 'number' },
|
|
659
|
+
// z: { type: 'number' }
|
|
660
|
+
// }
|
|
661
|
+
// }
|
|
662
|
+
|
|
663
|
+
type NumberVector = Static<typeof NumberVector> // type NumberVector = {
|
|
664
|
+
// x: number,
|
|
665
|
+
// y: number,
|
|
666
|
+
// z: number
|
|
667
|
+
// }
|
|
668
|
+
|
|
669
|
+
const BooleanVector = Vector(Type.Boolean()) // const BooleanVector = {
|
|
670
|
+
// type: 'object',
|
|
671
|
+
// required: ['x', 'y', 'z'],
|
|
672
|
+
// properties: {
|
|
673
|
+
// x: { type: 'boolean' },
|
|
674
|
+
// y: { type: 'boolean' },
|
|
675
|
+
// z: { type: 'boolean' }
|
|
676
|
+
// }
|
|
677
|
+
// }
|
|
678
|
+
|
|
679
|
+
type BooleanVector = Static<typeof BooleanVector> // type BooleanVector = {
|
|
680
|
+
// x: boolean,
|
|
681
|
+
// y: boolean,
|
|
682
|
+
// z: boolean
|
|
683
|
+
// }
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
The following creates a generic `Nullable<T>` type.
|
|
522
687
|
|
|
523
688
|
```typescript
|
|
524
|
-
|
|
525
|
-
const T = Type.String({ format: 'email' })
|
|
689
|
+
const Nullable = <T extends TSchema>(schema: T) => Type.Union([schema, Type.Null()])
|
|
526
690
|
|
|
527
|
-
|
|
528
|
-
|
|
691
|
+
const T = Nullable(Type.String()) // const T = {
|
|
692
|
+
// anyOf: [
|
|
693
|
+
// { type: 'string' },
|
|
694
|
+
// { type: 'null' }
|
|
695
|
+
// ]
|
|
696
|
+
// }
|
|
529
697
|
|
|
530
|
-
|
|
531
|
-
const T = Type.Array(Type.Integer(), { minItems: 5 })
|
|
698
|
+
type T = Static<typeof T> // type T = string | null
|
|
532
699
|
```
|
|
533
700
|
|
|
534
|
-
<a name='types-
|
|
701
|
+
<a name='types-references'></a>
|
|
535
702
|
|
|
536
|
-
### Reference
|
|
703
|
+
### Reference Types
|
|
537
704
|
|
|
538
|
-
|
|
705
|
+
Reference types are supported with `Type.Ref`. The target type must specify a valid `$id`.
|
|
539
706
|
|
|
540
707
|
```typescript
|
|
541
708
|
const T = Type.String({ $id: 'T' }) // const T = {
|
|
@@ -550,9 +717,9 @@ const R = Type.Ref(T) // const R = {
|
|
|
550
717
|
|
|
551
718
|
<a name='types-recursive'></a>
|
|
552
719
|
|
|
553
|
-
### Recursive
|
|
720
|
+
### Recursive Types
|
|
554
721
|
|
|
555
|
-
|
|
722
|
+
Recursive types are supported with `Type.Recursive`
|
|
556
723
|
|
|
557
724
|
```typescript
|
|
558
725
|
const Node = Type.Recursive(Node => Type.Object({ // const Node = {
|
|
@@ -581,102 +748,93 @@ type Node = Static<typeof Node> // type Node = {
|
|
|
581
748
|
// }
|
|
582
749
|
|
|
583
750
|
function test(node: Node) {
|
|
584
|
-
const id = node.nodes[0].nodes[0]
|
|
585
|
-
.nodes[0].nodes[0]
|
|
586
|
-
.id
|
|
751
|
+
const id = node.nodes[0].nodes[0].id // id is string
|
|
587
752
|
}
|
|
588
753
|
```
|
|
589
754
|
|
|
590
|
-
<a name='types-
|
|
755
|
+
<a name='types-conditional'></a>
|
|
591
756
|
|
|
592
|
-
###
|
|
757
|
+
### Conditional Types
|
|
593
758
|
|
|
594
|
-
|
|
759
|
+
Conditional types are supported with `Type.Extends`, `Type.Exclude` and `Type.Extract`
|
|
595
760
|
|
|
596
761
|
```typescript
|
|
597
|
-
|
|
762
|
+
// TypeScript
|
|
598
763
|
|
|
599
|
-
|
|
764
|
+
type T0 = string extends number ? true : false // type T0 = false
|
|
600
765
|
|
|
601
|
-
|
|
602
|
-
// anyOf: [{
|
|
603
|
-
// type: 'string'
|
|
604
|
-
// }, {
|
|
605
|
-
// type: 'null'
|
|
606
|
-
// }]
|
|
607
|
-
// }
|
|
766
|
+
type T1 = Extract<string | number, number> // type T1 = number
|
|
608
767
|
|
|
609
|
-
type
|
|
768
|
+
type T2 = Exclude<string | number, number> // type T2 = string
|
|
610
769
|
|
|
611
|
-
|
|
612
|
-
// anyOf: [{
|
|
613
|
-
// type: 'number'
|
|
614
|
-
// }, {
|
|
615
|
-
// type: 'null'
|
|
616
|
-
// }]
|
|
617
|
-
// }
|
|
770
|
+
// TypeBox
|
|
618
771
|
|
|
619
|
-
|
|
620
|
-
```
|
|
772
|
+
const T0 = Type.Extends(Type.String(), Type.Number(), Type.Literal(true), Type.Literal(false))
|
|
621
773
|
|
|
622
|
-
|
|
774
|
+
const T1 = Type.Extract(Type.Union([Type.String(), Type.Number()]), Type.Number())
|
|
623
775
|
|
|
624
|
-
|
|
776
|
+
const T2 = Type.Exclude(Type.Union([Type.String(), Type.Number()]), Type.Number())
|
|
625
777
|
|
|
626
|
-
Use the conditional module to create [Conditional Types](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html). This module implements TypeScript's structural equivalence checks to enable TypeBox types to be conditionally inferred at runtime. This module also provides the [Extract](https://www.typescriptlang.org/docs/handbook/utility-types.html#extracttype-union) and [Exclude](https://www.typescriptlang.org/docs/handbook/utility-types.html#excludeuniontype-excludedmembers) utility types which are expressed as conditional types in TypeScript.
|
|
627
778
|
|
|
628
|
-
|
|
779
|
+
type T0 = Static<typeof T0> // type T0 = false
|
|
629
780
|
|
|
630
|
-
|
|
631
|
-
|
|
781
|
+
type T1 = Static<typeof T1> // type T1 = number
|
|
782
|
+
|
|
783
|
+
type T2 = Static<typeof T2> // type T2 = string
|
|
632
784
|
```
|
|
633
|
-
|
|
785
|
+
|
|
786
|
+
<a name='types-template-literal'></a>
|
|
787
|
+
|
|
788
|
+
### Template Literal Types
|
|
789
|
+
|
|
790
|
+
Template Literal types are supported with `Type.TemplateLiteral`
|
|
634
791
|
|
|
635
792
|
```typescript
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
793
|
+
// TypeScript
|
|
794
|
+
|
|
795
|
+
type T = `option${'A'|'B'}` // type T = 'optionA' | 'optionB'
|
|
796
|
+
|
|
797
|
+
type R = Record<T, string> // type R = {
|
|
798
|
+
// optionA: string
|
|
799
|
+
// optionB: string
|
|
800
|
+
// }
|
|
801
|
+
|
|
802
|
+
// TypeBox
|
|
803
|
+
|
|
804
|
+
const T = Type.TemplateLiteral([ // const T = {
|
|
805
|
+
Type.Literal('option'), // pattern: '^option(A|B)$',
|
|
806
|
+
Type.Union([ // type: 'string'
|
|
807
|
+
Type.Literal('A'), // }
|
|
808
|
+
Type.Literal('B')
|
|
809
|
+
])
|
|
810
|
+
])
|
|
811
|
+
|
|
812
|
+
const R = Type.Record(T, Type.String()) // const R = {
|
|
813
|
+
// type: 'object',
|
|
814
|
+
// required: ['optionA', 'optionB'],
|
|
815
|
+
// properties: {
|
|
816
|
+
// optionA: {
|
|
817
|
+
// type: 'string'
|
|
818
|
+
// },
|
|
819
|
+
// optionB: {
|
|
820
|
+
// type: 'string'
|
|
821
|
+
// }
|
|
822
|
+
// }
|
|
823
|
+
// }
|
|
824
|
+
|
|
825
|
+
type T = Static<typeof T> // type T = 'optionA' | 'optionB'
|
|
826
|
+
|
|
827
|
+
type R = Static<typeof R> // type R = {
|
|
828
|
+
// optionA: string
|
|
829
|
+
// optionB: string
|
|
830
|
+
// }
|
|
673
831
|
```
|
|
674
832
|
|
|
675
833
|
<a name='types-unsafe'></a>
|
|
676
834
|
|
|
677
835
|
### Unsafe
|
|
678
836
|
|
|
679
|
-
Use `Type.Unsafe
|
|
837
|
+
Use `Type.Unsafe` to create custom schematics with user defined inference rules.
|
|
680
838
|
|
|
681
839
|
```typescript
|
|
682
840
|
const T = Type.Unsafe<string>({ type: 'number' }) // const T = {
|
|
@@ -686,16 +844,12 @@ const T = Type.Unsafe<string>({ type: 'number' }) // const T = {
|
|
|
686
844
|
type T = Static<typeof T> // type T = string
|
|
687
845
|
```
|
|
688
846
|
|
|
689
|
-
|
|
847
|
+
The `Type.Unsafe` type can be useful to express specific OpenAPI schema representations.
|
|
690
848
|
|
|
691
849
|
```typescript
|
|
692
850
|
import { Type, Static, TSchema } from '@sinclair/typebox'
|
|
693
851
|
|
|
694
|
-
//--------------------------------------------------------------------------------------------
|
|
695
|
-
//
|
|
696
852
|
// Nullable<T>
|
|
697
|
-
//
|
|
698
|
-
//--------------------------------------------------------------------------------------------
|
|
699
853
|
|
|
700
854
|
function Nullable<T extends TSchema>(schema: T) {
|
|
701
855
|
return Type.Unsafe<Static<T> | null>({ ...schema, nullable: true })
|
|
@@ -708,12 +862,7 @@ const T = Nullable(Type.String()) // const T = {
|
|
|
708
862
|
|
|
709
863
|
type T = Static<typeof T> // type T = string | null
|
|
710
864
|
|
|
711
|
-
|
|
712
|
-
//--------------------------------------------------------------------------------------------
|
|
713
|
-
//
|
|
714
865
|
// StringEnum<string[]>
|
|
715
|
-
//
|
|
716
|
-
//--------------------------------------------------------------------------------------------
|
|
717
866
|
|
|
718
867
|
function StringEnum<T extends string[]>(values: [...T]) {
|
|
719
868
|
return Type.Unsafe<T[number]>({ type: 'string', enum: values })
|
|
@@ -730,10 +879,10 @@ type T = Static<typeof T> // type T = 'A' | 'B' | 'C'
|
|
|
730
879
|
|
|
731
880
|
### Guards
|
|
732
881
|
|
|
733
|
-
|
|
882
|
+
TypeBox provides a `TypeGuard` module that can be used for reflection and asserting values as types.
|
|
734
883
|
|
|
735
884
|
```typescript
|
|
736
|
-
import { TypeGuard } from '@sinclair/typebox
|
|
885
|
+
import { Type, TypeGuard } from '@sinclair/typebox'
|
|
737
886
|
|
|
738
887
|
const T = Type.String()
|
|
739
888
|
|
|
@@ -747,7 +896,7 @@ if(TypeGuard.TString(T)) {
|
|
|
747
896
|
|
|
748
897
|
### Strict
|
|
749
898
|
|
|
750
|
-
TypeBox schemas contain the `Kind` and `Modifier` symbol properties. These properties are
|
|
899
|
+
TypeBox schemas contain the `Kind` and `Modifier` symbol properties. These properties are used for type composition and reflection. These properties are not strictly valid JSON schema; so in some cases it may be desirable to omit them. TypeBox provides a `Type.Strict` function that will omit these properties if necessary.
|
|
751
900
|
|
|
752
901
|
```typescript
|
|
753
902
|
const T = Type.Object({ // const T = {
|
|
@@ -776,7 +925,7 @@ const U = Type.Strict(T) // const U = {
|
|
|
776
925
|
|
|
777
926
|
## Values
|
|
778
927
|
|
|
779
|
-
TypeBox
|
|
928
|
+
TypeBox provides an optional utility module that can be used to perform common operations on JavaScript values. This module includes functionality to create, check and cast values from types as well as check equality, clone, diff and patch JavaScript values. This module is provided via optional import.
|
|
780
929
|
|
|
781
930
|
```typescript
|
|
782
931
|
import { Value } from '@sinclair/typebox/value'
|
|
@@ -786,7 +935,7 @@ import { Value } from '@sinclair/typebox/value'
|
|
|
786
935
|
|
|
787
936
|
### Create
|
|
788
937
|
|
|
789
|
-
Use the Create function to create a value from a
|
|
938
|
+
Use the Create function to create a value from a type. TypeBox will use default values if specified.
|
|
790
939
|
|
|
791
940
|
```typescript
|
|
792
941
|
const T = Type.Object({ x: Type.Number(), y: Type.Number({ default: 42 }) })
|
|
@@ -816,6 +965,20 @@ const T = Type.Object({ x: Type.Number() })
|
|
|
816
965
|
const R = Value.Check(T, { x: 1 }) // const R = true
|
|
817
966
|
```
|
|
818
967
|
|
|
968
|
+
<a name='values-convert'></a>
|
|
969
|
+
|
|
970
|
+
### Convert
|
|
971
|
+
|
|
972
|
+
Use the Convert function to convert a value into its target type if a reasonable conversion is possible.
|
|
973
|
+
|
|
974
|
+
```typescript
|
|
975
|
+
const T = Type.Object({ x: Type.Number() })
|
|
976
|
+
|
|
977
|
+
const R1 = Value.Convert(T, { x: '3.14' }) // const R1 = { x: 3.14 }
|
|
978
|
+
|
|
979
|
+
const R2 = Value.Convert(T, { x: 'not a number' }) // const R2 = { x: 'not a number' }
|
|
980
|
+
```
|
|
981
|
+
|
|
819
982
|
<a name='values-cast'></a>
|
|
820
983
|
|
|
821
984
|
### Cast
|
|
@@ -891,7 +1054,6 @@ const E = Value.Diff(A, B) // const E = [
|
|
|
891
1054
|
const C = Value.Patch<typeof B>(A, E) // const C = { x: 3 }
|
|
892
1055
|
```
|
|
893
1056
|
|
|
894
|
-
|
|
895
1057
|
<a name='values-errors'></a>
|
|
896
1058
|
|
|
897
1059
|
### Errors
|
|
@@ -914,34 +1076,60 @@ const R = [...Value.Errors(T, { x: '42' })] // const R = [{
|
|
|
914
1076
|
// }]
|
|
915
1077
|
```
|
|
916
1078
|
|
|
1079
|
+
<a name='values-mutate'></a>
|
|
1080
|
+
|
|
1081
|
+
### Mutate
|
|
1082
|
+
|
|
1083
|
+
Use the Mutate function to perform a deep mutable value assignment while retaining internal references.
|
|
1084
|
+
|
|
1085
|
+
```typescript
|
|
1086
|
+
const Y = { z: 1 } // const Y = { z: 1 }
|
|
1087
|
+
|
|
1088
|
+
const X = { y: Y } // const X = { y: { z: 1 } }
|
|
1089
|
+
|
|
1090
|
+
const A = { x: X } // const A = { x: { y: { z: 1 } } }
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
Value.Mutate(A, { x: { y: { z: 2 } } }) // const A' = { x: { y: { z: 2 } } }
|
|
1094
|
+
|
|
1095
|
+
const R0 = A.x.y.z === 2 // const R0 = 2
|
|
1096
|
+
|
|
1097
|
+
const R1 = A.x.y === Y // const R1 = true
|
|
1098
|
+
|
|
1099
|
+
const R2 = A.x === X // const R2 = true
|
|
1100
|
+
```
|
|
1101
|
+
|
|
917
1102
|
<a name='values-pointer'></a>
|
|
918
1103
|
|
|
919
1104
|
### Pointer
|
|
920
1105
|
|
|
921
|
-
Use ValuePointer to perform mutable updates on existing values using [RFC6901](https://www.rfc-editor.org/rfc/rfc6901)
|
|
1106
|
+
Use ValuePointer to perform mutable updates on existing values using [RFC6901](https://www.rfc-editor.org/rfc/rfc6901) JSON Pointers.
|
|
922
1107
|
|
|
923
1108
|
```typescript
|
|
924
1109
|
import { ValuePointer } from '@sinclair/typebox/value'
|
|
925
1110
|
|
|
926
1111
|
const A = { x: 0, y: 0, z: 0 }
|
|
927
1112
|
|
|
928
|
-
ValuePointer.Set(A, '/x', 1) // const A = { x: 1, y: 0, z: 0 }
|
|
929
|
-
|
|
930
|
-
ValuePointer.Set(A, '/
|
|
1113
|
+
ValuePointer.Set(A, '/x', 1) // const A' = { x: 1, y: 0, z: 0 }
|
|
1114
|
+
|
|
1115
|
+
ValuePointer.Set(A, '/y', 1) // const A' = { x: 1, y: 1, z: 0 }
|
|
1116
|
+
|
|
1117
|
+
ValuePointer.Set(A, '/z', 1) // const A' = { x: 1, y: 1, z: 1 }
|
|
931
1118
|
```
|
|
1119
|
+
|
|
932
1120
|
<a name='typecheck'></a>
|
|
933
1121
|
|
|
934
1122
|
## TypeCheck
|
|
935
1123
|
|
|
936
|
-
TypeBox
|
|
1124
|
+
TypeBox types target JSON Schema draft 6 so are compatible with any validator that supports this specification. TypeBox also provides a built in type checking compiler designed specifically for high performance compilation and value assertion.
|
|
937
1125
|
|
|
938
|
-
The following sections detail using
|
|
1126
|
+
The following sections detail using Ajv and TypeBox's compiler infrastructure.
|
|
939
1127
|
|
|
940
1128
|
<a name='typecheck-ajv'></a>
|
|
941
1129
|
|
|
942
1130
|
## Ajv
|
|
943
1131
|
|
|
944
|
-
The following shows the recommended setup for Ajv.
|
|
1132
|
+
The following shows the recommended setup for Ajv.
|
|
945
1133
|
|
|
946
1134
|
```bash
|
|
947
1135
|
$ npm install ajv ajv-formats --save
|
|
@@ -982,7 +1170,7 @@ const R = C({ x: 1, y: 2, z: 3 }) // const R = true
|
|
|
982
1170
|
|
|
983
1171
|
### TypeCompiler
|
|
984
1172
|
|
|
985
|
-
The TypeCompiler is a
|
|
1173
|
+
The TypeBox TypeCompiler is a high performance JIT compiler that transforms TypeBox types into optimized JavaScript validation routines. The compiler is tuned for fast compilation as well as fast value assertion. It is designed to serve as a validation backend that can be integrated into larger applications; but can also be used as a general purpose validator.
|
|
986
1174
|
|
|
987
1175
|
The TypeCompiler is provided as an optional import.
|
|
988
1176
|
|
|
@@ -1002,7 +1190,7 @@ const C = TypeCompiler.Compile(Type.Object({ // const C: TypeCheck<TObje
|
|
|
1002
1190
|
const R = C.Check({ x: 1, y: 2, z: 3 }) // const R = true
|
|
1003
1191
|
```
|
|
1004
1192
|
|
|
1005
|
-
Use `Errors(...)` to
|
|
1193
|
+
Use the `Errors(...)` function to produce diagnostic errors for a value. The `Errors(...)` function will return an iterator that if enumerated; will perform an exhaustive check across the entire value and yield any error found. For performance, this function should only be called after failed `Check(...)`. Applications may also choose to yield only the first value to avoid exhaustive error generation.
|
|
1006
1194
|
|
|
1007
1195
|
```typescript
|
|
1008
1196
|
const C = TypeCompiler.Compile(Type.Object({ // const C: TypeCheck<TObject<{
|
|
@@ -1047,7 +1235,7 @@ console.log(C.Code()) // return function check(va
|
|
|
1047
1235
|
|
|
1048
1236
|
## TypeSystem
|
|
1049
1237
|
|
|
1050
|
-
TypeBox
|
|
1238
|
+
The TypeBox TypeSystem module provides functionality to define types above and beyond the Standard and Extended type sets as well as control various assertion polices. Configurations made to the TypeSystem module are observed by both `TypeCompiler` and `Value` modules.
|
|
1051
1239
|
|
|
1052
1240
|
The TypeSystem module is provided as an optional import.
|
|
1053
1241
|
|
|
@@ -1059,78 +1247,69 @@ import { TypeSystem } from '@sinclair/typebox/system'
|
|
|
1059
1247
|
|
|
1060
1248
|
### Types
|
|
1061
1249
|
|
|
1062
|
-
Use the `
|
|
1250
|
+
Use the `Type(...)` function to create a custom type. This function will return a type factory function that can be used to construct the type. The following creates a Point type.
|
|
1063
1251
|
|
|
1064
1252
|
```typescript
|
|
1065
|
-
|
|
1066
|
-
//
|
|
1067
|
-
// Use TypeSystem.CreateType(...) to define and return a type factory function
|
|
1068
|
-
//
|
|
1069
|
-
//--------------------------------------------------------------------------------------------
|
|
1253
|
+
type PointOptions = { } // The Type Options
|
|
1070
1254
|
|
|
1071
|
-
type
|
|
1255
|
+
type PointType = { x: number, y: number } // The Static<T> Type
|
|
1072
1256
|
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
}
|
|
1081
|
-
)
|
|
1257
|
+
const Point = TypeSystem.Type<PointType, PointOptions>('Point', (options, value) => {
|
|
1258
|
+
return (
|
|
1259
|
+
typeof value === 'object' && value !== null &&
|
|
1260
|
+
typeof value.x === 'number' &&
|
|
1261
|
+
typeof value.y === 'number'
|
|
1262
|
+
)
|
|
1263
|
+
})
|
|
1082
1264
|
|
|
1083
|
-
|
|
1084
|
-
//
|
|
1085
|
-
// Use the custom type like any other type
|
|
1086
|
-
//
|
|
1087
|
-
//--------------------------------------------------------------------------------------------
|
|
1265
|
+
const T = Point()
|
|
1088
1266
|
|
|
1089
|
-
|
|
1090
|
-
// minimum: 10n,
|
|
1091
|
-
// maximum: 20n,
|
|
1092
|
-
// [Symbol(TypeBox.Kind)]: 'BigNumber'
|
|
1093
|
-
// }
|
|
1267
|
+
type T = Static<typeof T> // type T = { x: number, y: number }
|
|
1094
1268
|
|
|
1095
|
-
const
|
|
1096
|
-
const X = C.Check(15n) // const X = true
|
|
1097
|
-
const Y = C.Check(5n) // const Y = false
|
|
1098
|
-
const Z = C.Check(25n) // const Z = false
|
|
1269
|
+
const R = Value.Check(T, { x: 1, y: 2 }) // const R = true
|
|
1099
1270
|
```
|
|
1100
1271
|
|
|
1101
1272
|
<a name='typesystem-formats'></a>
|
|
1102
1273
|
|
|
1103
1274
|
### Formats
|
|
1104
1275
|
|
|
1105
|
-
Use the `
|
|
1276
|
+
Use the `Format(...)` function to create a custom string format. The following creates a format that checks for lowercase strings.
|
|
1106
1277
|
|
|
1107
1278
|
```typescript
|
|
1108
|
-
|
|
1109
|
-
//
|
|
1110
|
-
// Use TypeSystem.CreateFormat(...) to define a custom string format
|
|
1111
|
-
//
|
|
1112
|
-
//--------------------------------------------------------------------------------------------
|
|
1279
|
+
TypeSystem.Format('lowercase', value => value === value.toLowerCase()) // format should be lowercase
|
|
1113
1280
|
|
|
1114
|
-
|
|
1281
|
+
const T = Type.String({ format: 'lowercase' })
|
|
1115
1282
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1283
|
+
const A = Value.Check(T, 'Hello') // const A = false
|
|
1284
|
+
|
|
1285
|
+
const B = Value.Check(T, 'hello') // const B = true
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
<a name='typesystem-policies'></a>
|
|
1289
|
+
|
|
1290
|
+
### Policies
|
|
1291
|
+
|
|
1292
|
+
TypeBox validates using JSON Schema assertion policies by default. It is possible to override these policies and have TypeBox assert using TypeScript policies. The following overrides are available.
|
|
1293
|
+
|
|
1294
|
+
```typescript
|
|
1295
|
+
// Allow arrays to validate as object types (default is false)
|
|
1119
1296
|
//
|
|
1120
|
-
|
|
1297
|
+
// const A: {} = [] - allowed in TS
|
|
1121
1298
|
|
|
1122
|
-
|
|
1299
|
+
TypeSystem.AllowArrayObjects = true
|
|
1123
1300
|
|
|
1124
|
-
|
|
1301
|
+
// Allow numeric values to be NaN or + or - Infinity (default is false)
|
|
1302
|
+
//
|
|
1303
|
+
// const A: number = NaN - allowed in TS
|
|
1125
1304
|
|
|
1126
|
-
|
|
1305
|
+
TypeSystem.AllowNaN = true
|
|
1127
1306
|
```
|
|
1128
1307
|
|
|
1129
1308
|
<a name='benchmark'></a>
|
|
1130
1309
|
|
|
1131
1310
|
## Benchmark
|
|
1132
1311
|
|
|
1133
|
-
This project maintains a set of benchmarks that measure Ajv, Value and TypeCompiler compilation and validation performance. These benchmarks can be run locally by cloning this repository and running `npm run benchmark`. The results below show for Ajv version 8.
|
|
1312
|
+
This project maintains a set of benchmarks that measure Ajv, Value and TypeCompiler compilation and validation performance. These benchmarks can be run locally by cloning this repository and running `npm run benchmark`. The results below show for Ajv version 8.12.0.
|
|
1134
1313
|
|
|
1135
1314
|
For additional comparative benchmarks, please refer to [typescript-runtime-type-benchmarks](https://moltar.github.io/typescript-runtime-type-benchmarks/).
|
|
1136
1315
|
|
|
@@ -1141,33 +1320,39 @@ For additional comparative benchmarks, please refer to [typescript-runtime-type-
|
|
|
1141
1320
|
This benchmark measures compilation performance for varying types. You can review this benchmark [here](https://github.com/sinclairzx81/typebox/blob/master/benchmark/measurement/module/compile.ts).
|
|
1142
1321
|
|
|
1143
1322
|
```typescript
|
|
1144
|
-
|
|
1145
|
-
│
|
|
1146
|
-
|
|
1147
|
-
│
|
|
1148
|
-
│
|
|
1149
|
-
│
|
|
1150
|
-
│
|
|
1151
|
-
│
|
|
1152
|
-
│
|
|
1153
|
-
│
|
|
1154
|
-
│
|
|
1155
|
-
│
|
|
1156
|
-
│
|
|
1157
|
-
│
|
|
1158
|
-
│
|
|
1159
|
-
│
|
|
1160
|
-
│
|
|
1161
|
-
│
|
|
1162
|
-
│
|
|
1163
|
-
│
|
|
1164
|
-
│
|
|
1165
|
-
│
|
|
1166
|
-
│
|
|
1167
|
-
│
|
|
1168
|
-
│
|
|
1169
|
-
│
|
|
1170
|
-
|
|
1323
|
+
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
1324
|
+
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
1325
|
+
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
1326
|
+
│ Literal_String │ 1000 │ ' 257 ms' │ ' 8 ms' │ ' 32.13 x' │
|
|
1327
|
+
│ Literal_Number │ 1000 │ ' 203 ms' │ ' 4 ms' │ ' 50.75 x' │
|
|
1328
|
+
│ Literal_Boolean │ 1000 │ ' 183 ms' │ ' 4 ms' │ ' 45.75 x' │
|
|
1329
|
+
│ Primitive_Number │ 1000 │ ' 174 ms' │ ' 8 ms' │ ' 21.75 x' │
|
|
1330
|
+
│ Primitive_String │ 1000 │ ' 158 ms' │ ' 9 ms' │ ' 17.56 x' │
|
|
1331
|
+
│ Primitive_String_Pattern │ 1000 │ ' 213 ms' │ ' 13 ms' │ ' 16.38 x' │
|
|
1332
|
+
│ Primitive_Boolean │ 1000 │ ' 136 ms' │ ' 6 ms' │ ' 22.67 x' │
|
|
1333
|
+
│ Primitive_Null │ 1000 │ ' 144 ms' │ ' 6 ms' │ ' 24.00 x' │
|
|
1334
|
+
│ Object_Unconstrained │ 1000 │ ' 1176 ms' │ ' 38 ms' │ ' 30.95 x' │
|
|
1335
|
+
│ Object_Constrained │ 1000 │ ' 1181 ms' │ ' 31 ms' │ ' 38.10 x' │
|
|
1336
|
+
│ Object_Vector3 │ 1000 │ ' 387 ms' │ ' 8 ms' │ ' 48.38 x' │
|
|
1337
|
+
│ Object_Box3D │ 1000 │ ' 1693 ms' │ ' 25 ms' │ ' 67.72 x' │
|
|
1338
|
+
│ Tuple_Primitive │ 1000 │ ' 470 ms' │ ' 15 ms' │ ' 31.33 x' │
|
|
1339
|
+
│ Tuple_Object │ 1000 │ ' 1206 ms' │ ' 17 ms' │ ' 70.94 x' │
|
|
1340
|
+
│ Composite_Intersect │ 1000 │ ' 567 ms' │ ' 20 ms' │ ' 28.35 x' │
|
|
1341
|
+
│ Composite_Union │ 1000 │ ' 515 ms' │ ' 21 ms' │ ' 24.52 x' │
|
|
1342
|
+
│ Math_Vector4 │ 1000 │ ' 787 ms' │ ' 10 ms' │ ' 78.70 x' │
|
|
1343
|
+
│ Math_Matrix4 │ 1000 │ ' 386 ms' │ ' 8 ms' │ ' 48.25 x' │
|
|
1344
|
+
│ Array_Primitive_Number │ 1000 │ ' 349 ms' │ ' 7 ms' │ ' 49.86 x' │
|
|
1345
|
+
│ Array_Primitive_String │ 1000 │ ' 336 ms' │ ' 4 ms' │ ' 84.00 x' │
|
|
1346
|
+
│ Array_Primitive_Boolean │ 1000 │ ' 284 ms' │ ' 3 ms' │ ' 94.67 x' │
|
|
1347
|
+
│ Array_Object_Unconstrained │ 1000 │ ' 1704 ms' │ ' 19 ms' │ ' 89.68 x' │
|
|
1348
|
+
│ Array_Object_Constrained │ 1000 │ ' 1456 ms' │ ' 18 ms' │ ' 80.89 x' │
|
|
1349
|
+
│ Array_Tuple_Primitive │ 1000 │ ' 792 ms' │ ' 15 ms' │ ' 52.80 x' │
|
|
1350
|
+
│ Array_Tuple_Object │ 1000 │ ' 1552 ms' │ ' 17 ms' │ ' 91.29 x' │
|
|
1351
|
+
│ Array_Composite_Intersect │ 1000 │ ' 744 ms' │ ' 18 ms' │ ' 41.33 x' │
|
|
1352
|
+
│ Array_Composite_Union │ 1000 │ ' 783 ms' │ ' 15 ms' │ ' 52.20 x' │
|
|
1353
|
+
│ Array_Math_Vector4 │ 1000 │ ' 1093 ms' │ ' 14 ms' │ ' 78.07 x' │
|
|
1354
|
+
│ Array_Math_Matrix4 │ 1000 │ ' 684 ms' │ ' 6 ms' │ ' 114.00 x' │
|
|
1355
|
+
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
1171
1356
|
```
|
|
1172
1357
|
|
|
1173
1358
|
<a name='benchmark-validate'></a>
|
|
@@ -1177,35 +1362,41 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
1177
1362
|
This benchmark measures validation performance for varying types. You can review this benchmark [here](https://github.com/sinclairzx81/typebox/blob/master/benchmark/measurement/module/check.ts).
|
|
1178
1363
|
|
|
1179
1364
|
```typescript
|
|
1180
|
-
|
|
1181
|
-
│
|
|
1182
|
-
|
|
1183
|
-
│
|
|
1184
|
-
│
|
|
1185
|
-
│
|
|
1186
|
-
│
|
|
1187
|
-
│
|
|
1188
|
-
│
|
|
1189
|
-
│
|
|
1190
|
-
│
|
|
1191
|
-
│
|
|
1192
|
-
│
|
|
1193
|
-
│
|
|
1194
|
-
│
|
|
1195
|
-
│
|
|
1196
|
-
│
|
|
1197
|
-
│
|
|
1198
|
-
│
|
|
1199
|
-
│
|
|
1200
|
-
│
|
|
1201
|
-
│
|
|
1202
|
-
│
|
|
1203
|
-
│
|
|
1204
|
-
│
|
|
1205
|
-
│
|
|
1206
|
-
│
|
|
1207
|
-
│
|
|
1208
|
-
|
|
1365
|
+
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
|
|
1366
|
+
│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
|
|
1367
|
+
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
|
|
1368
|
+
│ Literal_String │ 1000000 │ ' 27 ms' │ ' 6 ms' │ ' 5 ms' │ ' 1.20 x' │
|
|
1369
|
+
│ Literal_Number │ 1000000 │ ' 23 ms' │ ' 21 ms' │ ' 11 ms' │ ' 1.91 x' │
|
|
1370
|
+
│ Literal_Boolean │ 1000000 │ ' 21 ms' │ ' 20 ms' │ ' 10 ms' │ ' 2.00 x' │
|
|
1371
|
+
│ Primitive_Number │ 1000000 │ ' 26 ms' │ ' 19 ms' │ ' 11 ms' │ ' 1.73 x' │
|
|
1372
|
+
│ Primitive_String │ 1000000 │ ' 25 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
|
|
1373
|
+
│ Primitive_String_Pattern │ 1000000 │ ' 155 ms' │ ' 49 ms' │ ' 43 ms' │ ' 1.14 x' │
|
|
1374
|
+
│ Primitive_Boolean │ 1000000 │ ' 23 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
|
|
1375
|
+
│ Primitive_Null │ 1000000 │ ' 24 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
|
|
1376
|
+
│ Object_Unconstrained │ 1000000 │ ' 804 ms' │ ' 35 ms' │ ' 28 ms' │ ' 1.25 x' │
|
|
1377
|
+
│ Object_Constrained │ 1000000 │ ' 1041 ms' │ ' 55 ms' │ ' 41 ms' │ ' 1.34 x' │
|
|
1378
|
+
│ Object_Vector3 │ 1000000 │ ' 380 ms' │ ' 26 ms' │ ' 20 ms' │ ' 1.30 x' │
|
|
1379
|
+
│ Object_Box3D │ 1000000 │ ' 1785 ms' │ ' 65 ms' │ ' 52 ms' │ ' 1.25 x' │
|
|
1380
|
+
│ Object_Recursive │ 1000000 │ ' 4984 ms' │ ' 396 ms' │ ' 114 ms' │ ' 3.47 x' │
|
|
1381
|
+
│ Tuple_Primitive │ 1000000 │ ' 168 ms' │ ' 24 ms' │ ' 16 ms' │ ' 1.50 x' │
|
|
1382
|
+
│ Tuple_Object │ 1000000 │ ' 673 ms' │ ' 30 ms' │ ' 26 ms' │ ' 1.15 x' │
|
|
1383
|
+
│ Composite_Intersect │ 1000000 │ ' 751 ms' │ ' 28 ms' │ ' 20 ms' │ ' 1.40 x' │
|
|
1384
|
+
│ Composite_Union │ 1000000 │ ' 489 ms' │ ' 24 ms' │ ' 16 ms' │ ' 1.50 x' │
|
|
1385
|
+
│ Math_Vector4 │ 1000000 │ ' 259 ms' │ ' 23 ms' │ ' 13 ms' │ ' 1.77 x' │
|
|
1386
|
+
│ Math_Matrix4 │ 1000000 │ ' 1002 ms' │ ' 40 ms' │ ' 30 ms' │ ' 1.33 x' │
|
|
1387
|
+
│ Array_Primitive_Number │ 1000000 │ ' 252 ms' │ ' 22 ms' │ ' 15 ms' │ ' 1.47 x' │
|
|
1388
|
+
│ Array_Primitive_String │ 1000000 │ ' 227 ms' │ ' 22 ms' │ ' 18 ms' │ ' 1.22 x' │
|
|
1389
|
+
│ Array_Primitive_Boolean │ 1000000 │ ' 150 ms' │ ' 23 ms' │ ' 22 ms' │ ' 1.05 x' │
|
|
1390
|
+
│ Array_Object_Unconstrained │ 1000000 │ ' 4754 ms' │ ' 71 ms' │ ' 64 ms' │ ' 1.11 x' │
|
|
1391
|
+
│ Array_Object_Constrained │ 1000000 │ ' 4787 ms' │ ' 142 ms' │ ' 123 ms' │ ' 1.15 x' │
|
|
1392
|
+
│ Array_Object_Recursive │ 1000000 │ ' 19088 ms' │ ' 1735 ms' │ ' 314 ms' │ ' 5.53 x' │
|
|
1393
|
+
│ Array_Tuple_Primitive │ 1000000 │ ' 650 ms' │ ' 41 ms' │ ' 31 ms' │ ' 1.32 x' │
|
|
1394
|
+
│ Array_Tuple_Object │ 1000000 │ ' 2770 ms' │ ' 67 ms' │ ' 55 ms' │ ' 1.22 x' │
|
|
1395
|
+
│ Array_Composite_Intersect │ 1000000 │ ' 2693 ms' │ ' 50 ms' │ ' 39 ms' │ ' 1.28 x' │
|
|
1396
|
+
│ Array_Composite_Union │ 1000000 │ ' 1982 ms' │ ' 72 ms' │ ' 33 ms' │ ' 2.18 x' │
|
|
1397
|
+
│ Array_Math_Vector4 │ 1000000 │ ' 1068 ms' │ ' 40 ms' │ ' 26 ms' │ ' 1.54 x' │
|
|
1398
|
+
│ Array_Math_Matrix4 │ 1000000 │ ' 4609 ms' │ ' 115 ms' │ ' 88 ms' │ ' 1.31 x' │
|
|
1399
|
+
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
|
|
1209
1400
|
```
|
|
1210
1401
|
|
|
1211
1402
|
<a name='benchmark-compression'></a>
|
|
@@ -1218,15 +1409,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1218
1409
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1219
1410
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1220
1411
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1221
|
-
│ typebox/compiler │ '
|
|
1222
|
-
│ typebox/
|
|
1223
|
-
│ typebox/
|
|
1224
|
-
│ typebox/
|
|
1225
|
-
│ typebox
|
|
1226
|
-
│ typebox/hash │ ' 4.2 kb' │ ' 1.8 kb' │ '2.30 x' │
|
|
1227
|
-
│ typebox/system │ ' 14.0 kb' │ ' 7.1 kb' │ '1.96 x' │
|
|
1228
|
-
│ typebox/value │ ' 90.0 kb' │ ' 41.8 kb' │ '2.15 x' │
|
|
1229
|
-
│ typebox │ ' 12.0 kb' │ ' 6.4 kb' │ '1.89 x' │
|
|
1412
|
+
│ typebox/compiler │ '124.3 kb' │ ' 55.7 kb' │ '2.23 x' │
|
|
1413
|
+
│ typebox/errors │ '107.8 kb' │ ' 47.9 kb' │ '2.25 x' │
|
|
1414
|
+
│ typebox/system │ ' 73.3 kb' │ ' 30.2 kb' │ '2.43 x' │
|
|
1415
|
+
│ typebox/value │ '170.7 kb' │ ' 74.2 kb' │ '2.30 x' │
|
|
1416
|
+
│ typebox │ ' 72.0 kb' │ ' 29.7 kb' │ '2.43 x' │
|
|
1230
1417
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1231
1418
|
```
|
|
1232
1419
|
|