fig-tree-evaluator 2.8.0 → 2.8.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.
Files changed (109) hide show
  1. package/README.md +4 -2
  2. package/build/FigTreeEvaluator.d.ts +6 -16
  3. package/build/FigTreeEvaluator.js +8 -4
  4. package/build/cache.d.ts +3 -1
  5. package/build/cache.js +10 -11
  6. package/build/evaluate.js +3 -6
  7. package/build/helpers.d.ts +8 -34
  8. package/build/helpers.js +1 -10
  9. package/build/index.d.ts +2 -2
  10. package/build/operators/AND/data.d.ts +0 -1
  11. package/build/operators/AND/data.js +1 -2
  12. package/build/operators/AND/index.d.ts +1 -1
  13. package/build/operators/AND/operator.d.ts +2 -6
  14. package/build/operators/AND/operator.js +1 -2
  15. package/build/operators/BUILD_OBJECT/data.d.ts +0 -1
  16. package/build/operators/BUILD_OBJECT/data.js +1 -2
  17. package/build/operators/BUILD_OBJECT/operator.d.ts +1 -9
  18. package/build/operators/BUILD_OBJECT/operator.js +1 -2
  19. package/build/operators/CONDITIONAL/data.d.ts +0 -1
  20. package/build/operators/CONDITIONAL/data.js +1 -2
  21. package/build/operators/CONDITIONAL/operator.d.ts +1 -5
  22. package/build/operators/CONDITIONAL/operator.js +7 -2
  23. package/build/operators/COUNT/data.d.ts +0 -1
  24. package/build/operators/COUNT/data.js +1 -2
  25. package/build/operators/COUNT/operator.js +1 -2
  26. package/build/operators/CUSTOM_FUNCTIONS/data.d.ts +0 -1
  27. package/build/operators/CUSTOM_FUNCTIONS/data.js +9 -3
  28. package/build/operators/CUSTOM_FUNCTIONS/operator.d.ts +1 -7
  29. package/build/operators/CUSTOM_FUNCTIONS/operator.js +7 -6
  30. package/build/operators/DIVIDE/data.d.ts +0 -1
  31. package/build/operators/DIVIDE/data.js +2 -3
  32. package/build/operators/DIVIDE/operator.d.ts +1 -11
  33. package/build/operators/DIVIDE/operator.js +5 -4
  34. package/build/operators/EQUAL/data.d.ts +0 -1
  35. package/build/operators/EQUAL/data.js +1 -2
  36. package/build/operators/EQUAL/operator.js +1 -2
  37. package/build/operators/GET/data.d.ts +0 -1
  38. package/build/operators/GET/data.js +2 -3
  39. package/build/operators/GET/index.d.ts +1 -1
  40. package/build/operators/GET/operator.d.ts +2 -10
  41. package/build/operators/GET/operator.js +16 -14
  42. package/build/operators/GRAPHQL/data.d.ts +0 -1
  43. package/build/operators/GRAPHQL/data.js +1 -2
  44. package/build/operators/GRAPHQL/operator.d.ts +1 -10
  45. package/build/operators/GRAPHQL/operator.js +20 -9
  46. package/build/operators/GREATER_THAN/data.d.ts +0 -1
  47. package/build/operators/GREATER_THAN/data.js +1 -2
  48. package/build/operators/GREATER_THAN/operator.d.ts +0 -4
  49. package/build/operators/GREATER_THAN/operator.js +1 -2
  50. package/build/operators/LESS_THAN/data.d.ts +0 -1
  51. package/build/operators/LESS_THAN/data.js +1 -2
  52. package/build/operators/LESS_THAN/operator.js +1 -2
  53. package/build/operators/MATCH/data.d.ts +0 -1
  54. package/build/operators/MATCH/data.js +1 -2
  55. package/build/operators/MATCH/operator.d.ts +1 -5
  56. package/build/operators/MATCH/operator.js +12 -6
  57. package/build/operators/MULTIPLY/data.d.ts +0 -1
  58. package/build/operators/MULTIPLY/data.js +1 -2
  59. package/build/operators/MULTIPLY/operator.js +5 -2
  60. package/build/operators/NOT_EQUAL/data.d.ts +0 -1
  61. package/build/operators/NOT_EQUAL/data.js +1 -2
  62. package/build/operators/NOT_EQUAL/operator.js +1 -2
  63. package/build/operators/OBJECT_PROPERTIES/data.d.ts +0 -1
  64. package/build/operators/OBJECT_PROPERTIES/data.js +1 -2
  65. package/build/operators/OBJECT_PROPERTIES/operator.d.ts +1 -7
  66. package/build/operators/OBJECT_PROPERTIES/operator.js +1 -2
  67. package/build/operators/OR/data.d.ts +0 -1
  68. package/build/operators/OR/data.js +1 -2
  69. package/build/operators/OR/operator.js +1 -2
  70. package/build/operators/PASSTHRU/data.d.ts +0 -1
  71. package/build/operators/PASSTHRU/data.js +1 -2
  72. package/build/operators/PASSTHRU/operator.d.ts +1 -5
  73. package/build/operators/PASSTHRU/operator.js +2 -1
  74. package/build/operators/PG_SQL/data.d.ts +0 -1
  75. package/build/operators/PG_SQL/data.js +9 -3
  76. package/build/operators/PG_SQL/operator.d.ts +1 -23
  77. package/build/operators/PG_SQL/operator.js +22 -30
  78. package/build/operators/PLUS/data.d.ts +0 -1
  79. package/build/operators/PLUS/data.js +2 -3
  80. package/build/operators/PLUS/operator.d.ts +1 -8
  81. package/build/operators/PLUS/operator.js +5 -5
  82. package/build/operators/POST/data.d.ts +0 -1
  83. package/build/operators/POST/data.js +3 -4
  84. package/build/operators/POST/operator.js +14 -6
  85. package/build/operators/REGEX/data.d.ts +0 -1
  86. package/build/operators/REGEX/data.js +1 -2
  87. package/build/operators/REGEX/operator.d.ts +1 -5
  88. package/build/operators/REGEX/operator.js +1 -2
  89. package/build/operators/SPLIT/data.d.ts +0 -1
  90. package/build/operators/SPLIT/data.js +1 -2
  91. package/build/operators/SPLIT/operator.d.ts +1 -9
  92. package/build/operators/SPLIT/operator.js +1 -2
  93. package/build/operators/STRING_SUBSTITUTION/data.d.ts +0 -1
  94. package/build/operators/STRING_SUBSTITUTION/data.js +1 -2
  95. package/build/operators/STRING_SUBSTITUTION/operator.d.ts +1 -5
  96. package/build/operators/STRING_SUBSTITUTION/operator.js +5 -6
  97. package/build/operators/SUBTRACT/data.d.ts +0 -1
  98. package/build/operators/SUBTRACT/data.js +1 -2
  99. package/build/operators/SUBTRACT/operator.d.ts +1 -8
  100. package/build/operators/SUBTRACT/operator.js +4 -3
  101. package/build/operators/_operatorUtils.d.ts +16 -17
  102. package/build/operators/_operatorUtils.js +17 -17
  103. package/build/shorthandSyntax.js +1 -1
  104. package/build/typeCheck.d.ts +8 -4
  105. package/build/typeCheck.js +25 -20
  106. package/build/types.d.ts +32 -33
  107. package/build/version.d.ts +1 -0
  108. package/build/version.js +4 -0
  109. package/package.json +10 -3
