@cubejs-client/core 0.28.35 → 0.28.52
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 +15 -10
- package/dist/cubejs-client-core.esm.js.map +1 -1
- package/dist/cubejs-client-core.js +15 -10
- package/dist/cubejs-client-core.js.map +1 -1
- package/dist/cubejs-client-core.umd.js +15 -10
- package/dist/cubejs-client-core.umd.js.map +1 -1
- package/index.d.ts +30 -8
- package/package.json +2 -2
- package/src/ResultSet.js +10 -10
- package/src/tests/granularity.test.js +110 -1
package/index.d.ts
CHANGED
|
@@ -94,6 +94,10 @@ declare module '@cubejs-client/core' {
|
|
|
94
94
|
* Pass `true` to use continuous fetch behavior.
|
|
95
95
|
*/
|
|
96
96
|
subscribe?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* A Cube.js API instance. If not provided will be taken from `CubeProvider`
|
|
99
|
+
*/
|
|
100
|
+
cubejsApi?: CubejsApi;
|
|
97
101
|
/**
|
|
98
102
|
* Function that receives `ProgressResult` on each `Continue wait` message.
|
|
99
103
|
*/
|
|
@@ -144,7 +148,7 @@ declare module '@cubejs-client/core' {
|
|
|
144
148
|
type UsedPreAggregation = {
|
|
145
149
|
targetTableName: string;
|
|
146
150
|
type: PreAggregationType;
|
|
147
|
-
}
|
|
151
|
+
};
|
|
148
152
|
|
|
149
153
|
type LoadResponseResult<T> = {
|
|
150
154
|
annotation: QueryAnnotations;
|
|
@@ -154,6 +158,7 @@ declare module '@cubejs-client/core' {
|
|
|
154
158
|
external: boolean | null;
|
|
155
159
|
dbType: string;
|
|
156
160
|
extDbType: string;
|
|
161
|
+
requestId?: string,
|
|
157
162
|
usedPreAggregations?: Record<string, UsedPreAggregation>;
|
|
158
163
|
transformedQuery?: TransformedQuery;
|
|
159
164
|
};
|
|
@@ -710,11 +715,11 @@ declare module '@cubejs-client/core' {
|
|
|
710
715
|
|
|
711
716
|
export type Filter = BinaryFilter | UnaryFilter | LogicalOrFilter | LogicalAndFilter;
|
|
712
717
|
type LogicalAndFilter = {
|
|
713
|
-
and: (BinaryFilter | UnaryFilter | LogicalOrFilter)[]
|
|
718
|
+
and: (BinaryFilter | UnaryFilter | LogicalOrFilter)[];
|
|
714
719
|
};
|
|
715
720
|
|
|
716
721
|
type LogicalOrFilter = {
|
|
717
|
-
or: (BinaryFilter | UnaryFilter | LogicalAndFilter)[]
|
|
722
|
+
or: (BinaryFilter | UnaryFilter | LogicalAndFilter)[];
|
|
718
723
|
};
|
|
719
724
|
|
|
720
725
|
type BinaryFilter = {
|
|
@@ -812,14 +817,25 @@ declare module '@cubejs-client/core' {
|
|
|
812
817
|
|
|
813
818
|
type TCubeMemberType = 'time' | 'number' | 'string' | 'boolean';
|
|
814
819
|
|
|
820
|
+
// @see BaseCubeMember
|
|
821
|
+
// @depreacated
|
|
815
822
|
export type TCubeMember = {
|
|
816
823
|
type: TCubeMemberType;
|
|
817
824
|
name: string;
|
|
818
825
|
title: string;
|
|
819
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;
|
|
820
836
|
};
|
|
821
837
|
|
|
822
|
-
export type TCubeMeasure =
|
|
838
|
+
export type TCubeMeasure = BaseCubeMember & {
|
|
823
839
|
aggType: 'count' | 'number';
|
|
824
840
|
cumulative: boolean;
|
|
825
841
|
cumulativeTotal: boolean;
|
|
@@ -830,11 +846,11 @@ declare module '@cubejs-client/core' {
|
|
|
830
846
|
};
|
|
831
847
|
};
|
|
832
848
|
|
|
833
|
-
export type TCubeDimension =
|
|
849
|
+
export type TCubeDimension = BaseCubeMember & {
|
|
834
850
|
suggestFilterValues: boolean;
|
|
835
851
|
};
|
|
836
852
|
|
|
837
|
-
export type TCubeSegment =
|
|
853
|
+
export type TCubeSegment = Omit<BaseCubeMember, 'type'>;
|
|
838
854
|
|
|
839
855
|
type TCubeMemberByType<T> = T extends 'measures'
|
|
840
856
|
? TCubeMeasure
|
|
@@ -844,6 +860,8 @@ declare module '@cubejs-client/core' {
|
|
|
844
860
|
? TCubeSegment
|
|
845
861
|
: never;
|
|
846
862
|
|
|
863
|
+
export type CubeMember = TCubeMeasure | TCubeDimension | TCubeSegment;
|
|
864
|
+
|
|
847
865
|
/**
|
|
848
866
|
* @deprecated use DryRunResponse
|
|
849
867
|
*/
|
|
@@ -852,7 +870,7 @@ declare module '@cubejs-client/core' {
|
|
|
852
870
|
normalizedQueries: Query[];
|
|
853
871
|
pivotQuery: PivotQuery;
|
|
854
872
|
queryOrder: Array<{ [k: string]: QueryOrder }>;
|
|
855
|
-
transformedQueries: TransformedQuery[]
|
|
873
|
+
transformedQueries: TransformedQuery[];
|
|
856
874
|
};
|
|
857
875
|
|
|
858
876
|
export type DryRunResponse = {
|
|
@@ -860,6 +878,7 @@ declare module '@cubejs-client/core' {
|
|
|
860
878
|
normalizedQueries: Query[];
|
|
861
879
|
pivotQuery: PivotQuery;
|
|
862
880
|
queryOrder: Array<{ [k: string]: QueryOrder }>;
|
|
881
|
+
transformedQueries: TransformedQuery[];
|
|
863
882
|
};
|
|
864
883
|
|
|
865
884
|
export type Cube = {
|
|
@@ -928,6 +947,9 @@ declare module '@cubejs-client/core' {
|
|
|
928
947
|
): { title: string; error: string } | TCubeMemberByType<T>;
|
|
929
948
|
defaultTimeDimensionNameFor(memberName: string): string;
|
|
930
949
|
filterOperatorsForMember(memberName: string, memberType: MemberType | MemberType[]): FilterOperator[];
|
|
950
|
+
|
|
951
|
+
// todo: types
|
|
952
|
+
membersGroupedByCube(): any;
|
|
931
953
|
}
|
|
932
954
|
|
|
933
955
|
/**
|
|
@@ -1068,7 +1090,7 @@ declare module '@cubejs-client/core' {
|
|
|
1068
1090
|
/**
|
|
1069
1091
|
* @hidden
|
|
1070
1092
|
*/
|
|
1071
|
-
export function isQueryPresent(query: Query | Query[]): boolean;
|
|
1093
|
+
export function isQueryPresent(query: Query | Query[] | null | undefined): boolean;
|
|
1072
1094
|
export function movePivotItem(
|
|
1073
1095
|
pivotConfig: PivotConfig,
|
|
1074
1096
|
sourceIndex: number,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubejs-client/core",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.52",
|
|
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": "22f1fcf3dc77d5784eda6b8eff8bcd430652cc69"
|
|
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
|
|
|
@@ -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
|
});
|