mongoose 6.3.4 → 6.3.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.
- package/.eslintrc.json +1 -1
- package/dist/browser.umd.js +1 -1
- package/lgtm.yml +12 -0
- package/lib/cast/objectid.js +3 -2
- package/lib/connection.js +3 -2
- package/lib/document.js +37 -24
- package/lib/error/index.js +2 -2
- package/lib/helpers/clone.js +7 -1
- package/lib/helpers/common.js +3 -4
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +2 -2
- package/lib/helpers/isBsonType.js +5 -3
- package/lib/helpers/path/setDottedPath.js +14 -1
- package/lib/helpers/schematype/handleImmutable.js +2 -1
- package/lib/helpers/topology/isAtlas.js +15 -2
- package/lib/helpers/update/applyTimestampsToChildren.js +4 -0
- package/lib/helpers/update/castArrayFilters.js +3 -0
- package/lib/index.js +4 -3
- package/lib/options/SchemaTypeOptions.js +13 -0
- package/lib/query.js +4 -1
- package/lib/schema/SubdocumentPath.js +8 -1
- package/lib/schema/decimal128.js +4 -4
- package/lib/schema/documentarray.js +2 -4
- package/lib/schema/map.js +8 -0
- package/lib/schema/objectid.js +4 -3
- package/lib/schema/string.js +2 -2
- package/lib/schema.js +33 -2
- package/lib/schematype.js +1 -0
- package/lib/types/DocumentArray/methods/index.js +3 -3
- package/lib/types/array/methods/index.js +3 -3
- package/lib/types/map.js +4 -4
- package/lib/utils.js +3 -4
- package/package.json +17 -15
- package/types/aggregate.d.ts +3 -4
- package/types/callback.d.ts +8 -0
- package/types/collection.d.ts +46 -0
- package/types/connection.d.ts +91 -71
- package/types/document.d.ts +1 -1
- package/types/error.d.ts +5 -1
- package/types/helpers.d.ts +32 -0
- package/types/index.d.ts +32 -1859
- package/types/indizes.d.ts +98 -0
- package/types/middlewares.d.ts +14 -0
- package/types/models.d.ts +419 -0
- package/types/populate.d.ts +40 -0
- package/types/query.d.ts +637 -0
- package/types/schematypes.d.ts +427 -0
- package/types/session.d.ts +36 -0
- package/types/types.d.ts +102 -0
- package/types/utility.d.ts +13 -0
- package/types/validation.d.ts +32 -0
- package/.lgtm.yml +0 -3
- package/CHANGELOG.md +0 -7300
- package/History.md +0 -1
package/types/connection.d.ts
CHANGED
|
@@ -2,16 +2,36 @@ declare module 'mongoose' {
|
|
|
2
2
|
import mongodb = require('mongodb');
|
|
3
3
|
import events = require('events');
|
|
4
4
|
|
|
5
|
+
/** The Mongoose module's default connection. Equivalent to `mongoose.connections[0]`, see [`connections`](#mongoose_Mongoose-connections). */
|
|
6
|
+
const connection: Connection;
|
|
7
|
+
|
|
8
|
+
/** An array containing all connections associated with this Mongoose instance. */
|
|
9
|
+
const connections: Connection[];
|
|
10
|
+
|
|
11
|
+
/** Opens Mongoose's default connection to MongoDB, see [connections docs](https://mongoosejs.com/docs/connections.html) */
|
|
12
|
+
function connect(uri: string, options: ConnectOptions, callback: CallbackWithoutResult): void;
|
|
13
|
+
function connect(uri: string, callback: CallbackWithoutResult): void;
|
|
14
|
+
function connect(uri: string, options?: ConnectOptions): Promise<Mongoose>;
|
|
15
|
+
|
|
16
|
+
/** Creates a Connection instance. */
|
|
17
|
+
function createConnection(uri: string, options: ConnectOptions, callback: Callback<Connection>): void;
|
|
18
|
+
function createConnection(uri: string, callback: Callback<Connection>): void;
|
|
19
|
+
function createConnection(uri: string, options?: ConnectOptions): Connection;
|
|
20
|
+
function createConnection(): Connection;
|
|
21
|
+
|
|
22
|
+
function disconnect(callback: CallbackWithoutResult): void;
|
|
23
|
+
function disconnect(): Promise<void>;
|
|
24
|
+
|
|
5
25
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
26
|
+
* Connection ready state
|
|
27
|
+
*
|
|
28
|
+
* - 0 = disconnected
|
|
29
|
+
* - 1 = connected
|
|
30
|
+
* - 2 = connecting
|
|
31
|
+
* - 3 = disconnecting
|
|
32
|
+
* - 99 = uninitialized
|
|
33
|
+
*/
|
|
34
|
+
enum ConnectionStates {
|
|
15
35
|
disconnected = 0,
|
|
16
36
|
connected = 1,
|
|
17
37
|
connecting = 2,
|
|
@@ -20,7 +40,7 @@ declare module 'mongoose' {
|
|
|
20
40
|
}
|
|
21
41
|
|
|
22
42
|
/** Expose connection states for user-land */
|
|
23
|
-
|
|
43
|
+
const STATES: typeof ConnectionStates;
|
|
24
44
|
|
|
25
45
|
interface ConnectOptions extends mongodb.MongoClientOptions {
|
|
26
46
|
/** Set to false to [disable buffering](http://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection. */
|
|
@@ -37,7 +57,7 @@ declare module 'mongoose' {
|
|
|
37
57
|
autoCreate?: boolean;
|
|
38
58
|
}
|
|
39
59
|
|
|
40
|
-
class Connection extends events.EventEmitter {
|
|
60
|
+
class Connection extends events.EventEmitter implements SessionStarter {
|
|
41
61
|
/** Returns a promise that resolves when this connection successfully connects to MongoDB */
|
|
42
62
|
asPromise(): Promise<this>;
|
|
43
63
|
|
|
@@ -59,32 +79,32 @@ declare module 'mongoose' {
|
|
|
59
79
|
readonly db: mongodb.Db;
|
|
60
80
|
|
|
61
81
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
82
|
+
* Helper for `createCollection()`. Will explicitly create the given collection
|
|
83
|
+
* with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
|
|
84
|
+
* and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
|
|
85
|
+
*/
|
|
66
86
|
createCollection<T extends AnyObject = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, callback: Callback<mongodb.Collection<T>>): void;
|
|
67
87
|
createCollection<T extends AnyObject = AnyObject>(name: string, callback: Callback<mongodb.Collection<T>>): void;
|
|
68
88
|
createCollection<T extends AnyObject = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
|
|
69
89
|
|
|
70
90
|
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
* Removes the model named `name` from this connection, if it exists. You can
|
|
92
|
+
* use this function to clean up any models you created in your tests to
|
|
93
|
+
* prevent OverwriteModelErrors.
|
|
94
|
+
*/
|
|
75
95
|
deleteModel(name: string | RegExp): this;
|
|
76
96
|
|
|
77
97
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
* Helper for `dropCollection()`. Will delete the given collection, including
|
|
99
|
+
* all documents and indexes.
|
|
100
|
+
*/
|
|
81
101
|
dropCollection(collection: string, callback: CallbackWithoutResult): void;
|
|
82
102
|
dropCollection(collection: string): Promise<void>;
|
|
83
103
|
|
|
84
104
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
105
|
+
* Helper for `dropDatabase()`. Deletes the given database, including all
|
|
106
|
+
* collections, documents, and indexes.
|
|
107
|
+
*/
|
|
88
108
|
dropDatabase(callback: CallbackWithoutResult): void;
|
|
89
109
|
dropDatabase(): Promise<void>;
|
|
90
110
|
|
|
@@ -92,28 +112,28 @@ declare module 'mongoose' {
|
|
|
92
112
|
get(key: string): any;
|
|
93
113
|
|
|
94
114
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
115
|
+
* Returns the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
|
|
116
|
+
* that this connection uses to talk to MongoDB.
|
|
117
|
+
*/
|
|
98
118
|
getClient(): mongodb.MongoClient;
|
|
99
119
|
|
|
100
120
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
121
|
+
* The host name portion of the URI. If multiple hosts, such as a replica set,
|
|
122
|
+
* this will contain the first host name in the URI
|
|
123
|
+
*/
|
|
104
124
|
readonly host: string;
|
|
105
125
|
|
|
106
126
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
127
|
+
* A number identifier for this connection. Used for debugging when
|
|
128
|
+
* you have [multiple connections](/docs/connections.html#multiple_connections).
|
|
129
|
+
*/
|
|
110
130
|
readonly id: number;
|
|
111
131
|
|
|
112
132
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
133
|
+
* A [POJO](https://masteringjs.io/tutorials/fundamentals/pojo) containing
|
|
134
|
+
* a map from model names to models. Contains all models that have been
|
|
135
|
+
* added to this connection using [`Connection#model()`](/docs/api/connection.html#connection_Connection-model).
|
|
136
|
+
*/
|
|
117
137
|
readonly models: Readonly<{ [index: string]: Model<any> }>;
|
|
118
138
|
|
|
119
139
|
/** Defines or retrieves a model. */
|
|
@@ -140,9 +160,9 @@ declare module 'mongoose' {
|
|
|
140
160
|
readonly pass: string;
|
|
141
161
|
|
|
142
162
|
/**
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
* The port portion of the URI. If multiple hosts, such as a replica set,
|
|
164
|
+
* this will contain the port from the first host name in the URI.
|
|
165
|
+
*/
|
|
146
166
|
readonly port: number;
|
|
147
167
|
|
|
148
168
|
/** Declares a plugin executed on all schemas you pass to `conn.model()` */
|
|
@@ -152,51 +172,51 @@ declare module 'mongoose' {
|
|
|
152
172
|
plugins: Array<any>;
|
|
153
173
|
|
|
154
174
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
175
|
+
* Connection ready state
|
|
176
|
+
*
|
|
177
|
+
* - 0 = disconnected
|
|
178
|
+
* - 1 = connected
|
|
179
|
+
* - 2 = connecting
|
|
180
|
+
* - 3 = disconnecting
|
|
181
|
+
* - 99 = uninitialized
|
|
182
|
+
*/
|
|
163
183
|
readonly readyState: ConnectionStates;
|
|
164
184
|
|
|
165
185
|
/** Sets the value of the option `key`. */
|
|
166
186
|
set(key: string, value: any): any;
|
|
167
187
|
|
|
168
188
|
/**
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
189
|
+
* Set the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
|
|
190
|
+
* that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
|
|
191
|
+
* reuse it.
|
|
192
|
+
*/
|
|
173
193
|
setClient(client: mongodb.MongoClient): this;
|
|
174
194
|
|
|
175
195
|
/**
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
startSession(options:
|
|
181
|
-
startSession(callback: Callback<
|
|
182
|
-
startSession(options?:
|
|
196
|
+
* _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
|
|
197
|
+
* for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
|
|
198
|
+
* and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
|
|
199
|
+
*/
|
|
200
|
+
startSession(options: ClientSessionOptions | undefined | null, callback: Callback<ClientSession>): void;
|
|
201
|
+
startSession(callback: Callback<ClientSession>): void;
|
|
202
|
+
startSession(options?: ClientSessionOptions): Promise<ClientSession>;
|
|
183
203
|
|
|
184
204
|
/**
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
205
|
+
* Makes the indexes in MongoDB match the indexes defined in every model's
|
|
206
|
+
* schema. This function will drop any indexes that are not defined in
|
|
207
|
+
* the model's schema except the `_id` index, and build any indexes that
|
|
208
|
+
* are in your schema but not in MongoDB.
|
|
209
|
+
*/
|
|
190
210
|
syncIndexes(options: SyncIndexesOptions | undefined | null, callback: Callback<ConnectionSyncIndexesResult>): void;
|
|
191
211
|
syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
|
|
192
212
|
|
|
193
213
|
/**
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
transaction(fn: (session: mongodb.ClientSession) => Promise<any
|
|
214
|
+
* _Requires MongoDB >= 3.6.0._ Executes the wrapped async function
|
|
215
|
+
* in a transaction. Mongoose will commit the transaction if the
|
|
216
|
+
* async function executes successfully and attempt to retry if
|
|
217
|
+
* there was a retryable error.
|
|
218
|
+
*/
|
|
219
|
+
transaction(fn: (session: mongodb.ClientSession) => Promise<any>, options?: mongodb.TransactionOptions): Promise<void>;
|
|
200
220
|
|
|
201
221
|
/** Switches to a different database using the same connection pool. */
|
|
202
222
|
useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;
|
package/types/document.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ declare module 'mongoose' {
|
|
|
68
68
|
* automatically set `session` if you `save()` a doc that you got from a
|
|
69
69
|
* query with an associated session.
|
|
70
70
|
*/
|
|
71
|
-
$session(session?:
|
|
71
|
+
$session(session?: ClientSession | null): ClientSession | null;
|
|
72
72
|
|
|
73
73
|
/** Alias for `set()`, used internally to avoid conflicts */
|
|
74
74
|
$set(path: string, val: any, type: any, options?: any): this;
|
package/types/error.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ declare class NativeError extends global.Error { }
|
|
|
3
3
|
declare module 'mongoose' {
|
|
4
4
|
import mongodb = require('mongodb');
|
|
5
5
|
|
|
6
|
-
type
|
|
6
|
+
type CastError = Error.CastError;
|
|
7
|
+
type SyncIndexesError = Error.SyncIndexesError;
|
|
7
8
|
|
|
8
9
|
class MongooseError extends global.Error {
|
|
9
10
|
constructor(msg: string);
|
|
@@ -16,7 +17,10 @@ declare module 'mongoose' {
|
|
|
16
17
|
static Messages: any;
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
class Error extends MongooseError { }
|
|
21
|
+
|
|
19
22
|
namespace Error {
|
|
23
|
+
|
|
20
24
|
export class CastError extends MongooseError {
|
|
21
25
|
name: 'CastError';
|
|
22
26
|
stringValue: string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare 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
|
+
}
|