package/README.md CHANGED
@@ -883,7 +883,7 @@ Aliases: `get`, `api`
883
883
  #### Properties
884
884
 
885
885
  - `url` (or `endpoint`)<sup>*</sup>: (string) -- url to be queried
886
- - `parameters`: (object) -- key-value pairs for any query parameters for the request
886
+ - `parameters` (or `queryParams`, `queryParameters`, `urlQueries`): (object) -- key-value pairs for any query parameters for the request
887
887
  - `headers`: (object) -- any additional headers (such as authentication) required for the request
888
888
  - `returnProperty` (or `outputProperty`): (string) -- an object path for which property to extract from the returned data. E.g. if the API returns `{name: {first: "Bruce", last: "Banner"}, age: 35}` and you specify `returnProperty: "name.first`, the operator will return `"Bruce"` (Uses the same logic as the [objectProperties](#object_properties) internally)
889
889
 
@@ -946,7 +946,8 @@ The "POST" operator is basically structurally the same as [GET](#get).
946
946
 
947
947
  #### Properties
948
948
 
949
- - `url`/`endpoint`<sup>*</sup>,`parameters`, `headers`, `returnProperty`/`outputProperty` -- same as "GET" operator (although the `parameters` object will be passed to the Post request as body JSON rather than url query parameters)
949
+ - `url`/`endpoint`<sup>*</sup>, `headers`, `returnProperty`/`outputProperty` -- same as "GET" operator.
950
+ - `parameters` (or `bodyJson`, `data`) -- passed to the Post request as body JSON rather than url query parameters (hence the different aliases)
950
951
 
951
952
  e.g.
952
953
  ```js
@@ -1690,6 +1691,7 @@ Please open an issue: https://github.com/CarlosNZ/fig-tree-evaluator/issues
1690
1691
 
1691
1692
  *Trivial upgrades (e.g. documentation, small re-factors, types, etc.) not included*
1692
1693
 
1694
+ - **v2.8.4**: Refactor types, better compliance with [ESLint](https://eslint.org/) rules, add more tests
1693
1695
  - **v2.8.0**:
1694
1696
  - [Shorthand syntax](#shorthand-syntax) (#80)
1695
1697
  - Methods to retrieve [metadata](#metadata) about operators, fragments and functions (#82)
@@ -1,4 +1,4 @@
1
- import { EvaluatorNode, FigTreeOptions } from './types';
1
+ import { EvaluatorNode, FigTreeOptions, OperatorMetadata, FragmentMetadata } from './types';
2
2
  declare class FigTreeEvaluator {
3
3
  private options;
4
4
  private operators;
@@ -9,25 +9,15 @@ declare class FigTreeEvaluator {
9
9
  evaluate(expression: EvaluatorNode, options?: FigTreeOptions): Promise<import("./types").EvaluatorOutput>;
10
10
  getOptions(): FigTreeOptions;
11
11
  updateOptions(options: FigTreeOptions): void;
12
- getOperators(): {
13
- description: string;
14
- aliases: string[];
15
- parameters: import("./types").Parameter[];
16
- operator: string;
17
- }[];
18
- getFragments(): {
19
- description?: string | undefined;
20
- parameters?: Record<string, {
21
- type: string | string[];
22
- required: boolean;
23
- }> | undefined;
12
+ getOperators(): readonly OperatorMetadata[];
13
+ getFragments(): readonly (FragmentMetadata & {
24
14
  name: string;
25
- }[];
26
- getCustomFunctions(): {
15
+ })[];
16
+ getCustomFunctions(): readonly {
27
17
  name: string;
28
18
  numRequiredArgs: number;
29
19
  }[];
30
- getVersion: () => any;
20
+ getVersion: () => string;
31
21
  }
32
22
  export default FigTreeEvaluator;
33
23
  export declare const evaluateExpression: (expression: EvaluatorNode, options?: FigTreeOptions) => Promise<import("./types").EvaluatorOutput>;
@@ -42,18 +42,19 @@ const _operatorAliases_json_1 = __importDefault(require("./operators/_operatorAl
42
42
  const operators = __importStar(require("./operators"));
43
43
  const helpers_1 = require("./helpers");
44
44
  const cache_1 = __importDefault(require("./cache"));
45
- const pkg = require('../package.json');
45
+ const version_1 = require("./version");
46
46
  const operatorAliases = _operatorAliases_json_1.default;
47
47
  class FigTreeEvaluator {
48
48
  constructor(options = {}) {
49
49
  var _a, _b;
50
50
  this.typeChecker = (...args) => {
51
- const result = (0, typeCheck_1.typeCheck)(...args);
51
+ const inputArgs = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
52
+ const result = (0, typeCheck_1.typeCheck)(...inputArgs);
52
53
  if (result === true)
53
54
  return;
54
55
  throw new Error(result);
55
56
  };
56
- this.getVersion = () => pkg.version;
57
+ this.getVersion = () => version_1.version;
57
58
  this.options = standardiseOptionNames(options);
58
59
  this.operators = (0, helpers_1.filterOperators)(operators, (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.excludeOperators) !== null && _b !== void 0 ? _b : [], operatorAliases);
59
60
  this.operatorAliases = operatorAliases;
@@ -70,7 +71,10 @@ class FigTreeEvaluator {
70
71
  ? (0, helpers_1.filterOperators)(operators, options.excludeOperators, operatorAliases)
71
72
  : this.operators,
72
73
  operatorAliases: this.operatorAliases,
73
- typeChecker: currentOptions.skipRuntimeTypeCheck ? () => { } : this.typeChecker,
74
+ typeChecker: currentOptions.skipRuntimeTypeCheck
75
+ ? () => {
76
+ }
77
+ : this.typeChecker,
74
78
  resolvedAliasNodes: {},
75
79
  cache: this.cache,
76
80
  });
package/build/cache.d.ts CHANGED
@@ -1,10 +1,12 @@
1
+ import { EvaluatorOutput, UnknownFunction } from './types';
1
2
  declare class FigTreeCache {
2
3
  private store;
3
4
  private queue;
4
5
  private maxSize;
5
6
  constructor(maxSize?: number);
6
- useCache: (shouldUseCache: boolean, action: Function, ...args: unknown[]) => Promise<any>;
7
+ useCache: (shouldUseCache: boolean, action: UnknownFunction, ...args: unknown[]) => Promise<EvaluatorOutput>;
7
8
  getMax: () => number;
8
9
  setMax: (size: number) => void;
10
+ private resizeCache;
9
11
  }
10
12
  export default FigTreeCache;
package/build/cache.js CHANGED
@@ -23,17 +23,21 @@ class FigTreeCache {
23
23
  }
24
24
  const result = yield action(...args);
25
25
  this.store[key] = result;
26
- if (this.queue.length >= this.maxSize) {
27
- const keysToRemove = this.queue.slice(this.maxSize - 1);
28
- keysToRemove.forEach((key) => delete this.store[key]);
29
- this.queue = this.queue.slice(0, this.maxSize - 1);
30
- }
31
26
  this.queue.unshift(key);
27
+ this.resizeCache();
32
28
  return result;
33
29
  });
34
30
  this.getMax = () => this.maxSize;
35
31
  this.setMax = (size) => {
36
32
  this.maxSize = size;
33
+ this.resizeCache();
34
+ };
35
+ this.resizeCache = () => {
36
+ if (this.queue.length > this.maxSize) {
37
+ const keysToRemove = this.queue.slice(this.maxSize);
38
+ keysToRemove.forEach((key) => delete this.store[key]);
39
+ this.queue = this.queue.slice(0, this.maxSize);
40
+ }
37
41
  };
38
42
  this.store = {};
39
43
  this.queue = [];
@@ -41,9 +45,4 @@ class FigTreeCache {
41
45
  }
42
46
  }
43
47
  exports.default = FigTreeCache;
44
- const stringifyInput = (args) => {
45
- return args.reduce((outputString, arg, index) => {
46
- const part = typeof arg === 'object' ? JSON.stringify(arg) : arg;
47
- return index === 0 ? `${part}` : `${outputString}_${part}`;
48
- }, '');
49
- };
48
+ const stringifyInput = (args) => args.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : arg)).join('_');
package/build/evaluate.js CHANGED
@@ -41,7 +41,6 @@ const evaluatorFunction = (input, config) => __awaiter(void 0, void 0, void 0, f
41
41
  return (0, helpers_1.replaceAliasNodeValues)(fragmentReplacement, config);
42
42
  expression = Object.assign(Object.assign(Object.assign({}, expression), fragmentReplacement), parameters);
43
43
  delete expression.fragment;
44
- delete expression.parameters;
45
44
  }
46
45
  try {
47
46
  const operator = (0, helpers_1.getOperatorName)(expression.operator, operatorAliases);
@@ -49,29 +48,27 @@ const evaluatorFunction = (input, config) => __awaiter(void 0, void 0, void 0, f
49
48
  return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Invalid operator: ${expression.operator}`, returnErrorAsString);
50
49
  if (!config.operators[operator])
51
50
  return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Excluded operator: ${expression.operator}`, returnErrorAsString);
52
- const { requiredProperties, propertyAliases, evaluate, parseChildren } = operators[operator];
51
+ const { propertyAliases, evaluate, parseChildren } = operators[operator];
53
52
  expression = (0, helpers_1.mapPropertyAliases)(propertyAliases, expression);
54
53
  const newAliasNodes = yield (0, helpers_1.evaluateNodeAliases)(expression, config);
55
54
  if (!isFragment)
56
55
  Object.entries(newAliasNodes).forEach(([alias, result]) => (config.resolvedAliasNodes[alias] = result));
57
56
  const childConfig = isFragment
58
57
  ? Object.assign(Object.assign({}, config), { resolvedAliasNodes: Object.assign(Object.assign({}, config.resolvedAliasNodes), newAliasNodes) }) : config;
59
- const validationError = (0, helpers_1.checkRequiredNodes)(requiredProperties, expression);
60
- if (validationError)
61
- return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, childConfig), `Operator: ${operator}\n- ${validationError}`, returnErrorAsString);
62
58
  if ('children' in expression) {
63
59
  if (!Array.isArray(expression.children))
64
60
  expression.children = yield (0, exports.evaluatorFunction)(expression.children, childConfig);
65
61
  if (!Array.isArray(expression.children))
66
62
  return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Operator: ${operator}\n- Property "children" is not of type: array`, returnErrorAsString);
67
63
  expression = yield parseChildren(expression, childConfig);
64
+ delete expression.children;
68
65
  }
