wrangler 0.0.0-e64812e → 0.0.0-e665ccc3
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/README.md +24 -4
- package/bin/wrangler.js +170 -62
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +1643 -83
- package/package.json +198 -152
- package/src/__tests__/access.test.ts +25 -0
- package/src/__tests__/api-dev.test.ts +238 -0
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +102 -0
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +30 -24
- package/src/__tests__/configuration.test.ts +4506 -3363
- package/src/__tests__/constellation.test.ts +371 -0
- package/src/__tests__/d1/d1.test.ts +82 -0
- package/src/__tests__/d1/execute.test.ts +66 -0
- package/src/__tests__/d1/migrate.test.ts +257 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +272 -0
- package/src/__tests__/deployments.test.ts +369 -0
- package/src/__tests__/dev.test.tsx +1589 -952
- package/src/__tests__/generate.test.ts +237 -0
- package/src/__tests__/get-host-from-url.test.ts +16 -0
- package/src/__tests__/guess-worker-format.test.ts +103 -68
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +24 -24
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-console.ts +64 -39
- package/src/__tests__/helpers/mock-dialogs.ts +88 -79
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +11 -0
- package/src/__tests__/helpers/mock-http-server.ts +30 -30
- package/src/__tests__/helpers/mock-istty.ts +65 -18
- package/src/__tests__/helpers/mock-known-routes.ts +12 -0
- package/src/__tests__/helpers/mock-kv.ts +41 -28
- package/src/__tests__/helpers/mock-oauth-flow.ts +241 -233
- package/src/__tests__/helpers/mock-process.ts +34 -0
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
- package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +160 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +81 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +60 -0
- package/src/__tests__/helpers/msw/handlers/script.ts +56 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +52 -0
- package/src/__tests__/helpers/msw/handlers/zones.ts +20 -0
- package/src/__tests__/helpers/msw/index.ts +52 -0
- package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/run-in-tmp.ts +27 -28
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +11 -0
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
- package/src/__tests__/helpers/write-worker-source.ts +16 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +142 -109
- package/src/__tests__/index.test.ts +262 -236
- package/src/__tests__/init.test.ts +3167 -1605
- package/src/__tests__/jest.setup.ts +152 -50
- package/src/__tests__/kv.test.ts +1789 -1471
- package/src/__tests__/logger.test.ts +167 -75
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +493 -0
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +816 -0
- package/src/__tests__/mtls-certificates.test.ts +589 -0
- package/src/__tests__/package-manager.test.ts +303 -303
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +528 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +110 -0
- package/src/__tests__/pages/project-upload.test.ts +500 -0
- package/src/__tests__/pages/publish.test.ts +2864 -0
- package/src/__tests__/pages-deployment-tail.test.ts +957 -0
- package/src/__tests__/parse.test.ts +358 -252
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +8736 -5355
- package/src/__tests__/pubsub.test.ts +496 -0
- package/src/__tests__/queues.test.ts +532 -0
- package/src/__tests__/r2.test.ts +369 -228
- package/src/__tests__/route.test.ts +18 -18
- package/src/__tests__/secret.test.ts +681 -469
- package/src/__tests__/tail.test.ts +866 -567
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/__tests__/traverse-module-graph.test.ts +220 -0
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +234 -0
- package/src/__tests__/user.test.ts +107 -120
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/version.test.ts +35 -0
- package/src/__tests__/whoami.test.tsx +165 -98
- package/src/__tests__/worker-namespace.test.ts +340 -0
- package/src/abort.d.ts +1 -1
- package/src/api/dev.ts +321 -0
- package/src/api/index.ts +11 -0
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +77 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +371 -0
- package/src/bundle-reporter.ts +68 -0
- package/src/bundle.ts +890 -161
- package/src/cfetch/index.ts +120 -83
- package/src/cfetch/internal.ts +210 -97
- package/src/cli.ts +23 -8
- package/src/config/config.ts +244 -196
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +562 -357
- package/src/config/index.ts +374 -196
- package/src/config/validation-helpers.ts +379 -357
- package/src/config/validation.ts +2197 -1367
- package/src/config-cache.ts +81 -41
- package/src/constellation/createProject.tsx +51 -0
- package/src/constellation/deleteProject.ts +51 -0
- package/src/constellation/deleteProjectModel.ts +68 -0
- package/src/constellation/index.ts +75 -0
- package/src/constellation/listCatalog.tsx +35 -0
- package/src/constellation/listModel.tsx +41 -0
- package/src/constellation/listProject.tsx +28 -0
- package/src/constellation/listRuntime.tsx +28 -0
- package/src/constellation/options.ts +17 -0
- package/src/constellation/types.ts +17 -0
- package/src/constellation/uploadModel.tsx +64 -0
- package/src/constellation/utils.ts +90 -0
- package/src/create-worker-preview.ts +250 -142
- package/src/create-worker-upload-form.ts +347 -238
- package/src/d1/backups.tsx +219 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +70 -0
- package/src/d1/delete.ts +53 -0
- package/src/d1/execute.tsx +357 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +100 -0
- package/src/d1/list.tsx +62 -0
- package/src/d1/migrations/apply.tsx +212 -0
- package/src/d1/migrations/create.tsx +79 -0
- package/src/d1/migrations/helpers.ts +169 -0
- package/src/d1/migrations/index.ts +3 -0
- package/src/d1/migrations/list.tsx +95 -0
- package/src/d1/migrations/options.ts +23 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/splitter.ts +161 -0
- package/src/d1/types.ts +25 -0
- package/src/d1/utils.ts +49 -0
- package/src/delete.ts +100 -0
- package/src/deployments.ts +368 -0
- package/src/deprecated/index.ts +144 -0
- package/src/dev/dev-vars.ts +20 -17
- package/src/dev/dev.tsx +538 -352
- package/src/dev/get-local-persistence-path.ts +31 -0
- package/src/dev/local.tsx +932 -298
- package/src/dev/remote.tsx +623 -215
- package/src/dev/start-server.ts +545 -0
- package/src/dev/use-esbuild.ts +194 -97
- package/src/dev/validate-dev-props.ts +40 -0
- package/src/dev-registry.ts +202 -0
- package/src/dev.tsx +934 -0
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +211 -0
- package/src/docs/helpers.ts +50 -0
- package/src/docs/index.ts +54 -0
- package/src/durable.ts +87 -87
- package/src/entry.ts +253 -231
- package/src/environment-variables/factory.ts +89 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/errors.ts +6 -6
- package/src/generate/index.ts +298 -0
- package/src/git-client.ts +135 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +84 -80
- package/src/index.ts +768 -0
- package/src/init.ts +1037 -0
- package/src/inspect.ts +816 -595
- package/src/intl-polyfill.d.ts +123 -123
- package/src/is-ci.ts +14 -0
- package/src/is-interactive.ts +16 -0
- package/src/jest.d.ts +4 -0
- package/src/kv/helpers.ts +433 -0
- package/src/kv/index.ts +594 -0
- package/src/logger.ts +100 -43
- package/src/metrics/index.ts +5 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +96 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +99 -0
- package/src/miniflare-cli/assets.ts +255 -0
- package/src/miniflare-cli/index.ts +202 -33
- package/src/miniflare-cli/request-context.ts +18 -18
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +290 -215
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/open-in-browser.ts +4 -6
- package/src/package-manager.ts +173 -128
- package/src/pages/build.ts +423 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/constants.ts +18 -0
- package/src/pages/deployment-tails.ts +281 -0
- package/src/pages/deployments.tsx +84 -0
- package/src/pages/dev.ts +734 -0
- package/src/pages/errors.ts +67 -0
- package/src/pages/functions/buildPlugin.ts +114 -0
- package/src/pages/functions/buildWorker.ts +350 -0
- package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes-consolidation.test.ts +250 -0
- package/src/pages/functions/routes-consolidation.ts +73 -0
- package/src/pages/functions/routes-transformation.test.ts +282 -0
- package/src/pages/functions/routes-transformation.ts +115 -0
- package/src/pages/functions/routes-validation.test.ts +403 -0
- package/src/pages/functions/routes-validation.ts +202 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/functions.ts +86 -0
- package/src/pages/hash.ts +13 -0
- package/src/pages/index.ts +102 -0
- package/src/pages/projects.tsx +159 -0
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +267 -0
- package/src/pages/types.ts +46 -0
- package/src/pages/upload.tsx +469 -0
- package/src/pages/utils.ts +23 -0
- package/src/parse.ts +232 -126
- package/src/paths.ts +53 -8
- package/src/proxy.ts +623 -394
- package/src/publish/index.ts +274 -0
- package/src/publish/publish.ts +1065 -0
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.ts +623 -0
- package/src/queues/cli/commands/consumer/add.ts +71 -0
- package/src/queues/cli/commands/consumer/index.ts +19 -0
- package/src/queues/cli/commands/consumer/remove.ts +31 -0
- package/src/queues/cli/commands/create.ts +25 -0
- package/src/queues/cli/commands/delete.ts +26 -0
- package/src/queues/cli/commands/index.ts +35 -0
- package/src/queues/cli/commands/list.ts +25 -0
- package/src/queues/client.ts +136 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +132 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +377 -0
- package/src/selfsigned.d.ts +23 -23
- package/src/sites.ts +484 -0
- package/src/tail/createTail.ts +415 -0
- package/src/tail/filters.ts +109 -111
- package/src/tail/index.ts +208 -296
- package/src/tail/printing.ts +116 -51
- package/src/traverse-module-graph.ts +54 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/update-check.ts +11 -11
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +39 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +2 -0
- package/src/user/user.ts +1234 -0
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/utils/render.ts +93 -0
- package/src/whoami.ts +135 -0
- package/src/worker.ts +205 -106
- package/src/yargs-types.ts +37 -0
- package/src/zones.ts +191 -0
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/checked-fetch.js +23 -0
- package/templates/d1-beta-facade.js +244 -0
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +19 -0
- package/templates/format-dev-errors.ts +34 -0
- package/templates/gitignore +1 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +62 -0
- package/templates/middleware/loader-modules.ts +84 -0
- package/templates/middleware/loader-sw.ts +233 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/new-worker-scheduled.js +3 -3
- package/templates/new-worker-scheduled.ts +15 -15
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +18 -15
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +12 -0
- package/templates/pages-template-plugin.ts +180 -0
- package/templates/pages-template-worker.ts +189 -0
- package/templates/serve-static-assets.ts +66 -0
- package/templates/service-bindings-module-facade.js +55 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +6 -103
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +1652 -0
- package/wrangler-dist/cli.js +137978 -110578
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/pages/functions/buildPlugin.ts +0 -105
- package/pages/functions/buildWorker.ts +0 -151
- package/pages/functions/filepath-routing.ts +0 -189
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -156
- package/pages/functions/template-plugin.ts +0 -147
- package/pages/functions/template-worker.ts +0 -143
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/__tests__/helpers/mock-cfetch.ts +0 -211
- package/src/__tests__/pages.test.ts +0 -754
- package/src/dialogs.tsx +0 -135
- package/src/environment-variables.ts +0 -35
- package/src/index.tsx +0 -2864
- package/src/kv.ts +0 -408
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/pages.tsx +0 -2038
- package/src/publish.ts +0 -583
- package/src/r2.ts +0 -50
- package/src/sites.tsx +0 -295
- package/src/user.tsx +0 -1203
- package/src/whoami.tsx +0 -70
- package/templates/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
package/src/config/validation.ts
CHANGED
|
@@ -2,36 +2,36 @@ import path from "node:path";
|
|
|
2
2
|
import TOML from "@iarna/toml";
|
|
3
3
|
import { Diagnostics } from "./diagnostics";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
deprecated,
|
|
6
|
+
experimental,
|
|
7
|
+
hasProperty,
|
|
8
|
+
inheritable,
|
|
9
|
+
isBoolean,
|
|
10
|
+
isObjectWith,
|
|
11
|
+
isOneOf,
|
|
12
|
+
isOptionalProperty,
|
|
13
|
+
isRequiredProperty,
|
|
14
|
+
isString,
|
|
15
|
+
isStringArray,
|
|
16
|
+
validateAdditionalProperties,
|
|
17
|
+
notInheritable,
|
|
18
|
+
validateOptionalProperty,
|
|
19
|
+
validateOptionalTypedArray,
|
|
20
|
+
validateRequiredProperty,
|
|
21
|
+
validateTypedArray,
|
|
22
|
+
all,
|
|
23
|
+
isMutuallyExclusiveWith,
|
|
24
|
+
inheritableInLegacyEnvironments,
|
|
25
|
+
appendEnvName,
|
|
26
|
+
getBindingNames,
|
|
27
|
+
isValidName,
|
|
28
28
|
} from "./validation-helpers";
|
|
29
29
|
import type { Config, DevConfig, RawConfig, RawDevConfig } from "./config";
|
|
30
30
|
import type {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
RawEnvironment,
|
|
32
|
+
DeprecatedUpload,
|
|
33
|
+
Environment,
|
|
34
|
+
Rule,
|
|
35
35
|
} from "./environment";
|
|
36
36
|
import type { ValidatorFn } from "./validation-helpers";
|
|
37
37
|
|
|
@@ -46,549 +46,679 @@ const ENGLISH = new Intl.ListFormat("en");
|
|
|
46
46
|
* Any errors or warnings from the validation are available in the returned `diagnostics` object.
|
|
47
47
|
*/
|
|
48
48
|
export function normalizeAndValidateConfig(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
rawConfig: RawConfig,
|
|
50
|
+
configPath: string | undefined,
|
|
51
|
+
args: unknown
|
|
52
52
|
): {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
config: Config;
|
|
54
|
+
diagnostics: Diagnostics;
|
|
55
55
|
} {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
56
|
+
const diagnostics = new Diagnostics(
|
|
57
|
+
`Processing ${
|
|
58
|
+
configPath ? path.relative(process.cwd(), configPath) : "wrangler"
|
|
59
|
+
} configuration:`
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
deprecated(
|
|
63
|
+
diagnostics,
|
|
64
|
+
rawConfig,
|
|
65
|
+
"miniflare",
|
|
66
|
+
"Wrangler does not use configuration in the `miniflare` section. Unless you are using Miniflare directly you can remove this section.",
|
|
67
|
+
true,
|
|
68
|
+
"😶 Ignored"
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
deprecated(
|
|
72
|
+
diagnostics,
|
|
73
|
+
rawConfig,
|
|
74
|
+
"type",
|
|
75
|
+
"Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.",
|
|
76
|
+
true,
|
|
77
|
+
"😶 Ignored"
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
deprecated(
|
|
81
|
+
diagnostics,
|
|
82
|
+
rawConfig,
|
|
83
|
+
"webpack_config",
|
|
84
|
+
"Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.",
|
|
85
|
+
true,
|
|
86
|
+
"😶 Ignored"
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
validateOptionalProperty(
|
|
90
|
+
diagnostics,
|
|
91
|
+
"",
|
|
92
|
+
"legacy_env",
|
|
93
|
+
rawConfig.legacy_env,
|
|
94
|
+
"boolean"
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
validateOptionalProperty(
|
|
98
|
+
diagnostics,
|
|
99
|
+
"",
|
|
100
|
+
"send_metrics",
|
|
101
|
+
rawConfig.send_metrics,
|
|
102
|
+
"boolean"
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
validateOptionalProperty(
|
|
106
|
+
diagnostics,
|
|
107
|
+
"",
|
|
108
|
+
"keep_vars",
|
|
109
|
+
rawConfig.keep_vars,
|
|
110
|
+
"boolean"
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// TODO: set the default to false to turn on service environments as the default
|
|
114
|
+
const isLegacyEnv =
|
|
115
|
+
(args as { "legacy-env": boolean | undefined })["legacy-env"] ??
|
|
116
|
+
rawConfig.legacy_env ??
|
|
117
|
+
true;
|
|
118
|
+
|
|
119
|
+
// TODO: remove this once service environments goes GA.
|
|
120
|
+
if (!isLegacyEnv) {
|
|
121
|
+
diagnostics.warnings.push(
|
|
122
|
+
"Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION."
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const topLevelEnv = normalizeAndValidateEnvironment(
|
|
127
|
+
diagnostics,
|
|
128
|
+
configPath,
|
|
129
|
+
rawConfig
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
//TODO: find a better way to define the type of Args that can be passed to the normalizeAndValidateConfig()
|
|
133
|
+
const envName = (args as { env: string | undefined }).env;
|
|
134
|
+
|
|
135
|
+
let activeEnv = topLevelEnv;
|
|
136
|
+
if (envName !== undefined) {
|
|
137
|
+
const envDiagnostics = new Diagnostics(
|
|
138
|
+
`"env.${envName}" environment configuration`
|
|
139
|
+
);
|
|
140
|
+
const rawEnv = rawConfig.env?.[envName];
|
|
141
|
+
if (rawEnv !== undefined) {
|
|
142
|
+
activeEnv = normalizeAndValidateEnvironment(
|
|
143
|
+
envDiagnostics,
|
|
144
|
+
configPath,
|
|
145
|
+
rawEnv,
|
|
146
|
+
envName,
|
|
147
|
+
topLevelEnv,
|
|
148
|
+
isLegacyEnv,
|
|
149
|
+
rawConfig
|
|
150
|
+
);
|
|
151
|
+
diagnostics.addChild(envDiagnostics);
|
|
152
|
+
} else {
|
|
153
|
+
// An environment was specified, but no configuration for it was found.
|
|
154
|
+
// To cover any legacy environment cases, where the `envName` is used,
|
|
155
|
+
// Let's create a fake active environment with the specified `envName`.
|
|
156
|
+
activeEnv = normalizeAndValidateEnvironment(
|
|
157
|
+
envDiagnostics,
|
|
158
|
+
configPath,
|
|
159
|
+
{},
|
|
160
|
+
envName,
|
|
161
|
+
topLevelEnv,
|
|
162
|
+
isLegacyEnv,
|
|
163
|
+
rawConfig
|
|
164
|
+
);
|
|
165
|
+
const envNames = rawConfig.env
|
|
166
|
+
? `The available configured environment names are: ${JSON.stringify(
|
|
167
|
+
Object.keys(rawConfig.env)
|
|
168
|
+
)}\n`
|
|
169
|
+
: "";
|
|
170
|
+
const message =
|
|
171
|
+
`No environment found in configuration with name "${envName}".\n` +
|
|
172
|
+
`Before using \`--env=${envName}\` there should be an equivalent environment section in the configuration.\n` +
|
|
173
|
+
`${envNames}\n` +
|
|
174
|
+
`Consider adding an environment configuration section to the wrangler.toml file:\n` +
|
|
175
|
+
"```\n[env." +
|
|
176
|
+
envName +
|
|
177
|
+
"]\n```\n";
|
|
178
|
+
|
|
179
|
+
if (envNames.length > 0) {
|
|
180
|
+
diagnostics.errors.push(message);
|
|
181
|
+
} else {
|
|
182
|
+
// Only warn (rather than error) if there are not actually any environments configured in wrangler.toml.
|
|
183
|
+
diagnostics.warnings.push(message);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Process the top-level default environment configuration.
|
|
189
|
+
const config: Config = {
|
|
190
|
+
configPath,
|
|
191
|
+
legacy_env: isLegacyEnv,
|
|
192
|
+
send_metrics: rawConfig.send_metrics,
|
|
193
|
+
keep_vars: rawConfig.keep_vars,
|
|
194
|
+
...activeEnv,
|
|
195
|
+
dev: normalizeAndValidateDev(diagnostics, rawConfig.dev ?? {}),
|
|
196
|
+
migrations: normalizeAndValidateMigrations(
|
|
197
|
+
diagnostics,
|
|
198
|
+
rawConfig.migrations ?? [],
|
|
199
|
+
activeEnv.durable_objects
|
|
200
|
+
),
|
|
201
|
+
site: normalizeAndValidateSite(
|
|
202
|
+
diagnostics,
|
|
203
|
+
configPath,
|
|
204
|
+
rawConfig,
|
|
205
|
+
activeEnv.main
|
|
206
|
+
),
|
|
207
|
+
assets: normalizeAndValidateAssets(diagnostics, configPath, rawConfig),
|
|
208
|
+
wasm_modules: normalizeAndValidateModulePaths(
|
|
209
|
+
diagnostics,
|
|
210
|
+
configPath,
|
|
211
|
+
"wasm_modules",
|
|
212
|
+
rawConfig.wasm_modules
|
|
213
|
+
),
|
|
214
|
+
text_blobs: normalizeAndValidateModulePaths(
|
|
215
|
+
diagnostics,
|
|
216
|
+
configPath,
|
|
217
|
+
"text_blobs",
|
|
218
|
+
rawConfig.text_blobs
|
|
219
|
+
),
|
|
220
|
+
data_blobs: normalizeAndValidateModulePaths(
|
|
221
|
+
diagnostics,
|
|
222
|
+
configPath,
|
|
223
|
+
"data_blobs",
|
|
224
|
+
rawConfig.data_blobs
|
|
225
|
+
),
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
validateBindingsHaveUniqueNames(diagnostics, config);
|
|
229
|
+
|
|
230
|
+
validateAdditionalProperties(
|
|
231
|
+
diagnostics,
|
|
232
|
+
"top-level",
|
|
233
|
+
Object.keys(rawConfig),
|
|
234
|
+
[...Object.keys(config), "env"]
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
experimental(diagnostics, rawConfig, "assets");
|
|
238
|
+
|
|
239
|
+
return { config, diagnostics };
|
|
219
240
|
}
|
|
220
241
|
|
|
221
242
|
/**
|
|
222
243
|
* Validate the `build` configuration and return the normalized values.
|
|
223
244
|
*/
|
|
224
245
|
function normalizeAndValidateBuild(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
246
|
+
diagnostics: Diagnostics,
|
|
247
|
+
rawEnv: RawEnvironment,
|
|
248
|
+
rawBuild: Config["build"],
|
|
249
|
+
configPath: string | undefined
|
|
229
250
|
): Config["build"] & { deprecatedUpload: DeprecatedUpload } {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
251
|
+
const { command, cwd, watch_dir = "./src", upload, ...rest } = rawBuild;
|
|
252
|
+
const deprecatedUpload: DeprecatedUpload = { ...upload };
|
|
253
|
+
validateAdditionalProperties(diagnostics, "build", Object.keys(rest), []);
|
|
254
|
+
|
|
255
|
+
validateOptionalProperty(diagnostics, "build", "command", command, "string");
|
|
256
|
+
validateOptionalProperty(diagnostics, "build", "cwd", cwd, "string");
|
|
257
|
+
if (Array.isArray(watch_dir)) {
|
|
258
|
+
validateTypedArray(diagnostics, "build.watch_dir", watch_dir, "string");
|
|
259
|
+
} else {
|
|
260
|
+
validateOptionalProperty(
|
|
261
|
+
diagnostics,
|
|
262
|
+
"build",
|
|
263
|
+
"watch_dir",
|
|
264
|
+
watch_dir,
|
|
265
|
+
"string"
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
deprecated(
|
|
270
|
+
diagnostics,
|
|
271
|
+
rawEnv,
|
|
272
|
+
"build.upload.format",
|
|
273
|
+
"The format is inferred automatically from the code.",
|
|
274
|
+
true
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
if (rawEnv.main !== undefined && rawBuild.upload?.main) {
|
|
278
|
+
diagnostics.errors.push(
|
|
279
|
+
`Don't define both the \`main\` and \`build.upload.main\` fields in your configuration.\n` +
|
|
280
|
+
`They serve the same purpose: to point to the entry-point of your worker.\n` +
|
|
281
|
+
`Delete the \`build.upload.main\` and \`build.upload.dir\` field from your config.`
|
|
282
|
+
);
|
|
283
|
+
} else {
|
|
284
|
+
deprecated(
|
|
285
|
+
diagnostics,
|
|
286
|
+
rawEnv,
|
|
287
|
+
"build.upload.main",
|
|
288
|
+
`Delete the \`build.upload.main\` and \`build.upload.dir\` fields.\n` +
|
|
289
|
+
`Then add the top level \`main\` field to your configuration file:\n` +
|
|
290
|
+
`\`\`\`\n` +
|
|
291
|
+
`main = "${path.join(
|
|
292
|
+
rawBuild.upload?.dir ?? "./dist",
|
|
293
|
+
rawBuild.upload?.main ?? "."
|
|
294
|
+
)}"\n` +
|
|
295
|
+
`\`\`\``,
|
|
296
|
+
true
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
deprecated(
|
|
300
|
+
diagnostics,
|
|
301
|
+
rawEnv,
|
|
302
|
+
"build.upload.dir",
|
|
303
|
+
`Use the top level "main" field or a command-line argument to specify the entry-point for the Worker.`,
|
|
304
|
+
true
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
command,
|
|
310
|
+
watch_dir:
|
|
311
|
+
// - `watch_dir` only matters when `command` is defined, so we apply
|
|
312
|
+
// a default only when `command` is defined
|
|
313
|
+
// - `configPath` will always be defined since `build` can only
|
|
314
|
+
// be configured in `wrangler.toml`, but who knows, that may
|
|
315
|
+
// change in the future, so we do a check anyway
|
|
316
|
+
command && configPath
|
|
317
|
+
? Array.isArray(watch_dir)
|
|
318
|
+
? watch_dir.map((dir) =>
|
|
319
|
+
path.relative(
|
|
320
|
+
process.cwd(),
|
|
321
|
+
path.join(path.dirname(configPath), `${dir}`)
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
: path.relative(
|
|
325
|
+
process.cwd(),
|
|
326
|
+
path.join(path.dirname(configPath), `${watch_dir}`)
|
|
327
|
+
)
|
|
328
|
+
: watch_dir,
|
|
329
|
+
cwd,
|
|
330
|
+
deprecatedUpload,
|
|
331
|
+
};
|
|
302
332
|
}
|
|
303
333
|
|
|
304
334
|
/**
|
|
305
335
|
* Validate the `main` field and return the normalized values.
|
|
306
336
|
*/
|
|
307
337
|
function normalizeAndValidateMainField(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
338
|
+
configPath: string | undefined,
|
|
339
|
+
rawMain: string | undefined,
|
|
340
|
+
deprecatedUpload: DeprecatedUpload | undefined
|
|
311
341
|
): string | undefined {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
342
|
+
const configDir = path.dirname(configPath ?? "wrangler.toml");
|
|
343
|
+
if (rawMain !== undefined) {
|
|
344
|
+
if (typeof rawMain === "string") {
|
|
345
|
+
const directory = path.resolve(configDir);
|
|
346
|
+
return path.resolve(directory, rawMain);
|
|
347
|
+
} else {
|
|
348
|
+
return rawMain;
|
|
349
|
+
}
|
|
350
|
+
} else if (deprecatedUpload?.main !== undefined) {
|
|
351
|
+
const directory = path.resolve(
|
|
352
|
+
configDir,
|
|
353
|
+
deprecatedUpload?.dir || "./dist"
|
|
354
|
+
);
|
|
355
|
+
return path.resolve(directory, deprecatedUpload.main);
|
|
356
|
+
} else {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Validate the `base_dir` field and return the normalized values.
|
|
363
|
+
*/
|
|
364
|
+
function normalizeAndValidateBaseDirField(
|
|
365
|
+
configPath: string | undefined,
|
|
366
|
+
rawDir: string | undefined
|
|
367
|
+
): string | undefined {
|
|
368
|
+
const configDir = path.dirname(configPath ?? "wrangler.toml");
|
|
369
|
+
if (rawDir !== undefined) {
|
|
370
|
+
if (typeof rawDir === "string") {
|
|
371
|
+
const directory = path.resolve(configDir);
|
|
372
|
+
return path.resolve(directory, rawDir);
|
|
373
|
+
} else {
|
|
374
|
+
return rawDir;
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
329
379
|
}
|
|
330
380
|
|
|
331
381
|
/**
|
|
332
382
|
* Validate the `dev` configuration and return the normalized values.
|
|
333
383
|
*/
|
|
334
384
|
function normalizeAndValidateDev(
|
|
335
|
-
|
|
336
|
-
|
|
385
|
+
diagnostics: Diagnostics,
|
|
386
|
+
rawDev: RawDevConfig
|
|
337
387
|
): DevConfig {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
388
|
+
const {
|
|
389
|
+
ip = "0.0.0.0",
|
|
390
|
+
port,
|
|
391
|
+
inspector_port,
|
|
392
|
+
local_protocol = "http",
|
|
393
|
+
upstream_protocol = "https",
|
|
394
|
+
host,
|
|
395
|
+
...rest
|
|
396
|
+
} = rawDev;
|
|
397
|
+
validateAdditionalProperties(diagnostics, "dev", Object.keys(rest), []);
|
|
398
|
+
|
|
399
|
+
validateOptionalProperty(diagnostics, "dev", "ip", ip, "string");
|
|
400
|
+
validateOptionalProperty(diagnostics, "dev", "port", port, "number");
|
|
401
|
+
validateOptionalProperty(
|
|
402
|
+
diagnostics,
|
|
403
|
+
"dev",
|
|
404
|
+
"inspector_port",
|
|
405
|
+
inspector_port,
|
|
406
|
+
"number"
|
|
407
|
+
);
|
|
408
|
+
validateOptionalProperty(
|
|
409
|
+
diagnostics,
|
|
410
|
+
"dev",
|
|
411
|
+
"local_protocol",
|
|
412
|
+
local_protocol,
|
|
413
|
+
"string",
|
|
414
|
+
["http", "https"]
|
|
415
|
+
);
|
|
416
|
+
validateOptionalProperty(
|
|
417
|
+
diagnostics,
|
|
418
|
+
"dev",
|
|
419
|
+
"upstream_protocol",
|
|
420
|
+
upstream_protocol,
|
|
421
|
+
"string",
|
|
422
|
+
["http", "https"]
|
|
423
|
+
);
|
|
424
|
+
validateOptionalProperty(diagnostics, "dev", "host", host, "string");
|
|
425
|
+
return { ip, port, inspector_port, local_protocol, upstream_protocol, host };
|
|
368
426
|
}
|
|
369
427
|
|
|
370
428
|
/**
|
|
371
429
|
* Validate the `migrations` configuration and return the normalized values.
|
|
372
430
|
*/
|
|
373
431
|
function normalizeAndValidateMigrations(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
432
|
+
diagnostics: Diagnostics,
|
|
433
|
+
rawMigrations: Config["migrations"],
|
|
434
|
+
durableObjects: Config["durable_objects"]
|
|
377
435
|
): Config["migrations"] {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
436
|
+
if (!Array.isArray(rawMigrations)) {
|
|
437
|
+
diagnostics.errors.push(
|
|
438
|
+
`The optional "migrations" field should be an array, but got ${JSON.stringify(
|
|
439
|
+
rawMigrations
|
|
440
|
+
)}`
|
|
441
|
+
);
|
|
442
|
+
return [];
|
|
443
|
+
} else {
|
|
444
|
+
for (let i = 0; i < rawMigrations.length; i++) {
|
|
445
|
+
const { tag, new_classes, renamed_classes, deleted_classes, ...rest } =
|
|
446
|
+
rawMigrations[i];
|
|
447
|
+
|
|
448
|
+
validateAdditionalProperties(
|
|
449
|
+
diagnostics,
|
|
450
|
+
"migrations",
|
|
451
|
+
Object.keys(rest),
|
|
452
|
+
[]
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
validateRequiredProperty(
|
|
456
|
+
diagnostics,
|
|
457
|
+
`migrations[${i}]`,
|
|
458
|
+
`tag`,
|
|
459
|
+
tag,
|
|
460
|
+
"string"
|
|
461
|
+
);
|
|
462
|
+
validateOptionalTypedArray(
|
|
463
|
+
diagnostics,
|
|
464
|
+
`migrations[${i}].new_classes`,
|
|
465
|
+
new_classes,
|
|
466
|
+
"string"
|
|
467
|
+
);
|
|
468
|
+
if (renamed_classes !== undefined) {
|
|
469
|
+
if (!Array.isArray(renamed_classes)) {
|
|
470
|
+
diagnostics.errors.push(
|
|
471
|
+
`Expected "migrations[${i}].renamed_classes" to be an array of "{from: string, to: string}" objects but got ${JSON.stringify(
|
|
472
|
+
renamed_classes
|
|
473
|
+
)}.`
|
|
474
|
+
);
|
|
475
|
+
} else if (
|
|
476
|
+
renamed_classes.some(
|
|
477
|
+
(c) =>
|
|
478
|
+
typeof c !== "object" ||
|
|
479
|
+
!isRequiredProperty(c, "from", "string") ||
|
|
480
|
+
!isRequiredProperty(c, "to", "string")
|
|
481
|
+
)
|
|
482
|
+
) {
|
|
483
|
+
diagnostics.errors.push(
|
|
484
|
+
`Expected "migrations[${i}].renamed_classes" to be an array of "{from: string, to: string}" objects but got ${JSON.stringify(
|
|
485
|
+
renamed_classes
|
|
486
|
+
)}.`
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
validateOptionalTypedArray(
|
|
491
|
+
diagnostics,
|
|
492
|
+
`migrations[${i}].deleted_classes`,
|
|
493
|
+
deleted_classes,
|
|
494
|
+
"string"
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (
|
|
499
|
+
Array.isArray(durableObjects?.bindings) &&
|
|
500
|
+
durableObjects.bindings.length > 0
|
|
501
|
+
) {
|
|
502
|
+
// intrinsic [durable_objects] implies [migrations]
|
|
503
|
+
const exportedDurableObjects = (durableObjects.bindings || []).filter(
|
|
504
|
+
(binding) => !binding.script_name
|
|
505
|
+
);
|
|
506
|
+
if (exportedDurableObjects.length > 0 && rawMigrations.length === 0) {
|
|
507
|
+
if (
|
|
508
|
+
!exportedDurableObjects.some(
|
|
509
|
+
(exportedDurableObject) =>
|
|
510
|
+
typeof exportedDurableObject.class_name !== "string"
|
|
511
|
+
)
|
|
512
|
+
) {
|
|
513
|
+
const durableObjectClassnames = exportedDurableObjects.map(
|
|
514
|
+
(durable) => durable.class_name
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
diagnostics.warnings.push(
|
|
518
|
+
`In wrangler.toml, you have configured [durable_objects] exported by this Worker (${durableObjectClassnames.join(
|
|
519
|
+
", "
|
|
520
|
+
)}), but no [migrations] for them. This may not work as expected until you add a [migrations] section to your wrangler.toml. Add this configuration to your wrangler.toml:
|
|
463
521
|
|
|
464
522
|
\`\`\`
|
|
465
523
|
[[migrations]]
|
|
466
524
|
tag = "v1" # Should be unique for each entry
|
|
467
525
|
new_classes = [${durableObjectClassnames
|
|
468
|
-
|
|
469
|
-
|
|
526
|
+
.map((name) => `"${name}"`)
|
|
527
|
+
.join(", ")}]
|
|
470
528
|
\`\`\`
|
|
471
529
|
|
|
472
530
|
Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details.`
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
477
535
|
|
|
478
|
-
|
|
479
|
-
|
|
536
|
+
return rawMigrations;
|
|
537
|
+
}
|
|
480
538
|
}
|
|
481
539
|
|
|
482
540
|
/**
|
|
483
541
|
* Validate the `site` configuration and return the normalized values.
|
|
484
542
|
*/
|
|
485
543
|
function normalizeAndValidateSite(
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
544
|
+
diagnostics: Diagnostics,
|
|
545
|
+
configPath: string | undefined,
|
|
546
|
+
rawConfig: RawConfig,
|
|
547
|
+
mainEntryPoint: string | undefined
|
|
490
548
|
): Config["site"] {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
549
|
+
if (rawConfig?.site !== undefined) {
|
|
550
|
+
const { bucket, include = [], exclude = [], ...rest } = rawConfig.site;
|
|
551
|
+
|
|
552
|
+
validateAdditionalProperties(diagnostics, "site", Object.keys(rest), [
|
|
553
|
+
"entry-point",
|
|
554
|
+
]);
|
|
555
|
+
validateRequiredProperty(diagnostics, "site", "bucket", bucket, "string");
|
|
556
|
+
validateTypedArray(diagnostics, "sites.include", include, "string");
|
|
557
|
+
validateTypedArray(diagnostics, "sites.exclude", exclude, "string");
|
|
558
|
+
validateOptionalProperty(
|
|
559
|
+
diagnostics,
|
|
560
|
+
"site",
|
|
561
|
+
"entry-point",
|
|
562
|
+
rawConfig.site["entry-point"],
|
|
563
|
+
"string"
|
|
564
|
+
);
|
|
565
|
+
|
|
566
|
+
deprecated(
|
|
567
|
+
diagnostics,
|
|
568
|
+
rawConfig,
|
|
569
|
+
`site.entry-point`,
|
|
570
|
+
`Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration file:\n` +
|
|
571
|
+
`\`\`\`\n` +
|
|
572
|
+
`main = "${path.join(
|
|
573
|
+
String(rawConfig.site["entry-point"]) || "workers-site",
|
|
574
|
+
path.extname(String(rawConfig.site["entry-point"]) || "workers-site")
|
|
575
|
+
? ""
|
|
576
|
+
: "index.js"
|
|
577
|
+
)}"\n` +
|
|
578
|
+
`\`\`\``,
|
|
579
|
+
false,
|
|
580
|
+
undefined,
|
|
581
|
+
"warning"
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
let siteEntryPoint = rawConfig.site["entry-point"];
|
|
585
|
+
|
|
586
|
+
if (!mainEntryPoint && !siteEntryPoint) {
|
|
587
|
+
// this means that we're defaulting to "workers-site"
|
|
588
|
+
// so let's add the deprecation warning
|
|
589
|
+
diagnostics.warnings.push(
|
|
590
|
+
`Because you've defined a [site] configuration, we're defaulting to "workers-site" for the deprecated \`site.entry-point\`field.\n` +
|
|
591
|
+
`Add the top level \`main\` field to your configuration file:\n` +
|
|
592
|
+
`\`\`\`\n` +
|
|
593
|
+
`main = "workers-site/index.js"\n` +
|
|
594
|
+
`\`\`\``
|
|
595
|
+
);
|
|
596
|
+
siteEntryPoint = "workers-site";
|
|
597
|
+
} else if (mainEntryPoint && siteEntryPoint) {
|
|
598
|
+
diagnostics.errors.push(
|
|
599
|
+
`Don't define both the \`main\` and \`site.entry-point\` fields in your configuration.\n` +
|
|
600
|
+
`They serve the same purpose: to point to the entry-point of your worker.\n` +
|
|
601
|
+
`Delete the deprecated \`site.entry-point\` field from your config.`
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (configPath && siteEntryPoint) {
|
|
606
|
+
// rewrite the path to be relative to the working directory
|
|
607
|
+
siteEntryPoint = path.relative(
|
|
608
|
+
process.cwd(),
|
|
609
|
+
path.join(path.dirname(configPath), siteEntryPoint)
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return {
|
|
614
|
+
bucket,
|
|
615
|
+
"entry-point": siteEntryPoint,
|
|
616
|
+
include,
|
|
617
|
+
exclude,
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
return undefined;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Validate the `assets` configuration and return normalized values.
|
|
625
|
+
*/
|
|
626
|
+
function normalizeAndValidateAssets(
|
|
627
|
+
diagnostics: Diagnostics,
|
|
628
|
+
configPath: string | undefined,
|
|
629
|
+
rawConfig: RawConfig
|
|
630
|
+
): Config["assets"] {
|
|
631
|
+
// Even though the type doesn't say it,
|
|
632
|
+
// we allow for a string input in the config,
|
|
633
|
+
// so let's normalise it
|
|
634
|
+
if (typeof rawConfig?.assets === "string") {
|
|
635
|
+
return {
|
|
636
|
+
bucket: rawConfig.assets,
|
|
637
|
+
include: [],
|
|
638
|
+
exclude: [],
|
|
639
|
+
browser_TTL: undefined,
|
|
640
|
+
serve_single_page_app: false,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
if (rawConfig?.assets === undefined) {
|
|
645
|
+
return undefined;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
if (typeof rawConfig.assets !== "object") {
|
|
649
|
+
diagnostics.errors.push(
|
|
650
|
+
`Expected the \`assets\` field to be a string or an object, but got ${typeof rawConfig.assets}.`
|
|
651
|
+
);
|
|
652
|
+
return undefined;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
const {
|
|
656
|
+
bucket,
|
|
657
|
+
include = [],
|
|
658
|
+
exclude = [],
|
|
659
|
+
browser_TTL,
|
|
660
|
+
serve_single_page_app,
|
|
661
|
+
...rest
|
|
662
|
+
} = rawConfig.assets;
|
|
663
|
+
|
|
664
|
+
validateAdditionalProperties(diagnostics, "assets", Object.keys(rest), []);
|
|
665
|
+
|
|
666
|
+
validateRequiredProperty(diagnostics, "assets", "bucket", bucket, "string");
|
|
667
|
+
validateTypedArray(diagnostics, "assets.include", include, "string");
|
|
668
|
+
validateTypedArray(diagnostics, "assets.exclude", exclude, "string");
|
|
669
|
+
|
|
670
|
+
validateOptionalProperty(
|
|
671
|
+
diagnostics,
|
|
672
|
+
"assets",
|
|
673
|
+
"browser_TTL",
|
|
674
|
+
browser_TTL,
|
|
675
|
+
"number"
|
|
676
|
+
);
|
|
677
|
+
|
|
678
|
+
validateOptionalProperty(
|
|
679
|
+
diagnostics,
|
|
680
|
+
"assets",
|
|
681
|
+
"serve_single_page_app",
|
|
682
|
+
serve_single_page_app,
|
|
683
|
+
"boolean"
|
|
684
|
+
);
|
|
685
|
+
|
|
686
|
+
return {
|
|
687
|
+
bucket,
|
|
688
|
+
include,
|
|
689
|
+
exclude,
|
|
690
|
+
browser_TTL,
|
|
691
|
+
serve_single_page_app,
|
|
692
|
+
};
|
|
563
693
|
}
|
|
564
694
|
|
|
565
695
|
/**
|
|
566
696
|
* Map the paths of the `wasm_modules`, `text_blobs` or `data_blobs` configuration to be relative to the current working directory.
|
|
567
697
|
*/
|
|
568
698
|
function normalizeAndValidateModulePaths(
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
699
|
+
diagnostics: Diagnostics,
|
|
700
|
+
configPath: string | undefined,
|
|
701
|
+
field: "wasm_modules" | "text_blobs" | "data_blobs",
|
|
702
|
+
rawMapping: Record<string, string> | undefined
|
|
573
703
|
): Record<string, string> | undefined {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
704
|
+
if (rawMapping === undefined) {
|
|
705
|
+
return undefined;
|
|
706
|
+
}
|
|
707
|
+
const mapping: Record<string, string> = {};
|
|
708
|
+
// Rewrite paths to be relative to the cwd, rather than the config path.
|
|
709
|
+
for (const [name, filePath] of Object.entries(rawMapping)) {
|
|
710
|
+
if (isString(diagnostics, `${field}['${name}']`, filePath, undefined)) {
|
|
711
|
+
if (configPath) {
|
|
712
|
+
mapping[name] = configPath
|
|
713
|
+
? path.relative(
|
|
714
|
+
process.cwd(),
|
|
715
|
+
path.join(path.dirname(configPath), filePath)
|
|
716
|
+
)
|
|
717
|
+
: filePath;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return mapping;
|
|
592
722
|
}
|
|
593
723
|
|
|
594
724
|
/**
|
|
@@ -596,638 +726,968 @@ function normalizeAndValidateModulePaths(
|
|
|
596
726
|
* or an object that looks like {pattern: string, zone_id: string }
|
|
597
727
|
*/
|
|
598
728
|
function isValidRouteValue(item: unknown): boolean {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
729
|
+
if (!item) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
if (typeof item === "string") {
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
if (typeof item === "object") {
|
|
736
|
+
if (!hasProperty(item, "pattern") || typeof item.pattern !== "string") {
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
const otherKeys = Object.keys(item).length - 1; // minus one to subtract "pattern"
|
|
741
|
+
|
|
742
|
+
const hasZoneId =
|
|
743
|
+
hasProperty(item, "zone_id") && typeof item.zone_id === "string";
|
|
744
|
+
const hasZoneName =
|
|
745
|
+
hasProperty(item, "zone_name") && typeof item.zone_name === "string";
|
|
746
|
+
const hasCustomDomainFlag =
|
|
747
|
+
hasProperty(item, "custom_domain") &&
|
|
748
|
+
typeof item.custom_domain === "boolean";
|
|
749
|
+
|
|
750
|
+
if (otherKeys === 2 && hasCustomDomainFlag && (hasZoneId || hasZoneName)) {
|
|
751
|
+
return true;
|
|
752
|
+
} else if (
|
|
753
|
+
otherKeys === 1 &&
|
|
754
|
+
(hasZoneId || hasZoneName || hasCustomDomainFlag)
|
|
755
|
+
) {
|
|
756
|
+
return true;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* If account_id has been passed as an empty string, normalise it to undefined.
|
|
764
|
+
* This is to workaround older Wrangler v1-era templates that have account_id = '',
|
|
765
|
+
* which isn't a valid value anyway
|
|
766
|
+
*/
|
|
767
|
+
function mutateEmptyStringAccountIDValue(
|
|
768
|
+
diagnostics: Diagnostics,
|
|
769
|
+
rawEnv: RawEnvironment
|
|
770
|
+
) {
|
|
771
|
+
if (rawEnv.account_id === "") {
|
|
772
|
+
diagnostics.warnings.push(
|
|
773
|
+
`The "account_id" field in your configuration is an empty string and will be ignored.\n` +
|
|
774
|
+
`Please remove the "account_id" field from your configuration.`
|
|
775
|
+
);
|
|
776
|
+
rawEnv.account_id = undefined;
|
|
777
|
+
}
|
|
778
|
+
return rawEnv;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Normalize empty string to `undefined` by mutating rawEnv.route value.
|
|
783
|
+
* As part of backward compatibility with Wrangler v1 converting empty string to `undefined`
|
|
784
|
+
*/
|
|
785
|
+
function mutateEmptyStringRouteValue(
|
|
786
|
+
diagnostics: Diagnostics,
|
|
787
|
+
rawEnv: RawEnvironment
|
|
788
|
+
): RawEnvironment {
|
|
789
|
+
if (rawEnv["route"] === "") {
|
|
790
|
+
diagnostics.warnings.push(
|
|
791
|
+
`The "route" field in your configuration is an empty string and will be ignored.\n` +
|
|
792
|
+
`Please remove the "route" field from your configuration.`
|
|
793
|
+
);
|
|
794
|
+
rawEnv["route"] = undefined;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
return rawEnv;
|
|
630
798
|
}
|
|
631
799
|
|
|
632
800
|
/**
|
|
633
801
|
* Validate that the field is a route.
|
|
634
802
|
*/
|
|
635
803
|
const isRoute: ValidatorFn = (diagnostics, field, value) => {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
804
|
+
if (value !== undefined && !isValidRouteValue(value)) {
|
|
805
|
+
diagnostics.errors.push(
|
|
806
|
+
`Expected "${field}" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got ${JSON.stringify(
|
|
807
|
+
value
|
|
808
|
+
)}.`
|
|
809
|
+
);
|
|
810
|
+
return false;
|
|
811
|
+
}
|
|
812
|
+
return true;
|
|
645
813
|
};
|
|
646
814
|
|
|
647
815
|
/**
|
|
648
816
|
* Validate that the field is an array of routes.
|
|
649
817
|
*/
|
|
650
818
|
const isRouteArray: ValidatorFn = (diagnostics, field, value) => {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
819
|
+
if (value === undefined) {
|
|
820
|
+
return true;
|
|
821
|
+
}
|
|
822
|
+
if (!Array.isArray(value)) {
|
|
823
|
+
diagnostics.errors.push(
|
|
824
|
+
`Expected "${field}" to be an array but got ${JSON.stringify(value)}.`
|
|
825
|
+
);
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
const invalidRoutes = [];
|
|
829
|
+
for (const item of value) {
|
|
830
|
+
if (!isValidRouteValue(item)) {
|
|
831
|
+
invalidRoutes.push(item);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
if (invalidRoutes.length > 0) {
|
|
835
|
+
diagnostics.errors.push(
|
|
836
|
+
`Expected "${field}" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: ${JSON.stringify(
|
|
837
|
+
invalidRoutes,
|
|
838
|
+
null,
|
|
839
|
+
2
|
|
840
|
+
)}.`
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
return invalidRoutes.length === 0;
|
|
676
844
|
};
|
|
677
845
|
|
|
678
|
-
function
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
846
|
+
function normalizeAndValidateRoute(
|
|
847
|
+
diagnostics: Diagnostics,
|
|
848
|
+
topLevelEnv: Environment | undefined,
|
|
849
|
+
rawEnv: RawEnvironment
|
|
682
850
|
): Config["route"] {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
851
|
+
return inheritable(
|
|
852
|
+
diagnostics,
|
|
853
|
+
topLevelEnv,
|
|
854
|
+
mutateEmptyStringRouteValue(diagnostics, rawEnv),
|
|
855
|
+
"route",
|
|
856
|
+
isRoute,
|
|
857
|
+
undefined
|
|
858
|
+
);
|
|
691
859
|
}
|
|
692
860
|
|
|
693
861
|
function validateRoutes(
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
862
|
+
diagnostics: Diagnostics,
|
|
863
|
+
topLevelEnv: Environment | undefined,
|
|
864
|
+
rawEnv: RawEnvironment
|
|
697
865
|
): Config["routes"] {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
866
|
+
return inheritable(
|
|
867
|
+
diagnostics,
|
|
868
|
+
topLevelEnv,
|
|
869
|
+
rawEnv,
|
|
870
|
+
"routes",
|
|
871
|
+
all(isRouteArray, isMutuallyExclusiveWith(rawEnv, "route")),
|
|
872
|
+
undefined
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function normalizeAndValidatePlacement(
|
|
877
|
+
diagnostics: Diagnostics,
|
|
878
|
+
topLevelEnv: Environment | undefined,
|
|
879
|
+
rawEnv: RawEnvironment
|
|
880
|
+
): Config["placement"] {
|
|
881
|
+
if (rawEnv.placement) {
|
|
882
|
+
validateRequiredProperty(
|
|
883
|
+
diagnostics,
|
|
884
|
+
"placement",
|
|
885
|
+
"mode",
|
|
886
|
+
rawEnv.placement.mode,
|
|
887
|
+
"string",
|
|
888
|
+
["off", "smart"]
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
return inheritable(
|
|
893
|
+
diagnostics,
|
|
894
|
+
topLevelEnv,
|
|
895
|
+
rawEnv,
|
|
896
|
+
"placement",
|
|
897
|
+
() => true,
|
|
898
|
+
undefined
|
|
899
|
+
);
|
|
706
900
|
}
|
|
707
901
|
|
|
708
902
|
/**
|
|
709
903
|
* Validate top-level environment configuration and return the normalized values.
|
|
710
904
|
*/
|
|
711
905
|
function normalizeAndValidateEnvironment(
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
906
|
+
diagnostics: Diagnostics,
|
|
907
|
+
configPath: string | undefined,
|
|
908
|
+
topLevelEnv: RawEnvironment
|
|
715
909
|
): Environment;
|
|
716
910
|
/**
|
|
717
911
|
* Validate the named environment configuration and return the normalized values.
|
|
718
912
|
*/
|
|
719
913
|
function normalizeAndValidateEnvironment(
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
914
|
+
diagnostics: Diagnostics,
|
|
915
|
+
configPath: string | undefined,
|
|
916
|
+
rawEnv: RawEnvironment,
|
|
917
|
+
envName: string,
|
|
918
|
+
topLevelEnv: Environment,
|
|
919
|
+
isLegacyEnv: boolean,
|
|
920
|
+
rawConfig: RawConfig
|
|
727
921
|
): Environment;
|
|
728
922
|
function normalizeAndValidateEnvironment(
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
923
|
+
diagnostics: Diagnostics,
|
|
924
|
+
configPath: string | undefined,
|
|
925
|
+
rawEnv: RawEnvironment,
|
|
926
|
+
envName = "top level",
|
|
927
|
+
topLevelEnv?: Environment | undefined,
|
|
928
|
+
isLegacyEnv?: boolean,
|
|
929
|
+
rawConfig?: RawConfig | undefined
|
|
736
930
|
): Environment {
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
931
|
+
deprecated(
|
|
932
|
+
diagnostics,
|
|
933
|
+
rawEnv,
|
|
934
|
+
"kv-namespaces",
|
|
935
|
+
`The "kv-namespaces" field is no longer supported, please rename to "kv_namespaces"`,
|
|
936
|
+
true
|
|
937
|
+
);
|
|
938
|
+
deprecated(
|
|
939
|
+
diagnostics,
|
|
940
|
+
rawEnv,
|
|
941
|
+
"zone_id",
|
|
942
|
+
"This is unnecessary since we can deduce this from routes directly.",
|
|
943
|
+
false // We need to leave this in-place for the moment since `route` commands might use it.
|
|
944
|
+
);
|
|
945
|
+
|
|
946
|
+
// The field "experimental_services" doesn't exist anymore in the config, but we still want to error about any older usage.
|
|
947
|
+
|
|
948
|
+
deprecated(
|
|
949
|
+
diagnostics,
|
|
950
|
+
rawEnv,
|
|
951
|
+
"experimental_services",
|
|
952
|
+
`The "experimental_services" field is no longer supported. Simply rename the [experimental_services] field to [services].`,
|
|
953
|
+
true
|
|
954
|
+
);
|
|
955
|
+
|
|
956
|
+
experimental(diagnostics, rawEnv, "unsafe");
|
|
957
|
+
experimental(diagnostics, rawEnv, "services");
|
|
958
|
+
|
|
959
|
+
const route = normalizeAndValidateRoute(diagnostics, topLevelEnv, rawEnv);
|
|
960
|
+
|
|
961
|
+
const account_id = inheritableInLegacyEnvironments(
|
|
962
|
+
diagnostics,
|
|
963
|
+
isLegacyEnv,
|
|
964
|
+
topLevelEnv,
|
|
965
|
+
mutateEmptyStringAccountIDValue(diagnostics, rawEnv),
|
|
966
|
+
"account_id",
|
|
967
|
+
isString,
|
|
968
|
+
undefined,
|
|
969
|
+
undefined
|
|
970
|
+
);
|
|
971
|
+
|
|
972
|
+
const routes = validateRoutes(diagnostics, topLevelEnv, rawEnv);
|
|
973
|
+
|
|
974
|
+
const workers_dev = inheritable(
|
|
975
|
+
diagnostics,
|
|
976
|
+
topLevelEnv,
|
|
977
|
+
rawEnv,
|
|
978
|
+
"workers_dev",
|
|
979
|
+
isBoolean,
|
|
980
|
+
undefined
|
|
981
|
+
);
|
|
982
|
+
|
|
983
|
+
const { deprecatedUpload, ...build } = normalizeAndValidateBuild(
|
|
984
|
+
diagnostics,
|
|
985
|
+
rawEnv,
|
|
986
|
+
rawEnv.build ?? topLevelEnv?.build ?? {},
|
|
987
|
+
configPath
|
|
988
|
+
);
|
|
989
|
+
|
|
990
|
+
const environment: Environment = {
|
|
991
|
+
// Inherited fields
|
|
992
|
+
account_id,
|
|
993
|
+
compatibility_date: inheritable(
|
|
994
|
+
diagnostics,
|
|
995
|
+
topLevelEnv,
|
|
996
|
+
rawEnv,
|
|
997
|
+
"compatibility_date",
|
|
998
|
+
isString,
|
|
999
|
+
undefined
|
|
1000
|
+
),
|
|
1001
|
+
compatibility_flags: inheritable(
|
|
1002
|
+
diagnostics,
|
|
1003
|
+
topLevelEnv,
|
|
1004
|
+
rawEnv,
|
|
1005
|
+
"compatibility_flags",
|
|
1006
|
+
isStringArray,
|
|
1007
|
+
[]
|
|
1008
|
+
),
|
|
1009
|
+
jsx_factory: inheritable(
|
|
1010
|
+
diagnostics,
|
|
1011
|
+
topLevelEnv,
|
|
1012
|
+
rawEnv,
|
|
1013
|
+
"jsx_factory",
|
|
1014
|
+
isString,
|
|
1015
|
+
"React.createElement"
|
|
1016
|
+
),
|
|
1017
|
+
jsx_fragment: inheritable(
|
|
1018
|
+
diagnostics,
|
|
1019
|
+
topLevelEnv,
|
|
1020
|
+
rawEnv,
|
|
1021
|
+
"jsx_fragment",
|
|
1022
|
+
isString,
|
|
1023
|
+
"React.Fragment"
|
|
1024
|
+
),
|
|
1025
|
+
tsconfig: validateAndNormalizeTsconfig(
|
|
1026
|
+
diagnostics,
|
|
1027
|
+
topLevelEnv,
|
|
1028
|
+
rawEnv,
|
|
1029
|
+
configPath
|
|
1030
|
+
),
|
|
1031
|
+
rules: validateAndNormalizeRules(
|
|
1032
|
+
diagnostics,
|
|
1033
|
+
topLevelEnv,
|
|
1034
|
+
rawEnv,
|
|
1035
|
+
deprecatedUpload?.rules,
|
|
1036
|
+
envName
|
|
1037
|
+
),
|
|
1038
|
+
name: inheritableInLegacyEnvironments(
|
|
1039
|
+
diagnostics,
|
|
1040
|
+
isLegacyEnv,
|
|
1041
|
+
topLevelEnv,
|
|
1042
|
+
rawEnv,
|
|
1043
|
+
"name",
|
|
1044
|
+
isValidName,
|
|
1045
|
+
appendEnvName(envName),
|
|
1046
|
+
undefined
|
|
1047
|
+
),
|
|
1048
|
+
main: normalizeAndValidateMainField(
|
|
1049
|
+
configPath,
|
|
1050
|
+
inheritable(
|
|
1051
|
+
diagnostics,
|
|
1052
|
+
topLevelEnv,
|
|
1053
|
+
rawEnv,
|
|
1054
|
+
"main",
|
|
1055
|
+
isString,
|
|
1056
|
+
undefined
|
|
1057
|
+
),
|
|
1058
|
+
deprecatedUpload
|
|
1059
|
+
),
|
|
1060
|
+
base_dir: normalizeAndValidateBaseDirField(
|
|
1061
|
+
configPath,
|
|
1062
|
+
inheritable(
|
|
1063
|
+
diagnostics,
|
|
1064
|
+
topLevelEnv,
|
|
1065
|
+
rawEnv,
|
|
1066
|
+
"base_dir",
|
|
1067
|
+
isString,
|
|
1068
|
+
undefined
|
|
1069
|
+
)
|
|
1070
|
+
),
|
|
1071
|
+
route,
|
|
1072
|
+
routes,
|
|
1073
|
+
triggers: inheritable(
|
|
1074
|
+
diagnostics,
|
|
1075
|
+
topLevelEnv,
|
|
1076
|
+
rawEnv,
|
|
1077
|
+
"triggers",
|
|
1078
|
+
isObjectWith("crons"),
|
|
1079
|
+
{ crons: [] }
|
|
1080
|
+
),
|
|
1081
|
+
usage_model: inheritable(
|
|
1082
|
+
diagnostics,
|
|
1083
|
+
topLevelEnv,
|
|
1084
|
+
rawEnv,
|
|
1085
|
+
"usage_model",
|
|
1086
|
+
isOneOf("bundled", "unbound"),
|
|
1087
|
+
undefined
|
|
1088
|
+
),
|
|
1089
|
+
placement: normalizeAndValidatePlacement(diagnostics, topLevelEnv, rawEnv),
|
|
1090
|
+
build,
|
|
1091
|
+
workers_dev,
|
|
1092
|
+
// Not inherited fields
|
|
1093
|
+
vars: notInheritable(
|
|
1094
|
+
diagnostics,
|
|
1095
|
+
topLevelEnv,
|
|
1096
|
+
rawConfig,
|
|
1097
|
+
rawEnv,
|
|
1098
|
+
envName,
|
|
1099
|
+
"vars",
|
|
1100
|
+
validateVars(envName),
|
|
1101
|
+
{}
|
|
1102
|
+
),
|
|
1103
|
+
define: notInheritable(
|
|
1104
|
+
diagnostics,
|
|
1105
|
+
topLevelEnv,
|
|
1106
|
+
rawConfig,
|
|
1107
|
+
rawEnv,
|
|
1108
|
+
envName,
|
|
1109
|
+
"define",
|
|
1110
|
+
validateDefines(envName),
|
|
1111
|
+
{}
|
|
1112
|
+
),
|
|
1113
|
+
durable_objects: notInheritable(
|
|
1114
|
+
diagnostics,
|
|
1115
|
+
topLevelEnv,
|
|
1116
|
+
rawConfig,
|
|
1117
|
+
rawEnv,
|
|
1118
|
+
envName,
|
|
1119
|
+
"durable_objects",
|
|
1120
|
+
validateBindingsProperty(envName, validateDurableObjectBinding),
|
|
1121
|
+
{
|
|
1122
|
+
bindings: [],
|
|
1123
|
+
}
|
|
1124
|
+
),
|
|
1125
|
+
kv_namespaces: notInheritable(
|
|
1126
|
+
diagnostics,
|
|
1127
|
+
topLevelEnv,
|
|
1128
|
+
rawConfig,
|
|
1129
|
+
rawEnv,
|
|
1130
|
+
envName,
|
|
1131
|
+
"kv_namespaces",
|
|
1132
|
+
validateBindingArray(envName, validateKVBinding),
|
|
1133
|
+
[]
|
|
1134
|
+
),
|
|
1135
|
+
send_email: notInheritable(
|
|
1136
|
+
diagnostics,
|
|
1137
|
+
topLevelEnv,
|
|
1138
|
+
rawConfig,
|
|
1139
|
+
rawEnv,
|
|
1140
|
+
envName,
|
|
1141
|
+
"send_email",
|
|
1142
|
+
validateBindingArray(envName, validateSendEmailBinding),
|
|
1143
|
+
[]
|
|
1144
|
+
),
|
|
1145
|
+
queues: notInheritable(
|
|
1146
|
+
diagnostics,
|
|
1147
|
+
topLevelEnv,
|
|
1148
|
+
rawConfig,
|
|
1149
|
+
rawEnv,
|
|
1150
|
+
envName,
|
|
1151
|
+
"queues",
|
|
1152
|
+
validateQueues(envName),
|
|
1153
|
+
{ producers: [], consumers: [] }
|
|
1154
|
+
),
|
|
1155
|
+
r2_buckets: notInheritable(
|
|
1156
|
+
diagnostics,
|
|
1157
|
+
topLevelEnv,
|
|
1158
|
+
rawConfig,
|
|
1159
|
+
rawEnv,
|
|
1160
|
+
envName,
|
|
1161
|
+
"r2_buckets",
|
|
1162
|
+
validateBindingArray(envName, validateR2Binding),
|
|
1163
|
+
[]
|
|
1164
|
+
),
|
|
1165
|
+
d1_databases: notInheritable(
|
|
1166
|
+
diagnostics,
|
|
1167
|
+
topLevelEnv,
|
|
1168
|
+
rawConfig,
|
|
1169
|
+
rawEnv,
|
|
1170
|
+
envName,
|
|
1171
|
+
"d1_databases",
|
|
1172
|
+
validateBindingArray(envName, validateD1Binding),
|
|
1173
|
+
[]
|
|
1174
|
+
),
|
|
1175
|
+
services: notInheritable(
|
|
1176
|
+
diagnostics,
|
|
1177
|
+
topLevelEnv,
|
|
1178
|
+
rawConfig,
|
|
1179
|
+
rawEnv,
|
|
1180
|
+
envName,
|
|
1181
|
+
"services",
|
|
1182
|
+
validateBindingArray(envName, validateServiceBinding),
|
|
1183
|
+
[]
|
|
1184
|
+
),
|
|
1185
|
+
analytics_engine_datasets: notInheritable(
|
|
1186
|
+
diagnostics,
|
|
1187
|
+
topLevelEnv,
|
|
1188
|
+
rawConfig,
|
|
1189
|
+
rawEnv,
|
|
1190
|
+
envName,
|
|
1191
|
+
"analytics_engine_datasets",
|
|
1192
|
+
validateBindingArray(envName, validateAnalyticsEngineBinding),
|
|
1193
|
+
[]
|
|
1194
|
+
),
|
|
1195
|
+
dispatch_namespaces: notInheritable(
|
|
1196
|
+
diagnostics,
|
|
1197
|
+
topLevelEnv,
|
|
1198
|
+
rawConfig,
|
|
1199
|
+
rawEnv,
|
|
1200
|
+
envName,
|
|
1201
|
+
"dispatch_namespaces",
|
|
1202
|
+
validateBindingArray(envName, validateWorkerNamespaceBinding),
|
|
1203
|
+
[]
|
|
1204
|
+
),
|
|
1205
|
+
mtls_certificates: notInheritable(
|
|
1206
|
+
diagnostics,
|
|
1207
|
+
topLevelEnv,
|
|
1208
|
+
rawConfig,
|
|
1209
|
+
rawEnv,
|
|
1210
|
+
envName,
|
|
1211
|
+
"mtls_certificates",
|
|
1212
|
+
validateBindingArray(envName, validateMTlsCertificateBinding),
|
|
1213
|
+
[]
|
|
1214
|
+
),
|
|
1215
|
+
logfwdr: inheritable(
|
|
1216
|
+
diagnostics,
|
|
1217
|
+
topLevelEnv,
|
|
1218
|
+
rawEnv,
|
|
1219
|
+
"logfwdr",
|
|
1220
|
+
validateBindingsProperty(envName, validateCflogfwdrBinding),
|
|
1221
|
+
{
|
|
1222
|
+
schema: undefined,
|
|
1223
|
+
bindings: [],
|
|
1224
|
+
}
|
|
1225
|
+
),
|
|
1226
|
+
unsafe: notInheritable(
|
|
1227
|
+
diagnostics,
|
|
1228
|
+
topLevelEnv,
|
|
1229
|
+
rawConfig,
|
|
1230
|
+
rawEnv,
|
|
1231
|
+
envName,
|
|
1232
|
+
"unsafe",
|
|
1233
|
+
validateUnsafeSettings(envName),
|
|
1234
|
+
{}
|
|
1235
|
+
),
|
|
1236
|
+
zone_id: rawEnv.zone_id,
|
|
1237
|
+
no_bundle: inheritable(
|
|
1238
|
+
diagnostics,
|
|
1239
|
+
topLevelEnv,
|
|
1240
|
+
rawEnv,
|
|
1241
|
+
"no_bundle",
|
|
1242
|
+
isBoolean,
|
|
1243
|
+
undefined
|
|
1244
|
+
),
|
|
1245
|
+
minify: inheritable(
|
|
1246
|
+
diagnostics,
|
|
1247
|
+
topLevelEnv,
|
|
1248
|
+
rawEnv,
|
|
1249
|
+
"minify",
|
|
1250
|
+
isBoolean,
|
|
1251
|
+
undefined
|
|
1252
|
+
),
|
|
1253
|
+
node_compat: inheritable(
|
|
1254
|
+
diagnostics,
|
|
1255
|
+
topLevelEnv,
|
|
1256
|
+
rawEnv,
|
|
1257
|
+
"node_compat",
|
|
1258
|
+
isBoolean,
|
|
1259
|
+
undefined
|
|
1260
|
+
),
|
|
1261
|
+
first_party_worker: inheritable(
|
|
1262
|
+
diagnostics,
|
|
1263
|
+
topLevelEnv,
|
|
1264
|
+
rawEnv,
|
|
1265
|
+
"first_party_worker",
|
|
1266
|
+
isBoolean,
|
|
1267
|
+
undefined
|
|
1268
|
+
),
|
|
1269
|
+
logpush: inheritable(
|
|
1270
|
+
diagnostics,
|
|
1271
|
+
topLevelEnv,
|
|
1272
|
+
rawEnv,
|
|
1273
|
+
"logpush",
|
|
1274
|
+
isBoolean,
|
|
1275
|
+
undefined
|
|
1276
|
+
),
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1279
|
+
return environment;
|
|
962
1280
|
}
|
|
963
1281
|
|
|
964
1282
|
function validateAndNormalizeTsconfig(
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
1283
|
+
diagnostics: Diagnostics,
|
|
1284
|
+
topLevelEnv: Environment | undefined,
|
|
1285
|
+
rawEnv: RawEnvironment,
|
|
1286
|
+
configPath: string | undefined
|
|
969
1287
|
) {
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1288
|
+
const tsconfig = inheritable(
|
|
1289
|
+
diagnostics,
|
|
1290
|
+
topLevelEnv,
|
|
1291
|
+
rawEnv,
|
|
1292
|
+
"tsconfig",
|
|
1293
|
+
isString,
|
|
1294
|
+
undefined
|
|
1295
|
+
);
|
|
1296
|
+
|
|
1297
|
+
return configPath && tsconfig
|
|
1298
|
+
? path.relative(
|
|
1299
|
+
process.cwd(),
|
|
1300
|
+
path.join(path.dirname(configPath), tsconfig)
|
|
1301
|
+
)
|
|
1302
|
+
: tsconfig;
|
|
985
1303
|
}
|
|
986
1304
|
|
|
987
1305
|
const validateAndNormalizeRules = (
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1306
|
+
diagnostics: Diagnostics,
|
|
1307
|
+
topLevelEnv: Environment | undefined,
|
|
1308
|
+
rawEnv: RawEnvironment,
|
|
1309
|
+
deprecatedRules: Rule[] | undefined,
|
|
1310
|
+
envName: string
|
|
993
1311
|
): Rule[] => {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1312
|
+
if (topLevelEnv === undefined) {
|
|
1313
|
+
// Only create errors/warnings for the top-level environment
|
|
1314
|
+
if (rawEnv.rules && deprecatedRules) {
|
|
1315
|
+
diagnostics.errors.push(
|
|
1316
|
+
`You cannot configure both [rules] and [build.upload.rules] in your wrangler.toml. Delete the \`build.upload\` section.`
|
|
1317
|
+
);
|
|
1318
|
+
} else if (deprecatedRules) {
|
|
1319
|
+
diagnostics.warnings.push(
|
|
1320
|
+
`Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this:\n` +
|
|
1321
|
+
"```\n" +
|
|
1322
|
+
TOML.stringify({ rules: deprecatedRules }) +
|
|
1323
|
+
"```"
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
return inheritable(
|
|
1329
|
+
diagnostics,
|
|
1330
|
+
topLevelEnv,
|
|
1331
|
+
rawEnv,
|
|
1332
|
+
"rules",
|
|
1333
|
+
validateRules(envName),
|
|
1334
|
+
deprecatedRules ?? []
|
|
1335
|
+
);
|
|
1018
1336
|
};
|
|
1019
1337
|
|
|
1020
1338
|
const validateRules =
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1339
|
+
(envName: string): ValidatorFn =>
|
|
1340
|
+
(diagnostics, field, envValue, config) => {
|
|
1341
|
+
if (!envValue) {
|
|
1342
|
+
return true;
|
|
1343
|
+
}
|
|
1344
|
+
const fieldPath =
|
|
1345
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1346
|
+
if (!Array.isArray(envValue)) {
|
|
1347
|
+
diagnostics.errors.push(
|
|
1348
|
+
`The field "${fieldPath}" should be an array but got ${JSON.stringify(
|
|
1349
|
+
envValue
|
|
1350
|
+
)}.`
|
|
1351
|
+
);
|
|
1352
|
+
return false;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
let isValid = true;
|
|
1356
|
+
for (let i = 0; i < envValue.length; i++) {
|
|
1357
|
+
isValid =
|
|
1358
|
+
validateRule(diagnostics, `${fieldPath}[${i}]`, envValue[i], config) &&
|
|
1359
|
+
isValid;
|
|
1360
|
+
}
|
|
1361
|
+
return isValid;
|
|
1362
|
+
};
|
|
1045
1363
|
|
|
1046
1364
|
const validateRule: ValidatorFn = (diagnostics, field, value) => {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1365
|
+
if (typeof value !== "object" || value === null) {
|
|
1366
|
+
diagnostics.errors.push(
|
|
1367
|
+
`"${field}" should be an object but got ${JSON.stringify(value)}.`
|
|
1368
|
+
);
|
|
1369
|
+
return false;
|
|
1370
|
+
}
|
|
1371
|
+
// Rules must have a type string and glob string array, and optionally a fallthrough boolean.
|
|
1372
|
+
let isValid = true;
|
|
1373
|
+
const rule = value as Rule;
|
|
1374
|
+
|
|
1375
|
+
if (
|
|
1376
|
+
!isRequiredProperty(rule, "type", "string", [
|
|
1377
|
+
"ESModule",
|
|
1378
|
+
"CommonJS",
|
|
1379
|
+
"CompiledWasm",
|
|
1380
|
+
"Text",
|
|
1381
|
+
"Data",
|
|
1382
|
+
])
|
|
1383
|
+
) {
|
|
1384
|
+
diagnostics.errors.push(
|
|
1385
|
+
`bindings should have a string "type" field, which contains one of "ESModule", "CommonJS", "CompiledWasm", "Text", or "Data".`
|
|
1386
|
+
);
|
|
1387
|
+
isValid = false;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
isValid =
|
|
1391
|
+
validateTypedArray(diagnostics, `${field}.globs`, rule.globs, "string") &&
|
|
1392
|
+
isValid;
|
|
1393
|
+
|
|
1394
|
+
if (!isOptionalProperty(rule, "fallthrough", "boolean")) {
|
|
1395
|
+
diagnostics.errors.push(
|
|
1396
|
+
`the field "fallthrough", when present, should be a boolean.`
|
|
1397
|
+
);
|
|
1398
|
+
isValid = false;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
return isValid;
|
|
1084
1402
|
};
|
|
1085
1403
|
|
|
1404
|
+
const validateDefines =
|
|
1405
|
+
(envName: string): ValidatorFn =>
|
|
1406
|
+
(diagnostics, field, value, config) => {
|
|
1407
|
+
let isValid = true;
|
|
1408
|
+
const fieldPath =
|
|
1409
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1410
|
+
|
|
1411
|
+
if (typeof value === "object" && value !== null) {
|
|
1412
|
+
for (const varName in value) {
|
|
1413
|
+
// some casting here to appease typescript
|
|
1414
|
+
// even though the value might not match the type
|
|
1415
|
+
if (typeof (value as Record<string, string>)[varName] !== "string") {
|
|
1416
|
+
diagnostics.errors.push(
|
|
1417
|
+
`The field "${fieldPath}.${varName}" should be a string but got ${JSON.stringify(
|
|
1418
|
+
(value as Record<string, string>)[varName]
|
|
1419
|
+
)}.`
|
|
1420
|
+
);
|
|
1421
|
+
isValid = false;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
} else {
|
|
1425
|
+
if (value !== undefined) {
|
|
1426
|
+
diagnostics.errors.push(
|
|
1427
|
+
`The field "${fieldPath}" should be an object but got ${JSON.stringify(
|
|
1428
|
+
value
|
|
1429
|
+
)}.\n`
|
|
1430
|
+
);
|
|
1431
|
+
isValid = false;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
const configDefines = Object.keys(config?.define ?? {});
|
|
1436
|
+
|
|
1437
|
+
// If there are no top level vars then there is nothing to do here.
|
|
1438
|
+
if (configDefines.length > 0) {
|
|
1439
|
+
if (typeof value === "object" && value !== null) {
|
|
1440
|
+
const configEnvDefines = config === undefined ? [] : Object.keys(value);
|
|
1441
|
+
|
|
1442
|
+
for (const varName of configDefines) {
|
|
1443
|
+
if (!(varName in value)) {
|
|
1444
|
+
diagnostics.warnings.push(
|
|
1445
|
+
`"define.${varName}" exists at the top level, but not on "${fieldPath}".\n` +
|
|
1446
|
+
`This is not what you probably want, since "define" configuration is not inherited by environments.\n` +
|
|
1447
|
+
`Please add "define.${varName}" to "env.${envName}".`
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
for (const varName of configEnvDefines) {
|
|
1452
|
+
if (!configDefines.includes(varName)) {
|
|
1453
|
+
diagnostics.warnings.push(
|
|
1454
|
+
`"${varName}" exists on "env.${envName}", but not on the top level.\n` +
|
|
1455
|
+
`This is not what you probably want, since "define" configuration within environments can only override existing top level "define" configuration\n` +
|
|
1456
|
+
`Please remove "${fieldPath}.${varName}", or add "define.${varName}".`
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
return isValid;
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1086
1466
|
const validateVars =
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1467
|
+
(envName: string): ValidatorFn =>
|
|
1468
|
+
(diagnostics, field, value, config) => {
|
|
1469
|
+
let isValid = true;
|
|
1470
|
+
const fieldPath =
|
|
1471
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1472
|
+
const configVars = Object.keys(config?.vars ?? {});
|
|
1473
|
+
// If there are no top level vars then there is nothing to do here.
|
|
1474
|
+
if (configVars.length > 0) {
|
|
1475
|
+
if (typeof value !== "object" || value === null) {
|
|
1476
|
+
diagnostics.errors.push(
|
|
1477
|
+
`The field "${fieldPath}" should be an object but got ${JSON.stringify(
|
|
1478
|
+
value
|
|
1479
|
+
)}.\n`
|
|
1480
|
+
);
|
|
1481
|
+
isValid = false;
|
|
1482
|
+
} else {
|
|
1483
|
+
for (const varName of configVars) {
|
|
1484
|
+
if (!(varName in value)) {
|
|
1485
|
+
diagnostics.warnings.push(
|
|
1486
|
+
`"vars.${varName}" exists at the top level, but not on "${fieldPath}".\n` +
|
|
1487
|
+
`This is not what you probably want, since "vars" configuration is not inherited by environments.\n` +
|
|
1488
|
+
`Please add "vars.${varName}" to "env.${envName}".`
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
return isValid;
|
|
1495
|
+
};
|
|
1116
1496
|
|
|
1117
1497
|
const validateBindingsProperty =
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
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
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1498
|
+
(envName: string, validateBinding: ValidatorFn): ValidatorFn =>
|
|
1499
|
+
(diagnostics, field, value, config) => {
|
|
1500
|
+
let isValid = true;
|
|
1501
|
+
const fieldPath =
|
|
1502
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1503
|
+
|
|
1504
|
+
if (value !== undefined) {
|
|
1505
|
+
// Check the validity of the `value` as a bindings container.
|
|
1506
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1507
|
+
diagnostics.errors.push(
|
|
1508
|
+
`The field "${fieldPath}" should be an object but got ${JSON.stringify(
|
|
1509
|
+
value
|
|
1510
|
+
)}.`
|
|
1511
|
+
);
|
|
1512
|
+
isValid = false;
|
|
1513
|
+
} else if (!hasProperty(value, "bindings")) {
|
|
1514
|
+
diagnostics.errors.push(
|
|
1515
|
+
`The field "${fieldPath}" is missing the required "bindings" property.`
|
|
1516
|
+
);
|
|
1517
|
+
isValid = false;
|
|
1518
|
+
} else if (!Array.isArray(value.bindings)) {
|
|
1519
|
+
diagnostics.errors.push(
|
|
1520
|
+
`The field "${fieldPath}.bindings" should be an array but got ${JSON.stringify(
|
|
1521
|
+
value.bindings
|
|
1522
|
+
)}.`
|
|
1523
|
+
);
|
|
1524
|
+
isValid = false;
|
|
1525
|
+
} else {
|
|
1526
|
+
for (let i = 0; i < value.bindings.length; i++) {
|
|
1527
|
+
const binding = value.bindings[i];
|
|
1528
|
+
const bindingDiagnostics = new Diagnostics(
|
|
1529
|
+
`"${fieldPath}.bindings[${i}]": ${JSON.stringify(binding)}`
|
|
1530
|
+
);
|
|
1531
|
+
isValid =
|
|
1532
|
+
validateBinding(
|
|
1533
|
+
bindingDiagnostics,
|
|
1534
|
+
`${fieldPath}.bindings[${i}]`,
|
|
1535
|
+
binding,
|
|
1536
|
+
config
|
|
1537
|
+
) && isValid;
|
|
1538
|
+
diagnostics.addChild(bindingDiagnostics);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
const configBindingNames = getBindingNames(
|
|
1543
|
+
config?.[field as keyof Environment]
|
|
1544
|
+
);
|
|
1545
|
+
if (isValid && configBindingNames.length > 0) {
|
|
1546
|
+
// If there are top level bindings then check that they all appear in the environment.
|
|
1547
|
+
const envBindingNames = new Set(getBindingNames(value));
|
|
1548
|
+
const missingBindings = configBindingNames.filter(
|
|
1549
|
+
(name) => !envBindingNames.has(name)
|
|
1550
|
+
);
|
|
1551
|
+
if (missingBindings.length > 0) {
|
|
1552
|
+
diagnostics.warnings.push(
|
|
1553
|
+
`The following bindings are at the top level, but not on "env.${envName}".\n` +
|
|
1554
|
+
`This is not what you probably want, since "${field}" configuration is not inherited by environments.\n` +
|
|
1555
|
+
`Please add a binding for each to "${fieldPath}.bindings":\n` +
|
|
1556
|
+
missingBindings.map((name) => `- ${name}`).join("\n")
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
return isValid;
|
|
1562
|
+
};
|
|
1563
|
+
|
|
1564
|
+
const validateUnsafeSettings =
|
|
1565
|
+
(envName: string): ValidatorFn =>
|
|
1566
|
+
(diagnostics, field, value, config) => {
|
|
1567
|
+
const fieldPath =
|
|
1568
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1569
|
+
|
|
1570
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1571
|
+
diagnostics.errors.push(
|
|
1572
|
+
`The field "${fieldPath}" should be an object but got ${JSON.stringify(
|
|
1573
|
+
value
|
|
1574
|
+
)}.`
|
|
1575
|
+
);
|
|
1576
|
+
return false;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
// At least one of bindings and metadata must exist
|
|
1580
|
+
if (!hasProperty(value, "bindings") && !hasProperty(value, "metadata")) {
|
|
1581
|
+
diagnostics.errors.push(
|
|
1582
|
+
`The field "${fieldPath}" should contain at least one of "bindings" or "metadata" properties but got ${JSON.stringify(
|
|
1583
|
+
value
|
|
1584
|
+
)}.`
|
|
1585
|
+
);
|
|
1586
|
+
return false;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
// unsafe.bindings
|
|
1590
|
+
if (hasProperty(value, "bindings") && value.bindings !== undefined) {
|
|
1591
|
+
const validateBindingsFn = validateBindingsProperty(
|
|
1592
|
+
envName,
|
|
1593
|
+
validateUnsafeBinding
|
|
1594
|
+
);
|
|
1595
|
+
const valid = validateBindingsFn(diagnostics, field, value, config);
|
|
1596
|
+
if (!valid) {
|
|
1597
|
+
return false;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
// unsafe.metadata
|
|
1602
|
+
if (
|
|
1603
|
+
hasProperty(value, "metadata") &&
|
|
1604
|
+
value.metadata !== undefined &&
|
|
1605
|
+
(typeof value.metadata !== "object" ||
|
|
1606
|
+
value.metadata === null ||
|
|
1607
|
+
Array.isArray(value.metadata))
|
|
1608
|
+
) {
|
|
1609
|
+
diagnostics.errors.push(
|
|
1610
|
+
`The field "${fieldPath}.metadata" should be an object but got ${JSON.stringify(
|
|
1611
|
+
value.metadata
|
|
1612
|
+
)}.`
|
|
1613
|
+
);
|
|
1614
|
+
return false;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
return true;
|
|
1618
|
+
};
|
|
1183
1619
|
|
|
1184
1620
|
/**
|
|
1185
1621
|
* Check that the given field is a valid "durable_object" binding object.
|
|
1186
1622
|
*/
|
|
1187
1623
|
const validateDurableObjectBinding: ValidatorFn = (
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1624
|
+
diagnostics,
|
|
1625
|
+
field,
|
|
1626
|
+
value
|
|
1191
1627
|
) => {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1628
|
+
if (typeof value !== "object" || value === null) {
|
|
1629
|
+
diagnostics.errors.push(
|
|
1630
|
+
`Expected "${field}" to be an object but got ${JSON.stringify(value)}`
|
|
1631
|
+
);
|
|
1632
|
+
return false;
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
// Durable Object bindings must have a name and class_name, and optionally a script_name and an environment.
|
|
1636
|
+
let isValid = true;
|
|
1637
|
+
if (!isRequiredProperty(value, "name", "string")) {
|
|
1638
|
+
diagnostics.errors.push(`binding should have a string "name" field.`);
|
|
1639
|
+
isValid = false;
|
|
1640
|
+
}
|
|
1641
|
+
if (!isRequiredProperty(value, "class_name", "string")) {
|
|
1642
|
+
diagnostics.errors.push(`binding should have a string "class_name" field.`);
|
|
1643
|
+
isValid = false;
|
|
1644
|
+
}
|
|
1645
|
+
if (!isOptionalProperty(value, "script_name", "string")) {
|
|
1646
|
+
diagnostics.errors.push(
|
|
1647
|
+
`the field "script_name", when present, should be a string.`
|
|
1648
|
+
);
|
|
1649
|
+
isValid = false;
|
|
1650
|
+
}
|
|
1651
|
+
// environment requires a script_name
|
|
1652
|
+
if (!isOptionalProperty(value, "environment", "string")) {
|
|
1653
|
+
diagnostics.errors.push(
|
|
1654
|
+
`the field "environment", when present, should be a string.`
|
|
1655
|
+
);
|
|
1656
|
+
isValid = false;
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
if ("environment" in value && !("script_name" in value)) {
|
|
1660
|
+
diagnostics.errors.push(
|
|
1661
|
+
`binding should have a "script_name" field if "environment" is present.`
|
|
1662
|
+
);
|
|
1663
|
+
isValid = false;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
return isValid;
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1669
|
+
const validateCflogfwdrBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
1670
|
+
if (typeof value !== "object" || value === null) {
|
|
1671
|
+
diagnostics.errors.push(
|
|
1672
|
+
`Expected "${field}" to be an object but got ${JSON.stringify(value)}`
|
|
1673
|
+
);
|
|
1674
|
+
return false;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
let isValid = true;
|
|
1678
|
+
if (!isRequiredProperty(value, "name", "string")) {
|
|
1679
|
+
diagnostics.errors.push(`binding should have a string "name" field.`);
|
|
1680
|
+
isValid = false;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
if (!isRequiredProperty(value, "destination", "string")) {
|
|
1684
|
+
diagnostics.errors.push(
|
|
1685
|
+
`binding should have a string "destination" field.`
|
|
1686
|
+
);
|
|
1687
|
+
isValid = false;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
return isValid;
|
|
1231
1691
|
};
|
|
1232
1692
|
|
|
1233
1693
|
/**
|
|
@@ -1236,173 +1696,317 @@ const validateDurableObjectBinding: ValidatorFn = (
|
|
|
1236
1696
|
* TODO: further validation of known unsafe bindings.
|
|
1237
1697
|
*/
|
|
1238
1698
|
const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1699
|
+
if (typeof value !== "object" || value === null) {
|
|
1700
|
+
diagnostics.errors.push(
|
|
1701
|
+
`Expected ${field} to be an object but got ${JSON.stringify(value)}.`
|
|
1702
|
+
);
|
|
1703
|
+
return false;
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
let isValid = true;
|
|
1707
|
+
// Unsafe bindings must have a name and type.
|
|
1708
|
+
if (!isRequiredProperty(value, "name", "string")) {
|
|
1709
|
+
diagnostics.errors.push(`binding should have a string "name" field.`);
|
|
1710
|
+
isValid = false;
|
|
1711
|
+
}
|
|
1712
|
+
if (isRequiredProperty(value, "type", "string")) {
|
|
1713
|
+
const safeBindings = [
|
|
1714
|
+
"plain_text",
|
|
1715
|
+
"json",
|
|
1716
|
+
"wasm_module",
|
|
1717
|
+
"data_blob",
|
|
1718
|
+
"text_blob",
|
|
1719
|
+
"kv_namespace",
|
|
1720
|
+
"durable_object_namespace",
|
|
1721
|
+
"d1_database",
|
|
1722
|
+
"r2_bucket",
|
|
1723
|
+
"service",
|
|
1724
|
+
"logfwdr",
|
|
1725
|
+
"mtls_certificate",
|
|
1726
|
+
];
|
|
1727
|
+
|
|
1728
|
+
if (safeBindings.includes(value.type)) {
|
|
1729
|
+
diagnostics.warnings.push(
|
|
1730
|
+
`The binding type "${value.type}" is directly supported by wrangler.\n` +
|
|
1731
|
+
`Consider migrating this unsafe binding to a format for '${value.type}' bindings that is supported by wrangler for optimal support.\n` +
|
|
1732
|
+
"For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration"
|
|
1733
|
+
);
|
|
1734
|
+
}
|
|
1735
|
+
} else {
|
|
1736
|
+
diagnostics.errors.push(`binding should have a string "type" field.`);
|
|
1737
|
+
isValid = false;
|
|
1738
|
+
}
|
|
1739
|
+
return isValid;
|
|
1277
1740
|
};
|
|
1278
1741
|
|
|
1279
1742
|
/**
|
|
1280
1743
|
* Check that the given environment field is a valid array of bindings.
|
|
1281
1744
|
*/
|
|
1282
1745
|
const validateBindingArray =
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1746
|
+
(envName: string, validateBinding: ValidatorFn): ValidatorFn =>
|
|
1747
|
+
(diagnostics, field, envValue, config) => {
|
|
1748
|
+
if (envValue === undefined) {
|
|
1749
|
+
return true;
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
const fieldPath =
|
|
1753
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1754
|
+
if (!Array.isArray(envValue)) {
|
|
1755
|
+
diagnostics.errors.push(
|
|
1756
|
+
`The field "${fieldPath}" should be an array but got ${JSON.stringify(
|
|
1757
|
+
envValue
|
|
1758
|
+
)}.`
|
|
1759
|
+
);
|
|
1760
|
+
return false;
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
let isValid = true;
|
|
1764
|
+
for (let i = 0; i < envValue.length; i++) {
|
|
1765
|
+
isValid =
|
|
1766
|
+
validateBinding(
|
|
1767
|
+
diagnostics,
|
|
1768
|
+
`${fieldPath}[${i}]`,
|
|
1769
|
+
envValue[i],
|
|
1770
|
+
config
|
|
1771
|
+
) && isValid;
|
|
1772
|
+
}
|
|
1773
|
+
const configValue = config?.[field as keyof Environment] as {
|
|
1774
|
+
binding: unknown;
|
|
1775
|
+
}[];
|
|
1776
|
+
if (Array.isArray(configValue)) {
|
|
1777
|
+
const configBindingNames = configValue.map((value) => value.binding);
|
|
1778
|
+
// If there are no top level bindings then there is nothing to do here.
|
|
1779
|
+
if (configBindingNames.length > 0) {
|
|
1780
|
+
const envBindingNames = new Set(envValue.map((value) => value.binding));
|
|
1781
|
+
for (const configBindingName of configBindingNames) {
|
|
1782
|
+
if (!envBindingNames.has(configBindingName)) {
|
|
1783
|
+
diagnostics.warnings.push(
|
|
1784
|
+
`There is a ${field} binding with name "${configBindingName}" at the top level, but not on "env.${envName}".\n` +
|
|
1785
|
+
`This is not what you probably want, since "${field}" configuration is not inherited by environments.\n` +
|
|
1786
|
+
`Please add a binding for "${configBindingName}" to "env.${envName}.${field}.bindings".`
|
|
1787
|
+
);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
return isValid;
|
|
1793
|
+
};
|
|
1331
1794
|
|
|
1332
1795
|
const validateKVBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1796
|
+
if (typeof value !== "object" || value === null) {
|
|
1797
|
+
diagnostics.errors.push(
|
|
1798
|
+
`"kv_namespaces" bindings should be objects, but got ${JSON.stringify(
|
|
1799
|
+
value
|
|
1800
|
+
)}`
|
|
1801
|
+
);
|
|
1802
|
+
return false;
|
|
1803
|
+
}
|
|
1804
|
+
let isValid = true;
|
|
1805
|
+
// KV bindings must have a binding and id.
|
|
1806
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
1807
|
+
diagnostics.errors.push(
|
|
1808
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
1809
|
+
value
|
|
1810
|
+
)}.`
|
|
1811
|
+
);
|
|
1812
|
+
isValid = false;
|
|
1813
|
+
}
|
|
1814
|
+
if (
|
|
1815
|
+
!isRequiredProperty(value, "id", "string") ||
|
|
1816
|
+
(value as { id: string }).id.length === 0
|
|
1817
|
+
) {
|
|
1818
|
+
diagnostics.errors.push(
|
|
1819
|
+
`"${field}" bindings should have a string "id" field but got ${JSON.stringify(
|
|
1820
|
+
value
|
|
1821
|
+
)}.`
|
|
1822
|
+
);
|
|
1823
|
+
isValid = false;
|
|
1824
|
+
}
|
|
1825
|
+
if (!isOptionalProperty(value, "preview_id", "string")) {
|
|
1826
|
+
diagnostics.errors.push(
|
|
1827
|
+
`"${field}" bindings should, optionally, have a string "preview_id" field but got ${JSON.stringify(
|
|
1828
|
+
value
|
|
1829
|
+
)}.`
|
|
1830
|
+
);
|
|
1831
|
+
isValid = false;
|
|
1832
|
+
}
|
|
1833
|
+
return isValid;
|
|
1834
|
+
};
|
|
1835
|
+
|
|
1836
|
+
const validateSendEmailBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
1837
|
+
if (typeof value !== "object" || value === null) {
|
|
1838
|
+
diagnostics.errors.push(
|
|
1839
|
+
`"send_email" bindings should be objects, but got ${JSON.stringify(
|
|
1840
|
+
value
|
|
1841
|
+
)}`
|
|
1842
|
+
);
|
|
1843
|
+
return false;
|
|
1844
|
+
}
|
|
1845
|
+
let isValid = true;
|
|
1846
|
+
// send email bindings must have a name.
|
|
1847
|
+
if (!isRequiredProperty(value, "name", "string")) {
|
|
1848
|
+
diagnostics.errors.push(
|
|
1849
|
+
`"${field}" bindings should have a string "name" field but got ${JSON.stringify(
|
|
1850
|
+
value
|
|
1851
|
+
)}.`
|
|
1852
|
+
);
|
|
1853
|
+
isValid = false;
|
|
1854
|
+
}
|
|
1855
|
+
if (!isOptionalProperty(value, "destination_address", "string")) {
|
|
1856
|
+
diagnostics.errors.push(
|
|
1857
|
+
`"${field}" bindings should, optionally, have a string "destination_address" field but got ${JSON.stringify(
|
|
1858
|
+
value
|
|
1859
|
+
)}.`
|
|
1860
|
+
);
|
|
1861
|
+
isValid = false;
|
|
1862
|
+
}
|
|
1863
|
+
if (!isOptionalProperty(value, "allowed_destination_addresses", "object")) {
|
|
1864
|
+
diagnostics.errors.push(
|
|
1865
|
+
`"${field}" bindings should, optionally, have a []string "allowed_destination_addresses" field but got ${JSON.stringify(
|
|
1866
|
+
value
|
|
1867
|
+
)}.`
|
|
1868
|
+
);
|
|
1869
|
+
isValid = false;
|
|
1870
|
+
}
|
|
1871
|
+
if (
|
|
1872
|
+
"destination_address" in value &&
|
|
1873
|
+
"allowed_destination_addresses" in value
|
|
1874
|
+
) {
|
|
1875
|
+
diagnostics.errors.push(
|
|
1876
|
+
`"${field}" bindings should have either a "destination_address" or "allowed_destination_addresses" field, but not both.`
|
|
1877
|
+
);
|
|
1878
|
+
isValid = false;
|
|
1879
|
+
}
|
|
1880
|
+
return isValid;
|
|
1881
|
+
};
|
|
1882
|
+
|
|
1883
|
+
const validateQueueBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
1884
|
+
if (typeof value !== "object" || value === null) {
|
|
1885
|
+
diagnostics.errors.push(
|
|
1886
|
+
`"queue" bindings should be objects, but got ${JSON.stringify(value)}`
|
|
1887
|
+
);
|
|
1888
|
+
return false;
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
if (
|
|
1892
|
+
!validateAdditionalProperties(diagnostics, field, Object.keys(value), [
|
|
1893
|
+
"binding",
|
|
1894
|
+
"queue",
|
|
1895
|
+
])
|
|
1896
|
+
) {
|
|
1897
|
+
return false;
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
// Queue bindings must have a binding and queue.
|
|
1901
|
+
let isValid = true;
|
|
1902
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
1903
|
+
diagnostics.errors.push(
|
|
1904
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
1905
|
+
value
|
|
1906
|
+
)}.`
|
|
1907
|
+
);
|
|
1908
|
+
isValid = false;
|
|
1909
|
+
}
|
|
1910
|
+
if (
|
|
1911
|
+
!isRequiredProperty(value, "queue", "string") ||
|
|
1912
|
+
(value as { queue: string }).queue.length === 0
|
|
1913
|
+
) {
|
|
1914
|
+
diagnostics.errors.push(
|
|
1915
|
+
`"${field}" bindings should have a string "queue" field but got ${JSON.stringify(
|
|
1916
|
+
value
|
|
1917
|
+
)}.`
|
|
1918
|
+
);
|
|
1919
|
+
isValid = false;
|
|
1920
|
+
}
|
|
1921
|
+
return isValid;
|
|
1368
1922
|
};
|
|
1369
1923
|
|
|
1370
1924
|
const validateR2Binding: ValidatorFn = (diagnostics, field, value) => {
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1925
|
+
if (typeof value !== "object" || value === null) {
|
|
1926
|
+
diagnostics.errors.push(
|
|
1927
|
+
`"r2_buckets" bindings should be objects, but got ${JSON.stringify(
|
|
1928
|
+
value
|
|
1929
|
+
)}`
|
|
1930
|
+
);
|
|
1931
|
+
return false;
|
|
1932
|
+
}
|
|
1933
|
+
let isValid = true;
|
|
1934
|
+
// R2 bindings must have a binding and bucket_name.
|
|
1935
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
1936
|
+
diagnostics.errors.push(
|
|
1937
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
1938
|
+
value
|
|
1939
|
+
)}.`
|
|
1940
|
+
);
|
|
1941
|
+
isValid = false;
|
|
1942
|
+
}
|
|
1943
|
+
if (
|
|
1944
|
+
!isRequiredProperty(value, "bucket_name", "string") ||
|
|
1945
|
+
(value as { bucket_name: string }).bucket_name.length === 0
|
|
1946
|
+
) {
|
|
1947
|
+
diagnostics.errors.push(
|
|
1948
|
+
`"${field}" bindings should have a string "bucket_name" field but got ${JSON.stringify(
|
|
1949
|
+
value
|
|
1950
|
+
)}.`
|
|
1951
|
+
);
|
|
1952
|
+
isValid = false;
|
|
1953
|
+
}
|
|
1954
|
+
if (!isOptionalProperty(value, "preview_bucket_name", "string")) {
|
|
1955
|
+
diagnostics.errors.push(
|
|
1956
|
+
`"${field}" bindings should, optionally, have a string "preview_bucket_name" field but got ${JSON.stringify(
|
|
1957
|
+
value
|
|
1958
|
+
)}.`
|
|
1959
|
+
);
|
|
1960
|
+
isValid = false;
|
|
1961
|
+
}
|
|
1962
|
+
return isValid;
|
|
1963
|
+
};
|
|
1964
|
+
|
|
1965
|
+
const validateD1Binding: ValidatorFn = (diagnostics, field, value) => {
|
|
1966
|
+
if (typeof value !== "object" || value === null) {
|
|
1967
|
+
diagnostics.errors.push(
|
|
1968
|
+
`"d1_databases" bindings should be objects, but got ${JSON.stringify(
|
|
1969
|
+
value
|
|
1970
|
+
)}`
|
|
1971
|
+
);
|
|
1972
|
+
return false;
|
|
1973
|
+
}
|
|
1974
|
+
let isValid = true;
|
|
1975
|
+
// D1 databases must have a binding and either a database_name or database_id.
|
|
1976
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
1977
|
+
diagnostics.errors.push(
|
|
1978
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
1979
|
+
value
|
|
1980
|
+
)}.`
|
|
1981
|
+
);
|
|
1982
|
+
isValid = false;
|
|
1983
|
+
}
|
|
1984
|
+
if (
|
|
1985
|
+
// TODO: allow name only, where we look up the ID dynamically
|
|
1986
|
+
// !isOptionalProperty(value, "database_name", "string") &&
|
|
1987
|
+
!isRequiredProperty(value, "database_id", "string")
|
|
1988
|
+
) {
|
|
1989
|
+
diagnostics.errors.push(
|
|
1990
|
+
`"${field}" bindings must have a "database_id" field but got ${JSON.stringify(
|
|
1991
|
+
value
|
|
1992
|
+
)}.`
|
|
1993
|
+
);
|
|
1994
|
+
isValid = false;
|
|
1995
|
+
}
|
|
1996
|
+
if (!isOptionalProperty(value, "preview_database_id", "string")) {
|
|
1997
|
+
diagnostics.errors.push(
|
|
1998
|
+
`"${field}" bindings should, optionally, have a string "preview_database_id" field but got ${JSON.stringify(
|
|
1999
|
+
value
|
|
2000
|
+
)}.`
|
|
2001
|
+
);
|
|
2002
|
+
isValid = false;
|
|
2003
|
+
}
|
|
2004
|
+
if (isValid && !process.env.NO_D1_WARNING) {
|
|
2005
|
+
diagnostics.warnings.push(
|
|
2006
|
+
"D1 Bindings are currently in alpha to allow the API to evolve before general availability.\nPlease report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose\nNote: Run this command with the environment variable NO_D1_WARNING=true to hide this message\n\nFor example: `export NO_D1_WARNING=true && wrangler <YOUR COMMAND HERE>`"
|
|
2007
|
+
);
|
|
2008
|
+
}
|
|
2009
|
+
return isValid;
|
|
1406
2010
|
};
|
|
1407
2011
|
|
|
1408
2012
|
/**
|
|
@@ -1414,126 +2018,352 @@ const validateR2Binding: ValidatorFn = (diagnostics, field, value) => {
|
|
|
1414
2018
|
* the `DATA` global).
|
|
1415
2019
|
*/
|
|
1416
2020
|
const validateBindingsHaveUniqueNames = (
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
2021
|
+
diagnostics: Diagnostics,
|
|
2022
|
+
{
|
|
2023
|
+
durable_objects,
|
|
2024
|
+
kv_namespaces,
|
|
2025
|
+
r2_buckets,
|
|
2026
|
+
analytics_engine_datasets,
|
|
2027
|
+
text_blobs,
|
|
2028
|
+
unsafe,
|
|
2029
|
+
vars,
|
|
2030
|
+
define,
|
|
2031
|
+
wasm_modules,
|
|
2032
|
+
data_blobs,
|
|
2033
|
+
}: Partial<Config>
|
|
1428
2034
|
): boolean => {
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
2035
|
+
let hasDuplicates = false;
|
|
2036
|
+
|
|
2037
|
+
const bindingsGroupedByType = {
|
|
2038
|
+
"Durable Object": getBindingNames(durable_objects),
|
|
2039
|
+
"KV Namespace": getBindingNames(kv_namespaces),
|
|
2040
|
+
"R2 Bucket": getBindingNames(r2_buckets),
|
|
2041
|
+
"Analytics Engine Dataset": getBindingNames(analytics_engine_datasets),
|
|
2042
|
+
"Text Blob": getBindingNames(text_blobs),
|
|
2043
|
+
Unsafe: getBindingNames(unsafe),
|
|
2044
|
+
"Environment Variable": getBindingNames(vars),
|
|
2045
|
+
Definition: getBindingNames(define),
|
|
2046
|
+
"WASM Module": getBindingNames(wasm_modules),
|
|
2047
|
+
"Data Blob": getBindingNames(data_blobs),
|
|
2048
|
+
} as Record<string, string[]>;
|
|
2049
|
+
|
|
2050
|
+
const bindingsGroupedByName: Record<string, string[]> = {};
|
|
2051
|
+
|
|
2052
|
+
for (const bindingType in bindingsGroupedByType) {
|
|
2053
|
+
const bindingNames = bindingsGroupedByType[bindingType];
|
|
2054
|
+
|
|
2055
|
+
for (const bindingName of bindingNames) {
|
|
2056
|
+
if (!(bindingName in bindingsGroupedByName)) {
|
|
2057
|
+
bindingsGroupedByName[bindingName] = [];
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
bindingsGroupedByName[bindingName].push(bindingType);
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
for (const bindingName in bindingsGroupedByName) {
|
|
2065
|
+
const bindingTypes = bindingsGroupedByName[bindingName];
|
|
2066
|
+
if (bindingTypes.length < 2) {
|
|
2067
|
+
// there's only one (or zero) binding(s) with this name, which is fine, actually
|
|
2068
|
+
continue;
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
hasDuplicates = true;
|
|
2072
|
+
|
|
2073
|
+
// there's two types of duplicates we want to look for:
|
|
2074
|
+
// - bindings with the same name of the same type (e.g. two Durable Objects both named "OBJ")
|
|
2075
|
+
// - bindings with the same name of different types (a KV namespace and DO both named "DATA")
|
|
2076
|
+
|
|
2077
|
+
const sameType = bindingTypes
|
|
2078
|
+
// filter once to find duplicate binding types
|
|
2079
|
+
.filter((type, i) => bindingTypes.indexOf(type) !== i)
|
|
2080
|
+
// filter twice to only get _unique_ duplicate binding types
|
|
2081
|
+
.filter(
|
|
2082
|
+
(type, i, duplicateBindingTypes) =>
|
|
2083
|
+
duplicateBindingTypes.indexOf(type) === i
|
|
2084
|
+
);
|
|
2085
|
+
|
|
2086
|
+
const differentTypes = bindingTypes.filter(
|
|
2087
|
+
(type, i) => bindingTypes.indexOf(type) === i
|
|
2088
|
+
);
|
|
2089
|
+
|
|
2090
|
+
if (differentTypes.length > 1) {
|
|
2091
|
+
// we have multiple different types using the same name
|
|
2092
|
+
diagnostics.errors.push(
|
|
2093
|
+
`${bindingName} assigned to ${ENGLISH.format(differentTypes)} bindings.`
|
|
2094
|
+
);
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
sameType.forEach((bindingType) => {
|
|
2098
|
+
diagnostics.errors.push(
|
|
2099
|
+
`${bindingName} assigned to multiple ${bindingType} bindings.`
|
|
2100
|
+
);
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
if (hasDuplicates) {
|
|
2105
|
+
const problem =
|
|
2106
|
+
"Bindings must have unique names, so that they can all be referenced in the worker.";
|
|
2107
|
+
const resolution = "Please change your bindings to have unique names.";
|
|
2108
|
+
diagnostics.errors.push(`${problem}\n${resolution}`);
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
return !hasDuplicates;
|
|
1504
2112
|
};
|
|
2113
|
+
|
|
1505
2114
|
const validateServiceBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
2115
|
+
if (typeof value !== "object" || value === null) {
|
|
2116
|
+
diagnostics.errors.push(
|
|
2117
|
+
`"services" bindings should be objects, but got ${JSON.stringify(value)}`
|
|
2118
|
+
);
|
|
2119
|
+
return false;
|
|
2120
|
+
}
|
|
2121
|
+
let isValid = true;
|
|
2122
|
+
// Service bindings must have a binding, service, and environment.
|
|
2123
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
2124
|
+
diagnostics.errors.push(
|
|
2125
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
2126
|
+
value
|
|
2127
|
+
)}.`
|
|
2128
|
+
);
|
|
2129
|
+
isValid = false;
|
|
2130
|
+
}
|
|
2131
|
+
if (!isRequiredProperty(value, "service", "string")) {
|
|
2132
|
+
diagnostics.errors.push(
|
|
2133
|
+
`"${field}" bindings should have a string "service" field but got ${JSON.stringify(
|
|
2134
|
+
value
|
|
2135
|
+
)}.`
|
|
2136
|
+
);
|
|
2137
|
+
isValid = false;
|
|
2138
|
+
}
|
|
2139
|
+
if (!isOptionalProperty(value, "environment", "string")) {
|
|
2140
|
+
diagnostics.errors.push(
|
|
2141
|
+
`"${field}" bindings should have a string "environment" field but got ${JSON.stringify(
|
|
2142
|
+
value
|
|
2143
|
+
)}.`
|
|
2144
|
+
);
|
|
2145
|
+
isValid = false;
|
|
2146
|
+
}
|
|
2147
|
+
return isValid;
|
|
2148
|
+
};
|
|
2149
|
+
|
|
2150
|
+
const validateAnalyticsEngineBinding: ValidatorFn = (
|
|
2151
|
+
diagnostics,
|
|
2152
|
+
field,
|
|
2153
|
+
value
|
|
2154
|
+
) => {
|
|
2155
|
+
if (typeof value !== "object" || value === null) {
|
|
2156
|
+
diagnostics.errors.push(
|
|
2157
|
+
`"analytics_engine" bindings should be objects, but got ${JSON.stringify(
|
|
2158
|
+
value
|
|
2159
|
+
)}`
|
|
2160
|
+
);
|
|
2161
|
+
return false;
|
|
2162
|
+
}
|
|
2163
|
+
let isValid = true;
|
|
2164
|
+
// Service bindings must have a binding and optional dataset.
|
|
2165
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
2166
|
+
diagnostics.errors.push(
|
|
2167
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
2168
|
+
value
|
|
2169
|
+
)}.`
|
|
2170
|
+
);
|
|
2171
|
+
isValid = false;
|
|
2172
|
+
}
|
|
2173
|
+
if (
|
|
2174
|
+
!isOptionalProperty(value, "dataset", "string") ||
|
|
2175
|
+
(value as { dataset: string }).dataset?.length === 0
|
|
2176
|
+
) {
|
|
2177
|
+
diagnostics.errors.push(
|
|
2178
|
+
`"${field}" bindings should, optionally, have a string "dataset" field but got ${JSON.stringify(
|
|
2179
|
+
value
|
|
2180
|
+
)}.`
|
|
2181
|
+
);
|
|
2182
|
+
isValid = false;
|
|
2183
|
+
}
|
|
2184
|
+
return isValid;
|
|
2185
|
+
};
|
|
2186
|
+
|
|
2187
|
+
const validateWorkerNamespaceBinding: ValidatorFn = (
|
|
2188
|
+
diagnostics,
|
|
2189
|
+
field,
|
|
2190
|
+
value
|
|
2191
|
+
) => {
|
|
2192
|
+
if (typeof value !== "object" || value === null) {
|
|
2193
|
+
diagnostics.errors.push(
|
|
2194
|
+
`"${field}" binding should be objects, but got ${JSON.stringify(value)}`
|
|
2195
|
+
);
|
|
2196
|
+
return false;
|
|
2197
|
+
}
|
|
2198
|
+
let isValid = true;
|
|
2199
|
+
// Worker namespace bindings must have a binding, and a namespace.
|
|
2200
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
2201
|
+
diagnostics.errors.push(
|
|
2202
|
+
`"${field}" should have a string "binding" field but got ${JSON.stringify(
|
|
2203
|
+
value
|
|
2204
|
+
)}.`
|
|
2205
|
+
);
|
|
2206
|
+
isValid = false;
|
|
2207
|
+
}
|
|
2208
|
+
if (!isRequiredProperty(value, "namespace", "string")) {
|
|
2209
|
+
diagnostics.errors.push(
|
|
2210
|
+
`"${field}" should have a string "namespace" field but got ${JSON.stringify(
|
|
2211
|
+
value
|
|
2212
|
+
)}.`
|
|
2213
|
+
);
|
|
2214
|
+
isValid = false;
|
|
2215
|
+
}
|
|
2216
|
+
return isValid;
|
|
2217
|
+
};
|
|
2218
|
+
|
|
2219
|
+
const validateMTlsCertificateBinding: ValidatorFn = (
|
|
2220
|
+
diagnostics,
|
|
2221
|
+
field,
|
|
2222
|
+
value
|
|
2223
|
+
) => {
|
|
2224
|
+
if (typeof value !== "object" || value === null) {
|
|
2225
|
+
diagnostics.errors.push(
|
|
2226
|
+
`"mtls_certificates" bindings should be objects, but got ${JSON.stringify(
|
|
2227
|
+
value
|
|
2228
|
+
)}`
|
|
2229
|
+
);
|
|
2230
|
+
return false;
|
|
2231
|
+
}
|
|
2232
|
+
let isValid = true;
|
|
2233
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
2234
|
+
diagnostics.errors.push(
|
|
2235
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
2236
|
+
value
|
|
2237
|
+
)}.`
|
|
2238
|
+
);
|
|
2239
|
+
isValid = false;
|
|
2240
|
+
}
|
|
2241
|
+
if (
|
|
2242
|
+
!isRequiredProperty(value, "certificate_id", "string") ||
|
|
2243
|
+
(value as { certificate_id: string }).certificate_id.length === 0
|
|
2244
|
+
) {
|
|
2245
|
+
diagnostics.errors.push(
|
|
2246
|
+
`"${field}" bindings should have a string "certificate_id" field but got ${JSON.stringify(
|
|
2247
|
+
value
|
|
2248
|
+
)}.`
|
|
2249
|
+
);
|
|
2250
|
+
isValid = false;
|
|
2251
|
+
}
|
|
2252
|
+
return isValid;
|
|
2253
|
+
};
|
|
2254
|
+
|
|
2255
|
+
function validateQueues(envName: string): ValidatorFn {
|
|
2256
|
+
return (diagnostics, field, value, config) => {
|
|
2257
|
+
const fieldPath =
|
|
2258
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
2259
|
+
|
|
2260
|
+
if (typeof value !== "object" || Array.isArray(value) || value === null) {
|
|
2261
|
+
diagnostics.errors.push(
|
|
2262
|
+
`The field "${fieldPath}" should be an object but got ${JSON.stringify(
|
|
2263
|
+
value
|
|
2264
|
+
)}.`
|
|
2265
|
+
);
|
|
2266
|
+
return false;
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
let isValid = true;
|
|
2270
|
+
if (
|
|
2271
|
+
!validateAdditionalProperties(
|
|
2272
|
+
diagnostics,
|
|
2273
|
+
fieldPath,
|
|
2274
|
+
Object.keys(value),
|
|
2275
|
+
["consumers", "producers"]
|
|
2276
|
+
)
|
|
2277
|
+
) {
|
|
2278
|
+
isValid = false;
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
if (hasProperty(value, "consumers")) {
|
|
2282
|
+
const consumers = value.consumers;
|
|
2283
|
+
if (!Array.isArray(consumers)) {
|
|
2284
|
+
diagnostics.errors.push(
|
|
2285
|
+
`The field "${fieldPath}.consumers" should be an array but got ${JSON.stringify(
|
|
2286
|
+
consumers
|
|
2287
|
+
)}.`
|
|
2288
|
+
);
|
|
2289
|
+
isValid = false;
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
for (let i = 0; i < consumers.length; i++) {
|
|
2293
|
+
const consumer = consumers[i];
|
|
2294
|
+
const consumerPath = `${fieldPath}.consumers[${i}]`;
|
|
2295
|
+
if (!validateConsumer(diagnostics, consumerPath, consumer, config)) {
|
|
2296
|
+
isValid = false;
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
if (hasProperty(value, "producers")) {
|
|
2302
|
+
if (
|
|
2303
|
+
!validateBindingArray(envName, validateQueueBinding)(
|
|
2304
|
+
diagnostics,
|
|
2305
|
+
`${field}.producers`,
|
|
2306
|
+
value.producers,
|
|
2307
|
+
config
|
|
2308
|
+
)
|
|
2309
|
+
) {
|
|
2310
|
+
isValid = false;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
return isValid;
|
|
2314
|
+
};
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
const validateConsumer: ValidatorFn = (diagnostics, field, value, _config) => {
|
|
2318
|
+
if (typeof value !== "object" || value === null) {
|
|
2319
|
+
diagnostics.errors.push(
|
|
2320
|
+
`"${field}" should be a objects, but got ${JSON.stringify(value)}`
|
|
2321
|
+
);
|
|
2322
|
+
return false;
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
let isValid = true;
|
|
2326
|
+
if (
|
|
2327
|
+
!validateAdditionalProperties(diagnostics, field, Object.keys(value), [
|
|
2328
|
+
"queue",
|
|
2329
|
+
"max_batch_size",
|
|
2330
|
+
"max_batch_timeout",
|
|
2331
|
+
"max_retries",
|
|
2332
|
+
"dead_letter_queue",
|
|
2333
|
+
"max_concurrency",
|
|
2334
|
+
])
|
|
2335
|
+
) {
|
|
2336
|
+
isValid = false;
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
if (!isRequiredProperty(value, "queue", "string")) {
|
|
2340
|
+
diagnostics.errors.push(
|
|
2341
|
+
`"${field}" should have a string "queue" field but got ${JSON.stringify(
|
|
2342
|
+
value
|
|
2343
|
+
)}.`
|
|
2344
|
+
);
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
const options: {
|
|
2348
|
+
key: string;
|
|
2349
|
+
type: "number" | "string" | "boolean";
|
|
2350
|
+
}[] = [
|
|
2351
|
+
{ key: "max_batch_size", type: "number" },
|
|
2352
|
+
{ key: "max_batch_timeout", type: "number" },
|
|
2353
|
+
{ key: "max_retries", type: "number" },
|
|
2354
|
+
{ key: "dead_letter_queue", type: "string" },
|
|
2355
|
+
{ key: "max_concurrency", type: "number" },
|
|
2356
|
+
];
|
|
2357
|
+
for (const optionalOpt of options) {
|
|
2358
|
+
if (!isOptionalProperty(value, optionalOpt.key, optionalOpt.type)) {
|
|
2359
|
+
diagnostics.errors.push(
|
|
2360
|
+
`"${field}" should, optionally, have a ${optionalOpt.type} "${
|
|
2361
|
+
optionalOpt.key
|
|
2362
|
+
}" field but got ${JSON.stringify(value)}.`
|
|
2363
|
+
);
|
|
2364
|
+
isValid = false;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
return isValid;
|
|
1539
2369
|
};
|