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
207 lines • 5.37 kB
TypeScript
/**
* Defines the options for creating a BaseFlow Local client.
*/
export interface BaseFlowLocalClientOptions {
/**
* The URL of the local BaseFlow server.
* @default 'http://localhost:5555'
*/
url?: string;
/**
* Optional headers to send with every request.
*/
headers?: Record<string, string>;
/**
* Optional fetch implementation to use for requests.
*/
fetch?: typeof fetch;
/**
* Optional JWT token for authenticated requests.
*/
token?: string;
/**
* Optional API key for project authentication.
*/
apiKey?: string;
}
/**
* Defines the structure of a BaseFlow API response.
*/
export interface BaseFlowResponse<T = any> {
/**
* The data returned by the API.
*/
data: T | null;
/**
* The error returned by the API, if any.
*/
error: BaseFlowError | null;
/**
* The HTTP status code of the response.
*/
status?: number;
/**
* The HTTP status text of the response.
*/
statusText?: string;
}
/**
* Defines the structure of a BaseFlow API error.
*/
export interface BaseFlowError {
/**
* The error message.
*/
message: string;
/**
* The error code.
*/
code?: string;
/**
* Additional details about the error.
*/
details?: any;
}
/**
* Defines the options for a query.
*/
export interface QueryOptions {
/**
* The columns to select.
*/
select?: string;
/**
* The filter to apply.
*/
where?: string;
/**
* The order to sort the results by.
*/
order?: string;
/**
* The maximum number of results to return.
*/
limit?: number;
/**
* The number of results to skip.
*/
offset?: number;
}
/**
* Defines the interface for a query builder.
*/
export interface QueryBuilder<T = any> {
/**
* Starts a select query.
* @param columns The columns to select.
*/
select(columns?: string): LocalQueryBuilder<T>;
/**
* Starts an insert query.
* @param data The data to insert.
*/
insert(data: Partial<T> | Partial<T>[]): LocalBuilder<T>;
/**
* Starts an update query.
* @param data The data to update.
*/
update(data: Partial<T>): LocalFilterBuilder<T>;
/**
* Starts a delete query.
*/
delete(): LocalFilterBuilder<T>;
}
/**
* Defines the base interface for a builder, making it a "thenable".
*/
export interface LocalBuilder<T = any> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult1 = BaseFlowResponse<T>, TResult2 = never>(onfulfilled?: ((value: BaseFlowResponse<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
}
/**
* Defines the interface for a filter builder.
*/
export interface LocalFilterBuilder<T = any> extends LocalBuilder<T> {
eq(column: keyof T, value: any): LocalFilterBuilder<T>;
neq(column: keyof T, value: any): LocalFilterBuilder<T>;
gt(column: keyof T, value: any): LocalFilterBuilder<T>;
gte(column: keyof T, value: any): LocalFilterBuilder<T>;
lt(column: keyof T, value: any): LocalFilterBuilder<T>;
lte(column: keyof T, value: any): LocalFilterBuilder<T>;
like(column: keyof T, pattern: string): LocalFilterBuilder<T>;
ilike(column: keyof T, pattern: string): LocalFilterBuilder<T>;
is(column: keyof T, value: null | boolean): LocalFilterBuilder<T>;
in(column: keyof T, values: any[]): LocalFilterBuilder<T>;
match(query: Record<keyof T, any>): LocalFilterBuilder<T>;
filter(column: keyof T, operator: string, value: any): LocalFilterBuilder<T>;
}
/**
* Defines the interface for a query builder.
*/
export interface LocalQueryBuilder<T = any> extends LocalFilterBuilder<T> {
order(column: keyof T, options?: {
ascending?: boolean;
}): LocalQueryBuilder<T>;
limit(count: number): LocalQueryBuilder<T>;
offset(count: number): LocalQueryBuilder<T>;
range(from: number, to: number): LocalQueryBuilder<T>;
single(): LocalFilterBuilder<T>;
}
/**
* Auth event types
*/
export type AuthEvent = {
type: 'SIGNED_IN';
user: any;
} | {
type: 'SIGNED_OUT';
} | {
type: 'USER_UPDATED';
user: any;
};
/**
* Auth session interface
*/
export interface AuthSession {
token: string;
user: any;
}
/**
* Auth user interface
*/
export interface AuthUser {
id: number;
email: string;
name?: string;
created_at: string;
last_login?: string;
}
/**
* Storage upload options
*/
export interface StorageUploadOptions {
folder?: string;
isPublic?: boolean;
filename?: string;
}
/**
* Storage file metadata
*/
export interface StorageFile {
id: number;
filename: string;
originalName: string;
mimetype: string;
size: number;
path: string;
folder?: string;
isPublic: boolean;
publicUrl?: string;
uploadedAt: string;
}
//# sourceMappingURL=types.d.ts.map