@signaldb/core
Version:
SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON in
33 lines (32 loc) • 2.26 kB
TypeScript
import type PersistenceAdapter from '../types/PersistenceAdapter';
/**
* Creates a function that executes two asynchronous functions sequentially.
* The first function is tried first, and if it resolves, its value is used.
* If the first function fails or a fallback is required, the second function is executed.
* An optional cache mechanism can store the result temporarily to improve performance.
* @template Arguments - The argument types for the promise functions.
* @template ReturnValue - The return value type of the promise functions.
* @param firstResolvingPromiseFunction - The primary promise-based function to execute.
* @param secondResolvingPromiseFunction - The secondary fallback promise-based function to execute.
* @param [options] - Optional configuration.
* @param [options.onResolve] - Callback executed when a promise resolves.
* @param [options.cacheTimeout] - Time (in ms) to cache the resolved result.
* @returns A function that executes the two promises as described.
*/
export declare function createTemporaryFallbackExecutor<Arguments extends Array<any>, ReturnValue>(firstResolvingPromiseFunction: (...args: Arguments) => Promise<ReturnValue>, secondResolvingPromiseFunction: (...args: Arguments) => Promise<ReturnValue>, options?: {
onResolve?: (returnValue: ReturnValue) => void;
cacheTimeout?: number;
}): (...args: Arguments) => Promise<ReturnValue>;
/**
* Combines two persistence adapters (fast and slow) into a single interface.
* The fast adapter is used for quick read and write operations, while the slow adapter
* ensures data persistence and durability. The adapters sync automatically on read and save operations.
* @template T - The type of the persisted data items.
* @template I - The type of the identifier for persisted data items.
* @param slowAdapter - The slow persistence adapter for long-term storage.
* @param fastAdapter - The fast persistence adapter for quick access.
* @returns A combined persistence adapter that manages synchronization between the two adapters.
*/
export default function combinePersistenceAdapters<T extends {
id: I;
} & Record<string, any>, I>(slowAdapter: PersistenceAdapter<T, I>, fastAdapter: PersistenceAdapter<T, I>): PersistenceAdapter<T, I>;