fig-tree-evaluator 2.7.0 → 2.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/README.md +195 -12
  2. package/build/FigTreeEvaluator.d.ts +10 -2
  3. package/build/FigTreeEvaluator.js +25 -4
  4. package/build/cache.d.ts +3 -1
  5. package/build/cache.js +10 -11
  6. package/build/evaluate.js +18 -14
  7. package/build/helpers.d.ts +9 -34
  8. package/build/helpers.js +5 -13
  9. package/build/index.d.ts +2 -2
  10. package/build/operators/AND/data.d.ts +4 -0
  11. package/build/operators/AND/data.js +22 -0
  12. package/build/operators/AND/index.d.ts +1 -0
  13. package/build/operators/AND/index.js +5 -0
  14. package/build/operators/AND/operator.d.ts +3 -0
  15. package/build/operators/{logicalAnd.js → AND/operator.js} +28 -8
  16. package/build/operators/BUILD_OBJECT/data.d.ts +4 -0
  17. package/build/operators/BUILD_OBJECT/data.js +22 -0
  18. package/build/operators/BUILD_OBJECT/index.d.ts +1 -0
  19. package/build/operators/BUILD_OBJECT/index.js +17 -0
  20. package/build/operators/BUILD_OBJECT/operator.d.ts +2 -0
  21. package/build/operators/{buildObject.js → BUILD_OBJECT/operator.js} +28 -12
  22. package/build/operators/CONDITIONAL/data.d.ts +4 -0
  23. package/build/operators/CONDITIONAL/data.js +36 -0
  24. package/build/operators/CONDITIONAL/index.d.ts +1 -0
  25. package/build/operators/CONDITIONAL/index.js +17 -0
  26. package/build/operators/CONDITIONAL/operator.d.ts +2 -0
  27. package/build/operators/CONDITIONAL/operator.js +59 -0
  28. package/build/operators/COUNT/data.d.ts +4 -0
  29. package/build/operators/COUNT/data.js +22 -0
  30. package/build/operators/COUNT/index.d.ts +1 -0
  31. package/build/operators/COUNT/index.js +17 -0
  32. package/build/operators/COUNT/operator.d.ts +2 -0
  33. package/build/operators/COUNT/operator.js +49 -0
  34. package/build/operators/CUSTOM_FUNCTIONS/data.d.ts +4 -0
  35. package/build/operators/CUSTOM_FUNCTIONS/data.js +43 -0
  36. package/build/operators/CUSTOM_FUNCTIONS/index.d.ts +1 -0
  37. package/build/operators/CUSTOM_FUNCTIONS/index.js +17 -0
  38. package/build/operators/CUSTOM_FUNCTIONS/operator.d.ts +2 -0
  39. package/build/operators/CUSTOM_FUNCTIONS/operator.js +65 -0
  40. package/build/operators/DIVIDE/data.d.ts +4 -0
  41. package/build/operators/DIVIDE/data.js +43 -0
  42. package/build/operators/DIVIDE/index.d.ts +1 -0
  43. package/build/operators/DIVIDE/index.js +17 -0
  44. package/build/operators/DIVIDE/operator.d.ts +2 -0
  45. package/build/operators/DIVIDE/operator.js +63 -0
  46. package/build/operators/EQUAL/data.d.ts +4 -0
  47. package/build/operators/EQUAL/data.js +29 -0
  48. package/build/operators/EQUAL/index.d.ts +1 -0
  49. package/build/operators/EQUAL/index.js +17 -0
  50. package/build/operators/EQUAL/operator.d.ts +2 -0
  51. package/build/operators/{equal.js → EQUAL/operator.js} +30 -10
  52. package/build/operators/GET/data.d.ts +4 -0
  53. package/build/operators/GET/data.js +50 -0
  54. package/build/operators/GET/index.d.ts +1 -0
  55. package/build/operators/GET/index.js +5 -0
  56. package/build/operators/GET/operator.d.ts +3 -0
  57. package/build/operators/GET/operator.js +91 -0
  58. package/build/operators/GRAPHQL/data.d.ts +4 -0
  59. package/build/operators/GRAPHQL/data.js +57 -0
  60. package/build/operators/GRAPHQL/index.d.ts +1 -0
  61. package/build/operators/GRAPHQL/index.js +17 -0
  62. package/build/operators/GRAPHQL/operator.d.ts +8 -0
  63. package/build/operators/{graphQL.js → GRAPHQL/operator.js} +47 -15
  64. package/build/operators/GREATER_THAN/data.d.ts +4 -0
  65. package/build/operators/GREATER_THAN/data.js +29 -0
  66. package/build/operators/GREATER_THAN/index.d.ts +1 -0
  67. package/build/operators/GREATER_THAN/index.js +17 -0
  68. package/build/operators/GREATER_THAN/operator.d.ts +2 -0
  69. package/build/operators/GREATER_THAN/operator.js +54 -0
  70. package/build/operators/LESS_THAN/data.d.ts +4 -0
  71. package/build/operators/LESS_THAN/data.js +29 -0
  72. package/build/operators/LESS_THAN/index.d.ts +1 -0
  73. package/build/operators/LESS_THAN/index.js +17 -0
  74. package/build/operators/{lessThan.d.ts → LESS_THAN/operator.d.ts} +1 -1
  75. package/build/operators/LESS_THAN/operator.js +54 -0
  76. package/build/operators/MATCH/data.d.ts +4 -0
  77. package/build/operators/MATCH/data.js +29 -0
  78. package/build/operators/MATCH/index.d.ts +1 -0
  79. package/build/operators/MATCH/index.js +17 -0
  80. package/build/operators/MATCH/operator.d.ts +2 -0
  81. package/build/operators/{match.js → MATCH/operator.js} +36 -17
  82. package/build/operators/MULTIPLY/data.d.ts +4 -0
  83. package/build/operators/MULTIPLY/data.js +22 -0
  84. package/build/operators/MULTIPLY/index.d.ts +1 -0
  85. package/build/operators/MULTIPLY/index.js +17 -0
  86. package/build/operators/{multiply.d.ts → MULTIPLY/operator.d.ts} +1 -1
  87. package/build/operators/MULTIPLY/operator.js +53 -0
  88. package/build/operators/NOT_EQUAL/data.d.ts +4 -0
  89. package/build/operators/NOT_EQUAL/data.js +29 -0
  90. package/build/operators/NOT_EQUAL/index.d.ts +1 -0
  91. package/build/operators/NOT_EQUAL/index.js +17 -0
  92. package/build/operators/{notEqual.d.ts → NOT_EQUAL/operator.d.ts} +1 -1
  93. package/build/operators/{notEqual.js → NOT_EQUAL/operator.js} +30 -10
  94. package/build/operators/OBJECT_PROPERTIES/data.d.ts +4 -0
  95. package/build/operators/OBJECT_PROPERTIES/data.js +37 -0
  96. package/build/operators/OBJECT_PROPERTIES/index.d.ts +1 -0
  97. package/build/operators/OBJECT_PROPERTIES/index.js +17 -0
  98. package/build/operators/OBJECT_PROPERTIES/operator.d.ts +2 -0
  99. package/build/operators/{objectProperties.js → OBJECT_PROPERTIES/operator.js} +32 -24
  100. package/build/operators/OR/data.d.ts +4 -0
  101. package/build/operators/OR/data.js +22 -0
  102. package/build/operators/OR/index.d.ts +1 -0
  103. package/build/operators/OR/index.js +17 -0
  104. package/build/operators/OR/operator.d.ts +2 -0
  105. package/build/operators/OR/operator.js +49 -0
  106. package/build/operators/PASSTHRU/data.d.ts +4 -0
  107. package/build/operators/PASSTHRU/data.js +22 -0
  108. package/build/operators/PASSTHRU/index.d.ts +1 -0
  109. package/build/operators/PASSTHRU/index.js +17 -0
  110. package/build/operators/PASSTHRU/operator.d.ts +2 -0
  111. package/build/operators/PASSTHRU/operator.js +53 -0
  112. package/build/operators/PG_SQL/data.d.ts +4 -0
  113. package/build/operators/PG_SQL/data.js +43 -0
  114. package/build/operators/PG_SQL/index.d.ts +1 -0
  115. package/build/operators/PG_SQL/index.js +17 -0
  116. package/build/operators/PG_SQL/operator.d.ts +2 -0
  117. package/build/operators/PG_SQL/operator.js +83 -0
  118. package/build/operators/PLUS/data.d.ts +4 -0
  119. package/build/operators/PLUS/data.js +29 -0
  120. package/build/operators/PLUS/index.d.ts +1 -0
  121. package/build/operators/PLUS/index.js +17 -0
  122. package/build/operators/PLUS/operator.d.ts +2 -0
  123. package/build/operators/{plus.js → PLUS/operator.js} +37 -13
  124. package/build/operators/POST/data.d.ts +4 -0
  125. package/build/operators/POST/data.js +50 -0
  126. package/build/operators/POST/index.d.ts +1 -0
  127. package/build/operators/POST/index.js +17 -0
  128. package/build/operators/POST/operator.d.ts +2 -0
  129. package/build/operators/POST/operator.js +72 -0
  130. package/build/operators/REGEX/data.d.ts +4 -0
  131. package/build/operators/REGEX/data.js +29 -0
  132. package/build/operators/REGEX/index.d.ts +1 -0
  133. package/build/operators/REGEX/index.js +17 -0
  134. package/build/operators/REGEX/operator.d.ts +2 -0
  135. package/build/operators/{regex.js → REGEX/operator.js} +29 -16
  136. package/build/operators/SPLIT/data.d.ts +4 -0
  137. package/build/operators/SPLIT/data.js +43 -0
  138. package/build/operators/SPLIT/index.d.ts +1 -0
  139. package/build/operators/SPLIT/index.js +17 -0
  140. package/build/operators/SPLIT/operator.d.ts +2 -0
  141. package/build/operators/{split.js → SPLIT/operator.js} +33 -15
  142. package/build/operators/STRING_SUBSTITUTION/data.d.ts +4 -0
  143. package/build/operators/STRING_SUBSTITUTION/data.js +29 -0
  144. package/build/operators/STRING_SUBSTITUTION/index.d.ts +1 -0
  145. package/build/operators/STRING_SUBSTITUTION/index.js +17 -0
  146. package/build/operators/STRING_SUBSTITUTION/operator.d.ts +2 -0
  147. package/build/operators/STRING_SUBSTITUTION/operator.js +59 -0
  148. package/build/operators/SUBTRACT/data.d.ts +4 -0
  149. package/build/operators/SUBTRACT/data.js +36 -0
  150. package/build/operators/SUBTRACT/index.d.ts +1 -0
  151. package/build/operators/SUBTRACT/index.js +17 -0
  152. package/build/operators/SUBTRACT/operator.d.ts +2 -0
  153. package/build/operators/SUBTRACT/operator.js +54 -0
  154. package/build/operators/_operatorAliases.json +1 -0
  155. package/build/operators/_operatorUtils.d.ts +19 -12
  156. package/build/operators/_operatorUtils.js +33 -15
  157. package/build/operators/index.d.ts +24 -24
  158. package/build/operators/index.js +24 -27
  159. package/build/shorthandSyntax.d.ts +2 -0
  160. package/build/shorthandSyntax.js +55 -0
  161. package/build/typeCheck.d.ts +8 -4
  162. package/build/typeCheck.js +25 -19
  163. package/build/types.d.ts +51 -34
  164. package/build/version.d.ts +1 -0
  165. package/build/version.js +4 -0
  166. package/package.json +10 -3
  167. package/build/operators/buildObject.d.ts +0 -11
  168. package/build/operators/conditional.d.ts +0 -7
  169. package/build/operators/conditional.js +0 -33
  170. package/build/operators/count.d.ts +0 -2
  171. package/build/operators/count.js +0 -29
  172. package/build/operators/customFunctions.d.ts +0 -9
  173. package/build/operators/customFunctions.js +0 -57
  174. package/build/operators/divide.d.ts +0 -12
  175. package/build/operators/divide.js +0 -41
  176. package/build/operators/equal.d.ts +0 -2
  177. package/build/operators/getRequest.d.ts +0 -12
  178. package/build/operators/getRequest.js +0 -51
  179. package/build/operators/graphQL.d.ts +0 -18
  180. package/build/operators/greaterThan.d.ts +0 -6
  181. package/build/operators/greaterThan.js +0 -35
  182. package/build/operators/lessThan.js +0 -35
  183. package/build/operators/logicalAnd.d.ts +0 -8
  184. package/build/operators/logicalOr.d.ts +0 -2
  185. package/build/operators/logicalOr.js +0 -29
  186. package/build/operators/match.d.ts +0 -7
  187. package/build/operators/multiply.js +0 -29
  188. package/build/operators/objectProperties.d.ts +0 -9
  189. package/build/operators/passThru.d.ts +0 -7
  190. package/build/operators/passThru.js +0 -30
  191. package/build/operators/pgSQL.d.ts +0 -24
  192. package/build/operators/pgSQL.js +0 -70
  193. package/build/operators/plus.d.ts +0 -10
  194. package/build/operators/postRequest.d.ts +0 -2
  195. package/build/operators/postRequest.js +0 -43
  196. package/build/operators/regex.d.ts +0 -7
  197. package/build/operators/split.d.ts +0 -11
  198. package/build/operators/stringSubstitution.d.ts +0 -7
  199. package/build/operators/stringSubstitution.js +0 -40
  200. package/build/operators/subtract.d.ts +0 -9
  201. package/build/operators/subtract.js +0 -32
