@cubejs-client/core 0.28.37 → 0.29.0
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 +51 -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 +21 -7
- package/package.json +2 -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
|
@@ -148,7 +148,7 @@ declare module '@cubejs-client/core' {
|
|
|
148
148
|
type UsedPreAggregation = {
|
|
149
149
|
targetTableName: string;
|
|
150
150
|
type: PreAggregationType;
|
|
151
|
-
}
|
|
151
|
+
};
|
|
152
152
|
|
|
153
153
|
type LoadResponseResult<T> = {
|
|
154
154
|
annotation: QueryAnnotations;
|
|
@@ -158,6 +158,7 @@ declare module '@cubejs-client/core' {
|
|
|
158
158
|
external: boolean | null;
|
|
159
159
|
dbType: string;
|
|
160
160
|
extDbType: string;
|
|
161
|
+
requestId?: string,
|
|
161
162
|
usedPreAggregations?: Record<string, UsedPreAggregation>;
|
|
162
163
|
transformedQuery?: TransformedQuery;
|
|
163
164
|
};
|
|
@@ -714,11 +715,11 @@ declare module '@cubejs-client/core' {
|
|
|
714
715
|
|
|
715
716
|
export type Filter = BinaryFilter | UnaryFilter | LogicalOrFilter | LogicalAndFilter;
|
|
716
717
|
type LogicalAndFilter = {
|
|
717
|
-
and: (BinaryFilter | UnaryFilter | LogicalOrFilter)[]
|
|
718
|
+
and: (BinaryFilter | UnaryFilter | LogicalOrFilter)[];
|
|
718
719
|
};
|
|
719
720
|
|
|
720
721
|
type LogicalOrFilter = {
|
|
721
|
-
or: (BinaryFilter | UnaryFilter | LogicalAndFilter)[]
|
|
722
|
+
or: (BinaryFilter | UnaryFilter | LogicalAndFilter)[];
|
|
722
723
|
};
|
|
723
724
|
|
|
724
725
|
type BinaryFilter = {
|
|
@@ -816,14 +817,25 @@ declare module '@cubejs-client/core' {
|
|
|
816
817
|
|
|
817
818
|
type TCubeMemberType = 'time' | 'number' | 'string' | 'boolean';
|
|
818
819
|
|
|
820
|
+
// @see BaseCubeMember
|
|
821
|
+
// @depreacated
|
|
819
822
|
export type TCubeMember = {
|
|
820
823
|
type: TCubeMemberType;
|
|
821
824
|
name: string;
|
|
822
825
|
title: string;
|
|
823
826
|
shortTitle: string;
|
|
827
|
+
isVisible?: boolean;
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
export type BaseCubeMember = {
|
|
831
|
+
type: TCubeMemberType;
|
|
832
|
+
name: string;
|
|
833
|
+
title: string;
|
|
834
|
+
shortTitle: string;
|
|
835
|
+
isVisible?: boolean;
|
|
824
836
|
};
|
|
825
837
|
|
|
826
|
-
export type TCubeMeasure =
|
|
838
|
+
export type TCubeMeasure = BaseCubeMember & {
|
|
827
839
|
aggType: 'count' | 'number';
|
|
828
840
|
cumulative: boolean;
|
|
829
841
|
cumulativeTotal: boolean;
|
|
@@ -834,11 +846,11 @@ declare module '@cubejs-client/core' {
|
|
|
834
846
|
};
|
|
835
847
|
};
|
|
836
848
|
|
|
837
|
-
export type TCubeDimension =
|
|
849
|
+
export type TCubeDimension = BaseCubeMember & {
|
|
838
850
|
suggestFilterValues: boolean;
|
|
839
851
|
};
|
|
840
852
|
|
|
841
|
-
export type TCubeSegment =
|
|
853
|
+
export type TCubeSegment = Omit<BaseCubeMember, 'type'>;
|
|
842
854
|
|
|
843
855
|
type TCubeMemberByType<T> = T extends 'measures'
|
|
844
856
|
? TCubeMeasure
|
|
@@ -848,6 +860,8 @@ declare module '@cubejs-client/core' {
|
|
|
848
860
|
? TCubeSegment
|
|
849
861
|
: never;
|
|
850
862
|
|
|
863
|
+
export type CubeMember = TCubeMeasure | TCubeDimension | TCubeSegment;
|
|
864
|
+
|
|
851
865
|
/**
|
|
852
866
|
* @deprecated use DryRunResponse
|
|
853
867
|
*/
|
|
@@ -856,7 +870,7 @@ declare module '@cubejs-client/core' {
|
|
|
856
870
|
normalizedQueries: Query[];
|
|
857
871
|
pivotQuery: PivotQuery;
|
|
858
872
|
queryOrder: Array<{ [k: string]: QueryOrder }>;
|
|
859
|
-
transformedQueries: TransformedQuery[]
|
|
873
|
+
transformedQueries: TransformedQuery[];
|
|
860
874
|
};
|
|
861
875
|
|
|
862
876
|
export type DryRunResponse = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubejs-client/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"engines": {},
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"eslint-plugin-node": "^5.2.1",
|
|
46
46
|
"jest": "^26.0.1"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "15502010fedcb085860d4f35267a57a6d60aa9ab"
|
|
49
49
|
}
|
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
|
});
|