mongoose 9.0.0-rc1 → 9.0.1
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/lib/aggregate.js +1 -1
- package/lib/cast/double.js +1 -1
- package/lib/cast.js +1 -1
- package/lib/connection.js +10 -10
- package/lib/document.js +54 -17
- package/lib/drivers/node-mongodb-native/collection.js +16 -1
- package/lib/drivers/node-mongodb-native/connection.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 +8 -7
- package/lib/mongoose.js +3 -4
- package/lib/query.js +3 -3
- package/lib/schema/array.js +1 -1
- package/lib/schema/number.js +14 -2
- package/lib/schema/operators/text.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 +12 -24
- package/lib/virtualType.js +1 -1
- package/package.json +8 -7
- package/types/index.d.ts +1 -0
- package/types/models.d.ts +314 -86
- package/types/query.d.ts +91 -1
- package/types/utility.d.ts +2 -2
package/types/query.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare module 'mongoose' {
|
|
|
20
20
|
|
|
21
21
|
export type ApplyBasicQueryCasting<T> = QueryTypeCasting<T> | QueryTypeCasting<T[]> | (T extends (infer U)[] ? QueryTypeCasting<U> : T) | null;
|
|
22
22
|
|
|
23
|
-
type _QueryFilter<T> = ({ [P in keyof T]?: mongodb.Condition<ApplyBasicQueryCasting<T[P]>>; } & mongodb.RootFilterOperators<{ [P in keyof T]?: ApplyBasicQueryCasting<T[P]>; }>)
|
|
23
|
+
type _QueryFilter<T> = ({ [P in keyof T]?: mongodb.Condition<ApplyBasicQueryCasting<T[P]>>; } & mongodb.RootFilterOperators<{ [P in keyof T]?: ApplyBasicQueryCasting<T[P]>; }>);
|
|
24
24
|
type QueryFilter<T> = IsItRecordAndNotAny<T> extends true ? _QueryFilter<WithLevel1NestedPaths<T>> : _QueryFilter<Record<string, any>>;
|
|
25
25
|
|
|
26
26
|
type MongooseBaseQueryOptionKeys =
|
|
@@ -269,6 +269,10 @@ declare module 'mongoose' {
|
|
|
269
269
|
criteria?: QueryFilter<RawDocType>,
|
|
270
270
|
options?: QueryOptions<RawDocType>
|
|
271
271
|
): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments', TDocOverrides>;
|
|
272
|
+
countDocuments(
|
|
273
|
+
criteria?: Query<any, any>,
|
|
274
|
+
options?: QueryOptions<RawDocType>
|
|
275
|
+
): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments', TDocOverrides>;
|
|
272
276
|
|
|
273
277
|
/**
|
|
274
278
|
* Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html).
|
|
@@ -285,6 +289,10 @@ declare module 'mongoose' {
|
|
|
285
289
|
filter?: QueryFilter<RawDocType>,
|
|
286
290
|
options?: QueryOptions<RawDocType>
|
|
287
291
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TDocOverrides>;
|
|
292
|
+
deleteMany(
|
|
293
|
+
filter?: Query<any, any>,
|
|
294
|
+
options?: QueryOptions<RawDocType>
|
|
295
|
+
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TDocOverrides>;
|
|
288
296
|
deleteMany(filter: QueryFilter<RawDocType>): QueryWithHelpers<
|
|
289
297
|
any,
|
|
290
298
|
DocType,
|
|
@@ -293,6 +301,14 @@ declare module 'mongoose' {
|
|
|
293
301
|
'deleteMany',
|
|
294
302
|
TDocOverrides
|
|
295
303
|
>;
|
|
304
|
+
deleteMany(filter: Query<any, any>): QueryWithHelpers<
|
|
305
|
+
any,
|
|
306
|
+
DocType,
|
|
307
|
+
THelpers,
|
|
308
|
+
RawDocType,
|
|
309
|
+
'deleteMany',
|
|
310
|
+
TDocOverrides
|
|
311
|
+
>;
|
|
296
312
|
deleteMany(): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TDocOverrides>;
|
|
297
313
|
|
|
298
314
|
/**
|
|
@@ -304,6 +320,10 @@ declare module 'mongoose' {
|
|
|
304
320
|
filter?: QueryFilter<RawDocType>,
|
|
305
321
|
options?: QueryOptions<RawDocType>
|
|
306
322
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TDocOverrides>;
|
|
323
|
+
deleteOne(
|
|
324
|
+
filter?: Query<any, any>,
|
|
325
|
+
options?: QueryOptions<RawDocType>
|
|
326
|
+
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TDocOverrides>;
|
|
307
327
|
deleteOne(filter: QueryFilter<RawDocType>): QueryWithHelpers<
|
|
308
328
|
any,
|
|
309
329
|
DocType,
|
|
@@ -312,6 +332,14 @@ declare module 'mongoose' {
|
|
|
312
332
|
'deleteOne',
|
|
313
333
|
TDocOverrides
|
|
314
334
|
>;
|
|
335
|
+
deleteOne(filter: Query<any, any>): QueryWithHelpers<
|
|
336
|
+
any,
|
|
337
|
+
DocType,
|
|
338
|
+
THelpers,
|
|
339
|
+
RawDocType,
|
|
340
|
+
'deleteOne',
|
|
341
|
+
TDocOverrides
|
|
342
|
+
>;
|
|
315
343
|
deleteOne(): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TDocOverrides>;
|
|
316
344
|
|
|
317
345
|
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
|
|
@@ -331,6 +359,22 @@ declare module 'mongoose' {
|
|
|
331
359
|
'distinct',
|
|
332
360
|
TDocOverrides
|
|
333
361
|
>;
|
|
362
|
+
distinct<DocKey extends string, ResultType = unknown>(
|
|
363
|
+
field: DocKey,
|
|
364
|
+
filter?: Query<any, any>,
|
|
365
|
+
options?: QueryOptions<RawDocType>
|
|
366
|
+
): QueryWithHelpers<
|
|
367
|
+
Array<
|
|
368
|
+
DocKey extends keyof WithLevel1NestedPaths<DocType>
|
|
369
|
+
? WithoutUndefined<Unpacked<WithLevel1NestedPaths<DocType>[DocKey]>>
|
|
370
|
+
: ResultType
|
|
371
|
+
>,
|
|
372
|
+
DocType,
|
|
373
|
+
THelpers,
|
|
374
|
+
RawDocType,
|
|
375
|
+
'distinct',
|
|
376
|
+
TDocOverrides
|
|
377
|
+
>;
|
|
334
378
|
|
|
335
379
|
/** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
336
380
|
elemMatch(path: string, val: any): this;
|
|
@@ -374,6 +418,11 @@ declare module 'mongoose' {
|
|
|
374
418
|
projection?: ProjectionType<RawDocType> | null,
|
|
375
419
|
options?: QueryOptions<RawDocType> | null
|
|
376
420
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
|
|
421
|
+
find(
|
|
422
|
+
filter?: Query<any, any>,
|
|
423
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
424
|
+
options?: QueryOptions<RawDocType> | null
|
|
425
|
+
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
|
|
377
426
|
|
|
378
427
|
/** Declares the query a findOne operation. When executed, returns the first found document. */
|
|
379
428
|
findOne(
|
|
@@ -381,12 +430,21 @@ declare module 'mongoose' {
|
|
|
381
430
|
projection?: ProjectionType<RawDocType> | null,
|
|
382
431
|
options?: QueryOptions<RawDocType> | null
|
|
383
432
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
433
|
+
findOne(
|
|
434
|
+
filter?: Query<any, any>,
|
|
435
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
436
|
+
options?: QueryOptions<RawDocType> | null
|
|
437
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
384
438
|
|
|
385
439
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
386
440
|
findOneAndDelete(
|
|
387
441
|
filter?: QueryFilter<RawDocType>,
|
|
388
442
|
options?: QueryOptions<RawDocType> | null
|
|
389
443
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
|
|
444
|
+
findOneAndDelete(
|
|
445
|
+
filter?: Query<any, any>,
|
|
446
|
+
options?: QueryOptions<RawDocType> | null
|
|
447
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
|
|
390
448
|
|
|
391
449
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
392
450
|
findOneAndUpdate(
|
|
@@ -394,16 +452,31 @@ declare module 'mongoose' {
|
|
|
394
452
|
update: UpdateQuery<RawDocType>,
|
|
395
453
|
options: QueryOptions<RawDocType> & { includeResultMetadata: true }
|
|
396
454
|
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
455
|
+
findOneAndUpdate(
|
|
456
|
+
filter: Query<any, any>,
|
|
457
|
+
update: UpdateQuery<RawDocType>,
|
|
458
|
+
options: QueryOptions<RawDocType> & { includeResultMetadata: true }
|
|
459
|
+
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
397
460
|
findOneAndUpdate(
|
|
398
461
|
filter: QueryFilter<RawDocType>,
|
|
399
462
|
update: UpdateQuery<RawDocType>,
|
|
400
463
|
options: QueryOptions<RawDocType> & { upsert: true } & ReturnsNewDoc
|
|
401
464
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
465
|
+
findOneAndUpdate(
|
|
466
|
+
filter: Query<any, any>,
|
|
467
|
+
update: UpdateQuery<RawDocType>,
|
|
468
|
+
options: QueryOptions<RawDocType> & { upsert: true } & ReturnsNewDoc
|
|
469
|
+
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
402
470
|
findOneAndUpdate(
|
|
403
471
|
filter?: QueryFilter<RawDocType>,
|
|
404
472
|
update?: UpdateQuery<RawDocType>,
|
|
405
473
|
options?: QueryOptions<RawDocType> | null
|
|
406
474
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
475
|
+
findOneAndUpdate(
|
|
476
|
+
filter?: Query<any, any>,
|
|
477
|
+
update?: UpdateQuery<RawDocType>,
|
|
478
|
+
options?: QueryOptions<RawDocType> | null
|
|
479
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
407
480
|
|
|
408
481
|
/** Declares the query a findById operation. When executed, returns the document with the given `_id`. */
|
|
409
482
|
findById(
|
|
@@ -575,6 +648,7 @@ declare module 'mongoose' {
|
|
|
575
648
|
|
|
576
649
|
/** Merges another Query or conditions object into this one. */
|
|
577
650
|
merge(source: QueryFilter<RawDocType>): this;
|
|
651
|
+
merge(source: Query<any, any>): this;
|
|
578
652
|
|
|
579
653
|
/** Specifies a `$mod` condition, filters documents for documents whose `path` property is a number that is equal to `remainder` modulo `divisor`. */
|
|
580
654
|
mod(path: string, val: number): this;
|
|
@@ -697,6 +771,11 @@ declare module 'mongoose' {
|
|
|
697
771
|
replacement?: DocType | AnyObject,
|
|
698
772
|
options?: QueryOptions<RawDocType> | null
|
|
699
773
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne', TDocOverrides>;
|
|
774
|
+
replaceOne(
|
|
775
|
+
filter?: Query<any, any>,
|
|
776
|
+
replacement?: DocType | AnyObject,
|
|
777
|
+
options?: QueryOptions<RawDocType> | null
|
|
778
|
+
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne', TDocOverrides>;
|
|
700
779
|
|
|
701
780
|
/**
|
|
702
781
|
* Sets this query's `sanitizeProjection` option. With `sanitizeProjection()`, you can pass potentially untrusted user data to `.select()`.
|
|
@@ -765,6 +844,7 @@ declare module 'mongoose' {
|
|
|
765
844
|
|
|
766
845
|
/** Sets the query conditions to the provided JSON object. */
|
|
767
846
|
setQuery(val: QueryFilter<RawDocType> | null): void;
|
|
847
|
+
setQuery(val: Query<any, any> | null): void;
|
|
768
848
|
|
|
769
849
|
setUpdate(update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline): void;
|
|
770
850
|
|
|
@@ -809,6 +889,11 @@ declare module 'mongoose' {
|
|
|
809
889
|
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
810
890
|
options?: QueryOptions<RawDocType> | null
|
|
811
891
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany', TDocOverrides>;
|
|
892
|
+
updateMany(
|
|
893
|
+
filter: Query<any, any>,
|
|
894
|
+
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
895
|
+
options?: QueryOptions<RawDocType> | null
|
|
896
|
+
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany', TDocOverrides>;
|
|
812
897
|
|
|
813
898
|
/**
|
|
814
899
|
* Declare and/or execute this query as an updateOne() operation. Same as
|
|
@@ -819,6 +904,11 @@ declare module 'mongoose' {
|
|
|
819
904
|
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
820
905
|
options?: QueryOptions<RawDocType> | null
|
|
821
906
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne', TDocOverrides>;
|
|
907
|
+
updateOne(
|
|
908
|
+
filter: Query<any, any>,
|
|
909
|
+
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
910
|
+
options?: QueryOptions<RawDocType> | null
|
|
911
|
+
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne', TDocOverrides>;
|
|
822
912
|
|
|
823
913
|
/**
|
|
824
914
|
* Sets the specified number of `mongod` servers, or tag set of `mongod` servers,
|
package/types/utility.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ declare module 'mongoose' {
|
|
|
2
2
|
type IfAny<IFTYPE, THENTYPE, ELSETYPE = IFTYPE> = 0 extends 1 & IFTYPE
|
|
3
3
|
? THENTYPE
|
|
4
4
|
: ELSETYPE;
|
|
5
|
-
type
|
|
5
|
+
type IsUnknown<T> = unknown extends T ? true : false;
|
|
6
6
|
|
|
7
7
|
type IsNotNever<T> = [T] extends [never] ? false : true;
|
|
8
8
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
@@ -155,7 +155,7 @@ declare module 'mongoose' {
|
|
|
155
155
|
*/
|
|
156
156
|
type AddThisParameter<T, D> = {
|
|
157
157
|
[K in keyof T]: T[K] extends (...args: infer A) => infer R
|
|
158
|
-
? ThisParameter<T[K], unknown
|
|
158
|
+
? IsUnknown<ThisParameter<T[K], unknown>> extends true
|
|
159
159
|
? (this: D, ...args: A) => R
|
|
160
160
|
: T[K]
|
|
161
161
|
: T[K];
|