fig-tree-evaluator 2.11.4 → 2.11.6
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/README.md +2 -0
- package/build/index.cjs.js +1 -1
- package/build/index.d.ts +14 -12
- package/build/index.esm.js +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1793,6 +1793,8 @@ Please open an issue: https://github.com/CarlosNZ/fig-tree-evaluator/issues
|
|
|
1793
1793
|
|
|
1794
1794
|
*Trivial upgrades (e.g. documentation, small re-factors, types, etc.) not included*
|
|
1795
1795
|
|
|
1796
|
+
- **v2.11.5**: Upgrade dependencies
|
|
1797
|
+
- **v2.11.4**: Bundle target ES6
|
|
1796
1798
|
- **v2.11.0**: Improved package bundling (bundle size ~50%), with CommonJS and ESM outputs. Note: small **breaking change**: "FigTreeEvaluator" is no longer a default export, so need to import with: `import { FigTreeEvaluator } from 'fig-tree-evaluator'`
|
|
1797
1799
|
- **v2.10.0**: Extended stringSubstitution functionality to included named
|
|
1798
1800
|
property substitution, trim whitespace option, and pluralisation (#97)
|
package/build/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("change-case"),r=require("axios"),t=require("object-property-extractor"),a=require("dequal/lite");function i(e,r,t,a){return new(t||(t=Promise))((function(i,s){function n(e){try{l(a.next(e))}catch(e){s(e)}}function o(e){try{l(a.throw(e))}catch(e){s(e)}}function l(e){var r;e.done?i(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(n,o)}l((a=a.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=r=>{const t=e.camelCase(r);return t||r},l=(e,r)=>r[o(e)],u=(e,r,t)=>{const a=Object.assign({},e);return r.forEach((e=>{t[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[t[o(e)]]})),a},d=(e,r=200)=>e.length<r?e:`${e.slice(0,r-2).trim()}...`,c=(e,r,t=!1)=>{if(void 0!==e)return e;if(t)return d(r);throw new Error(d(r))},p=(e,r)=>{const t=Object.entries(e).map((([e,t])=>[r(e),t]));return Object.fromEntries(t)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:r})=>{var t;return"string"==typeof e&&h(e)&&null!==(t=null==r?void 0:r[e])&&void 0!==t?t:e},y=(e,r)=>{const t=Object.assign(Object.assign({},e),r);return(e.data||r.data)&&(t.data=Object.assign(Object.assign({},e.data),r.data)),(e.functions||r.functions)&&(t.functions=Object.assign(Object.assign({},e.functions),r.functions)),(e.fragments||r.fragments)&&(t.fragments=Object.assign(Object.assign({},e.fragments),r.fragments)),(e.headers||r.headers)&&(t.headers=Object.assign(Object.assign({},e.headers),r.headers)),t},m={number:e=>g(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=e=>e.message,g=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const r=new RegExp(/-?\d*\.?\d+/gm),t=e.match(r);return t?Number(t[0]):0},b=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),T={and:"AND","&":"AND","&&":"AND",or:"OR","|":"OR","||":"OR","=":"EQUAL",eq:"EQUAL",equal:"EQUAL",equals:"EQUAL","!=":"NOT_EQUAL","!":"NOT_EQUAL",ne:"NOT_EQUAL",notEqual:"NOT_EQUAL","+":"PLUS",plus:"PLUS",add:"PLUS",concat:"PLUS",join:"PLUS",merge:"PLUS","-":"SUBTRACT",subtract:"SUBTRACT",minus:"SUBTRACT",takeaway:"SUBTRACT","*":"MULTIPLY",x:"MULTIPLY",multiply:"MULTIPLY",times:"MULTIPLY","/":"DIVIDE",divide:"DIVIDE","÷":"DIVIDE",">":"GREATER_THAN",greaterThan:"GREATER_THAN",higher:"GREATER_THAN",larger:"GREATER_THAN","<":"LESS_THAN",lessThan:"LESS_THAN",lower:"LESS_THAN",smaller:"LESS_THAN","?":"CONDITIONAL",conditional:"CONDITIONAL",ifThen:"CONDITIONAL",regex:"REGEX",patternMatch:"REGEX",regexp:"REGEX",matchPattern:"REGEX",dataProperties:"OBJECT_PROPERTIES",data:"OBJECT_PROPERTIES",getData:"OBJECT_PROPERTIES",objectProperties:"OBJECT_PROPERTIES",objProps:"OBJECT_PROPERTIES",getProperty:"OBJECT_PROPERTIES",getObjProp:"OBJECT_PROPERTIES",stringSubstitution:"STRING_SUBSTITUTION",substitute:"STRING_SUBSTITUTION",stringSub:"STRING_SUBSTITUTION",replace:"STRING_SUBSTITUTION",split:"SPLIT",arraySplit:"SPLIT",count:"COUNT",length:"COUNT",get:"GET",api:"GET",post:"POST",pgSql:"PG_SQL",sql:"PG_SQL",postgres:"PG_SQL",pg:"PG_SQL",pgDb:"PG_SQL",graphQl:"GRAPHQL",graphql:"GRAPHQL",gql:"GRAPHQL",buildObject:"BUILD_OBJECT",build:"BUILD_OBJECT",object:"BUILD_OBJECT",match:"MATCH",switch:"MATCH",customFunctions:"CUSTOM_FUNCTIONS",customFunction:"CUSTOM_FUNCTIONS",objectFunctions:"CUSTOM_FUNCTIONS",function:"CUSTOM_FUNCTIONS",functions:"CUSTOM_FUNCTIONS",runFunction:"CUSTOM_FUNCTIONS",_:"PASSTHRU",passThru:"PASSTHRU",passthru:"PASSTHRU",pass:"PASSTHRU",ignore:"PASSTHRU",coerce:"PASSTHRU",convert:"PASSTHRU"},O=T,C=/(\$[^()]+)\((.*)\)/,j=(e,r={},t=!0)=>t?"string"==typeof e?q(e,r):b(e)?A(e,r):e:e,q=(e,r)=>{const t=C.exec(e);if(!t)return e;const a=t[1].trim(),i=t[2].split(",").map((e=>j(e.trim(),r)));return E(a,i,r)},A=(e,r)=>{if(s(e)||n(e))return e;const t=Object.entries(e),a=t.filter((([e])=>h(e))),i=t.filter((([e])=>!h(e))),o=a.reduce(((e,[t,a])=>e=Object.assign(Object.assign({},e),E(t,a,r))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,r,t)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(r)?{operator:i,children:r}:b(r)&&!Object.keys(r).some((e=>h(e)))?Object.assign({operator:i},r):{operator:i,children:[r]}:a in t?{fragment:a,parameters:Object.assign({},r)}:{[e]:r}},S=e=>b(e)&&"literal"in e,N=({value:e,name:r,expectedType:t})=>{if(S(t)){const{literal:a}=t;return!!a.includes(e)||w(r,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(t))return!!t.some((t=>!0===N({value:e,name:r,expectedType:t})))||w(r,e,t.join("|"));return!!(0,x[t])(e)||w(r,e,t)},P=(...e)=>{const r=[];return e.forEach((e=>{const t=N(e);!0!==t&&r.push(t)})),!(r.length>0)||r.join("\n")},x={any:e=>void 0!==e,string:e=>"string"==typeof e,number:e=>"number"==typeof e,boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),null:e=>null===e,object:e=>b(e),undefined:e=>void 0===e},w=(e,r,t)=>void 0===r&&e?`- Missing required property "${e}" (type: ${t})`:void 0!==e?`- Property "${e}" (value: ${U(r)}) is not of type: ${t}`:`- ${U(r)} is not of type: ${t}`,U=e=>{const r=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return d(r,50)},R=e=>{const r={};return e.forEach((e=>{e.aliases.forEach((t=>r[t]=e.name))})),r},I=(e,r)=>e.map((({name:e,required:t,type:a})=>{if(S(a)){const i=[...a.literal];return t||i.push(void 0),{name:e,value:r[e],expectedType:{literal:i}}}const i=Array.isArray(a)?a:[a];t||i.push("undefined");const s=1===i.length?i[0]:i;return{name:e,value:r[e],expectedType:s}})),L=(e,r)=>{const t=e.map(((e,t)=>[e,r[t]]));return Object.fromEntries(t)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=e.filter(((e,r)=>r%2==0)),t=P(...r.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==t)throw new Error(t);const a=e.filter(((e,r)=>r%2==1)),i={};return r.forEach(((e,r)=>{i[e]=a[r]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(e,r,a=void 0)=>{const i=r?t(e,r,a):e;return Array.isArray(i)?i.map((e=>D(e))):r?null===i?null:D(i):i},M=e=>/^https?:\/\/.+/.test(e),H=(...e)=>e.reduce(((e,r,t)=>{const a="/"===r[0]?1:0,i="/"===r.slice(-1)?-1:void 0,s=r.slice(a,i);return""===s?e:e+(0===t?"":"/")+s}),""),F=({url:e,params:t={},data:a={},headers:s={},method:n="get"})=>i(void 0,void 0,void 0,(function*(){var i;try{return(yield r({method:n,url:e,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:t,data:a})).data}catch(e){if(r.isAxiosError(e)){if(!(null==e?void 0:e.response))throw new Error("Network Error");console.log(null===(i=e.response)||void 0===i?void 0:i.data)}throw e}})),G=(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,i,o;const{options:u,operators:d,operatorAliases:h}=r;let y=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const r=JSON.parse(e);return s(r)?r:e}catch(r){return e}})(e):e;y=j(y,null===(t=r.options)||void 0===t?void 0:t.fragments,!u.noShorthand),Array.isArray(y)&&(y=yield Q(y,r));const g=s(y),T=n(y);if(u.evaluateFullObject&&!g&&!T)return v(yield B(y,r),r);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(y)&&"value"in y?y.value:v(y,r);const{fallback:O}=y,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,t]=yield Q([y.fragment,y.parameters],r),a=j(null===(i=null==u?void 0:u.fragments)||void 0===i?void 0:i[e],u.fragments,!u.noShorthand);if(void 0===a)return c(yield G(O,r),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,r);y=Object.assign(Object.assign(Object.assign({},y),a),t),delete y.fragment}try{const e=l(y.operator,h);if(!e)return c(yield G(O,r),`Invalid operator: ${y.operator}`,C);if(!r.operators[e])return c(yield G(O,r),`Excluded operator: ${y.operator}`,C);const{propertyAliases:t,evaluate:a,parseChildren:i}=d[e];y=((e,r)=>p(r,(r=>r in e?e[r]:r)))(t,y);const s=yield $(y,r);T||Object.entries(s).forEach((([e,t])=>r.resolvedAliasNodes[e]=t));const n=T?Object.assign(Object.assign({},r),{resolvedAliasNodes:Object.assign(Object.assign({},r.resolvedAliasNodes),s)}):r;if("children"in y){if(Array.isArray(y.children)||(y.children=yield G(y.children,n)),!Array.isArray(y.children))return c(yield G(O,r),`Operator: ${e}\n- Property "children" is not of type: array`,C);y=yield i(y,n),delete y.children}let u;try{u=yield a(y,n)}catch(t){return c(yield G(y.fallback,r),`Operator: ${e}\n${f(t)}`,C)}const v=null!==(o=null==y?void 0:y.outputType)&&void 0!==o?o:null==y?void 0:y.type;if(!v)return u;const g=yield G(v,r);return g in m?m[g](u):c(yield G(O,r),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield G(O,r),f(e),C)}})),Q=(e,r)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>G(e,r)))):yield G(e,r)})),$=(e,r)=>i(void 0,void 0,void 0,(function*(){const t=Object.keys(e).filter(h);if(0===t.length)return{};const a=[];return t.forEach((t=>a.push(G(e[t],r)))),L(t,yield Promise.all(a))})),B=(e,r)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const t=[],a=[];Object.entries(e).forEach((([t,i])=>{h(t)&&(a.push(t,G(i,r)),delete e[t])}));const i=yield Promise.all(a);r.resolvedAliasNodes=Object.assign(Object.assign({},r.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{t.push(e,G(a,r))}));const s=yield Promise.all(t);return v(k(s),r)})),W=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array"}],z=R(W),J={description:"Logical AND",aliases:["and","&","&&"],parameters:W},V=e=>{const r=e.children;return Object.assign(Object.assign({},e),{values:r})},X={propertyAliases:z,operatorData:J,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);return r.typeChecker(I(J.parameters,{values:t})),t.reduce(((e,r)=>e&&!!r),!0)})),parseChildren:V},Y=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array"}],K=R(Y),Z={description:"Logical OR",aliases:["or","|","||"],parameters:Y},ee={propertyAliases:K,operatorData:Z,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);return r.typeChecker(I(Z.parameters,{values:t})),t.reduce(((e,r)=>e||!!r),!1)})),parseChildren:V},re=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array"},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value",aliases:[],required:!1,type:"boolean"}],te=R(re),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:re},ie={propertyAliases:te,operatorData:ae,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const[i,s]=yield Q([e.values,e.nullEqualsUndefined],r);r.typeChecker(I(ae.parameters,{values:i,nullEqualsUndefined:s}));return!(void 0!==s?s:void 0!==(null===(t=r.options)||void 0===t?void 0:t.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==i[0]&&void 0!==i[0]?i.every((e=>a.dequal(e,i[0]))):i.every((e=>null==e))})),parseChildren:V},se=[{name:"values",description:"Array of values to check for inequality",aliases:[],required:!0,type:"array"},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value",aliases:[],required:!1,type:"boolean"}],ne=R(se),oe={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:se},le={propertyAliases:ne,operatorData:oe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const[i,s]=yield Q([e.values,e.nullEqualsUndefined],r);r.typeChecker(I(oe.parameters,{values:i,nullEqualsUndefined:s}));return!(void 0!==s?s:void 0!==(null===(t=r.options)||void 0===t?void 0:t.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==i[0]&&void 0!==i[0]?i.some((e=>!a.dequal(e,i[0]))):i.some((e=>null===e&&void 0===e))})),parseChildren:V},ue=[{name:"values",description:"Array of values to check to add together",aliases:[],required:!0,type:"array"},{name:"type",description:"Data type to coerce input values to before addition",aliases:[],required:!1,type:{literal:["string","array","number","boolean","bool"]}}],de=R(ue),ce={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ue},pe={propertyAliases:de,operatorData:ce,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);return r.typeChecker(I(ce.parameters,{values:t,type:e.type})),0===t.length?t:"string"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),""):"array"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),[]):t.every((e=>"string"==typeof e||Array.isArray(e)))?t.reduce(((e,r)=>e.concat(r))):t.every((e=>b(e)))?t.reduce(((e,r)=>Object.assign(Object.assign({},e),r)),{}):t.reduce(((e,r)=>e+r))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array"},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number"},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number"}],ve=R(he),ye={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},me={propertyAliases:ve,operatorData:ye,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i]=yield Q([e.values,e.from,e.subtract],r);r.typeChecker(I(ye.parameters,{values:t,from:a,subtract:i}));const s=null!=t?t:[a,i].filter((e=>void 0!==e));if(s.length<2)throw new Error("- Not enough values provided");if(s.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return s[0]-s[1]})),parseChildren:V},fe=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array"}],ge=R(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);if(r.typeChecker(I(be.parameters,{values:t})),0===t.length)return 0;if(t.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return t.reduce(((e,r)=>e*r))})),parseChildren:V},Oe=[{name:"values",description:"Array of values - 1st element will be divided by the first",aliases:[],required:!1,type:"array"},{name:"dividend",description:"The number that will be divided",aliases:["divide"],required:!1,type:"number"},{name:"divisor",description:"The number that dividend will be divided by",aliases:["by","divideBy"],required:!1,type:"number"},{name:"output",description:"Whether to output a quotient, remainder or decimal",aliases:[],required:!1,type:{literal:["quotient","remainder"]}}],Ce=R(Oe),je={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},qe={propertyAliases:Ce,operatorData:je,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i,s]=yield Q([e.values,e.dividend,e.divisor,e.output],r);r.typeChecker(I(je.parameters,{values:t,dividend:a,divisor:i,output:s}));const n=null!=t?t:[a,i].filter((e=>void 0!==e));if(n.length<2)throw new Error("- Not enough values provided");if(n.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");if(0===n[1])throw new Error("Division by zero!");switch(s){case"quotient":return Math.floor(n[0]/n[1]);case"remainder":return n[0]%n[1];default:return n[0]/n[1]}})),parseChildren:V},Ae=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array"},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean"}],Ee=R(Ae),Se={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Ae},Ne={propertyAliases:Ee,operatorData:Se,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a=!0]=yield Q([e.values,e.strict],r);if(r.typeChecker(I(Se.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[i,s]=t;return i===s&&!a||i>s})),parseChildren:V},Pe=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array"},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean"}],xe=R(Pe),we={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ue={propertyAliases:xe,operatorData:we,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a=!0]=yield Q([e.values,e.strict],r);if(r.typeChecker(I(we.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[i,s]=t;return i===s&&!a||i<s})),parseChildren:V},Re=[{name:"condition",description:"The expression to check for truthiness",aliases:[],required:!0,type:"any"},{name:"valueIfTrue",description:"Value to return if condition is true",aliases:["ifTrue"],required:!0,type:"any"},{name:"valueIfFalse",description:"Value to return if condition is false",aliases:["ifFalse","ifNot"],required:!0,type:"any"}],Ie=R(Re),Le={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Re},ke={propertyAliases:Ie,operatorData:Le,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(I(Le.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield G(e.condition,r))?yield G(e.valueIfTrue,r):yield G(e.valueIfFalse,r)})),parseChildren:e=>{const[r,t,a]=e.children;return Object.assign(Object.assign({},e),{condition:r,valueIfTrue:t,valueIfFalse:a})}},De=[{name:"testString",description:"The string to test",aliases:["string","value"],required:!0,type:"string"},{name:"pattern",description:"The regular expression pattern",aliases:["regex","regexp","regExp","re"],required:!0,type:"string"}],_e=R(De),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},He={propertyAliases:_e,operatorData:Me,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a]=yield Q([e.testString,e.pattern],r);r.typeChecker(I(Me.parameters,{testString:t,pattern:a}));try{return new RegExp(a).test(t)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[r,t]=e.children;return Object.assign(Object.assign({},e),{testString:r,pattern:t})}},Fe=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object"}],Ge=R(Fe),Qe={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:Fe},$e={propertyAliases:Ge,operatorData:Qe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,i,s,n;const[o,l]=yield Q([e.property,e.additionalData],r);r.typeChecker(I(Qe.parameters,{property:o,additionalData:l}));const u=l?Object.assign(Object.assign({},null!==(i=null===(a=r.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),l):null!==(n=null===(s=r.options)||void 0===s?void 0:s.data)&&void 0!==n?n:{};return t(u,o)})),parseChildren:e=>{const[r,t]=e.children,a=Object.assign(Object.assign({},e),{property:r});return void 0!==t&&(a.fallback=t),a}},Be=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!0,type:["array","object"]},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean"},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object"}],We=R(Be),ze={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:Be},Je={propertyAliases:We,operatorData:ze,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i=!0,s="%",n={}]=yield Q([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],r);if(r.typeChecker(I(ze.parameters,{string:t,substitutions:a,trimWhiteSpace:i,substitutionCharacter:s,numberMapping:n})),Array.isArray(a)){const e="$"===s?"$":"%",r=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(t.match(r)||[]).sort(((e,r)=>Number(e.slice(1))-Number(r.slice(1)))),o=new Set(n),l=L(Array.from(o),a.map((e=>i?String(e).trim():e)));return t.split(r).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}return t.split(/(?<!\\)({{[A-z0-9_]+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ve(e,a,n);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{string:r,substitutions:t})}},Ve=(e,r,t)=>{var a,i;const s=e.replace(/{{(.+)}}/,"$1"),n=null!==(a=null==r?void 0:r[s])&&void 0!==a?a:"";if("number"!=typeof n)return null!==(i=null==r?void 0:r[s])&&void 0!==i?i:"";if(!(s in t))return n;const o=t[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(t[s]),u=l.find((e=>e.startsWith(">")));if(u){if(n>Number(u.slice(1)))return null==o?void 0:o[u]}const d=l.find((e=>e.startsWith("<")));if(d){if(n<Number(d.slice(1)))return null==o?void 0:o[d]}return o.other?o.other.replace("{}",String(n)):n},Xe=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array"}],Ye=R(Xe),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Xe},Ze={propertyAliases:Ye,operatorData:Ke,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);return r.typeChecker(I(Ke.parameters,{values:t})),t.length})),parseChildren:e=>{const[r]=e.children;return Object.assign(Object.assign({},e),{values:r})}},er=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string"},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean"},{name:"excludeTrailing",description:"If the input string ends in a delimiter, there will be an additional blank element if this value is false (default: true)",aliases:["removeTrailing","excludeTrailingDelimiter"],required:!1,type:"boolean"}],rr=R(er),tr={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:er},ar=" ",ir={propertyAliases:rr,operatorData:tr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,i;const[s,n,o,l]=yield Q([e.value,null!==(t=e.delimiter)&&void 0!==t?t:ar,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],r);r.typeChecker(I(tr.parameters,{value:s,delimiter:n,trimWhiteSpace:o,excludeTrailing:l}));let u=s.split(n);return o&&(u=u.map((e=>e.trim()))),l&&""===u[u.length-1]&&u.pop(),u})),parseChildren:e=>{const[r,t=ar]=e.children;return Object.assign(Object.assign({},e),{value:r,delimiter:t})}},sr=[{name:"query",description:"A SQL query string, with parameterised replacements (i.e. $1, $2, etc)",aliases:[],required:!0,type:"string"},{name:"values",description:"An array of values to replace in the SQL string parameters",aliases:["replacements"],required:!1,type:"array"},{name:"type",description:"Determines the shape of the resulting data (see documentation)",aliases:["queryType"],required:!1,type:{literal:["array","string","number"]}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],nr=R(sr),or={description:"Query a Postgres database using node-postgres",aliases:["pgSql","sql","postgres","pg","pgDb"],parameters:sr},lr=(e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i={text:e,values:r,rowMode:a?"array":""},s=yield t.query(i);if(null==s?void 0:s.error)throw new Error(s.error);switch(a){case"array":return s.rows.flat();case"string":return s.rows.flat().join(" ");case"number":{const e=s.rows.flat();return Number.isNaN(Number(e))?e:Number(e)}default:return s.rows}})),ur={propertyAliases:nr,operatorData:or,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u]=yield Q([e.query,e.type,e.values||[],e.useCache],r);if(r.typeChecker(I(or.parameters,{query:n,type:o,values:l,useCache:u})),!(null===(t=r.options)||void 0===t?void 0:t.pgConnection))throw new Error("No Postgres database connection provided");const d=null===(s=null!==(a=e.useCache)&&void 0!==a?a:r.options.useCache)||void 0===s||s;return r.cache.useCache(d,((e,t,a)=>i(void 0,void 0,void 0,(function*(){return yield lr(e,a,r.options.pgConnection,t)}))),n,o,l)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{query:r,values:t})}},dr=[{name:"query",description:"GraphQL query string",aliases:[],required:!0,type:"string"},{name:"url",description:"Endpoint for the GraphQL request (if not already provided in options)",aliases:["endpoint"],required:!1,type:["string","null"]},{name:"headers",description:"HTTP Headers (if not already provided in options)",aliases:[],required:!1,type:"object"},{name:"variables",description:"Values for the variables used in query (key-value pairs)",aliases:[],required:!1,type:"object"},{name:"returnNode",description:"Property path to extract from the query response",aliases:["outputNode","returnProperty"],required:!1,type:"string"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],cr=R(dr),pr={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:dr},hr={propertyAliases:cr,operatorData:pr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s,n,o,l;const[u,d,c,p,h,v]=yield Q([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],r),{url:y,headers:m}=d instanceof Object?d:{url:d,headers:null};r.typeChecker([...I(pr.parameters,{url:y,query:u,variables:c,returnNode:p,headers:h,useCache:v}),{name:"headers",value:m,expectedType:["object","null"]}]);const f=y&&"graphqlendpoint"!==y.toLowerCase()?y:"",g=null!==(s=null!==(a=null===(t=r.options.graphQLConnection)||void 0===t?void 0:t.endpoint)&&void 0!==a?a:r.options.baseEndpoint)&&void 0!==s?s:"",b=M(f)?f:H(g,f),T={query:u,variables:c},O=null===(n=null!=v?v:r.options.useCache)||void 0===n||n,C=yield r.cache.useCache(O,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield F({url:e,method:"post",data:r,headers:t});return _(i.data,a)}))),b,T,Object.assign(Object.assign(Object.assign(Object.assign({},null===(o=r.options.graphQLConnection)||void 0===o?void 0:o.headers),null===(l=r.options)||void 0===l?void 0:l.headers),m),h),p);return C})),parseChildren:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a="",i,...s]=yield Q(e.children,r),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=L(n,o),u=Object.assign(Object.assign({},e),{query:t,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},vr=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string"},{name:"returnProperty",description:"Property from request result",aliases:["outputProperty"],required:!1,type:"string"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object"},{name:"parameters",description:"Query parameters (key-value)",aliases:["queryParams","queryParameters","urlQueries"],required:!1,type:"object"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],yr=R(vr),mr={description:"HTTP GET Request",aliases:["get","api"],parameters:vr},fr=(e,r)=>i(void 0,void 0,void 0,(function*(){const[t="",a,...i]=yield Q(e.children,r),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=L(s,n),l=Object.assign(Object.assign({},e),{url:t,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gr=fr,br={propertyAliases:yr,operatorData:mr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u,d]=yield Q([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],r),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};r.typeChecker([...I(mr.parameters,{url:c,returnProperty:l,headers:u,parameters:o,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",v=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),p),u),y=null===(s=null!=d?d:r.options.useCache)||void 0===s||s,m=yield r.cache.useCache(y,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield F({url:e,params:r,headers:t});return _(i,a)}))),M(c)?c:H(h,c),o,v,l);return m})),parseChildren:fr},Tr=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string"},{name:"returnProperty",description:"Property path from request result",aliases:["outputProperty"],required:!1,type:"string"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object"},{name:"parameters",description:"JSON Body parameters (key-value)",aliases:["bodyJson","data"],required:!1,type:"object"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],Or=R(Tr),Cr={description:"HTTP POST Request",aliases:["post"],parameters:Tr},jr={propertyAliases:Or,operatorData:Cr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u,d]=yield Q([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],r),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};r.typeChecker([...I(Cr.parameters,{url:c,headers:u,data:o,returnProperty:l,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",v=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),p),u),y=null===(s=null!=d?d:r.options.useCache)||void 0===s||s;return yield r.cache.useCache(y,(()=>i(void 0,void 0,void 0,(function*(){const e=yield F({url:c,data:o,headers:u,method:"post"});return _(e,l)}))),M(c)?c:H(h,c),o,v,l)})),parseChildren:gr},qr=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array"}],Ar=R(qr),Er={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:qr},Sr={propertyAliases:Ar,operatorData:Er,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(I(Er.parameters,{properties:e.properties}));const t=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:t})=>{return a=[e,t],i(void 0,void 0,void 0,(function*(){const[e,t]=yield Q(a,r);return r.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,t]}));var a}));return Object.fromEntries(yield Promise.all(t))})),parseChildren:e=>{const r=e.children;if(r.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=r.filter(((e,r)=>r%2==0)),a=r.filter(((e,r)=>r%2==1)),i=t.map(((e,r)=>({key:e,value:a[r]})));return Object.assign(Object.assign({},e),{properties:i})}},Nr=[{name:"matchExpression",description:"Expression to match against",aliases:["match"],required:!0,type:["string","number","boolean"]},{name:"branches",description:"Object whose keys are compared against the match expression. The value of the matching key is returned",aliases:["arms","cases"],required:!1,type:["object","array"]}],Pr={propertyAliases:R(Nr),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Nr},evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const a=yield G(e.matchExpression,r);r.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(t=e.branches)&&void 0!==t?t:{},n=s(i)?yield G(i,r):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield G(n[a],r);if("fallback"in n)return yield G(n.fallback,r);if(a in e)return yield G(e[a],r);throw new Error(`No match found for ${a}`)})),parseChildren:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,...a]=e.children,i=k(yield Q(a,r));return Object.assign(Object.assign({},e),{matchExpression:t,branches:i})}))},xr=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string"},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],wr=R(xr),Ur={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:xr},Rr={propertyAliases:wr,operatorData:Ur,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield Q([e.functionPath,e.args,e.useCache],r);r.typeChecker(I(Ur.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=r.options,p=null!==(s=null!==(a=t(c,o,null))&&void 0!==a?a:t(d,o,null))&&void 0!==s?s:t(r.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:r.options.useCache)&&void 0!==n&&n;return yield r.cache.useCache(h,((e,...r)=>i(void 0,void 0,void 0,(function*(){return yield p(...r)}))),o,...l)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{functionPath:r,args:t})}},Ir=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any"}],Lr=R(Ir),kr={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Ir},Dr={propertyAliases:Lr,operatorData:kr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){return r.typeChecker(I(kr.parameters,{value:e.value})),yield G(e.value,r)})),parseChildren:e=>{const[...r]=e.children,t=1===(null==r?void 0:r.length)?r[0]:r;return Object.assign(Object.assign({},e),{value:t})}};var _r=Object.freeze({__proto__:null,AND:X,BUILD_OBJECT:Sr,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Rr,DIVIDE:qe,EQUAL:ie,GET:br,GRAPHQL:hr,GREATER_THAN:Ne,LESS_THAN:Ue,MATCH:Pr,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:$e,OR:ee,PASSTHRU:Dr,PG_SQL:ur,PLUS:pe,POST:jr,REGEX:He,SPLIT:ir,STRING_SUBSTITUTION:Je,SUBTRACT:me});class Mr{constructor(e){var r,t;this.useCache=(e,r,...t)=>i(this,void 0,void 0,(function*(){if(!e)return yield r(...t);const a=Hr(t),i=a in this.store,s=Date.now(),n=i&&s-this.store[a].timestamp>1e3*this.maxTime;if(i)return this.queue=this.queue.filter((e=>e!==a)),this.queue.unshift(a),this.store[a].timestamp=s,n&&(this.store[a].result=yield r(...t)),this.store[a].result;const o=yield r(...t);return this.store[a]={result:o,timestamp:s},this.queue.unshift(a),this.resizeCache(),o})),this.getMax=()=>this.maxSize,this.setMax=e=>{this.maxSize=e,this.resizeCache()},this.getMaxTime=()=>this.maxTime,this.setMaxTime=e=>{this.maxTime=e},this.getCache=()=>this.store,this.setCache=e=>this.store=e,this.resizeCache=()=>{if(this.queue.length>this.maxSize){this.queue.slice(this.maxSize).forEach((e=>delete this.store[e])),this.queue=this.queue.slice(0,this.maxSize)}},this.store={},this.queue=[],this.maxSize=null!==(r=null==e?void 0:e.maxSize)&&void 0!==r?r:50,this.maxTime=null!==(t=null==e?void 0:e.maxTime)&&void 0!==t?t:1800}}const Hr=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_");class Fr{constructor(e={}){var r,t;this.typeChecker=(...e)=>{const r=1===e.length&&Array.isArray(e[0])?e[0]:e,t=P(...r);if(!0!==t)throw new Error(t)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.11.4",this.options=Gr(e),this.operators=u(_r,null!==(t=null===(r=this.options)||void 0===r?void 0:r.excludeOperators)&&void 0!==t?t:[],T),this.operatorAliases=T,this.cache=new Mr({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime})}evaluate(e,r={}){return i(this,void 0,void 0,(function*(){const t=y(this.options,Gr(r));return t.maxCacheSize&&t.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(t.maxCacheSize),t.maxCacheTime&&t.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(t.maxCacheTime),yield G(e,{options:t,operators:r.excludeOperators?u(_r,r.excludeOperators,T):this.operators,operatorAliases:this.operatorAliases,typeChecker:t.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache})}))}getOptions(){return this.options}updateOptions(e){this.options=y(this.options,Gr(e)),this.options.excludeOperators&&(this.operators=u(_r,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(_r,this.options.excludeOperators,T):this.operators;return Object.entries(e).map((([e,r])=>Object.assign({operator:e},r.operatorData)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,r])=>Object.assign({name:e},null==r?void 0:r.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,r])=>({name:e,numRequiredArgs:r.length})))}}const Gr=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;exports.FigTreeEvaluator=Fr,exports.evaluateExpression=(e,r)=>new Fr(r).evaluate(e);
|
|
1
|
+
"use strict";var e=require("change-case"),r=require("axios"),t=require("object-property-extractor"),a=require("dequal/lite");function i(e,r,t,a){return new(t||(t=Promise))((function(i,s){function n(e){try{l(a.next(e))}catch(e){s(e)}}function o(e){try{l(a.throw(e))}catch(e){s(e)}}function l(e){var r;e.done?i(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(n,o)}l((a=a.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=r=>{const t=e.camelCase(r);return t||r},l=(e,r)=>r[o(e)],u=(e,r,t)=>{const a=Object.assign({},e);return r.forEach((e=>{t[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[t[o(e)]]})),a},d=(e,r=200)=>e.length<r?e:`${e.slice(0,r-2).trim()}...`,c=(e,r,t=!1)=>{if(void 0!==e)return e;if(t)return d(r);throw new Error(d(r))},p=(e,r)=>{const t=Object.entries(e).map((([e,t])=>[r(e),t]));return Object.fromEntries(t)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:r})=>{var t;return"string"==typeof e&&h(e)&&null!==(t=null==r?void 0:r[e])&&void 0!==t?t:e},y=(e,r)=>{const t=Object.assign(Object.assign({},e),r);return(e.data||r.data)&&(t.data=Object.assign(Object.assign({},e.data),r.data)),(e.functions||r.functions)&&(t.functions=Object.assign(Object.assign({},e.functions),r.functions)),(e.fragments||r.fragments)&&(t.fragments=Object.assign(Object.assign({},e.fragments),r.fragments)),(e.headers||r.headers)&&(t.headers=Object.assign(Object.assign({},e.headers),r.headers)),t},m={number:e=>g(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=e=>e.message,g=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const r=new RegExp(/-?\d*\.?\d+/gm),t=e.match(r);return t?Number(t[0]):0},b=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),T={and:"AND","&":"AND","&&":"AND",or:"OR","|":"OR","||":"OR","=":"EQUAL",eq:"EQUAL",equal:"EQUAL",equals:"EQUAL","!=":"NOT_EQUAL","!":"NOT_EQUAL",ne:"NOT_EQUAL",notEqual:"NOT_EQUAL","+":"PLUS",plus:"PLUS",add:"PLUS",concat:"PLUS",join:"PLUS",merge:"PLUS","-":"SUBTRACT",subtract:"SUBTRACT",minus:"SUBTRACT",takeaway:"SUBTRACT","*":"MULTIPLY",x:"MULTIPLY",multiply:"MULTIPLY",times:"MULTIPLY","/":"DIVIDE",divide:"DIVIDE","÷":"DIVIDE",">":"GREATER_THAN",greaterThan:"GREATER_THAN",higher:"GREATER_THAN",larger:"GREATER_THAN","<":"LESS_THAN",lessThan:"LESS_THAN",lower:"LESS_THAN",smaller:"LESS_THAN","?":"CONDITIONAL",conditional:"CONDITIONAL",ifThen:"CONDITIONAL",regex:"REGEX",patternMatch:"REGEX",regexp:"REGEX",matchPattern:"REGEX",dataProperties:"OBJECT_PROPERTIES",data:"OBJECT_PROPERTIES",getData:"OBJECT_PROPERTIES",objectProperties:"OBJECT_PROPERTIES",objProps:"OBJECT_PROPERTIES",getProperty:"OBJECT_PROPERTIES",getObjProp:"OBJECT_PROPERTIES",stringSubstitution:"STRING_SUBSTITUTION",substitute:"STRING_SUBSTITUTION",stringSub:"STRING_SUBSTITUTION",replace:"STRING_SUBSTITUTION",split:"SPLIT",arraySplit:"SPLIT",count:"COUNT",length:"COUNT",get:"GET",api:"GET",post:"POST",pgSql:"PG_SQL",sql:"PG_SQL",postgres:"PG_SQL",pg:"PG_SQL",pgDb:"PG_SQL",graphQl:"GRAPHQL",graphql:"GRAPHQL",gql:"GRAPHQL",buildObject:"BUILD_OBJECT",build:"BUILD_OBJECT",object:"BUILD_OBJECT",match:"MATCH",switch:"MATCH",customFunctions:"CUSTOM_FUNCTIONS",customFunction:"CUSTOM_FUNCTIONS",objectFunctions:"CUSTOM_FUNCTIONS",function:"CUSTOM_FUNCTIONS",functions:"CUSTOM_FUNCTIONS",runFunction:"CUSTOM_FUNCTIONS",_:"PASSTHRU",passThru:"PASSTHRU",passthru:"PASSTHRU",pass:"PASSTHRU",ignore:"PASSTHRU",coerce:"PASSTHRU",convert:"PASSTHRU"},O=T,C=/(\$[^()]+)\((.*)\)/,j=(e,r={},t=!0)=>t?"string"==typeof e?q(e,r):b(e)?A(e,r):e:e,q=(e,r)=>{const t=C.exec(e);if(!t)return e;const a=t[1].trim(),i=t[2].split(",").map((e=>j(e.trim(),r)));return E(a,i,r)},A=(e,r)=>{if(s(e)||n(e))return e;const t=Object.entries(e),a=t.filter((([e])=>h(e))),i=t.filter((([e])=>!h(e))),o=a.reduce(((e,[t,a])=>e=Object.assign(Object.assign({},e),E(t,a,r))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,r,t)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(r)?{operator:i,children:r}:b(r)&&!Object.keys(r).some((e=>h(e)))?Object.assign({operator:i},r):{operator:i,children:[r]}:a in t?{fragment:a,parameters:Object.assign({},r)}:{[e]:r}},S=e=>b(e)&&"literal"in e,N=({value:e,name:r,expectedType:t})=>{if(S(t)){const{literal:a}=t;return!!a.includes(e)||w(r,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(t))return!!t.some((t=>!0===N({value:e,name:r,expectedType:t})))||w(r,e,t.join("|"));return!!(0,x[t])(e)||w(r,e,t)},P=(...e)=>{const r=[];return e.forEach((e=>{const t=N(e);!0!==t&&r.push(t)})),!(r.length>0)||r.join("\n")},x={any:e=>void 0!==e,string:e=>"string"==typeof e,number:e=>"number"==typeof e,boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),null:e=>null===e,object:e=>b(e),undefined:e=>void 0===e},w=(e,r,t)=>void 0===r&&e?`- Missing required property "${e}" (type: ${t})`:void 0!==e?`- Property "${e}" (value: ${U(r)}) is not of type: ${t}`:`- ${U(r)} is not of type: ${t}`,U=e=>{const r=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return d(r,50)},R=e=>{const r={};return e.forEach((e=>{e.aliases.forEach((t=>r[t]=e.name))})),r},I=(e,r)=>e.map((({name:e,required:t,type:a})=>{if(S(a)){const i=[...a.literal];return t||i.push(void 0),{name:e,value:r[e],expectedType:{literal:i}}}const i=Array.isArray(a)?a:[a];t||i.push("undefined");const s=1===i.length?i[0]:i;return{name:e,value:r[e],expectedType:s}})),L=(e,r)=>{const t=e.map(((e,t)=>[e,r[t]]));return Object.fromEntries(t)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=e.filter(((e,r)=>r%2==0)),t=P(...r.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==t)throw new Error(t);const a=e.filter(((e,r)=>r%2==1)),i={};return r.forEach(((e,r)=>{i[e]=a[r]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(e,r,a=void 0)=>{const i=r?t(e,r,a):e;return Array.isArray(i)?i.map((e=>D(e))):r?null===i?null:D(i):i},M=e=>/^https?:\/\/.+/.test(e),H=(...e)=>e.reduce(((e,r,t)=>{const a="/"===r[0]?1:0,i="/"===r.slice(-1)?-1:void 0,s=r.slice(a,i);return""===s?e:e+(0===t?"":"/")+s}),""),F=({url:e,params:t={},data:a={},headers:s={},method:n="get"})=>i(void 0,void 0,void 0,(function*(){var i;try{return(yield r({method:n,url:e,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:t,data:a})).data}catch(e){if(r.isAxiosError(e)){if(!(null==e?void 0:e.response))throw new Error("Network Error");console.log(null===(i=e.response)||void 0===i?void 0:i.data)}throw e}})),G=(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,i,o;const{options:u,operators:d,operatorAliases:h}=r;let y=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const r=JSON.parse(e);return s(r)?r:e}catch(r){return e}})(e):e;y=j(y,null===(t=r.options)||void 0===t?void 0:t.fragments,!u.noShorthand),Array.isArray(y)&&(y=yield Q(y,r));const g=s(y),T=n(y);if(u.evaluateFullObject&&!g&&!T)return v(yield B(y,r),r);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(y)&&"value"in y?y.value:v(y,r);const{fallback:O}=y,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,t]=yield Q([y.fragment,y.parameters],r),a=j(null===(i=null==u?void 0:u.fragments)||void 0===i?void 0:i[e],u.fragments,!u.noShorthand);if(void 0===a)return c(yield G(O,r),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,r);y=Object.assign(Object.assign(Object.assign({},y),a),t),delete y.fragment}try{const e=l(y.operator,h);if(!e)return c(yield G(O,r),`Invalid operator: ${y.operator}`,C);if(!r.operators[e])return c(yield G(O,r),`Excluded operator: ${y.operator}`,C);const{propertyAliases:t,evaluate:a,parseChildren:i}=d[e];y=((e,r)=>p(r,(r=>r in e?e[r]:r)))(t,y);const s=yield $(y,r);T||Object.entries(s).forEach((([e,t])=>r.resolvedAliasNodes[e]=t));const n=T?Object.assign(Object.assign({},r),{resolvedAliasNodes:Object.assign(Object.assign({},r.resolvedAliasNodes),s)}):r;if("children"in y){if(Array.isArray(y.children)||(y.children=yield G(y.children,n)),!Array.isArray(y.children))return c(yield G(O,r),`Operator: ${e}\n- Property "children" is not of type: array`,C);y=yield i(y,n),delete y.children}let u;try{u=yield a(y,n)}catch(t){return c(yield G(y.fallback,r),`Operator: ${e}\n${f(t)}`,C)}const v=null!==(o=null==y?void 0:y.outputType)&&void 0!==o?o:null==y?void 0:y.type;if(!v)return u;const g=yield G(v,r);return g in m?m[g](u):c(yield G(O,r),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield G(O,r),f(e),C)}})),Q=(e,r)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>G(e,r)))):yield G(e,r)})),$=(e,r)=>i(void 0,void 0,void 0,(function*(){const t=Object.keys(e).filter(h);if(0===t.length)return{};const a=[];return t.forEach((t=>a.push(G(e[t],r)))),L(t,yield Promise.all(a))})),B=(e,r)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const t=[],a=[];Object.entries(e).forEach((([t,i])=>{h(t)&&(a.push(t,G(i,r)),delete e[t])}));const i=yield Promise.all(a);r.resolvedAliasNodes=Object.assign(Object.assign({},r.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{t.push(e,G(a,r))}));const s=yield Promise.all(t);return v(k(s),r)})),W=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array"}],z=R(W),J={description:"Logical AND",aliases:["and","&","&&"],parameters:W},V=e=>{const r=e.children;return Object.assign(Object.assign({},e),{values:r})},X={propertyAliases:z,operatorData:J,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);return r.typeChecker(I(J.parameters,{values:t})),t.reduce(((e,r)=>e&&!!r),!0)})),parseChildren:V},Y=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array"}],K=R(Y),Z={description:"Logical OR",aliases:["or","|","||"],parameters:Y},ee={propertyAliases:K,operatorData:Z,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);return r.typeChecker(I(Z.parameters,{values:t})),t.reduce(((e,r)=>e||!!r),!1)})),parseChildren:V},re=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array"},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value",aliases:[],required:!1,type:"boolean"}],te=R(re),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:re},ie={propertyAliases:te,operatorData:ae,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const[i,s]=yield Q([e.values,e.nullEqualsUndefined],r);r.typeChecker(I(ae.parameters,{values:i,nullEqualsUndefined:s}));return!(void 0!==s?s:void 0!==(null===(t=r.options)||void 0===t?void 0:t.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==i[0]&&void 0!==i[0]?i.every((e=>a.dequal(e,i[0]))):i.every((e=>null==e))})),parseChildren:V},se=[{name:"values",description:"Array of values to check for inequality",aliases:[],required:!0,type:"array"},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value",aliases:[],required:!1,type:"boolean"}],ne=R(se),oe={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:se},le={propertyAliases:ne,operatorData:oe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const[i,s]=yield Q([e.values,e.nullEqualsUndefined],r);r.typeChecker(I(oe.parameters,{values:i,nullEqualsUndefined:s}));return!(void 0!==s?s:void 0!==(null===(t=r.options)||void 0===t?void 0:t.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==i[0]&&void 0!==i[0]?i.some((e=>!a.dequal(e,i[0]))):i.some((e=>null===e&&void 0===e))})),parseChildren:V},ue=[{name:"values",description:"Array of values to check to add together",aliases:[],required:!0,type:"array"},{name:"type",description:"Data type to coerce input values to before addition",aliases:[],required:!1,type:{literal:["string","array","number","boolean","bool"]}}],de=R(ue),ce={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ue},pe={propertyAliases:de,operatorData:ce,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);return r.typeChecker(I(ce.parameters,{values:t,type:e.type})),0===t.length?t:"string"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),""):"array"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),[]):t.every((e=>"string"==typeof e||Array.isArray(e)))?t.reduce(((e,r)=>e.concat(r))):t.every((e=>b(e)))?t.reduce(((e,r)=>Object.assign(Object.assign({},e),r)),{}):t.reduce(((e,r)=>e+r))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array"},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number"},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number"}],ve=R(he),ye={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},me={propertyAliases:ve,operatorData:ye,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i]=yield Q([e.values,e.from,e.subtract],r);r.typeChecker(I(ye.parameters,{values:t,from:a,subtract:i}));const s=null!=t?t:[a,i].filter((e=>void 0!==e));if(s.length<2)throw new Error("- Not enough values provided");if(s.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return s[0]-s[1]})),parseChildren:V},fe=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array"}],ge=R(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);if(r.typeChecker(I(be.parameters,{values:t})),0===t.length)return 0;if(t.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return t.reduce(((e,r)=>e*r))})),parseChildren:V},Oe=[{name:"values",description:"Array of values - 1st element will be divided by the first",aliases:[],required:!1,type:"array"},{name:"dividend",description:"The number that will be divided",aliases:["divide"],required:!1,type:"number"},{name:"divisor",description:"The number that dividend will be divided by",aliases:["by","divideBy"],required:!1,type:"number"},{name:"output",description:"Whether to output a quotient, remainder or decimal",aliases:[],required:!1,type:{literal:["quotient","remainder"]}}],Ce=R(Oe),je={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},qe={propertyAliases:Ce,operatorData:je,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i,s]=yield Q([e.values,e.dividend,e.divisor,e.output],r);r.typeChecker(I(je.parameters,{values:t,dividend:a,divisor:i,output:s}));const n=null!=t?t:[a,i].filter((e=>void 0!==e));if(n.length<2)throw new Error("- Not enough values provided");if(n.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");if(0===n[1])throw new Error("Division by zero!");switch(s){case"quotient":return Math.floor(n[0]/n[1]);case"remainder":return n[0]%n[1];default:return n[0]/n[1]}})),parseChildren:V},Ae=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array"},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean"}],Ee=R(Ae),Se={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Ae},Ne={propertyAliases:Ee,operatorData:Se,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a=!0]=yield Q([e.values,e.strict],r);if(r.typeChecker(I(Se.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[i,s]=t;return i===s&&!a||i>s})),parseChildren:V},Pe=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array"},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean"}],xe=R(Pe),we={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ue={propertyAliases:xe,operatorData:we,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a=!0]=yield Q([e.values,e.strict],r);if(r.typeChecker(I(we.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[i,s]=t;return i===s&&!a||i<s})),parseChildren:V},Re=[{name:"condition",description:"The expression to check for truthiness",aliases:[],required:!0,type:"any"},{name:"valueIfTrue",description:"Value to return if condition is true",aliases:["ifTrue"],required:!0,type:"any"},{name:"valueIfFalse",description:"Value to return if condition is false",aliases:["ifFalse","ifNot"],required:!0,type:"any"}],Ie=R(Re),Le={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Re},ke={propertyAliases:Ie,operatorData:Le,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(I(Le.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield G(e.condition,r))?yield G(e.valueIfTrue,r):yield G(e.valueIfFalse,r)})),parseChildren:e=>{const[r,t,a]=e.children;return Object.assign(Object.assign({},e),{condition:r,valueIfTrue:t,valueIfFalse:a})}},De=[{name:"testString",description:"The string to test",aliases:["string","value"],required:!0,type:"string"},{name:"pattern",description:"The regular expression pattern",aliases:["regex","regexp","regExp","re"],required:!0,type:"string"}],_e=R(De),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},He={propertyAliases:_e,operatorData:Me,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a]=yield Q([e.testString,e.pattern],r);r.typeChecker(I(Me.parameters,{testString:t,pattern:a}));try{return new RegExp(a).test(t)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[r,t]=e.children;return Object.assign(Object.assign({},e),{testString:r,pattern:t})}},Fe=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object"}],Ge=R(Fe),Qe={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:Fe},$e={propertyAliases:Ge,operatorData:Qe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,i,s,n;const[o,l]=yield Q([e.property,e.additionalData],r);r.typeChecker(I(Qe.parameters,{property:o,additionalData:l}));const u=l?Object.assign(Object.assign({},null!==(i=null===(a=r.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),l):null!==(n=null===(s=r.options)||void 0===s?void 0:s.data)&&void 0!==n?n:{};return t(u,o)})),parseChildren:e=>{const[r,t]=e.children,a=Object.assign(Object.assign({},e),{property:r});return void 0!==t&&(a.fallback=t),a}},Be=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!0,type:["array","object"]},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean"},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object"}],We=R(Be),ze={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:Be},Je={propertyAliases:We,operatorData:ze,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i=!0,s="%",n={}]=yield Q([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],r);if(r.typeChecker(I(ze.parameters,{string:t,substitutions:a,trimWhiteSpace:i,substitutionCharacter:s,numberMapping:n})),Array.isArray(a)){const e="$"===s?"$":"%",r=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(t.match(r)||[]).sort(((e,r)=>Number(e.slice(1))-Number(r.slice(1)))),o=new Set(n),l=L(Array.from(o),a.map((e=>i?String(e).trim():e)));return t.split(r).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}return t.split(/(?<!\\)({{[A-z0-9_]+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ve(e,a,n);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{string:r,substitutions:t})}},Ve=(e,r,t)=>{var a,i;const s=e.replace(/{{(.+)}}/,"$1"),n=null!==(a=null==r?void 0:r[s])&&void 0!==a?a:"";if("number"!=typeof n)return null!==(i=null==r?void 0:r[s])&&void 0!==i?i:"";if(!(s in t))return n;const o=t[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(t[s]),u=l.find((e=>e.startsWith(">")));if(u){if(n>Number(u.slice(1)))return null==o?void 0:o[u]}const d=l.find((e=>e.startsWith("<")));if(d){if(n<Number(d.slice(1)))return null==o?void 0:o[d]}return o.other?o.other.replace("{}",String(n)):n},Xe=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array"}],Ye=R(Xe),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Xe},Ze={propertyAliases:Ye,operatorData:Ke,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield Q(e.values,r);return r.typeChecker(I(Ke.parameters,{values:t})),t.length})),parseChildren:e=>{const[r]=e.children;return Object.assign(Object.assign({},e),{values:r})}},er=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string"},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean"},{name:"excludeTrailing",description:"If the input string ends in a delimiter, there will be an additional blank element if this value is false (default: true)",aliases:["removeTrailing","excludeTrailingDelimiter"],required:!1,type:"boolean"}],rr=R(er),tr={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:er},ar=" ",ir={propertyAliases:rr,operatorData:tr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,i;const[s,n,o,l]=yield Q([e.value,null!==(t=e.delimiter)&&void 0!==t?t:ar,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],r);r.typeChecker(I(tr.parameters,{value:s,delimiter:n,trimWhiteSpace:o,excludeTrailing:l}));let u=s.split(n);return o&&(u=u.map((e=>e.trim()))),l&&""===u[u.length-1]&&u.pop(),u})),parseChildren:e=>{const[r,t=ar]=e.children;return Object.assign(Object.assign({},e),{value:r,delimiter:t})}},sr=[{name:"query",description:"A SQL query string, with parameterised replacements (i.e. $1, $2, etc)",aliases:[],required:!0,type:"string"},{name:"values",description:"An array of values to replace in the SQL string parameters",aliases:["replacements"],required:!1,type:"array"},{name:"type",description:"Determines the shape of the resulting data (see documentation)",aliases:["queryType"],required:!1,type:{literal:["array","string","number"]}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],nr=R(sr),or={description:"Query a Postgres database using node-postgres",aliases:["pgSql","sql","postgres","pg","pgDb"],parameters:sr},lr=(e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i={text:e,values:r,rowMode:a?"array":""},s=yield t.query(i);if(null==s?void 0:s.error)throw new Error(s.error);switch(a){case"array":return s.rows.flat();case"string":return s.rows.flat().join(" ");case"number":{const e=s.rows.flat();return Number.isNaN(Number(e))?e:Number(e)}default:return s.rows}})),ur={propertyAliases:nr,operatorData:or,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u]=yield Q([e.query,e.type,e.values||[],e.useCache],r);if(r.typeChecker(I(or.parameters,{query:n,type:o,values:l,useCache:u})),!(null===(t=r.options)||void 0===t?void 0:t.pgConnection))throw new Error("No Postgres database connection provided");const d=null===(s=null!==(a=e.useCache)&&void 0!==a?a:r.options.useCache)||void 0===s||s;return r.cache.useCache(d,((e,t,a)=>i(void 0,void 0,void 0,(function*(){return yield lr(e,a,r.options.pgConnection,t)}))),n,o,l)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{query:r,values:t})}},dr=[{name:"query",description:"GraphQL query string",aliases:[],required:!0,type:"string"},{name:"url",description:"Endpoint for the GraphQL request (if not already provided in options)",aliases:["endpoint"],required:!1,type:["string","null"]},{name:"headers",description:"HTTP Headers (if not already provided in options)",aliases:[],required:!1,type:"object"},{name:"variables",description:"Values for the variables used in query (key-value pairs)",aliases:[],required:!1,type:"object"},{name:"returnNode",description:"Property path to extract from the query response",aliases:["outputNode","returnProperty"],required:!1,type:"string"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],cr=R(dr),pr={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:dr},hr={propertyAliases:cr,operatorData:pr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s,n,o,l;const[u,d,c,p,h,v]=yield Q([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],r),{url:y,headers:m}=d instanceof Object?d:{url:d,headers:null};r.typeChecker([...I(pr.parameters,{url:y,query:u,variables:c,returnNode:p,headers:h,useCache:v}),{name:"headers",value:m,expectedType:["object","null"]}]);const f=y&&"graphqlendpoint"!==y.toLowerCase()?y:"",g=null!==(s=null!==(a=null===(t=r.options.graphQLConnection)||void 0===t?void 0:t.endpoint)&&void 0!==a?a:r.options.baseEndpoint)&&void 0!==s?s:"",b=M(f)?f:H(g,f),T={query:u,variables:c},O=null===(n=null!=v?v:r.options.useCache)||void 0===n||n,C=yield r.cache.useCache(O,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield F({url:e,method:"post",data:r,headers:t});return _(i.data,a)}))),b,T,Object.assign(Object.assign(Object.assign(Object.assign({},null===(o=r.options.graphQLConnection)||void 0===o?void 0:o.headers),null===(l=r.options)||void 0===l?void 0:l.headers),m),h),p);return C})),parseChildren:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a="",i,...s]=yield Q(e.children,r),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=L(n,o),u=Object.assign(Object.assign({},e),{query:t,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},vr=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string"},{name:"returnProperty",description:"Property from request result",aliases:["outputProperty"],required:!1,type:"string"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object"},{name:"parameters",description:"Query parameters (key-value)",aliases:["queryParams","queryParameters","urlQueries"],required:!1,type:"object"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],yr=R(vr),mr={description:"HTTP GET Request",aliases:["get","api"],parameters:vr},fr=(e,r)=>i(void 0,void 0,void 0,(function*(){const[t="",a,...i]=yield Q(e.children,r),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=L(s,n),l=Object.assign(Object.assign({},e),{url:t,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gr=fr,br={propertyAliases:yr,operatorData:mr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u,d]=yield Q([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],r),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};r.typeChecker([...I(mr.parameters,{url:c,returnProperty:l,headers:u,parameters:o,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",v=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),p),u),y=null===(s=null!=d?d:r.options.useCache)||void 0===s||s,m=yield r.cache.useCache(y,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield F({url:e,params:r,headers:t});return _(i,a)}))),M(c)?c:H(h,c),o,v,l);return m})),parseChildren:fr},Tr=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string"},{name:"returnProperty",description:"Property path from request result",aliases:["outputProperty"],required:!1,type:"string"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object"},{name:"parameters",description:"JSON Body parameters (key-value)",aliases:["bodyJson","data"],required:!1,type:"object"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],Or=R(Tr),Cr={description:"HTTP POST Request",aliases:["post"],parameters:Tr},jr={propertyAliases:Or,operatorData:Cr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u,d]=yield Q([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],r),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};r.typeChecker([...I(Cr.parameters,{url:c,headers:u,data:o,returnProperty:l,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",v=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),p),u),y=null===(s=null!=d?d:r.options.useCache)||void 0===s||s;return yield r.cache.useCache(y,(()=>i(void 0,void 0,void 0,(function*(){const e=yield F({url:c,data:o,headers:u,method:"post"});return _(e,l)}))),M(c)?c:H(h,c),o,v,l)})),parseChildren:gr},qr=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array"}],Ar=R(qr),Er={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:qr},Sr={propertyAliases:Ar,operatorData:Er,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(I(Er.parameters,{properties:e.properties}));const t=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:t})=>{return a=[e,t],i(void 0,void 0,void 0,(function*(){const[e,t]=yield Q(a,r);return r.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,t]}));var a}));return Object.fromEntries(yield Promise.all(t))})),parseChildren:e=>{const r=e.children;if(r.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=r.filter(((e,r)=>r%2==0)),a=r.filter(((e,r)=>r%2==1)),i=t.map(((e,r)=>({key:e,value:a[r]})));return Object.assign(Object.assign({},e),{properties:i})}},Nr=[{name:"matchExpression",description:"Expression to match against",aliases:["match"],required:!0,type:["string","number","boolean"]},{name:"branches",description:"Object whose keys are compared against the match expression. The value of the matching key is returned",aliases:["arms","cases"],required:!1,type:["object","array"]}],Pr={propertyAliases:R(Nr),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Nr},evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const a=yield G(e.matchExpression,r);r.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(t=e.branches)&&void 0!==t?t:{},n=s(i)?yield G(i,r):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield G(n[a],r);if("fallback"in n)return yield G(n.fallback,r);if(a in e)return yield G(e[a],r);throw new Error(`No match found for ${a}`)})),parseChildren:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,...a]=e.children,i=k(yield Q(a,r));return Object.assign(Object.assign({},e),{matchExpression:t,branches:i})}))},xr=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string"},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],wr=R(xr),Ur={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:xr},Rr={propertyAliases:wr,operatorData:Ur,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield Q([e.functionPath,e.args,e.useCache],r);r.typeChecker(I(Ur.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=r.options,p=null!==(s=null!==(a=t(c,o,null))&&void 0!==a?a:t(d,o,null))&&void 0!==s?s:t(r.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:r.options.useCache)&&void 0!==n&&n;return yield r.cache.useCache(h,((e,...r)=>i(void 0,void 0,void 0,(function*(){return yield p(...r)}))),o,...l)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{functionPath:r,args:t})}},Ir=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any"}],Lr=R(Ir),kr={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Ir},Dr={propertyAliases:Lr,operatorData:kr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){return r.typeChecker(I(kr.parameters,{value:e.value})),yield G(e.value,r)})),parseChildren:e=>{const[...r]=e.children,t=1===(null==r?void 0:r.length)?r[0]:r;return Object.assign(Object.assign({},e),{value:t})}};var _r=Object.freeze({__proto__:null,AND:X,BUILD_OBJECT:Sr,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Rr,DIVIDE:qe,EQUAL:ie,GET:br,GRAPHQL:hr,GREATER_THAN:Ne,LESS_THAN:Ue,MATCH:Pr,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:$e,OR:ee,PASSTHRU:Dr,PG_SQL:ur,PLUS:pe,POST:jr,REGEX:He,SPLIT:ir,STRING_SUBSTITUTION:Je,SUBTRACT:me});class Mr{constructor(e){var r,t;this.useCache=(e,r,...t)=>i(this,void 0,void 0,(function*(){if(!e)return yield r(...t);const a=Hr(t),i=a in this.store,s=Date.now(),n=i&&s-this.store[a].timestamp>1e3*this.maxTime;if(i)return this.queue=this.queue.filter((e=>e!==a)),this.queue.unshift(a),this.store[a].timestamp=s,n&&(this.store[a].result=yield r(...t)),this.store[a].result;const o=yield r(...t);return this.store[a]={result:o,timestamp:s},this.queue.unshift(a),this.resizeCache(),o})),this.getMax=()=>this.maxSize,this.setMax=e=>{this.maxSize=e,this.resizeCache()},this.getMaxTime=()=>this.maxTime,this.setMaxTime=e=>{this.maxTime=e},this.getCache=()=>this.store,this.setCache=e=>this.store=e,this.resizeCache=()=>{if(this.queue.length>this.maxSize){this.queue.slice(this.maxSize).forEach((e=>delete this.store[e])),this.queue=this.queue.slice(0,this.maxSize)}},this.store={},this.queue=[],this.maxSize=null!==(r=null==e?void 0:e.maxSize)&&void 0!==r?r:50,this.maxTime=null!==(t=null==e?void 0:e.maxTime)&&void 0!==t?t:1800}}const Hr=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_");class Fr{constructor(e={}){var r,t;this.typeChecker=(...e)=>{const r=1===e.length&&Array.isArray(e[0])?e[0]:e,t=P(...r);if(!0!==t)throw new Error(t)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.11.6",this.options=Gr(e),this.operators=u(_r,null!==(t=null===(r=this.options)||void 0===r?void 0:r.excludeOperators)&&void 0!==t?t:[],T),this.operatorAliases=T,this.cache=new Mr({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime})}evaluate(e,r={}){return i(this,void 0,void 0,(function*(){const t=y(this.options,Gr(r));return t.maxCacheSize&&t.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(t.maxCacheSize),t.maxCacheTime&&t.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(t.maxCacheTime),yield G(e,{options:t,operators:r.excludeOperators?u(_r,r.excludeOperators,T):this.operators,operatorAliases:this.operatorAliases,typeChecker:t.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache})}))}getOptions(){return this.options}updateOptions(e){this.options=y(this.options,Gr(e)),this.options.excludeOperators&&(this.operators=u(_r,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(_r,this.options.excludeOperators,T):this.operators;return Object.entries(e).map((([e,r])=>Object.assign({operator:e},r.operatorData)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,r])=>Object.assign({name:e},null==r?void 0:r.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,r])=>({name:e,numRequiredArgs:r.length})))}}const Gr=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;exports.FigTreeEvaluator=Fr,exports.evaluateExpression=(e,r)=>new Fr(r).evaluate(e);
|
package/build/index.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ interface FragmentNode {
|
|
|
65
65
|
parameters?: Record<string, EvaluatorNode>;
|
|
66
66
|
[key: string]: EvaluatorNode;
|
|
67
67
|
}
|
|
68
|
-
interface
|
|
68
|
+
interface FragmentData {
|
|
69
69
|
description?: string;
|
|
70
70
|
parameters?: Record<string, {
|
|
71
71
|
type: string | string[];
|
|
@@ -73,7 +73,7 @@ interface FragmentMetadata {
|
|
|
73
73
|
}>;
|
|
74
74
|
}
|
|
75
75
|
type Fragment = (EvaluatorNode & {
|
|
76
|
-
metadata?:
|
|
76
|
+
metadata?: FragmentData;
|
|
77
77
|
}) | null;
|
|
78
78
|
type EvaluatorOutput = string | boolean | number | object | null | undefined | Array<EvaluatorOutput>;
|
|
79
79
|
type EvaluatorNode = OperatorNode | FragmentNode | EvaluatorOutput;
|
|
@@ -89,9 +89,16 @@ interface OperatorData {
|
|
|
89
89
|
aliases: string[];
|
|
90
90
|
parameters: Parameter[];
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
type OperatorMetadata = OperatorData & {
|
|
93
93
|
operator: Operator;
|
|
94
|
-
}
|
|
94
|
+
};
|
|
95
|
+
type FragmentMetadata = FragmentData & {
|
|
96
|
+
name: string;
|
|
97
|
+
};
|
|
98
|
+
type CustomFunctionMetadata = {
|
|
99
|
+
name: string;
|
|
100
|
+
numRequiredArgs: number;
|
|
101
|
+
};
|
|
95
102
|
|
|
96
103
|
declare class FigTreeEvaluator {
|
|
97
104
|
private options;
|
|
@@ -106,16 +113,11 @@ declare class FigTreeEvaluator {
|
|
|
106
113
|
getCache: () => Store;
|
|
107
114
|
setCache: (cache: Store) => Store;
|
|
108
115
|
getOperators(): readonly OperatorMetadata[];
|
|
109
|
-
getFragments(): readonly
|
|
110
|
-
|
|
111
|
-
})[];
|
|
112
|
-
getCustomFunctions(): readonly {
|
|
113
|
-
name: string;
|
|
114
|
-
numRequiredArgs: number;
|
|
115
|
-
}[];
|
|
116
|
+
getFragments(): readonly FragmentMetadata[];
|
|
117
|
+
getCustomFunctions(): readonly CustomFunctionMetadata[];
|
|
116
118
|
getVersion: () => string;
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
declare const evaluateExpression: (expression: EvaluatorNode, options?: FigTreeOptions) => Promise<EvaluatorOutput>;
|
|
120
122
|
|
|
121
|
-
export { EvaluatorNode, EvaluatorOutput, FigTreeEvaluator, FigTreeOptions, Operator, evaluateExpression };
|
|
123
|
+
export { CustomFunctionMetadata, EvaluatorNode, EvaluatorOutput, FigTreeEvaluator, FigTreeOptions, FragmentMetadata, Operator, OperatorAlias, OperatorMetadata, evaluateExpression };
|
package/build/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{camelCase as e}from"change-case";import r from"axios";import t from"object-property-extractor";import{dequal as a}from"dequal/lite";function i(e,r,t,a){return new(t||(t=Promise))((function(i,s){function n(e){try{l(a.next(e))}catch(e){s(e)}}function o(e){try{l(a.throw(e))}catch(e){s(e)}}function l(e){var r;e.done?i(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(n,o)}l((a=a.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=r=>{const t=e(r);return t||r},l=(e,r)=>r[o(e)],u=(e,r,t)=>{const a=Object.assign({},e);return r.forEach((e=>{t[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[t[o(e)]]})),a},d=(e,r=200)=>e.length<r?e:`${e.slice(0,r-2).trim()}...`,c=(e,r,t=!1)=>{if(void 0!==e)return e;if(t)return d(r);throw new Error(d(r))},p=(e,r)=>{const t=Object.entries(e).map((([e,t])=>[r(e),t]));return Object.fromEntries(t)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:r})=>{var t;return"string"==typeof e&&h(e)&&null!==(t=null==r?void 0:r[e])&&void 0!==t?t:e},m=(e,r)=>{const t=Object.assign(Object.assign({},e),r);return(e.data||r.data)&&(t.data=Object.assign(Object.assign({},e.data),r.data)),(e.functions||r.functions)&&(t.functions=Object.assign(Object.assign({},e.functions),r.functions)),(e.fragments||r.fragments)&&(t.fragments=Object.assign(Object.assign({},e.fragments),r.fragments)),(e.headers||r.headers)&&(t.headers=Object.assign(Object.assign({},e.headers),r.headers)),t},y={number:e=>g(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=e=>e.message,g=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const r=new RegExp(/-?\d*\.?\d+/gm),t=e.match(r);return t?Number(t[0]):0},b=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),T={and:"AND","&":"AND","&&":"AND",or:"OR","|":"OR","||":"OR","=":"EQUAL",eq:"EQUAL",equal:"EQUAL",equals:"EQUAL","!=":"NOT_EQUAL","!":"NOT_EQUAL",ne:"NOT_EQUAL",notEqual:"NOT_EQUAL","+":"PLUS",plus:"PLUS",add:"PLUS",concat:"PLUS",join:"PLUS",merge:"PLUS","-":"SUBTRACT",subtract:"SUBTRACT",minus:"SUBTRACT",takeaway:"SUBTRACT","*":"MULTIPLY",x:"MULTIPLY",multiply:"MULTIPLY",times:"MULTIPLY","/":"DIVIDE",divide:"DIVIDE","÷":"DIVIDE",">":"GREATER_THAN",greaterThan:"GREATER_THAN",higher:"GREATER_THAN",larger:"GREATER_THAN","<":"LESS_THAN",lessThan:"LESS_THAN",lower:"LESS_THAN",smaller:"LESS_THAN","?":"CONDITIONAL",conditional:"CONDITIONAL",ifThen:"CONDITIONAL",regex:"REGEX",patternMatch:"REGEX",regexp:"REGEX",matchPattern:"REGEX",dataProperties:"OBJECT_PROPERTIES",data:"OBJECT_PROPERTIES",getData:"OBJECT_PROPERTIES",objectProperties:"OBJECT_PROPERTIES",objProps:"OBJECT_PROPERTIES",getProperty:"OBJECT_PROPERTIES",getObjProp:"OBJECT_PROPERTIES",stringSubstitution:"STRING_SUBSTITUTION",substitute:"STRING_SUBSTITUTION",stringSub:"STRING_SUBSTITUTION",replace:"STRING_SUBSTITUTION",split:"SPLIT",arraySplit:"SPLIT",count:"COUNT",length:"COUNT",get:"GET",api:"GET",post:"POST",pgSql:"PG_SQL",sql:"PG_SQL",postgres:"PG_SQL",pg:"PG_SQL",pgDb:"PG_SQL",graphQl:"GRAPHQL",graphql:"GRAPHQL",gql:"GRAPHQL",buildObject:"BUILD_OBJECT",build:"BUILD_OBJECT",object:"BUILD_OBJECT",match:"MATCH",switch:"MATCH",customFunctions:"CUSTOM_FUNCTIONS",customFunction:"CUSTOM_FUNCTIONS",objectFunctions:"CUSTOM_FUNCTIONS",function:"CUSTOM_FUNCTIONS",functions:"CUSTOM_FUNCTIONS",runFunction:"CUSTOM_FUNCTIONS",_:"PASSTHRU",passThru:"PASSTHRU",passthru:"PASSTHRU",pass:"PASSTHRU",ignore:"PASSTHRU",coerce:"PASSTHRU",convert:"PASSTHRU"},O=T,C=/(\$[^()]+)\((.*)\)/,j=(e,r={},t=!0)=>t?"string"==typeof e?A(e,r):b(e)?q(e,r):e:e,A=(e,r)=>{const t=C.exec(e);if(!t)return e;const a=t[1].trim(),i=t[2].split(",").map((e=>j(e.trim(),r)));return E(a,i,r)},q=(e,r)=>{if(s(e)||n(e))return e;const t=Object.entries(e),a=t.filter((([e])=>h(e))),i=t.filter((([e])=>!h(e))),o=a.reduce(((e,[t,a])=>e=Object.assign(Object.assign({},e),E(t,a,r))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,r,t)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(r)?{operator:i,children:r}:b(r)&&!Object.keys(r).some((e=>h(e)))?Object.assign({operator:i},r):{operator:i,children:[r]}:a in t?{fragment:a,parameters:Object.assign({},r)}:{[e]:r}},S=e=>b(e)&&"literal"in e,N=({value:e,name:r,expectedType:t})=>{if(S(t)){const{literal:a}=t;return!!a.includes(e)||w(r,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(t))return!!t.some((t=>!0===N({value:e,name:r,expectedType:t})))||w(r,e,t.join("|"));return!!(0,x[t])(e)||w(r,e,t)},P=(...e)=>{const r=[];return e.forEach((e=>{const t=N(e);!0!==t&&r.push(t)})),!(r.length>0)||r.join("\n")},x={any:e=>void 0!==e,string:e=>"string"==typeof e,number:e=>"number"==typeof e,boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),null:e=>null===e,object:e=>b(e),undefined:e=>void 0===e},w=(e,r,t)=>void 0===r&&e?`- Missing required property "${e}" (type: ${t})`:void 0!==e?`- Property "${e}" (value: ${U(r)}) is not of type: ${t}`:`- ${U(r)} is not of type: ${t}`,U=e=>{const r=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return d(r,50)},R=e=>{const r={};return e.forEach((e=>{e.aliases.forEach((t=>r[t]=e.name))})),r},I=(e,r)=>e.map((({name:e,required:t,type:a})=>{if(S(a)){const i=[...a.literal];return t||i.push(void 0),{name:e,value:r[e],expectedType:{literal:i}}}const i=Array.isArray(a)?a:[a];t||i.push("undefined");const s=1===i.length?i[0]:i;return{name:e,value:r[e],expectedType:s}})),L=(e,r)=>{const t=e.map(((e,t)=>[e,r[t]]));return Object.fromEntries(t)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=e.filter(((e,r)=>r%2==0)),t=P(...r.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==t)throw new Error(t);const a=e.filter(((e,r)=>r%2==1)),i={};return r.forEach(((e,r)=>{i[e]=a[r]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(e,r,a=void 0)=>{const i=r?t(e,r,a):e;return Array.isArray(i)?i.map((e=>D(e))):r?null===i?null:D(i):i},M=e=>/^https?:\/\/.+/.test(e),H=(...e)=>e.reduce(((e,r,t)=>{const a="/"===r[0]?1:0,i="/"===r.slice(-1)?-1:void 0,s=r.slice(a,i);return""===s?e:e+(0===t?"":"/")+s}),""),G=({url:e,params:t={},data:a={},headers:s={},method:n="get"})=>i(void 0,void 0,void 0,(function*(){var i;try{return(yield r({method:n,url:e,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:t,data:a})).data}catch(e){if(r.isAxiosError(e)){if(!(null==e?void 0:e.response))throw new Error("Network Error");console.log(null===(i=e.response)||void 0===i?void 0:i.data)}throw e}})),Q=(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,i,o;const{options:u,operators:d,operatorAliases:h}=r;let m=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const r=JSON.parse(e);return s(r)?r:e}catch(r){return e}})(e):e;m=j(m,null===(t=r.options)||void 0===t?void 0:t.fragments,!u.noShorthand),Array.isArray(m)&&(m=yield $(m,r));const g=s(m),T=n(m);if(u.evaluateFullObject&&!g&&!T)return v(yield F(m,r),r);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(m)&&"value"in m?m.value:v(m,r);const{fallback:O}=m,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,t]=yield $([m.fragment,m.parameters],r),a=j(null===(i=null==u?void 0:u.fragments)||void 0===i?void 0:i[e],u.fragments,!u.noShorthand);if(void 0===a)return c(yield Q(O,r),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,r);m=Object.assign(Object.assign(Object.assign({},m),a),t),delete m.fragment}try{const e=l(m.operator,h);if(!e)return c(yield Q(O,r),`Invalid operator: ${m.operator}`,C);if(!r.operators[e])return c(yield Q(O,r),`Excluded operator: ${m.operator}`,C);const{propertyAliases:t,evaluate:a,parseChildren:i}=d[e];m=((e,r)=>p(r,(r=>r in e?e[r]:r)))(t,m);const s=yield B(m,r);T||Object.entries(s).forEach((([e,t])=>r.resolvedAliasNodes[e]=t));const n=T?Object.assign(Object.assign({},r),{resolvedAliasNodes:Object.assign(Object.assign({},r.resolvedAliasNodes),s)}):r;if("children"in m){if(Array.isArray(m.children)||(m.children=yield Q(m.children,n)),!Array.isArray(m.children))return c(yield Q(O,r),`Operator: ${e}\n- Property "children" is not of type: array`,C);m=yield i(m,n),delete m.children}let u;try{u=yield a(m,n)}catch(t){return c(yield Q(m.fallback,r),`Operator: ${e}\n${f(t)}`,C)}const v=null!==(o=null==m?void 0:m.outputType)&&void 0!==o?o:null==m?void 0:m.type;if(!v)return u;const g=yield Q(v,r);return g in y?y[g](u):c(yield Q(O,r),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield Q(O,r),f(e),C)}})),$=(e,r)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>Q(e,r)))):yield Q(e,r)})),B=(e,r)=>i(void 0,void 0,void 0,(function*(){const t=Object.keys(e).filter(h);if(0===t.length)return{};const a=[];return t.forEach((t=>a.push(Q(e[t],r)))),L(t,yield Promise.all(a))})),F=(e,r)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const t=[],a=[];Object.entries(e).forEach((([t,i])=>{h(t)&&(a.push(t,Q(i,r)),delete e[t])}));const i=yield Promise.all(a);r.resolvedAliasNodes=Object.assign(Object.assign({},r.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{t.push(e,Q(a,r))}));const s=yield Promise.all(t);return v(k(s),r)})),W=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array"}],z=R(W),J={description:"Logical AND",aliases:["and","&","&&"],parameters:W},V=e=>{const r=e.children;return Object.assign(Object.assign({},e),{values:r})},X={propertyAliases:z,operatorData:J,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(I(J.parameters,{values:t})),t.reduce(((e,r)=>e&&!!r),!0)})),parseChildren:V},Y=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array"}],K=R(Y),Z={description:"Logical OR",aliases:["or","|","||"],parameters:Y},ee={propertyAliases:K,operatorData:Z,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(I(Z.parameters,{values:t})),t.reduce(((e,r)=>e||!!r),!1)})),parseChildren:V},re=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array"},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value",aliases:[],required:!1,type:"boolean"}],te=R(re),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:re},ie={propertyAliases:te,operatorData:ae,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const[i,s]=yield $([e.values,e.nullEqualsUndefined],r);r.typeChecker(I(ae.parameters,{values:i,nullEqualsUndefined:s}));return!(void 0!==s?s:void 0!==(null===(t=r.options)||void 0===t?void 0:t.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==i[0]&&void 0!==i[0]?i.every((e=>a(e,i[0]))):i.every((e=>null==e))})),parseChildren:V},se=[{name:"values",description:"Array of values to check for inequality",aliases:[],required:!0,type:"array"},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value",aliases:[],required:!1,type:"boolean"}],ne=R(se),oe={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:se},le={propertyAliases:ne,operatorData:oe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const[i,s]=yield $([e.values,e.nullEqualsUndefined],r);r.typeChecker(I(oe.parameters,{values:i,nullEqualsUndefined:s}));return!(void 0!==s?s:void 0!==(null===(t=r.options)||void 0===t?void 0:t.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==i[0]&&void 0!==i[0]?i.some((e=>!a(e,i[0]))):i.some((e=>null===e&&void 0===e))})),parseChildren:V},ue=[{name:"values",description:"Array of values to check to add together",aliases:[],required:!0,type:"array"},{name:"type",description:"Data type to coerce input values to before addition",aliases:[],required:!1,type:{literal:["string","array","number","boolean","bool"]}}],de=R(ue),ce={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ue},pe={propertyAliases:de,operatorData:ce,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(I(ce.parameters,{values:t,type:e.type})),0===t.length?t:"string"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),""):"array"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),[]):t.every((e=>"string"==typeof e||Array.isArray(e)))?t.reduce(((e,r)=>e.concat(r))):t.every((e=>b(e)))?t.reduce(((e,r)=>Object.assign(Object.assign({},e),r)),{}):t.reduce(((e,r)=>e+r))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array"},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number"},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number"}],ve=R(he),me={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},ye={propertyAliases:ve,operatorData:me,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i]=yield $([e.values,e.from,e.subtract],r);r.typeChecker(I(me.parameters,{values:t,from:a,subtract:i}));const s=null!=t?t:[a,i].filter((e=>void 0!==e));if(s.length<2)throw new Error("- Not enough values provided");if(s.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return s[0]-s[1]})),parseChildren:V},fe=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array"}],ge=R(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);if(r.typeChecker(I(be.parameters,{values:t})),0===t.length)return 0;if(t.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return t.reduce(((e,r)=>e*r))})),parseChildren:V},Oe=[{name:"values",description:"Array of values - 1st element will be divided by the first",aliases:[],required:!1,type:"array"},{name:"dividend",description:"The number that will be divided",aliases:["divide"],required:!1,type:"number"},{name:"divisor",description:"The number that dividend will be divided by",aliases:["by","divideBy"],required:!1,type:"number"},{name:"output",description:"Whether to output a quotient, remainder or decimal",aliases:[],required:!1,type:{literal:["quotient","remainder"]}}],Ce=R(Oe),je={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},Ae={propertyAliases:Ce,operatorData:je,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i,s]=yield $([e.values,e.dividend,e.divisor,e.output],r);r.typeChecker(I(je.parameters,{values:t,dividend:a,divisor:i,output:s}));const n=null!=t?t:[a,i].filter((e=>void 0!==e));if(n.length<2)throw new Error("- Not enough values provided");if(n.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");if(0===n[1])throw new Error("Division by zero!");switch(s){case"quotient":return Math.floor(n[0]/n[1]);case"remainder":return n[0]%n[1];default:return n[0]/n[1]}})),parseChildren:V},qe=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array"},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean"}],Ee=R(qe),Se={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:qe},Ne={propertyAliases:Ee,operatorData:Se,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a=!0]=yield $([e.values,e.strict],r);if(r.typeChecker(I(Se.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[i,s]=t;return i===s&&!a||i>s})),parseChildren:V},Pe=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array"},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean"}],xe=R(Pe),we={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ue={propertyAliases:xe,operatorData:we,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a=!0]=yield $([e.values,e.strict],r);if(r.typeChecker(I(we.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[i,s]=t;return i===s&&!a||i<s})),parseChildren:V},Re=[{name:"condition",description:"The expression to check for truthiness",aliases:[],required:!0,type:"any"},{name:"valueIfTrue",description:"Value to return if condition is true",aliases:["ifTrue"],required:!0,type:"any"},{name:"valueIfFalse",description:"Value to return if condition is false",aliases:["ifFalse","ifNot"],required:!0,type:"any"}],Ie=R(Re),Le={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Re},ke={propertyAliases:Ie,operatorData:Le,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(I(Le.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield Q(e.condition,r))?yield Q(e.valueIfTrue,r):yield Q(e.valueIfFalse,r)})),parseChildren:e=>{const[r,t,a]=e.children;return Object.assign(Object.assign({},e),{condition:r,valueIfTrue:t,valueIfFalse:a})}},De=[{name:"testString",description:"The string to test",aliases:["string","value"],required:!0,type:"string"},{name:"pattern",description:"The regular expression pattern",aliases:["regex","regexp","regExp","re"],required:!0,type:"string"}],_e=R(De),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},He={propertyAliases:_e,operatorData:Me,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a]=yield $([e.testString,e.pattern],r);r.typeChecker(I(Me.parameters,{testString:t,pattern:a}));try{return new RegExp(a).test(t)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[r,t]=e.children;return Object.assign(Object.assign({},e),{testString:r,pattern:t})}},Ge=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object"}],Qe=R(Ge),$e={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:Ge},Be={propertyAliases:Qe,operatorData:$e,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,i,s,n;const[o,l]=yield $([e.property,e.additionalData],r);r.typeChecker(I($e.parameters,{property:o,additionalData:l}));const u=l?Object.assign(Object.assign({},null!==(i=null===(a=r.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),l):null!==(n=null===(s=r.options)||void 0===s?void 0:s.data)&&void 0!==n?n:{};return t(u,o)})),parseChildren:e=>{const[r,t]=e.children,a=Object.assign(Object.assign({},e),{property:r});return void 0!==t&&(a.fallback=t),a}},Fe=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!0,type:["array","object"]},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean"},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object"}],We=R(Fe),ze={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:Fe},Je={propertyAliases:We,operatorData:ze,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i=!0,s="%",n={}]=yield $([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],r);if(r.typeChecker(I(ze.parameters,{string:t,substitutions:a,trimWhiteSpace:i,substitutionCharacter:s,numberMapping:n})),Array.isArray(a)){const e="$"===s?"$":"%",r=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(t.match(r)||[]).sort(((e,r)=>Number(e.slice(1))-Number(r.slice(1)))),o=new Set(n),l=L(Array.from(o),a.map((e=>i?String(e).trim():e)));return t.split(r).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}return t.split(/(?<!\\)({{[A-z0-9_]+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ve(e,a,n);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{string:r,substitutions:t})}},Ve=(e,r,t)=>{var a,i;const s=e.replace(/{{(.+)}}/,"$1"),n=null!==(a=null==r?void 0:r[s])&&void 0!==a?a:"";if("number"!=typeof n)return null!==(i=null==r?void 0:r[s])&&void 0!==i?i:"";if(!(s in t))return n;const o=t[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(t[s]),u=l.find((e=>e.startsWith(">")));if(u){if(n>Number(u.slice(1)))return null==o?void 0:o[u]}const d=l.find((e=>e.startsWith("<")));if(d){if(n<Number(d.slice(1)))return null==o?void 0:o[d]}return o.other?o.other.replace("{}",String(n)):n},Xe=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array"}],Ye=R(Xe),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Xe},Ze={propertyAliases:Ye,operatorData:Ke,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(I(Ke.parameters,{values:t})),t.length})),parseChildren:e=>{const[r]=e.children;return Object.assign(Object.assign({},e),{values:r})}},er=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string"},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean"},{name:"excludeTrailing",description:"If the input string ends in a delimiter, there will be an additional blank element if this value is false (default: true)",aliases:["removeTrailing","excludeTrailingDelimiter"],required:!1,type:"boolean"}],rr=R(er),tr={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:er},ar=" ",ir={propertyAliases:rr,operatorData:tr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,i;const[s,n,o,l]=yield $([e.value,null!==(t=e.delimiter)&&void 0!==t?t:ar,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],r);r.typeChecker(I(tr.parameters,{value:s,delimiter:n,trimWhiteSpace:o,excludeTrailing:l}));let u=s.split(n);return o&&(u=u.map((e=>e.trim()))),l&&""===u[u.length-1]&&u.pop(),u})),parseChildren:e=>{const[r,t=ar]=e.children;return Object.assign(Object.assign({},e),{value:r,delimiter:t})}},sr=[{name:"query",description:"A SQL query string, with parameterised replacements (i.e. $1, $2, etc)",aliases:[],required:!0,type:"string"},{name:"values",description:"An array of values to replace in the SQL string parameters",aliases:["replacements"],required:!1,type:"array"},{name:"type",description:"Determines the shape of the resulting data (see documentation)",aliases:["queryType"],required:!1,type:{literal:["array","string","number"]}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],nr=R(sr),or={description:"Query a Postgres database using node-postgres",aliases:["pgSql","sql","postgres","pg","pgDb"],parameters:sr},lr=(e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i={text:e,values:r,rowMode:a?"array":""},s=yield t.query(i);if(null==s?void 0:s.error)throw new Error(s.error);switch(a){case"array":return s.rows.flat();case"string":return s.rows.flat().join(" ");case"number":{const e=s.rows.flat();return Number.isNaN(Number(e))?e:Number(e)}default:return s.rows}})),ur={propertyAliases:nr,operatorData:or,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u]=yield $([e.query,e.type,e.values||[],e.useCache],r);if(r.typeChecker(I(or.parameters,{query:n,type:o,values:l,useCache:u})),!(null===(t=r.options)||void 0===t?void 0:t.pgConnection))throw new Error("No Postgres database connection provided");const d=null===(s=null!==(a=e.useCache)&&void 0!==a?a:r.options.useCache)||void 0===s||s;return r.cache.useCache(d,((e,t,a)=>i(void 0,void 0,void 0,(function*(){return yield lr(e,a,r.options.pgConnection,t)}))),n,o,l)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{query:r,values:t})}},dr=[{name:"query",description:"GraphQL query string",aliases:[],required:!0,type:"string"},{name:"url",description:"Endpoint for the GraphQL request (if not already provided in options)",aliases:["endpoint"],required:!1,type:["string","null"]},{name:"headers",description:"HTTP Headers (if not already provided in options)",aliases:[],required:!1,type:"object"},{name:"variables",description:"Values for the variables used in query (key-value pairs)",aliases:[],required:!1,type:"object"},{name:"returnNode",description:"Property path to extract from the query response",aliases:["outputNode","returnProperty"],required:!1,type:"string"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],cr=R(dr),pr={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:dr},hr={propertyAliases:cr,operatorData:pr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s,n,o,l;const[u,d,c,p,h,v]=yield $([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],r),{url:m,headers:y}=d instanceof Object?d:{url:d,headers:null};r.typeChecker([...I(pr.parameters,{url:m,query:u,variables:c,returnNode:p,headers:h,useCache:v}),{name:"headers",value:y,expectedType:["object","null"]}]);const f=m&&"graphqlendpoint"!==m.toLowerCase()?m:"",g=null!==(s=null!==(a=null===(t=r.options.graphQLConnection)||void 0===t?void 0:t.endpoint)&&void 0!==a?a:r.options.baseEndpoint)&&void 0!==s?s:"",b=M(f)?f:H(g,f),T={query:u,variables:c},O=null===(n=null!=v?v:r.options.useCache)||void 0===n||n,C=yield r.cache.useCache(O,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield G({url:e,method:"post",data:r,headers:t});return _(i.data,a)}))),b,T,Object.assign(Object.assign(Object.assign(Object.assign({},null===(o=r.options.graphQLConnection)||void 0===o?void 0:o.headers),null===(l=r.options)||void 0===l?void 0:l.headers),y),h),p);return C})),parseChildren:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a="",i,...s]=yield $(e.children,r),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=L(n,o),u=Object.assign(Object.assign({},e),{query:t,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},vr=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string"},{name:"returnProperty",description:"Property from request result",aliases:["outputProperty"],required:!1,type:"string"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object"},{name:"parameters",description:"Query parameters (key-value)",aliases:["queryParams","queryParameters","urlQueries"],required:!1,type:"object"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],mr=R(vr),yr={description:"HTTP GET Request",aliases:["get","api"],parameters:vr},fr=(e,r)=>i(void 0,void 0,void 0,(function*(){const[t="",a,...i]=yield $(e.children,r),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=L(s,n),l=Object.assign(Object.assign({},e),{url:t,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gr=fr,br={propertyAliases:mr,operatorData:yr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u,d]=yield $([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],r),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};r.typeChecker([...I(yr.parameters,{url:c,returnProperty:l,headers:u,parameters:o,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",v=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),p),u),m=null===(s=null!=d?d:r.options.useCache)||void 0===s||s,y=yield r.cache.useCache(m,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield G({url:e,params:r,headers:t});return _(i,a)}))),M(c)?c:H(h,c),o,v,l);return y})),parseChildren:fr},Tr=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string"},{name:"returnProperty",description:"Property path from request result",aliases:["outputProperty"],required:!1,type:"string"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object"},{name:"parameters",description:"JSON Body parameters (key-value)",aliases:["bodyJson","data"],required:!1,type:"object"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],Or=R(Tr),Cr={description:"HTTP POST Request",aliases:["post"],parameters:Tr},jr={propertyAliases:Or,operatorData:Cr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u,d]=yield $([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],r),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};r.typeChecker([...I(Cr.parameters,{url:c,headers:u,data:o,returnProperty:l,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",v=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),p),u),m=null===(s=null!=d?d:r.options.useCache)||void 0===s||s;return yield r.cache.useCache(m,(()=>i(void 0,void 0,void 0,(function*(){const e=yield G({url:c,data:o,headers:u,method:"post"});return _(e,l)}))),M(c)?c:H(h,c),o,v,l)})),parseChildren:gr},Ar=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array"}],qr=R(Ar),Er={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:Ar},Sr={propertyAliases:qr,operatorData:Er,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(I(Er.parameters,{properties:e.properties}));const t=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:t})=>{return a=[e,t],i(void 0,void 0,void 0,(function*(){const[e,t]=yield $(a,r);return r.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,t]}));var a}));return Object.fromEntries(yield Promise.all(t))})),parseChildren:e=>{const r=e.children;if(r.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=r.filter(((e,r)=>r%2==0)),a=r.filter(((e,r)=>r%2==1)),i=t.map(((e,r)=>({key:e,value:a[r]})));return Object.assign(Object.assign({},e),{properties:i})}},Nr=[{name:"matchExpression",description:"Expression to match against",aliases:["match"],required:!0,type:["string","number","boolean"]},{name:"branches",description:"Object whose keys are compared against the match expression. The value of the matching key is returned",aliases:["arms","cases"],required:!1,type:["object","array"]}],Pr={propertyAliases:R(Nr),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Nr},evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const a=yield Q(e.matchExpression,r);r.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(t=e.branches)&&void 0!==t?t:{},n=s(i)?yield Q(i,r):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield Q(n[a],r);if("fallback"in n)return yield Q(n.fallback,r);if(a in e)return yield Q(e[a],r);throw new Error(`No match found for ${a}`)})),parseChildren:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,...a]=e.children,i=k(yield $(a,r));return Object.assign(Object.assign({},e),{matchExpression:t,branches:i})}))},xr=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string"},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],wr=R(xr),Ur={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:xr},Rr={propertyAliases:wr,operatorData:Ur,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield $([e.functionPath,e.args,e.useCache],r);r.typeChecker(I(Ur.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=r.options,p=null!==(s=null!==(a=t(c,o,null))&&void 0!==a?a:t(d,o,null))&&void 0!==s?s:t(r.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:r.options.useCache)&&void 0!==n&&n;return yield r.cache.useCache(h,((e,...r)=>i(void 0,void 0,void 0,(function*(){return yield p(...r)}))),o,...l)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{functionPath:r,args:t})}},Ir=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any"}],Lr=R(Ir),kr={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Ir},Dr={propertyAliases:Lr,operatorData:kr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){return r.typeChecker(I(kr.parameters,{value:e.value})),yield Q(e.value,r)})),parseChildren:e=>{const[...r]=e.children,t=1===(null==r?void 0:r.length)?r[0]:r;return Object.assign(Object.assign({},e),{value:t})}};var _r=Object.freeze({__proto__:null,AND:X,BUILD_OBJECT:Sr,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Rr,DIVIDE:Ae,EQUAL:ie,GET:br,GRAPHQL:hr,GREATER_THAN:Ne,LESS_THAN:Ue,MATCH:Pr,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:Be,OR:ee,PASSTHRU:Dr,PG_SQL:ur,PLUS:pe,POST:jr,REGEX:He,SPLIT:ir,STRING_SUBSTITUTION:Je,SUBTRACT:ye});class Mr{constructor(e){var r,t;this.useCache=(e,r,...t)=>i(this,void 0,void 0,(function*(){if(!e)return yield r(...t);const a=Hr(t),i=a in this.store,s=Date.now(),n=i&&s-this.store[a].timestamp>1e3*this.maxTime;if(i)return this.queue=this.queue.filter((e=>e!==a)),this.queue.unshift(a),this.store[a].timestamp=s,n&&(this.store[a].result=yield r(...t)),this.store[a].result;const o=yield r(...t);return this.store[a]={result:o,timestamp:s},this.queue.unshift(a),this.resizeCache(),o})),this.getMax=()=>this.maxSize,this.setMax=e=>{this.maxSize=e,this.resizeCache()},this.getMaxTime=()=>this.maxTime,this.setMaxTime=e=>{this.maxTime=e},this.getCache=()=>this.store,this.setCache=e=>this.store=e,this.resizeCache=()=>{if(this.queue.length>this.maxSize){this.queue.slice(this.maxSize).forEach((e=>delete this.store[e])),this.queue=this.queue.slice(0,this.maxSize)}},this.store={},this.queue=[],this.maxSize=null!==(r=null==e?void 0:e.maxSize)&&void 0!==r?r:50,this.maxTime=null!==(t=null==e?void 0:e.maxTime)&&void 0!==t?t:1800}}const Hr=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_");class Gr{constructor(e={}){var r,t;this.typeChecker=(...e)=>{const r=1===e.length&&Array.isArray(e[0])?e[0]:e,t=P(...r);if(!0!==t)throw new Error(t)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.11.4",this.options=$r(e),this.operators=u(_r,null!==(t=null===(r=this.options)||void 0===r?void 0:r.excludeOperators)&&void 0!==t?t:[],T),this.operatorAliases=T,this.cache=new Mr({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime})}evaluate(e,r={}){return i(this,void 0,void 0,(function*(){const t=m(this.options,$r(r));return t.maxCacheSize&&t.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(t.maxCacheSize),t.maxCacheTime&&t.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(t.maxCacheTime),yield Q(e,{options:t,operators:r.excludeOperators?u(_r,r.excludeOperators,T):this.operators,operatorAliases:this.operatorAliases,typeChecker:t.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache})}))}getOptions(){return this.options}updateOptions(e){this.options=m(this.options,$r(e)),this.options.excludeOperators&&(this.operators=u(_r,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(_r,this.options.excludeOperators,T):this.operators;return Object.entries(e).map((([e,r])=>Object.assign({operator:e},r.operatorData)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,r])=>Object.assign({name:e},null==r?void 0:r.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,r])=>({name:e,numRequiredArgs:r.length})))}}const Qr=(e,r)=>new Gr(r).evaluate(e),$r=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;export{Gr as FigTreeEvaluator,Qr as evaluateExpression};
|
|
1
|
+
import{camelCase as e}from"change-case";import r from"axios";import t from"object-property-extractor";import{dequal as a}from"dequal/lite";function i(e,r,t,a){return new(t||(t=Promise))((function(i,s){function n(e){try{l(a.next(e))}catch(e){s(e)}}function o(e){try{l(a.throw(e))}catch(e){s(e)}}function l(e){var r;e.done?i(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(n,o)}l((a=a.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=r=>{const t=e(r);return t||r},l=(e,r)=>r[o(e)],u=(e,r,t)=>{const a=Object.assign({},e);return r.forEach((e=>{t[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[t[o(e)]]})),a},d=(e,r=200)=>e.length<r?e:`${e.slice(0,r-2).trim()}...`,c=(e,r,t=!1)=>{if(void 0!==e)return e;if(t)return d(r);throw new Error(d(r))},p=(e,r)=>{const t=Object.entries(e).map((([e,t])=>[r(e),t]));return Object.fromEntries(t)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:r})=>{var t;return"string"==typeof e&&h(e)&&null!==(t=null==r?void 0:r[e])&&void 0!==t?t:e},m=(e,r)=>{const t=Object.assign(Object.assign({},e),r);return(e.data||r.data)&&(t.data=Object.assign(Object.assign({},e.data),r.data)),(e.functions||r.functions)&&(t.functions=Object.assign(Object.assign({},e.functions),r.functions)),(e.fragments||r.fragments)&&(t.fragments=Object.assign(Object.assign({},e.fragments),r.fragments)),(e.headers||r.headers)&&(t.headers=Object.assign(Object.assign({},e.headers),r.headers)),t},y={number:e=>g(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=e=>e.message,g=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const r=new RegExp(/-?\d*\.?\d+/gm),t=e.match(r);return t?Number(t[0]):0},b=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),T={and:"AND","&":"AND","&&":"AND",or:"OR","|":"OR","||":"OR","=":"EQUAL",eq:"EQUAL",equal:"EQUAL",equals:"EQUAL","!=":"NOT_EQUAL","!":"NOT_EQUAL",ne:"NOT_EQUAL",notEqual:"NOT_EQUAL","+":"PLUS",plus:"PLUS",add:"PLUS",concat:"PLUS",join:"PLUS",merge:"PLUS","-":"SUBTRACT",subtract:"SUBTRACT",minus:"SUBTRACT",takeaway:"SUBTRACT","*":"MULTIPLY",x:"MULTIPLY",multiply:"MULTIPLY",times:"MULTIPLY","/":"DIVIDE",divide:"DIVIDE","÷":"DIVIDE",">":"GREATER_THAN",greaterThan:"GREATER_THAN",higher:"GREATER_THAN",larger:"GREATER_THAN","<":"LESS_THAN",lessThan:"LESS_THAN",lower:"LESS_THAN",smaller:"LESS_THAN","?":"CONDITIONAL",conditional:"CONDITIONAL",ifThen:"CONDITIONAL",regex:"REGEX",patternMatch:"REGEX",regexp:"REGEX",matchPattern:"REGEX",dataProperties:"OBJECT_PROPERTIES",data:"OBJECT_PROPERTIES",getData:"OBJECT_PROPERTIES",objectProperties:"OBJECT_PROPERTIES",objProps:"OBJECT_PROPERTIES",getProperty:"OBJECT_PROPERTIES",getObjProp:"OBJECT_PROPERTIES",stringSubstitution:"STRING_SUBSTITUTION",substitute:"STRING_SUBSTITUTION",stringSub:"STRING_SUBSTITUTION",replace:"STRING_SUBSTITUTION",split:"SPLIT",arraySplit:"SPLIT",count:"COUNT",length:"COUNT",get:"GET",api:"GET",post:"POST",pgSql:"PG_SQL",sql:"PG_SQL",postgres:"PG_SQL",pg:"PG_SQL",pgDb:"PG_SQL",graphQl:"GRAPHQL",graphql:"GRAPHQL",gql:"GRAPHQL",buildObject:"BUILD_OBJECT",build:"BUILD_OBJECT",object:"BUILD_OBJECT",match:"MATCH",switch:"MATCH",customFunctions:"CUSTOM_FUNCTIONS",customFunction:"CUSTOM_FUNCTIONS",objectFunctions:"CUSTOM_FUNCTIONS",function:"CUSTOM_FUNCTIONS",functions:"CUSTOM_FUNCTIONS",runFunction:"CUSTOM_FUNCTIONS",_:"PASSTHRU",passThru:"PASSTHRU",passthru:"PASSTHRU",pass:"PASSTHRU",ignore:"PASSTHRU",coerce:"PASSTHRU",convert:"PASSTHRU"},O=T,C=/(\$[^()]+)\((.*)\)/,j=(e,r={},t=!0)=>t?"string"==typeof e?A(e,r):b(e)?q(e,r):e:e,A=(e,r)=>{const t=C.exec(e);if(!t)return e;const a=t[1].trim(),i=t[2].split(",").map((e=>j(e.trim(),r)));return E(a,i,r)},q=(e,r)=>{if(s(e)||n(e))return e;const t=Object.entries(e),a=t.filter((([e])=>h(e))),i=t.filter((([e])=>!h(e))),o=a.reduce(((e,[t,a])=>e=Object.assign(Object.assign({},e),E(t,a,r))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,r,t)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(r)?{operator:i,children:r}:b(r)&&!Object.keys(r).some((e=>h(e)))?Object.assign({operator:i},r):{operator:i,children:[r]}:a in t?{fragment:a,parameters:Object.assign({},r)}:{[e]:r}},S=e=>b(e)&&"literal"in e,N=({value:e,name:r,expectedType:t})=>{if(S(t)){const{literal:a}=t;return!!a.includes(e)||w(r,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(t))return!!t.some((t=>!0===N({value:e,name:r,expectedType:t})))||w(r,e,t.join("|"));return!!(0,x[t])(e)||w(r,e,t)},P=(...e)=>{const r=[];return e.forEach((e=>{const t=N(e);!0!==t&&r.push(t)})),!(r.length>0)||r.join("\n")},x={any:e=>void 0!==e,string:e=>"string"==typeof e,number:e=>"number"==typeof e,boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),null:e=>null===e,object:e=>b(e),undefined:e=>void 0===e},w=(e,r,t)=>void 0===r&&e?`- Missing required property "${e}" (type: ${t})`:void 0!==e?`- Property "${e}" (value: ${U(r)}) is not of type: ${t}`:`- ${U(r)} is not of type: ${t}`,U=e=>{const r=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return d(r,50)},R=e=>{const r={};return e.forEach((e=>{e.aliases.forEach((t=>r[t]=e.name))})),r},I=(e,r)=>e.map((({name:e,required:t,type:a})=>{if(S(a)){const i=[...a.literal];return t||i.push(void 0),{name:e,value:r[e],expectedType:{literal:i}}}const i=Array.isArray(a)?a:[a];t||i.push("undefined");const s=1===i.length?i[0]:i;return{name:e,value:r[e],expectedType:s}})),L=(e,r)=>{const t=e.map(((e,t)=>[e,r[t]]));return Object.fromEntries(t)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=e.filter(((e,r)=>r%2==0)),t=P(...r.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==t)throw new Error(t);const a=e.filter(((e,r)=>r%2==1)),i={};return r.forEach(((e,r)=>{i[e]=a[r]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(e,r,a=void 0)=>{const i=r?t(e,r,a):e;return Array.isArray(i)?i.map((e=>D(e))):r?null===i?null:D(i):i},M=e=>/^https?:\/\/.+/.test(e),H=(...e)=>e.reduce(((e,r,t)=>{const a="/"===r[0]?1:0,i="/"===r.slice(-1)?-1:void 0,s=r.slice(a,i);return""===s?e:e+(0===t?"":"/")+s}),""),G=({url:e,params:t={},data:a={},headers:s={},method:n="get"})=>i(void 0,void 0,void 0,(function*(){var i;try{return(yield r({method:n,url:e,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:t,data:a})).data}catch(e){if(r.isAxiosError(e)){if(!(null==e?void 0:e.response))throw new Error("Network Error");console.log(null===(i=e.response)||void 0===i?void 0:i.data)}throw e}})),Q=(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,i,o;const{options:u,operators:d,operatorAliases:h}=r;let m=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const r=JSON.parse(e);return s(r)?r:e}catch(r){return e}})(e):e;m=j(m,null===(t=r.options)||void 0===t?void 0:t.fragments,!u.noShorthand),Array.isArray(m)&&(m=yield $(m,r));const g=s(m),T=n(m);if(u.evaluateFullObject&&!g&&!T)return v(yield F(m,r),r);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(m)&&"value"in m?m.value:v(m,r);const{fallback:O}=m,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,t]=yield $([m.fragment,m.parameters],r),a=j(null===(i=null==u?void 0:u.fragments)||void 0===i?void 0:i[e],u.fragments,!u.noShorthand);if(void 0===a)return c(yield Q(O,r),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,r);m=Object.assign(Object.assign(Object.assign({},m),a),t),delete m.fragment}try{const e=l(m.operator,h);if(!e)return c(yield Q(O,r),`Invalid operator: ${m.operator}`,C);if(!r.operators[e])return c(yield Q(O,r),`Excluded operator: ${m.operator}`,C);const{propertyAliases:t,evaluate:a,parseChildren:i}=d[e];m=((e,r)=>p(r,(r=>r in e?e[r]:r)))(t,m);const s=yield B(m,r);T||Object.entries(s).forEach((([e,t])=>r.resolvedAliasNodes[e]=t));const n=T?Object.assign(Object.assign({},r),{resolvedAliasNodes:Object.assign(Object.assign({},r.resolvedAliasNodes),s)}):r;if("children"in m){if(Array.isArray(m.children)||(m.children=yield Q(m.children,n)),!Array.isArray(m.children))return c(yield Q(O,r),`Operator: ${e}\n- Property "children" is not of type: array`,C);m=yield i(m,n),delete m.children}let u;try{u=yield a(m,n)}catch(t){return c(yield Q(m.fallback,r),`Operator: ${e}\n${f(t)}`,C)}const v=null!==(o=null==m?void 0:m.outputType)&&void 0!==o?o:null==m?void 0:m.type;if(!v)return u;const g=yield Q(v,r);return g in y?y[g](u):c(yield Q(O,r),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield Q(O,r),f(e),C)}})),$=(e,r)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>Q(e,r)))):yield Q(e,r)})),B=(e,r)=>i(void 0,void 0,void 0,(function*(){const t=Object.keys(e).filter(h);if(0===t.length)return{};const a=[];return t.forEach((t=>a.push(Q(e[t],r)))),L(t,yield Promise.all(a))})),F=(e,r)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const t=[],a=[];Object.entries(e).forEach((([t,i])=>{h(t)&&(a.push(t,Q(i,r)),delete e[t])}));const i=yield Promise.all(a);r.resolvedAliasNodes=Object.assign(Object.assign({},r.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{t.push(e,Q(a,r))}));const s=yield Promise.all(t);return v(k(s),r)})),W=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array"}],z=R(W),J={description:"Logical AND",aliases:["and","&","&&"],parameters:W},V=e=>{const r=e.children;return Object.assign(Object.assign({},e),{values:r})},X={propertyAliases:z,operatorData:J,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(I(J.parameters,{values:t})),t.reduce(((e,r)=>e&&!!r),!0)})),parseChildren:V},Y=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array"}],K=R(Y),Z={description:"Logical OR",aliases:["or","|","||"],parameters:Y},ee={propertyAliases:K,operatorData:Z,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(I(Z.parameters,{values:t})),t.reduce(((e,r)=>e||!!r),!1)})),parseChildren:V},re=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array"},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value",aliases:[],required:!1,type:"boolean"}],te=R(re),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:re},ie={propertyAliases:te,operatorData:ae,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const[i,s]=yield $([e.values,e.nullEqualsUndefined],r);r.typeChecker(I(ae.parameters,{values:i,nullEqualsUndefined:s}));return!(void 0!==s?s:void 0!==(null===(t=r.options)||void 0===t?void 0:t.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==i[0]&&void 0!==i[0]?i.every((e=>a(e,i[0]))):i.every((e=>null==e))})),parseChildren:V},se=[{name:"values",description:"Array of values to check for inequality",aliases:[],required:!0,type:"array"},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value",aliases:[],required:!1,type:"boolean"}],ne=R(se),oe={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:se},le={propertyAliases:ne,operatorData:oe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const[i,s]=yield $([e.values,e.nullEqualsUndefined],r);r.typeChecker(I(oe.parameters,{values:i,nullEqualsUndefined:s}));return!(void 0!==s?s:void 0!==(null===(t=r.options)||void 0===t?void 0:t.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==i[0]&&void 0!==i[0]?i.some((e=>!a(e,i[0]))):i.some((e=>null===e&&void 0===e))})),parseChildren:V},ue=[{name:"values",description:"Array of values to check to add together",aliases:[],required:!0,type:"array"},{name:"type",description:"Data type to coerce input values to before addition",aliases:[],required:!1,type:{literal:["string","array","number","boolean","bool"]}}],de=R(ue),ce={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ue},pe={propertyAliases:de,operatorData:ce,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(I(ce.parameters,{values:t,type:e.type})),0===t.length?t:"string"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),""):"array"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),[]):t.every((e=>"string"==typeof e||Array.isArray(e)))?t.reduce(((e,r)=>e.concat(r))):t.every((e=>b(e)))?t.reduce(((e,r)=>Object.assign(Object.assign({},e),r)),{}):t.reduce(((e,r)=>e+r))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array"},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number"},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number"}],ve=R(he),me={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},ye={propertyAliases:ve,operatorData:me,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i]=yield $([e.values,e.from,e.subtract],r);r.typeChecker(I(me.parameters,{values:t,from:a,subtract:i}));const s=null!=t?t:[a,i].filter((e=>void 0!==e));if(s.length<2)throw new Error("- Not enough values provided");if(s.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return s[0]-s[1]})),parseChildren:V},fe=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array"}],ge=R(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);if(r.typeChecker(I(be.parameters,{values:t})),0===t.length)return 0;if(t.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return t.reduce(((e,r)=>e*r))})),parseChildren:V},Oe=[{name:"values",description:"Array of values - 1st element will be divided by the first",aliases:[],required:!1,type:"array"},{name:"dividend",description:"The number that will be divided",aliases:["divide"],required:!1,type:"number"},{name:"divisor",description:"The number that dividend will be divided by",aliases:["by","divideBy"],required:!1,type:"number"},{name:"output",description:"Whether to output a quotient, remainder or decimal",aliases:[],required:!1,type:{literal:["quotient","remainder"]}}],Ce=R(Oe),je={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},Ae={propertyAliases:Ce,operatorData:je,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i,s]=yield $([e.values,e.dividend,e.divisor,e.output],r);r.typeChecker(I(je.parameters,{values:t,dividend:a,divisor:i,output:s}));const n=null!=t?t:[a,i].filter((e=>void 0!==e));if(n.length<2)throw new Error("- Not enough values provided");if(n.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");if(0===n[1])throw new Error("Division by zero!");switch(s){case"quotient":return Math.floor(n[0]/n[1]);case"remainder":return n[0]%n[1];default:return n[0]/n[1]}})),parseChildren:V},qe=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array"},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean"}],Ee=R(qe),Se={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:qe},Ne={propertyAliases:Ee,operatorData:Se,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a=!0]=yield $([e.values,e.strict],r);if(r.typeChecker(I(Se.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[i,s]=t;return i===s&&!a||i>s})),parseChildren:V},Pe=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array"},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean"}],xe=R(Pe),we={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ue={propertyAliases:xe,operatorData:we,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a=!0]=yield $([e.values,e.strict],r);if(r.typeChecker(I(we.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[i,s]=t;return i===s&&!a||i<s})),parseChildren:V},Re=[{name:"condition",description:"The expression to check for truthiness",aliases:[],required:!0,type:"any"},{name:"valueIfTrue",description:"Value to return if condition is true",aliases:["ifTrue"],required:!0,type:"any"},{name:"valueIfFalse",description:"Value to return if condition is false",aliases:["ifFalse","ifNot"],required:!0,type:"any"}],Ie=R(Re),Le={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Re},ke={propertyAliases:Ie,operatorData:Le,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(I(Le.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield Q(e.condition,r))?yield Q(e.valueIfTrue,r):yield Q(e.valueIfFalse,r)})),parseChildren:e=>{const[r,t,a]=e.children;return Object.assign(Object.assign({},e),{condition:r,valueIfTrue:t,valueIfFalse:a})}},De=[{name:"testString",description:"The string to test",aliases:["string","value"],required:!0,type:"string"},{name:"pattern",description:"The regular expression pattern",aliases:["regex","regexp","regExp","re"],required:!0,type:"string"}],_e=R(De),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},He={propertyAliases:_e,operatorData:Me,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a]=yield $([e.testString,e.pattern],r);r.typeChecker(I(Me.parameters,{testString:t,pattern:a}));try{return new RegExp(a).test(t)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[r,t]=e.children;return Object.assign(Object.assign({},e),{testString:r,pattern:t})}},Ge=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object"}],Qe=R(Ge),$e={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:Ge},Be={propertyAliases:Qe,operatorData:$e,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,i,s,n;const[o,l]=yield $([e.property,e.additionalData],r);r.typeChecker(I($e.parameters,{property:o,additionalData:l}));const u=l?Object.assign(Object.assign({},null!==(i=null===(a=r.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),l):null!==(n=null===(s=r.options)||void 0===s?void 0:s.data)&&void 0!==n?n:{};return t(u,o)})),parseChildren:e=>{const[r,t]=e.children,a=Object.assign(Object.assign({},e),{property:r});return void 0!==t&&(a.fallback=t),a}},Fe=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!0,type:["array","object"]},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean"},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object"}],We=R(Fe),ze={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:Fe},Je={propertyAliases:We,operatorData:ze,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a,i=!0,s="%",n={}]=yield $([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],r);if(r.typeChecker(I(ze.parameters,{string:t,substitutions:a,trimWhiteSpace:i,substitutionCharacter:s,numberMapping:n})),Array.isArray(a)){const e="$"===s?"$":"%",r=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(t.match(r)||[]).sort(((e,r)=>Number(e.slice(1))-Number(r.slice(1)))),o=new Set(n),l=L(Array.from(o),a.map((e=>i?String(e).trim():e)));return t.split(r).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}return t.split(/(?<!\\)({{[A-z0-9_]+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ve(e,a,n);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{string:r,substitutions:t})}},Ve=(e,r,t)=>{var a,i;const s=e.replace(/{{(.+)}}/,"$1"),n=null!==(a=null==r?void 0:r[s])&&void 0!==a?a:"";if("number"!=typeof n)return null!==(i=null==r?void 0:r[s])&&void 0!==i?i:"";if(!(s in t))return n;const o=t[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(t[s]),u=l.find((e=>e.startsWith(">")));if(u){if(n>Number(u.slice(1)))return null==o?void 0:o[u]}const d=l.find((e=>e.startsWith("<")));if(d){if(n<Number(d.slice(1)))return null==o?void 0:o[d]}return o.other?o.other.replace("{}",String(n)):n},Xe=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array"}],Ye=R(Xe),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Xe},Ze={propertyAliases:Ye,operatorData:Ke,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(I(Ke.parameters,{values:t})),t.length})),parseChildren:e=>{const[r]=e.children;return Object.assign(Object.assign({},e),{values:r})}},er=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string"},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean"},{name:"excludeTrailing",description:"If the input string ends in a delimiter, there will be an additional blank element if this value is false (default: true)",aliases:["removeTrailing","excludeTrailingDelimiter"],required:!1,type:"boolean"}],rr=R(er),tr={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:er},ar=" ",ir={propertyAliases:rr,operatorData:tr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,i;const[s,n,o,l]=yield $([e.value,null!==(t=e.delimiter)&&void 0!==t?t:ar,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],r);r.typeChecker(I(tr.parameters,{value:s,delimiter:n,trimWhiteSpace:o,excludeTrailing:l}));let u=s.split(n);return o&&(u=u.map((e=>e.trim()))),l&&""===u[u.length-1]&&u.pop(),u})),parseChildren:e=>{const[r,t=ar]=e.children;return Object.assign(Object.assign({},e),{value:r,delimiter:t})}},sr=[{name:"query",description:"A SQL query string, with parameterised replacements (i.e. $1, $2, etc)",aliases:[],required:!0,type:"string"},{name:"values",description:"An array of values to replace in the SQL string parameters",aliases:["replacements"],required:!1,type:"array"},{name:"type",description:"Determines the shape of the resulting data (see documentation)",aliases:["queryType"],required:!1,type:{literal:["array","string","number"]}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],nr=R(sr),or={description:"Query a Postgres database using node-postgres",aliases:["pgSql","sql","postgres","pg","pgDb"],parameters:sr},lr=(e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i={text:e,values:r,rowMode:a?"array":""},s=yield t.query(i);if(null==s?void 0:s.error)throw new Error(s.error);switch(a){case"array":return s.rows.flat();case"string":return s.rows.flat().join(" ");case"number":{const e=s.rows.flat();return Number.isNaN(Number(e))?e:Number(e)}default:return s.rows}})),ur={propertyAliases:nr,operatorData:or,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u]=yield $([e.query,e.type,e.values||[],e.useCache],r);if(r.typeChecker(I(or.parameters,{query:n,type:o,values:l,useCache:u})),!(null===(t=r.options)||void 0===t?void 0:t.pgConnection))throw new Error("No Postgres database connection provided");const d=null===(s=null!==(a=e.useCache)&&void 0!==a?a:r.options.useCache)||void 0===s||s;return r.cache.useCache(d,((e,t,a)=>i(void 0,void 0,void 0,(function*(){return yield lr(e,a,r.options.pgConnection,t)}))),n,o,l)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{query:r,values:t})}},dr=[{name:"query",description:"GraphQL query string",aliases:[],required:!0,type:"string"},{name:"url",description:"Endpoint for the GraphQL request (if not already provided in options)",aliases:["endpoint"],required:!1,type:["string","null"]},{name:"headers",description:"HTTP Headers (if not already provided in options)",aliases:[],required:!1,type:"object"},{name:"variables",description:"Values for the variables used in query (key-value pairs)",aliases:[],required:!1,type:"object"},{name:"returnNode",description:"Property path to extract from the query response",aliases:["outputNode","returnProperty"],required:!1,type:"string"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],cr=R(dr),pr={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:dr},hr={propertyAliases:cr,operatorData:pr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s,n,o,l;const[u,d,c,p,h,v]=yield $([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],r),{url:m,headers:y}=d instanceof Object?d:{url:d,headers:null};r.typeChecker([...I(pr.parameters,{url:m,query:u,variables:c,returnNode:p,headers:h,useCache:v}),{name:"headers",value:y,expectedType:["object","null"]}]);const f=m&&"graphqlendpoint"!==m.toLowerCase()?m:"",g=null!==(s=null!==(a=null===(t=r.options.graphQLConnection)||void 0===t?void 0:t.endpoint)&&void 0!==a?a:r.options.baseEndpoint)&&void 0!==s?s:"",b=M(f)?f:H(g,f),T={query:u,variables:c},O=null===(n=null!=v?v:r.options.useCache)||void 0===n||n,C=yield r.cache.useCache(O,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield G({url:e,method:"post",data:r,headers:t});return _(i.data,a)}))),b,T,Object.assign(Object.assign(Object.assign(Object.assign({},null===(o=r.options.graphQLConnection)||void 0===o?void 0:o.headers),null===(l=r.options)||void 0===l?void 0:l.headers),y),h),p);return C})),parseChildren:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,a="",i,...s]=yield $(e.children,r),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=L(n,o),u=Object.assign(Object.assign({},e),{query:t,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},vr=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string"},{name:"returnProperty",description:"Property from request result",aliases:["outputProperty"],required:!1,type:"string"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object"},{name:"parameters",description:"Query parameters (key-value)",aliases:["queryParams","queryParameters","urlQueries"],required:!1,type:"object"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],mr=R(vr),yr={description:"HTTP GET Request",aliases:["get","api"],parameters:vr},fr=(e,r)=>i(void 0,void 0,void 0,(function*(){const[t="",a,...i]=yield $(e.children,r),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=L(s,n),l=Object.assign(Object.assign({},e),{url:t,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gr=fr,br={propertyAliases:mr,operatorData:yr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u,d]=yield $([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],r),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};r.typeChecker([...I(yr.parameters,{url:c,returnProperty:l,headers:u,parameters:o,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",v=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),p),u),m=null===(s=null!=d?d:r.options.useCache)||void 0===s||s,y=yield r.cache.useCache(m,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield G({url:e,params:r,headers:t});return _(i,a)}))),M(c)?c:H(h,c),o,v,l);return y})),parseChildren:fr},Tr=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string"},{name:"returnProperty",description:"Property path from request result",aliases:["outputProperty"],required:!1,type:"string"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object"},{name:"parameters",description:"JSON Body parameters (key-value)",aliases:["bodyJson","data"],required:!1,type:"object"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],Or=R(Tr),Cr={description:"HTTP POST Request",aliases:["post"],parameters:Tr},jr={propertyAliases:Or,operatorData:Cr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const[n,o,l,u,d]=yield $([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],r),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};r.typeChecker([...I(Cr.parameters,{url:c,headers:u,data:o,returnProperty:l,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",v=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),p),u),m=null===(s=null!=d?d:r.options.useCache)||void 0===s||s;return yield r.cache.useCache(m,(()=>i(void 0,void 0,void 0,(function*(){const e=yield G({url:c,data:o,headers:u,method:"post"});return _(e,l)}))),M(c)?c:H(h,c),o,v,l)})),parseChildren:gr},Ar=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array"}],qr=R(Ar),Er={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:Ar},Sr={propertyAliases:qr,operatorData:Er,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(I(Er.parameters,{properties:e.properties}));const t=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:t})=>{return a=[e,t],i(void 0,void 0,void 0,(function*(){const[e,t]=yield $(a,r);return r.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,t]}));var a}));return Object.fromEntries(yield Promise.all(t))})),parseChildren:e=>{const r=e.children;if(r.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=r.filter(((e,r)=>r%2==0)),a=r.filter(((e,r)=>r%2==1)),i=t.map(((e,r)=>({key:e,value:a[r]})));return Object.assign(Object.assign({},e),{properties:i})}},Nr=[{name:"matchExpression",description:"Expression to match against",aliases:["match"],required:!0,type:["string","number","boolean"]},{name:"branches",description:"Object whose keys are compared against the match expression. The value of the matching key is returned",aliases:["arms","cases"],required:!1,type:["object","array"]}],Pr={propertyAliases:R(Nr),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Nr},evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const a=yield Q(e.matchExpression,r);r.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(t=e.branches)&&void 0!==t?t:{},n=s(i)?yield Q(i,r):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield Q(n[a],r);if("fallback"in n)return yield Q(n.fallback,r);if(a in e)return yield Q(e[a],r);throw new Error(`No match found for ${a}`)})),parseChildren:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,...a]=e.children,i=k(yield $(a,r));return Object.assign(Object.assign({},e),{matchExpression:t,branches:i})}))},xr=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string"},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],wr=R(xr),Ur={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:xr},Rr={propertyAliases:wr,operatorData:Ur,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield $([e.functionPath,e.args,e.useCache],r);r.typeChecker(I(Ur.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=r.options,p=null!==(s=null!==(a=t(c,o,null))&&void 0!==a?a:t(d,o,null))&&void 0!==s?s:t(r.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:r.options.useCache)&&void 0!==n&&n;return yield r.cache.useCache(h,((e,...r)=>i(void 0,void 0,void 0,(function*(){return yield p(...r)}))),o,...l)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{functionPath:r,args:t})}},Ir=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any"}],Lr=R(Ir),kr={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Ir},Dr={propertyAliases:Lr,operatorData:kr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){return r.typeChecker(I(kr.parameters,{value:e.value})),yield Q(e.value,r)})),parseChildren:e=>{const[...r]=e.children,t=1===(null==r?void 0:r.length)?r[0]:r;return Object.assign(Object.assign({},e),{value:t})}};var _r=Object.freeze({__proto__:null,AND:X,BUILD_OBJECT:Sr,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Rr,DIVIDE:Ae,EQUAL:ie,GET:br,GRAPHQL:hr,GREATER_THAN:Ne,LESS_THAN:Ue,MATCH:Pr,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:Be,OR:ee,PASSTHRU:Dr,PG_SQL:ur,PLUS:pe,POST:jr,REGEX:He,SPLIT:ir,STRING_SUBSTITUTION:Je,SUBTRACT:ye});class Mr{constructor(e){var r,t;this.useCache=(e,r,...t)=>i(this,void 0,void 0,(function*(){if(!e)return yield r(...t);const a=Hr(t),i=a in this.store,s=Date.now(),n=i&&s-this.store[a].timestamp>1e3*this.maxTime;if(i)return this.queue=this.queue.filter((e=>e!==a)),this.queue.unshift(a),this.store[a].timestamp=s,n&&(this.store[a].result=yield r(...t)),this.store[a].result;const o=yield r(...t);return this.store[a]={result:o,timestamp:s},this.queue.unshift(a),this.resizeCache(),o})),this.getMax=()=>this.maxSize,this.setMax=e=>{this.maxSize=e,this.resizeCache()},this.getMaxTime=()=>this.maxTime,this.setMaxTime=e=>{this.maxTime=e},this.getCache=()=>this.store,this.setCache=e=>this.store=e,this.resizeCache=()=>{if(this.queue.length>this.maxSize){this.queue.slice(this.maxSize).forEach((e=>delete this.store[e])),this.queue=this.queue.slice(0,this.maxSize)}},this.store={},this.queue=[],this.maxSize=null!==(r=null==e?void 0:e.maxSize)&&void 0!==r?r:50,this.maxTime=null!==(t=null==e?void 0:e.maxTime)&&void 0!==t?t:1800}}const Hr=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_");class Gr{constructor(e={}){var r,t;this.typeChecker=(...e)=>{const r=1===e.length&&Array.isArray(e[0])?e[0]:e,t=P(...r);if(!0!==t)throw new Error(t)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.11.6",this.options=$r(e),this.operators=u(_r,null!==(t=null===(r=this.options)||void 0===r?void 0:r.excludeOperators)&&void 0!==t?t:[],T),this.operatorAliases=T,this.cache=new Mr({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime})}evaluate(e,r={}){return i(this,void 0,void 0,(function*(){const t=m(this.options,$r(r));return t.maxCacheSize&&t.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(t.maxCacheSize),t.maxCacheTime&&t.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(t.maxCacheTime),yield Q(e,{options:t,operators:r.excludeOperators?u(_r,r.excludeOperators,T):this.operators,operatorAliases:this.operatorAliases,typeChecker:t.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache})}))}getOptions(){return this.options}updateOptions(e){this.options=m(this.options,$r(e)),this.options.excludeOperators&&(this.operators=u(_r,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(_r,this.options.excludeOperators,T):this.operators;return Object.entries(e).map((([e,r])=>Object.assign({operator:e},r.operatorData)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,r])=>Object.assign({name:e},null==r?void 0:r.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,r])=>({name:e,numRequiredArgs:r.length})))}}const Qr=(e,r)=>new Gr(r).evaluate(e),$r=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;export{Gr as FigTreeEvaluator,Qr as evaluateExpression};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fig-tree-evaluator",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.6",
|
|
4
4
|
"description": "Module to evaluate JSON-structured expression trees",
|
|
5
5
|
"main": "build/index.cjs.js",
|
|
6
6
|
"module": "build/index.esm.js",
|
|
@@ -14,26 +14,26 @@
|
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@rollup/plugin-typescript": "^11.1.1",
|
|
16
16
|
"@testing-library/jest-dom": "^5.14.1",
|
|
17
|
-
"@testing-library/react": "^
|
|
18
|
-
"@types/jest": "^
|
|
19
|
-
"@types/node": "^
|
|
17
|
+
"@testing-library/react": "^14.0.0",
|
|
18
|
+
"@types/jest": "^29.5.3",
|
|
19
|
+
"@types/node": "^20.4.9",
|
|
20
20
|
"@types/pg": "^8.6.5",
|
|
21
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
22
|
-
"@typescript-eslint/parser": "^
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^6.3.0",
|
|
22
|
+
"@typescript-eslint/parser": "^6.3.0",
|
|
23
23
|
"dotenv": "^16.0.1",
|
|
24
24
|
"eslint": "^8.37.0",
|
|
25
|
-
"fig-tree-evaluator": "^2.11.
|
|
25
|
+
"fig-tree-evaluator": "^2.11.5",
|
|
26
26
|
"jest": "^29.6.2",
|
|
27
27
|
"pg": "^8.11.2",
|
|
28
28
|
"prettier": "^3.0.0",
|
|
29
|
-
"rimraf": "^
|
|
29
|
+
"rimraf": "^5.0.1",
|
|
30
30
|
"rollup-plugin-dts": "^5.3.0",
|
|
31
31
|
"rollup-plugin-sizes": "^1.0.5",
|
|
32
32
|
"rollup-plugin-terser": "^7.0.2",
|
|
33
33
|
"ts-jest": "^29.1.1",
|
|
34
34
|
"ts-node": "^10.8.0",
|
|
35
35
|
"tslib": "^2.5.0",
|
|
36
|
-
"typescript": "^
|
|
36
|
+
"typescript": "^5.1.6"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"setup": "yarn install && cd demo && yarn install",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"prepublishOnly": "yarn build"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"axios": "^
|
|
53
|
+
"axios": "^1.4.0",
|
|
54
54
|
"change-case": "^4.1.2",
|
|
55
55
|
"dequal": "^2.0.3",
|
|
56
56
|
"object-property-extractor": "^1.0.7"
|