fig-tree-evaluator 1.9.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.
Files changed (70) hide show
  1. package/README.md +1233 -0
  2. package/build/.DS_Store +0 -0
  3. package/build/FigTreeEvaluator.d.ts +13 -0
  4. package/build/FigTreeEvaluator.js +75 -0
  5. package/build/evaluate.d.ts +2 -0
  6. package/build/evaluate.js +63 -0
  7. package/build/evaluator.d.ts +13 -0
  8. package/build/evaluator.js +75 -0
  9. package/build/helpers.d.ts +16 -0
  10. package/build/helpers.js +63 -0
  11. package/build/index.d.ts +13 -0
  12. package/build/index.js +75 -0
  13. package/build/operators/_operatorAliases.json +86 -0
  14. package/build/operators/_operatorUtils.d.ts +16 -0
  15. package/build/operators/_operatorUtils.js +83 -0
  16. package/build/operators/buildObject.d.ts +11 -0
  17. package/build/operators/buildObject.js +48 -0
  18. package/build/operators/conditional.d.ts +7 -0
  19. package/build/operators/conditional.js +31 -0
  20. package/build/operators/count.d.ts +2 -0
  21. package/build/operators/count.js +29 -0
  22. package/build/operators/customFunctions.d.ts +9 -0
  23. package/build/operators/customFunctions.js +53 -0
  24. package/build/operators/divide.d.ts +11 -0
  25. package/build/operators/divide.js +42 -0
  26. package/build/operators/equal.d.ts +2 -0
  27. package/build/operators/equal.js +29 -0
  28. package/build/operators/getRequest.d.ts +12 -0
  29. package/build/operators/getRequest.js +47 -0
  30. package/build/operators/graphQL.d.ts +18 -0
  31. package/build/operators/graphQL.js +55 -0
  32. package/build/operators/greaterThan.d.ts +6 -0
  33. package/build/operators/greaterThan.js +35 -0
  34. package/build/operators/index.d.ts +23 -0
  35. package/build/operators/index.js +39 -0
  36. package/build/operators/lessThan.d.ts +2 -0
  37. package/build/operators/lessThan.js +35 -0
  38. package/build/operators/logicalAnd.d.ts +8 -0
  39. package/build/operators/logicalAnd.js +33 -0
  40. package/build/operators/logicalOr.d.ts +2 -0
  41. package/build/operators/logicalOr.js +29 -0
  42. package/build/operators/multiply.d.ts +2 -0
  43. package/build/operators/multiply.js +29 -0
  44. package/build/operators/notEqual.d.ts +2 -0
  45. package/build/operators/notEqual.js +29 -0
  46. package/build/operators/objectFunctions.d.ts +9 -0
  47. package/build/operators/objectFunctions.js +38 -0
  48. package/build/operators/objectProperties.d.ts +9 -0
  49. package/build/operators/objectProperties.js +44 -0
  50. package/build/operators/passThru.d.ts +7 -0
  51. package/build/operators/passThru.js +30 -0
  52. package/build/operators/pgSQL.d.ts +24 -0
  53. package/build/operators/pgSQL.js +66 -0
  54. package/build/operators/plus.d.ts +10 -0
  55. package/build/operators/plus.js +39 -0
  56. package/build/operators/postRequest.d.ts +2 -0
  57. package/build/operators/postRequest.js +39 -0
  58. package/build/operators/regex.d.ts +7 -0
  59. package/build/operators/regex.js +46 -0
  60. package/build/operators/split.d.ts +11 -0
  61. package/build/operators/split.js +51 -0
  62. package/build/operators/stringSubstitution.d.ts +7 -0
  63. package/build/operators/stringSubstitution.js +40 -0
  64. package/build/operators/subtract.d.ts +9 -0
  65. package/build/operators/subtract.js +32 -0
  66. package/build/typeCheck.d.ts +9 -0
  67. package/build/typeCheck.js +48 -0
  68. package/build/types.d.ts +53 -0
  69. package/build/types.js +28 -0
  70. package/package.json +45 -0
