prostgles-types 4.0.274 → 4.0.277

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.
Files changed (26) hide show
  1. package/dist/JSONBSchemaValidation/JSONBSchema.d.ts +82 -63
  2. package/dist/JSONBSchemaValidation/JSONBSchema.d.ts.map +1 -1
  3. package/dist/JSONBSchemaValidation/JSONBSchema.js +1 -0
  4. package/dist/JSONBSchemaValidation/JSONBSchema.js.map +1 -1
  5. package/dist/JSONBSchemaValidation/JSONBSchemaValidation.d.ts +14 -0
  6. package/dist/JSONBSchemaValidation/JSONBSchemaValidation.d.ts.map +1 -1
  7. package/dist/JSONBSchemaValidation/JSONBSchemaValidation.js +124 -14
  8. package/dist/JSONBSchemaValidation/JSONBSchemaValidation.js.map +1 -1
  9. package/dist/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.d.ts.map +1 -1
  10. package/dist/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.js +5 -4
  11. package/dist/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.js.map +1 -1
  12. package/dist/JSONBSchemaValidation/getJSONBSchemaTSTypes.d.ts.map +1 -1
  13. package/dist/JSONBSchemaValidation/getJSONBSchemaTSTypes.js +21 -40
  14. package/dist/JSONBSchemaValidation/getJSONBSchemaTSTypes.js.map +1 -1
  15. package/dist/index.d.ts +7 -7
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/index_umd.js +1 -1
  20. package/lib/JSONBSchemaValidation/JSONBSchema.ts +102 -79
  21. package/lib/JSONBSchemaValidation/JSONBSchemaValidation.ts +163 -12
  22. package/lib/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.ts +4 -4
  23. package/lib/JSONBSchemaValidation/getJSONBSchemaTSTypes.ts +29 -44
  24. package/lib/index.ts +7 -14
  25. package/package.json +3 -2
  26. package/scripts/check-type-instantiations.mjs +40 -0
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.tuple){const t=d.tuple;if(!Array.isArray(e))return f+`[${t.map(e=>u(e)).join(", ")}]`;if(e.length!==t.length)return`${s.length?s.join("."):"value"} is of invalid tuple length. Expecting ${t.length} elements but got ${e.length}`;for(let n=0;n<t.length;n++){const r=c(e[n],t[n],[...s,`${n}`],p);if(void 0!==r)return r}return}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,tuple:m,...g}="string"==typeof e?{type:e}:e;let h={};const b={...(g.enum||g.allowedValues?.length&&("string"!=typeof s||!s.endsWith("[]")))&&{enum:g.allowedValues?.slice(0)??g.enum.slice(0)},...!!c&&{description:c},...!!d&&{title:d}};if(g.enum?.length){const e=typeof g.enum[0];b.type="number"===e?"number":"boolean"===e?"boolean":"string"}if("string"==typeof s||a||l){if(s&&"string"!=typeof s)throw"Not expected";h=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,...g.allowedValues&&{enum:g.allowedValues.slice(0)}}}:{type:o(s)?.type}}else if((0,r.isObject)(s))h={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(m)h={type:"array",items:m.map(e=>(0,t.getJSONSchemaObject)(e)),additionalItems:!1,minItems:m.length,maxItems:m.length};else if(p||f){const e=p||f.map(e=>({type:e}));h={oneOf:e.map(e=>(0,t.getJSONSchemaObject)(e))}}else y&&(h={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"};h.oneOf?h.oneOf.push(e):h.enum&&!h.enum.includes(null)?h.enum.push(null):h={oneOf:[h,e]}}return{...n?{$id:n?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...b,...h}}},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.tuple)return`${p}[${u.tuple.map(n=>(0,t.getJSONBTSTypes)(e,n,!0,void 0,c+1)).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.forEach(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=>String(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.ABORTABLE_METHODS=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_bytes=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","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"],t._PG_bytes=["bytea"];const a={"ArrayBuffer | Uint8Array":t._PG_bytes,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),t.ABORTABLE_METHODS=["find","findOne","count","size"]},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"}}}},i={from_synced:{oneOf:["string","number",{enum:[void 0]}]},to_synced:{oneOf:["string","number",{enum:[void 0]}]}};e.ServerSyncRequest={name:"ServerSyncRequest",source:"server",request:{type:{...i,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:{oneOfType:[{success:{enum:[!0]}},{success:{enum:[!1]},err:"unknown"}]}},e.PullRequest={name:"PullRequest",source:"server",request:{type:{...i,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 o={ClientSyncRequest:e.ClientSyncRequest,ServerSyncRequest:e.ServerSyncRequest,PullRequest:e.PullRequest,UpdateRequest:e.UpdateRequest},s=Object.values(o),a=(e,t,n,i)=>(t.removeAllListeners(e),t.on(e,async(e,t)=>{const{type:o,request:a}=(0,r.isObject)(e)?e:{};if("string"!=typeof o||!a)return void t("Unexpected data");const l=s.find(e=>e.name===o&&e.source!==n);if(!l)return void t("Invalid data.type");if(l.source===n)return void t("Invalid schema.source");if("server"===n){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(await(0,r.withTimeout)(Promise.resolve(i[c](a)),1e4))}catch(e){t((0,r.getSerialisableError)(e))}}),(0,r.fromEntries)((0,r.getEntries)(o).map(([i,o])=>{if(o.source===n)return[i,i=>(0,r.createPromiseWithTimeout)((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 for "+o.name,t.error,e),void a(t.error)}s(e)})},1e4)]}).filter(r.isDefined)));e.getServerHandlers=(e,t,n)=>a(e,t,"server",n),e.getClientHandlers=(e,t,n)=>a(e,t,"client",n)}(i||(t.ReplicationProtocol=i={}))},472(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.fromEntries=t.getEntries=t.createPromiseWithTimeout=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.createPromiseWithTimeout=(e,t)=>{const n=new Promise((e,n)=>setTimeout(()=>n(new Error(`Timed out after ${t}ms`)),t)),r=new Promise(e);return Promise.race([r,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}}}}};const t={};return function n(r){const i=t[r];if(void 0!==i)return i.exports;const 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,Uint8Array: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.getJSONBSchemaValidationErrorAsync=t.getJSONBSchemaValidationError=t.getJSONBObjectSchemaValidationError=t.getFieldTypeObj=void 0;const r=n(472),i=n(441),o=n(704);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,Uint8Array:s,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,f)=>{const d=`${s.join(".")} is of invalid type. Expecting ${u(n).replaceAll("\n","")}`,y=(0,t.getFieldTypeObj)(n),{type:m,allowedValues:g,nullable:h,optional:b}=y;if(h&&null===e)return;if(b&&void 0===e)return;if(g){if("string"!=typeof m)throw new Error("allowedValues is only supported for primitive types");const t=m.endsWith("[]"),n=t&&Array.isArray(e)?e:[e],i=g.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(m){if((0,r.isObject)(m)){if(!(0,r.isObject)(e))return d;for(const t of(0,o.safeGetKeys)(m)){const n=(0,o.safeGetProperty)(m,t);if(!((0,r.isObject)(n)&&n.optional||(0,o.safeHasOwn)(e,t)))return`${[...s,t].join(".")} is missing but required`;const i=c((0,o.safeGetProperty)(e,t),n,[...s,t],p,f);if(void 0!==i)return i}if(!p?.allowExtraProperties){const t=(0,o.safeGetKeys)(e),n=(0,o.safeGetKeys)(m),r=t.filter(e=>!n.includes(e));if(r.length)return`${s.join(".")} has extra properties: ${r.join(", ")}`}return}if(m.includes("Lookup")){if(!f)throw new Error("Lookup types are not supported for validation");const t=m.endsWith("[]");if(t!==Array.isArray(e))return d;const n=m.replace("[]","");return(t?e:[e]).every(e=>"RowLookup"===n?(0,r.isObject)(e):"ValueLookup"===n?"function"!=typeof e&&"symbol"!=typeof e:"TableLookup"===n?"string"==typeof e:(0,r.isObject)(e)&&"string"==typeof(0,o.safeGetProperty)(e,"table")&&"string"==typeof(0,o.safeGetProperty)(e,"column")&&(0,o.safeGetKeys)(e).every(e=>"table"===e||"column"===e))?void f.push({schema:y,value:e,path:s}):d}const{validator:t}=((e,t)=>{const n=(e=>{if("string"==typeof e&&e.endsWith("[]")){const t=e.slice(0,-2);if(!(0,i.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}})(m,y);return t(e,y)?void 0:d}if(y.tuple){const t=y.tuple;if(!Array.isArray(e))return d+`[${t.map(e=>u(e)).join(", ")}]`;if(e.length!==t.length)return`${s.length?s.join("."):"value"} is of invalid tuple length. Expecting ${t.length} elements but got ${e.length}`;for(let n=0;n<t.length;n++){const r=c(e[n],t[n],[...s,`${n}`],p,f);if(void 0!==r)return r}return}if(y.enum){const t=[];return y.nullable&&t.push(null),y.optional&&t.push(void 0),y.enum.includes(e)?void 0:d}const O=y.arrayOf??(y.arrayOfType?{type:y.arrayOfType}:void 0);if(O){if(!Array.isArray(e))return d+" an array";const t=e.map((e,t)=>c(e,O,[...s,`${t}`],p,f)).filter(r.isDefined)[0];return void 0!==t?`${d}. Error at index ${s.length>0?s.join(".")+".":""}\n\n${t}`:void 0}const v=y.oneOf??y.oneOfType?.map(e=>({type:e}));if(v){if(!v.length)return d+"to not be empty";let t;if(v.find(n=>{const r=f?.length,i=c(e,n,s,p,f);return void 0!==i&&void 0!==r&&(f.length=r),t??(t=i),void 0===i}))return;return d}if(y.record){const{keysEnum:t,partial:n,values:i}=y.record;if(!(0,r.isObject)(e))return d+"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`${d} to have key ${l}`;const u=t&&a.filter(e=>!t.includes(e));if(u?.length)return`${d} has extra keys: ${u}`;if(i)for(const t of(0,o.safeGetKeys)(e)){const n=(0,o.safeGetProperty)(e,t),r=c(n,i,[...s,t],p,f);if(void 0!==r)return`${r}`}return}return`Could not validate field type. Some logic might be missing: ${JSON.stringify(y)}`},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}};const p=(e,t)=>[...e,...void 0===t?[]:[String(t)]].join(".")||"value",f=(e,t)=>{if(!(0,o.safeHasOwn)(e,t))return;const n=(0,o.safeGetProperty)(e,t);return(0,r.isObject)(n)?n:void 0},d=async(e,t)=>{const{schema:n,path:r}=e,i=n.type.endsWith("[]"),o=i?e.value:[e.value];for(const[e,s]of o.entries()){const o=p(r,i?e:void 0);if("TableLookup"===n.type||"TableLookup[]"===n.type){if(!f(t,s))return`${o} references an unknown table ${JSON.stringify(s)}`;continue}if("ColumnLookup"===n.type||"ColumnLookup[]"===n.type){const e=s;if(n.filter?.table&&e.table!==n.filter.table)return`${o} references a column that does not match the lookup filter`;const r=f(t,e.table);if(!r)return`${o} references an unknown table ${JSON.stringify(e.table)}`;if("function"!=typeof r.getColumns)throw new Error(`Cannot validate ColumnLookup: table ${JSON.stringify(e.table)} does not expose getColumns`);const i=(await r.getColumns()).find(({name:t})=>t===e.column);if(!i||n.filter?.tsDataType&&i.tsDataType!==n.filter.tsDataType||n.filter?.udt_name&&i.udt_name!==n.filter.udt_name)return`${o} references an unknown or disallowed column ${JSON.stringify(`${e.table}.${e.column}`)}`;continue}const a=n,l=f(t,a.table);if(!l)throw new Error(`Cannot validate ${a.type}: table ${JSON.stringify(a.table)} does not expose findOne`);const c="RowLookup"===a.type||"RowLookup[]"===a.type?s:{[a.column]:s},u=a.filter?{$and:[a.filter,c]}:c;if(void 0===await(l?.findOne?.(u)))return`${o} does not reference an existing row in ${JSON.stringify(a.table)}`}};t.getJSONBSchemaValidationErrorAsync=async(e,t,n,r)=>{const i=[],o=c(t,e,void 0,r,i);if(o)return{error:o};for(const e of i){const t=await d(e,n);if(t)return{error:t}}return{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||t.endsWith("Lookup")||"Uint8Array"===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,tuple:m,...g}="string"==typeof e?{type:e}:e;let h={};const b={...(g.enum||g.allowedValues?.length&&("string"!=typeof s||!s.endsWith("[]")))&&{enum:g.allowedValues?.slice(0)??g.enum.slice(0)},...!!c&&{description:c},...!!d&&{title:d}};if(g.enum?.length){const e=typeof g.enum[0];b.type="number"===e?"number":"boolean"===e?"boolean":"string"}if("string"==typeof s||a||l){if(s&&"string"!=typeof s)throw"Not expected";h=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,...g.allowedValues&&{enum:g.allowedValues.slice(0)}}}:{type:o(s)?.type}}else if((0,r.isObject)(s))h={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(m)h={type:"array",items:m.map(e=>(0,t.getJSONSchemaObject)(e)),additionalItems:!1,minItems:m.length,maxItems:m.length};else if(p||f){const e=p||f.map(e=>({type:e}));h={oneOf:e.map(e=>(0,t.getJSONSchemaObject)(e))}}else y&&(h={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"};h.oneOf?h.oneOf.push(e):h.enum&&!h.enum.includes(null)?h.enum.push(null):h={oneOf:[h,e]}}return{...n?{$id:n?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...b,...h}}},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("string"==typeof u.type&&u.type.includes("Lookup"))return((e,t)=>{const n=t.nullable?"null | ":"",i=t.type.endsWith("[]")?"[]":"";if("TableLookup"===t.type||"TableLookup[]"===t.type)return`${n}string${i}`;if("ColumnLookup"===t.type||"ColumnLookup[]"===t.type)return`${n}{ "table": string; "column": string; }${i}`;const o=t,s=e.find(e=>e.name===o.table)?.columns;if("ValueLookup"===t.type||"ValueLookup[]"===t.type){const e=t,o=s?.find(t=>t.name===e.column)?.udt_name;return`${n}${(0,r.postgresToTsType)(o??"text")}${i}`}return`${n}${s?`{ ${s.map(e=>`${JSON.stringify(e.name)}: ${e.is_nullable?"null | ":""} ${(0,r.postgresToTsType)(e.udt_name)}; `).join(" ")} }`:"any"}${i}`})(e,u);if("string"==typeof u.type){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.tuple)return`${p}[${u.tuple.map(n=>(0,t.getJSONBTSTypes)(e,n,!0,void 0,c+1)).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.forEach(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=>String(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.ABORTABLE_METHODS=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_bytes=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","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"],t._PG_bytes=["bytea"];const a={Uint8Array:t._PG_bytes,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),t.ABORTABLE_METHODS=["find","findOne","count","size"]},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"}}}},i={from_synced:{oneOf:["string","number",{enum:[void 0]}]},to_synced:{oneOf:["string","number",{enum:[void 0]}]}};e.ServerSyncRequest={name:"ServerSyncRequest",source:"server",request:{type:{...i,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:{oneOfType:[{success:{enum:[!0]}},{success:{enum:[!1]},err:"unknown"}]}},e.PullRequest={name:"PullRequest",source:"server",request:{type:{...i,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 o={ClientSyncRequest:e.ClientSyncRequest,ServerSyncRequest:e.ServerSyncRequest,PullRequest:e.PullRequest,UpdateRequest:e.UpdateRequest},s=Object.values(o),a=(e,t,n,i)=>(t.removeAllListeners(e),t.on(e,async(e,t)=>{const{type:o,request:a}=(0,r.isObject)(e)?e:{};if("string"!=typeof o||!a)return void t("Unexpected data");const l=s.find(e=>e.name===o&&e.source!==n);if(!l)return void t("Invalid data.type");if(l.source===n)return void t("Invalid schema.source");if("server"===n){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(await(0,r.withTimeout)(Promise.resolve(i[c](a)),1e4))}catch(e){t((0,r.getSerialisableError)(e))}}),(0,r.fromEntries)((0,r.getEntries)(o).map(([i,o])=>{if(o.source===n)return[i,i=>(0,r.createPromiseWithTimeout)((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 for "+o.name,t.error,e),void a(t.error)}s(e)})},1e4)]}).filter(r.isDefined)));e.getServerHandlers=(e,t,n)=>a(e,t,"server",n),e.getClientHandlers=(e,t,n)=>a(e,t,"client",n)}(i||(t.ReplicationProtocol=i={}))},472(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.fromEntries=t.getEntries=t.createPromiseWithTimeout=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.createPromiseWithTimeout=(e,t)=>{const n=new Promise((e,n)=>setTimeout(()=>n(new Error(`Timed out after ${t}ms`)),t)),r=new Promise(e);return Promise.race([r,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}}}}};const t={};return function n(r){const i=t[r];if(void 0!==i)return i.exports;const o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}(806)})());
@@ -11,11 +11,13 @@ export type PrimitiveTypeMap = {
11
11
  boolean: boolean;
12
12
  any: any;
13
13
  unknown: unknown;
14
+ Uint8Array: Uint8Array;
14
15
  Blob: Blob;
15
16
  FileLike: {
16
17
  name: string;
17
18
  type: string;
18
- data: Blob;
19
+ lastModified?: number;
20
+ data: Uint8Array | Blob;
19
21
  };
20
22
  };
21
23
 
@@ -55,6 +57,7 @@ export const PrimitiveTypesObj = {
55
57
  Date: 1,
56
58
  time: 1,
57
59
  timestamp: 1,
60
+ Uint8Array: 1,
58
61
  Blob: 1,
59
62
  FileLike: 1,
60
63
  any: 1,
@@ -85,50 +88,7 @@ export namespace JSONB {
85
88
  title?: string;
86
89
  };
87
90
 
88
- export type Lookup = BaseOptions & {
89
- type?: "Lookup" | "Lookup[]";
90
- lookup:
91
- | {
92
- type:
93
- | "data"
94
- /**
95
- * This is used as edit-mode (to generate lookup of type data)
96
- */
97
- | "data-def";
98
- table: string;
99
- column: string;
100
- filter?: AnyObject;
101
- isArray?: boolean;
102
- isFullRow?: {
103
- /**
104
- * Columns used to display the selected row in the dropdown
105
- */
106
- displayColumns?: string[];
107
- };
108
- /**
109
- * Columns used to search
110
- */
111
- searchColumns?: string[];
112
- /**
113
- * If true then a button will be shown
114
- * in the row card footer to access this action
115
- */
116
- showInRowCard?: {
117
- /**
118
- * Action button text. Defaults to the method name
119
- */
120
- actionLabel?: string;
121
- actionColor?: "danger" | "warn" | "action";
122
- actionStyle?: AnyObject;
123
- actionClass?: string;
124
- };
125
- }
126
- | {
127
- type: "schema";
128
- isArray?: boolean;
129
- object: "column" | "table";
130
- filter?: { table?: string; tsDataType?: string; udt_name?: string };
131
- };
91
+ type LookupBase = BaseOptions & {
132
92
  allowedValues?: undefined;
133
93
  oneOf?: undefined;
134
94
  oneOfType?: undefined;
@@ -139,6 +99,67 @@ export namespace JSONB {
139
99
  record?: undefined;
140
100
  };
141
101
 
102
+ type ShowInRowCardOptions = {
103
+ /**
104
+ * Action button text. Defaults to the method name
105
+ */
106
+ actionLabel?: string;
107
+ actionColor?: "danger" | "warn" | "action";
108
+ actionStyle?: AnyObject;
109
+ actionClass?: string;
110
+ };
111
+
112
+ type DataLookupOptions = {
113
+ table: string;
114
+ filter?: AnyObject;
115
+ /**
116
+ * Columns used to search
117
+ */
118
+ searchColumns?: string[];
119
+ /**
120
+ * If defined then a button will be shown
121
+ * in the row card footer to access this action
122
+ */
123
+ showInRowCard?: ShowInRowCardOptions;
124
+ };
125
+
126
+ type RowLookupOptions = {
127
+ type: "RowLookup" | "RowLookup[]";
128
+ /**
129
+ * Columns used to display the selected row in the dropdown
130
+ */
131
+ displayColumns?: string[];
132
+ };
133
+
134
+ type ValueLookupOptions = {
135
+ type: "ValueLookup" | "ValueLookup[]";
136
+ column: string;
137
+ };
138
+
139
+ type TableLookupOptions = {
140
+ type: "TableLookup" | "TableLookup[]";
141
+ };
142
+
143
+ type ColumnLookupOptions = {
144
+ type: "ColumnLookup" | "ColumnLookup[]";
145
+ filter?: {
146
+ table?: string;
147
+ tsDataType?: string;
148
+ udt_name?: string;
149
+ };
150
+ };
151
+
152
+ export type RowLookup = LookupBase & DataLookupOptions & RowLookupOptions;
153
+ export type ValueLookup = LookupBase & DataLookupOptions & ValueLookupOptions;
154
+ export type TableLookup = LookupBase & TableLookupOptions;
155
+ export type ColumnLookup = LookupBase & ColumnLookupOptions;
156
+ export type Lookup = LookupBase &
157
+ (
158
+ | (DataLookupOptions & (RowLookupOptions | ValueLookupOptions))
159
+ | TableLookupOptions
160
+ | ColumnLookupOptions
161
+ );
162
+
142
163
  export type BasicType = BaseOptions &
143
164
  PrimitiveOptions & {
144
165
  type: DataType;
@@ -254,47 +275,45 @@ export namespace JSONB {
254
275
  };
255
276
 
256
277
  export type FieldTypeObj =
257
- | BasicType
258
- | ObjectType
259
- | EnumType
260
- | TupleType
261
- | OneOf
262
- | ArrayOf
263
- | RecordType
264
- | Lookup;
278
+ BasicType | ObjectType | EnumType | TupleType | OneOf | ArrayOf | RecordType | Lookup;
265
279
 
266
280
  export type FieldType = DataType | FieldTypeObj;
267
281
  type ObjectSchema = Record<string, FieldType>;
268
282
 
269
- type NormalizeField<T extends FieldType | Omit<FieldTypeObj, "optional">> =
270
- T extends DataType ? { type: T } : T;
271
-
272
283
  type AllowedValueFromItem<I> = I extends { value: infer V } ? V : I;
273
284
 
274
285
  type AllowedValuesUnion<A extends readonly any[]> = AllowedValueFromItem<A[number]>;
275
286
 
276
287
  type ApplyAllowedToType<Allowed, TType> =
277
- TType extends readonly any[] ? Allowed[]
278
- : TType extends any[] ? Allowed[]
279
- : Allowed;
288
+ TType extends readonly any[] ? Allowed[] : Allowed;
280
289
 
281
- type GetAllowedValues<T extends FieldTypeObj | Omit<FieldTypeObj, "optional">, TType> =
290
+ type GetAllowedValues<T, TType> =
282
291
  T extends { allowedValues: readonly any[] } ?
283
292
  ApplyAllowedToType<AllowedValuesUnion<T["allowedValues"]>, TType>
284
293
  : TType;
285
294
 
286
295
  type PrimitiveValue<U extends DataType> =
287
- U extends `${infer P}[]` ?
296
+ U extends keyof PrimitiveTypeMap ? PrimitiveTypeMap[U]
297
+ : U extends `${infer P}[]` ?
288
298
  P extends keyof PrimitiveTypeMap ?
289
299
  PrimitiveTypeMap[P][]
290
300
  : never
291
- : U extends keyof PrimitiveTypeMap ? PrimitiveTypeMap[U]
292
301
  : never;
293
302
 
294
- type GetPrimitiveType<
295
- T extends FieldTypeObj | Omit<FieldTypeObj, "optional">,
296
- U extends DataType,
297
- > = GetAllowedValues<T, PrimitiveValue<U>>;
303
+ type GetPrimitiveType<T, U extends DataType> = GetAllowedValues<T, PrimitiveValue<U>>;
304
+
305
+ type LookupType = Lookup["type"];
306
+ type ColumnReference = { table: string; column: string };
307
+ type LookupValue<U extends LookupType> =
308
+ U extends "RowLookup" ? AnyObject
309
+ : U extends "RowLookup[]" ? AnyObject[]
310
+ : U extends "ValueLookup" ? any
311
+ : U extends "ValueLookup[]" ? any[]
312
+ : U extends "TableLookup" ? string
313
+ : U extends "TableLookup[]" ? string[]
314
+ : U extends "ColumnLookup" ? ColumnReference
315
+ : U extends "ColumnLookup[]" ? ColumnReference[]
316
+ : never;
298
317
 
299
318
  type ResolveRecord<R extends RecordType["record"]> = Record<
300
319
  R extends { keysEnum: readonly string[] } ? R["keysEnum"][number] : string,
@@ -307,9 +326,10 @@ export namespace JSONB {
307
326
  type ResolveTuple<T extends readonly FieldType[]> = {
308
327
  -readonly [K in keyof T]: T[K] extends FieldType ? GetType<T[K]> : never;
309
328
  };
310
- type ResolveField<T extends FieldTypeObj | Omit<FieldTypeObj, "optional">> =
329
+ type ResolveField<T> =
311
330
  T extends { type: infer U } ?
312
331
  U extends DataType ? GetPrimitiveType<T, U>
332
+ : U extends LookupType ? LookupValue<U>
313
333
  : U extends ObjectSchema ? GetObjectType<U>
314
334
  : never
315
335
  : T extends { enum: readonly any[] } ? T["enum"][number]
@@ -339,17 +359,13 @@ export namespace JSONB {
339
359
  : never
340
360
  : any;
341
361
 
342
- type GetWNullType<T extends FieldTypeObj | Omit<FieldTypeObj, "optional">> =
362
+ type GetWNullType<T> =
343
363
  T extends { nullable: true } ? null | ResolveField<T> : ResolveField<T>;
344
364
 
345
- export type GetType<T extends FieldType | Omit<FieldTypeObj, "optional">> = GetWNullType<
346
- NormalizeField<T>
347
- >;
365
+ export type GetType<T extends FieldType | Omit<FieldTypeObj, "optional">> =
366
+ T extends DataType ? PrimitiveValue<T> : GetWNullType<T>;
348
367
 
349
- type IsOptional<F extends FieldType> =
350
- F extends DataType ? false
351
- : F extends { optional: true } ? true
352
- : false;
368
+ type IsOptional<F extends FieldType> = F extends { optional: true } ? true : false;
353
369
 
354
370
  type OptionalKeys<S extends ObjectSchema> = {
355
371
  [K in keyof S]-?: IsOptional<S[K]> extends true ? K : never;
@@ -363,12 +379,19 @@ export namespace JSONB {
363
379
  [K in OptionalKeys<S>]?: GetType<S[K]>;
364
380
  };
365
381
 
366
- export type JSONBSchema = Omit<FieldTypeObj, "optional"> & {
367
- defaultValue?: unknown;
382
+ type RootLookupOptions = {
383
+ table?: string;
384
+ filter?: AnyObject;
385
+ searchColumns?: string[];
386
+ showInRowCard?: ShowInRowCardOptions;
387
+ column?: string;
388
+ displayColumns?: string[];
368
389
  };
369
390
 
370
- export type GetSchemaType<S extends JSONBSchema> =
371
- S["nullable"] extends true ? null | GetType<S> : GetType<S>;
391
+ export type JSONBSchema = Omit<FieldTypeObj, "optional"> &
392
+ RootLookupOptions & { defaultValue?: unknown };
393
+
394
+ export type GetSchemaType<S extends JSONBSchema> = GetType<S>;
372
395
 
373
396
  export type GetTypeIfDefined<Schema extends FieldType | undefined> =
374
397
  Schema extends FieldType ? GetType<Schema> : never;