@cubejs-client/core 0.29.23 → 0.29.42
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 +33 -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 +16 -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
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
declare module '@cubejs-client/core' {
|
|
11
|
-
|
|
12
11
|
export type TransportOptions = {
|
|
13
12
|
/**
|
|
14
13
|
* [jwt auth token](security)
|
|
@@ -80,6 +79,7 @@ declare module '@cubejs-client/core' {
|
|
|
80
79
|
pollInterval?: number;
|
|
81
80
|
credentials?: 'omit' | 'same-origin' | 'include';
|
|
82
81
|
parseDateMeasures?: boolean;
|
|
82
|
+
resType?: 'default' | 'compact';
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
export type LoadMethodOptions = {
|
|
@@ -131,6 +131,12 @@ declare module '@cubejs-client/core' {
|
|
|
131
131
|
|
|
132
132
|
type QueryType = 'regularQuery' | 'compareDateRangeQuery' | 'blendingQuery';
|
|
133
133
|
|
|
134
|
+
type LeafMeasure = {
|
|
135
|
+
measure: string;
|
|
136
|
+
additive: boolean;
|
|
137
|
+
type: 'count' | 'countDistinct' | 'sum' | 'min' | 'max' | 'number' | 'countDistinctApprox'
|
|
138
|
+
};
|
|
139
|
+
|
|
134
140
|
export type TransformedQuery = {
|
|
135
141
|
allFiltersWithinSelectedDimensions: boolean;
|
|
136
142
|
granularityHierarchies: Record<string, string[]>;
|
|
@@ -142,6 +148,7 @@ declare module '@cubejs-client/core' {
|
|
|
142
148
|
measures: string[];
|
|
143
149
|
sortedDimensions: string[];
|
|
144
150
|
sortedTimeDimensions: [[string, string]];
|
|
151
|
+
measureToLeafMeasures?: Record<string, LeafMeasure[]>;
|
|
145
152
|
};
|
|
146
153
|
|
|
147
154
|
export type PreAggregationType = 'rollup' | 'rollupJoin' | 'originalSql';
|
|
@@ -159,7 +166,7 @@ declare module '@cubejs-client/core' {
|
|
|
159
166
|
external: boolean | null;
|
|
160
167
|
dbType: string;
|
|
161
168
|
extDbType: string;
|
|
162
|
-
requestId?: string
|
|
169
|
+
requestId?: string;
|
|
163
170
|
usedPreAggregations?: Record<string, UsedPreAggregation>;
|
|
164
171
|
transformedQuery?: TransformedQuery;
|
|
165
172
|
};
|
|
@@ -790,6 +797,7 @@ declare module '@cubejs-client/core' {
|
|
|
790
797
|
timezone?: string;
|
|
791
798
|
renewQuery?: boolean;
|
|
792
799
|
ungrouped?: boolean;
|
|
800
|
+
responseFormat?: 'compact' | 'default';
|
|
793
801
|
}
|
|
794
802
|
|
|
795
803
|
export class ProgressResult {
|
|
@@ -993,6 +1001,12 @@ declare module '@cubejs-client/core' {
|
|
|
993
1001
|
* @param query - [Query object](query-format)
|
|
994
1002
|
*/
|
|
995
1003
|
load(query: Query | Query[], options?: LoadMethodOptions, callback?: LoadMethodCallback<ResultSet>): void;
|
|
1004
|
+
load(
|
|
1005
|
+
query: Query | Query[],
|
|
1006
|
+
options?: LoadMethodOptions,
|
|
1007
|
+
callback?: LoadMethodCallback<ResultSet>,
|
|
1008
|
+
responseFormat?: string
|
|
1009
|
+
): Promise<ResultSet>;
|
|
996
1010
|
|
|
997
1011
|
/**
|
|
998
1012
|
* 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.42",
|
|
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": "d05b5199da6e06f4d8baaed1baddb56cf1538637"
|
|
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);
|