69
66
  let result;
70
67
  try {
71
68
  result = yield evaluate(expression, childConfig);
72
69
  }
73
70
  catch (err) {
74
- result = (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(expression.fallback, config), `Operator: ${operator}\n${(0, helpers_1.errorMessage)(err)}`, returnErrorAsString);
71
+ return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(expression.fallback, config), `Operator: ${operator}\n${(0, helpers_1.errorMessage)(err)}`, returnErrorAsString);
75
72
  }
76
73
  const outputType = (_d = expression === null || expression === void 0 ? void 0 : expression.outputType) !== null && _d !== void 0 ? _d : expression === null || expression === void 0 ? void 0 : expression.type;
77
74
  if (!outputType)
@@ -1,49 +1,23 @@
1
- import { OutputType, EvaluatorNode, CombinedOperatorNode, EvaluatorOutput, FigTreeOptions, OperatorNodeUnion, FigTreeConfig, OperatorReference, OperatorAliases } from './types';
1
+ import { OutputType, EvaluatorNode, EvaluatorOutput, FigTreeOptions, FigTreeConfig, OperatorReference, OperatorAliases, Operator, FragmentNode, OperatorNode } from './types';
2
2
  export declare const parseIfJson: (input: EvaluatorNode) => any;
3
3
  export declare const isOperatorNode: (input: EvaluatorNode) => boolean;
