@fibery/views 1.1.2 → 1.1.5

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 (3) hide show
  1. package/README.md +31 -0
  2. package/lib/views.js +1066 -0
  3. package/package.json +20 -7
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ ## How to update and publish @fibery/views
2
+
3
+ Execute this:
4
+
5
+ cd fibery-views
6
+ yarn build
7
+ npm version patch
8
+ npm publish --dry-run
9
+
10
+ Check the output, it should say there are at least 2 total files:
11
+
12
+ npm notice 📦 @fibery/views@1.1.4
13
+ npm notice === Tarball Contents ===
14
+ npm notice 37.1kB lib/views.js
15
+ npm notice 1.1kB package.json
16
+ npm notice === Tarball Details ===
17
+ npm notice name: @fibery/views
18
+ npm notice version: 1.1.4
19
+ npm notice package size: 4.7 kB
20
+ npm notice unpacked size: 38.3 kB
21
+ npm notice shasum: 0c8f17195d49cda1a321edc9a07d443c97ed6ba5
22
+ npm notice integrity: sha512-XpaByuvN4YSZi[...]OFceXnL4J2VHw==
23
+ npm notice total files: 2
24
+ npm notice
25
+ + @fibery/views@1.1.4
26
+
27
+ If everything looks good, do
28
+
29
+ npm publish
30
+
31
+ Don't forget to commit the updated package.json.
package/lib/views.js ADDED
@@ -0,0 +1,1066 @@
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
+ const deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression = (schema, queryExpression) => {
112
+ const {
113
+ "q/from": fromExpression,
114
+ "q/where": whereExpression,
115
+ "q/order-by": orderByExpression
116
+ } = queryExpression;
117
+
118
+ if (schema.typeObjectsByName.hasOwnProperty(fromExpression)) {
119
+ const typeObject = schema.typeObjectsByName[fromExpression];
120
+ return ___default["default"].pickBy(_extends({}, queryExpression, whereExpression ? {
121
+ "q/where": visitors.deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitExpression(whereExpression)
122
+ } : null, orderByExpression ? {
123
+ "q/order-by": visitors.deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitOrderByExpression(orderByExpression)
124
+ } : null));
125
+ }
126
+
127
+ return null;
128
+ };
129
+ const replaceNamesWithIdsInExpression = (schema, fromType, expression) => {
130
+ if (schema.typeObjectsByName.hasOwnProperty(fromType)) {
131
+ const typeObject = schema.typeObjectsByName[fromType];
132
+ return visitors.replaceNamesWithIdsVisitor(typeObject).visitExpression(expression);
133
+ }
134
+
135
+ return expression;
136
+ };
137
+ const replaceIdsWithNamesInExpression = (schema, fromTypeId, expression) => {
138
+ if (schema.typeObjectsById.hasOwnProperty(fromTypeId)) {
139
+ const typeObject = schema.typeObjectsById[fromTypeId];
140
+ return visitors.replaceIdsWithNamesVisitor(typeObject).visitExpression(expression);
141
+ }
142
+
143
+ return expression;
144
+ };
145
+ const visitViewUnit = (fromType, unit, visitor) => {
146
+ const {
147
+ expression
148
+ } = unit;
149
+
150
+ if (expression) {
151
+ return _extends({}, unit, {
152
+ expression: visitor.visitExpression(fromType, expression)
153
+ });
154
+ }
155
+
156
+ return unit;
157
+ };
158
+ const replaceIdsWithNamesInQueryExpression = (schema, queryExpression) => {
159
+ const {
160
+ "q/from": fromExpression,
161
+ "q/where": whereExpression,
162
+ "q/order-by": orderByExpression
163
+ } = queryExpression;
164
+
165
+ if (schema.typeObjectsById.hasOwnProperty(fromExpression)) {
166
+ const typeObject = schema.typeObjectsById[fromExpression];
167
+ return _extends({}, queryExpression, {
168
+ "q/from": typeObject.name
169
+ }, whereExpression ? {
170
+ "q/where": visitors.replaceIdsWithNamesVisitor(typeObject).visitExpression(whereExpression)
171
+ } : null, orderByExpression ? {
172
+ "q/order-by": visitors.replaceIdsWithNamesVisitor(typeObject).visitOrderByExpression(orderByExpression)
173
+ } : null);
174
+ }
175
+
176
+ return queryExpression;
177
+ };
178
+ const replaceNamesWithIdsInQueryExpression = (schema, queryExpression) => {
179
+ const {
180
+ "q/from": fromExpression,
181
+ "q/where": whereExpression,
182
+ "q/order-by": orderByExpression
183
+ } = queryExpression;
184
+
185
+ if (schema.typeObjectsByName.hasOwnProperty(fromExpression)) {
186
+ const typeObject = schema.typeObjectsByName[fromExpression];
187
+ return _extends({}, queryExpression, {
188
+ "q/from": typeObject.id
189
+ }, whereExpression ? {
190
+ "q/where": visitors.replaceNamesWithIdsVisitor(typeObject).visitExpression(whereExpression)
191
+ } : null, orderByExpression ? {
192
+ "q/order-by": visitors.replaceNamesWithIdsVisitor(typeObject).visitOrderByExpression(orderByExpression)
193
+ } : null);
194
+ }
195
+
196
+ return queryExpression;
197
+ };
198
+ const deleteExpressionWithNotFoundFieldsOrTypesInExpression = (schema, fromType, expression) => {
199
+ if (schema.typeObjectsByName.hasOwnProperty(fromType)) {
200
+ const typeObject = schema.typeObjectsByName[fromType];
201
+ return visitors.deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitExpression(expression);
202
+ }
203
+
204
+ return null;
205
+ };
206
+ const isUnitExpressionValid = unit => {
207
+ if (unit.hasOwnProperty("expression")) {
208
+ const {
209
+ expression
210
+ } = unit;
211
+ return expression !== null;
212
+ }
213
+
214
+ return true;
215
+ };
216
+
217
+ const visitQueryExpressionHolder = (queryHolder, visitor) => {
218
+ if (queryHolder) {
219
+ const {
220
+ query
221
+ } = queryHolder;
222
+
223
+ if (query) {
224
+ const queryNew = visitor.visitQueryExpression(query);
225
+ return queryNew ? _extends({}, queryHolder, {
226
+ query: queryNew
227
+ }) : null;
228
+ }
229
+
230
+ return queryHolder;
231
+ }
232
+
233
+ return queryHolder;
234
+ };
235
+
236
+ const visitAxisUnits = (axis, fromType, visitor) => {
237
+ return fromType ? immutableUpdate__default["default"](axis, {
238
+ contextExpression: {
239
+ $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
240
+ },
241
+ units: {
242
+ $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
243
+ }
244
+ }) : axis;
245
+ };
246
+
247
+ const visitAxis$1 = (axis, visitor) => {
248
+ if (axis && axis.hasOwnProperty("query")) {
249
+ const fromType = ___default["default"].get(axis, ["query", "q/from"]);
250
+
251
+ const axisWithVisitedQuery = visitQueryExpressionHolder(axis, visitor);
252
+
253
+ if (axisWithVisitedQuery) {
254
+ return visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
255
+ }
256
+
257
+ return axisWithVisitedQuery;
258
+ }
259
+
260
+ if (axis && axis.hasOwnProperty("enums")) {
261
+ const axisNew = immutableUpdate__default["default"](axis, {
262
+ enums: {
263
+ $apply: enums => visitor.visitEnums(enums)
264
+ }
265
+ });
266
+ const {
267
+ enums
268
+ } = axisNew;
269
+ return enums ? axisNew : null;
270
+ }
271
+
272
+ return axis;
273
+ };
274
+
275
+ const ensureAxisAndItemExpressionInvariant$1 = view => {
276
+ const actions = [];
277
+
278
+ const x = ___default["default"].get(view, ["fibery/meta", "x"]);
279
+
280
+ const y = ___default["default"].get(view, ["fibery/meta", "y"]);
281
+
282
+ const items = ___default["default"].get(view, ["fibery/meta", "items"]);
283
+
284
+ if (x === null) {
285
+ const resetActions = items.map(item => () => item.xExpression = null);
286
+ actions.push(...resetActions);
287
+ }
288
+
289
+ if (x !== null && ___default["default"].some(items, ({
290
+ xExpression
291
+ }) => xExpression === null)) {
292
+ const resetActions = items.map(item => () => item.xExpression = null);
293
+ actions.push(...resetActions);
294
+ actions.push(() => ___default["default"].set(view, ["fibery/meta", "x"], null));
295
+ }
296
+
297
+ if (y === null) {
298
+ const resetActions = items.map(item => () => item.yExpression = null);
299
+ actions.push(...resetActions);
300
+ }
301
+
302
+ if (y !== null && ___default["default"].some(items, ({
303
+ yExpression
304
+ }) => yExpression === null)) {
305
+ const resetActions = items.map(item => () => item.yExpression = null);
306
+ actions.push(...resetActions);
307
+ actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
308
+ }
309
+
310
+ if (x !== null && ___default["default"].isEmpty(items)) {
311
+ actions.push(() => ___default["default"].set(view, ["fibery/meta", "x"], null));
312
+ }
313
+
314
+ if (y !== null && ___default["default"].isEmpty(items)) {
315
+ actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
316
+ }
317
+
318
+ if (x !== null && ___default["default"].some(items, ({
319
+ xExpression
320
+ }) => !utils.isAxisFieldExpression(xExpression))) {
321
+ const resetActions = items.map(item => () => item.xExpression = null);
322
+ actions.push(...resetActions);
323
+ actions.push(() => ___default["default"].set(view, ["fibery/meta", "x"], null));
324
+ }
325
+
326
+ if (y !== null && ___default["default"].some(items, ({
327
+ yExpression
328
+ }) => !utils.isAxisFieldExpression(yExpression))) {
329
+ const resetActions = items.map(item => () => item.yExpression = null);
330
+ actions.push(...resetActions);
331
+ actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
332
+ }
333
+
334
+ actions.forEach(action => action());
335
+ return view;
336
+ };
337
+
338
+ const visitView$4 = (view, visitor) => immutableUpdate__default["default"](view, {
339
+ "fibery/meta": {
340
+ x: {
341
+ $apply: x => visitAxis$1(x, visitor)
342
+ },
343
+ y: {
344
+ $apply: y => visitAxis$1(y, visitor)
345
+ },
346
+ items: {
347
+ $apply: items => items.map(item => {
348
+ const fromType = ___default["default"].get(item, ["query", "q/from"]);
349
+
350
+ return fromType ? immutableUpdate__default["default"](item, {
351
+ xExpression: {
352
+ $apply: xExpression => xExpression ? visitor.visitExpression(fromType, xExpression) : xExpression
353
+ },
354
+ yExpression: {
355
+ $apply: yExpression => yExpression ? visitor.visitExpression(fromType, yExpression) : yExpression
356
+ },
357
+ contextExpression: {
358
+ $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
359
+ },
360
+ query: {
361
+ $apply: query => query ? visitor.visitQueryExpression(query) : null
362
+ },
363
+ units: {
364
+ $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
365
+ },
366
+ colorCoding: {
367
+ $apply: colorCodings => {
368
+ return colorCodings ? colorCodings.map(colorCoding => _extends({}, colorCoding, {
369
+ expression: visitor.visitExpression(fromType, colorCoding.expression)
370
+ })).filter(colorCoding => colorCoding.expression !== null) : undefined;
371
+ }
372
+ }
373
+ }) : item;
374
+ }).filter(item => {
375
+ const {
376
+ query
377
+ } = item;
378
+ return query ? item : null;
379
+ })
380
+ }
381
+ }
382
+ });
383
+
384
+ const replaceNamesWithIdsViewVisitor = schema => {
385
+ const visitor = {
386
+ visitQueryExpression: queryExpression => replaceNamesWithIdsInQueryExpression(schema, queryExpression),
387
+ visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
388
+ visitEnums: enums => ___default["default"].entries(enums).reduce((result, [type, queryHolder]) => {
389
+ if (schema.typeObjectsByName.hasOwnProperty(type)) {
390
+ const typeObject = schema.typeObjectsByName[type];
391
+
392
+ const fromType = ___default["default"].get(queryHolder, ["query", "q/from"]);
393
+
394
+ const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
395
+ result[typeObject.id] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
396
+ } else {
397
+ result[type] = queryHolder;
398
+ }
399
+
400
+ return result;
401
+ }, {})
402
+ };
403
+ return visitor;
404
+ };
405
+
406
+ const replaceIdsWithNamesViewVisitor = schema => {
407
+ const visitor = {
408
+ visitQueryExpression: queryExpression => replaceIdsWithNamesInQueryExpression(schema, queryExpression),
409
+ visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
410
+ visitEnums: enums => ___default["default"].entries(enums).reduce((result, [typeId, queryHolder]) => {
411
+ if (schema.typeObjectsById.hasOwnProperty(typeId)) {
412
+ const typeObject = schema.typeObjectsById[typeId];
413
+
414
+ const fromType = ___default["default"].get(queryHolder, ["query", "q/from"]);
415
+
416
+ const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
417
+ result[typeObject.name] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
418
+ } else {
419
+ result[typeId] = queryHolder;
420
+ }
421
+
422
+ return result;
423
+ }, {})
424
+ };
425
+ return visitor;
426
+ };
427
+
428
+ const deleteExpressionWithNotFoundFieldsOrTypesViewVisitor = schema => {
429
+ const visitor = {
430
+ visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
431
+ visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression),
432
+ visitEnums: enums => {
433
+ const enumsNew = ___default["default"].entries(enums).reduce((result, [type, queryHolder]) => {
434
+ if (schema.typeObjectsByName.hasOwnProperty(type)) {
435
+ const typeObject = schema.typeObjectsByName[type];
436
+ const queryHolderResult = visitQueryExpressionHolder(queryHolder, visitor);
437
+
438
+ if (queryHolderResult) {
439
+ result[typeObject.name] = queryHolderResult;
440
+ }
441
+
442
+ return result;
443
+ }
444
+
445
+ return result;
446
+ }, {});
447
+
448
+ return ___default["default"].isEmpty(enumsNew) ? null : enumsNew;
449
+ }
450
+ };
451
+ return visitor;
452
+ };
453
+
454
+ const fixUserSelectedUnitsViewVisitor = schema => {
455
+ return {
456
+ visitQueryExpression: queryExpression => queryExpression,
457
+ visitExpression: (fromType, expression) => expression,
458
+ visitEnums: enums => enums,
459
+ visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
460
+ };
461
+ };
462
+
463
+ const replaceIdsWithNamesInBoardView = (schema, view) => visitView$4(view, replaceIdsWithNamesViewVisitor(schema));
464
+ const replaceNamesWithIdsInBoardView = (schema, view) => visitView$4(view, replaceNamesWithIdsViewVisitor(schema));
465
+ const deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView = (schema, view, ensureAxisInvariant = true) => {
466
+ const viewNew = visitView$4(view, deleteExpressionWithNotFoundFieldsOrTypesViewVisitor(schema));
467
+ return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant$1(viewNew) : viewNew;
468
+ };
469
+ const fixUserSelectedUnitsInBoardView = (schema, view) => {
470
+ return visitView$4(view, fixUserSelectedUnitsViewVisitor(schema));
471
+ };
472
+
473
+ const visitView$3 = (view, visitor) => immutableUpdate__default["default"](view, {
474
+ "fibery/meta": {
475
+ items: {
476
+ $apply: items => items.map(item => {
477
+ const fromType = ___default["default"].get(item, ["query", "q/from"]);
478
+
479
+ return fromType ? immutableUpdate__default["default"](item, {
480
+ startExpression: {
481
+ $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
482
+ },
483
+ endExpression: {
484
+ $apply: endExpression => endExpression ? visitor.visitExpression(fromType, endExpression) : endExpression
485
+ },
486
+ contextExpression: {
487
+ $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
488
+ },
489
+ query: {
490
+ $apply: query => query ? visitor.visitQueryExpression(query) : null
491
+ },
492
+ units: {
493
+ $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
494
+ },
495
+ colorCoding: {
496
+ $apply: colorCodings => {
497
+ return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
498
+ expression: visitor.visitExpression(fromType, colorCoding.expression)
499
+ })).filter(colorCoding => colorCoding.expression !== null);
500
+ }
501
+ }
502
+ }) : item;
503
+ }).filter(item => {
504
+ const {
505
+ query
506
+ } = item;
507
+ return query ? item : null;
508
+ })
509
+ }
510
+ }
511
+ });
512
+
513
+ const replaceNamesWithIdsInCalendarView = (schema, view) => {
514
+ return visitView$3(view, {
515
+ visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
516
+ visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query)
517
+ });
518
+ };
519
+ const replaceIdsWithNamesInCalendarView = (schema, view) => {
520
+ return visitView$3(view, {
521
+ visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
522
+ visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query)
523
+ });
524
+ };
525
+ const deleteExpressionWithNotFoundFieldsOrTypesInCalendarView = (schema, view) => visitView$3(view, {
526
+ visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
527
+ visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
528
+ });
529
+ const fixUserSelectedUnitsInCalendarView = (schema, view) => {
530
+ return visitView$3(view, {
531
+ visitExpression: (fromType, expression) => expression,
532
+ visitQueryExpression: query => query,
533
+ visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
534
+ });
535
+ };
536
+
537
+ const visitView$2 = (view, visitor) => immutableUpdate__default["default"](view, {
538
+ "fibery/meta": {
539
+ items: {
540
+ $apply: items => items.map(item => {
541
+ const fromType = ___default["default"].get(item, ["query", "q/from"]);
542
+
543
+ return fromType ? immutableUpdate__default["default"](item, {
544
+ postExpression: {
545
+ $apply: postExpression => postExpression ? visitor.visitExpression(fromType, postExpression) : postExpression
546
+ },
547
+ contextExpression: {
548
+ $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
549
+ },
550
+ query: {
551
+ $apply: query => query ? visitor.visitQueryExpression(query) : null
552
+ },
553
+ units: {
554
+ $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
555
+ },
556
+ colorCoding: {
557
+ $apply: colorCodings => {
558
+ return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
559
+ expression: visitor.visitExpression(fromType, colorCoding.expression)
560
+ })).filter(colorCoding => colorCoding.expression !== null);
561
+ }
562
+ }
563
+ }) : item;
564
+ }).filter(item => {
565
+ const {
566
+ query
567
+ } = item;
568
+ return query ? item : null;
569
+ })
570
+ }
571
+ }
572
+ });
573
+
574
+ const replaceNamesWithIdsInFeedView = (schema, view) => {
575
+ return visitView$2(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$2(view, {
582
+ visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
583
+ visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query)
584
+ });
585
+ };
586
+ const deleteExpressionWithNotFoundFieldsOrTypesInFeedView = (schema, view) => visitView$2(view, {
587
+ visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
588
+ visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
589
+ });
590
+ const fixUserSelectedUnitsInFeedView = (schema, view) => {
591
+ return visitView$2(view, {
592
+ visitExpression: (fromType, expression) => expression,
593
+ visitQueryExpression: query => query,
594
+ visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
595
+ });
596
+ };
597
+
598
+ const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["default"](smartFolder, {
599
+ "fibery/meta": {
600
+ items: {
601
+ $apply: items => {
602
+ const isOldSmartFolder = !items.every(item => item.hasOwnProperty("groupBy"));
603
+ const removedItemsIndexes = items.map((item, index) => visitor.visitQueryExpression(item.query) ? null : index).filter(value => value !== null);
604
+ return items.map((item, index) => {
605
+ if (isOldSmartFolder) {
606
+ return item;
607
+ }
608
+
609
+ const fromType = ___default["default"].get(item, ["query", "q/from"]);
610
+
611
+ return fromType ? immutableUpdate__default["default"](item, {
612
+ groupBy: {
613
+ $apply: groupBy => {
614
+ const removedItemsBeforeCurrent = removedItemsIndexes.filter(n => n < index);
615
+ return groupBy ? visitor.visitGroupByExpression(groupBy, fromType, removedItemsBeforeCurrent.length) : null;
616
+ }
617
+ }
618
+ }) : item;
619
+ }).map(item => {
620
+ const fromType = ___default["default"].get(item, ["query", "q/from"]);
621
+
622
+ return fromType ? immutableUpdate__default["default"](item, {
623
+ query: {
624
+ $apply: query => {
625
+ const visitedQuery = visitor.visitQueryExpression(query);
626
+ return query ? visitedQuery : null;
627
+ }
628
+ },
629
+ units: {
630
+ $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
631
+ },
632
+ contextExpression: {
633
+ $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
634
+ },
635
+ colorCoding: {
636
+ $apply: colorCodings => {
637
+ return colorCodings ? colorCodings.map(colorCoding => _extends({}, colorCoding, {
638
+ expression: visitor.visitExpression(fromType, colorCoding.expression)
639
+ })).filter(colorCoding => colorCoding.expression !== null) : undefined;
640
+ }
641
+ }
642
+ }) : item;
643
+ }).filter(item => {
644
+ const {
645
+ query
646
+ } = item;
647
+ return query ? item : null;
648
+ });
649
+ }
650
+ }
651
+ }
652
+ });
653
+
654
+ const deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression = (schema, groupByExpression, fromType, removedItems) => {
655
+ if (!groupByExpression) {
656
+ return null;
657
+ }
658
+
659
+ const [[index, {
660
+ expression
661
+ }]] = Object.entries(groupByExpression);
662
+ const visitedExpression = deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression);
663
+
664
+ if (visitedExpression) {
665
+ return {
666
+ [`${parseInt(index) - removedItems}`]: {
667
+ expression: visitedExpression
668
+ }
669
+ };
670
+ }
671
+
672
+ return null;
673
+ };
674
+
675
+ const replaceIdsWithNamesInGroupByExpression = (schema, groupByExpression, fromType) => {
676
+ if (!groupByExpression) {
677
+ return null;
678
+ }
679
+
680
+ const [[index, {
681
+ expression
682
+ }]] = Object.entries(groupByExpression);
683
+
684
+ if (schema.typeObjectsById.hasOwnProperty(fromType)) {
685
+ const typeObject = schema.typeObjectsById[fromType];
686
+ return {
687
+ [index]: {
688
+ expression: visitors.replaceIdsWithNamesVisitor(typeObject).visitExpression(expression)
689
+ }
690
+ };
691
+ }
692
+
693
+ return null;
694
+ };
695
+ const replaceNamesWithIdsInGroupByExpression = (schema, groupByExpression, fromType) => {
696
+ if (!groupByExpression) {
697
+ return null;
698
+ }
699
+
700
+ const [[index, {
701
+ expression
702
+ }]] = Object.entries(groupByExpression);
703
+
704
+ if (schema.typeObjectsByName.hasOwnProperty(fromType)) {
705
+ const typeObject = schema.typeObjectsByName[fromType];
706
+ return {
707
+ [index]: {
708
+ expression: visitors.replaceNamesWithIdsVisitor(typeObject).visitExpression(expression)
709
+ }
710
+ };
711
+ }
712
+
713
+ return null;
714
+ };
715
+ const replaceNamesWithIdsInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
716
+ visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
717
+ visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType),
718
+ visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression)
719
+ });
720
+ const replaceIdsWithNamesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
721
+ visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
722
+ visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType),
723
+ visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression)
724
+ });
725
+ const deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
726
+ visitQueryExpression: query => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, query),
727
+ visitGroupByExpression: (groupBy, fromType, removedItems) => deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression(schema, groupBy, fromType, removedItems),
728
+ visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
729
+ });
730
+ const fixUserSelectedUnitsInSmartFolder = (schema, view) => {
731
+ return visitSmartFolder(view, {
732
+ visitQueryExpression: query => query,
733
+ visitGroupByExpression: groupBy => groupBy,
734
+ visitExpression: (fromType, expression) => expression,
735
+ visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
736
+ });
737
+ };
738
+
739
+ const visitView$1 = (view, visitor) => immutableUpdate__default["default"](view, {
740
+ "fibery/meta": {
741
+ items: {
742
+ $apply: items => items.map(item => {
743
+ const fromType = ___default["default"].get(item, ["query", "q/from"]);
744
+
745
+ return fromType ? immutableUpdate__default["default"](item, {
746
+ query: {
747
+ $apply: query => query ? visitor.visitQueryExpression(query) : null
748
+ },
749
+ contextExpression: {
750
+ $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
751
+ },
752
+ units: {
753
+ $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
754
+ },
755
+ colorCoding: {
756
+ $apply: colorCodings => {
757
+ return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
758
+ expression: visitor.visitExpression(fromType, colorCoding.expression)
759
+ })).filter(colorCoding => colorCoding.expression !== null);
760
+ }
761
+ }
762
+ }) : item;
763
+ }).filter(item => {
764
+ const {
765
+ query
766
+ } = item;
767
+ return query ? item : null;
768
+ })
769
+ }
770
+ }
771
+ });
772
+
773
+ const replaceNamesWithIdsInTableView = (schema, view) => visitView$1(view, {
774
+ visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
775
+ visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query)
776
+ });
777
+ const replaceIdsWithNamesInTableView = (schema, view) => visitView$1(view, {
778
+ visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
779
+ visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query)
780
+ });
781
+ const deleteExpressionWithNotFoundFieldsOrTypesInTableView = (schema, view) => visitView$1(view, {
782
+ visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
783
+ visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
784
+ });
785
+ const fixUserSelectedUnitsInTableView = (schema, view) => visitView$1(view, {
786
+ visitExpression: (fromType, expression) => expression,
787
+ visitQueryExpression: query => query,
788
+ visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
789
+ });
790
+
791
+ const visitAxis = (axis, visitor) => {
792
+ if (!axis) {
793
+ return axis;
794
+ }
795
+
796
+ const fromType = ___default["default"].get(axis, ["query", "q/from"]);
797
+
798
+ const firstOrNull = x => ___default["default"].first(x) || null;
799
+
800
+ const axisResult = _extends({}, axis, {
801
+ query: axis.query && visitor.visitQueryExpression(axis.query),
802
+ contextExpression: axis.contextExpression && visitor.visitExpression(fromType, axis.contextExpression),
803
+ units: axis.units && axis.units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)),
804
+ groupByExpression: axis.groupByExpression && firstOrNull(visitor.visitExpression(fromType, [axis.groupByExpression]))
805
+ });
806
+
807
+ if (!axisResult.query) {
808
+ return null;
809
+ }
810
+
811
+ if (!axisResult.units) {
812
+ delete axisResult.units;
813
+ }
814
+
815
+ return axisResult;
816
+ };
817
+
818
+ const visitView = (view, visitor) => immutableUpdate__default["default"](view, {
819
+ "fibery/meta": {
820
+ y: {
821
+ $apply: y => visitAxis(y, visitor)
822
+ },
823
+ items: {
824
+ $apply: items => items.map(item => {
825
+ const fromType = ___default["default"].get(item, ["query", "q/from"]);
826
+
827
+ return fromType ? immutableUpdate__default["default"](item, {
828
+ yExpression: {
829
+ $apply: yExpression => yExpression ? visitor.visitExpression(fromType, yExpression) : yExpression
830
+ },
831
+ startExpression: {
832
+ $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
833
+ },
834
+ endExpression: {
835
+ $apply: endExpression => endExpression ? visitor.visitExpression(fromType, endExpression) : endExpression
836
+ },
837
+ contextExpression: {
838
+ $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
839
+ },
840
+ query: {
841
+ $apply: query => query ? visitor.visitQueryExpression(query) : null
842
+ },
843
+ units: {
844
+ $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
845
+ },
846
+ colorCoding: {
847
+ $apply: colorCodings => {
848
+ return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
849
+ expression: visitor.visitExpression(fromType, colorCoding.expression)
850
+ })).filter(colorCoding => colorCoding.expression !== null);
851
+ }
852
+ }
853
+ }) : item;
854
+ }).filter(item => {
855
+ const {
856
+ query
857
+ } = item;
858
+ return query ? item : null;
859
+ })
860
+ },
861
+ milestones: {
862
+ $apply: milestones => {
863
+ if (!milestones) {
864
+ return milestones;
865
+ }
866
+
867
+ return milestones.map(item => {
868
+ const fromType = ___default["default"].get(item, ["query", "q/from"]);
869
+
870
+ return fromType ? immutableUpdate__default["default"](item, {
871
+ dateExpression: {
872
+ $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
873
+ },
874
+ query: {
875
+ $apply: query => query ? visitor.visitQueryExpression(query) : null
876
+ }
877
+ }) : item;
878
+ }).filter(item => {
879
+ const {
880
+ query
881
+ } = item;
882
+ return query ? item : null;
883
+ });
884
+ }
885
+ }
886
+ }
887
+ });
888
+
889
+ const replaceNamesWithIdsInTimelineView = (schema, view) => {
890
+ return visitView(view, {
891
+ visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
892
+ visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression)
893
+ });
894
+ };
895
+ const replaceIdsWithNamesInTimelineView = (schema, view) => {
896
+ return visitView(view, {
897
+ visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
898
+ visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression)
899
+ });
900
+ };
901
+
902
+ const ensureAxisAndItemExpressionInvariant = view => {
903
+ const actions = [];
904
+
905
+ const y = ___default["default"].get(view, ["fibery/meta", "y"]);
906
+
907
+ const yQuery = ___default["default"].get(view, ["fibery/meta", "y", "query"]);
908
+
909
+ const yGroupByExpression = ___default["default"].get(view, ["fibery/meta", "y", "groupByExpression"]);
910
+
911
+ const items = ___default["default"].get(view, ["fibery/meta", "items"]);
912
+
913
+ if (yQuery === null && yGroupByExpression !== null) {
914
+ actions.push(() => ___default["default"].set(view, ["fibery/meta", "y", "groupByExpression"], null));
915
+ }
916
+
917
+ if (y === null) {
918
+ const resetActions = items.map(item => () => item.yExpression = null);
919
+ actions.push(...resetActions);
920
+ }
921
+
922
+ if (y !== null && ___default["default"].some(items, ({
923
+ yExpression
924
+ }) => yExpression === null)) {
925
+ const resetActions = items.map(item => () => item.yExpression = null);
926
+ actions.push(...resetActions);
927
+ actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
928
+ }
929
+
930
+ if (y !== null && ___default["default"].isEmpty(items)) {
931
+ actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
932
+ }
933
+
934
+ actions.forEach(action => action());
935
+ return view;
936
+ };
937
+
938
+ const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, ensureAxisInvariant = true) => {
939
+ const viewNew = visitView(view, {
940
+ visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
941
+ visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
942
+ });
943
+ return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant(viewNew) : viewNew;
944
+ };
945
+ const fixUserSelectedUnitsInTimelineView = (schema, view) => {
946
+ return visitView(view, {
947
+ visitQueryExpression: query => query,
948
+ visitExpression: (fromType, expression) => expression,
949
+ visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
950
+ });
951
+ };
952
+
953
+ const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view, ensureAxisInvariant = true) => {
954
+ switch (view["fibery/type"]) {
955
+ case "board":
956
+ return deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView(schema, view, ensureAxisInvariant);
957
+
958
+ case "list":
959
+ return deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder(schema, view);
960
+
961
+ case "timeline":
962
+ return deleteExpressionWithNotFoundFieldsOrTypesInTimelineView(schema, view, ensureAxisInvariant);
963
+
964
+ case "calendar":
965
+ return deleteExpressionWithNotFoundFieldsOrTypesInCalendarView(schema, view);
966
+
967
+ case "table":
968
+ return deleteExpressionWithNotFoundFieldsOrTypesInTableView(schema, view);
969
+
970
+ case "feed":
971
+ return deleteExpressionWithNotFoundFieldsOrTypesInFeedView(schema, view);
972
+
973
+ default:
974
+ return view;
975
+ }
976
+ };
977
+ const fixUserSelectedUnits = (schema, view) => {
978
+ switch (view["fibery/type"]) {
979
+ case "board":
980
+ return fixUserSelectedUnitsInBoardView(schema, view);
981
+
982
+ case "list":
983
+ return fixUserSelectedUnitsInSmartFolder(schema, view);
984
+
985
+ case "table":
986
+ return fixUserSelectedUnitsInTableView(schema, view);
987
+
988
+ case "timeline":
989
+ return fixUserSelectedUnitsInTimelineView(schema, view);
990
+
991
+ case "calendar":
992
+ return fixUserSelectedUnitsInCalendarView(schema, view);
993
+
994
+ case "feed":
995
+ return fixUserSelectedUnitsInFeedView(schema, view);
996
+
997
+ default:
998
+ return view;
999
+ }
1000
+ };
1001
+ const replaceNamesWithIdsInView = (schema, view) => {
1002
+ switch (view["fibery/type"]) {
1003
+ case "board":
1004
+ return replaceNamesWithIdsInBoardView(schema, view);
1005
+
1006
+ case "list":
1007
+ return replaceNamesWithIdsInSmartFolder(schema, view);
1008
+
1009
+ case "table":
1010
+ return replaceNamesWithIdsInTableView(schema, view);
1011
+
1012
+ case "timeline":
1013
+ return replaceNamesWithIdsInTimelineView(schema, view);
1014
+
1015
+ case "calendar":
1016
+ return replaceNamesWithIdsInCalendarView(schema, view);
1017
+
1018
+ case "feed":
1019
+ return replaceNamesWithIdsInFeedView(schema, view);
1020
+
1021
+ default:
1022
+ return view;
1023
+ }
1024
+ };
1025
+ const replaceIdsWithNamesInView = (schema, view) => {
1026
+ switch (view["fibery/type"]) {
1027
+ case "board":
1028
+ return replaceIdsWithNamesInBoardView(schema, view);
1029
+
1030
+ case "list":
1031
+ return replaceIdsWithNamesInSmartFolder(schema, view);
1032
+
1033
+ case "table":
1034
+ return replaceIdsWithNamesInTableView(schema, view);
1035
+
1036
+ case "timeline":
1037
+ return replaceIdsWithNamesInTimelineView(schema, view);
1038
+
1039
+ case "calendar":
1040
+ return replaceIdsWithNamesInCalendarView(schema, view);
1041
+
1042
+ case "feed":
1043
+ return replaceIdsWithNamesInFeedView(schema, view);
1044
+
1045
+ default:
1046
+ return view;
1047
+ }
1048
+ };
1049
+ const getViewCardTypes = ({
1050
+ "fibery/meta": {
1051
+ items
1052
+ }
1053
+ }) => items.map(({
1054
+ query: {
1055
+ "q/from": type
1056
+ }
1057
+ }) => type);
1058
+
1059
+ exports.deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder;
1060
+ exports.deleteExpressionWithNotFoundFieldsOrTypesInView = deleteExpressionWithNotFoundFieldsOrTypesInView;
1061
+ exports.fixUserSelectedUnits = fixUserSelectedUnits;
1062
+ exports.getViewCardTypes = getViewCardTypes;
1063
+ exports.replaceIdsWithNamesInSmartFolder = replaceIdsWithNamesInSmartFolder;
1064
+ exports.replaceIdsWithNamesInView = replaceIdsWithNamesInView;
1065
+ exports.replaceNamesWithIdsInSmartFolder = replaceNamesWithIdsInSmartFolder;
1066
+ exports.replaceNamesWithIdsInView = replaceNamesWithIdsInView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
4
  "description": "Operations on view objects",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Fibery",
