fig-tree-evaluator 2.2.1 → 2.2.2

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 (40) hide show
  1. package/README.md +14 -5
  2. package/build/evaluate.js +138 -50
  3. package/build/helpers.d.ts +1 -0
  4. package/build/helpers.js +131 -45
  5. package/build/index.js +82 -28
  6. package/build/operators/_operatorUtils.js +109 -48
  7. package/build/operators/buildObject.js +84 -26
  8. package/build/operators/conditional.js +70 -18
  9. package/build/operators/count.js +48 -14
  10. package/build/operators/customFunctions.js +76 -21
  11. package/build/operators/divide.js +63 -26
  12. package/build/operators/equal.js +57 -23
  13. package/build/operators/getRequest.js +85 -31
  14. package/build/operators/graphQL.js +90 -40
  15. package/build/operators/greaterThan.js +54 -20
  16. package/build/operators/lessThan.js +54 -20
  17. package/build/operators/logicalAnd.js +61 -16
  18. package/build/operators/logicalOr.js +48 -14
  19. package/build/operators/match.js +101 -38
  20. package/build/operators/multiply.js +48 -14
  21. package/build/operators/notEqual.js +57 -23
  22. package/build/operators/objectProperties.js +66 -21
  23. package/build/operators/passThru.js +58 -15
  24. package/build/operators/pgSQL.js +118 -50
  25. package/build/operators/plus.js +70 -24
  26. package/build/operators/postRequest.js +70 -23
  27. package/build/operators/regex.js +70 -24
  28. package/build/operators/split.js +74 -29
  29. package/build/operators/stringSubstitution.js +79 -25
  30. package/build/operators/subtract.js +50 -16
  31. package/build/typeCheck.js +27 -22
  32. package/build/types.d.ts +1 -0
  33. package/package.json +2 -2
  34. package/build/.DS_Store +0 -0
  35. package/build/FigTreeEvaluator.d.ts +0 -13
  36. package/build/FigTreeEvaluator.js +0 -75
  37. package/build/evaluator.d.ts +0 -13
  38. package/build/evaluator.js +0 -75
  39. package/build/operators/objectFunctions.d.ts +0 -9
  40. package/build/operators/objectFunctions.js +0 -38
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,53 +19,88 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
20
  });
10
21
  };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
11
49
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
51
  };
14
52
  Object.defineProperty(exports, "__esModule", { value: true });
15
53
  exports.axiosRequest = exports.joinUrlParts = exports.isFullUrl = exports.extractAndSimplify = exports.simplifyObject = exports.singleArrayToObject = exports.zipArraysToObject = exports.evaluateArray = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const extract_1 = __importDefault(require("object-property-extractor/build/extract"));
18
- const evaluate_1 = require("../evaluate");
19
- const typeCheck_1 = require("../typeCheck");
20
- const evaluateArray = (nodes, params) => __awaiter(void 0, void 0, void 0, function* () {
21
- if (!Array.isArray(nodes))
22
- return (yield (0, evaluate_1.evaluatorFunction)(nodes, params));
23
- return yield Promise.all(nodes.map((node) => (0, evaluate_1.evaluatorFunction)(node, params)));
24
- });
54
+ var axios_1 = __importDefault(require("axios"));
55
+ var extract_1 = __importDefault(require("object-property-extractor/build/extract"));
56
+ var evaluate_1 = require("../evaluate");
57
+ var typeCheck_1 = require("../typeCheck");
58
+ var evaluateArray = function (nodes, params) { return __awaiter(void 0, void 0, void 0, function () {
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ if (!!Array.isArray(nodes)) return [3, 2];
63
+ return [4, (0, evaluate_1.evaluatorFunction)(nodes, params)];
64
+ case 1: return [2, (_a.sent())];
65
+ case 2: return [4, Promise.all(nodes.map(function (node) { return (0, evaluate_1.evaluatorFunction)(node, params); }))];
66
+ case 3: return [2, _a.sent()];
67
+ }
68
+ });
69
+ }); };
25
70
  exports.evaluateArray = evaluateArray;
