From 020af54bafa72da742e8e0a6337e5e253d6e733e Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 20 Feb 2017 22:41:34 +0100 Subject: [PATCH 1/4] Add typings for massive-js --- massive/index.d.ts | 101 ++++++++++++++++++++++++++++++++++++++++++ massive/tsconfig.json | 11 +++++ massive/tslint.json | 1 + 3 files changed, 113 insertions(+) create mode 100755 massive/index.d.ts create mode 100755 massive/tsconfig.json create mode 100644 massive/tslint.json diff --git a/massive/index.d.ts b/massive/index.d.ts new file mode 100755 index 0000000000..480b01bc8e --- /dev/null +++ b/massive/index.d.ts @@ -0,0 +1,101 @@ +// Type definitions for massive-js 2.2 +// Project: https://github.com/robconery/massive-js +// Definitions by: Pascal Birchler +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module massive { + interface IConnectionOptions { + connectionString?: string; + db?: string; + } + + export type ResultCallback = (err: Error, res: any) => void; + export type ConnectCallback = (err: Error, db: Massive) => void; + + export interface QueryOptions { + limit?: number; + order?: string; + offset?: number; + columns?: string[]; + } + + export interface Table { + count(context: any, callback: ResultCallback): void; + find(context: any, callback: ResultCallback): void; + find(context: any, options: QueryOptions, callback: ResultCallback): void; + findOne(context: any, callback: ResultCallback): void; + findOne(context: any, options: QueryOptions, callback: ResultCallback): void; + insert(context: any, callback: ResultCallback): void; + save(context: any, callback: ResultCallback): void; + update(context: any, callback: ResultCallback): void; + update(context: any, data: any, callback: ResultCallback): void; + destroy(context: any, callback: ResultCallback): void; + } + + interface Doc { + findDoc(context: any, callback: ResultCallback): void; + searchDoc(options: { + keys: string[]; + term: string; + }, callback: ResultCallback): void; + saveDoc(context: string, callback: ResultCallback): void; + destroy(context: any, callback: ResultCallback): void; + } + + interface QueryFile { + schema: string; + name: string; + db: Massive; + delimitedName: string; + delimitedSchema: string; + fullname: string; + delimitedFullName: string; + sql: string; + filePath: string; + } + + interface QueryFunction { + find: (params: any|any[], callback: ResultCallback) => void; + } + + export interface Massive { + custom: any; + comment: Table; + friendship: Table; + participation: Table; + person: Table; + practice: Table; + practicesession: Table; + sport: Table; + testdata: (callback: ResultCallback) => void; + team: Table; + teammember: Table; + teamsport: Table; + scriptsDir: string; + connectionString: string; + query: Function; + stream: Function; + executeSqlFile: Function; + end: Function; + tables: Array; + views: any[]; + queryFiles: QueryFile[]; + schemas: any[]; + functions: any[]; + allowedSchemas: string; + blacklist: string; + exceptions: string; + excludeFunctions: boolean; + functionBlacklist: string; + } + + export function connectSync(options: IConnectionOptions): Massive + + export function connect(options: IConnectionOptions, callback: ConnectCallback): void; + + export function run(context: string, filter: number|number[], callback: ResultCallback): void; + + export function saveDoc(name: string, data: any, callback: ResultCallback): void; +} + +export = massive; diff --git a/massive/tsconfig.json b/massive/tsconfig.json new file mode 100755 index 0000000000..5025aabaa6 --- /dev/null +++ b/massive/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "noImplicitAny": true, + "sourceMap": false + }, + "files": [ + "index.d.ts" + ] +} diff --git a/massive/tslint.json b/massive/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/massive/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file From 47f4cc037609497fde2af77025d59512769473a7 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 20 Feb 2017 23:04:09 +0100 Subject: [PATCH 2/4] Fix tsconfig --- massive/tsconfig.json | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/massive/tsconfig.json b/massive/tsconfig.json index 5025aabaa6..dbec91cb4b 100755 --- a/massive/tsconfig.json +++ b/massive/tsconfig.json @@ -1,11 +1,13 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "noImplicitAny": true, - "sourceMap": false - }, - "files": [ - "index.d.ts" - ] + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "sourceMap": false + }, + "files": [ + "index.d.ts" + ] } From 952587467e15be132b4c253411a83114ff0cacf2 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 20 Feb 2017 23:04:14 +0100 Subject: [PATCH 3/4] Fix warnings --- massive/index.d.ts | 185 +++++++++++++++++++++++---------------------- 1 file changed, 95 insertions(+), 90 deletions(-) diff --git a/massive/index.d.ts b/massive/index.d.ts index 480b01bc8e..53e857e689 100755 --- a/massive/index.d.ts +++ b/massive/index.d.ts @@ -3,99 +3,104 @@ // Definitions by: Pascal Birchler // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module massive { - interface IConnectionOptions { - connectionString?: string; - db?: string; - } +declare namespace massive { + interface ConnectionOptions { + connectionString?: string; + db?: string; + } - export type ResultCallback = (err: Error, res: any) => void; - export type ConnectCallback = (err: Error, db: Massive) => void; + interface Doc { + findDoc(context: any, callback: ResultCallback): void; + searchDoc(options: { + keys: string[]; + term: string; + }, callback: ResultCallback): void; + saveDoc(context: string, callback: ResultCallback): void; + destroy(context: any, callback: ResultCallback): void; + } - export interface QueryOptions { - limit?: number; - order?: string; - offset?: number; - columns?: string[]; - } + interface QueryFile { + schema: string; + name: string; + db: Massive; + delimitedName: string; + delimitedSchema: string; + fullname: string; + delimitedFullName: string; + sql: string; + filePath: string; + } - export interface Table { - count(context: any, callback: ResultCallback): void; - find(context: any, callback: ResultCallback): void; - find(context: any, options: QueryOptions, callback: ResultCallback): void; - findOne(context: any, callback: ResultCallback): void; - findOne(context: any, options: QueryOptions, callback: ResultCallback): void; - insert(context: any, callback: ResultCallback): void; - save(context: any, callback: ResultCallback): void; - update(context: any, callback: ResultCallback): void; - update(context: any, data: any, callback: ResultCallback): void; - destroy(context: any, callback: ResultCallback): void; - } + interface QueryFunction { + find: (params: any|any[], callback: ResultCallback) => void; + } - interface Doc { - findDoc(context: any, callback: ResultCallback): void; - searchDoc(options: { - keys: string[]; - term: string; - }, callback: ResultCallback): void; - saveDoc(context: string, callback: ResultCallback): void; - destroy(context: any, callback: ResultCallback): void; - } - - interface QueryFile { - schema: string; - name: string; - db: Massive; - delimitedName: string; - delimitedSchema: string; - fullname: string; - delimitedFullName: string; - sql: string; - filePath: string; - } - - interface QueryFunction { - find: (params: any|any[], callback: ResultCallback) => void; - } - - export interface Massive { - custom: any; - comment: Table; - friendship: Table; - participation: Table; - person: Table; - practice: Table; - practicesession: Table; - sport: Table; - testdata: (callback: ResultCallback) => void; - team: Table; - teammember: Table; - teamsport: Table; - scriptsDir: string; - connectionString: string; - query: Function; - stream: Function; - executeSqlFile: Function; - end: Function; - tables: Array; - views: any[]; - queryFiles: QueryFile[]; - schemas: any[]; - functions: any[]; - allowedSchemas: string; - blacklist: string; - exceptions: string; - excludeFunctions: boolean; - functionBlacklist: string; - } - - export function connectSync(options: IConnectionOptions): Massive - - export function connect(options: IConnectionOptions, callback: ConnectCallback): void; - - export function run(context: string, filter: number|number[], callback: ResultCallback): void; - - export function saveDoc(name: string, data: any, callback: ResultCallback): void; + interface QueryArguments { + sql: string; + options: any; + params: any; + next: ResultCallback; + } } -export = massive; +export interface Massive { + custom: any; + comment: Table; + friendship: Table; + participation: Table; + person: Table; + practice: Table; + practicesession: Table; + sport: Table; + testdata: (callback: ResultCallback) => void; + team: Table; + teammember: Table; + teamsport: Table; + scriptsDir: string; + connectionString: string; + query: () => void; + stream: () => void; + executeSqlFile: (args: any, next: ResultCallback) => void; + end: () => void; + tables: Array; + views: any[]; + queryFiles: massive.QueryFile[]; + schemas: any[]; + functions: any[]; + allowedSchemas: string; + blacklist: string; + exceptions: string; + excludeFunctions: boolean; + functionBlacklist: string; +} + +export type ResultCallback = (err: Error, res: any) => void; +export type ConnectCallback = (err: Error, db: Massive) => void; + +export interface QueryOptions { + limit?: number; + order?: string; + offset?: number; + columns?: string[]; +} + +export interface Table { + count(context: any, callback: ResultCallback): void; + find(context: any, callback: ResultCallback): void; + find(context: any, options: QueryOptions, callback: ResultCallback): void; + findOne(context: any, callback: ResultCallback): void; + findOne(context: any, options: QueryOptions, callback: ResultCallback): void; + insert(context: any, callback: ResultCallback): void; + save(context: any, callback: ResultCallback): void; + update(context: any, callback: ResultCallback): void; + update(context: any, data: any, callback: ResultCallback): void; + destroy(context: any, callback: ResultCallback): void; +} + +export function connectSync(options: massive.ConnectionOptions): Massive; + +export function connect(options: massive.ConnectionOptions, callback: ConnectCallback): void; + +export function run(context: string, filter: number|number[], callback: ResultCallback): void; + +export function saveDoc(name: string, data: any, callback: ResultCallback): void; From 0dd7c7a7533e8de387ac0a9794535e2b1a65f455 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 20 Feb 2017 23:25:04 +0100 Subject: [PATCH 4/4] Add some tests --- massive/massive-tests.ts | 5 +++++ massive/tsconfig.json | 33 +++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 massive/massive-tests.ts diff --git a/massive/massive-tests.ts b/massive/massive-tests.ts new file mode 100644 index 0000000000..2978440f4a --- /dev/null +++ b/massive/massive-tests.ts @@ -0,0 +1,5 @@ +import * as Massive from 'massive'; + +Massive.connect({connectionString: 'foo'}, (err: Error, db: Massive.Massive) => {}); + +Massive.run('foo', 123, (err: Error, db: Massive.Massive) => {}); \ No newline at end of file diff --git a/massive/tsconfig.json b/massive/tsconfig.json index dbec91cb4b..7c91e19b44 100755 --- a/massive/tsconfig.json +++ b/massive/tsconfig.json @@ -1,13 +1,22 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "sourceMap": false - }, - "files": [ - "index.d.ts" - ] -} + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es5" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "massive-tests.ts" + ] +} \ No newline at end of file