@cubejs-client/core 0.10.16 → 0.10.61

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/CHANGELOG.md CHANGED
@@ -3,6 +3,41 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.10.61](https://github.com/statsbotco/cubejs-client/compare/v0.10.60...v0.10.61) (2019-10-10)
7
+
8
+ **Note:** Version bump only for package @cubejs-client/core
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.10.59](https://github.com/statsbotco/cubejs-client/compare/v0.10.58...v0.10.59) (2019-10-08)
15
+
16
+ **Note:** Version bump only for package @cubejs-client/core
17
+
18
+
19
+
20
+
21
+
22
+ ## [0.10.56](https://github.com/statsbotco/cubejs-client/compare/v0.10.55...v0.10.56) (2019-10-04)
23
+
24
+ **Note:** Version bump only for package @cubejs-client/core
25
+
26
+
27
+
28
+
29
+
30
+ ## [0.10.55](https://github.com/statsbotco/cubejs-client/compare/v0.10.54...v0.10.55) (2019-10-03)
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * **client-core:** can't read property 'title' of undefined ([4b48c7f](https://github.com/statsbotco/cubejs-client/commit/4b48c7f))
36
+
37
+
38
+
39
+
40
+
6
41
  ## [0.10.16](https://github.com/statsbotco/cubejs-client/compare/v0.10.15...v0.10.16) (2019-07-20)
7
42
 
8
43
  **Note:** Version bump only for package @cubejs-client/core
@@ -57,6 +57,9 @@ var TIME_SERIES = {
57
57
  });
58
58
  }
59
59
  };
60
+ /**
61
+ * Provides a convenient interface for data manipulation.
62
+ */
60
63
 
61
64
  var ResultSet =
62
65
  /*#__PURE__*/
@@ -160,6 +163,15 @@ function () {
160
163
  pivotConfig.y = pivotConfig.y.concat(['measures']);
161
164
  }
162
165
 
166
+ if (!(query.measures || []).length) {
167
+ pivotConfig.x = pivotConfig.x.filter(function (d) {
168
+ return d !== 'measures';
169
+ });
170
+ pivotConfig.y = pivotConfig.y.filter(function (d) {
171
+ return d !== 'measures';
172
+ });
173
+ }
174
+
163
175
  if (pivotConfig.fillMissingDates == null) {
164
176
  pivotConfig.fillMissingDates = true;
165
177
  }
@@ -311,6 +323,31 @@ function () {
311
323
  // TODO
312
324
  return this.chartPivot(pivotConfig);
313
325
  }
326
+ /**
327
+ * Returns normalized query result data in the following format.
328
+ *
329
+ * ```js
330
+ * // For query
331
+ * {
332
+ * measures: ['Stories.count'],
333
+ * timeDimensions: [{
334
+ * dimension: 'Stories.time',
335
+ * dateRange: ['2015-01-01', '2015-12-31'],
336
+ * granularity: 'month'
337
+ * }]
338
+ * }
339
+ *
340
+ * // ResultSet.chartPivot() will return
341
+ * [
342
+ * { "x":"2015-01-01T00:00:00", "Stories.count": 27120 },
343
+ * { "x":"2015-02-01T00:00:00", "Stories.count": 25861 },
344
+ * { "x": "2015-03-01T00:00:00", "Stories.count": 29661 },
345
+ * //...
346
+ * ]
347
+ * ```
348
+ * @param pivotConfig
349
+ */
350
+
314
351
  }, {
315
352
  key: "chartPivot",
316
353
  value: function chartPivot(pivotConfig) {
@@ -334,6 +371,34 @@ function () {
334
371
  }, {}));
335
372
  });
336
373
  }
374
+ /**
375
+ * Returns normalized query result data prepared for visualization in the table format.
376
+ *
377
+ * For example
378
+ *
379
+ * ```js
380
+ * // For query
381
+ * {
382
+ * measures: ['Stories.count'],
383
+ * timeDimensions: [{
384
+ * dimension: 'Stories.time',
385
+ * dateRange: ['2015-01-01', '2015-12-31'],
386
+ * granularity: 'month'
387
+ * }]
388
+ * }
389
+ *
390
+ * // ResultSet.tablePivot() will return
391
+ * [
392
+ * { "Stories.time": "2015-01-01T00:00:00", "Stories.count": 27120 },
393
+ * { "Stories.time": "2015-02-01T00:00:00", "Stories.count": 25861 },
394
+ * { "Stories.time": "2015-03-01T00:00:00", "Stories.count": 29661 },
395
+ * //...
396
+ * ]
397
+ * ```
398
+ * @param pivotConfig
399
+ * @returns {Array} of pivoted rows
400
+ */
401
+
337
402
  }, {
338
403
  key: "tablePivot",
339
404
  value: function tablePivot(pivotConfig) {
@@ -361,6 +426,33 @@ function () {
361
426
  }, {});
362
427
  });
363
428
  }
