fig-tree-evaluator 2.7.0 → 2.8.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 (174) hide show
  1. package/README.md +194 -12
  2. package/build/FigTreeEvaluator.d.ts +18 -0
  3. package/build/FigTreeEvaluator.js +17 -0
  4. package/build/evaluate.js +16 -10
  5. package/build/helpers.d.ts +1 -0
  6. package/build/helpers.js +5 -4
  7. package/build/operators/AND/data.d.ts +5 -0
  8. package/build/operators/AND/data.js +23 -0
  9. package/build/operators/AND/index.d.ts +1 -0
  10. package/build/operators/AND/index.js +5 -0
  11. package/build/operators/{logicalAnd.d.ts → AND/operator.d.ts} +2 -3
  12. package/build/operators/AND/operator.js +54 -0
  13. package/build/operators/BUILD_OBJECT/data.d.ts +5 -0
  14. package/build/operators/BUILD_OBJECT/data.js +23 -0
  15. package/build/operators/BUILD_OBJECT/index.d.ts +1 -0
  16. package/build/operators/BUILD_OBJECT/index.js +17 -0
  17. package/build/operators/{buildObject.d.ts → BUILD_OBJECT/operator.d.ts} +2 -3
  18. package/build/operators/{buildObject.js → BUILD_OBJECT/operator.js} +29 -12
  19. package/build/operators/CONDITIONAL/data.d.ts +5 -0
  20. package/build/operators/CONDITIONAL/data.js +37 -0
  21. package/build/operators/CONDITIONAL/index.d.ts +1 -0
  22. package/build/operators/CONDITIONAL/index.js +17 -0
  23. package/build/operators/{conditional.d.ts → CONDITIONAL/operator.d.ts} +2 -3
  24. package/build/operators/{conditional.js → CONDITIONAL/operator.js} +28 -7
  25. package/build/operators/COUNT/data.d.ts +5 -0
  26. package/build/operators/COUNT/data.js +23 -0
  27. package/build/operators/COUNT/index.d.ts +1 -0
  28. package/build/operators/COUNT/index.js +17 -0
  29. package/build/operators/COUNT/operator.d.ts +2 -0
  30. package/build/operators/COUNT/operator.js +50 -0
  31. package/build/operators/CUSTOM_FUNCTIONS/data.d.ts +5 -0
  32. package/build/operators/CUSTOM_FUNCTIONS/data.js +37 -0
  33. package/build/operators/CUSTOM_FUNCTIONS/index.d.ts +1 -0
  34. package/build/operators/CUSTOM_FUNCTIONS/index.js +17 -0
  35. package/build/operators/{customFunctions.d.ts → CUSTOM_FUNCTIONS/operator.d.ts} +2 -3
  36. package/build/operators/{customFunctions.js → CUSTOM_FUNCTIONS/operator.js} +29 -22
  37. package/build/operators/DIVIDE/data.d.ts +5 -0
  38. package/build/operators/DIVIDE/data.js +44 -0
  39. package/build/operators/DIVIDE/index.d.ts +1 -0
  40. package/build/operators/DIVIDE/index.js +17 -0
  41. package/build/operators/{divide.d.ts → DIVIDE/operator.d.ts} +2 -2
  42. package/build/operators/DIVIDE/operator.js +62 -0
  43. package/build/operators/EQUAL/data.d.ts +5 -0
  44. package/build/operators/EQUAL/data.js +30 -0
  45. package/build/operators/EQUAL/index.d.ts +1 -0
  46. package/build/operators/EQUAL/index.js +17 -0
  47. package/build/operators/EQUAL/operator.d.ts +2 -0
  48. package/build/operators/{equal.js → EQUAL/operator.js} +31 -10
  49. package/build/operators/GET/data.d.ts +5 -0
  50. package/build/operators/GET/data.js +51 -0
  51. package/build/operators/GET/index.d.ts +1 -0
  52. package/build/operators/GET/index.js +5 -0
  53. package/build/operators/{getRequest.d.ts → GET/operator.d.ts} +2 -3
  54. package/build/operators/{getRequest.js → GET/operator.js} +51 -13
  55. package/build/operators/GRAPHQL/data.d.ts +5 -0
  56. package/build/operators/GRAPHQL/data.js +58 -0
  57. package/build/operators/GRAPHQL/index.d.ts +1 -0
  58. package/build/operators/GRAPHQL/index.js +17 -0
  59. package/build/operators/{graphQL.d.ts → GRAPHQL/operator.d.ts} +2 -3
  60. package/build/operators/{graphQL.js → GRAPHQL/operator.js} +29 -8
  61. package/build/operators/GREATER_THAN/data.d.ts +5 -0
  62. package/build/operators/GREATER_THAN/data.js +30 -0
  63. package/build/operators/GREATER_THAN/index.d.ts +1 -0
  64. package/build/operators/GREATER_THAN/index.js +17 -0
  65. package/build/operators/{greaterThan.d.ts → GREATER_THAN/operator.d.ts} +2 -2
  66. package/build/operators/GREATER_THAN/operator.js +55 -0
  67. package/build/operators/LESS_THAN/data.d.ts +5 -0
  68. package/build/operators/LESS_THAN/data.js +30 -0
  69. package/build/operators/LESS_THAN/index.d.ts +1 -0
  70. package/build/operators/LESS_THAN/index.js +17 -0
  71. package/build/operators/{lessThan.d.ts → LESS_THAN/operator.d.ts} +1 -1
  72. package/build/operators/LESS_THAN/operator.js +55 -0
  73. package/build/operators/MATCH/data.d.ts +5 -0
  74. package/build/operators/MATCH/data.js +30 -0
  75. package/build/operators/MATCH/index.d.ts +1 -0
  76. package/build/operators/MATCH/index.js +17 -0
  77. package/build/operators/{match.d.ts → MATCH/operator.d.ts} +2 -3
  78. package/build/operators/{match.js → MATCH/operator.js} +31 -18
  79. package/build/operators/MULTIPLY/data.d.ts +5 -0
  80. package/build/operators/MULTIPLY/data.js +23 -0
  81. package/build/operators/MULTIPLY/index.d.ts +1 -0
  82. package/build/operators/MULTIPLY/index.js +17 -0
  83. package/build/operators/{multiply.d.ts → MULTIPLY/operator.d.ts} +1 -1
  84. package/build/operators/MULTIPLY/operator.js +50 -0
  85. package/build/operators/NOT_EQUAL/data.d.ts +5 -0
  86. package/build/operators/NOT_EQUAL/data.js +30 -0
  87. package/build/operators/NOT_EQUAL/index.d.ts +1 -0
  88. package/build/operators/NOT_EQUAL/index.js +17 -0
  89. package/build/operators/{notEqual.d.ts → NOT_EQUAL/operator.d.ts} +1 -1
  90. package/build/operators/{notEqual.js → NOT_EQUAL/operator.js} +31 -10
  91. package/build/operators/OBJECT_PROPERTIES/data.d.ts +5 -0
  92. package/build/operators/OBJECT_PROPERTIES/data.js +38 -0
  93. package/build/operators/OBJECT_PROPERTIES/index.d.ts +1 -0
  94. package/build/operators/OBJECT_PROPERTIES/index.js +17 -0
  95. package/build/operators/{objectProperties.d.ts → OBJECT_PROPERTIES/operator.d.ts} +2 -3
  96. package/build/operators/{objectProperties.js → OBJECT_PROPERTIES/operator.js} +33 -24
  97. package/build/operators/OR/data.d.ts +5 -0
  98. package/build/operators/OR/data.js +23 -0
  99. package/build/operators/OR/index.d.ts +1 -0
  100. package/build/operators/OR/index.js +17 -0
  101. package/build/operators/OR/operator.d.ts +2 -0
  102. package/build/operators/OR/operator.js +50 -0
  103. package/build/operators/PASSTHRU/data.d.ts +5 -0
  104. package/build/operators/PASSTHRU/data.js +23 -0
  105. package/build/operators/PASSTHRU/index.d.ts +1 -0
  106. package/build/operators/PASSTHRU/index.js +17 -0
  107. package/build/operators/{passThru.d.ts → PASSTHRU/operator.d.ts} +3 -4
  108. package/build/operators/PASSTHRU/operator.js +52 -0
  109. package/build/operators/PG_SQL/data.d.ts +5 -0
  110. package/build/operators/PG_SQL/data.js +37 -0
  111. package/build/operators/PG_SQL/index.d.ts +1 -0
  112. package/build/operators/PG_SQL/index.js +17 -0
  113. package/build/operators/{pgSQL.d.ts → PG_SQL/operator.d.ts} +2 -2
  114. package/build/operators/{pgSQL.js → PG_SQL/operator.js} +29 -8
  115. package/build/operators/PLUS/data.d.ts +5 -0
  116. package/build/operators/PLUS/data.js +30 -0
  117. package/build/operators/PLUS/index.d.ts +1 -0
  118. package/build/operators/PLUS/index.js +17 -0
  119. package/build/operators/{plus.d.ts → PLUS/operator.d.ts} +3 -4
  120. package/build/operators/{plus.js → PLUS/operator.js} +34 -10
  121. package/build/operators/POST/data.d.ts +5 -0
  122. package/build/operators/POST/data.js +51 -0
  123. package/build/operators/POST/index.d.ts +1 -0
  124. package/build/operators/POST/index.js +17 -0
  125. package/build/operators/POST/operator.d.ts +2 -0
  126. package/build/operators/{postRequest.js → POST/operator.js} +31 -10
  127. package/build/operators/REGEX/data.d.ts +5 -0
  128. package/build/operators/REGEX/data.js +30 -0
  129. package/build/operators/REGEX/index.d.ts +1 -0
  130. package/build/operators/REGEX/index.js +17 -0
  131. package/build/operators/{regex.d.ts → REGEX/operator.d.ts} +2 -3
  132. package/build/operators/{regex.js → REGEX/operator.js} +30 -16
  133. package/build/operators/SPLIT/data.d.ts +5 -0
  134. package/build/operators/SPLIT/data.js +44 -0
  135. package/build/operators/SPLIT/index.d.ts +1 -0
  136. package/build/operators/SPLIT/index.js +17 -0
  137. package/build/operators/{split.d.ts → SPLIT/operator.d.ts} +2 -3
  138. package/build/operators/{split.js → SPLIT/operator.js} +34 -15
  139. package/build/operators/STRING_SUBSTITUTION/data.d.ts +5 -0
  140. package/build/operators/STRING_SUBSTITUTION/data.js +30 -0
  141. package/build/operators/STRING_SUBSTITUTION/index.d.ts +1 -0
  142. package/build/operators/STRING_SUBSTITUTION/index.js +17 -0
  143. package/build/operators/{stringSubstitution.d.ts → STRING_SUBSTITUTION/operator.d.ts} +2 -3
  144. package/build/operators/{stringSubstitution.js → STRING_SUBSTITUTION/operator.js} +29 -9
  145. package/build/operators/SUBTRACT/data.d.ts +5 -0
  146. package/build/operators/SUBTRACT/data.js +37 -0
  147. package/build/operators/SUBTRACT/index.d.ts +1 -0
  148. package/build/operators/SUBTRACT/index.js +17 -0
  149. package/build/operators/{subtract.d.ts → SUBTRACT/operator.d.ts} +2 -2
  150. package/build/operators/SUBTRACT/operator.js +53 -0
  151. package/build/operators/_operatorAliases.json +1 -0
  152. package/build/operators/_operatorUtils.d.ts +9 -1
  153. package/build/operators/_operatorUtils.js +19 -1
  154. package/build/operators/index.d.ts +24 -24
  155. package/build/operators/index.js +24 -27
  156. package/build/shorthandSyntax.d.ts +2 -0
  157. package/build/shorthandSyntax.js +55 -0
  158. package/build/typeCheck.d.ts +1 -1
  159. package/build/typeCheck.js +1 -0
  160. package/build/types.d.ts +30 -12
  161. package/package.json +1 -1
  162. package/build/operators/count.d.ts +0 -2
  163. package/build/operators/count.js +0 -29
  164. package/build/operators/divide.js +0 -41
  165. package/build/operators/equal.d.ts +0 -2
  166. package/build/operators/greaterThan.js +0 -35
  167. package/build/operators/lessThan.js +0 -35
  168. package/build/operators/logicalAnd.js +0 -33
  169. package/build/operators/logicalOr.d.ts +0 -2
  170. package/build/operators/logicalOr.js +0 -29
  171. package/build/operators/multiply.js +0 -29
  172. package/build/operators/passThru.js +0 -30
  173. package/build/operators/postRequest.d.ts +0 -2
  174. package/build/operators/subtract.js +0 -32
