mongoose 8.0.0 → 8.0.2
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/README.md +1 -1
- package/dist/browser.umd.js +1 -1
- package/lib/aggregate.js +1 -1
- package/lib/connection.js +4 -0
- package/lib/cursor/changeStream.js +3 -0
- package/lib/document.js +16 -3
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +6 -2
- package/lib/helpers/populate/assignVals.js +3 -2
- package/lib/helpers/populate/getModelsMapForPopulate.js +2 -1
- package/lib/model.js +6 -3
- package/lib/query.js +0 -1
- package/lib/schema/array.js +2 -2
- package/lib/schema/documentArray.js +2 -2
- package/lib/schema/subdocument.js +6 -4
- package/lib/schema.js +5 -5
- package/lib/schemaType.js +2 -0
- package/lib/stateMachine.js +5 -1
- package/lib/types/array/methods/index.js +12 -9
- package/lib/utils.js +23 -0
- package/package.json +9 -7
- package/types/document.d.ts +7 -1
- package/types/index.d.ts +3 -2
- package/types/inferschematype.d.ts +42 -5
- package/types/middlewares.d.ts +3 -1
- package/types/models.d.ts +27 -39
- package/types/query.d.ts +45 -54
- package/types/schemaoptions.d.ts +2 -2
- package/types/types.d.ts +3 -0
- package/types/utility.d.ts +22 -0
- package/types/validation.d.ts +1 -0
package/types/models.d.ts
CHANGED
|
@@ -26,6 +26,14 @@ declare module 'mongoose' {
|
|
|
26
26
|
interface MongooseBulkWriteOptions {
|
|
27
27
|
skipValidation?: boolean;
|
|
28
28
|
throwOnValidationError?: boolean;
|
|
29
|
+
timestamps?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface MongooseBulkWritePerWriteOptions {
|
|
33
|
+
timestamps?: boolean;
|
|
34
|
+
strict?: boolean;
|
|
35
|
+
session?: ClientSession;
|
|
36
|
+
skipValidation?: boolean;
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
interface InsertManyOptions extends
|
|
@@ -183,11 +191,17 @@ declare module 'mongoose' {
|
|
|
183
191
|
* round trip to the MongoDB server.
|
|
184
192
|
*/
|
|
185
193
|
bulkWrite<DocContents = TRawDocType>(
|
|
186
|
-
writes: Array<
|
|
194
|
+
writes: Array<
|
|
195
|
+
mongodb.AnyBulkWriteOperation<
|
|
196
|
+
DocContents extends mongodb.Document ? DocContents : any
|
|
197
|
+
> & MongooseBulkWritePerWriteOptions>,
|
|
187
198
|
options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions & { ordered: false }
|
|
188
199
|
): Promise<mongodb.BulkWriteResult & { mongoose?: { validationErrors: Error[] } }>;
|
|
189
200
|
bulkWrite<DocContents = TRawDocType>(
|
|
190
|
-
writes: Array<
|
|
201
|
+
writes: Array<
|
|
202
|
+
mongodb.AnyBulkWriteOperation<
|
|
203
|
+
DocContents extends mongodb.Document ? DocContents : any
|
|
204
|
+
> & MongooseBulkWritePerWriteOptions>,
|
|
191
205
|
options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions
|
|
192
206
|
): Promise<mongodb.BulkWriteResult>;
|
|
193
207
|
|
|
@@ -201,15 +215,6 @@ declare module 'mongoose' {
|
|
|
201
215
|
/** Collection the model uses. */
|
|
202
216
|
collection: Collection;
|
|
203
217
|
|
|
204
|
-
/** Creates a `count` query: counts the number of documents that match `filter`. */
|
|
205
|
-
count(filter?: FilterQuery<TRawDocType>): QueryWithHelpers<
|
|
206
|
-
number,
|
|
207
|
-
THydratedDocumentType,
|
|
208
|
-
TQueryHelpers,
|
|
209
|
-
TRawDocType,
|
|
210
|
-
'count'
|
|
211
|
-
>;
|
|
212
|
-
|
|
213
218
|
/** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
|
|
214
219
|
countDocuments(
|
|
215
220
|
filter?: FilterQuery<TRawDocType>,
|
|
@@ -461,8 +466,9 @@ declare module 'mongoose' {
|
|
|
461
466
|
|
|
462
467
|
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
|
|
463
468
|
validate(): Promise<void>;
|
|
464
|
-
validate(
|
|
465
|
-
validate(
|
|
469
|
+
validate(obj: any): Promise<void>;
|
|
470
|
+
validate(obj: any, pathsOrOptions: PathsToValidate): Promise<void>;
|
|
471
|
+
validate(obj: any, pathsOrOptions: { pathsToSkip?: pathsToSkip }): Promise<void>;
|
|
466
472
|
|
|
467
473
|
/** Watches the underlying collection for changes using [MongoDB change streams](https://www.mongodb.com/docs/manual/changeStreams/). */
|
|
468
474
|
watch<ResultType extends mongodb.Document = any, ChangeType extends mongodb.ChangeStreamDocument = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions & { hydrate?: boolean }): mongodb.ChangeStream<ResultType, ChangeType>;
|
|
@@ -481,7 +487,7 @@ declare module 'mongoose' {
|
|
|
481
487
|
field: DocKey,
|
|
482
488
|
filter?: FilterQuery<TRawDocType>
|
|
483
489
|
): QueryWithHelpers<
|
|
484
|
-
Array<DocKey extends keyof TRawDocType ? TRawDocType[DocKey] : ResultType>,
|
|
490
|
+
Array<DocKey extends keyof TRawDocType ? Unpacked<TRawDocType[DocKey]> : ResultType>,
|
|
485
491
|
THydratedDocumentType,
|
|
486
492
|
TQueryHelpers,
|
|
487
493
|
TRawDocType,
|
|
@@ -551,21 +557,9 @@ declare module 'mongoose' {
|
|
|
551
557
|
>;
|
|
552
558
|
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
553
559
|
id?: mongodb.ObjectId | any,
|
|
554
|
-
options?: QueryOptions<TRawDocType>
|
|
555
|
-
): QueryWithHelpers<ResultDoc
|
|
556
|
-
|
|
557
|
-
/** Creates a `findByIdAndRemove` query, filtering by the given `_id`. */
|
|
558
|
-
findByIdAndRemove<ResultDoc = THydratedDocumentType>(
|
|
559
|
-
id: mongodb.ObjectId | any,
|
|
560
|
-
options: QueryOptions<TRawDocType> & { lean: true }
|
|
561
|
-
): QueryWithHelpers<
|
|
562
|
-
GetLeanResultType<TRawDocType, TRawDocType, 'findOneAndDelete'> | null,
|
|
563
|
-
ResultDoc,
|
|
564
|
-
TQueryHelpers,
|
|
565
|
-
TRawDocType,
|
|
566
|
-
'findOneAndDelete'
|
|
567
|
-
>;
|
|
568
|
-
findByIdAndRemove<ResultDoc = THydratedDocumentType>(
|
|
560
|
+
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
561
|
+
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
562
|
+
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
569
563
|
id?: mongodb.ObjectId | any,
|
|
570
564
|
options?: QueryOptions<TRawDocType> | null
|
|
571
565
|
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
@@ -587,11 +581,6 @@ declare module 'mongoose' {
|
|
|
587
581
|
update: UpdateQuery<TRawDocType>,
|
|
588
582
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
589
583
|
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate'>;
|
|
590
|
-
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
591
|
-
id: mongodb.ObjectId | any,
|
|
592
|
-
update: UpdateQuery<TRawDocType>,
|
|
593
|
-
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
594
|
-
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate'>;
|
|
595
584
|
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
596
585
|
id: mongodb.ObjectId | any,
|
|
597
586
|
update: UpdateQuery<TRawDocType>,
|
|
@@ -618,6 +607,10 @@ declare module 'mongoose' {
|
|
|
618
607
|
TRawDocType,
|
|
619
608
|
'findOneAndDelete'
|
|
620
609
|
>;
|
|
610
|
+
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
611
|
+
filter?: FilterQuery<TRawDocType>,
|
|
612
|
+
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
613
|
+
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
621
614
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
622
615
|
filter?: FilterQuery<TRawDocType>,
|
|
623
616
|
options?: QueryOptions<TRawDocType> | null
|
|
@@ -640,11 +633,6 @@ declare module 'mongoose' {
|
|
|
640
633
|
replacement: TRawDocType | AnyObject,
|
|
641
634
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
642
635
|
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndReplace'>;
|
|
643
|
-
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
644
|
-
filter: FilterQuery<TRawDocType>,
|
|
645
|
-
replacement: TRawDocType | AnyObject,
|
|
646
|
-
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
647
|
-
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndReplace'>;
|
|
648
636
|
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
649
637
|
filter: FilterQuery<TRawDocType>,
|
|
650
638
|
replacement: TRawDocType | AnyObject,
|
package/types/query.d.ts
CHANGED
|
@@ -212,7 +212,7 @@ declare module 'mongoose' {
|
|
|
212
212
|
allowDiskUse(value: boolean): this;
|
|
213
213
|
|
|
214
214
|
/** Specifies arguments for an `$and` condition. */
|
|
215
|
-
and(array: FilterQuery<
|
|
215
|
+
and(array: FilterQuery<RawDocType>[]): this;
|
|
216
216
|
|
|
217
217
|
/** Specifies the batchSize option. */
|
|
218
218
|
batchSize(val: number): this;
|
|
@@ -259,18 +259,9 @@ declare module 'mongoose' {
|
|
|
259
259
|
/** Specifies the `comment` option. */
|
|
260
260
|
comment(val: string): this;
|
|
261
261
|
|
|
262
|
-
/** Specifies this query as a `count` query. */
|
|
263
|
-
count(criteria?: FilterQuery<DocType>): QueryWithHelpers<
|
|
264
|
-
number,
|
|
265
|
-
DocType,
|
|
266
|
-
THelpers,
|
|
267
|
-
RawDocType,
|
|
268
|
-
'count'
|
|
269
|
-
>;
|
|
270
|
-
|
|
271
262
|
/** Specifies this query as a `countDocuments` query. */
|
|
272
263
|
countDocuments(
|
|
273
|
-
criteria?: FilterQuery<
|
|
264
|
+
criteria?: FilterQuery<RawDocType>,
|
|
274
265
|
options?: QueryOptions<DocType>
|
|
275
266
|
): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments'>;
|
|
276
267
|
|
|
@@ -286,10 +277,10 @@ declare module 'mongoose' {
|
|
|
286
277
|
* collection, regardless of the value of `single`.
|
|
287
278
|
*/
|
|
288
279
|
deleteMany(
|
|
289
|
-
filter?: FilterQuery<
|
|
280
|
+
filter?: FilterQuery<RawDocType>,
|
|
290
281
|
options?: QueryOptions<DocType>
|
|
291
282
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany'>;
|
|
292
|
-
deleteMany(filter: FilterQuery<
|
|
283
|
+
deleteMany(filter: FilterQuery<RawDocType>): QueryWithHelpers<
|
|
293
284
|
any,
|
|
294
285
|
DocType,
|
|
295
286
|
THelpers,
|
|
@@ -304,10 +295,10 @@ declare module 'mongoose' {
|
|
|
304
295
|
* option.
|
|
305
296
|
*/
|
|
306
297
|
deleteOne(
|
|
307
|
-
filter?: FilterQuery<
|
|
298
|
+
filter?: FilterQuery<RawDocType>,
|
|
308
299
|
options?: QueryOptions<DocType>
|
|
309
300
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne'>;
|
|
310
|
-
deleteOne(filter: FilterQuery<
|
|
301
|
+
deleteOne(filter: FilterQuery<RawDocType>): QueryWithHelpers<
|
|
311
302
|
any,
|
|
312
303
|
DocType,
|
|
313
304
|
THelpers,
|
|
@@ -319,8 +310,8 @@ declare module 'mongoose' {
|
|
|
319
310
|
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
|
|
320
311
|
distinct<DocKey extends string, ResultType = unknown>(
|
|
321
312
|
field: DocKey,
|
|
322
|
-
filter?: FilterQuery<
|
|
323
|
-
): QueryWithHelpers<Array<DocKey extends keyof DocType ? DocType[DocKey] : ResultType>, DocType, THelpers, RawDocType, 'distinct'>;
|
|
313
|
+
filter?: FilterQuery<RawDocType>
|
|
314
|
+
): QueryWithHelpers<Array<DocKey extends keyof DocType ? Unpacked<DocType[DocKey]> : ResultType>, DocType, THelpers, RawDocType, 'distinct'>;
|
|
324
315
|
|
|
325
316
|
/** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
326
317
|
elemMatch<K = string>(path: K, val: any): this;
|
|
@@ -359,65 +350,65 @@ declare module 'mongoose' {
|
|
|
359
350
|
|
|
360
351
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
361
352
|
find(
|
|
362
|
-
filter: FilterQuery<
|
|
363
|
-
projection?: ProjectionType<
|
|
353
|
+
filter: FilterQuery<RawDocType>,
|
|
354
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
364
355
|
options?: QueryOptions<DocType> | null
|
|
365
356
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
366
357
|
find(
|
|
367
|
-
filter: FilterQuery<
|
|
368
|
-
projection?: ProjectionType<
|
|
358
|
+
filter: FilterQuery<RawDocType>,
|
|
359
|
+
projection?: ProjectionType<RawDocType> | null
|
|
369
360
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
370
361
|
find(
|
|
371
|
-
filter: FilterQuery<
|
|
372
|
-
): QueryWithHelpers<Array<
|
|
362
|
+
filter: FilterQuery<RawDocType>
|
|
363
|
+
): QueryWithHelpers<Array<RawDocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
373
364
|
find(): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
374
365
|
|
|
375
366
|
/** Declares the query a findOne operation. When executed, returns the first found document. */
|
|
376
367
|
findOne(
|
|
377
|
-
filter?: FilterQuery<
|
|
378
|
-
projection?: ProjectionType<
|
|
368
|
+
filter?: FilterQuery<RawDocType>,
|
|
369
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
379
370
|
options?: QueryOptions<DocType> | null
|
|
380
371
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
381
372
|
findOne(
|
|
382
|
-
filter?: FilterQuery<
|
|
383
|
-
projection?: ProjectionType<
|
|
373
|
+
filter?: FilterQuery<RawDocType>,
|
|
374
|
+
projection?: ProjectionType<RawDocType> | null
|
|
384
375
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
385
376
|
findOne(
|
|
386
|
-
filter?: FilterQuery<
|
|
387
|
-
): QueryWithHelpers<DocType | null,
|
|
377
|
+
filter?: FilterQuery<RawDocType>
|
|
378
|
+
): QueryWithHelpers<DocType | null, RawDocType, THelpers, RawDocType, 'findOne'>;
|
|
388
379
|
|
|
389
380
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
390
381
|
findOneAndDelete(
|
|
391
|
-
filter?: FilterQuery<
|
|
382
|
+
filter?: FilterQuery<RawDocType>,
|
|
392
383
|
options?: QueryOptions<DocType> | null
|
|
393
384
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
|
|
394
385
|
|
|
395
386
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
396
387
|
findOneAndUpdate(
|
|
397
|
-
filter: FilterQuery<
|
|
398
|
-
update: UpdateQuery<
|
|
388
|
+
filter: FilterQuery<RawDocType>,
|
|
389
|
+
update: UpdateQuery<RawDocType>,
|
|
399
390
|
options: QueryOptions<DocType> & { includeResultMetadata: true }
|
|
400
391
|
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
401
392
|
findOneAndUpdate(
|
|
402
|
-
filter: FilterQuery<
|
|
403
|
-
update: UpdateQuery<
|
|
393
|
+
filter: FilterQuery<RawDocType>,
|
|
394
|
+
update: UpdateQuery<RawDocType>,
|
|
404
395
|
options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
|
|
405
396
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
406
397
|
findOneAndUpdate(
|
|
407
|
-
filter?: FilterQuery<
|
|
408
|
-
update?: UpdateQuery<
|
|
398
|
+
filter?: FilterQuery<RawDocType>,
|
|
399
|
+
update?: UpdateQuery<RawDocType>,
|
|
409
400
|
options?: QueryOptions<DocType> | null
|
|
410
401
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
411
402
|
|
|
412
403
|
/** Declares the query a findById operation. When executed, returns the document with the given `_id`. */
|
|
413
404
|
findById(
|
|
414
405
|
id: mongodb.ObjectId | any,
|
|
415
|
-
projection?: ProjectionType<
|
|
406
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
416
407
|
options?: QueryOptions<DocType> | null
|
|
417
408
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
418
409
|
findById(
|
|
419
410
|
id: mongodb.ObjectId | any,
|
|
420
|
-
projection?: ProjectionType<
|
|
411
|
+
projection?: ProjectionType<RawDocType> | null
|
|
421
412
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
422
413
|
findById(
|
|
423
414
|
id: mongodb.ObjectId | any
|
|
@@ -432,22 +423,22 @@ declare module 'mongoose' {
|
|
|
432
423
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
433
424
|
findByIdAndUpdate(
|
|
434
425
|
id: mongodb.ObjectId | any,
|
|
435
|
-
update: UpdateQuery<
|
|
426
|
+
update: UpdateQuery<RawDocType>,
|
|
436
427
|
options: QueryOptions<DocType> & { includeResultMetadata: true }
|
|
437
428
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
438
429
|
findByIdAndUpdate(
|
|
439
430
|
id: mongodb.ObjectId | any,
|
|
440
|
-
update: UpdateQuery<
|
|
431
|
+
update: UpdateQuery<RawDocType>,
|
|
441
432
|
options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
|
|
442
433
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
443
434
|
findByIdAndUpdate(
|
|
444
435
|
id?: mongodb.ObjectId | any,
|
|
445
|
-
update?: UpdateQuery<
|
|
436
|
+
update?: UpdateQuery<RawDocType>,
|
|
446
437
|
options?: QueryOptions<DocType> | null
|
|
447
438
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
448
439
|
findByIdAndUpdate(
|
|
449
440
|
id: mongodb.ObjectId | any,
|
|
450
|
-
update: UpdateQuery<
|
|
441
|
+
update: UpdateQuery<RawDocType>
|
|
451
442
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
452
443
|
|
|
453
444
|
/** Specifies a `$geometry` condition */
|
|
@@ -461,7 +452,7 @@ declare module 'mongoose' {
|
|
|
461
452
|
get(path: string): any;
|
|
462
453
|
|
|
463
454
|
/** Returns the current query filter (also known as conditions) as a POJO. */
|
|
464
|
-
getFilter(): FilterQuery<
|
|
455
|
+
getFilter(): FilterQuery<RawDocType>;
|
|
465
456
|
|
|
466
457
|
/** Gets query options. */
|
|
467
458
|
getOptions(): QueryOptions<DocType>;
|
|
@@ -470,7 +461,7 @@ declare module 'mongoose' {
|
|
|
470
461
|
getPopulatedPaths(): Array<string>;
|
|
471
462
|
|
|
472
463
|
/** Returns the current query filter. Equivalent to `getFilter()`. */
|
|
473
|
-
getQuery(): FilterQuery<
|
|
464
|
+
getQuery(): FilterQuery<RawDocType>;
|
|
474
465
|
|
|
475
466
|
/** Returns the current update operations as a JSON object. */
|
|
476
467
|
getUpdate(): UpdateQuery<DocType> | UpdateWithAggregationPipeline | null;
|
|
@@ -540,7 +531,7 @@ declare module 'mongoose' {
|
|
|
540
531
|
maxTimeMS(ms: number): this;
|
|
541
532
|
|
|
542
533
|
/** Merges another Query or conditions object into this one. */
|
|
543
|
-
merge(source: Query<any, any> | FilterQuery<
|
|
534
|
+
merge(source: Query<any, any> | FilterQuery<RawDocType>): this;
|
|
544
535
|
|
|
545
536
|
/** Specifies a `$mod` condition, filters documents for documents whose `path` property is a number that is equal to `remainder` modulo `divisor`. */
|
|
546
537
|
mod<K = string>(path: K, val: number): this;
|
|
@@ -568,10 +559,10 @@ declare module 'mongoose' {
|
|
|
568
559
|
nin(val: Array<any>): this;
|
|
569
560
|
|
|
570
561
|
/** Specifies arguments for an `$nor` condition. */
|
|
571
|
-
nor(array: Array<FilterQuery<
|
|
562
|
+
nor(array: Array<FilterQuery<RawDocType>>): this;
|
|
572
563
|
|
|
573
564
|
/** Specifies arguments for an `$or` condition. */
|
|
574
|
-
or(array: Array<FilterQuery<
|
|
565
|
+
or(array: Array<FilterQuery<RawDocType>>): this;
|
|
575
566
|
|
|
576
567
|
/**
|
|
577
568
|
* Make this query throw an error if no documents match the given `filter`.
|
|
@@ -628,7 +619,7 @@ declare module 'mongoose' {
|
|
|
628
619
|
* not accept any [atomic](https://www.mongodb.com/docs/manual/tutorial/model-data-for-atomic-operations/#pattern) operators (`$set`, etc.)
|
|
629
620
|
*/
|
|
630
621
|
replaceOne(
|
|
631
|
-
filter?: FilterQuery<
|
|
622
|
+
filter?: FilterQuery<RawDocType>,
|
|
632
623
|
replacement?: DocType | AnyObject,
|
|
633
624
|
options?: QueryOptions<DocType> | null
|
|
634
625
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne'>;
|
|
@@ -687,9 +678,9 @@ declare module 'mongoose' {
|
|
|
687
678
|
setOptions(options: QueryOptions<DocType>, overwrite?: boolean): this;
|
|
688
679
|
|
|
689
680
|
/** Sets the query conditions to the provided JSON object. */
|
|
690
|
-
setQuery(val: FilterQuery<
|
|
681
|
+
setQuery(val: FilterQuery<RawDocType> | null): void;
|
|
691
682
|
|
|
692
|
-
setUpdate(update: UpdateQuery<
|
|
683
|
+
setUpdate(update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline): void;
|
|
693
684
|
|
|
694
685
|
/** Specifies an `$size` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
695
686
|
size<K = string>(path: K, val: number): this;
|
|
@@ -727,8 +718,8 @@ declare module 'mongoose' {
|
|
|
727
718
|
* the `multi` option.
|
|
728
719
|
*/
|
|
729
720
|
updateMany(
|
|
730
|
-
filter?: FilterQuery<
|
|
731
|
-
update?: UpdateQuery<
|
|
721
|
+
filter?: FilterQuery<RawDocType>,
|
|
722
|
+
update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
732
723
|
options?: QueryOptions<DocType> | null
|
|
733
724
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany'>;
|
|
734
725
|
|
|
@@ -737,8 +728,8 @@ declare module 'mongoose' {
|
|
|
737
728
|
* `update()`, except it does not support the `multi` or `overwrite` options.
|
|
738
729
|
*/
|
|
739
730
|
updateOne(
|
|
740
|
-
filter?: FilterQuery<
|
|
741
|
-
update?: UpdateQuery<
|
|
731
|
+
filter?: FilterQuery<RawDocType>,
|
|
732
|
+
update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
742
733
|
options?: QueryOptions<DocType> | null
|
|
743
734
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne'>;
|
|
744
735
|
|
package/types/schemaoptions.d.ts
CHANGED
|
@@ -210,7 +210,7 @@ declare module 'mongoose' {
|
|
|
210
210
|
TStaticMethods,
|
|
211
211
|
{},
|
|
212
212
|
{ [name: string]: (this: Model<DocType>, ...args: any[]) => unknown },
|
|
213
|
-
|
|
213
|
+
AddThisParameter<TStaticMethods, Model<DocType>>
|
|
214
214
|
>
|
|
215
215
|
|
|
216
216
|
/**
|
|
@@ -220,7 +220,7 @@ declare module 'mongoose' {
|
|
|
220
220
|
TInstanceMethods,
|
|
221
221
|
{},
|
|
222
222
|
Record<any, (this: THydratedDocumentType, ...args: any) => unknown>,
|
|
223
|
-
TInstanceMethods
|
|
223
|
+
AddThisParameter<TInstanceMethods, THydratedDocumentType> & AnyObject
|
|
224
224
|
>
|
|
225
225
|
|
|
226
226
|
/**
|
package/types/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
declare module 'mongoose' {
|
|
3
3
|
import mongodb = require('mongodb');
|
|
4
|
+
import bson = require('bson');
|
|
4
5
|
|
|
5
6
|
class NativeBuffer extends Buffer {}
|
|
6
7
|
|
|
@@ -99,5 +100,7 @@ declare module 'mongoose' {
|
|
|
99
100
|
/** Returns this sub-documents parent array. */
|
|
100
101
|
parentArray(): Types.DocumentArray<unknown>;
|
|
101
102
|
}
|
|
103
|
+
|
|
104
|
+
class UUID extends bson.UUID {}
|
|
102
105
|
}
|
|
103
106
|
}
|
package/types/utility.d.ts
CHANGED
|
@@ -40,4 +40,26 @@ type IfEquals<T, U, Y = true, N = false> =
|
|
|
40
40
|
(<G>() => G extends T ? 1 : 0) extends
|
|
41
41
|
(<G>() => G extends U ? 1 : 0) ? Y : N;
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @summary Extracts 'this' parameter from a function, if it exists. Otherwise, returns fallback.
|
|
45
|
+
* @param {T} T Function type to extract 'this' parameter from.
|
|
46
|
+
* @param {F} F Fallback type to return if 'this' parameter does not exist.
|
|
47
|
+
*/
|
|
48
|
+
type ThisParameter<T, F> = T extends { (this: infer This): void }
|
|
49
|
+
? This
|
|
50
|
+
: F;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @summary Decorates all functions in an object with 'this' parameter.
|
|
54
|
+
* @param {T} T Object with functions as values to add 'D' parameter to as 'this'. {@link D}
|
|
55
|
+
* @param {D} D The type to be added as 'this' parameter to all functions in {@link T}.
|
|
56
|
+
*/
|
|
57
|
+
type AddThisParameter<T, D> = {
|
|
58
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R
|
|
59
|
+
? ThisParameter<T[K], unknown> extends unknown
|
|
60
|
+
? (this: D, ...args: A) => R
|
|
61
|
+
: T[K]
|
|
62
|
+
: T[K];
|
|
63
|
+
};
|
|
64
|
+
|
|
43
65
|
}
|