429
+ /**
430
+ * Returns array of column definitions for `tablePivot`.
431
+ *
432
+ * For example
433
+ *
434
+ * ```js
435
+ * // For query
436
+ * {
437
+ * measures: ['Stories.count'],
438
+ * timeDimensions: [{
439
+ * dimension: 'Stories.time',
440
+ * dateRange: ['2015-01-01', '2015-12-31'],
441
+ * granularity: 'month'
442
+ * }]
443
+ * }
444
+ *
445
+ * // ResultSet.tableColumns() will return
446
+ * [
447
+ * { key: "Stories.time", title: "Stories Time" },
448
+ * { key: "Stories.count", title: "Stories Count" },
449
+ * //...
450
+ * ]
451
+ * ```
452
+ * @param pivotConfig
453
+ * @returns {Array} of columns
454
+ */
455
+
364
456
  }, {
365
457
  key: "tableColumns",
366
458
  value: function tableColumns(pivotConfig) {
@@ -395,6 +487,29 @@ function () {
395
487
  // TODO
396
488
  return this.chartPivot(pivotConfig);
397
489
  }
490
+ /**
491
+ * Returns the array of series objects, containing `key` and `title` parameters.
492
+ *
493
+ * ```js
494
+ * // For query
495
+ * {
496
+ * measures: ['Stories.count'],
497
+ * timeDimensions: [{
498
+ * dimension: 'Stories.time',
499
+ * dateRange: ['2015-01-01', '2015-12-31'],
500
+ * granularity: 'month'
501
+ * }]
502
+ * }
503
+ *
504
+ * // ResultSet.seriesNames() will return
505
+ * [
506
+ * { "key":"Stories.count", "title": "Stories Count" }
507
+ * ]
508
+ * ```
509
+ * @param pivotConfig
510
+ * @returns {Array} of series names
511
+ */
512
+
398
513
  }, {
399
514
  key: "seriesNames",
400
515
  value: function seriesNames(pivotConfig) {
@@ -629,6 +744,11 @@ var mutexPromise = function mutexPromise(promise) {
629
744
  });
630
745
  });
631
746
  };
747
+ /**
748
+ * Main class for accessing Cube.js API
749
+ * @order -5
750
+ */
751
+
632
752
 
633
753
  var CubejsApi =
634
754
  /*#__PURE__*/
@@ -755,6 +875,34 @@ function () {
755
875
  return mutexPromise(loadImpl());
756
876
  }
757
877
  }
878
+ /**
879
+ * Fetch data for passed `query`.
880
+ *
881
+ * ```js
882
+ * import cubejs from '@cubejs-client/core';
883
+ * import Chart from 'chart.js';
884
+ * import chartjsConfig from './toChartjsData';
885
+ *
886
+ * const cubejsApi = cubejs('CUBEJS_TOKEN');
887
+ *
888
+ * const resultSet = await cubejsApi.load({
889
+ * measures: ['Stories.count'],
890
+ * timeDimensions: [{
891
+ * dimension: 'Stories.time',
892
+ * dateRange: ['2015-01-01', '2015-12-31'],
893
+ * granularity: 'month'
894
+ * }]
895
+ * });
896
+ *
897
+ * const context = document.getElementById('myChart');
898
+ * new Chart(context, chartjsConfig(resultSet));
899
+ * ```
900
+ * @param query - [Query object](query-format)
901
+ * @param options
902
+ * @param callback
903
+ * @returns {Promise} for {@link ResultSet} if `callback` isn't passed
904
+ */
905
+
758
906
  }, {
759
907
  key: "load",
760
908
  value: function load(query, options, callback) {
@@ -766,6 +914,14 @@ function () {
766
914
  return new ResultSet(body);
767
915
  }, options, callback);
768
916
  }
917
+ /**
918
+ * Get generated SQL string for given `query`.
919
+ * @param query - [Query object](query-format)
920
+ * @param options
921
+ * @param callback
922
+ * @return {Promise} for {@link SqlQuery} if `callback` isn't passed
923
+ */
924
+
769
925
  }, {
770
926
  key: "sql",
771
927
  value: function sql(query, options, callback) {
@@ -777,6 +933,13 @@ function () {
777
933
  return new SqlQuery(body);
778
934
  }, options, callback);
779
935
  }
