|
| 1 | +export interface TransportInterface { |
| 2 | + request(method: string, params: any): () => Promise<void>; |
| 3 | +} |
| 4 | + |
| 5 | +export type CubeJSApiOptions = { |
| 6 | + apiUrl: string; |
| 7 | + headers?: Record<string, string>; |
| 8 | + pollInterval?: number; |
| 9 | + transport?: TransportInterface; |
| 10 | +}; |
| 11 | + |
| 12 | +export enum QueryOrderOptions { |
| 13 | + ASC = 'asc', |
| 14 | + DESC = 'desc', |
| 15 | +} |
| 16 | + |
| 17 | +export type Annotation = { |
| 18 | + title: string; |
| 19 | + shortTitle: string; |
| 20 | + type: string; |
| 21 | + format?: 'currency' | 'percentage'; |
| 22 | +}; |
| 23 | + |
| 24 | +export type QueryAnnotations = { |
| 25 | + dimensions: Record<string, Annotation>; |
| 26 | + measures: Record<string, Annotation>; |
| 27 | + timeDimensions: Record<string, Annotation>; |
| 28 | +}; |
| 29 | + |
| 30 | +export type LoadResponse = { |
| 31 | + annotation: QueryAnnotations; |
| 32 | + lastRefreshTime: string; |
| 33 | + query: Query; |
| 34 | + data: any[]; |
| 35 | +}; |
| 36 | + |
| 37 | +export type PivotConfig = { |
| 38 | + x?: string[]; |
| 39 | + y?: string[]; |
| 40 | + fillMissingDates: boolean | null; |
| 41 | +}; |
| 42 | + |
| 43 | +export class ResultSet<T extends {} = {}> { |
| 44 | + static measureFromAxis(axisValues: string[]): string; |
| 45 | + |
| 46 | + loadResponse: LoadResponse; |
| 47 | + |
| 48 | + new(loadResponse: LoadResponse): ResultSet; |
| 49 | + |
| 50 | + series(pivotConfig: PivotConfig): T[]; |
| 51 | + chartPivot(pivotConfig: PivotConfig): T[]; |
| 52 | + tablePivot(pivotConfig: PivotConfig): T[]; |
| 53 | +} |
| 54 | + |
| 55 | +export type Filter = { |
| 56 | + dimension?: string; |
| 57 | + member?: string; |
| 58 | + operator: string; |
| 59 | + values?: string[]; |
| 60 | +}; |
| 61 | + |
| 62 | +export enum TimeDimensionGranularities { |
| 63 | + HOUR = 'hour', |
| 64 | + DAY = 'day', |
| 65 | + WEEK = 'week', |
| 66 | + MONTH = 'month', |
| 67 | + YEAR = 'year', |
| 68 | +} |
| 69 | + |
| 70 | +export type TimeDimension = { |
| 71 | + dimension: string; |
| 72 | + dateRange?: string | string[]; |
| 73 | + granularity?: TimeDimensionGranularities; |
| 74 | +}; |
| 75 | + |
| 76 | +export type Query = { |
| 77 | + measures?: string[]; |
| 78 | + dimensions?: string[]; |
| 79 | + filters?: Filter[]; |
| 80 | + timeDimensions?: TimeDimension[]; |
| 81 | + segments?: string[]; |
| 82 | + limit?: number; |
| 83 | + offset?: number; |
| 84 | + order?: { |
| 85 | + [key: string]: QueryOrderOptions; |
| 86 | + }; |
| 87 | + timezone?: string; |
| 88 | + renewQuery?: boolean; |
| 89 | + ungrouped?: boolean; |
| 90 | +}; |
| 91 | + |
| 92 | +export class CubejsApi { |
| 93 | + new(apiToken: string, options: CubeJSApiOptions): CubejsApi; |
| 94 | + |
| 95 | + load(query: Query, options, callback): void; |
| 96 | + load(query: Query, options): Promise<ResultSet>; |
| 97 | + |
| 98 | + sql(query: Query, options, callback): void; |
| 99 | + sql(query: Query, options): Promise<ResultSet>; |
| 100 | + |
| 101 | + meta(options, callback): void; |
| 102 | + meta(options): Promise<ResultSet>; |
| 103 | +} |
| 104 | + |
| 105 | +declare function cubejs( |
| 106 | + apiToken: string, |
| 107 | + options: CubeJSApiOptions, |
| 108 | +): CubejsApi; |
| 109 | + |
| 110 | +export default cubejs; |
0 commit comments