wrangler 2.1.6 → 2.1.8

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 (52) hide show
  1. package/miniflare-dist/index.mjs +5 -20
  2. package/package.json +14 -3
  3. package/src/__tests__/api-dev.test.ts +20 -0
  4. package/src/__tests__/configuration.test.ts +125 -22
  5. package/src/__tests__/dev.test.tsx +0 -2
  6. package/src/__tests__/helpers/mock-oauth-flow.ts +4 -2
  7. package/src/__tests__/index.test.ts +2 -0
  8. package/src/__tests__/paths.test.ts +23 -1
  9. package/src/__tests__/publish.test.ts +8 -10
  10. package/src/__tests__/user.test.ts +4 -4
  11. package/src/__tests__/whoami.test.tsx +0 -1
  12. package/src/__tests__/worker-namespace.test.ts +102 -112
  13. package/src/api/dev.ts +12 -12
  14. package/src/bundle.ts +59 -1
  15. package/src/cfetch/internal.ts +37 -21
  16. package/src/config/environment.ts +20 -0
  17. package/src/config/index.ts +32 -0
  18. package/src/config/validation.ts +59 -0
  19. package/src/config-cache.ts +1 -1
  20. package/src/create-worker-upload-form.ts +9 -0
  21. package/src/d1/backups.tsx +212 -0
  22. package/src/d1/create.tsx +54 -0
  23. package/src/d1/delete.tsx +56 -0
  24. package/src/d1/execute.tsx +294 -0
  25. package/src/d1/formatTimeAgo.ts +14 -0
  26. package/src/d1/index.ts +75 -0
  27. package/src/d1/list.tsx +48 -0
  28. package/src/d1/options.ts +12 -0
  29. package/src/d1/types.tsx +14 -0
  30. package/src/d1/utils.ts +39 -0
  31. package/src/dev/dev.tsx +30 -3
  32. package/src/dev/get-local-persistence-path.tsx +31 -0
  33. package/src/dev/local.tsx +73 -11
  34. package/src/dev/start-server.ts +6 -3
  35. package/src/dev/use-esbuild.ts +12 -1
  36. package/src/dev.tsx +48 -29
  37. package/src/dialogs.tsx +4 -0
  38. package/src/environment-variables.ts +17 -2
  39. package/src/index.tsx +18 -16
  40. package/src/logger.ts +11 -4
  41. package/src/miniflare-cli/index.ts +11 -16
  42. package/src/pages/dev.tsx +13 -9
  43. package/src/paths.ts +30 -4
  44. package/src/proxy.ts +21 -1
  45. package/src/publish.ts +7 -0
  46. package/src/user/user.tsx +1 -0
  47. package/src/worker.ts +30 -0
  48. package/templates/d1-beta-facade.js +174 -0
  49. package/templates/experimental-local-cache-stubs.js +27 -0
  50. package/wrangler-dist/cli.d.ts +438 -7
  51. package/wrangler-dist/cli.js +11679 -3911
  52. package/src/miniflare-cli/enum-keys.ts +0 -17
@@ -33,6 +33,47 @@ declare interface BodyMixin {
33
33
  readonly text: () => Promise<string>
34
34
  }
35
35
 
