fig-tree-evaluator 2.10.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/build/index.cjs.js +1 -0
- package/build/index.d.ts +121 -4
- package/build/index.esm.js +1 -0
- package/package.json +12 -3
- package/build/FigTreeEvaluator.d.ts +0 -26
- package/build/FigTreeEvaluator.js +0 -121
- package/build/cache.d.ts +0 -27
- package/build/cache.js +0 -63
- package/build/evaluate.d.ts +0 -2
- package/build/evaluate.js +0 -87
- package/build/helpers.d.ts +0 -23
- package/build/helpers.js +0 -137
- package/build/index.js +0 -29
- package/build/operators/AND/data.d.ts +0 -4
- package/build/operators/AND/data.js +0 -22
- package/build/operators/AND/index.d.ts +0 -1
- package/build/operators/AND/index.js +0 -5
- package/build/operators/AND/operator.d.ts +0 -3
- package/build/operators/AND/operator.js +0 -53
- package/build/operators/BUILD_OBJECT/data.d.ts +0 -4
- package/build/operators/BUILD_OBJECT/data.js +0 -22
- package/build/operators/BUILD_OBJECT/index.d.ts +0 -1
- package/build/operators/BUILD_OBJECT/index.js +0 -17
- package/build/operators/BUILD_OBJECT/operator.d.ts +0 -2
- package/build/operators/BUILD_OBJECT/operator.js +0 -64
- package/build/operators/CONDITIONAL/data.d.ts +0 -4
- package/build/operators/CONDITIONAL/data.js +0 -36
- package/build/operators/CONDITIONAL/index.d.ts +0 -1
- package/build/operators/CONDITIONAL/index.js +0 -17
- package/build/operators/CONDITIONAL/operator.d.ts +0 -2
- package/build/operators/CONDITIONAL/operator.js +0 -59
- package/build/operators/COUNT/data.d.ts +0 -4
- package/build/operators/COUNT/data.js +0 -22
- package/build/operators/COUNT/index.d.ts +0 -1
- package/build/operators/COUNT/index.js +0 -17
- package/build/operators/COUNT/operator.d.ts +0 -2
- package/build/operators/COUNT/operator.js +0 -52
- package/build/operators/CUSTOM_FUNCTIONS/data.d.ts +0 -4
- package/build/operators/CUSTOM_FUNCTIONS/data.js +0 -43
- package/build/operators/CUSTOM_FUNCTIONS/index.d.ts +0 -1
- package/build/operators/CUSTOM_FUNCTIONS/index.js +0 -17
- package/build/operators/CUSTOM_FUNCTIONS/operator.d.ts +0 -2
- package/build/operators/CUSTOM_FUNCTIONS/operator.js +0 -65
- package/build/operators/DIVIDE/data.d.ts +0 -4
- package/build/operators/DIVIDE/data.js +0 -43
- package/build/operators/DIVIDE/index.d.ts +0 -1
- package/build/operators/DIVIDE/index.js +0 -17
- package/build/operators/DIVIDE/operator.d.ts +0 -2
- package/build/operators/DIVIDE/operator.js +0 -63
- package/build/operators/EQUAL/data.d.ts +0 -4
- package/build/operators/EQUAL/data.js +0 -29
- package/build/operators/EQUAL/index.d.ts +0 -1
- package/build/operators/EQUAL/index.js +0 -17
- package/build/operators/EQUAL/operator.d.ts +0 -2
- package/build/operators/EQUAL/operator.js +0 -58
- package/build/operators/GET/data.d.ts +0 -4
- package/build/operators/GET/data.js +0 -50
- package/build/operators/GET/index.d.ts +0 -1
- package/build/operators/GET/index.js +0 -5
- package/build/operators/GET/operator.d.ts +0 -3
- package/build/operators/GET/operator.js +0 -91
- package/build/operators/GRAPHQL/data.d.ts +0 -4
- package/build/operators/GRAPHQL/data.js +0 -57
- package/build/operators/GRAPHQL/index.d.ts +0 -1
- package/build/operators/GRAPHQL/index.js +0 -17
- package/build/operators/GRAPHQL/operator.d.ts +0 -8
- package/build/operators/GRAPHQL/operator.js +0 -86
- package/build/operators/GREATER_THAN/data.d.ts +0 -4
- package/build/operators/GREATER_THAN/data.js +0 -29
- package/build/operators/GREATER_THAN/index.d.ts +0 -1
- package/build/operators/GREATER_THAN/index.js +0 -17
- package/build/operators/GREATER_THAN/operator.d.ts +0 -2
- package/build/operators/GREATER_THAN/operator.js +0 -54
- package/build/operators/LESS_THAN/data.d.ts +0 -4
- package/build/operators/LESS_THAN/data.js +0 -29
- package/build/operators/LESS_THAN/index.d.ts +0 -1
- package/build/operators/LESS_THAN/index.js +0 -17
- package/build/operators/LESS_THAN/operator.d.ts +0 -2
- package/build/operators/LESS_THAN/operator.js +0 -54
- package/build/operators/MATCH/data.d.ts +0 -4
- package/build/operators/MATCH/data.js +0 -29
- package/build/operators/MATCH/index.d.ts +0 -1
- package/build/operators/MATCH/index.js +0 -17
- package/build/operators/MATCH/operator.d.ts +0 -2
- package/build/operators/MATCH/operator.js +0 -72
- package/build/operators/MULTIPLY/data.d.ts +0 -4
- package/build/operators/MULTIPLY/data.js +0 -22
- package/build/operators/MULTIPLY/index.d.ts +0 -1
- package/build/operators/MULTIPLY/index.js +0 -17
- package/build/operators/MULTIPLY/operator.d.ts +0 -2
- package/build/operators/MULTIPLY/operator.js +0 -53
- package/build/operators/NOT_EQUAL/data.d.ts +0 -4
- package/build/operators/NOT_EQUAL/data.js +0 -29
- package/build/operators/NOT_EQUAL/index.d.ts +0 -1
- package/build/operators/NOT_EQUAL/index.js +0 -17
- package/build/operators/NOT_EQUAL/operator.d.ts +0 -2
- package/build/operators/NOT_EQUAL/operator.js +0 -58
- package/build/operators/OBJECT_PROPERTIES/data.d.ts +0 -4
- package/build/operators/OBJECT_PROPERTIES/data.js +0 -37
- package/build/operators/OBJECT_PROPERTIES/index.d.ts +0 -1
- package/build/operators/OBJECT_PROPERTIES/index.js +0 -17
- package/build/operators/OBJECT_PROPERTIES/operator.d.ts +0 -2
- package/build/operators/OBJECT_PROPERTIES/operator.js +0 -62
- package/build/operators/OR/data.d.ts +0 -4
- package/build/operators/OR/data.js +0 -22
- package/build/operators/OR/index.d.ts +0 -1
- package/build/operators/OR/index.js +0 -17
- package/build/operators/OR/operator.d.ts +0 -2
- package/build/operators/OR/operator.js +0 -49
- package/build/operators/PASSTHRU/data.d.ts +0 -4
- package/build/operators/PASSTHRU/data.js +0 -22
- package/build/operators/PASSTHRU/index.d.ts +0 -1
- package/build/operators/PASSTHRU/index.js +0 -17
- package/build/operators/PASSTHRU/operator.d.ts +0 -2
- package/build/operators/PASSTHRU/operator.js +0 -53
- package/build/operators/PG_SQL/data.d.ts +0 -4
- package/build/operators/PG_SQL/data.js +0 -43
- package/build/operators/PG_SQL/index.d.ts +0 -1
- package/build/operators/PG_SQL/index.js +0 -17
- package/build/operators/PG_SQL/operator.d.ts +0 -2
- package/build/operators/PG_SQL/operator.js +0 -83
- package/build/operators/PLUS/data.d.ts +0 -4
- package/build/operators/PLUS/data.js +0 -29
- package/build/operators/PLUS/index.d.ts +0 -1
- package/build/operators/PLUS/index.js +0 -17
- package/build/operators/PLUS/operator.d.ts +0 -2
- package/build/operators/PLUS/operator.js +0 -63
- package/build/operators/POST/data.d.ts +0 -4
- package/build/operators/POST/data.js +0 -50
- package/build/operators/POST/index.d.ts +0 -1
- package/build/operators/POST/index.js +0 -17
- package/build/operators/POST/operator.d.ts +0 -2
- package/build/operators/POST/operator.js +0 -72
- package/build/operators/REGEX/data.d.ts +0 -4
- package/build/operators/REGEX/data.js +0 -29
- package/build/operators/REGEX/index.d.ts +0 -1
- package/build/operators/REGEX/index.js +0 -17
- package/build/operators/REGEX/operator.d.ts +0 -2
- package/build/operators/REGEX/operator.js +0 -59
- package/build/operators/SPLIT/data.d.ts +0 -4
- package/build/operators/SPLIT/data.js +0 -43
- package/build/operators/SPLIT/index.d.ts +0 -1
- package/build/operators/SPLIT/index.js +0 -17
- package/build/operators/SPLIT/operator.d.ts +0 -2
- package/build/operators/SPLIT/operator.js +0 -69
- package/build/operators/STRING_SUBSTITUTION/data.d.ts +0 -4
- package/build/operators/STRING_SUBSTITUTION/data.js +0 -50
- package/build/operators/STRING_SUBSTITUTION/index.d.ts +0 -1
- package/build/operators/STRING_SUBSTITUTION/index.js +0 -17
- package/build/operators/STRING_SUBSTITUTION/operator.d.ts +0 -2
- package/build/operators/STRING_SUBSTITUTION/operator.js +0 -112
- package/build/operators/SUBTRACT/data.d.ts +0 -4
- package/build/operators/SUBTRACT/data.js +0 -36
- package/build/operators/SUBTRACT/index.d.ts +0 -1
- package/build/operators/SUBTRACT/index.js +0 -17
- package/build/operators/SUBTRACT/operator.d.ts +0 -2
- package/build/operators/SUBTRACT/operator.js +0 -54
- package/build/operators/_operatorAliases.json +0 -92
- package/build/operators/_operatorUtils.d.ts +0 -24
- package/build/operators/_operatorUtils.js +0 -122
- package/build/operators/index.d.ts +0 -24
- package/build/operators/index.js +0 -40
- package/build/shorthandSyntax.d.ts +0 -2
- package/build/shorthandSyntax.js +0 -55
- package/build/typeCheck.d.ts +0 -12
- package/build/typeCheck.js +0 -54
- package/build/types.d.ts +0 -96
- package/build/types.js +0 -29
- package/build/version.d.ts +0 -1
- package/build/version.js +0 -4
package/build/evaluate.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.evaluatorFunction = void 0;
|
|
13
|
-
const _operatorUtils_1 = require("./operators/_operatorUtils");
|
|
14
|
-
const shorthandSyntax_1 = require("./shorthandSyntax");
|
|
15
|
-
const helpers_1 = require("./helpers");
|
|
16
|
-
const evaluatorFunction = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
var _a, _b, _c, _d;
|
|
18
|
-
const { options, operators, operatorAliases } = config;
|
|
19
|
-
let expression = (options === null || options === void 0 ? void 0 : options.allowJSONStringInput) ? (0, helpers_1.parseIfJson)(input) : input;
|
|
20
|
-
expression = (0, shorthandSyntax_1.preProcessShorthand)(expression, (_a = config.options) === null || _a === void 0 ? void 0 : _a.fragments, !options.noShorthand);
|
|
21
|
-
if (Array.isArray(expression)) {
|
|
22
|
-
expression = yield (0, _operatorUtils_1.evaluateArray)(expression, config);
|
|
23
|
-
}
|
|
24
|
-
const isOperator = (0, helpers_1.isOperatorNode)(expression);
|
|
25
|
-
const isFragment = (0, helpers_1.isFragmentNode)(expression);
|
|
26
|
-
if (options.evaluateFullObject && !isOperator && !isFragment)
|
|
27
|
-
return (0, helpers_1.replaceAliasNodeValues)(yield (0, helpers_1.evaluateObject)(expression, config), config);
|
|
28
|
-
if (!isOperator && !isFragment) {
|
|
29
|
-
if (options.supportDeprecatedValueNodes && (0, helpers_1.isObject)(expression) && 'value' in expression)
|
|
30
|
-
return expression.value;
|
|
31
|
-
return (0, helpers_1.replaceAliasNodeValues)(expression, config);
|
|
32
|
-
}
|
|
33
|
-
const { fallback } = expression;
|
|
34
|
-
const returnErrorAsString = (_b = options === null || options === void 0 ? void 0 : options.returnErrorAsString) !== null && _b !== void 0 ? _b : false;
|
|
35
|
-
if (isFragment) {
|
|
36
|
-
const [fragment, parameters] = (yield (0, _operatorUtils_1.evaluateArray)([expression.fragment, expression.parameters], config));
|
|
37
|
-
const fragmentReplacement = (0, shorthandSyntax_1.preProcessShorthand)((_c = options === null || options === void 0 ? void 0 : options.fragments) === null || _c === void 0 ? void 0 : _c[fragment], options.fragments, !options.noShorthand);
|
|
38
|
-
if (fragmentReplacement === undefined)
|
|
39
|
-
return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Fragment not defined: ${fragment}`, returnErrorAsString);
|
|
40
|
-
if (!(0, helpers_1.isOperatorNode)(fragmentReplacement))
|
|
41
|
-
return (0, helpers_1.replaceAliasNodeValues)(fragmentReplacement, config);
|
|
42
|
-
expression = Object.assign(Object.assign(Object.assign({}, expression), fragmentReplacement), parameters);
|
|
43
|
-
delete expression.fragment;
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
const operator = (0, helpers_1.getOperatorName)(expression.operator, operatorAliases);
|
|
47
|
-
if (!operator)
|
|
48
|
-
return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Invalid operator: ${expression.operator}`, returnErrorAsString);
|
|
49
|
-
if (!config.operators[operator])
|
|
50
|
-
return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Excluded operator: ${expression.operator}`, returnErrorAsString);
|
|
51
|
-
const { propertyAliases, evaluate, parseChildren } = operators[operator];
|
|
52
|
-
expression = (0, helpers_1.mapPropertyAliases)(propertyAliases, expression);
|
|
53
|
-
const newAliasNodes = yield (0, helpers_1.evaluateNodeAliases)(expression, config);
|
|
54
|
-
if (!isFragment)
|
|
55
|
-
Object.entries(newAliasNodes).forEach(([alias, result]) => (config.resolvedAliasNodes[alias] = result));
|
|
56
|
-
const childConfig = isFragment
|
|
57
|
-
? Object.assign(Object.assign({}, config), { resolvedAliasNodes: Object.assign(Object.assign({}, config.resolvedAliasNodes), newAliasNodes) }) : config;
|
|
58
|
-
if ('children' in expression) {
|
|
59
|
-
if (!Array.isArray(expression.children))
|
|
60
|
-
expression.children = yield (0, exports.evaluatorFunction)(expression.children, childConfig);
|
|
61
|
-
if (!Array.isArray(expression.children))
|
|
62
|
-
return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Operator: ${operator}\n- Property "children" is not of type: array`, returnErrorAsString);
|
|
63
|
-
expression = yield parseChildren(expression, childConfig);
|
|
64
|
-
delete expression.children;
|
|
65
|
-
}
|
|
66
|
-
let result;
|
|
67
|
-
try {
|
|
68
|
-
result = yield evaluate(expression, childConfig);
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(expression.fallback, config), `Operator: ${operator}\n${(0, helpers_1.errorMessage)(err)}`, returnErrorAsString);
|
|
72
|
-
}
|
|
73
|
-
const outputType = (_d = expression === null || expression === void 0 ? void 0 : expression.outputType) !== null && _d !== void 0 ? _d : expression === null || expression === void 0 ? void 0 : expression.type;
|
|
74
|
-
if (!outputType)
|
|
75
|
-
return result;
|
|
76
|
-
const evaluatedOutputType = (yield (0, exports.evaluatorFunction)(outputType, config));
|
|
77
|
-
if (!(evaluatedOutputType in helpers_1.convertOutputMethods))
|
|
78
|
-
return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), `Operator: ${operator}\n- Invalid output type: ${evaluatedOutputType}`, returnErrorAsString);
|
|
79
|
-
else {
|
|
80
|
-
return helpers_1.convertOutputMethods[evaluatedOutputType](result);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
return (0, helpers_1.fallbackOrError)(yield (0, exports.evaluatorFunction)(fallback, config), (0, helpers_1.errorMessage)(err), returnErrorAsString);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
exports.evaluatorFunction = evaluatorFunction;
|
package/build/helpers.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { OutputType, EvaluatorNode, EvaluatorOutput, FigTreeOptions, FigTreeConfig, OperatorReference, OperatorAliases, Operator, FragmentNode, OperatorNode } from './types';
|
|
2
|
-
export declare const parseIfJson: (input: EvaluatorNode) => any;
|
|
3
|
-
export declare const isOperatorNode: (input: EvaluatorNode) => boolean;
|
|
4
|
-
export declare const isFragmentNode: (input: EvaluatorNode) => input is FragmentNode;
|
|
5
|
-
export declare const getOperatorName: (operator: string, operatorAliases: OperatorAliases) => Operator | undefined;
|
|
6
|
-
export declare const filterOperators: (operators: OperatorReference, exclusions: string[], operatorAliases: OperatorAliases) => OperatorReference;
|
|
7
|
-
export declare const truncateString: (string: string, length?: number) => string;
|
|
8
|
-
export declare const fallbackOrError: (fallback: EvaluatorOutput, errorMessage: string, returnErrorAsString?: boolean) => string | number | boolean | object | null;
|
|
9
|
-
export declare const mapPropertyAliases: (propertyAliases: {
|
|
10
|
-
[key: string]: string;
|
|
11
|
-
}, expression: OperatorNode) => OperatorNode;
|
|
12
|
-
export declare const isAliasString: (value: string) => boolean;
|
|
13
|
-
export declare const evaluateNodeAliases: (expression: OperatorNode, config: FigTreeConfig) => Promise<{
|
|
14
|
-
[x: string]: EvaluatorOutput;
|
|
15
|
-
}>;
|
|
16
|
-
export declare const replaceAliasNodeValues: (value: EvaluatorOutput, { resolvedAliasNodes }: FigTreeConfig) => EvaluatorOutput;
|
|
17
|
-
export declare const mergeOptions: (origOptions: FigTreeOptions, newOptions: FigTreeOptions) => FigTreeOptions;
|
|
18
|
-
export declare const convertOutputMethods: {
|
|
19
|
-
[key in OutputType]: (value: EvaluatorOutput) => EvaluatorOutput | EvaluatorOutput[];
|
|
20
|
-
};
|
|
21
|
-
export declare const errorMessage: (err: unknown) => string;
|
|
22
|
-
export declare const isObject: (input: unknown) => input is object;
|
|
23
|
-
export declare const evaluateObject: (input: EvaluatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
|
package/build/helpers.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.evaluateObject = exports.isObject = exports.errorMessage = exports.convertOutputMethods = exports.mergeOptions = exports.replaceAliasNodeValues = exports.evaluateNodeAliases = exports.isAliasString = exports.mapPropertyAliases = exports.fallbackOrError = exports.truncateString = exports.filterOperators = exports.getOperatorName = exports.isFragmentNode = exports.isOperatorNode = exports.parseIfJson = void 0;
|
|
13
|
-
const change_case_1 = require("change-case");
|
|
14
|
-
const evaluate_1 = require("./evaluate");
|
|
15
|
-
const _operatorUtils_1 = require("./operators/_operatorUtils");
|
|
16
|
-
const parseIfJson = (input) => {
|
|
17
|
-
if (typeof input !== 'string')
|
|
18
|
-
return input;
|
|
19
|
-
try {
|
|
20
|
-
const parsedInput = JSON.parse(input);
|
|
21
|
-
return (0, exports.isOperatorNode)(parsedInput) ? parsedInput : input;
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
return input;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
exports.parseIfJson = parseIfJson;
|
|
28
|
-
const isOperatorNode = (input) => input instanceof Object && 'operator' in input;
|
|
29
|
-
exports.isOperatorNode = isOperatorNode;
|
|
30
|
-
const isFragmentNode = (input) => input instanceof Object && 'fragment' in input;
|
|
31
|
-
exports.isFragmentNode = isFragmentNode;
|
|
32
|
-
const standardiseOperatorName = (name) => {
|
|
33
|
-
const camelCaseName = (0, change_case_1.camelCase)(name);
|
|
34
|
-
return camelCaseName ? camelCaseName : name;
|
|
35
|
-
};
|
|
36
|
-
const getOperatorName = (operator, operatorAliases) => operatorAliases[standardiseOperatorName(operator)];
|
|
37
|
-
exports.getOperatorName = getOperatorName;
|
|
38
|
-
const filterOperators = (operators, exclusions, operatorAliases) => {
|
|
39
|
-
const filteredOperators = Object.assign({}, operators);
|
|
40
|
-
exclusions.forEach((exclusion) => {
|
|
41
|
-
const operator = operatorAliases[standardiseOperatorName(exclusion)];
|
|
42
|
-
if (!operator)
|
|
43
|
-
console.warn(`Invalid operator exclusion: ${exclusion}`);
|
|
44
|
-
delete filteredOperators[operatorAliases[standardiseOperatorName(exclusion)]];
|
|
45
|
-
});
|
|
46
|
-
return filteredOperators;
|
|
47
|
-
};
|
|
48
|
-
exports.filterOperators = filterOperators;
|
|
49
|
-
const truncateString = (string, length = 200) => string.length < length ? string : `${string.slice(0, length - 2).trim()}...`;
|
|
50
|
-
exports.truncateString = truncateString;
|
|
51
|
-
const fallbackOrError = (fallback, errorMessage, returnErrorAsString = false) => {
|
|
52
|
-
if (fallback !== undefined)
|
|
53
|
-
return fallback;
|
|
54
|
-
if (returnErrorAsString)
|
|
55
|
-
return (0, exports.truncateString)(errorMessage);
|
|
56
|
-
else
|
|
57
|
-
throw new Error((0, exports.truncateString)(errorMessage));
|
|
58
|
-
};
|
|
59
|
-
exports.fallbackOrError = fallbackOrError;
|
|
60
|
-
const mapPropertyAliases = (propertyAliases, expression) => mapObjectKeys(expression, (key) => key in propertyAliases ? propertyAliases[key] : key);
|
|
61
|
-
exports.mapPropertyAliases = mapPropertyAliases;
|
|
62
|
-
const mapObjectKeys = (inputObj, mapFunction) => {
|
|
63
|
-
const keyVals = Object.entries(inputObj);
|
|
64
|
-
const mappedKeys = keyVals.map(([key, value]) => [mapFunction(key), value]);
|
|
65
|
-
return Object.fromEntries(mappedKeys);
|
|
66
|
-
};
|
|
67
|
-
const isAliasString = (value) => /^\$.+/.test(value);
|
|
68
|
-
exports.isAliasString = isAliasString;
|
|
69
|
-
const evaluateNodeAliases = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
-
const aliasKeys = Object.keys(expression).filter(exports.isAliasString);
|
|
71
|
-
if (aliasKeys.length === 0)
|
|
72
|
-
return {};
|
|
73
|
-
const evaluations = [];
|
|
74
|
-
aliasKeys.forEach((alias) => evaluations.push((0, evaluate_1.evaluatorFunction)(expression[alias], config)));
|
|
75
|
-
return (0, _operatorUtils_1.zipArraysToObject)(aliasKeys, yield Promise.all(evaluations));
|
|
76
|
-
});
|
|
77
|
-
exports.evaluateNodeAliases = evaluateNodeAliases;
|
|
78
|
-
const replaceAliasNodeValues = (value, { resolvedAliasNodes }) => {
|
|
79
|
-
var _a;
|
|
80
|
-
if (typeof value !== 'string' || !(0, exports.isAliasString)(value))
|
|
81
|
-
return value;
|
|
82
|
-
return (_a = resolvedAliasNodes === null || resolvedAliasNodes === void 0 ? void 0 : resolvedAliasNodes[value]) !== null && _a !== void 0 ? _a : value;
|
|
83
|
-
};
|
|
84
|
-
exports.replaceAliasNodeValues = replaceAliasNodeValues;
|
|
85
|
-
const mergeOptions = (origOptions, newOptions) => {
|
|
86
|
-
const combinedOptions = Object.assign(Object.assign({}, origOptions), newOptions);
|
|
87
|
-
if (origOptions.data || newOptions.data)
|
|
88
|
-
combinedOptions.data = Object.assign(Object.assign({}, origOptions.data), newOptions.data);
|
|
89
|
-
if (origOptions.functions || newOptions.functions)
|
|
90
|
-
combinedOptions.functions = Object.assign(Object.assign({}, origOptions.functions), newOptions.functions);
|
|
91
|
-
if (origOptions.fragments || newOptions.fragments)
|
|
92
|
-
combinedOptions.fragments = Object.assign(Object.assign({}, origOptions.fragments), newOptions.fragments);
|
|
93
|
-
if (origOptions.headers || newOptions.headers)
|
|
94
|
-
combinedOptions.headers = Object.assign(Object.assign({}, origOptions.headers), newOptions.headers);
|
|
95
|
-
return combinedOptions;
|
|
96
|
-
};
|
|
97
|
-
exports.mergeOptions = mergeOptions;
|
|
98
|
-
exports.convertOutputMethods = {
|
|
99
|
-
number: (value) => extractNumber(value),
|
|
100
|
-
string: (value) => String(value),
|
|
101
|
-
array: (value) => (Array.isArray(value) ? value : [value]),
|
|
102
|
-
boolean: (value) => Boolean(value),
|
|
103
|
-
bool: (value) => Boolean(value),
|
|
104
|
-
};
|
|
105
|
-
const errorMessage = (err) => err.message;
|
|
106
|
-
exports.errorMessage = errorMessage;
|
|
107
|
-
const extractNumber = (input) => {
|
|
108
|
-
if (typeof input !== 'string')
|
|
109
|
-
return Number.isNaN(Number(input)) ? input : Number(input);
|
|
110
|
-
const pattern = new RegExp(/-?\d*\.?\d+/gm);
|
|
111
|
-
const numberMatch = input.match(pattern);
|
|
112
|
-
if (!numberMatch)
|
|
113
|
-
return 0;
|
|
114
|
-
return Number(numberMatch[0]);
|
|
115
|
-
};
|
|
116
|
-
const isObject = (input) => typeof input === 'object' && input !== null && !Array.isArray(input);
|
|
117
|
-
exports.isObject = isObject;
|
|
118
|
-
const evaluateObject = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
-
if (!(0, exports.isObject)(input))
|
|
120
|
-
return input;
|
|
121
|
-
const newObjectEntries = [];
|
|
122
|
-
const newAliases = [];
|
|
123
|
-
Object.entries(input).forEach(([key, value]) => {
|
|
124
|
-
if ((0, exports.isAliasString)(key)) {
|
|
125
|
-
newAliases.push(key, (0, evaluate_1.evaluatorFunction)(value, config));
|
|
126
|
-
delete input[key];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
const aliasArray = yield Promise.all(newAliases);
|
|
130
|
-
config.resolvedAliasNodes = Object.assign(Object.assign({}, config.resolvedAliasNodes), (0, _operatorUtils_1.singleArrayToObject)(aliasArray));
|
|
131
|
-
Object.entries(input).forEach(([key, value]) => {
|
|
132
|
-
newObjectEntries.push(key, (0, evaluate_1.evaluatorFunction)(value, config));
|
|
133
|
-
});
|
|
134
|
-
const results = yield Promise.all(newObjectEntries);
|
|
135
|
-
return (0, exports.replaceAliasNodeValues)((0, _operatorUtils_1.singleArrayToObject)(results), config);
|
|
136
|
-
});
|
|
137
|
-
exports.evaluateObject = evaluateObject;
|
package/build/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.evaluateExpression = void 0;
|
|
27
|
-
const FigTreeEvaluator_1 = __importStar(require("./FigTreeEvaluator"));
|
|
28
|
-
Object.defineProperty(exports, "evaluateExpression", { enumerable: true, get: function () { return FigTreeEvaluator_1.evaluateExpression; } });
|
|
29
|
-
exports.default = FigTreeEvaluator_1.default;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases = void 0;
|
|
4
|
-
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
|
-
const description = 'Logical AND';
|
|
6
|
-
const aliases = ['and', '&', '&&'];
|
|
7
|
-
const parameters = [
|
|
8
|
-
{
|
|
9
|
-
name: 'values',
|
|
10
|
-
description: 'Returns true if all values are true',
|
|
11
|
-
aliases: [],
|
|
12
|
-
required: true,
|
|
13
|
-
type: 'array',
|
|
14
|
-
},
|
|
15
|
-
];
|
|
16
|
-
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
17
|
-
const operatorData = {
|
|
18
|
-
description,
|
|
19
|
-
aliases,
|
|
20
|
-
parameters,
|
|
21
|
-
};
|
|
22
|
-
exports.default = operatorData;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { AND } from './operator';
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.AND = exports.parseChildren = void 0;
|
|
36
|
-
const _operatorUtils_1 = require("../_operatorUtils");
|
|
37
|
-
const data_1 = __importStar(require("./data"));
|
|
38
|
-
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
const values = (yield (0, _operatorUtils_1.evaluateArray)(expression.values, config));
|
|
40
|
-
config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { values }));
|
|
41
|
-
return values.reduce((acc, val) => acc && !!val, true);
|
|
42
|
-
});
|
|
43
|
-
const parseChildren = (expression) => {
|
|
44
|
-
const values = expression.children;
|
|
45
|
-
return Object.assign(Object.assign({}, expression), { values });
|
|
46
|
-
};
|
|
47
|
-
exports.parseChildren = parseChildren;
|
|
48
|
-
exports.AND = {
|
|
49
|
-
propertyAliases: data_1.propertyAliases,
|
|
50
|
-
operatorData: data_1.default,
|
|
51
|
-
evaluate,
|
|
52
|
-
parseChildren: exports.parseChildren,
|
|
53
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases = void 0;
|
|
4
|
-
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
|
-
const aliases = ['buildObject', 'build', 'object'];
|
|
6
|
-
const description = 'Construct an object using objects defining keys and values';
|
|
7
|
-
const parameters = [
|
|
8
|
-
{
|
|
9
|
-
name: 'properties',
|
|
10
|
-
description: 'An array of objects, each with a "key" property and a "value" property',
|
|
11
|
-
aliases: ['values', 'keyValPairs', 'keyValuePairs'],
|
|
12
|
-
required: true,
|
|
13
|
-
type: 'array',
|
|
14
|
-
},
|
|
15
|
-
];
|
|
16
|
-
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
17
|
-
const operatorData = {
|
|
18
|
-
description,
|
|
19
|
-
aliases,
|
|
20
|
-
parameters,
|
|
21
|
-
};
|
|
22
|
-
exports.default = operatorData;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './operator';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./operator"), exports);
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.BUILD_OBJECT = void 0;
|
|
36
|
-
const _operatorUtils_1 = require("../_operatorUtils");
|
|
37
|
-
const data_1 = __importStar(require("./data"));
|
|
38
|
-
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
const evaluatePair = (nodes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
const [key, value] = (yield (0, _operatorUtils_1.evaluateArray)(nodes, config));
|
|
41
|
-
config.typeChecker({ name: 'key', value: key, expectedType: ['string', 'number', 'boolean'] });
|
|
42
|
-
return [key, value];
|
|
43
|
-
});
|
|
44
|
-
config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, { properties: expression.properties }));
|
|
45
|
-
const evaluated = expression.properties
|
|
46
|
-
.filter((element) => element instanceof Object && 'key' in element && 'value' in element)
|
|
47
|
-
.map(({ key, value }) => evaluatePair([key, value]));
|
|
48
|
-
return Object.fromEntries(yield Promise.all(evaluated));
|
|
49
|
-
});
|
|
50
|
-
const parseChildren = (expression) => {
|
|
51
|
-
const elements = expression.children;
|
|
52
|
-
if (elements.length % 2 !== 0)
|
|
53
|
-
throw new Error('Even number of children required to make key/value pairs');
|
|
54
|
-
const keys = elements.filter((_, index) => index % 2 === 0);
|
|
55
|
-
const values = elements.filter((_, index) => index % 2 === 1);
|
|
56
|
-
const properties = keys.map((key, index) => ({ key, value: values[index] }));
|
|
57
|
-
return Object.assign(Object.assign({}, expression), { properties });
|
|
58
|
-
};
|
|
59
|
-
exports.BUILD_OBJECT = {
|
|
60
|
-
propertyAliases: data_1.propertyAliases,
|
|
61
|
-
operatorData: data_1.default,
|
|
62
|
-
evaluate,
|
|
63
|
-
parseChildren,
|
|
64
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyAliases = void 0;
|
|
4
|
-
const _operatorUtils_1 = require("../_operatorUtils");
|
|
5
|
-
const description = 'Return a value based on a condition';
|
|
6
|
-
const aliases = ['?', 'conditional', 'ifThen'];
|
|
7
|
-
const parameters = [
|
|
8
|
-
{
|
|
9
|
-
name: 'condition',
|
|
10
|
-
description: 'The expression to check for truthiness',
|
|
11
|
-
aliases: [],
|
|
12
|
-
required: true,
|
|
13
|
-
type: 'any',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
name: 'valueIfTrue',
|
|
17
|
-
description: 'Value to return if condition is true',
|
|
18
|
-
aliases: ['ifTrue'],
|
|
19
|
-
required: true,
|
|
20
|
-
type: 'any',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
name: 'valueIfFalse',
|
|
24
|
-
description: 'Value to return if condition is false',
|
|
25
|
-
aliases: ['ifFalse', 'ifNot'],
|
|
26
|
-
required: true,
|
|
27
|
-
type: 'any',
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
exports.propertyAliases = (0, _operatorUtils_1.getPropertyAliases)(parameters);
|
|
31
|
-
const operatorData = {
|
|
32
|
-
description,
|
|
33
|
-
aliases,
|
|
34
|
-
parameters,
|
|
35
|
-
};
|
|
36
|
-
exports.default = operatorData;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './operator';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./operator"), exports);
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.CONDITIONAL = void 0;
|
|
36
|
-
const evaluate_1 = require("../../evaluate");
|
|
37
|
-
const _operatorUtils_1 = require("../_operatorUtils");
|
|
38
|
-
const data_1 = __importStar(require("./data"));
|
|
39
|
-
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
config.typeChecker((0, _operatorUtils_1.getTypeCheckInput)(data_1.default.parameters, {
|
|
41
|
-
condition: expression.condition,
|
|
42
|
-
valueIfTrue: expression.valueIfTrue,
|
|
43
|
-
valueIfFalse: expression.valueIfFalse,
|
|
44
|
-
}));
|
|
45
|
-
const condition = yield (0, evaluate_1.evaluatorFunction)(expression.condition, config);
|
|
46
|
-
return condition
|
|
47
|
-
? yield (0, evaluate_1.evaluatorFunction)(expression.valueIfTrue, config)
|
|
48
|
-
: yield (0, evaluate_1.evaluatorFunction)(expression.valueIfFalse, config);
|
|
49
|
-
});
|
|
50
|
-
const parseChildren = (expression) => {
|
|
51
|
-
const [condition, valueIfTrue, valueIfFalse] = expression.children;
|
|
52
|
-
return Object.assign(Object.assign({}, expression), { condition, valueIfTrue, valueIfFalse });
|
|
53
|
-
};
|
|
54
|
-
exports.CONDITIONAL = {
|
|
55
|
-
propertyAliases: data_1.propertyAliases,
|
|
56
|
-
operatorData: data_1.default,
|
|
57
|
-
evaluate,
|
|
58
|
-
parseChildren,
|
|
59
|
-
};
|