miniflare 3.0.2 → 3.20230710.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.
package/README.md CHANGED
@@ -5,8 +5,7 @@
5
5
  [`workerd`](https://github.com/cloudflare/workerd).
6
6
 
7
7
  > :warning: Miniflare 3 is API-only, and does not expose a CLI. Use Wrangler
8
- > with `wrangler dev --experimental-local` to develop your Workers locally with
9
- > Miniflare 3.
8
+ > with `wrangler dev` to develop your Workers locally with Miniflare 3.
10
9
 
11
10
  ## Quick Start
12
11
 
@@ -173,6 +172,27 @@ level will be logged.
173
172
  Creates a new logger that logs nothing to the `console`, and always `throw`s
174
173
  `message`s logged at the `ERROR` level.
175
174
 
175
+ ### `interface QueueConsumerOptions`
176
+
177
+ - `maxBatchSize?: number`
178
+
179
+ Maximum number of messages allowed in each batch. Defaults to `5`.
180
+
181
+ - `maxBatchTimeout?: number`
182
+
183
+ Maximum number of seconds to wait for a full batch. If a message is sent, and
184
+ this timeout elapses, a partial batch will be dispatched. Defaults to `1`.
185
+
186
+ - `maxRetries?: number`
187
+
188
+ Maximum number of times to retry dispatching a message, if handling it throws,
189
+ or it is explicitly retried. Defaults to `2`.
190
+
191
+ - `deadLetterQueue?: string`
192
+
193
+ Name of another Queue to send a message on if it fails processing after
194
+ `maxRetries`. If this isn't specified, failed messages will be discarded.
195
+
176
196
  ### `interface WorkerOptions`
177
197
 
178
198
  Options for an individual Worker/"nanoservice". All bindings are accessible on
@@ -295,6 +315,13 @@ parameter in module format Workers.
295
315
  handler. This allows you to access data and functions defined in Node.js
296
316
  from your Worker.
297
317
 
318
+ - `routes?: string[]`
319
+
320
+ Array of route patterns for this Worker. These follow the same
321
+ [routing rules](https://developers.cloudflare.com/workers/platform/triggers/routes/#matching-behavior)
322
+ as deployed Workers. If no routes match, Miniflare will fallback to the Worker
323
+ defined first.
324
+
298
325
  #### Cache
299
326
 
300
327
  - `cache?: boolean`
@@ -366,7 +393,25 @@ parameter in module format Workers.
366
393
  ID with different binding names. If a `string[]` of binding names is
367
394
  specified, the binding name and database ID are assumed to be the same.
368
395
 
369
- #### Analytics Engine and Queues
396
+ #### Queues
397
+
398
+ > :warning: Queues are only supported with Node.js 18 or above.
399
+
400
+ - `queueProducers?: Record<string, string> | string[]`
401
+
402
+ Record mapping binding name to queue names to inject as `WorkerQueue` bindings
403
+ into this Worker. Different Workers may bind to the same queue name with
404
+ different binding names. If a `string[]` of binding names is specified, the
405
+ binding name and queue name are assumed to be the same.
406
+
407
+ - `queueConsumers?: Record<string, QueueConsumerOptions> | string[]`
408
+
409
+ Record mapping queue name to consumer options. Messages enqueued on the
410
+ corresponding queues will be dispatched to this Worker. Note each queue can
411
+ have at most one consumer. If a `string[]` of queue names is specified,
412
+ default consumer options will be used.
413
+
414
+ #### Analytics Engine
370
415
 
371
416
  _Not yet supported_
372
417
 
@@ -387,6 +432,45 @@ Options shared between all Workers/"nanoservices".
387
432
  specified port is in use, Miniflare throws an error, rather than attempting to
388
433
  find a free port.
389
434
 
435
+ - `https?: boolean`
436
+
437
+ If `true`, start an HTTPS server using a pre-generated self-signed certificate
438
+ for `localhost`. Note this certificate is not valid for any other hostnames or
439
+ IP addresses. If you need to access the HTTPS server from another device,
440
+ you'll need to generate your own certificate and use the other `https*`
441
+ options below.
442
+
443
+ ```shell
444
+ $ openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out cert.pem
445
+ ```
446
+
447
+ ```js
448
+ new Miniflare({
449
+ httpsKeyPath: "key.pem",
450
+ httpsCertPath: "cert.pem",
451
+ });
452
+ ```
453
+
454
+ - `httpsKey?: string`
455
+
456
+ When one of `httpsCert` or `httpCertPath` is also specified, starts an HTTPS
457
+ server using the value of this option as the PEM encoded private key.
458
+
459
+ - `httpsKeyPath?: string`
460
+
461
+ When one of `httpsCert` or `httpCertPath` is also specified, starts an HTTPS
462
+ server using the PEM encoded private key stored at this file path.
463
+
464
+ - `httpsCert?: string`
465
+
466
+ When one of `httpsKey` or `httpsKeyPath` is also specified, starts an HTTPS
467
+ server using the value of this option as the PEM encoded certificate chain.
468
+
469
+ - `httpsCertPath?: string`
470
+
471
+ When one of `httpsKey` or `httpsKeyPath` is also specified, starts an HTTPS
472
+ server using the PEM encoded certificate chain stored at this file path.
473
+
390
474
  - `inspectorPort?: number`
391
475
 
392
476
  Port that `workerd` should start a DevTools inspector server on. Visit
@@ -404,6 +488,13 @@ Options shared between all Workers/"nanoservices".
404
488
  Logger implementation for Miniflare's errors, warnings and informative
405
489
  messages.
406
490
 
491
+ - `upstream?: string`
492
+
493
+ URL to use as the origin for incoming requests. If specified, all incoming
494
+ `request.url`s will be rewritten to start with this string. This is especially
495
+ useful when testing Workers that act as a proxy, and not as origins
496
+ themselves.
497
+
407
498
  - `cf?: boolean | string | Record<string, any>`
408
499
 
409
500
  Controls the object returned from incoming `Request`'s `cf` property.
@@ -431,8 +522,7 @@ Options shared between all Workers/"nanoservices".
431
522
 
432
523
  - `durableObjectsPersist?: Persistence`
433
524
 
434
- _Not yet supported_, Miniflare will throw if this is truthy and Durable Object
435
- bindings are specified.
525
+ Where to persist data stored in Durable Objects. See docs for `Persistence`.
436
526
 
437
527
  - `kvPersist?: Persistence`
438
528
 
@@ -446,7 +536,7 @@ Options shared between all Workers/"nanoservices".
446
536
 
447
537
  Where to persist data stored in D1 databases. See docs for `Persistence`.
448
538
 
449
- #### Analytics Engine and Queues
539
+ #### Analytics Engine
450
540
 
451
541
  _Not yet supported_
452
542
 
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
 
3
3
  import type { Abortable } from 'events';
4
+ import { Agent } from 'undici';
4
5
  import { BodyInit } from 'undici';
5
6
  import { CacheGateway as CacheGateway_2 } from './cache';
6
7
  import { D1Gateway as D1Gateway_2 } from './d1';
@@ -51,11 +52,14 @@ import { compatibilityDate as supportedCompatibilityDate } from 'workerd';
51
52
  import { Timers as Timers_2 } from '../shared';
52
53
  import { TlsOptions_Version as TlsOptions_Version_2 } from '../../runtime';
53
54
  import { TlsOptions_Version as TlsOptions_Version_3 } from '../index';
55
+ import { Transform } from 'stream';
54
56
  import { TransformStream } from 'stream/web';
55
57
  import { URLSearchParams as URLSearchParams_2 } from 'url';
56
58
  import { WritableStream } from 'stream/web';
57
59
  import { z } from 'zod';
58
60
 
61
+ export declare const allowUnauthorizedAgent: Agent;
62
+
59
63
  export declare type Awaitable<T> = T | Promise<T>;
60
64
 
61
65
  export declare const BASE64_REGEXP: RegExp;
@@ -151,6 +155,8 @@ export declare interface Config {
151
155
  extension?: Extension[];
152
156
  }
153
157
 
158
+ export declare function configureEntrySocket(coreOpts: z.infer<typeof CORE_PLUGIN.sharedOptions>): Promise<Socket>;
159
+
154
160
  export declare const CORE_PLUGIN: Plugin<typeof CoreOptionsSchema, typeof CoreSharedOptionsSchema>;
155
161
 
156
162
  export declare const CORE_PLUGIN_NAME = "core";
@@ -414,9 +420,9 @@ export declare const CoreOptionsSchema: z.ZodIntersection<z.ZodUnion<[z.ZodObjec
414
420
  }, "strip", z.ZodTypeAny, {
415
421
  name?: string | undefined;
416
422
  compatibilityDate?: string | undefined;
417
- bindings?: Record<string, Json_2> | undefined;
418
423
  compatibilityFlags?: string[] | undefined;
419
424
  routes?: string[] | undefined;
425
+ bindings?: Record<string, Json_2> | undefined;
420
426
  wasmBindings?: Record<string, string> | undefined;
421
427
  textBlobBindings?: Record<string, string> | undefined;
422
428
  dataBlobBindings?: Record<string, string> | undefined;
@@ -448,9 +454,9 @@ export declare const CoreOptionsSchema: z.ZodIntersection<z.ZodUnion<[z.ZodObjec
448
454
  }, {
449
455
  name?: string | undefined;
450
456
  compatibilityDate?: string | undefined;
451
- bindings?: Record<string, Json_2> | undefined;
452
457
  compatibilityFlags?: string[] | undefined;
453
458
  routes?: string[] | undefined;
459
+ bindings?: Record<string, Json_2> | undefined;
454
460
  wasmBindings?: Record<string, string> | undefined;
455
461
  textBlobBindings?: Record<string, string> | undefined;
456
462
  dataBlobBindings?: Record<string, string> | undefined;
@@ -484,6 +490,11 @@ export declare const CoreOptionsSchema: z.ZodIntersection<z.ZodUnion<[z.ZodObjec
484
490
  export declare const CoreSharedOptionsSchema: z.ZodObject<{
485
491
  host: z.ZodOptional<z.ZodString>;
486
492
  port: z.ZodOptional<z.ZodNumber>;
493
+ https: z.ZodOptional<z.ZodBoolean>;
494
+ httpsKey: z.ZodOptional<z.ZodString>;
495
+ httpsKeyPath: z.ZodOptional<z.ZodString>;
496
+ httpsCert: z.ZodOptional<z.ZodString>;
497
+ httpsCertPath: z.ZodOptional<z.ZodString>;
487
498
  inspectorPort: z.ZodOptional<z.ZodNumber>;
488
499
  verbose: z.ZodOptional<z.ZodBoolean>;
489
500
  log: z.ZodOptional<z.ZodType<Log, z.ZodTypeDef, Log>>;
@@ -497,6 +508,11 @@ export declare const CoreSharedOptionsSchema: z.ZodObject<{
497
508
  cf?: string | boolean | Record<string, any> | undefined;
498
509
  inspectorPort?: number | undefined;
499
510
  verbose?: boolean | undefined;
511
+ https?: boolean | undefined;
512
+ httpsKey?: string | undefined;
513
+ httpsKeyPath?: string | undefined;
514
+ httpsCert?: string | undefined;
515
+ httpsCertPath?: string | undefined;
500
516
  log?: Log | undefined;
501
517
  timers?: Timers<unknown> | undefined;
502
518
  upstream?: string | undefined;
@@ -507,6 +523,11 @@ export declare const CoreSharedOptionsSchema: z.ZodObject<{
507
523
  cf?: string | boolean | Record<string, any> | undefined;
508
524
  inspectorPort?: number | undefined;
509
525
  verbose?: boolean | undefined;
526
+ https?: boolean | undefined;
527
+ httpsKey?: string | undefined;
528
+ httpsKeyPath?: string | undefined;
529
+ httpsCert?: string | undefined;
530
+ httpsCertPath?: string | undefined;
510
531
  log?: Log | undefined;
511
532
  timers?: Timers<unknown> | undefined;
512
533
  upstream?: string | undefined;
@@ -1228,7 +1249,7 @@ export declare type Plugin<Options extends z.ZodType, SharedOptions extends z.Zo
1228
1249
  router: RouterConstructor<Gateway>;
1229
1250
  });
1230
1251
 
1231
- export declare const PLUGIN_ENTRIES: ["kv" | "cache" | "core" | "do" | "d1" | "queues" | "r2", ValueOf<{
1252
+ export declare const PLUGIN_ENTRIES: ["core" | "kv" | "cache" | "do" | "d1" | "queues" | "r2", ValueOf<{
1232
1253
  core: Plugin_2<z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
1233
1254
  modules: z.ZodArray<z.ZodObject<{
1234
1255
  type: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>;
@@ -1468,9 +1489,9 @@ export declare const PLUGIN_ENTRIES: ["kv" | "cache" | "core" | "do" | "d1" | "q
1468
1489
  }, "strip", z.ZodTypeAny, {
1469
1490
  name?: string | undefined;
1470
1491
  compatibilityDate?: string | undefined;
1471
- bindings?: Record<string, Json_3> | undefined;
1472
1492
  compatibilityFlags?: string[] | undefined;
1473
1493
  routes?: string[] | undefined;
1494
+ bindings?: Record<string, Json_3> | undefined;
1474
1495
  wasmBindings?: Record<string, string> | undefined;
1475
1496
  textBlobBindings?: Record<string, string> | undefined;
1476
1497
  dataBlobBindings?: Record<string, string> | undefined;
@@ -1502,9 +1523,9 @@ export declare const PLUGIN_ENTRIES: ["kv" | "cache" | "core" | "do" | "d1" | "q
1502
1523
  }, {
1503
1524
  name?: string | undefined;
1504
1525
  compatibilityDate?: string | undefined;
1505
- bindings?: Record<string, Json_3> | undefined;
1506
1526
  compatibilityFlags?: string[] | undefined;
1507
1527
  routes?: string[] | undefined;
1528
+ bindings?: Record<string, Json_3> | undefined;
1508
1529
  wasmBindings?: Record<string, string> | undefined;
1509
1530
  textBlobBindings?: Record<string, string> | undefined;
1510
1531
  dataBlobBindings?: Record<string, string> | undefined;
@@ -1536,6 +1557,11 @@ export declare const PLUGIN_ENTRIES: ["kv" | "cache" | "core" | "do" | "d1" | "q
1536
1557
  }>>, z.ZodObject<{
1537
1558
  host: z.ZodOptional<z.ZodString>;
1538
1559
  port: z.ZodOptional<z.ZodNumber>;
1560
+ https: z.ZodOptional<z.ZodBoolean>;
1561
+ httpsKey: z.ZodOptional<z.ZodString>;
1562
+ httpsKeyPath: z.ZodOptional<z.ZodString>;
1563
+ httpsCert: z.ZodOptional<z.ZodString>;
1564
+ httpsCertPath: z.ZodOptional<z.ZodString>;
1539
1565
  inspectorPort: z.ZodOptional<z.ZodNumber>;
1540
1566
  verbose: z.ZodOptional<z.ZodBoolean>;
1541
1567
  log: z.ZodOptional<z.ZodType<Log_2, z.ZodTypeDef, Log_2>>;
@@ -1549,6 +1575,11 @@ export declare const PLUGIN_ENTRIES: ["kv" | "cache" | "core" | "do" | "d1" | "q
1549
1575
  cf?: string | boolean | Record<string, any> | undefined;
1550
1576
  inspectorPort?: number | undefined;
1551
1577
  verbose?: boolean | undefined;
1578
+ https?: boolean | undefined;
1579
+ httpsKey?: string | undefined;
1580
+ httpsKeyPath?: string | undefined;
1581
+ httpsCert?: string | undefined;
1582
+ httpsCertPath?: string | undefined;
1552
1583
  log?: Log_2 | undefined;
1553
1584
  timers?: Timers_2<unknown> | undefined;
1554
1585
  upstream?: string | undefined;
@@ -1559,6 +1590,11 @@ export declare const PLUGIN_ENTRIES: ["kv" | "cache" | "core" | "do" | "d1" | "q
1559
1590
  cf?: string | boolean | Record<string, any> | undefined;
1560
1591
  inspectorPort?: number | undefined;
1561
1592
  verbose?: boolean | undefined;
1593
+ https?: boolean | undefined;
1594
+ httpsKey?: string | undefined;
1595
+ httpsKeyPath?: string | undefined;
1596
+ httpsCert?: string | undefined;
1597
+ httpsCertPath?: string | undefined;
1562
1598
  log?: Log_2 | undefined;
1563
1599
  timers?: Timers_2<unknown> | undefined;
1564
1600
  upstream?: string | undefined;
@@ -1946,9 +1982,9 @@ export declare const PLUGINS: {
1946
1982
  }, "strip", z.ZodTypeAny, {
1947
1983
  name?: string | undefined;
1948
1984
  compatibilityDate?: string | undefined;
1949
- bindings?: Record<string, Json_3> | undefined;
1950
1985
  compatibilityFlags?: string[] | undefined;
1951
1986
  routes?: string[] | undefined;
1987
+ bindings?: Record<string, Json_3> | undefined;
1952
1988
  wasmBindings?: Record<string, string> | undefined;
1953
1989
  textBlobBindings?: Record<string, string> | undefined;
1954
1990
  dataBlobBindings?: Record<string, string> | undefined;
@@ -1980,9 +2016,9 @@ export declare const PLUGINS: {
1980
2016
  }, {
1981
2017
  name?: string | undefined;
1982
2018
  compatibilityDate?: string | undefined;
1983
- bindings?: Record<string, Json_3> | undefined;
1984
2019
  compatibilityFlags?: string[] | undefined;
1985
2020
  routes?: string[] | undefined;
2021
+ bindings?: Record<string, Json_3> | undefined;
1986
2022
  wasmBindings?: Record<string, string> | undefined;
1987
2023
  textBlobBindings?: Record<string, string> | undefined;
1988
2024
  dataBlobBindings?: Record<string, string> | undefined;
@@ -2014,6 +2050,11 @@ export declare const PLUGINS: {
2014
2050
  }>>, z.ZodObject<{
2015
2051
  host: z.ZodOptional<z.ZodString>;
2016
2052
  port: z.ZodOptional<z.ZodNumber>;
2053
+ https: z.ZodOptional<z.ZodBoolean>;
2054
+ httpsKey: z.ZodOptional<z.ZodString>;
2055
+ httpsKeyPath: z.ZodOptional<z.ZodString>;
2056
+ httpsCert: z.ZodOptional<z.ZodString>;
2057
+ httpsCertPath: z.ZodOptional<z.ZodString>;
2017
2058
  inspectorPort: z.ZodOptional<z.ZodNumber>;
2018
2059
  verbose: z.ZodOptional<z.ZodBoolean>;
2019
2060
  log: z.ZodOptional<z.ZodType<Log_2, z.ZodTypeDef, Log_2>>;
@@ -2027,6 +2068,11 @@ export declare const PLUGINS: {
2027
2068
  cf?: string | boolean | Record<string, any> | undefined;
2028
2069
  inspectorPort?: number | undefined;
2029
2070
  verbose?: boolean | undefined;
2071
+ https?: boolean | undefined;
2072
+ httpsKey?: string | undefined;
2073
+ httpsKeyPath?: string | undefined;
2074
+ httpsCert?: string | undefined;
2075
+ httpsCertPath?: string | undefined;
2030
2076
  log?: Log_2 | undefined;
2031
2077
  timers?: Timers_2<unknown> | undefined;
2032
2078
  upstream?: string | undefined;
@@ -2037,6 +2083,11 @@ export declare const PLUGINS: {
2037
2083
  cf?: string | boolean | Record<string, any> | undefined;
2038
2084
  inspectorPort?: number | undefined;
2039
2085
  verbose?: boolean | undefined;
2086
+ https?: boolean | undefined;
2087
+ httpsKey?: string | undefined;
2088
+ httpsKeyPath?: string | undefined;
2089
+ httpsCert?: string | undefined;
2090
+ httpsCertPath?: string | undefined;
2040
2091
  log?: Log_2 | undefined;
2041
2092
  timers?: Timers_2<unknown> | undefined;
2042
2093
  upstream?: string | undefined;
@@ -4410,6 +4461,8 @@ export declare enum TlsOptions_Version {
4410
4461
  TLS1DOT3 = 5
4411
4462
  }
4412
4463
 
4464
+ export declare function _transformsForContentEncoding(encoding?: string): Transform[];
4465
+
4413
4466
  export declare type TypedDatabase = Omit<Database, "prepare"> & {
4414
4467
  prepare<Params = unknown[], SingleResult = unknown>(source: string): Params extends any[] ? TypedStatement<Params, SingleResult> : TypedStatement<[Params], SingleResult>;
4415
4468
  };