Socket
Socket
Sign inDemoInstall

idb

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idb - npm Package Compare versions

Comparing version 4.0.5 to 5.0.0

build/cjs/async-iterators.d.ts

3

.vscode/settings.json
{
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"editor.formatOnSave": true
}
'use strict';
var __chunk_1 = require('./chunk.js');
var wrapIdbValue = require('./wrap-idb-value.js');

@@ -34,3 +34,3 @@ const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];

// Map this double-proxy back to the original, so other cursor methods work.
__chunk_1.reverseTransformCache.set(proxiedCursor, __chunk_1.unwrap(cursor));
wrapIdbValue.reverseTransformCache.set(proxiedCursor, wrapIdbValue.unwrap(cursor));
while (cursor) {

@@ -45,6 +45,7 @@ yield proxiedCursor;

return ((prop === Symbol.asyncIterator &&
__chunk_1.instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor])) ||
(prop === 'iterate' && __chunk_1.instanceOfAny(target, [IDBIndex, IDBObjectStore])));
wrapIdbValue.instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor])) ||
(prop === 'iterate' && wrapIdbValue.instanceOfAny(target, [IDBIndex, IDBObjectStore])));
}
__chunk_1.addTraps(oldTraps => ({
wrapIdbValue.replaceTraps(oldTraps => ({
...oldTraps,
get(target, prop, receiver) {

@@ -51,0 +52,0 @@ if (isIteratorProp(target, prop))

@@ -5,3 +5,3 @@ 'use strict';

var __chunk_1 = require('./chunk.js');
var wrapIdbValue = require('./wrap-idb-value.js');

@@ -15,8 +15,8 @@ /**

*/
function openDB(name, version, { blocked, upgrade, blocking } = {}) {
function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
const request = indexedDB.open(name, version);
const openPromise = __chunk_1.wrap(request);
const openPromise = wrapIdbValue.wrap(request);
if (upgrade) {
request.addEventListener('upgradeneeded', event => {
upgrade(__chunk_1.wrap(request.result), event.oldVersion, event.newVersion, __chunk_1.wrap(request.transaction));
upgrade(wrapIdbValue.wrap(request.result), event.oldVersion, event.newVersion, wrapIdbValue.wrap(request.transaction));
});

@@ -26,4 +26,8 @@ }

request.addEventListener('blocked', () => blocked());
if (terminated)
request.addEventListener('close', () => terminated());
if (blocking) {
openPromise.then(db => db.addEventListener('versionchange', blocking)).catch(() => { });
openPromise
.then(db => db.addEventListener('versionchange', blocking))
.catch(() => { });
}

@@ -41,3 +45,3 @@ return openPromise;

request.addEventListener('blocked', () => blocked());
return __chunk_1.wrap(request).then(() => undefined);
return wrapIdbValue.wrap(request).then(() => undefined);
}

@@ -79,3 +83,4 @@

}
__chunk_1.addTraps(oldTraps => ({
wrapIdbValue.replaceTraps(oldTraps => ({
...oldTraps,
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),

@@ -85,5 +90,5 @@ has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),

exports.unwrap = __chunk_1.unwrap;
exports.wrap = __chunk_1.wrap;
exports.unwrap = wrapIdbValue.unwrap;
exports.wrap = wrapIdbValue.wrap;
exports.deleteDB = deleteDB;
exports.openDB = openDB;
exports.deleteDB = deleteDB;
export {};
//# sourceMappingURL=async-iterators.d.ts.map

@@ -1,2 +0,2 @@

import { b as addTraps, c as instanceOfAny, d as reverseTransformCache, e as unwrap } from './chunk.js';
import { r as replaceTraps, i as instanceOfAny, a as reverseTransformCache, u as unwrap } from './wrap-idb-value.js';

@@ -45,3 +45,4 @@ const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];

}
addTraps(oldTraps => ({
replaceTraps(oldTraps => ({
...oldTraps,
get(target, prop, receiver) {

@@ -48,0 +49,0 @@ if (isIteratorProp(target, prop))

export {};
//# sourceMappingURL=database-extras.d.ts.map

@@ -22,2 +22,7 @@ export interface OpenDBCallbacks<DBTypes extends DBSchema | unknown> {

blocking?(): void;
/**
* Called if the browser abnormally terminates the connection.
* This is not called when `db.close()` is called.
*/
terminated?(): void;
}

@@ -31,3 +36,3 @@ /**

*/
export declare function openDB<DBTypes extends DBSchema | unknown = unknown>(name: string, version: number, { blocked, upgrade, blocking }?: OpenDBCallbacks<DBTypes>): Promise<IDBPDatabase<DBTypes>>;
export declare function openDB<DBTypes extends DBSchema | unknown = unknown>(name: string, version: number, { blocked, upgrade, blocking, terminated }?: OpenDBCallbacks<DBTypes>): Promise<IDBPDatabase<DBTypes>>;
export interface DeleteDBCallbacks {

@@ -156,3 +161,3 @@ /**

*/
clear(name: StoreNames<DBTypes>): Promise<undefined>;
clear(name: StoreNames<DBTypes>): Promise<void>;
/**

@@ -188,3 +193,3 @@ * Retrieves the number of records matching the given query in a store.

*/
delete<Name extends StoreNames<DBTypes>>(storeName: Name, key: StoreKey<DBTypes, Name> | IDBKeyRange): Promise<undefined>;
delete<Name extends StoreNames<DBTypes>>(storeName: Name, key: StoreKey<DBTypes, Name> | IDBKeyRange): Promise<void>;
/**

@@ -313,3 +318,3 @@ * Retrieves the value of the first record in a store matching the query.

*/
readonly done: Promise<undefined>;
readonly done: Promise<void>;
/**

@@ -324,3 +329,3 @@ * The associated object store, if the transaction covers a single store, otherwise undefined.

}
declare type IDBPObjectStoreExtends = Omit<IDBObjectStore, 'transaction' | 'add' | 'clear' | 'count' | 'createIndex' | 'delete' | 'get' | 'getAll' | 'getAllKeys' | 'getKey' | 'index' | 'openCursor' | 'openKeyCursor' | 'put' | 'indexNames' | 'name'>;
declare type IDBPObjectStoreExtends = Omit<IDBObjectStore, 'transaction' | 'add' | 'clear' | 'count' | 'createIndex' | 'delete' | 'get' | 'getAll' | 'getAllKeys' | 'getKey' | 'index' | 'openCursor' | 'openKeyCursor' | 'put' | 'indexNames'>;
export interface IDBPObjectStore<DBTypes extends DBSchema | unknown = unknown, TxStores extends StoreNames<DBTypes>[] = StoreNames<DBTypes>[], StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>> extends IDBPObjectStoreExtends {

@@ -330,8 +335,4 @@ /**

*/
readonly indexNames: IndexNames<DBTypes, StoreName>[];
readonly indexNames: TypedDOMStringList<IndexNames<DBTypes, StoreName>>;
/**
* The name of the store to newName. Can be set during an upgrade transaction.
*/
name: StoreName;
/**
* The associated transaction.

@@ -349,3 +350,3 @@ */

*/
clear(): Promise<undefined>;
clear(): Promise<void>;
/**

@@ -364,3 +365,3 @@ * Retrieves the number of records matching the given query.

*/
delete(key: StoreKey<DBTypes, StoreName> | IDBKeyRange): Promise<undefined>;
delete(key: StoreKey<DBTypes, StoreName> | IDBKeyRange): Promise<void>;
/**

@@ -542,3 +543,3 @@ * Retrieves the value of the first record matching the query.

*/
delete(): Promise<undefined>;
delete(): Promise<void>;
/**

@@ -607,1 +608,2 @@ * Updated the current record.

}
//# sourceMappingURL=entry.d.ts.map
export * from './entry';
import './database-extras';
//# sourceMappingURL=index.d.ts.map

@@ -1,3 +0,3 @@

import { a as wrap, b as addTraps } from './chunk.js';
export { e as unwrap, a as wrap } from './chunk.js';
import { w as wrap, r as replaceTraps } from './wrap-idb-value.js';
export { u as unwrap, w as wrap } from './wrap-idb-value.js';

@@ -11,3 +11,3 @@ /**

*/
function openDB(name, version, { blocked, upgrade, blocking } = {}) {
function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
const request = indexedDB.open(name, version);

@@ -22,4 +22,8 @@ const openPromise = wrap(request);

request.addEventListener('blocked', () => blocked());
if (terminated)
request.addEventListener('close', () => terminated());
if (blocking) {
openPromise.then(db => db.addEventListener('versionchange', blocking)).catch(() => { });
openPromise
.then(db => db.addEventListener('versionchange', blocking))
.catch(() => { });
}

@@ -74,3 +78,4 @@ return openPromise;

}
addTraps(oldTraps => ({
replaceTraps(oldTraps => ({
...oldTraps,
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),

@@ -80,2 +85,2 @@ has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),

export { openDB, deleteDB };
export { deleteDB, openDB };
export declare type Constructor = new (...args: any[]) => any;
export declare type Func = (...args: any[]) => any;
export declare const instanceOfAny: (object: any, constructors: Constructor[]) => boolean;
//# sourceMappingURL=util.d.ts.map
import { IDBPCursor, IDBPCursorWithValue, IDBPDatabase, IDBPIndex, IDBPObjectStore, IDBPTransaction } from './entry';
export declare const reverseTransformCache: WeakMap<object, any>;
export declare function addTraps(callback: (currentTraps: ProxyHandler<any>) => ProxyHandler<any>): void;
export declare function replaceTraps(callback: (currentTraps: ProxyHandler<any>) => ProxyHandler<any>): void;
/**

@@ -35,1 +35,2 @@ * Enhance an IDB object with helpers.

export {};
//# sourceMappingURL=wrap-idb-value.d.ts.map

@@ -1,1 +0,1 @@

var idb=function(e){"use strict";const t=(e,t)=>t.some(t=>e instanceof t);let n,r;const o=new WeakMap,s=new WeakMap,a=new WeakMap,i=new WeakMap,c=new WeakMap;let u={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return s.get(e);if("objectStoreNames"===t)return e.objectStoreNames||a.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return p(e[t])},has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function d(e){return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(r||(r=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(l(this),t),p(o.get(this))}:function(...t){return p(e.apply(l(this),t))}:function(t,...n){const r=e.call(l(this),t,...n);return a.set(r,t.sort?t.sort():[t]),p(r)}}function f(e){return"function"==typeof e?d(e):(e instanceof IDBTransaction&&function(e){if(s.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)});s.set(e,t)}(e),t(e,n||(n=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,u):e)}function p(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(p(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)});return t.then(t=>{t instanceof IDBCursor&&o.set(t,e)}).catch(()=>{}),c.set(t,e),t}(e);if(i.has(e))return i.get(e);const t=f(e);return t!==e&&(i.set(e,t),c.set(t,e)),t}const l=e=>c.get(e);const D=["get","getKey","getAll","getAllKeys","count"],v=["put","add","delete","clear"],B=new Map;function I(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(B.get(t))return B.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=v.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!D.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let a=s.store;r&&(a=a.index(t.shift()));const i=a[n](...t);return o&&await s.done,i};return B.set(t,s),s}return u=(e=>({get:(t,n,r)=>I(t,n)||e.get(t,n,r),has:(t,n)=>!!I(t,n)||e.has(t,n)}))(u),e.openDB=function(e,t,{blocked:n,upgrade:r,blocking:o}={}){const s=indexedDB.open(e,t),a=p(s);return r&&s.addEventListener("upgradeneeded",e=>{r(p(s.result),e.oldVersion,e.newVersion,p(s.transaction))}),n&&s.addEventListener("blocked",()=>n()),o&&a.then(e=>e.addEventListener("versionchange",o)).catch(()=>{}),a},e.deleteDB=function(e,{blocked:t}={}){const n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",()=>t()),p(n).then(()=>void 0)},e.unwrap=l,e.wrap=p,e}({});
var idb=function(e){"use strict";let t,n;const r=new WeakMap,o=new WeakMap,s=new WeakMap,a=new WeakMap,i=new WeakMap;let c={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return o.get(e);if("objectStoreNames"===t)return e.objectStoreNames||s.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return p(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function u(e){return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(n||(n=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(f(this),t),p(r.get(this))}:function(...t){return p(e.apply(f(this),t))}:function(t,...n){const r=e.call(f(this),t,...n);return s.set(r,t.sort?t.sort():[t]),p(r)}}function d(e){return"function"==typeof e?u(e):(e instanceof IDBTransaction&&function(e){if(o.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)});o.set(e,t)}(e),n=e,(t||(t=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])).some(e=>n instanceof e)?new Proxy(e,c):e);var n}function p(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(p(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)});return t.then(t=>{t instanceof IDBCursor&&r.set(t,e)}).catch(()=>{}),i.set(t,e),t}(e);if(a.has(e))return a.get(e);const t=d(e);return t!==e&&(a.set(e,t),i.set(t,e)),t}const f=e=>i.get(e);const l=["get","getKey","getAll","getAllKeys","count"],D=["put","add","delete","clear"],v=new Map;function b(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(v.get(t))return v.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=D.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!l.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let a=s.store;r&&(a=a.index(t.shift()));const i=a[n](...t);return o&&await s.done,i};return v.set(t,s),s}return c=(e=>({...e,get:(t,n,r)=>b(t,n)||e.get(t,n,r),has:(t,n)=>!!b(t,n)||e.has(t,n)}))(c),e.deleteDB=function(e,{blocked:t}={}){const n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",()=>t()),p(n).then(()=>{})},e.openDB=function(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const a=indexedDB.open(e,t),i=p(a);return r&&a.addEventListener("upgradeneeded",e=>{r(p(a.result),e.oldVersion,e.newVersion,p(a.transaction))}),n&&a.addEventListener("blocked",()=>n()),s&&a.addEventListener("close",()=>s()),o&&i.then(e=>e.addEventListener("versionchange",o)).catch(()=>{}),i},e.unwrap=f,e.wrap=p,e}({});

@@ -1,1 +0,1 @@

var idb=function(e){"use strict";const t=(e,t)=>t.some(t=>e instanceof t);let n,r;const o=new WeakMap,s=new WeakMap,a=new WeakMap,i=new WeakMap,c=new WeakMap;let u={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return s.get(e);if("objectStoreNames"===t)return e.objectStoreNames||a.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return l(e[t])},has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function d(e){u=e(u)}function f(e){return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(r||(r=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(D(this),t),l(o.get(this))}:function(...t){return l(e.apply(D(this),t))}:function(t,...n){const r=e.call(D(this),t,...n);return a.set(r,t.sort?t.sort():[t]),l(r)}}function p(e){return"function"==typeof e?f(e):(e instanceof IDBTransaction&&function(e){if(s.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)});s.set(e,t)}(e),t(e,n||(n=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,u):e)}function l(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(l(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)});return t.then(t=>{t instanceof IDBCursor&&o.set(t,e)}).catch(()=>{}),c.set(t,e),t}(e);if(i.has(e))return i.get(e);const t=p(e);return t!==e&&(i.set(e,t),c.set(t,e)),t}const D=e=>c.get(e);const I=["get","getKey","getAll","getAllKeys","count"],B=["put","add","delete","clear"],v=new Map;function g(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(v.get(t))return v.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=B.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!I.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let a=s.store;r&&(a=a.index(t.shift()));const i=a[n](...t);return o&&await s.done,i};return v.set(t,s),s}d(e=>({get:(t,n,r)=>g(t,n)||e.get(t,n,r),has:(t,n)=>!!g(t,n)||e.has(t,n)}));const y=["continue","continuePrimaryKey","advance"],b={},h=new WeakMap,m=new WeakMap,w={get(e,t){if(!y.includes(t))return e[t];let n=b[t];return n||(n=b[t]=function(...e){h.set(this,m.get(this)[t](...e))}),n}};async function*E(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;t=t;const n=new Proxy(t,w);for(m.set(n,t),c.set(n,D(t));t;)yield n,t=await(h.get(n)||t.continue()),h.delete(n)}function L(e,n){return n===Symbol.asyncIterator&&t(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===n&&t(e,[IDBIndex,IDBObjectStore])}return d(e=>({get:(t,n,r)=>L(t,n)?E:e.get(t,n,r),has:(t,n)=>L(t,n)||e.has(t,n)})),e.openDB=function(e,t,{blocked:n,upgrade:r,blocking:o}={}){const s=indexedDB.open(e,t),a=l(s);return r&&s.addEventListener("upgradeneeded",e=>{r(l(s.result),e.oldVersion,e.newVersion,l(s.transaction))}),n&&s.addEventListener("blocked",()=>n()),o&&a.then(e=>e.addEventListener("versionchange",o)).catch(()=>{}),a},e.deleteDB=function(e,{blocked:t}={}){const n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",()=>t()),l(n).then(()=>void 0)},e.unwrap=D,e.wrap=l,e}({});
var idb=function(e){"use strict";const t=(e,t)=>t.some(t=>e instanceof t);let n,r;const o=new WeakMap,s=new WeakMap,a=new WeakMap,i=new WeakMap,c=new WeakMap;let u={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return s.get(e);if("objectStoreNames"===t)return e.objectStoreNames||a.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return l(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function d(e){u=e(u)}function f(e){return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(r||(r=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(D(this),t),l(o.get(this))}:function(...t){return l(e.apply(D(this),t))}:function(t,...n){const r=e.call(D(this),t,...n);return a.set(r,t.sort?t.sort():[t]),l(r)}}function p(e){return"function"==typeof e?f(e):(e instanceof IDBTransaction&&function(e){if(s.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)});s.set(e,t)}(e),t(e,n||(n=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,u):e)}function l(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(l(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)});return t.then(t=>{t instanceof IDBCursor&&o.set(t,e)}).catch(()=>{}),c.set(t,e),t}(e);if(i.has(e))return i.get(e);const t=p(e);return t!==e&&(i.set(e,t),c.set(t,e)),t}const D=e=>c.get(e);const I=["get","getKey","getAll","getAllKeys","count"],B=["put","add","delete","clear"],b=new Map;function v(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(b.get(t))return b.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=B.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!I.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let a=s.store;r&&(a=a.index(t.shift()));const i=a[n](...t);return o&&await s.done,i};return b.set(t,s),s}d(e=>({...e,get:(t,n,r)=>v(t,n)||e.get(t,n,r),has:(t,n)=>!!v(t,n)||e.has(t,n)}));const g=["continue","continuePrimaryKey","advance"],y={},h=new WeakMap,m=new WeakMap,w={get(e,t){if(!g.includes(t))return e[t];let n=y[t];return n||(n=y[t]=function(...e){h.set(this,m.get(this)[t](...e))}),n}};async function*E(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;t=t;const n=new Proxy(t,w);for(m.set(n,t),c.set(n,D(t));t;)yield n,t=await(h.get(n)||t.continue()),h.delete(n)}function L(e,n){return n===Symbol.asyncIterator&&t(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===n&&t(e,[IDBIndex,IDBObjectStore])}return d(e=>({...e,get:(t,n,r)=>L(t,n)?E:e.get(t,n,r),has:(t,n)=>L(t,n)||e.has(t,n)})),e.deleteDB=function(e,{blocked:t}={}){const n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",()=>t()),l(n).then(()=>{})},e.openDB=function(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const a=indexedDB.open(e,t),i=l(a);return r&&a.addEventListener("upgradeneeded",e=>{r(l(a.result),e.oldVersion,e.newVersion,l(a.transaction))}),n&&a.addEventListener("blocked",()=>n()),s&&a.addEventListener("close",()=>s()),o&&i.then(e=>e.addEventListener("versionchange",o)).catch(()=>{}),i},e.unwrap=D,e.wrap=l,e}({});

@@ -0,1 +1,5 @@

# Changes in 5.x
I moved some files around, so I bumped the major version for safety.
# Changes in 4.x

@@ -2,0 +6,0 @@

{
"name": "idb",
"version": "4.0.5",
"version": "5.0.0",
"description": "A small wrapper that makes IndexedDB usable",

@@ -9,5 +9,4 @@ "main": "build/cjs/index.js",

"scripts": {
"clean": "rm -rf build test-build",
"build": "npm run clean && rollup -c && gzip-size build/iife/index-min.js && gzip-size build/iife/with-async-ittr-min.js",
"dev": "npm run clean && rollup -c --watch"
"build": "rollup -c && node --experimental-modules lib/size-report.mjs",
"dev": "rollup -c --watch"
},

@@ -21,17 +20,19 @@ "repository": {

"devDependencies": {
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.6",
"@types/chai": "^4.2.7",
"@types/mocha": "^5.2.7",
"chai": "^4.2.0",
"conditional-type-checks": "^1.0.0",
"gzip-size-cli": "^3.0.0",
"mocha": "^6.0.2",
"prettier": "^1.18.2",
"rollup": "^1.6.1",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-copy": "^0.2.3",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript2": "^0.20.1",
"typescript": "^3.3.4000"
"conditional-type-checks": "^1.0.5",
"del": "^5.1.0",
"filesize": "^6.0.1",
"glob": "^7.1.6",
"mocha": "^7.0.0",
"prettier": "^1.19.1",
"rollup": "^1.29.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.1.3",
"typescript": "^3.7.4"
},
"dependencies": {
"@rollup/plugin-commonjs": "^11.0.1"
}
}
# IndexedDB with usability.
This is a tiny (~1.16k) library that mostly mirrors the IndexedDB API, but with small improvements that make a big difference to usability.
This is a tiny (~1.08k brotli'd) library that mostly mirrors the IndexedDB API, but with small improvements that make a big difference to usability.

@@ -50,3 +50,3 @@ 1. [Installation](#installation)

This is a rewrite from 3.x with substantial changes. [See details](changes.md).
[See details of (potentially) breaking changes](changes.md).

@@ -70,2 +70,5 @@ # API

},
terminated() {
// …
},
});

@@ -83,2 +86,3 @@ ```

- `blocking` (optional): Called if this connection is blocking a future version of the database from opening. This is similar to the [`versionchange` event](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/versionchange_event) in plain IndexedDB.
- `terminated` (optional): Called if the browser abnormally terminates the connection, but not on regular closures like calling `db.close()`. This is similar to the [`close` event](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/close_event) in plain IndexedDB.

@@ -236,3 +240,3 @@ ## `deleteDB`

Async iterator support isn't included by default (Edge doesn't support them). To include them, import `idb/with-async-ittr.js` instead of `idb` (this increases the library size to ~1.38k):
Async iterator support isn't included by default (Edge doesn't support them). To include them, import `idb/with-async-ittr.js` instead of `idb` (this increases the library size to ~1.3k brotli'd):

@@ -455,1 +459,11 @@ ```js

Note: Types like `IDBPDatabase` are used by TypeScript only. The implementation uses proxies under the hood.
# Building and testing
```sh
npm run build
```
This will also perform type testing.
To test, navigate to `build/test/` in a browser. You'll need to set up a [basic web server](https://www.npmjs.com/package/http-server) for this.

@@ -1,76 +0,87 @@

import typescript from 'rollup-plugin-typescript2';
import { promises as fsp } from 'fs';
import { terser } from 'rollup-plugin-terser';
import copy from 'rollup-plugin-copy';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import commonjs from '@rollup/plugin-commonjs';
import del from 'del';
const testBuild = {
plugins: [
resolve(),
commonjs({
namedExports: {
'chai': ['assert'],
import simpleTS from './lib/simple-ts';
export default async function({ watch }) {
await del('build');
const main = {
plugins: [simpleTS('test', { watch })],
input: ['src/index.ts', 'src/async-iterators.ts'],
output: [
{
dir: 'build/esm/',
format: 'esm',
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
},
}),
typescript({
tsconfig: 'test/tsconfig.json',
useTsconfigDeclarationDir: true
}),
copy({
'test/index.html': 'test-build/index.html',
}),
],
input: ['test/index.ts', 'test/main.ts', 'test/open.ts', 'test/iterate.ts'],
output: {
dir: 'test-build',
format: 'esm'
},
};
{
dir: 'build/cjs/',
format: 'cjs',
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
},
],
};
const esm = {
plugins: [typescript({ useTsconfigDeclarationDir: true })],
input: ['lib/index.ts', 'lib/async-iterators.ts'],
output: [{
dir: 'build/esm/',
format: 'esm',
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
}, {
dir: 'build/cjs/',
format: 'cjs',
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
}],
};
const iffeMin = {
input: 'build/esm/index.js',
plugins: [
terser({
compress: { ecma: 2019 },
}),
],
output: {
file: 'build/iife/index-min.js',
format: 'iife',
name: 'idb',
},
};
const iffeMin = {
input: 'build/esm/index.js',
plugins: [
terser({
compress: { ecma: 6 },
})
],
output: {
file: 'build/iife/index-min.js',
format: 'iife',
name: 'idb'
},
};
const iffeIttrMin = {
input: './with-async-ittr.js',
plugins: [
terser({
compress: { ecma: 2019 },
}),
],
output: {
file: 'build/iife/with-async-ittr-min.js',
format: 'iife',
name: 'idb',
},
};
const iffeIttrMin = {
input: './with-async-ittr.js',
plugins: [
terser({
compress: { ecma: 6 },
})
],
output: {
file: 'build/iife/with-async-ittr-min.js',
format: 'iife',
name: 'idb'
},
};
const testBuild = {
plugins: [
simpleTS('test', { noBuild: true }),
resolve(),
commonjs({
namedExports: {
chai: ['assert'],
},
}),
{
async generateBundle() {
this.emitFile({
type: 'asset',
source: await fsp.readFile('test/index.html'),
fileName: 'index.html',
});
},
},
],
input: ['test/index.ts', 'test/main.ts', 'test/open.ts', 'test/iterate.ts'],
output: {
dir: 'build/test',
format: 'esm',
},
};
export default [
testBuild, esm, iffeMin, iffeIttrMin,
];
return [main, iffeMin, iffeIttrMin, testBuild];
}

@@ -6,4 +6,4 @@ // Since this library proxies IDB, I haven't retested all of IDB. I've tried to cover parts of the

import { assert } from 'chai';
import { IDBPDatabase, IDBPCursorWithValueIteratorValue } from '../lib/';
import '../lib/async-iterators';
import { IDBPDatabase, IDBPCursorWithValueIteratorValue } from '../src/';
import '../src/async-iterators';
import { assert as typeAssert, IsExact } from 'conditional-type-checks';

@@ -10,0 +10,0 @@ import {

@@ -13,3 +13,5 @@ import 'mocha/mocha';

TypedDOMStringList,
} from '../lib/';
openDB,
DBSchema,
} from '../src/';
import { assert as typeAssert, IsExact } from 'conditional-type-checks';

@@ -22,2 +24,4 @@ import {

TestDBSchema,
getNextVersion,
dbName,
} from './utils';

@@ -44,3 +48,5 @@

typeAssert<IsExact<typeof db.objectStoreNames, DOMStringList>>(true);
typeAssert<IsExact<typeof db.objectStoreNames, TypedDOMStringList<string>>>(
true,
);
});

@@ -341,3 +347,3 @@

typeAssert<IsExact<typeof val2, any[]>>(true);
typeAssert<IsExact<typeof val2, IDBValidKey[]>>(true);

@@ -365,3 +371,3 @@ assert.deepStrictEqual(

typeAssert<IsExact<typeof val2, any[]>>(true);
typeAssert<IsExact<typeof val2, IDBValidKey[]>>(true);

@@ -696,3 +702,3 @@ assert.deepStrictEqual(val2, [1, 2, 3, 4], 'Correct values from store');

typeof schemalessStore,
IDBPObjectStore<any, ['object-store'], 'object-store'>
IDBPObjectStore<unknown, ['object-store'], 'object-store'>
>

@@ -705,2 +711,24 @@ >(true);

test('abort', async () => {
const schemaDB = await openDBWithSchema();
db = schemaDB as IDBPDatabase;
const tx = schemaDB.transaction('key-val-store');
tx.abort();
let threw = false;
let error: Error | null = null;
try {
await tx.done;
} catch (e) {
threw = true;
error = e;
}
assert(threw, 'Done threw');
assert.instanceOf(error, DOMException);
assert.strictEqual(error?.name, 'AbortError');
});
test('wrap', async () => {

@@ -742,2 +770,14 @@ const schemaDB = await openDBWithSchema();

export interface RenamedDBSchema extends DBSchema {
'key-val-store-renamed': {
key: string;
value: number;
};
'object-store': {
value: ObjectStoreValue;
key: number;
indexes: { 'date-renamed': Date; title: string };
};
}
suite('IDBPObjectStore', () => {

@@ -758,20 +798,25 @@ let db: IDBPDatabase;

typeAssert<IsExact<typeof tx.store.indexNames, ('date' | 'title')[]>>(true);
typeAssert<
IsExact<typeof tx.store.indexNames, TypedDOMStringList<'date' | 'title'>>
>(true);
typeAssert<IsExact<typeof tx2.store.indexNames, string[]>>(true);
typeAssert<
IsExact<typeof tx2.store.indexNames, TypedDOMStringList<string>>
>(true);
});
test('name', async () => {
test('set name', async () => {
const schemaDB = await openDBWithSchema();
db = schemaDB as IDBPDatabase;
schemaDB.close();
const tx = schemaDB.transaction('object-store');
const tx2 = db.transaction('object-store');
const store = db.transaction('object-store').objectStore('object-store');
const newDB = await openDB<RenamedDBSchema>(dbName, getNextVersion(), {
upgrade(db, oldVersion, newVersion, tx) {
const store = (tx as IDBPTransaction).objectStore('key-val-store');
store.name = 'key-val-store-renamed';
},
});
typeAssert<IsExact<typeof tx.store.name, 'object-store'>>(true);
db = newDB as IDBPDatabase;
typeAssert<IsExact<typeof tx2.store.name, 'object-store'>>(true);
typeAssert<IsExact<typeof store.name, 'object-store'>>(true);
assert(newDB.objectStoreNames.contains('key-val-store-renamed'));
});

@@ -1064,3 +1109,3 @@

typeAssert<IsExact<typeof val2, any[]>>(true);
typeAssert<IsExact<typeof val2, IDBValidKey[]>>(true);

@@ -1318,2 +1363,3 @@ assert.deepStrictEqual(

if (db) db.close();
await deleteDatabase();
});

@@ -1358,2 +1404,21 @@

test('set name', async () => {
const schemaDB = await openDBWithSchema();
schemaDB.close();
const newDB = await openDB<RenamedDBSchema>(dbName, getNextVersion(), {
upgrade(db, oldVersion, newVersion, tx) {
const store = (tx.objectStore(
'object-store',
) as unknown) as IDBObjectStore;
const index = store.index('date');
index.name = 'date-renamed';
},
});
db = newDB as IDBPDatabase;
const tx = newDB.transaction('object-store');
assert(tx.store.indexNames.contains('date-renamed'));
});
test('count', async () => {

@@ -1563,3 +1628,3 @@ const schemaDB = await openDBWithData();

typeAssert<IsExact<typeof val, any[]>>(true);
typeAssert<IsExact<typeof val, IDBValidKey[]>>(true);

@@ -1566,0 +1631,0 @@ assert.deepStrictEqual(val, [1, 2, 3, 4], 'Correct values from store');

import 'mocha/mocha';
import { assert } from 'chai';
import { openDB, IDBPDatabase, IDBPTransaction, wrap, unwrap } from '../lib/';
import { openDB, IDBPDatabase, IDBPTransaction, wrap, unwrap } from '../src/';
import { assert as typeAssert, IsExact } from 'conditional-type-checks';

@@ -5,0 +5,0 @@ import {

{
"extends": "../tsconfig.json",
"extends": "../generic-tsconfig.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"declarationDir": "../test-build"
"lib": ["esnext", "dom"]
},
"files": ["index.ts"]
"references": [{ "path": "../src" }]
}

@@ -7,3 +7,3 @@ import {

deleteDB,
} from '../lib/';
} from '../src/';

@@ -10,0 +10,0 @@ export interface ObjectStoreValue {

@@ -1,7 +0,2 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var index_js = require('./build/cjs/index.js');
module.exports = require('./build/cjs/index.js');
require('./build/cjs/async-iterators.js');
Object.keys(index_js).forEach(function (key) { exports[key] = index_js[key]; });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc