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
package/src/parse.ts CHANGED
@@ -2,8 +2,12 @@ import * as fs from "node:fs";
2
2
  import { resolve } from "node:path";
3
3
  import TOML from "@iarna/toml";
4
4
  import { formatMessagesSync } from "esbuild";
5
+ import {
6
+ parse as jsoncParse,
7
+ printParseErrorCode,
8
+ type ParseError as JsoncParseError,
9
+ } from "jsonc-parser";
5
10
  import { logger } from "./logger";
6
-
7
11
  export type Message = {
8
12
  text: string;
9
13
  location?: Location;
@@ -139,6 +143,24 @@ export function parseJSON<T>(input: string, file?: string): T {
139
143
  }
140
144
  }
141
145
 
146
+ /**
147
+ * A wrapper around `JSONC.parse` that throws a `ParseError`.
148
+ */
149
+ export function parseJSONC<T>(input: string, file?: string): T {
150
+ const errors: JsoncParseError[] = [];
151
+ const data = jsoncParse(input, errors);
152
+ if (errors.length) {
153
+ throw new ParseError({
154
+ text: printParseErrorCode(errors[0].error),
155
+ location: {
156
+ ...indexLocation({ file, fileText: input }, errors[0].offset + 1),
157
+ length: errors[0].length,
158
+ },
159
+ });
160
+ }
161
+ return data;
162
+ }
163
+
142
164
  /**
143
165
  * Reads a file into a node Buffer.
144
166
  */
@@ -13,14 +13,12 @@ import { getAssetPaths, getSiteAssetPaths } from "../sites";
13
13
  import { requireAuth } from "../user";
14
14
  import { collectKeyValues } from "../utils/collectKeyValues";
15
15
  import publish from "./publish";
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, ArgumentsCamelCase } from "yargs";
22
20
 
