Comparing version 2.0.4 to 2.1.0
@@ -68,3 +68,3 @@ /** This is your entry point to the API. It's exposed to the global scope unless you're using a module system such as browserify, in which case it's the exported object. */ | ||
* @returns The new object store. */ | ||
createObjectStore(name: string, optionalParameters?: IDBObjectStoreParameters): ObjectStore; | ||
createObjectStore<TValue=any, TKey=any>(name: string, optionalParameters?: IDBObjectStoreParameters): ObjectStore<TValue, TKey>; | ||
@@ -93,8 +93,8 @@ /** Destroys the object store with the given name in the connected database, along with any indexes that reference it. | ||
* @returns The object store in the context of the transaction. */ | ||
objectStore(name: string): ObjectStore; | ||
objectStore<TValue=any, TKey=any>(name: string): ObjectStore<TValue, TKey>; | ||
} | ||
/** Common interface for ObjectStore and Index, since bothe provide these cursor methods */ | ||
export interface HasCursor { | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves a new cursor object. | ||
export interface HasCursor<TValue, TKey> { | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves a new cursor object. | ||
* Used for iterating through an object store by primary key with a cursor. | ||
@@ -104,5 +104,5 @@ * @param range Optional. A key or IDBKeyRange to be queried. If a single valid key is passed, this will default to a range containing only that key. If nothing is passed, this will default to a key range that selects all the records in this object store. | ||
* @returns A promise that resolves with the cursor once it has been opened. */ | ||
openCursor(range?: IDBKeyRange | IDBValidKey | null, direction?: 'next' | 'nextunique' | 'prev' | 'prevunique'): Promise<Cursor>; | ||
openCursor(range?: IDBKeyRange | IDBValidKey | null, direction?: 'next' | 'nextunique' | 'prev' | 'prevunique'): Promise<Cursor<TValue, TKey>>; | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves a new cursor object. | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves a new cursor object. | ||
* Used for iterating through an object store with a key. | ||
@@ -112,19 +112,19 @@ * @param range Optional. A key or IDBKeyRange to be queried. If a single valid key is passed, this will default to a range containing only that key. If nothing is passed, this will default to a key range that selects all the records in this object store. | ||
* @returns A promise that resolves with the cursor once it has been opened. */ | ||
openKeyCursor(range?: IDBKeyRange | IDBValidKey | null, direction?: 'next' | 'nextunique' | 'prev' | 'prevunique'): Promise<Cursor>; | ||
openKeyCursor(range?: IDBKeyRange | IDBValidKey | null, direction?: 'next' | 'nextunique' | 'prev' | 'prevunique'): Promise<Cursor<TValue, TKey>>; | ||
/** Due to the microtask issues in some browsers, iterating over a cursor using promises doesn't always work. | ||
* So in the mean time, iterateCursor maps to openCursor, takes identical arguments, plus an additional callback that receives an IDBCursor */ | ||
iterateCursor(callback: (c: Cursor) => void): void; | ||
iterateCursor(range: IDBKeyRange | IDBValidKey | null, callback: (c: Cursor) => void): void; | ||
iterateCursor(range: IDBKeyRange | IDBValidKey | null, direction: 'next' | 'nextunique' | 'prev' | 'prevunique', callback: (c: Cursor) => void): void; | ||
iterateCursor(callback: (c: Cursor<TValue, TKey>) => void): void; | ||
iterateCursor(range: IDBKeyRange | IDBValidKey | null, callback: (c: Cursor<TValue, TKey>) => void): void; | ||
iterateCursor(range: IDBKeyRange | IDBValidKey | null, direction: 'next' | 'nextunique' | 'prev' | 'prevunique', callback: (c: Cursor<TValue, TKey>) => void): void; | ||
/** Due to the microtask issues in some browsers, iterating over a cursor using promises doesn't always work. | ||
* So in the mean time, iterateKeyCursor maps to openKeyCursor, takes identical arguments, plus an additional callback that receives an IDBCursor */ | ||
iterateKeyCursor(callback: (c: Cursor) => void): void; | ||
iterateKeyCursor(range: IDBKeyRange | IDBValidKey | null, callback: (c: Cursor) => void): void; | ||
iterateKeyCursor(range: IDBKeyRange | IDBValidKey | null, direction: 'next' | 'nextunique' | 'prev' | 'prevunique', callback: (c: Cursor) => void): void; | ||
iterateKeyCursor(callback: (c: Cursor<TValue, TKey>) => void): void; | ||
iterateKeyCursor(range: IDBKeyRange | IDBValidKey | null, callback: (c: Cursor<TValue, TKey>) => void): void; | ||
iterateKeyCursor(range: IDBKeyRange | IDBValidKey | null, direction: 'next' | 'nextunique' | 'prev' | 'prevunique', callback: (c: Cursor<TValue, TKey>) => void): void; | ||
} | ||
/** Wrapper of IDBObjectStore that presents the asynchronous operations as Promises. */ | ||
export interface ObjectStore extends HasCursor { | ||
export interface ObjectStore<TValue, TKey> extends HasCursor<TValue, TKey> { | ||
/** The name of this object store. Settable only during upgrades. */ | ||
@@ -142,3 +142,3 @@ name: string; | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) creates a structured clone of the value, and updates the cloned value in the object store. | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) creates a structured clone of the value, and updates the cloned value in the object store. | ||
* This is for updating existing records in an object store when the transaction's mode is readwrite. | ||
@@ -148,3 +148,3 @@ * @param value The value to be stored. | ||
* @returns A promise that resolves with the new key when the underlying put IDBRequest is successful. */ | ||
put(value: any, key?: IDBKeyRange | IDBValidKey): Promise<IDBValidKey>; | ||
put(value: TValue, key?: IDBKeyRange | IDBValidKey): Promise<IDBValidKey>; | ||
@@ -156,3 +156,3 @@ /** Returns a Promise of an IDBRequest object that (in a separate thread) creates a structured clone of the value, and stores the cloned value in the object store. | ||
* @returns A promise that resolves with the new key when the underlying add IDBRequest is successful. */ | ||
add(value: any, key?: IDBKeyRange | IDBValidKey): Promise<IDBValidKey>; | ||
add(value: TValue, key?: IDBKeyRange | IDBValidKey): Promise<IDBValidKey>; | ||
@@ -170,13 +170,13 @@ /** Returns a Promise of an IDBRequest object that (in a separate thread) deletes the store object specified. | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with the store object store selected by the specified key. | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with the store object store selected by the specified key. | ||
* This is for retrieving specific records from an object store. | ||
* @param key The key or key range that identifies the record to be retrieved. | ||
* @returns A promise that resolves with the item when the underlying get IDBRequest is successful. */ | ||
get(key: any): Promise<any>; | ||
get(key: TKey): Promise<TValue>; | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with the objects in the object store matching the specified parameter or all objects in the store if no parameters are given. | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with the objects in the object store matching the specified parameter or all objects in the store if no parameters are given. | ||
* @param query Optional. A key or IDBKeyRange to be queried. If nothing is passed, this will default to a key range that selects all the records in this object store. | ||
* @param count Optional. Specifies the number of values to return if more than one is found. If it is lower than 0 or greater than 232-1 a TypeError exception will be thrown. | ||
* @returns A promise that resolves with the items when the underlying getAll IDBRequest is successful. */ | ||
getAll(query?: IDBKeyRange | IDBValidKey, count?: number): Promise<any[]>; | ||
getAll(query?: IDBKeyRange | IDBValidKey, count?: number): Promise<TValue[]>; | ||
@@ -186,3 +186,3 @@ /** Returns a Promise of an IDBRequest object that (in a separate thread) finds either the given key or the primary key, if key is an IDBKeyRange. | ||
* @returns A promise that resolves with the item when the underlying get IDBRequest is successful. */ | ||
getKey(key: IDBKeyRange | IDBValidKey): Promise<any>; | ||
getKey(key: IDBKeyRange | IDBValidKey): Promise<TKey>; | ||
@@ -193,3 +193,3 @@ /** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with record keys for all the objects matching the specified parameter or all record keys in the store if no parameters are given. | ||
* @returns A promise that resolves with the record keys when the underlying getAllKeys IDBRequest is successful. */ | ||
getAllKeys(query?: IDBKeyRange, count?: number): Promise<any[]>; | ||
getAllKeys(query?: IDBKeyRange, count?: number): Promise<TKey[]>; | ||
@@ -207,3 +207,3 @@ /** Returns a Promise of an IDBRequest object that (in a separate thread) counts the matching records. | ||
* @returns The newly created index. */ | ||
createIndex(name: string, keyPath: string | string[], optionalParameters?: IDBIndexParameters): Index; | ||
createIndex<TKey=any>(name: string, keyPath: string | string[], optionalParameters?: IDBIndexParameters): Index<TValue, TKey>; | ||
@@ -217,7 +217,7 @@ /** Destroys the specified index in the connected database, used during a version upgrade. | ||
* @returns The specified index. */ | ||
index(name: string): Index; | ||
index<TKey=any>(name: string): Index<TValue, TKey>; | ||
} | ||
/** Wrapper of IDBIndex that presents the asynchronous operations as Promises. */ | ||
export interface Index extends HasCursor { | ||
export interface Index<TValue, TKey> extends HasCursor<TValue, TKey> { | ||
/** The name of this index. */ | ||
@@ -229,3 +229,3 @@ readonly name: string; | ||
/** Affects how the index behaves when the result of evaluating the index's key path yields an array. | ||
/** Affects how the index behaves when the result of evaluating the index's key path yields an array. | ||
* If true, there is one record in the index for each item in an array of keys. | ||
@@ -244,7 +244,7 @@ * If false, then there is one record for each key that is an array. */ | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with the store object store selected by the specified key. | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with the store object store selected by the specified key. | ||
* This is for retrieving specific records from an object store. | ||
* @param key The key or key range that identifies the record to be retrieved. | ||
* @returns A promise that resolves with the item when the underlying get IDBRequest is successful. */ | ||
get(key: IDBKeyRange | IDBValidKey): Promise<any>; | ||
get(key: IDBKeyRange | IDBValidKey): Promise<TValue>; | ||
@@ -254,9 +254,9 @@ /** Returns a Promise of an IDBRequest object that (in a separate thread) finds either the given key or the primary key, if key is an IDBKeyRange. | ||
* @returns A promise that resolves with the item when the underlying get IDBRequest is successful. */ | ||
getKey(key: IDBKeyRange | IDBValidKey): Promise<any>; | ||
getKey(key: IDBKeyRange | IDBValidKey): Promise<TValue>; | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with the objects in the object store matching the specified parameter or all objects in the store if no parameters are given. | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with the objects in the object store matching the specified parameter or all objects in the store if no parameters are given. | ||
* @param query Optional. A key or IDBKeyRange to be queried. If nothing is passed, this will default to a key range that selects all the records in this object store. | ||
* @param count Optional. Specifies the number of values to return if more than one is found. If it is lower than 0 or greater than 232-1 a TypeError exception will be thrown. | ||
* @returns A promise that resolves with the items when the underlying getAll IDBRequest is successful. */ | ||
getAll(query?: IDBKeyRange | IDBValidKey, count?: number): Promise<any[]>; | ||
getAll(query?: IDBKeyRange | IDBValidKey, count?: number): Promise<TValue[]>; | ||
@@ -267,7 +267,7 @@ /** Returns a Promise of an IDBRequest object that (in a separate thread) resolves with record keys for all the objects matching the specified parameter or all record keys in the store if no parameters are given. | ||
* @returns A promise that resolves with the record keys when the underlying getAllKeys IDBRequest is successful. */ | ||
getAllKeys(query?: IDBKeyRange, count?: number): Promise<any[]>; | ||
getAllKeys(query?: IDBKeyRange, count?: number): Promise<TKey[]>; | ||
} | ||
/** Wrapper of IDBCursor that presents the asynchronous operations as Promises. */ | ||
export interface Cursor { | ||
export interface Cursor<TValue, TKey> { | ||
/** The key for the record at the cursor's position. If the cursor is outside its range, this is set to undefined. The cursor's key can be any data type. */ | ||
@@ -277,3 +277,3 @@ readonly key: IDBKeyRange | IDBValidKey; | ||
/** The cursor's current effective primary key. If the cursor is currently being iterated or has iterated outside its range, this is set to undefined. The cursor's primary key can be any data type. */ | ||
readonly primaryKey: any; | ||
readonly primaryKey: TKey | undefined; | ||
@@ -284,5 +284,5 @@ /** The direction of traversal of the cursor. */ | ||
/** The current value under the cursor. */ | ||
readonly value: any; | ||
readonly value: TValue; | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) deletes the record at the cursor's position, without changing the cursor's position. | ||
/** Returns a Promise of an IDBRequest object that (in a separate thread) deletes the record at the cursor's position, without changing the cursor's position. | ||
* This can be used to delete specific records. | ||
@@ -296,3 +296,3 @@ * @returns A promise that resolves when the underlying delete IDBRequest is successful. */ | ||
* @returns A promise that resolves when the underlying update IDBRequest is successful. */ | ||
update(value: any): Promise<void>; | ||
update(value: TValue): Promise<void>; | ||
@@ -302,3 +302,3 @@ /** Sets the number times a cursor should move its position forward. | ||
* @returns The cursor after having been moved forward the specified number of times. */ | ||
advance(count: number): Promise<Cursor>; | ||
advance(count: number): Promise<Cursor<TValue, TKey>>; | ||
@@ -308,3 +308,3 @@ /** Advances the cursor to the next position along its direction, to the item whose key matches the optional key parameter. | ||
* @returns The cursor after having been continued to the next or specified record. */ | ||
continue(key?: IDBKeyRange | IDBValidKey): Promise<Cursor>; | ||
continue(key?: IDBKeyRange | IDBValidKey): Promise<Cursor<TValue, TKey>>; | ||
@@ -315,3 +315,3 @@ /** Sets the cursor to the given index key and primary key given as arguments. | ||
* @returns The cursor after having been continued to the next or specified record. */ | ||
continuePrimaryKey(key?: IDBKeyRange | IDBValidKey, primaryKey?: any): Promise<Cursor>; | ||
continuePrimaryKey(key?: IDBKeyRange | IDBValidKey, primaryKey?: TKey): Promise<Cursor<TValue, TKey>>; | ||
} |
{ | ||
"name": "idb", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "IndexedDB but with promises", | ||
@@ -5,0 +5,0 @@ "main": "lib/node.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
190386