@cubejs-client/core 0.33.47 → 0.33.55

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.
@@ -1498,19 +1498,43 @@ class CubejsApi {
1498
1498
  */
1499
1499
 
1500
1500
 
1501
- loadResponseInternal(response) {
1502
- if (response.results.length && response.results[0].query.responseFormat && response.results[0].query.responseFormat === ResultType.COMPACT) {
1503
- response.results.forEach((result, j) => {
1504
- const data = [];
1505
- result.data.dataset.forEach(r => {
1506
- const row = {};
1507
- result.data.members.forEach((m, i) => {
1508
- row[m] = r[i];
1501
+ loadResponseInternal(response, options = {}) {
1502
+ if (response.results.length) {
1503
+ if (options.castNumerics) {
1504
+ response.results.forEach(result => {
1505
+ const numericMembers = Object.entries({ ...result.annotation.measures,
1506
+ ...result.annotation.dimensions
1507
+ }).map(([k, v]) => {
1508
+ if (v.type === 'number') {
1509
+ return k;
1510
+ }
1511
+
1512
+ return undefined;
1513
+ }).filter(Boolean);
1514
+ result.data = result.data.map(row => {
1515
+ numericMembers.forEach(key => {
1516
+ if (row[key] != null) {
1517
+ row[key] = Number(row[key]);
1518
+ }
1519
+ });
1520
+ return row;
1509
1521
  });
1510
- data.push(row);
1511
1522
  });
1512
- response.results[j].data = data;
1513
- });
1523
+ }
1524
+
1525
+ if (response.results[0].query.responseFormat && response.results[0].query.responseFormat === ResultType.COMPACT) {
1526
+ response.results.forEach((result, j) => {
1527
+ const data = [];
1528
+ result.data.dataset.forEach(r => {
1529
+ const row = {};
1530
+ result.data.members.forEach((m, i) => {
1531
+ row[m] = r[i];
1532
+ });
1533
+ data.push(row);
1534
+ });
1535
+ response.results[j].data = data;
1536
+ });
1537
+ }
1514
1538
  }
1515
1539
 
1516
1540
  return new ResultSet(response, {
@@ -1530,7 +1554,7 @@ class CubejsApi {
1530
1554
  return this.loadMethod(() => this.request('load', {
1531
1555
  query,
1532
1556
  queryType: 'multi'
1533
- }), this.loadResponseInternal.bind(this), options, callback);
1557
+ }), response => this.loadResponseInternal(response, options), options, callback);
1534
1558
  }
1535
1559
 
1536
1560
  subscribe(query, options, callback, responseFormat = ResultType.DEFAULT) {
@@ -1545,7 +1569,7 @@ class CubejsApi {
1545
1569
  return this.loadMethod(() => this.request('subscribe', {
1546
1570
  query,
1547
1571
  queryType: 'multi'
1548
- }), this.loadResponseInternal.bind(this), { ...options,
1572
+ }), response => this.loadResponseInternal(response, options), { ...options,
1549
1573
  subscribe: true
1550
1574
  }, callback);
1551
1575
  }