4
- export declare const isFragmentNode: (input: EvaluatorNode) => boolean;
5
- export declare const getOperatorName: (operator: string, operatorAliases: OperatorAliases) => "AND" | "OR" | "EQUAL" | "NOT_EQUAL" | "PLUS" | "SUBTRACT" | "MULTIPLY" | "DIVIDE" | "GREATER_THAN" | "LESS_THAN" | "CONDITIONAL" | "REGEX" | "OBJECT_PROPERTIES" | "STRING_SUBSTITUTION" | "SPLIT" | "COUNT" | "GET" | "POST" | "PG_SQL" | "GRAPHQL" | "BUILD_OBJECT" | "MATCH" | "CUSTOM_FUNCTIONS" | "PASSTHRU";
6
- export declare const filterOperators: (operators: OperatorReference, exclusions: string[], operatorAliases: OperatorAliases) => {
7
- AND: import("./types").OperatorObject;
8
- OR: import("./types").OperatorObject;
9
- EQUAL: import("./types").OperatorObject;
10
- NOT_EQUAL: import("./types").OperatorObject;
11
- PLUS: import("./types").OperatorObject;
12
- SUBTRACT: import("./types").OperatorObject;
13
- MULTIPLY: import("./types").OperatorObject;
14
- DIVIDE: import("./types").OperatorObject;
15
- GREATER_THAN: import("./types").OperatorObject;
16
- LESS_THAN: import("./types").OperatorObject;
17
- CONDITIONAL: import("./types").OperatorObject;
18
- REGEX: import("./types").OperatorObject;
19
- OBJECT_PROPERTIES: import("./types").OperatorObject;
20
- STRING_SUBSTITUTION: import("./types").OperatorObject;
21
- SPLIT: import("./types").OperatorObject;
22
- COUNT: import("./types").OperatorObject;
23
- GET: import("./types").OperatorObject;
24
- POST: import("./types").OperatorObject;
25
- PG_SQL: import("./types").OperatorObject;
26
- GRAPHQL: import("./types").OperatorObject;
27
- BUILD_OBJECT: import("./types").OperatorObject;
28
- MATCH: import("./types").OperatorObject;
29
- CUSTOM_FUNCTIONS: import("./types").OperatorObject;
30
- PASSTHRU: import("./types").OperatorObject;
31
- };
4
+ export declare const isFragmentNode: (input: EvaluatorNode) => input is FragmentNode;
5
+ export declare const getOperatorName: (operator: string, operatorAliases: OperatorAliases) => Operator | undefined;
6
+ export declare const filterOperators: (operators: OperatorReference, exclusions: string[], operatorAliases: OperatorAliases) => OperatorReference;
32
7
  export declare const truncateString: (string: string, length?: number) => string;
