mongoose 8.16.2 → 8.16.4
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 +3 -1
- package/lib/document.js +2 -0
- package/lib/schema/documentArray.js +2 -3
- package/package.json +1 -1
- package/types/document.d.ts +2 -2
- package/types/index.d.ts +28 -12
- package/types/inferschematype.d.ts +5 -4
- package/types/query.d.ts +1 -1
- package/types/schemaoptions.d.ts +4 -3
package/lib/connection.js
CHANGED
|
@@ -1324,8 +1324,10 @@ Connection.prototype.onClose = function onClose(force) {
|
|
|
1324
1324
|
|
|
1325
1325
|
this.emit('close', force);
|
|
1326
1326
|
|
|
1327
|
+
const wasForceClosed = typeof force === 'object' && force !== null ? force.force : force;
|
|
1328
|
+
|
|
1327
1329
|
for (const db of this.otherDbs) {
|
|
1328
|
-
this._destroyCalled ? db.destroy({ force:
|
|
1330
|
+
this._destroyCalled ? db.destroy({ force: wasForceClosed, skipCloseClient: true }) : db.close({ force: wasForceClosed, skipCloseClient: true });
|
|
1329
1331
|
}
|
|
1330
1332
|
};
|
|
1331
1333
|
|
package/lib/document.js
CHANGED
|
@@ -1517,6 +1517,8 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1517
1517
|
|
|
1518
1518
|
if (schema.$isSingleNested && (this.isDirectModified(path) || val == null)) {
|
|
1519
1519
|
cleanModifiedSubpaths(this, path);
|
|
1520
|
+
} else if (schema.$isSchemaMap && val == null) {
|
|
1521
|
+
cleanModifiedSubpaths(this, path);
|
|
1520
1522
|
}
|
|
1521
1523
|
|
|
1522
1524
|
return this;
|
|
@@ -62,6 +62,7 @@ function SchemaDocumentArray(key, schema, options, schemaOptions) {
|
|
|
62
62
|
SchemaArray.call(this, key, EmbeddedDocument, options);
|
|
63
63
|
|
|
64
64
|
this.schema = schema;
|
|
65
|
+
// EmbeddedDocument schematype options
|
|
65
66
|
this.schemaOptions = schemaOptions || {};
|
|
66
67
|
this.$isMongooseDocumentArray = true;
|
|
67
68
|
this.Constructor = EmbeddedDocument;
|
|
@@ -83,9 +84,7 @@ function SchemaDocumentArray(key, schema, options, schemaOptions) {
|
|
|
83
84
|
|
|
84
85
|
const $parentSchemaType = this;
|
|
85
86
|
this.$embeddedSchemaType = new DocumentArrayElement(key + '.$', {
|
|
86
|
-
|
|
87
|
-
this.schemaOptions &&
|
|
88
|
-
this.schemaOptions.required || false,
|
|
87
|
+
...(schemaOptions || {}),
|
|
89
88
|
$parentSchemaType
|
|
90
89
|
});
|
|
91
90
|
|
package/package.json
CHANGED
package/types/document.d.ts
CHANGED
|
@@ -45,8 +45,8 @@ declare module 'mongoose' {
|
|
|
45
45
|
/** Don't run validation on this path or persist changes to this path. */
|
|
46
46
|
$ignore(path: string): void;
|
|
47
47
|
|
|
48
|
-
/** Checks if a path is set to its default. */
|
|
49
|
-
$isDefault(path
|
|
48
|
+
/** Checks if a path is set to its default. If no path set, checks if any path is set to its default. */
|
|
49
|
+
$isDefault(path?: string): boolean;
|
|
50
50
|
|
|
51
51
|
/** Getter/setter, determines whether the document was removed or not. */
|
|
52
52
|
$isDeleted(val?: boolean): boolean;
|
package/types/index.d.ts
CHANGED
|
@@ -83,17 +83,17 @@ declare module 'mongoose' {
|
|
|
83
83
|
collection?: string,
|
|
84
84
|
options?: CompileModelOptions
|
|
85
85
|
): Model<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
InferSchemaType<TSchema>,
|
|
87
|
+
ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>,
|
|
88
|
+
ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>,
|
|
89
|
+
ObtainSchemaGeneric<TSchema, 'TVirtuals'>,
|
|
90
|
+
HydratedDocument<
|
|
91
|
+
InferSchemaType<TSchema>,
|
|
92
|
+
ObtainSchemaGeneric<TSchema, 'TVirtuals'> & ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>,
|
|
93
|
+
ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>,
|
|
94
|
+
ObtainSchemaGeneric<TSchema, 'TVirtuals'>
|
|
95
|
+
>,
|
|
96
|
+
TSchema
|
|
97
97
|
> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
|
|
98
98
|
|
|
99
99
|
export function model<T>(name: string, schema?: Schema<T, any, any> | Schema<T & Document, any, any>, collection?: string, options?: CompileModelOptions): Model<T>;
|
|
@@ -278,7 +278,23 @@ declare module 'mongoose' {
|
|
|
278
278
|
/**
|
|
279
279
|
* Create a new schema
|
|
280
280
|
*/
|
|
281
|
-
constructor(
|
|
281
|
+
constructor(
|
|
282
|
+
definition?: SchemaDefinition<SchemaDefinitionType<RawDocType>, RawDocType, THydratedDocumentType> | DocType,
|
|
283
|
+
options?: SchemaOptions<
|
|
284
|
+
FlatRecord<DocType>,
|
|
285
|
+
TInstanceMethods,
|
|
286
|
+
TQueryHelpers,
|
|
287
|
+
TStaticMethods,
|
|
288
|
+
TVirtuals,
|
|
289
|
+
THydratedDocumentType,
|
|
290
|
+
IfEquals<
|
|
291
|
+
TModelType,
|
|
292
|
+
Model<any, any, any, any>,
|
|
293
|
+
Model<DocType, TQueryHelpers, TInstanceMethods, TVirtuals, THydratedDocumentType>,
|
|
294
|
+
TModelType
|
|
295
|
+
>
|
|
296
|
+
> | ResolveSchemaOptions<TSchemaOptions>
|
|
297
|
+
);
|
|
282
298
|
|
|
283
299
|
/** Adds key path / schema type pairs to this schema. */
|
|
284
300
|
add(obj: SchemaDefinition<SchemaDefinitionType<RawDocType>, RawDocType> | Schema, prefix?: string): this;
|
|
@@ -56,8 +56,8 @@ declare module 'mongoose' {
|
|
|
56
56
|
* @param {TSchema} TSchema A generic of schema type instance.
|
|
57
57
|
* @param {alias} alias Targeted generic alias.
|
|
58
58
|
*/
|
|
59
|
-
type ObtainSchemaGeneric<TSchema, alias extends 'EnforcedDocType' | 'M' | 'TInstanceMethods' | 'TQueryHelpers' | 'TVirtuals' | 'TStaticMethods' | 'TSchemaOptions' | 'DocType'> =
|
|
60
|
-
TSchema extends Schema<infer EnforcedDocType, infer M, infer TInstanceMethods, infer TQueryHelpers, infer TVirtuals, infer TStaticMethods, infer TSchemaOptions, infer DocType>
|
|
59
|
+
type ObtainSchemaGeneric<TSchema, alias extends 'EnforcedDocType' | 'M' | 'TInstanceMethods' | 'TQueryHelpers' | 'TVirtuals' | 'TStaticMethods' | 'TSchemaOptions' | 'DocType' | 'THydratedDocumentType'> =
|
|
60
|
+
TSchema extends Schema<infer EnforcedDocType, infer M, infer TInstanceMethods, infer TQueryHelpers, infer TVirtuals, infer TStaticMethods, infer TSchemaOptions, infer DocType, infer THydratedDocumentType>
|
|
61
61
|
? {
|
|
62
62
|
EnforcedDocType: EnforcedDocType;
|
|
63
63
|
M: M;
|
|
@@ -67,6 +67,7 @@ declare module 'mongoose' {
|
|
|
67
67
|
TStaticMethods: TStaticMethods;
|
|
68
68
|
TSchemaOptions: TSchemaOptions;
|
|
69
69
|
DocType: DocType;
|
|
70
|
+
THydratedDocumentType: THydratedDocumentType;
|
|
70
71
|
}[alias]
|
|
71
72
|
: unknown;
|
|
72
73
|
|
|
@@ -107,7 +108,7 @@ type IsPathDefaultUndefined<PathType> = PathType extends { default: undefined }
|
|
|
107
108
|
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
108
109
|
*/
|
|
109
110
|
type IsPathRequired<P, TypeKey extends string = DefaultTypeKey> =
|
|
110
|
-
P extends { required: true | [true, string | undefined] | { isRequired: true } } | ArrayConstructor | any[]
|
|
111
|
+
P extends { required: true | string | [true, string | undefined] | { isRequired: true } } | ArrayConstructor | any[]
|
|
111
112
|
? true
|
|
112
113
|
: P extends { required: boolean }
|
|
113
114
|
? P extends { required: false }
|
|
@@ -203,7 +204,7 @@ TypeHint<PathValueType>
|
|
|
203
204
|
* @param {T} T A generic refers to string path enums.
|
|
204
205
|
* @returns Path enum values type as literal strings or string.
|
|
205
206
|
*/
|
|
206
|
-
type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends ReadonlyArray<infer E> ? E : T extends { values: any } ? PathEnumOrString<T['values']> : string;
|
|
207
|
+
type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends ReadonlyArray<infer E> ? E : T extends { values: any } ? PathEnumOrString<T['values']> : T extends Record<string, infer V> ? V : string;
|
|
207
208
|
|
|
208
209
|
type IsSchemaTypeFromBuiltinClass<T> = T extends (typeof String)
|
|
209
210
|
? true
|
package/types/query.d.ts
CHANGED
|
@@ -758,7 +758,7 @@ declare module 'mongoose' {
|
|
|
758
758
|
|
|
759
759
|
/** Specifies which document fields to include or exclude (also known as the query "projection") */
|
|
760
760
|
select<RawDocTypeOverride extends { [P in keyof RawDocType]?: any } = {}>(
|
|
761
|
-
arg: string | string[] | Record<string, number | boolean | string | object>
|
|
761
|
+
arg: string | readonly string[] | Record<string, number | boolean | string | object>
|
|
762
762
|
): QueryWithHelpers<
|
|
763
763
|
IfEquals<
|
|
764
764
|
RawDocTypeOverride,
|
package/types/schemaoptions.d.ts
CHANGED
|
@@ -16,7 +16,8 @@ declare module 'mongoose' {
|
|
|
16
16
|
QueryHelpers = {},
|
|
17
17
|
TStaticMethods = {},
|
|
18
18
|
TVirtuals = {},
|
|
19
|
-
THydratedDocumentType = HydratedDocument<DocType, TInstanceMethods, QueryHelpers
|
|
19
|
+
THydratedDocumentType = HydratedDocument<DocType, TInstanceMethods, QueryHelpers>,
|
|
20
|
+
TModelType = Model<DocType, QueryHelpers, TInstanceMethods, TVirtuals, THydratedDocumentType>
|
|
20
21
|
> {
|
|
21
22
|
/**
|
|
22
23
|
* By default, Mongoose's init() function creates all the indexes defined in your model's schema by
|
|
@@ -219,8 +220,8 @@ declare module 'mongoose' {
|
|
|
219
220
|
statics?: IfEquals<
|
|
220
221
|
TStaticMethods,
|
|
221
222
|
{},
|
|
222
|
-
{ [name: string]: (this:
|
|
223
|
-
AddThisParameter<TStaticMethods,
|
|
223
|
+
{ [name: string]: (this: TModelType, ...args: any[]) => unknown },
|
|
224
|
+
AddThisParameter<TStaticMethods, TModelType>
|
|
224
225
|
>
|
|
225
226
|
|
|
226
227
|
/**
|