wrangler 0.0.0-e6c9c5c0 → 0.0.0-e6e1daba

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 (126) hide show
  1. package/README.md +3 -3
  2. package/miniflare-dist/index.mjs +22 -18
  3. package/package.json +12 -12
  4. package/src/__tests__/configuration.test.ts +70 -0
  5. package/src/__tests__/d1/d1.test.ts +13 -58
  6. package/src/__tests__/d1/execute.test.ts +64 -0
  7. package/src/__tests__/d1/migrate.test.ts +155 -0
  8. package/src/__tests__/deployments.test.ts +40 -16
  9. package/src/__tests__/dev.test.tsx +8 -7
  10. package/src/__tests__/generate.test.ts +1 -1
  11. package/src/__tests__/guess-worker-format.test.ts +35 -0
  12. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  13. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  14. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  15. package/src/__tests__/helpers/msw/handlers/deployments.ts +40 -16
  16. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  17. package/src/__tests__/index.test.ts +38 -32
  18. package/src/__tests__/init.test.ts +1 -1
  19. package/src/__tests__/kv.test.ts +63 -52
  20. package/src/__tests__/middleware.test.ts +65 -0
  21. package/src/__tests__/mtls-certificates.test.ts +585 -0
  22. package/src/__tests__/pages/deployment-list.test.ts +78 -0
  23. package/src/__tests__/pages/functions-build.test.ts +402 -0
  24. package/src/__tests__/pages/pages.test.ts +81 -0
  25. package/src/__tests__/pages/project-create.test.ts +63 -0
  26. package/src/__tests__/pages/project-list.test.ts +108 -0
  27. package/src/__tests__/pages/project-upload.test.ts +481 -0
  28. package/src/__tests__/pages/publish.test.ts +2745 -0
  29. package/src/__tests__/parse.test.ts +106 -0
  30. package/src/__tests__/publish.test.ts +80 -30
  31. package/src/__tests__/pubsub.test.ts +15 -12
  32. package/src/__tests__/queues.test.ts +37 -30
  33. package/src/__tests__/r2.test.ts +25 -20
  34. package/src/__tests__/secret.test.ts +4 -4
  35. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  36. package/src/__tests__/user.test.ts +1 -1
  37. package/src/__tests__/whoami.test.tsx +1 -1
  38. package/src/__tests__/worker-namespace.test.ts +26 -21
  39. package/src/api/dev.ts +80 -11
  40. package/src/api/index.ts +8 -0
  41. package/src/api/mtls-certificate.ts +148 -0
  42. package/src/api/pages/create-worker-bundle-contents.ts +75 -0
  43. package/src/api/pages/publish.tsx +59 -12
  44. package/src/bundle.ts +9 -7
  45. package/src/config/config.ts +14 -7
  46. package/src/config/environment.ts +9 -2
  47. package/src/config/index.ts +37 -20
  48. package/src/config/validation.ts +50 -3
  49. package/src/create-worker-preview.ts +19 -8
  50. package/src/create-worker-upload-form.ts +9 -0
  51. package/src/d1/backups.tsx +20 -24
  52. package/src/d1/create.tsx +6 -5
  53. package/src/d1/delete.ts +7 -10
  54. package/src/d1/execute.tsx +174 -143
  55. package/src/d1/index.ts +5 -6
  56. package/src/d1/list.tsx +21 -9
  57. package/src/d1/migrations/apply.tsx +42 -33
  58. package/src/d1/migrations/create.tsx +16 -17
  59. package/src/d1/migrations/helpers.ts +63 -38
  60. package/src/d1/migrations/list.tsx +37 -24
  61. package/src/d1/migrations/options.ts +7 -2
  62. package/src/d1/options.ts +3 -3
  63. package/src/d1/types.ts +1 -0
  64. package/src/d1/utils.ts +2 -1
  65. package/src/delete.ts +5 -8
  66. package/src/deployments.ts +62 -39
  67. package/src/deprecated/index.ts +7 -8
  68. package/src/dev/dev.tsx +1 -15
  69. package/src/dev/local.tsx +5 -6
  70. package/src/dev/remote.tsx +2 -2
  71. package/src/dev.tsx +51 -86
  72. package/src/dispatch-namespace.ts +20 -16
  73. package/src/docs/index.ts +7 -8
  74. package/src/entry.ts +1 -2
  75. package/src/generate/index.ts +6 -8
  76. package/src/index.ts +37 -26
  77. package/src/init.ts +5 -7
  78. package/src/inspect.ts +16 -1
  79. package/src/kv/index.ts +15 -17
  80. package/src/miniflare-cli/assets.ts +9 -8
  81. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  82. package/src/mtls-certificate/cli.ts +155 -0
  83. package/src/pages/build.ts +109 -27
  84. package/src/pages/buildFunctions.ts +32 -31
  85. package/src/pages/deployment-tails.ts +7 -10
  86. package/src/pages/deployments.tsx +6 -4
  87. package/src/pages/dev.ts +19 -19
  88. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  89. package/src/pages/functions.ts +8 -4
  90. package/src/pages/index.ts +3 -3
  91. package/src/pages/projects.tsx +7 -12
  92. package/src/pages/publish.tsx +18 -5
  93. package/src/pages/types.ts +5 -0
  94. package/src/pages/upload.tsx +6 -4
  95. package/src/pages/utils.ts +1 -1
  96. package/src/parse.ts +23 -1
  97. package/src/publish/index.ts +19 -15
  98. package/src/publish/publish.ts +5 -4
  99. package/src/pubsub/pubsub-commands.ts +18 -19
  100. package/src/queues/cli/commands/consumer/add.ts +18 -24
  101. package/src/queues/cli/commands/consumer/index.ts +3 -6
  102. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  103. package/src/queues/cli/commands/create.ts +8 -8
  104. package/src/queues/cli/commands/delete.ts +8 -8
  105. package/src/queues/cli/commands/index.ts +3 -4
  106. package/src/queues/cli/commands/list.ts +8 -8
  107. package/src/r2/helpers.ts +1 -0
  108. package/src/r2/index.ts +28 -28
  109. package/src/secret/index.ts +10 -14
  110. package/src/sites.ts +1 -1
  111. package/src/tail/filters.ts +1 -1
  112. package/src/tail/index.ts +6 -8
  113. package/src/user/user.ts +4 -3
  114. package/src/worker.ts +6 -0
  115. package/src/yargs-types.ts +18 -5
  116. package/templates/checked-fetch.js +9 -1
  117. package/templates/format-dev-errors.ts +1 -0
  118. package/templates/new-worker.ts +3 -0
  119. package/templates/pages-template-plugin.ts +7 -3
  120. package/templates/serve-static-assets.ts +1 -0
  121. package/templates/service-bindings-module-facade.js +1 -0
  122. package/templates/tsconfig.init.json +1 -1
  123. package/templates/tsconfig.tsbuildinfo +1 -1
  124. package/wrangler-dist/cli.d.ts +596 -3
  125. package/wrangler-dist/cli.js +14276 -6748
  126. package/src/__tests__/pages.test.ts +0 -2898
