@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.
@@ -1,232 +0,0 @@
1
- var _ = require('lodash');
2
- var moment = require('moment');
3
-
4
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
5
-
6
- var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
7
- var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
8
-
9
- const serializeDate = momentDate => {
10
- return momentDate.format("YYYY-MM-DD");
11
- };
12
- const serializeDateTime = momentDate => {
13
- return momentDate.toISOString();
14
- };
15
- const formulaTodayDateParamPlaceholder = "$formula-today-date-placeholder";
16
- const formulaNowDateTimeParamPlaceholder = "$formula-now-date-time-placeholder";
17
- const todayDateParamPlaceholder = "$today-date";
18
- const tomorrowDateParamPlaceholder = "$tomorrow-date";
19
- const yesterdayDateParamPlaceholder = "$yesterday-date";
20
- const weekAgoDateParamPlaceholder = "$week-ago-date";
21
- const weekFromNowDateParamPlaceholder = "$week-from-now-date";
22
- const monthAgoDateParamPlaceholder = "$month-ago-date";
23
- const monthFromNowDateParamPlaceholder = "$month-from-now-date";
24
- const yearAgoDateParamPlaceholder = "$year-ago-date";
25
- const yearFromNowDateParamPlaceholder = "$year-from-now-date";
26
- const todayStartDateTimeParamPlaceholder = "$today-date-time-start";
27
- const todayEndDateTimeParamPlaceholder = "$today-date-time-end";
28
- const tomorrowStartDateTimeParamPlaceholder = "$tomorrow-date-time-start";
29
- const tomorrowEndDateTimeParamPlaceholder = "$tomorrow-date-time-end";
30
- const yesterdayStartDateTimeParamPlaceholder = "$yesterday-date-time-start";
31
- const yesterdayEndDateTimeParamPlaceholder = "$yesterday-date-time-end";
32
- const weekAgoStartDateTimeParamPlaceholder = "$week-ago-date-time-start";
33
- const weekAgoEndDateTimeParamPlaceholder = "$week-ago-date-time-end";
34
- const weekFromNowStartDateTimeParamPlaceholder = "$week-from-now-date-time-start";
35
- const weekFromNowEndDateTimeParamPlaceholder = "$week-from-now-date-time-end";
36
- const monthAgoStartDateTimeParamPlaceholder = "$month-ago-date-time-start";
37
- const monthAgoEndDateTimeParamPlaceholder = "$month-ago-date-time-end";
38
- const monthFromNowStartDateTimeParamPlaceholder = "$month-from-now-date-time-start";
39
- const monthFromNowEndDateTimeParamPlaceholder = "$month-from-now-date-time-end";
40
- const yearAgoStartDateTimeParamPlaceholder = "$year-ago-date-time-start";
41
- const yearAgoEndDateTimeParamPlaceholder = "$year-ago-date-time-end";
42
- const yearFromNowStartDateTimeParamPlaceholder = "$year-from-now-date-time-start";
43
- const yearFromNowEndDateTimeParamPlaceholder = "$year-from-now-date-time-end";
44
- const paramsPlaceholdersLookup = {
45
- [todayDateParamPlaceholder]: () => serializeDate(moment__default["default"]()),
46
- [formulaTodayDateParamPlaceholder]: () => serializeDate(moment__default["default"]()),
47
- [formulaNowDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]()),
48
- [tomorrowDateParamPlaceholder]: () => serializeDate(moment__default["default"]().add(1, "days")),
49
- [yesterdayDateParamPlaceholder]: () => serializeDate(moment__default["default"]().subtract(1, "days")),
50
- [weekAgoDateParamPlaceholder]: () => serializeDate(moment__default["default"]().subtract(7, "days")),
51
- [weekFromNowDateParamPlaceholder]: () => serializeDate(moment__default["default"]().add(7, "days")),
52
- [monthAgoDateParamPlaceholder]: () => serializeDate(moment__default["default"]().subtract(1, "months")),
53
- [monthFromNowDateParamPlaceholder]: () => serializeDate(moment__default["default"]().add(1, "months")),
54
- [yearAgoDateParamPlaceholder]: () => serializeDate(moment__default["default"]().subtract(1, "year")),
55
- [yearFromNowDateParamPlaceholder]: () => serializeDate(moment__default["default"]().add(1, "year")),
56
- [todayStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().startOf("day")),
57
- [todayEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().endOf("day")),
58
- [tomorrowStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "days").startOf("day")),
59
- [tomorrowEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "days").endOf("day")),
60
- [yesterdayStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "days").startOf("day")),
61
- [yesterdayEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "days").endOf("day")),
62
- [weekAgoStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(7, "days").startOf("day")),
63
- [weekAgoEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(7, "days").endOf("day")),
64
- [weekFromNowStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(7, "days").startOf("day")),
65
- [weekFromNowEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(7, "days").endOf("day")),
66
- [monthAgoStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "months").startOf("day")),
67
- [monthAgoEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "months").endOf("day")),
68
- [monthFromNowStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "months").startOf("day")),
69
- [monthFromNowEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "months").endOf("day")),
70
- [yearAgoStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "year").startOf("day")),
71
- [yearAgoEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().subtract(1, "year").endOf("day")),
72
- [yearFromNowStartDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "year").startOf("day")),
73
- [yearFromNowEndDateTimeParamPlaceholder]: () => serializeDateTime(moment__default["default"]().add(1, "year").endOf("day"))
74
- };
75
- const dynamicFilterParamPrefix = `$dynamic_`;
76
- const isDynamicFilterParam = paramValue => paramValue.startsWith(dynamicFilterParamPrefix);
77
- const getFieldIdFromDynamicParam = paramValue => paramValue.substring(dynamicFilterParamPrefix.length);
78
- const whereParamPrefix = "$where";
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 relativeDatePlaceholderRegex = /\$(?:start-|end-|start-of-day-|end-of-day-)?(\d+)-(second|minute|hour|day|week|month|quarter|year)-(before-now|after-now)-(date-time|date)/;
94
- const getRelativeDateValue = ({
95
- isStartOfInterval,
96
- unitForStart,
97
- amount,
98
- unit,
99
- isBeforeNow,
100
- isDateTime
101
- }) => {
102
- const result = isBeforeNow ? moment__default["default"]().subtract(amount, unit) : moment__default["default"]().add(amount, unit);
103
- if (isStartOfInterval === undefined) {
104
- return isDateTime ? serializeDateTime(result) : serializeDate(result);
105
- } else {
106
- const resultByStartEnd = isStartOfInterval ? result.startOf(unitForStart) : result.endOf(unitForStart);
107
- return isDateTime ? serializeDateTime(resultByStartEnd) : serializeDate(resultByStartEnd);
108
- }
109
- };
110
- const toRelativeDatePlaceholder = ({
111
- isStartOfInterval,
112
- unitForStart,
113
- amount,
114
- unit,
115
- isBeforeNow,
116
- isDateTime
117
- }) => {
118
- return `$${isStartOfInterval === undefined ? "" : isStartOfInterval ? `start-of-${unitForStart}-` : `end-of-${unitForStart}-`}${amount}-${unit}-${isBeforeNow ? "before-now" : "after-now"}-${isDateTime ? "date-time" : "date"}`;
119
- };
120
- const parseRelativeDatePlaceholder = placeholder => {
121
- if (typeof placeholder === "string") {
122
- const relativeDatePlaceholderMatch = placeholder.match(relativeDatePlaceholderRegex);
123
- if (relativeDatePlaceholderMatch) {
124
- const fullMatch = relativeDatePlaceholderMatch[0];
125
- const isStartOfInterval = fullMatch.startsWith("$start") ? true : fullMatch.startsWith("$end") ? false : undefined;
126
- let unit = relativeDatePlaceholderMatch[2];
127
- return {
128
- isStartOfInterval,
129
- unitForStart:
130
- // Usually the "start" unit is the same as the unit for relative date calculation.
131
- // e.g. when we calculate the date "1 week ago", we want the beginning of the previous week.
132
- // But sometimes they are different. We have hardcoded "day" for now, but this can be extended to any unit.
133
- fullMatch.startsWith("$start-of-day") || fullMatch.startsWith("$end-of-day") ? "day" : isStartOfInterval !== undefined ? unit : undefined,
134
- amount: Number.parseInt(relativeDatePlaceholderMatch[1]),
135
- unit,
136
- isBeforeNow: relativeDatePlaceholderMatch[3] === "before-now",
137
- isDateTime: relativeDatePlaceholderMatch[4] === "date-time"
138
- };
139
- }
140
- }
141
- return null;
142
- };
143
- const replacePlaceholdersInParams = params => params && ___default["default"].mapValues(params, (value, key) => {
144
- const replaceFn = paramsPlaceholdersLookup[key];
145
- if (replaceFn) {
146
- return replaceFn();
147
- }
148
- const relativeDateInfo = parseRelativeDatePlaceholder(key);
149
- if (relativeDateInfo) {
150
- return getRelativeDateValue(relativeDateInfo);
151
- }
152
- return value;
153
- });
154
- const dateToDateTimeIntervalLookup = {
155
- [todayDateParamPlaceholder]: {
156
- start: todayStartDateTimeParamPlaceholder,
157
- end: todayEndDateTimeParamPlaceholder
158
- },
159
- [tomorrowDateParamPlaceholder]: {
160
- start: tomorrowStartDateTimeParamPlaceholder,
161
- end: tomorrowEndDateTimeParamPlaceholder
162
- },
163
- [yesterdayDateParamPlaceholder]: {
164
- start: yesterdayStartDateTimeParamPlaceholder,
165
- end: yesterdayEndDateTimeParamPlaceholder
166
- },
167
- [weekAgoDateParamPlaceholder]: {
168
- start: weekAgoStartDateTimeParamPlaceholder,
169
- end: weekAgoEndDateTimeParamPlaceholder
170
- },
171
- [weekFromNowDateParamPlaceholder]: {
172
- start: weekFromNowStartDateTimeParamPlaceholder,
173
- end: weekFromNowEndDateTimeParamPlaceholder
174
- },
175
- [monthAgoDateParamPlaceholder]: {
176
- start: monthAgoStartDateTimeParamPlaceholder,
177
- end: monthAgoEndDateTimeParamPlaceholder
178
- },
179
- [monthFromNowDateParamPlaceholder]: {
180
- start: monthFromNowStartDateTimeParamPlaceholder,
181
- end: monthFromNowEndDateTimeParamPlaceholder
182
- },
183
- [yearAgoDateParamPlaceholder]: {
184
- start: yearAgoStartDateTimeParamPlaceholder,
185
- end: yearAgoEndDateTimeParamPlaceholder
186
- },
187
- [yearFromNowDateParamPlaceholder]: {
188
- start: yearFromNowStartDateTimeParamPlaceholder,
189
- end: yearFromNowEndDateTimeParamPlaceholder
190
- }
191
- };
192
-
193
- exports.dateToDateTimeIntervalLookup = dateToDateTimeIntervalLookup;
194
- exports.dynamicFilterParamPrefix = dynamicFilterParamPrefix;
195
- exports.formulaNowDateTimeParamPlaceholder = formulaNowDateTimeParamPlaceholder;
196
- exports.formulaTodayDateParamPlaceholder = formulaTodayDateParamPlaceholder;
197
- exports.getFieldIdFromDynamicParam = getFieldIdFromDynamicParam;
198
- exports.getRelativeDateValue = getRelativeDateValue;
199
- exports.isDynamicFilterParam = isDynamicFilterParam;
200
- exports.mapDynamicParams = mapDynamicParams;
201
- exports.monthAgoDateParamPlaceholder = monthAgoDateParamPlaceholder;
202
- exports.monthAgoEndDateTimeParamPlaceholder = monthAgoEndDateTimeParamPlaceholder;
203
- exports.monthAgoStartDateTimeParamPlaceholder = monthAgoStartDateTimeParamPlaceholder;
204
- exports.monthFromNowDateParamPlaceholder = monthFromNowDateParamPlaceholder;
205
- exports.monthFromNowEndDateTimeParamPlaceholder = monthFromNowEndDateTimeParamPlaceholder;
206
- exports.monthFromNowStartDateTimeParamPlaceholder = monthFromNowStartDateTimeParamPlaceholder;
207
- exports.paramsPlaceholdersLookup = paramsPlaceholdersLookup;
208
- exports.parseRelativeDatePlaceholder = parseRelativeDatePlaceholder;
209
- exports.replacePlaceholdersInParams = replacePlaceholdersInParams;
210
- exports.toRelativeDatePlaceholder = toRelativeDatePlaceholder;
211
- exports.todayDateParamPlaceholder = todayDateParamPlaceholder;
212
- exports.todayEndDateTimeParamPlaceholder = todayEndDateTimeParamPlaceholder;
213
- exports.todayStartDateTimeParamPlaceholder = todayStartDateTimeParamPlaceholder;
214
- exports.tomorrowDateParamPlaceholder = tomorrowDateParamPlaceholder;
215
- exports.tomorrowEndDateTimeParamPlaceholder = tomorrowEndDateTimeParamPlaceholder;
216
- exports.tomorrowStartDateTimeParamPlaceholder = tomorrowStartDateTimeParamPlaceholder;
217
- exports.weekAgoDateParamPlaceholder = weekAgoDateParamPlaceholder;
218
- exports.weekAgoEndDateTimeParamPlaceholder = weekAgoEndDateTimeParamPlaceholder;
219
- exports.weekAgoStartDateTimeParamPlaceholder = weekAgoStartDateTimeParamPlaceholder;
220
- exports.weekFromNowDateParamPlaceholder = weekFromNowDateParamPlaceholder;
221
- exports.weekFromNowEndDateTimeParamPlaceholder = weekFromNowEndDateTimeParamPlaceholder;
222
- exports.weekFromNowStartDateTimeParamPlaceholder = weekFromNowStartDateTimeParamPlaceholder;
223
- exports.whereParamPrefix = whereParamPrefix;
224
- exports.yearAgoDateParamPlaceholder = yearAgoDateParamPlaceholder;
225
- exports.yearAgoEndDateTimeParamPlaceholder = yearAgoEndDateTimeParamPlaceholder;
226
- exports.yearAgoStartDateTimeParamPlaceholder = yearAgoStartDateTimeParamPlaceholder;
227
- exports.yearFromNowDateParamPlaceholder = yearFromNowDateParamPlaceholder;
228
- exports.yearFromNowEndDateTimeParamPlaceholder = yearFromNowEndDateTimeParamPlaceholder;
229
- exports.yearFromNowStartDateTimeParamPlaceholder = yearFromNowStartDateTimeParamPlaceholder;
230
- exports.yesterdayDateParamPlaceholder = yesterdayDateParamPlaceholder;
231
- exports.yesterdayEndDateTimeParamPlaceholder = yesterdayEndDateTimeParamPlaceholder;
232
- exports.yesterdayStartDateTimeParamPlaceholder = yesterdayStartDateTimeParamPlaceholder;
package/lib/utils.js DELETED
@@ -1,223 +0,0 @@
1
- var trace = require('@fibery/helpers/utils/trace');
2
- var _ = require('lodash');
3
-
4
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
5
-
6
- var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
7
-
8
- const stringify = x => {
9
- if (x === undefined) {
10
- return "undefined";
11
- }
12
- return JSON.stringify(x);
13
- };
14
- class NotImplementedError extends Error {
15
- constructor(value, itemType = undefined) {
16
- super([`"${stringify(value)}"`, itemType, "is not implemented"].filter(x => x !== undefined).join(" "));
17
- }
18
- }
19
-
20
- const assertIsValidExpression = expression => {
21
- trace.assert(Array.isArray(expression), "expression must be array", {
22
- expression
23
- });
24
- trace.assert(expression.length > 0, "empty expression does not make any sense");
25
- };
26
- const textTypes = ["fibery/text", "fibery/email", "fibery/url", "fibery/emoji"];
27
- const dateTypes = ["fibery/date", "fibery/date-time"];
28
- const dateRangeTypes = ["fibery/date-range", "fibery/date-time-range"];
29
- const convertableDateTypes = ["fibery/date", "fibery/date-range"];
30
- const numberTypes = ["fibery/int", "fibery/decimal"];
31
- const dateRangeFunctions = new Set(["q/start", "q/end"]);
32
- const firstLastFunctions = new Set(["q/first", "q/last"]);
33
- const collectionOps = new Set(["q/count", "q/count-distinct", "q/sum", "q/min", "q/max", "q/avg", "q/join", "q/first", "q/last"]);
34
- // [op, left, right]
35
- // [=, $true, $false]
36
- // [=, $my-id, ["fibery/id"]]
37
- const binaryOperations = new Set(["=", "!=", "<", ">", "<=", ">=", "in",
38
- //asc: obsolete,use q/in
39
- "q/contains", "q/not-contains", "+", "-", "q/+", "q/-", "*", "/", "and", "or",
40
- //asc: obsolete. use q/and, q/or
41
- "q/and", "q/or", "q/in", "q/not-in"]);
42
- const logicalOperators = new Set(["and", "or", "q/and", "q/or"]);
43
- const relationalOperators = new Set(["=", "!=", "<", ">", "<=", ">="]);
44
- const mathOperators = new Set(["+", "-", "*", "/", "q/+", "q/-", "q/concat"]);
45
- const isFunctionCallExpression = expression => expression.length > 1 && ___default["default"].isString(expression[0]) && (expression[0].startsWith("q/") || ["=", "!=", "<", ">", "<=", ">=", "+", "-", "*", "/", "in", "and", "or", "not-in"].includes(expression[0]));
46
- const fromRootKeyword = "q/from-root";
47
- const isFromRootFieldExpression = expression => ___default["default"].isArray(expression) && expression[0] === fromRootKeyword;
48
- const isDateRangeFunctionExpression = expression => (expression.length === 2 || expression.length === 3) && dateRangeFunctions.has(expression[0]) && isFieldExpression(expression[1]);
49
- const isCollectionFunctionExpression = expression =>
50
- //expression has length 3 in case of q/join
51
- (expression.length === 2 || expression.length === 3) && collectionOps.has(expression[0]);
52
- const isAccessFunctionExpression = expresion => expresion.length === 2 && expresion[0] === "q/access?" && isFieldExpression(expresion[1]);
53
- const isBinaryExpression = expression => expression.length === 3 && binaryOperations.has(expression[0]);
54
- const isNaryExpression = expression => expression.length > 1 && logicalOperators.has(expression[0]);
55
- const isVariableExpression = expression => ___default["default"].isString(expression) && expression.startsWith("$");
56
- const isMultiFieldAccess = expression => ___default["default"].isArray(expression) && expression.length === 2 && !isFunctionCallExpression(expression) && expression.every(x => ___default["default"].isString(x));
57
- const isMultiFieldExpression = expression => Array.isArray(expression) && !isFunctionCallExpression(expression) && expression.some(x => isMultiFieldAccess(x)) && expression.every(x => !isVariableExpression(x) && !binaryOperations.has(x) && (___default["default"].isString(x) || isMultiFieldAccess(x)));
58
- const isFieldExpression = expression => Array.isArray(expression) && !isFunctionCallExpression(expression) && expression.every(x => !isVariableExpression(x) && ___default["default"].isString(x));
59
- const isQueryExpression = expression => {
60
- if (___default["default"].isObject(expression) && "q/from" in expression) {
61
- const fromExpression = expression["q/from"];
62
- //asc: fromExpression === null for denormalizeSelect for reference collection case
63
- return fromExpression === null || isFieldExpression(fromExpression) || isFromRootFieldExpression(fromExpression) || isMultiFieldExpression(fromExpression);
64
- }
65
- return false;
66
- };
67
- const collectFieldExpressions = (memo, expression) => {
68
- if (isVariableExpression(expression)) ; else if (isFunctionCallExpression(expression)) {
69
- for (const part of expression.slice(1)) {
70
- if (isVariableExpression(part) || part === null) ; else {
71
- if (___default["default"].isString(part)) {
72
- // field path shortcut
73
- memo.push([part]);
74
- } else {
75
- collectFieldExpressions(memo, part);
76
- }
77
- }
78
- }
79
- } else if (isFieldExpression(expression) || isMultiFieldExpression(expression)) {
80
- memo.push(expression);
81
- } else if (expression["q/from"] && isFieldExpression(expression["q/from"])) {
82
- const innerMemo = [];
83
- expression["q/select"] && collectFieldExpressions(innerMemo, expression["q/select"]);
84
- expression["q/where"] && collectFieldExpressions(innerMemo, expression["q/where"]);
85
- for (const fieldExpression of innerMemo) {
86
- memo.push([...expression["q/from"], ...fieldExpression]);
87
- }
88
- } else {
89
- throw new NotImplementedError(expression, "expression");
90
- }
91
- };
92
- const getFieldObjectsByFieldExpression = ({
93
- typeObject,
94
- expression
95
- }) => {
96
- assertIsValidExpression(expression);
97
- const fieldObjects = [];
98
- let currentTypeObject = typeObject;
99
- for (const fieldOrMultiFieldAccess of expression) {
100
- if (isMultiFieldAccess(fieldOrMultiFieldAccess)) {
101
- const [multiField, type] = fieldOrMultiFieldAccess;
102
- const fieldObject = currentTypeObject.fieldObjectsByName[multiField];
103
- fieldObjects.push(fieldObject);
104
- const foundField = fieldObject.multiRelatedFieldObjects.find(f => f.holderType === type);
105
- trace.assert(foundField, "incorrect expression for multi-field");
106
- currentTypeObject = foundField.holderTypeObject;
107
- } else {
108
- const fieldObject = currentTypeObject.fieldObjectsByName[fieldOrMultiFieldAccess];
109
- fieldObjects.push(fieldObject);
110
- currentTypeObject = fieldObject.typeObject;
111
- }
112
- }
113
- return fieldObjects;
114
- };
115
- const getFieldObjectByFieldExpression = (x // TODO: review types. using type assertion now to avoid rewriting half of app
116
- ) => ___default["default"].last(getFieldObjectsByFieldExpression(x));
117
- const getFieldObjects = (expression, typeObject) => {
118
- const fieldExpression = extractFieldExpressions(expression)[0];
119
- return getFieldObjectsByFieldExpression({
120
- typeObject,
121
- expression: fieldExpression
122
- });
123
- };
124
-
125
- /** @deprecated
126
- * This method checks few expression forms, that we do not generate on frontend anymore(field-access shortcut, direct value as parameter).
127
- * 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.
128
- * If you need this method in new places, consider implementing same logic on visitors and use it.
129
- **/
130
- const extractFieldExpressions = expression => {
131
- const memo = [];
132
- collectFieldExpressions(memo, expression);
133
- return ___default["default"].uniqBy(memo, x => x.join(","));
134
- };
135
- const createExpressionVisitor = visitor => {
136
- let visitorWithDefault = null;
137
- const visitorDefault = {
138
- visitVariableExpression: expression => expression,
139
- visitFunctionCallExpression: ([fnName, ...args]) => [fnName, ...args.map(x => visitorWithDefault.visitExpression(x))],
140
- visitFromRootFieldExpression: ([fromRootKeyword, ...rest]) => [fromRootKeyword, ...rest.map(x => visitorWithDefault.visitExpression(x))],
141
- visitFieldExpression: expression => expression,
142
- visitOrderByExpression: orderByExpression => orderByExpression.map(x => {
143
- const [fieldExpression, orderDir] = x;
144
- const fieldExpressionNew = visitorWithDefault.visitExpression(fieldExpression);
145
- return [fieldExpressionNew, orderDir];
146
- }),
147
- visitQueryExpression: subQueryExpression => {
148
- const {
149
- "q/from": fromExpression,
150
- "q/select": selectExpression,
151
- "q/where": whereExpression,
152
- "q/order-by": orderByExpression
153
- } = subQueryExpression;
154
- return {
155
- ...subQueryExpression,
156
- ...(fromExpression ? {
157
- "q/from": visitorWithDefault.visitFieldExpression(fromExpression)
158
- } : null),
159
- ...(selectExpression ? {
160
- "q/select": ___default["default"].isPlainObject(selectExpression) ? ___default["default"].mapValues(selectExpression, val => visitorWithDefault.visitExpression(val)) : visitorWithDefault.visitExpression(selectExpression)
161
- } : null),
162
- ...(whereExpression ? {
163
- "q/where": visitorWithDefault.visitExpression(whereExpression)
164
- } : null),
165
- ...(orderByExpression ? {
166
- "q/order-by": visitorWithDefault.visitOrderByExpression(orderByExpression)
167
- } : null)
168
- };
169
- },
170
- visitExpression: expression => {
171
- if (expression === null) {
172
- throw new NotImplementedError(expression, "expression");
173
- } else if (isVariableExpression(expression)) {
174
- return visitorWithDefault.visitVariableExpression(expression, visitorDefault);
175
- } else if (isFromRootFieldExpression(expression)) {
176
- return visitorWithDefault.visitFromRootFieldExpression(expression, visitorDefault);
177
- } else if (isFunctionCallExpression(expression)) {
178
- return visitorWithDefault.visitFunctionCallExpression(expression, visitorDefault);
179
- } else if (isFieldExpression(expression) || isMultiFieldExpression(expression)) {
180
- return visitorWithDefault.visitFieldExpression(expression, visitorDefault);
181
- } else if (isQueryExpression(expression)) {
182
- return visitorWithDefault.visitQueryExpression(expression, visitorDefault);
183
- } else {
184
- throw new NotImplementedError(expression, "expression");
185
- }
186
- }
187
- };
188
- visitorWithDefault = {
189
- ...visitorDefault,
190
- ...visitor
191
- };
192
- return visitorWithDefault;
193
- };
194
-
195
- exports.assertIsValidExpression = assertIsValidExpression;
196
- exports.convertableDateTypes = convertableDateTypes;
197
- exports.createExpressionVisitor = createExpressionVisitor;
198
- exports.dateRangeFunctions = dateRangeFunctions;
199
- exports.dateRangeTypes = dateRangeTypes;
200
- exports.dateTypes = dateTypes;
201
- exports.extractFieldExpressions = extractFieldExpressions;
202
- exports.firstLastFunctions = firstLastFunctions;
203
- exports.fromRootKeyword = fromRootKeyword;
204
- exports.getFieldObjectByFieldExpression = getFieldObjectByFieldExpression;
205
- exports.getFieldObjects = getFieldObjects;
206
- exports.getFieldObjectsByFieldExpression = getFieldObjectsByFieldExpression;
207
- exports.isAccessFunctionExpression = isAccessFunctionExpression;
208
- exports.isBinaryExpression = isBinaryExpression;
209
- exports.isCollectionFunctionExpression = isCollectionFunctionExpression;
210
- exports.isDateRangeFunctionExpression = isDateRangeFunctionExpression;
211
- exports.isFieldExpression = isFieldExpression;
212
- exports.isFromRootFieldExpression = isFromRootFieldExpression;
213
- exports.isFunctionCallExpression = isFunctionCallExpression;
214
- exports.isMultiFieldAccess = isMultiFieldAccess;
215
- exports.isMultiFieldExpression = isMultiFieldExpression;
216
- exports.isNaryExpression = isNaryExpression;
217
- exports.isQueryExpression = isQueryExpression;
218
- exports.isVariableExpression = isVariableExpression;
219
- exports.logicalOperators = logicalOperators;
220
- exports.mathOperators = mathOperators;
221
- exports.numberTypes = numberTypes;
222
- exports.relationalOperators = relationalOperators;
223
- exports.textTypes = textTypes;