mongoose 8.20.1 → 8.20.3
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/dist/browser.umd.js +1 -1
- package/lib/aggregate.js +1 -1
- package/lib/cast.js +1 -1
- package/lib/connection.js +9 -9
- package/lib/document.js +58 -17
- package/lib/drivers/node-mongodb-native/connection.js +2 -2
- package/lib/error/objectParameter.js +1 -1
- package/lib/helpers/common.js +1 -1
- package/lib/helpers/indexes/applySchemaCollation.js +1 -1
- package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
- package/lib/helpers/model/applyMethods.js +1 -1
- package/lib/helpers/model/castBulkWrite.js +13 -6
- package/lib/helpers/populate/getModelsMapForPopulate.js +3 -3
- package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
- package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
- package/lib/helpers/projection/applyProjection.js +2 -2
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +2 -2
- package/lib/helpers/timestamps/setupTimestamps.js +1 -1
- package/lib/helpers/update/applyTimestampsToUpdate.js +38 -25
- package/lib/helpers/update/decorateUpdateWithVersionKey.js +1 -1
- package/lib/model.js +12 -15
- package/lib/mongoose.js +3 -4
- package/lib/query.js +3 -3
- package/lib/schema/array.js +1 -1
- package/lib/schema.js +21 -21
- package/lib/schemaType.js +8 -8
- package/lib/types/array/index.js +5 -5
- package/lib/types/documentArray/index.js +6 -6
- package/lib/types/objectid.js +1 -1
- package/lib/utils.js +1 -15
- package/lib/virtualType.js +1 -1
- package/package.json +3 -1
- package/types/index.d.ts +1 -1
- package/types/inferrawdoctype.d.ts +1 -1
- package/types/inferschematype.d.ts +16 -23
- package/types/models.d.ts +38 -85
- package/types/virtuals.d.ts +3 -3
package/types/models.d.ts
CHANGED
|
@@ -172,94 +172,47 @@ declare module 'mongoose' {
|
|
|
172
172
|
|
|
173
173
|
interface RemoveOptions extends SessionOption, Omit<mongodb.DeleteOptions, 'session'> {}
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
insertOne: InsertOneModel<TSchema>;
|
|
179
|
-
} | {
|
|
180
|
-
replaceOne: ReplaceOneModel<TSchema>;
|
|
181
|
-
} | {
|
|
182
|
-
updateOne: UpdateOneModel<TSchema>;
|
|
183
|
-
} | {
|
|
184
|
-
updateMany: UpdateManyModel<TSchema>;
|
|
185
|
-
} | {
|
|
186
|
-
deleteOne: DeleteOneModel<TSchema>;
|
|
187
|
-
} | {
|
|
188
|
-
deleteMany: DeleteManyModel<TSchema>;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export interface InsertOneModel<TSchema> {
|
|
192
|
-
document: mongodb.OptionalId<TSchema>;
|
|
175
|
+
interface MongooseBulkWritePerOperationOptions {
|
|
176
|
+
/** Skip validation for this operation. */
|
|
177
|
+
skipValidation?: boolean;
|
|
193
178
|
/** When false, do not add timestamps. When true, overrides the `timestamps` option set in the `bulkWrite` options. */
|
|
194
179
|
timestamps?: boolean;
|
|
195
180
|
}
|
|
196
181
|
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
|
|
202
|
-
/** Specifies a collation. */
|
|
203
|
-
collation?: mongodb.CollationOptions;
|
|
204
|
-
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
205
|
-
hint?: mongodb.Hint;
|
|
206
|
-
/** When true, creates a new document if no document matches the query. */
|
|
207
|
-
upsert?: boolean;
|
|
208
|
-
/** When false, do not add timestamps. When true, overrides the `timestamps` option set in the `bulkWrite` options. */
|
|
209
|
-
timestamps?: boolean;
|
|
182
|
+
interface MongooseBulkUpdatePerOperationOptions extends MongooseBulkWritePerOperationOptions {
|
|
183
|
+
/** When true, allows updating fields that are marked as `immutable` in the schema. */
|
|
184
|
+
overwriteImmutable?: boolean;
|
|
185
|
+
/** When false, do not set default values on insert. */
|
|
186
|
+
setDefaultsOnInsert?: boolean;
|
|
210
187
|
}
|
|
211
188
|
|
|
212
|
-
export
|
|
213
|
-
|
|
214
|
-
filter: RootFilterQuery<TSchema>;
|
|
215
|
-
/** A document or pipeline containing update operators. */
|
|
216
|
-
update: UpdateQuery<TSchema>;
|
|
217
|
-
/** A set of filters specifying to which array elements an update should apply. */
|
|
218
|
-
arrayFilters?: AnyObject[];
|
|
219
|
-
/** Specifies a collation. */
|
|
220
|
-
collation?: mongodb.CollationOptions;
|
|
221
|
-
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
222
|
-
hint?: mongodb.Hint;
|
|
223
|
-
/** When true, creates a new document if no document matches the query. */
|
|
224
|
-
upsert?: boolean;
|
|
225
|
-
/** When false, do not add timestamps. When true, overrides the `timestamps` option set in the `bulkWrite` options. */
|
|
226
|
-
timestamps?: boolean;
|
|
227
|
-
}
|
|
189
|
+
export type InsertOneModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
190
|
+
mongodb.InsertOneModel<TSchema> & MongooseBulkWritePerOperationOptions;
|
|
228
191
|
|
|
229
|
-
export
|
|
230
|
-
|
|
231
|
-
filter: RootFilterQuery<TSchema>;
|
|
232
|
-
/** A document or pipeline containing update operators. */
|
|
233
|
-
update: UpdateQuery<TSchema>;
|
|
234
|
-
/** A set of filters specifying to which array elements an update should apply. */
|
|
235
|
-
arrayFilters?: AnyObject[];
|
|
236
|
-
/** Specifies a collation. */
|
|
237
|
-
collation?: mongodb.CollationOptions;
|
|
238
|
-
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
239
|
-
hint?: mongodb.Hint;
|
|
240
|
-
/** When true, creates a new document if no document matches the query. */
|
|
241
|
-
upsert?: boolean;
|
|
242
|
-
/** When false, do not add timestamps. When true, overrides the `timestamps` option set in the `bulkWrite` options. */
|
|
243
|
-
timestamps?: boolean;
|
|
244
|
-
}
|
|
192
|
+
export type ReplaceOneModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
193
|
+
mongodb.ReplaceOneModel<TSchema> & MongooseBulkWritePerOperationOptions;
|
|
245
194
|
|
|
246
|
-
export
|
|
247
|
-
|
|
248
|
-
filter: RootFilterQuery<TSchema>;
|
|
249
|
-
/** Specifies a collation. */
|
|
250
|
-
collation?: mongodb.CollationOptions;
|
|
251
|
-
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
252
|
-
hint?: mongodb.Hint;
|
|
253
|
-
}
|
|
195
|
+
export type UpdateOneModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
196
|
+
mongodb.UpdateOneModel<TSchema> & MongooseBulkUpdatePerOperationOptions;
|
|
254
197
|
|
|
255
|
-
export
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
198
|
+
export type UpdateManyModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
199
|
+
mongodb.UpdateManyModel<TSchema> & MongooseBulkUpdatePerOperationOptions;
|
|
200
|
+
|
|
201
|
+
export type DeleteOneModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
202
|
+
mongodb.DeleteOneModel<TSchema>;
|
|
203
|
+
|
|
204
|
+
export type DeleteManyModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
205
|
+
mongodb.DeleteManyModel<TSchema>;
|
|
206
|
+
|
|
207
|
+
export type AnyBulkWriteOperation<TSchema extends mongodb.Document = mongodb.Document> =
|
|
208
|
+
| { insertOne: InsertOneModel<TSchema> }
|
|
209
|
+
| { replaceOne: ReplaceOneModel<TSchema> }
|
|
210
|
+
| { updateOne: UpdateOneModel<TSchema> }
|
|
211
|
+
| { updateMany: UpdateManyModel<TSchema> }
|
|
212
|
+
| { deleteOne: DeleteOneModel<TSchema> }
|
|
213
|
+
| { deleteMany: DeleteManyModel<TSchema> };
|
|
214
|
+
|
|
215
|
+
const Model: Model<any>;
|
|
263
216
|
|
|
264
217
|
type HasLeanOption<TSchema> = 'lean' extends keyof ObtainSchemaGeneric<TSchema, 'TSchemaOptions'> ?
|
|
265
218
|
ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>['lean'] extends Record<string, any> ?
|
|
@@ -319,13 +272,13 @@ declare module 'mongoose' {
|
|
|
319
272
|
* round trip to the MongoDB server.
|
|
320
273
|
*/
|
|
321
274
|
bulkWrite<DocContents = TRawDocType>(
|
|
322
|
-
writes: Array<AnyBulkWriteOperation<DocContents>>,
|
|
323
|
-
options: MongooseBulkWriteOptions & { ordered: false }
|
|
324
|
-
): Promise<
|
|
275
|
+
writes: Array<AnyBulkWriteOperation<DocContents extends mongodb.Document ? DocContents : any>>,
|
|
276
|
+
options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions & { ordered: false }
|
|
277
|
+
): Promise<mongodb.BulkWriteResult & { mongoose?: { validationErrors: Error[] } }>;
|
|
325
278
|
bulkWrite<DocContents = TRawDocType>(
|
|
326
|
-
writes: Array<AnyBulkWriteOperation<DocContents>>,
|
|
327
|
-
options?: MongooseBulkWriteOptions
|
|
328
|
-
): Promise<
|
|
279
|
+
writes: Array<AnyBulkWriteOperation<DocContents extends mongodb.Document ? DocContents : any>>,
|
|
280
|
+
options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions
|
|
281
|
+
): Promise<mongodb.BulkWriteResult>;
|
|
329
282
|
|
|
330
283
|
/**
|
|
331
284
|
* Sends multiple `save()` calls in a single `bulkWrite()`. This is faster than
|
package/types/virtuals.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare module 'mongoose' {
|
|
|
8
8
|
type TVirtualPathFN<DocType = {}, PathType = unknown, TInstanceMethods = {}, TReturn = unknown> =
|
|
9
9
|
<T = HydratedDocument<DocType, TInstanceMethods>>(this: Document<any, any, DocType> & DocType, value: PathType, virtual: VirtualType<T>, doc: Document<any, any, DocType> & DocType) => TReturn;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type SchemaOptionsVirtualsPropertyType<DocType = any, VirtualPaths = Record<any, unknown>, TInstanceMethods = {}> = {
|
|
12
|
+
[K in keyof VirtualPaths]: VirtualPathFunctions<IsItRecordAndNotAny<DocType> extends true ? DocType : any, VirtualPaths[K], TInstanceMethods>
|
|
13
|
+
};
|
|
14
14
|
}
|