fig-tree-evaluator 2.9.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +104 -8
  2. package/build/index.cjs.js +1 -0
  3. package/build/index.d.ts +121 -4
  4. package/build/index.esm.js +1 -0
  5. package/package.json +12 -3
  6. package/build/FigTreeEvaluator.d.ts +0 -26
  7. package/build/FigTreeEvaluator.js +0 -121
  8. package/build/cache.d.ts +0 -27
  9. package/build/cache.js +0 -63
  10. package/build/evaluate.d.ts +0 -2
  11. package/build/evaluate.js +0 -87
  12. package/build/helpers.d.ts +0 -23
  13. package/build/helpers.js +0 -137
  14. package/build/index.js +0 -29
  15. package/build/operators/AND/data.d.ts +0 -4
  16. package/build/operators/AND/data.js +0 -22
  17. package/build/operators/AND/index.d.ts +0 -1
  18. package/build/operators/AND/index.js +0 -5
  19. package/build/operators/AND/operator.d.ts +0 -3
  20. package/build/operators/AND/operator.js +0 -53
  21. package/build/operators/BUILD_OBJECT/data.d.ts +0 -4
  22. package/build/operators/BUILD_OBJECT/data.js +0 -22
  23. package/build/operators/BUILD_OBJECT/index.d.ts +0 -1
  24. package/build/operators/BUILD_OBJECT/index.js +0 -17
  25. package/build/operators/BUILD_OBJECT/operator.d.ts +0 -2
  26. package/build/operators/BUILD_OBJECT/operator.js +0 -64
  27. package/build/operators/CONDITIONAL/data.d.ts +0 -4
  28. package/build/operators/CONDITIONAL/data.js +0 -36
  29. package/build/operators/CONDITIONAL/index.d.ts +0 -1
  30. package/build/operators/CONDITIONAL/index.js +0 -17
  31. package/build/operators/CONDITIONAL/operator.d.ts +0 -2
  32. package/build/operators/CONDITIONAL/operator.js +0 -59
  33. package/build/operators/COUNT/data.d.ts +0 -4
  34. package/build/operators/COUNT/data.js +0 -22
  35. package/build/operators/COUNT/index.d.ts +0 -1
  36. package/build/operators/COUNT/index.js +0 -17
  37. package/build/operators/COUNT/operator.d.ts +0 -2
  38. package/build/operators/COUNT/operator.js +0 -52
  39. package/build/operators/CUSTOM_FUNCTIONS/data.d.ts +0 -4
  40. package/build/operators/CUSTOM_FUNCTIONS/data.js +0 -43
  41. package/build/operators/CUSTOM_FUNCTIONS/index.d.ts +0 -1
  42. package/build/operators/CUSTOM_FUNCTIONS/index.js +0 -17
  43. package/build/operators/CUSTOM_FUNCTIONS/operator.d.ts +0 -2
  44. package/build/operators/CUSTOM_FUNCTIONS/operator.js +0 -65
  45. package/build/operators/DIVIDE/data.d.ts +0 -4
  46. package/build/operators/DIVIDE/data.js +0 -43
  47. package/build/operators/DIVIDE/index.d.ts +0 -1
  48. package/build/operators/DIVIDE/index.js +0 -17
  49. package/build/operators/DIVIDE/operator.d.ts +0 -2
  50. package/build/operators/DIVIDE/operator.js +0 -63
  51. package/build/operators/EQUAL/data.d.ts +0 -4
  52. package/build/operators/EQUAL/data.js +0 -29
  53. package/build/operators/EQUAL/index.d.ts +0 -1
  54. package/build/operators/EQUAL/index.js +0 -17
  55. package/build/operators/EQUAL/operator.d.ts +0 -2
  56. package/build/operators/EQUAL/operator.js +0 -58
  57. package/build/operators/GET/data.d.ts +0 -4
  58. package/build/operators/GET/data.js +0 -50
  59. package/build/operators/GET/index.d.ts +0 -1
  60. package/build/operators/GET/index.js +0 -5
  61. package/build/operators/GET/operator.d.ts +0 -3
  62. package/build/operators/GET/operator.js +0 -91
  63. package/build/operators/GRAPHQL/data.d.ts +0 -4
  64. package/build/operators/GRAPHQL/data.js +0 -57
  65. package/build/operators/GRAPHQL/index.d.ts +0 -1
  66. package/build/operators/GRAPHQL/index.js +0 -17
  67. package/build/operators/GRAPHQL/operator.d.ts +0 -8
  68. package/build/operators/GRAPHQL/operator.js +0 -86
  69. package/build/operators/GREATER_THAN/data.d.ts +0 -4
  70. package/build/operators/GREATER_THAN/data.js +0 -29
  71. package/build/operators/GREATER_THAN/index.d.ts +0 -1
  72. package/build/operators/GREATER_THAN/index.js +0 -17
  73. package/build/operators/GREATER_THAN/operator.d.ts +0 -2
  74. package/build/operators/GREATER_THAN/operator.js +0 -54
  75. package/build/operators/LESS_THAN/data.d.ts +0 -4
  76. package/build/operators/LESS_THAN/data.js +0 -29
  77. package/build/operators/LESS_THAN/index.d.ts +0 -1
  78. package/build/operators/LESS_THAN/index.js +0 -17
  79. package/build/operators/LESS_THAN/operator.d.ts +0 -2
  80. package/build/operators/LESS_THAN/operator.js +0 -54
  81. package/build/operators/MATCH/data.d.ts +0 -4
  82. package/build/operators/MATCH/data.js +0 -29
  83. package/build/operators/MATCH/index.d.ts +0 -1
  84. package/build/operators/MATCH/index.js +0 -17
  85. package/build/operators/MATCH/operator.d.ts +0 -2
  86. package/build/operators/MATCH/operator.js +0 -72
  87. package/build/operators/MULTIPLY/data.d.ts +0 -4
  88. package/build/operators/MULTIPLY/data.js +0 -22
  89. package/build/operators/MULTIPLY/index.d.ts +0 -1
  90. package/build/operators/MULTIPLY/index.js +0 -17
  91. package/build/operators/MULTIPLY/operator.d.ts +0 -2
  92. package/build/operators/MULTIPLY/operator.js +0 -53
  93. package/build/operators/NOT_EQUAL/data.d.ts +0 -4
  94. package/build/operators/NOT_EQUAL/data.js +0 -29
  95. package/build/operators/NOT_EQUAL/index.d.ts +0 -1
  96. package/build/operators/NOT_EQUAL/index.js +0 -17
  97. package/build/operators/NOT_EQUAL/operator.d.ts +0 -2
  98. package/build/operators/NOT_EQUAL/operator.js +0 -58
  99. package/build/operators/OBJECT_PROPERTIES/data.d.ts +0 -4
  100. package/build/operators/OBJECT_PROPERTIES/data.js +0 -37
  101. package/build/operators/OBJECT_PROPERTIES/index.d.ts +0 -1
  102. package/build/operators/OBJECT_PROPERTIES/index.js +0 -17
  103. package/build/operators/OBJECT_PROPERTIES/operator.d.ts +0 -2
  104. package/build/operators/OBJECT_PROPERTIES/operator.js +0 -62
  105. package/build/operators/OR/data.d.ts +0 -4
  106. package/build/operators/OR/data.js +0 -22
  107. package/build/operators/OR/index.d.ts +0 -1
  108. package/build/operators/OR/index.js +0 -17
  109. package/build/operators/OR/operator.d.ts +0 -2
  110. package/build/operators/OR/operator.js +0 -49
  111. package/build/operators/PASSTHRU/data.d.ts +0 -4
  112. package/build/operators/PASSTHRU/data.js +0 -22
  113. package/build/operators/PASSTHRU/index.d.ts +0 -1
  114. package/build/operators/PASSTHRU/index.js +0 -17
  115. package/build/operators/PASSTHRU/operator.d.ts +0 -2
  116. package/build/operators/PASSTHRU/operator.js +0 -53
  117. package/build/operators/PG_SQL/data.d.ts +0 -4
  118. package/build/operators/PG_SQL/data.js +0 -43
  119. package/build/operators/PG_SQL/index.d.ts +0 -1
  120. package/build/operators/PG_SQL/index.js +0 -17
  121. package/build/operators/PG_SQL/operator.d.ts +0 -2
  122. package/build/operators/PG_SQL/operator.js +0 -83
  123. package/build/operators/PLUS/data.d.ts +0 -4
  124. package/build/operators/PLUS/data.js +0 -29
  125. package/build/operators/PLUS/index.d.ts +0 -1
  126. package/build/operators/PLUS/index.js +0 -17
  127. package/build/operators/PLUS/operator.d.ts +0 -2
  128. package/build/operators/PLUS/operator.js +0 -63
  129. package/build/operators/POST/data.d.ts +0 -4
  130. package/build/operators/POST/data.js +0 -50
  131. package/build/operators/POST/index.d.ts +0 -1
  132. package/build/operators/POST/index.js +0 -17
  133. package/build/operators/POST/operator.d.ts +0 -2
  134. package/build/operators/POST/operator.js +0 -72
  135. package/build/operators/REGEX/data.d.ts +0 -4
  136. package/build/operators/REGEX/data.js +0 -29
  137. package/build/operators/REGEX/index.d.ts +0 -1
  138. package/build/operators/REGEX/index.js +0 -17
  139. package/build/operators/REGEX/operator.d.ts +0 -2
  140. package/build/operators/REGEX/operator.js +0 -59
  141. package/build/operators/SPLIT/data.d.ts +0 -4
  142. package/build/operators/SPLIT/data.js +0 -43
  143. package/build/operators/SPLIT/index.d.ts +0 -1
  144. package/build/operators/SPLIT/index.js +0 -17
  145. package/build/operators/SPLIT/operator.d.ts +0 -2
  146. package/build/operators/SPLIT/operator.js +0 -69
  147. package/build/operators/STRING_SUBSTITUTION/data.d.ts +0 -4
  148. package/build/operators/STRING_SUBSTITUTION/data.js +0 -29
  149. package/build/operators/STRING_SUBSTITUTION/index.d.ts +0 -1
  150. package/build/operators/STRING_SUBSTITUTION/index.js +0 -17
  151. package/build/operators/STRING_SUBSTITUTION/operator.d.ts +0 -2
  152. package/build/operators/STRING_SUBSTITUTION/operator.js +0 -59
  153. package/build/operators/SUBTRACT/data.d.ts +0 -4
  154. package/build/operators/SUBTRACT/data.js +0 -36
  155. package/build/operators/SUBTRACT/index.d.ts +0 -1
  156. package/build/operators/SUBTRACT/index.js +0 -17
  157. package/build/operators/SUBTRACT/operator.d.ts +0 -2
  158. package/build/operators/SUBTRACT/operator.js +0 -54
  159. package/build/operators/_operatorAliases.json +0 -92
  160. package/build/operators/_operatorUtils.d.ts +0 -24
  161. package/build/operators/_operatorUtils.js +0 -122
  162. package/build/operators/index.d.ts +0 -24
  163. package/build/operators/index.js +0 -40
  164. package/build/shorthandSyntax.d.ts +0 -2
  165. package/build/shorthandSyntax.js +0 -55
  166. package/build/typeCheck.d.ts +0 -12
  167. package/build/typeCheck.js +0 -54
  168. package/build/types.d.ts +0 -96
  169. package/build/types.js +0 -29
  170. package/build/version.d.ts +0 -1
  171. package/build/version.js +0 -4
