react-indexeddb-kit
Version:
A TypeScript-based React IndexedDB wrapper with CRUD operations.
50 lines (49 loc) • 1.84 kB
TypeScript
import { ModelDefinition, QueryOptions } from "./types";
import { ReactIndexDBClient } from "./react-indexdb-client";
export declare class ReactIndexDBModel {
private dbClient;
private modelDef;
constructor(dbClient: ReactIndexDBClient, modelDef: ModelDefinition);
/**
* Ensure the database is connected before performing any operation.
*/
private ensureDatabase;
/**
* Create a new record in IndexedDB after validating the data.
* @param data - The record data to insert.
* @returns The inserted record ID.
*/
create(data: Record<string, any>): Promise<any>;
/**
* Update an existing record after validating the data.
* @param id - The ID of the record to update.
* @param data - The updated record data.
* @returns The updated record ID.
*/
update(id: any, data: Record<string, any>): Promise<any>;
/**
* Delete a record by ID.
* @param id - The ID of the record to delete.
* @returns A confirmation message.
*/
delete(id: any): Promise<any>;
/**
* Retrieve multiple records with optional query filters.
* @param options - Query options such as filters, pagination, sorting, etc.
* @returns An array of matching records.
*/
findMany(options?: QueryOptions): Promise<any>;
/**
* Find a single record by ID.
* @param id - The ID of the record to retrieve.
* @param options - Query options for selecting specific fields.
* @returns The found record or null.
*/
findUnique(id: any, options?: QueryOptions): Promise<any | null>;
/**
* Handles unknown errors and ensures they are transformed into a proper `ReactIndexDBError`.
* @param error - The caught error.
* @returns {ReactIndexDBError} - A formatted error.
*/
private handleError;
}