Skip to content

Support Images binding in getPlatformProxy()#9954

Merged
penalosa merged 4 commits intomainfrom
penalosa/images-platform-proxy
Jul 15, 2025
Merged

Support Images binding in getPlatformProxy()#9954
penalosa merged 4 commits intomainfrom
penalosa/images-platform-proxy

Conversation

@penalosa
Copy link
Copy Markdown
Contributor

@penalosa penalosa commented Jul 14, 2025

Adds support for the Images binding in getPlatformProxy(). Images bindings are some of the most complex bindings from an API perspective, other than RPC. In particular, they expose a synchronous API that accepts ReadableStream arguments. Multiple synchronous APIs are chained together in a builder pattern (e.g. await env.IMAGES.input(stream).transform(...).output(...)) before the final .output() call is awaited. This breaks our assumptions around functions that accept ReadableStream arguments always being async, and so doesn't work without some special casing.

In future, this could be replaced with a client JSRPC implementation (using promise pipelining), but for now special casing the entire binding seems to work well.


  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bugfix
  • Wrangler V3 Backport

@penalosa penalosa requested a review from a team as a code owner July 14, 2025 15:57
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jul 14, 2025

🦋 Changeset detected

Latest commit: cb01dcb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
miniflare Patch
wrangler Patch
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jul 14, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@9954

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@9954

miniflare

npm i https://pkg.pr.new/miniflare@9954

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@9954

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@9954

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@9954

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@9954

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@9954

wrangler

npm i https://pkg.pr.new/wrangler@9954

commit: cb01dcb

Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting approach. Generally looks good. CI is busted right now though.

@github-actions
Copy link
Copy Markdown
Contributor

Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the v3-maintenance branch with your changes. Thank you for helping us keep Wrangler v3 supported!

Depending on your changes, running git rebase --onto v3-maintenance main penalosa/images-platform-proxy might be a good starting point.

Notes:

  • your PR branch should be named v3-backport-9954
  • add the skip-v3-pr label to the current PR to stop this workflow from failing

@penalosa penalosa force-pushed the penalosa/images-platform-proxy branch from 566b36d to 123b2c7 Compare July 15, 2025 09:23
await fetch("https://playground.devprod.cloudflare.dev/flares.png")
).body?.tee()!;

// @ts-expect-error The stream types aren't matching up properly?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// @ts-expect-error The stream types aren't matching up properly?
// @ts-expect-error `ReadableStream` between Node.js and Workers doesn't quite along (Property 'readAtLeast' is missing in type 'import("stream/web").ReadableStreamBYOBReader')

This method is non-standard

What happens if the IMAGE binding actually starts to use this?

Should we have some kind of transform/polyfill for getPlatformProxy()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be fine at runtime, because by the time the ReadableStream gets to the Images binding it'll be a Workers Readable Stream. I'm not quite sure how we should fix this from a typing perspective though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a wrapper around the env type? e.g. getPlatformProxy() currently returns Env as-is, maybe it should be ConvertToNodeTypes<Env> or something?

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Jul 15, 2025
Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>
@penalosa penalosa merged commit bf4c9ab into main Jul 15, 2025
30 checks passed
@penalosa penalosa deleted the penalosa/images-platform-proxy branch July 15, 2025 15:11
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants