fig-tree-evaluator 2.10.0 → 2.11.4

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 (171) hide show
  1. package/README.md +3 -2
  2. package/build/index.cjs.js +1 -0
  3. package/build/index.d.ts +121 -4
  4. package/build/index.esm.js +1 -0
  5. package/package.json +14 -5
  6. package/build/FigTreeEvaluator.d.ts +0 -26
  7. package/build/FigTreeEvaluator.js +0 -121
  8. package/build/cache.d.ts +0 -27
  9. package/build/cache.js +0 -63
  10. package/build/evaluate.d.ts +0 -2
  11. package/build/evaluate.js +0 -87
  12. package/build/helpers.d.ts +0 -23
  13. package/build/helpers.js +0 -137
  14. package/build/index.js +0 -29
  15. package/build/operators/AND/data.d.ts +0 -4
  16. package/build/operators/AND/data.js +0 -22
  17. package/build/operators/AND/index.d.ts +0 -1
  18. package/build/operators/AND/index.js +0 -5
  19. package/build/operators/AND/operator.d.ts +0 -3
  20. package/build/operators/AND/operator.js +0 -53
  21. package/build/operators/BUILD_OBJECT/data.d.ts +0 -4
  22. package/build/operators/BUILD_OBJECT/data.js +0 -22
  23. package/build/operators/BUILD_OBJECT/index.d.ts +0 -1
  24. package/build/operators/BUILD_OBJECT/index.js +0 -17
  25. package/build/operators/BUILD_OBJECT/operator.d.ts +0 -2
  26. package/build/operators/BUILD_OBJECT/operator.js +0 -64
  27. package/build/operators/CONDITIONAL/data.d.ts +0 -4
  28. package/build/operators/CONDITIONAL/data.js +0 -36
  29. package/build/operators/CONDITIONAL/index.d.ts +0 -1
  30. package/build/operators/CONDITIONAL/index.js +0 -17
  31. package/build/operators/CONDITIONAL/operator.d.ts +0 -2
  32. package/build/operators/CONDITIONAL/operator.js +0 -59
  33. package/build/operators/COUNT/data.d.ts +0 -4
  34. package/build/operators/COUNT/data.js +0 -22
  35. package/build/operators/COUNT/index.d.ts +0 -1
  36. package/build/operators/COUNT/index.js +0 -17
  37. package/build/operators/COUNT/operator.d.ts +0 -2
  38. package/build/operators/COUNT/operator.js +0 -52
  39. package/build/operators/CUSTOM_FUNCTIONS/data.d.ts +0 -4
  40. package/build/operators/CUSTOM_FUNCTIONS/data.js +0 -43
  41. package/build/operators/CUSTOM_FUNCTIONS/index.d.ts +0 -1
  42. package/build/operators/CUSTOM_FUNCTIONS/index.js +0 -17
  43. package/build/operators/CUSTOM_FUNCTIONS/operator.d.ts +0 -2
  44. package/build/operators/CUSTOM_FUNCTIONS/operator.js +0 -65
  45. package/build/operators/DIVIDE/data.d.ts +0 -4
  46. package/build/operators/DIVIDE/data.js +0 -43
  47. package/build/operators/DIVIDE/index.d.ts +0 -1
  48. package/build/operators/DIVIDE/index.js +0 -17
  49. package/build/operators/DIVIDE/operator.d.ts +0 -2
  50. package/build/operators/DIVIDE/operator.js +0 -63
  51. package/build/operators/EQUAL/data.d.ts +0 -4
  52. package/build/operators/EQUAL/data.js +0 -29
  53. package/build/operators/EQUAL/index.d.ts +0 -1
  54. package/build/operators/EQUAL/index.js +0 -17
  55. package/build/operators/EQUAL/operator.d.ts +0 -2
  56. package/build/operators/EQUAL/operator.js +0 -58
  57. package/build/operators/GET/data.d.ts +0 -4
  58. package/build/operators/GET/data.js +0 -50
  59. package/build/operators/GET/index.d.ts +0 -1
  60. package/build/operators/GET/index.js +0 -5
  61. package/build/operators/GET/operator.d.ts +0 -3
  62. package/build/operators/GET/operator.js +0 -91
  63. package/build/operators/GRAPHQL/data.d.ts +0 -4
  64. package/build/operators/GRAPHQL/data.js +0 -57
  65. package/build/operators/GRAPHQL/index.d.ts +0 -1
  66. package/build/operators/GRAPHQL/index.js +0 -17
  67. package/build/operators/GRAPHQL/operator.d.ts +0 -8
  68. package/build/operators/GRAPHQL/operator.js +0 -86
  69. package/build/operators/GREATER_THAN/data.d.ts +0 -4
  70. package/build/operators/GREATER_THAN/data.js +0 -29
  71. package/build/operators/GREATER_THAN/index.d.ts +0 -1
  72. package/build/operators/GREATER_THAN/index.js +0 -17
  73. package/build/operators/GREATER_THAN/operator.d.ts +0 -2
  74. package/build/operators/GREATER_THAN/operator.js +0 -54
  75. package/build/operators/LESS_THAN/data.d.ts +0 -4
  76. package/build/operators/LESS_THAN/data.js +0 -29
  77. package/build/operators/LESS_THAN/index.d.ts +0 -1
  78. package/build/operators/LESS_THAN/index.js +0 -17
  79. package/build/operators/LESS_THAN/operator.d.ts +0 -2
  80. package/build/operators/LESS_THAN/operator.js +0 -54
  81. package/build/operators/MATCH/data.d.ts +0 -4
  82. package/build/operators/MATCH/data.js +0 -29
  83. package/build/operators/MATCH/index.d.ts +0 -1
  84. package/build/operators/MATCH/index.js +0 -17
  85. package/build/operators/MATCH/operator.d.ts +0 -2
  86. package/build/operators/MATCH/operator.js +0 -72
  87. package/build/operators/MULTIPLY/data.d.ts +0 -4
  88. package/build/operators/MULTIPLY/data.js +0 -22
  89. package/build/operators/MULTIPLY/index.d.ts +0 -1
  90. package/build/operators/MULTIPLY/index.js +0 -17
  91. package/build/operators/MULTIPLY/operator.d.ts +0 -2
  92. package/build/operators/MULTIPLY/operator.js +0 -53
  93. package/build/operators/NOT_EQUAL/data.d.ts +0 -4
  94. package/build/operators/NOT_EQUAL/data.js +0 -29
  95. package/build/operators/NOT_EQUAL/index.d.ts +0 -1
  96. package/build/operators/NOT_EQUAL/index.js +0 -17
  97. package/build/operators/NOT_EQUAL/operator.d.ts +0 -2
  98. package/build/operators/NOT_EQUAL/operator.js +0 -58
  99. package/build/operators/OBJECT_PROPERTIES/data.d.ts +0 -4
  100. package/build/operators/OBJECT_PROPERTIES/data.js +0 -37
  101. package/build/operators/OBJECT_PROPERTIES/index.d.ts +0 -1
  102. package/build/operators/OBJECT_PROPERTIES/index.js +0 -17
  103. package/build/operators/OBJECT_PROPERTIES/operator.d.ts +0 -2
  104. package/build/operators/OBJECT_PROPERTIES/operator.js +0 -62
  105. package/build/operators/OR/data.d.ts +0 -4
  106. package/build/operators/OR/data.js +0 -22
  107. package/build/operators/OR/index.d.ts +0 -1
  108. package/build/operators/OR/index.js +0 -17
  109. package/build/operators/OR/operator.d.ts +0 -2
  110. package/build/operators/OR/operator.js +0 -49
  111. package/build/operators/PASSTHRU/data.d.ts +0 -4
  112. package/build/operators/PASSTHRU/data.js +0 -22
  113. package/build/operators/PASSTHRU/index.d.ts +0 -1
  114. package/build/operators/PASSTHRU/index.js +0 -17
  115. package/build/operators/PASSTHRU/operator.d.ts +0 -2
  116. package/build/operators/PASSTHRU/operator.js +0 -53
  117. package/build/operators/PG_SQL/data.d.ts +0 -4
  118. package/build/operators/PG_SQL/data.js +0 -43
  119. package/build/operators/PG_SQL/index.d.ts +0 -1
  120. package/build/operators/PG_SQL/index.js +0 -17
  121. package/build/operators/PG_SQL/operator.d.ts +0 -2
  122. package/build/operators/PG_SQL/operator.js +0 -83
  123. package/build/operators/PLUS/data.d.ts +0 -4
  124. package/build/operators/PLUS/data.js +0 -29
  125. package/build/operators/PLUS/index.d.ts +0 -1
  126. package/build/operators/PLUS/index.js +0 -17
  127. package/build/operators/PLUS/operator.d.ts +0 -2
  128. package/build/operators/PLUS/operator.js +0 -63
  129. package/build/operators/POST/data.d.ts +0 -4
  130. package/build/operators/POST/data.js +0 -50
  131. package/build/operators/POST/index.d.ts +0 -1
  132. package/build/operators/POST/index.js +0 -17
  133. package/build/operators/POST/operator.d.ts +0 -2
  134. package/build/operators/POST/operator.js +0 -72
  135. package/build/operators/REGEX/data.d.ts +0 -4
  136. package/build/operators/REGEX/data.js +0 -29
  137. package/build/operators/REGEX/index.d.ts +0 -1
  138. package/build/operators/REGEX/index.js +0 -17
  139. package/build/operators/REGEX/operator.d.ts +0 -2
  140. package/build/operators/REGEX/operator.js +0 -59
  141. package/build/operators/SPLIT/data.d.ts +0 -4
  142. package/build/operators/SPLIT/data.js +0 -43
  143. package/build/operators/SPLIT/index.d.ts +0 -1
  144. package/build/operators/SPLIT/index.js +0 -17
  145. package/build/operators/SPLIT/operator.d.ts +0 -2
  146. package/build/operators/SPLIT/operator.js +0 -69
  147. package/build/operators/STRING_SUBSTITUTION/data.d.ts +0 -4
  148. package/build/operators/STRING_SUBSTITUTION/data.js +0 -50
  149. package/build/operators/STRING_SUBSTITUTION/index.d.ts +0 -1
  150. package/build/operators/STRING_SUBSTITUTION/index.js +0 -17
  151. package/build/operators/STRING_SUBSTITUTION/operator.d.ts +0 -2
  152. package/build/operators/STRING_SUBSTITUTION/operator.js +0 -112
  153. package/build/operators/SUBTRACT/data.d.ts +0 -4
  154. package/build/operators/SUBTRACT/data.js +0 -36
  155. package/build/operators/SUBTRACT/index.d.ts +0 -1
  156. package/build/operators/SUBTRACT/index.js +0 -17
  157. package/build/operators/SUBTRACT/operator.d.ts +0 -2
  158. package/build/operators/SUBTRACT/operator.js +0 -54
  159. package/build/operators/_operatorAliases.json +0 -92
  160. package/build/operators/_operatorUtils.d.ts +0 -24
  161. package/build/operators/_operatorUtils.js +0 -122
  162. package/build/operators/index.d.ts +0 -24
  163. package/build/operators/index.js +0 -40
  164. package/build/shorthandSyntax.d.ts +0 -2
  165. package/build/shorthandSyntax.js +0 -55
  166. package/build/typeCheck.d.ts +0 -12
  167. package/build/typeCheck.js +0 -54
  168. package/build/types.d.ts +0 -96
  169. package/build/types.js +0 -29
  170. package/build/version.d.ts +0 -1
  171. package/build/version.js +0 -4