936
+ /**
937
+ * Get meta description of cubes available for querying.
938
+ * @param options
939
+ * @param callback
940
+ * @return {Promise} for {@link Meta} if `callback` isn't passed
941
+ */
942
+
780
943
  }, {
781
944
  key: "meta",
782
945
  value: function meta(options, callback) {
@@ -792,6 +955,28 @@ function () {
792
955
 
793
956
  return CubejsApi;
794
957
  }();
958
+ /**
959
+ * Create instance of `CubejsApi`.
960
+ * API entry point.
961
+ *
962
+ * ```javascript
963
+ import cubejs from '@cubejs-client/core';
964
+
965
+ const cubejsApi = cubejs(
966
+ 'CUBEJS-API-TOKEN',
967
+ { apiUrl: 'http://localhost:4000/cubejs-api/v1' }
968
+ );
969
+ ```
970
+ * @name cubejs
971
+ * @param apiToken - [API token](security) is used to authorize requests and determine SQL database you're accessing.
972
+ * In the development mode, Cube.js Backend will print the API token to the console on on startup.
973
+ * @param options - options object.
974
+ * @param options.apiUrl - URL of your Cube.js Backend.
975
+ * By default, in the development environment it is `http://localhost:4000/cubejs-api/v1`.
976
+ * @returns {CubejsApi}
977
+ * @order -10
978
+ */
979
+
795
980
 
796
981
  var index = (function (apiToken, options) {
797
982
  return new CubejsApi(apiToken, options);
@@ -61,6 +61,9 @@ var TIME_SERIES = {
61
61
  });
62
62
  }
63
63
  };
64
+ /**
65
+ * Provides a convenient interface for data manipulation.
66
+ */
64
67
 
65
68
  var ResultSet =
66
69
  /*#__PURE__*/
@@ -164,6 +167,15 @@ function () {
164
167
  pivotConfig.y = pivotConfig.y.concat(['measures']);
165
168
  }
166
169
 
170
+ if (!(query.measures || []).length) {
171
+ pivotConfig.x = pivotConfig.x.filter(function (d) {
172
+ return d !== 'measures';
173
+ });
174
+ pivotConfig.y = pivotConfig.y.filter(function (d) {
175
+ return d !== 'measures';
176
+ });
177
+ }
178
+
167
179
  if (pivotConfig.fillMissingDates == null) {
168
180
  pivotConfig.fillMissingDates = true;
169
181
  }
@@ -315,6 +327,31 @@ function () {
315
327
  // TODO
316
328
  return this.chartPivot(pivotConfig);
317
329
  }
330
+ /**
331
+ * Returns normalized query result data in the following format.
332
+ *
333
+ * ```js
334
+ * // For query
335
+ * {
336
+ * measures: ['Stories.count'],
337
+ * timeDimensions: [{
338
+ * dimension: 'Stories.time',
339
+ * dateRange: ['2015-01-01', '2015-12-31'],
340
+ * granularity: 'month'
341
+ * }]
342
+ * }
343
+ *
344
+ * // ResultSet.chartPivot() will return
345
+ * [
346
+ * { "x":"2015-01-01T00:00:00", "Stories.count": 27120 },
347
+ * { "x":"2015-02-01T00:00:00", "Stories.count": 25861 },
348
+ * { "x": "2015-03-01T00:00:00", "Stories.count": 29661 },
349
+ * //...
350
+ * ]
351
+ * ```
352
+ * @param pivotConfig
353
+ */
354
+
318
355
  }, {
319
356
  key: "chartPivot",
320
357
  value: function chartPivot(pivotConfig) {
@@ -338,6 +375,34 @@ function () {
338
375
  }, {}));
339
376
  });
340
377
  }
378
+ /**
379
+ * Returns normalized query result data prepared for visualization in the table format.
380
+ *
381
+ * For example
382
+ *
383
+ * ```js
384
+ * // For query
385
+ * {
386
+ * measures: ['Stories.count'],
387
+ * timeDimensions: [{
388
+ * dimension: 'Stories.time',
389
+ * dateRange: ['2015-01-01', '2015-12-31'],
390
+ * granularity: 'month'
391
+ * }]
392
+ * }
393
+ *
394
+ * // ResultSet.tablePivot() will return
395
+ * [
396
+ * { "Stories.time": "2015-01-01T00:00:00", "Stories.count": 27120 },
397
+ * { "Stories.time": "2015-02-01T00:00:00", "Stories.count": 25861 },
398
+ * { "Stories.time": "2015-03-01T00:00:00", "Stories.count": 29661 },
399
+ * //...
400
+ * ]
401
+ * ```
402
+ * @param pivotConfig
403
+ * @returns {Array} of pivoted rows
404
+ */
405
+
341
406
  }, {
342
407
  key: "tablePivot",
343
408
  value: function tablePivot(pivotConfig) {
@@ -365,6 +430,33 @@ function () {
365
430
  }, {});
366
431
  });
367
432
  }
433
+ /**
434
+ * Returns array of column definitions for `tablePivot`.
435
+ *
436
+ * For example
437
+ *
438
+ * ```js
439
+ * // For query
440
+ * {
441
+ * measures: ['Stories.count'],
442
+ * timeDimensions: [{
443
+ * dimension: 'Stories.time',
444
+ * dateRange: ['2015-01-01', '2015-12-31'],
445
+ * granularity: 'month'
446
+ * }]
447
+ * }
448
+ *
449
+ * // ResultSet.tableColumns() will return
450
+ * [
451
+ * { key: "Stories.time", title: "Stories Time" },
452
+ * { key: "Stories.count", title: "Stories Count" },
453
+ * //...
454
+ * ]
455
+ * ```
456
+ * @param pivotConfig
457
+ * @returns {Array} of columns
458
+ */
459
+
368
460
  }, {
369
461
  key: "tableColumns",
370
462
  value: function tableColumns(pivotConfig) {
@@ -399,6 +491,29 @@ function () {
399
491
  // TODO
400
492
  return this.chartPivot(pivotConfig);
401
493
  }
494
+ /**
495
+ * Returns the array of series objects, containing `key` and `title` parameters.
496
+ *
497
+ * ```js
498
+ * // For query
499
+ * {
500
+ * measures: ['Stories.count'],
501
+ * timeDimensions: [{
502
+ * dimension: 'Stories.time',
503
+ * dateRange: ['2015-01-01', '2015-12-31'],
504
+ * granularity: 'month'
505
+ * }]
506
+ * }
507
+ *
508
+ * // ResultSet.seriesNames() will return
509
+ * [
510
+ * { "key":"Stories.count", "title": "Stories Count" }
511
+ * ]
512
+ * ```
513
+ * @param pivotConfig
514
+ * @returns {Array} of series names
515
+ */
516
+
402
517
  }, {
403
518
  key: "seriesNames",
404
519
  value: function seriesNames(pivotConfig) {
@@ -633,6 +748,11 @@ var mutexPromise = function mutexPromise(promise) {
633
748
  });
634
749
  });
