mongoose 8.10.1 → 8.11.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.
package/types/index.d.ts CHANGED
@@ -204,30 +204,32 @@ declare module 'mongoose' {
204
204
  }
205
205
 
206
206
  export interface ToObjectOptions<THydratedDocumentType = HydratedDocument<unknown>> {
207
- /** apply all getters (path and virtual getters) */
208
- getters?: boolean;
209
- /** apply virtual getters (can override getters option) */
210
- virtuals?: boolean | string[];
211
207
  /** if `options.virtuals = true`, you can set `options.aliases = false` to skip applying aliases. This option is a no-op if `options.virtuals = false`. */
212
208
  aliases?: boolean;
209
+ /** if true, replace any conventionally populated paths with the original id in the output. Has no affect on virtual populated paths. */
210
+ depopulate?: boolean;
211
+ /** if true, convert Maps to POJOs. Useful if you want to `JSON.stringify()` the result of `toObject()`. */
212
+ flattenMaps?: boolean;
213
+ /** if true, convert any ObjectIds in the result to 24 character hex strings. */
214
+ flattenObjectIds?: boolean;
215
+ /** apply all getters (path and virtual getters) */
216
+ getters?: boolean;
213
217
  /** remove empty objects (defaults to true) */
214
218
  minimize?: boolean;
219
+ /** If true, the resulting object will only have fields that are defined in the document's schema. By default, `toJSON()` & `toObject()` returns all fields in the underlying document from MongoDB, including ones that are not listed in the schema. */
220
+ schemaFieldsOnly?: boolean;
215
221
  /** if set, mongoose will call this function to allow you to transform the returned object */
216
222
  transform?: boolean | ((
217
223
  doc: THydratedDocumentType,
218
224
  ret: Record<string, any>,
219
225
  options: ToObjectOptions<THydratedDocumentType>
220
226
  ) => any);
221
- /** if true, replace any conventionally populated paths with the original id in the output. Has no affect on virtual populated paths. */
222
- depopulate?: boolean;
223
- /** if false, exclude the version key (`__v` by default) from the output */
224
- versionKey?: boolean;
225
- /** if true, convert Maps to POJOs. Useful if you want to `JSON.stringify()` the result of `toObject()`. */
226
- flattenMaps?: boolean;
227
- /** if true, convert any ObjectIds in the result to 24 character hex strings. */
228
- flattenObjectIds?: boolean;
229
227
  /** If true, omits fields that are excluded in this document's projection. Unless you specified a projection, this will omit any field that has `select: false` in the schema. */
230
228
  useProjection?: boolean;
229
+ /** if false, exclude the version key (`__v` by default) from the output */
230
+ versionKey?: boolean;
231
+ /** apply virtual getters (can override getters option) */
232
+ virtuals?: boolean | string[];
231
233
  }
232
234
 
233
235
  export type DiscriminatorModel<M, T> = T extends Model<infer T, infer TQueryHelpers, infer TInstanceMethods, infer TVirtuals>
@@ -712,47 +714,53 @@ declare module 'mongoose' {
712
714
  [K in keyof T]: FlattenProperty<T[K]>;
713
715
  };
714
716
 
715
- export type BufferToBinaryProperty<T> = T extends Buffer
716
- ? mongodb.Binary
717
- : T extends Types.DocumentArray<infer ItemType>
718
- ? Types.DocumentArray<BufferToBinary<ItemType>>
719
- : T extends Types.Subdocument<unknown, unknown, infer SubdocType>
720
- ? HydratedSingleSubdocument<BufferToBinary<SubdocType>>
721
- : BufferToBinary<T>;
717
+ export type BufferToBinaryProperty<T> = unknown extends Buffer
718
+ ? T
719
+ : T extends Buffer
720
+ ? mongodb.Binary
721
+ : T extends Types.DocumentArray<infer ItemType>
722
+ ? Types.DocumentArray<BufferToBinary<ItemType>>
723
+ : T extends Types.Subdocument<unknown, unknown, infer SubdocType>
724
+ ? HydratedSingleSubdocument<BufferToBinary<SubdocType>>
725
+ : BufferToBinary<T>;
722
726
 
723
727
  /**
724
728
  * Converts any Buffer properties into mongodb.Binary instances, which is what `lean()` returns
725
729
  */
726
- export type BufferToBinary<T> = T extends Buffer
727
- ? mongodb.Binary
728
- : T extends Document
729
- ? T
730
- : T extends TreatAsPrimitives
731
- ? T
732
- : T extends Record<string, any>
733
- ? {
734
- [K in keyof T]: BufferToBinaryProperty<T[K]>
735
- }
736
- : T;
730
+ export type BufferToBinary<T> = unknown extends Buffer
731
+ ? T
732
+ : T extends Buffer
733
+ ? mongodb.Binary
734
+ : T extends Document
735
+ ? T
736
+ : T extends TreatAsPrimitives
737
+ ? T
738
+ : T extends Record<string, any>
739
+ ? {
740
+ [K in keyof T]: BufferToBinaryProperty<T[K]>
741
+ }
742
+ : T;
737
743
 
