// Type definitions for Dexie v2.0.4 // Project: https://github.com/dfahlander/Dexie.js // Definitions by: David Fahlander declare type IndexableTypePart = string | number | Date | ArrayBuffer | ArrayBufferView | DataView | Array>; declare type IndexableTypeArray = Array; declare type IndexableTypeArrayReadonly = ReadonlyArray; export declare type IndexableType = IndexableTypePart | IndexableTypeArrayReadonly; declare type ThenShortcut = (value: T) => TResult | PromiseLike; declare type TransactionMode = 'r' | 'r!' | 'r?' | 'rw' | 'rw!' | 'rw?'; interface ProbablyError { name?: string; stack?: string; message?: string; } // Dexie is actually default exported at the end of this file. // Still, need to keep this explicit export anyway. Needed in order for // Typescript 2.1 to allow extension of the Dexie API. export declare class Dexie { constructor(databaseName: string, options?: { addons?: Array<(db: Dexie) => void>, autoOpen?: boolean, indexedDB?: IDBFactory, IDBKeyRange?: {new(): IDBKeyRange} }); readonly name: string; readonly tables: Dexie.Table[]; readonly verno: number; static addons: Array<(db: Dexie) => void>; static version: number; static semVer: string; static currentTransaction: Dexie.Transaction; static waitFor (promise: PromiseLike | T) : Dexie.Promise; static waitFor (promise: PromiseLike | T, timeoutMilliseconds: number) : Dexie.Promise; static getDatabaseNames(): Dexie.Promise; static getDatabaseNames(thenShortcut: ThenShortcut): Dexie.Promise; static override (origFunc:F, overridedFactory: (fn:any)=>any) : F; static getByKeyPath(obj: Object, keyPath: string): any; static setByKeyPath(obj: Object, keyPath: string, value: any): void; static delByKeyPath(obj: Object, keyPath: string): void; static shallowClone (obj: T): T; static deepClone(obj: T): T; static asap(fn: Function) : void; static maxKey: Array> | string; static minKey: number; static exists(dbName: string) : Dexie.Promise; static delete(dbName: string): Dexie.Promise; static dependencies: { indexedDB: IDBFactory, IDBKeyRange: IDBKeyRange }; static default: Dexie; version(versionNumber: Number): Dexie.Version; on: Dexie.DbEvents; open(): Dexie.Promise; table(tableName: string): Dexie.Table; table(tableName: string): Dexie.Table; table(tableName: string): Dexie.Table; transaction(mode: TransactionMode, table: Dexie.Table, scope: () => PromiseLike | U): Dexie.Promise; transaction(mode: TransactionMode, table: Dexie.Table, table2: Dexie.Table, scope: () => PromiseLike | U): Dexie.Promise; transaction(mode: TransactionMode, table: Dexie.Table, table2: Dexie.Table, table3: Dexie.Table, scope: () => PromiseLike | U): Dexie.Promise; transaction(mode: TransactionMode, table: Dexie.Table, table2: Dexie.Table, table3: Dexie.Table, table4: Dexie.Table, scope: () => PromiseLike | U): Dexie.Promise; transaction(mode: TransactionMode, table: Dexie.Table, table2: Dexie.Table, table3: Dexie.Table, table4: Dexie.Table, table5: Dexie.Table, scope: () => PromiseLike | U): Dexie.Promise; transaction(mode: TransactionMode, tables: Dexie.Table[], scope: () => PromiseLike | U): Dexie.Promise; close(): void; delete(): Dexie.Promise; isOpen(): boolean; hasBeenClosed(): boolean; hasFailed(): boolean; dynamicallyOpened(): boolean; backendDB(): IDBDatabase; vip(scopeFunction: () => U): U; // 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 : new()=>Dexie.Table; WhereClause: new()=>Dexie.WhereClause; Version: new()=>Dexie.Version; Transaction: new()=>Dexie.Transaction; Collection: new()=>Dexie.Collection; } export declare module Dexie { interface Promise { // From Promise in lib.es2015.d.ts and lib.es2015.symbol.wellknown.d.ts but with return type Dexie.Promise: then(onfulfilled?: ((value: T) => T | PromiseLike) | undefined | null, onrejected?: ((reason: any) => T | PromiseLike) | undefined | null): Dexie.Promise; then(onfulfilled: ((value: T) => T | PromiseLike) | undefined | null, onrejected: (reason: any) => TResult | PromiseLike): Dexie.Promise; then(onfulfilled: (value: T) => TResult | PromiseLike, onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Dexie.Promise; then(onfulfilled: (value: T) => TResult1 | PromiseLike, onrejected: (reason: any) => TResult2 | PromiseLike): Dexie.Promise; catch(onrejected?: ((reason: any) => T | PromiseLike) | undefined | null): Dexie.Promise; catch(onrejected: (reason: any) => TResult | PromiseLike): Dexie.Promise; readonly [Symbol.toStringTag]: "Promise"; // Extended methods provided by Dexie.Promise: /** * Catch errors where error => error.name === errorName. Other errors will remain uncaught. * * @param errorName Name of the type of error to catch such as 'RangeError', 'TypeError', 'DatabaseClosedError', etc. * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of the callback. */ catch(errorName: string, onrejected: (reason: Error) => TResult | PromiseLike): Dexie.Promise; /** * Catch errors where error => error.name === errorName. Other errors will remain uncaught. * * @param errorName Name of the type of error to catch such as 'RangeError', 'TypeError', 'DatabaseClosedError', etc. * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of the callback. */ catch(errorName: string, onrejected: (reason: Error) => T | PromiseLike): Dexie.Promise; /** * Catch errors where error => error instanceof errorConstructor. Other errors will remain uncaught. * * @param errorConstructor Type of error to catch such as RangeError, TypeError, etc. * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of the callback. */ catch(errorConstructor: {new():TError}, onrejected: (reason: TError) => TResult | PromiseLike): Dexie.Promise; /** * Catch errors where error => error instanceof errorConstructor. Other errors will remain uncaught. * * @param errorConstructor Type of error to catch such as RangeError, TypeError, etc. * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of the callback. */ catch(errorConstructor: {new():TError}, onrejected: (reason: TError) => T | PromiseLike): Dexie.Promise; /** * Attaches a callback to be executed when promise is settled no matter if it was rejected * or resolved. * * @param onFinally The callback to execute when promise is settled. * @returns A Promise for the completion of the callback. */ finally(onFinally: () => void): Dexie.Promise; /** * Apply a timeout limit for the promise. If timeout is reached before promise is settled, * the returned promise will reject with an Error object where name='TimeoutError'. * * @param milliseconds Number of milliseconds for the timeout. * @returns A Promise that will resolve or reject identically to current Promise, but if timeout is reached, * it will reject with TimeoutError. */ timeout(milliseconds: number): Dexie.Promise; } interface DexiePromiseConstructor { // From lib.es6.d.ts: all(values: Iterable>): Dexie.Promise; race(values: Iterable>): Dexie.Promise; readonly prototype: Dexie.Promise; new (executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Dexie.Promise; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Dexie.Promise<[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]): Dexie.Promise<[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]): Dexie.Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Dexie.Promise<[T1, T2, T3, T4, T5, T6, T7]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike, T6 | PromiseLike]): Dexie.Promise<[T1, T2, T3, T4, T5, T6]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike , T5 | PromiseLike]): Dexie.Promise<[T1, T2, T3, T4, T5]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike ]): Dexie.Promise<[T1, T2, T3, T4]>; all(values: [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Dexie.Promise<[T1, T2, T3]>; all(values: [T1 | PromiseLike, T2 | PromiseLike]): Dexie.Promise<[T1, T2]>; all(values: (T | PromiseLike)[]): Dexie.Promise; reject(reason: any): Dexie.Promise; reject(reason: any): Dexie.Promise; resolve(value: T | PromiseLike): Dexie.Promise; resolve(): Dexie.Promise; } var Promise: DexiePromiseConstructor; interface Version { stores(schema: { [key: string]: string | null }): Version; upgrade(fn: (trans: Transaction) => void): Version; } interface Transaction { active: boolean; db: Dexie; mode: string; idbtrans: IDBTransaction; tables: { [type: string]: Table }; storeNames: Array; on: TransactionEvents; abort(): void; table(tableName: string): Table; table(tableName: string): Table; table(tableName: string): Table; } interface DexieEvent { subscribers: Function[]; fire(...args:any[]): any; subscribe(fn: (...args:any[]) => any): void; unsubscribe(fn: (...args:any[]) => any): void; } interface DexieErrorEvent { subscribe(fn: (error: any) => any): void; unsubscribe(fn: (error: any) => any): void; fire(error: any): any; } interface DexieVersionChangeEvent { subscribe(fn: (event: IDBVersionChangeEvent) => any): void; unsubscribe(fn: (event: IDBVersionChangeEvent) => any): void; fire(event: IDBVersionChangeEvent): any; } interface DexieOnReadyEvent { subscribe(fn: () => any, bSticky: boolean): void; unsubscribe(fn: () => any): void; fire(): any; } interface DexieEventSet { (eventName: string): DexieEvent; // To be able to unsubscribe. addEventType ( eventName: string, chainFunction?: (f1:Function,f2:Function)=>Function, defaultFunction?: Function):Dexie.DexieEvent; addEventType ( events: {[eventName:string]: ('asap' | [(f1:Function,f2:Function)=>Function, Function])}) : Dexie.DexieEvent; } interface DbEvents extends DexieEventSet { (eventName: 'ready', subscriber: () => any, bSticky?: boolean): void; (eventName: 'populate', subscriber: () => any): void; (eventName: 'blocked', subscriber: () => any): void; (eventName: 'versionchange', subscriber: (event: IDBVersionChangeEvent) => any): void; ready: Dexie.DexieOnReadyEvent; populate: Dexie.DexieEvent; blocked: Dexie.DexieEvent; versionchange: Dexie.DexieVersionChangeEvent; } interface CreatingHookContext { onsuccess?: (primKey: Key) => void; onerror?: (err: any) => void; } interface UpdatingHookContext { onsuccess?: (updatedObj: T) => void; onerror?: (err: any) => void; } interface DeletingHookContext { onsuccess?: () => void; onerror?: (err: any) => void; } interface TableHooks extends DexieEventSet { (eventName: 'creating', subscriber: (this: CreatingHookContext, primKey:Key, obj:T, transaction:Transaction) => any): void; (eventName: 'reading', subscriber: (obj:T) => T | any): void; (eventName: 'updating', subscriber: (this: UpdatingHookContext, modifications:Object, primKey:Key, obj:T, transaction:Transaction) => any): void; (eventName: 'deleting', subscriber: (this: DeletingHookContext, primKey:Key, obj:T, transaction:Transaction) => any): void; creating: DexieEvent; reading: DexieEvent; updating: DexieEvent; deleting: DexieEvent; } 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; } interface Table { name: string; schema: TableSchema; hook: TableHooks; get(key: Key): Promise; get(key: Key, thenShortcut: ThenShortcut): Promise; get(equalityCriterias: {[key:string]:IndexableType}): Promise; get(equalityCriterias: {[key:string]:IndexableType}, thenShortcut: ThenShortcut): Promise; where(index: string | string[]): WhereClause; where(equalityCriterias: {[key:string]:IndexableType}): Collection; filter(fn: (obj: T) => boolean): Collection; count(): Promise; count(thenShortcut: ThenShortcut): Promise; offset(n: number): Collection; limit(n: number): Collection; each(callback: (obj: T, cursor: {key: IndexableType, primaryKey: Key}) => any): Promise; toArray(): Promise>; toArray(thenShortcut: ThenShortcut): Promise; toCollection(): Collection; orderBy(index: string | string[]): Collection; reverse(): Collection; mapToClass(constructor: Function): Function; add(item: T, key?: Key): Promise; update(key: Key, changes: { [keyPath: string]: any }): Promise; put(item: T, key?: Key): Promise; delete(key: Key): Promise; clear(): Promise; bulkAdd(items: T[], keys?: IndexableTypeArrayReadonly): Promise; bulkPut(items: T[], keys?: IndexableTypeArrayReadonly): Promise; bulkDelete(keys: IndexableTypeArrayReadonly) : Promise; } interface WhereClause { above(key: IndexableType): Collection; aboveOrEqual(key: IndexableType): Collection; anyOf(keys: IndexableTypeArrayReadonly): Collection; anyOf(...keys: IndexableTypeArray): Collection; anyOfIgnoreCase(keys: string[]): Collection; anyOfIgnoreCase(...keys: string[]): Collection; below(key: IndexableType): Collection; belowOrEqual(key: IndexableType): Collection; between(lower: IndexableType, upper: IndexableType, includeLower?: boolean, includeUpper?: boolean): Collection; equals(key: IndexableType): Collection; equalsIgnoreCase(key: string): Collection; inAnyRange(ranges: Array): 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: Array): Collection; notEqual(key: IndexableType): Collection; } interface Collection { and(filter: (x: T) => boolean): Collection; clone(props?: Object): Collection; count(): Promise; count(thenShortcut: ThenShortcut): Promise; distinct(): Collection; each(callback: (obj: T, cursor: {key: IndexableType, primaryKey: Key}) => any): Promise; eachKey(callback: (key: IndexableType, cursor: {key: IndexableType, primaryKey: Key}) => any): Promise; eachPrimaryKey(callback: (key: Key, cursor: {key: IndexableType, primaryKey: Key}) => any): Promise; eachUniqueKey(callback: (key: IndexableType, cursor: {key: IndexableType, primaryKey: Key}) => any): Promise; filter(filter: (x: T) => boolean): Collection; first(): Promise; first(thenShortcut: ThenShortcut): Promise; keys(): Promise; keys(thenShortcut: ThenShortcut): Promise; primaryKeys(): Promise; primaryKeys(thenShortcut: ThenShortcut): Promise; last(): Promise; last(thenShortcut: ThenShortcut): Promise; limit(n: number): Collection; offset(n: number): Collection; or(indexOrPrimayKey: string): WhereClause; raw(): Collection; reverse(): Collection; sortBy(keyPath: string): Promise; sortBy(keyPath: string, thenShortcut: ThenShortcut) : Promise; toArray(): Promise>; toArray(thenShortcut: ThenShortcut) : Promise; uniqueKeys(): Promise; uniqueKeys(thenShortcut: ThenShortcut): Promise; until(filter: (value: T) => boolean, includeStopEntry?: boolean): Collection; // Mutating methods delete(): Promise; modify(changeCallback: (obj: T, ctx:{value: T}) => void): Promise; modify(changes: { [keyPath: string]: any } ): Promise; } interface TableSchema { name: string; primKey: IndexSpec; indexes: IndexSpec[]; mappedClass: Function; } interface IndexSpec { name: string; keyPath: string | Array; unique: boolean; multi: boolean; auto: boolean; compound: boolean; src: string; } // Make it possible to touch physical classes as they are var TableSchema: new()=>TableSchema, IndexSpec: new()=>IndexSpec, Events: any; // Too complex to define correctly right now. // errnames - handy spellcheck in switch (error.name) {} cases. var errnames: { // Error names generated by indexedDB: Unknown: 'UnknownError'; Constraint: 'ConstraintError'; Data: 'DataError'; TransactionInactive: 'TransactionInactiveError'; ReadOnly: 'ReadOnlyError'; Version: 'VersionError'; NotFound: 'NotFoundError'; InvalidState: 'InvalidStateError'; InvalidAccess: 'InvalidAccessError'; Abort: 'AbortError'; Timeout: 'TimeoutError'; QuotaExceeded: 'QuotaExceededError'; Syntax: 'SyntaxError'; DataClone: 'DataCloneError'; // Dexie-specific error names: Modify: 'ModifyError'; OpenFailed: 'OpenFailedError'; VersionChange: 'VersionChangeError'; Schema: 'SchemaError'; Upgrade: 'UpgradeError'; InvalidTable: 'InvalidTableError'; MissingAPI: 'MissingAPIError'; NoSuchDatabase: 'NoSuchDatabaseError'; InvalidArgument: 'InvalidArgumentError'; SubTransaction: 'Error'; Unsupported: 'UnsupportedError'; Internal: 'InternalError'; DatabaseClosed: 'DatabaseClosedError'; }; class DexieError extends Error { name: string; message: string; stack: string; inner: any; constructor (name?:string, message?:string); toString(): string; } class ModifyError extends DexieError{ constructor (msg?:string, failures?: any[], successCount?: number, failedKeys?: IndexableTypeArrayReadonly); failures: Array; failedKeys: IndexableTypeArrayReadonly; successCount: number; } class BulkError extends DexieError{ constructor (msg?:string, failures?: any[]); failures: Array; } class OpenFailedError extends DexieError {constructor (msg?: string, inner?: Object);constructor (inner: Object);} class VersionChangeError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class SchemaError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class UpgradeError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class InvalidTableError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class MissingAPIError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class NoSuchDatabaseError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class InvalidArgumentError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class SubTransactionError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class UnsupportedError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class InternalError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class DatabaseClosedError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class UnknownError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class ConstraintError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class DataError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class TransactionInactiveError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class ReadOnlyError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class VersionError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class NotFoundError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class InvalidStateError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class InvalidAccessError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class AbortError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class TimeoutError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class QuotaExceededError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class SyntaxError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} class DataCloneError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} } export default Dexie;