Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.0-beta.1 to 4.0.0-beta.2

40

build/cjs/chunk.js

@@ -9,17 +9,12 @@ 'use strict';

function getIdbProxyableTypes() {
if (!idbProxyableTypes) {
idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction];
}
return idbProxyableTypes;
return idbProxyableTypes ||
(idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
}
// This is a function to prevent it throwing up in node environments.
function getCursorAdvanceMethods() {
if (!cursorAdvanceMethods) {
cursorAdvanceMethods = [
IDBCursor.prototype.advance,
IDBCursor.prototype.continue,
IDBCursor.prototype.continuePrimaryKey,
];
}
return cursorAdvanceMethods;
return cursorAdvanceMethods || (cursorAdvanceMethods = [
IDBCursor.prototype.advance,
IDBCursor.prototype.continue,
IDBCursor.prototype.continuePrimaryKey,
]);
}

@@ -118,7 +113,6 @@ const cursorRequestMap = new WeakMap();

if (func === IDBDatabase.prototype.transaction &&
!('objectStoreNames' in IDBTransaction.prototype)) {
'objectStoreNames' in IDBTransaction.prototype) {
return function (storeNames, ...args) {
const originalDb = unwrap(this);
const tx = func.call(originalDb, storeNames, ...args);
transactionStoreNamesMap.set(tx, Array.isArray(storeNames) ? storeNames.sort() : [storeNames]);
const tx = func.call(unwrap(this), storeNames, ...args);
transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
return wrap(tx);

@@ -136,6 +130,4 @@ };

// the original object.
const originalCursor = unwrap(this);
func.apply(originalCursor, args);
const request = cursorRequestMap.get(this);
return wrap(request);
func.apply(unwrap(this), args);
return wrap(cursorRequestMap.get(this));
};

@@ -146,5 +138,3 @@ }

// the original object.
const originalParent = unwrap(this);
const value = func.apply(originalParent, args);
return wrap(value);
return wrap(func.apply(unwrap(this), args));
};

@@ -182,5 +172,3 @@ }

}
function unwrap(value) {
return reverseTransformCache.get(value);
}
const unwrap = (value) => reverseTransformCache.get(value);

@@ -187,0 +175,0 @@ exports.wrap = wrap;

@@ -14,4 +14,3 @@ 'use strict';

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

@@ -35,4 +34,3 @@ const openPromise = __chunk_1.wrap(request);

*/
function deleteDB(name, callbacks = {}) {
const { blocked } = callbacks;
function deleteDB(name, { blocked } = {}) {
const request = indexedDB.deleteDatabase(name);

@@ -52,5 +50,4 @@ if (blocked)

return;
const cachedMethod = cachedMethods.get(prop);
if (cachedMethod)
return cachedMethod;
if (cachedMethods.get(prop))
return cachedMethods.get(prop);
const targetFuncName = prop.replace(/FromIndex$/, '');

@@ -65,4 +62,3 @@ const useIndex = prop !== targetFuncName;

method = function (storeName, ...args) {
const tx = this.transaction(storeName);
let target = tx.store;
let target = this.transaction(storeName).store;
if (useIndex)

@@ -85,8 +81,4 @@ target = target.index(args.shift());

__chunk_1.addTraps(oldTraps => ({
get(target, prop, receiver) {
return getMethod(target, prop) || oldTraps.get(target, prop, receiver);
},
has(target, prop) {
return !!getMethod(target, prop) || oldTraps.has(target, prop);
},
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
}));

@@ -93,0 +85,0 @@

@@ -7,17 +7,12 @@ const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);

function getIdbProxyableTypes() {
if (!idbProxyableTypes) {
idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction];
}
return idbProxyableTypes;
return idbProxyableTypes ||
(idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
}
// This is a function to prevent it throwing up in node environments.
function getCursorAdvanceMethods() {
if (!cursorAdvanceMethods) {
cursorAdvanceMethods = [
IDBCursor.prototype.advance,
IDBCursor.prototype.continue,
IDBCursor.prototype.continuePrimaryKey,
];
}
return cursorAdvanceMethods;
return cursorAdvanceMethods || (cursorAdvanceMethods = [
IDBCursor.prototype.advance,
IDBCursor.prototype.continue,
IDBCursor.prototype.continuePrimaryKey,
]);
}

@@ -116,7 +111,6 @@ const cursorRequestMap = new WeakMap();

if (func === IDBDatabase.prototype.transaction &&
!('objectStoreNames' in IDBTransaction.prototype)) {
'objectStoreNames' in IDBTransaction.prototype) {
return function (storeNames, ...args) {
const originalDb = unwrap(this);
const tx = func.call(originalDb, storeNames, ...args);
transactionStoreNamesMap.set(tx, Array.isArray(storeNames) ? storeNames.sort() : [storeNames]);
const tx = func.call(unwrap(this), storeNames, ...args);
transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
return wrap(tx);

@@ -134,6 +128,4 @@ };

// the original object.
const originalCursor = unwrap(this);
func.apply(originalCursor, args);
const request = cursorRequestMap.get(this);
return wrap(request);
func.apply(unwrap(this), args);
return wrap(cursorRequestMap.get(this));
};

@@ -144,5 +136,3 @@ }

// the original object.
const originalParent = unwrap(this);
const value = func.apply(originalParent, args);
return wrap(value);
return wrap(func.apply(unwrap(this), args));
};

