+269
@@ -0,0 +1,269 @@
|
||||
'use strict';
|
||||
|
||||
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
||||
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
||||
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
||||
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
||||
function promisifyRequest(request) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
// @ts-ignore - file size hacks
|
||||
request.oncomplete = request.onsuccess = function () {
|
||||
return resolve(request.result);
|
||||
};
|
||||
// @ts-ignore - file size hacks
|
||||
request.onabort = request.onerror = function () {
|
||||
return reject(request.error);
|
||||
};
|
||||
});
|
||||
}
|
||||
function createStore(dbName, storeName) {
|
||||
var dbp;
|
||||
var getDB = function getDB() {
|
||||
if (dbp) return dbp;
|
||||
var request = indexedDB.open(dbName);
|
||||
request.onupgradeneeded = function () {
|
||||
return request.result.createObjectStore(storeName);
|
||||
};
|
||||
dbp = promisifyRequest(request);
|
||||
dbp.then(function (db) {
|
||||
// It seems like Safari sometimes likes to just close the connection.
|
||||
// It's supposed to fire this event when that happens. Let's hope it does!
|
||||
db.onclose = function () {
|
||||
return dbp = undefined;
|
||||
};
|
||||
}, function () {
|
||||
dbp = undefined;
|
||||
});
|
||||
return dbp;
|
||||
};
|
||||
return function (txMode, callback) {
|
||||
return getDB().then(function (db) {
|
||||
return callback(db.transaction(storeName, txMode).objectStore(storeName));
|
||||
});
|
||||
};
|
||||
}
|
||||
var defaultGetStoreFunc;
|
||||
function defaultGetStore() {
|
||||
if (!defaultGetStoreFunc) {
|
||||
defaultGetStoreFunc = createStore('keyval-store', 'keyval');
|
||||
}
|
||||
return defaultGetStoreFunc;
|
||||
}
|
||||
/**
|
||||
* Get a value by its key.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function get(key) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
return promisifyRequest(store.get(key));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Set a value with a key.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function set(key, value) {
|
||||
var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
store.put(value, key);
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Set multiple values at once. This is faster than calling set() multiple times.
|
||||
* It's also atomic – if one of the pairs can't be added, none will be added.
|
||||
*
|
||||
* @param entries Array of entries, where each entry is an array of `[key, value]`.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function setMany(entries) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
entries.forEach(function (entry) {
|
||||
return store.put(entry[1], entry[0]);
|
||||
});
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get multiple values by their keys
|
||||
*
|
||||
* @param keys
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function getMany(keys) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
return Promise.all(keys.map(function (key) {
|
||||
return promisifyRequest(store.get(key));
|
||||
}));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Update a value. This lets you see the old value and update it as an atomic operation.
|
||||
*
|
||||
* @param key
|
||||
* @param updater A callback that takes the old value and returns a new value.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function update(key, updater) {
|
||||
var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
return (
|
||||
// Need to create the promise manually.
|
||||
// If I try to chain promises, the transaction closes in browsers
|
||||
// that use a promise polyfill (IE10/11).
|
||||
new Promise(function (resolve, reject) {
|
||||
var req = store.get(key);
|
||||
req.onsuccess = function () {
|
||||
try {
|
||||
store.put(updater(req.result), key);
|
||||
resolve(promisifyRequest(store.transaction));
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
req.onerror = function () {
|
||||
return reject(req.error);
|
||||
};
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete a particular key from the store.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function del(key) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
store.delete(key);
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete multiple keys at once.
|
||||
*
|
||||
* @param keys List of keys to delete.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function delMany(keys) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
keys.forEach(function (key) {
|
||||
return store.delete(key);
|
||||
});
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Clear all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function clear() {
|
||||
var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
store.clear();
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
function eachCursor(store, callback) {
|
||||
store.openCursor().onsuccess = function () {
|
||||
if (!this.result) return;
|
||||
callback(this.result);
|
||||
this.result.continue();
|
||||
};
|
||||
return promisifyRequest(store.transaction);
|
||||
}
|
||||
/**
|
||||
* Get all keys in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function keys() {
|
||||
var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
// Fast path for modern browsers
|
||||
if (store.getAllKeys) {
|
||||
return promisifyRequest(store.getAllKeys());
|
||||
}
|
||||
var items = [];
|
||||
return eachCursor(store, function (cursor) {
|
||||
return items.push(cursor.key);
|
||||
}).then(function () {
|
||||
return items;
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function values() {
|
||||
var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
// Fast path for modern browsers
|
||||
if (store.getAll) {
|
||||
return promisifyRequest(store.getAll());
|
||||
}
|
||||
var items = [];
|
||||
return eachCursor(store, function (cursor) {
|
||||
return items.push(cursor.value);
|
||||
}).then(function () {
|
||||
return items;
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get all entries in the store. Each entry is an array of `[key, value]`.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function entries() {
|
||||
var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
// Fast path for modern browsers
|
||||
// (although, hopefully we'll get a simpler path some day)
|
||||
if (store.getAll && store.getAllKeys) {
|
||||
return Promise.all([promisifyRequest(store.getAllKeys()), promisifyRequest(store.getAll())]).then(function (_ref) {
|
||||
var _ref2 = _slicedToArray(_ref, 2),
|
||||
keys = _ref2[0],
|
||||
values = _ref2[1];
|
||||
return keys.map(function (key, i) {
|
||||
return [key, values[i]];
|
||||
});
|
||||
});
|
||||
}
|
||||
var items = [];
|
||||
return eachCursor(store, function (cursor) {
|
||||
return items.push([cursor.key, cursor.value]);
|
||||
}).then(function () {
|
||||
return items;
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.clear = clear;
|
||||
exports.createStore = createStore;
|
||||
exports.del = del;
|
||||
exports.delMany = delMany;
|
||||
exports.entries = entries;
|
||||
exports.get = get;
|
||||
exports.getMany = getMany;
|
||||
exports.keys = keys;
|
||||
exports.promisifyRequest = promisifyRequest;
|
||||
exports.set = set;
|
||||
exports.setMany = setMany;
|
||||
exports.update = update;
|
||||
exports.values = values;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export * from './';
|
||||
+255
@@ -0,0 +1,255 @@
|
||||
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
||||
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
||||
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
||||
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
||||
function promisifyRequest(request) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
// @ts-ignore - file size hacks
|
||||
request.oncomplete = request.onsuccess = function () {
|
||||
return resolve(request.result);
|
||||
};
|
||||
// @ts-ignore - file size hacks
|
||||
request.onabort = request.onerror = function () {
|
||||
return reject(request.error);
|
||||
};
|
||||
});
|
||||
}
|
||||
function createStore(dbName, storeName) {
|
||||
var dbp;
|
||||
var getDB = function getDB() {
|
||||
if (dbp) return dbp;
|
||||
var request = indexedDB.open(dbName);
|
||||
request.onupgradeneeded = function () {
|
||||
return request.result.createObjectStore(storeName);
|
||||
};
|
||||
dbp = promisifyRequest(request);
|
||||
dbp.then(function (db) {
|
||||
// It seems like Safari sometimes likes to just close the connection.
|
||||
// It's supposed to fire this event when that happens. Let's hope it does!
|
||||
db.onclose = function () {
|
||||
return dbp = undefined;
|
||||
};
|
||||
}, function () {
|
||||
dbp = undefined;
|
||||
});
|
||||
return dbp;
|
||||
};
|
||||
return function (txMode, callback) {
|
||||
return getDB().then(function (db) {
|
||||
return callback(db.transaction(storeName, txMode).objectStore(storeName));
|
||||
});
|
||||
};
|
||||
}
|
||||
var defaultGetStoreFunc;
|
||||
function defaultGetStore() {
|
||||
if (!defaultGetStoreFunc) {
|
||||
defaultGetStoreFunc = createStore('keyval-store', 'keyval');
|
||||
}
|
||||
return defaultGetStoreFunc;
|
||||
}
|
||||
/**
|
||||
* Get a value by its key.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function get(key) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
return promisifyRequest(store.get(key));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Set a value with a key.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function set(key, value) {
|
||||
var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
store.put(value, key);
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Set multiple values at once. This is faster than calling set() multiple times.
|
||||
* It's also atomic – if one of the pairs can't be added, none will be added.
|
||||
*
|
||||
* @param entries Array of entries, where each entry is an array of `[key, value]`.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function setMany(entries) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
entries.forEach(function (entry) {
|
||||
return store.put(entry[1], entry[0]);
|
||||
});
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get multiple values by their keys
|
||||
*
|
||||
* @param keys
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function getMany(keys) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
return Promise.all(keys.map(function (key) {
|
||||
return promisifyRequest(store.get(key));
|
||||
}));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Update a value. This lets you see the old value and update it as an atomic operation.
|
||||
*
|
||||
* @param key
|
||||
* @param updater A callback that takes the old value and returns a new value.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function update(key, updater) {
|
||||
var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
return (
|
||||
// Need to create the promise manually.
|
||||
// If I try to chain promises, the transaction closes in browsers
|
||||
// that use a promise polyfill (IE10/11).
|
||||
new Promise(function (resolve, reject) {
|
||||
var req = store.get(key);
|
||||
req.onsuccess = function () {
|
||||
try {
|
||||
store.put(updater(req.result), key);
|
||||
resolve(promisifyRequest(store.transaction));
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
req.onerror = function () {
|
||||
return reject(req.error);
|
||||
};
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete a particular key from the store.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function del(key) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
store.delete(key);
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete multiple keys at once.
|
||||
*
|
||||
* @param keys List of keys to delete.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function delMany(keys) {
|
||||
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
keys.forEach(function (key) {
|
||||
return store.delete(key);
|
||||
});
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Clear all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function clear() {
|
||||
var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
|
||||
return customStore('readwrite', function (store) {
|
||||
store.clear();
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
function eachCursor(store, callback) {
|
||||
store.openCursor().onsuccess = function () {
|
||||
if (!this.result) return;
|
||||
callback(this.result);
|
||||
this.result.continue();
|
||||
};
|
||||
return promisifyRequest(store.transaction);
|
||||
}
|
||||
/**
|
||||
* Get all keys in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function keys() {
|
||||
var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
// Fast path for modern browsers
|
||||
if (store.getAllKeys) {
|
||||
return promisifyRequest(store.getAllKeys());
|
||||
}
|
||||
var items = [];
|
||||
return eachCursor(store, function (cursor) {
|
||||
return items.push(cursor.key);
|
||||
}).then(function () {
|
||||
return items;
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function values() {
|
||||
var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
// Fast path for modern browsers
|
||||
if (store.getAll) {
|
||||
return promisifyRequest(store.getAll());
|
||||
}
|
||||
var items = [];
|
||||
return eachCursor(store, function (cursor) {
|
||||
return items.push(cursor.value);
|
||||
}).then(function () {
|
||||
return items;
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get all entries in the store. Each entry is an array of `[key, value]`.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function entries() {
|
||||
var customStore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultGetStore();
|
||||
return customStore('readonly', function (store) {
|
||||
// Fast path for modern browsers
|
||||
// (although, hopefully we'll get a simpler path some day)
|
||||
if (store.getAll && store.getAllKeys) {
|
||||
return Promise.all([promisifyRequest(store.getAllKeys()), promisifyRequest(store.getAll())]).then(function (_ref) {
|
||||
var _ref2 = _slicedToArray(_ref, 2),
|
||||
keys = _ref2[0],
|
||||
values = _ref2[1];
|
||||
return keys.map(function (key, i) {
|
||||
return [key, values[i]];
|
||||
});
|
||||
});
|
||||
}
|
||||
var items = [];
|
||||
return eachCursor(store, function (cursor) {
|
||||
return items.push([cursor.key, cursor.value]);
|
||||
}).then(function () {
|
||||
return items;
|
||||
});
|
||||
});
|
||||
}
|
||||
export { clear, createStore, del, delMany, entries, get, getMany, keys, promisifyRequest, set, setMany, update, values };
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
'use strict';
|
||||
|
||||
function promisifyRequest(request) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// @ts-ignore - file size hacks
|
||||
request.oncomplete = request.onsuccess = () => resolve(request.result);
|
||||
// @ts-ignore - file size hacks
|
||||
request.onabort = request.onerror = () => reject(request.error);
|
||||
});
|
||||
}
|
||||
function createStore(dbName, storeName) {
|
||||
let dbp;
|
||||
const getDB = () => {
|
||||
if (dbp)
|
||||
return dbp;
|
||||
const request = indexedDB.open(dbName);
|
||||
request.onupgradeneeded = () => request.result.createObjectStore(storeName);
|
||||
dbp = promisifyRequest(request);
|
||||
dbp.then((db) => {
|
||||
// It seems like Safari sometimes likes to just close the connection.
|
||||
// It's supposed to fire this event when that happens. Let's hope it does!
|
||||
db.onclose = () => (dbp = undefined);
|
||||
}, () => {
|
||||
dbp = undefined;
|
||||
});
|
||||
return dbp;
|
||||
};
|
||||
return (txMode, callback) => getDB().then((db) => callback(db.transaction(storeName, txMode).objectStore(storeName)));
|
||||
}
|
||||
let defaultGetStoreFunc;
|
||||
function defaultGetStore() {
|
||||
if (!defaultGetStoreFunc) {
|
||||
defaultGetStoreFunc = createStore('keyval-store', 'keyval');
|
||||
}
|
||||
return defaultGetStoreFunc;
|
||||
}
|
||||
/**
|
||||
* Get a value by its key.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function get(key, customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => promisifyRequest(store.get(key)));
|
||||
}
|
||||
/**
|
||||
* Set a value with a key.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function set(key, value, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
store.put(value, key);
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Set multiple values at once. This is faster than calling set() multiple times.
|
||||
* It's also atomic – if one of the pairs can't be added, none will be added.
|
||||
*
|
||||
* @param entries Array of entries, where each entry is an array of `[key, value]`.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function setMany(entries, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
entries.forEach((entry) => store.put(entry[1], entry[0]));
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get multiple values by their keys
|
||||
*
|
||||
* @param keys
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function getMany(keys, customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => Promise.all(keys.map((key) => promisifyRequest(store.get(key)))));
|
||||
}
|
||||
/**
|
||||
* Update a value. This lets you see the old value and update it as an atomic operation.
|
||||
*
|
||||
* @param key
|
||||
* @param updater A callback that takes the old value and returns a new value.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function update(key, updater, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) =>
|
||||
// Need to create the promise manually.
|
||||
// If I try to chain promises, the transaction closes in browsers
|
||||
// that use a promise polyfill (IE10/11).
|
||||
new Promise((resolve, reject) => {
|
||||
const req = store.get(key);
|
||||
req.onsuccess = function () {
|
||||
try {
|
||||
store.put(updater(req.result), key);
|
||||
resolve(promisifyRequest(store.transaction));
|
||||
}
|
||||
catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
req.onerror = () => reject(req.error);
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Delete a particular key from the store.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function del(key, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
store.delete(key);
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete multiple keys at once.
|
||||
*
|
||||
* @param keys List of keys to delete.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function delMany(keys, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
keys.forEach((key) => store.delete(key));
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Clear all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function clear(customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
store.clear();
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
function eachCursor(store, callback) {
|
||||
store.openCursor().onsuccess = function () {
|
||||
if (!this.result)
|
||||
return;
|
||||
callback(this.result);
|
||||
this.result.continue();
|
||||
};
|
||||
return promisifyRequest(store.transaction);
|
||||
}
|
||||
/**
|
||||
* Get all keys in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function keys(customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => {
|
||||
// Fast path for modern browsers
|
||||
if (store.getAllKeys) {
|
||||
return promisifyRequest(store.getAllKeys());
|
||||
}
|
||||
const items = [];
|
||||
return eachCursor(store, (cursor) => items.push(cursor.key)).then(() => items);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function values(customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => {
|
||||
// Fast path for modern browsers
|
||||
if (store.getAll) {
|
||||
return promisifyRequest(store.getAll());
|
||||
}
|
||||
const items = [];
|
||||
return eachCursor(store, (cursor) => items.push(cursor.value)).then(() => items);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get all entries in the store. Each entry is an array of `[key, value]`.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function entries(customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => {
|
||||
// Fast path for modern browsers
|
||||
// (although, hopefully we'll get a simpler path some day)
|
||||
if (store.getAll && store.getAllKeys) {
|
||||
return Promise.all([
|
||||
promisifyRequest(store.getAllKeys()),
|
||||
promisifyRequest(store.getAll()),
|
||||
]).then(([keys, values]) => keys.map((key, i) => [key, values[i]]));
|
||||
}
|
||||
const items = [];
|
||||
return eachCursor(store, (cursor) => items.push([cursor.key, cursor.value])).then(() => items);
|
||||
});
|
||||
}
|
||||
|
||||
exports.clear = clear;
|
||||
exports.createStore = createStore;
|
||||
exports.del = del;
|
||||
exports.delMany = delMany;
|
||||
exports.entries = entries;
|
||||
exports.get = get;
|
||||
exports.getMany = getMany;
|
||||
exports.keys = keys;
|
||||
exports.promisifyRequest = promisifyRequest;
|
||||
exports.set = set;
|
||||
exports.setMany = setMany;
|
||||
exports.update = update;
|
||||
exports.values = values;
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
export declare function promisifyRequest<T = undefined>(request: IDBRequest<T> | IDBTransaction): Promise<T>;
|
||||
export declare function createStore(dbName: string, storeName: string): UseStore;
|
||||
export type UseStore = <T>(txMode: IDBTransactionMode, callback: (store: IDBObjectStore) => T | PromiseLike<T>) => Promise<T>;
|
||||
/**
|
||||
* Get a value by its key.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function get<T = any>(key: IDBValidKey, customStore?: UseStore): Promise<T | undefined>;
|
||||
/**
|
||||
* Set a value with a key.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function set(key: IDBValidKey, value: any, customStore?: UseStore): Promise<void>;
|
||||
/**
|
||||
* Set multiple values at once. This is faster than calling set() multiple times.
|
||||
* It's also atomic – if one of the pairs can't be added, none will be added.
|
||||
*
|
||||
* @param entries Array of entries, where each entry is an array of `[key, value]`.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function setMany(entries: [IDBValidKey, any][], customStore?: UseStore): Promise<void>;
|
||||
/**
|
||||
* Get multiple values by their keys
|
||||
*
|
||||
* @param keys
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function getMany<T = any>(keys: IDBValidKey[], customStore?: UseStore): Promise<(T | undefined)[]>;
|
||||
/**
|
||||
* Update a value. This lets you see the old value and update it as an atomic operation.
|
||||
*
|
||||
* @param key
|
||||
* @param updater A callback that takes the old value and returns a new value.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: UseStore): Promise<void>;
|
||||
/**
|
||||
* Delete a particular key from the store.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function del(key: IDBValidKey, customStore?: UseStore): Promise<void>;
|
||||
/**
|
||||
* Delete multiple keys at once.
|
||||
*
|
||||
* @param keys List of keys to delete.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function delMany(keys: IDBValidKey[], customStore?: UseStore): Promise<void>;
|
||||
/**
|
||||
* Clear all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function clear(customStore?: UseStore): Promise<void>;
|
||||
/**
|
||||
* Get all keys in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function keys<KeyType extends IDBValidKey>(customStore?: UseStore): Promise<KeyType[]>;
|
||||
/**
|
||||
* Get all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function values<T = any>(customStore?: UseStore): Promise<T[]>;
|
||||
/**
|
||||
* Get all entries in the store. Each entry is an array of `[key, value]`.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
export declare function entries<KeyType extends IDBValidKey, ValueType = any>(customStore?: UseStore): Promise<[KeyType, ValueType][]>;
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
function promisifyRequest(request) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// @ts-ignore - file size hacks
|
||||
request.oncomplete = request.onsuccess = () => resolve(request.result);
|
||||
// @ts-ignore - file size hacks
|
||||
request.onabort = request.onerror = () => reject(request.error);
|
||||
});
|
||||
}
|
||||
function createStore(dbName, storeName) {
|
||||
let dbp;
|
||||
const getDB = () => {
|
||||
if (dbp)
|
||||
return dbp;
|
||||
const request = indexedDB.open(dbName);
|
||||
request.onupgradeneeded = () => request.result.createObjectStore(storeName);
|
||||
dbp = promisifyRequest(request);
|
||||
dbp.then((db) => {
|
||||
// It seems like Safari sometimes likes to just close the connection.
|
||||
// It's supposed to fire this event when that happens. Let's hope it does!
|
||||
db.onclose = () => (dbp = undefined);
|
||||
}, () => {
|
||||
dbp = undefined;
|
||||
});
|
||||
return dbp;
|
||||
};
|
||||
return (txMode, callback) => getDB().then((db) => callback(db.transaction(storeName, txMode).objectStore(storeName)));
|
||||
}
|
||||
let defaultGetStoreFunc;
|
||||
function defaultGetStore() {
|
||||
if (!defaultGetStoreFunc) {
|
||||
defaultGetStoreFunc = createStore('keyval-store', 'keyval');
|
||||
}
|
||||
return defaultGetStoreFunc;
|
||||
}
|
||||
/**
|
||||
* Get a value by its key.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function get(key, customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => promisifyRequest(store.get(key)));
|
||||
}
|
||||
/**
|
||||
* Set a value with a key.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function set(key, value, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
store.put(value, key);
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Set multiple values at once. This is faster than calling set() multiple times.
|
||||
* It's also atomic – if one of the pairs can't be added, none will be added.
|
||||
*
|
||||
* @param entries Array of entries, where each entry is an array of `[key, value]`.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function setMany(entries, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
entries.forEach((entry) => store.put(entry[1], entry[0]));
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get multiple values by their keys
|
||||
*
|
||||
* @param keys
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function getMany(keys, customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => Promise.all(keys.map((key) => promisifyRequest(store.get(key)))));
|
||||
}
|
||||
/**
|
||||
* Update a value. This lets you see the old value and update it as an atomic operation.
|
||||
*
|
||||
* @param key
|
||||
* @param updater A callback that takes the old value and returns a new value.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function update(key, updater, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) =>
|
||||
// Need to create the promise manually.
|
||||
// If I try to chain promises, the transaction closes in browsers
|
||||
// that use a promise polyfill (IE10/11).
|
||||
new Promise((resolve, reject) => {
|
||||
const req = store.get(key);
|
||||
req.onsuccess = function () {
|
||||
try {
|
||||
store.put(updater(req.result), key);
|
||||
resolve(promisifyRequest(store.transaction));
|
||||
}
|
||||
catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
req.onerror = () => reject(req.error);
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Delete a particular key from the store.
|
||||
*
|
||||
* @param key
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function del(key, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
store.delete(key);
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete multiple keys at once.
|
||||
*
|
||||
* @param keys List of keys to delete.
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function delMany(keys, customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
keys.forEach((key) => store.delete(key));
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Clear all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function clear(customStore = defaultGetStore()) {
|
||||
return customStore('readwrite', (store) => {
|
||||
store.clear();
|
||||
return promisifyRequest(store.transaction);
|
||||
});
|
||||
}
|
||||
function eachCursor(store, callback) {
|
||||
store.openCursor().onsuccess = function () {
|
||||
if (!this.result)
|
||||
return;
|
||||
callback(this.result);
|
||||
this.result.continue();
|
||||
};
|
||||
return promisifyRequest(store.transaction);
|
||||
}
|
||||
/**
|
||||
* Get all keys in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function keys(customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => {
|
||||
// Fast path for modern browsers
|
||||
if (store.getAllKeys) {
|
||||
return promisifyRequest(store.getAllKeys());
|
||||
}
|
||||
const items = [];
|
||||
return eachCursor(store, (cursor) => items.push(cursor.key)).then(() => items);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get all values in the store.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function values(customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => {
|
||||
// Fast path for modern browsers
|
||||
if (store.getAll) {
|
||||
return promisifyRequest(store.getAll());
|
||||
}
|
||||
const items = [];
|
||||
return eachCursor(store, (cursor) => items.push(cursor.value)).then(() => items);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get all entries in the store. Each entry is an array of `[key, value]`.
|
||||
*
|
||||
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
||||
*/
|
||||
function entries(customStore = defaultGetStore()) {
|
||||
return customStore('readonly', (store) => {
|
||||
// Fast path for modern browsers
|
||||
// (although, hopefully we'll get a simpler path some day)
|
||||
if (store.getAll && store.getAllKeys) {
|
||||
return Promise.all([
|
||||
promisifyRequest(store.getAllKeys()),
|
||||
promisifyRequest(store.getAll()),
|
||||
]).then(([keys, values]) => keys.map((key, i) => [key, values[i]]));
|
||||
}
|
||||
const items = [];
|
||||
return eachCursor(store, (cursor) => items.push([cursor.key, cursor.value])).then(() => items);
|
||||
});
|
||||
}
|
||||
|
||||
export { clear, createStore, del, delMany, entries, get, getMany, keys, promisifyRequest, set, setMany, update, values };
|
||||
+1
@@ -0,0 +1 @@
|
||||
function _slicedToArray(n,t){return _arrayWithHoles(n)||_iterableToArrayLimit(n,t)||_unsupportedIterableToArray(n,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(n,t){if(n){if("string"==typeof n)return _arrayLikeToArray(n,t);var r={}.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(n,t):void 0}}function _arrayLikeToArray(n,t){(null==t||t>n.length)&&(t=n.length);for(var r=0,e=Array(t);r<t;r++)e[r]=n[r];return e}function _iterableToArrayLimit(n,t){var r=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=r){var e,o,u,i,a=[],c=!0,l=!1;try{if(u=(r=r.call(n)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(e=u.call(r)).done)&&(a.push(e.value),a.length!==t);c=!0);}catch(n){l=!0,o=n}finally{try{if(!c&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(l)throw o}}return a}}function _arrayWithHoles(n){if(Array.isArray(n))return n}function _typeof(n){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},_typeof(n)}!function(n,t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).idbKeyval={})}(this,(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;return function(o,u){return function(){if(e)return e;var o=indexedDB.open(n);return o.onupgradeneeded=function(){return o.result.createObjectStore(r)},(e=t(o)).then((function(n){n.onclose=function(){return e=void 0}}),(function(){e=void 0})),e}().then((function(n){return u(n.transaction(r,o).objectStore(r))}))}}var e;function o(){return e||(e=r("keyval-store","keyval")),e}function u(n,r){return n.openCursor().onsuccess=function(){this.result&&(r(this.result),this.result.continue())},t(n.transaction)}n.clear=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:o())("readwrite",(function(n){return n.clear(),t(n.transaction)}))},n.createStore=r,n.del=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readwrite",(function(r){return r.delete(n),t(r.transaction)}))},n.delMany=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readwrite",(function(r){return n.forEach((function(n){return r.delete(n)})),t(r.transaction)}))},n.entries=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:o())("readonly",(function(n){if(n.getAll&&n.getAllKeys)return Promise.all([t(n.getAllKeys()),t(n.getAll())]).then((function(n){var t=_slicedToArray(n,2),r=t[0],e=t[1];return r.map((function(n,t){return[n,e[t]]}))}));var r=[];return u(n,(function(n){return r.push([n.key,n.value])})).then((function(){return r}))}))},n.get=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readonly",(function(r){return t(r.get(n))}))},n.getMany=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readonly",(function(r){return Promise.all(n.map((function(n){return t(r.get(n))})))}))},n.keys=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:o())("readonly",(function(n){if(n.getAllKeys)return t(n.getAllKeys());var r=[];return u(n,(function(n){return r.push(n.key)})).then((function(){return r}))}))},n.promisifyRequest=t,n.set=function(n,r){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:o())("readwrite",(function(e){return e.put(r,n),t(e.transaction)}))},n.setMany=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readwrite",(function(r){return n.forEach((function(n){return r.put(n[1],n[0])})),t(r.transaction)}))},n.update=function(n,r){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:o())("readwrite",(function(e){return new Promise((function(o,u){var i=e.get(n);i.onsuccess=function(){try{e.put(r(i.result),n),o(t(e.transaction))}catch(n){u(n)}},i.onerror=function(){return u(i.error)}}))}))},n.values=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:o())("readonly",(function(n){if(n.getAll)return t(n.getAll());var r=[];return u(n,(function(n){return r.push(n.value)})).then((function(){return r}))}))}}));
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * from './';
|
||||
+1
@@ -0,0 +1 @@
|
||||
function _slicedToArray(n,t){return _arrayWithHoles(n)||_iterableToArrayLimit(n,t)||_unsupportedIterableToArray(n,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(n,t){if(n){if("string"==typeof n)return _arrayLikeToArray(n,t);var r={}.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(n,t):void 0}}function _arrayLikeToArray(n,t){(null==t||t>n.length)&&(t=n.length);for(var r=0,e=Array(t);r<t;r++)e[r]=n[r];return e}function _iterableToArrayLimit(n,t){var r=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=r){var e,o,u,i,a=[],c=!0,l=!1;try{if(u=(r=r.call(n)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(e=u.call(r)).done)&&(a.push(e.value),a.length!==t);c=!0);}catch(n){l=!0,o=n}finally{try{if(!c&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(l)throw o}}return a}}function _arrayWithHoles(n){if(Array.isArray(n))return n}function _typeof(n){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},_typeof(n)}!function(n,t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).idbKeyval={})}(this,(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;return function(o,u){return function(){if(e)return e;var o=indexedDB.open(n);return o.onupgradeneeded=function(){return o.result.createObjectStore(r)},(e=t(o)).then((function(n){n.onclose=function(){return e=void 0}}),(function(){e=void 0})),e}().then((function(n){return u(n.transaction(r,o).objectStore(r))}))}}var e;function o(){return e||(e=r("keyval-store","keyval")),e}function u(n,r){return n.openCursor().onsuccess=function(){this.result&&(r(this.result),this.result.continue())},t(n.transaction)}n.clear=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:o())("readwrite",(function(n){return n.clear(),t(n.transaction)}))},n.createStore=r,n.del=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readwrite",(function(r){return r.delete(n),t(r.transaction)}))},n.delMany=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readwrite",(function(r){return n.forEach((function(n){return r.delete(n)})),t(r.transaction)}))},n.entries=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:o())("readonly",(function(n){if(n.getAll&&n.getAllKeys)return Promise.all([t(n.getAllKeys()),t(n.getAll())]).then((function(n){var t=_slicedToArray(n,2),r=t[0],e=t[1];return r.map((function(n,t){return[n,e[t]]}))}));var r=[];return u(n,(function(n){return r.push([n.key,n.value])})).then((function(){return r}))}))},n.get=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readonly",(function(r){return t(r.get(n))}))},n.getMany=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readonly",(function(r){return Promise.all(n.map((function(n){return t(r.get(n))})))}))},n.keys=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:o())("readonly",(function(n){if(n.getAllKeys)return t(n.getAllKeys());var r=[];return u(n,(function(n){return r.push(n.key)})).then((function(){return r}))}))},n.promisifyRequest=t,n.set=function(n,r){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:o())("readwrite",(function(e){return e.put(r,n),t(e.transaction)}))},n.setMany=function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:o())("readwrite",(function(r){return n.forEach((function(n){return r.put(n[1],n[0])})),t(r.transaction)}))},n.update=function(n,r){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:o())("readwrite",(function(e){return new Promise((function(o,u){var i=e.get(n);i.onsuccess=function(){try{e.put(r(i.result),n),o(t(e.transaction))}catch(n){u(n)}},i.onerror=function(){return u(i.error)}}))}))},n.values=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:o())("readonly",(function(n){if(n.getAll)return t(n.getAll());var r=[];return u(n,(function(n){return r.push(n.value)})).then((function(){return r}))}))}}));
|
||||
Reference in New Issue
Block a user