diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index e2a6593019..e26ae3ef90 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -256,7 +256,7 @@ declare module "mongoose" { type model = _mongoose.Model; type Model = _mongoose.ModelConstructor; type Mongoose = typeof mongoose; - interface Promise extends MongoosePromise {} + interface Promise extends _mongoose._MongoosePromise {} interface Query extends _mongoose.Query {} interface QueryCursor extends _mongoose.QueryCursor {} interface QueryStream extends _mongoose.QueryStream {} @@ -305,13 +305,13 @@ declare module "mongoose" { * and .disconnect().then() are viable. */ static then(onFulfill?: () => void | TRes | PromiseLike, - onRejected?: (err: mongodb.MongoError) => void | TRes | PromiseLike): MongoosePromise; + onRejected?: (err: mongodb.MongoError) => void | TRes | PromiseLike): _MongoosePromise; /** * Ability to use mongoose object as a pseudo-promise so .connect().then() * and .disconnect().then() are viable. */ - static catch(onRejected?: (err: mongodb.MongoError) => void | TRes | PromiseLike): MongoosePromise; + static catch(onRejected?: (err: mongodb.MongoError) => void | TRes | PromiseLike): _MongoosePromise; } class CastError extends _mongoose.Error { @@ -422,7 +422,7 @@ declare module "mongoose" { callback?: (err: any) => void): any; /** Closes the connection */ - close(callback?: (err: any) => void): MongoosePromise; + close(callback?: (err: any) => void): _MongoosePromise; /** * Retrieves a collection, creating it if not cached. @@ -600,7 +600,7 @@ declare module "mongoose" { constructor(query: Query, options: Object): QueryCursor; /** Marks this cursor as closed. Will stop streaming and subsequent calls to next() will error. */ - close(callback?: (error: any, result: any) => void): MongoosePromise; + close(callback?: (error: any, result: any) => void): _MongoosePromise; /** * Execute fn for every document in the cursor. If fn returns a promise, @@ -608,13 +608,13 @@ declare module "mongoose" { * Returns a promise that resolves when done. * @param callback executed when all docs have been processed */ - eachAsync(fn: (doc: Model) => any, callback?: (err: any) => void): MongoosePromise>; + eachAsync(fn: (doc: Model) => any, callback?: (err: any) => void): _MongoosePromise>; /** * Get the next document from this cursor. Will return null when there are * no documents left. */ - next(callback?: (err: any) => void): MongoosePromise; + next(callback?: (err: any) => void): _MongoosePromise; } /* @@ -871,7 +871,7 @@ declare module "mongoose" { * Useful for ES2015 integration. * @returns promise that resolves to the document when population is done */ - execPopulate(): MongoosePromise; + execPopulate(): _MongoosePromise; /** * Returns the value of a path. @@ -990,8 +990,8 @@ declare module "mongoose" { * @param optional options internal options * @param callback callback called after validation completes, passing an error if one occurred */ - validate(callback?: (err: any) => void): MongoosePromise; - validate(optional: Object, callback?: (err: any) => void): MongoosePromise; + validate(callback?: (err: any) => void): _MongoosePromise; + validate(optional: Object, callback?: (err: any) => void): _MongoosePromise; /** * Executes registered validation rules (skipping asynchronous validators) for this document. @@ -1310,7 +1310,7 @@ declare module "mongoose" { * resolved with either the doc(s) or rejected with the error. * Like .then(), but only takes a rejection handler. */ - catch(reject?: (err: any) => void | TRes | PromiseLike): MongoosePromise; + catch(reject?: (err: any) => void | TRes | PromiseLike): _MongoosePromise; /** * DEPRECATED Alias for circle @@ -1363,8 +1363,8 @@ declare module "mongoose" { equals(val: Object): this; /** Executes the query */ - exec(callback?: (err: any, res: T) => void): MongoosePromise; - exec(operation: string | Function, callback?: (err: any, res: T) => void): MongoosePromise; + exec(callback?: (err: any, res: T) => void): _MongoosePromise; + exec(operation: string | Function, callback?: (err: any, res: T) => void): _MongoosePromise; /** Specifies an $exists condition */ exists(val?: boolean): this; @@ -1655,7 +1655,7 @@ declare module "mongoose" { /** Executes this query and returns a promise */ then(resolve?: (res: T) => void | TRes | PromiseLike, - reject?: (err: any) => void | TRes | PromiseLike): MongoosePromise; + reject?: (err: any) => void | TRes | PromiseLike): _MongoosePromise; /** * Converts this query to a customized, reusable query @@ -1998,10 +1998,10 @@ declare module "mongoose" { // If cursor option is on, could return an object /** Executes the aggregate pipeline on the currently bound Model. */ - exec(callback?: (err: any, result: T) => void): MongoosePromise | any; + exec(callback?: (err: any, result: T) => void): _MongoosePromise | any; /** Execute the aggregation with explain */ - explain(callback?: (err: any, result: T) => void): MongoosePromise; + explain(callback?: (err: any, result: T) => void): _MongoosePromise; /** * Appends a new custom $group operator to this aggregate pipeline. @@ -2076,7 +2076,7 @@ declare module "mongoose" { /** Provides promise for aggregate. */ then(resolve?: (val: T) => void | TRes | PromiseLike, - reject?: (err: any) => void | TRes | PromiseLike): MongoosePromise + reject?: (err: any) => void | TRes | PromiseLike): _MongoosePromise /** * Appends new custom $unwind operator(s) to this aggregate pipeline. @@ -2144,6 +2144,25 @@ declare module "mongoose" { type?: string): this; } + /** + * section promise.js + * http://mongoosejs.com/docs/api.html#promise-js + * + * You must assign a promise library: + * + * 1. To use mongoose's default promise library: + * Install mongoose-promise.d.ts + * + * 2. To use native ES6 promises, add this line to your main .d.ts file: + * type MongoosePromise = Promise; + * + * 3. To use another promise library (for example q): + * Install q.d.ts + * Then add this line to your main .d.ts file: + * type MongoosePromise = Q.Promise; + */ + type _MongoosePromise = MongoosePromise; + /* * section model.js * http://mongoosejs.com/docs/api.html#model-js @@ -2203,7 +2222,7 @@ declare module "mongoose" { * @param ... aggregation pipeline operator(s) or operator array */ aggregate(...aggregations: Object[]): Aggregate; - aggregate(...aggregationsWithCallback: Object[]): MongoosePromise; + aggregate(...aggregationsWithCallback: Object[]): _MongoosePromise; /** Counts number of matching documents in a database collection. */ count(conditions: Object, callback?: (err: any, count: number) => void): Query; @@ -2213,9 +2232,9 @@ declare module "mongoose" { * does new MyModel(doc).save() for every doc in docs. * Triggers the save() hook. */ - create(docs: any[], callback?: (err: any, res: Model[]) => void): MongoosePromise[]>; - create(...docs: Object[]): MongoosePromise>; - create(...docsWithCallback: Object[]): MongoosePromise>; + create(docs: any[], callback?: (err: any, res: Model[]) => void): _MongoosePromise[]>; + create(...docs: Object[]): _MongoosePromise>; + create(...docsWithCallback: Object[]): _MongoosePromise>; /** * Adds a discriminator type. @@ -2234,8 +2253,8 @@ declare module "mongoose" { * @param options internal options * @param cb optional callback */ - ensureIndexes(callback?: (err: any) => void): MongoosePromise; - ensureIndexes(options: Object, callback?: (err: any) => void): MongoosePromise; + ensureIndexes(callback?: (err: any) => void): _MongoosePromise; + ensureIndexes(options: Object, callback?: (err: any) => void): _MongoosePromise; /** * Finds documents. @@ -2370,9 +2389,9 @@ declare module "mongoose" { * document. * This function does not trigger save middleware. */ - insertMany(docs: any[], callback?: (error: any, docs: Model[]) => void): MongoosePromise[]>; - insertMany(doc: any, callback?: (error: any, doc: Model) => void): MongoosePromise>; - insertMany(...docsWithCallback: Object[]): MongoosePromise>; + insertMany(docs: any[], callback?: (error: any, docs: Model[]) => void): _MongoosePromise[]>; + insertMany(doc: any, callback?: (error: any, doc: Model) => void): _MongoosePromise>; + insertMany(...docsWithCallback: Object[]): _MongoosePromise>; /** * Executes a mapReduce command. @@ -2382,7 +2401,7 @@ declare module "mongoose" { mapReduce( o: ModelMapReduceOption, Key, Value>, callback?: (err: any, res: any) => void - ): MongoosePromise; + ): _MongoosePromise; /** * Populates document references. @@ -2391,9 +2410,9 @@ declare module "mongoose" { * @param callback Optional callback, executed upon completion. Receives err and the doc(s). */ populate(docs: Object[], options: ModelPopulateOptions | ModelPopulateOptions[], - callback?: (err: any, res: Model[]) => void): MongoosePromise[]>; + callback?: (err: any, res: Model[]) => void): _MongoosePromise[]>; populate(docs: Object, options: ModelPopulateOptions | ModelPopulateOptions[], - callback?: (err: any, res: Model) => void): MongoosePromise>; + callback?: (err: any, res: Model) => void): _MongoosePromise>; /** Removes documents from the collection. */ remove(conditions: Object, callback?: (err: any) => void): Query; @@ -2425,7 +2444,7 @@ declare module "mongoose" { * Removes this document from the db. * @param fn optional callback */ - remove(fn?: (err: any, product: Model) => void): MongoosePromise>; + remove(fn?: (err: any, product: Model) => void): _MongoosePromise>; /** * Saves this document. @@ -2434,7 +2453,7 @@ declare module "mongoose" { * @param options.validateBeforeSave set to false to save without validating. * @param fn optional callback */ - save(fn?: (err: any, product: Model, numAffected: number) => void): MongoosePromise>; + save(fn?: (err: any, product: Model, numAffected: number) => void): _MongoosePromise>; /** Base Mongoose instance the model uses. */ base: typeof mongoose;