@cubejs-client/core 0.28.38 → 0.29.5
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 +46 -0
- package/dist/cubejs-client-core.esm.js +26 -25
- package/dist/cubejs-client-core.esm.js.map +1 -1
- package/dist/cubejs-client-core.js +26 -25
- package/dist/cubejs-client-core.js.map +1 -1
- package/dist/cubejs-client-core.umd.js +1134 -2012
- package/dist/cubejs-client-core.umd.js.map +1 -1
- package/index.d.ts +27 -14
- package/package.json +3 -2
- package/src/ResultSet.js +11 -13
- package/src/tests/ResultSet.test.js +2 -3
- package/src/tests/data-blending.test.js +3 -0
- package/src/tests/granularity.test.js +110 -1
package/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
declare module '@cubejs-client/core' {
|
|
11
|
+
|
|
11
12
|
export type TransportOptions = {
|
|
12
13
|
/**
|
|
13
14
|
* [jwt auth token](security)
|
|
@@ -158,6 +159,7 @@ declare module '@cubejs-client/core' {
|
|
|
158
159
|
external: boolean | null;
|
|
159
160
|
dbType: string;
|
|
160
161
|
extDbType: string;
|
|
162
|
+
requestId?: string,
|
|
161
163
|
usedPreAggregations?: Record<string, UsedPreAggregation>;
|
|
162
164
|
transformedQuery?: TransformedQuery;
|
|
163
165
|
};
|
|
@@ -713,28 +715,34 @@ declare module '@cubejs-client/core' {
|
|
|
713
715
|
}
|
|
714
716
|
|
|
715
717
|
export type Filter = BinaryFilter | UnaryFilter | LogicalOrFilter | LogicalAndFilter;
|
|
716
|
-
type LogicalAndFilter = {
|
|
718
|
+
export type LogicalAndFilter = {
|
|
717
719
|
and: (BinaryFilter | UnaryFilter | LogicalOrFilter)[];
|
|
718
720
|
};
|
|
719
721
|
|
|
720
|
-
type LogicalOrFilter = {
|
|
722
|
+
export type LogicalOrFilter = {
|
|
721
723
|
or: (BinaryFilter | UnaryFilter | LogicalAndFilter)[];
|
|
722
724
|
};
|
|
723
725
|
|
|
724
|
-
|
|
726
|
+
export interface BinaryFilter {
|
|
727
|
+
/**
|
|
728
|
+
* @deprecated Use `member` instead.
|
|
729
|
+
*/
|
|
725
730
|
dimension?: string;
|
|
726
731
|
member?: string;
|
|
727
732
|
operator: BinaryOperator;
|
|
728
733
|
values: string[];
|
|
729
|
-
}
|
|
730
|
-
|
|
734
|
+
}
|
|
735
|
+
export interface UnaryFilter {
|
|
736
|
+
/**
|
|
737
|
+
* @deprecated Use `member` instead.
|
|
738
|
+
*/
|
|
731
739
|
dimension?: string;
|
|
732
740
|
member?: string;
|
|
733
741
|
operator: UnaryOperator;
|
|
734
742
|
values?: never;
|
|
735
|
-
}
|
|
736
|
-
type UnaryOperator = 'set' | 'notSet';
|
|
737
|
-
type BinaryOperator =
|
|
743
|
+
}
|
|
744
|
+
export type UnaryOperator = 'set' | 'notSet';
|
|
745
|
+
export type BinaryOperator =
|
|
738
746
|
| 'equals'
|
|
739
747
|
| 'notEquals'
|
|
740
748
|
| 'contains'
|
|
@@ -752,10 +760,10 @@ declare module '@cubejs-client/core' {
|
|
|
752
760
|
|
|
753
761
|
export type DateRange = string | [string, string];
|
|
754
762
|
|
|
755
|
-
export
|
|
763
|
+
export interface TimeDimensionBase {
|
|
756
764
|
dimension: string;
|
|
757
765
|
granularity?: TimeDimensionGranularity;
|
|
758
|
-
}
|
|
766
|
+
}
|
|
759
767
|
|
|
760
768
|
type TimeDimensionComparisonFields = {
|
|
761
769
|
compareDateRange: Array<DateRange>;
|
|
@@ -770,7 +778,7 @@ declare module '@cubejs-client/core' {
|
|
|
770
778
|
|
|
771
779
|
export type TimeDimension = TimeDimensionComparison | TimeDimensionRanged;
|
|
772
780
|
|
|
773
|
-
export
|
|
781
|
+
export interface Query {
|
|
774
782
|
measures?: string[];
|
|
775
783
|
dimensions?: string[];
|
|
776
784
|
filters?: Filter[];
|
|
@@ -782,7 +790,7 @@ declare module '@cubejs-client/core' {
|
|
|
782
790
|
timezone?: string;
|
|
783
791
|
renewQuery?: boolean;
|
|
784
792
|
ungrouped?: boolean;
|
|
785
|
-
}
|
|
793
|
+
}
|
|
786
794
|
|
|
787
795
|
export class ProgressResult {
|
|
788
796
|
stage(): string;
|
|
@@ -1104,12 +1112,15 @@ declare module '@cubejs-client/core' {
|
|
|
1104
1112
|
|
|
1105
1113
|
export function defaultOrder(query: Query): { [key: string]: QueryOrder };
|
|
1106
1114
|
|
|
1107
|
-
|
|
1115
|
+
export interface TFlatFilter {
|
|
1116
|
+
/**
|
|
1117
|
+
* @deprecated Use `member` instead.
|
|
1118
|
+
*/
|
|
1108
1119
|
dimension?: string;
|
|
1109
1120
|
member?: string;
|
|
1110
1121
|
operator: BinaryOperator;
|
|
1111
1122
|
values: string[];
|
|
1112
|
-
}
|
|
1123
|
+
}
|
|
1113
1124
|
|
|
1114
1125
|
/**
|
|
1115
1126
|
* @hidden
|
|
@@ -1142,3 +1153,5 @@ declare module '@cubejs-client/core' {
|
|
|
1142
1153
|
timeElapsed: number;
|
|
1143
1154
|
};
|
|
1144
1155
|
}
|
|
1156
|
+
|
|
1157
|
+
import '@cubejs-client/dx';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubejs-client/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.5",
|
|
4
4
|
"engines": {},
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"author": "Cube Dev, Inc.",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.1.2",
|
|
17
|
+
"@cubejs-client/dx": "^0.29.5",
|
|
17
18
|
"core-js": "^3.6.5",
|
|
18
19
|
"cross-fetch": "^3.0.2",
|
|
19
20
|
"dayjs": "^1.10.4",
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"eslint-plugin-node": "^5.2.1",
|
|
46
47
|
"jest": "^26.0.1"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "518281dea6e0c511813df4502f3aa97038f9be23"
|
|
49
50
|
}
|
package/src/ResultSet.js
CHANGED
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
|
|
10
10
|
import { aliasSeries } from './utils';
|
|
11
11
|
|
|
12
|
-
dayjs.locale({
|
|
13
|
-
...en,
|
|
14
|
-
weekStart: 1,
|
|
15
|
-
});
|
|
16
12
|
dayjs.extend(quarterOfYear);
|
|
17
13
|
|
|
14
|
+
// When granularity is week, weekStart Value must be 1. However, since the client can change it globally (https://day.js.org/docs/en/i18n/changing-locale)
|
|
15
|
+
// So the function below has been added.
|
|
16
|
+
const internalDayjs = (...args) => dayjs(...args).locale({ ...en, weekStart: 1 });
|
|
17
|
+
|
|
18
18
|
export const TIME_SERIES = {
|
|
19
19
|
day: (range) => range.by('d').map(d => d.format('YYYY-MM-DDT00:00:00.000')),
|
|
20
20
|
month: (range) => range.snapTo('month').by('M').map(d => d.format('YYYY-MM-01T00:00:00.000')),
|
|
@@ -60,8 +60,8 @@ export const dayRange = (from, to) => ({
|
|
|
60
60
|
by: (value) => {
|
|
61
61
|
const results = [];
|
|
62
62
|
|
|
63
|
-
let start =
|
|
64
|
-
const end =
|
|
63
|
+
let start = internalDayjs(from);
|
|
64
|
+
const end = internalDayjs(to);
|
|
65
65
|
|
|
66
66
|
while (start.isBefore(end) || start.isSame(end)) {
|
|
67
67
|
results.push(start);
|
|
@@ -70,9 +70,9 @@ export const dayRange = (from, to) => ({
|
|
|
70
70
|
|
|
71
71
|
return results;
|
|
72
72
|
},
|
|
73
|
-
snapTo: (value) => dayRange(
|
|
74
|
-
start:
|
|
75
|
-
end:
|
|
73
|
+
snapTo: (value) => dayRange(internalDayjs(from).startOf(value), internalDayjs(to).endOf(value)),
|
|
74
|
+
start: internalDayjs(from),
|
|
75
|
+
end: internalDayjs(to),
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
export const QUERY_TYPE = {
|
|
@@ -318,7 +318,7 @@ class ResultSet {
|
|
|
318
318
|
if (!dateRange) {
|
|
319
319
|
const member = ResultSet.timeDimensionMember(timeDimension);
|
|
320
320
|
const dates = pipe(
|
|
321
|
-
map(row => row[member] &&
|
|
321
|
+
map(row => row[member] && internalDayjs(row[member])),
|
|
322
322
|
filter(Boolean)
|
|
323
323
|
)(this.timeDimensionBackwardCompatibleData(resultIndex));
|
|
324
324
|
|
|
@@ -355,7 +355,7 @@ class ResultSet {
|
|
|
355
355
|
const pivotImpl = (resultIndex = 0) => {
|
|
356
356
|
let groupByXAxis = groupByToPairs(({ xValues }) => this.axisValuesString(xValues));
|
|
357
357
|
|
|
358
|
-
|
|
358
|
+
const measureValue = (row, measure) => row[measure] || 0;
|
|
359
359
|
|
|
360
360
|
if (
|
|
361
361
|
pivotConfig.fillMissingDates &&
|
|
@@ -379,8 +379,6 @@ class ResultSet {
|
|
|
379
379
|
);
|
|
380
380
|
return series[resultIndex].map(d => [d, byXValues[d] || [{ xValues: [d], row: {} }]]);
|
|
381
381
|
};
|
|
382
|
-
|
|
383
|
-
measureValue = (row, measure) => row[measure] || 0;
|
|
384
382
|
}
|
|
385
383
|
}
|
|
386
384
|
|
|
@@ -187,7 +187,7 @@ describe('ResultSet', () => {
|
|
|
187
187
|
{
|
|
188
188
|
x: 'Name 1',
|
|
189
189
|
|
|
190
|
-
'Foo.count':
|
|
190
|
+
'Foo.count': 0,
|
|
191
191
|
xValues: [
|
|
192
192
|
'Name 1'
|
|
193
193
|
],
|
|
@@ -235,8 +235,7 @@ describe('ResultSet', () => {
|
|
|
235
235
|
expect(resultSet.chartPivot()).toEqual([
|
|
236
236
|
{
|
|
237
237
|
x: 'Name 1',
|
|
238
|
-
|
|
239
|
-
'Foo.count': undefined,
|
|
238
|
+
'Foo.count': 0,
|
|
240
239
|
xValues: [
|
|
241
240
|
'Name 1'
|
|
242
241
|
],
|
|
@@ -255,11 +255,14 @@ describe('data blending', () => {
|
|
|
255
255
|
xValues: ['2020-08-01T00:00:00.000'],
|
|
256
256
|
'Orders.count': 1,
|
|
257
257
|
'Australia,Users.count': 20,
|
|
258
|
+
'Italy,Users.count': 0,
|
|
259
|
+
'Spain,Users.count': 0
|
|
258
260
|
},
|
|
259
261
|
{
|
|
260
262
|
x: '2020-08-02T00:00:00.000',
|
|
261
263
|
xValues: ['2020-08-02T00:00:00.000'],
|
|
262
264
|
'Orders.count': 2,
|
|
265
|
+
'Australia,Users.count': 0,
|
|
263
266
|
'Spain,Users.count': 34,
|
|
264
267
|
'Italy,Users.count': 18,
|
|
265
268
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import 'jest';
|
|
2
|
-
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import ko from 'dayjs/locale/ko';
|
|
3
4
|
import ResultSet from '../ResultSet';
|
|
4
5
|
|
|
5
6
|
describe('ResultSet Granularity', () => {
|
|
@@ -110,5 +111,113 @@ describe('ResultSet Granularity', () => {
|
|
|
110
111
|
},
|
|
111
112
|
]);
|
|
112
113
|
});
|
|
114
|
+
|
|
115
|
+
test('week granularity in other locale', () => {
|
|
116
|
+
dayjs.locale(ko);
|
|
117
|
+
const result = new ResultSet({
|
|
118
|
+
queryType: 'regularQuery',
|
|
119
|
+
results: [
|
|
120
|
+
{
|
|
121
|
+
query: {
|
|
122
|
+
measures: ['LineItems.count'],
|
|
123
|
+
timeDimensions: [
|
|
124
|
+
{
|
|
125
|
+
dimension: 'LineItems.createdAt',
|
|
126
|
+
granularity: 'week',
|
|
127
|
+
dateRange: ['2019-01-08T00:00:00.000', '2019-01-18T00:00:00.000'],
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
filters: [
|
|
131
|
+
{
|
|
132
|
+
operator: 'equals',
|
|
133
|
+
values: ['us-ut'],
|
|
134
|
+
member: 'Users.state',
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
limit: 2,
|
|
138
|
+
rowLimit: 2,
|
|
139
|
+
timezone: 'UTC',
|
|
140
|
+
order: [],
|
|
141
|
+
dimensions: [],
|
|
142
|
+
queryType: 'regularQuery',
|
|
143
|
+
},
|
|
144
|
+
data: [
|
|
145
|
+
{
|
|
146
|
+
'LineItems.createdAt.week': '2019-01-07T00:00:00.000',
|
|
147
|
+
'LineItems.createdAt': '2019-01-07T00:00:00.000',
|
|
148
|
+
'LineItems.count': '2',
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
lastRefreshTime: '2021-07-07T14:31:30.458Z',
|
|
152
|
+
annotation: {
|
|
153
|
+
measures: {
|
|
154
|
+
'LineItems.count': {
|
|
155
|
+
title: 'Line Items Count',
|
|
156
|
+
shortTitle: 'Count',
|
|
157
|
+
type: 'number',
|
|
158
|
+
drillMembers: ['LineItems.id', 'LineItems.createdAt'],
|
|
159
|
+
drillMembersGrouped: {
|
|
160
|
+
measures: [],
|
|
161
|
+
dimensions: ['LineItems.id', 'LineItems.createdAt'],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
dimensions: {},
|
|
166
|
+
segments: {},
|
|
167
|
+
timeDimensions: {
|
|
168
|
+
'LineItems.createdAt.week': {
|
|
169
|
+
title: 'Line Items Created at',
|
|
170
|
+
shortTitle: 'Created at',
|
|
171
|
+
type: 'time',
|
|
172
|
+
},
|
|
173
|
+
'LineItems.createdAt': {
|
|
174
|
+
title: 'Line Items Created at',
|
|
175
|
+
shortTitle: 'Created at',
|
|
176
|
+
type: 'time',
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
slowQuery: false,
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
pivotQuery: {
|
|
184
|
+
measures: ['LineItems.count'],
|
|
185
|
+
timeDimensions: [
|
|
186
|
+
{
|
|
187
|
+
dimension: 'LineItems.createdAt',
|
|
188
|
+
granularity: 'week',
|
|
189
|
+
dateRange: ['2019-01-08T00:00:00.000', '2019-01-18T00:00:00.000'],
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
filters: [
|
|
193
|
+
{
|
|
194
|
+
operator: 'equals',
|
|
195
|
+
values: ['us-ut'],
|
|
196
|
+
member: 'Users.state',
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
limit: 2,
|
|
200
|
+
rowLimit: 2,
|
|
201
|
+
timezone: 'UTC',
|
|
202
|
+
order: [],
|
|
203
|
+
dimensions: [],
|
|
204
|
+
queryType: 'regularQuery',
|
|
205
|
+
},
|
|
206
|
+
slowQuery: false,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
expect(result.chartPivot()).toStrictEqual([
|
|
210
|
+
{
|
|
211
|
+
x: '2019-01-07T00:00:00.000',
|
|
212
|
+
xValues: ['2019-01-07T00:00:00.000'],
|
|
213
|
+
'LineItems.count': 2,
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
x: '2019-01-14T00:00:00.000',
|
|
217
|
+
xValues: ['2019-01-14T00:00:00.000'],
|
|
218
|
+
'LineItems.count': 0,
|
|
219
|
+
},
|
|
220
|
+
]);
|
|
221
|
+
});
|
|
113
222
|
});
|
|
114
223
|
});
|