browser-cache-async
Version:
The browser-cache-async package provides a highly customizable, asynchronous caching system for client-side data management. Leveraging the power of the browser's IndexedDB, it enables efficient storage and retrieval of API responses, significantly reduci
44 lines (43 loc) • 1.82 kB
TypeScript
import { IRecordID } from 'browser-keyval-stores';
import { ICacheIfFn, IStringValue, IProcessedQueryOptions, IQueryOptions, IWrappedData } from '../shared/types.js';
/**
* Given a StringValue or a number, returns the number of milliseconds before the data becomes
* stale.
* @param revalidate
* @returns number
* @throws
* - INVALID_REVALIDATE_VALUE: If the revalidate value is not a valid number or StringValue.
*/
declare const calculateRevalidateTime: (revalidate?: IStringValue | number) => number;
/**
* Validates and builds the query options object based on a partial one. It also calculates the
* revalidate time.
* @param options
* @returns IProcessedQueryOptions<T>
* @throws
* - INVALID_QUERY_FUNCTION: If the query function is not a function.
* - INVALID_REVALIDATE_VALUE: If the revalidate value is not a valid number or StringValue.
*/
declare const buildQueryOptions: <T>(options: IQueryOptions<T>) => IProcessedQueryOptions<T>;
/**
* Verifies if the data retrieved from the query can be cached based on the cacheIf function.
* @param id
* @param data
* @param cacheIf
* @returns Promise<boolean>
*/
declare const canQueryBeCached: <T>(id: IRecordID, data: T, cacheIf: ICacheIfFn<T> | boolean | undefined) => Promise<boolean>;
/**
* Wraps a given record with a timestamp indicating when it will become stale.
* @param data
* @param revalidate
* @returns IWrappedData<T>
*/
declare const wrapData: <T>(data: T, revalidate: number) => IWrappedData<T>;
/**
* Unwraps the data from the wrapped object. If the data is stale, it returns undefined.
* @param wrappedData
* @returns T | undefined
*/
declare const unwrapData: <T>(wrappedData: IWrappedData<T> | undefined) => T | undefined;
export { calculateRevalidateTime, buildQueryOptions, canQueryBeCached, wrapData, unwrapData, };