@fibery/views 1.1.12 → 1.1.13

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