prostgles-client
Version:
Reactive client for Postgres
1 lines • 133 kB
JavaScript
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(function(){try{return require("react")}catch(e){}}());else if("function"==typeof define&&define.amd)define(["react"],t);else{var n="object"==typeof exports?t(function(){try{return require("react")}catch(e){}}()):t(e.react);for(var s in n)("object"==typeof exports?exports:e)[s]=n[s]}}(Object(this||window),e=>(()=>{var t={9515(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FunctionQueuer=void 0,t.FunctionQueuer=class{constructor(e,t){this.queue=[],this.isRunning=!1,this.startQueueJob=async()=>{if(this.isRunning)return;this.isRunning=!0;const e=async e=>{if(e)try{const t=await this.func(...e.arguments);e.onResult(t)}catch(t){e.onFail(t)}};if(this.groupBy){const t=new Set,n=[];this.queue.forEach(e=>{const s=this.groupBy(e.arguments);t.has(s)||(t.add(s),n.push(e))}),n.slice(0).reverse().forEach(e=>{this.queue.splice(this.queue.indexOf(e),1)}),await Promise.all(n.map(t=>e(t)))}else{const t=this.queue.shift();await e(t)}this.isRunning=!1,this.queue.length&&this.startQueueJob()},this.func=e,this.groupBy=t}async run(e){const t=new Promise((t,n)=>{const s={arguments:e,onResult:t,onFail:n};this.queue.push(s)});return this.startQueueJob(),t}}},3333(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.quickClone=t.mergeDeep=t.SyncedTable=t.debug=void 0;const s=n(3316),r=n(4476),i="DEBUG_SYNCEDTABLE",o="undefined"!=typeof window;t.debug=function(...e){o&&window[i]&&window[i](...e)};const a={map:"map",localStorage:"localStorage"};class c{set multiSubscriptions(e){(0,t.debug)(e,this._multiSubscriptions),this._multiSubscriptions=e.slice(0)}get multiSubscriptions(){return this._multiSubscriptions}set singleSubscriptions(e){(0,t.debug)(e,this._singleSubscriptions),this._singleSubscriptions=e.slice(0)}get singleSubscriptions(){return this._singleSubscriptions}constructor({name:e,filter:n,onChange:r,onReady:i,onDebug:c,db:l,skipFirstTrigger:u=!1,select:d="*",storageType:h="map",patchText:p=!1,patchJSON:f=!1,onError:y}){if(this.throttle=100,this.batch_size=50,this.skipFirstTrigger=!1,this.columns=[],this._multiSubscriptions=[],this._singleSubscriptions=[],this.itemsMap=new Map,this.isSynced=!1,this.updatePatches=async e=>{var t,n;let r=e.map(e=>e.current);const i=[],o=[];if(this.columns.length&&(null===(t=this.tableHandler)||void 0===t?void 0:t.updateBatch)&&(this.patchText||this.patchJSON)){const t=this.columns.filter(e=>"text"===e.data_type);if(this.patchText&&t.length){r=[];const n=[this.synced_field,...this.id_fields];await Promise.all(e.slice(0).map(async(e,a)=>{const{current:c,initial:l}={...e};let u;l&&(t.map(e=>{!n.includes(e.name)&&e.name in c&&(null!=u||(u={...c}),u[e.name]=(0,s.getTextPatch)(l[e.name],c[e.name]))}),u&&this.wal&&(o.push(u),i.push([this.wal.getIdObj(u),this.wal.getDeltaObj(u)]))),u||r.push(c)}))}}if(i.length)try{await(null===(n=this.tableHandler)||void 0===n?void 0:n.updateBatch(i))}catch(e){console.log("failed to patch update",e),r=r.concat(o)}return r.filter(e=>e)},this._notifySubscribers=(e=[])=>{var t,n;if(!this.isSynced)return void(null===(t=this.onDebug)||void 0===t||t.call(this,{command:"notifySubscribers",data:[],info:"not synced yet"}));null===(n=this.onDebug)||void 0===n||n.call(this,{command:"notifySubscribers",data:e});const s=[],r=[],i=[];if(e.map(({idObj:e,newItem:t,delta:n})=>{this.singleSubscriptions.filter(t=>this.matchesIdObj(t.idObj,e)).map(async e=>{try{await e.notify(t,n)}catch(e){console.error("SyncedTable failed to notify: ",e)}}),this.matchesFilter(t)&&(s.push(t),r.push(n),i.push(e))}),this.onChange||this.multiSubscriptions.length){const e=[],t=[];if(this.getItems().map(n=>{e.push({...n});const i=s.findIndex(e=>this.matchesIdObj(n,e));t.push(r[i])}),this.onChange)try{this.onChange(e,t)}catch(e){console.error("SyncedTable failed to notify onChange: ",e)}this.multiSubscriptions.map(async n=>{try{await n.notify(e,t)}catch(e){console.error("SyncedTable failed to notify: ",e)}})}},this.unsubscribe=e=>(this.singleSubscriptions=this.singleSubscriptions.filter(t=>t._onChange!==e),this.multiSubscriptions=this.multiSubscriptions.filter(t=>t._onChange!==e),(0,t.debug)("unsubscribe",this),"ok"),this.unsync=()=>{var e;null===(e=this.dbSync)||void 0===e||e.unsync()},this.destroy=()=>{this.unsync(),this.multiSubscriptions=[],this.singleSubscriptions=[],this.itemsMap.clear(),this.onChange=void 0},this.delete=async(e,t=!1)=>{var n;const s=this.getIdObj(e);return this.setItem(s,!0,!0),!t&&(null===(n=this.tableHandler)||void 0===n?void 0:n.delete)&&await this.tableHandler.delete(s),this._notifySubscribers(),!0},this.checkItemCols=e=>{if(this.columns.length){const t=Object.keys({...e}).filter(e=>!this.columns.find(t=>t.name===e));if(t.length)throw"Unexpected columns in sync item update: "+t.join(", ")}},this.upsert=async(e,n=!1)=>{var r,i;if(!(e&&e.length||n))throw"No data provided for upsert";const o=[];let a;const c=[];await Promise.all(e.map(async(e,r)=>{var i;const l={...e.idObj};let u={...e.delta};Object.keys(u).map(e=>{void 0===u[e]&&(u[e]=null)}),n||this.checkItemCols({...e.delta,...e.idObj});const d=this.getItem(l);!n&&!(0,s.isEmpty)(u)||(0,s.isEmpty)(d)||(u=this.getDelta(d||{},u)),n||(u[this.synced_field]=Date.now());let h={...d,...u,...l};d&&!n&&(null===(i=e.opts)||void 0===i?void 0:i.deepMerge)&&(h=(0,t.mergeDeep)({...d,...l},{...u})),a=d?d[this.synced_field]<h[this.synced_field]?"updated":"unchanged":"inserted",this.setItem(h);const p={idObj:l,delta:u,oldItem:d,newItem:h,status:a,from_server:n};return n||c.push({initial:d,current:{...h}}),(0,s.isEmpty)(p.delta)||o.push(p),!0})).catch(e=>{console.error("SyncedTable failed upsert: ",e)}),null===(r=this.notifyWal)||void 0===r||r.addData(o.map(e=>({initial:e.oldItem,current:e.newItem}))),!n&&c.length&&(null===(i=this.wal)||void 0===i||i.addData(c))},this.setItems=e=>{const n=(0,t.quickClone)(e);if(this.storageType===a.localStorage){if(!o)throw"Cannot access window object. Choose another storage method (array OR object)";window.localStorage.setItem(this.name,JSON.stringify(n))}else this.storageType===a.map&&(this.itemsMap=new Map(n.map(e=>[this.getIdStr(e),{...e}])))},this.getItems=()=>{let e=[];if(this.storageType===a.localStorage){if(!o)throw"Cannot access window object. Choose another storage method (array OR object)";const t=window.localStorage.getItem(this.name);if(t)try{e=JSON.parse(t)}catch(e){console.error(e)}}else this.storageType===a.map&&(e=Array.from(this.itemsMap.values()).map(e=>({...e})));if(!this.id_fields.length||!this.synced_field)throw"id_fields AND/OR synced_field missing";{const t=[this.synced_field,...this.id_fields.sort()];e=e.filter(e=>!this.filter||!(0,s.getKeys)(this.filter).find(t=>e[t]!==this.filter[t])).sort((e,n)=>t.map(t=>e[t]<n[t]?-1:e[t]>n[t]?1:0).find(e=>e))}return(0,t.quickClone)(e)},this.getBatch=({from_synced:e,to_synced:t,offset:n,limit:s}={offset:0,limit:void 0})=>{let r=this.getItems().map(e=>({...e})).filter(n=>(!Number.isFinite(e)||+n[this.synced_field]>=+e)&&(!Number.isFinite(t)||+n[this.synced_field]<=+t));return(n||s)&&(r=r.splice(null!=n?n:0,s||r.length)),r},this.name=e,this.filter=n,this.select=d,this.onChange=r,c&&(this.onDebug=t=>c({...t,type:"sync",tableName:e},this)),!a[h])throw"Invalid storage type. Expecting one of: "+Object.keys(a).join(", ");o||h!==a.localStorage||(console.warn("Could not set storageType to localStorage: window object missing\nStorage changed to map"),h="map"),this.storageType=h,this.patchText=p,this.patchJSON=f;const m=l[e];if(!m)throw`${e} table not found in db`;this.db=l;const{_sync:g,_syncInfo:b}=m;if(!g||!b)throw`${e} table does not support sync`;const{id_fields:_,synced_field:v,throttle:O=100,batch_size:w=50}=b;if(!_.length||!v)throw"id_fields/synced_field missing";this.id_fields=_,this.synced_field=v,this.batch_size=w,this.throttle=O,this.skipFirstTrigger=u,this.multiSubscriptions=[],this.singleSubscriptions=[],this.onError=y||function(e){console.error("Sync internal error: ",e)};const S={id_fields:_,synced_field:v,throttle:O};g(n,{select:d},{onSyncRequest:e=>{var t;let n={c_lr:void 0,c_fr:void 0,c_count:0};const s=this.getBatch(e);return s.length&&(n={c_fr:this.getRowSyncObj(s[0]),c_lr:this.getRowSyncObj(s[s.length-1]),c_count:s.length}),null===(t=this.onDebug)||void 0===t||t.call(this,{command:"onUpdates",data:{syncBatchParams:e,batch:s,clientSyncInfo:n}}),n},onPullRequest:async e=>{var t;const n=this.getBatch(e);return await(null===(t=this.onDebug)||void 0===t?void 0:t.call(this,{command:"onPullRequest",data:{syncBatchParams:e,data:n}})),{data:n}},onUpdates:async e=>{var t,n;if(await(null===(t=this.onDebug)||void 0===t?void 0:t.call(this,{command:"onUpdates",data:{onUpdatesParams:e}})),"err"in e&&e.err)null===(n=this.onError)||void 0===n||n.call(this,e.err);else if("isSynced"in e&&e.isSynced&&!this.isSynced){this.isSynced=e.isSynced;const t=this.getItems().map(e=>({...e}));this.setItems([]);const n=t.map(e=>({idObj:this.getIdObj(e),delta:{...e}}));await this.upsert(n,!0)}else if("data"in e){const t=e.data.map(e=>({idObj:this.getIdObj(e),delta:e}));await this.upsert(t,!0)}else console.error("Unexpected onUpdates");return!0}}).then(e=>{function t(){return"Data may be lost. Are you sure?"}this.dbSync=e,this.wal=new s.WAL({...S,batch_size:w,onSendStart:()=>{o&&(window.onbeforeunload=t)},onSend:async(e,t)=>(await this.updatePatches(t)).length?this.dbSync.syncData(e):[],onSendEnd:()=>{o&&(window.onbeforeunload=null)}}),this.notifyWal=new s.WAL({...S,batch_size:1/0,throttle:5,onSend:async(e,t)=>{this._notifySubscribers(t.map(e=>{var t;return{delta:this.getDelta(null!==(t=e.initial)&&void 0!==t?t:{},e.current),idObj:this.getIdObj(e.current),newItem:e.current}}))}}),i()}),m.getColumns&&m.getColumns().then(e=>{this.columns=e}),this.onChange&&!this.skipFirstTrigger&&setTimeout(this.onChange,0),(0,t.debug)(this)}static create(e){return new Promise((t,n)=>{try{const n=new c({...e,onReady:()=>{setTimeout(()=>{t(n)},0)}})}catch(e){n(e)}})}sync(e,t=!0){const{sub:n,handles:s}=r.getMultiSyncSubscription.bind(this)({onChange:e,handlesOnData:t});return this.multiSubscriptions.push(n),this.skipFirstTrigger||setTimeout(()=>{const e=this.getItems();n.notify(e,e)},0),Object.freeze({...s})}makeSingleSyncHandles(e,n){if(!e||!n)throw"syncOne(idObj, onChange) -> MISSING idObj or onChange";const s={$get:()=>this.getItem(e),$find:e=>this.getItem(e),$unsync:()=>this.unsubscribe(n),$delete:()=>this.delete(e),$update:(n,s)=>{this.singleSubscriptions.length||this.multiSubscriptions.length||(console.warn("No sync listeners"),(0,t.debug)("nosync",this._singleSubscriptions,this._multiSubscriptions)),this.upsert([{idObj:e,delta:n,opts:s}])},$cloneSync:t=>this.syncOne(e,t),$cloneMultiSync:e=>this.sync(e,!0)};return s}syncOne(e,t,n=!0){const s=this.makeSingleSyncHandles(e,t),r={_onChange:t,idObj:e,handlesOnData:n,handles:s,notify:(e,r)=>{const i={...e};return n&&(i.$get=s.$get,i.$find=s.$find,i.$update=s.$update,i.$delete=s.$delete,i.$unsync=s.$unsync,i.$cloneSync=s.$cloneSync),t(i,r)}};return this.singleSubscriptions.push(r),setTimeout(()=>{const e=s.$get();e&&r.notify(e,e)},0),Object.freeze({...s})}getIdStr(e){return this.id_fields.sort().map(t=>`${e[t]||""}`).join(".")}getIdObj(e){const t={};return this.id_fields.sort().map(n=>{t[n]=e[n]}),t}getRowSyncObj(e){const t={};return[this.synced_field,...this.id_fields].sort().map(n=>{t[n]=e[n]}),t}matchesFilter(e){return Boolean(e&&(!this.filter||(0,s.isEmpty)(this.filter)||!Object.keys(this.filter).find(t=>this.filter[t]!==e[t])))}matchesIdObj(e,t){return Boolean(e&&t&&!this.id_fields.sort().find(n=>e[n]!==t[n]))}getDelta(e,t){return(0,s.isEmpty)(e)?{...t}:Object.fromEntries(Object.entries({...t}).filter(([e])=>!this.id_fields.includes(e)).map(([t,n])=>{if(!(0,s.isEqual)(n,e[t]))return[t,(0,s.isObject)(n)?{...n}:Array.isArray(n)?n.slice(0):n]}).filter(s.isDefined))}deleteAll(){this.getItems().map(e=>this.delete(e))}get tableHandler(){const e=this.db[this.name];if((null==e?void 0:e.update)&&e.updateBatch)return e}getItem(e){let n;return n=this.storageType===a.localStorage?this.getItems().find(t=>this.matchesIdObj(t,e)):this.itemsMap.get(this.getIdStr(e)),(0,t.quickClone)(n)}setItem(e,n=!1,s=!1){var r;const i=(0,t.quickClone)(e);if(this.storageType===a.localStorage){let e=this.getItems();if(s)e=e.filter(e=>!this.matchesIdObj(e,i));else{let t=!1;e=e.map(e=>this.matchesIdObj(e,i)?(t=!0,n?{...i}:{...e,...i}):e),t||e.push(i)}o&&window.localStorage.setItem(this.name,JSON.stringify(e))}else{const e=this.getIdStr(i);if(s)this.itemsMap.delete(e);else{const t=null!==(r=this.itemsMap.get(e))&&void 0!==r?r:{};this.itemsMap.set(e,n?{...i}:{...t,...i})}}}}t.SyncedTable=c,t.mergeDeep=(e,n)=>{const r=e?(0,t.quickClone)(e):e,i=n?(0,t.quickClone)(n):n,o=(0,s.isObject)(r)?{...r}:{};return(0,s.isObject)(r)&&(0,s.isObject)(i)&&Object.keys(i).forEach(e=>{const n=i[e],a=r[e];(0,s.isObject)(n)&&(0,s.isObject)(a)?o[e]=(0,t.mergeDeep)(a,n):o[e]=(0,t.quickClone)(n)}),o},t.quickClone=e=>{if(o&&"structuredClone"in window&&"function"==typeof window.structuredClone)return window.structuredClone(e);if(Array.isArray(e))return e.slice(0).map(e=>(0,t.quickClone)(e));if((0,s.isObject)(e)){const n={};return(0,s.getKeys)(e).map(s=>{n[s]=(0,t.quickClone)(e[s])}),n}return e}},4476(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getMultiSyncSubscription=function({onChange:e,handlesOnData:t}){const n={$unsync:()=>this.unsubscribe(e),getItems:()=>this.getItems(),$upsert:e=>{if(!e)throw"No data provided for upsert";const t=e=>({idObj:this.getIdObj(e),delta:e});Array.isArray(e)?this.upsert(e.map(e=>t(e))):this.upsert([t(e)])}};return{sub:{_onChange:e,handlesOnData:t,handles:n,notify:(n,s)=>{let r=[...n];const i=[...s];return t&&(r=r.map((n,s)=>{const r=(n,s)=>({...n,...this.makeSingleSyncHandles(s,e),$get:()=>r(this.getItem(s),s),$find:e=>r(this.getItem(e),e),$update:(e,t)=>this.upsert([{idObj:s,delta:e,opts:t}]).then(e=>!0),$delete:async()=>this.delete(s),$cloneMultiSync:e=>this.sync(e,t)}),i=this.getIdObj(n);return r(n,i)})),e(r,i)}},handles:n}}},2886(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.authRequest=t.getAuthHandler=void 0;const s=n(3316),r=n(9653);t.getAuthHandler=({authData:e,socket:n,onReload:i,endpoint:o,...a})=>{var c;const l=e=>{const{search:t}=window.location;let n=e+t;return o&&(n=`${o}${n}`),n};if((null==e?void 0:e.pathGuard)&&r.isClientSide){const e=e=>{(null==e?void 0:e.shouldReload)&&(i?i():r.isClientSide&&(console.log("prostgles page reload due to authguard",e),setTimeout(()=>{window.location.reload()},200)))};n.emit(s.CHANNELS.AUTHGUARD,JSON.stringify(window.location),(t,n)=>{e(n)}),n.removeAllListeners(s.CHANNELS.AUTHGUARD),n.on(s.CHANNELS.AUTHGUARD,t=>{e(t)})}const u={loginType:null===(c=null==e?void 0:e.login)||void 0===c?void 0:c.mode,login:void 0,preferredLogin:null==e?void 0:e.preferredLogin,loginWithProvider:void 0,signupWithEmailAndPassword:void 0,confirmEmail:void 0,providers:null==e?void 0:e.providers};if(e){const{providers:n,signupWithEmailAndPassword:r,login:i}=e;u.loginWithProvider=(0,s.isEmpty)(n)?void 0:n&&Object.entries(n).reduce((e,[t,{url:n}])=>(e[t]=()=>{window.location.assign(n)},e),{}),u.login=i&&(async e=>(0,t.authRequest)(l(i.loginRoute),e,"POST",a)),u.signupWithEmailAndPassword=r&&(e=>(0,t.authRequest)(l(r.url),e,"POST",a)),u.confirmEmail=r&&(e=>(0,t.authRequest)(l(r.emailConfirmationRoute),e,"POST",a))}return(null==e?void 0:e.user)?{isLoggedin:!0,user:e.user,logout:async()=>{var n;const{logoutRoute:s}=null!==(n=e.login)&&void 0!==n?n:{};if(!s)throw new Error("Unexpected");return(0,t.authRequest)(l(s),{},"POST",a)},...u}:{isLoggedin:!1,user:void 0,...u}},t.authRequest=async(e,t,n,{credentials:s,redirect:r})=>{const i=await fetch(e,{method:n,headers:{Accept:"application/json","Content-Type":"application/json"},..."GET"!==n&&{body:JSON.stringify(t)},credentials:s,redirect:r});if(!i.ok){const e=await i.json().catch(()=>i.text()).catch(()=>i.statusText);return"string"==typeof e?{success:!1,code:"something-went-wrong",message:e}:e}const o=await i.json().catch(async()=>({message:await i.text()})).catch(()=>({message:i.statusText}));return i.redirected?{...o,success:!0,redirect_url:i.url}:o}},9930(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getDB=void 0;const s=n(3316),r=n(8552),i=n(1632),o=n(6469),a=n(3333),c=s.CHANNELS._preffix;t.getDB=({tableSchema:e,onDebug:t,syncedTable:n,syncHandler:l,subscriptionHandler:u,socket:d})=>{var h;const p=(e,t,n,r)=>{if(void 0!==e&&!(0,s.isObject)(e)||void 0!==t&&!(0,s.isObject)(t)||"function"!=typeof n||void 0!==r&&"function"!=typeof r)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},f=["subscribe","subscribeOne"],y={};return(null!==(h=(0,a.quickClone)(e))&&void 0!==h?h:[]).forEach(({name:a,publishInfo:h})=>{const m=(0,s.getAllowedTableMethods)({publishInfo:h});y[a]={};const g=y[a];m.sort((e,t)=>Number((0,s.includes)(f,e))-Number((0,s.includes)(f,t))).forEach(m=>{var b;if("sync"===m){const e=null===(b=h.select)||void 0===b?void 0:b.syncConfig;if(!e)throw`Table ${a} does not have syncConfig in publishInfo.select`;if(g._syncInfo={...e},n){g.getSync=async(e,s={})=>(await(null==t?void 0:t({type:"table",command:"getSync",tableName:a,data:{filter:e,params:s}})),n.create({name:a,onDebug:t,filter:e,db:y,...s}));const e=async(e={},r={},i)=>{var o;const c=`${a}.${JSON.stringify(e)}.${JSON.stringify((0,s.omitKeys)(r,["handlesOnData"]))}`,u=null!==(o=l.syncedTables[c])&&void 0!==o?o:await n.create({...r,onDebug:t,name:a,filter:e,db:y,onError:i});return l.syncedTables[c]=u,u},r=async(n,s={handlesOnData:!0,select:"*"},r,i)=>{await(null==t?void 0:t({type:"table",command:"sync",tableName:a,data:{basicFilter:n,options:s}})),p(n,s,r,i);const o=await e(n,s,i);return await o.sync(r,s.handlesOnData)},i=async(n,s={handlesOnData:!0},r,i)=>{await(null==t?void 0:t({type:"table",command:"syncOne",tableName:a,data:{basicFilter:n,options:s}})),p(n,s,r,i);const o=await e(n,s,i);return await o.syncOne(n,r,s.handlesOnData)};g.sync=r,g.syncOne=i,g.useSync=(e,t,n)=>(0,o.useSync)(r,e,t,n),g.useSyncOne=(e,t,n)=>(0,o.useSync)(i,e,t,n)}g._sync=async function(e,n,s){return await(null==t?void 0:t({type:"table",command:"_sync",tableName:a,data:{param1:e,param2:n,syncHandles:s}})),l.addSync({tableName:a,command:m,param1:e,param2:n},s)}}else if(f.includes(m)){const e=async function(e={},n={},s,r){return await(null==t?void 0:t({type:"table",command:m,tableName:a,data:{param1:e,param2:n,onChange:s,onError:r}})),p(e,n,s,r),u.addSub(y,{tableName:a,command:m,param1:e,param2:n},s,r)};g[m]=e;const n="subscribeOne",s="subscribe"===m?"useSubscribe":"subscribeOne"===m?"useSubscribeOne":void 0;s&&(g[s]=(t,s,r)=>(0,i.useSubscribe)(e,m===n,t,s,r)),m!==n&&f.includes(n)||(g[n]=async function(e,n,s){return await(null==t?void 0:t({type:"table",command:"getSync",tableName:a,data:{param1:e,param2:n,onChange:s}})),p(e,n,s),u.addSub(y,{tableName:a,command:m,param1:e,param2:n},e=>{s(e[0])})})}else{const n=async function(n,s,r){var i;if("getColumns"===m&&!n&&!s&&!r){const t=null===(i=null==e?void 0:e.find(e=>e.name===a))||void 0===i?void 0:i.columns;if(t)return t}return await(null==t?void 0:t({type:"table",command:m,tableName:a,data:{param1:n,param2:s,param3:r}})),new Promise((e,t)=>{d.emit(c,{tableName:a,command:m,param1:n,param2:s,param3:r},(n,s)=>{n?t(n):e(s)})})};g[m]=n;const s="findOne"===m?"useFindOne":"find"===m?"useFind":"count"===m?"useCount":"size"===m?"useSize":void 0;s&&(g[s]=(e,t,s)=>(0,r.useFetch)(n,[e,t],s))}})}),{db:y}}},7030(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getMethods=void 0;const s=n(3316);t.getMethods=({onDebug:e,methods:t,socket:n})=>{let r={};const i={};return JSON.parse(JSON.stringify(t)).map(({name:t,description:o,input:a,output:c})=>{const l=async function(r){return await(null==e?void 0:e({type:"method",command:t,data:{params:r}})),new Promise((e,i)=>{n.emit(s.CHANNELS.METHOD,{name:t,input:r},(t,n)=>{t?i(t):e(n)})})};r[t]={description:o,input:a,output:c,run:l},i[t]=l}),r=Object.freeze(r),{methodSchema:r,methodHandlers:i}}},3382(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getSqlHandler=void 0;const s=n(3316);t.getSqlHandler=({socket:e})=>{let t;const n={};return{sql:function(r,i,o){return new Promise((a,c)=>{e.emit(s.CHANNELS.SQL,{query:r,params:i,options:o},(s,r)=>{if(s)return c(s);if("stream"===(null==o?void 0:o.returnType)){const{channel:t,unsubChannel:n}=r,s=s=>new Promise((r,i)=>{e.on(t,s),e.emit(t,{},(s,o)=>{o?(i(o),e.removeAllListeners(t)):r({pid:s,run:(n,s)=>new Promise((r,i)=>{e.emit(t,{query:n,params:s},(e,t)=>{t?i(t):r(e)})}),stop:t=>new Promise((s,r)=>{e.emit(n,{terminate:t},(e,t)=>{t?r(t):s(e)})})})})});return a({channel:t,unsubChannel:n,start:s})}if(o&&"noticeSubscription"===o.returnType&&r&&Object.keys(r).sort().join()===["socketChannel","socketUnsubChannel"].sort().join()&&!Object.values(r).find(e=>"string"!=typeof e)){const n=r,s=s=>(((e,n,s)=>{null!=t||(t={config:n,listeners:[]}),t.listeners.length||(s.removeAllListeners(n.socketChannel),s.on(n.socketChannel,e=>{t&&t.listeners.length?t.listeners.map(t=>{t(e)}):s.emit(n.socketUnsubChannel,{})})),t.listeners.push(e)})(s,n,e),{...n,removeListener:()=>((e,n)=>{t&&(t.listeners=t.listeners.filter(t=>t!==e),!t.listeners.length&&t.config.socketUnsubChannel&&n&&n.emit(t.config.socketUnsubChannel,{}))})(s,e)}),i={...n,addListener:s};a(i)}else if(o&&o.returnType&&"statement"===o.returnType||!r||Object.keys(r).sort().join()!==["socketChannel","socketUnsubChannel","notifChannel"].sort().join()||Object.values(r).find(e=>"string"!=typeof e))a(r);else{const t=r,s=s=>(((e,t,s)=>{var r;n[t.notifChannel]?null===(r=n[t.notifChannel])||void 0===r||r.listeners.push(e):(n[t.notifChannel]={config:t,listeners:[e]},s.removeAllListeners(t.socketChannel),s.on(t.socketChannel,e=>{var r,i;(null===(r=n[t.notifChannel])||void 0===r?void 0:r.listeners.length)?n[t.notifChannel].listeners.map(t=>{t(e)}):s.emit(null===(i=n[t.notifChannel])||void 0===i?void 0:i.config.socketUnsubChannel,{})}))})(s,t,e),{...r,removeListener:()=>((e,t,s)=>{const r=n[t.notifChannel];r&&(r.listeners=r.listeners.filter(t=>t!==e),!r.listeners.length&&r.config.socketUnsubChannel&&s&&(s.emit(r.config.socketUnsubChannel,{}),delete n[t.notifChannel]))})(s,t,e)}),i={...r,addListener:s};a(i)}})})}}}},395(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getSubscriptionHandler=void 0;const s=n(3316),r=n(9653),i=n(9515),o=s.CHANNELS._preffix;t.getSubscriptionHandler=e=>{const{socket:t,onDebug:n}=e,a=new Map,c=e=>new Promise((n,s)=>{t.emit(e,{},(e,t)=>{e?(console.error(e),s(e)):n(t)})});function l(e,s,i){return(0,r.debug)("_unsubscribe",{channelName:e,handler:i}),new Promise(r=>{const o=a.get(e);o?(o.handlers=o.handlers.filter(e=>e!==i),null==n||n({type:"table",command:"unsubscribe",tableName:o.tableName,unsubChannel:s,handlers:o.handlers}),o.handlers.length||(c(s),t.removeListener(e,o.onCall),a.delete(e)),r(!0)):r(!0)})}function u({tableName:e,command:n,param1:s,param2:r}){return new Promise((i,a)=>{t.emit(o,{tableName:e,command:n,param1:s,param2:r},(e,t)=>{e?(console.error(e),a(e)):t&&i(t)})})}const d=new i.FunctionQueuer(async function(e,{tableName:n,command:r,param1:i,param2:o},d){const h=(t,s)=>{let r={unsubscribe:function(){return l(t,s,d)},filter:{...i}};return e[n].update&&(r={...r,update:function(t,s){return e[n].update(i,t,s)}}),e[n].delete&&(r={...r,delete:function(t){return e[n].delete(i,t)}}),Object.freeze(r)},p=Array.from(a.entries()).find(([e,t])=>t.tableName===n&&t.command===r&&(0,s.isEqual)(t.param1||{},i||{})&&(0,s.isEqual)(t.param2||{},o||{}));if(p){const[e,t]=p;return t.handlers.push(d),setTimeout(()=>{const t=a.get(e);(null==t?void 0:t.lastData)&&d(t.lastData)},10),h(e,t.unsubChannel)}const{channelName:f,channelNameReady:y,channelNameUnsubscribe:m}=await u({tableName:n,command:r,param1:i,param2:o}),g=function(e){const t=a.get(f),{data:n,err:s}=e;t?void 0!==n||void 0!==s?(t.lastData=n,t.handlers.forEach(e=>{void 0!==s&&console.error(`Error within running subscription \n ${f}`,s),e(null!=n?n:[],s)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",e):console.warn("Orphaned subscription: ",f)};return t.on(f,g),a.set(f,{lastData:void 0,tableName:n,command:r,param1:i,param2:o,onCall:g,unsubChannel:m,handlers:[d],reAttach:async()=>{await c(m).catch(console.error),await u({tableName:n,command:r,param1:i,param2:o}),t.emit(y,{now:Date.now()})}}),t.emit(y,{now:Date.now()}),h(f,m)},([e,{tableName:t}])=>t);return{addSub:async(e,t,n,s)=>d.run([e,t,n]),subscriptions:a,addServerSub:u,_unsubscribe:l,reAttachAll:async()=>{await(null==n?void 0:n({type:"subscriptions",command:"reAttachAll.start",subscriptions:a}));for await(const e of Array.from(a.values()))try{await e.reAttach()}catch(t){console.error("There was an issue reconnecting old subscriptions",t,e),e.onCall({data:[],err:t})}await(null==n?void 0:n({type:"subscriptions",command:"reAttachAll.end",subscriptions:a}))}}}},9609(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getSyncHandler=void 0;const s=n(3316),r=n(9515),i=n(9653),o=s.CHANNELS._preffix;t.getSyncHandler=({socket:e})=>{let t={},n={};function a({tableName:t,command:n,param1:s,param2:r},i){return new Promise((a,c)=>{e.emit(o,{tableName:t,command:n,param1:s,param2:r},(t,n)=>{if(t)console.error(t),c(t);else if(n){const{id_fields:t,synced_field:s,channelName:r}=n;e.emit(r,{onSyncRequest:i({})},e=>{console.log(e)}),a({id_fields:t,synced_field:s,channelName:r})}})})}const c=new r.FunctionQueuer(async function({tableName:t,command:r,param1:o,param2:c},l){const{onSyncRequest:u}=l;function d(t){return Object.freeze({unsync:function(){!function(t,s){(0,i.debug)("_unsync",{channelName:t,triggers:s}),new Promise((r,i)=>{n[t]&&(n[t].triggers=n[t].triggers.filter(e=>e.onPullRequest!==s.onPullRequest&&e.onSyncRequest!==s.onSyncRequest&&e.onUpdates!==s.onUpdates),n[t].triggers.length||(e.emit(t+"unsync",{},(e,t)=>{e?i(e):r(t)}),e.removeListener(t,n[t].onCall),delete n[t]))})}(t,l)},syncData:function(n,s,r){e.emit(t,{onSyncRequest:{...u({}),data:n,deleted:s}},r?e=>{r(e)}:null)}})}const h=Object.keys(n).find(e=>{const i=n[e];return i&&i.tableName===t&&i.command===r&&(0,s.isEqual)(i.param1,o)&&(0,s.isEqual)(i.param2,c)});if(h)return n[h].triggers.push(l),d(h);{const s=await a({tableName:t,command:r,param1:o,param2:c},u),{channelName:i}=s,h=function(e,t){e&&n[i]&&n[i].triggers.map(({onUpdates:n,onSyncRequest:s,onPullRequest:r})=>{e.data?Promise.resolve(n(e)).then(()=>{t({ok:!0})}).catch(e=>{t({err:e})}):e.onSyncRequest?Promise.resolve(s(e.onSyncRequest)).then(e=>t({onSyncRequest:e})).catch(e=>{t({err:e})}):e.onPullRequest?Promise.resolve(r(e.onPullRequest)).then(e=>{t(e)}).catch(e=>{t({err:e})}):console.log("unexpected response")})};return n[i]={tableName:t,command:r,param1:o,param2:c,triggers:[l],syncInfo:s,onCall:h},e.on(i,h),d(i)}},([{tableName:e}])=>e);return{destroySyncs:async()=>{(0,i.debug)("destroySyncs",{syncedTables:t}),n={},Object.values(t).forEach(e=>{e.destroy()}),t={}},syncedTables:t,addSync:async function(e,t){return c.run([e,t])},reAttachAll:async()=>{let t=0;Object.entries(n).forEach(async([n,s])=>{const r=s.triggers[0];if(r)try{await a(s,r.onSyncRequest),e.on(n,s.onCall),t++}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}}),t&&console.log("reAttached",t," syncs",n)}}}},4926(e,t,n){"use strict";var s;let r;Object.defineProperty(t,"__esModule",{value:!0}),t.__prglReactInstalled=t.reactImports=t.getReact=void 0;const i=(...e)=>{throw"Must install react"},o=(...e)=>{throw"Must install react"};t.getReact=e=>{try{null!=r||(r=n(9155))}catch(e){}if(e&&!r)throw new Error("Must install react");return r},(0,t.getReact)();const{useEffect:a=i,useCallback:c=i,useRef:l,useState:u=o}=null!==(s=r)&&void 0!==s?s:{},d={useEffect:a,useCallback:c,useRef:l,useState:u,getReact:()=>r};t.reactImports=d,t.__prglReactInstalled=()=>Boolean(r&&l)},7566(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useAsyncEffectQueue=void 0;const s=n(9501),r=n(4926),{useRef:i}=r.reactImports;t.useAsyncEffectQueue=(e,t,n)=>{const r=i(0),o=i(!0),a=i(),c=i(),l=async()=>{var e,t;if("resolved"===(null===(e=c.current)||void 0===e?void 0:e.state)){const{cleanup:e,effect:t,id:n}=c.current;c.current={id:n,state:"cleaning",effect:t},await e().catch(console.error),c.current={id:n,state:"cleaned",effect:t}}if(a.current&&(!c.current||"cleaned"===c.current.state)&&(null===(t=c.current)||void 0===t?void 0:t.id)!==a.current.id){const e=a.current,{effect:t,id:n}=e;c.current={id:n,state:"resolving",effect:t};const s=await t().then(e=>async()=>{await(null==e?void 0:e())}).catch(e=>(console.error(e),async()=>{}));c.current={id:n,state:"resolved",effect:t,cleanup:s},o.current&&e===a.current&&c.current.id===a.current.id||l()}},u=i(null),d=()=>{n?(u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{l()},n)):l()};(0,s.useEffectDeep)(()=>(o.current=!0,a.current={effect:e,deps:t,id:++r.current},d(),()=>{o.current=!1,d()}),t)}},9501(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useEffectDeep=t.useMemoDeep=t.useDeepCompareMemoize=void 0;const s=n(3316),r=n(4926),{getReact:i,useEffect:o,useRef:a}=r.reactImports,c=i();t.useDeepCompareMemoize=e=>{const t=a();return(0,s.isEqual)(e,t.current)||(t.current=e),t.current},t.useMemoDeep=(e,n)=>c.useMemo(e,n.map(t.useDeepCompareMemoize)),t.useEffectDeep=(e,n)=>{o(e,null==n?void 0:n.map(t.useDeepCompareMemoize))}},8552(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useFetch=void 0;const s=n(4926),{useState:r}=s.reactImports,i=n(7566),o=n(6912);t.useFetch=(e,t=[],n)=>{const{skip:s,deps:a=[]}=null!=n?n:{},c={data:void 0,error:void 0,isLoading:!0},[{data:l,error:u,isLoading:d},h]=r(c),p=(0,o.useIsMounted)();return(0,i.useAsyncEffectQueue)(async()=>{if(p()&&!s){h(c);try{const n=await e(...t);if(!p())return;h({data:n,error:void 0,isLoading:!1})}catch(e){if(!p())return;h({data:void 0,error:e,isLoading:!1})}}},[e,...t,...a]),{data:l,error:u,isLoading:d}}},6912(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useIsMounted=void 0;const s=n(4926),{useEffect:r,useRef:i,useCallback:o}=s.reactImports;t.useIsMounted=()=>{const e=i(!0),t=o(()=>e.current,[]);return r(()=>(e.current=!0,()=>{e.current=!1}),[]),t}},1044(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useProstglesClient=t.getIO=void 0;const s=n(9653),r=n(3333),i=n(4926),o=n(7566),a=n(6912);t.getIO=(e=!1)=>{try{return n(8007)}catch(e){}if(e)throw new Error("Must install socket.io-client");return{}},t.useProstglesClient=({skip:e,socketOptions:n,endpoint:c,token:l,...u}={})=>{const{useRef:d,useState:h}=(0,i.getReact)(!0),[p,f]=h({isLoading:!0,hasError:!1}),y=(0,a.useIsMounted)(),m=d();return(0,o.useAsyncEffectQueue)(async()=>{var i,o;if(e)return;null===(i=m.current)||void 0===i||i.disconnect();const a=(0,t.getIO)(),d="string"==typeof n?{path:n}:n,h={withCredentials:u.credentials&&"omit"!==u.credentials,...d,reconnectionDelay:1e3,reconnection:!0};null!==(o=h.path)&&void 0!==o||(h.path="/ws-api"),l&&(h.auth={token:l});const p=c?a(c,h):a(h);return m.current=p,await(0,s.prostgles)({socket:p,endpoint:c,...u,onReady:e=>{var t,n;y()?(null===(n=u.onDebug)||void 0===n||n.call(u,{type:"onReady",data:e}),f({...e,hasError:!1,isLoading:!1})):null===(t=u.onDebug)||void 0===t||t.call(u,{type:"onReady.notMounted",data:e})}},r.SyncedTable).catch(e=>{y()&&f({isLoading:!1,error:e,hasError:!0})}),()=>{p.disconnect(),p.emit=()=>{throw"Socket disconnected"}}},[u,n,e],80),p}},1632(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useSubscribe=void 0;const s=n(3316),r=n(4926),{useRef:i,useState:o}=r.reactImports,a=n(6912),c=n(7566);t.useSubscribe=(e,t,n,r,l)=>{const{skip:u}=null!=l?l:{},d={data:void 0,error:void 0,isLoading:!0},[h,p]=o(d),f=i(h);f.current=h;const y=(0,a.useIsMounted)();return(0,c.useAsyncEffectQueue)(async()=>{if(!y()||u)return;(0,s.isEqual)(f.current,d)||p(d);const i=e=>{y()&&p({data:void 0,error:e,isLoading:!1})};try{const s=await e(n,r,e=>{y()&&p({data:t?e[0]:e,error:void 0,isLoading:!1})},i);return()=>{s.unsubscribe()}}catch(e){i(e)}},[e,n,r,u]),h}},6469(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useSync=void 0;const s=n(4926),{useState:r}=s.reactImports,i=n(7566),o=n(6912);t.useSync=(e,t,n,s)=>{const{skip:a}=null!=s?s:{},[{data:c,error:l,isLoading:u},d]=r({data:void 0,error:void 0,isLoading:!0}),h=(0,o.useIsMounted)();return(0,i.useAsyncEffectQueue)(async()=>{if(!h()||a)return;const s=e=>{h()&&d({data:void 0,error:e,isLoading:!1})};try{return(await e(t,n,e=>{h()&&d({data:e,error:void 0,isLoading:!1})},s)).$unsync}catch(e){s(e)}},[e,t,n,a]),{data:c,error:l,isLoading:u}}},9653(e,t,n){"use strict";var s=this&&this.__createBinding||(Object.create?function(e,t,n,s){void 0===s&&(s=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,s,r)}:function(e,t,n,s){void 0===s&&(s=n),e[s]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||s(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.asName=t.debug=t.isClientSide=void 0,t.prostgles=function(e,n){const{endpoint:s,socket:r,onReady:h,onDisconnect:p,onReconnect:f,onSchemaChange:y,onReload:m,onDebug:g,credentials:b,redirect:_}=e;let v;(0,t.debug)("prostgles",{initOpts:e}),y&&(r.removeAllListeners(i.CHANNELS.SCHEMA_CHANGED),r.on(i.CHANNELS.SCHEMA_CHANGED,y));const O=(0,u.getSubscriptionHandler)(e),w=(0,d.getSyncHandler)(e);let S;return(0,l.getSqlHandler)(e),new Promise((t,u)=>{r.removeAllListeners("connect_error"),r.on("connect_error",e=>{u(e)}),r.removeAllListeners(i.CHANNELS.CONNECTION),r.on(i.CHANNELS.CONNECTION,e=>(u(e),"ok")),p&&r.on("disconnect",()=>{S="disconnected",p()}),f&&r.on("connect",()=>{"disconnected"===S&&(S="reconnected")}),r.on(i.CHANNELS.SCHEMA,async d=>{await(null==g?void 0:g({type:"schemaChanged",data:d,state:S}));const{joinTables:p=[],...y}=d,{methods:k,tableSchema:T,auth:E,rawSQL:C,err:j}=y;if((null==v?void 0:v.clientSchema)&&(0,i.isEqual)(v.clientSchema,y)||w.destroySyncs().catch(e=>console.error("Error while destroying syncs",e)),j&&console.error("Error on schema change:",j),"connected"!==S&&"reconnected"!==S||!f)v={origin:"onReady",date:new Date,clientSchema:y};else{if(f(r,j),j)return;v={origin:"onReconnect",date:new Date,clientSchema:y}}if(j)return void u(j);const P="reconnected"===S;S="connected";const N=(0,o.getAuthHandler)({authData:E,socket:r,onReload:m,endpoint:s,credentials:b,redirect:_}),{methodHandlers:A,methodSchema:x}=(0,c.getMethods)({onDebug:g,methods:k,socket:r}),{db:R}=(0,a.getDB)({onDebug:g,syncedTable:n,syncHandler:w,subscriptionHandler:O,socket:r,tableSchema:T}),M=C?(0,l.getSqlHandler)(e).sql:void 0;O.reAttachAll(),w.reAttachAll(),(async()=>{try{const e={db:R,sql:M,methods:A,methodSchema:x,tableSchema:T,auth:N,socket:r,isReconnect:P};await(null==g?void 0:g({type:"onReady.call",data:e,state:S})),await h(e)}catch(e){console.error("Prostgles: Error within onReady: \n",e),u(e)}t(R)})()})})};const i=n(3316);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return i.asName}});const o=n(2886),a=n(9930),c=n(7030),l=n(3382),u=n(395),d=n(9609),h="DEBUG_SYNCEDTABLE";t.isClientSide="undefined"!=typeof window,t.debug=function(...e){t.isClientSide&&window[h]&&window[h](...e)},r(n(9501),t),r(n(1044),t)},7833(e,t,n){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let s=0,r=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(s++,"%c"===e&&(r=s))}),t.splice(r,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=n(736)(t);const{formatters:s}=e.exports;s.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},736(e,t,n){e.exports=function(e){function t(e){let n,r,i,o=null;function a(...e){if(!a.enabled)return;const s=a,r=Number(new Date),i=r-(n||r);s.diff=i,s.prev=n,s.curr=r,n=r,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let o=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(n,r)=>{if("%%"===n)return"%";o++;const i=t.formatters[r];if("function"==typeof i){const t=e[o];n=i.call(s,t),e.splice(o,1),o--}return n}),t.formatArgs.call(s,e),(s.log||t.log).apply(s,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=s,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==o?o:(r!==t.namespaces&&(r=t.namespaces,i=t.enabled(e)),i),set:e=>{o=e}}),"function"==typeof t.init&&t.init(a),a}function s(e,n){const s=t(this.namespace+(void 0===n?":":n)+e);return s.log=this.log,s}function r(e,t){let n=0,s=0,r=-1,i=0;for(;n<e.length;)if(s<t.length&&(t[s]===e[n]||"*"===t[s]))"*"===t[s]?(r=s,i=n,s++):(n++,s++);else{if(-1===r)return!1;s=r+1,i++,n=i}for(;s<t.length&&"*"===t[s];)s++;return s===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const n=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of n)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(const n of t.skips)if(r(e,n))return!1;for(const n of t.names)if(r(e,n))return!0;return!1},t.humanize=n(6585),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}},6585(e){var t=1e3,n=60*t,s=60*n,r=24*s,i=7*r;function o(e,t,n,s){var r=t>=1.5*n;return Math.round(e/n)+" "+s+(r?"s":"")}e.exports=function(e,a){a=a||{};var c,l,u=typeof e;if("string"===u&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var o=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(o){var a=parseFloat(o[1]);switch((o[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*a;case"weeks":case"week":case"w":return a*i;case"days":case"day":case"d":return a*r;case"hours":case"hour":case"hrs":case"hr":case"h":return a*s;case"minutes":case"minute":case"mins":case"min":case"m":return a*n;case"seconds":case"second":case"secs":case"sec":case"s":return a*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}(e);if("number"===u&&isFinite(e))return a.long?(c=e,(l=Math.abs(c))>=r?o(c,l,r,"day"):l>=s?o(c,l,s,"hour"):l>=n?o(c,l,n,"minute"):l>=t?o(c,l,t,"second"):c+" ms"):function(e){var i=Math.abs(e);return i>=r?Math.round(e/r)+"d":i>=s?Math.round(e/s)+"h":i>=n?Math.round(e/n)+"m":i>=t?Math.round(e/t)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},3316(e){var t;Object(this||window),t=()=>(()=>{"use strict";var e={994(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=t.PrimitiveTypesObj=void 0;const s=n(472);t.PrimitiveTypesObj={boolean:1,number:1,integer:1,string:1,Date:1,time:1,timestamp:1,Blob:1,FileLike:1,any:1,unknown:1},t.PrimitiveTypes=(0,s.getKeys)(t.PrimitiveTypesObj),t.PrimitiveArrayTypes=t.PrimitiveTypes.map(e=>`${e}[]`),t.DATA_TYPES=[...t.PrimitiveTypes,...t.PrimitiveArrayTypes]},897(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.assertJSONBObjectAgainstSchema=t.validateJSONBObjectAgainstSchema=t.getJSONBSchemaValidationError=t.getJSONBObjectSchemaValidationError=t.getFieldTypeObj=void 0;const s=n(472),r=n(704),i=n(441);t.getFieldTypeObj=e=>"string"==typeof e?{type:e}:e;const o=e=>e instanceof Blob||"undefined"!=typeof Buffer&&e instanceof Buffer||"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer,a={string:e=>"string"==typeof e,number:e=>"number"==typeof e&&Number.isFinite(e),integer:e=>"number"==typeof e&&Number.isInteger(e),boolean:e=>"boolean"==typeof e,time:e=>"string"==typeof e,timestamp:e=>"string"==typeof e,any:e=>"function"!=typeof e&&"symbol"!=typeof e,unknown:e=>"function"!=typeof e&&"symbol"!=typeof e,Date:e=>"string"==typeof e,Lookup:e=>{throw new Error("Lookup type is not supported for validation")},Blob:o,FileLike:(e,t)=>{if("FileLike"!==t.type)throw new Error("FileLike type must have type 'FileLike'");const n=(0,s.isObject)(e)&&"string"==typeof e.name&&"string"==typeof e.type&&o(e.data);if(n&&t.mimeTypes&&!Object.keys(t.mimeTypes).some(t=>e.type===t))throw new Error(`Invalid FileLike type. Expected one of: ${Object.keys(t.mimeTypes).join(", ")}`);return n}},c=(0,s.getKeys)(a),l=(e,n,o=[],d)=>{const h=`${o.join(".")} is of invalid type. Expecting ${u(n).replaceAll("\n","")}`,p=(0,t.getFieldTypeObj)(n),{type:f,allowedValues:y,nullable:m,optional:g}=p;if(m&&null===e)return;if(g&&void 0===e)return;if(y){if("string"!=typeof f)throw new Error("allowedValues is only supported for primitive types");const t=f.endsWith("[]"),n=t&&Array.isArray(e)?e:[e],r=y.map(e=>(0,s.isObject)(e)?e.value:e);for(const[e,s]of n.entries())if(!r.includes(s))return`${t?`${o.join(".")}[${e}]`:o.join(".")} is of invalid type. Expecting ${r.map(e=>"string"==typeof e?JSON.stringify(e):String(e)).join(" | ")} But got ${JSON.stringify(s)}`}if(f){if((0,s.isObject)(f)){if(!(0,s.isObject)(e))return h;for(const t of(0,r.safeGetKeys)(f)){const n=(0,r.safeGetProperty)(f,t);if(!((0,s.isObject)(n)&&n.optional||(0,r.safeHasOwn)(e,t)))return`${[...o,t].join(".")} is missing but required`;const i=l((0,r.safeGetProperty)(e,t),n,[...o,t],d);if(void 0!==i)return i}if(!d?.allowExtraProperties){const t=(0,r.safeGetKeys)(e),n=(0,r.safeGetKeys)(f),s=t.filter(e=>!n.includes(e));if(s.length)return`${o.join(".")} has extra properties: ${s.join(", ")}`}return}const{validator:t}=((e,t)=>{const n=(e=>{if("string"==typeof e&&e.endsWith("[]")){const t=e.slice(0,-2);if(!(0,i.includes)(c,t))throw new Error(`Invalid array field type ${e}`);return t}})(e);if(n){const e=a[n];return{isArray:!0,validator:n=>Array.isArray(n)&&n.every(n=>e(n,t))}}const s=a[e];if(!s)throw new Error(`Unknown field type ${e}`);return{isArray:!1,validator:s}})(f,p);return t(e,p)?void 0:h}if(p.enum){const t=[];return p.nullable&&t.push(null),p.optional&&t.push(void 0),p.enum.includes(e)?void 0:h}const b=p.arrayOf??(p.arrayOfType?{type:p.arrayOfType}:void 0);if(b){if(!Array.isArray(e))return h+" an array";const t=e.map((e,t)=>l(e,b,[...o,`${t}`],d)).filter(s.isDefined)[0];return void 0!==t?`${h}. Error at index ${o.length>0?o.join(".")+".":""}\n\n${t}`:void 0}const _=p.oneOf??p.oneOfType?.map(e=>({type:e}));if(_){if(!_.length)return h+"to not be empty";let t;if(_.find(n=>{const s=l(e,n,o,d);return t??(t=s),void 0===s}))return;return h}if(p.record){const{keysEnum:t,partial:n,values:i}=p.record;if(!(0,s.isObject)(e))return h+"object";if(n&&(0,s.isEmpty)(e))return;const a=(0,s.getKeys)(e),c=n?void 0:t?.find(e=>!a.includes(e));if(void 0!==c)return`${h} to have key ${c}`;const u=t&&a.filter(e=>!t.includes(e));if(u?.length)return`${h} has extra keys: ${u}`;if(i)for(const t of(0,r.safeGetKeys)(e)){const n=(0,r.safeGetProperty)(e,t),s=l(n,i,[...o,t],d);if(void 0!==s)return`${s}`}return}return`Could not validate field type. Some logic might be missing: ${JSON.stringify(p)}`},u=e=>{const n=(0,t.getFieldTypeObj)(e),{type:r,nullable:i,optional:o,record:a}=n,c=n.oneOf??n.oneOfType?.map(e=>({type:e})),l=[];if(i&&l.push("null"),o&&l.push("undefined"),"string"==typeof r)l.push(r);else if(r&&(0,s.isObject)(r)){const e=[];Object.entries(r).forEach(([t,n])=>{e.push(`${t}: ${u(n)}`)}),l.push(`{ ${e.join("; ")} }`)}if(n.enum?.forEach(e=>{null===e?l.push("null"):void 0===e?l.push("undefined"):"string"==typeof e?l.push(JSON.stringify(e)):l.push(e)}),c?.forEach(e=>{const t=u(e);l.push(t)}),a){const{keysEnum:e,partial:t,values:n}=a,s=t?"?":"",r=n?u(n):"any";e?l.push(`{ [${e.join(" | ")}]${s}: ${r} }`):l.push(`{ [key: string]${s}: ${r} }`)}return l.join(" | ")};t.getJSONBObjectSchemaValidationError=(e,t,n="input",r=!1,i)=>{if(void 0===t&&!r)return{error:`Expecting ${n} to be defined`};if(!(0,s.isObject)(t))return{error:`Expecting ${n} to be an object`};const o=l(t,{type:e},[],i);return o?{error:o}:{data:t}},t.getJSONBSchemaValidationError=(e,t,n)=>{const s=l(t,e,void 0,n);return s?{error:s}:{data:t}},t.validateJSONBObjectAgainstSchema=(e,n,s,r=!1)=>{const{error:i}=(0,t.getJSONBObjectSchemaValidationError)(e,n,s,r);return void 0===i},t.assertJSONBObjectAgainstSchema=(e,n,s,r=!1)=>{const{error:i}=(0,t.getJSONBObjectSchemaValidationError)(e,n,s,r);if(i)throw new Error(i)}},699(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONSchemaObject=void 0,t.getJSONBSchemaAsJSONSchema=function(e,n,s){return(0,t.getJSONSchemaObject)(s,{id:`${e}.${n}`})};const s=n(472),r=n(704),i=e=>{if(!e)return;const t=e.endsWith("[]")?e.slice(0,-2):e;return{type:"integer"===t?"integer":"boolean"===t?"boolean":"number"===t?"number":"any"===t||"unknown"===t||"Lookup"===t||"Blob"===t||"FileLike"===t?void 0:"string",isArray:e.endsWith("[]")}};t.getJSONSchemaObject=(e,n)=>{const{type:o,arrayOf:a,arrayOfType:c,description:l,nullable:u,oneOf:d,oneOfType:h,title:p,record:f,...y}="string"==typeof e?{type:e}:e;let m={};const g={...(y.enum||y.allowedValues?.length&&("string"!=typeof o||!o.endsWith("[]")))&&{enum:y.allowedValues?.slice(0)??y.enum.slice(0)},...!!l&&{description:l},...!!p&&{title:p}};if(y.enum?.length){const e=typeof y.enum[0];g.type="number"===e?"number":"boolean"===e?"boolean":"string"}if("string"==typeof o||a||c){if(o&&"string"!=typeof o)throw"Not expected";m=a||c||o?.endsWith("[]")?{type:"array",items:a||c?(0,t.getJSONSchemaObject)(a||{type:c}):o?.startsWith("any")?{type:void 0}:{type:i(o)?.type,...y.allowedValues&&{enum:y.allowedValues.slice(0)}}}:{type:i(o)?.type}}else(0,s.isObject)(o)?m={type:"object",required:(0,r.safeGetKeys)(o).filter(e=>{const t=o[e];return"string"==typeof t||!t.optional}),properties:(0,s.getObjectEntries)(o).reduce((e,[n,s])=>({...e,[n]:(0,t.getJSONSchemaObject)(s)}),{})}:d||h?m={oneOf:(d||h.map(e=>({type:e}))).map(e=>(0,t.getJSONSchemaObject)(e))}:f&&(m={type:"object",...f.values&&!f.keysEnum&&{additionalProperties:(0,t.getJSONSchemaObject)(f.values)},...f.keysEnum&&{properties:f.keysEnum.reduce((e,n)=>({...e,[n]:f.values?(0,t.getJSONSchemaObject)(f.values):{type:{}}}),{})}});if(u){const e={type:"null"};m.oneOf?m.oneOf.push(e):m.enum&&!m.enum.includes(null)?m.enum.push(null):m={oneOf:[m,e]}}return{...n?{$id:n?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...g,...m}}},394(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBTSTypes=void 0,t.getJSONBSchemaTSTypes=function(e,n,s="",r){return(0,t.getJSONBTSTypes)(r,{...e,nullable:n.nullable},void 0,s)};const s=n(806),r=n(897),i=e=>null===e?"null":void 0===e?"undefined":"string"==typeof e?JSON.stringify(e):String(e);t.getJSONBTSTypes=(e,n,a=!1,c="",l=0)=>{const u=(0,r.getFieldTypeObj)(n),d=u.nullable?"null | ":"";if(u.lookup){const n=u.lookup;if("data-def"===n.type)return`${u.nullable?"null |":""} ${(0,t.getJSONBTSTypes)(e,{type:{table:"string",column:"string",filter:{record:{},optional:!0},isArray:{type:"boolean",optional:!0},searchColumns:{type:"string[]",optional:!0},isFullRow:{