635
750
  };
751
+ /**
752
+ * Main class for accessing Cube.js API
753
+ * @order -5
754
+ */
755
+
636
756
 
637
757
  var CubejsApi =
638
758
  /*#__PURE__*/
@@ -759,6 +879,34 @@ function () {
759
879
  return mutexPromise(loadImpl());
760
880
  }
761
881
  }
882
+ /**
883
+ * Fetch data for passed `query`.
884
+ *
885
+ * ```js
886
+ * import cubejs from '@cubejs-client/core';
887
+ * import Chart from 'chart.js';
888
+ * import chartjsConfig from './toChartjsData';
889
+ *
890
+ * const cubejsApi = cubejs('CUBEJS_TOKEN');
891
+ *
892
+ * const resultSet = await cubejsApi.load({
893
+ * measures: ['Stories.count'],
894
+ * timeDimensions: [{
895
+ * dimension: 'Stories.time',
896
+ * dateRange: ['2015-01-01', '2015-12-31'],
897
+ * granularity: 'month'
898
+ * }]
899
+ * });
900
+ *
901
+ * const context = document.getElementById('myChart');
902
+ * new Chart(context, chartjsConfig(resultSet));
903
+ * ```
904
+ * @param query - [Query object](query-format)
905
+ * @param options
906
+ * @param callback
907
+ * @returns {Promise} for {@link ResultSet} if `callback` isn't passed
908
+ */
909
+
762
910
  }, {
763
911
  key: "load",
764
912
  value: function load(query, options, callback) {
@@ -770,6 +918,14 @@ function () {
770
918
  return new ResultSet(body);
771
919
  }, options, callback);
772
920
  }
921
+ /**
922
+ * Get generated SQL string for given `query`.
923
+ * @param query - [Query object](query-format)
924
+ * @param options
925
+ * @param callback
926
+ * @return {Promise} for {@link SqlQuery} if `callback` isn't passed
927
+ */
928
+
773
929
  }, {
774
930
  key: "sql",
775
931
  value: function sql(query, options, callback) {
@@ -781,6 +937,13 @@ function () {
781
937
  return new SqlQuery(body);
782
938
  }, options, callback);
783
939
  }
940
+ /**
941
+ * Get meta description of cubes available for querying.
942
+ * @param options
943
+ * @param callback
944
+ * @return {Promise} for {@link Meta} if `callback` isn't passed
945
+ */
946
+
784
947
  }, {
785
948
  key: "meta",
786
949
  value: function meta(options, callback) {
@@ -796,6 +959,28 @@ function () {
796
959
 
797
960
  return CubejsApi;
798
961
  }();
962
+ /**
963
+ * Create instance of `CubejsApi`.
964
+ * API entry point.
965
+ *
966
+ * ```javascript
967
+ import cubejs from '@cubejs-client/core';
968
+
969
+ const cubejsApi = cubejs(
970
+ 'CUBEJS-API-TOKEN',
971
+ { apiUrl: 'http://localhost:4000/cubejs-api/v1' }
972
+ );
973
+ ```
974
+ * @name cubejs
975
+ * @param apiToken - [API token](security) is used to authorize requests and determine SQL database you're accessing.
976
+ * In the development mode, Cube.js Backend will print the API token to the console on on startup.
977
+ * @param options - options object.
978
+ * @param options.apiUrl - URL of your Cube.js Backend.
979
+ * By default, in the development environment it is `http://localhost:4000/cubejs-api/v1`.
980
+ * @returns {CubejsApi}
981
+ * @order -10
982
+ */
983
+
799
984
 
800
985
  var index = (function (apiToken, options) {
801
986
  return new CubejsApi(apiToken, options);
@@ -14387,6 +14387,9 @@
14387
14387
  });
14388
14388
  }
14389
14389
  };
14390
+ /**
14391
+ * Provides a convenient interface for data manipulation.
14392
+ */
14390
14393
 
14391
14394
  var ResultSet =
14392
14395
  /*#__PURE__*/
@@ -14490,6 +14493,15 @@
14490
14493
  pivotConfig.y = pivotConfig.y.concat(['measures']);
14491
14494
  }
14492
14495
 
14496
+ if (!(query.measures || []).length) {
14497
+ pivotConfig.x = pivotConfig.x.filter(function (d) {
14498
+ return d !== 'measures';
14499
+ });
14500
+ pivotConfig.y = pivotConfig.y.filter(function (d) {
14501
+ return d !== 'measures';
14502
+ });
14503
+ }
14504
+
14493
14505
  if (pivotConfig.fillMissingDates == null) {
14494
14506
  pivotConfig.fillMissingDates = true;
14495
14507
  }
