diff --git a/packages/core/supabase-js/src/SupabaseClient.ts b/packages/core/supabase-js/src/SupabaseClient.ts index 0526ef3cd..6bc312122 100644 --- a/packages/core/supabase-js/src/SupabaseClient.ts +++ b/packages/core/supabase-js/src/SupabaseClient.ts @@ -1,27 +1,28 @@ +import type { AuthChangeEvent } from '@supabase/auth-js' import { FunctionsClient } from '@supabase/functions-js' -import { AuthChangeEvent } from '@supabase/auth-js' +import { PostgrestClient } from '@supabase/postgrest-js' import { - PostgrestClient, - PostgrestFilterBuilder, - PostgrestQueryBuilder, -} from '@supabase/postgrest-js' -import { - RealtimeChannel, - RealtimeChannelOptions, + type RealtimeChannel, + type RealtimeChannelOptions, RealtimeClient, - RealtimeClientOptions, + type RealtimeClientOptions, } from '@supabase/realtime-js' import { StorageClient as SupabaseStorageClient } from '@supabase/storage-js' import { - DEFAULT_GLOBAL_OPTIONS, - DEFAULT_DB_OPTIONS, DEFAULT_AUTH_OPTIONS, + DEFAULT_DB_OPTIONS, + DEFAULT_GLOBAL_OPTIONS, DEFAULT_REALTIME_OPTIONS, } from './lib/constants' import { fetchWithAuth } from './lib/fetch' import { applySettingDefaults, validateSupabaseUrl } from './lib/helpers' import { SupabaseAuthClient } from './lib/SupabaseAuthClient' -import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions } from './lib/types' +import type { + Fetch, + GenericSchema, + SupabaseAuthClientOptions, + SupabaseClientOptions, +} from './lib/types' /** * Supabase Client. @@ -178,20 +179,15 @@ export default class SupabaseClient< }) } - // NOTE: signatures must be kept in sync with PostgrestClient.from - from< - TableName extends string & keyof Schema['Tables'], - Table extends Schema['Tables'][TableName], - >(relation: TableName): PostgrestQueryBuilder - from( - relation: ViewName - ): PostgrestQueryBuilder /** * Perform a query on a table or a view. * * @param relation - The table or view name to query */ - from(relation: string): PostgrestQueryBuilder { + // @jsr-ignore slow-type-missing-explicit-return-type + from( + relation: RelationName + ) { return this.rest.from(relation) } @@ -203,15 +199,11 @@ export default class SupabaseClient< * * @param schema - The schema to query */ + // @jsr-ignore slow-type-missing-explicit-return-type schema>( schema: DynamicSchema - ): PostgrestClient< - Database, - ClientOptions, - DynamicSchema, - Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any - > { - return this.rest.schema(schema) + ) { + return this.rest.schema(schema) } // NOTE: signatures must be kept in sync with PostgrestClient.rpc @@ -238,27 +230,23 @@ export default class SupabaseClient< * `"estimated"`: Uses exact count for low numbers and planned count for high * numbers. */ - rpc( + // @jsr-ignore slow-type-missing-explicit-return-type + rpc< + FnName extends string & keyof Schema['Functions'], + Args extends Schema['Functions'][FnName]['Args'] = never, + >( fn: FnName, - args: Fn['Args'] = {}, + args: Args = {} as Args, options: { head?: boolean get?: boolean count?: 'exact' | 'planned' | 'estimated' - } = {} - ): PostgrestFilterBuilder< - ClientOptions, - Schema, - Fn['Returns'] extends any[] - ? Fn['Returns'][number] extends Record - ? Fn['Returns'][number] - : never - : never, - Fn['Returns'], - FnName, - null, - 'RPC' - > { + } = { + head: false, + get: false, + count: undefined, + } + ) { return this.rest.rpc(fn, args, options) } @@ -355,7 +343,7 @@ export default class SupabaseClient< } private _listenForAuthEvents() { - let data = this.auth.onAuthStateChange((event, session) => { + const data = this.auth.onAuthStateChange((event, session) => { this._handleTokenChanged(event, 'CLIENT', session?.access_token) }) return data @@ -374,7 +362,7 @@ export default class SupabaseClient< this.realtime.setAuth(token) } else if (event === 'SIGNED_OUT') { this.realtime.setAuth() - if (source == 'STORAGE') this.auth.signOut() + if (source === 'STORAGE') this.auth.signOut() this.changedAccessToken = undefined } }