fig-tree-evaluator 2.17.0 → 2.18.1

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
@@ -12,7 +12,7 @@ A typical use case would be for evaluating **configuration** files, where you ne
12
12
 
13
13
  A range of built-in operators are available, from simple logic, arithmetic and string manipulation, to data fetching from local sources or remote APIs. Plus, you can extend functionality with your own [custom operators](#custom-functionsoperators)
14
14
 
15
- [**Demo/Playground**](https://carlosnz.github.io/fig-tree-evaluator/)
15
+ ### [Try the Demo/Playground](https://carlosnz.github.io/fig-tree-evaluator/)
16
16
 
17
17
  ## Contents <!-- omit in toc -->
18
18
  <!-- TOC -->
@@ -157,8 +157,8 @@ The `options` parameter is an object with the following available properties (al
157
157
  - `httpClient` -- pass your http client in here in order to use the HTTP-based operators ([`GET`](#get), [`POST`](#post), [`GraphQL`](#graphql)) (uses browser's native `fetch` by default).
158
158
  - `graphQLConnection` -- a GraphQL connection object, if using the [`graphQL` operator](#graphql). See operator details below.
159
159
  - `sqlConnection` -- if you wish to make calls to an SQL database using the [`SQL` operator](#sql), pass a connection to the database here. See operator details below.
160
- - `baseEndpoint` -- A general http headers object that will be passed to *all* http-based operators (`GET`, `POST`, `GraphQL`). Useful if all http queries are to a common server -- then each individual node will only require a relative url. See specific operator for more details.
161
- - `headers` -- A general http headers object that will be passed to *all* http-based operators. Useful for authentication headers, for example. Each operator and instance can have its own headers, though, so see specific operator reference for details.
160
+ - `baseEndpoint` -- If specified, any partial urls specified in the http-based operators (`GET`, `POST`) will be relative to to this base. Useful if you expect most http requests to be to the same server.
161
+ - `headers` -- A general http headers object that will be passed to *all* http-based operators (`GET`, `POST`, `GraphQL`). Useful for authentication headers, for example. Each operator and instance can have its own headers, though, so see specific operator reference for details.
162
162
  - `returnErrorAsString` -- by default the evaluator will throw errors with invalid evaluation expressions (with helpful error messages indicating the node which threw the error and what the problem was). But if you have `returnErrorAsString: true` set, the evaluator will never throw, but instead return error messages as a valid string output. (See also the [`fallback`](#other-common-properties) parameter below). See [Error handling](#error-handling) section for more detail.
163
163
  - `allowJSONStringInput` -- the evaluator is expecting the input expression to be a javascript object. However, it will also accept JSON strings if this option is set to `true`. We have to perform additional logic on every evaluation input to determine if a string is a JSON expression or a standard string, so this is skipped by default for performance reasons. However, if you want to send (for example) user input directly to the evaluator without running it through your own `JSON.parse()`, then enable this option.
164
164
  - `skipRuntimeTypeCheck` -- we perform comprehensive type checking at runtime to ensure that each operator only performs its operation on valid inputs. If type checking fails, we throw an error detailing the explicit problem. However, if `skipRuntimeTypeCheck` is set to `true`, then all inputs are passed to the operator regardless, and any errors will come from whatever standard javascript errors might be encountered (e.g. trying to pass a primitive value when an array is expected => `.map is not a function`)
@@ -1022,10 +1022,10 @@ To specify one of these for use, just pass the client directly to the `httpClien
1022
1022
 
1023
1023
  ```js
1024
1024
  import axios from 'axios'
1025
- import { FigTreeEvaluator } from 'fig-tree-evaluator'
1025
+ import { FigTreeEvaluator, AxiosClient } from 'fig-tree-evaluator'
1026
1026
 
1027
1027
  const fig = new FigTreeEvaluator({
1028
- httpClient: axios,
1028
+ httpClient: AxiosClient(axios),
1029
1029
  ...otherOptions
1030
1030
  })
1031
1031
  ```
@@ -1034,10 +1034,10 @@ const fig = new FigTreeEvaluator({
1034
1034
 
1035
1035
  ```js
1036
1036
  import fetch from 'node-fetch'
1037
- import { FigTreeEvaluator } from 'fig-tree-evaluator'
1037
+ import { FigTreeEvaluator, FetchClient } from 'fig-tree-evaluator'
1038
1038
 
1039
1039
  const fig = new FigTreeEvaluator({
1040
- httpClient: fetch,
1040
+ httpClient: FetchClient(fetch),
1041
1041
  ...otherOptions
1042
1042
  })
1043
1043
  ```
@@ -1 +1 @@
1
- "use strict";var e=require("object-property-extractor"),t=require("dequal/lite"),r=require("querystring");function a(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 i=e=>e instanceof Object&&"operator"in e,s=e=>e instanceof Object&&"fragment"in e,n=e=>{const t=m(e);return t||e},o=(e,t)=>t[n(e)],l=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[n(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[n(e)]]})),a},u=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,d=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},c=e=>/^\$.+/.test(e),p=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&c(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},h=(e,t)=>a(void 0,void 0,void 0,(function*(){var r,a;if(!(e.operator in(null!==(a=null===(r=t.options)||void 0===r?void 0:r.functions)&&void 0!==a?a:{})))return e;const{operator:i,fallback:s,outputType:n,type:o,useCache:l,input:u,args:d}=e,c=function(e,t){var r={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)t.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(r[a[i]]=e[a[i]])}return r}(e,["operator","fallback","outputType","type","useCache","input","args"]),p={operator:"CUSTOM_FUNCTIONS",function:i};return void 0!==s&&(p.fallback=s),void 0!==n&&(p.outputType=n),void 0!==o&&(p.type=o),void 0!==l&&(p.useCache=l),void 0!==d&&(p.args=d),void 0!==u?p.input=u:Object.keys(c).length>0&&(p.input=c),p})),v=(e,t,r)=>{const a=Object.assign(Object.assign({},e),t);return r?((e.data||t.data)&&(a.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(a.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(a.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(a.headers=Object.assign(Object.assign({},e.headers),t.headers)),a):a},y={number:e=>f(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=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},m=e=>e.replace(/[^A-Za-z\d _-]/g,"").split(/[-_ ]/).map((e=>{var t;return null!==(t=e.match(/[a-z]+|[A-Z]+[a-z]*/g))&&void 0!==t?t:e})).flat().filter((e=>""!==e)).map(((e,t)=>0===t?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""),g=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),b={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",sql:"SQL",pgSql:"SQL",postgres:"SQL",pg:"SQL",sqLite:"SQL",sqlite:"SQL",mySql:"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"},T=b,O=/(\$[^()]+)\((.*)\)/,C=(e,t={},r,a=!0)=>a?"string"==typeof e?q(e,t,r):g(e)?S(e,t,r):e:e,q=(e,t,r)=>{const a=O.exec(e);if(!a)return e;const i=a[1].trim(),s=a[2].split(",").map((e=>C(e.trim(),t,r)));return j(i,s,t,r)},S=(e,t,r)=>{if(i(e)||s(e))return e;const a=Object.entries(e),n=a.filter((([e])=>c(e))),o=a.filter((([e])=>!c(e))),l=n.reduce(((e,[a,i])=>e=Object.assign(Object.assign({},e),j(a,i,t,r))),{});return Object.assign(Object.assign({},l),Object.fromEntries(o))},j=(e,t,r,a)=>{const i=e.slice(1),s=o(i,T);return s?Array.isArray(t)?{operator:s,children:t}:g(t)&&!Object.keys(t).some((e=>c(e)))?Object.assign({operator:s},t):{operator:s,children:[t]}:i in r?{fragment:i,parameters:Object.assign({},t)}:a.includes(i)?Array.isArray(t)?{operator:i,args:t}:g(t)?"input"in t||"args"in t?Object.assign({operator:i},t):{operator:i,input:t}:{operator:i,args:[t]}:{[e]:t}};class E extends Error{constructor(e,t,r,a){super(e.message),Object.assign(this,e),this.operator=t,this.expression=a,this.errorData=e.errorData,r&&(this.name=r),"Error"===this.name&&(this.name="FigTreeError");const i=(t?"Operator: "+t:"")+("FigTreeError"===this.name?"":` - ${this.name}`),s=this.errorData?"\n"+JSON.stringify(this.errorData,null,2):"";this.prettyPrint=`${""!==i?i+"\n":""}${this.message}${"\n{}"===s?"":s}`}}const A=({fallback:e,operator:t,name:r,error:a,expression:i,returnErrorAsString:s=!1})=>{if(void 0!==e)return e;if(a instanceof E){if(!s)throw a;return a.prettyPrint}const n=new E("string"==typeof a?new Error(a):a,t,r,i);if(s)return n.prettyPrint;throw n},x=e=>g(e)&&"literal"in e,N=({value:e,name:t,expectedType:r})=>{if(x(r)){const{literal:a}=r;return!!a.includes(e)||L(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})))||L(t,e,r.join("|"));return!!(0,P[r])(e)||L(t,e,r)},w=(...e)=>{const t=[];return e.forEach((e=>{const r=N(e);!0!==r&&t.push(r)})),!(t.length>0)||t.join("\n")},P={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=>g(e),undefined:e=>void 0===e},L=(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 u(t,50)},U=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},k=(e,t)=>e.map((({name:e,required:r,type:a})=>{if(x(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}})),R=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},D=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=w(...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},_=e=>g(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,Q=(t,r,a=void 0)=>{const i=r?e(t,r,a):t;return Array.isArray(i)?i.map((e=>_(e))):r?null===i?null:_(i):i},F=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}),""),M=(e,t)=>a(void 0,void 0,void 0,(function*(){const{url:r,params:a={},data:i={},headers:s={},method:n="get"}=t;if(!r||""===r)throw new Error("Invalid url");try{return yield e[n]({url:r,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:a,data:i})}catch(t){e.throwError(t)}})),$=(e,t)=>a(void 0,void 0,void 0,(function*(){var r,a,n,l,u,c;const{options:v,operators:f,operatorAliases:m}=t;let b=(null==v?void 0:v.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return i(t)?t:e}catch(t){return e}})(e):e;const T=Object.keys(null!==(a=null===(r=t.options)||void 0===r?void 0:r.functions)&&void 0!==a?a:{});b=C(b,null===(n=t.options)||void 0===n?void 0:n.fragments,T,!v.noShorthand),Array.isArray(b)&&(b=yield B(b,t));const O=i(b),q=s(b);if(O&&(b=yield h(b,t)),v.evaluateFullObject&&!O&&!q)return p(yield z(b,t),t);if(!O&&!q)return v.supportDeprecatedValueNodes&&g(b)&&"value"in b?b.value:p(b,t);const{fallback:S}=b,j=null!==(l=null==v?void 0:v.returnErrorAsString)&&void 0!==l&&l;if(q){const[e,r]=yield B([b.fragment,b.parameters],t),a=C(null===(u=null==v?void 0:v.fragments)||void 0===u?void 0:u[e],v.fragments,T,!v.noShorthand);if(void 0===a)return A({fallback:yield $(S,t),error:`Fragment not defined: ${e}`,expression:b,returnErrorAsString:j});if(!i(a))return p(a,t);b=Object.assign(Object.assign(Object.assign({},b),a),r),delete b.fragment}const E=o(b.operator,m);if(!E)return A({fallback:yield $(S,t),error:`Invalid operator: ${b.operator}`,expression:b,returnErrorAsString:j});if(!t.operators[E])return A({fallback:yield $(S,t),error:`Excluded operator: ${b.operator}`,expression:b,returnErrorAsString:j});const{propertyAliases:x,evaluate:N,parseChildren:w}=f[E];b=((e,t)=>d(t,(t=>t in e?e[t]:t)))(x,b);const P=yield G(b,t);q||Object.entries(P).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const L=q?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),P)}):t;if("children"in b){if(Array.isArray(b.children)||(b.children=yield $(b.children,L)),!Array.isArray(b.children))return A({fallback:yield $(S,t),operator:E,name:"Type Error",error:'- Property "children" is not of type: array',expression:b,returnErrorAsString:j});b=yield w(b,L),delete b.children}let I;try{I=yield N(b,L)}catch(e){return A({fallback:yield $(b.fallback,t),operator:E,error:e,expression:b,returnErrorAsString:j})}const U=null!==(c=null==b?void 0:b.outputType)&&void 0!==c?c:null==b?void 0:b.type;if(!U)return I;const k=yield $(U,t);return k in y?y[k](I):A({fallback:yield $(S,t),operator:E,error:`- Invalid output type: ${k}`,expression:b,returnErrorAsString:j})})),B=(e,t)=>a(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)=>a(void 0,void 0,void 0,(function*(){var r;const a=Object.keys(e).filter(c);if(0===a.length)return{};const i=[];a.forEach((r=>i.push($(e[r],t))));const s=yield Promise.all(i),n=R(a,yield Promise.all(i));for(const[e,t]of s.entries())"string"==typeof t&&c(t)&&(n[a[e]]=null!==(r=null==n?void 0:n[t])&&void 0!==r?r:t);return n})),z=(e,t)=>a(void 0,void 0,void 0,(function*(){if(!g(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{c(r)&&(a.push(r,$(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),D(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,$(a,t))}));const s=yield Promise.all(r);return p(D(s),t)})),W=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],J=U(W),V={description:"Logical AND",aliases:["and","&","&&"],parameters:W},Y=e=>{const t=e.children;return Object.assign(Object.assign({},e),{values:t})},X={propertyAliases:J,operatorData:V,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(k(V.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:Y},Z=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],K=U(Z),ee={description:"Logical OR",aliases:["or","|","||"],parameters:Z},te={propertyAliases:K,operatorData:ee,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(k(ee.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:Y},re=[{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}],ae=U(re),ie={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:re},se={propertyAliases:ae,operatorData:ie,evaluate:(e,r)=>a(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],r);r.typeChecker(k(ie.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=r.options)||void 0===a?void 0:a.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=r.options)||void 0===s?void 0:s.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>t.dequal(e,u[0]))):u.every((e=>null==e))})),parseChildren:Y},ne=[{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}],oe=U(ne),le={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:ne},ue={propertyAliases:oe,operatorData:le,evaluate:(e,r)=>a(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],r);r.typeChecker(k(le.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=r.options)||void 0===a?void 0:a.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=r.options)||void 0===s?void 0:s.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!t.dequal(e,u[0]))):u.some((e=>null===e&&void 0===e))})),parseChildren:Y},de=[{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"}],ce=U(de),pe={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:de},he={propertyAliases:ce,operatorData:pe,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(k(pe.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=>g(e)))?r.reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{}):r.reduce(((e,t)=>e+t))})),parseChildren:Y},ve=[{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}],ye=U(ve),fe={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:ve},me={propertyAliases:ye,operatorData:fe,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a,i]=yield B([e.values,e.from,e.subtract],t);t.typeChecker(k(fe.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:Y},ge=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],be=U(ge),Te={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:ge},Oe={propertyAliases:be,operatorData:Te,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);if(t.typeChecker(k(Te.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:Y},Ce=[{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"}],qe=U(Ce),Se={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Ce},je={propertyAliases:qe,operatorData:Se,evaluate:(e,t)=>a(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(k(Se.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:Y},Ee=[{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}],Ae=U(Ee),xe={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Ee},Ne={propertyAliases:Ae,operatorData:xe,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(k(xe.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:Y},we=[{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}],Pe=U(we),Le={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:we},Ie={propertyAliases:Pe,operatorData:Le,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(k(Le.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:Y},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"}],ke=U(Ue),Re={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ue},De={propertyAliases:ke,operatorData:Re,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){t.typeChecker(k(Re.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})}},_e=[{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}$"}],Qe=U(_e),Fe={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:_e},He={propertyAliases:Qe,operatorData:Fe,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a]=yield B([e.testString,e.pattern],t);t.typeChecker(k(Fe.parameters,{testString:r,pattern:a}));return new RegExp(a).test(r)})),parseChildren:e=>{const[t,r]=e.children;return Object.assign(Object.assign({},e),{testString:t,pattern:r})}},Me=[{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(Me),Be={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:Me},Ge={propertyAliases:$e,operatorData:Be,evaluate:(t,r)=>a(void 0,void 0,void 0,(function*(){var a,i;const[s,n={}]=yield B([t.property,t.additionalData],r);r.typeChecker(k(Be.parameters,{property:s,additionalData:n}));const o=Object.assign(Object.assign({},null!==(i=null===(a=r.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),n);return e(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}},ze=[{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:{}},{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(ze),Je={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:ze},Ve={propertyAliases:We,operatorData:Je,evaluate:(e,t)=>a(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(k(Je.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=R(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)}const o=/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g,l=[];for(const e of r.split(o)){if(!/(?<!\\){{(.+)}}/.exec(e)){l.push(e.replace("\\{{","{{"));continue}const r=yield Ye(e,a,n,t);l.push(i?String(r).trim():r)}return l.join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ye=(t,r,i,s)=>a(void 0,void 0,void 0,(function*(){var a,n;const o=null!==(n=null===(a=s.options)||void 0===a?void 0:a.data)&&void 0!==n?n:{},l=t.replace(/{{(.+)}}/,"$1"),u=yield $(e(r,l,e(o,l,"")),s);if("number"!=typeof u)return u;if(!(l in i))return u;const d=i[l];if(u in d)return d[u].replace("{}",String(u));const c=Object.keys(i[l]),p=c.find((e=>e.startsWith(">")));if(p){if(u>Number(p.slice(1)))return null==d?void 0:d[p]}const h=c.find((e=>e.startsWith("<")));if(h){if(u<Number(h.slice(1)))return null==d?void 0:d[h]}return d.other?d.other.replace("{}",String(u)):u})),Xe=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Ze=U(Xe),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Xe},et={propertyAliases:Ze,operatorData:Ke,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(k(Ke.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},tt=[{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}],rt=U(tt),at={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:tt},it=" ",st={propertyAliases:rt,operatorData:at,evaluate:(e,t)=>a(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:it,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(k(at.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=it]=e.children;return Object.assign(Object.assign({},e),{value:t,delimiter:r})}},nt=[{name:"query",description:"SQL query string, with parameterised replacements (e.g. $1, $2, etc)",aliases:["text"],required:!0,type:"string"},{name:"values",description:"An array/object of values to replace the SQL string parameters, as per SQL connection specifications ",aliases:["replacements"],required:!1,type:["array","object"]},{name:"single",description:"Specify if returning a single record",aliases:["singleRecord"],required:!1,type:"boolean"},{name:"flatten",description:"Specify whether to flatten resulting record objects to arrays of values",aliases:["flat","array"],required:!1,type:"boolean"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],ot=U(nt),lt={description:"Query an SQL database",aliases:["sql","pgSql","postgres","pg","sqLite","sqlite","mySql"],parameters:nt},ut={propertyAliases:ot,operatorData:lt,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){var r,i,s;const n=null===(r=t.options)||void 0===r?void 0:r.sqlConnection;if(!n)throw new Error("No SQL database connection provided");const[o,l,u,d,c,p]=yield B([e.query,e.values||[],e.single,e.flatten,e.useCache,e.type],t);t.typeChecker(k(lt.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(s=null!==(i=e.useCache)&&void 0!==i?i:t.options.useCache)||void 0===s||s;{const e=t.cache.useCache(h,((e,t,r,i,s)=>a(void 0,void 0,void 0,(function*(){const a=(yield n.query({query:e,values:t}))||[];["array","string","number"].includes(null!=s?s:"")&&(i=!0);const o=i?a.map((e=>{const t=Object.values(e);return t.length<=1?t[0]:t})):a;return r?o[0]:o}))),o,l,u,d,p);return e}})),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)=>a(void 0,void 0,void 0,(function*(){var r,i,s,n,o,l,u;const d=null!==(r=t.graphQLClient)&&void 0!==r?r:t.httpClient;if(!d)throw new Error("No HTTP client provided for GraphQL connection");const[c,p,h,v,y,f]=yield B([e.query,e.url,yield z(e.variables,t),e.returnNode,e.headers,e.useCache],t),{url:m,headers:g}=p instanceof Object?p:{url:p,headers:null};t.typeChecker([...k(pt.parameters,{url:m,query:c,variables:h,returnNode:v,headers:y,useCache:f}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=m&&"graphqlendpoint"!==m.toLowerCase()?m:"",T=null!==(n=null!==(s=null===(i=t.options.graphQLConnection)||void 0===i?void 0:i.endpoint)&&void 0!==s?s:t.options.baseEndpoint)&&void 0!==n?n:"",O=F(b)?b:H(T,b),C={query:c,variables:h},q=null===(o=null!=f?f:t.options.useCache)||void 0===o||o,S=yield t.cache.useCache(q,((e,t,r,i)=>a(void 0,void 0,void 0,(function*(){const a=yield M(d,{url:e,method:"post",data:t,headers:r});return Q(null==a?void 0:a.data,i)}))),O,C,Object.assign(Object.assign(Object.assign(Object.assign({},null===(l=t.options.graphQLConnection)||void 0===l?void 0:l.headers),null===(u=t.options)||void 0===u?void 0:u.headers),g),y),v);return S})),parseChildren:(e,t)=>a(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=R(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}],yt=U(vt),ft={description:"HTTP GET Request",aliases:["get","api"],parameters:vt},mt=(e,t)=>a(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=R(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gt=mt,bt={propertyAliases:yt,operatorData:ft,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){var r,i,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield B([e.url,yield z(e.parameters,t),e.returnProperty,yield z(e.headers,t),e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...k(ft.parameters,{url:p,returnProperty:u,headers:d,parameters:l,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",y=Object.assign(Object.assign(Object.assign({},null===(i=t.options)||void 0===i?void 0:i.headers),h),d),f=null===(s=null!=c?c:t.options.useCache)||void 0===s||s,m=yield t.cache.useCache(f,((e,t,r,i)=>a(void 0,void 0,void 0,(function*(){const a=yield M(n,{url:e,params:t,headers:r});return Q(a,i)}))),F(p)?p:H(v,p),l,y,u);return m})),parseChildren:mt},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)=>a(void 0,void 0,void 0,(function*(){var r,i,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield B([e.url,yield z(e.parameters,t),e.returnProperty,yield z(e.headers,t),e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...k(Ct.parameters,{url:p,headers:d,data:l,returnProperty:u,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",y=Object.assign(Object.assign(Object.assign({},null===(i=t.options)||void 0===i?void 0:i.headers),h),d),f=null!==(s=null!=c?c:t.options.useCache)&&void 0!==s&&s,m=yield t.cache.useCache(f,((e,t,r,i)=>a(void 0,void 0,void 0,(function*(){const a=yield M(n,{url:e,data:t,headers:r,method:"post"});return Q(a,i)}))),F(p)?p:H(v,p),l,y,u);return m})),parseChildren:gt},St=[{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"]}],jt=U(St),Et={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:St},At={propertyAliases:jt,operatorData:Et,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){t.typeChecker(k(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 i=[e,r],a(void 0,void 0,void 0,(function*(){const[e,r]=yield B(i,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var i}));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})}},xt=[{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"]}],Nt={propertyAliases:U(xt),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:xt},evaluate:(e,t)=>a(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 s=Array.isArray(e.branches)?D(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=i(s)?yield $(s,t):s;if(!g(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)=>a(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=D(yield B(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},wt=[{name:"functionName",description:"Path (in options.functions) to the required function",aliases:["functionPath","funcName","function","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:["array","any"],default:[]},{name:"input",description:"Argument for the function if a single input parameter",aliases:["arg"],required:!1,type:"any",default:"input"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],Pt=U(wt),Lt={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:wt},It={propertyAliases:Pt,operatorData:Lt,evaluate:(t,r)=>a(void 0,void 0,void 0,(function*(){var i,s,n,o;const[l,u=[],d,c]=yield B([t.functionName,t.args,t.input,t.useCache],r);r.typeChecker(k(Lt.parameters,{functionName:l,args:u}));const{data:p,functions:h}=r.options;if(!h)throw new Error("- No functions defined");const v=null!==(n=null!==(s=null!==(i=e(h,`${l}.function`,null))&&void 0!==i?i:e(h,l,null))&&void 0!==s?s:e(p,l,null))&&void 0!==n?n:e(r.options,l,null);if(!v||"function"!=typeof v)throw new Error(`- No function found: "${l}"`);const y=null!==(o=null!=c?c:r.options.useCache)&&void 0!==o&&o,f=[...void 0===d?[]:[yield z(d,r)],...Array.isArray(u)?u:[u]];return yield r.cache.useCache(y,((e,...t)=>a(void 0,void 0,void 0,(function*(){return yield v(...t)}))),l,...f)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionName:t,args:r})}},Ut=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],kt=U(Ut),Rt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Ut},Dt={propertyAliases:kt,operatorData:Rt,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){return t.typeChecker(k(Rt.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:X,BUILD_OBJECT:At,CONDITIONAL:De,COUNT:et,CUSTOM_FUNCTIONS:It,DIVIDE:je,EQUAL:se,GET:bt,GRAPHQL:ht,GREATER_THAN:Ne,LESS_THAN:Ie,MATCH:Nt,MULTIPLY:Oe,NOT_EQUAL:ue,OBJECT_PROPERTIES:Ge,OR:te,PASSTHRU:Dt,PLUS:he,POST:qt,REGEX:He,SPLIT:st,SQL:ut,STRING_SUBSTITUTION:Ve,SUBTRACT:me});class Qt{constructor(e){var t,r;this.useCache=(e,t,...r)=>a(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("_"),Ht=e=>e?"name"in e&&"fetch"===e.name?$t(e):"Axios"in e&&"Axios"===e.Axios.name?Mt(e):e:"undefined"!=typeof window&&"document"in window&&"fetch"in window?$t(window.fetch):void 0,Mt=e=>({get:t=>a(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"get"}))).data})),post:t=>a(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"post"}))).data})),throwError:t=>{var r,a,i,s;if(e.isAxiosError(t)&&t.response)throw t.errorData={status:null===(r=t.response)||void 0===r?void 0:r.status,error:null===(a=t.response)||void 0===a?void 0:a.statusText,url:null===(i=t.config)||void 0===i?void 0:i.url,response:null===(s=t.response)||void 0===s?void 0:s.data},t;throw new Error("Network error: "+(null==t?void 0:t.message))}}),$t=e=>({get:t=>a(void 0,void 0,void 0,(function*(){const{url:a,headers:i,params:s={}}=t,n=Object.keys(s).length>0?`?${r.stringify(s)}`:"",o=yield e(a+n,{headers:i,method:"GET"}),l=yield o.json();if(!o.ok){const e=new Error("Problem with GET request");throw e.name="FetchError",e.errorData={status:o.status,error:o.statusText,url:o.url,response:l},console.log(e.errorData),e}return l})),post:t=>a(void 0,void 0,void 0,(function*(){const{url:r,headers:a,params:i,data:s}=t,n=new URLSearchParams(i),o=n.size>0?`?${n.toString()}`:"",l=yield e(r+o,{headers:a,body:JSON.stringify(s),method:"POST"}),u=yield l.json();if(!l.ok){const e=new Error("Problem with POST request");throw e.name="FetchError",e.errorData={status:l.status,error:l.statusText,url:l.url,response:u},console.log(e.errorData),e}return u})),throwError:e=>{throw e}});class Bt{constructor(e={}){var t,r,a;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=w(...t);if(!0===r)return;const a=new Error(r);throw a.name="Type Error",a},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.17.0",this.options=Gt(e),this.operators=l(_t,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],b),this.operatorAliases=b,this.cache=new Qt({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime}),this.graphQLClient=Ht(null===(a=e.graphQLConnection)||void 0===a?void 0:a.httpClient),this.httpClient=Ht(e.httpClient)}evaluate(e,t={}){var r;return a(this,void 0,void 0,(function*(){const a=v(this.options,Gt(t),!0);return t.httpClient&&(this.httpClient=Ht(t.httpClient)),(null===(r=t.graphQLConnection)||void 0===r?void 0:r.httpClient)&&(this.graphQLClient=Ht(t.graphQLConnection.httpClient)),a.maxCacheSize&&a.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(a.maxCacheSize),a.maxCacheTime&&a.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(a.maxCacheTime),yield $(e,{options:a,operators:t.excludeOperators?l(_t,t.excludeOperators,b):this.operators,operatorAliases:this.operatorAliases,typeChecker:a.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient})}))}getOptions(){return this.options}updateOptions(e){this.options=v(this.options,Gt(e),!1),this.options.excludeOperators&&(this.operators=l(_t,this.options.excludeOperators,b))}getOperators(){const e=this.options.excludeOperators?l(_t,this.options.excludeOperators,b):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(b))];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])=>{const r="function"==typeof t?t:null==t?void 0:t.function,a={name:e,numRequiredArgs:null==r?void 0:r.length};if("function"!=typeof t){const{description:e,argsDefault:r,inputDefault:i,textColor:s,backgroundColor:n}=t;return e&&(a.description=e),r&&(a.argsDefault=r),i&&(a.inputDefault=i),s&&(a.textColor=s),n&&(a.backgroundColor=n),a}return a}))}}const Gt=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;exports.AxiosClient=Mt,exports.FetchClient=$t,exports.FigTreeError=E,exports.FigTreeEvaluator=Bt,exports.SQLNodePostgres=e=>({query:({query:t,values:r=[]})=>a(void 0,void 0,void 0,(function*(){const a={text:t,values:null!=r?r:[]};try{const t=yield e.query(a);if(null==t?void 0:t.error)throw new Error(t.error);return t.rows}catch(e){throw e.name="Node-Postgres error",e}}))}),exports.SQLite=e=>({query:({query:t,values:r=[]})=>a(void 0,void 0,void 0,(function*(){try{return yield e.all(t,r)}catch(e){throw e.name="SQLite error",e}}))}),exports.evaluateExpression=(e,t)=>new Bt(t).evaluate(e),exports.isAliasString=c,exports.isFigTreeError=e=>e instanceof E,exports.isFragmentNode=s,exports.isObject=g,exports.isOperatorNode=i,exports.preProcessShorthand=C,exports.standardiseOperatorName=n,exports.truncateString=u;
1
+ "use strict";var e=require("object-property-extractor"),t=require("dequal/lite");function r(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 a=e=>e instanceof Object&&"operator"in e,i=e=>e instanceof Object&&"fragment"in e,s=e=>{const t=f(e);return t||e},n=(e,t)=>t[s(e)],o=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[s(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[s(e)]]})),a},l=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,u=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},d=e=>/^\$.+/.test(e),c=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&d(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},p=(e,t)=>r(void 0,void 0,void 0,(function*(){var r,a;if(!(e.operator in(null!==(a=null===(r=t.options)||void 0===r?void 0:r.functions)&&void 0!==a?a:{})))return e;const{operator:i,fallback:s,outputType:n,type:o,useCache:l,input:u,args:d}=e,c=function(e,t){var r={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)t.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(r[a[i]]=e[a[i]])}return r}(e,["operator","fallback","outputType","type","useCache","input","args"]),p={operator:"CUSTOM_FUNCTIONS",function:i};return void 0!==s&&(p.fallback=s),void 0!==n&&(p.outputType=n),void 0!==o&&(p.type=o),void 0!==l&&(p.useCache=l),void 0!==d&&(p.args=d),void 0!==u?p.input=u:Object.keys(c).length>0&&(p.input=c),p})),h=(e,t,r)=>{const a=Object.assign(Object.assign({},e),t);return r?((e.data||t.data)&&(a.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(a.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(a.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(a.headers=Object.assign(Object.assign({},e.headers),t.headers)),a):a},v={number:e=>y(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},y=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},f=e=>e.replace(/[^A-Za-z\d _-]/g,"").split(/[-_ ]/).map((e=>{var t;return null!==(t=e.match(/[a-z]+|[A-Z]+[a-z]*/g))&&void 0!==t?t:e})).flat().filter((e=>""!==e)).map(((e,t)=>0===t?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""),m=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),g={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",sql:"SQL",pgSql:"SQL",postgres:"SQL",pg:"SQL",sqLite:"SQL",sqlite:"SQL",mySql:"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"},b=g,T=/(\$[^()]+)\((.*)\)/,O=(e,t={},r,a=!0)=>a?"string"==typeof e?C(e,t,r):m(e)?S(e,t,r):e:e,C=(e,t,r)=>{const a=T.exec(e);if(!a)return e;const i=a[1].trim(),s=a[2].split(",").map((e=>O(e.trim(),t,r)));return j(i,s,t,r)},S=(e,t,r)=>{if(a(e)||i(e))return e;const s=Object.entries(e),n=s.filter((([e])=>d(e))),o=s.filter((([e])=>!d(e))),l=n.reduce(((e,[a,i])=>e=Object.assign(Object.assign({},e),j(a,i,t,r))),{});return Object.assign(Object.assign({},l),Object.fromEntries(o))},j=(e,t,r,a)=>{const i=e.slice(1),s=n(i,b);return s?Array.isArray(t)?{operator:s,children:t}:m(t)&&!Object.keys(t).some((e=>d(e)))?Object.assign({operator:s},t):{operator:s,children:[t]}:i in r?{fragment:i,parameters:Object.assign({},t)}:a.includes(i)?Array.isArray(t)?{operator:i,args:t}:m(t)?"input"in t||"args"in t?Object.assign({operator:i},t):{operator:i,input:t}:{operator:i,args:[t]}:{[e]:t}};class E extends Error{constructor(e,t,r,a){super(e.message),Object.assign(this,e),this.operator=t,this.expression=a,this.errorData=e.errorData,r&&(this.name=r),"Error"===this.name&&(this.name="FigTreeError");const i=(t?"Operator: "+t:"")+("FigTreeError"===this.name?"":` - ${this.name}`),s=this.errorData?"\n"+JSON.stringify(this.errorData,null,2):"";this.prettyPrint=`${""!==i?i+"\n":""}${this.message}${"\n{}"===s?"":s}`}}const q=({fallback:e,operator:t,name:r,error:a,expression:i,returnErrorAsString:s=!1})=>{if(void 0!==e)return e;if(a instanceof E){if(!s)throw a;return a.prettyPrint}const n=new E("string"==typeof a?new Error(a):a,t,r,i);if(s)return n.prettyPrint;throw n},A=e=>m(e)&&"literal"in e,x=({value:e,name:t,expectedType:r})=>{if(A(r)){const{literal:a}=r;return!!a.includes(e)||P(t,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(r))return!!r.some((r=>!0===x({value:e,name:t,expectedType:r})))||P(t,e,r.join("|"));return!!(0,N[r])(e)||P(t,e,r)},w=(...e)=>{const t=[];return e.forEach((e=>{const r=x(e);!0!==r&&t.push(r)})),!(t.length>0)||t.join("\n")},N={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=>m(e),undefined:e=>void 0===e},P=(e,t,r)=>void 0===t&&e?`- Missing required property "${e}" (type: ${r})`:void 0!==e?`- Property "${e}" (value: ${L(t)}) is not of type: ${r}`:`- ${L(t)} is not of type: ${r}`,L=e=>{const t=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return l(t,50)},I=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},k=(e,t)=>e.map((({name:e,required:r,type:a})=>{if(A(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}})),U=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},R=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=w(...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=>m(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(t,r,a=void 0)=>{const i=r?e(t,r,a):t;return Array.isArray(i)?i.map((e=>D(e))):r?null===i?null:D(i):i},Q=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=(e,t)=>r(void 0,void 0,void 0,(function*(){const{url:r,params:a={},data:i={},headers:s={},method:n="get"}=t;if(!r||""===r)throw new Error("Invalid url");try{return yield e[n]({url:r,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:a,data:i})}catch(t){e.throwError(t)}})),M=(e,t)=>r(void 0,void 0,void 0,(function*(){var r,s,o,l,d,h;const{options:y,operators:f,operatorAliases:g}=t;let b=(null==y?void 0:y.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return a(t)?t:e}catch(t){return e}})(e):e;const T=Object.keys(null!==(s=null===(r=t.options)||void 0===r?void 0:r.functions)&&void 0!==s?s:{});b=O(b,null===(o=t.options)||void 0===o?void 0:o.fragments,T,!y.noShorthand),Array.isArray(b)&&(b=yield $(b,t));const C=a(b),S=i(b);if(C&&(b=yield p(b,t)),y.evaluateFullObject&&!C&&!S)return c(yield G(b,t),t);if(!C&&!S)return y.supportDeprecatedValueNodes&&m(b)&&"value"in b?b.value:c(b,t);const{fallback:j}=b,E=null!==(l=null==y?void 0:y.returnErrorAsString)&&void 0!==l&&l;if(S){const e=b,[r,i]=yield $([e.fragment,e.parameters],t),s=O(null===(d=null==y?void 0:y.fragments)||void 0===d?void 0:d[r],y.fragments,T,!y.noShorthand);if(void 0===s)return q({fallback:yield M(j,t),error:`Fragment not defined: ${r}`,expression:b,returnErrorAsString:E});if(!a(s))return c(s,t);b=Object.assign(Object.assign(Object.assign({},e),s),i),delete b.fragment}const A=b,x=n(A.operator,g);if(!x)return q({fallback:yield M(j,t),error:`Invalid operator: ${A.operator}`,expression:b,returnErrorAsString:E});if(!t.operators[x])return q({fallback:yield M(j,t),error:`Excluded operator: ${A.operator}`,expression:b,returnErrorAsString:E});const{propertyAliases:w,evaluate:N,parseChildren:P}=f[x];let L=((e,t)=>u(t,(t=>t in e?e[t]:t)))(w,A);const I=yield B(L,t);S||Object.entries(I).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const k=S?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),I)}):t;if("children"in L){if(Array.isArray(L.children)||(L.children=yield M(L.children,k)),!Array.isArray(L.children))return q({fallback:yield M(j,t),operator:x,name:"Type Error",error:'- Property "children" is not of type: array',expression:b,returnErrorAsString:E});L=yield P(L,k),delete L.children}let U;try{U=yield N(L,k)}catch(e){return q({fallback:yield M(L.fallback,t),operator:x,error:e,expression:L,returnErrorAsString:E})}const R=null!==(h=null==L?void 0:L.outputType)&&void 0!==h?h:null==L?void 0:L.type;if(!R)return U;const D=yield M(R,t);return D in v?v[D](U):q({fallback:yield M(j,t),operator:x,error:`- Invalid output type: ${D}`,expression:L,returnErrorAsString:E})})),$=(e,t)=>r(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>M(e,t)))):yield M(e,t)})),B=(e,t)=>r(void 0,void 0,void 0,(function*(){var r;const a=Object.keys(e).filter(d);if(0===a.length)return{};const i=[];a.forEach((r=>i.push(M(e[r],t))));const s=yield Promise.all(i),n=U(a,yield Promise.all(i));for(const[e,t]of s.entries())"string"==typeof t&&d(t)&&(n[a[e]]=null!==(r=null==n?void 0:n[t])&&void 0!==r?r:t);return n})),G=(e,t)=>r(void 0,void 0,void 0,(function*(){if(!m(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{d(r)&&(a.push(r,M(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),R(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,M(a,t))}));const s=yield Promise.all(r);return c(R(s),t)})),z=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],W=I(z),J={description:"Logical AND",aliases:["and","&","&&"],parameters:z},V=e=>{const t=e.children;return Object.assign(Object.assign({},e),{values:t})},Y={propertyAliases:W,operatorData:J,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);return t.typeChecker(k(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]}],Z=I(X),K={description:"Logical OR",aliases:["or","|","||"],parameters:X},ee={propertyAliases:Z,operatorData:K,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);return t.typeChecker(k(K.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=I(te),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:te},ie={propertyAliases:re,operatorData:ae,evaluate:(e,a)=>r(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield $([e.values,e.caseInsensitive,e.nullEqualsUndefined],a);a.typeChecker(k(ae.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=a.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=a.options)||void 0===s?void 0:s.nullEqualsUndefined)&&a.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>t.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=I(se),oe={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:se},le={propertyAliases:ne,operatorData:oe,evaluate:(e,a)=>r(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield $([e.values,e.caseInsensitive,e.nullEqualsUndefined],a);a.typeChecker(k(oe.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=a.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=a.options)||void 0===s?void 0:s.nullEqualsUndefined)&&a.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!t.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=I(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)=>r(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);return t.typeChecker(k(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=>m(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=I(he),ye={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},fe={propertyAliases:ve,operatorData:ye,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a,i]=yield $([e.values,e.from,e.subtract],t);t.typeChecker(k(ye.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},me=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],ge=I(me),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:me},Te={propertyAliases:ge,operatorData:be,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);if(t.typeChecker(k(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=I(Oe),Se={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},je={propertyAliases:Ce,operatorData:Se,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield $([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(k(Se.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},Ee=[{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}],qe=I(Ee),Ae={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Ee},xe={propertyAliases:qe,operatorData:Ae,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield $([e.values,e.strict],t);if(t.typeChecker(k(Ae.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},we=[{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}],Ne=I(we),Pe={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:we},Le={propertyAliases:Ne,operatorData:Pe,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield $([e.values,e.strict],t);if(t.typeChecker(k(Pe.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},Ie=[{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"}],ke=I(Ie),Ue={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ie},Re={propertyAliases:ke,operatorData:Ue,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){t.typeChecker(k(Ue.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield M(e.condition,t))?yield M(e.valueIfTrue,t):yield M(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=I(De),Qe={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},Fe={propertyAliases:_e,operatorData:Qe,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a]=yield $([e.testString,e.pattern],t);t.typeChecker(k(Qe.parameters,{testString:r,pattern:a}));return new RegExp(a).test(r)})),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:{}}],Me=I(He),$e={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:He},Be={propertyAliases:Me,operatorData:$e,evaluate:(t,a)=>r(void 0,void 0,void 0,(function*(){var r,i;const[s,n={}]=yield $([t.property,t.additionalData],a);a.typeChecker(k($e.parameters,{property:s,additionalData:n}));const o=Object.assign(Object.assign({},null!==(i=null===(r=a.options)||void 0===r?void 0:r.data)&&void 0!==i?i:{}),n);return e(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}},Ge=[{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:{}},{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:{}}],ze=I(Ge),We={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:Ge},Je={propertyAliases:ze,operatorData:We,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a={},i=!0,s="%",n={}]=yield $([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(k(We.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=U(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)}const o=/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g,l=[];for(const e of r.split(o)){if(!/(?<!\\){{(.+)}}/.exec(e)){l.push(e.replace("\\{{","{{"));continue}const r=yield Ve(e,a,n,t);l.push(i?String(r).trim():r)}return l.join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ve=(t,a,i,s)=>r(void 0,void 0,void 0,(function*(){var r,n;const o=null!==(n=null===(r=s.options)||void 0===r?void 0:r.data)&&void 0!==n?n:{},l=t.replace(/{{(.+)}}/,"$1"),u=yield M(e(a,l,e(o,l,"")),s);if("number"!=typeof u)return u;if(!(l in i))return u;const d=i[l];if(u in d)return d[u].replace("{}",String(u));const c=Object.keys(i[l]),p=c.find((e=>e.startsWith(">")));if(p){if(u>Number(p.slice(1)))return null==d?void 0:d[p]}const h=c.find((e=>e.startsWith("<")));if(h){if(u<Number(h.slice(1)))return null==d?void 0:d[h]}return d.other?d.other.replace("{}",String(u)):u})),Ye=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Xe=I(Ye),Ze={description:"Count elements in an array",aliases:["count","length"],parameters:Ye},Ke={propertyAliases:Xe,operatorData:Ze,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);return t.typeChecker(k(Ze.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=I(et),rt={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:et},at=" ",it={propertyAliases:tt,operatorData:rt,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield $([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(k(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:"SQL query string, with parameterised replacements (e.g. $1, $2, etc)",aliases:["text"],required:!0,type:"string"},{name:"values",description:"An array/object of values to replace the SQL string parameters, as per SQL connection specifications ",aliases:["replacements"],required:!1,type:["array","object"]},{name:"single",description:"Specify if returning a single record",aliases:["singleRecord"],required:!1,type:"boolean"},{name:"flatten",description:"Specify whether to flatten resulting record objects to arrays of values",aliases:["flat","array"],required:!1,type:"boolean"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],nt=I(st),ot={description:"Query an SQL database",aliases:["sql","pgSql","postgres","pg","sqLite","sqlite","mySql"],parameters:st},lt={propertyAliases:nt,operatorData:ot,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var a,i,s;const n=null===(a=t.options)||void 0===a?void 0:a.sqlConnection;if(!n)throw new Error("No SQL database connection provided");const[o,l,u,d,c,p]=yield $([e.query,e.values||[],e.single,e.flatten,e.useCache,e.type],t);t.typeChecker(k(ot.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(s=null!==(i=e.useCache)&&void 0!==i?i:t.options.useCache)||void 0===s||s;{const e=t.cache.useCache(h,((e,t,a,i,s)=>r(void 0,void 0,void 0,(function*(){const r=(yield n.query({query:e,values:t}))||[];["array","string","number"].includes(null!=s?s:"")&&(i=!0);const o=i?r.map((e=>{const t=Object.values(e);return t.length<=1?t[0]:t})):r;return a?o[0]:o}))),o,l,u,d,p);return e}})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{query:t,values:r})}},ut=[{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}],dt=I(ut),ct={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:ut},pt={propertyAliases:dt,operatorData:ct,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var a,i,s,n,o,l,u;const d=null!==(a=t.graphQLClient)&&void 0!==a?a:t.httpClient;if(!d)throw new Error("No HTTP client provided for GraphQL connection");const[c,p,h,v,y,f]=yield $([e.query,e.url,yield G(e.variables,t),e.returnNode,e.headers,e.useCache],t),{url:m,headers:g}=p instanceof Object?p:{url:p,headers:null};t.typeChecker([...k(ct.parameters,{url:m,query:c,variables:h,returnNode:v,headers:y,useCache:f}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=m&&"graphqlendpoint"!==m.toLowerCase()?m:"",T=null!==(n=null!==(s=null===(i=t.options.graphQLConnection)||void 0===i?void 0:i.endpoint)&&void 0!==s?s:t.options.baseEndpoint)&&void 0!==n?n:"",O=Q(b)?b:F(T,b),C={query:c,variables:h},S=null===(o=null!=f?f:t.options.useCache)||void 0===o||o,j=yield t.cache.useCache(S,((e,t,a,i)=>r(void 0,void 0,void 0,(function*(){const r=yield H(d,{url:e,method:"post",data:t,headers:a});return _(null==r?void 0:r.data,i)}))),O,C,Object.assign(Object.assign(Object.assign(Object.assign({},null===(l=t.options.graphQLConnection)||void 0===l?void 0:l.headers),null===(u=t.options)||void 0===u?void 0:u.headers),g),y),v);return j})),parseChildren:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield $(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=U(n,o),u=Object.assign(Object.assign({},e),{query:r,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},ht=[{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}],vt=I(ht),yt={description:"HTTP GET Request",aliases:["get","api"],parameters:ht},ft=(e,t)=>r(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield $(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=U(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),mt=ft,gt={propertyAliases:vt,operatorData:yt,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var a,i,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield $([e.url,yield G(e.parameters,t),e.returnProperty,yield G(e.headers,t),e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...k(yt.parameters,{url:p,returnProperty:u,headers:d,parameters:l,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(a=t.options.baseEndpoint)&&void 0!==a?a:"",y=Object.assign(Object.assign(Object.assign({},null===(i=t.options)||void 0===i?void 0:i.headers),h),d),f=null===(s=null!=c?c:t.options.useCache)||void 0===s||s,m=yield t.cache.useCache(f,((e,t,a,i)=>r(void 0,void 0,void 0,(function*(){const r=yield H(n,{url:e,params:t,headers:a});return _(r,i)}))),Q(p)?p:F(v,p),l,y,u);return m})),parseChildren:ft},bt=[{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}],Tt=I(bt),Ot={description:"HTTP POST Request",aliases:["post"],parameters:bt},Ct={propertyAliases:Tt,operatorData:Ot,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var a,i,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield $([e.url,yield G(e.parameters,t),e.returnProperty,yield G(e.headers,t),e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...k(Ot.parameters,{url:p,headers:d,data:l,returnProperty:u,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(a=t.options.baseEndpoint)&&void 0!==a?a:"",y=Object.assign(Object.assign(Object.assign({},null===(i=t.options)||void 0===i?void 0:i.headers),h),d),f=null!==(s=null!=c?c:t.options.useCache)&&void 0!==s&&s,m=yield t.cache.useCache(f,((e,t,a,i)=>r(void 0,void 0,void 0,(function*(){const r=yield H(n,{url:e,data:t,headers:a,method:"post"});return _(r,i)}))),Q(p)?p:F(v,p),l,y,u);return m})),parseChildren:mt},St=[{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"]}],jt=I(St),Et={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:St},qt={propertyAliases:jt,operatorData:Et,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){t.typeChecker(k(Et.parameters,{properties:e.properties}));const a=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:a})=>{return i=[e,a],r(void 0,void 0,void 0,(function*(){const[e,r]=yield $(i,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var i}));return Object.fromEntries(yield Promise.all(a))})),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})}},At=[{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"]}],xt={propertyAliases:I(At),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:At},evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var r;const i=yield M(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:i,expectedType:["string","number","boolean"]});const s=Array.isArray(e.branches)?R(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=a(s)?yield M(s,t):s;if(!m(n))throw new Error("Branches don't evaluate to an object");if(i in n)return yield M(n[i],t);if("fallback"in n)return yield M(n.fallback,t);if(i in e)return yield M(e[i],t);throw new Error(`No match found for ${i}`)})),parseChildren:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=R(yield $(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},wt=[{name:"functionName",description:"Path (in options.functions) to the required function",aliases:["functionPath","funcName","function","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:["array","any"],default:[]},{name:"input",description:"Argument for the function if a single input parameter",aliases:["arg"],required:!1,type:"any",default:"input"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],Nt=I(wt),Pt={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:wt},Lt={propertyAliases:Nt,operatorData:Pt,evaluate:(t,a)=>r(void 0,void 0,void 0,(function*(){var i,s,n,o;const[l,u=[],d,c]=yield $([t.functionName,t.args,t.input,t.useCache],a);a.typeChecker(k(Pt.parameters,{functionName:l,args:u}));const{data:p,functions:h}=a.options;if(!h)throw new Error("- No functions defined");const v=null!==(n=null!==(s=null!==(i=e(h,`${l}.function`,null))&&void 0!==i?i:e(h,l,null))&&void 0!==s?s:e(p,l,null))&&void 0!==n?n:e(a.options,l,null);if(!v||"function"!=typeof v)throw new Error(`- No function found: "${l}"`);const y=null!==(o=null!=c?c:a.options.useCache)&&void 0!==o&&o,f=[...void 0===d?[]:[yield G(d,a)],...Array.isArray(u)?u:[u]];return yield a.cache.useCache(y,((e,...t)=>r(void 0,void 0,void 0,(function*(){return yield v(...t)}))),l,...f)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionName:t,args:r})}},It=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],kt=I(It),Ut={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:It},Rt={propertyAliases:kt,operatorData:Ut,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){return t.typeChecker(k(Ut.parameters,{value:e.value})),yield M(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 Dt=Object.freeze({__proto__:null,AND:Y,BUILD_OBJECT:qt,CONDITIONAL:Re,COUNT:Ke,CUSTOM_FUNCTIONS:Lt,DIVIDE:je,EQUAL:ie,GET:gt,GRAPHQL:pt,GREATER_THAN:xe,LESS_THAN:Le,MATCH:xt,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:Be,OR:ee,PASSTHRU:Rt,PLUS:pe,POST:Ct,REGEX:Fe,SPLIT:it,SQL:lt,STRING_SUBSTITUTION:Je,SUBTRACT:fe});class _t{constructor(e){var t,a;this.useCache=(e,t,...a)=>r(this,void 0,void 0,(function*(){if(!e)return yield t(...a);const r=Qt(a),i=r in this.store,s=Date.now(),n=i&&s-this.store[r].timestamp>1e3*this.maxTime;if(i)return this.queue=this.queue.filter((e=>e!==r)),this.queue.unshift(r),this.store[r].timestamp=s,n&&(this.store[r].result=yield t(...a)),this.store[r].result;const o=yield t(...a);return this.store[r]={result:o,timestamp:s},this.queue.unshift(r),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!==(a=null==e?void 0:e.maxTime)&&void 0!==a?a:1800}}const Qt=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),Ft=e=>e||("undefined"!=typeof window&&"document"in window&&"fetch"in window?Ht(window.fetch):void 0),Ht=e=>({get:t=>r(void 0,void 0,void 0,(function*(){const{url:r,headers:a,params:i={}}=t,s=Object.keys(i).length>0?`?${new URLSearchParams(i).toString()}`:"",n=yield e(r+s,{headers:a,method:"GET"}),o=yield n.json();if(!n.ok){const e=new Error("Problem with GET request");throw e.name="FetchError",e.errorData={status:n.status,error:n.statusText,url:n.url,response:o},console.log(e.errorData),e}return o})),post:t=>r(void 0,void 0,void 0,(function*(){const{url:r,headers:a,params:i,data:s}=t,n=new URLSearchParams(i),o=n.size>0?`?${n.toString()}`:"",l=yield e(r+o,{headers:a,body:JSON.stringify(s),method:"POST"}),u=yield l.json();if(!l.ok){const e=new Error("Problem with POST request");throw e.name="FetchError",e.errorData={status:l.status,error:l.statusText,url:l.url,response:u},console.log(e.errorData),e}return u})),throwError:e=>{throw e}});class Mt{constructor(e={}){var t,r,a;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=w(...t);if(!0===r)return;const a=new Error(r);throw a.name="Type Error",a},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.18.1",this.options=$t(e),this.operators=o(Dt,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],g),this.operatorAliases=g,this.cache=new _t({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime}),this.graphQLClient=Ft(null===(a=e.graphQLConnection)||void 0===a?void 0:a.httpClient),this.httpClient=Ft(e.httpClient)}evaluate(e,t={}){var a;return r(this,void 0,void 0,(function*(){const r=h(this.options,$t(t),!0);return t.httpClient&&(this.httpClient=Ft(t.httpClient)),(null===(a=t.graphQLConnection)||void 0===a?void 0:a.httpClient)&&(this.graphQLClient=Ft(t.graphQLConnection.httpClient)),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 M(e,{options:r,operators:t.excludeOperators?o(Dt,t.excludeOperators,g):this.operators,operatorAliases:this.operatorAliases,typeChecker:r.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient})}))}getOptions(){return this.options}updateOptions(e){this.options=h(this.options,$t(e),!1),this.options.excludeOperators&&(this.operators=o(Dt,this.options.excludeOperators,g))}getOperators(){const e=this.options.excludeOperators?o(Dt,this.options.excludeOperators,g):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(g))];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])=>{const r="function"==typeof t?t:null==t?void 0:t.function,a={name:e,numRequiredArgs:null==r?void 0:r.length};if("function"!=typeof t){const{description:e,argsDefault:r,inputDefault:i,textColor:s,backgroundColor:n}=t;return e&&(a.description=e),r&&(a.argsDefault=r),i&&(a.inputDefault=i),s&&(a.textColor=s),n&&(a.backgroundColor=n),a}return a}))}}const $t=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;exports.AxiosClient=e=>({get:t=>r(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"get"}))).data})),post:t=>r(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"post"}))).data})),throwError:t=>{var r,a,i,s;if(e.isAxiosError(t)&&t.response)throw t.errorData={status:null===(r=t.response)||void 0===r?void 0:r.status,error:null===(a=t.response)||void 0===a?void 0:a.statusText,url:null===(i=t.config)||void 0===i?void 0:i.url,response:null===(s=t.response)||void 0===s?void 0:s.data},t;throw new Error("Network error: "+(null==t?void 0:t.message))}}),exports.FetchClient=Ht,exports.FigTreeError=E,exports.FigTreeEvaluator=Mt,exports.SQLNodePostgres=e=>({query:({query:t,values:a=[]})=>r(void 0,void 0,void 0,(function*(){const r={text:t,values:null!=a?a:[]};try{const t=yield e.query(r);if(null==t?void 0:t.error)throw new Error(t.error);return t.rows}catch(e){throw e.name="Node-Postgres error",e}}))}),exports.SQLite=e=>({query:({query:t,values:a=[]})=>r(void 0,void 0,void 0,(function*(){try{return yield e.all(t,a)}catch(e){throw e.name="SQLite error",e}}))}),exports.evaluateExpression=(e,t)=>new Mt(t).evaluate(e),exports.isAliasString=d,exports.isFigTreeError=e=>e instanceof E,exports.isFigTreeExpression=e=>a(e)||i(e)||"string"==typeof e&&d(e)||m(e)&&1===Object.keys(e).length&&d(Object.keys(e)[0]),exports.isFragmentNode=i,exports.isObject=m,exports.isOperatorNode=a,exports.preProcessShorthand=O,exports.standardiseOperatorName=s,exports.truncateString=l;
package/build/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
- import { AxiosStatic } from 'axios';
3
- import { RequestInfo, RequestInit, Response } from 'node-fetch';
4
2
  import { Client } from 'pg';
5
3
  import { Database } from 'sqlite';
4
+ import { AxiosStatic } from 'axios';
5
+ import { RequestInfo, RequestInit, Response } from 'node-fetch';
6
6
 
7
7
  interface CacheOptions {
8
8
  maxSize?: number;
@@ -67,24 +67,12 @@ interface HttpRequest {
67
67
  method?: 'get' | 'post';
68
68
  }
69
69
 
70
- type Fetch = (input: URL | string | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
71
- declare const AxiosClient: (axios: AxiosStatic) => {
72
- get: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
73
- post: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
74
- throwError: (err: unknown) => never;
75
- };
76
- declare const FetchClient: (fetch: Fetch) => {
77
- get: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
78
- post: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
79
- throwError: (err: unknown) => never;
80
- };
81
-
82
70
  interface GraphQLConnection {
83
71
  endpoint: string;
84
72
  headers?: {
85
73
  [key: string]: string;
86
74
  };
87
- httpClient?: HttpClient | AxiosStatic | Fetch;
75
+ httpClient?: HttpClient;
88
76
  }
89
77
 
90
78
  declare const operatorAliases: OperatorAliases;
@@ -96,11 +84,11 @@ type OperatorAliases = Record<string, Operator>;
96
84
  type Fragments = Record<string, Fragment>;
97
85
  type UnknownFunction = (...args: any[]) => EvaluatorOutput;
98
86
  interface FigTreeOptions {
99
- data?: object;
100
- objects?: object;
87
+ data?: Record<string, unknown>;
88
+ objects?: Record<string, unknown>;
101
89
  functions?: Record<string, UnknownFunction | FunctionDefinition>;
102
90
  fragments?: Fragments;
103
- httpClient?: HttpClient | AxiosStatic | Fetch;
91
+ httpClient?: HttpClient;
104
92
  graphQLConnection?: GraphQLConnection;
105
93
  sqlConnection?: SQLConnection;
106
94
  baseEndpoint?: string;
@@ -226,7 +214,6 @@ declare class FigTreeEvaluator {
226
214
  getCustomFunctions(): readonly CustomFunctionMetadata[];
227
215
  getVersion: () => string;
228
216
  }
229
-
230
217
  declare const evaluateExpression: (expression: EvaluatorNode, options?: FigTreeOptions) => Promise<EvaluatorOutput>;
231
218
 
232
219
  declare class FigTreeError extends Error {
@@ -247,13 +234,26 @@ declare const SQLite: (db: Database) => {
247
234
  query: ({ query, values }: QueryInput) => Promise<any[]>;
248
235
  };
249
236
 
237
+ type Fetch = (input: URL | string | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
238
+ declare const AxiosClient: (axios: AxiosStatic) => {
239
+ get: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
240
+ post: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
241
+ throwError: (err: unknown) => never;
242
+ };
243
+ declare const FetchClient: (fetch: Fetch) => {
244
+ get: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
245
+ post: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
246
+ throwError: (err: unknown) => never;
247
+ };
248
+
250
249
  declare const preProcessShorthand: (expression: EvaluatorNode, fragments: Fragments | undefined, functionNames: string[], useShorthand?: boolean) => EvaluatorNode | FragmentNode;
251
250
 
252
- declare const isOperatorNode: (input: EvaluatorNode) => boolean;
251
+ declare const isOperatorNode: (input: EvaluatorNode) => input is OperatorNode;
253
252
  declare const isFragmentNode: (input: EvaluatorNode) => input is FragmentNode;
254
253
  declare const standardiseOperatorName: (name: string) => string;
255
254
  declare const truncateString: (string: string, length?: number) => string;
256
255
  declare const isAliasString: (value: string) => boolean;
257
256
  declare const isObject: (input: unknown) => input is object;
257
+ declare const isFigTreeExpression: (expression: EvaluatorNode) => boolean;
258
258
 
259
- export { AxiosClient, type BasicType, type CustomFunctionMetadata, type EvaluatorNode, type EvaluatorOutput, type ExpectedType, FetchClient, type FigTreeConfig, FigTreeError, FigTreeEvaluator, type FigTreeOptions, type FragmentMetadata, type FragmentNode, type FragmentParameterMetadata, type GraphQLConnection, type LiteralType, type Operator, type OperatorAlias, type OperatorData, type OperatorMetadata, type OperatorNode, type OperatorParameterMetadata, type OutputType, SQLNodePostgres, SQLite, evaluateExpression, isAliasString, isFigTreeError, isFragmentNode, isObject, isOperatorNode, preProcessShorthand, standardiseOperatorName, truncateString };
259
+ export { AxiosClient, type BasicType, type CustomFunctionMetadata, type EvaluatorNode, type EvaluatorOutput, type ExpectedType, FetchClient, type FigTreeConfig, FigTreeError, FigTreeEvaluator, type FigTreeOptions, type Fragment, type FragmentMetadata, type FragmentNode, type FragmentParameterMetadata, type GraphQLConnection, type LiteralType, type Operator, type OperatorAlias, type OperatorData, type OperatorMetadata, type OperatorNode, type OperatorParameterMetadata, type OutputType, SQLNodePostgres, SQLite, evaluateExpression, isAliasString, isFigTreeError, isFigTreeExpression, isFragmentNode, isObject, isOperatorNode, preProcessShorthand, standardiseOperatorName, truncateString };
@@ -1 +1 @@
1
- import e from"object-property-extractor";import{dequal as t}from"dequal/lite";import r from"querystring";function a(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 i=e=>e instanceof Object&&"operator"in e,s=e=>e instanceof Object&&"fragment"in e,n=e=>{const t=m(e);return t||e},o=(e,t)=>t[n(e)],l=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[n(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[n(e)]]})),a},u=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,d=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},c=e=>/^\$.+/.test(e),p=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&c(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},h=(e,t)=>a(void 0,void 0,void 0,(function*(){var r,a;if(!(e.operator in(null!==(a=null===(r=t.options)||void 0===r?void 0:r.functions)&&void 0!==a?a:{})))return e;const{operator:i,fallback:s,outputType:n,type:o,useCache:l,input:u,args:d}=e,c=function(e,t){var r={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)t.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(r[a[i]]=e[a[i]])}return r}(e,["operator","fallback","outputType","type","useCache","input","args"]),p={operator:"CUSTOM_FUNCTIONS",function:i};return void 0!==s&&(p.fallback=s),void 0!==n&&(p.outputType=n),void 0!==o&&(p.type=o),void 0!==l&&(p.useCache=l),void 0!==d&&(p.args=d),void 0!==u?p.input=u:Object.keys(c).length>0&&(p.input=c),p})),v=(e,t,r)=>{const a=Object.assign(Object.assign({},e),t);return r?((e.data||t.data)&&(a.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(a.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(a.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(a.headers=Object.assign(Object.assign({},e.headers),t.headers)),a):a},y={number:e=>f(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=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},m=e=>e.replace(/[^A-Za-z\d _-]/g,"").split(/[-_ ]/).map((e=>{var t;return null!==(t=e.match(/[a-z]+|[A-Z]+[a-z]*/g))&&void 0!==t?t:e})).flat().filter((e=>""!==e)).map(((e,t)=>0===t?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""),g=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),b={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",sql:"SQL",pgSql:"SQL",postgres:"SQL",pg:"SQL",sqLite:"SQL",sqlite:"SQL",mySql:"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"},T=b,O=/(\$[^()]+)\((.*)\)/,C=(e,t={},r,a=!0)=>a?"string"==typeof e?j(e,t,r):g(e)?q(e,t,r):e:e,j=(e,t,r)=>{const a=O.exec(e);if(!a)return e;const i=a[1].trim(),s=a[2].split(",").map((e=>C(e.trim(),t,r)));return E(i,s,t,r)},q=(e,t,r)=>{if(i(e)||s(e))return e;const a=Object.entries(e),n=a.filter((([e])=>c(e))),o=a.filter((([e])=>!c(e))),l=n.reduce(((e,[a,i])=>e=Object.assign(Object.assign({},e),E(a,i,t,r))),{});return Object.assign(Object.assign({},l),Object.fromEntries(o))},E=(e,t,r,a)=>{const i=e.slice(1),s=o(i,T);return s?Array.isArray(t)?{operator:s,children:t}:g(t)&&!Object.keys(t).some((e=>c(e)))?Object.assign({operator:s},t):{operator:s,children:[t]}:i in r?{fragment:i,parameters:Object.assign({},t)}:a.includes(i)?Array.isArray(t)?{operator:i,args:t}:g(t)?"input"in t||"args"in t?Object.assign({operator:i},t):{operator:i,input:t}:{operator:i,args:[t]}:{[e]:t}};class S extends Error{constructor(e,t,r,a){super(e.message),Object.assign(this,e),this.operator=t,this.expression=a,this.errorData=e.errorData,r&&(this.name=r),"Error"===this.name&&(this.name="FigTreeError");const i=(t?"Operator: "+t:"")+("FigTreeError"===this.name?"":` - ${this.name}`),s=this.errorData?"\n"+JSON.stringify(this.errorData,null,2):"";this.prettyPrint=`${""!==i?i+"\n":""}${this.message}${"\n{}"===s?"":s}`}}const A=e=>e instanceof S,w=({fallback:e,operator:t,name:r,error:a,expression:i,returnErrorAsString:s=!1})=>{if(void 0!==e)return e;if(a instanceof S){if(!s)throw a;return a.prettyPrint}const n=new S("string"==typeof a?new Error(a):a,t,r,i);if(s)return n.prettyPrint;throw n},N=e=>g(e)&&"literal"in e,x=({value:e,name:t,expectedType:r})=>{if(N(r)){const{literal:a}=r;return!!a.includes(e)||I(t,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(r))return!!r.some((r=>!0===x({value:e,name:t,expectedType:r})))||I(t,e,r.join("|"));return!!(0,L[r])(e)||I(t,e,r)},P=(...e)=>{const t=[];return e.forEach((e=>{const r=x(e);!0!==r&&t.push(r)})),!(t.length>0)||t.join("\n")},L={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=>g(e),undefined:e=>void 0===e},I=(e,t,r)=>void 0===t&&e?`- Missing required property "${e}" (type: ${r})`:void 0!==e?`- Property "${e}" (value: ${U(t)}) is not of type: ${r}`:`- ${U(t)} is not of type: ${r}`,U=e=>{const t=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return u(t,50)},k=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(N(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}})),D=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},_=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},Q=e=>g(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,H=(t,r,a=void 0)=>{const i=r?e(t,r,a):t;return Array.isArray(i)?i.map((e=>Q(e))):r?null===i?null:Q(i):i},M=e=>/^https?:\/\/.+/.test(e),$=(...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}),""),F=(e,t)=>a(void 0,void 0,void 0,(function*(){const{url:r,params:a={},data:i={},headers:s={},method:n="get"}=t;if(!r||""===r)throw new Error("Invalid url");try{return yield e[n]({url:r,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:a,data:i})}catch(t){e.throwError(t)}})),B=(e,t)=>a(void 0,void 0,void 0,(function*(){var r,a,n,l,u,c;const{options:v,operators:f,operatorAliases:m}=t;let b=(null==v?void 0:v.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return i(t)?t:e}catch(t){return e}})(e):e;const T=Object.keys(null!==(a=null===(r=t.options)||void 0===r?void 0:r.functions)&&void 0!==a?a:{});b=C(b,null===(n=t.options)||void 0===n?void 0:n.fragments,T,!v.noShorthand),Array.isArray(b)&&(b=yield G(b,t));const O=i(b),j=s(b);if(O&&(b=yield h(b,t)),v.evaluateFullObject&&!O&&!j)return p(yield W(b,t),t);if(!O&&!j)return v.supportDeprecatedValueNodes&&g(b)&&"value"in b?b.value:p(b,t);const{fallback:q}=b,E=null!==(l=null==v?void 0:v.returnErrorAsString)&&void 0!==l&&l;if(j){const[e,r]=yield G([b.fragment,b.parameters],t),a=C(null===(u=null==v?void 0:v.fragments)||void 0===u?void 0:u[e],v.fragments,T,!v.noShorthand);if(void 0===a)return w({fallback:yield B(q,t),error:`Fragment not defined: ${e}`,expression:b,returnErrorAsString:E});if(!i(a))return p(a,t);b=Object.assign(Object.assign(Object.assign({},b),a),r),delete b.fragment}const S=o(b.operator,m);if(!S)return w({fallback:yield B(q,t),error:`Invalid operator: ${b.operator}`,expression:b,returnErrorAsString:E});if(!t.operators[S])return w({fallback:yield B(q,t),error:`Excluded operator: ${b.operator}`,expression:b,returnErrorAsString:E});const{propertyAliases:A,evaluate:N,parseChildren:x}=f[S];b=((e,t)=>d(t,(t=>t in e?e[t]:t)))(A,b);const P=yield z(b,t);j||Object.entries(P).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const L=j?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),P)}):t;if("children"in b){if(Array.isArray(b.children)||(b.children=yield B(b.children,L)),!Array.isArray(b.children))return w({fallback:yield B(q,t),operator:S,name:"Type Error",error:'- Property "children" is not of type: array',expression:b,returnErrorAsString:E});b=yield x(b,L),delete b.children}let I;try{I=yield N(b,L)}catch(e){return w({fallback:yield B(b.fallback,t),operator:S,error:e,expression:b,returnErrorAsString:E})}const U=null!==(c=null==b?void 0:b.outputType)&&void 0!==c?c:null==b?void 0:b.type;if(!U)return I;const k=yield B(U,t);return k in y?y[k](I):w({fallback:yield B(q,t),operator:S,error:`- Invalid output type: ${k}`,expression:b,returnErrorAsString:E})})),G=(e,t)=>a(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>B(e,t)))):yield B(e,t)})),z=(e,t)=>a(void 0,void 0,void 0,(function*(){var r;const a=Object.keys(e).filter(c);if(0===a.length)return{};const i=[];a.forEach((r=>i.push(B(e[r],t))));const s=yield Promise.all(i),n=D(a,yield Promise.all(i));for(const[e,t]of s.entries())"string"==typeof t&&c(t)&&(n[a[e]]=null!==(r=null==n?void 0:n[t])&&void 0!==r?r:t);return n})),W=(e,t)=>a(void 0,void 0,void 0,(function*(){if(!g(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{c(r)&&(a.push(r,B(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),_(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,B(a,t))}));const s=yield Promise.all(r);return p(_(s),t)})),J=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],V=k(J),Y={description:"Logical AND",aliases:["and","&","&&"],parameters:J},X=e=>{const t=e.children;return Object.assign(Object.assign({},e),{values:t})},Z={propertyAliases:V,operatorData:Y,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);return t.typeChecker(R(Y.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:X},K=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],ee=k(K),te={description:"Logical OR",aliases:["or","|","||"],parameters:K},re={propertyAliases:ee,operatorData:te,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);return t.typeChecker(R(te.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:X},ae=[{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}],ie=k(ae),se={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:ae},ne={propertyAliases:ie,operatorData:se,evaluate:(e,r)=>a(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield G([e.values,e.caseInsensitive,e.nullEqualsUndefined],r);r.typeChecker(R(se.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=r.options)||void 0===a?void 0:a.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=r.options)||void 0===s?void 0:s.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>t(e,u[0]))):u.every((e=>null==e))})),parseChildren:X},oe=[{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}],le=k(oe),ue={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:oe},de={propertyAliases:le,operatorData:ue,evaluate:(e,r)=>a(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield G([e.values,e.caseInsensitive,e.nullEqualsUndefined],r);r.typeChecker(R(ue.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=r.options)||void 0===a?void 0:a.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=r.options)||void 0===s?void 0:s.nullEqualsUndefined)&&r.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!t(e,u[0]))):u.some((e=>null===e&&void 0===e))})),parseChildren:X},ce=[{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"}],pe=k(ce),he={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ce},ve={propertyAliases:pe,operatorData:he,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);return t.typeChecker(R(he.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=>g(e)))?r.reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{}):r.reduce(((e,t)=>e+t))})),parseChildren:X},ye=[{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}],fe=k(ye),me={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:ye},ge={propertyAliases:fe,operatorData:me,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a,i]=yield G([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:X},be=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],Te=k(be),Oe={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:be},Ce={propertyAliases:Te,operatorData:Oe,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);if(t.typeChecker(R(Oe.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:X},je=[{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"}],qe=k(je),Ee={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:je},Se={propertyAliases:qe,operatorData:Ee,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield G([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(R(Ee.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:X},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}],we=k(Ae),Ne={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Ae},xe={propertyAliases:we,operatorData:Ne,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield G([e.values,e.strict],t);if(t.typeChecker(R(Ne.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:X},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}],Le=k(Pe),Ie={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ue={propertyAliases:Le,operatorData:Ie,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield G([e.values,e.strict],t);if(t.typeChecker(R(Ie.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:X},ke=[{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=k(ke),De={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:ke},_e={propertyAliases:Re,operatorData:De,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){t.typeChecker(R(De.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})}},Qe=[{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}$"}],He=k(Qe),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:Qe},$e={propertyAliases:He,operatorData:Me,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a]=yield G([e.testString,e.pattern],t);t.typeChecker(R(Me.parameters,{testString:r,pattern:a}));return new RegExp(a).test(r)})),parseChildren:e=>{const[t,r]=e.children;return Object.assign(Object.assign({},e),{testString:t,pattern:r})}},Fe=[{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=k(Fe),Ge={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:Fe},ze={propertyAliases:Be,operatorData:Ge,evaluate:(t,r)=>a(void 0,void 0,void 0,(function*(){var a,i;const[s,n={}]=yield G([t.property,t.additionalData],r);r.typeChecker(R(Ge.parameters,{property:s,additionalData:n}));const o=Object.assign(Object.assign({},null!==(i=null===(a=r.options)||void 0===a?void 0:a.data)&&void 0!==i?i:{}),n);return e(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}},We=[{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:{}},{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:{}}],Je=k(We),Ve={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:We},Ye={propertyAliases:Je,operatorData:Ve,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a={},i=!0,s="%",n={}]=yield G([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(R(Ve.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=D(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)}const o=/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g,l=[];for(const e of r.split(o)){if(!/(?<!\\){{(.+)}}/.exec(e)){l.push(e.replace("\\{{","{{"));continue}const r=yield Xe(e,a,n,t);l.push(i?String(r).trim():r)}return l.join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Xe=(t,r,i,s)=>a(void 0,void 0,void 0,(function*(){var a,n;const o=null!==(n=null===(a=s.options)||void 0===a?void 0:a.data)&&void 0!==n?n:{},l=t.replace(/{{(.+)}}/,"$1"),u=yield B(e(r,l,e(o,l,"")),s);if("number"!=typeof u)return u;if(!(l in i))return u;const d=i[l];if(u in d)return d[u].replace("{}",String(u));const c=Object.keys(i[l]),p=c.find((e=>e.startsWith(">")));if(p){if(u>Number(p.slice(1)))return null==d?void 0:d[p]}const h=c.find((e=>e.startsWith("<")));if(h){if(u<Number(h.slice(1)))return null==d?void 0:d[h]}return d.other?d.other.replace("{}",String(u)):u})),Ze=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Ke=k(Ze),et={description:"Count elements in an array",aliases:["count","length"],parameters:Ze},tt={propertyAliases:Ke,operatorData:et,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);return t.typeChecker(R(et.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},rt=[{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}],at=k(rt),it={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:rt},st=" ",nt={propertyAliases:at,operatorData:it,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield G([e.value,null!==(r=e.delimiter)&&void 0!==r?r:st,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(R(it.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=st]=e.children;return Object.assign(Object.assign({},e),{value:t,delimiter:r})}},ot=[{name:"query",description:"SQL query string, with parameterised replacements (e.g. $1, $2, etc)",aliases:["text"],required:!0,type:"string"},{name:"values",description:"An array/object of values to replace the SQL string parameters, as per SQL connection specifications ",aliases:["replacements"],required:!1,type:["array","object"]},{name:"single",description:"Specify if returning a single record",aliases:["singleRecord"],required:!1,type:"boolean"},{name:"flatten",description:"Specify whether to flatten resulting record objects to arrays of values",aliases:["flat","array"],required:!1,type:"boolean"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],lt=k(ot),ut={description:"Query an SQL database",aliases:["sql","pgSql","postgres","pg","sqLite","sqlite","mySql"],parameters:ot},dt={propertyAliases:lt,operatorData:ut,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){var r,i,s;const n=null===(r=t.options)||void 0===r?void 0:r.sqlConnection;if(!n)throw new Error("No SQL database connection provided");const[o,l,u,d,c,p]=yield G([e.query,e.values||[],e.single,e.flatten,e.useCache,e.type],t);t.typeChecker(R(ut.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(s=null!==(i=e.useCache)&&void 0!==i?i:t.options.useCache)||void 0===s||s;{const e=t.cache.useCache(h,((e,t,r,i,s)=>a(void 0,void 0,void 0,(function*(){const a=(yield n.query({query:e,values:t}))||[];["array","string","number"].includes(null!=s?s:"")&&(i=!0);const o=i?a.map((e=>{const t=Object.values(e);return t.length<=1?t[0]:t})):a;return r?o[0]:o}))),o,l,u,d,p);return e}})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{query:t,values:r})}},ct=[{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}],pt=k(ct),ht={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:ct},vt={propertyAliases:pt,operatorData:ht,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){var r,i,s,n,o,l,u;const d=null!==(r=t.graphQLClient)&&void 0!==r?r:t.httpClient;if(!d)throw new Error("No HTTP client provided for GraphQL connection");const[c,p,h,v,y,f]=yield G([e.query,e.url,yield W(e.variables,t),e.returnNode,e.headers,e.useCache],t),{url:m,headers:g}=p instanceof Object?p:{url:p,headers:null};t.typeChecker([...R(ht.parameters,{url:m,query:c,variables:h,returnNode:v,headers:y,useCache:f}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=m&&"graphqlendpoint"!==m.toLowerCase()?m:"",T=null!==(n=null!==(s=null===(i=t.options.graphQLConnection)||void 0===i?void 0:i.endpoint)&&void 0!==s?s:t.options.baseEndpoint)&&void 0!==n?n:"",O=M(b)?b:$(T,b),C={query:c,variables:h},j=null===(o=null!=f?f:t.options.useCache)||void 0===o||o,q=yield t.cache.useCache(j,((e,t,r,i)=>a(void 0,void 0,void 0,(function*(){const a=yield F(d,{url:e,method:"post",data:t,headers:r});return H(null==a?void 0:a.data,i)}))),O,C,Object.assign(Object.assign(Object.assign(Object.assign({},null===(l=t.options.graphQLConnection)||void 0===l?void 0:l.headers),null===(u=t.options)||void 0===u?void 0:u.headers),g),y),v);return q})),parseChildren:(e,t)=>a(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield G(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=D(n,o),u=Object.assign(Object.assign({},e),{query:r,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},yt=[{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}],ft=k(yt),mt={description:"HTTP GET Request",aliases:["get","api"],parameters:yt},gt=(e,t)=>a(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield G(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=D(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),bt=gt,Tt={propertyAliases:ft,operatorData:mt,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){var r,i,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield G([e.url,yield W(e.parameters,t),e.returnProperty,yield W(e.headers,t),e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...R(mt.parameters,{url:p,returnProperty:u,headers:d,parameters:l,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",y=Object.assign(Object.assign(Object.assign({},null===(i=t.options)||void 0===i?void 0:i.headers),h),d),f=null===(s=null!=c?c:t.options.useCache)||void 0===s||s,m=yield t.cache.useCache(f,((e,t,r,i)=>a(void 0,void 0,void 0,(function*(){const a=yield F(n,{url:e,params:t,headers:r});return H(a,i)}))),M(p)?p:$(v,p),l,y,u);return m})),parseChildren:gt},Ot=[{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}],Ct=k(Ot),jt={description:"HTTP POST Request",aliases:["post"],parameters:Ot},qt={propertyAliases:Ct,operatorData:jt,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){var r,i,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield G([e.url,yield W(e.parameters,t),e.returnProperty,yield W(e.headers,t),e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...R(jt.parameters,{url:p,headers:d,data:l,returnProperty:u,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(r=t.options.baseEndpoint)&&void 0!==r?r:"",y=Object.assign(Object.assign(Object.assign({},null===(i=t.options)||void 0===i?void 0:i.headers),h),d),f=null!==(s=null!=c?c:t.options.useCache)&&void 0!==s&&s,m=yield t.cache.useCache(f,((e,t,r,i)=>a(void 0,void 0,void 0,(function*(){const a=yield F(n,{url:e,data:t,headers:r,method:"post"});return H(a,i)}))),M(p)?p:$(v,p),l,y,u);return m})),parseChildren:bt},Et=[{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"]}],St=k(Et),At={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:Et},wt={propertyAliases:St,operatorData:At,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){t.typeChecker(R(At.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 i=[e,r],a(void 0,void 0,void 0,(function*(){const[e,r]=yield G(i,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var i}));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"]}],xt={propertyAliases:k(Nt),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Nt},evaluate:(e,t)=>a(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 s=Array.isArray(e.branches)?_(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=i(s)?yield B(s,t):s;if(!g(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)=>a(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=_(yield G(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},Pt=[{name:"functionName",description:"Path (in options.functions) to the required function",aliases:["functionPath","funcName","function","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:["array","any"],default:[]},{name:"input",description:"Argument for the function if a single input parameter",aliases:["arg"],required:!1,type:"any",default:"input"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],Lt=k(Pt),It={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:Pt},Ut={propertyAliases:Lt,operatorData:It,evaluate:(t,r)=>a(void 0,void 0,void 0,(function*(){var i,s,n,o;const[l,u=[],d,c]=yield G([t.functionName,t.args,t.input,t.useCache],r);r.typeChecker(R(It.parameters,{functionName:l,args:u}));const{data:p,functions:h}=r.options;if(!h)throw new Error("- No functions defined");const v=null!==(n=null!==(s=null!==(i=e(h,`${l}.function`,null))&&void 0!==i?i:e(h,l,null))&&void 0!==s?s:e(p,l,null))&&void 0!==n?n:e(r.options,l,null);if(!v||"function"!=typeof v)throw new Error(`- No function found: "${l}"`);const y=null!==(o=null!=c?c:r.options.useCache)&&void 0!==o&&o,f=[...void 0===d?[]:[yield W(d,r)],...Array.isArray(u)?u:[u]];return yield r.cache.useCache(y,((e,...t)=>a(void 0,void 0,void 0,(function*(){return yield v(...t)}))),l,...f)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionName:t,args:r})}},kt=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Rt=k(kt),Dt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:kt},_t={propertyAliases:Rt,operatorData:Dt,evaluate:(e,t)=>a(void 0,void 0,void 0,(function*(){return t.typeChecker(R(Dt.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 Qt=Object.freeze({__proto__:null,AND:Z,BUILD_OBJECT:wt,CONDITIONAL:_e,COUNT:tt,CUSTOM_FUNCTIONS:Ut,DIVIDE:Se,EQUAL:ne,GET:Tt,GRAPHQL:vt,GREATER_THAN:xe,LESS_THAN:Ue,MATCH:xt,MULTIPLY:Ce,NOT_EQUAL:de,OBJECT_PROPERTIES:ze,OR:re,PASSTHRU:_t,PLUS:ve,POST:qt,REGEX:$e,SPLIT:nt,SQL:dt,STRING_SUBSTITUTION:Ye,SUBTRACT:ge});class Ht{constructor(e){var t,r;this.useCache=(e,t,...r)=>a(this,void 0,void 0,(function*(){if(!e)return yield t(...r);const a=Mt(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 Mt=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),$t=e=>e?"name"in e&&"fetch"===e.name?Bt(e):"Axios"in e&&"Axios"===e.Axios.name?Ft(e):e:"undefined"!=typeof window&&"document"in window&&"fetch"in window?Bt(window.fetch):void 0,Ft=e=>({get:t=>a(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"get"}))).data})),post:t=>a(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"post"}))).data})),throwError:t=>{var r,a,i,s;if(e.isAxiosError(t)&&t.response)throw t.errorData={status:null===(r=t.response)||void 0===r?void 0:r.status,error:null===(a=t.response)||void 0===a?void 0:a.statusText,url:null===(i=t.config)||void 0===i?void 0:i.url,response:null===(s=t.response)||void 0===s?void 0:s.data},t;throw new Error("Network error: "+(null==t?void 0:t.message))}}),Bt=e=>({get:t=>a(void 0,void 0,void 0,(function*(){const{url:a,headers:i,params:s={}}=t,n=Object.keys(s).length>0?`?${r.stringify(s)}`:"",o=yield e(a+n,{headers:i,method:"GET"}),l=yield o.json();if(!o.ok){const e=new Error("Problem with GET request");throw e.name="FetchError",e.errorData={status:o.status,error:o.statusText,url:o.url,response:l},console.log(e.errorData),e}return l})),post:t=>a(void 0,void 0,void 0,(function*(){const{url:r,headers:a,params:i,data:s}=t,n=new URLSearchParams(i),o=n.size>0?`?${n.toString()}`:"",l=yield e(r+o,{headers:a,body:JSON.stringify(s),method:"POST"}),u=yield l.json();if(!l.ok){const e=new Error("Problem with POST request");throw e.name="FetchError",e.errorData={status:l.status,error:l.statusText,url:l.url,response:u},console.log(e.errorData),e}return u})),throwError:e=>{throw e}});class Gt{constructor(e={}){var t,r,a;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=P(...t);if(!0===r)return;const a=new Error(r);throw a.name="Type Error",a},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.17.0",this.options=Wt(e),this.operators=l(Qt,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],b),this.operatorAliases=b,this.cache=new Ht({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime}),this.graphQLClient=$t(null===(a=e.graphQLConnection)||void 0===a?void 0:a.httpClient),this.httpClient=$t(e.httpClient)}evaluate(e,t={}){var r;return a(this,void 0,void 0,(function*(){const a=v(this.options,Wt(t),!0);return t.httpClient&&(this.httpClient=$t(t.httpClient)),(null===(r=t.graphQLConnection)||void 0===r?void 0:r.httpClient)&&(this.graphQLClient=$t(t.graphQLConnection.httpClient)),a.maxCacheSize&&a.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(a.maxCacheSize),a.maxCacheTime&&a.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(a.maxCacheTime),yield B(e,{options:a,operators:t.excludeOperators?l(Qt,t.excludeOperators,b):this.operators,operatorAliases:this.operatorAliases,typeChecker:a.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient})}))}getOptions(){return this.options}updateOptions(e){this.options=v(this.options,Wt(e),!1),this.options.excludeOperators&&(this.operators=l(Qt,this.options.excludeOperators,b))}getOperators(){const e=this.options.excludeOperators?l(Qt,this.options.excludeOperators,b):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(b))];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])=>{const r="function"==typeof t?t:null==t?void 0:t.function,a={name:e,numRequiredArgs:null==r?void 0:r.length};if("function"!=typeof t){const{description:e,argsDefault:r,inputDefault:i,textColor:s,backgroundColor:n}=t;return e&&(a.description=e),r&&(a.argsDefault=r),i&&(a.inputDefault=i),s&&(a.textColor=s),n&&(a.backgroundColor=n),a}return a}))}}const zt=(e,t)=>new Gt(t).evaluate(e),Wt=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e,Jt=e=>({query:({query:t,values:r=[]})=>a(void 0,void 0,void 0,(function*(){const a={text:t,values:null!=r?r:[]};try{const t=yield e.query(a);if(null==t?void 0:t.error)throw new Error(t.error);return t.rows}catch(e){throw e.name="Node-Postgres error",e}}))}),Vt=e=>({query:({query:t,values:r=[]})=>a(void 0,void 0,void 0,(function*(){try{return yield e.all(t,r)}catch(e){throw e.name="SQLite error",e}}))});export{Ft as AxiosClient,Bt as FetchClient,S as FigTreeError,Gt as FigTreeEvaluator,Jt as SQLNodePostgres,Vt as SQLite,zt as evaluateExpression,c as isAliasString,A as isFigTreeError,s as isFragmentNode,g as isObject,i as isOperatorNode,C as preProcessShorthand,n as standardiseOperatorName,u as truncateString};
1
+ import e from"object-property-extractor";import{dequal as t}from"dequal/lite";function r(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 a=e=>e instanceof Object&&"operator"in e,i=e=>e instanceof Object&&"fragment"in e,s=e=>{const t=f(e);return t||e},n=(e,t)=>t[s(e)],o=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[s(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[s(e)]]})),a},l=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,u=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},d=e=>/^\$.+/.test(e),c=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&d(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},p=(e,t)=>r(void 0,void 0,void 0,(function*(){var r,a;if(!(e.operator in(null!==(a=null===(r=t.options)||void 0===r?void 0:r.functions)&&void 0!==a?a:{})))return e;const{operator:i,fallback:s,outputType:n,type:o,useCache:l,input:u,args:d}=e,c=function(e,t){var r={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)t.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(r[a[i]]=e[a[i]])}return r}(e,["operator","fallback","outputType","type","useCache","input","args"]),p={operator:"CUSTOM_FUNCTIONS",function:i};return void 0!==s&&(p.fallback=s),void 0!==n&&(p.outputType=n),void 0!==o&&(p.type=o),void 0!==l&&(p.useCache=l),void 0!==d&&(p.args=d),void 0!==u?p.input=u:Object.keys(c).length>0&&(p.input=c),p})),h=(e,t,r)=>{const a=Object.assign(Object.assign({},e),t);return r?((e.data||t.data)&&(a.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(a.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(a.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(a.headers=Object.assign(Object.assign({},e.headers),t.headers)),a):a},v={number:e=>y(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},y=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},f=e=>e.replace(/[^A-Za-z\d _-]/g,"").split(/[-_ ]/).map((e=>{var t;return null!==(t=e.match(/[a-z]+|[A-Z]+[a-z]*/g))&&void 0!==t?t:e})).flat().filter((e=>""!==e)).map(((e,t)=>0===t?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""),m=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),g=e=>a(e)||i(e)||"string"==typeof e&&d(e)||m(e)&&1===Object.keys(e).length&&d(Object.keys(e)[0]),b={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",sql:"SQL",pgSql:"SQL",postgres:"SQL",pg:"SQL",sqLite:"SQL",sqlite:"SQL",mySql:"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"},T=b,O=/(\$[^()]+)\((.*)\)/,C=(e,t={},r,a=!0)=>a?"string"==typeof e?j(e,t,r):m(e)?S(e,t,r):e:e,j=(e,t,r)=>{const a=O.exec(e);if(!a)return e;const i=a[1].trim(),s=a[2].split(",").map((e=>C(e.trim(),t,r)));return E(i,s,t,r)},S=(e,t,r)=>{if(a(e)||i(e))return e;const s=Object.entries(e),n=s.filter((([e])=>d(e))),o=s.filter((([e])=>!d(e))),l=n.reduce(((e,[a,i])=>e=Object.assign(Object.assign({},e),E(a,i,t,r))),{});return Object.assign(Object.assign({},l),Object.fromEntries(o))},E=(e,t,r,a)=>{const i=e.slice(1),s=n(i,T);return s?Array.isArray(t)?{operator:s,children:t}:m(t)&&!Object.keys(t).some((e=>d(e)))?Object.assign({operator:s},t):{operator:s,children:[t]}:i in r?{fragment:i,parameters:Object.assign({},t)}:a.includes(i)?Array.isArray(t)?{operator:i,args:t}:m(t)?"input"in t||"args"in t?Object.assign({operator:i},t):{operator:i,input:t}:{operator:i,args:[t]}:{[e]:t}};class q extends Error{constructor(e,t,r,a){super(e.message),Object.assign(this,e),this.operator=t,this.expression=a,this.errorData=e.errorData,r&&(this.name=r),"Error"===this.name&&(this.name="FigTreeError");const i=(t?"Operator: "+t:"")+("FigTreeError"===this.name?"":` - ${this.name}`),s=this.errorData?"\n"+JSON.stringify(this.errorData,null,2):"";this.prettyPrint=`${""!==i?i+"\n":""}${this.message}${"\n{}"===s?"":s}`}}const A=e=>e instanceof q,w=({fallback:e,operator:t,name:r,error:a,expression:i,returnErrorAsString:s=!1})=>{if(void 0!==e)return e;if(a instanceof q){if(!s)throw a;return a.prettyPrint}const n=new q("string"==typeof a?new Error(a):a,t,r,i);if(s)return n.prettyPrint;throw n},N=e=>m(e)&&"literal"in e,P=({value:e,name:t,expectedType:r})=>{if(N(r)){const{literal:a}=r;return!!a.includes(e)||I(t,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(r))return!!r.some((r=>!0===P({value:e,name:t,expectedType:r})))||I(t,e,r.join("|"));return!!(0,L[r])(e)||I(t,e,r)},x=(...e)=>{const t=[];return e.forEach((e=>{const r=P(e);!0!==r&&t.push(r)})),!(t.length>0)||t.join("\n")},L={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=>m(e),undefined:e=>void 0===e},I=(e,t,r)=>void 0===t&&e?`- Missing required property "${e}" (type: ${r})`:void 0!==e?`- Property "${e}" (value: ${k(t)}) is not of type: ${r}`:`- ${k(t)} is not of type: ${r}`,k=e=>{const t=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return l(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(N(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}})),D=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},_=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=x(...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},Q=e=>m(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,H=(t,r,a=void 0)=>{const i=r?e(t,r,a):t;return Array.isArray(i)?i.map((e=>Q(e))):r?null===i?null:Q(i):i},M=e=>/^https?:\/\/.+/.test(e),$=(...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}),""),F=(e,t)=>r(void 0,void 0,void 0,(function*(){const{url:r,params:a={},data:i={},headers:s={},method:n="get"}=t;if(!r||""===r)throw new Error("Invalid url");try{return yield e[n]({url:r,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:a,data:i})}catch(t){e.throwError(t)}})),B=(e,t)=>r(void 0,void 0,void 0,(function*(){var r,s,o,l,d,h;const{options:y,operators:f,operatorAliases:g}=t;let b=(null==y?void 0:y.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return a(t)?t:e}catch(t){return e}})(e):e;const T=Object.keys(null!==(s=null===(r=t.options)||void 0===r?void 0:r.functions)&&void 0!==s?s:{});b=C(b,null===(o=t.options)||void 0===o?void 0:o.fragments,T,!y.noShorthand),Array.isArray(b)&&(b=yield G(b,t));const O=a(b),j=i(b);if(O&&(b=yield p(b,t)),y.evaluateFullObject&&!O&&!j)return c(yield W(b,t),t);if(!O&&!j)return y.supportDeprecatedValueNodes&&m(b)&&"value"in b?b.value:c(b,t);const{fallback:S}=b,E=null!==(l=null==y?void 0:y.returnErrorAsString)&&void 0!==l&&l;if(j){const e=b,[r,i]=yield G([e.fragment,e.parameters],t),s=C(null===(d=null==y?void 0:y.fragments)||void 0===d?void 0:d[r],y.fragments,T,!y.noShorthand);if(void 0===s)return w({fallback:yield B(S,t),error:`Fragment not defined: ${r}`,expression:b,returnErrorAsString:E});if(!a(s))return c(s,t);b=Object.assign(Object.assign(Object.assign({},e),s),i),delete b.fragment}const q=b,A=n(q.operator,g);if(!A)return w({fallback:yield B(S,t),error:`Invalid operator: ${q.operator}`,expression:b,returnErrorAsString:E});if(!t.operators[A])return w({fallback:yield B(S,t),error:`Excluded operator: ${q.operator}`,expression:b,returnErrorAsString:E});const{propertyAliases:N,evaluate:P,parseChildren:x}=f[A];let L=((e,t)=>u(t,(t=>t in e?e[t]:t)))(N,q);const I=yield z(L,t);j||Object.entries(I).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const k=j?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),I)}):t;if("children"in L){if(Array.isArray(L.children)||(L.children=yield B(L.children,k)),!Array.isArray(L.children))return w({fallback:yield B(S,t),operator:A,name:"Type Error",error:'- Property "children" is not of type: array',expression:b,returnErrorAsString:E});L=yield x(L,k),delete L.children}let U;try{U=yield P(L,k)}catch(e){return w({fallback:yield B(L.fallback,t),operator:A,error:e,expression:L,returnErrorAsString:E})}const R=null!==(h=null==L?void 0:L.outputType)&&void 0!==h?h:null==L?void 0:L.type;if(!R)return U;const D=yield B(R,t);return D in v?v[D](U):w({fallback:yield B(S,t),operator:A,error:`- Invalid output type: ${D}`,expression:L,returnErrorAsString:E})})),G=(e,t)=>r(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>B(e,t)))):yield B(e,t)})),z=(e,t)=>r(void 0,void 0,void 0,(function*(){var r;const a=Object.keys(e).filter(d);if(0===a.length)return{};const i=[];a.forEach((r=>i.push(B(e[r],t))));const s=yield Promise.all(i),n=D(a,yield Promise.all(i));for(const[e,t]of s.entries())"string"==typeof t&&d(t)&&(n[a[e]]=null!==(r=null==n?void 0:n[t])&&void 0!==r?r:t);return n})),W=(e,t)=>r(void 0,void 0,void 0,(function*(){if(!m(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{d(r)&&(a.push(r,B(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),_(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,B(a,t))}));const s=yield Promise.all(r);return c(_(s),t)})),J=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],V=U(J),Y={description:"Logical AND",aliases:["and","&","&&"],parameters:J},X=e=>{const t=e.children;return Object.assign(Object.assign({},e),{values:t})},Z={propertyAliases:V,operatorData:Y,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);return t.typeChecker(R(Y.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:X},K=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],ee=U(K),te={description:"Logical OR",aliases:["or","|","||"],parameters:K},re={propertyAliases:ee,operatorData:te,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);return t.typeChecker(R(te.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:X},ae=[{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}],ie=U(ae),se={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:ae},ne={propertyAliases:ie,operatorData:se,evaluate:(e,a)=>r(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield G([e.values,e.caseInsensitive,e.nullEqualsUndefined],a);a.typeChecker(R(se.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=a.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=a.options)||void 0===s?void 0:s.nullEqualsUndefined)&&a.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>t(e,u[0]))):u.every((e=>null==e))})),parseChildren:X},oe=[{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}],le=U(oe),ue={description:"Test if any values are different",aliases:["!=","!","ne","notEqual"],parameters:oe},de={propertyAliases:le,operatorData:ue,evaluate:(e,a)=>r(void 0,void 0,void 0,(function*(){var r,i,s;const[n,o,l]=yield G([e.values,e.caseInsensitive,e.nullEqualsUndefined],a);a.typeChecker(R(ue.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(r=a.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=a.options)||void 0===s?void 0:s.nullEqualsUndefined)&&a.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!t(e,u[0]))):u.some((e=>null===e&&void 0===e))})),parseChildren:X},ce=[{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"}],pe=U(ce),he={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ce},ve={propertyAliases:pe,operatorData:he,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);return t.typeChecker(R(he.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=>m(e)))?r.reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{}):r.reduce(((e,t)=>e+t))})),parseChildren:X},ye=[{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}],fe=U(ye),me={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:ye},ge={propertyAliases:fe,operatorData:me,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a,i]=yield G([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:X},be=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],Te=U(be),Oe={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:be},Ce={propertyAliases:Te,operatorData:Oe,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);if(t.typeChecker(R(Oe.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:X},je=[{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"}],Se=U(je),Ee={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:je},qe={propertyAliases:Se,operatorData:Ee,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield G([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(R(Ee.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:X},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}],we=U(Ae),Ne={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Ae},Pe={propertyAliases:we,operatorData:Ne,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield G([e.values,e.strict],t);if(t.typeChecker(R(Ne.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:X},xe=[{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}],Le=U(xe),Ie={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:xe},ke={propertyAliases:Le,operatorData:Ie,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield G([e.values,e.strict],t);if(t.typeChecker(R(Ie.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:X},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),De={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ue},_e={propertyAliases:Re,operatorData:De,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){t.typeChecker(R(De.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})}},Qe=[{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}$"}],He=U(Qe),Me={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:Qe},$e={propertyAliases:He,operatorData:Me,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a]=yield G([e.testString,e.pattern],t);t.typeChecker(R(Me.parameters,{testString:r,pattern:a}));return new RegExp(a).test(r)})),parseChildren:e=>{const[t,r]=e.children;return Object.assign(Object.assign({},e),{testString:t,pattern:r})}},Fe=[{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(Fe),Ge={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:Fe},ze={propertyAliases:Be,operatorData:Ge,evaluate:(t,a)=>r(void 0,void 0,void 0,(function*(){var r,i;const[s,n={}]=yield G([t.property,t.additionalData],a);a.typeChecker(R(Ge.parameters,{property:s,additionalData:n}));const o=Object.assign(Object.assign({},null!==(i=null===(r=a.options)||void 0===r?void 0:r.data)&&void 0!==i?i:{}),n);return e(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}},We=[{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:{}},{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:{}}],Je=U(We),Ve={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:We},Ye={propertyAliases:Je,operatorData:Ve,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a={},i=!0,s="%",n={}]=yield G([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(R(Ve.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=D(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)}const o=/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g,l=[];for(const e of r.split(o)){if(!/(?<!\\){{(.+)}}/.exec(e)){l.push(e.replace("\\{{","{{"));continue}const r=yield Xe(e,a,n,t);l.push(i?String(r).trim():r)}return l.join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Xe=(t,a,i,s)=>r(void 0,void 0,void 0,(function*(){var r,n;const o=null!==(n=null===(r=s.options)||void 0===r?void 0:r.data)&&void 0!==n?n:{},l=t.replace(/{{(.+)}}/,"$1"),u=yield B(e(a,l,e(o,l,"")),s);if("number"!=typeof u)return u;if(!(l in i))return u;const d=i[l];if(u in d)return d[u].replace("{}",String(u));const c=Object.keys(i[l]),p=c.find((e=>e.startsWith(">")));if(p){if(u>Number(p.slice(1)))return null==d?void 0:d[p]}const h=c.find((e=>e.startsWith("<")));if(h){if(u<Number(h.slice(1)))return null==d?void 0:d[h]}return d.other?d.other.replace("{}",String(u)):u})),Ze=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Ke=U(Ze),et={description:"Count elements in an array",aliases:["count","length"],parameters:Ze},tt={propertyAliases:Ke,operatorData:et,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){const r=yield G(e.values,t);return t.typeChecker(R(et.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},rt=[{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}],at=U(rt),it={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:rt},st=" ",nt={propertyAliases:at,operatorData:it,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield G([e.value,null!==(r=e.delimiter)&&void 0!==r?r:st,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(R(it.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=st]=e.children;return Object.assign(Object.assign({},e),{value:t,delimiter:r})}},ot=[{name:"query",description:"SQL query string, with parameterised replacements (e.g. $1, $2, etc)",aliases:["text"],required:!0,type:"string"},{name:"values",description:"An array/object of values to replace the SQL string parameters, as per SQL connection specifications ",aliases:["replacements"],required:!1,type:["array","object"]},{name:"single",description:"Specify if returning a single record",aliases:["singleRecord"],required:!1,type:"boolean"},{name:"flatten",description:"Specify whether to flatten resulting record objects to arrays of values",aliases:["flat","array"],required:!1,type:"boolean"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean"}],lt=U(ot),ut={description:"Query an SQL database",aliases:["sql","pgSql","postgres","pg","sqLite","sqlite","mySql"],parameters:ot},dt={propertyAliases:lt,operatorData:ut,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var a,i,s;const n=null===(a=t.options)||void 0===a?void 0:a.sqlConnection;if(!n)throw new Error("No SQL database connection provided");const[o,l,u,d,c,p]=yield G([e.query,e.values||[],e.single,e.flatten,e.useCache,e.type],t);t.typeChecker(R(ut.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(s=null!==(i=e.useCache)&&void 0!==i?i:t.options.useCache)||void 0===s||s;{const e=t.cache.useCache(h,((e,t,a,i,s)=>r(void 0,void 0,void 0,(function*(){const r=(yield n.query({query:e,values:t}))||[];["array","string","number"].includes(null!=s?s:"")&&(i=!0);const o=i?r.map((e=>{const t=Object.values(e);return t.length<=1?t[0]:t})):r;return a?o[0]:o}))),o,l,u,d,p);return e}})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{query:t,values:r})}},ct=[{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}],pt=U(ct),ht={description:"GraphQL request",aliases:["graphQl","graphql","gql"],parameters:ct},vt={propertyAliases:pt,operatorData:ht,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var a,i,s,n,o,l,u;const d=null!==(a=t.graphQLClient)&&void 0!==a?a:t.httpClient;if(!d)throw new Error("No HTTP client provided for GraphQL connection");const[c,p,h,v,y,f]=yield G([e.query,e.url,yield W(e.variables,t),e.returnNode,e.headers,e.useCache],t),{url:m,headers:g}=p instanceof Object?p:{url:p,headers:null};t.typeChecker([...R(ht.parameters,{url:m,query:c,variables:h,returnNode:v,headers:y,useCache:f}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=m&&"graphqlendpoint"!==m.toLowerCase()?m:"",T=null!==(n=null!==(s=null===(i=t.options.graphQLConnection)||void 0===i?void 0:i.endpoint)&&void 0!==s?s:t.options.baseEndpoint)&&void 0!==n?n:"",O=M(b)?b:$(T,b),C={query:c,variables:h},j=null===(o=null!=f?f:t.options.useCache)||void 0===o||o,S=yield t.cache.useCache(j,((e,t,a,i)=>r(void 0,void 0,void 0,(function*(){const r=yield F(d,{url:e,method:"post",data:t,headers:a});return H(null==r?void 0:r.data,i)}))),O,C,Object.assign(Object.assign(Object.assign(Object.assign({},null===(l=t.options.graphQLConnection)||void 0===l?void 0:l.headers),null===(u=t.options)||void 0===u?void 0:u.headers),g),y),v);return S})),parseChildren:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield G(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=D(n,o),u=Object.assign(Object.assign({},e),{query:r,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},yt=[{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}],ft=U(yt),mt={description:"HTTP GET Request",aliases:["get","api"],parameters:yt},gt=(e,t)=>r(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield G(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=D(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),bt=gt,Tt={propertyAliases:ft,operatorData:mt,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var a,i,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield G([e.url,yield W(e.parameters,t),e.returnProperty,yield W(e.headers,t),e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...R(mt.parameters,{url:p,returnProperty:u,headers:d,parameters:l,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(a=t.options.baseEndpoint)&&void 0!==a?a:"",y=Object.assign(Object.assign(Object.assign({},null===(i=t.options)||void 0===i?void 0:i.headers),h),d),f=null===(s=null!=c?c:t.options.useCache)||void 0===s||s,m=yield t.cache.useCache(f,((e,t,a,i)=>r(void 0,void 0,void 0,(function*(){const r=yield F(n,{url:e,params:t,headers:a});return H(r,i)}))),M(p)?p:$(v,p),l,y,u);return m})),parseChildren:gt},Ot=[{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}],Ct=U(Ot),jt={description:"HTTP POST Request",aliases:["post"],parameters:Ot},St={propertyAliases:Ct,operatorData:jt,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){var a,i,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield G([e.url,yield W(e.parameters,t),e.returnProperty,yield W(e.headers,t),e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...R(jt.parameters,{url:p,headers:d,data:l,returnProperty:u,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(a=t.options.baseEndpoint)&&void 0!==a?a:"",y=Object.assign(Object.assign(Object.assign({},null===(i=t.options)||void 0===i?void 0:i.headers),h),d),f=null!==(s=null!=c?c:t.options.useCache)&&void 0!==s&&s,m=yield t.cache.useCache(f,((e,t,a,i)=>r(void 0,void 0,void 0,(function*(){const r=yield F(n,{url:e,data:t,headers:a,method:"post"});return H(r,i)}))),M(p)?p:$(v,p),l,y,u);return m})),parseChildren:bt},Et=[{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"]}],qt=U(Et),At={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:Et},wt={propertyAliases:qt,operatorData:At,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){t.typeChecker(R(At.parameters,{properties:e.properties}));const a=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:a})=>{return i=[e,a],r(void 0,void 0,void 0,(function*(){const[e,r]=yield G(i,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var i}));return Object.fromEntries(yield Promise.all(a))})),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)=>r(void 0,void 0,void 0,(function*(){var r;const i=yield B(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:i,expectedType:["string","number","boolean"]});const s=Array.isArray(e.branches)?_(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=a(s)?yield B(s,t):s;if(!m(n))throw new Error("Branches don't evaluate to an object");if(i in n)return yield B(n[i],t);if("fallback"in n)return yield B(n.fallback,t);if(i in e)return yield B(e[i],t);throw new Error(`No match found for ${i}`)})),parseChildren:(e,t)=>r(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=_(yield G(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},xt=[{name:"functionName",description:"Path (in options.functions) to the required function",aliases:["functionPath","funcName","function","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:["array","any"],default:[]},{name:"input",description:"Argument for the function if a single input parameter",aliases:["arg"],required:!1,type:"any",default:"input"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],Lt=U(xt),It={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:xt},kt={propertyAliases:Lt,operatorData:It,evaluate:(t,a)=>r(void 0,void 0,void 0,(function*(){var i,s,n,o;const[l,u=[],d,c]=yield G([t.functionName,t.args,t.input,t.useCache],a);a.typeChecker(R(It.parameters,{functionName:l,args:u}));const{data:p,functions:h}=a.options;if(!h)throw new Error("- No functions defined");const v=null!==(n=null!==(s=null!==(i=e(h,`${l}.function`,null))&&void 0!==i?i:e(h,l,null))&&void 0!==s?s:e(p,l,null))&&void 0!==n?n:e(a.options,l,null);if(!v||"function"!=typeof v)throw new Error(`- No function found: "${l}"`);const y=null!==(o=null!=c?c:a.options.useCache)&&void 0!==o&&o,f=[...void 0===d?[]:[yield W(d,a)],...Array.isArray(u)?u:[u]];return yield a.cache.useCache(y,((e,...t)=>r(void 0,void 0,void 0,(function*(){return yield v(...t)}))),l,...f)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionName:t,args:r})}},Ut=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Rt=U(Ut),Dt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Ut},_t={propertyAliases:Rt,operatorData:Dt,evaluate:(e,t)=>r(void 0,void 0,void 0,(function*(){return t.typeChecker(R(Dt.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 Qt=Object.freeze({__proto__:null,AND:Z,BUILD_OBJECT:wt,CONDITIONAL:_e,COUNT:tt,CUSTOM_FUNCTIONS:kt,DIVIDE:qe,EQUAL:ne,GET:Tt,GRAPHQL:vt,GREATER_THAN:Pe,LESS_THAN:ke,MATCH:Pt,MULTIPLY:Ce,NOT_EQUAL:de,OBJECT_PROPERTIES:ze,OR:re,PASSTHRU:_t,PLUS:ve,POST:St,REGEX:$e,SPLIT:nt,SQL:dt,STRING_SUBSTITUTION:Ye,SUBTRACT:ge});class Ht{constructor(e){var t,a;this.useCache=(e,t,...a)=>r(this,void 0,void 0,(function*(){if(!e)return yield t(...a);const r=Mt(a),i=r in this.store,s=Date.now(),n=i&&s-this.store[r].timestamp>1e3*this.maxTime;if(i)return this.queue=this.queue.filter((e=>e!==r)),this.queue.unshift(r),this.store[r].timestamp=s,n&&(this.store[r].result=yield t(...a)),this.store[r].result;const o=yield t(...a);return this.store[r]={result:o,timestamp:s},this.queue.unshift(r),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!==(a=null==e?void 0:e.maxTime)&&void 0!==a?a:1800}}const Mt=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),$t=e=>e||("undefined"!=typeof window&&"document"in window&&"fetch"in window?Bt(window.fetch):void 0),Ft=e=>({get:t=>r(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"get"}))).data})),post:t=>r(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"post"}))).data})),throwError:t=>{var r,a,i,s;if(e.isAxiosError(t)&&t.response)throw t.errorData={status:null===(r=t.response)||void 0===r?void 0:r.status,error:null===(a=t.response)||void 0===a?void 0:a.statusText,url:null===(i=t.config)||void 0===i?void 0:i.url,response:null===(s=t.response)||void 0===s?void 0:s.data},t;throw new Error("Network error: "+(null==t?void 0:t.message))}}),Bt=e=>({get:t=>r(void 0,void 0,void 0,(function*(){const{url:r,headers:a,params:i={}}=t,s=Object.keys(i).length>0?`?${new URLSearchParams(i).toString()}`:"",n=yield e(r+s,{headers:a,method:"GET"}),o=yield n.json();if(!n.ok){const e=new Error("Problem with GET request");throw e.name="FetchError",e.errorData={status:n.status,error:n.statusText,url:n.url,response:o},console.log(e.errorData),e}return o})),post:t=>r(void 0,void 0,void 0,(function*(){const{url:r,headers:a,params:i,data:s}=t,n=new URLSearchParams(i),o=n.size>0?`?${n.toString()}`:"",l=yield e(r+o,{headers:a,body:JSON.stringify(s),method:"POST"}),u=yield l.json();if(!l.ok){const e=new Error("Problem with POST request");throw e.name="FetchError",e.errorData={status:l.status,error:l.statusText,url:l.url,response:u},console.log(e.errorData),e}return u})),throwError:e=>{throw e}});class Gt{constructor(e={}){var t,r,a;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=x(...t);if(!0===r)return;const a=new Error(r);throw a.name="Type Error",a},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.18.1",this.options=Wt(e),this.operators=o(Qt,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],b),this.operatorAliases=b,this.cache=new Ht({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime}),this.graphQLClient=$t(null===(a=e.graphQLConnection)||void 0===a?void 0:a.httpClient),this.httpClient=$t(e.httpClient)}evaluate(e,t={}){var a;return r(this,void 0,void 0,(function*(){const r=h(this.options,Wt(t),!0);return t.httpClient&&(this.httpClient=$t(t.httpClient)),(null===(a=t.graphQLConnection)||void 0===a?void 0:a.httpClient)&&(this.graphQLClient=$t(t.graphQLConnection.httpClient)),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?o(Qt,t.excludeOperators,b):this.operators,operatorAliases:this.operatorAliases,typeChecker:r.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient})}))}getOptions(){return this.options}updateOptions(e){this.options=h(this.options,Wt(e),!1),this.options.excludeOperators&&(this.operators=o(Qt,this.options.excludeOperators,b))}getOperators(){const e=this.options.excludeOperators?o(Qt,this.options.excludeOperators,b):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(b))];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])=>{const r="function"==typeof t?t:null==t?void 0:t.function,a={name:e,numRequiredArgs:null==r?void 0:r.length};if("function"!=typeof t){const{description:e,argsDefault:r,inputDefault:i,textColor:s,backgroundColor:n}=t;return e&&(a.description=e),r&&(a.argsDefault=r),i&&(a.inputDefault=i),s&&(a.textColor=s),n&&(a.backgroundColor=n),a}return a}))}}const zt=(e,t)=>new Gt(t).evaluate(e),Wt=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e,Jt=e=>({query:({query:t,values:a=[]})=>r(void 0,void 0,void 0,(function*(){const r={text:t,values:null!=a?a:[]};try{const t=yield e.query(r);if(null==t?void 0:t.error)throw new Error(t.error);return t.rows}catch(e){throw e.name="Node-Postgres error",e}}))}),Vt=e=>({query:({query:t,values:a=[]})=>r(void 0,void 0,void 0,(function*(){try{return yield e.all(t,a)}catch(e){throw e.name="SQLite error",e}}))});export{Ft as AxiosClient,Bt as FetchClient,q as FigTreeError,Gt as FigTreeEvaluator,Jt as SQLNodePostgres,Vt as SQLite,zt as evaluateExpression,d as isAliasString,A as isFigTreeError,g as isFigTreeExpression,i as isFragmentNode,m as isObject,a as isOperatorNode,C as preProcessShorthand,s as standardiseOperatorName,l as truncateString};
package/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "fig-tree-evaluator",
3
- "version": "2.17.0",
3
+ "version": "2.18.1",
4
4
  "description": "Module to evaluate JSON-structured expression trees",
5
5
  "main": "build/index.cjs.js",
6
6
  "module": "build/index.esm.js",
7
+ "sideEffects": false,
7
8
  "types": "build/index.d.ts",
9
+ "exports": {
10
+ "types": "./build/index.d.ts",
11
+ "import": "./build/index.esm.js",
12
+ "require": "./dist/index.cjs.js"
13
+ },
8
14
  "files": [
9
- "build/**/*"
15
+ "build"
10
16
  ],
11
17
  "repository": "git+https://github.com/CarlosNZ/fig-tree-evaluator.git",
12
18
  "author": "Carl Smith <5456533+CarlosNZ@users.noreply.github.com>",
@@ -24,12 +30,13 @@
24
30
  "axios": "^1.7.2",
25
31
  "dotenv": "^16.0.1",
26
32
  "eslint": "^8.53.0",
27
- "fig-tree-evaluator": "^2.16.10",
33
+ "fig-tree-evaluator": "^2.17.1",
28
34
  "jest": "^29.7.0",
29
35
  "node-fetch": "2.7.0",
30
36
  "pg": "^8.11.3",
31
37
  "prettier": "^3.0.3",
32
38
  "rimraf": "^5.0.5",
39
+ "rollup-plugin-bundle-size": "^1.0.3",
33
40
  "rollup-plugin-dts": "^6.0.2",
34
41
  "rollup-plugin-sizes": "^1.0.5",
35
42
  "rollup-plugin-terser": "^7.0.2",