wrangler 0.0.0-e95bea2 → 0.0.0-ea8e701
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 +3 -3
- package/bin/wrangler.js +10 -1
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +7 -6
- package/pages/functions/filepath-routing.test.ts +125 -25
- package/pages/functions/filepath-routing.ts +6 -3
- package/src/__tests__/configuration.test.ts +826 -223
- package/src/__tests__/dev.test.tsx +145 -9
- package/src/__tests__/guess-worker-format.test.ts +26 -1
- package/src/__tests__/helpers/mock-account-id.ts +4 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +178 -0
- package/src/__tests__/helpers/run-in-tmp.ts +3 -0
- package/src/__tests__/index.test.ts +9 -13
- package/src/__tests__/jest.setup.ts +5 -0
- package/src/__tests__/kv.test.ts +43 -71
- package/src/__tests__/pages.test.ts +48 -10
- package/src/__tests__/publish.test.ts +1456 -327
- package/src/__tests__/r2.test.ts +4 -4
- package/src/__tests__/tail.test.ts +78 -4
- package/src/__tests__/user.test.ts +83 -0
- package/src/__tests__/whoami.test.tsx +16 -7
- package/src/bundle.ts +15 -2
- package/src/cfetch/internal.ts +9 -5
- package/src/config/README.md +6 -6
- package/src/config/config.ts +17 -78
- package/src/config/environment.ts +67 -1
- package/src/config/index.ts +13 -3
- package/src/config/validation-helpers.ts +177 -11
- package/src/config/validation.ts +305 -100
- package/src/dev/dev.tsx +76 -41
- package/src/dev/local.tsx +105 -114
- package/src/dev/remote.tsx +2 -0
- package/src/dev/use-esbuild.ts +4 -0
- package/src/entry.ts +103 -6
- package/src/index.tsx +251 -189
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv/index.tsx → kv.ts} +8 -28
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +37 -0
- package/src/module-collection.ts +58 -53
- package/src/pages.tsx +26 -10
- package/src/proxy.ts +5 -3
- package/src/publish.ts +17 -21
- package/src/sites.tsx +67 -25
- package/src/tail/index.ts +1 -1
- package/src/tail/printing.ts +2 -2
- package/src/user.tsx +161 -81
- package/wrangler-dist/cli.js +3418 -1437
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/dev2.test.tsx +0 -152
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RawConfig } from "./config";
|
|
2
2
|
import type { Diagnostics } from "./diagnostics";
|
|
3
3
|
import type { Environment, RawEnvironment } from "./environment";
|
|
4
4
|
|
|
@@ -54,14 +54,82 @@ export function experimental<T extends object>(
|
|
|
54
54
|
*/
|
|
55
55
|
export function inheritable<K extends keyof Environment>(
|
|
56
56
|
diagnostics: Diagnostics,
|
|
57
|
-
|
|
57
|
+
topLevelEnv: Environment | undefined,
|
|
58
58
|
rawEnv: RawEnvironment,
|
|
59
59
|
field: K,
|
|
60
60
|
validate: ValidatorFn,
|
|
61
|
+
defaultValue: Environment[K],
|
|
62
|
+
transformFn: TransformFn<Environment[K]> = (v) => v
|
|
63
|
+
): Environment[K] {
|
|
64
|
+
validate(diagnostics, field, rawEnv[field], topLevelEnv);
|
|
65
|
+
return (
|
|
66
|
+
(rawEnv[field] as Environment[K]) ??
|
|
67
|
+
transformFn(topLevelEnv?.[field]) ??
|
|
68
|
+
defaultValue
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get an inheritable environment field, but only if we are in legacy environments
|
|
74
|
+
*/
|
|
75
|
+
export function inheritableInLegacyEnvironments<K extends keyof Environment>(
|
|
76
|
+
diagnostics: Diagnostics,
|
|
77
|
+
isLegacyEnv: boolean | undefined,
|
|
78
|
+
topLevelEnv: Environment | undefined,
|
|
79
|
+
rawEnv: RawEnvironment,
|
|
80
|
+
field: K,
|
|
81
|
+
validate: ValidatorFn,
|
|
82
|
+
transformFn: TransformFn<Environment[K]>,
|
|
61
83
|
defaultValue: Environment[K]
|
|
62
84
|
): Environment[K] {
|
|
63
|
-
|
|
64
|
-
|
|
85
|
+
return topLevelEnv === undefined || isLegacyEnv === true
|
|
86
|
+
? inheritable(
|
|
87
|
+
diagnostics,
|
|
88
|
+
topLevelEnv,
|
|
89
|
+
rawEnv,
|
|
90
|
+
field,
|
|
91
|
+
validate,
|
|
92
|
+
defaultValue,
|
|
93
|
+
transformFn
|
|
94
|
+
)
|
|
95
|
+
: notAllowedInNamedServiceEnvironment(
|
|
96
|
+
diagnostics,
|
|
97
|
+
topLevelEnv,
|
|
98
|
+
rawEnv,
|
|
99
|
+
field
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Type of function that is used to transform an inheritable environment field.
|
|
105
|
+
*/
|
|
106
|
+
type TransformFn<T> = (fieldValue: T | undefined) => T | undefined;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Transform an environment field by appending current environment name to it.
|
|
110
|
+
*/
|
|
111
|
+
export const appendEnvName =
|
|
112
|
+
(envName: string): TransformFn<string | undefined> =>
|
|
113
|
+
(fieldValue) =>
|
|
114
|
+
fieldValue ? `${fieldValue}-${envName}` : undefined;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Log an error if this named environment is trying to override the value in the top-level
|
|
118
|
+
* environment, which is not allow for this field.
|
|
119
|
+
*/
|
|
120
|
+
function notAllowedInNamedServiceEnvironment<K extends keyof Environment>(
|
|
121
|
+
diagnostics: Diagnostics,
|
|
122
|
+
topLevelEnv: Environment,
|
|
123
|
+
rawEnv: RawEnvironment,
|
|
124
|
+
field: K
|
|
125
|
+
): Environment[K] {
|
|
126
|
+
if (field in rawEnv) {
|
|
127
|
+
diagnostics.errors.push(
|
|
128
|
+
`The "${field}" field is not allowed in named service environments.\n` +
|
|
129
|
+
`Please remove the field from this environment.`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return topLevelEnv[field];
|
|
65
133
|
}
|
|
66
134
|
|
|
67
135
|
/**
|
|
@@ -72,7 +140,7 @@ export function inheritable<K extends keyof Environment>(
|
|
|
72
140
|
*/
|
|
73
141
|
export function notInheritable<K extends keyof Environment>(
|
|
74
142
|
diagnostics: Diagnostics,
|
|
75
|
-
|
|
143
|
+
topLevelEnv: Environment | undefined,
|
|
76
144
|
rawConfig: RawConfig | undefined,
|
|
77
145
|
rawEnv: RawEnvironment,
|
|
78
146
|
envName: string,
|
|
@@ -81,7 +149,7 @@ export function notInheritable<K extends keyof Environment>(
|
|
|
81
149
|
defaultValue: Environment[K]
|
|
82
150
|
): Environment[K] {
|
|
83
151
|
if (rawEnv[field] !== undefined) {
|
|
84
|
-
validate(diagnostics, field, rawEnv[field],
|
|
152
|
+
validate(diagnostics, field, rawEnv[field], topLevelEnv);
|
|
85
153
|
} else {
|
|
86
154
|
if (rawConfig?.[field] !== undefined) {
|
|
87
155
|
diagnostics.warnings.push(
|
|
@@ -139,7 +207,7 @@ export type ValidatorFn = (
|
|
|
139
207
|
diagnostics: Diagnostics,
|
|
140
208
|
field: string,
|
|
141
209
|
value: unknown,
|
|
142
|
-
|
|
210
|
+
topLevelEnv: Environment | undefined
|
|
143
211
|
) => boolean;
|
|
144
212
|
|
|
145
213
|
/**
|
|
@@ -148,7 +216,7 @@ export type ValidatorFn = (
|
|
|
148
216
|
export const isString: ValidatorFn = (diagnostics, field, value) => {
|
|
149
217
|
if (value !== undefined && typeof value !== "string") {
|
|
150
218
|
diagnostics.errors.push(
|
|
151
|
-
`Expected "${field}"
|
|
219
|
+
`Expected "${field}" to be of type string but got ${JSON.stringify(
|
|
152
220
|
value
|
|
153
221
|
)}.`
|
|
154
222
|
);
|
|
@@ -166,7 +234,7 @@ export const isStringArray: ValidatorFn = (diagnostics, field, value) => {
|
|
|
166
234
|
(!Array.isArray(value) || value.some((item) => typeof item !== "string"))
|
|
167
235
|
) {
|
|
168
236
|
diagnostics.errors.push(
|
|
169
|
-
`Expected "${field}"
|
|
237
|
+
`Expected "${field}" to be of type string array but got ${JSON.stringify(
|
|
170
238
|
value
|
|
171
239
|
)}.`
|
|
172
240
|
);
|
|
@@ -188,7 +256,7 @@ export const isObjectWith =
|
|
|
188
256
|
!properties.every((prop) => prop in value))
|
|
189
257
|
) {
|
|
190
258
|
diagnostics.errors.push(
|
|
191
|
-
`Expected "${field}"
|
|
259
|
+
`Expected "${field}" to be of type object, containing properties ${properties}, but got ${JSON.stringify(
|
|
192
260
|
value
|
|
193
261
|
)}.`
|
|
194
262
|
);
|
|
@@ -214,13 +282,61 @@ export const isOneOf =
|
|
|
214
282
|
return true;
|
|
215
283
|
};
|
|
216
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Aggregate multiple validator functions
|
|
287
|
+
*/
|
|
288
|
+
export const all = (...validations: ValidatorFn[]): ValidatorFn => {
|
|
289
|
+
return (diagnostics, field, value, config) => {
|
|
290
|
+
let passedValidations = true;
|
|
291
|
+
|
|
292
|
+
for (const validate of validations) {
|
|
293
|
+
if (!validate(diagnostics, field, value, config)) {
|
|
294
|
+
passedValidations = false;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return passedValidations;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Check that the field is mutually exclusive with a list of other fields.
|
|
304
|
+
*
|
|
305
|
+
* @param container the container of the fields to check against.
|
|
306
|
+
* @param fields the names of the fields to check against.
|
|
307
|
+
*/
|
|
308
|
+
export const isMutuallyExclusiveWith = <T extends RawEnvironment | RawConfig>(
|
|
309
|
+
container: T,
|
|
310
|
+
...fields: (keyof T)[]
|
|
311
|
+
): ValidatorFn => {
|
|
312
|
+
return (diagnostics, field, value) => {
|
|
313
|
+
if (value === undefined) {
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
for (const exclusiveWith of fields) {
|
|
318
|
+
if (container[exclusiveWith] !== undefined) {
|
|
319
|
+
diagnostics.errors.push(
|
|
320
|
+
`Expected exactly one of the following fields ${JSON.stringify([
|
|
321
|
+
field,
|
|
322
|
+
...fields,
|
|
323
|
+
])}.`
|
|
324
|
+
);
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return true;
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
|
|
217
333
|
/**
|
|
218
334
|
* Validate that the field is a boolean.
|
|
219
335
|
*/
|
|
220
336
|
export const isBoolean: ValidatorFn = (diagnostics, field, value) => {
|
|
221
337
|
if (value !== undefined && typeof value !== "boolean") {
|
|
222
338
|
diagnostics.errors.push(
|
|
223
|
-
`Expected "${field}"
|
|
339
|
+
`Expected "${field}" to be of type boolean but got ${JSON.stringify(
|
|
224
340
|
value
|
|
225
341
|
)}.`
|
|
226
342
|
);
|
|
@@ -386,3 +502,53 @@ export const validateAdditionalProperties = (
|
|
|
386
502
|
}
|
|
387
503
|
return true;
|
|
388
504
|
};
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Get the names of the bindings collection in `value`.
|
|
508
|
+
*
|
|
509
|
+
* Will return an empty array if it doesn't understand the value
|
|
510
|
+
* passed in, so another form of validation should be
|
|
511
|
+
* performed externally.
|
|
512
|
+
*/
|
|
513
|
+
export const getBindingNames = (value: unknown): string[] => {
|
|
514
|
+
if (typeof value !== "object" || value === null) {
|
|
515
|
+
return [];
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (isBindingList(value)) {
|
|
519
|
+
return value.bindings.map(({ name }) => name);
|
|
520
|
+
} else if (isNamespaceList(value)) {
|
|
521
|
+
return value.map(({ binding }) => binding);
|
|
522
|
+
} else if (isRecord(value)) {
|
|
523
|
+
return Object.keys(value);
|
|
524
|
+
} else {
|
|
525
|
+
return [];
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
const isBindingList = (
|
|
530
|
+
value: unknown
|
|
531
|
+
): value is {
|
|
532
|
+
bindings: {
|
|
533
|
+
name: string;
|
|
534
|
+
}[];
|
|
535
|
+
} =>
|
|
536
|
+
isRecord(value) &&
|
|
537
|
+
"bindings" in value &&
|
|
538
|
+
Array.isArray(value.bindings) &&
|
|
539
|
+
value.bindings.every(
|
|
540
|
+
(binding) =>
|
|
541
|
+
isRecord(binding) && "name" in binding && typeof binding.name === "string"
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
const isNamespaceList = (value: unknown): value is { binding: string }[] =>
|
|
545
|
+
Array.isArray(value) &&
|
|
546
|
+
value.every(
|
|
547
|
+
(entry) =>
|
|
548
|
+
isRecord(entry) && "binding" in entry && typeof entry.binding === "string"
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
const isRecord = (
|
|
552
|
+
value: unknown
|
|
553
|
+
): value is Record<string | number | symbol, unknown> =>
|
|
554
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|