Skip to content

Commit

Permalink
Fix: missing type from SvelteKit and remix package (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks authored May 23, 2023
1 parent a128b9e commit 3bda304
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
19 changes: 13 additions & 6 deletions packages/remix/src/createSupabaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SupabaseClientOptionsWithoutAuth
} from '@supabase/auth-helpers-shared';
import { SupabaseClient } from '@supabase/supabase-js';
import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types';

/**
* ## Authenticated Supabase client
Expand Down Expand Up @@ -90,7 +91,10 @@ export function createBrowserClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>(
supabaseUrl: string,
supabaseKey: string,
Expand All @@ -101,14 +105,14 @@ export function createBrowserClient<
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
} = {}
): SupabaseClient<Database, SchemaName> {
): SupabaseClient<Database, SchemaName, Schema> {
if (!supabaseUrl || !supabaseKey) {
throw new Error(
'supabaseUrl and supabaseKey are required to create a Supabase client! Find these under `Settings` > `API` in your Supabase dashboard.'
);
}

return createSupabaseClient<Database, SchemaName>(supabaseUrl, supabaseKey, {
return createSupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
global: {
...options?.global,
Expand Down Expand Up @@ -159,7 +163,10 @@ export function createServerClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>(
supabaseUrl: string,
supabaseKey: string,
Expand All @@ -174,7 +181,7 @@ export function createServerClient<
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
}
): SupabaseClient<Database, SchemaName> {
): SupabaseClient<Database, SchemaName, Schema> {
if (!supabaseUrl || !supabaseKey) {
throw new Error(
'supabaseUrl and supabaseKey are required to create a Supabase client! Find these under `Settings` > `API` in your Supabase dashboard.'
Expand All @@ -187,7 +194,7 @@ export function createServerClient<
);
}

return createSupabaseClient<Database, SchemaName>(supabaseUrl, supabaseKey, {
return createSupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
global: {
...options?.global,
Expand Down
8 changes: 6 additions & 2 deletions packages/shared/src/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { createClient } from '@supabase/supabase-js';
import { SupabaseClientOptionsWithoutAuth } from './types';
import { isBrowser } from './utils';
import { StorageAdapter } from './cookieAuthStorageAdapter';
import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types';

export function createSupabaseClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>(
supabaseUrl: string,
supabaseKey: string,
Expand All @@ -20,7 +24,7 @@ export function createSupabaseClient<
) {
const bowser = isBrowser();

return createClient(supabaseUrl, supabaseKey, {
return createClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
auth: {
flowType: 'pkce',
Expand Down
12 changes: 8 additions & 4 deletions packages/sveltekit/src/supabaseLoadClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { Session, SupabaseClient } from '@supabase/supabase-js';
import { LoadEvent } from '@sveltejs/kit';
import { SvelteKitLoadAuthStorageAdapter } from './loadStorageAdapter';
import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types';

let cachedBrowserClient: SupabaseClient<any, string> | undefined;

Expand Down Expand Up @@ -52,7 +53,10 @@ export function createSupabaseLoadClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>({
supabaseUrl,
supabaseKey,
Expand All @@ -73,13 +77,13 @@ export function createSupabaseLoadClient<
serverSession: Session | null;
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
}): SupabaseClient<Database, SchemaName> {
}): SupabaseClient<Database, SchemaName, Schema> {
const browser = isBrowser();
if (browser && cachedBrowserClient) {
return cachedBrowserClient as SupabaseClient<Database, SchemaName>;
return cachedBrowserClient as SupabaseClient<Database, SchemaName, Schema>;
}

const client = createSupabaseClient<Database, SchemaName>(supabaseUrl, supabaseKey, {
const client = createSupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
global: {
fetch: event.fetch,
Expand Down
11 changes: 8 additions & 3 deletions packages/sveltekit/src/supabaseServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
} from '@supabase/auth-helpers-shared';
import { RequestEvent } from '@sveltejs/kit';
import { SvelteKitServerAuthStorageAdapter } from './serverStorageAdapter';
import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types';
import { SupabaseClient } from '@supabase/supabase-js';

/**
* ## Authenticated Supabase client
Expand Down Expand Up @@ -61,7 +63,10 @@ export function createSupabaseServerClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>({
supabaseUrl,
supabaseKey,
Expand All @@ -76,8 +81,8 @@ export function createSupabaseServerClient<
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
expiryMargin?: number;
}) {
const client = createSupabaseClient<Database, SchemaName>(supabaseUrl, supabaseKey, {
}): SupabaseClient<Database, SchemaName, Schema> {
const client = createSupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
global: {
...options?.global,
Expand Down

0 comments on commit 3bda304

Please sign in to comment.