36
+ /**
37
+ * The possible types for a `Rule`.
38
+ */
39
+ declare type ConfigModuleRuleType = "ESModule" | "CommonJS" | "CompiledWasm" | "Text" | "Data";
40
+
41
+ declare type CustomDomainRoute = {
42
+ pattern: string;
43
+ custom_domain: boolean;
44
+ };
45
+
46
+ /**
47
+ * Deprecated upload configuration.
48
+ */
49
+ declare interface DeprecatedUpload {
50
+ /**
51
+ * The format of the Worker script.
52
+ *
53
+ * @deprecated We infer the format automatically now.
54
+ */
55
+ format?: "modules" | "service-worker";
56
+ /**
57
+ * The directory you wish to upload your worker from,
58
+ * relative to the wrangler.toml file.
59
+ *
60
+ * Defaults to the directory containing the wrangler.toml file.
61
+ *
62
+ * @deprecated
63
+ */
64
+ dir?: string;
65
+ /**
66
+ * The path to the Worker script, relative to `upload.dir`.
67
+ *
68
+ * @deprecated This will be replaced by a command line argument.
69
+ */
70
+ main?: string;
71
+ /**
72
+ * @deprecated This is now defined at the top level `rules` field.
73
+ */
74
+ rules?: Environment["rules"];
75
+ }
76
+
36
77
  declare interface DevApiOptions {
37
78
  testMode?: boolean;
38
79
  disableExperimentalWarning?: boolean;
@@ -43,7 +84,7 @@ declare interface DevOptions {
43
84
  env?: string;
44
85
  ip?: string;
45
86
  port?: number;
46
- noBundle?: boolean;
87
+ bundle?: boolean;
47
88
  inspectorPort?: number;
48
89
  localProtocol?: "http" | "https";
49
90
  assets?: string;
@@ -76,8 +117,9 @@ declare interface DevOptions {
76
117
  bucket_name: string;
77
118
  preview_bucket_name?: string;
78
119
  }[];
120
+ d1Databases?: Environment["d1_databases"];
79
121
  showInteractiveDevSession?: boolean;
80
- logLevel?: "none" | "error" | "log" | "warn" | "debug";
122
+ logLevel?: "none" | "info" | "error" | "log" | "warn" | "debug";
81
123
  logPrefix?: string;
82
124
  inspect?: boolean;
83
125
  forceLocal?: boolean;
@@ -92,6 +134,372 @@ declare interface EnablePagesAssetsServiceBindingOptions {
92
134
  directory?: string;
93
135
  }
94
136
 
137
+ /**
138
+ * The `Environment` interface declares all the configuration fields that
139
+ * can be specified for an environment.
140
+ *
141
+ * This could be the top-level default environment, or a specific named environment.
142
+ */
143
+ declare interface Environment extends EnvironmentInheritable, EnvironmentNonInheritable {
144
+ }
145
+
146
+ /**
147
+ * The `EnvironmentInheritable` interface declares all the configuration fields for an environment
148
+ * that can be inherited (and overridden) from the top-level environment.
149
+ */
150
+ declare interface EnvironmentInheritable {
151
+ /**
152
+ * The name of your worker. Alphanumeric + dashes only.
153
+ *
154
+ * @inheritable
155
+ */
156
+ name: string | undefined;
157
+ /**
158
+ * This is the ID of the account associated with your zone.
159
+ * You might have more than one account, so make sure to use
160
+ * the ID of the account associated with the zone/route you
161
+ * provide, if you provide one. It can also be specified through
162
+ * the CLOUDFLARE_ACCOUNT_ID environment variable.
163
+ *
164
+ * @inheritable
165
+ */
166
+ account_id: string | undefined;
167
+ /**
168
+ * A date in the form yyyy-mm-dd, which will be used to determine
169
+ * which version of the Workers runtime is used.
170
+ *
171
+ * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
172
+ *
173
+ * @inheritable
174
+ */
175
+ compatibility_date: string | undefined;
176
+ /**
177
+ * A list of flags that enable features from upcoming features of
178
+ * the Workers runtime, usually used together with compatibility_flags.
179
+ *
180
+ * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
181
+ *
182
+ * @inheritable
183
+ */
184
+ compatibility_flags: string[];
185
+ /**
186
+ * The entrypoint/path to the JavaScript file that will be executed.
187
+ */
188
+ main: string | undefined;
189
+ /**
190
+ * Whether we use <name>.<subdomain>.workers.dev to
191
+ * test and deploy your worker.
192
+ *
193
+ * @default `true` (This is a breaking change from wrangler 1)
194
+ * @breaking
195
+ * @inheritable
196
+ */
197
+ workers_dev: boolean | undefined;
198
+ /**
199
+ * A list of routes that your worker should be published to.
200
+ * Only one of `routes` or `route` is required.
201
+ *
202
+ * Only required when workers_dev is false, and there's no scheduled worker (see `triggers`)
203
+ *
204
+ * @inheritable
205
+ */
206
+ routes: Route[] | undefined;
207
+ /**
208
+ * A route that your worker should be published to. Literally
209
+ * the same as routes, but only one.
210
+ * Only one of `routes` or `route` is required.
211
+ *
212
+ * Only required when workers_dev is false, and there's no scheduled worker
213
+ *
214
+ * @inheritable
215
+ */
216
+ route: Route | undefined;
217
+ /**
218
+ * Path to a custom tsconfig
219
+ */
220
+ tsconfig: string | undefined;
221
+ /**
222
+ * The function to use to replace jsx syntax.
223
+ *
224
+ * @default `"React.createElement"`
225
+ * @inheritable
226
+ */
227
+ jsx_factory: string;
228
+ /**
229
+ * The function to use to replace jsx fragment syntax.
230
+ *
231
+ * @default `"React.Fragment"`
232
+ * @inheritable
233
+ */
234
+ jsx_fragment: string;
235
+ /**
236
+ * "Cron" definitions to trigger a worker's "scheduled" function.
237
+ *
238
+ * Lets you call workers periodically, much like a cron job.
239
+ *
240
+ * More details here https://developers.cloudflare.com/workers/platform/cron-triggers
241
+ *
242
+ * @default `{crons:[]}`
243
+ * @inheritable
244
+ */
245
+ triggers: {
246
+ crons: string[];
247
+ };
248
+ /**
249
+ * Specifies the Usage Model for your Worker. There are two options -
250
+ * [bundled](https://developers.cloudflare.com/workers/platform/limits#bundled-usage-model) and
251
+ * [unbound](https://developers.cloudflare.com/workers/platform/limits#unbound-usage-model).
252
+ * For newly created Workers, if the Usage Model is omitted
253
+ * it will be set to the [default Usage Model set on the account](https://dash.cloudflare.com/?account=workers/default-usage-model).
254
+ * For existing Workers, if the Usage Model is omitted, it will be
255
+ * set to the Usage Model configured in the dashboard for that Worker.
256
+ *
257
+ * @inheritable
258
+ */
259
+ usage_model: "bundled" | "unbound" | undefined;
260
+ /**
261
+ * An ordered list of rules that define which modules to import,
262
+ * and what type to import them as. You will need to specify rules
263
+ * to use Text, Data, and CompiledWasm modules, or when you wish to
264
+ * have a .js file be treated as an ESModule instead of CommonJS.
265
+ *
266
+ * @inheritable
267
+ */
268
+ rules: Rule[];
269
+ /**
270
+ * Configures a custom build step to be run by Wrangler when building your Worker.
271
+ *
272
+ * Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
273
+ * for more details.
274
+ *
275
+ * @default {}
276
+ */
277
+ build: {
278
+ /** The command used to build your Worker. On Linux and macOS, the command is executed in the `sh` shell and the `cmd` shell for Windows. The `&&` and `||` shell operators may be used. */
279
+ command?: string;
280
+ /** The directory in which the command is executed. */
281
+ cwd?: string;
282
+ /** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
283
+ watch_dir?: string | string[];
284
+ /**
285
+ * Deprecated field previously used to configure the build and upload of the script.
286
+ * @deprecated
287
+ */
288
+ upload?: DeprecatedUpload;
289
+ };
290
+ /**
291
+ * Skip internal build steps and directly publish script
292
+ * @inheritable
293
+ */
294
+ no_bundle: boolean | undefined;
295
+ /**
296
+ * Minify the script before uploading.
297
+ * @inheritable
298
+ */
299
+ minify: boolean | undefined;
300
+ /**
301
+ * Add polyfills for node builtin modules and globals
302
+ * @inheritable
303
+ */
304
+ node_compat: boolean | undefined;
305
+ /**
306
+ * Specifies namespace bindings that are bound to this Worker environment.
307
+ *
308
+ * NOTE: This field is not automatically inherited from the top level environment,
309
+ * and so must be specified in every named environment.
310
+ *
311
+ * @default `[]`
312
+ * @nonInheritable
313
+ */
314
+ dispatch_namespaces: {
315
+ /** The binding name used to refer to the bound service. */
316
+ binding: string;
317
+ /** The namespace to bind to. */
318
+ namespace: string;
319
+ }[];
320
+ /**
321
+ * Designates this worker as an internal-only "first-party" worker.
322
+ */
323
+ first_party_worker: boolean | undefined;
324
+ /**
325
+ * TODO: remove this as it has been deprecated.
326
+ *
327
+ * This is just here for now because the `route` commands use it.
328
+ * So we need to include it in this type so it is available.
329
+ */
330
+ zone_id?: string;
331
+ /**
332
+ * Specify a compiled capnp schema to use
333
+ * Then add a binding per field in the top level message that you will send to logfwdr
334
+ *
335
+ * @default `{schema:undefined,bindings:[]}`
336
+ * @inheritable
337
+ */
338
+ logfwdr: {
339
+ /** capnp schema filename */
340
+ schema: string | undefined;
341
+ bindings: {
342
+ /** The binding name used to refer to logfwdr */
343
+ name: string;
344
+ /** The destination for this logged message */
345
+ destination: string;
346
+ }[];
347
+ };
348
+ }
349
+
350
+ /**
351
+ * The `EnvironmentNonInheritable` interface declares all the configuration fields for an environment
352
+ * that cannot be inherited from the top-level environment, and must be defined specifically.
353
+ *
354
+ * If any of these fields are defined at the top-level then they should also be specifically defined
355
+ * for each named environment.
356
+ */
357
+ declare interface EnvironmentNonInheritable {
358
+ /**
359
+ * A map of values to substitute when deploying your worker.
360
+ *
361
+ * NOTE: This field is not automatically inherited from the top level environment,
362
+ * and so must be specified in every named environment.
363
+ *
364
+ * @default `{}`
365
+ * @nonInheritable
366
+ */
367
+ define: Record<string, string>;
368
+ /**
369
+ * A map of environment variables to set when deploying your worker.
370
+ *
371
+ * NOTE: This field is not automatically inherited from the top level environment,
372
+ * and so must be specified in every named environment.
373
+ *
374
+ * @default `{}`
375
+ * @nonInheritable
376
+ */
377
+ vars: {
378
+ [key: string]: unknown;
379
+ };
380
+ /**
381
+ * A list of durable objects that your worker should be bound to.
382
+ *
383
+ * For more information about Durable Objects, see the documentation at
384
+ * https://developers.cloudflare.com/workers/learning/using-durable-objects
385
+ *
386
+ * NOTE: This field is not automatically inherited from the top level environment,
387
+ * and so must be specified in every named environment.
388
+ *
389
+ * @default `{bindings:[]}`
390
+ * @nonInheritable
391
+ */
392
+ durable_objects: {
393
+ bindings: {
394
+ /** The name of the binding used to refer to the Durable Object */
395
+ name: string;
396
+ /** The exported class name of the Durable Object */
397
+ class_name: string;
398
+ /** The script where the Durable Object is defined (if it's external to this worker) */
399
+ script_name?: string;
400
+ /** The service environment of the script_name to bind to */
401
+ environment?: string;
402
+ }[];
403
+ };
404
+ /**
405
+ * These specify any Workers KV Namespaces you want to
406
+ * access from inside your Worker.
407
+ *
408
+ * To learn more about KV Namespaces,
409
+ * see the documentation at https://developers.cloudflare.com/workers/learning/how-kv-works
410
+ *
411
+ * NOTE: This field is not automatically inherited from the top level environment,
412
+ * and so must be specified in every named environment.
413
+ *
414
+ * @default `[]`
415
+ * @nonInheritable
416
+ */
417
+ kv_namespaces: {
418
+ /** The binding name used to refer to the KV Namespace */
419
+ binding: string;
420
+ /** The ID of the KV namespace */
421
+ id: string;
422
+ /** The ID of the KV namespace used during `wrangler dev` */
423
+ preview_id?: string;
424
+ }[];
425
+ /**
426
+ * Specifies R2 buckets that are bound to this Worker environment.
427
+ *
428
+ * NOTE: This field is not automatically inherited from the top level environment,
429
+ * and so must be specified in every named environment.
430
+ *
431
+ * @default `[]`
432
+ * @nonInheritable
433
+ */
434
+ r2_buckets: {
435
+ /** The binding name used to refer to the R2 bucket in the worker. */
436
+ binding: string;
437
+ /** The name of this R2 bucket at the edge. */
438
+ bucket_name: string;
439
+ /** The preview name of this R2 bucket at the edge. */
440
+ preview_bucket_name?: string;
441
+ }[];
442
+ /**
443
+ * Specifies D1 databases that are bound to this Worker environment.
444
+ *
445
+ * NOTE: This field is not automatically inherited from the top level environment,
446
+ * and so must be specified in every named environment.
447
+ *
448
+ * @default `[]`
449
+ * @nonInheritable
450
+ */
451
+ d1_databases: {
452
+ /** The binding name used to refer to the D1 database in the worker. */
453
+ binding: string;
454
+ /** The name of this D1 database. */
455
+ database_name: string;
456
+ /** The UUID of this D1 database (not required). */
457
+ database_id: string;
458
+ /** The UUID of this D1 database for Wrangler Dev (if specified). */
459
+ preview_database_id?: string;
460
+ }[];
461
+ /**
462
+ * Specifies service bindings (worker-to-worker) that are bound to this Worker environment.
463
+ *
464
+ * NOTE: This field is not automatically inherited from the top level environment,
465
+ * and so must be specified in every named environment.
466
+ *
467
+ * @default `[]`
468
+ * @nonInheritable
469
+ */
470
+ services: {
471
+ /** The binding name used to refer to the bound service. */
472
+ binding: string;
473
+ /** The name of the service. */
474
+ service: string;
475
+ /** The environment of the service (e.g. production, staging, etc). */
476
+ environment?: string;
477
+ }[] | undefined;
478
+ /**
479
+ * "Unsafe" tables for features that aren't directly supported by wrangler.
480
+ *
481
+ * NOTE: This field is not automatically inherited from the top level environment,
482
+ * and so must be specified in every named environment.
483
+ *
484
+ * @default `{ bindings: [] }`
485
+ * @nonInheritable
486
+ */
487
+ unsafe: {
488
+ /**
489
+ * A set of bindings that should be put into a Worker's upload metadata without changes. These
490
+ * can be used to implement bindings for features that haven't released and aren't supported
491
+ * directly by wrangler or miniflare.
492
+ *
493
+ * @default []
494
+ */
495
+ bindings: {
496
+ name: string;
497
+ type: string;
498
+ [key: string]: unknown;
499
+ }[];
500
+ };
501
+ }
502
+
95
503
  declare class File extends Blob_2 {
96
504
  /**
97
505
  * Creates a new File instance.
@@ -380,6 +788,19 @@ declare type ResponseType =
380
788
  | 'opaque'
381
789
  | 'opaqueredirect'
382
790
 
791
+ declare type Route = SimpleRoute | ZoneIdRoute | ZoneNameRoute | CustomDomainRoute;
792
+
793
+ /**
794
+ * A bundling resolver rule, defining the modules type for paths that match the specified globs.
795
+ */
796
+ declare type Rule = {
797
+ type: ConfigModuleRuleType;
798
+ globs: string[];
799
+ fallthrough?: boolean;
800
+ };
801
+
802
+ declare type SimpleRoute = string;
803
+
383
804
  declare interface SpecIterable<T> {
384
805
  [Symbol.iterator](): SpecIterator<T>;
385
806
  }
@@ -394,17 +815,27 @@ declare interface SpecIterator<T, TReturn = any, TNext = undefined> {
394
815
 
395
816
  /**
396
817
  * unstable_dev starts a wrangler dev server, and returns a promise that resolves with utility functions to interact with it.
397
- * @param {string} script
398
- * @param {DevOptions} options
399
- * @param {DevApiOptions} apiOptions
400
- * @returns {Promise<UnstableDev>}
401
818
  */
402
819
  export declare function unstable_dev(script: string, options?: DevOptions, apiOptions?: DevApiOptions): Promise<UnstableDevWorker>;
403
820
 
404
821
  export declare interface UnstableDevWorker {
822
+ port: number;
823
+ address: string;
405
824
  stop: () => Promise<void>;
406
- fetch: (input?: RequestInfo, init?: RequestInit) => Promise<Response | undefined>;
825
+ fetch: (input?: RequestInfo, init?: RequestInit) => Promise<Response>;
407
826
  waitUntilExit: () => Promise<void>;
408
827
  }
409
828
 
829
+ declare type ZoneIdRoute = {
830
+ pattern: string;
831
+ zone_id: string;
832
+ custom_domain?: boolean;
833
+ };
834
+
835
+ declare type ZoneNameRoute = {
836
+ pattern: string;
837
+ zone_name: string;
838
+ custom_domain?: boolean;
839
+ };
840
+
410
841
  export { }