mongoose 8.10.0 → 8.10.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/dist/browser.umd.js +1 -1
- package/lib/connection.js +34 -23
- package/lib/document.js +5 -8
- package/lib/drivers/browser/index.js +1 -0
- package/lib/drivers/node-mongodb-native/bulkWriteResult.js +5 -0
- package/lib/drivers/node-mongodb-native/collection.js +5 -1
- package/lib/drivers/node-mongodb-native/index.js +1 -0
- package/lib/helpers/clone.js +1 -1
- package/lib/helpers/getDefaultBulkwriteResult.js +11 -20
- package/lib/helpers/model/decorateBulkWriteResult.js +8 -0
- package/lib/helpers/query/castUpdate.js +10 -0
- package/lib/model.js +33 -16
- package/lib/query.js +33 -23
- package/lib/schema/map.js +1 -8
- package/lib/schema.js +3 -0
- package/package.json +1 -1
- package/types/index.d.ts +57 -51
- package/types/inferschematype.d.ts +8 -4
- package/types/models.d.ts +1 -1
- package/types/schematypes.d.ts +12 -12
- package/types/validation.d.ts +6 -1
package/types/index.d.ts
CHANGED
|
@@ -273,10 +273,10 @@ declare module 'mongoose' {
|
|
|
273
273
|
/**
|
|
274
274
|
* Create a new schema
|
|
275
275
|
*/
|
|
276
|
-
constructor(definition?: SchemaDefinition<SchemaDefinitionType<RawDocType>, RawDocType> | DocType, options?: SchemaOptions<FlatRecord<DocType>, TInstanceMethods, TQueryHelpers, TStaticMethods, TVirtuals, THydratedDocumentType> | ResolveSchemaOptions<TSchemaOptions>);
|
|
276
|
+
constructor(definition?: SchemaDefinition<SchemaDefinitionType<RawDocType>, RawDocType, THydratedDocumentType> | DocType, options?: SchemaOptions<FlatRecord<DocType>, TInstanceMethods, TQueryHelpers, TStaticMethods, TVirtuals, THydratedDocumentType> | ResolveSchemaOptions<TSchemaOptions>);
|
|
277
277
|
|
|
278
278
|
/** Adds key path / schema type pairs to this schema. */
|
|
279
|
-
add(obj: SchemaDefinition<SchemaDefinitionType<RawDocType
|
|
279
|
+
add(obj: SchemaDefinition<SchemaDefinitionType<RawDocType>, RawDocType> | Schema, prefix?: string): this;
|
|
280
280
|
|
|
281
281
|
/**
|
|
282
282
|
* Add an alias for `path`. This means getting or setting the `alias`
|
|
@@ -297,7 +297,7 @@ declare module 'mongoose' {
|
|
|
297
297
|
/** Returns a copy of this schema */
|
|
298
298
|
clone<T = this>(): T;
|
|
299
299
|
|
|
300
|
-
discriminator<DisSchema = Schema>(name: string | number, schema: DisSchema): this;
|
|
300
|
+
discriminator<DisSchema = Schema>(name: string | number, schema: DisSchema, options?: DiscriminatorOptions): this;
|
|
301
301
|
|
|
302
302
|
/** Returns a new schema that has the picked `paths` from this schema. */
|
|
303
303
|
pick<T = this>(paths: string[], options?: SchemaOptions): T;
|
|
@@ -541,21 +541,21 @@ declare module 'mongoose' {
|
|
|
541
541
|
? DateSchemaDefinition
|
|
542
542
|
: (Function | string);
|
|
543
543
|
|
|
544
|
-
export type SchemaDefinitionProperty<T = undefined, EnforcedDocType = any
|
|
545
|
-
|
|
546
|
-
typeof SchemaType
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
typeof Schema.Types.Mixed
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
export type SchemaDefinition<T = undefined, EnforcedDocType = any
|
|
544
|
+
export type SchemaDefinitionProperty<T = undefined, EnforcedDocType = any, THydratedDocumentType = HydratedDocument<EnforcedDocType>> = SchemaDefinitionWithBuiltInClass<T>
|
|
545
|
+
| SchemaTypeOptions<T extends undefined ? any : T, EnforcedDocType, THydratedDocumentType>
|
|
546
|
+
| typeof SchemaType
|
|
547
|
+
| Schema<any, any, any>
|
|
548
|
+
| Schema<any, any, any>[]
|
|
549
|
+
| SchemaTypeOptions<T extends undefined ? any : Unpacked<T>, EnforcedDocType, THydratedDocumentType>[]
|
|
550
|
+
| Function[]
|
|
551
|
+
| SchemaDefinition<T, EnforcedDocType, THydratedDocumentType>
|
|
552
|
+
| SchemaDefinition<Unpacked<T>, EnforcedDocType, THydratedDocumentType>[]
|
|
553
|
+
| typeof Schema.Types.Mixed
|
|
554
|
+
| MixedSchemaTypeOptions<EnforcedDocType>;
|
|
555
|
+
|
|
556
|
+
export type SchemaDefinition<T = undefined, EnforcedDocType = any, THydratedDocumentType = HydratedDocument<EnforcedDocType>> = T extends undefined
|
|
557
557
|
? { [path: string]: SchemaDefinitionProperty; }
|
|
558
|
-
: { [path in keyof T]?: SchemaDefinitionProperty<T[path], EnforcedDocType>; };
|
|
558
|
+
: { [path in keyof T]?: SchemaDefinitionProperty<T[path], EnforcedDocType, THydratedDocumentType>; };
|
|
559
559
|
|
|
560
560
|
export type AnyArray<T> = T[] | ReadonlyArray<T>;
|
|
561
561
|
export type ExtractMongooseArray<T> = T extends Types.Array<any> ? AnyArray<Unpacked<T>> : T;
|
|
@@ -712,47 +712,53 @@ declare module 'mongoose' {
|
|
|
712
712
|
[K in keyof T]: FlattenProperty<T[K]>;
|
|
713
713
|
};
|
|
714
714
|
|
|
715
|
-
export type BufferToBinaryProperty<T> =
|
|
716
|
-
?
|
|
717
|
-
: T extends
|
|
718
|
-
?
|
|
719
|
-
: T extends Types.
|
|
720
|
-
?
|
|
721
|
-
:
|
|
715
|
+
export type BufferToBinaryProperty<T> = unknown extends Buffer
|
|
716
|
+
? T
|
|
717
|
+
: T extends Buffer
|
|
718
|
+
? mongodb.Binary
|
|
719
|
+
: T extends Types.DocumentArray<infer ItemType>
|
|
720
|
+
? Types.DocumentArray<BufferToBinary<ItemType>>
|
|
721
|
+
: T extends Types.Subdocument<unknown, unknown, infer SubdocType>
|
|
722
|
+
? HydratedSingleSubdocument<BufferToBinary<SubdocType>>
|
|
723
|
+
: BufferToBinary<T>;
|
|
722
724
|
|
|
723
725
|
/**
|
|
724
726
|
* Converts any Buffer properties into mongodb.Binary instances, which is what `lean()` returns
|
|
725
727
|
*/
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
728
|
+
export type BufferToBinary<T> = unknown extends Buffer
|
|
729
|
+
? T
|
|
730
|
+
: T extends Buffer
|
|
731
|
+
? mongodb.Binary
|
|
732
|
+
: T extends Document
|
|
733
|
+
? T
|
|
734
|
+
: T extends TreatAsPrimitives
|
|
735
|
+
? T
|
|
736
|
+
: T extends Record<string, any>
|
|
737
|
+
? {
|
|
738
|
+
[K in keyof T]: BufferToBinaryProperty<T[K]>
|
|
739
|
+
}
|
|
740
|
+
: T;
|
|
737
741
|
|
|
738
742
|
/**
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
export type BufferToJSON<T> =
|
|
742
|
-
?
|
|
743
|
-
: T extends
|
|
744
|
-
?
|
|
745
|
-
: T extends
|
|
743
|
+
* Converts any Buffer properties into { type: 'buffer', data: [1, 2, 3] } format for JSON serialization
|
|
744
|
+
*/
|
|
745
|
+
export type BufferToJSON<T> = unknown extends Buffer
|
|
746
|
+
? T
|
|
747
|
+
: T extends Buffer
|
|
748
|
+
? { type: 'buffer', data: number[] }
|
|
749
|
+
: T extends Document
|
|
746
750
|
? T
|
|
747
|
-
: T extends
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
: T[K] extends
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
?
|
|
754
|
-
:
|
|
755
|
-
|
|
751
|
+
: T extends TreatAsPrimitives
|
|
752
|
+
? T
|
|
753
|
+
: T extends Record<string, any> ? {
|
|
754
|
+
[K in keyof T]: T[K] extends Buffer
|
|
755
|
+
? { type: 'buffer', data: number[] }
|
|
756
|
+
: T[K] extends Types.DocumentArray<infer ItemType>
|
|
757
|
+
? Types.DocumentArray<BufferToBinary<ItemType>>
|
|
758
|
+
: T[K] extends Types.Subdocument<unknown, unknown, infer SubdocType>
|
|
759
|
+
? HydratedSingleSubdocument<SubdocType>
|
|
760
|
+
: BufferToBinary<T[K]>;
|
|
761
|
+
} : T;
|
|
756
762
|
|
|
757
763
|
/**
|
|
758
764
|
* 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
|
|
238
|
+
: T extends NativeDate
|
|
239
239
|
? true
|
|
240
|
-
: T extends
|
|
240
|
+
: T extends (typeof Schema.Types.Mixed)
|
|
241
241
|
? true
|
|
242
|
-
: T
|
|
242
|
+
: IfEquals<T, Schema.Types.ObjectId, true, false> extends true
|
|
243
243
|
? true
|
|
244
|
-
:
|
|
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.
|
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 | null> } }>;
|
|
312
312
|
bulkWrite<DocContents = TRawDocType>(
|
|
313
313
|
writes: Array<AnyBulkWriteOperation<DocContents extends Document ? any : (DocContents extends {} ? DocContents : any)>>,
|
|
314
314
|
options?: MongooseBulkWriteOptions
|
package/types/schematypes.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ declare module 'mongoose' {
|
|
|
56
56
|
|
|
57
57
|
type DefaultType<T> = T extends Schema.Types.Mixed ? any : Partial<ExtractMongooseArray<T>>;
|
|
58
58
|
|
|
59
|
-
class SchemaTypeOptions<T, EnforcedDocType = any
|
|
59
|
+
class SchemaTypeOptions<T, EnforcedDocType = any, THydratedDocumentType = HydratedDocument<EnforcedDocType>> {
|
|
60
60
|
type?:
|
|
61
61
|
T extends string ? StringSchemaDefinition :
|
|
62
62
|
T extends number ? NumberSchemaDefinition :
|
|
@@ -65,19 +65,19 @@ declare module 'mongoose' {
|
|
|
65
65
|
T extends Map<any, any> ? SchemaDefinition<typeof Map> :
|
|
66
66
|
T extends Buffer ? SchemaDefinition<typeof Buffer> :
|
|
67
67
|
T extends Types.ObjectId ? ObjectIdSchemaDefinition :
|
|
68
|
-
T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId, EnforcedDocType>> :
|
|
69
|
-
T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>, EnforcedDocType>>) :
|
|
70
|
-
T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string, EnforcedDocType>> :
|
|
71
|
-
T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number, EnforcedDocType>> :
|
|
72
|
-
T extends boolean[] ? AnyArray<BooleanSchemaDefinition> | AnyArray<SchemaTypeOptions<boolean, EnforcedDocType>> :
|
|
73
|
-
T extends Function[] ? AnyArray<Function | string> | AnyArray<SchemaTypeOptions<Unpacked<T>, EnforcedDocType>> :
|
|
68
|
+
T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId, EnforcedDocType, THydratedDocumentType>> :
|
|
69
|
+
T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>, EnforcedDocType, THydratedDocumentType>>) :
|
|
70
|
+
T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string, EnforcedDocType, THydratedDocumentType>> :
|
|
71
|
+
T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number, EnforcedDocType, THydratedDocumentType>> :
|
|
72
|
+
T extends boolean[] ? AnyArray<BooleanSchemaDefinition> | AnyArray<SchemaTypeOptions<boolean, EnforcedDocType, THydratedDocumentType>> :
|
|
73
|
+
T extends Function[] ? AnyArray<Function | string> | AnyArray<SchemaTypeOptions<Unpacked<T>, EnforcedDocType, THydratedDocumentType>> :
|
|
74
74
|
T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T> | Function | AnyArray<Function>;
|
|
75
75
|
|
|
76
76
|
/** Defines a virtual with the given name that gets/sets this path. */
|
|
77
77
|
alias?: string | string[];
|
|
78
78
|
|
|
79
79
|
/** Function or object describing how to validate this schematype. See [validation docs](https://mongoosejs.com/docs/validation.html). */
|
|
80
|
-
validate?: SchemaValidator<T, EnforcedDocType> | AnyArray<SchemaValidator<T, EnforcedDocType>>;
|
|
80
|
+
validate?: SchemaValidator<T, EnforcedDocType, THydratedDocumentType> | AnyArray<SchemaValidator<T, EnforcedDocType, THydratedDocumentType>>;
|
|
81
81
|
|
|
82
82
|
/** Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message. */
|
|
83
83
|
cast?: string |
|
|
@@ -389,10 +389,10 @@ declare module 'mongoose' {
|
|
|
389
389
|
expires(when: number | string): this;
|
|
390
390
|
|
|
391
391
|
/** Sets a maximum date validator. */
|
|
392
|
-
max(value: NativeDate, message
|
|
392
|
+
max(value: NativeDate, message?: string): this;
|
|
393
393
|
|
|
394
394
|
/** Sets a minimum date validator. */
|
|
395
|
-
min(value: NativeDate, message
|
|
395
|
+
min(value: NativeDate, message?: string): this;
|
|
396
396
|
|
|
397
397
|
/** Default options for this SchemaType */
|
|
398
398
|
defaultOptions: Record<string, any>;
|
|
@@ -457,10 +457,10 @@ declare module 'mongoose' {
|
|
|
457
457
|
enum(vals: number[]): this;
|
|
458
458
|
|
|
459
459
|
/** Sets a maximum number validator. */
|
|
460
|
-
max(value: number, message
|
|
460
|
+
max(value: number, message?: string): this;
|
|
461
461
|
|
|
462
462
|
/** Sets a minimum number validator. */
|
|
463
|
-
min(value: number, message
|
|
463
|
+
min(value: number, message?: string): this;
|
|
464
464
|
|
|
465
465
|
/** Default options for this SchemaType */
|
|
466
466
|
defaultOptions: Record<string, any>;
|
package/types/validation.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
declare module 'mongoose' {
|
|
2
2
|
|
|
3
|
-
type SchemaValidator<T, EnforcedDocType> = RegExp
|
|
3
|
+
type SchemaValidator<T, EnforcedDocType, THydratedDocumentType> = RegExp
|
|
4
|
+
| [RegExp, string]
|
|
5
|
+
| Function
|
|
6
|
+
| [Function, string]
|
|
7
|
+
| ValidateOpts<T, THydratedDocumentType>
|
|
8
|
+
| ValidateOpts<T, THydratedDocumentType>[];
|
|
4
9
|
|
|
5
10
|
interface ValidatorProps {
|
|
6
11
|
path: string;
|