fig-tree-evaluator 2.13.5 → 2.14.0

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 CHANGED
@@ -785,7 +785,7 @@ Aliases: `stringSubstitution`, `substitute`, `stringSub`, `replace`
785
785
 
786
786
  #### Properties
787
787
 
788
- - `string`<sup>*</sup>: (string) -- a parameterized (`%1`, `%2`) string, where the parameters are to be replaced by dynamic values. E.g. `"My name is %1 (age %2)"`
788
+ - `string`<sup>*</sup>: (string) -- a parameterized (`%1`, `%2`, or `{{named}}`) string, where the parameters are to be replaced by dynamic values. E.g. `"My name is %1 (age %2)"`, or `"My name is {{name}} (age {{age}})"`
789
789
  - `substitutions` (or `replacements`, `values`)<sup>*</sup>: (array | object) -- the values to be substituted into `string`. Will be either an array or object depending on whether you're using positional replacements or named properties (see [below](#positional-replacement)).
790
790
  - `trimWhiteSpace` (or `trimWhitespace`, `trim`): (boolean, default `true`) -- strips whitespace from the beginning or end of the substitution values
791
791
  - `substitutionCharacter` (or `subCharacter`, `subChar`): (`"%"` or `"$"`) -- by default, when using positional replacement, it looks for the `%` token (i.e `%1, %2, etc`), but this can be changed to `$` (i.e. `$1, $2, $3, etc`) by setting this property to `$`.
@@ -867,19 +867,51 @@ e.g.
867
867
 
868
868
  #### Named property replacement
869
869
 
870
- Replacement tokens can be indicated in the main string with a named value, using `{{<name>}}` syntax, e.g. `"Your name is {{firstName}} {{lastName}}"`. Then the `substitutions` property must be an object with those property names:
870
+ Replacement tokens can be indicated in the main string with a named value, using `{{<name>}}` syntax, e.g. `"Your name is {{firstName}} {{lastName}} and your best friend is {{friends[0]}}"`. Then the `substitutions` property should be an object with those property names:
871
871
 
872
872
  ```js
873
873
  {
874
874
  operator: 'stringSubstitution',
875
- string: 'Your name is {{firstName}} {{lastName}}',
875
+ string: 'Your name is {{firstName}} {{lastName}} and your best friend is {{friends[0]}}',
876
876
  substitutions: {
877
877
  firstName: 'Steve',
878
878
  lastName: "Rogers"
879
+ friends: [ "Bucky Barnes", "Peggy Carter" ]
879
880
  }
880
881
  }
881
- // => "Your name is Steve Rogers"
882
+ // => "Your name is Steve Rogers and your best friend is Bucky Barnes"
882
883
  ```
