mongoose 9.6.3 → 9.7.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/lib/aggregate.js +50 -23
- package/lib/connection.js +1 -1
- package/lib/cursor/aggregationCursor.js +47 -16
- package/lib/cursor/queryCursor.js +23 -7
- package/lib/document.js +49 -34
- package/lib/error/divergentArray.js +1 -1
- package/lib/helpers/document/applyDefaults.js +5 -0
- package/lib/helpers/populate/createPopulateQueryFilter.js +9 -1
- package/lib/helpers/populate/getModelsMapForPopulate.js +8 -6
- package/lib/helpers/populate/splitPopulateQuery.js +81 -0
- package/lib/helpers/schema/getKeysInSchemaOrder.js +13 -16
- package/lib/model.js +136 -28
- package/lib/plugins/saveSubdocs.js +16 -13
- package/lib/query.js +44 -28
- package/lib/schema/date.js +7 -5
- package/lib/schema/documentArray.js +1 -1
- package/lib/schema/objectId.js +7 -1
- package/lib/schema/subdocument.js +1 -1
- package/lib/schema/union.js +2 -2
- package/lib/schemaType.js +2 -1
- package/lib/standardSchema/convertErrorToIssues.js +20 -0
- package/lib/stateMachine.js +11 -6
- package/lib/tracing.js +38 -0
- package/package.json +8 -7
- package/types/document.d.ts +21 -4
- package/types/index.d.ts +1 -0
- package/types/models.d.ts +42 -4
- package/types/tracing.d.ts +10 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "9.
|
|
4
|
+
"version": "9.7.1",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"c8": "11.0.0",
|
|
40
40
|
"cheerio": "1.2.0",
|
|
41
41
|
"dox": "1.0.0",
|
|
42
|
-
"eslint": "10.
|
|
42
|
+
"eslint": "10.4.1",
|
|
43
43
|
"eslint-plugin-mocha-no-only": "1.2.0",
|
|
44
|
-
"express": "
|
|
44
|
+
"express": "5.2.1",
|
|
45
45
|
"fs-extra": "~11.3.0",
|
|
46
46
|
"globals": "^17.4.0",
|
|
47
47
|
"glob": "^13.0.6",
|
|
@@ -50,20 +50,21 @@
|
|
|
50
50
|
"lodash.isequal": "4.5.0",
|
|
51
51
|
"lodash.isequalwith": "4.4.0",
|
|
52
52
|
"markdownlint-cli2": "0.22.1",
|
|
53
|
-
"marked": "18.0.
|
|
53
|
+
"marked": "18.0.4",
|
|
54
54
|
"mkdirp": "^3.0.1",
|
|
55
55
|
"mocha": "12.0.0-beta-10",
|
|
56
56
|
"moment": "2.30.1",
|
|
57
57
|
"mongodb-client-encryption": "~7.0",
|
|
58
|
-
"mongodb-memory-server": "11.
|
|
58
|
+
"mongodb-memory-server": "11.2.0",
|
|
59
59
|
"mongodb-runner": "^6.0.0",
|
|
60
60
|
"ncp": "^2.0.0",
|
|
61
61
|
"pug": "3.0.4",
|
|
62
|
-
"sinon": "
|
|
62
|
+
"sinon": "22.0.0",
|
|
63
63
|
"tstyche": "^7.0.0",
|
|
64
64
|
"typescript": "5.9.3",
|
|
65
65
|
"typescript-eslint": "^8.31.1",
|
|
66
|
-
"uuid": "14.0.0"
|
|
66
|
+
"uuid": "14.0.0",
|
|
67
|
+
"xss": "1.0.15"
|
|
67
68
|
},
|
|
68
69
|
"directories": {
|
|
69
70
|
"lib": "./lib/mongoose"
|
package/types/document.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ declare module 'mongoose' {
|
|
|
11
11
|
middleware?: boolean | SkipMiddlewareOptions;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
interface ValidateSyncOptions extends Omit<ValidateOptions, 'middleware'> {
|
|
15
|
+
/** `validateSync()` does not run middleware. Use `validate()` if you need middleware. */
|
|
16
|
+
middleware?: never;
|
|
17
|
+
[k: string]: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
interface DocumentSetOptions {
|
|
15
21
|
merge?: boolean;
|
|
16
22
|
|
|
@@ -320,9 +326,20 @@ declare module 'mongoose' {
|
|
|
320
326
|
validate(pathsToValidate?: pathsToValidate, options?: Omit<ValidateOptions, 'pathsToSkip'> & AnyObject): Promise<void>;
|
|
321
327
|
validate(options: ValidateOptions): Promise<void>;
|
|
322
328
|
|
|
323
|
-
/**
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
329
|
+
/**
|
|
330
|
+
* Executes registered validation rules (skipping asynchronous validators) for this document.
|
|
331
|
+
* @deprecated Use `validate()` instead. `validateSync()` does not run middleware and will be removed in Mongoose 10.
|
|
332
|
+
*/
|
|
333
|
+
validateSync(options: ValidateSyncOptions): Error.ValidationError | null;
|
|
334
|
+
/**
|
|
335
|
+
* Executes registered validation rules (skipping asynchronous validators) for this document.
|
|
336
|
+
* @deprecated Use `validate()` instead. `validateSync()` does not run middleware and will be removed in Mongoose 10.
|
|
337
|
+
*/
|
|
338
|
+
validateSync<T extends keyof DocType>(pathsToValidate?: T | T[], options?: Omit<ValidateSyncOptions, 'pathsToSkip'>): Error.ValidationError | null;
|
|
339
|
+
/**
|
|
340
|
+
* Executes registered validation rules (skipping asynchronous validators) for this document.
|
|
341
|
+
* @deprecated Use `validate()` instead. `validateSync()` does not run middleware and will be removed in Mongoose 10.
|
|
342
|
+
*/
|
|
343
|
+
validateSync(pathsToValidate?: pathsToValidate, options?: Omit<ValidateSyncOptions, 'pathsToSkip'>): Error.ValidationError | null;
|
|
327
344
|
}
|
|
328
345
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
/// <reference path="./inferrawdoctype.d.ts" />
|
|
25
25
|
/// <reference path="./inferschematype.d.ts" />
|
|
26
26
|
/// <reference path="./virtuals.d.ts" />
|
|
27
|
+
/// <reference path="./tracing.d.ts" />
|
|
27
28
|
/// <reference path="./augmentations.d.ts" />
|
|
28
29
|
|
|
29
30
|
declare class NativeDate extends globalThis.Date { }
|
package/types/models.d.ts
CHANGED
|
@@ -108,6 +108,41 @@ declare module 'mongoose' {
|
|
|
108
108
|
*/
|
|
109
109
|
type pathsToValidate = PathsToValidate;
|
|
110
110
|
|
|
111
|
+
export namespace StandardSchemaV1 {
|
|
112
|
+
export interface Props<Output = unknown> {
|
|
113
|
+
readonly version: 1;
|
|
114
|
+
readonly vendor: 'mongoose';
|
|
115
|
+
readonly validate: (
|
|
116
|
+
value: unknown,
|
|
117
|
+
options?: Options | undefined
|
|
118
|
+
) => Result<Output> | Promise<Result<Output>>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface Options {
|
|
122
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
126
|
+
|
|
127
|
+
export interface SuccessResult<Output> {
|
|
128
|
+
readonly value: Output;
|
|
129
|
+
readonly issues?: undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface FailureResult {
|
|
133
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface Issue {
|
|
137
|
+
readonly message: string;
|
|
138
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface PathSegment {
|
|
142
|
+
readonly key: PropertyKey;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
111
146
|
interface SaveOptions extends
|
|
112
147
|
SessionOption {
|
|
113
148
|
checkKeys?: boolean;
|
|
@@ -192,15 +227,15 @@ declare module 'mongoose' {
|
|
|
192
227
|
type CreateObjectWithExtraKeys<T> = T & Record<string, unknown>;
|
|
193
228
|
type ApplyBasicCreateCasting<T> = {
|
|
194
229
|
[K in keyof T]: NonNullable<T[K]> extends Map<infer KeyType extends string, infer ValueType>
|
|
195
|
-
? (Record<KeyType, ValueType> | Array<[KeyType, ValueType]> | T[K])
|
|
230
|
+
? (Record<KeyType, ValueType> | Array<[KeyType, ValueType]> | T[K] | QueryTypeCasting<Extract<T[K], TreatAsPrimitives>>)
|
|
196
231
|
: NonNullable<T[K]> extends Types.DocumentArray<infer RawSubdocType>
|
|
197
|
-
? RawSubdocType[] | T[K]
|
|
232
|
+
? RawSubdocType[] | T[K] | QueryTypeCasting<Extract<T[K], TreatAsPrimitives>>
|
|
198
233
|
: NonNullable<T[K]> extends Document<any, any, infer RawSubdocType>
|
|
199
|
-
? CreateObjectWithExtraKeys<ApplyBasicCreateCasting<RawSubdocType>> | T[K]
|
|
234
|
+
? CreateObjectWithExtraKeys<ApplyBasicCreateCasting<RawSubdocType>> | T[K] | QueryTypeCasting<Extract<T[K], TreatAsPrimitives>>
|
|
200
235
|
: NonNullable<T[K]> extends TreatAsPrimitives
|
|
201
236
|
? QueryTypeCasting<T[K]>
|
|
202
237
|
: NonNullable<T[K]> extends object
|
|
203
|
-
? CreateObjectWithExtraKeys<ApplyBasicCreateCasting<T[K]>> | T[K]
|
|
238
|
+
? CreateObjectWithExtraKeys<ApplyBasicCreateCasting<T[K]>> | T[K] | QueryTypeCasting<Extract<T[K], TreatAsPrimitives>>
|
|
204
239
|
: QueryTypeCasting<T[K]>;
|
|
205
240
|
};
|
|
206
241
|
|
|
@@ -234,6 +269,9 @@ declare module 'mongoose' {
|
|
|
234
269
|
/** Base Mongoose instance the model uses. */
|
|
235
270
|
base: Mongoose;
|
|
236
271
|
|
|
272
|
+
/** Standard Schema adapter for validating input with this model's schema. */
|
|
273
|
+
readonly '~standard': StandardSchemaV1.Props<TRawDocType>;
|
|
274
|
+
|
|
237
275
|
/**
|
|
238
276
|
* If this is a discriminator model, `baseModelName` is the name of
|
|
239
277
|
* the base model.
|