@@ -9,10 +9,16 @@ export type CubeJSApiOptions = {
9
9
transport ?: TransportInterface ;
10
10
} ;
11
11
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' ;
16
22
17
23
export type Annotation = {
18
24
title : string ;
@@ -27,29 +33,38 @@ export type QueryAnnotations = {
27
33
timeDimensions : Record < string , Annotation > ;
28
34
} ;
29
35
30
- export type LoadResponse = {
36
+ export type LoadResponse < T > = {
31
37
annotation : QueryAnnotations ;
32
38
lastRefreshTime : string ;
33
39
query : Query ;
34
- data : any [ ] ;
40
+ data : T [ ] ;
35
41
} ;
36
42
37
43
export type PivotConfig = {
38
44
x ?: string [ ] ;
39
45
y ?: string [ ] ;
40
- fillMissingDates : boolean | null ;
46
+ fillMissingDates ? : boolean | null ;
41
47
} ;
42
48
49
+ export type Column = {
50
+ key : string ;
51
+ title : string ;
52
+ }
53
+
43
54
export class ResultSet < T extends { } = { } > {
44
55
static measureFromAxis ( axisValues : string [ ] ) : string ;
45
56
46
- loadResponse : LoadResponse ;
57
+ loadResponse : LoadResponse < T > ;
47
58
48
- new ( loadResponse : LoadResponse ) : ResultSet ;
59
+ new ( loadResponse : LoadResponse < T > ) : ResultSet ;
49
60
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 [ ] ;
53
68
}
54
69
55
70
export type Filter = {
@@ -82,24 +97,64 @@ export type Query = {
82
97
limit ?: number ;
83
98
offset ?: number ;
84
99
order ?: {
85
- [ key : string ] : QueryOrderOptions ;
100
+ [ key : string ] : QueryOrder ;
86
101
} ;
87
102
timezone ?: string ;
88
103
renewQuery ?: boolean ;
89
104
ungrouped ?: boolean ;
90
105
} ;
91
106
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
+
92
147
export class CubejsApi {
93
148
new ( apiToken : string , options : CubeJSApiOptions ) : CubejsApi ;
94
149
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 > ;
97
152
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 > ;
100
155
101
- meta ( options , callback ) : void ;
102
- meta ( options ) : Promise < ResultSet > ;
156
+ meta ( options ?: LoadMethodOptions , callback ?: LoadMethodCallback < Meta > ) : void ;
157
+ meta ( options ?: LoadMethodOptions ) : Promise < Meta > ;
103
158
}
104
159
105
160
declare function cubejs (
0 commit comments