Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(supabase): update to v2 #185

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/supabase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
},
"homepage": "https://github.com/grammyjs/storages/tree/main/packages/supabase#readme",
"devDependencies": {
"@supabase/supabase-js": "^1.24.0"
"@supabase/supabase-js": "^2.26.0"
},
"peerDependencies": {
"@supabase/supabase-js": "^1.0.0"
"@supabase/supabase-js": "^2.26.0"
},
"keywords": [
"grammy",
Expand Down
2 changes: 1 addition & 1 deletion packages/supabase/src/deps.deno.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { SupabaseClient } from 'https://deno.land/x/supabase/mod.ts';
export { SupabaseClient } from 'https://esm.sh/@supabase/[email protected]';
20 changes: 12 additions & 8 deletions packages/supabase/src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { SupabaseClient } from './deps.deno.ts';

interface Session {
id: string;
session: string;
type Opts = {
supabase: SupabaseClient,
table: string
}

export function supabaseAdapter<T>({ supabase, table }: { supabase: SupabaseClient; table: string }) {
export function supabaseAdapter<T>({ supabase, table }: Opts) {
if (!supabase) {
throw new Error('Kindly pass an instance of supabase client to the parameter list.');
}
Expand All @@ -16,9 +16,13 @@ export function supabaseAdapter<T>({ supabase, table }: { supabase: SupabaseClie

return {
read: async (id: string) => {
const { data, error } = await supabase.from<Session>(table).select('session').eq('id', id).single();
const { data, error } = await supabase.from(table).select('session').eq('id', id).limit(1).throwOnError().single();
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the updates. But looks like there's bug with throwOnError so i think we don't need it here, see this and this.

Suggested change
const { data, error } = await supabase.from(table).select('session').eq('id', id).limit(1).throwOnError().single();
const { data, error } = await supabase.from(table).select('session').eq('id', id).limit(1).single();


if (error || !data) {
if (error) {
throw error;
}

if (!data) {
return undefined;
}

Expand All @@ -27,10 +31,10 @@ export function supabaseAdapter<T>({ supabase, table }: { supabase: SupabaseClie
write: async (id: string, value: T) => {
const input = { id, session: JSON.stringify(value) };

await supabase.from<Session>(table).upsert(input, { returning: 'minimal' });
await supabase.from(table).upsert(input);
},
delete: async (id: string) => {
await supabase.from<Session>(table).delete({ returning: 'minimal' }).match({ id });
await supabase.from(table).delete().match({ id });
},
};
}
Loading