@fibery/expression-utils 9.2.1 → 9.4.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.
- package/lib/index.d.ts +6 -0
- package/lib/index.js +44 -0
- package/lib/src/context-variables.d.ts +22 -0
- package/lib/src/context-variables.js +122 -0
- package/lib/src/errors.d.ts +4 -0
- package/lib/src/errors.js +15 -0
- package/lib/src/fieldExpressionVisitorTypeAware.d.ts +5 -0
- package/lib/src/fieldExpressionVisitorTypeAware.js +133 -0
- package/lib/src/params-placeholders.d.ts +55 -0
- package/lib/src/params-placeholders.js +204 -0
- package/lib/src/tsfixme.d.ts +1 -0
- package/lib/src/tsfixme.js +2 -0
- package/lib/src/types.d.ts +35 -0
- package/lib/src/types.js +2 -0
- package/lib/src/utils.d.ts +42 -0
- package/lib/src/utils.js +260 -0
- package/lib/src/visitors.d.ts +44 -0
- package/lib/src/visitors.js +382 -0
- package/lib/testData/schemaMock.d.ts +502 -0
- package/lib/testData/schemaMock.js +138 -0
- package/package.json +22 -22
- package/lib/contextVariables.js +0 -20
- package/lib/expression-utils.js +0 -1035
- package/lib/paramsPlaceholders.js +0 -232
- package/lib/utils.js +0 -223
- package/lib/visitors.js +0 -660
- package/types.d.ts +0 -119
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { $TSFixMe } from "./tsfixme";
|
|
2
|
+
type NestedArray<T> = Array<T | NestedArray<T>>;
|
|
3
|
+
export type Expression = NestedArray<string>;
|
|
4
|
+
type SelectPart = Record<string, Expression>;
|
|
5
|
+
export type Select = SelectPart | Record<string, SelectPart>;
|
|
6
|
+
export type OrderBy = Array<[Expression, string]>;
|
|
7
|
+
export type QueryLimit = number | "q/no-limit";
|
|
8
|
+
export type Query = {
|
|
9
|
+
"q/from": string;
|
|
10
|
+
"q/select"?: Select;
|
|
11
|
+
"q/offset"?: number;
|
|
12
|
+
"q/order-by"?: OrderBy;
|
|
13
|
+
"q/limit"?: number | "q/no-limit";
|
|
14
|
+
"q/where"?: NestedArray<unknown>;
|
|
15
|
+
};
|
|
16
|
+
export type SubQuery = {
|
|
17
|
+
"q/from": Expression;
|
|
18
|
+
"q/select"?: Select;
|
|
19
|
+
"q/offset"?: number;
|
|
20
|
+
"q/order-by"?: OrderBy;
|
|
21
|
+
"q/limit"?: QueryLimit;
|
|
22
|
+
"q/where"?: Expression;
|
|
23
|
+
};
|
|
24
|
+
export type ExpressionVisitor = {
|
|
25
|
+
visitVariableExpression?: (expression: string, visitor?: ExpressionVisitor) => any;
|
|
26
|
+
visitFunctionCallExpression?: (expression: [string, ...Expression[]], visitor?: ExpressionVisitor) => any;
|
|
27
|
+
visitFromRootFieldExpression?: (expression: [string, ...Expression[]], visitor?: ExpressionVisitor) => any;
|
|
28
|
+
visitFieldExpression?: (expression: Expression, visitor?: ExpressionVisitor) => any;
|
|
29
|
+
visitOrderByExpression?: (orderByExpression: OrderBy, visitor?: ExpressionVisitor) => any;
|
|
30
|
+
visitQueryExpression?: (subQueryExpression: SubQuery, visitor?: ExpressionVisitor) => any;
|
|
31
|
+
visitExpression?: (expression: Expression, visitor?: ExpressionVisitor) => any;
|
|
32
|
+
[key: string]: $TSFixMe;
|
|
33
|
+
};
|
|
34
|
+
export type ExpressionVisitorWithDefault = Required<ExpressionVisitor>;
|
|
35
|
+
export {};
|
package/lib/src/types.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ExpressionVisitorWithDefault, Expression, ExpressionVisitor, SubQuery } from "./types";
|
|
2
|
+
import { FieldObject, TypeObject } from "@fibery/schema";
|
|
3
|
+
export declare const assertIsValidExpression: (expression: Expression) => void;
|
|
4
|
+
export declare const textTypes: string[];
|
|
5
|
+
export declare const dateTypes: string[];
|
|
6
|
+
export declare const dateRangeTypes: string[];
|
|
7
|
+
export declare const convertableDateTypes: string[];
|
|
8
|
+
export declare const numberTypes: string[];
|
|
9
|
+
export declare const dateRangeFunctions: Set<string>;
|
|
10
|
+
export declare const firstLastFunctions: Set<string>;
|
|
11
|
+
export declare const logicalOperators: Set<string>;
|
|
12
|
+
export declare const relationalOperators: Set<string>;
|
|
13
|
+
export declare const mathOperators: Set<string>;
|
|
14
|
+
export declare const isFunctionCallExpression: (expression: Expression) => boolean;
|
|
15
|
+
export declare const fromRootKeyword = "q/from-root";
|
|
16
|
+
export declare const isFromRootFieldExpression: (expression: Expression) => boolean;
|
|
17
|
+
export declare const isDateRangeFunctionExpression: (expression: Expression) => boolean;
|
|
18
|
+
export declare const isCollectionFunctionExpression: (expression: Expression) => boolean;
|
|
19
|
+
export declare const isAccessFunctionExpression: (expresion: Expression) => boolean;
|
|
20
|
+
export declare const isBinaryExpression: (expression: Expression) => boolean;
|
|
21
|
+
export declare const isNaryExpression: (expression: Expression) => boolean;
|
|
22
|
+
export declare const isVariableExpression: (expression: Expression | string | null) => boolean;
|
|
23
|
+
export declare const isMultiFieldAccess: (expression: Expression | string) => boolean;
|
|
24
|
+
export declare const isMultiFieldExpression: (expression: Expression) => boolean;
|
|
25
|
+
export declare const isFieldExpression: (expression: string | Expression) => boolean;
|
|
26
|
+
export declare const isQueryExpression: (expression: Expression | SubQuery | null) => boolean;
|
|
27
|
+
export declare const getFieldObjectsByFieldExpression: ({ typeObject, expression, }: {
|
|
28
|
+
typeObject: TypeObject;
|
|
29
|
+
expression: Expression;
|
|
30
|
+
}) => FieldObject[];
|
|
31
|
+
export declare const getFieldObjectByFieldExpression: (x: {
|
|
32
|
+
typeObject: TypeObject;
|
|
33
|
+
expression: Expression;
|
|
34
|
+
}) => FieldObject;
|
|
35
|
+
export declare const getFieldObjects: (expression: Expression, typeObject: TypeObject) => FieldObject[];
|
|
36
|
+
/** @deprecated
|
|
37
|
+
* This method checks few expression forms, that we do not generate on frontend anymore(field-access shortcut, direct value as parameter).
|
|
38
|
+
* I'm afraid to replace it with implementation based on visitor everywhere, as visitors don't allow such expression forms and I don't want to extend visitor with those forms.
|
|
39
|
+
* If you need this method in new places, consider implementing same logic on visitors and use it.
|
|
40
|
+
**/
|
|
41
|
+
export declare const extractFieldExpressions: (expression: Expression) => Expression[];
|
|
42
|
+
export declare const createExpressionVisitor: (visitor: ExpressionVisitor) => ExpressionVisitorWithDefault;
|
package/lib/src/utils.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
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.createExpressionVisitor = exports.extractFieldExpressions = exports.getFieldObjects = exports.getFieldObjectByFieldExpression = exports.getFieldObjectsByFieldExpression = exports.isQueryExpression = exports.isFieldExpression = exports.isMultiFieldExpression = exports.isMultiFieldAccess = exports.isVariableExpression = exports.isNaryExpression = exports.isBinaryExpression = exports.isAccessFunctionExpression = exports.isCollectionFunctionExpression = exports.isDateRangeFunctionExpression = exports.isFromRootFieldExpression = exports.fromRootKeyword = exports.isFunctionCallExpression = exports.mathOperators = exports.relationalOperators = exports.logicalOperators = exports.firstLastFunctions = exports.dateRangeFunctions = exports.numberTypes = exports.convertableDateTypes = exports.dateRangeTypes = exports.dateTypes = exports.textTypes = exports.assertIsValidExpression = void 0;
|
|
7
|
+
const trace_1 = require("@fibery/helpers/utils/trace");
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const errors_1 = require("./errors");
|
|
10
|
+
const assertIsValidExpression = (expression) => {
|
|
11
|
+
(0, trace_1.assert)(Array.isArray(expression), "expression must be array", { expression });
|
|
12
|
+
(0, trace_1.assert)(expression.length > 0, "empty expression does not make any sense");
|
|
13
|
+
};
|
|
14
|
+
exports.assertIsValidExpression = assertIsValidExpression;
|
|
15
|
+
exports.textTypes = ["fibery/text", "fibery/email", "fibery/url", "fibery/emoji"];
|
|
16
|
+
exports.dateTypes = ["fibery/date", "fibery/date-time"];
|
|
17
|
+
exports.dateRangeTypes = ["fibery/date-range", "fibery/date-time-range"];
|
|
18
|
+
exports.convertableDateTypes = ["fibery/date", "fibery/date-range"];
|
|
19
|
+
exports.numberTypes = ["fibery/int", "fibery/decimal"];
|
|
20
|
+
exports.dateRangeFunctions = new Set(["q/start", "q/end"]);
|
|
21
|
+
exports.firstLastFunctions = new Set(["q/first", "q/last"]);
|
|
22
|
+
const collectionOps = new Set([
|
|
23
|
+
"q/count",
|
|
24
|
+
"q/count-distinct",
|
|
25
|
+
"q/sum",
|
|
26
|
+
"q/min",
|
|
27
|
+
"q/max",
|
|
28
|
+
"q/avg",
|
|
29
|
+
"q/join",
|
|
30
|
+
"q/first",
|
|
31
|
+
"q/last",
|
|
32
|
+
]);
|
|
33
|
+
// [op, left, right]
|
|
34
|
+
// [=, $true, $false]
|
|
35
|
+
// [=, $my-id, ["fibery/id"]]
|
|
36
|
+
const binaryOperations = new Set([
|
|
37
|
+
"=",
|
|
38
|
+
"!=",
|
|
39
|
+
"<",
|
|
40
|
+
">",
|
|
41
|
+
"<=",
|
|
42
|
+
">=",
|
|
43
|
+
"in", //asc: obsolete,use q/in
|
|
44
|
+
"q/contains",
|
|
45
|
+
"q/not-contains",
|
|
46
|
+
"+",
|
|
47
|
+
"-",
|
|
48
|
+
"q/+",
|
|
49
|
+
"q/-",
|
|
50
|
+
"*",
|
|
51
|
+
"/",
|
|
52
|
+
"and",
|
|
53
|
+
"or", //asc: obsolete. use q/and, q/or
|
|
54
|
+
"q/and",
|
|
55
|
+
"q/or",
|
|
56
|
+
"q/in",
|
|
57
|
+
"q/not-in",
|
|
58
|
+
]);
|
|
59
|
+
exports.logicalOperators = new Set(["and", "or", "q/and", "q/or"]);
|
|
60
|
+
exports.relationalOperators = new Set(["=", "!=", "<", ">", "<=", ">="]);
|
|
61
|
+
exports.mathOperators = new Set(["+", "-", "*", "/", "q/+", "q/-", "q/concat"]);
|
|
62
|
+
const isFunctionCallExpression = (expression) => expression.length > 1 &&
|
|
63
|
+
lodash_1.default.isString(expression[0]) &&
|
|
64
|
+
(expression[0].startsWith("q/") ||
|
|
65
|
+
["=", "!=", "<", ">", "<=", ">=", "+", "-", "*", "/", "in", "and", "or", "not-in"].includes(expression[0]));
|
|
66
|
+
exports.isFunctionCallExpression = isFunctionCallExpression;
|
|
67
|
+
exports.fromRootKeyword = "q/from-root";
|
|
68
|
+
const isFromRootFieldExpression = (expression) => lodash_1.default.isArray(expression) && expression[0] === exports.fromRootKeyword;
|
|
69
|
+
exports.isFromRootFieldExpression = isFromRootFieldExpression;
|
|
70
|
+
const isDateRangeFunctionExpression = (expression) => (expression.length === 2 || expression.length === 3) &&
|
|
71
|
+
exports.dateRangeFunctions.has(expression[0]) &&
|
|
72
|
+
(0, exports.isFieldExpression)(expression[1]);
|
|
73
|
+
exports.isDateRangeFunctionExpression = isDateRangeFunctionExpression;
|
|
74
|
+
const isCollectionFunctionExpression = (expression) =>
|
|
75
|
+
//expression has length 3 in case of q/join
|
|
76
|
+
(expression.length === 2 || expression.length === 3) && collectionOps.has(expression[0]);
|
|
77
|
+
exports.isCollectionFunctionExpression = isCollectionFunctionExpression;
|
|
78
|
+
const isAccessFunctionExpression = (expresion) => expresion.length === 2 && expresion[0] === "q/access?" && (0, exports.isFieldExpression)(expresion[1]);
|
|
79
|
+
exports.isAccessFunctionExpression = isAccessFunctionExpression;
|
|
80
|
+
const isBinaryExpression = (expression) => expression.length === 3 && binaryOperations.has(expression[0]);
|
|
81
|
+
exports.isBinaryExpression = isBinaryExpression;
|
|
82
|
+
const isNaryExpression = (expression) => expression.length > 1 && exports.logicalOperators.has(expression[0]);
|
|
83
|
+
exports.isNaryExpression = isNaryExpression;
|
|
84
|
+
const isVariableExpression = (expression) => lodash_1.default.isString(expression) && expression.startsWith("$");
|
|
85
|
+
exports.isVariableExpression = isVariableExpression;
|
|
86
|
+
const isMultiFieldAccess = (expression) => lodash_1.default.isArray(expression) &&
|
|
87
|
+
expression.length === 2 &&
|
|
88
|
+
!(0, exports.isFunctionCallExpression)(expression) &&
|
|
89
|
+
expression.every((x) => lodash_1.default.isString(x));
|
|
90
|
+
exports.isMultiFieldAccess = isMultiFieldAccess;
|
|
91
|
+
const isMultiFieldExpression = (expression) => Array.isArray(expression) &&
|
|
92
|
+
!(0, exports.isFunctionCallExpression)(expression) &&
|
|
93
|
+
expression.some((x) => (0, exports.isMultiFieldAccess)(x)) &&
|
|
94
|
+
expression.every((x) => !(0, exports.isVariableExpression)(x) &&
|
|
95
|
+
!binaryOperations.has(x) &&
|
|
96
|
+
(lodash_1.default.isString(x) || (0, exports.isMultiFieldAccess)(x)));
|
|
97
|
+
exports.isMultiFieldExpression = isMultiFieldExpression;
|
|
98
|
+
const isFieldExpression = (expression) => Array.isArray(expression) &&
|
|
99
|
+
!(0, exports.isFunctionCallExpression)(expression) &&
|
|
100
|
+
expression.every((x) => !(0, exports.isVariableExpression)(x) && lodash_1.default.isString(x));
|
|
101
|
+
exports.isFieldExpression = isFieldExpression;
|
|
102
|
+
const isQueryExpression = (expression) => {
|
|
103
|
+
if (lodash_1.default.isObject(expression) && "q/from" in expression) {
|
|
104
|
+
const fromExpression = expression["q/from"];
|
|
105
|
+
//asc: fromExpression === null for denormalizeSelect for reference collection case
|
|
106
|
+
return (fromExpression === null ||
|
|
107
|
+
(0, exports.isFieldExpression)(fromExpression) ||
|
|
108
|
+
(0, exports.isFromRootFieldExpression)(fromExpression) ||
|
|
109
|
+
(0, exports.isMultiFieldExpression)(fromExpression));
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
};
|
|
113
|
+
exports.isQueryExpression = isQueryExpression;
|
|
114
|
+
const collectFieldExpressions = (memo, expression) => {
|
|
115
|
+
if ((0, exports.isVariableExpression)(expression)) {
|
|
116
|
+
/* empty */
|
|
117
|
+
}
|
|
118
|
+
else if ((0, exports.isFunctionCallExpression)(expression)) {
|
|
119
|
+
for (const part of expression.slice(1)) {
|
|
120
|
+
if ((0, exports.isVariableExpression)(part) || part === null) {
|
|
121
|
+
/* empty */
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
if (lodash_1.default.isString(part)) {
|
|
125
|
+
// field path shortcut
|
|
126
|
+
memo.push([part]);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
collectFieldExpressions(memo, part);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if ((0, exports.isFieldExpression)(expression) || (0, exports.isMultiFieldExpression)(expression)) {
|
|
135
|
+
memo.push(expression);
|
|
136
|
+
}
|
|
137
|
+
else if (expression["q/from"] &&
|
|
138
|
+
(0, exports.isFieldExpression)(expression["q/from"])) {
|
|
139
|
+
const innerMemo = [];
|
|
140
|
+
expression["q/select"] &&
|
|
141
|
+
collectFieldExpressions(innerMemo, expression["q/select"]);
|
|
142
|
+
expression["q/where"] && collectFieldExpressions(innerMemo, expression["q/where"]);
|
|
143
|
+
for (const fieldExpression of innerMemo) {
|
|
144
|
+
memo.push([...expression["q/from"], ...fieldExpression]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
throw new errors_1.NotImplementedError(expression, "expression");
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const getFieldObjectsByFieldExpression = ({ typeObject, expression, }) => {
|
|
152
|
+
(0, exports.assertIsValidExpression)(expression);
|
|
153
|
+
const fieldObjects = [];
|
|
154
|
+
let currentTypeObject = typeObject;
|
|
155
|
+
for (const fieldOrMultiFieldAccess of expression) {
|
|
156
|
+
if ((0, exports.isMultiFieldAccess)(fieldOrMultiFieldAccess)) {
|
|
157
|
+
const [multiField, type] = fieldOrMultiFieldAccess;
|
|
158
|
+
const fieldObject = currentTypeObject.fieldObjectsByName[multiField];
|
|
159
|
+
fieldObjects.push(fieldObject);
|
|
160
|
+
const foundField = fieldObject.multiRelatedFieldObjects.find((f) => f.holderType === type);
|
|
161
|
+
(0, trace_1.assert)(foundField, "incorrect expression for multi-field");
|
|
162
|
+
currentTypeObject = foundField.holderTypeObject;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const fieldObject = currentTypeObject.fieldObjectsByName[fieldOrMultiFieldAccess];
|
|
166
|
+
fieldObjects.push(fieldObject);
|
|
167
|
+
currentTypeObject = fieldObject.typeObject;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return fieldObjects;
|
|
171
|
+
};
|
|
172
|
+
exports.getFieldObjectsByFieldExpression = getFieldObjectsByFieldExpression;
|
|
173
|
+
const getFieldObjectByFieldExpression = (x // TODO: review types. using type assertion now to avoid rewriting half of app
|
|
174
|
+
) => lodash_1.default.last((0, exports.getFieldObjectsByFieldExpression)(x));
|
|
175
|
+
exports.getFieldObjectByFieldExpression = getFieldObjectByFieldExpression;
|
|
176
|
+
const getFieldObjects = (expression, typeObject) => {
|
|
177
|
+
const fieldExpression = (0, exports.extractFieldExpressions)(expression)[0];
|
|
178
|
+
return (0, exports.getFieldObjectsByFieldExpression)({
|
|
179
|
+
typeObject,
|
|
180
|
+
expression: fieldExpression,
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
exports.getFieldObjects = getFieldObjects;
|
|
184
|
+
/** @deprecated
|
|
185
|
+
* This method checks few expression forms, that we do not generate on frontend anymore(field-access shortcut, direct value as parameter).
|
|
186
|
+
* I'm afraid to replace it with implementation based on visitor everywhere, as visitors don't allow such expression forms and I don't want to extend visitor with those forms.
|
|
187
|
+
* If you need this method in new places, consider implementing same logic on visitors and use it.
|
|
188
|
+
**/
|
|
189
|
+
const extractFieldExpressions = (expression) => {
|
|
190
|
+
const memo = [];
|
|
191
|
+
collectFieldExpressions(memo, expression);
|
|
192
|
+
return lodash_1.default.uniqBy(memo, (x) => x.join(","));
|
|
193
|
+
};
|
|
194
|
+
exports.extractFieldExpressions = extractFieldExpressions;
|
|
195
|
+
const createExpressionVisitor = (visitor) => {
|
|
196
|
+
let visitorWithDefault = null;
|
|
197
|
+
const visitorDefault = {
|
|
198
|
+
visitVariableExpression: (expression) => expression,
|
|
199
|
+
visitFunctionCallExpression: ([fnName, ...args]) => [
|
|
200
|
+
fnName,
|
|
201
|
+
...args.map((x) => visitorWithDefault.visitExpression(x)),
|
|
202
|
+
],
|
|
203
|
+
visitFromRootFieldExpression: ([fromRootKeyword, ...rest]) => [
|
|
204
|
+
fromRootKeyword,
|
|
205
|
+
...rest.map((x) => visitorWithDefault.visitExpression(x)),
|
|
206
|
+
],
|
|
207
|
+
visitFieldExpression: (expression) => expression,
|
|
208
|
+
visitOrderByExpression: (orderByExpression) => orderByExpression.map((x) => {
|
|
209
|
+
const [fieldExpression, orderDir] = x;
|
|
210
|
+
const fieldExpressionNew = visitorWithDefault.visitExpression(fieldExpression);
|
|
211
|
+
return [fieldExpressionNew, orderDir];
|
|
212
|
+
}),
|
|
213
|
+
visitQueryExpression: (subQueryExpression) => {
|
|
214
|
+
const { "q/from": fromExpression, "q/select": selectExpression, "q/where": whereExpression, "q/order-by": orderByExpression, } = subQueryExpression;
|
|
215
|
+
return {
|
|
216
|
+
...subQueryExpression,
|
|
217
|
+
...(fromExpression ? { "q/from": visitorWithDefault.visitFieldExpression(fromExpression) } : null),
|
|
218
|
+
...(selectExpression
|
|
219
|
+
? {
|
|
220
|
+
"q/select": lodash_1.default.isPlainObject(selectExpression)
|
|
221
|
+
? lodash_1.default.mapValues(selectExpression, (val) => visitorWithDefault.visitExpression(val))
|
|
222
|
+
: visitorWithDefault.visitExpression(selectExpression),
|
|
223
|
+
}
|
|
224
|
+
: null),
|
|
225
|
+
...(whereExpression ? { "q/where": visitorWithDefault.visitExpression(whereExpression) } : null),
|
|
226
|
+
...(orderByExpression
|
|
227
|
+
? {
|
|
228
|
+
"q/order-by": visitorWithDefault.visitOrderByExpression(orderByExpression),
|
|
229
|
+
}
|
|
230
|
+
: null),
|
|
231
|
+
};
|
|
232
|
+
},
|
|
233
|
+
visitExpression: (expression) => {
|
|
234
|
+
if (expression === null) {
|
|
235
|
+
throw new errors_1.NotImplementedError(expression, "expression");
|
|
236
|
+
}
|
|
237
|
+
else if ((0, exports.isVariableExpression)(expression)) {
|
|
238
|
+
return visitorWithDefault.visitVariableExpression(expression, visitorDefault);
|
|
239
|
+
}
|
|
240
|
+
else if ((0, exports.isFromRootFieldExpression)(expression)) {
|
|
241
|
+
return visitorWithDefault.visitFromRootFieldExpression(expression, visitorDefault);
|
|
242
|
+
}
|
|
243
|
+
else if ((0, exports.isFunctionCallExpression)(expression)) {
|
|
244
|
+
return visitorWithDefault.visitFunctionCallExpression(expression, visitorDefault);
|
|
245
|
+
}
|
|
246
|
+
else if ((0, exports.isFieldExpression)(expression) || (0, exports.isMultiFieldExpression)(expression)) {
|
|
247
|
+
return visitorWithDefault.visitFieldExpression(expression, visitorDefault);
|
|
248
|
+
}
|
|
249
|
+
else if ((0, exports.isQueryExpression)(expression)) {
|
|
250
|
+
return visitorWithDefault.visitQueryExpression(expression, visitorDefault);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
throw new errors_1.NotImplementedError(expression, "expression");
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
visitorWithDefault = { ...visitorDefault, ...visitor };
|
|
258
|
+
return visitorWithDefault;
|
|
259
|
+
};
|
|
260
|
+
exports.createExpressionVisitor = createExpressionVisitor;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { fieldAccessVisitorTypeAware } from "./fieldExpressionVisitorTypeAware";
|
|
2
|
+
import { TypeObject } from "@fibery/schema";
|
|
3
|
+
import { Expression } from "./types";
|
|
4
|
+
type OnFieldNotFoundInNamesTerms = (params: {
|
|
5
|
+
fieldExpressionInNamesTerms: Expression;
|
|
6
|
+
fieldId: string;
|
|
7
|
+
currentTypeObject: TypeObject | null;
|
|
8
|
+
expression: Expression;
|
|
9
|
+
}) => {
|
|
10
|
+
currentTypeObject: TypeObject | null;
|
|
11
|
+
fieldExpressionInNamesTerms: Expression;
|
|
12
|
+
};
|
|
13
|
+
type OnFieldNotFoundInIdsTerms = (params: {
|
|
14
|
+
fieldExpressionInIdsTerms: Expression;
|
|
15
|
+
field: string;
|
|
16
|
+
currentTypeObject: TypeObject | null;
|
|
17
|
+
expression: Expression;
|
|
18
|
+
}) => {
|
|
19
|
+
currentTypeObject: TypeObject | null;
|
|
20
|
+
fieldExpressionInIdsTerms: Expression;
|
|
21
|
+
};
|
|
22
|
+
export declare const replaceIdsWithNamesVisitor: (typeObject: TypeObject, onFieldNotFound?: OnFieldNotFoundInNamesTerms) => Required<import("./types").ExpressionVisitor>;
|
|
23
|
+
export declare const replaceNamesWithIdsVisitor: (typeObject: TypeObject, onFieldNotFound?: OnFieldNotFoundInIdsTerms) => Required<import("./types").ExpressionVisitor>;
|
|
24
|
+
export declare const deleteExpressionsWithNotFoundFieldsVisitor: (typeObject: TypeObject) => Required<import("./types").ExpressionVisitor>;
|
|
25
|
+
export declare const expressionContainsAggregation: (expression: Expression) => boolean;
|
|
26
|
+
export declare const UNKNOWN_EXPRESSION_TYPE = "unknown";
|
|
27
|
+
export declare const getExpressionType: ({ expression, typeObject, functionsMeta, onFieldNotFound, returnRefTypeInsteadOfId, }: {
|
|
28
|
+
expression: Expression;
|
|
29
|
+
typeObject: TypeObject;
|
|
30
|
+
functionsMeta: Record<string, {
|
|
31
|
+
overloads: {
|
|
32
|
+
"arg-types": string[];
|
|
33
|
+
"result-type": string;
|
|
34
|
+
}[];
|
|
35
|
+
}>;
|
|
36
|
+
onFieldNotFound: ({ currentTypeObject, fieldId }: {
|
|
37
|
+
currentTypeObject: TypeObject | null;
|
|
38
|
+
fieldId: string;
|
|
39
|
+
}) => {
|
|
40
|
+
currentTypeObject: TypeObject | null;
|
|
41
|
+
};
|
|
42
|
+
returnRefTypeInsteadOfId: boolean;
|
|
43
|
+
}) => string | null;
|
|
44
|
+
export { fieldAccessVisitorTypeAware };
|