From f48f415b0a6049399ee9e150a604ae39b6b4e70f Mon Sep 17 00:00:00 2001 From: fredericogalvao Date: Tue, 22 Sep 2015 14:01:08 -0300 Subject: [PATCH 1/7] Implementing standard Promises, so that the 3rd party implementations can merge declarations. --- pouchdb-tests.ts | 8 +++--- pouchdb.d.ts | 67 +++++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/pouchdb-tests.ts b/pouchdb-tests.ts index e17f9f9..18e1469 100644 --- a/pouchdb-tests.ts +++ b/pouchdb-tests.ts @@ -14,16 +14,18 @@ module promise { foo: string; } - class fakePromise implements pouchdb.async.Thenable { + class fakePromise implements Promise { new() { } - then(onFulfilled?: (value: T) => pouchdb.async.Thenable | R, onRejected?: (error: any) => pouchdb.async.Thenable | R) { + then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: any) => Promise | R) { return new fakePromise(); } - catch(onRejected: (error: any) => pouchdb.async.Thenable | R) { + catch(onRejected: (error: any) => Promise | R) { return undefined; } + + [Symbol.toStringTag]: string; } function chainedThen() { diff --git a/pouchdb.d.ts b/pouchdb.d.ts index a454e21..cb4e656 100644 --- a/pouchdb.d.ts +++ b/pouchdb.d.ts @@ -126,7 +126,7 @@ declare module pouchdb { } } /** - * Contains the standard pouchdb promises + * Contains the standard pouchdb promise utilities * @todo what is the error shape? looks like they contain status/reason/message and id(s)? */ module async { @@ -140,13 +140,6 @@ declare module pouchdb { message?: string; status?: number; } - /** An interface to represent a promise object */ - interface Thenable { - /** A Promises/A+ `then` implementation */ - then(onFulfilled?: (value: T) => Thenable|R, onRejected?: (error: Error) => Thenable|R): Thenable; - /** `catch` implementation as per the pouchdb example docs */ - catch(onRejected: (error: Error) => Thenable|R): Thenable; - } /** Callback alternatives to promised */ interface Callback { /** @@ -338,13 +331,13 @@ declare module pouchdb { /** Promise pattern for allDocs() */ interface Promise { /** Fetch multiple documents, indexed and sorted by the `_id`. */ - allDocs(): async.Thenable; + allDocs(): GlobalPromise; /** Fetch multiple documents, indexed and sorted by the `_id`. */ - allDocs(options: RangeOptions): async.Thenable; + allDocs(options: RangeOptions): GlobalPromise; /** Fetch multiple documents, indexed and sorted by the `_id`. */ - allDocs(options: PaginationOptions): async.Thenable; + allDocs(options: PaginationOptions): GlobalPromise; /** Fetch multiple documents, indexed and sorted by the `_id`. */ - allDocs(options: FilterOptions): async.Thenable; + allDocs(options: FilterOptions): GlobalPromise; } } @@ -480,40 +473,40 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - bulkDocs(folder: DocumentPouch, options?: BulkDocsOptions): async.Thenable; + bulkDocs(folder: DocumentPouch, options?: BulkDocsOptions): GlobalPromise; /** * Update/Delete each doc in an array of documents. * @param doc the doc * @param options * @todo define options shape - docs don't make it clear what this is */ - bulkDocs(docs: ExistingDoc[], options?: BulkDocsOptions): async.Thenable; + bulkDocs(docs: ExistingDoc[], options?: BulkDocsOptions): GlobalPromise; /** * Create multiple documents. * @param doc the doc * @param options */ - bulkDocs(folder: DocumentPouch): async.Thenable; + bulkDocs(folder: DocumentPouch): GlobalPromise; /** * Create multiple documents. * @param doc the doc * @param options * @todo define options shape - docs don't make it clear what this is */ - bulkDocs(docs: NewDoc[], options?: BulkDocsOptions): async.Thenable; + bulkDocs(docs: NewDoc[], options?: BulkDocsOptions): GlobalPromise; /** * Perform mixed Create/Update/Delete operations on multiple documents. * @param docs the documents to act on * @param options */ - bulkDocs(folder: DocumentPouch): async.Thenable; + bulkDocs(folder: DocumentPouch): GlobalPromise; /** * Perform mixed Create/Update/Delete operations on multiple documents. * @param docs the documents to act on * @param options * @todo define options shape - docs don't make it clear what this is */ - bulkDocs(docs: MixedDoc[], options?: BulkDocsOptions): async.Thenable; + bulkDocs(docs: MixedDoc[], options?: BulkDocsOptions): GlobalPromise; } } @@ -690,7 +683,7 @@ declare module pouchdb { /** Promise pattern for close() */ interface Promise { /** Closes the pouchdb */ - close(): async.Thenable; + close(): GlobalPromise; } } @@ -724,7 +717,7 @@ declare module pouchdb { * Deletes a database * @param options ajax options */ - destroy(options?: options.OptionsWithAjax): async.Thenable; + destroy(options?: options.OptionsWithAjax): GlobalPromise; } } @@ -803,7 +796,7 @@ declare module pouchdb { * @param docId the doc id * @param options */ - get(docId: string, options?: Options): async.Thenable; + get(docId: string, options?: Options): GlobalPromise; } } @@ -817,7 +810,7 @@ declare module pouchdb { /** Promise pattern for `id()` */ interface Promise { /** Returns the instance id for the pouchdb */ - id(): async.Thenable; + id(): GlobalPromise; } } @@ -852,7 +845,7 @@ declare module pouchdb { /** Promise pattern for `info()` */ interface Promise { /** Returns the instance info for the pouchdb */ - info(): async.Thenable; + info(): GlobalPromise; } } @@ -890,7 +883,7 @@ declare module pouchdb { * @param options ajax options * @todo define options shape - docs don't make it clear what this is */ - post(doc: BaseDoc, options?: options.EmptyOptions): async.Thenable; + post(doc: BaseDoc, options?: options.EmptyOptions): GlobalPromise; } } @@ -971,14 +964,14 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - put(doc: ExistingDoc, options?: options.EmptyOptions): async.Thenable; + put(doc: ExistingDoc, options?: options.EmptyOptions): GlobalPromise; /** * Create a new document. * @param doc the doc * @param options * @todo define options shape - docs don't make it clear what this is */ - put(doc: NewDoc, options?: options.EmptyOptions): async.Thenable; + put(doc: NewDoc, options?: options.EmptyOptions): GlobalPromise; /** * Update an existing document. * @param doc the doc @@ -987,7 +980,7 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - put(doc: BaseDoc, docId: string, docRev: string, options?: options.EmptyOptions): async.Thenable; + put(doc: BaseDoc, docId: string, docRev: string, options?: options.EmptyOptions): GlobalPromise; /** * Create a new document. If the document already exists, * you must use the update overload otherwise a conflict will occur. @@ -996,7 +989,7 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - put(doc: BaseDoc, docId: string, options?: options.EmptyOptions): async.Thenable; + put(doc: BaseDoc, docId: string, options?: options.EmptyOptions): GlobalPromise; } } @@ -1070,7 +1063,7 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - remove(docId: string, docRev: string, options?: options.EmptyOptions): async.Thenable; + remove(docId: string, docRev: string, options?: options.EmptyOptions): GlobalPromise; /** * Deletes the document. * `doc` is required to be a document with at least an `_id` and a `_rev` property. @@ -1079,14 +1072,14 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - remove(doc: ExistingDoc, options?: options.EmptyOptions): async.Thenable; + remove(doc: ExistingDoc, options?: options.EmptyOptions): GlobalPromise; /** * Deletes the document. * `doc` is required to be a document with at least an `_id` property, `rev` is specified in the `options`. * @param doc the doc (with only an `id` property) * @param options options that specify */ - remove(doc: NewDoc, options: RevOptions): async.Thenable; + remove(doc: NewDoc, options: RevOptions): GlobalPromise; } } } @@ -1241,7 +1234,7 @@ declare module pouchdb { * Usually only a `pouchdb.promise.PouchDB` reference would be kept, assigned by * the `then` of the constructor. */ - interface PouchDB extends promise.PouchDB, async.Thenable { } + interface PouchDB extends promise.PouchDB, GlobalPromise { } } /** Static-side interface for PouchDB */ @@ -1380,3 +1373,13 @@ declare module pouchdb { new (options: options.ctor.DbName): thenable.PouchDB; } } + +/** Merges declaration with another supplied interface to represent a promise object with custom error typings */ +interface GlobalPromise extends Promise { + /** A Promises/A+ `then` implementation */ + then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: pouchdb.async.Error) => Promise | R): Promise; + then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: pouchdb.async.Error) => void): Promise; + /** `catch` implementation as per the pouchdb example docs */ + catch(onRejected?: (error: pouchdb.async.Error) => Promise | R): Promise; + catch(onRejected?: (error: pouchdb.async.Error) => void): Promise; +} From 6f6e8e4e5befc0e77506acb476f09fffe22e40d5 Mon Sep 17 00:00:00 2001 From: fredericogalvao Date: Wed, 23 Sep 2015 16:27:08 -0300 Subject: [PATCH 2/7] Fixing tests after tsconfig changes --- pouchdb-tests.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pouchdb-tests.ts b/pouchdb-tests.ts index 18e1469..92eeb0c 100644 --- a/pouchdb-tests.ts +++ b/pouchdb-tests.ts @@ -14,18 +14,16 @@ module promise { foo: string; } - class fakePromise implements Promise { + class fakePromise implements GlobalPromise { new() { } - then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: any) => Promise | R) { + then(onFulfilled?: (value: T) => GlobalPromise | R, onRejected?: (error: any) => GlobalPromise | R) { return new fakePromise(); } - catch(onRejected: (error: any) => Promise | R) { + catch(onRejected: (error: any) => GlobalPromise | R) { return undefined; } - - [Symbol.toStringTag]: string; } function chainedThen() { From d19f9d29d0e93190eb5f7e23f8319e3bf527aa3b Mon Sep 17 00:00:00 2001 From: fredericogalvao Date: Wed, 23 Sep 2015 18:34:29 -0300 Subject: [PATCH 3/7] Finishing touch on the PouchPromise as per #22. FIxing tests to compile on es6. Conflicts: tsconfig.json Conflicts: pouchdb.d.ts Conflicts: pouchdb.d.ts --- pouchdb-tests.ts | 8 +++--- pouchdb.d.ts | 67 ++++++++++++++++++++++++------------------------ 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/pouchdb-tests.ts b/pouchdb-tests.ts index 92eeb0c..18e1469 100644 --- a/pouchdb-tests.ts +++ b/pouchdb-tests.ts @@ -14,16 +14,18 @@ module promise { foo: string; } - class fakePromise implements GlobalPromise { + class fakePromise implements Promise { new() { } - then(onFulfilled?: (value: T) => GlobalPromise | R, onRejected?: (error: any) => GlobalPromise | R) { + then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: any) => Promise | R) { return new fakePromise(); } - catch(onRejected: (error: any) => GlobalPromise | R) { + catch(onRejected: (error: any) => Promise | R) { return undefined; } + + [Symbol.toStringTag]: string; } function chainedThen() { diff --git a/pouchdb.d.ts b/pouchdb.d.ts index cb4e656..68294d5 100644 --- a/pouchdb.d.ts +++ b/pouchdb.d.ts @@ -140,6 +140,15 @@ declare module pouchdb { message?: string; status?: number; } + /** Overrides a supplied interface to represent a promise object with custom error typings for the first pass */ + export interface PouchPromise extends Promise { + /** A Promises/A+ `then` implementation */ + then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: pouchdb.async.Error) => Promise | R): Promise; + then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: pouchdb.async.Error) => void): Promise; + /** `catch` implementation as per the pouchdb example docs */ + catch(onRejected?: (error: pouchdb.async.Error) => Promise | R): Promise; + catch(onRejected?: (error: pouchdb.async.Error) => void): Promise; + } /** Callback alternatives to promised */ interface Callback { /** @@ -331,13 +340,13 @@ declare module pouchdb { /** Promise pattern for allDocs() */ interface Promise { /** Fetch multiple documents, indexed and sorted by the `_id`. */ - allDocs(): GlobalPromise; + allDocs(): async.PouchPromise; /** Fetch multiple documents, indexed and sorted by the `_id`. */ - allDocs(options: RangeOptions): GlobalPromise; + allDocs(options: RangeOptions): async.PouchPromise; /** Fetch multiple documents, indexed and sorted by the `_id`. */ - allDocs(options: PaginationOptions): GlobalPromise; + allDocs(options: PaginationOptions): async.PouchPromise; /** Fetch multiple documents, indexed and sorted by the `_id`. */ - allDocs(options: FilterOptions): GlobalPromise; + allDocs(options: FilterOptions): async.PouchPromise; } } @@ -473,40 +482,40 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - bulkDocs(folder: DocumentPouch, options?: BulkDocsOptions): GlobalPromise; + bulkDocs(folder: DocumentPouch, options?: BulkDocsOptions): async.PouchPromise; /** * Update/Delete each doc in an array of documents. * @param doc the doc * @param options * @todo define options shape - docs don't make it clear what this is */ - bulkDocs(docs: ExistingDoc[], options?: BulkDocsOptions): GlobalPromise; + bulkDocs(docs: ExistingDoc[], options?: BulkDocsOptions): async.PouchPromise; /** * Create multiple documents. * @param doc the doc * @param options */ - bulkDocs(folder: DocumentPouch): GlobalPromise; + bulkDocs(folder: DocumentPouch): async.PouchPromise; /** * Create multiple documents. * @param doc the doc * @param options * @todo define options shape - docs don't make it clear what this is */ - bulkDocs(docs: NewDoc[], options?: BulkDocsOptions): GlobalPromise; + bulkDocs(docs: NewDoc[], options?: BulkDocsOptions): async.PouchPromise; /** * Perform mixed Create/Update/Delete operations on multiple documents. * @param docs the documents to act on * @param options */ - bulkDocs(folder: DocumentPouch): GlobalPromise; + bulkDocs(folder: DocumentPouch): async.PouchPromise; /** * Perform mixed Create/Update/Delete operations on multiple documents. * @param docs the documents to act on * @param options * @todo define options shape - docs don't make it clear what this is */ - bulkDocs(docs: MixedDoc[], options?: BulkDocsOptions): GlobalPromise; + bulkDocs(docs: MixedDoc[], options?: BulkDocsOptions): async.PouchPromise; } } @@ -683,7 +692,7 @@ declare module pouchdb { /** Promise pattern for close() */ interface Promise { /** Closes the pouchdb */ - close(): GlobalPromise; + close(): async.PouchPromise; } } @@ -717,7 +726,7 @@ declare module pouchdb { * Deletes a database * @param options ajax options */ - destroy(options?: options.OptionsWithAjax): GlobalPromise; + destroy(options?: options.OptionsWithAjax): async.PouchPromise; } } @@ -796,7 +805,7 @@ declare module pouchdb { * @param docId the doc id * @param options */ - get(docId: string, options?: Options): GlobalPromise; + get(docId: string, options?: Options): async.PouchPromise; } } @@ -810,7 +819,7 @@ declare module pouchdb { /** Promise pattern for `id()` */ interface Promise { /** Returns the instance id for the pouchdb */ - id(): GlobalPromise; + id(): async.PouchPromise; } } @@ -845,7 +854,7 @@ declare module pouchdb { /** Promise pattern for `info()` */ interface Promise { /** Returns the instance info for the pouchdb */ - info(): GlobalPromise; + info(): async.PouchPromise; } } @@ -883,7 +892,7 @@ declare module pouchdb { * @param options ajax options * @todo define options shape - docs don't make it clear what this is */ - post(doc: BaseDoc, options?: options.EmptyOptions): GlobalPromise; + post(doc: BaseDoc, options?: options.EmptyOptions): async.PouchPromise; } } @@ -964,14 +973,14 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - put(doc: ExistingDoc, options?: options.EmptyOptions): GlobalPromise; + put(doc: ExistingDoc, options?: options.EmptyOptions): async.PouchPromise; /** * Create a new document. * @param doc the doc * @param options * @todo define options shape - docs don't make it clear what this is */ - put(doc: NewDoc, options?: options.EmptyOptions): GlobalPromise; + put(doc: NewDoc, options?: options.EmptyOptions): async.PouchPromise; /** * Update an existing document. * @param doc the doc @@ -980,7 +989,7 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - put(doc: BaseDoc, docId: string, docRev: string, options?: options.EmptyOptions): GlobalPromise; + put(doc: BaseDoc, docId: string, docRev: string, options?: options.EmptyOptions): async.PouchPromise; /** * Create a new document. If the document already exists, * you must use the update overload otherwise a conflict will occur. @@ -989,7 +998,7 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - put(doc: BaseDoc, docId: string, options?: options.EmptyOptions): GlobalPromise; + put(doc: BaseDoc, docId: string, options?: options.EmptyOptions): async.PouchPromise; } } @@ -1063,7 +1072,7 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - remove(docId: string, docRev: string, options?: options.EmptyOptions): GlobalPromise; + remove(docId: string, docRev: string, options?: options.EmptyOptions): async.PouchPromise; /** * Deletes the document. * `doc` is required to be a document with at least an `_id` and a `_rev` property. @@ -1072,14 +1081,14 @@ declare module pouchdb { * @param options * @todo define options shape - docs don't make it clear what this is */ - remove(doc: ExistingDoc, options?: options.EmptyOptions): GlobalPromise; + remove(doc: ExistingDoc, options?: options.EmptyOptions): async.PouchPromise; /** * Deletes the document. * `doc` is required to be a document with at least an `_id` property, `rev` is specified in the `options`. * @param doc the doc (with only an `id` property) * @param options options that specify */ - remove(doc: NewDoc, options: RevOptions): GlobalPromise; + remove(doc: NewDoc, options: RevOptions): async.PouchPromise; } } } @@ -1234,7 +1243,7 @@ declare module pouchdb { * Usually only a `pouchdb.promise.PouchDB` reference would be kept, assigned by * the `then` of the constructor. */ - interface PouchDB extends promise.PouchDB, GlobalPromise { } + interface PouchDB extends promise.PouchDB, async.PouchPromise { } } /** Static-side interface for PouchDB */ @@ -1373,13 +1382,3 @@ declare module pouchdb { new (options: options.ctor.DbName): thenable.PouchDB; } } - -/** Merges declaration with another supplied interface to represent a promise object with custom error typings */ -interface GlobalPromise extends Promise { - /** A Promises/A+ `then` implementation */ - then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: pouchdb.async.Error) => Promise | R): Promise; - then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: pouchdb.async.Error) => void): Promise; - /** `catch` implementation as per the pouchdb example docs */ - catch(onRejected?: (error: pouchdb.async.Error) => Promise | R): Promise; - catch(onRejected?: (error: pouchdb.async.Error) => void): Promise; -} From 074f2039df1380cee5126852b999f868b1ba0582 Mon Sep 17 00:00:00 2001 From: fredericogalvao Date: Wed, 23 Sep 2015 18:50:53 -0300 Subject: [PATCH 4/7] Renaming modulator interfaces to Promisable, as per #22. Closes #22. --- pouchdb.d.ts | 78 ++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/pouchdb.d.ts b/pouchdb.d.ts index 68294d5..5db55ca 100644 --- a/pouchdb.d.ts +++ b/pouchdb.d.ts @@ -149,7 +149,7 @@ declare module pouchdb { catch(onRejected?: (error: pouchdb.async.Error) => Promise | R): Promise; catch(onRejected?: (error: pouchdb.async.Error) => void): Promise; } - /** Callback alternatives to promised */ + /** Callback alternatives to promises */ interface Callback { /** * @param error the error object @@ -337,8 +337,8 @@ declare module pouchdb { /** Fetch multiple documents, indexed and sorted by the `_id`. */ allDocs(options: FilterOptions, callback?: async.Callback): void; } - /** Promise pattern for allDocs() */ - interface Promise { + /** Promisable pattern for allDocs() */ + interface Promisable { /** Fetch multiple documents, indexed and sorted by the `_id`. */ allDocs(): async.PouchPromise; /** Fetch multiple documents, indexed and sorted by the `_id`. */ @@ -474,8 +474,8 @@ declare module pouchdb { */ bulkDocs(docs: MixedDoc[], options: BulkDocsOptions, callback?: async.Callback): void; } - /** Promise pattern for bulkDocs() */ - interface Promise { + /** Promisable pattern for bulkDocs() */ + interface Promisable { /** * Update/Delete each doc in an array of documents. * @param folder the documents storage object @@ -678,8 +678,8 @@ declare module pouchdb { } /** Callback pattern for changes() */ interface Callback { } - /** Promise pattern for changes() */ - interface Promise { } + /** Promisable pattern for changes() */ + interface Promisable { } } /** Contains the method and call/return types for close() */ @@ -689,8 +689,8 @@ declare module pouchdb { /** Closes the pouchdb */ close(callback?: async.Callback): void; } - /** Promise pattern for close() */ - interface Promise { + /** Promisable pattern for close() */ + interface Promisable { /** Closes the pouchdb */ close(): async.PouchPromise; } @@ -719,9 +719,9 @@ declare module pouchdb { destroy(callback?: async.Callback): void; } /** - * Promise pattern for destroy + * Promisable pattern for destroy */ - interface Promise { + interface Promisable { /** * Deletes a database * @param options ajax options @@ -798,8 +798,8 @@ declare module pouchdb { */ get(docId: string, options: Options, callback?: async.Callback): void; } - /** Promise pattern for remove */ - interface Promise { + /** Promisable pattern for remove */ + interface Promisable { /** * Retrieves a document, specified by `docId`. * @param docId the doc id @@ -816,8 +816,8 @@ declare module pouchdb { /** Returns the instance id for the pouchdb */ id(callback?: async.Callback): void; } - /** Promise pattern for `id()` */ - interface Promise { + /** Promisable pattern for `id()` */ + interface Promisable { /** Returns the instance id for the pouchdb */ id(): async.PouchPromise; } @@ -851,8 +851,8 @@ declare module pouchdb { /** Returns the instance info for the pouchdb */ info(callback?: async.Callback): void; } - /** Promise pattern for `info()` */ - interface Promise { + /** Promisable pattern for `info()` */ + interface Promisable { /** Returns the instance info for the pouchdb */ info(): async.PouchPromise; } @@ -883,8 +883,8 @@ declare module pouchdb { */ post(doc: BaseDoc, options: options.EmptyOptions, callback?: async.Callback): void; } - /** Promise pattern for post */ - interface Promise { + /** Promisable pattern for post */ + interface Promisable { /** * Create a new document and let PouchDB auto-generate an _id for it. * (tip: use `put()` instead for better indexing) @@ -965,8 +965,8 @@ declare module pouchdb { */ put(doc: BaseDoc, docId: string, options: options.EmptyOptions, callback?: async.Callback): void; } - /** Promise pattern for put */ - interface Promise { + /** Promisable pattern for put */ + interface Promisable { /** * Update an existing document. * @param doc the doc @@ -1061,8 +1061,8 @@ declare module pouchdb { */ remove(doc: NewDoc, options: RevOptions, callback?: async.Callback): void; } - /** Promise pattern for remove */ - interface Promise { + /** Promisable pattern for remove */ + interface Promisable { /** * Deletes the document. * `doc` is required to be a document with at least an `_id` and a `_rev` property. @@ -1109,19 +1109,19 @@ declare module pouchdb { , methods.put.Callback , methods.remove.Callback { } /** pouchDB api: promise based */ - interface Promise extends + interface Promisable extends PouchInstance - , methods.allDocs.Promise - , methods.bulkDocs.Promise + , methods.allDocs.Promisable + , methods.bulkDocs.Promisable , methods.changes.Overloads - , methods.close.Promise - , methods.destroy.Promise - , methods.get.Promise - , methods.id.Promise - , methods.info.Promise - , methods.post.Promise - , methods.put.Promise - , methods.remove.Promise { } + , methods.close.Promisable + , methods.destroy.Promisable + , methods.get.Promisable + , methods.id.Promisable + , methods.info.Promisable + , methods.post.Promisable + , methods.put.Promisable + , methods.remove.Promisable { } } /** The main pouchDB interface */ @@ -1231,15 +1231,15 @@ declare module pouchdb { /** The main pouchDB interface (callback pattern) */ interface PouchDB extends api.db.Callback { } } - /** The api module for the pouchdb promise pattern */ + /** The api module for the pouchdb Promisable pattern */ module promise { - /** The main pouchDB interface (promise pattern) */ - interface PouchDB extends api.db.Promise { } + /** The main pouchDB interface (Promisable pattern) */ + interface PouchDB extends api.db.Promisable { } } /** The api module for the pouchdb promise pattern (constructor only) */ module thenable { /** - * Special case class returned by the constructors of the promise api pouchDB. + * Special case class returned by the constructors of the Promisable api pouchDB. * Usually only a `pouchdb.promise.PouchDB` reference would be kept, assigned by * the `then` of the constructor. */ @@ -1253,7 +1253,7 @@ declare module pouchdb { } /** * The main pouchDB entry point. The constructors here will return either a - * Callback or Promise pattern api. + * Callback or Promisable pattern api. */ export interface PouchDB { ////////////////////////////// local db ///////////////////////////// From 2512453d367e61d7e8e0159e233a5087a1d8a7c3 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 29 Sep 2015 00:47:25 +0100 Subject: [PATCH 5/7] Revert documentation changes from s&r --- pouchdb.d.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pouchdb.d.ts b/pouchdb.d.ts index 5db55ca..245dc90 100644 --- a/pouchdb.d.ts +++ b/pouchdb.d.ts @@ -337,7 +337,7 @@ declare module pouchdb { /** Fetch multiple documents, indexed and sorted by the `_id`. */ allDocs(options: FilterOptions, callback?: async.Callback): void; } - /** Promisable pattern for allDocs() */ + /** Promise pattern for allDocs() */ interface Promisable { /** Fetch multiple documents, indexed and sorted by the `_id`. */ allDocs(): async.PouchPromise; @@ -474,7 +474,7 @@ declare module pouchdb { */ bulkDocs(docs: MixedDoc[], options: BulkDocsOptions, callback?: async.Callback): void; } - /** Promisable pattern for bulkDocs() */ + /** Promise pattern for bulkDocs() */ interface Promisable { /** * Update/Delete each doc in an array of documents. @@ -678,7 +678,7 @@ declare module pouchdb { } /** Callback pattern for changes() */ interface Callback { } - /** Promisable pattern for changes() */ + /** Promise pattern for changes() */ interface Promisable { } } @@ -689,7 +689,7 @@ declare module pouchdb { /** Closes the pouchdb */ close(callback?: async.Callback): void; } - /** Promisable pattern for close() */ + /** Promise pattern for close() */ interface Promisable { /** Closes the pouchdb */ close(): async.PouchPromise; @@ -719,7 +719,7 @@ declare module pouchdb { destroy(callback?: async.Callback): void; } /** - * Promisable pattern for destroy + * Promise pattern for destroy */ interface Promisable { /** @@ -798,7 +798,7 @@ declare module pouchdb { */ get(docId: string, options: Options, callback?: async.Callback): void; } - /** Promisable pattern for remove */ + /** Promise pattern for remove */ interface Promisable { /** * Retrieves a document, specified by `docId`. @@ -816,7 +816,7 @@ declare module pouchdb { /** Returns the instance id for the pouchdb */ id(callback?: async.Callback): void; } - /** Promisable pattern for `id()` */ + /** Promise pattern for `id()` */ interface Promisable { /** Returns the instance id for the pouchdb */ id(): async.PouchPromise; @@ -851,7 +851,7 @@ declare module pouchdb { /** Returns the instance info for the pouchdb */ info(callback?: async.Callback): void; } - /** Promisable pattern for `info()` */ + /** Promise pattern for `info()` */ interface Promisable { /** Returns the instance info for the pouchdb */ info(): async.PouchPromise; @@ -883,7 +883,7 @@ declare module pouchdb { */ post(doc: BaseDoc, options: options.EmptyOptions, callback?: async.Callback): void; } - /** Promisable pattern for post */ + /** Promise pattern for post */ interface Promisable { /** * Create a new document and let PouchDB auto-generate an _id for it. @@ -965,7 +965,7 @@ declare module pouchdb { */ put(doc: BaseDoc, docId: string, options: options.EmptyOptions, callback?: async.Callback): void; } - /** Promisable pattern for put */ + /** Promise pattern for put */ interface Promisable { /** * Update an existing document. @@ -1061,7 +1061,7 @@ declare module pouchdb { */ remove(doc: NewDoc, options: RevOptions, callback?: async.Callback): void; } - /** Promisable pattern for remove */ + /** Promise pattern for remove */ interface Promisable { /** * Deletes the document. @@ -1231,15 +1231,15 @@ declare module pouchdb { /** The main pouchDB interface (callback pattern) */ interface PouchDB extends api.db.Callback { } } - /** The api module for the pouchdb Promisable pattern */ + /** The api module for the pouchdb promise pattern */ module promise { - /** The main pouchDB interface (Promisable pattern) */ + /** The main pouchDB interface (promise pattern) */ interface PouchDB extends api.db.Promisable { } } /** The api module for the pouchdb promise pattern (constructor only) */ module thenable { /** - * Special case class returned by the constructors of the Promisable api pouchDB. + * Special case class returned by the constructors of the promise api pouchDB. * Usually only a `pouchdb.promise.PouchDB` reference would be kept, assigned by * the `then` of the constructor. */ @@ -1253,7 +1253,7 @@ declare module pouchdb { } /** * The main pouchDB entry point. The constructors here will return either a - * Callback or Promisable pattern api. + * Callback or Promise pattern api. */ export interface PouchDB { ////////////////////////////// local db ///////////////////////////// From 683960011d84c774d73ab4d4c878a77aeb1eff10 Mon Sep 17 00:00:00 2001 From: fredericogalvao Date: Wed, 23 Sep 2015 18:53:23 -0300 Subject: [PATCH 6/7] Making sure all test-based code is inside an explicitly-named test module, to prevent using test code in definition files. --- pouchdb-tests.ts | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pouchdb-tests.ts b/pouchdb-tests.ts index 18e1469..8964a87 100644 --- a/pouchdb-tests.ts +++ b/pouchdb-tests.ts @@ -9,34 +9,34 @@ /// /// -module promise { - class Foo { - foo: string; - } +module PouchDBTest { + module promise { + class Foo { + foo: string; + } - class fakePromise implements Promise { - new() { } + class fakePromise implements Promise { + new() { } - then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: any) => Promise | R) { - return new fakePromise(); - } + then(onFulfilled?: (value: T) => Promise | R, onRejected?: (error: any) => Promise | R) { + return new fakePromise(); + } - catch(onRejected: (error: any) => Promise | R) { - return undefined; - } + catch(onRejected: (error: any) => Promise | R) { + return undefined; + } - [Symbol.toStringTag]: string; - } + [Symbol.toStringTag]: string; + } - function chainedThen() { - var fooOut: string; - new PouchDB("dbname") - .then((db) => new fakePromise()) - .then((value: Foo) => { fooOut = value.foo; }); + function chainedThen() { + var fooOut: string; + new PouchDB("dbname") + .then((db) => new fakePromise()) + .then((value: Foo) => { fooOut = value.foo; }); + } } -} -module PouchDBTest { module localDb { // common variables var dbt: pouchdb.thenable.PouchDB; From 08c11312ab55516c5a0065cea3ab91d3cf2331f0 Mon Sep 17 00:00:00 2001 From: fredericogalvao Date: Tue, 29 Sep 2015 19:57:12 -0300 Subject: [PATCH 7/7] Normalizing jsDoc with proper reference on thenable.PouchDB --- pouchdb.d.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pouchdb.d.ts b/pouchdb.d.ts index 245dc90..2ae36f7 100644 --- a/pouchdb.d.ts +++ b/pouchdb.d.ts @@ -1261,7 +1261,7 @@ declare module pouchdb { * Creates a new local pouchDb with the name specified and * all the default options * @param name the database name - * @returns a Thenable + * @returns a thenable.PouchDB */ new (name: string): thenable.PouchDB; /** @@ -1279,7 +1279,7 @@ declare module pouchdb { * Creates a new local SQLite pouchDb with the name and options provided * @param name the database name * @param options the SQlite database options - * @returns a Thenable + * @returns a thenable.PouchDB */ new (name: string, options: options.ctor.LocalSQLiteDb): thenable.PouchDB; /** @@ -1294,7 +1294,7 @@ declare module pouchdb { /** * Creates a new local SQLite pouchDb with the options provided * @param options the SQlite database options, including the name - * @returns a Thenable + * @returns a thenable.PouchDB */ new (options: options.ctor.LocalSQLiteDbWithName): thenable.PouchDB; /** @@ -1310,7 +1310,7 @@ declare module pouchdb { * Creates a new local WebSQL pouchDb with the name and options provided * @param name A string value that specifies the database name * @param options An object that specifies the local database options - * @returns a Thenable + * @returns a thenable.PouchDB */ new (name: string, options: options.ctor.LocalWebSQLDb): thenable.PouchDB; /** @@ -1325,7 +1325,7 @@ declare module pouchdb { /** * Creates a new local WebSQL pouchDb with the options provided * @param options An object that specifies the local database options - * @returns a Thenable + * @returns a thenable.PouchDB */ new (options: options.ctor.LocalWebSQLDbWithName): thenable.PouchDB; /** @@ -1341,7 +1341,7 @@ declare module pouchdb { * Creates a new local pouchDb with the name and options provided * @param name the database name * @param options the local database options - * @returns a Thenable + * @returns a thenable.PouchDB */ new (name: string, options: options.ctor.LocalDb): thenable.PouchDB; /** @@ -1356,7 +1356,7 @@ declare module pouchdb { /** * Creates a new local pouchDb with the options provided * @param options the local database options, including the name - * @returns a Thenable + * @returns a thenable.PouchDB */ new (options: options.ctor.LocalDbWithName): thenable.PouchDB; /** @@ -1372,12 +1372,14 @@ declare module pouchdb { * A fallback constructor if none of the typed constructors cover a use case * @todo if you find yourself using this, consider contributing a patch * to add/improve the necessary typed overload instead of `options: any` + * @returns a thenable.PouchDB */ new (name: string, options: any): thenable.PouchDB; /** * A fallback constructor if none of the typed constructors cover a use case * @todo if you find yourself using this, consider contributing a patch * to add/improve the necessary typed overload instead of `options: pouchdb.options.DbName` + * @returns a thenable.PouchDB */ new (options: options.ctor.DbName): thenable.PouchDB; }