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,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
+ }
File without changes
@@ -0,0 +1,189 @@
1
+ import mongodb = require('mongodb');
2
+
3
+ declare module 'mongoose' {
4
+
5
+ interface SchemaTimestampsConfig {
6
+ createdAt?: boolean | string;
7
+ updatedAt?: boolean | string;
8
+ currentTime?: () => (NativeDate | number);
9
+ }
10
+
11
+ interface SchemaOptions {
12
+ /**
13
+ * By default, Mongoose's init() function creates all the indexes defined in your model's schema by
14
+ * calling Model.createIndexes() after you successfully connect to MongoDB. If you want to disable
15
+ * automatic index builds, you can set autoIndex to false.
16
+ */
17
+ autoIndex?: boolean;
18
+ /**
19
+ * If set to `true`, Mongoose will call Model.createCollection() to create the underlying collection
20
+ * in MongoDB if autoCreate is set to true. Calling createCollection() sets the collection's default
21
+ * collation based on the collation option and establishes the collection as a capped collection if
22
+ * you set the capped schema option.
23
+ */
24
+ autoCreate?: boolean;
25
+ /**
26
+ * By default, mongoose buffers commands when the connection goes down until the driver manages to reconnect.
27
+ * To disable buffering, set bufferCommands to false.
28
+ */
29
+ bufferCommands?: boolean;
30
+ /**
31
+ * If bufferCommands is on, this option sets the maximum amount of time Mongoose buffering will wait before
32
+ * throwing an error. If not specified, Mongoose will use 10000 (10 seconds).
33
+ */
34
+ bufferTimeoutMS?: number;
35
+ /**
36
+ * Mongoose supports MongoDBs capped collections. To specify the underlying MongoDB collection be capped, set
37
+ * the capped option to the maximum size of the collection in bytes.
38
+ */
39
+ capped?: boolean | number | { size?: number; max?: number; autoIndexId?: boolean; };
40
+ /** Sets a default collation for every query and aggregation. */
41
+ collation?: mongodb.CollationOptions;
42
+
43
+ /** The timeseries option to use when creating the model's collection. */
44
+ timeseries?: mongodb.TimeSeriesCollectionOptions;
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
+
52
+ /**
53
+ * Mongoose by default produces a collection name by passing the model name to the utils.toCollectionName
54
+ * method. This method pluralizes the name. Set this option if you need a different name for your collection.
55
+ */
56
+ collection?: string;
57
+ /**
58
+ * When you define a [discriminator](/docs/discriminators.html), Mongoose adds a path to your
59
+ * schema that stores which discriminator a document is an instance of. By default, Mongoose
60
+ * adds an `__t` path, but you can set `discriminatorKey` to overwrite this default.
61
+ *
62
+ * @default '__t'
63
+ */
64
+ discriminatorKey?: string;
65
+
66
+ /**
67
+ * Option for nested Schemas.
68
+ *
69
+ * If true, skip building indexes on this schema's path.
70
+ *
71
+ * @default false
72
+ */
73
+ excludeIndexes?: boolean;
74
+ /**
75
+ * Mongoose assigns each of your schemas an id virtual getter by default which returns the document's _id field
76
+ * cast to a string, or in the case of ObjectIds, its hexString.
77
+ */
78
+ id?: boolean;
79
+ /**
80
+ * Mongoose assigns each of your schemas an _id field by default if one is not passed into the Schema
81
+ * constructor. The type assigned is an ObjectId to coincide with MongoDB's default behavior. If you
82
+ * don't want an _id added to your schema at all, you may disable it using this option.
83
+ */
84
+ _id?: boolean;
85
+ /**
86
+ * Mongoose will, by default, "minimize" schemas by removing empty objects. This behavior can be
87
+ * overridden by setting minimize option to false. It will then store empty objects.
88
+ */
89
+ minimize?: boolean;
90
+ /**
91
+ * Optimistic concurrency is a strategy to ensure the document you're updating didn't change between when you
92
+ * loaded it using find() or findOne(), and when you update it using save(). Set to `true` to enable
93
+ * optimistic concurrency.
94
+ */
95
+ optimisticConcurrency?: boolean;
96
+ /**
97
+ * If `plugin()` called with tags, Mongoose will only apply plugins to schemas that have
98
+ * a matching tag in `pluginTags`
99
+ */
100
+ pluginTags?: string[];
101
+ /**
102
+ * Allows setting query#read options at the schema level, providing us a way to apply default ReadPreferences
103
+ * to all queries derived from a model.
104
+ */
105
+ read?: string;
106
+ /** Allows setting write concern at the schema level. */
107
+ writeConcern?: WriteConcern;
108
+ /** defaults to true. */
109
+ safe?: boolean | { w?: number | string; wtimeout?: number; j?: boolean };
110
+ /**
111
+ * The shardKey option is used when we have a sharded MongoDB architecture. Each sharded collection is
112
+ * given a shard key which must be present in all insert/update operations. We just need to set this
113
+ * schema option to the same shard key and we'll be all set.
114
+ */
115
+ shardKey?: Record<string, unknown>;
116
+ /**
117
+ * The strict option, (enabled by default), ensures that values passed to our model constructor that were not
118
+ * specified in our schema do not get saved to the db.
119
+ */
120
+ strict?: boolean | 'throw';
121
+ /**
122
+ * equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default
123
+ * [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
124
+ */
125
+ strictQuery?: boolean | 'throw';
126
+ /** Exactly the same as the toObject option but only applies when the document's toJSON method is called. */
127
+ toJSON?: ToObjectOptions;
128
+ /**
129
+ * Documents have a toObject method which converts the mongoose document into a plain JavaScript object.
130
+ * This method accepts a few options. Instead of applying these options on a per-document basis, we may
131
+ * declare the options at the schema level and have them applied to all of the schema's documents by
132
+ * default.
133
+ */
134
+ toObject?: ToObjectOptions;
135
+ /**
136
+ * By default, if you have an object with key 'type' in your schema, mongoose will interpret it as a
137
+ * type declaration. However, for applications like geoJSON, the 'type' property is important. If you want to
138
+ * control which key mongoose uses to find type declarations, set the 'typeKey' schema option.
139
+ */
140
+ typeKey?: string;
141
+
142
+ /**
143
+ * By default, documents are automatically validated before they are saved to the database. This is to
144
+ * prevent saving an invalid document. If you want to handle validation manually, and be able to save
145
+ * objects which don't pass validation, you can set validateBeforeSave to false.
146
+ */
147
+ validateBeforeSave?: boolean;
148
+ /**
149
+ * The versionKey is a property set on each document when first created by Mongoose. This keys value
150
+ * contains the internal revision of the document. The versionKey option is a string that represents
151
+ * the path to use for versioning. The default is '__v'.
152
+ *
153
+ * @default '__v'
154
+ */
155
+ versionKey?: string | boolean;
156
+ /**
157
+ * By default, Mongoose will automatically select() any populated paths for you, unless you explicitly exclude them.
158
+ *
159
+ * @default true
160
+ */
161
+ selectPopulatedPaths?: boolean;
162
+ /**
163
+ * skipVersioning allows excluding paths from versioning (i.e., the internal revision will not be
164
+ * incremented even if these paths are updated). DO NOT do this unless you know what you're doing.
165
+ * For subdocuments, include this on the parent document using the fully qualified path.
166
+ */
167
+ skipVersioning?: {[key: string]: boolean; };
168
+ /**
169
+ * Validation errors in a single nested schema are reported
170
+ * both on the child and on the parent schema.
171
+ * Set storeSubdocValidationError to false on the child schema
172
+ * to make Mongoose only report the parent error.
173
+ */
174
+ storeSubdocValidationError?: boolean;
175
+ /**
176
+ * The timestamps option tells mongoose to assign createdAt and updatedAt fields to your schema. The type
177
+ * assigned is Date. By default, the names of the fields are createdAt and updatedAt. Customize the
178
+ * field names by setting timestamps.createdAt and timestamps.updatedAt.
179
+ */
180
+ timestamps?: boolean | SchemaTimestampsConfig;
181
+
182
+ /**
183
+ * Using `save`, `isNew`, and other Mongoose reserved names as schema path names now triggers a warning, not an error.
184
+ * You can suppress the warning by setting { supressReservedKeysWarning: true } schema options. Keep in mind that this
185
+ * can break plugins that rely on these reserved names.
186
+ */
187
+ supressReservedKeysWarning?: boolean
188
+ }
189
+ }