mongoose 6.2.2 → 6.2.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.2.2",
4
+ "version": "6.2.5",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -24,39 +24,37 @@
24
24
  "mongodb": "4.3.1",
25
25
  "mpath": "0.8.4",
26
26
  "mquery": "4.0.2",
27
- "ms": "2.1.2",
28
- "sift": "13.5.2"
27
+ "ms": "2.1.3",
28
+ "sift": "16.0.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@babel/core": "7.10.5",
32
- "@babel/preset-env": "7.10.4",
33
- "@typescript-eslint/eslint-plugin": "5.8.0",
34
- "@typescript-eslint/parser": "5.8.0",
31
+ "@babel/core": "7.17.5",
32
+ "@babel/preset-env": "7.16.11",
33
+ "@typescript-eslint/eslint-plugin": "5.12.0",
34
+ "@typescript-eslint/parser": "5.12.0",
35
35
  "acquit": "1.x",
36
- "acquit-ignore": "0.1.x",
36
+ "acquit-ignore": "0.2.x",
37
37
  "acquit-require": "0.1.x",
38
- "babel-loader": "8.1.0",
38
+ "babel-loader": "8.2.3",
39
39
  "benchmark": "2.1.4",
40
40
  "bluebird": "3.7.2",
41
- "cheerio": "1.0.0-rc.5",
41
+ "cheerio": "1.0.0-rc.10",
42
42
  "dox": "0.3.1",
43
- "eslint": "8.5.0",
44
- "eslint-plugin-mocha-no-only": "1.1.0",
43
+ "eslint": "8.9.0",
44
+ "eslint-plugin-mocha-no-only": "1.1.1",
45
45
  "highlight.js": "9.18.3",
46
46
  "lodash.isequal": "4.5.0",
47
47
  "lodash.isequalwith": "4.4.0",
48
48
  "marked": "2.1.3",
49
- "mkdirp": "0.5.5",
50
- "mocha": "9.2.0",
49
+ "mocha": "9.2.1",
51
50
  "moment": "2.x",
52
- "mongodb-memory-server": "^8.2.0",
51
+ "mongodb-memory-server": "^8.3.0",
53
52
  "nyc": "^15.1.0",
54
53
  "pug": "3.0.2",
55
54
  "q": "1.5.1",
56
- "rimraf": "2.6.3",
57
55
  "serve-handler": "6.1.3",
58
56
  "tsd": "0.19.1",
59
- "typescript": "4.5.3",
57
+ "typescript": "4.5.5",
60
58
  "uuid": "8.3.2",
61
59
  "webpack": "4.44.1"
62
60
  },
@@ -118,4 +116,4 @@
118
116
  "target": "ES2017"
119
117
  }
120
118
  }
