@cubejs-client/core 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -252,9 +252,13 @@ declare module '@cubejs-client/core' {
252
252
  */
253
253
  y?: string[];
254
254
  /**
255
- * If `true` missing dates on the time dimensions will be filled with `0` for all measures.Note: the `fillMissingDates` option set to `true` will override any **order** applied to the query
255
+ * If `true` missing dates on the time dimensions will be filled with fillWithValue or `0` by default for all measures.Note: the `fillMissingDates` option set to `true` will override any **order** applied to the query
256
256
  */
257
257
  fillMissingDates?: boolean | null;
258
+ /**
259
+ * Value to autofill all the missing date's measure.
260
+ */
261
+ fillWithValue?: string | number | null;
258
262
  /**
259
263
  * Give each series a prefix alias. Should have one entry for each query:measure. See [chartPivot](#result-set-chart-pivot)
260
264
  */
@@ -972,6 +976,18 @@ declare module '@cubejs-client/core' {
972
976
 
973
977
  export type CubeMember = TCubeMeasure | TCubeDimension | TCubeSegment;
974
978
 
979
+ export type TCubeFolder = {
980
+ name: string;
981
+ members: string[];
982
+ };
983
+
984
+ export type TCubeHierarchy = {
985
+ name: string;
986
+ title?: string;
987
+ levels: string[];
988
+ public?: boolean;
989
+ };
990
+
975
991
  /**
976
992
  * @deprecated use DryRunResponse
977
993
  */
@@ -998,6 +1014,8 @@ declare module '@cubejs-client/core' {
998
1014
  measures: TCubeMeasure[];
999
1015
  dimensions: TCubeDimension[];
1000
1016
  segments: TCubeSegment[];
1017
+ folders: TCubeFolder[];
1018
+ hierarchies: TCubeHierarchy[];
1001
1019
  connectedComponent?: number;
1002
1020
  type?: 'view' | 'cube';
1003
1021
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubejs-client/core",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "engines": {},
5
5
  "repository": {
6
6
  "type": "git",
@@ -45,5 +45,5 @@
45
45
  "eslint-plugin-node": "^5.2.1",
46
46
  "jest": "^27"
47
47
  },
48
- "gitHead": "a8f48f289ebf11ce3b0480cf3713ba060c7e0270"
48
+ "gitHead": "64c572835e71fdfd7c8aaf87a4fad4cc083c55b5"
49
49
  }
package/src/ResultSet.js CHANGED
@@ -341,7 +341,7 @@ class ResultSet {
341
341
  const pivotImpl = (resultIndex = 0) => {
342
342
  let groupByXAxis = groupByToPairs(({ xValues }) => this.axisValuesString(xValues));
343
343
 
344
- const measureValue = (row, measure) => row[measure] || 0;
344
+ const measureValue = (row, measure) => row[measure] || pivotConfig.fillWithValue || 0;
345
345
 
346
346
  if (
347
347
  pivotConfig.fillMissingDates &&
@@ -1418,6 +1418,126 @@ describe('ResultSet', () => {
1418
1418
  ]);
1419
1419
  });
1420
1420
 
1421
+ test('fill missing dates with custom value', () => {
1422
+ const resultSet = new ResultSet({
1423
+ query: {
1424
+ measures: ['Orders.total'],
1425
+ timeDimensions: [
1426
+ {
1427
+ dimension: 'Orders.createdAt',
1428
+ granularity: 'day',
1429
+ dateRange: ['2020-01-08T00:00:00.000', '2020-01-11T23:59:59.999']
1430
+ }
1431
+ ],
1432
+ filters: [],
1433
+ timezone: 'UTC'
1434
+ },
1435
+ data: [
1436
+ {
1437
+ 'Orders.createdAt': '2020-01-08T00:00:00.000',
1438
+ 'Orders.total': 1
1439
+ },
1440
+ {
1441
+ 'Orders.createdAt': '2020-01-10T00:00:00.000',
1442
+ 'Orders.total': 10
1443
+ }
1444
+ ],
1445
+ annotation: {
1446
+ measures: {},
1447
+ dimensions: {},
1448
+ segments: {},
1449
+ timeDimensions: {
1450
+ 'Orders.createdAt': {
1451
+ title: 'Orders Created at',
1452
+ shortTitle: 'Created at',
1453
+ type: 'time'
1454
+ }
1455
+ }
1456
+ }
1457
+ });
1458
+
1459
+ expect(resultSet.tablePivot({
1460
+ 'fillWithValue': 5
1461
+ })).toEqual([
1462
+ {
1463
+ 'Orders.createdAt.day': '2020-01-08T00:00:00.000',
1464
+ 'Orders.total': 1
1465
+ },
1466
+ {
1467
+ 'Orders.createdAt.day': '2020-01-09T00:00:00.000',
1468
+ 'Orders.total': 5
1469
+ },
1470
+ {
1471
+ 'Orders.createdAt.day': '2020-01-10T00:00:00.000',
1472
+ 'Orders.total': 10
1473
+ },
1474
+ {
1475
+ 'Orders.createdAt.day': '2020-01-11T00:00:00.000',
1476
+ 'Orders.total': 5
1477
+ }
1478
+ ]);
1479
+ });
1480
+
1481
+ test('fill missing dates with custom string', () => {
1482
+ const resultSet = new ResultSet({
1483
+ query: {
1484
+ measures: ['Orders.total'],
1485
+ timeDimensions: [
1486
+ {
1487
+ dimension: 'Orders.createdAt',
1488
+ granularity: 'day',
1489
+ dateRange: ['2020-01-08T00:00:00.000', '2020-01-11T23:59:59.999']
1490
+ }
1491
+ ],
1492
+ filters: [],
1493
+ timezone: 'UTC'
1494
+ },
1495
+ data: [
1496
+ {
1497
+ 'Orders.createdAt': '2020-01-08T00:00:00.000',
1498
+ 'Orders.total': 1
1499
+ },
1500
+ {
1501
+ 'Orders.createdAt': '2020-01-10T00:00:00.000',
1502
+ 'Orders.total': 10
1503
+ }
1504
+ ],
1505
+ annotation: {
1506
+ measures: {},
1507
+ dimensions: {},
1508
+ segments: {},
1509
+ timeDimensions: {
1510
+ 'Orders.createdAt': {
1511
+ title: 'Orders Created at',
1512
+ shortTitle: 'Created at',
1513
+ type: 'time'
1514
+ }
1515
+ }
1516
+ }
1517
+ });
1518
+
1519
+ expect(resultSet.tablePivot({
1520
+ 'fillWithValue': 'N/A'
1521
+ })).toEqual([
1522
+ {
1523
+ 'Orders.createdAt.day': '2020-01-08T00:00:00.000',
1524
+ 'Orders.total': 1
1525
+ },
1526
+ {
1527
+ 'Orders.createdAt.day': '2020-01-09T00:00:00.000',
1528
+ 'Orders.total': "N/A"
1529
+ },
1530
+ {
1531
+ 'Orders.createdAt.day': '2020-01-10T00:00:00.000',
1532
+ 'Orders.total': 10
1533
+ },
1534
+ {
1535
+ 'Orders.createdAt.day': '2020-01-11T00:00:00.000',
1536
+ 'Orders.total': "N/A"
1537
+ }
1538
+ ]);
1539
+ });
1540
+
1421
1541
  test('same dimension and time dimension without granularity', () => {
1422
1542
  const resultSet = new ResultSet({
1423
1543
  query: {