fig-tree-evaluator 2.8.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.
- package/README.md +1 -0
- package/build/FigTreeEvaluator.d.ts +6 -16
- package/build/FigTreeEvaluator.js +8 -4
- package/build/cache.d.ts +3 -1
- package/build/cache.js +10 -11
- package/build/evaluate.js +3 -5
- package/build/helpers.d.ts +8 -34
- package/build/helpers.js +1 -10
- package/build/index.d.ts +2 -2
- package/build/operators/AND/data.d.ts +0 -1
- package/build/operators/AND/data.js +1 -2
- package/build/operators/AND/index.d.ts +1 -1
- package/build/operators/AND/operator.d.ts +2 -6
- package/build/operators/AND/operator.js +1 -2
- package/build/operators/BUILD_OBJECT/data.d.ts +0 -1
- package/build/operators/BUILD_OBJECT/data.js +1 -2
- package/build/operators/BUILD_OBJECT/operator.d.ts +1 -9
- package/build/operators/BUILD_OBJECT/operator.js +1 -2
- package/build/operators/CONDITIONAL/data.d.ts +0 -1
- package/build/operators/CONDITIONAL/data.js +1 -2
- package/build/operators/CONDITIONAL/operator.d.ts +1 -5
- package/build/operators/CONDITIONAL/operator.js +7 -2
- package/build/operators/COUNT/data.d.ts +0 -1
- package/build/operators/COUNT/data.js +1 -2
- package/build/operators/COUNT/operator.js +1 -2
- package/build/operators/CUSTOM_FUNCTIONS/data.d.ts +0 -1
- package/build/operators/CUSTOM_FUNCTIONS/data.js +9 -3
- package/build/operators/CUSTOM_FUNCTIONS/operator.d.ts +1 -7
- package/build/operators/CUSTOM_FUNCTIONS/operator.js +7 -6
- package/build/operators/DIVIDE/data.d.ts +0 -1
- package/build/operators/DIVIDE/data.js +2 -3
- package/build/operators/DIVIDE/operator.d.ts +1 -11
- package/build/operators/DIVIDE/operator.js +5 -4
- package/build/operators/EQUAL/data.d.ts +0 -1
- package/build/operators/EQUAL/data.js +1 -2
- package/build/operators/EQUAL/operator.js +1 -2
- package/build/operators/GET/data.d.ts +0 -1
- package/build/operators/GET/data.js +1 -2
- package/build/operators/GET/index.d.ts +1 -1
- package/build/operators/GET/operator.d.ts +2 -10
- package/build/operators/GET/operator.js +16 -14
- package/build/operators/GRAPHQL/data.d.ts +0 -1
- package/build/operators/GRAPHQL/data.js +1 -2
- package/build/operators/GRAPHQL/operator.d.ts +1 -10
- package/build/operators/GRAPHQL/operator.js +20 -9
- package/build/operators/GREATER_THAN/data.d.ts +0 -1
- package/build/operators/GREATER_THAN/data.js +1 -2
- package/build/operators/GREATER_THAN/operator.d.ts +0 -4
- package/build/operators/GREATER_THAN/operator.js +1 -2
- package/build/operators/LESS_THAN/data.d.ts +0 -1
- package/build/operators/LESS_THAN/data.js +1 -2
- package/build/operators/LESS_THAN/operator.js +1 -2
- package/build/operators/MATCH/data.d.ts +0 -1
- package/build/operators/MATCH/data.js +1 -2
- package/build/operators/MATCH/operator.d.ts +1 -5
- package/build/operators/MATCH/operator.js +12 -6
- package/build/operators/MULTIPLY/data.d.ts +0 -1
- package/build/operators/MULTIPLY/data.js +1 -2
- package/build/operators/MULTIPLY/operator.js +5 -2
- package/build/operators/NOT_EQUAL/data.d.ts +0 -1
- package/build/operators/NOT_EQUAL/data.js +1 -2
- package/build/operators/NOT_EQUAL/operator.js +1 -2
- package/build/operators/OBJECT_PROPERTIES/data.d.ts +0 -1
- package/build/operators/OBJECT_PROPERTIES/data.js +1 -2
- package/build/operators/OBJECT_PROPERTIES/operator.d.ts +1 -7
- package/build/operators/OBJECT_PROPERTIES/operator.js +1 -2
- package/build/operators/OR/data.d.ts +0 -1
- package/build/operators/OR/data.js +1 -2
- package/build/operators/OR/operator.js +1 -2
- package/build/operators/PASSTHRU/data.d.ts +0 -1
- package/build/operators/PASSTHRU/data.js +1 -2
- package/build/operators/PASSTHRU/operator.d.ts +1 -5
- package/build/operators/PASSTHRU/operator.js +2 -1
- package/build/operators/PG_SQL/data.d.ts +0 -1
- package/build/operators/PG_SQL/data.js +9 -3
- package/build/operators/PG_SQL/operator.d.ts +1 -23
- package/build/operators/PG_SQL/operator.js +22 -30
- package/build/operators/PLUS/data.d.ts +0 -1
- package/build/operators/PLUS/data.js +2 -3
- package/build/operators/PLUS/operator.d.ts +1 -8
- package/build/operators/PLUS/operator.js +5 -5
- package/build/operators/POST/data.d.ts +0 -1
- package/build/operators/POST/data.js +1 -2
- package/build/operators/POST/operator.js +14 -6
- package/build/operators/REGEX/data.d.ts +0 -1
- package/build/operators/REGEX/data.js +1 -2
- package/build/operators/REGEX/operator.d.ts +1 -5
- package/build/operators/REGEX/operator.js +1 -2
- package/build/operators/SPLIT/data.d.ts +0 -1
- package/build/operators/SPLIT/data.js +1 -2
- package/build/operators/SPLIT/operator.d.ts +1 -9
- package/build/operators/SPLIT/operator.js +1 -2
- package/build/operators/STRING_SUBSTITUTION/data.d.ts +0 -1
- package/build/operators/STRING_SUBSTITUTION/data.js +1 -2
- package/build/operators/STRING_SUBSTITUTION/operator.d.ts +1 -5
- package/build/operators/STRING_SUBSTITUTION/operator.js +5 -6
- package/build/operators/SUBTRACT/data.d.ts +0 -1
- package/build/operators/SUBTRACT/data.js +1 -2
- package/build/operators/SUBTRACT/operator.d.ts +1 -8
- package/build/operators/SUBTRACT/operator.js +4 -3
- package/build/operators/_operatorUtils.d.ts +16 -17
- package/build/operators/_operatorUtils.js +17 -17
- package/build/shorthandSyntax.js +1 -1
- package/build/typeCheck.d.ts +8 -4
- package/build/typeCheck.js +25 -20
- package/build/types.d.ts +32 -33
- package/build/version.d.ts +1 -0
- package/build/version.js +4 -0
- package/package.json +10 -3
package/build/typeCheck.js
CHANGED
|
@@ -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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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,19 +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) =>
|
|
39
|
-
|
|
41
|
+
object: (value) => (0, helpers_1.isObject)(value),
|
|
42
|
+
undefined: (value) => value === undefined,
|
|
40
43
|
};
|
|
41
|
-
const makeErrorString = (name, value, type
|
|
44
|
+
const makeErrorString = (name, value, type) => {
|
|
45
|
+
if (value === undefined && !!name)
|
|
46
|
+
return `- Missing required property "${name}" (type: ${type})`;
|
|
42
47
|
if (name !== undefined)
|
|
43
|
-
return `- Property "${name}" (value: ${stringifyValue(value)}) is not of type: ${
|
|
44
|
-
return `- ${stringifyValue(value)} is not of type: ${
|
|
48
|
+
return `- Property "${name}" (value: ${stringifyValue(value)}) is not of type: ${type}`;
|
|
49
|
+
return `- ${stringifyValue(value)} is not of type: ${type}`;
|
|
45
50
|
};
|
|
46
51
|
const stringifyValue = (value) => {
|
|
47
52
|
const stringValue = value === undefined || Number.isNaN(value) ? String(value) : JSON.stringify(value);
|
package/build/types.d.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import FigTreeCache from './cache';
|
|
2
|
-
import {
|
|
2
|
+
import { Client } from 'pg';
|
|
3
|
+
import { GraphQLConnection } from './operators';
|
|
3
4
|
import operatorAliases from './operators/_operatorAliases.json';
|
|
4
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>;
|
|
12
10
|
export type Fragments = Record<string, Fragment>;
|
|
13
|
-
export type
|
|
11
|
+
export type UnknownFunction = (...args: any[]) => EvaluatorOutput;
|
|
14
12
|
export interface FigTreeOptions {
|
|
15
|
-
data?:
|
|
16
|
-
objects?:
|
|
17
|
-
functions?:
|
|
13
|
+
data?: object;
|
|
14
|
+
objects?: object;
|
|
15
|
+
functions?: Record<string, UnknownFunction>;
|
|
18
16
|
fragments?: Fragments;
|
|
19
|
-
pgConnection?:
|
|
17
|
+
pgConnection?: Client;
|
|
20
18
|
graphQLConnection?: GraphQLConnection;
|
|
21
19
|
baseEndpoint?: string;
|
|
22
20
|
headers?: {
|
|
@@ -28,7 +26,7 @@ export interface FigTreeOptions {
|
|
|
28
26
|
noShorthand?: boolean;
|
|
29
27
|
skipRuntimeTypeCheck?: boolean;
|
|
30
28
|
evaluateFullObject?: boolean;
|
|
31
|
-
excludeOperators?:
|
|
29
|
+
excludeOperators?: OperatorAlias[];
|
|
32
30
|
useCache?: boolean;
|
|
33
31
|
maxCacheSize?: number;
|
|
34
32
|
supportDeprecatedValueNodes?: boolean;
|
|
@@ -37,48 +35,46 @@ export interface FigTreeConfig {
|
|
|
37
35
|
options: FigTreeOptions;
|
|
38
36
|
operators: OperatorReference;
|
|
39
37
|
operatorAliases: OperatorAliases;
|
|
40
|
-
typeChecker: (...
|
|
38
|
+
typeChecker: (...args: TypeCheckInput[] | [TypeCheckInput[]]) => void;
|
|
41
39
|
resolvedAliasNodes: {
|
|
42
40
|
[key: string]: EvaluatorOutput;
|
|
43
41
|
};
|
|
44
42
|
cache: FigTreeCache;
|
|
45
43
|
}
|
|
46
44
|
export type OutputType = 'string' | 'number' | 'boolean' | 'bool' | 'array';
|
|
47
|
-
export interface
|
|
48
|
-
operator:
|
|
45
|
+
export interface OperatorNode {
|
|
46
|
+
operator: OperatorAlias;
|
|
49
47
|
outputType?: OutputType;
|
|
50
|
-
children?:
|
|
51
|
-
fallback?:
|
|
48
|
+
children?: EvaluatorNode[];
|
|
49
|
+
fallback?: EvaluatorNode;
|
|
52
50
|
useCache?: boolean;
|
|
53
51
|
[key: string]: EvaluatorNode;
|
|
54
52
|
}
|
|
55
53
|
export interface FragmentNode {
|
|
56
54
|
fragment: string;
|
|
57
|
-
parameters?:
|
|
58
|
-
[key: string]: EvaluatorNode;
|
|
59
|
-
};
|
|
55
|
+
parameters?: Record<string, EvaluatorNode>;
|
|
60
56
|
[key: string]: EvaluatorNode;
|
|
61
57
|
}
|
|
58
|
+
export interface FragmentMetadata {
|
|
59
|
+
description?: string;
|
|
60
|
+
parameters?: Record<string, {
|
|
61
|
+
type: string | string[];
|
|
62
|
+
required: boolean;
|
|
63
|
+
}>;
|
|
64
|
+
}
|
|
62
65
|
export type Fragment = (EvaluatorNode & {
|
|
63
|
-
metadata?:
|
|
64
|
-
description?: string;
|
|
65
|
-
parameters?: Record<string, {
|
|
66
|
-
type: string | string[];
|
|
67
|
-
required: boolean;
|
|
68
|
-
}>;
|
|
69
|
-
};
|
|
66
|
+
metadata?: FragmentMetadata;
|
|
70
67
|
}) | null;
|
|
71
|
-
export type
|
|
72
|
-
export type
|
|
73
|
-
export type EvaluatorOutput = string | boolean | number | GenericObject | null | undefined | any[];
|
|
74
|
-
export type EvaluatorNode = CombinedOperatorNode | FragmentNode | EvaluatorOutput;
|
|
68
|
+
export type EvaluatorOutput = string | boolean | number | object | null | undefined | Array<EvaluatorOutput>;
|
|
69
|
+
export type EvaluatorNode = OperatorNode | FragmentNode | EvaluatorOutput;
|
|
75
70
|
export type OperatorObject = {
|
|
76
|
-
requiredProperties: readonly string[];
|
|
77
71
|
propertyAliases: Record<string, string>;
|
|
78
72
|
operatorData: OperatorData;
|
|
79
|
-
evaluate:
|
|
80
|
-
parseChildren:
|
|
73
|
+
evaluate: EvaluateMethod;
|
|
74
|
+
parseChildren: ParseChildrenMethod;
|
|
81
75
|
};
|
|
76
|
+
export type EvaluateMethod = (expression: OperatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
|
|
77
|
+
export type ParseChildrenMethod = (expression: OperatorNode, config: FigTreeConfig) => OperatorNode | Promise<OperatorNode>;
|
|
82
78
|
export type OperatorReference = {
|
|
83
79
|
[key in Operator]: OperatorObject;
|
|
84
80
|
};
|
|
@@ -87,10 +83,13 @@ export type Parameter = {
|
|
|
87
83
|
description: string;
|
|
88
84
|
aliases: string[];
|
|
89
85
|
required: boolean;
|
|
90
|
-
type: ExpectedType
|
|
86
|
+
type: ExpectedType;
|
|
91
87
|
};
|
|
92
88
|
export interface OperatorData {
|
|
93
89
|
description: string;
|
|
94
90
|
aliases: string[];
|
|
95
91
|
parameters: Parameter[];
|
|
96
92
|
}
|
|
93
|
+
export interface OperatorMetadata extends OperatorData {
|
|
94
|
+
operator: Operator;
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "2.8.3";
|
package/build/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fig-tree-evaluator",
|
|
3
|
-
"version": "2.8.
|
|
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
|
-
"
|
|
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": {
|