@cubejs-client/core 0.28.45 → 0.29.8
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 +49 -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)
|
|
@@ -714,28 +715,34 @@ declare module '@cubejs-client/core' {
|
|
|
714
715
|
}
|
|
715
716
|
|
|
716
717
|
export type Filter = BinaryFilter | UnaryFilter | LogicalOrFilter | LogicalAndFilter;
|
|
717
|
-
type LogicalAndFilter = {
|
|
718
|
+
export type LogicalAndFilter = {
|
|
718
719
|
and: (BinaryFilter | UnaryFilter | LogicalOrFilter)[];
|
|
719
720
|
};
|
|
720
721
|
|
|
721
|
-
type LogicalOrFilter = {
|
|
722
|
+
export type LogicalOrFilter = {
|
|
722
723
|
or: (BinaryFilter | UnaryFilter | LogicalAndFilter)[];
|
|
723
724
|
};
|
|
724
725
|
|
|
725
|
-
|
|
726
|
+
export interface BinaryFilter {
|
|
727
|
+
/**
|
|
728
|
+
* @deprecated Use `member` instead.
|
|
729
|
+
*/
|
|
726
730
|
dimension?: string;
|
|
727
731
|
member?: string;
|
|
728
732
|
operator: BinaryOperator;
|
|
729
733
|
values: string[];
|
|
730
|
-
}
|
|
731
|
-
|
|
734
|
+
}
|
|
735
|
+
export interface UnaryFilter {
|
|
736
|
+
/**
|
|
737
|
+
* @deprecated Use `member` instead.
|
|
738
|
+
*/
|
|
732
739
|
dimension?: string;
|
|
733
740
|
member?: string;
|
|
734
741
|
operator: UnaryOperator;
|
|
735
742
|
values?: never;
|
|
736
|
-
}
|
|
737
|
-
type UnaryOperator = 'set' | 'notSet';
|
|
738
|
-
type BinaryOperator =
|
|
743
|
+
}
|
|
744
|
+
export type UnaryOperator = 'set' | 'notSet';
|
|
745
|
+
export type BinaryOperator =
|
|
739
746
|
| 'equals'
|
|
740
747
|
| 'notEquals'
|
|
741
748
|
| 'contains'
|
|
@@ -753,10 +760,10 @@ declare module '@cubejs-client/core' {
|
|
|
753
760
|
|
|
754
761
|
export type DateRange = string | [string, string];
|
|
755
762
|
|
|
756
|
-
export
|
|
763
|
+
export interface TimeDimensionBase {
|
|
757
764
|
dimension: string;
|
|
758
765
|
granularity?: TimeDimensionGranularity;
|
|
759
|
-
}
|
|
766
|
+
}
|
|
760
767
|
|
|
761
768
|
type TimeDimensionComparisonFields = {
|
|
762
769
|
compareDateRange: Array<DateRange>;
|
|
@@ -771,7 +778,7 @@ declare module '@cubejs-client/core' {
|
|
|
771
778
|
|
|
772
779
|
export type TimeDimension = TimeDimensionComparison | TimeDimensionRanged;
|
|
773
780
|
|
|
774
|
-
export
|
|
781
|
+
export interface Query {
|
|
775
782
|
measures?: string[];
|
|
776
783
|
dimensions?: string[];
|
|
777
784
|
filters?: Filter[];
|
|
@@ -783,7 +790,7 @@ declare module '@cubejs-client/core' {
|
|
|
783
790
|
timezone?: string;
|
|
784
791
|
renewQuery?: boolean;
|
|
785
792
|
ungrouped?: boolean;
|
|
786
|
-
}
|
|
793
|
+
}
|
|
787
794
|
|
|
788
795
|
export class ProgressResult {
|
|
789
796
|
stage(): string;
|
|
@@ -825,6 +832,7 @@ declare module '@cubejs-client/core' {
|
|
|
825
832
|
title: string;
|
|
826
833
|
shortTitle: string;
|
|
827
834
|
isVisible?: boolean;
|
|
835
|
+
meta?: any;
|
|
828
836
|
};
|
|
829
837
|
|
|
830
838
|
export type BaseCubeMember = {
|
|
@@ -1105,12 +1113,15 @@ declare module '@cubejs-client/core' {
|
|
|
1105
1113
|
|
|
1106
1114
|
export function defaultOrder(query: Query): { [key: string]: QueryOrder };
|
|
1107
1115
|
|
|
1108
|
-
|
|
1116
|
+
export interface TFlatFilter {
|
|
1117
|
+
/**
|
|
1118
|
+
* @deprecated Use `member` instead.
|
|
1119
|
+
*/
|
|
1109
1120
|
dimension?: string;
|
|
1110
1121
|
member?: string;
|
|
1111
1122
|
operator: BinaryOperator;
|
|
1112
1123
|
values: string[];
|
|
1113
|
-
}
|
|
1124
|
+
}
|
|
1114
1125
|
|
|
1115
1126
|
/**
|
|
1116
1127
|
* @hidden
|
|
@@ -1143,3 +1154,5 @@ declare module '@cubejs-client/core' {
|
|
|
1143
1154
|
timeElapsed: number;
|
|
1144
1155
|
};
|
|
1145
1156
|
}
|
|
1157
|
+
|
|
1158
|
+
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.8",
|
|
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": "2bd982f9f7aff8afc071c01015306421a2cd7739"
|
|
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
|
});
|