@@ -1,17 +1,24 @@
1
- import { GenericObject, EvaluatorNode, EvaluatorOutput, FigTreeConfig } from '../types';
2
- export declare const evaluateArray: (nodes: EvaluatorNode[], params: FigTreeConfig) => Promise<EvaluatorOutput[]>;
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { EvaluatorNode, EvaluatorOutput, FigTreeConfig, Parameter } from '../types';
3
+ export declare const getPropertyAliases: (parameters: Parameter[]) => Record<string, string>;
4
+ export declare const getTypeCheckInput: (parameterDefinitions: Parameter[], params: Record<string, unknown>) => ({
5
+ name: string;
6
+ value: unknown;
7
+ expectedType: {
8
+ literal: (string | undefined)[];
9
+ };
10
+ } | {
11
+ name: string;
12
+ value: unknown;
13
+ expectedType: import("../typeCheck").BasicType | import("../typeCheck").BasicType[];
14
+ })[];
15
+ export declare const evaluateArray: (nodes: EvaluatorNode[] | EvaluatorNode, params: FigTreeConfig) => Promise<EvaluatorOutput[]>;
3
16
  export declare const zipArraysToObject: <T>(keys: string[], values: T[]) => {
4
17
  [x: string]: T;
5
18
  };
6
- export declare const singleArrayToObject: (elements: any[]) => any;
7
- export declare const simplifyObject: (item: number | string | boolean | GenericObject) => any;
8
- export declare const extractAndSimplify: (data: GenericObject | GenericObject[], returnProperty: string | undefined, fallback?: any) => any;
19
+ export declare const singleArrayToObject: <T>(elements: unknown[]) => Record<string, T>;
20
+ export declare const simplifyObject: (item: unknown) => any;
21
+ export declare const extractAndSimplify: (data: object | object[], returnProperty: string | undefined, fallback?: unknown) => any;
9
22
  export declare const isFullUrl: (url: string) => boolean;
