wrangler 2.8.1 → 2.9.0

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.
Files changed (66) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/d1/d1.test.ts +10 -52
  3. package/src/__tests__/d1/migrate.test.ts +48 -0
  4. package/src/__tests__/dev.test.tsx +5 -4
  5. package/src/__tests__/index.test.ts +35 -28
  6. package/src/__tests__/kv.test.ts +55 -44
  7. package/src/__tests__/pages.test.ts +27 -20
  8. package/src/__tests__/parse.test.ts +106 -0
  9. package/src/__tests__/pubsub.test.ts +15 -12
  10. package/src/__tests__/queues.test.ts +35 -28
  11. package/src/__tests__/r2.test.ts +25 -20
  12. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  13. package/src/__tests__/worker-namespace.test.ts +25 -20
  14. package/src/api/dev.ts +80 -11
  15. package/src/api/pages/publish.tsx +7 -4
  16. package/src/bundle.ts +1 -1
  17. package/src/config/config.ts +7 -0
  18. package/src/config/index.ts +24 -20
  19. package/src/d1/backups.tsx +20 -24
  20. package/src/d1/create.tsx +6 -5
  21. package/src/d1/delete.ts +7 -10
  22. package/src/d1/execute.tsx +82 -84
  23. package/src/d1/index.ts +5 -6
  24. package/src/d1/list.tsx +21 -9
  25. package/src/d1/migrations/apply.tsx +7 -5
  26. package/src/d1/migrations/create.tsx +7 -10
  27. package/src/d1/migrations/list.tsx +7 -5
  28. package/src/d1/migrations/options.ts +2 -2
  29. package/src/d1/options.ts +3 -3
  30. package/src/delete.ts +5 -8
  31. package/src/deprecated/index.ts +7 -8
  32. package/src/dev.tsx +42 -80
  33. package/src/dispatch-namespace.ts +20 -16
  34. package/src/docs/index.ts +7 -8
  35. package/src/generate/index.ts +5 -7
  36. package/src/index.ts +22 -21
  37. package/src/init.ts +5 -7
  38. package/src/kv/index.ts +15 -17
  39. package/src/pages/build.ts +6 -4
  40. package/src/pages/deployment-tails.ts +7 -10
  41. package/src/pages/deployments.tsx +6 -4
  42. package/src/pages/dev.ts +15 -17
  43. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  44. package/src/pages/functions.ts +8 -4
  45. package/src/pages/index.ts +3 -3
  46. package/src/pages/projects.tsx +7 -12
  47. package/src/pages/publish.tsx +6 -4
  48. package/src/pages/types.ts +5 -0
  49. package/src/pages/upload.tsx +6 -4
  50. package/src/parse.ts +23 -1
  51. package/src/publish/index.ts +19 -15
  52. package/src/publish/publish.ts +2 -2
  53. package/src/pubsub/pubsub-commands.ts +18 -19
  54. package/src/queues/cli/commands/consumer/add.ts +18 -24
  55. package/src/queues/cli/commands/consumer/index.ts +3 -6
  56. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  57. package/src/queues/cli/commands/create.ts +8 -8
  58. package/src/queues/cli/commands/delete.ts +8 -8
  59. package/src/queues/cli/commands/index.ts +3 -4
  60. package/src/queues/cli/commands/list.ts +8 -8
  61. package/src/r2/index.ts +28 -28
  62. package/src/secret/index.ts +9 -14
  63. package/src/tail/index.ts +6 -8
  64. package/src/yargs-types.ts +18 -5
  65. package/templates/checked-fetch.js +9 -1
  66. package/wrangler-dist/cli.js +1969 -1228
@@ -13,14 +13,12 @@ import * as metrics from "../metrics";
13
13
  import { parseJSON, readFileSync } from "../parse";
14
14
  import { requireAuth } from "../user";
15
15
 