@@ -14641,6 +14653,31 @@
14641
14653
  // TODO
14642
14654
  return this.chartPivot(pivotConfig);
14643
14655
  }
14656
+ /**
14657
+ * Returns normalized query result data in the following format.
14658
+ *
14659
+ * ```js
14660
+ * // For query
14661
+ * {
14662
+ * measures: ['Stories.count'],
14663
+ * timeDimensions: [{
14664
+ * dimension: 'Stories.time',
14665
+ * dateRange: ['2015-01-01', '2015-12-31'],
14666
+ * granularity: 'month'
14667
+ * }]
14668
+ * }
14669
+ *
14670
+ * // ResultSet.chartPivot() will return
14671
+ * [
14672
+ * { "x":"2015-01-01T00:00:00", "Stories.count": 27120 },
14673
+ * { "x":"2015-02-01T00:00:00", "Stories.count": 25861 },
14674
+ * { "x": "2015-03-01T00:00:00", "Stories.count": 29661 },
14675
+ * //...
14676
+ * ]
14677
+ * ```
14678
+ * @param pivotConfig
14679
+ */
14680
+
14644
14681
  }, {
14645
14682
  key: "chartPivot",
14646
14683
  value: function chartPivot(pivotConfig) {
@@ -14664,6 +14701,34 @@
14664
14701
  }, {}));
14665
14702
  });
14666
14703
  }
14704
+ /**
14705
+ * Returns normalized query result data prepared for visualization in the table format.
14706
+ *
14707
+ * For example
14708
+ *
14709
+ * ```js
14710
+ * // For query
14711
+ * {
14712
+ * measures: ['Stories.count'],
14713
+ * timeDimensions: [{
14714
+ * dimension: 'Stories.time',
14715
+ * dateRange: ['2015-01-01', '2015-12-31'],
14716
+ * granularity: 'month'
14717
+ * }]
14718
+ * }
14719
+ *
14720
+ * // ResultSet.tablePivot() will return
14721
+ * [
14722
+ * { "Stories.time": "2015-01-01T00:00:00", "Stories.count": 27120 },
14723
+ * { "Stories.time": "2015-02-01T00:00:00", "Stories.count": 25861 },
14724
+ * { "Stories.time": "2015-03-01T00:00:00", "Stories.count": 29661 },
14725
+ * //...
14726
+ * ]
14727
+ * ```
14728
+ * @param pivotConfig
14729
+ * @returns {Array} of pivoted rows
14730
+ */
14731
+
14667
14732
  }, {
14668
14733
  key: "tablePivot",
14669
14734
  value: function tablePivot(pivotConfig) {
@@ -14691,6 +14756,33 @@
14691
14756
  }, {});
14692
14757
  });
14693
14758
  }
14759
+ /**
14760
+ * Returns array of column definitions for `tablePivot`.
14761
+ *
14762
+ * For example
14763
+ *
14764
+ * ```js
14765
+ * // For query
14766
+ * {
14767
+ * measures: ['Stories.count'],
14768
+ * timeDimensions: [{
14769
+ * dimension: 'Stories.time',
14770
+ * dateRange: ['2015-01-01', '2015-12-31'],
14771
+ * granularity: 'month'
14772
+ * }]
14773
+ * }
14774
+ *
14775
+ * // ResultSet.tableColumns() will return
14776
+ * [
14777
+ * { key: "Stories.time", title: "Stories Time" },
14778
+ * { key: "Stories.count", title: "Stories Count" },
14779
+ * //...
14780
+ * ]
14781
+ * ```
14782
+ * @param pivotConfig
14783
+ * @returns {Array} of columns
14784
+ */
14785
+
14694
14786
  }, {
14695
14787
  key: "tableColumns",
14696
14788
  value: function tableColumns(pivotConfig) {
@@ -14725,6 +14817,29 @@
14725
14817
  // TODO
14726
14818
  return this.chartPivot(pivotConfig);
14727
14819
  }
14820
+ /**
14821
+ * Returns the array of series objects, containing `key` and `title` parameters.
14822
+ *
14823
+ * ```js
14824
+ * // For query
14825
+ * {
14826
+ * measures: ['Stories.count'],
14827
+ * timeDimensions: [{
14828
+ * dimension: 'Stories.time',
14829
+ * dateRange: ['2015-01-01', '2015-12-31'],
14830
+ * granularity: 'month'
14831
+ * }]
14832
+ * }
14833
+ *
14834
+ * // ResultSet.seriesNames() will return
14835
+ * [
14836
+ * { "key":"Stories.count", "title": "Stories Count" }
14837
+ * ]
14838
+ * ```
14839
+ * @param pivotConfig
14840
+ * @returns {Array} of series names
14841
+ */
14842
+
14728
14843
  }, {
14729
14844
  key: "seriesNames",
14730
14845
  value: function seriesNames(pivotConfig) {
@@ -14959,6 +15074,11 @@
14959
15074
  });
14960
15075
  });
14961
15076
  };
15077
+ /**
15078
+ * Main class for accessing Cube.js API
15079
+ * @order -5
15080
+ */
15081
+
14962
15082
 
