@cubejs-client/core
Advanced tools
Comparing version 0.10.56 to 0.10.59
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.10.59](https://github.com/statsbotco/cubejs-client/compare/v0.10.58...v0.10.59) (2019-10-08) | ||
**Note:** Version bump only for package @cubejs-client/core | ||
## [0.10.56](https://github.com/statsbotco/cubejs-client/compare/v0.10.55...v0.10.56) (2019-10-04) | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "@cubejs-client/core", | ||
"version": "0.10.56", | ||
"version": "0.10.59", | ||
"description": "cube.js client", | ||
@@ -29,3 +29,3 @@ "main": "dist/cubejs-client-core.js", | ||
}, | ||
"gitHead": "8f4f8594c09328cf48f09a6be731df17441f0ac4" | ||
"gitHead": "31a826dedfa046b442e43bb9885e2bcfb00aaebe" | ||
} |
@@ -0,1 +1,9 @@ | ||
/** | ||
* Vanilla JavaScript Cube.js client. | ||
* @module @cubejs-client/core | ||
* @permalink /@cubejs-client-core | ||
* @category Cube.js Frontend | ||
* @menuOrder 2 | ||
*/ | ||
import fetch from 'cross-fetch'; | ||
@@ -16,5 +24,9 @@ import ResultSet from './ResultSet'; | ||
promise.then(r => resolve(r), e => e !== MUTEX_ERROR && reject(e)); | ||
}) | ||
}); | ||
}; | ||
/** | ||
* Main class for accessing Cube.js API | ||
* @order -5 | ||
*/ | ||
class CubejsApi { | ||
@@ -82,2 +94,29 @@ constructor(apiToken, options) { | ||
/** | ||
* Fetch data for passed `query`. | ||
* | ||
* ```js | ||
* import cubejs from '@cubejs-client/core'; | ||
* import Chart from 'chart.js'; | ||
* import chartjsConfig from './toChartjsData'; | ||
* | ||
* const cubejsApi = cubejs('CUBEJS_TOKEN'); | ||
* | ||
* const resultSet = await cubejsApi.load({ | ||
* measures: ['Stories.count'], | ||
* timeDimensions: [{ | ||
* dimension: 'Stories.time', | ||
* dateRange: ['2015-01-01', '2015-12-31'], | ||
* granularity: 'month' | ||
* }] | ||
* }); | ||
* | ||
* const context = document.getElementById('myChart'); | ||
* new Chart(context, chartjsConfig(resultSet)); | ||
* ``` | ||
* @param query - [Query object](query-format) | ||
* @param options | ||
* @param callback | ||
* @returns {Promise} for {@link ResultSet} if `callback` isn't passed | ||
*/ | ||
load(query, options, callback) { | ||
@@ -92,2 +131,9 @@ return this.loadMethod( | ||
/** | ||
* Get generated SQL string for given `query`. | ||
* @param query - [Query object](query-format) | ||
* @param options | ||
* @param callback | ||
* @return {Promise} for {@link SqlQuery} if `callback` isn't passed | ||
*/ | ||
sql(query, options, callback) { | ||
@@ -102,2 +148,8 @@ return this.loadMethod( | ||
/** | ||
* Get meta description of cubes available for querying. | ||
* @param options | ||
* @param callback | ||
* @return {Promise} for {@link Meta} if `callback` isn't passed | ||
*/ | ||
meta(options, callback) { | ||
@@ -113,4 +165,25 @@ return this.loadMethod( | ||
/** | ||
* Create instance of `CubejsApi`. | ||
* API entry point. | ||
* | ||
* ```javascript | ||
import cubejs from '@cubejs-client/core'; | ||
const cubejsApi = cubejs( | ||
'CUBEJS-API-TOKEN', | ||
{ apiUrl: 'http://localhost:4000/cubejs-api/v1' } | ||
); | ||
``` | ||
* @name cubejs | ||
* @param apiToken - [API token](security) is used to authorize requests and determine SQL database you're accessing. | ||
* In the development mode, Cube.js Backend will print the API token to the console on on startup. | ||
* @param options - options object. | ||
* @param options.apiUrl - URL of your Cube.js Backend. | ||
* By default, in the development environment it is `http://localhost:4000/cubejs-api/v1`. | ||
* @returns {CubejsApi} | ||
* @order -10 | ||
*/ | ||
export default (apiToken, options) => { | ||
return new CubejsApi(apiToken, options); | ||
}; |
@@ -0,1 +1,5 @@ | ||
/** | ||
* @module @cubejs-client/core | ||
*/ | ||
import { | ||
@@ -22,3 +26,6 @@ groupBy, pipe, toPairs, uniq, filter, map, unnest, dropLast, equals, reduce, minBy, maxBy | ||
export default class ResultSet { | ||
/** | ||
* Provides a convenient interface for data manipulation. | ||
*/ | ||
class ResultSet { | ||
constructor(loadResponse) { | ||
@@ -195,2 +202,26 @@ this.loadResponse = loadResponse; | ||
/** | ||
* Returns normalized query result data in the following format. | ||
* | ||
* ```js | ||
* // For query | ||
* { | ||
* measures: ['Stories.count'], | ||
* timeDimensions: [{ | ||
* dimension: 'Stories.time', | ||
* dateRange: ['2015-01-01', '2015-12-31'], | ||
* granularity: 'month' | ||
* }] | ||
* } | ||
* | ||
* // ResultSet.chartPivot() will return | ||
* [ | ||
* { "x":"2015-01-01T00:00:00", "Stories.count": 27120 }, | ||
* { "x":"2015-02-01T00:00:00", "Stories.count": 25861 }, | ||
* { "x": "2015-03-01T00:00:00", "Stories.count": 29661 }, | ||
* //... | ||
* ] | ||
* ``` | ||
* @param pivotConfig | ||
*/ | ||
chartPivot(pivotConfig) { | ||
@@ -208,2 +239,29 @@ return this.pivot(pivotConfig).map(({ xValues, yValuesArray }) => ({ | ||
/** | ||
* Returns normalized query result data prepared for visualization in the table format. | ||
* | ||
* For example | ||
* | ||
* ```js | ||
* // For query | ||
* { | ||
* measures: ['Stories.count'], | ||
* timeDimensions: [{ | ||
* dimension: 'Stories.time', | ||
* dateRange: ['2015-01-01', '2015-12-31'], | ||
* granularity: 'month' | ||
* }] | ||
* } | ||
* | ||
* // ResultSet.tablePivot() will return | ||
* [ | ||
* { "Stories.time": "2015-01-01T00:00:00", "Stories.count": 27120 }, | ||
* { "Stories.time": "2015-02-01T00:00:00", "Stories.count": 25861 }, | ||
* { "Stories.time": "2015-03-01T00:00:00", "Stories.count": 29661 }, | ||
* //... | ||
* ] | ||
* ``` | ||
* @param pivotConfig | ||
* @returns {Array} of pivoted rows | ||
*/ | ||
tablePivot(pivotConfig) { | ||
@@ -227,2 +285,28 @@ const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig); | ||
/** | ||
* Returns array of column definitions for `tablePivot`. | ||
* | ||
* For example | ||
* | ||
* ```js | ||
* // For query | ||
* { | ||
* measures: ['Stories.count'], | ||
* timeDimensions: [{ | ||
* dimension: 'Stories.time', | ||
* dateRange: ['2015-01-01', '2015-12-31'], | ||
* granularity: 'month' | ||
* }] | ||
* } | ||
* | ||
* // ResultSet.tableColumns() will return | ||
* [ | ||
* { key: "Stories.time", title: "Stories Time" }, | ||
* { key: "Stories.count", title: "Stories Count" }, | ||
* //... | ||
* ] | ||
* ``` | ||
* @param pivotConfig | ||
* @returns {Array} of columns | ||
*/ | ||
tableColumns(pivotConfig) { | ||
@@ -254,2 +338,24 @@ const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig); | ||
/** | ||
* Returns the array of series objects, containing `key` and `title` parameters. | ||
* | ||
* ```js | ||
* // For query | ||
* { | ||
* measures: ['Stories.count'], | ||
* timeDimensions: [{ | ||
* dimension: 'Stories.time', | ||
* dateRange: ['2015-01-01', '2015-12-31'], | ||
* granularity: 'month' | ||
* }] | ||
* } | ||
* | ||
* // ResultSet.seriesNames() will return | ||
* [ | ||
* { "key":"Stories.count", "title": "Stories Count" } | ||
* ] | ||
* ``` | ||
* @param pivotConfig | ||
* @returns {Array} of series names | ||
*/ | ||
seriesNames(pivotConfig) { | ||
@@ -274,1 +380,3 @@ pivotConfig = this.normalizePivotConfig(pivotConfig); | ||
} | ||
export default ResultSet; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
540521
14995