UNPKG

prostgles-client

Version:

Reactive client for Postgres

2 lines 134 kB
/*! For license information please see index.no-sync.js.LICENSE.txt */ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this||window,(()=>(()=>{var e={515:(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.func=e,this.groupBy=t}async run(e){const t=new Promise(((t,n)=>{const r={arguments:e,onResult:t,onFail:n};this.queue.push(r)})),n=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=[],n=[];this.queue.forEach((async(e,r)=>{const s=this.groupBy(e.arguments);t.includes(s)||(t.push(s),n.push({index:r,item:e}))})),n.slice(0).reverse().forEach((e=>{this.queue.splice(e.index,1)})),await Promise.all(n.map((t=>e(t.item))))}else{const t=this.queue.shift();await e(t)}this.isRunning=!1,this.queue.length&&n()};return n(),t}}},333:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.quickClone=t.SyncedTable=t.debug=void 0;const r=n(316),s=n(476),i="DEBUG_SYNCEDTABLE",o="undefined"!=typeof window;t.debug=function(...e){o&&window[i]&&window[i](...e)};const a={array:"array",localStorage:"localStorage",object:"object"};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:s,onReady:i,onDebug:c,db:d,skipFirstTrigger:h=!1,select:p="*",storageType:f="object",patchText:y=!1,patchJSON:m=!1,onError:g}){if(this.throttle=100,this.batch_size=50,this.skipFirstTrigger=!1,this.columns=[],this._multiSubscriptions=[],this._singleSubscriptions=[],this.items=[],this.itemsObj={},this.isSynced=!1,this.updatePatches=async e=>{var t,n;let s=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){s=[];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,r.getTextPatch)(l[e.name],c[e.name]))})),u&&this.wal&&(o.push(u),i.push([this.wal.getIdObj(u),this.wal.getDeltaObj(u)]))),u||s.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),s=s.concat(o)}return s.filter((e=>e))},this._notifySubscribers=(e=[])=>{if(!this.isSynced)return;const t=[],n=[],r=[];if(e.map((({idObj:e,newItem:s,delta:i})=>{this.singleSubscriptions.filter((t=>this.matchesIdObj(t.idObj,e))).map((async e=>{try{await e.notify(s,i)}catch(e){console.error("SyncedTable failed to notify: ",e)}})),this.matchesFilter(s)&&(t.push(s),n.push(i),r.push(e))})),this.onChange||this.multiSubscriptions.length){const e=[],r=[];if(this.getItems().map((s=>{e.push({...s});const i=t.findIndex((e=>this.matchesIdObj(s,e)));r.push(n[i])})),this.onChange)try{this.onChange(e,r)}catch(e){console.error("SyncedTable failed to notify onChange: ",e)}this.multiSubscriptions.map((async t=>{try{await t.notify(e,r)}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.itemsObj={},this.items=[],this.onChange=void 0},this.delete=async(e,t=!1)=>{var n;const r=this.getIdObj(e);return this.setItem(r,void 0,!0,!0),!t&&(null===(n=this.tableHandler)||void 0===n?void 0:n.delete)&&await this.tableHandler.delete(r),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,t=!1)=>{var n,s;if(!(e&&e.length||t))throw"No data provided for upsert";const i=[];let o;const a=[];await Promise.all(e.map((async(e,n)=>{var s;const c={...e.idObj};let u={...e.delta};Object.keys(u).map((e=>{void 0===u[e]&&(u[e]=null)})),t||this.checkItemCols({...e.delta,...e.idObj});const d=this.getItem(c),h=d.index,p=d.data;!t&&!(0,r.isEmpty)(u)||(0,r.isEmpty)(p)||(u=this.getDelta(p||{},u)),t||(u[this.synced_field]=Date.now());let f={...p,...u,...c};p&&!t&&(null===(s=e.opts)||void 0===s?void 0:s.deepMerge)&&(f=l({...p,...c},{...u})),o=p?p[this.synced_field]<f[this.synced_field]?"updated":"unchanged":"inserted",this.setItem(f,h);const y={idObj:c,delta:u,oldItem:p,newItem:f,status:o,from_server:t};return t||a.push({initial:p,current:{...f}}),(0,r.isEmpty)(y.delta)||i.push(y),!0}))).catch((e=>{console.error("SyncedTable failed upsert: ",e)})),null===(n=this.notifyWal)||void 0===n||n.addData(i.map((e=>({initial:e.oldItem,current:e.newItem})))),!t&&a.length&&(null===(s=this.wal)||void 0===s||s.addData(a))},this.setItems=e=>{const t=u(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(t))}else this.storageType===a.array?this.items=t:this.itemsObj=t.reduce(((e,t)=>({...e,[this.getIdStr(t)]:{...t}})),{})},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 e=this.storageType===a.array?this.items.map((e=>({...e}))):Object.values({...this.itemsObj});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,r.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 u(e)},this.getBatch=({from_synced:e,to_synced:t,offset:n,limit:r}={offset:0,limit:void 0})=>{let s=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||r)&&(s=s.splice(null!=n?n:0,r||s.length)),s},this.name=e,this.filter=n,this.select=p,this.onChange=s,c&&(this.onDebug=t=>c({...t,type:"sync",tableName:e},this)),!a[f])throw"Invalid storage type. Expecting one of: "+Object.keys(a).join(", ");o||f!==a.localStorage||(console.warn("Could not set storageType to localStorage: window object missing\nStorage changed to object"),f="object"),this.storageType=f,this.patchText=y,this.patchJSON=m;const b=d[e];if(!b)throw`${e} table not found in db`;this.db=d;const{id_fields:_,synced_field:v,throttle:O=100,batch_size:S=50}=b._syncInfo;if(!_||!v)throw"id_fields/synced_field missing";this.id_fields=_,this.synced_field=v,this.batch_size=S,this.throttle=O,this.skipFirstTrigger=h,this.multiSubscriptions=[],this.singleSubscriptions=[],this.onError=g||function(e){console.error("Sync internal error: ",e)};const w={id_fields:_,synced_field:v,throttle:O};b._sync(n,{select:p},{onSyncRequest:e=>{var t;let n={c_lr:void 0,c_fr:void 0,c_count:0};const r=this.getBatch(e);return r.length&&(n={c_fr:this.getRowSyncObj(r[0]),c_lr:this.getRowSyncObj(r[r.length-1]),c_count:r.length}),null===(t=this.onDebug)||void 0===t||t.call(this,{command:"onUpdates",data:{syncBatchParams:e,batch:r,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}})),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 r.WAL({...w,batch_size:S,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 r.WAL({...w,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()})),b.getColumns&&b.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:r}=s.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({...r})}makeSingleSyncHandles(e,n){if(!e||!n)throw"syncOne(idObj, onChange) -> MISSING idObj or onChange";const r={$get:()=>this.getItem(e).data,$find:e=>this.getItem(e).data,$unsync:()=>this.unsubscribe(n),$delete:()=>this.delete(e),$update:(n,r)=>{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:r}])},$cloneSync:t=>this.syncOne(e,t),$cloneMultiSync:e=>this.sync(e,!0)};return r}syncOne(e,t,n=!0){const r=this.makeSingleSyncHandles(e,t),s={_onChange:t,idObj:e,handlesOnData:n,handles:r,notify:(e,s)=>{const i={...e};return n&&(i.$get=r.$get,i.$find=r.$find,i.$update=r.$update,i.$delete=r.$delete,i.$unsync=r.$unsync,i.$cloneSync=r.$cloneSync),t(i,s)}};return this.singleSubscriptions.push(s),setTimeout((()=>{const e=r.$get();e&&s.notify(e,e)}),0),Object.freeze({...r})}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,r.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,r.isEmpty)(e)?{...t}:Object.fromEntries(Object.entries({...t}).filter((([e])=>!this.id_fields.includes(e))).map((([t,n])=>{if(!(0,r.isEqual)(n,e[t]))return[t,(0,r.isObject)(n)?{...n}:Array.isArray(n)?n.slice(0):n]})).filter(r.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 t;return t=this.storageType===a.localStorage?this.getItems().find((t=>this.matchesIdObj(t,e))):this.storageType===a.array?this.items.find((t=>this.matchesIdObj(t,e))):{...this.itemsObj}[this.getIdStr(e)],{data:u(t),index:-1}}setItem(e,t,n=!1,r=!1){const s=u(e);if(this.storageType===a.localStorage){let e=this.getItems();r?e=e.filter((e=>!this.matchesIdObj(e,s))):void 0!==t&&e[t]?e[t]=n?{...s}:{...e[t],...s}:e.push(s),o&&window.localStorage.setItem(this.name,JSON.stringify(e))}else if(this.storageType===a.array)r?this.items=this.items.filter((e=>!this.matchesIdObj(e,s))):void 0===t||this.items[t]?void 0!==t&&(this.items[t]=n?{...s}:{...this.items[t],...s}):this.items.push(s);else if(r)delete this.itemsObj[this.getIdStr(s)];else{const e=this.itemsObj[this.getIdStr(s)]||{};this.itemsObj[this.getIdStr(s)]=n?{...s}:{...e,...s}}}}function l(e,t){const n=e?u(e):e,s=t?u(t):t,i=Object.assign({},n);return(0,r.isObject)(n)&&(0,r.isObject)(s)&&Object.keys(s).forEach((e=>{(0,r.isObject)(s[e])?e in n?i[e]=l(n[e],s[e]):Object.assign(i,{[e]:s[e]}):Object.assign(i,{[e]:s[e]})})),i}function u(e){if(o&&"structuredClone"in window&&"function"==typeof window.structuredClone)return window.structuredClone(e);if(Array.isArray(e))return e.slice(0).map((e=>u(e)));if((0,r.isObject)(e)){const t={};return(0,r.getKeys)(e).map((n=>{t[n]=u(e[n])})),t}return e}t.SyncedTable=c,t.default=l,t.quickClone=u},476:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getMultiSyncSubscription=void 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,r)=>{let s=[...n];const i=[...r];return t&&(s=s.map(((n,r)=>{const s=(n,r)=>({...n,...this.makeSingleSyncHandles(r,e),$get:()=>s(this.getItem(r).data,r),$find:e=>s(this.getItem(e).data,e),$update:(e,t)=>this.upsert([{idObj:r,delta:e,opts:t}]).then((e=>!0)),$delete:async()=>this.delete(r),$cloneMultiSync:e=>this.sync(e,t)}),i=this.getIdObj(n);return s(n,i)}))),e(s,i)}},handles:n}}},886:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.authRequest=t.getAuthHandler=void 0;const r=n(316),s=n(653);t.getAuthHandler=({authData:e,socket:n,onReload:o})=>{if((null==e?void 0:e.pathGuard)&&s.isClientSide){const e=e=>{(null==e?void 0:e.shouldReload)&&(o?o():s.isClientSide&&(console.log("prostgles page reload due to authguard",e),setTimeout((()=>{window.location.reload()}),200)))};n.emit(r.CHANNELS.AUTHGUARD,JSON.stringify(window.location),((t,n)=>{e(n)})),n.removeAllListeners(r.CHANNELS.AUTHGUARD),n.on(r.CHANNELS.AUTHGUARD,(t=>{e(t)}))}const a={loginType:null==e?void 0:e.loginType,login:void 0,preferredLogin:null==e?void 0:e.preferredLogin,loginWithProvider:void 0,signupWithEmailAndPassword:void 0,providers:null==e?void 0:e.providers};if(e){const{providers:n,signupWithEmailAndPassword:s,loginType:o}=e;a.loginWithProvider=(0,r.isEmpty)(n)?void 0:n&&Object.entries(n).reduce(((e,[t,{url:n}])=>(e[t]=()=>{window.location.assign(n)},e)),{}),a.login=o&&(async e=>(0,t.authRequest)(i("/login"),e)),a.signupWithEmailAndPassword=s&&(e=>(0,t.authRequest)(i(s.url),e))}return(null==e?void 0:e.user)?{isLoggedin:!0,user:e.user,logout:async()=>(0,t.authRequest)(i("/logout"),{},"POST"),...a}:{isLoggedin:!1,user:void 0,...a}};const i=e=>{const{search:t}=window.location;return e+t};t.authRequest=async(e,t,n)=>{const r=await fetch(e,{method:null!=n?n:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},..."GET"!==n&&{body:JSON.stringify(t)}});if(!r.ok){const e=await r.json().catch((()=>r.text())).catch((()=>r.statusText));return"string"==typeof e?{success:!1,code:"something-went-wrong",message:e}:e}const s=await r.json().catch((async()=>({message:await r.text()}))).catch((()=>({message:r.statusText})));return r.redirected?{...s,success:!0,redirect_url:r.url}:s}},930:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getDBO=void 0;const r=n(316),s=n(653),i=n(333),o=r.CHANNELS._preffix;t.getDBO=({schema:e,tableSchema:t,onDebug:n,syncedTable:a,syncHandler:c,subscriptionHandler:l,socket:u})=>{const d=(e,t,n,s)=>{if(void 0!==e&&!(0,r.isObject)(e)||void 0!==t&&!(0,r.isObject)(t)||"function"!=typeof n||void 0!==s&&"function"!=typeof s)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},h=["subscribe","subscribeOne"],p={},f=(0,i.quickClone)(e);return(0,r.getObjectEntries)(f).forEach((([e,i])=>{const f=(0,r.getKeys)(i);p[e]={};const y=p[e];f.sort(((e,t)=>h.includes(e)-h.includes(t))).forEach((f=>{if("sync"===f){if(y._syncInfo={...i[f]},a){y.getSync=async(t,r={})=>(await(null==n?void 0:n({type:"table",command:"getSync",tableName:e,data:{filter:t,params:r}})),a.create({name:e,onDebug:n,filter:t,db:p,...r}));const t=async(t={},s={},i)=>{const o=`${e}.${JSON.stringify(t)}.${JSON.stringify((0,r.omitKeys)(s,["handlesOnData"]))}`;return c.syncedTables[o]||(c.syncedTables[o]=await a.create({...s,onDebug:n,name:e,filter:t,db:p,onError:i})),c.syncedTables[o]},i=async(r,s={handlesOnData:!0,select:"*"},i,o)=>{await(null==n?void 0:n({type:"table",command:"sync",tableName:e,data:{basicFilter:r,options:s}})),d(r,s,i,o);const a=await t(r,s,o);return await a.sync(i,s.handlesOnData)},o=async(r,s={handlesOnData:!0},i,o)=>{await(null==n?void 0:n({type:"table",command:"syncOne",tableName:e,data:{basicFilter:r,options:s}})),d(r,s,i,o);const a=await t(r,s,o);return await a.syncOne(r,i,s.handlesOnData)};y.sync=i,y.syncOne=o,y.useSync=(e,t,n)=>(0,s.useSync)(i,e,t,n),y.useSyncOne=(e,t,n)=>(0,s.useSync)(o,e,t,n)}y._sync=async function(t,r,s){return await(null==n?void 0:n({type:"table",command:"_sync",tableName:e,data:{param1:t,param2:r,syncHandles:s}})),c.addSync({tableName:e,command:f,param1:t,param2:r},s)}}else if(h.includes(f)){const t=async function(t={},r={},s,i){return await(null==n?void 0:n({type:"table",command:f,tableName:e,data:{param1:t,param2:r,onChange:s,onError:i}})),d(t,r,s,i),l.addSub(p,{tableName:e,command:f,param1:t,param2:r},s,i)};y[f]=t;const r="subscribeOne",i="subscribe"===f?"useSubscribe":"subscribeOne"===f?"useSubscribeOne":void 0;i&&(y[i]=(e,n,i)=>(0,s.useSubscribe)(t,f===r,e,n,i)),f!==r&&h.includes(r)||(y[r]=async function(t,r,s,i){return await(null==n?void 0:n({type:"table",command:"getSync",tableName:e,data:{param1:t,param2:r,onChange:s,onError:i}})),d(t,r,s,i),l.addSub(p,{tableName:e,command:f,param1:t,param2:r},(e=>{s(e[0])}),i)})}else{const r=async function(r,s,i){var a;if("getColumns"===f&&!r&&!s&&!i){const n=null===(a=null==t?void 0:t.find((t=>t.name===e)))||void 0===a?void 0:a.columns;if(n)return n}return await(null==n?void 0:n({type:"table",command:f,tableName:e,data:{param1:r,param2:s,param3:i}})),new Promise(((t,n)=>{u.emit(o,{tableName:e,command:f,param1:r,param2:s,param3:i},((e,r)=>{e?n(e):t(r)}))}))};y[f]=r;const i="findOne"===f?"useFindOne":"find"===f?"useFind":"count"===f?"useCount":"size"===f?"useSize":void 0;i&&(y[i]=(e,t,n)=>(0,s.useFetch)(r,[e,t],n))}}))})),{dbo:p}}},30:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getMethods=void 0;const r=n(316);t.getMethods=({onDebug:e,methods:t,socket:n})=>{let s={};return JSON.parse(JSON.stringify(t)).map((t=>{const i="string"==typeof t,o=i?t:t.name,a=async function(...t){return await(null==e?void 0:e({type:"method",command:o,data:{params:t}})),new Promise(((e,s)=>{n.emit(r.CHANNELS.METHOD,{method:o,params:t},((t,n)=>{t?s(t):e(n)}))}))};s[o]=i?a:{...t,run:a}})),s=Object.freeze(s),{methodsObj:s}}},382:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getSqlHandler=void 0;const r=n(316);t.getSqlHandler=({socket:e})=>{let t;const n={};return{sql:function(s,i,o){return new Promise(((a,c)=>{e.emit(r.CHANNELS.SQL,{query:s,params:i,options:o},((r,s)=>{if(r)return c(r);if("stream"===(null==o?void 0:o.returnType)){const{channel:t,unsubChannel:n}=s,r=r=>new Promise(((s,i)=>{e.on(t,r),e.emit(t,{},((r,o)=>{o?(i(o),e.removeAllListeners(t)):s({pid:r,run:(n,r)=>new Promise(((s,i)=>{e.emit(t,{query:n,params:r},((e,t)=>{t?i(t):s(e)}))})),stop:t=>new Promise(((r,s)=>{e.emit(n,{terminate:t},((e,t)=>{t?s(t):r(e)}))}))})}))}));return a({channel:t,unsubChannel:n,start:r})}if(o&&"noticeSubscription"===o.returnType&&s&&Object.keys(s).sort().join()===["socketChannel","socketUnsubChannel"].sort().join()&&!Object.values(s).find((e=>"string"!=typeof e))){const n=s,r=r=>(((e,n,r)=>{null!=t||(t={config:n,listeners:[]}),t.listeners.length||(r.removeAllListeners(n.socketChannel),r.on(n.socketChannel,(e=>{t&&t.listeners.length?t.listeners.map((t=>{t(e)})):r.emit(n.socketUnsubChannel,{})}))),t.listeners.push(e)})(r,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,{}))})(r,e)}),i={...n,addListener:r};a(i)}else if(o&&o.returnType&&"statement"===o.returnType||!s||Object.keys(s).sort().join()!==["socketChannel","socketUnsubChannel","notifChannel"].sort().join()||Object.values(s).find((e=>"string"!=typeof e)))a(s);else{const t=s,r=r=>(((e,t,r)=>{var s;n[t.notifChannel]?null===(s=n[t.notifChannel])||void 0===s||s.listeners.push(e):(n[t.notifChannel]={config:t,listeners:[e]},r.removeAllListeners(t.socketChannel),r.on(t.socketChannel,(e=>{var s,i;(null===(s=n[t.notifChannel])||void 0===s?void 0:s.listeners.length)?n[t.notifChannel].listeners.map((t=>{t(e)})):r.emit(null===(i=n[t.notifChannel])||void 0===i?void 0:i.config.socketUnsubChannel,{})})))})(r,t,e),{...s,removeListener:()=>((e,t,r)=>{const s=n[t.notifChannel];s&&(s.listeners=s.listeners.filter((t=>t!==e)),!s.listeners.length&&s.config.socketUnsubChannel&&r&&(r.emit(s.config.socketUnsubChannel,{}),delete n[t.notifChannel]))})(r,t,e)}),i={...s,addListener:r};a(i)}}))}))}}}},395:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getSubscriptionHandler=void 0;const r=n(316),s=n(653),i=n(515),o=r.CHANNELS._preffix;t.getSubscriptionHandler=e=>{const{socket:t,onDebug:n}=e,a={},c=e=>new Promise(((n,r)=>{t.emit(e,{},((e,t)=>{e?(console.error(e),r(e)):n(t)}))}));function l(e,r,i){return(0,s.debug)("_unsubscribe",{channelName:e,handler:i}),new Promise((s=>{const o=a[e];o?(o.handlers=o.handlers.filter((e=>e!==i)),null==n||n({type:"table",command:"unsubscribe",tableName:o.tableName,unsubChannel:r,handlers:o.handlers}),o.handlers.length||(c(r),t.removeListener(e,o.onCall),delete a[e]),s(!0)):s(!0)}))}function u({tableName:e,command:n,param1:r,param2:s}){return new Promise(((i,a)=>{t.emit(o,{tableName:e,command:n,param1:r,param2:s},((e,t)=>{e?(console.error(e),a(e)):t&&i(t)}))}))}const d=new i.FunctionQueuer((async function(e,{tableName:n,command:s,param1:i,param2:o},d,h){const p=(t,r)=>{let s={unsubscribe:function(){return l(t,r,d)},filter:{...i}};return e[n].update&&(s={...s,update:function(t,r){return e[n].update(i,t,r)}}),e[n].delete&&(s={...s,delete:function(t){return e[n].delete(i,t)}}),Object.freeze(s)},f=Object.entries(a).find((([e,t])=>t.tableName===n&&t.command===s&&(0,r.isEqual)(t.param1||{},i||{})&&(0,r.isEqual)(t.param2||{},o||{})));if(f){const e=f[0];return f[1].handlers.push(d),f[1].errorHandlers.push(h),setTimeout((()=>{var t,n;(null===(t=a[e])||void 0===t?void 0:t.lastData)&&d(null===(n=a[e])||void 0===n?void 0:n.lastData)}),10),p(e,f[1].unsubChannel)}const{channelName:y,channelNameReady:m,channelNameUnsubscribe:g}=await u({tableName:n,command:s,param1:i,param2:o}),b=function(e){const t=a[y];t?e.data?(t.lastData=e.data,t.handlers.forEach((t=>{t(e.data)}))):e.err?t.errorHandlers.forEach((t=>{null==t||t(e.err)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",e):console.warn("Orphaned subscription: ",y)},_=h||function(e){console.error(`Uncaught error within running subscription \n ${y}`,e)};return t.on(y,b),a[y]={lastData:void 0,tableName:n,command:s,param1:i,param2:o,onCall:b,unsubChannel:g,handlers:[d],errorHandlers:[_],reAttach:async()=>{await c(g).catch(console.error),await u({tableName:n,command:s,param1:i,param2:o}),t.emit(m,{now:Date.now()})}},t.emit(m,{now:Date.now()}),p(y,g)}),(([e,{tableName:t}])=>t));return{addSub:async(e,t,n,r)=>d.run([e,t,n,r]),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 Object.values(a))try{await e.reAttach()}catch(t){console.error("There was an issue reconnecting old subscriptions",t,e),Object.values(e.errorHandlers).forEach((e=>null==e?void 0:e(t)))}await(null==n?void 0:n({type:"subscriptions",command:"reAttachAll.end",subscriptions:a}))}}}},609:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getSyncHandler=void 0;const r=n(316),s=n(515),i=n(653),o=r.CHANNELS._preffix;t.getSyncHandler=({socket:e,onDebug:t})=>{let n={},a={};function c({tableName:t,command:n,param1:r,param2:s},i){return new Promise(((a,c)=>{e.emit(o,{tableName:t,command:n,param1:r,param2:s},((t,n)=>{if(t)console.error(t),c(t);else if(n){const{id_fields:t,synced_field:r,channelName:s}=n;e.emit(s,{onSyncRequest:i({})},(e=>{console.log(e)})),a({id_fields:t,synced_field:r,channelName:s})}}))}))}const l=new s.FunctionQueuer((async function({tableName:t,command:n,param1:s,param2:o},l){const{onSyncRequest:u}=l;function d(t){return Object.freeze({unsync:function(){!function(t,n){(0,i.debug)("_unsync",{channelName:t,triggers:n}),new Promise(((r,s)=>{a[t]&&(a[t].triggers=a[t].triggers.filter((e=>e.onPullRequest!==n.onPullRequest&&e.onSyncRequest!==n.onSyncRequest&&e.onUpdates!==n.onUpdates)),a[t].triggers.length||(e.emit(t+"unsync",{},((e,t)=>{e?s(e):r(t)})),e.removeListener(t,a[t].onCall),delete a[t]))}))}(t,l)},syncData:function(n,r,s){e.emit(t,{onSyncRequest:{...u({}),data:n,deleted:r}},s?e=>{s(e)}:null)}})}const h=Object.keys(a).find((e=>{const i=a[e];return i&&i.tableName===t&&i.command===n&&(0,r.isEqual)(i.param1,s)&&(0,r.isEqual)(i.param2,o)}));if(h)return a[h].triggers.push(l),d(h);{const r=await c({tableName:t,command:n,param1:s,param2:o},u),{channelName:i}=r,h=function(e,t){e&&a[i]&&a[i].triggers.map((({onUpdates:n,onSyncRequest:r,onPullRequest:s})=>{e.data?Promise.resolve(n(e)).then((()=>{t({ok:!0})})).catch((e=>{t({err:e})})):e.onSyncRequest?Promise.resolve(r(e.onSyncRequest)).then((e=>t({onSyncRequest:e}))).catch((e=>{t({err:e})})):e.onPullRequest?Promise.resolve(s(e.onPullRequest)).then((e=>{t({data:e})})).catch((e=>{t({err:e})})):console.log("unexpected response")}))};return a[i]={tableName:t,command:n,param1:s,param2:o,triggers:[l],syncInfo:r,onCall:h},e.on(i,h),d(i)}}),(([{tableName:e}])=>e));return{destroySyncs:async()=>{(0,i.debug)("destroySyncs",{syncedTables:n}),a={},Object.values(n).map((e=>{e&&e.destroy&&e.destroy()})),n={}},syncedTables:n,addSync:async function(e,t){return l.run([e,t])},reAttachAll:async()=>{let t=0;Object.entries(a).forEach((async([n,r])=>{const s=r.triggers[0];if(s)try{await c(r,s.onSyncRequest),e.on(n,r.onCall),t++}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}})),t&&console.log("reAttached",t," syncs",a)}}}},653:function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var s=Object.getOwnPropertyDescriptor(t,n);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,s)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),s=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.prostgles=t.asName=t.debug=t.isClientSide=void 0;const i=n(316);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return i.asName}});const o=n(886),a=n(930),c=n(30),l=n(382),u=n(395),d=n(609),h="DEBUG_SYNCEDTABLE";t.isClientSide="undefined"!=typeof window,t.debug=function(...e){t.isClientSide&&window[h]&&window[h](...e)},s(n(512),t),s(n(641),t),t.prostgles=function(e,n){const{socket:r,onReady:s,onDisconnect:h,onReconnect:p,onSchemaChange:f,onReload:y,onDebug:m}=e;let g;(0,t.debug)("prostgles",{initOpts:e}),f&&(r.removeAllListeners(i.CHANNELS.SCHEMA_CHANGED),r.on(i.CHANNELS.SCHEMA_CHANGED,f));const b=(0,u.getSubscriptionHandler)(e),_=(0,d.getSyncHandler)(e),v=(0,l.getSqlHandler)(e);let O;return new Promise(((e,t)=>{r.removeAllListeners("connect_error"),r.on("connect_error",(e=>{t(e)})),r.removeAllListeners(i.CHANNELS.CONNECTION),r.on(i.CHANNELS.CONNECTION,(e=>(t(e),"ok"))),h&&r.on("disconnect",(()=>{O="disconnected",h()})),p&&r.on("connect",(()=>{"disconnected"===O&&(O="reconnected")})),r.on(i.CHANNELS.SCHEMA,(async l=>{await(null==m?void 0:m({type:"schemaChanged",data:l,state:O}));const{joinTables:u=[],...d}=l,{schema:h,methods:f,tableSchema:S,auth:w,rawSQL:k,err:T}=d;if((null==g?void 0:g.clientSchema)&&(0,i.isEqual)(g.clientSchema,d)||_.destroySyncs().catch((e=>console.error("Error while destroying syncs",e))),T&&console.error("Error on schema change:",T),"connected"!==O&&"reconnected"!==O||!p)g={origin:"onReady",date:new Date,clientSchema:d};else{if(p(r,T),T)return;g={origin:"onReconnect",date:new Date,clientSchema:d}}if(T)return void t(T);const E="reconnected"===O;O="connected";const C=(0,o.getAuthHandler)({authData:w,socket:r,onReload:y}),{methodsObj:j}=(0,c.getMethods)({onDebug:m,methods:f,socket:r}),{dbo:P}=(0,a.getDBO)({schema:h,onDebug:m,syncedTable:n,syncHandler:_,subscriptionHandler:b,socket:r,tableSchema:S});k&&(P.sql=v.sql),b.reAttachAll(),_.reAttachAll(),u.flat().map((e=>{var t,n,r,s;null!==(t=P.innerJoin)&&void 0!==t||(P.innerJoin={}),null!==(n=P.leftJoin)&&void 0!==n||(P.leftJoin={}),null!==(r=P.innerJoinOne)&&void 0!==r||(P.innerJoinOne={}),null!==(s=P.leftJoinOne)&&void 0!==s||(P.leftJoinOne={});const o=(0,i.getJoinHandlers)(e);P.leftJoin[e]=o.leftJoin,P.innerJoin[e]=o.innerJoin,P.leftJoinOne[e]=o.leftJoinOne,P.innerJoinOne[e]=o.innerJoinOne})),(async()=>{try{const e={dbo:P,methods:j,tableSchema:S,auth:C,isReconnect:E};await(null==m?void 0:m({type:"onReady.call",data:e,state:O})),await s(P,j,S,C,E)}catch(e){console.error("Prostgles: Error within onReady: \n",e),t(e)}e(P)})()}))}))}},512:(e,t,n)=>{"use strict";var r;Object.defineProperty(t,"__esModule",{value:!0}),t.__prglReactInstalled=t.useFetch=t.useSync=t.useSubscribe=t.usePromise=t.useIsMounted=t.useEffectAsync=t.useAsyncEffectQueue=t.useEffectDeep=t.useMemoDeep=t.useDeepCompareMemoize=t.getIO=t.getReact=void 0;const s=n(316);let i;const o=(...e)=>{throw"Must install react"},a=(...e)=>{throw"Must install react"};t.getReact=e=>{try{null!=i||(i=n(540))}catch(e){}if(e&&!i)throw new Error("Must install react");return i},(0,t.getReact)();const{useEffect:c=o,useCallback:l=o,useRef:u,useState:d=a}=null!==(r=i)&&void 0!==r?r:{};t.getIO=(e=!1)=>{try{return n(7)}catch(e){}if(e)throw new Error("Must install socket.io-client");return{}},t.useDeepCompareMemoize=e=>{const t=u();return(0,s.isEqual)(e,t.current)||(t.current=e),t.current},t.useMemoDeep=(e,n)=>i.useMemo(e,null==n?void 0:n.map(t.useDeepCompareMemoize)),t.useEffectDeep=(e,n)=>{c(e,null==n?void 0:n.map(t.useDeepCompareMemoize))},t.useAsyncEffectQueue=(e,n)=>{const r=u(),s=u(),i=async()=>{var e;if("resolved"===(null===(e=s.current)||void 0===e?void 0:e.state)){const{cleanup:e,effect:t}=s.current;s.current={state:"cleaning",effect:t},await e().catch(console.error),s.current=void 0}if(r.current&&!s.current){const e=r.current,{effect:t}=e;s.current={state:"resolving",effect:t};const n=await t().then((e=>async()=>{await(null==e?void 0:e())})).catch((e=>(console.error(e),async()=>{})));s.current={state:"resolved",effect:t,cleanup:n},e!==r.current&&i()}};(0,t.useEffectDeep)((()=>(r.current={effect:e,deps:n},i(),()=>{r.current=void 0,i()})),n)},t.useEffectAsync=(e,n)=>{const r=u({cleanup:void 0,effect:e,cleanupEffect:void 0});r.current.effect=e,(0,t.useEffectDeep)((()=>(e().then((t=>{"function"==typeof t&&(r.current.cleanup=t,r.current.cleanupEffect===e&&t())})),()=>{var t,n;r.current.cleanupEffect=e,null===(n=(t=r.current).cleanup)||void 0===n||n.call(t)})),n)},t.useIsMounted=()=>{const e=u(!0),t=l((()=>e.current),[]);return c((()=>(e.current=!0,()=>{e.current=!1})),[]),t},t.usePromise=(e,n=[])=>{const r=e=>{try{return"function"==typeof e||e instanceof Promise}catch(e){console.error(e)}return!1},i=e=>{try{return(0,s.isObject)(e)&&!r(e)}catch(e){console.error(e)}return!1},o=async e=>{const t={},n=(0,s.getKeys)(e);for await(const r of n){const n=e[r];try{t[r]="function"==typeof n?await n():await n}catch(e){console.error(e)}}return t},[a,c]=d(i(e)?{}:void 0),l=(0,t.useIsMounted)();return(0,t.useAsyncEffectQueue)((async()=>{let t;try{if(i(e))t=await o(e);else{const n=await e();t=i(n)?await o(n):r(n)?await n():n}}catch(e){console.error(e)}l()&&c(t)}),n),a},t.useSubscribe=(e,n,r,i,o)=>{const{skip:a}=null!=o?o:{},c={data:void 0,error:void 0,isLoading:!0},[{data:l,isLoading:h,error:p},f]=d(c),y={data:l,isLoading:h,error:p},m=u(y);m.current=y;const g=(0,t.useIsMounted)();return(0,t.useAsyncEffectQueue)((async()=>{if(!g()||a)return;(0,s.isEqual)(m.current,c)||f(c);const t=e=>{g()&&f({data:void 0,error:e,isLoading:!1})};try{const s=await e(r,i,(e=>{g()&&f({data:n?e[0]:e,error:void 0,isLoading:!1})}),t);return()=>{s.unsubscribe()}}catch(e){t(e)}}),[e,r,i,a]),{data:l,error:p,isLoading:h}},t.useSync=(e,n,r,s)=>{const{skip:i}=null!=s?s:{},[{data:o,error:a,isLoading:c},l]=d({data:void 0,error:void 0,isLoading:!0}),u=(0,t.useIsMounted)();return(0,t.useAsyncEffectQueue)((async()=>{if(!u()||i)return;const t=e=>{u()&&l({data:void 0,error:e,isLoading:!1})};try{return(await e(n,r,(e=>{u()&&l({data:e,error:void 0,isLoading:!1})}),t)).$unsync}catch(e){t(e)}}),[e,n,r,i]),{data:o,error:a,isLoading:c}},t.useFetch=(e,n=[],r)=>{const{skip:s,deps:i=[]}=null!=r?r:{},o={data:void 0,error:void 0,isLoading:!0},[{data:a,error:c,isLoading:l},u]=d(o),h=(0,t.useIsMounted)();return(0,t.useAsyncEffectQueue)((async()=>{if(h()&&!s){u(o);try{const t=await e(...n);if(!h())return;u({data:t,error:void 0,isLoading:!1})}catch(e){if(!h())return;u({data:void 0,error:e,isLoading:!1})}}}),[...n,...i]),{data:a,error:c,isLoading:l}},t.__prglReactInstalled=()=>Boolean(i&&u)},641:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useProstglesClient=void 0;const r=n(316),s=n(333),i=n(653),o=n(512);t.useProstglesClient=({skip:e,socketOptions:t,...n}={})=>{const{useRef:a,useState:c}=(0,o.getReact)(!0),[l,u]=c({isLoading:!0}),d=(0,o.useIsMounted)(),h=a();return(0,o.useAsyncEffectQueue)((async()=>{var a;if(e)return;null===(a=h.current)||void 0===a||a.disconnect();const c=(0,o.getIO)(),l="string"==typeof t?{path:t}:t,p={reconnectionDelay:1e3,reconnection:!0,...(0,r.omitKeys)(null!=l?l:{},["uri"])},f="string"==typeof(null==l?void 0:l.uri)?c(l.uri,p):c(p);return h.current=f,await(0,i.prostgles)({socket:f,...n,onReady:(...e)=>{var t,r;const[s,i,o,a,c]=e,l={dbo:s,methods:i,tableSchema:o,auth:a,isReconnect:c,socket:f};d()?(null===(r=n.onDebug)||void 0===r||r.call(n,{type:"onReady",data:l}),u({...l,isLoading:!1})):null===(t=n.onDebug)||void 0===t||t.call(n,{type:"onReady.notMounted",data:l})}},s.SyncedTable).catch((e=>{d()&&u({isLoading:!1,error:e,hasError:!0})})),()=>{f.disconnect()}}),[n,t,e]),l}},833:(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 r=0,s=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))})),t.splice(s,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")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("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&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$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:r}=e.exports;r.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,s,i,o=null;function a(...e){if(!a.enabled)return;const r=a,s=Number(new Date),i=s-(n||s);r.diff=i,r.prev=n,r.curr=s,n=s,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,s)=>{if("%%"===n)return"%";o++;const i=t.formatters[s];if("function"==typeof i){const t=e[o];n=i.call(r,t),e.splice(o,1),o--}return n})),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=r,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==o?o:(s!==t.namespaces&&(s=t.namespaces,i=t.enabled(e)),i),set:e=>{o=e}}),"function"==typeof t.init&&t.init(a),a}function r(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}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.map(s),...t.skips.map(s).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(n=0;n<s;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=n(585),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}},585:e=>{var t=1e3,n=60*t,r=60*n,s=24*r,i=7*s;function o(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"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*s;case"hours":case"hour":case"hrs":case"hr":case"h":return a*r;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))>=s?o(c,l,s,"day"):l>=r?o(c,l,r,"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>=s?Math.round(e/s)+"d":i>=r?Math.round(e/r)+"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))}},316:function(e){var t;this||window,t=()=>(()=>{"use strict";var e={994:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONSchemaObject=t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=void 0,t.getJSONBSchemaAsJSONSchema=function(e,n,r){return(0,t.getJSONSchemaObject)(r,{id:`${e}.${n}`})};const r=n(472);t.PrimitiveTypes=["boolean","number","integer","string","Date","time","timestamp","any"],t.PrimitiveArrayTypes=t.PrimitiveTypes.map((e=>`${e}[]`)),t.DATA_TYPES=[...t.PrimitiveTypes,...t.PrimitiveArrayTypes];const s=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||"Lookup"===t?void 0:"string",isArray:e.endsWith("[]")}};t.getJSONSchemaObject=(e,n)=>{const{type:i,arrayOf:o,arrayOfType:a,description:c,nullable:l,oneOf:u,oneOfType:d,title:h,record:p,...f}="string"==typeof e?{type:e}:e;let y={};const m={...(f.enum||f.allowedValues?.length&&("string"!=typeof i||!i.endsWith("[]")))&&{enum:f.allowedValues?.slice(0)??f.enum.slice(0)},...!!c&&{description:c},...!!h&&{title:h}};if(f.enum?.length){const e=typeof f.enum[0];m.type="number"===e?"number":"boolean"===e?"boolean":"string"}if("string"==typeof i||o||a){if(i&&"string"!=typeof i)throw"Not expected";y=o||a||i?.endsWith("[]")?{type:"array",items:o||a?(0,t.getJSONSchemaObject)(o||{type:a}):i?.startsWith("any")?{type:void 0}:{type:s(i)?.type,...f.allowedValues&&{enum:f.allowedValues.slice(0)}}}:{type:s(i)?.type}}else(0,r.isObject)(i)?y={type:"object",required:(0,r.getKeys)(i).filter((e=>{const t=i[e];return"string"==typeof t||!t.optional})),properties:(0,r.getObjectEntries)(i).reduce(((e,[n,r])=>({...e,[n]:(0,t.getJSONSchemaObject)(r)})),{})}:u||d?y={oneOf:(u||d.map((e=>({type:e})))).map((e=>(0,t.getJSONSchemaObject)(e)))}:p&&(y={type:"object",...p.values&&!p.keysEnum&&{additionalProperties:(0,t.getJSONSchemaObject)(p.values)},...p.keysEnum&&{properties:p.keysEnum.reduce(((e,n)=>({...e,[n]:p.values?(0,t.getJSONSchemaObject)(p.values):{type:{}}})),{})}});if(l){const e={type:"null"};y.oneOf?y.oneOf.push(e):y.enum&&!y.enum.includes(null)?y.enum.push(null):y={oneOf:[y,e]}}return{...n?{$id:n?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...m,...y}}},897:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.assertJSONBObjectAgainstSchema=t.validateJSONBObjectAgainstSchema=t.getJSONBObjectSchemaValidationError=t.getFieldTypeObj=void 0;const r=n(472);t.getFieldTypeObj=e=>"string"==typeof e?{type:e}:e;const s={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,Date:e=>"string"==typeof e,Lookup:()=>{throw new Error("Lookup type is not supported for validation")}},i=(0,r.getKeys)(s),o=(e,n,c=[])=>{const l=`${c.join(".")} is of invalid type. Expecting ${a(n).replaceAll("\n","")}`,u=(0,t.getFieldTypeObj)(n),{type:d,allowedValues:h,nullable:p,optional:f}=u;if(p&&null===e)return;if(f&&void 0===e)return;if(h)throw new Error("Allowed values are not supported for validation");if(d){if((0,r.isObject)(d)){if(!(0,r.isObject)(e))return l;for(const[t,n]of(0,r.getObjectEntries)(d)){const r=o(e[t],n,[...c,t]);if(void 0!==r)return r}return}const{validator:t}=(e=>{const t=(e=>{if("string"==typeof e&&e.endsWith("[]")){const t=e.slice(0,-2);if(!i.includes(t))throw new Error(`Unknown array field type ${e}`);return t}})(e);if(t){const e=s[t];return{isArray:!0,validator:t=>Array.isArray(t)&&t.every((t=>e(t)))}}const n=s[e];if(!n)throw new Error(`Unknown field type ${e}`);return{isArray:!1,validator:n}})(d);return t(e)?void 0:l}if(u.enum){const t=[];return u.nullable&&t.push(null),u.optional&&t.push(void 0),u.enum.includes(e)?void 0:l}const y=u.arrayOf??(u.arrayOfType?{type:u.arrayOfType}:void 0);if(y){if(!Array.isArray(e))return l+" to be an array";const t=e.map(((e,t)=>o(e,y,[...c,`${t}`]))).filter(r.isDefined)[0];return void 0!==t?`${l}. Error at index ${c.length>0?c.join(".")+".":""}\n\n${t}`:void 0}const m=u.oneOf??u.oneOfType?.map((e=>({type:e})));if(m){if(!m.length)return l+"to not be empty";let t;if(m.find((n=>{const r=o(e,n,c);return t??(t=r),void 0===r})))return;return l}if(!u.record)return`Could not validate field type. Some logic might be missing: ${JSON.stringify(u)}`;{const{keysEnum:t,partial:n,values:s}=u.record;if(!(0,r.isObject)(e))return l+"object";if(n&&(0,r.isEmpty)(e))return;const i=(0,r.getKeys)(e),a=n?void 0:t?.find((e=>!i.includes(e)));if(void 0!==a)return`${l} to have key ${a}`;const d=t&&i.filter((e=>!t.includes(e)));if(d?.length)return`${l} has extra keys: ${d}`;if(s)for(const[t,n]of Object.entries(e)){const e=o(n,s,[...c,t]);if(void 0!==e)return`${e}`}}},a=e=>{const n=(0,t.getFieldTypeObj)(e),{type:s,nullable:i,optional:o,record:c}=n,l=n.oneOf??n.oneOfType?.map((e=>({type:e}))),u=[];if(i&&u.push("null"),o&&u.push("undefined"),"string"==typeof s)u.push(s);else if(s&&(0,r.isObject)(s)){const e=[];Object.entries(s).forEach((([t,n])=>{e.push(`${t}: ${a(n)}`)})),u.push(`{ ${e.join("; ")} }`)}if(n.enum?.forEach((e=>{null===e?u.push("null"):void 0===e?u.push("undefined"):"string"==typeof e?u.push(JSON.stringify(e)):u.push(e)})),l?.forEach((e=>{const t=a(e);u.push(t)})),c){const{keysEnum:e,partial:t,values:n}=c,r=t?"?":"",s=n?a(n):"any";e?u.push(`{ [${e.join(" | ")}]${r}: ${s} }`):u.push(`{ [key: string]${r}: ${s} }`)}return u.join(" | ")};t.getJSONBObjectSchemaValidationError=(e,t,n,s=!1)=>{if(void 0===t&&!s)return{error:`Expecting ${n} to be defined`};if(!(0,r.isObject)(t))return{error:`Expecting ${n} to be an object`};for(const[n,r]of Object.entries(e)){const e=o(t[n],r,[n]);if(e)return{error:e}}return{data:t}},t.validateJSONBObjectAgainstSchema=(e,n,r,s=!1)=>{const{error:i}=(0,t.getJSONBObjectSchemaValidationError)(e,n,r,s);return void 0===i},t.assertJSONBObjectAgainstSchema=(e,n,r,s=!1)=>{const{error:i}=(0,t.getJSONBObjectSchemaValidationError)(e,n,r,s);if(i)throw new Error(i)}},394:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBTSTypes=void 0,t.getJSONBSchemaTSTypes=function(e,n,r="",s){return(0,t.getJSONBTSTypes)(s,{...e,nullable:n.nullable},void 0,r)};const r=n(806),s=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,s.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:{optional:!0,type:{displayColumns:{type:"string[]",optional:!0}}},showInRowCard:{optional:!0,record:{}}}})}`;const s="schema"===n.type;let i=s?"table"===n.object?"string":'{ "table": string; "column": string; }':"";if(!s){const t=e.find((e=>e.name===n.table))?.columns;i=n.isFullRow?t?`{ ${t.map((e=>`${JSON.stringify(e.name)}: ${e.is_nullable?"null | ":""} ${(0,r.postgresToTsType)(e.udt_name)}; `)).join(" ")} }`:"any":(0,r.postgresToTsType)(t?.find((e=>e.name===n.column))?.udt_name??"text")}return`${u.nullable?"null | ":""}${i}${n.isArray?"[]":""}`}if("string"==typeof u.type){if(u.type.toLowerCase().includes("lookup"))throw new Error("getJSONBTSTypes: Lookup type not handled correctly");const e=u.type.replace("integer","number").replace("time","string").replace("timestamp","string").replace("Date","string");return u.allowedValues&&u.type.endsWith("[]")?d+` (${u.allowedValues.map((e=>JSON.stringify(e))).join(" | ")})[]`:d+e}if((0,r.isObject)(u.type)){const n=e=>e.trim().endsWith(";")?e:e.trim()+";",{type:i}=u,c=a?" ":" ";let h=` {${c}`+(0,r.getObjectEntries)(i).map((([r,i])=>{const a=(0,s.getFieldTypeObj)(i),u=o(r)?r:JSON.stringify(r);return`${c}${u}${a.optional?"?":""}: `+n((0,t.getJSONBTSTypes)(e,a,!0,void 0,l+1))})).join(" ")+`${c}}`;return a||(h=n(h)),a&&(h=h.split("\n").join("")),d+h}if(u.enum)return d+u.enum.map((e=>i(e))).join(" | ");if(u.oneOf||u.oneOfType){const n=u.oneOf||u.oneOfType.map((e=>({type:e})));return(u.nullable?`\n${c} | null`:"")+n.map((n=>`\n${c} | `+(0,t.getJSONBTSTypes)(e,n,!0,void 0,l+1))).join("")}if(u.arrayOf||u.arrayOfType){const n=u.arrayOf||{type:u.arrayOfType};return`${u.nullable?"null | ":""} ( ${(0,t.getJSONBTSTypes)(e,n,!0,void 0,l+1)} )[]`}if(u.record){const{keysEnum:n,values:r,partial:s}=u.record,o=e=>s?`Partial<Record<${e}>>`:`Record<${e}>`;return`${u.nullable?"null |":""} ${o(`${n?.map((e=>i(e))).join(" | ")??"string"}, ${r?(0,t.getJSONBTSTypes)(e,r,!0,void 0,l+1):"any"}`)}`}throw"Unexpected getSchemaTSTyp