10
23
  export declare const joinUrlParts: (...urls: string[]) => string;
11
- export declare const axiosRequest: ({ url, params, data, headers, method, }: {
12
- url: string;
13
- params?: GenericObject | undefined;
14
- data?: GenericObject | undefined;
15
- headers?: GenericObject | undefined;
16
- method?: "get" | "post" | undefined;
17
- }) => Promise<any>;
24
+ export declare const axiosRequest: ({ url, params, data, headers, method, }: AxiosRequestConfig) => Promise<any>;
@@ -12,11 +12,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.axiosRequest = exports.joinUrlParts = exports.isFullUrl = exports.extractAndSimplify = exports.simplifyObject = exports.singleArrayToObject = exports.zipArraysToObject = exports.evaluateArray = void 0;
15
+ exports.axiosRequest = exports.joinUrlParts = exports.isFullUrl = exports.extractAndSimplify = exports.simplifyObject = exports.singleArrayToObject = exports.zipArraysToObject = exports.evaluateArray = exports.getTypeCheckInput = exports.getPropertyAliases = void 0;
16
16
  const axios_1 = __importDefault(require("axios"));
17
17
  const extract_1 = __importDefault(require("object-property-extractor/build/extract"));
18
18
  const evaluate_1 = require("../evaluate");
