@cubejs-client/core 0.29.23 → 0.29.29
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 +11 -0
- package/dist/cubejs-client-core.esm.js +120 -30
- package/dist/cubejs-client-core.esm.js.map +1 -1
- package/dist/cubejs-client-core.js +120 -30
- package/dist/cubejs-client-core.js.map +1 -1
- package/dist/cubejs-client-core.umd.js +152 -57
- package/dist/cubejs-client-core.umd.js.map +1 -1
- package/index.d.ts +13 -2
- package/package.json +3 -2
- package/src/index.js +117 -18
- package/src/index.test.js +454 -0
- package/src/tests/ResultSet.test.js +8 -0
package/index.d.ts
CHANGED
|
@@ -27,13 +27,21 @@ declare module '@cubejs-client/core' {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export interface ITransportResponse<R> {
|
|
30
|
-
subscribe: <CBResult>(
|
|
30
|
+
subscribe: <CBResult>(
|
|
31
|
+
cb: (
|
|
32
|
+
result: R,
|
|
33
|
+
resubscribe: () => Promise<CBResult>
|
|
34
|
+
) => CBResult
|
|
35
|
+
) => Promise<CBResult>;
|
|
31
36
|
// Optional, supported in WebSocketTransport
|
|
32
37
|
unsubscribe?: () => Promise<void>;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
export interface ITransport<R> {
|
|
36
|
-
request(
|
|
41
|
+
request(
|
|
42
|
+
method: string,
|
|
43
|
+
params: Record<string, unknown>
|
|
44
|
+
): ITransportResponse<R>;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
/**
|
|
@@ -80,6 +88,7 @@ declare module '@cubejs-client/core' {
|
|
|
80
88
|
pollInterval?: number;
|
|
81
89
|
credentials?: 'omit' | 'same-origin' | 'include';
|
|
82
90
|
parseDateMeasures?: boolean;
|
|
91
|
+
resType?: 'default' | 'compact';
|
|
83
92
|
};
|
|
84
93
|
|
|
85
94
|
export type LoadMethodOptions = {
|
|
@@ -790,6 +799,7 @@ declare module '@cubejs-client/core' {
|
|
|
790
799
|
timezone?: string;
|
|
791
800
|
renewQuery?: boolean;
|
|
792
801
|
ungrouped?: boolean;
|
|
802
|
+
responseFormat?: 'compact' | 'default'
|
|
793
803
|
}
|
|
794
804
|
|
|
795
805
|
export class ProgressResult {
|
|
@@ -993,6 +1003,7 @@ declare module '@cubejs-client/core' {
|
|
|
993
1003
|
* @param query - [Query object](query-format)
|
|
994
1004
|
*/
|
|
995
1005
|
load(query: Query | Query[], options?: LoadMethodOptions, callback?: LoadMethodCallback<ResultSet>): void;
|
|
1006
|
+
load(query: Query | Query[], options?: LoadMethodOptions, callback?: LoadMethodCallback<ResultSet>, responseFormat?: string): Promise<ResultSet>;
|
|
996
1007
|
|
|
997
1008
|
/**
|
|
998
1009
|
* Allows you to fetch data and receive updates over time. See [Real-Time Data Fetch](real-time-data-fetch)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubejs-client/core",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.29",
|
|
4
4
|
"engines": {},
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"author": "Cube Dev, Inc.",
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
16
17
|
"@babel/runtime": "^7.1.2",
|
|
17
18
|
"core-js": "^3.6.5",
|
|
18
19
|
"cross-fetch": "^3.0.2",
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"eslint-plugin-node": "^5.2.1",
|
|
46
47
|
"jest": "^26.0.1"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "23638ee42cceb8fc80e821486ab30825e2b9a483"
|
|
49
50
|
}
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,14 @@ let mutexCounter = 0;
|
|
|
10
10
|
|
|
11
11
|
const MUTEX_ERROR = 'Mutex has been changed';
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Query result dataset formats enum.
|
|
15
|
+
*/
|
|
16
|
+
const ResultType = {
|
|
17
|
+
DEFAULT: 'default',
|
|
18
|
+
COMPACT: 'compact'
|
|
19
|
+
};
|
|
20
|
+
|
|
13
21
|
function mutexPromise(promise) {
|
|
14
22
|
return new Promise(async (resolve, reject) => {
|
|
15
23
|
try {
|
|
@@ -53,7 +61,10 @@ class CubejsApi {
|
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
request(method, params) {
|
|
56
|
-
return this.transport.request(method, {
|
|
64
|
+
return this.transport.request(method, {
|
|
65
|
+
baseRequestId: uuidv4(),
|
|
66
|
+
...params
|
|
67
|
+
});
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
loadMethod(request, toResult, options, callback) {
|
|
@@ -70,7 +81,9 @@ class CubejsApi {
|
|
|
70
81
|
options.mutexObj[mutexKey] = mutexValue;
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
const requestPromise = this
|
|
84
|
+
const requestPromise = this
|
|
85
|
+
.updateTransportAuthorization()
|
|
86
|
+
.then(() => request());
|
|
74
87
|
|
|
75
88
|
let skipAuthorizationUpdate = true;
|
|
76
89
|
let unsubscribed = false;
|
|
@@ -78,7 +91,10 @@ class CubejsApi {
|
|
|
78
91
|
const checkMutex = async () => {
|
|
79
92
|
const requestInstance = await requestPromise;
|
|
80
93
|
|
|
81
|
-
if (
|
|
94
|
+
if (
|
|
95
|
+
options.mutexObj &&
|
|
96
|
+
options.mutexObj[mutexKey] !== mutexValue
|
|
97
|
+
) {
|
|
82
98
|
unsubscribed = true;
|
|
83
99
|
if (requestInstance.unsubscribe) {
|
|
84
100
|
await requestInstance.unsubscribe();
|
|
@@ -213,18 +229,113 @@ class CubejsApi {
|
|
|
213
229
|
}
|
|
214
230
|
}
|
|
215
231
|
|
|
216
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Add system properties to a query object.
|
|
234
|
+
* @param {Query} query
|
|
235
|
+
* @param {string} responseFormat
|
|
236
|
+
* @returns {void}
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
patchQueryInternal(query, responseFormat) {
|
|
240
|
+
if (
|
|
241
|
+
responseFormat === ResultType.COMPACT &&
|
|
242
|
+
query.responseFormat !== ResultType.COMPACT
|
|
243
|
+
) {
|
|
244
|
+
query.responseFormat = ResultType.COMPACT;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Process result fetched from the gateway#load method according
|
|
250
|
+
* to the network protocol.
|
|
251
|
+
* @param {*} response
|
|
252
|
+
* @returns ResultSet
|
|
253
|
+
* @private
|
|
254
|
+
*/
|
|
255
|
+
loadResponseInternal(response) {
|
|
256
|
+
if (
|
|
257
|
+
response.results.length &&
|
|
258
|
+
response.results[0].query.responseFormat &&
|
|
259
|
+
response.results[0].query.responseFormat === ResultType.COMPACT
|
|
260
|
+
) {
|
|
261
|
+
response.results.forEach((result, j) => {
|
|
262
|
+
const data = [];
|
|
263
|
+
result.data.dataset.forEach((r) => {
|
|
264
|
+
const row = {};
|
|
265
|
+
result.data.members.forEach((m, i) => {
|
|
266
|
+
row[m] = r[i];
|
|
267
|
+
});
|
|
268
|
+
data.push(row);
|
|
269
|
+
});
|
|
270
|
+
response.results[j].data = data;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return new ResultSet(response, {
|
|
274
|
+
parseDateMeasures: this.parseDateMeasures
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Fetch data for the passed `query`. Operates with the
|
|
280
|
+
* `ApiGateway#load` method to fetch the data.
|
|
281
|
+
* @param {Query | Query[]} query
|
|
282
|
+
* @param {LoadMethodOptions | undefined} options
|
|
283
|
+
* @param {LoadMethodCallback<ResultSet> | undefined} callback
|
|
284
|
+
* @param {string} responseFormat
|
|
285
|
+
* @returns {undefined | Promise<ResultSet>}
|
|
286
|
+
*/
|
|
287
|
+
load(query, options, callback, responseFormat = ResultType.DEFAULT) {
|
|
288
|
+
if (responseFormat === ResultType.COMPACT) {
|
|
289
|
+
if (Array.isArray(query)) {
|
|
290
|
+
query.forEach((q) => {
|
|
291
|
+
this.patchQueryInternal(q, ResultType.COMPACT);
|
|
292
|
+
});
|
|
293
|
+
} else {
|
|
294
|
+
this.patchQueryInternal(query, ResultType.COMPACT);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
217
297
|
return this.loadMethod(
|
|
218
298
|
() => this.request('load', {
|
|
219
299
|
query,
|
|
220
|
-
queryType: 'multi'
|
|
300
|
+
queryType: 'multi',
|
|
221
301
|
}),
|
|
222
|
-
(
|
|
302
|
+
this.loadResponseInternal.bind(this),
|
|
223
303
|
options,
|
|
224
304
|
callback
|
|
225
305
|
);
|
|
226
306
|
}
|
|
227
307
|
|
|
308
|
+
/**
|
|
309
|
+
* Allows you to fetch data and receive updates over time. Operates
|
|
310
|
+
* with the `ApiGateway#load` method to fetch the data.
|
|
311
|
+
* @link real-time-data-fetch
|
|
312
|
+
* @param {Query | Query[]} query
|
|
313
|
+
* @param {LoadMethodOptions | null} options
|
|
314
|
+
* @param {LoadMethodCallback<ResultSet> | undefined} callback
|
|
315
|
+
* @param {string} responseFormat
|
|
316
|
+
* @returns {void}
|
|
317
|
+
*/
|
|
318
|
+
subscribe(query, options, callback, responseFormat = ResultType.DEFAULT) {
|
|
319
|
+
if (responseFormat === ResultType.COMPACT) {
|
|
320
|
+
if (Array.isArray(query)) {
|
|
321
|
+
query.forEach((q) => {
|
|
322
|
+
this.patchQueryInternal(q, ResultType.COMPACT);
|
|
323
|
+
});
|
|
324
|
+
} else {
|
|
325
|
+
this.patchQueryInternal(query, ResultType.COMPACT);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return this.loadMethod(
|
|
329
|
+
() => this.request('subscribe', {
|
|
330
|
+
query,
|
|
331
|
+
queryType: 'multi',
|
|
332
|
+
}),
|
|
333
|
+
this.loadResponseInternal.bind(this),
|
|
334
|
+
{ ...options, subscribe: true },
|
|
335
|
+
callback
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
228
339
|
sql(query, options, callback) {
|
|
229
340
|
return this.loadMethod(
|
|
230
341
|
() => this.request('sql', { query }),
|
|
@@ -251,18 +362,6 @@ class CubejsApi {
|
|
|
251
362
|
callback
|
|
252
363
|
);
|
|
253
364
|
}
|
|
254
|
-
|
|
255
|
-
subscribe(query, options, callback) {
|
|
256
|
-
return this.loadMethod(
|
|
257
|
-
() => this.request('subscribe', {
|
|
258
|
-
query,
|
|
259
|
-
queryType: 'multi'
|
|
260
|
-
}),
|
|
261
|
-
(body) => new ResultSet(body, { parseDateMeasures: this.parseDateMeasures }),
|
|
262
|
-
{ ...options, subscribe: true },
|
|
263
|
-
callback
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
365
|
}
|
|
267
366
|
|
|
268
367
|
export default (apiToken, options) => new CubejsApi(apiToken, options);
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
* @copyright Cube Dev, Inc.
|
|
4
|
+
* @fileoverview CubejsApi class unit tests.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* globals describe,test,expect,beforeEach,jest */
|
|
8
|
+
|
|
9
|
+
import ResultSet from './ResultSet';
|
|
10
|
+
import { CubejsApi } from './index';
|
|
11
|
+
|
|
12
|
+
jest.mock('./ResultSet');
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
ResultSet.mockClear();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const mockData = {
|
|
18
|
+
regular_1: {
|
|
19
|
+
result_default: [
|
|
20
|
+
{
|
|
21
|
+
'ECommerceRecordsUs2021.city': 'Missouri City',
|
|
22
|
+
'ECommerceRecordsUs2021.avg_discount': '0.80000000000000000000'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
'ECommerceRecordsUs2021.city': 'Abilene',
|
|
26
|
+
'ECommerceRecordsUs2021.avg_discount': '0.80000000000000000000'
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
result_compact: {
|
|
30
|
+
members: ['ECommerceRecordsUs2021.city', 'ECommerceRecordsUs2021.avg_discount'],
|
|
31
|
+
dataset: [['Missouri City', '0.80000000000000000000'], ['Abilene', '0.80000000000000000000']],
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
regular_2: {
|
|
35
|
+
result_default: [
|
|
36
|
+
{
|
|
37
|
+
'ECommerceRecordsUs2021.postalCode': '95823',
|
|
38
|
+
'ECommerceRecordsUs2021.avg_profit': '646.1258666666666667'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
'ECommerceRecordsUs2021.postalCode': '64055',
|
|
42
|
+
'ECommerceRecordsUs2021.avg_profit': '487.8315000000000000'
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
result_compact: {
|
|
46
|
+
members: [
|
|
47
|
+
'ECommerceRecordsUs2021.postalCode',
|
|
48
|
+
'ECommerceRecordsUs2021.avg_profit',
|
|
49
|
+
],
|
|
50
|
+
dataset: [
|
|
51
|
+
['95823', '646.1258666666666667'],
|
|
52
|
+
['64055', '487.8315000000000000']
|
|
53
|
+
],
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
compare: [{
|
|
57
|
+
result_default: [
|
|
58
|
+
{
|
|
59
|
+
'ECommerceRecordsUs2021.orderDate.day': '2020-01-01T00:00:00.000',
|
|
60
|
+
'ECommerceRecordsUs2021.orderDate': '2020-01-01T00:00:00.000',
|
|
61
|
+
'ECommerceRecordsUs2021.count': '10',
|
|
62
|
+
compareDateRange: '2020-01-01T00:00:00.000 - 2020-01-31T23:59:59.999'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
'ECommerceRecordsUs2021.orderDate.day': '2020-01-02T00:00:00.000',
|
|
66
|
+
'ECommerceRecordsUs2021.orderDate': '2020-01-02T00:00:00.000',
|
|
67
|
+
'ECommerceRecordsUs2021.count': '8',
|
|
68
|
+
compareDateRange: '2020-01-01T00:00:00.000 - 2020-01-31T23:59:59.999'
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
result_compact: {
|
|
72
|
+
members: [
|
|
73
|
+
'ECommerceRecordsUs2021.orderDate.day',
|
|
74
|
+
'ECommerceRecordsUs2021.orderDate',
|
|
75
|
+
'ECommerceRecordsUs2021.count',
|
|
76
|
+
'compareDateRange',
|
|
77
|
+
],
|
|
78
|
+
dataset: [
|
|
79
|
+
[
|
|
80
|
+
'2020-01-01T00:00:00.000',
|
|
81
|
+
'2020-01-01T00:00:00.000',
|
|
82
|
+
'10',
|
|
83
|
+
'2020-01-01T00:00:00.000 - 2020-01-31T23:59:59.999',
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
'2020-01-02T00:00:00.000',
|
|
87
|
+
'2020-01-02T00:00:00.000',
|
|
88
|
+
'8',
|
|
89
|
+
'2020-01-01T00:00:00.000 - 2020-01-31T23:59:59.999'
|
|
90
|
+
],
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
}, {
|
|
94
|
+
result_default: [
|
|
95
|
+
{
|
|
96
|
+
'ECommerceRecordsUs2021.orderDate.day': '2020-03-02T00:00:00.000',
|
|
97
|
+
'ECommerceRecordsUs2021.orderDate': '2020-03-02T00:00:00.000',
|
|
98
|
+
'ECommerceRecordsUs2021.count': '11',
|
|
99
|
+
compareDateRange: '2020-03-01T00:00:00.000 - 2020-03-31T23:59:59.999'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
'ECommerceRecordsUs2021.orderDate.day': '2020-03-03T00:00:00.000',
|
|
103
|
+
'ECommerceRecordsUs2021.orderDate': '2020-03-03T00:00:00.000',
|
|
104
|
+
'ECommerceRecordsUs2021.count': '7',
|
|
105
|
+
compareDateRange: '2020-03-01T00:00:00.000 - 2020-03-31T23:59:59.999'
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
result_compact: {
|
|
109
|
+
members: [
|
|
110
|
+
'ECommerceRecordsUs2021.orderDate.day',
|
|
111
|
+
'ECommerceRecordsUs2021.orderDate',
|
|
112
|
+
'ECommerceRecordsUs2021.count',
|
|
113
|
+
'compareDateRange',
|
|
114
|
+
],
|
|
115
|
+
dataset: [
|
|
116
|
+
[
|
|
117
|
+
'2020-03-02T00:00:00.000',
|
|
118
|
+
'2020-03-02T00:00:00.000',
|
|
119
|
+
'11',
|
|
120
|
+
'2020-03-01T00:00:00.000 - 2020-03-31T23:59:59.999',
|
|
121
|
+
],
|
|
122
|
+
[
|
|
123
|
+
'2020-03-03T00:00:00.000',
|
|
124
|
+
'2020-03-03T00:00:00.000',
|
|
125
|
+
'7',
|
|
126
|
+
'2020-03-01T00:00:00.000 - 2020-03-31T23:59:59.999'
|
|
127
|
+
],
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
}],
|
|
131
|
+
blending: [{
|
|
132
|
+
result_default: [
|
|
133
|
+
{
|
|
134
|
+
'ECommerceRecordsUs2021.orderDate.month': '2020-01-01T00:00:00.000',
|
|
135
|
+
'ECommerceRecordsUs2021.orderDate': '2020-01-01T00:00:00.000',
|
|
136
|
+
'ECommerceRecordsUs2021.avg_discount': '0.15638297872340425532',
|
|
137
|
+
'time.month': '2020-01-01T00:00:00.000'
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
'ECommerceRecordsUs2021.orderDate.month': '2020-02-01T00:00:00.000',
|
|
141
|
+
'ECommerceRecordsUs2021.orderDate': '2020-02-01T00:00:00.000',
|
|
142
|
+
'ECommerceRecordsUs2021.avg_discount': '0.17573529411764705882',
|
|
143
|
+
'time.month': '2020-02-01T00:00:00.000'
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
result_compact: {
|
|
147
|
+
members: [
|
|
148
|
+
'ECommerceRecordsUs2021.orderDate.month',
|
|
149
|
+
'ECommerceRecordsUs2021.orderDate',
|
|
150
|
+
'ECommerceRecordsUs2021.avg_discount',
|
|
151
|
+
'time.month',
|
|
152
|
+
],
|
|
153
|
+
dataset: [
|
|
154
|
+
[
|
|
155
|
+
'2020-01-01T00:00:00.000',
|
|
156
|
+
'2020-01-01T00:00:00.000',
|
|
157
|
+
'0.15638297872340425532',
|
|
158
|
+
'2020-01-01T00:00:00.000',
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
'2020-02-01T00:00:00.000',
|
|
162
|
+
'2020-02-01T00:00:00.000',
|
|
163
|
+
'0.17573529411764705882',
|
|
164
|
+
'2020-02-01T00:00:00.000',
|
|
165
|
+
],
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
}, {
|
|
169
|
+
result_default: [{
|
|
170
|
+
'ECommerceRecordsUs2021.orderDate.month': '2020-01-01T00:00:00.000',
|
|
171
|
+
'ECommerceRecordsUs2021.orderDate': '2020-01-01T00:00:00.000',
|
|
172
|
+
'ECommerceRecordsUs2021.avg_discount': '0.28571428571428571429',
|
|
173
|
+
'time.month': '2020-01-01T00:00:00.000'
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
'ECommerceRecordsUs2021.orderDate.month': '2020-02-01T00:00:00.000',
|
|
177
|
+
'ECommerceRecordsUs2021.orderDate': '2020-02-01T00:00:00.000',
|
|
178
|
+
'ECommerceRecordsUs2021.avg_discount': '0.21777777777777777778',
|
|
179
|
+
'time.month': '2020-02-01T00:00:00.000'
|
|
180
|
+
}],
|
|
181
|
+
result_compact: {
|
|
182
|
+
members: [
|
|
183
|
+
'ECommerceRecordsUs2021.orderDate.month',
|
|
184
|
+
'ECommerceRecordsUs2021.orderDate',
|
|
185
|
+
'ECommerceRecordsUs2021.avg_discount',
|
|
186
|
+
'time.month',
|
|
187
|
+
],
|
|
188
|
+
dataset: [
|
|
189
|
+
[
|
|
190
|
+
'2020-01-01T00:00:00.000',
|
|
191
|
+
'2020-01-01T00:00:00.000',
|
|
192
|
+
'0.28571428571428571429',
|
|
193
|
+
'2020-01-01T00:00:00.000',
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
'2020-02-01T00:00:00.000',
|
|
197
|
+
'2020-02-01T00:00:00.000',
|
|
198
|
+
'0.21777777777777777778',
|
|
199
|
+
'2020-02-01T00:00:00.000',
|
|
200
|
+
],
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
}],
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
describe('CubejsApi', () => {
|
|
207
|
+
test('CubejsApi#loadResponseInternal should work with the "default" resType for regular query', () => {
|
|
208
|
+
const api = new CubejsApi(undefined, {
|
|
209
|
+
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
210
|
+
});
|
|
211
|
+
const income = {
|
|
212
|
+
results: [{
|
|
213
|
+
query: {},
|
|
214
|
+
data: JSON.parse(
|
|
215
|
+
JSON.stringify(
|
|
216
|
+
mockData.regular_1.result_default
|
|
217
|
+
)
|
|
218
|
+
)
|
|
219
|
+
}],
|
|
220
|
+
};
|
|
221
|
+
const outcome = {
|
|
222
|
+
results: [{
|
|
223
|
+
query: {},
|
|
224
|
+
data: JSON.parse(
|
|
225
|
+
JSON.stringify(
|
|
226
|
+
mockData.regular_1.result_default
|
|
227
|
+
)
|
|
228
|
+
)
|
|
229
|
+
}],
|
|
230
|
+
};
|
|
231
|
+
api.loadResponseInternal(income);
|
|
232
|
+
expect(ResultSet).toHaveBeenCalled();
|
|
233
|
+
expect(ResultSet).toHaveBeenCalledTimes(1);
|
|
234
|
+
expect(ResultSet).toHaveBeenCalledWith(outcome, {
|
|
235
|
+
parseDateMeasures: undefined
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('CubejsApi#loadResponseInternal should work with the "default" resType for compare date range query', () => {
|
|
240
|
+
const api = new CubejsApi(undefined, {
|
|
241
|
+
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
242
|
+
});
|
|
243
|
+
const income = {
|
|
244
|
+
results: [{
|
|
245
|
+
query: {},
|
|
246
|
+
data: JSON.parse(
|
|
247
|
+
JSON.stringify(
|
|
248
|
+
mockData.compare[0].result_default
|
|
249
|
+
)
|
|
250
|
+
)
|
|
251
|
+
}, {
|
|
252
|
+
query: {},
|
|
253
|
+
data: JSON.parse(
|
|
254
|
+
JSON.stringify(
|
|
255
|
+
mockData.compare[1].result_default
|
|
256
|
+
)
|
|
257
|
+
)
|
|
258
|
+
}],
|
|
259
|
+
};
|
|
260
|
+
const outcome = {
|
|
261
|
+
results: [{
|
|
262
|
+
query: {},
|
|
263
|
+
data: JSON.parse(
|
|
264
|
+
JSON.stringify(
|
|
265
|
+
mockData.compare[0].result_default
|
|
266
|
+
)
|
|
267
|
+
)
|
|
268
|
+
}, {
|
|
269
|
+
query: {},
|
|
270
|
+
data: JSON.parse(
|
|
271
|
+
JSON.stringify(
|
|
272
|
+
mockData.compare[1].result_default
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
}],
|
|
276
|
+
};
|
|
277
|
+
api.loadResponseInternal(income);
|
|
278
|
+
expect(ResultSet).toHaveBeenCalled();
|
|
279
|
+
expect(ResultSet).toHaveBeenCalledTimes(1);
|
|
280
|
+
expect(ResultSet).toHaveBeenCalledWith(outcome, {
|
|
281
|
+
parseDateMeasures: undefined
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('CubejsApi#loadResponseInternal should work with the "default" resType for blending query', () => {
|
|
286
|
+
const api = new CubejsApi(undefined, {
|
|
287
|
+
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
288
|
+
});
|
|
289
|
+
const income = {
|
|
290
|
+
results: [{
|
|
291
|
+
query: {},
|
|
292
|
+
data: JSON.parse(
|
|
293
|
+
JSON.stringify(
|
|
294
|
+
mockData.blending[0].result_default
|
|
295
|
+
)
|
|
296
|
+
)
|
|
297
|
+
}, {
|
|
298
|
+
query: {},
|
|
299
|
+
data: JSON.parse(
|
|
300
|
+
JSON.stringify(
|
|
301
|
+
mockData.blending[1].result_default
|
|
302
|
+
)
|
|
303
|
+
)
|
|
304
|
+
}],
|
|
305
|
+
};
|
|
306
|
+
const outcome = {
|
|
307
|
+
results: [{
|
|
308
|
+
query: {},
|
|
309
|
+
data: JSON.parse(
|
|
310
|
+
JSON.stringify(
|
|
311
|
+
mockData.blending[0].result_default
|
|
312
|
+
)
|
|
313
|
+
)
|
|
314
|
+
}, {
|
|
315
|
+
query: {},
|
|
316
|
+
data: JSON.parse(
|
|
317
|
+
JSON.stringify(
|
|
318
|
+
mockData.blending[1].result_default
|
|
319
|
+
)
|
|
320
|
+
)
|
|
321
|
+
}],
|
|
322
|
+
};
|
|
323
|
+
api.loadResponseInternal(income);
|
|
324
|
+
expect(ResultSet).toHaveBeenCalled();
|
|
325
|
+
expect(ResultSet).toHaveBeenCalledTimes(1);
|
|
326
|
+
expect(ResultSet).toHaveBeenCalledWith(outcome, {
|
|
327
|
+
parseDateMeasures: undefined
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test('CubejsApi#loadResponseInternal should work with the "compact" resType for regular query', () => {
|
|
332
|
+
const api = new CubejsApi(undefined, {
|
|
333
|
+
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
334
|
+
});
|
|
335
|
+
const income = {
|
|
336
|
+
results: [{
|
|
337
|
+
query: { responseFormat: 'compact' },
|
|
338
|
+
data: JSON.parse(
|
|
339
|
+
JSON.stringify(
|
|
340
|
+
mockData.regular_1.result_compact
|
|
341
|
+
)
|
|
342
|
+
)
|
|
343
|
+
}],
|
|
344
|
+
};
|
|
345
|
+
const outcome = {
|
|
346
|
+
results: [{
|
|
347
|
+
query: { responseFormat: 'compact' },
|
|
348
|
+
data: JSON.parse(
|
|
349
|
+
JSON.stringify(
|
|
350
|
+
mockData.regular_1.result_default
|
|
351
|
+
)
|
|
352
|
+
)
|
|
353
|
+
}],
|
|
354
|
+
};
|
|
355
|
+
api.loadResponseInternal(income);
|
|
356
|
+
expect(ResultSet).toHaveBeenCalled();
|
|
357
|
+
expect(ResultSet).toHaveBeenCalledTimes(1);
|
|
358
|
+
expect(ResultSet).toHaveBeenCalledWith(outcome, {
|
|
359
|
+
parseDateMeasures: undefined
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test('CubejsApi#loadResponseInternal should work with the "compact" resType for compare date range query', () => {
|
|
364
|
+
const api = new CubejsApi(undefined, {
|
|
365
|
+
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
366
|
+
});
|
|
367
|
+
const income = {
|
|
368
|
+
results: [{
|
|
369
|
+
query: { responseFormat: 'compact' },
|
|
370
|
+
data: JSON.parse(
|
|
371
|
+
JSON.stringify(
|
|
372
|
+
mockData.compare[0].result_compact
|
|
373
|
+
)
|
|
374
|
+
)
|
|
375
|
+
}, {
|
|
376
|
+
query: { responseFormat: 'compact' },
|
|
377
|
+
data: JSON.parse(
|
|
378
|
+
JSON.stringify(
|
|
379
|
+
mockData.compare[1].result_compact
|
|
380
|
+
)
|
|
381
|
+
)
|
|
382
|
+
}],
|
|
383
|
+
};
|
|
384
|
+
const outcome = {
|
|
385
|
+
results: [{
|
|
386
|
+
query: { responseFormat: 'compact' },
|
|
387
|
+
data: JSON.parse(
|
|
388
|
+
JSON.stringify(
|
|
389
|
+
mockData.compare[0].result_default
|
|
390
|
+
)
|
|
391
|
+
)
|
|
392
|
+
}, {
|
|
393
|
+
query: { responseFormat: 'compact' },
|
|
394
|
+
data: JSON.parse(
|
|
395
|
+
JSON.stringify(
|
|
396
|
+
mockData.compare[1].result_default
|
|
397
|
+
)
|
|
398
|
+
)
|
|
399
|
+
}],
|
|
400
|
+
};
|
|
401
|
+
api.loadResponseInternal(income);
|
|
402
|
+
expect(ResultSet).toHaveBeenCalled();
|
|
403
|
+
expect(ResultSet).toHaveBeenCalledTimes(1);
|
|
404
|
+
expect(ResultSet).toHaveBeenCalledWith(outcome, {
|
|
405
|
+
parseDateMeasures: undefined
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test('CubejsApi#loadResponseInternal should work with the "compact" resType for blending query', () => {
|
|
410
|
+
const api = new CubejsApi(undefined, {
|
|
411
|
+
apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
412
|
+
});
|
|
413
|
+
const income = {
|
|
414
|
+
results: [{
|
|
415
|
+
query: { responseFormat: 'compact' },
|
|
416
|
+
data: JSON.parse(
|
|
417
|
+
JSON.stringify(
|
|
418
|
+
mockData.blending[0].result_compact
|
|
419
|
+
)
|
|
420
|
+
)
|
|
421
|
+
}, {
|
|
422
|
+
query: { responseFormat: 'compact' },
|
|
423
|
+
data: JSON.parse(
|
|
424
|
+
JSON.stringify(
|
|
425
|
+
mockData.blending[1].result_compact
|
|
426
|
+
)
|
|
427
|
+
)
|
|
428
|
+
}],
|
|
429
|
+
};
|
|
430
|
+
const outcome = {
|
|
431
|
+
results: [{
|
|
432
|
+
query: { responseFormat: 'compact' },
|
|
433
|
+
data: JSON.parse(
|
|
434
|
+
JSON.stringify(
|
|
435
|
+
mockData.blending[0].result_default
|
|
436
|
+
)
|
|
437
|
+
)
|
|
438
|
+
}, {
|
|
439
|
+
query: { responseFormat: 'compact' },
|
|
440
|
+
data: JSON.parse(
|
|
441
|
+
JSON.stringify(
|
|
442
|
+
mockData.blending[1].result_default
|
|
443
|
+
)
|
|
444
|
+
)
|
|
445
|
+
}],
|
|
446
|
+
};
|
|
447
|
+
api.loadResponseInternal(income);
|
|
448
|
+
expect(ResultSet).toHaveBeenCalled();
|
|
449
|
+
expect(ResultSet).toHaveBeenCalledTimes(1);
|
|
450
|
+
expect(ResultSet).toHaveBeenCalledWith(outcome, {
|
|
451
|
+
parseDateMeasures: undefined
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
});
|