884
+ Note the use of `nested.properties` as per [objectProperties](#object_properties).
885
+
886
+ Additionally, the substitutions can actually be provided directly in the associated `data` object and the operator will search for them there if not found in the `substitutions` property. This could be achieved simply by nesting a [`getData` node](#object_properties) inside the `substitutions` property, but because this is a very common scenario (the values provided will normally be dynamic based on application state), this shorthand is provided as a convenience.
887
+
888
+ ```js
889
+ // With "data" object:
890
+ {
891
+ info: { where: "Spain", what: "plain" }
892
+ }
893
+
894
+ // These two expressions are equivalent:
895
+ {
896
+ operator: 'stringSubstitution',
897
+ string: 'The rain in {{where}} falls mainly on the {{what}}',
898
+ substitutions: {
899
+ where: { operator: "getData", property: "info.where" },
900
+ what: { operator: "getData", property: "info.where" }
901
+ }
902
+ }
903
+ // or
904
+ {
905
+ operator: 'stringSubstitution',
906
+ string: 'The rain in {{info.where}} falls mainly on the {{info.what}}',
907
+ }
908
+
909
+ // => "The rain in Spain falls mainly on the plain"
910
+ ```
911
+
912
+
913
+
914
+ #### Number mapping
883
915
 
884
916
  If the replacement values are numbers, we can extend this functionality with a special `numberMapping` object, which allows for different replacements depending on the value, which is handy for pluralisation, for example.
885
917
 
@@ -1796,6 +1828,9 @@ Please open an issue: https://github.com/CarlosNZ/fig-tree-evaluator/issues
1796
1828
 
1797
1829
  *Trivial upgrades (e.g. documentation, small re-factors, types, etc.) not included*
1798
1830
 
1831
+ - **v2.14.0**: Improvements to `stringSubstitution` operator:
1832
+ - Can accept nested property references (e.g. `{{user.name}}`)
1833
+ - Will also search for replacements from `data` object
1799
1834
  - **v2.13.4**: Bug fix for `objectProperties` operator when array index larger than `9` is used, and for sequential array indexes (e.g. `prop[1][2]`)
1800
1835
  - **v2.13.0**: Add default values to operator properties, export more types and helper methods
1801
1836
  - **v2.12.0**: Add `caseInsensitive` option to equality/non-equality operators
@@ -1 +1 @@
1
- "use strict";var e=require("change-case"),t=require("axios"),r=require("object-property-extractor"),a=require("dequal/lite");function i(e,t,r,a){return new(r||(r=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 t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=t=>{const r=e.camelCase(t);return r||t},l=(e,t)=>t[o(e)],u=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[o(e)]]})),a},d=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,c=(e,t,r=!1)=>{if(void 0!==e)return e;if(r)return d(t);throw new Error(d(t))},p=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&h(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},m=(e,t)=>{const r=Object.assign(Object.assign({},e),t);return(e.data||t.data)&&(r.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(r.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(r.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(r.headers=Object.assign(Object.assign({},e.headers),t.headers)),r},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 t=new RegExp(/-?\d*\.?\d+/gm),r=e.match(t);return r?Number(r[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=/(\$[^()]+)\((.*)\)/,q=(e,t={},r=!0)=>r?"string"==typeof e?j(e,t):b(e)?A(e,t):e:e,j=(e,t)=>{const r=C.exec(e);if(!r)return e;const a=r[1].trim(),i=r[2].split(",").map((e=>q(e.trim(),t)));return E(a,i,t)},A=(e,t)=>{if(s(e)||n(e))return e;const r=Object.entries(e),a=r.filter((([e])=>h(e))),i=r.filter((([e])=>!h(e))),o=a.reduce(((e,[r,a])=>e=Object.assign(Object.assign({},e),E(r,a,t))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,t,r)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(t)?{operator:i,children:t}:b(t)&&!Object.keys(t).some((e=>h(e)))?Object.assign({operator:i},t):{operator:i,children:[t]}:a in r?{fragment:a,parameters:Object.assign({},t)}:{[e]:t}},S=e=>b(e)&&"literal"in e,N=({value:e,name:t,expectedType:r})=>{if(S(r)){const{literal:a}=r;return!!a.includes(e)||w(t,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(r))return!!r.some((r=>!0===N({value:e,name:t,expectedType:r})))||w(t,e,r.join("|"));return!!(0,x[r])(e)||w(t,e,r)},P=(...e)=>{const t=[];return e.forEach((e=>{const r=N(e);!0!==r&&t.push(r)})),!(t.length>0)||t.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,t,r)=>void 0===t&&e?`- Missing required property "${e}" (type: ${r})`:void 0!==e?`- Property "${e}" (value: ${I(t)}) is not of type: ${r}`:`- ${I(t)} is not of type: ${r}`,I=e=>{const t=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return d(t,50)},U=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},R=(e,t)=>e.map((({name:e,required:r,type:a})=>{if(S(a)){const i=[...a.literal];return r||i.push(void 0),{name:e,value:t[e],expectedType:{literal:i}}}const i=Array.isArray(a)?a:[a];r||i.push("undefined");const s=1===i.length?i[0]:i;return{name:e,value:t[e],expectedType:s}})),L=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=e.filter(((e,t)=>t%2==0)),r=P(...t.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==r)throw new Error(r);const a=e.filter(((e,t)=>t%2==1)),i={};return t.forEach(((e,t)=>{i[e]=a[t]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(e,t,a=void 0)=>{const i=t?r(e,t,a):e;return Array.isArray(i)?i.map((e=>D(e))):t?null===i?null:D(i):i},M=e=>/^https?:\/\/.+/.test(e),F=(...e)=>e.reduce(((e,t,r)=>{const a="/"===t[0]?1:0,i="/"===t.slice(-1)?-1:void 0,s=t.slice(a,i);return""===s?e:e+(0===r?"":"/")+s}),""),H=({url:e,params:r={},data:a={},headers:s={},method:n="get"})=>i(void 0,void 0,void 0,(function*(){var i;try{return(yield t({method:n,url:e,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:r,data:a})).data}catch(e){if(t.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}})),$=(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i,o;const{options:u,operators:d,operatorAliases:h}=t;let m=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return s(t)?t:e}catch(t){return e}})(e):e;m=q(m,null===(r=t.options)||void 0===r?void 0:r.fragments,!u.noShorthand),Array.isArray(m)&&(m=yield B(m,t));const g=s(m),T=n(m);if(u.evaluateFullObject&&!g&&!T)return v(yield Q(m,t),t);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(m)&&"value"in m?m.value:v(m,t);const{fallback:O}=m,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,r]=yield B([m.fragment,m.parameters],t),a=q(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 $(O,t),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,t);m=Object.assign(Object.assign(Object.assign({},m),a),r),delete m.fragment}try{const e=l(m.operator,h);if(!e)return c(yield $(O,t),`Invalid operator: ${m.operator}`,C);if(!t.operators[e])return c(yield $(O,t),`Excluded operator: ${m.operator}`,C);const{propertyAliases:r,evaluate:a,parseChildren:i}=d[e];m=((e,t)=>p(t,(t=>t in e?e[t]:t)))(r,m);const s=yield G(m,t);T||Object.entries(s).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const n=T?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),s)}):t;if("children"in m){if(Array.isArray(m.children)||(m.children=yield $(m.children,n)),!Array.isArray(m.children))return c(yield $(O,t),`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(r){return c(yield $(m.fallback,t),`Operator: ${e}\n${f(r)}`,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 $(v,t);return g in y?y[g](u):c(yield $(O,t),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield $(O,t),f(e),C)}})),B=(e,t)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>$(e,t)))):yield $(e,t)})),G=(e,t)=>i(void 0,void 0,void 0,(function*(){const r=Object.keys(e).filter(h);if(0===r.length)return{};const a=[];return r.forEach((r=>a.push($(e[r],t)))),L(r,yield Promise.all(a))})),Q=(e,t)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{h(r)&&(a.push(r,$(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,$(a,t))}));const s=yield Promise.all(r);return v(k(s),t)})),W=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],z=U(W),J={description:"Logical AND",aliases:["and","&","&&"],parameters:W},V=e=>{const t=e.children;return Object.assign(Object.assign({},e),{values:t})},Y={propertyAliases:z,operatorData:J,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(J.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:V},X=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],K=U(X),Z={description:"Logical OR",aliases:["or","|","||"],parameters:X},ee={propertyAliases:K,operatorData:Z,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(Z.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:V},te=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array",default:["These are equal","These are equal"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],re=U(te),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:te},ie={propertyAliases:re,operatorData:ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(ae.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=t.options)||void 0===r?void 0:r.caseInsensitive)&&void 0!==i&&i)&&n.every((e=>"string"==typeof e))?n.map((e=>e.toLowerCase())):n;return!(void 0!==l?l:void 0!==(null===(s=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>a.dequal(e,u[0]))):u.every((e=>null==e))})),parseChildren:V},se=[{name:"values",description:"Array of values to check for inequality",aliases:[],required:!0,type:"array",default:["These items","don't match"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],ne=U(se),oe={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:se},le={propertyAliases:ne,operatorData:oe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(oe.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=t.options)||void 0===r?void 0:r.caseInsensitive)&&void 0!==i&&i)&&n.every((e=>"string"==typeof e))?n.map((e=>e.toLowerCase())):n;return!(void 0!==l?l:void 0!==(null===(s=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!a.dequal(e,u[0]))):u.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",default:[1,2,3]},{name:"type",description:"Data type to coerce input values to before addition",aliases:[],required:!1,type:{literal:["string","array","number","boolean","bool"]},default:"string"}],de=U(ue),ce={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ue},pe={propertyAliases:de,operatorData:ce,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(ce.parameters,{values:r,type:e.type})),0===r.length?r:"string"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),""):"array"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),[]):r.every((e=>"string"==typeof e||Array.isArray(e)))?r.reduce(((e,t)=>e.concat(t))):r.every((e=>b(e)))?r.reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{}):r.reduce(((e,t)=>e+t))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array",default:[10,5]},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number",default:100},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number",default:50}],ve=U(he),me={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},ye={propertyAliases:ve,operatorData:me,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i]=yield B([e.values,e.from,e.subtract],t);t.typeChecker(R(me.parameters,{values:r,from:a,subtract:i}));const s=null!=r?r:[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",default:[5,5]}],ge=U(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);if(t.typeChecker(R(be.parameters,{values:r})),0===r.length)return 0;if(r.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return r.reduce(((e,t)=>e*t))})),parseChildren:V},Oe=[{name:"values",description:"Array of values - 1st element will be divided by the first",aliases:[],required:!1,type:"array",default:[100,10]},{name:"dividend",description:"The number that will be divided",aliases:["divide"],required:!1,type:"number",default:99},{name:"divisor",description:"The number that dividend will be divided by",aliases:["by","divideBy"],required:!1,type:"number",default:3},{name:"output",description:"Whether to output a quotient, remainder or decimal",aliases:[],required:!1,type:{literal:["quotient","remainder"]},default:"quotient"}],Ce=U(Oe),qe={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},je={propertyAliases:Ce,operatorData:qe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield B([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(R(qe.parameters,{values:r,dividend:a,divisor:i,output:s}));const n=null!=r?r:[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",default:[10,9]},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],Ee=U(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,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(R(Se.parameters,{values:r,strict:a})),r.length<2)throw new Error("- Not enough values provided");const[i,s]=r;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",default:[9,10]},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],xe=U(Pe),we={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ie={propertyAliases:xe,operatorData:we,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(R(we.parameters,{values:r,strict:a})),r.length<2)throw new Error("- Not enough values provided");const[i,s]=r;return i===s&&!a||i<s})),parseChildren:V},Ue=[{name:"condition",description:"The expression to check for truthiness",aliases:[],required:!0,type:"any",default:!0},{name:"valueIfTrue",description:"Value to return if condition is true",aliases:["ifTrue"],required:!0,type:"any",default:"The condition is true"},{name:"valueIfFalse",description:"Value to return if condition is false",aliases:["ifFalse","ifNot"],required:!0,type:"any",default:"The condition is false"}],Re=U(Ue),Le={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ue},ke={propertyAliases:Re,operatorData:Le,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(Le.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield $(e.condition,t))?yield $(e.valueIfTrue,t):yield $(e.valueIfFalse,t)})),parseChildren:e=>{const[t,r,a]=e.children;return Object.assign(Object.assign({},e),{condition:t,valueIfTrue:r,valueIfFalse:a})}},De=[{name:"testString",description:"The string to test",aliases:["string","value"],required:!0,type:"string",default:"test-this"},{name:"pattern",description:"The regular expression pattern",aliases:["regex","regexp","regExp","re"],required:!0,type:"string",default:"^[a-z]{4}-[a-z]{4}$"}],_e=U(De),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},Fe={propertyAliases:_e,operatorData:Me,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a]=yield B([e.testString,e.pattern],t);t.typeChecker(R(Me.parameters,{testString:r,pattern:a}));try{return new RegExp(a).test(r)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[t,r]=e.children;return Object.assign(Object.assign({},e),{testString:t,pattern:r})}},He=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string",default:"path.to[0].my.data"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object",default:{}}],$e=U(He),Be={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:He},Ge={propertyAliases:$e,operatorData:Be,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s,n;const[o,l]=yield B([e.property,e.additionalData],t);t.typeChecker(R(Be.parameters,{property:o,additionalData:l}));const u=l?Object.assign(Object.assign({},null!==(i=null===(a=t.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),l):null!==(n=null===(s=t.options)||void 0===s?void 0:s.data)&&void 0!==n?n:{};return r(u,o)})),parseChildren:e=>{const[t,r]=e.children,a=Object.assign(Object.assign({},e),{property:t});return void 0!==r&&(a.fallback=r),a}},Qe=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string",default:"Hello, %1"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!0,type:["array","object"],default:["friend"]},{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",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],We=U(Qe),ze={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:Qe},Je={propertyAliases:We,operatorData:ze,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i=!0,s="%",n={}]=yield B([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(R(ze.parameters,{string:r,substitutions:a,trimWhiteSpace:i,substitutionCharacter:s,numberMapping:n})),Array.isArray(a)){const e="$"===s?"$":"%",t=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(r.match(t)||[]).sort(((e,t)=>Number(e.slice(1))-Number(t.slice(1)))),o=new Set(n),l=L(Array.from(o),a.map((e=>i?String(e).trim():e)));return r.split(t).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}return r.split(/(?<!\\)({{[A-z0-9_]+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const t=Ve(e,a,n);return i?String(t).trim():t})).join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ve=(e,t,r)=>{var a,i;const s=e.replace(/{{(.+)}}/,"$1"),n=null!==(a=null==t?void 0:t[s])&&void 0!==a?a:"";if("number"!=typeof n)return null!==(i=null==t?void 0:t[s])&&void 0!==i?i:"";if(!(s in r))return n;const o=r[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(r[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},Ye=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Xe=U(Ye),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Ye},Ze={propertyAliases:Xe,operatorData:Ke,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(Ke.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},et=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string",default:"Alpha, Bravo, Charlie"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string",default:","},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{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",default:!0}],tt=U(et),rt={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:et},at=" ",it={propertyAliases:tt,operatorData:rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield B([e.value,null!==(r=e.delimiter)&&void 0!==r?r:at,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(R(rt.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[t,r=at]=e.children;return Object.assign(Object.assign({},e),{value:t,delimiter:r})}},st=[{name:"query",description:"A SQL query string, with parameterised replacements (i.e. $1, $2, etc)",aliases:[],required:!0,type:"string",default:"SELECT contact_name FROM customers;"},{name:"values",description:"An array of values to replace in the SQL string parameters",aliases:["replacements"],required:!1,type:"array",default:[]},{name:"type",description:"Determines the shape of the resulting data (see documentation)",aliases:["queryType"],required:!1,type:{literal:["array","string","number"]},default:"array"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],nt=U(st),ot={description:"Query a Postgres database using node-postgres",aliases:["pgSql","sql","postgres","pg","pgDb"],parameters:st},lt=(e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i={text:e,values:t,rowMode:a?"array":""},s=yield r.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}})),ut={propertyAliases:nt,operatorData:ot,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u]=yield B([e.query,e.type,e.values||[],e.useCache],t);if(t.typeChecker(R(ot.parameters,{query:n,type:o,values:l,useCache:u})),!(null===(r=t.options)||void 0===r?void 0:r.pgConnection))throw new Error("No Postgres database connection provided");const d=null===(s=null!==(a=e.useCache)&&void 0!==a?a:t.options.useCache)||void 0===s||s;return t.cache.useCache(d,((e,r,a)=>i(void 0,void 0,void 0,(function*(){return yield lt(e,a,t.options.pgConnection,r)}))),n,o,l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{query:t,values:r})}},dt=[{name:"query",description:"GraphQL query string",aliases:[],required:!0,type:"string",default:'query getCountries {\n countries(filter: {continent: {eq: "OC"}}) {\n name\n }\n }'},{name:"url",description:"Endpoint for the GraphQL request (if not already provided in options)",aliases:["endpoint"],required:!1,type:["string","null"],default:"https://countries.trevorblades.com/"},{name:"headers",description:"HTTP Headers (if not already provided in options)",aliases:[],required:!1,type:"object",default:{}},{name:"variables",description:"Values for the variables used in query (key-value pairs)",aliases:[],required:!1,type:"object",default:{}},{name:"returnNode",description:"Property path to extract from the query response",aliases:["outputNode","returnProperty"],required:!1,type:"string",default:"data.countries[1].name"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],ct=U(dt),pt={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:dt},ht={propertyAliases:ct,operatorData:pt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s,n,o,l;const[u,d,c,p,h,v]=yield B([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],t),{url:m,headers:y}=d instanceof Object?d:{url:d,headers:null};t.typeChecker([...R(pt.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===(r=t.options.graphQLConnection)||void 0===r?void 0:r.endpoint)&&void 0!==a?a:t.options.baseEndpoint)&&void 0!==s?s:"",b=M(f)?f:F(g,f),T={query:u,variables:c},O=null===(n=null!=v?v:t.options.useCache)||void 0===n||n,C=yield t.cache.useCache(O,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H({url:e,method:"post",data:t,headers:r});return _(i.data,a)}))),b,T,Object.assign(Object.assign(Object.assign(Object.assign({},null===(o=t.options.graphQLConnection)||void 0===o?void 0:o.headers),null===(l=t.options)||void 0===l?void 0:l.headers),y),h),p);return C})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield B(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=L(n,o),u=Object.assign(Object.assign({},e),{query:r,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},vt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://restcountries.com/v3.1/name/zealand"},{name:"returnProperty",description:"Property from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"Query parameters (key-value)",aliases:["queryParams","queryParameters","urlQueries"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],mt=U(vt),yt={description:"HTTP GET Request",aliases:["get","api"],parameters:vt},ft=(e,t)=>i(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield B(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=L(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gt=ft,bt={propertyAliases:mt,operatorData:yt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u,d]=yield B([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};t.typeChecker([...R(yt.parameters,{url:c,returnProperty:l,headers:u,parameters:o,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",v=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),p),u),m=null===(s=null!=d?d:t.options.useCache)||void 0===s||s,y=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H({url:e,params:t,headers:r});return _(i,a)}))),M(c)?c:F(h,c),o,v,l);return y})),parseChildren:ft},Tt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://jsonplaceholder.typicode.com/posts"},{name:"returnProperty",description:"Property path from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"JSON Body parameters (key-value)",aliases:["bodyJson","data"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],Ot=U(Tt),Ct={description:"HTTP POST Request",aliases:["post"],parameters:Tt},qt={propertyAliases:Ot,operatorData:Ct,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u,d]=yield B([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};t.typeChecker([...R(Ct.parameters,{url:c,headers:u,data:o,returnProperty:l,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",v=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),p),u),m=null!==(s=null!=d?d:t.options.useCache)&&void 0!==s&&s;return yield t.cache.useCache(m,(()=>i(void 0,void 0,void 0,(function*(){const e=yield H({url:c,data:o,headers:u,method:"post"});return _(e,l)}))),M(c)?c:F(h,c),o,v,l)})),parseChildren:gt},jt=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array",default:["firstKey","firstValue","secondKey","secondValue"]}],At=U(jt),Et={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:jt},St={propertyAliases:At,operatorData:Et,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(Et.parameters,{properties:e.properties}));const r=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:r})=>{return a=[e,r],i(void 0,void 0,void 0,(function*(){const[e,r]=yield B(a,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var a}));return Object.fromEntries(yield Promise.all(r))})),parseChildren:e=>{const t=e.children;if(t.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=t.filter(((e,t)=>t%2==0)),a=t.filter(((e,t)=>t%2==1)),i=r.map(((e,t)=>({key:e,value:a[t]})));return Object.assign(Object.assign({},e),{properties:i})}},Nt=[{name:"matchExpression",description:"Expression to match against",aliases:["match"],required:!0,type:["string","number","boolean"],default:"matchMe"},{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"],default:{matchMe:"YES",nonMatch:"NO"}},{name:"[...branches]",description:"Branch properties can optionally be placed at the operator root",aliases:[],required:!1,type:["object","array"]}],Pt={propertyAliases:U(Nt),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Nt},evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r;const a=yield $(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=s(i)?yield $(i,t):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield $(n[a],t);if("fallback"in n)return yield $(n.fallback,t);if(a in e)return yield $(e[a],t);throw new Error(`No match found for ${a}`)})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=k(yield B(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},xt=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array",default:[]},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],wt=U(xt),It={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:xt},Ut={propertyAliases:wt,operatorData:It,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield B([e.functionPath,e.args,e.useCache],t);t.typeChecker(R(It.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=t.options,p=null!==(s=null!==(a=r(c,o,null))&&void 0!==a?a:r(d,o,null))&&void 0!==s?s:r(t.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:t.options.useCache)&&void 0!==n&&n;return yield t.cache.useCache(h,((e,...t)=>i(void 0,void 0,void 0,(function*(){return yield p(...t)}))),o,...l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionPath:t,args:r})}},Rt=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Lt=U(Rt),kt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Rt},Dt={propertyAliases:Lt,operatorData:kt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){return t.typeChecker(R(kt.parameters,{value:e.value})),yield $(e.value,t)})),parseChildren:e=>{const[...t]=e.children,r=1===(null==t?void 0:t.length)?t[0]:t;return Object.assign(Object.assign({},e),{value:r})}};var _t=Object.freeze({__proto__:null,AND:Y,BUILD_OBJECT:St,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Ut,DIVIDE:je,EQUAL:ie,GET:bt,GRAPHQL:ht,GREATER_THAN:Ne,LESS_THAN:Ie,MATCH:Pt,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:Ge,OR:ee,PASSTHRU:Dt,PG_SQL:ut,PLUS:pe,POST:qt,REGEX:Fe,SPLIT:it,STRING_SUBSTITUTION:Je,SUBTRACT:ye});class Mt{constructor(e){var t,r;this.useCache=(e,t,...r)=>i(this,void 0,void 0,(function*(){if(!e)return yield t(...r);const a=Ft(r),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 t(...r)),this.store[a].result;const o=yield t(...r);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!==(t=null==e?void 0:e.maxSize)&&void 0!==t?t:50,this.maxTime=null!==(r=null==e?void 0:e.maxTime)&&void 0!==r?r:1800}}const Ft=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_");class Ht{constructor(e={}){var t,r;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=P(...t);if(!0!==r)throw new Error(r)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.13.5",this.options=$t(e),this.operators=u(_t,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],T),this.operatorAliases=T,this.cache=new Mt({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime})}evaluate(e,t={}){return i(this,void 0,void 0,(function*(){const r=m(this.options,$t(t));return r.maxCacheSize&&r.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(r.maxCacheSize),r.maxCacheTime&&r.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(r.maxCacheTime),yield $(e,{options:r,operators:t.excludeOperators?u(_t,t.excludeOperators,T):this.operators,operatorAliases:this.operatorAliases,typeChecker:r.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache})}))}getOptions(){return this.options}updateOptions(e){this.options=m(this.options,$t(e)),this.options.excludeOperators&&(this.operators=u(_t,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(_t,this.options.excludeOperators,T):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(T))];return t.sort(((e,t)=>r.indexOf(e.name)-r.indexOf(t.name)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,t])=>Object.assign({name:e},null==t?void 0:t.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,t])=>({name:e,numRequiredArgs:t.length})))}}const $t=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;exports.FigTreeEvaluator=Ht,exports.evaluateExpression=(e,t)=>new Ht(t).evaluate(e),exports.isAliasString=h,exports.isFragmentNode=n,exports.isObject=b,exports.isOperatorNode=s,exports.standardiseOperatorName=o,exports.truncateString=d;
1
+ "use strict";var e=require("change-case"),t=require("axios"),r=require("object-property-extractor"),a=require("dequal/lite");function i(e,t,r,a){return new(r||(r=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 t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=t=>{const r=e.camelCase(t);return r||t},l=(e,t)=>t[o(e)],u=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[o(e)]]})),a},d=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,c=(e,t,r=!1)=>{if(void 0!==e)return e;if(r)return d(t);throw new Error(d(t))},p=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&h(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},m=(e,t)=>{const r=Object.assign(Object.assign({},e),t);return(e.data||t.data)&&(r.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(r.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(r.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(r.headers=Object.assign(Object.assign({},e.headers),t.headers)),r},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 t=new RegExp(/-?\d*\.?\d+/gm),r=e.match(t);return r?Number(r[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=/(\$[^()]+)\((.*)\)/,q=(e,t={},r=!0)=>r?"string"==typeof e?j(e,t):b(e)?A(e,t):e:e,j=(e,t)=>{const r=C.exec(e);if(!r)return e;const a=r[1].trim(),i=r[2].split(",").map((e=>q(e.trim(),t)));return E(a,i,t)},A=(e,t)=>{if(s(e)||n(e))return e;const r=Object.entries(e),a=r.filter((([e])=>h(e))),i=r.filter((([e])=>!h(e))),o=a.reduce(((e,[r,a])=>e=Object.assign(Object.assign({},e),E(r,a,t))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,t,r)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(t)?{operator:i,children:t}:b(t)&&!Object.keys(t).some((e=>h(e)))?Object.assign({operator:i},t):{operator:i,children:[t]}:a in r?{fragment:a,parameters:Object.assign({},t)}:{[e]:t}},S=e=>b(e)&&"literal"in e,N=({value:e,name:t,expectedType:r})=>{if(S(r)){const{literal:a}=r;return!!a.includes(e)||w(t,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(r))return!!r.some((r=>!0===N({value:e,name:t,expectedType:r})))||w(t,e,r.join("|"));return!!(0,x[r])(e)||w(t,e,r)},P=(...e)=>{const t=[];return e.forEach((e=>{const r=N(e);!0!==r&&t.push(r)})),!(t.length>0)||t.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,t,r)=>void 0===t&&e?`- Missing required property "${e}" (type: ${r})`:void 0!==e?`- Property "${e}" (value: ${I(t)}) is not of type: ${r}`:`- ${I(t)} is not of type: ${r}`,I=e=>{const t=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return d(t,50)},U=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},R=(e,t)=>e.map((({name:e,required:r,type:a})=>{if(S(a)){const i=[...a.literal];return r||i.push(void 0),{name:e,value:t[e],expectedType:{literal:i}}}const i=Array.isArray(a)?a:[a];r||i.push("undefined");const s=1===i.length?i[0]:i;return{name:e,value:t[e],expectedType:s}})),L=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=e.filter(((e,t)=>t%2==0)),r=P(...t.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==r)throw new Error(r);const a=e.filter(((e,t)=>t%2==1)),i={};return t.forEach(((e,t)=>{i[e]=a[t]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(e,t,a=void 0)=>{const i=t?r(e,t,a):e;return Array.isArray(i)?i.map((e=>D(e))):t?null===i?null:D(i):i},M=e=>/^https?:\/\/.+/.test(e),F=(...e)=>e.reduce(((e,t,r)=>{const a="/"===t[0]?1:0,i="/"===t.slice(-1)?-1:void 0,s=t.slice(a,i);return""===s?e:e+(0===r?"":"/")+s}),""),H=({url:e,params:r={},data:a={},headers:s={},method:n="get"})=>i(void 0,void 0,void 0,(function*(){var i;try{return(yield t({method:n,url:e,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:r,data:a})).data}catch(e){if(t.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}})),$=(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i,o;const{options:u,operators:d,operatorAliases:h}=t;let m=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return s(t)?t:e}catch(t){return e}})(e):e;m=q(m,null===(r=t.options)||void 0===r?void 0:r.fragments,!u.noShorthand),Array.isArray(m)&&(m=yield B(m,t));const g=s(m),T=n(m);if(u.evaluateFullObject&&!g&&!T)return v(yield Q(m,t),t);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(m)&&"value"in m?m.value:v(m,t);const{fallback:O}=m,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,r]=yield B([m.fragment,m.parameters],t),a=q(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 $(O,t),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,t);m=Object.assign(Object.assign(Object.assign({},m),a),r),delete m.fragment}try{const e=l(m.operator,h);if(!e)return c(yield $(O,t),`Invalid operator: ${m.operator}`,C);if(!t.operators[e])return c(yield $(O,t),`Excluded operator: ${m.operator}`,C);const{propertyAliases:r,evaluate:a,parseChildren:i}=d[e];m=((e,t)=>p(t,(t=>t in e?e[t]:t)))(r,m);const s=yield G(m,t);T||Object.entries(s).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const n=T?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),s)}):t;if("children"in m){if(Array.isArray(m.children)||(m.children=yield $(m.children,n)),!Array.isArray(m.children))return c(yield $(O,t),`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(r){return c(yield $(m.fallback,t),`Operator: ${e}\n${f(r)}`,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 $(v,t);return g in y?y[g](u):c(yield $(O,t),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield $(O,t),f(e),C)}})),B=(e,t)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>$(e,t)))):yield $(e,t)})),G=(e,t)=>i(void 0,void 0,void 0,(function*(){const r=Object.keys(e).filter(h);if(0===r.length)return{};const a=[];return r.forEach((r=>a.push($(e[r],t)))),L(r,yield Promise.all(a))})),Q=(e,t)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{h(r)&&(a.push(r,$(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,$(a,t))}));const s=yield Promise.all(r);return v(k(s),t)})),W=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],z=U(W),J={description:"Logical AND",aliases:["and","&","&&"],parameters:W},V=e=>{const t=e.children;return Object.assign(Object.assign({},e),{values:t})},Y={propertyAliases:z,operatorData:J,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(J.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:V},X=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],K=U(X),Z={description:"Logical OR",aliases:["or","|","||"],parameters:X},ee={propertyAliases:K,operatorData:Z,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(Z.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:V},te=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array",default:["These are equal","These are equal"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],re=U(te),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:te},ie={propertyAliases:re,operatorData:ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(ae.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=t.options)||void 0===r?void 0:r.caseInsensitive)&&void 0!==i&&i)&&n.every((e=>"string"==typeof e))?n.map((e=>e.toLowerCase())):n;return!(void 0!==l?l:void 0!==(null===(s=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>a.dequal(e,u[0]))):u.every((e=>null==e))})),parseChildren:V},se=[{name:"values",description:"Array of values to check for inequality",aliases:[],required:!0,type:"array",default:["These items","don't match"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],ne=U(se),oe={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:se},le={propertyAliases:ne,operatorData:oe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(oe.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=t.options)||void 0===r?void 0:r.caseInsensitive)&&void 0!==i&&i)&&n.every((e=>"string"==typeof e))?n.map((e=>e.toLowerCase())):n;return!(void 0!==l?l:void 0!==(null===(s=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!a.dequal(e,u[0]))):u.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",default:[1,2,3]},{name:"type",description:"Data type to coerce input values to before addition",aliases:[],required:!1,type:{literal:["string","array","number","boolean","bool"]},default:"string"}],de=U(ue),ce={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ue},pe={propertyAliases:de,operatorData:ce,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(ce.parameters,{values:r,type:e.type})),0===r.length?r:"string"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),""):"array"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),[]):r.every((e=>"string"==typeof e||Array.isArray(e)))?r.reduce(((e,t)=>e.concat(t))):r.every((e=>b(e)))?r.reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{}):r.reduce(((e,t)=>e+t))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array",default:[10,5]},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number",default:100},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number",default:50}],ve=U(he),me={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},ye={propertyAliases:ve,operatorData:me,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i]=yield B([e.values,e.from,e.subtract],t);t.typeChecker(R(me.parameters,{values:r,from:a,subtract:i}));const s=null!=r?r:[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",default:[5,5]}],ge=U(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);if(t.typeChecker(R(be.parameters,{values:r})),0===r.length)return 0;if(r.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return r.reduce(((e,t)=>e*t))})),parseChildren:V},Oe=[{name:"values",description:"Array of values - 1st element will be divided by the first",aliases:[],required:!1,type:"array",default:[100,10]},{name:"dividend",description:"The number that will be divided",aliases:["divide"],required:!1,type:"number",default:99},{name:"divisor",description:"The number that dividend will be divided by",aliases:["by","divideBy"],required:!1,type:"number",default:3},{name:"output",description:"Whether to output a quotient, remainder or decimal",aliases:[],required:!1,type:{literal:["quotient","remainder"]},default:"quotient"}],Ce=U(Oe),qe={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},je={propertyAliases:Ce,operatorData:qe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield B([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(R(qe.parameters,{values:r,dividend:a,divisor:i,output:s}));const n=null!=r?r:[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",default:[10,9]},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],Ee=U(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,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(R(Se.parameters,{values:r,strict:a})),r.length<2)throw new Error("- Not enough values provided");const[i,s]=r;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",default:[9,10]},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],xe=U(Pe),we={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ie={propertyAliases:xe,operatorData:we,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(R(we.parameters,{values:r,strict:a})),r.length<2)throw new Error("- Not enough values provided");const[i,s]=r;return i===s&&!a||i<s})),parseChildren:V},Ue=[{name:"condition",description:"The expression to check for truthiness",aliases:[],required:!0,type:"any",default:!0},{name:"valueIfTrue",description:"Value to return if condition is true",aliases:["ifTrue"],required:!0,type:"any",default:"The condition is true"},{name:"valueIfFalse",description:"Value to return if condition is false",aliases:["ifFalse","ifNot"],required:!0,type:"any",default:"The condition is false"}],Re=U(Ue),Le={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ue},ke={propertyAliases:Re,operatorData:Le,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(Le.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield $(e.condition,t))?yield $(e.valueIfTrue,t):yield $(e.valueIfFalse,t)})),parseChildren:e=>{const[t,r,a]=e.children;return Object.assign(Object.assign({},e),{condition:t,valueIfTrue:r,valueIfFalse:a})}},De=[{name:"testString",description:"The string to test",aliases:["string","value"],required:!0,type:"string",default:"test-this"},{name:"pattern",description:"The regular expression pattern",aliases:["regex","regexp","regExp","re"],required:!0,type:"string",default:"^[a-z]{4}-[a-z]{4}$"}],_e=U(De),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},Fe={propertyAliases:_e,operatorData:Me,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a]=yield B([e.testString,e.pattern],t);t.typeChecker(R(Me.parameters,{testString:r,pattern:a}));try{return new RegExp(a).test(r)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[t,r]=e.children;return Object.assign(Object.assign({},e),{testString:t,pattern:r})}},He=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string",default:"path.to[0].my.data"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object",default:{}}],$e=U(He),Be={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:He},Ge={propertyAliases:$e,operatorData:Be,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,i;const[s,n={}]=yield B([e.property,e.additionalData],t);t.typeChecker(R(Be.parameters,{property:s,additionalData:n}));const o=Object.assign(Object.assign({},null!==(i=null===(a=t.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),n);return r(o,s)})),parseChildren:e=>{const[t,r]=e.children,a=Object.assign(Object.assign({},e),{property:t});return void 0!==r&&(a.fallback=r),a}},Qe=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string",default:"Hello, %1"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!1,type:["array","object"],default:["friend"]},{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",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],We=U(Qe),ze={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:Qe},Je={propertyAliases:We,operatorData:ze,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a={},i=!0,s="%",n={}]=yield B([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(R(ze.parameters,{string:r,substitutions:a,trimWhiteSpace:i,substitutionCharacter:s,numberMapping:n})),Array.isArray(a)){const e="$"===s?"$":"%",t=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(r.match(t)||[]).sort(((e,t)=>Number(e.slice(1))-Number(t.slice(1)))),o=new Set(n),l=L(Array.from(o),a.map((e=>i?String(e).trim():e)));return r.split(t).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}return r.split(/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ve(e,a,n,t.options.data);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ve=(e,t,a,i={})=>{const s=e.replace(/{{(.+)}}/,"$1"),n=r(t,s,r(i,s,""));if("number"!=typeof n)return n;if(!(s in a))return n;const o=a[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(a[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},Ye=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Xe=U(Ye),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Ye},Ze={propertyAliases:Xe,operatorData:Ke,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(Ke.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},et=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string",default:"Alpha, Bravo, Charlie"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string",default:","},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{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",default:!0}],tt=U(et),rt={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:et},at=" ",it={propertyAliases:tt,operatorData:rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield B([e.value,null!==(r=e.delimiter)&&void 0!==r?r:at,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(R(rt.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[t,r=at]=e.children;return Object.assign(Object.assign({},e),{value:t,delimiter:r})}},st=[{name:"query",description:"A SQL query string, with parameterised replacements (i.e. $1, $2, etc)",aliases:[],required:!0,type:"string",default:"SELECT contact_name FROM customers;"},{name:"values",description:"An array of values to replace in the SQL string parameters",aliases:["replacements"],required:!1,type:"array",default:[]},{name:"type",description:"Determines the shape of the resulting data (see documentation)",aliases:["queryType"],required:!1,type:{literal:["array","string","number"]},default:"array"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],nt=U(st),ot={description:"Query a Postgres database using node-postgres",aliases:["pgSql","sql","postgres","pg","pgDb"],parameters:st},lt=(e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i={text:e,values:t,rowMode:a?"array":""},s=yield r.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}})),ut={propertyAliases:nt,operatorData:ot,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u]=yield B([e.query,e.type,e.values||[],e.useCache],t);if(t.typeChecker(R(ot.parameters,{query:n,type:o,values:l,useCache:u})),!(null===(r=t.options)||void 0===r?void 0:r.pgConnection))throw new Error("No Postgres database connection provided");const d=null===(s=null!==(a=e.useCache)&&void 0!==a?a:t.options.useCache)||void 0===s||s;return t.cache.useCache(d,((e,r,a)=>i(void 0,void 0,void 0,(function*(){return yield lt(e,a,t.options.pgConnection,r)}))),n,o,l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{query:t,values:r})}},dt=[{name:"query",description:"GraphQL query string",aliases:[],required:!0,type:"string",default:'query getCountries {\n countries(filter: {continent: {eq: "OC"}}) {\n name\n }\n }'},{name:"url",description:"Endpoint for the GraphQL request (if not already provided in options)",aliases:["endpoint"],required:!1,type:["string","null"],default:"https://countries.trevorblades.com/"},{name:"headers",description:"HTTP Headers (if not already provided in options)",aliases:[],required:!1,type:"object",default:{}},{name:"variables",description:"Values for the variables used in query (key-value pairs)",aliases:[],required:!1,type:"object",default:{}},{name:"returnNode",description:"Property path to extract from the query response",aliases:["outputNode","returnProperty"],required:!1,type:"string",default:"data.countries[1].name"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],ct=U(dt),pt={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:dt},ht={propertyAliases:ct,operatorData:pt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s,n,o,l;const[u,d,c,p,h,v]=yield B([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],t),{url:m,headers:y}=d instanceof Object?d:{url:d,headers:null};t.typeChecker([...R(pt.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===(r=t.options.graphQLConnection)||void 0===r?void 0:r.endpoint)&&void 0!==a?a:t.options.baseEndpoint)&&void 0!==s?s:"",b=M(f)?f:F(g,f),T={query:u,variables:c},O=null===(n=null!=v?v:t.options.useCache)||void 0===n||n,C=yield t.cache.useCache(O,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H({url:e,method:"post",data:t,headers:r});return _(i.data,a)}))),b,T,Object.assign(Object.assign(Object.assign(Object.assign({},null===(o=t.options.graphQLConnection)||void 0===o?void 0:o.headers),null===(l=t.options)||void 0===l?void 0:l.headers),y),h),p);return C})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield B(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=L(n,o),u=Object.assign(Object.assign({},e),{query:r,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},vt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://restcountries.com/v3.1/name/zealand"},{name:"returnProperty",description:"Property from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"Query parameters (key-value)",aliases:["queryParams","queryParameters","urlQueries"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],mt=U(vt),yt={description:"HTTP GET Request",aliases:["get","api"],parameters:vt},ft=(e,t)=>i(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield B(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=L(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gt=ft,bt={propertyAliases:mt,operatorData:yt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u,d]=yield B([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};t.typeChecker([...R(yt.parameters,{url:c,returnProperty:l,headers:u,parameters:o,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",v=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),p),u),m=null===(s=null!=d?d:t.options.useCache)||void 0===s||s,y=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H({url:e,params:t,headers:r});return _(i,a)}))),M(c)?c:F(h,c),o,v,l);return y})),parseChildren:ft},Tt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://jsonplaceholder.typicode.com/posts"},{name:"returnProperty",description:"Property path from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"JSON Body parameters (key-value)",aliases:["bodyJson","data"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],Ot=U(Tt),Ct={description:"HTTP POST Request",aliases:["post"],parameters:Tt},qt={propertyAliases:Ot,operatorData:Ct,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u,d]=yield B([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};t.typeChecker([...R(Ct.parameters,{url:c,headers:u,data:o,returnProperty:l,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",v=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),p),u),m=null!==(s=null!=d?d:t.options.useCache)&&void 0!==s&&s;return yield t.cache.useCache(m,(()=>i(void 0,void 0,void 0,(function*(){const e=yield H({url:c,data:o,headers:u,method:"post"});return _(e,l)}))),M(c)?c:F(h,c),o,v,l)})),parseChildren:gt},jt=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array",default:["firstKey","firstValue","secondKey","secondValue"]}],At=U(jt),Et={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:jt},St={propertyAliases:At,operatorData:Et,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(Et.parameters,{properties:e.properties}));const r=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:r})=>{return a=[e,r],i(void 0,void 0,void 0,(function*(){const[e,r]=yield B(a,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var a}));return Object.fromEntries(yield Promise.all(r))})),parseChildren:e=>{const t=e.children;if(t.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=t.filter(((e,t)=>t%2==0)),a=t.filter(((e,t)=>t%2==1)),i=r.map(((e,t)=>({key:e,value:a[t]})));return Object.assign(Object.assign({},e),{properties:i})}},Nt=[{name:"matchExpression",description:"Expression to match against",aliases:["match"],required:!0,type:["string","number","boolean"],default:"matchMe"},{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"],default:{matchMe:"YES",nonMatch:"NO"}},{name:"[...branches]",description:"Branch properties can optionally be placed at the operator root",aliases:[],required:!1,type:["object","array"]}],Pt={propertyAliases:U(Nt),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Nt},evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r;const a=yield $(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=s(i)?yield $(i,t):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield $(n[a],t);if("fallback"in n)return yield $(n.fallback,t);if(a in e)return yield $(e[a],t);throw new Error(`No match found for ${a}`)})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=k(yield B(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},xt=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array",default:[]},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],wt=U(xt),It={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:xt},Ut={propertyAliases:wt,operatorData:It,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield B([e.functionPath,e.args,e.useCache],t);t.typeChecker(R(It.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=t.options,p=null!==(s=null!==(a=r(c,o,null))&&void 0!==a?a:r(d,o,null))&&void 0!==s?s:r(t.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:t.options.useCache)&&void 0!==n&&n;return yield t.cache.useCache(h,((e,...t)=>i(void 0,void 0,void 0,(function*(){return yield p(...t)}))),o,...l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionPath:t,args:r})}},Rt=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Lt=U(Rt),kt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Rt},Dt={propertyAliases:Lt,operatorData:kt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){return t.typeChecker(R(kt.parameters,{value:e.value})),yield $(e.value,t)})),parseChildren:e=>{const[...t]=e.children,r=1===(null==t?void 0:t.length)?t[0]:t;return Object.assign(Object.assign({},e),{value:r})}};var _t=Object.freeze({__proto__:null,AND:Y,BUILD_OBJECT:St,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Ut,DIVIDE:je,EQUAL:ie,GET:bt,GRAPHQL:ht,GREATER_THAN:Ne,LESS_THAN:Ie,MATCH:Pt,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:Ge,OR:ee,PASSTHRU:Dt,PG_SQL:ut,PLUS:pe,POST:qt,REGEX:Fe,SPLIT:it,STRING_SUBSTITUTION:Je,SUBTRACT:ye});class Mt{constructor(e){var t,r;this.useCache=(e,t,...r)=>i(this,void 0,void 0,(function*(){if(!e)return yield t(...r);const a=Ft(r),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 t(...r)),this.store[a].result;const o=yield t(...r);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!==(t=null==e?void 0:e.maxSize)&&void 0!==t?t:50,this.maxTime=null!==(r=null==e?void 0:e.maxTime)&&void 0!==r?r:1800}}const Ft=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_");class Ht{constructor(e={}){var t,r;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=P(...t);if(!0!==r)throw new Error(r)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.14.0",this.options=$t(e),this.operators=u(_t,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],T),this.operatorAliases=T,this.cache=new Mt({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime})}evaluate(e,t={}){return i(this,void 0,void 0,(function*(){const r=m(this.options,$t(t));return r.maxCacheSize&&r.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(r.maxCacheSize),r.maxCacheTime&&r.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(r.maxCacheTime),yield $(e,{options:r,operators:t.excludeOperators?u(_t,t.excludeOperators,T):this.operators,operatorAliases:this.operatorAliases,typeChecker:r.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache})}))}getOptions(){return this.options}updateOptions(e){this.options=m(this.options,$t(e)),this.options.excludeOperators&&(this.operators=u(_t,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(_t,this.options.excludeOperators,T):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(T))];return t.sort(((e,t)=>r.indexOf(e.name)-r.indexOf(t.name)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,t])=>Object.assign({name:e},null==t?void 0:t.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,t])=>({name:e,numRequiredArgs:t.length})))}}const $t=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;exports.FigTreeEvaluator=Ht,exports.evaluateExpression=(e,t)=>new Ht(t).evaluate(e),exports.isAliasString=h,exports.isFragmentNode=n,exports.isObject=b,exports.isOperatorNode=s,exports.standardiseOperatorName=o,exports.truncateString=d;
@@ -1 +1 @@
1
- import{camelCase as e}from"change-case";import t from"axios";import r from"object-property-extractor";import{dequal as a}from"dequal/lite";function i(e,t,r,a){return new(r||(r=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 t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=t=>{const r=e(t);return r||t},l=(e,t)=>t[o(e)],u=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[o(e)]]})),a},d=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,c=(e,t,r=!1)=>{if(void 0!==e)return e;if(r)return d(t);throw new Error(d(t))},p=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&h(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},m=(e,t)=>{const r=Object.assign(Object.assign({},e),t);return(e.data||t.data)&&(r.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(r.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(r.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(r.headers=Object.assign(Object.assign({},e.headers),t.headers)),r},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 t=new RegExp(/-?\d*\.?\d+/gm),r=e.match(t);return r?Number(r[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,t={},r=!0)=>r?"string"==typeof e?q(e,t):b(e)?A(e,t):e:e,q=(e,t)=>{const r=C.exec(e);if(!r)return e;const a=r[1].trim(),i=r[2].split(",").map((e=>j(e.trim(),t)));return E(a,i,t)},A=(e,t)=>{if(s(e)||n(e))return e;const r=Object.entries(e),a=r.filter((([e])=>h(e))),i=r.filter((([e])=>!h(e))),o=a.reduce(((e,[r,a])=>e=Object.assign(Object.assign({},e),E(r,a,t))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,t,r)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(t)?{operator:i,children:t}:b(t)&&!Object.keys(t).some((e=>h(e)))?Object.assign({operator:i},t):{operator:i,children:[t]}:a in r?{fragment:a,parameters:Object.assign({},t)}:{[e]:t}},S=e=>b(e)&&"literal"in e,N=({value:e,name:t,expectedType:r})=>{if(S(r)){const{literal:a}=r;return!!a.includes(e)||w(t,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(r))return!!r.some((r=>!0===N({value:e,name:t,expectedType:r})))||w(t,e,r.join("|"));return!!(0,x[r])(e)||w(t,e,r)},P=(...e)=>{const t=[];return e.forEach((e=>{const r=N(e);!0!==r&&t.push(r)})),!(t.length>0)||t.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,t,r)=>void 0===t&&e?`- Missing required property "${e}" (type: ${r})`:void 0!==e?`- Property "${e}" (value: ${I(t)}) is not of type: ${r}`:`- ${I(t)} is not of type: ${r}`,I=e=>{const t=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return d(t,50)},U=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},R=(e,t)=>e.map((({name:e,required:r,type:a})=>{if(S(a)){const i=[...a.literal];return r||i.push(void 0),{name:e,value:t[e],expectedType:{literal:i}}}const i=Array.isArray(a)?a:[a];r||i.push("undefined");const s=1===i.length?i[0]:i;return{name:e,value:t[e],expectedType:s}})),L=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=e.filter(((e,t)=>t%2==0)),r=P(...t.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==r)throw new Error(r);const a=e.filter(((e,t)=>t%2==1)),i={};return t.forEach(((e,t)=>{i[e]=a[t]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(e,t,a=void 0)=>{const i=t?r(e,t,a):e;return Array.isArray(i)?i.map((e=>D(e))):t?null===i?null:D(i):i},M=e=>/^https?:\/\/.+/.test(e),H=(...e)=>e.reduce(((e,t,r)=>{const a="/"===t[0]?1:0,i="/"===t.slice(-1)?-1:void 0,s=t.slice(a,i);return""===s?e:e+(0===r?"":"/")+s}),""),$=({url:e,params:r={},data:a={},headers:s={},method:n="get"})=>i(void 0,void 0,void 0,(function*(){var i;try{return(yield t({method:n,url:e,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:r,data:a})).data}catch(e){if(t.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}})),B=(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i,o;const{options:u,operators:d,operatorAliases:h}=t;let m=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return s(t)?t:e}catch(t){return e}})(e):e;m=j(m,null===(r=t.options)||void 0===r?void 0:r.fragments,!u.noShorthand),Array.isArray(m)&&(m=yield F(m,t));const g=s(m),T=n(m);if(u.evaluateFullObject&&!g&&!T)return v(yield Q(m,t),t);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(m)&&"value"in m?m.value:v(m,t);const{fallback:O}=m,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,r]=yield F([m.fragment,m.parameters],t),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 B(O,t),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,t);m=Object.assign(Object.assign(Object.assign({},m),a),r),delete m.fragment}try{const e=l(m.operator,h);if(!e)return c(yield B(O,t),`Invalid operator: ${m.operator}`,C);if(!t.operators[e])return c(yield B(O,t),`Excluded operator: ${m.operator}`,C);const{propertyAliases:r,evaluate:a,parseChildren:i}=d[e];m=((e,t)=>p(t,(t=>t in e?e[t]:t)))(r,m);const s=yield G(m,t);T||Object.entries(s).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const n=T?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),s)}):t;if("children"in m){if(Array.isArray(m.children)||(m.children=yield B(m.children,n)),!Array.isArray(m.children))return c(yield B(O,t),`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(r){return c(yield B(m.fallback,t),`Operator: ${e}\n${f(r)}`,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 B(v,t);return g in y?y[g](u):c(yield B(O,t),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield B(O,t),f(e),C)}})),F=(e,t)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>B(e,t)))):yield B(e,t)})),G=(e,t)=>i(void 0,void 0,void 0,(function*(){const r=Object.keys(e).filter(h);if(0===r.length)return{};const a=[];return r.forEach((r=>a.push(B(e[r],t)))),L(r,yield Promise.all(a))})),Q=(e,t)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{h(r)&&(a.push(r,B(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,B(a,t))}));const s=yield Promise.all(r);return v(k(s),t)})),W=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],z=U(W),J={description:"Logical AND",aliases:["and","&","&&"],parameters:W},V=e=>{const t=e.children;return Object.assign(Object.assign({},e),{values:t})},Y={propertyAliases:z,operatorData:J,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(R(J.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:V},X=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],K=U(X),Z={description:"Logical OR",aliases:["or","|","||"],parameters:X},ee={propertyAliases:K,operatorData:Z,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(R(Z.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:V},te=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array",default:["These are equal","These are equal"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],re=U(te),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:te},ie={propertyAliases:re,operatorData:ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield F([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(ae.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=t.options)||void 0===r?void 0:r.caseInsensitive)&&void 0!==i&&i)&&n.every((e=>"string"==typeof e))?n.map((e=>e.toLowerCase())):n;return!(void 0!==l?l:void 0!==(null===(s=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>a(e,u[0]))):u.every((e=>null==e))})),parseChildren:V},se=[{name:"values",description:"Array of values to check for inequality",aliases:[],required:!0,type:"array",default:["These items","don't match"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],ne=U(se),oe={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:se},le={propertyAliases:ne,operatorData:oe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield F([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(oe.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=t.options)||void 0===r?void 0:r.caseInsensitive)&&void 0!==i&&i)&&n.every((e=>"string"==typeof e))?n.map((e=>e.toLowerCase())):n;return!(void 0!==l?l:void 0!==(null===(s=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!a(e,u[0]))):u.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",default:[1,2,3]},{name:"type",description:"Data type to coerce input values to before addition",aliases:[],required:!1,type:{literal:["string","array","number","boolean","bool"]},default:"string"}],de=U(ue),ce={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ue},pe={propertyAliases:de,operatorData:ce,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(R(ce.parameters,{values:r,type:e.type})),0===r.length?r:"string"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),""):"array"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),[]):r.every((e=>"string"==typeof e||Array.isArray(e)))?r.reduce(((e,t)=>e.concat(t))):r.every((e=>b(e)))?r.reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{}):r.reduce(((e,t)=>e+t))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array",default:[10,5]},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number",default:100},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number",default:50}],ve=U(he),me={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},ye={propertyAliases:ve,operatorData:me,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i]=yield F([e.values,e.from,e.subtract],t);t.typeChecker(R(me.parameters,{values:r,from:a,subtract:i}));const s=null!=r?r:[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",default:[5,5]}],ge=U(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);if(t.typeChecker(R(be.parameters,{values:r})),0===r.length)return 0;if(r.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return r.reduce(((e,t)=>e*t))})),parseChildren:V},Oe=[{name:"values",description:"Array of values - 1st element will be divided by the first",aliases:[],required:!1,type:"array",default:[100,10]},{name:"dividend",description:"The number that will be divided",aliases:["divide"],required:!1,type:"number",default:99},{name:"divisor",description:"The number that dividend will be divided by",aliases:["by","divideBy"],required:!1,type:"number",default:3},{name:"output",description:"Whether to output a quotient, remainder or decimal",aliases:[],required:!1,type:{literal:["quotient","remainder"]},default:"quotient"}],Ce=U(Oe),je={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},qe={propertyAliases:Ce,operatorData:je,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield F([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(R(je.parameters,{values:r,dividend:a,divisor:i,output:s}));const n=null!=r?r:[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",default:[10,9]},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],Ee=U(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,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield F([e.values,e.strict],t);if(t.typeChecker(R(Se.parameters,{values:r,strict:a})),r.length<2)throw new Error("- Not enough values provided");const[i,s]=r;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",default:[9,10]},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],xe=U(Pe),we={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ie={propertyAliases:xe,operatorData:we,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield F([e.values,e.strict],t);if(t.typeChecker(R(we.parameters,{values:r,strict:a})),r.length<2)throw new Error("- Not enough values provided");const[i,s]=r;return i===s&&!a||i<s})),parseChildren:V},Ue=[{name:"condition",description:"The expression to check for truthiness",aliases:[],required:!0,type:"any",default:!0},{name:"valueIfTrue",description:"Value to return if condition is true",aliases:["ifTrue"],required:!0,type:"any",default:"The condition is true"},{name:"valueIfFalse",description:"Value to return if condition is false",aliases:["ifFalse","ifNot"],required:!0,type:"any",default:"The condition is false"}],Re=U(Ue),Le={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ue},ke={propertyAliases:Re,operatorData:Le,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(Le.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield B(e.condition,t))?yield B(e.valueIfTrue,t):yield B(e.valueIfFalse,t)})),parseChildren:e=>{const[t,r,a]=e.children;return Object.assign(Object.assign({},e),{condition:t,valueIfTrue:r,valueIfFalse:a})}},De=[{name:"testString",description:"The string to test",aliases:["string","value"],required:!0,type:"string",default:"test-this"},{name:"pattern",description:"The regular expression pattern",aliases:["regex","regexp","regExp","re"],required:!0,type:"string",default:"^[a-z]{4}-[a-z]{4}$"}],_e=U(De),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},He={propertyAliases:_e,operatorData:Me,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a]=yield F([e.testString,e.pattern],t);t.typeChecker(R(Me.parameters,{testString:r,pattern:a}));try{return new RegExp(a).test(r)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[t,r]=e.children;return Object.assign(Object.assign({},e),{testString:t,pattern:r})}},$e=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string",default:"path.to[0].my.data"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object",default:{}}],Be=U($e),Fe={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:$e},Ge={propertyAliases:Be,operatorData:Fe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s,n;const[o,l]=yield F([e.property,e.additionalData],t);t.typeChecker(R(Fe.parameters,{property:o,additionalData:l}));const u=l?Object.assign(Object.assign({},null!==(i=null===(a=t.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),l):null!==(n=null===(s=t.options)||void 0===s?void 0:s.data)&&void 0!==n?n:{};return r(u,o)})),parseChildren:e=>{const[t,r]=e.children,a=Object.assign(Object.assign({},e),{property:t});return void 0!==r&&(a.fallback=r),a}},Qe=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string",default:"Hello, %1"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!0,type:["array","object"],default:["friend"]},{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",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],We=U(Qe),ze={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:Qe},Je={propertyAliases:We,operatorData:ze,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i=!0,s="%",n={}]=yield F([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(R(ze.parameters,{string:r,substitutions:a,trimWhiteSpace:i,substitutionCharacter:s,numberMapping:n})),Array.isArray(a)){const e="$"===s?"$":"%",t=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(r.match(t)||[]).sort(((e,t)=>Number(e.slice(1))-Number(t.slice(1)))),o=new Set(n),l=L(Array.from(o),a.map((e=>i?String(e).trim():e)));return r.split(t).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}return r.split(/(?<!\\)({{[A-z0-9_]+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const t=Ve(e,a,n);return i?String(t).trim():t})).join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ve=(e,t,r)=>{var a,i;const s=e.replace(/{{(.+)}}/,"$1"),n=null!==(a=null==t?void 0:t[s])&&void 0!==a?a:"";if("number"!=typeof n)return null!==(i=null==t?void 0:t[s])&&void 0!==i?i:"";if(!(s in r))return n;const o=r[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(r[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},Ye=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Xe=U(Ye),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Ye},Ze={propertyAliases:Xe,operatorData:Ke,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(R(Ke.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},et=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string",default:"Alpha, Bravo, Charlie"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string",default:","},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{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",default:!0}],tt=U(et),rt={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:et},at=" ",it={propertyAliases:tt,operatorData:rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield F([e.value,null!==(r=e.delimiter)&&void 0!==r?r:at,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(R(rt.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[t,r=at]=e.children;return Object.assign(Object.assign({},e),{value:t,delimiter:r})}},st=[{name:"query",description:"A SQL query string, with parameterised replacements (i.e. $1, $2, etc)",aliases:[],required:!0,type:"string",default:"SELECT contact_name FROM customers;"},{name:"values",description:"An array of values to replace in the SQL string parameters",aliases:["replacements"],required:!1,type:"array",default:[]},{name:"type",description:"Determines the shape of the resulting data (see documentation)",aliases:["queryType"],required:!1,type:{literal:["array","string","number"]},default:"array"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],nt=U(st),ot={description:"Query a Postgres database using node-postgres",aliases:["pgSql","sql","postgres","pg","pgDb"],parameters:st},lt=(e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i={text:e,values:t,rowMode:a?"array":""},s=yield r.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}})),ut={propertyAliases:nt,operatorData:ot,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u]=yield F([e.query,e.type,e.values||[],e.useCache],t);if(t.typeChecker(R(ot.parameters,{query:n,type:o,values:l,useCache:u})),!(null===(r=t.options)||void 0===r?void 0:r.pgConnection))throw new Error("No Postgres database connection provided");const d=null===(s=null!==(a=e.useCache)&&void 0!==a?a:t.options.useCache)||void 0===s||s;return t.cache.useCache(d,((e,r,a)=>i(void 0,void 0,void 0,(function*(){return yield lt(e,a,t.options.pgConnection,r)}))),n,o,l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{query:t,values:r})}},dt=[{name:"query",description:"GraphQL query string",aliases:[],required:!0,type:"string",default:'query getCountries {\n countries(filter: {continent: {eq: "OC"}}) {\n name\n }\n }'},{name:"url",description:"Endpoint for the GraphQL request (if not already provided in options)",aliases:["endpoint"],required:!1,type:["string","null"],default:"https://countries.trevorblades.com/"},{name:"headers",description:"HTTP Headers (if not already provided in options)",aliases:[],required:!1,type:"object",default:{}},{name:"variables",description:"Values for the variables used in query (key-value pairs)",aliases:[],required:!1,type:"object",default:{}},{name:"returnNode",description:"Property path to extract from the query response",aliases:["outputNode","returnProperty"],required:!1,type:"string",default:"data.countries[1].name"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],ct=U(dt),pt={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:dt},ht={propertyAliases:ct,operatorData:pt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s,n,o,l;const[u,d,c,p,h,v]=yield F([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],t),{url:m,headers:y}=d instanceof Object?d:{url:d,headers:null};t.typeChecker([...R(pt.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===(r=t.options.graphQLConnection)||void 0===r?void 0:r.endpoint)&&void 0!==a?a:t.options.baseEndpoint)&&void 0!==s?s:"",b=M(f)?f:H(g,f),T={query:u,variables:c},O=null===(n=null!=v?v:t.options.useCache)||void 0===n||n,C=yield t.cache.useCache(O,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield $({url:e,method:"post",data:t,headers:r});return _(i.data,a)}))),b,T,Object.assign(Object.assign(Object.assign(Object.assign({},null===(o=t.options.graphQLConnection)||void 0===o?void 0:o.headers),null===(l=t.options)||void 0===l?void 0:l.headers),y),h),p);return C})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield F(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=L(n,o),u=Object.assign(Object.assign({},e),{query:r,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},vt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://restcountries.com/v3.1/name/zealand"},{name:"returnProperty",description:"Property from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"Query parameters (key-value)",aliases:["queryParams","queryParameters","urlQueries"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],mt=U(vt),yt={description:"HTTP GET Request",aliases:["get","api"],parameters:vt},ft=(e,t)=>i(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield F(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=L(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gt=ft,bt={propertyAliases:mt,operatorData:yt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u,d]=yield F([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};t.typeChecker([...R(yt.parameters,{url:c,returnProperty:l,headers:u,parameters:o,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",v=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),p),u),m=null===(s=null!=d?d:t.options.useCache)||void 0===s||s,y=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield $({url:e,params:t,headers:r});return _(i,a)}))),M(c)?c:H(h,c),o,v,l);return y})),parseChildren:ft},Tt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://jsonplaceholder.typicode.com/posts"},{name:"returnProperty",description:"Property path from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"JSON Body parameters (key-value)",aliases:["bodyJson","data"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],Ot=U(Tt),Ct={description:"HTTP POST Request",aliases:["post"],parameters:Tt},jt={propertyAliases:Ot,operatorData:Ct,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u,d]=yield F([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};t.typeChecker([...R(Ct.parameters,{url:c,headers:u,data:o,returnProperty:l,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",v=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),p),u),m=null!==(s=null!=d?d:t.options.useCache)&&void 0!==s&&s;return yield t.cache.useCache(m,(()=>i(void 0,void 0,void 0,(function*(){const e=yield $({url:c,data:o,headers:u,method:"post"});return _(e,l)}))),M(c)?c:H(h,c),o,v,l)})),parseChildren:gt},qt=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array",default:["firstKey","firstValue","secondKey","secondValue"]}],At=U(qt),Et={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:qt},St={propertyAliases:At,operatorData:Et,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(Et.parameters,{properties:e.properties}));const r=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:r})=>{return a=[e,r],i(void 0,void 0,void 0,(function*(){const[e,r]=yield F(a,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var a}));return Object.fromEntries(yield Promise.all(r))})),parseChildren:e=>{const t=e.children;if(t.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=t.filter(((e,t)=>t%2==0)),a=t.filter(((e,t)=>t%2==1)),i=r.map(((e,t)=>({key:e,value:a[t]})));return Object.assign(Object.assign({},e),{properties:i})}},Nt=[{name:"matchExpression",description:"Expression to match against",aliases:["match"],required:!0,type:["string","number","boolean"],default:"matchMe"},{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"],default:{matchMe:"YES",nonMatch:"NO"}},{name:"[...branches]",description:"Branch properties can optionally be placed at the operator root",aliases:[],required:!1,type:["object","array"]}],Pt={propertyAliases:U(Nt),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Nt},evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r;const a=yield B(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=s(i)?yield B(i,t):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield B(n[a],t);if("fallback"in n)return yield B(n.fallback,t);if(a in e)return yield B(e[a],t);throw new Error(`No match found for ${a}`)})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=k(yield F(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},xt=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array",default:[]},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],wt=U(xt),It={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:xt},Ut={propertyAliases:wt,operatorData:It,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield F([e.functionPath,e.args,e.useCache],t);t.typeChecker(R(It.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=t.options,p=null!==(s=null!==(a=r(c,o,null))&&void 0!==a?a:r(d,o,null))&&void 0!==s?s:r(t.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:t.options.useCache)&&void 0!==n&&n;return yield t.cache.useCache(h,((e,...t)=>i(void 0,void 0,void 0,(function*(){return yield p(...t)}))),o,...l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionPath:t,args:r})}},Rt=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Lt=U(Rt),kt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Rt},Dt={propertyAliases:Lt,operatorData:kt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){return t.typeChecker(R(kt.parameters,{value:e.value})),yield B(e.value,t)})),parseChildren:e=>{const[...t]=e.children,r=1===(null==t?void 0:t.length)?t[0]:t;return Object.assign(Object.assign({},e),{value:r})}};var _t=Object.freeze({__proto__:null,AND:Y,BUILD_OBJECT:St,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Ut,DIVIDE:qe,EQUAL:ie,GET:bt,GRAPHQL:ht,GREATER_THAN:Ne,LESS_THAN:Ie,MATCH:Pt,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:Ge,OR:ee,PASSTHRU:Dt,PG_SQL:ut,PLUS:pe,POST:jt,REGEX:He,SPLIT:it,STRING_SUBSTITUTION:Je,SUBTRACT:ye});class Mt{constructor(e){var t,r;this.useCache=(e,t,...r)=>i(this,void 0,void 0,(function*(){if(!e)return yield t(...r);const a=Ht(r),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 t(...r)),this.store[a].result;const o=yield t(...r);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!==(t=null==e?void 0:e.maxSize)&&void 0!==t?t:50,this.maxTime=null!==(r=null==e?void 0:e.maxTime)&&void 0!==r?r:1800}}const Ht=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_");class $t{constructor(e={}){var t,r;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=P(...t);if(!0!==r)throw new Error(r)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.13.5",this.options=Ft(e),this.operators=u(_t,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],T),this.operatorAliases=T,this.cache=new Mt({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime})}evaluate(e,t={}){return i(this,void 0,void 0,(function*(){const r=m(this.options,Ft(t));return r.maxCacheSize&&r.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(r.maxCacheSize),r.maxCacheTime&&r.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(r.maxCacheTime),yield B(e,{options:r,operators:t.excludeOperators?u(_t,t.excludeOperators,T):this.operators,operatorAliases:this.operatorAliases,typeChecker:r.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache})}))}getOptions(){return this.options}updateOptions(e){this.options=m(this.options,Ft(e)),this.options.excludeOperators&&(this.operators=u(_t,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(_t,this.options.excludeOperators,T):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(T))];return t.sort(((e,t)=>r.indexOf(e.name)-r.indexOf(t.name)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,t])=>Object.assign({name:e},null==t?void 0:t.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,t])=>({name:e,numRequiredArgs:t.length})))}}const Bt=(e,t)=>new $t(t).evaluate(e),Ft=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;export{$t as FigTreeEvaluator,Bt as evaluateExpression,h as isAliasString,n as isFragmentNode,b as isObject,s as isOperatorNode,o as standardiseOperatorName,d as truncateString};
1
+ import{camelCase as e}from"change-case";import t from"axios";import r from"object-property-extractor";import{dequal as a}from"dequal/lite";function i(e,t,r,a){return new(r||(r=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 t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=t=>{const r=e(t);return r||t},l=(e,t)=>t[o(e)],u=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[o(e)]]})),a},d=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,c=(e,t,r=!1)=>{if(void 0!==e)return e;if(r)return d(t);throw new Error(d(t))},p=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&h(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},m=(e,t)=>{const r=Object.assign(Object.assign({},e),t);return(e.data||t.data)&&(r.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(r.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(r.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(r.headers=Object.assign(Object.assign({},e.headers),t.headers)),r},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 t=new RegExp(/-?\d*\.?\d+/gm),r=e.match(t);return r?Number(r[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,t={},r=!0)=>r?"string"==typeof e?q(e,t):b(e)?A(e,t):e:e,q=(e,t)=>{const r=C.exec(e);if(!r)return e;const a=r[1].trim(),i=r[2].split(",").map((e=>j(e.trim(),t)));return E(a,i,t)},A=(e,t)=>{if(s(e)||n(e))return e;const r=Object.entries(e),a=r.filter((([e])=>h(e))),i=r.filter((([e])=>!h(e))),o=a.reduce(((e,[r,a])=>e=Object.assign(Object.assign({},e),E(r,a,t))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,t,r)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(t)?{operator:i,children:t}:b(t)&&!Object.keys(t).some((e=>h(e)))?Object.assign({operator:i},t):{operator:i,children:[t]}:a in r?{fragment:a,parameters:Object.assign({},t)}:{[e]:t}},S=e=>b(e)&&"literal"in e,N=({value:e,name:t,expectedType:r})=>{if(S(r)){const{literal:a}=r;return!!a.includes(e)||w(t,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(r))return!!r.some((r=>!0===N({value:e,name:t,expectedType:r})))||w(t,e,r.join("|"));return!!(0,x[r])(e)||w(t,e,r)},P=(...e)=>{const t=[];return e.forEach((e=>{const r=N(e);!0!==r&&t.push(r)})),!(t.length>0)||t.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,t,r)=>void 0===t&&e?`- Missing required property "${e}" (type: ${r})`:void 0!==e?`- Property "${e}" (value: ${I(t)}) is not of type: ${r}`:`- ${I(t)} is not of type: ${r}`,I=e=>{const t=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return d(t,50)},U=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},R=(e,t)=>e.map((({name:e,required:r,type:a})=>{if(S(a)){const i=[...a.literal];return r||i.push(void 0),{name:e,value:t[e],expectedType:{literal:i}}}const i=Array.isArray(a)?a:[a];r||i.push("undefined");const s=1===i.length?i[0]:i;return{name:e,value:t[e],expectedType:s}})),L=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=e.filter(((e,t)=>t%2==0)),r=P(...t.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==r)throw new Error(r);const a=e.filter(((e,t)=>t%2==1)),i={};return t.forEach(((e,t)=>{i[e]=a[t]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(e,t,a=void 0)=>{const i=t?r(e,t,a):e;return Array.isArray(i)?i.map((e=>D(e))):t?null===i?null:D(i):i},M=e=>/^https?:\/\/.+/.test(e),H=(...e)=>e.reduce(((e,t,r)=>{const a="/"===t[0]?1:0,i="/"===t.slice(-1)?-1:void 0,s=t.slice(a,i);return""===s?e:e+(0===r?"":"/")+s}),""),$=({url:e,params:r={},data:a={},headers:s={},method:n="get"})=>i(void 0,void 0,void 0,(function*(){var i;try{return(yield t({method:n,url:e,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:r,data:a})).data}catch(e){if(t.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}})),B=(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i,o;const{options:u,operators:d,operatorAliases:h}=t;let m=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return s(t)?t:e}catch(t){return e}})(e):e;m=j(m,null===(r=t.options)||void 0===r?void 0:r.fragments,!u.noShorthand),Array.isArray(m)&&(m=yield F(m,t));const g=s(m),T=n(m);if(u.evaluateFullObject&&!g&&!T)return v(yield Q(m,t),t);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(m)&&"value"in m?m.value:v(m,t);const{fallback:O}=m,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,r]=yield F([m.fragment,m.parameters],t),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 B(O,t),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,t);m=Object.assign(Object.assign(Object.assign({},m),a),r),delete m.fragment}try{const e=l(m.operator,h);if(!e)return c(yield B(O,t),`Invalid operator: ${m.operator}`,C);if(!t.operators[e])return c(yield B(O,t),`Excluded operator: ${m.operator}`,C);const{propertyAliases:r,evaluate:a,parseChildren:i}=d[e];m=((e,t)=>p(t,(t=>t in e?e[t]:t)))(r,m);const s=yield G(m,t);T||Object.entries(s).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const n=T?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),s)}):t;if("children"in m){if(Array.isArray(m.children)||(m.children=yield B(m.children,n)),!Array.isArray(m.children))return c(yield B(O,t),`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(r){return c(yield B(m.fallback,t),`Operator: ${e}\n${f(r)}`,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 B(v,t);return g in y?y[g](u):c(yield B(O,t),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield B(O,t),f(e),C)}})),F=(e,t)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>B(e,t)))):yield B(e,t)})),G=(e,t)=>i(void 0,void 0,void 0,(function*(){const r=Object.keys(e).filter(h);if(0===r.length)return{};const a=[];return r.forEach((r=>a.push(B(e[r],t)))),L(r,yield Promise.all(a))})),Q=(e,t)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{h(r)&&(a.push(r,B(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,B(a,t))}));const s=yield Promise.all(r);return v(k(s),t)})),W=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],z=U(W),J={description:"Logical AND",aliases:["and","&","&&"],parameters:W},V=e=>{const t=e.children;return Object.assign(Object.assign({},e),{values:t})},Y={propertyAliases:z,operatorData:J,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(R(J.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:V},X=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],K=U(X),Z={description:"Logical OR",aliases:["or","|","||"],parameters:X},ee={propertyAliases:K,operatorData:Z,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(R(Z.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:V},te=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array",default:["These are equal","These are equal"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],re=U(te),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:te},ie={propertyAliases:re,operatorData:ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield F([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(ae.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=t.options)||void 0===r?void 0:r.caseInsensitive)&&void 0!==i&&i)&&n.every((e=>"string"==typeof e))?n.map((e=>e.toLowerCase())):n;return!(void 0!==l?l:void 0!==(null===(s=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>a(e,u[0]))):u.every((e=>null==e))})),parseChildren:V},se=[{name:"values",description:"Array of values to check for inequality",aliases:[],required:!0,type:"array",default:["These items","don't match"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],ne=U(se),oe={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:se},le={propertyAliases:ne,operatorData:oe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield F([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(oe.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=t.options)||void 0===r?void 0:r.caseInsensitive)&&void 0!==i&&i)&&n.every((e=>"string"==typeof e))?n.map((e=>e.toLowerCase())):n;return!(void 0!==l?l:void 0!==(null===(s=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!a(e,u[0]))):u.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",default:[1,2,3]},{name:"type",description:"Data type to coerce input values to before addition",aliases:[],required:!1,type:{literal:["string","array","number","boolean","bool"]},default:"string"}],de=U(ue),ce={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ue},pe={propertyAliases:de,operatorData:ce,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(R(ce.parameters,{values:r,type:e.type})),0===r.length?r:"string"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),""):"array"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),[]):r.every((e=>"string"==typeof e||Array.isArray(e)))?r.reduce(((e,t)=>e.concat(t))):r.every((e=>b(e)))?r.reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{}):r.reduce(((e,t)=>e+t))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array",default:[10,5]},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number",default:100},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number",default:50}],ve=U(he),me={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},ye={propertyAliases:ve,operatorData:me,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i]=yield F([e.values,e.from,e.subtract],t);t.typeChecker(R(me.parameters,{values:r,from:a,subtract:i}));const s=null!=r?r:[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",default:[5,5]}],ge=U(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);if(t.typeChecker(R(be.parameters,{values:r})),0===r.length)return 0;if(r.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return r.reduce(((e,t)=>e*t))})),parseChildren:V},Oe=[{name:"values",description:"Array of values - 1st element will be divided by the first",aliases:[],required:!1,type:"array",default:[100,10]},{name:"dividend",description:"The number that will be divided",aliases:["divide"],required:!1,type:"number",default:99},{name:"divisor",description:"The number that dividend will be divided by",aliases:["by","divideBy"],required:!1,type:"number",default:3},{name:"output",description:"Whether to output a quotient, remainder or decimal",aliases:[],required:!1,type:{literal:["quotient","remainder"]},default:"quotient"}],Ce=U(Oe),je={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},qe={propertyAliases:Ce,operatorData:je,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield F([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(R(je.parameters,{values:r,dividend:a,divisor:i,output:s}));const n=null!=r?r:[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",default:[10,9]},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],Ee=U(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,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield F([e.values,e.strict],t);if(t.typeChecker(R(Se.parameters,{values:r,strict:a})),r.length<2)throw new Error("- Not enough values provided");const[i,s]=r;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",default:[9,10]},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],xe=U(Pe),we={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ie={propertyAliases:xe,operatorData:we,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield F([e.values,e.strict],t);if(t.typeChecker(R(we.parameters,{values:r,strict:a})),r.length<2)throw new Error("- Not enough values provided");const[i,s]=r;return i===s&&!a||i<s})),parseChildren:V},Ue=[{name:"condition",description:"The expression to check for truthiness",aliases:[],required:!0,type:"any",default:!0},{name:"valueIfTrue",description:"Value to return if condition is true",aliases:["ifTrue"],required:!0,type:"any",default:"The condition is true"},{name:"valueIfFalse",description:"Value to return if condition is false",aliases:["ifFalse","ifNot"],required:!0,type:"any",default:"The condition is false"}],Re=U(Ue),Le={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ue},ke={propertyAliases:Re,operatorData:Le,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(Le.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield B(e.condition,t))?yield B(e.valueIfTrue,t):yield B(e.valueIfFalse,t)})),parseChildren:e=>{const[t,r,a]=e.children;return Object.assign(Object.assign({},e),{condition:t,valueIfTrue:r,valueIfFalse:a})}},De=[{name:"testString",description:"The string to test",aliases:["string","value"],required:!0,type:"string",default:"test-this"},{name:"pattern",description:"The regular expression pattern",aliases:["regex","regexp","regExp","re"],required:!0,type:"string",default:"^[a-z]{4}-[a-z]{4}$"}],_e=U(De),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},He={propertyAliases:_e,operatorData:Me,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a]=yield F([e.testString,e.pattern],t);t.typeChecker(R(Me.parameters,{testString:r,pattern:a}));try{return new RegExp(a).test(r)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[t,r]=e.children;return Object.assign(Object.assign({},e),{testString:t,pattern:r})}},$e=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string",default:"path.to[0].my.data"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object",default:{}}],Be=U($e),Fe={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:$e},Ge={propertyAliases:Be,operatorData:Fe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,i;const[s,n={}]=yield F([e.property,e.additionalData],t);t.typeChecker(R(Fe.parameters,{property:s,additionalData:n}));const o=Object.assign(Object.assign({},null!==(i=null===(a=t.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),n);return r(o,s)})),parseChildren:e=>{const[t,r]=e.children,a=Object.assign(Object.assign({},e),{property:t});return void 0!==r&&(a.fallback=r),a}},Qe=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string",default:"Hello, %1"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!1,type:["array","object"],default:["friend"]},{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",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],We=U(Qe),ze={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:Qe},Je={propertyAliases:We,operatorData:ze,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a={},i=!0,s="%",n={}]=yield F([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(R(ze.parameters,{string:r,substitutions:a,trimWhiteSpace:i,substitutionCharacter:s,numberMapping:n})),Array.isArray(a)){const e="$"===s?"$":"%",t=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(r.match(t)||[]).sort(((e,t)=>Number(e.slice(1))-Number(t.slice(1)))),o=new Set(n),l=L(Array.from(o),a.map((e=>i?String(e).trim():e)));return r.split(t).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}return r.split(/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ve(e,a,n,t.options.data);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ve=(e,t,a,i={})=>{const s=e.replace(/{{(.+)}}/,"$1"),n=r(t,s,r(i,s,""));if("number"!=typeof n)return n;if(!(s in a))return n;const o=a[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(a[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},Ye=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Xe=U(Ye),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Ye},Ze={propertyAliases:Xe,operatorData:Ke,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(R(Ke.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},et=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string",default:"Alpha, Bravo, Charlie"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string",default:","},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{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",default:!0}],tt=U(et),rt={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:et},at=" ",it={propertyAliases:tt,operatorData:rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield F([e.value,null!==(r=e.delimiter)&&void 0!==r?r:at,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(R(rt.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[t,r=at]=e.children;return Object.assign(Object.assign({},e),{value:t,delimiter:r})}},st=[{name:"query",description:"A SQL query string, with parameterised replacements (i.e. $1, $2, etc)",aliases:[],required:!0,type:"string",default:"SELECT contact_name FROM customers;"},{name:"values",description:"An array of values to replace in the SQL string parameters",aliases:["replacements"],required:!1,type:"array",default:[]},{name:"type",description:"Determines the shape of the resulting data (see documentation)",aliases:["queryType"],required:!1,type:{literal:["array","string","number"]},default:"array"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],nt=U(st),ot={description:"Query a Postgres database using node-postgres",aliases:["pgSql","sql","postgres","pg","pgDb"],parameters:st},lt=(e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i={text:e,values:t,rowMode:a?"array":""},s=yield r.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}})),ut={propertyAliases:nt,operatorData:ot,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u]=yield F([e.query,e.type,e.values||[],e.useCache],t);if(t.typeChecker(R(ot.parameters,{query:n,type:o,values:l,useCache:u})),!(null===(r=t.options)||void 0===r?void 0:r.pgConnection))throw new Error("No Postgres database connection provided");const d=null===(s=null!==(a=e.useCache)&&void 0!==a?a:t.options.useCache)||void 0===s||s;return t.cache.useCache(d,((e,r,a)=>i(void 0,void 0,void 0,(function*(){return yield lt(e,a,t.options.pgConnection,r)}))),n,o,l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{query:t,values:r})}},dt=[{name:"query",description:"GraphQL query string",aliases:[],required:!0,type:"string",default:'query getCountries {\n countries(filter: {continent: {eq: "OC"}}) {\n name\n }\n }'},{name:"url",description:"Endpoint for the GraphQL request (if not already provided in options)",aliases:["endpoint"],required:!1,type:["string","null"],default:"https://countries.trevorblades.com/"},{name:"headers",description:"HTTP Headers (if not already provided in options)",aliases:[],required:!1,type:"object",default:{}},{name:"variables",description:"Values for the variables used in query (key-value pairs)",aliases:[],required:!1,type:"object",default:{}},{name:"returnNode",description:"Property path to extract from the query response",aliases:["outputNode","returnProperty"],required:!1,type:"string",default:"data.countries[1].name"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],ct=U(dt),pt={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:dt},ht={propertyAliases:ct,operatorData:pt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s,n,o,l;const[u,d,c,p,h,v]=yield F([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],t),{url:m,headers:y}=d instanceof Object?d:{url:d,headers:null};t.typeChecker([...R(pt.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===(r=t.options.graphQLConnection)||void 0===r?void 0:r.endpoint)&&void 0!==a?a:t.options.baseEndpoint)&&void 0!==s?s:"",b=M(f)?f:H(g,f),T={query:u,variables:c},O=null===(n=null!=v?v:t.options.useCache)||void 0===n||n,C=yield t.cache.useCache(O,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield $({url:e,method:"post",data:t,headers:r});return _(i.data,a)}))),b,T,Object.assign(Object.assign(Object.assign(Object.assign({},null===(o=t.options.graphQLConnection)||void 0===o?void 0:o.headers),null===(l=t.options)||void 0===l?void 0:l.headers),y),h),p);return C})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield F(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=L(n,o),u=Object.assign(Object.assign({},e),{query:r,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},vt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://restcountries.com/v3.1/name/zealand"},{name:"returnProperty",description:"Property from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"Query parameters (key-value)",aliases:["queryParams","queryParameters","urlQueries"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],mt=U(vt),yt={description:"HTTP GET Request",aliases:["get","api"],parameters:vt},ft=(e,t)=>i(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield F(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=L(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gt=ft,bt={propertyAliases:mt,operatorData:yt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u,d]=yield F([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};t.typeChecker([...R(yt.parameters,{url:c,returnProperty:l,headers:u,parameters:o,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",v=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),p),u),m=null===(s=null!=d?d:t.options.useCache)||void 0===s||s,y=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield $({url:e,params:t,headers:r});return _(i,a)}))),M(c)?c:H(h,c),o,v,l);return y})),parseChildren:ft},Tt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://jsonplaceholder.typicode.com/posts"},{name:"returnProperty",description:"Property path from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"JSON Body parameters (key-value)",aliases:["bodyJson","data"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],Ot=U(Tt),Ct={description:"HTTP POST Request",aliases:["post"],parameters:Tt},jt={propertyAliases:Ot,operatorData:Ct,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const[n,o,l,u,d]=yield F([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:c,headers:p}=n instanceof Object?n:{url:n,headers:null};t.typeChecker([...R(Ct.parameters,{url:c,headers:u,data:o,returnProperty:l,useCache:d}),{name:"headers",value:p,expectedType:["object","null"]}]);const h=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",v=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),p),u),m=null!==(s=null!=d?d:t.options.useCache)&&void 0!==s&&s;return yield t.cache.useCache(m,(()=>i(void 0,void 0,void 0,(function*(){const e=yield $({url:c,data:o,headers:u,method:"post"});return _(e,l)}))),M(c)?c:H(h,c),o,v,l)})),parseChildren:gt},qt=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array",default:["firstKey","firstValue","secondKey","secondValue"]}],At=U(qt),Et={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:qt},St={propertyAliases:At,operatorData:Et,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(Et.parameters,{properties:e.properties}));const r=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:r})=>{return a=[e,r],i(void 0,void 0,void 0,(function*(){const[e,r]=yield F(a,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var a}));return Object.fromEntries(yield Promise.all(r))})),parseChildren:e=>{const t=e.children;if(t.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=t.filter(((e,t)=>t%2==0)),a=t.filter(((e,t)=>t%2==1)),i=r.map(((e,t)=>({key:e,value:a[t]})));return Object.assign(Object.assign({},e),{properties:i})}},Nt=[{name:"matchExpression",description:"Expression to match against",aliases:["match"],required:!0,type:["string","number","boolean"],default:"matchMe"},{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"],default:{matchMe:"YES",nonMatch:"NO"}},{name:"[...branches]",description:"Branch properties can optionally be placed at the operator root",aliases:[],required:!1,type:["object","array"]}],Pt={propertyAliases:U(Nt),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Nt},evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r;const a=yield B(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=s(i)?yield B(i,t):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield B(n[a],t);if("fallback"in n)return yield B(n.fallback,t);if(a in e)return yield B(e[a],t);throw new Error(`No match found for ${a}`)})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=k(yield F(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},xt=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array",default:[]},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],wt=U(xt),It={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:xt},Ut={propertyAliases:wt,operatorData:It,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield F([e.functionPath,e.args,e.useCache],t);t.typeChecker(R(It.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=t.options,p=null!==(s=null!==(a=r(c,o,null))&&void 0!==a?a:r(d,o,null))&&void 0!==s?s:r(t.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:t.options.useCache)&&void 0!==n&&n;return yield t.cache.useCache(h,((e,...t)=>i(void 0,void 0,void 0,(function*(){return yield p(...t)}))),o,...l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionPath:t,args:r})}},Rt=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Lt=U(Rt),kt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Rt},Dt={propertyAliases:Lt,operatorData:kt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){return t.typeChecker(R(kt.parameters,{value:e.value})),yield B(e.value,t)})),parseChildren:e=>{const[...t]=e.children,r=1===(null==t?void 0:t.length)?t[0]:t;return Object.assign(Object.assign({},e),{value:r})}};var _t=Object.freeze({__proto__:null,AND:Y,BUILD_OBJECT:St,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Ut,DIVIDE:qe,EQUAL:ie,GET:bt,GRAPHQL:ht,GREATER_THAN:Ne,LESS_THAN:Ie,MATCH:Pt,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:Ge,OR:ee,PASSTHRU:Dt,PG_SQL:ut,PLUS:pe,POST:jt,REGEX:He,SPLIT:it,STRING_SUBSTITUTION:Je,SUBTRACT:ye});class Mt{constructor(e){var t,r;this.useCache=(e,t,...r)=>i(this,void 0,void 0,(function*(){if(!e)return yield t(...r);const a=Ht(r),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 t(...r)),this.store[a].result;const o=yield t(...r);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!==(t=null==e?void 0:e.maxSize)&&void 0!==t?t:50,this.maxTime=null!==(r=null==e?void 0:e.maxTime)&&void 0!==r?r:1800}}const Ht=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_");class $t{constructor(e={}){var t,r;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=P(...t);if(!0!==r)throw new Error(r)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.14.0",this.options=Ft(e),this.operators=u(_t,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],T),this.operatorAliases=T,this.cache=new Mt({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime})}evaluate(e,t={}){return i(this,void 0,void 0,(function*(){const r=m(this.options,Ft(t));return r.maxCacheSize&&r.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(r.maxCacheSize),r.maxCacheTime&&r.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(r.maxCacheTime),yield B(e,{options:r,operators:t.excludeOperators?u(_t,t.excludeOperators,T):this.operators,operatorAliases:this.operatorAliases,typeChecker:r.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache})}))}getOptions(){return this.options}updateOptions(e){this.options=m(this.options,Ft(e)),this.options.excludeOperators&&(this.operators=u(_t,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(_t,this.options.excludeOperators,T):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(T))];return t.sort(((e,t)=>r.indexOf(e.name)-r.indexOf(t.name)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,t])=>Object.assign({name:e},null==t?void 0:t.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,t])=>({name:e,numRequiredArgs:t.length})))}}const Bt=(e,t)=>new $t(t).evaluate(e),Ft=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;export{$t as FigTreeEvaluator,Bt as evaluateExpression,h as isAliasString,n as isFragmentNode,b as isObject,s as isOperatorNode,o as standardiseOperatorName,d as truncateString};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fig-tree-evaluator",
3
- "version": "2.13.5",
3
+ "version": "2.14.0",
4
4
  "description": "Module to evaluate JSON-structured expression trees",
5
5
  "main": "build/index.cjs.js",
6
6
  "module": "build/index.esm.js",