@@ -13,11 +13,12 @@
13
13
  "dependencies": {},
14
14
  "devDependencies": {
15
15
  "@babel/core": "7.15.0",
16
- "babel-jest": "27.0.6",
17
- "babel-loader": "8.2.2",
18
- "babel-preset-fibery": "7.2.0",
19
- "eslint-config-fibery": "7.0.0",
20
- "jest": "27.0.6",
16
+ "babel-jest": "27.5.1",
17
+ "babel-loader": "8.2.5",
18
+ "@fibery/babel-preset": "7.2.0",
19
+ "@fibery/eslint-config": "7.1.0",
20
+ "jest": "27.5.1",
21
+ "jest-junit": "13.0.0",
21
22
  "microbundle": "0.14.1"
22
23
  },
23
24
  "peerDependencies": {
@@ -29,15 +30,27 @@
29
30
  "scripts": {
30
31
  "build": "rm -rf lib && microbundle index.js -o lib -f cjs --no-compress --target node --sourcemap false",
31
32
  "test": "node scripts/test.js",
33
+ "test:ci": "yarn test --coverage --reporters=default --reporters=jest-junit",
32
34
  "lint": "eslint ."
33
35
  },
34
36
  "jest": {
35
37
  "testEnvironment": "node",
38
+ "coveragePathIgnorePatterns": [
39
+ "/node_modules/"
40
+ ],
41
+ "collectCoverageFrom": [
42
+ "src/**/*.{js,jsx,ts,tsx}",
43
+ "!src/**/*.d.ts"
44
+ ],
45
+ "coverageReporters": [
46
+ "text",
47
+ "cobertura"
48
+ ],
36
49
  "testPathIgnorePatterns": [
37
50
  "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
38
51
  ],
39
52
  "transform": {
40
- "^.+\\.jsx?$": "../fibery-ui/config/jest/babel.js"
53
+ "^.+\\.(js|jsx|ts|tsx)$": "../fibery-ui/config/jest/babel.js"
41
54
  },
42
55
  "testURL": "http://localhost"
43
56
  }