Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript generics for main Client methods #403

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export class Client extends events.EventEmitter {

connect(callback: EmptyCallback): void;

execute(query: string, params?: ArrayOrObject, options?: QueryOptions): Promise<types.ResultSet>;
execute<T = any>(query: string, params?: ArrayOrObject, options?: QueryOptions): Promise<types.ResultSet<T>>;

execute(query: string, params: ArrayOrObject, options: QueryOptions, callback: ValueCallback<types.ResultSet>): void;
execute<T = any>(query: string, params: ArrayOrObject, options: QueryOptions, callback: ValueCallback<types.ResultSet<T>>): void;

execute(query: string, params: ArrayOrObject, callback: ValueCallback<types.ResultSet>): void;
execute<T = any>(query: string, params: ArrayOrObject, callback: ValueCallback<types.ResultSet<T>>): void;

execute(query: string, callback: ValueCallback<types.ResultSet>): void;
execute<T = any>(query: string, callback: ValueCallback<types.ResultSet<T>>): void;

executeGraph(
traversal: string,
Expand All @@ -80,34 +80,34 @@ export class Client extends events.EventEmitter {
parameters?: { [name: string]: any },
options?: GraphQueryOptions): Promise<graph.GraphResultSet>;

eachRow(query: string,
eachRow<T = any>(query: string,
params: ArrayOrObject,
options: QueryOptions,
rowCallback: (n: number, row: types.Row) => void,
callback?: ValueCallback<types.ResultSet>): void;
rowCallback: (n: number, row: types.Row<T>) => void,
callback?: ValueCallback<types.ResultSet<T>>): void;

eachRow(query: string,
eachRow<T = any>(query: string,
params: ArrayOrObject,
rowCallback: (n: number, row: types.Row) => void,
callback?: ValueCallback<types.ResultSet>): void;
rowCallback: (n: number, row: types.Row<T>) => void,
callback?: ValueCallback<types.ResultSet<T>>): void;

eachRow(query: string,
rowCallback: (n: number, row: types.Row) => void): void;
eachRow<T = any>(query: string,
rowCallback: (n: number, row: types.Row<T>) => void): void;

stream(query: string, params?: ArrayOrObject, options?: QueryOptions, callback?: EmptyCallback): events.EventEmitter;

batch(
batch<T = any>(
queries: Array<string|{query: string, params?: ArrayOrObject}>,
options?: QueryOptions): Promise<types.ResultSet>;
options?: QueryOptions): Promise<types.ResultSet<T>>;

batch(
batch<T = any>(
queries: Array<string|{query: string, params?: ArrayOrObject}>,
options: QueryOptions,
callback: ValueCallback<types.ResultSet>): void;
callback: ValueCallback<types.ResultSet<T>>): void;

batch(
batch<T = any>(
queries: Array<string|{query: string, params?: ArrayOrObject}>,
callback: ValueCallback<types.ResultSet>): void;
callback: ValueCallback<types.ResultSet<T>>): void;

shutdown(): Promise<void>;

Expand Down
2 changes: 1 addition & 1 deletion lib/datastax/graph/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export namespace graph {
}

class GraphResultSet implements Iterator<any> {
constructor(rs: types.ResultSet);
constructor(rs: types.ResultSet<any>);

first(): any;

Expand Down
18 changes: 8 additions & 10 deletions lib/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export namespace types {
toString(): string;
}

interface ResultSet extends Iterable<Row>, AsyncIterable<Row> {
interface ResultSet<T = any> extends Iterable<Row<T>>, AsyncIterable<Row<T>> {
info: {
queriedHost: string,
triedHosts: { [key: string]: any; },
Expand All @@ -335,9 +335,9 @@ export namespace types {
nextPage: (() => void) | null;
pageState: string;
rowLength: number;
rows: Row[];
rows: Row<T>[];

first(): Row;
first(): Row<T>;

wasApplied(): boolean;
}
Expand All @@ -349,16 +349,14 @@ export namespace types {
add(chunk: Buffer): void;
}

interface Row {
get(columnName: string | number): any;
type Row<T = any> = T & {
get<K extends keyof T>(columnName: K): T[K];

keys(): string[];
keys(): (keyof T)[];

forEach(callback: (row: Row) => void): void;
forEach(callback: (row: Row<T>) => void): void;

values(): any[];

[key: string]: any;
values(): T[];
}

class TimeUuid extends Uuid {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.