From a9e346334202ce611ffe087b45f786dbe5234ad3 Mon Sep 17 00:00:00 2001 From: Max Battcher Date: Thu, 8 Jun 2017 14:29:46 -0400 Subject: [PATCH] Update and lint pouchdb-mapreduce --- types/pouchdb-mapreduce/index.d.ts | 27 ++++++++++--------- .../pouchdb-mapreduce-tests.ts | 15 ++++++----- types/pouchdb-mapreduce/tslint.json | 1 + 3 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 types/pouchdb-mapreduce/tslint.json diff --git a/types/pouchdb-mapreduce/index.d.ts b/types/pouchdb-mapreduce/index.d.ts index 401f70afb0..7b398d730b 100644 --- a/types/pouchdb-mapreduce/index.d.ts +++ b/types/pouchdb-mapreduce/index.d.ts @@ -1,15 +1,18 @@ -// Type definitions for pouchdb-mapreduce v6.1.2 +// Type definitions for pouchdb-mapreduce 6.1 // Project: https://pouchdb.com/ // Definitions by: Simon Paulger , Brian Geppert , Frederico Galvão // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 /// -declare namespace PouchDB { +// TODO: Fixing this lint error will require a large refactor +/* tslint:disable:no-single-declare-module */ +declare namespace PouchDB { interface Filter { - map: (doc: any) => void; - reduce?: (key: string, value: any) => any; + map(doc: any): void; + reduce?(key: string, value: any): any; } namespace Query { @@ -55,19 +58,19 @@ declare namespace PouchDB { stale?: 'ok' | 'update_after'; } - interface Response { + interface Response { total_rows: number; offset: number; - rows: { + rows: Array<{ id: any; key: any; value: any; doc?: Core.ExistingDocument; - }[] + }>; } } - export interface Database { + interface Database { /** * Cleans up any stale map/reduce indexes. * @@ -76,7 +79,7 @@ declare namespace PouchDB { * to take up space on disk. viewCleanup() removes these unnecessary * index files. */ - viewCleanup(callback: PouchDB.Core.Callback): void; + viewCleanup(callback: PouchDB.Core.Callback): void; /** * Cleans up any stale map/reduce indexes. * @@ -91,17 +94,17 @@ declare namespace PouchDB { * Invoke a map/reduce function, which allows you to perform more complex queries * on PouchDB than what you get with allDocs(). */ - query(fun: string | Filter | Function, opts: Query.Options, callback: (err: Core.Error, res: Query.Response) => void): void; + query(fun: string | Filter | ((doc: any) => void), opts: Query.Options, callback: (err: Core.Error, res: Query.Response) => void): void; /** * Invoke a map/reduce function, which allows you to perform more complex queries * on PouchDB than what you get with allDocs(). */ - query(fun: string | Filter | Function, callback: (err: Core.Error, res: Query.Response) => void): void; + query(fun: string | Filter | ((doc: any) => void), callback: (err: Core.Error, res: Query.Response) => void): void; /** * Invoke a map/reduce function, which allows you to perform more complex queries * on PouchDB than what you get with allDocs(). */ - query(fun: string | Filter | Function, opts?: Query.Options): Promise>; + query(fun: string | Filter | ((doc: any) => void), opts?: Query.Options): Promise>; } } diff --git a/types/pouchdb-mapreduce/pouchdb-mapreduce-tests.ts b/types/pouchdb-mapreduce/pouchdb-mapreduce-tests.ts index 6f6d941e83..6c028a5d93 100644 --- a/types/pouchdb-mapreduce/pouchdb-mapreduce-tests.ts +++ b/types/pouchdb-mapreduce/pouchdb-mapreduce-tests.ts @@ -1,5 +1,7 @@ function testConstructor() { - type MyModel = { numericProperty: number }; + interface MyModel { + numericProperty: number; + } let model: PouchDB.Core.Document; let db = new PouchDB('mydb'); @@ -8,14 +10,14 @@ function testConstructor() { } function testQuery() { - let pouch = new PouchDB<{}>('mydb'); + let pouch = new PouchDB('mydb'); // find pokemon with name === 'Pika pi!' pouch.query('my_index/by_name', { key : 'Pika pi!', include_docs : true - }).then(function (result) { + }).then((result) => { // handle result - }).catch(function (err) { + }).catch((err) => { // handle errors }); @@ -25,10 +27,9 @@ function testQuery() { endkey : 'P\uffff', limit : 5, include_docs : true - }).then(function (result) { + }).then((result) => { // handle result - }).catch(function (err) { + }).catch((err) => { // handle errors }); - } diff --git a/types/pouchdb-mapreduce/tslint.json b/types/pouchdb-mapreduce/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pouchdb-mapreduce/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }