@fibery/expression-utils 1.1.15 → 1.1.16
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/contextVariables.js +20 -0
- package/lib/expression-utils.js +751 -0
- package/lib/paramsPlaceholders.js +173 -0
- package/lib/utils.js +193 -0
- package/lib/visitors.js +469 -0
- package/package.json +1 -1
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
var _ = require('lodash');
|
|
2
|
+
var moment = require('moment');
|
|
3
|
+
var trace = require('@fibery/helpers/utils/trace');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
6
|
+
|
|
7
|
+
var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
|
|
8
|
+
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
9
|
+
|
|
10
|
+
const serializeDate = momentDate => {
|
|
11
|
+
return momentDate.format("YYYY-MM-DD");
|
|
12
|
+
};
|
|
13
|
+
const serializeDateTime = momentDate => {
|
|
14
|
+
return momentDate.toISOString();
|
|
15
|
+
};
|
|
16
|
+
const formulaTodayDateParamPlaceholder = "$formula-today-date-placeholder";
|
|
17
|
+
const formulaNowDateTimeParamPlaceholder = "$formula-now-date-time-placeholder";
|
|
18
|
+
const todayDateParamPlaceholder = "$today-date";
|
|
19
|
+
const tomorrowDateParamPlaceholder = "$tomorrow-date";
|
|
20
|
+
const yesterdayDateParamPlaceholder = "$yesterday-date";
|
|
21
|
+
const weekAgoDateParamPlaceholder = "$week-ago-date";
|
|
22
|
+
const weekFromNowDateParamPlaceholder = "$week-from-now-date";
|
|
23
|
+
const monthAgoDateParamPlaceholder = "$month-ago-date";
|
|
24
|
+
const monthFromNowDateParamPlaceholder = "$month-from-now-date";
|
|
25
|
+
const yearAgoDateParamPlaceholder = "$year-ago-date";
|
|
26
|
+
const yearFromNowDateParamPlaceholder = "$year-from-now-date";
|
|
27
|
+
const todayStartDateTimeParamPlaceholder = "$today-date-time-start";
|
|
28
|
+
const todayEndDateTimeParamPlaceholder = "$today-date-time-end";
|
|
29
|
+
const tomorrowStartDateTimeParamPlaceholder = "$tomorrow-date-time-start";
|
|
30
|
+
const tomorrowEndDateTimeParamPlaceholder = "$tomorrow-date-time-end";
|
|
31
|
+
const yesterdayStartDateTimeParamPlaceholder = "$yesterday-date-time-start";
|
|
32
|
+
const yesterdayEndDateTimeParamPlaceholder = "$yesterday-date-time-end";
|
|
33
|
+
const weekAgoStartDateTimeParamPlaceholder = "$week-ago-date-time-start";
|
|
34
|
+
const weekAgoEndDateTimeParamPlaceholder = "$week-ago-date-time-end";
|
|
35
|
+
const weekFromNowStartDateTimeParamPlaceholder = "$week-from-now-date-time-start";
|
|
36
|
+
const weekFromNowEndDateTimeParamPlaceholder = "$week-from-now-date-time-end";
|
|
37
|
+
const monthAgoStartDateTimeParamPlaceholder = "$month-ago-date-time-start";
|
|
38
|
+
const monthAgoEndDateTimeParamPlaceholder = "$month-ago-date-time-end";
|
|
39
|
+
const monthFromNowStartDateTimeParamPlaceholder = "$month-from-now-date-time-start";
|
|
40
|
+
const monthFromNowEndDateTimeParamPlaceholder = "$month-from-now-date-time-end";
|
|
41
|
+
const yearAgoStartDateTimeParamPlaceholder = "$year-ago-date-time-start";
|
|
42
|
+
const yearAgoEndDateTimeParamPlaceholder = "$year-ago-date-time-end";
|
|
43
|
+
const yearFromNowStartDateTimeParamPlaceholder = "$year-from-now-date-time-start";
|
|
44
|
+
const yearFromNowEndDateTimeParamPlaceholder = "$year-from-now-date-time-end";
|
|
45
|
+
const paramsPlaceholdersLookup = {
|
|
46
|
+
[todayDateParamPlaceholder]: () => serializeDate(moment__default["default"]()),
|
|
47
|
+
[formulaTodayDateParamPlaceholder]: () => serializeDate(moment__default["default"]()),
|
|
48
|
+
[formulaNowDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]()),
|
|
49
|
+
[tomorrowDateParamPlaceholder]: () => serializeDate(moment__default["default"]().add(1, "days")),
|
|
50
|
+
[yesterdayDateParamPlaceholder]: () => serializeDate(moment__default["default"]().subtract(1, "days")),
|
|
51
|
+
[weekAgoDateParamPlaceholder]: () => serializeDate(moment__default["default"]().subtract(7, "days")),
|
|
52
|
+
[weekFromNowDateParamPlaceholder]: () => serializeDate(moment__default["default"]().add(7, "days")),
|
|
53
|
+
[monthAgoDateParamPlaceholder]: () => serializeDate(moment__default["default"]().subtract(1, "months")),
|
|
54
|
+
[monthFromNowDateParamPlaceholder]: () => serializeDate(moment__default["default"]().add(1, "months")),
|
|
55
|
+
[yearAgoDateParamPlaceholder]: () => serializeDate(moment__default["default"]().subtract(1, "year")),
|
|
56
|
+
[yearFromNowDateParamPlaceholder]: () => serializeDate(moment__default["default"]().add(1, "year")),
|
|
57
|
+
[todayStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().startOf("day")),
|
|
58
|
+
[todayEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().endOf("day")),
|
|
59
|
+
[tomorrowStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "days").startOf("day")),
|
|
60
|
+
[tomorrowEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "days").endOf("day")),
|
|
61
|
+
[yesterdayStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "days").startOf("day")),
|
|
62
|
+
[yesterdayEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "days").endOf("day")),
|
|
63
|
+
[weekAgoStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(7, "days").startOf("day")),
|
|
64
|
+
[weekAgoEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(7, "days").endOf("day")),
|
|
65
|
+
[weekFromNowStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(7, "days").startOf("day")),
|
|
66
|
+
[weekFromNowEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(7, "days").endOf("day")),
|
|
67
|
+
[monthAgoStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "months").startOf("day")),
|
|
68
|
+
[monthAgoEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "months").endOf("day")),
|
|
69
|
+
[monthFromNowStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "months").startOf("day")),
|
|
70
|
+
[monthFromNowEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "months").endOf("day")),
|
|
71
|
+
[yearAgoStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "year").startOf("day")),
|
|
72
|
+
[yearAgoEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "year").endOf("day")),
|
|
73
|
+
[yearFromNowStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "year").startOf("day")),
|
|
74
|
+
[yearFromNowEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "year").endOf("day"))
|
|
75
|
+
};
|
|
76
|
+
const dynamicFilterParamPrefix = `$dynamic_`;
|
|
77
|
+
const isDynamicFilterParam = paramValue => paramValue.startsWith(dynamicFilterParamPrefix);
|
|
78
|
+
const getFieldIdFromDynamicParam = paramValue => paramValue.substring(dynamicFilterParamPrefix.length);
|
|
79
|
+
const mapDynamicParams = (params, onDynamicParam) => {
|
|
80
|
+
if (!params) {
|
|
81
|
+
return params;
|
|
82
|
+
}
|
|
83
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => {
|
|
84
|
+
if (___default["default"].isArray(value)) {
|
|
85
|
+
return [key, value.map(v => {
|
|
86
|
+
return ___default["default"].isString(v) && isDynamicFilterParam(v) ? onDynamicParam(v) : v;
|
|
87
|
+
})];
|
|
88
|
+
} else {
|
|
89
|
+
return [key, ___default["default"].isString(value) && isDynamicFilterParam(value) ? onDynamicParam(value) : value];
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
92
|
+
};
|
|
93
|
+
const replacePlaceholdersInParams = params => params && ___default["default"].mapValues(params, (value, key) => {
|
|
94
|
+
const replaceFn = paramsPlaceholdersLookup[key];
|
|
95
|
+
if (replaceFn) {
|
|
96
|
+
return replaceFn();
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
});
|
|
100
|
+
const dateToDateTimeIntervalLookup = {
|
|
101
|
+
[todayDateParamPlaceholder]: {
|
|
102
|
+
start: todayStartDateTimeParamPlaceholder,
|
|
103
|
+
end: todayEndDateTimeParamPlaceholder
|
|
104
|
+
},
|
|
105
|
+
[tomorrowDateParamPlaceholder]: {
|
|
106
|
+
start: tomorrowStartDateTimeParamPlaceholder,
|
|
107
|
+
end: tomorrowEndDateTimeParamPlaceholder
|
|
108
|
+
},
|
|
109
|
+
[yesterdayDateParamPlaceholder]: {
|
|
110
|
+
start: yesterdayStartDateTimeParamPlaceholder,
|
|
111
|
+
end: yesterdayEndDateTimeParamPlaceholder
|
|
112
|
+
},
|
|
113
|
+
[weekAgoDateParamPlaceholder]: {
|
|
114
|
+
start: weekAgoStartDateTimeParamPlaceholder,
|
|
115
|
+
end: weekAgoEndDateTimeParamPlaceholder
|
|
116
|
+
},
|
|
117
|
+
[weekFromNowDateParamPlaceholder]: {
|
|
118
|
+
start: weekFromNowStartDateTimeParamPlaceholder,
|
|
119
|
+
end: weekFromNowEndDateTimeParamPlaceholder
|
|
120
|
+
},
|
|
121
|
+
[monthAgoDateParamPlaceholder]: {
|
|
122
|
+
start: monthAgoStartDateTimeParamPlaceholder,
|
|
123
|
+
end: monthAgoEndDateTimeParamPlaceholder
|
|
124
|
+
},
|
|
125
|
+
[monthFromNowDateParamPlaceholder]: {
|
|
126
|
+
start: monthFromNowStartDateTimeParamPlaceholder,
|
|
127
|
+
end: monthFromNowEndDateTimeParamPlaceholder
|
|
128
|
+
},
|
|
129
|
+
[yearAgoDateParamPlaceholder]: {
|
|
130
|
+
start: yearAgoStartDateTimeParamPlaceholder,
|
|
131
|
+
end: yearAgoEndDateTimeParamPlaceholder
|
|
132
|
+
},
|
|
133
|
+
[yearFromNowDateParamPlaceholder]: {
|
|
134
|
+
start: yearFromNowStartDateTimeParamPlaceholder,
|
|
135
|
+
end: yearFromNowEndDateTimeParamPlaceholder
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
var paramsPlaceholders = {
|
|
140
|
+
__proto__: null,
|
|
141
|
+
formulaTodayDateParamPlaceholder: formulaTodayDateParamPlaceholder,
|
|
142
|
+
formulaNowDateTimeParamPlaceholder: formulaNowDateTimeParamPlaceholder,
|
|
143
|
+
todayDateParamPlaceholder: todayDateParamPlaceholder,
|
|
144
|
+
tomorrowDateParamPlaceholder: tomorrowDateParamPlaceholder,
|
|
145
|
+
yesterdayDateParamPlaceholder: yesterdayDateParamPlaceholder,
|
|
146
|
+
weekAgoDateParamPlaceholder: weekAgoDateParamPlaceholder,
|
|
147
|
+
weekFromNowDateParamPlaceholder: weekFromNowDateParamPlaceholder,
|
|
148
|
+
monthAgoDateParamPlaceholder: monthAgoDateParamPlaceholder,
|
|
149
|
+
monthFromNowDateParamPlaceholder: monthFromNowDateParamPlaceholder,
|
|
150
|
+
yearAgoDateParamPlaceholder: yearAgoDateParamPlaceholder,
|
|
151
|
+
yearFromNowDateParamPlaceholder: yearFromNowDateParamPlaceholder,
|
|
152
|
+
todayStartDateTimeParamPlaceholder: todayStartDateTimeParamPlaceholder,
|
|
153
|
+
todayEndDateTimeParamPlaceholder: todayEndDateTimeParamPlaceholder,
|
|
154
|
+
tomorrowStartDateTimeParamPlaceholder: tomorrowStartDateTimeParamPlaceholder,
|
|
155
|
+
tomorrowEndDateTimeParamPlaceholder: tomorrowEndDateTimeParamPlaceholder,
|
|
156
|
+
yesterdayStartDateTimeParamPlaceholder: yesterdayStartDateTimeParamPlaceholder,
|
|
157
|
+
yesterdayEndDateTimeParamPlaceholder: yesterdayEndDateTimeParamPlaceholder,
|
|
158
|
+
weekAgoStartDateTimeParamPlaceholder: weekAgoStartDateTimeParamPlaceholder,
|
|
159
|
+
weekAgoEndDateTimeParamPlaceholder: weekAgoEndDateTimeParamPlaceholder,
|
|
160
|
+
weekFromNowStartDateTimeParamPlaceholder: weekFromNowStartDateTimeParamPlaceholder,
|
|
161
|
+
weekFromNowEndDateTimeParamPlaceholder: weekFromNowEndDateTimeParamPlaceholder,
|
|
162
|
+
monthAgoStartDateTimeParamPlaceholder: monthAgoStartDateTimeParamPlaceholder,
|
|
163
|
+
monthAgoEndDateTimeParamPlaceholder: monthAgoEndDateTimeParamPlaceholder,
|
|
164
|
+
monthFromNowStartDateTimeParamPlaceholder: monthFromNowStartDateTimeParamPlaceholder,
|
|
165
|
+
monthFromNowEndDateTimeParamPlaceholder: monthFromNowEndDateTimeParamPlaceholder,
|
|
166
|
+
yearAgoStartDateTimeParamPlaceholder: yearAgoStartDateTimeParamPlaceholder,
|
|
167
|
+
yearAgoEndDateTimeParamPlaceholder: yearAgoEndDateTimeParamPlaceholder,
|
|
168
|
+
yearFromNowStartDateTimeParamPlaceholder: yearFromNowStartDateTimeParamPlaceholder,
|
|
169
|
+
yearFromNowEndDateTimeParamPlaceholder: yearFromNowEndDateTimeParamPlaceholder,
|
|
170
|
+
paramsPlaceholdersLookup: paramsPlaceholdersLookup,
|
|
171
|
+
dynamicFilterParamPrefix: dynamicFilterParamPrefix,
|
|
172
|
+
isDynamicFilterParam: isDynamicFilterParam,
|
|
173
|
+
getFieldIdFromDynamicParam: getFieldIdFromDynamicParam,
|
|
174
|
+
mapDynamicParams: mapDynamicParams,
|
|
175
|
+
replacePlaceholdersInParams: replacePlaceholdersInParams,
|
|
176
|
+
dateToDateTimeIntervalLookup: dateToDateTimeIntervalLookup
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
function _extends() {
|
|
180
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
181
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
182
|
+
var source = arguments[i];
|
|
183
|
+
for (var key in source) {
|
|
184
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
185
|
+
target[key] = source[key];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return target;
|
|
190
|
+
};
|
|
191
|
+
return _extends.apply(this, arguments);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const stringify = x => {
|
|
195
|
+
if (x === undefined) {
|
|
196
|
+
return "undefined";
|
|
197
|
+
}
|
|
198
|
+
return JSON.stringify(x);
|
|
199
|
+
};
|
|
200
|
+
class NotImplementedError extends Error {
|
|
201
|
+
constructor(value, itemType = undefined) {
|
|
202
|
+
super([`"${stringify(value)}"`, itemType, "is not implemented"].filter(x => x !== undefined).join(" "));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const assertIsValidExpression = expression => {
|
|
207
|
+
trace.assert(Array.isArray(expression), "expression must be array", {
|
|
208
|
+
expression
|
|
209
|
+
});
|
|
210
|
+
trace.assert(expression.length > 0, "empty expression does not make any sense");
|
|
211
|
+
};
|
|
212
|
+
const dateRangeFunctions = new Set(["q/start", "q/end"]);
|
|
213
|
+
const firstLastFunctions = new Set(["q/first", "q/last"]);
|
|
214
|
+
const collectionOps = new Set(["q/count", "q/count-distinct", "q/sum", "q/min", "q/max", "q/avg", "q/join", "q/first", "q/last"]);
|
|
215
|
+
// [op, left, right]
|
|
216
|
+
// [=, $true, $false]
|
|
217
|
+
// [=, $my-id, ["fibery/id"]]
|
|
218
|
+
const binaryOperations = new Set(["=", "!=", "<", ">", "<=", ">=", "in",
|
|
219
|
+
//asc: obsolete,use q/in
|
|
220
|
+
"q/contains", "q/not-contains", "+", "-", "q/+", "q/-", "*", "/", "and", "or",
|
|
221
|
+
//asc: obsolete. use q/and, q/or
|
|
222
|
+
"q/and", "q/or", "q/in", "q/not-in"]);
|
|
223
|
+
|
|
224
|
+
// TODO: get rid of this. Use visitors everywhere
|
|
225
|
+
const naryOperations = new Set(["and", "or", "q/and", "q/or"]);
|
|
226
|
+
const logicalOperators = new Set(["and", "or", "q/and", "q/or"]);
|
|
227
|
+
const relationalOperators = new Set(["=", "!=", "<", ">", "<=", ">="]);
|
|
228
|
+
const mathOperators = new Set(["+", "-", "*", "/", "q/+", "q/-", "q/concat"]);
|
|
229
|
+
const isFunctionCallExpression = expression => expression.length > 1 && ___default["default"].isString(expression[0]) && (expression[0].startsWith("q/") || ["=", "!=", "<", ">", "<=", ">=", "+", "-", "*", "/", "in", "and", "or", "not-in"].includes(expression[0]));
|
|
230
|
+
const fromRootKeyword = "q/from-root";
|
|
231
|
+
const isFromRootFieldExpression = expression => ___default["default"].isArray(expression) && expression[0] === fromRootKeyword;
|
|
232
|
+
const isDateRangeFunctionExpression = expression => (expression.length === 2 || expression.length === 3) && dateRangeFunctions.has(expression[0]) && isFieldExpression(expression[1]);
|
|
233
|
+
const isCollectionFunctionExpression = expression =>
|
|
234
|
+
//expression has length 3 in case of q/join
|
|
235
|
+
(expression.length === 2 || expression.length === 3) && collectionOps.has(expression[0]);
|
|
236
|
+
const isAccessFunctionExpression = expresion => expresion.length === 2 && expresion[0] === "q/access?" && isFieldExpression(expresion[1]);
|
|
237
|
+
const isBinaryExpression = expression => expression.length === 3 && binaryOperations.has(expression[0]);
|
|
238
|
+
const isNaryExpression = expression => expression.length > 1 && naryOperations.has(expression[0]);
|
|
239
|
+
const isVariableExpression = expression => ___default["default"].isString(expression) && expression.startsWith("$");
|
|
240
|
+
const isFieldExpression = expression => Array.isArray(expression) && expression.every(x => !isVariableExpression(x) && !binaryOperations.has(x) && ___default["default"].isString(x));
|
|
241
|
+
const isQueryExpression = expression => {
|
|
242
|
+
if (___default["default"].isObject(expression) && "q/from" in expression) {
|
|
243
|
+
const fromExpression = expression["q/from"];
|
|
244
|
+
//asc: fromExpression === null for denormalizeSelect for reference collection case
|
|
245
|
+
return fromExpression === null || isFieldExpression(fromExpression);
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
};
|
|
249
|
+
// [q/count, [..., collection]]
|
|
250
|
+
// [q/start, [..., range]]
|
|
251
|
+
// [q/end, [..., range]]
|
|
252
|
+
// [q/access?, [..., field-expr]]
|
|
253
|
+
const isFunctionExpression = expression => {
|
|
254
|
+
if (!Array.isArray(expression)) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
if (isFieldExpression(expression)) {
|
|
258
|
+
return false;
|
|
259
|
+
} else if (isDateRangeFunctionExpression(expression) || isCollectionFunctionExpression(expression) || isAccessFunctionExpression(expression)) {
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
throw new Error("invalid expression:" + JSON.stringify(expression));
|
|
263
|
+
};
|
|
264
|
+
const collectFieldExpressions = (memo, expression) => {
|
|
265
|
+
if (isVariableExpression(expression)) ; else if (isFunctionCallExpression(expression)) {
|
|
266
|
+
for (const part of expression.slice(1)) {
|
|
267
|
+
if (isVariableExpression(part) || part === null) ; else {
|
|
268
|
+
if (___default["default"].isString(part)) {
|
|
269
|
+
// field path shortcut
|
|
270
|
+
memo.push([part]);
|
|
271
|
+
} else {
|
|
272
|
+
collectFieldExpressions(memo, part);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
} else if (isFieldExpression(expression)) {
|
|
277
|
+
memo.push(expression);
|
|
278
|
+
} else if (expression["q/from"] && isFieldExpression(expression["q/from"])) {
|
|
279
|
+
const innerMemo = [];
|
|
280
|
+
expression["q/select"] && collectFieldExpressions(innerMemo, expression["q/select"]);
|
|
281
|
+
expression["q/where"] && collectFieldExpressions(innerMemo, expression["q/where"]);
|
|
282
|
+
for (const fieldExpression of innerMemo) {
|
|
283
|
+
memo.push([...expression["q/from"], ...fieldExpression]);
|
|
284
|
+
}
|
|
285
|
+
} else {
|
|
286
|
+
throw new NotImplementedError(expression, "expression");
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const extractFieldExpressions = expression => {
|
|
290
|
+
const memo = [];
|
|
291
|
+
collectFieldExpressions(memo, expression);
|
|
292
|
+
return ___default["default"].uniqBy(memo, x => x.join(","));
|
|
293
|
+
};
|
|
294
|
+
const createExpressionVisitor = visitor => {
|
|
295
|
+
let visitorWithDefault = null;
|
|
296
|
+
const visitorDefault = {
|
|
297
|
+
visitVariableExpression: expression => expression,
|
|
298
|
+
visitFunctionCallExpression: ([fnName, ...args]) => [fnName, ...args.map(x => visitorWithDefault.visitExpression(x))],
|
|
299
|
+
visitFromRootFieldExpression: ([fromRootKeyword, ...rest]) => [fromRootKeyword, ...rest.map(x => visitorWithDefault.visitExpression(x))],
|
|
300
|
+
visitFieldExpression: expression => expression,
|
|
301
|
+
visitOrderByExpression: orderByExpression => orderByExpression.map(x => {
|
|
302
|
+
const [fieldExpression, orderDir] = x;
|
|
303
|
+
const fieldExpressionNew = visitorWithDefault.visitExpression(fieldExpression);
|
|
304
|
+
return [fieldExpressionNew, orderDir];
|
|
305
|
+
}),
|
|
306
|
+
visitQueryExpression: subQueryExpression => {
|
|
307
|
+
const {
|
|
308
|
+
"q/from": fromExpression,
|
|
309
|
+
"q/select": selectExpression,
|
|
310
|
+
"q/where": whereExpression,
|
|
311
|
+
"q/order-by": orderByExpression
|
|
312
|
+
} = subQueryExpression;
|
|
313
|
+
return _extends({}, subQueryExpression, fromExpression ? {
|
|
314
|
+
"q/from": visitorWithDefault.visitFieldExpression(fromExpression)
|
|
315
|
+
} : null, selectExpression ? {
|
|
316
|
+
"q/select": ___default["default"].isPlainObject(selectExpression) ? ___default["default"].mapValues(selectExpression, val => visitorWithDefault.visitExpression(val)) : visitorWithDefault.visitExpression(selectExpression)
|
|
317
|
+
} : null, whereExpression ? {
|
|
318
|
+
"q/where": visitorWithDefault.visitExpression(whereExpression)
|
|
319
|
+
} : null, orderByExpression ? {
|
|
320
|
+
"q/order-by": visitorWithDefault.visitOrderByExpression(orderByExpression)
|
|
321
|
+
} : null);
|
|
322
|
+
},
|
|
323
|
+
visitExpression: expression => {
|
|
324
|
+
if (expression === null) {
|
|
325
|
+
throw new NotImplementedError(expression, "expression");
|
|
326
|
+
} else if (isVariableExpression(expression)) {
|
|
327
|
+
return visitorWithDefault.visitVariableExpression(expression, visitorDefault);
|
|
328
|
+
} else if (isFromRootFieldExpression(expression)) {
|
|
329
|
+
return visitorWithDefault.visitFromRootFieldExpression(expression, visitorDefault);
|
|
330
|
+
} else if (isFunctionCallExpression(expression)) {
|
|
331
|
+
return visitorWithDefault.visitFunctionCallExpression(expression, visitorDefault);
|
|
332
|
+
} else if (isFieldExpression(expression)) {
|
|
333
|
+
return visitorWithDefault.visitFieldExpression(expression, visitorDefault);
|
|
334
|
+
} else if (isQueryExpression(expression)) {
|
|
335
|
+
return visitorWithDefault.visitQueryExpression(expression, visitorDefault);
|
|
336
|
+
} else {
|
|
337
|
+
throw new NotImplementedError(expression, "expression");
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
visitorWithDefault = _extends({}, visitorDefault, visitor);
|
|
342
|
+
return visitorWithDefault;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
var utils = {
|
|
346
|
+
__proto__: null,
|
|
347
|
+
assertIsValidExpression: assertIsValidExpression,
|
|
348
|
+
dateRangeFunctions: dateRangeFunctions,
|
|
349
|
+
firstLastFunctions: firstLastFunctions,
|
|
350
|
+
logicalOperators: logicalOperators,
|
|
351
|
+
relationalOperators: relationalOperators,
|
|
352
|
+
mathOperators: mathOperators,
|
|
353
|
+
isFunctionCallExpression: isFunctionCallExpression,
|
|
354
|
+
fromRootKeyword: fromRootKeyword,
|
|
355
|
+
isFromRootFieldExpression: isFromRootFieldExpression,
|
|
356
|
+
isDateRangeFunctionExpression: isDateRangeFunctionExpression,
|
|
357
|
+
isCollectionFunctionExpression: isCollectionFunctionExpression,
|
|
358
|
+
isAccessFunctionExpression: isAccessFunctionExpression,
|
|
359
|
+
isBinaryExpression: isBinaryExpression,
|
|
360
|
+
isNaryExpression: isNaryExpression,
|
|
361
|
+
isVariableExpression: isVariableExpression,
|
|
362
|
+
isFieldExpression: isFieldExpression,
|
|
363
|
+
isQueryExpression: isQueryExpression,
|
|
364
|
+
isFunctionExpression: isFunctionExpression,
|
|
365
|
+
extractFieldExpressions: extractFieldExpressions,
|
|
366
|
+
createExpressionVisitor: createExpressionVisitor
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const defaultIdsWithNamesOnFieldNotFound = ({
|
|
370
|
+
fieldExpressionInNamesTerms,
|
|
371
|
+
fieldId
|
|
372
|
+
}) => {
|
|
373
|
+
return {
|
|
374
|
+
currentTypeObject: null,
|
|
375
|
+
fieldExpressionInNamesTerms: [...fieldExpressionInNamesTerms, fieldId]
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
const visitFieldExpressionForReplaceIdsWithNamesVisitor = ({
|
|
379
|
+
expression,
|
|
380
|
+
typeObject,
|
|
381
|
+
onFieldNotFound
|
|
382
|
+
}) => expression.reduce(({
|
|
383
|
+
currentTypeObject,
|
|
384
|
+
fieldExpressionInNamesTerms
|
|
385
|
+
}, fieldId) => {
|
|
386
|
+
if (currentTypeObject && currentTypeObject.fieldObjectsById.hasOwnProperty(fieldId)) {
|
|
387
|
+
const fieldObject = currentTypeObject.fieldObjectsById[fieldId];
|
|
388
|
+
return {
|
|
389
|
+
currentTypeObject: fieldObject.typeObject,
|
|
390
|
+
fieldExpressionInNamesTerms: [...fieldExpressionInNamesTerms, fieldObject.name]
|
|
391
|
+
};
|
|
392
|
+
} else {
|
|
393
|
+
return onFieldNotFound({
|
|
394
|
+
currentTypeObject,
|
|
395
|
+
fieldExpressionInNamesTerms,
|
|
396
|
+
fieldId,
|
|
397
|
+
expression
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}, {
|
|
401
|
+
currentTypeObject: typeObject,
|
|
402
|
+
fieldExpressionInNamesTerms: []
|
|
403
|
+
});
|
|
404
|
+
const replaceIdsWithNamesVisitor = (typeObject, onFieldNotFound = defaultIdsWithNamesOnFieldNotFound) => {
|
|
405
|
+
const visitor = createExpressionVisitor({
|
|
406
|
+
visitFieldExpression: expression => visitFieldExpressionForReplaceIdsWithNamesVisitor({
|
|
407
|
+
expression,
|
|
408
|
+
typeObject,
|
|
409
|
+
onFieldNotFound
|
|
410
|
+
}).fieldExpressionInNamesTerms,
|
|
411
|
+
visitQueryExpression: subQueryExpression => {
|
|
412
|
+
const {
|
|
413
|
+
"q/from": fromExpression,
|
|
414
|
+
"q/select": selectExpression,
|
|
415
|
+
"q/where": whereExpression,
|
|
416
|
+
"q/order-by": orderByExpression
|
|
417
|
+
} = subQueryExpression;
|
|
418
|
+
const subQueryTypeObject = visitFieldExpressionForReplaceIdsWithNamesVisitor({
|
|
419
|
+
expression: fromExpression,
|
|
420
|
+
onFieldNotFound,
|
|
421
|
+
typeObject
|
|
422
|
+
}).currentTypeObject;
|
|
423
|
+
if (subQueryTypeObject) {
|
|
424
|
+
const subQueryVisitor = replaceIdsWithNamesVisitor(subQueryTypeObject, onFieldNotFound);
|
|
425
|
+
return _extends({}, subQueryExpression, {
|
|
426
|
+
"q/from": visitor.visitFieldExpression(fromExpression),
|
|
427
|
+
"q/select": ___default["default"].isPlainObject(selectExpression) ? ___default["default"].mapValues(selectExpression, val => subQueryVisitor.visitExpression(val)) : subQueryVisitor.visitExpression(selectExpression)
|
|
428
|
+
}, whereExpression ? {
|
|
429
|
+
"q/where": subQueryVisitor.visitExpression(whereExpression)
|
|
430
|
+
} : null, orderByExpression ? {
|
|
431
|
+
"q/order-by": subQueryVisitor.visitOrderByExpression(orderByExpression)
|
|
432
|
+
} : null);
|
|
433
|
+
}
|
|
434
|
+
return subQueryExpression;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
return visitor;
|
|
438
|
+
};
|
|
439
|
+
const defaultNamesWithIdsOnFieldNotFound = ({
|
|
440
|
+
fieldExpressionInIdsTerms,
|
|
441
|
+
field
|
|
442
|
+
}) => {
|
|
443
|
+
return {
|
|
444
|
+
currentTypeObject: null,
|
|
445
|
+
fieldExpressionInIdsTerms: [...fieldExpressionInIdsTerms, field]
|
|
446
|
+
};
|
|
447
|
+
};
|
|
448
|
+
const visitFieldExpressionForReplaceNamesWithIdsVisitor = ({
|
|
449
|
+
expression,
|
|
450
|
+
onFieldNotFound,
|
|
451
|
+
typeObject
|
|
452
|
+
}) => expression.reduce(({
|
|
453
|
+
currentTypeObject,
|
|
454
|
+
fieldExpressionInIdsTerms
|
|
455
|
+
}, field) => {
|
|
456
|
+
if (currentTypeObject && currentTypeObject.fieldObjectsByName.hasOwnProperty(field)) {
|
|
457
|
+
const fieldObject = currentTypeObject.fieldObjectsByName[field];
|
|
458
|
+
return {
|
|
459
|
+
currentTypeObject: fieldObject.typeObject,
|
|
460
|
+
fieldExpressionInIdsTerms: [...fieldExpressionInIdsTerms, fieldObject.id]
|
|
461
|
+
};
|
|
462
|
+
} else {
|
|
463
|
+
return onFieldNotFound({
|
|
464
|
+
currentTypeObject,
|
|
465
|
+
fieldExpressionInIdsTerms,
|
|
466
|
+
field,
|
|
467
|
+
expression
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}, {
|
|
471
|
+
currentTypeObject: typeObject,
|
|
472
|
+
fieldExpressionInIdsTerms: []
|
|
473
|
+
});
|
|
474
|
+
const replaceNamesWithIdsVisitor = (typeObject, onFieldNotFound = defaultNamesWithIdsOnFieldNotFound) => {
|
|
475
|
+
const visitor = createExpressionVisitor({
|
|
476
|
+
visitFieldExpression: expression => visitFieldExpressionForReplaceNamesWithIdsVisitor({
|
|
477
|
+
expression,
|
|
478
|
+
onFieldNotFound,
|
|
479
|
+
typeObject
|
|
480
|
+
}).fieldExpressionInIdsTerms,
|
|
481
|
+
visitQueryExpression: subQueryExpression => {
|
|
482
|
+
const {
|
|
483
|
+
"q/from": fromExpression,
|
|
484
|
+
"q/select": selectExpression,
|
|
485
|
+
"q/where": whereExpression,
|
|
486
|
+
"q/order-by": orderByExpression
|
|
487
|
+
} = subQueryExpression;
|
|
488
|
+
const subQueryTypeObject = visitFieldExpressionForReplaceNamesWithIdsVisitor({
|
|
489
|
+
expression: fromExpression,
|
|
490
|
+
onFieldNotFound,
|
|
491
|
+
typeObject
|
|
492
|
+
}).currentTypeObject;
|
|
493
|
+
if (subQueryTypeObject) {
|
|
494
|
+
const subQueryVisitor = replaceNamesWithIdsVisitor(subQueryTypeObject, onFieldNotFound);
|
|
495
|
+
return _extends({}, subQueryExpression, {
|
|
496
|
+
"q/from": visitor.visitFieldExpression(fromExpression),
|
|
497
|
+
"q/select": ___default["default"].isPlainObject(selectExpression) ? ___default["default"].mapValues(selectExpression, val => subQueryVisitor.visitExpression(val)) : subQueryVisitor.visitExpression(selectExpression)
|
|
498
|
+
}, whereExpression ? {
|
|
499
|
+
"q/where": subQueryVisitor.visitExpression(whereExpression)
|
|
500
|
+
} : null, orderByExpression ? {
|
|
501
|
+
"q/order-by": subQueryVisitor.visitOrderByExpression(orderByExpression)
|
|
502
|
+
} : null);
|
|
503
|
+
}
|
|
504
|
+
return subQueryExpression;
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
return visitor;
|
|
508
|
+
};
|
|
509
|
+
const deleteExpressionsWithNotFoundFieldsVisitor = typeObject => {
|
|
510
|
+
const visitor = createExpressionVisitor({
|
|
511
|
+
visitFunctionCallExpression: ([fnName, ...args]) => {
|
|
512
|
+
const argsNew = args.map(x => visitor.visitExpression(x)).filter(Boolean);
|
|
513
|
+
if (logicalOperators.has(fnName)) {
|
|
514
|
+
if (argsNew.length > 0) {
|
|
515
|
+
return argsNew.length === 1 ? argsNew[0] : [fnName, ...argsNew];
|
|
516
|
+
}
|
|
517
|
+
return null;
|
|
518
|
+
} else {
|
|
519
|
+
return argsNew.length === args.length ? [fnName, ...argsNew] : null;
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
visitFieldExpression: expression => {
|
|
523
|
+
const fieldTypeObject = expression.reduce((holderTypeObject, field) => holderTypeObject && holderTypeObject.fieldObjectsByName.hasOwnProperty(field) ? holderTypeObject.fieldObjectsByName[field].typeObject : null, typeObject);
|
|
524
|
+
return fieldTypeObject && expression;
|
|
525
|
+
},
|
|
526
|
+
visitOrderByExpression: orderByExpression => {
|
|
527
|
+
return orderByExpression.map(x => {
|
|
528
|
+
const [fieldExpression, orderDir] = x;
|
|
529
|
+
const fieldExpressionNew = visitor.visitExpression(fieldExpression);
|
|
530
|
+
return fieldExpressionNew && [fieldExpressionNew, orderDir];
|
|
531
|
+
}).filter(Boolean);
|
|
532
|
+
},
|
|
533
|
+
visitQueryExpression: subQueryExpression => {
|
|
534
|
+
const {
|
|
535
|
+
"q/from": fromExpression,
|
|
536
|
+
"q/select": selectExpression,
|
|
537
|
+
"q/where": whereExpression,
|
|
538
|
+
"q/order-by": orderByExpression
|
|
539
|
+
} = subQueryExpression;
|
|
540
|
+
const subQueryTypeObject = fromExpression.reduce((typeObject, field) => typeObject && typeObject.fieldObjectsByName.hasOwnProperty(field) ? typeObject.fieldObjectsByName[field].typeObject : null, typeObject);
|
|
541
|
+
if (subQueryTypeObject) {
|
|
542
|
+
const subQueryVisitor = deleteExpressionsWithNotFoundFieldsVisitor(subQueryTypeObject);
|
|
543
|
+
const subQueryExpressionNew = ___default["default"].pickBy(_extends({}, subQueryExpression, {
|
|
544
|
+
"q/from": visitor.visitFieldExpression(fromExpression),
|
|
545
|
+
"q/select": subQueryVisitor.visitExpression(selectExpression)
|
|
546
|
+
}, whereExpression ? {
|
|
547
|
+
"q/where": subQueryVisitor.visitExpression(whereExpression)
|
|
548
|
+
} : null, orderByExpression ? {
|
|
549
|
+
"q/order-by": subQueryVisitor.visitOrderByExpression(orderByExpression)
|
|
550
|
+
} : null));
|
|
551
|
+
const {
|
|
552
|
+
"q/select": selectExpressionNew
|
|
553
|
+
} = subQueryExpressionNew;
|
|
554
|
+
return selectExpressionNew ? subQueryExpressionNew : null;
|
|
555
|
+
} else {
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
return visitor;
|
|
561
|
+
};
|
|
562
|
+
const expressionContainsAggregation = expression => {
|
|
563
|
+
let result = false;
|
|
564
|
+
const visitor = createExpressionVisitor({
|
|
565
|
+
visitQueryExpression: queryExpression => {
|
|
566
|
+
const {
|
|
567
|
+
"q/select": selectExpression
|
|
568
|
+
} = queryExpression;
|
|
569
|
+
if (isCollectionFunctionExpression(selectExpression)) {
|
|
570
|
+
result = true;
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
visitFunctionCallExpression: (expression, visitorDefault) => {
|
|
574
|
+
if (firstLastFunctions.has(expression[0])) {
|
|
575
|
+
result = true;
|
|
576
|
+
} else {
|
|
577
|
+
visitorDefault.visitFunctionCallExpression(expression);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
visitor.visitExpression(expression);
|
|
582
|
+
return result;
|
|
583
|
+
};
|
|
584
|
+
const defaultGetExpressionTypeOnFieldNotFound = () => {
|
|
585
|
+
return {
|
|
586
|
+
currentTypeObject: null
|
|
587
|
+
};
|
|
588
|
+
};
|
|
589
|
+
const getFieldAccessExpressionTypeObject = ({
|
|
590
|
+
expression,
|
|
591
|
+
typeObject,
|
|
592
|
+
onFieldNotFound,
|
|
593
|
+
returnRefTypeInsteadOfId
|
|
594
|
+
}) => {
|
|
595
|
+
const reduced = expression.reduce(({
|
|
596
|
+
currentTypeObject
|
|
597
|
+
}, fieldId, index) => {
|
|
598
|
+
const fieldObject = currentTypeObject && currentTypeObject.fieldObjects.find(f => f.id === fieldId);
|
|
599
|
+
if (fieldObject) {
|
|
600
|
+
if (returnRefTypeInsteadOfId && index === expression.length - 1 && fieldObject.isId) {
|
|
601
|
+
return {
|
|
602
|
+
currentTypeObject
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
return {
|
|
606
|
+
currentTypeObject: fieldObject.typeObject
|
|
607
|
+
};
|
|
608
|
+
} else {
|
|
609
|
+
return onFieldNotFound({
|
|
610
|
+
currentTypeObject,
|
|
611
|
+
fieldId
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
}, {
|
|
615
|
+
currentTypeObject: typeObject
|
|
616
|
+
});
|
|
617
|
+
return reduced.currentTypeObject;
|
|
618
|
+
};
|
|
619
|
+
const UNKNOWN_EXPRESSION_TYPE = "unknown";
|
|
620
|
+
const getExpressionTypeInternal = ({
|
|
621
|
+
expression,
|
|
622
|
+
typeObject,
|
|
623
|
+
functionsMeta,
|
|
624
|
+
onFieldNotFound,
|
|
625
|
+
returnRefTypeInsteadOfId
|
|
626
|
+
}) => {
|
|
627
|
+
let result = null;
|
|
628
|
+
const visitor = createExpressionVisitor({
|
|
629
|
+
visitVariableExpression: function () {
|
|
630
|
+
result = UNKNOWN_EXPRESSION_TYPE;
|
|
631
|
+
},
|
|
632
|
+
visitFunctionCallExpression: function ([fnName, ...args]) {
|
|
633
|
+
const fnMeta = functionsMeta[fnName];
|
|
634
|
+
if (!fnMeta) {
|
|
635
|
+
throw new Error(`Function meta for "${fnName}" was not provided`);
|
|
636
|
+
}
|
|
637
|
+
const argTypes = args.map(arg => getExpressionTypeInternal({
|
|
638
|
+
expression: arg,
|
|
639
|
+
typeObject,
|
|
640
|
+
functionsMeta,
|
|
641
|
+
onFieldNotFound,
|
|
642
|
+
returnRefTypeInsteadOfId: firstLastFunctions.has(fnName) ? returnRefTypeInsteadOfId : false
|
|
643
|
+
}));
|
|
644
|
+
if (firstLastFunctions.has(fnName)) {
|
|
645
|
+
//assuming q/first has one argument and result type equals arg type.
|
|
646
|
+
//we need this trick to support 'returnRefTypeInsteadOfId' behavior for q/first and q/last.
|
|
647
|
+
result = argTypes[0];
|
|
648
|
+
} else {
|
|
649
|
+
const overload = fnMeta.overloads.find(o => o["arg-types"].every((argType, index) => argTypes[index] === UNKNOWN_EXPRESSION_TYPE || argTypes[index] === argType));
|
|
650
|
+
if (!overload) {
|
|
651
|
+
throw new Error(`No overload with args ${argTypes.join(",")} found for "${fnName}" in meta`);
|
|
652
|
+
}
|
|
653
|
+
result = overload["result-type"];
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
visitQueryExpression: expression => {
|
|
657
|
+
const {
|
|
658
|
+
"q/from": fromExpression,
|
|
659
|
+
"q/select": selectExpression
|
|
660
|
+
} = expression;
|
|
661
|
+
const fromTypeObject = getFieldAccessExpressionTypeObject({
|
|
662
|
+
expression: fromExpression,
|
|
663
|
+
typeObject,
|
|
664
|
+
onFieldNotFound,
|
|
665
|
+
returnRefTypeInsteadOfId
|
|
666
|
+
});
|
|
667
|
+
if (!fromTypeObject) {
|
|
668
|
+
result = null;
|
|
669
|
+
}
|
|
670
|
+
if (___default["default"].isPlainObject(selectExpression)) {
|
|
671
|
+
if (Object.values(selectExpression).length !== 1) {
|
|
672
|
+
throw new Error(`Cannot determine type of query expression ${JSON.stringify(expression)}`);
|
|
673
|
+
}
|
|
674
|
+
result = getExpressionTypeInternal({
|
|
675
|
+
expression: Object.values(selectExpression)[0],
|
|
676
|
+
typeObject: fromTypeObject,
|
|
677
|
+
functionsMeta,
|
|
678
|
+
onFieldNotFound,
|
|
679
|
+
returnRefTypeInsteadOfId
|
|
680
|
+
});
|
|
681
|
+
} else {
|
|
682
|
+
result = getExpressionTypeInternal({
|
|
683
|
+
expression: selectExpression,
|
|
684
|
+
typeObject: fromTypeObject,
|
|
685
|
+
functionsMeta,
|
|
686
|
+
onFieldNotFound,
|
|
687
|
+
returnRefTypeInsteadOfId
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
visitFieldExpression(expression) {
|
|
692
|
+
const fieldAccessExpressionTypeObject = getFieldAccessExpressionTypeObject({
|
|
693
|
+
expression,
|
|
694
|
+
typeObject,
|
|
695
|
+
onFieldNotFound,
|
|
696
|
+
returnRefTypeInsteadOfId
|
|
697
|
+
});
|
|
698
|
+
result = fieldAccessExpressionTypeObject && fieldAccessExpressionTypeObject.name;
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
visitor.visitExpression(expression);
|
|
702
|
+
return result;
|
|
703
|
+
};
|
|
704
|
+
const getExpressionType = ({
|
|
705
|
+
expression,
|
|
706
|
+
typeObject,
|
|
707
|
+
functionsMeta,
|
|
708
|
+
onFieldNotFound = defaultGetExpressionTypeOnFieldNotFound,
|
|
709
|
+
returnRefTypeInsteadOfId = true
|
|
710
|
+
}) => {
|
|
711
|
+
return getExpressionTypeInternal({
|
|
712
|
+
expression,
|
|
713
|
+
typeObject,
|
|
714
|
+
functionsMeta,
|
|
715
|
+
onFieldNotFound,
|
|
716
|
+
returnRefTypeInsteadOfId
|
|
717
|
+
});
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
var visitors = {
|
|
721
|
+
__proto__: null,
|
|
722
|
+
replaceIdsWithNamesVisitor: replaceIdsWithNamesVisitor,
|
|
723
|
+
replaceNamesWithIdsVisitor: replaceNamesWithIdsVisitor,
|
|
724
|
+
deleteExpressionsWithNotFoundFieldsVisitor: deleteExpressionsWithNotFoundFieldsVisitor,
|
|
725
|
+
expressionContainsAggregation: expressionContainsAggregation,
|
|
726
|
+
UNKNOWN_EXPRESSION_TYPE: UNKNOWN_EXPRESSION_TYPE,
|
|
727
|
+
getExpressionType: getExpressionType
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
const getEntityQueryVariables = schema => {
|
|
731
|
+
const grouped = ___default["default"].groupBy(schema.typeObjects.filter(x => x.isDomain), typeObject => typeObject.pluralTitle);
|
|
732
|
+
return ___default["default"].flatten(Object.values(grouped).map(group => {
|
|
733
|
+
return group.map(typeObject => ({
|
|
734
|
+
typeObject,
|
|
735
|
+
id: `entityQuery_${typeObject.id}`,
|
|
736
|
+
title: group.length > 1 ? `${typeObject.pluralTitle} (${typeObject.nameParts.namespace})` : typeObject.pluralTitle,
|
|
737
|
+
isCollection: true,
|
|
738
|
+
description: `All Entities from "${typeObject.title}" Database`
|
|
739
|
+
}));
|
|
740
|
+
}));
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
var contextVariables = {
|
|
744
|
+
__proto__: null,
|
|
745
|
+
getEntityQueryVariables: getEntityQueryVariables
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
exports.contextVariables = contextVariables;
|
|
749
|
+
exports.paramsPlaceholders = paramsPlaceholders;
|
|
750
|
+
exports.utils = utils;
|
|
751
|
+
exports.visitors = visitors;
|