From 5ac67c6749dd84d45b091ef1b991f5cbb1171536 Mon Sep 17 00:00:00 2001 From: Alex Gorbatchev Date: Mon, 26 Sep 2016 19:40:01 -0700 Subject: [PATCH 1/3] [rethinkdb] Adds missing promise methods to Cursor and Connection --- rethinkdb/rethinkdb-tests.ts | 6 ++++-- rethinkdb/rethinkdb.d.ts | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/rethinkdb/rethinkdb-tests.ts b/rethinkdb/rethinkdb-tests.ts index a6911e3021..4dbd7ab638 100644 --- a/rethinkdb/rethinkdb-tests.ts +++ b/rethinkdb/rethinkdb-tests.ts @@ -15,8 +15,10 @@ r.connect({host:"localhost", port: 28015}, function(err, conn) { }) .between("james", "beth") .limit(4) - .run(conn, function() { - + .run(conn, function(err, cursor) { + cursor.toArray().then(rows => { + console.log(rows); + }); }) }) diff --git a/rethinkdb/rethinkdb.d.ts b/rethinkdb/rethinkdb.d.ts index 7161e42060..0b4d6b54b9 100644 --- a/rethinkdb/rethinkdb.d.ts +++ b/rethinkdb/rethinkdb.d.ts @@ -35,11 +35,13 @@ declare module "rethinkdb" { export class Cursor { hasNext():boolean; - each(cb:(err:Error, row:any)=>void, done?:()=>void); - each(cb:(err:Error, row:any)=>boolean, done?:()=>void); // returning false stops iteration - next(cb:(err:Error, row:any) => void); - toArray(cb:(err:Error, rows:any[]) => void); - close(); + each(cb:(err:Error, row:any)=>void, done?:()=>void): void; + each(cb:(err:Error, row:any)=>boolean, done?:()=>void): void; // returning false stops iteration + next(cb:(err:Error, row:any) => void): void; + toArray(cb:(err:Error, rows:any[]) => void): void; + toArray(): Promise; + close(cb: (err: Error) => void): void; + close(): Promise; } interface ConnectionOptions { @@ -50,11 +52,14 @@ declare module "rethinkdb" { } interface Connection { - close(); + close(cb: (err: Error) => void): void; + close(opts: { noreplyWait: boolean }, cb: (err: Error) => void): void; + close(): Promise; + close(opts: { noreplyWait: boolean }): Promise; reconnect(cb?:(err:Error, conn:Connection)=>void):Promise; - use(dbName:string); - addListener(event:string, cb:Function); - on(event:string, cb:Function); + use(dbName:string): void; + addListener(event:string, cb:Function): void; + on(event:string, cb:Function): void; } interface Db { From 87a03f83ce8a03188424ca2126f4d1c70e17f0b4 Mon Sep 17 00:00:00 2001 From: Alex Gorbatchev Date: Mon, 26 Sep 2016 19:41:08 -0700 Subject: [PATCH 2/3] [rethinkdb] Applied TypeScript formatting to the file --- rethinkdb/rethinkdb.d.ts | 368 +++++++++++++++++++-------------------- 1 file changed, 184 insertions(+), 184 deletions(-) diff --git a/rethinkdb/rethinkdb.d.ts b/rethinkdb/rethinkdb.d.ts index 0b4d6b54b9..dc251b2a8e 100644 --- a/rethinkdb/rethinkdb.d.ts +++ b/rethinkdb/rethinkdb.d.ts @@ -8,234 +8,234 @@ declare module "rethinkdb" { - export function connect(host:ConnectionOptions, cb?:(err:Error, conn:Connection)=>void):Promise; + export function connect(host: ConnectionOptions, cb?: (err: Error, conn: Connection) => void): Promise; - export function dbCreate(name:string):Operation; - export function dbDrop(name:string):Operation; - export function dbList():Operation; + export function dbCreate(name: string): Operation; + export function dbDrop(name: string): Operation; + export function dbList(): Operation; - export function db(name:string):Db; - export function table(name:string, options?:{useOutdated:boolean}):Table; + export function db(name: string): Db; + export function table(name: string, options?: { useOutdated: boolean }): Table; - export function asc(property:string):Sort; - export function desc(property:string):Sort; + export function asc(property: string): Sort; + export function desc(property: string): Sort; - export var count:Aggregator; - export function sum(prop:string):Aggregator; - export function avg(prop:string):Aggregator; + export var count: Aggregator; + export function sum(prop: string): Aggregator; + export function avg(prop: string): Aggregator; - export function row(name:string):Expression; - export function expr(stuff:any):Expression; + export function row(name: string): Expression; + export function expr(stuff: any): Expression; - export function now():Time; + export function now(): Time; - // Control Structures - export function branch(test:Expression, trueBranch:Expression, falseBranch:Expression):Expression; + // Control Structures + export function branch(test: Expression, trueBranch: Expression, falseBranch: Expression): Expression; - export class Cursor { - hasNext():boolean; - each(cb:(err:Error, row:any)=>void, done?:()=>void): void; - each(cb:(err:Error, row:any)=>boolean, done?:()=>void): void; // returning false stops iteration - next(cb:(err:Error, row:any) => void): void; - toArray(cb:(err:Error, rows:any[]) => void): void; - toArray(): Promise; - close(cb: (err: Error) => void): void; - close(): Promise; - } + export class Cursor { + hasNext(): boolean; + each(cb: (err: Error, row: any) => void, done?: () => void): void; + each(cb: (err: Error, row: any) => boolean, done?: () => void): void; // returning false stops iteration + next(cb: (err: Error, row: any) => void): void; + toArray(cb: (err: Error, rows: any[]) => void): void; + toArray(): Promise; + close(cb: (err: Error) => void): void; + close(): Promise; + } - interface ConnectionOptions { - host:string; - port:number; - db?:string; - authKey?:string; - } + interface ConnectionOptions { + host: string; + port: number; + db?: string; + authKey?: string; + } - interface Connection { - close(cb: (err: Error) => void): void; - close(opts: { noreplyWait: boolean }, cb: (err: Error) => void): void; - close(): Promise; - close(opts: { noreplyWait: boolean }): Promise; - reconnect(cb?:(err:Error, conn:Connection)=>void):Promise; - use(dbName:string): void; - addListener(event:string, cb:Function): void; - on(event:string, cb:Function): void; - } + interface Connection { + close(cb: (err: Error) => void): void; + close(opts: { noreplyWait: boolean }, cb: (err: Error) => void): void; + close(): Promise; + close(opts: { noreplyWait: boolean }): Promise; + reconnect(cb?: (err: Error, conn: Connection) => void): Promise; + use(dbName: string): void; + addListener(event: string, cb: Function): void; + on(event: string, cb: Function): void; + } - interface Db { - tableCreate(name:string, options?:TableOptions):Operation; - tableDrop(name:string):Operation; - tableList():Operation; - table(name:string, options?:GetTableOptions):Table; - } + interface Db { + tableCreate(name: string, options?: TableOptions): Operation; + tableDrop(name: string): Operation; + tableList(): Operation; + table(name: string, options?: GetTableOptions): Table; + } - interface TableOptions { - primary_key?:string; // 'id' - durability?:string; // 'soft' - cache_size?:number; - datacenter?:string; - } + interface TableOptions { + primary_key?: string; // 'id' + durability?: string; // 'soft' + cache_size?: number; + datacenter?: string; + } - interface GetTableOptions { - useOutdated: boolean; - } + interface GetTableOptions { + useOutdated: boolean; + } - interface Writeable { - update(obj:Object, options?:UpdateOptions):Operation; - replace(obj:Object, options?:UpdateOptions):Operation; - replace(expr:ExpressionFunction):Operation; - delete(options?:UpdateOptions):Operation; - } + interface Writeable { + update(obj: Object, options?: UpdateOptions): Operation; + replace(obj: Object, options?: UpdateOptions): Operation; + replace(expr: ExpressionFunction): Operation; + delete(options?: UpdateOptions): Operation; + } - interface Table extends Sequence { - indexCreate(name:string, index?:ExpressionFunction):Operation; - indexDrop(name:string):Operation; - indexList():Operation; + interface Table extends Sequence { + indexCreate(name: string, index?: ExpressionFunction): Operation; + indexDrop(name: string): Operation; + indexList(): Operation; - insert(obj:any[], options?:InsertOptions):Operation; - insert(obj:any, options?:InsertOptions):Operation; + insert(obj: any[], options?: InsertOptions): Operation; + insert(obj: any, options?: InsertOptions): Operation; - get(key:string):Sequence; // primary key - getAll(key:string, index?:Index):Sequence; // without index defaults to primary key - getAll(...keys:string[]):Sequence; - } + get(key: string): Sequence; // primary key + getAll(key: string, index?: Index): Sequence; // without index defaults to primary key + getAll(...keys: string[]): Sequence; + } - interface Sequence extends Operation, Writeable { + interface Sequence extends Operation, Writeable { - between(lower:any, upper:any, index?:Index):Sequence; - filter(rql:ExpressionFunction):Sequence; - filter(rql:Expression):Sequence; - filter(obj:{[key:string]:any}):Sequence; + between(lower: any, upper: any, index?: Index): Sequence; + filter(rql: ExpressionFunction): Sequence; + filter(rql: Expression): Sequence; + filter(obj: { [key: string]: any }): Sequence; - // Join - // these return left, right - innerJoin(sequence:Sequence, join:JoinFunction):Sequence; - outerJoin(sequence:Sequence, join:JoinFunction):Sequence; - eqJoin(leftAttribute:string, rightSequence:Sequence, index?:Index):Sequence; - eqJoin(leftAttribute:ExpressionFunction, rightSequence:Sequence, index?:Index):Sequence; - zip():Sequence; + // Join + // these return left, right + innerJoin(sequence: Sequence, join: JoinFunction): Sequence; + outerJoin(sequence: Sequence, join: JoinFunction): Sequence; + eqJoin(leftAttribute: string, rightSequence: Sequence, index?: Index): Sequence; + eqJoin(leftAttribute: ExpressionFunction, rightSequence: Sequence, index?: Index): Sequence; + zip(): Sequence; - // Transform - map(transform:ExpressionFunction):Sequence; - withFields(...selectors:any[]):Sequence; - concatMap(transform:ExpressionFunction):Sequence; - orderBy(...keys:string[]):Sequence; - orderBy(...sorts:Sort[]):Sequence; - skip(n:number):Sequence; - limit(n:number):Sequence; - slice(start:number, end?:number):Sequence; - nth(n:number):Expression; - indexesOf(obj:any):Sequence; - isEmpty():Expression; - union(sequence:Sequence):Sequence; - sample(n:number):Sequence; + // Transform + map(transform: ExpressionFunction): Sequence; + withFields(...selectors: any[]): Sequence; + concatMap(transform: ExpressionFunction): Sequence; + orderBy(...keys: string[]): Sequence; + orderBy(...sorts: Sort[]): Sequence; + skip(n: number): Sequence; + limit(n: number): Sequence; + slice(start: number, end?: number): Sequence; + nth(n: number): Expression; + indexesOf(obj: any): Sequence; + isEmpty(): Expression; + union(sequence: Sequence): Sequence; + sample(n: number): Sequence; - // Aggregate - reduce(r:ReduceFunction, base?:any):Expression; - count():Expression; - distinct():Sequence; - groupedMapReduce(group:ExpressionFunction, map:ExpressionFunction, reduce:ReduceFunction, base?:any):Sequence; - groupBy(...aggregators:Aggregator[]):Expression; // TODO: reduction object - contains(prop:string):Expression; + // Aggregate + reduce(r: ReduceFunction, base?: any): Expression; + count(): Expression; + distinct(): Sequence; + groupedMapReduce(group: ExpressionFunction, map: ExpressionFunction, reduce: ReduceFunction, base?: any): Sequence; + groupBy(...aggregators: Aggregator[]): Expression; // TODO: reduction object + contains(prop: string): Expression; - // Manipulation - pluck(...props:string[]):Sequence; - without(...props:string[]):Sequence; - } + // Manipulation + pluck(...props: string[]): Sequence; + without(...props: string[]): Sequence; + } - interface ExpressionFunction { - (doc:Expression):Expression; - } + interface ExpressionFunction { + (doc: Expression): Expression; + } - interface JoinFunction { - (left:Expression, right:Expression):Expression; - } + interface JoinFunction { + (left: Expression, right: Expression): Expression; + } - interface ReduceFunction { - (acc:Expression, val:Expression):Expression; - } + interface ReduceFunction { + (acc: Expression, val: Expression): Expression; + } - interface InsertOptions { - upsert: boolean; // true - durability: string; // 'soft' - return_vals: boolean; // false - } + interface InsertOptions { + upsert: boolean; // true + durability: string; // 'soft' + return_vals: boolean; // false + } - interface UpdateOptions { - non_atomic: boolean; - durability: string; // 'soft' - return_vals: boolean; // false - } + interface UpdateOptions { + non_atomic: boolean; + durability: string; // 'soft' + return_vals: boolean; // false + } - interface WriteResult { - inserted: number; - replaced: number; - unchanged: number; - errors: number; - deleted: number; - skipped: number; - first_error: Error; - generated_keys: string[]; // only for insert - } + interface WriteResult { + inserted: number; + replaced: number; + unchanged: number; + errors: number; + deleted: number; + skipped: number; + first_error: Error; + generated_keys: string[]; // only for insert + } - interface JoinResult { - left:any; - right:any; - } + interface JoinResult { + left: any; + right: any; + } - interface CreateResult { - created: number; - } + interface CreateResult { + created: number; + } - interface DropResult { - dropped: number; - } + interface DropResult { + dropped: number; + } - interface Index { - index: string; - left_bound?: string; // 'closed' - right_bound?: string; // 'open' - } + interface Index { + index: string; + left_bound?: string; // 'closed' + right_bound?: string; // 'open' + } - interface Expression extends Writeable, Operation { - (prop:string):Expression; - merge(query:Expression):Expression; - append(prop:string):Expression; - contains(prop:string):Expression; + interface Expression extends Writeable, Operation { + (prop: string): Expression; + merge(query: Expression): Expression; + append(prop: string): Expression; + contains(prop: string): Expression; - and(b:boolean):Expression; - or(b:boolean):Expression; - eq(v:any):Expression; - ne(v:any):Expression; - not():Expression; + and(b: boolean): Expression; + or(b: boolean): Expression; + eq(v: any): Expression; + ne(v: any): Expression; + not(): Expression; - gt(value:T):Expression; - ge(value:T):Expression; - lt(value:T):Expression; - le(value:T):Expression; + gt(value: T): Expression; + ge(value: T): Expression; + lt(value: T): Expression; + le(value: T): Expression; - add(n:number):Expression; - sub(n:number):Expression; - mul(n:number):Expression; - div(n:number):Expression; - mod(n:number):Expression; + add(n: number): Expression; + sub(n: number): Expression; + mul(n: number): Expression; + div(n: number): Expression; + mod(n: number): Expression; - hasFields(...fields:string[]):Expression; + hasFields(...fields: string[]): Expression; - default(value:T):Expression; - } + default(value: T): Expression; + } - interface Operation { - run(conn:Connection, cb?:(err:Error, result:T)=>void):Promise; - } + interface Operation { + run(conn: Connection, cb?: (err: Error, result: T) => void): Promise; + } - interface Aggregator {} - interface Sort {} + interface Aggregator { } + interface Sort { } - interface Time {} + interface Time { } - // http://www.rethinkdb.com/api/#js - // TODO control structures + // http://www.rethinkdb.com/api/#js + // TODO control structures } From 317be6bc69da5f69b9517f1ff4c7908745dd5592 Mon Sep 17 00:00:00 2001 From: Alex Gorbatchev Date: Mon, 26 Sep 2016 19:59:32 -0700 Subject: [PATCH 3/3] [rethinkdb] Adds types to Cursor methods --- rethinkdb/rethinkdb.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rethinkdb/rethinkdb.d.ts b/rethinkdb/rethinkdb.d.ts index dc251b2a8e..7babd42fe2 100644 --- a/rethinkdb/rethinkdb.d.ts +++ b/rethinkdb/rethinkdb.d.ts @@ -36,10 +36,15 @@ declare module "rethinkdb" { export class Cursor { hasNext(): boolean; each(cb: (err: Error, row: any) => void, done?: () => void): void; + each(cb: (err: Error, row: T) => void, done?: () => void): void; each(cb: (err: Error, row: any) => boolean, done?: () => void): void; // returning false stops iteration + each(cb: (err: Error, row: T) => boolean, done?: () => void): void; // returning false stops iteration next(cb: (err: Error, row: any) => void): void; + next(cb: (err: Error, row: T) => void): void; toArray(cb: (err: Error, rows: any[]) => void): void; + toArray(cb: (err: Error, rows: T[]) => void): void; toArray(): Promise; + toArray(): Promise; close(cb: (err: Error) => void): void; close(): Promise; }