33
- export declare const fallbackOrError: (fallback: any, errorMessage: string, returnErrorAsString?: boolean) => any;
8
+ export declare const fallbackOrError: (fallback: EvaluatorOutput, errorMessage: string, returnErrorAsString?: boolean) => string | number | boolean | object | null;
34
9
  export declare const mapPropertyAliases: (propertyAliases: {
35
10
  [key: string]: string;
36
- }, expression: CombinedOperatorNode) => CombinedOperatorNode;
11
+ }, expression: OperatorNode) => OperatorNode;
37
12
  export declare const isAliasString: (value: string) => boolean;
38
- export declare const evaluateNodeAliases: (expression: OperatorNodeUnion, config: FigTreeConfig) => Promise<{
13
+ export declare const evaluateNodeAliases: (expression: OperatorNode, config: FigTreeConfig) => Promise<{
39
14
  [x: string]: EvaluatorOutput;
40
15
  }>;
41
16
  export declare const replaceAliasNodeValues: (value: EvaluatorOutput, { resolvedAliasNodes }: FigTreeConfig) => EvaluatorOutput;
42
- export declare const checkRequiredNodes: (requiredProps: readonly string[], expression: CombinedOperatorNode) => string | false;
43
17
  export declare const mergeOptions: (origOptions: FigTreeOptions, newOptions: FigTreeOptions) => FigTreeOptions;
44
18
  export declare const convertOutputMethods: {
45
19
  [key in OutputType]: (value: EvaluatorOutput) => EvaluatorOutput | EvaluatorOutput[];
46
20
  };
47
21
  export declare const errorMessage: (err: unknown) => string;
48
- export declare const isObject: (input: unknown) => boolean;
22
+ export declare const isObject: (input: unknown) => input is object;
49
23
  export declare const evaluateObject: (input: EvaluatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
package/build/helpers.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.evaluateObject = exports.isObject = exports.errorMessage = exports.convertOutputMethods = exports.mergeOptions = exports.checkRequiredNodes = exports.replaceAliasNodeValues = exports.evaluateNodeAliases = exports.isAliasString = exports.mapPropertyAliases = exports.fallbackOrError = exports.truncateString = exports.filterOperators = exports.getOperatorName = exports.isFragmentNode = exports.isOperatorNode = exports.parseIfJson = void 0;
12
+ exports.evaluateObject = exports.isObject = exports.errorMessage = exports.convertOutputMethods = exports.mergeOptions = exports.replaceAliasNodeValues = exports.evaluateNodeAliases = exports.isAliasString = exports.mapPropertyAliases = exports.fallbackOrError = exports.truncateString = exports.filterOperators = exports.getOperatorName = exports.isFragmentNode = exports.isOperatorNode = exports.parseIfJson = void 0;
13
13
  const change_case_1 = require("change-case");
14
14
  const evaluate_1 = require("./evaluate");
15
15
  const _operatorUtils_1 = require("./operators/_operatorUtils");
@@ -82,15 +82,6 @@ const replaceAliasNodeValues = (value, { resolvedAliasNodes }) => {
82
82
  return (_a = resolvedAliasNodes === null || resolvedAliasNodes === void 0 ? void 0 : resolvedAliasNodes[value]) !== null && _a !== void 0 ? _a : value;
83
83
  };
84
84
  exports.replaceAliasNodeValues = replaceAliasNodeValues;
85
- const checkRequiredNodes = (requiredProps, expression) => {
86
- const missingProps = requiredProps.filter((prop) => !(prop in expression));
87
- if (missingProps.length === 0)
88
- return false;
89
- if (!('children' in expression))
90
- return `Missing properties: ${missingProps}`;
91
- return false;
92
- };
93
- exports.checkRequiredNodes = checkRequiredNodes;
94
85
  const mergeOptions = (origOptions, newOptions) => {
95
86
  const combinedOptions = Object.assign(Object.assign({}, origOptions), newOptions);
96
87
  if (origOptions.data || newOptions.data)
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import FigTreeEvaluator, { evaluateExpression } from './FigTreeEvaluator';
2
- import { Operator, GenericObject, FigTreeOptions, EvaluatorNode, EvaluatorOutput } from './types';
3
- export { evaluateExpression, type Operator, type GenericObject, type FigTreeOptions, type EvaluatorNode, type EvaluatorOutput, };
2
+ import { Operator, FigTreeOptions, EvaluatorNode, EvaluatorOutput } from './types';
3
+ export { evaluateExpression, type Operator, type FigTreeOptions, type EvaluatorNode, type EvaluatorOutput, };
4
4
  export default FigTreeEvaluator;
@@ -1,5 +1,4 @@
1
1
  import { OperatorData } from '../../types';
2
- export declare const requiredProperties: string[];
3
2
  export declare const propertyAliases: Record<string, string>;
4
3
  declare const operatorData: OperatorData;
5
4
  export default operatorData;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyAliases = exports.requiredProperties = void 0;
3
+ exports.propertyAliases = void 0;
4
4
  const _operatorUtils_1 = require("../_operatorUtils");
5
5
  const description = 'Logical AND';
6
6
  const aliases = ['and', '&', '&&'];
@@ -13,7 +13,6 @@ const parameters = [
13
13
  type: 'array',
14
14
  },
15
15
  ];
16
- exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
17
16
  exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
18
17
  const operatorData = {
19
18
  description,
@@ -1 +1 @@
1
- export { AND, type BasicExtendedNode } from './operator';
1
+ export { AND } from './operator';
@@ -1,7 +1,3 @@
1
- import { EvaluatorNode, BaseOperatorNode, CombinedOperatorNode, OperatorObject } from '../../types';
2
- import { requiredProperties } from './data';
3
- export type BasicExtendedNode = {
4
- [key in typeof requiredProperties[number]]: EvaluatorNode[];
5
- } & BaseOperatorNode;
6
- export declare const parseChildren: (expression: CombinedOperatorNode) => BasicExtendedNode;
1
+ import { OperatorObject, ParseChildrenMethod } from '../../types';
2
+ export declare const parseChildren: ParseChildrenMethod;
7
3
  export declare const AND: OperatorObject;
@@ -37,7 +37,7 @@ const _operatorUtils_1 = require("../_operatorUtils");
37
37
  const data_1 = __importStar(require("./data"));
38
38
  const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
39
39
  const values = (yield (0, _operatorUtils_1.evaluateArray)(expression.values, config));
40
- config.typeChecker(...(0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { values }));
40
+ config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { values }));
41
41
  return values.reduce((acc, val) => acc && !!val, true);
42
42
  });