14963
15083
  var CubejsApi =
14964
15084
  /*#__PURE__*/
@@ -15085,6 +15205,34 @@
15085
15205
  return mutexPromise(loadImpl());
15086
15206
  }
15087
15207
  }
15208
+ /**
15209
+ * Fetch data for passed `query`.
15210
+ *
15211
+ * ```js
15212
+ * import cubejs from '@cubejs-client/core';
15213
+ * import Chart from 'chart.js';
15214
+ * import chartjsConfig from './toChartjsData';
15215
+ *
15216
+ * const cubejsApi = cubejs('CUBEJS_TOKEN');
15217
+ *
15218
+ * const resultSet = await cubejsApi.load({
15219
+ * measures: ['Stories.count'],
15220
+ * timeDimensions: [{
15221
+ * dimension: 'Stories.time',
15222
+ * dateRange: ['2015-01-01', '2015-12-31'],
15223
+ * granularity: 'month'
15224
+ * }]
15225
+ * });
15226
+ *
15227
+ * const context = document.getElementById('myChart');
15228
+ * new Chart(context, chartjsConfig(resultSet));
15229
+ * ```
15230
+ * @param query - [Query object](query-format)
15231
+ * @param options
15232
+ * @param callback
15233
+ * @returns {Promise} for {@link ResultSet} if `callback` isn't passed
15234
+ */
15235
+
15088
15236
  }, {
15089
15237
  key: "load",
15090
15238
  value: function load(query, options, callback) {
@@ -15096,6 +15244,14 @@
15096
15244
  return new ResultSet(body);
15097
15245
  }, options, callback);
15098
15246
  }
15247
+ /**
15248
+ * Get generated SQL string for given `query`.
15249
+ * @param query - [Query object](query-format)
15250
+ * @param options
15251
+ * @param callback
15252
+ * @return {Promise} for {@link SqlQuery} if `callback` isn't passed
15253
+ */
15254
+
15099
15255
  }, {
15100
15256
  key: "sql",
15101
15257
  value: function sql(query, options, callback) {
@@ -15107,6 +15263,13 @@
15107
15263
  return new SqlQuery(body);
15108
15264
  }, options, callback);
15109
15265
  }
