mongoose 6.2.4 → 6.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ import stream = require('stream');
2
+
3
+ declare module 'mongoose' {
4
+ type CursorFlag = 'tailable' | 'oplogReplay' | 'noCursorTimeout' | 'awaitData' | 'partial';
5
+
6
+ class Cursor<DocType = any, Options = never> extends stream.Readable {
7
+ [Symbol.asyncIterator](): AsyncIterableIterator<DocType>;
8
+
9
+ /**
10
+ * Adds a [cursor flag](http://mongodb.github.io/node-mongodb-native/2.2/api/Cursor.html#addCursorFlag).
11
+ * Useful for setting the `noCursorTimeout` and `tailable` flags.
12
+ */
13
+ addCursorFlag(flag: CursorFlag, value: boolean): this;
14
+
15
+ /**
16
+ * Marks this cursor as closed. Will stop streaming and subsequent calls to
17
+ * `next()` will error.
18
+ */
19
+ close(callback: CallbackWithoutResult): void;
20
+ close(): Promise<void>;
21
+
22
+ /**
23
+ * Execute `fn` for every document(s) in the cursor. If batchSize is provided
24
+ * `fn` will be executed for each batch of documents. If `fn` returns a promise,
25
+ * will wait for the promise to resolve before iterating on to the next one.
26
+ * Returns a promise that resolves when done.
27
+ */
28
+ eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }, callback: CallbackWithoutResult): void;
29
+ eachAsync(fn: (doc: DocType) => any, options: { parallel?: number }, callback: CallbackWithoutResult): void;
30
+ eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }): Promise<void>;
31
+ eachAsync(fn: (doc: DocType) => any, options?: { parallel?: number }): Promise<void>;
32
+
33
+ /**
34
+ * Registers a transform function which subsequently maps documents retrieved
35
+ * via the streams interface or `.next()`
36
+ */
37
+ map<ResultType>(fn: (res: DocType) => ResultType): Cursor<ResultType, Options>;
38
+
39
+ /**
40
+ * Get the next document from this cursor. Will return `null` when there are
41
+ * no documents left.
42
+ */
43
+ next(callback: Callback<DocType | null>): void;
44
+ next(): Promise<DocType>;
45
+
46
+ options: Options;
47
+ }
48
+ }
@@ -0,0 +1,244 @@
1
+ import mongodb = require('mongodb');
2
+
3
+ declare module 'mongoose' {
4
+
5
+ /** A list of paths to skip. If set, Mongoose will validate every modified path that is not in this list. */
6
+ type pathsToSkip = string[] | string;
7
+
8
+ class Document<T = any, TQueryHelpers = any, DocType = any> {
9
+ constructor(doc?: any);
10
+
11
+ /** This documents _id. */
12
+ _id?: T;
13
+
14
+ /** This documents __v. */
15
+ __v?: any;
16
+
17
+ /* Get all subdocs (by bfs) */
18
+ $getAllSubdocs(): Document[];
19
+
20
+ /** Don't run validation on this path or persist changes to this path. */
21
+ $ignore(path: string): void;
22
+
23
+ /** Checks if a path is set to its default. */
24
+ $isDefault(path: string): boolean;
25
+
26
+ /** Getter/setter, determines whether the document was removed or not. */
27
+ $isDeleted(val?: boolean): boolean;
28
+
29
+ /** Returns an array of all populated documents associated with the query */
30
+ $getPopulatedDocs(): Document[];
31
+
32
+ /**
33
+ * Returns true if the given path is nullish or only contains empty objects.
34
+ * Useful for determining whether this subdoc will get stripped out by the
35
+ * [minimize option](/docs/guide.html#minimize).
36
+ */
37
+ $isEmpty(path: string): boolean;
38
+
39
+ /** Checks if a path is invalid */
40
+ $isValid(path: string): boolean;
41
+
42
+ /**
43
+ * Empty object that you can use for storing properties on the document. This
44
+ * is handy for passing data to middleware without conflicting with Mongoose
45
+ * internals.
46
+ */
47
+ $locals: Record<string, unknown>;
48
+
49
+ /** Marks a path as valid, removing existing validation errors. */
50
+ $markValid(path: string): void;
51
+
52
+ /**
53
+ * A string containing the current operation that Mongoose is executing
54
+ * on this document. Can be `null`, `'save'`, `'validate'`, or `'remove'`.
55
+ */
56
+ $op: 'save' | 'validate' | 'remove' | null;
57
+
58
+ /**
59
+ * Getter/setter around the session associated with this document. Used to
60
+ * automatically set `session` if you `save()` a doc that you got from a
61
+ * query with an associated session.
62
+ */
63
+ $session(session?: mongodb.ClientSession | null): mongodb.ClientSession | null;
64
+
65
+ /** Alias for `set()`, used internally to avoid conflicts */
66
+ $set(path: string, val: any, type: any, options?: any): this;
67
+ $set(path: string, val: any, options?: any): this;
68
+ $set(value: any): this;
69
+
70
+ /** Set this property to add additional query filters when Mongoose saves this document and `isNew` is false. */
71
+ $where: Record<string, unknown>;
72
+
73
+ /** If this is a discriminator model, `baseModelName` is the name of the base model. */
74
+ baseModelName?: string;
75
+
76
+ /** Collection the model uses. */
77
+ collection: Collection;
78
+
79
+ /** Connection the model uses. */
80
+ db: Connection;
81
+
82
+ /** Removes this document from the db. */
83
+ delete(options: QueryOptions, callback: Callback): void;
84
+ delete(callback: Callback): void;
85
+ delete(options?: QueryOptions): QueryWithHelpers<any, this, TQueryHelpers>;
86
+
87
+ /** Removes this document from the db. */
88
+ deleteOne(options: QueryOptions, callback: Callback): void;
89
+ deleteOne(callback: Callback): void;
90
+ deleteOne(options?: QueryOptions): QueryWithHelpers<any, this, TQueryHelpers>;
91
+
92
+ /**
93
+ * Takes a populated field and returns it to its unpopulated state. If called with
94
+ * no arguments, then all populated fields are returned to their unpopulated state.
95
+ */
96
+ depopulate(path?: string | string[]): this;
97
+
98
+ /**
99
+ * Returns the list of paths that have been directly modified. A direct
100
+ * modified path is a path that you explicitly set, whether via `doc.foo = 'bar'`,
101
+ * `Object.assign(doc, { foo: 'bar' })`, or `doc.set('foo', 'bar')`.
102
+ */
103
+ directModifiedPaths(): Array<string>;
104
+
105
+ /**
106
+ * Returns true if this document is equal to another document.
107
+ *
108
+ * Documents are considered equal when they have matching `_id`s, unless neither
109
+ * document has an `_id`, in which case this function falls back to using
110
+ * `deepEqual()`.
111
+ */
112
+ equals(doc: Document<T>): boolean;
113
+
114
+ /** Returns the current validation errors. */
115
+ errors?: Error.ValidationError;
116
+
117
+ /** Returns the value of a path. */
118
+ get(path: string, type?: any, options?: any): any;
119
+
120
+ /**
121
+ * Returns the changes that happened to the document
122
+ * in the format that will be sent to MongoDB.
123
+ */
124
+ getChanges(): UpdateQuery<this>;
125
+
126
+ /** The string version of this documents _id. */
127
+ id?: any;
128
+
129
+ /** Signal that we desire an increment of this documents version. */
130
+ increment(): this;
131
+
132
+ /**
133
+ * Initializes the document without setters or marking anything modified.
134
+ * Called internally after a document is returned from mongodb. Normally,
135
+ * you do **not** need to call this function on your own.
136
+ */
137
+ init(obj: AnyObject, opts?: AnyObject, callback?: Callback<this>): this;
138
+
139
+ /** Marks a path as invalid, causing validation to fail. */
140
+ invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null;
141
+
142
+ /** Returns true if `path` was directly set and modified, else false. */
143
+ isDirectModified(path: string): boolean;
144
+
145
+ /** Checks if `path` was explicitly selected. If no projection, always returns true. */
146
+ isDirectSelected(path: string): boolean;
147
+
148
+ /** Checks if `path` is in the `init` state, that is, it was set by `Document#init()` and not modified since. */
149
+ isInit(path: string): boolean;
150
+
151
+ /**
152
+ * Returns true if any of the given paths are modified, else false. If no arguments, returns `true` if any path
153
+ * in this document is modified.
154
+ */
155
+ isModified(path?: string | Array<string>): boolean;
156
+
157
+ /** Boolean flag specifying if the document is new. */
158
+ isNew: boolean;
159
+
160
+ /** Checks if `path` was selected in the source query which initialized this document. */
161
+ isSelected(path: string): boolean;
162
+
163
+ /** Marks the path as having pending changes to write to the db. */
164
+ markModified(path: string, scope?: any): void;
165
+
166
+ /** Returns the list of paths that have been modified. */
167
+ modifiedPaths(options?: { includeChildren?: boolean }): Array<string>;
168
+
169
+ /** The name of the model */
170
+ modelName: string;
171
+
172
+ /**
173
+ * Overwrite all values in this document with the values of `obj`, except
174
+ * for immutable properties. Behaves similarly to `set()`, except for it
175
+ * unsets all properties that aren't in `obj`.
176
+ */
177
+ overwrite(obj: AnyObject): this;
178
+
179
+ /**
180
+ * If this document is a subdocument or populated document, returns the
181
+ * document's parent. Returns undefined otherwise.
182
+ */
183
+ $parent(): Document | undefined;
184
+
185
+ /** Populates document references. */
186
+ populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<this & Paths>): void;
187
+ populate<Paths = {}>(path: string, names: string, callback: Callback<this & Paths>): void;
188
+ populate<Paths = {}>(path: string, names: string): Promise<this & Paths>;
189
+ populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<this & Paths>;
190
+
191
+ /** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */
192
+ populated(path: string): any;
193
+
194
+ /** Removes this document from the db. */
195
+ remove(options: QueryOptions, callback: Callback): void;
196
+ remove(callback: Callback): void;
197
+ remove(options?: QueryOptions): Promise<this>;
198
+
199
+ /** Sends a replaceOne command with this document `_id` as the query selector. */
200
+ replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
201
+
202
+ /** Saves this document by inserting a new document into the database if [document.isNew](/docs/api.html#document_Document-isNew) is `true`, or sends an [updateOne](/docs/api.html#document_Document-updateOne) operation with just the modified paths if `isNew` is `false`. */
203
+ save(options: SaveOptions, callback: Callback<this>): void;
204
+ save(callback: Callback<this>): void;
205
+ save(options?: SaveOptions): Promise<this>;
206
+
207
+ /** The document's schema. */
208
+ schema: Schema;
209
+
210
+ /** Sets the value of a path, or many paths. */
211
+ set(path: string, val: any, type: any, options?: any): this;
212
+ set(path: string, val: any, options?: any): this;
213
+ set(value: any): this;
214
+
215
+ /** The return value of this method is used in calls to JSON.stringify(doc). */
216
+ toJSON(options: ToObjectOptions & { flattenMaps: false }): LeanDocument<this>;
217
+ toJSON(options?: ToObjectOptions): FlattenMaps<LeanDocument<this>>;
218
+ toJSON<T = FlattenMaps<DocType>>(options?: ToObjectOptions): T;
219
+
220
+ /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */
221
+ toObject(options?: ToObjectOptions): LeanDocument<this>;
222
+ toObject<T = DocType>(options?: ToObjectOptions): T;
223
+
224
+ /** Clears the modified state on the specified path. */
225
+ unmarkModified(path: string): void;
226
+
227
+ /** Sends an update command with this document `_id` as the query selector. */
228
+ update(update?: UpdateQuery<this> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
229
+
230
+ /** Sends an updateOne command with this document `_id` as the query selector. */
231
+ updateOne(update?: UpdateQuery<this> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
232
+
233
+ /** Executes registered validation rules for this document. */
234
+ validate(pathsToValidate: pathsToValidate, options: AnyObject, callback: CallbackWithoutResult): void;
235
+ validate(pathsToValidate: pathsToValidate, callback: CallbackWithoutResult): void;
236
+ validate(callback: CallbackWithoutResult): void;
237
+ validate(pathsToValidate?: pathsToValidate, options?: AnyObject): Promise<void>;
238
+ validate(options: { pathsToSkip?: pathsToSkip }): Promise<void>;
239
+
240
+ /** Executes registered validation rules (skipping asynchronous validators) for this document. */
241
+ validateSync(options: { pathsToSkip?: pathsToSkip, [k: string]: any }): Error.ValidationError | null;
242
+ validateSync(pathsToValidate?: Array<string>, options?: AnyObject): Error.ValidationError | null;
243
+ }
244
+ }
File without changes