@@ -0,0 +1,2 @@
1
+ import { OperatorObject } from '../types';
2
+ export declare const MULTIPLY: OperatorObject;
@@ -0,0 +1,29 @@
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.MULTIPLY = void 0;
13
+ const logicalAnd_1 = require("./logicalAnd");
14
+ const _operatorUtils_1 = require("./_operatorUtils");
15
+ const requiredProperties = ['values'];
16
+ const operatorAliases = ['*', 'x', 'multiply', 'times'];
17
+ const propertyAliases = {};
18
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const values = (yield (0, _operatorUtils_1.evaluateArray)(expression.values, config));
20
+ config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
21
+ return values.reduce((acc, number) => acc * number);
22
+ });
23
+ exports.MULTIPLY = {
24
+ requiredProperties,
25
+ operatorAliases,
26
+ propertyAliases,
27
+ evaluate,
28
+ parseChildren: logicalAnd_1.parseChildren,
29
+ };
@@ -0,0 +1,2 @@
1
+ import { OperatorObject } from '../types';
2
+ export declare const NOT_EQUAL: OperatorObject;
@@ -0,0 +1,29 @@
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.NOT_EQUAL = void 0;
13
+ const logicalAnd_1 = require("./logicalAnd");
14
+ const _operatorUtils_1 = require("./_operatorUtils");
15
+ const requiredProperties = ['values'];
16
+ const operatorAliases = ['!=', '!', 'ne', 'notEqual'];
17
+ const propertyAliases = {};
18
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const values = (yield (0, _operatorUtils_1.evaluateArray)(expression.values, config));
20
+ config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
21
+ return values.some((val) => val !== values[0]);
22
+ });
23
+ exports.NOT_EQUAL = {
24
+ requiredProperties,
25
+ operatorAliases,
26
+ propertyAliases,
27
+ evaluate,
28
+ parseChildren: logicalAnd_1.parseChildren,
29
+ };
@@ -0,0 +1,9 @@
1
+ import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../types';
2
+ declare const requiredProperties: readonly ["functionPath"];
3
+ export declare type ObjFuncNode = {
4
+ [key in typeof requiredProperties[number]]: EvaluatorNode;
5
+ } & BaseOperatorNode & {
6
+ args: EvaluatorNode[];
7
+ };
8
+ export declare const OBJECT_FUNCTIONS: OperatorObject;
9
+ export {};
@@ -0,0 +1,38 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OBJECT_FUNCTIONS = void 0;
16
+ const object_property_extractor_1 = __importDefault(require("object-property-extractor"));
17
+ const _operatorUtils_1 = require("./_operatorUtils");
18
+ const requiredProperties = ['functionPath'];
19
+ const operatorAliases = ['objectFunctions', 'function', 'functions', 'runFunction'];
20
+ const propertyAliases = { functionsPath: 'functionPath', arguments: 'args', variables: 'args' };
21
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
22
+ var _a, _b;
23
+ const [functionPath, ...args] = (yield _operatorUtils_1.evaluateArray([expression.functionPath, ...expression.args], config));
24
+ const inputObject = (_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.objects) !== null && _b !== void 0 ? _b : {};
25
+ const func = object_property_extractor_1.default(inputObject, functionPath);
26
+ return yield func(...args);
27
+ });
28
+ const parseChildren = (expression) => {
29
+ const [functionPath, ...args] = expression.children;
30
+ return Object.assign(Object.assign({}, expression), { functionPath, args });
31
+ };
32
+ exports.OBJECT_FUNCTIONS = {
33
+ requiredProperties,
34
+ operatorAliases,
35
+ propertyAliases,
36
+ evaluate,
37
+ parseChildren,
38
+ };
@@ -0,0 +1,9 @@
1
+ import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../types';
2
+ declare const requiredProperties: string[];
3
+ export declare type ObjPropNode = {
4
+ [key in typeof requiredProperties[number]]: EvaluatorNode;
5
+ } & BaseOperatorNode & {
6
+ additionalObjects: object;
7
+ };
8
+ export declare const OBJECT_PROPERTIES: OperatorObject;
9
+ export {};
@@ -0,0 +1,44 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OBJECT_PROPERTIES = void 0;
16
+ const object_property_extractor_1 = __importDefault(require("object-property-extractor"));
17
+ const _operatorUtils_1 = require("./_operatorUtils");
18
+ const requiredProperties = ['property'];
19
+ const operatorAliases = ['objectProperties', 'objProps', 'getProperty', 'getObjProp'];
20
+ const propertyAliases = {
21
+ path: 'property',
22
+ propertyName: 'property',
23
+ additional: 'additionalObjects',
24
+ objects: 'additionalObjects',
25
+ };
26
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
27
+ var _a, _b, _c, _d;
28
+ const [property, additionalObjects] = (yield (0, _operatorUtils_1.evaluateArray)([expression.property, expression.additionalObjects], config));
29
+ config.typeChecker({ name: 'property', value: property, expectedType: 'string' }, { name: 'additionalObjects', value: additionalObjects, expectedType: ['object', 'undefined'] });
30
+ const inputObject = additionalObjects
31
+ ? Object.assign(Object.assign({}, ((_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.objects) !== null && _b !== void 0 ? _b : {})), additionalObjects) : (_d = (_c = config.options) === null || _c === void 0 ? void 0 : _c.objects) !== null && _d !== void 0 ? _d : {};
32
+ return (0, object_property_extractor_1.default)(inputObject, property);
33
+ });
34
+ const parseChildren = (expression) => {
35
+ const [property, fallback] = expression.children;
36
+ return Object.assign(Object.assign({}, expression), { property, fallback });
37
+ };
38
+ exports.OBJECT_PROPERTIES = {
39
+ requiredProperties,
40
+ operatorAliases,
41
+ propertyAliases,
42
+ evaluate,
43
+ parseChildren,
44
+ };
@@ -0,0 +1,7 @@
1
+ import { OperatorObject, EvaluatorNode, BaseOperatorNode } from '../types';
2
+ declare const requiredProperties: readonly ["value"];
3
+ export declare type PassThruNode = {
4
+ [key in typeof requiredProperties[number]]: EvaluatorNode[];
5
+ } & BaseOperatorNode;
6
+ export declare const PASSTHRU: OperatorObject;
7
+ export {};
@@ -0,0 +1,30 @@
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.PASSTHRU = void 0;
13
+ const evaluate_1 = require("../evaluate");
14
+ const requiredProperties = ['value'];
15
+ const operatorAliases = ['_', 'passThru', 'pass', 'ignore', 'coerce', 'convert'];
16
+ const propertyAliases = { _: 'value', data: 'value' };
17
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
18
+ return yield (0, evaluate_1.evaluatorFunction)(expression.value, config);
19
+ });
20
+ const parseChildren = (expression) => {
21
+ const [...children] = expression.children;
22
+ return Object.assign(Object.assign({}, expression), { value: children });
23
+ };
24
+ exports.PASSTHRU = {
25
+ requiredProperties,
26
+ operatorAliases,
27
+ propertyAliases,
28
+ evaluate,
29
+ parseChildren,
30
+ };
@@ -0,0 +1,24 @@
1
+ import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../types';
2
+ declare const requiredProperties: readonly ["query"];
3
+ export declare 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
+ }
23
+ export declare const PG_SQL: OperatorObject;
24
+ export {};
@@ -0,0 +1,66 @@
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.PG_SQL = void 0;
13
+ const _operatorUtils_1 = require("./_operatorUtils");
14
+ const requiredProperties = ['query'];
15
+ const operatorAliases = ['pgSql', 'sql', 'postgres', 'pg', 'pgDb'];
16
+ const propertyAliases = { replacements: 'values' };
17
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
18
+ var _a;
19
+ const [query, ...values] = (yield (0, _operatorUtils_1.evaluateArray)([expression.query, ...(expression.values || [])], config));
20
+ config.typeChecker({ name: 'query', value: query, expectedType: 'string' }, { name: 'values', value: values, expectedType: 'array' });
21
+ if (!((_a = config.options) === null || _a === void 0 ? void 0 : _a.pgConnection))
22
+ throw new Error('No Postgres database connection provided');
23
+ try {
24
+ return yield processPgSQL([query, ...values], config.options.pgConnection, expression === null || expression === void 0 ? void 0 : expression.type);
25
+ }
26
+ catch (err) {
27
+ throw err;
28
+ }
29
+ });
30
+ const parseChildren = (expression) => {
31
+ const [query, ...values] = expression.children;
32
+ return Object.assign(Object.assign({}, expression), { query, values });
33
+ };
34
+ const processPgSQL = (queryArray, connection, queryType) => __awaiter(void 0, void 0, void 0, function* () {
35
+ const expression = {
36
+ text: queryArray[0],
37
+ values: queryArray.slice(1),
38
+ rowMode: queryType ? 'array' : '',
39
+ };
40
+ try {
41
+ const res = yield connection.query(expression);
42
+ if (res === null || res === void 0 ? void 0 : res.error)
43
+ throw new Error(res.error);
44
+ switch (queryType) {
45
+ case 'array':
46
+ return res.rows.flat();
47
+ case 'string':
48
+ return res.rows.flat().join(' ');
49
+ case 'number':
50
+ const result = res.rows.flat();
51
+ return Number.isNaN(Number(result)) ? result : Number(result);
52
+ default:
53
+ return res.rows;
54
+ }
55
+ }
56
+ catch (err) {
57
+ throw err;
58
+ }
59
+ });
60
+ exports.PG_SQL = {
61
+ requiredProperties,
62
+ operatorAliases,
63
+ propertyAliases,
64
+ evaluate,
65
+ parseChildren,
66
+ };
@@ -0,0 +1,10 @@
1
+ import { OperatorObject, EvaluatorNode } from '../types';
2
+ import { BasicExtendedNode } from './logicalAnd';
3
+ declare const requiredProperties: readonly ["values"];
4
+ export declare type AdditionNode = {
5
+ [key in typeof requiredProperties[number]]: EvaluatorNode;
6
+ } & BasicExtendedNode & {
7
+ type?: 'string' | 'array';
8
+ };
9
+ export declare const PLUS: OperatorObject;
10
+ export {};
@@ -0,0 +1,39 @@
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.PLUS = void 0;
13
+ const _operatorUtils_1 = require("./_operatorUtils");
14
+ const logicalAnd_1 = require("./logicalAnd");
15
+ const requiredProperties = ['values'];
16
+ const operatorAliases = ['+', 'plus', 'add', 'concat', 'join', 'merge'];
17
+ const propertyAliases = {};
18
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
19
+ if (expression.values.length === 0)
20
+ return expression.values;
21
+ const values = (yield (0, _operatorUtils_1.evaluateArray)(expression.values, config));
22
+ config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
23
+ if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'string')
24
+ return values.reduce((acc, child) => acc.concat(child), '');
25
+ if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'array')
26
+ return values.reduce((acc, child) => acc.concat(child), []);
27
+ if (values.every((child) => typeof child === 'string' || Array.isArray(child)))
28
+ return values.reduce((acc, child) => acc.concat(child));
29
+ if (values.every((child) => child instanceof Object && !Array.isArray(child)))
30
+ return values.reduce((acc, child) => (Object.assign(Object.assign({}, acc), child)), {});
31
+ return values.reduce((acc, child) => acc + child);
32
+ });
33
+ exports.PLUS = {
34
+ requiredProperties,
35
+ operatorAliases,
36
+ propertyAliases,
37
+ evaluate,
38
+ parseChildren: logicalAnd_1.parseChildren,
39
+ };
@@ -0,0 +1,2 @@
1
+ import { OperatorObject } from '../types';
2
+ export declare const POST: OperatorObject;
@@ -0,0 +1,39 @@
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.POST = void 0;
13
+ const _operatorUtils_1 = require("./_operatorUtils");
14
+ const getRequest_1 = require("./getRequest");
15
+ const requiredProperties = ['url'];
16
+ const operatorAliases = ['post'];
17
+ const propertyAliases = { endpoint: 'url', outputProperty: 'returnProperty' };
18
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
19
+ var _a, _b;
20
+ const [urlObj, data, returnProperty, headers] = (yield (0, _operatorUtils_1.evaluateArray)([expression.url, expression.parameters, expression.returnProperty, expression.headers], config));
21
+ const { url, headers: headersObj } = urlObj instanceof Object ? urlObj : { url: urlObj, headers: null };
22
+ config.typeChecker({ name: 'url', value: url, expectedType: 'string' }, { name: 'headers', value: headersObj, expectedType: ['object', 'null'] }, { name: 'data', value: data, expectedType: ['object', 'undefined'] }, { name: 'returnProperty', value: returnProperty, expectedType: ['string', 'undefined'] });
23
+ const baseUrl = (_a = config.options.baseEndpoint) !== null && _a !== void 0 ? _a : '';
24
+ const httpHeaders = Object.assign(Object.assign(Object.assign({}, (_b = config.options) === null || _b === void 0 ? void 0 : _b.headers), headersObj), headers);
25
+ const response = yield (0, _operatorUtils_1.axiosRequest)({
26
+ url: (0, _operatorUtils_1.isFullUrl)(url) ? url : (0, _operatorUtils_1.joinUrlParts)(baseUrl, url),
27
+ data,
28
+ headers: httpHeaders,
29
+ method: 'post',
30
+ });
31
+ return (0, _operatorUtils_1.extractAndSimplify)(response, returnProperty);
32
+ });
33
+ exports.POST = {
34
+ requiredProperties,
35
+ operatorAliases,
36
+ propertyAliases,
37
+ evaluate,
38
+ parseChildren: getRequest_1.parseChildrenGET,
39
+ };
@@ -0,0 +1,7 @@
1
+ import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../types';
2
+ declare const requiredProperties: readonly ["testString", "pattern"];
3
+ export declare type RegexNode = {
4
+ [key in typeof requiredProperties[number]]: EvaluatorNode;
5
+ } & BaseOperatorNode;
6
+ export declare const REGEX: OperatorObject;
7
+ export {};
@@ -0,0 +1,46 @@
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.REGEX = void 0;
13
+ const _operatorUtils_1 = require("./_operatorUtils");
14
+ const helpers_1 = require("../helpers");
15
+ const requiredProperties = ['testString', 'pattern'];
16
+ const operatorAliases = ['regex', 'patternMatch', 'regexp', 'matchPattern'];
17
+ const propertyAliases = {
18
+ string: 'testString',
19
+ value: 'testString',
20
+ regex: 'pattern',
21
+ regexp: 'pattern',
22
+ regExp: 'pattern',
23
+ re: 'pattern',
24
+ };
25
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const [testString, pattern] = (yield (0, _operatorUtils_1.evaluateArray)([expression.testString, expression.pattern], config));
27
+ config.typeChecker({ name: 'testString', value: testString, expectedType: 'string' }, { name: 'pattern', value: pattern, expectedType: 'string' });
28
+ try {
29
+ const re = new RegExp(pattern);
30
+ return re.test(testString);
31
+ }
32
+ catch (err) {
33
+ throw new Error('Regex error:' + (0, helpers_1.errorMessage)(err));
34
+ }
35
+ });
36
+ const parseChildren = (expression) => {
37
+ const [testString, pattern] = expression.children;
38
+ return Object.assign(Object.assign({}, expression), { testString, pattern });
39
+ };
40
+ exports.REGEX = {
41
+ requiredProperties,
42
+ operatorAliases,
43
+ propertyAliases,
44
+ evaluate,
45
+ parseChildren,
46
+ };
@@ -0,0 +1,11 @@
1
+ import { OperatorObject, EvaluatorNode, BaseOperatorNode } from '../types';
2
+ declare const requiredProperties: readonly ["value"];
3
+ export declare type SplitNode = {
4
+ [key in typeof requiredProperties[number]]: EvaluatorNode;
5
+ } & BaseOperatorNode & {
6
+ delimiter?: EvaluatorNode;
7
+ trimWhiteSpace: EvaluatorNode;
8
+ excludeTrailing: EvaluatorNode;
9
+ };
10
+ export declare const SPLIT: OperatorObject;
11
+ export {};
@@ -0,0 +1,51 @@
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.SPLIT = void 0;
13
+ const _operatorUtils_1 = require("./_operatorUtils");
14
+ const requiredProperties = ['value'];
15
+ const operatorAliases = ['split', 'arraySplit'];
16
+ const propertyAliases = {
17
+ string: 'value',
18
+ separator: 'delimiter',
19
+ trim: 'trimWhiteSpace',
20
+ trimWhitespace: 'trimWhiteSpace',
21
+ removeTrailing: 'excludeTrailing',
22
+ excludeTrailingDelimiter: 'excludeTrailing',
23
+ };
24
+ const DEFAULT_DELIMITER = ' ';
25
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
26
+ var _a, _b, _c;
27
+ const [value, delimiter, trimWhiteSpace, excludeTrailing] = (yield (0, _operatorUtils_1.evaluateArray)([
28
+ expression.value,
29
+ (_a = expression.delimiter) !== null && _a !== void 0 ? _a : DEFAULT_DELIMITER,
30
+ (_b = expression.trimWhiteSpace) !== null && _b !== void 0 ? _b : true,
31
+ (_c = expression.excludeTrailing) !== null && _c !== void 0 ? _c : true,
32
+ ], config));
33
+ config.typeChecker({ name: 'value', value: value, expectedType: 'string' }, { name: 'delimiter', value: delimiter, expectedType: 'string' }, { name: 'trimWhiteSpace', value: trimWhiteSpace, expectedType: 'boolean' }, { name: 'excludeTrailing', value: excludeTrailing, expectedType: 'boolean' });
34
+ let splitValues = value.split(delimiter);
35
+ if (trimWhiteSpace)
36
+ splitValues = splitValues.map((val) => val.trim());
37
+ if (excludeTrailing && splitValues[splitValues.length - 1] === '')
38
+ splitValues.pop();
39
+ return splitValues;
40
+ });
41
+ const parseChildren = (expression) => {
42
+ const [value, delimiter = DEFAULT_DELIMITER] = expression.children;
43
+ return Object.assign(Object.assign({}, expression), { value, delimiter });
44
+ };
45
+ exports.SPLIT = {
46
+ requiredProperties,
47
+ operatorAliases,
48
+ propertyAliases,
49
+ evaluate,
50
+ parseChildren,
51
+ };
@@ -0,0 +1,7 @@
1
+ import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../types';
2
+ declare const requiredProperties: readonly ["string", "substitutions"];
3
+ export declare type StringSubNode = {
4
+ [key in typeof requiredProperties[number]]: EvaluatorNode;
5
+ } & BaseOperatorNode;
6
+ export declare const STRING_SUBSTITUTION: OperatorObject;
7
+ export {};
@@ -0,0 +1,40 @@
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.STRING_SUBSTITUTION = void 0;
13
+ const _operatorUtils_1 = require("./_operatorUtils");
14
+ const requiredProperties = ['string', 'substitutions'];
15
+ const operatorAliases = ['stringSubstitution', 'substitute', 'stringSub', 'replace'];
16
+ const propertyAliases = { replacements: 'substitutions' };
17
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
18
+ const [string, ...substitutions] = (yield (0, _operatorUtils_1.evaluateArray)([expression.string, ...expression.substitutions], config));
19
+ config.typeChecker({ name: 'string', value: string, expectedType: 'string' });
20
+ config.typeChecker({ name: 'substitutions', value: substitutions, expectedType: 'array' });
21
+ const regex = /(%[\d]+)/g;
22
+ const parameters = (string.match(regex) || []).sort((a, b) => Number(a.slice(1)) - Number(b.slice(1)));
23
+ const uniqueParameters = new Set(parameters);
24
+ const replacementsObj = (0, _operatorUtils_1.zipArraysToObject)(Array.from(uniqueParameters), substitutions);
25
+ return string
26
+ .split(regex)
27
+ .map((fragment) => (fragment in replacementsObj ? replacementsObj[fragment] : fragment))
28
+ .join('');
29
+ });
30
+ const parseChildren = (expression) => {
31
+ const [string, ...substitutions] = expression.children;
32
+ return Object.assign(Object.assign({}, expression), { string, substitutions });
33
+ };
34
+ exports.STRING_SUBSTITUTION = {
35
+ requiredProperties,
36
+ operatorAliases,
37
+ propertyAliases,
38
+ evaluate,
39
+ parseChildren,
40
+ };
@@ -0,0 +1,9 @@
1
+ import { BasicExtendedNode } from './logicalAnd';
2
+ import { EvaluatorNode, OperatorObject, BaseOperatorNode } from '../types';
3
+ interface SubtractionNodeWithProps extends BaseOperatorNode {
4
+ subtract: EvaluatorNode;
5
+ from: EvaluatorNode;
6
+ }
7
+ export declare type SubtractionNode = BasicExtendedNode & SubtractionNodeWithProps;
8
+ export declare const SUBTRACT: OperatorObject;
9
+ export {};
@@ -0,0 +1,32 @@
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.SUBTRACT = void 0;
13
+ const logicalAnd_1 = require("./logicalAnd");
14
+ const _operatorUtils_1 = require("./_operatorUtils");
15
+ const requiredProperties = [];
16
+ const operatorAliases = ['-', 'subtract', 'minus', 'takeaway'];
17
+ const propertyAliases = { subtractFrom: 'from' };
18
+ const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
19
+ var _a;
20
+ const values = (yield (0, _operatorUtils_1.evaluateArray)((_a = expression.values) !== null && _a !== void 0 ? _a : [expression.from, expression.subtract], config));
21
+ config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
22
+ if (values.length < 2)
23
+ throw new Error('- Not enough values provided');
24
+ return values[0] - values[1];
25
+ });
26
+ exports.SUBTRACT = {
27
+ requiredProperties,
28
+ operatorAliases,
29
+ propertyAliases,
30
+ evaluate,
31
+ parseChildren: logicalAnd_1.parseChildren,
32
+ };
@@ -0,0 +1,9 @@
1
+ declare type ExpectedType = 'string' | 'boolean' | 'number' | 'array' | 'undefined' | 'null' | 'object';
2
+ export declare type TypeCheckInput = {
3
+ value: unknown;
4
+ name?: string;
5
+ not?: boolean;
6
+ expectedType: ExpectedType | ExpectedType[];
7
+ };
8
+ export declare const typeCheck: (...args: TypeCheckInput[]) => true | string;
9
+ export {};