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