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