Skip to content

Commit 55edf85

Browse files
committed
fix(@cubejs-client/core): improve types
Fixes #350
1 parent 6242b36 commit 55edf85

File tree

1 file changed

+74
-19
lines changed

1 file changed

+74
-19
lines changed

packages/cubejs-client-core/dist/index.d.ts

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ export type CubeJSApiOptions = {
99
transport?: TransportInterface;
1010
};
1111

12-
export enum QueryOrderOptions {
13-
ASC = 'asc',
14-
DESC = 'desc',
15-
}
12+
export type LoadMethodOptions = {
13+
mutexKey?: string;
14+
mutexObj?: {};
15+
progressCallback(result: ProgressResult): void;
16+
subscribe?: boolean;
17+
};
18+
19+
export type LoadMethodCallback<T> = (error: Error | null, resultSet: T) => void;
20+
21+
export type QueryOrder = 'asc' | 'desc';
1622

1723
export type Annotation = {
1824
title: string;
@@ -27,29 +33,38 @@ export type QueryAnnotations = {
2733
timeDimensions: Record<string, Annotation>;
2834
};
2935

30-
export type LoadResponse = {
36+
export type LoadResponse<T> = {
3137
annotation: QueryAnnotations;
3238
lastRefreshTime: string;
3339
query: Query;
34-
data: any[];
40+
data: T[];
3541
};
3642

3743
export type PivotConfig = {
3844
x?: string[];
3945
y?: string[];
40-
fillMissingDates: boolean | null;
46+
fillMissingDates?: boolean | null;
4147
};
4248

49+
export type Column = {
50+
key: string;
51+
title: string;
52+
}
53+
4354
export class ResultSet<T extends {} = {}> {
4455
static measureFromAxis(axisValues: string[]): string;
4556

46-
loadResponse: LoadResponse;
57+
loadResponse: LoadResponse<T>;
4758

48-
new(loadResponse: LoadResponse): ResultSet;
59+
new(loadResponse: LoadResponse<T>): ResultSet;
4960

50-
series(pivotConfig: PivotConfig): T[];
51-
chartPivot(pivotConfig: PivotConfig): T[];
52-
tablePivot(pivotConfig: PivotConfig): T[];
61+
series(pivotConfig?: PivotConfig): T[];
62+
seriesNames(pivotConfig?: PivotConfig): Column[];
63+
64+
chartPivot(pivotConfig?: PivotConfig): T[];
65+
66+
tablePivot(pivotConfig?: PivotConfig): T[];
67+
tableColumns(pivotConfig?: PivotConfig): Column[];
5368
}
5469

5570
export type Filter = {
@@ -82,24 +97,64 @@ export type Query = {
8297
limit?: number;
8398
offset?: number;
8499
order?: {
85-
[key: string]: QueryOrderOptions;
100+
[key: string]: QueryOrder;
86101
};
87102
timezone?: string;
88103
renewQuery?: boolean;
89104
ungrouped?: boolean;
90105
};
91106

107+
export type ProgressResponse = {
108+
stage: string;
109+
timeElapsed: number;
110+
}
111+
112+
export class ProgressResult {
113+
new(progressResponse: ProgressResponse): ProgressResult;
114+
115+
stage(): string;
116+
timeElapsed(): string;
117+
}
118+
119+
type PrimitiveValue = boolean | string | number;
120+
export type SqlQueryTuple = [string, PrimitiveValue];
121+
122+
export type SqlData = {
123+
aliasNameToMember: Record<string, string>;
124+
cacheKeyQueries: {
125+
queries: SqlQueryTuple[];
126+
};
127+
dataSource: boolean;
128+
external: boolean;
129+
sql: SqlQueryTuple;
130+
};
131+
132+
export type SqlApiResponse = {
133+
sql: SqlData;
134+
}
135+
136+
export class SqlQuery {
137+
new(sqlQuery: SqlApiResponse): SqlQuery;
138+
139+
rawQuery(): SqlData;
140+
sql(): string;
141+
}
142+
143+
export class Meta {
144+
new(metaResponse: {}): Meta;
145+
}
146+
92147
export class CubejsApi {
93148
new(apiToken: string, options: CubeJSApiOptions): CubejsApi;
94149

95-
load(query: Query, options, callback): void;
96-
load(query: Query, options): Promise<ResultSet>;
150+
load(query: Query, options?: LoadMethodOptions, callback?: LoadMethodCallback<ResultSet>): void;
151+
load(query: Query, options?: LoadMethodOptions): Promise<ResultSet>;
97152

98-
sql(query: Query, options, callback): void;
99-
sql(query: Query, options): Promise<ResultSet>;
153+
sql(query: Query, options?: LoadMethodOptions, callback?: LoadMethodCallback<SqlQuery>): void;
154+
sql(query: Query, options?: LoadMethodOptions): Promise<SqlQuery>;
100155

101-
meta(options, callback): void;
102-
meta(options): Promise<ResultSet>;
156+
meta(options?: LoadMethodOptions, callback?: LoadMethodCallback<Meta>): void;
157+
meta(options?: LoadMethodOptions): Promise<Meta>;
103158
}
104159

105160
declare function cubejs(

0 commit comments

Comments
 (0)