cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.58k stars 663 forks source link

🚀 Feature Request [getBindingsProxy]: add a convenient way to get hold of bindings of a specific types #4792

Open dario-piotrowicz opened 8 months ago

dario-piotrowicz commented 8 months ago

The getBindingsProxy utility (introduced in https://github.com/cloudflare/workers-sdk/pull/4523) should include as part of its return object some utility methods that allow users to get hold of specific type of binding proxies

Something along the line of

import { getBindingsProxy } from "wrangler";

const { getBindingsOfType } = await getBindingsProxy();

const kvs = getBindingsOfType('kv');
const d1s = getBindingsOfType('d1');

// ...

Or maybe the bindings could be already organized per-type as in:

import { getBindingsProxy } from "wrangler";

const { groupedBindings } = await getBindingsProxy();

const kvs = groupedBindings.kv;
const d1s = groupedBindings.d1;

// ...
dario-piotrowicz commented 8 months ago

cc. @alexanderniebuhr