mongoose 8.8.4 → 8.9.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.8.4",
4
+ "version": "8.9.1",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -19,9 +19,9 @@
19
19
  ],
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "bson": "^6.7.0",
22
+ "bson": "^6.10.1",
23
23
  "kareem": "2.6.3",
24
- "mongodb": "~6.10.0",
24
+ "mongodb": "~6.12.0",
25
25
  "mpath": "0.9.0",
26
26
  "mquery": "5.0.0",
27
27
  "ms": "2.1.3",
@@ -30,8 +30,8 @@
30
30
  "devDependencies": {
31
31
  "@babel/core": "7.26.0",
32
32
  "@babel/preset-env": "7.26.0",
33
- "@typescript-eslint/eslint-plugin": "^8.4.0",
34
- "@typescript-eslint/parser": "^8.4.0",
33
+ "@typescript-eslint/eslint-plugin": "^8.18.0",
34
+ "@typescript-eslint/parser": "^8.18.0",
35
35
  "acquit": "1.3.0",
36
36
  "acquit-ignore": "0.2.1",
37
37
  "acquit-require": "0.1.1",
@@ -1150,6 +1150,21 @@ declare module 'mongoose' {
1150
1150
  $first: Expression;
1151
1151
  }
1152
1152
 
1153
+ export interface FirstN {
1154
+ /**
1155
+ * $firstN can be used as an aggregation accumulator or array operator.
1156
+ * As an aggregation accumulator, it returns an aggregation of the first n elements within a group.
1157
+ * As an array operator, it returns the specified number of elements from the beginning of an array.
1158
+ *
1159
+ * @version 5.2
1160
+ * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#mongodb-expression-exp.-first
1161
+ */
1162
+ $firstN: {
1163
+ input: Expression
1164
+ n: Expression,
1165
+ };
1166
+ }
1167
+
1153
1168
  export interface In {
1154
1169
  /**
1155
1170
  * Returns a boolean indicating whether a specified value is in an array.
@@ -1190,6 +1205,21 @@ declare module 'mongoose' {
1190
1205
  $last: Expression;
1191
1206
  }
1192
1207
 
1208
+ export interface LastN {
1209
+ /**
1210
+ * $lastN can be used as an aggregation accumulator or array operator.
1211
+ * As an aggregation accumulator, it an aggregation of the last n elements within a group.
1212
+ * As an array operator, it returns the specified number of elements from the end of an array.
1213
+ *
1214
+ * @version 5.2
1215
+ * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#mongodb-group-grp.-lastN
1216
+ */
1217
+ $lastN: {
1218
+ input: Expression
1219
+ n: Expression,
1220
+ };
1221
+ }
1222
+
1193
1223
  export interface LinearFill {
1194
1224
  /**
1195
1225
  * Fills null and missing fields in a window using linear interpolation based on surrounding field values.
@@ -2000,6 +2030,34 @@ declare module 'mongoose' {
2000
2030
  $avg: Expression;
2001
2031
  }
2002
2032
 
2033
+ export interface Bottom {
2034
+ /**
2035
+ * Returns the bottom element within a group according to the specified sort order.
2036
+ *
2037
+ * @version 5.2
2038
+ * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/#mongodb-group-grp.-bottom
2039
+ */
2040
+ $bottom: {
2041
+ sortBy: AnyObject,
2042
+ output: Expression
2043
+ };
2044
+ }
2045
+
2046
+ export interface BottomN {
2047
+ /**
2048
+ * Returns an aggregation of the bottom n elements within a group, according to the specified sort order.
2049
+ * If the group contains fewer than n elements, $bottomN returns all elements in the group.
2050
+ *
2051
+ * @version 5.2
2052
+ * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/#mongodb-group-grp.-bottomN
2053
+ */
2054
+ $bottomN: {
2055
+ n: Expression,
2056
+ sortBy: AnyObject,
2057
+ output: Expression
2058
+ };
2059
+ }
2060
+
2003
2061
  export interface Count {
2004
2062
  /**
2005
2063
  * Returns the number of documents in a group.
@@ -2158,6 +2216,20 @@ declare module 'mongoose' {
2158
2216
  $max: Expression | Expression[];
2159
2217
  }
2160
2218
 
2219
+ export interface MaxN {
2220
+ /**
2221
+ * Returns an aggregation of the maxmimum value n elements within a group.
2222
+ * If the group contains fewer than n elements, $maxN returns all elements in the group.
2223
+ *
2224
+ * @version 5.2
2225
+ * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/#mongodb-group-grp.-maxN
2226
+ */
2227
+ $maxN: {
2228
+ input: Expression
2229
+ n: Expression,
2230
+ };
2231
+ }
2232
+
2161
2233
  export interface Min {
2162
2234
  /**
2163
2235
  * Returns the minimum value. $min compares both value and type, using the specified BSON comparison order for
@@ -2169,6 +2241,20 @@ declare module 'mongoose' {
2169
2241
  $min: Expression | Expression[];
2170
2242
  }
2171
2243
 
2244
+ export interface MinN {
2245
+ /**
2246
+ * Returns an aggregation of the minimum value n elements within a group.
2247
+ * If the group contains fewer than n elements, $minN returns all elements in the group.
2248
+ *
2249
+ * @version 5.2
2250
+ * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/#mongodb-group-grp.-minN
2251
+ */
2252
+ $minN: {
2253
+ input: Expression
2254
+ n: Expression,
2255
+ };
2256
+ }
2257
+
2172
2258
  export interface Push {
2173
2259
  /**
2174
2260
  * Returns an array of all values that result from applying an expression to documents.
@@ -2605,6 +2691,8 @@ declare module 'mongoose' {
2605
2691
  export type ArrayExpressionOperatorReturningArray =
2606
2692
  Expression.ConcatArrays |
2607
2693
  Expression.Filter |
2694
+ Expression.FirstN |
2695
+ Expression.LastN |
2608
2696
  Expression.Map |
2609
2697
  Expression.ObjectToArray |
2610
2698
  Expression.Range |
@@ -2763,12 +2851,16 @@ declare module 'mongoose' {
2763
2851
  Expression.DocumentNumber |
2764
2852
  Expression.ExpMovingAvg |
2765
2853
  Expression.First |
2854
+ Expression.FirstN |
2766
2855
  Expression.Integral |
2767
2856
  Expression.Last |
2857
+ Expression.LastN |
2768
2858
  Expression.LinearFill |
2769
2859
  Expression.Locf |
2770
2860
  Expression.Max |
2861
+ Expression.MaxN |
2771
2862
  Expression.Min |
2863
+ Expression.MinN |
2772
2864
  Expression.Push |
2773
2865
  Expression.Rank |
2774
2866
  Expression.Shift |
@@ -2783,6 +2875,10 @@ declare module 'mongoose' {
2783
2875
 
2784
2876
  export type WindowOperatorReturningArray =
2785
2877
  Expression.AddToSet |
2878
+ Expression.FirstN |
2879
+ Expression.LastN |
2880
+ Expression.MaxN |
2881
+ Expression.MinN |
2786
2882
  Expression.Push;
2787
2883
 
2788
2884
  export type WindowOperatorReturningNumber =
@@ -2858,12 +2954,18 @@ declare module 'mongoose' {
2858
2954
  Expression.Accumulator |
2859
2955
  Expression.AddToSet |
2860
2956
  Expression.Avg |
2957
+ Expression.Bottom |
2958
+ Expression.BottomN |
2861
2959
  Expression.Count |
2862
2960
  Expression.First |
2961
+ Expression.FirstN |
2863
2962
  Expression.Last |
2963
+ Expression.LastN |
2864
2964
  Expression.Max |
2965
+ Expression.MaxN |
2865
2966
  Expression.MergeObjects |
2866
2967
  Expression.Min |
2968
+ Expression.MinN |
2867
2969
  Expression.Push |
2868
2970
  Expression.StdDevPop |
2869
2971
  Expression.StdDevSamp |
package/types/index.d.ts CHANGED
@@ -309,7 +309,7 @@ declare module 'mongoose' {
309
309
  eachPath(fn: (path: string, type: SchemaType) => void): this;
310
310
 
311
311
  /** Defines an index (most likely compound) for this schema. */
312
- index(fields: IndexDefinition, options?: IndexOptions): this;
312
+ index(fields: IndexDefinition, options?: Omit<IndexOptions, 'unique'> & { unique?: boolean | [true, string] }): this;
313
313
 
314
314
  /**
315
315
  * Define a search index for this schema.
@@ -63,7 +63,7 @@ declare module 'mongoose' {
63
63
  type ConnectionSyncIndexesResult = Record<string, OneCollectionSyncIndexesResult>;
64
64
  type OneCollectionSyncIndexesResult = Array<string> & mongodb.MongoServerError;
65
65
 
66
- interface IndexOptions extends mongodb.CreateIndexesOptions {
66
+ type IndexOptions = Omit<mongodb.CreateIndexesOptions, 'expires' | 'weights' | 'unique'> & {
67
67
  /**
68
68
  * `expires` utilizes the `ms` module from [guille](https://github.com/guille/) allowing us to use a friendlier syntax:
69
69
  *
@@ -86,7 +86,9 @@ declare module 'mongoose' {
86
86
  */
87
87
  expires?: number | string;
88
88
  weights?: Record<string, number>;
89
- }
89
+
90
+ unique?: boolean | [true, string]
91
+ };
90
92
 
91
93
  type SearchIndexDescription = mongodb.SearchIndexDescription;
92
94
  }
@@ -219,27 +219,29 @@ type IsSchemaTypeFromBuiltinClass<T> = T extends (typeof String)
219
219
  ? true
220
220
  : T extends (typeof Schema.Types.Decimal128)
221
221
  ? true
222
- : T extends (typeof Schema.Types.String)
222
+ : T extends (typeof Schema.Types.Int32)
223
223
  ? true
224
- : T extends (typeof Schema.Types.Number)
225
- ? true
226
- : T extends (typeof Schema.Types.Date)
224
+ : T extends (typeof Schema.Types.String)
227
225
  ? true
228
- : T extends (typeof Schema.Types.Boolean)
226
+ : T extends (typeof Schema.Types.Number)
229
227
  ? true
230
- : T extends (typeof Schema.Types.Buffer)
228
+ : T extends (typeof Schema.Types.Date)
231
229
  ? true
232
- : T extends Types.ObjectId
230
+ : T extends (typeof Schema.Types.Double)
233
231
  ? true
234
- : T extends Types.Decimal128
232
+ : T extends (typeof Schema.Types.Boolean)
235
233
  ? true
236
- : T extends Buffer
234
+ : T extends Types.ObjectId
237
235
  ? true
