Socket
Socket
Sign inDemoInstall

idb-keyval

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idb-keyval - npm Package Compare versions

Comparing version 4.0.1 to 5.0.0

8

custom-stores.md

@@ -39,3 +39,3 @@ # Custom stores

A custom store in this library is just a function that takes `"readonly"` or `"readwrite"`, and returns a promise for an IDB store. Here's the implementation for `createStore`:
A custom store in this library is just a function that takes `"readonly"` or `"readwrite"`, a callback that provides an IDB store, and returns whatever that callback returns. Here's the implementation for `createStore`:

@@ -50,4 +50,6 @@ ```js

return (txMode) =>
dbp.then((db) => db.transaction(storeName, txMode).objectStore(storeName));
return (txMode, callback) =>
dbp.then((db) =>
callback(db.transaction(storeName, txMode).objectStore(storeName)),
);
}

@@ -54,0 +56,0 @@ ```

export declare function promisifyRequest<T = undefined>(request: IDBRequest<T> | IDBTransaction): Promise<T>;
export declare function createStore(dbName: string, storeName: string): (txMode: IDBTransactionMode) => Promise<IDBObjectStore>;
declare type StoreGetter = (txMode: IDBTransactionMode) => Promise<IDBObjectStore>;
export declare function createStore(dbName: string, storeName: string): UseStore;
export declare type UseStore = <T>(txMode: IDBTransactionMode, callback: (store: IDBObjectStore) => T) => T extends PromiseLike<any> ? T : Promise<T>;
/**

@@ -10,3 +10,3 @@ * Get a value by its key.

*/
export declare function get<T = any>(key: IDBValidKey, customStore?: StoreGetter): Promise<T | undefined>;
export declare function get<T = any>(key: IDBValidKey, customStore?: UseStore): Promise<T | undefined>;
/**

@@ -19,3 +19,3 @@ * Set a value with a key.

*/
export declare function set(key: IDBValidKey, value: any, customStore?: StoreGetter): Promise<void>;
export declare function set(key: IDBValidKey, value: any, customStore?: UseStore): Promise<void>;
/**

@@ -28,3 +28,3 @@ * Set multiple values at once. This is faster than calling set() multiple times.

*/
export declare function setMany(entries: [IDBValidKey, any][], customStore?: StoreGetter): Promise<void>;
export declare function setMany(entries: [IDBValidKey, any][], customStore?: UseStore): Promise<void>;
/**

@@ -36,3 +36,3 @@ * Get multiple values by their keys

*/
export declare function getMany(keys: IDBValidKey[], customStore?: StoreGetter): Promise<any[]>;
export declare function getMany(keys: IDBValidKey[], customStore?: UseStore): Promise<any[]>;
/**

@@ -45,3 +45,3 @@ * Update a value. This lets you see the old value and update it as an atomic operation.

*/
export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: StoreGetter): Promise<void>;
export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: UseStore): Promise<void>;
/**

@@ -53,3 +53,3 @@ * Delete a particular key from the store.

*/
export declare function del(key: IDBValidKey, customStore?: StoreGetter): Promise<void>;
export declare function del(key: IDBValidKey, customStore?: UseStore): Promise<void>;
/**

@@ -60,3 +60,3 @@ * Clear all values in the store.

*/
export declare function clear(customStore?: StoreGetter): Promise<void>;
export declare function clear(customStore?: UseStore): Promise<void>;
/**

@@ -67,3 +67,3 @@ * Get all keys in the store.

*/
export declare function keys(customStore?: StoreGetter): Promise<IDBValidKey[]>;
export declare function keys(customStore?: UseStore): Promise<IDBValidKey[]>;
/**

@@ -74,3 +74,3 @@ * Get all values in the store.

*/
export declare function values(customStore?: StoreGetter): Promise<IDBValidKey[]>;
export declare function values(customStore?: UseStore): Promise<IDBValidKey[]>;
/**

@@ -81,4 +81,3 @@ * Get all entries in the store. Each entry is an array of `[key, value]`.

*/
export declare function entries(customStore?: StoreGetter): Promise<[IDBValidKey, any][]>;
export {};
export declare function entries(customStore?: UseStore): Promise<[IDBValidKey, any][]>;
//# sourceMappingURL=index.d.ts.map