43
43
  const parseChildren = (expression) => {
@@ -46,7 +46,6 @@ const parseChildren = (expression) => {
46
46
  };
47
47
  exports.parseChildren = parseChildren;
48
48
  exports.AND = {
49
- requiredProperties: data_1.requiredProperties,
50
49
  propertyAliases: data_1.propertyAliases,
51
50
  operatorData: data_1.default,
52
51
  evaluate,
@@ -1,5 +1,4 @@
1
1
  import { OperatorData } from '../../types';
2
- export declare const requiredProperties: string[];
3
2
  export declare const propertyAliases: Record<string, string>;
4
3
  declare const operatorData: OperatorData;
5
4
  export default operatorData;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyAliases = exports.requiredProperties = void 0;
3
+ exports.propertyAliases = void 0;
4
4
  const _operatorUtils_1 = require("../_operatorUtils");
5
5
  const aliases = ['buildObject', 'build', 'object'];
6
6
  const description = 'Construct an object using objects defining keys and values';
@@ -13,7 +13,6 @@ const parameters = [
13
13
  type: 'array',
14
14
  },
15
15
  ];
16
- exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
17
16
  exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
18
17
  const operatorData = {
19
18
  description,
@@ -1,10 +1,2 @@
1
- import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../../types';
2
- export type BuildObjectNode = {
3
- properties: BuildObjectElement[];
4
- } & BaseOperatorNode;
5
- type BuildObjectElement = {
6
- key: EvaluatorNode;
7
- value: EvaluatorNode;
8
- };
1
+ import { OperatorObject } from '../../types';
9
2
  export declare const BUILD_OBJECT: OperatorObject;
10
- export {};
@@ -41,7 +41,7 @@ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, funct
41
41
  config.typeChecker({ name: 'key', value: key, expectedType: ['string', 'number', 'boolean'] });
42
42
  return [key, value];
43
43
  });
44
- config.typeChecker(...(0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { properties: expression.properties }));
44
+ config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { properties: expression.properties }));
45
45
  const evaluated = expression.properties
