|
|
|
|
|
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ clear: () => (/* binding */ clear),\n/* harmony export */ createStore: () => (/* binding */ createStore),\n/* harmony export */ del: () => (/* binding */ del),\n/* harmony export */ delMany: () => (/* binding */ delMany),\n/* harmony export */ entries: () => (/* binding */ entries),\n/* harmony export */ get: () => (/* binding */ get),\n/* harmony export */ getMany: () => (/* binding */ getMany),\n/* harmony export */ keys: () => (/* binding */ keys),\n/* harmony export */ promisifyRequest: () => (/* binding */ promisifyRequest),\n/* harmony export */ set: () => (/* binding */ set),\n/* harmony export */ setMany: () => (/* binding */ setMany),\n/* harmony export */ update: () => (/* binding */ update),\n/* harmony export */ values: () => (/* binding */ values)\n/* harmony export */ });\nfunction promisifyRequest(request) {\n return new Promise((resolve, reject)=>{\n // @ts-ignore - file size hacks\n request.oncomplete = request.onsuccess = ()=>resolve(request.result);\n // @ts-ignore - file size hacks\n request.onabort = request.onerror = ()=>reject(request.error);\n });\n}\nfunction createStore(dbName, storeName) {\n const request = indexedDB.open(dbName);\n request.onupgradeneeded = ()=>request.result.createObjectStore(storeName);\n const dbp = promisifyRequest(request);\n return (txMode, callback)=>dbp.then((db)=>callback(db.transaction(storeName, txMode).objectStore(storeName)));\n}\nlet defaultGetStoreFunc;\nfunction defaultGetStore() {\n if (!defaultGetStoreFunc) {\n defaultGetStoreFunc = createStore(\"keyval-store\", \"keyval\");\n }\n return defaultGetStoreFunc;\n}\n/**\n * Get a value by its key.\n *\n * @param key\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */ function get(key, customStore = defaultGetStore()) {\n return customStore(\"readonly\", (store)=>promisifyRequest(store.get(key)));\n}\n/**\n * Set a value with a key.\n *\n * @param key\n * @param value\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */ function set(key, value, customStore = defaultGetStore()) {\n return customStore(\"readwrite\", (store)=>{\n store.put(value, key);\n return promisifyRequest(store.transaction);\n });\n}\n/**\n * Set multiple values at once. This is faster than calling set() multiple times.\n * It's also atomic – if one of the pairs can't be added, none will be added.\n *\n * @param entries Array of entries, where each entry is an array of `[key, value]`.\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */ function setMany(entries, customStore = defaultGetStore()) {\n return customStore(\"readwrite\", (store)=>{\n entries.forEach((entry)=>store.put(entry[1], entry[0]));\n return promisifyRequest(store.transaction);\n });\n}\n/**\n * Get multiple values by their keys\n *\n * @param keys\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */ function getMany(keys, customStore = defaultGetStore()) {\n return customStore(\"readonly\", (store)=>Promise.all(keys.map((key)=>promisifyRequest(store.get(key)))));\n}\n/**\n * Update a value. This lets you see the old value and update it as an atomic operation.\n *\n * @param key\n * @param updater A callback that takes the old value and returns a new value.\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */ function update(key, updater, customStore = defaultGetStore()) {\n return customStore(\"readwrite\", (store)=>// Need to create the promise manually.\n // If I try to chain promises, the transaction closes in browsers\n // that use a promise polyfill (IE10/11).\n new Promise((resolve, reject)=>{\n store.get(key).onsuccess = function() {\n try {\n
|