/
types.d.ts
104 lines (75 loc) · 3.51 KB
/
types.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
declare module 'mongoose' {
import mongodb = require('mongodb');
class NativeBuffer extends Buffer {}
namespace Types {
class Array<T> extends global.Array<T> {
/** Pops the array atomically at most one time per document `save()`. */
$pop(): T;
/** Atomically shifts the array at most one time per document `save()`. */
$shift(): T;
/** Adds values to the array if not already present. */
addToSet(...args: any[]): any[];
isMongooseArray: true;
/** Pushes items to the array non-atomically. */
nonAtomicPush(...args: any[]): number;
/** Wraps [`Array#push`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push) with proper change tracking. */
push(...args: any[]): number;
/**
* Pulls items from the array atomically. Equality is determined by casting
* the provided value to an embedded document and comparing using
* [the `Document.equals()` function.](./api.html#document_Document-equals)
*/
pull(...args: any[]): this;
/**
* Alias of [pull](#mongoosearray_MongooseArray-pull)
*/
remove(...args: any[]): this;
/** Sets the casted `val` at index `i` and marks the array modified. */
set(index: number, val: T): this;
/** Atomically shifts the array at most one time per document `save()`. */
shift(): T;
/** Returns a native js Array. */
toObject(options?: ToObjectOptions): any;
toObject<T>(options?: ToObjectOptions): T;
/** Wraps [`Array#unshift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking. */
unshift(...args: any[]): number;
}
class Buffer extends NativeBuffer {
/** Sets the subtype option and marks the buffer modified. */
subtype(subtype: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128 | ToObjectOptions): void;
/** Converts this buffer to its Binary type representation. */
toObject(subtype?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128): mongodb.Binary;
}
class Decimal128 extends mongodb.Decimal128 { }
class DocumentArray<T> extends Types.Array<T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T> {
/** DocumentArray constructor */
constructor(values: any[]);
isMongooseDocumentArray: true;
/** Creates a subdocument casted to this schema. */
create(obj: any): T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T;
/** Searches array items for the first document with a matching _id. */
id(id: any): (T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T) | null;
push(...args: (AnyKeys<T> & AnyObject)[]): number;
}
class Map<V> extends global.Map<string, V> {
/** Converts a Mongoose map into a vanilla JavaScript map. */
toObject(options?: ToObjectOptions & { flattenMaps?: boolean }): any;
}
class ObjectId extends mongodb.ObjectId {
_id: this;
}
class Subdocument<IdType = any> extends Document<IdType> {
$isSingleNested: true;
/** Returns the top level document of this sub-document. */
ownerDocument(): Document;
/** Returns this sub-documents parent document. */
parent(): Document;
/** Returns this sub-documents parent document. */
$parent(): Document;
}
class ArraySubdocument<IdType = any> extends Subdocument<IdType> {
/** Returns this sub-documents parent array. */
parentArray(): Types.DocumentArray<unknown>;
}
}
}