/* * Dexie.js - a minimalistic wrapper for IndexedDB * =============================================== * * By David Fahlander, david.fahlander@gmail.com * * Version 3.0.1, Thu May 07 2020 * * http://dexie.org * * Apache License Version 2.0, January 2004, http://www.apache.org/licenses/ */ export interface IndexSpec { name: string; keyPath: string | Array | undefined; unique: boolean | undefined; multi: boolean | undefined; auto: boolean | undefined; compound: boolean | undefined; src: string; } export interface TableSchema { name: string; primKey: IndexSpec; indexes: IndexSpec[]; mappedClass: Function; idxByName: {[name: string]: IndexSpec}; readHook?: (x:any) => any } export type IndexableTypePart = string | number | Date | ArrayBuffer | ArrayBufferView | DataView | Array>; export type IndexableTypeArray = Array; export type IndexableTypeArrayReadonly = ReadonlyArray; export type IndexableType = IndexableTypePart | IndexableTypeArrayReadonly; export interface DexieEvent { subscribers: Function[]; fire(...args:any[]): any; subscribe(fn: (...args:any[]) => any): void; unsubscribe(fn: (...args:any[]) => any): void; } export interface DexieEventSet { (eventName: string): DexieEvent; // To be able to unsubscribe. addEventType ( eventName: string, chainFunction?: (f1:Function,f2:Function)=>Function, defaultFunction?: Function): DexieEvent; addEventType ( events: {[eventName:string]: ('asap' | [(f1:Function,f2:Function)=>Function, Function])}) : DexieEvent; } export type TransactionMode = 'readonly' | 'readwrite' | 'r' | 'r!' | 'r?' | 'rw' | 'rw!' | 'rw?'; export interface PromiseExtendedConstructor extends PromiseConstructor { readonly prototype: PromiseExtended; new (executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): PromiseExtended; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): PromiseExtended<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): PromiseExtended<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): PromiseExtended<[T1, T2, T3, T4, T5, T6, T7, T8]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): PromiseExtended<[T1, T2, T3, T4, T5, T6, T7]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike, T6 | PromiseLike]): PromiseExtended<[T1, T2, T3, T4, T5, T6]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike]): PromiseExtended<[T1, T2, T3, T4, T5]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike ]): PromiseExtended<[T1, T2, T3, T4]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): PromiseExtended<[T1, T2, T3]>; all(values: [T1 | PromiseLike, T2 | PromiseLike]): PromiseExtended<[T1, T2]>; all(values: (T | PromiseLike)[]): PromiseExtended; race(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): PromiseExtended; race(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): PromiseExtended; race(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): PromiseExtended; race(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): PromiseExtended; race(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): PromiseExtended; race(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): PromiseExtended; race(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): PromiseExtended; race(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): PromiseExtended; race(values: [T1 | PromiseLike, T2 | PromiseLike]): PromiseExtended; race(values: (T | PromiseLike)[]): PromiseExtended; reject(reason: any): PromiseExtended; reject(reason: any): PromiseExtended; resolve(value: T | PromiseLike): PromiseExtended; resolve(): PromiseExtended; } /** The interface of Dexie.Promise, which basically extends standard Promise with methods: * * finally() - also subject for standardization * timeout() - set a completion timeout * catch(ErrorClass, handler) - java style error catching * catch(errorName, handler) - cross-domain safe type error catching (checking error.name instead of instanceof) * */ export interface PromiseExtended extends Promise { then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): PromiseExtended; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): PromiseExtended; catch(ErrorConstructor: Function, onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): PromiseExtended; catch(errorName: string, onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): PromiseExtended; finally(onFinally?: () => U | PromiseLike): PromiseExtended; timeout (ms: number, msg?: string): PromiseExtended; } export type ThenShortcut = (value: T) => TResult | PromiseLike; export interface Collection { //db: Database; and(filter: (x: T) => boolean): Collection; clone(props?: Object): Collection; count(): PromiseExtended; count(thenShortcut: ThenShortcut): PromiseExtended; distinct(): Collection; each(callback: (obj: T, cursor: {key: IndexableType, primaryKey: TKey}) => any): PromiseExtended; eachKey(callback: (key: IndexableType, cursor: {key: IndexableType, primaryKey: TKey}) => any): PromiseExtended; eachPrimaryKey(callback: (key: TKey, cursor: {key: IndexableType, primaryKey: TKey}) => any): PromiseExtended; eachUniqueKey(callback: (key: IndexableType, cursor: {key: IndexableType, primaryKey: TKey}) => any): PromiseExtended; filter(filter: (x: T) => boolean): Collection; first(): PromiseExtended; first(thenShortcut: ThenShortcut): PromiseExtended; keys(): PromiseExtended; keys(thenShortcut: ThenShortcut): PromiseExtended; primaryKeys(): PromiseExtended; primaryKeys(thenShortcut: ThenShortcut): PromiseExtended; last(): PromiseExtended; last(thenShortcut: ThenShortcut): PromiseExtended; limit(n: number): Collection; offset(n: number): Collection; or(indexOrPrimayKey: string): WhereClause; raw(): Collection; reverse(): Collection; sortBy(keyPath: string): PromiseExtended; sortBy(keyPath: string, thenShortcut: ThenShortcut) : PromiseExtended; toArray(): PromiseExtended>; toArray(thenShortcut: ThenShortcut) : PromiseExtended; uniqueKeys(): PromiseExtended; uniqueKeys(thenShortcut: ThenShortcut): PromiseExtended; until(filter: (value: T) => boolean, includeStopEntry?: boolean): Collection; // Mutating methods delete(): PromiseExtended; modify(changeCallback: (obj: T, ctx:{value: T}) => void | boolean): PromiseExtended; modify(changes: { [keyPath: string]: any } ): PromiseExtended; } export interface WhereClause { above(key: any): Collection; aboveOrEqual(key: any): Collection; anyOf(keys: ReadonlyArray): Collection; anyOf(...keys: Array): Collection; anyOfIgnoreCase(keys: string[]): Collection; anyOfIgnoreCase(...keys: string[]): Collection; below(key: any): Collection; belowOrEqual(key: any): Collection; between(lower: any, upper: any, includeLower?: boolean, includeUpper?: boolean): Collection; equals(key: IndexableType): Collection; equalsIgnoreCase(key: string): Collection; inAnyRange(ranges: ReadonlyArray<{0: any, 1: any}>, options?: { includeLowers?: boolean, includeUppers?: boolean }): Collection; startsWith(key: string): Collection; startsWithAnyOf(prefixes: string[]): Collection; startsWithAnyOf(...prefixes: string[]): Collection; startsWithIgnoreCase(key: string): Collection; startsWithAnyOfIgnoreCase(prefixes: string[]): Collection; startsWithAnyOfIgnoreCase(...prefixes: string[]): Collection; noneOf(keys: ReadonlyArray): Collection; notEqual(key: IndexableType): Collection; } export interface Database { readonly name: string; readonly tables: Table[]; table(tableName: string): Table; transaction(mode: TransactionMode, table: Table, scope: () => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: Table, table2: Table, scope: () => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: Table, table2: Table, table3: Table, scope: () => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: Table, table2: Table, table3: Table, table4: Table, scope: () => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: Table, table2: Table, table3: Table, table4: Table, table5: Table, scope: () => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, tables: Table[], scope: () => PromiseLike | U): PromiseExtended; } export interface TransactionEvents extends DexieEventSet { (eventName: 'complete', subscriber: () => any): void; (eventName: 'abort', subscriber: () => any): void; (eventName: 'error', subscriber: (error:any) => any): void; complete: DexieEvent; abort: DexieEvent; error: DexieEvent; } export interface Transaction { db: Database; active: boolean; mode: IDBTransactionMode; //tables: { [type: string]: Table }; Deprecated since 2.0. Obsolete from v3.0. storeNames: Array; parent?: Transaction; on: TransactionEvents; abort(): void; table(tableName: string): Table; table(tableName: string): Table; table(tableName: string): Table; } export interface CreatingHookContext { onsuccess?: (primKey: Key) => void; onerror?: (err: any) => void; } export interface UpdatingHookContext { onsuccess?: (updatedObj: T) => void; onerror?: (err: any) => void; } export interface DeletingHookContext { onsuccess?: () => void; onerror?: (err: any) => void; } export interface TableHooks extends DexieEventSet { (eventName: 'creating', subscriber: (this: CreatingHookContext, primKey:TKey, obj:T, transaction:Transaction) => any): void; (eventName: 'reading', subscriber: (obj:T) => T | any): void; (eventName: 'updating', subscriber: (this: UpdatingHookContext, modifications:Object, primKey:TKey, obj:T, transaction:Transaction) => any): void; (eventName: 'deleting', subscriber: (this: DeletingHookContext, primKey:TKey, obj:T, transaction:Transaction) => any): void; creating: DexieEvent; reading: DexieEvent; updating: DexieEvent; deleting: DexieEvent; } export const enum DBCoreRangeType { Equal = 1, Range = 2, Any = 3, Never = 4 } export interface DBCoreKeyRange { readonly type: DBCoreRangeType; readonly lower: any; readonly lowerOpen?: boolean; readonly upper: any; readonly upperOpen?: boolean; //includes (key: Key) : boolean; Despite IDBKeyRange api - it's no good to have this as a method. Benefit from using a more functional approach. } export interface DBCoreTransaction { abort(): void; } export interface DBCoreTransactionRequest { tables: string[]; mode: 'readonly' | 'readwrite'; } export type DBCoreMutateRequest = DBCoreAddRequest | DBCorePutRequest | DBCoreDeleteRequest | DBCoreDeleteRangeRequest; export interface DBCoreMutateResponse { numFailures: number, failures: {[operationNumber: number]: Error}; lastResult: any; results?: any[]; // Present on AddRequest and PutRequest if request.wantResults is truthy. } export interface DBCoreAddRequest { type: 'add'; trans: DBCoreTransaction; values: any[]; keys?: any[]; wantResults?: boolean; } export interface DBCorePutRequest { type: 'put'; trans: DBCoreTransaction; values: any[]; keys?: any[]; wantResults?: boolean; } export interface DBCoreDeleteRequest { type: 'delete'; trans: DBCoreTransaction; keys: any[]; } export interface DBCoreDeleteRangeRequest { type: 'deleteRange'; trans: DBCoreTransaction; range: DBCoreKeyRange; } export interface DBCoreGetManyRequest { trans: DBCoreTransaction; keys: any[]; } export interface DBCoreGetRequest { trans: DBCoreTransaction; key: any; } export interface DBCoreQuery { index: DBCoreIndex;//keyPath: null | string | string[]; // null represents primary key. string a property, string[] several properties. range: DBCoreKeyRange; } export interface DBCoreQueryRequest { trans: DBCoreTransaction; values?: boolean; limit?: number; query: DBCoreQuery; } export interface DBCoreQueryResponse { result: any[]; } export interface DBCoreOpenCursorRequest { trans: DBCoreTransaction; values?: boolean; unique?: boolean; reverse?: boolean; query: DBCoreQuery; } export interface DBCoreCountRequest { trans: DBCoreTransaction; query: DBCoreQuery; } export interface DBCoreCursor { readonly trans: DBCoreTransaction; readonly key: any; readonly primaryKey: any; readonly value?: any; readonly done?: boolean; continue(key?: any): void; continuePrimaryKey(key: any, primaryKey: any): void; advance(count: number): void; start(onNext: ()=>void): Promise stop(value?: any | Promise): void; next(): Promise; fail(error: Error): void; } export interface DBCoreSchema { name: string; tables: DBCoreTableSchema[]; } export interface DBCoreTableSchema { readonly name: string; readonly primaryKey: DBCoreIndex; readonly indexes: DBCoreIndex[]; readonly getIndexByKeyPath: (keyPath: null | string | string[]) => DBCoreIndex | undefined; } export interface DBCoreIndex { /** Name of the index, or null for primary key */ readonly name: string | null; /** True if this index represents the primary key */ readonly isPrimaryKey?: boolean; /** True if this index represents the primary key and is not inbound (http://dexie.org/docs/inbound) */ readonly outbound?: boolean; /** True if and only if keyPath is an array (http://dexie.org/docs/Compound-Index) */ readonly compound?: boolean; /** keyPath, null for primary key, string for single-property indexes, Array for compound indexes */ readonly keyPath: null | string | string[]; /** Auto-generated primary key (does not apply to secondary indexes) */ readonly autoIncrement?: boolean; /** Whether index is unique. Also true if index is primary key. */ readonly unique?: boolean; /** Whether index is multiEntry. */ readonly multiEntry?: boolean; /** Extract (using keyPath) a key from given value (object) */ readonly extractKey: (value: any) => any; } export interface DBCore { stack: "dbcore"; // Transaction and Object Store transaction(req: DBCoreTransactionRequest): DBCoreTransaction; // Utility methods cmp(a: any, b: any) : number; readonly MIN_KEY: any; readonly MAX_KEY: any; readonly schema: DBCoreSchema; table(name: string): DBCoreTable; } export interface DBCoreTable { readonly name: string; readonly schema: DBCoreTableSchema; mutate(req: DBCoreMutateRequest): Promise; get(req: DBCoreGetRequest): Promise; getMany(req: DBCoreGetManyRequest): Promise; query(req: DBCoreQueryRequest): Promise; openCursor(req: DBCoreOpenCursorRequest): Promise; count(req: DBCoreCountRequest): Promise; } export interface Table { db: Database; name: string; schema: TableSchema; hook: TableHooks; core: DBCoreTable; get(key: TKey): PromiseExtended; get(key: TKey, thenShortcut: ThenShortcut): PromiseExtended; get(equalityCriterias: {[key:string]:any}): PromiseExtended; get(equalityCriterias: {[key:string]:any}, thenShortcut: ThenShortcut): PromiseExtended; where(index: string | string[]): WhereClause; where(equalityCriterias: {[key:string]:any}): Collection; filter(fn: (obj: T) => boolean): Collection; count(): PromiseExtended; count(thenShortcut: ThenShortcut): PromiseExtended; offset(n: number): Collection; limit(n: number): Collection; each(callback: (obj: T, cursor: {key: any, primaryKey: TKey}) => any): PromiseExtended; toArray(): PromiseExtended>; toArray(thenShortcut: ThenShortcut): PromiseExtended; toCollection(): Collection; orderBy(index: string | string[]): Collection; reverse(): Collection; mapToClass(constructor: Function): Function; add(item: T, key?: TKey): PromiseExtended; update(key: TKey | T, changes: { [keyPath: string]: any }): PromiseExtended; put(item: T, key?: TKey): PromiseExtended; delete(key: TKey): PromiseExtended; clear(): PromiseExtended; bulkGet(keys: TKey[]): PromiseExtended; bulkAdd(items: T[], keys: IndexableTypeArrayReadonly, options: { allKeys: B }): PromiseExtended; bulkAdd(items: T[], options: { allKeys: B }): PromiseExtended; bulkAdd(items: T[], keys?: IndexableTypeArrayReadonly, options?: { allKeys: boolean }): PromiseExtended; bulkPut(items: T[], keys: IndexableTypeArrayReadonly, options: { allKeys: B }): PromiseExtended; bulkPut(items: T[], options: { allKeys: B }): PromiseExtended; bulkPut(items: T[], keys?: IndexableTypeArrayReadonly, options?: { allKeys: boolean }): PromiseExtended; bulkDelete(keys: IndexableTypeArrayReadonly): PromiseExtended; } export interface Version { stores(schema: { [tableName: string]: string | null }): Version; upgrade(fn: (trans: Transaction) => void): Version; } export interface DexieOnReadyEvent { subscribe(fn: () => any, bSticky: boolean): void; unsubscribe(fn: () => any): void; fire(): any; } export interface DexieVersionChangeEvent { subscribe(fn: (event: IDBVersionChangeEvent) => any): void; unsubscribe(fn: (event: IDBVersionChangeEvent) => any): void; fire(event: IDBVersionChangeEvent): any; } export interface DexiePopulateEvent { subscribe(fn: (trans: Transaction) => any): void; unsubscribe(fn: (trans: Transaction) => any): void; fire(trans: Transaction): any; } export interface DbEvents extends DexieEventSet { (eventName: 'ready', subscriber: () => any, bSticky?: boolean): void; (eventName: 'populate', subscriber: (trans: Transaction) => any): void; (eventName: 'blocked', subscriber: (event: IDBVersionChangeEvent) => any): void; (eventName: 'versionchange', subscriber: (event: IDBVersionChangeEvent) => any): void; ready: DexieOnReadyEvent; populate: DexiePopulateEvent; blocked: DexieEvent; versionchange: DexieVersionChangeEvent; } export type DbSchema = {[tableName: string]: TableSchema}; export interface Middleware { stack: TStack["stack"], create: (down: TStack) => Partial; level?: number; name?: string; } export interface DexieStacks { dbcore: DBCore; } export interface Dexie extends Database { readonly name: string; readonly tables: Table[]; readonly verno: number; readonly _allTables: {[name: string]: Table}; readonly core: DBCore; _createTransaction: ( this: Dexie, mode: IDBTransactionMode, storeNames: ArrayLike, dbschema: DbSchema, parentTransaction?: Transaction | null) => Transaction; _dbSchema: DbSchema; version(versionNumber: number): Version; on: DbEvents; open(): PromiseExtended; table(tableName: string): Table; transaction(mode: TransactionMode, table: Table, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: string, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: Table, table2: Table, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: string, table2: string, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: Table, table2: Table, table3: Table, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: string, table2: string, table3: string, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: Table, table2: Table, table3: Table, table4: Table, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: string, table2: string, table3: string, table4: string, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: Table, table2: Table, table3: Table, table4: Table, table5: Table, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, table: string, table2: string, table3: string, table4: string, table5: string, scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, tables: Table[], scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; transaction(mode: TransactionMode, tables: string[], scope: (trans: Transaction) => PromiseLike | U): PromiseExtended; close(): void; delete(): PromiseExtended; isOpen(): boolean; hasBeenClosed(): boolean; hasFailed(): boolean; dynamicallyOpened(): boolean; backendDB(): IDBDatabase; use(middleware: Middleware): this; // Add more supported stacks here... : use(middleware: Middleware): this; unuse({stack, create}: Middleware<{stack: keyof DexieStacks}>): this; unuse({stack, name}: {stack: keyof DexieStacks, name: string}): this; // Make it possible to touch physical class constructors where they reside - as properties on db instance. // For example, checking if (x instanceof db.Table). Can't do (x instanceof Dexie.Table because it's just a virtual interface) Table : {prototype: Table}; WhereClause: {prototype: WhereClause}; Version: {prototype: Version}; Transaction: {prototype: Transaction}; Collection: {prototype: Collection}; } /** DexieError * * Common base class for all errors originating from Dexie.js except TypeError, * SyntaxError and RangeError. * * http://dexie.org/docs/DexieErrors/DexieError * */ export interface DexieError extends Error { name: string; message: string; stack: string; inner: any; toString(): string; } /** * List of the names of auto-generated error classes that extends DexieError * and shares the interface of DexieError. * * Each error should be documented at http://dexie.org/docs/DexieErrors/Dexie. * * The generic type DexieExceptionClasses is a map of full error name to * error constructor. The DexieExceptionClasses is mixed in into Dexie, * so that it is always possible to throw or catch certain errors via * Dexie.ErrorName. Example: * * try { * throw new Dexie.InvalidTableError("Invalid table foo", innerError?); * } catch (err) { * if (err instanceof Dexie.InvalidTableError) { * // Could also have check for err.name === "InvalidTableError", or * // err.name === Dexie.errnames.InvalidTableError. * console.log("Seems to be an invalid table here..."); * } else { * throw err; * } * } */ export type DexieErrors = { // http://dexie.org/docs/DexieErrors/Dexie.OpenFailedError OpenFailed: 'OpenFailedError', // http://dexie.org/docs/DexieErrors/Dexie.VersionChangeError VersionChange: 'VersionChangeError', // http://dexie.org/docs/DexieErrors/Dexie.SchemaError Schema: 'SchemaError', // http://dexie.org/docs/DexieErrors/Dexie.UpgradeError Upgrade: 'UpgradeError', // http://dexie.org/docs/DexieErrors/Dexie.InvalidTableError InvalidTable: 'InvalidTableError', // http://dexie.org/docs/DexieErrors/Dexie.MissingAPIError MissingAPI: 'MissingAPIError', // http://dexie.org/docs/DexieErrors/Dexie.NoSuchDatabaseError NoSuchDatabase: 'NoSuchDatabaseError', // http://dexie.org/docs/DexieErrors/Dexie.InvalidArgumentError InvalidArgument: 'InvalidArgumentError', // http://dexie.org/docs/DexieErrors/Dexie.SubTransactionError SubTransaction: 'SubTransactionError', // http://dexie.org/docs/DexieErrors/Dexie.UnsupportedError Unsupported: 'UnsupportedError', // http://dexie.org/docs/DexieErrors/Dexie.InternalError Internal: 'InternalError', // http://dexie.org/docs/DexieErrors/Dexie.DatabaseClosedError DatabaseClosed: 'DatabaseClosedError', // http://dexie.org/docs/DexieErrors/Dexie.PrematureCommitError PrematureCommit: 'PrematureCommitError', // http://dexie.org/docs/DexieErrors/Dexie.ForeignAwaitError ForeignAwait: 'ForeignAwaitError', // http://dexie.org/docs/DexieErrors/Dexie.UnknownError Unknown: 'UnknownError', // http://dexie.org/docs/DexieErrors/Dexie.ConstraintError Constraint: 'ConstraintError', // http://dexie.org/docs/DexieErrors/Dexie.DataError Data: 'DataError', // http://dexie.org/docs/DexieErrors/Dexie.TransactionInactiveError TransactionInactive: 'TransactionInactiveError', // http://dexie.org/docs/DexieErrors/Dexie.ReadOnlyError ReadOnly: 'ReadOnlyError', // http://dexie.org/docs/DexieErrors/Dexie.VersionError Version: 'VersionError', // http://dexie.org/docs/DexieErrors/Dexie.NotFoundError NotFound: 'NotFoundError', // http://dexie.org/docs/DexieErrors/Dexie.InvalidStateError InvalidState: 'InvalidStateError', // http://dexie.org/docs/DexieErrors/Dexie.InvalidAccessError InvalidAccess: 'InvalidAccessError', // http://dexie.org/docs/DexieErrors/Dexie.AbortError Abort: 'AbortError', // http://dexie.org/docs/DexieErrors/Dexie.TimeoutError Timeout: 'TimeoutError', // http://dexie.org/docs/DexieErrors/Dexie.QuotaExceededError QuotaExceeded: 'QuotaExceededError', // http://dexie.org/docs/DexieErrors/Dexie.DataCloneError DataClone: 'DataCloneError' } /** ModifyError * * http://dexie.org/docs/DexieErrors/Dexie.ModifyError */ export interface ModifyError extends DexieError { failures: Array; failedKeys: IndexableTypeArrayReadonly; successCount: number; } /** BulkError * * http://dexie.org/docs/DexieErrors/Dexie.BulkError */ export interface BulkError extends DexieError { failures: {[operationNumber: number]: Error}; } export interface DexieErrorConstructor { new(msg?: string, inner?: Object) : DexieError; new(inner: Object): DexieError; prototype: DexieError; } export interface ModifyErrorConstructor { new ( msg?:string, failures?: any[], successCount?: number, failedKeys?: IndexableTypeArrayReadonly) : ModifyError; prototype: ModifyError; } export interface BulkErrorConstructor { new (msg?:string, failures?: {[operationNumber: number]: Error}) : BulkError; prototype: BulkError; } export type ExceptionSet = {[P in DexieErrors[keyof DexieErrors]]: DexieErrorConstructor}; export type DexieExceptionClasses = ExceptionSet & { DexieError: DexieErrorConstructor, ModifyError: ModifyErrorConstructor; BulkError: BulkErrorConstructor; } export interface DexieDOMDependencies { indexedDB: IDBFactory; IDBKeyRange: typeof IDBKeyRange; } export interface DexieOptions { addons?: Array<(db: Dexie) => void>, autoOpen?: boolean, indexedDB?: {open: Function}, IDBKeyRange?: {bound: Function, lowerBound: Function, upperBound: Function}, allowEmptyDB?: boolean; } export interface DexieConstructor extends DexieExceptionClasses { new(databaseName: string, options?: DexieOptions) : Dexie; prototype: Dexie; addons: Array<(db: Dexie) => void>; version: number; semVer: string; currentTransaction: Transaction; waitFor (promise: PromiseLike | T, timeoutMilliseconds?: number) : Promise; getDatabaseNames(): Promise; getDatabaseNames(thenShortcut: ThenShortcut): Promise; vip(scopeFunction: () => U): U; ignoreTransaction(fn: ()=> U) : U; override (origFunc:F, overridedFactory: (fn:any)=>any) : F; // ? getByKeyPath(obj: Object, keyPath: string): any; setByKeyPath(obj: Object, keyPath: string, value: any): void; delByKeyPath(obj: Object, keyPath: string): void; shallowClone (obj: T): T; deepClone(obj: T): T; asap(fn: Function) : void; //? maxKey: Array> | string; minKey: number; exists(dbName: string) : Promise; delete(dbName: string): Promise; dependencies: DexieDOMDependencies; default: Dexie; // Work-around for different build tools handling default imports differently. Promise: PromiseExtendedConstructor; //TableSchema: {}; // Deprecate! //IndexSpec: {new():IndexSpec}; //? Deprecate Events: (ctx?: any)=>DexieEventSet; errnames: {[P in keyof DexieExceptionClasses]: P}; } export declare var Dexie: DexieConstructor; export interface _Table extends Table {} export interface _Collection extends Collection {} export declare module Dexie { // The "Dexie.Promise" type. type Promise = PromiseExtended // Because many samples have been Dexie.Promise. // The "Dexie.Table" interface. Same as named exported interface Table. interface Table extends _Table {} // Because all samples have been Dexie.Table<...> // The "Dexie.Collection" interface. Same as named exported interface Collection. interface Collection extends _Collection {} // Because app-code may declare it. } /** Exporting 'Dexie' as the default export. **/ export default Dexie; export as namespace Dexie;