@snap/camera-kit
Version:
Camera Kit Web
48 lines • 2.2 kB
TypeScript
import type { Persistence, ValidKey } from "./Persistence";
/**
* Specify a database name for this {@link IndexedDBPersistence} instance to use.
* This will be prefixed by `Snap.CameraKit`.
*
* A databaseVersion and objectStore may also be specified. Keep in mind the following limitations:
* - IndexedDBPersistence currently does nothing to migrate data between versions.
* - If two different IndexedDBPersistence instances use the same databaseName, they must also use the same objectStore.
* Otherwise a race condition will occur which prevents the creation of all but one objectStore per database.
*/
export interface IndexedDBPersistenceOptions {
databaseName: string;
databaseVersion?: number;
objectStore?: string;
}
/**
* A simple key/value persistence using an IndexedDB storage backend.
*
* See [Using IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB) for an
* introduction to how IndexedDB works, its APIs, and how to use it.
*
* Note: Currently there is no support for database upgrades. Each instance of this class uses a single IDBObjectStore
* object set at instantiation time, and there are no hooks for performing migrations between versions. This may be
* added in the future if such functionality is needed.
*/
export declare class IndexedDBPersistence<T> implements Persistence<T> {
size: number;
private db;
private readonly databaseName;
private readonly databaseVersion?;
private readonly objectStore;
/**
* Construct an {@link IndexedDBPersistence} instance corresponding to a given IndexedDB database version.
*
* Throws `ConstraintError` if the version number is invalid (e.g. NaN, or less than 1).
*/
constructor(options: IndexedDBPersistenceOptions);
retrieve(key: ValidKey): Promise<T | undefined>;
retrieveAll(): Promise<Array<[ValidKey, T]>>;
remove(key: ValidKey): Promise<void>;
removeAll(): Promise<T[]>;
store(value: T): Promise<ValidKey>;
store(key: ValidKey, value: T): Promise<ValidKey>;
private openDatabase;
private simpleTransaction;
private transaction;
}
//# sourceMappingURL=IndexedDBPersistence.d.ts.map