mongoose 6.2.6 → 6.2.9

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
@@ -2,13 +2,13 @@
2
2
  /// <reference path="./cursor.d.ts" />
3
3
  /// <reference path="./document.d.ts" />
4
4
  /// <reference path="./error.d.ts" />
5
+ /// <reference path="./mongooseoptions.d.ts" />
5
6
  /// <reference path="./pipelinestage.d.ts" />
6
7
  /// <reference path="./schemaoptions.d.ts" />
7
8
 
8
9
  import events = require('events');
9
10
  import mongodb = require('mongodb');
10
11
  import mongoose = require('mongoose');
11
- import stream = require('stream');
12
12
 
13
13
  declare module 'mongoose' {
14
14
 
@@ -175,121 +175,10 @@ declare module 'mongoose' {
175
175
 
176
176
  type Mongoose = typeof mongoose;
177
177
 
178
- interface MongooseOptions {
179
- /** true by default. Set to false to skip applying global plugins to child schemas */
180
- applyPluginsToChildSchemas?: boolean;
181
-
182
- /**
183
- * false by default. Set to true to apply global plugins to discriminator schemas.
184
- * This typically isn't necessary because plugins are applied to the base schema and
185
- * discriminators copy all middleware, methods, statics, and properties from the base schema.
186
- */
187
- applyPluginsToDiscriminators?: boolean;
188
-
189
- /**
190
- * Set to `true` to make Mongoose call` Model.createCollection()` automatically when you
191
- * create a model with `mongoose.model()` or `conn.model()`. This is useful for testing
192
- * transactions, change streams, and other features that require the collection to exist.
193
- */
194
- autoCreate?: boolean;
195
-
196
- /**
197
- * true by default. Set to false to disable automatic index creation
198
- * for all models associated with this Mongoose instance.
199
- */
200
- autoIndex?: boolean;
201
-
202
- /** enable/disable mongoose's buffering mechanism for all connections and models */
203
- bufferCommands?: boolean;
204
-
205
- bufferTimeoutMS?: number;
206
-
207
- /** false by default. Set to `true` to `clone()` all schemas before compiling into a model. */
208
- cloneSchemas?: boolean;
209
-
210
- /**
211
- * If `true`, prints the operations mongoose sends to MongoDB to the console.
212
- * If a writable stream is passed, it will log to that stream, without colorization.
213
- * If a callback function is passed, it will receive the collection name, the method
214
- * name, then all arguments passed to the method. For example, if you wanted to
215
- * replicate the default logging, you could output from the callback
216
- * `Mongoose: ${collectionName}.${methodName}(${methodArgs.join(', ')})`.
217
- */
218
- debug?:
219
- | boolean
220
- | { color?: boolean; shell?: boolean }
221
- | stream.Writable
222
- | ((collectionName: string, methodName: string, ...methodArgs: any[]) => void);
223
-
224
- /** If set, attaches [maxTimeMS](https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/) to every query */
225
- maxTimeMS?: number;
226
-
227
- /**
228
- * true by default. Mongoose adds a getter to MongoDB ObjectId's called `_id` that
229
- * returns `this` for convenience with populate. Set this to false to remove the getter.
230
- */
231
- objectIdGetter?: boolean;
232
-
233
- /**
234
- * Set to `true` to default to overwriting models with the same name when calling
235
- * `mongoose.model()`, as opposed to throwing an `OverwriteModelError`.
236
- */
237
- overwriteModels?: boolean;
238
-
239
- /**
240
- * If `false`, changes the default `returnOriginal` option to `findOneAndUpdate()`,
241
- * `findByIdAndUpdate`, and `findOneAndReplace()` to false. This is equivalent to
242
- * setting the `new` option to `true` for `findOneAndX()` calls by default. Read our
243
- * `findOneAndUpdate()` [tutorial](https://mongoosejs.com/docs/tutorials/findoneandupdate.html)
244
- * for more information.
245
- */
246
- returnOriginal?: boolean;
247
-
248
- /**
249
- * false by default. Set to true to enable [update validators](
250
- * https://mongoosejs.com/docs/validation.html#update-validators
251
- * ) for all validators by default.
252
- */
253
- runValidators?: boolean;
254
-
255
- sanitizeFilter?: boolean;
256
-
257
- sanitizeProjection?: boolean;
258
-
259
- /**
260
- * true by default. Set to false to opt out of Mongoose adding all fields that you `populate()`
261
- * to your `select()`. The schema-level option `selectPopulatedPaths` overwrites this one.
262
- */
263
- selectPopulatedPaths?: boolean;
264
-
265
- setDefaultsOnInsert?: boolean;
266
-
267
- /** true by default, may be `false`, `true`, or `'throw'`. Sets the default strict mode for schemas. */
268
- strict?: boolean | 'throw';
269
-
270
- /** true by default. set to `false` to allow populating paths that aren't in the schema */
271
- strictPopulate?: boolean;
272
-
273
- /**
274
- * false by default, may be `false`, `true`, or `'throw'`. Sets the default
275
- * [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
276
- */
277
- strictQuery?: boolean | 'throw';
278
-
279
- /**
280
- * `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to
281
- * `toJSON()`, for determining how Mongoose documents get serialized by `JSON.stringify()`
282
- */
283
- toJSON?: ToObjectOptions;
284
-
285
- /** `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to `toObject()` */
286
- toObject?: ToObjectOptions;
287
- }
288
-
289
178
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
290
179
  interface ClientSession extends mongodb.ClientSession { }
291
180
 
292
- /*
181
+ /*
293
182
  * section collection.js
294
183
  * http://mongoosejs.com/docs/api.html#collection-js
295
184
  */
@@ -342,7 +231,9 @@ declare module 'mongoose' {
342
231
  }
343
232
 
344
233
  type AnyKeys<T> = { [P in keyof T]?: T[P] | any };
345
- interface AnyObject { [k: string]: any }
234
+ interface AnyObject {
235
+ [k: string]: any
236
+ }
346
237
 
347
238
  type Require_id<T> = T extends { _id?: any } ? (T & { _id: T['_id'] }) : (T & { _id: Types.ObjectId });
348
239
 
@@ -421,8 +312,8 @@ declare module 'mongoose' {
421
312
  * mongoose will not create the collection for the model until any documents are
422
313
  * created. Use this method to create the collection explicitly.
423
314
  */
424
- createCollection<T>(options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
425
- createCollection<T>(options: mongodb.CreateCollectionOptions | null, callback: Callback<mongodb.Collection<T>>): void;
315
+ createCollection<T>(options?: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'>): Promise<mongodb.Collection<T>>;
316
+ createCollection<T>(options: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'> | null, callback: Callback<mongodb.Collection<T>>): void;
426
317
 
427
318
  /**
428
319
  * Similar to `ensureIndexes()`, except for it uses the [`createIndex`](http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#createIndex)
@@ -820,6 +711,8 @@ declare module 'mongoose' {
820
711
  model?: string | Model<any>;
821
712
  /** optional query options like sort, limit, etc */
822
713
  options?: any;
714
+ /** optional boolean, set to `false` to allow populating paths that aren't in the schema */
715
+ strictPopulate?: boolean;
823
716
  /** deep populate */
824
717
  populate?: string | PopulateOptions | (string | PopulateOptions)[];
825
718
  /**
@@ -868,7 +761,7 @@ declare module 'mongoose' {
868
761
  export type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>;
869
762
  export type ErrorHandlingMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: CallbackWithoutResultAndOptionalError) => void;
870
763
 
871
- class Schema<DocType = any, M = Model<DocType, any, any, any>, TInstanceMethods = any, TQueryHelpers = any> extends events.EventEmitter {
764
+ class Schema<DocType = any, M = Model<DocType, any, any, any>, TInstanceMethods = {}, TQueryHelpers = {}> extends events.EventEmitter {
872
765
  /**
873
766
  * Create a new schema
874
767
  */
@@ -922,7 +815,7 @@ declare module 'mongoose' {
922
815
  method(obj: Partial<TInstanceMethods>): this;
923
816
 
924
817
  /** Object of currently defined methods on this schema. */
925
- methods: { [F in keyof TInstanceMethods]: TInstanceMethods[F] };
818
+ methods: { [F in keyof TInstanceMethods]: TInstanceMethods[F] } & AnyObject;
926
819
 
927
820
  /** The original object passed to the schema constructor */
928
821
  obj: SchemaDefinition<SchemaDefinitionType<DocType>>;
@@ -1015,22 +908,22 @@ declare module 'mongoose' {
1015
908
  type SchemaDefinitionWithBuiltInClass<T> = T extends number
1016
909
  ? NumberSchemaDefinition
1017
910
  : T extends string
1018
- ? StringSchemaDefinition
1019
- : T extends boolean
1020
- ? BooleanSchemaDefinition
1021
- : T extends NativeDate
1022
- ? DateSchemaDefinition
1023
- : (Function | string);
911
+ ? StringSchemaDefinition
912
+ : T extends boolean
913
+ ? BooleanSchemaDefinition
914
+ : T extends NativeDate
915
+ ? DateSchemaDefinition
916
+ : (Function | string);
1024
917
 
1025
918
  type SchemaDefinitionProperty<T = undefined> = SchemaDefinitionWithBuiltInClass<T> |
1026
- SchemaTypeOptions<T extends undefined ? any : T> |
919
+ SchemaTypeOptions<T extends undefined ? any : T> |
1027
920
  typeof SchemaType |
1028
- Schema<any, any, any> |
1029
- Schema<any, any, any>[] |
1030
- SchemaTypeOptions<T extends undefined ? any : Unpacked<T>>[] |
1031
- Function[] |
1032
- SchemaDefinition<T> |
1033
- SchemaDefinition<Unpacked<T>>[] |
921
+ Schema<any, any, any> |
922
+ Schema<any, any, any>[] |
923
+ SchemaTypeOptions<T extends undefined ? any : Unpacked<T>>[] |
924
+ Function[] |
925
+ SchemaDefinition<T> |
926
+ SchemaDefinition<Unpacked<T>>[] |
1034
927
  typeof SchemaTypes.Mixed;
1035
928
 
1036
929
  type SchemaDefinition<T = undefined> = T extends undefined
@@ -1044,22 +937,24 @@ declare module 'mongoose' {
1044
937
  type AnyArray<T> = T[] | ReadonlyArray<T>;
1045
938
  type SchemaValidator<T> = RegExp | [RegExp, string] | Function | [Function, string] | ValidateOpts<T> | ValidateOpts<T>[];
1046
939
 
940
+ type ExtractMongooseArray<T> = T extends Types.Array<any> ? AnyArray<Unpacked<T>> : T;
941
+
1047
942
  export class SchemaTypeOptions<T> {
1048
943
  type?:
1049
- T extends string ? StringSchemaDefinition :
944
+ T extends string ? StringSchemaDefinition :
1050
945
  T extends number ? NumberSchemaDefinition :
1051
- T extends boolean ? BooleanSchemaDefinition :
1052
- T extends NativeDate ? DateSchemaDefinition :
1053
- T extends Map<any, any> ? SchemaDefinition<typeof Map> :
1054
- T extends Buffer ? SchemaDefinition<typeof Buffer> :
1055
- T extends Types.ObjectId ? ObjectIdSchemaDefinition :
1056
- T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId>> :
1057
- T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>>>) :
1058
- T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string>> :
1059
- T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number>> :
1060
- T extends boolean[] ? AnyArray<BooleanSchemaDefinition> | AnyArray<SchemaTypeOptions<boolean>> :
1061
- T extends Function[] ? AnyArray<Function | string> | AnyArray<SchemaTypeOptions<Unpacked<T>>> :
1062
- T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T> | Function | AnyArray<Function>;
946
+ T extends boolean ? BooleanSchemaDefinition :
947
+ T extends NativeDate ? DateSchemaDefinition :
948
+ T extends Map<any, any> ? SchemaDefinition<typeof Map> :
949
+ T extends Buffer ? SchemaDefinition<typeof Buffer> :
950
+ T extends Types.ObjectId ? ObjectIdSchemaDefinition :
951
+ T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId>> :
952
+ T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>>>) :
953
+ T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string>> :
954
+ T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number>> :
955
+ T extends boolean[] ? AnyArray<BooleanSchemaDefinition> | AnyArray<SchemaTypeOptions<boolean>> :
956
+ T extends Function[] ? AnyArray<Function | string> | AnyArray<SchemaTypeOptions<Unpacked<T>>> :
957
+ T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T> | Function | AnyArray<Function>;
1063
958
 
1064
959
  /** Defines a virtual with the given name that gets/sets this path. */
1065
960
  alias?: string;
@@ -1081,7 +976,7 @@ declare module 'mongoose' {
1081
976
  * The default value for this path. If a function, Mongoose executes the function
1082
977
  * and uses the return value as the default.
1083
978
  */
1084
- default?: T | ((this: any, doc: any) => Partial<T>);
979
+ default?: ExtractMongooseArray<T> | ((this: any, doc: any) => Partial<ExtractMongooseArray<T>>);
1085
980
 
1086
981
  /**
1087
982
  * The model that `populate()` should use if populating this path.
@@ -1204,7 +1099,7 @@ declare module 'mongoose' {
1204
1099
  export type PopulatedDoc<
1205
1100
  PopulatedType,
1206
1101
  RawId extends RefType = (PopulatedType extends { _id?: RefType; } ? NonNullable<PopulatedType['_id']> : mongoose.Types.ObjectId) | undefined
1207
- > = PopulatedType | RawId;
1102
+ > = PopulatedType | RawId;
1208
1103
 
1209
1104
  interface IndexOptions extends mongodb.CreateIndexesOptions {
1210
1105
  /**
@@ -1572,17 +1467,17 @@ declare module 'mongoose' {
1572
1467
  }
1573
1468
  }
1574
1469
 
1575
- type ReturnsNewDoc = { new: true } | { returnOriginal: false } | {returnDocument: 'after'};
1470
+ type ReturnsNewDoc = { new: true } | { returnOriginal: false } | { returnDocument: 'after' };
1576
1471
 
1577
1472
  type QueryWithHelpers<ResultType, DocType, THelpers = {}, RawDocType = DocType> = Query<ResultType, DocType, THelpers, RawDocType> & THelpers;
1578
1473
 
1579
- type UnpackedIntersection<T, U> = T extends (infer A)[]
1474
+ type UnpackedIntersection<T, U> = T extends null ? null : T extends (infer A)[]
1580
1475
  ? (Omit<A, keyof U> & U)[]
1581
1476
  : keyof U extends never
1582
- ? T
1583
- : Omit<T, keyof U> & U;
1477
+ ? T
1478
+ : Omit<T, keyof U> & U;
1584
1479
 
1585
- type ProjectionFields<DocType> = {[Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any} & Record<string, any>;
1480
+ type ProjectionFields<DocType> = { [Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any } & Record<string, any>;
1586
1481
 
1587
1482
  class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {
1588
1483
  _mongooseOptions: MongooseQueryOptions;
@@ -1881,8 +1776,8 @@ declare module 'mongoose' {
1881
1776
  polygon(path: string, ...coordinatePairs: number[][]): this;
1882
1777
 
1883
1778
  /** Specifies paths which should be populated with other documents. */
1884
- populate<Paths = {}>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>;
1885
- populate<Paths = {}>(options: PopulateOptions | (PopulateOptions | string)[]): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>;
1779
+ populate<Paths = {}>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, UnpackedIntersection<RawDocType, Paths>>;
1780
+ populate<Paths = {}>(options: PopulateOptions | (PopulateOptions | string)[]): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, UnpackedIntersection<RawDocType, Paths>>;
1886
1781
 
1887
1782
  /** Get/set the current projection (AKA fields). Pass `null` to remove the current projection. */
1888
1783
  projection(): ProjectionFields<DocType> | null;
@@ -2072,10 +1967,10 @@ declare module 'mongoose' {
2072
1967
  $or?: Array<FilterQuery<T>>;
2073
1968
  /** @see https://docs.mongodb.com/manual/reference/operator/query/text */
2074
1969
  $text?: {
2075
- $search: string;
2076
- $language?: string;
2077
- $caseSensitive?: boolean;
2078
- $diacriticSensitive?: boolean;
1970
+ $search: string;
1971
+ $language?: string;
1972
+ $caseSensitive?: boolean;
1973
+ $diacriticSensitive?: boolean;
2079
1974
  };
2080
1975
  /** @see https://docs.mongodb.com/manual/reference/operator/query/where/#op._S_where */
2081
1976
  $where?: string | Function;
@@ -2092,7 +1987,7 @@ declare module 'mongoose' {
2092
1987
  type _FilterQuery<T> = {
2093
1988
  [P in keyof T]?: Condition<T[P]>;
2094
1989
  } &
2095
- RootQuerySelector<T>;
1990
+ RootQuerySelector<T>;
2096
1991
 
2097
1992
  /**
2098
1993
  * Filter query to select the documents that match the query
@@ -2139,21 +2034,21 @@ declare module 'mongoose' {
2139
2034
 
2140
2035
  /** @see https://docs.mongodb.com/manual/reference/operator/update-bitwise/ */
2141
2036
  $bit?: {
2142
- [key: string]: { [key in 'and' | 'or' | 'xor']?: number };
2037
+ [key: string]: { [key in 'and' | 'or' | 'xor']?: number };
2143
2038
  };
2144
2039
  };
2145
2040
 
2146
2041
  type UpdateWithAggregationPipeline = UpdateAggregationStage[];
2147
2042
  type UpdateAggregationStage = { $addFields: any } |
2148
- { $set: any } |
2149
- { $project: any } |
2150
- { $unset: any } |
2151
- { $replaceRoot: any } |
2152
- { $replaceWith: any };
2043
+ { $set: any } |
2044
+ { $project: any } |
2045
+ { $unset: any } |
2046
+ { $replaceRoot: any } |
2047
+ { $replaceWith: any };
2153
2048
 
2154
2049
  type __UpdateDefProperty<T> =
2155
2050
  [Extract<T, mongodb.ObjectId>] extends [never] ? T :
2156
- T | string;
2051
+ T | string;
2157
2052
  type _UpdateQueryDef<T> = {
2158
2053
  [K in keyof T]?: __UpdateDefProperty<T[K]>;
2159
2054
  };
@@ -2169,28 +2064,28 @@ declare module 'mongoose' {
2169
2064
 
2170
2065
  export type DocumentDefinition<T> = {
2171
2066
  [K in keyof Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>>]:
2172
- [Extract<T[K], mongodb.ObjectId>] extends [never]
2067
+ [Extract<T[K], mongodb.ObjectId>] extends [never]
2173
2068
  ? T[K] extends TreatAsPrimitives
2174
2069
  ? T[K]
2175
2070
  : LeanDocumentElement<T[K]>
2176
2071
  : T[K] | string;
2177
- };
2072
+ };
2178
2073
 
2179
2074
  export type FlattenMaps<T> = {
2180
2075
  [K in keyof T]: T[K] extends Map<any, any>
2181
2076
  ? AnyObject : T[K] extends TreatAsPrimitives
2182
- ? T[K] : FlattenMaps<T[K]>;
2077
+ ? T[K] : FlattenMaps<T[K]>;
2183
2078
  };
2184
2079
 
2185
2080
  type actualPrimitives = string | boolean | number | bigint | symbol | null | undefined;
2186
2081
  type TreatAsPrimitives = actualPrimitives |
2187
- NativeDate | RegExp | symbol | Error | BigInt | Types.ObjectId;
2082
+ NativeDate | RegExp | symbol | Error | BigInt | Types.ObjectId;
2188
2083
 
2189
2084
  type LeanType<T> =
2190
2085
  0 extends (1 & T) ? T : // any
2191
- T extends TreatAsPrimitives ? T : // primitives
2192
- T extends Types.Subdocument ? Omit<LeanDocument<T>, '$isSingleNested' | 'ownerDocument' | 'parent'> : // subdocs
2193
- LeanDocument<T>; // Documents and everything else
2086
+ T extends TreatAsPrimitives ? T : // primitives
2087
+ T extends Types.Subdocument ? Omit<LeanDocument<T>, '$isSingleNested' | 'ownerDocument' | 'parent'> : // subdocs
2088
+ LeanDocument<T>; // Documents and everything else
2194
2089
 
2195
2090
  type LeanArray<T extends unknown[]> = T extends unknown[][] ? LeanArray<T[number]>[] : LeanType<T[number]>[];
2196
2091
 
@@ -2203,8 +2098,8 @@ declare module 'mongoose' {
2203
2098
  // This is required for PopulatedDoc.
2204
2099
  type LeanDocumentElement<T> =
2205
2100
  T extends unknown[] ? LeanArray<T> : // Array
2206
- T extends Document ? LeanDocument<T> : // Subdocument
2207
- T;
2101
+ T extends Document ? LeanDocument<T> : // Subdocument
2102
+ T;
2208
2103
 
2209
2104
  export type SchemaDefinitionType<T> = T extends Document ? Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>> : T;
2210
2105
 
@@ -2217,13 +2112,13 @@ declare module 'mongoose' {
2217
2112
 
2218
2113
  export type LeanDocumentOrArray<T> = 0 extends (1 & T) ? T :
2219
2114
  T extends unknown[] ? LeanDocument<T[number]>[] :
2220
- T extends Document ? LeanDocument<T> :
2221
- T;
2115
+ T extends Document ? LeanDocument<T> :
2116
+ T;
2222
2117
 
2223
2118
  export type LeanDocumentOrArrayWithRawType<T, RawDocType> = 0 extends (1 & T) ? T :
2224
2119
  T extends unknown[] ? RawDocType[] :
2225
- T extends Document ? RawDocType :
2226
- T;
2120
+ T extends Document ? RawDocType :
2121
+ T;
2227
2122
 
2228
2123
  class Aggregate<R> {
2229
2124
  /**
@@ -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
+ }