prostgles-types 4.0.254 → 4.0.256
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index_umd.js +1 -1
- package/dist/replication.d.ts +30 -93
- package/dist/replication.d.ts.map +1 -1
- package/dist/replication.js +6 -2
- package/dist/replication.js.map +1 -1
- package/lib/replication.ts +44 -20
- package/package.json +1 -1
package/dist/index_umd.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 r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(Object(this||window),()=>(()=>{"use strict";var e={994(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=t.PrimitiveTypesObj=void 0;const r=n(472);t.PrimitiveTypesObj={boolean:1,number:1,integer:1,string:1,Date:1,time:1,timestamp:1,Blob:1,FileLike:1,any:1,unknown:1},t.PrimitiveTypes=(0,r.getKeys)(t.PrimitiveTypesObj),t.PrimitiveArrayTypes=t.PrimitiveTypes.map(e=>`${e}[]`),t.DATA_TYPES=[...t.PrimitiveTypes,...t.PrimitiveArrayTypes]},897(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.assertJSONBObjectAgainstSchema=t.validateJSONBObjectAgainstSchema=t.getJSONBSchemaValidationError=t.getJSONBObjectSchemaValidationError=t.getFieldTypeObj=void 0;const r=n(472),i=n(704),o=n(441);t.getFieldTypeObj=e=>"string"==typeof e?{type:e}:e;const s=e=>e instanceof Blob||"undefined"!=typeof Buffer&&e instanceof Buffer||"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer,a={string:e=>"string"==typeof e,number:e=>"number"==typeof e&&Number.isFinite(e),integer:e=>"number"==typeof e&&Number.isInteger(e),boolean:e=>"boolean"==typeof e,time:e=>"string"==typeof e,timestamp:e=>"string"==typeof e,any:e=>"function"!=typeof e&&"symbol"!=typeof e,unknown:e=>"function"!=typeof e&&"symbol"!=typeof e,Date:e=>"string"==typeof e,Lookup:e=>{throw new Error("Lookup type is not supported for validation")},Blob:s,FileLike:(e,t)=>{if("FileLike"!==t.type)throw new Error("FileLike type must have type 'FileLike'");const n=(0,r.isObject)(e)&&"string"==typeof e.name&&"string"==typeof e.type&&s(e.data);if(n&&t.mimeTypes&&!Object.keys(t.mimeTypes).some(t=>e.type===t))throw new Error(`Invalid FileLike type. Expected one of: ${Object.keys(t.mimeTypes).join(", ")}`);return n}},l=(0,r.getKeys)(a),c=(e,n,s=[],p)=>{const f=`${s.join(".")} is of invalid type. Expecting ${u(n).replaceAll("\n","")}`,d=(0,t.getFieldTypeObj)(n),{type:y,allowedValues:m,nullable:g,optional:h}=d;if(g&&null===e)return;if(h&&void 0===e)return;if(m){if("string"!=typeof y)throw new Error("allowedValues is only supported for primitive types");const t=y.endsWith("[]"),n=t&&Array.isArray(e)?e:[e],i=m.map(e=>(0,r.isObject)(e)?e.value:e);for(const[e,r]of n.entries())if(!i.includes(r))return`${t?`${s.join(".")}[${e}]`:s.join(".")} is of invalid type. Expecting ${i.map(e=>"string"==typeof e?JSON.stringify(e):String(e)).join(" | ")} But got ${JSON.stringify(r)}`}if(y){if((0,r.isObject)(y)){if(!(0,r.isObject)(e))return f;for(const t of(0,i.safeGetKeys)(y)){const n=(0,i.safeGetProperty)(y,t);if(!((0,r.isObject)(n)&&n.optional||(0,i.safeHasOwn)(e,t)))return`${[...s,t].join(".")} is missing but required`;const o=c((0,i.safeGetProperty)(e,t),n,[...s,t],p);if(void 0!==o)return o}if(!p?.allowExtraProperties){const t=(0,i.safeGetKeys)(e),n=(0,i.safeGetKeys)(y),r=t.filter(e=>!n.includes(e));if(r.length)return`${s.join(".")} has extra properties: ${r.join(", ")}`}return}const{validator:t}=((e,t)=>{const n=(e=>{if("string"==typeof e&&e.endsWith("[]")){const t=e.slice(0,-2);if(!(0,o.includes)(l,t))throw new Error(`Invalid array field type ${e}`);return t}})(e);if(n){const e=a[n];return{isArray:!0,validator:n=>Array.isArray(n)&&n.every(n=>e(n,t))}}const r=a[e];if(!r)throw new Error(`Unknown field type ${e}`);return{isArray:!1,validator:r}})(y,d);return t(e,d)?void 0:f}if(d.enum){const t=[];return d.nullable&&t.push(null),d.optional&&t.push(void 0),d.enum.includes(e)?void 0:f}const b=d.arrayOf??(d.arrayOfType?{type:d.arrayOfType}:void 0);if(b){if(!Array.isArray(e))return f+" an array";const t=e.map((e,t)=>c(e,b,[...s,`${t}`],p)).filter(r.isDefined)[0];return void 0!==t?`${f}. Error at index ${s.length>0?s.join(".")+".":""}\n\n${t}`:void 0}const O=d.oneOf??d.oneOfType?.map(e=>({type:e}));if(O){if(!O.length)return f+"to not be empty";let t;if(O.find(n=>{const r=c(e,n,s,p);return t??(t=r),void 0===r}))return;return f}if(d.record){const{keysEnum:t,partial:n,values:o}=d.record;if(!(0,r.isObject)(e))return f+"object";if(n&&(0,r.isEmpty)(e))return;const a=(0,r.getKeys)(e),l=n?void 0:t?.find(e=>!a.includes(e));if(void 0!==l)return`${f} to have key ${l}`;const u=t&&a.filter(e=>!t.includes(e));if(u?.length)return`${f} has extra keys: ${u}`;if(o)for(const t of(0,i.safeGetKeys)(e)){const n=(0,i.safeGetProperty)(e,t),r=c(n,o,[...s,t],p);if(void 0!==r)return`${r}`}return}return`Could not validate field type. Some logic might be missing: ${JSON.stringify(d)}`},u=e=>{const n=(0,t.getFieldTypeObj)(e),{type:i,nullable:o,optional:s,record:a}=n,l=n.oneOf??n.oneOfType?.map(e=>({type:e})),c=[];if(o&&c.push("null"),s&&c.push("undefined"),"string"==typeof i)c.push(i);else if(i&&(0,r.isObject)(i)){const e=[];Object.entries(i).forEach(([t,n])=>{e.push(`${t}: ${u(n)}`)}),c.push(`{ ${e.join("; ")} }`)}if(n.enum?.forEach(e=>{null===e?c.push("null"):void 0===e?c.push("undefined"):"string"==typeof e?c.push(JSON.stringify(e)):c.push(e)}),l?.forEach(e=>{const t=u(e);c.push(t)}),a){const{keysEnum:e,partial:t,values:n}=a,r=t?"?":"",i=n?u(n):"any";e?c.push(`{ [${e.join(" | ")}]${r}: ${i} }`):c.push(`{ [key: string]${r}: ${i} }`)}return c.join(" | ")};t.getJSONBObjectSchemaValidationError=(e,t,n="input",i=!1,o)=>{if(void 0===t&&!i)return{error:`Expecting ${n} to be defined`};if(!(0,r.isObject)(t))return{error:`Expecting ${n} to be an object`};const s=c(t,{type:e},[],o);return s?{error:s}:{data:t}},t.getJSONBSchemaValidationError=(e,t,n)=>{const r=c(t,e,void 0,n);return r?{error:r}:{data:t}},t.validateJSONBObjectAgainstSchema=(e,n,r,i=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,n,r,i);return void 0===o},t.assertJSONBObjectAgainstSchema=(e,n,r,i=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,n,r,i);if(o)throw new Error(o)}},699(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONSchemaObject=void 0,t.getJSONBSchemaAsJSONSchema=function(e,n,r){return(0,t.getJSONSchemaObject)(r,{id:`${e}.${n}`})};const r=n(472),i=n(704),o=e=>{if(!e)return;const t=e.endsWith("[]")?e.slice(0,-2):e;return{type:"integer"===t?"integer":"boolean"===t?"boolean":"number"===t?"number":"any"===t||"unknown"===t||"Lookup"===t||"Blob"===t||"FileLike"===t?void 0:"string",isArray:e.endsWith("[]")}};t.getJSONSchemaObject=(e,n)=>{const{type:s,arrayOf:a,arrayOfType:l,description:c,nullable:u,oneOf:p,oneOfType:f,title:d,record:y,...m}="string"==typeof e?{type:e}:e;let g={};const h={...(m.enum||m.allowedValues?.length&&("string"!=typeof s||!s.endsWith("[]")))&&{enum:m.allowedValues?.slice(0)??m.enum.slice(0)},...!!c&&{description:c},...!!d&&{title:d}};if(m.enum?.length){const e=typeof m.enum[0];h.type="number"===e?"number":"boolean"===e?"boolean":"string"}if("string"==typeof s||a||l){if(s&&"string"!=typeof s)throw"Not expected";g=a||l||s?.endsWith("[]")?{type:"array",items:a||l?(0,t.getJSONSchemaObject)(a||{type:l}):s?.startsWith("any")?{type:void 0}:{type:o(s)?.type,...m.allowedValues&&{enum:m.allowedValues.slice(0)}}}:{type:o(s)?.type}}else if((0,r.isObject)(s))g={type:"object",required:(0,i.safeGetKeys)(s).filter(e=>{const t=s[e];return"string"==typeof t||!t.optional}),properties:(0,r.getObjectEntries)(s).reduce((e,[n,r])=>({...e,[n]:(0,t.getJSONSchemaObject)(r)}),{})};else if(p||f){const e=p||f.map(e=>({type:e}));g={oneOf:e.map(e=>(0,t.getJSONSchemaObject)(e))}}else y&&(g={type:"object",...y.values&&!y.keysEnum&&{additionalProperties:(0,t.getJSONSchemaObject)(y.values)},...y.keysEnum&&{properties:y.keysEnum.reduce((e,n)=>({...e,[n]:y.values?(0,t.getJSONSchemaObject)(y.values):{type:{}}}),{})}});if(u){const e={type:"null"};g.oneOf?g.oneOf.push(e):g.enum&&!g.enum.includes(null)?g.enum.push(null):g={oneOf:[g,e]}}return{...n?{$id:n?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...h,...g}}},394(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBTSTypes=void 0,t.getJSONBSchemaTSTypes=function(e,n,r="",i){return(0,t.getJSONBTSTypes)(i,{...e,nullable:n.nullable},void 0,r)};const r=n(806),i=n(897),o=e=>null===e?"null":void 0===e?"undefined":"string"==typeof e?JSON.stringify(e):String(e);t.getJSONBTSTypes=(e,n,a=!1,l="",c=0)=>{const u=(0,i.getFieldTypeObj)(n),p=u.nullable?"null | ":"";if(u.lookup){const n=u.lookup;if("data-def"===n.type)return`${u.nullable?"null |":""} ${(0,t.getJSONBTSTypes)(e,{type:{table:"string",column:"string",filter:{record:{},optional:!0},isArray:{type:"boolean",optional:!0},searchColumns:{type:"string[]",optional:!0},isFullRow:{optional:!0,type:{displayColumns:{type:"string[]",optional:!0}}},showInRowCard:{optional:!0,record:{}}}})}`;const i="schema"===n.type;let o=i?"table"===n.object?"string":'{ "table": string; "column": string; }':"";if(!i){const t=e.find(e=>e.name===n.table)?.columns;o=n.isFullRow?t?`{ ${t.map(e=>`${JSON.stringify(e.name)}: ${e.is_nullable?"null | ":""} ${(0,r.postgresToTsType)(e.udt_name)}; `).join(" ")} }`:"any":(0,r.postgresToTsType)(t?.find(e=>e.name===n.column)?.udt_name??"text")}return`${u.nullable?"null | ":""}${o}${n.isArray?"[]":""}`}if("string"==typeof u.type){if(u.type.toLowerCase().includes("lookup"))throw new Error("getJSONBTSTypes: Lookup type not handled correctly");const e=u.type.replace("integer","number").replace("time","string").replace("timestamp","string").replace("FileLike","{ name: string; type: string; data: Blob; }").replace("Date","string");if(u.allowedValues){const e=u.type.endsWith("[]")?"[]":"";return p+` (${u.allowedValues.map(e=>JSON.stringify((0,r.isObject)(e)?e.value:e)).join(" | ")})${e}`}return p+e}if((0,r.isObject)(u.type)){const n=e=>e.trim().endsWith(";")?e:e.trim()+";",{type:o}=u,l=a?" ":" ";let f=` {${l}`+(0,r.getObjectEntries)(o).map(([r,o])=>{const a=(0,i.getFieldTypeObj)(o),u=s(r)?r:JSON.stringify(r);return`${l}${u}${a.optional?"?":""}: `+n((0,t.getJSONBTSTypes)(e,a,!0,void 0,c+1))}).join(" ")+`${l}}`;return a||(f=n(f)),a&&(f=f.split("\n").join("")),p+f}if(u.enum)return p+u.enum.map(e=>o(e)).join(" | ");if(u.oneOf||u.oneOfType){const n=u.oneOf||u.oneOfType.map(e=>({type:e}));return(u.nullable?`\n${l} | null`:"")+n.map(n=>`\n${l} | `+(0,t.getJSONBTSTypes)(e,n,!0,void 0,c+1)).join("")}if(u.arrayOf||u.arrayOfType){const n=u.arrayOf||{type:u.arrayOfType};return`${u.nullable?"null | ":""} ( ${(0,t.getJSONBTSTypes)(e,n,!0,void 0,c+1)} )[]`}if(u.record){const{keysEnum:n,values:r,partial:i}=u.record,s=e=>i?`Partial<Record<${e}>>`:`Record<${e}>`;return`${u.nullable?"null |":""} ${s(`${n?.map(e=>o(e)).join(" | ")??"string"}, ${r?(0,t.getJSONBTSTypes)(e,r,!0,void 0,c+1):"any"}`)}`}throw"Unexpected getSchemaTSTypes: "+JSON.stringify({fieldType:u},null,2)};const s=e=>/^[A-Za-z$_][A-Za-z0-9$_]*$/.test(e)},704(e,t){t.safeGetKeys=t.safeGetProperty=t.safeHasOwn=void 0;const n=["__proto__","constructor","prototype"];t.safeHasOwn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t.safeGetProperty=(e,t)=>{if(n.includes(t)){const n=Object.getOwnPropertyDescriptor(e,t);return n?.value}return e[t]},t.safeGetKeys=e=>{const r=Object.keys(e);for(const i of n)(0,t.safeHasOwn)(e,i)&&!r.includes(i)&&r.push(i);return r}},502(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.WAL=void 0;const r=n(806);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],o=+r-+i,s=r<i?-1:r==i?0:1;return"number"===n.tsDataType&&Number.isFinite(o)?o:s}).find(e=>e)||0},this.isInHistory=e=>{if(!e)throw"Provide item";const t=e[this.options.synced_field];if(!Number.isFinite(+t))throw"Provided item Synced field value is missing/invalid ";const n=this.sentHistory[this.getIdStr(e)],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=>((0,r.isEmpty)(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map(e=>{var t;const{initial:n,current:r,delta:i}={...e};if(!r)throw"Expecting { current: object, initial?: object }";const o=this.getIdStr(r);this.changed??(this.changed={}),(t=this.changed)[o]??(t[o]={initial:n,current:r,delta:i}),this.changed[o].current={...this.changed[o].current,...r},this.changed[o].delta={...this.changed[o].delta,...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:o,historyAgeSeconds:s=2}=this.options;if(this.isSendingTimeout||this.sending&&!(0,r.isEmpty)(this.sending))return;if(!this.changed||(0,r.isEmpty)(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,i).map(e=>{let t={...this.changed[e]};this.sending[e]={...t},c.push({...t}),u[e]={...t.current},delete this.changed[e]}),l=c.map(e=>{let t={};return Object.keys(e.current).map(n=>{const i=e.initial?.[n],o=e.current[n];![this.options.synced_field,...this.options.id_fields].includes(n)&&(0,r.isEqual)(i,o)||(t[n]=o)}),t}),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout(()=>{this.isSendingTimeout=void 0,(0,r.isEmpty)(this.changed)||this.sendItems()},o)),this.isOnSending=!0;try{await t(l,c),s&&(this.sentHistory={...this.sentHistory,...u},this.willDeleteHistory||(this.willDeleteHistory=setTimeout(()=>{this.willDeleteHistory=void 0,this.sentHistory={}},1e3*s)))}catch(e){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]),(0,r.isEmpty)(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||!((0,r.isEmpty)(this.sending)&&(0,r.isEmpty)(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}}},618(e,t){Object.defineProperty(t,"__esModule",{value:!0})},521(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=void 0,t.CONTENT_TYPE_TO_EXT={"text/html":["html","htm","shtml"],"text/css":["css"],"text/csv":["csv"],"text/tsv":["tsv"],"text/xml":["xml"],"text/mathml":["mml"],"text/plain":["txt"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/x-component":["htc"],"image/gif":["gif"],"image/jpeg":["jpeg","jpg"],"image/png":["png"],"image/tiff":["tif","tiff"],"image/vnd.wap.wbmp":["wbmp"],"image/x-icon":["ico"],"image/x-jng":["jng"],"image/x-ms-bmp":["bmp"],"image/svg+xml":["svg"],"image/webp":["webp"],"application/sql":["sql"],"application/x-javascript":["js"],"application/atom+xml":["atom"],"application/rss+xml":["rss"],"application/java-archive":["jar","war","ear"],"application/mac-binhex40":["hqx"],"application/msword":["doc","docx"],"application/pdf":["pdf"],"application/postscript":["ps","eps","ai"],"application/rtf":["rtf"],"application/vnd.ms-excel":["xls","xlsx"],"application/vnd.ms-powerpoint":["ppt","pptx"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/x-7z-compressed":["7z"],"application/x-cocoa":["cco"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-makeself":["run"],"application/x-perl":["pl","pm"],"application/x-pilot":["prc","pdb"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-sea":["sea"],"application/x-shockwave-flash":["swf"],"application/x-stuffit":["sit"],"application/x-tcl":["tcl","tk"],"application/x-x509-ca-cert":["der","pem","crt"],"application/x-xpinstall":["xpi"],"application/xhtml+xml":["xhtml"],"application/zip":["zip"],"application/octet-stream":["bin","exe","dll","deb","dmg","eot","iso","img","msi","msp","msm"],"audio/midi":["mid","midi","kar"],"audio/mpeg":["mp3"],"audio/ogg":["ogg"],"audio/x-realaudio":["ra"],"video/3gpp":["3gpp","3gp"],"video/mpeg":["mpeg","mpg"],"video/quicktime":["mov"],"video/x-flv":["flv"],"video/x-mng":["mng"],"video/x-ms-asf":["asx","asf"],"video/x-ms-wmv":["wmv"],"video/x-msvideo":["avi"],"video/mp4":["m4v","mp4"],"video/webm":["webm"]}},209(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.COMPLEX_FILTER_KEY=t.ComplexFilterComparisonKeys=t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.ArrayFilterOperands=t.TextFilter_FullTextSearchFilterKeys=t.TextFilterFTSKeys=t.TextFilterKeys=t.JsonbFilterKeys=t.JsonbOperands=t.BetweenFilterKeys=t.CompareInFilterKeys=t.CompareFilterKeys=void 0;const r=n(472);t.CompareFilterKeys=["=","<>",">","<",">=","<=","$eq","$ne","$gt","$gte","$lt","$lte","$isDistinctFrom","$isNotDistinctFrom"],t.CompareInFilterKeys=["$in","$nin"],t.BetweenFilterKeys=["$between","$notBetween"],t.JsonbOperands={"@>":{Operator:"@>","Right Operand Type":"jsonb",Description:"Does the left JSON value contain the right JSON path/value entries at the top level?",Example:'\'{"a":1, "b":2}\'::jsonb @> \'{"b":2}\'::jsonb'},"<@":{Operator:"<@","Right Operand Type":"jsonb",Description:"Are the left JSON path/value entries contained at the top level within the right JSON value?",Example:'\'{"b":2}\'::jsonb <@ \'{"a":1, "b":2}\'::jsonb'},"?":{Operator:"?","Right Operand Type":"text",Description:"Does the string exist as a top-level key within the JSON value?",Example:"'{\"a\":1, \"b\":2}'::jsonb ? 'b'"},"?|":{Operator:"?|","Right Operand Type":"text[]",Description:"Do any of these array strings exist as top-level keys?",Example:"'{\"a\":1, \"b\":2, \"c\":3}'::jsonb ?| array['b', 'c']"},"?&":{Operator:"?&","Right Operand Type":"text[]",Description:"Do all of these array strings exist as top-level keys?",Example:"'[\"a\", \"b\"]'::jsonb ?& array['a', 'b']"},"||":{Operator:"||","Right Operand Type":"jsonb",Description:"Concatenate two jsonb values into a new jsonb value",Example:'\'["a", "b"]\'::jsonb || \'["c", "d"]\'::jsonb'},"-":{Operator:"-","Right Operand Type":"integer",Description:"Delete the array element with specified index (Negative integers count from the end). Throws an error if top level container is not an array.",Example:'\'["a", "b"]\'::jsonb - 1'},"#-":{Operator:"#-","Right Operand Type":"text[]",Description:"Delete the field or element with specified path (for JSON arrays, negative integers count from the end)",Example:"'[\"a\", {\"b\":1}]'::jsonb #- '{1,b}'"},"@?":{Operator:"@?","Right Operand Type":"jsonpath",Description:"Does JSON path return any item for the specified JSON value?",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)'"},"@@":{Operator:"@@","Right Operand Type":"jsonpath",Description:"Returns the result of JSON path predicate check for the specified JSON value. Only the first item of the result is taken into account. If the result is not Boolean, then null is returned.",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @@ '$.a[*] > 2'"}},t.JsonbFilterKeys=(0,r.getKeys)(t.JsonbOperands),t.TextFilterKeys=["$ilike","$like","$nilike","$nlike"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.ArrayFilterOperands=["@>","<@","=","$eq","$contains","$containedBy","&&","$overlaps"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"],t.GeomFilter_Funcs=["ST_MakeEnvelope","st_makeenvelope","ST_MakePolygon","st_makepolygon"],t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"],t.ComplexFilterComparisonKeys=[...t.TextFilterKeys,...t.JsonbFilterKeys,...t.CompareFilterKeys,...t.BetweenFilterKeys,...t.CompareInFilterKeys],t.COMPLEX_FILTER_KEY="$filter"},806(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.CONTENT_TYPE_TO_EXT=t.getPossibleNestedInsert=t.SQL_COMMAND_TABLE_METHODS=t.CHANNELS=t.CHANNEL_PREFIX=t.JOIN_PARAMS=t.JOIN_KEYS=t.getAllowedTableMethods=t.postgresToTsType=t.TS_PG_Types=t._PG_geometric=t._PG_postgis=t._PG_interval=t._PG_date=t._PG_bool=t._PG_json=t._PG_numbers=t._PG_numbers_str=t._PG_numbers_num=t._PG_strings=void 0;const o=n(472),s=n(441);t._PG_strings=["bpchar","char","varchar","text","citext","uuid","bytea","time","timetz","interval","name","cidr","inet","macaddr","macaddr8","int4range","int8range","numrange","tsvector"],t._PG_numbers_num=["int2","int4","float4","float8","oid"],t._PG_numbers_str=["int8","numeric","money"],t._PG_numbers=[...t._PG_numbers_num,...t._PG_numbers_str],t._PG_json=["json","jsonb"],t._PG_bool=["bool"],t._PG_date=["date","timestamp","timestamptz"],t._PG_interval=["interval"],t._PG_postgis=["geometry","geography"],t._PG_geometric=["point","line","lseg","box","path","polygon","circle"];const a={string:[...t._PG_strings,...t._PG_numbers_str,...t._PG_date,...t._PG_geometric,...t._PG_postgis,"lseg"],number:t._PG_numbers_num,boolean:t._PG_bool,any:[...t._PG_json,...t._PG_interval]};t.TS_PG_Types={...a,"number[]":a.number.map(e=>`_${e}`),"boolean[]":a.boolean.map(e=>`_${e}`),"string[]":a.string.map(e=>`_${e}`),"any[]":a.any.map(e=>`_${e}`)},t.postgresToTsType=e=>(0,o.getKeys)(t.TS_PG_Types).find(n=>(0,s.includes)(t.TS_PG_Types[n],e))??"any",t.getAllowedTableMethods=({publishInfo:e})=>{let n=[...e.select||e.insert||e.delete||e.update?t.SQL_COMMAND_TABLE_METHODS.schema:[],...t.SQL_COMMAND_TABLE_METHODS.select.filter(t=>"sync"===t?void 0!==e.select?.syncConfig:e.select&&!Object.keys(e.select.disabledMethods??{}).includes(t)),...t.SQL_COMMAND_TABLE_METHODS.update.filter(t=>e.update&&!Object.keys(e.update.disabledMethods??{}).includes(t)),...e.insert?t.SQL_COMMAND_TABLE_METHODS.insert:[],...e.delete?t.SQL_COMMAND_TABLE_METHODS.delete:[]];const r=new Map;return Object.values(t.SQL_COMMAND_TABLE_METHODS).forEach(e=>{e.forEach(e=>{r.set(e,(r.get(e)??0)+1)})}),r.forEach((e,t)=>{n.filter(e=>e===t).length!==e&&r.delete(t)}),Array.from(r.keys())},t.JOIN_KEYS=["$innerJoin","$leftJoin"],t.JOIN_PARAMS=["select","filter","$path","$condition","offset","limit","orderBy"],t.CHANNEL_PREFIX="_psqlWS_.",t.CHANNELS={SCHEMA_CHANGED:t.CHANNEL_PREFIX+"schema-changed",SCHEMA:t.CHANNEL_PREFIX+"schema",DEFAULT:t.CHANNEL_PREFIX,SQL:`${t.CHANNEL_PREFIX}sql`,SQL_STREAM:`${t.CHANNEL_PREFIX}sql-stream`,METHOD:`${t.CHANNEL_PREFIX}method`,NOTICE_EV:`${t.CHANNEL_PREFIX}notice`,LISTEN_EV:`${t.CHANNEL_PREFIX}listen`,REGISTER:`${t.CHANNEL_PREFIX}register`,LOGIN:`${t.CHANNEL_PREFIX}login`,LOGOUT:`${t.CHANNEL_PREFIX}logout`,AUTH_GUARD:`${t.CHANNEL_PREFIX}authguard`,CONNECTION:`${t.CHANNEL_PREFIX}connection`,_preffix:t.CHANNEL_PREFIX},t.SQL_COMMAND_TABLE_METHODS={schema:["getColumns","getInfo"],insert:["insert","insertMany","upsert"],update:["update","upsert","updateBatch"],select:["findOne","find","count","size","subscribe","subscribeOne","sync"],delete:["delete","remove"]},t.getPossibleNestedInsert=(e,t,n=!0)=>{const r=(e.references??[]).map(e=>{const{ftable:n,fcols:r}=e,i=t.find(e=>e.name===n);if(!i)return;const o=i.columns.filter(e=>r.includes(e.name));return o.length?{ref:e,fcolsInfo:o}:void 0}).filter(o.isDefined),[i,...s]=r??[];if(!s.length)return i?.ref;const[a,...l]=r.filter(e=>e.fcolsInfo.some(e=>e.is_pkey));if(!l.length)return a?.ref;if(!n)throw["Cannot do a nested insert on column that references multiple tables.","Expecting only one reference to a single primary key fcol"].join("\n")},i(n(618),t);var l=n(521);Object.defineProperty(t,"CONTENT_TYPE_TO_EXT",{enumerable:!0,get:function(){return l.CONTENT_TYPE_TO_EXT}}),i(n(209),t),i(n(319),t),i(n(699),t),i(n(394),t),i(n(994),t),i(n(897),t),i(n(164),t),i(n(472),t),i(n(502),t),i(n(778),t)},319(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.leftJoin=t.innerJoin=void 0;const r=n(472),i=(e="$leftJoin")=>(t,n,i,o={})=>({[e]:o.path??t,filter:n,...(0,r.omitKeys)(o,["path","select"]),select:i});t.innerJoin=i("$innerJoin"),t.leftJoin=i("$leftJoin")},666(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=o(n,r=i(r,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=o(c,n,r,l,t[6],9,-1069501632),l=o(l,c,n,r,t[11],14,643717713),r=o(r,l,c,n,t[0],20,-373897302),n=o(n,r,l,c,t[5],5,-701558691),c=o(c,n,r,l,t[10],9,38016083),l=o(l,c,n,r,t[15],14,-660478335),r=o(r,l,c,n,t[4],20,-405537848),n=o(n,r,l,c,t[9],5,568446438),c=o(c,n,r,l,t[14],9,-1019803690),l=o(l,c,n,r,t[3],14,-187363961),r=o(r,l,c,n,t[8],20,1163531501),n=o(n,r,l,c,t[13],5,-1444681467),c=o(c,n,r,l,t[2],9,-51403784),l=o(l,c,n,r,t[7],14,1735328473),n=s(n,r=o(r,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=s(c,n,r,l,t[8],11,-2022574463),l=s(l,c,n,r,t[11],16,1839030562),r=s(r,l,c,n,t[14],23,-35309556),n=s(n,r,l,c,t[1],4,-1530992060),c=s(c,n,r,l,t[4],11,1272893353),l=s(l,c,n,r,t[7],16,-155497632),r=s(r,l,c,n,t[10],23,-1094730640),n=s(n,r,l,c,t[13],4,681279174),c=s(c,n,r,l,t[0],11,-358537222),l=s(l,c,n,r,t[3],16,-722521979),r=s(r,l,c,n,t[6],23,76029189),n=s(n,r,l,c,t[9],4,-640364487),c=s(c,n,r,l,t[12],11,-421815835),l=s(l,c,n,r,t[15],16,530742520),n=a(n,r=s(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,o){return t=f(f(t,e),f(r,o)),f(t<<i|t>>>32-i,n)}function i(e,t,n,i,o,s,a){return r(t&n|~t&i,e,t,o,s,a)}function o(e,t,n,i,o,s,a){return r(t&i|n&~i,e,t,o,s,a)}function s(e,t,n,i,o,s,a){return r(t^n^i,e,t,o,s,a)}function a(e,t,n,i,o,s,a){return r(n^(t|~i),e,t,o,s,a)}function l(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}t.md5=p;var c="0123456789abcdef".split("");function u(e){for(var t="",n=0;n<4;n++)t+=c[e>>8*n+4&15]+c[e>>8*n&15];return t}function p(e){return function(e){for(var t=0;t<e.length;t++)e[t]=u(e[t]);return e.join("")}(function(e){var t,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 o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<e.length;t++)o[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(n(i,o),t=0;t<16;t++)o[t]=0;return o[14]=8*r,n(i,o),i}(e))}function f(e,t){return e+t&4294967295}p("hello")},164(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.ReplicationProtocol=t.getSyncChannelName=void 0;const r=n(806);var i;t.getSyncChannelName=({tableName:e,filter:t={},select:n="*"})=>[r.CHANNEL_PREFIX,e,"sync",(0,r.stableStringify)(t),"string"==typeof n?n:(0,r.stableStringify)(n)].join("."),function(e){e.CreateSchema={name:"Create",source:"client",request:{type:{tableName:"string",command:{enum:["sync"]},param1:{record:{values:"unknown"}},param2:{type:{select:"unknown"}}}},response:{type:{id_fields:"string[]",synced_field:"string",channelName:"string",data:"any[]",isSynced:"boolean"}}};const t={state:{enum:["syncing"]},c_fr:{optional:!0,record:{values:"unknown"}},c_lr:{optional:!0,record:{values:"unknown"}},c_count:"number"},n={state:{enum:["syncing-data"]},c_fr:{record:{values:"unknown"}},c_lr:{record:{values:"unknown"}},c_count:"number",data:{arrayOf:{record:{values:"unknown"}}}};e.ServerSyncRequest={name:"ServerSyncRequest",source:"server",request:{type:{from_synced:{oneOf:["string",{enum:[null]}]},to_synced:{oneOf:["string",{enum:[null]}]},end_offset:{oneOf:["number",{enum:[null]}]}}},response:{oneOfType:[t,n,{state:{enum:["error"]},err:"unknown"}]}},e.ClientSyncRequest={name:"ClientSyncRequest",source:"client",request:{oneOfType:[t,n]},response:e.ServerSyncRequest.response},e.PullRequest={name:"PullRequest",source:"server",request:{type:{from_synced:{oneOf:["string",{enum:[void 0]}]},to_synced:{oneOf:["string",{enum:[void 0]}]},offset:{oneOf:["number",{enum:[void 0]}]},limit:{oneOf:["number",{enum:[void 0]}]}}},response:{oneOfType:[{success:{enum:[!0]},data:{arrayOf:{record:{values:"unknown"}}}},{success:{enum:[!1]},err:"unknown"}]}},e.UpdateRequest={name:"UpdateRequest",source:"server",request:{oneOfType:[{state:{enum:["error"]},err:"unknown"},{state:{enum:["synced"]},isSynced:"boolean"},{state:{enum:["syncing"]},data:{arrayOf:{record:{values:"unknown"}}}}]},response:{oneOfType:[{success:{enum:[!0]}},{success:{enum:[!1]},err:"unknown"}]}};const i={ClientSyncRequest:e.ClientSyncRequest,ServerSyncRequest:e.ServerSyncRequest,PullRequest:e.PullRequest,UpdateRequest:e.UpdateRequest},o=Object.values(i);e.getHandlers=(e,t,n,s)=>(t.removeAllListeners(e),t.on(e,async(e,t)=>{const{type:i,request:a}=(0,r.isObject)(e)?e:{};if("string"!=typeof i||!a)return void t("Unexpected data");const l=o.find(e=>e.name===i&&e.source!==n);if(!l)return void t("Invalid data.type");if(l.source===n)return void t("Invalid schema.source");if("server"===n&&"server"===l.source){const e=(0,r.getJSONBSchemaValidationError)(l.request,a);if(void 0!==e.error)return console.error("Invalid request from client",e.error,a),void t(e.error)}const c=l.name;try{t(void 0,await s[c](a))}catch(e){t((0,r.getSerialisableError)(e))}}),(0,r.fromEntries)((0,r.getEntries)(i).map(([i,o])=>{if(o.source===n)return[i,i=>new Promise((s,a)=>{t.emit(e,{type:o.name,request:i},e=>{if("server"===n){const t=(0,r.getJSONBSchemaValidationError)(o.response,e);if(void 0!==t.error)return console.error("Invalid response from client",t.error,e),void a(t.error)}s(e)})})]}).filter(r.isDefined)))}(i||(t.ReplicationProtocol=i={}))},472(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.fromEntries=t.getEntries=t.withTimeout=t.getProperty=t.getSerialisableError=t.safeStringify=t.extractTypeUtil=t.reverseParsedPath=t.reverseJoinOn=t.tryCatch=t.getObjectEntries=t.isNotEmpty=t.pickKeys=void 0,t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},t.omitKeys=i,t.filter=o,t.find=function(e,t){return o(e,t)[0]},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]},o={key:r,value:e[r]};return n(i,o)}}),o=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var n,s;if(Array.isArray(t)){for(s="[",n=0;n<t.length;n++)n&&(s+=","),s+=e(t[n])||"null";return s+"]"}if(null===t)return"null";if(-1!==o.indexOf(t)){if(r)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=o.push(t)-1,l=Object.keys(t).sort(i&&i(t));for(s="",n=0;n<l.length;n++){var c=l[n],u=e(t[c]);u&&(s&&(s+=","),s+=JSON.stringify(c)+":"+u)}return o.splice(a,1),"{"+s+"}"}}(e)},t.getTextPatch=function(e,t){if(!(e&&t&&e.trim().length&&t.trim().length))return t;if(e===t)return{from:0,to:0,text:"",md5:(0,r.md5)(t)};function n(n=1){let r=n<1?-1:0,i=!1;for(;!i&&Math.abs(r)<=t.length;){const o=n<1?[r]:[0,r];e.slice(...o)!==t.slice(...o)?i=!0:r+=1*Math.sign(n)}return r}let i=n()-1,o=e.length+n(-1)+1,s=t.length+n(-1)+1;return{from:i,to:o,text:t.slice(i,s),md5:(0,r.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:i,text:o,md5:s}=t;if(null===o||null===e)return o;let a=e.slice(0,n)+o+e.slice(i);if(s&&(0,r.md5)(a)!==s)throw"Patch text error: Could not match md5 hash: (original/result) \n"+e+"\n"+a;return a},t.isEmpty=s,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=a,t.getKeys=l;const r=n(666);function i(e,n){return(0,t.pickKeys)(e,l(e).filter(e=>!n.includes(e)))}function o(e,t){return e.filter(e=>Object.entries(t).every(([t,n])=>e[t]===n))}function s(e){for(var t in e)return!1;return!0}function a(e){return null!=e}function l(e){return Object.keys(e)}t.pickKeys=(e,t=[],n=!0)=>{if(!t.length)return{};if(e&&t.length){let r={};return t.forEach(t=>{n&&void 0===e[t]||(r[t]=e[t])}),r}return e},t.isNotEmpty=e=>!s(e),t.getObjectEntries=e=>Object.entries(e),t.tryCatch=async e=>{const t=Date.now();try{return{...await e(),duration:Date.now()-t}}catch(e){return{error:e,hasError:!0,duration:Date.now()-t}}},t.reverseJoinOn=e=>e.map(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[t,e]))),t.reverseParsedPath=(e,n)=>{const r=[{table:n,on:[{}]},...e??[]];return r.map((e,n)=>{const i=r[n+1];if(i)return{table:e.table,on:(0,t.reverseJoinOn)(i.on)}}).filter(a).reverse()},t.extractTypeUtil=(e,t)=>{if(Object.entries(t).every(([t,n])=>e[t]===n))return e},t.safeStringify=e=>{const t=new WeakSet;return JSON.stringify(e,(e,n)=>{if("object"==typeof n&&null!==n){if(t.has(n))return"[Circular]";t.add(n)}return n})},t.getSerialisableError=(e,n=!1)=>{if(null==e)return e;if("string"==typeof e||"boolean"==typeof e||"bigint"==typeof e||void 0===e||"number"==typeof e)return e?.toString();if(e instanceof DOMException)return{name:e.name,message:e.message,code:e.code,...n?{stack:e.stack}:{}};if(e instanceof Error){const r=Object.getOwnPropertyNames(e).reduce((t,n)=>({...t,[n]:e[n]}),{}),o=JSON.parse((0,t.safeStringify)(r));return n?o:i(o,["stack"])}return Array.isArray(e)?e.map(e=>(0,t.getSerialisableError)(e,n)):e},t.getProperty=(e,t)=>{if(Object.keys(e).includes(t))return e[t]},t.withTimeout=(e,t)=>{const n=new Promise((e,n)=>setTimeout(()=>n(new Error(`Timed out after ${t}ms`)),t));return Promise.race([e,n])},t.getEntries=e=>Object.entries(e),t.fromEntries=e=>Object.fromEntries(e)},441(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.includes=function(e,t){return e.some(e=>e===t)}},778(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}),i(n(102),t),i(n(436),t),i(n(441),t)},102(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.isEqual=void 0,t.isEqual=(e,t,r="trace")=>n(e,t,void 0,r);const n=(e,t,r=new WeakMap,i)=>{if(e===t)return!0;if(typeof e!=typeof t)return!1;if(null===e||null===t)return!1;if("object"!=typeof e||"object"!=typeof t)return e!=e&&t!=t;let o=r.get(e);if(o?.has(t)){if("quiet"!==i&&console.trace("Circular reference detected in isEqual",e,t),"error"===i)throw new Error("Circular reference detected in isEqual");return"return-true"===i}if(o||(o=new WeakSet,r.set(e,o)),o.add(t),e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.source===t.source&&e.flags===t.flags;const s=Array.isArray(e),a=Array.isArray(t);if(s&&a){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!n(e[o],t[o],r,i))return!1;return!0}if(s!==a)return!1;if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if(e.byteLength!==t.byteLength)return!1;const n=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0}if(e instanceof ArrayBuffer&&t instanceof ArrayBuffer){if(e.byteLength!==t.byteLength)return!1;const n=new Uint8Array(e),r=new Uint8Array(t);for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0}const l=Object.keys(e);if(l.length!==Object.keys(t).length)return!1;for(const o of l){if(!(o in t))return!1;{const s=e[o],a=t[o];if(!n(s,a,r,i))return!1}}return!0}},436(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.tryCatchV2=void 0,t.tryCatchV2=e=>{const t=Date.now();try{const n=e();return n instanceof Promise?new Promise(async(e,r)=>{e({...await n.then(e=>({data:e})).catch(e=>({error:e,hasError:!0})),duration:Date.now()-t})}):{data:n,duration:Date.now()-t}}catch(e){return{error:e,hasError:!0,duration:Date.now()-t}}}}},t={};return function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}(806)})());
|
|
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]}}(Object(this||window),()=>(()=>{"use strict";var e={994(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=t.PrimitiveTypesObj=void 0;const r=n(472);t.PrimitiveTypesObj={boolean:1,number:1,integer:1,string:1,Date:1,time:1,timestamp:1,Blob:1,FileLike:1,any:1,unknown:1},t.PrimitiveTypes=(0,r.getKeys)(t.PrimitiveTypesObj),t.PrimitiveArrayTypes=t.PrimitiveTypes.map(e=>`${e}[]`),t.DATA_TYPES=[...t.PrimitiveTypes,...t.PrimitiveArrayTypes]},897(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.assertJSONBObjectAgainstSchema=t.validateJSONBObjectAgainstSchema=t.getJSONBSchemaValidationError=t.getJSONBObjectSchemaValidationError=t.getFieldTypeObj=void 0;const r=n(472),i=n(704),o=n(441);t.getFieldTypeObj=e=>"string"==typeof e?{type:e}:e;const s=e=>e instanceof Blob||"undefined"!=typeof Buffer&&e instanceof Buffer||"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer,a={string:e=>"string"==typeof e,number:e=>"number"==typeof e&&Number.isFinite(e),integer:e=>"number"==typeof e&&Number.isInteger(e),boolean:e=>"boolean"==typeof e,time:e=>"string"==typeof e,timestamp:e=>"string"==typeof e,any:e=>"function"!=typeof e&&"symbol"!=typeof e,unknown:e=>"function"!=typeof e&&"symbol"!=typeof e,Date:e=>"string"==typeof e,Lookup:e=>{throw new Error("Lookup type is not supported for validation")},Blob:s,FileLike:(e,t)=>{if("FileLike"!==t.type)throw new Error("FileLike type must have type 'FileLike'");const n=(0,r.isObject)(e)&&"string"==typeof e.name&&"string"==typeof e.type&&s(e.data);if(n&&t.mimeTypes&&!Object.keys(t.mimeTypes).some(t=>e.type===t))throw new Error(`Invalid FileLike type. Expected one of: ${Object.keys(t.mimeTypes).join(", ")}`);return n}},l=(0,r.getKeys)(a),c=(e,n,s=[],p)=>{const f=`${s.join(".")} is of invalid type. Expecting ${u(n).replaceAll("\n","")}`,d=(0,t.getFieldTypeObj)(n),{type:y,allowedValues:m,nullable:g,optional:h}=d;if(g&&null===e)return;if(h&&void 0===e)return;if(m){if("string"!=typeof y)throw new Error("allowedValues is only supported for primitive types");const t=y.endsWith("[]"),n=t&&Array.isArray(e)?e:[e],i=m.map(e=>(0,r.isObject)(e)?e.value:e);for(const[e,r]of n.entries())if(!i.includes(r))return`${t?`${s.join(".")}[${e}]`:s.join(".")} is of invalid type. Expecting ${i.map(e=>"string"==typeof e?JSON.stringify(e):String(e)).join(" | ")} But got ${JSON.stringify(r)}`}if(y){if((0,r.isObject)(y)){if(!(0,r.isObject)(e))return f;for(const t of(0,i.safeGetKeys)(y)){const n=(0,i.safeGetProperty)(y,t);if(!((0,r.isObject)(n)&&n.optional||(0,i.safeHasOwn)(e,t)))return`${[...s,t].join(".")} is missing but required`;const o=c((0,i.safeGetProperty)(e,t),n,[...s,t],p);if(void 0!==o)return o}if(!p?.allowExtraProperties){const t=(0,i.safeGetKeys)(e),n=(0,i.safeGetKeys)(y),r=t.filter(e=>!n.includes(e));if(r.length)return`${s.join(".")} has extra properties: ${r.join(", ")}`}return}const{validator:t}=((e,t)=>{const n=(e=>{if("string"==typeof e&&e.endsWith("[]")){const t=e.slice(0,-2);if(!(0,o.includes)(l,t))throw new Error(`Invalid array field type ${e}`);return t}})(e);if(n){const e=a[n];return{isArray:!0,validator:n=>Array.isArray(n)&&n.every(n=>e(n,t))}}const r=a[e];if(!r)throw new Error(`Unknown field type ${e}`);return{isArray:!1,validator:r}})(y,d);return t(e,d)?void 0:f}if(d.enum){const t=[];return d.nullable&&t.push(null),d.optional&&t.push(void 0),d.enum.includes(e)?void 0:f}const b=d.arrayOf??(d.arrayOfType?{type:d.arrayOfType}:void 0);if(b){if(!Array.isArray(e))return f+" an array";const t=e.map((e,t)=>c(e,b,[...s,`${t}`],p)).filter(r.isDefined)[0];return void 0!==t?`${f}. Error at index ${s.length>0?s.join(".")+".":""}\n\n${t}`:void 0}const O=d.oneOf??d.oneOfType?.map(e=>({type:e}));if(O){if(!O.length)return f+"to not be empty";let t;if(O.find(n=>{const r=c(e,n,s,p);return t??(t=r),void 0===r}))return;return f}if(d.record){const{keysEnum:t,partial:n,values:o}=d.record;if(!(0,r.isObject)(e))return f+"object";if(n&&(0,r.isEmpty)(e))return;const a=(0,r.getKeys)(e),l=n?void 0:t?.find(e=>!a.includes(e));if(void 0!==l)return`${f} to have key ${l}`;const u=t&&a.filter(e=>!t.includes(e));if(u?.length)return`${f} has extra keys: ${u}`;if(o)for(const t of(0,i.safeGetKeys)(e)){const n=(0,i.safeGetProperty)(e,t),r=c(n,o,[...s,t],p);if(void 0!==r)return`${r}`}return}return`Could not validate field type. Some logic might be missing: ${JSON.stringify(d)}`},u=e=>{const n=(0,t.getFieldTypeObj)(e),{type:i,nullable:o,optional:s,record:a}=n,l=n.oneOf??n.oneOfType?.map(e=>({type:e})),c=[];if(o&&c.push("null"),s&&c.push("undefined"),"string"==typeof i)c.push(i);else if(i&&(0,r.isObject)(i)){const e=[];Object.entries(i).forEach(([t,n])=>{e.push(`${t}: ${u(n)}`)}),c.push(`{ ${e.join("; ")} }`)}if(n.enum?.forEach(e=>{null===e?c.push("null"):void 0===e?c.push("undefined"):"string"==typeof e?c.push(JSON.stringify(e)):c.push(e)}),l?.forEach(e=>{const t=u(e);c.push(t)}),a){const{keysEnum:e,partial:t,values:n}=a,r=t?"?":"",i=n?u(n):"any";e?c.push(`{ [${e.join(" | ")}]${r}: ${i} }`):c.push(`{ [key: string]${r}: ${i} }`)}return c.join(" | ")};t.getJSONBObjectSchemaValidationError=(e,t,n="input",i=!1,o)=>{if(void 0===t&&!i)return{error:`Expecting ${n} to be defined`};if(!(0,r.isObject)(t))return{error:`Expecting ${n} to be an object`};const s=c(t,{type:e},[],o);return s?{error:s}:{data:t}},t.getJSONBSchemaValidationError=(e,t,n)=>{const r=c(t,e,void 0,n);return r?{error:r}:{data:t}},t.validateJSONBObjectAgainstSchema=(e,n,r,i=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,n,r,i);return void 0===o},t.assertJSONBObjectAgainstSchema=(e,n,r,i=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,n,r,i);if(o)throw new Error(o)}},699(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONSchemaObject=void 0,t.getJSONBSchemaAsJSONSchema=function(e,n,r){return(0,t.getJSONSchemaObject)(r,{id:`${e}.${n}`})};const r=n(472),i=n(704),o=e=>{if(!e)return;const t=e.endsWith("[]")?e.slice(0,-2):e;return{type:"integer"===t?"integer":"boolean"===t?"boolean":"number"===t?"number":"any"===t||"unknown"===t||"Lookup"===t||"Blob"===t||"FileLike"===t?void 0:"string",isArray:e.endsWith("[]")}};t.getJSONSchemaObject=(e,n)=>{const{type:s,arrayOf:a,arrayOfType:l,description:c,nullable:u,oneOf:p,oneOfType:f,title:d,record:y,...m}="string"==typeof e?{type:e}:e;let g={};const h={...(m.enum||m.allowedValues?.length&&("string"!=typeof s||!s.endsWith("[]")))&&{enum:m.allowedValues?.slice(0)??m.enum.slice(0)},...!!c&&{description:c},...!!d&&{title:d}};if(m.enum?.length){const e=typeof m.enum[0];h.type="number"===e?"number":"boolean"===e?"boolean":"string"}if("string"==typeof s||a||l){if(s&&"string"!=typeof s)throw"Not expected";g=a||l||s?.endsWith("[]")?{type:"array",items:a||l?(0,t.getJSONSchemaObject)(a||{type:l}):s?.startsWith("any")?{type:void 0}:{type:o(s)?.type,...m.allowedValues&&{enum:m.allowedValues.slice(0)}}}:{type:o(s)?.type}}else if((0,r.isObject)(s))g={type:"object",required:(0,i.safeGetKeys)(s).filter(e=>{const t=s[e];return"string"==typeof t||!t.optional}),properties:(0,r.getObjectEntries)(s).reduce((e,[n,r])=>({...e,[n]:(0,t.getJSONSchemaObject)(r)}),{})};else if(p||f){const e=p||f.map(e=>({type:e}));g={oneOf:e.map(e=>(0,t.getJSONSchemaObject)(e))}}else y&&(g={type:"object",...y.values&&!y.keysEnum&&{additionalProperties:(0,t.getJSONSchemaObject)(y.values)},...y.keysEnum&&{properties:y.keysEnum.reduce((e,n)=>({...e,[n]:y.values?(0,t.getJSONSchemaObject)(y.values):{type:{}}}),{})}});if(u){const e={type:"null"};g.oneOf?g.oneOf.push(e):g.enum&&!g.enum.includes(null)?g.enum.push(null):g={oneOf:[g,e]}}return{...n?{$id:n?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...h,...g}}},394(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBTSTypes=void 0,t.getJSONBSchemaTSTypes=function(e,n,r="",i){return(0,t.getJSONBTSTypes)(i,{...e,nullable:n.nullable},void 0,r)};const r=n(806),i=n(897),o=e=>null===e?"null":void 0===e?"undefined":"string"==typeof e?JSON.stringify(e):String(e);t.getJSONBTSTypes=(e,n,a=!1,l="",c=0)=>{const u=(0,i.getFieldTypeObj)(n),p=u.nullable?"null | ":"";if(u.lookup){const n=u.lookup;if("data-def"===n.type)return`${u.nullable?"null |":""} ${(0,t.getJSONBTSTypes)(e,{type:{table:"string",column:"string",filter:{record:{},optional:!0},isArray:{type:"boolean",optional:!0},searchColumns:{type:"string[]",optional:!0},isFullRow:{optional:!0,type:{displayColumns:{type:"string[]",optional:!0}}},showInRowCard:{optional:!0,record:{}}}})}`;const i="schema"===n.type;let o=i?"table"===n.object?"string":'{ "table": string; "column": string; }':"";if(!i){const t=e.find(e=>e.name===n.table)?.columns;o=n.isFullRow?t?`{ ${t.map(e=>`${JSON.stringify(e.name)}: ${e.is_nullable?"null | ":""} ${(0,r.postgresToTsType)(e.udt_name)}; `).join(" ")} }`:"any":(0,r.postgresToTsType)(t?.find(e=>e.name===n.column)?.udt_name??"text")}return`${u.nullable?"null | ":""}${o}${n.isArray?"[]":""}`}if("string"==typeof u.type){if(u.type.toLowerCase().includes("lookup"))throw new Error("getJSONBTSTypes: Lookup type not handled correctly");const e=u.type.replace("integer","number").replace("time","string").replace("timestamp","string").replace("FileLike","{ name: string; type: string; data: Blob; }").replace("Date","string");if(u.allowedValues){const e=u.type.endsWith("[]")?"[]":"";return p+` (${u.allowedValues.map(e=>JSON.stringify((0,r.isObject)(e)?e.value:e)).join(" | ")})${e}`}return p+e}if((0,r.isObject)(u.type)){const n=e=>e.trim().endsWith(";")?e:e.trim()+";",{type:o}=u,l=a?" ":" ";let f=` {${l}`+(0,r.getObjectEntries)(o).map(([r,o])=>{const a=(0,i.getFieldTypeObj)(o),u=s(r)?r:JSON.stringify(r);return`${l}${u}${a.optional?"?":""}: `+n((0,t.getJSONBTSTypes)(e,a,!0,void 0,c+1))}).join(" ")+`${l}}`;return a||(f=n(f)),a&&(f=f.split("\n").join("")),p+f}if(u.enum)return p+u.enum.map(e=>o(e)).join(" | ");if(u.oneOf||u.oneOfType){const n=u.oneOf||u.oneOfType.map(e=>({type:e}));return(u.nullable?`\n${l} | null`:"")+n.map(n=>`\n${l} | `+(0,t.getJSONBTSTypes)(e,n,!0,void 0,c+1)).join("")}if(u.arrayOf||u.arrayOfType){const n=u.arrayOf||{type:u.arrayOfType};return`${u.nullable?"null | ":""} ( ${(0,t.getJSONBTSTypes)(e,n,!0,void 0,c+1)} )[]`}if(u.record){const{keysEnum:n,values:r,partial:i}=u.record,s=e=>i?`Partial<Record<${e}>>`:`Record<${e}>`;return`${u.nullable?"null |":""} ${s(`${n?.map(e=>o(e)).join(" | ")??"string"}, ${r?(0,t.getJSONBTSTypes)(e,r,!0,void 0,c+1):"any"}`)}`}throw"Unexpected getSchemaTSTypes: "+JSON.stringify({fieldType:u},null,2)};const s=e=>/^[A-Za-z$_][A-Za-z0-9$_]*$/.test(e)},704(e,t){t.safeGetKeys=t.safeGetProperty=t.safeHasOwn=void 0;const n=["__proto__","constructor","prototype"];t.safeHasOwn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t.safeGetProperty=(e,t)=>{if(n.includes(t)){const n=Object.getOwnPropertyDescriptor(e,t);return n?.value}return e[t]},t.safeGetKeys=e=>{const r=Object.keys(e);for(const i of n)(0,t.safeHasOwn)(e,i)&&!r.includes(i)&&r.push(i);return r}},502(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.WAL=void 0;const r=n(806);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],o=+r-+i,s=r<i?-1:r==i?0:1;return"number"===n.tsDataType&&Number.isFinite(o)?o:s}).find(e=>e)||0},this.isInHistory=e=>{if(!e)throw"Provide item";const t=e[this.options.synced_field];if(!Number.isFinite(+t))throw"Provided item Synced field value is missing/invalid ";const n=this.sentHistory[this.getIdStr(e)],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=>((0,r.isEmpty)(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map(e=>{var t;const{initial:n,current:r,delta:i}={...e};if(!r)throw"Expecting { current: object, initial?: object }";const o=this.getIdStr(r);this.changed??(this.changed={}),(t=this.changed)[o]??(t[o]={initial:n,current:r,delta:i}),this.changed[o].current={...this.changed[o].current,...r},this.changed[o].delta={...this.changed[o].delta,...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:o,historyAgeSeconds:s=2}=this.options;if(this.isSendingTimeout||this.sending&&!(0,r.isEmpty)(this.sending))return;if(!this.changed||(0,r.isEmpty)(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,i).map(e=>{let t={...this.changed[e]};this.sending[e]={...t},c.push({...t}),u[e]={...t.current},delete this.changed[e]}),l=c.map(e=>{let t={};return Object.keys(e.current).map(n=>{const i=e.initial?.[n],o=e.current[n];![this.options.synced_field,...this.options.id_fields].includes(n)&&(0,r.isEqual)(i,o)||(t[n]=o)}),t}),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout(()=>{this.isSendingTimeout=void 0,(0,r.isEmpty)(this.changed)||this.sendItems()},o)),this.isOnSending=!0;try{await t(l,c),s&&(this.sentHistory={...this.sentHistory,...u},this.willDeleteHistory||(this.willDeleteHistory=setTimeout(()=>{this.willDeleteHistory=void 0,this.sentHistory={}},1e3*s)))}catch(e){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]),(0,r.isEmpty)(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||!((0,r.isEmpty)(this.sending)&&(0,r.isEmpty)(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}}},618(e,t){Object.defineProperty(t,"__esModule",{value:!0})},521(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=void 0,t.CONTENT_TYPE_TO_EXT={"text/html":["html","htm","shtml"],"text/css":["css"],"text/csv":["csv"],"text/tsv":["tsv"],"text/xml":["xml"],"text/mathml":["mml"],"text/plain":["txt"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/x-component":["htc"],"image/gif":["gif"],"image/jpeg":["jpeg","jpg"],"image/png":["png"],"image/tiff":["tif","tiff"],"image/vnd.wap.wbmp":["wbmp"],"image/x-icon":["ico"],"image/x-jng":["jng"],"image/x-ms-bmp":["bmp"],"image/svg+xml":["svg"],"image/webp":["webp"],"application/sql":["sql"],"application/x-javascript":["js"],"application/atom+xml":["atom"],"application/rss+xml":["rss"],"application/java-archive":["jar","war","ear"],"application/mac-binhex40":["hqx"],"application/msword":["doc","docx"],"application/pdf":["pdf"],"application/postscript":["ps","eps","ai"],"application/rtf":["rtf"],"application/vnd.ms-excel":["xls","xlsx"],"application/vnd.ms-powerpoint":["ppt","pptx"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/x-7z-compressed":["7z"],"application/x-cocoa":["cco"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-makeself":["run"],"application/x-perl":["pl","pm"],"application/x-pilot":["prc","pdb"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-sea":["sea"],"application/x-shockwave-flash":["swf"],"application/x-stuffit":["sit"],"application/x-tcl":["tcl","tk"],"application/x-x509-ca-cert":["der","pem","crt"],"application/x-xpinstall":["xpi"],"application/xhtml+xml":["xhtml"],"application/zip":["zip"],"application/octet-stream":["bin","exe","dll","deb","dmg","eot","iso","img","msi","msp","msm"],"audio/midi":["mid","midi","kar"],"audio/mpeg":["mp3"],"audio/ogg":["ogg"],"audio/x-realaudio":["ra"],"video/3gpp":["3gpp","3gp"],"video/mpeg":["mpeg","mpg"],"video/quicktime":["mov"],"video/x-flv":["flv"],"video/x-mng":["mng"],"video/x-ms-asf":["asx","asf"],"video/x-ms-wmv":["wmv"],"video/x-msvideo":["avi"],"video/mp4":["m4v","mp4"],"video/webm":["webm"]}},209(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.COMPLEX_FILTER_KEY=t.ComplexFilterComparisonKeys=t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.ArrayFilterOperands=t.TextFilter_FullTextSearchFilterKeys=t.TextFilterFTSKeys=t.TextFilterKeys=t.JsonbFilterKeys=t.JsonbOperands=t.BetweenFilterKeys=t.CompareInFilterKeys=t.CompareFilterKeys=void 0;const r=n(472);t.CompareFilterKeys=["=","<>",">","<",">=","<=","$eq","$ne","$gt","$gte","$lt","$lte","$isDistinctFrom","$isNotDistinctFrom"],t.CompareInFilterKeys=["$in","$nin"],t.BetweenFilterKeys=["$between","$notBetween"],t.JsonbOperands={"@>":{Operator:"@>","Right Operand Type":"jsonb",Description:"Does the left JSON value contain the right JSON path/value entries at the top level?",Example:'\'{"a":1, "b":2}\'::jsonb @> \'{"b":2}\'::jsonb'},"<@":{Operator:"<@","Right Operand Type":"jsonb",Description:"Are the left JSON path/value entries contained at the top level within the right JSON value?",Example:'\'{"b":2}\'::jsonb <@ \'{"a":1, "b":2}\'::jsonb'},"?":{Operator:"?","Right Operand Type":"text",Description:"Does the string exist as a top-level key within the JSON value?",Example:"'{\"a\":1, \"b\":2}'::jsonb ? 'b'"},"?|":{Operator:"?|","Right Operand Type":"text[]",Description:"Do any of these array strings exist as top-level keys?",Example:"'{\"a\":1, \"b\":2, \"c\":3}'::jsonb ?| array['b', 'c']"},"?&":{Operator:"?&","Right Operand Type":"text[]",Description:"Do all of these array strings exist as top-level keys?",Example:"'[\"a\", \"b\"]'::jsonb ?& array['a', 'b']"},"||":{Operator:"||","Right Operand Type":"jsonb",Description:"Concatenate two jsonb values into a new jsonb value",Example:'\'["a", "b"]\'::jsonb || \'["c", "d"]\'::jsonb'},"-":{Operator:"-","Right Operand Type":"integer",Description:"Delete the array element with specified index (Negative integers count from the end). Throws an error if top level container is not an array.",Example:'\'["a", "b"]\'::jsonb - 1'},"#-":{Operator:"#-","Right Operand Type":"text[]",Description:"Delete the field or element with specified path (for JSON arrays, negative integers count from the end)",Example:"'[\"a\", {\"b\":1}]'::jsonb #- '{1,b}'"},"@?":{Operator:"@?","Right Operand Type":"jsonpath",Description:"Does JSON path return any item for the specified JSON value?",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)'"},"@@":{Operator:"@@","Right Operand Type":"jsonpath",Description:"Returns the result of JSON path predicate check for the specified JSON value. Only the first item of the result is taken into account. If the result is not Boolean, then null is returned.",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @@ '$.a[*] > 2'"}},t.JsonbFilterKeys=(0,r.getKeys)(t.JsonbOperands),t.TextFilterKeys=["$ilike","$like","$nilike","$nlike"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.ArrayFilterOperands=["@>","<@","=","$eq","$contains","$containedBy","&&","$overlaps"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"],t.GeomFilter_Funcs=["ST_MakeEnvelope","st_makeenvelope","ST_MakePolygon","st_makepolygon"],t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"],t.ComplexFilterComparisonKeys=[...t.TextFilterKeys,...t.JsonbFilterKeys,...t.CompareFilterKeys,...t.BetweenFilterKeys,...t.CompareInFilterKeys],t.COMPLEX_FILTER_KEY="$filter"},806(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.CONTENT_TYPE_TO_EXT=t.getPossibleNestedInsert=t.SQL_COMMAND_TABLE_METHODS=t.CHANNELS=t.CHANNEL_PREFIX=t.JOIN_PARAMS=t.JOIN_KEYS=t.getAllowedTableMethods=t.postgresToTsType=t.TS_PG_Types=t._PG_geometric=t._PG_postgis=t._PG_interval=t._PG_date=t._PG_bool=t._PG_json=t._PG_numbers=t._PG_numbers_str=t._PG_numbers_num=t._PG_strings=void 0;const o=n(472),s=n(441);t._PG_strings=["bpchar","char","varchar","text","citext","uuid","bytea","time","timetz","interval","name","cidr","inet","macaddr","macaddr8","int4range","int8range","numrange","tsvector"],t._PG_numbers_num=["int2","int4","float4","float8","oid"],t._PG_numbers_str=["int8","numeric","money"],t._PG_numbers=[...t._PG_numbers_num,...t._PG_numbers_str],t._PG_json=["json","jsonb"],t._PG_bool=["bool"],t._PG_date=["date","timestamp","timestamptz"],t._PG_interval=["interval"],t._PG_postgis=["geometry","geography"],t._PG_geometric=["point","line","lseg","box","path","polygon","circle"];const a={string:[...t._PG_strings,...t._PG_numbers_str,...t._PG_date,...t._PG_geometric,...t._PG_postgis,"lseg"],number:t._PG_numbers_num,boolean:t._PG_bool,any:[...t._PG_json,...t._PG_interval]};t.TS_PG_Types={...a,"number[]":a.number.map(e=>`_${e}`),"boolean[]":a.boolean.map(e=>`_${e}`),"string[]":a.string.map(e=>`_${e}`),"any[]":a.any.map(e=>`_${e}`)},t.postgresToTsType=e=>(0,o.getKeys)(t.TS_PG_Types).find(n=>(0,s.includes)(t.TS_PG_Types[n],e))??"any",t.getAllowedTableMethods=({publishInfo:e})=>{let n=[...e.select||e.insert||e.delete||e.update?t.SQL_COMMAND_TABLE_METHODS.schema:[],...t.SQL_COMMAND_TABLE_METHODS.select.filter(t=>"sync"===t?void 0!==e.select?.syncConfig:e.select&&!Object.keys(e.select.disabledMethods??{}).includes(t)),...t.SQL_COMMAND_TABLE_METHODS.update.filter(t=>e.update&&!Object.keys(e.update.disabledMethods??{}).includes(t)),...e.insert?t.SQL_COMMAND_TABLE_METHODS.insert:[],...e.delete?t.SQL_COMMAND_TABLE_METHODS.delete:[]];const r=new Map;return Object.values(t.SQL_COMMAND_TABLE_METHODS).forEach(e=>{e.forEach(e=>{r.set(e,(r.get(e)??0)+1)})}),r.forEach((e,t)=>{n.filter(e=>e===t).length!==e&&r.delete(t)}),Array.from(r.keys())},t.JOIN_KEYS=["$innerJoin","$leftJoin"],t.JOIN_PARAMS=["select","filter","$path","$condition","offset","limit","orderBy"],t.CHANNEL_PREFIX="_psqlWS_.",t.CHANNELS={SCHEMA_CHANGED:t.CHANNEL_PREFIX+"schema-changed",SCHEMA:t.CHANNEL_PREFIX+"schema",DEFAULT:t.CHANNEL_PREFIX,SQL:`${t.CHANNEL_PREFIX}sql`,SQL_STREAM:`${t.CHANNEL_PREFIX}sql-stream`,METHOD:`${t.CHANNEL_PREFIX}method`,NOTICE_EV:`${t.CHANNEL_PREFIX}notice`,LISTEN_EV:`${t.CHANNEL_PREFIX}listen`,REGISTER:`${t.CHANNEL_PREFIX}register`,LOGIN:`${t.CHANNEL_PREFIX}login`,LOGOUT:`${t.CHANNEL_PREFIX}logout`,AUTH_GUARD:`${t.CHANNEL_PREFIX}authguard`,CONNECTION:`${t.CHANNEL_PREFIX}connection`,_preffix:t.CHANNEL_PREFIX},t.SQL_COMMAND_TABLE_METHODS={schema:["getColumns","getInfo"],insert:["insert","insertMany","upsert"],update:["update","upsert","updateBatch"],select:["findOne","find","count","size","subscribe","subscribeOne","sync"],delete:["delete","remove"]},t.getPossibleNestedInsert=(e,t,n=!0)=>{const r=(e.references??[]).map(e=>{const{ftable:n,fcols:r}=e,i=t.find(e=>e.name===n);if(!i)return;const o=i.columns.filter(e=>r.includes(e.name));return o.length?{ref:e,fcolsInfo:o}:void 0}).filter(o.isDefined),[i,...s]=r??[];if(!s.length)return i?.ref;const[a,...l]=r.filter(e=>e.fcolsInfo.some(e=>e.is_pkey));if(!l.length)return a?.ref;if(!n)throw["Cannot do a nested insert on column that references multiple tables.","Expecting only one reference to a single primary key fcol"].join("\n")},i(n(618),t);var l=n(521);Object.defineProperty(t,"CONTENT_TYPE_TO_EXT",{enumerable:!0,get:function(){return l.CONTENT_TYPE_TO_EXT}}),i(n(209),t),i(n(319),t),i(n(699),t),i(n(394),t),i(n(994),t),i(n(897),t),i(n(164),t),i(n(472),t),i(n(502),t),i(n(778),t)},319(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.leftJoin=t.innerJoin=void 0;const r=n(472),i=(e="$leftJoin")=>(t,n,i,o={})=>({[e]:o.path??t,filter:n,...(0,r.omitKeys)(o,["path","select"]),select:i});t.innerJoin=i("$innerJoin"),t.leftJoin=i("$leftJoin")},666(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=o(n,r=i(r,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=o(c,n,r,l,t[6],9,-1069501632),l=o(l,c,n,r,t[11],14,643717713),r=o(r,l,c,n,t[0],20,-373897302),n=o(n,r,l,c,t[5],5,-701558691),c=o(c,n,r,l,t[10],9,38016083),l=o(l,c,n,r,t[15],14,-660478335),r=o(r,l,c,n,t[4],20,-405537848),n=o(n,r,l,c,t[9],5,568446438),c=o(c,n,r,l,t[14],9,-1019803690),l=o(l,c,n,r,t[3],14,-187363961),r=o(r,l,c,n,t[8],20,1163531501),n=o(n,r,l,c,t[13],5,-1444681467),c=o(c,n,r,l,t[2],9,-51403784),l=o(l,c,n,r,t[7],14,1735328473),n=s(n,r=o(r,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=s(c,n,r,l,t[8],11,-2022574463),l=s(l,c,n,r,t[11],16,1839030562),r=s(r,l,c,n,t[14],23,-35309556),n=s(n,r,l,c,t[1],4,-1530992060),c=s(c,n,r,l,t[4],11,1272893353),l=s(l,c,n,r,t[7],16,-155497632),r=s(r,l,c,n,t[10],23,-1094730640),n=s(n,r,l,c,t[13],4,681279174),c=s(c,n,r,l,t[0],11,-358537222),l=s(l,c,n,r,t[3],16,-722521979),r=s(r,l,c,n,t[6],23,76029189),n=s(n,r,l,c,t[9],4,-640364487),c=s(c,n,r,l,t[12],11,-421815835),l=s(l,c,n,r,t[15],16,530742520),n=a(n,r=s(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,o){return t=f(f(t,e),f(r,o)),f(t<<i|t>>>32-i,n)}function i(e,t,n,i,o,s,a){return r(t&n|~t&i,e,t,o,s,a)}function o(e,t,n,i,o,s,a){return r(t&i|n&~i,e,t,o,s,a)}function s(e,t,n,i,o,s,a){return r(t^n^i,e,t,o,s,a)}function a(e,t,n,i,o,s,a){return r(n^(t|~i),e,t,o,s,a)}function l(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}t.md5=p;var c="0123456789abcdef".split("");function u(e){for(var t="",n=0;n<4;n++)t+=c[e>>8*n+4&15]+c[e>>8*n&15];return t}function p(e){return function(e){for(var t=0;t<e.length;t++)e[t]=u(e[t]);return e.join("")}(function(e){var t,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 o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<e.length;t++)o[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(n(i,o),t=0;t<16;t++)o[t]=0;return o[14]=8*r,n(i,o),i}(e))}function f(e,t){return e+t&4294967295}p("hello")},164(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.ReplicationProtocol=t.getSyncChannelName=void 0;const r=n(806);var i;t.getSyncChannelName=({tableName:e,filter:t={},select:n="*"})=>[r.CHANNEL_PREFIX,e,"sync",(0,r.stableStringify)(t),"string"==typeof n?n:(0,r.stableStringify)(n)].join("."),function(e){e.CreateSchema={name:"Create",source:"client",request:{type:{tableName:"string",command:{enum:["sync"]},param1:{record:{values:"unknown"}},param2:{type:{select:"unknown"}}}},response:{type:{id_fields:"string[]",synced_field:"string",channelName:"string",data:"any[]",isSynced:"boolean"}}};const t={state:{enum:["syncing"]},c_fr:{optional:!0,record:{values:"unknown"}},c_lr:{optional:!0,record:{values:"unknown"}},c_count:"number"},n={state:{enum:["syncing-data"]},c_fr:{record:{values:"unknown"}},c_lr:{record:{values:"unknown"}},c_count:"number",data:{arrayOf:{record:{values:"unknown"}}}};e.ServerSyncRequest={name:"ServerSyncRequest",source:"server",request:{type:{from_synced:{oneOf:["string",{enum:[null]}]},to_synced:{oneOf:["string",{enum:[null]}]},end_offset:{oneOf:["number",{enum:[null]}]}}},response:{oneOfType:[t,n,{state:{enum:["error"]},err:"unknown"}]}},e.ClientSyncRequest={name:"ClientSyncRequest",source:"client",request:{oneOfType:[t,n]},response:{type:{ok:{enum:[!0]}}}},e.PullRequest={name:"PullRequest",source:"server",request:{type:{from_synced:{oneOf:["string",{enum:[void 0]}]},to_synced:{oneOf:["string",{enum:[void 0]}]},offset:{oneOf:["number",{enum:[void 0]}]},limit:{oneOf:["number",{enum:[void 0]}]}}},response:{oneOfType:[{success:{enum:[!0]},data:{arrayOf:{record:{values:"unknown"}}}},{success:{enum:[!1]},err:"unknown"}]}},e.UpdateRequest={name:"UpdateRequest",source:"server",request:{oneOfType:[{state:{enum:["error"]},err:"unknown"},{state:{enum:["synced"]},isSynced:"boolean"},{state:{enum:["syncing"]},data:{arrayOf:{record:{values:"unknown"}}}}]},response:{oneOfType:[{success:{enum:[!0]}},{success:{enum:[!1]},err:"unknown"}]}};const i={ClientSyncRequest:e.ClientSyncRequest,ServerSyncRequest:e.ServerSyncRequest,PullRequest:e.PullRequest,UpdateRequest:e.UpdateRequest},o=Object.values(i),s=(e,t,n,s)=>(t.removeAllListeners(e),t.on(e,async(e,t)=>{const{type:i,request:a}=(0,r.isObject)(e)?e:{};if("string"!=typeof i||!a)return void t("Unexpected data");const l=o.find(e=>e.name===i&&e.source!==n);if(!l)return void t("Invalid data.type");if(l.source===n)return void t("Invalid schema.source");if("server"===n&&"server"===l.source){const e=(0,r.getJSONBSchemaValidationError)(l.request,a);if(void 0!==e.error)return console.error("Invalid request from client",e.error,a),void t(e.error)}const c=l.name;try{t(void 0,await s[c](a))}catch(e){t((0,r.getSerialisableError)(e))}}),(0,r.fromEntries)((0,r.getEntries)(i).map(([i,o])=>{if(o.source===n)return[i,i=>new Promise((s,a)=>{t.emit(e,{type:o.name,request:i},e=>{if("server"===n){const t=(0,r.getJSONBSchemaValidationError)(o.response,e);if(void 0!==t.error)return console.error("Invalid response from client",t.error,e),void a(t.error)}s(e)})})]}).filter(r.isDefined)));e.getServerHandlers=(e,t,n)=>s(e,t,"server",n),e.getClientHandlers=(e,t,n)=>s(e,t,"client",n)}(i||(t.ReplicationProtocol=i={}))},472(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.fromEntries=t.getEntries=t.withTimeout=t.getProperty=t.getSerialisableError=t.safeStringify=t.extractTypeUtil=t.reverseParsedPath=t.reverseJoinOn=t.tryCatch=t.getObjectEntries=t.isNotEmpty=t.pickKeys=void 0,t.asName=function(e){if(null==e||!e.toString||!e.toString())throw"Expecting a non empty string";return`"${e.toString().replace(/"/g,'""')}"`},t.omitKeys=i,t.filter=o,t.find=function(e,t){return o(e,t)[0]},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]},o={key:r,value:e[r]};return n(i,o)}}),o=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var n,s;if(Array.isArray(t)){for(s="[",n=0;n<t.length;n++)n&&(s+=","),s+=e(t[n])||"null";return s+"]"}if(null===t)return"null";if(-1!==o.indexOf(t)){if(r)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=o.push(t)-1,l=Object.keys(t).sort(i&&i(t));for(s="",n=0;n<l.length;n++){var c=l[n],u=e(t[c]);u&&(s&&(s+=","),s+=JSON.stringify(c)+":"+u)}return o.splice(a,1),"{"+s+"}"}}(e)},t.getTextPatch=function(e,t){if(!(e&&t&&e.trim().length&&t.trim().length))return t;if(e===t)return{from:0,to:0,text:"",md5:(0,r.md5)(t)};function n(n=1){let r=n<1?-1:0,i=!1;for(;!i&&Math.abs(r)<=t.length;){const o=n<1?[r]:[0,r];e.slice(...o)!==t.slice(...o)?i=!0:r+=1*Math.sign(n)}return r}let i=n()-1,o=e.length+n(-1)+1,s=t.length+n(-1)+1;return{from:i,to:o,text:t.slice(i,s),md5:(0,r.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:i,text:o,md5:s}=t;if(null===o||null===e)return o;let a=e.slice(0,n)+o+e.slice(i);if(s&&(0,r.md5)(a)!==s)throw"Patch text error: Could not match md5 hash: (original/result) \n"+e+"\n"+a;return a},t.isEmpty=s,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=a,t.getKeys=l;const r=n(666);function i(e,n){return(0,t.pickKeys)(e,l(e).filter(e=>!n.includes(e)))}function o(e,t){return e.filter(e=>Object.entries(t).every(([t,n])=>e[t]===n))}function s(e){for(var t in e)return!1;return!0}function a(e){return null!=e}function l(e){return Object.keys(e)}t.pickKeys=(e,t=[],n=!0)=>{if(!t.length)return{};if(e&&t.length){let r={};return t.forEach(t=>{n&&void 0===e[t]||(r[t]=e[t])}),r}return e},t.isNotEmpty=e=>!s(e),t.getObjectEntries=e=>Object.entries(e),t.tryCatch=async e=>{const t=Date.now();try{return{...await e(),duration:Date.now()-t}}catch(e){return{error:e,hasError:!0,duration:Date.now()-t}}},t.reverseJoinOn=e=>e.map(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[t,e]))),t.reverseParsedPath=(e,n)=>{const r=[{table:n,on:[{}]},...e??[]];return r.map((e,n)=>{const i=r[n+1];if(i)return{table:e.table,on:(0,t.reverseJoinOn)(i.on)}}).filter(a).reverse()},t.extractTypeUtil=(e,t)=>{if(Object.entries(t).every(([t,n])=>e[t]===n))return e},t.safeStringify=e=>{const t=new WeakSet;return JSON.stringify(e,(e,n)=>{if("object"==typeof n&&null!==n){if(t.has(n))return"[Circular]";t.add(n)}return n})},t.getSerialisableError=(e,n=!1)=>{if(null==e)return e;if("string"==typeof e||"boolean"==typeof e||"bigint"==typeof e||void 0===e||"number"==typeof e)return e?.toString();if(e instanceof DOMException)return{name:e.name,message:e.message,code:e.code,...n?{stack:e.stack}:{}};if(e instanceof Error){const r=Object.getOwnPropertyNames(e).reduce((t,n)=>({...t,[n]:e[n]}),{}),o=JSON.parse((0,t.safeStringify)(r));return n?o:i(o,["stack"])}return Array.isArray(e)?e.map(e=>(0,t.getSerialisableError)(e,n)):e},t.getProperty=(e,t)=>{if(Object.keys(e).includes(t))return e[t]},t.withTimeout=(e,t)=>{const n=new Promise((e,n)=>setTimeout(()=>n(new Error(`Timed out after ${t}ms`)),t));return Promise.race([e,n])},t.getEntries=e=>Object.entries(e),t.fromEntries=e=>Object.fromEntries(e)},441(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.includes=function(e,t){return e.some(e=>e===t)}},778(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}),i(n(102),t),i(n(436),t),i(n(441),t)},102(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.isEqual=void 0,t.isEqual=(e,t,r="trace")=>n(e,t,void 0,r);const n=(e,t,r=new WeakMap,i)=>{if(e===t)return!0;if(typeof e!=typeof t)return!1;if(null===e||null===t)return!1;if("object"!=typeof e||"object"!=typeof t)return e!=e&&t!=t;let o=r.get(e);if(o?.has(t)){if("quiet"!==i&&console.trace("Circular reference detected in isEqual",e,t),"error"===i)throw new Error("Circular reference detected in isEqual");return"return-true"===i}if(o||(o=new WeakSet,r.set(e,o)),o.add(t),e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.source===t.source&&e.flags===t.flags;const s=Array.isArray(e),a=Array.isArray(t);if(s&&a){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!n(e[o],t[o],r,i))return!1;return!0}if(s!==a)return!1;if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if(e.byteLength!==t.byteLength)return!1;const n=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0}if(e instanceof ArrayBuffer&&t instanceof ArrayBuffer){if(e.byteLength!==t.byteLength)return!1;const n=new Uint8Array(e),r=new Uint8Array(t);for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0}const l=Object.keys(e);if(l.length!==Object.keys(t).length)return!1;for(const o of l){if(!(o in t))return!1;{const s=e[o],a=t[o];if(!n(s,a,r,i))return!1}}return!0}},436(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.tryCatchV2=void 0,t.tryCatchV2=e=>{const t=Date.now();try{const n=e();return n instanceof Promise?new Promise(async(e,r)=>{e({...await n.then(e=>({data:e})).catch(e=>({error:e,hasError:!0})),duration:Date.now()-t})}):{data:n,duration:Date.now()-t}}catch(e){return{error:e,hasError:!0,duration:Date.now()-t}}}}},t={};return function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}(806)})());
|
package/dist/replication.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type SyncConfig = {
|
|
|
12
12
|
* If no data on client then will return { c_count: 0 }
|
|
13
13
|
*/
|
|
14
14
|
export type ClientSyncInfo = {
|
|
15
|
+
state: "syncing";
|
|
15
16
|
c_fr?: AnyObject;
|
|
16
17
|
c_lr?: AnyObject;
|
|
17
18
|
/**
|
|
@@ -20,25 +21,31 @@ export type ClientSyncInfo = {
|
|
|
20
21
|
c_count: number;
|
|
21
22
|
};
|
|
22
23
|
export type onUpdatesParams = {
|
|
24
|
+
state: "error";
|
|
23
25
|
err?: AnyObject;
|
|
24
26
|
} | {
|
|
27
|
+
state: "synced";
|
|
25
28
|
/**
|
|
26
29
|
* TRUE after server had sent/pulled all data and both databases are in sync now.
|
|
27
30
|
* Client will notify listeners with all data items
|
|
28
31
|
*/
|
|
29
32
|
isSynced: boolean;
|
|
30
33
|
} | {
|
|
34
|
+
state: "syncing";
|
|
31
35
|
/**
|
|
32
36
|
* Ordered data
|
|
33
37
|
*/
|
|
34
38
|
data: AnyObject[];
|
|
35
39
|
};
|
|
36
40
|
export type ClientExpressData = Required<ClientSyncInfo> & {
|
|
41
|
+
state: "syncing-data";
|
|
37
42
|
data: AnyObject[];
|
|
38
43
|
};
|
|
39
44
|
export type ClientSyncPullResponse = {
|
|
45
|
+
success: true;
|
|
40
46
|
data: AnyObject[];
|
|
41
47
|
} | {
|
|
48
|
+
success: false;
|
|
42
49
|
err: AnyObject;
|
|
43
50
|
};
|
|
44
51
|
/**
|
|
@@ -70,18 +77,18 @@ export type ClientSyncHandles = {
|
|
|
70
77
|
* Used by client to notify server that data has changed (and send express data if necessary)
|
|
71
78
|
* Also used by server to request client ClientSyncInfo
|
|
72
79
|
*/
|
|
73
|
-
onSyncRequest: (params: SyncBatchParams) =>
|
|
80
|
+
onSyncRequest: (params: SyncBatchParams) => MaybePromise<ClientSyncInfo | ClientExpressData>;
|
|
74
81
|
/**
|
|
75
82
|
* Used to respond to server with the requested data
|
|
76
83
|
* @description: server will send { onPullRequest: { from_synced, limit, ...etc } }
|
|
77
84
|
*/
|
|
78
|
-
onPullRequest: (params: SyncBatchParams) =>
|
|
85
|
+
onPullRequest: (params: SyncBatchParams) => MaybePromise<ClientSyncPullResponse>;
|
|
79
86
|
/**
|
|
80
87
|
* Used to set the data sent by server.
|
|
81
88
|
* Must acknowledge so server can send next batch if necessary
|
|
82
89
|
* @description: server will send { onUpdates: { data } }
|
|
83
90
|
*/
|
|
84
|
-
onUpdates: (params: onUpdatesParams) =>
|
|
91
|
+
onUpdates: (params: onUpdatesParams) => MaybePromise<true>;
|
|
85
92
|
};
|
|
86
93
|
export declare const getSyncChannelName: ({ tableName, filter, select, }: {
|
|
87
94
|
tableName: string;
|
|
@@ -129,6 +136,8 @@ export declare namespace ReplicationProtocol {
|
|
|
129
136
|
};
|
|
130
137
|
};
|
|
131
138
|
};
|
|
139
|
+
export type CreateSchemaRequest = JSONB.GetType<typeof CreateSchema.request>;
|
|
140
|
+
export type CreateSchemaResponse = JSONB.GetType<typeof CreateSchema.response>;
|
|
132
141
|
export const ServerSyncRequest: {
|
|
133
142
|
readonly name: "ServerSyncRequest";
|
|
134
143
|
readonly source: "server";
|
|
@@ -245,51 +254,11 @@ export declare namespace ReplicationProtocol {
|
|
|
245
254
|
}];
|
|
246
255
|
};
|
|
247
256
|
readonly response: {
|
|
248
|
-
readonly
|
|
249
|
-
readonly
|
|
250
|
-
readonly enum: readonly [
|
|
251
|
-
};
|
|
252
|
-
readonly c_fr: {
|
|
253
|
-
readonly optional: true;
|
|
254
|
-
readonly record: {
|
|
255
|
-
readonly values: "unknown";
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
readonly c_lr: {
|
|
259
|
-
readonly optional: true;
|
|
260
|
-
readonly record: {
|
|
261
|
-
readonly values: "unknown";
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
|
-
readonly c_count: "number";
|
|
265
|
-
}, {
|
|
266
|
-
readonly state: {
|
|
267
|
-
readonly enum: readonly ["syncing-data"];
|
|
268
|
-
};
|
|
269
|
-
readonly c_fr: {
|
|
270
|
-
readonly record: {
|
|
271
|
-
readonly values: "unknown";
|
|
272
|
-
};
|
|
273
|
-
};
|
|
274
|
-
readonly c_lr: {
|
|
275
|
-
readonly record: {
|
|
276
|
-
readonly values: "unknown";
|
|
277
|
-
};
|
|
278
|
-
};
|
|
279
|
-
readonly c_count: "number";
|
|
280
|
-
readonly data: {
|
|
281
|
-
readonly arrayOf: {
|
|
282
|
-
readonly record: {
|
|
283
|
-
readonly values: "unknown";
|
|
284
|
-
};
|
|
285
|
-
};
|
|
286
|
-
};
|
|
287
|
-
}, {
|
|
288
|
-
readonly state: {
|
|
289
|
-
readonly enum: readonly ["error"];
|
|
257
|
+
readonly type: {
|
|
258
|
+
readonly ok: {
|
|
259
|
+
readonly enum: readonly [true];
|
|
290
260
|
};
|
|
291
|
-
|
|
292
|
-
}];
|
|
261
|
+
};
|
|
293
262
|
};
|
|
294
263
|
};
|
|
295
264
|
export const PullRequest: {
|
|
@@ -426,51 +395,11 @@ export declare namespace ReplicationProtocol {
|
|
|
426
395
|
}];
|
|
427
396
|
};
|
|
428
397
|
readonly response: {
|
|
429
|
-
readonly
|
|
430
|
-
readonly
|
|
431
|
-
readonly enum: readonly [
|
|
432
|
-
};
|
|
433
|
-
readonly c_fr: {
|
|
434
|
-
readonly optional: true;
|
|
435
|
-
readonly record: {
|
|
436
|
-
readonly values: "unknown";
|
|
437
|
-
};
|
|
438
|
-
};
|
|
439
|
-
readonly c_lr: {
|
|
440
|
-
readonly optional: true;
|
|
441
|
-
readonly record: {
|
|
442
|
-
readonly values: "unknown";
|
|
443
|
-
};
|
|
444
|
-
};
|
|
445
|
-
readonly c_count: "number";
|
|
446
|
-
}, {
|
|
447
|
-
readonly state: {
|
|
448
|
-
readonly enum: readonly ["syncing-data"];
|
|
449
|
-
};
|
|
450
|
-
readonly c_fr: {
|
|
451
|
-
readonly record: {
|
|
452
|
-
readonly values: "unknown";
|
|
453
|
-
};
|
|
454
|
-
};
|
|
455
|
-
readonly c_lr: {
|
|
456
|
-
readonly record: {
|
|
457
|
-
readonly values: "unknown";
|
|
458
|
-
};
|
|
459
|
-
};
|
|
460
|
-
readonly c_count: "number";
|
|
461
|
-
readonly data: {
|
|
462
|
-
readonly arrayOf: {
|
|
463
|
-
readonly record: {
|
|
464
|
-
readonly values: "unknown";
|
|
465
|
-
};
|
|
466
|
-
};
|
|
467
|
-
};
|
|
468
|
-
}, {
|
|
469
|
-
readonly state: {
|
|
470
|
-
readonly enum: readonly ["error"];
|
|
398
|
+
readonly type: {
|
|
399
|
+
readonly ok: {
|
|
400
|
+
readonly enum: readonly [true];
|
|
471
401
|
};
|
|
472
|
-
|
|
473
|
-
}];
|
|
402
|
+
};
|
|
474
403
|
};
|
|
475
404
|
};
|
|
476
405
|
readonly ServerSyncRequest: {
|
|
@@ -632,11 +561,19 @@ export declare namespace ReplicationProtocol {
|
|
|
632
561
|
};
|
|
633
562
|
};
|
|
634
563
|
type SchemasType = typeof Schemas;
|
|
635
|
-
|
|
564
|
+
type IncomingHandlers<Side extends RequestBase["source"]> = {
|
|
565
|
+
[K in keyof SchemasType as SchemasType[K]["source"] extends Side ? never : K]: (params: JSONB.GetType<SchemasType[K]["request"]>) => Promise<JSONB.GetType<SchemasType[K]["response"]>>;
|
|
566
|
+
};
|
|
567
|
+
type OutgoingHandlers<Side extends RequestBase["source"]> = {
|
|
568
|
+
[K in keyof SchemasType as SchemasType[K]["source"] extends Side ? K : never]: (params: JSONB.GetType<SchemasType[K]["request"]>) => Promise<JSONB.GetType<SchemasType[K]["response"]>>;
|
|
569
|
+
};
|
|
570
|
+
const getHandlers: <Side extends RequestBase["source"]>(channelName: string, socket: {
|
|
636
571
|
on: (channelName: string, request: (data: unknown, cb: SocketCallback) => MaybePromise<void>) => void;
|
|
637
572
|
emit: (channelName: string, request: unknown, response: (response: unknown) => MaybePromise<void>) => void;
|
|
638
573
|
removeAllListeners: (channelName: string) => void;
|
|
639
|
-
}, side: Side, onResponse:
|
|
574
|
+
}, side: Side, onResponse: IncomingHandlers<Side>) => OutgoingHandlers<Side>;
|
|
575
|
+
export const getServerHandlers: (channelName: string, socket: Parameters<typeof getHandlers>[1], onResponse: IncomingHandlers<"server">) => OutgoingHandlers<"server">;
|
|
576
|
+
export const getClientHandlers: (channelName: string, socket: Parameters<typeof getHandlers>[1], onResponse: IncomingHandlers<"client">) => OutgoingHandlers<"client">;
|
|
640
577
|
export {};
|
|
641
578
|
}
|
|
642
579
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replication.d.ts","sourceRoot":"","sources":["../lib/replication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EASL,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,YAAY,EAClB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,CAA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AAC,CAAC,KAC7C,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;KACxD,CAAC;IAEF,MAAM,WAAW,GAAI,IAAI,SAAS,WAAW,CAAC,QAAQ,CAAC,EACrD,aAAa,MAAM,EACnB,QAAQ;QACN,EAAE,EAAE,CACF,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,cAAc,KAAK,YAAY,CAAC,IAAI,CAAC,KAC/D,IAAI,CAAC;QACV,IAAI,EAAE,CACJ,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,YAAY,CAAC,IAAI,CAAC,KAChD,IAAI,CAAC;QACV,kBAAkB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;KACnD,EACD,MAAM,IAAI,EACV,YAAY,gBAAgB,CAAC,IAAI,CAAC,KACjC,gBAAgB,CAAC,IAAI,CA4EvB,CAAC;IAEF,MAAM,CAAC,MAAM,iBAAiB,GAC5B,aAAa,MAAM,EACnB,QAAQ,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,EACzC,YAAY,gBAAgB,CAAC,QAAQ,CAAC,+BACmB,CAAC;IAE5D,MAAM,CAAC,MAAM,iBAAiB,GAC5B,aAAa,MAAM,EACnB,QAAQ,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,EACzC,YAAY,gBAAgB,CAAC,QAAQ,CAAC,+BACmB,CAAC;;CAC7D"}
|
package/dist/replication.js
CHANGED
|
@@ -81,7 +81,9 @@ var ReplicationProtocol;
|
|
|
81
81
|
request: {
|
|
82
82
|
oneOfType: [ClientSyncInfoSchema, ClientExpressDataSchema],
|
|
83
83
|
},
|
|
84
|
-
response:
|
|
84
|
+
response: {
|
|
85
|
+
type: { ok: { enum: [true] } },
|
|
86
|
+
},
|
|
85
87
|
};
|
|
86
88
|
ReplicationProtocol.PullRequest = {
|
|
87
89
|
name: "PullRequest",
|
|
@@ -140,7 +142,7 @@ var ReplicationProtocol;
|
|
|
140
142
|
};
|
|
141
143
|
const Schemas = { ClientSyncRequest: ReplicationProtocol.ClientSyncRequest, ServerSyncRequest: ReplicationProtocol.ServerSyncRequest, PullRequest: ReplicationProtocol.PullRequest, UpdateRequest: ReplicationProtocol.UpdateRequest };
|
|
142
144
|
const SchemasList = Object.values(Schemas);
|
|
143
|
-
|
|
145
|
+
const getHandlers = (channelName, socket, side, onResponse) => {
|
|
144
146
|
socket.removeAllListeners(channelName);
|
|
145
147
|
socket.on(channelName, async (requestRaw, cb) => {
|
|
146
148
|
const { type, request } = (0, index_1.isObject)(requestRaw) ? requestRaw : {};
|
|
@@ -204,5 +206,7 @@ var ReplicationProtocol;
|
|
|
204
206
|
.filter(index_1.isDefined));
|
|
205
207
|
return outgoingSchemas;
|
|
206
208
|
};
|
|
209
|
+
ReplicationProtocol.getServerHandlers = (channelName, socket, onResponse) => getHandlers(channelName, socket, "server", onResponse);
|
|
210
|
+
ReplicationProtocol.getClientHandlers = (channelName, socket, onResponse) => getHandlers(channelName, socket, "client", onResponse);
|
|
207
211
|
})(ReplicationProtocol || (exports.ReplicationProtocol = ReplicationProtocol = {}));
|
|
208
212
|
//# sourceMappingURL=replication.js.map
|
package/dist/replication.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replication.js","sourceRoot":"","sources":["../lib/replication.ts"],"names":[],"mappings":";;;AACA,mCAYiB;
|
|
1
|
+
{"version":3,"file":"replication.js","sourceRoot":"","sources":["../lib/replication.ts"],"names":[],"mappings":";;;AACA,mCAYiB;AA6GV,MAAM,kBAAkB,GAAG,CAAC,EACjC,SAAS,EACT,MAAM,GAAG,EAAE,EACX,MAAM,GAAG,GAAG,GAKb,EAAE,EAAE,CACH;IACE,sBAAc;IACd,SAAS;IAC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26,6 +26,7 @@ export type SyncConfig = {
|
|
|
26
26
|
* If no data on client then will return { c_count: 0 }
|
|
27
27
|
*/
|
|
28
28
|
export type ClientSyncInfo = {
|
|
29
|
+
state: "syncing";
|
|
29
30
|
c_fr?: AnyObject;
|
|
30
31
|
c_lr?: AnyObject;
|
|
31
32
|
/**
|
|
@@ -36,9 +37,11 @@ export type ClientSyncInfo = {
|
|
|
36
37
|
|
|
37
38
|
export type onUpdatesParams =
|
|
38
39
|
| {
|
|
40
|
+
state: "error";
|
|
39
41
|
err?: AnyObject;
|
|
40
42
|
}
|
|
41
43
|
| {
|
|
44
|
+
state: "synced";
|
|
42
45
|
/**
|
|
43
46
|
* TRUE after server had sent/pulled all data and both databases are in sync now.
|
|
44
47
|
* Client will notify listeners with all data items
|
|
@@ -46,6 +49,7 @@ export type onUpdatesParams =
|
|
|
46
49
|
isSynced: boolean;
|
|
47
50
|
}
|
|
48
51
|
| {
|
|
52
|
+
state: "syncing";
|
|
49
53
|
/**
|
|
50
54
|
* Ordered data
|
|
51
55
|
*/
|
|
@@ -53,14 +57,17 @@ export type onUpdatesParams =
|
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
export type ClientExpressData = Required<ClientSyncInfo> & {
|
|
60
|
+
state: "syncing-data";
|
|
56
61
|
data: AnyObject[];
|
|
57
62
|
};
|
|
58
63
|
|
|
59
64
|
export type ClientSyncPullResponse =
|
|
60
65
|
| {
|
|
66
|
+
success: true;
|
|
61
67
|
data: AnyObject[];
|
|
62
68
|
}
|
|
63
69
|
| {
|
|
70
|
+
success: false;
|
|
64
71
|
err: AnyObject;
|
|
65
72
|
};
|
|
66
73
|
|
|
@@ -97,24 +104,20 @@ export type ClientSyncHandles = {
|
|
|
97
104
|
* Used by client to notify server that data has changed (and send express data if necessary)
|
|
98
105
|
* Also used by server to request client ClientSyncInfo
|
|
99
106
|
*/
|
|
100
|
-
onSyncRequest: (
|
|
101
|
-
params: SyncBatchParams,
|
|
102
|
-
) => ClientSyncInfo | ClientExpressData | Promise<ClientSyncInfo | ClientExpressData>;
|
|
107
|
+
onSyncRequest: (params: SyncBatchParams) => MaybePromise<ClientSyncInfo | ClientExpressData>;
|
|
103
108
|
|
|
104
109
|
/**
|
|
105
110
|
* Used to respond to server with the requested data
|
|
106
111
|
* @description: server will send { onPullRequest: { from_synced, limit, ...etc } }
|
|
107
112
|
*/
|
|
108
|
-
onPullRequest: (
|
|
109
|
-
params: SyncBatchParams,
|
|
110
|
-
) => ClientSyncPullResponse | Promise<ClientSyncPullResponse>;
|
|
113
|
+
onPullRequest: (params: SyncBatchParams) => MaybePromise<ClientSyncPullResponse>;
|
|
111
114
|
|
|
112
115
|
/**
|
|
113
116
|
* Used to set the data sent by server.
|
|
114
117
|
* Must acknowledge so server can send next batch if necessary
|
|
115
118
|
* @description: server will send { onUpdates: { data } }
|
|
116
119
|
*/
|
|
117
|
-
onUpdates: (params: onUpdatesParams) =>
|
|
120
|
+
onUpdates: (params: onUpdatesParams) => MaybePromise<true>;
|
|
118
121
|
};
|
|
119
122
|
|
|
120
123
|
export const getSyncChannelName = ({
|
|
@@ -169,6 +172,9 @@ export namespace ReplicationProtocol {
|
|
|
169
172
|
},
|
|
170
173
|
} as const satisfies RequestBase;
|
|
171
174
|
|
|
175
|
+
export type CreateSchemaRequest = JSONB.GetType<typeof CreateSchema.request>;
|
|
176
|
+
export type CreateSchemaResponse = JSONB.GetType<typeof CreateSchema.response>;
|
|
177
|
+
|
|
172
178
|
const ClientSyncInfoSchema = {
|
|
173
179
|
state: { enum: ["syncing"] },
|
|
174
180
|
c_fr: { optional: true, record: { values: "unknown" } },
|
|
@@ -216,7 +222,9 @@ export namespace ReplicationProtocol {
|
|
|
216
222
|
request: {
|
|
217
223
|
oneOfType: [ClientSyncInfoSchema, ClientExpressDataSchema],
|
|
218
224
|
},
|
|
219
|
-
response:
|
|
225
|
+
response: {
|
|
226
|
+
type: { ok: { enum: [true] } },
|
|
227
|
+
},
|
|
220
228
|
} as const satisfies RequestBase;
|
|
221
229
|
|
|
222
230
|
export const PullRequest = {
|
|
@@ -280,7 +288,19 @@ export namespace ReplicationProtocol {
|
|
|
280
288
|
type SchemasType = typeof Schemas;
|
|
281
289
|
const SchemasList = Object.values(Schemas);
|
|
282
290
|
|
|
283
|
-
|
|
291
|
+
type IncomingHandlers<Side extends RequestBase["source"]> = {
|
|
292
|
+
[K in keyof SchemasType as SchemasType[K]["source"] extends Side ? never : K]: (
|
|
293
|
+
params: JSONB.GetType<SchemasType[K]["request"]>,
|
|
294
|
+
) => Promise<JSONB.GetType<SchemasType[K]["response"]>>;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
type OutgoingHandlers<Side extends RequestBase["source"]> = {
|
|
298
|
+
[K in keyof SchemasType as SchemasType[K]["source"] extends Side ? K : never]: (
|
|
299
|
+
params: JSONB.GetType<SchemasType[K]["request"]>,
|
|
300
|
+
) => Promise<JSONB.GetType<SchemasType[K]["response"]>>;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const getHandlers = <Side extends RequestBase["source"]>(
|
|
284
304
|
channelName: string,
|
|
285
305
|
socket: {
|
|
286
306
|
on: (
|
|
@@ -295,16 +315,8 @@ export namespace ReplicationProtocol {
|
|
|
295
315
|
removeAllListeners: (channelName: string) => void;
|
|
296
316
|
},
|
|
297
317
|
side: Side,
|
|
298
|
-
onResponse:
|
|
299
|
-
|
|
300
|
-
params: JSONB.GetType<SchemasType[K]["request"]>,
|
|
301
|
-
) => Promise<JSONB.GetType<SchemasType[K]["response"]>>;
|
|
302
|
-
},
|
|
303
|
-
): {
|
|
304
|
-
[K in keyof SchemasType as SchemasType[K]["source"] extends Side ? K : never]: (
|
|
305
|
-
params: JSONB.GetType<SchemasType[K]["request"]>,
|
|
306
|
-
) => Promise<JSONB.GetType<SchemasType[K]["response"]>>;
|
|
307
|
-
} => {
|
|
318
|
+
onResponse: IncomingHandlers<Side>,
|
|
319
|
+
): OutgoingHandlers<Side> => {
|
|
308
320
|
socket.removeAllListeners(channelName);
|
|
309
321
|
socket.on(channelName, async (requestRaw, cb) => {
|
|
310
322
|
const { type, request } = isObject(requestRaw) ? requestRaw : {};
|
|
@@ -379,6 +391,18 @@ export namespace ReplicationProtocol {
|
|
|
379
391
|
.filter(isDefined),
|
|
380
392
|
);
|
|
381
393
|
|
|
382
|
-
return outgoingSchemas as
|
|
394
|
+
return outgoingSchemas as OutgoingHandlers<Side>;
|
|
383
395
|
};
|
|
396
|
+
|
|
397
|
+
export const getServerHandlers = (
|
|
398
|
+
channelName: string,
|
|
399
|
+
socket: Parameters<typeof getHandlers>[1],
|
|
400
|
+
onResponse: IncomingHandlers<"server">,
|
|
401
|
+
) => getHandlers(channelName, socket, "server", onResponse);
|
|
402
|
+
|
|
403
|
+
export const getClientHandlers = (
|
|
404
|
+
channelName: string,
|
|
405
|
+
socket: Parameters<typeof getHandlers>[1],
|
|
406
|
+
onResponse: IncomingHandlers<"client">,
|
|
407
|
+
) => getHandlers(channelName, socket, "client", onResponse);
|
|
384
408
|
}
|