From 3437ff93e758117edd028629870d804dd1ab1dc4 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Wed, 6 Jan 2021 13:05:18 +0000 Subject: [PATCH] Allow null queries (fixes #211) --- src/entry.ts | 38 +++++++++++++++++++------------------ test/iterate.ts | 8 ++++---- test/main.ts | 50 ++++++++++++++++++++++++------------------------- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/entry.ts b/src/entry.ts index bdf9794..03936fe 100644 --- a/src/entry.ts +++ b/src/entry.ts @@ -313,7 +313,7 @@ export interface IDBPDatabase */ count>( storeName: Name, - key?: StoreKey | IDBKeyRange, + key?: StoreKey | IDBKeyRange | null, ): Promise; /** * Retrieves the number of records matching the given query in an index. @@ -331,7 +331,7 @@ export interface IDBPDatabase >( storeName: Name, indexName: IndexName, - key?: IndexKey | IDBKeyRange, + key?: IndexKey | IDBKeyRange | null, ): Promise; /** * Deletes records in a store matching the given query. @@ -393,7 +393,7 @@ export interface IDBPDatabase */ getAll>( storeName: Name, - query?: StoreKey | IDBKeyRange, + query?: StoreKey | IDBKeyRange | null, count?: number, ): Promise[]>; /** @@ -413,7 +413,7 @@ export interface IDBPDatabase >( storeName: Name, indexName: IndexName, - query?: IndexKey | IDBKeyRange, + query?: IndexKey | IDBKeyRange | null, count?: number, ): Promise[]>; /** @@ -428,7 +428,7 @@ export interface IDBPDatabase */ getAllKeys>( storeName: Name, - query?: StoreKey | IDBKeyRange, + query?: StoreKey | IDBKeyRange | null, count?: number, ): Promise[]>; /** @@ -448,7 +448,7 @@ export interface IDBPDatabase >( storeName: Name, indexName: IndexName, - query?: IndexKey | IDBKeyRange, + query?: IndexKey | IDBKeyRange | null, count?: number, ): Promise[]>; /** @@ -596,7 +596,9 @@ export interface IDBPObjectStore< /** * Retrieves the number of records matching the given query. */ - count(key?: StoreKey | IDBKeyRange): Promise; + count( + key?: StoreKey | IDBKeyRange | null, + ): Promise; /** * Creates a new index in store. * @@ -630,7 +632,7 @@ export interface IDBPObjectStore< * @param count Maximum number of values to return. */ getAll( - query?: StoreKey | IDBKeyRange, + query?: StoreKey | IDBKeyRange | null, count?: number, ): Promise[]>; /** @@ -640,7 +642,7 @@ export interface IDBPObjectStore< * @param count Maximum number of keys to return. */ getAllKeys( - query?: StoreKey | IDBKeyRange, + query?: StoreKey | IDBKeyRange | null, count?: number, ): Promise[]>; /** @@ -666,7 +668,7 @@ export interface IDBPObjectStore< * @param direction */ openCursor( - query?: StoreKey | IDBKeyRange, + query?: StoreKey | IDBKeyRange | null, direction?: IDBCursorDirection, ): Promise | IDBKeyRange, + query?: StoreKey | IDBKeyRange | null, direction?: IDBCursorDirection, ): Promise | null>; /** @@ -717,7 +719,7 @@ export interface IDBPObjectStore< * @param direction */ iterate( - query?: StoreKey | IDBKeyRange, + query?: StoreKey | IDBKeyRange | null, direction?: IDBCursorDirection, ): AsyncIterableIterator< IDBPCursorWithValueIteratorValue< @@ -761,7 +763,7 @@ export interface IDBPIndex< * Retrieves the number of records matching the given query. */ count( - key?: IndexKey | IDBKeyRange, + key?: IndexKey | IDBKeyRange | null, ): Promise; /** * Retrieves the value of the first record matching the query. @@ -778,7 +780,7 @@ export interface IDBPIndex< * @param count Maximum number of values to return. */ getAll( - query?: IndexKey | IDBKeyRange, + query?: IndexKey | IDBKeyRange | null, count?: number, ): Promise[]>; /** @@ -788,7 +790,7 @@ export interface IDBPIndex< * @param count Maximum number of keys to return. */ getAllKeys( - query?: IndexKey | IDBKeyRange, + query?: IndexKey | IDBKeyRange | null, count?: number, ): Promise[]>; /** @@ -808,7 +810,7 @@ export interface IDBPIndex< * @param direction */ openCursor( - query?: IndexKey | IDBKeyRange, + query?: IndexKey | IDBKeyRange | null, direction?: IDBCursorDirection, ): Promise | IDBKeyRange, + query?: IndexKey | IDBKeyRange | null, direction?: IDBCursorDirection, ): Promise | null>; /** @@ -850,7 +852,7 @@ export interface IDBPIndex< * @param direction */ iterate( - query?: IndexKey | IDBKeyRange, + query?: IndexKey | IDBKeyRange | null, direction?: IDBCursorDirection, ): AsyncIterableIterator< IDBPCursorWithValueIteratorValue< diff --git a/test/iterate.ts b/test/iterate.ts index 99bfa34..52134b3 100644 --- a/test/iterate.ts +++ b/test/iterate.ts @@ -100,7 +100,7 @@ suite('Async iterators', () => { typeAssert< IsExact< Parameters[0], - string | IDBKeyRange | undefined + string | IDBKeyRange | undefined | null > >(true); @@ -114,7 +114,7 @@ suite('Async iterators', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -279,7 +279,7 @@ suite('Async iterators', () => { typeAssert< IsExact< Parameters[0], - Date | IDBKeyRange | undefined + Date | IDBKeyRange | undefined | null > >(true); @@ -294,7 +294,7 @@ suite('Async iterators', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); diff --git a/test/main.ts b/test/main.ts index bf285e8..3e00b8d 100644 --- a/test/main.ts +++ b/test/main.ts @@ -1029,7 +1029,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - string | IDBKeyRange | undefined + string | IDBKeyRange | undefined | null > >(true); @@ -1044,7 +1044,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -1070,12 +1070,12 @@ suite('IDBPObjectStore', () => { db = (await openDB(dbName, getNextVersion(), { upgrade(db, oldVersion, newVersion, tx) { const store = db.createObjectStore('object-store'); - typeAssert< - IsExact[0], string> - >(true); + typeAssert[0], string>>( + true, + ); }, - })) as IDBPDatabase; - }); + })) as IDBPDatabase; + }); test('delete', async () => { const schemaDB = await openDBWithData(); @@ -1143,7 +1143,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - string | IDBKeyRange | undefined + string | IDBKeyRange | undefined | null > >(true); @@ -1158,7 +1158,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -1179,7 +1179,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - string | IDBKeyRange | undefined + string | IDBKeyRange | undefined | null > >(true); @@ -1198,7 +1198,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -1267,7 +1267,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - string | IDBKeyRange | undefined + string | IDBKeyRange | undefined | null > >(true); @@ -1292,7 +1292,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -1323,7 +1323,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - string | IDBKeyRange | undefined + string | IDBKeyRange | undefined | null > >(true); @@ -1346,7 +1346,7 @@ suite('IDBPObjectStore', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -1546,7 +1546,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - Date | IDBKeyRange | undefined + Date | IDBKeyRange | undefined | null > >(true); @@ -1561,7 +1561,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -1628,7 +1628,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - Date | IDBKeyRange | undefined + Date | IDBKeyRange | undefined | null > >(true); @@ -1670,7 +1670,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -1718,7 +1718,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - Date | IDBKeyRange | undefined + Date | IDBKeyRange | undefined | null > >(true); @@ -1735,7 +1735,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -1792,7 +1792,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - Date | IDBKeyRange | undefined + Date | IDBKeyRange | undefined | null > >(true); @@ -1819,7 +1819,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true); @@ -1851,7 +1851,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - Date | IDBKeyRange | undefined + Date | IDBKeyRange | undefined | null > >(true); @@ -1878,7 +1878,7 @@ suite('IDBPIndex', () => { typeAssert< IsExact< Parameters[0], - IDBValidKey | IDBKeyRange | undefined + IDBValidKey | IDBKeyRange | undefined | null > >(true);