2019-06-15 22:44:54 +02:00
|
|
|
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;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-06-15 22:44:54 +02:00
|
|
|
range: BridgeIDBKeyRange | undefined;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-06-15 22:44:54 +02:00
|
|
|
lastIndexPosition?: Key;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
|
|
|
* Last position in terms of the object store key.
|
|
|
|
*/
|
2019-06-15 22:44:54 +02:00
|
|
|
lastObjectStorePosition?: Key;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
|
|
|
* If specified, the index key of the results must be
|
|
|
|
* greater or equal to advanceIndexKey.
|
|
|
|
*
|
|
|
|
* Only applicable if indexName is specified.
|
|
|
|
*/
|
2019-06-15 22:44:54 +02:00
|
|
|
advanceIndexKey?: Key;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
|
|
|
* If specified, the primary key of the results must be greater
|
|
|
|
* or equal to advancePrimaryKey.
|
|
|
|
*/
|
2019-06-15 22:44:54 +02:00
|
|
|
advancePrimaryKey?: Key;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
|
|
|
* Maximum number of resuts to return.
|
|
|
|
* If -1, return all available results
|
|
|
|
*/
|
2019-06-15 22:44:54 +02:00
|
|
|
limit: number;
|
|
|
|
resultLevel: ResultLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RecordGetResponse {
|
|
|
|
values: Value[] | undefined;
|
2019-06-21 19:18:36 +02:00
|
|
|
indexKeys: Key[] | undefined;
|
2019-06-15 22:44:54 +02:00
|
|
|
primaryKeys: Key[] | undefined;
|
|
|
|
count: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RecordStoreRequest {
|
|
|
|
objectStoreName: string;
|
|
|
|
value: Value;
|
|
|
|
key: Key | undefined;
|
|
|
|
overwrite: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Backend {
|
|
|
|
getDatabases(): Promise<BridgeIDBDatabaseInfo[]>;
|
|
|
|
|
|
|
|
connectDatabase(name: string): Promise<DatabaseConnection>;
|
|
|
|
|
|
|
|
beginTransaction(
|
|
|
|
conn: DatabaseConnection,
|
|
|
|
objectStores: string[],
|
|
|
|
mode: TransactionMode,
|
|
|
|
): Promise<DatabaseTransaction>;
|
|
|
|
|
|
|
|
enterVersionChange(
|
|
|
|
conn: DatabaseConnection,
|
|
|
|
newVersion: number,
|
|
|
|
): Promise<DatabaseTransaction>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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<void>;
|
|
|
|
|
|
|
|
close(db: DatabaseConnection): Promise<void>;
|
|
|
|
|
|
|
|
getSchema(db: DatabaseConnection): Schema;
|
|
|
|
|
|
|
|
renameIndex(btx: DatabaseTransaction, oldName: string, newName: string): void;
|
|
|
|
|
|
|
|
deleteIndex(btx: DatabaseTransaction, indexName: string): void;
|
|
|
|
|
|
|
|
rollback(btx: DatabaseTransaction): Promise<void>;
|
|
|
|
|
|
|
|
commit(btx: DatabaseTransaction): Promise<void>;
|
|
|
|
|
|
|
|
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<void>;
|
|
|
|
|
|
|
|
getRecords(
|
|
|
|
btx: DatabaseTransaction,
|
|
|
|
req: RecordGetRequest,
|
|
|
|
): Promise<RecordGetResponse>;
|
|
|
|
|
|
|
|
storeRecord(
|
|
|
|
btx: DatabaseTransaction,
|
|
|
|
storeReq: RecordStoreRequest,
|
|
|
|
): Promise<void>;
|
|
|
|
}
|