@@ -14,30 +14,27 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.GET = exports.AND = void 0;
18
- __exportStar(require("./logicalOr"), exports);
19
- var logicalAnd_1 = require("./logicalAnd");
20
- Object.defineProperty(exports, "AND", { enumerable: true, get: function () { return logicalAnd_1.AND; } });
21
- __exportStar(require("./equal"), exports);
22
- __exportStar(require("./notEqual"), exports);
23
- __exportStar(require("./plus"), exports);
24
- __exportStar(require("./subtract"), exports);
25
- __exportStar(require("./multiply"), exports);
26
- __exportStar(require("./divide"), exports);
27
- __exportStar(require("./greaterThan"), exports);
28
- __exportStar(require("./lessThan"), exports);
29
- __exportStar(require("./conditional"), exports);
30
- __exportStar(require("./regex"), exports);
31
- __exportStar(require("./objectProperties"), exports);
32
- __exportStar(require("./stringSubstitution"), exports);
33
- __exportStar(require("./count"), exports);
34
- __exportStar(require("./split"), exports);
35
- __exportStar(require("./pgSQL"), exports);
36
- __exportStar(require("./graphQL"), exports);
37
- var getRequest_1 = require("./getRequest");
38
- Object.defineProperty(exports, "GET", { enumerable: true, get: function () { return getRequest_1.GET; } });
39
- __exportStar(require("./postRequest"), exports);
40
- __exportStar(require("./buildObject"), exports);
41
- __exportStar(require("./match"), exports);
42
- __exportStar(require("./customFunctions"), exports);
43
- __exportStar(require("./passThru"), exports);
17
+ __exportStar(require("./AND"), exports);
18
+ __exportStar(require("./OR"), exports);
19
+ __exportStar(require("./EQUAL"), exports);
20
+ __exportStar(require("./NOT_EQUAL"), exports);
21
+ __exportStar(require("./PLUS"), exports);
22
+ __exportStar(require("./SUBTRACT"), exports);
23
+ __exportStar(require("./MULTIPLY"), exports);
24
+ __exportStar(require("./DIVIDE"), exports);
25
+ __exportStar(require("./GREATER_THAN"), exports);
26
+ __exportStar(require("./LESS_THAN"), exports);
27
+ __exportStar(require("./CONDITIONAL"), exports);
28
+ __exportStar(require("./REGEX"), exports);
29
+ __exportStar(require("./OBJECT_PROPERTIES"), exports);
30
+ __exportStar(require("./STRING_SUBSTITUTION"), exports);
31
+ __exportStar(require("./COUNT"), exports);
32
+ __exportStar(require("./SPLIT"), exports);
33
+ __exportStar(require("./PG_SQL"), exports);
34
+ __exportStar(require("./GRAPHQL"), exports);
35
+ __exportStar(require("./GET"), exports);
36
+ __exportStar(require("./POST"), exports);
37
+ __exportStar(require("./BUILD_OBJECT"), exports);
38
+ __exportStar(require("./MATCH"), exports);
39
+ __exportStar(require("./CUSTOM_FUNCTIONS"), exports);
40
+ __exportStar(require("./PASSTHRU"), exports);
@@ -0,0 +1,2 @@
1
+ import { EvaluatorNode, Fragments, FragmentNode } from './types';
2
+ export declare const preProcessShorthand: (expression: EvaluatorNode, fragments?: Fragments, useShorthand?: boolean) => EvaluatorNode | FragmentNode;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.preProcessShorthand = void 0;
7
+ const helpers_1 = require("./helpers");
8
+ const _operatorAliases_json_1 = __importDefault(require("./operators/_operatorAliases.json"));
9
+ const operatorAliases = _operatorAliases_json_1.default;
10
+ const functionStringRegex = /(\$[^\(\)]+)\((.*)\)/;
11
+ const preProcessShorthand = (expression, fragments = {}, useShorthand = true) => {
12
+ if (!useShorthand)
13
+ return expression;
14
+ if (typeof expression === 'string')
15
+ return processString(expression, fragments);
16
+ if ((0, helpers_1.isObject)(expression))
17
+ return processObject(expression, fragments);
18
+ return expression;
19
+ };
20
+ exports.preProcessShorthand = preProcessShorthand;
21
+ const processString = (expString, fragments) => {
22
+ const match = functionStringRegex.exec(expString);
23
+ if (!match)
24
+ return expString;
25
+ const method = match[1].trim();
26
+ const params = match[2].split(',').map((p) => (0, exports.preProcessShorthand)(p.trim(), fragments));
27
+ return buildNodeElements(method, params, fragments);
28
+ };
29
+ const processObject = (expObject, fragments) => {
30
+ if ((0, helpers_1.isOperatorNode)(expObject) || (0, helpers_1.isFragmentNode)(expObject))
31
+ return expObject;
32
+ const keyVals = Object.entries(expObject);
33
+ const aliasParams = keyVals.filter(([key]) => (0, helpers_1.isAliasString)(key));
34
+ const otherParams = keyVals.filter(([key]) => !(0, helpers_1.isAliasString)(key));
35
+ const newKeyVals = aliasParams.reduce((accObj, [alias, params]) => {
36
+ accObj = Object.assign(Object.assign({}, accObj), buildNodeElements(alias, params, fragments));
37
+ return accObj;
38
+ }, {});
39
+ return Object.assign(Object.assign({}, newKeyVals), Object.fromEntries(otherParams));
40
+ };
41
+ const buildNodeElements = (alias, params, fragments) => {
42
+ const aliasName = alias.slice(1);
43
+ const operator = (0, helpers_1.getOperatorName)(aliasName, operatorAliases);
44
+ if (operator) {
45
+ if (Array.isArray(params))
46
+ return { operator, children: params };
47
+ if ((0, helpers_1.isObject)(params) && !Object.keys(params).some((key) => (0, helpers_1.isAliasString)(key)))
48
+ return Object.assign({ operator }, params);
49
+ return { operator, children: [params] };
50
+ }
51
+ if (aliasName in fragments) {
52
+ return { fragment: aliasName, parameters: Object.assign({}, params) };
53
+ }
54
+ return { [alias]: params };
55
+ };
@@ -1,4 +1,4 @@
1
- export type ExpectedType = 'string' | 'boolean' | 'number' | 'array' | 'undefined' | 'null' | 'object';
1
+ export type ExpectedType = 'string' | 'boolean' | 'number' | 'array' | 'undefined' | 'null' | 'object' | 'any';
2
2
  export type TypeCheckInput = {
3
3
  value: unknown;
4
4
  name?: string;
@@ -36,6 +36,7 @@ const typeCheckMap = {
36
36
  undefined: (value) => value === undefined,
37
37
  null: (value) => value === null,
38
38
  object: (value) => typeof value === 'object' && !Array.isArray(value) && value !== null,
39
+ any: (value) => value !== undefined,
39
40
  };
40
41
  const makeErrorString = (name, value, type, not) => {
41
42
  if (name !== undefined)
package/build/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import FigTreeCache from './cache';
2
2
  import { BasicExtendedNode, SubtractionNode, DivisionNode, ComparatorNode, ConditionalNode, RegexNode, StringSubNode, SplitNode, ObjPropNode, APINode, PGNode, GraphQLNode, BuildObjectNode, MatchNode, FunctionNode, PassThruNode, PGConnection, GraphQLConnection } from './operators';
3
3
  import operatorAliases from './operators/_operatorAliases.json';
4
- import { TypeCheckInput } from './typeCheck';
4
+ import { ExpectedType, TypeCheckInput } from './typeCheck';
5
5
  export declare const Operators: readonly ["AND", "OR", "EQUAL", "NOT_EQUAL", "PLUS", "SUBTRACT", "MULTIPLY", "DIVIDE", "GREATER_THAN", "LESS_THAN", "CONDITIONAL", "REGEX", "OBJECT_PROPERTIES", "STRING_SUBSTITUTION", "SPLIT", "COUNT", "GET", "POST", "PG_SQL", "GRAPHQL", "BUILD_OBJECT", "MATCH", "CUSTOM_FUNCTIONS", "PASSTHRU"];
6
6
  export type Operator = typeof Operators[number];
7
7
  export type GenericObject = {
@@ -9,15 +9,13 @@ export type GenericObject = {
9
9
  };
10
10
  export type OperatorAlias = keyof typeof operatorAliases;
11
11
  export type OperatorAliases = Record<OperatorAlias, Operator>;
12
+ export type Fragments = Record<string, Fragment>;
13
+ export type Functions = Record<string, Function>;
12
14
  export interface FigTreeOptions {
13
15
  data?: GenericObject;
14
16
  objects?: GenericObject;
15
- functions?: {
16
- [key: string]: Function;
17
- };
18
- fragments?: {
19
- [key: string]: EvaluatorNode;
20
- };
17
+ functions?: Functions;
18
+ fragments?: Fragments;
21
19
  pgConnection?: PGConnection;
22
20
  graphQLConnection?: GraphQLConnection;
23
21
  baseEndpoint?: string;
@@ -27,6 +25,7 @@ export interface FigTreeOptions {
27
25
  returnErrorAsString?: boolean;
28
26
  nullEqualsUndefined?: boolean;
29
27
  allowJSONStringInput?: boolean;
28
+ noShorthand?: boolean;
30
29
  skipRuntimeTypeCheck?: boolean;
31
30
  evaluateFullObject?: boolean;
32
31
  excludeOperators?: string[];
@@ -60,19 +59,38 @@ export interface FragmentNode {
60
59
  };
61
60
  [key: string]: EvaluatorNode;
62
61
  }
62
+ export type Fragment = (EvaluatorNode & {
63
+ metadata?: {
64
+ description?: string;
65
+ parameters?: Record<string, {
66
+ type: string | string[];
67
+ required: boolean;
68
+ }>;
69
+ };
70
+ }) | null;
63
71
  export type CombinedOperatorNode = BaseOperatorNode & BasicExtendedNode & SubtractionNode & DivisionNode & ComparatorNode & ConditionalNode & RegexNode & StringSubNode & SplitNode & ObjPropNode & APINode & PGNode & GraphQLNode & BuildObjectNode & MatchNode & FunctionNode & PassThruNode;
64
- export type OperatorNodeUnion = BasicExtendedNode | SubtractionNode | DivisionNode | ComparatorNode | ConditionalNode | RegexNode | StringSubNode | SplitNode | ObjPropNode | PGNode | GraphQLNode | APINode | BuildObjectNode | MatchNode | FunctionNode | PassThruNode;
72
+ export type OperatorNodeUnion = BasicExtendedNode | SubtractionNode | DivisionNode | ComparatorNode | ConditionalNode | RegexNode | StringSubNode | SplitNode | ObjPropNode | APINode | PGNode | GraphQLNode | BuildObjectNode | MatchNode | FunctionNode | PassThruNode;
65
73
  export type EvaluatorOutput = string | boolean | number | GenericObject | null | undefined | any[];
66
74
  export type EvaluatorNode = CombinedOperatorNode | FragmentNode | EvaluatorOutput;
67
75
  export type OperatorObject = {
68
76
  requiredProperties: readonly string[];
69
- operatorAliases: string[];
70
- propertyAliases: {
71
- [key: string]: string;
72
- };
77
+ propertyAliases: Record<string, string>;
78
+ operatorData: OperatorData;
73
79
  evaluate: (expression: CombinedOperatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
74
80
  parseChildren: (expression: CombinedOperatorNode, config: FigTreeConfig) => OperatorNodeUnion | Promise<OperatorNodeUnion>;
75
81
  };
76
82
  export type OperatorReference = {
77
83
  [key in Operator]: OperatorObject;
78
84
  };
85
+ export type Parameter = {
86
+ name: string;
87
+ description: string;
88
+ aliases: string[];
89
+ required: boolean;
90
+ type: ExpectedType | ExpectedType[];
91
+ };
92
+ export interface OperatorData {
93
+ description: string;
94
+ aliases: string[];
95
+ parameters: Parameter[];
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fig-tree-evaluator",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "Module to evaluate JSON-structured expression trees",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -1,2 +0,0 @@
1
- import { OperatorObject } from '../types';
2
- export declare const COUNT: OperatorObject;
@@ -1,29 +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.COUNT = void 0;
13
- const logicalAnd_1 = require("./logicalAnd");
14
- const _operatorUtils_1 = require("./_operatorUtils");
15
- const requiredProperties = ['values'];
16
- const operatorAliases = ['count', 'length'];
17
- const propertyAliases = {};
18
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
19
- const values = yield (0, _operatorUtils_1.evaluateArray)(expression.values, config);
20
- config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
21
- return values.length;
22
- });
23
- exports.COUNT = {
24
- requiredProperties,
25
- operatorAliases,
26
- propertyAliases,
27
- evaluate,
28
- parseChildren: logicalAnd_1.parseChildren,
29
- };
@@ -1,41 +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.DIVIDE = void 0;
13
- const logicalAnd_1 = require("./logicalAnd");
14
- const _operatorUtils_1 = require("./_operatorUtils");
15
- const requiredProperties = [];
16
- const operatorAliases = ['/', 'divide', '÷'];
17
- const propertyAliases = { divide: 'dividend', by: 'divisor', divideBy: 'divisor' };
18
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
19
- var _a;
20
- const [values, output] = (yield (0, _operatorUtils_1.evaluateArray)([(_a = expression.values) !== null && _a !== void 0 ? _a : [expression.dividend, expression.divisor], expression.output], config));
21
- config.typeChecker({ name: 'values', value: values, expectedType: 'array' }, { name: 'output', value: output, expectedType: ['string', 'undefined'] });
22
- if (values.length < 2)
23
- throw new Error('- Not enough values provided');
24
- if (!values[1])
25
- throw new Error('Division by zero!');
26
- switch (output) {
27
- case 'quotient':
28
- return Math.floor(values[0] / values[1]);
29
- case 'remainder':
30
- return values[0] % values[1];
31
- default:
32
- return values[0] / values[1];
33
- }
34
- });
35
- exports.DIVIDE = {
36
- requiredProperties,
37
- operatorAliases,
38
- propertyAliases,
39
- evaluate,
40
- parseChildren: logicalAnd_1.parseChildren,
41
- };
@@ -1,2 +0,0 @@
1
- import { OperatorObject } from '../types';
2
- export declare const EQUAL: OperatorObject;
@@ -1,35 +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.GREATER_THAN = void 0;
13
- const _operatorUtils_1 = require("./_operatorUtils");
14
- const logicalAnd_1 = require("./logicalAnd");
15
- const requiredProperties = ['values'];
16
- const operatorAliases = ['>', 'greaterThan', 'higher', 'larger'];
17
- const aliasExtensions = [{ '>=': { strict: false } }];
18
- const propertyAliases = {};
19
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
20
- const [values, strict = true] = (yield (0, _operatorUtils_1.evaluateArray)([expression.values, expression.strict], config));
21
- config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
22
- if (values.length < 2)
23
- throw new Error('- Not enough values provided');
24
- const [first, second] = values;
25
- if (first === second && !strict)
26
- return true;
27
- return first > second;
28
- });
29
- exports.GREATER_THAN = {
30
- requiredProperties,
31
- operatorAliases,
32
- propertyAliases,
33
- evaluate,
34
- parseChildren: logicalAnd_1.parseChildren,
35
- };
@@ -1,35 +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.LESS_THAN = void 0;
13
- const _operatorUtils_1 = require("./_operatorUtils");
14
- const logicalAnd_1 = require("./logicalAnd");
15
- const requiredProperties = ['values'];
16
- const operatorAliases = ['<', 'lessThan', 'lower', 'smaller'];
17
- const aliasExtensions = [{ '<=': { strict: false } }];
18
- const propertyAliases = {};
19
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
20
- const [values, strict = true] = (yield (0, _operatorUtils_1.evaluateArray)([expression.values, expression.strict], config));
21
- config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
22
- if (values.length < 2)
23
- throw new Error('- Not enough values provided');
24
- const [first, second] = values;
25
- if (first === second && !strict)
26
- return true;
27
- return first < second;
28
- });
29
- exports.LESS_THAN = {
30
- requiredProperties,
31
- operatorAliases,
32
- propertyAliases,
33
- evaluate,
34
- parseChildren: logicalAnd_1.parseChildren,
35
- };
@@ -1,33 +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.AND = exports.parseChildren = void 0;
13
- const _operatorUtils_1 = require("./_operatorUtils");
14
- const requiredProperties = ['values'];
15
- const operatorAliases = ['and', '&', '&&'];
16
- const propertyAliases = {};
17
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
18
- const values = (yield (0, _operatorUtils_1.evaluateArray)(expression.values, config));
19
- config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
20
- return values.reduce((acc, val) => acc && !!val, true);
21
- });
22
- const parseChildren = (expression) => {
23
- const values = expression.children;
24
- return Object.assign(Object.assign({}, expression), { values });
25
- };
26
- exports.parseChildren = parseChildren;
27
- exports.AND = {
28
- requiredProperties,
29
- operatorAliases,
30
- propertyAliases,
31
- evaluate,
32
- parseChildren: exports.parseChildren,
33
- };
@@ -1,2 +0,0 @@
1
- import { OperatorObject } from '../types';
2
- export declare const OR: OperatorObject;
@@ -1,29 +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.OR = void 0;
13
- const logicalAnd_1 = require("./logicalAnd");
14
- const _operatorUtils_1 = require("./_operatorUtils");
15
- const requiredProperties = ['values'];
16
- const operatorAliases = ['or', '|', '||'];
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, val) => acc || !!val, false);
22
- });
23
- exports.OR = {
24
- requiredProperties,
25
- operatorAliases,
26
- propertyAliases,
27
- evaluate,
28
- parseChildren: logicalAnd_1.parseChildren,
29
- };
@@ -1,29 +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.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
- };
@@ -1,30 +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.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
- };
@@ -1,2 +0,0 @@
1
- import { OperatorObject } from '../types';
2
- export declare const POST: OperatorObject;
@@ -1,32 +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.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
- };