@dill-pixel/storage-adapter-supabase
Version:
Supabase Storage Adapter
72 lines • 3.2 kB
TypeScript
import { SupabaseClient } from '@supabase/supabase-js';
import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types';
import { IApplication, IStorageAdapter, StorageAdapter } from 'dill-pixel';
type SaveMethod = 'insert' | 'update' | 'upsert';
type DeleteData = {
[key: string]: any;
};
interface ISupabaseAdapterOptions {
supabaseUrl?: string;
anonKey?: string;
debug?: boolean;
}
export interface ISupabaseAdapter<Database extends GenericSchema = any> extends IStorageAdapter<ISupabaseAdapterOptions, Database> {
client: SupabaseClient<Database>;
initialize(options: Partial<ISupabaseAdapterOptions>, _app: IApplication): void;
save(tableId: string, data: any, method?: SaveMethod): Promise<any>;
load<T = any>(tableId: string, selectors?: string[]): Promise<T>;
delete(tableId: string, data: DeleteData): Promise<any>;
}
/**
* A class representing a storage adapter that uses Supabase.
*/
export declare class SupabaseAdapter<Database extends GenericSchema = any> extends StorageAdapter<ISupabaseAdapterOptions, Database> implements ISupabaseAdapter<Database> {
private _options;
private _supabase;
/**
* Returns the Supabase client.
* @returns {SupabaseClient<Database>} The Supabase client.
*/
get client(): SupabaseClient<Database>;
private hello;
/**
* Initializes the adapter.
* @param {IApplication} _app The application that the adapter belongs to.
* @param {ISupabaseAdapterOptions} options The options to initialize the adapter with.
* @returns {void}
*/
initialize(options: Partial<ISupabaseAdapterOptions> | undefined, _app: IApplication): void;
/**
* Saves data to a specified table in the Supabase database.
* @param {string} tableId The table to save the data to.
* @param {any} data The data to save.
* @param {SaveMethod} method The method to use for saving the data.
* @returns {Promise<any>} The saved data.
*
* @example
* await this.app.supabase.save('scores', { username: 'relish', score: 50 })
*/
save(tableId: string, data: any, method?: SaveMethod): Promise<any>;
/**
* Loads data from a specified table in the Supabase database.
* @param {string} tableId The table from which to load the data.
* @param {string[]} selectors The columns to select. Default is '*'.
* @returns {PostgrestFilterBuilder<any, any, any>} PostgrestFilterBuilder // TODO
*
* @example
* await this.app.supabase.load('scores', ['score', 'username']).order('score', { ascending: false }).limit(5)
*/
load<TExpectedLoadResult = any>(tableId: string, selectors?: string[]): Promise<TExpectedLoadResult>;
/**
* Deletes data from a specified table in the Supabase database.
* @param {string} tableId The table from which to load the data.
* @param {DeleteData} data The data to delete.
* @returns {Promise<any>} The deleted data.
*
* @example
* await this.app.supabase.delete('scores', { username: 'relish', score: 50 })
*/
delete(tableId: string, data: DeleteData): Promise<any>;
}
export {};
//# sourceMappingURL=SupabaseAdapter.d.ts.map