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