26
- const zipArraysToObject = (keys, values) => {
27
- const pairs = keys.map((key, index) => [key, values[index]]);
71
+ var zipArraysToObject = function (keys, values) {
72
+ var pairs = keys.map(function (key, index) { return [key, values[index]]; });
28
73
  return Object.fromEntries(pairs);
29
74
  };
30
75
  exports.zipArraysToObject = zipArraysToObject;
31
- const singleArrayToObject = (elements) => {
76
+ var singleArrayToObject = function (elements) {
32
77
  if (elements.length % 2 !== 0)
33
78
  throw new Error('Even number of children required to make key/value pairs');
34
- const keys = elements.filter((_, index) => index % 2 === 0);
35
- const result = (0, typeCheck_1.typeCheck)(...keys.map((key) => ({
79
+ var keys = elements.filter(function (_, index) { return index % 2 === 0; });
80
+ var result = typeCheck_1.typeCheck.apply(void 0, keys.map(function (key) { return ({
36
81
  value: key,
37
82
  expectedType: ['string', 'number', 'boolean'],
38
- })));
83
+ }); }));
39
84
  if (result !== true)
40
85
  throw new Error(result);
41
- const values = elements.filter((_, index) => index % 2 === 1);
42
- const output = {};
43
- keys.forEach((key, index) => {
86
+ var values = elements.filter(function (_, index) { return index % 2 === 1; });
87
+ var output = {};
88
+ keys.forEach(function (key, index) {
44
89
  output[key] = values[index];
45
90
  });
46
91
  return output;
47
92
  };
48
93
  exports.singleArrayToObject = singleArrayToObject;
49
- const simplifyObject = (item) => {
94
+ var simplifyObject = function (item) {
50
95
  return item instanceof Object && Object.keys(item).length === 1 ? Object.values(item)[0] : item;
51
96
  };
52
97
  exports.simplifyObject = simplifyObject;
53
- const extractAndSimplify = (data, returnProperty, fallback = undefined) => {
98
+ var extractAndSimplify = function (data, returnProperty, fallback) {
99
+ if (fallback === void 0) { fallback = undefined; }
54
100
  try {
55
- const selectedProperty = returnProperty ? (0, extract_1.default)(data, returnProperty, fallback) : data;
101
+ var selectedProperty = returnProperty ? (0, extract_1.default)(data, returnProperty, fallback) : data;
56
102
  if (Array.isArray(selectedProperty))
57
- return selectedProperty.map((item) => (0, exports.simplifyObject)(item));
103
+ return selectedProperty.map(function (item) { return (0, exports.simplifyObject)(item); });
58
104
  if (returnProperty) {
59
105
  if (selectedProperty === null)
60
106
  return null;
@@ -67,36 +113,51 @@ const extractAndSimplify = (data, returnProperty, fallback = undefined) => {
67
113
  }
68
114
  };
69
115
  exports.extractAndSimplify = extractAndSimplify;
70
- const isFullUrl = (url) => /^https?:\/\/.+/.test(url);
116
+ var isFullUrl = function (url) { return /^https?:\/\/.+/.test(url); };
71
117
  exports.isFullUrl = isFullUrl;
72
- const joinUrlParts = (...urls) => {
73
- return urls.reduce((acc, curr, index) => {
74
- const startSliceIndex = curr[0] === '/' ? 1 : 0;
75
- const endSliceIndex = curr.slice(-1) === '/' ? -1 : undefined;
76
- const newPart = curr.slice(startSliceIndex, endSliceIndex);
118
+ var joinUrlParts = function () {
119
+ var urls = [];
120
+ for (var _i = 0; _i < arguments.length; _i++) {
121
+ urls[_i] = arguments[_i];
122
+ }
123
+ return urls.reduce(function (acc, curr, index) {
124
+ var startSliceIndex = curr[0] === '/' ? 1 : 0;
125
+ var endSliceIndex = curr.slice(-1) === '/' ? -1 : undefined;
126
+ var newPart = curr.slice(startSliceIndex, endSliceIndex);
77
127
  return acc + (index === 0 ? '' : '/') + newPart;
78
128
  }, '');
79
129
  };
80
130
  exports.joinUrlParts = joinUrlParts;
81
- const axiosRequest = ({ url, params = {}, data = {}, headers = {}, method = 'get', }) => __awaiter(void 0, void 0, void 0, function* () {
82
- var _a;
83
- try {
84
- const response = yield (0, axios_1.default)({
85
- method,
86
- url,
87
- headers: Object.assign({ 'Content-Type': 'application/json', Accept: 'application/json' }, headers),
88
- params,
89
- data,
131
+ var axiosRequest = function (_a) {
132
+ var url = _a.url, _b = _a.params, params = _b === void 0 ? {} : _b, _c = _a.data, data = _c === void 0 ? {} : _c, _d = _a.headers, headers = _d === void 0 ? {} : _d, _e = _a.method, method = _e === void 0 ? 'get' : _e;
133
+ return __awaiter(void 0, void 0, void 0, function () {
134
+ var response, err_1;
135
+ var _f;
136
+ return __generator(this, function (_g) {
137
+ switch (_g.label) {
138
+ case 0:
139
+ _g.trys.push([0, 2, , 3]);
140
+ return [4, (0, axios_1.default)({
141
+ method: method,
142
+ url: url,
143
+ headers: __assign({ 'Content-Type': 'application/json', Accept: 'application/json' }, headers),
144
+ params: params,
145
+ data: data,
146
+ })];
147
+ case 1:
148
+ response = _g.sent();
149
+ return [2, response.data];
150
+ case 2:
151
+ err_1 = _g.sent();
152
+ if (axios_1.default.isAxiosError(err_1)) {
153
+ if (!(err_1 === null || err_1 === void 0 ? void 0 : err_1.response))
154
+ throw new Error('Network Error');
155
+ console.log((_f = err_1.response) === null || _f === void 0 ? void 0 : _f.data);
156
+ }
157
+ throw err_1;
158
+ case 3: return [2];
159
+ }
90
160
  });
91
- return response.data;
92
- }
93
- catch (err) {
94
- if (axios_1.default.isAxiosError(err)) {
95
- if (!(err === null || err === void 0 ? void 0 : err.response))
96
- throw new Error('Network Error');
97
- console.log((_a = err.response) === null || _a === void 0 ? void 0 : _a.data);
98
- }
99
- throw err;
100
- }
101
- });
161
+ });
162
+ };
102
163
  exports.axiosRequest = axiosRequest;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,41 +19,88 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
20
  });
10
21
  };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
11
49
  Object.defineProperty(exports, "__esModule", { value: true });
12
50
  exports.BUILD_OBJECT = void 0;
13
- const _operatorUtils_1 = require("./_operatorUtils");
14
- const requiredProperties = ['properties'];
15
- const operatorAliases = ['buildObject', 'build', 'object'];
16
- const propertyAliases = {
51
+ var _operatorUtils_1 = require("./_operatorUtils");
52
+ var requiredProperties = ['properties'];
53
+ var operatorAliases = ['buildObject', 'build', 'object'];
54
+ var propertyAliases = {
17
55
  values: 'properties',
18
56
  keyValPairs: 'properties',
19
57
  keyValuePairs: 'properties',
20
58
  };
21
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
22
- const evaluatePair = (nodes) => __awaiter(void 0, void 0, void 0, function* () {
23
- const [key, value] = (yield (0, _operatorUtils_1.evaluateArray)(nodes, config));
24
- config.typeChecker({ name: 'key', value: key, expectedType: ['string', 'number', 'boolean'] });
25
- return [key, value];
59
+ var evaluate = function (expression, config) { return __awaiter(void 0, void 0, void 0, function () {
60
+ var evaluatePair, evaluated, _a, _b;
61
+ return __generator(this, function (_c) {
62
+ switch (_c.label) {
63
+ case 0:
64
+ evaluatePair = function (nodes) { return __awaiter(void 0, void 0, void 0, function () {
65
+ var _a, key, value;
66
+ return __generator(this, function (_b) {
67
+ switch (_b.label) {
68
+ case 0: return [4, (0, _operatorUtils_1.evaluateArray)(nodes, config)];
69
+ case 1:
70
+ _a = (_b.sent()), key = _a[0], value = _a[1];
71
+ config.typeChecker({ name: 'key', value: key, expectedType: ['string', 'number', 'boolean'] });
72
+ return [2, [key, value]];
73
+ }
74
+ });
75
+ }); };
76
+ config.typeChecker({ name: 'properties', value: expression.properties, expectedType: 'array' });
77
+ evaluated = expression.properties
78
+ .filter(function (element) {
79
+ return element instanceof Object && 'key' in element && 'value' in element;
80
+ })
81
+ .map(function (_a) {
82
+ var key = _a.key, value = _a.value;
83
+ return evaluatePair([key, value]);
84
+ });
85
+ _b = (_a = Object).fromEntries;
86
+ return [4, Promise.all(evaluated)];
87
+ case 1: return [2, _b.apply(_a, [_c.sent()])];
88
+ }
26
89
  });
27
- config.typeChecker({ name: 'properties', value: expression.properties, expectedType: 'array' });
28
- const evaluated = expression.properties
29
- .filter((element) => element instanceof Object && 'key' in element && 'value' in element)
30
- .map(({ key, value }) => evaluatePair([key, value]));
31
- return Object.fromEntries(yield Promise.all(evaluated));
32
- });
33
- const parseChildren = (expression) => {
34
- const elements = expression.children;
90
+ }); };
91
+ var parseChildren = function (expression) {
92
+ var elements = expression.children;
35
93
  if (elements.length % 2 !== 0)
36
94
  throw new Error('Even number of children required to make key/value pairs');
37
- const keys = elements.filter((_, index) => index % 2 === 0);
38
- const values = elements.filter((_, index) => index % 2 === 1);
39
- const properties = keys.map((key, index) => ({ key, value: values[index] }));
40
- return Object.assign(Object.assign({}, expression), { properties });
95
+ var keys = elements.filter(function (_, index) { return index % 2 === 0; });
96
+ var values = elements.filter(function (_, index) { return index % 2 === 1; });
97
+ var properties = keys.map(function (key, index) { return ({ key: key, value: values[index] }); });
98
+ return __assign(__assign({}, expression), { properties: properties });
41
99
  };
42
100
  exports.BUILD_OBJECT = {
43
- requiredProperties,
44
- operatorAliases,
45
- propertyAliases,
46
- evaluate,
47
- parseChildren,
101
+ requiredProperties: requiredProperties,
102
+ operatorAliases: operatorAliases,
103
+ propertyAliases: propertyAliases,
104
+ evaluate: evaluate,
105
+ parseChildren: parseChildren,
48
106
  };
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,26 +19,67 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
20
  });
10
21
  };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
11
49
  Object.defineProperty(exports, "__esModule", { value: true });
12
50
  exports.CONDITIONAL = void 0;
13
- const evaluate_1 = require("../evaluate");
14
- const requiredProperties = ['condition', 'valueIfTrue', 'valueIfFalse'];
15
- const operatorAliases = ['?', 'conditional', 'ifThen'];
16
- const propertyAliases = { ifTrue: 'valueIfTrue', ifFalse: 'valueIfFalse', ifNot: 'valueIfFalse' };
17
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
18
- const condition = yield (0, evaluate_1.evaluatorFunction)(expression.condition, config);
19
- return !!condition
20
- ? yield (0, evaluate_1.evaluatorFunction)(expression.valueIfTrue, config)
21
- : yield (0, evaluate_1.evaluatorFunction)(expression.valueIfFalse, config);
22
- });
23
- const parseChildren = (expression) => {
24
- const [condition, valueIfTrue, valueIfFalse] = expression.children;
25
- return Object.assign(Object.assign({}, expression), { condition, valueIfTrue, valueIfFalse });
51
+ var evaluate_1 = require("../evaluate");
52
+ var requiredProperties = ['condition', 'valueIfTrue', 'valueIfFalse'];
53
+ var operatorAliases = ['?', 'conditional', 'ifThen'];
54
+ var propertyAliases = { ifTrue: 'valueIfTrue', ifFalse: 'valueIfFalse', ifNot: 'valueIfFalse' };
55
+ var evaluate = function (expression, config) { return __awaiter(void 0, void 0, void 0, function () {
56
+ var condition, _a;
57
+ return __generator(this, function (_b) {
58
+ switch (_b.label) {
59
+ case 0: return [4, (0, evaluate_1.evaluatorFunction)(expression.condition, config)];
60
+ case 1:
61
+ condition = _b.sent();
62
+ if (!!!condition) return [3, 3];
63
+ return [4, (0, evaluate_1.evaluatorFunction)(expression.valueIfTrue, config)];
64
+ case 2:
65
+ _a = _b.sent();
66
+ return [3, 5];
67
+ case 3: return [4, (0, evaluate_1.evaluatorFunction)(expression.valueIfFalse, config)];
68
+ case 4:
69
+ _a = _b.sent();
70
+ _b.label = 5;
71
+ case 5: return [2, _a];
72
+ }
73
+ });
74
+ }); };
75
+ var parseChildren = function (expression) {
76
+ var _a = expression.children, condition = _a[0], valueIfTrue = _a[1], valueIfFalse = _a[2];
77
+ return __assign(__assign({}, expression), { condition: condition, valueIfTrue: valueIfTrue, valueIfFalse: valueIfFalse });
26
78
  };
27
79
  exports.CONDITIONAL = {
28
- requiredProperties,
29
- operatorAliases,
30
- propertyAliases,
31
- evaluate,
32
- parseChildren,
80
+ requiredProperties: requiredProperties,
81
+ operatorAliases: operatorAliases,
82
+ propertyAliases: propertyAliases,
83
+ evaluate: evaluate,
84
+ parseChildren: parseChildren,
33
85
  };
@@ -8,22 +8,56 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
11
38
  Object.defineProperty(exports, "__esModule", { value: true });
12
39
  exports.COUNT = void 0;
13
- const logicalAnd_1 = require("./logicalAnd");
14
- const _operatorUtils_1 = require("./_operatorUtils");
15
- const requiredProperties = ['values'];
16
- const operatorAliases = ['count', 'length'];
17
- const propertyAliases = {};
18
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
19
- const values = yield (0, _operatorUtils_1.evaluateArray)(expression.values, config);
20
- config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
21
- return values.length;
22
- });
40
+ var logicalAnd_1 = require("./logicalAnd");
41
+ var _operatorUtils_1 = require("./_operatorUtils");
42
+ var requiredProperties = ['values'];
43
+ var operatorAliases = ['count', 'length'];
44
+ var propertyAliases = {};
45
+ var evaluate = function (expression, config) { return __awaiter(void 0, void 0, void 0, function () {
46
+ var values;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0: return [4, (0, _operatorUtils_1.evaluateArray)(expression.values, config)];
50
+ case 1:
51
+ values = _a.sent();
52
+ config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
53
+ return [2, values.length];
54
+ }
55
+ });
56
+ }); };
23
57
  exports.COUNT = {
24
- requiredProperties,
25
- operatorAliases,
26
- propertyAliases,
27
- evaluate,
58
+ requiredProperties: requiredProperties,
59
+ operatorAliases: operatorAliases,
60
+ propertyAliases: propertyAliases,
61
+ evaluate: evaluate,
28
62
  parseChildren: logicalAnd_1.parseChildren,
29
63
  };
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,15 +19,51 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
20
  });
10
21
  };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
