fig-tree-evaluator 2.21.2 → 2.21.4
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/CHANGELOG.md +86 -0
- package/README.md +1 -71
- package/build/index.cjs.js +1 -1
- package/build/index.esm.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
The format below (from v2.21.4 onwards) is loosely based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## [2.21.4] - 2026-06-28
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Compile bundle to ES2020 (from ES2015). Eliminates the `tslib` runtime helpers that were ~13% of the bundle, reducing it by ~7% gzipped. Minimum supported runtime is now ES2020 (Node 14+, evergreen browsers).
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Shorthand conversion (`convertToShorthand`) of `getData`/`objectProperties` nodes that include an `additionalData` parameter. Previously this produced a malformed, deeply-nested array instead of a named-property object.
|
|
14
|
+
|
|
15
|
+
## Earlier versions
|
|
16
|
+
|
|
17
|
+
*Trivial upgrades (e.g. documentation, small re-factors, types, etc.) not included*
|
|
18
|
+
|
|
19
|
+
- **v2.21.0**: Use default parameter values for Fragments if not provided in expression
|
|
20
|
+
- **v2.20.6**: Fix certain `parseChildren` methods to not evaluate while parsing
|
|
21
|
+
- **v2.20.0**:
|
|
22
|
+
- Add helper scripts to convert V1 to V2 expressions, and to and from Shorthand syntax -- used in [FigTree Editor](https://github.com/CarlosNZ/fig-tree-editor-react) tool.
|
|
23
|
+
- Small tweaks to `buildObject` and `match` operators to make them a little more consistent in their behaviour.
|
|
24
|
+
- **v2.19.0**: *Remove* "string" shorthand syntax (technically a breaking change, but I doubt anyone is affected by this) #124
|
|
25
|
+
- **v2.18.0**: Prevent HTTP clients from being bundled with main package
|
|
26
|
+
- **v2.17.0**: Allow Custom Functions to be expressed as Custom Operators
|
|
27
|
+
- **v2.16.10**: Fix for when aliases reference other aliases at the same level
|
|
28
|
+
- **v2.16.8**: Don't deep merge fragments, data, headers and functions when using `.updateOptions()`
|
|
29
|
+
- **v2.16.5**: Make sure all parameters that are objects get pre-evaluated, even when
|
|
30
|
+
`evaluateFullObject` is off.
|
|
31
|
+
- **v2.16.0**: Standardise error response (see [Error handling](#error-handling))
|
|
32
|
+
- **v2.15.0**:
|
|
33
|
+
- Remove `axios` package dependency and create HTTP client abstraction (with built-in wrappers for `axios` and `fetch`). *Results in significantly smaller bundle size.*
|
|
34
|
+
- Generalise `PG_SQL` operator to a client-agnostic `SQL` operator (with built-in abstractions for `node-postgres` and `SQLite`)
|
|
35
|
+
- ***Breaking changes*** as a result of the above: SQL client and HTTP client must be specified differently. See relevant operator details.
|
|
36
|
+
- Changes to `SQL` parameters to reflect the aforementioned agnosticism.
|
|
37
|
+
- **v2.14.0**: Improvements to `stringSubstitution` operator:
|
|
38
|
+
- Can accept nested property references (e.g. `{{user.name}}`)
|
|
39
|
+
- Will also search for replacements from `data` object
|
|
40
|
+
- **v2.13.4**: Bug fix for `objectProperties` operator when array index larger than `9` is used, and for sequential array indexes (e.g. `prop[1][2]`)
|
|
41
|
+
- **v2.13.0**: Add default values to operator properties, export more types and helper methods
|
|
42
|
+
- **v2.12.0**: Add `caseInsensitive` option to equality/non-equality operators
|
|
43
|
+
- **v2.11.5**: Upgrade dependencies
|
|
44
|
+
- **v2.11.4**: Bundle target ES6
|
|
45
|
+
- **v2.11.0**: Improved package bundling (bundle size ~50%), with CommonJS and ESM outputs. Note: small **breaking change**: "FigTreeEvaluator" is no longer a default export, so need to import with: `import { FigTreeEvaluator } from 'fig-tree-evaluator'`
|
|
46
|
+
- **v2.10.0**: Extended stringSubstitution functionality to included named
|
|
47
|
+
property substitution, trim whitespace option, and pluralisation (#97)
|
|
48
|
+
- **v2.9.0**: Added ability to invalidate cache by time (#94)
|
|
49
|
+
- **v2.8.6**: Small bug fix where `options` object would be mutated instead of replaced
|
|
50
|
+
- **v2.8.5**: Small bug fix in [COUNT](#count) operator
|
|
51
|
+
- **v2.8.4**: Refactor types, better compliance with [ESLint](https://eslint.org/) rules, add more tests
|
|
52
|
+
- **v2.8.0**:
|
|
53
|
+
- **[Shorthand syntax](#shorthand-syntax)** (#80)
|
|
54
|
+
- **Methods to retrieve [metadata](#metadata)** about operators, fragments and
|
|
55
|
+
functions (#82)
|
|
56
|
+
- **v2.7.0**: **Add `excludeOperators` option** to allow certain operators to be
|
|
57
|
+
prohibited (e.g. database lookups) (#54)
|
|
58
|
+
- **v2.6.0**: Resolve alias nodes that are not part of an Operator node when `evaluateFullObject` is enabled (#78)
|
|
59
|
+
- **v2.5.0**:
|
|
60
|
+
- Bug fixes for edge cases (mainly related to backwards compatibility)
|
|
61
|
+
- More backwards compatibility for very old (pre-v1) syntax (undocumented)
|
|
62
|
+
- **v2.4.1**: Small bug fix for Fragments edge case
|
|
63
|
+
- **v2.4.0**: **Implement [Fragments](#fragments)** (#74)
|
|
64
|
+
- **v2.3.2**: Bug fix: alias nodes not working with `evaluateFullObject` (#72)
|
|
65
|
+
- **v2.3.0**: **Implement [caching/memoization](#caching-memoization)** (#68)
|
|
66
|
+
- **v2.2.3**: Change option `objects` name to `data` (but keep backward compatibility) (#66)
|
|
67
|
+
- **v2.2.2**: **Option to evaluate whole object** if operator nodes are deep within it (#64)
|
|
68
|
+
- **v2.2.1**: More efficient branch evaluation for condition/match operators (#63)
|
|
69
|
+
- **v2.2.0**:
|
|
70
|
+
- **New "[Match](#match)" operator** (#61)
|
|
71
|
+
- Fix for regex incompatibility with Safari (#60)
|
|
72
|
+
- **v2.1.4**: Upgrade dependencies
|
|
73
|
+
- **v2.1.0**: **[Alias nodes](#alias-nodes)** (#57)
|
|
74
|
+
- **v2.0.4**: Backwards compatibility for customFunctions (#53)
|
|
75
|
+
- **v2.0.1**: **Add deep equality comparison** for objects/arrays in `=`/`!=` operators
|
|
76
|
+
- **v2.0.0**: Re-write as stand-alone package. Major improvements include:
|
|
77
|
+
- more [operators](#operator-reference)
|
|
78
|
+
- operator (and property) [aliases](#operator--property-aliases)
|
|
79
|
+
- more appropriately-named properties associated with each operator (as
|
|
80
|
+
opposed to a single `children` array)
|
|
81
|
+
- class-based Evaluator instances
|
|
82
|
+
- runtime type-checking
|
|
83
|
+
- better error handling and error reporting
|
|
84
|
+
- more flexible output conversion
|
|
85
|
+
- more well-organised codebase
|
|
86
|
+
- **v1.x.x**: created specifically for [Conforma](https://github.com/openmsupply/conforma-server/wiki/Query-Syntax) application manager by [mSupplyFoundation](https://github.com/openmsupply). v2 is a complete re-write with numerous improvements, but should be 99% backwards compatible.
|
package/README.md
CHANGED
|
@@ -2124,77 +2124,7 @@ Please open an issue: https://github.com/CarlosNZ/fig-tree-evaluator/issues
|
|
|
2124
2124
|
|
|
2125
2125
|
## Changelog
|
|
2126
2126
|
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
- **v2.21.0**: Use default parameter values for Fragments if not provided in expression
|
|
2131
|
-
- **v2.20.6**: Fix certain `parseChildren` methods to not evaluate while parsing
|
|
2132
|
-
- **v2.20.0**:
|
|
2133
|
-
- Add helper scripts to convert V1 to V2 expressions, and to and from Shorthand syntax -- used in [FigTree Editor](https://github.com/CarlosNZ/fig-tree-editor-react) tool.
|
|
2134
|
-
- Small tweaks to `buildObject` and `match` operators to make them a little more consistent in their behaviour.
|
|
2135
|
-
- **v2.19.0**: *Remove* "string" shorthand syntax (technically a breaking change, but I doubt anyone is affected by this) #124
|
|
2136
|
-
- **v2.18.0**: Prevent HTTP clients from being bundled with main package
|
|
2137
|
-
- **v2.17.0**: Allow Custom Functions to be expressed as Custom Operators
|
|
2138
|
-
- **v2.16.10**: Fix for when aliases reference other aliases at the same level
|
|
2139
|
-
- **v2.16.8**: Don't deep merge fragments, data, headers and functions when using `.updateOptions()`
|
|
2140
|
-
- **v2.16.5**: Make sure all parameters that are objects get pre-evaluated, even when
|
|
2141
|
-
`evaluateFullObject` is off.
|
|
2142
|
-
- **v2.16.0**: Standardise error response (see [Error handling](#error-handling))
|
|
2143
|
-
- **v2.15.0**:
|
|
2144
|
-
- Remove `axios` package dependency and create HTTP client abstraction (with built-in wrappers for `axios` and `fetch`). *Results in significantly smaller bundle size.*
|
|
2145
|
-
- Generalise `PG_SQL` operator to a client-agnostic `SQL` operator (with built-in abstractions for `node-postgres` and `SQLite`)
|
|
2146
|
-
- ***Breaking changes*** as a result of the above: SQL client and HTTP client must be specified differently. See relevant operator details.
|
|
2147
|
-
- Changes to `SQL` parameters to reflect the aforementioned agnosticism.
|
|
2148
|
-
- **v2.14.0**: Improvements to `stringSubstitution` operator:
|
|
2149
|
-
- Can accept nested property references (e.g. `{{user.name}}`)
|
|
2150
|
-
- Will also search for replacements from `data` object
|
|
2151
|
-
- **v2.13.4**: Bug fix for `objectProperties` operator when array index larger than `9` is used, and for sequential array indexes (e.g. `prop[1][2]`)
|
|
2152
|
-
- **v2.13.0**: Add default values to operator properties, export more types and helper methods
|
|
2153
|
-
- **v2.12.0**: Add `caseInsensitive` option to equality/non-equality operators
|
|
2154
|
-
- **v2.11.5**: Upgrade dependencies
|
|
2155
|
-
- **v2.11.4**: Bundle target ES6
|
|
2156
|
-
- **v2.11.0**: Improved package bundling (bundle size ~50%), with CommonJS and ESM outputs. Note: small **breaking change**: "FigTreeEvaluator" is no longer a default export, so need to import with: `import { FigTreeEvaluator } from 'fig-tree-evaluator'`
|
|
2157
|
-
- **v2.10.0**: Extended stringSubstitution functionality to included named
|
|
2158
|
-
property substitution, trim whitespace option, and pluralisation (#97)
|
|
2159
|
-
- **v2.9.0**: Added ability to invalidate cache by time (#94)
|
|
2160
|
-
- **v2.8.6**: Small bug fix where `options` object would be mutated instead of replaced
|
|
2161
|
-
- **v2.8.5**: Small bug fix in [COUNT](#count) operator
|
|
2162
|
-
- **v2.8.4**: Refactor types, better compliance with [ESLint](https://eslint.org/) rules, add more tests
|
|
2163
|
-
- **v2.8.0**:
|
|
2164
|
-
- **[Shorthand syntax](#shorthand-syntax)** (#80)
|
|
2165
|
-
- **Methods to retrieve [metadata](#metadata)** about operators, fragments and
|
|
2166
|
-
functions (#82)
|
|
2167
|
-
- **v2.7.0**: **Add `excludeOperators` option** to allow certain operators to be
|
|
2168
|
-
prohibited (e.g. database lookups) (#54)
|
|
2169
|
-
- **v2.6.0**: Resolve alias nodes that are not part of an Operator node when `evaluateFullObject` is enabled (#78)
|
|
2170
|
-
- **v2.5.0**:
|
|
2171
|
-
- Bug fixes for edge cases (mainly related to backwards compatibility)
|
|
2172
|
-
- More backwards compatibility for very old (pre-v1) syntax (undocumented)
|
|
2173
|
-
- **v2.4.1**: Small bug fix for Fragments edge case
|
|
2174
|
-
- **v2.4.0**: **Implement [Fragments](#fragments)** (#74)
|
|
2175
|
-
- **v2.3.2**: Bug fix: alias nodes not working with `evaluateFullObject` (#72)
|
|
2176
|
-
- **v2.3.0**: **Implement [caching/memoization](#caching-memoization)** (#68)
|
|
2177
|
-
- **v2.2.3**: Change option `objects` name to `data` (but keep backward compatibility) (#66)
|
|
2178
|
-
- **v2.2.2**: **Option to evaluate whole object** if operator nodes are deep within it (#64)
|
|
2179
|
-
- **v2.2.1**: More efficient branch evaluation for condition/match operators (#63)
|
|
2180
|
-
- **v2.2.0**:
|
|
2181
|
-
- **New "[Match](#match)" operator** (#61)
|
|
2182
|
-
- Fix for regex incompatibility with Safari (#60)
|
|
2183
|
-
- **v2.1.4**: Upgrade dependencies
|
|
2184
|
-
- **v2.1.0**: **[Alias nodes](#alias-nodes)** (#57)
|
|
2185
|
-
- **v2.0.4**: Backwards compatibility for customFunctions (#53)
|
|
2186
|
-
- **v2.0.1**: **Add deep equality comparison** for objects/arrays in `=`/`!=` operators
|
|
2187
|
-
- **v2.0.0**: Re-write as stand-alone package. Major improvements include:
|
|
2188
|
-
- more [operators](#operator-reference)
|
|
2189
|
-
- operator (and property) [aliases](#operator--property-aliases)
|
|
2190
|
-
- more appropriately-named properties associated with each operator (as
|
|
2191
|
-
opposed to a single `children` array)
|
|
2192
|
-
- class-based Evaluator instances
|
|
2193
|
-
- runtime type-checking
|
|
2194
|
-
- better error handling and error reporting
|
|
2195
|
-
- more flexible output conversion
|
|
2196
|
-
- more well-organised codebase
|
|
2197
|
-
- **v1.x.x**: created specifically for [Conforma](https://github.com/openmsupply/conforma-server/wiki/Query-Syntax) application manager by [mSupplyFoundation](https://github.com/openmsupply). v2 is a complete re-write with numerous improvements, but should be 99% backwards compatible.
|
|
2127
|
+
See [here](https://github.com/CarlosNZ/fig-tree-evaluator/blob/main/CHANGELOG.md)
|
|
2198
2128
|
|
|
2199
2129
|
## Credit
|
|
2200
2130
|
Icon: Tree by ka reemov from <a href="https://thenounproject.com/icon/tree-2665898/" target="_blank" title="Tree Icon">Noun Project</a>
|
package/build/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("object-property-extractor"),r=require("dequal/lite");function t(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&r.indexOf(i)<0&&(t[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(i=Object.getOwnPropertySymbols(e);a<i.length;a++)r.indexOf(i[a])<0&&Object.prototype.propertyIsEnumerable.call(e,i[a])&&(t[i[a]]=e[i[a]])}return t}function i(e,r,t,i){return new(t||(t=Promise))((function(a,s){function n(e){try{l(i.next(e))}catch(e){s(e)}}function o(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var r;e.done?a(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(n,o)}l((i=i.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const a=e=>e instanceof Object&&"operator"in e,s=e=>e instanceof Object&&"fragment"in e,n=e=>{const r=m(e);return r||e},o=(e,r)=>r[n(e)],l=(e,r,t)=>{const i=Object.assign({},e);return r.forEach((e=>{t[n(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete i[t[n(e)]]})),i},u=(e,r=200)=>e.length<r?e:`${e.slice(0,r-2).trim()}...`,d=(e,r)=>{const t=Object.entries(e).map((([e,t])=>[r(e),t]));return Object.fromEntries(t)},c=e=>/^\$.+/.test(e),p=(e,{resolvedAliasNodes:r})=>{var t;return"string"==typeof e&&c(e)&&null!==(t=null==r?void 0:r[e])&&void 0!==t?t:e},h=(e,r,t)=>{const i=Object.assign(Object.assign({},e),r);return t?((e.data||r.data)&&(i.data=Object.assign(Object.assign({},e.data),r.data)),(e.functions||r.functions)&&(i.functions=Object.assign(Object.assign({},e.functions),r.functions)),(e.fragments||r.fragments)&&(i.fragments=Object.assign(Object.assign({},e.fragments),r.fragments)),(e.headers||r.headers)&&(i.headers=Object.assign(Object.assign({},e.headers),r.headers)),i):i},v={number:e=>f(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const r=new RegExp(/-?\d*\.?\d+/gm),t=e.match(r);return t?Number(t[0]):0},m=e=>e.replace(/[^A-Za-z\d _-]/g,"").split(/[-_ ]/).map((e=>{var r;return null!==(r=e.match(/[a-z]+|[A-Z]+[a-z]*/g))&&void 0!==r?r:e})).flat().filter((e=>""!==e)).map(((e,r)=>0===r?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""),y=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",notEqual:"NOT_EQUAL","!":"NOT_EQUAL",ne:"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",getData:"OBJECT_PROPERTIES",dataProperties:"OBJECT_PROPERTIES",data:"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",get:"GET",api:"GET",POST:"POST",post:"POST",sql:"SQL",pgSql:"SQL",postgres:"SQL",pg:"SQL",sqLite:"SQL",sqlite:"SQL",mySql:"SQL",graphQL:"GRAPHQL",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",pass:"PASSTHRU",_:"PASSTHRU",passThru:"PASSTHRU",passthru:"PASSTHRU",ignore:"PASSTHRU",coerce:"PASSTHRU",convert:"PASSTHRU"},b=g,O=(e,r={},t,i=!0)=>i&&y(e)?T(e,r,t):e,T=(e,r,t)=>{if(a(e)||s(e))return e;const i=Object.entries(e),n=i.filter((([e])=>c(e))),o=i.filter((([e])=>!c(e))),l=n.reduce(((e,[i,a])=>e=Object.assign(Object.assign({},e),j(i,a,r,t))),{});return Object.assign(Object.assign({},l),Object.fromEntries(o))},j=(e,r,t,i)=>{const a=e.slice(1),s=o(a,b);return s?Array.isArray(r)?{operator:s,children:r}:y(r)&&!Object.keys(r).some((e=>c(e)))?Object.assign({operator:s},r):{operator:s,children:[r]}:a in t?{fragment:a,parameters:Object.assign({},r)}:i.includes(a)?Array.isArray(r)?{operator:a,args:r}:y(r)?"input"in r||"args"in r?Object.assign({operator:a},r):{operator:a,input:r}:{operator:a,args:[r]}:{[e]:r}};class C extends Error{constructor(e,r,t,i){super(e.message),Object.assign(this,e),this.operator=r,this.expression=i,this.errorData=e.errorData,t&&(this.name=t),"Error"===this.name&&(this.name="FigTreeError");const a=(r?"Operator: "+r:"")+("FigTreeError"===this.name?"":` - ${this.name}`),s=this.errorData?"\n"+JSON.stringify(this.errorData,null,2):"";this.prettyPrint=`${""!==a?a+"\n":""}${this.message}${"\n{}"===s?"":s}`}}const E=({fallback:e,operator:r,name:t,error:i,expression:a,returnErrorAsString:s=!1})=>{if(void 0!==e)return e;if(i instanceof C){if(!s)throw i;return i.prettyPrint}const n=new C("string"==typeof i?new Error(i):i,r,t,a);if(s)return n.prettyPrint;throw n},S=e=>y(e)&&"literal"in e,A=({value:e,name:r,expectedType:t})=>{if(S(t)){const{literal:i}=t;return!!i.includes(e)||x(r,e,`Literal(${i.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(t))return!!t.some((t=>!0===A({value:e,name:r,expectedType:t})))||x(r,e,t.join("|"));return!!(0,w[t])(e)||x(r,e,t)},q=(...e)=>{const r=[];return e.forEach((e=>{const t=A(e);!0!==t&&r.push(t)})),!(r.length>0)||r.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=>y(e),undefined:e=>void 0===e},x=(e,r,t)=>void 0===r&&e?`- Missing required property "${e}" (type: ${t})`:void 0!==e?`- Property "${e}" (value: ${N(r)}) is not of type: ${t}`:`- ${N(r)} is not of type: ${t}`,N=e=>{const r=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return u(r,50)},P=e=>{const r={};return e.forEach((e=>{e.aliases.forEach((t=>r[t]=e.name))})),r},L=(e,r)=>e.map((({name:e,required:t,type:i})=>{if(S(i)){const a=[...i.literal];return t||a.push(void 0),{name:e,value:r[e],expectedType:{literal:a}}}const a=Array.isArray(i)?i:[i];t||a.push("undefined");const s=1===a.length?a[0]:a;return{name:e,value:r[e],expectedType:s}})),k=(e,r)=>{const t=e.map(((e,t)=>[e,r[t]]));return Object.fromEntries(t)},I=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=e.filter(((e,r)=>r%2==0)),t=q(...r.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==t)throw new Error(t);const i=e.filter(((e,r)=>r%2==1)),a={};return r.forEach(((e,r)=>{a[e]=i[r]})),a},U=e=>y(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,R=(r,t,i=void 0)=>{const a=t?e(r,t,i):r;return Array.isArray(a)?a.map((e=>U(e))):t?null===a?null:U(a):a},D=e=>/^https?:\/\/.+/.test(e),Q=(...e)=>e.reduce(((e,r,t)=>{const i="/"===r[0]?1:0,a="/"===r.slice(-1)?-1:void 0,s=r.slice(i,a);return""===s?e:e+(0===t?"":"/")+s}),""),_=(e,r)=>i(void 0,void 0,void 0,(function*(){const{url:t,params:i={},data:a={},headers:s={},method:n="get"}=r;if(!t||""===t)throw new Error("Invalid url");try{return yield e[n]({url:t,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},s),params:i,data:a})}catch(r){e.throwError(r)}})),F=(e,r)=>i(void 0,void 0,void 0,(function*(){var n,l,u,c,h,f,m,g,b,T;const{options:j,operators:C,operatorAliases:S}=r;let A=(null==j?void 0:j.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const r=JSON.parse(e);return a(r)?r:e}catch(r){return e}})(e):e;const q=Object.keys(null!==(l=null===(n=r.options)||void 0===n?void 0:n.functions)&&void 0!==l?l:{});A=O(A,null===(u=r.options)||void 0===u?void 0:u.fragments,q,!j.noShorthand),Array.isArray(A)&&(A=yield $(A,r));const w=a(A),x=s(A);if(w&&(A=yield((e,r)=>i(void 0,void 0,void 0,(function*(){var i,a;if(!(e.operator in(null!==(a=null===(i=r.options)||void 0===i?void 0:i.functions)&&void 0!==a?a:{})))return e;const{operator:s,fallback:n,outputType:o,type:l,useCache:u,input:d,args:c}=e,p=t(e,["operator","fallback","outputType","type","useCache","input","args"]),h={operator:"CUSTOM_FUNCTIONS",function:s};return void 0!==n&&(h.fallback=n),void 0!==o&&(h.outputType=o),void 0!==l&&(h.type=l),void 0!==u&&(h.useCache=u),void 0!==c&&(h.args=c),void 0!==d?h.input=d:Object.keys(p).length>0&&(h.input=p),h})))(A,r)),j.evaluateFullObject&&!w&&!x)return p(yield H(A,r),r);if(!w&&!x)return j.supportDeprecatedValueNodes&&y(A)&&"value"in A?A.value:p(A,r);const{fallback:N}=A,P=null!==(c=null==j?void 0:j.returnErrorAsString)&&void 0!==c&&c;if(x){const e=Object.assign({},A),t=null===(g=null===(m=null===(f=null===(h=null==j?void 0:j.fragments)||void 0===h?void 0:h[e.fragment])||void 0===f?void 0:f.metadata)||void 0===m?void 0:m.parameters)||void 0===g?void 0:g.filter((e=>void 0!==e.default));void 0===e.parameters&&(e.parameters={}),null==t||t.forEach((r=>{var t;void 0===(null===(t=e.parameters)||void 0===t?void 0:t[r.name])&&void 0===(null==e?void 0:e[r.name])&&(e.parameters[r.name]=r.default)}));const[i,s]=yield $([e.fragment,e.parameters],r),n=O(null===(b=null==j?void 0:j.fragments)||void 0===b?void 0:b[i],j.fragments,q,!j.noShorthand);if(void 0===n)return E({fallback:yield F(N,r),error:`Fragment not defined: ${i}`,expression:A,returnErrorAsString:P});if(!a(n))return p(n,r);A=Object.assign(Object.assign(Object.assign({},e),n),s),delete A.fragment}const L=A,k=o(L.operator,S);if(!k)return E({fallback:yield F(N,r),error:`Invalid operator: ${L.operator}`,expression:A,returnErrorAsString:P});if(!r.operators[k])return E({fallback:yield F(N,r),error:`Excluded operator: ${L.operator}`,expression:A,returnErrorAsString:P});const{propertyAliases:I,evaluate:U,parseChildren:R}=C[k];let D=((e,r)=>d(r,(r=>r in e?e[r]:r)))(I,L);const Q=yield M(D,r);x||Object.entries(Q).forEach((([e,t])=>r.resolvedAliasNodes[e]=t));const _=x?Object.assign(Object.assign({},r),{resolvedAliasNodes:Object.assign(Object.assign({},r.resolvedAliasNodes),Q)}):r;if("children"in D){if(Array.isArray(D.children)||(D.children=yield F(D.children,_)),!Array.isArray(D.children))return E({fallback:yield F(N,r),operator:k,name:"Type Error",error:'- Property "children" is not of type: array',expression:A,returnErrorAsString:P});try{D=yield R(D,_),delete D.children}catch(e){return E({fallback:yield F(D.fallback,r),operator:k,error:e,expression:D,returnErrorAsString:P})}}let B;try{B=yield U(D,_)}catch(e){return E({fallback:yield F(D.fallback,r),operator:k,error:e,expression:D,returnErrorAsString:P})}const G=null!==(T=null==D?void 0:D.outputType)&&void 0!==T?T:null==D?void 0:D.type;if(!G)return B;const z=yield F(G,r);return z in v?v[z](B):E({fallback:yield F(N,r),operator:k,error:`- Invalid output type: ${z}`,expression:D,returnErrorAsString:P})})),$=(e,r)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>F(e,r)))):yield F(e,r)})),M=(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const i=Object.keys(e).filter(c);if(0===i.length)return{};const a=[];i.forEach((t=>a.push(F(e[t],r))));const s=yield Promise.all(a),n=k(i,yield Promise.all(a));for(const[e,r]of s.entries())"string"==typeof r&&c(r)&&(n[i[e]]=null!==(t=null==n?void 0:n[r])&&void 0!==t?t:r);return n})),H=(e,r)=>i(void 0,void 0,void 0,(function*(){var t,i,a;const s=Object.keys(null!==(i=null===(t=r.options)||void 0===t?void 0:t.functions)&&void 0!==i?i:{}),n=O(e,null===(a=r.options)||void 0===a?void 0:a.fragments,s);if(!y(n))return e;const o=[],l=[];Object.entries(n).forEach((([e,t])=>{c(e)&&(l.push(e,F(t,r)),delete n[e])}));const u=yield Promise.all(l);r.resolvedAliasNodes=Object.assign(Object.assign({},r.resolvedAliasNodes),I(u)),Object.entries(n).forEach((([e,t])=>{o.push(e,F(t,r))}));const d=yield Promise.all(o);return p(I(d),r)})),B=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],G=P(B),z={description:"Logical AND",aliases:["and","&","&&"],parameters:B},W=e=>{const r=e.children;return Object.assign(Object.assign({},e),{values:r})},J={propertyAliases:G,operatorData:z,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(L(z.parameters,{values:t})),t.reduce(((e,r)=>e&&!!r),!0)})),parseChildren:W},V=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],Y=P(V),X={description:"Logical OR",aliases:["or","|","||"],parameters:V},Z={propertyAliases:Y,operatorData:X,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(L(X.parameters,{values:t})),t.reduce(((e,r)=>e||!!r),!1)})),parseChildren:W},K=[{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}],ee=P(K),re={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:K},te={propertyAliases:ee,operatorData:re,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var i,a,s;const[n,o,l]=yield $([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(L(re.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(a=null===(i=t.options)||void 0===i?void 0:i.caseInsensitive)&&void 0!==a&&a)&&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:W},ie=[{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}],ae=P(ie),se={description:"Test if any values are different",aliases:["!=","notEqual","!","ne"],parameters:ie},ne={propertyAliases:ae,operatorData:se,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var i,a,s;const[n,o,l]=yield $([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(L(se.parameters,{values:n,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(a=null===(i=t.options)||void 0===i?void 0:i.caseInsensitive)&&void 0!==a&&a)&&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:W},oe=[{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"}],le=P(oe),ue={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:oe},de={propertyAliases:le,operatorData:ue,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(L(ue.parameters,{values:t,type:e.type})),0===t.length?t:"string"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),""):"array"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),[]):t.every((e=>"string"==typeof e||Array.isArray(e)))?t.reduce(((e,r)=>e.concat(r))):t.every((e=>y(e)))?t.reduce(((e,r)=>Object.assign(Object.assign({},e),r)),{}):t.reduce(((e,r)=>e+r))})),parseChildren:W},ce=[{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}],pe=P(ce),he={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:ce},ve={propertyAliases:pe,operatorData:he,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i,a]=yield $([e.values,e.from,e.subtract],r);r.typeChecker(L(he.parameters,{values:t,from:i,subtract:a}));const s=null!=t?t:[i,a].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:W},fe=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],me=P(fe),ye={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},ge={propertyAliases:me,operatorData:ye,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);if(r.typeChecker(L(ye.parameters,{values:t})),0===t.length)return 0;if(t.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return t.reduce(((e,r)=>e*r))})),parseChildren:W},be=[{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"}],Oe=P(be),Te={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:be},je={propertyAliases:Oe,operatorData:Te,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i,a,s]=yield $([e.values,e.dividend,e.divisor,e.output],r);r.typeChecker(L(Te.parameters,{values:t,dividend:i,divisor:a,output:s}));const n=null!=t?t:[i,a].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:W},Ce=[{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=P(Ce),Se={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Ce},Ae={propertyAliases:Ee,operatorData:Se,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i=!0]=yield $([e.values,e.strict],r);if(r.typeChecker(L(Se.parameters,{values:t,strict:i})),t.length<2)throw new Error("- Not enough values provided");const[a,s]=t;return a===s&&!i||a>s})),parseChildren:W},qe=[{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=P(qe),xe={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:qe},Ne={propertyAliases:we,operatorData:xe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i=!0]=yield $([e.values,e.strict],r);if(r.typeChecker(L(xe.parameters,{values:t,strict:i})),t.length<2)throw new Error("- Not enough values provided");const[a,s]=t;return a===s&&!i||a<s})),parseChildren:W},Pe=[{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"}],Le=P(Pe),ke={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Pe},Ie={propertyAliases:Le,operatorData:ke,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(L(ke.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield F(e.condition,r))?yield F(e.valueIfTrue,r):yield F(e.valueIfFalse,r)})),parseChildren:e=>{const[r,t,i]=e.children;return Object.assign(Object.assign({},e),{condition:r,valueIfTrue:t,valueIfFalse:i})}},Ue=[{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}$"}],Re=P(Ue),De={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:Ue},Qe={propertyAliases:Re,operatorData:De,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i]=yield $([e.testString,e.pattern],r);r.typeChecker(L(De.parameters,{testString:t,pattern:i}));return new RegExp(i).test(t)})),parseChildren:e=>{const[r,t]=e.children;return Object.assign(Object.assign({},e),{testString:r,pattern:t})}},_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","array"],default:{}}],Fe=P(_e),$e={description:"Extract values from data objects",aliases:["getData","dataProperties","data","objectProperties","objProps","getProperty","getObjProp"],parameters:_e},Me={propertyAliases:Fe,operatorData:$e,evaluate:(r,t)=>i(void 0,void 0,void 0,(function*(){var i,a;const[s,n={}]=yield $([r.property,r.additionalData],t);t.typeChecker(L($e.parameters,{property:s,additionalData:n}));const o=Object.assign(Object.assign({},null!==(a=null===(i=t.options)||void 0===i?void 0:i.data)&&void 0!==a?a:{}),n);return e(o,s)})),parseChildren:e=>{const[r,t]=e.children,i=Object.assign(Object.assign({},e),{property:r});return void 0!==t&&(i.fallback=t),i}},He=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string",default:"Hello, %1"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!1,type:["array","object"],default:{}},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],Be=P(He),Ge={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:He},ze={propertyAliases:Be,operatorData:Ge,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i={},a=!0,s="%",n={}]=yield $([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],r);if(r.typeChecker(L(Ge.parameters,{string:t,substitutions:i,trimWhiteSpace:a,substitutionCharacter:s,numberMapping:n})),Array.isArray(i)){const e="$"===s?"$":"%",r=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(t.match(r)||[]).sort(((e,r)=>Number(e.slice(1))-Number(r.slice(1)))),o=new Set(n),l=k(Array.from(o),i.map((e=>a?String(e).trim():e)));return t.split(r).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}const o=/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g,l=[];for(const e of t.split(o)){if(!/(?<!\\){{(.+)}}/.exec(e)){l.push(e.replace("\\{{","{{"));continue}const t=yield We(e,i,n,r);l.push(a?String(t).trim():t)}return l.join("")})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{string:r,substitutions:t})}},We=(r,t,a,s)=>i(void 0,void 0,void 0,(function*(){var i,n;const o=null!==(n=null===(i=s.options)||void 0===i?void 0:i.data)&&void 0!==n?n:{},l=r.replace(/{{(.+)}}/,"$1"),u=yield F(e(t,l,e(o,l,"")),s);if("number"!=typeof u)return u;if(!(l in a))return u;const d=a[l];if(u in d)return d[u].replace("{}",String(u));const c=Object.keys(a[l]),p=c.find((e=>e.startsWith(">")));if(p){if(u>Number(p.slice(1)))return null==d?void 0:d[p]}const h=c.find((e=>e.startsWith("<")));if(h){if(u<Number(h.slice(1)))return null==d?void 0:d[h]}return d.other?d.other.replace("{}",String(u)):u})),Je=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Ve=P(Je),Ye={description:"Count elements in an array",aliases:["count","length"],parameters:Je},Xe={propertyAliases:Ve,operatorData:Ye,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.values,r);return r.typeChecker(L(Ye.parameters,{values:t})),t.length})),parseChildren:W},Ze=[{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}],Ke=P(Ze),er={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:Ze},rr=" ",tr={propertyAliases:Ke,operatorData:er,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,i,a;const[s,n,o,l]=yield $([e.value,null!==(t=e.delimiter)&&void 0!==t?t:rr,null===(i=e.trimWhiteSpace)||void 0===i||i,null===(a=e.excludeTrailing)||void 0===a||a],r);r.typeChecker(L(er.parameters,{value:s,delimiter:n,trimWhiteSpace:o,excludeTrailing:l}));let u=s.split(n);return o&&(u=u.map((e=>e.trim()))),l&&""===u[u.length-1]&&u.pop(),u})),parseChildren:e=>{const[r,t=rr]=e.children;return Object.assign(Object.assign({},e),{value:r,delimiter:t})}},ir=[{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"}],ar=P(ir),sr={description:"Query an SQL database",aliases:["sql","pgSql","postgres","pg","sqLite","sqlite","mySql"],parameters:ir},nr={propertyAliases:ar,operatorData:sr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const n=null===(t=r.options)||void 0===t?void 0:t.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],r);r.typeChecker(L(sr.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(s=null!==(a=e.useCache)&&void 0!==a?a:r.options.useCache)||void 0===s||s;{const e=r.cache.useCache(h,((e,r,t,a,s)=>i(void 0,void 0,void 0,(function*(){const i=(yield n.query({query:e,values:r}))||[];["array","string","number"].includes(null!=s?s:"")&&(a=!0);const o=a?i.map((e=>{const r=Object.values(e);return r.length<=1?r[0]:r})):i;return t?o[0]:o}))),o,l,u,d,p);return e}})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{query:r,values:t})}},or=[{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}],lr=P(or),ur={description:"GraphQL request",aliases:["graphQL","graphQl","graphql","gql"],parameters:or},dr={propertyAliases:lr,operatorData:ur,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s,n,o,l,u;const d=null!==(t=r.graphQLClient)&&void 0!==t?t:r.httpClient;if(!d)throw new Error("No HTTP client provided for GraphQL connection");const[c,p,h,v,f,m]=yield $([e.query,e.url,yield H(e.variables,r),e.returnNode,e.headers,e.useCache],r),{url:y,headers:g}=p instanceof Object?p:{url:p,headers:null};r.typeChecker([...L(ur.parameters,{url:y,query:c,variables:h,returnNode:v,headers:f,useCache:m}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=y&&"graphqlendpoint"!==y.toLowerCase()?y:"",O=null!==(n=null!==(s=null===(a=r.options.graphQLConnection)||void 0===a?void 0:a.endpoint)&&void 0!==s?s:r.options.baseEndpoint)&&void 0!==n?n:"",T=D(b)?b:Q(O,b),j={query:c,variables:h},C=null===(o=null!=m?m:r.options.useCache)||void 0===o||o,E=yield r.cache.useCache(C,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield _(d,{url:e,method:"post",data:r,headers:t});return R(null==i?void 0:i.data,a)}))),T,j,Object.assign(Object.assign(Object.assign(Object.assign({},null===(l=r.options.graphQLConnection)||void 0===l?void 0:l.headers),null===(u=r.options)||void 0===u?void 0:u.headers),g),f),v);return E})),parseChildren:e=>{const[r,t="",i,...a]=e.children,s=Array.isArray(i)?i:[i],n=a.slice(0,s.length),o=k(s,n),l=Object.assign(Object.assign({},e),{query:r,url:t,variables:o});return a.length>s.length&&(l.returnNode=a.pop()),l}},cr=[{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}],pr=P(cr),hr={description:"HTTP GET Request",aliases:["GET","get","api"],parameters:cr},vr=e=>{const[r="",t,...i]=e.children,a=Array.isArray(t)?t:[t],s=i.slice(0,a.length),n=k(a,s),o=Object.assign(Object.assign({},e),{url:r,parameters:n});return i.length>a.length&&(o.returnProperty=i.pop()),o},fr=vr,mr={propertyAliases:pr,operatorData:hr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const n=r.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield $([e.url,yield H(e.parameters,r),e.returnProperty,yield H(e.headers,r),e.useCache],r),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};r.typeChecker([...L(hr.parameters,{url:p,returnProperty:u,headers:d,parameters:l,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",f=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),h),d),m=null===(s=null!=c?c:r.options.useCache)||void 0===s||s,y=yield r.cache.useCache(m,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield _(n,{url:e,params:r,headers:t});return R(i,a)}))),D(p)?p:Q(v,p),l,f,u);return y})),parseChildren:vr},yr=[{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}],gr=P(yr),br={description:"HTTP POST Request",aliases:["POST","post"],parameters:yr},Or={propertyAliases:gr,operatorData:br,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,s;const n=r.httpClient;if(!n)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield $([e.url,yield H(e.parameters,r),e.returnProperty,yield H(e.headers,r),e.useCache],r),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};r.typeChecker([...L(br.parameters,{url:p,headers:d,data:l,returnProperty:u,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",f=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),h),d),m=null!==(s=null!=c?c:r.options.useCache)&&void 0!==s&&s,y=yield r.cache.useCache(m,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield _(n,{url:e,data:r,headers:t,method:"post"});return R(i,a)}))),D(p)?p:Q(v,p),l,f,u);return y})),parseChildren:fr},Tr=[{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"]}],jr=P(Tr),Cr={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:Tr},Er=e=>{const r=e.children;if(r.every((e=>y(e))))return Object.assign(Object.assign({},e),{properties:r});if(r.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=r.filter(((e,r)=>r%2==0)),i=r.filter(((e,r)=>r%2==1)),a=t.map(((e,r)=>({key:e,value:i[r]})));return Object.assign(Object.assign({},e),{properties:a})},Sr={propertyAliases:jr,operatorData:Cr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield $(e.properties,r);r.typeChecker(L(Cr.parameters,{properties:t}));const{properties:a}=t.some((e=>!y(e)))?yield Er(Object.assign(Object.assign({},e),{children:t})):{properties:t},s=a.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:t})=>{return a=[e,t],i(void 0,void 0,void 0,(function*(){const[e,t]=yield $(a,r);return r.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,t]}));var a}));return Object.fromEntries(yield Promise.all(s))})),parseChildren:Er},Ar=[{name:"matchExpression",description:"Expression to match against",aliases:["matchValue"],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"]}],qr={propertyAliases:P(Ar),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Ar},evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const i=yield F(e.matchExpression,r);r.typeChecker({name:"matchExpression",value:i,expectedType:["string","number","boolean"]});const s=Array.isArray(e.branches)?I(e.branches):null!==(t=e.branches)&&void 0!==t?t:{},n=a(s)?yield F(s,r):s;if(!y(n))throw new Error("Branches don't evaluate to an object");if(i in n)return yield F(n[i],r);if("fallback"in n)return yield F(n.fallback,r);if(i in e)return yield F(e[i],r);throw new Error(`No match found for ${i}`)})),parseChildren:e=>{const[r,...t]=e.children,i=I(t);return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}},wr=[{name:"functionName",description:"Path (in options.functions) to the required function",aliases:["functionPath","funcName","function","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:["array","any"],default:[]},{name:"input",description:"Argument for the function if a single input parameter",aliases:["arg"],required:!1,type:"any",default:"input"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],xr=P(wr),Nr={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:wr},Pr={propertyAliases:xr,operatorData:Nr,evaluate:(r,t)=>i(void 0,void 0,void 0,(function*(){var a,s,n,o,l;const[u,d=[],c,p]=yield $([r.functionName,r.args,r.input,r.useCache],t);t.typeChecker(L(Nr.parameters,{functionName:u,args:d}));const{data:h,functions:v}=t.options;if(!v)throw new Error("- No functions defined");const f=null!==(o=null!==(n=null!==(s=null!==(a=e(v,`${u}.function`,null))&&void 0!==a?a:e(v,u,null))&&void 0!==s?s:e(t.options,`${u}.function`,null))&&void 0!==n?n:e(t.options,u,null))&&void 0!==o?o:e(h,u,null);if(!f||"function"!=typeof f)throw new Error(`- No function found: "${u}"`);const m=null!==(l=null!=p?p:t.options.useCache)&&void 0!==l&&l,y=[...void 0===c?[]:[yield H(c,t)],...Array.isArray(d)?d:[d]];return yield t.cache.useCache(m,((e,...r)=>i(void 0,void 0,void 0,(function*(){return yield f(...r)}))),u,...y)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{functionName:r,args:t})}},Lr=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],kr=P(Lr),Ir={description:"Pass through a value unchanged (or change its type)",aliases:["pass","_","passThru","passthru","ignore","coerce","convert"],parameters:Lr},Ur={propertyAliases:kr,operatorData:Ir,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){return r.typeChecker(L(Ir.parameters,{value:e.value})),yield F(e.value,r)})),parseChildren:e=>{const[...r]=e.children,t=1===(null==r?void 0:r.length)?r[0]:r;return Object.assign(Object.assign({},e),{value:t})}};var Rr=Object.freeze({__proto__:null,AND:J,BUILD_OBJECT:Sr,CONDITIONAL:Ie,COUNT:Xe,CUSTOM_FUNCTIONS:Pr,DIVIDE:je,EQUAL:te,GET:mr,GRAPHQL:dr,GREATER_THAN:Ae,LESS_THAN:Ne,MATCH:qr,MULTIPLY:ge,NOT_EQUAL:ne,OBJECT_PROPERTIES:Me,OR:Z,PASSTHRU:Ur,PLUS:de,POST:Or,REGEX:Qe,SPLIT:tr,SQL:nr,STRING_SUBSTITUTION:ze,SUBTRACT:ve});class Dr{constructor(e){var r,t;this.useCache=(e,r,...t)=>i(this,void 0,void 0,(function*(){if(!e)return yield r(...t);const i=Qr(t),a=i in this.store,s=Date.now(),n=a&&s-this.store[i].timestamp>1e3*this.maxTime;if(a)return this.queue=this.queue.filter((e=>e!==i)),this.queue.unshift(i),this.store[i].timestamp=s,n&&(this.store[i].result=yield r(...t)),this.store[i].result;const o=yield r(...t);return this.store[i]={result:o,timestamp:s},this.queue.unshift(i),this.resizeCache(),o})),this.getMax=()=>this.maxSize,this.setMax=e=>{this.maxSize=e,this.resizeCache()},this.getMaxTime=()=>this.maxTime,this.setMaxTime=e=>{this.maxTime=e},this.getCache=()=>this.store,this.setCache=e=>this.store=e,this.resizeCache=()=>{if(this.queue.length>this.maxSize){this.queue.slice(this.maxSize).forEach((e=>delete this.store[e])),this.queue=this.queue.slice(0,this.maxSize)}},this.store={},this.queue=[],this.maxSize=null!==(r=null==e?void 0:e.maxSize)&&void 0!==r?r:50,this.maxTime=null!==(t=null==e?void 0:e.maxTime)&&void 0!==t?t:1800}}const Qr=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),_r=e=>e||("undefined"!=typeof window&&"document"in window&&"fetch"in window?Fr(window.fetch):void 0),Fr=e=>({get:r=>i(void 0,void 0,void 0,(function*(){const{url:t,headers:i,params:a={}}=r,s=Object.keys(a).length>0?`?${new URLSearchParams(a).toString()}`:"",n=yield e(t+s,{headers:i,method:"GET"}),o=yield n.json();if(!n.ok){const e=new Error("Problem with GET request");throw e.name="FetchError",e.errorData={status:n.status,error:n.statusText,url:n.url,response:o},console.log(e.errorData),e}return o})),post:r=>i(void 0,void 0,void 0,(function*(){const{url:t,headers:i,params:a,data:s}=r,n=new URLSearchParams(a),o=n.size>0?`?${n.toString()}`:"",l=yield e(t+o,{headers:i,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 $r{constructor(e={}){var r,t,i;this.typeChecker=(...e)=>{const r=1===e.length&&Array.isArray(e[0])?e[0]:e,t=q(...r);if(!0===t)return;const i=new Error(t);throw i.name="Type Error",i},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.21.2",this.options=Mr(e),this.operators=l(Rr,null!==(t=null===(r=this.options)||void 0===r?void 0:r.excludeOperators)&&void 0!==t?t:[],g),this.operatorAliases=g,this.cache=new Dr({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime}),this.graphQLClient=_r(null===(i=e.graphQLConnection)||void 0===i?void 0:i.httpClient),this.httpClient=_r(e.httpClient)}evaluate(e,r={}){var t;return i(this,void 0,void 0,(function*(){const i=h(this.options,Mr(r),!0);return r.httpClient&&(this.httpClient=_r(r.httpClient)),(null===(t=r.graphQLConnection)||void 0===t?void 0:t.httpClient)&&(this.graphQLClient=_r(r.graphQLConnection.httpClient)),i.maxCacheSize&&i.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(i.maxCacheSize),i.maxCacheTime&&i.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(i.maxCacheTime),yield F(e,{options:i,operators:r.excludeOperators?l(Rr,r.excludeOperators,g):this.operators,operatorAliases:this.operatorAliases,typeChecker:i.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient})}))}getOptions(){return this.options}updateOptions(e){this.options=h(this.options,Mr(e),!1),this.options.excludeOperators&&(this.operators=l(Rr,this.options.excludeOperators,g))}getOperators(){const e=this.options.excludeOperators?l(Rr,this.options.excludeOperators,g):this.operators,r=Object.entries(e).map((([e,r])=>Object.assign(Object.assign({name:e},r.operatorData),{parseChildren:r.parseChildren}))),t=[...new Set(Object.values(g))];return r.sort(((e,r)=>t.indexOf(e.name)-t.indexOf(r.name)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,r])=>Object.assign({name:e},null==r?void 0:r.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,r])=>{const t="function"==typeof r?r:null==r?void 0:r.function,i={name:e,numRequiredArgs:null==t?void 0:t.length};if("function"!=typeof r){const{description:e,argsDefault:t,inputDefault:a,textColor:s,backgroundColor:n}=r;return e&&(i.description=e),t&&(i.argsDefault=t),a&&(i.inputDefault=a),s&&(i.textColor=s),n&&(i.backgroundColor=n),i}return i}))}getConfig(){return{options:this.options,operators:this.options.excludeOperators?l(Rr,this.options.excludeOperators,g):this.operators,operatorAliases:this.operatorAliases,typeChecker:this.options.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient}}}const Mr=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e,Hr=e=>y(e)&&"operator"in e&&"children"in e&&Array.isArray(e.children),Br=(e,r,t)=>{const i=t.find((r=>r.name===e||r.aliases.includes(e)));if(!i)throw new Error("Invalid operator: "+e);const a=[];if("OBJECT_PROPERTIES"===i.name){if(Gr("additionalData",r,i.parameters))return Object.entries(r);const e=Gr("property",r,i.parameters);if(!e)throw new Error("Missing required property for operator $getData: property");const t=r.find((([e])=>"fallback"===e));return t?[e[1],t[1]]:e[1]}for(const{name:t,aliases:s,required:n}of i.parameters){const i=[t,...s],o=r.find((([e])=>i.includes(e)));if(void 0===o&&n)throw new Error(`Missing required property for operator ${e}: ${t}`);if(void 0===o)break;a.push(o[1])}return a},Gr=(e,r,t)=>{const i=t.find((r=>r.name===e));if(!i)return;const a=[i.name,...i.aliases];return r.find((([e])=>a.includes(e)))},zr=(e,r)=>c(e)&&!r.has(e),Wr=(e,r)=>{if(!e)return;const t=r.find((r=>e===r.name||r.aliases.includes(n(e))));return null==t?void 0:t.aliases.find((e=>/^[A-Za-z_]{2,}$/.test(e)))},Jr=(e,r={})=>{const t=r[e];if(!t)throw new Error("Fragment referenced in expression that is not defined in FigTree: "+e);const i=JSON.stringify(t).match(/"(\$\w+)"/gm);if(!i)return[];const a=new Set;return i.forEach((e=>a.add(e.replace(/"/g,"")))),Array.from(a)},Vr=(e,r)=>{const t=r.parameters.map((e=>[e.name,...e.aliases])).flat();return Object.keys(e).some((e=>t.includes(e)))};Object.defineProperty(exports,"dequal",{enumerable:!0,get:function(){return r.dequal}}),exports.AxiosClient=e=>({get:r=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},r),{method:"get"}))).data})),post:r=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},r),{method:"post"}))).data})),throwError:r=>{var t,i,a,s;if(e.isAxiosError(r)&&r.response)throw r.errorData={status:null===(t=r.response)||void 0===t?void 0:t.status,error:null===(i=r.response)||void 0===i?void 0:i.statusText,url:null===(a=r.config)||void 0===a?void 0:a.url,response:null===(s=r.response)||void 0===s?void 0:s.data},r;throw new Error("Network error: "+(null==r?void 0:r.message))}}),exports.FetchClient=Fr,exports.FigTreeError=C,exports.FigTreeEvaluator=$r,exports.SQLNodePostgres=e=>({query:({query:r,values:t=[]})=>i(void 0,void 0,void 0,(function*(){const i={text:r,values:null!=t?t:[]};try{const r=yield e.query(i);if(null==r?void 0:r.error)throw new Error(r.error);return r.rows}catch(e){throw e.name="Node-Postgres error",e}}))}),exports.SQLite=e=>({query:({query:r,values:t=[]})=>i(void 0,void 0,void 0,(function*(){try{return yield e.all(r,t)}catch(e){throw e.name="SQLite error",e}}))}),exports.convertFromShorthand=(e,r)=>i(void 0,void 0,void 0,(function*(){const t=r.getOperators(),o=r.getFragments(),l=r.getCustomFunctions(),u=o.map((e=>e.name)),d=l.map((e=>e.name)),c=e=>i(void 0,void 0,void 0,(function*(){if(Array.isArray(e))return yield Promise.all(e.map((e=>c(e))));if(!y(e))return e;const o=Object.entries(e);if(0===o.length)return e;const l=o[0][0].replace("$",""),h=n(l),v=t.find((e=>e.name===h||e.aliases.includes(h))),f=u.includes(l),m=d.includes(l);if(v){const e=v.aliases[0],t=o[0][1];if(Array.isArray(t)){const i=yield Promise.all(t.map((e=>c(e)))),a=yield v.parseChildren({operator:e,children:i},r.getConfig());return delete a.children,Object.assign(Object.assign({},a),yield p(o))}const i=yield c(t);if(!y(i)||!Vr(i,v)||a(i)||s(i)){return{operator:e,[v.parameters[0].name]:i}}return Object.assign(Object.assign({operator:e},i),yield p(o))}if(f){const r=yield c(e[o[0][0]]);if(!y(r))throw new Error("Invalid shorthand Fragment");return Object.assign(Object.assign({fragment:l},r),yield p(o))}if(m){const e=l,r=o[0][1],t=yield c(r);if(!y(t)||a(t)||s(t)){return{operator:e,["args"]:t}}return Object.assign(Object.assign({operator:e},t),yield p(o))}return Object.fromEntries(yield Promise.all(o.map((([e,r])=>i(void 0,void 0,void 0,(function*(){return[e,yield c(r)]}))))))})),p=e=>i(void 0,void 0,void 0,(function*(){const r=e.slice(1);return Object.fromEntries(yield Promise.all(r.map((([e,r])=>i(void 0,void 0,void 0,(function*(){return[e,yield c(r)]}))))))}));return c(e)})),exports.convertToShorthand=(e,r,i=2)=>{const a=r.getOperators(),s=r.getFragments(),o=r.getCustomFunctions(),l=r.getOptions().fragments,u=a.map((e=>[e.name,...e.aliases])).flat(),d=s.map((e=>e.name)),c=o.map((e=>e.name)),p=new Set([...u,...d,...c]),h=e=>{if(Array.isArray(e))return e.map((e=>h(e)));if(!y(e))return e;const r=e,{operator:s,fragment:o}=r,u=t(r,["operator","fragment"]);if(!s&&!o)return Object.fromEntries(Object.entries(e).map((([e,r])=>[e,h(r)])));const d=c.includes(s);o&&(null==u?void 0:u.parameters)&&(Object.entries(u.parameters).forEach((([e,r])=>{u[e]=r})),delete u.parameters);const v=d?s:Wr(s,a),f=`$${null!=v?v:o}`,m=o?Jr(o,l):[],g=Object.keys(u).filter((e=>zr(e,p)&&!m.includes(e))),b=Object.entries(u).filter((([e])=>!g.includes(e)&&!m.includes(e))).map((([e,r])=>[e,h(r)])),O=Object.fromEntries(g.map((e=>[e,h(u[e])]))),T=Object.fromEntries(m.map((e=>[e,h(u[e])])));switch(!0){case Object.keys(T).length>0:return Object.assign({[f]:T},O);case d:return 1!==b.length||"input"in u?Object.assign({[f]:Object.fromEntries(b)},O):{[f]:b[0][1]};case"values"in u:return 1===b.length?{[f]:b[0][1]}:Object.assign({[f]:Object.fromEntries(b)},O);case"match"===v:return Object.assign({[f]:Object.fromEntries(b)},O);case b.length>i||!!o||b.some((([e])=>"useCache"===e||"outputType"===e))||b.some((e=>Array.isArray(e[1]))):return Object.assign({[f]:Object.fromEntries(b)},O);case 1===b.length:return Object.assign({[f]:b[0][1]},O);default:return Object.assign({[f]:Br(n(s),b,a)},O)}};return h(e)},exports.convertV1ToV2=(e,r)=>i(void 0,void 0,void 0,(function*(){const t=r.getOperators(),a=e=>i(void 0,void 0,void 0,(function*(){if(!y(e))return e;const s=Hr(e)?yield i(void 0,void 0,void 0,(function*(){const{operator:i}=e,a=n(i),s=t.find((e=>e.name===a||e.aliases.includes(a)));if(s){const t=yield s.parseChildren(e,r.getConfig());delete t.children;const i=s.aliases[0];return t.operator=i,t}throw new Error("Invalid operator: "+i)})):e,o={};for(const[e,r]of Object.entries(s)){const t="type"===e?"outputType":e;if(Array.isArray(r)){const e=r.map((e=>a(e))),i=yield Promise.all(e);o[t]=i}else o[t]=yield a(r)}return o}));return a(e)})),exports.evaluateExpression=(e,r)=>new $r(r).evaluate(e),exports.isAliasString=c,exports.isFigTreeError=e=>e instanceof C,exports.isFigTreeExpression=e=>a(e)||s(e)||"string"==typeof e&&c(e)||y(e)&&1===Object.keys(e).length&&c(Object.keys(e)[0]),exports.isFragmentNode=s,exports.isObject=y,exports.isOperatorNode=a,exports.isV1Node=Hr,exports.preProcessShorthand=O,exports.standardiseOperatorName=n,exports.truncateString=u;
|
|
1
|
+
"use strict";var e=require("object-property-extractor"),r=require("dequal/lite");const t=e=>e instanceof Object&&"operator"in e,a=e=>e instanceof Object&&"fragment"in e,s=e=>{const r=m(e);return r||e},i=(e,r)=>r[s(e)],n=(e,r,t)=>{const a={...e};return r.forEach((e=>{t[s(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[t[s(e)]]})),a},o=(e,r=200)=>e.length<r?e:`${e.slice(0,r-2).trim()}...`,l=(e,r)=>{const t=Object.entries(e).map((([e,t])=>[r(e),t]));return Object.fromEntries(t)},u=e=>/^\$.+/.test(e),p=(e,{resolvedAliasNodes:r})=>"string"==typeof e&&u(e)?r?.[e]??e:e,c=(e,r,t)=>{const a={...e,...r};return t?((e.data||r.data)&&(a.data={...e.data,...r.data}),(e.functions||r.functions)&&(a.functions={...e.functions,...r.functions}),(e.fragments||r.fragments)&&(a.fragments={...e.fragments,...r.fragments}),(e.headers||r.headers)&&(a.headers={...e.headers,...r.headers}),a):a},d={number:e=>h(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},h=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const r=new RegExp(/-?\d*\.?\d+/gm),t=e.match(r);return t?Number(t[0]):0},m=e=>e.replace(/[^A-Za-z\d _-]/g,"").split(/[-_ ]/).map((e=>e.match(/[a-z]+|[A-Z]+[a-z]*/g)??e)).flat().filter((e=>""!==e)).map(((e,r)=>0===r?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""),f=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),y={and:"AND","&":"AND","&&":"AND",or:"OR","|":"OR","||":"OR","=":"EQUAL",eq:"EQUAL",equal:"EQUAL",equals:"EQUAL","!=":"NOT_EQUAL",notEqual:"NOT_EQUAL","!":"NOT_EQUAL",ne:"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",getData:"OBJECT_PROPERTIES",dataProperties:"OBJECT_PROPERTIES",data:"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",get:"GET",api:"GET",POST:"POST",post:"POST",sql:"SQL",pgSql:"SQL",postgres:"SQL",pg:"SQL",sqLite:"SQL",sqlite:"SQL",mySql:"SQL",graphQL:"GRAPHQL",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",pass:"PASSTHRU",_:"PASSTHRU",passThru:"PASSTHRU",passthru:"PASSTHRU",ignore:"PASSTHRU",coerce:"PASSTHRU",convert:"PASSTHRU"},g=y,v=(e,r={},t,a=!0)=>a&&f(e)?b(e,r,t):e,b=(e,r,s)=>{if(t(e)||a(e))return e;const i=Object.entries(e),n=i.filter((([e])=>u(e))),o=i.filter((([e])=>!u(e)));return{...n.reduce(((e,[t,a])=>e={...e,...T(t,a,r,s)}),{}),...Object.fromEntries(o)}},T=(e,r,t,a)=>{const s=e.slice(1),n=i(s,g);return n?Array.isArray(r)?{operator:n,children:r}:f(r)&&!Object.keys(r).some((e=>u(e)))?{operator:n,...r}:{operator:n,children:[r]}:s in t?{fragment:s,parameters:{...r}}:a.includes(s)?Array.isArray(r)?{operator:s,args:r}:f(r)?"input"in r||"args"in r?{operator:s,...r}:{operator:s,input:r}:{operator:s,args:[r]}:{[e]:r}};class w extends Error{constructor(e,r,t,a){super(e.message),Object.assign(this,e),this.operator=r,this.expression=a,this.errorData=e.errorData,t&&(this.name=t),"Error"===this.name&&(this.name="FigTreeError");const s=(r?"Operator: "+r:"")+("FigTreeError"===this.name?"":` - ${this.name}`),i=this.errorData?"\n"+JSON.stringify(this.errorData,null,2):"";this.prettyPrint=`${""!==s?s+"\n":""}${this.message}${"\n{}"===i?"":i}`}}const C=({fallback:e,operator:r,name:t,error:a,expression:s,returnErrorAsString:i=!1})=>{if(void 0!==e)return e;if(a instanceof w){if(!i)throw a;return a.prettyPrint}const n=new w("string"==typeof a?new Error(a):a,r,t,s);if(i)return n.prettyPrint;throw n},E=e=>f(e)&&"literal"in e,A=({value:e,name:r,expectedType:t})=>{if(E(t)){const{literal:a}=t;return!!a.includes(e)||O(r,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(t))return!!t.some((t=>!0===A({value:e,name:r,expectedType:t})))||O(r,e,t.join("|"));return!!(0,q[t])(e)||O(r,e,t)},S=(...e)=>{const r=[];return e.forEach((e=>{const t=A(e);!0!==t&&r.push(t)})),!(r.length>0)||r.join("\n")},q={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},O=(e,r,t)=>void 0===r&&e?`- Missing required property "${e}" (type: ${t})`:void 0!==e?`- Property "${e}" (value: ${x(r)}) is not of type: ${t}`:`- ${x(r)} is not of type: ${t}`,x=e=>{const r=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return o(r,50)},N=e=>{const r={};return e.forEach((e=>{e.aliases.forEach((t=>r[t]=e.name))})),r},P=(e,r)=>e.map((({name:e,required:t,type:a})=>{if(E(a)){const s=[...a.literal];return t||s.push(void 0),{name:e,value:r[e],expectedType:{literal:s}}}const s=Array.isArray(a)?a:[a];t||s.push("undefined");const i=1===s.length?s[0]:s;return{name:e,value:r[e],expectedType:i}})),j=(e,r)=>{const t=e.map(((e,t)=>[e,r[t]]));return Object.fromEntries(t)},L=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=e.filter(((e,r)=>r%2==0)),t=S(...r.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==t)throw new Error(t);const a=e.filter(((e,r)=>r%2==1)),s={};return r.forEach(((e,r)=>{s[e]=a[r]})),s},k=e=>f(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,I=(r,t,a=void 0)=>{const s=t?e(r,t,a):r;return Array.isArray(s)?s.map((e=>k(e))):t?null===s?null:k(s):s},U=e=>/^https?:\/\/.+/.test(e),R=(...e)=>e.reduce(((e,r,t)=>{const a="/"===r[0]?1:0,s="/"===r.slice(-1)?-1:void 0,i=r.slice(a,s);return""===i?e:e+(0===t?"":"/")+i}),""),D=async(e,r)=>{const{url:t,params:a={},data:s={},headers:i={},method:n="get"}=r;if(!t||""===t)throw new Error("Invalid url");try{return await e[n]({url:t,headers:{"Content-Type":"application/json",Accept:"application/json",...i},params:a,data:s})}catch(r){e.throwError(r)}},Q=async(e,r)=>{const{options:s,operators:n,operatorAliases:o}=r;let u=s?.allowJSONStringInput?(e=>{if("string"!=typeof e)return e;try{const r=JSON.parse(e);return t(r)?r:e}catch(r){return e}})(e):e;const c=Object.keys(r.options?.functions??{});u=v(u,r.options?.fragments,c,!s.noShorthand),Array.isArray(u)&&(u=await _(u,r));const h=t(u),m=a(u);if(h&&(u=await(async(e,r)=>{if(!(e.operator in(r.options?.functions??{})))return e;const{operator:t,fallback:a,outputType:s,type:i,useCache:n,input:o,args:l,...u}=e,p={operator:"CUSTOM_FUNCTIONS",function:t};return void 0!==a&&(p.fallback=a),void 0!==s&&(p.outputType=s),void 0!==i&&(p.type=i),void 0!==n&&(p.useCache=n),void 0!==l&&(p.args=l),void 0!==o?p.input=o:Object.keys(u).length>0&&(p.input=u),p})(u,r)),s.evaluateFullObject&&!h&&!m)return p(await $(u,r),r);if(!h&&!m)return s.supportDeprecatedValueNodes&&f(u)&&"value"in u?u.value:p(u,r);const{fallback:y}=u,g=s?.returnErrorAsString??!1;if(m){const e={...u},a=s?.fragments?.[e.fragment]?.metadata?.parameters?.filter((e=>void 0!==e.default));void 0===e.parameters&&(e.parameters={}),a?.forEach((r=>{void 0===e.parameters?.[r.name]&&void 0===e?.[r.name]&&(e.parameters[r.name]=r.default)}));const[i,n]=await _([e.fragment,e.parameters],r),o=v(s?.fragments?.[i],s.fragments,c,!s.noShorthand);if(void 0===o)return C({fallback:await Q(y,r),error:`Fragment not defined: ${i}`,expression:u,returnErrorAsString:g});if(!t(o))return p(o,r);u={...e,...o,...n},delete u.fragment}const b=u,T=i(b.operator,o);if(!T)return C({fallback:await Q(y,r),error:`Invalid operator: ${b.operator}`,expression:u,returnErrorAsString:g});if(!r.operators[T])return C({fallback:await Q(y,r),error:`Excluded operator: ${b.operator}`,expression:u,returnErrorAsString:g});const{propertyAliases:w,evaluate:E,parseChildren:A}=n[T];let S=((e,r)=>l(r,(r=>r in e?e[r]:r)))(w,b);const q=await F(S,r);m||Object.entries(q).forEach((([e,t])=>r.resolvedAliasNodes[e]=t));const O=m?{...r,resolvedAliasNodes:{...r.resolvedAliasNodes,...q}}:r;if("children"in S){if(Array.isArray(S.children)||(S.children=await Q(S.children,O)),!Array.isArray(S.children))return C({fallback:await Q(y,r),operator:T,name:"Type Error",error:'- Property "children" is not of type: array',expression:u,returnErrorAsString:g});try{S=await A(S,O),delete S.children}catch(e){return C({fallback:await Q(S.fallback,r),operator:T,error:e,expression:S,returnErrorAsString:g})}}let x;try{x=await E(S,O)}catch(e){return C({fallback:await Q(S.fallback,r),operator:T,error:e,expression:S,returnErrorAsString:g})}const N=S?.outputType??S?.type;if(!N)return x;const P=await Q(N,r);return P in d?d[P](x):C({fallback:await Q(y,r),operator:T,error:`- Invalid output type: ${P}`,expression:S,returnErrorAsString:g})},_=async(e,r)=>Array.isArray(e)?await Promise.all(e.map((e=>Q(e,r)))):await Q(e,r),F=async(e,r)=>{const t=Object.keys(e).filter(u);if(0===t.length)return{};const a=[];t.forEach((t=>a.push(Q(e[t],r))));const s=await Promise.all(a),i=j(t,await Promise.all(a));for(const[e,r]of s.entries())"string"==typeof r&&u(r)&&(i[t[e]]=i?.[r]??r);return i},$=async(e,r)=>{const t=Object.keys(r.options?.functions??{}),a=v(e,r.options?.fragments,t);if(!f(a))return e;const s=[],i=[];Object.entries(a).forEach((([e,t])=>{u(e)&&(i.push(e,Q(t,r)),delete a[e])}));const n=await Promise.all(i);r.resolvedAliasNodes={...r.resolvedAliasNodes,...L(n)},Object.entries(a).forEach((([e,t])=>{s.push(e,Q(t,r))}));const o=await Promise.all(s);return p(L(o),r)},M=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],H=N(M),B={description:"Logical AND",aliases:["and","&","&&"],parameters:M},G=e=>{const r=e.children;return{...e,values:r}},z={propertyAliases:H,operatorData:B,evaluate:async(e,r)=>{const t=await _(e.values,r);return r.typeChecker(P(B.parameters,{values:t})),t.reduce(((e,r)=>e&&!!r),!0)},parseChildren:G},W=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],J=N(W),V={description:"Logical OR",aliases:["or","|","||"],parameters:W},Y={propertyAliases:J,operatorData:V,evaluate:async(e,r)=>{const t=await _(e.values,r);return r.typeChecker(P(V.parameters,{values:t})),t.reduce(((e,r)=>e||!!r),!1)},parseChildren:G},X=[{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}],Z=N(X),K={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:X},ee={propertyAliases:Z,operatorData:K,evaluate:async(e,t)=>{const[a,s,i]=await _([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(P(K.parameters,{values:a,caseInsensitive:s,nullEqualsUndefined:i}));const n=(void 0!==s?s:t.options?.caseInsensitive??!1)&&a.every((e=>"string"==typeof e))?a.map((e=>e.toLowerCase())):a;return!(void 0!==i?i:void 0!==t.options?.nullEqualsUndefined&&t.options.nullEqualsUndefined)||null!==n[0]&&void 0!==n[0]?n.every((e=>r.dequal(e,n[0]))):n.every((e=>null==e))},parseChildren:G},re=[{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}],te=N(re),ae={description:"Test if any values are different",aliases:["!=","notEqual","!","ne"],parameters:re},se={propertyAliases:te,operatorData:ae,evaluate:async(e,t)=>{const[a,s,i]=await _([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(P(ae.parameters,{values:a,caseInsensitive:s,nullEqualsUndefined:i}));const n=(void 0!==s?s:t.options?.caseInsensitive??!1)&&a.every((e=>"string"==typeof e))?a.map((e=>e.toLowerCase())):a;return!(void 0!==i?i:void 0!==t.options?.nullEqualsUndefined&&t.options.nullEqualsUndefined)||null!==n[0]&&void 0!==n[0]?n.some((e=>!r.dequal(e,n[0]))):n.some((e=>null===e&&void 0===e))},parseChildren:G},ie=[{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"}],ne=N(ie),oe={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ie},le={propertyAliases:ne,operatorData:oe,evaluate:async(e,r)=>{const t=await _(e.values,r);return r.typeChecker(P(oe.parameters,{values:t,type:e.type})),0===t.length?t:"string"===e?.type?t.reduce(((e,r)=>e.concat(r)),""):"array"===e?.type?t.reduce(((e,r)=>e.concat(r)),[]):t.every((e=>"string"==typeof e||Array.isArray(e)))?t.reduce(((e,r)=>e.concat(r))):t.every((e=>f(e)))?t.reduce(((e,r)=>({...e,...r})),{}):t.reduce(((e,r)=>e+r))},parseChildren:G},ue=[{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}],pe=N(ue),ce={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:ue},de={propertyAliases:pe,operatorData:ce,evaluate:async(e,r)=>{const[t,a,s]=await _([e.values,e.from,e.subtract],r);r.typeChecker(P(ce.parameters,{values:t,from:a,subtract:s}));const i=t??[a,s].filter((e=>void 0!==e));if(i.length<2)throw new Error("- Not enough values provided");if(i.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return i[0]-i[1]},parseChildren:G},he=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],me=N(he),fe={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:he},ye={propertyAliases:me,operatorData:fe,evaluate:async(e,r)=>{const t=await _(e.values,r);if(r.typeChecker(P(fe.parameters,{values:t})),0===t.length)return 0;if(t.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return t.reduce(((e,r)=>e*r))},parseChildren:G},ge=[{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"}],ve=N(ge),be={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:ge},Te={propertyAliases:ve,operatorData:be,evaluate:async(e,r)=>{const[t,a,s,i]=await _([e.values,e.dividend,e.divisor,e.output],r);r.typeChecker(P(be.parameters,{values:t,dividend:a,divisor:s,output:i}));const n=t??[a,s].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(i){case"quotient":return Math.floor(n[0]/n[1]);case"remainder":return n[0]%n[1];default:return n[0]/n[1]}},parseChildren:G},we=[{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}],Ce=N(we),Ee={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:we},Ae={propertyAliases:Ce,operatorData:Ee,evaluate:async(e,r)=>{const[t,a=!0]=await _([e.values,e.strict],r);if(r.typeChecker(P(Ee.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[s,i]=t;return s===i&&!a||s>i},parseChildren:G},Se=[{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}],qe=N(Se),Oe={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Se},xe={propertyAliases:qe,operatorData:Oe,evaluate:async(e,r)=>{const[t,a=!0]=await _([e.values,e.strict],r);if(r.typeChecker(P(Oe.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[s,i]=t;return s===i&&!a||s<i},parseChildren:G},Ne=[{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"}],Pe=N(Ne),je={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Ne},Le={propertyAliases:Pe,operatorData:je,evaluate:async(e,r)=>{r.typeChecker(P(je.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return await Q(e.condition,r)?await Q(e.valueIfTrue,r):await Q(e.valueIfFalse,r)},parseChildren:e=>{const[r,t,a]=e.children;return{...e,condition:r,valueIfTrue:t,valueIfFalse:a}}},ke=[{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}$"}],Ie=N(ke),Ue={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:ke},Re={propertyAliases:Ie,operatorData:Ue,evaluate:async(e,r)=>{const[t,a]=await _([e.testString,e.pattern],r);r.typeChecker(P(Ue.parameters,{testString:t,pattern:a}));return new RegExp(a).test(t)},parseChildren:e=>{const[r,t]=e.children;return{...e,testString:r,pattern:t}}},De=[{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","array"],default:{}}],Qe=N(De),_e={description:"Extract values from data objects",aliases:["getData","dataProperties","data","objectProperties","objProps","getProperty","getObjProp"],parameters:De},Fe={propertyAliases:Qe,operatorData:_e,evaluate:async(r,t)=>{const[a,s={}]=await _([r.property,r.additionalData],t);t.typeChecker(P(_e.parameters,{property:a,additionalData:s}));const i={...t.options?.data??{},...s};return e(i,a)},parseChildren:e=>{const[r,t]=e.children,a={...e,property:r};return void 0!==t&&(a.fallback=t),a}},$e=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string",default:"Hello, %1"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!1,type:["array","object"],default:{}},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],Me=N($e),He={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:$e},Be={propertyAliases:Me,operatorData:He,evaluate:async(e,r)=>{const[t,a={},s=!0,i="%",n={}]=await _([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],r);if(r.typeChecker(P(He.parameters,{string:t,substitutions:a,trimWhiteSpace:s,substitutionCharacter:i,numberMapping:n})),Array.isArray(a)){const e="$"===i?"$":"%",r=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(t.match(r)||[]).sort(((e,r)=>Number(e.slice(1))-Number(r.slice(1)))),o=new Set(n),l=j(Array.from(o),a.map((e=>s?String(e).trim():e)));return t.split(r).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}const o=/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g,l=[];for(const e of t.split(o)){if(!/(?<!\\){{(.+)}}/.exec(e)){l.push(e.replace("\\{{","{{"));continue}const t=await Ge(e,a,n,r);l.push(s?String(t).trim():t)}return l.join("")},parseChildren:e=>{const[r,...t]=e.children;return{...e,string:r,substitutions:t}}},Ge=async(r,t,a,s)=>{const i=s.options?.data??{},n=r.replace(/{{(.+)}}/,"$1"),o=await Q(e(t,n,e(i,n,"")),s);if("number"!=typeof o)return o;if(!(n in a))return o;const l=a[n];if(o in l)return l[o].replace("{}",String(o));const u=Object.keys(a[n]),p=u.find((e=>e.startsWith(">")));if(p){if(o>Number(p.slice(1)))return l?.[p]}const c=u.find((e=>e.startsWith("<")));if(c){if(o<Number(c.slice(1)))return l?.[c]}return l.other?l.other.replace("{}",String(o)):o},ze=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],We=N(ze),Je={description:"Count elements in an array",aliases:["count","length"],parameters:ze},Ve={propertyAliases:We,operatorData:Je,evaluate:async(e,r)=>{const t=await _(e.values,r);return r.typeChecker(P(Je.parameters,{values:t})),t.length},parseChildren:G},Ye=[{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}],Xe=N(Ye),Ze={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:Ye},Ke=" ",er={propertyAliases:Xe,operatorData:Ze,evaluate:async(e,r)=>{const[t,a,s,i]=await _([e.value,e.delimiter??Ke,e.trimWhiteSpace??!0,e.excludeTrailing??!0],r);r.typeChecker(P(Ze.parameters,{value:t,delimiter:a,trimWhiteSpace:s,excludeTrailing:i}));let n=t.split(a);return s&&(n=n.map((e=>e.trim()))),i&&""===n[n.length-1]&&n.pop(),n},parseChildren:e=>{const[r,t=Ke]=e.children;return{...e,value:r,delimiter:t}}},rr=[{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"}],tr=N(rr),ar={description:"Query an SQL database",aliases:["sql","pgSql","postgres","pg","sqLite","sqlite","mySql"],parameters:rr},sr={propertyAliases:tr,operatorData:ar,evaluate:async(e,r)=>{const t=r.options?.sqlConnection;if(!t)throw new Error("No SQL database connection provided");const[a,s,i,n,o,l]=await _([e.query,e.values||[],e.single,e.flatten,e.useCache,e.type],r);r.typeChecker(P(ar.parameters,{query:a,single:i,flatten:n,values:s,useCache:o}));const u=e.useCache??r.options.useCache??!0;{const e=r.cache.useCache(u,(async(e,r,a,s,i)=>{const n=await t.query({query:e,values:r})||[];["array","string","number"].includes(i??"")&&(s=!0);const o=s?n.map((e=>{const r=Object.values(e);return r.length<=1?r[0]:r})):n;return a?o[0]:o}),a,s,i,n,l);return e}},parseChildren:e=>{const[r,...t]=e.children;return{...e,query:r,values:t}}},ir=[{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}],nr=N(ir),or={description:"GraphQL request",aliases:["graphQL","graphQl","graphql","gql"],parameters:ir},lr={propertyAliases:nr,operatorData:or,evaluate:async(e,r)=>{const t=r.graphQLClient??r.httpClient;if(!t)throw new Error("No HTTP client provided for GraphQL connection");const[a,s,i,n,o,l]=await _([e.query,e.url,await $(e.variables,r),e.returnNode,e.headers,e.useCache],r),{url:u,headers:p}=s instanceof Object?s:{url:s,headers:null};r.typeChecker([...P(or.parameters,{url:u,query:a,variables:i,returnNode:n,headers:o,useCache:l}),{name:"headers",value:p,expectedType:["object","null"]}]);const c=u&&"graphqlendpoint"!==u.toLowerCase()?u:"",d=r.options.graphQLConnection?.endpoint??r.options.baseEndpoint??"",h=U(c)?c:R(d,c),m={query:a,variables:i},f=l??r.options.useCache??!0,y=await r.cache.useCache(f,(async(e,r,a,s)=>{const i=await D(t,{url:e,method:"post",data:r,headers:a});return I(i?.data,s)}),h,m,{...r.options.graphQLConnection?.headers,...r.options?.headers,...p,...o},n);return y},parseChildren:e=>{const[r,t="",a,...s]=e.children,i=Array.isArray(a)?a:[a],n=s.slice(0,i.length),o=j(i,n),l={...e,query:r,url:t,variables:o};return s.length>i.length&&(l.returnNode=s.pop()),l}},ur=[{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}],pr=N(ur),cr={description:"HTTP GET Request",aliases:["GET","get","api"],parameters:ur},dr=e=>{const[r="",t,...a]=e.children,s=Array.isArray(t)?t:[t],i=a.slice(0,s.length),n=j(s,i),o={...e,url:r,parameters:n};return a.length>s.length&&(o.returnProperty=a.pop()),o},hr=dr,mr={propertyAliases:pr,operatorData:cr,evaluate:async(e,r)=>{const t=r.httpClient;if(!t)throw new Error("No HTTP client provided");const[a,s,i,n,o]=await _([e.url,await $(e.parameters,r),e.returnProperty,await $(e.headers,r),e.useCache],r),{url:l,headers:u}=a instanceof Object?a:{url:a,headers:null};r.typeChecker([...P(cr.parameters,{url:l,returnProperty:i,headers:n,parameters:s,useCache:o}),{name:"headers",value:u,expectedType:["object","null"]}]);const p=r.options.baseEndpoint??"",c={...r.options?.headers,...u,...n},d=o??r.options.useCache??!0,h=await r.cache.useCache(d,(async(e,r,a,s)=>{const i=await D(t,{url:e,params:r,headers:a});return I(i,s)}),U(l)?l:R(p,l),s,c,i);return h},parseChildren:dr},fr=[{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}],yr=N(fr),gr={description:"HTTP POST Request",aliases:["POST","post"],parameters:fr},vr={propertyAliases:yr,operatorData:gr,evaluate:async(e,r)=>{const t=r.httpClient;if(!t)throw new Error("No HTTP client provided");const[a,s,i,n,o]=await _([e.url,await $(e.parameters,r),e.returnProperty,await $(e.headers,r),e.useCache],r),{url:l,headers:u}=a instanceof Object?a:{url:a,headers:null};r.typeChecker([...P(gr.parameters,{url:l,headers:n,data:s,returnProperty:i,useCache:o}),{name:"headers",value:u,expectedType:["object","null"]}]);const p=r.options.baseEndpoint??"",c={...r.options?.headers,...u,...n},d=o??r.options.useCache??!1,h=await r.cache.useCache(d,(async(e,r,a,s)=>{const i=await D(t,{url:e,data:r,headers:a,method:"post"});return I(i,s)}),U(l)?l:R(p,l),s,c,i);return h},parseChildren:hr},br=[{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"]}],Tr=N(br),wr={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:br},Cr=e=>{const r=e.children;if(r.every((e=>f(e))))return{...e,properties:r};if(r.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=r.filter(((e,r)=>r%2==0)),a=r.filter(((e,r)=>r%2==1)),s=t.map(((e,r)=>({key:e,value:a[r]})));return{...e,properties:s}},Er={propertyAliases:Tr,operatorData:wr,evaluate:async(e,r)=>{const t=await _(e.properties,r);r.typeChecker(P(wr.parameters,{properties:t}));const{properties:a}=t.some((e=>!f(e)))?await Cr({...e,children:t}):{properties:t},s=a.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:t})=>(async e=>{const[t,a]=await _(e,r);return r.typeChecker({name:"key",value:t,expectedType:["string","number","boolean"]}),[t,a]})([e,t])));return Object.fromEntries(await Promise.all(s))},parseChildren:Cr},Ar=[{name:"matchExpression",description:"Expression to match against",aliases:["matchValue"],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"]}],Sr={propertyAliases:N(Ar),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:Ar},evaluate:async(e,r)=>{const a=await Q(e.matchExpression,r);r.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const s=Array.isArray(e.branches)?L(e.branches):e.branches??{},i=t(s)?await Q(s,r):s;if(!f(i))throw new Error("Branches don't evaluate to an object");if(a in i)return await Q(i[a],r);if("fallback"in i)return await Q(i.fallback,r);if(a in e)return await Q(e[a],r);throw new Error(`No match found for ${a}`)},parseChildren:e=>{const[r,...t]=e.children,a=L(t);return{...e,matchExpression:r,branches:a}}},qr=[{name:"functionName",description:"Path (in options.functions) to the required function",aliases:["functionPath","funcName","function","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:["array","any"],default:[]},{name:"input",description:"Argument for the function if a single input parameter",aliases:["arg"],required:!1,type:"any",default:"input"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],Or=N(qr),xr={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:qr},Nr={propertyAliases:Or,operatorData:xr,evaluate:async(r,t)=>{const[a,s=[],i,n]=await _([r.functionName,r.args,r.input,r.useCache],t);t.typeChecker(P(xr.parameters,{functionName:a,args:s}));const{data:o,functions:l}=t.options;if(!l)throw new Error("- No functions defined");const u=e(l,`${a}.function`,null)??e(l,a,null)??e(t.options,`${a}.function`,null)??e(t.options,a,null)??e(o,a,null);if(!u||"function"!=typeof u)throw new Error(`- No function found: "${a}"`);const p=n??t.options.useCache??!1,c=[...void 0===i?[]:[await $(i,t)],...Array.isArray(s)?s:[s]];return await t.cache.useCache(p,(async(e,...r)=>await u(...r)),a,...c)},parseChildren:e=>{const[r,...t]=e.children;return{...e,functionName:r,args:t}}},Pr=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],jr=N(Pr),Lr={description:"Pass through a value unchanged (or change its type)",aliases:["pass","_","passThru","passthru","ignore","coerce","convert"],parameters:Pr},kr={propertyAliases:jr,operatorData:Lr,evaluate:async(e,r)=>(r.typeChecker(P(Lr.parameters,{value:e.value})),await Q(e.value,r)),parseChildren:e=>{const[...r]=e.children,t=1===r?.length?r[0]:r;return{...e,value:t}}};var Ir=Object.freeze({__proto__:null,AND:z,BUILD_OBJECT:Er,CONDITIONAL:Le,COUNT:Ve,CUSTOM_FUNCTIONS:Nr,DIVIDE:Te,EQUAL:ee,GET:mr,GRAPHQL:lr,GREATER_THAN:Ae,LESS_THAN:xe,MATCH:Sr,MULTIPLY:ye,NOT_EQUAL:se,OBJECT_PROPERTIES:Fe,OR:Y,PASSTHRU:kr,PLUS:le,POST:vr,REGEX:Re,SPLIT:er,SQL:sr,STRING_SUBSTITUTION:Be,SUBTRACT:de});class Ur{constructor(e){this.useCache=async(e,r,...t)=>{if(!e)return await r(...t);const a=Rr(t),s=a in this.store,i=Date.now(),n=s&&i-this.store[a].timestamp>1e3*this.maxTime;if(s)return this.queue=this.queue.filter((e=>e!==a)),this.queue.unshift(a),this.store[a].timestamp=i,n&&(this.store[a].result=await r(...t)),this.store[a].result;const o=await r(...t);return this.store[a]={result:o,timestamp:i},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=e?.maxSize??50,this.maxTime=e?.maxTime??1800}}const Rr=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),Dr=e=>e||("undefined"!=typeof window&&"document"in window&&"fetch"in window?Qr(window.fetch):void 0),Qr=e=>({get:async r=>{const{url:t,headers:a,params:s={}}=r,i=Object.keys(s).length>0?`?${new URLSearchParams(s).toString()}`:"",n=await e(t+i,{headers:a,method:"GET"}),o=await n.json();if(!n.ok){const e=new Error("Problem with GET request");throw e.name="FetchError",e.errorData={status:n.status,error:n.statusText,url:n.url,response:o},console.log(e.errorData),e}return o},post:async r=>{const{url:t,headers:a,params:s,data:i}=r,n=new URLSearchParams(s),o=n.size>0?`?${n.toString()}`:"",l=await e(t+o,{headers:a,body:JSON.stringify(i),method:"POST"}),u=await 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 _r{constructor(e={}){this.typeChecker=(...e)=>{const r=1===e.length&&Array.isArray(e[0])?e[0]:e,t=S(...r);if(!0===t)return;const a=new Error(t);throw a.name="Type Error",a},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.21.4",this.options=Fr(e),this.operators=n(Ir,this.options?.excludeOperators??[],y),this.operatorAliases=y,this.cache=new Ur({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime}),this.graphQLClient=Dr(e.graphQLConnection?.httpClient),this.httpClient=Dr(e.httpClient)}async evaluate(e,r={}){const t=c(this.options,Fr(r),!0);return r.httpClient&&(this.httpClient=Dr(r.httpClient)),r.graphQLConnection?.httpClient&&(this.graphQLClient=Dr(r.graphQLConnection.httpClient)),t.maxCacheSize&&t.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(t.maxCacheSize),t.maxCacheTime&&t.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(t.maxCacheTime),await Q(e,{options:t,operators:r.excludeOperators?n(Ir,r.excludeOperators,y):this.operators,operatorAliases:this.operatorAliases,typeChecker:t.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient})}getOptions(){return this.options}updateOptions(e){this.options=c(this.options,Fr(e),!1),this.options.excludeOperators&&(this.operators=n(Ir,this.options.excludeOperators,y))}getOperators(){const e=this.options.excludeOperators?n(Ir,this.options.excludeOperators,y):this.operators,r=Object.entries(e).map((([e,r])=>({name:e,...r.operatorData,parseChildren:r.parseChildren}))),t=[...new Set(Object.values(y))];return r.sort(((e,r)=>t.indexOf(e.name)-t.indexOf(r.name)))}getFragments(){return Object.entries(this.options.fragments??{}).map((([e,r])=>({name:e,...r?.metadata})))}getCustomFunctions(){return Object.entries(this.options.functions??{}).map((([e,r])=>{const t="function"==typeof r?r:r?.function,a={name:e,numRequiredArgs:t?.length};if("function"!=typeof r){const{description:e,argsDefault:t,inputDefault:s,textColor:i,backgroundColor:n}=r;return e&&(a.description=e),t&&(a.argsDefault=t),s&&(a.inputDefault=s),i&&(a.textColor=i),n&&(a.backgroundColor=n),a}return a}))}getConfig(){return{options:this.options,operators:this.options.excludeOperators?n(Ir,this.options.excludeOperators,y):this.operators,operatorAliases:this.operatorAliases,typeChecker:this.options.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient}}}const Fr=e=>"objects"in e?{...e,data:e.objects}:e,$r=e=>f(e)&&"operator"in e&&"children"in e&&Array.isArray(e.children),Mr=(e,r,t)=>{const a=t.find((r=>r.name===e||r.aliases.includes(e)));if(!a)throw new Error("Invalid operator: "+e);const s=[];if("OBJECT_PROPERTIES"===a.name){if(Hr("additionalData",r,a.parameters))return Object.fromEntries(r);const e=Hr("property",r,a.parameters);if(!e)throw new Error("Missing required property for operator $getData: property");const t=r.find((([e])=>"fallback"===e));return t?[e[1],t[1]]:e[1]}for(const{name:t,aliases:i,required:n}of a.parameters){const a=[t,...i],o=r.find((([e])=>a.includes(e)));if(void 0===o&&n)throw new Error(`Missing required property for operator ${e}: ${t}`);if(void 0===o)break;s.push(o[1])}return s},Hr=(e,r,t)=>{const a=t.find((r=>r.name===e));if(!a)return;const s=[a.name,...a.aliases];return r.find((([e])=>s.includes(e)))},Br=(e,r)=>u(e)&&!r.has(e),Gr=(e,r)=>{if(!e)return;const t=r.find((r=>e===r.name||r.aliases.includes(s(e))));return t?.aliases.find((e=>/^[A-Za-z_]{2,}$/.test(e)))},zr=(e,r={})=>{const t=r[e];if(!t)throw new Error("Fragment referenced in expression that is not defined in FigTree: "+e);const a=JSON.stringify(t).match(/"(\$\w+)"/gm);if(!a)return[];const s=new Set;return a.forEach((e=>s.add(e.replace(/"/g,"")))),Array.from(s)},Wr=(e,r)=>{const t=r.parameters.map((e=>[e.name,...e.aliases])).flat();return Object.keys(e).some((e=>t.includes(e)))};Object.defineProperty(exports,"dequal",{enumerable:!0,get:function(){return r.dequal}}),exports.AxiosClient=e=>({get:async r=>(await e({...r,method:"get"})).data,post:async r=>(await e({...r,method:"post"})).data,throwError:r=>{if(e.isAxiosError(r)&&r.response)throw r.errorData={status:r.response?.status,error:r.response?.statusText,url:r.config?.url,response:r.response?.data},r;throw new Error("Network error: "+r?.message)}}),exports.FetchClient=Qr,exports.FigTreeError=w,exports.FigTreeEvaluator=_r,exports.SQLNodePostgres=e=>({query:async({query:r,values:t=[]})=>{const a={text:r,values:t??[]};try{const r=await e.query(a);if(r?.error)throw new Error(r.error);return r.rows}catch(e){throw e.name="Node-Postgres error",e}}}),exports.SQLite=e=>({query:async({query:r,values:t=[]})=>{try{return await e.all(r,t)}catch(e){throw e.name="SQLite error",e}}}),exports.convertFromShorthand=async(e,r)=>{const i=r.getOperators(),n=r.getFragments(),o=r.getCustomFunctions(),l=n.map((e=>e.name)),u=o.map((e=>e.name)),p=async e=>{if(Array.isArray(e))return await Promise.all(e.map((e=>p(e))));if(!f(e))return e;const n=Object.entries(e);if(0===n.length)return e;const o=n[0][0].replace("$",""),d=s(o),h=i.find((e=>e.name===d||e.aliases.includes(d))),m=l.includes(o),y=u.includes(o);if(h){const e=h.aliases[0],s=n[0][1];if(Array.isArray(s)){const t=await Promise.all(s.map((e=>p(e)))),a=await h.parseChildren({operator:e,children:t},r.getConfig());return delete a.children,{...a,...await c(n)}}const i=await p(s);if(!f(i)||!Wr(i,h)||t(i)||a(i)){return{operator:e,[h.parameters[0].name]:i}}return{operator:e,...i,...await c(n)}}if(m){const r=await p(e[n[0][0]]);if(!f(r))throw new Error("Invalid shorthand Fragment");return{fragment:o,...r,...await c(n)}}if(y){const e=o,r=n[0][1],s=await p(r);if(!f(s)||t(s)||a(s)){return{operator:e,["args"]:s}}return{operator:e,...s,...await c(n)}}return Object.fromEntries(await Promise.all(n.map((async([e,r])=>[e,await p(r)]))))},c=async e=>{const r=e.slice(1);return Object.fromEntries(await Promise.all(r.map((async([e,r])=>[e,await p(r)]))))};return p(e)},exports.convertToShorthand=(e,r,t=2)=>{const a=r.getOperators(),i=r.getFragments(),n=r.getCustomFunctions(),o=r.getOptions().fragments,l=a.map((e=>[e.name,...e.aliases])).flat(),u=i.map((e=>e.name)),p=n.map((e=>e.name)),c=new Set([...l,...u,...p]),d=e=>{if(Array.isArray(e))return e.map((e=>d(e)));if(!f(e))return e;const{operator:r,fragment:i,...n}=e;if(!r&&!i)return Object.fromEntries(Object.entries(e).map((([e,r])=>[e,d(r)])));const l=p.includes(r);i&&n?.parameters&&(Object.entries(n.parameters).forEach((([e,r])=>{n[e]=r})),delete n.parameters);const u=l?r:Gr(r,a),h=`$${u??i}`,m=i?zr(i,o):[],y=Object.keys(n).filter((e=>Br(e,c)&&!m.includes(e))),g=Object.entries(n).filter((([e])=>!y.includes(e)&&!m.includes(e))).map((([e,r])=>[e,d(r)])),v=Object.fromEntries(y.map((e=>[e,d(n[e])]))),b=Object.fromEntries(m.map((e=>[e,d(n[e])])));switch(!0){case Object.keys(b).length>0:return{[h]:b,...v};case l:return 1!==g.length||"input"in n?{[h]:Object.fromEntries(g),...v}:{[h]:g[0][1]};case"values"in n:return 1===g.length?{[h]:g[0][1]}:{[h]:Object.fromEntries(g),...v};case"match"===u:return{[h]:Object.fromEntries(g),...v};case g.length>t||!!i||g.some((([e])=>"useCache"===e||"outputType"===e))||g.some((e=>Array.isArray(e[1]))):return{[h]:Object.fromEntries(g),...v};case 1===g.length:return{[h]:g[0][1],...v};default:return{[h]:Mr(s(r),g,a),...v}}};return d(e)},exports.convertV1ToV2=async(e,r)=>{const t=r.getOperators(),a=async e=>{if(!f(e))return e;const i=$r(e)?await(async()=>{const{operator:a}=e,i=s(a),n=t.find((e=>e.name===i||e.aliases.includes(i)));if(n){const t=await n.parseChildren(e,r.getConfig());delete t.children;const a=n.aliases[0];return t.operator=a,t}throw new Error("Invalid operator: "+a)})():e,n={};for(const[e,r]of Object.entries(i)){const t="type"===e?"outputType":e;if(Array.isArray(r)){const e=r.map((e=>a(e))),s=await Promise.all(e);n[t]=s}else n[t]=await a(r)}return n};return a(e)},exports.evaluateExpression=(e,r)=>new _r(r).evaluate(e),exports.isAliasString=u,exports.isFigTreeError=e=>e instanceof w,exports.isFigTreeExpression=e=>t(e)||a(e)||"string"==typeof e&&u(e)||f(e)&&1===Object.keys(e).length&&u(Object.keys(e)[0]),exports.isFragmentNode=a,exports.isObject=f,exports.isOperatorNode=t,exports.isV1Node=$r,exports.preProcessShorthand=v,exports.standardiseOperatorName=s,exports.truncateString=o;
|
package/build/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"object-property-extractor";import{dequal as r}from"dequal/lite";export{dequal}from"dequal/lite";function t(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&r.indexOf(i)<0&&(t[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(i=Object.getOwnPropertySymbols(e);a<i.length;a++)r.indexOf(i[a])<0&&Object.prototype.propertyIsEnumerable.call(e,i[a])&&(t[i[a]]=e[i[a]])}return t}function i(e,r,t,i){return new(t||(t=Promise))((function(a,n){function s(e){try{l(i.next(e))}catch(e){n(e)}}function o(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var r;e.done?a(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(s,o)}l((i=i.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const a=e=>e instanceof Object&&"operator"in e,n=e=>e instanceof Object&&"fragment"in e,s=e=>{const r=m(e);return r||e},o=(e,r)=>r[s(e)],l=(e,r,t)=>{const i=Object.assign({},e);return r.forEach((e=>{t[s(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete i[t[s(e)]]})),i},u=(e,r=200)=>e.length<r?e:`${e.slice(0,r-2).trim()}...`,d=(e,r)=>{const t=Object.entries(e).map((([e,t])=>[r(e),t]));return Object.fromEntries(t)},c=e=>/^\$.+/.test(e),p=(e,{resolvedAliasNodes:r})=>{var t;return"string"==typeof e&&c(e)&&null!==(t=null==r?void 0:r[e])&&void 0!==t?t:e},h=(e,r,t)=>{const i=Object.assign(Object.assign({},e),r);return t?((e.data||r.data)&&(i.data=Object.assign(Object.assign({},e.data),r.data)),(e.functions||r.functions)&&(i.functions=Object.assign(Object.assign({},e.functions),r.functions)),(e.fragments||r.fragments)&&(i.fragments=Object.assign(Object.assign({},e.fragments),r.fragments)),(e.headers||r.headers)&&(i.headers=Object.assign(Object.assign({},e.headers),r.headers)),i):i},v={number:e=>f(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},f=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const r=new RegExp(/-?\d*\.?\d+/gm),t=e.match(r);return t?Number(t[0]):0},m=e=>e.replace(/[^A-Za-z\d _-]/g,"").split(/[-_ ]/).map((e=>{var r;return null!==(r=e.match(/[a-z]+|[A-Z]+[a-z]*/g))&&void 0!==r?r:e})).flat().filter((e=>""!==e)).map(((e,r)=>0===r?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""),y=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),g=e=>a(e)||n(e)||"string"==typeof e&&c(e)||y(e)&&1===Object.keys(e).length&&c(Object.keys(e)[0]),b={and:"AND","&":"AND","&&":"AND",or:"OR","|":"OR","||":"OR","=":"EQUAL",eq:"EQUAL",equal:"EQUAL",equals:"EQUAL","!=":"NOT_EQUAL",notEqual:"NOT_EQUAL","!":"NOT_EQUAL",ne:"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",getData:"OBJECT_PROPERTIES",dataProperties:"OBJECT_PROPERTIES",data:"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",get:"GET",api:"GET",POST:"POST",post:"POST",sql:"SQL",pgSql:"SQL",postgres:"SQL",pg:"SQL",sqLite:"SQL",sqlite:"SQL",mySql:"SQL",graphQL:"GRAPHQL",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",pass:"PASSTHRU",_:"PASSTHRU",passThru:"PASSTHRU",passthru:"PASSTHRU",ignore:"PASSTHRU",coerce:"PASSTHRU",convert:"PASSTHRU"},O=b,T=(e,r={},t,i=!0)=>i&&y(e)?j(e,r,t):e,j=(e,r,t)=>{if(a(e)||n(e))return e;const i=Object.entries(e),s=i.filter((([e])=>c(e))),o=i.filter((([e])=>!c(e))),l=s.reduce(((e,[i,a])=>e=Object.assign(Object.assign({},e),C(i,a,r,t))),{});return Object.assign(Object.assign({},l),Object.fromEntries(o))},C=(e,r,t,i)=>{const a=e.slice(1),n=o(a,O);return n?Array.isArray(r)?{operator:n,children:r}:y(r)&&!Object.keys(r).some((e=>c(e)))?Object.assign({operator:n},r):{operator:n,children:[r]}:a in t?{fragment:a,parameters:Object.assign({},r)}:i.includes(a)?Array.isArray(r)?{operator:a,args:r}:y(r)?"input"in r||"args"in r?Object.assign({operator:a},r):{operator:a,input:r}:{operator:a,args:[r]}:{[e]:r}};class E extends Error{constructor(e,r,t,i){super(e.message),Object.assign(this,e),this.operator=r,this.expression=i,this.errorData=e.errorData,t&&(this.name=t),"Error"===this.name&&(this.name="FigTreeError");const a=(r?"Operator: "+r:"")+("FigTreeError"===this.name?"":` - ${this.name}`),n=this.errorData?"\n"+JSON.stringify(this.errorData,null,2):"";this.prettyPrint=`${""!==a?a+"\n":""}${this.message}${"\n{}"===n?"":n}`}}const A=e=>e instanceof E,S=({fallback:e,operator:r,name:t,error:i,expression:a,returnErrorAsString:n=!1})=>{if(void 0!==e)return e;if(i instanceof E){if(!n)throw i;return i.prettyPrint}const s=new E("string"==typeof i?new Error(i):i,r,t,a);if(n)return s.prettyPrint;throw s},q=e=>y(e)&&"literal"in e,w=({value:e,name:r,expectedType:t})=>{if(q(t)){const{literal:i}=t;return!!i.includes(e)||x(r,e,`Literal(${i.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(t))return!!t.some((t=>!0===w({value:e,name:r,expectedType:t})))||x(r,e,t.join("|"));return!!(0,P[t])(e)||x(r,e,t)},N=(...e)=>{const r=[];return e.forEach((e=>{const t=w(e);!0!==t&&r.push(t)})),!(r.length>0)||r.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=>y(e),undefined:e=>void 0===e},x=(e,r,t)=>void 0===r&&e?`- Missing required property "${e}" (type: ${t})`:void 0!==e?`- Property "${e}" (value: ${k(r)}) is not of type: ${t}`:`- ${k(r)} is not of type: ${t}`,k=e=>{const r=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return u(r,50)},L=e=>{const r={};return e.forEach((e=>{e.aliases.forEach((t=>r[t]=e.name))})),r},I=(e,r)=>e.map((({name:e,required:t,type:i})=>{if(q(i)){const a=[...i.literal];return t||a.push(void 0),{name:e,value:r[e],expectedType:{literal:a}}}const a=Array.isArray(i)?i:[i];t||a.push("undefined");const n=1===a.length?a[0]:a;return{name:e,value:r[e],expectedType:n}})),U=(e,r)=>{const t=e.map(((e,t)=>[e,r[t]]));return Object.fromEntries(t)},R=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=e.filter(((e,r)=>r%2==0)),t=N(...r.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==t)throw new Error(t);const i=e.filter(((e,r)=>r%2==1)),a={};return r.forEach(((e,r)=>{a[e]=i[r]})),a},D=e=>y(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,_=(r,t,i=void 0)=>{const a=t?e(r,t,i):r;return Array.isArray(a)?a.map((e=>D(e))):t?null===a?null:D(a):a},Q=e=>/^https?:\/\/.+/.test(e),$=(...e)=>e.reduce(((e,r,t)=>{const i="/"===r[0]?1:0,a="/"===r.slice(-1)?-1:void 0,n=r.slice(i,a);return""===n?e:e+(0===t?"":"/")+n}),""),F=(e,r)=>i(void 0,void 0,void 0,(function*(){const{url:t,params:i={},data:a={},headers:n={},method:s="get"}=r;if(!t||""===t)throw new Error("Invalid url");try{return yield e[s]({url:t,headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},n),params:i,data:a})}catch(r){e.throwError(r)}})),M=(e,r)=>i(void 0,void 0,void 0,(function*(){var s,l,u,c,h,f,m,g,b,O;const{options:j,operators:C,operatorAliases:E}=r;let A=(null==j?void 0:j.allowJSONStringInput)?(e=>{if("string"!=typeof e)return e;try{const r=JSON.parse(e);return a(r)?r:e}catch(r){return e}})(e):e;const q=Object.keys(null!==(l=null===(s=r.options)||void 0===s?void 0:s.functions)&&void 0!==l?l:{});A=T(A,null===(u=r.options)||void 0===u?void 0:u.fragments,q,!j.noShorthand),Array.isArray(A)&&(A=yield H(A,r));const w=a(A),N=n(A);if(w&&(A=yield((e,r)=>i(void 0,void 0,void 0,(function*(){var i,a;if(!(e.operator in(null!==(a=null===(i=r.options)||void 0===i?void 0:i.functions)&&void 0!==a?a:{})))return e;const{operator:n,fallback:s,outputType:o,type:l,useCache:u,input:d,args:c}=e,p=t(e,["operator","fallback","outputType","type","useCache","input","args"]),h={operator:"CUSTOM_FUNCTIONS",function:n};return void 0!==s&&(h.fallback=s),void 0!==o&&(h.outputType=o),void 0!==l&&(h.type=l),void 0!==u&&(h.useCache=u),void 0!==c&&(h.args=c),void 0!==d?h.input=d:Object.keys(p).length>0&&(h.input=p),h})))(A,r)),j.evaluateFullObject&&!w&&!N)return p(yield G(A,r),r);if(!w&&!N)return j.supportDeprecatedValueNodes&&y(A)&&"value"in A?A.value:p(A,r);const{fallback:P}=A,x=null!==(c=null==j?void 0:j.returnErrorAsString)&&void 0!==c&&c;if(N){const e=Object.assign({},A),t=null===(g=null===(m=null===(f=null===(h=null==j?void 0:j.fragments)||void 0===h?void 0:h[e.fragment])||void 0===f?void 0:f.metadata)||void 0===m?void 0:m.parameters)||void 0===g?void 0:g.filter((e=>void 0!==e.default));void 0===e.parameters&&(e.parameters={}),null==t||t.forEach((r=>{var t;void 0===(null===(t=e.parameters)||void 0===t?void 0:t[r.name])&&void 0===(null==e?void 0:e[r.name])&&(e.parameters[r.name]=r.default)}));const[i,n]=yield H([e.fragment,e.parameters],r),s=T(null===(b=null==j?void 0:j.fragments)||void 0===b?void 0:b[i],j.fragments,q,!j.noShorthand);if(void 0===s)return S({fallback:yield M(P,r),error:`Fragment not defined: ${i}`,expression:A,returnErrorAsString:x});if(!a(s))return p(s,r);A=Object.assign(Object.assign(Object.assign({},e),s),n),delete A.fragment}const k=A,L=o(k.operator,E);if(!L)return S({fallback:yield M(P,r),error:`Invalid operator: ${k.operator}`,expression:A,returnErrorAsString:x});if(!r.operators[L])return S({fallback:yield M(P,r),error:`Excluded operator: ${k.operator}`,expression:A,returnErrorAsString:x});const{propertyAliases:I,evaluate:U,parseChildren:R}=C[L];let D=((e,r)=>d(r,(r=>r in e?e[r]:r)))(I,k);const _=yield B(D,r);N||Object.entries(_).forEach((([e,t])=>r.resolvedAliasNodes[e]=t));const Q=N?Object.assign(Object.assign({},r),{resolvedAliasNodes:Object.assign(Object.assign({},r.resolvedAliasNodes),_)}):r;if("children"in D){if(Array.isArray(D.children)||(D.children=yield M(D.children,Q)),!Array.isArray(D.children))return S({fallback:yield M(P,r),operator:L,name:"Type Error",error:'- Property "children" is not of type: array',expression:A,returnErrorAsString:x});try{D=yield R(D,Q),delete D.children}catch(e){return S({fallback:yield M(D.fallback,r),operator:L,error:e,expression:D,returnErrorAsString:x})}}let $;try{$=yield U(D,Q)}catch(e){return S({fallback:yield M(D.fallback,r),operator:L,error:e,expression:D,returnErrorAsString:x})}const F=null!==(O=null==D?void 0:D.outputType)&&void 0!==O?O:null==D?void 0:D.type;if(!F)return $;const z=yield M(F,r);return z in v?v[z]($):S({fallback:yield M(P,r),operator:L,error:`- Invalid output type: ${z}`,expression:D,returnErrorAsString:x})})),H=(e,r)=>i(void 0,void 0,void 0,(function*(){return Array.isArray(e)?yield Promise.all(e.map((e=>M(e,r)))):yield M(e,r)})),B=(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const i=Object.keys(e).filter(c);if(0===i.length)return{};const a=[];i.forEach((t=>a.push(M(e[t],r))));const n=yield Promise.all(a),s=U(i,yield Promise.all(a));for(const[e,r]of n.entries())"string"==typeof r&&c(r)&&(s[i[e]]=null!==(t=null==s?void 0:s[r])&&void 0!==t?t:r);return s})),G=(e,r)=>i(void 0,void 0,void 0,(function*(){var t,i,a;const n=Object.keys(null!==(i=null===(t=r.options)||void 0===t?void 0:t.functions)&&void 0!==i?i:{}),s=T(e,null===(a=r.options)||void 0===a?void 0:a.fragments,n);if(!y(s))return e;const o=[],l=[];Object.entries(s).forEach((([e,t])=>{c(e)&&(l.push(e,M(t,r)),delete s[e])}));const u=yield Promise.all(l);r.resolvedAliasNodes=Object.assign(Object.assign({},r.resolvedAliasNodes),R(u)),Object.entries(s).forEach((([e,t])=>{o.push(e,M(t,r))}));const d=yield Promise.all(o);return p(R(d),r)})),z=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],W=L(z),J={description:"Logical AND",aliases:["and","&","&&"],parameters:z},V=e=>{const r=e.children;return Object.assign(Object.assign({},e),{values:r})},Y={propertyAliases:W,operatorData:J,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield H(e.values,r);return r.typeChecker(I(J.parameters,{values:t})),t.reduce(((e,r)=>e&&!!r),!0)})),parseChildren:V},X=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],Z=L(X),K={description:"Logical OR",aliases:["or","|","||"],parameters:X},ee={propertyAliases:Z,operatorData:K,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield H(e.values,r);return r.typeChecker(I(K.parameters,{values:t})),t.reduce(((e,r)=>e||!!r),!1)})),parseChildren:V},re=[{name:"values",description:"Array of values to check for equality",aliases:[],required:!0,type:"array",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}],te=L(re),ie={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:re},ae={propertyAliases:te,operatorData:ie,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var i,a,n;const[s,o,l]=yield H([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(I(ie.parameters,{values:s,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(a=null===(i=t.options)||void 0===i?void 0:i.caseInsensitive)&&void 0!==a&&a)&&s.every((e=>"string"==typeof e))?s.map((e=>e.toLowerCase())):s;return!(void 0!==l?l:void 0!==(null===(n=t.options)||void 0===n?void 0:n.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},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}],se=L(ne),oe={description:"Test if any values are different",aliases:["!=","notEqual","!","ne"],parameters:ne},le={propertyAliases:se,operatorData:oe,evaluate:(e,t)=>i(void 0,void 0,void 0,(function*(){var i,a,n;const[s,o,l]=yield H([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(I(oe.parameters,{values:s,caseInsensitive:o,nullEqualsUndefined:l}));const u=(void 0!==o?o:null!==(a=null===(i=t.options)||void 0===i?void 0:i.caseInsensitive)&&void 0!==a&&a)&&s.every((e=>"string"==typeof e))?s.map((e=>e.toLowerCase())):s;return!(void 0!==l?l:void 0!==(null===(n=t.options)||void 0===n?void 0:n.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=L(ue),ce={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:ue},pe={propertyAliases:de,operatorData:ce,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield H(e.values,r);return r.typeChecker(I(ce.parameters,{values:t,type:e.type})),0===t.length?t:"string"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),""):"array"===(null==e?void 0:e.type)?t.reduce(((e,r)=>e.concat(r)),[]):t.every((e=>"string"==typeof e||Array.isArray(e)))?t.reduce(((e,r)=>e.concat(r))):t.every((e=>y(e)))?t.reduce(((e,r)=>Object.assign(Object.assign({},e),r)),{}):t.reduce(((e,r)=>e+r))})),parseChildren:V},he=[{name:"values",description:"Array of values - 2nd element will be subtracted from the first",aliases:[],required:!1,type:"array",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=L(he),fe={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:he},me={propertyAliases:ve,operatorData:fe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i,a]=yield H([e.values,e.from,e.subtract],r);r.typeChecker(I(fe.parameters,{values:t,from:i,subtract:a}));const n=null!=t?t:[i,a].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");return n[0]-n[1]})),parseChildren:V},ye=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],ge=L(ye),be={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:ye},Oe={propertyAliases:ge,operatorData:be,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield H(e.values,r);if(r.typeChecker(I(be.parameters,{values:t})),0===t.length)return 0;if(t.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return t.reduce(((e,r)=>e*r))})),parseChildren:V},Te=[{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"}],je=L(Te),Ce={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:Te},Ee={propertyAliases:je,operatorData:Ce,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i,a,n]=yield H([e.values,e.dividend,e.divisor,e.output],r);r.typeChecker(I(Ce.parameters,{values:t,dividend:i,divisor:a,output:n}));const s=null!=t?t:[i,a].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");if(0===s[1])throw new Error("Division by zero!");switch(n){case"quotient":return Math.floor(s[0]/s[1]);case"remainder":return s[0]%s[1];default:return s[0]/s[1]}})),parseChildren:V},Ae=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array",default:[10,9]},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],Se=L(Ae),qe={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Ae},we={propertyAliases:Se,operatorData:qe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i=!0]=yield H([e.values,e.strict],r);if(r.typeChecker(I(qe.parameters,{values:t,strict:i})),t.length<2)throw new Error("- Not enough values provided");const[a,n]=t;return a===n&&!i||a>n})),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=L(Ne),xe={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Ne},ke={propertyAliases:Pe,operatorData:xe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i=!0]=yield H([e.values,e.strict],r);if(r.typeChecker(I(xe.parameters,{values:t,strict:i})),t.length<2)throw new Error("- Not enough values provided");const[a,n]=t;return a===n&&!i||a<n})),parseChildren:V},Le=[{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"}],Ie=L(Le),Ue={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:Le},Re={propertyAliases:Ie,operatorData:Ue,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){r.typeChecker(I(Ue.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return(yield M(e.condition,r))?yield M(e.valueIfTrue,r):yield M(e.valueIfFalse,r)})),parseChildren:e=>{const[r,t,i]=e.children;return Object.assign(Object.assign({},e),{condition:r,valueIfTrue:t,valueIfFalse:i})}},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=L(De),Qe={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:De},$e={propertyAliases:_e,operatorData:Qe,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const[t,i]=yield H([e.testString,e.pattern],r);r.typeChecker(I(Qe.parameters,{testString:t,pattern:i}));return new RegExp(i).test(t)})),parseChildren:e=>{const[r,t]=e.children;return Object.assign(Object.assign({},e),{testString:r,pattern:t})}},Fe=[{name:"property",description:'The path to the required property (e.g. "user.firstName")',aliases:["path","propertyName"],required:!0,type:"string",default:"path.to[0].my.data"},{name:"additionalData",description:"Additional data objects to be considered",aliases:["additional","objects","data","additionalObjects"],required:!1,type:["object","array"],default:{}}],Me=L(Fe),He={description:"Extract values from data objects",aliases:["getData","dataProperties","data","objectProperties","objProps","getProperty","getObjProp"],parameters:Fe},Be={propertyAliases:Me,operatorData:He,evaluate:(r,t)=>i(void 0,void 0,void 0,(function*(){var i,a;const[n,s={}]=yield H([r.property,r.additionalData],t);t.typeChecker(I(He.parameters,{property:n,additionalData:s}));const o=Object.assign(Object.assign({},null!==(a=null===(i=t.options)||void 0===i?void 0:i.data)&&void 0!==a?a:{}),s);return e(o,n)})),parseChildren:e=>{const[r,t]=e.children,i=Object.assign(Object.assign({},e),{property:r});return void 0!==t&&(i.fallback=t),i}},Ge=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string",default:"Hello, %1"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!1,type:["array","object"],default:{}},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],ze=L(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,r)=>i(void 0,void 0,void 0,(function*(){const[t,i={},a=!0,n="%",s={}]=yield H([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],r);if(r.typeChecker(I(We.parameters,{string:t,substitutions:i,trimWhiteSpace:a,substitutionCharacter:n,numberMapping:s})),Array.isArray(i)){const e="$"===n?"$":"%",r=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),s=(t.match(r)||[]).sort(((e,r)=>Number(e.slice(1))-Number(r.slice(1)))),o=new Set(s),l=U(Array.from(o),i.map((e=>a?String(e).trim():e)));return t.split(r).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}const o=/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g,l=[];for(const e of t.split(o)){if(!/(?<!\\){{(.+)}}/.exec(e)){l.push(e.replace("\\{{","{{"));continue}const t=yield Ve(e,i,s,r);l.push(a?String(t).trim():t)}return l.join("")})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{string:r,substitutions:t})}},Ve=(r,t,a,n)=>i(void 0,void 0,void 0,(function*(){var i,s;const o=null!==(s=null===(i=n.options)||void 0===i?void 0:i.data)&&void 0!==s?s:{},l=r.replace(/{{(.+)}}/,"$1"),u=yield M(e(t,l,e(o,l,"")),n);if("number"!=typeof u)return u;if(!(l in a))return u;const d=a[l];if(u in d)return d[u].replace("{}",String(u));const c=Object.keys(a[l]),p=c.find((e=>e.startsWith(">")));if(p){if(u>Number(p.slice(1)))return null==d?void 0:d[p]}const h=c.find((e=>e.startsWith("<")));if(h){if(u<Number(h.slice(1)))return null==d?void 0:d[h]}return d.other?d.other.replace("{}",String(u)):u})),Ye=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Xe=L(Ye),Ze={description:"Count elements in an array",aliases:["count","length"],parameters:Ye},Ke={propertyAliases:Xe,operatorData:Ze,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield H(e.values,r);return r.typeChecker(I(Ze.parameters,{values:t})),t.length})),parseChildren:V},er=[{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}],rr=L(er),tr={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:er},ir=" ",ar={propertyAliases:rr,operatorData:tr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,i,a;const[n,s,o,l]=yield H([e.value,null!==(t=e.delimiter)&&void 0!==t?t:ir,null===(i=e.trimWhiteSpace)||void 0===i||i,null===(a=e.excludeTrailing)||void 0===a||a],r);r.typeChecker(I(tr.parameters,{value:n,delimiter:s,trimWhiteSpace:o,excludeTrailing:l}));let u=n.split(s);return o&&(u=u.map((e=>e.trim()))),l&&""===u[u.length-1]&&u.pop(),u})),parseChildren:e=>{const[r,t=ir]=e.children;return Object.assign(Object.assign({},e),{value:r,delimiter:t})}},nr=[{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"}],sr=L(nr),or={description:"Query an SQL database",aliases:["sql","pgSql","postgres","pg","sqLite","sqlite","mySql"],parameters:nr},lr={propertyAliases:sr,operatorData:or,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,n;const s=null===(t=r.options)||void 0===t?void 0:t.sqlConnection;if(!s)throw new Error("No SQL database connection provided");const[o,l,u,d,c,p]=yield H([e.query,e.values||[],e.single,e.flatten,e.useCache,e.type],r);r.typeChecker(I(or.parameters,{query:o,single:u,flatten:d,values:l,useCache:c}));const h=null===(n=null!==(a=e.useCache)&&void 0!==a?a:r.options.useCache)||void 0===n||n;{const e=r.cache.useCache(h,((e,r,t,a,n)=>i(void 0,void 0,void 0,(function*(){const i=(yield s.query({query:e,values:r}))||[];["array","string","number"].includes(null!=n?n:"")&&(a=!0);const o=a?i.map((e=>{const r=Object.values(e);return r.length<=1?r[0]:r})):i;return t?o[0]:o}))),o,l,u,d,p);return e}})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{query:r,values:t})}},ur=[{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}],dr=L(ur),cr={description:"GraphQL request",aliases:["graphQL","graphQl","graphql","gql"],parameters:ur},pr={propertyAliases:dr,operatorData:cr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,n,s,o,l,u;const d=null!==(t=r.graphQLClient)&&void 0!==t?t:r.httpClient;if(!d)throw new Error("No HTTP client provided for GraphQL connection");const[c,p,h,v,f,m]=yield H([e.query,e.url,yield G(e.variables,r),e.returnNode,e.headers,e.useCache],r),{url:y,headers:g}=p instanceof Object?p:{url:p,headers:null};r.typeChecker([...I(cr.parameters,{url:y,query:c,variables:h,returnNode:v,headers:f,useCache:m}),{name:"headers",value:g,expectedType:["object","null"]}]);const b=y&&"graphqlendpoint"!==y.toLowerCase()?y:"",O=null!==(s=null!==(n=null===(a=r.options.graphQLConnection)||void 0===a?void 0:a.endpoint)&&void 0!==n?n:r.options.baseEndpoint)&&void 0!==s?s:"",T=Q(b)?b:$(O,b),j={query:c,variables:h},C=null===(o=null!=m?m:r.options.useCache)||void 0===o||o,E=yield r.cache.useCache(C,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield F(d,{url:e,method:"post",data:r,headers:t});return _(null==i?void 0:i.data,a)}))),T,j,Object.assign(Object.assign(Object.assign(Object.assign({},null===(l=r.options.graphQLConnection)||void 0===l?void 0:l.headers),null===(u=r.options)||void 0===u?void 0:u.headers),g),f),v);return E})),parseChildren:e=>{const[r,t="",i,...a]=e.children,n=Array.isArray(i)?i:[i],s=a.slice(0,n.length),o=U(n,s),l=Object.assign(Object.assign({},e),{query:r,url:t,variables:o});return a.length>n.length&&(l.returnNode=a.pop()),l}},hr=[{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}],vr=L(hr),fr={description:"HTTP GET Request",aliases:["GET","get","api"],parameters:hr},mr=e=>{const[r="",t,...i]=e.children,a=Array.isArray(t)?t:[t],n=i.slice(0,a.length),s=U(a,n),o=Object.assign(Object.assign({},e),{url:r,parameters:s});return i.length>a.length&&(o.returnProperty=i.pop()),o},yr=mr,gr={propertyAliases:vr,operatorData:fr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,n;const s=r.httpClient;if(!s)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield H([e.url,yield G(e.parameters,r),e.returnProperty,yield G(e.headers,r),e.useCache],r),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};r.typeChecker([...I(fr.parameters,{url:p,returnProperty:u,headers:d,parameters:l,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",f=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),h),d),m=null===(n=null!=c?c:r.options.useCache)||void 0===n||n,y=yield r.cache.useCache(m,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield F(s,{url:e,params:r,headers:t});return _(i,a)}))),Q(p)?p:$(v,p),l,f,u);return y})),parseChildren:mr},br=[{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}],Or=L(br),Tr={description:"HTTP POST Request",aliases:["POST","post"],parameters:br},jr={propertyAliases:Or,operatorData:Tr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t,a,n;const s=r.httpClient;if(!s)throw new Error("No HTTP client provided");const[o,l,u,d,c]=yield H([e.url,yield G(e.parameters,r),e.returnProperty,yield G(e.headers,r),e.useCache],r),{url:p,headers:h}=o instanceof Object?o:{url:o,headers:null};r.typeChecker([...I(Tr.parameters,{url:p,headers:d,data:l,returnProperty:u,useCache:c}),{name:"headers",value:h,expectedType:["object","null"]}]);const v=null!==(t=r.options.baseEndpoint)&&void 0!==t?t:"",f=Object.assign(Object.assign(Object.assign({},null===(a=r.options)||void 0===a?void 0:a.headers),h),d),m=null!==(n=null!=c?c:r.options.useCache)&&void 0!==n&&n,y=yield r.cache.useCache(m,((e,r,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield F(s,{url:e,data:r,headers:t,method:"post"});return _(i,a)}))),Q(p)?p:$(v,p),l,f,u);return y})),parseChildren:yr},Cr=[{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"]}],Er=L(Cr),Ar={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:Cr},Sr=e=>{const r=e.children;if(r.every((e=>y(e))))return Object.assign(Object.assign({},e),{properties:r});if(r.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=r.filter(((e,r)=>r%2==0)),i=r.filter(((e,r)=>r%2==1)),a=t.map(((e,r)=>({key:e,value:i[r]})));return Object.assign(Object.assign({},e),{properties:a})},qr={propertyAliases:Er,operatorData:Ar,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){const t=yield H(e.properties,r);r.typeChecker(I(Ar.parameters,{properties:t}));const{properties:a}=t.some((e=>!y(e)))?yield Sr(Object.assign(Object.assign({},e),{children:t})):{properties:t},n=a.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:t})=>{return a=[e,t],i(void 0,void 0,void 0,(function*(){const[e,t]=yield H(a,r);return r.typeChecker({name:"key",value:e,expectedType:["string","number","boolean"]}),[e,t]}));var a}));return Object.fromEntries(yield Promise.all(n))})),parseChildren:Sr},wr=[{name:"matchExpression",description:"Expression to match against",aliases:["matchValue"],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"]}],Nr={propertyAliases:L(wr),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:wr},evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){var t;const i=yield M(e.matchExpression,r);r.typeChecker({name:"matchExpression",value:i,expectedType:["string","number","boolean"]});const n=Array.isArray(e.branches)?R(e.branches):null!==(t=e.branches)&&void 0!==t?t:{},s=a(n)?yield M(n,r):n;if(!y(s))throw new Error("Branches don't evaluate to an object");if(i in s)return yield M(s[i],r);if("fallback"in s)return yield M(s.fallback,r);if(i in e)return yield M(e[i],r);throw new Error(`No match found for ${i}`)})),parseChildren:e=>{const[r,...t]=e.children,i=R(t);return Object.assign(Object.assign({},e),{matchExpression:r,branches:i})}},Pr=[{name:"functionName",description:"Path (in options.functions) to the required function",aliases:["functionPath","funcName","function","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:["array","any"],default:[]},{name:"input",description:"Argument for the function if a single input parameter",aliases:["arg"],required:!1,type:"any",default:"input"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],xr=L(Pr),kr={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:Pr},Lr={propertyAliases:xr,operatorData:kr,evaluate:(r,t)=>i(void 0,void 0,void 0,(function*(){var a,n,s,o,l;const[u,d=[],c,p]=yield H([r.functionName,r.args,r.input,r.useCache],t);t.typeChecker(I(kr.parameters,{functionName:u,args:d}));const{data:h,functions:v}=t.options;if(!v)throw new Error("- No functions defined");const f=null!==(o=null!==(s=null!==(n=null!==(a=e(v,`${u}.function`,null))&&void 0!==a?a:e(v,u,null))&&void 0!==n?n:e(t.options,`${u}.function`,null))&&void 0!==s?s:e(t.options,u,null))&&void 0!==o?o:e(h,u,null);if(!f||"function"!=typeof f)throw new Error(`- No function found: "${u}"`);const m=null!==(l=null!=p?p:t.options.useCache)&&void 0!==l&&l,y=[...void 0===c?[]:[yield G(c,t)],...Array.isArray(d)?d:[d]];return yield t.cache.useCache(m,((e,...r)=>i(void 0,void 0,void 0,(function*(){return yield f(...r)}))),u,...y)})),parseChildren:e=>{const[r,...t]=e.children;return Object.assign(Object.assign({},e),{functionName:r,args:t})}},Ir=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Ur=L(Ir),Rr={description:"Pass through a value unchanged (or change its type)",aliases:["pass","_","passThru","passthru","ignore","coerce","convert"],parameters:Ir},Dr={propertyAliases:Ur,operatorData:Rr,evaluate:(e,r)=>i(void 0,void 0,void 0,(function*(){return r.typeChecker(I(Rr.parameters,{value:e.value})),yield M(e.value,r)})),parseChildren:e=>{const[...r]=e.children,t=1===(null==r?void 0:r.length)?r[0]:r;return Object.assign(Object.assign({},e),{value:t})}};var _r=Object.freeze({__proto__:null,AND:Y,BUILD_OBJECT:qr,CONDITIONAL:Re,COUNT:Ke,CUSTOM_FUNCTIONS:Lr,DIVIDE:Ee,EQUAL:ae,GET:gr,GRAPHQL:pr,GREATER_THAN:we,LESS_THAN:ke,MATCH:Nr,MULTIPLY:Oe,NOT_EQUAL:le,OBJECT_PROPERTIES:Be,OR:ee,PASSTHRU:Dr,PLUS:pe,POST:jr,REGEX:$e,SPLIT:ar,SQL:lr,STRING_SUBSTITUTION:Je,SUBTRACT:me});class Qr{constructor(e){var r,t;this.useCache=(e,r,...t)=>i(this,void 0,void 0,(function*(){if(!e)return yield r(...t);const i=$r(t),a=i in this.store,n=Date.now(),s=a&&n-this.store[i].timestamp>1e3*this.maxTime;if(a)return this.queue=this.queue.filter((e=>e!==i)),this.queue.unshift(i),this.store[i].timestamp=n,s&&(this.store[i].result=yield r(...t)),this.store[i].result;const o=yield r(...t);return this.store[i]={result:o,timestamp:n},this.queue.unshift(i),this.resizeCache(),o})),this.getMax=()=>this.maxSize,this.setMax=e=>{this.maxSize=e,this.resizeCache()},this.getMaxTime=()=>this.maxTime,this.setMaxTime=e=>{this.maxTime=e},this.getCache=()=>this.store,this.setCache=e=>this.store=e,this.resizeCache=()=>{if(this.queue.length>this.maxSize){this.queue.slice(this.maxSize).forEach((e=>delete this.store[e])),this.queue=this.queue.slice(0,this.maxSize)}},this.store={},this.queue=[],this.maxSize=null!==(r=null==e?void 0:e.maxSize)&&void 0!==r?r:50,this.maxTime=null!==(t=null==e?void 0:e.maxTime)&&void 0!==t?t:1800}}const $r=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),Fr=e=>e||("undefined"!=typeof window&&"document"in window&&"fetch"in window?Hr(window.fetch):void 0),Mr=e=>({get:r=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},r),{method:"get"}))).data})),post:r=>i(void 0,void 0,void 0,(function*(){return(yield e(Object.assign(Object.assign({},r),{method:"post"}))).data})),throwError:r=>{var t,i,a,n;if(e.isAxiosError(r)&&r.response)throw r.errorData={status:null===(t=r.response)||void 0===t?void 0:t.status,error:null===(i=r.response)||void 0===i?void 0:i.statusText,url:null===(a=r.config)||void 0===a?void 0:a.url,response:null===(n=r.response)||void 0===n?void 0:n.data},r;throw new Error("Network error: "+(null==r?void 0:r.message))}}),Hr=e=>({get:r=>i(void 0,void 0,void 0,(function*(){const{url:t,headers:i,params:a={}}=r,n=Object.keys(a).length>0?`?${new URLSearchParams(a).toString()}`:"",s=yield e(t+n,{headers:i,method:"GET"}),o=yield s.json();if(!s.ok){const e=new Error("Problem with GET request");throw e.name="FetchError",e.errorData={status:s.status,error:s.statusText,url:s.url,response:o},console.log(e.errorData),e}return o})),post:r=>i(void 0,void 0,void 0,(function*(){const{url:t,headers:i,params:a,data:n}=r,s=new URLSearchParams(a),o=s.size>0?`?${s.toString()}`:"",l=yield e(t+o,{headers:i,body:JSON.stringify(n),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 Br{constructor(e={}){var r,t,i;this.typeChecker=(...e)=>{const r=1===e.length&&Array.isArray(e[0])?e[0]:e,t=N(...r);if(!0===t)return;const i=new Error(t);throw i.name="Type Error",i},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.21.2",this.options=zr(e),this.operators=l(_r,null!==(t=null===(r=this.options)||void 0===r?void 0:r.excludeOperators)&&void 0!==t?t:[],b),this.operatorAliases=b,this.cache=new Qr({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime}),this.graphQLClient=Fr(null===(i=e.graphQLConnection)||void 0===i?void 0:i.httpClient),this.httpClient=Fr(e.httpClient)}evaluate(e,r={}){var t;return i(this,void 0,void 0,(function*(){const i=h(this.options,zr(r),!0);return r.httpClient&&(this.httpClient=Fr(r.httpClient)),(null===(t=r.graphQLConnection)||void 0===t?void 0:t.httpClient)&&(this.graphQLClient=Fr(r.graphQLConnection.httpClient)),i.maxCacheSize&&i.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(i.maxCacheSize),i.maxCacheTime&&i.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(i.maxCacheTime),yield M(e,{options:i,operators:r.excludeOperators?l(_r,r.excludeOperators,b):this.operators,operatorAliases:this.operatorAliases,typeChecker:i.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient})}))}getOptions(){return this.options}updateOptions(e){this.options=h(this.options,zr(e),!1),this.options.excludeOperators&&(this.operators=l(_r,this.options.excludeOperators,b))}getOperators(){const e=this.options.excludeOperators?l(_r,this.options.excludeOperators,b):this.operators,r=Object.entries(e).map((([e,r])=>Object.assign(Object.assign({name:e},r.operatorData),{parseChildren:r.parseChildren}))),t=[...new Set(Object.values(b))];return r.sort(((e,r)=>t.indexOf(e.name)-t.indexOf(r.name)))}getFragments(){var e;return Object.entries(null!==(e=this.options.fragments)&&void 0!==e?e:{}).map((([e,r])=>Object.assign({name:e},null==r?void 0:r.metadata)))}getCustomFunctions(){var e;return Object.entries(null!==(e=this.options.functions)&&void 0!==e?e:{}).map((([e,r])=>{const t="function"==typeof r?r:null==r?void 0:r.function,i={name:e,numRequiredArgs:null==t?void 0:t.length};if("function"!=typeof r){const{description:e,argsDefault:t,inputDefault:a,textColor:n,backgroundColor:s}=r;return e&&(i.description=e),t&&(i.argsDefault=t),a&&(i.inputDefault=a),n&&(i.textColor=n),s&&(i.backgroundColor=s),i}return i}))}getConfig(){return{options:this.options,operators:this.options.excludeOperators?l(_r,this.options.excludeOperators,b):this.operators,operatorAliases:this.operatorAliases,typeChecker:this.options.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient}}}const Gr=(e,r)=>new Br(r).evaluate(e),zr=e=>"objects"in e?Object.assign(Object.assign({},e),{data:e.objects}):e,Wr=e=>({query:({query:r,values:t=[]})=>i(void 0,void 0,void 0,(function*(){const i={text:r,values:null!=t?t:[]};try{const r=yield e.query(i);if(null==r?void 0:r.error)throw new Error(r.error);return r.rows}catch(e){throw e.name="Node-Postgres error",e}}))}),Jr=e=>({query:({query:r,values:t=[]})=>i(void 0,void 0,void 0,(function*(){try{return yield e.all(r,t)}catch(e){throw e.name="SQLite error",e}}))}),Vr=(e,r)=>i(void 0,void 0,void 0,(function*(){const t=r.getOperators(),a=e=>i(void 0,void 0,void 0,(function*(){if(!y(e))return e;const n=Yr(e)?yield i(void 0,void 0,void 0,(function*(){const{operator:i}=e,a=s(i),n=t.find((e=>e.name===a||e.aliases.includes(a)));if(n){const t=yield n.parseChildren(e,r.getConfig());delete t.children;const i=n.aliases[0];return t.operator=i,t}throw new Error("Invalid operator: "+i)})):e,o={};for(const[e,r]of Object.entries(n)){const t="type"===e?"outputType":e;if(Array.isArray(r)){const e=r.map((e=>a(e))),i=yield Promise.all(e);o[t]=i}else o[t]=yield a(r)}return o}));return a(e)})),Yr=e=>y(e)&&"operator"in e&&"children"in e&&Array.isArray(e.children),Xr=(e,r,i=2)=>{const a=r.getOperators(),n=r.getFragments(),o=r.getCustomFunctions(),l=r.getOptions().fragments,u=a.map((e=>[e.name,...e.aliases])).flat(),d=n.map((e=>e.name)),c=o.map((e=>e.name)),p=new Set([...u,...d,...c]),h=e=>{if(Array.isArray(e))return e.map((e=>h(e)));if(!y(e))return e;const r=e,{operator:n,fragment:o}=r,u=t(r,["operator","fragment"]);if(!n&&!o)return Object.fromEntries(Object.entries(e).map((([e,r])=>[e,h(r)])));const d=c.includes(n);o&&(null==u?void 0:u.parameters)&&(Object.entries(u.parameters).forEach((([e,r])=>{u[e]=r})),delete u.parameters);const v=d?n:rt(n,a),f=`$${null!=v?v:o}`,m=o?tt(o,l):[],g=Object.keys(u).filter((e=>et(e,p)&&!m.includes(e))),b=Object.entries(u).filter((([e])=>!g.includes(e)&&!m.includes(e))).map((([e,r])=>[e,h(r)])),O=Object.fromEntries(g.map((e=>[e,h(u[e])]))),T=Object.fromEntries(m.map((e=>[e,h(u[e])])));switch(!0){case Object.keys(T).length>0:return Object.assign({[f]:T},O);case d:return 1!==b.length||"input"in u?Object.assign({[f]:Object.fromEntries(b)},O):{[f]:b[0][1]};case"values"in u:return 1===b.length?{[f]:b[0][1]}:Object.assign({[f]:Object.fromEntries(b)},O);case"match"===v:return Object.assign({[f]:Object.fromEntries(b)},O);case b.length>i||!!o||b.some((([e])=>"useCache"===e||"outputType"===e))||b.some((e=>Array.isArray(e[1]))):return Object.assign({[f]:Object.fromEntries(b)},O);case 1===b.length:return Object.assign({[f]:b[0][1]},O);default:return Object.assign({[f]:Zr(s(n),b,a)},O)}};return h(e)},Zr=(e,r,t)=>{const i=t.find((r=>r.name===e||r.aliases.includes(e)));if(!i)throw new Error("Invalid operator: "+e);const a=[];if("OBJECT_PROPERTIES"===i.name){if(Kr("additionalData",r,i.parameters))return Object.entries(r);const e=Kr("property",r,i.parameters);if(!e)throw new Error("Missing required property for operator $getData: property");const t=r.find((([e])=>"fallback"===e));return t?[e[1],t[1]]:e[1]}for(const{name:t,aliases:n,required:s}of i.parameters){const i=[t,...n],o=r.find((([e])=>i.includes(e)));if(void 0===o&&s)throw new Error(`Missing required property for operator ${e}: ${t}`);if(void 0===o)break;a.push(o[1])}return a},Kr=(e,r,t)=>{const i=t.find((r=>r.name===e));if(!i)return;const a=[i.name,...i.aliases];return r.find((([e])=>a.includes(e)))},et=(e,r)=>c(e)&&!r.has(e),rt=(e,r)=>{if(!e)return;const t=r.find((r=>e===r.name||r.aliases.includes(s(e))));return null==t?void 0:t.aliases.find((e=>/^[A-Za-z_]{2,}$/.test(e)))},tt=(e,r={})=>{const t=r[e];if(!t)throw new Error("Fragment referenced in expression that is not defined in FigTree: "+e);const i=JSON.stringify(t).match(/"(\$\w+)"/gm);if(!i)return[];const a=new Set;return i.forEach((e=>a.add(e.replace(/"/g,"")))),Array.from(a)},it=(e,r)=>i(void 0,void 0,void 0,(function*(){const t=r.getOperators(),o=r.getFragments(),l=r.getCustomFunctions(),u=o.map((e=>e.name)),d=l.map((e=>e.name)),c=e=>i(void 0,void 0,void 0,(function*(){if(Array.isArray(e))return yield Promise.all(e.map((e=>c(e))));if(!y(e))return e;const o=Object.entries(e);if(0===o.length)return e;const l=o[0][0].replace("$",""),h=s(l),v=t.find((e=>e.name===h||e.aliases.includes(h))),f=u.includes(l),m=d.includes(l);if(v){const e=v.aliases[0],t=o[0][1];if(Array.isArray(t)){const i=yield Promise.all(t.map((e=>c(e)))),a=yield v.parseChildren({operator:e,children:i},r.getConfig());return delete a.children,Object.assign(Object.assign({},a),yield p(o))}const i=yield c(t);if(!y(i)||!at(i,v)||a(i)||n(i)){return{operator:e,[v.parameters[0].name]:i}}return Object.assign(Object.assign({operator:e},i),yield p(o))}if(f){const r=yield c(e[o[0][0]]);if(!y(r))throw new Error("Invalid shorthand Fragment");return Object.assign(Object.assign({fragment:l},r),yield p(o))}if(m){const e=l,r=o[0][1],t=yield c(r);if(!y(t)||a(t)||n(t)){return{operator:e,["args"]:t}}return Object.assign(Object.assign({operator:e},t),yield p(o))}return Object.fromEntries(yield Promise.all(o.map((([e,r])=>i(void 0,void 0,void 0,(function*(){return[e,yield c(r)]}))))))})),p=e=>i(void 0,void 0,void 0,(function*(){const r=e.slice(1);return Object.fromEntries(yield Promise.all(r.map((([e,r])=>i(void 0,void 0,void 0,(function*(){return[e,yield c(r)]}))))))}));return c(e)})),at=(e,r)=>{const t=r.parameters.map((e=>[e.name,...e.aliases])).flat();return Object.keys(e).some((e=>t.includes(e)))};export{Mr as AxiosClient,Hr as FetchClient,E as FigTreeError,Br as FigTreeEvaluator,Wr as SQLNodePostgres,Jr as SQLite,it as convertFromShorthand,Xr as convertToShorthand,Vr as convertV1ToV2,Gr as evaluateExpression,c as isAliasString,A as isFigTreeError,g as isFigTreeExpression,n as isFragmentNode,y as isObject,a as isOperatorNode,Yr as isV1Node,T as preProcessShorthand,s as standardiseOperatorName,u as truncateString};
|
|
1
|
+
import e from"object-property-extractor";import{dequal as r}from"dequal/lite";export{dequal}from"dequal/lite";const t=e=>e instanceof Object&&"operator"in e,a=e=>e instanceof Object&&"fragment"in e,s=e=>{const r=m(e);return r||e},i=(e,r)=>r[s(e)],n=(e,r,t)=>{const a={...e};return r.forEach((e=>{t[s(e)]||console.warn(`Invalid operator exclusion: ${e}`),delete a[t[s(e)]]})),a},o=(e,r=200)=>e.length<r?e:`${e.slice(0,r-2).trim()}...`,l=(e,r)=>{const t=Object.entries(e).map((([e,t])=>[r(e),t]));return Object.fromEntries(t)},u=e=>/^\$.+/.test(e),c=(e,{resolvedAliasNodes:r})=>"string"==typeof e&&u(e)?r?.[e]??e:e,p=(e,r,t)=>{const a={...e,...r};return t?((e.data||r.data)&&(a.data={...e.data,...r.data}),(e.functions||r.functions)&&(a.functions={...e.functions,...r.functions}),(e.fragments||r.fragments)&&(a.fragments={...e.fragments,...r.fragments}),(e.headers||r.headers)&&(a.headers={...e.headers,...r.headers}),a):a},d={number:e=>h(e),string:e=>String(e),array:e=>Array.isArray(e)?e:[e],boolean:e=>Boolean(e),bool:e=>Boolean(e)},h=e=>{if("string"!=typeof e)return Number.isNaN(Number(e))?e:Number(e);const r=new RegExp(/-?\d*\.?\d+/gm),t=e.match(r);return t?Number(t[0]):0},m=e=>e.replace(/[^A-Za-z\d _-]/g,"").split(/[-_ ]/).map((e=>e.match(/[a-z]+|[A-Z]+[a-z]*/g)??e)).flat().filter((e=>""!==e)).map(((e,r)=>0===r?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""),f=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),y=e=>t(e)||a(e)||"string"==typeof e&&u(e)||f(e)&&1===Object.keys(e).length&&u(Object.keys(e)[0]),g={and:"AND","&":"AND","&&":"AND",or:"OR","|":"OR","||":"OR","=":"EQUAL",eq:"EQUAL",equal:"EQUAL",equals:"EQUAL","!=":"NOT_EQUAL",notEqual:"NOT_EQUAL","!":"NOT_EQUAL",ne:"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",getData:"OBJECT_PROPERTIES",dataProperties:"OBJECT_PROPERTIES",data:"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",get:"GET",api:"GET",POST:"POST",post:"POST",sql:"SQL",pgSql:"SQL",postgres:"SQL",pg:"SQL",sqLite:"SQL",sqlite:"SQL",mySql:"SQL",graphQL:"GRAPHQL",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",pass:"PASSTHRU",_:"PASSTHRU",passThru:"PASSTHRU",passthru:"PASSTHRU",ignore:"PASSTHRU",coerce:"PASSTHRU",convert:"PASSTHRU"},v=g,b=(e,r={},t,a=!0)=>a&&f(e)?w(e,r,t):e,w=(e,r,s)=>{if(t(e)||a(e))return e;const i=Object.entries(e),n=i.filter((([e])=>u(e))),o=i.filter((([e])=>!u(e)));return{...n.reduce(((e,[t,a])=>e={...e,...T(t,a,r,s)}),{}),...Object.fromEntries(o)}},T=(e,r,t,a)=>{const s=e.slice(1),n=i(s,v);return n?Array.isArray(r)?{operator:n,children:r}:f(r)&&!Object.keys(r).some((e=>u(e)))?{operator:n,...r}:{operator:n,children:[r]}:s in t?{fragment:s,parameters:{...r}}:a.includes(s)?Array.isArray(r)?{operator:s,args:r}:f(r)?"input"in r||"args"in r?{operator:s,...r}:{operator:s,input:r}:{operator:s,args:[r]}:{[e]:r}};class C extends Error{constructor(e,r,t,a){super(e.message),Object.assign(this,e),this.operator=r,this.expression=a,this.errorData=e.errorData,t&&(this.name=t),"Error"===this.name&&(this.name="FigTreeError");const s=(r?"Operator: "+r:"")+("FigTreeError"===this.name?"":` - ${this.name}`),i=this.errorData?"\n"+JSON.stringify(this.errorData,null,2):"";this.prettyPrint=`${""!==s?s+"\n":""}${this.message}${"\n{}"===i?"":i}`}}const E=e=>e instanceof C,A=({fallback:e,operator:r,name:t,error:a,expression:s,returnErrorAsString:i=!1})=>{if(void 0!==e)return e;if(a instanceof C){if(!i)throw a;return a.prettyPrint}const n=new C("string"==typeof a?new Error(a):a,r,t,s);if(i)return n.prettyPrint;throw n},S=e=>f(e)&&"literal"in e,q=({value:e,name:r,expectedType:t})=>{if(S(t)){const{literal:a}=t;return!!a.includes(e)||P(r,e,`Literal(${a.map((e=>void 0===e?"undefined":`"${e}"`)).join(", ")})`)}if(Array.isArray(t))return!!t.some((t=>!0===q({value:e,name:r,expectedType:t})))||P(r,e,t.join("|"));return!!(0,N[t])(e)||P(r,e,t)},O=(...e)=>{const r=[];return e.forEach((e=>{const t=q(e);!0!==t&&r.push(t)})),!(r.length>0)||r.join("\n")},N={any:e=>void 0!==e,string:e=>"string"==typeof e,number:e=>"number"==typeof e,boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),null:e=>null===e,object:e=>f(e),undefined:e=>void 0===e},P=(e,r,t)=>void 0===r&&e?`- Missing required property "${e}" (type: ${t})`:void 0!==e?`- Property "${e}" (value: ${j(r)}) is not of type: ${t}`:`- ${j(r)} is not of type: ${t}`,j=e=>{const r=void 0===e||Number.isNaN(e)?String(e):JSON.stringify(e);return o(r,50)},x=e=>{const r={};return e.forEach((e=>{e.aliases.forEach((t=>r[t]=e.name))})),r},k=(e,r)=>e.map((({name:e,required:t,type:a})=>{if(S(a)){const s=[...a.literal];return t||s.push(void 0),{name:e,value:r[e],expectedType:{literal:s}}}const s=Array.isArray(a)?a:[a];t||s.push("undefined");const i=1===s.length?s[0]:s;return{name:e,value:r[e],expectedType:i}})),L=(e,r)=>{const t=e.map(((e,t)=>[e,r[t]]));return Object.fromEntries(t)},I=e=>{if(e.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const r=e.filter(((e,r)=>r%2==0)),t=O(...r.map((e=>({value:e,expectedType:["string","number","boolean"]}))));if(!0!==t)throw new Error(t);const a=e.filter(((e,r)=>r%2==1)),s={};return r.forEach(((e,r)=>{s[e]=a[r]})),s},U=e=>f(e)&&1===Object.keys(e).length?Object.values(e)[0]:e,R=(r,t,a=void 0)=>{const s=t?e(r,t,a):r;return Array.isArray(s)?s.map((e=>U(e))):t?null===s?null:U(s):s},D=e=>/^https?:\/\/.+/.test(e),_=(...e)=>e.reduce(((e,r,t)=>{const a="/"===r[0]?1:0,s="/"===r.slice(-1)?-1:void 0,i=r.slice(a,s);return""===i?e:e+(0===t?"":"/")+i}),""),Q=async(e,r)=>{const{url:t,params:a={},data:s={},headers:i={},method:n="get"}=r;if(!t||""===t)throw new Error("Invalid url");try{return await e[n]({url:t,headers:{"Content-Type":"application/json",Accept:"application/json",...i},params:a,data:s})}catch(r){e.throwError(r)}},$=async(e,r)=>{const{options:s,operators:n,operatorAliases:o}=r;let u=s?.allowJSONStringInput?(e=>{if("string"!=typeof e)return e;try{const r=JSON.parse(e);return t(r)?r:e}catch(r){return e}})(e):e;const p=Object.keys(r.options?.functions??{});u=b(u,r.options?.fragments,p,!s.noShorthand),Array.isArray(u)&&(u=await F(u,r));const h=t(u),m=a(u);if(h&&(u=await(async(e,r)=>{if(!(e.operator in(r.options?.functions??{})))return e;const{operator:t,fallback:a,outputType:s,type:i,useCache:n,input:o,args:l,...u}=e,c={operator:"CUSTOM_FUNCTIONS",function:t};return void 0!==a&&(c.fallback=a),void 0!==s&&(c.outputType=s),void 0!==i&&(c.type=i),void 0!==n&&(c.useCache=n),void 0!==l&&(c.args=l),void 0!==o?c.input=o:Object.keys(u).length>0&&(c.input=u),c})(u,r)),s.evaluateFullObject&&!h&&!m)return c(await H(u,r),r);if(!h&&!m)return s.supportDeprecatedValueNodes&&f(u)&&"value"in u?u.value:c(u,r);const{fallback:y}=u,g=s?.returnErrorAsString??!1;if(m){const e={...u},a=s?.fragments?.[e.fragment]?.metadata?.parameters?.filter((e=>void 0!==e.default));void 0===e.parameters&&(e.parameters={}),a?.forEach((r=>{void 0===e.parameters?.[r.name]&&void 0===e?.[r.name]&&(e.parameters[r.name]=r.default)}));const[i,n]=await F([e.fragment,e.parameters],r),o=b(s?.fragments?.[i],s.fragments,p,!s.noShorthand);if(void 0===o)return A({fallback:await $(y,r),error:`Fragment not defined: ${i}`,expression:u,returnErrorAsString:g});if(!t(o))return c(o,r);u={...e,...o,...n},delete u.fragment}const v=u,w=i(v.operator,o);if(!w)return A({fallback:await $(y,r),error:`Invalid operator: ${v.operator}`,expression:u,returnErrorAsString:g});if(!r.operators[w])return A({fallback:await $(y,r),error:`Excluded operator: ${v.operator}`,expression:u,returnErrorAsString:g});const{propertyAliases:T,evaluate:C,parseChildren:E}=n[w];let S=((e,r)=>l(r,(r=>r in e?e[r]:r)))(T,v);const q=await M(S,r);m||Object.entries(q).forEach((([e,t])=>r.resolvedAliasNodes[e]=t));const O=m?{...r,resolvedAliasNodes:{...r.resolvedAliasNodes,...q}}:r;if("children"in S){if(Array.isArray(S.children)||(S.children=await $(S.children,O)),!Array.isArray(S.children))return A({fallback:await $(y,r),operator:w,name:"Type Error",error:'- Property "children" is not of type: array',expression:u,returnErrorAsString:g});try{S=await E(S,O),delete S.children}catch(e){return A({fallback:await $(S.fallback,r),operator:w,error:e,expression:S,returnErrorAsString:g})}}let N;try{N=await C(S,O)}catch(e){return A({fallback:await $(S.fallback,r),operator:w,error:e,expression:S,returnErrorAsString:g})}const P=S?.outputType??S?.type;if(!P)return N;const j=await $(P,r);return j in d?d[j](N):A({fallback:await $(y,r),operator:w,error:`- Invalid output type: ${j}`,expression:S,returnErrorAsString:g})},F=async(e,r)=>Array.isArray(e)?await Promise.all(e.map((e=>$(e,r)))):await $(e,r),M=async(e,r)=>{const t=Object.keys(e).filter(u);if(0===t.length)return{};const a=[];t.forEach((t=>a.push($(e[t],r))));const s=await Promise.all(a),i=L(t,await Promise.all(a));for(const[e,r]of s.entries())"string"==typeof r&&u(r)&&(i[t[e]]=i?.[r]??r);return i},H=async(e,r)=>{const t=Object.keys(r.options?.functions??{}),a=b(e,r.options?.fragments,t);if(!f(a))return e;const s=[],i=[];Object.entries(a).forEach((([e,t])=>{u(e)&&(i.push(e,$(t,r)),delete a[e])}));const n=await Promise.all(i);r.resolvedAliasNodes={...r.resolvedAliasNodes,...I(n)},Object.entries(a).forEach((([e,t])=>{s.push(e,$(t,r))}));const o=await Promise.all(s);return c(I(o),r)},B=[{name:"values",description:"Returns true if all values are true",aliases:[],required:!0,type:"array",default:[!0,!0]}],G=x(B),z={description:"Logical AND",aliases:["and","&","&&"],parameters:B},W=e=>{const r=e.children;return{...e,values:r}},J={propertyAliases:G,operatorData:z,evaluate:async(e,r)=>{const t=await F(e.values,r);return r.typeChecker(k(z.parameters,{values:t})),t.reduce(((e,r)=>e&&!!r),!0)},parseChildren:W},V=[{name:"values",description:"Returns true if any values are true",aliases:[],required:!0,type:"array",default:[!0,!1]}],Y=x(V),X={description:"Logical OR",aliases:["or","|","||"],parameters:V},Z={propertyAliases:Y,operatorData:X,evaluate:async(e,r)=>{const t=await F(e.values,r);return r.typeChecker(k(X.parameters,{values:t})),t.reduce(((e,r)=>e||!!r),!1)},parseChildren:W},K=[{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}],ee=x(K),re={description:"Test multiple values are equal",aliases:["=","eq","equal","equals"],parameters:K},te={propertyAliases:ee,operatorData:re,evaluate:async(e,t)=>{const[a,s,i]=await F([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(k(re.parameters,{values:a,caseInsensitive:s,nullEqualsUndefined:i}));const n=(void 0!==s?s:t.options?.caseInsensitive??!1)&&a.every((e=>"string"==typeof e))?a.map((e=>e.toLowerCase())):a;return!(void 0!==i?i:void 0!==t.options?.nullEqualsUndefined&&t.options.nullEqualsUndefined)||null!==n[0]&&void 0!==n[0]?n.every((e=>r(e,n[0]))):n.every((e=>null==e))},parseChildren:W},ae=[{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}],se=x(ae),ie={description:"Test if any values are different",aliases:["!=","notEqual","!","ne"],parameters:ae},ne={propertyAliases:se,operatorData:ie,evaluate:async(e,t)=>{const[a,s,i]=await F([e.values,e.caseInsensitive,e.nullEqualsUndefined],t);t.typeChecker(k(ie.parameters,{values:a,caseInsensitive:s,nullEqualsUndefined:i}));const n=(void 0!==s?s:t.options?.caseInsensitive??!1)&&a.every((e=>"string"==typeof e))?a.map((e=>e.toLowerCase())):a;return!(void 0!==i?i:void 0!==t.options?.nullEqualsUndefined&&t.options.nullEqualsUndefined)||null!==n[0]&&void 0!==n[0]?n.some((e=>!r(e,n[0]))):n.some((e=>null===e&&void 0===e))},parseChildren:W},oe=[{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"}],le=x(oe),ue={description:"Add, concatenate or merge multiple values",aliases:["+","plus","add","concat","join","merge"],parameters:oe},ce={propertyAliases:le,operatorData:ue,evaluate:async(e,r)=>{const t=await F(e.values,r);return r.typeChecker(k(ue.parameters,{values:t,type:e.type})),0===t.length?t:"string"===e?.type?t.reduce(((e,r)=>e.concat(r)),""):"array"===e?.type?t.reduce(((e,r)=>e.concat(r)),[]):t.every((e=>"string"==typeof e||Array.isArray(e)))?t.reduce(((e,r)=>e.concat(r))):t.every((e=>f(e)))?t.reduce(((e,r)=>({...e,...r})),{}):t.reduce(((e,r)=>e+r))},parseChildren:W},pe=[{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}],de=x(pe),he={description:"Subtract one numerical value from another",aliases:["-","subtract","minus","takeaway"],parameters:pe},me={propertyAliases:de,operatorData:he,evaluate:async(e,r)=>{const[t,a,s]=await F([e.values,e.from,e.subtract],r);r.typeChecker(k(he.parameters,{values:t,from:a,subtract:s}));const i=t??[a,s].filter((e=>void 0!==e));if(i.length<2)throw new Error("- Not enough values provided");if(i.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return i[0]-i[1]},parseChildren:W},fe=[{name:"values",description:"Array of values whose product will be calculated",aliases:[],required:!0,type:"array",default:[5,5]}],ye=x(fe),ge={description:"Multiply several numerical values together",aliases:["*","x","multiply","times"],parameters:fe},ve={propertyAliases:ye,operatorData:ge,evaluate:async(e,r)=>{const t=await F(e.values,r);if(r.typeChecker(k(ge.parameters,{values:t})),0===t.length)return 0;if(t.some((e=>"number"!=typeof e)))throw new Error("- Not all values are numbers");return t.reduce(((e,r)=>e*r))},parseChildren:W},be=[{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"}],we=x(be),Te={description:"Divide one numerical value by another",aliases:["/","divide","÷"],parameters:be},Ce={propertyAliases:we,operatorData:Te,evaluate:async(e,r)=>{const[t,a,s,i]=await F([e.values,e.dividend,e.divisor,e.output],r);r.typeChecker(k(Te.parameters,{values:t,dividend:a,divisor:s,output:i}));const n=t??[a,s].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(i){case"quotient":return Math.floor(n[0]/n[1]);case"remainder":return n[0]%n[1];default:return n[0]/n[1]}},parseChildren:W},Ee=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array",default:[10,9]},{name:"strict",description:"Whether value must be strictly greater than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],Ae=x(Ee),Se={description:"Test if a value is greater than (or equal to) another value",aliases:[">","greaterThan","higher","larger"],parameters:Ee},qe={propertyAliases:Ae,operatorData:Se,evaluate:async(e,r)=>{const[t,a=!0]=await F([e.values,e.strict],r);if(r.typeChecker(k(Se.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[s,i]=t;return s===i&&!a||s>i},parseChildren:W},Oe=[{name:"values",description:"Array of values - 1st element will be compared to the second",aliases:[],required:!0,type:"array",default:[9,10]},{name:"strict",description:"Whether value must be strictly smaller than (i.e. not equal) (default: false)",aliases:[],required:!1,type:"boolean",default:!1}],Ne=x(Oe),Pe={description:"Test if a value is smaller than (or equal to) another value",aliases:["<","lessThan","lower","smaller"],parameters:Oe},je={propertyAliases:Ne,operatorData:Pe,evaluate:async(e,r)=>{const[t,a=!0]=await F([e.values,e.strict],r);if(r.typeChecker(k(Pe.parameters,{values:t,strict:a})),t.length<2)throw new Error("- Not enough values provided");const[s,i]=t;return s===i&&!a||s<i},parseChildren:W},xe=[{name:"condition",description:"The expression to check for truthiness",aliases:[],required:!0,type:"any",default:!0},{name:"valueIfTrue",description:"Value to return if condition is true",aliases:["ifTrue"],required:!0,type:"any",default:"The condition is true"},{name:"valueIfFalse",description:"Value to return if condition is false",aliases:["ifFalse","ifNot"],required:!0,type:"any",default:"The condition is false"}],ke=x(xe),Le={description:"Return a value based on a condition",aliases:["?","conditional","ifThen"],parameters:xe},Ie={propertyAliases:ke,operatorData:Le,evaluate:async(e,r)=>{r.typeChecker(k(Le.parameters,{condition:e.condition,valueIfTrue:e.valueIfTrue,valueIfFalse:e.valueIfFalse}));return await $(e.condition,r)?await $(e.valueIfTrue,r):await $(e.valueIfFalse,r)},parseChildren:e=>{const[r,t,a]=e.children;return{...e,condition:r,valueIfTrue:t,valueIfFalse:a}}},Ue=[{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}$"}],Re=x(Ue),De={description:"Compare a string against a regex pattern",aliases:["regex","patternMatch","regexp","matchPattern"],parameters:Ue},_e={propertyAliases:Re,operatorData:De,evaluate:async(e,r)=>{const[t,a]=await F([e.testString,e.pattern],r);r.typeChecker(k(De.parameters,{testString:t,pattern:a}));return new RegExp(a).test(t)},parseChildren:e=>{const[r,t]=e.children;return{...e,testString:r,pattern:t}}},Qe=[{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","array"],default:{}}],$e=x(Qe),Fe={description:"Extract values from data objects",aliases:["getData","dataProperties","data","objectProperties","objProps","getProperty","getObjProp"],parameters:Qe},Me={propertyAliases:$e,operatorData:Fe,evaluate:async(r,t)=>{const[a,s={}]=await F([r.property,r.additionalData],t);t.typeChecker(k(Fe.parameters,{property:a,additionalData:s}));const i={...t.options?.data??{},...s};return e(i,a)},parseChildren:e=>{const[r,t]=e.children,a={...e,property:r};return void 0!==t&&(a.fallback=t),a}},He=[{name:"string",description:"A parameterised (%1, %2) string where the parameters are to be replaced",aliases:[],required:!0,type:"string",default:"Hello, %1"},{name:"substitutions",description:"An array of substitution values for the parameterised string",aliases:["replacements","values"],required:!1,type:["array","object"],default:{}},{name:"trimWhiteSpace",description:"Whether or not to trim white space from either end of the substituted strings (default: true)",aliases:["trim","trimWhitespace"],required:!1,type:"boolean",default:!0},{name:"substitutionCharacter",description:'Which character to search for in original string for replacement -- can be "%" or "$" (default: "%")',aliases:["subCharacter","subChar"],required:!1,type:"string",default:"$"},{name:"numberMapping",description:"Rules for mapping number values to text strings, such as pluralisation.",aliases:["numMap","numberMap","pluralisation","pluralization","plurals"],required:!1,type:"object",default:{}}],Be=x(He),Ge={description:"Replace values in a string using simple parameter substitution",aliases:["stringSubstitution","substitute","stringSub","replace"],parameters:He},ze={propertyAliases:Be,operatorData:Ge,evaluate:async(e,r)=>{const[t,a={},s=!0,i="%",n={}]=await F([e.string,e.substitutions,e.trimWhiteSpace,e.substitutionCharacter,e.numberMapping],r);if(r.typeChecker(k(Ge.parameters,{string:t,substitutions:a,trimWhiteSpace:s,substitutionCharacter:i,numberMapping:n})),Array.isArray(a)){const e="$"===i?"$":"%",r=new RegExp(`(?<!\\\\)(${"%"===e?"%":"\\$"}[\\d]+)`,"g"),n=(t.match(r)||[]).sort(((e,r)=>Number(e.slice(1))-Number(r.slice(1)))),o=new Set(n),l=L(Array.from(o),a.map((e=>s?String(e).trim():e)));return t.split(r).map((e=>e in l?l[e]:e)).join("").replace(`\\${e}`,e)}const o=/(?<!\\)({{(?:[A-Za-z0-9_.]|\[[0-9]+\])+}})/g,l=[];for(const e of t.split(o)){if(!/(?<!\\){{(.+)}}/.exec(e)){l.push(e.replace("\\{{","{{"));continue}const t=await We(e,a,n,r);l.push(s?String(t).trim():t)}return l.join("")},parseChildren:e=>{const[r,...t]=e.children;return{...e,string:r,substitutions:t}}},We=async(r,t,a,s)=>{const i=s.options?.data??{},n=r.replace(/{{(.+)}}/,"$1"),o=await $(e(t,n,e(i,n,"")),s);if("number"!=typeof o)return o;if(!(n in a))return o;const l=a[n];if(o in l)return l[o].replace("{}",String(o));const u=Object.keys(a[n]),c=u.find((e=>e.startsWith(">")));if(c){if(o>Number(c.slice(1)))return l?.[c]}const p=u.find((e=>e.startsWith("<")));if(p){if(o<Number(p.slice(1)))return l?.[p]}return l.other?l.other.replace("{}",String(o)):o},Je=[{name:"values",description:"An array to count",aliases:[],required:!0,type:"array",default:[1,2,3,4,5]}],Ve=x(Je),Ye={description:"Count elements in an array",aliases:["count","length"],parameters:Je},Xe={propertyAliases:Ve,operatorData:Ye,evaluate:async(e,r)=>{const t=await F(e.values,r);return r.typeChecker(k(Ye.parameters,{values:t})),t.length},parseChildren:W},Ze=[{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}],Ke=x(Ze),er={description:"Split a string into an array",aliases:["split","arraySplit"],parameters:Ze},rr=" ",tr={propertyAliases:Ke,operatorData:er,evaluate:async(e,r)=>{const[t,a,s,i]=await F([e.value,e.delimiter??rr,e.trimWhiteSpace??!0,e.excludeTrailing??!0],r);r.typeChecker(k(er.parameters,{value:t,delimiter:a,trimWhiteSpace:s,excludeTrailing:i}));let n=t.split(a);return s&&(n=n.map((e=>e.trim()))),i&&""===n[n.length-1]&&n.pop(),n},parseChildren:e=>{const[r,t=rr]=e.children;return{...e,value:r,delimiter:t}}},ar=[{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"}],sr=x(ar),ir={description:"Query an SQL database",aliases:["sql","pgSql","postgres","pg","sqLite","sqlite","mySql"],parameters:ar},nr={propertyAliases:sr,operatorData:ir,evaluate:async(e,r)=>{const t=r.options?.sqlConnection;if(!t)throw new Error("No SQL database connection provided");const[a,s,i,n,o,l]=await F([e.query,e.values||[],e.single,e.flatten,e.useCache,e.type],r);r.typeChecker(k(ir.parameters,{query:a,single:i,flatten:n,values:s,useCache:o}));const u=e.useCache??r.options.useCache??!0;{const e=r.cache.useCache(u,(async(e,r,a,s,i)=>{const n=await t.query({query:e,values:r})||[];["array","string","number"].includes(i??"")&&(s=!0);const o=s?n.map((e=>{const r=Object.values(e);return r.length<=1?r[0]:r})):n;return a?o[0]:o}),a,s,i,n,l);return e}},parseChildren:e=>{const[r,...t]=e.children;return{...e,query:r,values:t}}},or=[{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}],lr=x(or),ur={description:"GraphQL request",aliases:["graphQL","graphQl","graphql","gql"],parameters:or},cr={propertyAliases:lr,operatorData:ur,evaluate:async(e,r)=>{const t=r.graphQLClient??r.httpClient;if(!t)throw new Error("No HTTP client provided for GraphQL connection");const[a,s,i,n,o,l]=await F([e.query,e.url,await H(e.variables,r),e.returnNode,e.headers,e.useCache],r),{url:u,headers:c}=s instanceof Object?s:{url:s,headers:null};r.typeChecker([...k(ur.parameters,{url:u,query:a,variables:i,returnNode:n,headers:o,useCache:l}),{name:"headers",value:c,expectedType:["object","null"]}]);const p=u&&"graphqlendpoint"!==u.toLowerCase()?u:"",d=r.options.graphQLConnection?.endpoint??r.options.baseEndpoint??"",h=D(p)?p:_(d,p),m={query:a,variables:i},f=l??r.options.useCache??!0,y=await r.cache.useCache(f,(async(e,r,a,s)=>{const i=await Q(t,{url:e,method:"post",data:r,headers:a});return R(i?.data,s)}),h,m,{...r.options.graphQLConnection?.headers,...r.options?.headers,...c,...o},n);return y},parseChildren:e=>{const[r,t="",a,...s]=e.children,i=Array.isArray(a)?a:[a],n=s.slice(0,i.length),o=L(i,n),l={...e,query:r,url:t,variables:o};return s.length>i.length&&(l.returnNode=s.pop()),l}},pr=[{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}],dr=x(pr),hr={description:"HTTP GET Request",aliases:["GET","get","api"],parameters:pr},mr=e=>{const[r="",t,...a]=e.children,s=Array.isArray(t)?t:[t],i=a.slice(0,s.length),n=L(s,i),o={...e,url:r,parameters:n};return a.length>s.length&&(o.returnProperty=a.pop()),o},fr=mr,yr={propertyAliases:dr,operatorData:hr,evaluate:async(e,r)=>{const t=r.httpClient;if(!t)throw new Error("No HTTP client provided");const[a,s,i,n,o]=await F([e.url,await H(e.parameters,r),e.returnProperty,await H(e.headers,r),e.useCache],r),{url:l,headers:u}=a instanceof Object?a:{url:a,headers:null};r.typeChecker([...k(hr.parameters,{url:l,returnProperty:i,headers:n,parameters:s,useCache:o}),{name:"headers",value:u,expectedType:["object","null"]}]);const c=r.options.baseEndpoint??"",p={...r.options?.headers,...u,...n},d=o??r.options.useCache??!0,h=await r.cache.useCache(d,(async(e,r,a,s)=>{const i=await Q(t,{url:e,params:r,headers:a});return R(i,s)}),D(l)?l:_(c,l),s,p,i);return h},parseChildren:mr},gr=[{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}],vr=x(gr),br={description:"HTTP POST Request",aliases:["POST","post"],parameters:gr},wr={propertyAliases:vr,operatorData:br,evaluate:async(e,r)=>{const t=r.httpClient;if(!t)throw new Error("No HTTP client provided");const[a,s,i,n,o]=await F([e.url,await H(e.parameters,r),e.returnProperty,await H(e.headers,r),e.useCache],r),{url:l,headers:u}=a instanceof Object?a:{url:a,headers:null};r.typeChecker([...k(br.parameters,{url:l,headers:n,data:s,returnProperty:i,useCache:o}),{name:"headers",value:u,expectedType:["object","null"]}]);const c=r.options.baseEndpoint??"",p={...r.options?.headers,...u,...n},d=o??r.options.useCache??!1,h=await r.cache.useCache(d,(async(e,r,a,s)=>{const i=await Q(t,{url:e,data:r,headers:a,method:"post"});return R(i,s)}),D(l)?l:_(c,l),s,p,i);return h},parseChildren:fr},Tr=[{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"]}],Cr=x(Tr),Er={description:"Construct an object using objects defining keys and values",aliases:["buildObject","build","object"],parameters:Tr},Ar=e=>{const r=e.children;if(r.every((e=>f(e))))return{...e,properties:r};if(r.length%2!=0)throw new Error("Even number of children required to make key/value pairs");const t=r.filter(((e,r)=>r%2==0)),a=r.filter(((e,r)=>r%2==1)),s=t.map(((e,r)=>({key:e,value:a[r]})));return{...e,properties:s}},Sr={propertyAliases:Cr,operatorData:Er,evaluate:async(e,r)=>{const t=await F(e.properties,r);r.typeChecker(k(Er.parameters,{properties:t}));const{properties:a}=t.some((e=>!f(e)))?await Ar({...e,children:t}):{properties:t},s=a.filter((e=>e instanceof Object&&"key"in e&&"value"in e)).map((({key:e,value:t})=>(async e=>{const[t,a]=await F(e,r);return r.typeChecker({name:"key",value:t,expectedType:["string","number","boolean"]}),[t,a]})([e,t])));return Object.fromEntries(await Promise.all(s))},parseChildren:Ar},qr=[{name:"matchExpression",description:"Expression to match against",aliases:["matchValue"],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"]}],Or={propertyAliases:x(qr),operatorData:{description:"Return different values depending on a matching expression",aliases:["match","switch"],parameters:qr},evaluate:async(e,r)=>{const a=await $(e.matchExpression,r);r.typeChecker({name:"matchExpression",value:a,expectedType:["string","number","boolean"]});const s=Array.isArray(e.branches)?I(e.branches):e.branches??{},i=t(s)?await $(s,r):s;if(!f(i))throw new Error("Branches don't evaluate to an object");if(a in i)return await $(i[a],r);if("fallback"in i)return await $(i.fallback,r);if(a in e)return await $(e[a],r);throw new Error(`No match found for ${a}`)},parseChildren:e=>{const[r,...t]=e.children,a=I(t);return{...e,matchExpression:r,branches:a}}},Nr=[{name:"functionName",description:"Path (in options.functions) to the required function",aliases:["functionPath","funcName","function","path","name"],required:!0,type:"string",default:null},{name:"args",description:"Arguments for the function",aliases:["arguments","variables"],required:!1,type:["array","any"],default:[]},{name:"input",description:"Argument for the function if a single input parameter",aliases:["arg"],required:!1,type:"any",default:"input"},{name:"useCache",description:"Whether or not the FigTree cache is used",aliases:[],required:!1,type:"boolean",default:!1}],Pr=x(Nr),jr={description:"Call a custom function (defined in options)",aliases:["customFunctions","customFunction","objectFunctions","function","functions","runFunction"],parameters:Nr},xr={propertyAliases:Pr,operatorData:jr,evaluate:async(r,t)=>{const[a,s=[],i,n]=await F([r.functionName,r.args,r.input,r.useCache],t);t.typeChecker(k(jr.parameters,{functionName:a,args:s}));const{data:o,functions:l}=t.options;if(!l)throw new Error("- No functions defined");const u=e(l,`${a}.function`,null)??e(l,a,null)??e(t.options,`${a}.function`,null)??e(t.options,a,null)??e(o,a,null);if(!u||"function"!=typeof u)throw new Error(`- No function found: "${a}"`);const c=n??t.options.useCache??!1,p=[...void 0===i?[]:[await H(i,t)],...Array.isArray(s)?s:[s]];return await t.cache.useCache(c,(async(e,...r)=>await u(...r)),a,...p)},parseChildren:e=>{const[r,...t]=e.children;return{...e,functionName:r,args:t}}},kr=[{name:"value",description:"Value to pass through",aliases:["_","data"],required:!0,type:"any",default:null}],Lr=x(kr),Ir={description:"Pass through a value unchanged (or change its type)",aliases:["pass","_","passThru","passthru","ignore","coerce","convert"],parameters:kr},Ur={propertyAliases:Lr,operatorData:Ir,evaluate:async(e,r)=>(r.typeChecker(k(Ir.parameters,{value:e.value})),await $(e.value,r)),parseChildren:e=>{const[...r]=e.children,t=1===r?.length?r[0]:r;return{...e,value:t}}};var Rr=Object.freeze({__proto__:null,AND:J,BUILD_OBJECT:Sr,CONDITIONAL:Ie,COUNT:Xe,CUSTOM_FUNCTIONS:xr,DIVIDE:Ce,EQUAL:te,GET:yr,GRAPHQL:cr,GREATER_THAN:qe,LESS_THAN:je,MATCH:Or,MULTIPLY:ve,NOT_EQUAL:ne,OBJECT_PROPERTIES:Me,OR:Z,PASSTHRU:Ur,PLUS:ce,POST:wr,REGEX:_e,SPLIT:tr,SQL:nr,STRING_SUBSTITUTION:ze,SUBTRACT:me});class Dr{constructor(e){this.useCache=async(e,r,...t)=>{if(!e)return await r(...t);const a=_r(t),s=a in this.store,i=Date.now(),n=s&&i-this.store[a].timestamp>1e3*this.maxTime;if(s)return this.queue=this.queue.filter((e=>e!==a)),this.queue.unshift(a),this.store[a].timestamp=i,n&&(this.store[a].result=await r(...t)),this.store[a].result;const o=await r(...t);return this.store[a]={result:o,timestamp:i},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=e?.maxSize??50,this.maxTime=e?.maxTime??1800}}const _r=e=>e.map((e=>"object"==typeof e?JSON.stringify(e):e)).join("_"),Qr=e=>e||("undefined"!=typeof window&&"document"in window&&"fetch"in window?Fr(window.fetch):void 0),$r=e=>({get:async r=>(await e({...r,method:"get"})).data,post:async r=>(await e({...r,method:"post"})).data,throwError:r=>{if(e.isAxiosError(r)&&r.response)throw r.errorData={status:r.response?.status,error:r.response?.statusText,url:r.config?.url,response:r.response?.data},r;throw new Error("Network error: "+r?.message)}}),Fr=e=>({get:async r=>{const{url:t,headers:a,params:s={}}=r,i=Object.keys(s).length>0?`?${new URLSearchParams(s).toString()}`:"",n=await e(t+i,{headers:a,method:"GET"}),o=await n.json();if(!n.ok){const e=new Error("Problem with GET request");throw e.name="FetchError",e.errorData={status:n.status,error:n.statusText,url:n.url,response:o},console.log(e.errorData),e}return o},post:async r=>{const{url:t,headers:a,params:s,data:i}=r,n=new URLSearchParams(s),o=n.size>0?`?${n.toString()}`:"",l=await e(t+o,{headers:a,body:JSON.stringify(i),method:"POST"}),u=await 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 Mr{constructor(e={}){this.typeChecker=(...e)=>{const r=1===e.length&&Array.isArray(e[0])?e[0]:e,t=O(...r);if(!0===t)return;const a=new Error(t);throw a.name="Type Error",a},this.getCache=()=>this.cache.getCache(),this.setCache=e=>this.cache.setCache(e),this.getVersion=()=>"2.21.4",this.options=Br(e),this.operators=n(Rr,this.options?.excludeOperators??[],g),this.operatorAliases=g,this.cache=new Dr({maxSize:e.maxCacheSize,maxTime:e.maxCacheTime}),this.graphQLClient=Qr(e.graphQLConnection?.httpClient),this.httpClient=Qr(e.httpClient)}async evaluate(e,r={}){const t=p(this.options,Br(r),!0);return r.httpClient&&(this.httpClient=Qr(r.httpClient)),r.graphQLConnection?.httpClient&&(this.graphQLClient=Qr(r.graphQLConnection.httpClient)),t.maxCacheSize&&t.maxCacheSize!==this.cache.getMax()&&this.cache.setMax(t.maxCacheSize),t.maxCacheTime&&t.maxCacheTime!==this.cache.getMaxTime()&&this.cache.setMaxTime(t.maxCacheTime),await $(e,{options:t,operators:r.excludeOperators?n(Rr,r.excludeOperators,g):this.operators,operatorAliases:this.operatorAliases,typeChecker:t.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient})}getOptions(){return this.options}updateOptions(e){this.options=p(this.options,Br(e),!1),this.options.excludeOperators&&(this.operators=n(Rr,this.options.excludeOperators,g))}getOperators(){const e=this.options.excludeOperators?n(Rr,this.options.excludeOperators,g):this.operators,r=Object.entries(e).map((([e,r])=>({name:e,...r.operatorData,parseChildren:r.parseChildren}))),t=[...new Set(Object.values(g))];return r.sort(((e,r)=>t.indexOf(e.name)-t.indexOf(r.name)))}getFragments(){return Object.entries(this.options.fragments??{}).map((([e,r])=>({name:e,...r?.metadata})))}getCustomFunctions(){return Object.entries(this.options.functions??{}).map((([e,r])=>{const t="function"==typeof r?r:r?.function,a={name:e,numRequiredArgs:t?.length};if("function"!=typeof r){const{description:e,argsDefault:t,inputDefault:s,textColor:i,backgroundColor:n}=r;return e&&(a.description=e),t&&(a.argsDefault=t),s&&(a.inputDefault=s),i&&(a.textColor=i),n&&(a.backgroundColor=n),a}return a}))}getConfig(){return{options:this.options,operators:this.options.excludeOperators?n(Rr,this.options.excludeOperators,g):this.operators,operatorAliases:this.operatorAliases,typeChecker:this.options.skipRuntimeTypeCheck?()=>{}:this.typeChecker,resolvedAliasNodes:{},cache:this.cache,graphQLClient:this.graphQLClient,httpClient:this.httpClient}}}const Hr=(e,r)=>new Mr(r).evaluate(e),Br=e=>"objects"in e?{...e,data:e.objects}:e,Gr=e=>({query:async({query:r,values:t=[]})=>{const a={text:r,values:t??[]};try{const r=await e.query(a);if(r?.error)throw new Error(r.error);return r.rows}catch(e){throw e.name="Node-Postgres error",e}}}),zr=e=>({query:async({query:r,values:t=[]})=>{try{return await e.all(r,t)}catch(e){throw e.name="SQLite error",e}}}),Wr=async(e,r)=>{const t=r.getOperators(),a=async e=>{if(!f(e))return e;const i=Jr(e)?await(async()=>{const{operator:a}=e,i=s(a),n=t.find((e=>e.name===i||e.aliases.includes(i)));if(n){const t=await n.parseChildren(e,r.getConfig());delete t.children;const a=n.aliases[0];return t.operator=a,t}throw new Error("Invalid operator: "+a)})():e,n={};for(const[e,r]of Object.entries(i)){const t="type"===e?"outputType":e;if(Array.isArray(r)){const e=r.map((e=>a(e))),s=await Promise.all(e);n[t]=s}else n[t]=await a(r)}return n};return a(e)},Jr=e=>f(e)&&"operator"in e&&"children"in e&&Array.isArray(e.children),Vr=(e,r,t=2)=>{const a=r.getOperators(),i=r.getFragments(),n=r.getCustomFunctions(),o=r.getOptions().fragments,l=a.map((e=>[e.name,...e.aliases])).flat(),u=i.map((e=>e.name)),c=n.map((e=>e.name)),p=new Set([...l,...u,...c]),d=e=>{if(Array.isArray(e))return e.map((e=>d(e)));if(!f(e))return e;const{operator:r,fragment:i,...n}=e;if(!r&&!i)return Object.fromEntries(Object.entries(e).map((([e,r])=>[e,d(r)])));const l=c.includes(r);i&&n?.parameters&&(Object.entries(n.parameters).forEach((([e,r])=>{n[e]=r})),delete n.parameters);const u=l?r:Kr(r,a),h=`$${u??i}`,m=i?et(i,o):[],y=Object.keys(n).filter((e=>Zr(e,p)&&!m.includes(e))),g=Object.entries(n).filter((([e])=>!y.includes(e)&&!m.includes(e))).map((([e,r])=>[e,d(r)])),v=Object.fromEntries(y.map((e=>[e,d(n[e])]))),b=Object.fromEntries(m.map((e=>[e,d(n[e])])));switch(!0){case Object.keys(b).length>0:return{[h]:b,...v};case l:return 1!==g.length||"input"in n?{[h]:Object.fromEntries(g),...v}:{[h]:g[0][1]};case"values"in n:return 1===g.length?{[h]:g[0][1]}:{[h]:Object.fromEntries(g),...v};case"match"===u:return{[h]:Object.fromEntries(g),...v};case g.length>t||!!i||g.some((([e])=>"useCache"===e||"outputType"===e))||g.some((e=>Array.isArray(e[1]))):return{[h]:Object.fromEntries(g),...v};case 1===g.length:return{[h]:g[0][1],...v};default:return{[h]:Yr(s(r),g,a),...v}}};return d(e)},Yr=(e,r,t)=>{const a=t.find((r=>r.name===e||r.aliases.includes(e)));if(!a)throw new Error("Invalid operator: "+e);const s=[];if("OBJECT_PROPERTIES"===a.name){if(Xr("additionalData",r,a.parameters))return Object.fromEntries(r);const e=Xr("property",r,a.parameters);if(!e)throw new Error("Missing required property for operator $getData: property");const t=r.find((([e])=>"fallback"===e));return t?[e[1],t[1]]:e[1]}for(const{name:t,aliases:i,required:n}of a.parameters){const a=[t,...i],o=r.find((([e])=>a.includes(e)));if(void 0===o&&n)throw new Error(`Missing required property for operator ${e}: ${t}`);if(void 0===o)break;s.push(o[1])}return s},Xr=(e,r,t)=>{const a=t.find((r=>r.name===e));if(!a)return;const s=[a.name,...a.aliases];return r.find((([e])=>s.includes(e)))},Zr=(e,r)=>u(e)&&!r.has(e),Kr=(e,r)=>{if(!e)return;const t=r.find((r=>e===r.name||r.aliases.includes(s(e))));return t?.aliases.find((e=>/^[A-Za-z_]{2,}$/.test(e)))},et=(e,r={})=>{const t=r[e];if(!t)throw new Error("Fragment referenced in expression that is not defined in FigTree: "+e);const a=JSON.stringify(t).match(/"(\$\w+)"/gm);if(!a)return[];const s=new Set;return a.forEach((e=>s.add(e.replace(/"/g,"")))),Array.from(s)},rt=async(e,r)=>{const i=r.getOperators(),n=r.getFragments(),o=r.getCustomFunctions(),l=n.map((e=>e.name)),u=o.map((e=>e.name)),c=async e=>{if(Array.isArray(e))return await Promise.all(e.map((e=>c(e))));if(!f(e))return e;const n=Object.entries(e);if(0===n.length)return e;const o=n[0][0].replace("$",""),d=s(o),h=i.find((e=>e.name===d||e.aliases.includes(d))),m=l.includes(o),y=u.includes(o);if(h){const e=h.aliases[0],s=n[0][1];if(Array.isArray(s)){const t=await Promise.all(s.map((e=>c(e)))),a=await h.parseChildren({operator:e,children:t},r.getConfig());return delete a.children,{...a,...await p(n)}}const i=await c(s);if(!f(i)||!tt(i,h)||t(i)||a(i)){return{operator:e,[h.parameters[0].name]:i}}return{operator:e,...i,...await p(n)}}if(m){const r=await c(e[n[0][0]]);if(!f(r))throw new Error("Invalid shorthand Fragment");return{fragment:o,...r,...await p(n)}}if(y){const e=o,r=n[0][1],s=await c(r);if(!f(s)||t(s)||a(s)){return{operator:e,["args"]:s}}return{operator:e,...s,...await p(n)}}return Object.fromEntries(await Promise.all(n.map((async([e,r])=>[e,await c(r)]))))},p=async e=>{const r=e.slice(1);return Object.fromEntries(await Promise.all(r.map((async([e,r])=>[e,await c(r)]))))};return c(e)},tt=(e,r)=>{const t=r.parameters.map((e=>[e.name,...e.aliases])).flat();return Object.keys(e).some((e=>t.includes(e)))};export{$r as AxiosClient,Fr as FetchClient,C as FigTreeError,Mr as FigTreeEvaluator,Gr as SQLNodePostgres,zr as SQLite,rt as convertFromShorthand,Vr as convertToShorthand,Wr as convertV1ToV2,Hr as evaluateExpression,u as isAliasString,E as isFigTreeError,y as isFigTreeExpression,a as isFragmentNode,f as isObject,t as isOperatorNode,Jr as isV1Node,b as preProcessShorthand,s as standardiseOperatorName,o as truncateString};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fig-tree-evaluator",
|
|
3
|
-
"version": "2.21.
|
|
3
|
+
"version": "2.21.4",
|
|
4
4
|
"description": "Module to evaluate JSON-structured expression trees",
|
|
5
5
|
"main": "build/index.cjs.js",
|
|
6
6
|
"module": "build/index.esm.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"axios": "^1.7.2",
|
|
34
34
|
"dotenv": "^16.0.1",
|
|
35
35
|
"eslint": "^8.53.0",
|
|
36
|
-
"fig-tree-evaluator": "^2.
|
|
36
|
+
"fig-tree-evaluator": "^2.21.3",
|
|
37
37
|
"jest": "^29.7.0",
|
|
38
38
|
"node-fetch": "2.7.0",
|
|
39
39
|
"pg": "^8.11.3",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"dequal": "^2.0.3",
|
|
69
|
-
"object-property-extractor": "^1.0.
|
|
69
|
+
"object-property-extractor": "^1.0.14"
|
|
70
70
|
},
|
|
71
71
|
"bugs": {
|
|
72
72
|
"url": "https://github.com/CarlosNZ/fig-tree-evaluator/issues"
|