@@ -180,6 +170,4 @@ }

}
function unwrap(value) {
return reverseTransformCache.get(value);
}
const unwrap = (value) => reverseTransformCache.get(value);
export { wrap as a, addTraps as b, instanceOfAny as c, reverseTransformCache as d, unwrap as e };

@@ -30,3 +30,3 @@ export interface OpenDBCallbacks<DBTypes extends DBSchema | unknown> {

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

@@ -43,3 +43,3 @@ /**

*/
export declare function deleteDB(name: string, callbacks?: DeleteDBCallbacks): Promise<void>;
export declare function deleteDB(name: string, { blocked }?: DeleteDBCallbacks): Promise<void>;
export { unwrap, wrap } from './wrap-idb-value';

@@ -46,0 +46,0 @@ declare type KnownKeys<T> = {

@@ -11,4 +11,3 @@ import { a as wrap, b as addTraps } from './chunk.js';

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

@@ -32,4 +31,3 @@ const openPromise = wrap(request);

*/
function deleteDB(name, callbacks = {}) {
const { blocked } = callbacks;
function deleteDB(name, { blocked } = {}) {
const request = indexedDB.deleteDatabase(name);

@@ -49,5 +47,4 @@ if (blocked)

return;
const cachedMethod = cachedMethods.get(prop);
if (cachedMethod)
return cachedMethod;
if (cachedMethods.get(prop))
return cachedMethods.get(prop);
const targetFuncName = prop.replace(/FromIndex$/, '');

@@ -62,4 +59,3 @@ const useIndex = prop !== targetFuncName;

method = function (storeName, ...args) {
const tx = this.transaction(storeName);
let target = tx.store;
let target = this.transaction(storeName).store;
if (useIndex)

@@ -82,10 +78,6 @@ target = target.index(args.shift());

addTraps(oldTraps => ({
get(target, prop, receiver) {
return getMethod(target, prop) || oldTraps.get(target, prop, receiver);
},
has(target, prop) {
return !!getMethod(target, prop) || oldTraps.has(target, prop);
},
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
}));
export { openDB, deleteDB };

@@ -22,10 +22,14 @@ import { IDBPCursor, IDBPCursorWithValue, IDBPDatabase, IDBPIndex, IDBPObjectStore, IDBPTransaction } from './entry';

*/
export declare function unwrap(value: IDBPCursorWithValue<any, any, any, any>): IDBCursorWithValue;
export declare function unwrap(value: IDBPCursor<any, any, any, any>): IDBCursor;
export declare function unwrap(value: IDBPDatabase): IDBDatabase;
export declare function unwrap(value: IDBPIndex<any, any, any, any>): IDBIndex;
export declare function unwrap(value: IDBPObjectStore<any, any, any>): IDBObjectStore;
export declare function unwrap(value: IDBPTransaction<any, any>): IDBTransaction;
export declare function unwrap<T extends any>(value: Promise<IDBPDatabase<T>>): IDBOpenDBRequest;
export declare function unwrap(value: Promise<IDBPDatabase>): IDBOpenDBRequest;
export declare function unwrap<T>(value: Promise<T>): IDBRequest<T>;
interface Unwrap {
(value: IDBPCursorWithValue<any, any, any, any>): IDBCursorWithValue;
(value: IDBPCursor<any, any, any, any>): IDBCursor;
(value: IDBPDatabase): IDBDatabase;
(value: IDBPIndex<any, any, any, any>): IDBIndex;
(value: IDBPObjectStore<any, any, any>): IDBObjectStore;
(value: IDBPTransaction<any, any>): IDBTransaction;
<T extends any>(value: Promise<IDBPDatabase<T>>): IDBOpenDBRequest;
(value: Promise<IDBPDatabase>): IDBOpenDBRequest;
<T>(value: Promise<T>): IDBRequest<T>;
}
export declare const unwrap: Unwrap;
export {};

@@ -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,i=new WeakMap,a=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||i.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]),r).includes(e)?function(...t){const n=l(this);return e.apply(n,t),p(o.get(this))}:function(...t){const n=l(this);return p(e.apply(n,t))}:function(t,...n){const r=l(this),o=e.call(r,t,...n);return i.set(o,Array.isArray(t)?t.sort():[t]),p(o)}}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]),n))?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)}),c.set(t,e),t}(e);if(a.has(e))return a.get(e);const t=f(e);return t!==e&&(a.set(e,t),c.set(t,e)),t}function l(e){return 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;const n=B.get(t);if(n)return n;const r=t.replace(/FromIndex$/,""),o=t!==r;if(!(r in(o?IDBIndex:IDBObjectStore).prototype))return;let s;return D.includes(r)&&(s=function(e,...t){let n=this.transaction(e).store;return o&&(n=n.index(t.shift())),n[r](...t)}),v.includes(r)&&(s=function(e,...t){const n=this.transaction(e,"readwrite");return n.store[r](...t),n.done}),s&&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,n={}){const{blocked:r,upgrade:o,blocking:s}=n,i=indexedDB.open(e,t),a=p(i);return o&&i.addEventListener("upgradeneeded",e=>{o(p(i.result),e.oldVersion,e.newVersion,p(i.transaction))}),r&&i.addEventListener("blocked",()=>r()),s&&a.then(e=>e.addEventListener("versionchange",s)),a},e.deleteDB=function(e,t={}){const{blocked:n}=t,r=indexedDB.deleteDatabase(e);return n&&r.addEventListener("blocked",()=>n()),p(r).then(()=>void 0)},e.unwrap=l,e.wrap=p,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,i=new WeakMap,a=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||i.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?function(t,...n){const r=e.call(l(this),t,...n);return i.set(r,t.sort?t.sort():[t]),p(r)}:(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 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)}),c.set(t,e),t}(e);if(a.has(e))return a.get(e);const t=f(e);return t!==e&&(a.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;if(!(n in(r?IDBIndex:IDBObjectStore).prototype))return;let o;return D.includes(n)&&(o=function(e,...t){let o=this.transaction(e).store;return r&&(o=o.index(t.shift())),o[n](...t)}),v.includes(n)&&(o=function(e,...t){const r=this.transaction(e,"readwrite");return r.store[n](...t),r.done}),o&&B.set(t,o),o}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),i=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&&i.then(e=>e.addEventListener("versionchange",o)),i},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}({});

