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 21, 2020
1 parent 6242b36 commit 7c0748a
Showing 1 changed file with 84 additions and 19 deletions.
103 changes: 84 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<T> = (error: Error | null, resultSet: T) => 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,74 @@ 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;
}

type PrimitiveValue = boolean | string | number;
export type SqlQueryTuple = [string, PrimitiveValue];

export type SqlApiResponse = {
sql: {
aliasNameToMember: Record<string, string>;
cacheKeyQueries: {
queries: SqlQueryTuple[];
};
dataSource: boolean;
external: boolean;
sql: SqlQueryTuple;
};
}

export class SqlQuery {
new(sqlQuery: SqlApiResponse): SqlQuery;

rawQuery(): string;
sql(): string;
}

export type Cube = {
dimensions: Record<string, PrimitiveValue>[];
measures: Record<string, PrimitiveValue>[];
name: string;
segments: Record<string, PrimitiveValue>[];
title: string;
};

export type MetaApiResponse = {
cubes: Cube[];
};

export class Meta {
new(metaResponse: MetaApiResponse): Meta;
}

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<ResultSet>): 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<SqlQuery>): void;
sql(query: Query, options?: LoadMethodOptions): Promise<SqlQuery>;

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

declare function cubejs(
Expand Down

0 comments on commit 7c0748a

Please sign in to comment.