Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Miniflare 3] ✨ Implement *magic* proxy and add back support for Miniflare#get*() methods #639

Merged
merged 14 commits into from
Aug 17, 2023

Commits on Aug 17, 2023

  1. Implement magic proxy

    This provides the foundations for adding back `Miniflare#get*()`
    methods. It implements a proxy system, that makes HTTP requests to
    `workerd` on property access/function calls. Synchronous access/calls
    are supported too.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    a447741 View commit details
    Browse the repository at this point in the history
  2. Implement Miniflare#getBindings()

    Adds back support for `Miniflare#getBindings()` from Miniflare 2.
    This function returns a copy of the `env` object passed to module
    workers in Node.js. This could be used with framework dev servers to
    populate their "platform" objects.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    102f449 View commit details
    Browse the repository at this point in the history
  3. Implement remaining Miniflare#get*() methods

    Adds back support for `Miniflare#getCaches()`, `getD1Database()`,
    `getDurableObjectNamespace()`, `getKVNamespace()`,
    `getQueueProducer()`, and `getR2Bucket()` from Miniflare 2. Tests
    will follow in future commits.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    a26adf9 View commit details
    Browse the repository at this point in the history
  4. Rewrite Cache tests to use proxy

    Cache tests previously used custom HTTP endpoints to put/match/delete
    cached data. With the new `Miniflare#getCaches()` function, we can
    simplify the tests to use the exact same Cache API as workers.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    9ca92da View commit details
    Browse the repository at this point in the history
  5. Rewrite D1 tests to use proxy

    D1 tests previously defined a `TestD1Database` stub that made calls
    to custom HTTP endpoints to perform operations. With the new
    `Miniflare#getD1Database()` function, we can simplify the unshimmed
    test using the wrapped binding. Note we still need to use
    `TestD1Database` for the shimmed tests, as the proxy will only give
    us a `Fetcher` binding.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    05691bd View commit details
    Browse the repository at this point in the history
  6. Add Durable Object tests for proxy

    Tests the synchronous Durable Object ID creation methods, and
    performing a WebSocket upgrade on a proxied Durable Object stub.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    28d9406 View commit details
    Browse the repository at this point in the history
  7. Rewrite R2 tests to use proxy

    R2 tests previously defined a bunch of `Test*` stubs that made
    requests to custom HTTP endpoints and used custom JSON replacers/
    revivers to encode R2 objects. With the new `Miniflare#getR2Bucket()`
    function, we can delete a lot of this code, and just use the proxy.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    b78c755 View commit details
    Browse the repository at this point in the history
  8. Add additional tests for proxy

    Adds a few more tests for proxy edge cases, like WebSocket upgrades
    with service bindings and calling with multiple stream/blob
    arguments.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    3e90c0c View commit details
    Browse the repository at this point in the history
  9. Run tests with --serial

    ...to try and improve test stability. This isn't ideal, but hopefully
    it should fix some of the flakiness we're seeing. We can investigate
    this further later.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    4ca1950 View commit details
    Browse the repository at this point in the history
  10. Assert bodies consumed

    This change throws an uncaught exception if we forget to consume a
    response body in a test. Unconsumed bodies may cause `undici` to hang
    or throw socket errors.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    df5e518 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    fb01b1a View commit details
    Browse the repository at this point in the history
  12. Bump undici to 5.22.1

    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    5455ed2 View commit details
    Browse the repository at this point in the history
  13. Automatically substitute Workers types for Node equivalents

    Declares a `ReplaceWorkersTypes` type instead of manually declaring
    types for each of the Workers APIs.
    mrbbot committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    38e067d View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    62c842e View commit details
    Browse the repository at this point in the history