varOS;!function(e){lett;!function(e){classt{constructor(e){t.REGISTY||(t.REGISTY={}),this.db_file=e.asFileHandle(),t.REGISTY[this.db_file.path]?this.db_file=t.REGISTY[this.db_file.path]:t.REGISTY[this.db_file.path]=this.db_file}pwd(){return"pkg://SQLiteDB/".asFileHandle()}fileinfo(){returnthis.db_file.info}init(){returnnewPromise(async(e,t)=>{try{if(this.db_file.ready)returne(!0);lett={action:"init",args:{db_source:this.db_file.path}},a=awaitthis.call(t);if(a=awaitthis.db_file.onready(),!this.db_file||!this.db_file.ready||"file"!==this.db_file.info.type)throw__("DB file meta-data is invalid: {0}",this.db_file.path).__();e(!0)}catch(e){t(__e(e))}})}call(t){returnnewPromise(async(a,i)=>{t.args.db_source=this.db_file.path;lets={path:this.pwd().path+"/api/api.lua",parameters:t},r=awaite.apigateway(s,!1);r.error?i(e.throwe(__("SQLiteDB server call error: {0}",r.error))):a(r.result)})}request(e){returnnewPromise(async(t,a)=>{try{this.db_file.ready||awaitthis.init(),t(awaitthis.call(e))}catch(e){a(__e(e))}})}select(e){lett={action:"select",args:{filter:e}};returnthis.request(t)}delete_records(e){lett={action:"delete_records",args:{filter:e}};returnthis.request(t)}drop_table(e){lett={action:"drop_table",args:{table_name:e}};returnthis.request(t)}list_tables(){returnthis.request({action:"list_table",args:{}})}create_table(e,t){leta={action:"create_table",args:{table_name:e,scheme:t}};returnthis.request(a)}get_table_scheme(e){lett={action:"table_scheme",args:{table_name:e}};returnthis.request(t)}insert(e,t,a){leti={action:"insert",args:{table_name:e,record:t,pk:a}};returnthis.request(i)}update(e,t,a){leti={action:"update",args:{table_name:e,record:t,pk:a}};returnthis.request(i)}last_insert_id(){returnthis.request({action:"last_insert_id",args:{}})}}leta;!function(e){classaextendse.BaseFileHandle{setPath(e){leta=e.split("@");if(super.setPath(a[0]),a.length>3)thrownewError(__("Invalid file path").__());this.path=e,this._table_name=a[1],this._id=a[2]?parseInt(a[2]):void0,this._handle=newt("home://"+this.genealogy.join("/"))}meta(){returnnewPromise(async(e,t)=>{try{awaitthis._handle.init();lett={result:{file:this._handle.fileinfo(),schema:void0},error:!1};if(this._table_name){conste=awaitthis._handle.get_table_scheme(this._table_name);if(0==e.length)t.result.schema=void0;else{t.result.schema={fields:[],types:{},pk:void0},t.result.schema.fields=e.map(e=>e.name);for(letaofe)t.result.schema.types[a.name]=a.type,a.pk&&(t.result.schema.pk=a.name)}}returne(t)}catch(e){returnt(__e(e))}})}_rd(e){returnnewPromise(async(t,a)=>{try{if(this._table_name&&!this.info.schema)thrownewError(__("Table `{0}` does not exists in database: {1}",this._table_name,this.path).__());if(this._table_name){leta=e;a&&!this._id||(a={}),a.table_name=this._table_name,this._id&&(a.where={id:this._id});leti=awaitthis._handle.select(a);this._id?this.cache=i[0]:this.cache=i,t(this.cache)}else{lete=awaitthis._handle.list_tables();consta={};for(lettofe)a[t.name]=`${this.path}@${t.name}`.asFileHandle();this.cache=a,t(a)}}catch(e){returna(__e(e))}})}_wr(e){returnnewPromise(async(t,a)=>{try{if(!this.cache)thrownewError(__("No data to submit to remote database, please check the `cache` field").__());if(awaitthis.onready(),this._id&&this._table_name)returnthis.cache.id=this._id,voidt({result:awaitthis._handle.update(this._table_name,this.cache,this.info.schema.pk),error:!1});if(this._table_name)returnvoidt({result:awaitthis._handle.insert(this._table_name,this.cache,this.info.schema.pk),error:!1});t({result:awaitthis._handle.create_table(e,this.cache),error:!1})}catch(e){returna(__e(e))}})}_rm(e){returnnewPromise(async(t,a)=>{try{if(this._table_name&&!this.info.schema)thrownewError(__("Table `{0}` does not exists in database: {1}",this._table_name,this.path).__());if(this._table_name){leta=e;a&&!this._id||(a={}),a.table_name=this._table_name,this._id&&(a.where={id:this._id}),t({result:awaitthis._handle.delete_records(a),error:!1})}else{leta=e;if(!a)thrownewError(__("Notablespecifiedf