23
- export function publishOptions(yargs: Argv<CommonYargsOptions>) {
21
+ export function publishOptions(yargs: CommonYargsArgv) {
24
22
  return (
25
23
  yargs
26
24
  .positional("script", {
@@ -82,6 +80,13 @@ export function publishOptions(yargs: Argv<CommonYargsOptions>) {
82
80
  deprecated: true,
83
81
  hidden: true,
84
82
  })
83
+ .option("public", {
84
+ describe: "Static assets to be served",
85
+ type: "string",
86
+ requiresArg: true,
87
+ deprecated: true,
88
+ hidden: true,
89
+ })
85
90
  .option("assets", {
86
91
  describe: "Static assets to be served",
87
92
  type: "string",
@@ -179,14 +184,13 @@ export function publishOptions(yargs: Argv<CommonYargsOptions>) {
179
184
  );
180
185
  }
181
186
 
182
- type PublishArgs = YargsOptionsToInterface<typeof publishOptions>;
183
-
184
- export async function publishHandler(args: ArgumentsCamelCase<PublishArgs>) {
187
+ export async function publishHandler(
188
+ args: StrictYargsOptionsToInterface<typeof publishOptions>
189
+ ) {
185
190
  await printWranglerBanner();
186
191
 
187
192
  const configPath =
188
- (args.config as ConfigPath) ||
189
- (args.script && findWranglerToml(path.dirname(args.script)));
193
+ args.config || (args.script && findWranglerToml(path.dirname(args.script)));
190
194
  const config = readConfig(configPath, args);
191
195
  const entry = await getEntry(args, config, "publish");
192
196
  await metrics.sendMetricsEvent(
@@ -202,7 +206,7 @@ export async function publishHandler(args: ArgumentsCamelCase<PublishArgs>) {
202
206
  if (args.public) {
203
207
  throw new Error("The --public field has been renamed to --assets");
204
208
  }
205
- if (args["experimental-public"]) {
209
+ if (args.experimentalPublic) {
206
210
  throw new Error(
207
211
  "The --experimental-public field has been renamed to --assets"
208
212
  );
@@ -247,13 +251,13 @@ export async function publishHandler(args: ArgumentsCamelCase<PublishArgs>) {
247
251
  env: args.env,
248
252
  compatibilityDate: args.latest
249
253
  ? new Date().toISOString().substring(0, 10)
250
- : args["compatibility-date"],
251
- compatibilityFlags: args["compatibility-flags"],
254
+ : args.compatibilityDate,
255
+ compatibilityFlags: args.compatibilityFlags,
252
256
  vars: cliVars,
253
257
  defines: cliDefines,
254
258
  triggers: args.triggers,
255
- jsxFactory: args["jsx-factory"],
256
- jsxFragment: args["jsx-fragment"],
259
+ jsxFactory: args.jsxFactory,
260
+ jsxFragment: args.jsxFragment,
257
261
  tsconfig: args.tsconfig,
258
262
  routes: args.routes,
259
263
  assetPaths,
@@ -609,9 +609,9 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
609
609
 
610
610
  printBindings({ ...withoutStaticAssets, vars: maskedVars });
611
611
 
612
- await ensureQueuesExist(config);
613
-
614
612
  if (!props.dryRun) {
613
+ await ensureQueuesExist(config);
614
+
615
615
  // Upload the script so it has time to propagate.
616
616
  // We can also now tell whether available_on_subdomain is set
617
617
  try {
@@ -1,4 +1,3 @@
1
- import { type ConfigPath } from "..";
2
1
  import { readConfig } from "../config";
3
2
  import { confirm } from "../dialogs";
4
3
  import { CommandLineArgsError } from "../index";
@@ -7,13 +6,13 @@ import * as metrics from "../metrics";
7
6
  import { parseHumanDuration } from "../parse";
8
7
  import { requireAuth } from "../user";
9
8
  import * as pubsub from ".";
10
- import type { CommonYargsOptions } from "../yargs-types";
11
- import type { Argv, CommandModule } from "yargs";
9
+ import type { CommonYargsArgv, CommonYargsOptions } from "../yargs-types";
10
+ import type { CommandModule } from "yargs";
12
11
 
13
12
  export function pubSubCommands(
14
- pubsubYargs: Argv<CommonYargsOptions>,
13
+ pubsubYargs: CommonYargsArgv,
15
14
  subHelp: CommandModule<CommonYargsOptions, CommonYargsOptions>
16
- ): Argv {
15
+ ) {
17
16
  return pubsubYargs
18
17
  .command(subHelp)
19
18
  .command(
@@ -39,7 +38,7 @@ export function pubSubCommands(
39
38
  .epilogue(pubsub.pubSubBetaWarning);
40
39
  },
41
40
  async (args) => {
42
- const config = readConfig(args.config as ConfigPath, args);
41
+ const config = readConfig(args.config, args);
43
42
  const accountId = await requireAuth(config);
44
43
 
45
44
  const namespace: pubsub.PubSubNamespace = {
@@ -64,7 +63,7 @@ export function pubSubCommands(
64
63
  return yargs.epilogue(pubsub.pubSubBetaWarning);
65
64
  },
66
65
  async (args) => {
67
- const config = readConfig(args.config as ConfigPath, args);
66
+ const config = readConfig(args.config, args);
68
67
  const accountId = await requireAuth(config);
69
68
 
70
69
  logger.log(await pubsub.listPubSubNamespaces(accountId));
@@ -86,7 +85,7 @@ export function pubSubCommands(
86
85
  .epilogue(pubsub.pubSubBetaWarning);
87
86
  },
88
87
  async (args) => {
89
- const config = readConfig(args.config as ConfigPath, args);
88
+ const config = readConfig(args.config, args);
90
89
  const accountId = await requireAuth(config);
91
90
 
92
91
  if (
@@ -116,7 +115,7 @@ export function pubSubCommands(
116
115
  .epilogue(pubsub.pubSubBetaWarning);
117
116
  },
118
117
  async (args) => {
119
- const config = readConfig(args.config as ConfigPath, args);
118
+ const config = readConfig(args.config, args);
120
119
  const accountId = await requireAuth(config);
121
120
 
122
121
  logger.log(
@@ -165,7 +164,7 @@ export function pubSubCommands(
165
164
  })
166
165
  .epilogue(pubsub.pubSubBetaWarning),
167
166
  async (args) => {
168
- const config = readConfig(args.config as ConfigPath, args);
167
+ const config = readConfig(args.config, args);
169
168
  const accountId = await requireAuth(config);
170
169
 
171
170
  const broker: pubsub.PubSubBroker = {
@@ -230,7 +229,7 @@ export function pubSubCommands(
230
229
  })
231
230
  .epilogue(pubsub.pubSubBetaWarning),
232
231
  async (args) => {
233
- const config = readConfig(args.config as ConfigPath, args);
232
+ const config = readConfig(args.config, args);
234
233
  const accountId = await requireAuth(config);
235
234
 
236
235
  const broker: pubsub.PubSubBrokerUpdate = {};
@@ -284,7 +283,7 @@ export function pubSubCommands(
284
283
  .epilogue(pubsub.pubSubBetaWarning);
285
284
  },
286
285
  async (args) => {
287
- const config = readConfig(args.config as ConfigPath, args);
286
+ const config = readConfig(args.config, args);
288
287
  const accountId = await requireAuth(config);
289
288
 
290
289
  logger.log(await pubsub.listPubSubBrokers(accountId, args.namespace));
@@ -314,7 +313,7 @@ export function pubSubCommands(
314
313
  .epilogue(pubsub.pubSubBetaWarning);
315
314
  },
316
315
  async (args) => {
317
- const config = readConfig(args.config as ConfigPath, args);
316
+ const config = readConfig(args.config, args);
318
317
  const accountId = await requireAuth(config);
319
318
 
320
319
  if (
@@ -354,7 +353,7 @@ export function pubSubCommands(
354
353
  .epilogue(pubsub.pubSubBetaWarning);
355
354
  },
356
355
  async (args) => {
357
- const config = readConfig(args.config as ConfigPath, args);
356
+ const config = readConfig(args.config, args);
358
357
  const accountId = await requireAuth(config);
359
358
 
360
359
  logger.log(
@@ -413,7 +412,7 @@ export function pubSubCommands(
413
412
  .epilogue(pubsub.pubSubBetaWarning);
414
413
  },
415
414
  async (args) => {
416
- const config = readConfig(args.config as ConfigPath, args);
415
+ const config = readConfig(args.config, args);
417
416
  const accountId = await requireAuth(config);
418
417
 
419
418
  let parsedExpiration: number | undefined;
@@ -473,7 +472,7 @@ export function pubSubCommands(
473
472
  .epilogue(pubsub.pubSubBetaWarning);
474
473
  },
475
474
  async (args) => {
476
- const config = readConfig(args.config as ConfigPath, args);
475
+ const config = readConfig(args.config, args);
477
476
  const accountId = await requireAuth(config);
478
477
 
479
478
  const numTokens = args.jti.length;
@@ -521,7 +520,7 @@ export function pubSubCommands(
521
520
  .epilogue(pubsub.pubSubBetaWarning);
522
521
  },
523
522
  async (args) => {
524
- const config = readConfig(args.config as ConfigPath, args);
523
+ const config = readConfig(args.config, args);
525
524
  const accountId = await requireAuth(config);
526
525
 
527
526
  const numTokens = args.jti.length;
@@ -562,7 +561,7 @@ export function pubSubCommands(
562
561
  .epilogue(pubsub.pubSubBetaWarning);
563
562
  },
564
563
  async (args) => {
565
- const config = readConfig(args.config as ConfigPath, args);
564
+ const config = readConfig(args.config, args);
566
565
  const accountId = await requireAuth(config);
567
566
 
568
567
  logger.log(`Listing previously revoked tokens for ${args.name}...`);
@@ -601,7 +600,7 @@ export function pubSubCommands(
601
600
  .epilogue(pubsub.pubSubBetaWarning);
602
601
  },
603
602
  async (args) => {
604
- const config = readConfig(args.config as ConfigPath, args);
603
+ const config = readConfig(args.config, args);
605
604
  const accountId = await requireAuth(config);
606
605
 
607
606
  logger.log(
@@ -1,21 +1,13 @@
1
- import { type Argv } from "yargs";
2
1
  import { readConfig } from "../../../../config";
3
2
  import { logger } from "../../../../logger";
4
3
  import { postConsumer } from "../../../client";
5
- import type { CommonYargsOptions } from "../../../../yargs-types";
4
+ import type {
5
+ CommonYargsArgv,
6
+ StrictYargsOptionsToInterface,
7
+ } from "../../../../yargs-types";
6
8
  import type { PostConsumerBody } from "../../../client";
7
9
 
8
- type Args = CommonYargsOptions & {
9
- config?: string;
10
- ["queue-name"]: string;
11
- ["script-name"]: string;
12
- ["batch-size"]?: number;
13
- ["batch-timeout"]?: number;
14
- ["message-retries"]?: number;
15
- ["dead-letter-queue"]?: string;
16
- };
17
-
18
- export function options(yargs: Argv<CommonYargsOptions>): Argv<Args> {
10
+ export function options(yargs: CommonYargsArgv) {
19
11
  return yargs
20
12
  .positional("queue-name", {
21
13
  type: "string",
@@ -48,24 +40,26 @@ export function options(yargs: Argv<CommonYargsOptions>): Argv<Args> {
48
40
  });
49
41
  }
50
42
 
51
- export async function handler(args: Args) {
43
+ export async function handler(
44
+ args: StrictYargsOptionsToInterface<typeof options>
45
+ ) {
52
46
  const config = readConfig(args.config, args);
53
47
 
54
48
  const body: PostConsumerBody = {
55
- script_name: args["script-name"],
49
+ script_name: args.scriptName,
56
50
  // TODO(soon) is this still the correct usage of the environment?
57
- environment_name: args.env || "", // API expects empty string as default
51
+ environment_name: args.env ?? "", // API expects empty string as default
58
52
  settings: {
59
- batch_size: args["batch-size"],
60
- max_retries: args["message-retries"],
61
- max_wait_time_ms: args["batch-timeout"] // API expects milliseconds
62
- ? 1000 * args["batch-timeout"]
53
+ batch_size: args.batchSize,
54
+ max_retries: args.messageRetries,
55
+ max_wait_time_ms: args.batchTimeout // API expects milliseconds
56
+ ? 1000 * args.batchTimeout
63
57
  : undefined,
64
58
  },
65
- dead_letter_queue: args["dead-letter-queue"],
59
+ dead_letter_queue: args.deadLetterQueue,
66
60
  };
67
61
 
68
- logger.log(`Adding consumer to queue ${args["queue-name"]}.`);
69
- await postConsumer(config, args["queue-name"], body);
70
- logger.log(`Added consumer to queue ${args["queue-name"]}.`);
62
+ logger.log(`Adding consumer to queue ${args.queueName}.`);
63
+ await postConsumer(config, args.queueName, body);
64
+ logger.log(`Added consumer to queue ${args.queueName}.`);
71
65
  }
@@ -1,11 +1,8 @@
1
- import { type BuilderCallback } from "yargs";
2
- import { type CommonYargsOptions } from "../../../../yargs-types";
3
1
  import { options as addOptions, handler as addHandler } from "./add";
4
2
  import { options as removeOptions, handler as removeHandler } from "./remove";
3
+ import type { CommonYargsArgv } from "../../../../yargs-types";
5
4
 
6
- export const consumers: BuilderCallback<CommonYargsOptions, unknown> = (
7
- yargs
8
- ) => {
5
+ export function consumers(yargs: CommonYargsArgv) {
9
6
  yargs.command(
10
7
  "add <queue-name> <script-name>",
11
8
  "Add a Queue Consumer",
@@ -19,4 +16,4 @@ export const consumers: BuilderCallback<CommonYargsOptions, unknown> = (
19
16
  removeOptions,
20
17
  removeHandler
21
18
  );
22
- };
19
+ }
@@ -1,16 +1,12 @@
1
- import { type Argv } from "yargs";
2
1
  import { readConfig } from "../../../../config";
3
2
  import { logger } from "../../../../logger";
4
3
  import { deleteConsumer } from "../../../client";
5
- import type { CommonYargsOptions } from "../../../../yargs-types";
4
+ import type {
5
+ CommonYargsArgv,
6
+ StrictYargsOptionsToInterface,
7
+ } from "../../../../yargs-types";
6
8
 
7
- type Args = CommonYargsOptions & {
8
- config?: string;
9
- ["queue-name"]: string;
10
- ["script-name"]: string;
11
- };
12
-
13
- export function options(yargs: Argv<CommonYargsOptions>): Argv<Args> {
9
+ export function options(yargs: CommonYargsArgv) {
14
10
  return yargs
15
11
  .positional("queue-name", {
16
12
  type: "string",
@@ -24,15 +20,12 @@ export function options(yargs: Argv<CommonYargsOptions>): Argv<Args> {
24
20
  });
25
21
  }
26
22
 
27
- export async function handler(args: Args) {
23
+ export async function handler(
24
+ args: StrictYargsOptionsToInterface<typeof options>
25
+ ) {
28
26
  const config = readConfig(args.config, args);
29
27
 
30
- logger.log(`Removing consumer from queue ${args["queue-name"]}.`);
31
- await deleteConsumer(
32
- config,
33
- args["queue-name"],
34
- args["script-name"],
35
- args.env
36
- );
37
- logger.log(`Removed consumer from queue ${args["queue-name"]}.`);
28
+ logger.log(`Removing consumer from queue ${args.queueName}.`);
29
+ await deleteConsumer(config, args.queueName, args.scriptName, args.env);
30
+ logger.log(`Removed consumer from queue ${args.queueName}.`);
38
31
  }
@@ -1,14 +1,12 @@
1
- import { type Argv } from "yargs";
2
1
  import { readConfig } from "../../../config";
3
2
  import { logger } from "../../../logger";
4
3
  import { createQueue } from "../../client";
4
+ import type {
5
+ CommonYargsArgv,
6
+ StrictYargsOptionsToInterface,
7
+ } from "../../../yargs-types";
5
8
 
6
- interface Args {
7
- config?: string;
8
- name: string;
9
- }
10
-
11
- export function options(yargs: Argv): Argv<Args> {
9
+ export function options(yargs: CommonYargsArgv) {
12
10
  return yargs.positional("name", {
13
11
  type: "string",
14
12
  demandOption: true,
@@ -16,7 +14,9 @@ export function options(yargs: Argv): Argv<Args> {
16
14
  });
17
15
  }
18
16
 
19
- export async function handler(args: Args) {
17
+ export async function handler(
18
+ args: StrictYargsOptionsToInterface<typeof options>
19
+ ) {
20
20
  const config = readConfig(args.config, args);
21
21
 
22
22
  logger.log(`Creating queue ${args.name}.`);
@@ -1,14 +1,12 @@
1
- import { type Argv } from "yargs";
2
1
  import { readConfig } from "../../../config";
3
2
  import { logger } from "../../../logger";
4
3
  import { deleteQueue } from "../../client";
4
+ import type {
5
+ CommonYargsArgv,
6
+ StrictYargsOptionsToInterface,
7
+ } from "../../../yargs-types";
5
8
 
6
- interface Args {
7
- config?: string;
8
- name: string;
9
- }
10
-
11
- export function options(yargs: Argv): Argv<Args> {
9
+ export function options(yargs: CommonYargsArgv) {
12
10
  // TODO(soon) --force option
13
11
  return yargs.positional("name", {
14
12
  type: "string",
@@ -17,7 +15,9 @@ export function options(yargs: Argv): Argv<Args> {
17
15
  });
18
16
  }
19
17
 
20
- export async function handler(args: Args) {
18
+ export async function handler(
19
+ args: StrictYargsOptionsToInterface<typeof options>
20
+ ) {
21
21
  const config = readConfig(args.config, args);
22
22
 
23
23
  logger.log(`Deleting queue ${args.name}.`);
@@ -1,13 +1,12 @@
1
- import { type BuilderCallback } from "yargs";
2
- import { type CommonYargsOptions } from "../../../yargs-types";
3
1
  import { HandleUnauthorizedError } from "../../utils";
4
2
  import { consumers } from "./consumer";
5
3
 
6
4
  import { options as createOptions, handler as createHandler } from "./create";
7
5
  import { options as deleteOptions, handler as deleteHandler } from "./delete";
8
6
  import { options as listOptions, handler as listHandler } from "./list";
7
+ import type { CommonYargsArgv } from "../../../yargs-types";
9
8
 
10
- export const queues: BuilderCallback<CommonYargsOptions, unknown> = (yargs) => {
9
+ export function queues(yargs: CommonYargsArgv) {
11
10
  yargs.command("list", "List Queues", listOptions, listHandler);
12
11
 
13
12
  yargs.command(
@@ -33,4 +32,4 @@ export const queues: BuilderCallback<CommonYargsOptions, unknown> = (yargs) => {
33
32
  );
34
33
 
35
34
  yargs.fail(HandleUnauthorizedError);
36
- };
35
+ }
@@ -1,14 +1,12 @@
1
- import { type Argv } from "yargs";
2
1
  import { readConfig } from "../../../config";
3
2
  import { logger } from "../../../logger";
4
3
  import { listQueues } from "../../client";
4
+ import type {
5
+ CommonYargsArgv,
6
+ StrictYargsOptionsToInterface,
7
+ } from "../../../yargs-types";
5
8
 
6
- interface Args {
7
- config?: string;
8
- page?: number;
9
- }
10
-
11
- export function options(yargs: Argv): Argv<Args> {
9
+ export function options(yargs: CommonYargsArgv) {
12
10
  return yargs.options({
13
11
  page: {
14
12
  type: "number",
@@ -17,7 +15,9 @@ export function options(yargs: Argv): Argv<Args> {
17
15
  });
18
16
  }
19
17
 
20
- export async function handler(args: Args) {
18
+ export async function handler(
19
+ args: StrictYargsOptionsToInterface<typeof options>
20
+ ) {
21
21
  const config = readConfig(args.config, args);
22
22
 
23
23
  const queues = await listQueues(config, args.page);
package/src/r2/index.ts CHANGED
@@ -19,22 +19,23 @@ import {
19
19
  putR2Object,
20
20
  } from "./helpers";
21
21
 
22
- import type { ConfigPath } from "../index";
22
+ import type { CommonYargsArgv } from "../yargs-types";
23
23
  import type { Readable } from "node:stream";
24
- import type { BuilderCallback } from "yargs";
25
24
 
26
- export const r2: BuilderCallback<unknown, unknown> = (r2Yargs) => {
25
+ export function r2(r2Yargs: CommonYargsArgv) {
27
26
  return r2Yargs
28
27
  .command("object", "Manage R2 objects", (r2ObjectYargs) => {
29
28
  return r2ObjectYargs
30
29
  .command(
31
30
  "get <objectPath>",
32
31
  "Fetch an object from an R2 bucket",
33
- (Objectyargs) => {
34
- return Objectyargs.positional("objectPath", {
35
- describe: "The source object path in the form of {bucket}/{key}",
36
- type: "string",
37
- })
32
+ (objectArgs) => {
33
+ return objectArgs
34
+ .positional("objectPath", {
35
+ describe:
36
+ "The source object path in the form of {bucket}/{key}",
37
+ type: "string",
38
+ })
38
39
  .option("file", {
39
40
  describe: "The destination file to create",
40
41
  alias: "f",
@@ -51,10 +52,7 @@ export const r2: BuilderCallback<unknown, unknown> = (r2Yargs) => {
51
52
  });
52
53
  },
53
54
  async (objectGetYargs) => {
54
- const config = readConfig(
55
- objectGetYargs.config as ConfigPath,
56
- objectGetYargs
57
- );
55
+ const config = readConfig(objectGetYargs.config, objectGetYargs);
58
56
  const accountId = await requireAuth(config);
59
57
  const { objectPath, pipe } = objectGetYargs;
60
58
  const { bucket, key } = bucketAndKeyFromObjectPath(objectPath);
@@ -144,10 +142,7 @@ export const r2: BuilderCallback<unknown, unknown> = (r2Yargs) => {
144
142
  async (objectPutYargs) => {
145
143
  await printWranglerBanner();
146
144
 
147
- const config = readConfig(
148
- objectPutYargs.config as ConfigPath,
149
- objectPutYargs
150
- );
145
+ const config = readConfig(objectPutYargs.config, objectPutYargs);
151
146
  const accountId = await requireAuth(config);
152
147
  const { objectPath, file, pipe, ...options } = objectPutYargs;
153
148
  const { bucket, key } = bucketAndKeyFromObjectPath(objectPath);
@@ -210,7 +205,7 @@ export const r2: BuilderCallback<unknown, unknown> = (r2Yargs) => {
210
205
  const { objectPath } = args;
211
206
  await printWranglerBanner();
212
207
 
213
- const config = readConfig(args.config as ConfigPath, args);
208
+ const config = readConfig(args.config, args);
214
209
  const accountId = await requireAuth(config);
215
210
  const { bucket, key } = bucketAndKeyFromObjectPath(objectPath);
216
211
  logger.log(`Deleting object "${key}" from bucket "${bucket}".`);
@@ -235,7 +230,7 @@ export const r2: BuilderCallback<unknown, unknown> = (r2Yargs) => {
235
230
  async (args) => {
236
231
  await printWranglerBanner();
237
232
 
238
- const config = readConfig(args.config as ConfigPath, args);
233
+ const config = readConfig(args.config, args);
239
234
 
240
235
  const accountId = await requireAuth(config);
241
236
 
@@ -248,16 +243,21 @@ export const r2: BuilderCallback<unknown, unknown> = (r2Yargs) => {
248
243
  }
249
244
  );
250
245
 
251
- r2BucketYargs.command("list", "List R2 buckets", {}, async (args) => {
252
- const config = readConfig(args.config as ConfigPath, args);
246
+ r2BucketYargs.command(
247
+ "list",
248
+ "List R2 buckets",
249
+ (listArgs) => listArgs,
250
+ async (args) => {
251
+ const config = readConfig(args.config, args);
253
252
 
254
- const accountId = await requireAuth(config);
253
+ const accountId = await requireAuth(config);
255
254
 
256
- logger.log(JSON.stringify(await listR2Buckets(accountId), null, 2));
257
- await metrics.sendMetricsEvent("list r2 buckets", {
258
- sendMetrics: config.send_metrics,
259
- });
260
- });
255
+ logger.log(JSON.stringify(await listR2Buckets(accountId), null, 2));
256
+ await metrics.sendMetricsEvent("list r2 buckets", {
257
+ sendMetrics: config.send_metrics,
258
+ });
259
+ }
260
+ );
261
261
 
262
262
  r2BucketYargs.command(
263
263
  "delete <name>",
@@ -272,7 +272,7 @@ export const r2: BuilderCallback<unknown, unknown> = (r2Yargs) => {
272
272
  async (args) => {
273
273
  await printWranglerBanner();
274
274
 
275
- const config = readConfig(args.config as ConfigPath, args);
275
+ const config = readConfig(args.config, args);
276
276
 
277
277
  const accountId = await requireAuth(config);
278
278
 
@@ -286,4 +286,4 @@ export const r2: BuilderCallback<unknown, unknown> = (r2Yargs) => {
286
286
  );
287
287
  return r2BucketYargs;
288
288
  });
289
- };
289
+ }