From 8f92ae45d43ed9074df3531909eb92f5a4eabe16 Mon Sep 17 00:00:00 2001 From: Max Battcher Date: Thu, 8 Jun 2017 20:12:24 -0400 Subject: [PATCH] Further model reduction in pouchdb-mapreduce Reduce should be a CouchDB-style reduction function (keys, values, rereduce). For query, the Model is the Reduction or the currently hidden from types emit(key, value) value. --- types/pouchdb-mapreduce/index.d.ts | 33 ++++++++++-------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/types/pouchdb-mapreduce/index.d.ts b/types/pouchdb-mapreduce/index.d.ts index b9a05ff7d6..4ecf21d370 100644 --- a/types/pouchdb-mapreduce/index.d.ts +++ b/types/pouchdb-mapreduce/index.d.ts @@ -10,15 +10,19 @@ /* tslint:disable:no-single-declare-module */ declare namespace PouchDB { + type Map = (doc: Content) => void; + // The any below would be the value type from emit(key, value), currently hidden from type information in the Map + type Reducer = (keys: Array<[string, any]> | null, values: Content[] | Reduction[], rereduce: boolean) => Reduction[] | Reduction; + interface Filter { - map(doc: Content): void; - reduce?(key: string, value: Content): Reduction; + map: Map; + reduce?: Reducer | '_sum' | '_count' | '_stats' | string; } namespace Query { - interface Options { + interface Options { /** Reduce function, or the string name of a built-in function: '_sum', '_count', or '_stats'. */ - reduce?: ((...args: any[]) => void) | '_sum' | '_count' | '_stats' | boolean; + reduce?: Reducer | '_sum' | '_count' | '_stats' | boolean; /** Include the document in each row in the doc field. */ include_docs?: boolean; /** Include conflicts in the _conflicts field of a doc. */ @@ -94,32 +98,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 | ((doc: Content & Model) => void), opts: Query.Options, callback: (err: Core.Error, res: Query.Response) => void): void; + query(fun: string | Map | Filter, opts: Query.Options, callback: Core.Callback>): void; /** * Invoke a map/reduce function, which allows you to perform more complex queries * on PouchDB than what you get with allDocs(). */ - query(fun: Filter, opts: Query.Options, callback: (err: Core.Error, res: Query.Response) => void): void; + query(fun: string | Map | Filter, callback: Core.Callback>): 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 | ((doc: Content & Model) => 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: Filter, 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 | ((doc: Content & Model) => void), opts?: Query.Options): Promise>; - /** - * Invoke a map/reduce function, which allows you to perform more complex queries - * on PouchDB than what you get with allDocs(). - */ - query(fun: Filter, opts?: Query.Options): Promise>; + query(fun: string | Map | Filter, opts?: Query.Options): Promise>; } }