46
46
  .filter((element) => element instanceof Object && 'key' in element && 'value' in element)
47
47
  .map(({ key, value }) => evaluatePair([key, value]));
@@ -57,7 +57,6 @@ const parseChildren = (expression) => {
57
57
  return Object.assign(Object.assign({}, expression), { properties });
58
58
  };
59
59
  exports.BUILD_OBJECT = {
60
- requiredProperties: data_1.requiredProperties,
61
60
  propertyAliases: data_1.propertyAliases,
62
61
  operatorData: data_1.default,
63
62
  evaluate,
@@ -1,5 +1,4 @@
1
1
  import { OperatorData } from '../../types';
2
- export declare const requiredProperties: string[];
3
2
  export declare const propertyAliases: Record<string, string>;
4
3
  declare const operatorData: OperatorData;
5
4
  export default operatorData;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyAliases = exports.requiredProperties = void 0;
3
+ exports.propertyAliases = void 0;
4
4
  const _operatorUtils_1 = require("../_operatorUtils");
5
5
  const description = 'Return a value based on a condition';
6
6
  const aliases = ['?', 'conditional', 'ifThen'];
@@ -27,7 +27,6 @@ const parameters = [
27
27
  type: 'any',
28
28
  },
29
29
  ];
30
- exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
31
30
  exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
32
31
  const operatorData = {
33
32
  description,
@@ -1,6 +1,2 @@
1
- import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../../types';
2
- import { requiredProperties } from './data';
3
- export type ConditionalNode = {
4
- [key in typeof requiredProperties[number]]: EvaluatorNode;
5
- } & BaseOperatorNode;
1
+ import { OperatorObject } from '../../types';
6
2
  export declare const CONDITIONAL: OperatorObject;
@@ -34,10 +34,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.CONDITIONAL = void 0;
36
36
  const evaluate_1 = require("../../evaluate");
37
+ const _operatorUtils_1 = require("../_operatorUtils");
37
38
  const data_1 = __importStar(require("./data"));
38
39
  const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
40
+ config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, {
41
+ condition: expression.condition,
42
+ valueIfTrue: expression.valueIfTrue,
43
+ valueIfFalse: expression.valueIfFalse,
44
+ }));
39
45
  const condition = yield (0, evaluate_1.evaluatorFunction)(expression.condition, config);
40
- return !!condition
46
+ return condition
41
47
  ? yield (0, evaluate_1.evaluatorFunction)(expression.valueIfTrue, config)
42
48
  : yield (0, evaluate_1.evaluatorFunction)(expression.valueIfFalse, config);
43
49
  });
@@ -46,7 +52,6 @@ const parseChildren = (expression) => {
46
52
  return Object.assign(Object.assign({}, expression), { condition, valueIfTrue, valueIfFalse });
47
53
  };
48
54
  exports.CONDITIONAL = {
49
- requiredProperties: data_1.requiredProperties,
50
55
  propertyAliases: data_1.propertyAliases,
51
56
  operatorData: data_1.default,
52
57
  evaluate,
@@ -1,5 +1,4 @@
1
1
  import { OperatorData } from '../../types';
2
- export declare const requiredProperties: string[];
3
2
  export declare const propertyAliases: Record<string, string>;
4
3
  declare const operatorData: OperatorData;
5
4
  export default operatorData;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyAliases = exports.requiredProperties = void 0;
3
+ exports.propertyAliases = void 0;
4
4
  const _operatorUtils_1 = require("../_operatorUtils");
5
5
  const description = 'Count elements in an array';
6
6
  const aliases = ['count', 'length'];
@@ -13,7 +13,6 @@ const parameters = [
13
13
  type: 'array',
14
14
  },
15
15
  ];
16
- exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
17
16
  exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
18
17
  const operatorData = {
19
18
  description,
@@ -38,11 +38,10 @@ const _operatorUtils_1 = require("../_operatorUtils");
38
38
  const data_1 = __importStar(require("./data"));
39
39
  const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
40
40
  const values = yield (0, _operatorUtils_1.evaluateArray)(expression.values, config);
41
- config.typeChecker(...(0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { values }));
41
+ config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { values }));
42
42
  return values.length;
43
43
  });