@@ -1,55 +0,0 @@
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,12 +0,0 @@
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[];
6
- export type TypeCheckInput = {
7
- name?: string;
8
- value: unknown;
9
- expectedType: ExpectedType;
10
- };
11
- export declare const isLiteralType: (typeDefinition: ExpectedType) => typeDefinition is LiteralType;
12
- export declare const typeCheck: (...args: TypeCheckInput[]) => true | string;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typeCheck = exports.isLiteralType = void 0;
4
- const helpers_1 = require("./helpers");
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(', ')})`);
15
- }
16
- if (Array.isArray(expectedType)) {
17
- return expectedType.some((type) => typeCheckItem({ value, name, expectedType: type }) === true)
18
- ? true
19
- : makeErrorString(name, value, expectedType.join('|'));
20
- }
21
- const checker = typeCheckMap[expectedType];
22
- return checker(value) ? true : makeErrorString(name, value, expectedType);
23
- };
24
- const typeCheck = (...args) => {
25
- const errorStrings = [];
26
- args.forEach((item) => {
27
- const result = typeCheckItem(item);
28
- if (result !== true)
29
- errorStrings.push(result);
30
- });
31
- return errorStrings.length > 0 ? errorStrings.join('\n') : true;
32
- };
33
- exports.typeCheck = typeCheck;
34
- const typeCheckMap = {
35
- any: (value) => value !== undefined,
36
- string: (value) => typeof value === 'string',
37
- number: (value) => typeof value === 'number',
38
- boolean: (value) => typeof value === 'boolean',
39
- array: (value) => Array.isArray(value),
40
- null: (value) => value === null,
41
- object: (value) => (0, helpers_1.isObject)(value),
42
- undefined: (value) => value === undefined,
43
- };
44
- const makeErrorString = (name, value, type) => {
45
- if (value === undefined && !!name)
46
- return `- Missing required property "${name}" (type: ${type})`;
47
- if (name !== undefined)
48
- return `- Property "${name}" (value: ${stringifyValue(value)}) is not of type: ${type}`;
49
- return `- ${stringifyValue(value)} is not of type: ${type}`;
50
- };
51
- const stringifyValue = (value) => {
52
- const stringValue = value === undefined || Number.isNaN(value) ? String(value) : JSON.stringify(value);
53
- return (0, helpers_1.truncateString)(stringValue, 50);
54
- };
package/build/types.d.ts DELETED
@@ -1,96 +0,0 @@
1
- import FigTreeCache from './cache';
2
- import { Client } from 'pg';
3
- import { GraphQLConnection } from './operators';
4
- import operatorAliases from './operators/_operatorAliases.json';
5
- import { ExpectedType, TypeCheckInput } from './typeCheck';
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"];
7
- export type Operator = (typeof Operators)[number];
8
- export type OperatorAlias = keyof typeof operatorAliases;
9
- export type OperatorAliases = Record<OperatorAlias, Operator>;
10
- export type Fragments = Record<string, Fragment>;
11
- export type UnknownFunction = (...args: any[]) => EvaluatorOutput;
12
- export interface FigTreeOptions {
13
- data?: object;
14
- objects?: object;
15
- functions?: Record<string, UnknownFunction>;
16
- fragments?: Fragments;
17
- pgConnection?: Client;
18
- graphQLConnection?: GraphQLConnection;
19
- baseEndpoint?: string;
20
- headers?: {
21
- [key: string]: string;
22
- };
23
- returnErrorAsString?: boolean;
24
- nullEqualsUndefined?: boolean;
25
- allowJSONStringInput?: boolean;
26
- noShorthand?: boolean;
27
- skipRuntimeTypeCheck?: boolean;
28
- evaluateFullObject?: boolean;
29
- excludeOperators?: OperatorAlias[];
30
- useCache?: boolean;
31
- maxCacheSize?: number;
32
- maxCacheTime?: number;
33
- supportDeprecatedValueNodes?: boolean;
34
- }
35
- export interface FigTreeConfig {
36
- options: FigTreeOptions;
37
- operators: OperatorReference;
38
- operatorAliases: OperatorAliases;
39
- typeChecker: (...args: TypeCheckInput[] | [TypeCheckInput[]]) => void;
40
- resolvedAliasNodes: {
41
- [key: string]: EvaluatorOutput;
42
- };
43
- cache: FigTreeCache;
44
- }
45
- export type OutputType = 'string' | 'number' | 'boolean' | 'bool' | 'array';
46
- export interface OperatorNode {
47
- operator: OperatorAlias;
48
- outputType?: OutputType;
49
- children?: EvaluatorNode[];
50
- fallback?: EvaluatorNode;
51
- useCache?: boolean;
52
- [key: string]: EvaluatorNode;
53
- }
54
- export interface FragmentNode {
55
- fragment: string;
56
- parameters?: Record<string, EvaluatorNode>;
57
- [key: string]: EvaluatorNode;
58
- }
59
- export interface FragmentMetadata {
60
- description?: string;
61
- parameters?: Record<string, {
62
- type: string | string[];
63
- required: boolean;
64
- }>;
65
- }
66
- export type Fragment = (EvaluatorNode & {
67
- metadata?: FragmentMetadata;
68
- }) | null;
69
- export type EvaluatorOutput = string | boolean | number | object | null | undefined | Array<EvaluatorOutput>;
70
- export type EvaluatorNode = OperatorNode | FragmentNode | EvaluatorOutput;
71
- export type OperatorObject = {
72
- propertyAliases: Record<string, string>;
73
- operatorData: OperatorData;
74
- evaluate: EvaluateMethod;
75
- parseChildren: ParseChildrenMethod;
76
- };
77
- export type EvaluateMethod = (expression: OperatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
78
- export type ParseChildrenMethod = (expression: OperatorNode, config: FigTreeConfig) => OperatorNode | Promise<OperatorNode>;
79
- export type OperatorReference = {
80
- [key in Operator]: OperatorObject;
81
- };
82
- export type Parameter = {
83
- name: string;
84
- description: string;
85
- aliases: string[];
86
- required: boolean;
87
- type: ExpectedType;
88
- };
89
- export interface OperatorData {
90
- description: string;
91
- aliases: string[];
92
- parameters: Parameter[];
93
- }
94
- export interface OperatorMetadata extends OperatorData {
95
- operator: Operator;
96
- }
package/build/types.js DELETED
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Operators = void 0;
4
- exports.Operators = [
5
- 'AND',
6
- 'OR',
7
- 'EQUAL',
8
- 'NOT_EQUAL',
9
- 'PLUS',
10
- 'SUBTRACT',
11
- 'MULTIPLY',
12
- 'DIVIDE',
13
- 'GREATER_THAN',
14
- 'LESS_THAN',
15
- 'CONDITIONAL',
16
- 'REGEX',
17
- 'OBJECT_PROPERTIES',
18
- 'STRING_SUBSTITUTION',
19
- 'SPLIT',
20
- 'COUNT',
21
- 'GET',
22
- 'POST',
23
- 'PG_SQL',
24
- 'GRAPHQL',
25
- 'BUILD_OBJECT',
26
- 'MATCH',
27
- 'CUSTOM_FUNCTIONS',
28
- 'PASSTHRU',
29
- ];
@@ -1 +0,0 @@
1
- export declare const version = "2.10.0";
package/build/version.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.version = void 0;
4
- exports.version = '2.10.0';