mongoose 8.8.4 → 8.9.0

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.
@@ -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> {