16
- import type { ConfigPath } from "../index";
17
16
  import type {
18
- CommonYargsOptions,
19
- YargsOptionsToInterface,
17
+ CommonYargsArgv,
18
+ StrictYargsOptionsToInterface,
20
19
  } from "../yargs-types";
21
- import type { Argv } from "yargs";
22
20
 
23
- export const secret = (secretYargs: Argv<CommonYargsOptions>) => {
21
+ export const secret = (secretYargs: CommonYargsArgv) => {
24
22
  return secretYargs
25
23
  .option("legacy-env", {
26
24
  type: "boolean",
@@ -44,7 +42,7 @@ export const secret = (secretYargs: Argv<CommonYargsOptions>) => {
44
42
  },
45
43
  async (args) => {
46
44
  await printWranglerBanner();
47
- const config = readConfig(args.config as ConfigPath, args);
45
+ const config = readConfig(args.config, args);
48
46
 
49
47
  const scriptName = getLegacyScriptName(args, config);
50
48
  if (!scriptName) {
@@ -172,7 +170,7 @@ export const secret = (secretYargs: Argv<CommonYargsOptions>) => {
172
170
  });
173
171
  },
174
172
  async (args) => {
175
- const config = readConfig(args.config as ConfigPath, args);
173
+ const config = readConfig(args.config, args);
176
174
 
177
175
  const scriptName = getLegacyScriptName(args, config);
178
176
  if (!scriptName) {
@@ -222,7 +220,7 @@ export const secret = (secretYargs: Argv<CommonYargsOptions>) => {
222
220
  });
223
221
  },
224
222
  async (args) => {
225
- const config = readConfig(args.config as ConfigPath, args);
223
+ const config = readConfig(args.config, args);
226
224
 
227
225
  const scriptName = getLegacyScriptName(args, config);
228
226
  if (!scriptName) {
@@ -246,7 +244,7 @@ export const secret = (secretYargs: Argv<CommonYargsOptions>) => {
246
244
  );
247
245
  };
248
246
 
249
- export const secretBulkOptions = (yargs: Argv<CommonYargsOptions>) => {
247
+ export const secretBulkOptions = (yargs: CommonYargsArgv) => {
250
248
  return yargs
251
249
  .positional("json", {
252
250
  describe: `The JSON file of key-value pairs to upload, in form {"key": value, ...}`,
@@ -301,14 +299,11 @@ function readFromStdin(): Promise<string> {
301
299
  });
302
300
  }
303
301
 
304
- type SecretBulkArgs = YargsOptionsToInterface<typeof secretBulkOptions>;
302
+ type SecretBulkArgs = StrictYargsOptionsToInterface<typeof secretBulkOptions>;
305
303
 
306
304
  export const secretBulkHandler = async (secretBulkArgs: SecretBulkArgs) => {
307
305
  await printWranglerBanner();
308
- const config = readConfig(
309
- secretBulkArgs.config as ConfigPath,
310
- secretBulkArgs
311
- );
306
+ const config = readConfig(secretBulkArgs.config, secretBulkArgs);
312
307
 
313
308
  const scriptName = getLegacyScriptName(secretBulkArgs, config);
314
309
  if (!scriptName) {
package/src/tail/index.ts CHANGED
@@ -20,16 +20,14 @@ import {
20
20
  translateCLICommandToFilterMessage,
21
21
  } from "./createTail";
22
22
  import type { WorkerMetadata } from "../create-worker-upload-form";
23
- import type { ConfigPath } from "../index";
24
23
  import type {
25
- CommonYargsOptions,
26
- YargsOptionsToInterface,
24
+ CommonYargsArgv,
25
+ StrictYargsOptionsToInterface,
27
26
  } from "../yargs-types";
28
27
  import type { TailCLIFilters } from "./createTail";
29
28
  import type { RawData } from "ws";
30
- import type { Argv } from "yargs";
31
29
 
32
- export function tailOptions(yargs: Argv<CommonYargsOptions>) {
30
+ export function tailOptions(yargs: CommonYargsArgv) {
33
31
  return yargs
34
32
  .positional("worker", {
35
33
  describe: "Name or route of the worker to tail",
@@ -86,13 +84,13 @@ export function tailOptions(yargs: Argv<CommonYargsOptions>) {
86
84
  });
87
85
  }
88
86
 
89
- type TailArgs = YargsOptionsToInterface<typeof tailOptions>;
87
+ type TailArgs = StrictYargsOptionsToInterface<typeof tailOptions>;
90
88
 
91
89
  export async function tailHandler(args: TailArgs) {
92
90
  if (args.format === "pretty") {
93
91
  await printWranglerBanner();
94
92
  }
95
- const config = readConfig(args.config as ConfigPath, args);
93
+ const config = readConfig(args.config, args);
96
94
  await metrics.sendMetricsEvent("begin log stream", {
97
95
  sendMetrics: config.send_metrics,
98
96
  });
@@ -121,7 +119,7 @@ export async function tailHandler(args: TailArgs) {
121
119
  status: args.status as ("ok" | "error" | "canceled")[] | undefined,
122
120
  header: args.header,
123
121
  method: args.method,
124
- samplingRate: args["sampling-rate"],
122
+ samplingRate: args.samplingRate,
125
123
  search: args.search,
126
124
  clientIp: args.ip,
127
125
  };
@@ -1,3 +1,4 @@
1
+ import type { OnlyCamelCase } from "./config/config";
1
2
  import type { ArgumentsCamelCase, Argv } from "yargs";
2
3
 
3
4
  /**
@@ -7,18 +8,30 @@ export interface CommonYargsOptions {
7
8
  v: boolean | undefined;
8
9
  config: string | undefined;
9
10
  env: string | undefined;
11
+ "experimental-json-config": boolean | undefined;
10
12
  }
11
13
 
14
+ export type CommonYargsArgv = Argv<CommonYargsOptions>;
15
+
12
16
  export type YargvToInterface<T> = T extends Argv<infer P>
13
17
  ? ArgumentsCamelCase<P>
14
18
  : never;
15
19
 
20
+ // See http://stackoverflow.com/questions/51465182/how-to-remove-index-signature-using-mapped-types
21
+ type RemoveIndex<T> = {
22
+ [K in keyof T as string extends K
23
+ ? never
24
+ : number extends K
25
+ ? never
26
+ : K]: T[K];
27
+ };
28
+
16
29
  /**
17
30
  * Given some Yargs Options function factory, extract the interface
18
- * that corresponds to the yargs arguments
31
+ * that corresponds to the yargs arguments, remove index types, and only allow camelCase
19
32
  */
20
- export type YargsOptionsToInterface<
21
- T extends (yargs: Argv<CommonYargsOptions>) => Argv
22
- > = T extends (yargs: Argv<CommonYargsOptions>) => Argv<infer P>
23
- ? ArgumentsCamelCase<P>
33
+ export type StrictYargsOptionsToInterface<
34
+ T extends (yargs: CommonYargsArgv) => Argv
35
+ > = T extends (yargs: CommonYargsArgv) => Argv<infer P>
36
+ ? OnlyCamelCase<RemoveIndex<ArgumentsCamelCase<P>>>
24
37
  : never;
@@ -1,7 +1,15 @@
1
1
  const urls = new Set();
2
2
 
3
3
  export function checkedFetch(request, init) {
4
- const url = new URL(new Request(request, init).url);
4
+ const url =
5
+ request instanceof URL
6
+ ? request
7
+ : new URL(
8
+ (typeof request === "string"
9
+ ? new Request(request, init)
10
+ : request
11
+ ).url
12
+ );
5
13
  if (url.port && url.port !== "443" && url.protocol === "https:") {
6
14
  if (!urls.has(url.toString())) {
7
15
  urls.add(url.toString());