make MongoosePromise errors occur only in one place

This commit is contained in:
Simon
2016-07-21 11:02:26 -04:00
parent e3865142f9
commit 76eba7e5e4
+50 -31
View File
@@ -256,7 +256,7 @@ declare module "mongoose" {
type model<T> = _mongoose.Model<T>;
type Model<T> = _mongoose.ModelConstructor<T>;
type Mongoose = typeof mongoose;
interface Promise<T> extends MongoosePromise<T> {}
interface Promise<T> extends _mongoose._MongoosePromise<T> {}
interface Query<T> extends _mongoose.Query<T> {}
interface QueryCursor<T> extends _mongoose.QueryCursor<T> {}
interface QueryStream extends _mongoose.QueryStream {}
@@ -305,13 +305,13 @@ declare module "mongoose" {
* and .disconnect().then() are viable.
*/
static then<TRes>(onFulfill?: () => void | TRes | PromiseLike<TRes>,
onRejected?: (err: mongodb.MongoError) => void | TRes | PromiseLike<TRes>): MongoosePromise<TRes>;
onRejected?: (err: mongodb.MongoError) => void | TRes | PromiseLike<TRes>): _MongoosePromise<TRes>;
/**
* Ability to use mongoose object as a pseudo-promise so .connect().then()
* and .disconnect().then() are viable.
*/
static catch<TRes>(onRejected?: (err: mongodb.MongoError) => void | TRes | PromiseLike<TRes>): MongoosePromise<TRes>;
static catch<TRes>(onRejected?: (err: mongodb.MongoError) => void | TRes | PromiseLike<TRes>): _MongoosePromise<TRes>;
}
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<void>;
close(callback?: (err: any) => void): _MongoosePromise<void>;
/**
* Retrieves a collection, creating it if not cached.
@@ -600,7 +600,7 @@ declare module "mongoose" {
constructor(query: Query<T>, options: Object): QueryCursor<T>;
/** Marks this cursor as closed. Will stop streaming and subsequent calls to next() will error. */
close(callback?: (error: any, result: any) => void): MongoosePromise<any>;
close(callback?: (error: any, result: any) => void): _MongoosePromise<any>;
/**
* 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<T>) => any, callback?: (err: any) => void): MongoosePromise<Model<T>>;
eachAsync(fn: (doc: Model<T>) => any, callback?: (err: any) => void): _MongoosePromise<Model<T>>;
/**
* Get the next document from this cursor. Will return null when there are
* no documents left.
*/
next(callback?: (err: any) => void): MongoosePromise<any>;
next(callback?: (err: any) => void): _MongoosePromise<any>;
}
/*
@@ -871,7 +871,7 @@ declare module "mongoose" {
* Useful for ES2015 integration.
* @returns promise that resolves to the document when population is done
*/
execPopulate(): MongoosePromise<this>;
execPopulate(): _MongoosePromise<this>;
/**
* 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<void>;
validate(optional: Object, callback?: (err: any) => void): MongoosePromise<void>;
validate(callback?: (err: any) => void): _MongoosePromise<void>;
validate(optional: Object, callback?: (err: any) => void): _MongoosePromise<void>;
/**
* 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<TRes>(reject?: (err: any) => void | TRes | PromiseLike<TRes>): MongoosePromise<TRes>;
catch<TRes>(reject?: (err: any) => void | TRes | PromiseLike<TRes>): _MongoosePromise<TRes>;
/**
* 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<T>;
exec(operation: string | Function, callback?: (err: any, res: T) => void): MongoosePromise<T>;
exec(callback?: (err: any, res: T) => void): _MongoosePromise<T>;
exec(operation: string | Function, callback?: (err: any, res: T) => void): _MongoosePromise<T>;
/** Specifies an $exists condition */
exists(val?: boolean): this;
@@ -1655,7 +1655,7 @@ declare module "mongoose" {
/** Executes this query and returns a promise */
then<TRes>(resolve?: (res: T) => void | TRes | PromiseLike<TRes>,
reject?: (err: any) => void | TRes | PromiseLike<TRes>): MongoosePromise<TRes>;
reject?: (err: any) => void | TRes | PromiseLike<TRes>): _MongoosePromise<TRes>;
/**
* 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<T> | any;
exec(callback?: (err: any, result: T) => void): _MongoosePromise<T> | any;
/** Execute the aggregation with explain */
explain(callback?: (err: any, result: T) => void): MongoosePromise<T>;
explain(callback?: (err: any, result: T) => void): _MongoosePromise<T>;
/**
* Appends a new custom $group operator to this aggregate pipeline.
@@ -2076,7 +2076,7 @@ declare module "mongoose" {
/** Provides promise for aggregate. */
then<TRes>(resolve?: (val: T) => void | TRes | PromiseLike<TRes>,
reject?: (err: any) => void | TRes | PromiseLike<TRes>): MongoosePromise<TRes>
reject?: (err: any) => void | TRes | PromiseLike<TRes>): _MongoosePromise<TRes>
/**
* 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<T> = Promise<T>;
*
* 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<T> = Q.Promise<T>;
*/
type _MongoosePromise<T> = MongoosePromise<T>;
/*
* 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<Object[]>;
aggregate(...aggregationsWithCallback: Object[]): MongoosePromise<Object[]>;
aggregate(...aggregationsWithCallback: Object[]): _MongoosePromise<Object[]>;
/** Counts number of matching documents in a database collection. */
count(conditions: Object, callback?: (err: any, count: number) => void): Query<number>;
@@ -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<T>[]) => void): MongoosePromise<Model<T>[]>;
create(...docs: Object[]): MongoosePromise<Model<T>>;
create(...docsWithCallback: Object[]): MongoosePromise<Model<T>>;
create(docs: any[], callback?: (err: any, res: Model<T>[]) => void): _MongoosePromise<Model<T>[]>;
create(...docs: Object[]): _MongoosePromise<Model<T>>;
create(...docsWithCallback: Object[]): _MongoosePromise<Model<T>>;
/**
* 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<void>;
ensureIndexes(options: Object, callback?: (err: any) => void): MongoosePromise<void>;
ensureIndexes(callback?: (err: any) => void): _MongoosePromise<void>;
ensureIndexes(options: Object, callback?: (err: any) => void): _MongoosePromise<void>;
/**
* 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<T>[]) => void): MongoosePromise<Model<T>[]>;
insertMany(doc: any, callback?: (error: any, doc: Model<T>) => void): MongoosePromise<Model<T>>;
insertMany(...docsWithCallback: Object[]): MongoosePromise<Model<T>>;
insertMany(docs: any[], callback?: (error: any, docs: Model<T>[]) => void): _MongoosePromise<Model<T>[]>;
insertMany(doc: any, callback?: (error: any, doc: Model<T>) => void): _MongoosePromise<Model<T>>;
insertMany(...docsWithCallback: Object[]): _MongoosePromise<Model<T>>;
/**
* Executes a mapReduce command.
@@ -2382,7 +2401,7 @@ declare module "mongoose" {
mapReduce<Key, Value>(
o: ModelMapReduceOption<Model<T>, Key, Value>,
callback?: (err: any, res: any) => void
): MongoosePromise<any>;
): _MongoosePromise<any>;
/**
* 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<T>[]) => void): MongoosePromise<Model<T>[]>;
callback?: (err: any, res: Model<T>[]) => void): _MongoosePromise<Model<T>[]>;
populate<T>(docs: Object, options: ModelPopulateOptions | ModelPopulateOptions[],
callback?: (err: any, res: Model<T>) => void): MongoosePromise<Model<T>>;
callback?: (err: any, res: Model<T>) => void): _MongoosePromise<Model<T>>;
/** Removes documents from the collection. */
remove(conditions: Object, callback?: (err: any) => void): Query<void>;
@@ -2425,7 +2444,7 @@ declare module "mongoose" {
* Removes this document from the db.
* @param fn optional callback
*/
remove(fn?: (err: any, product: Model<T>) => void): MongoosePromise<Model<T>>;
remove(fn?: (err: any, product: Model<T>) => void): _MongoosePromise<Model<T>>;
/**
* 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<T>, numAffected: number) => void): MongoosePromise<Model<T>>;
save(fn?: (err: any, product: Model<T>, numAffected: number) => void): _MongoosePromise<Model<T>>;
/** Base Mongoose instance the model uses. */
base: typeof mongoose;