define(["exports"],function(_exports){function getObjectByKey(db,key,storeName){return new Promise(function(resolve,reject){var request=getStore(db,storeName).get(key);request.onerror=reject,request.onsuccess=function(){resolve(request.result)}})}function getObjectsBySingleIndexKey(db,indexName,key,storeName){return new Promise(function(resolve,reject){storeName=storeName||db.name;var results,request,index=db.transaction([storeName],"readonly").objectStore(storeName).index(indexName);"function"==typeof index.getAll?(request=index.getAll(key)).onsuccess=function(event){resolve(event.target.result)}:(results=[],(request=index.openCursor(key)).onsuccess=function(event){event=event.target.result;event?(results.push(event.value),event.continue()):resolve(results)}),request.onerror=reject})}function getStore(db,storeName,access){return storeName=storeName||db.name,db.transaction(storeName,access=access||"readonly").objectStore(storeName)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;_exports.default={addObject:function(db,key,val,storeName){return new Promise(function(resolve,reject){var request=getStore(db,storeName,"readwrite").put(val,key);request.onerror=reject,request.onsuccess=resolve})},updateObject:function(db,key,val,storeName){return new Promise(function(resolve,reject){var request=getStore(db,storeName,"readwrite").put(val,key);request.onerror=reject,request.onsuccess=function(){resolve(request.result)}})},deleteObject:function(db,key,storeName){return new Promise(function(resolve,reject){var request=getStore(db,storeName,"readwrite").delete(key);request.onerror=reject,request.onsuccess=resolve})},clearObjects:function(db,storeName){return new Promise(function(resolve,reject){var request=getStore(db,storeName,"readwrite").clear();request.onerror=reject,request.onsuccess=resolve})},getAllObjects:function(db,storeName){return new Promise(function(resolve,reject){var results,request,objectStore=getStore(db,storeName);"function"==typeof objectStore.getAll?(request=objectStore.getAll()).onsuccess=function(event){resolve(event.target.result)}:(results=[],(request=objectStore.openCursor()).onsuccess=function(event){event=event.target.result;event?(results.push(event.value),event.continue()):resolve(results)}),request.onerror=reject})},getObjectByKey:getObjectByKey,getObjectsByKeys:function(db,keys,storeName){return Array.isArray(keys)&&1!==keys.length?(4<keys.length?function(db,keys,storeName){return new Promise(function(resolve,reject){var objectStore=getStore(db,storeName),set=keys.slice(0),i=(set.sort(function(a,b){return indexedDB.cmp(a,b)}),0),range=IDBKeyRange.bound(set[0],set[set.length-1]),results=[],objectStore=objectStore.openCursor(range);objectStore.onsuccess=function(event){event=event.target.result;if(event){for(var key=event.key;0<indexedDB.cmp(key,set[i]);)if(++i===set.length)return void resolve(results);key===set[i]?(results.push(event.value),event.continue()):event.continue(set[i])}else resolve(results)},objectStore.onerror=reject})}:function(db,keys,storeName){keys=keys.map(function(key){return getObjectByKey(db,key,storeName)});return Promise.all(keys).then(function(results){results=results.reduce(function(acc,val){return acc.concat(val)},[]);return Promise.resolve(results)})})(db,keys,storeName):getObjectByKey(db,Array.isArray(keys)?keys[0]:keys,storeName)},getObjectsByIndexKeys:function(db,indexName,keys,storeName){return Array.isArray(keys)&&1!==keys.length?(4<keys.length?function(db,indexName,keys,storeName){return new Promise(function(resolve,reject){var index=getStore(db,storeName).index(indexName),set=keys.slice(0),i=(set.sort(function(a,b){return indexedDB.cmp(a,b)}),0),range=IDBKeyRange.bound(set[0],set[set.length-1]),results=[],index=index.openCursor(range);index.onsuccess=function(event){event=event.target.result;if(event){for(var key=event.key;0<indexedDB.cmp(key,set[i]);)if(++i===set.length)return void resolve(results);key===set[i]?(results.push(event.value),event.continue()):event.continue(set[i])}else resolve(results)},index.onerror=reject})}:function(db,indexName,keys,storeName){keys=keys.map(function(key){return getObjectsBySingleIndexKey(db,indexName,key,storeName)});return Promise.all(keys).then(function(results){results=results.reduce(function(acc,val){return acc.concat(val)},[]);return Promise.resolve(results)})})(db,indexName,keys,storeName):getObjectsBySingleIndexKey(db,indexName,Array.isArray(keys)?keys[0]:keys,storeName)},getDistinctndexKeys:function(db,indexName,storeName){return new Promise(function(resolve,reject){var index=getStore(db,storeName).index(indexName),results=[],index=index.openKeyCursor(null,"nextunique");index.onsuccess=function(event){event=event.target.result;event?(results.push(event.key),event.continue()):resolve(results)},index.onerror=reject})}}});