forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongoose-promise.d.ts
127 lines (110 loc) · 4.88 KB
/
mongoose-promise.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Type definitions for Mongoose-Promise 4.5.4
// Project: http://mongoosejs.com/
// Definitions by: simonxca <https://github.com/simonxca/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../mongoose/mongoose.d.ts" />
/// <reference path="../mpromise/mpromise.d.ts" />
/*
* http://mongoosejs.com/docs/api.html#promise-js
*
* mongoose.d.ts uses global.Promise by default. This is the MongooseJS
* mpromise implementation (which are deprecated). If you still want to
* use it, install these definitions in your project.
*/
declare module 'mongoose' {
import mpromise = require('mpromise');
type Promise<T> = MongoosePromise<T>;
/*
* mpromise definitions.
* Callback signatures are from the mPromise type definitions.
*/
class MongoosePromise<T> extends mpromise<T, any> {
/**
* Promise constructor.
* Promises are returned from executed queries.
* @param fn a function which will be called when the promise
* is resolved that accepts fn(err, ...){} as signature
* @event err Emits when the promise is rejected
* @event complete Emits when the promise is fulfilled
* @deprecated Mongoose 5.0 will use native promises by default (or bluebird, if native
* promises are not present) but still support plugging in your own ES6-compatible
* promises library. Mongoose 5.0 will not support mpromise.
*/
constructor(fn?: (err: any, arg: T) => void);
constructor(fn?: (err: any, ...args: T[]) => void);
/**
* Adds a single function as a listener to both err and complete.
* It will be executed with traditional node.js argument position when the promise is resolved.
* @deprecated Use onResolve instead.
*/
addBack(listener: (err: any, arg: T) => void): this;
addBack(listener: (err: any, ...args: T[]) => void): this;
/**
* Adds a listener to the complete (success) event.
* @deprecated Adds a listener to the complete (success) event.
*/
addCallback(listener: (arg: T) => void): this;
addCallback(listener: (...args: T[]) => void): this;
/**
* Adds a listener to the err (rejected) event.
* @deprecated Use onReject instead.
*/
addErrback(listener: (err: any) => void): this;
/** ES6-style .catch() shorthand */
catch<TRes>(onReject?: (err: any) => void | TRes | PromiseLike<TRes>): MongoosePromise<TRes>;
/**
* Signifies that this promise was the last in a chain of then()s: if a handler passed
* to the call to then which produced this promise throws, the exception will go uncaught.
*/
end(): void;
/**
* Rejects this promise with err.
* If the promise has already been fulfilled or rejected, not action is taken.
* Differs from #reject by first casting err to an Error if it is not instanceof Error.
*/
error(err: any): this;
/**
* Adds listener to the event.
* If event is either the success or failure event and the event has already been emitted,
* thelistener is called immediately and passed the results of the original emitted event.
*/
on(event: string, listener: Function): this;
/**
* Rejects this promise with reason.
* If the promise has already been fulfilled or rejected, not action is taken.
*/
reject(reason: Object | string | Error): this;
/**
* Resolves this promise to a rejected state if err is passed or a fulfilled state if no err is passed.
* If the promise has already been fulfilled or rejected, not action is taken.
* err will be cast to an Error if not already instanceof Error.
* NOTE: overrides mpromise#resolve to provide error casting.
* @param err error or null
* @param val value to fulfill the promise with
*/
resolve(err?: any, val?: Object): this;
/**
* Creates a new promise and returns it. If onFulfill or onReject are passed, they are added as
* SUCCESS/ERROR callbacks to this promise after the nextTick.
* Conforms to promises/A+ specification.
*/
then<TRes>(onFulFill: (arg: T) => void | TRes | PromiseLike<TRes>,
onReject?: (err: any) => void | TRes | PromiseLike<TRes>): MongoosePromise<TRes>;
then<TRes>(onFulfill: (...args: T[]) => void | TRes | PromiseLike<TRes>,
onReject?: (err: any) => void | TRes | PromiseLike<TRes>): MongoosePromise<TRes>;
/**
* Fulfills this promise with passed arguments. Alias of mpromise#fulfill.
* @deprecated Use fulfill instead.
*/
complete(args: T): this;
complete(...args: T[]): this;
/** Fulfills this promise with passed arguments. */
fulfill(...args: T[]): this;
fulfill(arg: T): this;
/** ES6-style promise constructor wrapper around mpromise. */
static ES6<TRes>(resolver: (
complete: (...args: TRes[]) => void | TRes | PromiseLike<TRes>,
error: (e: any) => void | TRes | PromiseLike<TRes>
) => void): MongoosePromise<TRes>;
}
}