238
- : T extends NativeDate
236
+ : T extends Types.Decimal128
239
237
  ? true
240
- : T extends (typeof Schema.Types.Mixed)
238
+ : T extends Buffer
241
239
  ? true
242
- : IfEquals<T, Schema.Types.ObjectId, true, false>;
240
+ : T extends NativeDate
241
+ ? true
242
+ : T extends (typeof Schema.Types.Mixed)
243
+ ? true
244
+ : IfEquals<T, Schema.Types.ObjectId, true, false>;
243
245
 
244
246
  /**
245
247
  * @summary Resolve path type by returning the corresponding type.
@@ -302,18 +304,18 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
302
304
  PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 :
303
305
  IfEquals<PathValueType, Schema.Types.Decimal128> extends true ? Types.Decimal128 :
304
306
  IfEquals<PathValueType, Types.Decimal128> extends true ? Types.Decimal128 :
305
- IfEquals<PathValueType, Schema.Types.BigInt> extends true ? bigint :
306
- IfEquals<PathValueType, BigInt> extends true ? bigint :
307
- PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
308
- PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
309
- IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
310
- PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
311
- IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
312
- PathValueType extends ArrayConstructor ? any[] :
313
- PathValueType extends typeof Schema.Types.Mixed ? any:
314
- IfEquals<PathValueType, ObjectConstructor> extends true ? any:
315
- IfEquals<PathValueType, {}> extends true ? any:
316
- PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
317
- PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
318
- unknown,
319
- TypeHint>;
307
+ IfEquals<PathValueType, Schema.Types.BigInt> extends true ? bigint :
308
+ IfEquals<PathValueType, BigInt> extends true ? bigint :
309
+ PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
310
+ PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
311
+ IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
312
+ PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
313
+ IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
314
+ PathValueType extends ArrayConstructor ? any[] :
315
+ PathValueType extends typeof Schema.Types.Mixed ? any:
316
+ IfEquals<PathValueType, ObjectConstructor> extends true ? any:
317
+ IfEquals<PathValueType, {}> extends true ? any:
318
+ PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
319
+ PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
320
+ unknown,
321
+ TypeHint>;
@@ -37,6 +37,8 @@ declare module 'mongoose' {
37
37
  localField?: string;
38
38
  /** Overwrite the schema-level foreign field to populate on if this is a populated virtual. */
39
39
  foreignField?: string;
40
+ /** Set to `false` to prevent Mongoose from repopulating paths that are already populated */
41
+ forceRepopulate?: boolean;
40
42
  }
