miniflare 0.0.0-e3efd68e3 → 0.0.0-e44afaf79

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 (48) hide show
  1. package/README.md +34 -8
  2. package/dist/src/index.d.ts +2442 -352
  3. package/dist/src/index.js +15435 -9874
  4. package/dist/src/index.js.map +3 -3
  5. package/dist/src/workers/analytics-engine/analytics-engine.worker.js +15 -0
  6. package/dist/src/workers/analytics-engine/analytics-engine.worker.js.map +6 -0
  7. package/dist/src/workers/assets/assets-kv.worker.js.map +1 -1
  8. package/dist/src/workers/assets/assets.worker.js +685 -286
  9. package/dist/src/workers/assets/assets.worker.js.map +2 -2
  10. package/dist/src/workers/assets/router.worker.js +33 -42
  11. package/dist/src/workers/assets/router.worker.js.map +2 -2
  12. package/dist/src/workers/assets/rpc-proxy.worker.js +7 -0
  13. package/dist/src/workers/assets/rpc-proxy.worker.js.map +1 -1
  14. package/dist/src/workers/cache/cache-entry.worker.js.map +1 -1
  15. package/dist/src/workers/cache/cache.worker.js +14 -25
  16. package/dist/src/workers/cache/cache.worker.js.map +1 -1
  17. package/dist/src/workers/core/entry.worker.js +3402 -108
  18. package/dist/src/workers/core/entry.worker.js.map +3 -3
  19. package/dist/src/workers/core/strip-cf-connecting-ip.worker.js +11 -0
  20. package/dist/src/workers/core/strip-cf-connecting-ip.worker.js.map +6 -0
  21. package/dist/src/workers/d1/database.worker.js +8 -6
  22. package/dist/src/workers/d1/database.worker.js.map +1 -1
  23. package/dist/src/workers/dispatch-namespace/dispatch-namespace.worker.js +25 -0
  24. package/dist/src/workers/dispatch-namespace/dispatch-namespace.worker.js.map +6 -0
  25. package/dist/src/workers/email/email.worker.js +23 -0
  26. package/dist/src/workers/email/email.worker.js.map +6 -0
  27. package/dist/src/workers/email/send_email.worker.js +3181 -0
  28. package/dist/src/workers/email/send_email.worker.js.map +6 -0
  29. package/dist/src/workers/kv/namespace.worker.js +69 -6
  30. package/dist/src/workers/kv/namespace.worker.js.map +2 -2
  31. package/dist/src/workers/kv/sites.worker.js +5 -7
  32. package/dist/src/workers/kv/sites.worker.js.map +1 -1
  33. package/dist/src/workers/queues/broker.worker.js +12 -17
  34. package/dist/src/workers/queues/broker.worker.js.map +1 -1
  35. package/dist/src/workers/r2/bucket.worker.js +23 -46
  36. package/dist/src/workers/r2/bucket.worker.js.map +1 -1
  37. package/dist/src/workers/ratelimit/ratelimit.worker.js.map +1 -1
  38. package/dist/src/workers/secrets-store/secret.worker.js +65 -0
  39. package/dist/src/workers/secrets-store/secret.worker.js.map +6 -0
  40. package/dist/src/workers/shared/index.worker.js +24 -50
  41. package/dist/src/workers/shared/index.worker.js.map +1 -1
  42. package/dist/src/workers/shared/mixed-mode-client.worker.js +18 -0
  43. package/dist/src/workers/shared/mixed-mode-client.worker.js.map +6 -0
  44. package/dist/src/workers/shared/zod.worker.js +80 -84
  45. package/dist/src/workers/shared/zod.worker.js.map +1 -1
  46. package/dist/src/workers/workflows/binding.worker.js +275 -139
  47. package/dist/src/workers/workflows/binding.worker.js.map +1 -1
  48. package/package.json +20 -13
package/README.md CHANGED
@@ -107,11 +107,13 @@ modules.
107
107
 
108
108
  Represents where data should be persisted, if anywhere.
109
109
 
110
- - If this is `undefined` or `false`, data will be stored in-memory and only
110
+ - If this is `undefined`, it defaults to `true` if `defaultPersistRoot` is set
111
+ or otherwise defaults to `false`.
112
+ - If this is`false`, data will be stored in-memory and only
111
113
  persist between `Miniflare#setOptions()` calls, not restarts nor
112
114
  `new Miniflare` instances.
113
- - If this is `true`, data will be stored on the file-system, in the `$PWD/.mf`
114
- directory.
115
+ - If this is `true`, data will be stored in a subdirectory of the `defaultPersistRoot` path if `defaultPersistRoot` is set
116
+ or otherwise will be stored in a subdirectory of `$PWD/.mf`.
115
117
  - If this looks like a URL, then:
116
118
  - If the protocol is `memory:`, data will be stored in-memory as above.
117
119
  - If the protocol is `file:`, data will be stored on the file-system, in the
@@ -326,7 +328,7 @@ parameter in module format Workers.
326
328
  Record mapping binding name to paths containing arbitrary binary data to
327
329
  inject as `ArrayBuffer` bindings into this Worker.
328
330
 
329
- - `serviceBindings?: Record<string, string | typeof kCurrentWorker | { name: string | typeof kCurrentWorker, entrypoint?: string } | { network: Network } | { external: ExternalServer } | { disk: DiskDirectory } | (request: Request, instance: Miniflare) => Awaitable<Response>>`
331
+ - `serviceBindings?: Record<string, string | typeof kCurrentWorker | { name: string | typeof kCurrentWorker, entrypoint?: string } | { network: Network } | { external: ExternalServer } | { disk: DiskDirectory } | { node: (req: http.IncomingMessage, res: http.ServerResponse, miniflare: Miniflare) => Awaitable<void> } | (request: Request, miniflare: Miniflare) => Awaitable<Response>>`
330
332
 
331
333
  Record mapping binding name to service designators to inject as
332
334
  `{ fetch: typeof fetch }`
@@ -356,9 +358,10 @@ parameter in module format Workers.
356
358
  [`workerd` `DiskDirectory` struct](https://github.com/cloudflare/workerd/blob/bdbd6075c7c53948050c52d22f2dfa37bf376253/src/workerd/server/workerd.capnp#L600-L643),
357
359
  requests will be dispatched to an HTTP service backed by an on-disk
358
360
  directory.
359
- - If the designator is a function, requests will be dispatched to your custom
360
- handler. This allows you to access data and functions defined in Node.js
361
- from your Worker. Note `instance` will be the `Miniflare` instance
361
+ - If the designator is an object of the form `{ node: (req: http.IncomingMessage, res: http.ServerResponse, miniflare: Miniflare) => Awaitable<void> }`, requests will be dispatched to your custom Node handler. This allows you to access data and functions defined in Node.js from your Worker using Node.js `req` and `res` objects. Note, `miniflare` will be the `Miniflare` instance dispatching the request.
362
+ - If the designator is a function with the signature `(request: Request, miniflare: Miniflare) => Response`, requests will be dispatched to your custom
363
+ fetch handler. This allows you to access data and functions defined in Node.js
364
+ from your Worker using fetch `Request` and `Response` objects. Note, `miniflare` will be the `Miniflare` instance
362
365
  dispatching the request.
363
366
 
364
367
  <!--prettier-ignore-start-->
@@ -469,7 +472,7 @@ parameter in module format Workers.
469
472
 
470
473
  <!--prettier-ignore-end-->
471
474
 
472
- - `outboundService?: string | { network: Network } | { external: ExternalServer } | { disk: DiskDirectory } | (request: Request) => Awaitable<Response>`
475
+ - `outboundService?: string | { network: Network } | { external: ExternalServer } | { disk: DiskDirectory } | { node: (req: http.IncomingMessage, res: http.ServerResponse, miniflare: Miniflare) => Awaitable<void> } | (request: Request, miniflare: Miniflare) => Awaitable<Response>`
473
476
 
474
477
  Dispatch this Worker's global `fetch()` and `connect()` requests to the
475
478
  configured service. Service designators follow the same rules above for
@@ -490,6 +493,29 @@ parameter in module format Workers.
490
493
  as deployed Workers. If no routes match, Miniflare will fallback to the Worker
491
494
  defined first.
492
495
 
496
+ - `defaultPersistRoot?: string`
497
+
498
+ Specifies the default directory where Miniflare will write persisted data when persistence is enabled.
499
+
500
+ ```js
501
+ // Without `defaultPersistRoot`
502
+ new Miniflare({
503
+ kvPersist: undefined, // → "/(tmp)/kv"
504
+ d1Persist: true, // → "$PWD/.mf/d1"
505
+ r2Persist: false, // → "/(tmp)/r2"
506
+ cachePersist: "/my-cache", // → "/my-cache"
507
+ });
508
+
509
+ // With `defaultPersistRoot`
510
+ new Miniflare({
511
+ defaultPersistRoot: "/storage",
512
+ kvPersist: undefined, // → "/storage/kv"
513
+ d1Persist: true, // → "/storage/d1"
514
+ r2Persist: false, // → "/(tmp)/r2"
515
+ cachePersist: "/my-cache", // → "/my-cache"
516
+ });
517
+ ```
518
+
493
519
  #### Cache
494
520
 
495
521
  - `cache?: boolean`