@@ -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,i=new WeakMap,a=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||i.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]),r).includes(e)?function(...t){const n=D(this);return e.apply(n,t),l(o.get(this))}:function(...t){const n=D(this);return l(e.apply(n,t))}:function(t,...n){const r=D(this),o=e.call(r,t,...n);return i.set(o,Array.isArray(t)?t.sort():[t]),l(o)}}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]),n))?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)}),c.set(t,e),t}(e);if(a.has(e))return a.get(e);const t=p(e);return t!==e&&(a.set(e,t),c.set(t,e)),t}function D(e){return c.get(e)}const I=["get","getKey","getAll","getAllKeys","count"],B=["put","add","delete","clear"],v=new Map;function y(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;const n=v.get(t);if(n)return n;const r=t.replace(/FromIndex$/,""),o=t!==r;if(!(r in(o?IDBIndex:IDBObjectStore).prototype))return;let s;return I.includes(r)&&(s=function(e,...t){let n=this.transaction(e).store;return o&&(n=n.index(t.shift())),n[r](...t)}),B.includes(r)&&(s=function(e,...t){const n=this.transaction(e,"readwrite");return n.store[r](...t),n.done}),s&&v.set(t,s),s}d(e=>({get:(t,n,r)=>y(t,n)||e.get(t,n,r),has:(t,n)=>!!y(t,n)||e.has(t,n)}));const b=["continue","continuePrimaryKey","advance"],g={},h=new WeakMap,m=new WeakMap,w={get(e,t){if(!b.includes(t))return e[t];let n=g[t];return n||(n=g[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,n={}){const{blocked:r,upgrade:o,blocking:s}=n,i=indexedDB.open(e,t),a=l(i);return o&&i.addEventListener("upgradeneeded",e=>{o(l(i.result),e.oldVersion,e.newVersion,l(i.transaction))}),r&&i.addEventListener("blocked",()=>r()),s&&a.then(e=>e.addEventListener("versionchange",s)),a},e.deleteDB=function(e,t={}){const{blocked:n}=t,r=indexedDB.deleteDatabase(e);return n&&r.addEventListener("blocked",()=>n()),l(r).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,i=new WeakMap,a=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||i.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?function(t,...n){const r=e.call(D(this),t,...n);return i.set(r,t.sort?t.sort():[t]),l(r)}:(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 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)}),c.set(t,e),t}(e);if(a.has(e))return a.get(e);const t=p(e);return t!==e&&(a.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;if(!(n in(r?IDBIndex:IDBObjectStore).prototype))return;let o;return I.includes(n)&&(o=function(e,...t){let o=this.transaction(e).store;return r&&(o=o.index(t.shift())),o[n](...t)}),B.includes(n)&&(o=function(e,...t){const r=this.transaction(e,"readwrite");return r.store[n](...t),r.done}),o&&v.set(t,o),o}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 b=["continue","continuePrimaryKey","advance"],y={},h=new WeakMap,m=new WeakMap,w={get(e,t){if(!b.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=>({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),i=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&&i.then(e=>e.addEventListener("versionchange",o)),i},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}({});

@@ -7,3 +7,2 @@ import { Func } from './util';

const writeMethods = ['put', 'add', 'delete', 'clear'];
const cachedMethods = new Map<string, Func>();

@@ -18,4 +17,3 @@

const cachedMethod = cachedMethods.get(prop);
if (cachedMethod) return cachedMethod;
if (cachedMethods.get(prop)) return cachedMethods.get(prop);

@@ -34,6 +32,4 @@ const targetFuncName: string = prop.replace(/FromIndex$/, '');

method = function (this: IDBPDatabase, storeName: string, ...args: any[]) {
const tx = this.transaction(storeName);
let target: IDBPObjectStore | IDBPIndex = tx.store;
let target: IDBPObjectStore | IDBPIndex = this.transaction(storeName).store;
if (useIndex) target = target.index(args.shift());
return (target as any)[targetFuncName](...args);

@@ -55,8 +51,4 @@ };

addTraps(oldTraps => ({
get(target, prop, receiver) {
return getMethod(target, prop) || oldTraps.get!(target, prop, receiver);
},
has(target, prop) {
return !!getMethod(target, prop) || oldTraps.has!(target, prop);
},
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get!(target, prop, receiver),
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has!(target, prop),
}));

@@ -39,5 +39,4 @@ import { wrap } from './wrap-idb-value';

export function openDB<DBTypes extends DBSchema | unknown = unknown>(
name: string, version: number, callbacks: OpenDBCallbacks<DBTypes> = {},
name: string, version: number, { blocked, upgrade, blocking }: OpenDBCallbacks<DBTypes> = {},
): Promise<IDBPDatabase<DBTypes>> {
const { blocked, upgrade, blocking } = callbacks;
const request = indexedDB.open(name, version);

@@ -75,4 +74,3 @@ const openPromise = wrap(request) as Promise<IDBPDatabase<DBTypes>>;

*/
export function deleteDB(name: string, callbacks: DeleteDBCallbacks = {}): Promise<void> {
const { blocked } = callbacks;
export function deleteDB(name: string, { blocked }: DeleteDBCallbacks = {}): Promise<void> {
const request = indexedDB.deleteDatabase(name);

@@ -79,0 +77,0 @@ if (blocked) request.addEventListener('blocked', () => blocked());

@@ -11,6 +11,4 @@ import {

function getIdbProxyableTypes(): Constructor[] {
if (!idbProxyableTypes) {
idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction];
}
return idbProxyableTypes;
return idbProxyableTypes ||
(idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
}

@@ -20,10 +18,7 @@

function getCursorAdvanceMethods(): Func[] {
if (!cursorAdvanceMethods) {
cursorAdvanceMethods = [
IDBCursor.prototype.advance,
IDBCursor.prototype.continue,
IDBCursor.prototype.continuePrimaryKey,
];
}
return cursorAdvanceMethods;
return cursorAdvanceMethods || (cursorAdvanceMethods = [
IDBCursor.prototype.advance,
IDBCursor.prototype.continue,
IDBCursor.prototype.continuePrimaryKey,
]);
}

@@ -134,10 +129,9 @@

func === IDBDatabase.prototype.transaction &&
!('objectStoreNames' in IDBTransaction.prototype)
'objectStoreNames' in IDBTransaction.prototype
) {
return function (this: IDBPDatabase, storeNames: string | string[], ...args: any[]) {
const originalDb = unwrap(this);
const tx = func.call(originalDb, storeNames, ...args);
const tx = func.call(unwrap(this), storeNames, ...args);
transactionStoreNamesMap.set(
tx,
Array.isArray(storeNames) ? storeNames.sort() : [storeNames],
(storeNames as any).sort ? (storeNames as any[]).sort() : [storeNames],
);

@@ -157,6 +151,4 @@ return wrap(tx);

// the original object.
const originalCursor = unwrap(this);
func.apply(originalCursor, args);
const request = cursorRequestMap.get(this)!;
return wrap(request);
func.apply(unwrap(this), args);
return wrap(cursorRequestMap.get(this)!);
};

@@ -168,5 +160,3 @@ }

// the original object.
const originalParent = unwrap(this);
const value = func.apply(originalParent, args);
return wrap(value);
return wrap(func.apply(unwrap(this), args));
};

@@ -226,13 +216,13 @@ }

*/
export function unwrap(value: IDBPCursorWithValue<any, any, any, any>): IDBCursorWithValue;
export function unwrap(value: IDBPCursor<any, any, any, any>): IDBCursor;
export function unwrap(value: IDBPDatabase): IDBDatabase;
export function unwrap(value: IDBPIndex<any, any, any, any>): IDBIndex;
export function unwrap(value: IDBPObjectStore<any, any, any>): IDBObjectStore;
export function unwrap(value: IDBPTransaction<any, any>): IDBTransaction;
export function unwrap<T extends any>(value: Promise<IDBPDatabase<T>>): IDBOpenDBRequest;
export function unwrap(value: Promise<IDBPDatabase>): IDBOpenDBRequest;
export function unwrap<T>(value: Promise<T>): IDBRequest<T>;
export function unwrap(value: any): any {
return reverseTransformCache.get(value);
interface Unwrap {
(value: IDBPCursorWithValue<any, any, any, any>): IDBCursorWithValue;
(value: IDBPCursor<any, any, any, any>): IDBCursor;
(value: IDBPDatabase): IDBDatabase;
(value: IDBPIndex<any, any, any, any>): IDBIndex;
(value: IDBPObjectStore<any, any, any>): IDBObjectStore;
(value: IDBPTransaction<any, any>): IDBTransaction;
<T extends any>(value: Promise<IDBPDatabase<T>>): IDBOpenDBRequest;
(value: Promise<IDBPDatabase>): IDBOpenDBRequest;
<T>(value: Promise<T>): IDBRequest<T>;
}
export const unwrap: Unwrap = (value: any): any => reverseTransformCache.get(value);
{
"name": "idb",
"version": "4.0.0-beta.1",
"version": "4.0.0-beta.2",
"description": "A small wrapper that makes IndexedDB usable",

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

# IndexedDB with usability.
This is a tiny (~1.17k) library that mostly mirrors the IndexedDB API, but with small improvements that make a big difference to usability.
This is a tiny (~1.13k) library that mostly mirrors the IndexedDB API, but with small improvements that make a big difference to usability.

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

Async iterator support isn't included by default (Edge doesn't support them). To include them, import `idb/with-async-ittr.js` (~1.4k) instead of `idb`:
Async iterator support isn't included by default (Edge doesn't support them). To include them, import `idb/with-async-ittr.js` (~1.37k) instead of `idb`:

@@ -181,0 +181,0 @@ ```js

@@ -83,2 +83,5 @@ import typescript from 'rollup-plugin-typescript2';

export default [testBuild, esm, iffeMin, iffeIttrMin, cjsAsyncIttrEntry];
export default [
testBuild,
esm, iffeMin, iffeIttrMin, cjsAsyncIttrEntry
];
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