@cubejs-client/core 1.3.15 → 1.3.16
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.js → cubejs-client-core.cjs.js} +1016 -411
- package/dist/cubejs-client-core.cjs.js.map +1 -0
- package/dist/cubejs-client-core.umd.js +2901 -12088
- package/dist/cubejs-client-core.umd.js.map +1 -1
- package/dist/src/HttpTransport.d.ts +54 -0
- package/dist/src/HttpTransport.d.ts.map +1 -0
- package/dist/src/HttpTransport.js +55 -0
- package/dist/src/Meta.d.ts +62 -0
- package/dist/src/Meta.d.ts.map +1 -0
- package/dist/src/Meta.js +150 -0
- package/dist/src/ProgressResult.d.ts +8 -0
- package/dist/src/ProgressResult.d.ts.map +1 -0
- package/dist/src/ProgressResult.js +11 -0
- package/dist/src/RequestError.d.ts +6 -0
- package/dist/src/RequestError.d.ts.map +1 -0
- package/dist/src/RequestError.js +7 -0
- package/dist/src/ResultSet.d.ts +430 -0
- package/dist/src/ResultSet.d.ts.map +1 -0
- package/dist/src/ResultSet.js +952 -0
- package/dist/src/SqlQuery.d.ts +17 -0
- package/dist/src/SqlQuery.d.ts.map +1 -0
- package/dist/src/SqlQuery.js +11 -0
- package/dist/src/index.d.ts +194 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +411 -0
- package/dist/src/index.umd.d.ts +3 -0
- package/dist/src/index.umd.d.ts.map +1 -0
- package/dist/src/index.umd.js +6 -0
- package/dist/src/time.d.ts +70 -0
- package/dist/src/time.d.ts.map +1 -0
- package/dist/src/time.js +249 -0
- package/dist/src/types.d.ts +424 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1 -0
- package/dist/src/utils.d.ts +19 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +294 -0
- package/dist/test/CubeApi.test.d.ts +7 -0
- package/dist/test/CubeApi.test.d.ts.map +1 -0
- package/dist/test/CubeApi.test.js +279 -0
- package/dist/test/HttpTransport.test.d.ts +2 -0
- package/dist/test/HttpTransport.test.d.ts.map +1 -0
- package/dist/test/HttpTransport.test.js +244 -0
- package/dist/test/ResultSet.test.d.ts +7 -0
- package/dist/test/ResultSet.test.d.ts.map +1 -0
- package/dist/test/ResultSet.test.js +1725 -0
- package/dist/test/compare-date-range.test.d.ts +2 -0
- package/dist/test/compare-date-range.test.d.ts.map +1 -0
- package/dist/test/compare-date-range.test.js +742 -0
- package/dist/test/data-blending.test.d.ts +2 -0
- package/dist/test/data-blending.test.d.ts.map +1 -0
- package/dist/test/data-blending.test.js +423 -0
- package/dist/test/default-heuristics.test.d.ts +2 -0
- package/dist/test/default-heuristics.test.d.ts.map +1 -0
- package/dist/test/default-heuristics.test.js +108 -0
- package/dist/test/drill-down.test.d.ts +2 -0
- package/dist/test/drill-down.test.d.ts.map +1 -0
- package/dist/test/drill-down.test.js +373 -0
- package/dist/test/fixtures/datablending/load-responses.json +261 -0
- package/dist/test/granularity.test.d.ts +2 -0
- package/dist/test/granularity.test.d.ts.map +1 -0
- package/dist/test/granularity.test.js +218 -0
- package/dist/test/helpers.d.ts +283 -0
- package/dist/test/helpers.d.ts.map +1 -0
- package/dist/test/helpers.js +974 -0
- package/dist/test/index.test.d.ts +7 -0
- package/dist/test/index.test.d.ts.map +1 -0
- package/dist/test/index.test.js +370 -0
- package/dist/test/table.test.d.ts +2 -0
- package/dist/test/table.test.d.ts.map +1 -0
- package/dist/test/table.test.js +757 -0
- package/dist/test/utils.test.d.ts +2 -0
- package/dist/test/utils.test.d.ts.map +1 -0
- package/dist/test/utils.test.js +32 -0
- package/package.json +26 -21
- package/dist/cubejs-client-core.esm.js +0 -1639
- package/dist/cubejs-client-core.esm.js.map +0 -1
- package/dist/cubejs-client-core.js.map +0 -1
- package/index.d.ts +0 -1338
- package/src/HttpTransport.js +0 -60
- package/src/HttpTransport.test.js +0 -117
- package/src/Meta.js +0 -142
- package/src/ProgressResult.js +0 -13
- package/src/RequestError.js +0 -7
- package/src/ResultSet.js +0 -746
- package/src/SqlQuery.js +0 -13
- package/src/index.js +0 -398
- package/src/index.test.js +0 -454
- package/src/index.umd.js +0 -8
- package/src/tests/ResultSet.test.js +0 -1655
- package/src/tests/compare-date-range.test.js +0 -753
- package/src/tests/data-blending.test.js +0 -432
- package/src/tests/default-heuristics.test.js +0 -118
- package/src/tests/drill-down.test.js +0 -402
- package/src/tests/fixtures/datablending/load-responses.json +0 -261
- package/src/tests/granularity.test.js +0 -225
- package/src/tests/table.test.js +0 -791
- package/src/tests/utils.test.js +0 -35
- package/src/time.js +0 -296
- package/src/utils.js +0 -368
package/index.d.ts
DELETED
|
@@ -1,1338 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @title @cubejs-client/core
|
|
3
|
-
* @permalink /@cubejs-client-core
|
|
4
|
-
* @menuCategory Reference
|
|
5
|
-
* @subcategory Frontend
|
|
6
|
-
* @menuOrder 2
|
|
7
|
-
* @description Vanilla JavaScript Cube.js client.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
declare module '@cubejs-client/core' {
|
|
11
|
-
export type TransportOptions = {
|
|
12
|
-
/**
|
|
13
|
-
* [jwt auth token](security)
|
|
14
|
-
*/
|
|
15
|
-
authorization: string;
|
|
16
|
-
/**
|
|
17
|
-
* path to `/cubejs-api/v1`
|
|
18
|
-
*/
|
|
19
|
-
apiUrl: string;
|
|
20
|
-
/**
|
|
21
|
-
* custom headers
|
|
22
|
-
*/
|
|
23
|
-
headers?: Record<string, string>;
|
|
24
|
-
credentials?: 'omit' | 'same-origin' | 'include';
|
|
25
|
-
method?: 'GET' | 'PUT' | 'POST' | 'PATCH';
|
|
26
|
-
/**
|
|
27
|
-
* Fetch timeout in milliseconds. Would be passed as AbortSignal.timeout()
|
|
28
|
-
*/
|
|
29
|
-
fetchTimeout?: number;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export interface ITransportResponse<R> {
|
|
33
|
-
subscribe: <CBResult>(cb: (result: R, resubscribe: () => Promise<CBResult>) => CBResult) => Promise<CBResult>;
|
|
34
|
-
// Optional, supported in WebSocketTransport
|
|
35
|
-
unsubscribe?: () => Promise<void>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface ITransport<R> {
|
|
39
|
-
request(method: string, params: Record<string, unknown>): ITransportResponse<R>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Default transport implementation.
|
|
44
|
-
* @order 3
|
|
45
|
-
*/
|
|
46
|
-
export class HttpTransport implements ITransport<ResultSet> {
|
|
47
|
-
/**
|
|
48
|
-
* @hidden
|
|
49
|
-
*/
|
|
50
|
-
protected authorization: TransportOptions['authorization'];
|
|
51
|
-
/**
|
|
52
|
-
* @hidden
|
|
53
|
-
*/
|
|
54
|
-
protected apiUrl: TransportOptions['apiUrl'];
|
|
55
|
-
/**
|
|
56
|
-
* @hidden
|
|
57
|
-
*/
|
|
58
|
-
protected method: TransportOptions['method'];
|
|
59
|
-
/**
|
|
60
|
-
* @hidden
|
|
61
|
-
*/
|
|
62
|
-
protected headers: TransportOptions['headers'];
|
|
63
|
-
/**
|
|
64
|
-
* @hidden
|
|
65
|
-
*/
|
|
66
|
-
protected credentials: TransportOptions['credentials'];
|
|
67
|
-
|
|
68
|
-
constructor(options: TransportOptions);
|
|
69
|
-
|
|
70
|
-
public request(method: string, params: any): ITransportResponse<ResultSet>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type CubeApiOptions = {
|
|
74
|
-
/**
|
|
75
|
-
* URL of your Cube.js Backend. By default, in the development environment it is `http://localhost:4000/cubejs-api/v1`
|
|
76
|
-
*/
|
|
77
|
-
apiUrl: string;
|
|
78
|
-
/**
|
|
79
|
-
* Transport implementation to use. [HttpTransport](#http-transport) will be used by default.
|
|
80
|
-
*/
|
|
81
|
-
transport?: ITransport<any>;
|
|
82
|
-
headers?: Record<string, string>;
|
|
83
|
-
pollInterval?: number;
|
|
84
|
-
credentials?: 'omit' | 'same-origin' | 'include';
|
|
85
|
-
parseDateMeasures?: boolean;
|
|
86
|
-
resType?: 'default' | 'compact';
|
|
87
|
-
castNumerics?: boolean;
|
|
88
|
-
/**
|
|
89
|
-
* How many network errors would be retried before returning to users. Default to 0.
|
|
90
|
-
*/
|
|
91
|
-
networkErrorRetries?: number;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export type LoadMethodOptions = {
|
|
95
|
-
/**
|
|
96
|
-
* Key to store the current request's MUTEX inside the `mutexObj`. MUTEX object is used to reject orphaned queries results when new queries are sent. For example: if two queries are sent with the same `mutexKey` only the last one will return results.
|
|
97
|
-
*/
|
|
98
|
-
mutexKey?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Object to store MUTEX
|
|
101
|
-
*/
|
|
102
|
-
mutexObj?: Object;
|
|
103
|
-
/**
|
|
104
|
-
* Pass `true` to use continuous fetch behavior.
|
|
105
|
-
*/
|
|
106
|
-
subscribe?: boolean;
|
|
107
|
-
/**
|
|
108
|
-
* A Cube API instance. If not provided will be taken from `CubeProvider`
|
|
109
|
-
*/
|
|
110
|
-
cubeApi?: CubeApi;
|
|
111
|
-
/**
|
|
112
|
-
* If enabled, all members of the 'number' type will be automatically converted to numerical values on the client side
|
|
113
|
-
*/
|
|
114
|
-
castNumerics?: boolean;
|
|
115
|
-
/**
|
|
116
|
-
* Function that receives `ProgressResult` on each `Continue wait` message.
|
|
117
|
-
*/
|
|
118
|
-
progressCallback?(result: ProgressResult): void;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export type LoadMethodCallback<T> = (error: Error | null, resultSet: T) => void;
|
|
122
|
-
|
|
123
|
-
export type QueryOrder = 'asc' | 'desc';
|
|
124
|
-
|
|
125
|
-
export type TQueryOrderObject = { [key: string]: QueryOrder };
|
|
126
|
-
export type TQueryOrderArray = Array<[string, QueryOrder]>;
|
|
127
|
-
|
|
128
|
-
export type Annotation = {
|
|
129
|
-
title: string;
|
|
130
|
-
shortTitle: string;
|
|
131
|
-
type: string;
|
|
132
|
-
format?: 'currency' | 'percent' | 'number';
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export type QueryAnnotations = {
|
|
136
|
-
dimensions: Record<string, Annotation>;
|
|
137
|
-
measures: Record<string, Annotation>;
|
|
138
|
-
timeDimensions: Record<string, Annotation>;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
type PivotQuery = Query & {
|
|
142
|
-
queryType: QueryType;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
type QueryType = 'regularQuery' | 'compareDateRangeQuery' | 'blendingQuery';
|
|
146
|
-
|
|
147
|
-
type LeafMeasure = {
|
|
148
|
-
measure: string;
|
|
149
|
-
additive: boolean;
|
|
150
|
-
type: 'count' | 'countDistinct' | 'sum' | 'min' | 'max' | 'number' | 'countDistinctApprox'
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
export type TransformedQuery = {
|
|
154
|
-
allFiltersWithinSelectedDimensions: boolean;
|
|
155
|
-
granularityHierarchies: Record<string, string[]>;
|
|
156
|
-
hasMultipliedMeasures: boolean;
|
|
157
|
-
hasNoTimeDimensionsWithoutGranularity: boolean;
|
|
158
|
-
isAdditive: boolean;
|
|
159
|
-
leafMeasureAdditive: boolean;
|
|
160
|
-
leafMeasures: string[];
|
|
161
|
-
measures: string[];
|
|
162
|
-
sortedDimensions: string[];
|
|
163
|
-
sortedTimeDimensions: [[string, string]];
|
|
164
|
-
measureToLeafMeasures?: Record<string, LeafMeasure[]>;
|
|
165
|
-
ownedDimensions: string[];
|
|
166
|
-
ownedTimeDimensionsAsIs: [[string, string | null]];
|
|
167
|
-
ownedTimeDimensionsWithRollupGranularity: [[string, string]];
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
export type PreAggregationType = 'rollup' | 'rollupJoin' | 'rollupLambda' | 'originalSql';
|
|
171
|
-
|
|
172
|
-
type UsedPreAggregation = {
|
|
173
|
-
targetTableName: string;
|
|
174
|
-
type: PreAggregationType;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
type LoadResponseResult<T> = {
|
|
178
|
-
annotation: QueryAnnotations;
|
|
179
|
-
lastRefreshTime: string;
|
|
180
|
-
query: Query;
|
|
181
|
-
data: T[];
|
|
182
|
-
external: boolean | null;
|
|
183
|
-
dbType: string;
|
|
184
|
-
extDbType: string;
|
|
185
|
-
requestId?: string;
|
|
186
|
-
usedPreAggregations?: Record<string, UsedPreAggregation>;
|
|
187
|
-
transformedQuery?: TransformedQuery;
|
|
188
|
-
total?: number
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export type LoadResponse<T> = {
|
|
192
|
-
queryType: QueryType;
|
|
193
|
-
results: LoadResponseResult<T>[];
|
|
194
|
-
pivotQuery: PivotQuery;
|
|
195
|
-
[key: string]: any;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Configuration object that contains information about pivot axes and other options.
|
|
200
|
-
*
|
|
201
|
-
* Let's apply `pivotConfig` and see how it affects the axes
|
|
202
|
-
* ```js
|
|
203
|
-
* // Example query
|
|
204
|
-
* {
|
|
205
|
-
* measures: ['Orders.count'],
|
|
206
|
-
* dimensions: ['Users.country', 'Users.gender']
|
|
207
|
-
* }
|
|
208
|
-
* ```
|
|
209
|
-
* If we put the `Users.gender` dimension on **y** axis
|
|
210
|
-
* ```js
|
|
211
|
-
* resultSet.tablePivot({
|
|
212
|
-
* x: ['Users.country'],
|
|
213
|
-
* y: ['Users.gender', 'measures']
|
|
214
|
-
* })
|
|
215
|
-
* ```
|
|
216
|
-
*
|
|
217
|
-
* The resulting table will look the following way
|
|
218
|
-
*
|
|
219
|
-
* | Users Country | male, Orders.count | female, Orders.count |
|
|
220
|
-
* | ------------- | ------------------ | -------------------- |
|
|
221
|
-
* | Australia | 3 | 27 |
|
|
222
|
-
* | Germany | 10 | 12 |
|
|
223
|
-
* | US | 5 | 7 |
|
|
224
|
-
*
|
|
225
|
-
* Now let's put the `Users.country` dimension on **y** axis instead
|
|
226
|
-
* ```js
|
|
227
|
-
* resultSet.tablePivot({
|
|
228
|
-
* x: ['Users.gender'],
|
|
229
|
-
* y: ['Users.country', 'measures'],
|
|
230
|
-
* });
|
|
231
|
-
* ```
|
|
232
|
-
*
|
|
233
|
-
* in this case the `Users.country` values will be laid out on **y** or **columns** axis
|
|
234
|
-
*
|
|
235
|
-
* | Users Gender | Australia, Orders.count | Germany, Orders.count | US, Orders.count |
|
|
236
|
-
* | ------------ | ----------------------- | --------------------- | ---------------- |
|
|
237
|
-
* | male | 3 | 10 | 5 |
|
|
238
|
-
* | female | 27 | 12 | 7 |
|
|
239
|
-
*
|
|
240
|
-
* It's also possible to put the `measures` on **x** axis. But in either case it should always be the last item of the array.
|
|
241
|
-
* ```js
|
|
242
|
-
* resultSet.tablePivot({
|
|
243
|
-
* x: ['Users.gender', 'measures'],
|
|
244
|
-
* y: ['Users.country'],
|
|
245
|
-
* });
|
|
246
|
-
* ```
|
|
247
|
-
*
|
|
248
|
-
* | Users Gender | measures | Australia | Germany | US |
|
|
249
|
-
* | ------------ | ------------ | --------- | ------- | --- |
|
|
250
|
-
* | male | Orders.count | 3 | 10 | 5 |
|
|
251
|
-
* | female | Orders.count | 27 | 12 | 7 |
|
|
252
|
-
*/
|
|
253
|
-
export type PivotConfig = {
|
|
254
|
-
/**
|
|
255
|
-
* Dimensions to put on **x** or **rows** axis.
|
|
256
|
-
*/
|
|
257
|
-
x?: string[];
|
|
258
|
-
/**
|
|
259
|
-
* Dimensions to put on **y** or **columns** axis.
|
|
260
|
-
*/
|
|
261
|
-
y?: string[];
|
|
262
|
-
/**
|
|
263
|
-
* If `true` missing dates on the time dimensions will be filled with fillWithValue or `0` by default for all measures.Note: the `fillMissingDates` option set to `true` will override any **order** applied to the query
|
|
264
|
-
*/
|
|
265
|
-
fillMissingDates?: boolean | null;
|
|
266
|
-
/**
|
|
267
|
-
* Value to autofill all the missing date's measure.
|
|
268
|
-
*/
|
|
269
|
-
fillWithValue?: string | number | null;
|
|
270
|
-
/**
|
|
271
|
-
* Give each series a prefix alias. Should have one entry for each query:measure. See [chartPivot](#result-set-chart-pivot)
|
|
272
|
-
*/
|
|
273
|
-
aliasSeries?: string[];
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
export type DrillDownLocator = {
|
|
277
|
-
xValues: string[];
|
|
278
|
-
yValues?: string[];
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
export type Series<T> = {
|
|
282
|
-
key: string;
|
|
283
|
-
title: string;
|
|
284
|
-
shortTitle: string;
|
|
285
|
-
series: T[];
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
export type Column = {
|
|
289
|
-
key: string;
|
|
290
|
-
title: string;
|
|
291
|
-
series: [];
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
export type SeriesNamesColumn = {
|
|
295
|
-
key: string;
|
|
296
|
-
title: string;
|
|
297
|
-
shortTitle: string;
|
|
298
|
-
yValues: string[];
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
export type ChartPivotRow = {
|
|
302
|
-
x: string;
|
|
303
|
-
xValues: string[];
|
|
304
|
-
[key: string]: any;
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
export type TableColumn = {
|
|
308
|
-
key: string;
|
|
309
|
-
dataIndex: string;
|
|
310
|
-
meta: any;
|
|
311
|
-
type: string | number;
|
|
312
|
-
title: string;
|
|
313
|
-
shortTitle: string;
|
|
314
|
-
format?: any;
|
|
315
|
-
children?: TableColumn[];
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
export type PivotRow = {
|
|
319
|
-
xValues: Array<string | number>;
|
|
320
|
-
yValuesArray: Array<[string[], number]>;
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
export type SerializedResult<T = any> = {
|
|
324
|
-
loadResponse: LoadResponse<T>;
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Provides a convenient interface for data manipulation.
|
|
329
|
-
*/
|
|
330
|
-
export class ResultSet<T = any> {
|
|
331
|
-
/**
|
|
332
|
-
* @hidden
|
|
333
|
-
*/
|
|
334
|
-
static measureFromAxis(axisValues: string[]): string;
|
|
335
|
-
static getNormalizedPivotConfig(query: PivotQuery, pivotConfig?: Partial<PivotConfig>): PivotConfig;
|
|
336
|
-
/**
|
|
337
|
-
* ```js
|
|
338
|
-
* import { ResultSet } from '@cubejs-client/core';
|
|
339
|
-
*
|
|
340
|
-
* const resultSet = await cubeApi.load(query);
|
|
341
|
-
* // You can store the result somewhere
|
|
342
|
-
* const tmp = resultSet.serialize();
|
|
343
|
-
*
|
|
344
|
-
* // and restore it later
|
|
345
|
-
* const resultSet = ResultSet.deserialize(tmp);
|
|
346
|
-
* ```
|
|
347
|
-
* @param data the result of [serialize](#result-set-serialize)
|
|
348
|
-
*/
|
|
349
|
-
static deserialize<TData = any>(data: Object, options?: Object): ResultSet<TData>;
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Can be used to stash the `ResultSet` in a storage and restored later with [deserialize](#result-set-deserialize)
|
|
353
|
-
*/
|
|
354
|
-
serialize(): SerializedResult;
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Can be used when you need access to the methods that can't be used with some query types (eg `compareDateRangeQuery` or `blendingQuery`)
|
|
358
|
-
* ```js
|
|
359
|
-
* resultSet.decompose().forEach((currentResultSet) => {
|
|
360
|
-
* console.log(currentResultSet.rawData());
|
|
361
|
-
* });
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
364
|
-
decompose(): ResultSet[];
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* @hidden
|
|
368
|
-
*/
|
|
369
|
-
normalizePivotConfig(pivotConfig?: PivotConfig): PivotConfig;
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Returns a measure drill down query.
|
|
373
|
-
*
|
|
374
|
-
* Provided you have a measure with the defined `drillMemebers` on the `Orders` cube
|
|
375
|
-
* ```js
|
|
376
|
-
* measures: {
|
|
377
|
-
* count: {
|
|
378
|
-
* type: `count`,
|
|
379
|
-
* drillMembers: [Orders.status, Users.city, count],
|
|
380
|
-
* },
|
|
381
|
-
* // ...
|
|
382
|
-
* }
|
|
383
|
-
* ```
|
|
384
|
-
*
|
|
385
|
-
* Then you can use the `drillDown` method to see the rows that contribute to that metric
|
|
386
|
-
* ```js
|
|
387
|
-
* resultSet.drillDown(
|
|
388
|
-
* {
|
|
389
|
-
* xValues,
|
|
390
|
-
* yValues,
|
|
391
|
-
* },
|
|
392
|
-
* // you should pass the `pivotConfig` if you have used it for axes manipulation
|
|
393
|
-
* pivotConfig
|
|
394
|
-
* )
|
|
395
|
-
* ```
|
|
396
|
-
*
|
|
397
|
-
* the result will be a query with the required filters applied and the dimensions/measures filled out
|
|
398
|
-
* ```js
|
|
399
|
-
* {
|
|
400
|
-
* measures: ['Orders.count'],
|
|
401
|
-
* dimensions: ['Orders.status', 'Users.city'],
|
|
402
|
-
* filters: [
|
|
403
|
-
* // dimension and measure filters
|
|
404
|
-
* ],
|
|
405
|
-
* timeDimensions: [
|
|
406
|
-
* //...
|
|
407
|
-
* ]
|
|
408
|
-
* }
|
|
409
|
-
* ```
|
|
410
|
-
*
|
|
411
|
-
* In case when you want to add `order` or `limit` to the query, you can simply spread it
|
|
412
|
-
*
|
|
413
|
-
* ```js
|
|
414
|
-
* // An example for React
|
|
415
|
-
* const drillDownResponse = useCubeQuery(
|
|
416
|
-
* {
|
|
417
|
-
* ...drillDownQuery,
|
|
418
|
-
* limit: 30,
|
|
419
|
-
* order: {
|
|
420
|
-
* 'Orders.ts': 'desc'
|
|
421
|
-
* }
|
|
422
|
-
* },
|
|
423
|
-
* {
|
|
424
|
-
* skip: !drillDownQuery
|
|
425
|
-
* }
|
|
426
|
-
* );
|
|
427
|
-
* ```
|
|
428
|
-
* @returns Drill down query
|
|
429
|
-
*/
|
|
430
|
-
drillDown(drillDownLocator: DrillDownLocator, pivotConfig?: PivotConfig): Query | null;
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Returns an array of series with key, title and series data.
|
|
434
|
-
* ```js
|
|
435
|
-
* // For the 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.series() will return
|
|
446
|
-
* [
|
|
447
|
-
* {
|
|
448
|
-
* key: 'Stories.count',
|
|
449
|
-
* title: 'Stories Count',
|
|
450
|
-
* shortTitle: 'Count',
|
|
451
|
-
* series: [
|
|
452
|
-
* { x: '2015-01-01T00:00:00', value: 27120 },
|
|
453
|
-
* { x: '2015-02-01T00:00:00', value: 25861 },
|
|
454
|
-
* { x: '2015-03-01T00:00:00', value: 29661 },
|
|
455
|
-
* //...
|
|
456
|
-
* ],
|
|
457
|
-
* },
|
|
458
|
-
* ]
|
|
459
|
-
* ```
|
|
460
|
-
*/
|
|
461
|
-
series<SeriesItem = any>(pivotConfig?: PivotConfig): Series<SeriesItem>[];
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* Returns an array of series objects, containing `key` and `title` parameters.
|
|
465
|
-
* ```js
|
|
466
|
-
* // For query
|
|
467
|
-
* {
|
|
468
|
-
* measures: ['Stories.count'],
|
|
469
|
-
* timeDimensions: [{
|
|
470
|
-
* dimension: 'Stories.time',
|
|
471
|
-
* dateRange: ['2015-01-01', '2015-12-31'],
|
|
472
|
-
* granularity: 'month'
|
|
473
|
-
* }]
|
|
474
|
-
* }
|
|
475
|
-
*
|
|
476
|
-
* // ResultSet.seriesNames() will return
|
|
477
|
-
* [
|
|
478
|
-
* {
|
|
479
|
-
* key: 'Stories.count',
|
|
480
|
-
* title: 'Stories Count',
|
|
481
|
-
* shortTitle: 'Count',
|
|
482
|
-
* yValues: ['Stories.count'],
|
|
483
|
-
* },
|
|
484
|
-
* ]
|
|
485
|
-
* ```
|
|
486
|
-
* @returns An array of series names
|
|
487
|
-
*/
|
|
488
|
-
seriesNames(pivotConfig?: PivotConfig): SeriesNamesColumn[];
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Base method for pivoting [ResultSet](#result-set) data.
|
|
492
|
-
* Most of the times shouldn't be used directly and [chartPivot](#result-set-chart-pivot)
|
|
493
|
-
* or [tablePivot](#table-pivot) should be used instead.
|
|
494
|
-
*
|
|
495
|
-
* You can find the examples of using the `pivotConfig` [here](#types-pivot-config)
|
|
496
|
-
* ```js
|
|
497
|
-
* // For query
|
|
498
|
-
* {
|
|
499
|
-
* measures: ['Stories.count'],
|
|
500
|
-
* timeDimensions: [{
|
|
501
|
-
* dimension: 'Stories.time',
|
|
502
|
-
* dateRange: ['2015-01-01', '2015-03-31'],
|
|
503
|
-
* granularity: 'month'
|
|
504
|
-
* }]
|
|
505
|
-
* }
|
|
506
|
-
*
|
|
507
|
-
* // ResultSet.pivot({ x: ['Stories.time'], y: ['measures'] }) will return
|
|
508
|
-
* [
|
|
509
|
-
* {
|
|
510
|
-
* xValues: ["2015-01-01T00:00:00"],
|
|
511
|
-
* yValuesArray: [
|
|
512
|
-
* [['Stories.count'], 27120]
|
|
513
|
-
* ]
|
|
514
|
-
* },
|
|
515
|
-
* {
|
|
516
|
-
* xValues: ["2015-02-01T00:00:00"],
|
|
517
|
-
* yValuesArray: [
|
|
518
|
-
* [['Stories.count'], 25861]
|
|
519
|
-
* ]
|
|
520
|
-
* },
|
|
521
|
-
* {
|
|
522
|
-
* xValues: ["2015-03-01T00:00:00"],
|
|
523
|
-
* yValuesArray: [
|
|
524
|
-
* [['Stories.count'], 29661]
|
|
525
|
-
* ]
|
|
526
|
-
* }
|
|
527
|
-
* ]
|
|
528
|
-
* ```
|
|
529
|
-
* @returns An array of pivoted rows.
|
|
530
|
-
*/
|
|
531
|
-
pivot(pivotConfig?: PivotConfig): PivotRow[];
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* Returns normalized query result data in the following format.
|
|
535
|
-
*
|
|
536
|
-
* You can find the examples of using the `pivotConfig` [here](#types-pivot-config)
|
|
537
|
-
* ```js
|
|
538
|
-
* // For the query
|
|
539
|
-
* {
|
|
540
|
-
* measures: ['Stories.count'],
|
|
541
|
-
* timeDimensions: [{
|
|
542
|
-
* dimension: 'Stories.time',
|
|
543
|
-
* dateRange: ['2015-01-01', '2015-12-31'],
|
|
544
|
-
* granularity: 'month'
|
|
545
|
-
* }]
|
|
546
|
-
* }
|
|
547
|
-
*
|
|
548
|
-
* // ResultSet.chartPivot() will return
|
|
549
|
-
* [
|
|
550
|
-
* { "x":"2015-01-01T00:00:00", "Stories.count": 27120, "xValues": ["2015-01-01T00:00:00"] },
|
|
551
|
-
* { "x":"2015-02-01T00:00:00", "Stories.count": 25861, "xValues": ["2015-02-01T00:00:00"] },
|
|
552
|
-
* { "x":"2015-03-01T00:00:00", "Stories.count": 29661, "xValues": ["2015-03-01T00:00:00"] },
|
|
553
|
-
* //...
|
|
554
|
-
* ]
|
|
555
|
-
*
|
|
556
|
-
* ```
|
|
557
|
-
* When using `chartPivot()` or `seriesNames()`, you can pass `aliasSeries` in the [pivotConfig](#types-pivot-config)
|
|
558
|
-
* to give each series a unique prefix. This is useful for `blending queries` which use the same measure multiple times.
|
|
559
|
-
*
|
|
560
|
-
* ```js
|
|
561
|
-
* // For the queries
|
|
562
|
-
* {
|
|
563
|
-
* measures: ['Stories.count'],
|
|
564
|
-
* timeDimensions: [
|
|
565
|
-
* {
|
|
566
|
-
* dimension: 'Stories.time',
|
|
567
|
-
* dateRange: ['2015-01-01', '2015-12-31'],
|
|
568
|
-
* granularity: 'month',
|
|
569
|
-
* },
|
|
570
|
-
* ],
|
|
571
|
-
* },
|
|
572
|
-
* {
|
|
573
|
-
* measures: ['Stories.count'],
|
|
574
|
-
* timeDimensions: [
|
|
575
|
-
* {
|
|
576
|
-
* dimension: 'Stories.time',
|
|
577
|
-
* dateRange: ['2015-01-01', '2015-12-31'],
|
|
578
|
-
* granularity: 'month',
|
|
579
|
-
* },
|
|
580
|
-
* ],
|
|
581
|
-
* filters: [
|
|
582
|
-
* {
|
|
583
|
-
* member: 'Stores.read',
|
|
584
|
-
* operator: 'equals',
|
|
585
|
-
* value: ['true'],
|
|
586
|
-
* },
|
|
587
|
-
* ],
|
|
588
|
-
* },
|
|
589
|
-
*
|
|
590
|
-
* // ResultSet.chartPivot({ aliasSeries: ['one', 'two'] }) will return
|
|
591
|
-
* [
|
|
592
|
-
* {
|
|
593
|
-
* x: '2015-01-01T00:00:00',
|
|
594
|
-
* 'one,Stories.count': 27120,
|
|
595
|
-
* 'two,Stories.count': 8933,
|
|
596
|
-
* xValues: ['2015-01-01T00:00:00'],
|
|
597
|
-
* },
|
|
598
|
-
* {
|
|
599
|
-
* x: '2015-02-01T00:00:00',
|
|
600
|
-
* 'one,Stories.count': 25861,
|
|
601
|
-
* 'two,Stories.count': 8344,
|
|
602
|
-
* xValues: ['2015-02-01T00:00:00'],
|
|
603
|
-
* },
|
|
604
|
-
* {
|
|
605
|
-
* x: '2015-03-01T00:00:00',
|
|
606
|
-
* 'one,Stories.count': 29661,
|
|
607
|
-
* 'two,Stories.count': 9023,
|
|
608
|
-
* xValues: ['2015-03-01T00:00:00'],
|
|
609
|
-
* },
|
|
610
|
-
* //...
|
|
611
|
-
* ];
|
|
612
|
-
* ```
|
|
613
|
-
*/
|
|
614
|
-
chartPivot(pivotConfig?: PivotConfig): ChartPivotRow[];
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Returns normalized query result data prepared for visualization in the table format.
|
|
618
|
-
*
|
|
619
|
-
* You can find the examples of using the `pivotConfig` [here](#types-pivot-config)
|
|
620
|
-
*
|
|
621
|
-
* For example:
|
|
622
|
-
* ```js
|
|
623
|
-
* // For the query
|
|
624
|
-
* {
|
|
625
|
-
* measures: ['Stories.count'],
|
|
626
|
-
* timeDimensions: [{
|
|
627
|
-
* dimension: 'Stories.time',
|
|
628
|
-
* dateRange: ['2015-01-01', '2015-12-31'],
|
|
629
|
-
* granularity: 'month'
|
|
630
|
-
* }]
|
|
631
|
-
* }
|
|
632
|
-
*
|
|
633
|
-
* // ResultSet.tablePivot() will return
|
|
634
|
-
* [
|
|
635
|
-
* { "Stories.time": "2015-01-01T00:00:00", "Stories.count": 27120 },
|
|
636
|
-
* { "Stories.time": "2015-02-01T00:00:00", "Stories.count": 25861 },
|
|
637
|
-
* { "Stories.time": "2015-03-01T00:00:00", "Stories.count": 29661 },
|
|
638
|
-
* //...
|
|
639
|
-
* ]
|
|
640
|
-
* ```
|
|
641
|
-
* @returns An array of pivoted rows
|
|
642
|
-
*/
|
|
643
|
-
tablePivot(pivotConfig?: PivotConfig): Array<{ [key: string]: string | number | boolean }>;
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* Returns an array of column definitions for `tablePivot`.
|
|
647
|
-
*
|
|
648
|
-
* For example:
|
|
649
|
-
* ```js
|
|
650
|
-
* // For the query
|
|
651
|
-
* {
|
|
652
|
-
* measures: ['Stories.count'],
|
|
653
|
-
* timeDimensions: [{
|
|
654
|
-
* dimension: 'Stories.time',
|
|
655
|
-
* dateRange: ['2015-01-01', '2015-12-31'],
|
|
656
|
-
* granularity: 'month'
|
|
657
|
-
* }]
|
|
658
|
-
* }
|
|
659
|
-
*
|
|
660
|
-
* // ResultSet.tableColumns() will return
|
|
661
|
-
* [
|
|
662
|
-
* {
|
|
663
|
-
* key: 'Stories.time',
|
|
664
|
-
* dataIndex: 'Stories.time',
|
|
665
|
-
* title: 'Stories Time',
|
|
666
|
-
* shortTitle: 'Time',
|
|
667
|
-
* type: 'time',
|
|
668
|
-
* format: undefined,
|
|
669
|
-
* },
|
|
670
|
-
* {
|
|
671
|
-
* key: 'Stories.count',
|
|
672
|
-
* dataIndex: 'Stories.count',
|
|
673
|
-
* title: 'Stories Count',
|
|
674
|
-
* shortTitle: 'Count',
|
|
675
|
-
* type: 'count',
|
|
676
|
-
* format: undefined,
|
|
677
|
-
* },
|
|
678
|
-
* //...
|
|
679
|
-
* ]
|
|
680
|
-
* ```
|
|
681
|
-
*
|
|
682
|
-
* In case we want to pivot the table axes
|
|
683
|
-
* ```js
|
|
684
|
-
* // Let's take this query as an example
|
|
685
|
-
* {
|
|
686
|
-
* measures: ['Orders.count'],
|
|
687
|
-
* dimensions: ['Users.country', 'Users.gender']
|
|
688
|
-
* }
|
|
689
|
-
*
|
|
690
|
-
* // and put the dimensions on `y` axis
|
|
691
|
-
* resultSet.tableColumns({
|
|
692
|
-
* x: [],
|
|
693
|
-
* y: ['Users.country', 'Users.gender', 'measures']
|
|
694
|
-
* })
|
|
695
|
-
* ```
|
|
696
|
-
*
|
|
697
|
-
* then `tableColumns` will group the table head and return
|
|
698
|
-
* ```js
|
|
699
|
-
* {
|
|
700
|
-
* key: 'Germany',
|
|
701
|
-
* type: 'string',
|
|
702
|
-
* title: 'Users Country Germany',
|
|
703
|
-
* shortTitle: 'Germany',
|
|
704
|
-
* meta: undefined,
|
|
705
|
-
* format: undefined,
|
|
706
|
-
* children: [
|
|
707
|
-
* {
|
|
708
|
-
* key: 'male',
|
|
709
|
-
* type: 'string',
|
|
710
|
-
* title: 'Users Gender male',
|
|
711
|
-
* shortTitle: 'male',
|
|
712
|
-
* meta: undefined,
|
|
713
|
-
* format: undefined,
|
|
714
|
-
* children: [
|
|
715
|
-
* {
|
|
716
|
-
* // ...
|
|
717
|
-
* dataIndex: 'Germany.male.Orders.count',
|
|
718
|
-
* shortTitle: 'Count',
|
|
719
|
-
* },
|
|
720
|
-
* ],
|
|
721
|
-
* },
|
|
722
|
-
* {
|
|
723
|
-
* // ...
|
|
724
|
-
* shortTitle: 'female',
|
|
725
|
-
* children: [
|
|
726
|
-
* {
|
|
727
|
-
* // ...
|
|
728
|
-
* dataIndex: 'Germany.female.Orders.count',
|
|
729
|
-
* shortTitle: 'Count',
|
|
730
|
-
* },
|
|
731
|
-
* ],
|
|
732
|
-
* },
|
|
733
|
-
* ],
|
|
734
|
-
* },
|
|
735
|
-
* // ...
|
|
736
|
-
* ```
|
|
737
|
-
* @returns An array of columns
|
|
738
|
-
*/
|
|
739
|
-
tableColumns(pivotConfig?: PivotConfig): TableColumn[];
|
|
740
|
-
totalRow(pivotConfig?: PivotConfig): ChartPivotRow;
|
|
741
|
-
categories(pivotConfig?: PivotConfig): ChartPivotRow[];
|
|
742
|
-
|
|
743
|
-
tableRow(): ChartPivotRow;
|
|
744
|
-
query(): Query;
|
|
745
|
-
rawData(): T[];
|
|
746
|
-
annotation(): QueryAnnotations;
|
|
747
|
-
|
|
748
|
-
/**
|
|
749
|
-
* @return the total number of rows if the `total` option was set, when sending the query
|
|
750
|
-
*/
|
|
751
|
-
totalRows(): number | null;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
export type Filter = BinaryFilter | UnaryFilter | LogicalOrFilter | LogicalAndFilter;
|
|
755
|
-
export type LogicalAndFilter = {
|
|
756
|
-
and: Filter[];
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
export type LogicalOrFilter = {
|
|
760
|
-
or: Filter[];
|
|
761
|
-
};
|
|
762
|
-
|
|
763
|
-
export interface BinaryFilter {
|
|
764
|
-
/**
|
|
765
|
-
* @deprecated Use `member` instead.
|
|
766
|
-
*/
|
|
767
|
-
dimension?: string;
|
|
768
|
-
member?: string;
|
|
769
|
-
operator: BinaryOperator;
|
|
770
|
-
values: string[];
|
|
771
|
-
}
|
|
772
|
-
export interface UnaryFilter {
|
|
773
|
-
/**
|
|
774
|
-
* @deprecated Use `member` instead.
|
|
775
|
-
*/
|
|
776
|
-
dimension?: string;
|
|
777
|
-
member?: string;
|
|
778
|
-
operator: UnaryOperator;
|
|
779
|
-
values?: never;
|
|
780
|
-
}
|
|
781
|
-
export type UnaryOperator = 'set' | 'notSet';
|
|
782
|
-
export type BinaryOperator =
|
|
783
|
-
| 'equals'
|
|
784
|
-
| 'notEquals'
|
|
785
|
-
| 'contains'
|
|
786
|
-
| 'notContains'
|
|
787
|
-
| 'startsWith'
|
|
788
|
-
| 'notStartsWith'
|
|
789
|
-
| 'endsWith'
|
|
790
|
-
| 'notEndsWith'
|
|
791
|
-
| 'gt'
|
|
792
|
-
| 'gte'
|
|
793
|
-
| 'lt'
|
|
794
|
-
| 'lte'
|
|
795
|
-
| 'inDateRange'
|
|
796
|
-
| 'notInDateRange'
|
|
797
|
-
| 'beforeDate'
|
|
798
|
-
| 'beforeOrOnDate'
|
|
799
|
-
| 'afterDate'
|
|
800
|
-
| 'afterOrOnDate';
|
|
801
|
-
|
|
802
|
-
export type TimeDimensionPredefinedGranularity = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
803
|
-
|
|
804
|
-
export type TimeDimensionGranularity = TimeDimensionPredefinedGranularity | string;
|
|
805
|
-
|
|
806
|
-
export type DateRange = string | [string, string];
|
|
807
|
-
|
|
808
|
-
export interface TimeDimensionBase {
|
|
809
|
-
dimension: string;
|
|
810
|
-
granularity?: TimeDimensionGranularity;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
type TimeDimensionComparisonFields = {
|
|
814
|
-
compareDateRange: Array<DateRange>;
|
|
815
|
-
dateRange?: never;
|
|
816
|
-
};
|
|
817
|
-
export type TimeDimensionComparison = TimeDimensionBase & TimeDimensionComparisonFields;
|
|
818
|
-
|
|
819
|
-
type TimeDimensionRangedFields = {
|
|
820
|
-
dateRange?: DateRange;
|
|
821
|
-
};
|
|
822
|
-
export type TimeDimensionRanged = TimeDimensionBase & TimeDimensionRangedFields;
|
|
823
|
-
|
|
824
|
-
export type TimeDimension = TimeDimensionComparison | TimeDimensionRanged;
|
|
825
|
-
|
|
826
|
-
type DeeplyReadonly<T> = {
|
|
827
|
-
readonly [K in keyof T]: DeeplyReadonly<T[K]>;
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
export interface Query {
|
|
831
|
-
measures?: string[];
|
|
832
|
-
dimensions?: string[];
|
|
833
|
-
filters?: Filter[];
|
|
834
|
-
timeDimensions?: TimeDimension[];
|
|
835
|
-
segments?: string[];
|
|
836
|
-
limit?: null | number;
|
|
837
|
-
offset?: number;
|
|
838
|
-
order?: TQueryOrderObject | TQueryOrderArray;
|
|
839
|
-
timezone?: string;
|
|
840
|
-
renewQuery?: boolean;
|
|
841
|
-
ungrouped?: boolean;
|
|
842
|
-
responseFormat?: 'compact' | 'default';
|
|
843
|
-
total?: boolean;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
export type QueryRecordType<T extends DeeplyReadonly<Query | Query[]>> =
|
|
847
|
-
T extends DeeplyReadonly<Query[]> ? QueryArrayRecordType<T> :
|
|
848
|
-
T extends DeeplyReadonly<Query> ? SingleQueryRecordType<T> :
|
|
849
|
-
never;
|
|
850
|
-
|
|
851
|
-
type QueryArrayRecordType<T extends DeeplyReadonly<Query[]>> =
|
|
852
|
-
T extends readonly [infer First, ...infer Rest]
|
|
853
|
-
? SingleQueryRecordType<DeeplyReadonly<First>> | QueryArrayRecordType<Rest & DeeplyReadonly<Query[]>>
|
|
854
|
-
: never;
|
|
855
|
-
|
|
856
|
-
// If we can't infer any members at all, then return any.
|
|
857
|
-
type SingleQueryRecordType<T extends DeeplyReadonly<Query>> = ExtractMembers<T> extends never
|
|
858
|
-
? any
|
|
859
|
-
: { [K in string & ExtractMembers<T>]: string | number | boolean | null };
|
|
860
|
-
|
|
861
|
-
type ExtractMembers<T extends DeeplyReadonly<Query>> =
|
|
862
|
-
| (T extends { dimensions: readonly (infer Names)[]; } ? Names : never)
|
|
863
|
-
| (T extends { measures: readonly (infer Names)[]; } ? Names : never)
|
|
864
|
-
| (T extends { timeDimensions: (infer U); } ? ExtractTimeMembers<U> : never);
|
|
865
|
-
|
|
866
|
-
type ExtractTimeMembers<T> =
|
|
867
|
-
T extends readonly [infer First, ...infer Rest]
|
|
868
|
-
? ExtractTimeMember<First> | ExtractTimeMembers<Rest>
|
|
869
|
-
: never;
|
|
870
|
-
|
|
871
|
-
type ExtractTimeMember<T> =
|
|
872
|
-
T extends { dimension: infer Dimension, granularity: infer Granularity }
|
|
873
|
-
? Dimension | `${Dimension & string}.${Granularity & string}`
|
|
874
|
-
: never;
|
|
875
|
-
|
|
876
|
-
export class ProgressResult {
|
|
877
|
-
stage(): string;
|
|
878
|
-
timeElapsed(): string;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
export interface UnsubscribeObj {
|
|
882
|
-
/**
|
|
883
|
-
* Allows to stop requests in-flight in long polling or web socket subscribe loops.
|
|
884
|
-
* It doesn't cancel any submitted requests to the underlying databases.
|
|
885
|
-
*/
|
|
886
|
-
unsubscribe(): Promise<void>;
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
export type SqlQueryTuple = [string, any[], any];
|
|
890
|
-
|
|
891
|
-
export type SqlData = {
|
|
892
|
-
aliasNameToMember: Record<string, string>;
|
|
893
|
-
cacheKeyQueries: SqlQueryTuple[];
|
|
894
|
-
dataSource: boolean;
|
|
895
|
-
external: boolean;
|
|
896
|
-
sql: SqlQueryTuple;
|
|
897
|
-
preAggregations: any[];
|
|
898
|
-
rollupMatchResults: any[];
|
|
899
|
-
};
|
|
900
|
-
|
|
901
|
-
export class SqlQuery {
|
|
902
|
-
rawQuery(): SqlData;
|
|
903
|
-
sql(): string;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
export type MemberType = 'measures' | 'dimensions' | 'segments';
|
|
907
|
-
|
|
908
|
-
type TOrderMember = {
|
|
909
|
-
id: string;
|
|
910
|
-
title: string;
|
|
911
|
-
order: QueryOrder | 'none';
|
|
912
|
-
};
|
|
913
|
-
|
|
914
|
-
type TCubeMemberType = 'time' | 'number' | 'string' | 'boolean';
|
|
915
|
-
|
|
916
|
-
// @see BaseCubeMember
|
|
917
|
-
// @deprecated
|
|
918
|
-
export type TCubeMember = {
|
|
919
|
-
type: TCubeMemberType;
|
|
920
|
-
name: string;
|
|
921
|
-
title: string;
|
|
922
|
-
shortTitle: string;
|
|
923
|
-
description?: string;
|
|
924
|
-
/**
|
|
925
|
-
* @deprecated use `public` instead
|
|
926
|
-
*/
|
|
927
|
-
isVisible?: boolean;
|
|
928
|
-
public?: boolean;
|
|
929
|
-
meta?: any;
|
|
930
|
-
};
|
|
931
|
-
|
|
932
|
-
export type BaseCubeMember = {
|
|
933
|
-
type: TCubeMemberType;
|
|
934
|
-
name: string;
|
|
935
|
-
title: string;
|
|
936
|
-
shortTitle: string;
|
|
937
|
-
description?: string;
|
|
938
|
-
/**
|
|
939
|
-
* @deprecated use `public` instead
|
|
940
|
-
*/
|
|
941
|
-
isVisible?: boolean;
|
|
942
|
-
public?: boolean;
|
|
943
|
-
meta?: any;
|
|
944
|
-
};
|
|
945
|
-
|
|
946
|
-
export type TCubeMeasure = BaseCubeMember & {
|
|
947
|
-
aggType: 'count' | 'number';
|
|
948
|
-
cumulative: boolean;
|
|
949
|
-
cumulativeTotal: boolean;
|
|
950
|
-
drillMembers: string[];
|
|
951
|
-
drillMembersGrouped: {
|
|
952
|
-
measures: string[];
|
|
953
|
-
dimensions: string[];
|
|
954
|
-
};
|
|
955
|
-
format?: 'currency' | 'percent';
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
export type CubeTimeDimensionGranularity = {
|
|
959
|
-
name: string;
|
|
960
|
-
title: string;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
export type BaseCubeDimension = BaseCubeMember & {
|
|
964
|
-
primaryKey?: boolean;
|
|
965
|
-
suggestFilterValues: boolean;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
export type CubeTimeDimension = BaseCubeDimension &
|
|
969
|
-
{ type: 'time'; granularities?: CubeTimeDimensionGranularity[] };
|
|
970
|
-
|
|
971
|
-
export type TCubeDimension =
|
|
972
|
-
(BaseCubeDimension & { type: Exclude<BaseCubeDimension['type'], 'time'> }) |
|
|
973
|
-
CubeTimeDimension;
|
|
974
|
-
|
|
975
|
-
export type TCubeSegment = Omit<BaseCubeMember, 'type'>;
|
|
976
|
-
|
|
977
|
-
type TCubeMemberByType<T> = T extends 'measures'
|
|
978
|
-
? TCubeMeasure
|
|
979
|
-
: T extends 'dimensions'
|
|
980
|
-
? TCubeDimension
|
|
981
|
-
: T extends 'segments'
|
|
982
|
-
? TCubeSegment
|
|
983
|
-
: never;
|
|
984
|
-
|
|
985
|
-
export type CubeMember = TCubeMeasure | TCubeDimension | TCubeSegment;
|
|
986
|
-
|
|
987
|
-
export type TCubeFolder = {
|
|
988
|
-
name: string;
|
|
989
|
-
members: string[];
|
|
990
|
-
};
|
|
991
|
-
|
|
992
|
-
export type TCubeHierarchy = {
|
|
993
|
-
name: string;
|
|
994
|
-
title?: string;
|
|
995
|
-
levels: string[];
|
|
996
|
-
public?: boolean;
|
|
997
|
-
};
|
|
998
|
-
|
|
999
|
-
/**
|
|
1000
|
-
* @deprecated use DryRunResponse
|
|
1001
|
-
*/
|
|
1002
|
-
type TDryRunResponse = {
|
|
1003
|
-
queryType: QueryType;
|
|
1004
|
-
normalizedQueries: Query[];
|
|
1005
|
-
pivotQuery: PivotQuery;
|
|
1006
|
-
queryOrder: Array<{ [k: string]: QueryOrder }>;
|
|
1007
|
-
transformedQueries: TransformedQuery[];
|
|
1008
|
-
};
|
|
1009
|
-
|
|
1010
|
-
export type DryRunResponse = {
|
|
1011
|
-
queryType: QueryType;
|
|
1012
|
-
normalizedQueries: Query[];
|
|
1013
|
-
pivotQuery: PivotQuery;
|
|
1014
|
-
queryOrder: Array<{ [k: string]: QueryOrder }>;
|
|
1015
|
-
transformedQueries: TransformedQuery[];
|
|
1016
|
-
};
|
|
1017
|
-
|
|
1018
|
-
export type Cube = {
|
|
1019
|
-
name: string;
|
|
1020
|
-
title: string;
|
|
1021
|
-
description?: string;
|
|
1022
|
-
measures: TCubeMeasure[];
|
|
1023
|
-
dimensions: TCubeDimension[];
|
|
1024
|
-
segments: TCubeSegment[];
|
|
1025
|
-
folders: TCubeFolder[];
|
|
1026
|
-
hierarchies: TCubeHierarchy[];
|
|
1027
|
-
connectedComponent?: number;
|
|
1028
|
-
type?: 'view' | 'cube';
|
|
1029
|
-
/**
|
|
1030
|
-
* @deprecated use `public` instead
|
|
1031
|
-
*/
|
|
1032
|
-
isVisible?: boolean;
|
|
1033
|
-
public?: boolean;
|
|
1034
|
-
meta?: any;
|
|
1035
|
-
};
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
export type CubeMap = {
|
|
1039
|
-
measures: Record<string, TCubeMeasure>;
|
|
1040
|
-
dimensions: Record<string, TCubeDimension>;
|
|
1041
|
-
segments: Record<string, TCubeSegment>;
|
|
1042
|
-
};
|
|
1043
|
-
|
|
1044
|
-
export type CubesMap = Record<
|
|
1045
|
-
string,
|
|
1046
|
-
CubeMap
|
|
1047
|
-
>;
|
|
1048
|
-
|
|
1049
|
-
export type MetaResponse = {
|
|
1050
|
-
cubes: Cube[];
|
|
1051
|
-
};
|
|
1052
|
-
|
|
1053
|
-
type FilterOperator = {
|
|
1054
|
-
name: string;
|
|
1055
|
-
title: string;
|
|
1056
|
-
};
|
|
1057
|
-
|
|
1058
|
-
/**
|
|
1059
|
-
* Contains information about available cubes and it's members.
|
|
1060
|
-
* @order 4
|
|
1061
|
-
*/
|
|
1062
|
-
export class Meta {
|
|
1063
|
-
|
|
1064
|
-
constructor(metaResponse: MetaResponse);
|
|
1065
|
-
|
|
1066
|
-
/**
|
|
1067
|
-
* Raw meta response
|
|
1068
|
-
*/
|
|
1069
|
-
meta: MetaResponse;
|
|
1070
|
-
|
|
1071
|
-
/**
|
|
1072
|
-
* An array of all available cubes with their members
|
|
1073
|
-
*/
|
|
1074
|
-
cubes: Cube[];
|
|
1075
|
-
|
|
1076
|
-
/**
|
|
1077
|
-
* A map of all cubes where the key is a cube name
|
|
1078
|
-
*/
|
|
1079
|
-
cubesMap: CubesMap;
|
|
1080
|
-
|
|
1081
|
-
/**
|
|
1082
|
-
* Get all members of a specific type for a given query.
|
|
1083
|
-
* If empty query is provided no filtering is done based on query context and all available members are retrieved.
|
|
1084
|
-
* @param query - context query to provide filtering of members available to add to this query
|
|
1085
|
-
*/
|
|
1086
|
-
membersForQuery(query: DeeplyReadonly<Query> | null, memberType: MemberType): TCubeMeasure[] | TCubeDimension[] | TCubeMember[];
|
|
1087
|
-
|
|
1088
|
-
/**
|
|
1089
|
-
* Get meta information for a cube member
|
|
1090
|
-
* Member meta information contains:
|
|
1091
|
-
* ```javascript
|
|
1092
|
-
* {
|
|
1093
|
-
* name,
|
|
1094
|
-
* title,
|
|
1095
|
-
* shortTitle,
|
|
1096
|
-
* type,
|
|
1097
|
-
* description,
|
|
1098
|
-
* format
|
|
1099
|
-
* }
|
|
1100
|
-
* ```
|
|
1101
|
-
* @param memberName - Fully qualified member name in a form `Cube.memberName`
|
|
1102
|
-
* @return An object containing meta information about member
|
|
1103
|
-
*/
|
|
1104
|
-
resolveMember<T extends MemberType>(
|
|
1105
|
-
memberName: string,
|
|
1106
|
-
memberType: T | T[]
|
|
1107
|
-
): { title: string; error: string } | TCubeMemberByType<T>;
|
|
1108
|
-
defaultTimeDimensionNameFor(memberName: string): string;
|
|
1109
|
-
filterOperatorsForMember(memberName: string, memberType: MemberType | MemberType[]): FilterOperator[];
|
|
1110
|
-
|
|
1111
|
-
// todo: types
|
|
1112
|
-
membersGroupedByCube(): any;
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
/**
|
|
1116
|
-
* Main class for accessing Cube API
|
|
1117
|
-
*
|
|
1118
|
-
* @order 2
|
|
1119
|
-
*/
|
|
1120
|
-
export class CubeApi {
|
|
1121
|
-
load<QueryType extends DeeplyReadonly<Query | Query[]>>(
|
|
1122
|
-
query: QueryType,
|
|
1123
|
-
options?: LoadMethodOptions,
|
|
1124
|
-
): Promise<ResultSet<QueryRecordType<QueryType>>>;
|
|
1125
|
-
/**
|
|
1126
|
-
* Fetch data for the passed `query`.
|
|
1127
|
-
*
|
|
1128
|
-
* ```js
|
|
1129
|
-
* import cube from '@cubejs-client/core';
|
|
1130
|
-
* import Chart from 'chart.js';
|
|
1131
|
-
* import chartjsConfig from './toChartjsData';
|
|
1132
|
-
*
|
|
1133
|
-
* const cubeApi = cube('CUBEJS_TOKEN');
|
|
1134
|
-
*
|
|
1135
|
-
* const resultSet = await cubeApi.load({
|
|
1136
|
-
* measures: ['Stories.count'],
|
|
1137
|
-
* timeDimensions: [{
|
|
1138
|
-
* dimension: 'Stories.time',
|
|
1139
|
-
* dateRange: ['2015-01-01', '2015-12-31'],
|
|
1140
|
-
* granularity: 'month'
|
|
1141
|
-
* }]
|
|
1142
|
-
* });
|
|
1143
|
-
*
|
|
1144
|
-
* const context = document.getElementById('myChart');
|
|
1145
|
-
* new Chart(context, chartjsConfig(resultSet));
|
|
1146
|
-
* ```
|
|
1147
|
-
* @param query - [Query object](/product/apis-integrations/rest-api/query-format)
|
|
1148
|
-
*/
|
|
1149
|
-
load<QueryType extends DeeplyReadonly<Query | Query[]>>(
|
|
1150
|
-
query: QueryType,
|
|
1151
|
-
options?: LoadMethodOptions,
|
|
1152
|
-
callback?: LoadMethodCallback<ResultSet<QueryRecordType<QueryType>>>,
|
|
1153
|
-
): UnsubscribeObj;
|
|
1154
|
-
|
|
1155
|
-
load<QueryType extends DeeplyReadonly<Query | Query[]>>(
|
|
1156
|
-
query: QueryType,
|
|
1157
|
-
options?: LoadMethodOptions,
|
|
1158
|
-
callback?: LoadMethodCallback<ResultSet>,
|
|
1159
|
-
responseFormat?: string
|
|
1160
|
-
): Promise<ResultSet<QueryRecordType<QueryType>>>;
|
|
1161
|
-
|
|
1162
|
-
/**
|
|
1163
|
-
* Allows you to fetch data and receive updates over time. See [Real-Time Data Fetch](/product/apis-integrations/rest-api/real-time-data-fetch)
|
|
1164
|
-
*
|
|
1165
|
-
* ```js
|
|
1166
|
-
* // Subscribe to a query's updates
|
|
1167
|
-
* const subscription = await cubeApi.subscribe(
|
|
1168
|
-
* {
|
|
1169
|
-
* measures: ['Logs.count'],
|
|
1170
|
-
* timeDimensions: [
|
|
1171
|
-
* {
|
|
1172
|
-
* dimension: 'Logs.time',
|
|
1173
|
-
* granularity: 'hour',
|
|
1174
|
-
* dateRange: 'last 1440 minutes',
|
|
1175
|
-
* },
|
|
1176
|
-
* ],
|
|
1177
|
-
* },
|
|
1178
|
-
* options,
|
|
1179
|
-
* (error, resultSet) => {
|
|
1180
|
-
* if (!error) {
|
|
1181
|
-
* // handle the update
|
|
1182
|
-
* }
|
|
1183
|
-
* }
|
|
1184
|
-
* );
|
|
1185
|
-
*
|
|
1186
|
-
* // Unsubscribe from a query's updates
|
|
1187
|
-
* subscription.unsubscribe();
|
|
1188
|
-
* ```
|
|
1189
|
-
*/
|
|
1190
|
-
subscribe<QueryType extends DeeplyReadonly<Query | Query[]>>(
|
|
1191
|
-
query: QueryType,
|
|
1192
|
-
options: LoadMethodOptions | null,
|
|
1193
|
-
callback: LoadMethodCallback<ResultSet<QueryRecordType<QueryType>>>,
|
|
1194
|
-
): UnsubscribeObj;
|
|
1195
|
-
|
|
1196
|
-
sql(query: DeeplyReadonly<Query | Query[]>, options?: LoadMethodOptions): Promise<SqlQuery>;
|
|
1197
|
-
/**
|
|
1198
|
-
* Get generated SQL string for the given `query`.
|
|
1199
|
-
* @param query - [Query object](query-format)
|
|
1200
|
-
*/
|
|
1201
|
-
sql(query: DeeplyReadonly<Query | Query[]>, options?: LoadMethodOptions, callback?: LoadMethodCallback<SqlQuery>): UnsubscribeObj;
|
|
1202
|
-
|
|
1203
|
-
meta(options?: LoadMethodOptions): Promise<Meta>;
|
|
1204
|
-
/**
|
|
1205
|
-
* Get meta description of cubes available for querying.
|
|
1206
|
-
*/
|
|
1207
|
-
meta(options?: LoadMethodOptions, callback?: LoadMethodCallback<Meta>): UnsubscribeObj;
|
|
1208
|
-
|
|
1209
|
-
dryRun(query: DeeplyReadonly<Query | Query[]>, options?: LoadMethodOptions): Promise<DryRunResponse>;
|
|
1210
|
-
/**
|
|
1211
|
-
* Get query related meta without query execution
|
|
1212
|
-
*/
|
|
1213
|
-
dryRun(query: DeeplyReadonly<Query | Query[]>, options: LoadMethodOptions, callback?: LoadMethodCallback<DryRunResponse>): UnsubscribeObj;
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
/**
|
|
1217
|
-
* Creates an instance of the `CubeApi`. The API entry point.
|
|
1218
|
-
*
|
|
1219
|
-
* ```js
|
|
1220
|
-
* import cube from '@cubejs-client/core';
|
|
1221
|
-
* const cubeApi = cube(
|
|
1222
|
-
* 'CUBE-API-TOKEN',
|
|
1223
|
-
* { apiUrl: 'http://localhost:4000/cubejs-api/v1' }
|
|
1224
|
-
* );
|
|
1225
|
-
* ```
|
|
1226
|
-
*
|
|
1227
|
-
* You can also pass an async function or a promise that will resolve to the API token
|
|
1228
|
-
*
|
|
1229
|
-
* ```js
|
|
1230
|
-
* import cube from '@cubejs-client/core';
|
|
1231
|
-
* const cubeApi = cube(
|
|
1232
|
-
* async () => await Auth.getJwtToken(),
|
|
1233
|
-
* { apiUrl: 'http://localhost:4000/cubejs-api/v1' }
|
|
1234
|
-
* );
|
|
1235
|
-
* ```
|
|
1236
|
-
*
|
|
1237
|
-
* @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.
|
|
1238
|
-
* @order 1
|
|
1239
|
-
*/
|
|
1240
|
-
export default function cube(apiToken: string | (() => Promise<string>), options: CubeApiOptions): CubeApi;
|
|
1241
|
-
export default function cube(options: CubeApiOptions): CubeApi;
|
|
1242
|
-
|
|
1243
|
-
/**
|
|
1244
|
-
* @hidden
|
|
1245
|
-
*/
|
|
1246
|
-
export type TSourceAxis = 'x' | 'y';
|
|
1247
|
-
|
|
1248
|
-
export type ChartType = 'line' | 'bar' | 'table' | 'area' | 'number' | 'pie';
|
|
1249
|
-
|
|
1250
|
-
export type TDefaultHeuristicsOptions = {
|
|
1251
|
-
meta: Meta;
|
|
1252
|
-
sessionGranularity?: TimeDimensionGranularity;
|
|
1253
|
-
};
|
|
1254
|
-
|
|
1255
|
-
export type TDefaultHeuristicsResponse = {
|
|
1256
|
-
shouldApplyHeuristicOrder: boolean;
|
|
1257
|
-
pivotConfig: PivotConfig | null;
|
|
1258
|
-
query: Query;
|
|
1259
|
-
chartType?: ChartType;
|
|
1260
|
-
};
|
|
1261
|
-
|
|
1262
|
-
export type TDefaultHeuristicsState = {
|
|
1263
|
-
query: Query;
|
|
1264
|
-
chartType?: ChartType;
|
|
1265
|
-
};
|
|
1266
|
-
|
|
1267
|
-
export function defaultHeuristics(
|
|
1268
|
-
newState: TDefaultHeuristicsState,
|
|
1269
|
-
oldQuery: Query,
|
|
1270
|
-
options: TDefaultHeuristicsOptions
|
|
1271
|
-
): TDefaultHeuristicsResponse;
|
|
1272
|
-
/**
|
|
1273
|
-
* @hidden
|
|
1274
|
-
*/
|
|
1275
|
-
export function isQueryPresent(query: DeeplyReadonly<Query | Query[]> | null | undefined): boolean;
|
|
1276
|
-
export function movePivotItem(
|
|
1277
|
-
pivotConfig: PivotConfig,
|
|
1278
|
-
sourceIndex: number,
|
|
1279
|
-
destinationIndex: number,
|
|
1280
|
-
sourceAxis: TSourceAxis,
|
|
1281
|
-
destinationAxis: TSourceAxis
|
|
1282
|
-
): PivotConfig;
|
|
1283
|
-
/**
|
|
1284
|
-
* @hidden
|
|
1285
|
-
*/
|
|
1286
|
-
export function moveItemInArray<T = any>(list: T[], sourceIndex: number, destinationIndex: number): T[];
|
|
1287
|
-
|
|
1288
|
-
export function defaultOrder(query: DeeplyReadonly<Query>): { [key: string]: QueryOrder };
|
|
1289
|
-
|
|
1290
|
-
export interface TFlatFilter {
|
|
1291
|
-
/**
|
|
1292
|
-
* @deprecated Use `member` instead.
|
|
1293
|
-
*/
|
|
1294
|
-
dimension?: string;
|
|
1295
|
-
member?: string;
|
|
1296
|
-
operator: BinaryOperator;
|
|
1297
|
-
values: string[];
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
/**
|
|
1301
|
-
* @hidden
|
|
1302
|
-
*/
|
|
1303
|
-
export function flattenFilters(filters: Filter[]): TFlatFilter[];
|
|
1304
|
-
|
|
1305
|
-
type TGranularityMap = {
|
|
1306
|
-
name: TimeDimensionGranularity | undefined;
|
|
1307
|
-
title: string;
|
|
1308
|
-
};
|
|
1309
|
-
|
|
1310
|
-
/**
|
|
1311
|
-
* @hidden
|
|
1312
|
-
*/
|
|
1313
|
-
export function getOrderMembersFromOrder(
|
|
1314
|
-
orderMembers: any,
|
|
1315
|
-
order: TQueryOrderObject | TQueryOrderArray
|
|
1316
|
-
): TOrderMember[];
|
|
1317
|
-
|
|
1318
|
-
export const GRANULARITIES: TGranularityMap[];
|
|
1319
|
-
/**
|
|
1320
|
-
* @hidden
|
|
1321
|
-
*/
|
|
1322
|
-
export function getQueryMembers(query: DeeplyReadonly<Query>): string[];
|
|
1323
|
-
|
|
1324
|
-
export function areQueriesEqual(query1: DeeplyReadonly<Query> | null, query2: DeeplyReadonly<Query> | null): boolean;
|
|
1325
|
-
|
|
1326
|
-
export function validateQuery(query: DeeplyReadonly<Query> | null | undefined): Query;
|
|
1327
|
-
|
|
1328
|
-
export type ProgressResponse = {
|
|
1329
|
-
stage: string;
|
|
1330
|
-
timeElapsed: number;
|
|
1331
|
-
};
|
|
1332
|
-
|
|
1333
|
-
export function granularityFor(dateStr: string): string;
|
|
1334
|
-
|
|
1335
|
-
export function minGranularityForIntervals(i1: string, i2: string): string;
|
|
1336
|
-
|
|
1337
|
-
export function isPredefinedGranularity(granularity: TimeDimensionGranularity): boolean;
|
|
1338
|
-
}
|