19
+ const helpers_1 = require("../helpers");
19
20
  const typeCheck_1 = require("../typeCheck");
21
+ const getPropertyAliases = (parameters) => {
22
+ const propertyAliases = {};
23
+ parameters.forEach((param) => {
24
+ param.aliases.forEach((alias) => (propertyAliases[alias] = param.name));
25
+ });
26
+ return propertyAliases;
27
+ };
28
+ exports.getPropertyAliases = getPropertyAliases;
29
+ const getTypeCheckInput = (parameterDefinitions, params) => parameterDefinitions.map(({ name, required, type }) => {
30
+ if ((0, typeCheck_1.isLiteralType)(type)) {
31
+ const literal = [...type.literal];
32
+ if (!required)
33
+ literal.push(undefined);
34
+ return { name, value: params[name], expectedType: { literal } };
35
+ }
36
+ const allTypes = Array.isArray(type) ? type : [type];
37
+ if (!required)
38
+ allTypes.push('undefined');
39
+ const expectedType = allTypes.length === 1 ? allTypes[0] : allTypes;
40
+ return { name, value: params[name], expectedType };
41
+ });
42
+ exports.getTypeCheckInput = getTypeCheckInput;
20
43
  const evaluateArray = (nodes, params) => __awaiter(void 0, void 0, void 0, function* () {
21
44
  if (!Array.isArray(nodes))
22
45
  return (yield (0, evaluate_1.evaluatorFunction)(nodes, params));
@@ -47,24 +70,19 @@ const singleArrayToObject = (elements) => {
47
70
  };
48
71
  exports.singleArrayToObject = singleArrayToObject;
49
72
  const simplifyObject = (item) => {
50
- return item instanceof Object && Object.keys(item).length === 1 ? Object.values(item)[0] : item;
73
+ return (0, helpers_1.isObject)(item) && Object.keys(item).length === 1 ? Object.values(item)[0] : item;
51
74
  };
52
75
  exports.simplifyObject = simplifyObject;
53
76
  const extractAndSimplify = (data, returnProperty, fallback = undefined) => {
54
- try {
55
- const selectedProperty = returnProperty ? (0, extract_1.default)(data, returnProperty, fallback) : data;
56
- if (Array.isArray(selectedProperty))
57
- return selectedProperty.map((item) => (0, exports.simplifyObject)(item));
58
- if (returnProperty) {
59
- if (selectedProperty === null)
60
- return null;
61
- return (0, exports.simplifyObject)(selectedProperty);
62
- }
63
- return selectedProperty;
64
- }
65
- catch (err) {
66
- throw err;
77
+ const selectedProperty = returnProperty ? (0, extract_1.default)(data, returnProperty, fallback) : data;
78
+ if (Array.isArray(selectedProperty))
79
+ return selectedProperty.map((item) => (0, exports.simplifyObject)(item));
80
+ if (returnProperty) {
81
+ if (selectedProperty === null)
82
+ return null;
83
+ return (0, exports.simplifyObject)(selectedProperty);
67
84
  }
85
+ return selectedProperty;
68
86
  };
69
87
  exports.extractAndSimplify = extractAndSimplify;
70
88
  const isFullUrl = (url) => /^https?:\/\/.+/.test(url);
@@ -1,24 +1,24 @@
1
- export * from './logicalOr';
2
- export { AND, type BasicExtendedNode } from './logicalAnd';
3
- export * from './equal';
4
- export * from './notEqual';
5
- export * from './plus';
6
- export * from './subtract';
7
- export * from './multiply';
8
- export * from './divide';
9
- export * from './greaterThan';
10
- export * from './lessThan';
11
- export * from './conditional';
12
- export * from './regex';
13
- export * from './objectProperties';
14
- export * from './stringSubstitution';
15
- export * from './count';
16
- export * from './split';
17
- export * from './pgSQL';
18
- export * from './graphQL';
19
- export { GET, type APINode } from './getRequest';
20
- export * from './postRequest';
21
- export * from './buildObject';
22
- export * from './match';
23
- export * from './customFunctions';
24
- export * from './passThru';
1
+ export * from './AND';
2
+ export * from './OR';
3
+ export * from './EQUAL';
4
+ export * from './NOT_EQUAL';
5
+ export * from './PLUS';
6
+ export * from './SUBTRACT';
7
+ export * from './MULTIPLY';
8
+ export * from './DIVIDE';
9
+ export * from './GREATER_THAN';
10
+ export * from './LESS_THAN';
11
+ export * from './CONDITIONAL';
12
+ export * from './REGEX';
13
+ export * from './OBJECT_PROPERTIES';
14
+ export * from './STRING_SUBSTITUTION';
15
+ export * from './COUNT';
16
+ export * from './SPLIT';
17
+ export * from './PG_SQL';
18
+ export * from './GRAPHQL';
19
+ export * from './GET';
20
+ export * from './POST';
21
+ export * from './BUILD_OBJECT';
22
+ export * from './MATCH';
23
+ export * from './CUSTOM_FUNCTIONS';
24
+ export * from './PASSTHRU';
@@ -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,8 +1,12 @@
1
- export type ExpectedType = 'string' | 'boolean' | 'number' | 'array' | 'undefined' | 'null' | 'object';
1
+ export type BasicType = 'any' | 'string' | 'boolean' | 'number' | 'array' | 'object' | 'null' | 'undefined';
2
+ export type LiteralType = {
3
+ literal: (string | undefined)[];
4
+ };
5
+ export type ExpectedType = BasicType | LiteralType | BasicType[];
2
6
  export type TypeCheckInput = {
3
- value: unknown;
4
7
  name?: string;
5
- not?: boolean;
6
- expectedType: ExpectedType | ExpectedType[];
8
+ value: unknown;
9
+ expectedType: ExpectedType;
7
10
  };
11
+ export declare const isLiteralType: (typeDefinition: ExpectedType) => typeDefinition is LiteralType;
8
12
  export declare const typeCheck: (...args: TypeCheckInput[]) => true | string;
@@ -1,22 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typeCheck = void 0;
3
+ exports.typeCheck = exports.isLiteralType = void 0;
4
4
  const helpers_1 = require("./helpers");
5
- const typeCheckItem = ({ value, name, not = false, expectedType, }) => {
6
- let result;
7
- if (Array.isArray(expectedType)) {
8
- result = expectedType.some((type) => typeCheckItem({ value, name, expectedType: type }) === true);
9
- if (not)
10
- result = !result;
11
- return result ? true : makeErrorString(name, value, expectedType.join('|'), not);
5
+ const isLiteralType = (typeDefinition) => (0, helpers_1.isObject)(typeDefinition) && 'literal' in typeDefinition;
6
+ exports.isLiteralType = isLiteralType;
7
+ const typeCheckItem = ({ value, name, expectedType }) => {
8
+ if ((0, exports.isLiteralType)(expectedType)) {
9
+ const { literal } = expectedType;
10
+ return literal.includes(value)
11
+ ? true
12
+ : makeErrorString(name, value, `Literal(${literal
13
+ .map((val) => (val === undefined ? `undefined` : `"${val}"`))
14
+ .join(', ')})`);
12
15
  }
13
- else {
14
- const checker = typeCheckMap[expectedType];
15
- result = checker(value);
16
- if (not)
17
- result = !result;
18
- return result ? true : makeErrorString(name, value, expectedType, not);
16
+ if (Array.isArray(expectedType)) {
17
+ return expectedType.some((type) => typeCheckItem({ value, name, expectedType: type }) === true)
18
+ ? true
19
+ : makeErrorString(name, value, expectedType.join('|'));
19
20
  }
21
+ const checker = typeCheckMap[expectedType];
22
+ return checker(value) ? true : makeErrorString(name, value, expectedType);
20
23
  };
21
24
  const typeCheck = (...args) => {
22
25
  const errorStrings = [];
@@ -29,18 +32,21 @@ const typeCheck = (...args) => {
29
32
  };
30
33
  exports.typeCheck = typeCheck;
31
34
  const typeCheckMap = {
35
+ any: (value) => value !== undefined,
32
36
  string: (value) => typeof value === 'string',
33
37
  number: (value) => typeof value === 'number',
34
38
  boolean: (value) => typeof value === 'boolean',
35
39
  array: (value) => Array.isArray(value),
36
- undefined: (value) => value === undefined,
37
40
  null: (value) => value === null,
38
- object: (value) => typeof value === 'object' && !Array.isArray(value) && value !== null,
41
+ object: (value) => (0, helpers_1.isObject)(value),
42
+ undefined: (value) => value === undefined,
39
43
  };
40
- const makeErrorString = (name, value, type, not) => {
44
+ const makeErrorString = (name, value, type) => {
45
+ if (value === undefined && !!name)
46
+ return `- Missing required property "${name}" (type: ${type})`;
41
47
  if (name !== undefined)
42
- return `- Property "${name}" (value: ${stringifyValue(value)}) is not of type: ${not ? `!(${type})` : type}`;
43
- return `- ${stringifyValue(value)} is not of type: ${not ? `!(${type})` : type}`;
48
+ return `- Property "${name}" (value: ${stringifyValue(value)}) is not of type: ${type}`;
49
+ return `- ${stringifyValue(value)} is not of type: ${type}`;
44
50
  };
45
51
  const stringifyValue = (value) => {
46
52
  const stringValue = value === undefined || Number.isNaN(value) ? String(value) : JSON.stringify(value);
package/build/types.d.ts CHANGED
@@ -1,24 +1,20 @@
1
1
  import FigTreeCache from './cache';
2
- import { BasicExtendedNode, SubtractionNode, DivisionNode, ComparatorNode, ConditionalNode, RegexNode, StringSubNode, SplitNode, ObjPropNode, APINode, PGNode, GraphQLNode, BuildObjectNode, MatchNode, FunctionNode, PassThruNode, PGConnection, GraphQLConnection } from './operators';
2
+ import { Client } from 'pg';
3
+ import { GraphQLConnection } from './operators';
3
4
  import operatorAliases from './operators/_operatorAliases.json';
4
- import { TypeCheckInput } from './typeCheck';
5
+ import { ExpectedType, TypeCheckInput } from './typeCheck';
5
6
  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
7
  export type Operator = typeof Operators[number];
7
- export type GenericObject = {
8
- [key: string]: any;
9
- };
10
8
  export type OperatorAlias = keyof typeof operatorAliases;
11
9
  export type OperatorAliases = Record<OperatorAlias, Operator>;
10
+ export type Fragments = Record<string, Fragment>;
11
+ export type UnknownFunction = (...args: any[]) => EvaluatorOutput;
12
12
  export interface FigTreeOptions {
13
- data?: GenericObject;
14
- objects?: GenericObject;
15
- functions?: {
16
- [key: string]: Function;
17
- };
18
- fragments?: {
19
- [key: string]: EvaluatorNode;
20
- };
21
- pgConnection?: PGConnection;
13
+ data?: object;
14
+ objects?: object;
15
+ functions?: Record<string, UnknownFunction>;
16
+ fragments?: Fragments;
17
+ pgConnection?: Client;
22
18
  graphQLConnection?: GraphQLConnection;
23
19
  baseEndpoint?: string;
24
20
  headers?: {
@@ -27,9 +23,10 @@ export interface FigTreeOptions {
27
23
  returnErrorAsString?: boolean;
28
24
  nullEqualsUndefined?: boolean;
29
25
  allowJSONStringInput?: boolean;
26
+ noShorthand?: boolean;
30
27
  skipRuntimeTypeCheck?: boolean;
31
28
  evaluateFullObject?: boolean;
32
- excludeOperators?: string[];
29
+ excludeOperators?: OperatorAlias[];
33
30
  useCache?: boolean;
34
31
  maxCacheSize?: number;
35
32
  supportDeprecatedValueNodes?: boolean;
@@ -38,41 +35,61 @@ export interface FigTreeConfig {
38
35
  options: FigTreeOptions;
39
36
  operators: OperatorReference;
40
37
  operatorAliases: OperatorAliases;
41
- typeChecker: (...input: TypeCheckInput[]) => void;
38
+ typeChecker: (...args: TypeCheckInput[] | [TypeCheckInput[]]) => void;
42
39
  resolvedAliasNodes: {
43
40
  [key: string]: EvaluatorOutput;
44
41
  };
45
42
  cache: FigTreeCache;
46
43
  }
47
44
  export type OutputType = 'string' | 'number' | 'boolean' | 'bool' | 'array';
48
- export interface BaseOperatorNode {
49
- operator: Operator;
45
+ export interface OperatorNode {
46
+ operator: OperatorAlias;
50
47
  outputType?: OutputType;
51
- children?: Array<EvaluatorNode>;
52
- fallback?: any;
48
+ children?: EvaluatorNode[];
49
+ fallback?: EvaluatorNode;
53
50
  useCache?: boolean;
54
51
  [key: string]: EvaluatorNode;
55
52
  }
56
53
  export interface FragmentNode {
57
54
  fragment: string;
58
- parameters?: {
59
- [key: string]: EvaluatorNode;
60
- };
55
+ parameters?: Record<string, EvaluatorNode>;
61
56
  [key: string]: EvaluatorNode;
62
57
  }
63
- 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;
65
- export type EvaluatorOutput = string | boolean | number | GenericObject | null | undefined | any[];
66
- export type EvaluatorNode = CombinedOperatorNode | FragmentNode | EvaluatorOutput;
58
+ export interface FragmentMetadata {
59
+ description?: string;
60
+ parameters?: Record<string, {
61
+ type: string | string[];
62
+ required: boolean;
63
+ }>;
64
+ }
65
+ export type Fragment = (EvaluatorNode & {
66
+ metadata?: FragmentMetadata;
67
+ }) | null;
68
+ export type EvaluatorOutput = string | boolean | number | object | null | undefined | Array<EvaluatorOutput>;
69
+ export type EvaluatorNode = OperatorNode | FragmentNode | EvaluatorOutput;
67
70
  export type OperatorObject = {
68
- requiredProperties: readonly string[];
69
- operatorAliases: string[];
70
- propertyAliases: {
71
- [key: string]: string;
72
- };
73
- evaluate: (expression: CombinedOperatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
74
- parseChildren: (expression: CombinedOperatorNode, config: FigTreeConfig) => OperatorNodeUnion | Promise<OperatorNodeUnion>;
71
+ propertyAliases: Record<string, string>;
72
+ operatorData: OperatorData;
73
+ evaluate: EvaluateMethod;
74
+ parseChildren: ParseChildrenMethod;
75
75
  };
76
+ export type EvaluateMethod = (expression: OperatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
77
+ export type ParseChildrenMethod = (expression: OperatorNode, config: FigTreeConfig) => OperatorNode | Promise<OperatorNode>;
76
78
  export type OperatorReference = {
77
79
  [key in Operator]: OperatorObject;
78
80
  };
81
+ export type Parameter = {
82
+ name: string;
83
+ description: string;
84
+ aliases: string[];
85
+ required: boolean;
86
+ type: ExpectedType;
87
+ };
88
+ export interface OperatorData {
89
+ description: string;
90
+ aliases: string[];
91
+ parameters: Parameter[];
92
+ }
93
+ export interface OperatorMetadata extends OperatorData {
94
+ operator: Operator;
95
+ }
@@ -0,0 +1 @@
1
+ export declare const version = "2.8.3";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = void 0;
4
+ exports.version = '2.8.3';
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.3",
4
4
  "description": "Module to evaluate JSON-structured expression trees",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -16,7 +16,10 @@
16
16
  "@types/jest": "^27.5.1",
17
17
  "@types/node": "^17.0.38",
18
18
  "@types/pg": "^8.6.5",
19
+ "@typescript-eslint/eslint-plugin": "^5.57.0",
20
+ "@typescript-eslint/parser": "^5.57.0",
19
21
  "dotenv": "^16.0.1",
22
+ "eslint": "^8.37.0",
20
23
  "jest": "^28.1.0",
21
24
  "pg": "^8.7.3",
22
25
  "rimraf": "^3.0.2",
@@ -28,9 +31,13 @@
28
31
  "setup": "yarn install && cd demo && yarn install",
29
32
  "test": "jest",
30
33
  "generate": "ts-node ./codegen/buildOperatorAliasReference.ts",
31
- "build": "yarn generate && rimraf ./build && tsc",
34
+ "generateMassiveQuery": "ts-node ./codegen/generateMassiveQuery.ts",
35
+ "getVersion": "ts-node ./codegen/getVersion.ts",
36
+ "lint": "eslint . --ext .ts",
37
+ "build": "rimraf ./build && tsc",
38
+ "prebuild": "yarn generate && yarn getVersion",
32
39
  "dev": "cp -n src/dev/playground_example.ts src/dev/playground.ts || ts-node src/dev/playground.ts",
33
- "demo": "cd demo && yarn start",
40
+ "demo": "yarn getVersion && cd demo && yarn start",
34
41
  "prepublishOnly": "yarn build"
35
42
  },
36
43
  "dependencies": {
@@ -1,11 +0,0 @@
1
- import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../types';
2
- declare const requiredProperties: readonly ["properties"];
3
- export type BuildObjectNode = {
4
- [key in typeof requiredProperties[number]]: BuildObjectElement[];
5
- } & BaseOperatorNode;
6
- type BuildObjectElement = {
7
- key: EvaluatorNode;
8
- value: EvaluatorNode;
9
- };
10
- export declare const BUILD_OBJECT: OperatorObject;
11
- export {};
@@ -1,7 +0,0 @@
1
- import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../types';
2
- declare const requiredProperties: readonly ["condition", "valueIfTrue", "valueIfFalse"];
3
- export type ConditionalNode = {
4
- [key in typeof requiredProperties[number]]: EvaluatorNode;
5
- } & BaseOperatorNode;
6
- export declare const CONDITIONAL: OperatorObject;
7
- export {};
@@ -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.CONDITIONAL = void 0;
13
- const evaluate_1 = require("../evaluate");
14
- const requiredProperties = ['condition', 'valueIfTrue', 'valueIfFalse'];
15
- const operatorAliases = ['?', 'conditional', 'ifThen'];
16
- const propertyAliases = { ifTrue: 'valueIfTrue', ifFalse: 'valueIfFalse', ifNot: 'valueIfFalse' };
17
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
18
- const condition = yield (0, evaluate_1.evaluatorFunction)(expression.condition, config);
19
- return !!condition
20
- ? yield (0, evaluate_1.evaluatorFunction)(expression.valueIfTrue, config)
21
- : yield (0, evaluate_1.evaluatorFunction)(expression.valueIfFalse, config);
22
- });
23
- const parseChildren = (expression) => {
24
- const [condition, valueIfTrue, valueIfFalse] = expression.children;
25
- return Object.assign(Object.assign({}, expression), { condition, valueIfTrue, valueIfFalse });
26
- };
27
- exports.CONDITIONAL = {
28
- requiredProperties,
29
- operatorAliases,
30
- propertyAliases,
31
- evaluate,
32
- parseChildren,
33
- };
@@ -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,9 +0,0 @@
1
- import { BaseOperatorNode, EvaluatorNode, OperatorObject } from '../types';
2
- declare const requiredProperties: readonly ["functionPath"];
3
- export type FunctionNode = {
4
- [key in typeof requiredProperties[number]]: EvaluatorNode;
5
- } & BaseOperatorNode & {
6
- args: EvaluatorNode[];
7
- };
8
- export declare const CUSTOM_FUNCTIONS: OperatorObject;
9
- export {};