import { TransactionMode, Value, BridgeIDBCursorDirection, Key, KeyPath, BridgeIDBDatabaseInfo, } from "./util/types"; import BridgeIDBKeyRange from "./BridgeIDBKeyRange"; export interface ObjectStoreProperties { keyPath: KeyPath | null; autoIncrement: boolean; indexes: string[]; } export interface IndexProperties { keyPath: KeyPath; multiEntry: boolean; unique: boolean; } export interface Schema { databaseName: string; databaseVersion: number; objectStores: { [name: string]: ObjectStoreProperties }; indexes: { [name: string]: IndexProperties }; } export interface DatabaseConnection { connectionCookie: string; } export interface DatabaseTransaction { transactionCookie: string; } export enum ResultLevel { OnlyCount, OnlyKeys, Full, } export enum StoreLevel { NoOverwrite, AllowOverwrite, UpdateExisting, } export interface RecordGetRequest { direction: BridgeIDBCursorDirection; objectStoreName: string; indexName: string | undefined; /** * The range of keys to return. * If indexName is defined, the range refers to the index keys. * Otherwise it refers to the object store keys. */ range: BridgeIDBKeyRange | undefined; /** * Last cursor position in terms of the index key. * Can only be specified if indexName is defined and * lastObjectStorePosition is defined. * * Must either be undefined or within range. */ lastIndexPosition?: Key; /** * Last position in terms of the object store key. */ lastObjectStorePosition?: Key; /** * If specified, the index key of the results must be * greater or equal to advanceIndexKey. * * Only applicable if indexName is specified. */ advanceIndexKey?: Key; /** * If specified, the primary key of the results must be greater * or equal to advancePrimaryKey. */ advancePrimaryKey?: Key; /** * Maximum number of resuts to return. * If -1, return all available results */ limit: number; resultLevel: ResultLevel; } export interface RecordGetResponse { values: Value[] | undefined; indexKeys: Key[] | undefined; primaryKeys: Key[] | undefined; count: number; } export interface RecordStoreRequest { objectStoreName: string; value: Value; key: Key | undefined; storeLevel: StoreLevel; } export interface Backend { getDatabases(): Promise; connectDatabase(name: string): Promise; beginTransaction( conn: DatabaseConnection, objectStores: string[], mode: TransactionMode, ): Promise; enterVersionChange( conn: DatabaseConnection, newVersion: number, ): Promise; /** * Even though the standard interface for indexedDB doesn't require * the client to run deleteDatabase in a version transaction, there is * implicitly one running. */ deleteDatabase(btx: DatabaseTransaction, name: string): Promise; close(db: DatabaseConnection): Promise; getSchema(db: DatabaseConnection): Schema; renameIndex(btx: DatabaseTransaction, oldName: string, newName: string): void; deleteIndex(btx: DatabaseTransaction, indexName: string): void; rollback(btx: DatabaseTransaction): Promise; commit(btx: DatabaseTransaction): Promise; deleteObjectStore(btx: DatabaseTransaction, name: string): void; createObjectStore( btx: DatabaseTransaction, name: string, keyPath: string | string[] | null, autoIncrement: boolean, ): void; renameObjectStore( btx: DatabaseTransaction, oldName: string, newName: string, ): void; createIndex( btx: DatabaseTransaction, indexName: string, objectStoreName: string, keyPath: KeyPath, multiEntry: boolean, unique: boolean, ): void; deleteRecord( btx: DatabaseTransaction, objectStoreName: string, range: BridgeIDBKeyRange, ): Promise; getRecords( btx: DatabaseTransaction, req: RecordGetRequest, ): Promise; storeRecord( btx: DatabaseTransaction, storeReq: RecordStoreRequest, ): Promise; }