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.
- package/dist/browser.umd.js +1 -1
- package/index.js +1 -0
- package/lib/cast/double.js +50 -0
- package/lib/cast/int32.js +36 -0
- package/lib/connection.js +180 -0
- package/lib/document.js +12 -3
- package/lib/drivers/node-mongodb-native/connection.js +0 -4
- package/lib/helpers/clone.js +5 -0
- package/lib/helpers/model/castBulkWrite.js +218 -205
- package/lib/helpers/populate/getModelsMapForPopulate.js +7 -0
- package/lib/helpers/schema/getIndexes.js +5 -0
- package/lib/model.js +64 -99
- package/lib/mongoose.js +2 -0
- package/lib/query.js +6 -2
- package/lib/queryHelpers.js +13 -32
- package/lib/schema/bigint.js +2 -2
- package/lib/schema/double.js +212 -0
- package/lib/schema/index.js +2 -0
- package/lib/schema/int32.js +249 -0
- package/lib/schema.js +35 -0
- package/lib/schemaType.js +36 -8
- package/lib/validOptions.js +1 -0
- package/package.json +3 -3
- package/types/expressions.d.ts +102 -0
- package/types/index.d.ts +1 -1
- package/types/indexes.d.ts +4 -2
- package/types/inferschematype.d.ts +29 -27
- package/types/populate.d.ts +2 -0
- package/types/schematypes.d.ts +34 -1
- package/types/types.d.ts +5 -3
|
@@ -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.
|
|
222
|
+
: T extends (typeof Schema.Types.Int32)
|
|
223
223
|
? true
|
|
224
|
-
|
|
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.
|
|
226
|
+
: T extends (typeof Schema.Types.Number)
|
|
229
227
|
? true
|
|
230
|
-
: T extends (typeof Schema.Types.
|
|
228
|
+
: T extends (typeof Schema.Types.Date)
|
|
231
229
|
? true
|
|
232
|
-
: T extends Types.
|
|
230
|
+
: T extends (typeof Schema.Types.Double)
|
|
233
231
|
? true
|
|
234
|
-
: T extends Types.
|
|
232
|
+
: T extends (typeof Schema.Types.Boolean)
|
|
235
233
|
? true
|
|
236
|
-
: T extends
|
|
234
|
+
: T extends Types.ObjectId
|
|
237
235
|
? true
|
|
238
|
-
: T extends
|
|
236
|
+
: T extends Types.Decimal128
|
|
239
237
|
? true
|
|
240
|
-
: T extends
|
|
238
|
+
: T extends Buffer
|
|
241
239
|
? true
|
|
242
|
-
:
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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>;
|
package/types/populate.d.ts
CHANGED
|
@@ -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 {
|
package/types/schematypes.d.ts
CHANGED
|
@@ -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
|
|
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):
|
|
70
|
+
create(obj: any): THydratedDocumentType;
|
|
71
71
|
|
|
72
72
|
/** Searches array items for the first document with a matching _id. */
|
|
73
|
-
id(id: any):
|
|
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> {
|