From e73a94c7ec0df9e22ce134cc0ee3afa17a756bf9 Mon Sep 17 00:00:00 2001 From: Clarence Ho Date: Wed, 3 Jan 2018 02:46:44 +0800 Subject: [PATCH] Updated to Massive v4 (#22594) * Updated to Massive v4 * Update tsconfig.json * Remove white space --- types/massive/index.d.ts | 2 +- types/massive/v3/index.d.ts | 82 +++++++++++++++++++++++++++++++ types/massive/v3/massive-tests.ts | 10 ++++ types/massive/v3/tsconfig.json | 26 ++++++++++ types/massive/v3/tslint.json | 1 + 5 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 types/massive/v3/index.d.ts create mode 100644 types/massive/v3/massive-tests.ts create mode 100644 types/massive/v3/tsconfig.json create mode 100644 types/massive/v3/tslint.json diff --git a/types/massive/index.d.ts b/types/massive/index.d.ts index b7132ab910..39ec1c9b66 100644 --- a/types/massive/index.d.ts +++ b/types/massive/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for massive 3.0 +// Type definitions for massive 4.0 // Project: https://github.com/dmfay/massive-js.git // Definitions by: Pascal Birchler // Clarence Ho diff --git a/types/massive/v3/index.d.ts b/types/massive/v3/index.d.ts new file mode 100644 index 0000000000..b7132ab910 --- /dev/null +++ b/types/massive/v3/index.d.ts @@ -0,0 +1,82 @@ +// Type definitions for massive 3.0 +// Project: https://github.com/dmfay/massive-js.git +// Definitions by: Pascal Birchler +// Clarence Ho +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +export = massive; + +declare function massive( + connection: massive.ConnectionInfo | string, + loaderConfig?: object, + driverConfig?: object): Promise; + +declare namespace massive { + interface ConnectionInfo { + user?: string; + database?: string; + password?: string | null; + port?: number; + host?: string; + ssl?: boolean; + application_name?: string; + fallback_application_name?: boolean; + } + + interface QueryOptions { + columns?: string[]; + limit?: number; + offset?: number; + only?: boolean; + order?: string[]; + orderBody?: boolean; + build?: boolean; + document?: boolean; + single?: boolean; + stream?: boolean; + } + + interface SearchCriteria { + fields: string[]; + term: string; + } + + interface Table { + find(criteria: object | {}, queryOptions?: QueryOptions): Promise; + findOne(criteria: number | object, queryOptions?: QueryOptions): Promise; + count(criteria: object): Promise; + where(query: string, params: any[] | object): Promise; + search(criteria: SearchCriteria, queryOptions?: QueryOptions): Promise; + save(data: object): Promise; + insert(data: object): Promise; + insert(data: object[]): Promise; + update(dataOrCriteria: object, changesMap?: object): Promise; + update(dataOrCriteria: object[], changesMap?: object): Promise; + destroy(criteria: object): Promise; + } + + interface Document { + countDoc(criteria: object): Promise; + findDoc(criteria: number | string| object): Promise; + searchDoc(criteria: SearchCriteria): Promise; + saveDoc(doc: object): Promise; + modify(docId: number | string, doc: object, fieldName?: string): Promise; + } + + interface Database { + attach(ctor: any, ...sources: any[]): Promise; + detach(entity: string, collection: string): void; + reload(): void; + query(query: any, params: any, options: any): Promise; + saveDoc(collectionName: string, doc: object): Promise; + createDocumentTable(path: any): Promise; + getObject(path: any, collection: any): object; + dropTable(table: string, options: any): void; + createSchema(schemaName: string): void; + dropSchema(schemaName: string, options: any): void; + run(query: string, params: any[] | object): Promise; + } +} diff --git a/types/massive/v3/massive-tests.ts b/types/massive/v3/massive-tests.ts new file mode 100644 index 0000000000..c201541a12 --- /dev/null +++ b/types/massive/v3/massive-tests.ts @@ -0,0 +1,10 @@ +import massive = require('massive'); + +let dbconn: massive.Database; + +massive('postgres://app:password@localhost:5432/app').then(db => { + console.log(`DB connected successfully`); + dbconn = db; +}).catch(err => { + console.error(`Error connecting DB`); +}); diff --git a/types/massive/v3/tsconfig.json b/types/massive/v3/tsconfig.json new file mode 100644 index 0000000000..ddfdc175d3 --- /dev/null +++ b/types/massive/v3/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es2015" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "massive": [ "massive/v3" ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true + }, + "files": [ + "index.d.ts", + "massive-tests.ts" + ] +} diff --git a/types/massive/v3/tslint.json b/types/massive/v3/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/massive/v3/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }