fauna / faunadb-js

Javascript driver for Fauna v4 (deprecated)
https://docs.fauna.com/fauna/v4/
Other
702 stars 73 forks source link

Cloudflare Workers and global fetch??? #548

Open danboyle8637 opened 3 years ago

danboyle8637 commented 3 years ago

I have been trying to figure out a way to make this...

https://github.com/fauna/faunadb-js#known-issues

Work with Typescript. But I'm confused.

Cloudlfare Workers do have a native fetch so I'm confused as to why the workaround is needed.

I can't find anything about them supporting AbortController.... but maybe we can set a timeout and skill the Fauna Request or the stream. Although if it's a stream would you not kill that manually???

Can you help explain how Fauna uses cross-fetch more?

Maybe there is a way around this. Cloudflare Workers did just release Workers Unbound with 30 seconds of "alive" time.. not sure what you realy call that.

Anyway I would really love to get this working with TS support but I am at a standstill at the moment.

github-actions[bot] commented 3 years ago

Internal ticket number is OSS-958

grempe commented 2 years ago

FYI The known issues section of the README that the OP referenced has apparently been removed in this commit by @parkhomenko :

https://github.com/fauna/faunadb-js/commit/6e386ec53bc4420424282a4cde38895b0d8a6e78

It's not clear if anything else other than the doc removal has changed.

dferber90 commented 2 years ago

AbortController and AbortSignal are both supported now. It seems this is why the docs were removed and I believe this issue can be closed now.

https://community.cloudflare.com/t/2021-9-24-workers-runtime-release-notes/308821

Only for reference, no longer needed This is how the workaround would have needed to be typed to work with TypeScript. But the workaround itself is no longer necessary now, so don't copy this into any new projects. You don't need to specify `fetch` anymore when creating a fauna client in a Cloudflare Worker. ```ts new faunadb.Client({ // ... fetch: ( url: RequestInfo, params?: RequestInit | undefined ): Promise => { let signal: RequestInit["signal"]; if (params) { signal = params.signal; delete params.signal; } const abortPromise = new Promise((resolve) => { if (signal) { // @ts-ignore signal.onabort = resolve; } }); return Promise.race([abortPromise, patchedFetch(url, params)]); }, }) ```