121
- }
119
+ }
@@ -0,0 +1,212 @@
1
+ import mongodb = require('mongodb');
2
+ import events = require('events');
3
+
4
+ declare module 'mongoose' {
5
+
6
+ /**
7
+ * Connection ready state
8
+ *
9
+ * - 0 = disconnected
10
+ * - 1 = connected
11
+ * - 2 = connecting
12
+ * - 3 = disconnecting
13
+ * - 99 = uninitialized
14
+ */
15
+ export enum ConnectionStates {
16
+ disconnected = 0,
17
+ connected = 1,
18
+ connecting = 2,
19
+ disconnecting = 3,
20
+ uninitialized = 99,
21
+ }
22
+
23
+ /** Expose connection states for user-land */
24
+ export const STATES: typeof ConnectionStates;
25
+
26
+ interface ConnectOptions extends mongodb.MongoClientOptions {
27
+ /** Set to false to [disable buffering](http://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection. */
28
+ bufferCommands?: boolean;
29
+ /** The name of the database you want to use. If not provided, Mongoose uses the database name from connection string. */
30
+ dbName?: string;
31
+ /** username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility. */
32
+ user?: string;
33
+ /** password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility. */
34
+ pass?: string;
35
+ /** Set to false to disable automatic index creation for all models associated with this connection. */
36
+ autoIndex?: boolean;
37
+ /** Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection. */
38
+ autoCreate?: boolean;
39
+ }
40
+
41
+ class Connection extends events.EventEmitter {
42
+ /** Returns a promise that resolves when this connection successfully connects to MongoDB */
43
+ asPromise(): Promise<this>;
44
+
45
+ /** Closes the connection */
46
+ close(force: boolean, callback: CallbackWithoutResult): void;
47
+ close(callback: CallbackWithoutResult): void;
48
+ close(force?: boolean): Promise<void>;
49
+
50
+ /** Retrieves a collection, creating it if not cached. */
51
+ collection<T extends AnyObject = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Collection<T>;
52
+
53
+ /** A hash of the collections associated with this connection */
54
+ readonly collections: { [index: string]: Collection };
55
+
56
+ /** A hash of the global options that are associated with this connection */
57
+ readonly config: any;
58
+
59
+ /** The mongodb.Db instance, set when the connection is opened */
60
+ readonly db: mongodb.Db;
61
+
62
+ /**
63
+ * Helper for `createCollection()`. Will explicitly create the given collection
64
+ * with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
65
+ * and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
66
+ */
67
+ createCollection<T extends AnyObject = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, callback: Callback<mongodb.Collection<T>>): void;
68
+ createCollection<T extends AnyObject = AnyObject>(name: string, callback: Callback<mongodb.Collection<T>>): void;
69
+ createCollection<T extends AnyObject = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
70
+
71
+ /**
72
+ * Removes the model named `name` from this connection, if it exists. You can
73
+ * use this function to clean up any models you created in your tests to
74
+ * prevent OverwriteModelErrors.
75
+ */
76
+ deleteModel(name: string): this;
77
+
78
+ /**
79
+ * Helper for `dropCollection()`. Will delete the given collection, including
80
+ * all documents and indexes.
81
+ */
82
+ dropCollection(collection: string, callback: CallbackWithoutResult): void;
83
+ dropCollection(collection: string): Promise<void>;
84
+
85
+ /**
86
+ * Helper for `dropDatabase()`. Deletes the given database, including all
87
+ * collections, documents, and indexes.
88
+ */
89
+ dropDatabase(callback: CallbackWithoutResult): void;
90
+ dropDatabase(): Promise<void>;
91
+
92
+ /** Gets the value of the option `key`. */
93
+ get(key: string): any;
94
+
95
+ /**
96
+ * Returns the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
97
+ * that this connection uses to talk to MongoDB.
98
+ */
99
+ getClient(): mongodb.MongoClient;
100
+
101
+ /**
102
+ * The host name portion of the URI. If multiple hosts, such as a replica set,
103
+ * this will contain the first host name in the URI
104
+ */
105
+ readonly host: string;
106
+
107
+ /**
108
+ * A number identifier for this connection. Used for debugging when
109
+ * you have [multiple connections](/docs/connections.html#multiple_connections).
110
+ */
111
+ readonly id: number;
112
+
113
+ /**
114
+ * A [POJO](https://masteringjs.io/tutorials/fundamentals/pojo) containing
115
+ * a map from model names to models. Contains all models that have been
116
+ * added to this connection using [`Connection#model()`](/docs/api/connection.html#connection_Connection-model).
117
+ */
118
+ readonly models: Readonly<{ [index: string]: Model<any> }>;
119
+
120
+ /** Defines or retrieves a model. */
121
+ model<T, U, TQueryHelpers = {}>(
122
+ name: string,
123
+ schema?: Schema<T, U, TQueryHelpers>,
124
+ collection?: string,
125
+ options?: CompileModelOptions
126
+ ): U;
127
+ model<T>(name: string, schema?: Schema<T>, collection?: string, options?: CompileModelOptions): Model<T>;
128
+
129
+ /** Returns an array of model names created on this connection. */
130
+ modelNames(): Array<string>;
131
+
132
+ /** The name of the database this connection points to. */
133
+ readonly name: string;
134
+
135
+ /** Opens the connection with a URI using `MongoClient.connect()`. */
136
+ openUri(uri: string, options: ConnectOptions, callback: Callback<Connection>): Connection;
137
+ openUri(uri: string, callback: Callback<Connection>): Connection;
138
+ openUri(uri: string, options?: ConnectOptions): Promise<Connection>;
139
+
140
+ /** The password specified in the URI */
141
+ readonly pass: string;
142
+
143
+ /**
144
+ * The port portion of the URI. If multiple hosts, such as a replica set,
145
+ * this will contain the port from the first host name in the URI.
146
+ */
147
+ readonly port: number;
148
+
149
+ /** Declares a plugin executed on all schemas you pass to `conn.model()` */
150
+ plugin<S extends Schema = Schema, O = AnyObject>(fn: (schema: S, opts?: any) => void, opts?: O): Connection;
151
+
152
+ /** The plugins that will be applied to all models created on this connection. */
153
+ plugins: Array<any>;
154
+
155
+ /**
156
+ * Connection ready state
157
+ *
158
+ * - 0 = disconnected
159
+ * - 1 = connected
160
+ * - 2 = connecting
161
+ * - 3 = disconnecting
162
+ * - 99 = uninitialized
163
+ */
164
+ readonly readyState: ConnectionStates;
165
+
166
+ /** Sets the value of the option `key`. */
167
+ set(key: string, value: any): any;
168
+
169
+ /**
170
+ * Set the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
171
+ * that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
172
+ * reuse it.
173
+ */
174
+ setClient(client: mongodb.MongoClient): this;
175
+
176
+ /**
177
+ * _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
178
+ * for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
179
+ * and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
180
+ */
181
+ startSession(options: mongodb.ClientSessionOptions | undefined | null, callback: Callback<mongodb.ClientSession>): void;
182
+ startSession(callback: Callback<mongodb.ClientSession>): void;
183
+ startSession(options?: mongodb.ClientSessionOptions): Promise<mongodb.ClientSession>;
184
+
185
+ /**
186
+ * Makes the indexes in MongoDB match the indexes defined in every model's
187
+ * schema. This function will drop any indexes that are not defined in
188
+ * the model's schema except the `_id` index, and build any indexes that
189
+ * are in your schema but not in MongoDB.
190
+ */
191
+ syncIndexes(options: SyncIndexesOptions | undefined | null, callback: Callback<ConnectionSyncIndexesResult>): void;
192
+ syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
193
+
194
+ /**
195
+ * _Requires MongoDB >= 3.6.0._ Executes the wrapped async function
196
+ * in a transaction. Mongoose will commit the transaction if the
197
+ * async function executes successfully and attempt to retry if
198
+ * there was a retryable error.
199
+ */
200
+ transaction<U = any>(fn: (session: mongodb.ClientSession) => Promise<U>): Promise<U>;
201
+
202
+ /** Switches to a different database using the same connection pool. */
203
+ useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;
204
+
205
+ /** The username specified in the URI */
206
+ readonly user: string;
207
+
208
+ /** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model.watch). */
209
+ watch<ResultType = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
210
+ }
211
+
212
+ }
@@ -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,129 @@
1
+ import mongodb = require('mongodb');
2
+
3
+ declare module 'mongoose' {
4
+
5
+ class NativeError extends global.Error { }
6
+ type CallbackError = NativeError | null;
7
+
8
+ class MongooseError extends global.Error {
9
+ constructor(msg: string);
10
+
11
+ /** The type of error. "MongooseError" for generic errors. */
12
+ name: string;
13
+
14
+ static messages: any;
15
+
16
+ static Messages: any;
17
+ }
18
+
19
+ namespace Error {
20
+ export class CastError extends MongooseError {
21
+ name: 'CastError';
22
+ stringValue: string;
23
+ kind: string;
24
+ value: any;
25
+ path: string;
26
+ reason?: NativeError | null;
27
+ model?: any;
28
+
29
+ constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
30
+ }
31
+ export class SyncIndexesError extends MongooseError {
32
+ name: 'SyncIndexesError';
33
+ errors?: Record<string, mongodb.MongoServerError>;
34
+
35
+ constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
36
+ }
37
+
38
+ export class DisconnectedError extends MongooseError {
39
+ name: 'DisconnectedError';
40
+ }
41
+
42
+ export class DivergentArrayError extends MongooseError {
43
+ name: 'DivergentArrayError';
44
+ }
45
+
46
+ export class MissingSchemaError extends MongooseError {
47
+ name: 'MissingSchemaError';
48
+ }
49
+
50
+ export class DocumentNotFoundError extends MongooseError {
51
+ name: 'DocumentNotFoundError';
52
+ result: any;
53
+ numAffected: number;
54
+ filter: any;
55
+ query: any;
56
+ }
57
+
58
+ export class ObjectExpectedError extends MongooseError {
59
+ name: 'ObjectExpectedError';
60
+ path: string;
61
+ }
62
+
63
+ export class ObjectParameterError extends MongooseError {
64
+ name: 'ObjectParameterError';
65
+ }
66
+
67
+ export class OverwriteModelError extends MongooseError {
68
+ name: 'OverwriteModelError';
69
+ }
70
+
71
+ export class ParallelSaveError extends MongooseError {
72
+ name: 'ParallelSaveError';
73
+ }
74
+
75
+ export class ParallelValidateError extends MongooseError {
76
+ name: 'ParallelValidateError';
77
+ }
78
+
79
+ export class MongooseServerSelectionError extends MongooseError {
80
+ name: 'MongooseServerSelectionError';
81
+ }
82
+
83
+ export class StrictModeError extends MongooseError {
84
+ name: 'StrictModeError';
85
+ isImmutableError: boolean;
86
+ path: string;
87
+ }
88
+
89
+ export class ValidationError extends MongooseError {
90
+ name: 'ValidationError';
91
+
92
+ errors: { [path: string]: ValidatorError | CastError };
93
+ addError: (path: string, error: ValidatorError | CastError) => void;
94
+
95
+ constructor(instance?: MongooseError);
96
+ }
97
+
98
+ export class ValidatorError extends MongooseError {
99
+ name: 'ValidatorError';
100
+ properties: {
101
+ message: string,
102
+ type?: string,
103
+ path?: string,
104
+ value?: any,
105
+ reason?: any
106
+ };
107
+ kind: string;
108
+ path: string;
109
+ value: any;
110
+ reason?: MongooseError | null;
111
+
112
+ constructor(properties: {
113
+ message?: string,
114
+ type?: string,
115
+ path?: string,
116
+ value?: any,
117
+ reason?: any
118
+ });
119
+ }
120
+
121
+ export class VersionError extends MongooseError {
122
+ name: 'VersionError';
123
+ version: number;
124
+ modifiedPaths: Array<string>;
125
+
126
+ constructor(doc: Document, currentVersion: number, modifiedPaths: Array<string>);
127
+ }
128
+ }
129
+ }