41
43
 
42
44
  interface PopulateOption {
@@ -12,6 +12,16 @@ declare module 'mongoose' {
12
12
  */
13
13
  type Decimal128 = Schema.Types.Decimal128;
14
14
 
15
+
16
+ /**
17
+ * The Mongoose Int32 [SchemaType](/docs/schematypes.html). Used for
18
+ * declaring paths in your schema that should be
19
+ * 32-bit integers
20
+ * Do not use this to create a new Int32 instance, use `mongoose.Types.Int32`
21
+ * instead.
22
+ */
23
+ type Int32 = Schema.Types.Int32;
24
+
15
25
  /**
16
26
  * The Mongoose Mixed [SchemaType](/docs/schematypes.html). Used for
17
27
  * declaring paths in your schema that Mongoose's change tracking, casting,
@@ -25,6 +35,13 @@ declare module 'mongoose' {
25
35
  */
26
36
  type Number = Schema.Types.Number;
27
37
 
38
+
39
+ /**
40
+ * The Mongoose Double [SchemaType](/docs/schematypes.html). Used for
41
+ * declaring paths in your schema that Mongoose should cast to doubles (IEEE 754-2008)/
42
+ */
43
+ type Double = Schema.Types.Double;
44
+
28
45
  /**
29
46
  * The Mongoose ObjectId [SchemaType](/docs/schematypes.html). Used for
30
47
  * declaring paths in your schema that should be
@@ -111,7 +128,7 @@ declare module 'mongoose' {
111
128
  * will build a unique index on this path when the
112
129
  * model is compiled. [The `unique` option is **not** a validator](/docs/validation.html#the-unique-option-is-not-a-validator).
113
130
  */
114
- unique?: boolean | number;
131
+ unique?: boolean | number | [true, string];
115
132
 
116
133
  /**
117
134
  * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
@@ -387,6 +404,14 @@ declare module 'mongoose' {
387
404
  defaultOptions: Record<string, any>;
388
405
  }
389
406
 
407
+ class Int32 extends SchemaType {
408
+ /** This schema type's name, to defend against minifiers that mangle function names. */
409
+ static schemaName: 'Int32';
410
+
411
+ /** Default options for this SchemaType */
412
+ defaultOptions: Record<string, any>;
413
+ }
414
+
390
415
  class DocumentArray extends SchemaType implements AcceptsDiscriminator {
391
416
  /** This schema type's name, to defend against minifiers that mangle function names. */
392
417
  static schemaName: 'DocumentArray';
@@ -439,6 +464,14 @@ declare module 'mongoose' {
439
464
  defaultOptions: Record<string, any>;
440
465
  }
441
466
 
467
+ class Double extends SchemaType {
468
+ /** This schema type's name, to defend against minifiers that mangle function names. */
469
+ static schemaName: 'Double';
470
+
471
+ /** Default options for this SchemaType */
472
+ defaultOptions: Record<string, any>;
473
+ }
474
+
442
475
  class ObjectId extends SchemaType {
443
476
  /** This schema type's name, to defend against minifiers that mangle function names. */
444
477
  static schemaName: 'ObjectId';
package/types/types.d.ts CHANGED
@@ -60,19 +60,21 @@ declare module 'mongoose' {
60
60
 
61
61
  class Decimal128 extends mongodb.Decimal128 { }
62
62
 
63
- class DocumentArray<T> extends Types.Array<T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>, any, T> & T> {
63
+ class DocumentArray<T, THydratedDocumentType extends Types.Subdocument<any> = Types.Subdocument<InferId<T>, any, T> & T> extends Types.Array<THydratedDocumentType> {
64
64
  /** DocumentArray constructor */
65
65
  constructor(values: AnyObject[]);
66
66
 
67
67
  isMongooseDocumentArray: true;
68
68
 
69
69
  /** Creates a subdocument casted to this schema. */
70
- create(obj: any): T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T;
70
+ create(obj: any): THydratedDocumentType;
71
71
 
72
72
  /** Searches array items for the first document with a matching _id. */
73
- id(id: any): (T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T) | null;
73
+ id(id: any): THydratedDocumentType | null;
74
74
 
75
75
  push(...args: (AnyKeys<T> & AnyObject)[]): number;
76
+
77
+ splice(start: number, deleteCount?: number, ...args: (AnyKeys<T> & AnyObject)[]): THydratedDocumentType[];
76
78
  }
77
79
 
78
80
  class Map<V> extends global.Map<string, V> {