From 2ee9431f1ba5bf67546bbf85758a01991c40673f Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 15 Jun 2019 22:44:54 +0200 Subject: idb wip --- packages/idb-bridge/src/backend-interface.ts | 145 +++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 packages/idb-bridge/src/backend-interface.ts (limited to 'packages/idb-bridge/src/backend-interface.ts') diff --git a/packages/idb-bridge/src/backend-interface.ts b/packages/idb-bridge/src/backend-interface.ts new file mode 100644 index 000000000..c0f498a10 --- /dev/null +++ b/packages/idb-bridge/src/backend-interface.ts @@ -0,0 +1,145 @@ +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 { + Full, + OnlyKeys, + OnlyCount, +} + +export interface RecordGetRequest { + direction: BridgeIDBCursorDirection; + objectStoreName: string; + indexName: string | undefined; + range: BridgeIDBKeyRange | undefined; + lastIndexPosition?: Key; + lastObjectStorePosition?: Key; + advanceIndexKey?: Key; + advancePrimaryKey?: Key; + limit: number; + resultLevel: ResultLevel; +} + +export interface RecordGetResponse { + values: Value[] | undefined; + keys: Key[] | undefined; + primaryKeys: Key[] | undefined; + count: number; +} + +export interface RecordStoreRequest { + objectStoreName: string; + value: Value; + key: Key | undefined; + overwrite: boolean; +} + +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; +} -- cgit v1.2.3