@fibery/views 1.1.16 → 2.0.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/views.js DELETED
@@ -1,1229 +0,0 @@
1
- var utils = require('@fibery/expression-utils/utils');
2
- var immutableUpdate = require('immutability-helper');
3
- var _ = require('lodash');
4
- var visitors = require('@fibery/expression-utils/visitors');
5
-
6
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
-
8
- var immutableUpdate__default = /*#__PURE__*/_interopDefaultLegacy(immutableUpdate);
9
- var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
10
-
11
- function _extends() {
12
- _extends = Object.assign ? Object.assign.bind() : function (target) {
13
- for (var i = 1; i < arguments.length; i++) {
14
- var source = arguments[i];
15
- for (var key in source) {
16
- if (Object.prototype.hasOwnProperty.call(source, key)) {
17
- target[key] = source[key];
18
- }
19
- }
20
- }
21
- return target;
22
- };
23
- return _extends.apply(this, arguments);
24
- }
25
-
26
- const getFieldType = (schema, fromType, field) => {
27
- if (!schema.typeObjectsByName.hasOwnProperty(fromType) || !schema.typeObjectsByName[fromType].fieldObjectsByName.hasOwnProperty(field)) {
28
- return null;
29
- }
30
- return schema.typeObjectsByName[fromType].fieldObjectsByName[field].type;
31
- };
32
- const getFieldMeta = (schema, fromType, field) => {
33
- if (!schema.typeObjectsByName.hasOwnProperty(fromType) || !schema.typeObjectsByName[fromType].fieldObjectsByName.hasOwnProperty(field)) {
34
- return null;
35
- }
36
- return schema.typeObjectsByName[fromType].fieldObjectsByName[field].rawMeta;
37
- };
38
- const getUnitTypeForTextField = fieldMeta => {
39
- switch (fieldMeta["ui/type"]) {
40
- case "email":
41
- return "email";
42
- case "url":
43
- return "url";
44
- case "phone":
45
- return "phone";
46
- default:
47
- return "text";
48
- }
49
- };
50
- const fixViewUnit = (schema, fromType, unit) => {
51
- const {
52
- type,
53
- expression
54
- } = unit;
55
- if (type === "date") {
56
- const [field] = expression;
57
- if (getFieldType(schema, fromType, field) === "fibery/date-time") {
58
- return _extends({}, unit, {
59
- type: "date-time"
60
- });
61
- }
62
- }
63
- if (type === "date-range") {
64
- const [field] = expression;
65
- if (getFieldType(schema, fromType, field) === "fibery/date-time-range") {
66
- return _extends({}, unit, {
67
- type: "date-time-range"
68
- });
69
- }
70
- }
71
- if (type === "text") {
72
- const [field] = expression;
73
- const fieldType = getFieldType(schema, fromType, field);
74
- if (fieldType === "fibery/email") {
75
- return _extends({}, unit, {
76
- type: "email"
77
- });
78
- }
79
- }
80
- if (["text", "email", "phone", "url"].includes(type)) {
81
- const [field] = expression;
82
- if (getFieldType(schema, fromType, field) === "fibery/text") {
83
- return _extends({}, unit, {
84
- type: getUnitTypeForTextField(getFieldMeta(schema, fromType, field))
85
- });
86
- }
87
- }
88
- return unit;
89
- };
90
-
91
- // Return this symbol from a visitor callback to remove the node from the
92
- // output. Not supported in all places, add support as needed.
93
- const REMOVE = Symbol("remove");
94
- const deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression = (schema, queryExpression) => {
95
- const {
96
- "q/from": fromExpression,
97
- "q/where": whereExpression,
98
- "q/order-by": orderByExpression
99
- } = queryExpression;
100
- if (schema.typeObjectsByName.hasOwnProperty(fromExpression)) {
101
- const typeObject = schema.typeObjectsByName[fromExpression];
102
- return ___default["default"].pickBy(_extends({}, queryExpression, whereExpression ? {
103
- "q/where": visitors.deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitExpression(whereExpression)
104
- } : null, orderByExpression ? {
105
- "q/order-by": visitors.deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitOrderByExpression(orderByExpression)
106
- } : null));
107
- }
108
- return null;
109
- };
110
- const replaceNamesWithIdsInExpression = (schema, fromType, expression) => {
111
- if (schema.typeObjectsByName.hasOwnProperty(fromType)) {
112
- const typeObject = schema.typeObjectsByName[fromType];
113
- return visitors.replaceNamesWithIdsVisitor(typeObject).visitExpression(expression);
114
- }
115
- return expression;
116
- };
117
- const replaceIdsWithNamesInExpression = (schema, fromTypeId, expression) => {
118
- if (schema.typeObjectsById.hasOwnProperty(fromTypeId)) {
119
- const typeObject = schema.typeObjectsById[fromTypeId];
120
- return visitors.replaceIdsWithNamesVisitor(typeObject).visitExpression(expression);
121
- }
122
- return expression;
123
- };
124
- const visitViewUnit = (fromType, unit, visitor) => {
125
- const {
126
- expression
127
- } = unit;
128
- if (expression) {
129
- return _extends({}, unit, {
130
- expression: visitor.visitExpression(fromType, expression)
131
- });
132
- }
133
- return unit;
134
- };
135
- const visitContextExpression = (fromType, contextExpression, visitor) => {
136
- const visitContextExpression = visitor.visitContextExpression ? visitor.visitContextExpression : visitor.visitExpression;
137
- return contextExpression ? visitContextExpression(fromType, contextExpression) : contextExpression;
138
- };
139
- const replaceIdsWithNamesInQueryExpression = (schema, queryExpression) => {
140
- const {
141
- "q/from": fromExpression,
142
- "q/where": whereExpression,
143
- "q/order-by": orderByExpression
144
- } = queryExpression;
145
- if (schema.typeObjectsById.hasOwnProperty(fromExpression)) {
146
- const typeObject = schema.typeObjectsById[fromExpression];
147
- return _extends({}, queryExpression, {
148
- "q/from": typeObject.name
149
- }, whereExpression ? {
150
- "q/where": visitors.replaceIdsWithNamesVisitor(typeObject).visitExpression(whereExpression)
151
- } : null, orderByExpression ? {
152
- "q/order-by": visitors.replaceIdsWithNamesVisitor(typeObject).visitOrderByExpression(orderByExpression)
153
- } : null);
154
- }
155
- return queryExpression;
156
- };
157
- const replaceNamesWithIdsInQueryExpression = (schema, queryExpression) => {
158
- const {
159
- "q/from": fromExpression,
160
- "q/where": whereExpression,
161
- "q/order-by": orderByExpression
162
- } = queryExpression;
163
- if (schema.typeObjectsByName.hasOwnProperty(fromExpression)) {
164
- const typeObject = schema.typeObjectsByName[fromExpression];
165
- return _extends({}, queryExpression, {
166
- "q/from": typeObject.id
167
- }, whereExpression ? {
168
- "q/where": visitors.replaceNamesWithIdsVisitor(typeObject).visitExpression(whereExpression)
169
- } : null, orderByExpression ? {
170
- "q/order-by": visitors.replaceNamesWithIdsVisitor(typeObject).visitOrderByExpression(orderByExpression)
171
- } : null);
172
- }
173
- return queryExpression;
174
- };
175
- const deleteExpressionWithNotFoundFieldsOrTypesInExpression = (schema, fromType, expression) => {
176
- if (schema.typeObjectsByName.hasOwnProperty(fromType)) {
177
- const typeObject = schema.typeObjectsByName[fromType];
178
- return visitors.deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitExpression(expression);
179
- }
180
- return null;
181
- };
182
- const resetContextExpressionIfBroken = (schema, fromType, expression, defaultExpression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression) || defaultExpression;
183
- const isUnitExpressionValid = unit => {
184
- if (unit.hasOwnProperty("expression")) {
185
- const {
186
- expression
187
- } = unit;
188
- return expression !== null;
189
- }
190
- return true;
191
- };
192
-
193
- const visitQueryExpressionHolder = (queryHolder, visitor) => {
194
- if (queryHolder) {
195
- const {
196
- query
197
- } = queryHolder;
198
- if (query) {
199
- const queryNew = visitor.visitQueryExpression(query);
200
- return queryNew ? _extends({}, queryHolder, {
201
- query: queryNew
202
- }) : null;
203
- }
204
- return queryHolder;
205
- }
206
- return queryHolder;
207
- };
208
- const visitAxisUnits = (axis, fromType, visitor) => {
209
- return fromType ? immutableUpdate__default["default"](axis, {
210
- contextExpression: {
211
- $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
212
- },
213
- units: {
214
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
215
- }
216
- }) : axis;
217
- };
218
- const visitAxis$1 = (axis, visitor) => {
219
- if (axis && axis.hasOwnProperty("query")) {
220
- const fromType = ___default["default"].get(axis, ["query", "q/from"]);
221
- const axisWithVisitedQuery = visitQueryExpressionHolder(axis, visitor);
222
- if (axisWithVisitedQuery) {
223
- return visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
224
- }
225
- return axisWithVisitedQuery;
226
- }
227
- if (axis && axis.hasOwnProperty("enums")) {
228
- const axisNew = immutableUpdate__default["default"](axis, {
229
- enums: {
230
- $apply: enums => visitor.visitEnums(enums)
231
- }
232
- });
233
- const {
234
- enums
235
- } = axisNew;
236
- return enums ? axisNew : null;
237
- }
238
- return axis;
239
- };
240
- const isAxisFieldExpression = expression => utils.isFieldExpression(expression) && expression.length === 1;
241
- const ensureAxisAndItemExpressionInvariant$1 = view => {
242
- const actions = [];
243
- const x = ___default["default"].get(view, ["fibery/meta", "x"]);
244
- const y = ___default["default"].get(view, ["fibery/meta", "y"]);
245
- const items = ___default["default"].get(view, ["fibery/meta", "items"]);
246
- if (x === null) {
247
- const resetActions = items.map(item => () => item.xExpression = null);
248
- actions.push(...resetActions);
249
- }
250
- if (x !== null && ___default["default"].some(items, ({
251
- xExpression
252
- }) => xExpression === null)) {
253
- const resetActions = items.map(item => () => item.xExpression = null);
254
- actions.push(...resetActions);
255
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "x"], null));
256
- }
257
- if (y === null) {
258
- const resetActions = items.map(item => () => item.yExpression = null);
259
- actions.push(...resetActions);
260
- }
261
- if (y !== null && ___default["default"].some(items, ({
262
- yExpression
263
- }) => yExpression === null)) {
264
- const resetActions = items.map(item => () => item.yExpression = null);
265
- actions.push(...resetActions);
266
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
267
- }
268
- if (x !== null && ___default["default"].isEmpty(items)) {
269
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "x"], null));
270
- }
271
- if (y !== null && ___default["default"].isEmpty(items)) {
272
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
273
- }
274
- if (x !== null && ___default["default"].some(items, ({
275
- xExpression
276
- }) => !isAxisFieldExpression(xExpression))) {
277
- const resetActions = items.map(item => () => item.xExpression = null);
278
- actions.push(...resetActions);
279
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "x"], null));
280
- }
281
- if (y !== null && ___default["default"].some(items, ({
282
- yExpression
283
- }) => !isAxisFieldExpression(yExpression))) {
284
- const resetActions = items.map(item => () => item.yExpression = null);
285
- actions.push(...resetActions);
286
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
287
- }
288
- actions.forEach(action => action());
289
- return view;
290
- };
291
- const visitView$5 = (view, visitor) => immutableUpdate__default["default"](view, {
292
- "fibery/meta": {
293
- x: {
294
- $apply: x => visitAxis$1(x, visitor)
295
- },
296
- y: {
297
- $apply: y => visitAxis$1(y, visitor)
298
- },
299
- items: {
300
- $apply: items => items.map(item => {
301
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
302
- return fromType ? immutableUpdate__default["default"](item, {
303
- coverExpression: {
304
- $apply: coverExpression => coverExpression ? visitor.visitExpression(fromType, coverExpression) : coverExpression
305
- },
306
- xExpression: {
307
- $apply: xExpression => xExpression ? visitor.visitExpression(fromType, xExpression) : xExpression
308
- },
309
- yExpression: {
310
- $apply: yExpression => yExpression ? visitor.visitExpression(fromType, yExpression) : yExpression
311
- },
312
- contextExpression: {
313
- $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
314
- },
315
- query: {
316
- $apply: query => query ? visitor.visitQueryExpression(query) : null
317
- },
318
- units: {
319
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
320
- },
321
- colorCoding: {
322
- $apply: colorCodings => {
323
- return colorCodings ? colorCodings.map(colorCoding => _extends({}, colorCoding, {
324
- expression: visitor.visitExpression(fromType, colorCoding.expression)
325
- })).filter(colorCoding => colorCoding.expression !== null) : undefined;
326
- }
327
- }
328
- }) : item;
329
- }).filter(item => {
330
- const {
331
- query
332
- } = item;
333
- return query ? item : null;
334
- })
335
- }
336
- }
337
- });
338
- const replaceNamesWithIdsViewVisitor = schema => {
339
- const visitor = {
340
- visitQueryExpression: queryExpression => replaceNamesWithIdsInQueryExpression(schema, queryExpression),
341
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
342
- visitEnums: enums => ___default["default"].entries(enums).reduce((result, [type, queryHolder]) => {
343
- if (schema.typeObjectsByName.hasOwnProperty(type)) {
344
- const typeObject = schema.typeObjectsByName[type];
345
- const fromType = ___default["default"].get(queryHolder, ["query", "q/from"]);
346
- const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
347
- result[typeObject.id] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
348
- } else {
349
- result[type] = queryHolder;
350
- }
351
- return result;
352
- }, {})
353
- };
354
- return visitor;
355
- };
356
- const replaceIdsWithNamesViewVisitor = schema => {
357
- const visitor = {
358
- visitQueryExpression: queryExpression => replaceIdsWithNamesInQueryExpression(schema, queryExpression),
359
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
360
- visitEnums: enums => ___default["default"].entries(enums).reduce((result, [typeId, queryHolder]) => {
361
- if (schema.typeObjectsById.hasOwnProperty(typeId)) {
362
- const typeObject = schema.typeObjectsById[typeId];
363
- const fromType = ___default["default"].get(queryHolder, ["query", "q/from"]);
364
- const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
365
- result[typeObject.name] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
366
- } else {
367
- result[typeId] = queryHolder;
368
- }
369
- return result;
370
- }, {})
371
- };
372
- return visitor;
373
- };
374
- const deleteExpressionWithNotFoundFieldsOrTypesViewVisitor = schema => {
375
- const visitor = {
376
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
377
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression),
378
- visitEnums: enums => {
379
- const enumsNew = ___default["default"].entries(enums).reduce((result, [type, queryHolder]) => {
380
- if (schema.typeObjectsByName.hasOwnProperty(type)) {
381
- const typeObject = schema.typeObjectsByName[type];
382
- const queryHolderResult = visitQueryExpressionHolder(queryHolder, visitor);
383
- if (queryHolderResult) {
384
- result[typeObject.name] = queryHolderResult;
385
- }
386
- return result;
387
- }
388
- return result;
389
- }, {});
390
- return ___default["default"].isEmpty(enumsNew) ? null : enumsNew;
391
- }
392
- };
393
- return visitor;
394
- };
395
- const fixUserSelectedUnitsViewVisitor = schema => {
396
- return {
397
- visitQueryExpression: queryExpression => queryExpression,
398
- visitExpression: (fromType, expression) => expression,
399
- visitEnums: enums => enums,
400
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
401
- };
402
- };
403
- const replaceIdsWithNamesInBoardView = (schema, view) => visitView$5(view, replaceIdsWithNamesViewVisitor(schema));
404
- const replaceNamesWithIdsInBoardView = (schema, view) => visitView$5(view, replaceNamesWithIdsViewVisitor(schema));
405
- const deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView = (schema, view, ensureAxisInvariant = true) => {
406
- const viewNew = visitView$5(view, deleteExpressionWithNotFoundFieldsOrTypesViewVisitor(schema));
407
- return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant$1(viewNew) : viewNew;
408
- };
409
- const fixUserSelectedUnitsInBoardView = (schema, view) => {
410
- return visitView$5(view, fixUserSelectedUnitsViewVisitor(schema));
411
- };
412
- const fixContextExpressionWithBrokenPath$7 = (schema, view, defaultContextExpression) => visitView$5(view, {
413
- visitQueryExpression: query => query,
414
- visitExpression: (fromType, expression) => expression,
415
- visitEnums: enums => enums,
416
- visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
417
- });
418
- const collectGarbage$7 = view => {
419
- return visitView$5(view, {
420
- visitQueryExpression: queryExpression => queryExpression,
421
- visitExpression: (fromType, expression) => expression,
422
- visitEnums: enums => enums,
423
- visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
424
- });
425
- };
426
-
427
- const visitView$4 = (view, visitor) => immutableUpdate__default["default"](view, {
428
- "fibery/meta": {
429
- items: {
430
- $apply: items => items.map(item => {
431
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
432
- return fromType ? immutableUpdate__default["default"](item, {
433
- startExpression: {
434
- $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
435
- },
436
- endExpression: {
437
- $apply: endExpression => endExpression ? visitor.visitExpression(fromType, endExpression) : endExpression
438
- },
439
- contextExpression: {
440
- $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
441
- },
442
- query: {
443
- $apply: query => query ? visitor.visitQueryExpression(query) : null
444
- },
445
- units: {
446
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
447
- },
448
- colorCoding: {
449
- $apply: colorCodings => {
450
- return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
451
- expression: visitor.visitExpression(fromType, colorCoding.expression)
452
- })).filter(colorCoding => colorCoding.expression !== null);
453
- }
454
- }
455
- }) : item;
456
- }).filter(item => {
457
- const {
458
- query
459
- } = item;
460
- return query ? item : null;
461
- })
462
- }
463
- }
464
- });
465
- const replaceNamesWithIdsInCalendarView = (schema, view) => {
466
- return visitView$4(view, {
467
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
468
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query)
469
- });
470
- };
471
- const replaceIdsWithNamesInCalendarView = (schema, view) => {
472
- return visitView$4(view, {
473
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
474
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query)
475
- });
476
- };
477
- const deleteExpressionWithNotFoundFieldsOrTypesInCalendarView = (schema, view) => visitView$4(view, {
478
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
479
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
480
- });
481
- const fixUserSelectedUnitsInCalendarView = (schema, view) => {
482
- return visitView$4(view, {
483
- visitExpression: (fromType, expression) => expression,
484
- visitQueryExpression: query => query,
485
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
486
- });
487
- };
488
- const fixContextExpressionWithBrokenPath$6 = (schema, view, defaultContextExpression) => visitView$4(view, {
489
- visitQueryExpression: query => query,
490
- visitExpression: (fromType, expression) => expression,
491
- visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
492
- });
493
- const collectGarbage$6 = view => {
494
- return visitView$4(view, {
495
- visitExpression: (fromType, expression) => expression,
496
- visitQueryExpression: query => query,
497
- visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
498
- });
499
- };
500
-
501
- const visitView$3 = (view, visitor) => immutableUpdate__default["default"](view, {
502
- "fibery/meta": {
503
- items: {
504
- $apply: items => items.map(item => {
505
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
506
- return fromType ? immutableUpdate__default["default"](item, {
507
- postExpression: {
508
- $apply: postExpression => postExpression ? visitor.visitExpression(fromType, postExpression) : postExpression
509
- },
510
- contextExpression: {
511
- $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
512
- },
513
- query: {
514
- $apply: query => query ? visitor.visitQueryExpression(query) : null
515
- },
516
- units: {
517
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
518
- },
519
- colorCoding: {
520
- $apply: colorCodings => {
521
- return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
522
- expression: visitor.visitExpression(fromType, colorCoding.expression)
523
- })).filter(colorCoding => colorCoding.expression !== null);
524
- }
525
- }
526
- }) : item;
527
- }).filter(item => {
528
- const {
529
- query
530
- } = item;
531
- return query ? item : null;
532
- })
533
- }
534
- }
535
- });
536
- const replaceNamesWithIdsInFeedView = (schema, view) => {
537
- return visitView$3(view, {
538
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
539
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query)
540
- });
541
- };
542
- const replaceIdsWithNamesInFeedView = (schema, view) => {
543
- return visitView$3(view, {
544
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
545
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query)
546
- });
547
- };
548
- const deleteExpressionWithNotFoundFieldsOrTypesInFeedView = (schema, view) => visitView$3(view, {
549
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
550
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
551
- });
552
- const fixUserSelectedUnitsInFeedView = (schema, view) => {
553
- return visitView$3(view, {
554
- visitExpression: (fromType, expression) => expression,
555
- visitQueryExpression: query => query,
556
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
557
- });
558
- };
559
- const fixContextExpressionWithBrokenPath$5 = (schema, view, defaultContextExpression) => visitView$3(view, {
560
- visitQueryExpression: query => query,
561
- visitExpression: (fromType, expression) => expression,
562
- visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
563
- });
564
- const collectGarbage$5 = view => {
565
- return visitView$3(view, {
566
- visitExpression: (fromType, expression) => expression,
567
- visitQueryExpression: query => query,
568
- visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
569
- });
570
- };
571
-
572
- const replaceNamesWithIdsInFormView = (schema, view) => {
573
- var _view$fiberyMeta, _view$fiberyMeta2;
574
- const typeId = (_view$fiberyMeta = view["fibery/meta"]) == null ? void 0 : _view$fiberyMeta.typeId;
575
- const typeObject = schema.typeObjectsByName.hasOwnProperty(typeId) ? schema.typeObjectsByName[typeId] : null;
576
- const fields = (_view$fiberyMeta2 = view["fibery/meta"]) == null ? void 0 : _view$fiberyMeta2.fields;
577
- const fieldsInIdsTerms = fields && fields.map(field => {
578
- if (!(typeObject != null && typeObject.fieldObjectsByName.hasOwnProperty(field.id))) {
579
- return field;
580
- }
581
- return _extends({}, field, {
582
- id: typeObject.fieldObjectsByName[field.id].id
583
- });
584
- });
585
- return _extends({}, view, {
586
- "fibery/meta": _extends({}, view["fibery/meta"], {
587
- typeId: typeObject ? typeObject.id : typeId,
588
- fields: fieldsInIdsTerms || fields
589
- })
590
- });
591
- };
592
- const replaceIdsWithNamesInFormView = (schema, view) => {
593
- var _view$fiberyMeta3, _view$fiberyMeta4;
594
- const typeId = (_view$fiberyMeta3 = view["fibery/meta"]) == null ? void 0 : _view$fiberyMeta3.typeId;
595
- const typeObject = schema.typeObjectsById.hasOwnProperty(typeId) ? schema.typeObjectsById[typeId] : null;
596
- const fields = (_view$fiberyMeta4 = view["fibery/meta"]) == null ? void 0 : _view$fiberyMeta4.fields;
597
- const fieldsInNameTerms = fields && fields.map(field => {
598
- if (!(typeObject != null && typeObject.fieldObjectsById.hasOwnProperty(field.id))) {
599
- return field;
600
- }
601
- return _extends({}, field, {
602
- id: typeObject.fieldObjectsById[field.id].name
603
- });
604
- });
605
- return _extends({}, view, {
606
- "fibery/meta": _extends({}, view["fibery/meta"], {
607
- typeId: typeObject ? typeObject.name : typeId,
608
- fields: fieldsInNameTerms || fields
609
- })
610
- });
611
- };
612
- const deleteExpressionWithNotFoundFieldsOrTypesInFormView = (schema, view) => {
613
- var _view$fiberyMeta5, _view$fiberyMeta6;
614
- // we expect view in names terms here.
615
- const typeName = (_view$fiberyMeta5 = view["fibery/meta"]) == null ? void 0 : _view$fiberyMeta5.typeId;
616
- const typeObject = schema.typeObjectsByName.hasOwnProperty(typeName) ? schema.typeObjectsByName[typeName] : null;
617
- const fields = (_view$fiberyMeta6 = view["fibery/meta"]) == null ? void 0 : _view$fiberyMeta6.fields;
618
- const existingFields = fields && fields.filter(field => typeObject == null ? void 0 : typeObject.fieldObjectsByName.hasOwnProperty(field.id));
619
- return _extends({}, view, {
620
- "fibery/meta": _extends({}, view["fibery/meta"], {
621
- typeId: typeObject ? typeObject.name : typeName,
622
- fields: existingFields || fields
623
- })
624
- });
625
- };
626
-
627
- const visitView$2 = (view, visitor) => immutableUpdate__default["default"](view, {
628
- "fibery/meta": {
629
- items: {
630
- $apply: items => items.map(item => {
631
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
632
- return fromType ? immutableUpdate__default["default"](item, {
633
- locationExpression: {
634
- $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
635
- },
636
- contextExpression: {
637
- $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
638
- },
639
- query: {
640
- $apply: query => query ? visitor.visitQueryExpression(query) : null
641
- },
642
- units: {
643
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
644
- },
645
- colorCoding: {
646
- $apply: colorCodings => {
647
- return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
648
- expression: visitor.visitExpression(fromType, colorCoding.expression)
649
- })).filter(colorCoding => colorCoding.expression !== null);
650
- }
651
- }
652
- }) : item;
653
- }).filter(item => {
654
- const {
655
- query
656
- } = item;
657
- return query ? item : null;
658
- })
659
- }
660
- }
661
- });
662
- const replaceNamesWithIdsInMapView = (schema, view) => {
663
- return visitView$2(view, {
664
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
665
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression)
666
- });
667
- };
668
- const replaceIdsWithNamesInMapView = (schema, view) => {
669
- return visitView$2(view, {
670
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
671
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression)
672
- });
673
- };
674
- const deleteExpressionWithNotFoundFieldsOrTypesInMapView = (schema, view) => visitView$2(view, {
675
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
676
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
677
- });
678
- const fixUserSelectedUnitsInMapView = (schema, view) => {
679
- return visitView$2(view, {
680
- visitQueryExpression: query => query,
681
- visitExpression: (fromType, expression) => expression,
682
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
683
- });
684
- };
685
- const fixContextExpressionWithBrokenPath$4 = (schema, view, defaultContextExpression) => visitView$2(view, {
686
- visitExpression: (fromType, expression) => expression,
687
- visitQueryExpression: query => query,
688
- visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
689
- });
690
- const collectGarbage$4 = view => {
691
- return visitView$2(view, {
692
- visitQueryExpression: query => query,
693
- visitExpression: (fromType, expression) => expression,
694
- visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
695
- });
696
- };
697
-
698
- const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["default"](smartFolder, {
699
- "fibery/meta": {
700
- items: {
701
- $apply: (items = []) => {
702
- const isOldSmartFolder = !items.every(item => item.hasOwnProperty("groupBy"));
703
- const removedItemsIndexes = items.map((item, index) => visitor.visitQueryExpression(item.query) ? null : index).filter(value => value !== null);
704
- return items.map((item, index) => {
705
- if (isOldSmartFolder) {
706
- return item;
707
- }
708
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
709
- return fromType ? immutableUpdate__default["default"](item, {
710
- groupBy: {
711
- $apply: groupBy => {
712
- const removedItemsBeforeCurrent = removedItemsIndexes.filter(n => n < index);
713
- return groupBy ? visitor.visitGroupByExpression(groupBy, fromType, removedItemsBeforeCurrent.length) : null;
714
- }
715
- }
716
- }) : item;
717
- }).map(item => {
718
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
719
- return fromType ? immutableUpdate__default["default"](item, {
720
- query: {
721
- $apply: query => {
722
- const visitedQuery = visitor.visitQueryExpression(query);
723
- return query ? visitedQuery : null;
724
- }
725
- },
726
- units: {
727
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
728
- },
729
- contextExpression: {
730
- $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
731
- },
732
- colorCoding: {
733
- $apply: colorCodings => {
734
- return colorCodings ? colorCodings.map(colorCoding => _extends({}, colorCoding, {
735
- expression: visitor.visitExpression(fromType, colorCoding.expression)
736
- })).filter(colorCoding => colorCoding.expression !== null) : undefined;
737
- }
738
- }
739
- }) : item;
740
- }).filter(item => {
741
- const {
742
- query
743
- } = item;
744
- return query ? item : null;
745
- });
746
- }
747
- }
748
- }
749
- });
750
- const deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression = (schema, groupByExpression, fromType, removedItems) => {
751
- if (!groupByExpression) {
752
- return null;
753
- }
754
- const [[index, {
755
- expression
756
- }]] = Object.entries(groupByExpression);
757
- const visitedExpression = deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression);
758
- if (visitedExpression) {
759
- return {
760
- [`${parseInt(index) - removedItems}`]: {
761
- expression: visitedExpression
762
- }
763
- };
764
- }
765
- return null;
766
- };
767
- const replaceIdsWithNamesInGroupByExpression = (schema, groupByExpression, fromType) => {
768
- if (!groupByExpression) {
769
- return null;
770
- }
771
- const [[index, {
772
- expression
773
- }]] = Object.entries(groupByExpression);
774
- if (schema.typeObjectsById.hasOwnProperty(fromType)) {
775
- const typeObject = schema.typeObjectsById[fromType];
776
- return {
777
- [index]: {
778
- expression: visitors.replaceIdsWithNamesVisitor(typeObject).visitExpression(expression)
779
- }
780
- };
781
- }
782
- return groupByExpression;
783
- };
784
- const replaceNamesWithIdsInGroupByExpression = (schema, groupByExpression, fromType) => {
785
- if (!groupByExpression) {
786
- return null;
787
- }
788
- const [[index, {
789
- expression
790
- }]] = Object.entries(groupByExpression);
791
- if (schema.typeObjectsByName.hasOwnProperty(fromType)) {
792
- const typeObject = schema.typeObjectsByName[fromType];
793
- return {
794
- [index]: {
795
- expression: visitors.replaceNamesWithIdsVisitor(typeObject).visitExpression(expression)
796
- }
797
- };
798
- }
799
- return groupByExpression;
800
- };
801
- const replaceNamesWithIdsInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
802
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
803
- visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType),
804
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression)
805
- });
806
- const replaceIdsWithNamesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
807
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
808
- visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType),
809
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression)
810
- });
811
- const deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
812
- visitQueryExpression: query => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, query),
813
- visitGroupByExpression: (groupBy, fromType, removedItems) => deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression(schema, groupBy, fromType, removedItems),
814
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
815
- });
816
- const fixContextExpressionWithBrokenPath$3 = (schema, view, defaultContextExpression) => visitSmartFolder(view, {
817
- visitQueryExpression: query => query,
818
- visitGroupByExpression: groupBy => groupBy,
819
- visitExpression: (fromType, expression) => expression,
820
- visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
821
- });
822
- const fixUserSelectedUnitsInSmartFolder = (schema, view) => {
823
- return visitSmartFolder(view, {
824
- visitQueryExpression: query => query,
825
- visitGroupByExpression: groupBy => groupBy,
826
- visitExpression: (fromType, expression) => expression,
827
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
828
- });
829
- };
830
- const collectGarbage$3 = view => {
831
- return visitSmartFolder(view, {
832
- visitQueryExpression: query => query,
833
- visitGroupByExpression: groupBy => groupBy,
834
- visitExpression: (fromType, expression) => expression,
835
- visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
836
- });
837
- };
838
-
839
- const visitView$1 = (view, visitor) => immutableUpdate__default["default"](view, {
840
- "fibery/meta": {
841
- items: {
842
- $apply: items => items.map(item => {
843
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
844
- return fromType ? immutableUpdate__default["default"](item, {
845
- query: {
846
- $apply: query => query ? visitor.visitQueryExpression(query) : null
847
- },
848
- contextExpression: {
849
- $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
850
- },
851
- units: {
852
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
853
- },
854
- colorCoding: {
855
- $apply: colorCodings => {
856
- return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
857
- expression: visitor.visitExpression(fromType, colorCoding.expression)
858
- })).filter(colorCoding => colorCoding.expression !== null);
859
- }
860
- }
861
- }) : item;
862
- }).filter(item => {
863
- const {
864
- query
865
- } = item;
866
- return query ? item : null;
867
- })
868
- }
869
- }
870
- });
871
- const replaceNamesWithIdsInTableView = (schema, view) => visitView$1(view, {
872
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
873
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query)
874
- });
875
- const replaceIdsWithNamesInTableView = (schema, view) => visitView$1(view, {
876
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
877
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query)
878
- });
879
- const deleteExpressionWithNotFoundFieldsOrTypesInTableView = (schema, view) => visitView$1(view, {
880
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
881
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
882
- });
883
- const fixUserSelectedUnitsInTableView = (schema, view) => visitView$1(view, {
884
- visitExpression: (fromType, expression) => expression,
885
- visitQueryExpression: query => query,
886
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
887
- });
888
- const fixContextExpressionWithBrokenPath$2 = (schema, view, defaultContextExpression) => visitView$1(view, {
889
- visitExpression: (fromType, expression) => expression,
890
- visitQueryExpression: query => query,
891
- visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
892
- });
893
- const collectGarbage$2 = view => {
894
- return visitView$1(view, {
895
- visitExpression: (fromType, expression) => expression,
896
- visitQueryExpression: query => query,
897
- visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
898
- });
899
- };
900
-
901
- const visitAxis = (axis, visitor) => {
902
- if (!axis) {
903
- return axis;
904
- }
905
- const fromType = ___default["default"].get(axis, ["query", "q/from"]);
906
- const firstOrNull = x => ___default["default"].first(x) || null;
907
- const axisResult = _extends({}, axis, {
908
- query: axis.query && visitor.visitQueryExpression(axis.query),
909
- contextExpression: visitContextExpression(fromType, axis.contextExpression, visitor),
910
- units: axis.units && axis.units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)),
911
- groupByExpression: axis.groupByExpression && firstOrNull(visitor.visitExpression(fromType, [axis.groupByExpression]))
912
- });
913
- if (!axisResult.query) {
914
- return null;
915
- }
916
- if (!axisResult.units) {
917
- delete axisResult.units;
918
- }
919
- return axisResult;
920
- };
921
- const visitView = (view, visitor) => immutableUpdate__default["default"](view, {
922
- "fibery/meta": {
923
- y: {
924
- $apply: y => visitAxis(y, visitor)
925
- },
926
- items: {
927
- $apply: items => items.map(item => {
928
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
929
- return fromType ? immutableUpdate__default["default"](item, {
930
- yExpression: {
931
- $apply: yExpression => yExpression ? visitor.visitExpression(fromType, yExpression) : yExpression
932
- },
933
- startExpression: {
934
- $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
935
- },
936
- endExpression: {
937
- $apply: endExpression => endExpression ? visitor.visitExpression(fromType, endExpression) : endExpression
938
- },
939
- contextExpression: {
940
- $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
941
- },
942
- query: {
943
- $apply: query => query ? visitor.visitQueryExpression(query) : null
944
- },
945
- units: {
946
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
947
- },
948
- colorCoding: {
949
- $apply: colorCodings => {
950
- return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
951
- expression: visitor.visitExpression(fromType, colorCoding.expression)
952
- })).filter(colorCoding => colorCoding.expression !== null);
953
- }
954
- }
955
- }) : item;
956
- }).filter(item => {
957
- const {
958
- query
959
- } = item;
960
- return query ? item : null;
961
- })
962
- },
963
- milestones: {
964
- $apply: milestones => {
965
- if (!milestones) {
966
- return milestones;
967
- }
968
- return milestones.map(item => {
969
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
970
- return fromType ? immutableUpdate__default["default"](item, {
971
- dateExpression: {
972
- $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
973
- },
974
- query: {
975
- $apply: query => query ? visitor.visitQueryExpression(query) : null
976
- },
977
- contextExpression: {
978
- $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
979
- }
980
- }) : item;
981
- }).filter(item => {
982
- const {
983
- query
984
- } = item;
985
- return query ? item : null;
986
- });
987
- }
988
- }
989
- }
990
- });
991
- const replaceNamesWithIdsInTimelineView = (schema, view) => {
992
- return visitView(view, {
993
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
994
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression)
995
- });
996
- };
997
- const replaceIdsWithNamesInTimelineView = (schema, view) => {
998
- return visitView(view, {
999
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
1000
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression)
1001
- });
1002
- };
1003
- const ensureAxisAndItemExpressionInvariant = view => {
1004
- const actions = [];
1005
- const y = ___default["default"].get(view, ["fibery/meta", "y"]);
1006
- const yQuery = ___default["default"].get(view, ["fibery/meta", "y", "query"]);
1007
- const yGroupByExpression = ___default["default"].get(view, ["fibery/meta", "y", "groupByExpression"]);
1008
- const items = ___default["default"].get(view, ["fibery/meta", "items"]);
1009
- if (yQuery === null && yGroupByExpression !== null) {
1010
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y", "groupByExpression"], null));
1011
- }
1012
- if (y === null) {
1013
- const resetActions = items.map(item => () => item.yExpression = null);
1014
- actions.push(...resetActions);
1015
- }
1016
- if (y !== null && ___default["default"].some(items, ({
1017
- yExpression
1018
- }) => yExpression === null)) {
1019
- const resetActions = items.map(item => () => item.yExpression = null);
1020
- actions.push(...resetActions);
1021
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
1022
- }
1023
- if (y !== null && ___default["default"].isEmpty(items)) {
1024
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
1025
- }
1026
- actions.forEach(action => action());
1027
- return view;
1028
- };
1029
- const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, ensureAxisInvariant = true) => {
1030
- const viewNew = visitView(view, {
1031
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
1032
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
1033
- });
1034
- return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant(viewNew) : viewNew;
1035
- };
1036
- const fixUserSelectedUnitsInTimelineView = (schema, view) => {
1037
- return visitView(view, {
1038
- visitQueryExpression: query => query,
1039
- visitExpression: (fromType, expression) => expression,
1040
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
1041
- });
1042
- };
1043
- const fixContextExpressionWithBrokenPath$1 = (schema, view, defaultContextExpression) => visitView(view, {
1044
- visitExpression: (fromType, expression) => expression,
1045
- visitQueryExpression: query => query,
1046
- visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
1047
- });
1048
- const collectGarbage$1 = view => {
1049
- return visitView(view, {
1050
- visitQueryExpression: query => query,
1051
- visitExpression: (fromType, expression) => expression,
1052
- visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
1053
- });
1054
- };
1055
-
1056
- const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view, ensureAxisInvariant = true) => {
1057
- switch (view["fibery/type"]) {
1058
- case "board":
1059
- return deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView(schema, view, ensureAxisInvariant);
1060
- case "list":
1061
- return deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder(schema, view);
1062
- case "grid":
1063
- return deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder(schema, view);
1064
- case "timeline":
1065
- return deleteExpressionWithNotFoundFieldsOrTypesInTimelineView(schema, view, ensureAxisInvariant);
1066
- case "calendar":
1067
- return deleteExpressionWithNotFoundFieldsOrTypesInCalendarView(schema, view);
1068
- case "table":
1069
- return deleteExpressionWithNotFoundFieldsOrTypesInTableView(schema, view);
1070
- case "feed":
1071
- return deleteExpressionWithNotFoundFieldsOrTypesInFeedView(schema, view);
1072
- case "form":
1073
- return deleteExpressionWithNotFoundFieldsOrTypesInFormView(schema, view);
1074
- case "map":
1075
- return deleteExpressionWithNotFoundFieldsOrTypesInMapView(schema, view);
1076
- default:
1077
- return view;
1078
- }
1079
- };
1080
- const fixUserSelectedUnits = (schema, view) => {
1081
- switch (view["fibery/type"]) {
1082
- case "board":
1083
- return fixUserSelectedUnitsInBoardView(schema, view);
1084
- case "list":
1085
- return fixUserSelectedUnitsInSmartFolder(schema, view);
1086
- case "grid":
1087
- return fixUserSelectedUnitsInSmartFolder(schema, view);
1088
- case "table":
1089
- return fixUserSelectedUnitsInTableView(schema, view);
1090
- case "timeline":
1091
- return fixUserSelectedUnitsInTimelineView(schema, view);
1092
- case "calendar":
1093
- return fixUserSelectedUnitsInCalendarView(schema, view);
1094
- case "feed":
1095
- return fixUserSelectedUnitsInFeedView(schema, view);
1096
- case "map":
1097
- return fixUserSelectedUnitsInMapView(schema, view);
1098
- default:
1099
- return view;
1100
- }
1101
- };
1102
- const fixContextExpressionWithBrokenPath = (schema, view, defaultContextExpression) => {
1103
- switch (view["fibery/type"]) {
1104
- case "board":
1105
- return fixContextExpressionWithBrokenPath$7(schema, view, defaultContextExpression);
1106
- case "list":
1107
- return fixContextExpressionWithBrokenPath$3(schema, view, defaultContextExpression);
1108
- case "grid":
1109
- return fixContextExpressionWithBrokenPath$3(schema, view, defaultContextExpression);
1110
- case "table":
1111
- return fixContextExpressionWithBrokenPath$2(schema, view, defaultContextExpression);
1112
- case "timeline":
1113
- return fixContextExpressionWithBrokenPath$1(schema, view, defaultContextExpression);
1114
- case "calendar":
1115
- return fixContextExpressionWithBrokenPath$6(schema, view, defaultContextExpression);
1116
- case "feed":
1117
- return fixContextExpressionWithBrokenPath$5(schema, view, defaultContextExpression);
1118
- case "map":
1119
- return fixContextExpressionWithBrokenPath$4(schema, view, defaultContextExpression);
1120
- default:
1121
- return view;
1122
- }
1123
- };
1124
-
1125
- /**
1126
- * Removes garbage from view's meta to reduce the size.
1127
- */
1128
- const collectGarbage = (schema, view) => {
1129
- const deleteRemoved = x => {
1130
- if (Array.isArray(x)) {
1131
- return x.map(deleteRemoved).filter(y => y !== REMOVE);
1132
- }
1133
- if (typeof x === "object" && x !== null) {
1134
- let tmp = Object.entries(x);
1135
- tmp = tmp.map(e => [e[0], deleteRemoved(e[1])]);
1136
- tmp = tmp.filter(e => e[1] !== REMOVE);
1137
- return Object.fromEntries(tmp);
1138
- }
1139
- return x;
1140
- };
1141
- switch (view["fibery/type"]) {
1142
- case "board":
1143
- return deleteRemoved(collectGarbage$7(view));
1144
- case "list":
1145
- return deleteRemoved(collectGarbage$3(view));
1146
- case "grid":
1147
- return deleteRemoved(collectGarbage$3(view));
1148
- case "table":
1149
- return deleteRemoved(collectGarbage$2(view));
1150
- case "timeline":
1151
- return deleteRemoved(collectGarbage$1(view));
1152
- case "calendar":
1153
- return deleteRemoved(collectGarbage$6(view));
1154
- case "feed":
1155
- return deleteRemoved(collectGarbage$5(view));
1156
- case "map":
1157
- return deleteRemoved(collectGarbage$4(view));
1158
- default:
1159
- return view;
1160
- }
1161
- };
1162
- const replaceNamesWithIdsInView = (schema, view) => {
1163
- switch (view["fibery/type"]) {
1164
- case "board":
1165
- return replaceNamesWithIdsInBoardView(schema, view);
1166
- case "list":
1167
- return replaceNamesWithIdsInSmartFolder(schema, view);
1168
- case "grid":
1169
- return replaceNamesWithIdsInSmartFolder(schema, view);
1170
- case "table":
1171
- return replaceNamesWithIdsInTableView(schema, view);
1172
- case "timeline":
1173
- return replaceNamesWithIdsInTimelineView(schema, view);
1174
- case "calendar":
1175
- return replaceNamesWithIdsInCalendarView(schema, view);
1176
- case "feed":
1177
- return replaceNamesWithIdsInFeedView(schema, view);
1178
- case "form":
1179
- return replaceNamesWithIdsInFormView(schema, view);
1180
- case "map":
1181
- return replaceNamesWithIdsInMapView(schema, view);
1182
- default:
1183
- return view;
1184
- }
1185
- };
1186
- const replaceIdsWithNamesInView = (schema, view) => {
1187
- switch (view["fibery/type"]) {
1188
- case "board":
1189
- return replaceIdsWithNamesInBoardView(schema, view);
1190
- case "list":
1191
- return replaceIdsWithNamesInSmartFolder(schema, view);
1192
- case "grid":
1193
- return replaceIdsWithNamesInSmartFolder(schema, view);
1194
- case "table":
1195
- return replaceIdsWithNamesInTableView(schema, view);
1196
- case "timeline":
1197
- return replaceIdsWithNamesInTimelineView(schema, view);
1198
- case "calendar":
1199
- return replaceIdsWithNamesInCalendarView(schema, view);
1200
- case "feed":
1201
- return replaceIdsWithNamesInFeedView(schema, view);
1202
- case "form":
1203
- return replaceIdsWithNamesInFormView(schema, view);
1204
- case "map":
1205
- return replaceIdsWithNamesInMapView(schema, view);
1206
- default:
1207
- return view;
1208
- }
1209
- };
1210
- const getViewCardTypes = ({
1211
- "fibery/meta": {
1212
- items
1213
- }
1214
- }) => items.map(({
1215
- query: {
1216
- "q/from": type
1217
- }
1218
- }) => type);
1219
-
1220
- exports.collectGarbage = collectGarbage;
1221
- exports.deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder;
1222
- exports.deleteExpressionWithNotFoundFieldsOrTypesInView = deleteExpressionWithNotFoundFieldsOrTypesInView;
1223
- exports.fixContextExpressionWithBrokenPath = fixContextExpressionWithBrokenPath;
1224
- exports.fixUserSelectedUnits = fixUserSelectedUnits;
1225
- exports.getViewCardTypes = getViewCardTypes;
1226
- exports.replaceIdsWithNamesInSmartFolder = replaceIdsWithNamesInSmartFolder;
1227
- exports.replaceIdsWithNamesInView = replaceIdsWithNamesInView;
1228
- exports.replaceNamesWithIdsInSmartFolder = replaceNamesWithIdsInSmartFolder;
1229
- exports.replaceNamesWithIdsInView = replaceNamesWithIdsInView;