@cubejs-client/core 0.34.37 → 0.35.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/dist/cubejs-client-core.esm.js +6 -4
- package/dist/cubejs-client-core.esm.js.map +1 -1
- package/dist/cubejs-client-core.js +10 -9
- package/dist/cubejs-client-core.js.map +1 -1
- package/dist/cubejs-client-core.umd.js +14 -13
- package/dist/cubejs-client-core.umd.js.map +1 -1
- package/index.d.ts +17 -17
- package/package.json +2 -2
- package/src/index.js +3 -3
- package/src/index.test.js +15 -15
- package/src/index.umd.js +3 -3
- package/src/utils.js +7 -0
package/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ declare module '@cubejs-client/core' {
|
|
|
66
66
|
public request(method: string, params: any): ITransportResponse<ResultSet>;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export type
|
|
69
|
+
export type CubeApiOptions = {
|
|
70
70
|
/**
|
|
71
71
|
* URL of your Cube.js Backend. By default, in the development environment it is `http://localhost:4000/cubejs-api/v1`
|
|
72
72
|
*/
|
|
@@ -98,7 +98,7 @@ declare module '@cubejs-client/core' {
|
|
|
98
98
|
/**
|
|
99
99
|
* A Cube API instance. If not provided will be taken from `CubeProvider`
|
|
100
100
|
*/
|
|
101
|
-
|
|
101
|
+
cubeApi?: CubeApi;
|
|
102
102
|
/**
|
|
103
103
|
* If enabled, all members of the 'number' type will be automatically converted to numerical values on the client side
|
|
104
104
|
*/
|
|
@@ -324,7 +324,7 @@ declare module '@cubejs-client/core' {
|
|
|
324
324
|
* ```js
|
|
325
325
|
* import { ResultSet } from '@cubejs-client/core';
|
|
326
326
|
*
|
|
327
|
-
* const resultSet = await
|
|
327
|
+
* const resultSet = await cubeApi.load(query);
|
|
328
328
|
* // You can store the result somewhere
|
|
329
329
|
* const tmp = resultSet.serialize();
|
|
330
330
|
*
|
|
@@ -1072,11 +1072,11 @@ declare module '@cubejs-client/core' {
|
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
1074
1074
|
/**
|
|
1075
|
-
* Main class for accessing Cube
|
|
1075
|
+
* Main class for accessing Cube API
|
|
1076
1076
|
*
|
|
1077
1077
|
* @order 2
|
|
1078
1078
|
*/
|
|
1079
|
-
export class
|
|
1079
|
+
export class CubeApi {
|
|
1080
1080
|
load<QueryType extends DeeplyReadonly<Query | Query[]>>(
|
|
1081
1081
|
query: QueryType,
|
|
1082
1082
|
options?: LoadMethodOptions,
|
|
@@ -1085,13 +1085,13 @@ declare module '@cubejs-client/core' {
|
|
|
1085
1085
|
* Fetch data for the passed `query`.
|
|
1086
1086
|
*
|
|
1087
1087
|
* ```js
|
|
1088
|
-
* import
|
|
1088
|
+
* import cube from '@cubejs-client/core';
|
|
1089
1089
|
* import Chart from 'chart.js';
|
|
1090
1090
|
* import chartjsConfig from './toChartjsData';
|
|
1091
1091
|
*
|
|
1092
|
-
* const
|
|
1092
|
+
* const cubeApi = cube('CUBEJS_TOKEN');
|
|
1093
1093
|
*
|
|
1094
|
-
* const resultSet = await
|
|
1094
|
+
* const resultSet = await cubeApi.load({
|
|
1095
1095
|
* measures: ['Stories.count'],
|
|
1096
1096
|
* timeDimensions: [{
|
|
1097
1097
|
* dimension: 'Stories.time',
|
|
@@ -1123,7 +1123,7 @@ declare module '@cubejs-client/core' {
|
|
|
1123
1123
|
*
|
|
1124
1124
|
* ```js
|
|
1125
1125
|
* // Subscribe to a query's updates
|
|
1126
|
-
* const subscription = await
|
|
1126
|
+
* const subscription = await cubeApi.subscribe(
|
|
1127
1127
|
* {
|
|
1128
1128
|
* measures: ['Logs.count'],
|
|
1129
1129
|
* timeDimensions: [
|
|
@@ -1173,12 +1173,12 @@ declare module '@cubejs-client/core' {
|
|
|
1173
1173
|
}
|
|
1174
1174
|
|
|
1175
1175
|
/**
|
|
1176
|
-
* Creates an instance of the `
|
|
1176
|
+
* Creates an instance of the `CubeApi`. The API entry point.
|
|
1177
1177
|
*
|
|
1178
1178
|
* ```js
|
|
1179
|
-
* import
|
|
1180
|
-
* const
|
|
1181
|
-
* '
|
|
1179
|
+
* import cube from '@cubejs-client/core';
|
|
1180
|
+
* const cubeApi = cube(
|
|
1181
|
+
* 'CUBE-API-TOKEN',
|
|
1182
1182
|
* { apiUrl: 'http://localhost:4000/cubejs-api/v1' }
|
|
1183
1183
|
* );
|
|
1184
1184
|
* ```
|
|
@@ -1186,8 +1186,8 @@ declare module '@cubejs-client/core' {
|
|
|
1186
1186
|
* You can also pass an async function or a promise that will resolve to the API token
|
|
1187
1187
|
*
|
|
1188
1188
|
* ```js
|
|
1189
|
-
* import
|
|
1190
|
-
* const
|
|
1189
|
+
* import cube from '@cubejs-client/core';
|
|
1190
|
+
* const cubeApi = cube(
|
|
1191
1191
|
* async () => await Auth.getJwtToken(),
|
|
1192
1192
|
* { apiUrl: 'http://localhost:4000/cubejs-api/v1' }
|
|
1193
1193
|
* );
|
|
@@ -1196,8 +1196,8 @@ declare module '@cubejs-client/core' {
|
|
|
1196
1196
|
* @param apiToken - [API token](/product/auth) 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 startup. In case of async function `authorization` is updated for `options.transport` on each request.
|
|
1197
1197
|
* @order 1
|
|
1198
1198
|
*/
|
|
1199
|
-
export default function
|
|
1200
|
-
export default function
|
|
1199
|
+
export default function cube(apiToken: string | (() => Promise<string>), options: CubeApiOptions): CubeApi;
|
|
1200
|
+
export default function cube(options: CubeApiOptions): CubeApi;
|
|
1201
1201
|
|
|
1202
1202
|
/**
|
|
1203
1203
|
* @hidden
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubejs-client/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.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": "
|
|
48
|
+
"gitHead": "75bc6c3d96392b7823e714d17ac85ab435e55b05"
|
|
49
49
|
}
|
package/src/index.js
CHANGED
|
@@ -30,7 +30,7 @@ function mutexPromise(promise) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
class
|
|
33
|
+
class CubeApi {
|
|
34
34
|
constructor(apiToken, options) {
|
|
35
35
|
if (apiToken !== null && !Array.isArray(apiToken) && typeof apiToken === 'object') {
|
|
36
36
|
options = apiToken;
|
|
@@ -373,7 +373,7 @@ class CubejsApi {
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
-
export default (apiToken, options) => new
|
|
376
|
+
export default (apiToken, options) => new CubeApi(apiToken, options);
|
|
377
377
|
|
|
378
|
-
export {
|
|
378
|
+
export { CubeApi, HttpTransport, ResultSet, RequestError, Meta };
|
|
379
379
|
export * from './utils';
|
package/src/index.test.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license Apache-2.0
|
|
3
3
|
* @copyright Cube Dev, Inc.
|
|
4
|
-
* @fileoverview
|
|
4
|
+
* @fileoverview CubeApi class unit tests.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/* globals describe,test,expect,beforeEach,jest */
|
|
8
8
|
|
|
9
9
|
import ResultSet from './ResultSet';
|
|
10
|
-
import {
|
|
10
|
+
import { CubeApi } from './index';
|
|
11
11
|
|
|
12
12
|
jest.mock('./ResultSet');
|
|
13
13
|
beforeEach(() => {
|
|
@@ -203,9 +203,9 @@ const mockData = {
|
|
|
203
203
|
}],
|
|
204
204
|
};
|
|
205
205
|
|
|
206
|
-
describe('
|
|
207
|
-
test('
|
|
208
|
-
const api = new
|
|
206
|
+
describe('CubeApi', () => {
|
|
207
|
+
test('CubeApi#loadResponseInternal should work with the "default" resType for regular query', () => {
|
|
208
|
+
const api = new CubeApi(undefined, {
|
|
209
209
|
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
210
210
|
});
|
|
211
211
|
const income = {
|
|
@@ -236,8 +236,8 @@ describe('CubejsApi', () => {
|
|
|
236
236
|
});
|
|
237
237
|
});
|
|
238
238
|
|
|
239
|
-
test('
|
|
240
|
-
const api = new
|
|
239
|
+
test('CubeApi#loadResponseInternal should work with the "default" resType for compare date range query', () => {
|
|
240
|
+
const api = new CubeApi(undefined, {
|
|
241
241
|
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
242
242
|
});
|
|
243
243
|
const income = {
|
|
@@ -282,8 +282,8 @@ describe('CubejsApi', () => {
|
|
|
282
282
|
});
|
|
283
283
|
});
|
|
284
284
|
|
|
285
|
-
test('
|
|
286
|
-
const api = new
|
|
285
|
+
test('CubeApi#loadResponseInternal should work with the "default" resType for blending query', () => {
|
|
286
|
+
const api = new CubeApi(undefined, {
|
|
287
287
|
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
288
288
|
});
|
|
289
289
|
const income = {
|
|
@@ -328,8 +328,8 @@ describe('CubejsApi', () => {
|
|
|
328
328
|
});
|
|
329
329
|
});
|
|
330
330
|
|
|
331
|
-
test('
|
|
332
|
-
const api = new
|
|
331
|
+
test('CubeApi#loadResponseInternal should work with the "compact" resType for regular query', () => {
|
|
332
|
+
const api = new CubeApi(undefined, {
|
|
333
333
|
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
334
334
|
});
|
|
335
335
|
const income = {
|
|
@@ -360,8 +360,8 @@ describe('CubejsApi', () => {
|
|
|
360
360
|
});
|
|
361
361
|
});
|
|
362
362
|
|
|
363
|
-
test('
|
|
364
|
-
const api = new
|
|
363
|
+
test('CubeApi#loadResponseInternal should work with the "compact" resType for compare date range query', () => {
|
|
364
|
+
const api = new CubeApi(undefined, {
|
|
365
365
|
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
366
366
|
});
|
|
367
367
|
const income = {
|
|
@@ -406,8 +406,8 @@ describe('CubejsApi', () => {
|
|
|
406
406
|
});
|
|
407
407
|
});
|
|
408
408
|
|
|
409
|
-
test('
|
|
410
|
-
const api = new
|
|
409
|
+
test('CubeApi#loadResponseInternal should work with the "compact" resType for blending query', () => {
|
|
410
|
+
const api = new CubeApi(undefined, {
|
|
411
411
|
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
412
412
|
});
|
|
413
413
|
const income = {
|
package/src/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cube from './index';
|
|
2
2
|
import * as clientCoreExports from './index';
|
|
3
3
|
|
|
4
4
|
Object.keys(clientCoreExports).forEach((key) => {
|
|
5
|
-
|
|
5
|
+
cube[key] = clientCoreExports[key];
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
export default
|
|
8
|
+
export default cube;
|
package/src/utils.js
CHANGED
|
@@ -288,10 +288,17 @@ export function movePivotItem(
|
|
|
288
288
|
if (id === 'measures') {
|
|
289
289
|
destinationIndex = lastIndex + 1;
|
|
290
290
|
} else if (
|
|
291
|
+
sourceAxis === destinationAxis &&
|
|
291
292
|
destinationIndex >= lastIndex &&
|
|
292
293
|
nextPivotConfig[destinationAxis][lastIndex] === 'measures'
|
|
293
294
|
) {
|
|
294
295
|
destinationIndex = lastIndex - 1;
|
|
296
|
+
} else if (
|
|
297
|
+
sourceAxis !== destinationAxis &&
|
|
298
|
+
destinationIndex > lastIndex &&
|
|
299
|
+
nextPivotConfig[destinationAxis][lastIndex] === 'measures'
|
|
300
|
+
) {
|
|
301
|
+
destinationIndex = lastIndex;
|
|
295
302
|
}
|
|
296
303
|
|
|
297
304
|
nextPivotConfig[sourceAxis].splice(sourceIndex, 1);
|