mongoose 8.23.1 → 8.24.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/lib/aggregate.js +24 -1
- package/lib/cursor/changeStream.js +41 -3
- package/package.json +4 -4
- package/types/aggregate.d.ts +3 -0
- package/types/inferrawdoctype.d.ts +1 -1
- package/types/inferschematype.d.ts +1 -1
- package/types/pipelinestage.d.ts +3 -2
- package/types/schematypes.d.ts +1 -1
package/lib/aggregate.js
CHANGED
|
@@ -1027,7 +1027,7 @@ Aggregate.prototype.search = function(options) {
|
|
|
1027
1027
|
*
|
|
1028
1028
|
* MyModel.aggregate().match({ test: 1 }).pipeline(); // [{ $match: { test: 1 } }]
|
|
1029
1029
|
*
|
|
1030
|
-
* @return {
|
|
1030
|
+
* @return {PipelineStage[]} The current pipeline similar to the operation that will be executed
|
|
1031
1031
|
* @api public
|
|
1032
1032
|
*/
|
|
1033
1033
|
|
|
@@ -1035,6 +1035,29 @@ Aggregate.prototype.pipeline = function() {
|
|
|
1035
1035
|
return this._pipeline;
|
|
1036
1036
|
};
|
|
1037
1037
|
|
|
1038
|
+
/**
|
|
1039
|
+
* Returns the current pipeline as a `$unionWith`-safe pipeline.
|
|
1040
|
+
* Throws if this pipeline contains `$out` or `$merge`.
|
|
1041
|
+
*
|
|
1042
|
+
* #### Example:
|
|
1043
|
+
*
|
|
1044
|
+
* const base = MyModel.aggregate().match({ test: 1 });
|
|
1045
|
+
* base.pipelineForUnionWith(); // [{ $match: { test: 1 } }]
|
|
1046
|
+
*
|
|
1047
|
+
* @return {PipelineStage[]} The current pipeline with `$unionWith` stage restrictions
|
|
1048
|
+
* @api public
|
|
1049
|
+
*/
|
|
1050
|
+
|
|
1051
|
+
Aggregate.prototype.pipelineForUnionWith = function pipelineForUnionWith() {
|
|
1052
|
+
for (const stage of this._pipeline) {
|
|
1053
|
+
if (stage?.$out != null || stage?.$merge != null) {
|
|
1054
|
+
throw new MongooseError('Aggregate pipeline for $unionWith cannot include `$out` or `$merge` stages');
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
return this._pipeline;
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1038
1061
|
/**
|
|
1039
1062
|
* Executes the aggregate pipeline on the currently bound Model.
|
|
1040
1063
|
*
|
|
@@ -114,7 +114,20 @@ class ChangeStream extends EventEmitter {
|
|
|
114
114
|
if (this.errored) {
|
|
115
115
|
throw new MongooseError('Cannot call hasNext() on errored ChangeStream');
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
|
|
118
|
+
if (this.driverChangeStream != null) {
|
|
119
|
+
return this.driverChangeStream.hasNext(cb);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return this.$driverChangeStreamPromise.then(
|
|
123
|
+
() => this.driverChangeStream.hasNext(cb),
|
|
124
|
+
err => {
|
|
125
|
+
if (cb != null) {
|
|
126
|
+
return cb(err);
|
|
127
|
+
}
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
);
|
|
118
131
|
}
|
|
119
132
|
|
|
120
133
|
next(cb) {
|
|
@@ -135,7 +148,20 @@ class ChangeStream extends EventEmitter {
|
|
|
135
148
|
};
|
|
136
149
|
}
|
|
137
150
|
|
|
138
|
-
let maybePromise
|
|
151
|
+
let maybePromise;
|
|
152
|
+
if (this.driverChangeStream != null) {
|
|
153
|
+
maybePromise = this.driverChangeStream.next(cb);
|
|
154
|
+
} else {
|
|
155
|
+
maybePromise = this.$driverChangeStreamPromise.then(
|
|
156
|
+
() => this.driverChangeStream.next(cb),
|
|
157
|
+
err => {
|
|
158
|
+
if (cb != null) {
|
|
159
|
+
return cb(err);
|
|
160
|
+
}
|
|
161
|
+
throw err;
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
}
|
|
139
165
|
if (maybePromise && typeof maybePromise.then === 'function') {
|
|
140
166
|
maybePromise = maybePromise.then(data => {
|
|
141
167
|
if (data.fullDocument != null) {
|
|
@@ -147,7 +173,19 @@ class ChangeStream extends EventEmitter {
|
|
|
147
173
|
return maybePromise;
|
|
148
174
|
}
|
|
149
175
|
|
|
150
|
-
|
|
176
|
+
if (this.driverChangeStream != null) {
|
|
177
|
+
return this.driverChangeStream.next(cb);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return this.$driverChangeStreamPromise.then(
|
|
181
|
+
() => this.driverChangeStream.next(cb),
|
|
182
|
+
err => {
|
|
183
|
+
if (cb != null) {
|
|
184
|
+
return cb(err);
|
|
185
|
+
}
|
|
186
|
+
throw err;
|
|
187
|
+
}
|
|
188
|
+
);
|
|
151
189
|
}
|
|
152
190
|
|
|
153
191
|
addListener(event, handler) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.24.0",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
|
37
37
|
"@typescript-eslint/parser": "^8.19.1",
|
|
38
38
|
"acquit": "1.4.0",
|
|
39
|
-
"acquit-ignore": "0.2.
|
|
39
|
+
"acquit-ignore": "0.2.2",
|
|
40
40
|
"acquit-require": "0.1.1",
|
|
41
|
-
"ajv": "8.
|
|
41
|
+
"ajv": "8.20.0",
|
|
42
42
|
"assert-browserify": "2.0.0",
|
|
43
43
|
"babel-loader": "8.2.5",
|
|
44
44
|
"broken-link-checker": "^0.7.8",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"tsd": "0.33.0",
|
|
71
71
|
"typescript": "5.9.3",
|
|
72
72
|
"uuid": "11.1.0",
|
|
73
|
-
"webpack": "5.
|
|
73
|
+
"webpack": "5.106.2"
|
|
74
74
|
},
|
|
75
75
|
"directories": {
|
|
76
76
|
"lib": "./lib/mongoose"
|
package/types/aggregate.d.ts
CHANGED
|
@@ -123,6 +123,9 @@ declare module 'mongoose' {
|
|
|
123
123
|
/** Returns the current pipeline */
|
|
124
124
|
pipeline(): PipelineStage[];
|
|
125
125
|
|
|
126
|
+
/** Returns the current pipeline typed for use in `$unionWith` */
|
|
127
|
+
pipelineForUnionWith(): PipelineStage.UnionWithPipelineStage[];
|
|
128
|
+
|
|
126
129
|
/** Appends a new $project operator to this aggregate pipeline. */
|
|
127
130
|
project(arg: PipelineStage.Project['$project'] | string): this;
|
|
128
131
|
|
|
@@ -72,7 +72,7 @@ declare module 'mongoose' {
|
|
|
72
72
|
: // If the type key isn't callable, then this is an array of objects, in which case
|
|
73
73
|
// we need to call InferRawDocType to correctly infer its type.
|
|
74
74
|
Array<InferRawDocType<Item>>
|
|
75
|
-
: IsSchemaTypeFromBuiltinClass<Item> extends true ? ResolveRawPathType<Item, { enum: Options['enum'] }, TypeKey>[]
|
|
75
|
+
: IsSchemaTypeFromBuiltinClass<Item> extends true ? ResolveRawPathType<Item, { enum: Exclude<Options['enum'], undefined> }, TypeKey>[]
|
|
76
76
|
: IsItRecordAndNotAny<Item> extends true ?
|
|
77
77
|
Item extends Record<string, never> ?
|
|
78
78
|
ObtainRawDocumentPathType<Item, TypeKey>[]
|
|
@@ -287,7 +287,7 @@ type ResolvePathType<
|
|
|
287
287
|
: // If the type key isn't callable, then this is an array of objects, in which case
|
|
288
288
|
// we need to call ObtainDocumentType to correctly infer its type.
|
|
289
289
|
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>>
|
|
290
|
-
: IsSchemaTypeFromBuiltinClass<Item> extends true ? ResolvePathType<Item, { enum: Options['enum'] }, TypeKey>[]
|
|
290
|
+
: IsSchemaTypeFromBuiltinClass<Item> extends true ? ResolvePathType<Item, { enum: Exclude<Options['enum'], undefined> }, TypeKey>[]
|
|
291
291
|
: IsItRecordAndNotAny<Item> extends true ?
|
|
292
292
|
Item extends Record<string, never> ?
|
|
293
293
|
ObtainDocumentPathType<Item, TypeKey>[]
|
package/types/pipelinestage.d.ts
CHANGED
|
@@ -115,6 +115,7 @@ declare module 'mongoose' {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
export type FacetPipelineStage = Exclude<PipelineStage, PipelineStage.CollStats | PipelineStage.Facet | PipelineStage.GeoNear | PipelineStage.IndexStats | PipelineStage.Out | PipelineStage.Merge | PipelineStage.PlanCacheStats>;
|
|
118
|
+
export type UnionWithPipelineStage = Exclude<PipelineStage, PipelineStage.Out | PipelineStage.Merge>;
|
|
118
119
|
|
|
119
120
|
export interface GeoNear {
|
|
120
121
|
/** [`$geoNear` reference](https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/) */
|
|
@@ -303,8 +304,8 @@ declare module 'mongoose' {
|
|
|
303
304
|
/** [`$unionWith` reference](https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/) */
|
|
304
305
|
$unionWith:
|
|
305
306
|
| string
|
|
306
|
-
| { coll: string; pipeline?:
|
|
307
|
-
| { coll?: string; pipeline:
|
|
307
|
+
| { coll: string; pipeline?: UnionWithPipelineStage[] }
|
|
308
|
+
| { coll?: string; pipeline: UnionWithPipelineStage[] }
|
|
308
309
|
}
|
|
309
310
|
|
|
310
311
|
export interface Unset {
|
package/types/schematypes.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ declare module 'mongoose' {
|
|
|
110
110
|
* The default value for this path. If a function, Mongoose executes the function
|
|
111
111
|
* and uses the return value as the default.
|
|
112
112
|
*/
|
|
113
|
-
default?: DefaultType<T> | ((this: EnforcedDocType, doc: any) => DefaultType<T> | null | undefined) | null;
|
|
113
|
+
default?: DefaultType<T> | ((this: EnforcedDocType, doc: any) => DefaultType<T> | null | undefined) | null | undefined;
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* The model that `populate()` should use if populating this path.
|