738
744
  /**
739
- * Converts any Buffer properties into { type: 'buffer', data: [1, 2, 3] } format for JSON serialization
740
- */
741
- export type BufferToJSON<T> = T extends Buffer
742
- ? { type: 'buffer', data: number[] }
743
- : T extends Document
744
- ? T
745
- : T extends TreatAsPrimitives
745
+ * Converts any Buffer properties into { type: 'buffer', data: [1, 2, 3] } format for JSON serialization
746
+ */
747
+ export type BufferToJSON<T> = unknown extends Buffer
748
+ ? T
749
+ : T extends Buffer
750
+ ? { type: 'buffer', data: number[] }
751
+ : T extends Document
746
752
  ? T
747
- : T extends Record<string, any> ? {
748
- [K in keyof T]: T[K] extends Buffer
749
- ? { type: 'buffer', data: number[] }
750
- : T[K] extends Types.DocumentArray<infer ItemType>
751
- ? Types.DocumentArray<BufferToBinary<ItemType>>
752
- : T[K] extends Types.Subdocument<unknown, unknown, infer SubdocType>
753
- ? HydratedSingleSubdocument<SubdocType>
754
- : BufferToBinary<T[K]>;
755
- } : T;
753
+ : T extends TreatAsPrimitives
754
+ ? T
755
+ : T extends Record<string, any> ? {
756
+ [K in keyof T]: T[K] extends Buffer
757
+ ? { type: 'buffer', data: number[] }
758
+ : T[K] extends Types.DocumentArray<infer ItemType>
759
+ ? Types.DocumentArray<BufferToBinary<ItemType>>
760
+ : T[K] extends Types.Subdocument<unknown, unknown, infer SubdocType>
761
+ ? HydratedSingleSubdocument<SubdocType>
762
+ : BufferToBinary<T[K]>;
763
+ } : T;
756
764
 
757
765
  /**
758
766
  * Converts any ObjectId properties into strings for JSON serialization
@@ -235,13 +235,17 @@ type IsSchemaTypeFromBuiltinClass<T> = T extends (typeof String)
235
235
  ? true
236
236
  : T extends Types.Decimal128
237
237
  ? true
238
- : T extends Buffer
238
+ : T extends NativeDate
239
239
  ? true
240
- : T extends NativeDate
240
+ : T extends (typeof Schema.Types.Mixed)
241
241
  ? true
242
- : T extends (typeof Schema.Types.Mixed)
242
+ : IfEquals<T, Schema.Types.ObjectId, true, false> extends true
243
243
  ? true
244
- : IfEquals<T, Schema.Types.ObjectId, true, false>;
244
+ : unknown extends Buffer
245
+ ? false
246
+ : T extends Buffer
247
+ ? true
248
+ : false;
245
249
 
246
250
  /**
247
251
  * @summary Resolve path type by returning the corresponding type.
@@ -308,14 +312,15 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
308
312
  IfEquals<PathValueType, BigInt> extends true ? bigint :
309
313
  PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
310
314
  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,
315
+ PathValueType extends 'double' | 'Double' | typeof Schema.Types.Double ? Types.Double :
316
+ IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
317
+ PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
318
+ IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
319
+ PathValueType extends ArrayConstructor ? any[] :
320
+ PathValueType extends typeof Schema.Types.Mixed ? any:
321
+ IfEquals<PathValueType, ObjectConstructor> extends true ? any:
322
+ IfEquals<PathValueType, {}> extends true ? any:
323
+ PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
324
+ PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
325
+ unknown,
321
326
  TypeHint>;
package/types/models.d.ts CHANGED
@@ -308,7 +308,7 @@ declare module 'mongoose' {
308
308
  bulkWrite<DocContents = TRawDocType>(
309
309
  writes: Array<AnyBulkWriteOperation<DocContents extends Document ? any : (DocContents extends {} ? DocContents : any)>>,
310
310
  options: MongooseBulkWriteOptions & { ordered: false }
311
- ): Promise<mongodb.BulkWriteResult & { mongoose?: { validationErrors: Error[] } }>;
311
+ ): Promise<mongodb.BulkWriteResult & { mongoose?: { validationErrors: Error[], results: Array<Error | mongodb.WriteError | null> } }>;
312
312
  bulkWrite<DocContents = TRawDocType>(
313
313
  writes: Array<AnyBulkWriteOperation<DocContents extends Document ? any : (DocContents extends {} ? DocContents : any)>>,
314
314
  options?: MongooseBulkWriteOptions
@@ -39,6 +39,12 @@ declare module 'mongoose' {
39
39
  foreignField?: string;
40
40
  /** Set to `false` to prevent Mongoose from repopulating paths that are already populated */
41
41
  forceRepopulate?: boolean;
42
+ /**
43
+ * Set to `true` to execute any populate queries one at a time, as opposed to in parallel.
44
+ * We recommend setting this option to `true` if using transactions, especially if also populating multiple paths or paths with multiple models.
45
+ * MongoDB server does **not** support multiple operations in parallel on a single transaction.
46
+ */
47
+ ordered?: boolean;
42
48
  }
43
49
 
44
50
  interface PopulateOption {
package/types/types.d.ts CHANGED
@@ -104,5 +104,7 @@ declare module 'mongoose' {
104
104
  }
105
105
 
106
106
  class UUID extends bson.UUID {}
107
+
108
+ class Double extends bson.Double {}
107
109
  }
108
110
  }