@@ -29,6 +29,8 @@ 'use strict';

var dbp = promisifyRequest(request);
return function (txMode) {
return dbp.then(function (db) {
return db.transaction(storeName, txMode).objectStore(storeName);
});
return function (txMode, callback) {
return (// TODO: I'm not sure why I have to cast to any here. Maybe some TypeScript expert can help?
dbp.then(function (db) {
return callback(db.transaction(storeName, txMode).objectStore(storeName));
})
);
};

@@ -56,3 +58,3 @@ }

var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
return customStore('readonly').then(function (store) {
return customStore('readonly', function (store) {
return promisifyRequest(store.get(key));

@@ -72,3 +74,3 @@ });

var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
store.put(value, key);

@@ -89,3 +91,3 @@ return promisifyRequest(store.transaction);

var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
entries.forEach(function (entry) {

@@ -107,3 +109,3 @@ return store.put(entry[1], entry[0]);

var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
return customStore('readonly').then(function (store) {
return customStore('readonly', function (store) {
return Promise.all(keys.map(function (key) {

@@ -125,3 +127,3 @@ return promisifyRequest(store.get(key));

var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
return (// Need to create the promise manually.

@@ -153,3 +155,3 @@ // If I try to chain promises, the transaction closes in browsers

var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
store.delete(key);

@@ -168,3 +170,3 @@ return promisifyRequest(store.transaction);

var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
store.clear();

@@ -176,3 +178,3 @@ return promisifyRequest(store.transaction);

function eachCursor(customStore, callback) {
return customStore('readonly').then(function (store) {
return customStore('readonly', function (store) {
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.

@@ -179,0 +181,0 @@ // And openKeyCursor isn't supported by Safari.

export declare function promisifyRequest<T = undefined>(request: IDBRequest<T> | IDBTransaction): Promise<T>;
export declare function createStore(dbName: string, storeName: string): (txMode: IDBTransactionMode) => Promise<IDBObjectStore>;
declare type StoreGetter = (txMode: IDBTransactionMode) => Promise<IDBObjectStore>;
export declare function createStore(dbName: string, storeName: string): UseStore;
export declare type UseStore = <T>(txMode: IDBTransactionMode, callback: (store: IDBObjectStore) => T) => T extends PromiseLike<any> ? T : Promise<T>;
/**

@@ -10,3 +10,3 @@ * Get a value by its key.

*/
export declare function get<T = any>(key: IDBValidKey, customStore?: StoreGetter): Promise<T | undefined>;
export declare function get<T = any>(key: IDBValidKey, customStore?: UseStore): Promise<T | undefined>;
/**

@@ -19,3 +19,3 @@ * Set a value with a key.

*/
export declare function set(key: IDBValidKey, value: any, customStore?: StoreGetter): Promise<void>;
export declare function set(key: IDBValidKey, value: any, customStore?: UseStore): Promise<void>;
/**

@@ -28,3 +28,3 @@ * Set multiple values at once. This is faster than calling set() multiple times.

*/
export declare function setMany(entries: [IDBValidKey, any][], customStore?: StoreGetter): Promise<void>;
export declare function setMany(entries: [IDBValidKey, any][], customStore?: UseStore): Promise<void>;
/**

@@ -36,3 +36,3 @@ * Get multiple values by their keys

*/
export declare function getMany(keys: IDBValidKey[], customStore?: StoreGetter): Promise<any[]>;
export declare function getMany(keys: IDBValidKey[], customStore?: UseStore): Promise<any[]>;
/**

@@ -45,3 +45,3 @@ * Update a value. This lets you see the old value and update it as an atomic operation.

*/
export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: StoreGetter): Promise<void>;
export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: UseStore): Promise<void>;
/**

@@ -53,3 +53,3 @@ * Delete a particular key from the store.

*/
export declare function del(key: IDBValidKey, customStore?: StoreGetter): Promise<void>;
export declare function del(key: IDBValidKey, customStore?: UseStore): Promise<void>;
/**

@@ -60,3 +60,3 @@ * Clear all values in the store.

*/
export declare function clear(customStore?: StoreGetter): Promise<void>;
export declare function clear(customStore?: UseStore): Promise<void>;
/**

@@ -67,3 +67,3 @@ * Get all keys in the store.

*/
export declare function keys(customStore?: StoreGetter): Promise<IDBValidKey[]>;
export declare function keys(customStore?: UseStore): Promise<IDBValidKey[]>;
/**

@@ -74,3 +74,3 @@ * Get all values in the store.

*/
export declare function values(customStore?: StoreGetter): Promise<IDBValidKey[]>;
export declare function values(customStore?: UseStore): Promise<IDBValidKey[]>;
/**

@@ -81,4 +81,3 @@ * Get all entries in the store. Each entry is an array of `[key, value]`.

*/
export declare function entries(customStore?: StoreGetter): Promise<[IDBValidKey, any][]>;
export {};
export declare function entries(customStore?: UseStore): Promise<[IDBValidKey, any][]>;
//# sourceMappingURL=index.d.ts.map

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

const dbp = promisifyRequest(request);
return (txMode) => dbp.then((db) => db.transaction(storeName, txMode).objectStore(storeName));
return (txMode, callback) =>
// TODO: I'm not sure why I have to cast to any here. Maybe some TypeScript expert can help?
dbp.then((db) => callback(db.transaction(storeName, txMode).objectStore(storeName)));
}

@@ -34,3 +36,3 @@ let defaultGetStoreFunc;

function get(key, customStore = defaultGetStore()) {
return customStore('readonly').then((store) => promisifyRequest(store.get(key)));
return customStore('readonly', (store) => promisifyRequest(store.get(key)));
}

@@ -45,3 +47,3 @@ /**

function set(key, value, customStore = defaultGetStore()) {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
store.put(value, key);

@@ -59,3 +61,3 @@ return promisifyRequest(store.transaction);

function setMany(entries, customStore = defaultGetStore()) {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
entries.forEach((entry) => store.put(entry[1], entry[0]));

@@ -72,3 +74,3 @@ return promisifyRequest(store.transaction);

function getMany(keys, customStore = defaultGetStore()) {
return customStore('readonly').then((store) => Promise.all(keys.map((key) => promisifyRequest(store.get(key)))));
return customStore('readonly', (store) => Promise.all(keys.map((key) => promisifyRequest(store.get(key)))));
}

@@ -83,3 +85,3 @@ /**

function update(key, updater, customStore = defaultGetStore()) {
return customStore('readwrite').then((store) =>
return customStore('readwrite', (store) =>
// Need to create the promise manually.

@@ -107,3 +109,3 @@ // If I try to chain promises, the transaction closes in browsers

function del(key, customStore = defaultGetStore()) {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
store.delete(key);

@@ -119,3 +121,3 @@ return promisifyRequest(store.transaction);

function clear(customStore = defaultGetStore()) {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
store.clear();

@@ -126,3 +128,3 @@ return promisifyRequest(store.transaction);

function eachCursor(customStore, callback) {
return customStore('readonly').then((store) => {
return customStore('readonly', (store) => {
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.

@@ -129,0 +131,0 @@ // And openKeyCursor isn't supported by Safari.

export declare function promisifyRequest<T = undefined>(request: IDBRequest<T> | IDBTransaction): Promise<T>;
export declare function createStore(dbName: string, storeName: string): (txMode: IDBTransactionMode) => Promise<IDBObjectStore>;
declare type StoreGetter = (txMode: IDBTransactionMode) => Promise<IDBObjectStore>;
export declare function createStore(dbName: string, storeName: string): UseStore;
export declare type UseStore = <T>(txMode: IDBTransactionMode, callback: (store: IDBObjectStore) => T) => T extends PromiseLike<any> ? T : Promise<T>;
/**

@@ -10,3 +10,3 @@ * Get a value by its key.

*/
export declare function get<T = any>(key: IDBValidKey, customStore?: StoreGetter): Promise<T | undefined>;
export declare function get<T = any>(key: IDBValidKey, customStore?: UseStore): Promise<T | undefined>;
/**

@@ -19,3 +19,3 @@ * Set a value with a key.

*/
export declare function set(key: IDBValidKey, value: any, customStore?: StoreGetter): Promise<void>;
export declare function set(key: IDBValidKey, value: any, customStore?: UseStore): Promise<void>;
/**

@@ -28,3 +28,3 @@ * Set multiple values at once. This is faster than calling set() multiple times.

*/
export declare function setMany(entries: [IDBValidKey, any][], customStore?: StoreGetter): Promise<void>;
export declare function setMany(entries: [IDBValidKey, any][], customStore?: UseStore): Promise<void>;
/**

@@ -36,3 +36,3 @@ * Get multiple values by their keys

*/
export declare function getMany(keys: IDBValidKey[], customStore?: StoreGetter): Promise<any[]>;
export declare function getMany(keys: IDBValidKey[], customStore?: UseStore): Promise<any[]>;
/**

@@ -45,3 +45,3 @@ * Update a value. This lets you see the old value and update it as an atomic operation.

*/
export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: StoreGetter): Promise<void>;
export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: UseStore): Promise<void>;
/**

@@ -53,3 +53,3 @@ * Delete a particular key from the store.

*/
export declare function del(key: IDBValidKey, customStore?: StoreGetter): Promise<void>;
export declare function del(key: IDBValidKey, customStore?: UseStore): Promise<void>;
/**

@@ -60,3 +60,3 @@ * Clear all values in the store.

*/
export declare function clear(customStore?: StoreGetter): Promise<void>;
export declare function clear(customStore?: UseStore): Promise<void>;
/**

@@ -67,3 +67,3 @@ * Get all keys in the store.

*/
export declare function keys(customStore?: StoreGetter): Promise<IDBValidKey[]>;
export declare function keys(customStore?: UseStore): Promise<IDBValidKey[]>;
/**

@@ -74,3 +74,3 @@ * Get all values in the store.

*/
export declare function values(customStore?: StoreGetter): Promise<IDBValidKey[]>;
export declare function values(customStore?: UseStore): Promise<IDBValidKey[]>;
/**

@@ -81,4 +81,3 @@ * Get all entries in the store. Each entry is an array of `[key, value]`.

*/
export declare function entries(customStore?: StoreGetter): Promise<[IDBValidKey, any][]>;
export {};
export declare function entries(customStore?: UseStore): Promise<[IDBValidKey, any][]>;
//# sourceMappingURL=index.d.ts.map

@@ -23,6 +23,8 @@ function promisifyRequest(request) {

var dbp = promisifyRequest(request);
return function (txMode) {
return dbp.then(function (db) {
return db.transaction(storeName, txMode).objectStore(storeName);
});
return function (txMode, callback) {
return (// TODO: I'm not sure why I have to cast to any here. Maybe some TypeScript expert can help?
dbp.then(function (db) {
return callback(db.transaction(storeName, txMode).objectStore(storeName));
})
);
};

@@ -50,3 +52,3 @@ }

var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
return customStore('readonly').then(function (store) {
return customStore('readonly', function (store) {
return promisifyRequest(store.get(key));

@@ -66,3 +68,3 @@ });

var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
store.put(value, key);

@@ -83,3 +85,3 @@ return promisifyRequest(store.transaction);

var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
entries.forEach(function (entry) {

@@ -101,3 +103,3 @@ return store.put(entry[1], entry[0]);

var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
return customStore('readonly').then(function (store) {
return customStore('readonly', function (store) {
return Promise.all(keys.map(function (key) {

@@ -119,3 +121,3 @@ return promisifyRequest(store.get(key));

var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
return (// Need to create the promise manually.

@@ -147,3 +149,3 @@ // If I try to chain promises, the transaction closes in browsers

var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
store.delete(key);

@@ -162,3 +164,3 @@ return promisifyRequest(store.transaction);

var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
return customStore('readwrite').then(function (store) {
return customStore('readwrite', function (store) {
store.clear();

@@ -170,3 +172,3 @@ return promisifyRequest(store.transaction);

function eachCursor(customStore, callback) {
return customStore('readonly').then(function (store) {
return customStore('readonly', function (store) {
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.

@@ -173,0 +175,0 @@ // And openKeyCursor isn't supported by Safari.

export declare function promisifyRequest<T = undefined>(request: IDBRequest<T> | IDBTransaction): Promise<T>;
export declare function createStore(dbName: string, storeName: string): (txMode: IDBTransactionMode) => Promise<IDBObjectStore>;
declare type StoreGetter = (txMode: IDBTransactionMode) => Promise<IDBObjectStore>;
export declare function createStore(dbName: string, storeName: string): UseStore;
export declare type UseStore = <T>(txMode: IDBTransactionMode, callback: (store: IDBObjectStore) => T) => T extends PromiseLike<any> ? T : Promise<T>;
/**

@@ -10,3 +10,3 @@ * Get a value by its key.

*/
export declare function get<T = any>(key: IDBValidKey, customStore?: StoreGetter): Promise<T | undefined>;
export declare function get<T = any>(key: IDBValidKey, customStore?: UseStore): Promise<T | undefined>;
/**

@@ -19,3 +19,3 @@ * Set a value with a key.

*/
export declare function set(key: IDBValidKey, value: any, customStore?: StoreGetter): Promise<void>;
export declare function set(key: IDBValidKey, value: any, customStore?: UseStore): Promise<void>;
/**

@@ -28,3 +28,3 @@ * Set multiple values at once. This is faster than calling set() multiple times.

*/
export declare function setMany(entries: [IDBValidKey, any][], customStore?: StoreGetter): Promise<void>;
export declare function setMany(entries: [IDBValidKey, any][], customStore?: UseStore): Promise<void>;
/**

@@ -36,3 +36,3 @@ * Get multiple values by their keys

*/
export declare function getMany(keys: IDBValidKey[], customStore?: StoreGetter): Promise<any[]>;
export declare function getMany(keys: IDBValidKey[], customStore?: UseStore): Promise<any[]>;
/**

@@ -45,3 +45,3 @@ * Update a value. This lets you see the old value and update it as an atomic operation.

*/
export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: StoreGetter): Promise<void>;
export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: UseStore): Promise<void>;
/**

@@ -53,3 +53,3 @@ * Delete a particular key from the store.

*/
export declare function del(key: IDBValidKey, customStore?: StoreGetter): Promise<void>;
export declare function del(key: IDBValidKey, customStore?: UseStore): Promise<void>;
/**

@@ -60,3 +60,3 @@ * Clear all values in the store.

*/
export declare function clear(customStore?: StoreGetter): Promise<void>;
export declare function clear(customStore?: UseStore): Promise<void>;
/**

@@ -67,3 +67,3 @@ * Get all keys in the store.

*/
export declare function keys(customStore?: StoreGetter): Promise<IDBValidKey[]>;
export declare function keys(customStore?: UseStore): Promise<IDBValidKey[]>;
/**

@@ -74,3 +74,3 @@ * Get all values in the store.

*/
export declare function values(customStore?: StoreGetter): Promise<IDBValidKey[]>;
export declare function values(customStore?: UseStore): Promise<IDBValidKey[]>;
/**

@@ -81,4 +81,3 @@ * Get all entries in the store. Each entry is an array of `[key, value]`.

*/
export declare function entries(customStore?: StoreGetter): Promise<[IDBValidKey, any][]>;
export {};
export declare function entries(customStore?: UseStore): Promise<[IDBValidKey, any][]>;
//# sourceMappingURL=index.d.ts.map

@@ -13,3 +13,5 @@ function promisifyRequest(request) {

const dbp = promisifyRequest(request);
return (txMode) => dbp.then((db) => db.transaction(storeName, txMode).objectStore(storeName));
return (txMode, callback) =>
// TODO: I'm not sure why I have to cast to any here. Maybe some TypeScript expert can help?
dbp.then((db) => callback(db.transaction(storeName, txMode).objectStore(storeName)));
}

@@ -30,3 +32,3 @@ let defaultGetStoreFunc;

function get(key, customStore = defaultGetStore()) {
return customStore('readonly').then((store) => promisifyRequest(store.get(key)));
return customStore('readonly', (store) => promisifyRequest(store.get(key)));
}

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

function set(key, value, customStore = defaultGetStore()) {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
store.put(value, key);

@@ -55,3 +57,3 @@ return promisifyRequest(store.transaction);

function setMany(entries, customStore = defaultGetStore()) {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
entries.forEach((entry) => store.put(entry[1], entry[0]));

@@ -68,3 +70,3 @@ return promisifyRequest(store.transaction);

function getMany(keys, customStore = defaultGetStore()) {
return customStore('readonly').then((store) => Promise.all(keys.map((key) => promisifyRequest(store.get(key)))));
return customStore('readonly', (store) => Promise.all(keys.map((key) => promisifyRequest(store.get(key)))));
}

@@ -79,3 +81,3 @@ /**

function update(key, updater, customStore = defaultGetStore()) {
return customStore('readwrite').then((store) =>
return customStore('readwrite', (store) =>
// Need to create the promise manually.

@@ -103,3 +105,3 @@ // If I try to chain promises, the transaction closes in browsers

function del(key, customStore = defaultGetStore()) {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
store.delete(key);

@@ -115,3 +117,3 @@ return promisifyRequest(store.transaction);

function clear(customStore = defaultGetStore()) {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
store.clear();

@@ -122,3 +124,3 @@ return promisifyRequest(store.transaction);

function eachCursor(customStore, callback) {
return customStore('readonly').then((store) => {
return customStore('readonly', (store) => {
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.

@@ -125,0 +127,0 @@ // And openKeyCursor isn't supported by Safari.

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

var idbKeyval=function(n){"use strict";function t(n){return new Promise((function(t,r){n.oncomplete=n.onsuccess=function(){return t(n.result)},n.onabort=n.onerror=function(){return r(n.error)}}))}function r(n,r){var e=indexedDB.open(n);e.onupgradeneeded=function(){return e.result.createObjectStore(r)};var u=t(e);return function(n){return u.then((function(t){return t.transaction(r,n).objectStore(r)}))}}var e;function u(){return e||(e=r("keyval-store","keyval")),e}function o(n,r){return n("readonly").then((function(n){return n.openCursor().onsuccess=function(){this.result&&(r(this.result),this.result.continue())},t(n.transaction)}))}return n.clear=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u();return n("readwrite").then((function(n){return n.clear(),t(n.transaction)}))},n.createStore=r,n.del=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:u();return r("readwrite").then((function(r){return r.delete(n),t(r.transaction)}))},n.entries=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u(),t=[];return o(n,(function(n){return t.push([n.key,n.value])})).then((function(){return t}))},n.get=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:u();return r("readonly").then((function(r){return t(r.get(n))}))},n.getMany=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:u();return r("readonly").then((function(r){return Promise.all(n.map((function(n){return t(r.get(n))})))}))},n.keys=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u(),t=[];return o(n,(function(n){return t.push(n.key)})).then((function(){return t}))},n.promisifyRequest=t,n.set=function(n,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:u();return e("readwrite").then((function(e){return e.put(r,n),t(e.transaction)}))},n.setMany=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:u();return r("readwrite").then((function(r){return n.forEach((function(n){return r.put(n[1],n[0])})),t(r.transaction)}))},n.update=function(n,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:u();return e("readwrite").then((function(e){return new Promise((function(u,o){e.get(n).onsuccess=function(){try{e.put(r(this.result),n),u(t(e.transaction))}catch(n){o(n)}}}))}))},n.values=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u(),t=[];return o(n,(function(n){return t.push(n.value)})).then((function(){return t}))},n}({});
var idbKeyval=function(n){"use strict";function t(n){return new Promise((function(t,r){n.oncomplete=n.onsuccess=function(){return t(n.result)},n.onabort=n.onerror=function(){return r(n.error)}}))}function r(n,r){var e=indexedDB.open(n);e.onupgradeneeded=function(){return e.result.createObjectStore(r)};var u=t(e);return function(n,t){return u.then((function(e){return t(e.transaction(r,n).objectStore(r))}))}}var e;function u(){return e||(e=r("keyval-store","keyval")),e}function o(n,r){return n("readonly",(function(n){return n.openCursor().onsuccess=function(){this.result&&(r(this.result),this.result.continue())},t(n.transaction)}))}return n.clear=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u();return n("readwrite",(function(n){return n.clear(),t(n.transaction)}))},n.createStore=r,n.del=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:u();return r("readwrite",(function(r){return r.delete(n),t(r.transaction)}))},n.entries=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u(),t=[];return o(n,(function(n){return t.push([n.key,n.value])})).then((function(){return t}))},n.get=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:u();return r("readonly",(function(r){return t(r.get(n))}))},n.getMany=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:u();return r("readonly",(function(r){return Promise.all(n.map((function(n){return t(r.get(n))})))}))},n.keys=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u(),t=[];return o(n,(function(n){return t.push(n.key)})).then((function(){return t}))},n.promisifyRequest=t,n.set=function(n,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:u();return e("readwrite",(function(e){return e.put(r,n),t(e.transaction)}))},n.setMany=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:u();return r("readwrite",(function(r){return n.forEach((function(n){return r.put(n[1],n[0])})),t(r.transaction)}))},n.update=function(n,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:u();return e("readwrite",(function(e){return new Promise((function(u,o){e.get(n).onsuccess=function(){try{e.put(r(this.result),n),u(t(e.transaction))}catch(n){o(n)}}}))}))},n.values=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u(),t=[];return o(n,(function(n){return t.push(n.value)})).then((function(){return t}))},n}({});

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

var idbKeyval=function(t){"use strict";function e(t){return new Promise(((e,n)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>n(t.error)}))}function n(t,n){const r=indexedDB.open(t);r.onupgradeneeded=()=>r.result.createObjectStore(n);const o=e(r);return t=>o.then((e=>e.transaction(n,t).objectStore(n)))}let r;function o(){return r||(r=n("keyval-store","keyval")),r}function u(t,n){return t("readonly").then((t=>(t.openCursor().onsuccess=function(){this.result&&(n(this.result),this.result.continue())},e(t.transaction))))}return t.clear=function(t=o()){return t("readwrite").then((t=>(t.clear(),e(t.transaction))))},t.createStore=n,t.del=function(t,n=o()){return n("readwrite").then((n=>(n.delete(t),e(n.transaction))))},t.entries=function(t=o()){const e=[];return u(t,(t=>e.push([t.key,t.value]))).then((()=>e))},t.get=function(t,n=o()){return n("readonly").then((n=>e(n.get(t))))},t.getMany=function(t,n=o()){return n("readonly").then((n=>Promise.all(t.map((t=>e(n.get(t)))))))},t.keys=function(t=o()){const e=[];return u(t,(t=>e.push(t.key))).then((()=>e))},t.promisifyRequest=e,t.set=function(t,n,r=o()){return r("readwrite").then((r=>(r.put(n,t),e(r.transaction))))},t.setMany=function(t,n=o()){return n("readwrite").then((n=>(t.forEach((t=>n.put(t[1],t[0]))),e(n.transaction))))},t.update=function(t,n,r=o()){return r("readwrite").then((r=>new Promise(((o,u)=>{r.get(t).onsuccess=function(){try{r.put(n(this.result),t),o(e(r.transaction))}catch(t){u(t)}}}))))},t.values=function(t=o()){const e=[];return u(t,(t=>e.push(t.value))).then((()=>e))},t}({});
var idbKeyval=function(t){"use strict";function e(t){return new Promise(((e,n)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>n(t.error)}))}function n(t,n){const r=indexedDB.open(t);r.onupgradeneeded=()=>r.result.createObjectStore(n);const o=e(r);return(t,e)=>o.then((r=>e(r.transaction(n,t).objectStore(n))))}let r;function o(){return r||(r=n("keyval-store","keyval")),r}function u(t,n){return t("readonly",(t=>(t.openCursor().onsuccess=function(){this.result&&(n(this.result),this.result.continue())},e(t.transaction))))}return t.clear=function(t=o()){return t("readwrite",(t=>(t.clear(),e(t.transaction))))},t.createStore=n,t.del=function(t,n=o()){return n("readwrite",(n=>(n.delete(t),e(n.transaction))))},t.entries=function(t=o()){const e=[];return u(t,(t=>e.push([t.key,t.value]))).then((()=>e))},t.get=function(t,n=o()){return n("readonly",(n=>e(n.get(t))))},t.getMany=function(t,n=o()){return n("readonly",(n=>Promise.all(t.map((t=>e(n.get(t)))))))},t.keys=function(t=o()){const e=[];return u(t,(t=>e.push(t.key))).then((()=>e))},t.promisifyRequest=e,t.set=function(t,n,r=o()){return r("readwrite",(r=>(r.put(n,t),e(r.transaction))))},t.setMany=function(t,n=o()){return n("readwrite",(n=>(t.forEach((t=>n.put(t[1],t[0]))),e(n.transaction))))},t.update=function(t,n,r=o()){return r("readwrite",(r=>new Promise(((o,u)=>{r.get(t).onsuccess=function(){try{r.put(n(this.result),t),o(e(r.transaction))}catch(t){u(t)}}}))))},t.values=function(t=o()){const e=[];return u(t,(t=>e.push(t.value))).then((()=>e))},t}({});
{
"name": "idb-keyval",
"version": "4.0.1",
"version": "5.0.0",
"description": "A super-simple-small keyval store built on top of IndexedDB",

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

@@ -47,3 +47,3 @@ # IDB-Keyval

```html
<script src="https://cdn.jsdelivr.net/npm/idb-keyval@4/dist/iife/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/idb-keyval@5/dist/iife/index.js"></script>
<!-- Or in modern browsers: -->

@@ -54,3 +54,3 @@ <script type="module">

set,
} from 'https://cdn.jsdelivr.net/npm/idb-keyval@4/dist/esm/index.js';
} from 'https://cdn.jsdelivr.net/npm/idb-keyval@5/dist/esm/index.js';
</script>

@@ -221,6 +221,8 @@ ```

# Updating from 3.x
### Updating from 3.x
The changes between 3.x and 4.x related to custom stores.
The changes between 3.x and 5.x related to custom stores.
(4.x was abandoned due to a Safari bug)
Old way:

@@ -247,3 +249,3 @@

# Updating from 2.x
### Updating from 2.x

@@ -250,0 +252,0 @@ 2.x exported an object with methods:

@@ -12,3 +12,3 @@ export function promisifyRequest<T = undefined>(

export function createStore(dbName: string, storeName: string) {
export function createStore(dbName: string, storeName: string): UseStore {
const request = indexedDB.open(dbName);

@@ -18,13 +18,17 @@ request.onupgradeneeded = () => request.result.createObjectStore(storeName);

return (txMode: IDBTransactionMode) =>
dbp.then((db) => db.transaction(storeName, txMode).objectStore(storeName));
return (txMode, callback) =>
// TODO: I'm not sure why I have to cast to any here. Maybe some TypeScript expert can help?
dbp.then((db) =>
callback(db.transaction(storeName, txMode).objectStore(storeName)),
) as any;
}
let defaultGetStoreFunc:
| ((txMode: IDBTransactionMode) => Promise<IDBObjectStore>)
| undefined;
export type UseStore = <T>(
txMode: IDBTransactionMode,
callback: (store: IDBObjectStore) => T,
) => T extends PromiseLike<any> ? T : Promise<T>;
type StoreGetter = (txMode: IDBTransactionMode) => Promise<IDBObjectStore>;
let defaultGetStoreFunc: UseStore | undefined;
function defaultGetStore(): StoreGetter {
function defaultGetStore() {
if (!defaultGetStoreFunc) {

@@ -46,5 +50,3 @@ defaultGetStoreFunc = createStore('keyval-store', 'keyval');

): Promise<T | undefined> {
return customStore('readonly').then((store) =>
promisifyRequest(store.get(key)),
);
return customStore('readonly', (store) => promisifyRequest(store.get(key)));
}

@@ -64,3 +66,3 @@

): Promise<void> {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
store.put(value, key);

@@ -82,3 +84,3 @@ return promisifyRequest(store.transaction);

): Promise<void> {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
entries.forEach((entry) => store.put(entry[1], entry[0]));

@@ -99,3 +101,3 @@ return promisifyRequest(store.transaction);

): Promise<any[]> {
return customStore('readonly').then((store) =>
return customStore('readonly', (store) =>
Promise.all(keys.map((key) => promisifyRequest(store.get(key)))),

@@ -117,3 +119,4 @@ );

): Promise<void> {
return customStore('readwrite').then(
return customStore(
'readwrite',
(store) =>

@@ -146,3 +149,3 @@ // Need to create the promise manually.

): Promise<void> {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
store.delete(key);

@@ -159,3 +162,3 @@ return promisifyRequest(store.transaction);

export function clear(customStore = defaultGetStore()): Promise<void> {
return customStore('readwrite').then((store) => {
return customStore('readwrite', (store) => {
store.clear();

@@ -167,6 +170,6 @@ return promisifyRequest(store.transaction);

function eachCursor(
customStore: StoreGetter,
customStore: UseStore,
callback: (cursor: IDBCursorWithValue) => void,
): Promise<void> {
return customStore('readonly').then((store) => {
return customStore('readonly', (store) => {
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.

@@ -173,0 +176,0 @@ // And openKeyCursor isn't supported by Safari.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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