github cloudflare/miniflare v2.9.0
2.9.0

latest releases: v2.14.2, v3.20231025.0, v3.20231023.0...
20 months ago

Features

  • πŸ’Ύ Add support for D1. Closes issue #277, thanks @geelen for the PR. Docs coming soonβ„’... πŸ‘€

  • πŸšͺ Add getMiniflareDurableObjectState() and runWithMiniflareDurableObjectGates() functions to the Jest/Vitest environments. This allows you to construct and call instance methods of Durable Objects directly, without having to fetch through a stub. Closes issue #157, thanks @jorroll.

    // Durable Object class, would probably come from an import
    class Counter {
      constructor(state) {
        this.storage = state.storage;
      }
      async fetch() {
        const count = ((await this.storage.get("count")) ?? 0) + 1;
        void this.storage.put("count", count);
        return new Response(String(count));
      }
    }
    
    const env = getMiniflareBindings();
    // Use standard Durable Object bindings to generate IDs
    const id = env.COUNTER.newUniqueId();
    // Get DurableObjectState, and seed data
    const state = await getMiniflareDurableObjectState(id);
    await state.storage.put("count", 3);
    // Construct object directly
    const object = new Counter(state, env);
    // Call instance method directly, closing input gate,
    // and waiting for output gate to open
    const res = await runWithMiniflareDurableObjectGates(state, () =>
      object.fetch(new Request("http://localhost/"))
    );
    expect(await res.text()).toBe("4");
  • πŸ₯· Don't construct corresponding Durable Object instance when calling Miniflare#getDurableObjectStorage(). This allows you to seed data before your Durable Object's constructor is invoked. Closes issue #300, thanks @spigaz.

  • β˜‘οΈ Add support for WebSocket#readyState and WebSocket.READY_STATE_{CONNECTING,OPEN,CLOSING,CLOSED} constants. Note these constant names intentionally deviate from the spec to match the Workers runtime.

  • πŸ“œ Add persistent history to the REPL. This respects the MINIFLARE_REPL_HISTORY, MINIFLARE_REPL_HISTORY_SIZE, and MINIFLARE_REPL_MODE environment variables based on Node's.

  • πŸ’΅ Add support for Range, If-Modified-Since and If-None-Match headers on Requests to Cache#match. Closes issue #246.

Fixes

  • Don't wait for waitUntil Promises to resolve before opening WebSocket connections
  • Allow WebSockets to be close()d on receiving a close event. Closes issue #331, thanks @awthwathje.
  • Ensure calling WebSocket#close() before returning a WebSocket response sends the correct close code and reason.
  • Fix delivery of incoming WebSocket error events
  • Ensure only scheduled Durable Object alarms are flushed. Previously, flushing all alarms would attempt to execute the alarm handler of every constructed Durable Object instance, even if that instance hadn't scheduled an alarm, or didn't have an alarm handler.
  • Delay scheduled missed alarms. Previously, if Durable Object persistence was enabled, and an alarm should've executed when Miniflare wasn't running, Miniflare may have crashed on startup. Closes issue #359, thanks @AlCalzone.
  • Allow empty-chunk writes to IdentityTransformStream. Closes issue #374, thanks @cdloh.
  • Don't hang when fetching from Durable Objects with fake-timers installed. Closes issue #190, thanks @vlovich.
  • Match unimplemented Request/Response properties with the Workers runtime. Specifically, throw unimplemented errors when attempting to access Request#{context,mode,credentials,integrity,cache} and Response#{type,useFinalUrl}.
  • Discard Content-Length: NaN headers as a temporary workaround until cloudflare/kv-asset-handler#295 is released. Closes honojs/hono#520, thanks @Cherry.
  • Return byte streams when tee()ing byte streams to match the behaviour of the Workers runtime. Closes issues #317 and #375.
  • Throw TypeError when calling Fetcher#fetch with an illegal this to match the behaviour of the Workers runtime.

Don't miss a new miniflare release

NewReleases is sending notifications on new releases.