mongoose 6.2.5 → 6.2.8

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/types/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  /// <reference path="./connection.d.ts" />
2
- /// <reference path="./cursor.ts" />
2
+ /// <reference path="./cursor.d.ts" />
3
+ /// <reference path="./document.d.ts" />
3
4
  /// <reference path="./error.d.ts" />
5
+ /// <reference path="./mongooseoptions.d.ts" />
4
6
  /// <reference path="./pipelinestage.d.ts" />
5
7
  /// <reference path="./schemaoptions.d.ts" />
6
8
 
7
9
  import events = require('events');
8
10
  import mongodb = require('mongodb');
9
11
  import mongoose = require('mongoose');
10
- import stream = require('stream');
11
12
 
12
13
  declare module 'mongoose' {
13
14
 
@@ -174,117 +175,6 @@ declare module 'mongoose' {
174
175
 
175
176
  type Mongoose = typeof mongoose;
176
177
 
177
- interface MongooseOptions {
178
- /** true by default. Set to false to skip applying global plugins to child schemas */
179
- applyPluginsToChildSchemas?: boolean;
180
-
181
- /**
182
- * false by default. Set to true to apply global plugins to discriminator schemas.
183
- * This typically isn't necessary because plugins are applied to the base schema and
184
- * discriminators copy all middleware, methods, statics, and properties from the base schema.
185
- */
186
- applyPluginsToDiscriminators?: boolean;
187
-
188
- /**
189
- * Set to `true` to make Mongoose call` Model.createCollection()` automatically when you
190
- * create a model with `mongoose.model()` or `conn.model()`. This is useful for testing
191
- * transactions, change streams, and other features that require the collection to exist.
192
- */
193
- autoCreate?: boolean;
194
-
195
- /**
196
- * true by default. Set to false to disable automatic index creation
197
- * for all models associated with this Mongoose instance.
198
- */
199
- autoIndex?: boolean;
200
-
201
- /** enable/disable mongoose's buffering mechanism for all connections and models */
202
- bufferCommands?: boolean;
203
-
204
- bufferTimeoutMS?: number;
205
-
206
- /** false by default. Set to `true` to `clone()` all schemas before compiling into a model. */
207
- cloneSchemas?: boolean;
208
-
209
- /**
210
- * If `true`, prints the operations mongoose sends to MongoDB to the console.
211
- * If a writable stream is passed, it will log to that stream, without colorization.
212
- * If a callback function is passed, it will receive the collection name, the method
213
- * name, then all arguments passed to the method. For example, if you wanted to
214
- * replicate the default logging, you could output from the callback
215
- * `Mongoose: ${collectionName}.${methodName}(${methodArgs.join(', ')})`.
216
- */
217
- debug?:
218
- | boolean
219
- | { color?: boolean; shell?: boolean }
220
- | stream.Writable
221
- | ((collectionName: string, methodName: string, ...methodArgs: any[]) => void);
222
-
223
- /** If set, attaches [maxTimeMS](https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/) to every query */
224
- maxTimeMS?: number;
225
-
226
- /**
227
- * true by default. Mongoose adds a getter to MongoDB ObjectId's called `_id` that
228
- * returns `this` for convenience with populate. Set this to false to remove the getter.
229
- */
230
- objectIdGetter?: boolean;
231
-
232
- /**
233
- * Set to `true` to default to overwriting models with the same name when calling
234
- * `mongoose.model()`, as opposed to throwing an `OverwriteModelError`.
235
- */
236
- overwriteModels?: boolean;
237
-
238
- /**
239
- * If `false`, changes the default `returnOriginal` option to `findOneAndUpdate()`,
240
- * `findByIdAndUpdate`, and `findOneAndReplace()` to false. This is equivalent to
241
- * setting the `new` option to `true` for `findOneAndX()` calls by default. Read our
242
- * `findOneAndUpdate()` [tutorial](https://mongoosejs.com/docs/tutorials/findoneandupdate.html)
243
- * for more information.
244
- */
245
- returnOriginal?: boolean;
246
-
247
- /**
248
- * false by default. Set to true to enable [update validators](
249
- * https://mongoosejs.com/docs/validation.html#update-validators
250
- * ) for all validators by default.
251
- */
252
- runValidators?: boolean;
253
-
254
- sanitizeFilter?: boolean;
255
-
256
- sanitizeProjection?: boolean;
257
-
258
- /**
259
- * true by default. Set to false to opt out of Mongoose adding all fields that you `populate()`
260
- * to your `select()`. The schema-level option `selectPopulatedPaths` overwrites this one.
261
- */
262
- selectPopulatedPaths?: boolean;
263
-
264
- setDefaultsOnInsert?: boolean;
265
-
266
- /** true by default, may be `false`, `true`, or `'throw'`. Sets the default strict mode for schemas. */
267
- strict?: boolean | 'throw';
268
-
269
- /** true by default. set to `false` to allow populating paths that aren't in the schema */
270
- strictPopulate?: boolean;
271
-
272
- /**
273
- * false by default, may be `false`, `true`, or `'throw'`. Sets the default
274
- * [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
275
- */
276
- strictQuery?: boolean | 'throw';
277
-
278
- /**
279
- * `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to
280
- * `toJSON()`, for determining how Mongoose documents get serialized by `JSON.stringify()`
281
- */
282
- toJSON?: ToObjectOptions;
283
-
284
- /** `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to `toObject()` */
285
- toObject?: ToObjectOptions;
286
- }
287
-
288
178
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
289
179
  interface ClientSession extends mongodb.ClientSession { }
290
180
 
@@ -331,247 +221,8 @@ declare module 'mongoose' {
331
221
  getIndexes(): any;
332
222
  }
333
223
 
334
- class Document<T = any, TQueryHelpers = any, DocType = any> {
335
- constructor(doc?: any);
336
-
337
- /** This documents _id. */
338
- _id?: T;
339
-
340
- /** This documents __v. */
341
- __v?: any;
342
-
343
- /* Get all subdocs (by bfs) */
344
- $getAllSubdocs(): Document[];
345
-
346
- /** Don't run validation on this path or persist changes to this path. */
347
- $ignore(path: string): void;
348
-
349
- /** Checks if a path is set to its default. */
350
- $isDefault(path: string): boolean;
351
-
352
- /** Getter/setter, determines whether the document was removed or not. */
353
- $isDeleted(val?: boolean): boolean;
354
-
355
- /** Returns an array of all populated documents associated with the query */
356
- $getPopulatedDocs(): Document[];
357
-
358
- /**
359
- * Returns true if the given path is nullish or only contains empty objects.
360
- * Useful for determining whether this subdoc will get stripped out by the
361
- * [minimize option](/docs/guide.html#minimize).
362
- */
363
- $isEmpty(path: string): boolean;
364
-
365
- /** Checks if a path is invalid */
366
- $isValid(path: string): boolean;
367
-
368
- /**
369
- * Empty object that you can use for storing properties on the document. This
370
- * is handy for passing data to middleware without conflicting with Mongoose
371
- * internals.
372
- */
373
- $locals: Record<string, unknown>;
374
-
375
- /** Marks a path as valid, removing existing validation errors. */
376
- $markValid(path: string): void;
377
-
378
- /**
379
- * A string containing the current operation that Mongoose is executing
380
- * on this document. May be `null`, `'save'`, `'validate'`, or `'remove'`.
381
- */
382
- $op: string | null;
383
-
384
- /**
385
- * Getter/setter around the session associated with this document. Used to
386
- * automatically set `session` if you `save()` a doc that you got from a
387
- * query with an associated session.
388
- */
389
- $session(session?: mongodb.ClientSession | null): mongodb.ClientSession;
390
-
391
- /** Alias for `set()`, used internally to avoid conflicts */
392
- $set(path: string, val: any, options?: any): this;
393
- $set(path: string, val: any, type: any, options?: any): this;
394
- $set(value: any): this;
395
-
396
- /** Set this property to add additional query filters when Mongoose saves this document and `isNew` is false. */
397
- $where: Record<string, unknown>;
398
-
399
- /** If this is a discriminator model, `baseModelName` is the name of the base model. */
400
- baseModelName?: string;
401
-
402
- /** Collection the model uses. */
403
- collection: Collection;
404
-
405
- /** Connection the model uses. */
406
- db: Connection;
407
-
408
- /** Removes this document from the db. */
409
- delete(options?: QueryOptions): QueryWithHelpers<any, this, TQueryHelpers>;
410
- delete(options: QueryOptions, cb?: Callback): void;
411
- delete(cb: Callback): void;
412
-
413
- /** Removes this document from the db. */
414
- deleteOne(options?: QueryOptions): QueryWithHelpers<any, this, TQueryHelpers>;
415
- deleteOne(options: QueryOptions, cb?: Callback): void;
416
- deleteOne(cb: Callback): void;
417
-
418
- /**
419
- * Takes a populated field and returns it to its unpopulated state. If called with
420
- * no arguments, then all populated fields are returned to their unpopulated state.
421
- */
422
- depopulate(path?: string | string[]): this;
423
-
424
- /**
425
- * Returns the list of paths that have been directly modified. A direct
426
- * modified path is a path that you explicitly set, whether via `doc.foo = 'bar'`,
427
- * `Object.assign(doc, { foo: 'bar' })`, or `doc.set('foo', 'bar')`.
428
- */
429
- directModifiedPaths(): Array<string>;
430
-
431
- /**
432
- * Returns true if this document is equal to another document.
433
- *
434
- * Documents are considered equal when they have matching `_id`s, unless neither
435
- * document has an `_id`, in which case this function falls back to using
436
- * `deepEqual()`.
437
- */
438
- equals(doc: Document<T>): boolean;
439
-
440
- /** Hash containing current validation errors. */
441
- errors?: Error.ValidationError;
442
-
443
- /** Returns the value of a path. */
444
- get(path: string, type?: any, options?: any): any;
445
-
446
- /**
447
- * Returns the changes that happened to the document
448
- * in the format that will be sent to MongoDB.
449
- */
450
- getChanges(): UpdateQuery<this>;
451
-
452
- /** The string version of this documents _id. */
453
- id?: any;
454
-
455
- /** Signal that we desire an increment of this documents version. */
456
- increment(): this;
457
-
458
- /**
459
- * Initializes the document without setters or marking anything modified.
460
- * Called internally after a document is returned from mongodb. Normally,
461
- * you do **not** need to call this function on your own.
462
- */
463
- init(obj: any, opts?: any, cb?: Callback<this>): this;
464
-
465
- /** Marks a path as invalid, causing validation to fail. */
466
- invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null;
467
-
468
- /** Returns true if `path` was directly set and modified, else false. */
469
- isDirectModified(path: string): boolean;
470
-
471
- /** Checks if `path` was explicitly selected. If no projection, always returns true. */
472
- isDirectSelected(path: string): boolean;
473
-
474
- /** Checks if `path` is in the `init` state, that is, it was set by `Document#init()` and not modified since. */
475
- isInit(path: string): boolean;
476
-
477
- /**
478
- * Returns true if any of the given paths is modified, else false. If no arguments, returns `true` if any path
479
- * in this document is modified.
480
- */
481
- isModified(path?: string | Array<string>): boolean;
482
-
483
- /** Boolean flag specifying if the document is new. */
484
- isNew: boolean;
485
-
486
- /** Checks if `path` was selected in the source query which initialized this document. */
487
- isSelected(path: string): boolean;
488
-
489
- /** Marks the path as having pending changes to write to the db. */
490
- markModified(path: string, scope?: any): void;
491
-
492
- /** Returns the list of paths that have been modified. */
493
- modifiedPaths(options?: { includeChildren?: boolean }): Array<string>;
494
-
495
- /** The name of the model */
496
- modelName: string;
497
-
498
- /**
499
- * Overwrite all values in this document with the values of `obj`, except
500
- * for immutable properties. Behaves similarly to `set()`, except for it
501
- * unsets all properties that aren't in `obj`.
502
- */
503
- overwrite(obj: AnyObject): this;
504
-
505
- /**
506
- * If this document is a subdocument or populated document, returns the
507
- * document's parent. Returns undefined otherwise.
508
- */
509
- $parent(): Document | undefined;
510
-
511
- /** Populates document references. */
512
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<this & Paths>;
513
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<this & Paths>): void;
514
- populate<Paths = {}>(path: string, names: string): Promise<this & Paths>;
515
- populate<Paths = {}>(path: string, names: string, callback: Callback<this & Paths>): void;
516
-
517
- /** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */
518
- populated(path: string): any;
519
-
520
- /** Removes this document from the db. */
521
- remove(options?: QueryOptions): Promise<this>;
522
- remove(options?: QueryOptions, cb?: Callback): void;
523
-
524
- /** Sends a replaceOne command with this document `_id` as the query selector. */
525
- replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
526
- replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
527
-
528
- /** 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`. */
529
- save(options?: SaveOptions): Promise<this>;
530
- save(options?: SaveOptions, fn?: Callback<this>): void;
531
- save(fn?: Callback<this>): void;
532
-
533
- /** The document's schema. */
534
- schema: Schema;
535
-
536
- /** Sets the value of a path, or many paths. */
537
- set(path: string, val: any, options?: any): this;
538
- set(path: string, val: any, type: any, options?: any): this;
539
- set(value: any): this;
540
-
541
- /** The return value of this method is used in calls to JSON.stringify(doc). */
542
- toJSON(options: ToObjectOptions & { flattenMaps: false }): LeanDocument<this>;
543
- toJSON(options?: ToObjectOptions): FlattenMaps<LeanDocument<this>>;
544
- toJSON<T = FlattenMaps<DocType>>(options?: ToObjectOptions): T;
545
-
546
- /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */
547
- toObject(options?: ToObjectOptions): LeanDocument<this>;
548
- toObject<T = DocType>(options?: ToObjectOptions): T;
549
-
550
- /** Clears the modified state on the specified path. */
551
- unmarkModified(path: string): void;
552
-
553
- /** Sends an update command with this document `_id` as the query selector. */
554
- update(update?: UpdateQuery<this> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
555
-
556
- /** Sends an updateOne command with this document `_id` as the query selector. */
557
- updateOne(update?: UpdateQuery<this> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
558
-
559
- /** Executes registered validation rules for this document. */
560
- validate(options:{ pathsToSkip?: pathsToSkip }): Promise<void>;
561
- validate(pathsToValidate?: pathsToValidate, options?: any): Promise<void>;
562
- validate(callback: CallbackWithoutResult): void;
563
- validate(pathsToValidate: pathsToValidate, callback: CallbackWithoutResult): void;
564
- validate(pathsToValidate: pathsToValidate, options: any, callback: CallbackWithoutResult): void;
565
-
566
- /** Executes registered validation rules (skipping asynchronous validators) for this document. */
567
- validateSync(options:{pathsToSkip?: pathsToSkip, [k:string]: any }): Error.ValidationError | null;
568
- validateSync(pathsToValidate?: Array<string>, options?: any): Error.ValidationError | null;
569
- }
570
-
571
224
  /** A list of paths to validate. If set, Mongoose will validate only the modified paths that are in the given list. */
572
225
  type pathsToValidate = string[] | string;
573
- /** A list of paths to skip. If set, Mongoose will validate every modified path that is not in this list. */
574
- type pathsToSkip = string[] | string;
575
226
 
576
227
  interface AcceptsDiscriminator {
577
228
  /** Adds a discriminator type. */
@@ -659,8 +310,8 @@ declare module 'mongoose' {
659
310
  * mongoose will not create the collection for the model until any documents are
660
311
  * created. Use this method to create the collection explicitly.
661
312
  */
662
- createCollection<T>(options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
663
- createCollection<T>(options: mongodb.CreateCollectionOptions | null, callback: Callback<mongodb.Collection<T>>): void;
313
+ createCollection<T>(options?: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'>): Promise<mongodb.Collection<T>>;
314
+ createCollection<T>(options: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'> | null, callback: Callback<mongodb.Collection<T>>): void;
664
315
 
665
316
  /**
666
317
  * Similar to `ensureIndexes()`, except for it uses the [`createIndex`](http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#createIndex)
@@ -1058,6 +709,8 @@ declare module 'mongoose' {
1058
709
  model?: string | Model<any>;
1059
710
  /** optional query options like sort, limit, etc */
1060
711
  options?: any;
712
+ /** optional boolean, set to `false` to allow populating paths that aren't in the schema */
713
+ strictPopulate?: boolean;
1061
714
  /** deep populate */
1062
715
  populate?: string | PopulateOptions | (string | PopulateOptions)[];
1063
716
  /**
@@ -1101,12 +754,12 @@ declare module 'mongoose' {
1101
754
  type IndexDirection = 1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text';
1102
755
  type IndexDefinition = Record<string, IndexDirection>;
1103
756
 
1104
- type PreMiddlewareFunction<T> = (this: T, next: (err?: CallbackError) => void) => void | Promise<void>;
1105
- type PreSaveMiddlewareFunction<T> = (this: T, next: (err?: CallbackError) => void, opts: SaveOptions) => void | Promise<void>;
1106
- type PostMiddlewareFunction<ThisType, ResType = any> = (this: ThisType, res: ResType, next: (err?: CallbackError) => void) => void | Promise<void>;
1107
- type ErrorHandlingMiddlewareFunction<ThisType, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: (err?: CallbackError) => void) => void;
757
+ export type PreMiddlewareFunction<ThisType = any> = (this: ThisType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>;
758
+ export type PreSaveMiddlewareFunction<ThisType = any> = (this: ThisType, next: CallbackWithoutResultAndOptionalError, opts: SaveOptions) => void | Promise<void>;
759
+ export type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>;
760
+ export type ErrorHandlingMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: CallbackWithoutResultAndOptionalError) => void;
1108
761
 
1109
- class Schema<DocType = any, M = Model<DocType, any, any, any>, TInstanceMethods = any, TQueryHelpers = any> extends events.EventEmitter {
762
+ class Schema<DocType = any, M = Model<DocType, any, any, any>, TInstanceMethods = {}, TQueryHelpers = {}> extends events.EventEmitter {
1110
763
  /**
1111
764
  * Create a new schema
1112
765
  */
@@ -1160,7 +813,7 @@ declare module 'mongoose' {
1160
813
  method(obj: Partial<TInstanceMethods>): this;
1161
814
 
1162
815
  /** Object of currently defined methods on this schema. */
1163
- methods: { [F in keyof TInstanceMethods]: TInstanceMethods[F] };
816
+ methods: { [F in keyof TInstanceMethods]: TInstanceMethods[F] } & AnyObject;
1164
817
 
1165
818
  /** The original object passed to the schema constructor */
1166
819
  obj: SchemaDefinition<SchemaDefinitionType<DocType>>;
@@ -1282,6 +935,8 @@ declare module 'mongoose' {
1282
935
  type AnyArray<T> = T[] | ReadonlyArray<T>;
1283
936
  type SchemaValidator<T> = RegExp | [RegExp, string] | Function | [Function, string] | ValidateOpts<T> | ValidateOpts<T>[];
1284
937
 
938
+ type ExtractMongooseArray<T> = T extends Types.Array<any> ? AnyArray<Unpacked<T>> : T;
939
+
1285
940
  export class SchemaTypeOptions<T> {
1286
941
  type?:
1287
942
  T extends string ? StringSchemaDefinition :
@@ -1319,7 +974,7 @@ declare module 'mongoose' {
1319
974
  * The default value for this path. If a function, Mongoose executes the function
1320
975
  * and uses the return value as the default.
1321
976
  */
1322
- default?: T | ((this: any, doc: any) => Partial<T>);
977
+ default?: ExtractMongooseArray<T> | ((this: any, doc: any) => Partial<ExtractMongooseArray<T>>);
1323
978
 
1324
979
  /**
1325
980
  * The model that `populate()` should use if populating this path.
@@ -1814,8 +1469,11 @@ declare module 'mongoose' {
1814
1469
 
1815
1470
  type QueryWithHelpers<ResultType, DocType, THelpers = {}, RawDocType = DocType> = Query<ResultType, DocType, THelpers, RawDocType> & THelpers;
1816
1471
 
1817
- type UnpackedIntersection<T, U> = T extends (infer V)[] ? (V & U)[] : T & U;
1818
- type UnpackedIntersectionWithNull<T, U> = T extends null ? UnpackedIntersection<T, U> | null : UnpackedIntersection<T, U>;
1472
+ type UnpackedIntersection<T, U> = T extends (infer A)[]
1473
+ ? (Omit<A, keyof U> & U)[]
1474
+ : keyof U extends never
1475
+ ? T
1476
+ : Omit<T, keyof U> & U;
1819
1477
 
1820
1478
  type ProjectionFields<DocType> = {[Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any} & Record<string, any>;
1821
1479
 
@@ -2116,8 +1774,8 @@ declare module 'mongoose' {
2116
1774
  polygon(path: string, ...coordinatePairs: number[][]): this;
2117
1775
 
2118
1776
  /** Specifies paths which should be populated with other documents. */
2119
- populate<Paths = {}>(path: string, select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersectionWithNull<ResultType, Paths>, DocType, THelpers, RawDocType>;
2120
- populate<Paths = {}>(options: PopulateOptions | Array<PopulateOptions>): QueryWithHelpers<UnpackedIntersectionWithNull<ResultType, Paths>, DocType, THelpers, RawDocType>;
1777
+ populate<Paths = {}>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>;
1778
+ populate<Paths = {}>(options: PopulateOptions | (PopulateOptions | string)[]): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>;
2121
1779
 
2122
1780
  /** Get/set the current projection (AKA fields). Pass `null` to remove the current projection. */
2123
1781
  projection(): ProjectionFields<DocType> | null;
@@ -2704,6 +2362,7 @@ declare module 'mongoose' {
2704
2362
  type Callback<T = any> = (error: CallbackError, result: T) => void;
2705
2363
 
2706
2364
  type CallbackWithoutResult = (error: CallbackError) => void;
2365
+ type CallbackWithoutResultAndOptionalError = (error?: CallbackError) => void;
2707
2366
 
2708
2367
  /* for ts-mongoose */
2709
2368
  class mquery {}
@@ -0,0 +1,180 @@
1
+ import stream = require('stream');
2
+
3
+ declare module 'mongoose' {
4
+
5
+ interface MongooseOptions {
6
+ /**
7
+ * Set to false to skip applying global plugins to child schemas.
8
+ *
9
+ * @default true
10
+ */
11
+ applyPluginsToChildSchemas?: boolean;
12
+
13
+ /**
14
+ * Set to true to apply global plugins to discriminator schemas.
15
+ * This typically isn't necessary because plugins are applied to the base schema and
16
+ * discriminators copy all middleware, methods, statics, and properties from the base schema.
17
+ *
18
+ * @default false
19
+ */
20
+ applyPluginsToDiscriminators?: boolean;
21
+
22
+ /**
23
+ * autoCreate is true by default unless readPreference is secondary or secondaryPreferred,
24
+ * which means Mongoose will attempt to create every model's underlying collection before
25
+ * creating indexes. If readPreference is secondary or secondaryPreferred, Mongoose will
26
+ * default to false for both autoCreate and autoIndex because both createCollection() and
27
+ * createIndex() will fail when connected to a secondary.
28
+ */
29
+ autoCreate?: boolean;
30
+
31
+ /**
32
+ * Set to false to disable automatic index creation for all models associated with this Mongoose instance.
33
+ *
34
+ * @default true
35
+ */
36
+ autoIndex?: boolean;
37
+
38
+ /**
39
+ * enable/disable mongoose's buffering mechanism for all connections and models.
40
+ *
41
+ * @default true
42
+ */
43
+ bufferCommands?: boolean;
44
+
45
+ /**
46
+ * If bufferCommands is on, this option sets the maximum amount of time Mongoose
47
+ * buffering will wait before throwing an error.
48
+ * If not specified, Mongoose will use 10000 (10 seconds).
49
+ *
50
+ * @default 10000
51
+ */
52
+ bufferTimeoutMS?: number;
53
+
54
+ /**
55
+ * Set to `true` to `clone()` all schemas before compiling into a model.
56
+ *
57
+ * @default false
58
+ */
59
+ cloneSchemas?: boolean;
60
+
61
+ /**
62
+ * If `true`, prints the operations mongoose sends to MongoDB to the console.
63
+ * If a writable stream is passed, it will log to that stream, without colorization.
64
+ * If a callback function is passed, it will receive the collection name, the method
65
+ * name, then all arguments passed to the method. For example, if you wanted to
66
+ * replicate the default logging, you could output from the callback
67
+ * `Mongoose: ${collectionName}.${methodName}(${methodArgs.join(', ')})`.
68
+ *
69
+ * @default false
70
+ */
71
+ debug?:
72
+ | boolean
73
+ | { color?: boolean; shell?: boolean; }
74
+ | stream.Writable
75
+ | ((collectionName: string, methodName: string, ...methodArgs: any[]) => void);
76
+
77
+ /** If set, attaches [maxTimeMS](https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/) to every query */
78
+ maxTimeMS?: number;
79
+
80
+ /**
81
+ * Mongoose adds a getter to MongoDB ObjectId's called `_id` that
82
+ * returns `this` for convenience with populate. Set this to false to remove the getter.
83
+ *
84
+ * @default true
85
+ */
86
+ objectIdGetter?: boolean;
87
+
88
+ /**
89
+ * Set to `true` to default to overwriting models with the same name when calling
90
+ * `mongoose.model()`, as opposed to throwing an `OverwriteModelError`.
91
+ *
92
+ * @default false
93
+ */
94
+ overwriteModels?: boolean;
95
+
96
+ /**
97
+ * If `false`, changes the default `returnOriginal` option to `findOneAndUpdate()`,
98
+ * `findByIdAndUpdate`, and `findOneAndReplace()` to false. This is equivalent to
99
+ * setting the `new` option to `true` for `findOneAndX()` calls by default. Read our
100
+ * `findOneAndUpdate()` [tutorial](https://mongoosejs.com/docs/tutorials/findoneandupdate.html)
101
+ * for more information.
102
+ *
103
+ * @default true
104
+ */
105
+ returnOriginal?: boolean;
106
+
107
+ /**
108
+ * Set to true to enable [update validators](
109
+ * https://mongoosejs.com/docs/validation.html#update-validators
110
+ * ) for all validators by default.
111
+ *
112
+ * @default false
113
+ */
114
+ runValidators?: boolean;
115
+
116
+ /**
117
+ * Sanitizes query filters against [query selector injection attacks](
118
+ * https://thecodebarbarian.com/2014/09/04/defending-against-query-selector-injection-attacks.html
119
+ * ) by wrapping any nested objects that have a property whose name starts with $ in a $eq.
120
+ */
121
+ sanitizeFilter?: boolean;
122
+
123
+ sanitizeProjection?: boolean;
124
+
125
+ /**
126
+ * Set to false to opt out of Mongoose adding all fields that you `populate()`
127
+ * to your `select()`. The schema-level option `selectPopulatedPaths` overwrites this one.
128
+ *
129
+ * @default true
130
+ */
131
+ selectPopulatedPaths?: boolean;
132
+
133
+ /**
134
+ * Mongoose also sets defaults on update() and findOneAndUpdate() when the upsert option is
135
+ * set by adding your schema's defaults to a MongoDB $setOnInsert operator. You can disable
136
+ * this behavior by setting the setDefaultsOnInsert option to false.
137
+ *
138
+ * @default true
139
+ */
140
+ setDefaultsOnInsert?: boolean;
141
+
142
+ /**
143
+ * Sets the default strict mode for schemas.
144
+ * May be `false`, `true`, or `'throw'`.
145
+ *
146
+ * @default true
147
+ */
148
+ strict?: boolean | 'throw';
149
+
150
+ /**
151
+ * Set to `false` to allow populating paths that aren't in the schema.
152
+ *
153
+ * @default true
154
+ */
155
+ strictPopulate?: boolean;
156
+
157
+ /**
158
+ * Sets the default [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
159
+ * May be `false`, `true`, or `'throw'`.
160
+ *
161
+ * @default false
162
+ */
163
+ strictQuery?: boolean | 'throw';
164
+
165
+ /**
166
+ * Overwrites default objects to `toJSON()`, for determining how Mongoose
167
+ * documents get serialized by `JSON.stringify()`
168
+ *
169
+ * @default { transform: true, flattenDecimals: true }
170
+ */
171
+ toJSON?: ToObjectOptions;
172
+
173
+ /**
174
+ * Overwrites default objects to `toObject()`
175
+ *
176
+ * @default { transform: true, flattenDecimals: true }
177
+ */
178
+ toObject?: ToObjectOptions;
179
+ }
180
+ }
@@ -43,6 +43,12 @@ declare module 'mongoose' {
43
43
  /** The timeseries option to use when creating the model's collection. */
44
44
  timeseries?: mongodb.TimeSeriesCollectionOptions;
45
45
 
46
+ /** The number of seconds after which a document in a timeseries collection expires. */
47
+ expireAfterSeconds?: number;
48
+
49
+ /** The time after which a document in a timeseries collection expires. */
50
+ expires?: number | string;
51
+
46
52
  /**
47
53
  * Mongoose by default produces a collection name by passing the model name to the utils.toCollectionName
48
54
  * method. This method pluralizes the name. Set this option if you need a different name for your collection.