fig-tree-evaluator 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/build/evaluate.js +39 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1427,6 +1427,7 @@ Please open an issue: https://github.com/CarlosNZ/fig-tree-evaluator/issues
|
|
|
1427
1427
|
|
|
1428
1428
|
## Changelog
|
|
1429
1429
|
|
|
1430
|
+
- **v2.3.1**: Bug fix: alias nodes not working with `evaluateFullObject` (#72)
|
|
1430
1431
|
- **v2.3.0**: Implement [caching/memoization](#caching-memoization) (#68)
|
|
1431
1432
|
- **v2.2.3**: Change option `objects` name to `data` (but keep backward compatibility) (#66)
|
|
1432
1433
|
- **v2.2.2**: Option to evaluate whole object if operator nodes are deep within it (#64)
|
package/build/evaluate.js
CHANGED
|
@@ -51,99 +51,100 @@ exports.evaluatorFunction = void 0;
|
|
|
51
51
|
var _operatorUtils_1 = require("./operators/_operatorUtils");
|
|
52
52
|
var helpers_1 = require("./helpers");
|
|
53
53
|
var evaluatorFunction = function (input, config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
-
var options, operators, operatorAliases, expression, fallback, returnErrorAsString, operator,
|
|
55
|
-
var
|
|
56
|
-
return __generator(this, function (
|
|
57
|
-
switch (
|
|
54
|
+
var options, operators, operatorAliases, expression, _a, fallback, returnErrorAsString, operator, _b, _c, requiredProperties, propertyAliases, evaluate, parseChildren, _d, _e, validationError, _f, _g, _h, result, err_1, _j, outputType, evaluatedOutputType, _k, err_2, _l;
|
|
55
|
+
var _m, _o;
|
|
56
|
+
return __generator(this, function (_p) {
|
|
57
|
+
switch (_p.label) {
|
|
58
58
|
case 0:
|
|
59
59
|
options = config.options, operators = config.operators, operatorAliases = config.operatorAliases;
|
|
60
60
|
expression = (options === null || options === void 0 ? void 0 : options.allowJSONStringInput) ? (0, helpers_1.parseIfJson)(input) : input;
|
|
61
61
|
if (!Array.isArray(expression)) return [3, 2];
|
|
62
62
|
return [4, (0, _operatorUtils_1.evaluateArray)(expression, config)];
|
|
63
63
|
case 1:
|
|
64
|
-
expression =
|
|
65
|
-
|
|
64
|
+
expression = _p.sent();
|
|
65
|
+
_p.label = 2;
|
|
66
66
|
case 2:
|
|
67
67
|
if (!(options.evaluateFullObject && !(0, helpers_1.isOperatorNode)(expression))) return [3, 4];
|
|
68
|
+
_a = helpers_1.replaceAliasNodeValues;
|
|
68
69
|
return [4, (0, helpers_1.evaluateObject)(expression, config)];
|
|
69
|
-
case 3: return [2,
|
|
70
|
+
case 3: return [2, _a.apply(void 0, [_p.sent(), config])];
|
|
70
71
|
case 4:
|
|
71
72
|
if (!(0, helpers_1.isOperatorNode)(expression))
|
|
72
73
|
return [2, (0, helpers_1.replaceAliasNodeValues)(expression, config)];
|
|
73
74
|
fallback = expression.fallback;
|
|
74
|
-
returnErrorAsString = (
|
|
75
|
-
|
|
75
|
+
returnErrorAsString = (_m = options === null || options === void 0 ? void 0 : options.returnErrorAsString) !== null && _m !== void 0 ? _m : false;
|
|
76
|
+
_p.label = 5;
|
|
76
77
|
case 5:
|
|
77
|
-
|
|
78
|
+
_p.trys.push([5, 26, , 28]);
|
|
78
79
|
operator = (0, helpers_1.getOperatorName)(expression.operator, operatorAliases);
|
|
79
80
|
if (!!operator) return [3, 7];
|
|
80
|
-
|
|
81
|
+
_b = helpers_1.fallbackOrError;
|
|
81
82
|
return [4, (0, exports.evaluatorFunction)(fallback, config)];
|
|
82
|
-
case 6: return [2,
|
|
83
|
+
case 6: return [2, _b.apply(void 0, [_p.sent(), "Invalid operator: ".concat(expression.operator), returnErrorAsString])];
|
|
83
84
|
case 7:
|
|
84
|
-
|
|
85
|
+
_c = operators[operator], requiredProperties = _c.requiredProperties, propertyAliases = _c.propertyAliases, evaluate = _c.evaluate, parseChildren = _c.parseChildren;
|
|
85
86
|
expression = (0, helpers_1.mapPropertyAliases)(propertyAliases, expression);
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
_d = config;
|
|
88
|
+
_e = [__assign({}, config.resolvedAliasNodes)];
|
|
88
89
|
return [4, (0, helpers_1.evaluateNodeAliases)(expression, config)];
|
|
89
90
|
case 8:
|
|
90
|
-
|
|
91
|
+
_d.resolvedAliasNodes = __assign.apply(void 0, _e.concat([(_p.sent())]));
|
|
91
92
|
validationError = (0, helpers_1.checkRequiredNodes)(requiredProperties, expression);
|
|
92
93
|
if (!validationError) return [3, 10];
|
|
93
|
-
|
|
94
|
+
_f = helpers_1.fallbackOrError;
|
|
94
95
|
return [4, (0, exports.evaluatorFunction)(fallback, config)];
|
|
95
|
-
case 9: return [2,
|
|
96
|
+
case 9: return [2, _f.apply(void 0, [_p.sent(), "Operator: ".concat(operator, "\n- ").concat(validationError), returnErrorAsString])];
|
|
96
97
|
case 10:
|
|
97
98
|
if (!('children' in expression)) return [3, 16];
|
|
98
99
|
if (!!Array.isArray(expression.children)) return [3, 12];
|
|
99
|
-
|
|
100
|
+
_g = expression;
|
|
100
101
|
return [4, (0, exports.evaluatorFunction)(expression.children, config)];
|
|
101
102
|
case 11:
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
_g.children = _p.sent();
|
|
104
|
+
_p.label = 12;
|
|
104
105
|
case 12:
|
|
105
106
|
if (!!Array.isArray(expression.children)) return [3, 14];
|
|
106
|
-
|
|
107
|
+
_h = helpers_1.fallbackOrError;
|
|
107
108
|
return [4, (0, exports.evaluatorFunction)(fallback, config)];
|
|
108
|
-
case 13: return [2,
|
|
109
|
+
case 13: return [2, _h.apply(void 0, [_p.sent(), "Operator: ".concat(operator, "\n- Property \"children\" is not of type: array"), returnErrorAsString])];
|
|
109
110
|
case 14: return [4, parseChildren(expression, config)];
|
|
110
111
|
case 15:
|
|
111
|
-
expression =
|
|
112
|
-
|
|
112
|
+
expression = _p.sent();
|
|
113
|
+
_p.label = 16;
|
|
113
114
|
case 16:
|
|
114
115
|
result = void 0;
|
|
115
|
-
|
|
116
|
+
_p.label = 17;
|
|
116
117
|
case 17:
|
|
117
|
-
|
|
118
|
+
_p.trys.push([17, 19, , 21]);
|
|
118
119
|
return [4, evaluate(expression, config)];
|
|
119
120
|
case 18:
|
|
120
|
-
result =
|
|
121
|
+
result = _p.sent();
|
|
121
122
|
return [3, 21];
|
|
122
123
|
case 19:
|
|
123
|
-
err_1 =
|
|
124
|
-
|
|
124
|
+
err_1 = _p.sent();
|
|
125
|
+
_j = helpers_1.fallbackOrError;
|
|
125
126
|
return [4, (0, exports.evaluatorFunction)(fallback, config)];
|
|
126
127
|
case 20:
|
|
127
|
-
result =
|
|
128
|
+
result = _j.apply(void 0, [_p.sent(), "Operator: ".concat(operator, "\n").concat((0, helpers_1.errorMessage)(err_1)), returnErrorAsString]);
|
|
128
129
|
return [3, 21];
|
|
129
130
|
case 21:
|
|
130
|
-
outputType = (
|
|
131
|
+
outputType = (_o = expression === null || expression === void 0 ? void 0 : expression.outputType) !== null && _o !== void 0 ? _o : expression === null || expression === void 0 ? void 0 : expression.type;
|
|
131
132
|
if (!outputType)
|
|
132
133
|
return [2, result];
|
|
133
134
|
return [4, (0, exports.evaluatorFunction)(outputType, config)];
|
|
134
135
|
case 22:
|
|
135
|
-
evaluatedOutputType = (
|
|
136
|
+
evaluatedOutputType = (_p.sent());
|
|
136
137
|
if (!!(evaluatedOutputType in helpers_1.convertOutputMethods)) return [3, 24];
|
|
137
|
-
|
|
138
|
+
_k = helpers_1.fallbackOrError;
|
|
138
139
|
return [4, (0, exports.evaluatorFunction)(fallback, config)];
|
|
139
|
-
case 23: return [2,
|
|
140
|
+
case 23: return [2, _k.apply(void 0, [_p.sent(), "Operator: ".concat(operator, "\n- Invalid output type: ").concat(evaluatedOutputType), returnErrorAsString])];
|
|
140
141
|
case 24: return [2, helpers_1.convertOutputMethods[evaluatedOutputType](result)];
|
|
141
142
|
case 25: return [3, 28];
|
|
142
143
|
case 26:
|
|
143
|
-
err_2 =
|
|
144
|
-
|
|
144
|
+
err_2 = _p.sent();
|
|
145
|
+
_l = helpers_1.fallbackOrError;
|
|
145
146
|
return [4, (0, exports.evaluatorFunction)(fallback, config)];
|
|
146
|
-
case 27: return [2,
|
|
147
|
+
case 27: return [2, _l.apply(void 0, [_p.sent(), (0, helpers_1.errorMessage)(err_2),
|
|
147
148
|
returnErrorAsString])];
|
|
148
149
|
case 28: return [2];
|
|
149
150
|
}
|