-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsstore.min.js
6 lines (6 loc) · 86.3 KB
/
jsstore.min.js
1
2
3
4
5
6
/*!
* @license :JsStore.js - v1.6.3 - 03/03/2018
* https://github.com/ujjwalguptaofficial/JsStore
* Copyright (c) 2017 @Ujjwal Gupta; Licensed MIT
*/
var __extends=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),KeyStore,KeyStore,KeyStore,KeyStore,KeyStore,KeyStore,KeyStore,KeyStore,KeyStore,KeyStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore,JsStore;!function(e){var t=function(){function t(){}return t.setDbType=function(){self.indexedDB=self.indexedDB||self.mozIndexedDB||self.webkitIndexedDB||self.msIndexedDB,indexedDB?(self.IDBTransaction=self.IDBTransaction||self.webkitIDBTransaction||self.msIDBTransaction,self.IDBKeyRange=self.IDBKeyRange||self.webkitIDBKeyRange||self.msIDBKeyRange):self.alert?JsStore.db_status={ConStatus:JsStore.Connection_Status.UnableToStart,LastError:JsStore.Error_Type.IndexedDbUndefined}:(console.log("worked failed"),self.postMessage("message:WorkerFailed"))},t.updateDbStatus=function(t,r){void 0===r?e.db_status.ConStatus=t:e.db_status={ConStatus:t,LastError:r}},t}();e.Utils=t}(KeyStore||(KeyStore={})),function(e){var t,r;(r=t=e.Connection_Status||(e.Connection_Status={})).Connected="connected",r.Closed="closed",r.NotStarted="not_connected",e.request_queue=[],e.table_name="LocalStore",e.is_code_executing=!1,e.db_status={ConStatus:t.NotStarted,LastError:""}}(KeyStore||(KeyStore={})),function(e){e.prcoessExecutionOfCode=function(t){e.request_queue.push(t),1===e.request_queue.length&&e.executeCode()},e.executeCode=function(){if(!e.is_code_executing&&e.request_queue.length>0){e.is_code_executing=!0;var t={Name:e.request_queue[0].Name,Query:e.request_queue[0].Query};e.executeCodeDirect(t)}},e.executeCodeDirect=function(t){new e.Business.Main(function(e){this.processFinishedRequest(e)}.bind(this)).checkConnectionAndExecuteLogic(t)},e.processFinishedRequest=function(t){var r=e.request_queue.shift();e.is_code_executing=!1,t.ErrorOccured?r.OnError?r.OnError(t.ErrorDetails):console.log(t.ErrorDetails):r.OnSuccess&&r.OnSuccess(t.ReturnedValue),this.executeCode()}}(KeyStore||(KeyStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(){function e(){this._results=null,this._errorOccured=!1,this._errorCount=0}return e.prototype.onErrorOccured=function(e){++this._errorCount,1===this._errorCount&&null!=this._onError&&this._onError(e.target.error),console.error(e)},e}(),t.Base=r}(KeyStore||(KeyStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(e){function r(t,r,n){var s=e.call(this)||this;return s._query=t,s._onSuccess=r,s._onError=n,s}return __extends(r,e),r.prototype.execute=function(){var e=function(e,t){var r=this._objectStore.index(e).openCursor(IDBKeyRange.only(t));r.onerror=function(e){this._errorOccured=!0,this.on_errorOccured(e)}.bind(this),r.onsuccess=function(e){var t=e.target.result;t&&(this._results=t.value.Value)}.bind(this)}.bind(this);for(var t in this.initTransaction(),this._query.Where){e(t,this._query.Where[t]);break}},r.prototype.initTransaction=function(){t.createTransaction([this._query.From],this.onTransactionCompleted.bind(this),"readonly"),this._objectStore=t.db_transaction.objectStore(this._query.From)},r.prototype.onTransactionCompleted=function(){!1===this._errorOccured&&this._onSuccess(this._results)},r}(t.Base),t.Get=r}(KeyStore||(KeyStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(e){function r(t,r,n){var s=e.call(this)||this;try{s._query=t,s._onSuccess=r,s._onError=n}catch(e){console.error(e)}return s}return __extends(r,e),r.prototype.execute=function(){var e=function(){var e=this._objectStore.index("Key").openCursor(IDBKeyRange.only(this._query.Set.Key));e.onsuccess=function(e){var r=e.target.result;r?(r.value.Value=this._query.Set.Value,r.update(r.value)):t()}.bind(this),e.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)}.bind(this),t=function(){this._objectStore.add(this._query.Set).onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)}.bind(this);this.initTransaction(),e()},r.prototype.initTransaction=function(){t.createTransaction([this._query.TableName],this.onTransactionCompleted.bind(this)),this._objectStore=t.db_transaction.objectStore(this._query.TableName)},r.prototype.onTransactionCompleted=function(){!1===this._errorOccured&&this._onSuccess&&this._onSuccess(null)},r}(t.Base),t.Set=r}(KeyStore||(KeyStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(e){function r(t,r,n){var s=e.call(this)||this;return s._rowAffected=0,s._query=t,s._onSuccess=r,s._onError=n,s}return __extends(r,e),r.prototype.execute=function(){this.initTransaction();var e=function(e,t){var r=this._objectStore.index(e).openCursor(IDBKeyRange.only(t));r.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this),r.onsuccess=function(e){var t=e.target.result;t&&(t.delete(),++this._rowAffected,t.continue())}.bind(this)}.bind(this);for(var t in this._query.Where){this._errorOccured||e(t,this._query.Where[t]);break}},r.prototype.initTransaction=function(){t.createTransaction([this._query.From],this.onTransactionCompleted.bind(this)),this._objectStore=t.db_transaction.objectStore(this._query.From)},r.prototype.onTransactionCompleted=function(){!1===this._errorOccured&&this._onSuccess(this._rowAffected)},r}(t.Base),t.Remove=r}(KeyStore||(KeyStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(){return function(r,n,s){var o=self.indexedDB.open(r,1);t.is_db_deleted_by_browser=!1,o.onerror=function(e){"InvalidStateError"===e.target.error.name&&(JsStore.db_status={ConStatus:JsStore.Connection_Status.UnableToStart,LastError:JsStore.Error_Type.IndexedDbBlocked}),null!=s&&s(e.target.error)},o.onsuccess=function(r){e.db_status.ConStatus=e.Connection_Status.Connected,t.db_connection=o.result,t.db_connection.onclose=function(){t.callDbDroppedByBrowser(),e.Utils.updateDbStatus(e.Connection_Status.Closed,JsStore.Error_Type.ConnectionClosed)},t.db_connection.onversionchange=function(r){null===r.newVersion&&(r.target.close(),t.callDbDroppedByBrowser(),e.Utils.updateDbStatus(e.Connection_Status.Closed,JsStore.Error_Type.ConnectionClosed))},t.db_connection.onerror=function(t){e.db_status.LastError="Error occured in connection :"+t.target.result},t.db_connection.onabort=function(t){e.db_status.ConStatus=e.Connection_Status.Closed,e.db_status.LastError="Connection aborted"},null!=n&&n()},o.onupgradeneeded=function(t){t.target.result.createObjectStore(e.table_name,{keyPath:"Key"}).createIndex("Key","Key",{unique:!0})}}}(),t.InitDb=r}(KeyStore||(KeyStore={})),function(e){!function(t){t.db_transaction=null,t.callDbDroppedByBrowser=function(){t.is_db_deleted_by_browser=e.db_status.ConStatus===e.Connection_Status.Connected},t.createTransaction=function(e,r,n){null===t.db_transaction&&(n=n||"readwrite",t.db_transaction=t.db_connection.transaction(e,n),t.db_transaction.oncomplete=function(){t.db_transaction=null,r()},t.db_transaction.ontimeout=function(){t.db_transaction=null,console.error("transaction timed out")})};var r=function(){function r(e){void 0===e&&(e=null),this.executeLogic=function(e){var t=function(e){this.returnResult({ReturnedValue:e})}.bind(this),r=function(e){this.returnResult({ErrorDetails:e,ErrorOccured:!0})}.bind(this);switch(e.Name){case"get":this.get(e.Query,t,r);break;case"set":this.set(e.Query,t,r);break;case"remove":this.remove(e.Query,t,r);break;case"create_db":this.createDb(t,r)}},this._onSuccess=e}return r.prototype.set=function(e,r,n){new t.Set(e,r,n).execute()},r.prototype.remove=function(e,r,n){new t.Remove(e,r,n).execute()},r.prototype.get=function(e,r,n){new t.Get(e,r,n).execute()},r.prototype.createDb=function(e,r){new t.InitDb("KeyStore",e,r)},r.prototype.checkConnectionAndExecuteLogic=function(r){if("create_db"===r.Name||"open_db"===r.Name)this.executeLogic(r);else switch(e.db_status.ConStatus){case e.Connection_Status.Connected:this.executeLogic(r);break;case e.Connection_Status.NotStarted:setTimeout(function(){this.checkConnectionAndExecuteLogic(r)}.bind(this),100);break;case e.Connection_Status.Closed:t.is_db_deleted_by_browser&&this.createDb(function(){t.is_db_deleted_by_browser=!1,this.checkConnectionAndExecuteLogic(r)}.bind(this),function(e){console.error(e)})}},r.prototype.returnResult=function(e){this._onSuccess&&this._onSuccess(e)},r}();t.Main=r}(e.Business||(e.Business={}))}(KeyStore||(KeyStore={})),function(e){e.init=function(){e.Utils.setDbType(),indexedDB&&e.prcoessExecutionOfCode({Name:"create_db",Query:null})},e.get=function(t,r,n){void 0===n&&(n=null);var s={From:e.table_name,Where:{Key:t}};return e.prcoessExecutionOfCode({Name:"get",OnError:n,OnSuccess:r,Query:s}),this},e.set=function(t,r,n,s){var o={Set:{Key:t,Value:r},TableName:e.table_name};return e.prcoessExecutionOfCode({Name:"set",OnError:s,OnSuccess:n,Query:o}),this},e.remove=function(t,r,n){void 0===r&&(r=null),void 0===n&&(n=null);var s={From:e.table_name,Where:{Key:t}};return e.prcoessExecutionOfCode({Name:"remove",OnError:n,OnSuccess:r,Query:s}),this}}(KeyStore||(KeyStore={})),function(e){var t,r,n,s,o;(t=e.Occurence||(e.Occurence={})).First="f",t.Last="l",t.Any="a",(r=e.WebWorker_Status||(e.WebWorker_Status={})).Registered="registerd",r.Failed="failed",r.NotStarted="not_started",(n=e.Connection_Status||(e.Connection_Status={})).Connected="connected",n.Closed="closed",n.NotStarted="not_started",n.UnableToStart="unable_to_start",n.ClosedByJsStore="closed_by_jsstore",(s=e.WhereQryOption||(e.WhereQryOption={})).In="In",s.Like="Like",s.Or="Or",(o=e.Data_Type||(e.Data_Type={})).String="string",o.Object="object",o.Array="array",o.Number="number",o.Boolean="boolean",o.Null="null"}(JsStore||(JsStore={})),function(e){e.enable_log=!1,e.db_version=0,e.db_status={ConStatus:e.Connection_Status.NotStarted,LastError:null},e.setFileName=function(t){e.file_name=t},e.getObjectFirstKey=function(e){for(var t in e)return t;return null},e.log=function(t){e.enable_log&&console.log(t)},e.logError=function(t){e.enable_log&&console.error(t)}}(JsStore||(JsStore={})),function(e){var t=function(){function t(){}return t.updateDbStatus=function(t,r){void 0===r?e.db_status.ConStatus=t:e.db_status={ConStatus:t,LastError:r}},t.changeLogStatus=function(){e.worker_instance&&e.worker_instance.postMessage({Name:"change_log_status",Query:{logging:e.enable_log}})},t}();e.Utils=t}(JsStore||(JsStore={})),function(e){e.isDbExist=function(t,r,n){var s=!r;if(e.db_status.ConStatus!==e.Connection_Status.UnableToStart){if(s)return new Promise(function(r,n){"string"==typeof t?e.getDbVersion(t,function(e){r(Boolean(e))}):e.getDbVersion(t.DbName,function(e){r(t.Table.Version<=e)})});"string"==typeof t?e.getDbVersion.call(this,t,function(e){r.call(this,Boolean(e))}):e.getDbVersion.call(this,t.DbName,function(e){r.call(this,t.Table.Version<=e)})}else{var o={_message:null,_type:e.db_status.LastError};switch(o._type){case e.Error_Type.IndexedDbBlocked:o._message="IndexedDB is blocked";break;case e.Error_Type.IndexedDbUndefined:o._message="IndexedDB is not supported"}if(s)return new Promise(function(e,t){t(o)});n&&n(o)}},e.getDbVersion=function(e,t){KeyStore.get("JsStore_"+e+"_Db_Version",function(e){t.call(this,Number(e))}.bind(this))},e.getDbSchema=function(t,r){r&&KeyStore.get("JsStore_"+t+"_Schema",function(n){if(n)if(n._name)r(n);else{var s=new e.Model.DataBase(n);KeyStore.set("JsStore_"+t+"_Schema",s),r(s)}else r(n)})},e.isNull=function(e){if(null==e)return!0;switch(typeof e){case"string":return 0===e.length;case"number":return isNaN(e)}return!1},e.enableLog=function(){e.enable_log=!0,e.Utils.changeLogStatus()},e.disableLog=function(){e.enable_log=!1,e.Utils.changeLogStatus()},e.setConfig=function(t){t.OnDbDroppedByBrowser&&(t.OnDbDroppedByBrowser=t.OnDbDroppedByBrowser.toString()),e.worker_instance&&e.worker_instance.postMessage({Name:"set_config",Query:t})},e.getType=function(t){if(null===t)return e.Data_Type.Null;var r=typeof t;switch(r){case"object":if(Array.isArray(t))return e.Data_Type.Array;default:return r}}}(JsStore||(JsStore={})),function(e){var t,r;(r=t=e.Error_Type||(e.Error_Type={})).UndefinedColumn="undefined_column",r.UndefinedValue="undefined_value",r.UndefinedColumnName="undefined_column_name",r.UndefinedDbName="undefined_database_name",r.UndefinedColumnValue="undefined_column_value",r.NotArray="not_array",r.NoValueSupplied="no_value_supplied",r.ColumnNotExist="column_not_exist",r.EnableSearchOff="enable_search_off",r.InvalidOp="invalid_operator",r.NullValue="null_value",r.BadDataType="bad_data_type",r.NextJoinNotExist="next_join_not_exist",r.TableNotExist="table_not_exist",r.DbNotExist="db_not_exist",r.IndexedDbUndefined="indexeddb_undefined",r.IndexedDbBlocked="indexeddb_blocked",r.ConnectionAborted="connection_aborted",r.ConnectionClosed="connection_closed",r.NotObject="not_object",r.InvalidConfig="invalid_config";var n=function(){function e(e,r){void 0===r&&(r=null),this.throw=function(){throw this.get()},this.logError=function(){console.error(this.get())},this.logWarning=function(){console.warn(this.get())},this.getMsg=function(){var e;switch(this._type){case t.NotArray:e="Supplied value is not an array";break;case t.UndefinedColumn:e="Column is undefined in Where";break;case t.UndefinedValue:e="Value is undefined in Where";break;case t.UndefinedColumnName:e="Column name is undefined '"+this._info.TableName+"'";break;case t.UndefinedDbName:e="Database name is not supplied";break;case t.UndefinedColumnValue:e="Column value is undefined";break;case t.NoValueSupplied:e="No value supplied";break;case t.InvalidOp:e="Invalid Op Value '"+this._info.Op+"'";break;case t.ColumnNotExist:e="Column '"+this._info.ColumnName+"' does not exist";break;case t.EnableSearchOff:e="Search is turned off for the Column '"+this._info.ColumnName+"'";break;case t.NullValue:e="Null value is not allowed for column '"+this._info.ColumnName+"'";break;case t.BadDataType:e="Supplied value for column '"+this._info.ColumnName+"' does not have valid type";break;case t.NextJoinNotExist:e="Next join details not supplied";break;case t.TableNotExist:e="Table '"+this._info.TableName+"' does not exist";break;case t.DbNotExist:e="Database '"+this._info.DbName+"' does not exist";break;case t.NotObject:e="supplied value is not object";break;case t.InvalidOp:e="Invalid Config '"+this._info.Config+" '";default:e=this._message}return e},this._type=e,this._info=r,this._message=this.getMsg()}return e.prototype.get=function(){return{_message:this._message,_type:this._type}},e}();e.Error=n}(JsStore||(JsStore={})),function(e){var t,r;t=e.Model||(e.Model={}),r=function(){return function(t,r){null!=t.Name?this._name=t.Name:new e.Error(e.Error_Type.UndefinedColumnName,{TableName:r}).throw(),this._autoIncrement=null!=t.AutoIncrement&&t.AutoIncrement,this._primaryKey=null!=t.PrimaryKey&&t.PrimaryKey,this._unique=null!=t.Unique&&t.Unique,this._notNull=null!=t.NotNull&&t.NotNull,this._dataType=null!=t.DataType?t.DataType:t.AutoIncrement?"number":null,this._default=t.Default,this._multiEntry=null!=t.MultiEntry&&t.MultiEntry,this._enableSearch=null==t.EnableSearch||t.EnableSearch}}(),t.Column=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Model||(e.Model={}),r=function(){return function(e){this._columns=[],this._name=e.Name,this._version=null==e.Version?1:e.Version,e.Columns.forEach(function(r){this._columns.push(new t.Column(r,e.Name))},this)}}(),t.Table=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Model||(e.Model={}),r=function(){function t(e){this._columns=[],this._requireDelete=!1,this._requireCreation=!1,this._name=e._name,this._version=e._version,this._columns=e._columns,this.setPrimaryKey()}return t.prototype.createMetaData=function(e,t){this._callback=t,this.setRequireDelete(e),this.setDbVersion(e)},t.prototype.setPrimaryKey=function(){this._columns.every(function(e){return this._primaryKey=e._primaryKey?e._name:"",!e._primaryKey},this)},t.prototype.setRequireDelete=function(e){KeyStore.get("JsStore_"+e+"_"+this._name+"_Version",function(e){null==e?this._requireCreation=!0:e<this._version&&(this._requireDelete=!0)}.bind(this))},t.prototype.setDbVersion=function(t){e.db_version=e.db_version>this._version?e.db_version:this._version,KeyStore.set("JsStore_"+t+"_Db_Version",e.db_version).set("JsStore_"+t+"_"+this._name+"_Version",e.db_version,this._callback),this._version=e.db_version},t}(),t.TableHelper=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Model||(e.Model={}),r=function(){function e(e){this._tables=[],this._name=e._name,this._tables=e._tables}return e.prototype.createMetaData=function(e){var r=0,n=[],s=function(){if(r<this._tables.length){var o=this._tables[r],i=new t.TableHelper(o);i.createMetaData(this._name,function(){i._callback=null,n.push(i),s()}),++r}else e(n)}.bind(this);s()},e}(),t.DbHelper=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Model||(e.Model={}),r=function(){return function(e){this._tables=[],this._name=e.Name,e.Tables.forEach(function(e){this._tables.push(new t.Table(e))},this)}}(),t.DataBase=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(){function r(){this.filterOnOccurence=function(t){var r=!1;switch(t=t.toLowerCase(),this._compSymbol){case e.Occurence.Any:t.indexOf(this._compValue)>=0&&(r=!0);break;case e.Occurence.First:0===t.indexOf(this._compValue)&&(r=!0);break;case e.Occurence.Last:t.lastIndexOf(this._compValue)===t.length-this._compValueLength&&(r=!0);break;default:t!==this._compValue&&(r=!0)}return r}}return r.prototype.containsNot=function(e){var t=!1;return Object.keys(e).every(function(r){return e[r]["!="]&&(t=!0),!t}),t},r.prototype.isTableExist=function(e){var r=!1;return t.active_db._tables.every(function(t){return t._name!==e||(r=!0,!1)}),r},r.prototype.getTable=function(e){var r;return t.active_db._tables.every(function(t){return t._name!==e||(r=t,!1)}),r},r.prototype.getKeyRange=function(e,t){var r;switch(t){case"-":r=IDBKeyRange.bound(e.Low,e.High,!1,!1);break;case">":r=IDBKeyRange.lowerBound(e,!0);break;case">=":r=IDBKeyRange.lowerBound(e);break;case"<":r=IDBKeyRange.upperBound(e,!0);break;case"<=":r=IDBKeyRange.upperBound(e);break;default:r=IDBKeyRange.only(e)}return r},r.prototype.getPrimaryKey=function(e){var t=this.getTable(e)._primaryKey;return t||this.getKeyPath(e)},r.prototype.getKeyPath=function(e){return t.db_connection.transaction([e],"readonly").objectStore(e).keyPath},r.prototype.sortNumberInAsc=function(e){return e.sort(function(e,t){return e-t}),e},r.prototype.sortNumberInDesc=function(e){return e.sort(function(e,t){return t-e}),e},r.prototype.sortAlphabetInAsc=function(e){return e.sort(function(e,t){return e.toLowerCase().localeCompare(t.toLowerCase())}),e},r.prototype.sortAlphabetInDesc=function(e){return e.sort(function(e,t){return t.toLowerCase().localeCompare(e.toLowerCase())}),e},r.prototype.getAllCombinationOfWord=function(e,t){if(t){for(var r=[],n=0,s=e.length;n<s;n++)r=r.concat(this.getCombination(e[n]));return r}return this.getCombination(e)},r.prototype.getCombination=function(e){var t=[],r=function(e,n,s){if(s===e.length)t.push(n.join(""));else{var o=e.charAt(s);n[s]=o.toLowerCase(),r(e,n,s+1),n[s]=o.toUpperCase(),r(e,n,s+1)}};return r(e,[],0),t},r}(),t.BaseHelper=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(r){function n(){var n=null!==r&&r.apply(this,arguments)||this;return n._errorOccured=!1,n._errorCount=0,n._rowAffected=0,n.goToWhereLogic=function(){var r=e.getObjectFirstKey(this._query.Where);if(!0===this._query.IgnoreCase&&(this._query.Where=this.makeQryInCaseSensitive(this._query.Where)),this._objectStore.indexNames.contains(r)){var n=this._query.Where[r];if("object"==typeof n){this._checkFlag=Boolean(Object.keys(n).length>1||Object.keys(this._query.Where).length>1),!0===this._checkFlag&&(this._whereChecker=new t.WhereChecker(this._query.Where));var s=e.getObjectFirstKey(n);switch(s){case"Like":var o,i,u=n.Like.split("%");u[1]?(o=u[1],i=u.length>2?e.Occurence.Any:e.Occurence.Last):(o=u[0],i=e.Occurence.First),i===e.Occurence.First?(this.getAllCombinationOfWord(o).forEach(function(e){this.executeWhereLogic(r,{"-":{Low:e,High:e+""}},"-")},this),delete this._query.Where[r].Like):this.executeLikeLogic(r,o,i);break;case"In":this.executeInLogic(r,n.In);break;case"-":case">":case"<":case">=":case"<=":this.executeWhereLogic(r,n,s);break;case"Aggregate":break;default:this.executeWhereLogic(r,n)}}else this._checkFlag=Boolean(Object.keys(this._query.Where).length>1),!0===this._checkFlag&&(this._whereChecker=new t.WhereChecker(this._query.Where)),this.executeWhereLogic(r,n)}else{var c;this._errorOccured=!0,c=null==this.getColumnInfo(r)?new e.Error(e.Error_Type.ColumnNotExist,{ColumnName:r}).get():new e.Error(e.Error_Type.EnableSearchOff,{ColumnName:r}).get(),this.onErrorOccured(c,!0)}},n}return __extends(n,r),n.prototype.onErrorOccured=function(t,r){if(void 0===r&&(r=!1),++this._errorCount,1===this._errorCount&&null!=this._onError)if(r)this._onError(t),e.logError(t);else{var n={_message:t.target.error.message,_type:t.target.error.name};this._onError(n),e.logError(n)}},n.prototype.onExceptionOccured=function(t,r){switch(t.name){case"NotFoundError":var n=new e.Error(e.Error_Type.TableNotExist,r);this.onErrorOccured(n.get(),!0);break;default:console.error(t)}},n.prototype.getColumnInfo=function(e){var t;return this.getTable(this._tableName)._columns.every(function(r){return r._name!==e||(t=r,!1)}),t},n.prototype.addGreatAndLessToNotOp=function(){var e,t=this._query.Where;if(this.containsNot(t)){var r=Object.keys(t);if(1===r.length)r.forEach(function(r){(e=t[r])["!="]&&(t[r][">"]=e["!="],void 0===t.Or?(t.Or={},t.Or[r]={}):void 0===t.Or[r]&&(t.Or[r]={}),t.Or[r]["<"]=e["!="],delete t[r]["!="])}),this._query.Where=t;else{var n=[];r.forEach(function(r){var s={};(e=t[r])["!="]?(s[r]={">":e["!="],Or:{}},s[r].Or[r]={},s[r].Or[r]["<"]=e["!="]):s[r]=e,n.push(s)}),this._query.Where=n}}},n.prototype.makeQryInCaseSensitive=function(t){var r,n,s=[];for(var o in t)if("object"==typeof(r=t[o])){for(var i in r)switch(n=r[i],i){case e.WhereQryOption.In:s=s.concat(this.getAllCombinationOfWord(n,!0));break;case e.WhereQryOption.Like:break;default:s=s.concat(this.getAllCombinationOfWord(n))}t[o].In=s}else s=s.concat(this.getAllCombinationOfWord(r)),t[o]={In:s};return t},n}(t.BaseHelper),t.Base=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(){function r(r,n,s){var o=[],i=indexedDB.open(t.active_db._name,e.db_version);i.onerror=function(e){null!=s&&s(e.target.error)},i.onsuccess=function(r){e.db_status.ConStatus=e.Connection_Status.Connected,t.db_connection=i.result,t.db_connection.onclose=function(r){t.callDbDroppedByBrowser(),e.Utils.updateDbStatus(e.Connection_Status.Closed,e.Error_Type.ConnectionClosed)},t.db_connection.onversionchange=function(r){null===r.newVersion&&(r.target.close(),t.callDbDroppedByBrowser(!0),e.Utils.updateDbStatus(e.Connection_Status.Closed,e.Error_Type.ConnectionClosed))},t.db_connection.onerror=function(t){e.db_status.LastError="Error occured in connection :"+t.target.result},t.db_connection.onabort=function(t){e.db_status={ConStatus:e.Connection_Status.Closed,LastError:e.Error_Type.ConnectionAborted}},this.saveDbName(),null!=n&&n(o)}.bind(this),i.onupgradeneeded=function(e){t.db_connection=e.target.result,r.forEach(function(e,r){e._requireDelete?(t.db_connection.objectStoreNames.contains(e._name)&&t.db_connection.deleteObjectStore(e._name),u(e,r)):e._requireCreation&&u(e,r)})};var u=function(e,r){try{if(e._primaryKey.length>0){t.active_db._tables[r]._primaryKey=e._primaryKey;var n=t.db_connection.createObjectStore(e._name,{keyPath:e._primaryKey});e._columns.forEach(function(r){if(!0===r._enableSearch){var s=r._primaryKey?{unique:!0}:{unique:r._unique};s.multiEntry=r._multiEntry,n.createIndex(r._name,r._name,s),r._autoIncrement&&KeyStore.set("JsStore_"+t.active_db._name+"_"+e._name+"_"+r._name+"_Value",0)}})}else{n=t.db_connection.createObjectStore(e._name,{autoIncrement:!0});e._columns.forEach(function(r){var s={unique:r._unique,multiEntry:r._multiEntry};n.createIndex(r._name,r._name,s),r._autoIncrement&&KeyStore.set("JsStore_"+t.active_db._name+"_"+e._name+"_"+r._name+"_Value",0)})}o.push(e._name),KeyStore.set("JsStore_"+t.active_db._name+"_"+e._name+"_Version",e._version)}catch(e){console.error(e)}}}return r.prototype.saveDbName=function(){KeyStore.get("database_list",function(r){e.getType(r)!==e.Data_Type.Array&&(r=[]),r.push(t.active_db._name),KeyStore.set("database_list",r)})},r}(),t.CreateDb=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(){function r(e,t){this._onSuccess=e,this._onError=t}return r.prototype.deleteMetaData=function(){KeyStore.remove("JsStore_"+t.active_db._name+"_Db_Version"),t.active_db._tables.forEach(function(e){KeyStore.remove("JsStore_"+t.active_db._name+"_"+e._name+"_Version"),e._columns.forEach(function(r){r._autoIncrement&&KeyStore.remove("JsStore_"+t.active_db._name+"_"+e._name+"_"+r._name+"_Value")})}),KeyStore.get("database_list",function(e){e.splice(e.indexOf(t.active_db._name),1),KeyStore.set("database_list",e)}),KeyStore.remove("JsStore_"+t.active_db._name+"_Schema",this._onSuccess)},r.prototype.deleteDb=function(){setTimeout(function(){var r=indexedDB.deleteDatabase(t.active_db._name);r.onblocked=function(){null!=this._onError&&this._onError("database is blocked, cant be deleted right now.")}.bind(this),r.onerror=function(e){null!=this._onError&&this._onError(event.target.error)}.bind(this),r.onsuccess=function(){e.db_status.ConStatus=e.Connection_Status.Closed,this.deleteMetaData()}.bind(this)}.bind(this),100)},r}(),t.DropDb=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(r){function n(e,t,n){var s=r.call(this)||this;return s._query=e,s._onSuccess=t,s._onError=n,s}return __extends(n,r),n.prototype.execute=function(){if(Array.isArray(this._query.Values))if(!0===this.isTableExist(this._query.Into))try{this.bulkinsertData()}catch(e){this.onExceptionOccured(e,{TableName:this._query.Into})}else{new e.Error(e.Error_Type.TableNotExist,{TableName:this._query.Into}).throw()}else this.onErrorOccured(new e.Error(e.Error_Type.NotArray).get(),!0)},n.prototype.bulkinsertData=function(){t.createTransaction([this._query.Into],function(e){this._onSuccess()}.bind(this)),this._objectStore=t.db_transaction.objectStore(this._query.Into),this._query.Values.forEach(function(e){this._objectStore.add(e)},this)},n}(t.Base),t.BulkInsert=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(){return function(r,n,s){if(this.setPrimaryKey=function(){t.active_db._tables.forEach(function(e,r){e._columns.every(function(e){return t.active_db._tables[r]._primaryKey=e._primaryKey?e._name:"",!e._primaryKey})})},t.active_db._name.length>0){var o=indexedDB.open(t.active_db._name,r);o.onerror=function(e){null!=s&&s(e.target.error)},o.onsuccess=function(r){e.db_status.ConStatus=e.Connection_Status.Connected,t.db_connection=o.result,t.db_connection.onclose=function(r){t.callDbDroppedByBrowser(),e.Utils.updateDbStatus(e.Connection_Status.Closed,e.Error_Type.ConnectionClosed)},t.db_connection.onversionchange=function(r){null===r.newVersion&&null===r.newVersion&&(r.target.close(),t.callDbDroppedByBrowser(!0),e.Utils.updateDbStatus(e.Connection_Status.Closed,e.Error_Type.ConnectionClosed))},t.db_connection.onerror=function(t){e.db_status.LastError="Error occured in connection :"+t.target.result},t.db_connection.onabort=function(t){e.db_status.ConStatus=e.Connection_Status.Closed,e.db_status.LastError=e.Error_Type.ConnectionAborted},null!=n&&n(),this.setPrimaryKey()}.bind(this)}else new e.Error(e.Error_Type.UndefinedDbName).throw()}}(),t.OpenDb=r}(JsStore||(JsStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(e){function r(t,r,n){var s=e.call(this)||this;return s._query=t,s._onSuccess=r,s._onError=n,s}return __extends(r,e),r.prototype.execute=function(){t.createTransaction([this._query],function(e){!1===this._errorOccured&&this._onSuccess()}.bind(this));var e=t.db_transaction.objectStore(this._query).clear();e.onsuccess=function(e){this.getTable(this._query)._columns.forEach(function(e){e._autoIncrement&&KeyStore.set("JsStore_"+t.active_db._name+"_"+this._query+"_"+e._name+"_Value",0)},this)}.bind(this),e.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)},r}(t.Base),t.Clear=r}(JsStore||(JsStore={})),function(JsStore){var Business;!function(Business){Business.db_transaction=null,Business.callDbDroppedByBrowser=function(e){JsStore.db_status.ConStatus===JsStore.Connection_Status.Connected&&(Business.is_db_deleted_by_browser=!0,!0===e&&new Business.DropDb(Business.on_db_dropped_by_browser,null).deleteMetaData())},Business.createTransaction=function(e,t,r){null===Business.db_transaction&&(r=r||"readwrite",Business.db_transaction=Business.db_connection.transaction(e,r),Business.db_transaction.oncomplete=function(){Business.db_transaction=null,t()},Business.db_transaction.ontimeout=function(){Business.db_transaction=null,console.error("transaction timed out")})};var Main=function(){function Main(e){this._onSuccess=e}return Main.prototype.checkConnectionAndExecuteLogic=function(e){switch(JsStore.log("checking connection and executing request:"+e.Name),e.Name){case"create_db":case"open_db":this.executeLogic(e);break;case"change_log_status":this.changeLogStatus(e.Query.logging);break;case"set_config":this.setConfig(e.Query);break;default:switch(JsStore.db_status.ConStatus){case JsStore.Connection_Status.Connected:this.executeLogic(e);break;case JsStore.Connection_Status.Closed:!0===Business.is_db_deleted_by_browser?this.createDb(null,function(){Business.is_db_deleted_by_browser=!1,this.checkConnectionAndExecuteLogic(e)}.bind(this),e.OnError):this.openDb(Business.active_db._name,function(){this.checkConnectionAndExecuteLogic(e)}.bind(this),e.OnError)}}},Main.prototype.changeLogStatus=function(e){JsStore.enable_log=e},Main.prototype.setConfig=function(config){for(var prop in config)switch(prop){case"EnableLog":this.changeLogStatus(config[prop]);break;case"FileName":JsStore.file_name=config[prop];break;case"OnDbDroppedByBrowser":eval("on_db_dropped_by_browser="+config.OnDbDroppedByBrowser);break;default:var err=new JsStore.Error(JsStore.Error_Type.InvalidConfig,{Config:prop});err.logError()}},Main.prototype.returnResult=function(e){this._onSuccess?this._onSuccess(e):self.postMessage(e)},Main.prototype.executeLogic=function(e){var t=function(e){this.returnResult({ReturnedValue:e})}.bind(this),r=function(e){this.returnResult({ErrorDetails:e,ErrorOccured:!0})}.bind(this);switch(e.Name){case"select":this.select(e.Query,t,r);break;case"insert":this.insert(e.Query,t,r);break;case"update":this.update(e.Query,t,r);break;case"remove":this.remove(e.Query,t,r);break;case"open_db":!0===Business.is_db_deleted_by_browser?this.createDb(null,function(){Business.is_db_deleted_by_browser=!1,t()}.bind(this),r):this.openDb(e.Query,t,r);break;case"create_db":this.createDb(e.Query,t,r);break;case"clear":this.clear(e.Query,t,r);break;case"drop_db":this.dropDb(t,r);break;case"count":this.count(e.Query,t,r);break;case"bulk_insert":this.bulkInsert(e.Query,t,r);break;case"transaction":this.transaction(e.Query,t,r);break;case"export_json":this.exportJson(e.Query,t,r);break;default:console.error("The Api:-"+e.Name+" does not support.")}},Main.prototype.transaction=function(e,t,r){new Business.Transaction(e,t,r).execute()},Main.prototype.openDb=function(e,t,r){JsStore.getDbVersion(e,function(n){if(0!==n)JsStore.getDbSchema(e,function(e){Business.active_db=e;new Business.OpenDb(n,t,r)});else{var s=new JsStore.Error(JsStore.Error_Type.DbNotExist,{DbName:e});s.logError(),r(s.get())}})},Main.prototype.closeDb=function(){JsStore.db_status.ConStatus===JsStore.Connection_Status.Connected&&(JsStore.db_status.ConStatus=JsStore.Connection_Status.ClosedByJsStore,Business.db_connection.close())},Main.prototype.dropDb=function(e,t){this.closeDb(),new Business.DropDb(e,t).deleteDb()},Main.prototype.update=function(e,t,r){new Business.Update.Instance(e,t,r).execute()},Main.prototype.insert=function(e,t,r){new Business.Insert.Instance(e,t,r).execute()},Main.prototype.bulkInsert=function(e,t,r){new Business.BulkInsert(e,t,r).execute()},Main.prototype.remove=function(e,t,r){new Business.Remove.Instance(e,t,r).execute()},Main.prototype.select=function(e,t,r){"object"==typeof e.From?new Business.Select.Join(e,t,r):new Business.Select.Instance(e,t,r).execute()},Main.prototype.count=function(e,t,r){if("object"==typeof e.From){e.Count=!0;new Business.Select.Join(e,t,r)}else{new Business.Count.Instance(e,t,r).execute()}},Main.prototype.createDb=function(e,t,r){var n=function(){KeyStore.set("JsStore_"+Business.active_db._name+"_Schema",Business.active_db),new JsStore.Model.DbHelper(Business.active_db).createMetaData(function(e){new Business.CreateDb(e,t,r)})};null==e?n():(this.closeDb(),JsStore.getDbVersion(e.Name,function(t){JsStore.db_version=t||1,Business.active_db=new JsStore.Model.DataBase(e),n()}))},Main.prototype.clear=function(e,t,r){new Business.Clear(e,t,r).execute()},Main.prototype.exportJson=function(e,t,r){this.select(e,function(e){var r=URL.createObjectURL(new Blob([JSON.stringify(e)],{type:"text/json"}));t(r)},function(e){r(e)})},Main}();Business.Main=Main}(Business=JsStore.Business||(JsStore.Business={}))}(JsStore||(JsStore={})),function(e){var t,r;t=e.Business||(e.Business={}),r=function(){function t(e){this._where=e}return t.prototype.check=function(e){var t;for(var r in this._status=!0,this._where){if(!this._status)break;if("object"==typeof(t=this._where[r]))for(var n in t){if(!this._status)break;switch(n){case"In":this.checkIn(r,e[r]);break;case"Like":this.checkLike(r,e[r]);break;case"-":case">":case"<":case">=":case"<=":case"!=":this.checkComparisionOp(r,e[r],n)}}else if(t!==e[r]){this._status=!1;break}}return this._status},t.prototype.checkIn=function(e,t){for(var r=0,n=this._where[e].In,s=n.length;r<s;r++){if(n[r]===t){this._status=!0;break}this._status=!1}},t.prototype.checkLike=function(t,r){var n,s,o,i=this._where[t].Like.split("%");switch(i[1]?(s=i[1],n=i.length>2?e.Occurence.Any:e.Occurence.Last):(s=i[0],n=e.Occurence.First),r=r.toLowerCase(),n){case e.Occurence.Any:(o=r.indexOf(s.toLowerCase()))<0&&(this._status=!1);break;case e.Occurence.First:((o=r.indexOf(s.toLowerCase()))>0||o<0)&&(this._status=!1);break;default:(o=r.lastIndexOf(s.toLowerCase()))<r.length-s.length&&(this._status=!1)}},t.prototype.checkComparisionOp=function(e,t,r){var n=this._where[e][r];switch(r){case">":t<=n&&(this._status=!1);break;case"<":t>=n&&(this._status=!1);break;case"<=":t>n&&(this._status=!1);break;case">=":t<n&&(this._status=!1);break;case"-":(t<n.Low||t>n.High)&&(this._status=!1);break;case"!=":t===n&&(this._status=!1)}},t}(),t.WhereChecker=r}(JsStore||(JsStore={})),function(JsStore){var Business;!function(Business){var Transaction=function(_super){function Transaction(e,t,r){var n=_super.call(this)||this;return e.AbortOnError=!e.AbortOnError||e.AbortOnError,n._query=e,n._onSuccess=t,n._onError=r,n}return __extends(Transaction,_super),Transaction.prototype.execute=function(){var request_queue=[],onRequestFinished=function(e){var t=request_queue.shift();t&&(this._errorOccured&&!0===this._query.AbortOnError?Business.db_transaction.abort():(t.OnSuccess&&t.OnSuccess(e),request_queue.length>=1&&executeRequest(request_queue[0])))}.bind(this),executeRequest=function(e){var t;switch(e.Name){case"select":t=new Business.Select.Instance(e.Query,onRequestFinished,this._onError.bind(this));break;case"insert":t=new Business.Insert.Instance(e.Query,onRequestFinished,this._onError.bind(this))}t._isTransaction=!0,t.execute()}.bind(this),pushRequest=function(e){request_queue.push(e),1===request_queue.length&&(this.initTransaction(this._query.TableNames),executeRequest(request_queue[0]))}.bind(this),select=function(e,t){t=e.OnSuccess?e.OnSuccess:t,pushRequest({Name:"select",OnSuccess:t,Query:e})},insert=function(e,t){t=e.OnSuccess?e.OnSuccess:t,pushRequest({Name:"insert",OnSuccess:t,Query:e})},update=function(e,t){t=e.OnSuccess?e.OnSuccess:t,pushRequest({Name:"update",OnSuccess:t,Query:e})},remove=function(e,t){t=e.OnSuccess?e.OnSuccess:t,pushRequest({Name:"remove",OnSuccess:t,Query:e})},count=function(e,t){t=e.OnSuccess?e.OnSuccess:t,pushRequest({Name:"count",OnSuccess:t,Query:e})};eval("var tx_logic ="+this._query.Logic),tx_logic.call(this,this._query.Data),this._query.Data=this._query.Logic=null},Transaction.prototype.initTransaction=function(e){Business.createTransaction(e,this.onTransactionCompleted.bind(this))},Transaction.prototype.onTransactionCompleted=function(){this._onSuccess(this._results)},Transaction}(Business.Base);Business.Transaction=Transaction}(Business=JsStore.Business||(JsStore.Business={}))}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Select||(t.Select={}),n=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._results=[],t._sorted=!1,t._checkFlag=!1,t}return __extends(t,e),t.prototype.removeDuplicates=function(){var e=this._results;this._results=void 0;var t=this.getPrimaryKey(this._query.From),r={};for(var n in e)r[e[n][t]]=e[n];for(n in e=[],r)e.push(r[n]);this._results=e},t}(t.Base),r.BaseSelect=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Select||(t.Select={}),n=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return __extends(r,t),r.prototype.executeWhereUndefinedLogic=function(){if(this._query.Order&&this._query.Order.By)if(this._objectStore.indexNames.contains(this._query.Order.By)){var t=this._query.Order.Type&&"desc"===this._query.Order.Type.toLowerCase()?"prev":"next";this._sorted=!0,this._cursorOpenRequest=this._objectStore.index(this._query.Order.By).openCursor(null,t)}else new e.Error(e.Error_Type.ColumnNotExist,{ColumnName:this._query.Order.By}).throw();else this._cursorOpenRequest=this._objectStore.openCursor();this._skipRecord&&this._limitRecord?this.executeSkipAndLimitForNoWhere():this._skipRecord?this.executeSkipForNoWhere():this._limitRecord?this.executeLimitForNotWhere():this.executeSimpleForNotWhere(),this._cursorOpenRequest.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)},r.prototype.executeSkipAndLimitForNoWhere=function(){var e,t=!1;this._cursorOpenRequest.onsuccess=function(r){(e=r.target.result)?t&&this._results.length!==this._limitRecord?(this._results.push(e.value),e.continue()):(t=!0,e.advance(this._skipRecord)):this.onQueryFinished()}.bind(this)},r.prototype.executeSkipForNoWhere=function(){var e,t=!1;this._cursorOpenRequest.onsuccess=function(r){(e=r.target.result)?t?(this._results.push(e.value),e.continue()):(t=!0,e.advance(this._skipRecord)):this.onQueryFinished()}.bind(this)},r.prototype.executeSimpleForNotWhere=function(){var e;this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)?(this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this)},r.prototype.executeLimitForNotWhere=function(){var e;this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)&&this._results.length!==this._limitRecord?(this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this)},r}(r.BaseSelect),r.NotWhere=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Select||(t.Select={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeInLogic=function(e,t){this._skipRecord&&this._limitRecord?this.executeSkipAndLimitForIn(e,t):this._skipRecord?this.executeSkipForIn(e,t):this._limitRecord?this.executeLimitForIn(e,t):this.executeSimpleForIn(e,t)},t.prototype.executeSkipAndLimitForIn=function(e,t){var r,n,s=this._skipRecord,o=this._objectStore.index(e),i=function(e){0===s?this._results.push(e):--s}.bind(this),u=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this);if(this._checkFlag)for(var c=0,a=t.length;c<a;c++)this._errorOccured||((n=o.openCursor(IDBKeyRange.only(t[c]))).onsuccess=function(e){r=e.target.result,this._results.length!==this._limitRecord&&r?(this._whereChecker.check(r.value)&&i(r.value),r.continue()):c+1===a&&this.onQueryFinished()}.bind(this),n.onerror=u);else for(c=0,a=t.length;c<a;c++)this._errorOccured||((n=o.openCursor(IDBKeyRange.only(t[c]))).onsuccess=function(e){r=e.target.result,this._results.length!==this._limitRecord&&r?(i(r.value),r.continue()):c+1===a&&this.onQueryFinished()}.bind(this),n.onerror=u)},t.prototype.executeSkipForIn=function(e,t){var r,n,s=this._skipRecord,o=this._objectStore.index(e),i=function(e){0===s?this._results.push(e):--s}.bind(this),u=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this);if(this._checkFlag)for(var c=0,a=t.length;c<a;c++)this._errorOccured||((n=o.openCursor(IDBKeyRange.only(t[c]))).onsuccess=function(e){(r=e.target.result)?(this._whereChecker.check(r.value)&&i(r.value),r.continue()):c+1===a&&this.onQueryFinished()}.bind(this),n.onerror=u);else for(c=0,a=t.length;c<a;c++)this._errorOccured||((n=o.openCursor(IDBKeyRange.only(t[c]))).onsuccess=function(e){(r=e.target.result)?(i(r.value),r.continue()):c+1===a&&this.onQueryFinished()}.bind(this),n.onerror=u)},t.prototype.executeLimitForIn=function(e,t){var r,n,s=this._objectStore.index(e),o=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this);if(this._checkFlag)for(var i=0,u=t.length;i<u;i++)this._errorOccured||((n=s.openCursor(IDBKeyRange.only(t[i]))).onsuccess=function(e){(r=e.target.result)&&this._results.length!==this._limitRecord?(this._whereChecker.check(r.value)&&this._results.push(r.value),r.continue()):i+1===u&&this.onQueryFinished()}.bind(this),n.onerror=o);else for(i=0,u=t.length;i<u;i++)this._errorOccured||((n=s.openCursor(IDBKeyRange.only(t[i]))).onsuccess=function(e){(r=e.target.result)&&this._results.length!==this._limitRecord?(this._results.push(r.value),r.continue()):i+1===u&&this.onQueryFinished()}.bind(this),n.onerror=o)},t.prototype.executeSimpleForIn=function(e,t){var r,n,s=this._objectStore.index(e),o=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this);if(this._checkFlag)for(var i=0,u=t.length;i<u;i++)this._errorOccured||((n=s.openCursor(IDBKeyRange.only(t[i]))).onsuccess=function(e){(r=e.target.result)?(this._whereChecker.check(r.value)&&this._results.push(r.value),r.continue()):i+1===u&&this.onQueryFinished()}.bind(this),n.onerror=o);else for(i=0,u=t.length;i<u;i++)this._errorOccured||((n=s.openCursor(IDBKeyRange.only(t[i]))).onsuccess=function(e){(r=e.target.result)?(this._results.push(r.value),r.continue()):i+1===u&&this.onQueryFinished()}.bind(this),n.onerror=o)},t}(r.NotWhere),r.In=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Select||(t.Select={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeLikeLogic=function(e,t,r){this._compValue=t.toLowerCase(),this._compValueLength=this._compValue.length,this._compSymbol=r,this._cursorOpenRequest=this._objectStore.index(e).openCursor(),this._cursorOpenRequest.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this),this._skipRecord&&this._limitRecord?this.executeSkipAndLimit():this._skipRecord?this.executeSkip():this._limitRecord?this.executeLimit():this.executeSimple()},t.prototype.executeSkipAndLimit=function(){var e,t=this._skipRecord,r=function(e){0===t?this._results.push(e):--t}.bind(this);this._checkFlag?this._cursorOpenRequest.onsuccess=function(t){e=t.target.result,this._results.length!==this._limitRecord&&e?(this.filterOnOccurence(e.key)&&this._whereChecker.check(e.value)&&r(e.value),e.continue()):this.onQueryFinished()}.bind(this):this._cursorOpenRequest.onsuccess=function(t){e=t.target.result,this._results.length!==this._limitRecord&&e?(this.filterOnOccurence(e.key)&&r(e.value),e.continue()):this.onQueryFinished()}.bind(this)},t.prototype.executeSkip=function(){var e,t=this._skipRecord,r=function(e){0===t?this._results.push(e):--t}.bind(this);this._checkFlag?this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)?(this.filterOnOccurence(e.key)&&this._whereChecker.check(e.value)&&r(e.value),e.continue()):this.onQueryFinished()}.bind(this):this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)?(this.filterOnOccurence(e.key)&&r(e.value),e.continue()):this.onQueryFinished()}.bind(this)},t.prototype.executeLimit=function(){var e;this._checkFlag?this._cursorOpenRequest.onsuccess=function(t){e=t.target.result,this._results.length!==this._limitRecord&&e?(this.filterOnOccurence(e.key)&&this._whereChecker.check(e.value)&&this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this):this._cursorOpenRequest.onsuccess=function(t){e=t.target.result,this._results.length!==this._limitRecord&&e?(this.filterOnOccurence(e.key)&&this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this)},t.prototype.executeSimple=function(){var e;this._checkFlag?this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)?(this.filterOnOccurence(e.key)&&this._whereChecker.check(e.value)&&this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this):this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)?(this.filterOnOccurence(e.key)&&this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this)},t}(r.In),r.Like=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Select||(t.Select={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeSkipAndLimitForWhere=function(){var e,t=!1;this._checkFlag?this._cursorOpenRequest.onsuccess=function(r){(e=r.target.result)?t&&this._results.length!==this._limitRecord?(this._whereChecker.check(e.value)&&this._results.push(e.value),e.continue()):(t=!0,e.advance(this._skipRecord)):this.onQueryFinished()}.bind(this):this._cursorOpenRequest.onsuccess=function(r){(e=r.target.result)?t&&this._results.length!==this._limitRecord?(this._results.push(e.value),e.continue()):(t=!0,e.advance(this._skipRecord)):this.onQueryFinished()}.bind(this)},t.prototype.executeSkipForWhere=function(){var e,t=!1;this._checkFlag?this._cursorOpenRequest.onsuccess=function(r){(e=r.target.result)?t?(this._whereChecker.check(e.value)&&this._results.push(e.value),e.continue()):(t=!0,e.advance(this._skipRecord)):this.onQueryFinished()}.bind(this):this._cursorOpenRequest.onsuccess=function(r){(e=r.target.result)?t?(this._results.push(e.value),e.continue()):(t=!0,e.advance(this._skipRecord)):this.onQueryFinished()}.bind(this)},t.prototype.executeLimitForWhere=function(){var e;this._checkFlag?this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)&&this._results.length!==this._limitRecord&&this._whereChecker.check(e.value)?(this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this):this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)&&this._results.length!==this._limitRecord?(this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this)},t.prototype.executeSimpleForWhere=function(){var e;this._checkFlag?this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)?(this._whereChecker.check(e.value)&&this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this):this._cursorOpenRequest.onsuccess=function(t){(e=t.target.result)?(this._results.push(e.value),e.continue()):this.onQueryFinished()}.bind(this)},t.prototype.executeWhereLogic=function(e,t,r,n){t=r?t[r]:t,this._cursorOpenRequest=this._objectStore.index(e).openCursor(this.getKeyRange(t,r),n),this._cursorOpenRequest.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this),this._skipRecord&&this._limitRecord?this.executeSkipAndLimitForWhere():this._skipRecord?this.executeSkipForWhere():this._limitRecord?this.executeLimitForWhere():this.executeSimpleForWhere()},t}(r.Like),r.Where=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Select||(t.Select={}),n=function(e){function t(t,n,s){var o=e.call(this)||this;o._queryStack=[],o._currentQueryStackIndex=0,o._onSuccess=n,o._onError=s,o._query=t;var i=[],u=function(e){return e.hasOwnProperty("Table1")?(e.Table2.JoinType=void 0===e.Join?"inner":e.Join.toLowerCase(),this._queryStack.push(e.Table2),this._queryStack.length%2==0&&(this._queryStack[this._queryStack.length-1].NextJoin=e.NextJoin),i.push(e.Table2.Table),u(e.Table1)):(this._queryStack.push(e),void i.push(e.Table))}.bind(o);return u(t.From),o._queryStack.reverse(),o._errorOccured||new r.Instance({From:o._queryStack[0].Table,Where:o._queryStack[0].Where},function(e){var t=this._queryStack[0].Table;e.forEach(function(e,r){this._results[r]={},this._results[r][t]=e},this),this.startExecutionJoinLogic()}.bind(o),o.onErrorOccured.bind(o)).execute(),o}return __extends(t,e),t.prototype.onTransactionCompleted=function(e){null!=this._onSuccess&&this._queryStack.length===this._currentQueryStackIndex+1&&(this._query.Count?this._onSuccess(this._results.length):(this._query.Skip&&this._query.Limit?(this._results.splice(0,this._query.Skip),this._results.splice(this._query.Limit-1,this._results.length)):this._query.Skip?this._results.splice(0,this._query.Skip):this._query.Limit&&this._results.splice(this._query.Limit-1,this._results.length),this._onSuccess(this._results)))},t.prototype.executeWhereJoinLogic=function(e,t){var n,s=[],o=0,i=(t.Column,this._results),u=i.length;new r.Instance({From:t.Table,Order:t.Order,Where:t.Where},function(t){t.forEach(function(t,r){for(var s=0;s<u;s++)n=i[s][e.Table][e.Column],c(n,t,s)}),this._results=s,this._queryStack.length>this._currentQueryStackIndex+1?this.startExecutionJoinLogic():this.onTransactionCompleted(null)}.bind(this),this.onErrorOccured.bind(this)).execute();var c=function(e,r,n){if(s[o]={},e===r[t.Column]){s[o][t.Table]=r;for(var u=0;u<this._currentQueryStackIndex;u++)s[o][this._queryStack[u].Table]=i[n][this._queryStack[u].Table];++o}else if("left"===t.JoinType){for(s[o]={},s[o][t.Table]=null,u=0;u<this._currentQueryStackIndex;u++)s[o][this._queryStack[u].Table]=i[n][this._queryStack[u].Table];++o}}.bind(this)},t.prototype.executeRightJoin=function(e,t){var n=[],s=(t.Column,this._results),o=s.length,i=0,u=function(){this._results=n,this._queryStack.length>this._currentQueryStackIndex+1?this.startExecutionJoinLogic():this.onTransactionCompleted(null)}.bind(this),c=function(r){var u=!1;r.forEach(function(r,c){for(i=0;i<o;i++)if(r[t.Column]===s[i][e.Table][e.Column]){u=!0;break}if(n[c]={},n[c][t.Table]=r,u){u=!1;for(var a=0;a<this._currentQueryStackIndex;a++)n[c][this._queryStack[a].Table]=s[i][this._queryStack[a].Table]}else for(a=0;a<this._currentQueryStackIndex;a++)n[c][this._queryStack[a].Table]=null},this)}.bind(this);(function(){new r.Instance({From:t.Table,Order:t.Order,Where:t.Where},function(e){c(e),u()}.bind(this),this.onErrorOccured.bind(this)).execute()}).bind(this)()},t.prototype.executeWhereUndefinedLogicForJoin=function(e,t){var n=[],s=0,o=(t.Column,this._results),i=o.length,u=0,c={},a=function(){this._results=n,this._queryStack.length>this._currentQueryStackIndex+1?this.startExecutionJoinLogic():this.onTransactionCompleted(null)}.bind(this),h=function(e){if(e.length>0)e.forEach(function(e){n[s]={},n[s][t.Table]=e;for(var r=0;r<this._currentQueryStackIndex;r++)n[s][this._queryStack[r].Table]=o[u][this._queryStack[r].Table];++s},this);else if("left"===t.JoinType){n[s]={},n[s][t.Table]=null;for(var r=0;r<this._currentQueryStackIndex;r++)n[s][this._queryStack[r].Table]=o[u][this._queryStack[r].Table];++s}}.bind(this),l=function(){u<i?this._errorOccured||(c[t.Column]=o[u][e.Table][e.Column],new r.Instance({From:t.Table,Order:t.Order,Where:c},function(e){h(e),++u,l()}.bind(this),this.onErrorOccured.bind(this)).execute()):a()}.bind(this);l()},t.prototype.startExecutionJoinLogic=function(){var e;this._currentQueryStackIndex>=1&&this._currentQueryStackIndex%2==1?(e={Column:this._queryStack[this._currentQueryStackIndex].NextJoin.Column,Table:this._queryStack[this._currentQueryStackIndex].NextJoin.Table},this._currentQueryStackIndex++):e=this._queryStack[this._currentQueryStackIndex++];var t=this._queryStack[this._currentQueryStackIndex];"right"===t.JoinType?this.executeRightJoin(e,t):t.Where?this.executeWhereJoinLogic(e,t):this.executeWhereUndefinedLogicForJoin(e,t)},t}(r.BaseSelect),r.Join=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Select||(t.Select={}),n=function(e){function t(){return e.call(this)||this}return __extends(t,e),t.prototype.processGroupBy=function(){var e,t=this._query.GroupBy,r=this._results,n={};if(this._results=this._query.GroupBy=void 0,"string"==typeof t)for(var s in r)n[r[s][t]]=r[s];else for(var s in r){for(var o in e="",t)e+=r[s][t[o]];n[e]=r[s]}for(s in r=[],n)r.push(n[s]);this._results=r},t.prototype.executeAggregateGroupBy=function(){var e,t,r,n,s=this._query.GroupBy,o=this._results,i={},u=this._query.Aggregate;this._query.Aggregate=void 0,this._results=void 0;var c=function(){for(var s in u)switch(s){case"Count":var c=function(){return r=(r=i[t])?r["Count("+n+")"]:0,r+=o[e][n]?1:0};if("string"==typeof u[s])n=u[s],o[e]["Count("+n+")"]=c();else if(Array.isArray(u[s]))for(var a in u[s])n=u[s][a],o[e]["Count("+n+")"]=c();break;case"Max":var h=function(){return r=(r=i[t])?r["Max("+n+")"]:0,o[e][n]=o[e][n]?o[e][n]:0,r>o[e][n]?r:o[e][n]};if("string"==typeof u[s])n=u[s],o[e]["Max("+n+")"]=h();else if(Array.isArray(u[s]))for(var a in u[s])n=u[s][a],o[e]["Max("+n+")"]=h();break;case"Min":var l=function(){return r=(r=i[t])?r["Min("+n+")"]:1/0,o[e][n]=o[e][n]?o[e][n]:1/0,r<o[e][n]?r:o[e][n]};if("string"==typeof u[s])n=u[s],o[e]["Min("+n+")"]=l();else if(Array.isArray(u[s]))for(var a in u[s])n=u[s][a],o[e]["Min("+n+")"]=l();break;case"Sum":var _=function(){return r=(r=i[t])?r["Sum("+n+")"]:0,r+=o[e][n]?o[e][n]:0};if("string"==typeof u[s])n=u[s],o[e]["Sum("+n+")"]=_();else if(Array.isArray(u[s]))for(var a in u[s])n=u[s][a],o[e]["Sum("+n+")"]=_();break;case"Avg":var d=function(){var s=(r=i[t])?r["Sum("+n+")"]:0;s+=o[e][n]?o[e][n]:0,o[e]["Sum("+n+")"]=s,r=r?r["Count("+n+")"]:0,r+=o[e][n]?1:0,o[e]["Count("+n+")"]=r};if("string"==typeof u[s])n=u[s],d();else if(Array.isArray(u[s]))for(var a in u[s])n=u[s][a],d()}};if("string"==typeof s)for(e in o)t=o[e][s],c(),i[t]=o[e];else for(e in o){for(var a in t="",s)t+=o[e][s[a]];c(),i[t]=o[e]}for(var h in o=[],i)o.push(i[h]);if(u.Avg)if("string"==typeof u.Avg)for(e in o){var l=o[e]["Sum("+u.Avg+")"],_=o[e]["Count("+u.Avg+")"];o[e]["Avg("+u.Avg+")"]=l/_,u.Count!==u.Avg&&delete o[e]["Count("+u.Avg+")"],u.Sum!==u.Avg&&delete o[e]["Sum("+u.Avg+")"]}else{var d=typeof u.Count,f=typeof u.Count;for(e in o)for(var a in u.Avg){var y=u.Avg[a],p=o[e]["Sum("+y+")"],b=o[e]["Count("+y+")"];o[e]["Avg("+y+")"]=p/b,d&&(u.Count!==y?delete o[e]["Count("+y+")"]:-1===u.Count.indexOf(y)&&delete o[e]["Count("+y+")"]),f&&(u.Sum!==y?delete o[e]["Sum("+y+")"]:-1===u.Sum.indexOf(y)&&delete o[e]["Sum("+y+")"])}}this._results=o},t}(r.Where),r.GroupByHelper=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Select||(t.Select={}),n=function(e){function t(){return e.call(this)||this}return __extends(t,e),t.prototype.processOrderBy=function(){var e=this._query.Order;if(e&&this._results.length>0&&!this._sorted&&e.By){e.Type=e.Type?e.Type.toLowerCase():"asc";var t=e.By,r=function(){this._results.sort(function(e,r){return e[t]-r[t]})}.bind(this),n=function(){this._results.sort(function(e,r){return r[t]-e[t]})}.bind(this),s=function(){this._results.sort(function(e,r){return e[t].toLowerCase().localeCompare(r[t].toLowerCase())})}.bind(this),o=function(){this._results.sort(function(e,r){return r[t].toLowerCase().localeCompare(e[t].toLowerCase())})}.bind(this);"string"==typeof this._results[0][t]?"asc"===e.Type?s():o():"number"==typeof this._results[0][t]&&("asc"===e.Type?r():n())}},t.prototype.processAggregateQry=function(){var e,t=this._results,r={};for(var n in this._results=void 0,this._query.Aggregate)switch(n){case"Count":var s=function(){var r=0;for(var n in t)r+=t[n][e]?1:0;return r};if("string"==typeof this._query.Aggregate[n])r["Count("+(e=this._query.Aggregate[n])+")"]=s();else if(Array.isArray(this._query.Aggregate[n]))for(var o in this._query.Aggregate[n])r["Count("+(e=this._query.Aggregate[n][o])+")"]=s();break;case"Max":var i=function(){var r=0;for(var n in t)r=r>t[n][e]?r:t[n][e];return r};if("string"==typeof this._query.Aggregate[n])r["Max("+(e=this._query.Aggregate[n])+")"]=i();else if(Array.isArray(this._query.Aggregate[n]))for(var o in this._query.Aggregate[n])r["Max("+(e=this._query.Aggregate[n][o])+")"]=i();break;case"Min":var u=function(){var r=1/0,n=1/0;for(var s in t)r=r<(n=t[s][e]?t[s][e]:1/0)?r:n;return r};if("string"==typeof this._query.Aggregate[n])r["Min("+(e=this._query.Aggregate[n])+")"]=u();else if(Array.isArray(this._query.Aggregate[n]))for(var o in this._query.Aggregate[n])r["Min("+(e=this._query.Aggregate[n][o])+")"]=u();break;case"Sum":var c=function(){var r=0;for(var n in t)r+=t[n][e];return r};if("string"==typeof this._query.Aggregate[n])r["Sum("+(e=this._query.Aggregate[n])+")"]=c();else if(Array.isArray(this._query.Aggregate[n]))for(var o in this._query.Aggregate[n])r["Sum("+(e=this._query.Aggregate[n][o])+")"]=c();break;case"Avg":var a=function(){var r=0;for(var n in t)r+=t[n][e];return r/t.length};if("string"==typeof this._query.Aggregate[n])r["Avg("+(e=this._query.Aggregate[n])+")"]=a();else if(Array.isArray(this._query.Aggregate[n]))for(var o in this._query.Aggregate[n])r["Avg("+(e=this._query.Aggregate[n][o])+")"]=a()}for(var n in r)t[0][n]=r[n];this._results=t},t}(r.GroupByHelper),r.Helper=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Select||(t.Select={}),n=function(r){function n(e,t,n){var s=r.call(this)||this;return s._onError=n,s._onSuccess=t,s._query=e,s._skipRecord=s._query.Skip,s._limitRecord=s._query.Limit,s._tableName=s._query.From,s}return __extends(n,r),n.prototype.execute=function(){if(!0===this.isTableExist(this._tableName))try{void 0!==this._query.Where?(this.addGreatAndLessToNotOp(),this.initTransaction(),Array.isArray(this._query.Where)?this.processWhereArrayQry():this.processWhere()):(this.initTransaction(),this.executeWhereUndefinedLogic())}catch(e){this._errorOccured=!0,this.onExceptionOccured.call(this,e,{TableName:this._query.From})}else this._errorOccured=!0,this.onErrorOccured(new e.Error(e.Error_Type.TableNotExist,{TableName:this._query.From}).get(),!0)},n.prototype.processWhereArrayQry=function(){this._isArrayQry=!0;var e,t=!0,r=this._query.Where,n=[],s=this.getPrimaryKey(this._query.From),o=function(){if("and"===e){var o=function(){var e=[];this._results.forEach(function(t){var r,o;r=t[s],o=!1,n.every(function(e){return e[s]!==r||(o=!0,!1)}),o&&e.push(t)}),n=e,e=null}.bind(this);n.length>0?o():!0===t?n=this._results:o()}else n.length>0?(this._results=n.concat(this._results),this.removeDuplicates(),n=this._results):n=this._results;r.length>0?(this._results=[],i()):this._results=n,t=!1}.bind(this),i=function(){this._query.Where=r.shift(),this._query.Where.Or&&1===Object.keys(this._query.Where).length?(e="or",this._query.Where=this._query.Where.Or,this._onWhereArrayQrySuccess=o):(e="and",this._onWhereArrayQrySuccess=o),this.processWhere()}.bind(this);i()},n.prototype.onQueryFinished=function(){!0===this._isOr?this.orQuerySuccess():!0===this._isArrayQry?this._onWhereArrayQrySuccess():!0===this._isTransaction&&this.onTransactionCompleted()},n.prototype.initTransaction=function(){t.createTransaction([this._query.From],this.onTransactionCompleted.bind(this),"readonly"),this._objectStore=t.db_transaction.objectStore(this._query.From)},n.prototype.processWhere=function(){this._query.Where.Or&&this.processOrLogic(),this.goToWhereLogic()},n.prototype.onTransactionCompleted=function(){if(!1===this._errorOccured){if(this.processOrderBy(),this._query.Distinct){var e=[],t=this._results[0];for(var r in t)e.push(r);var n=this.getPrimaryKey(this._query.From),s=e.indexOf(n);e.splice(s,1),this._query.GroupBy=e.length>0?e:null}this._query.GroupBy?this._query.Aggregate?this.executeAggregateGroupBy():this.processGroupBy():this._query.Aggregate&&this.processAggregateQry(),this._onSuccess(this._results)}},n.prototype.orQueryFinish=function(){this._isOr=!1,this._results=this._orInfo.Results,this._orInfo=void 0,this.removeDuplicates(),this.onQueryFinished()},n.prototype.orQuerySuccess=function(){if(this._orInfo.Results=this._orInfo.Results.concat(this._results),!this._query.Limit||this._query.Limit>this._orInfo.Results.length){this._results=[];var t=e.getObjectFirstKey(this._orInfo.OrQuery);if(null!=t){var r={};r[t]=this._orInfo.OrQuery[t],delete this._orInfo.OrQuery[t],this._query.Where=r,this.goToWhereLogic()}else this.orQueryFinish()}else this.orQueryFinish()},n.prototype.processOrLogic=function(){this._isOr=!0,this._orInfo={OrQuery:this._query.Where.Or,Results:[]},delete this._query.Where.Or},n}(r.Helper),r.Instance=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Count||(t.Count={}),n=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._resultCount=0,t._checkFlag=!1,t}return __extends(t,e),t}(t.Base),r.BaseCount=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Count||(t.Count={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeWhereUndefinedLogic=function(){if(this._objectStore.count){var e=this._objectStore.count();e.onsuccess=function(){this._resultCount=e.result,this.onQueryFinished()}.bind(this),e.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)}else{var t,r=this._objectStore.openCursor();r.onsuccess=function(e){(t=e.target.result)?(++this._resultCount,t.continue()):this.onQueryFinished()}.bind(this),r.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)}},t}(r.BaseCount),r.NotWhere=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Count||(t.Count={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeInLogic=function(e,t){var r,n,s=this._objectStore.index(e),o=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this);if(this._checkFlag)for(var i=0,u=t.length;i<u;i++)this._errorOccured||((n=s.openCursor(IDBKeyRange.only(t[i]))).onsuccess=function(e){(r=e.target.result)?(this._whereChecker.check(r.value)&&++this._resultCount,r.continue()):i+1===u&&this.onQueryFinished()}.bind(this),n.onerror=o);else if(this._objectStore.count)for(i=0,u=t.length;i<u;i++)this._errorOccured||((n=s.count(IDBKeyRange.only(t[i]))).onsuccess=function(e){this._resultCount+=e.target.result,i+1===u&&this.onQueryFinished()}.bind(this),n.onerror=o);else for(i=0,u=t.length;i<u;i++)this._errorOccured||((n=s.openCursor(IDBKeyRange.only(t[i]))).onsuccess=function(e){(r=e.target.result)?(++this._resultCount,r.continue()):i+1===u&&this.onQueryFinished()}.bind(this),n.onerror=o)},t}(r.NotWhere),r.In=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Count||(t.Count={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeLikeLogic=function(e,t,r){var n;this._compValue=t.toLowerCase(),this._compValueLength=this._compValue.length,this._compSymbol=r;var s=this._objectStore.index(e).openCursor();s.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this),this._checkFlag?s.onsuccess=function(e){(n=e.target.result)?(this.filterOnOccurence(n.key)&&this._whereChecker.check(n.value)&&++this._resultCount,n.continue()):this.onQueryFinished()}.bind(this):s.onsuccess=function(e){(n=e.target.result)?(this.filterOnOccurence(n.key)&&++this._resultCount,n.continue()):this.onQueryFinished()}.bind(this)},t}(r.In),r.Like=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Count||(t.Count={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeWhereLogic=function(e,t,r){var n,s;t=r?t[r]:t,this._checkFlag?(n=this._objectStore.index(e).openCursor(this.getKeyRange(t,r))).onsuccess=function(e){(s=e.target.result)?(this._whereChecker.check(s.value)&&++this._resultCount,s.continue()):this.onQueryFinished()}.bind(this):this._objectStore.count?(n=this._objectStore.index(e).count(this.getKeyRange(t,r))).onsuccess=function(){this._resultCount=n.result,this.onQueryFinished()}.bind(this):(n=this._objectStore.index(e).openCursor(this.getKeyRange(t,r))).onsuccess=function(e){(s=e.target.result)?(++this._resultCount,s.continue()):this.onQueryFinished()}.bind(this),n.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)},t}(r.Like),r.Where=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Count||(t.Count={}),n=function(r){function n(e,t,n){var s=r.call(this)||this;return s._onError=n,s._onSuccess=t,s._query=e,s}return __extends(n,r),n.prototype.execute=function(){if(this.isTableExist(this._query.From))try{void 0!==this._query.Where?(this.addGreatAndLessToNotOp(),this._query.Where.Or||Array.isArray(this._query.Where)?new t.Select.Instance(this._query,function(e){this._resultCount=e.length,this.onTransactionCompleted()}.bind(this),this._onError).execute():(this.initTransaction(),this.goToWhereLogic())):(this.initTransaction(),this.executeWhereUndefinedLogic())}catch(e){this.onExceptionOccured(e,{TableName:this._query.From})}else this._errorOccured=!0,this.onErrorOccured(new e.Error(e.Error_Type.TableNotExist,{TableName:this._query.From}).get(),!0)},n.prototype.initTransaction=function(){t.createTransaction([this._query.From],this.onTransactionCompleted.bind(this),"readonly"),this._objectStore=t.db_transaction.objectStore(this._query.From)},n.prototype.onQueryFinished=function(){!0===this._isTransaction&&this.onTransactionCompleted()},n.prototype.onTransactionCompleted=function(){!1===this._errorOccured&&this._onSuccess(this._resultCount)},n}(r.Where),r.Instance=n}(JsStore||(JsStore={})),function(e){!function(e){(e.Update||(e.Update={})).updateValue=function(e,t){for(var r in e)if("object"!=typeof e[r])t[r]=e[r];else for(var n in e[r]){switch(n){case"+":t[r]+=e[r][n];break;case"-":t[r]-=e[r][n];break;case"*":t[r]*=e[r][n];break;case"/":t[r]/=e[r][n];break;default:t[r]=e[r]}break}return t};var t=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e._checkFlag=!1,e}return __extends(r,t),r.prototype.initTransaction=function(){e.createTransaction([this._query.In],this.onTransactionCompleted.bind(this)),this._objectStore=e.db_transaction.objectStore(this._query.In)},r.prototype.onQueryFinished=function(){!0===this._isTransaction&&this.onTransactionCompleted()},r.prototype.onTransactionCompleted=function(){!1===this._errorOccured&&this._onSuccess(this._rowAffected)},r}(e.Base);e.BaseUpdate=t}(e.Business||(e.Business={}))}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Update||(t.Update={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeWhereUndefinedLogic=function(){var e,t=this._objectStore.openCursor();t.onsuccess=function(t){(e=t.target.result)?(e.update(r.updateValue(this._query.Set,e.value)),++this._rowAffected,e.continue()):this.onQueryFinished()}.bind(this),t.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)},t}(t.BaseUpdate),r.NotWhere=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Update||(t.Update={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeInLogic=function(e,t){var n,s,o=this._objectStore.index(e),i=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this);if(this._checkFlag)for(var u=0,c=t.length;u<c;u++)this._errorOccured||((s=o.openCursor(IDBKeyRange.only(t[u]))).onsuccess=function(e){(n=e.target.result)?(this._whereChecker.check(n.value)&&(n.update(r.updateValue(this._query.Set,n.value)),++this._rowAffected),n.continue()):u+1===c&&this.onQueryFinished()}.bind(this),s.onerror=i);else for(u=0,c=t.length;u<c;u++)this._errorOccured||((s=o.openCursor(IDBKeyRange.only(t[u]))).onsuccess=function(e){(n=e.target.result)?(n.update(r.updateValue(this._query.Set,n.value)),++this._rowAffected,n.continue()):u+1===c&&this.onQueryFinished()}.bind(this),s.onerror=i)},t}(r.NotWhere),r.In=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Update||(t.Update={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeLikeLogic=function(e,t,n){var s;this._compValue=t.toLowerCase(),this._compValueLength=this._compValue.length,this._compSymbol=n;var o=this._objectStore.index(e).openCursor();o.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this),this._checkFlag?o.onsuccess=function(e){(s=e.target.result)?(this.filterOnOccurence(s.key)&&this._whereChecker.check(s.value)&&(s.update(r.updateValue(this._query.Set,s.value)),++this._rowAffected),s.continue()):this.onQueryFinished()}.bind(this):o.onsuccess=function(e){(s=e.target.result)?(this.filterOnOccurence(s.key)&&(s.update(r.updateValue(this._query.Set,s.value)),++this._rowAffected),s.continue()):this.onQueryFinished()}.bind(this)},t}(r.In),r.Like=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Update||(t.Update={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeWhereLogic=function(e,t,n){var s,o;t=n?t[n]:t,o=this._objectStore.index(e).openCursor(this.getKeyRange(t,n)),this._checkFlag?o.onsuccess=function(e){(s=e.target.result)?(this._whereChecker.check(s.value)&&(s.update(r.updateValue(this._query.Set,s.value)),++this._rowAffected),s.continue()):this.onQueryFinished()}.bind(this):o.onsuccess=function(e){(s=e.target.result)?(s.update(r.updateValue(this._query.Set,s.value)),++this._rowAffected,s.continue()):this.onQueryFinished()}.bind(this),o.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)},t}(r.Like),r.Where=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Update||(t.Update={}),n=function(e){function n(t,r,n){var s=e.call(this)||this;return s._onSuccess=r,s._onError=n,s._query=t,s}return __extends(n,e),n.prototype.execute=function(){try{this._error=new r.SchemaChecker(this.getTable(this._query.In)).check(this._query.Set,this._query.In),this._error?(this._errorOccured=!0,this.onErrorOccured(this._error,!0)):void 0!==this._query.Where?(this.addGreatAndLessToNotOp(),this._query.Where.Or||Array.isArray(this._query.Where)?this.executeComplexLogic():(this.initTransaction(),this.goToWhereLogic())):(this.initTransaction(),this.executeWhereUndefinedLogic())}catch(e){this._errorOccured=!0,this.onExceptionOccured.call(this,e,{TableName:this._query.In})}},n.prototype.executeComplexLogic=function(){new t.Select.Instance({From:this._query.In,Where:this._query.Where},function(e){var t=this.getPrimaryKey(this._query.In),r=[],n={};e.forEach(function(e){r.push(e[t])}),e=null,n[t]={In:r},this._query.Where=n,this.initTransaction(),this.goToWhereLogic()}.bind(this),this._onError.bind(this)).execute()},n}(r.Where),r.Instance=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Update||(t.Update={}),n=function(){function t(e){this._table=e}return t.prototype.check=function(t,r){var n=null;return"object"==typeof t?this._table?this._table._columns.every(function(e){return null===n&&(e._name in t&&(n=this.checkByColumn(e,t[e._name])),!0)},this):n=new e.Error(e.Error_Type.TableNotExist,{TableName:r}).get():n=new e.Error(e.Error_Type.NotObject).get(),n},t.prototype.checkByColumn=function(t,r){var n=null;t._notNull&&e.isNull(r)&&(n=new e.Error(e.Error_Type.NullValue,{ColumnName:t._name}).get());var s=e.getType(r);if(t._dataType&&s!==t._dataType&&"object"!==s&&(n=new e.Error(e.Error_Type.BadDataType,{ColumnName:t._name}).get()),"object"===s){var o=["+","-","*","/"];for(var i in r){o.indexOf(i)<0&&t._dataType&&s!==t._dataType&&(n=new e.Error(e.Error_Type.BadDataType,{ColumnName:t._name}).get());break}}return n},t}(),r.SchemaChecker=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Remove||(t.Remove={}),n=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._checkFlag=!1,t}return __extends(t,e),t}(t.Base),r.BaseRemove=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Remove||(t.Remove={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeWhereUndefinedLogic=function(){var e,t=this._objectStore.openCursor();t.onsuccess=function(t){(e=t.target.result)?(e.delete(),++this._rowAffected,e.continue()):this.onQueryFinished()}.bind(this),t.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)},t}(r.BaseRemove),r.NotWhere=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Remove||(t.Remove={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeInLogic=function(e,t){var r,n,s=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this);if(this._checkFlag)for(var o=0,i=t.length;o<i;o++)this._errorOccured||((n=this._objectStore.index(e).openCursor(IDBKeyRange.only(t[o]))).onsuccess=function(e){(r=e.target.result)?(this._whereChecker.check(r.value)&&(r.delete(),++this._rowAffected),r.continue()):o+1===i&&this.onQueryFinished()}.bind(this),n.onerror=s);else for(o=0,i=t.length;o<i;o++)this._errorOccured||((n=this._objectStore.index(e).openCursor(IDBKeyRange.only(t[o]))).onsuccess=function(e){(r=e.target.result)?(r.delete(),++this._rowAffected,r.continue()):o+1===i&&this.onQueryFinished()}.bind(this),n.onerror=s)},t}(r.NotWhere),r.In=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Remove||(t.Remove={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeLikeLogic=function(e,t,r){var n;this._compValue=t.toLowerCase(),this._compValueLength=this._compValue.length,this._compSymbol=r;var s=this._objectStore.index(e).openCursor();s.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this),this._checkFlag?s.onsuccess=function(e){(n=e.target.result)?(this.filterOnOccurence(n.key)&&this._whereChecker.check(n.value)&&(n.delete(),++this._rowAffected),n.continue()):this.onQueryFinished()}.bind(this):s.onsuccess=function(e){(n=e.target.result)?(this.filterOnOccurence(n.key)&&(n.delete(),++this._rowAffected),n.continue()):this.onQueryFinished()}.bind(this)},t}(r.In),r.Like=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Remove||(t.Remove={}),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.executeWhereLogic=function(e,t,r){var n,s;t=r?t[r]:t,s=this._objectStore.index(e).openCursor(this.getKeyRange(t,r)),this._checkFlag?s.onsuccess=function(e){(n=e.target.result)?(this._whereChecker.check(n.value)&&(n.delete(),++this._rowAffected),n.continue()):this.onQueryFinished()}.bind(this):s.onsuccess=function(e){(n=e.target.result)?(n.delete(),++this._rowAffected,n.continue()):this.onQueryFinished()}.bind(this),s.onerror=function(e){this._errorOccured=!0,this.onErrorOccured(e)}.bind(this)},t}(r.Like),r.Where=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Remove||(t.Remove={}),n=function(r){function n(e,t,n){var s=r.call(this)||this;return s._query=e,s._onSuccess=t,s._onError=n,s}return __extends(n,r),n.prototype.execute=function(){try{void 0!==this._query.Where?(this.addGreatAndLessToNotOp(),this.initTransaction(),Array.isArray(this._query.Where)?this.processWhereArrayQry():this.processWhere()):(this.initTransaction(),this.executeWhereUndefinedLogic())}catch(e){this._errorOccured=!0,this.onExceptionOccured(e,{TableName:this._query.From})}},n.prototype.processWhereArrayQry=function(){new t.Select.Instance(this._query,function(e){var t=[],r=this.getPrimaryKey(this._query.From);e.forEach(function(e){t.push(e[r])}),e=null,this._query.Where={},this._query.Where[r]={In:t},this.processWhere(!1)}.bind(this),this._onError).execute()},n.prototype.processWhere=function(){this._query.Where.Or&&this.processOrLogic(),this.goToWhereLogic()},n.prototype.initTransaction=function(){t.createTransaction([this._query.From],this.onTransactionCompleted.bind(this)),this._objectStore=t.db_transaction.objectStore(this._query.From)},n.prototype.onTransactionCompleted=function(){!1===this._errorOccured&&this._onSuccess(this._rowAffected)},n.prototype.onQueryFinished=function(){!0===this._isOr?this.orQuerySuccess():!0===this._isTransaction&&this.onTransactionCompleted()},n.prototype.orQuerySuccess=function(){var t=e.getObjectFirstKey(this._orInfo.OrQuery);if(null!=t){var r={};r[t]=this._orInfo.OrQuery[t],delete this._orInfo.OrQuery[t],this._query.Where=r,this.goToWhereLogic()}else this._isOr=!0},n.prototype.processOrLogic=function(){this._isOr=!0,this._orInfo={OrQuery:this._query.Where.Or},delete this._query.Where.Or},n}(r.Where),r.Instance=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Insert||(t.Insert={}),n=function(n){function s(e,t,r){var s=n.call(this)||this;return s._valuesAffected=[],s._onError=r,s._query=e,s._onSuccess=t,s._tableName=s._query.Into,s}return __extends(s,n),s.prototype.execute=function(){var t=this.getTable(this._tableName);if(Array.isArray(this._query.Values))if(t)try{if(this._query.SkipDataCheck)this.insertData(this._query.Values);else{var n=new r.ValuesChecker(t,this._query.Values);n.checkAndModifyValues(function(e){e?this.onErrorOccured(n._error,!0):this.insertData(n._values),n=void 0}.bind(this))}this._query.Values=void 0}catch(e){this.onExceptionOccured(e,{TableName:this._tableName})}else new e.Error(e.Error_Type.TableNotExist,{TableName:this._tableName}).throw();else this.onErrorOccured(new e.Error(e.Error_Type.NotArray).get(),!0)},s.prototype.onTransactionCompleted=function(){!1===this._errorOccured&&this._onSuccess(this._query.Return?this._valuesAffected:this._rowAffected)},s.prototype.onQueryFinished=function(){!0===this._isTransaction&&this.onTransactionCompleted()},s.prototype.insertData=function(e){var r,n=0;r=this._query.Return?function(t){if(t){var o=s.add(t);o.onerror=this.onErrorOccured.bind(this),o.onsuccess=function(s){this._valuesAffected.push(t),r.call(this,e[n++])}.bind(this)}else this.onQueryFinished()}:function(t){if(t){var o=s.add(t);o.onerror=this.onErrorOccured.bind(this),o.onsuccess=function(t){++this._rowAffected,r.call(this,e[n++])}.bind(this)}else this.onQueryFinished()},t.createTransaction([this._query.Into],this.onTransactionCompleted.bind(this));var s=t.db_transaction.objectStore(this._query.Into);r.call(this,e[n++])},s}(t.Base),r.Instance=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Insert||(t.Insert={}),n=function(){function t(e,t){this._errorOccured=!1,this._autoIncrementValue={},this._table=e,this._autoIncrementValue=t}return t.prototype.checkAndModifyValue=function(e){return this._value=e,this._table._columns.every(function(t){return this.checkAndModifyColumnValue(t,e),!this._errorOccured},this),this._errorOccured},t.prototype.checkNotNullAndDataType=function(t){t._notNull&&e.isNull(this._value[t._name])?this.onValidationError(e.Error_Type.NullValue,{ColumnName:t._name}):t._dataType&&!e.isNull(this._value[t._name])&&e.getType(this._value[t._name])!==t._dataType&&this.onValidationError(e.Error_Type.BadDataType,{ColumnName:t._name})},t.prototype.checkAndModifyColumnValue=function(t){t._autoIncrement?this._value[t._name]=++this._autoIncrementValue[t._name]:t._default&&e.isNull(this._value[t._name])&&(this._value[t._name]=t._default),this.checkNotNullAndDataType(t)},t.prototype.onValidationError=function(t,r){this._errorOccured=!0,this._error=new e.Error(t,r).get()},t}(),r.ValueChecker=n}(JsStore||(JsStore={})),function(e){var t,r,n;t=e.Business||(e.Business={}),r=t.Insert||(t.Insert={}),n=function(){function e(e,t){this._table=e,this._values=t}return e.prototype.checkAndModifyValues=function(e){this._onFinish=e;var n={};this._table._columns.filter(function(e){return e._autoIncrement}).forEach(function(e){var r="JsStore_"+t.active_db._name+"_"+this._table._name+"_"+e._name+"_Value";KeyStore.get(r,function(t){n[e._name]=t})},this),KeyStore.get("dumy_key",function(e){this._valueCheckerObj=new r.ValueChecker(this._table,n),this.startChecking()}.bind(this),function(e){this._error=e,this._onFinish(!0)}.bind(this))},e.prototype.startChecking=function(){var e=!1;if(this._values.every(function(t){return!(e=this._valueCheckerObj.checkAndModifyValue(t))},this),e)this._error=this._valueCheckerObj._error,this._onFinish(!0);else{for(var r in this._valueCheckerObj._autoIncrementValue){var n="JsStore_"+t.active_db._name+"_"+this._table._name+"_"+r+"_Value";KeyStore.set(n,this._valueCheckerObj._autoIncrementValue[r])}KeyStore.get("dumy_key",function(e){this._onFinish(!1)}.bind(this),function(e){this._error=e,this._onFinish(!0)}.bind(this))}},e}(),r.ValuesChecker=n}(JsStore||(JsStore={})),function(e){e.worker_status=e.WebWorker_Status.NotStarted;var t=function(){function t(){this._requestQueue=[],this._isCodeExecuting=!1}return t.prototype.pushApi=function(e,t){return!0===t?new Promise(function(t,r){e.OnSuccess=function(e){t(e)},e.OnError=function(e){r(e)},this.prcoessExecutionOfCode(e)}.bind(this)):(this.prcoessExecutionOfCode(e),this)},t.prototype.createWorker=function(){try{if(Worker){var t=this.getScriptUrl(e.file_name);t&&t.length>0?(e.worker_instance=new Worker(t),e.worker_instance.onmessage=function(e){this.onMessageFromWorker(e)}.bind(this),this.executeCodeUsingWorker({Name:"change_log_status",Query:{logging:e.enable_log}}),setTimeout(function(){e.worker_status!==e.WebWorker_Status.Failed&&(e.worker_status=e.WebWorker_Status.Registered),e.db_status.ConStatus===e.Connection_Status.Connected&&this.executeCode()}.bind(this),100)):this.onWorkerFailed()}else this.onWorkerFailed()}catch(e){this.onWorkerFailed()}},t.prototype.prcoessExecutionOfCode=function(t){if(e.db_status.ConStatus===e.Connection_Status.NotStarted)switch(t.Name){case"create_db":case"open_db":this._requestQueue.splice(0,0,t),e.worker_status!==e.WebWorker_Status.NotStarted&&this.executeCode(),e.db_status.ConStatus=e.Connection_Status.Connected;break;default:this._requestQueue.push(t)}else this._requestQueue.push(t),1===this._requestQueue.length&&e.worker_status!==e.WebWorker_Status.NotStarted&&this.executeCode();e.log("request pushed: "+t.Name)},t.prototype.executeCode=function(){if(!this._isCodeExecuting&&this._requestQueue.length>0){this._isCodeExecuting=!0;var t=this._requestQueue[0],r={Name:t.Name,Query:t.Query};e.log("request executing : "+t.Name),e.worker_status===e.WebWorker_Status.Registered?this.executeCodeUsingWorker(r):this.executeCodeDirect(r)}},t.prototype.executeCodeDirect=function(t){new e.Business.Main(function(e){this.processFinishedRequest(e)}.bind(this)).checkConnectionAndExecuteLogic(t)},t.prototype.executeCodeUsingWorker=function(t){e.worker_instance.postMessage(t)},t.prototype.processFinishedRequest=function(t){var r=this._requestQueue.shift();this._isCodeExecuting=!1,r&&(e.log("request finished : "+r.Name),t.ErrorOccured?r.OnError&&r.OnError(t.ErrorDetails):r.OnSuccess&&r.OnSuccess(t.ReturnedValue),this.executeCode())},t.prototype.onWorkerFailed=function(){console.warn("JsStore is not runing in web worker"),e.worker_status=e.WebWorker_Status.Failed,e.db_status.ConStatus===e.Connection_Status.NotStarted&&this.executeCode()},t.prototype.getScriptUrl=function(e){for(var t="",r=e?e.toLowerCase():"jsstore",n=document.getElementsByTagName("script"),s=n.length-1,o="";s>=0;s--)if((o=(o=n[s].src).substring(o.lastIndexOf("/")+1).toLowerCase()).length>0&&o.indexOf(r)>=0)return t=n[s].src;return t},t.prototype.onMessageFromWorker=function(e){if("string"==typeof e.data)switch(e.data.split(":")[1]){case"WorkerFailed":this.onWorkerFailed()}else this.processFinishedRequest(e.data)},t}();e.CodeExecutionHelper=t}(JsStore||(JsStore={}));var Model=JsStore.Model,DataBase=Model.DataBase,Column=Model.Column,Table=Model.Table,JsStore;!function(e){var t=function(t){function r(r){var n=t.call(this)||this;return e.worker_status===e.WebWorker_Status.Registered?e.worker_instance.terminate():e.worker_status===e.WebWorker_Status.NotStarted&&KeyStore.init(),n.createWorker(),r&&n.openDb(r,null,null),n}return __extends(r,t),r.prototype.openDb=function(e,t,r){return this.pushApi({Name:"open_db",OnError:r,OnSuccess:t,Query:e},!1)},r.prototype.createDb=function(e,t,r){return this.pushApi({Name:"create_db",OnError:r,OnSuccess:t,Query:e},!1)},r.prototype.dropDb=function(e,t){var r=!e;return this.pushApi({Name:"drop_db",OnError:t,OnSuccess:e,Query:null},r)},r.prototype.select=function(e,t,r){t=e.OnSuccess?e.OnSuccess:t,r=e.OnError?e.OnError:r,e.OnSuccess=e.OnError=null;var n=!t;return this.pushApi({Name:"select",OnError:r,OnSuccess:t,Query:e},n)},r.prototype.transaction=function(e,t,r){t=e.OnSuccess?e.OnSuccess:t,r=e.OnError?e.OnError:r,e.OnSuccess=e.OnError=null;var n=!t;return e.Logic=e.Logic.toString(),this.pushApi({Name:"transaction",OnError:r,OnSuccess:t,Query:e},n)},r.prototype.count=function(e,t,r){t=e.OnSuccess?e.OnSuccess:t,r=e.OnError?e.OnError:r,e.OnSuccess=e.OnError=null;var n=!t;return this.pushApi({Name:"count",OnError:r,OnSuccess:t,Query:e},n)},r.prototype.insert=function(e,t,r){t=e.OnSuccess?e.OnSuccess:t,r=e.OnError?e.OnError:r,e.OnSuccess=e.OnError=null;var n=!t;return this.pushApi({Name:"insert",OnError:r,OnSuccess:t,Query:e},n)},r.prototype.update=function(e,t,r){t=e.OnSuccess?e.OnSuccess:t,r=e.OnError?e.OnError:r,e.OnSuccess=e.OnError=null;var n=!t;return this.pushApi({Name:"update",OnError:r,OnSuccess:t,Query:e},n)},r.prototype.delete=function(t,r,n){e.logError("delete is deprecated because delete is reserved keyword in js. Please use remove api.")},r.prototype.remove=function(e,t,r){t=e.OnSuccess?e.OnSuccess:t,r=e.OnError?e.OnError:r,e.OnSuccess=e.OnError=null;var n=!t;return this.pushApi({Name:"remove",OnError:r,OnSuccess:t,Query:e},n)},r.prototype.clear=function(e,t,r){var n=!t;return this.pushApi({Name:"clear",OnError:r,OnSuccess:t,Query:e},n)},r.prototype.bulkInsert=function(e,t,r){t=e.OnSuccess?e.OnSuccess:t,r=e.OnError?e.OnError:r;var n=!t;return e.OnSuccess=e.OnError=null,this.pushApi({Name:"bulk_insert",OnError:r,OnSuccess:t,Query:e},n)},r.prototype.exportJson=function(e){var t=function(t){var r=document.createElement("a");r.href=t,r.download=e.From+".json",r.click(),n&&n(null)},r=e.OnError,n=e.OnSuccess;e.OnSuccess=e.OnError=void 0;var s=!n;if(s)return new Promise(function(n,o){this.pushApi({Name:"export_json",OnError:r,OnSuccess:t,Query:e},s).then(function(e){t(e),n()}).catch(function(e){o(e)})});this.pushApi({Name:"export_json",OnError:r,OnSuccess:t,Query:e},s)},r}(e.CodeExecutionHelper);e.Instance=t}(JsStore||(JsStore={})),self&&!self.alert&&(self.onmessage=function(e){JsStore.log("Request executing from WebWorker, request name: "+e.data.Name);var t=e.data;(new JsStore.Business.Main).checkConnectionAndExecuteLogic(t)},JsStore.worker_status=JsStore.WebWorker_Status.Registered,KeyStore.init());