Skip to content

Commit

Permalink
fix(@cubejs-client/core): improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
hassankhan committed Jan 20, 2020
1 parent 6242b36 commit 92e2ea8
Showing 1 changed file with 46 additions and 19 deletions.
65 changes: 46 additions & 19 deletions packages/cubejs-client-core/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ export type CubeJSApiOptions = {
transport?: TransportInterface;
};

export enum QueryOrderOptions {
ASC = 'asc',
DESC = 'desc',
}
export type LoadMethodOptions = {
mutexKey?: string;
mutexObj?: {};
progressCallback(result: ProgressResult): void;
subscribe?: boolean;
};

export type LoadMethodCallback = (error: Error | null, resultSet: ResultSet) => void;

export type QueryOrder = 'asc' | 'desc';

export type Annotation = {
title: string;
Expand All @@ -27,29 +33,38 @@ export type QueryAnnotations = {
timeDimensions: Record<string, Annotation>;
};

export type LoadResponse = {
export type LoadResponse<T> = {
annotation: QueryAnnotations;
lastRefreshTime: string;
query: Query;
data: any[];
data: T[];
};

export type PivotConfig = {
x?: string[];
y?: string[];
fillMissingDates: boolean | null;
fillMissingDates?: boolean | null;
};

export type Column = {
key: string;
title: string;
}

export class ResultSet<T extends {} = {}> {
static measureFromAxis(axisValues: string[]): string;

loadResponse: LoadResponse;
loadResponse: LoadResponse<T>;

new(loadResponse: LoadResponse): ResultSet;
new(loadResponse: LoadResponse<T>): ResultSet;

series(pivotConfig: PivotConfig): T[];
chartPivot(pivotConfig: PivotConfig): T[];
tablePivot(pivotConfig: PivotConfig): T[];
series(pivotConfig?: PivotConfig): T[];
seriesNames(pivotConfig?: PivotConfig): Column[];

chartPivot(pivotConfig?: PivotConfig): T[];

tablePivot(pivotConfig?: PivotConfig): T[];
tableColumns(pivotConfig?: PivotConfig): Column[];
}

export type Filter = {
Expand Down Expand Up @@ -82,24 +97,36 @@ export type Query = {
limit?: number;
offset?: number;
order?: {
[key: string]: QueryOrderOptions;
[key: string]: QueryOrder;
};
timezone?: string;
renewQuery?: boolean;
ungrouped?: boolean;
};

export type ProgressResponse = {
stage: string;
timeElapsed: number;
}

export class ProgressResult {
new(progressResponse: ProgressResponse): ProgressResult;

stage(): string;
timeElapsed(): string;
}

export class CubejsApi {
new(apiToken: string, options: CubeJSApiOptions): CubejsApi;

load(query: Query, options, callback): void;
load(query: Query, options): Promise<ResultSet>;
load(query: Query, options?: LoadMethodOptions, callback?: LoadMethodCallback): void;
load(query: Query, options?: LoadMethodOptions): Promise<ResultSet>;

sql(query: Query, options, callback): void;
sql(query: Query, options): Promise<ResultSet>;
sql(query: Query, options?: LoadMethodOptions, callback?: LoadMethodCallback): void;
sql(query: Query, options?: LoadMethodOptions): Promise<ResultSet>;

meta(options, callback): void;
meta(options): Promise<ResultSet>;
meta(options?: LoadMethodOptions, callback?: LoadMethodCallback): void;
meta(options?: LoadMethodOptions): Promise<ResultSet>;
}

declare function cubejs(
Expand Down

0 comments on commit 92e2ea8

Please sign in to comment.