fig-tree-evaluator 2.5.0 → 2.5.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 +5 -5
- package/build/FigTreeEvaluator.js +32 -75
- package/build/cache.js +29 -75
- package/build/evaluate.js +68 -159
- package/build/helpers.js +55 -133
- package/build/index.js +1 -1
- package/build/operators/_operatorUtils.js +48 -109
- package/build/operators/buildObject.js +26 -84
- package/build/operators/conditional.js +18 -70
- package/build/operators/count.js +14 -48
- package/build/operators/customFunctions.js +25 -95
- package/build/operators/divide.js +26 -61
- package/build/operators/equal.js +23 -57
- package/build/operators/getRequest.js +36 -97
- package/build/operators/graphQL.js +40 -101
- package/build/operators/greaterThan.js +20 -54
- package/build/operators/lessThan.js +20 -54
- package/build/operators/logicalAnd.js +16 -61
- package/build/operators/logicalOr.js +14 -48
- package/build/operators/match.js +38 -101
- package/build/operators/multiply.js +14 -48
- package/build/operators/notEqual.js +23 -57
- package/build/operators/objectProperties.js +21 -66
- package/build/operators/passThru.js +15 -58
- package/build/operators/pgSQL.js +54 -135
- package/build/operators/plus.js +24 -70
- package/build/operators/postRequest.js +28 -82
- package/build/operators/regex.js +24 -70
- package/build/operators/split.js +29 -74
- package/build/operators/stringSubstitution.js +25 -79
- package/build/operators/subtract.js +16 -50
- package/build/typeCheck.js +22 -27
- package/package.json +2 -2
package/build/helpers.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
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
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,43 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
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
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
12
|
exports.evaluateObject = exports.isObject = exports.errorMessage = exports.convertOutputMethods = exports.mergeOptions = exports.checkRequiredNodes = exports.replaceAliasNodeValues = exports.evaluateNodeAliases = exports.mapPropertyAliases = exports.fallbackOrError = exports.truncateString = exports.getOperatorName = exports.isFragmentNode = exports.isOperatorNode = exports.parseIfJson = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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) => {
|
|
55
17
|
if (typeof input !== 'string')
|
|
56
18
|
return input;
|
|
57
19
|
try {
|
|
58
|
-
|
|
20
|
+
const parsedInput = JSON.parse(input);
|
|
59
21
|
return (0, exports.isOperatorNode)(parsedInput) ? parsedInput : input;
|
|
60
22
|
}
|
|
61
23
|
catch (err) {
|
|
@@ -63,29 +25,19 @@ var parseIfJson = function (input) {
|
|
|
63
25
|
}
|
|
64
26
|
};
|
|
65
27
|
exports.parseIfJson = parseIfJson;
|
|
66
|
-
|
|
67
|
-
return input instanceof Object && 'operator' in input;
|
|
68
|
-
};
|
|
28
|
+
const isOperatorNode = (input) => input instanceof Object && 'operator' in input;
|
|
69
29
|
exports.isOperatorNode = isOperatorNode;
|
|
70
|
-
|
|
71
|
-
return input instanceof Object && 'fragment' in input;
|
|
72
|
-
};
|
|
30
|
+
const isFragmentNode = (input) => input instanceof Object && 'fragment' in input;
|
|
73
31
|
exports.isFragmentNode = isFragmentNode;
|
|
74
|
-
|
|
75
|
-
|
|
32
|
+
const standardiseOperatorName = (name) => {
|
|
33
|
+
const camelCaseName = (0, change_case_1.camelCase)(name);
|
|
76
34
|
return camelCaseName ? camelCaseName : name;
|
|
77
35
|
};
|
|
78
|
-
|
|
79
|
-
return operatorAliases[standardiseOperatorName(operator)];
|
|
80
|
-
};
|
|
36
|
+
const getOperatorName = (operator, operatorAliases) => operatorAliases[standardiseOperatorName(operator)];
|
|
81
37
|
exports.getOperatorName = getOperatorName;
|
|
82
|
-
|
|
83
|
-
if (length === void 0) { length = 200; }
|
|
84
|
-
return string.length < length ? string : "".concat(string.slice(0, length - 2).trim(), "...");
|
|
85
|
-
};
|
|
38
|
+
const truncateString = (string, length = 200) => string.length < length ? string : `${string.slice(0, length - 2).trim()}...`;
|
|
86
39
|
exports.truncateString = truncateString;
|
|
87
|
-
|
|
88
|
-
if (returnErrorAsString === void 0) { returnErrorAsString = false; }
|
|
40
|
+
const fallbackOrError = (fallback, errorMessage, returnErrorAsString = false) => {
|
|
89
41
|
if (fallback !== undefined)
|
|
90
42
|
return fallback;
|
|
91
43
|
if (returnErrorAsString)
|
|
@@ -94,108 +46,78 @@ var fallbackOrError = function (fallback, errorMessage, returnErrorAsString) {
|
|
|
94
46
|
throw new Error((0, exports.truncateString)(errorMessage));
|
|
95
47
|
};
|
|
96
48
|
exports.fallbackOrError = fallbackOrError;
|
|
97
|
-
|
|
98
|
-
return mapObjectKeys(expression, function (key) {
|
|
99
|
-
return key in propertyAliases ? propertyAliases[key] : key;
|
|
100
|
-
});
|
|
101
|
-
};
|
|
49
|
+
const mapPropertyAliases = (propertyAliases, expression) => mapObjectKeys(expression, (key) => key in propertyAliases ? propertyAliases[key] : key);
|
|
102
50
|
exports.mapPropertyAliases = mapPropertyAliases;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
var key = _a[0], value = _a[1];
|
|
107
|
-
return [mapFunction(key), value];
|
|
108
|
-
});
|
|
51
|
+
const mapObjectKeys = (inputObj, mapFunction) => {
|
|
52
|
+
const keyVals = Object.entries(inputObj);
|
|
53
|
+
const mappedKeys = keyVals.map(([key, value]) => [mapFunction(key), value]);
|
|
109
54
|
return Object.fromEntries(mappedKeys);
|
|
110
55
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
evaluations = [];
|
|
121
|
-
aliasKeys.forEach(function (alias) { return evaluations.push((0, evaluate_1.evaluatorFunction)(expression[alias], config)); });
|
|
122
|
-
_a = _operatorUtils_1.zipArraysToObject;
|
|
123
|
-
_b = [aliasKeys];
|
|
124
|
-
return [4, Promise.all(evaluations)];
|
|
125
|
-
case 1: return [2, _a.apply(void 0, _b.concat([_c.sent()]))];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}); };
|
|
56
|
+
const isAliasString = (value) => /^\$.+/.test(value);
|
|
57
|
+
const evaluateNodeAliases = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
const aliasKeys = Object.keys(expression).filter(isAliasString);
|
|
59
|
+
if (aliasKeys.length === 0)
|
|
60
|
+
return expression;
|
|
61
|
+
const evaluations = [];
|
|
62
|
+
aliasKeys.forEach((alias) => evaluations.push((0, evaluate_1.evaluatorFunction)(expression[alias], config)));
|
|
63
|
+
return (0, _operatorUtils_1.zipArraysToObject)(aliasKeys, yield Promise.all(evaluations));
|
|
64
|
+
});
|
|
129
65
|
exports.evaluateNodeAliases = evaluateNodeAliases;
|
|
130
|
-
|
|
131
|
-
var
|
|
132
|
-
var resolvedAliasNodes = _a.resolvedAliasNodes;
|
|
66
|
+
const replaceAliasNodeValues = (value, { resolvedAliasNodes }) => {
|
|
67
|
+
var _a;
|
|
133
68
|
if (typeof value !== 'string' || !isAliasString(value))
|
|
134
69
|
return value;
|
|
135
|
-
return (
|
|
70
|
+
return (_a = resolvedAliasNodes === null || resolvedAliasNodes === void 0 ? void 0 : resolvedAliasNodes[value]) !== null && _a !== void 0 ? _a : value;
|
|
136
71
|
};
|
|
137
72
|
exports.replaceAliasNodeValues = replaceAliasNodeValues;
|
|
138
|
-
|
|
139
|
-
|
|
73
|
+
const checkRequiredNodes = (requiredProps, expression) => {
|
|
74
|
+
const missingProps = requiredProps.filter((prop) => !(prop in expression));
|
|
140
75
|
if (missingProps.length === 0)
|
|
141
76
|
return false;
|
|
142
77
|
if (!('children' in expression))
|
|
143
|
-
return
|
|
78
|
+
return `Missing properties: ${missingProps}`;
|
|
144
79
|
return false;
|
|
145
80
|
};
|
|
146
81
|
exports.checkRequiredNodes = checkRequiredNodes;
|
|
147
|
-
|
|
148
|
-
|
|
82
|
+
const mergeOptions = (origOptions, newOptions) => {
|
|
83
|
+
const combinedOptions = Object.assign(Object.assign({}, origOptions), newOptions);
|
|
149
84
|
if (origOptions.data || newOptions.data)
|
|
150
|
-
combinedOptions.data =
|
|
85
|
+
combinedOptions.data = Object.assign(Object.assign({}, origOptions.data), newOptions.data);
|
|
151
86
|
if (origOptions.functions || newOptions.functions)
|
|
152
|
-
combinedOptions.functions =
|
|
87
|
+
combinedOptions.functions = Object.assign(Object.assign({}, origOptions.functions), newOptions.functions);
|
|
153
88
|
if (origOptions.fragments || newOptions.fragments)
|
|
154
|
-
combinedOptions.fragments =
|
|
89
|
+
combinedOptions.fragments = Object.assign(Object.assign({}, origOptions.fragments), newOptions.fragments);
|
|
155
90
|
if (origOptions.headers || newOptions.headers)
|
|
156
|
-
combinedOptions.headers =
|
|
91
|
+
combinedOptions.headers = Object.assign(Object.assign({}, origOptions.headers), newOptions.headers);
|
|
157
92
|
return combinedOptions;
|
|
158
93
|
};
|
|
159
94
|
exports.mergeOptions = mergeOptions;
|
|
160
95
|
exports.convertOutputMethods = {
|
|
161
|
-
number:
|
|
162
|
-
string:
|
|
163
|
-
array:
|
|
164
|
-
boolean:
|
|
165
|
-
bool:
|
|
96
|
+
number: (value) => extractNumber(value),
|
|
97
|
+
string: (value) => String(value),
|
|
98
|
+
array: (value) => (Array.isArray(value) ? value : [value]),
|
|
99
|
+
boolean: (value) => Boolean(value),
|
|
100
|
+
bool: (value) => Boolean(value),
|
|
166
101
|
};
|
|
167
|
-
|
|
102
|
+
const errorMessage = (err) => err.message;
|
|
168
103
|
exports.errorMessage = errorMessage;
|
|
169
|
-
|
|
104
|
+
const extractNumber = (input) => {
|
|
170
105
|
if (typeof input !== 'string')
|
|
171
106
|
return Number.isNaN(Number(input)) ? input : Number(input);
|
|
172
|
-
|
|
173
|
-
|
|
107
|
+
const pattern = new RegExp(/-?\d*\.?\d+/gm);
|
|
108
|
+
const numberMatch = input.match(pattern);
|
|
174
109
|
if (!numberMatch)
|
|
175
110
|
return 0;
|
|
176
111
|
return Number(numberMatch[0]);
|
|
177
112
|
};
|
|
178
|
-
|
|
179
|
-
return typeof input === 'object' && input !== null && !Array.isArray(input);
|
|
180
|
-
};
|
|
113
|
+
const isObject = (input) => typeof input === 'object' && input !== null && !Array.isArray(input);
|
|
181
114
|
exports.isObject = isObject;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
Object.entries(input).forEach(function (_a) {
|
|
191
|
-
var key = _a[0], value = _a[1];
|
|
192
|
-
return newObjectEntries.push(key, (0, evaluate_1.evaluatorFunction)(value, config));
|
|
193
|
-
});
|
|
194
|
-
return [4, Promise.all(newObjectEntries)];
|
|
195
|
-
case 1:
|
|
196
|
-
result = _a.sent();
|
|
197
|
-
return [2, (0, _operatorUtils_1.singleArrayToObject)(result)];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}); };
|
|
115
|
+
const evaluateObject = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
if (!(0, exports.isObject)(input))
|
|
117
|
+
return input;
|
|
118
|
+
const newObjectEntries = [];
|
|
119
|
+
Object.entries(input).forEach(([key, value]) => newObjectEntries.push(key, (0, evaluate_1.evaluatorFunction)(value, config)));
|
|
120
|
+
const result = yield Promise.all(newObjectEntries);
|
|
121
|
+
return (0, _operatorUtils_1.singleArrayToObject)(result);
|
|
122
|
+
});
|
|
201
123
|
exports.evaluateObject = evaluateObject;
|
package/build/index.js
CHANGED
|
@@ -24,6 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.evaluateExpression = void 0;
|
|
27
|
-
|
|
27
|
+
const FigTreeEvaluator_1 = __importStar(require("./FigTreeEvaluator"));
|
|
28
28
|
Object.defineProperty(exports, "evaluateExpression", { enumerable: true, get: function () { return FigTreeEvaluator_1.evaluateExpression; } });
|
|
29
29
|
exports.default = FigTreeEvaluator_1.default;
|
|
@@ -1,15 +1,4 @@
|
|
|
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
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,88 +8,53 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
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
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
13
|
};
|
|
52
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
15
|
exports.axiosRequest = exports.joinUrlParts = exports.isFullUrl = exports.extractAndSimplify = exports.simplifyObject = exports.singleArrayToObject = exports.zipArraysToObject = exports.evaluateArray = void 0;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
}); };
|
|
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
|
+
});
|
|
70
25
|
exports.evaluateArray = evaluateArray;
|
|
71
|
-
|
|
72
|
-
|
|
26
|
+
const zipArraysToObject = (keys, values) => {
|
|
27
|
+
const pairs = keys.map((key, index) => [key, values[index]]);
|
|
73
28
|
return Object.fromEntries(pairs);
|
|
74
29
|
};
|
|
75
30
|
exports.zipArraysToObject = zipArraysToObject;
|
|
76
|
-
|
|
31
|
+
const singleArrayToObject = (elements) => {
|
|
77
32
|
if (elements.length % 2 !== 0)
|
|
78
33
|
throw new Error('Even number of children required to make key/value pairs');
|
|
79
|
-
|
|
80
|
-
|
|
34
|
+
const keys = elements.filter((_, index) => index % 2 === 0);
|
|
35
|
+
const result = (0, typeCheck_1.typeCheck)(...keys.map((key) => ({
|
|
81
36
|
value: key,
|
|
82
37
|
expectedType: ['string', 'number', 'boolean'],
|
|
83
|
-
})
|
|
38
|
+
})));
|
|
84
39
|
if (result !== true)
|
|
85
40
|
throw new Error(result);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
keys.forEach(
|
|
41
|
+
const values = elements.filter((_, index) => index % 2 === 1);
|
|
42
|
+
const output = {};
|
|
43
|
+
keys.forEach((key, index) => {
|
|
89
44
|
output[key] = values[index];
|
|
90
45
|
});
|
|
91
46
|
return output;
|
|
92
47
|
};
|
|
93
48
|
exports.singleArrayToObject = singleArrayToObject;
|
|
94
|
-
|
|
49
|
+
const simplifyObject = (item) => {
|
|
95
50
|
return item instanceof Object && Object.keys(item).length === 1 ? Object.values(item)[0] : item;
|
|
96
51
|
};
|
|
97
52
|
exports.simplifyObject = simplifyObject;
|
|
98
|
-
|
|
99
|
-
if (fallback === void 0) { fallback = undefined; }
|
|
53
|
+
const extractAndSimplify = (data, returnProperty, fallback = undefined) => {
|
|
100
54
|
try {
|
|
101
|
-
|
|
55
|
+
const selectedProperty = returnProperty ? (0, extract_1.default)(data, returnProperty, fallback) : data;
|
|
102
56
|
if (Array.isArray(selectedProperty))
|
|
103
|
-
return selectedProperty.map(
|
|
57
|
+
return selectedProperty.map((item) => (0, exports.simplifyObject)(item));
|
|
104
58
|
if (returnProperty) {
|
|
105
59
|
if (selectedProperty === null)
|
|
106
60
|
return null;
|
|
@@ -113,53 +67,38 @@ var extractAndSimplify = function (data, returnProperty, fallback) {
|
|
|
113
67
|
}
|
|
114
68
|
};
|
|
115
69
|
exports.extractAndSimplify = extractAndSimplify;
|
|
116
|
-
|
|
70
|
+
const isFullUrl = (url) => /^https?:\/\/.+/.test(url);
|
|
117
71
|
exports.isFullUrl = isFullUrl;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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);
|
|
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);
|
|
127
77
|
if (newPart === '')
|
|
128
78
|
return acc;
|
|
129
79
|
return acc + (index === 0 ? '' : '/') + newPart;
|
|
130
80
|
}, '');
|
|
131
81
|
};
|
|
132
82
|
exports.joinUrlParts = joinUrlParts;
|
|
133
|
-
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return [4, (0, axios_1.default)({
|
|
143
|
-
method: method,
|
|
144
|
-
url: url,
|
|
145
|
-
headers: __assign({ 'Content-Type': 'application/json', Accept: 'application/json' }, headers),
|
|
146
|
-
params: params,
|
|
147
|
-
data: data,
|
|
148
|
-
})];
|
|
149
|
-
case 1:
|
|
150
|
-
response = _g.sent();
|
|
151
|
-
return [2, response.data];
|
|
152
|
-
case 2:
|
|
153
|
-
err_1 = _g.sent();
|
|
154
|
-
if (axios_1.default.isAxiosError(err_1)) {
|
|
155
|
-
if (!(err_1 === null || err_1 === void 0 ? void 0 : err_1.response))
|
|
156
|
-
throw new Error('Network Error');
|
|
157
|
-
console.log((_f = err_1.response) === null || _f === void 0 ? void 0 : _f.data);
|
|
158
|
-
}
|
|
159
|
-
throw err_1;
|
|
160
|
-
case 3: return [2];
|
|
161
|
-
}
|
|
83
|
+
const axiosRequest = ({ url, params = {}, data = {}, headers = {}, method = 'get', }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
var _a;
|
|
85
|
+
try {
|
|
86
|
+
const response = yield (0, axios_1.default)({
|
|
87
|
+
method,
|
|
88
|
+
url,
|
|
89
|
+
headers: Object.assign({ 'Content-Type': 'application/json', Accept: 'application/json' }, headers),
|
|
90
|
+
params,
|
|
91
|
+
data,
|
|
162
92
|
});
|
|
163
|
-
|
|
164
|
-
}
|
|
93
|
+
return response.data;
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
if (axios_1.default.isAxiosError(err)) {
|
|
97
|
+
if (!(err === null || err === void 0 ? void 0 : err.response))
|
|
98
|
+
throw new Error('Network Error');
|
|
99
|
+
console.log((_a = err.response) === null || _a === void 0 ? void 0 : _a.data);
|
|
100
|
+
}
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
165
104
|
exports.axiosRequest = axiosRequest;
|
|
@@ -1,15 +1,4 @@
|
|
|
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
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,88 +8,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
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
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
12
|
exports.BUILD_OBJECT = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
13
|
+
const _operatorUtils_1 = require("./_operatorUtils");
|
|
14
|
+
const requiredProperties = ['properties'];
|
|
15
|
+
const operatorAliases = ['buildObject', 'build', 'object'];
|
|
16
|
+
const propertyAliases = {
|
|
55
17
|
values: 'properties',
|
|
56
18
|
keyValPairs: 'properties',
|
|
57
19
|
keyValuePairs: 'properties',
|
|
58
20
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}
|
|
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];
|
|
89
26
|
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
|
|
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;
|
|
93
35
|
if (elements.length % 2 !== 0)
|
|
94
36
|
throw new Error('Even number of children required to make key/value pairs');
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
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 });
|
|
99
41
|
};
|
|
100
42
|
exports.BUILD_OBJECT = {
|
|
101
|
-
requiredProperties
|
|
102
|
-
operatorAliases
|
|
103
|
-
propertyAliases
|
|
104
|
-
evaluate
|
|
105
|
-
parseChildren
|
|
43
|
+
requiredProperties,
|
|
44
|
+
operatorAliases,
|
|
45
|
+
propertyAliases,
|
|
46
|
+
evaluate,
|
|
47
|
+
parseChildren,
|
|
106
48
|
};
|