prostgles-client 4.0.26 → 4.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SyncedTable.d.ts +2 -2
- package/dist/SyncedTable.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.no-sync.js +1 -1
- package/lib/SyncedTable.ts +6 -6
- package/package.json +2 -2
package/dist/SyncedTable.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export type ItemUpdated = ItemUpdate & {
|
|
|
47
47
|
status: "inserted" | "updated" | "deleted" | "unchanged";
|
|
48
48
|
from_server: boolean;
|
|
49
49
|
};
|
|
50
|
-
export type CloneSync<T extends AnyObject, Full extends boolean> = (onChange: SingleChangeListener<T>, onError?: (error: any) => void) => SingleSyncHandles<T, Full>;
|
|
50
|
+
export type CloneSync<T extends AnyObject, Full extends boolean> = (onChange: SingleChangeListener<T, Full>, onError?: (error: any) => void) => SingleSyncHandles<T, Full>;
|
|
51
51
|
export type CloneMultiSync<T extends AnyObject> = (onChange: MultiChangeListener<T>, onError?: (error: any) => void) => MultiSyncHandles<T>;
|
|
52
52
|
type $UpdateOpts = {
|
|
53
53
|
deepMerge: boolean;
|
|
@@ -69,7 +69,7 @@ export type SingleSyncHandles<T extends AnyObject = AnyObject, Full extends bool
|
|
|
69
69
|
$cloneSync: CloneSync<T, Full>;
|
|
70
70
|
$cloneMultiSync: CloneMultiSync<T>;
|
|
71
71
|
};
|
|
72
|
-
export type SyncDataItem<T extends AnyObject = AnyObject, Full extends boolean = false> = T & (Full extends true ? SingleSyncHandles<T,
|
|
72
|
+
export type SyncDataItem<T extends AnyObject = AnyObject, Full extends boolean = false> = T & (Full extends true ? SingleSyncHandles<T, Full> : Partial<SingleSyncHandles<T, Full>>);
|
|
73
73
|
export type MultiSyncHandles<T extends AnyObject> = {
|
|
74
74
|
$unsync: () => void;
|
|
75
75
|
$upsert: (newData: T[]) => any;
|
|
@@ -1 +1 @@
|
|
|
1
|
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OAEG;IACH,QAAQ,6CAwCP;IAED;;;OAGG;IACH,QAAQ,+CAA+C,eAAe;;QAarE;CACF;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,OAAO,KAAA,EAAE,OAAO,KAAA,OAkBjD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAevC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!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 i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this||window,(()=>(()=>{var e={133:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.quickClone=t.SyncedTable=t.debug=void 0;const i=n(792),s="DEBUG_SYNCEDTABLE",r="undefined"!=typeof window;t.debug=function(...e){r&&window[s]&&window[s](...e)};const o={array:"array",localStorage:"localStorage",object:"object"};class a{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:a,onDebug:d,db:u,skipFirstTrigger:h=!1,select:p="*",storageType:m="object",patchText:f=!1,patchJSON:g=!1,onError:y}){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)),r=[],o=[];if(this.columns&&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:l,initial:c}={...e};let d;c&&(t.map((e=>{!n.includes(e.name)&&e.name in l&&(null!=d||(d={...l}),d[e.name]=(0,i.getTextPatch)(c[e.name],l[e.name]))})),d&&this.wal&&(o.push(d),r.push([this.wal.getIdObj(d),this.wal.getDeltaObj(d)]))),d||s.push(l)})))}}if(r.length)try{await(null===(n=this.tableHandler)||void 0===n?void 0:n.updateBatch(r))}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;let t=[],n=[],i=[];if(e.map((({idObj:e,newItem:s,delta:r})=>{this.singleSubscriptions.filter((t=>this.matchesIdObj(t.idObj,e))).map((async e=>{try{await e.notify(s,r)}catch(e){console.error("SyncedTable failed to notify: ",e)}})),this.matchesFilter(s)&&(t.push(s),n.push(r),i.push(e))})),this.onChange||this.multiSubscriptions.length){let e=[],i=[];if(this.getItems().map((s=>{e.push({...s});const r=t.findIndex((e=>this.matchesIdObj(s,e)));i.push(n[r])})),this.onChange)try{this.onChange(e,i)}catch(e){console.error("SyncedTable failed to notify onChange: ",e)}this.multiSubscriptions.map((async t=>{try{await t.notify(e,i)}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=()=>{this.dbSync&&this.dbSync.unsync&&this.dbSync.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 i=this.getIdObj(e);return this.setItem(i,void 0,!0,!0),!t&&(null===(n=this.tableHandler)||void 0===n?void 0:n.delete)&&await this.tableHandler.delete(i),this._notifySubscribers(),!0},this.checkItemCols=e=>{if(this.columns&&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";let r,o=[],a=[];await Promise.all(e.map((async(e,n)=>{var s;let c={...e.idObj},d={...e.delta};Object.keys(d).map((e=>{void 0===d[e]&&(d[e]=null)})),t||this.checkItemCols({...e.delta,...e.idObj});let u=this.getItem(c),h=u.index,p=u.data;!t&&!(0,i.isEmpty)(d)||(0,i.isEmpty)(p)||(d=this.getDelta(p||{},d)),t||(d[this.synced_field]=Date.now());let m={...p,...d,...c};p&&!t&&(null===(s=e.opts)||void 0===s?void 0:s.deepMerge)&&(m=l({...p,...c},{...d})),r=p?p[this.synced_field]<m[this.synced_field]?"updated":"unchanged":"inserted",this.setItem(m,h);let f={idObj:c,delta:d,oldItem:p,newItem:m,status:r,from_server:t};return t||a.push({initial:p,current:{...m}}),f.delta&&!(0,i.isEmpty)(f.delta)&&o.push(f),!0}))).catch((e=>{console.error("SyncedTable failed upsert: ",e)})),null===(n=this.notifyWal)||void 0===n||n.addData(o.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=c(e);if(this.storageType===o.localStorage){if(!r)throw"Cannot access window object. Choose another storage method (array OR object)";window.localStorage.setItem(this.name,JSON.stringify(t))}else this.storageType===o.array?this.items=t:this.itemsObj=t.reduce(((e,t)=>({...e,[this.getIdStr(t)]:{...t}})),{})},this.getItems=()=>{let e=[];if(this.storageType===o.localStorage){if(!r)throw"Cannot access window object. Choose another storage method (array OR object)";let t=window.localStorage.getItem(this.name);if(t)try{e=JSON.parse(t)}catch(e){console.error(e)}}else e=this.storageType===o.array?this.items.map((e=>({...e}))):Object.values({...this.itemsObj});if(!this.id_fields||!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,i.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 c(e)},this.getBatch=({from_synced:e,to_synced:t,offset:n,limit:i}={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||i)&&(s=s.splice(null!=n?n:0,i||s.length)),s},this.name=e,this.filter=n,this.select=p,this.onChange=s,d&&(this.onDebug=t=>d({...t,type:"sync",tableName:e},this)),!o[m])throw"Invalid storage type. Expecting one of: "+Object.keys(o).join(", ");if(r||m!==o.localStorage||(console.warn("Could not set storageType to localStorage: window object missing\nStorage changed to object"),m="object"),this.storageType=m,this.patchText=f,this.patchJSON=g,!u)throw"db missing";this.db=u;const{id_fields:b,synced_field:O,throttle:S=100,batch_size:v=50}=u[this.name]._syncInfo;if(!b||!O)throw"id_fields/synced_field missing";this.id_fields=b,this.synced_field=O,this.batch_size=v,this.throttle=S,this.skipFirstTrigger=h,this.multiSubscriptions=[],this.singleSubscriptions=[],this.onError=y||function(e){console.error("Sync internal error: ",e)};const _={id_fields:b,synced_field:O,throttle:S};u[this.name]._sync(n,{select:p},{onSyncRequest:e=>{var t;let n={c_lr:void 0,c_fr:void 0,c_count:0},i=this.getBatch(e);return i.length&&(n={c_fr:this.getRowSyncObj(i[0]),c_lr:this.getRowSyncObj(i[i.length-1]),c_count:i.length}),null===(t=this.onDebug)||void 0===t||t.call(this,{command:"onUpdates",data:{syncBatchParams:e,batch:i,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;let 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){let 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 i.WAL({..._,batch_size:v,onSendStart:()=>{r&&(window.onbeforeunload=t)},onSend:async(e,t)=>(await this.updatePatches(t)).length?this.dbSync.syncData(e):[],onSendEnd:()=>{r&&(window.onbeforeunload=null)}}),this.notifyWal=new i.WAL({..._,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}})))}}),a()})),u[this.name].getColumns&&u[this.name].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 a({...e,onReady:()=>{setTimeout((()=>{t(n)}),0)}})}catch(e){n(e)}}))}sync(e,t=!0){const n={$unsync:()=>this.unsubscribe(e),getItems:()=>this.getItems(),$upsert:e=>{if(e){const t=e=>({idObj:this.getIdObj(e),delta:e});Array.isArray(e)?this.upsert(e.map((e=>t(e)))):this.upsert([t(e)])}}},i={_onChange:e,handlesOnData:t,handles:n,notify:(n,i)=>{let s=[...n],r=[...i];return t&&(s=s.map(((n,i)=>{const s=(n,i)=>({...n,...this.makeSingleSyncHandles(i,e),$get:()=>s(this.getItem(i).data,i),$find:e=>s(this.getItem(e).data,e),$update:(e,t)=>this.upsert([{idObj:i,delta:e,opts:t}]).then((e=>!0)),$delete:async()=>this.delete(i),$cloneMultiSync:e=>this.sync(e,t)}),r=this.getIdObj(n);return s(n,r)}))),e(s,r)}};return this.multiSubscriptions.push(i),this.skipFirstTrigger||setTimeout((()=>{let e=this.getItems();i.notify(e,e)}),0),Object.freeze({...n})}makeSingleSyncHandles(e,n){if(!e||!n)throw"syncOne(idObj, onChange) -> MISSING idObj or onChange";const i={$get:()=>this.getItem(e).data,$find:e=>this.getItem(e).data,$unsync:()=>this.unsubscribe(n),$delete:()=>this.delete(e),$update:(n,i)=>{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:i}])},$cloneSync:t=>this.syncOne(e,t),$cloneMultiSync:e=>this.sync(e,!0)};return i}syncOne(e,t,n=!0){const i=this.makeSingleSyncHandles(e,t),s={_onChange:t,idObj:e,handlesOnData:n,handles:i,notify:(e,s)=>{let r={...e};return n&&(r.$get=i.$get,r.$find=i.$find,r.$update=i.$update,r.$delete=i.$delete,r.$unsync=i.$unsync,r.$cloneSync=i.$cloneSync),t(r,s)}};return this.singleSubscriptions.push(s),setTimeout((()=>{let e=i.$get();e&&s.notify(e,e)}),0),Object.freeze({...i})}getIdStr(e){return this.id_fields.sort().map((t=>`${e[t]||""}`)).join(".")}getIdObj(e){let t={};return this.id_fields.sort().map((n=>{t[n]=e[n]})),t}getRowSyncObj(e){let t={};return[this.synced_field,...this.id_fields].sort().map((n=>{t[n]=e[n]})),t}matchesFilter(e){return Boolean(e&&(!this.filter||(0,i.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,i.isEmpty)(e)?{...t}:Object.keys({...e,...t}).filter((e=>!this.id_fields.includes(e))).reduce(((n,i)=>{let s={};if(i in t&&t[i]!==e[i]){let n={[i]:t[i]};t[i]&&e[i]&&"object"==typeof e[i]?JSON.stringify(t[i])!==JSON.stringify(e[i])&&(s=n):s=n}return{...n,...s}}),{})}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 this.storageType===o.localStorage?t=this.getItems().find((t=>this.matchesIdObj(t,e))):this.storageType===o.array?t=this.items.find((t=>this.matchesIdObj(t,e))):(this.itemsObj=this.itemsObj||{},t={...this.itemsObj}[this.getIdStr(e)]),{data:c(t),index:-1}}setItem(e,t,n=!1,i=!1){const s=c(e);if(this.storageType===o.localStorage){let e=this.getItems();i?e=e.filter((e=>!this.matchesIdObj(e,s))):void 0!==t&&e[t]?e[t]=n?{...s}:{...e[t],...s}:e.push(s),r&&window.localStorage.setItem(this.name,JSON.stringify(e))}else if(this.storageType===o.array)i?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(this.itemsObj=this.itemsObj||{},i)delete this.itemsObj[this.getIdStr(s)];else{let e=this.itemsObj[this.getIdStr(s)]||{};this.itemsObj[this.getIdStr(s)]=n?{...s}:{...e,...s}}}}function l(e,t){const n=e?c(e):e,s=t?c(t):t;let r=Object.assign({},n);return(0,i.isObject)(n)&&(0,i.isObject)(s)&&Object.keys(s).forEach((e=>{(0,i.isObject)(s[e])?e in n?r[e]=l(n[e],s[e]):Object.assign(r,{[e]:s[e]}):Object.assign(r,{[e]:s[e]})})),r}function c(e){if(r&&"structuredClone"in window&&"function"==typeof window.structuredClone)return window.structuredClone(e);if(Array.isArray(e))return e.slice(0).map((e=>c(e)));if((0,i.isObject)(e)){let t={};return(0,i.getKeys)(e).map((n=>{t[n]=c(e[n])})),t}return e}t.SyncedTable=a,t.default=l,t.quickClone=c},274:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prostgles=t.asName=t.debug=void 0;const i=n(792);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return i.asName}});const s="DEBUG_SYNCEDTABLE",r="undefined"!=typeof window;t.debug=function(...e){r&&window[s]&&window[s](...e)},t.prostgles=function(e,n){const{socket:s,onReady:a,onDisconnect:l,onReconnect:c,onSchemaChange:d=!0,onReload:u,onDebug:h}=e;if((0,t.debug)("prostgles",{initOpts:e}),d){let e;"function"==typeof d&&(e=d),s.removeAllListeners(i.CHANNELS.SCHEMA_CHANGED),e&&s.on(i.CHANNELS.SCHEMA_CHANGED,e)}const p=i.CHANNELS._preffix;let m,f={},g={},y={},b={},O=!1;function S(e,n,i){return(0,t.debug)("_unsubscribe",{channelName:e,handler:i}),new Promise(((t,r)=>{f[e]?(f[e].handlers=f[e].handlers.filter((e=>e!==i)),f[e].handlers.length||(s.emit(n,{},((e,t)=>{e&&console.error(e)})),s.removeListener(e,f[e].onCall),delete f[e]),t(!0)):t(!0)}))}function v({tableName:e,command:t,param1:n,param2:i},r){return new Promise(((o,a)=>{s.emit(p,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{if(e)console.error(e),a(e);else if(t){const{id_fields:e,synced_field:n,channelName:i}=t;s.emit(i,{onSyncRequest:r({})},(e=>{console.log(e)})),o({id_fields:e,synced_field:n,channelName:i})}}))}))}function _({tableName:e,command:t,param1:n,param2:i}){return new Promise(((r,o)=>{s.emit(p,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{e?(console.error(e),o(e)):t&&r(t)}))}))}const w=new o((async function({tableName:e,command:n,param1:i,param2:r},o){const{onPullRequest:a,onSyncRequest:l,onUpdates:c}=o;function d(e){return Object.freeze({unsync:function(){!function(e,n){(0,t.debug)("_unsync",{channelName:e,triggers:n}),new Promise(((t,i)=>{y[e]&&(y[e].triggers=y[e].triggers.filter((e=>e.onPullRequest!==n.onPullRequest&&e.onSyncRequest!==n.onSyncRequest&&e.onUpdates!==n.onUpdates)),y[e].triggers.length||(s.emit(e+"unsync",{},((e,n)=>{e?i(e):t(n)})),s.removeListener(e,y[e].onCall),delete y[e]))}))}(e,o)},syncData:function(t,n,i){s.emit(e,{onSyncRequest:{...l({}),...{data:t}||{},...{deleted:n}||{}}},i?e=>{i(e)}:null)}})}const u=Object.keys(y).find((t=>{let s=y[t];return s&&s.tableName===e&&s.command===n&&JSON.stringify(s.param1||{})===JSON.stringify(i||{})&&JSON.stringify(s.param2||{})===JSON.stringify(r||{})}));if(u)return y[u].triggers.push(o),d(u);{const h=await v({tableName:e,command:n,param1:i,param2:r},l),{channelName:p,synced_field:m,id_fields:f}=h;function g(t,n){t&&y[p]&&y[p].triggers.map((({onUpdates:i,onSyncRequest:s,onPullRequest:r})=>{t.data?Promise.resolve(i(t)).then((()=>{n&&n({ok:!0})})).catch((t=>{n?n({err:t}):console.error(e+" onUpdates error",t)})):t.onSyncRequest?Promise.resolve(s(t.onSyncRequest)).then((e=>n({onSyncRequest:e}))).catch((t=>{n?n({err:t}):console.error(e+" onSyncRequest error",t)})):t.onPullRequest?Promise.resolve(r(t.onPullRequest)).then((e=>{n({data:e})})).catch((t=>{n?n({err:t}):console.error(e+" onPullRequest error",t)})):console.log("unexpected response")}))}return y[p]={tableName:e,command:n,param1:i,param2:r,triggers:[o],syncInfo:h,onCall:g},s.on(p,g),d(p)}}),(([{tableName:e}])=>e)),j=new o((async function(e,{tableName:t,command:n,param1:i,param2:r},o,a){function l(n,s){let r={unsubscribe:function(){return S(n,s,o)},filter:{...i}};return e[t].update&&(r={...r,update:function(n,s){return e[t].update(i,n,s)}}),e[t].delete&&(r={...r,delete:function(n){return e[t].delete(i,n)}}),Object.freeze(r)}const c=Object.entries(f).find((([e])=>{let s=f[e];return s&&s.tableName===t&&s.command===n&&JSON.stringify(s.param1||{})===JSON.stringify(i||{})&&JSON.stringify(s.param2||{})===JSON.stringify(r||{})}));if(c){const e=c[0];return c[1].handlers.push(o),c[1].errorHandlers.push(a),setTimeout((()=>{var t,n;o&&(null===(t=null==f?void 0:f[e])||void 0===t?void 0:t.lastData)&&o(null===(n=null==f?void 0:f[e])||void 0===n?void 0:n.lastData)}),10),l(e,c[1].unsubChannel)}const{channelName:d,channelNameReady:u,channelNameUnsubscribe:h}=await _({tableName:t,command:n,param1:i,param2:r}),p=function(e,t){const n=f[d];n?e.data?(n.lastData=e.data,n.handlers.forEach((t=>{t(e.data)}))):e.err?n.errorHandlers.forEach((t=>{null==t||t(e.err)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",e):console.warn("Orphaned subscription: ",d)},m=a||function(e){console.error(`Uncaught error within running subscription \n ${d}`,e)};return s.on(d,p),f[d]={lastData:void 0,tableName:t,command:n,param1:i,param2:r,onCall:p,unsubChannel:h,handlers:[o],errorHandlers:[m],destroy:()=>{f[d]&&(Object.values(f[d]).map((e=>{e&&e.handlers&&e.handlers.map((e=>S(d,h,e)))})),delete f[d])}},s.emit(u,{now:Date.now()}),l(d,h)}),(([e,{tableName:t}])=>t));async function N(e,t,n,i){return j.run([e,t,n,i])}return new Promise(((e,o)=>{s.removeAllListeners(i.CHANNELS.CONNECTION),s.on(i.CHANNELS.CONNECTION,(e=>(o(e),"ok"))),l&&s.on("disconnect",l),s.on(i.CHANNELS.SCHEMA,(({schema:l,methods:d,tableSchema:S,auth:j,rawSQL:T,joinTables:x=[],err:E})=>{if((0,t.debug)("destroySyncs",{subscriptions:f,syncedTables:g}),Object.values(f).map((e=>e.destroy())),f={},y={},Object.values(g).map((e=>{e&&e.destroy&&e.destroy()})),g={},O&&c&&(c(s,E),E))return void console.error(E);if(E)throw o(E),E;O=!0;let C=JSON.parse(JSON.stringify(l)),P=JSON.parse(JSON.stringify(d)),I={},D={};if(j){if(j.pathGuard&&r){const e=e=>{var t,n;(null==e?void 0:e.shouldReload)&&(u?u():"undefined"!=typeof window&&(null===(n=null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.reload)||void 0===n||n.call(t)))};s.emit(i.CHANNELS.AUTHGUARD,JSON.stringify(window.location),((t,n)=>{e(n)})),s.removeAllListeners(i.CHANNELS.AUTHGUARD),s.on(i.CHANNELS.AUTHGUARD,(t=>{e(t)}))}D={...j},[i.CHANNELS.LOGIN,i.CHANNELS.LOGOUT,i.CHANNELS.REGISTER].map((e=>{j[e]&&(D[e]=function(t){return new Promise(((n,i)=>{s.emit(p+e,t,((e,t)=>{e?i(e):n(t)}))}))})}))}P.map((e=>{const t="string"==typeof e,n=t?e:e.name,r=async function(...e){return await(null==h?void 0:h({type:"method",command:n,data:{params:e}})),new Promise(((t,r)=>{s.emit(i.CHANNELS.METHOD,{method:n,params:e},((e,n)=>{e?r(e):t(n)}))}))};I[n]=t?r:{...e,run:r}})),I=Object.freeze(I),T&&(C.sql=function(e,t,n){return new Promise(((r,o)=>{s.emit(i.CHANNELS.SQL,{query:e,params:t,options:n},((e,t)=>{if(e)o(e);else if(n&&"noticeSubscription"===n.returnType&&t&&Object.keys(t).sort().join()===["socketChannel","socketUnsubChannel"].sort().join()&&!Object.values(t).find((e=>"string"!=typeof e))){const e=t,n=t=>(((e,t)=>{m=m||{config:t,listeners:[]},m.listeners.length||(s.removeAllListeners(t.socketChannel),s.on(t.socketChannel,(e=>{m&&m.listeners&&m.listeners.length?m.listeners.map((t=>{t(e)})):s.emit(t.socketUnsubChannel,{})}))),m.listeners.push(e)})(t,e),{...e,removeListener:()=>(e=>{m&&(m.listeners=m.listeners.filter((t=>t!==e)),!m.listeners.length&&m.config&&m.config.socketUnsubChannel&&s&&s.emit(m.config.socketUnsubChannel,{}))})(t)}),i={...e,addListener:n};r(i)}else if(n&&n.returnType&&"statement"===n.returnType||!t||Object.keys(t).sort().join()!==["socketChannel","socketUnsubChannel","notifChannel"].sort().join()||Object.values(t).find((e=>"string"!=typeof e)))r(t);else{const e=e=>(((e,t)=>{var n;b=b||{},b[t.notifChannel]?null===(n=b[t.notifChannel])||void 0===n||n.listeners.push(e):(b[t.notifChannel]={config:t,listeners:[e]},s.removeAllListeners(t.socketChannel),s.on(t.socketChannel,(e=>{var n,i;(null===(n=b[t.notifChannel])||void 0===n?void 0:n.listeners.length)?b[t.notifChannel].listeners.map((t=>{t(e)})):s.emit(null===(i=b[t.notifChannel])||void 0===i?void 0:i.config.socketUnsubChannel,{})})))})(e,t),{...t,removeListener:()=>((e,t)=>{const n=b[t.notifChannel];n&&(n.listeners=n.listeners.filter((t=>t!==e)),!n.listeners.length&&n.config&&n.config.socketUnsubChannel&&s&&(s.emit(n.config.socketUnsubChannel,{}),delete b[t.notifChannel]))})(e,t)}),n={...t,addListener:e};r(n)}}))}))});const k=e=>"[object Object]"===Object.prototype.toString.call(e),J=(e,t,n,i)=>{if(!k(e)||!k(t)||"function"!=typeof n||i&&"function"!=typeof i)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},$=["subscribe","subscribeOne"];(0,i.getKeys)(C).forEach((e=>{Object.keys(C[e]).sort(((e,t)=>$.includes(e)-$.includes(t))).forEach((t=>{if(["find","findOne"].includes(t)&&(C[e].getJoinedTables=function(){return(x||[]).filter((t=>Array.isArray(t)&&t.includes(e))).flat().filter((t=>t!==e))}),"sync"===t){if(C[e]._syncInfo={...C[e][t]},n){C[e].getSync=async(t,i={})=>(await(null==h?void 0:h({type:"table",command:"getSync",tableName:e,data:{filter:t,params:i}})),n.create({name:e,onDebug:h,filter:t,db:C,...i}));const t=async(t={},i={},s)=>{const r=`${e}.${JSON.stringify(t)}.${JSON.stringify(i)}`;return g[r]||(g[r]=await n.create({...i,onDebug:h,name:e,filter:t,db:C,onError:s})),g[r]};C[e].sync=async(n,i={handlesOnData:!0,select:"*"},s,r)=>{await(null==h?void 0:h({type:"table",command:"sync",tableName:e,data:{basicFilter:n,options:i}})),J(n,i,s,r);const o=await t(n,i,r);return await o.sync(s,i.handlesOnData)},C[e].syncOne=async(n,i={handlesOnData:!0},s,r)=>{await(null==h?void 0:h({type:"table",command:"syncOne",tableName:e,data:{basicFilter:n,options:i}})),J(n,i,s,r);const o=await t(n,i,r);return await o.syncOne(n,s,i.handlesOnData)}}C[e]._sync=async function(n,i,s){return await(null==h?void 0:h({type:"table",command:"_sync",tableName:e,data:{param1:n,param2:i,syncHandles:s}})),async function(e,t){return w.run([e,t])}({tableName:e,command:t,param1:n,param2:i},s)}}else if($.includes(t)){const n=async function(n,i,s,r){return await(null==h?void 0:h({type:"table",command:t,tableName:e,data:{param1:n,param2:i,onChange:s,onError:r}})),J(n,i,s,r),N(C,{tableName:e,command:t,param1:n,param2:i},s,r)};C[e][t]=n;const i="subscribeOne";C[e][t+"Hook"]=function(e={},s={},r){return{start:o=>n(e,s,t!==i?o:e=>{o(e[0])},r),args:[e,s,r]}},t!==i&&$.includes(i)||(C[e][i]=async function(n,i,s,r){return await(null==h?void 0:h({type:"table",command:"getSync",tableName:e,data:{param1:n,param2:i,onChange:s,onError:r}})),J(n,i,s,r),N(C,{tableName:e,command:t,param1:n,param2:i},(e=>{s(e[0])}),r)})}else C[e][t]=async function(n,i,r){return await(null==h?void 0:h({type:"table",command:t,tableName:e,data:{param1:n,param2:i,param3:r}})),new Promise(((o,a)=>{s.emit(p,{tableName:e,command:t,param1:n,param2:i,param3:r},((e,t)=>{e?a(e):o(t)}))}))}}))})),f&&Object.keys(f).length&&Object.keys(f).map((async e=>{try{let t=f[e];await _(t),s.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting old subscriptions",e)}})),y&&Object.keys(y).length&&(0,i.getKeys)(y).filter((e=>{var t;return null===(t=y[e])||void 0===t?void 0:t.triggers.length})).map((async e=>{try{let t=y[e];await v(t,t.triggers[0].onSyncRequest),s.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}})),x.flat().map((e=>{C.innerJoin=C.innerJoin||{},C.leftJoin=C.leftJoin||{},C.innerJoinOne=C.innerJoinOne||{},C.leftJoinOne=C.leftJoinOne||{};const t=(0,i.getJoinHandlers)(e);C.leftJoin[e]=t.leftJoin,C.innerJoin[e]=t.innerJoin,C.leftJoinOne[e]=t.leftJoinOne,C.innerJoinOne[e]=t.innerJoinOne})),(async()=>{try{await a(C,I,S,D,O)}catch(e){console.error("Prostgles: Error within onReady: \n",e),o(e)}e(C)})()}))}))};class o{constructor(e,t){this.queue=[],this.isRunning=!1,this.func=e,this.groupBy=t}async run(e){const t=new Promise(((t,n)=>{const i={arguments:e,onResult:t,onFail:n};this.queue.push(i)})),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,i)=>{const s=this.groupBy(e.arguments);t.includes(s)||(t.push(s),n.push({index:i,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}}},792:function(e){var t;this||window,t=()=>(()=>{"use strict";var e={31:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=void 0,t.CONTENT_TYPE_TO_EXT={"text/html":["html","htm","shtml"],"text/css":["css"],"text/csv":["csv"],"text/tsv":["tsv"],"text/xml":["xml"],"text/mathml":["mml"],"text/plain":["txt"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/x-component":["htc"],"image/gif":["gif"],"image/jpeg":["jpeg","jpg"],"image/png":["png"],"image/tiff":["tif","tiff"],"image/vnd.wap.wbmp":["wbmp"],"image/x-icon":["ico"],"image/x-jng":["jng"],"image/x-ms-bmp":["bmp"],"image/svg+xml":["svg"],"image/webp":["webp"],"application/sql":["sql"],"application/x-javascript":["js"],"application/atom+xml":["atom"],"application/rss+xml":["rss"],"application/java-archive":["jar","war","ear"],"application/mac-binhex40":["hqx"],"application/msword":["doc","docx"],"application/pdf":["pdf"],"application/postscript":["ps","eps","ai"],"application/rtf":["rtf"],"application/vnd.ms-excel":["xls","xlsx"],"application/vnd.ms-powerpoint":["ppt","pptx"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/x-7z-compressed":["7z"],"application/x-cocoa":["cco"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-makeself":["run"],"application/x-perl":["pl","pm"],"application/x-pilot":["prc","pdb"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-sea":["sea"],"application/x-shockwave-flash":["swf"],"application/x-stuffit":["sit"],"application/x-tcl":["tcl","tk"],"application/x-x509-ca-cert":["der","pem","crt"],"application/x-xpinstall":["xpi"],"application/xhtml+xml":["xhtml"],"application/zip":["zip"],"application/octet-stream":["bin","exe","dll","deb","dmg","eot","iso","img","msi","msp","msm"],"audio/midi":["mid","midi","kar"],"audio/mpeg":["mp3"],"audio/ogg":["ogg"],"audio/x-realaudio":["ra"],"video/3gpp":["3gpp","3gp"],"video/mpeg":["mpeg","mpg"],"video/quicktime":["mov"],"video/x-flv":["flv"],"video/x-mng":["mng"],"video/x-ms-asf":["asx","asf"],"video/x-ms-wmv":["wmv"],"video/x-msvideo":["avi"],"video/mp4":["m4v","mp4"],"video/webm":["webm"]}},444:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.COMPLEX_FILTER_KEY=t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.ArrayFilterOperands=t.TextFilter_FullTextSearchFilterKeys=t.TextFilterFTSKeys=t.TextFilterKeys=t.JsonbFilterKeys=t.JsonbOperands=t.CompareInFilterKeys=t.CompareFilterKeys=void 0;const i=n(128);t.CompareFilterKeys=["=","$eq","<>",">","<",">=","<=","$eq","$ne","$gt","$gte","$lte"],t.CompareInFilterKeys=["$in","$nin"],t.JsonbOperands={"@>":{Operator:"@>","Right Operand Type":"jsonb",Description:"Does the left JSON value contain the right JSON path/value entries at the top level?",Example:'\'{"a":1, "b":2}\'::jsonb @> \'{"b":2}\'::jsonb'},"<@":{Operator:"<@","Right Operand Type":"jsonb",Description:"Are the left JSON path/value entries contained at the top level within the right JSON value?",Example:'\'{"b":2}\'::jsonb <@ \'{"a":1, "b":2}\'::jsonb'},"?":{Operator:"?","Right Operand Type":"text",Description:"Does the string exist as a top-level key within the JSON value?",Example:"'{\"a\":1, \"b\":2}'::jsonb ? 'b'"},"?|":{Operator:"?|","Right Operand Type":"text[]",Description:"Do any of these array strings exist as top-level keys?",Example:"'{\"a\":1, \"b\":2, \"c\":3}'::jsonb ?| array['b', 'c']"},"?&":{Operator:"?&","Right Operand Type":"text[]",Description:"Do all of these array strings exist as top-level keys?",Example:"'[\"a\", \"b\"]'::jsonb ?& array['a', 'b']"},"||":{Operator:"||","Right Operand Type":"jsonb",Description:"Concatenate two jsonb values into a new jsonb value",Example:'\'["a", "b"]\'::jsonb || \'["c", "d"]\'::jsonb'},"-":{Operator:"-","Right Operand Type":"integer",Description:"Delete the array element with specified index (Negative integers count from the end). Throws an error if top level container is not an array.",Example:'\'["a", "b"]\'::jsonb - 1'},"#-":{Operator:"#-","Right Operand Type":"text[]",Description:"Delete the field or element with specified path (for JSON arrays, negative integers count from the end)",Example:"'[\"a\", {\"b\":1}]'::jsonb #- '{1,b}'"},"@?":{Operator:"@?","Right Operand Type":"jsonpath",Description:"Does JSON path return any item for the specified JSON value?",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)'"},"@@":{Operator:"@@","Right Operand Type":"jsonpath",Description:"Returns the result of JSON path predicate check for the specified JSON value. Only the first item of the result is taken into account. If the result is not Boolean, then null is returned.",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @@ '$.a[*] > 2'"}},t.JsonbFilterKeys=(0,i.getKeys)(t.JsonbOperands),t.TextFilterKeys=["$ilike","$like","$nilike","$nlike"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.ArrayFilterOperands=["@>","<@","=","$eq","$contains","$containedBy","&&","$overlaps"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"],t.GeomFilter_Funcs=["ST_MakeEnvelope","st_makeenvelope","ST_MakePolygon","st_makepolygon"],t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"],t.COMPLEX_FILTER_KEY="$filter"},590:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=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,i,s)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),s=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=t.RULE_METHODS=t.CHANNELS=t.JOIN_PARAMS=t.JOIN_KEYS=t.TS_PG_Types=t._PG_geometric=t._PG_postgis=t._PG_interval=t._PG_date=t._PG_bool=t._PG_json=t._PG_numbers=t._PG_strings=void 0,t._PG_strings=["bpchar","char","varchar","text","citext","uuid","bytea","time","timetz","interval","name","cidr","inet","macaddr","macaddr8","int4range","int8range","numrange","tsvector"],t._PG_numbers=["int2","int4","int8","float4","float8","numeric","money","oid"],t._PG_json=["json","jsonb"],t._PG_bool=["bool"],t._PG_date=["date","timestamp","timestamptz"],t._PG_interval=["interval"],t._PG_postgis=["geometry","geography"],t._PG_geometric=["point","line","lseg","box","path","polygon","circle"];const r={string:[...t._PG_strings,...t._PG_date,...t._PG_geometric,...t._PG_postgis,"lseg"],number:t._PG_numbers,boolean:t._PG_bool,any:[...t._PG_json,...t._PG_interval]};t.TS_PG_Types={...r,"number[]":r.number.map((e=>`_${e}`)),"boolean[]":r.boolean.map((e=>`_${e}`)),"string[]":r.string.map((e=>`_${e}`)),"any[]":r.any.map((e=>`_${e}`))},t.JOIN_KEYS=["$innerJoin","$leftJoin"],t.JOIN_PARAMS=["select","filter","$path","$condition","offset","limit","orderBy"];const o="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:o+"schema-changed",SCHEMA:o+"schema",DEFAULT:o,SQL:`${o}sql`,METHOD:`${o}method`,NOTICE_EV:`${o}notice`,LISTEN_EV:`${o}listen`,REGISTER:`${o}register`,LOGIN:`${o}login`,LOGOUT:`${o}logout`,AUTHGUARD:`${o}authguard`,CONNECTION:`${o}connection`,_preffix:o},t.RULE_METHODS={getColumns:["getColumns"],getInfo:["getInfo"],insert:["insert","upsert"],update:["update","upsert","updateBatch"],select:["findOne","find","count","size"],delete:["delete","remove"],sync:["sync","unsync"],subscribe:["unsubscribe","subscribe","subscribeOne"]},s(n(128),t),s(n(444),t);var a=n(31);Object.defineProperty(t,"CONTENT_TYPE_TO_EXT",{enumerable:!0,get:function(){return a.CONTENT_TYPE_TO_EXT}}),s(n(929),t)},929:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBSchemaAsJSONSchema=t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=void 0;const i=n(128);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,t)=>{const{type:n,arrayOf:r,arrayOfType:o,description:a,nullable:l,oneOf:c,oneOfType:d,title:u,record:h,...p}="string"==typeof e?{type:e}:e;let m={};const f={...(p.enum||p.allowedValues?.length)&&{enum:p.allowedValues?.slice(0)??p.enum.slice(0)},...!!a&&{description:a},...!!u&&{title:u}};if(p.enum?.length&&(f.type=typeof p.enum[0]),"string"==typeof n||r||o){if(n&&"string"!=typeof n)throw"Not expected";m=r||o||n?.endsWith("[]")?{type:"array",items:r||o?s(r||{type:o}):n?.startsWith("any")?{type:void 0}:{type:n?.slice(0,-2),...p.allowedValues&&{enum:p.allowedValues.slice(0)}}}:{type:n}}else(0,i.isObject)(n)?m={type:"object",required:(0,i.getKeys)(n).filter((e=>{const t=n[e];return"string"==typeof t||!t.optional})),properties:(0,i.getKeys)(n).reduce(((e,t)=>({...e,[t]:s(n[t])})),{})}:c||d?m={oneOf:(c||d.map((e=>({type:e})))).map((e=>s(e)))}:h&&(m={type:"object",...h.values&&!h.keysEnum&&{additionalProperties:s(h.values)},...h.keysEnum&&{properties:h.keysEnum.reduce(((e,t)=>({...e,[t]:h.values?s(h.values):{type:{}}})),{})}});if(l){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{...t?{$id:t?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...f,...m}};t.getJSONBSchemaAsJSONSchema=function(e,t,n){return s(n,{id:`${e}.${t}`})}},899:(e,t)=>{function n(e,t){var n=e[0],i=e[1],l=e[2],c=e[3];n=s(n,i,l,c,t[0],7,-680876936),c=s(c,n,i,l,t[1],12,-389564586),l=s(l,c,n,i,t[2],17,606105819),i=s(i,l,c,n,t[3],22,-1044525330),n=s(n,i,l,c,t[4],7,-176418897),c=s(c,n,i,l,t[5],12,1200080426),l=s(l,c,n,i,t[6],17,-1473231341),i=s(i,l,c,n,t[7],22,-45705983),n=s(n,i,l,c,t[8],7,1770035416),c=s(c,n,i,l,t[9],12,-1958414417),l=s(l,c,n,i,t[10],17,-42063),i=s(i,l,c,n,t[11],22,-1990404162),n=s(n,i,l,c,t[12],7,1804603682),c=s(c,n,i,l,t[13],12,-40341101),l=s(l,c,n,i,t[14],17,-1502002290),n=r(n,i=s(i,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=r(c,n,i,l,t[6],9,-1069501632),l=r(l,c,n,i,t[11],14,643717713),i=r(i,l,c,n,t[0],20,-373897302),n=r(n,i,l,c,t[5],5,-701558691),c=r(c,n,i,l,t[10],9,38016083),l=r(l,c,n,i,t[15],14,-660478335),i=r(i,l,c,n,t[4],20,-405537848),n=r(n,i,l,c,t[9],5,568446438),c=r(c,n,i,l,t[14],9,-1019803690),l=r(l,c,n,i,t[3],14,-187363961),i=r(i,l,c,n,t[8],20,1163531501),n=r(n,i,l,c,t[13],5,-1444681467),c=r(c,n,i,l,t[2],9,-51403784),l=r(l,c,n,i,t[7],14,1735328473),n=o(n,i=r(i,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=o(c,n,i,l,t[8],11,-2022574463),l=o(l,c,n,i,t[11],16,1839030562),i=o(i,l,c,n,t[14],23,-35309556),n=o(n,i,l,c,t[1],4,-1530992060),c=o(c,n,i,l,t[4],11,1272893353),l=o(l,c,n,i,t[7],16,-155497632),i=o(i,l,c,n,t[10],23,-1094730640),n=o(n,i,l,c,t[13],4,681279174),c=o(c,n,i,l,t[0],11,-358537222),l=o(l,c,n,i,t[3],16,-722521979),i=o(i,l,c,n,t[6],23,76029189),n=o(n,i,l,c,t[9],4,-640364487),c=o(c,n,i,l,t[12],11,-421815835),l=o(l,c,n,i,t[15],16,530742520),n=a(n,i=o(i,l,c,n,t[2],23,-995338651),l,c,t[0],6,-198630844),c=a(c,n,i,l,t[7],10,1126891415),l=a(l,c,n,i,t[14],15,-1416354905),i=a(i,l,c,n,t[5],21,-57434055),n=a(n,i,l,c,t[12],6,1700485571),c=a(c,n,i,l,t[3],10,-1894986606),l=a(l,c,n,i,t[10],15,-1051523),i=a(i,l,c,n,t[1],21,-2054922799),n=a(n,i,l,c,t[8],6,1873313359),c=a(c,n,i,l,t[15],10,-30611744),l=a(l,c,n,i,t[6],15,-1560198380),i=a(i,l,c,n,t[13],21,1309151649),n=a(n,i,l,c,t[4],6,-145523070),c=a(c,n,i,l,t[11],10,-1120210379),l=a(l,c,n,i,t[2],15,718787259),i=a(i,l,c,n,t[9],21,-343485551),e[0]=h(n,e[0]),e[1]=h(i,e[1]),e[2]=h(l,e[2]),e[3]=h(c,e[3])}function i(e,t,n,i,s,r){return t=h(h(t,e),h(i,r)),h(t<<s|t>>>32-s,n)}function s(e,t,n,s,r,o,a){return i(t&n|~t&s,e,t,r,o,a)}function r(e,t,n,s,r,o,a){return i(t&s|n&~s,e,t,r,o,a)}function o(e,t,n,s,r,o,a){return i(t^n^s,e,t,r,o,a)}function a(e,t,n,s,r,o,a){return i(n^(t|~s),e,t,r,o,a)}function l(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}Object.defineProperty(t,"__esModule",{value:!0}),t.md5=t.md5cycle=void 0,t.md5cycle=n;var c="0123456789abcdef".split("");function d(e){for(var t="",n=0;n<4;n++)t+=c[e>>8*n+4&15]+c[e>>8*n&15];return t}function u(e){return function(e){for(var t=0;t<e.length;t++)e[t]=d(e[t]);return e.join("")}(function(e){var t,i=e.length,s=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)n(s,l(e.substring(t-64,t)));e=e.substring(t-64);var r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<e.length;t++)r[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(n(s,r),t=0;t<16;t++)r[t]=0;return r[14]=8*i,n(s,r),s}(e))}function h(e,t){return e+t&4294967295}t.md5=u,u("hello")},128:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJoinHandlers=t.tryCatch=t.getKeys=t.isDefined=t.isObject=t.get=t.isEmpty=t.WAL=t.unpatchText=t.getTextPatch=t.stableStringify=t.includes=t.find=t.filter=t.omitKeys=t.pickKeys=t.asName=void 0;const i=n(899);function s(e,t=[],n=!1){let i=t;if(!i.length)return{};if(e&&i.length){let t={};return i.forEach((i=>{n&&void 0===e[i]||(t[i]=e[i])})),t}return e}function r(e,t){return s(e,l(e).filter((e=>!t.includes(e))))}function o(e,t){return e.filter((e=>Object.entries(t).every((([t,n])=>e[t]===n))))}function a(e){for(var t in e)return!1;return!0}function l(e){return Object.keys(e)}t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},t.pickKeys=s,t.omitKeys=r,t.filter=o,t.find=function(e,t){return o(e,t)[0]},t.includes=function(e,t){return e.some((e=>e===t))},t.stableStringify=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var n,i="boolean"==typeof t.cycles&&t.cycles,s=t.cmp&&(n=t.cmp,function(e){return function(t,i){var s={key:t,value:e[t]},r={key:i,value:e[i]};return n(s,r)}}),r=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var n,o;if(Array.isArray(t)){for(o="[",n=0;n<t.length;n++)n&&(o+=","),o+=e(t[n])||"null";return o+"]"}if(null===t)return"null";if(-1!==r.indexOf(t)){if(i)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=r.push(t)-1,l=Object.keys(t).sort(s&&s(t));for(o="",n=0;n<l.length;n++){var c=l[n],d=e(t[c]);d&&(o&&(o+=","),o+=JSON.stringify(c)+":"+d)}return r.splice(a,1),"{"+o+"}"}}(e)},t.getTextPatch=function(e,t){if(!(e&&t&&e.trim().length&&t.trim().length))return t;if(e===t)return{from:0,to:0,text:"",md5:(0,i.md5)(t)};function n(n=1){let i=n<1?-1:0,s=!1;for(;!s&&Math.abs(i)<=t.length;){const r=n<1?[i]:[0,i];e.slice(...r)!==t.slice(...r)?s=!0:i+=1*Math.sign(n)}return i}let s=n()-1,r=e.length+n(-1)+1,o=t.length+n(-1)+1;return{from:s,to:r,text:t.slice(s,o),md5:(0,i.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:s,text:r,md5:o}=t;if(null===r||null===e)return r;let a=e.slice(0,n)+r+e.slice(s);if(o&&(0,i.md5)(a)!==o)throw"Patch text error: Could not match md5 hash: (original/result) \n"+e+"\n"+a;return a},t.WAL=class{constructor(e){if(this.changed={},this.sending={},this.sentHistory={},this.callbacks=[],this.sort=(e,t)=>{const{orderBy:n}=this.options;return n&&e&&t&&n.map((n=>{if(!(n.fieldName in e)||!(n.fieldName in t))throw"Replication error: \n some orderBy fields missing from data";let i=n.asc?e[n.fieldName]:t[n.fieldName],s=n.asc?t[n.fieldName]:e[n.fieldName],r=+i-+s,o=i<s?-1:i==s?0:1;return"number"===n.tsDataType&&Number.isFinite(r)?r:o})).find((e=>e))||0},this.isInHistory=e=>{if(!e)throw"Provide item";const t=e[this.options.synced_field];if(!Number.isFinite(+t))throw"Provided item Synced field value is missing/invalid ";const n=this.sentHistory[this.getIdStr(e)],i=n?.[this.options.synced_field];if(n){if(!Number.isFinite(+i))throw"Provided historic item Synced field value is missing/invalid";if(+i==+t)return!0}return!1},this.addData=e=>{a(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map((e=>{var t;const{initial:n,current:i,delta:s}={...e};if(!i)throw"Expecting { current: object, initial?: object }";const r=this.getIdStr(i);this.changed??(this.changed={}),(t=this.changed)[r]??(t[r]={initial:n,current:i,delta:s}),this.changed[r].current={...this.changed[r].current,...i},this.changed[r].delta={...this.changed[r].delta,...s}})),this.sendItems()},this.isOnSending=!1,this.isSendingTimeout=void 0,this.willDeleteHistory=void 0,this.sendItems=async()=>{const{DEBUG_MODE:e,onSend:t,onSendEnd:n,batch_size:i,throttle:s,historyAgeSeconds:r=2}=this.options;if(this.isSendingTimeout||this.sending&&!a(this.sending))return;if(!this.changed||a(this.changed))return;let o,l=[],c=[],d={};Object.keys(this.changed).sort(((e,t)=>this.sort(this.changed[e].current,this.changed[t].current))).slice(0,i).map((e=>{let t={...this.changed[e]};this.sending[e]={...t},c.push({...t}),d[e]={...t.current},delete this.changed[e]})),l=c.map((e=>{let t={};return Object.keys(e.current).map((n=>{const i=e.initial?.[n],s=e.current[n];var r,o;![this.options.synced_field,...this.options.id_fields].includes(n)&&((r=i)===(o=s)||(["number","string","boolean"].includes(typeof r)?r===o:JSON.stringify(r)===JSON.stringify(o)))||(t[n]=s)})),t})),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout((()=>{this.isSendingTimeout=void 0,a(this.changed)||this.sendItems()}),s)),this.isOnSending=!0;try{await t(l,c),r&&(this.sentHistory={...this.sentHistory,...d},this.willDeleteHistory||(this.willDeleteHistory=setTimeout((()=>{this.willDeleteHistory=void 0,this.sentHistory={}}),1e3*r)))}catch(e){o=e,console.error("WAL onSend failed:",e,l,c)}if(this.isOnSending=!1,this.callbacks.length){const e=Object.keys(this.sending);this.callbacks.forEach(((t,n)=>{t.idStrs=t.idStrs.filter((t=>e.includes(t))),t.idStrs.length||t.cb(o)})),this.callbacks=this.callbacks.filter((e=>e.idStrs.length))}this.sending={},e&&console.log(this.options.id," SENT lr->",l[l.length-1]),a(this.changed)?n&&n(l,c,o):this.sendItems()},this.options={...e},!this.options.orderBy){const{synced_field:t,id_fields:n}=e;this.options.orderBy=[t,...n.sort()].map((e=>({fieldName:e,tsDataType:e===t?"number":"string",asc:!0})))}}isSending(){const e=this.isOnSending||!(a(this.sending)&&a(this.changed));return this.options.DEBUG_MODE&&console.log(this.options.id," CHECKING isSending ->",e),e}getIdStr(e){return this.options.id_fields.sort().map((t=>`${e[t]||""}`)).join(".")}getIdObj(e){let t={};return this.options.id_fields.sort().map((n=>{t[n]=e[n]})),t}getDeltaObj(e){let t={};return Object.keys(e).map((n=>{this.options.id_fields.includes(n)||(t[n]=e[n])})),t}},t.isEmpty=a,t.get=function(e,t){let n=t,i=e;return e?("string"==typeof n&&(n=n.split(".")),n.reduce(((e,t)=>e&&e[t]?e[t]:void 0),i)):e},t.isObject=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},t.isDefined=function(e){return null!=e},t.getKeys=l,t.tryCatch=async e=>{const t=Date.now();try{return{...await e(),duration:Date.now()-t}}catch(e){return{error:e,duration:Date.now()-t}}},t.getJoinHandlers=e=>{const t=(t,n)=>(n,i,s={})=>({[t?"$leftJoin":"$innerJoin"]:s.path??e,filter:n,...r(s,["path","select"]),select:i});return{innerJoin:t(!1),leftJoin:t(!0),innerJoinOne:t(!1),leftJoinOne:t(!0)}}}},t={};return function n(i){var s=t[i];if(void 0!==s)return s.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}(590)})(),e.exports=t()}},t={};function n(i){var s=t[i];if(void 0!==s)return s.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}var i={};return(()=>{"use strict";var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.prostgles=void 0;const t=n(274),s=n(133);e.prostgles=function(e){return(0,t.prostgles)(e,s.SyncedTable)}})(),i})()));
|
|
1
|
+
!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 i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this||window,(()=>(()=>{var e={133:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.quickClone=t.SyncedTable=t.debug=void 0;const i=n(792),s="DEBUG_SYNCEDTABLE",r="undefined"!=typeof window;t.debug=function(...e){r&&window[s]&&window[s](...e)};const o={array:"array",localStorage:"localStorage",object:"object"};class a{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:a,onDebug:d,db:u,skipFirstTrigger:h=!1,select:p="*",storageType:m="object",patchText:f=!1,patchJSON:g=!1,onError:y}){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)),r=[],o=[];if(this.columns&&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:l,initial:c}={...e};let d;c&&(t.map((e=>{!n.includes(e.name)&&e.name in l&&(null!=d||(d={...l}),d[e.name]=(0,i.getTextPatch)(c[e.name],l[e.name]))})),d&&this.wal&&(o.push(d),r.push([this.wal.getIdObj(d),this.wal.getDeltaObj(d)]))),d||s.push(l)})))}}if(r.length)try{await(null===(n=this.tableHandler)||void 0===n?void 0:n.updateBatch(r))}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;let t=[],n=[],i=[];if(e.map((({idObj:e,newItem:s,delta:r})=>{this.singleSubscriptions.filter((t=>this.matchesIdObj(t.idObj,e))).map((async e=>{try{await e.notify(s,r)}catch(e){console.error("SyncedTable failed to notify: ",e)}})),this.matchesFilter(s)&&(t.push(s),n.push(r),i.push(e))})),this.onChange||this.multiSubscriptions.length){let e=[],i=[];if(this.getItems().map((s=>{e.push({...s});const r=t.findIndex((e=>this.matchesIdObj(s,e)));i.push(n[r])})),this.onChange)try{this.onChange(e,i)}catch(e){console.error("SyncedTable failed to notify onChange: ",e)}this.multiSubscriptions.map((async t=>{try{await t.notify(e,i)}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=()=>{this.dbSync&&this.dbSync.unsync&&this.dbSync.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 i=this.getIdObj(e);return this.setItem(i,void 0,!0,!0),!t&&(null===(n=this.tableHandler)||void 0===n?void 0:n.delete)&&await this.tableHandler.delete(i),this._notifySubscribers(),!0},this.checkItemCols=e=>{if(this.columns&&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";let r,o=[],a=[];await Promise.all(e.map((async(e,n)=>{var s;let c={...e.idObj},d={...e.delta};Object.keys(d).map((e=>{void 0===d[e]&&(d[e]=null)})),t||this.checkItemCols({...e.delta,...e.idObj});let u=this.getItem(c),h=u.index,p=u.data;!t&&!(0,i.isEmpty)(d)||(0,i.isEmpty)(p)||(d=this.getDelta(p||{},d)),t||(d[this.synced_field]=Date.now());let m={...p,...d,...c};p&&!t&&(null===(s=e.opts)||void 0===s?void 0:s.deepMerge)&&(m=l({...p,...c},{...d})),r=p?p[this.synced_field]<m[this.synced_field]?"updated":"unchanged":"inserted",this.setItem(m,h);let f={idObj:c,delta:d,oldItem:p,newItem:m,status:r,from_server:t};return t||a.push({initial:p,current:{...m}}),f.delta&&!(0,i.isEmpty)(f.delta)&&o.push(f),!0}))).catch((e=>{console.error("SyncedTable failed upsert: ",e)})),null===(n=this.notifyWal)||void 0===n||n.addData(o.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=c(e);if(this.storageType===o.localStorage){if(!r)throw"Cannot access window object. Choose another storage method (array OR object)";window.localStorage.setItem(this.name,JSON.stringify(t))}else this.storageType===o.array?this.items=t:this.itemsObj=t.reduce(((e,t)=>({...e,[this.getIdStr(t)]:{...t}})),{})},this.getItems=()=>{let e=[];if(this.storageType===o.localStorage){if(!r)throw"Cannot access window object. Choose another storage method (array OR object)";let t=window.localStorage.getItem(this.name);if(t)try{e=JSON.parse(t)}catch(e){console.error(e)}}else e=this.storageType===o.array?this.items.map((e=>({...e}))):Object.values({...this.itemsObj});if(!this.id_fields||!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,i.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 c(e)},this.getBatch=({from_synced:e,to_synced:t,offset:n,limit:i}={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||i)&&(s=s.splice(null!=n?n:0,i||s.length)),s},this.name=e,this.filter=n,this.select=p,this.onChange=s,d&&(this.onDebug=t=>d({...t,type:"sync",tableName:e},this)),!o[m])throw"Invalid storage type. Expecting one of: "+Object.keys(o).join(", ");if(r||m!==o.localStorage||(console.warn("Could not set storageType to localStorage: window object missing\nStorage changed to object"),m="object"),this.storageType=m,this.patchText=f,this.patchJSON=g,!u)throw"db missing";this.db=u;const{id_fields:b,synced_field:O,throttle:S=100,batch_size:v=50}=u[this.name]._syncInfo;if(!b||!O)throw"id_fields/synced_field missing";this.id_fields=b,this.synced_field=O,this.batch_size=v,this.throttle=S,this.skipFirstTrigger=h,this.multiSubscriptions=[],this.singleSubscriptions=[],this.onError=y||function(e){console.error("Sync internal error: ",e)};const _={id_fields:b,synced_field:O,throttle:S};u[this.name]._sync(n,{select:p},{onSyncRequest:e=>{var t;let n={c_lr:void 0,c_fr:void 0,c_count:0},i=this.getBatch(e);return i.length&&(n={c_fr:this.getRowSyncObj(i[0]),c_lr:this.getRowSyncObj(i[i.length-1]),c_count:i.length}),null===(t=this.onDebug)||void 0===t||t.call(this,{command:"onUpdates",data:{syncBatchParams:e,batch:i,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;let 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){let 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 i.WAL({..._,batch_size:v,onSendStart:()=>{r&&(window.onbeforeunload=t)},onSend:async(e,t)=>(await this.updatePatches(t)).length?this.dbSync.syncData(e):[],onSendEnd:()=>{r&&(window.onbeforeunload=null)}}),this.notifyWal=new i.WAL({..._,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}})))}}),a()})),u[this.name].getColumns&&u[this.name].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 a({...e,onReady:()=>{setTimeout((()=>{t(n)}),0)}})}catch(e){n(e)}}))}sync(e,t=!0){const n={$unsync:()=>this.unsubscribe(e),getItems:()=>this.getItems(),$upsert:e=>{if(e){const t=e=>({idObj:this.getIdObj(e),delta:e});Array.isArray(e)?this.upsert(e.map((e=>t(e)))):this.upsert([t(e)])}}},i={_onChange:e,handlesOnData:t,handles:n,notify:(n,i)=>{let s=[...n],r=[...i];return t&&(s=s.map(((n,i)=>{const s=(n,i)=>({...n,...this.makeSingleSyncHandles(i,e),$get:()=>s(this.getItem(i).data,i),$find:e=>s(this.getItem(e).data,e),$update:(e,t)=>this.upsert([{idObj:i,delta:e,opts:t}]).then((e=>!0)),$delete:async()=>this.delete(i),$cloneMultiSync:e=>this.sync(e,t)}),r=this.getIdObj(n);return s(n,r)}))),e(s,r)}};return this.multiSubscriptions.push(i),this.skipFirstTrigger||setTimeout((()=>{let e=this.getItems();i.notify(e,e)}),0),Object.freeze({...n})}makeSingleSyncHandles(e,n){if(!e||!n)throw"syncOne(idObj, onChange) -> MISSING idObj or onChange";const i={$get:()=>this.getItem(e).data,$find:e=>this.getItem(e).data,$unsync:()=>this.unsubscribe(n),$delete:()=>this.delete(e),$update:(n,i)=>{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:i}])},$cloneSync:t=>this.syncOne(e,t),$cloneMultiSync:e=>this.sync(e,!0)};return i}syncOne(e,t,n=!0){const i=this.makeSingleSyncHandles(e,t),s={_onChange:t,idObj:e,handlesOnData:n,handles:i,notify:(e,s)=>{let r={...e};return n&&(r.$get=i.$get,r.$find=i.$find,r.$update=i.$update,r.$delete=i.$delete,r.$unsync=i.$unsync,r.$cloneSync=i.$cloneSync),t(r,s)}};return this.singleSubscriptions.push(s),setTimeout((()=>{let e=i.$get();e&&s.notify(e,e)}),0),Object.freeze({...i})}getIdStr(e){return this.id_fields.sort().map((t=>`${e[t]||""}`)).join(".")}getIdObj(e){let t={};return this.id_fields.sort().map((n=>{t[n]=e[n]})),t}getRowSyncObj(e){let t={};return[this.synced_field,...this.id_fields].sort().map((n=>{t[n]=e[n]})),t}matchesFilter(e){return Boolean(e&&(!this.filter||(0,i.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,i.isEmpty)(e)?{...t}:Object.keys({...e,...t}).filter((e=>!this.id_fields.includes(e))).reduce(((n,i)=>{let s={};if(i in t&&t[i]!==e[i]){let n={[i]:t[i]};t[i]&&e[i]&&"object"==typeof e[i]?JSON.stringify(t[i])!==JSON.stringify(e[i])&&(s=n):s=n}return{...n,...s}}),{})}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 this.storageType===o.localStorage?t=this.getItems().find((t=>this.matchesIdObj(t,e))):this.storageType===o.array?t=this.items.find((t=>this.matchesIdObj(t,e))):(this.itemsObj=this.itemsObj||{},t={...this.itemsObj}[this.getIdStr(e)]),{data:c(t),index:-1}}setItem(e,t,n=!1,i=!1){const s=c(e);if(this.storageType===o.localStorage){let e=this.getItems();i?e=e.filter((e=>!this.matchesIdObj(e,s))):void 0!==t&&e[t]?e[t]=n?{...s}:{...e[t],...s}:e.push(s),r&&window.localStorage.setItem(this.name,JSON.stringify(e))}else if(this.storageType===o.array)i?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(this.itemsObj=this.itemsObj||{},i)delete this.itemsObj[this.getIdStr(s)];else{let e=this.itemsObj[this.getIdStr(s)]||{};this.itemsObj[this.getIdStr(s)]=n?{...s}:{...e,...s}}}}function l(e,t){const n=e?c(e):e,s=t?c(t):t;let r=Object.assign({},n);return(0,i.isObject)(n)&&(0,i.isObject)(s)&&Object.keys(s).forEach((e=>{(0,i.isObject)(s[e])?e in n?r[e]=l(n[e],s[e]):Object.assign(r,{[e]:s[e]}):Object.assign(r,{[e]:s[e]})})),r}function c(e){if(r&&"structuredClone"in window&&"function"==typeof window.structuredClone)return window.structuredClone(e);if(Array.isArray(e))return e.slice(0).map((e=>c(e)));if((0,i.isObject)(e)){let t={};return(0,i.getKeys)(e).map((n=>{t[n]=c(e[n])})),t}return e}t.SyncedTable=a,t.default=l,t.quickClone=c},274:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prostgles=t.asName=t.debug=void 0;const i=n(792);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return i.asName}});const s="DEBUG_SYNCEDTABLE",r="undefined"!=typeof window;t.debug=function(...e){r&&window[s]&&window[s](...e)},t.prostgles=function(e,n){const{socket:s,onReady:a,onDisconnect:l,onReconnect:c,onSchemaChange:d=!0,onReload:u,onDebug:h}=e;if((0,t.debug)("prostgles",{initOpts:e}),d){let e;"function"==typeof d&&(e=d),s.removeAllListeners(i.CHANNELS.SCHEMA_CHANGED),e&&s.on(i.CHANNELS.SCHEMA_CHANGED,e)}const p=i.CHANNELS._preffix;let m,f={},g={},y={},b={},O=!1;function S(e,n,i){return(0,t.debug)("_unsubscribe",{channelName:e,handler:i}),new Promise(((t,r)=>{f[e]?(f[e].handlers=f[e].handlers.filter((e=>e!==i)),f[e].handlers.length||(s.emit(n,{},((e,t)=>{e&&console.error(e)})),s.removeListener(e,f[e].onCall),delete f[e]),t(!0)):t(!0)}))}function v({tableName:e,command:t,param1:n,param2:i},r){return new Promise(((o,a)=>{s.emit(p,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{if(e)console.error(e),a(e);else if(t){const{id_fields:e,synced_field:n,channelName:i}=t;s.emit(i,{onSyncRequest:r({})},(e=>{console.log(e)})),o({id_fields:e,synced_field:n,channelName:i})}}))}))}function _({tableName:e,command:t,param1:n,param2:i}){return new Promise(((r,o)=>{s.emit(p,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{e?(console.error(e),o(e)):t&&r(t)}))}))}const w=new o((async function({tableName:e,command:n,param1:i,param2:r},o){const{onPullRequest:a,onSyncRequest:l,onUpdates:c}=o;function d(e){return Object.freeze({unsync:function(){!function(e,n){(0,t.debug)("_unsync",{channelName:e,triggers:n}),new Promise(((t,i)=>{y[e]&&(y[e].triggers=y[e].triggers.filter((e=>e.onPullRequest!==n.onPullRequest&&e.onSyncRequest!==n.onSyncRequest&&e.onUpdates!==n.onUpdates)),y[e].triggers.length||(s.emit(e+"unsync",{},((e,n)=>{e?i(e):t(n)})),s.removeListener(e,y[e].onCall),delete y[e]))}))}(e,o)},syncData:function(t,n,i){s.emit(e,{onSyncRequest:{...l({}),...{data:t}||{},...{deleted:n}||{}}},i?e=>{i(e)}:null)}})}const u=Object.keys(y).find((t=>{let s=y[t];return s&&s.tableName===e&&s.command===n&&JSON.stringify(s.param1||{})===JSON.stringify(i||{})&&JSON.stringify(s.param2||{})===JSON.stringify(r||{})}));if(u)return y[u].triggers.push(o),d(u);{const h=await v({tableName:e,command:n,param1:i,param2:r},l),{channelName:p,synced_field:m,id_fields:f}=h;function g(t,n){t&&y[p]&&y[p].triggers.map((({onUpdates:i,onSyncRequest:s,onPullRequest:r})=>{t.data?Promise.resolve(i(t)).then((()=>{n&&n({ok:!0})})).catch((t=>{n?n({err:t}):console.error(e+" onUpdates error",t)})):t.onSyncRequest?Promise.resolve(s(t.onSyncRequest)).then((e=>n({onSyncRequest:e}))).catch((t=>{n?n({err:t}):console.error(e+" onSyncRequest error",t)})):t.onPullRequest?Promise.resolve(r(t.onPullRequest)).then((e=>{n({data:e})})).catch((t=>{n?n({err:t}):console.error(e+" onPullRequest error",t)})):console.log("unexpected response")}))}return y[p]={tableName:e,command:n,param1:i,param2:r,triggers:[o],syncInfo:h,onCall:g},s.on(p,g),d(p)}}),(([{tableName:e}])=>e)),j=new o((async function(e,{tableName:t,command:n,param1:i,param2:r},o,a){function l(n,s){let r={unsubscribe:function(){return S(n,s,o)},filter:{...i}};return e[t].update&&(r={...r,update:function(n,s){return e[t].update(i,n,s)}}),e[t].delete&&(r={...r,delete:function(n){return e[t].delete(i,n)}}),Object.freeze(r)}const c=Object.entries(f).find((([e])=>{let s=f[e];return s&&s.tableName===t&&s.command===n&&JSON.stringify(s.param1||{})===JSON.stringify(i||{})&&JSON.stringify(s.param2||{})===JSON.stringify(r||{})}));if(c){const e=c[0];return c[1].handlers.push(o),c[1].errorHandlers.push(a),setTimeout((()=>{var t,n;o&&(null===(t=null==f?void 0:f[e])||void 0===t?void 0:t.lastData)&&o(null===(n=null==f?void 0:f[e])||void 0===n?void 0:n.lastData)}),10),l(e,c[1].unsubChannel)}const{channelName:d,channelNameReady:u,channelNameUnsubscribe:h}=await _({tableName:t,command:n,param1:i,param2:r}),p=function(e,t){const n=f[d];n?e.data?(n.lastData=e.data,n.handlers.forEach((t=>{t(e.data)}))):e.err?n.errorHandlers.forEach((t=>{null==t||t(e.err)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",e):console.warn("Orphaned subscription: ",d)},m=a||function(e){console.error(`Uncaught error within running subscription \n ${d}`,e)};return s.on(d,p),f[d]={lastData:void 0,tableName:t,command:n,param1:i,param2:r,onCall:p,unsubChannel:h,handlers:[o],errorHandlers:[m],destroy:()=>{f[d]&&(Object.values(f[d]).map((e=>{e&&e.handlers&&e.handlers.map((e=>S(d,h,e)))})),delete f[d])}},s.emit(u,{now:Date.now()}),l(d,h)}),(([e,{tableName:t}])=>t));async function N(e,t,n,i){return j.run([e,t,n,i])}return new Promise(((e,o)=>{s.removeAllListeners(i.CHANNELS.CONNECTION),s.on(i.CHANNELS.CONNECTION,(e=>(o(e),"ok"))),l&&s.on("disconnect",l),s.on(i.CHANNELS.SCHEMA,(({schema:l,methods:d,tableSchema:S,auth:j,rawSQL:T,joinTables:x=[],err:E})=>{if((0,t.debug)("destroySyncs",{subscriptions:f,syncedTables:g}),Object.values(f).map((e=>e.destroy())),f={},y={},Object.values(g).map((e=>{e&&e.destroy&&e.destroy()})),g={},O&&c&&(c(s,E),E))return void console.error(E);if(E)throw o(E),E;O=!0;let C=JSON.parse(JSON.stringify(l)),P=JSON.parse(JSON.stringify(d)),I={},J={};if(j){if(j.pathGuard&&r){const e=e=>{var t,n;(null==e?void 0:e.shouldReload)&&(u?u():"undefined"!=typeof window&&(null===(n=null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.reload)||void 0===n||n.call(t)))};s.emit(i.CHANNELS.AUTHGUARD,JSON.stringify(window.location),((t,n)=>{e(n)})),s.removeAllListeners(i.CHANNELS.AUTHGUARD),s.on(i.CHANNELS.AUTHGUARD,(t=>{e(t)}))}J={...j},[i.CHANNELS.LOGIN,i.CHANNELS.LOGOUT,i.CHANNELS.REGISTER].map((e=>{j[e]&&(J[e]=function(t){return new Promise(((n,i)=>{s.emit(p+e,t,((e,t)=>{e?i(e):n(t)}))}))})}))}P.map((e=>{const t="string"==typeof e,n=t?e:e.name,r=async function(...e){return await(null==h?void 0:h({type:"method",command:n,data:{params:e}})),new Promise(((t,r)=>{s.emit(i.CHANNELS.METHOD,{method:n,params:e},((e,n)=>{e?r(e):t(n)}))}))};I[n]=t?r:{...e,run:r}})),I=Object.freeze(I),T&&(C.sql=function(e,t,n){return new Promise(((r,o)=>{s.emit(i.CHANNELS.SQL,{query:e,params:t,options:n},((e,t)=>{if(e)o(e);else if(n&&"noticeSubscription"===n.returnType&&t&&Object.keys(t).sort().join()===["socketChannel","socketUnsubChannel"].sort().join()&&!Object.values(t).find((e=>"string"!=typeof e))){const e=t,n=t=>(((e,t)=>{m=m||{config:t,listeners:[]},m.listeners.length||(s.removeAllListeners(t.socketChannel),s.on(t.socketChannel,(e=>{m&&m.listeners&&m.listeners.length?m.listeners.map((t=>{t(e)})):s.emit(t.socketUnsubChannel,{})}))),m.listeners.push(e)})(t,e),{...e,removeListener:()=>(e=>{m&&(m.listeners=m.listeners.filter((t=>t!==e)),!m.listeners.length&&m.config&&m.config.socketUnsubChannel&&s&&s.emit(m.config.socketUnsubChannel,{}))})(t)}),i={...e,addListener:n};r(i)}else if(n&&n.returnType&&"statement"===n.returnType||!t||Object.keys(t).sort().join()!==["socketChannel","socketUnsubChannel","notifChannel"].sort().join()||Object.values(t).find((e=>"string"!=typeof e)))r(t);else{const e=e=>(((e,t)=>{var n;b=b||{},b[t.notifChannel]?null===(n=b[t.notifChannel])||void 0===n||n.listeners.push(e):(b[t.notifChannel]={config:t,listeners:[e]},s.removeAllListeners(t.socketChannel),s.on(t.socketChannel,(e=>{var n,i;(null===(n=b[t.notifChannel])||void 0===n?void 0:n.listeners.length)?b[t.notifChannel].listeners.map((t=>{t(e)})):s.emit(null===(i=b[t.notifChannel])||void 0===i?void 0:i.config.socketUnsubChannel,{})})))})(e,t),{...t,removeListener:()=>((e,t)=>{const n=b[t.notifChannel];n&&(n.listeners=n.listeners.filter((t=>t!==e)),!n.listeners.length&&n.config&&n.config.socketUnsubChannel&&s&&(s.emit(n.config.socketUnsubChannel,{}),delete b[t.notifChannel]))})(e,t)}),n={...t,addListener:e};r(n)}}))}))});const D=e=>"[object Object]"===Object.prototype.toString.call(e),k=(e,t,n,i)=>{if(!D(e)||!D(t)||"function"!=typeof n||i&&"function"!=typeof i)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},$=["subscribe","subscribeOne"];(0,i.getKeys)(C).forEach((e=>{Object.keys(C[e]).sort(((e,t)=>$.includes(e)-$.includes(t))).forEach((t=>{if(["find","findOne"].includes(t)&&(C[e].getJoinedTables=function(){return(x||[]).filter((t=>Array.isArray(t)&&t.includes(e))).flat().filter((t=>t!==e))}),"sync"===t){if(C[e]._syncInfo={...C[e][t]},n){C[e].getSync=async(t,i={})=>(await(null==h?void 0:h({type:"table",command:"getSync",tableName:e,data:{filter:t,params:i}})),n.create({name:e,onDebug:h,filter:t,db:C,...i}));const t=async(t={},i={},s)=>{const r=`${e}.${JSON.stringify(t)}.${JSON.stringify(i)}`;return g[r]||(g[r]=await n.create({...i,onDebug:h,name:e,filter:t,db:C,onError:s})),g[r]};C[e].sync=async(n,i={handlesOnData:!0,select:"*"},s,r)=>{await(null==h?void 0:h({type:"table",command:"sync",tableName:e,data:{basicFilter:n,options:i}})),k(n,i,s,r);const o=await t(n,i,r);return await o.sync(s,i.handlesOnData)},C[e].syncOne=async(n,i={handlesOnData:!0},s,r)=>{await(null==h?void 0:h({type:"table",command:"syncOne",tableName:e,data:{basicFilter:n,options:i}})),k(n,i,s,r);const o=await t(n,i,r);return await o.syncOne(n,s,i.handlesOnData)}}C[e]._sync=async function(n,i,s){return await(null==h?void 0:h({type:"table",command:"_sync",tableName:e,data:{param1:n,param2:i,syncHandles:s}})),async function(e,t){return w.run([e,t])}({tableName:e,command:t,param1:n,param2:i},s)}}else if($.includes(t)){const n=async function(n,i,s,r){return await(null==h?void 0:h({type:"table",command:t,tableName:e,data:{param1:n,param2:i,onChange:s,onError:r}})),k(n,i,s,r),N(C,{tableName:e,command:t,param1:n,param2:i},s,r)};C[e][t]=n;const i="subscribeOne";C[e][t+"Hook"]=function(e={},s={},r){return{start:o=>n(e,s,t!==i?o:e=>{o(e[0])},r),args:[e,s,r]}},t!==i&&$.includes(i)||(C[e][i]=async function(n,i,s,r){return await(null==h?void 0:h({type:"table",command:"getSync",tableName:e,data:{param1:n,param2:i,onChange:s,onError:r}})),k(n,i,s,r),N(C,{tableName:e,command:t,param1:n,param2:i},(e=>{s(e[0])}),r)})}else C[e][t]=async function(n,i,r){return await(null==h?void 0:h({type:"table",command:t,tableName:e,data:{param1:n,param2:i,param3:r}})),new Promise(((o,a)=>{s.emit(p,{tableName:e,command:t,param1:n,param2:i,param3:r},((e,t)=>{e?a(e):o(t)}))}))}}))})),f&&Object.keys(f).length&&Object.keys(f).map((async e=>{try{let t=f[e];await _(t),s.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting old subscriptions",e)}})),y&&Object.keys(y).length&&(0,i.getKeys)(y).filter((e=>{var t;return null===(t=y[e])||void 0===t?void 0:t.triggers.length})).map((async e=>{try{let t=y[e];await v(t,t.triggers[0].onSyncRequest),s.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}})),x.flat().map((e=>{C.innerJoin=C.innerJoin||{},C.leftJoin=C.leftJoin||{},C.innerJoinOne=C.innerJoinOne||{},C.leftJoinOne=C.leftJoinOne||{};const t=(0,i.getJoinHandlers)(e);C.leftJoin[e]=t.leftJoin,C.innerJoin[e]=t.innerJoin,C.leftJoinOne[e]=t.leftJoinOne,C.innerJoinOne[e]=t.innerJoinOne})),(async()=>{try{await a(C,I,S,J,O)}catch(e){console.error("Prostgles: Error within onReady: \n",e),o(e)}e(C)})()}))}))};class o{constructor(e,t){this.queue=[],this.isRunning=!1,this.func=e,this.groupBy=t}async run(e){const t=new Promise(((t,n)=>{const i={arguments:e,onResult:t,onFail:n};this.queue.push(i)})),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,i)=>{const s=this.groupBy(e.arguments);t.includes(s)||(t.push(s),n.push({index:i,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}}},792:function(e){var t;this||window,t=()=>(()=>{"use strict";var e={31:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=void 0,t.CONTENT_TYPE_TO_EXT={"text/html":["html","htm","shtml"],"text/css":["css"],"text/csv":["csv"],"text/tsv":["tsv"],"text/xml":["xml"],"text/mathml":["mml"],"text/plain":["txt"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/x-component":["htc"],"image/gif":["gif"],"image/jpeg":["jpeg","jpg"],"image/png":["png"],"image/tiff":["tif","tiff"],"image/vnd.wap.wbmp":["wbmp"],"image/x-icon":["ico"],"image/x-jng":["jng"],"image/x-ms-bmp":["bmp"],"image/svg+xml":["svg"],"image/webp":["webp"],"application/sql":["sql"],"application/x-javascript":["js"],"application/atom+xml":["atom"],"application/rss+xml":["rss"],"application/java-archive":["jar","war","ear"],"application/mac-binhex40":["hqx"],"application/msword":["doc","docx"],"application/pdf":["pdf"],"application/postscript":["ps","eps","ai"],"application/rtf":["rtf"],"application/vnd.ms-excel":["xls","xlsx"],"application/vnd.ms-powerpoint":["ppt","pptx"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/x-7z-compressed":["7z"],"application/x-cocoa":["cco"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-makeself":["run"],"application/x-perl":["pl","pm"],"application/x-pilot":["prc","pdb"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-sea":["sea"],"application/x-shockwave-flash":["swf"],"application/x-stuffit":["sit"],"application/x-tcl":["tcl","tk"],"application/x-x509-ca-cert":["der","pem","crt"],"application/x-xpinstall":["xpi"],"application/xhtml+xml":["xhtml"],"application/zip":["zip"],"application/octet-stream":["bin","exe","dll","deb","dmg","eot","iso","img","msi","msp","msm"],"audio/midi":["mid","midi","kar"],"audio/mpeg":["mp3"],"audio/ogg":["ogg"],"audio/x-realaudio":["ra"],"video/3gpp":["3gpp","3gp"],"video/mpeg":["mpeg","mpg"],"video/quicktime":["mov"],"video/x-flv":["flv"],"video/x-mng":["mng"],"video/x-ms-asf":["asx","asf"],"video/x-ms-wmv":["wmv"],"video/x-msvideo":["avi"],"video/mp4":["m4v","mp4"],"video/webm":["webm"]}},444:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.COMPLEX_FILTER_KEY=t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.ArrayFilterOperands=t.TextFilter_FullTextSearchFilterKeys=t.TextFilterFTSKeys=t.TextFilterKeys=t.JsonbFilterKeys=t.JsonbOperands=t.CompareInFilterKeys=t.CompareFilterKeys=void 0;const i=n(128);t.CompareFilterKeys=["=","$eq","<>",">","<",">=","<=","$eq","$ne","$gt","$gte","$lte"],t.CompareInFilterKeys=["$in","$nin"],t.JsonbOperands={"@>":{Operator:"@>","Right Operand Type":"jsonb",Description:"Does the left JSON value contain the right JSON path/value entries at the top level?",Example:'\'{"a":1, "b":2}\'::jsonb @> \'{"b":2}\'::jsonb'},"<@":{Operator:"<@","Right Operand Type":"jsonb",Description:"Are the left JSON path/value entries contained at the top level within the right JSON value?",Example:'\'{"b":2}\'::jsonb <@ \'{"a":1, "b":2}\'::jsonb'},"?":{Operator:"?","Right Operand Type":"text",Description:"Does the string exist as a top-level key within the JSON value?",Example:"'{\"a\":1, \"b\":2}'::jsonb ? 'b'"},"?|":{Operator:"?|","Right Operand Type":"text[]",Description:"Do any of these array strings exist as top-level keys?",Example:"'{\"a\":1, \"b\":2, \"c\":3}'::jsonb ?| array['b', 'c']"},"?&":{Operator:"?&","Right Operand Type":"text[]",Description:"Do all of these array strings exist as top-level keys?",Example:"'[\"a\", \"b\"]'::jsonb ?& array['a', 'b']"},"||":{Operator:"||","Right Operand Type":"jsonb",Description:"Concatenate two jsonb values into a new jsonb value",Example:'\'["a", "b"]\'::jsonb || \'["c", "d"]\'::jsonb'},"-":{Operator:"-","Right Operand Type":"integer",Description:"Delete the array element with specified index (Negative integers count from the end). Throws an error if top level container is not an array.",Example:'\'["a", "b"]\'::jsonb - 1'},"#-":{Operator:"#-","Right Operand Type":"text[]",Description:"Delete the field or element with specified path (for JSON arrays, negative integers count from the end)",Example:"'[\"a\", {\"b\":1}]'::jsonb #- '{1,b}'"},"@?":{Operator:"@?","Right Operand Type":"jsonpath",Description:"Does JSON path return any item for the specified JSON value?",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)'"},"@@":{Operator:"@@","Right Operand Type":"jsonpath",Description:"Returns the result of JSON path predicate check for the specified JSON value. Only the first item of the result is taken into account. If the result is not Boolean, then null is returned.",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @@ '$.a[*] > 2'"}},t.JsonbFilterKeys=(0,i.getKeys)(t.JsonbOperands),t.TextFilterKeys=["$ilike","$like","$nilike","$nlike"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.ArrayFilterOperands=["@>","<@","=","$eq","$contains","$containedBy","&&","$overlaps"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"],t.GeomFilter_Funcs=["ST_MakeEnvelope","st_makeenvelope","ST_MakePolygon","st_makepolygon"],t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"],t.COMPLEX_FILTER_KEY="$filter"},590:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=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,i,s)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),s=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=t.RULE_METHODS=t.CHANNELS=t.JOIN_PARAMS=t.JOIN_KEYS=t.TS_PG_Types=t._PG_geometric=t._PG_postgis=t._PG_interval=t._PG_date=t._PG_bool=t._PG_json=t._PG_numbers=t._PG_strings=void 0,t._PG_strings=["bpchar","char","varchar","text","citext","uuid","bytea","time","timetz","interval","name","cidr","inet","macaddr","macaddr8","int4range","int8range","numrange","tsvector"],t._PG_numbers=["int2","int4","int8","float4","float8","numeric","money","oid"],t._PG_json=["json","jsonb"],t._PG_bool=["bool"],t._PG_date=["date","timestamp","timestamptz"],t._PG_interval=["interval"],t._PG_postgis=["geometry","geography"],t._PG_geometric=["point","line","lseg","box","path","polygon","circle"];const r={string:[...t._PG_strings,...t._PG_date,...t._PG_geometric,...t._PG_postgis,"lseg"],number:t._PG_numbers,boolean:t._PG_bool,any:[...t._PG_json,...t._PG_interval]};t.TS_PG_Types={...r,"number[]":r.number.map((e=>`_${e}`)),"boolean[]":r.boolean.map((e=>`_${e}`)),"string[]":r.string.map((e=>`_${e}`)),"any[]":r.any.map((e=>`_${e}`))},t.JOIN_KEYS=["$innerJoin","$leftJoin"],t.JOIN_PARAMS=["select","filter","$path","$condition","offset","limit","orderBy"];const o="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:o+"schema-changed",SCHEMA:o+"schema",DEFAULT:o,SQL:`${o}sql`,METHOD:`${o}method`,NOTICE_EV:`${o}notice`,LISTEN_EV:`${o}listen`,REGISTER:`${o}register`,LOGIN:`${o}login`,LOGOUT:`${o}logout`,AUTHGUARD:`${o}authguard`,CONNECTION:`${o}connection`,_preffix:o},t.RULE_METHODS={getColumns:["getColumns"],getInfo:["getInfo"],insert:["insert","upsert"],update:["update","upsert","updateBatch"],select:["findOne","find","count","size"],delete:["delete","remove"],sync:["sync","unsync"],subscribe:["unsubscribe","subscribe","subscribeOne"]},s(n(128),t),s(n(444),t);var a=n(31);Object.defineProperty(t,"CONTENT_TYPE_TO_EXT",{enumerable:!0,get:function(){return a.CONTENT_TYPE_TO_EXT}}),s(n(929),t)},929:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBSchemaAsJSONSchema=t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=void 0;const i=n(128);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,t)=>{const{type:n,arrayOf:r,arrayOfType:o,description:a,nullable:l,oneOf:c,oneOfType:d,title:u,record:h,...p}="string"==typeof e?{type:e}:e;let m={};const f={...(p.enum||p.allowedValues?.length)&&{enum:p.allowedValues?.slice(0)??p.enum.slice(0)},...!!a&&{description:a},...!!u&&{title:u}};if(p.enum?.length&&(f.type=typeof p.enum[0]),"string"==typeof n||r||o){if(n&&"string"!=typeof n)throw"Not expected";m=r||o||n?.endsWith("[]")?{type:"array",items:r||o?s(r||{type:o}):n?.startsWith("any")?{type:void 0}:{type:n?.slice(0,-2),...p.allowedValues&&{enum:p.allowedValues.slice(0)}}}:{type:n}}else(0,i.isObject)(n)?m={type:"object",required:(0,i.getKeys)(n).filter((e=>{const t=n[e];return"string"==typeof t||!t.optional})),properties:(0,i.getKeys)(n).reduce(((e,t)=>({...e,[t]:s(n[t])})),{})}:c||d?m={oneOf:(c||d.map((e=>({type:e})))).map((e=>s(e)))}:h&&(m={type:"object",...h.values&&!h.keysEnum&&{additionalProperties:s(h.values)},...h.keysEnum&&{properties:h.keysEnum.reduce(((e,t)=>({...e,[t]:h.values?s(h.values):{type:{}}})),{})}});if(l){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{...t?{$id:t?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...f,...m}};t.getJSONBSchemaAsJSONSchema=function(e,t,n){return s(n,{id:`${e}.${t}`})}},899:(e,t)=>{function n(e,t){var n=e[0],i=e[1],l=e[2],c=e[3];n=s(n,i,l,c,t[0],7,-680876936),c=s(c,n,i,l,t[1],12,-389564586),l=s(l,c,n,i,t[2],17,606105819),i=s(i,l,c,n,t[3],22,-1044525330),n=s(n,i,l,c,t[4],7,-176418897),c=s(c,n,i,l,t[5],12,1200080426),l=s(l,c,n,i,t[6],17,-1473231341),i=s(i,l,c,n,t[7],22,-45705983),n=s(n,i,l,c,t[8],7,1770035416),c=s(c,n,i,l,t[9],12,-1958414417),l=s(l,c,n,i,t[10],17,-42063),i=s(i,l,c,n,t[11],22,-1990404162),n=s(n,i,l,c,t[12],7,1804603682),c=s(c,n,i,l,t[13],12,-40341101),l=s(l,c,n,i,t[14],17,-1502002290),n=r(n,i=s(i,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=r(c,n,i,l,t[6],9,-1069501632),l=r(l,c,n,i,t[11],14,643717713),i=r(i,l,c,n,t[0],20,-373897302),n=r(n,i,l,c,t[5],5,-701558691),c=r(c,n,i,l,t[10],9,38016083),l=r(l,c,n,i,t[15],14,-660478335),i=r(i,l,c,n,t[4],20,-405537848),n=r(n,i,l,c,t[9],5,568446438),c=r(c,n,i,l,t[14],9,-1019803690),l=r(l,c,n,i,t[3],14,-187363961),i=r(i,l,c,n,t[8],20,1163531501),n=r(n,i,l,c,t[13],5,-1444681467),c=r(c,n,i,l,t[2],9,-51403784),l=r(l,c,n,i,t[7],14,1735328473),n=o(n,i=r(i,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=o(c,n,i,l,t[8],11,-2022574463),l=o(l,c,n,i,t[11],16,1839030562),i=o(i,l,c,n,t[14],23,-35309556),n=o(n,i,l,c,t[1],4,-1530992060),c=o(c,n,i,l,t[4],11,1272893353),l=o(l,c,n,i,t[7],16,-155497632),i=o(i,l,c,n,t[10],23,-1094730640),n=o(n,i,l,c,t[13],4,681279174),c=o(c,n,i,l,t[0],11,-358537222),l=o(l,c,n,i,t[3],16,-722521979),i=o(i,l,c,n,t[6],23,76029189),n=o(n,i,l,c,t[9],4,-640364487),c=o(c,n,i,l,t[12],11,-421815835),l=o(l,c,n,i,t[15],16,530742520),n=a(n,i=o(i,l,c,n,t[2],23,-995338651),l,c,t[0],6,-198630844),c=a(c,n,i,l,t[7],10,1126891415),l=a(l,c,n,i,t[14],15,-1416354905),i=a(i,l,c,n,t[5],21,-57434055),n=a(n,i,l,c,t[12],6,1700485571),c=a(c,n,i,l,t[3],10,-1894986606),l=a(l,c,n,i,t[10],15,-1051523),i=a(i,l,c,n,t[1],21,-2054922799),n=a(n,i,l,c,t[8],6,1873313359),c=a(c,n,i,l,t[15],10,-30611744),l=a(l,c,n,i,t[6],15,-1560198380),i=a(i,l,c,n,t[13],21,1309151649),n=a(n,i,l,c,t[4],6,-145523070),c=a(c,n,i,l,t[11],10,-1120210379),l=a(l,c,n,i,t[2],15,718787259),i=a(i,l,c,n,t[9],21,-343485551),e[0]=h(n,e[0]),e[1]=h(i,e[1]),e[2]=h(l,e[2]),e[3]=h(c,e[3])}function i(e,t,n,i,s,r){return t=h(h(t,e),h(i,r)),h(t<<s|t>>>32-s,n)}function s(e,t,n,s,r,o,a){return i(t&n|~t&s,e,t,r,o,a)}function r(e,t,n,s,r,o,a){return i(t&s|n&~s,e,t,r,o,a)}function o(e,t,n,s,r,o,a){return i(t^n^s,e,t,r,o,a)}function a(e,t,n,s,r,o,a){return i(n^(t|~s),e,t,r,o,a)}function l(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}Object.defineProperty(t,"__esModule",{value:!0}),t.md5=t.md5cycle=void 0,t.md5cycle=n;var c="0123456789abcdef".split("");function d(e){for(var t="",n=0;n<4;n++)t+=c[e>>8*n+4&15]+c[e>>8*n&15];return t}function u(e){return function(e){for(var t=0;t<e.length;t++)e[t]=d(e[t]);return e.join("")}(function(e){var t,i=e.length,s=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)n(s,l(e.substring(t-64,t)));e=e.substring(t-64);var r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<e.length;t++)r[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(n(s,r),t=0;t<16;t++)r[t]=0;return r[14]=8*i,n(s,r),s}(e))}function h(e,t){return e+t&4294967295}t.md5=u,u("hello")},128:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.reverseParsedPath=t.reverseJoinOn=t.getJoinHandlers=t.tryCatch=t.getKeys=t.isDefined=t.isObject=t.get=t.isEmpty=t.WAL=t.unpatchText=t.getTextPatch=t.stableStringify=t.includes=t.find=t.filter=t.omitKeys=t.pickKeys=t.asName=void 0;const i=n(899);function s(e,t=[],n=!1){let i=t;if(!i.length)return{};if(e&&i.length){let t={};return i.forEach((i=>{n&&void 0===e[i]||(t[i]=e[i])})),t}return e}function r(e,t){return s(e,c(e).filter((e=>!t.includes(e))))}function o(e,t){return e.filter((e=>Object.entries(t).every((([t,n])=>e[t]===n))))}function a(e){for(var t in e)return!1;return!0}function l(e){return null!=e}function c(e){return Object.keys(e)}t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},t.pickKeys=s,t.omitKeys=r,t.filter=o,t.find=function(e,t){return o(e,t)[0]},t.includes=function(e,t){return e.some((e=>e===t))},t.stableStringify=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var n,i="boolean"==typeof t.cycles&&t.cycles,s=t.cmp&&(n=t.cmp,function(e){return function(t,i){var s={key:t,value:e[t]},r={key:i,value:e[i]};return n(s,r)}}),r=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var n,o;if(Array.isArray(t)){for(o="[",n=0;n<t.length;n++)n&&(o+=","),o+=e(t[n])||"null";return o+"]"}if(null===t)return"null";if(-1!==r.indexOf(t)){if(i)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=r.push(t)-1,l=Object.keys(t).sort(s&&s(t));for(o="",n=0;n<l.length;n++){var c=l[n],d=e(t[c]);d&&(o&&(o+=","),o+=JSON.stringify(c)+":"+d)}return r.splice(a,1),"{"+o+"}"}}(e)},t.getTextPatch=function(e,t){if(!(e&&t&&e.trim().length&&t.trim().length))return t;if(e===t)return{from:0,to:0,text:"",md5:(0,i.md5)(t)};function n(n=1){let i=n<1?-1:0,s=!1;for(;!s&&Math.abs(i)<=t.length;){const r=n<1?[i]:[0,i];e.slice(...r)!==t.slice(...r)?s=!0:i+=1*Math.sign(n)}return i}let s=n()-1,r=e.length+n(-1)+1,o=t.length+n(-1)+1;return{from:s,to:r,text:t.slice(s,o),md5:(0,i.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:s,text:r,md5:o}=t;if(null===r||null===e)return r;let a=e.slice(0,n)+r+e.slice(s);if(o&&(0,i.md5)(a)!==o)throw"Patch text error: Could not match md5 hash: (original/result) \n"+e+"\n"+a;return a},t.WAL=class{constructor(e){if(this.changed={},this.sending={},this.sentHistory={},this.callbacks=[],this.sort=(e,t)=>{const{orderBy:n}=this.options;return n&&e&&t&&n.map((n=>{if(!(n.fieldName in e)||!(n.fieldName in t))throw"Replication error: \n some orderBy fields missing from data";let i=n.asc?e[n.fieldName]:t[n.fieldName],s=n.asc?t[n.fieldName]:e[n.fieldName],r=+i-+s,o=i<s?-1:i==s?0:1;return"number"===n.tsDataType&&Number.isFinite(r)?r:o})).find((e=>e))||0},this.isInHistory=e=>{if(!e)throw"Provide item";const t=e[this.options.synced_field];if(!Number.isFinite(+t))throw"Provided item Synced field value is missing/invalid ";const n=this.sentHistory[this.getIdStr(e)],i=n?.[this.options.synced_field];if(n){if(!Number.isFinite(+i))throw"Provided historic item Synced field value is missing/invalid";if(+i==+t)return!0}return!1},this.addData=e=>{a(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map((e=>{var t;const{initial:n,current:i,delta:s}={...e};if(!i)throw"Expecting { current: object, initial?: object }";const r=this.getIdStr(i);this.changed??(this.changed={}),(t=this.changed)[r]??(t[r]={initial:n,current:i,delta:s}),this.changed[r].current={...this.changed[r].current,...i},this.changed[r].delta={...this.changed[r].delta,...s}})),this.sendItems()},this.isOnSending=!1,this.isSendingTimeout=void 0,this.willDeleteHistory=void 0,this.sendItems=async()=>{const{DEBUG_MODE:e,onSend:t,onSendEnd:n,batch_size:i,throttle:s,historyAgeSeconds:r=2}=this.options;if(this.isSendingTimeout||this.sending&&!a(this.sending))return;if(!this.changed||a(this.changed))return;let o,l=[],c=[],d={};Object.keys(this.changed).sort(((e,t)=>this.sort(this.changed[e].current,this.changed[t].current))).slice(0,i).map((e=>{let t={...this.changed[e]};this.sending[e]={...t},c.push({...t}),d[e]={...t.current},delete this.changed[e]})),l=c.map((e=>{let t={};return Object.keys(e.current).map((n=>{const i=e.initial?.[n],s=e.current[n];var r,o;![this.options.synced_field,...this.options.id_fields].includes(n)&&((r=i)===(o=s)||(["number","string","boolean"].includes(typeof r)?r===o:JSON.stringify(r)===JSON.stringify(o)))||(t[n]=s)})),t})),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout((()=>{this.isSendingTimeout=void 0,a(this.changed)||this.sendItems()}),s)),this.isOnSending=!0;try{await t(l,c),r&&(this.sentHistory={...this.sentHistory,...d},this.willDeleteHistory||(this.willDeleteHistory=setTimeout((()=>{this.willDeleteHistory=void 0,this.sentHistory={}}),1e3*r)))}catch(e){o=e,console.error("WAL onSend failed:",e,l,c)}if(this.isOnSending=!1,this.callbacks.length){const e=Object.keys(this.sending);this.callbacks.forEach(((t,n)=>{t.idStrs=t.idStrs.filter((t=>e.includes(t))),t.idStrs.length||t.cb(o)})),this.callbacks=this.callbacks.filter((e=>e.idStrs.length))}this.sending={},e&&console.log(this.options.id," SENT lr->",l[l.length-1]),a(this.changed)?n&&n(l,c,o):this.sendItems()},this.options={...e},!this.options.orderBy){const{synced_field:t,id_fields:n}=e;this.options.orderBy=[t,...n.sort()].map((e=>({fieldName:e,tsDataType:e===t?"number":"string",asc:!0})))}}isSending(){const e=this.isOnSending||!(a(this.sending)&&a(this.changed));return this.options.DEBUG_MODE&&console.log(this.options.id," CHECKING isSending ->",e),e}getIdStr(e){return this.options.id_fields.sort().map((t=>`${e[t]||""}`)).join(".")}getIdObj(e){let t={};return this.options.id_fields.sort().map((n=>{t[n]=e[n]})),t}getDeltaObj(e){let t={};return Object.keys(e).map((n=>{this.options.id_fields.includes(n)||(t[n]=e[n])})),t}},t.isEmpty=a,t.get=function(e,t){let n=t,i=e;return e?("string"==typeof n&&(n=n.split(".")),n.reduce(((e,t)=>e&&e[t]?e[t]:void 0),i)):e},t.isObject=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},t.isDefined=l,t.getKeys=c,t.tryCatch=async e=>{const t=Date.now();try{return{...await e(),duration:Date.now()-t}}catch(e){return{error:e,duration:Date.now()-t}}},t.getJoinHandlers=e=>{const t=(t,n)=>(n,i,s={})=>({[t?"$leftJoin":"$innerJoin"]:s.path??e,filter:n,...r(s,["path","select"]),select:i});return{innerJoin:t(!1),leftJoin:t(!0),innerJoinOne:t(!1),leftJoinOne:t(!0)}},t.reverseJoinOn=e=>e.map((e=>Object.fromEntries(Object.entries(e).map((([e,t])=>[t,e]))))),t.reverseParsedPath=(e,n)=>{const i=[{table:n,on:[{}]},...e??[]];return i.map(((e,n)=>{const s=i[n+1];if(s)return{table:e.table,on:(0,t.reverseJoinOn)(s.on)}})).filter(l).reverse()}}},t={};return function n(i){var s=t[i];if(void 0!==s)return s.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}(590)})(),e.exports=t()}},t={};function n(i){var s=t[i];if(void 0!==s)return s.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}var i={};return(()=>{"use strict";var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.prostgles=void 0;const t=n(274),s=n(133);e.prostgles=function(e){return(0,t.prostgles)(e,s.SyncedTable)}})(),i})()));
|
package/dist/index.no-sync.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!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 i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this||window,(()=>{return e={274:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prostgles=t.asName=t.debug=void 0;const i=n(792);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return i.asName}});const r="DEBUG_SYNCEDTABLE",o="undefined"!=typeof window;t.debug=function(...e){o&&window[r]&&window[r](...e)},t.prostgles=function(e,n){const{socket:r,onReady:a,onDisconnect:l,onReconnect:c,onSchemaChange:u=!0,onReload:p,onDebug:d}=e;if((0,t.debug)("prostgles",{initOpts:e}),u){let e;"function"==typeof u&&(e=u),r.removeAllListeners(i.CHANNELS.SCHEMA_CHANGED),e&&r.on(i.CHANNELS.SCHEMA_CHANGED,e)}const m=i.CHANNELS._preffix;let f,h={},g={},y={},b={},v=!1;function O(e,n,i){return(0,t.debug)("_unsubscribe",{channelName:e,handler:i}),new Promise(((t,o)=>{h[e]?(h[e].handlers=h[e].handlers.filter((e=>e!==i)),h[e].handlers.length||(r.emit(n,{},((e,t)=>{e&&console.error(e)})),r.removeListener(e,h[e].onCall),delete h[e]),t(!0)):t(!0)}))}function N({tableName:e,command:t,param1:n,param2:i},o){return new Promise(((s,a)=>{r.emit(m,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{if(e)console.error(e),a(e);else if(t){const{id_fields:e,synced_field:n,channelName:i}=t;r.emit(i,{onSyncRequest:o({})},(e=>{console.log(e)})),s({id_fields:e,synced_field:n,channelName:i})}}))}))}function _({tableName:e,command:t,param1:n,param2:i}){return new Promise(((o,s)=>{r.emit(m,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{e?(console.error(e),s(e)):t&&o(t)}))}))}const S=new s((async function({tableName:e,command:n,param1:i,param2:o},s){const{onPullRequest:a,onSyncRequest:l,onUpdates:c}=s;function u(e){return Object.freeze({unsync:function(){!function(e,n){(0,t.debug)("_unsync",{channelName:e,triggers:n}),new Promise(((t,i)=>{y[e]&&(y[e].triggers=y[e].triggers.filter((e=>e.onPullRequest!==n.onPullRequest&&e.onSyncRequest!==n.onSyncRequest&&e.onUpdates!==n.onUpdates)),y[e].triggers.length||(r.emit(e+"unsync",{},((e,n)=>{e?i(e):t(n)})),r.removeListener(e,y[e].onCall),delete y[e]))}))}(e,s)},syncData:function(t,n,i){r.emit(e,{onSyncRequest:{...l({}),...{data:t}||{},...{deleted:n}||{}}},i?e=>{i(e)}:null)}})}const p=Object.keys(y).find((t=>{let r=y[t];return r&&r.tableName===e&&r.command===n&&JSON.stringify(r.param1||{})===JSON.stringify(i||{})&&JSON.stringify(r.param2||{})===JSON.stringify(o||{})}));if(p)return y[p].triggers.push(s),u(p);{const d=await N({tableName:e,command:n,param1:i,param2:o},l),{channelName:m,synced_field:f,id_fields:h}=d;function g(t,n){t&&y[m]&&y[m].triggers.map((({onUpdates:i,onSyncRequest:r,onPullRequest:o})=>{t.data?Promise.resolve(i(t)).then((()=>{n&&n({ok:!0})})).catch((t=>{n?n({err:t}):console.error(e+" onUpdates error",t)})):t.onSyncRequest?Promise.resolve(r(t.onSyncRequest)).then((e=>n({onSyncRequest:e}))).catch((t=>{n?n({err:t}):console.error(e+" onSyncRequest error",t)})):t.onPullRequest?Promise.resolve(o(t.onPullRequest)).then((e=>{n({data:e})})).catch((t=>{n?n({err:t}):console.error(e+" onPullRequest error",t)})):console.log("unexpected response")}))}return y[m]={tableName:e,command:n,param1:i,param2:o,triggers:[s],syncInfo:d,onCall:g},r.on(m,g),u(m)}}),(([{tableName:e}])=>e)),x=new s((async function(e,{tableName:t,command:n,param1:i,param2:o},s,a){function l(n,r){let o={unsubscribe:function(){return O(n,r,s)},filter:{...i}};return e[t].update&&(o={...o,update:function(n,r){return e[t].update(i,n,r)}}),e[t].delete&&(o={...o,delete:function(n){return e[t].delete(i,n)}}),Object.freeze(o)}const c=Object.entries(h).find((([e])=>{let r=h[e];return r&&r.tableName===t&&r.command===n&&JSON.stringify(r.param1||{})===JSON.stringify(i||{})&&JSON.stringify(r.param2||{})===JSON.stringify(o||{})}));if(c){const e=c[0];return c[1].handlers.push(s),c[1].errorHandlers.push(a),setTimeout((()=>{var t,n;s&&(null===(t=null==h?void 0:h[e])||void 0===t?void 0:t.lastData)&&s(null===(n=null==h?void 0:h[e])||void 0===n?void 0:n.lastData)}),10),l(e,c[1].unsubChannel)}const{channelName:u,channelNameReady:p,channelNameUnsubscribe:d}=await _({tableName:t,command:n,param1:i,param2:o}),m=function(e,t){const n=h[u];n?e.data?(n.lastData=e.data,n.handlers.forEach((t=>{t(e.data)}))):e.err?n.errorHandlers.forEach((t=>{null==t||t(e.err)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",e):console.warn("Orphaned subscription: ",u)},f=a||function(e){console.error(`Uncaught error within running subscription \n ${u}`,e)};return r.on(u,m),h[u]={lastData:void 0,tableName:t,command:n,param1:i,param2:o,onCall:m,unsubChannel:d,handlers:[s],errorHandlers:[f],destroy:()=>{h[u]&&(Object.values(h[u]).map((e=>{e&&e.handlers&&e.handlers.map((e=>O(u,d,e)))})),delete h[u])}},r.emit(p,{now:Date.now()}),l(u,d)}),(([e,{tableName:t}])=>t));async function E(e,t,n,i){return x.run([e,t,n,i])}return new Promise(((e,s)=>{r.removeAllListeners(i.CHANNELS.CONNECTION),r.on(i.CHANNELS.CONNECTION,(e=>(s(e),"ok"))),l&&r.on("disconnect",l),r.on(i.CHANNELS.SCHEMA,(({schema:l,methods:u,tableSchema:O,auth:x,rawSQL:w,joinTables:T=[],err:j})=>{if((0,t.debug)("destroySyncs",{subscriptions:h,syncedTables:g}),Object.values(h).map((e=>e.destroy())),h={},y={},Object.values(g).map((e=>{e&&e.destroy&&e.destroy()})),g={},v&&c&&(c(r,j),j))return void console.error(j);if(j)throw s(j),j;v=!0;let C=JSON.parse(JSON.stringify(l)),P=JSON.parse(JSON.stringify(u)),J={},A={};if(x){if(x.pathGuard&&o){const e=e=>{var t,n;(null==e?void 0:e.shouldReload)&&(p?p():"undefined"!=typeof window&&(null===(n=null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.reload)||void 0===n||n.call(t)))};r.emit(i.CHANNELS.AUTHGUARD,JSON.stringify(window.location),((t,n)=>{e(n)})),r.removeAllListeners(i.CHANNELS.AUTHGUARD),r.on(i.CHANNELS.AUTHGUARD,(t=>{e(t)}))}A={...x},[i.CHANNELS.LOGIN,i.CHANNELS.LOGOUT,i.CHANNELS.REGISTER].map((e=>{x[e]&&(A[e]=function(t){return new Promise(((n,i)=>{r.emit(m+e,t,((e,t)=>{e?i(e):n(t)}))}))})}))}P.map((e=>{const t="string"==typeof e,n=t?e:e.name,o=async function(...e){return await(null==d?void 0:d({type:"method",command:n,data:{params:e}})),new Promise(((t,o)=>{r.emit(i.CHANNELS.METHOD,{method:n,params:e},((e,n)=>{e?o(e):t(n)}))}))};J[n]=t?o:{...e,run:o}})),J=Object.freeze(J),w&&(C.sql=function(e,t,n){return new Promise(((o,s)=>{r.emit(i.CHANNELS.SQL,{query:e,params:t,options:n},((e,t)=>{if(e)s(e);else if(n&&"noticeSubscription"===n.returnType&&t&&Object.keys(t).sort().join()===["socketChannel","socketUnsubChannel"].sort().join()&&!Object.values(t).find((e=>"string"!=typeof e))){const e=t,n=t=>(((e,t)=>{f=f||{config:t,listeners:[]},f.listeners.length||(r.removeAllListeners(t.socketChannel),r.on(t.socketChannel,(e=>{f&&f.listeners&&f.listeners.length?f.listeners.map((t=>{t(e)})):r.emit(t.socketUnsubChannel,{})}))),f.listeners.push(e)})(t,e),{...e,removeListener:()=>(e=>{f&&(f.listeners=f.listeners.filter((t=>t!==e)),!f.listeners.length&&f.config&&f.config.socketUnsubChannel&&r&&r.emit(f.config.socketUnsubChannel,{}))})(t)}),i={...e,addListener:n};o(i)}else if(n&&n.returnType&&"statement"===n.returnType||!t||Object.keys(t).sort().join()!==["socketChannel","socketUnsubChannel","notifChannel"].sort().join()||Object.values(t).find((e=>"string"!=typeof e)))o(t);else{const e=e=>(((e,t)=>{var n;b=b||{},b[t.notifChannel]?null===(n=b[t.notifChannel])||void 0===n||n.listeners.push(e):(b[t.notifChannel]={config:t,listeners:[e]},r.removeAllListeners(t.socketChannel),r.on(t.socketChannel,(e=>{var n,i;(null===(n=b[t.notifChannel])||void 0===n?void 0:n.listeners.length)?b[t.notifChannel].listeners.map((t=>{t(e)})):r.emit(null===(i=b[t.notifChannel])||void 0===i?void 0:i.config.socketUnsubChannel,{})})))})(e,t),{...t,removeListener:()=>((e,t)=>{const n=b[t.notifChannel];n&&(n.listeners=n.listeners.filter((t=>t!==e)),!n.listeners.length&&n.config&&n.config.socketUnsubChannel&&r&&(r.emit(n.config.socketUnsubChannel,{}),delete b[t.notifChannel]))})(e,t)}),n={...t,addListener:e};o(n)}}))}))});const D=e=>"[object Object]"===Object.prototype.toString.call(e),k=(e,t,n,i)=>{if(!D(e)||!D(t)||"function"!=typeof n||i&&"function"!=typeof i)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},R=["subscribe","subscribeOne"];(0,i.getKeys)(C).forEach((e=>{Object.keys(C[e]).sort(((e,t)=>R.includes(e)-R.includes(t))).forEach((t=>{if(["find","findOne"].includes(t)&&(C[e].getJoinedTables=function(){return(T||[]).filter((t=>Array.isArray(t)&&t.includes(e))).flat().filter((t=>t!==e))}),"sync"===t){if(C[e]._syncInfo={...C[e][t]},n){C[e].getSync=async(t,i={})=>(await(null==d?void 0:d({type:"table",command:"getSync",tableName:e,data:{filter:t,params:i}})),n.create({name:e,onDebug:d,filter:t,db:C,...i}));const t=async(t={},i={},r)=>{const o=`${e}.${JSON.stringify(t)}.${JSON.stringify(i)}`;return g[o]||(g[o]=await n.create({...i,onDebug:d,name:e,filter:t,db:C,onError:r})),g[o]};C[e].sync=async(n,i={handlesOnData:!0,select:"*"},r,o)=>{await(null==d?void 0:d({type:"table",command:"sync",tableName:e,data:{basicFilter:n,options:i}})),k(n,i,r,o);const s=await t(n,i,o);return await s.sync(r,i.handlesOnData)},C[e].syncOne=async(n,i={handlesOnData:!0},r,o)=>{await(null==d?void 0:d({type:"table",command:"syncOne",tableName:e,data:{basicFilter:n,options:i}})),k(n,i,r,o);const s=await t(n,i,o);return await s.syncOne(n,r,i.handlesOnData)}}C[e]._sync=async function(n,i,r){return await(null==d?void 0:d({type:"table",command:"_sync",tableName:e,data:{param1:n,param2:i,syncHandles:r}})),async function(e,t){return S.run([e,t])}({tableName:e,command:t,param1:n,param2:i},r)}}else if(R.includes(t)){const n=async function(n,i,r,o){return await(null==d?void 0:d({type:"table",command:t,tableName:e,data:{param1:n,param2:i,onChange:r,onError:o}})),k(n,i,r,o),E(C,{tableName:e,command:t,param1:n,param2:i},r,o)};C[e][t]=n;const i="subscribeOne";C[e][t+"Hook"]=function(e={},r={},o){return{start:s=>n(e,r,t!==i?s:e=>{s(e[0])},o),args:[e,r,o]}},t!==i&&R.includes(i)||(C[e][i]=async function(n,i,r,o){return await(null==d?void 0:d({type:"table",command:"getSync",tableName:e,data:{param1:n,param2:i,onChange:r,onError:o}})),k(n,i,r,o),E(C,{tableName:e,command:t,param1:n,param2:i},(e=>{r(e[0])}),o)})}else C[e][t]=async function(n,i,o){return await(null==d?void 0:d({type:"table",command:t,tableName:e,data:{param1:n,param2:i,param3:o}})),new Promise(((s,a)=>{r.emit(m,{tableName:e,command:t,param1:n,param2:i,param3:o},((e,t)=>{e?a(e):s(t)}))}))}}))})),h&&Object.keys(h).length&&Object.keys(h).map((async e=>{try{let t=h[e];await _(t),r.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting old subscriptions",e)}})),y&&Object.keys(y).length&&(0,i.getKeys)(y).filter((e=>{var t;return null===(t=y[e])||void 0===t?void 0:t.triggers.length})).map((async e=>{try{let t=y[e];await N(t,t.triggers[0].onSyncRequest),r.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}})),T.flat().map((e=>{C.innerJoin=C.innerJoin||{},C.leftJoin=C.leftJoin||{},C.innerJoinOne=C.innerJoinOne||{},C.leftJoinOne=C.leftJoinOne||{};const t=(0,i.getJoinHandlers)(e);C.leftJoin[e]=t.leftJoin,C.innerJoin[e]=t.innerJoin,C.leftJoinOne[e]=t.leftJoinOne,C.innerJoinOne[e]=t.innerJoinOne})),(async()=>{try{await a(C,J,O,A,v)}catch(e){console.error("Prostgles: Error within onReady: \n",e),s(e)}e(C)})()}))}))};class s{constructor(e,t){this.queue=[],this.isRunning=!1,this.func=e,this.groupBy=t}async run(e){const t=new Promise(((t,n)=>{const i={arguments:e,onResult:t,onFail:n};this.queue.push(i)})),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,i)=>{const r=this.groupBy(e.arguments);t.includes(r)||(t.push(r),n.push({index:i,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}}},792:function(e){var t;this||window,t=()=>(()=>{"use strict";var e={31:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=void 0,t.CONTENT_TYPE_TO_EXT={"text/html":["html","htm","shtml"],"text/css":["css"],"text/csv":["csv"],"text/tsv":["tsv"],"text/xml":["xml"],"text/mathml":["mml"],"text/plain":["txt"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/x-component":["htc"],"image/gif":["gif"],"image/jpeg":["jpeg","jpg"],"image/png":["png"],"image/tiff":["tif","tiff"],"image/vnd.wap.wbmp":["wbmp"],"image/x-icon":["ico"],"image/x-jng":["jng"],"image/x-ms-bmp":["bmp"],"image/svg+xml":["svg"],"image/webp":["webp"],"application/sql":["sql"],"application/x-javascript":["js"],"application/atom+xml":["atom"],"application/rss+xml":["rss"],"application/java-archive":["jar","war","ear"],"application/mac-binhex40":["hqx"],"application/msword":["doc","docx"],"application/pdf":["pdf"],"application/postscript":["ps","eps","ai"],"application/rtf":["rtf"],"application/vnd.ms-excel":["xls","xlsx"],"application/vnd.ms-powerpoint":["ppt","pptx"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/x-7z-compressed":["7z"],"application/x-cocoa":["cco"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-makeself":["run"],"application/x-perl":["pl","pm"],"application/x-pilot":["prc","pdb"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-sea":["sea"],"application/x-shockwave-flash":["swf"],"application/x-stuffit":["sit"],"application/x-tcl":["tcl","tk"],"application/x-x509-ca-cert":["der","pem","crt"],"application/x-xpinstall":["xpi"],"application/xhtml+xml":["xhtml"],"application/zip":["zip"],"application/octet-stream":["bin","exe","dll","deb","dmg","eot","iso","img","msi","msp","msm"],"audio/midi":["mid","midi","kar"],"audio/mpeg":["mp3"],"audio/ogg":["ogg"],"audio/x-realaudio":["ra"],"video/3gpp":["3gpp","3gp"],"video/mpeg":["mpeg","mpg"],"video/quicktime":["mov"],"video/x-flv":["flv"],"video/x-mng":["mng"],"video/x-ms-asf":["asx","asf"],"video/x-ms-wmv":["wmv"],"video/x-msvideo":["avi"],"video/mp4":["m4v","mp4"],"video/webm":["webm"]}},444:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.COMPLEX_FILTER_KEY=t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.ArrayFilterOperands=t.TextFilter_FullTextSearchFilterKeys=t.TextFilterFTSKeys=t.TextFilterKeys=t.JsonbFilterKeys=t.JsonbOperands=t.CompareInFilterKeys=t.CompareFilterKeys=void 0;const i=n(128);t.CompareFilterKeys=["=","$eq","<>",">","<",">=","<=","$eq","$ne","$gt","$gte","$lte"],t.CompareInFilterKeys=["$in","$nin"],t.JsonbOperands={"@>":{Operator:"@>","Right Operand Type":"jsonb",Description:"Does the left JSON value contain the right JSON path/value entries at the top level?",Example:'\'{"a":1, "b":2}\'::jsonb @> \'{"b":2}\'::jsonb'},"<@":{Operator:"<@","Right Operand Type":"jsonb",Description:"Are the left JSON path/value entries contained at the top level within the right JSON value?",Example:'\'{"b":2}\'::jsonb <@ \'{"a":1, "b":2}\'::jsonb'},"?":{Operator:"?","Right Operand Type":"text",Description:"Does the string exist as a top-level key within the JSON value?",Example:"'{\"a\":1, \"b\":2}'::jsonb ? 'b'"},"?|":{Operator:"?|","Right Operand Type":"text[]",Description:"Do any of these array strings exist as top-level keys?",Example:"'{\"a\":1, \"b\":2, \"c\":3}'::jsonb ?| array['b', 'c']"},"?&":{Operator:"?&","Right Operand Type":"text[]",Description:"Do all of these array strings exist as top-level keys?",Example:"'[\"a\", \"b\"]'::jsonb ?& array['a', 'b']"},"||":{Operator:"||","Right Operand Type":"jsonb",Description:"Concatenate two jsonb values into a new jsonb value",Example:'\'["a", "b"]\'::jsonb || \'["c", "d"]\'::jsonb'},"-":{Operator:"-","Right Operand Type":"integer",Description:"Delete the array element with specified index (Negative integers count from the end). Throws an error if top level container is not an array.",Example:'\'["a", "b"]\'::jsonb - 1'},"#-":{Operator:"#-","Right Operand Type":"text[]",Description:"Delete the field or element with specified path (for JSON arrays, negative integers count from the end)",Example:"'[\"a\", {\"b\":1}]'::jsonb #- '{1,b}'"},"@?":{Operator:"@?","Right Operand Type":"jsonpath",Description:"Does JSON path return any item for the specified JSON value?",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)'"},"@@":{Operator:"@@","Right Operand Type":"jsonpath",Description:"Returns the result of JSON path predicate check for the specified JSON value. Only the first item of the result is taken into account. If the result is not Boolean, then null is returned.",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @@ '$.a[*] > 2'"}},t.JsonbFilterKeys=(0,i.getKeys)(t.JsonbOperands),t.TextFilterKeys=["$ilike","$like","$nilike","$nlike"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.ArrayFilterOperands=["@>","<@","=","$eq","$contains","$containedBy","&&","$overlaps"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"],t.GeomFilter_Funcs=["ST_MakeEnvelope","st_makeenvelope","ST_MakePolygon","st_makepolygon"],t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"],t.COMPLEX_FILTER_KEY="$filter"},590:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=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,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=t.RULE_METHODS=t.CHANNELS=t.JOIN_PARAMS=t.JOIN_KEYS=t.TS_PG_Types=t._PG_geometric=t._PG_postgis=t._PG_interval=t._PG_date=t._PG_bool=t._PG_json=t._PG_numbers=t._PG_strings=void 0,t._PG_strings=["bpchar","char","varchar","text","citext","uuid","bytea","time","timetz","interval","name","cidr","inet","macaddr","macaddr8","int4range","int8range","numrange","tsvector"],t._PG_numbers=["int2","int4","int8","float4","float8","numeric","money","oid"],t._PG_json=["json","jsonb"],t._PG_bool=["bool"],t._PG_date=["date","timestamp","timestamptz"],t._PG_interval=["interval"],t._PG_postgis=["geometry","geography"],t._PG_geometric=["point","line","lseg","box","path","polygon","circle"];const o={string:[...t._PG_strings,...t._PG_date,...t._PG_geometric,...t._PG_postgis,"lseg"],number:t._PG_numbers,boolean:t._PG_bool,any:[...t._PG_json,...t._PG_interval]};t.TS_PG_Types={...o,"number[]":o.number.map((e=>`_${e}`)),"boolean[]":o.boolean.map((e=>`_${e}`)),"string[]":o.string.map((e=>`_${e}`)),"any[]":o.any.map((e=>`_${e}`))},t.JOIN_KEYS=["$innerJoin","$leftJoin"],t.JOIN_PARAMS=["select","filter","$path","$condition","offset","limit","orderBy"];const s="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:s+"schema-changed",SCHEMA:s+"schema",DEFAULT:s,SQL:`${s}sql`,METHOD:`${s}method`,NOTICE_EV:`${s}notice`,LISTEN_EV:`${s}listen`,REGISTER:`${s}register`,LOGIN:`${s}login`,LOGOUT:`${s}logout`,AUTHGUARD:`${s}authguard`,CONNECTION:`${s}connection`,_preffix:s},t.RULE_METHODS={getColumns:["getColumns"],getInfo:["getInfo"],insert:["insert","upsert"],update:["update","upsert","updateBatch"],select:["findOne","find","count","size"],delete:["delete","remove"],sync:["sync","unsync"],subscribe:["unsubscribe","subscribe","subscribeOne"]},r(n(128),t),r(n(444),t);var a=n(31);Object.defineProperty(t,"CONTENT_TYPE_TO_EXT",{enumerable:!0,get:function(){return a.CONTENT_TYPE_TO_EXT}}),r(n(929),t)},929:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBSchemaAsJSONSchema=t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=void 0;const i=n(128);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 r=(e,t)=>{const{type:n,arrayOf:o,arrayOfType:s,description:a,nullable:l,oneOf:c,oneOfType:u,title:p,record:d,...m}="string"==typeof e?{type:e}:e;let f={};const h={...(m.enum||m.allowedValues?.length)&&{enum:m.allowedValues?.slice(0)??m.enum.slice(0)},...!!a&&{description:a},...!!p&&{title:p}};if(m.enum?.length&&(h.type=typeof m.enum[0]),"string"==typeof n||o||s){if(n&&"string"!=typeof n)throw"Not expected";f=o||s||n?.endsWith("[]")?{type:"array",items:o||s?r(o||{type:s}):n?.startsWith("any")?{type:void 0}:{type:n?.slice(0,-2),...m.allowedValues&&{enum:m.allowedValues.slice(0)}}}:{type:n}}else(0,i.isObject)(n)?f={type:"object",required:(0,i.getKeys)(n).filter((e=>{const t=n[e];return"string"==typeof t||!t.optional})),properties:(0,i.getKeys)(n).reduce(((e,t)=>({...e,[t]:r(n[t])})),{})}:c||u?f={oneOf:(c||u.map((e=>({type:e})))).map((e=>r(e)))}:d&&(f={type:"object",...d.values&&!d.keysEnum&&{additionalProperties:r(d.values)},...d.keysEnum&&{properties:d.keysEnum.reduce(((e,t)=>({...e,[t]:d.values?r(d.values):{type:{}}})),{})}});if(l){const e={type:"null"};f.oneOf?f.oneOf.push(e):f.enum&&!f.enum.includes(null)?f.enum.push(null):f={oneOf:[f,e]}}return{...t?{$id:t?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...h,...f}};t.getJSONBSchemaAsJSONSchema=function(e,t,n){return r(n,{id:`${e}.${t}`})}},899:(e,t)=>{function n(e,t){var n=e[0],i=e[1],l=e[2],c=e[3];n=r(n,i,l,c,t[0],7,-680876936),c=r(c,n,i,l,t[1],12,-389564586),l=r(l,c,n,i,t[2],17,606105819),i=r(i,l,c,n,t[3],22,-1044525330),n=r(n,i,l,c,t[4],7,-176418897),c=r(c,n,i,l,t[5],12,1200080426),l=r(l,c,n,i,t[6],17,-1473231341),i=r(i,l,c,n,t[7],22,-45705983),n=r(n,i,l,c,t[8],7,1770035416),c=r(c,n,i,l,t[9],12,-1958414417),l=r(l,c,n,i,t[10],17,-42063),i=r(i,l,c,n,t[11],22,-1990404162),n=r(n,i,l,c,t[12],7,1804603682),c=r(c,n,i,l,t[13],12,-40341101),l=r(l,c,n,i,t[14],17,-1502002290),n=o(n,i=r(i,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=o(c,n,i,l,t[6],9,-1069501632),l=o(l,c,n,i,t[11],14,643717713),i=o(i,l,c,n,t[0],20,-373897302),n=o(n,i,l,c,t[5],5,-701558691),c=o(c,n,i,l,t[10],9,38016083),l=o(l,c,n,i,t[15],14,-660478335),i=o(i,l,c,n,t[4],20,-405537848),n=o(n,i,l,c,t[9],5,568446438),c=o(c,n,i,l,t[14],9,-1019803690),l=o(l,c,n,i,t[3],14,-187363961),i=o(i,l,c,n,t[8],20,1163531501),n=o(n,i,l,c,t[13],5,-1444681467),c=o(c,n,i,l,t[2],9,-51403784),l=o(l,c,n,i,t[7],14,1735328473),n=s(n,i=o(i,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=s(c,n,i,l,t[8],11,-2022574463),l=s(l,c,n,i,t[11],16,1839030562),i=s(i,l,c,n,t[14],23,-35309556),n=s(n,i,l,c,t[1],4,-1530992060),c=s(c,n,i,l,t[4],11,1272893353),l=s(l,c,n,i,t[7],16,-155497632),i=s(i,l,c,n,t[10],23,-1094730640),n=s(n,i,l,c,t[13],4,681279174),c=s(c,n,i,l,t[0],11,-358537222),l=s(l,c,n,i,t[3],16,-722521979),i=s(i,l,c,n,t[6],23,76029189),n=s(n,i,l,c,t[9],4,-640364487),c=s(c,n,i,l,t[12],11,-421815835),l=s(l,c,n,i,t[15],16,530742520),n=a(n,i=s(i,l,c,n,t[2],23,-995338651),l,c,t[0],6,-198630844),c=a(c,n,i,l,t[7],10,1126891415),l=a(l,c,n,i,t[14],15,-1416354905),i=a(i,l,c,n,t[5],21,-57434055),n=a(n,i,l,c,t[12],6,1700485571),c=a(c,n,i,l,t[3],10,-1894986606),l=a(l,c,n,i,t[10],15,-1051523),i=a(i,l,c,n,t[1],21,-2054922799),n=a(n,i,l,c,t[8],6,1873313359),c=a(c,n,i,l,t[15],10,-30611744),l=a(l,c,n,i,t[6],15,-1560198380),i=a(i,l,c,n,t[13],21,1309151649),n=a(n,i,l,c,t[4],6,-145523070),c=a(c,n,i,l,t[11],10,-1120210379),l=a(l,c,n,i,t[2],15,718787259),i=a(i,l,c,n,t[9],21,-343485551),e[0]=d(n,e[0]),e[1]=d(i,e[1]),e[2]=d(l,e[2]),e[3]=d(c,e[3])}function i(e,t,n,i,r,o){return t=d(d(t,e),d(i,o)),d(t<<r|t>>>32-r,n)}function r(e,t,n,r,o,s,a){return i(t&n|~t&r,e,t,o,s,a)}function o(e,t,n,r,o,s,a){return i(t&r|n&~r,e,t,o,s,a)}function s(e,t,n,r,o,s,a){return i(t^n^r,e,t,o,s,a)}function a(e,t,n,r,o,s,a){return i(n^(t|~r),e,t,o,s,a)}function l(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}Object.defineProperty(t,"__esModule",{value:!0}),t.md5=t.md5cycle=void 0,t.md5cycle=n;var c="0123456789abcdef".split("");function u(e){for(var t="",n=0;n<4;n++)t+=c[e>>8*n+4&15]+c[e>>8*n&15];return t}function p(e){return function(e){for(var t=0;t<e.length;t++)e[t]=u(e[t]);return e.join("")}(function(e){var t,i=e.length,r=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)n(r,l(e.substring(t-64,t)));e=e.substring(t-64);var o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<e.length;t++)o[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(n(r,o),t=0;t<16;t++)o[t]=0;return o[14]=8*i,n(r,o),r}(e))}function d(e,t){return e+t&4294967295}t.md5=p,p("hello")},128:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJoinHandlers=t.tryCatch=t.getKeys=t.isDefined=t.isObject=t.get=t.isEmpty=t.WAL=t.unpatchText=t.getTextPatch=t.stableStringify=t.includes=t.find=t.filter=t.omitKeys=t.pickKeys=t.asName=void 0;const i=n(899);function r(e,t=[],n=!1){let i=t;if(!i.length)return{};if(e&&i.length){let t={};return i.forEach((i=>{n&&void 0===e[i]||(t[i]=e[i])})),t}return e}function o(e,t){return r(e,l(e).filter((e=>!t.includes(e))))}function s(e,t){return e.filter((e=>Object.entries(t).every((([t,n])=>e[t]===n))))}function a(e){for(var t in e)return!1;return!0}function l(e){return Object.keys(e)}t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},t.pickKeys=r,t.omitKeys=o,t.filter=s,t.find=function(e,t){return s(e,t)[0]},t.includes=function(e,t){return e.some((e=>e===t))},t.stableStringify=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var n,i="boolean"==typeof t.cycles&&t.cycles,r=t.cmp&&(n=t.cmp,function(e){return function(t,i){var r={key:t,value:e[t]},o={key:i,value:e[i]};return n(r,o)}}),o=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var n,s;if(Array.isArray(t)){for(s="[",n=0;n<t.length;n++)n&&(s+=","),s+=e(t[n])||"null";return s+"]"}if(null===t)return"null";if(-1!==o.indexOf(t)){if(i)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=o.push(t)-1,l=Object.keys(t).sort(r&&r(t));for(s="",n=0;n<l.length;n++){var c=l[n],u=e(t[c]);u&&(s&&(s+=","),s+=JSON.stringify(c)+":"+u)}return o.splice(a,1),"{"+s+"}"}}(e)},t.getTextPatch=function(e,t){if(!(e&&t&&e.trim().length&&t.trim().length))return t;if(e===t)return{from:0,to:0,text:"",md5:(0,i.md5)(t)};function n(n=1){let i=n<1?-1:0,r=!1;for(;!r&&Math.abs(i)<=t.length;){const o=n<1?[i]:[0,i];e.slice(...o)!==t.slice(...o)?r=!0:i+=1*Math.sign(n)}return i}let r=n()-1,o=e.length+n(-1)+1,s=t.length+n(-1)+1;return{from:r,to:o,text:t.slice(r,s),md5:(0,i.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:r,text:o,md5:s}=t;if(null===o||null===e)return o;let a=e.slice(0,n)+o+e.slice(r);if(s&&(0,i.md5)(a)!==s)throw"Patch text error: Could not match md5 hash: (original/result) \n"+e+"\n"+a;return a},t.WAL=class{constructor(e){if(this.changed={},this.sending={},this.sentHistory={},this.callbacks=[],this.sort=(e,t)=>{const{orderBy:n}=this.options;return n&&e&&t&&n.map((n=>{if(!(n.fieldName in e)||!(n.fieldName in t))throw"Replication error: \n some orderBy fields missing from data";let i=n.asc?e[n.fieldName]:t[n.fieldName],r=n.asc?t[n.fieldName]:e[n.fieldName],o=+i-+r,s=i<r?-1:i==r?0:1;return"number"===n.tsDataType&&Number.isFinite(o)?o:s})).find((e=>e))||0},this.isInHistory=e=>{if(!e)throw"Provide item";const t=e[this.options.synced_field];if(!Number.isFinite(+t))throw"Provided item Synced field value is missing/invalid ";const n=this.sentHistory[this.getIdStr(e)],i=n?.[this.options.synced_field];if(n){if(!Number.isFinite(+i))throw"Provided historic item Synced field value is missing/invalid";if(+i==+t)return!0}return!1},this.addData=e=>{a(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map((e=>{var t;const{initial:n,current:i,delta:r}={...e};if(!i)throw"Expecting { current: object, initial?: object }";const o=this.getIdStr(i);this.changed??(this.changed={}),(t=this.changed)[o]??(t[o]={initial:n,current:i,delta:r}),this.changed[o].current={...this.changed[o].current,...i},this.changed[o].delta={...this.changed[o].delta,...r}})),this.sendItems()},this.isOnSending=!1,this.isSendingTimeout=void 0,this.willDeleteHistory=void 0,this.sendItems=async()=>{const{DEBUG_MODE:e,onSend:t,onSendEnd:n,batch_size:i,throttle:r,historyAgeSeconds:o=2}=this.options;if(this.isSendingTimeout||this.sending&&!a(this.sending))return;if(!this.changed||a(this.changed))return;let s,l=[],c=[],u={};Object.keys(this.changed).sort(((e,t)=>this.sort(this.changed[e].current,this.changed[t].current))).slice(0,i).map((e=>{let t={...this.changed[e]};this.sending[e]={...t},c.push({...t}),u[e]={...t.current},delete this.changed[e]})),l=c.map((e=>{let t={};return Object.keys(e.current).map((n=>{const i=e.initial?.[n],r=e.current[n];var o,s;![this.options.synced_field,...this.options.id_fields].includes(n)&&((o=i)===(s=r)||(["number","string","boolean"].includes(typeof o)?o===s:JSON.stringify(o)===JSON.stringify(s)))||(t[n]=r)})),t})),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout((()=>{this.isSendingTimeout=void 0,a(this.changed)||this.sendItems()}),r)),this.isOnSending=!0;try{await t(l,c),o&&(this.sentHistory={...this.sentHistory,...u},this.willDeleteHistory||(this.willDeleteHistory=setTimeout((()=>{this.willDeleteHistory=void 0,this.sentHistory={}}),1e3*o)))}catch(e){s=e,console.error("WAL onSend failed:",e,l,c)}if(this.isOnSending=!1,this.callbacks.length){const e=Object.keys(this.sending);this.callbacks.forEach(((t,n)=>{t.idStrs=t.idStrs.filter((t=>e.includes(t))),t.idStrs.length||t.cb(s)})),this.callbacks=this.callbacks.filter((e=>e.idStrs.length))}this.sending={},e&&console.log(this.options.id," SENT lr->",l[l.length-1]),a(this.changed)?n&&n(l,c,s):this.sendItems()},this.options={...e},!this.options.orderBy){const{synced_field:t,id_fields:n}=e;this.options.orderBy=[t,...n.sort()].map((e=>({fieldName:e,tsDataType:e===t?"number":"string",asc:!0})))}}isSending(){const e=this.isOnSending||!(a(this.sending)&&a(this.changed));return this.options.DEBUG_MODE&&console.log(this.options.id," CHECKING isSending ->",e),e}getIdStr(e){return this.options.id_fields.sort().map((t=>`${e[t]||""}`)).join(".")}getIdObj(e){let t={};return this.options.id_fields.sort().map((n=>{t[n]=e[n]})),t}getDeltaObj(e){let t={};return Object.keys(e).map((n=>{this.options.id_fields.includes(n)||(t[n]=e[n])})),t}},t.isEmpty=a,t.get=function(e,t){let n=t,i=e;return e?("string"==typeof n&&(n=n.split(".")),n.reduce(((e,t)=>e&&e[t]?e[t]:void 0),i)):e},t.isObject=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},t.isDefined=function(e){return null!=e},t.getKeys=l,t.tryCatch=async e=>{const t=Date.now();try{return{...await e(),duration:Date.now()-t}}catch(e){return{error:e,duration:Date.now()-t}}},t.getJoinHandlers=e=>{const t=(t,n)=>(n,i,r={})=>({[t?"$leftJoin":"$innerJoin"]:r.path??e,filter:n,...o(r,["path","select"]),select:i});return{innerJoin:t(!1),leftJoin:t(!0),innerJoinOne:t(!1),leftJoinOne:t(!0)}}}},t={};return function n(i){var r=t[i];if(void 0!==r)return r.exports;var o=t[i]={exports:{}};return e[i].call(o.exports,o,o.exports,n),o.exports}(590)})(),e.exports=t()}},t={},function n(i){var r=t[i];if(void 0!==r)return r.exports;var o=t[i]={exports:{}};return e[i].call(o.exports,o,o.exports,n),o.exports}(274);var e,t}));
|
|
1
|
+
!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 i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this||window,(()=>{return e={274:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prostgles=t.asName=t.debug=void 0;const i=n(792);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return i.asName}});const r="DEBUG_SYNCEDTABLE",s="undefined"!=typeof window;t.debug=function(...e){s&&window[r]&&window[r](...e)},t.prostgles=function(e,n){const{socket:r,onReady:a,onDisconnect:l,onReconnect:c,onSchemaChange:u=!0,onReload:p,onDebug:d}=e;if((0,t.debug)("prostgles",{initOpts:e}),u){let e;"function"==typeof u&&(e=u),r.removeAllListeners(i.CHANNELS.SCHEMA_CHANGED),e&&r.on(i.CHANNELS.SCHEMA_CHANGED,e)}const m=i.CHANNELS._preffix;let f,h={},g={},y={},b={},v=!1;function O(e,n,i){return(0,t.debug)("_unsubscribe",{channelName:e,handler:i}),new Promise(((t,s)=>{h[e]?(h[e].handlers=h[e].handlers.filter((e=>e!==i)),h[e].handlers.length||(r.emit(n,{},((e,t)=>{e&&console.error(e)})),r.removeListener(e,h[e].onCall),delete h[e]),t(!0)):t(!0)}))}function N({tableName:e,command:t,param1:n,param2:i},s){return new Promise(((o,a)=>{r.emit(m,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{if(e)console.error(e),a(e);else if(t){const{id_fields:e,synced_field:n,channelName:i}=t;r.emit(i,{onSyncRequest:s({})},(e=>{console.log(e)})),o({id_fields:e,synced_field:n,channelName:i})}}))}))}function _({tableName:e,command:t,param1:n,param2:i}){return new Promise(((s,o)=>{r.emit(m,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{e?(console.error(e),o(e)):t&&s(t)}))}))}const S=new o((async function({tableName:e,command:n,param1:i,param2:s},o){const{onPullRequest:a,onSyncRequest:l,onUpdates:c}=o;function u(e){return Object.freeze({unsync:function(){!function(e,n){(0,t.debug)("_unsync",{channelName:e,triggers:n}),new Promise(((t,i)=>{y[e]&&(y[e].triggers=y[e].triggers.filter((e=>e.onPullRequest!==n.onPullRequest&&e.onSyncRequest!==n.onSyncRequest&&e.onUpdates!==n.onUpdates)),y[e].triggers.length||(r.emit(e+"unsync",{},((e,n)=>{e?i(e):t(n)})),r.removeListener(e,y[e].onCall),delete y[e]))}))}(e,o)},syncData:function(t,n,i){r.emit(e,{onSyncRequest:{...l({}),...{data:t}||{},...{deleted:n}||{}}},i?e=>{i(e)}:null)}})}const p=Object.keys(y).find((t=>{let r=y[t];return r&&r.tableName===e&&r.command===n&&JSON.stringify(r.param1||{})===JSON.stringify(i||{})&&JSON.stringify(r.param2||{})===JSON.stringify(s||{})}));if(p)return y[p].triggers.push(o),u(p);{const d=await N({tableName:e,command:n,param1:i,param2:s},l),{channelName:m,synced_field:f,id_fields:h}=d;function g(t,n){t&&y[m]&&y[m].triggers.map((({onUpdates:i,onSyncRequest:r,onPullRequest:s})=>{t.data?Promise.resolve(i(t)).then((()=>{n&&n({ok:!0})})).catch((t=>{n?n({err:t}):console.error(e+" onUpdates error",t)})):t.onSyncRequest?Promise.resolve(r(t.onSyncRequest)).then((e=>n({onSyncRequest:e}))).catch((t=>{n?n({err:t}):console.error(e+" onSyncRequest error",t)})):t.onPullRequest?Promise.resolve(s(t.onPullRequest)).then((e=>{n({data:e})})).catch((t=>{n?n({err:t}):console.error(e+" onPullRequest error",t)})):console.log("unexpected response")}))}return y[m]={tableName:e,command:n,param1:i,param2:s,triggers:[o],syncInfo:d,onCall:g},r.on(m,g),u(m)}}),(([{tableName:e}])=>e)),x=new o((async function(e,{tableName:t,command:n,param1:i,param2:s},o,a){function l(n,r){let s={unsubscribe:function(){return O(n,r,o)},filter:{...i}};return e[t].update&&(s={...s,update:function(n,r){return e[t].update(i,n,r)}}),e[t].delete&&(s={...s,delete:function(n){return e[t].delete(i,n)}}),Object.freeze(s)}const c=Object.entries(h).find((([e])=>{let r=h[e];return r&&r.tableName===t&&r.command===n&&JSON.stringify(r.param1||{})===JSON.stringify(i||{})&&JSON.stringify(r.param2||{})===JSON.stringify(s||{})}));if(c){const e=c[0];return c[1].handlers.push(o),c[1].errorHandlers.push(a),setTimeout((()=>{var t,n;o&&(null===(t=null==h?void 0:h[e])||void 0===t?void 0:t.lastData)&&o(null===(n=null==h?void 0:h[e])||void 0===n?void 0:n.lastData)}),10),l(e,c[1].unsubChannel)}const{channelName:u,channelNameReady:p,channelNameUnsubscribe:d}=await _({tableName:t,command:n,param1:i,param2:s}),m=function(e,t){const n=h[u];n?e.data?(n.lastData=e.data,n.handlers.forEach((t=>{t(e.data)}))):e.err?n.errorHandlers.forEach((t=>{null==t||t(e.err)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",e):console.warn("Orphaned subscription: ",u)},f=a||function(e){console.error(`Uncaught error within running subscription \n ${u}`,e)};return r.on(u,m),h[u]={lastData:void 0,tableName:t,command:n,param1:i,param2:s,onCall:m,unsubChannel:d,handlers:[o],errorHandlers:[f],destroy:()=>{h[u]&&(Object.values(h[u]).map((e=>{e&&e.handlers&&e.handlers.map((e=>O(u,d,e)))})),delete h[u])}},r.emit(p,{now:Date.now()}),l(u,d)}),(([e,{tableName:t}])=>t));async function E(e,t,n,i){return x.run([e,t,n,i])}return new Promise(((e,o)=>{r.removeAllListeners(i.CHANNELS.CONNECTION),r.on(i.CHANNELS.CONNECTION,(e=>(o(e),"ok"))),l&&r.on("disconnect",l),r.on(i.CHANNELS.SCHEMA,(({schema:l,methods:u,tableSchema:O,auth:x,rawSQL:w,joinTables:T=[],err:j})=>{if((0,t.debug)("destroySyncs",{subscriptions:h,syncedTables:g}),Object.values(h).map((e=>e.destroy())),h={},y={},Object.values(g).map((e=>{e&&e.destroy&&e.destroy()})),g={},v&&c&&(c(r,j),j))return void console.error(j);if(j)throw o(j),j;v=!0;let C=JSON.parse(JSON.stringify(l)),P=JSON.parse(JSON.stringify(u)),J={},A={};if(x){if(x.pathGuard&&s){const e=e=>{var t,n;(null==e?void 0:e.shouldReload)&&(p?p():"undefined"!=typeof window&&(null===(n=null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.reload)||void 0===n||n.call(t)))};r.emit(i.CHANNELS.AUTHGUARD,JSON.stringify(window.location),((t,n)=>{e(n)})),r.removeAllListeners(i.CHANNELS.AUTHGUARD),r.on(i.CHANNELS.AUTHGUARD,(t=>{e(t)}))}A={...x},[i.CHANNELS.LOGIN,i.CHANNELS.LOGOUT,i.CHANNELS.REGISTER].map((e=>{x[e]&&(A[e]=function(t){return new Promise(((n,i)=>{r.emit(m+e,t,((e,t)=>{e?i(e):n(t)}))}))})}))}P.map((e=>{const t="string"==typeof e,n=t?e:e.name,s=async function(...e){return await(null==d?void 0:d({type:"method",command:n,data:{params:e}})),new Promise(((t,s)=>{r.emit(i.CHANNELS.METHOD,{method:n,params:e},((e,n)=>{e?s(e):t(n)}))}))};J[n]=t?s:{...e,run:s}})),J=Object.freeze(J),w&&(C.sql=function(e,t,n){return new Promise(((s,o)=>{r.emit(i.CHANNELS.SQL,{query:e,params:t,options:n},((e,t)=>{if(e)o(e);else if(n&&"noticeSubscription"===n.returnType&&t&&Object.keys(t).sort().join()===["socketChannel","socketUnsubChannel"].sort().join()&&!Object.values(t).find((e=>"string"!=typeof e))){const e=t,n=t=>(((e,t)=>{f=f||{config:t,listeners:[]},f.listeners.length||(r.removeAllListeners(t.socketChannel),r.on(t.socketChannel,(e=>{f&&f.listeners&&f.listeners.length?f.listeners.map((t=>{t(e)})):r.emit(t.socketUnsubChannel,{})}))),f.listeners.push(e)})(t,e),{...e,removeListener:()=>(e=>{f&&(f.listeners=f.listeners.filter((t=>t!==e)),!f.listeners.length&&f.config&&f.config.socketUnsubChannel&&r&&r.emit(f.config.socketUnsubChannel,{}))})(t)}),i={...e,addListener:n};s(i)}else if(n&&n.returnType&&"statement"===n.returnType||!t||Object.keys(t).sort().join()!==["socketChannel","socketUnsubChannel","notifChannel"].sort().join()||Object.values(t).find((e=>"string"!=typeof e)))s(t);else{const e=e=>(((e,t)=>{var n;b=b||{},b[t.notifChannel]?null===(n=b[t.notifChannel])||void 0===n||n.listeners.push(e):(b[t.notifChannel]={config:t,listeners:[e]},r.removeAllListeners(t.socketChannel),r.on(t.socketChannel,(e=>{var n,i;(null===(n=b[t.notifChannel])||void 0===n?void 0:n.listeners.length)?b[t.notifChannel].listeners.map((t=>{t(e)})):r.emit(null===(i=b[t.notifChannel])||void 0===i?void 0:i.config.socketUnsubChannel,{})})))})(e,t),{...t,removeListener:()=>((e,t)=>{const n=b[t.notifChannel];n&&(n.listeners=n.listeners.filter((t=>t!==e)),!n.listeners.length&&n.config&&n.config.socketUnsubChannel&&r&&(r.emit(n.config.socketUnsubChannel,{}),delete b[t.notifChannel]))})(e,t)}),n={...t,addListener:e};s(n)}}))}))});const D=e=>"[object Object]"===Object.prototype.toString.call(e),k=(e,t,n,i)=>{if(!D(e)||!D(t)||"function"!=typeof n||i&&"function"!=typeof i)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},R=["subscribe","subscribeOne"];(0,i.getKeys)(C).forEach((e=>{Object.keys(C[e]).sort(((e,t)=>R.includes(e)-R.includes(t))).forEach((t=>{if(["find","findOne"].includes(t)&&(C[e].getJoinedTables=function(){return(T||[]).filter((t=>Array.isArray(t)&&t.includes(e))).flat().filter((t=>t!==e))}),"sync"===t){if(C[e]._syncInfo={...C[e][t]},n){C[e].getSync=async(t,i={})=>(await(null==d?void 0:d({type:"table",command:"getSync",tableName:e,data:{filter:t,params:i}})),n.create({name:e,onDebug:d,filter:t,db:C,...i}));const t=async(t={},i={},r)=>{const s=`${e}.${JSON.stringify(t)}.${JSON.stringify(i)}`;return g[s]||(g[s]=await n.create({...i,onDebug:d,name:e,filter:t,db:C,onError:r})),g[s]};C[e].sync=async(n,i={handlesOnData:!0,select:"*"},r,s)=>{await(null==d?void 0:d({type:"table",command:"sync",tableName:e,data:{basicFilter:n,options:i}})),k(n,i,r,s);const o=await t(n,i,s);return await o.sync(r,i.handlesOnData)},C[e].syncOne=async(n,i={handlesOnData:!0},r,s)=>{await(null==d?void 0:d({type:"table",command:"syncOne",tableName:e,data:{basicFilter:n,options:i}})),k(n,i,r,s);const o=await t(n,i,s);return await o.syncOne(n,r,i.handlesOnData)}}C[e]._sync=async function(n,i,r){return await(null==d?void 0:d({type:"table",command:"_sync",tableName:e,data:{param1:n,param2:i,syncHandles:r}})),async function(e,t){return S.run([e,t])}({tableName:e,command:t,param1:n,param2:i},r)}}else if(R.includes(t)){const n=async function(n,i,r,s){return await(null==d?void 0:d({type:"table",command:t,tableName:e,data:{param1:n,param2:i,onChange:r,onError:s}})),k(n,i,r,s),E(C,{tableName:e,command:t,param1:n,param2:i},r,s)};C[e][t]=n;const i="subscribeOne";C[e][t+"Hook"]=function(e={},r={},s){return{start:o=>n(e,r,t!==i?o:e=>{o(e[0])},s),args:[e,r,s]}},t!==i&&R.includes(i)||(C[e][i]=async function(n,i,r,s){return await(null==d?void 0:d({type:"table",command:"getSync",tableName:e,data:{param1:n,param2:i,onChange:r,onError:s}})),k(n,i,r,s),E(C,{tableName:e,command:t,param1:n,param2:i},(e=>{r(e[0])}),s)})}else C[e][t]=async function(n,i,s){return await(null==d?void 0:d({type:"table",command:t,tableName:e,data:{param1:n,param2:i,param3:s}})),new Promise(((o,a)=>{r.emit(m,{tableName:e,command:t,param1:n,param2:i,param3:s},((e,t)=>{e?a(e):o(t)}))}))}}))})),h&&Object.keys(h).length&&Object.keys(h).map((async e=>{try{let t=h[e];await _(t),r.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting old subscriptions",e)}})),y&&Object.keys(y).length&&(0,i.getKeys)(y).filter((e=>{var t;return null===(t=y[e])||void 0===t?void 0:t.triggers.length})).map((async e=>{try{let t=y[e];await N(t,t.triggers[0].onSyncRequest),r.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}})),T.flat().map((e=>{C.innerJoin=C.innerJoin||{},C.leftJoin=C.leftJoin||{},C.innerJoinOne=C.innerJoinOne||{},C.leftJoinOne=C.leftJoinOne||{};const t=(0,i.getJoinHandlers)(e);C.leftJoin[e]=t.leftJoin,C.innerJoin[e]=t.innerJoin,C.leftJoinOne[e]=t.leftJoinOne,C.innerJoinOne[e]=t.innerJoinOne})),(async()=>{try{await a(C,J,O,A,v)}catch(e){console.error("Prostgles: Error within onReady: \n",e),o(e)}e(C)})()}))}))};class o{constructor(e,t){this.queue=[],this.isRunning=!1,this.func=e,this.groupBy=t}async run(e){const t=new Promise(((t,n)=>{const i={arguments:e,onResult:t,onFail:n};this.queue.push(i)})),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,i)=>{const r=this.groupBy(e.arguments);t.includes(r)||(t.push(r),n.push({index:i,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}}},792:function(e){var t;this||window,t=()=>(()=>{"use strict";var e={31:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=void 0,t.CONTENT_TYPE_TO_EXT={"text/html":["html","htm","shtml"],"text/css":["css"],"text/csv":["csv"],"text/tsv":["tsv"],"text/xml":["xml"],"text/mathml":["mml"],"text/plain":["txt"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/x-component":["htc"],"image/gif":["gif"],"image/jpeg":["jpeg","jpg"],"image/png":["png"],"image/tiff":["tif","tiff"],"image/vnd.wap.wbmp":["wbmp"],"image/x-icon":["ico"],"image/x-jng":["jng"],"image/x-ms-bmp":["bmp"],"image/svg+xml":["svg"],"image/webp":["webp"],"application/sql":["sql"],"application/x-javascript":["js"],"application/atom+xml":["atom"],"application/rss+xml":["rss"],"application/java-archive":["jar","war","ear"],"application/mac-binhex40":["hqx"],"application/msword":["doc","docx"],"application/pdf":["pdf"],"application/postscript":["ps","eps","ai"],"application/rtf":["rtf"],"application/vnd.ms-excel":["xls","xlsx"],"application/vnd.ms-powerpoint":["ppt","pptx"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/x-7z-compressed":["7z"],"application/x-cocoa":["cco"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-makeself":["run"],"application/x-perl":["pl","pm"],"application/x-pilot":["prc","pdb"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-sea":["sea"],"application/x-shockwave-flash":["swf"],"application/x-stuffit":["sit"],"application/x-tcl":["tcl","tk"],"application/x-x509-ca-cert":["der","pem","crt"],"application/x-xpinstall":["xpi"],"application/xhtml+xml":["xhtml"],"application/zip":["zip"],"application/octet-stream":["bin","exe","dll","deb","dmg","eot","iso","img","msi","msp","msm"],"audio/midi":["mid","midi","kar"],"audio/mpeg":["mp3"],"audio/ogg":["ogg"],"audio/x-realaudio":["ra"],"video/3gpp":["3gpp","3gp"],"video/mpeg":["mpeg","mpg"],"video/quicktime":["mov"],"video/x-flv":["flv"],"video/x-mng":["mng"],"video/x-ms-asf":["asx","asf"],"video/x-ms-wmv":["wmv"],"video/x-msvideo":["avi"],"video/mp4":["m4v","mp4"],"video/webm":["webm"]}},444:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.COMPLEX_FILTER_KEY=t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.ArrayFilterOperands=t.TextFilter_FullTextSearchFilterKeys=t.TextFilterFTSKeys=t.TextFilterKeys=t.JsonbFilterKeys=t.JsonbOperands=t.CompareInFilterKeys=t.CompareFilterKeys=void 0;const i=n(128);t.CompareFilterKeys=["=","$eq","<>",">","<",">=","<=","$eq","$ne","$gt","$gte","$lte"],t.CompareInFilterKeys=["$in","$nin"],t.JsonbOperands={"@>":{Operator:"@>","Right Operand Type":"jsonb",Description:"Does the left JSON value contain the right JSON path/value entries at the top level?",Example:'\'{"a":1, "b":2}\'::jsonb @> \'{"b":2}\'::jsonb'},"<@":{Operator:"<@","Right Operand Type":"jsonb",Description:"Are the left JSON path/value entries contained at the top level within the right JSON value?",Example:'\'{"b":2}\'::jsonb <@ \'{"a":1, "b":2}\'::jsonb'},"?":{Operator:"?","Right Operand Type":"text",Description:"Does the string exist as a top-level key within the JSON value?",Example:"'{\"a\":1, \"b\":2}'::jsonb ? 'b'"},"?|":{Operator:"?|","Right Operand Type":"text[]",Description:"Do any of these array strings exist as top-level keys?",Example:"'{\"a\":1, \"b\":2, \"c\":3}'::jsonb ?| array['b', 'c']"},"?&":{Operator:"?&","Right Operand Type":"text[]",Description:"Do all of these array strings exist as top-level keys?",Example:"'[\"a\", \"b\"]'::jsonb ?& array['a', 'b']"},"||":{Operator:"||","Right Operand Type":"jsonb",Description:"Concatenate two jsonb values into a new jsonb value",Example:'\'["a", "b"]\'::jsonb || \'["c", "d"]\'::jsonb'},"-":{Operator:"-","Right Operand Type":"integer",Description:"Delete the array element with specified index (Negative integers count from the end). Throws an error if top level container is not an array.",Example:'\'["a", "b"]\'::jsonb - 1'},"#-":{Operator:"#-","Right Operand Type":"text[]",Description:"Delete the field or element with specified path (for JSON arrays, negative integers count from the end)",Example:"'[\"a\", {\"b\":1}]'::jsonb #- '{1,b}'"},"@?":{Operator:"@?","Right Operand Type":"jsonpath",Description:"Does JSON path return any item for the specified JSON value?",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)'"},"@@":{Operator:"@@","Right Operand Type":"jsonpath",Description:"Returns the result of JSON path predicate check for the specified JSON value. Only the first item of the result is taken into account. If the result is not Boolean, then null is returned.",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @@ '$.a[*] > 2'"}},t.JsonbFilterKeys=(0,i.getKeys)(t.JsonbOperands),t.TextFilterKeys=["$ilike","$like","$nilike","$nlike"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.ArrayFilterOperands=["@>","<@","=","$eq","$contains","$containedBy","&&","$overlaps"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"],t.GeomFilter_Funcs=["ST_MakeEnvelope","st_makeenvelope","ST_MakePolygon","st_makepolygon"],t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"],t.COMPLEX_FILTER_KEY="$filter"},590:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=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,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=t.RULE_METHODS=t.CHANNELS=t.JOIN_PARAMS=t.JOIN_KEYS=t.TS_PG_Types=t._PG_geometric=t._PG_postgis=t._PG_interval=t._PG_date=t._PG_bool=t._PG_json=t._PG_numbers=t._PG_strings=void 0,t._PG_strings=["bpchar","char","varchar","text","citext","uuid","bytea","time","timetz","interval","name","cidr","inet","macaddr","macaddr8","int4range","int8range","numrange","tsvector"],t._PG_numbers=["int2","int4","int8","float4","float8","numeric","money","oid"],t._PG_json=["json","jsonb"],t._PG_bool=["bool"],t._PG_date=["date","timestamp","timestamptz"],t._PG_interval=["interval"],t._PG_postgis=["geometry","geography"],t._PG_geometric=["point","line","lseg","box","path","polygon","circle"];const s={string:[...t._PG_strings,...t._PG_date,...t._PG_geometric,...t._PG_postgis,"lseg"],number:t._PG_numbers,boolean:t._PG_bool,any:[...t._PG_json,...t._PG_interval]};t.TS_PG_Types={...s,"number[]":s.number.map((e=>`_${e}`)),"boolean[]":s.boolean.map((e=>`_${e}`)),"string[]":s.string.map((e=>`_${e}`)),"any[]":s.any.map((e=>`_${e}`))},t.JOIN_KEYS=["$innerJoin","$leftJoin"],t.JOIN_PARAMS=["select","filter","$path","$condition","offset","limit","orderBy"];const o="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:o+"schema-changed",SCHEMA:o+"schema",DEFAULT:o,SQL:`${o}sql`,METHOD:`${o}method`,NOTICE_EV:`${o}notice`,LISTEN_EV:`${o}listen`,REGISTER:`${o}register`,LOGIN:`${o}login`,LOGOUT:`${o}logout`,AUTHGUARD:`${o}authguard`,CONNECTION:`${o}connection`,_preffix:o},t.RULE_METHODS={getColumns:["getColumns"],getInfo:["getInfo"],insert:["insert","upsert"],update:["update","upsert","updateBatch"],select:["findOne","find","count","size"],delete:["delete","remove"],sync:["sync","unsync"],subscribe:["unsubscribe","subscribe","subscribeOne"]},r(n(128),t),r(n(444),t);var a=n(31);Object.defineProperty(t,"CONTENT_TYPE_TO_EXT",{enumerable:!0,get:function(){return a.CONTENT_TYPE_TO_EXT}}),r(n(929),t)},929:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBSchemaAsJSONSchema=t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=void 0;const i=n(128);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 r=(e,t)=>{const{type:n,arrayOf:s,arrayOfType:o,description:a,nullable:l,oneOf:c,oneOfType:u,title:p,record:d,...m}="string"==typeof e?{type:e}:e;let f={};const h={...(m.enum||m.allowedValues?.length)&&{enum:m.allowedValues?.slice(0)??m.enum.slice(0)},...!!a&&{description:a},...!!p&&{title:p}};if(m.enum?.length&&(h.type=typeof m.enum[0]),"string"==typeof n||s||o){if(n&&"string"!=typeof n)throw"Not expected";f=s||o||n?.endsWith("[]")?{type:"array",items:s||o?r(s||{type:o}):n?.startsWith("any")?{type:void 0}:{type:n?.slice(0,-2),...m.allowedValues&&{enum:m.allowedValues.slice(0)}}}:{type:n}}else(0,i.isObject)(n)?f={type:"object",required:(0,i.getKeys)(n).filter((e=>{const t=n[e];return"string"==typeof t||!t.optional})),properties:(0,i.getKeys)(n).reduce(((e,t)=>({...e,[t]:r(n[t])})),{})}:c||u?f={oneOf:(c||u.map((e=>({type:e})))).map((e=>r(e)))}:d&&(f={type:"object",...d.values&&!d.keysEnum&&{additionalProperties:r(d.values)},...d.keysEnum&&{properties:d.keysEnum.reduce(((e,t)=>({...e,[t]:d.values?r(d.values):{type:{}}})),{})}});if(l){const e={type:"null"};f.oneOf?f.oneOf.push(e):f.enum&&!f.enum.includes(null)?f.enum.push(null):f={oneOf:[f,e]}}return{...t?{$id:t?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...h,...f}};t.getJSONBSchemaAsJSONSchema=function(e,t,n){return r(n,{id:`${e}.${t}`})}},899:(e,t)=>{function n(e,t){var n=e[0],i=e[1],l=e[2],c=e[3];n=r(n,i,l,c,t[0],7,-680876936),c=r(c,n,i,l,t[1],12,-389564586),l=r(l,c,n,i,t[2],17,606105819),i=r(i,l,c,n,t[3],22,-1044525330),n=r(n,i,l,c,t[4],7,-176418897),c=r(c,n,i,l,t[5],12,1200080426),l=r(l,c,n,i,t[6],17,-1473231341),i=r(i,l,c,n,t[7],22,-45705983),n=r(n,i,l,c,t[8],7,1770035416),c=r(c,n,i,l,t[9],12,-1958414417),l=r(l,c,n,i,t[10],17,-42063),i=r(i,l,c,n,t[11],22,-1990404162),n=r(n,i,l,c,t[12],7,1804603682),c=r(c,n,i,l,t[13],12,-40341101),l=r(l,c,n,i,t[14],17,-1502002290),n=s(n,i=r(i,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=s(c,n,i,l,t[6],9,-1069501632),l=s(l,c,n,i,t[11],14,643717713),i=s(i,l,c,n,t[0],20,-373897302),n=s(n,i,l,c,t[5],5,-701558691),c=s(c,n,i,l,t[10],9,38016083),l=s(l,c,n,i,t[15],14,-660478335),i=s(i,l,c,n,t[4],20,-405537848),n=s(n,i,l,c,t[9],5,568446438),c=s(c,n,i,l,t[14],9,-1019803690),l=s(l,c,n,i,t[3],14,-187363961),i=s(i,l,c,n,t[8],20,1163531501),n=s(n,i,l,c,t[13],5,-1444681467),c=s(c,n,i,l,t[2],9,-51403784),l=s(l,c,n,i,t[7],14,1735328473),n=o(n,i=s(i,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=o(c,n,i,l,t[8],11,-2022574463),l=o(l,c,n,i,t[11],16,1839030562),i=o(i,l,c,n,t[14],23,-35309556),n=o(n,i,l,c,t[1],4,-1530992060),c=o(c,n,i,l,t[4],11,1272893353),l=o(l,c,n,i,t[7],16,-155497632),i=o(i,l,c,n,t[10],23,-1094730640),n=o(n,i,l,c,t[13],4,681279174),c=o(c,n,i,l,t[0],11,-358537222),l=o(l,c,n,i,t[3],16,-722521979),i=o(i,l,c,n,t[6],23,76029189),n=o(n,i,l,c,t[9],4,-640364487),c=o(c,n,i,l,t[12],11,-421815835),l=o(l,c,n,i,t[15],16,530742520),n=a(n,i=o(i,l,c,n,t[2],23,-995338651),l,c,t[0],6,-198630844),c=a(c,n,i,l,t[7],10,1126891415),l=a(l,c,n,i,t[14],15,-1416354905),i=a(i,l,c,n,t[5],21,-57434055),n=a(n,i,l,c,t[12],6,1700485571),c=a(c,n,i,l,t[3],10,-1894986606),l=a(l,c,n,i,t[10],15,-1051523),i=a(i,l,c,n,t[1],21,-2054922799),n=a(n,i,l,c,t[8],6,1873313359),c=a(c,n,i,l,t[15],10,-30611744),l=a(l,c,n,i,t[6],15,-1560198380),i=a(i,l,c,n,t[13],21,1309151649),n=a(n,i,l,c,t[4],6,-145523070),c=a(c,n,i,l,t[11],10,-1120210379),l=a(l,c,n,i,t[2],15,718787259),i=a(i,l,c,n,t[9],21,-343485551),e[0]=d(n,e[0]),e[1]=d(i,e[1]),e[2]=d(l,e[2]),e[3]=d(c,e[3])}function i(e,t,n,i,r,s){return t=d(d(t,e),d(i,s)),d(t<<r|t>>>32-r,n)}function r(e,t,n,r,s,o,a){return i(t&n|~t&r,e,t,s,o,a)}function s(e,t,n,r,s,o,a){return i(t&r|n&~r,e,t,s,o,a)}function o(e,t,n,r,s,o,a){return i(t^n^r,e,t,s,o,a)}function a(e,t,n,r,s,o,a){return i(n^(t|~r),e,t,s,o,a)}function l(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}Object.defineProperty(t,"__esModule",{value:!0}),t.md5=t.md5cycle=void 0,t.md5cycle=n;var c="0123456789abcdef".split("");function u(e){for(var t="",n=0;n<4;n++)t+=c[e>>8*n+4&15]+c[e>>8*n&15];return t}function p(e){return function(e){for(var t=0;t<e.length;t++)e[t]=u(e[t]);return e.join("")}(function(e){var t,i=e.length,r=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)n(r,l(e.substring(t-64,t)));e=e.substring(t-64);var s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<e.length;t++)s[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(n(r,s),t=0;t<16;t++)s[t]=0;return s[14]=8*i,n(r,s),r}(e))}function d(e,t){return e+t&4294967295}t.md5=p,p("hello")},128:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.reverseParsedPath=t.reverseJoinOn=t.getJoinHandlers=t.tryCatch=t.getKeys=t.isDefined=t.isObject=t.get=t.isEmpty=t.WAL=t.unpatchText=t.getTextPatch=t.stableStringify=t.includes=t.find=t.filter=t.omitKeys=t.pickKeys=t.asName=void 0;const i=n(899);function r(e,t=[],n=!1){let i=t;if(!i.length)return{};if(e&&i.length){let t={};return i.forEach((i=>{n&&void 0===e[i]||(t[i]=e[i])})),t}return e}function s(e,t){return r(e,c(e).filter((e=>!t.includes(e))))}function o(e,t){return e.filter((e=>Object.entries(t).every((([t,n])=>e[t]===n))))}function a(e){for(var t in e)return!1;return!0}function l(e){return null!=e}function c(e){return Object.keys(e)}t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},t.pickKeys=r,t.omitKeys=s,t.filter=o,t.find=function(e,t){return o(e,t)[0]},t.includes=function(e,t){return e.some((e=>e===t))},t.stableStringify=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var n,i="boolean"==typeof t.cycles&&t.cycles,r=t.cmp&&(n=t.cmp,function(e){return function(t,i){var r={key:t,value:e[t]},s={key:i,value:e[i]};return n(r,s)}}),s=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var n,o;if(Array.isArray(t)){for(o="[",n=0;n<t.length;n++)n&&(o+=","),o+=e(t[n])||"null";return o+"]"}if(null===t)return"null";if(-1!==s.indexOf(t)){if(i)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=s.push(t)-1,l=Object.keys(t).sort(r&&r(t));for(o="",n=0;n<l.length;n++){var c=l[n],u=e(t[c]);u&&(o&&(o+=","),o+=JSON.stringify(c)+":"+u)}return s.splice(a,1),"{"+o+"}"}}(e)},t.getTextPatch=function(e,t){if(!(e&&t&&e.trim().length&&t.trim().length))return t;if(e===t)return{from:0,to:0,text:"",md5:(0,i.md5)(t)};function n(n=1){let i=n<1?-1:0,r=!1;for(;!r&&Math.abs(i)<=t.length;){const s=n<1?[i]:[0,i];e.slice(...s)!==t.slice(...s)?r=!0:i+=1*Math.sign(n)}return i}let r=n()-1,s=e.length+n(-1)+1,o=t.length+n(-1)+1;return{from:r,to:s,text:t.slice(r,o),md5:(0,i.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:r,text:s,md5:o}=t;if(null===s||null===e)return s;let a=e.slice(0,n)+s+e.slice(r);if(o&&(0,i.md5)(a)!==o)throw"Patch text error: Could not match md5 hash: (original/result) \n"+e+"\n"+a;return a},t.WAL=class{constructor(e){if(this.changed={},this.sending={},this.sentHistory={},this.callbacks=[],this.sort=(e,t)=>{const{orderBy:n}=this.options;return n&&e&&t&&n.map((n=>{if(!(n.fieldName in e)||!(n.fieldName in t))throw"Replication error: \n some orderBy fields missing from data";let i=n.asc?e[n.fieldName]:t[n.fieldName],r=n.asc?t[n.fieldName]:e[n.fieldName],s=+i-+r,o=i<r?-1:i==r?0:1;return"number"===n.tsDataType&&Number.isFinite(s)?s:o})).find((e=>e))||0},this.isInHistory=e=>{if(!e)throw"Provide item";const t=e[this.options.synced_field];if(!Number.isFinite(+t))throw"Provided item Synced field value is missing/invalid ";const n=this.sentHistory[this.getIdStr(e)],i=n?.[this.options.synced_field];if(n){if(!Number.isFinite(+i))throw"Provided historic item Synced field value is missing/invalid";if(+i==+t)return!0}return!1},this.addData=e=>{a(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map((e=>{var t;const{initial:n,current:i,delta:r}={...e};if(!i)throw"Expecting { current: object, initial?: object }";const s=this.getIdStr(i);this.changed??(this.changed={}),(t=this.changed)[s]??(t[s]={initial:n,current:i,delta:r}),this.changed[s].current={...this.changed[s].current,...i},this.changed[s].delta={...this.changed[s].delta,...r}})),this.sendItems()},this.isOnSending=!1,this.isSendingTimeout=void 0,this.willDeleteHistory=void 0,this.sendItems=async()=>{const{DEBUG_MODE:e,onSend:t,onSendEnd:n,batch_size:i,throttle:r,historyAgeSeconds:s=2}=this.options;if(this.isSendingTimeout||this.sending&&!a(this.sending))return;if(!this.changed||a(this.changed))return;let o,l=[],c=[],u={};Object.keys(this.changed).sort(((e,t)=>this.sort(this.changed[e].current,this.changed[t].current))).slice(0,i).map((e=>{let t={...this.changed[e]};this.sending[e]={...t},c.push({...t}),u[e]={...t.current},delete this.changed[e]})),l=c.map((e=>{let t={};return Object.keys(e.current).map((n=>{const i=e.initial?.[n],r=e.current[n];var s,o;![this.options.synced_field,...this.options.id_fields].includes(n)&&((s=i)===(o=r)||(["number","string","boolean"].includes(typeof s)?s===o:JSON.stringify(s)===JSON.stringify(o)))||(t[n]=r)})),t})),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout((()=>{this.isSendingTimeout=void 0,a(this.changed)||this.sendItems()}),r)),this.isOnSending=!0;try{await t(l,c),s&&(this.sentHistory={...this.sentHistory,...u},this.willDeleteHistory||(this.willDeleteHistory=setTimeout((()=>{this.willDeleteHistory=void 0,this.sentHistory={}}),1e3*s)))}catch(e){o=e,console.error("WAL onSend failed:",e,l,c)}if(this.isOnSending=!1,this.callbacks.length){const e=Object.keys(this.sending);this.callbacks.forEach(((t,n)=>{t.idStrs=t.idStrs.filter((t=>e.includes(t))),t.idStrs.length||t.cb(o)})),this.callbacks=this.callbacks.filter((e=>e.idStrs.length))}this.sending={},e&&console.log(this.options.id," SENT lr->",l[l.length-1]),a(this.changed)?n&&n(l,c,o):this.sendItems()},this.options={...e},!this.options.orderBy){const{synced_field:t,id_fields:n}=e;this.options.orderBy=[t,...n.sort()].map((e=>({fieldName:e,tsDataType:e===t?"number":"string",asc:!0})))}}isSending(){const e=this.isOnSending||!(a(this.sending)&&a(this.changed));return this.options.DEBUG_MODE&&console.log(this.options.id," CHECKING isSending ->",e),e}getIdStr(e){return this.options.id_fields.sort().map((t=>`${e[t]||""}`)).join(".")}getIdObj(e){let t={};return this.options.id_fields.sort().map((n=>{t[n]=e[n]})),t}getDeltaObj(e){let t={};return Object.keys(e).map((n=>{this.options.id_fields.includes(n)||(t[n]=e[n])})),t}},t.isEmpty=a,t.get=function(e,t){let n=t,i=e;return e?("string"==typeof n&&(n=n.split(".")),n.reduce(((e,t)=>e&&e[t]?e[t]:void 0),i)):e},t.isObject=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},t.isDefined=l,t.getKeys=c,t.tryCatch=async e=>{const t=Date.now();try{return{...await e(),duration:Date.now()-t}}catch(e){return{error:e,duration:Date.now()-t}}},t.getJoinHandlers=e=>{const t=(t,n)=>(n,i,r={})=>({[t?"$leftJoin":"$innerJoin"]:r.path??e,filter:n,...s(r,["path","select"]),select:i});return{innerJoin:t(!1),leftJoin:t(!0),innerJoinOne:t(!1),leftJoinOne:t(!0)}},t.reverseJoinOn=e=>e.map((e=>Object.fromEntries(Object.entries(e).map((([e,t])=>[t,e]))))),t.reverseParsedPath=(e,n)=>{const i=[{table:n,on:[{}]},...e??[]];return i.map(((e,n)=>{const r=i[n+1];if(r)return{table:e.table,on:(0,t.reverseJoinOn)(r.on)}})).filter(l).reverse()}}},t={};return function n(i){var r=t[i];if(void 0!==r)return r.exports;var s=t[i]={exports:{}};return e[i].call(s.exports,s,s.exports,n),s.exports}(590)})(),e.exports=t()}},t={},function n(i){var r=t[i];if(void 0!==r)return r.exports;var s=t[i]={exports:{}};return e[i].call(s.exports,s,s.exports,n),s.exports}(274);var e,t}));
|
package/lib/SyncedTable.ts
CHANGED
|
@@ -78,7 +78,7 @@ export type ItemUpdated = ItemUpdate & {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export type CloneSync<T extends AnyObject, Full extends boolean> = (
|
|
81
|
-
onChange: SingleChangeListener<T>,
|
|
81
|
+
onChange: SingleChangeListener<T, Full>,
|
|
82
82
|
onError?: (error: any) => void
|
|
83
83
|
) => SingleSyncHandles<T, Full>;
|
|
84
84
|
|
|
@@ -107,7 +107,7 @@ export type SingleSyncHandles<T extends AnyObject = AnyObject, Full extends bool
|
|
|
107
107
|
$cloneMultiSync: CloneMultiSync<T>;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
export type SyncDataItem<T extends AnyObject = AnyObject, Full extends boolean = false> = T & (Full extends true ? SingleSyncHandles<T,
|
|
110
|
+
export type SyncDataItem<T extends AnyObject = AnyObject, Full extends boolean = false> = T & (Full extends true ? SingleSyncHandles<T, Full> : Partial<SingleSyncHandles<T, Full>>);
|
|
111
111
|
|
|
112
112
|
export type MultiSyncHandles<T extends AnyObject> = {
|
|
113
113
|
$unsync: () => void;
|
|
@@ -531,7 +531,7 @@ export class SyncedTable {
|
|
|
531
531
|
private makeSingleSyncHandles<T extends AnyObject = AnyObject, Full extends boolean = false>(idObj: Partial<T>, onChange: SingleChangeListener<T, Full> | MultiChangeListener<T>): SingleSyncHandles<T, Full> {
|
|
532
532
|
if (!idObj || !onChange) throw `syncOne(idObj, onChange) -> MISSING idObj or onChange`;
|
|
533
533
|
|
|
534
|
-
const handles: SingleSyncHandles<T> = {
|
|
534
|
+
const handles: SingleSyncHandles<T, Full> = {
|
|
535
535
|
$get: () => this.getItem<T>(idObj).data!,
|
|
536
536
|
$find: (idObject) => this.getItem<T>(idObject).data,
|
|
537
537
|
$unsync: () => {
|
|
@@ -548,7 +548,7 @@ export class SyncedTable {
|
|
|
548
548
|
}
|
|
549
549
|
this.upsert([{ idObj, delta: newData, opts }]);
|
|
550
550
|
},
|
|
551
|
-
$cloneSync: (onChange) => this.syncOne<T>(idObj, onChange)
|
|
551
|
+
$cloneSync: (onChange) => this.syncOne<T, Full>(idObj, onChange),
|
|
552
552
|
$cloneMultiSync: (onChange) => this.sync(onChange, true),
|
|
553
553
|
};
|
|
554
554
|
|
|
@@ -563,7 +563,7 @@ export class SyncedTable {
|
|
|
563
563
|
*/
|
|
564
564
|
syncOne<T extends AnyObject = AnyObject, Full extends boolean = false>(idObj: Partial<T>, onChange: SingleChangeListener<T, Full>, handlesOnData = true): SingleSyncHandles<T, Full> {
|
|
565
565
|
|
|
566
|
-
const handles = this.makeSingleSyncHandles(idObj, onChange);
|
|
566
|
+
const handles = this.makeSingleSyncHandles<T, Full>(idObj, onChange);
|
|
567
567
|
const sub: SubscriptionSingle<T, Full> = {
|
|
568
568
|
_onChange: onChange,
|
|
569
569
|
idObj,
|
|
@@ -578,7 +578,7 @@ export class SyncedTable {
|
|
|
578
578
|
newData.$update = handles.$update;
|
|
579
579
|
newData.$delete = handles.$delete;
|
|
580
580
|
newData.$unsync = handles.$unsync;
|
|
581
|
-
newData.$cloneSync = handles.$cloneSync;
|
|
581
|
+
newData.$cloneSync = handles.$cloneSync as any;
|
|
582
582
|
}
|
|
583
583
|
return onChange(newData, delta)
|
|
584
584
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-client",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.28",
|
|
4
4
|
"description": "Reactive client for Postgres",
|
|
5
5
|
"main": "dist/prostgles-full.js",
|
|
6
6
|
"types": "dist/prostgles-full.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"pushpublish": "npm version patch --git-tag-version false && git push && npm publish"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"prostgles-types": "^4.0.
|
|
31
|
+
"prostgles-types": "^4.0.43"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^14.14.14",
|