supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
2.86k stars 220 forks source link

Deno / Deno Deploy compatibility #161

Closed jcs224 closed 1 year ago

jcs224 commented 3 years ago

Feature request

Is your feature request related to a problem? Please describe.

I tried importing a Skypack and jspm version of the supabase-js client library, without success. I can create issues for the problems if you want, but since no one has brought up Deno yet I thought I'd start with a feature request.

Also, it would be really cool to be able to use Supabase with the new Deno Deploy service, just announced a couple of weeks ago.

https://deno.com/deploy

Describe the solution you'd like

Compatibility and instructions on how to use Deno / Deno Deploy with Supabase.

Describe alternatives you've considered

Using Node, of course :p but Deno is really nice to use and seems ambitious and forward thinking, similar to Supabase.

Additional context

Add any other context or screenshots about the feature request here.

kiwicopple commented 3 years ago

it would be really cool to be able to use Supabase with the new Deno Deploy service

Nice one, thanks @jcs224. Did you attempt this one already? Where there any issues/errors?

jcs224 commented 3 years ago

@kiwicopple I didn't try it with Deno Deploy yet, just the regular Deno CLI. I will try it with Deno Deploy, I'm sure the issues will be similar. Deno Deploy only has a subset of the Deno CLI since it's meant to run in an idempotent serverless environment (at least that's my understanding).

The first show-stopper has to to with XMLHttpRequest, which isn't present in Deno, and seems like this would be addressed if #154 is fixed.

Once I tried a workaround to ignore the XMLHttpRequest keyword, I got an error from GoTrue saying that getItem is not defined, probably referring to localStorage which Deno also doesn't support. It looks like it's on Deno's roadmap, but it's not implemented yet.

jcs224 commented 3 years ago

As I look into it more, I might try just using the postgrest-js library instead of the whole Supabase client. The current supabase-js implementation seems more focused on the browser environment than the server one, understandably. Although Deno has quite a bit of browser-compatible APIs, it's not all quite there (and may never be?)

kiwicopple commented 3 years ago

Agreed 👍 . This will still be compatible with Supabase projects too (you can just append /rest/v1 to the URL). Thanks for looking into this @jcs224

jcs224 commented 3 years ago

So, just tried this with postgrest-js and ran into the same XMLHttpRequest issue as before, because of the cross-fetch dependency. Maybe I'll fork that dependency and see if I can finagle it into submission.

kiwicopple commented 3 years ago

If you manage to solve it in cross-fetch, you'd also solve the problem for Cloudflare workers and Vite, so that would be a huge contribution

jcs224 commented 3 years ago

A little bit of a shot in the dark (hard to test with Deno as Skypack and jspm aren't cooperating with my test packages), but I sent a PR to cross-fetch's dependency, whatwg-fetch, to see what happens.

abnemo commented 3 years ago

A little bit of a shot in the dark (hard to test with Deno as Skypack and jspm aren't cooperating with my test packages), but I sent a PR to cross-fetch's dependency, whatwg-fetch, to see what happens.

Hello =) Any news on PR? I'd really like to use supabase-js client in deno environment, but because of lack of XMLHttpRequest, it is not possible =(

jcs224 commented 3 years ago

@abnemo this is an upstream dependency that will likely need to be updated. You should add a comment or give an emoji on this issue, maybe it will help get the ball rolling: https://github.com/github/fetch/pull/956

salemalem commented 3 years ago

I would love to see a dedicated supabase package on Deno land.

mirus-ua commented 2 years ago

Tried to run supabase-js today via cdn.skypack.dev and still got XMLHttpRequest error at cross-fetch

jcs224 commented 2 years ago

Well, someone ported all the Supabase JS libraries to Deno!

I tried just running Skypack, esm.sh, and jspm versions of Supabase, still not working. But, maybe stuff from these ports can be merged in with Supabase proper somehow? @link-discord?

jcs224 commented 2 years ago

@salemalem :point_up:

link-discord commented 2 years ago

yeah I was crazy enough to go ahead and port everything. wasn't really that hard cuz the supabase packages itself only ever use 1 dependency

link-discord commented 2 years ago

What also helped porting is the fact they added websocket support to deno while I was porting the realtime lib

link-discord commented 2 years ago

Also none of the ports use external dependencies only native things built in deno just so you know

littledivy commented 2 years ago

The following works with esm.sh:

import "https://deno.land/x/xhr@0.1.2/mod.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js";

const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key');
console.log(supabase.supabaseUrl); // https://xyzcompany.subabase.co
andrew-pyle commented 2 years ago

While the Deno runtime does support LocalStorage, and the supabase-js package works there, the code will not run on the Deno Deploy service.

Deno Deploy doesn't support LocalStorage, even though the Deno runtime does. The linked proposal indicates thatLocalStorage won't ever be implemented, since it's synchronous.

That means the Deno port of supabase-js (https://deno.land/x/supabase@1.2.0/) doesn't work on Deno Deploy.

Anyone tried the Deno port of PostgREST (https://deno.land/x/postgrest) with Deno Deploy specifically?

salemalem commented 2 years ago

@andrew-pyle so we won't see Supabase + Deno combination? What's at least Supabase analog in Deno?

andrew-pyle commented 2 years ago

@salemalem My observations above are specifically about the Deno Deploy service.

The Deno port of supabase-js works fine with Deno on the command line.

salemalem commented 2 years ago

@salemalem My observations above are specifically about the Deno Deploy service.

The Deno port of supabase-js works fine with Deno on the command line.

Oh so it will work perfectly if I will host it on Digital Ocean, right?

andrew-pyle commented 2 years ago

Give it a try and let us know what happens. It should work as far as I can tell.

link-discord commented 2 years ago

I haven't updated the ports in a while but I will probably update them soon again

link-discord commented 2 years ago

I just updated all the deno ports to match the current code of the supabase js libs

soedirgo commented 1 year ago

The official recommendation is to use supabase-js via esm.sh (it wasn't working at the time this issue was created, but should work now).

The situation with LocalStorage on Deno is unfortunate (there's a similar issue on Node) - you might need to use the service_role key which bypasses RLS (make sure to harden your Function!) instead of signing in with Auth.

ije commented 1 year ago

esm.sh v112 will inject XHR polyfill for cross-fetch automatically now