prostgles-types 4.0.248 → 4.0.250

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 CHANGED
@@ -1 +1 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(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 i=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,i.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 i=n(472),r=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,i.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,i.getKeys)(a),c=(e,n,s=[],u)=>{const f=`${s.join(".")} is of invalid type. Expecting ${p(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],r=m.map(e=>(0,i.isObject)(e)?e.value:e);for(const[e,i]of n.entries())if(!r.includes(i))return`${t?`${s.join(".")}[${e}]`:s.join(".")} is of invalid type. Expecting ${r.map(e=>"string"==typeof e?JSON.stringify(e):String(e)).join(" | ")} But got ${JSON.stringify(i)}`}if(y){if((0,i.isObject)(y)){if(!(0,i.isObject)(e))return f;for(const t of(0,r.safeGetKeys)(y)){const n=(0,r.safeGetProperty)(y,t);if(!((0,i.isObject)(n)&&n.optional||(0,r.safeHasOwn)(e,t)))return`${[...s,t].join(".")} is missing but required`;const o=c((0,r.safeGetProperty)(e,t),n,[...s,t],u);if(void 0!==o)return o}if(!u?.allowExtraProperties){const t=(0,r.safeGetKeys)(e),n=(0,r.safeGetKeys)(y),i=t.filter(e=>!n.includes(e));if(i.length)return`${s.join(".")} has extra properties: ${i.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 i=a[e];if(!i)throw new Error(`Unknown field type ${e}`);return{isArray:!1,validator:i}})(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}`],u)).filter(i.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 i=c(e,n,s,u);return t??(t=i),void 0===i}))return;return f}if(d.record){const{keysEnum:t,partial:n,values:o}=d.record;if(!(0,i.isObject)(e))return f+"object";if(n&&(0,i.isEmpty)(e))return;const a=(0,i.getKeys)(e),l=n?void 0:t?.find(e=>!a.includes(e));if(void 0!==l)return`${f} to have key ${l}`;const p=t&&a.filter(e=>!t.includes(e));if(p?.length)return`${f} has extra keys: ${p}`;if(o)for(const t of(0,r.safeGetKeys)(e)){const n=(0,r.safeGetProperty)(e,t),i=c(n,o,[...s,t],u);if(void 0!==i)return`${i}`}return}return`Could not validate field type. Some logic might be missing: ${JSON.stringify(d)}`},p=e=>{const n=(0,t.getFieldTypeObj)(e),{type:r,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 r)c.push(r);else if(r&&(0,i.isObject)(r)){const e=[];Object.entries(r).forEach(([t,n])=>{e.push(`${t}: ${p(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=p(e);c.push(t)}),a){const{keysEnum:e,partial:t,values:n}=a,i=t?"?":"",r=n?p(n):"any";e?c.push(`{ [${e.join(" | ")}]${i}: ${r} }`):c.push(`{ [key: string]${i}: ${r} }`)}return c.join(" | ")};t.getJSONBObjectSchemaValidationError=(e,t,n="input",r=!1,o)=>{if(void 0===t&&!r)return{error:`Expecting ${n} to be defined`};if(!(0,i.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 i=c(t,e,void 0,n);return i?{error:i}:{data:t}},t.validateJSONBObjectAgainstSchema=(e,n,i,r=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,n,i,r);return void 0===o},t.assertJSONBObjectAgainstSchema=(e,n,i,r=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,n,i,r);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,i){return(0,t.getJSONSchemaObject)(i,{id:`${e}.${n}`})};const i=n(472),r=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:p,oneOf:u,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,i.isObject)(s))g={type:"object",required:(0,r.safeGetKeys)(s).filter(e=>{const t=s[e];return"string"==typeof t||!t.optional}),properties:(0,i.getObjectEntries)(s).reduce((e,[n,i])=>({...e,[n]:(0,t.getJSONSchemaObject)(i)}),{})};else if(u||f){const e=u||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(p){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,i="",r){return(0,t.getJSONBTSTypes)(r,{...e,nullable:n.nullable},void 0,i)};const i=n(806),r=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 p=(0,r.getFieldTypeObj)(n),u=p.nullable?"null | ":"";if(p.lookup){const n=p.lookup;if("data-def"===n.type)return`${p.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 r="schema"===n.type;let o=r?"table"===n.object?"string":'{ "table": string; "column": string; }':"";if(!r){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,i.postgresToTsType)(e.udt_name)}; `).join(" ")} }`:"any":(0,i.postgresToTsType)(t?.find(e=>e.name===n.column)?.udt_name??"text")}return`${p.nullable?"null | ":""}${o}${n.isArray?"[]":""}`}if("string"==typeof p.type){if(p.type.toLowerCase().includes("lookup"))throw new Error("getJSONBTSTypes: Lookup type not handled correctly");const e=p.type.replace("integer","number").replace("time","string").replace("timestamp","string").replace("FileLike","{ name: string; type: string; data: Blob; }").replace("Date","string");if(p.allowedValues){const e=p.type.endsWith("[]")?"[]":"";return u+` (${p.allowedValues.map(e=>JSON.stringify((0,i.isObject)(e)?e.value:e)).join(" | ")})${e}`}return u+e}if((0,i.isObject)(p.type)){const n=e=>e.trim().endsWith(";")?e:e.trim()+";",{type:o}=p,l=a?" ":" ";let f=` {${l}`+(0,i.getObjectEntries)(o).map(([i,o])=>{const a=(0,r.getFieldTypeObj)(o),p=s(i)?i:JSON.stringify(i);return`${l}${p}${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("")),u+f}if(p.enum)return u+p.enum.map(e=>o(e)).join(" | ");if(p.oneOf||p.oneOfType){const n=p.oneOf||p.oneOfType.map(e=>({type:e}));return(p.nullable?`\n${l} | null`:"")+n.map(n=>`\n${l} | `+(0,t.getJSONBTSTypes)(e,n,!0,void 0,c+1)).join("")}if(p.arrayOf||p.arrayOfType){const n=p.arrayOf||{type:p.arrayOfType};return`${p.nullable?"null | ":""} ( ${(0,t.getJSONBTSTypes)(e,n,!0,void 0,c+1)} )[]`}if(p.record){const{keysEnum:n,values:i,partial:r}=p.record,s=e=>r?`Partial<Record<${e}>>`:`Record<${e}>`;return`${p.nullable?"null |":""} ${s(`${n?.map(e=>o(e)).join(" | ")??"string"}, ${i?(0,t.getJSONBTSTypes)(e,i,!0,void 0,c+1):"any"}`)}`}throw"Unexpected getSchemaTSTypes: "+JSON.stringify({fieldType:p},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 i=Object.keys(e);for(const r of n)(0,t.safeHasOwn)(e,r)&&!i.includes(r)&&i.push(r);return i}},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 i=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,i.getKeys)(t.JsonbOperands),t.TextFilterKeys=["$ilike","$like","$nilike","$nlike"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.ArrayFilterOperands=["@>","<@","=","$eq","$contains","$containedBy","&&","$overlaps"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"],t.GeomFilter_Funcs=["ST_MakeEnvelope","st_makeenvelope","ST_MakePolygon","st_makepolygon"],t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"],t.ComplexFilterComparisonKeys=[...t.TextFilterKeys,...t.JsonbFilterKeys,...t.CompareFilterKeys,...t.BetweenFilterKeys,...t.CompareInFilterKeys],t.COMPLEX_FILTER_KEY="$filter"},806(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=t.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 i=new Map;return Object.values(t.SQL_COMMAND_TABLE_METHODS).forEach(e=>{e.forEach(e=>{i.set(e,(i.get(e)??0)+1)})}),i.forEach((e,t)=>{n.filter(e=>e===t).length!==e&&i.delete(t)}),Array.from(i.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 i=(e.references??[]).map(e=>{const{ftable:n,fcols:i}=e,r=t.find(e=>e.name===n);if(!r)return;const o=r.columns.filter(e=>i.includes(e.name));return o.length?{ref:e,fcolsInfo:o}:void 0}).filter(o.isDefined),[r,...s]=i??[];if(!s.length)return r?.ref;const[a,...l]=i.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")},r(n(618),t);var l=n(521);Object.defineProperty(t,"CONTENT_TYPE_TO_EXT",{enumerable:!0,get:function(){return l.CONTENT_TYPE_TO_EXT}}),r(n(209),t),r(n(319),t),r(n(699),t),r(n(394),t),r(n(994),t),r(n(897),t),r(n(164),t),r(n(472),t),r(n(778),t)},319(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.leftJoin=t.innerJoin=void 0;const i=n(472),r=(e="$leftJoin")=>(t,n,r,o={})=>({[e]:o.path??t,filter:n,...(0,i.omitKeys)(o,["path","select"]),select:r});t.innerJoin=r("$innerJoin"),t.leftJoin=r("$leftJoin")},666(e,t){function n(e,t){var n=e[0],i=e[1],l=e[2],c=e[3];n=r(n,i,l,c,t[0],7,-680876936),c=r(c,n,i,l,t[1],12,-389564586),l=r(l,c,n,i,t[2],17,606105819),i=r(i,l,c,n,t[3],22,-1044525330),n=r(n,i,l,c,t[4],7,-176418897),c=r(c,n,i,l,t[5],12,1200080426),l=r(l,c,n,i,t[6],17,-1473231341),i=r(i,l,c,n,t[7],22,-45705983),n=r(n,i,l,c,t[8],7,1770035416),c=r(c,n,i,l,t[9],12,-1958414417),l=r(l,c,n,i,t[10],17,-42063),i=r(i,l,c,n,t[11],22,-1990404162),n=r(n,i,l,c,t[12],7,1804603682),c=r(c,n,i,l,t[13],12,-40341101),l=r(l,c,n,i,t[14],17,-1502002290),n=o(n,i=r(i,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=o(c,n,i,l,t[6],9,-1069501632),l=o(l,c,n,i,t[11],14,643717713),i=o(i,l,c,n,t[0],20,-373897302),n=o(n,i,l,c,t[5],5,-701558691),c=o(c,n,i,l,t[10],9,38016083),l=o(l,c,n,i,t[15],14,-660478335),i=o(i,l,c,n,t[4],20,-405537848),n=o(n,i,l,c,t[9],5,568446438),c=o(c,n,i,l,t[14],9,-1019803690),l=o(l,c,n,i,t[3],14,-187363961),i=o(i,l,c,n,t[8],20,1163531501),n=o(n,i,l,c,t[13],5,-1444681467),c=o(c,n,i,l,t[2],9,-51403784),l=o(l,c,n,i,t[7],14,1735328473),n=s(n,i=o(i,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=s(c,n,i,l,t[8],11,-2022574463),l=s(l,c,n,i,t[11],16,1839030562),i=s(i,l,c,n,t[14],23,-35309556),n=s(n,i,l,c,t[1],4,-1530992060),c=s(c,n,i,l,t[4],11,1272893353),l=s(l,c,n,i,t[7],16,-155497632),i=s(i,l,c,n,t[10],23,-1094730640),n=s(n,i,l,c,t[13],4,681279174),c=s(c,n,i,l,t[0],11,-358537222),l=s(l,c,n,i,t[3],16,-722521979),i=s(i,l,c,n,t[6],23,76029189),n=s(n,i,l,c,t[9],4,-640364487),c=s(c,n,i,l,t[12],11,-421815835),l=s(l,c,n,i,t[15],16,530742520),n=a(n,i=s(i,l,c,n,t[2],23,-995338651),l,c,t[0],6,-198630844),c=a(c,n,i,l,t[7],10,1126891415),l=a(l,c,n,i,t[14],15,-1416354905),i=a(i,l,c,n,t[5],21,-57434055),n=a(n,i,l,c,t[12],6,1700485571),c=a(c,n,i,l,t[3],10,-1894986606),l=a(l,c,n,i,t[10],15,-1051523),i=a(i,l,c,n,t[1],21,-2054922799),n=a(n,i,l,c,t[8],6,1873313359),c=a(c,n,i,l,t[15],10,-30611744),l=a(l,c,n,i,t[6],15,-1560198380),i=a(i,l,c,n,t[13],21,1309151649),n=a(n,i,l,c,t[4],6,-145523070),c=a(c,n,i,l,t[11],10,-1120210379),l=a(l,c,n,i,t[2],15,718787259),i=a(i,l,c,n,t[9],21,-343485551),e[0]=f(n,e[0]),e[1]=f(i,e[1]),e[2]=f(l,e[2]),e[3]=f(c,e[3])}function i(e,t,n,i,r,o){return t=f(f(t,e),f(i,o)),f(t<<r|t>>>32-r,n)}function r(e,t,n,r,o,s,a){return i(t&n|~t&r,e,t,o,s,a)}function o(e,t,n,r,o,s,a){return i(t&r|n&~r,e,t,o,s,a)}function s(e,t,n,r,o,s,a){return i(t^n^r,e,t,o,s,a)}function a(e,t,n,r,o,s,a){return i(n^(t|~r),e,t,o,s,a)}function l(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}t.md5=u;var c="0123456789abcdef".split("");function p(e){for(var t="",n=0;n<4;n++)t+=c[e>>8*n+4&15]+c[e>>8*n&15];return t}function u(e){return function(e){for(var t=0;t<e.length;t++)e[t]=p(e[t]);return e.join("")}(function(e){var t,i=e.length,r=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)n(r,l(e.substring(t-64,t)));e=e.substring(t-64);var o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<e.length;t++)o[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(n(r,o),t=0;t<16;t++)o[t]=0;return o[14]=8*i,n(r,o),r}(e))}function f(e,t){return e+t&4294967295}u("hello")},164(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.getSyncChannelName=void 0;const i=n(806);t.getSyncChannelName=({tableName:e,filter:t={},select:n={}})=>[i.CHANNEL_PREFIX,e,"sync",(0,i.stableStringify)(t),"string"==typeof n?n:(0,i.stableStringify)(n)].join(".")},472(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.getProperty=t.getSerialisableError=t.safeStringify=t.extractTypeUtil=t.reverseParsedPath=t.reverseJoinOn=t.tryCatch=t.getObjectEntries=t.isNotEmpty=t.WAL=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=r,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,i="boolean"==typeof t.cycles&&t.cycles,r=t.cmp&&(n=t.cmp,function(e){return function(t,i){var r={key:t,value:e[t]},o={key:i,value:e[i]};return n(r,o)}}),o=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var n,s;if(Array.isArray(t)){for(s="[",n=0;n<t.length;n++)n&&(s+=","),s+=e(t[n])||"null";return s+"]"}if(null===t)return"null";if(-1!==o.indexOf(t)){if(i)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=o.push(t)-1,l=Object.keys(t).sort(r&&r(t));for(s="",n=0;n<l.length;n++){var c=l[n],p=e(t[c]);p&&(s&&(s+=","),s+=JSON.stringify(c)+":"+p)}return o.splice(a,1),"{"+s+"}"}}(e)},t.getTextPatch=function(e,t){if(!(e&&t&&e.trim().length&&t.trim().length))return t;if(e===t)return{from:0,to:0,text:"",md5:(0,i.md5)(t)};function n(n=1){let i=n<1?-1:0,r=!1;for(;!r&&Math.abs(i)<=t.length;){const o=n<1?[i]:[0,i];e.slice(...o)!==t.slice(...o)?r=!0:i+=1*Math.sign(n)}return i}let r=n()-1,o=e.length+n(-1)+1,s=t.length+n(-1)+1;return{from:r,to:o,text:t.slice(r,s),md5:(0,i.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:r,text:o,md5:s}=t;if(null===o||null===e)return o;let a=e.slice(0,n)+o+e.slice(r);if(s&&(0,i.md5)(a)!==s)throw"Patch text error: Could not match md5 hash: (original/result) \n"+e+"\n"+a;return a},t.isEmpty=s,t.get=function(e,t){let n=t,i=e;return e?("string"==typeof n&&(n=n.split(".")),n.reduce((e,t)=>e&&e[t]?e[t]:void 0,i)):e},t.isObject=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},t.isDefined=a,t.getKeys=l;const i=n(666);function r(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 i={};return t.forEach(t=>{n&&void 0===e[t]||(i[t]=e[t])}),i}return e},t.WAL=class{constructor(e){if(this.changed={},this.sending={},this.sentHistory={},this.callbacks=[],this.sort=(e,t)=>{const{orderBy:n}=this.options;return n&&e&&t&&n.map(n=>{if(!(n.fieldName in e)||!(n.fieldName in t))throw"Replication error: \n some orderBy fields missing from data";let i=n.asc?e[n.fieldName]:t[n.fieldName],r=n.asc?t[n.fieldName]:e[n.fieldName],o=+i-+r,s=i<r?-1:i==r?0:1;return"number"===n.tsDataType&&Number.isFinite(o)?o:s}).find(e=>e)||0},this.isInHistory=e=>{if(!e)throw"Provide item";const t=e[this.options.synced_field];if(!Number.isFinite(+t))throw"Provided item Synced field value is missing/invalid ";const n=this.sentHistory[this.getIdStr(e)],i=n?.[this.options.synced_field];if(n){if(!Number.isFinite(+i))throw"Provided historic item Synced field value is missing/invalid";if(+i===+t)return!0}return!1},this.addData=e=>(s(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map(e=>{var t;const{initial:n,current:i,delta:r}={...e};if(!i)throw"Expecting { current: object, initial?: object }";const o=this.getIdStr(i);this.changed??(this.changed={}),(t=this.changed)[o]??(t[o]={initial:n,current:i,delta:r}),this.changed[o].current={...this.changed[o].current,...i},this.changed[o].delta={...this.changed[o].delta,...r}}),this.sendItems()),this.isOnSending=!1,this.isSendingTimeout=void 0,this.willDeleteHistory=void 0,this.sendItems=async()=>{const{DEBUG_MODE:e,onSend:t,onSendEnd:n,batch_size:i,throttle:r,historyAgeSeconds:o=2}=this.options;if(this.isSendingTimeout||this.sending&&!s(this.sending))return;if(!this.changed||s(this.changed))return;let a,l=[],c=[],p={};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}),p[e]={...t.current},delete this.changed[e]}),l=c.map(e=>{let t={};return Object.keys(e.current).map(n=>{const i=e.initial?.[n],r=e.current[n];var o,s;![this.options.synced_field,...this.options.id_fields].includes(n)&&((o=i)===(s=r)||(["number","string","boolean"].includes(typeof o)?o===s:JSON.stringify(o)===JSON.stringify(s)))||(t[n]=r)}),t}),e&&console.log(this.options.id," SENDING lr->",l[l.length-1]),this.isSendingTimeout||(this.isSendingTimeout=setTimeout(()=>{this.isSendingTimeout=void 0,s(this.changed)||this.sendItems()},r)),this.isOnSending=!0;try{await t(l,c),o&&(this.sentHistory={...this.sentHistory,...p},this.willDeleteHistory||(this.willDeleteHistory=setTimeout(()=>{this.willDeleteHistory=void 0,this.sentHistory={}},1e3*o)))}catch(e){a=e,console.error("WAL onSend failed:",e,l,c)}if(this.isOnSending=!1,this.callbacks.length){const e=Object.keys(this.sending);this.callbacks.forEach((t,n)=>{t.idStrs=t.idStrs.filter(t=>e.includes(t)),t.idStrs.length||t.cb(a)}),this.callbacks=this.callbacks.filter(e=>e.idStrs.length)}this.sending={},e&&console.log(this.options.id," SENT lr->",l[l.length-1]),s(this.changed)?n&&n(l,c,a):this.sendItems()},this.options={...e},!this.options.orderBy){const{synced_field:t,id_fields:n}=e;this.options.orderBy=[t,...n.sort()].map(e=>({fieldName:e,tsDataType:e===t?"number":"string",asc:!0}))}}isSending(){const e=this.isOnSending||!(s(this.sending)&&s(this.changed));return this.options.DEBUG_MODE&&console.log(this.options.id," CHECKING isSending ->",e),e}getIdStr(e){return this.options.id_fields.sort().map(t=>`${e[t]||""}`).join(".")}getIdObj(e){let t={};return this.options.id_fields.sort().map(n=>{t[n]=e[n]}),t}getDeltaObj(e){let t={};return Object.keys(e).map(n=>{this.options.id_fields.includes(n)||(t[n]=e[n])}),t}},t.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 i=[{table:n,on:[{}]},...e??[]];return i.map((e,n)=>{const r=i[n+1];if(r)return{table:e.table,on:(0,t.reverseJoinOn)(r.on)}}).filter(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 i=Object.getOwnPropertyNames(e).reduce((t,n)=>({...t,[n]:e[n]}),{}),o=JSON.parse((0,t.safeStringify)(i));return n?o:r(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]}},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 i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(102),t),r(n(436),t),r(n(441),t)},102(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.isEqual=void 0,t.isEqual=(e,t,i="trace")=>n(e,t,void 0,i);const n=(e,t,i=new WeakMap,r)=>{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=i.get(e);if(o?.has(t)){if("quiet"!==r&&console.trace("Circular reference detected in isEqual",e,t),"error"===r)throw new Error("Circular reference detected in isEqual");return"return-true"===r}if(o||(o=new WeakSet,i.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],i,r))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),i=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<n.length;e++)if(n[e]!==i[e])return!1;return!0}if(e instanceof ArrayBuffer&&t instanceof ArrayBuffer){if(e.byteLength!==t.byteLength)return!1;const n=new Uint8Array(e),i=new Uint8Array(t);for(let e=0;e<n.length;e++)if(n[e]!==i[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,i,r))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,i)=>{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(i){var r=t[i];if(void 0!==r)return r.exports;var o=t[i]={exports:{}};return e[i].call(o.exports,o,o.exports,n),o.exports}(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 r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(Object(this||window),()=>(()=>{"use strict";var e={994(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=t.PrimitiveTypesObj=void 0;const n=r(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,n.getKeys)(t.PrimitiveTypesObj),t.PrimitiveArrayTypes=t.PrimitiveTypes.map(e=>`${e}[]`),t.DATA_TYPES=[...t.PrimitiveTypes,...t.PrimitiveArrayTypes]},897(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.assertJSONBObjectAgainstSchema=t.validateJSONBObjectAgainstSchema=t.getJSONBSchemaValidationError=t.getJSONBObjectSchemaValidationError=t.getFieldTypeObj=void 0;const n=r(472),i=r(704),o=r(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 r=(0,n.isObject)(e)&&"string"==typeof e.name&&"string"==typeof e.type&&s(e.data);if(r&&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 r}},l=(0,n.getKeys)(a),p=(e,r,s=[],u)=>{const f=`${s.join(".")} is of invalid type. Expecting ${c(r).replaceAll("\n","")}`,y=(0,t.getFieldTypeObj)(r),{type:d,allowedValues:m,nullable:g,optional:b}=y;if(g&&null===e)return;if(b&&void 0===e)return;if(m){if("string"!=typeof d)throw new Error("allowedValues is only supported for primitive types");const t=d.endsWith("[]"),r=t&&Array.isArray(e)?e:[e],i=m.map(e=>(0,n.isObject)(e)?e.value:e);for(const[e,n]of r.entries())if(!i.includes(n))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(n)}`}if(d){if((0,n.isObject)(d)){if(!(0,n.isObject)(e))return f;for(const t of(0,i.safeGetKeys)(d)){const r=(0,i.safeGetProperty)(d,t);if(!((0,n.isObject)(r)&&r.optional||(0,i.safeHasOwn)(e,t)))return`${[...s,t].join(".")} is missing but required`;const o=p((0,i.safeGetProperty)(e,t),r,[...s,t],u);if(void 0!==o)return o}if(!u?.allowExtraProperties){const t=(0,i.safeGetKeys)(e),r=(0,i.safeGetKeys)(d),n=t.filter(e=>!r.includes(e));if(n.length)return`${s.join(".")} has extra properties: ${n.join(", ")}`}return}const{validator:t}=((e,t)=>{const r=(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(r){const e=a[r];return{isArray:!0,validator:r=>Array.isArray(r)&&r.every(r=>e(r,t))}}const n=a[e];if(!n)throw new Error(`Unknown field type ${e}`);return{isArray:!1,validator:n}})(d,y);return t(e,y)?void 0:f}if(y.enum){const t=[];return y.nullable&&t.push(null),y.optional&&t.push(void 0),y.enum.includes(e)?void 0:f}const h=y.arrayOf??(y.arrayOfType?{type:y.arrayOfType}:void 0);if(h){if(!Array.isArray(e))return f+" an array";const t=e.map((e,t)=>p(e,h,[...s,`${t}`],u)).filter(n.isDefined)[0];return void 0!==t?`${f}. Error at index ${s.length>0?s.join(".")+".":""}\n\n${t}`:void 0}const O=y.oneOf??y.oneOfType?.map(e=>({type:e}));if(O){if(!O.length)return f+"to not be empty";let t;if(O.find(r=>{const n=p(e,r,s,u);return t??(t=n),void 0===n}))return;return f}if(y.record){const{keysEnum:t,partial:r,values:o}=y.record;if(!(0,n.isObject)(e))return f+"object";if(r&&(0,n.isEmpty)(e))return;const a=(0,n.getKeys)(e),l=r?void 0:t?.find(e=>!a.includes(e));if(void 0!==l)return`${f} to have key ${l}`;const c=t&&a.filter(e=>!t.includes(e));if(c?.length)return`${f} has extra keys: ${c}`;if(o)for(const t of(0,i.safeGetKeys)(e)){const r=(0,i.safeGetProperty)(e,t),n=p(r,o,[...s,t],u);if(void 0!==n)return`${n}`}return}return`Could not validate field type. Some logic might be missing: ${JSON.stringify(y)}`},c=e=>{const r=(0,t.getFieldTypeObj)(e),{type:i,nullable:o,optional:s,record:a}=r,l=r.oneOf??r.oneOfType?.map(e=>({type:e})),p=[];if(o&&p.push("null"),s&&p.push("undefined"),"string"==typeof i)p.push(i);else if(i&&(0,n.isObject)(i)){const e=[];Object.entries(i).forEach(([t,r])=>{e.push(`${t}: ${c(r)}`)}),p.push(`{ ${e.join("; ")} }`)}if(r.enum?.forEach(e=>{null===e?p.push("null"):void 0===e?p.push("undefined"):"string"==typeof e?p.push(JSON.stringify(e)):p.push(e)}),l?.forEach(e=>{const t=c(e);p.push(t)}),a){const{keysEnum:e,partial:t,values:r}=a,n=t?"?":"",i=r?c(r):"any";e?p.push(`{ [${e.join(" | ")}]${n}: ${i} }`):p.push(`{ [key: string]${n}: ${i} }`)}return p.join(" | ")};t.getJSONBObjectSchemaValidationError=(e,t,r="input",i=!1,o)=>{if(void 0===t&&!i)return{error:`Expecting ${r} to be defined`};if(!(0,n.isObject)(t))return{error:`Expecting ${r} to be an object`};const s=p(t,{type:e},[],o);return s?{error:s}:{data:t}},t.getJSONBSchemaValidationError=(e,t,r)=>{const n=p(t,e,void 0,r);return n?{error:n}:{data:t}},t.validateJSONBObjectAgainstSchema=(e,r,n,i=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,r,n,i);return void 0===o},t.assertJSONBObjectAgainstSchema=(e,r,n,i=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,r,n,i);if(o)throw new Error(o)}},699(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONSchemaObject=void 0,t.getJSONBSchemaAsJSONSchema=function(e,r,n){return(0,t.getJSONSchemaObject)(n,{id:`${e}.${r}`})};const n=r(472),i=r(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,r)=>{const{type:s,arrayOf:a,arrayOfType:l,description:p,nullable:c,oneOf:u,oneOfType:f,title:y,record:d,...m}="string"==typeof e?{type:e}:e;let g={};const b={...(m.enum||m.allowedValues?.length&&("string"!=typeof s||!s.endsWith("[]")))&&{enum:m.allowedValues?.slice(0)??m.enum.slice(0)},...!!p&&{description:p},...!!y&&{title:y}};if(m.enum?.length){const e=typeof m.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";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,n.isObject)(s))g={type:"object",required:(0,i.safeGetKeys)(s).filter(e=>{const t=s[e];return"string"==typeof t||!t.optional}),properties:(0,n.getObjectEntries)(s).reduce((e,[r,n])=>({...e,[r]:(0,t.getJSONSchemaObject)(n)}),{})};else if(u||f){const e=u||f.map(e=>({type:e}));g={oneOf:e.map(e=>(0,t.getJSONSchemaObject)(e))}}else d&&(g={type:"object",...d.values&&!d.keysEnum&&{additionalProperties:(0,t.getJSONSchemaObject)(d.values)},...d.keysEnum&&{properties:d.keysEnum.reduce((e,r)=>({...e,[r]:d.values?(0,t.getJSONSchemaObject)(d.values):{type:{}}}),{})}});if(c){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{...r?{$id:r?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...b,...g}}},394(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBTSTypes=void 0,t.getJSONBSchemaTSTypes=function(e,r,n="",i){return(0,t.getJSONBTSTypes)(i,{...e,nullable:r.nullable},void 0,n)};const n=r(806),i=r(897),o=e=>null===e?"null":void 0===e?"undefined":"string"==typeof e?JSON.stringify(e):String(e);t.getJSONBTSTypes=(e,r,a=!1,l="",p=0)=>{const c=(0,i.getFieldTypeObj)(r),u=c.nullable?"null | ":"";if(c.lookup){const r=c.lookup;if("data-def"===r.type)return`${c.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"===r.type;let o=i?"table"===r.object?"string":'{ "table": string; "column": string; }':"";if(!i){const t=e.find(e=>e.name===r.table)?.columns;o=r.isFullRow?t?`{ ${t.map(e=>`${JSON.stringify(e.name)}: ${e.is_nullable?"null | ":""} ${(0,n.postgresToTsType)(e.udt_name)}; `).join(" ")} }`:"any":(0,n.postgresToTsType)(t?.find(e=>e.name===r.column)?.udt_name??"text")}return`${c.nullable?"null | ":""}${o}${r.isArray?"[]":""}`}if("string"==typeof c.type){if(c.type.toLowerCase().includes("lookup"))throw new Error("getJSONBTSTypes: Lookup type not handled correctly");const e=c.type.replace("integer","number").replace("time","string").replace("timestamp","string").replace("FileLike","{ name: string; type: string; data: Blob; }").replace("Date","string");if(c.allowedValues){const e=c.type.endsWith("[]")?"[]":"";return u+` (${c.allowedValues.map(e=>JSON.stringify((0,n.isObject)(e)?e.value:e)).join(" | ")})${e}`}return u+e}if((0,n.isObject)(c.type)){const r=e=>e.trim().endsWith(";")?e:e.trim()+";",{type:o}=c,l=a?" ":" ";let f=` {${l}`+(0,n.getObjectEntries)(o).map(([n,o])=>{const a=(0,i.getFieldTypeObj)(o),c=s(n)?n:JSON.stringify(n);return`${l}${c}${a.optional?"?":""}: `+r((0,t.getJSONBTSTypes)(e,a,!0,void 0,p+1))}).join(" ")+`${l}}`;return a||(f=r(f)),a&&(f=f.split("\n").join("")),u+f}if(c.enum)return u+c.enum.map(e=>o(e)).join(" | ");if(c.oneOf||c.oneOfType){const r=c.oneOf||c.oneOfType.map(e=>({type:e}));return(c.nullable?`\n${l} | null`:"")+r.map(r=>`\n${l} | `+(0,t.getJSONBTSTypes)(e,r,!0,void 0,p+1)).join("")}if(c.arrayOf||c.arrayOfType){const r=c.arrayOf||{type:c.arrayOfType};return`${c.nullable?"null | ":""} ( ${(0,t.getJSONBTSTypes)(e,r,!0,void 0,p+1)} )[]`}if(c.record){const{keysEnum:r,values:n,partial:i}=c.record,s=e=>i?`Partial<Record<${e}>>`:`Record<${e}>`;return`${c.nullable?"null |":""} ${s(`${r?.map(e=>o(e)).join(" | ")??"string"}, ${n?(0,t.getJSONBTSTypes)(e,n,!0,void 0,p+1):"any"}`)}`}throw"Unexpected getSchemaTSTypes: "+JSON.stringify({fieldType:c},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 r=["__proto__","constructor","prototype"];t.safeHasOwn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t.safeGetProperty=(e,t)=>{if(r.includes(t)){const r=Object.getOwnPropertyDescriptor(e,t);return r?.value}return e[t]},t.safeGetKeys=e=>{const n=Object.keys(e);for(const i of r)(0,t.safeHasOwn)(e,i)&&!n.includes(i)&&n.push(i);return n}},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,r){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 n=r(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,n.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,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};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=r(472),s=r(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(r=>(0,s.includes)(t.TS_PG_Types[r],e))??"any",t.getAllowedTableMethods=({publishInfo:e})=>{let r=[...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 n=new Map;return Object.values(t.SQL_COMMAND_TABLE_METHODS).forEach(e=>{e.forEach(e=>{n.set(e,(n.get(e)??0)+1)})}),n.forEach((e,t)=>{r.filter(e=>e===t).length!==e&&n.delete(t)}),Array.from(n.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,r=!0)=>{const n=(e.references??[]).map(e=>{const{ftable:r,fcols:n}=e,i=t.find(e=>e.name===r);if(!i)return;const o=i.columns.filter(e=>n.includes(e.name));return o.length?{ref:e,fcolsInfo:o}:void 0}).filter(o.isDefined),[i,...s]=n??[];if(!s.length)return i?.ref;const[a,...l]=n.filter(e=>e.fcolsInfo.some(e=>e.is_pkey));if(!l.length)return a?.ref;if(!r)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(r(618),t);var l=r(521);Object.defineProperty(t,"CONTENT_TYPE_TO_EXT",{enumerable:!0,get:function(){return l.CONTENT_TYPE_TO_EXT}}),i(r(209),t),i(r(319),t),i(r(699),t),i(r(394),t),i(r(994),t),i(r(897),t),i(r(164),t),i(r(472),t),i(r(778),t)},319(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.leftJoin=t.innerJoin=void 0;const n=r(472),i=(e="$leftJoin")=>(t,r,i,o={})=>({[e]:o.path??t,filter:r,...(0,n.omitKeys)(o,["path","select"]),select:i});t.innerJoin=i("$innerJoin"),t.leftJoin=i("$leftJoin")},666(e,t){function r(e,t){var r=e[0],n=e[1],l=e[2],p=e[3];r=i(r,n,l,p,t[0],7,-680876936),p=i(p,r,n,l,t[1],12,-389564586),l=i(l,p,r,n,t[2],17,606105819),n=i(n,l,p,r,t[3],22,-1044525330),r=i(r,n,l,p,t[4],7,-176418897),p=i(p,r,n,l,t[5],12,1200080426),l=i(l,p,r,n,t[6],17,-1473231341),n=i(n,l,p,r,t[7],22,-45705983),r=i(r,n,l,p,t[8],7,1770035416),p=i(p,r,n,l,t[9],12,-1958414417),l=i(l,p,r,n,t[10],17,-42063),n=i(n,l,p,r,t[11],22,-1990404162),r=i(r,n,l,p,t[12],7,1804603682),p=i(p,r,n,l,t[13],12,-40341101),l=i(l,p,r,n,t[14],17,-1502002290),r=o(r,n=i(n,l,p,r,t[15],22,1236535329),l,p,t[1],5,-165796510),p=o(p,r,n,l,t[6],9,-1069501632),l=o(l,p,r,n,t[11],14,643717713),n=o(n,l,p,r,t[0],20,-373897302),r=o(r,n,l,p,t[5],5,-701558691),p=o(p,r,n,l,t[10],9,38016083),l=o(l,p,r,n,t[15],14,-660478335),n=o(n,l,p,r,t[4],20,-405537848),r=o(r,n,l,p,t[9],5,568446438),p=o(p,r,n,l,t[14],9,-1019803690),l=o(l,p,r,n,t[3],14,-187363961),n=o(n,l,p,r,t[8],20,1163531501),r=o(r,n,l,p,t[13],5,-1444681467),p=o(p,r,n,l,t[2],9,-51403784),l=o(l,p,r,n,t[7],14,1735328473),r=s(r,n=o(n,l,p,r,t[12],20,-1926607734),l,p,t[5],4,-378558),p=s(p,r,n,l,t[8],11,-2022574463),l=s(l,p,r,n,t[11],16,1839030562),n=s(n,l,p,r,t[14],23,-35309556),r=s(r,n,l,p,t[1],4,-1530992060),p=s(p,r,n,l,t[4],11,1272893353),l=s(l,p,r,n,t[7],16,-155497632),n=s(n,l,p,r,t[10],23,-1094730640),r=s(r,n,l,p,t[13],4,681279174),p=s(p,r,n,l,t[0],11,-358537222),l=s(l,p,r,n,t[3],16,-722521979),n=s(n,l,p,r,t[6],23,76029189),r=s(r,n,l,p,t[9],4,-640364487),p=s(p,r,n,l,t[12],11,-421815835),l=s(l,p,r,n,t[15],16,530742520),r=a(r,n=s(n,l,p,r,t[2],23,-995338651),l,p,t[0],6,-198630844),p=a(p,r,n,l,t[7],10,1126891415),l=a(l,p,r,n,t[14],15,-1416354905),n=a(n,l,p,r,t[5],21,-57434055),r=a(r,n,l,p,t[12],6,1700485571),p=a(p,r,n,l,t[3],10,-1894986606),l=a(l,p,r,n,t[10],15,-1051523),n=a(n,l,p,r,t[1],21,-2054922799),r=a(r,n,l,p,t[8],6,1873313359),p=a(p,r,n,l,t[15],10,-30611744),l=a(l,p,r,n,t[6],15,-1560198380),n=a(n,l,p,r,t[13],21,1309151649),r=a(r,n,l,p,t[4],6,-145523070),p=a(p,r,n,l,t[11],10,-1120210379),l=a(l,p,r,n,t[2],15,718787259),n=a(n,l,p,r,t[9],21,-343485551),e[0]=f(r,e[0]),e[1]=f(n,e[1]),e[2]=f(l,e[2]),e[3]=f(p,e[3])}function n(e,t,r,n,i,o){return t=f(f(t,e),f(n,o)),f(t<<i|t>>>32-i,r)}function i(e,t,r,i,o,s,a){return n(t&r|~t&i,e,t,o,s,a)}function o(e,t,r,i,o,s,a){return n(t&i|r&~i,e,t,o,s,a)}function s(e,t,r,i,o,s,a){return n(t^r^i,e,t,o,s,a)}function a(e,t,r,i,o,s,a){return n(r^(t|~i),e,t,o,s,a)}function l(e){var t,r=[];for(t=0;t<64;t+=4)r[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return r}t.md5=u;var p="0123456789abcdef".split("");function c(e){for(var t="",r=0;r<4;r++)t+=p[e>>8*r+4&15]+p[e>>8*r&15];return t}function u(e){return function(e){for(var t=0;t<e.length;t++)e[t]=c(e[t]);return e.join("")}(function(e){var t,n=e.length,i=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)r(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(r(i,o),t=0;t<16;t++)o[t]=0;return o[14]=8*n,r(i,o),i}(e))}function f(e,t){return e+t&4294967295}u("hello")},164(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.getSyncChannelName=void 0;const n=r(806);t.getSyncChannelName=({tableName:e,filter:t={},select:r={}})=>[n.CHANNEL_PREFIX,e,"sync",(0,n.stableStringify)(t),"string"==typeof r?r:(0,n.stableStringify)(r)].join(".")},472(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),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 r,n="boolean"==typeof t.cycles&&t.cycles,i=t.cmp&&(r=t.cmp,function(e){return function(t,n){var i={key:t,value:e[t]},o={key:n,value:e[n]};return r(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 r,s;if(Array.isArray(t)){for(s="[",r=0;r<t.length;r++)r&&(s+=","),s+=e(t[r])||"null";return s+"]"}if(null===t)return"null";if(-1!==o.indexOf(t)){if(n)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="",r=0;r<l.length;r++){var p=l[r],c=e(t[p]);c&&(s&&(s+=","),s+=JSON.stringify(p)+":"+c)}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,n.md5)(t)};function r(r=1){let n=r<1?-1:0,i=!1;for(;!i&&Math.abs(n)<=t.length;){const o=r<1?[n]:[0,n];e.slice(...o)!==t.slice(...o)?i=!0:n+=1*Math.sign(r)}return n}let i=r()-1,o=e.length+r(-1)+1,s=t.length+r(-1)+1;return{from:i,to:o,text:t.slice(i,s),md5:(0,n.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:r,to:i,text:o,md5:s}=t;if(null===o||null===e)return o;let a=e.slice(0,r)+o+e.slice(i);if(s&&(0,n.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 r=t,n=e;return e?("string"==typeof r&&(r=r.split(".")),r.reduce((e,t)=>e&&e[t]?e[t]:void 0,n)):e},t.isObject=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},t.isDefined=a,t.getKeys=l;const n=r(666);function i(e,r){return(0,t.pickKeys)(e,l(e).filter(e=>!r.includes(e)))}function o(e,t){return e.filter(e=>Object.entries(t).every(([t,r])=>e[t]===r))}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=[],r=!0)=>{if(!t.length)return{};if(e&&t.length){let n={};return t.forEach(t=>{r&&void 0===e[t]||(n[t]=e[t])}),n}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,r)=>{const n=[{table:r,on:[{}]},...e??[]];return n.map((e,r)=>{const i=n[r+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,r])=>e[t]===r))return e},t.safeStringify=e=>{const t=new WeakSet;return JSON.stringify(e,(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return"[Circular]";t.add(r)}return r})},t.getSerialisableError=(e,r=!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,...r?{stack:e.stack}:{}};if(e instanceof Error){const n=Object.getOwnPropertyNames(e).reduce((t,r)=>({...t,[r]:e[r]}),{}),o=JSON.parse((0,t.safeStringify)(n));return r?o:i(o,["stack"])}return Array.isArray(e)?e.map(e=>(0,t.getSerialisableError)(e,r)):e},t.getProperty=(e,t)=>{if(Object.keys(e).includes(t))return e[t]}},441(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.includes=function(e,t){return e.some(e=>e===t)}},778(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(102),t),i(r(436),t),i(r(441),t)},102(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.isEqual=void 0,t.isEqual=(e,t,n="trace")=>r(e,t,void 0,n);const r=(e,t,n=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=n.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,n.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(!r(e[o],t[o],n,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 r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<r.length;e++)if(r[e]!==n[e])return!1;return!0}if(e instanceof ArrayBuffer&&t instanceof ArrayBuffer){if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),n=new Uint8Array(t);for(let e=0;e<r.length;e++)if(r[e]!==n[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(!r(s,a,n,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 r=e();return r instanceof Promise?new Promise(async(e,n)=>{e({...await r.then(e=>({data:e})).catch(e=>({error:e,hasError:!0})),duration:Date.now()-t})}):{data:r,duration:Date.now()-t}}catch(e){return{error:e,hasError:!0,duration:Date.now()-t}}}}},t={};return function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}(806)})());
@@ -99,7 +99,9 @@ export type ReplicationState = {
99
99
  /** Filter */
100
100
  param1: EqualityFilter<AnyObject>;
101
101
  /** Select */
102
- param2: FieldFilter;
102
+ param2: {
103
+ select: FieldFilter;
104
+ };
103
105
  };
104
106
  "server.response": {
105
107
  data: SyncConfig & {
@@ -1 +1 @@
1
- {"version":3,"file":"replication.d.ts","sourceRoot":"","sources":["../lib/replication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3D;;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,CAAC,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,GACvB;IACE,GAAG,CAAC,EAAE,SAAS,CAAC;CACjB,GACD;IACE;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB,GACD;IACE;;OAEG;IACH,IAAI,EAAE,SAAS,EAAE,CAAC;CACnB,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,cAAc,CAAC,GAAG;IACzD,IAAI,EAAE,SAAS,EAAE,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAC9B;IACE,IAAI,EAAE,SAAS,EAAE,CAAC;CACnB,GAC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E;oBACjB,IAAI,EAAE,UAAU,GAAG;wBACjB,IAAI,EAAE,SAAS,EAAE,CAAC;wBAClB,QAAQ,EAAE,OAAO,CAAC;qBACnB,CAAC;oBAEF,QAAQ,EAAE;wBACR,WAAW,EAAE;4BACX,uCAAuC;4BACvC,iBAAiB,EAAE,MAAM,MAAM,CAAC;4BAChC,aAAa,EAAE;gCACb,IAAI,EAAE;oCACJ,aAAa,EACT,cAAc,GACd,iBAAiB,GACjB,OAAO,CAAC,cAAc,GAAG,iBAAiB,CAAC,CAAC;iCACjD,CAAC;6BACH,CAAC;yBACH,CAAC;qBACH,CAAC;iBACH,CAAC;aACH,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC"}
package/dist/util.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyObject, JoinPath, TS_COLUMN_DATA_TYPES } from ".";
1
+ import { AnyObject, JoinPath } from ".";
2
2
  export declare function asName(str: string): string;
3
3
  export declare const pickKeys: <T extends AnyObject, Include extends keyof T>(obj: T, keys?: Include[] | readonly Include[], onlyIfDefined?: boolean) => Pick<T, Include>;
4
4
  export declare function omitKeys<T extends AnyObject, Exclude extends keyof T>(obj: T, exclude: Exclude[]): Omit<T, Exclude>;
@@ -16,88 +16,6 @@ export type TextPatch = {
16
16
  };
17
17
  export declare function getTextPatch(oldStr: string, newStr: string): TextPatch | string;
18
18
  export declare function unpatchText(original: string | null, patch: TextPatch): string;
19
- export type SyncTableInfo = {
20
- id_fields: string[];
21
- synced_field: string;
22
- throttle: number;
23
- batch_size: number;
24
- };
25
- export type BasicOrderBy = {
26
- fieldName: string;
27
- /**
28
- * Used to ensure numbers are not left as strings in some cases
29
- */
30
- tsDataType: TS_COLUMN_DATA_TYPES;
31
- asc: boolean;
32
- }[];
33
- export type WALConfig = SyncTableInfo & {
34
- /**
35
- * Fired when new data is added and there is no sending in progress
36
- */
37
- onSendStart?: () => any;
38
- /**
39
- * Fired on each data send batch
40
- */
41
- onSend: (items: any[], fullItems: WALItem[]) => Promise<any>;
42
- /**
43
- * Fired after all data was sent or when a batch error is thrown
44
- */
45
- onSendEnd?: (batch: any[], fullItems: WALItem[], error?: any) => any;
46
- /**
47
- * Order by which the items will be synced. Defaults to [synced_field, ...id_fields.sort()]
48
- */
49
- orderBy?: BasicOrderBy;
50
- /**
51
- * Defaults to 2 seconds
52
- */
53
- historyAgeSeconds?: number;
54
- DEBUG_MODE?: boolean;
55
- id?: string;
56
- };
57
- export type WALItem = {
58
- initial?: AnyObject;
59
- delta?: AnyObject;
60
- current: AnyObject;
61
- };
62
- export type WALItemsObj = Record<string, WALItem>;
63
- /**
64
- * Used to throttle and combine updates sent to server
65
- * This allows a high rate of optimistic updates on the client
66
- */
67
- export declare class WAL {
68
- /**
69
- * Instantly merged records for prepared for update
70
- */
71
- private changed;
72
- /**
73
- * Batch of records (removed from this.changed) that are currently being sent
74
- */
75
- private sending;
76
- /**
77
- * Historic data used to reduce data pushes from server to client
78
- */
79
- private sentHistory;
80
- private options;
81
- private callbacks;
82
- constructor(args: WALConfig);
83
- sort: (a?: AnyObject, b?: AnyObject) => number;
84
- isSending(): boolean;
85
- /**
86
- * Used by server to avoid unnecessary data push to client.
87
- * This can happen due to the same data item having been previously pushed by the client
88
- * @param item data item
89
- * @returns boolean
90
- */
91
- isInHistory: (item: AnyObject) => boolean;
92
- getIdStr(d: AnyObject): string;
93
- getIdObj(d: AnyObject): AnyObject;
94
- getDeltaObj(d: AnyObject): AnyObject;
95
- addData: (data: WALItem[]) => Promise<void>;
96
- isOnSending: boolean;
97
- isSendingTimeout?: ReturnType<typeof setTimeout>;
98
- willDeleteHistory?: ReturnType<typeof setTimeout>;
99
- private sendItems;
100
- }
101
19
  export declare function isEmpty(obj?: any): boolean;
102
20
  export declare const isNotEmpty: <T extends Record<string, unknown>>(obj?: T | null | undefined) => obj is T;
103
21
  export declare function get(obj: any, propertyPath: string | string[]): any;
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../lib/util.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EF,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAChD,eAAO,MAAM,aAAa,GAAI,IAAI,cAAc,CAAC,IAAI,CAAC;;GAIrD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,YAAY,cAAc,EAAE,EAAE,OAAO,MAAM;;;;;GAa5E,CAAC;AAEF,KAAK,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AAErD,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,EACvE,KAAK,CAAC,EACN,YAAY,CAAC,KACZ,WAAW,CAAC,CAAC,EAAE,CAAC,CAKlB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,KAAK,SAAS,WAW3C,CAAC;AACF,eAAO,MAAM,oBAAoB,GAC/B,UAAU,GAAG,EACb,sBAAoB,KACnB,SAAS,GAAG,GAAG,EAAE,GAAG,MAAM,GAAG,SAAS,GAAG,IA0C3C,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC5D,KAAK,CAAC,EACN,KAAK,CAAC,GAAG,MAAM,KACd,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GACzB,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,GACzC,SAGD,CAAC"}
package/dist/util.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProperty = exports.getSerialisableError = exports.safeStringify = exports.extractTypeUtil = exports.reverseParsedPath = exports.reverseJoinOn = exports.tryCatch = exports.getObjectEntries = exports.isNotEmpty = exports.WAL = exports.pickKeys = void 0;
3
+ exports.getProperty = exports.getSerialisableError = exports.safeStringify = exports.extractTypeUtil = exports.reverseParsedPath = exports.reverseJoinOn = exports.tryCatch = exports.getObjectEntries = exports.isNotEmpty = exports.pickKeys = void 0;
4
4
  exports.asName = asName;
5
5
  exports.omitKeys = omitKeys;
6
6
  exports.filter = filter;
@@ -152,233 +152,6 @@ function unpatchText(original, patch) {
152
152
  throw ("Patch text error: Could not match md5 hash: (original/result) \n" + original + "\n" + res);
153
153
  return res;
154
154
  }
155
- /**
156
- * Used to throttle and combine updates sent to server
157
- * This allows a high rate of optimistic updates on the client
158
- */
159
- class WAL {
160
- constructor(args) {
161
- /**
162
- * Instantly merged records for prepared for update
163
- */
164
- this.changed = {};
165
- /**
166
- * Batch of records (removed from this.changed) that are currently being sent
167
- */
168
- this.sending = {};
169
- /**
170
- * Historic data used to reduce data pushes from server to client
171
- */
172
- this.sentHistory = {};
173
- this.callbacks = [];
174
- this.sort = (a, b) => {
175
- const { orderBy } = this.options;
176
- if (!orderBy || !a || !b)
177
- return 0;
178
- return (orderBy
179
- .map((ob) => {
180
- /* TODO: add fullData to changed items + ensure orderBy is in select */
181
- if (!(ob.fieldName in a) || !(ob.fieldName in b)) {
182
- throw `Replication error: \n some orderBy fields missing from data`;
183
- }
184
- let v1 = ob.asc ? a[ob.fieldName] : b[ob.fieldName], v2 = ob.asc ? b[ob.fieldName] : a[ob.fieldName];
185
- let vNum = +v1 - +v2, vStr = v1 < v2 ? -1
186
- : v1 == v2 ? 0
187
- : 1;
188
- return ob.tsDataType === "number" && Number.isFinite(vNum) ? vNum : vStr;
189
- })
190
- .find((v) => v) || 0);
191
- };
192
- /**
193
- * Used by server to avoid unnecessary data push to client.
194
- * This can happen due to the same data item having been previously pushed by the client
195
- * @param item data item
196
- * @returns boolean
197
- */
198
- this.isInHistory = (item) => {
199
- if (!item)
200
- throw "Provide item";
201
- const itemSyncVal = item[this.options.synced_field];
202
- if (!Number.isFinite(+itemSyncVal))
203
- throw "Provided item Synced field value is missing/invalid ";
204
- const existing = this.sentHistory[this.getIdStr(item)];
205
- const existingSyncVal = existing?.[this.options.synced_field];
206
- if (existing) {
207
- if (!Number.isFinite(+existingSyncVal))
208
- throw "Provided historic item Synced field value is missing/invalid";
209
- if (+existingSyncVal === +itemSyncVal) {
210
- return true;
211
- }
212
- }
213
- return false;
214
- };
215
- this.addData = (data) => {
216
- if (isEmpty(this.changed) && this.options.onSendStart)
217
- this.options.onSendStart();
218
- data.map((d) => {
219
- var _a;
220
- const { initial, current, delta } = { ...d };
221
- if (!current)
222
- throw "Expecting { current: object, initial?: object }";
223
- const idStr = this.getIdStr(current);
224
- this.changed ?? (this.changed = {});
225
- (_a = this.changed)[idStr] ?? (_a[idStr] = { initial, current, delta });
226
- this.changed[idStr].current = {
227
- ...this.changed[idStr].current,
228
- ...current,
229
- };
230
- this.changed[idStr].delta = {
231
- ...this.changed[idStr].delta,
232
- ...delta,
233
- };
234
- });
235
- return this.sendItems();
236
- };
237
- this.isOnSending = false;
238
- this.isSendingTimeout = undefined;
239
- this.willDeleteHistory = undefined;
240
- this.sendItems = async () => {
241
- const { DEBUG_MODE, onSend, onSendEnd, batch_size, throttle, historyAgeSeconds = 2, } = this.options;
242
- // Sending data. stop here
243
- if (this.isSendingTimeout || (this.sending && !isEmpty(this.sending)))
244
- return;
245
- // Nothing to send. stop here
246
- if (!this.changed || isEmpty(this.changed))
247
- return;
248
- // Prepare batch to send
249
- let batchItems = [], walBatch = [], batchObj = {};
250
- /**
251
- * Prepare and remove a batch from this.changed
252
- */
253
- Object.keys(this.changed)
254
- .sort((a, b) => this.sort(this.changed[a].current, this.changed[b].current))
255
- .slice(0, batch_size)
256
- .map((key) => {
257
- let item = { ...this.changed[key] };
258
- this.sending[key] = { ...item };
259
- walBatch.push({ ...item });
260
- /* Used for history */
261
- batchObj[key] = { ...item.current };
262
- delete this.changed[key];
263
- });
264
- batchItems = walBatch.map((d) => {
265
- let result = {};
266
- Object.keys(d.current).map((k) => {
267
- const oldVal = d.initial?.[k];
268
- const newVal = d.current[k];
269
- /** Send only id fields and delta */
270
- if ([this.options.synced_field, ...this.options.id_fields].includes(k) ||
271
- !areEqual(oldVal, newVal)) {
272
- result[k] = newVal;
273
- }
274
- });
275
- return result;
276
- });
277
- if (DEBUG_MODE) {
278
- console.log(this.options.id, " SENDING lr->", batchItems[batchItems.length - 1]);
279
- }
280
- // Throttle next data send
281
- if (!this.isSendingTimeout) {
282
- this.isSendingTimeout = setTimeout(() => {
283
- this.isSendingTimeout = undefined;
284
- if (!isEmpty(this.changed)) {
285
- this.sendItems();
286
- }
287
- }, throttle);
288
- }
289
- let error;
290
- this.isOnSending = true;
291
- try {
292
- /* Deleted data should be sent normally through await db.table.delete(...) */
293
- await onSend(batchItems, walBatch); //, deletedData);
294
- /**
295
- * Keep history if required
296
- */
297
- if (historyAgeSeconds) {
298
- this.sentHistory = {
299
- ...this.sentHistory,
300
- ...batchObj,
301
- };
302
- /**
303
- * Delete history after some time
304
- */
305
- if (!this.willDeleteHistory) {
306
- this.willDeleteHistory = setTimeout(() => {
307
- this.willDeleteHistory = undefined;
308
- this.sentHistory = {};
309
- }, historyAgeSeconds * 1000);
310
- }
311
- }
312
- }
313
- catch (err) {
314
- error = err;
315
- console.error("WAL onSend failed:", err, batchItems, walBatch);
316
- }
317
- this.isOnSending = false;
318
- /* Fire any callbacks */
319
- if (this.callbacks.length) {
320
- const ids = Object.keys(this.sending);
321
- this.callbacks.forEach((c, i) => {
322
- c.idStrs = c.idStrs.filter((id) => ids.includes(id));
323
- if (!c.idStrs.length) {
324
- c.cb(error);
325
- }
326
- });
327
- this.callbacks = this.callbacks.filter((cb) => cb.idStrs.length);
328
- }
329
- this.sending = {};
330
- if (DEBUG_MODE) {
331
- console.log(this.options.id, " SENT lr->", batchItems[batchItems.length - 1]);
332
- }
333
- if (!isEmpty(this.changed)) {
334
- this.sendItems();
335
- }
336
- else {
337
- if (onSendEnd)
338
- onSendEnd(batchItems, walBatch, error);
339
- }
340
- };
341
- this.options = { ...args };
342
- if (!this.options.orderBy) {
343
- const { synced_field, id_fields } = args;
344
- this.options.orderBy = [synced_field, ...id_fields.sort()].map((fieldName) => ({
345
- fieldName,
346
- tsDataType: fieldName === synced_field ? "number" : "string",
347
- asc: true,
348
- }));
349
- }
350
- }
351
- isSending() {
352
- const result = this.isOnSending || !(isEmpty(this.sending) && isEmpty(this.changed));
353
- if (this.options.DEBUG_MODE) {
354
- console.log(this.options.id, " CHECKING isSending ->", result);
355
- }
356
- return result;
357
- }
358
- getIdStr(d) {
359
- return this.options.id_fields
360
- .sort()
361
- .map((key) => `${d[key] || ""}`)
362
- .join(".");
363
- }
364
- getIdObj(d) {
365
- let res = {};
366
- this.options.id_fields.sort().map((key) => {
367
- res[key] = d[key];
368
- });
369
- return res;
370
- }
371
- getDeltaObj(d) {
372
- let res = {};
373
- Object.keys(d).map((key) => {
374
- if (!this.options.id_fields.includes(key)) {
375
- res[key] = d[key];
376
- }
377
- });
378
- return res;
379
- }
380
- }
381
- exports.WAL = WAL;
382
155
  function isEmpty(obj) {
383
156
  for (var v in obj)
384
157
  return false;
@@ -406,14 +179,6 @@ const getObjectEntries = (obj) => {
406
179
  return Object.entries(obj);
407
180
  };
408
181
  exports.getObjectEntries = getObjectEntries;
409
- function areEqual(a, b) {
410
- if (a === b)
411
- return true;
412
- if (["number", "string", "boolean"].includes(typeof a)) {
413
- return a === b;
414
- }
415
- return JSON.stringify(a) === JSON.stringify(b);
416
- }
417
182
  function isObject(obj) {
418
183
  return Boolean(obj && typeof obj === "object" && !Array.isArray(obj));
419
184
  }