Skip to content

Commit

Permalink
Fix unwrapping of types when transaction is readwrite. Fixes jakearch…
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald committed Oct 18, 2021
1 parent 8ee0403 commit 447a973
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions build/cjs/wrap-idb-value.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ interface Unwrap {
(value: IDBPCursorWithValue<any, any, any, any, any>): IDBCursorWithValue;
(value: IDBPCursor<any, any, any, any, any>): IDBCursor;
(value: IDBPDatabase): IDBDatabase;
(value: IDBPIndex<any, any, any, any>): IDBIndex;
(value: IDBPObjectStore<any, any, any>): IDBObjectStore;
(value: IDBPIndex<any, any, any, any, any>): IDBIndex;
(value: IDBPObjectStore<any, any, any, any>): IDBObjectStore;
(value: IDBPTransaction<any, any, any>): IDBTransaction;
<T extends any>(value: Promise<IDBPDatabase<T>>): IDBOpenDBRequest;
(value: Promise<IDBPDatabase>): IDBOpenDBRequest;
Expand Down
2 changes: 1 addition & 1 deletion build/cjs/wrap-idb-value.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build/esm/wrap-idb-value.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ interface Unwrap {
(value: IDBPCursorWithValue<any, any, any, any, any>): IDBCursorWithValue;
(value: IDBPCursor<any, any, any, any, any>): IDBCursor;
(value: IDBPDatabase): IDBDatabase;
(value: IDBPIndex<any, any, any, any>): IDBIndex;
(value: IDBPObjectStore<any, any, any>): IDBObjectStore;
(value: IDBPIndex<any, any, any, any, any>): IDBIndex;
(value: IDBPObjectStore<any, any, any, any>): IDBObjectStore;
(value: IDBPTransaction<any, any, any>): IDBTransaction;
<T extends any>(value: Promise<IDBPDatabase<T>>): IDBOpenDBRequest;
(value: Promise<IDBPDatabase>): IDBOpenDBRequest;
Expand Down
2 changes: 1 addition & 1 deletion build/esm/wrap-idb-value.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/wrap-idb-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ interface Unwrap {
(value: IDBPCursorWithValue<any, any, any, any, any>): IDBCursorWithValue;
(value: IDBPCursor<any, any, any, any, any>): IDBCursor;
(value: IDBPDatabase): IDBDatabase;
(value: IDBPIndex<any, any, any, any>): IDBIndex;
(value: IDBPObjectStore<any, any, any>): IDBObjectStore;
(value: IDBPIndex<any, any, any, any, any>): IDBIndex;
(value: IDBPObjectStore<any, any, any, any>): IDBObjectStore;
(value: IDBPTransaction<any, any, any>): IDBTransaction;
<T extends any>(value: Promise<IDBPDatabase<T>>): IDBOpenDBRequest;
(value: Promise<IDBPDatabase>): IDBOpenDBRequest;
Expand Down
18 changes: 15 additions & 3 deletions test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,15 +838,18 @@ suite('IDBPTransaction', () => {

const tx = schemaDB.transaction('key-val-store');
const tx2 = db.transaction('key-val-store');
const tx3 = schemaDB.transaction('key-val-store', 'readwrite');
const unwrappedTx = unwrap(tx);
const unwrappedTx2 = unwrap(tx2);
const unwrappedTx3 = unwrap(tx3);

typeAssert<IsExact<typeof unwrappedTx, IDBTransaction>>(true);

typeAssert<IsExact<typeof unwrappedTx2, IDBTransaction>>(true);
typeAssert<IsExact<typeof unwrappedTx3, IDBTransaction>>(true);

assert.notProperty(unwrappedTx, 'store');
assert.notProperty(unwrappedTx2, 'store');
assert.notProperty(unwrappedTx3, 'store');
});
});

Expand Down Expand Up @@ -1495,15 +1498,18 @@ suite('IDBPObjectStore', () => {

const store1 = schemaDB.transaction('key-val-store').store;
const store2 = db.transaction('key-val-store').store;
const store3 = schemaDB.transaction('key-val-store', 'readwrite').store;
const unwrappedStore1 = unwrap(store1);
const unwrappedStore2 = unwrap(store2);
const unwrappedStore3 = unwrap(store3);

typeAssert<IsExact<typeof unwrappedStore1, IDBObjectStore>>(true);

typeAssert<IsExact<typeof unwrappedStore2, IDBObjectStore>>(true);
typeAssert<IsExact<typeof unwrappedStore3, IDBObjectStore>>(true);

assert.instanceOf(unwrappedStore1.get('foo'), IDBRequest);
assert.instanceOf(unwrappedStore2.get('foo'), IDBRequest);
assert.instanceOf(unwrappedStore3.get('foo'), IDBRequest);
});
});

Expand Down Expand Up @@ -1973,15 +1979,21 @@ suite('IDBPIndex', () => {

const index1 = schemaDB.transaction('object-store').store.index('date');
const index2 = db.transaction('object-store').store.index('title');
const index3 = schemaDB
.transaction('object-store', 'readwrite')
.store.index('date');

const unwrappedIndex1 = unwrap(index1);
const unwrappedIndex2 = unwrap(index2);
const unwrappedIndex3 = unwrap(index3);

typeAssert<IsExact<typeof unwrappedIndex1, IDBIndex>>(true);

typeAssert<IsExact<typeof unwrappedIndex2, IDBIndex>>(true);
typeAssert<IsExact<typeof unwrappedIndex3, IDBIndex>>(true);

assert.instanceOf(unwrappedIndex1.get('foo'), IDBRequest);
assert.instanceOf(unwrappedIndex2.get('foo'), IDBRequest);
assert.instanceOf(unwrappedIndex3.get('foo'), IDBRequest);
});
});

Expand Down

0 comments on commit 447a973

Please sign in to comment.