UNPKG

3.67 kBTypeScriptView Raw
1
2declare module 'mongoose' {
3 import mongodb = require('mongodb');
4 import bson = require('bson');
5
6 class NativeBuffer extends Buffer {}
7
8 namespace Types {
9 class Array<T> extends global.Array<T> {
10 /** Pops the array atomically at most one time per document `save()`. */
11 $pop(): T;
12
13 /** Atomically shifts the array at most one time per document `save()`. */
14 $shift(): T;
15
16 /** Adds values to the array if not already present. */
17 addToSet(...args: any[]): any[];
18
19 isMongooseArray: true;
20
21 /** Pushes items to the array non-atomically. */
22 nonAtomicPush(...args: any[]): number;
23
24 /** Wraps [`Array#push`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push) with proper change tracking. */
25 push(...args: any[]): number;
26
27 /**
28 * Pulls items from the array atomically. Equality is determined by casting
29 * the provided value to an embedded document and comparing using
30 * [the `Document.equals()` function.](./api/document.html#document_Document-equals)
31 */
32 pull(...args: any[]): this;
33
34 /**
35 * Alias of [pull](#mongoosearray_MongooseArray-pull)
36 */
37 remove(...args: any[]): this;
38
39 /** Sets the casted `val` at index `i` and marks the array modified. */
40 set(index: number, val: T): this;
41
42 /** Atomically shifts the array at most one time per document `save()`. */
43 shift(): T;
44
45 /** Returns a native js Array. */
46 toObject(options?: ToObjectOptions): any;
47 toObject<T>(options?: ToObjectOptions<T>): T;
48
49 /** Wraps [`Array#unshift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking. */
50 unshift(...args: any[]): number;
51 }
52
53 class Buffer extends NativeBuffer {
54 /** Sets the subtype option and marks the buffer modified. */
55 subtype(subtype: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128 | ToObjectOptions): void;
56
57 /** Converts this buffer to its Binary type representation. */
58 toObject(subtype?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128): mongodb.Binary;
59 }
60
61 class Decimal128 extends mongodb.Decimal128 { }
62
63 class DocumentArray<T> extends Types.Array<T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T> {
64 /** DocumentArray constructor */
65 constructor(values: AnyObject[]);
66
67 isMongooseDocumentArray: true;
68
69 /** Creates a subdocument casted to this schema. */
70 create(obj: any): T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T;
71
72 /** Searches array items for the first document with a matching _id. */
73 id(id: any): (T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T) | null;
74
75 push(...args: (AnyKeys<T> & AnyObject)[]): number;
76 }
77
78 class Map<V> extends global.Map<string, V> {
79 /** Converts a Mongoose map into a vanilla JavaScript map. */
80 toObject(options?: ToObjectOptions & { flattenMaps?: boolean }): any;
81 }
82
83 class ObjectId extends mongodb.ObjectId {
84 }
85
86 class Subdocument<IdType = any> extends Document<IdType> {
87 $isSingleNested: true;
88
89 /** Returns the top level document of this sub-document. */
90 ownerDocument(): Document;
91
92 /** Returns this sub-documents parent document. */
93 parent(): Document;
94
95 /** Returns this sub-documents parent document. */
96 $parent(): Document;
97 }
98
99 class ArraySubdocument<IdType = any> extends Subdocument<IdType> {
100 /** Returns this sub-documents parent array. */
101 parentArray(): Types.DocumentArray<unknown>;
102 }
103
104 class UUID extends bson.UUID {}
105 }
106}