44
44
  exports.COUNT = {
45
- requiredProperties: data_1.requiredProperties,
46
45
  propertyAliases: data_1.propertyAliases,
47
46
  operatorData: data_1.default,
48
47
  evaluate,
@@ -1,5 +1,4 @@
1
1
  import { OperatorData } from '../../types';
2
- export declare const requiredProperties: string[];
3
2
  export declare const propertyAliases: Record<string, string>;
4
3
  declare const operatorData: OperatorData;
5
4
  export default operatorData;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyAliases = exports.requiredProperties = void 0;
3
+ exports.propertyAliases = void 0;
4
4
  const _operatorUtils_1 = require("../_operatorUtils");
5
5
  const description = 'Call a custom function (defined in options)';
6
6
  const aliases = [
@@ -24,10 +24,16 @@ const parameters = [
24
24
  description: 'Arguments for the function',
25
25
  aliases: ['arguments', 'variables'],
26
26
  required: false,
27
- type: ['array'],
27
+ type: 'array',
28
+ },
29
+ {
30
+ name: 'useCache',
31
+ description: 'Whether or not the FigTree cache is used',
32
+ aliases: [],
33
+ required: false,
34
+ type: 'boolean',
28
35
  },
29
36
  ];
30
- exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
31
37
  exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
32
38
  const operatorData = {
33
39
  description,
@@ -1,8 +1,2 @@
1
- import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../../types';
2
- import { requiredProperties } from './data';
3
- export type FunctionNode = {
4
- [key in typeof requiredProperties[number]]: EvaluatorNode;
5
- } & BaseOperatorNode & {
6
- args: EvaluatorNode[];
7
- };
1
+ import { OperatorObject } from '../../types';
8
2
  export declare const CUSTOM_FUNCTIONS: OperatorObject;
@@ -40,12 +40,14 @@ const object_property_extractor_1 = __importDefault(require("object-property-ext
40
40
  const _operatorUtils_1 = require("../_operatorUtils");
41
41
  const data_1 = __importStar(require("./data"));
42
42
  const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
43
- var _a, _b, _c, _d;
44
- const [functionPath, ...args] = (yield (0, _operatorUtils_1.evaluateArray)([expression.functionPath, ...(expression.args || [])], config));
45
- config.typeChecker(...(0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { functionPath, args }));
43
+ var _a, _b, _c;
44
+ const [functionPath, args = [], useCache] = (yield (0, _operatorUtils_1.evaluateArray)([expression.functionPath, expression.args, expression.useCache], config));
45
+ config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { functionPath, args }));
46
46
  const { data, functions } = config.options;
47
- const func = ((_b = (_a = (0, object_property_extractor_1.default)(functions, functionPath, null)) !== null && _a !== void 0 ? _a : (0, object_property_extractor_1.default)(data, functionPath, null)) !== null && _b !== void 0 ? _b : (0, object_property_extractor_1.default)(config.options, functionPath));
48
- const shouldUseCache = (_d = (_c = expression.useCache) !== null && _c !== void 0 ? _c : config.options.useCache) !== null && _d !== void 0 ? _d : false;
47
+ const func = (_b = (_a = (0, object_property_extractor_1.default)(functions, functionPath, null)) !== null && _a !== void 0 ? _a : (0, object_property_extractor_1.default)(data, functionPath, null)) !== null && _b !== void 0 ? _b : (0, object_property_extractor_1.default)(config.options, functionPath, null);
48
+ if (!func || typeof func !== 'function')
49
+ throw new Error(`- No function found: "${functionPath}"`);
50
+ const shouldUseCache = (_c = useCache !== null && useCache !== void 0 ? useCache : config.options.useCache) !== null && _c !== void 0 ? _c : false;
49
51
  const result = yield config.cache.useCache(shouldUseCache, (_, ...args) => __awaiter(void 0, void 0, void 0, function* () {
50
52
  return yield func(...args);
51
53
  }), functionPath, ...args);
@@ -56,7 +58,6 @@ const parseChildren = (expression) => {
56
58
  return Object.assign(Object.assign({}, expression), { functionPath, args });
57
59
  };
58
60
  exports.CUSTOM_FUNCTIONS = {
59
- requiredProperties: data_1.requiredProperties,
60
61
  propertyAliases: data_1.propertyAliases,
61
62
  operatorData: data_1.default,
62
63
  evaluate,
@@ -1,5 +1,4 @@
1
1
  import { OperatorData } from '../../types';
2
- export declare const requiredProperties: string[];
3
2
  export declare const propertyAliases: Record<string, string>;
4
3
  declare const operatorData: OperatorData;
5
4
  export default operatorData;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyAliases = exports.requiredProperties = void 0;
3
+ exports.propertyAliases = void 0;
4
4
  const _operatorUtils_1 = require("../_operatorUtils");
5
5
  const description = 'Divide one numerical value by another';
6
6
  const aliases = ['/', 'divide', '÷'];
@@ -31,10 +31,9 @@ const parameters = [
31
31
  description: 'Whether to output a quotient, remainder or decimal',
32
32
  aliases: [],
33
33
  required: false,
34
- type: 'string',
34
+ type: { literal: ['quotient', 'remainder'] },
35
35
  },
36
36
  ];
37
- exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
38
37
  exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
39
38
  const operatorData = {
40
39
  description,
@@ -1,12 +1,2 @@
1
- import { BasicExtendedNode } from '../AND/operator';
2
- import { EvaluatorNode, OperatorObject, BaseOperatorNode } from '../../types';
3
- interface DivisionNodeWithProps extends BaseOperatorNode {
4
- dividend: EvaluatorNode;
5
- divisor: EvaluatorNode;
6
- }
7
- type DivisionOutput = 'quotient' | 'remainder';
8
- export type DivisionNode = BasicExtendedNode & DivisionNodeWithProps & {
9
- output?: DivisionOutput;
10
- };
1
+ import { OperatorObject } from '../../types';
11
2
  export declare const DIVIDE: OperatorObject;
12
- export {};