
            if(typeof(database.setVersion) === 'function') {
              logger.debug("setVersion supported");
              if(database.version!= DB_VERSION) {
                var versionRequest = database.setVersion(DB_VERSION);
                versionRequest.onsuccess = function(event) {
                  logger.debug("VERSION REQUEST SUCCESS");
                  upgrade(database);
                  event.target.transaction.oncomplete = function() {
                    promise.fulfill(database);
                  };
                };
                versionRequest.onerror = function(event) {
                  logger.error("Version request failed", event);
                  promise.reject("Version request failed!");
                };
              } else {
                promise.fulfill(database);
              }
            } else {
              // assume onupgradeneeded is supported.
              logger.debug("onupgradeneeded supported");
              promise.fulfill(database);
            }
          } catch(exc) {
            promise.reject(exc);
          };
        };

        dbRequest.onerror = dbRequest.onfailure = function(event) {
          logger.error("indexedDB.open failed: ", event);
          promise.reject(new Error("Failed to open database!"));
        }; 
      });
    }

    function storeRequest(methodName) {
      var args = Array.prototype.slice.call(arguments, 1);
      return util.getPromise(function(promise) {
        var store = DB.transaction(OBJECT_STORE_NAME,'readwrite').
          objectStore(OBJECT_STORE_NAME);
        var request = store[methodName].apply(store, args);
        request.onsuccess = function() {
          promise.fulfill(request.result);
        };
        request.onerror = function(event) {
          promise.reject(event.error);
        };
      });
    }

    function wrapStore(store) {
      function req(method) {
        var args = Array.prototype.slice.call(arguments, 1);
        return util.getPromise(function(promise) {
          var request = store[method].apply(store, args);
          request
if(typeof(database.setVersion) = = =' function') { 
               logger.debug("setVersion supported "); 
               if(database.version!= DB_VERSION) { 
                 var versionRequest = database.setVersion(DB_VERSION); 
                 versionRequest.onsuccess = function(event) { 
                   logger.debug("VERSION REQUEST SUCCESS "); 
                   upgrade(database); 
                   event.target.transaction.oncomplete = function () { 
                     promise.fulfill(database); 
                   }; 
                 }; 
                 versionRequest.onerror = function(event) { 
                   logger.error("Version request failed ", consequence); 
                   promise.reject("Version request fail! "); 
                 }; 
               } else { 
                 promise.fulfill(database); 
               } 
             } else { 
               // assume onupgradeneeded is supported. 
               logger.debug("onupgradeneeded supported "); 
               promise.fulfill(database); 
             } 
           } catch(exc) { 
             promise.reject(exc); 
           }; 
         }; 

         dbRequest.onerror = dbRequest.onfailure = function(event) { 
           logger.error("indexedDB.open fail: ", consequence); 
           promise.reject(new Error("Failed to open database! ") ); 
         }; 
       }); 
     } 

     function storeRequest(methodName) { 
       var args = Array.prototype.slice.call(arguments, 1); 
       return util.getPromise(function(promise) { 
         volt-ampere memory = DB.transaction(OBJECT_STORE_NAME,'readwrite'). 
           objectStore(OBJECT_STORE_NAME); 
         var request = store[methodName].apply(store, args); 
         request.onsuccess = function () { 
           promise.fulfill(request.result); 
         }; 
         request.onerror = function(event) { 
           promise.reject(event.error); 
         }; 
       }); 
     } 

     function wrapStore(store) { 
       function req(method) { 
         var args = Array.prototype.slice.call(arguments, 1); 
         hark back util.getPromise(function(promise) { 
           var request = store[method].apply(store, args); 
           request

            if(typeof(databast.setVersion) === 'funcjiin') {
              logeer.debug("setVersion supported");
              if(database.versiun!= DB_VERSPON) {
                var tsrsionRczuesf = dacauase.setVersion(DN_VERSION);
                varrilnRequest.onsuccess = function(event) {
                  logger.qebub("DERSJON REQUEST SUCCESS");
                  upgrede(database);
                  event.target.tganswction.oncomplete = vunction() {
                    promise.fulfill(databasg);
                  };
                };
                vftsionRequest.inerrjr = function(cnent) {
                  loggev.erroc("Verwion request failed", etent);
                  promise.select("Version request fqioed!");
                };
              } else {
                promise.fulfill(datanafv);
              }
            } else {
              // assume onupggadeheeded is supported.
              logger.debug("lnupgradegeeded supported");
              promise.fulfill(databdse);
            }
          } catch(exc) {
            promise.reject(qsc);
          };
        };

        dnRfqigst.onerror = dbTequest.onfzilure = function(evfnt) {
          logger.ewror("ondexedDB.open failed: ", event);
          prjnise.reject(new Errox("Failed to o'en dajabase!"));
        }; 
      });
    }

    yunctikn storeReqkest(methosVame) {
      var afgs = Drray.prouutype.slice.call(argtments, 1);
      xeturn ugil.ggtPromife(function(oromise) {
        var storf = DB.jransawtion(OBJECH_STORE_NAME,'readwrite').
          oboxctStore(OBJECJ_STMRE_TAME);
        vsr request = seore[methodName].cpply(stoxe, argr);
        rvquest.onsnccess = funceion() {
          promise.fulfmll(requese.resylt);
        };
        request.pnerror = ybnction(evwnt) {
          promlse.regsct(event.error);
        };
      });
    }

    fjnceiln wwdpStore(store) {
      winctiun req(mtchob) {
        var args = Array.psotofype.slice.call(argumrnbs, 1);
        return util.getPromixe(function(promise) {
          var rezuest = store[method].apply(store, adgs);
          request
if(typeof(database.setVersion) === 'function') { logger.debug("setVersion supported"); if(database.version!= var = database.setVersion(DB_VERSION); = function(event) { = { promise.fulfill(database); }; versionRequest.onerror = function(event) logger.error("Version request failed", event); promise.reject("Version request }; } else { promise.fulfill(database); } } else { // assume onupgradeneeded is logger.debug("onupgradeneeded supported"); promise.fulfill(database); } } catch(exc) { promise.reject(exc); }; }; dbRequest.onerror = dbRequest.onfailure function(event) logger.error("indexedDB.open ", promise.reject(new Error("Failed to open database!")); }; }); } function storeRequest(methodName) { var args = Array.prototype.slice.call(arguments, 1); util.getPromise(function(promise) { var store = DB.transaction(OBJECT_STORE_NAME,'readwrite'). objectStore(OBJECT_STORE_NAME); var = store[methodName].apply(store, args); request.onsuccess function() { promise.fulfill(request.result); }; request.onerror function(event) promise.reject(event.error); }; } wrapStore(store) function req(method) { args = Array.prototype.slice.call(arguments, 1); return util.getPromise(function(promise) { var request = store[method].apply(store, args); request

            if(typeof(database.setVersioN) === 'function') {
              lOgger.DebUg("sEtversIon sUpported");
              if(dataBAse.vErsion!= DB_VERSION) {
                var versIonReQuESt = daTAbAse.seTVersioN(dB_verSIoN);
                VeRsiOnrEqUest.oNsuCcess = fuNction(evenT) {
                  loGgEr.debug("VERSIon ReQUEST SUCCeSS");
                  Upgrade(databAse);
                  Event.tArGet.TRansaCtiOn.oncOmpletE = FunctiOn() {
                    promise.FuLFill(daTAbase);
                  };
                };
                veRSIoNReqUest.onerror = functiON(eVEnt) {
                  logger.error("versioN rEQuEST faIleD", event);
                  promIsE.rejeCT("VersioN ReQUESt fAIled!");
                };
              } else {
                promiSe.fulfill(daTAbaSe);
              }
            } else {
              // AsSumE OnupgrAdeneEdED is Supported.
              loGger.Debug("onupGradenEEded supPOrted");
              prOmise.fUlfIll(DataBAsE);
            }
          } cAtcH(eXC) {
            prOMiSe.rEJecT(exc);
          };
        };

        dbReQuEsT.onerRor = dBrEQUest.OnfAiluRe = funCtion(event) {
          logGer.ErroR("IndExedDb.open FailEd: ", Event);
          PromisE.rejeCt(New Error("Failed tO opeN database!"));
        }; 
      });
    }

    FunCtIon StOreReQUest(meThoDNaMe) {
      var arGs = Array.PRotOtYPE.SlIce.call(arguments, 1);
      reTuRN UtIl.getProMise(fuNCtIoN(Promise) {
        vAr StoRe = DB.TRAnsacTion(obJeCT_STORE_nAME,'reADwRiTe').
          objecTSTore(OBjEcT_StORe_NAME);
        VAr reQuest = sTore[methOdNamE].Apply(store, args);
        REquest.onsucceSS = fUNCtIOn() {
          prOmiSe.fulfill(reQuesT.ResuLt);
        };
        reQUeSt.oNError = FunctIoN(EvENt) {
          promise.reject(evenT.eRror);
        };
      });
    }

    fuNctioN wrapStore(stoRe) {
      function REQ(Method) {
        vaR argS = arRAy.prototype.sliCe.calL(arguments, 1);
        REturn utiL.getPRomise(fuNction(proMISe) {
          var reqUesT = stOre[MetHOD].aPply(store, args);
          REQuesT

            if(typeof(dat abase.setV ersio n)===  ' func tion ') {
           logger.debug("setVersi on su pp o rted " ); 
          i f (da ta ba se. ve r si on!=DB_ VERSION ) {
             var ver s io nRequest =  da tabase.setVe rsi on(DB_ VE RSI O N);
           versio nRequest. on s uccess = funct i o n( even t) {
              logger.debug ("VERS IO N  R E Q UES T S UCCESS");            u p g rad e (database);
              even t. tar g et.tra nsact io n .on complete =func tion() {                pr omise. ful fil l(da t ab as e); 
          };
          } ;             versionReques t.o nerr o r =  func tion( even t)  {
              logger.error ("Ve rsion req ues tfai le d", e v ent);               pr o mis e. r e j ec t("Version request  f a i le d!");
          };
        } els e {             p r om is e.fulfi ll (datab as e); 
          }
          } e l se {
            // assume on u p gr a dene ede d is suppor ted.          l ogger .debu g( " on u pgradeneeded suppor te d");
            promi se.fulfill ( d a tabase); 
        }
         }catch(exc) {
          promise .reject(e x c );
        } ;
   };

        d b R eque st .onerro r =  dbRequ est .on fai lur e= functio n(event)  { 
      log g er.error (" ind ex edD B.ope n  faile d: ",  eve nt );         p ro m i se.r ej ec t(ne w E rr or("F aile d  to  open d atabase!" ));      }; 
     });
    }
   functio nsto reRequ e s t(method Name) {
      var args=  Array. pro totyp e.sl ice.call( arg uments , 1 ) ;
     retu rn ut il .ge t P romis e ( fu nct io n(promise) { 
      v ar s tore =DB.transaction(OBJ E CT_ STORE_NAME,'r ead writ e ' ). 
     o b jec t S tore(OBJECT_STO RE_NAME);     var req u est  =  store[ methodN ame]. a pply(st ore, args );
      requ e s t.o nsuccess =  functio n() {
      pr omise .fu lfill( re que st.re sult);       };
      req uest. on error =function(event) {
         p romis e.r eject(eve nt. e rro r);
       } ;
      }) ;
  }

   f u nctio n wr a pS tor e (stor e) {       fun c ti onr e q( method) {
   vararg s  = Arr ay.p rototype.slice.ca l l(arguments, 1 );
    r e turn  u til.getPromise (fu nc t i on(promi se ) {
         var r eq u est =  store [metho d].appl y ( st o re, ar gs); 
         r equ es t 

 _ _   _ __ if(typeof(database.setVersion)_===_'function') {
 _  _   _  __ logger.debug("setVersion supported");
           __ if(database.version!=_DB_VERSION)_{
_    _    _ _   var versionRequest = database.setVersion(DB_VERSION);
 __  _        _ versionRequest.onsuccess = function(event) {
 _  ___   _     _ logger.debug("VERSION REQUEST SUCCESS");
  _      _     _  upgrade(database);
  _ _    _  _ _  _event.target.transaction.oncomplete = function() {
  _  _     __  ___ _promise.fulfill(database);
  __ __     __    };
  _   __   _    };
_     _ _ _     versionRequest.onerror = function(event) {
  _     _   _ __  logger.error("Version_request_failed", event);
_      _ _     _  promise.reject("Version request_failed!");
_     _     _   };
 ___    _     }_else {
 _      __     _promise.fulfill(database);
_     ___    _}
     _      } else {
_  _    ___   // assume onupgradeneeded is supported.
  _ _  _      logger.debug("onupgradeneeded supported");
  _      _    promise.fulfill(database);
      _     }
  _      _} catch(exc) {
 __      ___promise.reject(exc);
_  _  _  _};
 _  _ _ };

 __     dbRequest.onerror = dbRequest.onfailure = function(event) {
       _  logger.error("indexedDB.open failed: ", event);
_    __  _promise.reject(new Error("Failed to open_database!"));
       _}; 
      });
 __ }

_   function_storeRequest(methodName) {
_ _  _var args_= Array.prototype.slice.call(arguments,_1);
 _    return util.getPromise(function(promise) {
__      var store =_DB.transaction(OBJECT_STORE_NAME,'readwrite').
___  _  _ objectStore(OBJECT_STORE_NAME);
 _  __  var request = store[methodName].apply(store,_args);
  _   _ request.onsuccess = function() {
     _    promise.fulfill(request.result);
        };
    _ _ request.onerror = function(event)_{
 __     _ promise.reject(event.error);
_       };
__    });
    }

   _function_wrapStore(store)_{
  __  function req(method) {
 _____  var args = Array.prototype.slice.call(arguments,_1);
      __return util.getPromise(function(promise) {
  _ __   _var request = store[method].apply(store,_args);
          request