diff --git a/src/sync-plugins/supabase.ts b/src/sync-plugins/supabase.ts index 235da33b..377b93f0 100644 --- a/src/sync-plugins/supabase.ts +++ b/src/sync-plugins/supabase.ts @@ -87,13 +87,7 @@ interface SyncedSupabaseProps< supabase?: Client; collection: Collection; schema?: SchemaName; - select?: ( - query: PostgrestQueryBuilder< - SupabaseSchemaOf, - SupabaseTableOf[Collection], - Collection - >, - ) => PostgrestFilterBuilder, TRemote, TRemote[], Collection, []>; + select?: never; filter?: ( select: PostgrestFilterBuilder, TRemote, TRemote[], Collection, []>, params: SyncedGetParams, @@ -115,6 +109,23 @@ interface SyncedSupabaseProps< ) => PromiseLike> | Promise>>; } +interface SyncedSupabasePropsWithSelect< + Client extends SupabaseClient, + Collection extends SupabaseCollectionOf, + SchemaName extends SchemaNameOf = 'public', + TOption extends CrudAsOption = 'object', + TRemote extends SupabaseRowOf = SupabaseRowOf, + TLocal = TRemote, +> extends Omit, 'select'> { + select: ( + query: PostgrestQueryBuilder< + SupabaseSchemaOf, + SupabaseTableOf[Collection], + Collection + >, + ) => PostgrestFilterBuilder, TRemote, TRemote[], Collection, []>; +} + let channelNum = 1; const supabaseConfig: SyncedSupabaseConfiguration = {}; const isEnabled$ = observable(true); @@ -146,6 +157,16 @@ function wrapSupabaseFn(fn: (...args: any) => PromiseLike, source: CrudErro }; } +export function syncedSupabase< + Client extends SupabaseClient, + Collection extends SupabaseCollectionOf & string, + SchemaName extends SchemaNameOf = 'public', + AsOption extends CrudAsOption = 'object', + TRemote = SupabaseRowOf, + TLocal = TRemote, +>( + props: SyncedSupabasePropsWithSelect, +): SyncedCrudReturnType; export function syncedSupabase< Client extends SupabaseClient, Collection extends SupabaseCollectionOf & string, @@ -155,6 +176,18 @@ export function syncedSupabase< TLocal = TRemote, >( props: SyncedSupabaseProps, +): SyncedCrudReturnType; +export function syncedSupabase< + Client extends SupabaseClient, + Collection extends SupabaseCollectionOf & string, + SchemaName extends SchemaNameOf = 'public', + AsOption extends CrudAsOption = 'object', + TRemote extends SupabaseRowOf = SupabaseRowOf, + TLocal = TRemote, +>( + props: + | SyncedSupabaseProps + | SyncedSupabasePropsWithSelect, ): SyncedCrudReturnType { props = { ...supabaseConfig, ...props } as any; const {