Update type signatures to match IDB's types

This commit is contained in:
Danila Fedorin 2021-08-16 10:35:34 -07:00
parent 3ed639d1c5
commit a4375c0e15
2 changed files with 14 additions and 14 deletions

View file

@ -18,15 +18,15 @@ import {iterateCursor, reqAsPromise} from "./utils";
type Reducer<A,B> = (acc: B, val: A) => B type Reducer<A,B> = (acc: B, val: A) => B
type IDBQuery = IDBValidKey | IDBKeyRange | undefined export type IDBQuery = IDBValidKey | IDBKeyRange | undefined | null
interface QueryTargetInterface<T> { interface QueryTargetInterface<T> {
openCursor: (range?: IDBQuery | null , direction?: IDBCursorDirection) => IDBRequest<IDBCursorWithValue | null>; openCursor: (range?: IDBQuery, direction?: IDBCursorDirection | undefined) => IDBRequest<IDBCursorWithValue | null>;
openKeyCursor: (range?: IDBQuery, direction?: IDBCursorDirection) => IDBRequest<IDBCursor | null>; openKeyCursor: (range?: IDBQuery, direction?: IDBCursorDirection | undefined) => IDBRequest<IDBCursor | null>;
supports: (method: string) => boolean; supports: (method: string) => boolean;
keyPath: string | string[]; keyPath: string | string[];
get: (key: IDBQuery) => IDBRequest<T | null>; get: (key: IDBValidKey | IDBKeyRange) => IDBRequest<T | null>;
getKey: (key: IDBQuery) => IDBRequest<IDBValidKey | undefined>; getKey: (key: IDBValidKey | IDBKeyRange) => IDBRequest<IDBValidKey | undefined>;
} }
export class QueryTarget<T> { export class QueryTarget<T> {
@ -52,11 +52,11 @@ export class QueryTarget<T> {
return this._target.supports(methodName); return this._target.supports(methodName);
} }
get(key: IDBQuery): Promise<T | null> { get(key: IDBValidKey | IDBKeyRange): Promise<T | null> {
return reqAsPromise(this._target.get(key)); return reqAsPromise(this._target.get(key));
} }
getKey(key: IDBQuery): Promise<IDBValidKey | undefined> { getKey(key: IDBValidKey | IDBKeyRange): Promise<IDBValidKey | undefined> {
if (this._target.supports("getKey")) { if (this._target.supports("getKey")) {
return reqAsPromise(this._target.getKey(key)); return reqAsPromise(this._target.getKey(key));
} else { } else {

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {QueryTarget} from "./QueryTarget"; import {QueryTarget, IDBQuery} from "./QueryTarget";
import {IDBRequestAttemptError} from "./error"; import {IDBRequestAttemptError} from "./error";
import {reqAsPromise} from "./utils"; import {reqAsPromise} from "./utils";
import {Transaction} from "./Transaction"; import {Transaction} from "./Transaction";
@ -50,7 +50,7 @@ class QueryTargetWrapper<T> {
return !!this._qt[methodName]; return !!this._qt[methodName];
} }
openKeyCursor(range?: IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursor | null> { openKeyCursor(range?: IDBQuery, direction?: IDBCursorDirection | undefined): IDBRequest<IDBCursor | null> {
try { try {
// not supported on Edge 15 // not supported on Edge 15
if (!this._qt.openKeyCursor) { if (!this._qt.openKeyCursor) {
@ -64,7 +64,7 @@ class QueryTargetWrapper<T> {
} }
} }
openCursor(range?: IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null> { openCursor(range?: IDBQuery, direction?: IDBCursorDirection | undefined): IDBRequest<IDBCursorWithValue | null> {
try { try {
LOG_REQUESTS && logRequest("openCursor", [], this._qt); LOG_REQUESTS && logRequest("openCursor", [], this._qt);
return this._qt.openCursor(range, direction) return this._qt.openCursor(range, direction)
@ -73,7 +73,7 @@ class QueryTargetWrapper<T> {
} }
} }
put(item: T, key?: IDBValidKey): IDBRequest<IDBValidKey> { put(item: T, key?: IDBValidKey | undefined): IDBRequest<IDBValidKey> {
try { try {
LOG_REQUESTS && logRequest("put", [item, key], this._qt); LOG_REQUESTS && logRequest("put", [item, key], this._qt);
return this._qtStore.put(item, key); return this._qtStore.put(item, key);
@ -82,7 +82,7 @@ class QueryTargetWrapper<T> {
} }
} }
add(item: T, key?: IDBValidKey): IDBRequest<IDBValidKey> { add(item: T, key?: IDBValidKey | undefined): IDBRequest<IDBValidKey> {
try { try {
LOG_REQUESTS && logRequest("add", [item, key], this._qt); LOG_REQUESTS && logRequest("add", [item, key], this._qt);
return this._qtStore.add(item, key); return this._qtStore.add(item, key);
@ -91,7 +91,7 @@ class QueryTargetWrapper<T> {
} }
} }
get(key: IDBValidKey): IDBRequest<T | null> { get(key: IDBValidKey | IDBKeyRange): IDBRequest<T | null> {
try { try {
LOG_REQUESTS && logRequest("get", [key], this._qt); LOG_REQUESTS && logRequest("get", [key], this._qt);
return this._qt.get(key); return this._qt.get(key);
@ -100,7 +100,7 @@ class QueryTargetWrapper<T> {
} }
} }
getKey(key: IDBValidKey): IDBRequest<IDBValidKey | undefined> { getKey(key: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey | undefined> {
try { try {
LOG_REQUESTS && logRequest("getKey", [key], this._qt); LOG_REQUESTS && logRequest("getKey", [key], this._qt);
return this._qt.getKey(key) return this._qt.getKey(key)