@fibery/expression-utils 9.4.0 → 9.4.1
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/lib/src/types.d.ts +9 -3
- package/lib/src/utils.d.ts +7 -7
- package/lib/src/utils.js +14 -4
- package/lib/src/visitors.d.ts +1 -1
- package/package.json +5 -5
package/lib/src/types.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export type Query = {
|
|
|
10
10
|
"q/select"?: Select;
|
|
11
11
|
"q/offset"?: number;
|
|
12
12
|
"q/order-by"?: OrderBy;
|
|
13
|
-
"q/limit"?:
|
|
14
|
-
"q/where"?:
|
|
13
|
+
"q/limit"?: QueryLimit;
|
|
14
|
+
"q/where"?: Expression;
|
|
15
15
|
};
|
|
16
16
|
export type SubQuery = {
|
|
17
17
|
"q/from": Expression;
|
|
@@ -21,6 +21,12 @@ export type SubQuery = {
|
|
|
21
21
|
"q/limit"?: QueryLimit;
|
|
22
22
|
"q/where"?: Expression;
|
|
23
23
|
};
|
|
24
|
+
export type FunctionsMeta = Record<string, {
|
|
25
|
+
overloads: {
|
|
26
|
+
"arg-types": string[];
|
|
27
|
+
"result-type": string;
|
|
28
|
+
}[];
|
|
29
|
+
}>;
|
|
24
30
|
export type ExpressionVisitor = {
|
|
25
31
|
visitVariableExpression?: (expression: string, visitor?: ExpressionVisitor) => any;
|
|
26
32
|
visitFunctionCallExpression?: (expression: [string, ...Expression[]], visitor?: ExpressionVisitor) => any;
|
|
@@ -28,7 +34,7 @@ export type ExpressionVisitor = {
|
|
|
28
34
|
visitFieldExpression?: (expression: Expression, visitor?: ExpressionVisitor) => any;
|
|
29
35
|
visitOrderByExpression?: (orderByExpression: OrderBy, visitor?: ExpressionVisitor) => any;
|
|
30
36
|
visitQueryExpression?: (subQueryExpression: SubQuery, visitor?: ExpressionVisitor) => any;
|
|
31
|
-
visitExpression?: (expression: Expression, visitor?: ExpressionVisitor) => any;
|
|
37
|
+
visitExpression?: (expression: Expression | SubQuery | OrderBy | string, visitor?: ExpressionVisitor) => any;
|
|
32
38
|
[key: string]: $TSFixMe;
|
|
33
39
|
};
|
|
34
40
|
export type ExpressionVisitorWithDefault = Required<ExpressionVisitor>;
|
package/lib/src/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Expression, ExpressionVisitor, ExpressionVisitorWithDefault, OrderBy, SubQuery } from "./types";
|
|
2
2
|
import { FieldObject, TypeObject } from "@fibery/schema";
|
|
3
3
|
export declare const assertIsValidExpression: (expression: Expression) => void;
|
|
4
4
|
export declare const textTypes: string[];
|
|
@@ -11,19 +11,19 @@ export declare const firstLastFunctions: Set<string>;
|
|
|
11
11
|
export declare const logicalOperators: Set<string>;
|
|
12
12
|
export declare const relationalOperators: Set<string>;
|
|
13
13
|
export declare const mathOperators: Set<string>;
|
|
14
|
-
export declare const isFunctionCallExpression: (expression: Expression) => boolean;
|
|
14
|
+
export declare const isFunctionCallExpression: (expression: Expression | SubQuery | OrderBy | string) => boolean;
|
|
15
15
|
export declare const fromRootKeyword = "q/from-root";
|
|
16
|
-
export declare const isFromRootFieldExpression: (expression: Expression) => boolean;
|
|
16
|
+
export declare const isFromRootFieldExpression: (expression: Expression | SubQuery | OrderBy | string) => boolean;
|
|
17
17
|
export declare const isDateRangeFunctionExpression: (expression: Expression) => boolean;
|
|
18
18
|
export declare const isCollectionFunctionExpression: (expression: Expression) => boolean;
|
|
19
19
|
export declare const isAccessFunctionExpression: (expresion: Expression) => boolean;
|
|
20
20
|
export declare const isBinaryExpression: (expression: Expression) => boolean;
|
|
21
21
|
export declare const isNaryExpression: (expression: Expression) => boolean;
|
|
22
|
-
export declare const isVariableExpression: (expression: Expression | string | null) => boolean;
|
|
22
|
+
export declare const isVariableExpression: (expression: Expression | SubQuery | OrderBy | string | null) => boolean;
|
|
23
23
|
export declare const isMultiFieldAccess: (expression: Expression | string) => boolean;
|
|
24
|
-
export declare const isMultiFieldExpression: (expression: Expression) => boolean;
|
|
25
|
-
export declare const isFieldExpression: (expression:
|
|
26
|
-
export declare const isQueryExpression: (expression: Expression | SubQuery | null) => boolean;
|
|
24
|
+
export declare const isMultiFieldExpression: (expression: Expression | SubQuery | OrderBy | string) => boolean;
|
|
25
|
+
export declare const isFieldExpression: (expression: Expression | SubQuery | OrderBy | string) => boolean;
|
|
26
|
+
export declare const isQueryExpression: (expression: Expression | SubQuery | OrderBy | string | null) => boolean;
|
|
27
27
|
export declare const getFieldObjectsByFieldExpression: ({ typeObject, expression, }: {
|
|
28
28
|
typeObject: TypeObject;
|
|
29
29
|
expression: Expression;
|
package/lib/src/utils.js
CHANGED
|
@@ -59,10 +59,20 @@ const binaryOperations = new Set([
|
|
|
59
59
|
exports.logicalOperators = new Set(["and", "or", "q/and", "q/or"]);
|
|
60
60
|
exports.relationalOperators = new Set(["=", "!=", "<", ">", "<=", ">="]);
|
|
61
61
|
exports.mathOperators = new Set(["+", "-", "*", "/", "q/+", "q/-", "q/concat"]);
|
|
62
|
-
const isFunctionCallExpression = (expression) =>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
const isFunctionCallExpression = (expression) => {
|
|
63
|
+
if (!Array.isArray(expression)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (expression.length <= 1) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const firstElement = expression[0];
|
|
70
|
+
if (!lodash_1.default.isString(firstElement)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return (firstElement.startsWith("q/") ||
|
|
74
|
+
["=", "!=", "<", ">", "<=", ">=", "+", "-", "*", "/", "in", "and", "or", "not-in"].includes(firstElement));
|
|
75
|
+
};
|
|
66
76
|
exports.isFunctionCallExpression = isFunctionCallExpression;
|
|
67
77
|
exports.fromRootKeyword = "q/from-root";
|
|
68
78
|
const isFromRootFieldExpression = (expression) => lodash_1.default.isArray(expression) && expression[0] === exports.fromRootKeyword;
|
package/lib/src/visitors.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export declare const getExpressionType: ({ expression, typeObject, functionsMeta
|
|
|
33
33
|
"result-type": string;
|
|
34
34
|
}[];
|
|
35
35
|
}>;
|
|
36
|
-
onFieldNotFound
|
|
36
|
+
onFieldNotFound?: ({ currentTypeObject, fieldId }: {
|
|
37
37
|
currentTypeObject: TypeObject | null;
|
|
38
38
|
fieldId: string;
|
|
39
39
|
}) => {
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/expression-utils",
|
|
3
|
-
"version": "9.4.
|
|
3
|
+
"version": "9.4.1",
|
|
4
4
|
"description": "utils for working with fibery api expressions",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
|
-
"types": "./lib/index.d.ts",
|
|
7
6
|
"files": [
|
|
8
7
|
"./lib"
|
|
9
8
|
],
|
|
@@ -34,8 +33,8 @@
|
|
|
34
33
|
"jest-junit": "13.0.0",
|
|
35
34
|
"typescript": "5.8.3",
|
|
36
35
|
"@fibery/babel-preset": "7.4.0",
|
|
37
|
-
"@fibery/
|
|
38
|
-
"@fibery/
|
|
36
|
+
"@fibery/eslint-config": "8.6.1",
|
|
37
|
+
"@fibery/schema": "10.2.8"
|
|
39
38
|
},
|
|
40
39
|
"peerDependencies": {
|
|
41
40
|
"@fibery/schema": "10.2.8"
|
|
@@ -84,5 +83,6 @@
|
|
|
84
83
|
"test:ci": "jest --reporters=default --reporters=jest-junit",
|
|
85
84
|
"test:coverage": "jest --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/formulas --reporters=default --reporters=jest-junit",
|
|
86
85
|
"lint": "eslint ."
|
|
87
|
-
}
|
|
86
|
+
},
|
|
87
|
+
"types": "./lib/index.d.ts"
|
|
88
88
|
}
|