Giter Site home page Giter Site logo

chientrm / wrangler-proxy Goto Github PK

View Code? Open in Web Editor NEW
30.0 2.0 1.0 140 KB

Wrangler Proxy exposes Workers API to outside and integrate to your favorite frameworks. Compatible with DrizzleORM.

License: MIT License

TypeScript 97.41% JavaScript 2.59%
cloudflare d1 kv workers wrangler bindings cloudflare-kv cloudflare-r2 drizzle-orm fullstack

wrangler-proxy's People

Contributors

chientrm avatar jahir9991 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jahir9991

wrangler-proxy's Issues

Queue support

This looks great! Have struggled so much with this in my SvelteKit apps. Any plans to add support for

  • Durable objects
  • Queues
  • global vars like crypto and cache
  • websocket bindings

Main ones for me right now are Durable objects and Queues

HTTP API fallback, without wrangler

Hi,
I want to use CF and D1 for building a project using SvelteKit and its prerender feature.

Prerender is done at build time with vanilla node, not wrangler, so no bindings are available.
But HTTP requests are allowed and we can call APIs with HTTP.
I'll do this because the Query API is simple.
I also need D1 at runtime so I can use D1 bindings in this case.

But I wondering if this great wrangler-proxy project can perform API calls directly on the D1 HTTP endpoint, by providing in environment variables kind of CF_ACCOUNT_ID, CF_D1_DB_ID, CF_D1_DB_TOKEN.

For now, I just need simple query and I have no time to contribute but maybe one day.
Thx.

Trying to get fetch() working with image re-size

Goal is to re-size image and then upload to R2 - so the idea was to use the service binding fetch() to re-size an image so I can then upload it to R2 - but I wasn't exactly sure if it was implemented.

I see that fetch() is proxied, but I am getting Error: Method not implemented. when trying to call the fetch request with cf-image options.

Perhaps I am doing this incorrectly? Is there an example of this possibly?

Errors are wrapped

When I want to try catch errors I get errors like:

โ€Œ{"status":500,"statusText":"Internal Server Error","message":"{\"name\":\"Error\",\"message\":\"D1_ERROR: UNIQUE constraint failed: user.username\",\"stack\":\"Error: D1_ERROR: UNIQUE constraint failed: user.username\\n    at D1Database._sendOrThrow (cloudflare-internal:d1-api:66:19)\\n    at async D1Database.batch (cloudflare-internal:d1-api:35:22)\\n    at async o6.execute (file:///Users/shyim/Downloads/shopmon/.wrangler/tmp/dev-koxavv/worker.js:170:132)\\n    at async Object.fetch (file:///Users/shyim/Downloads/shopmon/.wrangler/tmp/dev-koxavv/worker.js:449:29)\\n    at async jsonError (file:///Users/shyim/Downloads/shopmon/.wrangler/tmp/dev-koxavv/worker.js:469:12)\"}"}

The real error is inside the message as JSON. Therefore such checks in libraries are not working:
https://github.com/lucia-auth/lucia/blob/main/packages/adapter-sqlite/src/drivers/d1.ts#L58-L64

KV: getWithMetadata: Method not implemented

Hi.
Just trying out this repo. It looks like that KV proxy isn't fully implemented

Error: Method not implemented.
    at v.getWithMetadata (file:///.../node_modules/wrangler-proxy/dist/index.js:1:9379)

R2 PUT is returning "null" even though its technically working

When I am running the proxy, the "PUT" command for R2 is not returning anything. It's returning null but on CF it returns an object.

const file = form.get('file');
const image = await locals.R2.put(`${fileName}.${ext}`, file);

if (!image) {
error(500, {
  title: 'Failed to upload image.',
  detail: 'Something went wrong when trying to save your save your image.'
});
}

This code fails because image is null, even though it gets properly uploaded via proxy bindings - but does not fail when hosted on CF.

About the future of `wrangler-proxy` since `[email protected]` and up exposes `getBindingsProxy`

Hello!

Since https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%403.24.0 it is now possible to do the following:

import { getBindingsProxy } from "wrangler";

const { bindings, dispose } = await getBindingsProxy();

try {
	const myKv = bindings.MY_KV;
	const kvValue = await myKv.get("my-kv-key");

	console.log(`KV Value = ${kvValue}`);
} finally {
	await dispose();
}

The PR is cloudflare/workers-sdk#4523

@chientrm Maybe you already know about this, I wanted to mention it, in my context I first used wrangler-proxy, to query D1, which worked great! And now switched to getBindingsProxy and it also works great! I like how it's an official feature now ๐Ÿ™Œ๐Ÿผ

So, I'm not sure what it means for this project here, if you see the need to continue or to recommend getBindingsProxy instead? Just curious about your thoughts.

D1 Query Bugs

OK not sure if this is a problem with the proxy, but when attempting to use DrizzleORM and do a findFirst() query I'm getting the following error:

image

The same table running a query with findMany() works fine.. Also getting similar errors on any queries that involve where clauses.. Is there some query translation problem?

Error in hook action

The example code
waitUntil(async () => {}, platform?.context);

has an error
Argument of type '() => Promise<void>' is not assignable to parameter of type 'Promise<any>'.ts(2345)

Perhaps it should be like this?
waitUntil((async () => {})(), platform?.context);

List operation in KV TBD?

Are there any plans to implement list operation for KV?

If not, I would be keen to help out in this open source repository.

R2 `PUT` operation not working

I've got the setup with a small Svelte project, and any attempt to use a PUT operation with R2 fails.

const r2 = event.platform?.env.TORCH_R2 ?? connectR2('R2_STORE');
if (!r2) throw new Error('Torch R2 binding not found');

await r2.put('newvalue', 'test'); <-- stack points here

Wrangler-proxy Console Error:

[wrangler:inf] POST /instruction 200 OK (2ms)
[wrangler:inf] POST /data 500 Internal Server Error (3ms)   

Svelte Console Error

Error: {"name":"TypeError","message":"Provided readable stream must have a known length (request/response body or readable half of FixedLengthStream)","stack":"TypeError: Provided readable stream must have a known length (request/response body or readable half of FixedLengthStream)"}
    at W (file:///C:/Users/XXX/development/svelte-test/node_modules/wrangler-proxy/dist/index.js:1:197)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async o.post (file:///C:/Users/XXX/development/svelte-test/node_modules/wrangler-proxy/dist/index.js:1:714)
    at async Module.init (C:\Users\XXX\development\svelte-test\src\lib\middleware\init.ts:29:3)
    at async Object.handle (C:\Users\XXX\development\svelte-test\src\hooks.server.ts:9:14)
    at async Module.respond (C:\Users\XXX\development\svelte-test\node_modules\@sveltejs\kit\src\runtime\server\respond.js:282:20)
    at async file:///C:/Users/XXX/development/svelte-test/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:502:22
j {
  host: 'http://127.0.0.1:8787',
  name: 'R2_STORE',
  metadata: {},
  data: null <-- null?
}

It looks like data is null, but I am passing a value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.