11
58
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
60
  };
14
61
  Object.defineProperty(exports, "__esModule", { value: true });
15
62
  exports.CUSTOM_FUNCTIONS = void 0;
16
- const object_property_extractor_1 = __importDefault(require("object-property-extractor"));
17
- const _operatorUtils_1 = require("./_operatorUtils");
18
- const requiredProperties = ['functionPath'];
19
- const operatorAliases = [
63
+ var object_property_extractor_1 = __importDefault(require("object-property-extractor"));
64
+ var _operatorUtils_1 = require("./_operatorUtils");
65
+ var requiredProperties = ['functionPath'];
66
+ var operatorAliases = [
20
67
  'customFunctions',
21
68
  'customFunction',
22
69
  'objectFunctions',
@@ -24,7 +71,7 @@ const operatorAliases = [
24
71
  'functions',
25
72
  'runFunction',
26
73
  ];
27
- const propertyAliases = {
74
+ var propertyAliases = {
28
75
  functionsPath: 'functionPath',
29
76
  functionName: 'functionPath',
30
77
  funcName: 'functionPath',
@@ -32,22 +79,30 @@ const propertyAliases = {
32
79
  arguments: 'args',
33
80
  variables: 'args',
34
81
  };
35
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
36
- var _a, _b;
37
- const [functionPath, ...args] = (yield (0, _operatorUtils_1.evaluateArray)([expression.functionPath, ...(expression.args || [])], config));
38
- config.typeChecker({ name: 'functionPath', value: functionPath, expectedType: 'string' });
39
- const { objects, functions } = config.options;
40
- const func = ((_b = (_a = (0, object_property_extractor_1.default)(functions, functionPath, null)) !== null && _a !== void 0 ? _a : (0, object_property_extractor_1.default)(objects, functionPath, null)) !== null && _b !== void 0 ? _b : (0, object_property_extractor_1.default)(config.options, functionPath));
41
- return yield func(...args);
42
- });
43
- const parseChildren = (expression) => {
44
- const [functionPath, ...args] = expression.children;
45
- return Object.assign(Object.assign({}, expression), { functionPath, args });
82
+ var evaluate = function (expression, config) { return __awaiter(void 0, void 0, void 0, function () {
83
+ var _a, functionPath, args, _b, objects, functions, func;
84
+ var _c, _d;
85
+ return __generator(this, function (_e) {
86
+ switch (_e.label) {
87
+ case 0: return [4, (0, _operatorUtils_1.evaluateArray)(__spreadArray([expression.functionPath], (expression.args || []), true), config)];
88
+ case 1:
89
+ _a = (_e.sent()), functionPath = _a[0], args = _a.slice(1);
90
+ config.typeChecker({ name: 'functionPath', value: functionPath, expectedType: 'string' });
91
+ _b = config.options, objects = _b.objects, functions = _b.functions;
92
+ func = ((_d = (_c = (0, object_property_extractor_1.default)(functions, functionPath, null)) !== null && _c !== void 0 ? _c : (0, object_property_extractor_1.default)(objects, functionPath, null)) !== null && _d !== void 0 ? _d : (0, object_property_extractor_1.default)(config.options, functionPath));
93
+ return [4, func.apply(void 0, args)];
94
+ case 2: return [2, _e.sent()];
95
+ }
96
+ });
97
+ }); };
98
+ var parseChildren = function (expression) {
99
+ var _a = expression.children, functionPath = _a[0], args = _a.slice(1);
100
+ return __assign(__assign({}, expression), { functionPath: functionPath, args: args });
46
101
  };
47
102
  exports.CUSTOM_FUNCTIONS = {
48
- requiredProperties,
49
- operatorAliases,
50
- propertyAliases,
51
- evaluate,
52
- parseChildren,
103
+ requiredProperties: requiredProperties,
104
+ operatorAliases: operatorAliases,
105
+ propertyAliases: propertyAliases,
106
+ evaluate: evaluate,
107
+ parseChildren: parseChildren,
53
108
  };