@cubejs-client/core 0.29.48 → 0.29.54
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 +40 -0
- package/dist/cubejs-client-core.esm.js +28 -14
- package/dist/cubejs-client-core.esm.js.map +1 -1
- package/dist/cubejs-client-core.js +28 -14
- package/dist/cubejs-client-core.js.map +1 -1
- package/dist/cubejs-client-core.umd.js +41 -27
- package/dist/cubejs-client-core.umd.js.map +1 -1
- package/index.d.ts +66 -18
- package/package.json +2 -2
- package/src/HttpTransport.js +9 -2
- package/src/RequestError.js +2 -1
- package/src/index.js +17 -16
package/index.d.ts
CHANGED
|
@@ -724,11 +724,11 @@ declare module '@cubejs-client/core' {
|
|
|
724
724
|
|
|
725
725
|
export type Filter = BinaryFilter | UnaryFilter | LogicalOrFilter | LogicalAndFilter;
|
|
726
726
|
export type LogicalAndFilter = {
|
|
727
|
-
and:
|
|
727
|
+
and: Filter[];
|
|
728
728
|
};
|
|
729
729
|
|
|
730
730
|
export type LogicalOrFilter = {
|
|
731
|
-
or:
|
|
731
|
+
or: Filter[];
|
|
732
732
|
};
|
|
733
733
|
|
|
734
734
|
export interface BinaryFilter {
|
|
@@ -755,6 +755,8 @@ declare module '@cubejs-client/core' {
|
|
|
755
755
|
| 'notEquals'
|
|
756
756
|
| 'contains'
|
|
757
757
|
| 'notContains'
|
|
758
|
+
| 'startsWith'
|
|
759
|
+
| 'endsWith'
|
|
758
760
|
| 'gt'
|
|
759
761
|
| 'gte'
|
|
760
762
|
| 'lt'
|
|
@@ -786,13 +788,17 @@ declare module '@cubejs-client/core' {
|
|
|
786
788
|
|
|
787
789
|
export type TimeDimension = TimeDimensionComparison | TimeDimensionRanged;
|
|
788
790
|
|
|
791
|
+
type DeeplyReadonly<T> = {
|
|
792
|
+
readonly [K in keyof T]: DeeplyReadonly<T[K]>;
|
|
793
|
+
};
|
|
794
|
+
|
|
789
795
|
export interface Query {
|
|
790
796
|
measures?: string[];
|
|
791
797
|
dimensions?: string[];
|
|
792
798
|
filters?: Filter[];
|
|
793
799
|
timeDimensions?: TimeDimension[];
|
|
794
800
|
segments?: string[];
|
|
795
|
-
limit?: number;
|
|
801
|
+
limit?: null | number;
|
|
796
802
|
offset?: number;
|
|
797
803
|
order?: TQueryOrderObject | TQueryOrderArray;
|
|
798
804
|
timezone?: string;
|
|
@@ -802,6 +808,36 @@ declare module '@cubejs-client/core' {
|
|
|
802
808
|
total?: boolean;
|
|
803
809
|
}
|
|
804
810
|
|
|
811
|
+
export type QueryRecordType<T extends DeeplyReadonly<Query | Query[]>> =
|
|
812
|
+
T extends DeeplyReadonly<Query[]> ? QueryArrayRecordType<T> :
|
|
813
|
+
T extends DeeplyReadonly<Query> ? SingleQueryRecordType<T> :
|
|
814
|
+
never;
|
|
815
|
+
|
|
816
|
+
type QueryArrayRecordType<T extends DeeplyReadonly<Query[]>> =
|
|
817
|
+
T extends readonly [infer First, ...infer Rest]
|
|
818
|
+
? SingleQueryRecordType<First> | QueryArrayRecordType<Rest>
|
|
819
|
+
: never;
|
|
820
|
+
|
|
821
|
+
// If we can't infer any members at all, then return any.
|
|
822
|
+
type SingleQueryRecordType<T extends DeeplyReadonly<Query>> = ExtractMembers<T> extends never
|
|
823
|
+
? any
|
|
824
|
+
: { [K in string & ExtractMembers<T>]: string | number | boolean | null };
|
|
825
|
+
|
|
826
|
+
type ExtractMembers<T extends DeeplyReadonly<Query>> =
|
|
827
|
+
| ( T extends { dimensions: readonly (infer Names)[]; } ? Names : never )
|
|
828
|
+
| ( T extends { measures: readonly (infer Names)[]; } ? Names : never )
|
|
829
|
+
| ( T extends { timeDimensions: (infer U); } ? ExtractTimeMembers<U> : never );
|
|
830
|
+
|
|
831
|
+
type ExtractTimeMembers<T> =
|
|
832
|
+
T extends readonly [infer First, ...infer Rest]
|
|
833
|
+
? ExtractTimeMember<First> | ExtractTimeMembers<Rest>
|
|
834
|
+
: never;
|
|
835
|
+
|
|
836
|
+
type ExtractTimeMember<T> =
|
|
837
|
+
T extends { dimension: infer Dimension, granularity: infer Granularity }
|
|
838
|
+
? Dimension | `${Dimension & string}.${Granularity & string}`
|
|
839
|
+
: never;
|
|
840
|
+
|
|
805
841
|
export class ProgressResult {
|
|
806
842
|
stage(): string;
|
|
807
843
|
timeElapsed(): string;
|
|
@@ -942,7 +978,7 @@ declare module '@cubejs-client/core' {
|
|
|
942
978
|
* If empty query is provided no filtering is done based on query context and all available members are retrieved.
|
|
943
979
|
* @param query - context query to provide filtering of members available to add to this query
|
|
944
980
|
*/
|
|
945
|
-
membersForQuery(query: Query | null, memberType: MemberType): TCubeMeasure[] | TCubeDimension[] | TCubeMember[];
|
|
981
|
+
membersForQuery(query: DeeplyReadonly<Query> | null, memberType: MemberType): TCubeMeasure[] | TCubeDimension[] | TCubeMember[];
|
|
946
982
|
|
|
947
983
|
/**
|
|
948
984
|
* Get meta information for a cube member
|
|
@@ -977,7 +1013,10 @@ declare module '@cubejs-client/core' {
|
|
|
977
1013
|
* @order 2
|
|
978
1014
|
*/
|
|
979
1015
|
export class CubejsApi {
|
|
980
|
-
load
|
|
1016
|
+
load<QueryType extends DeeplyReadonly<Query | Query[]>>(
|
|
1017
|
+
query: QueryType,
|
|
1018
|
+
options?: LoadMethodOptions,
|
|
1019
|
+
): Promise<ResultSet<QueryRecordType<QueryType>>>;
|
|
981
1020
|
/**
|
|
982
1021
|
* Fetch data for the passed `query`.
|
|
983
1022
|
*
|
|
@@ -1002,13 +1041,18 @@ declare module '@cubejs-client/core' {
|
|
|
1002
1041
|
* ```
|
|
1003
1042
|
* @param query - [Query object](query-format)
|
|
1004
1043
|
*/
|
|
1005
|
-
load
|
|
1006
|
-
|
|
1007
|
-
|
|
1044
|
+
load<QueryType extends DeeplyReadonly<Query | Query[]>>(
|
|
1045
|
+
query: QueryType,
|
|
1046
|
+
options?: LoadMethodOptions,
|
|
1047
|
+
callback?: LoadMethodCallback<ResultSet<QueryRecordType<QueryType>>>,
|
|
1048
|
+
): void;
|
|
1049
|
+
|
|
1050
|
+
load<QueryType extends DeeplyReadonly<Query | Query[]>>(
|
|
1051
|
+
query: QueryType,
|
|
1008
1052
|
options?: LoadMethodOptions,
|
|
1009
1053
|
callback?: LoadMethodCallback<ResultSet>,
|
|
1010
1054
|
responseFormat?: string
|
|
1011
|
-
): Promise<ResultSet
|
|
1055
|
+
): Promise<ResultSet<QueryRecordType<QueryType>>>;
|
|
1012
1056
|
|
|
1013
1057
|
/**
|
|
1014
1058
|
* Allows you to fetch data and receive updates over time. See [Real-Time Data Fetch](real-time-data-fetch)
|
|
@@ -1034,14 +1078,18 @@ declare module '@cubejs-client/core' {
|
|
|
1034
1078
|
* );
|
|
1035
1079
|
* ```
|
|
1036
1080
|
*/
|
|
1037
|
-
subscribe
|
|
1081
|
+
subscribe<QueryType extends DeeplyReadonly<Query | Query[]>>(
|
|
1082
|
+
query: QueryType,
|
|
1083
|
+
options: LoadMethodOptions | null,
|
|
1084
|
+
callback: LoadMethodCallback<ResultSet<QueryRecordType<QueryType>>>,
|
|
1085
|
+
): void;
|
|
1038
1086
|
|
|
1039
|
-
sql(query: Query | Query[]
|
|
1087
|
+
sql(query: DeeplyReadonly<Query | Query[]>, options?: LoadMethodOptions): Promise<SqlQuery>;
|
|
1040
1088
|
/**
|
|
1041
1089
|
* Get generated SQL string for the given `query`.
|
|
1042
1090
|
* @param query - [Query object](query-format)
|
|
1043
1091
|
*/
|
|
1044
|
-
sql(query: Query | Query[]
|
|
1092
|
+
sql(query: DeeplyReadonly<Query | Query[]>, options?: LoadMethodOptions, callback?: LoadMethodCallback<SqlQuery>): void;
|
|
1045
1093
|
|
|
1046
1094
|
meta(options?: LoadMethodOptions): Promise<Meta>;
|
|
1047
1095
|
/**
|
|
@@ -1049,11 +1097,11 @@ declare module '@cubejs-client/core' {
|
|
|
1049
1097
|
*/
|
|
1050
1098
|
meta(options?: LoadMethodOptions, callback?: LoadMethodCallback<Meta>): void;
|
|
1051
1099
|
|
|
1052
|
-
dryRun(query: Query | Query[]
|
|
1100
|
+
dryRun(query: DeeplyReadonly<Query | Query[]>, options?: LoadMethodOptions): Promise<DryRunResponse>;
|
|
1053
1101
|
/**
|
|
1054
1102
|
* Get query related meta without query execution
|
|
1055
1103
|
*/
|
|
1056
|
-
dryRun(query: Query | Query[]
|
|
1104
|
+
dryRun(query: DeeplyReadonly<Query | Query[]>, options: LoadMethodOptions, callback?: LoadMethodCallback<DryRunResponse>): void;
|
|
1057
1105
|
}
|
|
1058
1106
|
|
|
1059
1107
|
/**
|
|
@@ -1115,7 +1163,7 @@ declare module '@cubejs-client/core' {
|
|
|
1115
1163
|
/**
|
|
1116
1164
|
* @hidden
|
|
1117
1165
|
*/
|
|
1118
|
-
export function isQueryPresent(query: Query | Query[] | null | undefined): boolean;
|
|
1166
|
+
export function isQueryPresent(query: DeeplyReadonly<Query | Query[]> | null | undefined): boolean;
|
|
1119
1167
|
export function movePivotItem(
|
|
1120
1168
|
pivotConfig: PivotConfig,
|
|
1121
1169
|
sourceIndex: number,
|
|
@@ -1128,7 +1176,7 @@ declare module '@cubejs-client/core' {
|
|
|
1128
1176
|
*/
|
|
1129
1177
|
export function moveItemInArray<T = any>(list: T[], sourceIndex: number, destinationIndex: number): T[];
|
|
1130
1178
|
|
|
1131
|
-
export function defaultOrder(query: Query): { [key: string]: QueryOrder };
|
|
1179
|
+
export function defaultOrder(query: DeeplyReadonly<Query>): { [key: string]: QueryOrder };
|
|
1132
1180
|
|
|
1133
1181
|
export interface TFlatFilter {
|
|
1134
1182
|
/**
|
|
@@ -1162,9 +1210,9 @@ declare module '@cubejs-client/core' {
|
|
|
1162
1210
|
/**
|
|
1163
1211
|
* @hidden
|
|
1164
1212
|
*/
|
|
1165
|
-
export function getQueryMembers(query: Query): string[];
|
|
1213
|
+
export function getQueryMembers(query: DeeplyReadonly<Query>): string[];
|
|
1166
1214
|
|
|
1167
|
-
export function areQueriesEqual(query1: Query | null, query2: Query | null): boolean;
|
|
1215
|
+
export function areQueriesEqual(query1: DeeplyReadonly<Query> | null, query2: DeeplyReadonly<Query> | null): boolean;
|
|
1168
1216
|
|
|
1169
1217
|
export type ProgressResponse = {
|
|
1170
1218
|
stage: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubejs-client/core",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.54",
|
|
4
4
|
"engines": {},
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"eslint-plugin-node": "^5.2.1",
|
|
47
47
|
"jest": "^26.0.1"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c5383fcfaaa088e6ca09cee3384da163d3ad6af5"
|
|
50
50
|
}
|
package/src/HttpTransport.js
CHANGED
|
@@ -40,9 +40,16 @@ class HttpTransport {
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
return {
|
|
43
|
+
/* eslint no-unsafe-finally: off */
|
|
43
44
|
async subscribe(callback) {
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
let result = {
|
|
46
|
+
error: 'network Error' // add default error message
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
result = await runRequest();
|
|
50
|
+
} finally {
|
|
51
|
+
return callback(result, () => this.subscribe(callback));
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
};
|
|
48
55
|
}
|
package/src/RequestError.js
CHANGED
package/src/index.js
CHANGED
|
@@ -56,7 +56,7 @@ class CubejsApi {
|
|
|
56
56
|
});
|
|
57
57
|
this.pollInterval = options.pollInterval || 5;
|
|
58
58
|
this.parseDateMeasures = options.parseDateMeasures;
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
this.updateAuthorizationPromise = null;
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -73,7 +73,7 @@ class CubejsApi {
|
|
|
73
73
|
callback = options;
|
|
74
74
|
options = undefined;
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
options = options || {};
|
|
78
78
|
|
|
79
79
|
const mutexKey = options.mutexKey || 'default';
|
|
@@ -127,11 +127,11 @@ class CubejsApi {
|
|
|
127
127
|
}
|
|
128
128
|
return null;
|
|
129
129
|
};
|
|
130
|
-
|
|
130
|
+
|
|
131
131
|
if (options.subscribe && !skipAuthorizationUpdate) {
|
|
132
132
|
await this.updateTransportAuthorization();
|
|
133
133
|
}
|
|
134
|
-
|
|
134
|
+
|
|
135
135
|
skipAuthorizationUpdate = false;
|
|
136
136
|
|
|
137
137
|
if (response.status === 502) {
|
|
@@ -162,7 +162,7 @@ class CubejsApi {
|
|
|
162
162
|
await requestInstance.unsubscribe();
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
const error = new RequestError(body.error, body); // TODO error class
|
|
165
|
+
const error = new RequestError(body.error, body, response.status); // TODO error class
|
|
166
166
|
if (callback) {
|
|
167
167
|
callback(error);
|
|
168
168
|
} else {
|
|
@@ -209,7 +209,7 @@ class CubejsApi {
|
|
|
209
209
|
await this.updateAuthorizationPromise;
|
|
210
210
|
return;
|
|
211
211
|
}
|
|
212
|
-
|
|
212
|
+
|
|
213
213
|
if (typeof this.apiToken === 'function') {
|
|
214
214
|
this.updateAuthorizationPromise = new Promise(async (resolve, reject) => {
|
|
215
215
|
try {
|
|
@@ -224,7 +224,7 @@ class CubejsApi {
|
|
|
224
224
|
this.updateAuthorizationPromise = null;
|
|
225
225
|
}
|
|
226
226
|
});
|
|
227
|
-
|
|
227
|
+
|
|
228
228
|
await this.updateAuthorizationPromise;
|
|
229
229
|
}
|
|
230
230
|
}
|
|
@@ -241,7 +241,12 @@ class CubejsApi {
|
|
|
241
241
|
responseFormat === ResultType.COMPACT &&
|
|
242
242
|
query.responseFormat !== ResultType.COMPACT
|
|
243
243
|
) {
|
|
244
|
-
|
|
244
|
+
return {
|
|
245
|
+
...query,
|
|
246
|
+
responseFormat: ResultType.COMPACT,
|
|
247
|
+
};
|
|
248
|
+
} else {
|
|
249
|
+
return query;
|
|
245
250
|
}
|
|
246
251
|
}
|
|
247
252
|
|
|
@@ -287,11 +292,9 @@ class CubejsApi {
|
|
|
287
292
|
load(query, options, callback, responseFormat = ResultType.DEFAULT) {
|
|
288
293
|
if (responseFormat === ResultType.COMPACT) {
|
|
289
294
|
if (Array.isArray(query)) {
|
|
290
|
-
query.
|
|
291
|
-
this.patchQueryInternal(q, ResultType.COMPACT);
|
|
292
|
-
});
|
|
295
|
+
query = query.map((q) => this.patchQueryInternal(q, ResultType.COMPACT));
|
|
293
296
|
} else {
|
|
294
|
-
this.patchQueryInternal(query, ResultType.COMPACT);
|
|
297
|
+
query = this.patchQueryInternal(query, ResultType.COMPACT);
|
|
295
298
|
}
|
|
296
299
|
}
|
|
297
300
|
return this.loadMethod(
|
|
@@ -318,11 +321,9 @@ class CubejsApi {
|
|
|
318
321
|
subscribe(query, options, callback, responseFormat = ResultType.DEFAULT) {
|
|
319
322
|
if (responseFormat === ResultType.COMPACT) {
|
|
320
323
|
if (Array.isArray(query)) {
|
|
321
|
-
query.
|
|
322
|
-
this.patchQueryInternal(q, ResultType.COMPACT);
|
|
323
|
-
});
|
|
324
|
+
query = query.map((q) => this.patchQueryInternal(q, ResultType.COMPACT));
|
|
324
325
|
} else {
|
|
325
|
-
this.patchQueryInternal(query, ResultType.COMPACT);
|
|
326
|
+
query = this.patchQueryInternal(query, ResultType.COMPACT);
|
|
326
327
|
}
|
|
327
328
|
}
|
|
328
329
|
return this.loadMethod(
|