jsstore
Version:
Harness the power of JsStore to streamline database operations in your web applications. With its SQL-like API, JsStore simplifies IndexedDB interactions, enabling developers to easily query, filter, and manipulate data with familiar syntax and efficiency
2 lines • 61.3 kB
JavaScript
/*! For license information please see jsstore.worker.min.js.LICENSE.txt */
var JsStoreWorker;(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{QueryManager:()=>rt});var n,r,o,u,i,a,c,s,l=function(e){return Promise.resolve(e)},f=function(e){return new Promise(e)},h="not_array",p="no_value_supplied",y="column_not_exist",d="no_index_found",v="null_value",m="wrong_data_type",b="table_not_exist",g="not_object",w="Db_blocked",_="indexeddb_not_supported",x="null_value_in_where",k="invalid_join_query",T="import_scripts_failed",S="method_not_exist",E="invalid_middleware";!function(e){e.Registered="registerd",e.Failed="failed",e.NotStarted="not_started"}(n||(n={})),function(e){e.String="string",e.Object="object",e.Array="array",e.Number="number",e.Boolean="boolean",e.Null="null",e.DateTime="date_time"}(r||(r={})),function(e){e.InitDb="init_db",e.MapGet="map_get",e.MapSet="map_set",e.MapHas="map_has",e.MapDelete="map_delete",e.Select="select",e.Insert="insert",e.Update="update",e.Remove="remove",e.OpenDb="open_db",e.Clear="clear",e.DropDb="drop_db",e.Count="count",e.ChangeLogStatus="change_log_status",e.Terminate="terminate",e.Transaction="transaction",e.CloseDb="close_db",e.Union="union",e.Intersect="intersect",e.ImportScripts="import_scripts",e.Middleware="middleware"}(o||(o={})),function(e){e.RequestQueueEmpty="requestQueueEmpty",e.RequestQueueFilled="requestQueueFilled",e.Upgrade="upgrade",e.Create="create",e.Open="open"}(u||(u={})),function(e){e.Where="where",e.Like="like",e.Regex="regex",e.In="in",e.Equal="=",e.Between="-",e.GreaterThan=">",e.LessThan="<",e.GreaterThanEqualTo=">=",e.LessThanEqualTo="<=",e.NotEqualTo="!=",e.Aggregate="aggregate",e.Max="max",e.Min="min",e.Avg="avg",e.Count="count",e.Sum="sum",e.List="list",e.Or="or",e.Skip="skip",e.Limit="limit",e.And="and",e.IgnoreCase="ignoreCase",e.Then="then"}(i||(i={})),function(e){e.ReadOnly="readonly",e.ReadWrite="readwrite"}(a||(a={})),function(e){e.First="f",e.Last="l",e.Any="a"}(c||(c={})),function(e){e.Connected="connected",e.Closed="closed",e.NotStarted="not_started",e.UnableToStart="unable_to_start",e.ClosedByJsStore="closed_by_jsstore"}(s||(s={}));var O,C=function(){function e(e){this.columns=[],this.autoIncColumnValue={},this.columns=this.setColumn(e.columns),this.name=e.name,this.alter=e.alter||{}}return e.prototype.setColumn=function(e){var t=[],n=function(n){var o=e[n];o.name=n,o.autoIncrement&&(r.autoIncColumnValue[n]=0),o.primaryKey&&(r.primaryKey=n,r.keypath=o.keyPath||n),o.enableSearch=null==o.enableSearch||o.enableSearch;var u=r.columns.indexOf((function(e){return e.name===n}));if(u<0)t.push(o);else{var i=r.columns[u];Object.assign(i,o)}},r=this;for(var o in e)n(o);return t},e}(),j=function(){function e(){}return e.autoIncrementKey=function(e,t){return"JsStore_".concat(e,"_").concat(t,"_Value")},e.getStore=function(t){return t.tx||t.createTransaction([e.tableName]),t.objectStore(e.tableName)},e.set=function(t,n,r){var o=e.getStore(r);return f((function(e,r){var u=o.put({key:t,value:n});u.onsuccess=function(){e()},u.onerror=r}))},e.get=function(t,n){var r=e.getStore(n);return f((function(e,o){var u=r.get(n.keyRange(t));u.onsuccess=function(){var t=u.result;e(t&&t.value)},u.onerror=o}))},e.remove=function(t,n){var r=e.getStore(n);return f((function(e,o){var u=r.delete(n.keyRange(t));u.onsuccess=function(){e()},u.onerror=o}))},e.has=function(t,n){var r=e.getStore(n);return f((function(e,o){var u=r.count(n.keyRange(t));u.onsuccess=function(){var t=u.result;e(t>0)},u.onerror=o}))},e.tableName="JsStore_Meta",e.dbSchema="JsStore_DbSchema",e}(),A=function(e){this.name=e.name,this.version=e.version||1,e.tables.push({name:j.tableName,columns:{key:{primaryKey:!0},value:{enableSearch:!1}}}),this.tables=e.tables.map((function(e){return new C(e)}))},q=function(e,t){for(var n in e)t(n,e[n])},I=function(){function e(e,t){this.type=e,this.info_=t,this.message=this.getMsg_()}return e.prototype.log=function(e){this.status&&console.log(e)},e.prototype.throw=function(){throw this.get()},e.prototype.logError=function(){console.error(this.get())},e.prototype.get=function(){return{message:this.message,type:this.type}},e.prototype.warn=function(){console.warn(this.get())},e.prototype.getMsg_=function(){var e,t,n=this.info_,r=((e={})[h]=function(){t="Supplied value is not an array"},e.undefined_column=function(){t="Column is undefined in Where"},e.undefined_value=function(){t="Value is undefined in Where"},e.undefined_column_name=function(){t="Column name is undefined '"+n.TableName+"'"},e.undefined_database_name=function(){t="Database name is not supplied"},e.undefined_column_value=function(){t="Column value is undefined"},e[p]=function(){t="No value is supplied"},e.invalid_operator=function(){t="Invalid Op Value '"+n.Op+"'"},e[y]=function(){var e=n.column;t=n.isOrder?"Column '".concat(e,"' in order query does not exist"):"Column '".concat(e,"' does not exist")},e[d]=function(){t="No index found for column '"+n.column+"'. Query can not be executed without index."},e[v]=function(){t="Null value is not allowed for column '"+n.ColumnName+"'"},e[m]=function(){t="Expected data type for the column ".concat(n.column," is ").concat(n.expected,", but received a ").concat(n.received,".")},e[b]=function(){t="Table '"+n.tableName+"' does not exist"},e.db_not_exist=function(){t="Database with name ".concat(n.dbName," does not exist")},e[g]=function(){t="supplied value is not object"},e.invalid_config=function(){t="Invalid Config '"+n.Config+" '"},e[w]=function(){t="database is blocked, cant be deleted right now"},e[x]=function(){t="Null/undefined is not allowed in where. Column '".concat(n.column,"' has null")},e[S]=function(){t="method '".concat(n,"' does not exist.")},e[_]=function(){t="Browser does not support indexeddb"},e.getInfo=function(){t=n},e[k]=function(){r.getInfo()},e[T]=function(){r.getInfo()},e[E]=function(){t="No function ".concat(n," is found.")},e),o=this.type,u=r[o];return u?u():(o||(this.type="unknown"),t=this.message),t},e}(),R=function(){function e(){this.logger=new I(null)}return e.prototype.emptyTx=function(){this.tx&&(this.tx.oncomplete=null,this.tx.onabort=null,this.tx.onerror=null,this.tx=null)},e.prototype.createTransactionIfNotExist=function(e,t){this.tx||this.createTransaction(e,t)},e.prototype.createTransaction=function(e,t){var n=this;return void 0===t&&(t=a.ReadWrite),this.tx=this.con.transaction(e,t),f((function(e,t){n.tx.oncomplete=e,n.tx.onabort=e,n.tx.onerror=t}))},e.prototype.keyRange=function(e,t){var n;switch(t){case i.Between:n=IDBKeyRange.bound(e.low,e.high,!1,!1);break;case i.GreaterThan:n=IDBKeyRange.lowerBound(e,!0);break;case i.GreaterThanEqualTo:n=IDBKeyRange.lowerBound(e);break;case i.LessThan:n=IDBKeyRange.upperBound(e,!0);break;case i.LessThanEqualTo:n=IDBKeyRange.upperBound(e);break;default:n=IDBKeyRange.only(e)}return n},e.prototype.objectStore=function(e){return this.tx.objectStore(e)},e.prototype.abortTransaction=function(){this.tx&&this.tx.abort()},e.prototype.close=function(){var e=this;return this.con&&this.con.close(),f((function(t){e.con=null,setTimeout(t,100)}))},e.prototype.initDb=function(e){var t,n=this,r=!1,o=e.version;return f((function(u,i){var a=indexedDB.open(e.name,o);a.onsuccess=function(){n.con=a.result,n.con.onversionchange=function(e){e.target.close()},u({isCreated:r,oldVersion:t,newVersion:o})},a.onerror=function(e){console.error("error",e),i(e)},a.onupgradeneeded=function(n){t=n.oldVersion;var u=n.target,i=u.result;r=!0;var a=u.transaction,c=i.objectStoreNames,s=function(e,t){var n=t.name;if(t.enableSearch&&!e.indexNames.contains(n)){var r=t.primaryKey?{unique:!0}:{unique:t.unique};r.multiEntry=t.multiEntry;var o=null==t.keyPath?n:t.keyPath;e.createIndex(n,o,r)}},l=function(e,t,n){var r=t.columns.findIndex((function(e){return e.name===n}));r>=0&&(t.columns.splice(r,1),e.deleteIndex(n))};e.tables.forEach((function(e){c.contains(e.name)||function(e){var t=e.primaryKey?{keyPath:e.keypath}:{autoIncrement:!0},n=i.createObjectStore(e.name,t);e.columns.forEach((function(e){s(n,e)}))}(e);for(var n=a.objectStore(e.name),r=t+1;r<=o;r++){var u=e.alter[r];u&&(u.add&&e.setColumn(u.add).forEach((function(t){s(n,t),e.columns.push(t)})),q(u.drop||{},(function(t){l(n,e,t)})),q(u.modify||{},(function(t,r){var o=r.multiEntry||r.keyPath||r.unique,u=e.columns.find((function(e){return e.name===t})),i=Object.assign(u,r);i.name=t,o&&(l(n,e,t),s(n,i),e.columns.push(i))})))}}));for(var f=function(t,n){var r=c.item(t);e.tables.findIndex((function(e){return e.name===r}))<0&&i.deleteObjectStore(r)},h=0,p=c.length;h<p;h++)f(h)}}))},e}(),Q=function(e){return Promise.all(e)},L=function(e){return Promise.reject(e)},N=function(e){if(e instanceof I)return e.logError(),e.get();var t=void 0;return e.name?(t=new I(e.name)).message=e.message:(t=new I(e.target.error.name)).message=e.target.error.message,t.get()},D=function(){function e(){this.rowAffected=0,this.isTxQuery=!1,this.results=[]}return Object.defineProperty(e.prototype,"db",{get:function(){return this.util.db},enumerable:!1,configurable:!0}),e.prototype.table=function(e){var t=e||this.tableName;return this.db.tables.find((function(e){return e.name===t}))},e.prototype.primaryKey=function(e){var t=this.query;return!t.from&&t.store&&t.meta?t.meta.primaryKey:this.table(e).primaryKey},e.prototype.getColumnInfo=function(e,t){return this.table(t).columns.find((function(t){return t.name===e}))},e.prototype.onException=function(e,t){return console.error(e),this.util.abortTransaction(),L(function(e,t){return void 0===t&&(t="invalid_query"),e.name=t,N(e)}(e,t))},e}(),W=function(e){if(null==e)return r.Null;var t=typeof e;if("object"===t){if(Array.isArray(e))return r.Array;if(e instanceof Date)return r.DateTime}return t},V=function(e){return null==e||"number"==typeof e&&isNaN(e)},B=function(){function e(e,t){this.table=e,this.autoIncrementValue=t}return e.prototype.checkAndModifyValues=function(e){var t,n=this;this.query=e;var r=e.values,o=[];return r.every((function(r,u){return t=n.checkAndModifyValue(r),e.ignore&&t&&(o.push(u),t=null),!t})),o.forEach((function(e){r.splice(e,1)})),{err:t,values:r}},e.prototype.checkAndModifyValue=function(e){var t,n=this;return this.table.columns.every((function(r){return!(t=n.checkAndModifyColumnValue_(r,e))})),t},e.prototype.checkNotNullAndDataType_=function(e,t){if(e.notNull&&V(t[e.name]))return this.getError(v,{ColumnName:e.name});if(e.dataType&&!V(t[e.name])){var n=W(t[e.name]);if(n!==e.dataType)return this.getError(m,{column:e.name,expected:e.dataType,received:n})}},e.prototype.checkAndModifyColumnValue_=function(e,t){var n=t[e.name];if(e.autoIncrement?V(n)?t[e.name]=++this.autoIncrementValue[e.name]:W(n)===r.Number&&n>this.autoIncrementValue[e.name]&&(this.autoIncrementValue[e.name]=n):void 0!==e.default&&V(n)&&(t[e.name]=e.default),this.query.validation)return this.checkNotNullAndDataType_(e,t)},e.prototype.getError=function(e,t){return new I(e,t)},e}(),P=function(){function e(e){this.table=e}return e.prototype.check=function(e,t){var n,o=this;return typeof e===r.Object?this.table?this.table.columns.every((function(t){return t.name in e&&(n=o.checkByColumn_(t,e[t.name])),!n})):n=new I(b,{tableName:t}):n=new I(g),n},e.prototype.checkByColumn_=function(e,t){if(!0===e.notNull&&V(t))return new I(v,{ColumnName:e.name});var n=W(t),r=null!=t;if(e.dataType&&r&&n!==e.dataType&&"object"!==n)return new I(m,{column:e.name,expected:e.dataType,received:n});if(r&&"object"===n){var o=["+","-","*","/","{push}"];for(var u in t)if(o.indexOf(u)<0&&e.dataType&&n!==e.dataType)return new I(m,{column:e.name,expected:e.dataType,received:n})}},e}(),M=function(){function e(e){this.db=e}return e.prototype.validate=function(e,t){switch(e){case o.Select:case o.Remove:case o.Count:return this.checkSelect(t);case o.Insert:return this.checkInsertQuery(t);case o.Update:return this.checkUpdate(t)}},e.prototype.getTable_=function(e){return this.db.tables.find((function(t){return t.name===e}))},e.prototype.isInsertQryValid=function(e){var t,n=this.getTable_(e.into);if(n)switch(W(e.values)){case r.Array:break;case r.Null:t=new I(p);break;default:t=new I(h)}else t=new I(b,{tableName:e.into});return{table:n,log:t}},e.prototype.checkUpdate=function(e){var t=new P(this.getTable_(e.in)).check(e.set,e.in);if(t)return t;if(null!=e.where){if(t=this.checkForNullInWhere_(e))return t;this.addGreatAndLessToNotOp_(e)}},e.prototype.checkSelect=function(e){if(!e.store&&!this.getTable_(e.from))return new I(b,{tableName:e.from});if(e.where){var t=this.checkForNullInWhere_(e);if(t)return t;this.addGreatAndLessToNotOp_(e)}},e.prototype.checkForNullInWhere_=function(e){for(var t in e.where)if(null==e.where[t])return new I(x,{column:t})},e.prototype.addGreatAndLessToNotOp_=function(e){var t=e.where,n=function(e,t){return t.findIndex((function(t){return null!=e[t][i.NotEqualTo]}))>=0},o=function(e,t){var n;return t.forEach((function(t){null!=(n=e[t])[i.NotEqualTo]&&(e[t][i.GreaterThan]=n[i.NotEqualTo],void 0===e[i.Or]?(e[i.Or]={},e[i.Or][t]={}):void 0===e[i.Or][t]&&(e[i.Or][t]={}),e[i.Or][t][i.LessThan]=n[i.NotEqualTo],delete e[t][i.NotEqualTo])})),e};if(W(t)===r.Object){var u=Object.keys(t);if(n(t,u))if(1===u.length)e.where=o(t,u);else{var a=[];u.forEach((function(e){var n;a.push(o(((n={})[e]=t[e],n),[e]))})),e.where=a}}else{var c=[];t.forEach((function(e){var t=Object.keys(e);n(e,t)&&(e=o(e,t)),c.push(e)})),e.where=c}},e.prototype.checkInsertQuery=function(e){var t=this.isInsertQryValid(e),n=t.table,r=t.log;if(r)return r;if(!e.skipDataCheck){var o=new B(n,n.autoIncColumnValue).checkAndModifyValues(e),u=o.values,i=o.err;return e.values=u,i}},e}(),G=(O=function(e,t){return O=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},O(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}O(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),K=function(e){function t(t,n){var r=e.call(this)||this;return r.valuesAffected_=[],null==t.validation&&(t.validation=!0),r.query=t,r.util=n,r.tableName=t.into,r}return G(t,e),t.prototype.execute=function(e){var t=this,n=this.db,r=new M(n).validate(o.Insert,this.query);return r?L(r):e().then((function(e){return t.insertData_(n).then((function(e){return t.query.return?t.valuesAffected_:t.rowAffected}))})).catch((function(e){return t.util.abortTransaction(),L(e)}))},t.prototype.insertData_=function(e){var t,n,r,o=this,u=this.query;return t=u.return?function(e){o.valuesAffected_.push(e)}:function(e){++o.rowAffected},r=u.upsert?"put":"add",n=u.ignore&&!o.isTxQuery?function(e){return o.util.con.transaction(u.into,a.ReadWrite).objectStore(u.into)[r](e)}:(o.isTxQuery||o.util.createTransaction([u.into,j.tableName]),o.objectStore=o.util.objectStore(o.tableName),function(e){return o.objectStore[r](e)}),Q(u.values.map((function(e){return f((function(r,o){var i=n(e);i.onerror=function(e){u.ignore?r():o(e)},i.onsuccess=function(){t(e),r()}}))}))).then((function(){return j.set(j.dbSchema,e,o.util)}))},t}(D),J=void 0===self.alert&&"undefined"==typeof ServiceWorkerGlobalScope,F=function(){try{if(indexedDB||(indexedDB=self.mozIndexedDB||self.webkitIndexedDB||self.msIndexedDB),!indexedDB)return!1;IDBTransaction=IDBTransaction||self.webkitIDBTransaction||self.msIDBTransaction,self.IDBKeyRange=self.IDBKeyRange||self.webkitIDBKeyRange||self.msIDBKeyRange}catch(e){return!1}return!0}(),U=function(e){return Array.isArray(e)},H=function(e){return Object.keys(e)},z=function(e){return H(e).length},$=function(){function e(){}return e.prototype.setCaseAndValue=function(e,t){this.caseQuery_=e,this.setValue(t)},e.prototype.setCaseAndColumn=function(e,t){return this.caseQuery_=e,this.setColumn(t),this},e.prototype.setColumn=function(e){return this.columnName_=e,this.caseColumnQuery_=this.caseQuery_[this.columnName_],this.length_=this.caseColumnQuery_.length,this},e.prototype.setValue=function(e){return this.value=e,this},e.prototype.evaluate=function(){for(var e=0;e<this.length_;e++)if(!0===this.checkCase_(this.caseColumnQuery_[e]))return this.caseColumnQuery_[e].then;var t=this.caseColumnQuery_[this.length_-1].then;return null==t?this.value[this.columnName_]:t},e.prototype.checkCase_=function(e){var t;for(t in e){switch(t){case i.GreaterThan:if(this.value[this.columnName_]>e[t])return!0;break;case i.Equal:if(this.value[this.columnName_]===e[t])return!0;break;case i.LessThan:if(this.value[this.columnName_]<e[t])return!0;break;case i.GreaterThanEqualTo:if(this.value[this.columnName_]>=e[t])return!0;break;case i.LessThanEqualTo:if(this.value[this.columnName_]<=e[t])return!0;break;case i.NotEqualTo:if(this.value[this.columnName_]!==e[t])return!0;break;case i.Between:if(this.value[this.columnName_]>e[t].low&&this.value[this.columnName_]<e[t].high)return!0}return!1}},e}(),X=function(e,t,n,r){if(!1===this.limitAtEnd&&!1===this.skipAtEnd){if(this.skipRecord)return this.limitRecord?r:n;if(this.limitRecord)return t}return e},Y=function(e){var t=this,n=!1;return function(r){var o=r.target.result;o?n&&t.results.length!==t.limitRecord?(t.shouldAddValue(o)&&t.pushResult(o.value),o.continue()):(n=!0,o.advance(t.skipRecord)):e()}},Z=function(e){var t=this,n=!1;return function(r){var o=r.target.result;o?n?(t.shouldAddValue(o)&&t.pushResult(o.value),o.continue()):(n=!0,o.advance(t.skipRecord)):e()}},ee=function(e){var t=this;return function(n){var r=n.target.result;r&&t.results.length!==t.limitRecord?(t.shouldAddValue(r)&&t.pushResult(r.value),r.continue()):e()}},te=function(e){var t=this;return function(n){var r=n.target.result;r?(t.shouldAddValue(r)&&t.pushResult(r.value),r.continue()):e()}},ne=function(e){var t,n=this,r=!1;return function(o){(t=o.target.result)?r&&n.results.length!==n.limitRecord?(n.pushResult(t.value),t.continue()):(r=!0,t.advance(n.skipRecord)):e()}},re=function(e){var t,n=this,r=!1;return function(o){(t=o.target.result)?r?(n.pushResult(t.value),t.continue()):(r=!0,t.advance(n.skipRecord)):e()}},oe=function(e){var t,n=this;return function(r){(t=r.target.result)?(n.pushResult(t.value),t.continue()):e()}},ue=function(e){var t,n=this;return function(r){(t=r.target.result)&&n.results.length!==n.limitRecord?(n.pushResult(t.value),t.continue()):e()}},ie=function(e){return e.replace(/\s/g,"")},ae=function(e){var t;if(!this.query.store)if(null==this.query.join)t=this.getColumnInfo(e);else{var n=ie(e).split("."),r=n[1];t=this.getColumnInfo(r,n[0])}if(null==t){var o=this.results[0][e];if(o)return{dataType:W(o),name:e};throw new I(y,{column:e,isOrder:!0})}return t},ce=function(e,t){return t.localeCompare(e)},se=function(e,t){return e.localeCompare(t)},le=function(e,t){return new String(t).localeCompare(e)},fe=function(e,t){return new String(e).localeCompare(t)},he=function(e,t){return t-e},pe=function(e,t){return e-t},ye=function(e,t){return t.getTime()-e.getTime()},de=function(e,t){return e.getTime()-t.getTime()},ve=function(e,t){switch(e.dataType){case r.String:return"asc"===t.type?se:ce;case r.Number:return"asc"===t.type?pe:he;case r.DateTime:return"asc"===t.type?de:ye;default:return"asc"===t.type?fe:le}},me=function(e){var t;e.type=be(e.type);var n=e.by,o=this.thenEvaluator;if(null!=n&&typeof n===r.Object){var u=n,i=function(e,t){return function(n,i){for(var a in u){o.setCaseAndValue(u,n);var c=o.setColumn(a).evaluate();o.setCaseAndValue(u,i);var s=o.setColumn(a).evaluate();return typeof n[c]===r.String?e(n[c],i[s]):t(n[c],i[s])}}},a="asc"===e.type?i(se,pe):i(ce,he);this.results.sort(a)}else{var c=ae.call(this,n);if(null!=c){var s=ve(c,e);n=c.name,null==e.case?this.results.sort((function(e,t){return s(e[n],t[n])})):(o.setCaseAndColumn(((t={})[n]=e.case,t),n),this.results.sort((function(e,t){return s(o.setValue(e).evaluate(),o.setValue(t).evaluate())})))}}},be=function(e){return null==e?"asc":e.toLowerCase()},ge=function(e){for(var t in e)return t},we=function(e){var t,n,r=e.split("%");switch(r[1]?(t=r[1],n=r.length>2?c.Any:c.Last):(t=r[0],n=c.First),n){case c.First:return new RegExp("^".concat(t),"i");case c.Last:return new RegExp("".concat(t,"$"),"i");default:return new RegExp("".concat(t),"i")}},_e=function(e){return"object"===W(e)&&!(e instanceof RegExp)},xe=function(e){if(_e(e)){var t={};for(var n in e)t[n]=null!=e[n]&&_e(e[n])?xe(e[n]):e[n];return t}return e},ke=function(e,t,n){var o=W(e);if(o!==W(t))return!1;switch(o===r.DateTime&&(e=e.getTime(),t=t.getTime()),n){case i.GreaterThan:return e>t;case i.LessThan:return e<t;case i.LessThanEqualTo:return e<=t;case i.GreaterThanEqualTo:return e>=t;case i.NotEqualTo:return e!==t;default:var u;return"array"===o?e.length===t.length&&(e.every((function(e,n){return u=e===t[n]})),u):e===t}},Te=function(){function e(e,t){this.where=xe(e),this.checkFlag=t}return e.prototype.remove=function(e){var t=e.pop();delete e.reduce((function(e,t){return e&&e[t]}),this.where)[t]},e.prototype.check=function(e){var t=this,n=!0;if(!this.checkFlag)return n;var r=this.where,o=function(o){if(!n)return{value:n};var u=r[o],a=e[o],c=U(a),s=U(u),l=function(e){c&&!s?a.every((function(t){return!(n=e(t))})):n=e(a)};if("object"===W(u)){var f=function(e){if(!n)return{value:n};switch(e){case i.In:l((function(e){return t.checkIn(u[i.In],e)}));break;case i.Like:l((function(e){return t.checkLike_(o,e)}));break;case i.Regex:l((function(e){return t.checkRegex(o,e)}));break;case i.Between:case i.GreaterThan:case i.LessThan:case i.GreaterThanEqualTo:case i.LessThanEqualTo:case i.NotEqualTo:l((function(n){return t.checkComparisionOp_(o,n,e)}));break;default:n=!1}};for(var h in u){var p=f(h);if("object"==typeof p)return p}}else l((function(e){return ke(u,e)}))};for(var u in r){var a=o(u);if("object"==typeof a)return a.value}return n},e.prototype.checkIn=function(e,t){return null!=e.find((function(e){return ke(e,t)}))},e.prototype.checkLike_=function(e,t){return we(this.where[e][i.Like]).test(t)},e.prototype.checkRegex=function(e,t){return this.where[e][i.Regex].test(t)},e.prototype.checkComparisionOp_=function(e,t,n){var r=this.where[e][n];return n!=i.Between?ke(t,r,n):ke(t,r.low,">=")&&ke(t,r.high,"<=")},e}(),Se=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Ee=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.limitAtEnd=!1,t.skipAtEnd=!1,t}return Se(t,e),t.prototype.goToWhereLogic=function(){var e=this,t=this.query,n=t.where,r=function(){for(var t in n)if(e.objectStore.indexNames.contains(t))return t}();if(null==r&&(r=ge(n),!t.store))return L(new I(d,{column:r}));var o=n[r];if("object"!==W(o))return u=z(n)>1,this.whereChecker=new Te(n,u),this.whereChecker.remove([r]),this.executeWhereLogic(r,o,null,"next");var u=z(o)>1||z(n)>1;this.whereChecker=new Te(n,u);var a=ge(o);switch(this.whereChecker.remove([r,a]),a){case i.Like:var c=we(o[i.Like]);return this.executeRegexLogic(r,c);case i.Regex:return this.executeRegexLogic(r,o[i.Regex]);case i.In:return this.executeInLogic(r,o[i.In]);case i.Between:case i.GreaterThan:case i.LessThan:case i.GreaterThanEqualTo:case i.LessThanEqualTo:return this.executeWhereLogic(r,o,a,"next");case i.Aggregate:break;default:return this.executeWhereLogic(r,o,null,"next")}},t}(D),Oe=function(e,t){var n=this;return function(r){var o=r.target.result;n.results.length!==n.limitRecord&&o?(n.shouldAddValue(o)&&t(o.value),o.continue()):e()}},Ce=function(e,t){var n=this;return function(r){var o=r.target.result;o?(n.shouldAddValue(o)&&t(o.value),o.continue()):e()}},je=function(){return je=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},je.apply(this,arguments)},Ae=function(){function e(e){this.joinQueryStack_=[],this.currentQueryStackIndex_=0,this.tablesFetched=[],this.results=[],this.select=e}return Object.defineProperty(e.prototype,"query",{get:function(){return this.select.query},enumerable:!1,configurable:!0}),e.prototype.getTable=function(e){return this.select.table(e)},e.prototype.executeSelect=function(e){return new Qe(e,this.select.util).execute()},e.prototype.execute=function(){var e=this,t=this.query;this.joinQueryStack_=W(t.join)===r.Object?[t.join]:t.join;var n=t.from,o=[];n&&o.push(n);for(var u=this.joinQueryStack_,i=0,a=u.length;i<a;i++){var c=u[i],s=this.getJoinTableInfo_(c.on);c.with===s.table1.table&&(s={table1:s.table2,table2:s.table1});var l=this.checkJoinQuery_(s,c);if(l)return L(l);u[i].joinTableInfo=s,c.with&&o.push(c.with)}!this.select.isTxQuery&&o.length>0&&this.select.util.createTransaction(o);var f=t.where;if(f&&!t.store){var h=this.getTable(n),p=function(e){var t;if(Array.isArray(e))t=[],e=e.filter((function(e){var n=p(e);return Object.keys(n.whereQryAfterJoin).length>0&&t.push(n.whereQryAfterJoin),!n.isWhereEmpty}));else{t={};var n=function(n){if("or"===n){var r={},o=e[n],u=function(e){h.columns.find((function(t){return t.name===e}))||(r[e]=o[e])};for(var i in o)u(i);if(z(r)>0)for(var i in t.or=r,r)delete o[i]}else h.columns.find((function(e){return e.name===n}))||(t[n]=f[n])};for(var r in e)n(r);for(var r in t)delete e[r]}return{isWhereEmpty:0===z(e),whereQryAfterJoin:t,whereQueryModified:e}},y=p(f),d=y.whereQryAfterJoin;t.where=y.whereQueryModified,y.isWhereEmpty&&delete t.where;var v=this.joinQueryStack_[0];Object.assign(v.whereJoin,d)}return this.executeSelect({from:n,where:t.where,case:t.case,flatten:t.flatten,store:t.store,meta:t.meta}).then((function(t){return e.results=t.map((function(t){var n;return(n={})[e.currentQueryStackIndex_]=t,n})),e.tablesFetched.push(u[0].joinTableInfo.table1.table),e.startExecutingJoinLogic_()}))},e.prototype.onJoinQueryFinished_=function(){if(0!==this.results.length){var e=this.select;try{var t=[],n=H(this.results[0]).length;this.results.forEach((function(e){for(var r=e[0],o=1;o<n;o++)r=je(je({},r),e[o]);t.push(r)})),e.results=t,e.setLimitAndSkipEvaluationAtEnd_(),e.query.flatten=null,e.processOrderBy()}catch(e){return console.error(e),L(new I(k,e.message))}}},e.prototype.startExecutingJoinLogic_=function(){var e=this,t=this.joinQueryStack_[this.currentQueryStackIndex_];if(!t)return this.onJoinQueryFinished_();try{var n=t.joinTableInfo;return this.executeSelect({from:t.with,where:t.where,case:t.case,flatten:t.flatten,store:t.store,meta:t.meta}).then((function(r){return e.jointables(t,n,r),e.tablesFetched.push(n.table2.table),++e.currentQueryStackIndex_,e.startExecutingJoinLogic_()}))}catch(e){return console.error(e),L(new I(k,e.message))}},e.prototype.jointables=function(e,t,n){var r,o,u,i,a=e.type,c=[],s=t.table1.column,l=t.table2.column,f=this.tablesFetched.indexOf(t.table1.table),h=this.currentQueryStackIndex_+1,p=e.as,y=p?function(e){for(var t in p){var n=p[t];void 0===e[n]&&(e[n]=e[t],delete e[t])}return e}:function(e){return e},d=0,v=Object.assign({},e.whereJoin),m=new Te(v,z(v)>0);"left"===a?(i={},e.store?H(e.store).forEach((function(e){i[e]=null})):this.getTable(t.table2.table).columns.forEach((function(e){i[e.name]=null})),o=1===h?function(e,t){return t[f][s]===e[l]}:function(e,t){var n=t[f];return null!=n&&n[s]===e[l]},u=function(){0===r.length&&(r=[i])}):(o=function(e,t){return t[f][s]===e[l]},u=function(){}),this.results.forEach((function(e){r=[],n.forEach((function(t){o(t,e)&&r.push(je({},t))})),u(),r.forEach((function(t){t=y(t),m.check(t)&&(c[d]=je({},e),c[d++][h]=t)}))})),this.results=c},e.prototype.getJoinTableInfo_=function(e){var t=(e=ie(e)).split("="),n=t[0].split("."),r=t[1].split(".");return{table1:{table:n[0],column:n[1]},table2:{table:r[0],column:r[1]}}},e.prototype.checkJoinQuery_=function(e,t){if(t.store)return null;var n,r=e.table1,o=e.table2,u=this.getTable(r.table),i=this.getTable(o.table);t.with!==o.table&&(n=new I(k,"The 'on' condition must reference a column from the table specified in 'with'. Found '".concat(t.on,"', but '").concat(t.with,"' was provided in 'with'."))),null==u.columns.find((function(e){return e.name===r.column}))?n=new I(k,"column ".concat(r.column," does not exist in table ").concat(r.table)):null==i.columns.find((function(e){return e.name===o.column}))&&(n=new I(k,"column ".concat(o.column," does not exist in table ").concat(o.table))),null==t.as&&(t.as={}),u.columns.every((function(e){var u=i.columns.find((function(t){return t.name===e.name&&t.name!==r.column}));return null==u||null!=t.as[u.name]||(n=new I(k,"column ".concat(e.name," exist in both table ").concat(r.table," & ").concat(o.table)),!1)}));var a=t.where;if(a){var c,s=function(e,t){var n=function(n){switch(n){case"or":case"in":break;default:i.columns.find((function(e){return e.name===n}))||(t[n]=e[n],delete e[n])}};for(var r in e)n(r)};Array.isArray(a)?(c=[],a=a.filter((function(e){var t={};return s(e,t),0!==z(t)&&c.push(t),0!==z(e)}))):s(a,c={}),0===z(a)&&(t.where=null),t.whereJoin=c}else t.whereJoin={};return n},e}(),qe=function(){function e(e){this.data=e}return Object.defineProperty(e.prototype,"indexNames",{get:function(){var e=H(this.data[0]);return{contains:function(t){return e.indexOf(t)>=0}}},enumerable:!1,configurable:!0}),e.prototype.index=function(e){var t=this;return{openCursor:function(n){var r={},o=0,u={continue:function(){++o,a()}},i=function(e){r.onsuccess({target:{result:e}})},a=function(){var r=t.data[o];if(r){var a=r[e];a&&(null==n||n.includes(a))?(u.key=a,u.value=r,i(u)):u.continue()}else i(null)};return l().then(a),r}}},e}(),Ie=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Re=function(){return Re=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Re.apply(this,arguments)},Qe=function(e){function t(t,n){var r=e.call(this)||this;r.sorted=!1,r.isSubQuery=!1,r.thenEvaluator=new $,r.returnResult_=function(){if(r.results.length>0){var e=r.query;if(e.flatten){var t=[],n=new Map;e.flatten.forEach((function(e){r.results.forEach((function(r,o){r[e].forEach((function(n){var o;t.push(Re(Re({},r),((o={})[e]=n,o)))})),n.set(o,!0)}))}));var o=0;n.forEach((function(e,t){r.results.splice(t-o,1),++o})),r.results=r.results.concat(t)}r.processGroupDistinctAggr(),r.processOrderBy(),r.skipAtEnd&&r.results.splice(0,e.skip),r.limitAtEnd&&(r.results=r.results.slice(0,e.limit))}return r.results},r.query=t,r.util=n,r.tableName=t.from,r.setPushResult(),U(t.where)?(r.isArrayQry=!0,r.setLimitAndSkipEvaluationAtEnd_()):(r.skipRecord=t.skip,r.limitRecord=t.limit);var o=t.order;return o?((U(o)||o.case||"object"==typeof o.by)&&(o.idbSorting=!1),r.setLimitAndSkipEvaluationAtEnd_()):t.groupBy&&r.setLimitAndSkipEvaluationAtEnd_(),r}return Ie(t,e),t.prototype.execute=function(e){var t=this;e||(e=function(){return l(null)});var n=this.query;try{var r=new M(this.db).validate(o.Select,n);return r?L(r):e().then((function(e){return t.initTransaction_(),(null==n.join?null!=n.where?U(n.where)?t.processWhereArrayQry():t.processWhere_():t.executeWhereUndefinedLogic():t.executeJoinQuery()).then(t.returnResult_.bind(t))}))}catch(e){return this.onException(e)}},t.prototype.processWhereArrayQry=function(){var e=this;this.isArrayQry=!0;var n,r=this.query.where,o=this.primaryKey(),u=!0,a=[],c=function(){var t;return n===i.And?!0===u?a=e.results:a.length>0&&(t=[],e.results.forEach((function(e){var n;n=e[o],a.findIndex((function(e){return e[o]===n}))>=0&&t.push(e)})),a=t,t=null):(a.length>0&&e.mergeWithResults(a),a=e.results),u=!1,r.length>0?(e.results=[],f()):(e.results=a,l())},s=function(n){return new t({from:e.query.from,where:n},e.util).execute().then((function(t){return e.results=t,c()}))},f=function(){var t=r.shift(),o=t[i.Or];if(o){if(U(o))return n=i.Or,s(o);1===z(t)?(n=i.Or,t=o):n=i.And}else if(n=i.And,U(t))return s(t);return e.query.where=t,e.processWhere_().then(c)};return f()},t.prototype.initTransaction_=function(){var e=this.query.store;e?this.objectStore=new qe(e):(this.isTxQuery||this.util.createTransactionIfNotExist([this.tableName],a.ReadOnly),this.objectStore=this.util.objectStore(this.tableName))},t.prototype.processWhere_=function(){var e=this;return this.shouldAddValue=function(t){var n=t.value,r=e,o=new Proxy(n,{get:function(e,t,o){var u=n[t];if(!u){var i=r.getColumnInfo(t);if(i&&i.keyPath)return i.keyPath.map((function(e){return n[e]}))}return u}});return e.whereChecker.check(o)},this.query.where.or&&this.processOrLogic_(),this.goToWhereLogic().then((function(){return e.onWhereEvaluated()}))},t.prototype.onWhereEvaluated=function(){if(this.isOr)return this.orQuerySuccess_()},t.prototype.orQuerySuccess_=function(){var e=this,n=this.query,r=this.orInfo;return this.results.length>0&&this.mergeWithResults(r.results),new t({where:r.orQuery,from:n.from,case:n.case,store:n.store,meta:n.meta},this.util).execute().then((function(t){e.mergeWithResults(t),e.isOr=!1,e.orInfo=null}))},t.prototype.processOrLogic_=function(){this.isOr=!0;var e=this.query.where;this.orInfo={orQuery:e.or,results:[]},this.setLimitAndSkipEvaluationAtEnd_(),delete e.or},t}(Ee);function Le(e){var t=1===z(e);if(t){var n=ge(e);t=1===z(e[n])}return t}Qe.prototype.executeInLogic=function(e,t){var n=this,r=this.skipRecord,o=function(e){0===r?n.pushResult(e):--r},u=X.call(this,te,ee,Ce,Oe);return Q(t.map((function(t){return f((function(r,i){var a=n.objectStore.index(e).openCursor(n.util.keyRange(t));a.onsuccess=u.call(n,r,o),a.onerror=i}))})))},Qe.prototype.executeWhereUndefinedLogic=function(){var e,t=this,n=this.query,r=n.store;if(r)return this.results=r,this.setLimitAndSkipEvaluationAtEnd_(),l();var o=n.order,u=this.objectStore;if(o&&!1!==o.idbSorting&&o.by){if(!u.indexNames.contains(o.by))return L(new I(y,{column:o.by,isOrder:!0}));var i=o.type&&"desc"===o.type.toLowerCase()?"prev":"next";this.sorted=!0,e=u.index(o.by).openCursor(null,i)}else e=u.openCursor();var a=X.call(this,oe,ue,re,ne);return f((function(n,r){e.onerror=r,e.onsuccess=a.call(t,n)}))},Qe.prototype.executeWhereLogic=function(e,t,n,r){var o=this;t=n?t[n]:t;var u=this.objectStore.index(e).openCursor(this.util.keyRange(t,n),r),i=X.call(this,te,ee,Z,Y);return f((function(e,t){u.onerror=t,u.onsuccess=i.call(o,e)}))},Qe.prototype.executeRegexLogic=function(e,t){var n=this,r=this.skipRecord,o=function(e){0===r?n.pushResult(e):--r};this.shouldAddValue=function(e){return t.test(e.key)&&n.whereChecker.check(e.value)};var u=this.objectStore.index(e).openCursor(),i=X.call(this,te,ee,Ce,Oe);return f((function(e,t){u.onerror=t,u.onsuccess=i.call(n,e,o)}))},Qe.prototype.setLimitAndSkipEvaluationAtEnd_=function(){this.query.limit&&(this.limitAtEnd=!0),this.query.skip&&(this.skipAtEnd=!0)},Qe.prototype.setPushResult=function(){var e=this,t=this.query.case;this.pushResult=t?function(n){var r;for(r in e.thenEvaluator.setCaseAndValue(t,n),t)n[r]=e.thenEvaluator.setColumn(r).evaluate();e.results.push(n)}:function(t){e.results.push(t)}},Qe.prototype.mergeWithResults=function(e){var t=this.results,n=this.primaryKey(),r=new Map;t.forEach((function(e){r.set(e[n],1)})),e.forEach((function(e){r.has(e[n])||t.push(e)}))},Qe.prototype.executeJoinQuery=function(){return new Ae(this).execute()},Qe.prototype.processGroupDistinctAggr=function(){var e=this.query;if(e.distinct){var t=[],n=this.results[0];for(var r in n)t.push(r);var o=this.primaryKey(),u=t.indexOf(o);t.splice(u,1),e.groupBy=t.length>0?t:null}e.groupBy?e.aggregate?this.executeAggregateGroupBy():this.processGroupBy():e.aggregate&&this.processAggregateQry()},Qe.prototype.processOrderBy=function(){var e=this.query.order;if(e&&this.results.length>0&&!this.sorted){var t=W(e);if(t===r.Object)me.call(this,e);else if(t===r.Array){me.call(this,e[0]);for(var n=function(t,n){var r=e[t-1].by,u=e[t],i=u.by,a=ae.call(o,i);if(null!=a){i=a.name,u.type=be(u.type);var c=ve(a,u);o.results.sort((function(e,t){return e[r]===t[r]?c(e[i],t[i]):0}))}},o=this,u=1,i=e.length;u<i;u++)n(u)}}},Qe.prototype.processAggregateQry=function(){var e,t=this.results,n=t.length,o={},u=function(){var n=0;for(var r in t)n+=t[r][e]?1:0;return n},i=function(){var n=0;for(var r in t)n=n>t[r][e]?n:t[r][e];return n},a=function(){var n=1/0,r=1/0;for(var o in t)n=n<(r=t[o][e]?t[o][e]:1/0)?n:r;return n},c=function(){var n=0;for(var r in t)n+=t[r][e];return n},s=function(){return c()/n},l=this.query.aggregate;for(var f in l){var h=l[f],p=W(h),y=void 0;switch(f){case"count":y=u;break;case"max":y=i;break;case"min":y=a;break;case"sum":y=c;break;case"avg":y=s}switch(p){case r.String:e=h,o["".concat(f,"(").concat(e,")")]=y();break;case r.Array:for(var d in h)e=h[d],o["".concat(f,"(").concat(e,")")]=y()}}for(var f in o)t[0][f]=o[f];this.results=[t[0]]},Qe.prototype.executeAggregateGroupBy=function(){var e,t,n,o,u=this.query.groupBy,a=this.results,c=new Map,s=this.query.aggregate,l=function(){var u=function(){return n=(n=c.get(t))?n["count("+o+")"]:0,n+=a[e][o]?1:0},l=function(){return(n=(n=c.get(t))?n["list("+o+")"]:[]).push(a[e][o]),n},f=function(){return n=(n=c.get(t))?n["max("+o+")"]:0,a[e][o]=a[e][o]?a[e][o]:0,n>a[e][o]?n:a[e][o]},h=function(){return n=(n=c.get(t))?n["min("+o+")"]:1/0,a[e][o]=a[e][o]?a[e][o]:1/0,n<a[e][o]?n:a[e][o]},p=function(){return n=(n=c.get(t))?n["sum("+o+")"]:0,n+=a[e][o]?a[e][o]:0},y=function(){var r=(n=c.get(t))?n["sum("+o+")"]:0;r+=a[e][o]?a[e][o]:0,a[e]["sum("+o+")"]=r,n=n?n["count("+o+")"]:0,n+=a[e][o]?1:0,a[e]["count("+o+")"]=n};for(var d in s){var v=s[d],m=W(v),b=void 0;switch(d){case i.Count:b=u;break;case i.Max:b=f;break;case i.Min:b=h;break;case i.Sum:b=p;break;case i.Avg:b=y;break;case i.List:b=l}switch(m){case r.String:o=v,a[e]["".concat(d,"(").concat(o,")")]=b();break;case r.Array:for(var g in v)o=v[g],a[e]["".concat(d,"(").concat(o,")")]=b()}}};if(W(u)===r.String)for(e in a)t=a[e][u],l(),c.set(t,a[e]);else for(e in a){for(var f in t="",u)t+=a[e][u[f]];l(),c.set(t,a[e])}a=Array.from(c.values());var h=s.avg;if(h)if(W(h)===r.String)for(e in a){var p=a[e]["sum("+h+")"],y=a[e]["count("+h+")"];a[e]["avg("+h+")"]=p/y,s.count!==h&&delete a[e]["count("+h+")"],s.sum!==h&&delete a[e]["sum("+h+")"]}else{var d=W(s.count)===r.String,v=W(s.sum)===r.String;for(e in a)for(var f in h){var m=h[f],b=a[e]["sum("+m+")"],g=a[e]["count("+m+")"];a[e]["avg("+m+")"]=b/g,d&&(s.count!==m||-1===s.count.indexOf(m))&&delete a[e]["count("+m+")"],v&&(s.sum!==m||-1===s.sum.indexOf(m))&&delete a[e]["sum("+m+")"]}}this.results=a},Qe.prototype.processGroupBy=function(){var e=this.query.groupBy,t=this.results,n=new Map,o=W(e);if(o!==r.Object)if(o===r.String)for(var u in t)n.set(t[u][e],t[u]);else{var i=void 0;for(var u in t){for(var a in i="",e)i+=t[u][e[a]];n.set(i,t[u])}}else if(1===Object.keys(e).length){var c=ge(e);for(var u in this.thenEvaluator.setCaseAndColumn(e,c),t)n.set(this.thenEvaluator.setValue(t[u]).evaluate(),t[u])}else for(var u in i=void 0,t){for(var a in i="",this.thenEvaluator.setCaseAndValue(e,t[u]),e)i+=this.thenEvaluator.setColumn(a).evaluate();n.set(i,t[u])}this.results=Array.from(n.values())};var Ne=function(e){var t=this;return function(n){var r=n.target.result;r?(t.shouldAddValue(r)&&++t.resultCount,r.continue()):e()}},De=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),We=function(e){function t(t,n){var r=e.call(this)||this;return r.resultCount=0,r.query=t,r.util=n,r.tableName=t.from,r}return De(t,e),t.prototype.execute=function(e){var t=this,n=new M(this.db),r=this.query,u=n.validate(o.Count,r);return u?L(u):e().then((function(e){var n;try{var o=function(){var e=new Qe(r,t.util);return e.isTxQuery=t.isTxQuery,e.execute().then((function(e){t.resultCount=e.length}))};t.initTransaction_(),null==r.join?null!=r.where?r.where.or||U(r.where)?n=o():(t.shouldAddValue=function(e){return t.whereChecker.check(e.value)},n=t.goToWhereLogic()):n=t.executeWhereUndefinedLogic():n=o()}catch(e){t.onException(e)}return n.then((function(e){return t.resultCount}))}))},t.prototype.initTransaction_=function(){var e=this.query.from;this.isTxQuery||this.util.createTransaction([e],a.ReadOnly),this.objectStore=this.util.objectStore(e)},t}(Ee);We.prototype.executeWhereUndefinedLogic=function(){var e,t,n=this,r=this.objectStore,o=r.count?(e=r.count(),function(t){return function(){n.resultCount=e.result,t()}}):(e=r.openCursor(),function(e){return function(r){(t=r.target.result)?(++n.resultCount,t.continue()):e()}});return f((function(t,n){e.onerror=n,e.onsuccess=o(t)}))},We.prototype.executeWhereLogic=function(e,t,n){var r,o=this;t=n?t[n]:t;var u=Le(this.query.where),i=this.objectStore;return f((function(a,c){u&&i.count?(r=i.index(e).count(o.util.keyRange(t,n))).onsuccess=function(){o.resultCount=r.result,a()}:(r=i.index(e).openCursor(o.util.keyRange(t,n))).onsuccess=Ne.call(o,a),r.onerror=c}))},We.prototype.executeRegexLogic=function(e,t){var n=this,r=this.objectStore.index(e).openCursor();return this.shouldAddValue=function(e){return t.test(e.key)&&n.whereChecker.check(e.value)},f((function(e,t){r.onerror=t,r.onsuccess=Ne.call(n,e)}))},We.prototype.executeInLogic=function(e,t){var n=this,r=this.objectStore,o=r.index(e),u=Le(this.query.where);return Q(t.map((function(e){return t=e,i=n.util.keyRange(t),u&&r.count?f((function(e,t){var r=o.count(i);r.onsuccess=function(t){n.resultCount+=t.target.result,e()},r.onerror=t})):f((function(e,t){var r=o.openCursor(i);r.onsuccess=Ne.call(n,e),r.onerror=t}));var t,i})))};var Ve=function(e){return(U(e)?e:e.split(".")).reduce((function(e,t){return e&&e[t]}),self)},Be=function(e,t){var n=e.set,o=e.mapSet;if(o){var u=o(n,t);null!=u&&(n=u)}for(var i in n){var a=n[i];if(W(a)!==r.Object)t[i]=a;else for(var c in a){var s=a[c];switch(c){case"+":t[i]+=s;break;case"-":t[i]-=s;break;case"*":t[i]*=s;break;case"/":t[i]/=s;break;case"{push}":t[i].push(s);break;default:t[i]=a}break}}return t},Pe=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Me=function(e){function t(t,n){var o=e.call(this)||this;t.returnImmediate=null!=t.returnImmediate&&t.returnImmediate,o.query=t,o.util=n,o.tableName=t.in;var u=t.mapSet;if(u){var i=W(u)===r.String?Ve(u):u;if(!i)throw new I(S,u);t.mapSet=i}return o}return Pe(t,e),t.prototype.execute=function(e){var t=this,n=this.query;try{var r=new M(this.db).validate(o.Update,n);return r?L(r):e().then((function(e){var r=t.initTransaction(),o=[null!=n.where?n.where.or||U(n.where)?t.executeComplexLogic_():t.goToWhereLogic():t.executeWhereUndefinedLogic()];return!1===n.returnImmediate&&r&&o.push(r),Q(o).then((function(){return t.rowAffected}))}))}catch(e){return this.onException(e)}},t.prototype.executeComplexLogic_=function(){var e=this,t=this.query,n=new Qe({from:t.in,where:t.where,ignoreCase:t.ignoreCase},this.util);return n.isTxQuery=this.isTxQuery,n.execute().then((function(n){var r,o,u=e.primaryKey(t.in),a=[];n.forEach((function(e){a.push(e[u])})),n=null;var c=((r={})[u]=((o={})[i.In]=a,o),r);return e.query.where=c,e.goToWhereLogic()}))},t.prototype.initTransaction=function(){var e,t=this.query.in;return this.isTxQuery||(e=this.util.createTransaction([t])),this.objectStore=this.util.objectStore(t),e},t}(Ee);Me.prototype.executeWhereUndefinedLogic=function(){var e=this,t=this.objectStore.openCursor();return f((function(n,r){t.onsuccess=function(t){var o=t.target.result;if(o)try{var u=o.update(Be(e.query,o.value));u.onsuccess=function(){++e.rowAffected,o.continue()},u.onerror=r}catch(e){r(e)}else n()},t.onerror=r}))},Me.prototype.executeWhereLogic=function(e,t,n){var r=this,o=this.query;t=n?t[n]:t;var u=this.objectStore.index(e).openCursor(this.util.keyRange(t,n));return f((function(e,t){u.onsuccess=function(n){var u=n.target.result;if(u)if(r.whereChecker.check(u.value))try{var i=u.update(Be(o,u.value));i.onsuccess=function(){++r.rowAffected,u.continue()},i.onerror=t}catch(e){t(e)}else u.continue();else e()},u.onerror=t}))},Me.prototype.executeRegexLogic=function(e,t){var n,r=this,o=this.objectStore.index(e).openCursor();return this.shouldAddValue=function(e){return t.test(e.key)&&r.whereChecker.check(e.value)},f((function(e,t){o.onsuccess=function(o){if(n=o.target.result)if(r.shouldAddValue(n))try{var u=n.update(Be(r.query,n.value));u.onsuccess=function(){++r.rowAffected,n.continue()},u.onerror=t}catch(e){t(e)}else n.continue();else e()},o.onerror=t}))},Me.prototype.executeInLogic=function(e,t){var n=this,r=this.objectStore.index(e),o=this.query;return Q(t.map((function(e){return t=e,f((function(e,u){var i=r.openCursor(n.util.keyRange(t));i.onsuccess=function(t){var r=t.target.result;if(r){var i=r.value;if(n.whereChecker.check(i))try{var a=r.update(Be(o,i));a.onsuccess=function(){++n.rowAffected,r.continue()},a.onerror=u}catch(e){u(e)}else r.continue()}else e()},i.onerror=u}));var t})))};var Ge=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Ke=function(){return Ke=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ke.apply(this,arguments)},Je=function(e){function t(t,n){var r=e.call(this)||this;return r.query=t,r.util=n,r}return Ge(t,e),t.prototype.execute=function(){var e,t,n=this,r=this.query,o=0,u={},i={},a=!0,c=r.queries,s=c.length;if(c.every((function(e,t){return!(t+1<s&&e.from!==c[t+1].from&&(a=!1,1))})),a){var l=this.primaryKey(c[0].from);e=function(e){return e[l]}}else e=function(e){var t="";for(var n in e)t+=e[n];return t};var f=function(){if(o<s)return(t=new Qe(c[o],n.util)).execute().then((function(t){return u={},t.forEach((function(t){var n=e(t);0===o?i[n]=t:null!=i[n]&&(u[n]=t)})),o>0&&(i=Ke({},u)),++o,f()}));var a,l=[],h=void 0,p=r.skip,y=r.limit,d=!1,v=function(){l.push(u[a])},m=function(){l.length<y?v():d=!0},b=function(e){0===p?e():--p};if(h=r.skip&&r.limit?function(){b((function(){m()}))}:r.limit?m:r.skip?function(){b((function(){v()}))}:function(){v()},y){for(a in u)if(h(a),d)break}else for(a in u)h(a);return t.results=l,Object.assign(t.query,{order:r.order,join:{}}),t.processOrderBy(),t.processGroupDistinctAggr(),t.results};return f()},t}(D),Fe=function(){function e(){}return e.prototype.execute=function(e){return f((function(t,n){var r=indexedDB.deleteDatabase(e);r.onblocked=function(){var e=new I(w);return n(N(e))},r.onerror=function(e){return n(N(e))},r.onsuccess=function(){t()}}))},e}(),Ue=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),He=function(e){function t(t,n){var r=e.call(this)||this;return r.query=t,r.util=n,r}return Ue(t,e),t.prototype.execute=function(){var e,t=this,n=this.query,r=0,o=new Map,u=!0,i=n.length;if(n.every((function(e,t){return!(t+1<i&&e.from!==n[t+1].from&&(u=!1,1))})),u){var a=this.primaryKey(n[0].from);e=function(e){return e[a]}}else e=function(e){var t="";for(var n in e)t+=e[n];return t};var c=function(){return r<n.length?new Qe(n[r++],t.util).execute().then((function(t){return t.forEach((function(t){o.set(e(t),t)})),c()})):Array.from(o.values())};return c()},t}(D),ze=function(e){var t=this;return function(n){var r=n.target.result;r?(t.shouldAddValue(r.value)&&(r.delete(),++t.rowAffected),r.continue()):e()}},$e=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+"