15266
+ /**
15267
+ * Get meta description of cubes available for querying.
15268
+ * @param options
15269
+ * @param callback
15270
+ * @return {Promise} for {@link Meta} if `callback` isn't passed
15271
+ */
15272
+
15110
15273
  }, {
15111
15274
  key: "meta",
15112
15275
  value: function meta(options, callback) {
@@ -15122,6 +15285,28 @@
15122
15285
 
15123
15286
  return CubejsApi;
15124
15287
  }();
15288
+ /**
15289
+ * Create instance of `CubejsApi`.
15290
+ * API entry point.
15291
+ *
15292
+ * ```javascript
15293
+ import cubejs from '@cubejs-client/core';
15294
+
15295
+ const cubejsApi = cubejs(
15296
+ 'CUBEJS-API-TOKEN',
15297
+ { apiUrl: 'http://localhost:4000/cubejs-api/v1' }
15298
+ );
15299
+ ```
15300
+ * @name cubejs
15301
+ * @param apiToken - [API token](security) is used to authorize requests and determine SQL database you're accessing.
15302
+ * In the development mode, Cube.js Backend will print the API token to the console on on startup.
15303
+ * @param options - options object.
15304
+ * @param options.apiUrl - URL of your Cube.js Backend.
15305
+ * By default, in the development environment it is `http://localhost:4000/cubejs-api/v1`.
15306
+ * @returns {CubejsApi}
15307
+ * @order -10
15308
+ */
15309
+
15125
15310
 
15126
15311
  var index = (function (apiToken, options) {
15127
15312
  return new CubejsApi(apiToken, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubejs-client/core",
3
- "version": "0.10.16",
3
+ "version": "0.10.61",
4
4
  "description": "cube.js client",
5
5
  "main": "dist/cubejs-client-core.js",
6
6
  "author": "Statsbot, Inc.",
@@ -26,5 +26,5 @@
26
26
  "babel-jest": "^24.1.0",
27
27
  "jest": "^24.1.0"
28
28
  },
29
- "gitHead": "993b8eaf27d17e8d319d26c588490764936ef5fd"
29
+ "gitHead": "cc5aa4570e7bf9f920686e3574f657ec474bceaf"
30
30
  }
package/src/ResultSet.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module @cubejs-client/core
3
+ */
4
+
1
5
  import {
2
6
  groupBy, pipe, toPairs, uniq, filter, map, unnest, dropLast, equals, reduce, minBy, maxBy
3
7
  } from 'ramda';
@@ -19,7 +23,10 @@ const TIME_SERIES = {
19
23
  .map(d => d.startOf('isoweek').format('YYYY-MM-DDT00:00:00.000'))
20
24
  };
21
25
 
22
- export default class ResultSet {
26
+ /**
27
+ * Provides a convenient interface for data manipulation.
28
+ */
29
+ class ResultSet {
23
30
  constructor(loadResponse) {
24
31
  this.loadResponse = loadResponse;
25
32
  }
@@ -74,6 +81,10 @@ export default class ResultSet {
74
81
  if (!pivotConfig.x.concat(pivotConfig.y).find(d => d === 'measures')) {
75
82
  pivotConfig.y = pivotConfig.y.concat(['measures']);
76
83
  }
84
+ if (!(query.measures || []).length) {
85
+ pivotConfig.x = pivotConfig.x.filter(d => d !== 'measures');
86
+ pivotConfig.y = pivotConfig.y.filter(d => d !== 'measures');
87
+ }
77
88
  if (pivotConfig.fillMissingDates == null) {
78
89
  pivotConfig.fillMissingDates = true;
79
90
  }
@@ -187,6 +198,30 @@ export default class ResultSet {
187
198
  return this.chartPivot(pivotConfig);
188
199
  }
189
200
 
201
+ /**
202
+ * Returns normalized query result data in the following format.
203
+ *
204
+ * ```js
205
+ * // For query
206
+ * {
207
+ * measures: ['Stories.count'],
208
+ * timeDimensions: [{
209
+ * dimension: 'Stories.time',
210
+ * dateRange: ['2015-01-01', '2015-12-31'],
211
+ * granularity: 'month'
212
+ * }]
213
+ * }
214
+ *
215
+ * // ResultSet.chartPivot() will return
216
+ * [
217
+ * { "x":"2015-01-01T00:00:00", "Stories.count": 27120 },
218
+ * { "x":"2015-02-01T00:00:00", "Stories.count": 25861 },
219
+ * { "x": "2015-03-01T00:00:00", "Stories.count": 29661 },
220
+ * //...
221
+ * ]
222
+ * ```
223
+ * @param pivotConfig
224
+ */
190
225
  chartPivot(pivotConfig) {
191
226
  return this.pivot(pivotConfig).map(({ xValues, yValuesArray }) => ({
192
227
  category: this.axisValuesString(xValues, ', '), // TODO deprecated
@@ -199,6 +234,33 @@ export default class ResultSet {
199
234
  }));
200
235
  }
201
236
 
237
+ /**
238
+ * Returns normalized query result data prepared for visualization in the table format.
239
+ *
240
+ * For example
241
+ *
242
+ * ```js
243
+ * // For query
244
+ * {
245
+ * measures: ['Stories.count'],
246
+ * timeDimensions: [{
247
+ * dimension: 'Stories.time',
248
+ * dateRange: ['2015-01-01', '2015-12-31'],
249
+ * granularity: 'month'
250
+ * }]
251
+ * }
252
+ *
253
+ * // ResultSet.tablePivot() will return
254
+ * [
255
+ * { "Stories.time": "2015-01-01T00:00:00", "Stories.count": 27120 },
256
+ * { "Stories.time": "2015-02-01T00:00:00", "Stories.count": 25861 },
257
+ * { "Stories.time": "2015-03-01T00:00:00", "Stories.count": 29661 },
258
+ * //...
259
+ * ]
260
+ * ```
261
+ * @param pivotConfig
262
+ * @returns {Array} of pivoted rows
263
+ */
202
264
  tablePivot(pivotConfig) {
203
265
  const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig);
204
266
  const valueToObject =
@@ -217,6 +279,32 @@ export default class ResultSet {
217
279
  ));
218
280
  }
219
281
 
282
+ /**
283
+ * Returns array of column definitions for `tablePivot`.
284
+ *
285
+ * For example
286
+ *
287
+ * ```js
288
+ * // For query
289
+ * {
290
+ * measures: ['Stories.count'],
291
+ * timeDimensions: [{
292
+ * dimension: 'Stories.time',
293
+ * dateRange: ['2015-01-01', '2015-12-31'],
294
+ * granularity: 'month'
295
+ * }]
296
+ * }
297
+ *
298
+ * // ResultSet.tableColumns() will return
299
+ * [
300
+ * { key: "Stories.time", title: "Stories Time" },
301
+ * { key: "Stories.count", title: "Stories Count" },
302
+ * //...
303
+ * ]
304
+ * ```
305
+ * @param pivotConfig
306
+ * @returns {Array} of columns
307
+ */
220
308
  tableColumns(pivotConfig) {
221
309
  const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig);
222
310
  const column = field => (
@@ -243,6 +331,28 @@ export default class ResultSet {
243
331
  return this.chartPivot(pivotConfig);
244
332
  }
245
333
 
334
+ /**
335
+ * Returns the array of series objects, containing `key` and `title` parameters.
336
+ *
337
+ * ```js
338
+ * // For query
339
+ * {
340
+ * measures: ['Stories.count'],
341
+ * timeDimensions: [{
342
+ * dimension: 'Stories.time',
343
+ * dateRange: ['2015-01-01', '2015-12-31'],
344
+ * granularity: 'month'
345
+ * }]
346
+ * }
347
+ *
348
+ * // ResultSet.seriesNames() will return
349
+ * [
350
+ * { "key":"Stories.count", "title": "Stories Count" }
351
+ * ]
352
+ * ```
353
+ * @param pivotConfig
354
+ * @returns {Array} of series names
355
+ */
246
356
  seriesNames(pivotConfig) {
247
357
  pivotConfig = this.normalizePivotConfig(pivotConfig);
248
358
  return pipe(map(this.axisValues(pivotConfig.y)), unnest, uniq)(this.loadResponse.data).map(axisValues => ({
@@ -262,3 +372,5 @@ export default class ResultSet {
262
372
  return this.loadResponse.data;
263
373
  }
264
374
  }
375
+
376
+ export default ResultSet;
@@ -87,7 +87,7 @@ describe('ResultSet', () => {
87
87
 
88
88
  expect(resultSet.normalizePivotConfig({ y: ['Foo.bar'] })).toEqual({
89
89
  x: ['Foo.createdAt'],
90
- y: ['Foo.bar', 'measures'],
90
+ y: ['Foo.bar'],
91
91
  fillMissingDates: true
92
92
  });
93
93
  });
package/src/index.js CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Vanilla JavaScript Cube.js client.
3
+ * @module @cubejs-client/core
4
+ * @permalink /@cubejs-client-core
5
+ * @category Cube.js Frontend
6
+ * @menuOrder 2
7
+ */
8
+
1
9
  import fetch from 'cross-fetch';
2
10
  import ResultSet from './ResultSet';
3
11
  import SqlQuery from './SqlQuery';
@@ -13,9 +21,13 @@ const MUTEX_ERROR = 'Mutex has been changed';
13
21
  const mutexPromise = (promise) => {
14
22
  return new Promise((resolve, reject) => {
15
23
  promise.then(r => resolve(r), e => e !== MUTEX_ERROR && reject(e));
16
- })
24
+ });
17
25
  };
18
26
 
27
+ /**
28
+ * Main class for accessing Cube.js API
29
+ * @order -5
30
+ */
19
31
  class CubejsApi {
20
32
  constructor(apiToken, options) {
21
33
  options = options || {};
@@ -78,6 +90,33 @@ class CubejsApi {
78
90
  }
79
91
  }
80
92
 
93
+ /**
94
+ * Fetch data for passed `query`.
95
+ *
96
+ * ```js
97
+ * import cubejs from '@cubejs-client/core';
98
+ * import Chart from 'chart.js';
99
+ * import chartjsConfig from './toChartjsData';
100
+ *
101
+ * const cubejsApi = cubejs('CUBEJS_TOKEN');
102
+ *
103
+ * const resultSet = await cubejsApi.load({
104
+ * measures: ['Stories.count'],
105
+ * timeDimensions: [{
106
+ * dimension: 'Stories.time',
107
+ * dateRange: ['2015-01-01', '2015-12-31'],
108
+ * granularity: 'month'
109
+ * }]
110
+ * });
111
+ *
112
+ * const context = document.getElementById('myChart');
113
+ * new Chart(context, chartjsConfig(resultSet));
114
+ * ```
115
+ * @param query - [Query object](query-format)
116
+ * @param options
117
+ * @param callback
118
+ * @returns {Promise} for {@link ResultSet} if `callback` isn't passed
119
+ */
81
120
  load(query, options, callback) {
82
121
  return this.loadMethod(
83
122
  () => this.request(`/load?query=${encodeURIComponent(JSON.stringify(query))}`),
@@ -87,6 +126,13 @@ class CubejsApi {
87
126
  );
88
127
  }
89
128
 
129
+ /**
130
+ * Get generated SQL string for given `query`.
131
+ * @param query - [Query object](query-format)
132
+ * @param options
133
+ * @param callback
134
+ * @return {Promise} for {@link SqlQuery} if `callback` isn't passed
135
+ */
90
136
  sql(query, options, callback) {
91
137
  return this.loadMethod(
92
138
  () => this.request(`/sql?query=${JSON.stringify(query)}`),
@@ -96,6 +142,12 @@ class CubejsApi {
96
142
  );
97
143
  }
98
144
 
145
+ /**
146
+ * Get meta description of cubes available for querying.
147
+ * @param options
148
+ * @param callback
149
+ * @return {Promise} for {@link Meta} if `callback` isn't passed
150
+ */
99
151
  meta(options, callback) {
100
152
  return this.loadMethod(
101
153
  () => this.request(`/meta`),
@@ -106,6 +158,27 @@ class CubejsApi {
106
158
  }
107
159
  }
108
160
 
161
+ /**
162
+ * Create instance of `CubejsApi`.
163
+ * API entry point.
164
+ *
165
+ * ```javascript
166
+ import cubejs from '@cubejs-client/core';
167
+
168
+ const cubejsApi = cubejs(
169
+ 'CUBEJS-API-TOKEN',
170
+ { apiUrl: 'http://localhost:4000/cubejs-api/v1' }
171
+ );
172
+ ```
173
+ * @name cubejs
174
+ * @param apiToken - [API token](security) is used to authorize requests and determine SQL database you're accessing.
175
+ * In the development mode, Cube.js Backend will print the API token to the console on on startup.
176
+ * @param options - options object.
177
+ * @param options.apiUrl - URL of your Cube.js Backend.
178
+ * By default, in the development environment it is `http://localhost:4000/cubejs-api/v1`.
179
+ * @returns {CubejsApi}
180
+ * @order -10
181
+ */
109
182
  export default (apiToken, options) => {
110
183
  return new CubejsApi(apiToken, options);
111
184
  };