@@ -1,4 +1,5 @@
1
1
  import type { Environment, RawEnvironment } from "./environment";
2
+ import type { CamelCaseKey } from "yargs";
2
3
 
3
4
  /**
4
5
  * This is the static type definition for the configuration object.
@@ -17,7 +18,7 @@ import type { Environment, RawEnvironment } from "./environment";
17
18
  *
18
19
  * Legend for the annotations:
19
20
  *
20
- * - `@breaking`: the deprecation/optionality is a breaking change from wrangler 1.
21
+ * - `@breaking`: the deprecation/optionality is a breaking change from Wrangler v1.
21
22
  * - `@todo`: there's more work to be done (with details attached).
22
23
  */
23
24
  export type Config = ConfigFields<DevConfig> & Environment;
@@ -31,7 +32,7 @@ export interface ConfigFields<Dev extends RawDevConfig> {
31
32
  configPath: string | undefined;
32
33
 
33
34
  /**
34
- * A boolean to enable "legacy" style wrangler environments (from wrangler 1).
35
+ * A boolean to enable "legacy" style wrangler environments (from Wrangler v1).
35
36
  * These have been superseded by Services, but there may be projects that won't
36
37
  * (or can't) use them. If you're using a legacy environment, you can set this
37
38
  * to `true` to enable it.
@@ -95,7 +96,7 @@ export interface ConfigFields<Dev extends RawDevConfig> {
95
96
  /**
96
97
  * The location of your Worker script.
97
98
  *
98
- * @deprecated DO NOT use this (it's a holdover from wrangler 1.x). Either use the top level `main` field, or pass the path to your entry file as a command line argument.
99
+ * @deprecated DO NOT use this (it's a holdover from Wrangler v1.x). Either use the top level `main` field, or pass the path to your entry file as a command line argument.
99
100
  * @breaking
100
101
  */
101
102
  "entry-point"?: string;
@@ -215,10 +216,10 @@ export interface DevConfig {
215
216
  * Protocol that wrangler dev forwards requests on
216
217
  *
217
218
  * Setting this to `http` is not currently implemented.
218
- * See https://github.com/cloudflare/wrangler2/issues/583
219
+ * See https://github.com/cloudflare/workers-sdk/issues/583
219
220
  *
220
221
  * @default `https`
221
- * @todo this needs to be implemented https://github.com/cloudflare/wrangler2/issues/583
222
+ * @todo this needs to be implemented https://github.com/cloudflare/workers-sdk/issues/583
222
223
  */
223
224
  upstream_protocol: "https" | "http";
224
225
 
@@ -232,7 +233,7 @@ export type RawDevConfig = Partial<DevConfig>;
232
233
 
233
234
  export interface DeprecatedConfigFields {
234
235
  /**
235
- * The project "type". A holdover from wrangler 1.x.
236
+ * The project "type". A holdover from Wrangler v1.x.
236
237
  * Valid values were "webpack", "javascript", and "rust".
237
238
  *
238
239
  * @deprecated DO NOT USE THIS. 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.
@@ -242,7 +243,7 @@ export interface DeprecatedConfigFields {
242
243
 
243
244
  /**
244
245
  * Path to the webpack config to use when building your worker.
245
- * A holdover from wrangler 1.x, used with `type: "webpack"`.
246
+ * A holdover from Wrangler v1.x, used with `type: "webpack"`.
246
247
  *
247
248
  * @deprecated DO NOT USE THIS. 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.
248
249
  * @breaking
@@ -273,3 +274,9 @@ interface EnvironmentMap {
273
274
  [envName: string]: RawEnvironment;
274
275
  };
275
276
  }
277
+
278
+ // API dev only passes in camel-cased versions of keys, so ensure
279
+ // only camel-cased keys are used
280
+ export type OnlyCamelCase<T = Record<string, never>> = {
281
+ [key in keyof T as CamelCaseKey<key>]: T[key];
282
+ };
@@ -78,7 +78,7 @@ interface EnvironmentInheritable {
78
78
  * Whether we use <name>.<subdomain>.workers.dev to
79
79
  * test and deploy your worker.
80
80
  *
81
- * @default `true` (This is a breaking change from wrangler 1)
81
+ * @default `true` (This is a breaking change from Wrangler v1)
82
82
  * @breaking
83
83
  * @inheritable
84
84
  */
@@ -480,6 +480,13 @@ interface EnvironmentNonInheritable {
480
480
  [key: string]: unknown;
481
481
  }[];
482
482
  };
483
+
484
+ mtls_certificates: {
485
+ /** The binding name used to refer to the certificate in the worker */
486
+ binding: string;
487
+ /** The uuid of the uploaded mTLS certificate */
488
+ certificate_id: string;
489
+ }[];
483
490
  }
484
491
 
485
492
  /**
@@ -497,7 +504,7 @@ interface EnvironmentDeprecated {
497
504
  /**
498
505
  * Legacy way of defining KVNamespaces that is no longer supported.
499
506
  *
500
- * @deprecated DO NOT USE. This was a legacy bug from wrangler 1, that we do not want to support.
507
+ * @deprecated DO NOT USE. This was a legacy bug from Wrangler v1, that we do not want to support.
501
508
  */
502
509
  "kv-namespaces"?: string;
503
510
 
@@ -2,12 +2,12 @@ import fs from "node:fs";
2
2
  import dotenv from "dotenv";
3
3
  import { findUpSync } from "find-up";
4
4
  import { logger } from "../logger";
5
- import { parseTOML, readFileSync } from "../parse";
5
+ import { parseJSONC, parseTOML, readFileSync } from "../parse";
6
6
  import { removeD1BetaPrefix } from "../worker";
7
7
  import { normalizeAndValidateConfig } from "./validation";
8
8
  import type { CfWorkerInit } from "../worker";
9
- import type { Config, RawConfig } from "./config";
10
- import type { CamelCaseKey } from "yargs";
9
+ import type { CommonYargsOptions } from "../yargs-types";
10
+ import type { Config, OnlyCamelCase, RawConfig } from "./config";
11
11
 
12
12
  export type {
13
13
  Config,
@@ -25,18 +25,21 @@ export type {
25
25
  /**
26
26
  * Get the Wrangler configuration; read it from the give `configPath` if available.
27
27
  */
28
- export function readConfig(
28
+
29
+ export function readConfig<CommandArgs>(
29
30
  configPath: string | undefined,
30
- args: unknown
31
+ // Include command specific args as well as the wrangler global flags
32
+ args: CommandArgs & OnlyCamelCase<CommonYargsOptions>
31
33
  ): Config {
32
34
  let rawConfig: RawConfig = {};
33
35
  if (!configPath) {
34
- configPath = findWranglerToml();
36
+ configPath = findWranglerToml(process.cwd(), args.experimentalJsonConfig);
35
37
  }
36
-
37
38
  // Load the configuration from disk if available
38
- if (configPath) {
39
+ if (configPath?.endsWith("toml")) {
39
40
  rawConfig = parseTOML(readFileSync(configPath), configPath);
41
+ } else if (configPath?.endsWith("json")) {
42
+ rawConfig = parseJSONC(readFileSync(configPath), configPath);
40
43
  }
41
44
 
42
45
  // Process the top-level configuration.
@@ -61,10 +64,16 @@ export function readConfig(
61
64
  * from the current working directory.
62
65
  */
63
66
  export function findWranglerToml(
64
- referencePath: string = process.cwd()
67
+ referencePath: string = process.cwd(),
68
+ preferJson = false
65
69
  ): string | undefined {
66
- const configPath = findUpSync("wrangler.toml", { cwd: referencePath });
67
- return configPath;
70
+ if (preferJson) {
71
+ return (
72
+ findUpSync(`wrangler.json`, { cwd: referencePath }) ??
73
+ findUpSync(`wrangler.toml`, { cwd: referencePath })
74
+ );
75
+ }
76
+ return findUpSync(`wrangler.toml`, { cwd: referencePath });
68
77
  }
69
78
 
70
79
  /**
@@ -99,6 +108,7 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) {
99
108
  vars,
100
109
  wasm_modules,
101
110
  dispatch_namespaces,
111
+ mtls_certificates,
102
112
  } = bindings;
103
113
 
104
114
  if (data_blobs !== undefined && Object.keys(data_blobs).length > 0) {
@@ -297,6 +307,18 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) {
297
307
  });
298
308
  }
299
309
 
310
+ if (mtls_certificates !== undefined && mtls_certificates.length > 0) {
311
+ output.push({
312
+ type: "mTLS Certificates",
313
+ entries: mtls_certificates.map(({ binding, certificate_id }) => {
314
+ return {
315
+ key: binding,
316
+ value: certificate_id,
317
+ };
318
+ }),
319
+ });
320
+ }
321
+
300
322
  if (output.length === 0) {
301
323
  return;
302
324
  }
@@ -316,18 +338,13 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) {
316
338
  logger.log(message);
317
339
  }
318
340
 
319
- type CamelCase<T> = {
320
- [key in keyof T as key | CamelCaseKey<key>]: T[key];
321
- };
322
-
323
- export function withConfig<T extends { config?: string }>(
341
+ export function withConfig<T>(
324
342
  handler: (
325
- t: Omit<CamelCase<T>, "config"> & { config: Config }
343
+ t: OnlyCamelCase<T & CommonYargsOptions> & { config: Config }
326
344
  ) => Promise<void>
327
345
  ) {
328
- return (t: CamelCase<T>) => {
329
- const { config: configPath, ...rest } = t;
330
- return handler({ ...rest, config: readConfig(configPath, rest) });
346
+ return (t: OnlyCamelCase<T & CommonYargsOptions>) => {
347
+ return handler({ ...t, config: readConfig(t.config, t) });
331
348
  };
332
349
  }
333
350
 
@@ -741,7 +741,7 @@ function isValidRouteValue(item: unknown): boolean {
741
741
 
742
742
  /**
743
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 = '',
744
+ * This is to workaround older Wrangler v1-era templates that have account_id = '',
745
745
  * which isn't a valid value anyway
746
746
  */
747
747
  function mutateEmptyStringAccountIDValue(
@@ -760,7 +760,7 @@ function mutateEmptyStringAccountIDValue(
760
760
 
761
761
  /**
762
762
  * Normalize empty string to `undefined` by mutating rawEnv.route value.
763
- * As part of backward compatibility with Wrangler1 converting empty string to `undefined`
763
+ * As part of backward compatibility with Wrangler v1 converting empty string to `undefined`
764
764
  */
765
765
  function mutateEmptyStringRouteValue(
766
766
  diagnostics: Diagnostics,
@@ -1134,6 +1134,16 @@ function normalizeAndValidateEnvironment(
1134
1134
  validateBindingArray(envName, validateWorkerNamespaceBinding),
1135
1135
  []
1136
1136
  ),
1137
+ mtls_certificates: notInheritable(
1138
+ diagnostics,
1139
+ topLevelEnv,
1140
+ rawConfig,
1141
+ rawEnv,
1142
+ envName,
1143
+ "mtls_certificates",
1144
+ validateBindingArray(envName, validateMTlsCertificateBinding),
1145
+ []
1146
+ ),
1137
1147
  logfwdr: inheritable(
1138
1148
  diagnostics,
1139
1149
  topLevelEnv,
@@ -1590,6 +1600,7 @@ const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => {
1590
1600
  "r2_bucket",
1591
1601
  "service",
1592
1602
  "logfwdr",
1603
+ "mtls_certificate",
1593
1604
  ];
1594
1605
 
1595
1606
  if (safeBindings.includes(value.type)) {
@@ -1823,7 +1834,7 @@ const validateD1Binding: ValidatorFn = (diagnostics, field, value) => {
1823
1834
  }
1824
1835
  if (isValid && !process.env.NO_D1_WARNING) {
1825
1836
  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>`"
1837
+ "D1 Bindings are currently in alpha to allow the API to evolve before general availability.\nPlease report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose\nNote: Run this command with the environment variable NO_D1_WARNING=true to hide this message\n\nFor example: `export NO_D1_WARNING=true && wrangler <YOUR COMMAND HERE>`"
1827
1838
  );
1828
1839
  }
1829
1840
  return isValid;
@@ -2036,6 +2047,42 @@ const validateWorkerNamespaceBinding: ValidatorFn = (
2036
2047
  return isValid;
2037
2048
  };
2038
2049
 
2050
+ const validateMTlsCertificateBinding: ValidatorFn = (
2051
+ diagnostics,
2052
+ field,
2053
+ value
2054
+ ) => {
2055
+ if (typeof value !== "object" || value === null) {
2056
+ diagnostics.errors.push(
2057
+ `"mtls_certificates" bindings should be objects, but got ${JSON.stringify(
2058
+ value
2059
+ )}`
2060
+ );
2061
+ return false;
2062
+ }
2063
+ let isValid = true;
2064
+ if (!isRequiredProperty(value, "binding", "string")) {
2065
+ diagnostics.errors.push(
2066
+ `"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
2067
+ value
2068
+ )}.`
2069
+ );
2070
+ isValid = false;
2071
+ }
2072
+ if (
2073
+ !isRequiredProperty(value, "certificate_id", "string") ||
2074
+ (value as { certificate_id: string }).certificate_id.length === 0
2075
+ ) {
2076
+ diagnostics.errors.push(
2077
+ `"${field}" bindings should have a string "certificate_id" field but got ${JSON.stringify(
2078
+ value
2079
+ )}.`
2080
+ );
2081
+ isValid = false;
2082
+ }
2083
+ return isValid;
2084
+ };
2085
+
2039
2086
  function validateQueues(envName: string): ValidatorFn {
2040
2087
  return (diagnostics, field, value, config) => {
2041
2088
  const fieldPath =
@@ -109,6 +109,14 @@ function randomId(): string {
109
109
  });
110
110
  }
111
111
 
112
+ // URLs are often relative to the zone. Sometimes the base zone
113
+ // will be grey-clouded, and so the host must be swapped out for
114
+ // the worker route host, which is more likely to be orange-clouded
115
+ function switchHost(originalUrl: string, host?: string): URL {
116
+ const url = new URL(originalUrl);
117
+ url.hostname = host ?? url.hostname;
118
+ return url;
119
+ }
112
120
  /**
113
121
  * Generates a preview session token.
114
122
  */
@@ -129,9 +137,13 @@ export async function createPreviewSession(
129
137
  abortSignal
130
138
  );
131
139
 
132
- logger.debug(`-- START EXCHANGE API REQUEST: GET ${exchange_url}`);
140
+ const switchedExchangeUrl = switchHost(exchange_url, ctx.host).toString();
141
+
142
+ logger.debug(`-- START EXCHANGE API REQUEST: GET ${switchedExchangeUrl}`);
133
143
  logger.debug("-- END EXCHANGE API REQUEST");
134
- const exchangeResponse = await fetch(exchange_url, { signal: abortSignal });
144
+ const exchangeResponse = await fetch(switchedExchangeUrl, {
145
+ signal: abortSignal,
146
+ });
135
147
  const bodyText = await exchangeResponse.text();
136
148
  logger.debug(
137
149
  "-- START EXCHANGE API RESPONSE:",
@@ -147,16 +159,15 @@ export async function createPreviewSession(
147
159
  token: string;
148
160
  prewarm: string;
149
161
  }>(bodyText);
150
-
151
- const { host } = new URL(inspector_websocket);
152
- const query = `cf_workers_preview_token=${token}`;
162
+ const inspector = new URL(inspector_websocket);
163
+ inspector.searchParams.append("cf_workers_preview_token", token);
153
164
 
154
165
  return {
155
166
  id: randomId(),
156
167
  value: token,
157
- host,
158
- inspectorUrl: new URL(`${inspector_websocket}?${query}`),
159
- prewarmUrl: new URL(prewarm),
168
+ host: ctx.host ?? inspector.host,
169
+ inspectorUrl: switchHost(inspector.href, ctx.host),
170
+ prewarmUrl: switchHost(prewarm, ctx.host),
160
171
  };
161
172
  }
162
173
 
@@ -45,6 +45,7 @@ type WorkerMetadataBinding =
45
45
  | { type: "service"; name: string; service: string; environment?: string }
46
46
  | { type: "analytics_engine"; name: string; dataset?: string }
47
47
  | { type: "dispatch_namespace"; name: string; namespace: string }
48
+ | { type: "mtls_certificate"; name: string; certificate_id: string }
48
49
  | {
49
50
  type: "logfwdr";
50
51
  name: string;
@@ -166,6 +167,14 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData {
166
167
  });
167
168
  });
168
169
 
170
+ bindings.mtls_certificates?.forEach(({ binding, certificate_id }) => {
171
+ metadataBindings.push({
172
+ name: binding,
173
+ type: "mtls_certificate",
174
+ certificate_id,
175
+ });
176
+ });
177
+
169
178
  bindings.logfwdr?.bindings.forEach(({ name, destination }) => {
170
179
  metadataBindings.push({
171
180
  name: name,
@@ -11,17 +11,18 @@ import { requireAuth } from "../user";
11
11
  import { formatBytes, formatTimeAgo } from "./formatTimeAgo";
12
12
  import { Name } from "./options";
13
13
  import { d1BetaWarning, getDatabaseByNameOrBinding } from "./utils";
14
+ import type {
15
+ CommonYargsArgv,
16
+ StrictYargsOptionsToInterface,
17
+ } from "../yargs-types";
14
18
  import type { Backup, Database } from "./types";
15
19
  import type { Response } from "undici";
16
- import type { Argv } from "yargs";
17
20
 
18
- type BackupListArgs = { config?: string; name: string };
19
-
20
- export function ListOptions(yargs: Argv): Argv<BackupListArgs> {
21
+ export function ListOptions(yargs: CommonYargsArgv) {
21
22
  return Name(yargs);
22
23
  }
23
-
24
- export const ListHandler = withConfig<BackupListArgs>(
24
+ type ListHandlerOptions = StrictYargsOptionsToInterface<typeof ListOptions>;
25
+ export const ListHandler = withConfig<ListHandlerOptions>(
25
26
  async ({ config, name }): Promise<void> => {
26
27
  const accountId = await requireAuth({});
27
28
  logger.log(d1BetaWarning);
@@ -77,13 +78,12 @@ export const listBackups = async (
77
78
  return Object.values(results);
78
79
  };
79
80
 
80
- type BackupCreateArgs = BackupListArgs;
81
-
82
- export function CreateOptions(yargs: Argv): Argv<BackupCreateArgs> {
81
+ export function CreateOptions(yargs: CommonYargsArgv) {
83
82
  return ListOptions(yargs);
84
83
  }
84
+ type CreateHandlerOptions = StrictYargsOptionsToInterface<typeof CreateOptions>;
85
85
 
86
- export const CreateHandler = withConfig<BackupCreateArgs>(
86
+ export const CreateHandler = withConfig<CreateHandlerOptions>(
87
87
  async ({ config, name }): Promise<void> => {
88
88
  const accountId = await requireAuth({});
89
89
  logger.log(d1BetaWarning);
@@ -119,19 +119,17 @@ export const createBackup = async (
119
119
  };
120
120
  };
121
121
 
122
- type BackupRestoreArgs = BackupListArgs & {
123
- "backup-id": string;
124
- };
125
-
126
- export function RestoreOptions(yargs: Argv): Argv<BackupRestoreArgs> {
122
+ export function RestoreOptions(yargs: CommonYargsArgv) {
127
123
  return ListOptions(yargs).positional("backup-id", {
128
124
  describe: "The Backup ID to restore",
129
125
  type: "string",
130
126
  demandOption: true,
131
127
  });
132
128
  }
133
-
134
- export const RestoreHandler = withConfig<BackupRestoreArgs>(
129
+ type RestoreHandlerOptions = StrictYargsOptionsToInterface<
130
+ typeof RestoreOptions
131
+ >;
132
+ export const RestoreHandler = withConfig<RestoreHandlerOptions>(
135
133
  async ({ config, name, backupId }): Promise<void> => {
136
134
  const accountId = await requireAuth({});
137
135
  logger.log(d1BetaWarning);
@@ -163,11 +161,7 @@ export const restoreBackup = async (
163
161
  );
164
162
  };
165
163
 
166
- type BackupDownloadArgs = BackupRestoreArgs & {
167
- output?: string;
168
- };
169
-
170
- export function DownloadOptions(yargs: Argv): Argv<BackupDownloadArgs> {
164
+ export function DownloadOptions(yargs: CommonYargsArgv) {
171
165
  return ListOptions(yargs)
172
166
  .positional("backup-id", {
173
167
  describe: "The Backup ID to download",
@@ -180,8 +174,10 @@ export function DownloadOptions(yargs: Argv): Argv<BackupDownloadArgs> {
180
174
  type: "string",
181
175
  });
182
176
  }
183
-
184
- export const DownloadHandler = withConfig<BackupDownloadArgs>(
177
+ type DownloadHandlerOptions = StrictYargsOptionsToInterface<
178
+ typeof DownloadOptions
179
+ >;
180
+ export const DownloadHandler = withConfig<DownloadHandlerOptions>(
185
181
  async ({ name, backupId, output, config }): Promise<void> => {
186
182
  const accountId = await requireAuth({});
187
183
  logger.log(d1BetaWarning);
package/src/d1/create.tsx CHANGED
@@ -4,12 +4,13 @@ import { fetchResult } from "../cfetch";
4
4
  import { logger } from "../logger";
5
5
  import { requireAuth } from "../user";
6
6
  import { d1BetaWarning } from "./utils";
7
+ import type {
8
+ CommonYargsArgv,
9
+ StrictYargsOptionsToInterface,
10
+ } from "../yargs-types";
7
11
  import type { Database } from "./types";
8
- import type { ArgumentsCamelCase, Argv } from "yargs";
9
12
 
10
- type CreateArgs = { name: string };
11
-
12
- export function Options(yargs: Argv): Argv<CreateArgs> {
13
+ export function Options(yargs: CommonYargsArgv) {
13
14
  return yargs
14
15
  .positional("name", {
15
16
  describe: "The name of the new DB",
@@ -21,7 +22,7 @@ export function Options(yargs: Argv): Argv<CreateArgs> {
21
22
 
22
23
  export async function Handler({
23
24
  name,
24
- }: ArgumentsCamelCase<CreateArgs>): Promise<void> {
25
+ }: StrictYargsOptionsToInterface<typeof Options>): Promise<void> {
25
26
  const accountId = await requireAuth({});
26
27
 
27
28
  logger.log(d1BetaWarning);
package/src/d1/delete.ts CHANGED
@@ -5,16 +5,13 @@ import { logger } from "../logger";
5
5
  import { requireAuth } from "../user";
6
6
  import { Name } from "./options";
7
7
  import { d1BetaWarning, getDatabaseByNameOrBinding } from "./utils";
8
+ import type {
9
+ CommonYargsArgv,
10
+ StrictYargsOptionsToInterface,
11
+ } from "../yargs-types";
8
12
  import type { Database } from "./types";
9
- import type { Argv } from "yargs";
10
13
 
11
- type CreateArgs = {
12
- config?: string;
13
- name: string;
14
- "skip-confirmation": boolean;
15
- };
16
-
17
- export function Options(d1ListYargs: Argv): Argv<CreateArgs> {
14
+ export function Options(d1ListYargs: CommonYargsArgv) {
18
15
  return Name(d1ListYargs)
19
16
  .option("skip-confirmation", {
20
17
  describe: "Skip confirmation",
@@ -24,8 +21,8 @@ export function Options(d1ListYargs: Argv): Argv<CreateArgs> {
24
21
  })
25
22
  .epilogue(d1BetaWarning);
26
23
  }
27
-
28
- export const Handler = withConfig<CreateArgs>(
24
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof Options>;
25
+ export const Handler = withConfig<HandlerOptions>(
29
26
  async ({ name, skipConfirmation, config }): Promise<void> => {
30
27
  const accountId = await requireAuth({});
31
28
  logger.log(d1BetaWarning);