prostgles-client 1.5.148 → 1.5.151

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.
@@ -1,4 +1,5 @@
1
1
  import { FieldFilter, WAL, AnyObject, SyncBatchParams } from "prostgles-types";
2
+ import { DBHandlerClient } from "./prostgles";
2
3
  export declare type POJO = {
3
4
  [key: string]: any;
4
5
  };
@@ -104,7 +105,7 @@ export declare type DbTableSync = {
104
105
  syncData: (data?: AnyObject[], deleted?: AnyObject[], cb?: (err?: any) => void) => void;
105
106
  };
106
107
  export declare class SyncedTable {
107
- db: any;
108
+ db: DBHandlerClient;
108
109
  name: string;
109
110
  select?: "*" | {};
110
111
  filter?: POJO;
@@ -179,6 +180,7 @@ export declare class SyncedTable {
179
180
  */
180
181
  private getDelta;
181
182
  deleteAll(): void;
183
+ private get tableHandler();
182
184
  private delete;
183
185
  /**
184
186
  * Ensures that all object keys match valid column names
@@ -1 +1 @@
1
- {"version":3,"file":"SyncedTable.d.ts","sourceRoot":"","sources":["../lib/SyncedTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAyB,GAAG,EAAW,SAAS,EAAqB,eAAe,EAAqC,MAAM,iBAAiB,CAAC;AACrK,oBAAY,IAAI,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAC;AAI1C,eAAO,MAAM,KAAK,EAAE,GAInB,CAAC;AAMF,oBAAY,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,GAAG;IACtD,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAA;AACD,oBAAY,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC,GAAG;IACzD,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAA;AAED;;GAEG;AACH,oBAAY,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,WAAW,EAAE,GAAG,EAA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AAU,GAAE,OAAe;IA2BvG;;;OAGG;IACH,QAAQ,UAAW,IAAI,EAAE,KAAG,IAAI,CAY/B;IAED;;OAEG;IACH,QAAQ,QAAO,SAAS,EAAE,CAwCzB;IAED;;;OAGG;IACH,QAAQ,+CAA+C,eAAe;;QAarE;CACF;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,MAAM,KAAA,EAAE,MAAM,KAAA,OAgB/C"}
@@ -34,9 +34,10 @@ class SyncedTable {
34
34
  * @param walData
35
35
  */
36
36
  this.updatePatches = async (walData) => {
37
+ var _a, _b;
37
38
  let remaining = walData.map(d => d.current);
38
39
  let patched = [], patchedItems = [];
39
- if (this.columns && this.columns.length && this.db[this.name].updateBatch && (this.patchText || this.patchJSON)) {
40
+ if (this.columns && this.columns.length && ((_a = this.tableHandler) === null || _a === void 0 ? void 0 : _a.updateBatch) && (this.patchText || this.patchJSON)) {
40
41
  // const jCols = this.columns.filter(c => c.data_type === "json")
41
42
  const txtCols = this.columns.filter(c => c.data_type === "text");
42
43
  if (this.patchText && txtCols.length) {
@@ -74,7 +75,7 @@ class SyncedTable {
74
75
  */
75
76
  if (patched.length) {
76
77
  try {
77
- await this.db[this.name].updateBatch(patched);
78
+ await ((_b = this.tableHandler) === null || _b === void 0 ? void 0 : _b.updateBatch(patched));
78
79
  }
79
80
  catch (e) {
80
81
  console.log("failed to patch update", e);
@@ -155,10 +156,11 @@ class SyncedTable {
155
156
  this.onChange = undefined;
156
157
  };
157
158
  this.delete = async (item, from_server = false) => {
159
+ var _a;
158
160
  const idObj = this.getIdObj(item);
159
161
  this.setItem(idObj, undefined, true, true);
160
- if (!from_server) {
161
- await this.db[this.name].delete(idObj);
162
+ if (!from_server && ((_a = this.tableHandler) === null || _a === void 0 ? void 0 : _a.delete)) {
163
+ await this.tableHandler.delete(idObj);
162
164
  }
163
165
  this._notifySubscribers();
164
166
  return true;
@@ -459,14 +461,17 @@ class SyncedTable {
459
461
  }
460
462
  return true;
461
463
  };
464
+ const opts = {
465
+ id_fields,
466
+ synced_field,
467
+ throttle,
468
+ };
462
469
  db[this.name]._sync(filter, { select }, { onSyncRequest, onPullRequest, onUpdates }).then((s) => {
463
470
  this.dbSync = s;
464
471
  function confirmExit() { return "Data may be lost. Are you sure?"; }
465
- const opts = {
466
- id_fields,
467
- synced_field,
468
- throttle,
469
- };
472
+ /**
473
+ * Some syncs can be read only. Any changes are local
474
+ */
470
475
  this.wal = new prostgles_types_1.WAL({
471
476
  ...opts,
472
477
  batch_size,
@@ -609,7 +614,7 @@ class SyncedTable {
609
614
  },
610
615
  $cloneMultiSync: (onChange) => this.sync(onChange, handlesOnData)
611
616
  });
612
- const idObj = this.wal.getIdObj(item);
617
+ const idObj = this.getIdObj(item);
613
618
  return getItem(item, idObj);
614
619
  });
615
620
  }
@@ -766,6 +771,13 @@ class SyncedTable {
766
771
  deleteAll() {
767
772
  this.getItems().map(d => this.delete(d));
768
773
  }
774
+ get tableHandler() {
775
+ const tblHandler = this.db[this.name];
776
+ if (tblHandler.update && tblHandler.updateBatch) {
777
+ return tblHandler;
778
+ }
779
+ return undefined;
780
+ }
769
781
  // /* Returns an item by idObj from the local store */
770
782
  // getItem(idObj?: object, byFilter = false): { data?: object, index: number } {
771
783
  // let items = this.getItems();
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.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{constructor({name:e,filter:n,onChange:s,onReady:a,db:c,skipFirstTrigger:h=!1,select:d="*",storageType:u="object",patchText:f=!1,patchJSON:m=!1,onError:g}){if(this.throttle=100,this.batch_size=50,this.skipFirstTrigger=!1,this.columns=[],this._multiSubscriptions=[],this._singleSubscriptions=[],this.items=[],this.itemsObj={},this.isSynced=!1,this.updatePatches=async e=>{let t=e.map((e=>e.current)),n=[],s=[];if(this.columns&&this.columns.length&&this.db[this.name].updateBatch&&(this.patchText||this.patchJSON)){const r=this.columns.filter((e=>"text"===e.data_type));if(this.patchText&&r.length){t=[];const o=[this.synced_field,...this.id_fields];await Promise.all(e.slice(0).map((async(e,a)=>{const{current:l,initial:c}={...e};let h;c&&(r.map((e=>{!o.includes(e.name)&&e.name in l&&(null!=h||(h={...l}),h[e.name]=(0,i.getTextPatch)(c[e.name],l[e.name]))})),h&&this.wal&&(s.push(h),n.push([this.wal.getIdObj(h),this.wal.getDeltaObj(h)]))),h||t.push(l)})))}}if(n.length)try{await this.db[this.name].updateBatch(n)}catch(e){console.log("failed to patch update",e),t=t.concat(s)}return t.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)=>{const n=this.getIdObj(e);return this.setItem(n,void 0,!0,!0),t||await this.db[this.name].delete(n),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},h={...e.delta};Object.keys(h).map((e=>{void 0===h[e]&&(h[e]=null)})),t||this.checkItemCols({...e.delta,...e.idObj});let d=this.getItem(c),u=d.index,f=d.data;!t&&!(0,i.isEmpty)(h)||(0,i.isEmpty)(f)||(h=this.getDelta(f||{},h)),t||(h[this.synced_field]=Date.now());let m={...f,...h,...c};f&&!t&&(null===(s=e.opts)||void 0===s?void 0:s.deepMerge)&&(m=l({...f,...c},{...h})),r=f?f[this.synced_field]<m[this.synced_field]?"updated":"unchanged":"inserted",this.setItem(m,u);let g={idObj:c,delta:h,oldItem:f,newItem:m,status:r,from_server:t};return t||a.push({initial:f,current:{...m}}),g.delta&&!(0,i.isEmpty)(g.delta)&&o.push(g),!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=>{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(e))}else this.storageType===o.array?this.items=e:this.itemsObj=e.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 e.map((e=>({...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=d,this.onChange=s,!o[u])throw"Invalid storage type. Expecting one of: "+Object.keys(o).join(", ");if(r||u!==o.localStorage||(console.warn("Could not set storageType to localStorage: window object missing\nStorage changed to object"),u="object"),this.storageType=u,this.patchText=f,this.patchJSON=m,!c)throw"db missing";this.db=c;const{id_fields:p,synced_field:y,throttle:b=100,batch_size:S=50}=c[this.name]._syncInfo;if(!p||!y)throw"id_fields/synced_field missing";this.id_fields=p,this.synced_field=y,this.batch_size=S,this.throttle=b,this.skipFirstTrigger=h,this.multiSubscriptions=[],this.singleSubscriptions=[],this.onError=g||function(e){console.error("Sync internal error: ",e)},c[this.name]._sync(n,{select:d},{onSyncRequest:e=>{let t={c_lr:void 0,c_fr:void 0,c_count:0},n=this.getBatch(e);return n.length&&(t={c_fr:this.getRowSyncObj(n[0]),c_lr:this.getRowSyncObj(n[n.length-1]),c_count:n.length}),t},onPullRequest:async e=>this.getBatch(e),onUpdates:async e=>{var t;if("err"in e&&e.err)null===(t=this.onError)||void 0===t||t.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;const n={id_fields:p,synced_field:y,throttle:b};this.wal=new i.WAL({...n,batch_size:S,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({...n,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()})),c[this.name].getColumns&&c[this.name].getColumns().then((e=>{this.columns=e})),this.onChange&&!this.skipFirstTrigger&&setTimeout(this.onChange,0),(0,t.debug)(this)}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}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.wal.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)))}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:t?{...t}:t,index:-1}}setItem(e,t,n=!1,i=!1){if(this.storageType===o.localStorage){let s=this.getItems();i?s=s.filter((t=>!this.matchesIdObj(t,e))):void 0!==t&&s[t]?s[t]=n?{...e}:{...s[t],...e}:s.push(e),r&&window.localStorage.setItem(this.name,JSON.stringify(s))}else if(this.storageType===o.array)i?this.items=this.items.filter((t=>!this.matchesIdObj(t,e))):void 0===t||this.items[t]?void 0!==t&&(this.items[t]=n?{...e}:{...this.items[t],...e}):this.items.push(e);else if(this.itemsObj=this.itemsObj||{},i)delete this.itemsObj[this.getIdStr(e)];else{let t=this.itemsObj[this.getIdStr(e)]||{};this.itemsObj[this.getIdStr(e)]=n?{...e}:{...t,...e}}}}function l(e,t){let n=Object.assign({},e);return(0,i.isObject)(e)&&(0,i.isObject)(t)&&Object.keys(t).forEach((s=>{(0,i.isObject)(t[s])?s in e?n[s]=l(e[s],t[s]):Object.assign(n,{[s]:t[s]}):Object.assign(n,{[s]:t[s]})})),n}t.SyncedTable=a,t.default=l},274:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prostgles=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)},t.prostgles=function(e,n){const{socket:s,onReady:r,onDisconnect:o,onReconnect:a,onSchemaChange:l=!0}=e;if((0,t.debug)("prostgles",{initOpts:e}),l){let e;"function"==typeof l&&(e=l),s.removeAllListeners(i.CHANNELS.SCHEMA_CHANGED),e&&s.on(i.CHANNELS.SCHEMA_CHANGED,e)}const c=i.CHANNELS._preffix;let h,d={},u={},f={},m={},g=!1;function p(e,n){return(0,t.debug)("_unsubscribe",{channelName:e,handler:n}),new Promise(((t,i)=>{d[e]?(d[e].handlers=d[e].handlers.filter((e=>e!==n)),d[e].handlers.length||(s.emit(e+"unsubscribe",{},((e,t)=>{e&&console.error(e)})),s.removeListener(e,d[e].onCall),delete d[e]),t(!0)):t(!0)}))}function y({tableName:e,command:t,param1:n,param2:i},r){return new Promise(((o,a)=>{s.emit(c,{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 b({tableName:e,command:t,param1:n,param2:i}){return new Promise(((r,o)=>{s.emit(c,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{e?(console.error(e),o(e)):t&&r(t.channelName)}))}))}async function S(e,{tableName:t,command:n,param1:i,param2:r},o,a){function l(n){let s={unsubscribe:function(){return p(n,o)},filter:{...i}};return e[t].update&&(s={...s,update:function(n,s){return e[t].update(i,n,s)}}),e[t].delete&&(s={...s,delete:function(n){return e[t].delete(i,n)}}),Object.freeze(s)}const c=Object.keys(d).find((e=>{let s=d[e];return s.tableName===t&&s.command===n&&JSON.stringify(s.param1||{})===JSON.stringify(i||{})&&JSON.stringify(s.param2||{})===JSON.stringify(r||{})}));if(c)return d[c].handlers.push(o),setTimeout((()=>{o&&(null==d?void 0:d[c].lastData)&&o(null==d?void 0:d[c].lastData)}),10),l(c);{const e=await b({tableName:t,command:n,param1:i,param2:r});let c=function(t,n){d[e]?t.data?(d[e].lastData=t.data,d[e].handlers.map((e=>{e(t.data)}))):t.err?d[e].errorHandlers.map((e=>{e(t.err)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",t):console.warn("Orphaned subscription: ",e)},h=a||function(t){console.error(`Uncaught error within running subscription \n ${e}`,t)};return s.on(e,c),d[e]={lastData:void 0,tableName:t,command:n,param1:i,param2:r,onCall:c,handlers:[o],errorHandlers:[h],destroy:()=>{d[e]&&(Object.values(d[e]).map((t=>{t&&t.handlers&&t.handlers.map((t=>p(e,t)))})),delete d[e])}},l(e)}}return new Promise(((e,l)=>{o&&s.on("disconnect",o),s.on(i.CHANNELS.SCHEMA,(({schema:o,methods:p,fullSchema:_,auth:O,rawSQL:j,joinTables:w=[],err:v})=>{if(v)throw l(v),v;(0,t.debug)("destroySyncs",{subscriptions:d,syncedTables:u}),Object.values(d).map((e=>e.destroy())),d={},f={},Object.values(u).map((e=>{e&&e.destroy&&e.destroy()})),u={},g&&a&&a(s),g=!0;let N=JSON.parse(JSON.stringify(o)),C=JSON.parse(JSON.stringify(p)),T={},E={};if(O){if(O.pathGuard){const e=e=>{var t,n;(null==e?void 0:e.shouldReload)&&"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)}))}E={...O},[i.CHANNELS.LOGIN,i.CHANNELS.LOGOUT,i.CHANNELS.REGISTER].map((e=>{O[e]&&(E[e]=function(t){return new Promise(((n,i)=>{s.emit(c+e,t,((e,t)=>{e?i(e):n(t)}))}))})}))}C.map((e=>{T[e]=function(...t){return new Promise(((n,r)=>{s.emit(i.CHANNELS.METHOD,{method:e,params:t},((e,t)=>{e?r(e):n(t)}))}))}})),T=Object.freeze(T),j&&(N.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)=>{h=h||{config:t,listeners:[]},h.listeners.length||(s.removeAllListeners(t.socketChannel),s.on(t.socketChannel,(e=>{h&&h.listeners&&h.listeners.length?h.listeners.map((t=>{t(e)})):s.emit(t.socketUnsubChannel,{})}))),h.listeners.push(e)})(t,e),{...e,removeListener:()=>(e=>{h&&(h.listeners=h.listeners.filter((t=>t!==e)),!h.listeners.length&&h.config&&h.config.socketUnsubChannel&&s&&s.emit(h.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)=>{m=m||{},m[t.notifChannel]?m[t.notifChannel].listeners.push(e):(m[t.notifChannel]={config:t,listeners:[e]},s.removeAllListeners(t.socketChannel),s.on(t.socketChannel,(e=>{m[t.notifChannel]&&m[t.notifChannel].listeners&&m[t.notifChannel].listeners.length?m[t.notifChannel].listeners.map((t=>{t(e)})):s.emit(m[t.notifChannel].config.socketUnsubChannel,{})})))})(e,t),{...t,removeListener:()=>((e,t)=>{m&&m[t.notifChannel]&&(m[t.notifChannel].listeners=m[t.notifChannel].listeners.filter((t=>t!==e)),!m[t.notifChannel].listeners.length&&m[t.notifChannel].config&&m[t.notifChannel].config.socketUnsubChannel&&s&&(s.emit(m[t.notifChannel].config.socketUnsubChannel,{}),delete m[t.notifChannel]))})(e,t)}),n={...t,addListener:e};r(n)}}))}))});const I=e=>"[object Object]"===Object.prototype.toString.call(e),P=(e,t,n,i)=>{if(!I(e)||!I(t)||"function"!=typeof n||i&&"function"!=typeof i)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},A=["subscribe","subscribeOne"];Object.keys(N).forEach((e=>{Object.keys(N[e]).sort(((e,t)=>A.includes(e)-A.includes(t))).forEach((i=>{if(["find","findOne"].includes(i)&&(N[e].getJoinedTables=function(){return(w||[]).filter((t=>Array.isArray(t)&&t.includes(e))).flat().filter((t=>t!==e))}),"sync"===i){if(N[e]._syncInfo={...N[e][i]},n){N[e].getSync=(t,i={})=>n.create({name:e,filter:t,db:N,...i});const t=async(t={},i={},s)=>{const r=`${e}.${JSON.stringify(t)}.${JSON.stringify(i)}`;return u[r]||(u[r]=await n.create({...i,name:e,filter:t,db:N,onError:s})),u[r]};N[e].sync=async(e,n={handlesOnData:!0,select:"*"},i,s)=>{P(e,n,i,s);const r=await t(e,n,s);return await r.sync(i,n.handlesOnData)},N[e].syncOne=async(e,n={handlesOnData:!0},i,s)=>{P(e,n,i,s);const r=await t(e,n,s);return await r.syncOne(e,i,n.handlesOnData)}}N[e]._sync=function(n,r,o){return async function({tableName:e,command:n,param1:i,param2:r},o){const{onPullRequest:a,onSyncRequest:l,onUpdates:c}=o;function h(e){return Object.freeze({unsync:function(){!function(e,n){(0,t.debug)("_unsync",{channelName:e,triggers:n}),new Promise(((t,i)=>{f[e]&&(f[e].triggers=f[e].triggers.filter((e=>e.onPullRequest!==n.onPullRequest&&e.onSyncRequest!==n.onSyncRequest&&e.onUpdates!==n.onUpdates)),f[e].triggers.length||(s.emit(e+"unsync",{},((e,n)=>{e?i(e):t(n)})),s.removeListener(e,f[e].onCall),delete f[e]))}))}(e,o)},syncData:function(t,n,i){s.emit(e,{onSyncRequest:{...l({}),...{data:t}||{},...{deleted:n}||{}}},i?e=>{i(e)}:null)}})}const d=Object.keys(f).find((t=>{let s=f[t];return s.tableName===e&&s.command===n&&JSON.stringify(s.param1||{})===JSON.stringify(i||{})&&JSON.stringify(s.param2||{})===JSON.stringify(r||{})}));if(d)return f[d].triggers.push(o),h(d);{const u=await y({tableName:e,command:n,param1:i,param2:r},l),{channelName:m,synced_field:g,id_fields:p}=u;function b(t,n){t&&f[m]&&f[m].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 f[m]={tableName:e,command:n,param1:i,param2:r,triggers:[o],syncInfo:u,onCall:b},s.on(m,b),h(m)}}({tableName:e,command:i,param1:n,param2:r},o)}}else if(A.includes(i)){N[e][i]=function(t,n,s,r){return P(t,n,s,r),S(N,{tableName:e,command:i,param1:t,param2:n},s,r)};const t="subscribeOne";i!==t&&A.includes(t)||(N[e][t]=function(t,n,s,r){return P(t,n,s,r),S(N,{tableName:e,command:i,param1:t,param2:n},(e=>{s(e[0])}),r)})}else N[e][i]=function(t,n,r){return new Promise(((o,a)=>{s.emit(c,{tableName:e,command:i,param1:t,param2:n,param3:r},((e,t)=>{e?a(e):o(t)}))}))}}))})),d&&Object.keys(d).length&&Object.keys(d).map((async e=>{try{let t=d[e];await b(t),s.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting old subscriptions",e)}})),f&&Object.keys(f).length&&Object.keys(f).filter((e=>f[e].triggers&&f[e].triggers.length)).map((async e=>{try{let t=f[e];await y(t,t.triggers[0].onSyncRequest),s.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}})),w.flat().map((e=>{function t(t=!0,n,i,s){return{[t?"$leftJoin":"$innerJoin"]:e,filter:n,select:i,...s}}N.innerJoin=N.innerJoin||{},N.leftJoin=N.leftJoin||{},N.innerJoinOne=N.innerJoinOne||{},N.leftJoinOne=N.leftJoinOne||{},N.leftJoin[e]=(e,n,i={})=>t(!0,e,n,i),N.innerJoin[e]=(e,n,i={})=>t(!1,e,n,i),N.leftJoinOne[e]=(e,n,i={})=>t(!0,e,n,{...i,limit:1}),N.innerJoinOne[e]=(e,n,i={})=>t(!1,e,n,{...i,limit:1})})),(async()=>{try{await r(N,T,_,E)}catch(e){console.error("Prostgles: Error within onReady: \n",e),l(e)}e(N)})()}))}))}},792:function(e){var t;this||window,t=()=>(()=>{"use strict";var e={444:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.TextFilterFTSKeys=t.TextFilter_FullTextSearchFilterKeys=t.CompareInFilterKeys=t.CompareFilterKeys=void 0,t.CompareFilterKeys=["=","$eq","<>",">",">=","<=","$eq","$ne","$gt","$gte","$lte"],t.CompareInFilterKeys=["$in","$nin"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"];const n=["ST_MakeEnvelope","ST_MakePolygon"];t.GeomFilter_Funcs=n.concat(n.map((e=>e.toLowerCase()))),t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"]},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.getKeys=t.isObject=t.isDefined=t.get=t.WAL=t.unpatchText=t.stableStringify=t.isEmpty=t.getTextPatch=t.asName=t.RULE_METHODS=t.CHANNELS=t.TS_PG_Types=t._PG_postgis=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","inet","time","timetz","interval","name"],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_postgis=["geometry","geography"],t.TS_PG_Types={string:t._PG_strings,number:t._PG_numbers,boolean:t._PG_bool,Object:t._PG_json,Date:t._PG_date,"Array<number>":t._PG_numbers.map((e=>`_${e}`)),"Array<boolean>":t._PG_bool.map((e=>`_${e}`)),"Array<string>":t._PG_strings.map((e=>`_${e}`)),"Array<Object>":t._PG_json.map((e=>`_${e}`)),"Array<Date>":t._PG_date.map((e=>`_${e}`)),any:[]};const r="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:r+"schema-changed",SCHEMA:r+"schema",DEFAULT:r,SQL:"_psqlWS_.sql",METHOD:"_psqlWS_.method",NOTICE_EV:"_psqlWS_.notice",LISTEN_EV:"_psqlWS_.listen",REGISTER:"_psqlWS_.register",LOGIN:"_psqlWS_.login",LOGOUT:"_psqlWS_.logout",AUTHGUARD:"_psqlWS_.authguard",_preffix:r},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"]};var o=n(128);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return o.asName}}),Object.defineProperty(t,"getTextPatch",{enumerable:!0,get:function(){return o.getTextPatch}}),Object.defineProperty(t,"isEmpty",{enumerable:!0,get:function(){return o.isEmpty}}),Object.defineProperty(t,"stableStringify",{enumerable:!0,get:function(){return o.stableStringify}}),Object.defineProperty(t,"unpatchText",{enumerable:!0,get:function(){return o.unpatchText}}),Object.defineProperty(t,"WAL",{enumerable:!0,get:function(){return o.WAL}}),Object.defineProperty(t,"get",{enumerable:!0,get:function(){return o.get}}),Object.defineProperty(t,"isDefined",{enumerable:!0,get:function(){return o.isDefined}}),Object.defineProperty(t,"isObject",{enumerable:!0,get:function(){return o.isObject}}),Object.defineProperty(t,"getKeys",{enumerable:!0,get:function(){return o.getKeys}}),s(n(444),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]=u(n,e[0]),e[1]=u(i,e[1]),e[2]=u(l,e[2]),e[3]=u(c,e[3])}function i(e,t,n,i,s,r){return t=u(u(t,e),u(i,r)),u(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 h(e){for(var t="",n=0;n<4;n++)t+=c[e>>8*n+4&15]+c[e>>8*n&15];return t}function d(e){return function(e){for(var t=0;t<e.length;t++)e[t]=h(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 u(e,t){return e+t&4294967295}t.md5=d,d("hello")},128:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getKeys=t.isDefined=t.isObject=t.get=t.isEmpty=t.WAL=t.unpatchText=t.getTextPatch=t.stableStringify=t.asName=void 0;const i=n(899);function s(e){for(var t in e)return!1;return!0}t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},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],h=e(t[c]);h&&(o&&(o+=","),o+=JSON.stringify(c)+":"+h)}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=>{s(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map((e=>{var t;const{initial:n,current:i}={...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}),this.changed[s].current={...this.changed[s].current,...i}})),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&&!s(this.sending))return;if(!this.changed||s(this.changed))return;let a,l=[],c=[],h={};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}),h[e]={...t.current},delete this.changed[e]})),l=c.map((e=>e.current)),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout((()=>{this.isSendingTimeout=void 0,s(this.changed)||this.sendItems()}),r)),this.isOnSending=!0;try{await t(l,c),o&&(this.sentHistory={...this.sentHistory,...h},this.willDeleteHistory||(this.willDeleteHistory=setTimeout((()=>{this.willDeleteHistory=void 0,this.sentHistory={}}),1e3*o)))}catch(e){a=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(a)})),this.callbacks=this.callbacks.filter((e=>e.idStrs.length))}this.sending={},e&&console.log(this.options.id," SENT lr->",l[l.length-1]),s(this.changed)?n&&n(l,c,a):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||!(s(this.sending)&&s(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=s,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=function(e){return Object.keys(e)}}},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.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{constructor({name:e,filter:n,onChange:s,onReady:a,db:c,skipFirstTrigger:d=!1,select:h="*",storageType:u="object",patchText:f=!1,patchJSON:m=!1,onError:g}){if(this.throttle=100,this.batch_size=50,this.skipFirstTrigger=!1,this.columns=[],this._multiSubscriptions=[],this._singleSubscriptions=[],this.items=[],this.itemsObj={},this.isSynced=!1,this.updatePatches=async e=>{var t,n;let s=e.map((e=>e.current)),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 h=this.getItem(c),u=h.index,f=h.data;!t&&!(0,i.isEmpty)(d)||(0,i.isEmpty)(f)||(d=this.getDelta(f||{},d)),t||(d[this.synced_field]=Date.now());let m={...f,...d,...c};f&&!t&&(null===(s=e.opts)||void 0===s?void 0:s.deepMerge)&&(m=l({...f,...c},{...d})),r=f?f[this.synced_field]<m[this.synced_field]?"updated":"unchanged":"inserted",this.setItem(m,u);let g={idObj:c,delta:d,oldItem:f,newItem:m,status:r,from_server:t};return t||a.push({initial:f,current:{...m}}),g.delta&&!(0,i.isEmpty)(g.delta)&&o.push(g),!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=>{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(e))}else this.storageType===o.array?this.items=e:this.itemsObj=e.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 e.map((e=>({...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=h,this.onChange=s,!o[u])throw"Invalid storage type. Expecting one of: "+Object.keys(o).join(", ");if(r||u!==o.localStorage||(console.warn("Could not set storageType to localStorage: window object missing\nStorage changed to object"),u="object"),this.storageType=u,this.patchText=f,this.patchJSON=m,!c)throw"db missing";this.db=c;const{id_fields:p,synced_field:y,throttle:b=100,batch_size:S=50}=c[this.name]._syncInfo;if(!p||!y)throw"id_fields/synced_field missing";this.id_fields=p,this.synced_field=y,this.batch_size=S,this.throttle=b,this.skipFirstTrigger=d,this.multiSubscriptions=[],this.singleSubscriptions=[],this.onError=g||function(e){console.error("Sync internal error: ",e)};const _={id_fields:p,synced_field:y,throttle:b};c[this.name]._sync(n,{select:h},{onSyncRequest:e=>{let t={c_lr:void 0,c_fr:void 0,c_count:0},n=this.getBatch(e);return n.length&&(t={c_fr:this.getRowSyncObj(n[0]),c_lr:this.getRowSyncObj(n[n.length-1]),c_count:n.length}),t},onPullRequest:async e=>this.getBatch(e),onUpdates:async e=>{var t;if("err"in e&&e.err)null===(t=this.onError)||void 0===t||t.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:S,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()})),c[this.name].getColumns&&c[this.name].getColumns().then((e=>{this.columns=e})),this.onChange&&!this.skipFirstTrigger&&setTimeout(this.onChange,0),(0,t.debug)(this)}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}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(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:t?{...t}:t,index:-1}}setItem(e,t,n=!1,i=!1){if(this.storageType===o.localStorage){let s=this.getItems();i?s=s.filter((t=>!this.matchesIdObj(t,e))):void 0!==t&&s[t]?s[t]=n?{...e}:{...s[t],...e}:s.push(e),r&&window.localStorage.setItem(this.name,JSON.stringify(s))}else if(this.storageType===o.array)i?this.items=this.items.filter((t=>!this.matchesIdObj(t,e))):void 0===t||this.items[t]?void 0!==t&&(this.items[t]=n?{...e}:{...this.items[t],...e}):this.items.push(e);else if(this.itemsObj=this.itemsObj||{},i)delete this.itemsObj[this.getIdStr(e)];else{let t=this.itemsObj[this.getIdStr(e)]||{};this.itemsObj[this.getIdStr(e)]=n?{...e}:{...t,...e}}}}function l(e,t){let n=Object.assign({},e);return(0,i.isObject)(e)&&(0,i.isObject)(t)&&Object.keys(t).forEach((s=>{(0,i.isObject)(t[s])?s in e?n[s]=l(e[s],t[s]):Object.assign(n,{[s]:t[s]}):Object.assign(n,{[s]:t[s]})})),n}t.SyncedTable=a,t.default=l},274:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prostgles=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)},t.prostgles=function(e,n){const{socket:s,onReady:r,onDisconnect:o,onReconnect:a,onSchemaChange:l=!0}=e;if((0,t.debug)("prostgles",{initOpts:e}),l){let e;"function"==typeof l&&(e=l),s.removeAllListeners(i.CHANNELS.SCHEMA_CHANGED),e&&s.on(i.CHANNELS.SCHEMA_CHANGED,e)}const c=i.CHANNELS._preffix;let d,h={},u={},f={},m={},g=!1;function p(e,n){return(0,t.debug)("_unsubscribe",{channelName:e,handler:n}),new Promise(((t,i)=>{h[e]?(h[e].handlers=h[e].handlers.filter((e=>e!==n)),h[e].handlers.length||(s.emit(e+"unsubscribe",{},((e,t)=>{e&&console.error(e)})),s.removeListener(e,h[e].onCall),delete h[e]),t(!0)):t(!0)}))}function y({tableName:e,command:t,param1:n,param2:i},r){return new Promise(((o,a)=>{s.emit(c,{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 b({tableName:e,command:t,param1:n,param2:i}){return new Promise(((r,o)=>{s.emit(c,{tableName:e,command:t,param1:n,param2:i},((e,t)=>{e?(console.error(e),o(e)):t&&r(t.channelName)}))}))}async function S(e,{tableName:t,command:n,param1:i,param2:r},o,a){function l(n){let s={unsubscribe:function(){return p(n,o)},filter:{...i}};return e[t].update&&(s={...s,update:function(n,s){return e[t].update(i,n,s)}}),e[t].delete&&(s={...s,delete:function(n){return e[t].delete(i,n)}}),Object.freeze(s)}const c=Object.keys(h).find((e=>{let s=h[e];return s.tableName===t&&s.command===n&&JSON.stringify(s.param1||{})===JSON.stringify(i||{})&&JSON.stringify(s.param2||{})===JSON.stringify(r||{})}));if(c)return h[c].handlers.push(o),setTimeout((()=>{o&&(null==h?void 0:h[c].lastData)&&o(null==h?void 0:h[c].lastData)}),10),l(c);{const e=await b({tableName:t,command:n,param1:i,param2:r});let c=function(t,n){h[e]?t.data?(h[e].lastData=t.data,h[e].handlers.map((e=>{e(t.data)}))):t.err?h[e].errorHandlers.map((e=>{e(t.err)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",t):console.warn("Orphaned subscription: ",e)},d=a||function(t){console.error(`Uncaught error within running subscription \n ${e}`,t)};return s.on(e,c),h[e]={lastData:void 0,tableName:t,command:n,param1:i,param2:r,onCall:c,handlers:[o],errorHandlers:[d],destroy:()=>{h[e]&&(Object.values(h[e]).map((t=>{t&&t.handlers&&t.handlers.map((t=>p(e,t)))})),delete h[e])}},l(e)}}return new Promise(((e,l)=>{o&&s.on("disconnect",o),s.on(i.CHANNELS.SCHEMA,(({schema:o,methods:p,tableSchema:_,auth:O,rawSQL:j,joinTables:w=[],err:v})=>{if(v)throw l(v),v;(0,t.debug)("destroySyncs",{subscriptions:h,syncedTables:u}),Object.values(h).map((e=>e.destroy())),h={},f={},Object.values(u).map((e=>{e&&e.destroy&&e.destroy()})),u={},g&&a&&a(s),g=!0;let N=JSON.parse(JSON.stringify(o)),C=JSON.parse(JSON.stringify(p)),T={},E={};if(O){if(O.pathGuard){const e=e=>{var t,n;(null==e?void 0:e.shouldReload)&&"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)}))}E={...O},[i.CHANNELS.LOGIN,i.CHANNELS.LOGOUT,i.CHANNELS.REGISTER].map((e=>{O[e]&&(E[e]=function(t){return new Promise(((n,i)=>{s.emit(c+e,t,((e,t)=>{e?i(e):n(t)}))}))})}))}C.map((e=>{T[e]=function(...t){return new Promise(((n,r)=>{s.emit(i.CHANNELS.METHOD,{method:e,params:t},((e,t)=>{e?r(e):n(t)}))}))}})),T=Object.freeze(T),j&&(N.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)=>{d=d||{config:t,listeners:[]},d.listeners.length||(s.removeAllListeners(t.socketChannel),s.on(t.socketChannel,(e=>{d&&d.listeners&&d.listeners.length?d.listeners.map((t=>{t(e)})):s.emit(t.socketUnsubChannel,{})}))),d.listeners.push(e)})(t,e),{...e,removeListener:()=>(e=>{d&&(d.listeners=d.listeners.filter((t=>t!==e)),!d.listeners.length&&d.config&&d.config.socketUnsubChannel&&s&&s.emit(d.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)=>{m=m||{},m[t.notifChannel]?m[t.notifChannel].listeners.push(e):(m[t.notifChannel]={config:t,listeners:[e]},s.removeAllListeners(t.socketChannel),s.on(t.socketChannel,(e=>{m[t.notifChannel]&&m[t.notifChannel].listeners&&m[t.notifChannel].listeners.length?m[t.notifChannel].listeners.map((t=>{t(e)})):s.emit(m[t.notifChannel].config.socketUnsubChannel,{})})))})(e,t),{...t,removeListener:()=>((e,t)=>{m&&m[t.notifChannel]&&(m[t.notifChannel].listeners=m[t.notifChannel].listeners.filter((t=>t!==e)),!m[t.notifChannel].listeners.length&&m[t.notifChannel].config&&m[t.notifChannel].config.socketUnsubChannel&&s&&(s.emit(m[t.notifChannel].config.socketUnsubChannel,{}),delete m[t.notifChannel]))})(e,t)}),n={...t,addListener:e};r(n)}}))}))});const I=e=>"[object Object]"===Object.prototype.toString.call(e),P=(e,t,n,i)=>{if(!I(e)||!I(t)||"function"!=typeof n||i&&"function"!=typeof i)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},A=["subscribe","subscribeOne"];Object.keys(N).forEach((e=>{Object.keys(N[e]).sort(((e,t)=>A.includes(e)-A.includes(t))).forEach((i=>{if(["find","findOne"].includes(i)&&(N[e].getJoinedTables=function(){return(w||[]).filter((t=>Array.isArray(t)&&t.includes(e))).flat().filter((t=>t!==e))}),"sync"===i){if(N[e]._syncInfo={...N[e][i]},n){N[e].getSync=(t,i={})=>n.create({name:e,filter:t,db:N,...i});const t=async(t={},i={},s)=>{const r=`${e}.${JSON.stringify(t)}.${JSON.stringify(i)}`;return u[r]||(u[r]=await n.create({...i,name:e,filter:t,db:N,onError:s})),u[r]};N[e].sync=async(e,n={handlesOnData:!0,select:"*"},i,s)=>{P(e,n,i,s);const r=await t(e,n,s);return await r.sync(i,n.handlesOnData)},N[e].syncOne=async(e,n={handlesOnData:!0},i,s)=>{P(e,n,i,s);const r=await t(e,n,s);return await r.syncOne(e,i,n.handlesOnData)}}N[e]._sync=function(n,r,o){return 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)=>{f[e]&&(f[e].triggers=f[e].triggers.filter((e=>e.onPullRequest!==n.onPullRequest&&e.onSyncRequest!==n.onSyncRequest&&e.onUpdates!==n.onUpdates)),f[e].triggers.length||(s.emit(e+"unsync",{},((e,n)=>{e?i(e):t(n)})),s.removeListener(e,f[e].onCall),delete f[e]))}))}(e,o)},syncData:function(t,n,i){s.emit(e,{onSyncRequest:{...l({}),...{data:t}||{},...{deleted:n}||{}}},i?e=>{i(e)}:null)}})}const h=Object.keys(f).find((t=>{let s=f[t];return s.tableName===e&&s.command===n&&JSON.stringify(s.param1||{})===JSON.stringify(i||{})&&JSON.stringify(s.param2||{})===JSON.stringify(r||{})}));if(h)return f[h].triggers.push(o),d(h);{const u=await y({tableName:e,command:n,param1:i,param2:r},l),{channelName:m,synced_field:g,id_fields:p}=u;function b(t,n){t&&f[m]&&f[m].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 f[m]={tableName:e,command:n,param1:i,param2:r,triggers:[o],syncInfo:u,onCall:b},s.on(m,b),d(m)}}({tableName:e,command:i,param1:n,param2:r},o)}}else if(A.includes(i)){N[e][i]=function(t,n,s,r){return P(t,n,s,r),S(N,{tableName:e,command:i,param1:t,param2:n},s,r)};const t="subscribeOne";i!==t&&A.includes(t)||(N[e][t]=function(t,n,s,r){return P(t,n,s,r),S(N,{tableName:e,command:i,param1:t,param2:n},(e=>{s(e[0])}),r)})}else N[e][i]=function(t,n,r){return new Promise(((o,a)=>{s.emit(c,{tableName:e,command:i,param1:t,param2:n,param3:r},((e,t)=>{e?a(e):o(t)}))}))}}))})),h&&Object.keys(h).length&&Object.keys(h).map((async e=>{try{let t=h[e];await b(t),s.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting old subscriptions",e)}})),f&&Object.keys(f).length&&Object.keys(f).filter((e=>f[e].triggers&&f[e].triggers.length)).map((async e=>{try{let t=f[e];await y(t,t.triggers[0].onSyncRequest),s.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}})),w.flat().map((e=>{function t(t=!0,n,i,s){return{[t?"$leftJoin":"$innerJoin"]:e,filter:n,select:i,...s}}N.innerJoin=N.innerJoin||{},N.leftJoin=N.leftJoin||{},N.innerJoinOne=N.innerJoinOne||{},N.leftJoinOne=N.leftJoinOne||{},N.leftJoin[e]=(e,n,i={})=>t(!0,e,n,i),N.innerJoin[e]=(e,n,i={})=>t(!1,e,n,i),N.leftJoinOne[e]=(e,n,i={})=>t(!0,e,n,{...i,limit:1}),N.innerJoinOne[e]=(e,n,i={})=>t(!1,e,n,{...i,limit:1})})),(async()=>{try{await r(N,T,_,E)}catch(e){console.error("Prostgles: Error within onReady: \n",e),l(e)}e(N)})()}))}))}},792:function(e){var t;this||window,t=()=>(()=>{"use strict";var e={444:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.TextFilterFTSKeys=t.TextFilter_FullTextSearchFilterKeys=t.TextFilterKeys=t.CompareInFilterKeys=t.CompareFilterKeys=void 0,t.CompareFilterKeys=["=","$eq","<>",">",">=","<=","$eq","$ne","$gt","$gte","$lte"],t.CompareInFilterKeys=["$in","$nin"],t.TextFilterKeys=["$ilike","$like"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"];const n=["ST_MakeEnvelope","ST_MakePolygon"];t.GeomFilter_Funcs=n.concat(n.map((e=>e.toLowerCase()))),t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"]},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.getKeys=t.isObject=t.isDefined=t.get=t.WAL=t.unpatchText=t.stableStringify=t.isEmpty=t.getTextPatch=t.asName=t.RULE_METHODS=t.CHANNELS=t.TS_PG_Types=t._PG_postgis=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","inet","time","timetz","interval","name"],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_postgis=["geometry","geography"],t.TS_PG_Types={string:t._PG_strings,number:t._PG_numbers,boolean:t._PG_bool,Date:t._PG_date,"Array<number>":t._PG_numbers.map((e=>`_${e}`)),"Array<boolean>":t._PG_bool.map((e=>`_${e}`)),"Array<string>":t._PG_strings.map((e=>`_${e}`)),"Array<Object>":t._PG_json.map((e=>`_${e}`)),"Array<Date>":t._PG_date.map((e=>`_${e}`)),any:[]};const r="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:r+"schema-changed",SCHEMA:r+"schema",DEFAULT:r,SQL:"_psqlWS_.sql",METHOD:"_psqlWS_.method",NOTICE_EV:"_psqlWS_.notice",LISTEN_EV:"_psqlWS_.listen",REGISTER:"_psqlWS_.register",LOGIN:"_psqlWS_.login",LOGOUT:"_psqlWS_.logout",AUTHGUARD:"_psqlWS_.authguard",_preffix:r},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"]};var o=n(128);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return o.asName}}),Object.defineProperty(t,"getTextPatch",{enumerable:!0,get:function(){return o.getTextPatch}}),Object.defineProperty(t,"isEmpty",{enumerable:!0,get:function(){return o.isEmpty}}),Object.defineProperty(t,"stableStringify",{enumerable:!0,get:function(){return o.stableStringify}}),Object.defineProperty(t,"unpatchText",{enumerable:!0,get:function(){return o.unpatchText}}),Object.defineProperty(t,"WAL",{enumerable:!0,get:function(){return o.WAL}}),Object.defineProperty(t,"get",{enumerable:!0,get:function(){return o.get}}),Object.defineProperty(t,"isDefined",{enumerable:!0,get:function(){return o.isDefined}}),Object.defineProperty(t,"isObject",{enumerable:!0,get:function(){return o.isObject}}),Object.defineProperty(t,"getKeys",{enumerable:!0,get:function(){return o.getKeys}}),s(n(444),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]=u(n,e[0]),e[1]=u(i,e[1]),e[2]=u(l,e[2]),e[3]=u(c,e[3])}function i(e,t,n,i,s,r){return t=u(u(t,e),u(i,r)),u(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 h(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 u(e,t){return e+t&4294967295}t.md5=h,h("hello")},128:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getKeys=t.isDefined=t.isObject=t.get=t.isEmpty=t.WAL=t.unpatchText=t.getTextPatch=t.stableStringify=t.asName=void 0;const i=n(899);function s(e){for(var t in e)return!1;return!0}t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},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=>{s(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map((e=>{var t;const{initial:n,current:i}={...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}),this.changed[s].current={...this.changed[s].current,...i}})),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&&!s(this.sending))return;if(!this.changed||s(this.changed))return;let a,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=>e.current)),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout((()=>{this.isSendingTimeout=void 0,s(this.changed)||this.sendItems()}),r)),this.isOnSending=!0;try{await t(l,c),o&&(this.sentHistory={...this.sentHistory,...d},this.willDeleteHistory||(this.willDeleteHistory=setTimeout((()=>{this.willDeleteHistory=void 0,this.sentHistory={}}),1e3*o)))}catch(e){a=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(a)})),this.callbacks=this.callbacks.filter((e=>e.idStrs.length))}this.sending={},e&&console.log(this.options.id," SENT lr->",l[l.length-1]),s(this.changed)?n&&n(l,c,a):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||!(s(this.sending)&&s(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=s,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=function(e){return Object.keys(e)}}},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 +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 r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this||window,(()=>{return e={274:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prostgles=t.debug=void 0;const r=n(792),i="DEBUG_SYNCEDTABLE",s="undefined"!=typeof window;t.debug=function(...e){s&&window[i]&&window[i](...e)},t.prostgles=function(e,n){const{socket:i,onReady:s,onDisconnect:o,onReconnect:a,onSchemaChange:l=!0}=e;if((0,t.debug)("prostgles",{initOpts:e}),l){let e;"function"==typeof l&&(e=l),i.removeAllListeners(r.CHANNELS.SCHEMA_CHANGED),e&&i.on(r.CHANNELS.SCHEMA_CHANGED,e)}const c=r.CHANNELS._preffix;let u,d={},f={},m={},h={},p=!1;function g(e,n){return(0,t.debug)("_unsubscribe",{channelName:e,handler:n}),new Promise(((t,r)=>{d[e]?(d[e].handlers=d[e].handlers.filter((e=>e!==n)),d[e].handlers.length||(i.emit(e+"unsubscribe",{},((e,t)=>{e&&console.error(e)})),i.removeListener(e,d[e].onCall),delete d[e]),t(!0)):t(!0)}))}function y({tableName:e,command:t,param1:n,param2:r},s){return new Promise(((o,a)=>{i.emit(c,{tableName:e,command:t,param1:n,param2:r},((e,t)=>{if(e)console.error(e),a(e);else if(t){const{id_fields:e,synced_field:n,channelName:r}=t;i.emit(r,{onSyncRequest:s({})},(e=>{console.log(e)})),o({id_fields:e,synced_field:n,channelName:r})}}))}))}function b({tableName:e,command:t,param1:n,param2:r}){return new Promise(((s,o)=>{i.emit(c,{tableName:e,command:t,param1:n,param2:r},((e,t)=>{e?(console.error(e),o(e)):t&&s(t.channelName)}))}))}async function _(e,{tableName:t,command:n,param1:r,param2:s},o,a){function l(n){let i={unsubscribe:function(){return g(n,o)},filter:{...r}};return e[t].update&&(i={...i,update:function(n,i){return e[t].update(r,n,i)}}),e[t].delete&&(i={...i,delete:function(n){return e[t].delete(r,n)}}),Object.freeze(i)}const c=Object.keys(d).find((e=>{let i=d[e];return i.tableName===t&&i.command===n&&JSON.stringify(i.param1||{})===JSON.stringify(r||{})&&JSON.stringify(i.param2||{})===JSON.stringify(s||{})}));if(c)return d[c].handlers.push(o),setTimeout((()=>{o&&(null==d?void 0:d[c].lastData)&&o(null==d?void 0:d[c].lastData)}),10),l(c);{const e=await b({tableName:t,command:n,param1:r,param2:s});let c=function(t,n){d[e]?t.data?(d[e].lastData=t.data,d[e].handlers.map((e=>{e(t.data)}))):t.err?d[e].errorHandlers.map((e=>{e(t.err)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",t):console.warn("Orphaned subscription: ",e)},u=a||function(t){console.error(`Uncaught error within running subscription \n ${e}`,t)};return i.on(e,c),d[e]={lastData:void 0,tableName:t,command:n,param1:r,param2:s,onCall:c,handlers:[o],errorHandlers:[u],destroy:()=>{d[e]&&(Object.values(d[e]).map((t=>{t&&t.handlers&&t.handlers.map((t=>g(e,t)))})),delete d[e])}},l(e)}}return new Promise(((e,l)=>{o&&i.on("disconnect",o),i.on(r.CHANNELS.SCHEMA,(({schema:o,methods:g,fullSchema:S,auth:O,rawSQL:N,joinTables:v=[],err:C})=>{if(C)throw l(C),C;(0,t.debug)("destroySyncs",{subscriptions:d,syncedTables:f}),Object.values(d).map((e=>e.destroy())),d={},m={},Object.values(f).map((e=>{e&&e.destroy&&e.destroy()})),f={},p&&a&&a(i),p=!0;let j=JSON.parse(JSON.stringify(o)),E=JSON.parse(JSON.stringify(g)),P={},w={};if(O){if(O.pathGuard){const e=e=>{var t,n;(null==e?void 0:e.shouldReload)&&"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))};i.emit(r.CHANNELS.AUTHGUARD,JSON.stringify(window.location),((t,n)=>{e(n)})),i.removeAllListeners(r.CHANNELS.AUTHGUARD),i.on(r.CHANNELS.AUTHGUARD,(t=>{e(t)}))}w={...O},[r.CHANNELS.LOGIN,r.CHANNELS.LOGOUT,r.CHANNELS.REGISTER].map((e=>{O[e]&&(w[e]=function(t){return new Promise(((n,r)=>{i.emit(c+e,t,((e,t)=>{e?r(e):n(t)}))}))})}))}E.map((e=>{P[e]=function(...t){return new Promise(((n,s)=>{i.emit(r.CHANNELS.METHOD,{method:e,params:t},((e,t)=>{e?s(e):n(t)}))}))}})),P=Object.freeze(P),N&&(j.sql=function(e,t,n){return new Promise(((s,o)=>{i.emit(r.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)=>{u=u||{config:t,listeners:[]},u.listeners.length||(i.removeAllListeners(t.socketChannel),i.on(t.socketChannel,(e=>{u&&u.listeners&&u.listeners.length?u.listeners.map((t=>{t(e)})):i.emit(t.socketUnsubChannel,{})}))),u.listeners.push(e)})(t,e),{...e,removeListener:()=>(e=>{u&&(u.listeners=u.listeners.filter((t=>t!==e)),!u.listeners.length&&u.config&&u.config.socketUnsubChannel&&i&&i.emit(u.config.socketUnsubChannel,{}))})(t)}),r={...e,addListener:n};s(r)}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)=>{h=h||{},h[t.notifChannel]?h[t.notifChannel].listeners.push(e):(h[t.notifChannel]={config:t,listeners:[e]},i.removeAllListeners(t.socketChannel),i.on(t.socketChannel,(e=>{h[t.notifChannel]&&h[t.notifChannel].listeners&&h[t.notifChannel].listeners.length?h[t.notifChannel].listeners.map((t=>{t(e)})):i.emit(h[t.notifChannel].config.socketUnsubChannel,{})})))})(e,t),{...t,removeListener:()=>((e,t)=>{h&&h[t.notifChannel]&&(h[t.notifChannel].listeners=h[t.notifChannel].listeners.filter((t=>t!==e)),!h[t.notifChannel].listeners.length&&h[t.notifChannel].config&&h[t.notifChannel].config.socketUnsubChannel&&i&&(i.emit(h[t.notifChannel].config.socketUnsubChannel,{}),delete h[t.notifChannel]))})(e,t)}),n={...t,addListener:e};s(n)}}))}))});const T=e=>"[object Object]"===Object.prototype.toString.call(e),A=(e,t,n,r)=>{if(!T(e)||!T(t)||"function"!=typeof n||r&&"function"!=typeof r)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},x=["subscribe","subscribeOne"];Object.keys(j).forEach((e=>{Object.keys(j[e]).sort(((e,t)=>x.includes(e)-x.includes(t))).forEach((r=>{if(["find","findOne"].includes(r)&&(j[e].getJoinedTables=function(){return(v||[]).filter((t=>Array.isArray(t)&&t.includes(e))).flat().filter((t=>t!==e))}),"sync"===r){if(j[e]._syncInfo={...j[e][r]},n){j[e].getSync=(t,r={})=>n.create({name:e,filter:t,db:j,...r});const t=async(t={},r={},i)=>{const s=`${e}.${JSON.stringify(t)}.${JSON.stringify(r)}`;return f[s]||(f[s]=await n.create({...r,name:e,filter:t,db:j,onError:i})),f[s]};j[e].sync=async(e,n={handlesOnData:!0,select:"*"},r,i)=>{A(e,n,r,i);const s=await t(e,n,i);return await s.sync(r,n.handlesOnData)},j[e].syncOne=async(e,n={handlesOnData:!0},r,i)=>{A(e,n,r,i);const s=await t(e,n,i);return await s.syncOne(e,r,n.handlesOnData)}}j[e]._sync=function(n,s,o){return async function({tableName:e,command:n,param1:r,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,r)=>{m[e]&&(m[e].triggers=m[e].triggers.filter((e=>e.onPullRequest!==n.onPullRequest&&e.onSyncRequest!==n.onSyncRequest&&e.onUpdates!==n.onUpdates)),m[e].triggers.length||(i.emit(e+"unsync",{},((e,n)=>{e?r(e):t(n)})),i.removeListener(e,m[e].onCall),delete m[e]))}))}(e,o)},syncData:function(t,n,r){i.emit(e,{onSyncRequest:{...l({}),...{data:t}||{},...{deleted:n}||{}}},r?e=>{r(e)}:null)}})}const d=Object.keys(m).find((t=>{let i=m[t];return i.tableName===e&&i.command===n&&JSON.stringify(i.param1||{})===JSON.stringify(r||{})&&JSON.stringify(i.param2||{})===JSON.stringify(s||{})}));if(d)return m[d].triggers.push(o),u(d);{const f=await y({tableName:e,command:n,param1:r,param2:s},l),{channelName:h,synced_field:p,id_fields:g}=f;function b(t,n){t&&m[h]&&m[h].triggers.map((({onUpdates:r,onSyncRequest:i,onPullRequest:s})=>{t.data?Promise.resolve(r(t)).then((()=>{n&&n({ok:!0})})).catch((t=>{n?n({err:t}):console.error(e+" onUpdates error",t)})):t.onSyncRequest?Promise.resolve(i(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 m[h]={tableName:e,command:n,param1:r,param2:s,triggers:[o],syncInfo:f,onCall:b},i.on(h,b),u(h)}}({tableName:e,command:r,param1:n,param2:s},o)}}else if(x.includes(r)){j[e][r]=function(t,n,i,s){return A(t,n,i,s),_(j,{tableName:e,command:r,param1:t,param2:n},i,s)};const t="subscribeOne";r!==t&&x.includes(t)||(j[e][t]=function(t,n,i,s){return A(t,n,i,s),_(j,{tableName:e,command:r,param1:t,param2:n},(e=>{i(e[0])}),s)})}else j[e][r]=function(t,n,s){return new Promise(((o,a)=>{i.emit(c,{tableName:e,command:r,param1:t,param2:n,param3:s},((e,t)=>{e?a(e):o(t)}))}))}}))})),d&&Object.keys(d).length&&Object.keys(d).map((async e=>{try{let t=d[e];await b(t),i.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting old subscriptions",e)}})),m&&Object.keys(m).length&&Object.keys(m).filter((e=>m[e].triggers&&m[e].triggers.length)).map((async e=>{try{let t=m[e];await y(t,t.triggers[0].onSyncRequest),i.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}})),v.flat().map((e=>{function t(t=!0,n,r,i){return{[t?"$leftJoin":"$innerJoin"]:e,filter:n,select:r,...i}}j.innerJoin=j.innerJoin||{},j.leftJoin=j.leftJoin||{},j.innerJoinOne=j.innerJoinOne||{},j.leftJoinOne=j.leftJoinOne||{},j.leftJoin[e]=(e,n,r={})=>t(!0,e,n,r),j.innerJoin[e]=(e,n,r={})=>t(!1,e,n,r),j.leftJoinOne[e]=(e,n,r={})=>t(!0,e,n,{...r,limit:1}),j.innerJoinOne[e]=(e,n,r={})=>t(!1,e,n,{...r,limit:1})})),(async()=>{try{await s(j,P,S,w)}catch(e){console.error("Prostgles: Error within onReady: \n",e),l(e)}e(j)})()}))}))}},792:function(e){var t;this||window,t=()=>(()=>{"use strict";var e={444:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.TextFilterFTSKeys=t.TextFilter_FullTextSearchFilterKeys=t.CompareInFilterKeys=t.CompareFilterKeys=void 0,t.CompareFilterKeys=["=","$eq","<>",">",">=","<=","$eq","$ne","$gt","$gte","$lte"],t.CompareInFilterKeys=["$in","$nin"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"];const n=["ST_MakeEnvelope","ST_MakePolygon"];t.GeomFilter_Funcs=n.concat(n.map((e=>e.toLowerCase()))),t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"]},590:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.getKeys=t.isObject=t.isDefined=t.get=t.WAL=t.unpatchText=t.stableStringify=t.isEmpty=t.getTextPatch=t.asName=t.RULE_METHODS=t.CHANNELS=t.TS_PG_Types=t._PG_postgis=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","inet","time","timetz","interval","name"],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_postgis=["geometry","geography"],t.TS_PG_Types={string:t._PG_strings,number:t._PG_numbers,boolean:t._PG_bool,Object:t._PG_json,Date:t._PG_date,"Array<number>":t._PG_numbers.map((e=>`_${e}`)),"Array<boolean>":t._PG_bool.map((e=>`_${e}`)),"Array<string>":t._PG_strings.map((e=>`_${e}`)),"Array<Object>":t._PG_json.map((e=>`_${e}`)),"Array<Date>":t._PG_date.map((e=>`_${e}`)),any:[]};const s="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:s+"schema-changed",SCHEMA:s+"schema",DEFAULT:s,SQL:"_psqlWS_.sql",METHOD:"_psqlWS_.method",NOTICE_EV:"_psqlWS_.notice",LISTEN_EV:"_psqlWS_.listen",REGISTER:"_psqlWS_.register",LOGIN:"_psqlWS_.login",LOGOUT:"_psqlWS_.logout",AUTHGUARD:"_psqlWS_.authguard",_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"]};var o=n(128);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return o.asName}}),Object.defineProperty(t,"getTextPatch",{enumerable:!0,get:function(){return o.getTextPatch}}),Object.defineProperty(t,"isEmpty",{enumerable:!0,get:function(){return o.isEmpty}}),Object.defineProperty(t,"stableStringify",{enumerable:!0,get:function(){return o.stableStringify}}),Object.defineProperty(t,"unpatchText",{enumerable:!0,get:function(){return o.unpatchText}}),Object.defineProperty(t,"WAL",{enumerable:!0,get:function(){return o.WAL}}),Object.defineProperty(t,"get",{enumerable:!0,get:function(){return o.get}}),Object.defineProperty(t,"isDefined",{enumerable:!0,get:function(){return o.isDefined}}),Object.defineProperty(t,"isObject",{enumerable:!0,get:function(){return o.isObject}}),Object.defineProperty(t,"getKeys",{enumerable:!0,get:function(){return o.getKeys}}),i(n(444),t)},899:(e,t)=>{function n(e,t){var n=e[0],r=e[1],l=e[2],c=e[3];n=i(n,r,l,c,t[0],7,-680876936),c=i(c,n,r,l,t[1],12,-389564586),l=i(l,c,n,r,t[2],17,606105819),r=i(r,l,c,n,t[3],22,-1044525330),n=i(n,r,l,c,t[4],7,-176418897),c=i(c,n,r,l,t[5],12,1200080426),l=i(l,c,n,r,t[6],17,-1473231341),r=i(r,l,c,n,t[7],22,-45705983),n=i(n,r,l,c,t[8],7,1770035416),c=i(c,n,r,l,t[9],12,-1958414417),l=i(l,c,n,r,t[10],17,-42063),r=i(r,l,c,n,t[11],22,-1990404162),n=i(n,r,l,c,t[12],7,1804603682),c=i(c,n,r,l,t[13],12,-40341101),l=i(l,c,n,r,t[14],17,-1502002290),n=s(n,r=i(r,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=s(c,n,r,l,t[6],9,-1069501632),l=s(l,c,n,r,t[11],14,643717713),r=s(r,l,c,n,t[0],20,-373897302),n=s(n,r,l,c,t[5],5,-701558691),c=s(c,n,r,l,t[10],9,38016083),l=s(l,c,n,r,t[15],14,-660478335),r=s(r,l,c,n,t[4],20,-405537848),n=s(n,r,l,c,t[9],5,568446438),c=s(c,n,r,l,t[14],9,-1019803690),l=s(l,c,n,r,t[3],14,-187363961),r=s(r,l,c,n,t[8],20,1163531501),n=s(n,r,l,c,t[13],5,-1444681467),c=s(c,n,r,l,t[2],9,-51403784),l=s(l,c,n,r,t[7],14,1735328473),n=o(n,r=s(r,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=o(c,n,r,l,t[8],11,-2022574463),l=o(l,c,n,r,t[11],16,1839030562),r=o(r,l,c,n,t[14],23,-35309556),n=o(n,r,l,c,t[1],4,-1530992060),c=o(c,n,r,l,t[4],11,1272893353),l=o(l,c,n,r,t[7],16,-155497632),r=o(r,l,c,n,t[10],23,-1094730640),n=o(n,r,l,c,t[13],4,681279174),c=o(c,n,r,l,t[0],11,-358537222),l=o(l,c,n,r,t[3],16,-722521979),r=o(r,l,c,n,t[6],23,76029189),n=o(n,r,l,c,t[9],4,-640364487),c=o(c,n,r,l,t[12],11,-421815835),l=o(l,c,n,r,t[15],16,530742520),n=a(n,r=o(r,l,c,n,t[2],23,-995338651),l,c,t[0],6,-198630844),c=a(c,n,r,l,t[7],10,1126891415),l=a(l,c,n,r,t[14],15,-1416354905),r=a(r,l,c,n,t[5],21,-57434055),n=a(n,r,l,c,t[12],6,1700485571),c=a(c,n,r,l,t[3],10,-1894986606),l=a(l,c,n,r,t[10],15,-1051523),r=a(r,l,c,n,t[1],21,-2054922799),n=a(n,r,l,c,t[8],6,1873313359),c=a(c,n,r,l,t[15],10,-30611744),l=a(l,c,n,r,t[6],15,-1560198380),r=a(r,l,c,n,t[13],21,1309151649),n=a(n,r,l,c,t[4],6,-145523070),c=a(c,n,r,l,t[11],10,-1120210379),l=a(l,c,n,r,t[2],15,718787259),r=a(r,l,c,n,t[9],21,-343485551),e[0]=f(n,e[0]),e[1]=f(r,e[1]),e[2]=f(l,e[2]),e[3]=f(c,e[3])}function r(e,t,n,r,i,s){return t=f(f(t,e),f(r,s)),f(t<<i|t>>>32-i,n)}function i(e,t,n,i,s,o,a){return r(t&n|~t&i,e,t,s,o,a)}function s(e,t,n,i,s,o,a){return r(t&i|n&~i,e,t,s,o,a)}function o(e,t,n,i,s,o,a){return r(t^n^i,e,t,s,o,a)}function a(e,t,n,i,s,o,a){return r(n^(t|~i),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 d(e){return function(e){for(var t=0;t<e.length;t++)e[t]=u(e[t]);return e.join("")}(function(e){var t,r=e.length,i=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)n(i,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(i,s),t=0;t<16;t++)s[t]=0;return s[14]=8*r,n(i,s),i}(e))}function f(e,t){return e+t&4294967295}t.md5=d,d("hello")},128:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getKeys=t.isDefined=t.isObject=t.get=t.isEmpty=t.WAL=t.unpatchText=t.getTextPatch=t.stableStringify=t.asName=void 0;const r=n(899);function i(e){for(var t in e)return!1;return!0}t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},t.stableStringify=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var n,r="boolean"==typeof t.cycles&&t.cycles,i=t.cmp&&(n=t.cmp,function(e){return function(t,r){var i={key:t,value:e[t]},s={key:r,value:e[r]};return n(i,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(r)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=s.push(t)-1,l=Object.keys(t).sort(i&&i(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,r.md5)(t)};function n(n=1){let r=n<1?-1:0,i=!1;for(;!i&&Math.abs(r)<=t.length;){const s=n<1?[r]:[0,r];e.slice(...s)!==t.slice(...s)?i=!0:r+=1*Math.sign(n)}return r}let i=n()-1,s=e.length+n(-1)+1,o=t.length+n(-1)+1;return{from:i,to:s,text:t.slice(i,o),md5:(0,r.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:i,text:s,md5:o}=t;if(null===s||null===e)return s;let a=e.slice(0,n)+s+e.slice(i);if(o&&(0,r.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 r=n.asc?e[n.fieldName]:t[n.fieldName],i=n.asc?t[n.fieldName]:e[n.fieldName],s=+r-+i,o=r<i?-1:r==i?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)],r=n?.[this.options.synced_field];if(n){if(!Number.isFinite(+r))throw"Provided historic item Synced field value is missing/invalid";if(+r==+t)return!0}return!1},this.addData=e=>{i(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map((e=>{var t;const{initial:n,current:r}={...e};if(!r)throw"Expecting { current: object, initial?: object }";const i=this.getIdStr(r);this.changed??(this.changed={}),(t=this.changed)[i]??(t[i]={initial:n,current:r}),this.changed[i].current={...this.changed[i].current,...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:r,throttle:s,historyAgeSeconds:o=2}=this.options;if(this.isSendingTimeout||this.sending&&!i(this.sending))return;if(!this.changed||i(this.changed))return;let a,l=[],c=[],u={};Object.keys(this.changed).sort(((e,t)=>this.sort(this.changed[e].current,this.changed[t].current))).slice(0,r).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=>e.current)),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout((()=>{this.isSendingTimeout=void 0,i(this.changed)||this.sendItems()}),s)),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){a=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(a)})),this.callbacks=this.callbacks.filter((e=>e.idStrs.length))}this.sending={},e&&console.log(this.options.id," SENT lr->",l[l.length-1]),i(this.changed)?n&&n(l,c,a):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||!(i(this.sending)&&i(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=i,t.get=function(e,t){let n=t,r=e;return e?("string"==typeof n&&(n=n.split(".")),n.reduce(((e,t)=>e&&e[t]?e[t]:void 0),r)):e},t.isObject=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},t.isDefined=function(e){return null!=e},t.getKeys=function(e){return Object.keys(e)}}},t={};return function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,n),s.exports}(590)})(),e.exports=t()}},t={},function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,n),s.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 r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this||window,(()=>{return e={274:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prostgles=t.debug=void 0;const r=n(792),i="DEBUG_SYNCEDTABLE",s="undefined"!=typeof window;t.debug=function(...e){s&&window[i]&&window[i](...e)},t.prostgles=function(e,n){const{socket:i,onReady:s,onDisconnect:o,onReconnect:a,onSchemaChange:l=!0}=e;if((0,t.debug)("prostgles",{initOpts:e}),l){let e;"function"==typeof l&&(e=l),i.removeAllListeners(r.CHANNELS.SCHEMA_CHANGED),e&&i.on(r.CHANNELS.SCHEMA_CHANGED,e)}const c=r.CHANNELS._preffix;let u,d={},f={},m={},h={},p=!1;function g(e,n){return(0,t.debug)("_unsubscribe",{channelName:e,handler:n}),new Promise(((t,r)=>{d[e]?(d[e].handlers=d[e].handlers.filter((e=>e!==n)),d[e].handlers.length||(i.emit(e+"unsubscribe",{},((e,t)=>{e&&console.error(e)})),i.removeListener(e,d[e].onCall),delete d[e]),t(!0)):t(!0)}))}function y({tableName:e,command:t,param1:n,param2:r},s){return new Promise(((o,a)=>{i.emit(c,{tableName:e,command:t,param1:n,param2:r},((e,t)=>{if(e)console.error(e),a(e);else if(t){const{id_fields:e,synced_field:n,channelName:r}=t;i.emit(r,{onSyncRequest:s({})},(e=>{console.log(e)})),o({id_fields:e,synced_field:n,channelName:r})}}))}))}function b({tableName:e,command:t,param1:n,param2:r}){return new Promise(((s,o)=>{i.emit(c,{tableName:e,command:t,param1:n,param2:r},((e,t)=>{e?(console.error(e),o(e)):t&&s(t.channelName)}))}))}async function _(e,{tableName:t,command:n,param1:r,param2:s},o,a){function l(n){let i={unsubscribe:function(){return g(n,o)},filter:{...r}};return e[t].update&&(i={...i,update:function(n,i){return e[t].update(r,n,i)}}),e[t].delete&&(i={...i,delete:function(n){return e[t].delete(r,n)}}),Object.freeze(i)}const c=Object.keys(d).find((e=>{let i=d[e];return i.tableName===t&&i.command===n&&JSON.stringify(i.param1||{})===JSON.stringify(r||{})&&JSON.stringify(i.param2||{})===JSON.stringify(s||{})}));if(c)return d[c].handlers.push(o),setTimeout((()=>{o&&(null==d?void 0:d[c].lastData)&&o(null==d?void 0:d[c].lastData)}),10),l(c);{const e=await b({tableName:t,command:n,param1:r,param2:s});let c=function(t,n){d[e]?t.data?(d[e].lastData=t.data,d[e].handlers.map((e=>{e(t.data)}))):t.err?d[e].errorHandlers.map((e=>{e(t.err)})):console.error("INTERNAL ERROR: Unexpected data format from subscription: ",t):console.warn("Orphaned subscription: ",e)},u=a||function(t){console.error(`Uncaught error within running subscription \n ${e}`,t)};return i.on(e,c),d[e]={lastData:void 0,tableName:t,command:n,param1:r,param2:s,onCall:c,handlers:[o],errorHandlers:[u],destroy:()=>{d[e]&&(Object.values(d[e]).map((t=>{t&&t.handlers&&t.handlers.map((t=>g(e,t)))})),delete d[e])}},l(e)}}return new Promise(((e,l)=>{o&&i.on("disconnect",o),i.on(r.CHANNELS.SCHEMA,(({schema:o,methods:g,tableSchema:S,auth:O,rawSQL:N,joinTables:v=[],err:C})=>{if(C)throw l(C),C;(0,t.debug)("destroySyncs",{subscriptions:d,syncedTables:f}),Object.values(d).map((e=>e.destroy())),d={},m={},Object.values(f).map((e=>{e&&e.destroy&&e.destroy()})),f={},p&&a&&a(i),p=!0;let j=JSON.parse(JSON.stringify(o)),E=JSON.parse(JSON.stringify(g)),P={},w={};if(O){if(O.pathGuard){const e=e=>{var t,n;(null==e?void 0:e.shouldReload)&&"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))};i.emit(r.CHANNELS.AUTHGUARD,JSON.stringify(window.location),((t,n)=>{e(n)})),i.removeAllListeners(r.CHANNELS.AUTHGUARD),i.on(r.CHANNELS.AUTHGUARD,(t=>{e(t)}))}w={...O},[r.CHANNELS.LOGIN,r.CHANNELS.LOGOUT,r.CHANNELS.REGISTER].map((e=>{O[e]&&(w[e]=function(t){return new Promise(((n,r)=>{i.emit(c+e,t,((e,t)=>{e?r(e):n(t)}))}))})}))}E.map((e=>{P[e]=function(...t){return new Promise(((n,s)=>{i.emit(r.CHANNELS.METHOD,{method:e,params:t},((e,t)=>{e?s(e):n(t)}))}))}})),P=Object.freeze(P),N&&(j.sql=function(e,t,n){return new Promise(((s,o)=>{i.emit(r.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)=>{u=u||{config:t,listeners:[]},u.listeners.length||(i.removeAllListeners(t.socketChannel),i.on(t.socketChannel,(e=>{u&&u.listeners&&u.listeners.length?u.listeners.map((t=>{t(e)})):i.emit(t.socketUnsubChannel,{})}))),u.listeners.push(e)})(t,e),{...e,removeListener:()=>(e=>{u&&(u.listeners=u.listeners.filter((t=>t!==e)),!u.listeners.length&&u.config&&u.config.socketUnsubChannel&&i&&i.emit(u.config.socketUnsubChannel,{}))})(t)}),r={...e,addListener:n};s(r)}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)=>{h=h||{},h[t.notifChannel]?h[t.notifChannel].listeners.push(e):(h[t.notifChannel]={config:t,listeners:[e]},i.removeAllListeners(t.socketChannel),i.on(t.socketChannel,(e=>{h[t.notifChannel]&&h[t.notifChannel].listeners&&h[t.notifChannel].listeners.length?h[t.notifChannel].listeners.map((t=>{t(e)})):i.emit(h[t.notifChannel].config.socketUnsubChannel,{})})))})(e,t),{...t,removeListener:()=>((e,t)=>{h&&h[t.notifChannel]&&(h[t.notifChannel].listeners=h[t.notifChannel].listeners.filter((t=>t!==e)),!h[t.notifChannel].listeners.length&&h[t.notifChannel].config&&h[t.notifChannel].config.socketUnsubChannel&&i&&(i.emit(h[t.notifChannel].config.socketUnsubChannel,{}),delete h[t.notifChannel]))})(e,t)}),n={...t,addListener:e};s(n)}}))}))});const T=e=>"[object Object]"===Object.prototype.toString.call(e),A=(e,t,n,r)=>{if(!T(e)||!T(t)||"function"!=typeof n||r&&"function"!=typeof r)throw"Expecting: ( basicFilter<object>, options<object>, onChange<function> , onError?<function>) but got something else"},x=["subscribe","subscribeOne"];Object.keys(j).forEach((e=>{Object.keys(j[e]).sort(((e,t)=>x.includes(e)-x.includes(t))).forEach((r=>{if(["find","findOne"].includes(r)&&(j[e].getJoinedTables=function(){return(v||[]).filter((t=>Array.isArray(t)&&t.includes(e))).flat().filter((t=>t!==e))}),"sync"===r){if(j[e]._syncInfo={...j[e][r]},n){j[e].getSync=(t,r={})=>n.create({name:e,filter:t,db:j,...r});const t=async(t={},r={},i)=>{const s=`${e}.${JSON.stringify(t)}.${JSON.stringify(r)}`;return f[s]||(f[s]=await n.create({...r,name:e,filter:t,db:j,onError:i})),f[s]};j[e].sync=async(e,n={handlesOnData:!0,select:"*"},r,i)=>{A(e,n,r,i);const s=await t(e,n,i);return await s.sync(r,n.handlesOnData)},j[e].syncOne=async(e,n={handlesOnData:!0},r,i)=>{A(e,n,r,i);const s=await t(e,n,i);return await s.syncOne(e,r,n.handlesOnData)}}j[e]._sync=function(n,s,o){return async function({tableName:e,command:n,param1:r,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,r)=>{m[e]&&(m[e].triggers=m[e].triggers.filter((e=>e.onPullRequest!==n.onPullRequest&&e.onSyncRequest!==n.onSyncRequest&&e.onUpdates!==n.onUpdates)),m[e].triggers.length||(i.emit(e+"unsync",{},((e,n)=>{e?r(e):t(n)})),i.removeListener(e,m[e].onCall),delete m[e]))}))}(e,o)},syncData:function(t,n,r){i.emit(e,{onSyncRequest:{...l({}),...{data:t}||{},...{deleted:n}||{}}},r?e=>{r(e)}:null)}})}const d=Object.keys(m).find((t=>{let i=m[t];return i.tableName===e&&i.command===n&&JSON.stringify(i.param1||{})===JSON.stringify(r||{})&&JSON.stringify(i.param2||{})===JSON.stringify(s||{})}));if(d)return m[d].triggers.push(o),u(d);{const f=await y({tableName:e,command:n,param1:r,param2:s},l),{channelName:h,synced_field:p,id_fields:g}=f;function b(t,n){t&&m[h]&&m[h].triggers.map((({onUpdates:r,onSyncRequest:i,onPullRequest:s})=>{t.data?Promise.resolve(r(t)).then((()=>{n&&n({ok:!0})})).catch((t=>{n?n({err:t}):console.error(e+" onUpdates error",t)})):t.onSyncRequest?Promise.resolve(i(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 m[h]={tableName:e,command:n,param1:r,param2:s,triggers:[o],syncInfo:f,onCall:b},i.on(h,b),u(h)}}({tableName:e,command:r,param1:n,param2:s},o)}}else if(x.includes(r)){j[e][r]=function(t,n,i,s){return A(t,n,i,s),_(j,{tableName:e,command:r,param1:t,param2:n},i,s)};const t="subscribeOne";r!==t&&x.includes(t)||(j[e][t]=function(t,n,i,s){return A(t,n,i,s),_(j,{tableName:e,command:r,param1:t,param2:n},(e=>{i(e[0])}),s)})}else j[e][r]=function(t,n,s){return new Promise(((o,a)=>{i.emit(c,{tableName:e,command:r,param1:t,param2:n,param3:s},((e,t)=>{e?a(e):o(t)}))}))}}))})),d&&Object.keys(d).length&&Object.keys(d).map((async e=>{try{let t=d[e];await b(t),i.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting old subscriptions",e)}})),m&&Object.keys(m).length&&Object.keys(m).filter((e=>m[e].triggers&&m[e].triggers.length)).map((async e=>{try{let t=m[e];await y(t,t.triggers[0].onSyncRequest),i.on(e,t.onCall)}catch(e){console.error("There was an issue reconnecting olf subscriptions",e)}})),v.flat().map((e=>{function t(t=!0,n,r,i){return{[t?"$leftJoin":"$innerJoin"]:e,filter:n,select:r,...i}}j.innerJoin=j.innerJoin||{},j.leftJoin=j.leftJoin||{},j.innerJoinOne=j.innerJoinOne||{},j.leftJoinOne=j.leftJoinOne||{},j.leftJoin[e]=(e,n,r={})=>t(!0,e,n,r),j.innerJoin[e]=(e,n,r={})=>t(!1,e,n,r),j.leftJoinOne[e]=(e,n,r={})=>t(!0,e,n,{...r,limit:1}),j.innerJoinOne[e]=(e,n,r={})=>t(!1,e,n,{...r,limit:1})})),(async()=>{try{await s(j,P,S,w)}catch(e){console.error("Prostgles: Error within onReady: \n",e),l(e)}e(j)})()}))}))}},792:function(e){var t;this||window,t=()=>(()=>{"use strict";var e={444:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.TextFilterFTSKeys=t.TextFilter_FullTextSearchFilterKeys=t.TextFilterKeys=t.CompareInFilterKeys=t.CompareFilterKeys=void 0,t.CompareFilterKeys=["=","$eq","<>",">",">=","<=","$eq","$ne","$gt","$gte","$lte"],t.CompareInFilterKeys=["$in","$nin"],t.TextFilterKeys=["$ilike","$like"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"];const n=["ST_MakeEnvelope","ST_MakePolygon"];t.GeomFilter_Funcs=n.concat(n.map((e=>e.toLowerCase()))),t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"]},590:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.getKeys=t.isObject=t.isDefined=t.get=t.WAL=t.unpatchText=t.stableStringify=t.isEmpty=t.getTextPatch=t.asName=t.RULE_METHODS=t.CHANNELS=t.TS_PG_Types=t._PG_postgis=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","inet","time","timetz","interval","name"],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_postgis=["geometry","geography"],t.TS_PG_Types={string:t._PG_strings,number:t._PG_numbers,boolean:t._PG_bool,Date:t._PG_date,"Array<number>":t._PG_numbers.map((e=>`_${e}`)),"Array<boolean>":t._PG_bool.map((e=>`_${e}`)),"Array<string>":t._PG_strings.map((e=>`_${e}`)),"Array<Object>":t._PG_json.map((e=>`_${e}`)),"Array<Date>":t._PG_date.map((e=>`_${e}`)),any:[]};const s="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:s+"schema-changed",SCHEMA:s+"schema",DEFAULT:s,SQL:"_psqlWS_.sql",METHOD:"_psqlWS_.method",NOTICE_EV:"_psqlWS_.notice",LISTEN_EV:"_psqlWS_.listen",REGISTER:"_psqlWS_.register",LOGIN:"_psqlWS_.login",LOGOUT:"_psqlWS_.logout",AUTHGUARD:"_psqlWS_.authguard",_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"]};var o=n(128);Object.defineProperty(t,"asName",{enumerable:!0,get:function(){return o.asName}}),Object.defineProperty(t,"getTextPatch",{enumerable:!0,get:function(){return o.getTextPatch}}),Object.defineProperty(t,"isEmpty",{enumerable:!0,get:function(){return o.isEmpty}}),Object.defineProperty(t,"stableStringify",{enumerable:!0,get:function(){return o.stableStringify}}),Object.defineProperty(t,"unpatchText",{enumerable:!0,get:function(){return o.unpatchText}}),Object.defineProperty(t,"WAL",{enumerable:!0,get:function(){return o.WAL}}),Object.defineProperty(t,"get",{enumerable:!0,get:function(){return o.get}}),Object.defineProperty(t,"isDefined",{enumerable:!0,get:function(){return o.isDefined}}),Object.defineProperty(t,"isObject",{enumerable:!0,get:function(){return o.isObject}}),Object.defineProperty(t,"getKeys",{enumerable:!0,get:function(){return o.getKeys}}),i(n(444),t)},899:(e,t)=>{function n(e,t){var n=e[0],r=e[1],l=e[2],c=e[3];n=i(n,r,l,c,t[0],7,-680876936),c=i(c,n,r,l,t[1],12,-389564586),l=i(l,c,n,r,t[2],17,606105819),r=i(r,l,c,n,t[3],22,-1044525330),n=i(n,r,l,c,t[4],7,-176418897),c=i(c,n,r,l,t[5],12,1200080426),l=i(l,c,n,r,t[6],17,-1473231341),r=i(r,l,c,n,t[7],22,-45705983),n=i(n,r,l,c,t[8],7,1770035416),c=i(c,n,r,l,t[9],12,-1958414417),l=i(l,c,n,r,t[10],17,-42063),r=i(r,l,c,n,t[11],22,-1990404162),n=i(n,r,l,c,t[12],7,1804603682),c=i(c,n,r,l,t[13],12,-40341101),l=i(l,c,n,r,t[14],17,-1502002290),n=s(n,r=i(r,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=s(c,n,r,l,t[6],9,-1069501632),l=s(l,c,n,r,t[11],14,643717713),r=s(r,l,c,n,t[0],20,-373897302),n=s(n,r,l,c,t[5],5,-701558691),c=s(c,n,r,l,t[10],9,38016083),l=s(l,c,n,r,t[15],14,-660478335),r=s(r,l,c,n,t[4],20,-405537848),n=s(n,r,l,c,t[9],5,568446438),c=s(c,n,r,l,t[14],9,-1019803690),l=s(l,c,n,r,t[3],14,-187363961),r=s(r,l,c,n,t[8],20,1163531501),n=s(n,r,l,c,t[13],5,-1444681467),c=s(c,n,r,l,t[2],9,-51403784),l=s(l,c,n,r,t[7],14,1735328473),n=o(n,r=s(r,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=o(c,n,r,l,t[8],11,-2022574463),l=o(l,c,n,r,t[11],16,1839030562),r=o(r,l,c,n,t[14],23,-35309556),n=o(n,r,l,c,t[1],4,-1530992060),c=o(c,n,r,l,t[4],11,1272893353),l=o(l,c,n,r,t[7],16,-155497632),r=o(r,l,c,n,t[10],23,-1094730640),n=o(n,r,l,c,t[13],4,681279174),c=o(c,n,r,l,t[0],11,-358537222),l=o(l,c,n,r,t[3],16,-722521979),r=o(r,l,c,n,t[6],23,76029189),n=o(n,r,l,c,t[9],4,-640364487),c=o(c,n,r,l,t[12],11,-421815835),l=o(l,c,n,r,t[15],16,530742520),n=a(n,r=o(r,l,c,n,t[2],23,-995338651),l,c,t[0],6,-198630844),c=a(c,n,r,l,t[7],10,1126891415),l=a(l,c,n,r,t[14],15,-1416354905),r=a(r,l,c,n,t[5],21,-57434055),n=a(n,r,l,c,t[12],6,1700485571),c=a(c,n,r,l,t[3],10,-1894986606),l=a(l,c,n,r,t[10],15,-1051523),r=a(r,l,c,n,t[1],21,-2054922799),n=a(n,r,l,c,t[8],6,1873313359),c=a(c,n,r,l,t[15],10,-30611744),l=a(l,c,n,r,t[6],15,-1560198380),r=a(r,l,c,n,t[13],21,1309151649),n=a(n,r,l,c,t[4],6,-145523070),c=a(c,n,r,l,t[11],10,-1120210379),l=a(l,c,n,r,t[2],15,718787259),r=a(r,l,c,n,t[9],21,-343485551),e[0]=f(n,e[0]),e[1]=f(r,e[1]),e[2]=f(l,e[2]),e[3]=f(c,e[3])}function r(e,t,n,r,i,s){return t=f(f(t,e),f(r,s)),f(t<<i|t>>>32-i,n)}function i(e,t,n,i,s,o,a){return r(t&n|~t&i,e,t,s,o,a)}function s(e,t,n,i,s,o,a){return r(t&i|n&~i,e,t,s,o,a)}function o(e,t,n,i,s,o,a){return r(t^n^i,e,t,s,o,a)}function a(e,t,n,i,s,o,a){return r(n^(t|~i),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 d(e){return function(e){for(var t=0;t<e.length;t++)e[t]=u(e[t]);return e.join("")}(function(e){var t,r=e.length,i=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)n(i,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(i,s),t=0;t<16;t++)s[t]=0;return s[14]=8*r,n(i,s),i}(e))}function f(e,t){return e+t&4294967295}t.md5=d,d("hello")},128:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getKeys=t.isDefined=t.isObject=t.get=t.isEmpty=t.WAL=t.unpatchText=t.getTextPatch=t.stableStringify=t.asName=void 0;const r=n(899);function i(e){for(var t in e)return!1;return!0}t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},t.stableStringify=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var n,r="boolean"==typeof t.cycles&&t.cycles,i=t.cmp&&(n=t.cmp,function(e){return function(t,r){var i={key:t,value:e[t]},s={key:r,value:e[r]};return n(i,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(r)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=s.push(t)-1,l=Object.keys(t).sort(i&&i(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,r.md5)(t)};function n(n=1){let r=n<1?-1:0,i=!1;for(;!i&&Math.abs(r)<=t.length;){const s=n<1?[r]:[0,r];e.slice(...s)!==t.slice(...s)?i=!0:r+=1*Math.sign(n)}return r}let i=n()-1,s=e.length+n(-1)+1,o=t.length+n(-1)+1;return{from:i,to:s,text:t.slice(i,o),md5:(0,r.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:i,text:s,md5:o}=t;if(null===s||null===e)return s;let a=e.slice(0,n)+s+e.slice(i);if(o&&(0,r.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 r=n.asc?e[n.fieldName]:t[n.fieldName],i=n.asc?t[n.fieldName]:e[n.fieldName],s=+r-+i,o=r<i?-1:r==i?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)],r=n?.[this.options.synced_field];if(n){if(!Number.isFinite(+r))throw"Provided historic item Synced field value is missing/invalid";if(+r==+t)return!0}return!1},this.addData=e=>{i(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map((e=>{var t;const{initial:n,current:r}={...e};if(!r)throw"Expecting { current: object, initial?: object }";const i=this.getIdStr(r);this.changed??(this.changed={}),(t=this.changed)[i]??(t[i]={initial:n,current:r}),this.changed[i].current={...this.changed[i].current,...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:r,throttle:s,historyAgeSeconds:o=2}=this.options;if(this.isSendingTimeout||this.sending&&!i(this.sending))return;if(!this.changed||i(this.changed))return;let a,l=[],c=[],u={};Object.keys(this.changed).sort(((e,t)=>this.sort(this.changed[e].current,this.changed[t].current))).slice(0,r).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=>e.current)),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout((()=>{this.isSendingTimeout=void 0,i(this.changed)||this.sendItems()}),s)),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){a=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(a)})),this.callbacks=this.callbacks.filter((e=>e.idStrs.length))}this.sending={},e&&console.log(this.options.id," SENT lr->",l[l.length-1]),i(this.changed)?n&&n(l,c,a):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||!(i(this.sending)&&i(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=i,t.get=function(e,t){let n=t,r=e;return e?("string"==typeof n&&(n=n.split(".")),n.reduce(((e,t)=>e&&e[t]?e[t]:void 0),r)):e},t.isObject=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},t.isDefined=function(e){return null!=e},t.getKeys=function(e){return Object.keys(e)}}},t={};return function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,n),s.exports}(590)})(),e.exports=t()}},t={},function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,n),s.exports}(274);var e,t}));
@@ -1,4 +1,4 @@
1
- import { TableHandler, TableHandlerBasic, DbJoinMaker, TableJoinBasic, AnyObject, SQLHandler, MethodHandler, SQLResult } from "prostgles-types";
1
+ import { TableHandler, TableHandlerBasic, DbJoinMaker, TableJoinBasic, AnyObject, SQLHandler, DBSchemaTable, MethodHandler, SQLResult } from "prostgles-types";
2
2
  import type { Sync, SyncOne } from "./SyncedTable";
3
3
  export declare const debug: any;
4
4
  export { MethodHandler, SQLResult };
@@ -18,8 +18,8 @@ export declare type TableHandlerClientBasic = TableHandlerBasic & {
18
18
  syncOne?: SyncOne;
19
19
  _sync?: any;
20
20
  };
21
- export declare type DBHandlerClient = {
22
- [key: string]: Partial<TableHandlerClient>;
21
+ export declare type DBHandlerClient<Tables extends Record<string, Record<string, any>> = Record<string, any>> = {
22
+ [key in keyof Tables]: Partial<TableHandlerClient<Tables[key]>>;
23
23
  } & DbJoinMaker & {
24
24
  sql?: SQLHandler;
25
25
  };
@@ -51,7 +51,7 @@ export declare type InitOptions = {
51
51
  * true by default
52
52
  */
53
53
  onSchemaChange?: false | (() => void);
54
- onReady: (dbo: DBHandlerClient, methods?: MethodHandler, fullSchema?: any, auth?: Auth) => any;
54
+ onReady: (dbo: DBHandlerClient, methods: MethodHandler | undefined, tableSchema: DBSchemaTable[] | undefined, auth?: Auth) => any;
55
55
  onReconnect?: (socket: any) => any;
56
56
  onDisconnect?: (socket: any) => any;
57
57
  };
@@ -1 +1 @@
1
- {"version":3,"file":"prostgles.d.ts","sourceRoot":"","sources":["../lib/prostgles.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EACjD,cAAc,EACE,SAAS,EACzB,UAAU,EACiB,aAAa,EAA+D,SAAS,EACnH,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAe,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CA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E"}
package/dist/prostgles.js CHANGED
@@ -16,6 +16,13 @@ const debug = function (...args) {
16
16
  }
17
17
  };
18
18
  exports.debug = debug;
19
+ /** Type inference check */
20
+ const db = 1;
21
+ (async () => {
22
+ const res = await db.tbl1.findOne();
23
+ res.col1;
24
+ res.col2;
25
+ });
19
26
  function prostgles(initOpts, syncedTable) {
20
27
  const { socket, onReady, onDisconnect, onReconnect, onSchemaChange = true } = initOpts;
21
28
  (0, exports.debug)("prostgles", { initOpts });
@@ -398,7 +405,7 @@ function prostgles(initOpts, syncedTable) {
398
405
  }
399
406
  /* Schema = published schema */
400
407
  // socket.removeAllListeners(CHANNELS.SCHEMA)
401
- socket.on(prostgles_types_1.CHANNELS.SCHEMA, ({ schema, methods, fullSchema, auth, rawSQL, joinTables = [], err }) => {
408
+ socket.on(prostgles_types_1.CHANNELS.SCHEMA, ({ schema, methods, tableSchema, auth, rawSQL, joinTables = [], err }) => {
402
409
  if (err) {
403
410
  reject(err);
404
411
  throw err;
@@ -641,7 +648,7 @@ function prostgles(initOpts, syncedTable) {
641
648
  });
642
649
  (async () => {
643
650
  try {
644
- await onReady(dbo, methodsObj, fullSchema, _auth);
651
+ await onReady(dbo, methodsObj, tableSchema, _auth);
645
652
  }
646
653
  catch (err) {
647
654
  console.error("Prostgles: Error within onReady: \n", err);
@@ -1,4 +1,5 @@
1
- import { FieldFilter, getTextPatch, isEmpty, WAL, WALItem, AnyObject, ClientSyncHandles, SyncBatchParams, ClientSyncInfo, getKeys, isObject } from "prostgles-types";
1
+ import { FieldFilter, getTextPatch, isEmpty, WAL, WALItem, AnyObject, ClientSyncHandles, SyncBatchParams, ClientSyncInfo, getKeys, isObject, TableHandler } from "prostgles-types";
2
+ import { DBHandlerClient } from "./prostgles";
2
3
  export type POJO = { [key: string]: any };
3
4
 
4
5
  const DEBUG_KEY = "DEBUG_SYNCEDTABLE";
@@ -137,7 +138,7 @@ export type DbTableSync = {
137
138
 
138
139
  export class SyncedTable {
139
140
 
140
- db: any;
141
+ db: DBHandlerClient;
141
142
  name: string;
142
143
  select?: "*" | {};
143
144
  filter?: POJO;
@@ -272,15 +273,20 @@ export class SyncedTable {
272
273
  return true;
273
274
  };
274
275
 
276
+ const opts = {
277
+ id_fields,
278
+ synced_field,
279
+ throttle,
280
+ }
281
+
275
282
  db[this.name]._sync(filter, { select }, { onSyncRequest, onPullRequest, onUpdates }).then((s: DbTableSync) => {
276
283
  this.dbSync = s;
277
284
 
278
285
  function confirmExit() { return "Data may be lost. Are you sure?"; }
279
- const opts = {
280
- id_fields,
281
- synced_field,
282
- throttle,
283
- }
286
+
287
+ /**
288
+ * Some syncs can be read only. Any changes are local
289
+ */
284
290
  this.wal = new WAL({
285
291
  ...opts,
286
292
  batch_size,
@@ -309,6 +315,7 @@ export class SyncedTable {
309
315
  if (hasWnd) window.onbeforeunload = null;
310
316
  }
311
317
  });
318
+
312
319
  this.notifyWal = new WAL({
313
320
  ...opts,
314
321
  batch_size: Infinity,
@@ -346,7 +353,7 @@ export class SyncedTable {
346
353
  let remaining: any[] = walData.map(d => d.current);
347
354
  let patched: [any, any][] = [],
348
355
  patchedItems: any[] = [];
349
- if (this.columns && this.columns.length && this.db[this.name].updateBatch && (this.patchText || this.patchJSON)) {
356
+ if (this.columns && this.columns.length && this.tableHandler?.updateBatch && (this.patchText || this.patchJSON)) {
350
357
 
351
358
  // const jCols = this.columns.filter(c => c.data_type === "json")
352
359
  const txtCols = this.columns.filter(c => c.data_type === "text");
@@ -391,7 +398,7 @@ export class SyncedTable {
391
398
  */
392
399
  if (patched.length) {
393
400
  try {
394
- await this.db[this.name].updateBatch(patched);
401
+ await this.tableHandler?.updateBatch!(patched);
395
402
  } catch (e) {
396
403
  console.log("failed to patch update", e);
397
404
  remaining = remaining.concat(patchedItems);
@@ -470,7 +477,7 @@ export class SyncedTable {
470
477
  },
471
478
  $cloneMultiSync: (onChange: MultiChangeListener) => this.sync(onChange, handlesOnData)
472
479
  })
473
- const idObj = this.wal!.getIdObj(item) as Partial<T>;
480
+ const idObj = this.getIdObj(item) as Partial<T>;
474
481
  return getItem(item, idObj);
475
482
  });
476
483
  }
@@ -728,12 +735,21 @@ export class SyncedTable {
728
735
  this.getItems().map(d => this.delete(d));
729
736
  }
730
737
 
738
+ private get tableHandler(): Pick<TableHandler, "update" | "updateBatch" | "delete"> | undefined {
739
+ const tblHandler = this.db[this.name];
740
+ if(tblHandler.update && tblHandler.updateBatch){
741
+ return tblHandler as any;
742
+ }
743
+
744
+ return undefined;
745
+ }
746
+
731
747
  private delete = async (item: AnyObject, from_server = false) => {
732
748
 
733
749
  const idObj = this.getIdObj(item);
734
750
  this.setItem(idObj, undefined, true, true);
735
- if (!from_server) {
736
- await this.db[this.name].delete(idObj);
751
+ if (!from_server && this.tableHandler?.delete) {
752
+ await this.tableHandler.delete(idObj);
737
753
  }
738
754
  this._notifySubscribers();
739
755
  return true
package/lib/prostgles.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  import { TableHandler, TableHandlerBasic, DbJoinMaker,
8
8
  TableJoinBasic, CHANNELS, DBNotifConfig,
9
9
  DBNoticeConfig, AnyObject, SubscriptionHandler,
10
- SQLHandler, DBEventHandles, AuthGuardLocation,
10
+ SQLHandler, DBEventHandles, AuthGuardLocation, DBSchemaTable,
11
11
  AuthGuardLocationResponse, MethodHandler, ClientSyncHandles, UpdateParams, DeleteParams, ClientSchema, SQLResult
12
12
  } from "prostgles-types";
13
13
 
@@ -43,11 +43,20 @@ export type TableHandlerClientBasic = TableHandlerBasic & {
43
43
  _sync?: any;
44
44
  }
45
45
 
46
- export type DBHandlerClient = {
47
- [key: string]: Partial<TableHandlerClient>;
46
+ export type DBHandlerClient<Tables extends Record<string, Record<string, any>> = Record<string, any>> = {
47
+ [key in keyof Tables]: Partial<TableHandlerClient<Tables[key]>>;
48
48
  } & DbJoinMaker & {
49
49
  sql?: SQLHandler;
50
50
  };
51
+
52
+ /** Type inference check */
53
+ const db: DBHandlerClient<{ tbl1: { col1: string; col2: number }}> = 1 as any;
54
+ (async () => {
55
+ const res = await db.tbl1.findOne!()
56
+ res.col1;
57
+ res.col2;
58
+ });
59
+
51
60
  export type DBHandlerClientBasic = {
52
61
  [key: string]: Partial<TableHandlerClientBasic>;
53
62
  } & {
@@ -80,7 +89,7 @@ export type InitOptions = {
80
89
  * true by default
81
90
  */
82
91
  onSchemaChange?: false | (() => void);
83
- onReady: (dbo: DBHandlerClient, methods?: MethodHandler, fullSchema?: any, auth?: Auth) => any;
92
+ onReady: (dbo: DBHandlerClient, methods: MethodHandler | undefined, tableSchema: DBSchemaTable[] | undefined, auth?: Auth) => any;
84
93
  onReconnect?: (socket: any) => any;
85
94
  onDisconnect?: (socket: any) => any;
86
95
  }
@@ -535,7 +544,7 @@ export function prostgles(initOpts: InitOptions, syncedTable: any){
535
544
 
536
545
  /* Schema = published schema */
537
546
  // socket.removeAllListeners(CHANNELS.SCHEMA)
538
- socket.on(CHANNELS.SCHEMA, ({ schema, methods, fullSchema, auth, rawSQL, joinTables = [], err }: ClientSchema) => {
547
+ socket.on(CHANNELS.SCHEMA, ({ schema, methods, tableSchema, auth, rawSQL, joinTables = [], err }: ClientSchema) => {
539
548
  if(err){
540
549
  reject(err)
541
550
  throw err;
@@ -791,7 +800,7 @@ export function prostgles(initOpts: InitOptions, syncedTable: any){
791
800
 
792
801
  (async () => {
793
802
  try {
794
- await onReady(dbo, methodsObj, fullSchema, _auth);
803
+ await onReady(dbo, methodsObj, tableSchema, _auth);
795
804
  } catch(err){
796
805
  console.error("Prostgles: Error within onReady: \n", err);
797
806
  reject(err);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "prostgles-client",
3
- "version": "1.5.148",
3
+ "version": "1.5.151",
4
4
  "description": "Reactive client for Postgres",
5
5
  "main": "dist/prostgles-full.js",
6
6
  "types": "dist/prostgles-full.d.ts",
7
7
  "dependencies": {
8
- "prostgles-types": "^1.5.134"
8
+ "prostgles-types": "^1.5.151"
9
9
  },
10
10
  "devDependencies": {
11
11
  "@types/node": "^14.14.14",
package/tsconfig.json CHANGED
@@ -23,7 +23,8 @@
23
23
  "outDir": "dist",
24
24
  // "moduleResolution": "node"
25
25
  "declaration": true,
26
- "declarationMap": true
26
+ "declarationMap": true,
27
+ "keyofStringsOnly": true
27
28
  },
28
29
  "include": ["lib"],
29
30
  "exclude": [