baseflow-local-client
Version:
Official TypeScript/JavaScript client for BaseFlow Local - a local-first BaaS with SQLite database, authentication, file storage, and real-time features
161 lines • 4.37 kB
TypeScript
import { BaseFlowLocalClientOptions, QueryBuilder, AuthEvent, BaseFlowResponse, StorageUploadOptions, StorageFile } from './types';
/**
* The main client for interacting with a BaseFlow Local backend.
*
* @example
* ```ts
* const client = createClient({
* url: 'http://localhost:5555'
* });
*
* const { data, error } = await client.from('users').select('*');
* ```
*/
export declare class BaseFlowLocalClient {
/** The URL of the BaseFlow Local backend. */
private url;
/** Additional headers to send with each request. */
private headers;
/** The underlying fetch implementation. */
private fetch;
/** The authentication API. */
auth: AuthAPI;
/** The storage API. */
storage: StorageAPI;
/**
* Creates a new BaseFlowLocalClient instance.
*
* @param options The options for the client.
*/
constructor(options?: BaseFlowLocalClientOptions);
/**
* Creates a query builder for a specific table.
*
* @param table The name of the table to query.
* @returns A query builder for the specified table.
*/
from<T = any>(table: string): QueryBuilder<T>;
/**
* Makes a request to the BaseFlow Local backend.
*
* @param method The HTTP method to use.
* @param path The path to request.
* @param options Additional options for the request.
* @returns The response from the backend.
*/
request(method: string, path: string, options?: {
body?: any;
headers?: Record<string, string>;
params?: Record<string, any>;
}): Promise<BaseFlowResponse>;
/**
* Set authentication token
*/
setAuth(token: string | null): void;
/**
* Call a remote procedure/function
*/
rpc(functionName: string, params?: any): Promise<BaseFlowResponse<any>>;
/**
* Get current schema
*/
getSchema(): Promise<BaseFlowResponse<any>>;
/**
* List all tables
*/
listTables(): Promise<BaseFlowResponse<any>>;
}
/**
* Storage API for file operations
*/
declare class StorageAPI {
private client;
constructor(client: BaseFlowLocalClient);
/**
* Upload a file
*/
upload(file: File | Buffer | Blob, options?: StorageUploadOptions): Promise<BaseFlowResponse<StorageFile>>;
/**
* List files
*/
list(folder?: string): Promise<BaseFlowResponse<{
files: StorageFile[];
count: number;
}>>;
/**
* Get file URL
*/
getUrl(filePath: string): string;
/**
* Download file
*/
download(filePath: string): Promise<BaseFlowResponse<any>>;
/**
* Delete file
*/
delete(fileId: number): Promise<BaseFlowResponse<any>>;
}
/**
* Auth API for authentication operations
*/
declare class AuthAPI {
private client;
private authToken;
private user;
private listeners;
constructor(client: BaseFlowLocalClient);
/**
* Register a new user
*/
signUp(credentials: {
email: string;
password: string;
name?: string;
}): Promise<BaseFlowResponse<any>>;
/**
* Sign in with email and password
*/
signInWithPassword(credentials: {
email: string;
password: string;
}): Promise<BaseFlowResponse<any>>;
/**
* Sign out the current user
*/
signOut(): Promise<BaseFlowResponse<any>>;
/**
* Get the current user
*/
getUser(): Promise<BaseFlowResponse<any>>;
/**
* Get the current session
*/
getSession(): {
token: string | null;
user: any;
};
/**
* Set the auth token manually
*/
setSession(session: {
token: string;
user?: any;
}): void;
/**
* Listen to auth state changes
*/
onAuthStateChange(callback: (event: AuthEvent) => void): () => void;
/**
* Notify all listeners of auth events
*/
private notifyListeners;
register(email: string, password: string, name?: string): Promise<BaseFlowResponse<any>>;
login(email: string, password: string): Promise<BaseFlowResponse<any>>;
logout(): Promise<BaseFlowResponse<any>>;
}
/**
* Create a new BaseFlow Local client instance
*/
export declare function createClient(options?: BaseFlowLocalClientOptions): BaseFlowLocalClient;
export {};
//# sourceMappingURL=client.d.ts.map