From 0a5d7232d4929460ea810688ba78092a1d973fa0 Mon Sep 17 00:00:00 2001 From: Evgeni Zharkov Date: Sat, 2 Mar 2019 18:31:09 +0300 Subject: [PATCH 1/4] Add typings for tarantool-driver --- types/tarantool-driver/index.d.ts | 58 +++++++++++++++++++ .../tarantool-driver-tests.ts | 3 + types/tarantool-driver/tsconfig.json | 23 ++++++++ types/tarantool-driver/tslint.json | 1 + 4 files changed, 85 insertions(+) create mode 100644 types/tarantool-driver/index.d.ts create mode 100644 types/tarantool-driver/tarantool-driver-tests.ts create mode 100644 types/tarantool-driver/tsconfig.json create mode 100644 types/tarantool-driver/tslint.json diff --git a/types/tarantool-driver/index.d.ts b/types/tarantool-driver/index.d.ts new file mode 100644 index 0000000000..63b34cb6fa --- /dev/null +++ b/types/tarantool-driver/index.d.ts @@ -0,0 +1,58 @@ +// Type definitions for tarantool-driver 3.0 +// Project: https://github.com/tarantool/node-tarantool-driver +// Definitions by: Evgeni Zharkov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { EventEmitter } from "events"; + +export interface TarantoolOptions { + host?: string; + port?: number; + username?: string; + password?: string; + reserveHosts?: string[]; + beforeReserve?: number; + timeout?: number; + retryStrategy?: (times: number) => number; + lazyConnect?: boolean; +} + +export default class TarantoolConnection extends EventEmitter { + constructor(options: TarantoolOptions); + + /* Connection */ + + connect(): Promise; + + flushQueue(cb: (err: Error) => void): void; + + destroy(): void; + + disconnect(reconnect?: boolean): void; + + /* Commands */ + + select(spaceId: number | string, + indexId: number | string, + limit: number, offset: number, + iterator: string, key: string | string[]): Promise; + + delete(spaceId: number | string, + indexId: number | string, + key: any[]): Promise; + + update(spaceId: number | string, + indexId: number | string, + key: any[], ops: any[]): Promise; + + upsert(spaceId: number | string, + ops: any[], tuple: any[]): Promise; + + eval(expression: string, ...args: any[]): Promise; + + call(functionName: string, ...args: any[]): Promise; + + insert(spaceId: number | string, tuple: any[]): Promise; + + replace(spaceId: number | string, tuple: any[]): Promise; +} diff --git a/types/tarantool-driver/tarantool-driver-tests.ts b/types/tarantool-driver/tarantool-driver-tests.ts new file mode 100644 index 0000000000..cf27d123fb --- /dev/null +++ b/types/tarantool-driver/tarantool-driver-tests.ts @@ -0,0 +1,3 @@ +import TarantoolDriver from "tarantool-driver"; + +new TarantoolDriver({}).connect(); // $ExpectedType Promise diff --git a/types/tarantool-driver/tsconfig.json b/types/tarantool-driver/tsconfig.json new file mode 100644 index 0000000000..c49fafed46 --- /dev/null +++ b/types/tarantool-driver/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "tarantool-driver-tests.ts" + ] +} \ No newline at end of file diff --git a/types/tarantool-driver/tslint.json b/types/tarantool-driver/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/tarantool-driver/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file From f89faea7bbf9af23606fb837c8f8473410119c1b Mon Sep 17 00:00:00 2001 From: Evgeni Zharkov Date: Tue, 5 Mar 2019 01:40:06 +0300 Subject: [PATCH 2/4] Fix to 0a5d7232d49: change default export --- types/tarantool-driver/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/tarantool-driver/index.d.ts b/types/tarantool-driver/index.d.ts index 63b34cb6fa..e8d8e01be3 100644 --- a/types/tarantool-driver/index.d.ts +++ b/types/tarantool-driver/index.d.ts @@ -17,7 +17,7 @@ export interface TarantoolOptions { lazyConnect?: boolean; } -export default class TarantoolConnection extends EventEmitter { +declare class TarantoolConnection extends EventEmitter { constructor(options: TarantoolOptions); /* Connection */ @@ -56,3 +56,5 @@ export default class TarantoolConnection extends EventEmitter { replace(spaceId: number | string, tuple: any[]): Promise; } + +export = TarantoolConnection; From 3d3fee9d5ceabbeaa664fa2e3af2fe4eee5c6775 Mon Sep 17 00:00:00 2001 From: Evgeni Zharkov Date: Tue, 5 Mar 2019 02:01:22 +0300 Subject: [PATCH 3/4] Fix to f89faea: wrap exports into namespace + Changed key in select() method to any[] --- types/tarantool-driver/index.d.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/types/tarantool-driver/index.d.ts b/types/tarantool-driver/index.d.ts index e8d8e01be3..08a5aa4b3f 100644 --- a/types/tarantool-driver/index.d.ts +++ b/types/tarantool-driver/index.d.ts @@ -5,20 +5,22 @@ import { EventEmitter } from "events"; -export interface TarantoolOptions { - host?: string; - port?: number; - username?: string; - password?: string; - reserveHosts?: string[]; - beforeReserve?: number; - timeout?: number; - retryStrategy?: (times: number) => number; - lazyConnect?: boolean; +declare namespace TarantoolConnection { + export interface TarantoolOptions { + host?: string; + port?: number; + username?: string; + password?: string; + reserveHosts?: string[]; + beforeReserve?: number; + timeout?: number; + retryStrategy?: (times: number) => number; + lazyConnect?: boolean; + } } declare class TarantoolConnection extends EventEmitter { - constructor(options: TarantoolOptions); + constructor(options: TarantoolConnection.TarantoolOptions); /* Connection */ @@ -35,7 +37,7 @@ declare class TarantoolConnection extends EventEmitter { select(spaceId: number | string, indexId: number | string, limit: number, offset: number, - iterator: string, key: string | string[]): Promise; + iterator: string, key: any[]): Promise; delete(spaceId: number | string, indexId: number | string, From 9d645ea67fcbaf3b9af8799963cd84e46c2a1235 Mon Sep 17 00:00:00 2001 From: Evgeni Zharkov Date: Tue, 5 Mar 2019 02:17:57 +0300 Subject: [PATCH 4/4] Fix to 3d3fee9: redundant export / resolve default export problem --- types/tarantool-driver/index.d.ts | 22 +++++++++---------- .../tarantool-driver-tests.ts | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/types/tarantool-driver/index.d.ts b/types/tarantool-driver/index.d.ts index 08a5aa4b3f..25d0e04a09 100644 --- a/types/tarantool-driver/index.d.ts +++ b/types/tarantool-driver/index.d.ts @@ -6,17 +6,17 @@ import { EventEmitter } from "events"; declare namespace TarantoolConnection { - export interface TarantoolOptions { - host?: string; - port?: number; - username?: string; - password?: string; - reserveHosts?: string[]; - beforeReserve?: number; - timeout?: number; - retryStrategy?: (times: number) => number; - lazyConnect?: boolean; - } + interface TarantoolOptions { + host?: string; + port?: number; + username?: string; + password?: string; + reserveHosts?: string[]; + beforeReserve?: number; + timeout?: number; + retryStrategy?: (times: number) => number; + lazyConnect?: boolean; + } } declare class TarantoolConnection extends EventEmitter { diff --git a/types/tarantool-driver/tarantool-driver-tests.ts b/types/tarantool-driver/tarantool-driver-tests.ts index cf27d123fb..e7fe424afb 100644 --- a/types/tarantool-driver/tarantool-driver-tests.ts +++ b/types/tarantool-driver/tarantool-driver-tests.ts @@ -1,3 +1,3 @@ -import TarantoolDriver from "tarantool-driver"; +import TarantoolDriver = require("tarantool-driver"); new TarantoolDriver({}).connect(); // $ExpectedType Promise