2019-08-01 23:27:42 +02:00
|
|
|
/*
|
|
|
|
Copyright 2019 Florian Dold
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
or implied. See the License for the specific language governing
|
|
|
|
permissions and limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-10 19:52:45 +01:00
|
|
|
import { BridgeIDBDatabaseInfo, BridgeIDBKeyRange } from "./bridge-idb.js";
|
2019-06-15 22:44:54 +02:00
|
|
|
import {
|
2021-02-08 15:23:44 +01:00
|
|
|
IDBCursorDirection,
|
|
|
|
IDBTransactionMode,
|
|
|
|
IDBValidKey,
|
2022-02-10 19:52:45 +01:00
|
|
|
} from "./idbtypes.js";
|
2021-02-08 15:23:44 +01:00
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export interface ObjectStoreProperties {
|
2021-02-08 19:59:19 +01:00
|
|
|
keyPath: string[] | null;
|
2019-06-15 22:44:54 +02:00
|
|
|
autoIncrement: boolean;
|
2019-08-17 01:03:55 +02:00
|
|
|
indexes: { [nameame: string]: IndexProperties };
|
2019-06-15 22:44:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export interface IndexProperties {
|
2021-02-08 19:59:19 +01:00
|
|
|
keyPath: string[];
|
2019-06-15 22:44:54 +02:00
|
|
|
multiEntry: boolean;
|
|
|
|
unique: boolean;
|
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export interface Schema {
|
|
|
|
databaseName: string;
|
|
|
|
databaseVersion: number;
|
|
|
|
objectStores: { [name: string]: ObjectStoreProperties };
|
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export interface DatabaseConnection {
|
|
|
|
connectionCookie: string;
|
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export interface DatabaseTransaction {
|
|
|
|
transactionCookie: string;
|
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export enum ResultLevel {
|
|
|
|
OnlyCount,
|
2019-06-23 22:16:03 +02:00
|
|
|
OnlyKeys,
|
|
|
|
Full,
|
2019-06-15 22:44:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-07-31 01:33:23 +02:00
|
|
|
export enum StoreLevel {
|
|
|
|
NoOverwrite,
|
|
|
|
AllowOverwrite,
|
|
|
|
UpdateExisting,
|
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export interface RecordGetRequest {
|
2021-02-08 15:23:44 +01:00
|
|
|
direction: IDBCursorDirection;
|
2019-06-15 22:44:54 +02:00
|
|
|
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.
|
|
|
|
*/
|
2021-02-08 15:23:44 +01:00
|
|
|
range: BridgeIDBKeyRange | undefined | null;
|
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.
|
2020-08-03 09:30:48 +02:00
|
|
|
*
|
2019-06-21 19:18:36 +02:00
|
|
|
* Must either be undefined or within range.
|
|
|
|
*/
|
2021-02-08 15:23:44 +01:00
|
|
|
lastIndexPosition?: IDBValidKey;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
|
|
|
* Last position in terms of the object store key.
|
|
|
|
*/
|
2021-02-08 15:23:44 +01:00
|
|
|
lastObjectStorePosition?: IDBValidKey;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
|
|
|
* If specified, the index key of the results must be
|
|
|
|
* greater or equal to advanceIndexKey.
|
2020-08-03 09:30:48 +02:00
|
|
|
*
|
2019-06-21 19:18:36 +02:00
|
|
|
* Only applicable if indexName is specified.
|
|
|
|
*/
|
2021-02-08 15:23:44 +01:00
|
|
|
advanceIndexKey?: IDBValidKey;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
|
|
|
* If specified, the primary key of the results must be greater
|
|
|
|
* or equal to advancePrimaryKey.
|
|
|
|
*/
|
2021-02-08 15:23:44 +01:00
|
|
|
advancePrimaryKey?: IDBValidKey;
|
2019-06-21 19:18:36 +02:00
|
|
|
/**
|
2021-02-22 20:49:36 +01:00
|
|
|
* Maximum number of results to return.
|
2021-12-15 02:37:03 +01:00
|
|
|
* If 0, return all available results
|
2019-06-21 19:18:36 +02:00
|
|
|
*/
|
2019-06-15 22:44:54 +02:00
|
|
|
limit: number;
|
|
|
|
resultLevel: ResultLevel;
|
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export interface RecordGetResponse {
|
2021-02-08 15:23:44 +01:00
|
|
|
values: any[] | undefined;
|
|
|
|
indexKeys: IDBValidKey[] | undefined;
|
|
|
|
primaryKeys: IDBValidKey[] | undefined;
|
2019-06-15 22:44:54 +02:00
|
|
|
count: number;
|
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export interface RecordStoreRequest {
|
|
|
|
objectStoreName: string;
|
2021-02-08 15:23:44 +01:00
|
|
|
value: any;
|
|
|
|
key: IDBValidKey | undefined;
|
2019-07-31 01:33:23 +02:00
|
|
|
storeLevel: StoreLevel;
|
2019-06-15 22:44:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-08-01 23:21:05 +02:00
|
|
|
export interface RecordStoreResponse {
|
|
|
|
/**
|
|
|
|
* Key that the record was stored under in the object store.
|
|
|
|
*/
|
2021-02-08 15:23:44 +01:00
|
|
|
key: IDBValidKey;
|
2019-08-01 23:21:05 +02:00
|
|
|
}
|
|
|
|
|
2020-08-10 11:07:20 +02:00
|
|
|
/** @public */
|
2019-06-15 22:44:54 +02:00
|
|
|
export interface Backend {
|
|
|
|
getDatabases(): Promise<BridgeIDBDatabaseInfo[]>;
|
|
|
|
|
|
|
|
connectDatabase(name: string): Promise<DatabaseConnection>;
|
|
|
|
|
|
|
|
beginTransaction(
|
|
|
|
conn: DatabaseConnection,
|
|
|
|
objectStores: string[],
|
2021-02-08 15:23:44 +01:00
|
|
|
mode: IDBTransactionMode,
|
2019-06-15 22:44:54 +02:00
|
|
|
): Promise<DatabaseTransaction>;
|
|
|
|
|
|
|
|
enterVersionChange(
|
|
|
|
conn: DatabaseConnection,
|
|
|
|
newVersion: number,
|
|
|
|
): Promise<DatabaseTransaction>;
|
|
|
|
|
2021-02-19 21:27:49 +01:00
|
|
|
deleteDatabase(name: string): Promise<void>;
|
2019-06-15 22:44:54 +02:00
|
|
|
|
|
|
|
close(db: DatabaseConnection): Promise<void>;
|
|
|
|
|
|
|
|
getSchema(db: DatabaseConnection): Schema;
|
|
|
|
|
2021-02-16 14:49:38 +01:00
|
|
|
getCurrentTransactionSchema(btx: DatabaseTransaction): Schema;
|
|
|
|
|
|
|
|
getInitialTransactionSchema(btx: DatabaseTransaction): Schema;
|
|
|
|
|
2020-08-03 09:30:48 +02:00
|
|
|
renameIndex(
|
|
|
|
btx: DatabaseTransaction,
|
|
|
|
objectStoreName: string,
|
|
|
|
oldName: string,
|
|
|
|
newName: string,
|
|
|
|
): void;
|
2019-06-15 22:44:54 +02:00
|
|
|
|
2020-08-03 09:30:48 +02:00
|
|
|
deleteIndex(
|
|
|
|
btx: DatabaseTransaction,
|
|
|
|
objectStoreName: string,
|
|
|
|
indexName: string,
|
|
|
|
): void;
|
2019-06-15 22:44:54 +02:00
|
|
|
|
|
|
|
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,
|
2021-02-08 19:59:19 +01:00
|
|
|
keyPath: string | string[],
|
2019-06-15 22:44:54 +02:00
|
|
|
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,
|
2019-08-01 23:21:05 +02:00
|
|
|
): Promise<RecordStoreResponse>;
|
2021-02-23 20:16:10 +01:00
|
|
|
|
|
|
|
clearObjectStore(
|
|
|
|
btx: DatabaseTransaction,
|
|
|
|
objectStoreName: string,
|
2021-06-09 15:26:18 +02:00
|
|
|
): Promise<void>;
|
2019-06-15 22:44:54 +02:00
|
|
|
}
|