UNPKG

1.22 kBTypeScriptView Raw
1declare module 'mongoose' {
2 import mongodb = require('mongodb');
3
4 /**
5 * Mongoose uses this function to get the current time when setting
6 * [timestamps](/docs/guide.html#timestamps). You may stub out this function
7 * using a tool like [Sinon](https://www.npmjs.com/package/sinon) for testing.
8 */
9 function now(): NativeDate;
10
11 /**
12 * Tells `sanitizeFilter()` to skip the given object when filtering out potential query selector injection attacks.
13 * Use this method when you have a known query selector that you want to use.
14 */
15 function trusted<T>(obj: T): T;
16
17 /**
18 * Returns true if the given value is a Mongoose ObjectId (using `instanceof`) or if the
19 * given value is a 24 character hex string, which is the most commonly used string representation
20 * of an ObjectId.
21 */
22 function isObjectIdOrHexString(v: mongodb.ObjectId): true;
23 function isObjectIdOrHexString(v: mongodb.ObjectId | string): boolean;
24 function isObjectIdOrHexString(v: any): false;
25
26 /**
27 * Returns true if Mongoose can cast the given value to an ObjectId, or
28 * false otherwise.
29 */
30 function isValidObjectId(v: mongodb.ObjectId | Types.ObjectId): true;
31 function isValidObjectId(v: any): boolean;
32}