fig-tree-evaluator 2.15.2 → 2.16.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 +76 -4
- package/build/index.cjs.js +1 -1
- package/build/index.d.ts +12 -1
- package/build/index.esm.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,7 @@ A range of built-in operators are available, from simple logic, arithmetic and s
|
|
|
53
53
|
- [Fragments](#fragments)
|
|
54
54
|
- [Shorthand syntax](#shorthand-syntax)
|
|
55
55
|
- [Caching (Memoization)](#caching-memoization)
|
|
56
|
+
- [Error handling](#error-handling)
|
|
56
57
|
- [Metadata](#metadata)
|
|
57
58
|
- [More examples](#more-examples)
|
|
58
59
|
- [Development environment](#development-environment)
|
|
@@ -156,7 +157,7 @@ The `options` parameter is an object with the following available properties (al
|
|
|
156
157
|
- `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.
|
|
157
158
|
- `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.
|
|
158
159
|
- `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.
|
|
159
|
-
- `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)
|
|
160
|
+
- `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.
|
|
160
161
|
- `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.
|
|
161
162
|
- `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`)
|
|
162
163
|
- `caseInsensitive` -- this only affects the [`equal`/`notEqual` operators](#equal) (see there for more detail).
|
|
@@ -226,7 +227,8 @@ Most of the time named properties would be preferable; however there are occasio
|
|
|
226
227
|
|
|
227
228
|
In each operator node, as well as the operator-specific properties, the following three optional properties can be provided:
|
|
228
229
|
|
|
229
|
-
- `fallback`: if the operation throws an error, the `fallback` value will be returned instead. The `fallback` property can be provided at any level of the expression tree and bubbled up from where errors are caught to parent nodes. *Fallbacks are strongly recommended if there is any chance of an error (e.g. a network "GET" request that doesn't yet have its parameters defined).*
|
|
230
|
+
- `fallback`: if the operation throws an error, the `fallback` value will be returned instead. The `fallback` property can be provided at any level of the expression tree and bubbled up from where errors are caught to parent nodes. *Fallbacks are strongly recommended if there is any chance of an error (e.g. a network "GET" request that doesn't yet have its parameters defined).*
|
|
231
|
+
See [Error handling](#error-handling)
|
|
230
232
|
- `outputType` (or `type`): will convert the result of the current node to the specified `outputType`. Valid values are `string`, `number`, `boolean` (or `bool`), and `array`. You can experiment in the [demo app](https://carlosnz.github.io/fig-tree-evaluator/) to see the outcome of applying different `outputType` values to various results.
|
|
231
233
|
- `useCache`: Overrides the global `useCache` value (from [options](#available-options)) for this node only. See [Caching/Memoization](#caching-memoization) below for more info.
|
|
232
234
|
|
|
@@ -1840,6 +1842,75 @@ fig.getCache() // returns key-value store
|
|
|
1840
1842
|
fig.setCache(cache) // where "cache" is the object retrieved by .getCache()
|
|
1841
1843
|
```
|
|
1842
1844
|
|
|
1845
|
+
## Error handling
|
|
1846
|
+
|
|
1847
|
+
By default, FigTree will throw errors that can be caught and handled by your application. The Error object is a `FigTreeError` type, which extends the standard `Error` object (with `name`, `message` and `stack` fields) with the following interface:
|
|
1848
|
+
|
|
1849
|
+
```ts
|
|
1850
|
+
interface FigTreeError extends Error {
|
|
1851
|
+
errorData?: Record<string, unknown>
|
|
1852
|
+
operator?: Operator
|
|
1853
|
+
expression?: EvaluatorNode
|
|
1854
|
+
prettyPrint: string // nicely formatted summary
|
|
1855
|
+
}
|
|
1856
|
+
```
|
|
1857
|
+
|
|
1858
|
+
There are two alternatives to throwing:
|
|
1859
|
+
|
|
1860
|
+
1. **Fallback**: If the `fallback` property is specified in the expression, this will be returned whenever an error occurs at that node (or below). See [Fallback option](#other-common-properties).
|
|
1861
|
+
2. **Formatted string**: By using the `returnErrorAsString: true` option, FigTree will return a nicely formatted string describing the error. *This is the same string returned in the `prettyPrint` property of the FigTreeError.* The formatted string will be structured like so:
|
|
1862
|
+
|
|
1863
|
+
```
|
|
1864
|
+
Operator: <OPERATOR_NAME>: - <error.name (if specific)>
|
|
1865
|
+
<error.message>
|
|
1866
|
+
{
|
|
1867
|
+
...errorData
|
|
1868
|
+
}
|
|
1869
|
+
```
|
|
1870
|
+
`errorData` is specific data returned by the error thrown by an internal process (such as a network request using [fetch](#http-requests)).
|
|
1871
|
+
|
|
1872
|
+
For example, a 403 (forbidden) error thrown by the `GET` operator (with Axios HTTP client) would return a string like:
|
|
1873
|
+
```
|
|
1874
|
+
Operator: GET - AxiosError
|
|
1875
|
+
Request failed with status code 403
|
|
1876
|
+
{
|
|
1877
|
+
"status": 403,
|
|
1878
|
+
"error": "Forbidden",
|
|
1879
|
+
"url": "http://httpstat.us/403",
|
|
1880
|
+
"response": {
|
|
1881
|
+
"success": false,
|
|
1882
|
+
"message": "jwt must be provided"
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
```
|
|
1886
|
+
|
|
1887
|
+
And, if thrown, the error object would contain:
|
|
1888
|
+
```js
|
|
1889
|
+
{
|
|
1890
|
+
name: "AxiosError",
|
|
1891
|
+
message: "Request failed with status code 403"
|
|
1892
|
+
operator: "GET",
|
|
1893
|
+
errorData: {
|
|
1894
|
+
status: 403,
|
|
1895
|
+
error: 'Forbidden',
|
|
1896
|
+
url: 'http://httpstat.us/403',
|
|
1897
|
+
response: {
|
|
1898
|
+
success: false,
|
|
1899
|
+
message: "jwt must be provided"
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
expression: {
|
|
1903
|
+
operator: 'API',
|
|
1904
|
+
url: 'http://httpstat.us/403',
|
|
1905
|
+
},
|
|
1906
|
+
prettyPrint: '[...the above formatted string...]'
|
|
1907
|
+
...otherProperties // all AxiosError and standard Error properties
|
|
1908
|
+
}
|
|
1909
|
+
```
|
|
1910
|
+
|
|
1911
|
+
It may seem that returning the error as a string results in the same output as catching the error and displaying `error.prettyPrint`. There is one key difference, however: if the error occurs deeper in the expression tree, a thrown error will be bubbled up immediately, whereas if it's returned as a string (or a fallback, for that matter), it'll be treated as any other string, which means it will be continued to be operated on as the expression is evaluated (you could concatenate multiple error strings together in this manner, for example).
|
|
1912
|
+
|
|
1913
|
+
If extending FigTree with additional [HTTP Client](#http-requests), [SQL Connection](#connecting-to-the-database) or [Custom functions](#custom_functions), you don't need to specifically throw a `FigTreeError` -- just throw a normal error and FigTree will encapsulate it into a FigTreeError object further upstream. (The one exception is for detailed `errorData`, if you want it -- attach this as a property to your error object before throwing it.) See the [included http clients](https://github.com/CarlosNZ/fig-tree-evaluator/blob/main/src/httpClients.ts) for an example.
|
|
1843
1914
|
|
|
1844
1915
|
## Metadata
|
|
1845
1916
|
|
|
@@ -1847,9 +1918,9 @@ Evaluator expressions can be configured by hand, with [aliases](#alias-nodes), [
|
|
|
1847
1918
|
|
|
1848
1919
|
However, you may wish to build an external UI for building FigTree expression. To this end, the FigTree instance provides three methods that could be useful for populating your configuration UI:
|
|
1849
1920
|
|
|
1850
|
-
####
|
|
1921
|
+
#### A new FigTree instance:
|
|
1851
1922
|
|
|
1852
|
-
|
|
1923
|
+
- containing fragments and [custom functions](#custom_functions).
|
|
1853
1924
|
|
|
1854
1925
|
```js
|
|
1855
1926
|
const fig = new FigTreeEvaluator({
|
|
@@ -1989,6 +2060,7 @@ Please open an issue: https://github.com/CarlosNZ/fig-tree-evaluator/issues
|
|
|
1989
2060
|
|
|
1990
2061
|
*Trivial upgrades (e.g. documentation, small re-factors, types, etc.) not included*
|
|
1991
2062
|
|
|
2063
|
+
- **v2.16.0**: Standardise error response (see [Error handling](#error-handling))
|
|
1992
2064
|
- **v2.15.0**:
|
|
1993
2065
|
- Remove `axios` package dependency and create HTTP client abstraction (with built-in wrappers for `axios` and `fetch`). *Results in significantly smaller bundle size.*
|
|
1994
2066
|
- Generalise `PG_SQL` operator to a client-agnostic `SQL` operator (with built-in abstractions for `node-postgres` and `SQLite`)
|
package/build/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("change-case"),t=require("object-property-extractor"),r=require("dequal/lite"),a=require("querystring");function i(e,t,r,a){return new(r||(r=Promise))((function(i,s){function n(e){try{l(a.next(e))}catch(e){s(e)}}function o(e){try{l(a.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=t=>{const r=e.camelCase(t);return r||t},l=(e,t)=>t[o(e)],u=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[o(e)]]})),a},d=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,c=(e,t,r=!1)=>{if(void 0!==e)return e;if(r)return d(t);throw new Error(d(t))},p=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&h(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},y=(e,t)=>{const r=Object.assign(Object.assign({},e),t);return(e.data||t.data)&&(r.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(r.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(r.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(r.headers=Object.assign(Object.assign({},e.headers),t.headers)),r},m={number:e=>g(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=e=>e.message,g=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const t=new RegExp(/-?\d*\.?\d+/gm),r=e.match(t);return r?Number(r[0]):0},b=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),T={and:"AND","&":"AND","&&":"AND",or:"OR","|":"OR","||":"OR","=":"EQUAL",eq:"EQUAL",equal:"EQUAL",equals:"EQUAL","!=":"NOT_EQUAL","!":"NOT_EQUAL",ne:"NOT_EQUAL",notEqual:"NOT_EQUAL","+":"PLUS",plus:"PLUS",add:"PLUS",concat:"PLUS",join:"PLUS",merge:"PLUS","-":"SUBTRACT",subtract:"SUBTRACT",minus:"SUBTRACT",takeaway:"SUBTRACT","*":"MULTIPLY",x:"MULTIPLY",multiply:"MULTIPLY",times:"MULTIPLY","/":"DIVIDE",divide:"DIVIDE","÷":"DIVIDE",">":"GREATER_THAN",greaterThan:"GREATER_THAN",higher:"GREATER_THAN",larger:"GREATER_THAN","<":"LESS_THAN",lessThan:"LESS_THAN",lower:"LESS_THAN",smaller:"LESS_THAN","?":"CONDITIONAL",conditional:"CONDITIONAL",ifThen:"CONDITIONAL",regex:"REGEX",patternMatch:"REGEX",regexp:"REGEX",matchPattern:"REGEX",dataProperties:"OBJECT_PROPERTIES",data:"OBJECT_PROPERTIES",getData:"OBJECT_PROPERTIES",objectProperties:"OBJECT_PROPERTIES",objProps:"OBJECT_PROPERTIES",getProperty:"OBJECT_PROPERTIES",getObjProp:"OBJECT_PROPERTIES",stringSubstitution:"STRING_SUBSTITUTION",substitute:"STRING_SUBSTITUTION",stringSub:"STRING_SUBSTITUTION",replace:"STRING_SUBSTITUTION",split:"SPLIT",arraySplit:"SPLIT",count:"COUNT",length:"COUNT",get:"GET",api:"GET",post:"POST",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"},O=T,C=/(\$[^()]+)\((.*)\)/,q=(e,t={},r=!0)=>r?"string"==typeof e?j(e,t):b(e)?S(e,t):e:e,j=(e,t)=>{const r=C.exec(e);if(!r)return e;const a=r[1].trim(),i=r[2].split(",").map((e=>q(e.trim(),t)));return E(a,i,t)},S=(e,t)=>{if(s(e)||n(e))return e;const r=Object.entries(e),a=r.filter((([e])=>h(e))),i=r.filter((([e])=>!h(e))),o=a.reduce(((e,[r,a])=>e=Object.assign(Object.assign({},e),E(r,a,t))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,t,r)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(t)?{operator:i,children:t}:b(t)&&!Object.keys(t).some((e=>h(e)))?Object.assign({operator:i},t):{operator:i,children:[t]}:a in r?{fragment:a,parameters:Object.assign({},t)}:{[e]:t}},A=e=>b(e)&&"literal"in e,w=({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===w({value:e,name:t,expectedType:r})))||P(t,e,r.join("|"));return!!(0,x[r])(e)||P(t,e,r)},N=(...e)=>{const t=[];return e.forEach((e=>{const r=w(e);!0!==r&&t.push(r)})),!(t.length>0)||t.join("\n")},x={any:e=>void 0!==e,string:e=>"string"==typeof e,number:e=>"number"==typeof e,boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),null:e=>null===e,object:e=>b(e),undefined:e=>void 0===e},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 d(t,50)},I=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},U=(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}})),R=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=e.filter(((e,t)=>t%2==0)),r=N(...t.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==r)throw new Error(r);const a=e.filter(((e,t)=>t%2==1)),i={};return t.forEach(((e,t)=>{i[e]=a[t]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,Q=(e,r,a=void 0)=>{const i=r?t(e,r,a):e;return Array.isArray(i)?i.map((e=>D(e))):r?null===i?null:D(i):i},_=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}),""),H=(e,t)=>i(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)=>i(void 0,void 0,void 0,(function*(){var r,a,i,o;const{options:u,operators:d,operatorAliases:h}=t;let y=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return s(t)?t:e}catch(t){return e}})(e):e;y=q(y,null===(r=t.options)||void 0===r?void 0:r.fragments,!u.noShorthand),Array.isArray(y)&&(y=yield F(y,t));const g=s(y),T=n(y);if(u.evaluateFullObject&&!g&&!T)return v(yield G(y,t),t);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(y)&&"value"in y?y.value:v(y,t);const{fallback:O}=y,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,r]=yield F([y.fragment,y.parameters],t),a=q(null===(i=null==u?void 0:u.fragments)||void 0===i?void 0:i[e],u.fragments,!u.noShorthand);if(void 0===a)return c(yield M(O,t),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,t);y=Object.assign(Object.assign(Object.assign({},y),a),r),delete y.fragment}try{const e=l(y.operator,h);if(!e)return c(yield M(O,t),`Invalid operator: ${y.operator}`,C);if(!t.operators[e])return c(yield M(O,t),`Excluded operator: ${y.operator}`,C);const{propertyAliases:r,evaluate:a,parseChildren:i}=d[e];y=((e,t)=>p(t,(t=>t in e?e[t]:t)))(r,y);const s=yield B(y,t);T||Object.entries(s).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const n=T?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),s)}):t;if("children"in y){if(Array.isArray(y.children)||(y.children=yield M(y.children,n)),!Array.isArray(y.children))return c(yield M(O,t),`Operator: ${e}\n- Property "children" is not of type: array`,C);y=yield i(y,n),delete y.children}let u;try{u=yield a(y,n)}catch(r){return c(yield M(y.fallback,t),`Operator: ${e}\n${f(r)}`,C)}const v=null!==(o=null==y?void 0:y.outputType)&&void 0!==o?o:null==y?void 0:y.type;if(!v)return u;const g=yield M(v,t);return g in m?m[g](u):c(yield M(O,t),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield M(O,t),f(e),C)}})),F=(e,t)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>M(e,t)))):yield M(e,t)})),B=(e,t)=>i(void 0,void 0,void 0,(function*(){const r=Object.keys(e).filter(h);if(0===r.length)return{};const a=[];return r.forEach((r=>a.push(M(e[r],t)))),R(r,yield Promise.all(a))})),G=(e,t)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{h(r)&&(a.push(r,M(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,M(a,t))}));const s=yield Promise.all(r);return v(k(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)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(U(J.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:V},X=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],K=I(X),Z={description:"Logical OR",aliases:["or","|","||"],parameters:X},ee={propertyAliases:K,operatorData:Z,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(U(Z.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:V},te=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array",default:["These are equal","These are equal"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],re=I(te),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:te},ie={propertyAliases:re,operatorData:ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield F([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(U(ae.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=t.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=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>r.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,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield F([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(U(oe.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=t.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=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!r.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)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(U(ce.parameters,{values:r,type:e.type})),0===r.length?r:"string"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),""):"array"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),[]):r.every((e=>"string"==typeof e||Array.isArray(e)))?r.reduce(((e,t)=>e.concat(t))):r.every((e=>b(e)))?r.reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{}):r.reduce(((e,t)=>e+t))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array",default:[10,5]},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number",default:100},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number",default:50}],ve=I(he),ye={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},me={propertyAliases:ve,operatorData:ye,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i]=yield F([e.values,e.from,e.subtract],t);t.typeChecker(U(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},fe=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],ge=I(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);if(t.typeChecker(U(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),qe={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},je={propertyAliases:Ce,operatorData:qe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield F([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(U(qe.parameters,{values:r,dividend:a,divisor:i,output:s}));const n=null!=r?r:[a,i].filter((e=>void 0!==e));if(n.length<2)throw new Error("- Not enough values provided");if(n.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");if(0===n[1])throw new Error("Division by zero!");switch(s){case"quotient":return Math.floor(n[0]/n[1]);case"remainder":return n[0]%n[1];default:return n[0]/n[1]}})),parseChildren:V},Se=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array",default:[10,9]},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],Ee=I(Se),Ae={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Se},we={propertyAliases:Ee,operatorData:Ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield F([e.values,e.strict],t);if(t.typeChecker(U(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},Ne=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array",default:[9,10]},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],xe=I(Ne),Pe={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Ne},Le={propertyAliases:xe,operatorData:Pe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield F([e.values,e.strict],t);if(t.typeChecker(U(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"}],Ue=I(Ie),Re={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ie},ke={propertyAliases:Ue,operatorData:Re,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(U(Re.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}$"}],Qe=I(De),_e={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},$e={propertyAliases:Qe,operatorData:_e,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a]=yield F([e.testString,e.pattern],t);t.typeChecker(U(_e.parameters,{testString:r,pattern:a}));try{return new RegExp(a).test(r)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[t,r]=e.children;return Object.assign(Object.assign({},e),{testString:t,pattern:r})}},He=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string",default:"path.to[0].my.data"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object",default:{}}],Me=I(He),Fe={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:He},Be={propertyAliases:Me,operatorData:Fe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,i;const[s,n={}]=yield F([e.property,e.additionalData],r);r.typeChecker(U(Fe.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 t(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:["friend"]},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],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)=>i(void 0,void 0,void 0,(function*(){const[r,a={},i=!0,s="%",n={}]=yield F([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(U(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=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)}return r.split(/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ve(e,a,n,t.options.data);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ve=(e,r,a,i={})=>{const s=e.replace(/{{(.+)}}/,"$1"),n=t(r,s,t(i,s,""));if("number"!=typeof n)return n;if(!(s in a))return n;const o=a[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(a[s]),u=l.find((e=>e.startsWith(">")));if(u){if(n>Number(u.slice(1)))return null==o?void 0:o[u]}const d=l.find((e=>e.startsWith("<")));if(d){if(n<Number(d.slice(1)))return null==o?void 0:o[d]}return o.other?o.other.replace("{}",String(n)):n},Ye=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Xe=I(Ye),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Ye},Ze={propertyAliases:Xe,operatorData:Ke,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield F(e.values,t);return t.typeChecker(U(Ke.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},et=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string",default:"Alpha, Bravo, Charlie"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string",default:","},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"excludeTrailing",description:"If the input string ends in a delimiter, there will be an additional blank element if this value is false (default: true)",aliases:["removeTrailing","excludeTrailingDelimiter"],required:!1,type:"boolean",default:!0}],tt=I(et),rt={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:et},at=" ",it={propertyAliases:tt,operatorData:rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield F([e.value,null!==(r=e.delimiter)&&void 0!==r?r:at,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(U(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)=>i(void 0,void 0,void 0,(function*(){var r,a,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 F([e.query,e.values||[],e.single,e.flatten,e.useCache,e.type],t);t.typeChecker(U(ot.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(s=null!==(a=e.useCache)&&void 0!==a?a:t.options.useCache)||void 0===s||s;{const e=t.cache.useCache(h,((e,t,r,a,s)=>i(void 0,void 0,void 0,(function*(){const i=(yield n.query({query:e,values:t}))||[];["array","string","number"].includes(null!=s?s:"")&&(a=!0);const o=a?i.map((e=>{const t=Object.values(e);return t.length<=1?t[0]:t})):i;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})}},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)=>i(void 0,void 0,void 0,(function*(){var r,a,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,m]=yield F([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],t),{url:f,headers:g}=p instanceof Object?p:{url:p,headers:null};t.typeChecker([...U(ct.parameters,{url:f,query:c,variables:h,returnNode:v,headers:y,useCache:m}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=f&&"graphqlendpoint"!==f.toLowerCase()?f:"",T=null!==(n=null!==(s=null===(a=t.options.graphQLConnection)||void 0===a?void 0:a.endpoint)&&void 0!==s?s:t.options.baseEndpoint)&&void 0!==n?n:"",O=_(b)?b:$(T,b),C={query:c,variables:h},q=null===(o=null!=m?m:t.options.useCache)||void 0===o||o,j=yield t.cache.useCache(q,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H(d,{url:e,method:"post",data:t,headers:r});return Q(null==i?void 0:i.data,a)}))),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)=>i(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield F(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=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}))},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},mt=(e,t)=>i(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield F(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=R(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),ft=mt,gt={propertyAliases:vt,operatorData:yt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield F([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...U(yt.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===(a=t.options)||void 0===a?void 0:a.headers),h),d),m=null===(s=null!=c?c:t.options.useCache)||void 0===s||s,f=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H(n,{url:e,params:t,headers:r});return Q(i,a)}))),_(p)?p:$(v,p),l,y,u);return f})),parseChildren:mt},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)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield F([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...U(Ot.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===(a=t.options)||void 0===a?void 0:a.headers),h),d),m=null!==(s=null!=c?c:t.options.useCache)&&void 0!==s&&s,f=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H(n,{url:e,data:t,headers:r,method:"post"});return Q(i,a)}))),_(p)?p:$(v,p),l,y,u);return f})),parseChildren:ft},qt=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array",default:["firstKey","firstValue","secondKey","secondValue"]}],jt=I(qt),St={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:qt},Et={propertyAliases:jt,operatorData:St,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(U(St.parameters,{properties:e.properties}));const r=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:r})=>{return a=[e,r],i(void 0,void 0,void 0,(function*(){const[e,r]=yield F(a,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var a}));return Object.fromEntries(yield Promise.all(r))})),parseChildren:e=>{const t=e.children;if(t.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=t.filter(((e,t)=>t%2==0)),a=t.filter(((e,t)=>t%2==1)),i=r.map(((e,t)=>({key:e,value:a[t]})));return Object.assign(Object.assign({},e),{properties:i})}},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"]}],wt={propertyAliases:I(At),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:At},evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r;const a=yield M(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=s(i)?yield M(i,t):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield M(n[a],t);if("fallback"in n)return yield M(n.fallback,t);if(a in e)return yield M(e[a],t);throw new Error(`No match found for ${a}`)})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=k(yield F(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},Nt=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array",default:[]},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],xt=I(Nt),Pt={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:Nt},Lt={propertyAliases:xt,operatorData:Pt,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield F([e.functionPath,e.args,e.useCache],r);r.typeChecker(U(Pt.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=r.options,p=null!==(s=null!==(a=t(c,o,null))&&void 0!==a?a:t(d,o,null))&&void 0!==s?s:t(r.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:r.options.useCache)&&void 0!==n&&n;return yield r.cache.useCache(h,((e,...t)=>i(void 0,void 0,void 0,(function*(){return yield p(...t)}))),o,...l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionPath:t,args:r})}},It=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Ut=I(It),Rt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:It},kt={propertyAliases:Ut,operatorData:Rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){return t.typeChecker(U(Rt.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:Et,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Lt,DIVIDE:je,EQUAL:ie,GET:gt,GRAPHQL:pt,GREATER_THAN:we,LESS_THAN:Le,MATCH:wt,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:Be,OR:ee,PASSTHRU:kt,PLUS:pe,POST:Ct,REGEX:$e,SPLIT:it,SQL:lt,STRING_SUBSTITUTION:Je,SUBTRACT:me});class Qt{constructor(e){var t,r;this.useCache=(e,t,...r)=>i(this,void 0,void 0,(function*(){if(!e)return yield t(...r);const a=_t(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 _t=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),$t=e=>e?"name"in e&&"fetch"===e.name?Mt(e):"Axios"in e&&"Axios"===e.Axios.name?Ht(e):e:"undefined"!=typeof window&&"document"in window&&"fetch"in window?Mt(window.fetch):void 0,Ht=e=>({get:t=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"get"}))).data})),post:t=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"post"}))).data})),throwError:t=>{var r;if(e.isAxiosError(t)){if(!(null==t?void 0:t.response))throw new Error("Network Error");console.log(null===(r=t.response)||void 0===r?void 0:r.data)}throw t}}),Mt=e=>({get:t=>i(void 0,void 0,void 0,(function*(){const{url:r,headers:i,params:s={}}=t,n=Object.keys(s).length>0?`?${a.stringify(s)}`:"",o=yield e(r+n,{headers:i,method:"GET"}),l=yield o.json();if(!o.ok)throw console.log(l),new Error(`Request failed with status code ${o.status}`);return l})),post:t=>i(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)throw console.log(u),new Error(`Request failed with status code ${l.status}`);return u})),throwError:e=>{throw new Error(`${f(e)}`)}});class Ft{constructor(e={}){var t,r,a;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=N(...t);if(!0!==r)throw new Error(r)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.15.2",this.options=Bt(e),this.operators=u(Dt,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],T),this.operatorAliases=T,this.cache=new Qt({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 i(this,void 0,void 0,(function*(){const a=y(this.options,Bt(t));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 M(e,{options:a,operators:t.excludeOperators?u(Dt,t.excludeOperators,T):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=y(this.options,Bt(e)),this.options.excludeOperators&&(this.operators=u(Dt,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(Dt,this.options.excludeOperators,T):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(T))];return t.sort(((e,t)=>r.indexOf(e.name)-r.indexOf(t.name)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,t])=>Object.assign({name:e},null==t?void 0:t.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,t])=>({name:e,numRequiredArgs:t.length})))}}const Bt=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;exports.AxiosClient=Ht,exports.FetchClient=Mt,exports.FigTreeEvaluator=Ft,exports.SQLNodePostgres=e=>({query:({query:t,values:r=[]})=>i(void 0,void 0,void 0,(function*(){const a={text:t,values:null!=r?r:[]},i=yield e.query(a);if(null==i?void 0:i.error)throw new Error(i.error);return i.rows}))}),exports.SQLite=e=>({query:({query:t,values:r=[]})=>i(void 0,void 0,void 0,(function*(){try{return yield e.all(t,r)}catch(e){throw`SQLite error: ${null==e?void 0:e.message}`}}))}),exports.evaluateExpression=(e,t)=>new Ft(t).evaluate(e),exports.isAliasString=h,exports.isFragmentNode=n,exports.isObject=b,exports.isOperatorNode=s,exports.preProcessShorthand=q,exports.standardiseOperatorName=o,exports.truncateString=d;
|
|
1
|
+
"use strict";var e=require("change-case"),t=require("object-property-extractor"),r=require("dequal/lite"),a=require("querystring");function i(e,t,r,a){return new(r||(r=Promise))((function(i,s){function n(e){try{l(a.next(e))}catch(e){s(e)}}function o(e){try{l(a.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=t=>{const r=e.camelCase(t);return r||t},l=(e,t)=>t[o(e)],u=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[o(e)]]})),a},d=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,c=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},p=e=>/^\$.+/.test(e),h=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&p(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},v=(e,t)=>{const r=Object.assign(Object.assign({},e),t);return(e.data||t.data)&&(r.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(r.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(r.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(r.headers=Object.assign(Object.assign({},e.headers),t.headers)),r},y={number:e=>m(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},m=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=>"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=!0)=>r?"string"==typeof e?C(e,t):f(e)?q(e,t):e:e,C=(e,t)=>{const r=T.exec(e);if(!r)return e;const a=r[1].trim(),i=r[2].split(",").map((e=>O(e.trim(),t)));return E(a,i,t)},q=(e,t)=>{if(s(e)||n(e))return e;const r=Object.entries(e),a=r.filter((([e])=>p(e))),i=r.filter((([e])=>!p(e))),o=a.reduce(((e,[r,a])=>e=Object.assign(Object.assign({},e),E(r,a,t))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,t,r)=>{const a=e.slice(1),i=l(a,b);return i?Array.isArray(t)?{operator:i,children:t}:f(t)&&!Object.keys(t).some((e=>p(e)))?Object.assign({operator:i},t):{operator:i,children:[t]}:a in r?{fragment:a,parameters:Object.assign({},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 j=({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},A=e=>f(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,w[r])(e)||P(t,e,r)},N=(...e)=>{const t=[];return e.forEach((e=>{const r=x(e);!0!==r&&t.push(r)})),!(t.length>0)||t.join("\n")},w={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=>f(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 d(t,50)},I=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},U=(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}})),R=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=e.filter(((e,t)=>t%2==0)),r=N(...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=>f(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,Q=(e,r,a=void 0)=>{const i=r?t(e,r,a):e;return Array.isArray(i)?i.map((e=>D(e))):r?null===i?null:D(i):i},_=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)=>i(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)=>i(void 0,void 0,void 0,(function*(){var r,a,i,o;const{options:u,operators:d,operatorAliases:p}=t;let v=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return s(t)?t:e}catch(t){return e}})(e):e;v=O(v,null===(r=t.options)||void 0===r?void 0:r.fragments,!u.noShorthand),Array.isArray(v)&&(v=yield $(v,t));const m=s(v),g=n(v);if(u.evaluateFullObject&&!m&&!g)return h(yield G(v,t),t);if(!m&&!g)return u.supportDeprecatedValueNodes&&f(v)&&"value"in v?v.value:h(v,t);const{fallback:b}=v,T=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(g){const[e,r]=yield $([v.fragment,v.parameters],t),a=O(null===(i=null==u?void 0:u.fragments)||void 0===i?void 0:i[e],u.fragments,!u.noShorthand);if(void 0===a)return j({fallback:yield M(b,t),error:`Fragment not defined: ${e}`,expression:v,returnErrorAsString:T});if(!s(a))return h(a,t);v=Object.assign(Object.assign(Object.assign({},v),a),r),delete v.fragment}const C=l(v.operator,p);if(!C)return j({fallback:yield M(b,t),error:`Invalid operator: ${v.operator}`,expression:v,returnErrorAsString:T});if(!t.operators[C])return j({fallback:yield M(b,t),error:`Excluded operator: ${v.operator}`,expression:v,returnErrorAsString:T});const{propertyAliases:q,evaluate:E,parseChildren:S}=d[C];v=((e,t)=>c(t,(t=>t in e?e[t]:t)))(q,v);const A=yield B(v,t);g||Object.entries(A).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const x=g?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),A)}):t;if("children"in v){if(Array.isArray(v.children)||(v.children=yield M(v.children,x)),!Array.isArray(v.children))return j({fallback:yield M(b,t),operator:C,name:"Type Error",error:'- Property "children" is not of type: array',expression:v,returnErrorAsString:T});v=yield S(v,x),delete v.children}let N;try{N=yield E(v,x)}catch(e){return j({fallback:yield M(v.fallback,t),operator:C,error:e,expression:v,returnErrorAsString:T})}const w=null!==(o=null==v?void 0:v.outputType)&&void 0!==o?o:null==v?void 0:v.type;if(!w)return N;const P=yield M(w,t);return P in y?y[P](N):j({fallback:yield M(b,t),operator:C,error:`- Invalid output type: ${P}`,expression:v,returnErrorAsString:T})})),$=(e,t)=>i(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)=>i(void 0,void 0,void 0,(function*(){const r=Object.keys(e).filter(p);if(0===r.length)return{};const a=[];return r.forEach((r=>a.push(M(e[r],t)))),R(r,yield Promise.all(a))})),G=(e,t)=>i(void 0,void 0,void 0,(function*(){if(!f(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{p(r)&&(a.push(r,M(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,M(a,t))}));const s=yield Promise.all(r);return h(k(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)=>i(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);return t.typeChecker(U(J.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:V},X=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],K=I(X),Z={description:"Logical OR",aliases:["or","|","||"],parameters:X},ee={propertyAliases:K,operatorData:Z,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);return t.typeChecker(U(Z.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:V},te=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array",default:["These are equal","These are equal"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],re=I(te),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:te},ie={propertyAliases:re,operatorData:ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield $([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(U(ae.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=t.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=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>r.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,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield $([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(U(oe.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=t.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=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!r.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)=>i(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);return t.typeChecker(U(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=>f(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},me={propertyAliases:ve,operatorData:ye,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i]=yield $([e.values,e.from,e.subtract],t);t.typeChecker(U(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},fe=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],ge=I(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);if(t.typeChecker(U(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),qe={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},Ee={propertyAliases:Ce,operatorData:qe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield $([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(U(qe.parameters,{values:r,dividend:a,divisor:i,output:s}));const n=null!=r?r:[a,i].filter((e=>void 0!==e));if(n.length<2)throw new Error("- Not enough values provided");if(n.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");if(0===n[1])throw new Error("Division by zero!");switch(s){case"quotient":return Math.floor(n[0]/n[1]);case"remainder":return n[0]%n[1];default:return n[0]/n[1]}})),parseChildren:V},Se=[{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}],je=I(Se),Ae={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Se},xe={propertyAliases:je,operatorData:Ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield $([e.values,e.strict],t);if(t.typeChecker(U(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},Ne=[{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}],we=I(Ne),Pe={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Ne},Le={propertyAliases:we,operatorData:Pe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield $([e.values,e.strict],t);if(t.typeChecker(U(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"}],Ue=I(Ie),Re={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ie},ke={propertyAliases:Ue,operatorData:Re,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(U(Re.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}$"}],Qe=I(De),_e={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},Fe={propertyAliases:Qe,operatorData:_e,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a]=yield $([e.testString,e.pattern],t);t.typeChecker(U(_e.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:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,i;const[s,n={}]=yield $([e.property,e.additionalData],r);r.typeChecker(U($e.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 t(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:["friend"]},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],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)=>i(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(U(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=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)}return r.split(/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ve(e,a,n,t.options.data);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ve=(e,r,a,i={})=>{const s=e.replace(/{{(.+)}}/,"$1"),n=t(r,s,t(i,s,""));if("number"!=typeof n)return n;if(!(s in a))return n;const o=a[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(a[s]),u=l.find((e=>e.startsWith(">")));if(u){if(n>Number(u.slice(1)))return null==o?void 0:o[u]}const d=l.find((e=>e.startsWith("<")));if(d){if(n<Number(d.slice(1)))return null==o?void 0:o[d]}return o.other?o.other.replace("{}",String(n)):n},Ye=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Xe=I(Ye),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Ye},Ze={propertyAliases:Xe,operatorData:Ke,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield $(e.values,t);return t.typeChecker(U(Ke.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},et=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string",default:"Alpha, Bravo, Charlie"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string",default:","},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"excludeTrailing",description:"If the input string ends in a delimiter, there will be an additional blank element if this value is false (default: true)",aliases:["removeTrailing","excludeTrailingDelimiter"],required:!1,type:"boolean",default:!0}],tt=I(et),rt={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:et},at=" ",it={propertyAliases:tt,operatorData:rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield $([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(U(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)=>i(void 0,void 0,void 0,(function*(){var r,a,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 $([e.query,e.values||[],e.single,e.flatten,e.useCache,e.type],t);t.typeChecker(U(ot.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(s=null!==(a=e.useCache)&&void 0!==a?a:t.options.useCache)||void 0===s||s;{const e=t.cache.useCache(h,((e,t,r,a,s)=>i(void 0,void 0,void 0,(function*(){const i=(yield n.query({query:e,values:t}))||[];["array","string","number"].includes(null!=s?s:"")&&(a=!0);const o=a?i.map((e=>{const t=Object.values(e);return t.length<=1?t[0]:t})):i;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})}},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)=>i(void 0,void 0,void 0,(function*(){var r,a,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,m]=yield $([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],t),{url:f,headers:g}=p instanceof Object?p:{url:p,headers:null};t.typeChecker([...U(ct.parameters,{url:f,query:c,variables:h,returnNode:v,headers:y,useCache:m}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=f&&"graphqlendpoint"!==f.toLowerCase()?f:"",T=null!==(n=null!==(s=null===(a=t.options.graphQLConnection)||void 0===a?void 0:a.endpoint)&&void 0!==s?s:t.options.baseEndpoint)&&void 0!==n?n:"",O=_(b)?b:F(T,b),C={query:c,variables:h},q=null===(o=null!=m?m:t.options.useCache)||void 0===o||o,E=yield t.cache.useCache(q,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H(d,{url:e,method:"post",data:t,headers:r});return Q(null==i?void 0:i.data,a)}))),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 E})),parseChildren:(e,t)=>i(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=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}))},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},mt=(e,t)=>i(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=R(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),ft=mt,gt={propertyAliases:vt,operatorData:yt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield $([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...U(yt.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===(a=t.options)||void 0===a?void 0:a.headers),h),d),m=null===(s=null!=c?c:t.options.useCache)||void 0===s||s,f=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H(n,{url:e,params:t,headers:r});return Q(i,a)}))),_(p)?p:F(v,p),l,y,u);return f})),parseChildren:mt},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)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield $([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...U(Ot.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===(a=t.options)||void 0===a?void 0:a.headers),h),d),m=null!==(s=null!=c?c:t.options.useCache)&&void 0!==s&&s,f=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H(n,{url:e,data:t,headers:r,method:"post"});return Q(i,a)}))),_(p)?p:F(v,p),l,y,u);return f})),parseChildren:ft},qt=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array",default:["firstKey","firstValue","secondKey","secondValue"]}],Et=I(qt),St={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:qt},jt={propertyAliases:Et,operatorData:St,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(U(St.parameters,{properties:e.properties}));const r=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:r})=>{return a=[e,r],i(void 0,void 0,void 0,(function*(){const[e,r]=yield $(a,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var a}));return Object.fromEntries(yield Promise.all(r))})),parseChildren:e=>{const t=e.children;if(t.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=t.filter(((e,t)=>t%2==0)),a=t.filter(((e,t)=>t%2==1)),i=r.map(((e,t)=>({key:e,value:a[t]})));return Object.assign(Object.assign({},e),{properties:i})}},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)=>i(void 0,void 0,void 0,(function*(){var r;const a=yield M(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=s(i)?yield M(i,t):i;if(!f(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield M(n[a],t);if("fallback"in n)return yield M(n.fallback,t);if(a in e)return yield M(e[a],t);throw new Error(`No match found for ${a}`)})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=k(yield $(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},Nt=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array",default:[]},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],wt=I(Nt),Pt={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:Nt},Lt={propertyAliases:wt,operatorData:Pt,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield $([e.functionPath,e.args,e.useCache],r);r.typeChecker(U(Pt.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=r.options,p=null!==(s=null!==(a=t(c,o,null))&&void 0!==a?a:t(d,o,null))&&void 0!==s?s:t(r.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:r.options.useCache)&&void 0!==n&&n;return yield r.cache.useCache(h,((e,...t)=>i(void 0,void 0,void 0,(function*(){return yield p(...t)}))),o,...l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionPath:t,args:r})}},It=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Ut=I(It),Rt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:It},kt={propertyAliases:Ut,operatorData:Rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){return t.typeChecker(U(Rt.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:jt,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Lt,DIVIDE:Ee,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:kt,PLUS:pe,POST:Ct,REGEX:Fe,SPLIT:it,SQL:lt,STRING_SUBSTITUTION:Je,SUBTRACT:me});class Qt{constructor(e){var t,r;this.useCache=(e,t,...r)=>i(this,void 0,void 0,(function*(){if(!e)return yield t(...r);const a=_t(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 _t=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),Ft=e=>e?"name"in e&&"fetch"===e.name?Mt(e):"Axios"in e&&"Axios"===e.Axios.name?Ht(e):e:"undefined"!=typeof window&&"document"in window&&"fetch"in window?Mt(window.fetch):void 0,Ht=e=>({get:t=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"get"}))).data})),post:t=>i(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))}}),Mt=e=>({get:t=>i(void 0,void 0,void 0,(function*(){const{url:r,headers:i,params:s={}}=t,n=Object.keys(s).length>0?`?${a.stringify(s)}`:"",o=yield e(r+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=>i(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 $t{constructor(e={}){var t,r,a;this.typeChecker=(...e)=>{const t=1===e.length&&Array.isArray(e[0])?e[0]:e,r=N(...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.16.1",this.options=Bt(e),this.operators=u(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 Qt({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 r;return i(this,void 0,void 0,(function*(){const a=v(this.options,Bt(t));return t.httpClient&&(this.httpClient=Ft(t.httpClient)),(null===(r=t.graphQLConnection)||void 0===r?void 0:r.httpClient)&&(this.graphQLClient=Ft(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 M(e,{options:a,operators:t.excludeOperators?u(Dt,t.excludeOperators,g):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,Bt(e)),this.options.excludeOperators&&(this.operators=u(Dt,this.options.excludeOperators,g))}getOperators(){const e=this.options.excludeOperators?u(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])=>({name:e,numRequiredArgs:t.length})))}}const Bt=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e;exports.AxiosClient=Ht,exports.FetchClient=Mt,exports.FigTreeError=S,exports.FigTreeEvaluator=$t,exports.SQLNodePostgres=e=>({query:({query:t,values:r=[]})=>i(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=[]})=>i(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 $t(t).evaluate(e),exports.isAliasString=p,exports.isFigTreeError=e=>e instanceof S,exports.isFragmentNode=n,exports.isObject=f,exports.isOperatorNode=s,exports.preProcessShorthand=O,exports.standardiseOperatorName=o,exports.truncateString=d;
|
package/build/index.d.ts
CHANGED
|
@@ -219,6 +219,17 @@ declare class FigTreeEvaluator {
|
|
|
219
219
|
|
|
220
220
|
declare const evaluateExpression: (expression: EvaluatorNode, options?: FigTreeOptions) => Promise<EvaluatorOutput>;
|
|
221
221
|
|
|
222
|
+
declare class FigTreeError extends Error {
|
|
223
|
+
operator?: Operator;
|
|
224
|
+
errorData?: Record<string, unknown>;
|
|
225
|
+
expression?: EvaluatorNode;
|
|
226
|
+
prettyPrint: string;
|
|
227
|
+
constructor(error: Error & {
|
|
228
|
+
errorData?: Record<string, unknown>;
|
|
229
|
+
}, operator?: Operator, name?: string, expression?: EvaluatorNode);
|
|
230
|
+
}
|
|
231
|
+
declare const isFigTreeError: (input: unknown) => input is FigTreeError;
|
|
232
|
+
|
|
222
233
|
declare const SQLNodePostgres: (client: Client) => {
|
|
223
234
|
query: ({ query, values }: QueryInput) => Promise<QueryOutput>;
|
|
224
235
|
};
|
|
@@ -235,4 +246,4 @@ declare const truncateString: (string: string, length?: number) => string;
|
|
|
235
246
|
declare const isAliasString: (value: string) => boolean;
|
|
236
247
|
declare const isObject: (input: unknown) => input is object;
|
|
237
248
|
|
|
238
|
-
export { AxiosClient, type BasicType, type CustomFunctionMetadata, type EvaluatorNode, type EvaluatorOutput, type ExpectedType, FetchClient, type FigTreeConfig, 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, isFragmentNode, isObject, isOperatorNode, preProcessShorthand, standardiseOperatorName, truncateString };
|
|
249
|
+
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 };
|
package/build/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{camelCase as e}from"change-case";import t from"object-property-extractor";import{dequal as r}from"dequal/lite";import a from"querystring";function i(e,t,r,a){return new(r||(r=Promise))((function(i,s){function n(e){try{l(a.next(e))}catch(e){s(e)}}function o(e){try{l(a.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=t=>{const r=e(t);return r||t},l=(e,t)=>t[o(e)],u=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[o(e)]]})),a},d=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,c=(e,t,r=!1)=>{if(void 0!==e)return e;if(r)return d(t);throw new Error(d(t))},p=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},h=e=>/^\$.+/.test(e),v=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&h(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},y=(e,t)=>{const r=Object.assign(Object.assign({},e),t);return(e.data||t.data)&&(r.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(r.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(r.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(r.headers=Object.assign(Object.assign({},e.headers),t.headers)),r},m={number:e=>g(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=e=>e.message,g=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const t=new RegExp(/-?\d*\.?\d+/gm),r=e.match(t);return r?Number(r[0]):0},b=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),T={and:"AND","&":"AND","&&":"AND",or:"OR","|":"OR","||":"OR","=":"EQUAL",eq:"EQUAL",equal:"EQUAL",equals:"EQUAL","!=":"NOT_EQUAL","!":"NOT_EQUAL",ne:"NOT_EQUAL",notEqual:"NOT_EQUAL","+":"PLUS",plus:"PLUS",add:"PLUS",concat:"PLUS",join:"PLUS",merge:"PLUS","-":"SUBTRACT",subtract:"SUBTRACT",minus:"SUBTRACT",takeaway:"SUBTRACT","*":"MULTIPLY",x:"MULTIPLY",multiply:"MULTIPLY",times:"MULTIPLY","/":"DIVIDE",divide:"DIVIDE","÷":"DIVIDE",">":"GREATER_THAN",greaterThan:"GREATER_THAN",higher:"GREATER_THAN",larger:"GREATER_THAN","<":"LESS_THAN",lessThan:"LESS_THAN",lower:"LESS_THAN",smaller:"LESS_THAN","?":"CONDITIONAL",conditional:"CONDITIONAL",ifThen:"CONDITIONAL",regex:"REGEX",patternMatch:"REGEX",regexp:"REGEX",matchPattern:"REGEX",dataProperties:"OBJECT_PROPERTIES",data:"OBJECT_PROPERTIES",getData:"OBJECT_PROPERTIES",objectProperties:"OBJECT_PROPERTIES",objProps:"OBJECT_PROPERTIES",getProperty:"OBJECT_PROPERTIES",getObjProp:"OBJECT_PROPERTIES",stringSubstitution:"STRING_SUBSTITUTION",substitute:"STRING_SUBSTITUTION",stringSub:"STRING_SUBSTITUTION",replace:"STRING_SUBSTITUTION",split:"SPLIT",arraySplit:"SPLIT",count:"COUNT",length:"COUNT",get:"GET",api:"GET",post:"POST",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"},O=T,C=/(\$[^()]+)\((.*)\)/,q=(e,t={},r=!0)=>r?"string"==typeof e?j(e,t):b(e)?S(e,t):e:e,j=(e,t)=>{const r=C.exec(e);if(!r)return e;const a=r[1].trim(),i=r[2].split(",").map((e=>q(e.trim(),t)));return E(a,i,t)},S=(e,t)=>{if(s(e)||n(e))return e;const r=Object.entries(e),a=r.filter((([e])=>h(e))),i=r.filter((([e])=>!h(e))),o=a.reduce(((e,[r,a])=>e=Object.assign(Object.assign({},e),E(r,a,t))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,t,r)=>{const a=e.slice(1),i=l(a,O);return i?Array.isArray(t)?{operator:i,children:t}:b(t)&&!Object.keys(t).some((e=>h(e)))?Object.assign({operator:i},t):{operator:i,children:[t]}:a in r?{fragment:a,parameters:Object.assign({},t)}:{[e]:t}},A=e=>b(e)&&"literal"in e,w=({value:e,name:t,expectedType:r})=>{if(A(r)){const{literal:a}=r;return!!a.includes(e)||x(t,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(r))return!!r.some((r=>!0===w({value:e,name:t,expectedType:r})))||x(t,e,r.join("|"));return!!(0,P[r])(e)||x(t,e,r)},N=(...e)=>{const t=[];return e.forEach((e=>{const r=w(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=>b(e),undefined:e=>void 0===e},x=(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 d(t,50)},I=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},U=(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}})),R=(e,t)=>{const r=e.map(((e,r)=>[e,t[r]]));return Object.fromEntries(r)},k=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=e.filter(((e,t)=>t%2==0)),r=N(...t.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==r)throw new Error(r);const a=e.filter(((e,t)=>t%2==1)),i={};return t.forEach(((e,t)=>{i[e]=a[t]})),i},D=e=>b(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(e,r,a=void 0)=>{const i=r?t(e,r,a):e;return Array.isArray(i)?i.map((e=>D(e))):r?null===i?null:D(i):i},Q=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}),""),H=(e,t)=>i(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)=>i(void 0,void 0,void 0,(function*(){var r,a,i,o;const{options:u,operators:d,operatorAliases:h}=t;let y=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return s(t)?t:e}catch(t){return e}})(e):e;y=q(y,null===(r=t.options)||void 0===r?void 0:r.fragments,!u.noShorthand),Array.isArray(y)&&(y=yield B(y,t));const g=s(y),T=n(y);if(u.evaluateFullObject&&!g&&!T)return v(yield G(y,t),t);if(!g&&!T)return u.supportDeprecatedValueNodes&&b(y)&&"value"in y?y.value:v(y,t);const{fallback:O}=y,C=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(T){const[e,r]=yield B([y.fragment,y.parameters],t),a=q(null===(i=null==u?void 0:u.fragments)||void 0===i?void 0:i[e],u.fragments,!u.noShorthand);if(void 0===a)return c(yield M(O,t),`Fragment not defined: ${e}`,C);if(!s(a))return v(a,t);y=Object.assign(Object.assign(Object.assign({},y),a),r),delete y.fragment}try{const e=l(y.operator,h);if(!e)return c(yield M(O,t),`Invalid operator: ${y.operator}`,C);if(!t.operators[e])return c(yield M(O,t),`Excluded operator: ${y.operator}`,C);const{propertyAliases:r,evaluate:a,parseChildren:i}=d[e];y=((e,t)=>p(t,(t=>t in e?e[t]:t)))(r,y);const s=yield F(y,t);T||Object.entries(s).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const n=T?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),s)}):t;if("children"in y){if(Array.isArray(y.children)||(y.children=yield M(y.children,n)),!Array.isArray(y.children))return c(yield M(O,t),`Operator: ${e}\n- Property "children" is not of type: array`,C);y=yield i(y,n),delete y.children}let u;try{u=yield a(y,n)}catch(r){return c(yield M(y.fallback,t),`Operator: ${e}\n${f(r)}`,C)}const v=null!==(o=null==y?void 0:y.outputType)&&void 0!==o?o:null==y?void 0:y.type;if(!v)return u;const g=yield M(v,t);return g in m?m[g](u):c(yield M(O,t),`Operator: ${e}\n- Invalid output type: ${g}`,C)}catch(e){return c(yield M(O,t),f(e),C)}})),B=(e,t)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>M(e,t)))):yield M(e,t)})),F=(e,t)=>i(void 0,void 0,void 0,(function*(){const r=Object.keys(e).filter(h);if(0===r.length)return{};const a=[];return r.forEach((r=>a.push(M(e[r],t)))),R(r,yield Promise.all(a))})),G=(e,t)=>i(void 0,void 0,void 0,(function*(){if(!b(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{h(r)&&(a.push(r,M(i,t)),delete e[r])}));const i=yield Promise.all(a);t.resolvedAliasNodes=Object.assign(Object.assign({},t.resolvedAliasNodes),k(i)),Object.entries(e).forEach((([e,a])=>{r.push(e,M(a,t))}));const s=yield Promise.all(r);return v(k(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)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(U(J.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:V},X=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],K=I(X),Z={description:"Logical OR",aliases:["or","|","||"],parameters:X},ee={propertyAliases:K,operatorData:Z,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(U(Z.parameters,{values:r})),r.reduce(((e,t)=>e||!!t),!1)})),parseChildren:V},te=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array",default:["These are equal","These are equal"]},{name:"caseInsensitive",description:"If the values are strings, ignore the case (default: false)",aliases:[],required:!1,type:"boolean",default:!1},{name:"nullEqualsUndefined",description:"Whether a null value should be considered equal to an undefined value (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],re=I(te),ae={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:te},ie={propertyAliases:re,operatorData:ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(U(ae.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=t.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=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>r(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,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(U(oe.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=t.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=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!r(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)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(U(ce.parameters,{values:r,type:e.type})),0===r.length?r:"string"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),""):"array"===(null==e?void 0:e.type)?r.reduce(((e,t)=>e.concat(t)),[]):r.every((e=>"string"==typeof e||Array.isArray(e)))?r.reduce(((e,t)=>e.concat(t))):r.every((e=>b(e)))?r.reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{}):r.reduce(((e,t)=>e+t))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array",default:[10,5]},{name:"from",description:"Numerical value that will be subtracted from",aliases:["subtractFrom"],required:!1,type:"number",default:100},{name:"subtract",description:"Numerical value to subtract",aliases:[],required:!1,type:"number",default:50}],ve=I(he),ye={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},me={propertyAliases:ve,operatorData:ye,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i]=yield B([e.values,e.from,e.subtract],t);t.typeChecker(U(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},fe=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],ge=I(fe),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},Te={propertyAliases:ge,operatorData:be,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);if(t.typeChecker(U(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),qe={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Oe},je={propertyAliases:Ce,operatorData:qe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield B([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(U(qe.parameters,{values:r,dividend:a,divisor:i,output:s}));const n=null!=r?r:[a,i].filter((e=>void 0!==e));if(n.length<2)throw new Error("- Not enough values provided");if(n.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");if(0===n[1])throw new Error("Division by zero!");switch(s){case"quotient":return Math.floor(n[0]/n[1]);case"remainder":return n[0]%n[1];default:return n[0]/n[1]}})),parseChildren:V},Se=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array",default:[10,9]},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],Ee=I(Se),Ae={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Se},we={propertyAliases:Ee,operatorData:Ae,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(U(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},Ne=[{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=I(Ne),xe={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Ne},Le={propertyAliases:Pe,operatorData:xe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(U(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: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"}],Ue=I(Ie),Re={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ie},ke={propertyAliases:Ue,operatorData:Re,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(U(Re.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},$e={propertyAliases:_e,operatorData:Qe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a]=yield B([e.testString,e.pattern],t);t.typeChecker(U(Qe.parameters,{testString:r,pattern:a}));try{return new RegExp(a).test(r)}catch(e){throw new Error("Regex error:"+f(e))}})),parseChildren:e=>{const[t,r]=e.children;return Object.assign(Object.assign({},e),{testString:t,pattern:r})}},He=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string",default:"path.to[0].my.data"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object",default:{}}],Me=I(He),Be={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:He},Fe={propertyAliases:Me,operatorData:Be,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,i;const[s,n={}]=yield B([e.property,e.additionalData],r);r.typeChecker(U(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 t(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:["friend"]},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],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)=>i(void 0,void 0,void 0,(function*(){const[r,a={},i=!0,s="%",n={}]=yield B([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(U(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=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)}return r.split(/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ve(e,a,n,t.options.data);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ve=(e,r,a,i={})=>{const s=e.replace(/{{(.+)}}/,"$1"),n=t(r,s,t(i,s,""));if("number"!=typeof n)return n;if(!(s in a))return n;const o=a[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(a[s]),u=l.find((e=>e.startsWith(">")));if(u){if(n>Number(u.slice(1)))return null==o?void 0:o[u]}const d=l.find((e=>e.startsWith("<")));if(d){if(n<Number(d.slice(1)))return null==o?void 0:o[d]}return o.other?o.other.replace("{}",String(n)):n},Ye=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Xe=I(Ye),Ke={description:"Count elements in an array",aliases:["count","length"],parameters:Ye},Ze={propertyAliases:Xe,operatorData:Ke,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(U(Ke.parameters,{values:r})),r.length})),parseChildren:e=>{const[t]=e.children;return Object.assign(Object.assign({},e),{values:t})}},et=[{name:"value",description:"The string to be split",aliases:["string"],required:!0,type:"string",default:"Alpha, Bravo, Charlie"},{name:"delimiter",description:"The value to split the string on (default is white space)",aliases:["separator"],required:!1,type:"string",default:","},{name:"trimWhiteSpace",description:"Whether to trim white space from around the resulting elements (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"excludeTrailing",description:"If the input string ends in a delimiter, there will be an additional blank element if this value is false (default: true)",aliases:["removeTrailing","excludeTrailingDelimiter"],required:!1,type:"boolean",default:!0}],tt=I(et),rt={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:et},at=" ",it={propertyAliases:tt,operatorData:rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield B([e.value,null!==(r=e.delimiter)&&void 0!==r?r:at,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(U(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)=>i(void 0,void 0,void 0,(function*(){var r,a,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(U(ot.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(s=null!==(a=e.useCache)&&void 0!==a?a:t.options.useCache)||void 0===s||s;{const e=t.cache.useCache(h,((e,t,r,a,s)=>i(void 0,void 0,void 0,(function*(){const i=(yield n.query({query:e,values:t}))||[];["array","string","number"].includes(null!=s?s:"")&&(a=!0);const o=a?i.map((e=>{const t=Object.values(e);return t.length<=1?t[0]:t})):i;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})}},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)=>i(void 0,void 0,void 0,(function*(){var r,a,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,m]=yield B([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],t),{url:f,headers:g}=p instanceof Object?p:{url:p,headers:null};t.typeChecker([...U(ct.parameters,{url:f,query:c,variables:h,returnNode:v,headers:y,useCache:m}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=f&&"graphqlendpoint"!==f.toLowerCase()?f:"",T=null!==(n=null!==(s=null===(a=t.options.graphQLConnection)||void 0===a?void 0:a.endpoint)&&void 0!==s?s:t.options.baseEndpoint)&&void 0!==n?n:"",O=Q(b)?b:$(T,b),C={query:c,variables:h},q=null===(o=null!=m?m:t.options.useCache)||void 0===o||o,j=yield t.cache.useCache(q,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H(d,{url:e,method:"post",data:t,headers:r});return _(null==i?void 0:i.data,a)}))),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)=>i(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield B(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=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}))},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},mt=(e,t)=>i(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield B(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=R(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),ft=mt,gt={propertyAliases:vt,operatorData:yt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield B([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...U(yt.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===(a=t.options)||void 0===a?void 0:a.headers),h),d),m=null===(s=null!=c?c:t.options.useCache)||void 0===s||s,f=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H(n,{url:e,params:t,headers:r});return _(i,a)}))),Q(p)?p:$(v,p),l,y,u);return f})),parseChildren:mt},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)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield B([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...U(Ot.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===(a=t.options)||void 0===a?void 0:a.headers),h),d),m=null!==(s=null!=c?c:t.options.useCache)&&void 0!==s&&s,f=yield t.cache.useCache(m,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield H(n,{url:e,data:t,headers:r,method:"post"});return _(i,a)}))),Q(p)?p:$(v,p),l,y,u);return f})),parseChildren:ft},qt=[{name:"properties",description:'An array of objects, each with a "key" property and a "value" property',aliases:["values","keyValPairs","keyValuePairs"],required:!0,type:"array",default:["firstKey","firstValue","secondKey","secondValue"]}],jt=I(qt),St={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:qt},Et={propertyAliases:jt,operatorData:St,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(U(St.parameters,{properties:e.properties}));const r=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:r})=>{return a=[e,r],i(void 0,void 0,void 0,(function*(){const[e,r]=yield B(a,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var a}));return Object.fromEntries(yield Promise.all(r))})),parseChildren:e=>{const t=e.children;if(t.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=t.filter(((e,t)=>t%2==0)),a=t.filter(((e,t)=>t%2==1)),i=r.map(((e,t)=>({key:e,value:a[t]})));return Object.assign(Object.assign({},e),{properties:i})}},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"]}],wt={propertyAliases:I(At),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:At},evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r;const a=yield M(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?k(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=s(i)?yield M(i,t):i;if(!b(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield M(n[a],t);if("fallback"in n)return yield M(n.fallback,t);if(a in e)return yield M(e[a],t);throw new Error(`No match found for ${a}`)})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=k(yield B(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},Nt=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array",default:[]},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],Pt=I(Nt),xt={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:Nt},Lt={propertyAliases:Pt,operatorData:xt,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield B([e.functionPath,e.args,e.useCache],r);r.typeChecker(U(xt.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=r.options,p=null!==(s=null!==(a=t(c,o,null))&&void 0!==a?a:t(d,o,null))&&void 0!==s?s:t(r.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:r.options.useCache)&&void 0!==n&&n;return yield r.cache.useCache(h,((e,...t)=>i(void 0,void 0,void 0,(function*(){return yield p(...t)}))),o,...l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionPath:t,args:r})}},It=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Ut=I(It),Rt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:It},kt={propertyAliases:Ut,operatorData:Rt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){return t.typeChecker(U(Rt.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:Et,CONDITIONAL:ke,COUNT:Ze,CUSTOM_FUNCTIONS:Lt,DIVIDE:je,EQUAL:ie,GET:gt,GRAPHQL:pt,GREATER_THAN:we,LESS_THAN:Le,MATCH:wt,MULTIPLY:Te,NOT_EQUAL:le,OBJECT_PROPERTIES:Fe,OR:ee,PASSTHRU:kt,PLUS:pe,POST:Ct,REGEX:$e,SPLIT:it,SQL:lt,STRING_SUBSTITUTION:Je,SUBTRACT:me});class _t{constructor(e){var t,r;this.useCache=(e,t,...r)=>i(this,void 0,void 0,(function*(){if(!e)return yield t(...r);const a=Qt(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 Qt=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),$t=e=>e?"name"in e&&"fetch"===e.name?Mt(e):"Axios"in e&&"Axios"===e.Axios.name?Ht(e):e:"undefined"!=typeof window&&"document"in window&&"fetch"in window?Mt(window.fetch):void 0,Ht=e=>({get:t=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"get"}))).data})),post:t=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"post"}))).data})),throwError:t=>{var r;if(e.isAxiosError(t)){if(!(null==t?void 0:t.response))throw new Error("Network Error");console.log(null===(r=t.response)||void 0===r?void 0:r.data)}throw t}}),Mt=e=>({get:t=>i(void 0,void 0,void 0,(function*(){const{url:r,headers:i,params:s={}}=t,n=Object.keys(s).length>0?`?${a.stringify(s)}`:"",o=yield e(r+n,{headers:i,method:"GET"}),l=yield o.json();if(!o.ok)throw console.log(l),new Error(`Request failed with status code ${o.status}`);return l})),post:t=>i(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)throw console.log(u),new Error(`Request failed with status code ${l.status}`);return u})),throwError:e=>{throw new Error(`${f(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=N(...t);if(!0!==r)throw new Error(r)},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.15.2",this.options=Gt(e),this.operators=u(Dt,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],T),this.operatorAliases=T,this.cache=new _t({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 i(this,void 0,void 0,(function*(){const a=y(this.options,Gt(t));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 M(e,{options:a,operators:t.excludeOperators?u(Dt,t.excludeOperators,T):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=y(this.options,Gt(e)),this.options.excludeOperators&&(this.operators=u(Dt,this.options.excludeOperators,T))}getOperators(){const e=this.options.excludeOperators?u(Dt,this.options.excludeOperators,T):this.operators,t=Object.entries(e).map((([e,t])=>Object.assign({name:e},t.operatorData))),r=[...new Set(Object.values(T))];return t.sort(((e,t)=>r.indexOf(e.name)-r.indexOf(t.name)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,t])=>Object.assign({name:e},null==t?void 0:t.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,t])=>({name:e,numRequiredArgs:t.length})))}}const Ft=(e,t)=>new Bt(t).evaluate(e),Gt=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e,zt=e=>({query:({query:t,values:r=[]})=>i(void 0,void 0,void 0,(function*(){const a={text:t,values:null!=r?r:[]},i=yield e.query(a);if(null==i?void 0:i.error)throw new Error(i.error);return i.rows}))}),Wt=e=>({query:({query:t,values:r=[]})=>i(void 0,void 0,void 0,(function*(){try{return yield e.all(t,r)}catch(e){throw`SQLite error: ${null==e?void 0:e.message}`}}))});export{Ht as AxiosClient,Mt as FetchClient,Bt as FigTreeEvaluator,zt as SQLNodePostgres,Wt as SQLite,Ft as evaluateExpression,h as isAliasString,n as isFragmentNode,b as isObject,s as isOperatorNode,q as preProcessShorthand,o as standardiseOperatorName,d as truncateString};
|
|
1
|
+
import{camelCase as e}from"change-case";import t from"object-property-extractor";import{dequal as r}from"dequal/lite";import a from"querystring";function i(e,t,r,a){return new(r||(r=Promise))((function(i,s){function n(e){try{l(a.next(e))}catch(e){s(e)}}function o(e){try{l(a.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,o=t=>{const r=e(t);return r||t},l=(e,t)=>t[o(e)],u=(e,t,r)=>{const a=Object.assign({},e);return t.forEach((e=>{r[o(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[r[o(e)]]})),a},d=(e,t=200)=>e.length<t?e:`${e.slice(0,t-2).trim()}...`,c=(e,t)=>{const r=Object.entries(e).map((([e,r])=>[t(e),r]));return Object.fromEntries(r)},p=e=>/^\$.+/.test(e),h=(e,{resolvedAliasNodes:t})=>{var r;return"string"==typeof e&&p(e)&&null!==(r=null==t?void 0:t[e])&&void 0!==r?r:e},v=(e,t)=>{const r=Object.assign(Object.assign({},e),t);return(e.data||t.data)&&(r.data=Object.assign(Object.assign({},e.data),t.data)),(e.functions||t.functions)&&(r.functions=Object.assign(Object.assign({},e.functions),t.functions)),(e.fragments||t.fragments)&&(r.fragments=Object.assign(Object.assign({},e.fragments),t.fragments)),(e.headers||t.headers)&&(r.headers=Object.assign(Object.assign({},e.headers),t.headers)),r},m={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=>"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=!0)=>r?"string"==typeof e?C(e,t):f(e)?q(e,t):e:e,C=(e,t)=>{const r=T.exec(e);if(!r)return e;const a=r[1].trim(),i=r[2].split(",").map((e=>O(e.trim(),t)));return E(a,i,t)},q=(e,t)=>{if(s(e)||n(e))return e;const r=Object.entries(e),a=r.filter((([e])=>p(e))),i=r.filter((([e])=>!p(e))),o=a.reduce(((e,[r,a])=>e=Object.assign(Object.assign({},e),E(r,a,t))),{});return Object.assign(Object.assign({},o),Object.fromEntries(i))},E=(e,t,r)=>{const a=e.slice(1),i=l(a,b);return i?Array.isArray(t)?{operator:i,children:t}:f(t)&&!Object.keys(t).some((e=>p(e)))?Object.assign({operator:i},t):{operator:i,children:[t]}:a in r?{fragment:a,parameters:Object.assign({},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 j=e=>e instanceof S,A=({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},w=e=>f(e)&&"literal"in e,N=({value:e,name:t,expectedType:r})=>{if(w(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,x[r])(e)||L(t,e,r)},P=(...e)=>{const t=[];return e.forEach((e=>{const r=N(e);!0!==r&&t.push(r)})),!(t.length>0)||t.join("\n")},x={any:e=>void 0!==e,string:e=>"string"==typeof e,number:e=>"number"==typeof e,boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),null:e=>null===e,object:e=>f(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 d(t,50)},U=e=>{const t={};return e.forEach((e=>{e.aliases.forEach((r=>t[r]=e.name))})),t},R=(e,t)=>e.map((({name:e,required:r,type:a})=>{if(w(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}})),k=(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=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},_=e=>f(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,Q=(e,r,a=void 0)=>{const i=r?t(e,r,a):e;return Array.isArray(i)?i.map((e=>_(e))):r?null===i?null:_(i):i},H=e=>/^https?:\/\/.+/.test(e),M=(...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}),""),$=(e,t)=>i(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)}})),F=(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,i,o;const{options:u,operators:d,operatorAliases:p}=t;let v=(null==u?void 0:u.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const t=JSON.parse(e);return s(t)?t:e}catch(t){return e}})(e):e;v=O(v,null===(r=t.options)||void 0===r?void 0:r.fragments,!u.noShorthand),Array.isArray(v)&&(v=yield B(v,t));const y=s(v),g=n(v);if(u.evaluateFullObject&&!y&&!g)return h(yield z(v,t),t);if(!y&&!g)return u.supportDeprecatedValueNodes&&f(v)&&"value"in v?v.value:h(v,t);const{fallback:b}=v,T=null!==(a=null==u?void 0:u.returnErrorAsString)&&void 0!==a&&a;if(g){const[e,r]=yield B([v.fragment,v.parameters],t),a=O(null===(i=null==u?void 0:u.fragments)||void 0===i?void 0:i[e],u.fragments,!u.noShorthand);if(void 0===a)return A({fallback:yield F(b,t),error:`Fragment not defined: ${e}`,expression:v,returnErrorAsString:T});if(!s(a))return h(a,t);v=Object.assign(Object.assign(Object.assign({},v),a),r),delete v.fragment}const C=l(v.operator,p);if(!C)return A({fallback:yield F(b,t),error:`Invalid operator: ${v.operator}`,expression:v,returnErrorAsString:T});if(!t.operators[C])return A({fallback:yield F(b,t),error:`Excluded operator: ${v.operator}`,expression:v,returnErrorAsString:T});const{propertyAliases:q,evaluate:E,parseChildren:S}=d[C];v=((e,t)=>c(t,(t=>t in e?e[t]:t)))(q,v);const j=yield G(v,t);g||Object.entries(j).forEach((([e,r])=>t.resolvedAliasNodes[e]=r));const w=g?Object.assign(Object.assign({},t),{resolvedAliasNodes:Object.assign(Object.assign({},t.resolvedAliasNodes),j)}):t;if("children"in v){if(Array.isArray(v.children)||(v.children=yield F(v.children,w)),!Array.isArray(v.children))return A({fallback:yield F(b,t),operator:C,name:"Type Error",error:'- Property "children" is not of type: array',expression:v,returnErrorAsString:T});v=yield S(v,w),delete v.children}let N;try{N=yield E(v,w)}catch(e){return A({fallback:yield F(v.fallback,t),operator:C,error:e,expression:v,returnErrorAsString:T})}const P=null!==(o=null==v?void 0:v.outputType)&&void 0!==o?o:null==v?void 0:v.type;if(!P)return N;const x=yield F(P,t);return x in m?m[x](N):A({fallback:yield F(b,t),operator:C,error:`- Invalid output type: ${x}`,expression:v,returnErrorAsString:T})})),B=(e,t)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>F(e,t)))):yield F(e,t)})),G=(e,t)=>i(void 0,void 0,void 0,(function*(){const r=Object.keys(e).filter(p);if(0===r.length)return{};const a=[];return r.forEach((r=>a.push(F(e[r],t)))),k(r,yield Promise.all(a))})),z=(e,t)=>i(void 0,void 0,void 0,(function*(){if(!f(e))return e;const r=[],a=[];Object.entries(e).forEach((([r,i])=>{p(r)&&(a.push(r,F(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,F(a,t))}));const s=yield Promise.all(r);return h(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)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(V.parameters,{values:r})),r.reduce(((e,t)=>e&&!!t),!0)})),parseChildren:Y},K=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],Z=U(K),ee={description:"Logical OR",aliases:["or","|","||"],parameters:K},te={propertyAliases:Z,operatorData:ee,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(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,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(ie.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=t.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=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.every((e=>r(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,t)=>i(void 0,void 0,void 0,(function*(){var a,i,s;const[n,o,l]=yield B([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(R(le.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(i=null===(a=t.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=t.options)||void 0===s?void 0:s.nullEqualsUndefined)&&t.options.nullEqualsUndefined)||null!==u[0]&&void 0!==u[0]?u.some((e=>!r(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)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(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=>f(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}],me=U(ve),ye={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:ve},fe={propertyAliases:me,operatorData:ye,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i]=yield B([e.values,e.from,e.subtract],t);t.typeChecker(R(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: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)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);if(t.typeChecker(R(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),Ee={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Ce},Se={propertyAliases:qe,operatorData:Ee,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a,i,s]=yield B([e.values,e.dividend,e.divisor,e.output],t);t.typeChecker(R(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:Y},je=[{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(je),we={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:je},Ne={propertyAliases:Ae,operatorData:we,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(R(we.parameters,{values:r,strict:a})),r.length<2)throw new Error("- Not enough values provided");const[i,s]=r;return i===s&&!a||i>s})),parseChildren:Y},Pe=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array",default:[9,10]},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],xe=U(Pe),Le={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Pe},Ie={propertyAliases:xe,operatorData:Le,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a=!0]=yield B([e.values,e.strict],t);if(t.typeChecker(R(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"}],Re=U(Ue),ke={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ue},De={propertyAliases:Re,operatorData:ke,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(ke.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield F(e.condition,t))?yield F(e.valueIfTrue,t):yield F(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),He={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:_e},Me={propertyAliases:Qe,operatorData:He,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a]=yield B([e.testString,e.pattern],t);t.typeChecker(R(He.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})}},$e=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string",default:"path.to[0].my.data"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:"object",default:{}}],Fe=U($e),Be={description:"Extract values from data objects",aliases:["dataProperties","data","getData","objectProperties","objProps","getProperty","getObjProp"],parameters:$e},Ge={propertyAliases:Fe,operatorData:Be,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,i;const[s,n={}]=yield B([e.property,e.additionalData],r);r.typeChecker(R(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 t(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:["friend"]},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],We=U(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)=>i(void 0,void 0,void 0,(function*(){const[r,a={},i=!0,s="%",n={}]=yield B([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],t);if(t.typeChecker(R(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=k(Array.from(o),a.map((e=>i?String(e).trim():e)));return r.split(t).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}return r.split(/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g).map((e=>{if(!/(?<!\\){{(.+)}}/.exec(e))return e.replace("\\{{","{{");const r=Ye(e,a,n,t.options.data);return i?String(r).trim():r})).join("")})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{string:t,substitutions:r})}},Ye=(e,r,a,i={})=>{const s=e.replace(/{{(.+)}}/,"$1"),n=t(r,s,t(i,s,""));if("number"!=typeof n)return n;if(!(s in a))return n;const o=a[s];if(n in o)return o[n].replace("{}",String(n));const l=Object.keys(a[s]),u=l.find((e=>e.startsWith(">")));if(u){if(n>Number(u.slice(1)))return null==o?void 0:o[u]}const d=l.find((e=>e.startsWith("<")));if(d){if(n<Number(d.slice(1)))return null==o?void 0:o[d]}return o.other?o.other.replace("{}",String(n)):n},Xe=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Ke=U(Xe),Ze={description:"Count elements in an array",aliases:["count","length"],parameters:Xe},et={propertyAliases:Ke,operatorData:Ze,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){const r=yield B(e.values,t);return t.typeChecker(R(Ze.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)=>i(void 0,void 0,void 0,(function*(){var r,a,i;const[s,n,o,l]=yield B([e.value,null!==(r=e.delimiter)&&void 0!==r?r:it,null===(a=e.trimWhiteSpace)||void 0===a||a,null===(i=e.excludeTrailing)||void 0===i||i],t);t.typeChecker(R(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)=>i(void 0,void 0,void 0,(function*(){var r,a,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(R(lt.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(s=null!==(a=e.useCache)&&void 0!==a?a:t.options.useCache)||void 0===s||s;{const e=t.cache.useCache(h,((e,t,r,a,s)=>i(void 0,void 0,void 0,(function*(){const i=(yield n.query({query:e,values:t}))||[];["array","string","number"].includes(null!=s?s:"")&&(a=!0);const o=a?i.map((e=>{const t=Object.values(e);return t.length<=1?t[0]:t})):i;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)=>i(void 0,void 0,void 0,(function*(){var r,a,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,m,y]=yield B([e.query,e.url,e.variables,e.returnNode,e.headers,e.useCache],t),{url:f,headers:g}=p instanceof Object?p:{url:p,headers:null};t.typeChecker([...R(pt.parameters,{url:f,query:c,variables:h,returnNode:v,headers:m,useCache:y}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=f&&"graphqlendpoint"!==f.toLowerCase()?f:"",T=null!==(n=null!==(s=null===(a=t.options.graphQLConnection)||void 0===a?void 0:a.endpoint)&&void 0!==s?s:t.options.baseEndpoint)&&void 0!==n?n:"",O=H(b)?b:M(T,b),C={query:c,variables:h},q=null===(o=null!=y?y:t.options.useCache)||void 0===o||o,E=yield t.cache.useCache(q,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield $(d,{url:e,method:"post",data:t,headers:r});return Q(null==i?void 0:i.data,a)}))),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),m),v);return E})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,a="",i,...s]=yield B(e.children,t),n=Array.isArray(i)?i:[i],o=s.slice(0,n.length),l=k(n,o),u=Object.assign(Object.assign({},e),{query:r,url:a,variables:l});return s.length>n.length&&(u.returnNode=s.pop()),u}))},vt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://restcountries.com/v3.1/name/zealand"},{name:"returnProperty",description:"Property from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"Query parameters (key-value)",aliases:["queryParams","queryParameters","urlQueries"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],mt=U(vt),yt={description:"HTTP GET Request",aliases:["get","api"],parameters:vt},ft=(e,t)=>i(void 0,void 0,void 0,(function*(){const[r="",a,...i]=yield B(e.children,t),s=Array.isArray(a)?a:[a],n=i.slice(0,s.length),o=k(s,n),l=Object.assign(Object.assign({},e),{url:r,parameters:o});return i.length>s.length&&(l.returnProperty=i.pop()),l})),gt=ft,bt={propertyAliases:mt,operatorData:yt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield B([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...R(yt.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:"",m=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),h),d),y=null===(s=null!=c?c:t.options.useCache)||void 0===s||s,f=yield t.cache.useCache(y,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield $(n,{url:e,params:t,headers:r});return Q(i,a)}))),H(p)?p:M(v,p),l,m,u);return f})),parseChildren:ft},Tt=[{name:"url",description:"Endpoint URL",aliases:["endpoint"],required:!0,type:"string",default:"https://jsonplaceholder.typicode.com/posts"},{name:"returnProperty",description:"Property path from request result",aliases:["outputProperty"],required:!1,type:"string",default:"result.path"},{name:"headers",description:"HTTP Headers",aliases:[],required:!1,type:"object",default:{}},{name:"parameters",description:"JSON Body parameters (key-value)",aliases:["bodyJson","data"],required:!1,type:"object",default:{}},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!0}],Ot=U(Tt),Ct={description:"HTTP POST Request",aliases:["post"],parameters:Tt},qt={propertyAliases:Ot,operatorData:Ct,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r,a,s;const n=t.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield B([e.url,e.parameters,e.returnProperty,e.headers,e.useCache],t),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};t.typeChecker([...R(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:"",m=Object.assign(Object.assign(Object.assign({},null===(a=t.options)||void 0===a?void 0:a.headers),h),d),y=null!==(s=null!=c?c:t.options.useCache)&&void 0!==s&&s,f=yield t.cache.useCache(y,((e,t,r,a)=>i(void 0,void 0,void 0,(function*(){const i=yield $(n,{url:e,data:t,headers:r,method:"post"});return Q(i,a)}))),H(p)?p:M(v,p),l,m,u);return f})),parseChildren:gt},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=U(Et),jt={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:Et},At={propertyAliases:St,operatorData:jt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){t.typeChecker(R(jt.parameters,{properties:e.properties}));const r=e.properties.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:r})=>{return a=[e,r],i(void 0,void 0,void 0,(function*(){const[e,r]=yield B(a,t);return t.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,r]}));var a}));return Object.fromEntries(yield Promise.all(r))})),parseChildren:e=>{const t=e.children;if(t.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=t.filter(((e,t)=>t%2==0)),a=t.filter(((e,t)=>t%2==1)),i=r.map(((e,t)=>({key:e,value:a[t]})));return Object.assign(Object.assign({},e),{properties:i})}},wt=[{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(wt),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:wt},evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var r;const a=yield F(e.matchExpression,t);t.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const i=Array.isArray(e.branches)?D(e.branches):null!==(r=e.branches)&&void 0!==r?r:{},n=s(i)?yield F(i,t):i;if(!f(n))throw new Error("Branches don't evaluate to an object");if(a in n)return yield F(n[a],t);if("fallback"in n)return yield F(n.fallback,t);if(a in e)return yield F(e[a],t);throw new Error(`No match found for ${a}`)})),parseChildren:(e,t)=>i(void 0,void 0,void 0,(function*(){const[r,...a]=e.children,i=D(yield B(a,t));return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}))},Pt=[{name:"functionPath",description:"Path (in options.functions) to the required function",aliases:["functionsPath","functionName","funcName","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:"array",default:[]},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],xt=U(Pt),Lt={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:Pt},It={propertyAliases:xt,operatorData:Lt,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var a,s,n;const[o,l=[],u]=yield B([e.functionPath,e.args,e.useCache],r);r.typeChecker(R(Lt.parameters,{functionPath:o,args:l}));const{data:d,functions:c}=r.options,p=null!==(s=null!==(a=t(c,o,null))&&void 0!==a?a:t(d,o,null))&&void 0!==s?s:t(r.options,o,null);if(!p||"function"!=typeof p)throw new Error(`- No function found: "${o}"`);const h=null!==(n=null!=u?u:r.options.useCache)&&void 0!==n&&n;return yield r.cache.useCache(h,((e,...t)=>i(void 0,void 0,void 0,(function*(){return yield p(...t)}))),o,...l)})),parseChildren:e=>{const[t,...r]=e.children;return Object.assign(Object.assign({},e),{functionPath:t,args:r})}},Ut=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Rt=U(Ut),kt={description:"Pass through a value unchanged (or change its type)",aliases:["_","passThru","passthru","pass","ignore","coerce","convert"],parameters:Ut},Dt={propertyAliases:Rt,operatorData:kt,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){return t.typeChecker(R(kt.parameters,{value:e.value})),yield F(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:Se,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:Me,SPLIT:st,SQL:ut,STRING_SUBSTITUTION:Ve,SUBTRACT:fe});class Qt{constructor(e){var t,r;this.useCache=(e,t,...r)=>i(this,void 0,void 0,(function*(){if(!e)return yield t(...r);const a=Ht(r),i=a in this.store,s=Date.now(),n=i&&s-this.store[a].timestamp>1e3*this.maxTime;if(i)return this.queue=this.queue.filter((e=>e!==a)),this.queue.unshift(a),this.store[a].timestamp=s,n&&(this.store[a].result=yield t(...r)),this.store[a].result;const o=yield t(...r);return this.store[a]={result:o,timestamp:s},this.queue.unshift(a),this.resizeCache(),o})),this.getMax=()=>this.maxSize,this.setMax=e=>{this.maxSize=e,this.resizeCache()},this.getMaxTime=()=>this.maxTime,this.setMaxTime=e=>{this.maxTime=e},this.getCache=()=>this.store,this.setCache=e=>this.store=e,this.resizeCache=()=>{if(this.queue.length>this.maxSize){this.queue.slice(this.maxSize).forEach((e=>delete this.store[e])),this.queue=this.queue.slice(0,this.maxSize)}},this.store={},this.queue=[],this.maxSize=null!==(t=null==e?void 0:e.maxSize)&&void 0!==t?t:50,this.maxTime=null!==(r=null==e?void 0:e.maxTime)&&void 0!==r?r:1800}}const Ht=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),Mt=e=>e?"name"in e&&"fetch"===e.name?Ft(e):"Axios"in e&&"Axios"===e.Axios.name?$t(e):e:"undefined"!=typeof window&&"document"in window&&"fetch"in window?Ft(window.fetch):void 0,$t=e=>({get:t=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},t),{method:"get"}))).data})),post:t=>i(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))}}),Ft=e=>({get:t=>i(void 0,void 0,void 0,(function*(){const{url:r,headers:i,params:s={}}=t,n=Object.keys(s).length>0?`?${a.stringify(s)}`:"",o=yield e(r+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=>i(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=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.16.1",this.options=zt(e),this.operators=u(_t,null!==(r=null===(t=this.options)||void 0===t?void 0:t.excludeOperators)&&void 0!==r?r:[],g),this.operatorAliases=g,this.cache=new Qt({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime}),this.graphQLClient=Mt(null===(a=e.graphQLConnection)||void 0===a?void 0:a.httpClient),this.httpClient=Mt(e.httpClient)}evaluate(e,t={}){var r;return i(this,void 0,void 0,(function*(){const a=v(this.options,zt(t));return t.httpClient&&(this.httpClient=Mt(t.httpClient)),(null===(r=t.graphQLConnection)||void 0===r?void 0:r.httpClient)&&(this.graphQLClient=Mt(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 F(e,{options:a,operators:t.excludeOperators?u(_t,t.excludeOperators,g):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,zt(e)),this.options.excludeOperators&&(this.operators=u(_t,this.options.excludeOperators,g))}getOperators(){const e=this.options.excludeOperators?u(_t,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])=>({name:e,numRequiredArgs:t.length})))}}const Gt=(e,t)=>new Bt(t).evaluate(e),zt=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e,Wt=e=>({query:({query:t,values:r=[]})=>i(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}}))}),Jt=e=>({query:({query:t,values:r=[]})=>i(void 0,void 0,void 0,(function*(){try{return yield e.all(t,r)}catch(e){throw e.name="SQLite error",e}}))});export{$t as AxiosClient,Ft as FetchClient,S as FigTreeError,Bt as FigTreeEvaluator,Wt as SQLNodePostgres,Jt as SQLite,Gt as evaluateExpression,p as isAliasString,j as isFigTreeError,n as isFragmentNode,f as isObject,s as isOperatorNode,O as preProcessShorthand,o as standardiseOperatorName,d as truncateString};
|