@@ -1,121 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.evaluateExpression = void 0;
39
- const evaluate_1 = require("./evaluate");
40
- const typeCheck_1 = require("./typeCheck");
41
- const _operatorAliases_json_1 = __importDefault(require("./operators/_operatorAliases.json"));
42
- const operators = __importStar(require("./operators"));
43
- const helpers_1 = require("./helpers");
44
- const cache_1 = __importDefault(require("./cache"));
45
- const version_1 = require("./version");
46
- const operatorAliases = _operatorAliases_json_1.default;
47
- class FigTreeEvaluator {
48
- constructor(options = {}) {
49
- var _a, _b;
50
- this.typeChecker = (...args) => {
51
- const inputArgs = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
52
- const result = (0, typeCheck_1.typeCheck)(...inputArgs);
53
- if (result === true)
54
- return;
55
- throw new Error(result);
56
- };
57
- this.getCache = () => this.cache.getCache();
58
- this.setCache = (cache) => this.cache.setCache(cache);
59
- this.getVersion = () => version_1.version;
60
- this.options = standardiseOptionNames(options);
61
- 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);
62
- this.operatorAliases = operatorAliases;
63
- this.cache = new cache_1.default({ maxSize: options.maxCacheSize, maxTime: options.maxCacheTime });
64
- }
65
- evaluate(expression, options = {}) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const currentOptions = (0, helpers_1.mergeOptions)(this.options, standardiseOptionNames(options));
68
- if (currentOptions.maxCacheSize && currentOptions.maxCacheSize !== this.cache.getMax())
69
- this.cache.setMax(currentOptions.maxCacheSize);
70
- if (currentOptions.maxCacheTime && currentOptions.maxCacheTime !== this.cache.getMaxTime())
71
- this.cache.setMaxTime(currentOptions.maxCacheTime);
72
- return yield (0, evaluate_1.evaluatorFunction)(expression, {
73
- options: currentOptions,
74
- operators: options.excludeOperators
75
- ? (0, helpers_1.filterOperators)(operators, options.excludeOperators, operatorAliases)
76
- : this.operators,
77
- operatorAliases: this.operatorAliases,
78
- typeChecker: currentOptions.skipRuntimeTypeCheck
79
- ? () => {
80
- }
81
- : this.typeChecker,
82
- resolvedAliasNodes: {},
83
- cache: this.cache,
84
- });
85
- });
86
- }
87
- getOptions() {
88
- return this.options;
89
- }
90
- updateOptions(options) {
91
- this.options = (0, helpers_1.mergeOptions)(this.options, standardiseOptionNames(options));
92
- if (this.options.excludeOperators)
93
- this.operators = (0, helpers_1.filterOperators)(operators, this.options.excludeOperators, operatorAliases);
94
- }
95
- getOperators() {
96
- const validOperators = this.options.excludeOperators
97
- ? (0, helpers_1.filterOperators)(operators, this.options.excludeOperators, operatorAliases)
98
- : this.operators;
99
- return Object.entries(validOperators).map(([key, value]) => (Object.assign({ operator: key }, value.operatorData)));
100
- }
101
- getFragments() {
102
- var _a;
103
- return Object.entries((_a = this.options.fragments) !== null && _a !== void 0 ? _a : {}).map(([key, value]) => (Object.assign({ name: key }, value === null || value === void 0 ? void 0 : value.metadata)));
104
- }
105
- getCustomFunctions() {
106
- var _a;
107
- return Object.entries((_a = this.options.functions) !== null && _a !== void 0 ? _a : {}).map(([name, value]) => ({
108
- name,
109
- numRequiredArgs: value.length,
110
- }));
111
- }
112
- }
113
- exports.default = FigTreeEvaluator;
114
- const evaluateExpression = (expression, options) => new FigTreeEvaluator(options).evaluate(expression);
115
- exports.evaluateExpression = evaluateExpression;
116
- const standardiseOptionNames = (options) => {
117
- if ('objects' in options) {
118
- return Object.assign(Object.assign({}, options), { data: options.objects });
119
- }
120
- return options;
121
- };
package/build/cache.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { EvaluatorOutput, UnknownFunction } from './types';
2
- interface CacheOptions {
3
- maxSize?: number;
4
- maxTime?: number;
5
- }
6
- export interface Store {
7
- [key: string]: {
8
- result: EvaluatorOutput;
9
- timestamp: number;
10
- };
11
- }
12
- declare class FigTreeCache {
13
- private store;
14
- private queue;
15
- private maxSize;
16
- private maxTime;
17
- constructor(options?: CacheOptions);
18
- useCache: (shouldUseCache: boolean, action: UnknownFunction, ...args: unknown[]) => Promise<EvaluatorOutput>;
19
- getMax: () => number;
20
- setMax: (size: number) => void;
21
- getMaxTime: () => number;
22
- setMaxTime: (time: number) => void;
23
- getCache: () => Store;
24
- setCache: (cache: Store) => Store;
25
- private resizeCache;
26
- }
27
- export default FigTreeCache;
package/build/cache.js DELETED
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const MAX_CACHED_ITEMS = 50;
13
- const MAX_CACHE_TIME = 1800;
14
- class FigTreeCache {
15
- constructor(options) {
16
- var _a, _b;
17
- this.useCache = (shouldUseCache, action, ...args) => __awaiter(this, void 0, void 0, function* () {
18
- if (!shouldUseCache)
19
- return yield action(...args);
20
- const key = stringifyInput(args);
21
- const keyExists = key in this.store;
22
- const newTimestamp = Date.now();
23
- const isExpired = keyExists && newTimestamp - this.store[key].timestamp > this.maxTime * 1000;
24
- if (keyExists) {
25
- this.queue = this.queue.filter((val) => val !== key);
26
- this.queue.unshift(key);
27
- this.store[key].timestamp = newTimestamp;
28
- if (isExpired)
29
- this.store[key].result = yield action(...args);
30
- return this.store[key].result;
31
- }
32
- const result = yield action(...args);
33
- this.store[key] = { result, timestamp: newTimestamp };
34
- this.queue.unshift(key);
35
- this.resizeCache();
36
- return result;
37
- });
38
- this.getMax = () => this.maxSize;
39
- this.setMax = (size) => {
40
- this.maxSize = size;
41
- this.resizeCache();
42
- };
43
- this.getMaxTime = () => this.maxTime;
44
- this.setMaxTime = (time) => {
45
- this.maxTime = time;
46
- };
47
- this.getCache = () => this.store;
48
- this.setCache = (cache) => (this.store = cache);
49
- this.resizeCache = () => {
50
- if (this.queue.length > this.maxSize) {
51
- const keysToRemove = this.queue.slice(this.maxSize);
52
- keysToRemove.forEach((key) => delete this.store[key]);
53
- this.queue = this.queue.slice(0, this.maxSize);
54
- }
55
- };
56
- this.store = {};
57
- this.queue = [];
58
- this.maxSize = (_a = options === null || options === void 0 ? void 0 : options.maxSize) !== null && _a !== void 0 ? _a : MAX_CACHED_ITEMS;
59
- this.maxTime = (_b = options === null || options === void 0 ? void 0 : options.maxTime) !== null && _b !== void 0 ? _b : MAX_CACHE_TIME;
60
- }
61
- }
62
- exports.default = FigTreeCache;
63
- const stringifyInput = (args) => args.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : arg)).join('_');
@@ -1,2 +0,0 @@
1
- import { FigTreeConfig, EvaluatorNode, EvaluatorOutput } from './types';
2
- export declare const evaluatorFunction: (input: EvaluatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
package/build/evaluate.js DELETED
@@ -1,87 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.evaluatorFunction = void 0;
13
- const _operatorUtils_1 = require("./operators/_operatorUtils");
14
- const shorthandSyntax_1 = require("./shorthandSyntax");
15
- const helpers_1 = require("./helpers");
16
- const evaluatorFunction = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
17
- var _a, _b, _c, _d;
18
- const { options, operators, operatorAliases } = config;
19
- let expression = (options === null || options === void 0 ? void 0 : options.allowJSONStringInput) ? (0, helpers_1.parseIfJson)(input) : input;
20
- expression = (0, shorthandSyntax_1.preProcessShorthand)(expression, (_a = config.options) === null || _a === void 0 ? void 0 : _a.fragments, !options.noShorthand);
21
- if (Array.isArray(expression)) {
22
- expression = yield (0, _operatorUtils_1.evaluateArray)(expression, config);
23
- }
24
- const isOperator = (0, helpers_1.isOperatorNode)(expression);
25
- const isFragment = (0, helpers_1.isFragmentNode)(expression);
26
- if (options.evaluateFullObject && !isOperator && !isFragment)
27
- return (0, helpers_1.replaceAliasNodeValues)(yield (0, helpers_1.evaluateObject)(expression, config), config);
28
- if (!isOperator && !isFragment) {
29
- if (options.supportDeprecatedValueNodes && (0, helpers_1.isObject)(expression) && 'value' in expression)
30
- return expression.value;
31
- return (0, helpers_1.replaceAliasNodeValues)(expression, config);
32
- }
33
- const { fallback } = expression;
34
- const returnErrorAsString = (_b = options === null || options === void 0 ? void 0 : options.returnErrorAsString) !== null && _b !== void 0 ? _b : false;
35
- if (isFragment) {
36
- const [fragment, parameters] = (yield (0, _operatorUtils_1.evaluateArray)([expression.fragment, expression.parameters], config));
37
- const fragmentReplacement = (0, shorthandSyntax_1.preProcessShorthand)((_c = options === null || options === void 0 ? void 0 : options.fragments) === null || _c === void 0 ? void 0 : _c[fragment], options.fragments, !options.noShorthand);
38
- if (fragmentReplacement === undefined)
39
- return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Fragment not defined: ${fragment}`, returnErrorAsString);
40
- if (!(0, helpers_1.isOperatorNode)(fragmentReplacement))
41
- return (0, helpers_1.replaceAliasNodeValues)(fragmentReplacement, config);
42
- expression = Object.assign(Object.assign(Object.assign({}, expression), fragmentReplacement), parameters);
43
- delete expression.fragment;
44
- }
45
- try {
46
- const operator = (0, helpers_1.getOperatorName)(expression.operator, operatorAliases);
47
- if (!operator)
48
- return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Invalid operator: ${expression.operator}`, returnErrorAsString);
49
- if (!config.operators[operator])
50
- return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Excluded operator: ${expression.operator}`, returnErrorAsString);
51
- const { propertyAliases, evaluate, parseChildren } = operators[operator];
52
- expression = (0, helpers_1.mapPropertyAliases)(propertyAliases, expression);
53
- const newAliasNodes = yield (0, helpers_1.evaluateNodeAliases)(expression, config);
54
- if (!isFragment)
55
- Object.entries(newAliasNodes).forEach(([alias, result]) => (config.resolvedAliasNodes[alias] = result));
56
- const childConfig = isFragment
57
- ? Object.assign(Object.assign({}, config), { resolvedAliasNodes: Object.assign(Object.assign({}, config.resolvedAliasNodes), newAliasNodes) }) : config;
58
- if ('children' in expression) {
59
- if (!Array.isArray(expression.children))
60
- expression.children = yield (0, exports.evaluatorFunction)(expression.children, childConfig);
61
- if (!Array.isArray(expression.children))
62
- return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Operator: ${operator}\n- Property "children" is not of type: array`, returnErrorAsString);
63
- expression = yield parseChildren(expression, childConfig);
64
- delete expression.children;
65
- }
66
- let result;
67
- try {
68
- result = yield evaluate(expression, childConfig);
69
- }
70
- catch (err) {
71
- return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(expression.fallback, config), `Operator: ${operator}\n${(0, helpers_1.errorMessage)(err)}`, returnErrorAsString);
72
- }
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;
74
- if (!outputType)
75
- return result;
76
- const evaluatedOutputType = (yield (0, exports.evaluatorFunction)(outputType, config));
77
- if (!(evaluatedOutputType in helpers_1.convertOutputMethods))
78
- return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Operator: ${operator}\n- Invalid output type: ${evaluatedOutputType}`, returnErrorAsString);
79
- else {
80
- return helpers_1.convertOutputMethods[evaluatedOutputType](result);
81
- }
82
- }
83
- catch (err) {
84
- return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), (0, helpers_1.errorMessage)(err), returnErrorAsString);
85
- }
86
- });
87
- exports.evaluatorFunction = evaluatorFunction;
@@ -1,23 +0,0 @@
1
- import { OutputType, EvaluatorNode, EvaluatorOutput, FigTreeOptions, FigTreeConfig, OperatorReference, OperatorAliases, Operator, FragmentNode, OperatorNode } from './types';
2
- export declare const parseIfJson: (input: EvaluatorNode) => any;
3
- export declare const isOperatorNode: (input: EvaluatorNode) => boolean;
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;
7
- export declare const truncateString: (string: string, length?: number) => string;
8
- export declare const fallbackOrError: (fallback: EvaluatorOutput, errorMessage: string, returnErrorAsString?: boolean) => string | number | boolean | object | null;
9
- export declare const mapPropertyAliases: (propertyAliases: {
10
- [key: string]: string;
11
- }, expression: OperatorNode) => OperatorNode;
12
- export declare const isAliasString: (value: string) => boolean;
13
- export declare const evaluateNodeAliases: (expression: OperatorNode, config: FigTreeConfig) => Promise<{
14
- [x: string]: EvaluatorOutput;
15
- }>;
16
- export declare const replaceAliasNodeValues: (value: EvaluatorOutput, { resolvedAliasNodes }: FigTreeConfig) => EvaluatorOutput;
17
- export declare const mergeOptions: (origOptions: FigTreeOptions, newOptions: FigTreeOptions) => FigTreeOptions;
18
- export declare const convertOutputMethods: {
19
- [key in OutputType]: (value: EvaluatorOutput) => EvaluatorOutput | EvaluatorOutput[];
20
- };
21
- export declare const errorMessage: (err: unknown) => string;
22
- export declare const isObject: (input: unknown) => input is object;
23
- export declare const evaluateObject: (input: EvaluatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
package/build/helpers.js DELETED
@@ -1,137 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
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
- const change_case_1 = require("change-case");
14
- const evaluate_1 = require("./evaluate");
15
- const _operatorUtils_1 = require("./operators/_operatorUtils");
16
- const parseIfJson = (input) => {
17
- if (typeof input !== 'string')
18
- return input;
19
- try {
20
- const parsedInput = JSON.parse(input);
21
- return (0, exports.isOperatorNode)(parsedInput) ? parsedInput : input;
22
- }
23
- catch (err) {
24
- return input;
25
- }
26
- };
27
- exports.parseIfJson = parseIfJson;
28
- const isOperatorNode = (input) => input instanceof Object && 'operator' in input;
29
- exports.isOperatorNode = isOperatorNode;
30
- const isFragmentNode = (input) => input instanceof Object && 'fragment' in input;
31
- exports.isFragmentNode = isFragmentNode;
32
- const standardiseOperatorName = (name) => {
33
- const camelCaseName = (0, change_case_1.camelCase)(name);
34
- return camelCaseName ? camelCaseName : name;
35
- };
36
- const getOperatorName = (operator, operatorAliases) => operatorAliases[standardiseOperatorName(operator)];
37
- exports.getOperatorName = getOperatorName;
38
- const filterOperators = (operators, exclusions, operatorAliases) => {
39
- const filteredOperators = Object.assign({}, operators);
40
- exclusions.forEach((exclusion) => {
41
- const operator = operatorAliases[standardiseOperatorName(exclusion)];
42
- if (!operator)
43
- console.warn(`Invalid operator exclusion: ${exclusion}`);
44
- delete filteredOperators[operatorAliases[standardiseOperatorName(exclusion)]];
45
- });
46
- return filteredOperators;
47
- };
48
- exports.filterOperators = filterOperators;
49
- const truncateString = (string, length = 200) => string.length < length ? string : `${string.slice(0, length - 2).trim()}...`;
50
- exports.truncateString = truncateString;
51
- const fallbackOrError = (fallback, errorMessage, returnErrorAsString = false) => {
52
- if (fallback !== undefined)
53
- return fallback;
54
- if (returnErrorAsString)
55
- return (0, exports.truncateString)(errorMessage);
56
- else
57
- throw new Error((0, exports.truncateString)(errorMessage));
58
- };
59
- exports.fallbackOrError = fallbackOrError;
60
- const mapPropertyAliases = (propertyAliases, expression) => mapObjectKeys(expression, (key) => key in propertyAliases ? propertyAliases[key] : key);
61
- exports.mapPropertyAliases = mapPropertyAliases;
62
- const mapObjectKeys = (inputObj, mapFunction) => {
63
- const keyVals = Object.entries(inputObj);
64
- const mappedKeys = keyVals.map(([key, value]) => [mapFunction(key), value]);
65
- return Object.fromEntries(mappedKeys);
66
- };
67
- const isAliasString = (value) => /^\$.+/.test(value);
68
- exports.isAliasString = isAliasString;
69
- const evaluateNodeAliases = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
70
- const aliasKeys = Object.keys(expression).filter(exports.isAliasString);
71
- if (aliasKeys.length === 0)
72
- return {};
73
- const evaluations = [];
74
- aliasKeys.forEach((alias) => evaluations.push((0, evaluate_1.evaluatorFunction)(expression[alias], config)));
75
- return (0, _operatorUtils_1.zipArraysToObject)(aliasKeys, yield Promise.all(evaluations));
76
- });
77
- exports.evaluateNodeAliases = evaluateNodeAliases;
78
- const replaceAliasNodeValues = (value, { resolvedAliasNodes }) => {
79
- var _a;
80
- if (typeof value !== 'string' || !(0, exports.isAliasString)(value))
81
- return value;
82
- return (_a = resolvedAliasNodes === null || resolvedAliasNodes === void 0 ? void 0 : resolvedAliasNodes[value]) !== null && _a !== void 0 ? _a : value;
83
- };
84
- exports.replaceAliasNodeValues = replaceAliasNodeValues;
85
- const mergeOptions = (origOptions, newOptions) => {
86
- const combinedOptions = Object.assign(Object.assign({}, origOptions), newOptions);
87
- if (origOptions.data || newOptions.data)
88
- combinedOptions.data = Object.assign(Object.assign({}, origOptions.data), newOptions.data);
89
- if (origOptions.functions || newOptions.functions)
90
- combinedOptions.functions = Object.assign(Object.assign({}, origOptions.functions), newOptions.functions);
91
- if (origOptions.fragments || newOptions.fragments)
92
- combinedOptions.fragments = Object.assign(Object.assign({}, origOptions.fragments), newOptions.fragments);
93
- if (origOptions.headers || newOptions.headers)
94
- combinedOptions.headers = Object.assign(Object.assign({}, origOptions.headers), newOptions.headers);
95
- return combinedOptions;
96
- };
97
- exports.mergeOptions = mergeOptions;
98
- exports.convertOutputMethods = {
99
- number: (value) => extractNumber(value),
100
- string: (value) => String(value),
101
- array: (value) => (Array.isArray(value) ? value : [value]),
102
- boolean: (value) => Boolean(value),
103
- bool: (value) => Boolean(value),
104
- };
105
- const errorMessage = (err) => err.message;
106
- exports.errorMessage = errorMessage;
107
- const extractNumber = (input) => {
108
- if (typeof input !== 'string')
109
- return Number.isNaN(Number(input)) ? input : Number(input);
110
- const pattern = new RegExp(/-?\d*\.?\d+/gm);
111
- const numberMatch = input.match(pattern);
112
- if (!numberMatch)
113
- return 0;
114
- return Number(numberMatch[0]);
115
- };
116
- const isObject = (input) => typeof input === 'object' && input !== null && !Array.isArray(input);
117
- exports.isObject = isObject;
118
- const evaluateObject = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
119
- if (!(0, exports.isObject)(input))
120
- return input;
121
- const newObjectEntries = [];
122
- const newAliases = [];
123
- Object.entries(input).forEach(([key, value]) => {
124
- if ((0, exports.isAliasString)(key)) {
125
- newAliases.push(key, (0, evaluate_1.evaluatorFunction)(value, config));
126
- delete input[key];
127
- }
128
- });
129
- const aliasArray = yield Promise.all(newAliases);
130
- config.resolvedAliasNodes = Object.assign(Object.assign({}, config.resolvedAliasNodes), (0, _operatorUtils_1.singleArrayToObject)(aliasArray));
131
- Object.entries(input).forEach(([key, value]) => {
132
- newObjectEntries.push(key, (0, evaluate_1.evaluatorFunction)(value, config));
133
- });
134
- const results = yield Promise.all(newObjectEntries);
135
- return (0, exports.replaceAliasNodeValues)((0, _operatorUtils_1.singleArrayToObject)(results), config);
136
- });
137
- exports.evaluateObject = evaluateObject;
package/build/index.js DELETED
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.evaluateExpression = void 0;
27
- const FigTreeEvaluator_1 = __importStar(require("./FigTreeEvaluator"));
28
- Object.defineProperty(exports, "evaluateExpression", { enumerable: true, get: function () { return FigTreeEvaluator_1.evaluateExpression; } });
29
- exports.default = FigTreeEvaluator_1.default;
@@ -1,4 +0,0 @@
1
- import { OperatorData } from '../../types';
2
- export declare const propertyAliases: Record<string, string>;
3
- declare const operatorData: OperatorData;
4
- export default operatorData;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyAliases = void 0;
4
- const _operatorUtils_1 = require("../_operatorUtils");
5
- const description = 'Logical AND';
6
- const aliases = ['and', '&', '&&'];
7
- const parameters = [
8
- {
9
- name: 'values',
10
- description: 'Returns true if all values are true',
11
- aliases: [],
12
- required: true,
13
- type: 'array',
14
- },
15
- ];
16
- exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
17
- const operatorData = {
18
- description,
19
- aliases,
20
- parameters,
21
- };
22
- exports.default = operatorData;
@@ -1 +0,0 @@
1
- export { AND } from './operator';
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AND = void 0;
4
- var operator_1 = require("./operator");
5
- Object.defineProperty(exports, "AND", { enumerable: true, get: function () { return operator_1.AND; } });
@@ -1,3 +0,0 @@
1
- import { OperatorObject, ParseChildrenMethod } from '../../types';
2
- export declare const parseChildren: ParseChildrenMethod;
3
- export declare const AND: OperatorObject;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.AND = exports.parseChildren = void 0;
36
- const _operatorUtils_1 = require("../_operatorUtils");
37
- const data_1 = __importStar(require("./data"));
38
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
39
- const values = (yield (0, _operatorUtils_1.evaluateArray)(expression.values, config));
40
- config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { values }));
41
- return values.reduce((acc, val) => acc && !!val, true);
42
- });
43
- const parseChildren = (expression) => {
44
- const values = expression.children;
45
- return Object.assign(Object.assign({}, expression), { values });
46
- };
47
- exports.parseChildren = parseChildren;
48
- exports.AND = {
49
- propertyAliases: data_1.propertyAliases,
50
- operatorData: data_1.default,
51
- evaluate,
52
- parseChildren: exports.parseChildren,
53
- };
@@ -1,4 +0,0 @@
1
- import { OperatorData } from '../../types';
2
- export declare const propertyAliases: Record<string, string>;
3
- declare const operatorData: OperatorData;
4
- export default operatorData;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyAliases = void 0;
4
- const _operatorUtils_1 = require("../_operatorUtils");
5
- const aliases = ['buildObject', 'build', 'object'];
6
- const description = 'Construct an object using objects defining keys and values';
7
- const parameters = [
8
- {
9
- name: 'properties',
10
- description: 'An array of objects, each with a "key" property and a "value" property',
11
- aliases: ['values', 'keyValPairs', 'keyValuePairs'],
12
- required: true,
13
- type: 'array',
14
- },
15
- ];
16
- exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
17
- const operatorData = {
18
- description,
19
- aliases,
20
- parameters,
21
- };
22
- exports.default = operatorData;
@@ -1 +0,0 @@
1
- export * from './operator';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./operator"), exports);
@@ -1,2 +0,0 @@
1
- import { OperatorObject } from '../../types';
2
- export declare const BUILD_OBJECT: OperatorObject;