UNPKG

prostgles-types

Version:

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

1 lines 32.7 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 r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(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,r){return(0,t.getJSONSchemaObject)(r,{id:`${e}.${n}`})};const r=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 i=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:f,record:d,...y}="string"==typeof e?{type:e}:e;let m={};const g={...(y.enum||y.allowedValues?.length&&("string"!=typeof o||!o.endsWith("[]")))&&{enum:y.allowedValues?.slice(0)??y.enum.slice(0)},...!!l&&{description:l},...!!f&&{title:f}};if(y.enum?.length){const e=typeof y.enum[0];g.type="number"===e?"number":"boolean"===e?"boolean":"string"}if("string"==typeof o||s||a){if(o&&"string"!=typeof o)throw"Not expected";m=s||a||o?.endsWith("[]")?{type:"array",items:s||a?(0,t.getJSONSchemaObject)(s||{type:a}):o?.startsWith("any")?{type:void 0}:{type:i(o)?.type,...y.allowedValues&&{enum:y.allowedValues.slice(0)}}}:{type:i(o)?.type}}else if((0,r.isObject)(o))m={type:"object",required:(0,r.getKeys)(o).filter((e=>{const t=o[e];return"string"==typeof t||!t.optional})),properties:(0,r.getObjectEntries)(o).reduce(((e,[n,r])=>({...e,[n]:(0,t.getJSONSchemaObject)(r)})),{})};else if(p||u){const e=p||u.map((e=>({type:e})));m={oneOf:e.map((e=>(0,t.getJSONSchemaObject)(e)))}}else d&&(m={type:"object",...d.values&&!d.keysEnum&&{additionalProperties:(0,t.getJSONSchemaObject)(d.values)},...d.keysEnum&&{properties:d.keysEnum.reduce(((e,n)=>({...e,[n]:d.values?(0,t.getJSONSchemaObject)(d.values):{type:{}}})),{})}});if(c){const e={type:"null"};m.oneOf?m.oneOf.push(e):m.enum&&!m.enum.includes(null)?m.enum.push(null):m={oneOf:[m,e]}}return{...n?{$id:n?.id,$schema:"https://json-schema.org/draft/2020-12/schema"}:void 0,...g,...m}}},897:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.assertJSONBObjectAgainstSchema=t.validateJSONBObjectAgainstSchema=t.getJSONBSchemaValidationError=t.getJSONBObjectSchemaValidationError=t.getFieldTypeObj=void 0;const r=n(472),i=n(704);t.getFieldTypeObj=e=>"string"==typeof e?{type:e}:e;const o={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")}},s=(0,r.getKeys)(o),a=(e,n,c=[],p)=>{const u=`${c.join(".")} is of invalid type. Expecting ${l(n).replaceAll("\n","")}`,f=(0,t.getFieldTypeObj)(n),{type:d,allowedValues:y,nullable:m,optional:g}=f;if(m&&null===e)return;if(g&&void 0===e)return;if(y)return`${c.join(".")} Allowed values are not supported for validation`;if(d){if((0,r.isObject)(d)){if(!(0,r.isObject)(e))return u;for(const t of(0,i.safeGetKeys)(d)){const n=(0,i.safeGetProperty)(d,t);if(!((0,r.isObject)(n)&&n.optional||(0,i.safeHasOwn)(e,t)))return`${[...c,t].join(".")} is missing but required`;const o=a((0,i.safeGetProperty)(e,t),n,[...c,t],p);if(void 0!==o)return o}if(!p?.allowExtraProperties){const t=(0,i.safeGetKeys)(e),n=(0,i.safeGetKeys)(d),r=t.filter((e=>!n.includes(e)));if(r.length)return`${c.join(".")} has extra properties: ${r.join(", ")}`}return}const{validator:t}=(e=>{const t=(e=>{if("string"==typeof e&&e.endsWith("[]")){const t=e.slice(0,-2);if(!s.includes(t))throw new Error(`Unknown array field type ${e}`);return t}})(e);if(t){const e=o[t];return{isArray:!0,validator:t=>Array.isArray(t)&&t.every((t=>e(t)))}}const n=o[e];if(!n)throw new Error(`Unknown field type ${e}`);return{isArray:!1,validator:n}})(d);return t(e)?void 0:u}if(f.enum){const t=[];return f.nullable&&t.push(null),f.optional&&t.push(void 0),f.enum.includes(e)?void 0:u}const h=f.arrayOf??(f.arrayOfType?{type:f.arrayOfType}:void 0);if(h){if(!Array.isArray(e))return u+" an array";const t=e.map(((e,t)=>a(e,h,[...c,`${t}`],p))).filter(r.isDefined)[0];return void 0!==t?`${u}. Error at index ${c.length>0?c.join(".")+".":""}\n\n${t}`:void 0}const b=f.oneOf??f.oneOfType?.map((e=>({type:e})));if(b){if(!b.length)return u+"to not be empty";let t;if(b.find((n=>{const r=a(e,n,c,p);return t??(t=r),void 0===r})))return;return u}if(!f.record)return`Could not validate field type. Some logic might be missing: ${JSON.stringify(f)}`;{const{keysEnum:t,partial:n,values:o}=f.record;if(!(0,r.isObject)(e))return u+"object";if(n&&(0,r.isEmpty)(e))return;const s=(0,r.getKeys)(e),l=n?void 0:t?.find((e=>!s.includes(e)));if(void 0!==l)return`${u} to have key ${l}`;const d=t&&s.filter((e=>!t.includes(e)));if(d?.length)return`${u} has extra keys: ${d}`;if(o)for(const t of(0,i.safeGetKeys)(e)){const n=(0,i.safeGetProperty)(e,t),r=a(n,o,[...c,t],p);if(void 0!==r)return`${r}`}}},l=e=>{const n=(0,t.getFieldTypeObj)(e),{type:i,nullable:o,optional:s,record:a}=n,c=n.oneOf??n.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,r.isObject)(i)){const e=[];Object.entries(i).forEach((([t,n])=>{e.push(`${t}: ${l(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=l(e);p.push(t)})),a){const{keysEnum:e,partial:t,values:n}=a,r=t?"?":"",i=n?l(n):"any";e?p.push(`{ [${e.join(" | ")}]${r}: ${i} }`):p.push(`{ [key: string]${r}: ${i} }`)}return p.join(" | ")};t.getJSONBObjectSchemaValidationError=(e,t,n="input",i=!1,o)=>{if(void 0===t&&!i)return{error:`Expecting ${n} to be defined`};if(!(0,r.isObject)(t))return{error:`Expecting ${n} to be an object`};const s=a(t,{type:e},[],o);return s?{error:s}:{data:t}},t.getJSONBSchemaValidationError=(e,t,n)=>{const r=a(t,e,void 0,n);return r?{error:r}:{data:t}},t.validateJSONBObjectAgainstSchema=(e,n,r,i=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,n,r,i);return void 0===o},t.assertJSONBObjectAgainstSchema=(e,n,r,i=!1)=>{const{error:o}=(0,t.getJSONBObjectSchemaValidationError)(e,n,r,i);if(o)throw new Error(o)}},394:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getJSONBTSTypes=void 0,t.getJSONBSchemaTSTypes=function(e,n,r="",i){return(0,t.getJSONBTSTypes)(i,{...e,nullable:n.nullable},void 0,r)};const r=n(806),i=n(897),o=e=>null===e?"null":void 0===e?"undefined":"string"==typeof e?JSON.stringify(e):String(e);t.getJSONBTSTypes=(e,n,a=!1,l="",c=0)=>{const p=(0,i.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 i="schema"===n.type;let o=i?"table"===n.object?"string":'{ "table": string; "column": string; }':"";if(!i){const t=e.find((e=>e.name===n.table))?.columns;o=n.isFullRow?t?`{ ${t.map((e=>`${JSON.stringify(e.name)}: ${e.is_nullable?"null | ":""} ${(0,r.postgresToTsType)(e.udt_name)}; `)).join(" ")} }`:"any":(0,r.postgresToTsType)(t?.find((e=>e.name===n.column))?.udt_name??"text")}return`${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,r.isObject)(p.type)){const n=e=>e.trim().endsWith(";")?e:e.trim()+";",{type:o}=p,l=a?" ":" ";let f=` {${l}`+(0,r.getObjectEntries)(o).map((([r,o])=>{const a=(0,i.getFieldTypeObj)(o),p=s(r)?r:JSON.stringify(r);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:r,partial:i}=p.record,s=e=>i?`Partial<Record<${e}>>`:`Record<${e}>`;return`${p.nullable?"null |":""} ${s(`${n?.map((e=>o(e))).join(" | ")??"string"}, ${r?(0,t.getJSONBTSTypes)(e,r,!0,void 0,c+1):"any"}`)}`}throw"Unexpected getSchemaTSTypes: "+JSON.stringify({fieldType:p},null,2)};const s=e=>/^[A-Za-z$_][A-Za-z0-9$_]*$/.test(e)},704:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.safeGetKeys=t.safeGetProperty=t.safeHasOwn=void 0;const n=["__proto__","constructor","prototype"];t.safeHasOwn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t.safeGetProperty=(e,t)=>{if(n.includes(t)){const n=Object.getOwnPropertyDescriptor(e,t);return n?.value}return e[t]},t.safeGetKeys=e=>{const r=Object.keys(e);for(const i of n)(0,t.safeHasOwn)(e,i)&&!r.includes(i)&&r.push(i);return r}},618:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},521:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CONTENT_TYPE_TO_EXT=void 0,t.CONTENT_TYPE_TO_EXT={"text/html":["html","htm","shtml"],"text/css":["css"],"text/csv":["csv"],"text/tsv":["tsv"],"text/xml":["xml"],"text/mathml":["mml"],"text/plain":["txt"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/x-component":["htc"],"image/gif":["gif"],"image/jpeg":["jpeg","jpg"],"image/png":["png"],"image/tiff":["tif","tiff"],"image/vnd.wap.wbmp":["wbmp"],"image/x-icon":["ico"],"image/x-jng":["jng"],"image/x-ms-bmp":["bmp"],"image/svg+xml":["svg"],"image/webp":["webp"],"application/sql":["sql"],"application/x-javascript":["js"],"application/atom+xml":["atom"],"application/rss+xml":["rss"],"application/java-archive":["jar","war","ear"],"application/mac-binhex40":["hqx"],"application/msword":["doc","docx"],"application/pdf":["pdf"],"application/postscript":["ps","eps","ai"],"application/rtf":["rtf"],"application/vnd.ms-excel":["xls","xlsx"],"application/vnd.ms-powerpoint":["ppt","pptx"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/x-7z-compressed":["7z"],"application/x-cocoa":["cco"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-makeself":["run"],"application/x-perl":["pl","pm"],"application/x-pilot":["prc","pdb"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-sea":["sea"],"application/x-shockwave-flash":["swf"],"application/x-stuffit":["sit"],"application/x-tcl":["tcl","tk"],"application/x-x509-ca-cert":["der","pem","crt"],"application/x-xpinstall":["xpi"],"application/xhtml+xml":["xhtml"],"application/zip":["zip"],"application/octet-stream":["bin","exe","dll","deb","dmg","eot","iso","img","msi","msp","msm"],"audio/midi":["mid","midi","kar"],"audio/mpeg":["mp3"],"audio/ogg":["ogg"],"audio/x-realaudio":["ra"],"video/3gpp":["3gpp","3gp"],"video/mpeg":["mpeg","mpg"],"video/quicktime":["mov"],"video/x-flv":["flv"],"video/x-mng":["mng"],"video/x-ms-asf":["asx","asf"],"video/x-ms-wmv":["wmv"],"video/x-msvideo":["avi"],"video/mp4":["m4v","mp4"],"video/webm":["webm"]}},209:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.COMPLEX_FILTER_KEY=t.ComplexFilterComparisonKeys=t.EXISTS_KEYS=t.GeomFilter_Funcs=t.GeomFilterKeys=t.ArrayFilterOperands=t.TextFilter_FullTextSearchFilterKeys=t.TextFilterFTSKeys=t.TextFilterKeys=t.JsonbFilterKeys=t.JsonbOperands=t.BetweenFilterKeys=t.CompareInFilterKeys=t.CompareFilterKeys=void 0;const r=n(472);t.CompareFilterKeys=["=","$eq","<>",">","<",">=","<=","$eq","$ne","$gt","$gte","$lt","$lte","$isDistinctFrom","$isNotDistinctFrom"],t.CompareInFilterKeys=["$in","$nin"],t.BetweenFilterKeys=["$between","$notBetween"],t.JsonbOperands={"@>":{Operator:"@>","Right Operand Type":"jsonb",Description:"Does the left JSON value contain the right JSON path/value entries at the top level?",Example:'\'{"a":1, "b":2}\'::jsonb @> \'{"b":2}\'::jsonb'},"<@":{Operator:"<@","Right Operand Type":"jsonb",Description:"Are the left JSON path/value entries contained at the top level within the right JSON value?",Example:'\'{"b":2}\'::jsonb <@ \'{"a":1, "b":2}\'::jsonb'},"?":{Operator:"?","Right Operand Type":"text",Description:"Does the string exist as a top-level key within the JSON value?",Example:"'{\"a\":1, \"b\":2}'::jsonb ? 'b'"},"?|":{Operator:"?|","Right Operand Type":"text[]",Description:"Do any of these array strings exist as top-level keys?",Example:"'{\"a\":1, \"b\":2, \"c\":3}'::jsonb ?| array['b', 'c']"},"?&":{Operator:"?&","Right Operand Type":"text[]",Description:"Do all of these array strings exist as top-level keys?",Example:"'[\"a\", \"b\"]'::jsonb ?& array['a', 'b']"},"||":{Operator:"||","Right Operand Type":"jsonb",Description:"Concatenate two jsonb values into a new jsonb value",Example:'\'["a", "b"]\'::jsonb || \'["c", "d"]\'::jsonb'},"-":{Operator:"-","Right Operand Type":"integer",Description:"Delete the array element with specified index (Negative integers count from the end). Throws an error if top level container is not an array.",Example:'\'["a", "b"]\'::jsonb - 1'},"#-":{Operator:"#-","Right Operand Type":"text[]",Description:"Delete the field or element with specified path (for JSON arrays, negative integers count from the end)",Example:"'[\"a\", {\"b\":1}]'::jsonb #- '{1,b}'"},"@?":{Operator:"@?","Right Operand Type":"jsonpath",Description:"Does JSON path return any item for the specified JSON value?",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)'"},"@@":{Operator:"@@","Right Operand Type":"jsonpath",Description:"Returns the result of JSON path predicate check for the specified JSON value. Only the first item of the result is taken into account. If the result is not Boolean, then null is returned.",Example:"'{\"a\":[1,2,3,4,5]}'::jsonb @@ '$.a[*] > 2'"}},t.JsonbFilterKeys=(0,r.getKeys)(t.JsonbOperands),t.TextFilterKeys=["$ilike","$like","$nilike","$nlike"],t.TextFilterFTSKeys=["@@","@>","<@","$contains","$containedBy"],t.TextFilter_FullTextSearchFilterKeys=["to_tsquery","plainto_tsquery","phraseto_tsquery","websearch_to_tsquery"],t.ArrayFilterOperands=["@>","<@","=","$eq","$contains","$containedBy","&&","$overlaps"],t.GeomFilterKeys=["~","~=","@","|&>","|>>",">>","=","<<|","<<","&>","&<|","&<","&&&","&&"],t.GeomFilter_Funcs=["ST_MakeEnvelope","st_makeenvelope","ST_MakePolygon","st_makepolygon"],t.EXISTS_KEYS=["$exists","$notExists","$existsJoined","$notExistsJoined"],t.ComplexFilterComparisonKeys=[...t.TextFilterKeys,...t.JsonbFilterKeys,...t.CompareFilterKeys,...t.BetweenFilterKeys,...t.CompareInFilterKeys],t.COMPLEX_FILTER_KEY="$filter"},806:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.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),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.JOIN_KEYS=["$innerJoin","$leftJoin"],t.JOIN_PARAMS=["select","filter","$path","$condition","offset","limit","orderBy"];const l="_psqlWS_.";t.CHANNELS={SCHEMA_CHANGED:l+"schema-changed",SCHEMA:l+"schema",DEFAULT:l,SQL:`${l}sql`,SQL_STREAM:`${l}sql-stream`,METHOD:`${l}method`,NOTICE_EV:`${l}notice`,LISTEN_EV:`${l}listen`,REGISTER:`${l}register`,LOGIN:`${l}login`,LOGOUT:`${l}logout`,AUTHGUARD:`${l}authguard`,CONNECTION:`${l}connection`,_preffix:l},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 r=(e.references??[]).map((e=>{const{ftable:n,fcols:r}=e,i=t.find((e=>e.name===n));if(!i)return;const o=i.columns.filter((e=>r.includes(e.name)));return o.length?{ref:e,fcolsInfo:o}:void 0})).filter(o.isDefined),[i,...s]=r??[];if(!s.length)return i?.ref;const[a,...l]=r.filter((e=>e.fcolsInfo.some((e=>e.is_pkey))));if(!l.length)return a?.ref;if(!n)throw["Cannot do a nested insert on column that references multiple tables.","Expecting only one reference to a single primary key fcol"].join("\n")};var c=n(521);Object.defineProperty(t,"CONTENT_TYPE_TO_EXT",{enumerable:!0,get:function(){return c.CONTENT_TYPE_TO_EXT}}),i(n(209),t),i(n(994),t),i(n(472),t),i(n(618),t),i(n(897),t),i(n(394),t),i(n(778),t)},666:(e,t)=>{function n(e,t){var n=e[0],r=e[1],l=e[2],c=e[3];n=i(n,r,l,c,t[0],7,-680876936),c=i(c,n,r,l,t[1],12,-389564586),l=i(l,c,n,r,t[2],17,606105819),r=i(r,l,c,n,t[3],22,-1044525330),n=i(n,r,l,c,t[4],7,-176418897),c=i(c,n,r,l,t[5],12,1200080426),l=i(l,c,n,r,t[6],17,-1473231341),r=i(r,l,c,n,t[7],22,-45705983),n=i(n,r,l,c,t[8],7,1770035416),c=i(c,n,r,l,t[9],12,-1958414417),l=i(l,c,n,r,t[10],17,-42063),r=i(r,l,c,n,t[11],22,-1990404162),n=i(n,r,l,c,t[12],7,1804603682),c=i(c,n,r,l,t[13],12,-40341101),l=i(l,c,n,r,t[14],17,-1502002290),n=o(n,r=i(r,l,c,n,t[15],22,1236535329),l,c,t[1],5,-165796510),c=o(c,n,r,l,t[6],9,-1069501632),l=o(l,c,n,r,t[11],14,643717713),r=o(r,l,c,n,t[0],20,-373897302),n=o(n,r,l,c,t[5],5,-701558691),c=o(c,n,r,l,t[10],9,38016083),l=o(l,c,n,r,t[15],14,-660478335),r=o(r,l,c,n,t[4],20,-405537848),n=o(n,r,l,c,t[9],5,568446438),c=o(c,n,r,l,t[14],9,-1019803690),l=o(l,c,n,r,t[3],14,-187363961),r=o(r,l,c,n,t[8],20,1163531501),n=o(n,r,l,c,t[13],5,-1444681467),c=o(c,n,r,l,t[2],9,-51403784),l=o(l,c,n,r,t[7],14,1735328473),n=s(n,r=o(r,l,c,n,t[12],20,-1926607734),l,c,t[5],4,-378558),c=s(c,n,r,l,t[8],11,-2022574463),l=s(l,c,n,r,t[11],16,1839030562),r=s(r,l,c,n,t[14],23,-35309556),n=s(n,r,l,c,t[1],4,-1530992060),c=s(c,n,r,l,t[4],11,1272893353),l=s(l,c,n,r,t[7],16,-155497632),r=s(r,l,c,n,t[10],23,-1094730640),n=s(n,r,l,c,t[13],4,681279174),c=s(c,n,r,l,t[0],11,-358537222),l=s(l,c,n,r,t[3],16,-722521979),r=s(r,l,c,n,t[6],23,76029189),n=s(n,r,l,c,t[9],4,-640364487),c=s(c,n,r,l,t[12],11,-421815835),l=s(l,c,n,r,t[15],16,530742520),n=a(n,r=s(r,l,c,n,t[2],23,-995338651),l,c,t[0],6,-198630844),c=a(c,n,r,l,t[7],10,1126891415),l=a(l,c,n,r,t[14],15,-1416354905),r=a(r,l,c,n,t[5],21,-57434055),n=a(n,r,l,c,t[12],6,1700485571),c=a(c,n,r,l,t[3],10,-1894986606),l=a(l,c,n,r,t[10],15,-1051523),r=a(r,l,c,n,t[1],21,-2054922799),n=a(n,r,l,c,t[8],6,1873313359),c=a(c,n,r,l,t[15],10,-30611744),l=a(l,c,n,r,t[6],15,-1560198380),r=a(r,l,c,n,t[13],21,1309151649),n=a(n,r,l,c,t[4],6,-145523070),c=a(c,n,r,l,t[11],10,-1120210379),l=a(l,c,n,r,t[2],15,718787259),r=a(r,l,c,n,t[9],21,-343485551),e[0]=f(n,e[0]),e[1]=f(r,e[1]),e[2]=f(l,e[2]),e[3]=f(c,e[3])}function r(e,t,n,r,i,o){return t=f(f(t,e),f(r,o)),f(t<<i|t>>>32-i,n)}function i(e,t,n,i,o,s,a){return r(t&n|~t&i,e,t,o,s,a)}function o(e,t,n,i,o,s,a){return r(t&i|n&~i,e,t,o,s,a)}function s(e,t,n,i,o,s,a){return r(t^n^i,e,t,o,s,a)}function a(e,t,n,i,o,s,a){return r(n^(t|~i),e,t,o,s,a)}function l(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}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,r=e.length,i=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)n(i,l(e.substring(t-64,t)));e=e.substring(t-64);var o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<e.length;t++)o[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(n(i,o),t=0;t<16;t++)o[t]=0;return o[14]=8*r,n(i,o),i}(e))}function f(e,t){return e+t&4294967295}u("hello")},472:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getSerialisableError=t.safeStringify=t.extractTypeUtil=t.reverseParsedPath=t.reverseJoinOn=t.getJoinHandlers=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=i,t.filter=o,t.find=function(e,t){return o(e,t)[0]},t.stableStringify=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var n,r="boolean"==typeof t.cycles&&t.cycles,i=t.cmp&&(n=t.cmp,function(e){return function(t,r){var i={key:t,value:e[t]},o={key:r,value:e[r]};return n(i,o)}}),o=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var n,s;if(Array.isArray(t)){for(s="[",n=0;n<t.length;n++)n&&(s+=","),s+=e(t[n])||"null";return s+"]"}if(null===t)return"null";if(-1!==o.indexOf(t)){if(r)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=o.push(t)-1,l=Object.keys(t).sort(i&&i(t));for(s="",n=0;n<l.length;n++){var c=l[n],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,r.md5)(t)};function n(n=1){let r=n<1?-1:0,i=!1;for(;!i&&Math.abs(r)<=t.length;){const o=n<1?[r]:[0,r];e.slice(...o)!==t.slice(...o)?i=!0:r+=1*Math.sign(n)}return r}let i=n()-1,o=e.length+n(-1)+1,s=t.length+n(-1)+1;return{from:i,to:o,text:t.slice(i,s),md5:(0,r.md5)(t)}},t.unpatchText=function(e,t){if(!t||"string"==typeof t)return t;const{from:n,to:i,text:o,md5:s}=t;if(null===o||null===e)return o;let a=e.slice(0,n)+o+e.slice(i);if(s&&(0,r.md5)(a)!==s)throw"Patch text error: Could not match md5 hash: (original/result) \n"+e+"\n"+a;return a},t.isEmpty=s,t.get=function(e,t){let n=t,r=e;return e?("string"==typeof n&&(n=n.split(".")),n.reduce(((e,t)=>e&&e[t]?e[t]:void 0),r)):e},t.isObject=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},t.isDefined=a,t.getKeys=l;const r=n(666);function i(e,n){return(0,t.pickKeys)(e,l(e).filter((e=>!n.includes(e))))}function o(e,t){return e.filter((e=>Object.entries(t).every((([t,n])=>e[t]===n))))}function s(e){for(var t in e)return!1;return!0}function a(e){return null!=e}function l(e){return Object.keys(e)}t.pickKeys=(e,t=[],n=!0)=>{if(!t.length)return{};if(e&&t.length){let r={};return t.forEach((t=>{n&&void 0===e[t]||(r[t]=e[t])})),r}return e},t.WAL=class{constructor(e){if(this.changed={},this.sending={},this.sentHistory={},this.callbacks=[],this.sort=(e,t)=>{const{orderBy:n}=this.options;return n&&e&&t&&n.map((n=>{if(!(n.fieldName in e)||!(n.fieldName in t))throw"Replication error: \n some orderBy fields missing from data";let r=n.asc?e[n.fieldName]:t[n.fieldName],i=n.asc?t[n.fieldName]:e[n.fieldName],o=+r-+i,s=r<i?-1:r==i?0:1;return"number"===n.tsDataType&&Number.isFinite(o)?o:s})).find((e=>e))||0},this.isInHistory=e=>{if(!e)throw"Provide item";const t=e[this.options.synced_field];if(!Number.isFinite(+t))throw"Provided item Synced field value is missing/invalid ";const n=this.sentHistory[this.getIdStr(e)],r=n?.[this.options.synced_field];if(n){if(!Number.isFinite(+r))throw"Provided historic item Synced field value is missing/invalid";if(+r==+t)return!0}return!1},this.addData=e=>{s(this.changed)&&this.options.onSendStart&&this.options.onSendStart(),e.map((e=>{var t;const{initial:n,current:r,delta:i}={...e};if(!r)throw"Expecting { current: object, initial?: object }";const o=this.getIdStr(r);this.changed??(this.changed={}),(t=this.changed)[o]??(t[o]={initial:n,current:r,delta:i}),this.changed[o].current={...this.changed[o].current,...r},this.changed[o].delta={...this.changed[o].delta,...i}})),this.sendItems()},this.isOnSending=!1,this.isSendingTimeout=void 0,this.willDeleteHistory=void 0,this.sendItems=async()=>{const{DEBUG_MODE:e,onSend:t,onSendEnd:n,batch_size:r,throttle:i,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,r).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 r=e.initial?.[n],i=e.current[n];var o,s;![this.options.synced_field,...this.options.id_fields].includes(n)&&((o=r)===(s=i)||(["number","string","boolean"].includes(typeof o)?o===s:JSON.stringify(o)===JSON.stringify(s)))||(t[n]=i)})),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()}),i)),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.getJoinHandlers=e=>{const t=(t,n)=>(n,r,o={})=>({[t?"$leftJoin":"$innerJoin"]:o.path??e,filter:n,...i(o,["path","select"]),select:r});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 r=[{table:n,on:[{}]},...e??[]];return r.map(((e,n)=>{const i=r[n+1];if(i)return{table:e.table,on:(0,t.reverseJoinOn)(i.on)}})).filter(a).reverse()},t.extractTypeUtil=(e,t)=>{if(Object.entries(t).every((([t,n])=>e[t]===n)))return e},t.safeStringify=e=>{const t=new WeakSet;return JSON.stringify(e,((e,n)=>{if("object"==typeof n&&null!==n){if(t.has(n))return"[Circular]";t.add(n)}return n}))},t.getSerialisableError=(e,n=!1)=>{if(null==e)return e;if("string"==typeof e||"boolean"==typeof e||"bigint"==typeof e||void 0===e||"number"==typeof e)return e?.toString();if(e instanceof DOMException)return{name:e.name,message:e.message,code:e.code,...n?{stack:e.stack}:{}};if(e instanceof Error){const r=Object.getOwnPropertyNames(e).reduce(((t,n)=>({...t,[n]:e[n]})),{}),o=JSON.parse((0,t.safeStringify)(r));return n?o:i(o,["stack"])}return Array.isArray(e)?e.map((e=>(0,t.getSerialisableError)(e,n))):e}},441:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.includes=function(e,t){return e.some((e=>e===t))}},778:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),i(n(102),t),i(n(436),t),i(n(441),t)},102:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isEqual=void 0,t.isEqual=(e,t,r="trace")=>n(e,t,void 0,r);const n=(e,t,r=new WeakSet,i)=>{if(e===t)return!0;if(typeof e!=typeof t)return!1;if("object"==typeof e&&null!==e&&"object"==typeof t&&null!==t){if(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 o=Array.isArray(e),s=Array.isArray(t);if(o&&s){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!n(e[o],t[o],r,i))return!1;return!0}if(o!==s)return!1;if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if(e.byteLength!==t.byteLength)return!1;const n=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0}if(e instanceof ArrayBuffer&&t instanceof ArrayBuffer){if(e.byteLength!==t.byteLength)return!1;const n=new Uint8Array(e),r=new Uint8Array(t);for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0}const a=Object.keys(e);if(a.length!==Object.keys(t).length)return!1;if(r.has(e)||r.has(t)){if("quiet"!==i&&console.trace("Circular reference detected in isEqual",e,t,r),"error"===i)throw new Error("Circular reference detected in isEqual");return!1}r.add(e),r.add(t);for(const o of a){if(!(o in t))return!1;{const s=e[o],a=t[o];if(!n(s,a,r,i))return!1}}return!0}return e!=e&&t!=t}},436:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.tryCatchV2=void 0,t.tryCatchV2=e=>{const t=Date.now();try{const n=e();return n instanceof Promise?new Promise((async(e,r)=>{e({...await n.then((e=>({data:e}))).catch((e=>({error:e,hasError:!0}))),duration:Date.now()-t})})):{data:n,duration:Date.now()-t}}catch(e){return{error:e,hasError:!0,duration:Date.now()-t}}}}},t={};return function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}(806)})()));