fig-tree-evaluator 2.8.0 → 2.8.3
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/FigTreeEvaluator.d.ts +6 -16
- package/build/FigTreeEvaluator.js +8 -4
- package/build/cache.d.ts +3 -1
- package/build/cache.js +10 -11
- package/build/evaluate.js +3 -5
- package/build/helpers.d.ts +8 -34
- package/build/helpers.js +1 -10
- package/build/index.d.ts +2 -2
- package/build/operators/AND/data.d.ts +0 -1
- package/build/operators/AND/data.js +1 -2
- package/build/operators/AND/index.d.ts +1 -1
- package/build/operators/AND/operator.d.ts +2 -6
- package/build/operators/AND/operator.js +1 -2
- package/build/operators/BUILD_OBJECT/data.d.ts +0 -1
- package/build/operators/BUILD_OBJECT/data.js +1 -2
- package/build/operators/BUILD_OBJECT/operator.d.ts +1 -9
- package/build/operators/BUILD_OBJECT/operator.js +1 -2
- package/build/operators/CONDITIONAL/data.d.ts +0 -1
- package/build/operators/CONDITIONAL/data.js +1 -2
- package/build/operators/CONDITIONAL/operator.d.ts +1 -5
- package/build/operators/CONDITIONAL/operator.js +7 -2
- package/build/operators/COUNT/data.d.ts +0 -1
- package/build/operators/COUNT/data.js +1 -2
- package/build/operators/COUNT/operator.js +1 -2
- package/build/operators/CUSTOM_FUNCTIONS/data.d.ts +0 -1
- package/build/operators/CUSTOM_FUNCTIONS/data.js +9 -3
- package/build/operators/CUSTOM_FUNCTIONS/operator.d.ts +1 -7
- package/build/operators/CUSTOM_FUNCTIONS/operator.js +7 -6
- package/build/operators/DIVIDE/data.d.ts +0 -1
- package/build/operators/DIVIDE/data.js +2 -3
- package/build/operators/DIVIDE/operator.d.ts +1 -11
- package/build/operators/DIVIDE/operator.js +5 -4
- package/build/operators/EQUAL/data.d.ts +0 -1
- package/build/operators/EQUAL/data.js +1 -2
- package/build/operators/EQUAL/operator.js +1 -2
- package/build/operators/GET/data.d.ts +0 -1
- package/build/operators/GET/data.js +1 -2
- package/build/operators/GET/index.d.ts +1 -1
- package/build/operators/GET/operator.d.ts +2 -10
- package/build/operators/GET/operator.js +16 -14
- package/build/operators/GRAPHQL/data.d.ts +0 -1
- package/build/operators/GRAPHQL/data.js +1 -2
- package/build/operators/GRAPHQL/operator.d.ts +1 -10
- package/build/operators/GRAPHQL/operator.js +20 -9
- package/build/operators/GREATER_THAN/data.d.ts +0 -1
- package/build/operators/GREATER_THAN/data.js +1 -2
- package/build/operators/GREATER_THAN/operator.d.ts +0 -4
- package/build/operators/GREATER_THAN/operator.js +1 -2
- package/build/operators/LESS_THAN/data.d.ts +0 -1
- package/build/operators/LESS_THAN/data.js +1 -2
- package/build/operators/LESS_THAN/operator.js +1 -2
- package/build/operators/MATCH/data.d.ts +0 -1
- package/build/operators/MATCH/data.js +1 -2
- package/build/operators/MATCH/operator.d.ts +1 -5
- package/build/operators/MATCH/operator.js +12 -6
- package/build/operators/MULTIPLY/data.d.ts +0 -1
- package/build/operators/MULTIPLY/data.js +1 -2
- package/build/operators/MULTIPLY/operator.js +5 -2
- package/build/operators/NOT_EQUAL/data.d.ts +0 -1
- package/build/operators/NOT_EQUAL/data.js +1 -2
- package/build/operators/NOT_EQUAL/operator.js +1 -2
- package/build/operators/OBJECT_PROPERTIES/data.d.ts +0 -1
- package/build/operators/OBJECT_PROPERTIES/data.js +1 -2
- package/build/operators/OBJECT_PROPERTIES/operator.d.ts +1 -7
- package/build/operators/OBJECT_PROPERTIES/operator.js +1 -2
- package/build/operators/OR/data.d.ts +0 -1
- package/build/operators/OR/data.js +1 -2
- package/build/operators/OR/operator.js +1 -2
- package/build/operators/PASSTHRU/data.d.ts +0 -1
- package/build/operators/PASSTHRU/data.js +1 -2
- package/build/operators/PASSTHRU/operator.d.ts +1 -5
- package/build/operators/PASSTHRU/operator.js +2 -1
- package/build/operators/PG_SQL/data.d.ts +0 -1
- package/build/operators/PG_SQL/data.js +9 -3
- package/build/operators/PG_SQL/operator.d.ts +1 -23
- package/build/operators/PG_SQL/operator.js +22 -30
- package/build/operators/PLUS/data.d.ts +0 -1
- package/build/operators/PLUS/data.js +2 -3
- package/build/operators/PLUS/operator.d.ts +1 -8
- package/build/operators/PLUS/operator.js +5 -5
- package/build/operators/POST/data.d.ts +0 -1
- package/build/operators/POST/data.js +1 -2
- package/build/operators/POST/operator.js +14 -6
- package/build/operators/REGEX/data.d.ts +0 -1
- package/build/operators/REGEX/data.js +1 -2
- package/build/operators/REGEX/operator.d.ts +1 -5
- package/build/operators/REGEX/operator.js +1 -2
- package/build/operators/SPLIT/data.d.ts +0 -1
- package/build/operators/SPLIT/data.js +1 -2
- package/build/operators/SPLIT/operator.d.ts +1 -9
- package/build/operators/SPLIT/operator.js +1 -2
- package/build/operators/STRING_SUBSTITUTION/data.d.ts +0 -1
- package/build/operators/STRING_SUBSTITUTION/data.js +1 -2
- package/build/operators/STRING_SUBSTITUTION/operator.d.ts +1 -5
- package/build/operators/STRING_SUBSTITUTION/operator.js +5 -6
- package/build/operators/SUBTRACT/data.d.ts +0 -1
- package/build/operators/SUBTRACT/data.js +1 -2
- package/build/operators/SUBTRACT/operator.d.ts +1 -8
- package/build/operators/SUBTRACT/operator.js +4 -3
- package/build/operators/_operatorUtils.d.ts +16 -17
- package/build/operators/_operatorUtils.js +17 -17
- package/build/shorthandSyntax.js +1 -1
- package/build/typeCheck.d.ts +8 -4
- package/build/typeCheck.js +25 -20
- package/build/types.d.ts +32 -33
- package/build/version.d.ts +1 -0
- package/build/version.js +4 -0
- package/package.json +10 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases =
|
|
3
|
+
exports.propertyAliases = void 0;
|
|
4
4
|
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
5
|
const description = 'Query a Postgres database using node-postgres';
|
|
6
6
|
const aliases = ['pgSql', 'sql', 'postgres', 'pg', 'pgDb'];
|
|
@@ -24,10 +24,16 @@ const parameters = [
|
|
|
24
24
|
description: 'Determines the shape of the resulting data (see documentation)',
|
|
25
25
|
aliases: ['queryType'],
|
|
26
26
|
required: false,
|
|
27
|
-
type: 'string',
|
|
27
|
+
type: { literal: ['array', 'string', 'number'] },
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'useCache',
|
|
31
|
+
description: 'Whether or not the FigTree cache is used',
|
|
32
|
+
aliases: [],
|
|
33
|
+
required: false,
|
|
34
|
+
type: 'boolean',
|
|
28
35
|
},
|
|
29
36
|
];
|
|
30
|
-
exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
|
|
31
37
|
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
32
38
|
const operatorData = {
|
|
33
39
|
description,
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { requiredProperties } from './data';
|
|
3
|
-
export type PGNode = {
|
|
4
|
-
[key in typeof requiredProperties[number]]: EvaluatorNode;
|
|
5
|
-
} & BaseOperatorNode & {
|
|
6
|
-
values?: EvaluatorNode[];
|
|
7
|
-
type?: 'string';
|
|
8
|
-
};
|
|
9
|
-
export interface PGConnection {
|
|
10
|
-
query: (expression: {
|
|
11
|
-
text: string;
|
|
12
|
-
values?: any[];
|
|
13
|
-
rowMode?: string;
|
|
14
|
-
}) => Promise<QueryResult>;
|
|
15
|
-
}
|
|
16
|
-
interface QueryRowResult {
|
|
17
|
-
[columns: string]: any;
|
|
18
|
-
}
|
|
19
|
-
export interface QueryResult {
|
|
20
|
-
rows: QueryRowResult[];
|
|
21
|
-
error?: string;
|
|
22
|
-
}
|
|
1
|
+
import { OperatorObject } from '../../types';
|
|
23
2
|
export declare const PG_SQL: OperatorObject;
|
|
24
|
-
export {};
|
|
@@ -37,53 +37,45 @@ const _operatorUtils_1 = require("../_operatorUtils");
|
|
|
37
37
|
const data_1 = __importStar(require("./data"));
|
|
38
38
|
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
39
|
var _a, _b, _c;
|
|
40
|
-
const [query, type,
|
|
41
|
-
config.typeChecker(
|
|
40
|
+
const [query, type, values, useCache] = (yield (0, _operatorUtils_1.evaluateArray)([expression.query, expression.type, expression.values || [], expression.useCache], config));
|
|
41
|
+
config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { query, type, values, useCache }));
|
|
42
42
|
if (!((_a = config.options) === null || _a === void 0 ? void 0 : _a.pgConnection))
|
|
43
43
|
throw new Error('No Postgres database connection provided');
|
|
44
44
|
const shouldUseCache = (_c = (_b = expression.useCache) !== null && _b !== void 0 ? _b : config.options.useCache) !== null && _c !== void 0 ? _c : true;
|
|
45
|
-
|
|
46
|
-
const result = config.cache.useCache(shouldUseCache, (query, type,
|
|
47
|
-
return yield processPgSQL(
|
|
48
|
-
}), query, type,
|
|
45
|
+
{
|
|
46
|
+
const result = config.cache.useCache(shouldUseCache, (query, type, values) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
return yield processPgSQL(query, values, config.options.pgConnection, type);
|
|
48
|
+
}), query, type, values);
|
|
49
49
|
return result;
|
|
50
50
|
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
throw err;
|
|
53
|
-
}
|
|
54
51
|
});
|
|
55
52
|
const parseChildren = (expression) => {
|
|
56
53
|
const [query, ...values] = expression.children;
|
|
57
54
|
return Object.assign(Object.assign({}, expression), { query, values });
|
|
58
55
|
};
|
|
59
|
-
const processPgSQL = (
|
|
56
|
+
const processPgSQL = (query, values, connection, queryType) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
57
|
const expression = {
|
|
61
|
-
text:
|
|
62
|
-
values:
|
|
58
|
+
text: query,
|
|
59
|
+
values: values,
|
|
63
60
|
rowMode: queryType ? 'array' : '',
|
|
64
61
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return Number.isNaN(Number(result)) ? result : Number(result);
|
|
77
|
-
default:
|
|
78
|
-
return res.rows;
|
|
62
|
+
const res = yield connection.query(expression);
|
|
63
|
+
if (res === null || res === void 0 ? void 0 : res.error)
|
|
64
|
+
throw new Error(res.error);
|
|
65
|
+
switch (queryType) {
|
|
66
|
+
case 'array':
|
|
67
|
+
return res.rows.flat();
|
|
68
|
+
case 'string':
|
|
69
|
+
return res.rows.flat().join(' ');
|
|
70
|
+
case 'number': {
|
|
71
|
+
const result = res.rows.flat();
|
|
72
|
+
return Number.isNaN(Number(result)) ? result : Number(result);
|
|
79
73
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
throw err;
|
|
74
|
+
default:
|
|
75
|
+
return res.rows;
|
|
83
76
|
}
|
|
84
77
|
});
|
|
85
78
|
exports.PG_SQL = {
|
|
86
|
-
requiredProperties: data_1.requiredProperties,
|
|
87
79
|
propertyAliases: data_1.propertyAliases,
|
|
88
80
|
operatorData: data_1.default,
|
|
89
81
|
evaluate,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases =
|
|
3
|
+
exports.propertyAliases = void 0;
|
|
4
4
|
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
5
|
const description = 'Add, concatenate or merge multiple values';
|
|
6
6
|
const aliases = ['+', 'plus', 'add', 'concat', 'join', 'merge'];
|
|
@@ -17,10 +17,9 @@ const parameters = [
|
|
|
17
17
|
description: 'Data type to coerce input values to before addition',
|
|
18
18
|
aliases: [],
|
|
19
19
|
required: false,
|
|
20
|
-
type: 'string',
|
|
20
|
+
type: { literal: ['string', 'array', 'number', 'boolean', 'bool'] },
|
|
21
21
|
},
|
|
22
22
|
];
|
|
23
|
-
exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
|
|
24
23
|
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
25
24
|
const operatorData = {
|
|
26
25
|
description,
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OperatorObject, EvaluatorNode } from '../../types';
|
|
3
|
-
import { requiredProperties } from './data';
|
|
4
|
-
export type AdditionNode = {
|
|
5
|
-
[key in typeof requiredProperties[number]]: EvaluatorNode;
|
|
6
|
-
} & BasicExtendedNode & {
|
|
7
|
-
type?: 'string' | 'array';
|
|
8
|
-
};
|
|
1
|
+
import { OperatorObject } from '../../types';
|
|
9
2
|
export declare const PLUS: OperatorObject;
|
|
@@ -36,26 +36,26 @@ exports.PLUS = void 0;
|
|
|
36
36
|
const operator_1 = require("../AND/operator");
|
|
37
37
|
const _operatorUtils_1 = require("../_operatorUtils");
|
|
38
38
|
const data_1 = __importStar(require("./data"));
|
|
39
|
+
const helpers_1 = require("../../helpers");
|
|
39
40
|
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
if (expression.values.length === 0)
|
|
41
|
-
return expression.values;
|
|
42
41
|
const values = (yield (0, _operatorUtils_1.evaluateArray)(expression.values, config));
|
|
43
|
-
config.typeChecker(
|
|
42
|
+
config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, {
|
|
44
43
|
values,
|
|
45
44
|
type: expression.type,
|
|
46
45
|
}));
|
|
46
|
+
if (values.length === 0)
|
|
47
|
+
return values;
|
|
47
48
|
if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'string')
|
|
48
49
|
return values.reduce((acc, child) => acc.concat(child), '');
|
|
49
50
|
if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'array')
|
|
50
51
|
return values.reduce((acc, child) => acc.concat(child), []);
|
|
51
52
|
if (values.every((child) => typeof child === 'string' || Array.isArray(child)))
|
|
52
53
|
return values.reduce((acc, child) => acc.concat(child));
|
|
53
|
-
if (values.every((child) =>
|
|
54
|
+
if (values.every((child) => (0, helpers_1.isObject)(child)))
|
|
54
55
|
return values.reduce((acc, child) => (Object.assign(Object.assign({}, acc), child)), {});
|
|
55
56
|
return values.reduce((acc, child) => acc + child);
|
|
56
57
|
});
|
|
57
58
|
exports.PLUS = {
|
|
58
|
-
requiredProperties: data_1.requiredProperties,
|
|
59
59
|
propertyAliases: data_1.propertyAliases,
|
|
60
60
|
operatorData: data_1.default,
|
|
61
61
|
evaluate,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases =
|
|
3
|
+
exports.propertyAliases = void 0;
|
|
4
4
|
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
5
|
const description = 'HTTP POST Request';
|
|
6
6
|
const aliases = ['post'];
|
|
@@ -41,7 +41,6 @@ const parameters = [
|
|
|
41
41
|
type: 'boolean',
|
|
42
42
|
},
|
|
43
43
|
];
|
|
44
|
-
exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
|
|
45
44
|
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
46
45
|
const operatorData = {
|
|
47
46
|
description,
|
|
@@ -37,14 +37,23 @@ const _operatorUtils_1 = require("../_operatorUtils");
|
|
|
37
37
|
const operator_1 = require("../GET/operator");
|
|
38
38
|
const data_1 = __importStar(require("./data"));
|
|
39
39
|
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
var _a, _b, _c
|
|
41
|
-
const [urlObj, data, returnProperty, headers] = (yield (0, _operatorUtils_1.evaluateArray)([
|
|
40
|
+
var _a, _b, _c;
|
|
41
|
+
const [urlObj, data, returnProperty, headers, useCache] = (yield (0, _operatorUtils_1.evaluateArray)([
|
|
42
|
+
expression.url,
|
|
43
|
+
expression.parameters,
|
|
44
|
+
expression.returnProperty,
|
|
45
|
+
expression.headers,
|
|
46
|
+
expression.useCache,
|
|
47
|
+
], config));
|
|
42
48
|
const { url, headers: headersObj } = urlObj instanceof Object ? urlObj : { url: urlObj, headers: null };
|
|
43
|
-
config.typeChecker(
|
|
49
|
+
config.typeChecker([
|
|
50
|
+
...(0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { url, headers, data, returnProperty, useCache }),
|
|
51
|
+
{ name: 'headers', value: headersObj, expectedType: ['object', 'null'] },
|
|
52
|
+
]);
|
|
44
53
|
const baseUrl = (_a = config.options.baseEndpoint) !== null && _a !== void 0 ? _a : '';
|
|
45
54
|
const httpHeaders = Object.assign(Object.assign(Object.assign({}, (_b = config.options) === null || _b === void 0 ? void 0 : _b.headers), headersObj), headers);
|
|
46
|
-
const shouldUseCache = (
|
|
47
|
-
const result = yield config.cache.useCache(shouldUseCache, (
|
|
55
|
+
const shouldUseCache = (_c = useCache !== null && useCache !== void 0 ? useCache : config.options.useCache) !== null && _c !== void 0 ? _c : true;
|
|
56
|
+
const result = yield config.cache.useCache(shouldUseCache, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
57
|
const response = yield (0, _operatorUtils_1.axiosRequest)({
|
|
49
58
|
url,
|
|
50
59
|
data,
|
|
@@ -56,7 +65,6 @@ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, funct
|
|
|
56
65
|
return result;
|
|
57
66
|
});
|
|
58
67
|
exports.POST = {
|
|
59
|
-
requiredProperties: data_1.requiredProperties,
|
|
60
68
|
propertyAliases: data_1.propertyAliases,
|
|
61
69
|
operatorData: data_1.default,
|
|
62
70
|
evaluate,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases =
|
|
3
|
+
exports.propertyAliases = void 0;
|
|
4
4
|
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
5
|
const description = 'Compare a string against a regex pattern';
|
|
6
6
|
const aliases = ['regex', 'patternMatch', 'regexp', 'matchPattern'];
|
|
@@ -20,7 +20,6 @@ const parameters = [
|
|
|
20
20
|
type: 'string',
|
|
21
21
|
},
|
|
22
22
|
];
|
|
23
|
-
exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
|
|
24
23
|
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
25
24
|
const operatorData = {
|
|
26
25
|
description,
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { requiredProperties } from './data';
|
|
3
|
-
export type RegexNode = {
|
|
4
|
-
[key in typeof requiredProperties[number]]: EvaluatorNode;
|
|
5
|
-
} & BaseOperatorNode;
|
|
1
|
+
import { OperatorObject } from '../../types';
|
|
6
2
|
export declare const REGEX: OperatorObject;
|
|
@@ -38,7 +38,7 @@ const helpers_1 = require("../../helpers");
|
|
|
38
38
|
const data_1 = __importStar(require("./data"));
|
|
39
39
|
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
40
|
const [testString, pattern] = (yield (0, _operatorUtils_1.evaluateArray)([expression.testString, expression.pattern], config));
|
|
41
|
-
config.typeChecker(
|
|
41
|
+
config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { testString, pattern }));
|
|
42
42
|
try {
|
|
43
43
|
const re = new RegExp(pattern);
|
|
44
44
|
return re.test(testString);
|
|
@@ -52,7 +52,6 @@ const parseChildren = (expression) => {
|
|
|
52
52
|
return Object.assign(Object.assign({}, expression), { testString, pattern });
|
|
53
53
|
};
|
|
54
54
|
exports.REGEX = {
|
|
55
|
-
requiredProperties: data_1.requiredProperties,
|
|
56
55
|
propertyAliases: data_1.propertyAliases,
|
|
57
56
|
operatorData: data_1.default,
|
|
58
57
|
evaluate,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases =
|
|
3
|
+
exports.propertyAliases = void 0;
|
|
4
4
|
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
5
|
const description = 'Split a string into an array';
|
|
6
6
|
const aliases = ['split', 'arraySplit'];
|
|
@@ -34,7 +34,6 @@ const parameters = [
|
|
|
34
34
|
type: 'boolean',
|
|
35
35
|
},
|
|
36
36
|
];
|
|
37
|
-
exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
|
|
38
37
|
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
39
38
|
const operatorData = {
|
|
40
39
|
description,
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import { OperatorObject
|
|
2
|
-
import { requiredProperties } from './data';
|
|
3
|
-
export type SplitNode = {
|
|
4
|
-
[key in typeof requiredProperties[number]]: EvaluatorNode;
|
|
5
|
-
} & BaseOperatorNode & {
|
|
6
|
-
delimiter?: EvaluatorNode;
|
|
7
|
-
trimWhiteSpace: EvaluatorNode;
|
|
8
|
-
excludeTrailing: EvaluatorNode;
|
|
9
|
-
};
|
|
1
|
+
import { OperatorObject } from '../../types';
|
|
10
2
|
export declare const SPLIT: OperatorObject;
|
|
@@ -44,7 +44,7 @@ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, funct
|
|
|
44
44
|
(_b = expression.trimWhiteSpace) !== null && _b !== void 0 ? _b : true,
|
|
45
45
|
(_c = expression.excludeTrailing) !== null && _c !== void 0 ? _c : true,
|
|
46
46
|
], config));
|
|
47
|
-
config.typeChecker(
|
|
47
|
+
config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, {
|
|
48
48
|
value,
|
|
49
49
|
delimiter,
|
|
50
50
|
trimWhiteSpace,
|
|
@@ -62,7 +62,6 @@ const parseChildren = (expression) => {
|
|
|
62
62
|
return Object.assign(Object.assign({}, expression), { value, delimiter });
|
|
63
63
|
};
|
|
64
64
|
exports.SPLIT = {
|
|
65
|
-
requiredProperties: data_1.requiredProperties,
|
|
66
65
|
propertyAliases: data_1.propertyAliases,
|
|
67
66
|
operatorData: data_1.default,
|
|
68
67
|
evaluate,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases =
|
|
3
|
+
exports.propertyAliases = void 0;
|
|
4
4
|
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
5
|
const description = 'Replace values in a string using simple parameter substitution';
|
|
6
6
|
const aliases = ['stringSubstitution', 'substitute', 'stringSub', 'replace'];
|
|
@@ -20,7 +20,6 @@ const parameters = [
|
|
|
20
20
|
type: 'array',
|
|
21
21
|
},
|
|
22
22
|
];
|
|
23
|
-
exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
|
|
24
23
|
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
25
24
|
const operatorData = {
|
|
26
25
|
description,
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { requiredProperties } from './data';
|
|
3
|
-
export type StringSubNode = {
|
|
4
|
-
[key in typeof requiredProperties[number]]: EvaluatorNode;
|
|
5
|
-
} & BaseOperatorNode;
|
|
1
|
+
import { OperatorObject } from '../../types';
|
|
6
2
|
export declare const STRING_SUBSTITUTION: OperatorObject;
|
|
@@ -36,14 +36,14 @@ exports.STRING_SUBSTITUTION = void 0;
|
|
|
36
36
|
const _operatorUtils_1 = require("../_operatorUtils");
|
|
37
37
|
const data_1 = __importStar(require("./data"));
|
|
38
38
|
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
const [string,
|
|
40
|
-
config.typeChecker(
|
|
41
|
-
const
|
|
42
|
-
const parameters = (string.match(
|
|
39
|
+
const [string, substitutions] = (yield (0, _operatorUtils_1.evaluateArray)([expression.string, expression.substitutions], config));
|
|
40
|
+
config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { string, substitutions }));
|
|
41
|
+
const parameterPattern = /(%[\d]+)/g;
|
|
42
|
+
const parameters = (string.match(parameterPattern) || []).sort((a, b) => Number(a.slice(1)) - Number(b.slice(1)));
|
|
43
43
|
const uniqueParameters = new Set(parameters);
|
|
44
44
|
const replacementsObj = (0, _operatorUtils_1.zipArraysToObject)(Array.from(uniqueParameters), substitutions);
|
|
45
45
|
return string
|
|
46
|
-
.split(
|
|
46
|
+
.split(parameterPattern)
|
|
47
47
|
.map((fragment) => (fragment in replacementsObj ? replacementsObj[fragment] : fragment))
|
|
48
48
|
.join('');
|
|
49
49
|
});
|
|
@@ -52,7 +52,6 @@ const parseChildren = (expression) => {
|
|
|
52
52
|
return Object.assign(Object.assign({}, expression), { string, substitutions });
|
|
53
53
|
};
|
|
54
54
|
exports.STRING_SUBSTITUTION = {
|
|
55
|
-
requiredProperties: data_1.requiredProperties,
|
|
56
55
|
propertyAliases: data_1.propertyAliases,
|
|
57
56
|
operatorData: data_1.default,
|
|
58
57
|
evaluate,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases =
|
|
3
|
+
exports.propertyAliases = void 0;
|
|
4
4
|
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
5
|
const description = 'Subtract one numerical value from another';
|
|
6
6
|
const aliases = ['-', 'subtract', 'minus', 'takeaway'];
|
|
@@ -27,7 +27,6 @@ const parameters = [
|
|
|
27
27
|
type: 'number',
|
|
28
28
|
},
|
|
29
29
|
];
|
|
30
|
-
exports.requiredProperties = (0, _operatorUtils_1.getRequiredProperties)(parameters);
|
|
31
30
|
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
32
31
|
const operatorData = {
|
|
33
32
|
description,
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EvaluatorNode, OperatorObject, BaseOperatorNode } from '../../types';
|
|
3
|
-
interface SubtractionNodeWithProps extends BaseOperatorNode {
|
|
4
|
-
subtract: EvaluatorNode;
|
|
5
|
-
from: EvaluatorNode;
|
|
6
|
-
}
|
|
7
|
-
export type SubtractionNode = BasicExtendedNode & SubtractionNodeWithProps;
|
|
1
|
+
import { OperatorObject } from '../../types';
|
|
8
2
|
export declare const SUBTRACT: OperatorObject;
|
|
9
|
-
export {};
|
|
@@ -38,14 +38,15 @@ const _operatorUtils_1 = require("../_operatorUtils");
|
|
|
38
38
|
const data_1 = __importStar(require("./data"));
|
|
39
39
|
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
40
|
const [values, from, subtract] = (yield (0, _operatorUtils_1.evaluateArray)([expression.values, expression.from, expression.subtract], config));
|
|
41
|
-
config.typeChecker(
|
|
42
|
-
const vals = values !== null && values !== void 0 ? values : [from, subtract];
|
|
41
|
+
config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { values, from, subtract }));
|
|
42
|
+
const vals = values !== null && values !== void 0 ? values : [from, subtract].filter((e) => e !== undefined);
|
|
43
43
|
if (vals.length < 2)
|
|
44
44
|
throw new Error('- Not enough values provided');
|
|
45
|
+
if (vals.some((e) => typeof e !== 'number'))
|
|
46
|
+
throw new Error('- Not all values are numbers');
|
|
45
47
|
return vals[0] - vals[1];
|
|
46
48
|
});
|
|
47
49
|
exports.SUBTRACT = {
|
|
48
|
-
requiredProperties: data_1.requiredProperties,
|
|
49
50
|
propertyAliases: data_1.propertyAliases,
|
|
50
51
|
operatorData: data_1.default,
|
|
51
52
|
evaluate,
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare const getRequiredProperties: (parameters: Parameter[]) => string[];
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { EvaluatorNode, EvaluatorOutput, FigTreeConfig, Parameter } from '../types';
|
|
4
3
|
export declare const getPropertyAliases: (parameters: Parameter[]) => Record<string, string>;
|
|
5
|
-
export declare const getTypeCheckInput: (parameterDefinitions: Parameter[], params: Record<string, unknown>) => {
|
|
4
|
+
export declare const getTypeCheckInput: (parameterDefinitions: Parameter[], params: Record<string, unknown>) => ({
|
|
6
5
|
name: string;
|
|
7
6
|
value: unknown;
|
|
8
|
-
expectedType:
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
expectedType: {
|
|
8
|
+
literal: (string | undefined)[];
|
|
9
|
+
};
|
|
10
|
+
} | {
|
|
11
|
+
name: string;
|
|
12
|
+
value: unknown;
|
|
13
|
+
expectedType: import("../typeCheck").BasicType | import("../typeCheck").BasicType[];
|
|
14
|
+
})[];
|
|
15
|
+
export declare const evaluateArray: (nodes: EvaluatorNode[] | EvaluatorNode, params: FigTreeConfig) => Promise<EvaluatorOutput[]>;
|
|
11
16
|
export declare const zipArraysToObject: <T>(keys: string[], values: T[]) => {
|
|
12
17
|
[x: string]: T;
|
|
13
18
|
};
|
|
14
|
-
export declare const singleArrayToObject: (elements:
|
|
15
|
-
export declare const simplifyObject: (item:
|
|
16
|
-
export declare const extractAndSimplify: (data:
|
|
19
|
+
export declare const singleArrayToObject: <T>(elements: unknown[]) => Record<string, T>;
|
|
20
|
+
export declare const simplifyObject: (item: unknown) => any;
|
|
21
|
+
export declare const extractAndSimplify: (data: object | object[], returnProperty: string | undefined, fallback?: unknown) => any;
|
|
17
22
|
export declare const isFullUrl: (url: string) => boolean;
|
|
18
23
|
export declare const joinUrlParts: (...urls: string[]) => string;
|
|
19
|
-
export declare const axiosRequest: ({ url, params, data, headers, method, }:
|
|
20
|
-
url: string;
|
|
21
|
-
params?: GenericObject | undefined;
|
|
22
|
-
data?: GenericObject | undefined;
|
|
23
|
-
headers?: GenericObject | undefined;
|
|
24
|
-
method?: "get" | "post" | undefined;
|
|
25
|
-
}) => Promise<any>;
|
|
24
|
+
export declare const axiosRequest: ({ url, params, data, headers, method, }: AxiosRequestConfig) => Promise<any>;
|
|
@@ -12,13 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.axiosRequest = exports.joinUrlParts = exports.isFullUrl = exports.extractAndSimplify = exports.simplifyObject = exports.singleArrayToObject = exports.zipArraysToObject = exports.evaluateArray = exports.getTypeCheckInput = exports.getPropertyAliases =
|
|
15
|
+
exports.axiosRequest = exports.joinUrlParts = exports.isFullUrl = exports.extractAndSimplify = exports.simplifyObject = exports.singleArrayToObject = exports.zipArraysToObject = exports.evaluateArray = exports.getTypeCheckInput = exports.getPropertyAliases = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
17
|
const extract_1 = __importDefault(require("object-property-extractor/build/extract"));
|
|
18
18
|
const evaluate_1 = require("../evaluate");
|
|
19
|
+
const helpers_1 = require("../helpers");
|
|
19
20
|
const typeCheck_1 = require("../typeCheck");
|
|
20
|
-
const getRequiredProperties = (parameters) => parameters.filter((p) => p.required).map((p) => p.name);
|
|
21
|
-
exports.getRequiredProperties = getRequiredProperties;
|
|
22
21
|
const getPropertyAliases = (parameters) => {
|
|
23
22
|
const propertyAliases = {};
|
|
24
23
|
parameters.forEach((param) => {
|
|
@@ -28,6 +27,12 @@ const getPropertyAliases = (parameters) => {
|
|
|
28
27
|
};
|
|
29
28
|
exports.getPropertyAliases = getPropertyAliases;
|
|
30
29
|
const getTypeCheckInput = (parameterDefinitions, params) => parameterDefinitions.map(({ name, required, type }) => {
|
|
30
|
+
if ((0, typeCheck_1.isLiteralType)(type)) {
|
|
31
|
+
const literal = [...type.literal];
|
|
32
|
+
if (!required)
|
|
33
|
+
literal.push(undefined);
|
|
34
|
+
return { name, value: params[name], expectedType: { literal } };
|
|
35
|
+
}
|
|
31
36
|
const allTypes = Array.isArray(type) ? type : [type];
|
|
32
37
|
if (!required)
|
|
33
38
|
allTypes.push('undefined');
|
|
@@ -65,24 +70,19 @@ const singleArrayToObject = (elements) => {
|
|
|
65
70
|
};
|
|
66
71
|
exports.singleArrayToObject = singleArrayToObject;
|
|
67
72
|
const simplifyObject = (item) => {
|
|
68
|
-
return item
|
|
73
|
+
return (0, helpers_1.isObject)(item) && Object.keys(item).length === 1 ? Object.values(item)[0] : item;
|
|
69
74
|
};
|
|
70
75
|
exports.simplifyObject = simplifyObject;
|
|
71
76
|
const extractAndSimplify = (data, returnProperty, fallback = undefined) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return (0, exports.simplifyObject)(selectedProperty);
|
|
80
|
-
}
|
|
81
|
-
return selectedProperty;
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
throw err;
|
|
77
|
+
const selectedProperty = returnProperty ? (0, extract_1.default)(data, returnProperty, fallback) : data;
|
|
78
|
+
if (Array.isArray(selectedProperty))
|
|
79
|
+
return selectedProperty.map((item) => (0, exports.simplifyObject)(item));
|
|
80
|
+
if (returnProperty) {
|
|
81
|
+
if (selectedProperty === null)
|
|
82
|
+
return null;
|
|
83
|
+
return (0, exports.simplifyObject)(selectedProperty);
|
|
85
84
|
}
|
|
85
|
+
return selectedProperty;
|
|
86
86
|
};
|
|
87
87
|
exports.extractAndSimplify = extractAndSimplify;
|
|
88
88
|
const isFullUrl = (url) => /^https?:\/\/.+/.test(url);
|
package/build/shorthandSyntax.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.preProcessShorthand = void 0;
|
|
|
7
7
|
const helpers_1 = require("./helpers");
|
|
8
8
|
const _operatorAliases_json_1 = __importDefault(require("./operators/_operatorAliases.json"));
|
|
9
9
|
const operatorAliases = _operatorAliases_json_1.default;
|
|
10
|
-
const functionStringRegex = /(\$[
|
|
10
|
+
const functionStringRegex = /(\$[^()]+)\((.*)\)/;
|
|
11
11
|
const preProcessShorthand = (expression, fragments = {}, useShorthand = true) => {
|
|
12
12
|
if (!useShorthand)
|
|
13
13
|
return expression;
|
package/build/typeCheck.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type BasicType = 'any' | 'string' | 'boolean' | 'number' | 'array' | 'object' | 'null' | 'undefined';
|
|
2
|
+
export type LiteralType = {
|
|
3
|
+
literal: (string | undefined)[];
|
|
4
|
+
};
|
|
5
|
+
export type ExpectedType = BasicType | LiteralType | BasicType[];
|
|
2
6
|
export type TypeCheckInput = {
|
|
3
|
-
value: unknown;
|
|
4
7
|
name?: string;
|
|
5
|
-
|
|
6
|
-
expectedType: ExpectedType
|
|
8
|
+
value: unknown;
|
|
9
|
+
expectedType: ExpectedType;
|
|
7
10
|
};
|
|
11
|
+
export declare const isLiteralType: (typeDefinition: ExpectedType) => typeDefinition is LiteralType;
|
|
8
12
|
export declare const typeCheck: (...args: TypeCheckInput[]) => true | string;
|