UNPKG

prostgles-types

Version:

Shared TypeScript object definitions for prostgles-client and prostgles-server

1 lines 30 kB
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this||window,(()=>(()=>{"use strict";var e={994:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONSchemaObject=t.DATA_TYPES=t.PrimitiveArrayTypes=t.PrimitiveTypes=void 0,t.getJSONBSchemaAsJSONSchema=function(e,n,i){return(0,t.getJSONSchemaObject)(i,{id:`${e}.${n}`})};const i=n(472);t.PrimitiveTypes=["boolean","number","integer","string","Date","time","timestamp","any"],t.PrimitiveArrayTypes=t.PrimitiveTypes.map((e=>`${e}[]`)),t.DATA_TYPES=[...t.PrimitiveTypes,...t.PrimitiveArrayTypes];const r=e=>{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||"Lookup"===t?void 0:"string",isArray:e.endsWith("[]")}};t.getJSONSchemaObject=(e,n)=>{const{type:o,arrayOf:s,arrayOfType:a,description:l,nullable:c,oneOf:p,oneOfType:u,title:d,record:f,...m}="string"==typeof e?{type:e}:e;let y={};const h={...(m.enum||m.allowedValues?.length&&("string"!=typeof o||!o.endsWith("[]")))&&{enum:m.allowedValues?.slice(0)??m.enum.slice(0)},...!!l&&{description:l},...!!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 o||s||a){if(o&&"string"!=typeof o)throw"Not expected";y=s||a||o?.endsWith("[]")?{type:"array",items:s||a?(0,t.getJSONSchemaObject)(s||{type:a}):o?.startsWith("any")?{type:void 0}:{type:r(o)?.type,...m.allowedValues&&{enum:m.allowedValues.slice(0)}}}:{type:r(o)?.type}}else if((0,i.isObject)(o))y={type:"object",required:(0,i.getKeys)(o).filter((e=>{const t=o[e];return"string"==typeof t||!t.optional})),properties:(0,i.getObjectEntries)(o).reduce(((e,[n,i])=>({...e,[n]:(0,t.getJSONSchemaObject)(i)})),{})};else if(p||u){const e=p||u.map((e=>({type:e})));y={oneOf:e.map((e=>(0,t.getJSONSchemaObject)(e)))}}else f&&(y={type:"object",...f.values&&!f.keysEnum&&{additionalProperties:(0,t.getJSONSchemaObject)(f.values)},...f.keysEnum&&{properties:f.keysEnum.reduce(((e,n)=>({...e,[n]:f.values?(0,t.getJSONSchemaObject)(f.values):{type:{}}})),{})}});if(c){const e={type:"null"};y.oneOf?y.oneOf.push(e):y.enum&&!y.enum.includes(null)?y.enum.push(null):y={oneOf:[y,e]}}return{...n?{$id:n?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...h,...y}}},897:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.assertJSONBObjectAgainstSchema=t.validateJSONBObjectAgainstSchema=t.getJSONBObjectSchemaValidationError=t.getFieldTypeObj=void 0;const i=n(472);t.getFieldTypeObj=e=>"string"==typeof e?{type:e}:e;const r={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,Date:e=>"string"==typeof e,Lookup:()=>{throw new Error("Lookup type is not supported for validation")}},o=(0,i.getKeys)(r),s=(e,n,l=[])=>{const c=`${l.join(".")} is of invalid type. Expecting ${a(n).replaceAll("\n","")}`,p=(0,t.getFieldTypeObj)(n),{type:u,allowedValues:d,nullable:f,optional:m}=p;if(f&&null===e)return;if(m&&void 0===e)return;if(d)throw new Error("Allowed values are not supported for validation");if(u){if((0,i.isObject)(u)){if(!(0,i.isObject)(e))return c;for(const[t,n]of(0,i.getObjectEntries)(u)){const i=s(e[t],n,[...l,t]);if(void 0!==i)return i}return}const{validator:t}=(e=>{const t=(e=>{if("string"==typeof e&&e.endsWith("[]")){const t=e.slice(0,-2);if(!o.includes(t))throw new Error(`Unknown array field type ${e}`);return t}})(e);if(t){const e=r[t];return{isArray:!0,validator:t=>Array.isArray(t)&&t.every((t=>e(t)))}}const n=r[e];if(!n)throw new Error(`Unknown field type ${e}`);return{isArray:!1,validator:n}})(u);return t(e)?void 0:c}if(p.enum){const t=[];return p.nullable&&t.push(null),p.optional&&t.push(void 0),p.enum.includes(e)?void 0:c}const y=p.arrayOf??(p.arrayOfType?{type:p.arrayOfType}:void 0);if(y){if(!Array.isArray(e))return c+" to be an array";const t=e.map(((e,t)=>s(e,y,[...l,`${t}`]))).filter(i.isDefined)[0];return void 0!==t?`${c}. Error at index ${l.length>0?l.join(".")+".":""}\n\n${t}`:void 0}const h=p.oneOf??p.oneOfType?.map((e=>({type:e})));if(h){if(!h.length)return c+"to not be empty";let t;if(h.find((n=>{const i=s(e,n,l);return t??(t=i),void 0===i})))return;return c}if(!p.record)return`Could not validate field type. Some logic might be missing: ${JSON.stringify(p)}`;{const{keysEnum:t,partial:n,values:r}=p.record;if(!(0,i.isObject)(e))return c+"object";if(n&&(0,i.isEmpty)(e))return;const o=(0,i.getKeys)(e),a=n?void 0:t?.find((e=>!o.includes(e)));if(void 0!==a)return`${c} to have key ${a}`;const u=t&&o.filter((e=>!t.includes(e)));if(u?.length)return`${c} has extra keys: ${u}`;if(r)for(const[t,n]of Object.entries(e)){const e=s(n,r,[...l,t]);if(void 0!==e)return`${e}`}}},a=e=>{const n=(0,t.getFieldTypeObj)(e),{type:r,nullable:o,optional:s,record:l}=n,c=n.oneOf??n.oneOfType?.map((e=>({type:e}))),p=[];if(o&&p.push("null"),s&&p.push("undefined"),"string"==typeof r)p.push(r);else if(r&&(0,i.isObject)(r)){const e=[];Object.entries(r).forEach((([t,n])=>{e.push(`${t}: ${a(n)}`)})),p.push(`{ ${e.join("; ")} }`)}if(n.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)})),c?.forEach((e=>{const t=a(e);p.push(t)})),l){const{keysEnum:e,partial:t,values:n}=l,i=t?"?":"",r=n?a(n):"any";e?p.push(`{ [${e.join(" | ")}]${i}: ${r} }`):p.push(`{ [key: string]${i}: ${r} }`)}return p.join(" | ")};t.getJSONBObjectSchemaValidationError=(e,t,n,r=!1)=>{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`};for(const[n,i]of Object.entries(e)){const e=s(t[n],i,[n]);if(e)return{error:e}}return{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)}},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("Date","string");return p.allowedValues&&p.type.endsWith("[]")?u+` (${p.allowedValues.map((e=>JSON.stringify(e))).join(" | ")})[]`:u+e}if((0,i.isObject)(p.type)){const n=e=>e.trim().endsWith(";")?e:e.trim()+";",{type:o}=p,l=a?" ":" ";let d=` {${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||(d=n(d)),a&&(d=d.split("\n").join("")),u+d}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)},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","<>",">","<",">=","<=","$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:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=t.getPossibleNestedInsert=t.RULE_METHODS=t.CHANNELS=t.JOIN_PARAMS=t.JOIN_KEYS=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);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 s={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={...s,"number[]":s.number.map((e=>`_${e}`)),"boolean[]":s.boolean.map((e=>`_${e}`)),"string[]":s.string.map((e=>`_${e}`)),"any[]":s.any.map((e=>`_${e}`))},t.postgresToTsType=e=>(0,o.getKeys)(t.TS_PG_Types).find((n=>(0,o.includes)(t.TS_PG_Types[n],e)))??"any",t.JOIN_KEYS=["$innerJoin","$leftJoin"],t.JOIN_PARAMS=["select","filter","$path","$condition","offset","limit","orderBy"];const a="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:a+"schema-changed",SCHEMA:a+"schema",DEFAULT:a,SQL:`${a}sql`,SQL_STREAM:`${a}sql-stream`,METHOD:`${a}method`,NOTICE_EV:`${a}notice`,LISTEN_EV:`${a}listen`,REGISTER:`${a}register`,LOGIN:`${a}login`,LOGOUT:`${a}logout`,AUTHGUARD:`${a}authguard`,CONNECTION:`${a}connection`,_preffix:a},t.RULE_METHODS={getColumns:["getColumns"],getInfo:["getInfo"],insert:["insert","upsert"],update:["update","upsert","updateBatch"],select:["findOne","find","count","size"],delete:["delete","remove"],sync:["sync","unsync"],subscribe:["unsubscribe","subscribe","subscribeOne"]},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")};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(994),t),r(n(472),t),r(n(618),t),r(n(897),t),r(n(394),t)},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]=d(n,e[0]),e[1]=d(i,e[1]),e[2]=d(l,e[2]),e[3]=d(c,e[3])}function i(e,t,n,i,r,o){return t=d(d(t,e),d(i,o)),d(t<<r|t>>>32-r,n)}function r(e,t,n,r,o,s,a){return i(t&n|~t&r,e,t,o,s,a)}function o(e,t,n,r,o,s,a){return i(t&r|n&~r,e,t,o,s,a)}function s(e,t,n,r,o,s,a){return i(t^n^r,e,t,o,s,a)}function a(e,t,n,r,o,s,a){return i(n^(t|~r),e,t,o,s,a)}function l(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}Object.defineProperty(t,"__esModule",{value:!0}),t.md5cycle=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 d(e,t){return e+t&4294967295}u("hello")},472:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getSerialisableError=t.safeStringify=t.extractTypeUtil=t.isEqual=t.reverseParsedPath=t.reverseJoinOn=t.getJoinHandlers=t.tryCatchV2=t.tryCatch=t.getObjectEntries=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.includes=function(e,t){return e.some((e=>e===t))},t.stableStringify=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var n,i="boolean"==typeof t.cycles&&t.cycles,r=t.cmp&&(n=t.cmp,function(e){return function(t,i){var r={key:t,value:e[t]},o={key:i,value:e[i]};return n(r,o)}}),o=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var n,s;if(Array.isArray(t)){for(s="[",n=0;n<t.length;n++)n&&(s+=","),s+=e(t[n])||"null";return s+"]"}if(null===t)return"null";if(-1!==o.indexOf(t)){if(i)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=o.push(t)-1,l=Object.keys(t).sort(r&&r(t));for(s="",n=0;n<l.length;n++){var c=l[n],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.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.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.getJoinHandlers=e=>{const t=(t,n)=>(n,i,o={})=>({[t?"$leftJoin":"$innerJoin"]:o.path??e,filter:n,...r(o,["path","select"]),select:i});return{innerJoin:t(!1),leftJoin:t(!0),innerJoinOne:t(!1),leftJoinOne:t(!0)}},t.reverseJoinOn=e=>e.map((e=>Object.fromEntries(Object.entries(e).map((([e,t])=>[t,e]))))),t.reverseParsedPath=(e,n)=>{const i=[{table:n,on:[{}]},...e??[]];return i.map(((e,n)=>{const r=i[n+1];if(r)return{table:e.table,on:(0,t.reverseJoinOn)(r.on)}})).filter(a).reverse()},t.isEqual=function(e,n,i=new WeakSet){if(e===n)return!0;if(typeof e!=typeof n)return!1;if("object"==typeof e&&null!==e&&"object"==typeof n&&null!==n){const r=Object.keys(e);if(r.length!==Object.keys(n).length)return!1;if(i.has(e)||i.has(n))return console.trace("Circular reference detected in isEqual",e,n,i),!1;i.add(e),i.add(n);for(const o of r){if(!(o in n))return!1;{const r=e[o],s=n[o];if(!(0,t.isEqual)(r,s,i))return!1}}return!0}return!1},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 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={};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)})()));