mongoose 6.3.8 → 6.4.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/.eslintrc.json +62 -34
- package/dist/browser.umd.js +68579 -2
- package/lib/connection.js +50 -9
- package/lib/document.js +49 -9
- package/lib/error/disconnected.js +3 -4
- package/lib/helpers/timestamps/setupTimestamps.js +4 -1
- package/lib/helpers/updateValidators.js +11 -18
- package/lib/index.js +108 -33
- package/lib/model.js +1 -1
- package/lib/query.js +61 -6
- package/lib/queryhelpers.js +5 -0
- package/lib/schema/array.js +1 -1
- package/lib/schema/date.js +2 -2
- package/lib/schema/documentarray.js +10 -0
- package/lib/schema/number.js +2 -2
- package/lib/schema/string.js +2 -2
- package/lib/schema.js +3 -4
- package/lib/statemachine.js +13 -0
- package/lib/utils.js +3 -0
- package/lib/validoptions.js +1 -0
- package/package.json +3 -3
- package/tsconfig.json +1 -0
- package/types/aggregate.d.ts +3 -0
- package/types/connection.d.ts +5 -0
- package/types/document.d.ts +13 -4
- package/types/expressions.d.ts +2882 -0
- package/types/index.d.ts +52 -23
- package/types/{indizes.d.ts → indexes.d.ts} +0 -0
- package/types/inferschematype.d.ts +155 -0
- package/types/models.d.ts +85 -70
- package/types/mongooseoptions.d.ts +8 -0
- package/types/pipelinestage.d.ts +76 -80
- package/types/query.d.ts +1 -1
- package/types/schemaoptions.d.ts +21 -3
- package/types/types.d.ts +3 -1
- package/types/utility.d.ts +2 -0
package/types/pipelinestage.d.ts
CHANGED
|
@@ -3,82 +3,82 @@ declare module 'mongoose' {
|
|
|
3
3
|
* [Stages reference](https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/#aggregation-pipeline-stages)
|
|
4
4
|
*/
|
|
5
5
|
export type PipelineStage =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
6
|
+
| PipelineStage.AddFields
|
|
7
|
+
| PipelineStage.Bucket
|
|
8
|
+
| PipelineStage.BucketAuto
|
|
9
|
+
| PipelineStage.CollStats
|
|
10
|
+
| PipelineStage.Count
|
|
11
|
+
| PipelineStage.Facet
|
|
12
|
+
| PipelineStage.GeoNear
|
|
13
|
+
| PipelineStage.GraphLookup
|
|
14
|
+
| PipelineStage.Group
|
|
15
|
+
| PipelineStage.IndexStats
|
|
16
|
+
| PipelineStage.Limit
|
|
17
|
+
| PipelineStage.ListSessions
|
|
18
|
+
| PipelineStage.Lookup
|
|
19
|
+
| PipelineStage.Match
|
|
20
|
+
| PipelineStage.Merge
|
|
21
|
+
| PipelineStage.Out
|
|
22
|
+
| PipelineStage.PlanCacheStats
|
|
23
|
+
| PipelineStage.Project
|
|
24
|
+
| PipelineStage.Redact
|
|
25
|
+
| PipelineStage.ReplaceRoot
|
|
26
|
+
| PipelineStage.ReplaceWith
|
|
27
|
+
| PipelineStage.Sample
|
|
28
|
+
| PipelineStage.Search
|
|
29
|
+
| PipelineStage.Set
|
|
30
|
+
| PipelineStage.SetWindowFields
|
|
31
|
+
| PipelineStage.Skip
|
|
32
|
+
| PipelineStage.Sort
|
|
33
|
+
| PipelineStage.SortByCount
|
|
34
|
+
| PipelineStage.UnionWith
|
|
35
|
+
| PipelineStage.Unset
|
|
36
|
+
| PipelineStage.Unwind;
|
|
37
37
|
|
|
38
38
|
export namespace PipelineStage {
|
|
39
39
|
export interface AddFields {
|
|
40
40
|
/** [`$addFields` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/) */
|
|
41
|
-
$addFields: Record<string,
|
|
41
|
+
$addFields: Record<string, AnyExpression>
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export interface Bucket {
|
|
45
45
|
/** [`$bucket` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucket/) */
|
|
46
46
|
$bucket: {
|
|
47
|
-
groupBy:
|
|
48
|
-
boundaries: any[]
|
|
47
|
+
groupBy: Expression;
|
|
48
|
+
boundaries: any[];
|
|
49
49
|
default?: any
|
|
50
|
-
output?: Record<string,
|
|
50
|
+
output?: Record<string, AccumulatorOperator>
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
export interface BucketAuto {
|
|
55
55
|
/** [`$bucketAuto` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/) */
|
|
56
56
|
$bucketAuto: {
|
|
57
|
-
groupBy:
|
|
58
|
-
buckets: number
|
|
59
|
-
output?: Record<string,
|
|
60
|
-
granularity?: 'R5' | 'R10' | 'R20' | 'R40' | 'R80' | '1-2-5' | 'E6' | 'E12' | 'E24' | 'E48' | 'E96' | 'E192' | 'POWERSOF2'
|
|
57
|
+
groupBy: Expression | Record<string, Expression>;
|
|
58
|
+
buckets: number;
|
|
59
|
+
output?: Record<string, AccumulatorOperator>;
|
|
60
|
+
granularity?: 'R5' | 'R10' | 'R20' | 'R40' | 'R80' | '1-2-5' | 'E6' | 'E12' | 'E24' | 'E48' | 'E96' | 'E192' | 'POWERSOF2';
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export interface CollStats {
|
|
65
65
|
/** [`$collStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/collStats/) */
|
|
66
66
|
$collStats: {
|
|
67
|
-
latencyStats?: { histograms?: boolean }
|
|
68
|
-
storageStats?: { scale?: number }
|
|
69
|
-
count?:
|
|
70
|
-
queryExecStats?:
|
|
67
|
+
latencyStats?: { histograms?: boolean };
|
|
68
|
+
storageStats?: { scale?: number };
|
|
69
|
+
count?: Record<string | number | symbol, never>;
|
|
70
|
+
queryExecStats?: Record<string | number | symbol, never>;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export interface Count {
|
|
75
75
|
/** [`$count` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/count/) */
|
|
76
|
-
$count: string
|
|
76
|
+
$count: string;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export interface Facet {
|
|
80
80
|
/** [`$facet` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/facet/) */
|
|
81
|
-
$facet: Record<string, FacetPipelineStage[]
|
|
81
|
+
$facet: Record<string, FacetPipelineStage[]>;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export type FacetPipelineStage = Exclude<PipelineStage, PipelineStage.CollStats | PipelineStage.Facet | PipelineStage.GeoNear | PipelineStage.IndexStats | PipelineStage.Out | PipelineStage.Merge | PipelineStage.PlanCacheStats>;
|
|
@@ -86,41 +86,41 @@ declare module 'mongoose' {
|
|
|
86
86
|
export interface GeoNear {
|
|
87
87
|
/** [`$geoNear` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/) */
|
|
88
88
|
$geoNear: {
|
|
89
|
-
near: { type: 'Point'; coordinates: [number, number] } | [number, number]
|
|
90
|
-
distanceField: string
|
|
91
|
-
distanceMultiplier?: number
|
|
92
|
-
includeLocs?: string
|
|
93
|
-
key?: string
|
|
94
|
-
maxDistance?: number
|
|
95
|
-
minDistance?: number
|
|
96
|
-
query?: AnyObject
|
|
97
|
-
spherical?: boolean
|
|
98
|
-
uniqueDocs?: boolean
|
|
89
|
+
near: { type: 'Point'; coordinates: [number, number] } | [number, number];
|
|
90
|
+
distanceField: string;
|
|
91
|
+
distanceMultiplier?: number;
|
|
92
|
+
includeLocs?: string;
|
|
93
|
+
key?: string;
|
|
94
|
+
maxDistance?: number;
|
|
95
|
+
minDistance?: number;
|
|
96
|
+
query?: AnyObject;
|
|
97
|
+
spherical?: boolean;
|
|
98
|
+
uniqueDocs?: boolean;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export interface GraphLookup {
|
|
103
103
|
/** [`$graphLookup` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/) */
|
|
104
104
|
$graphLookup: {
|
|
105
|
-
from: string
|
|
105
|
+
from: string;
|
|
106
106
|
startWith: any
|
|
107
|
-
connectFromField: string
|
|
108
|
-
connectToField: string
|
|
109
|
-
as: string
|
|
110
|
-
maxDepth?: number
|
|
111
|
-
depthField?: string
|
|
112
|
-
restrictSearchWithMatch?: AnyObject
|
|
107
|
+
connectFromField: string;
|
|
108
|
+
connectToField: string;
|
|
109
|
+
as: string;
|
|
110
|
+
maxDepth?: number;
|
|
111
|
+
depthField?: string;
|
|
112
|
+
restrictSearchWithMatch?: AnyObject;
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
export interface Group {
|
|
117
117
|
/** [`$group` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/group) */
|
|
118
|
-
$group: { _id: any } | { [key: string]:
|
|
118
|
+
$group: { _id: any } | { [key: string]: AccumulatorOperator }
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
export interface IndexStats {
|
|
122
122
|
/** [`$indexStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/) */
|
|
123
|
-
$indexStats:
|
|
123
|
+
$indexStats: Record<string | number | symbol, never>;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
export interface Limit {
|
|
@@ -147,7 +147,7 @@ declare module 'mongoose' {
|
|
|
147
147
|
|
|
148
148
|
export interface Match {
|
|
149
149
|
/** [`$match` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) */
|
|
150
|
-
$match:
|
|
150
|
+
$match: FilterQuery<any>;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
export interface Merge {
|
|
@@ -155,7 +155,7 @@ declare module 'mongoose' {
|
|
|
155
155
|
$merge: {
|
|
156
156
|
into: string | { db: string; coll: string }
|
|
157
157
|
on?: string | string[]
|
|
158
|
-
let?: Record<string,
|
|
158
|
+
let?: Record<string, Expression>
|
|
159
159
|
whenMatched?: 'replace' | 'keepExisting' | 'merge' | 'fail' | Extract<PipelineStage, PipelineStage.AddFields | PipelineStage.Set | PipelineStage.Project | PipelineStage.Unset | PipelineStage.ReplaceRoot | PipelineStage.ReplaceWith>[]
|
|
160
160
|
whenNotMatched?: 'insert' | 'discard' | 'fail'
|
|
161
161
|
}
|
|
@@ -168,27 +168,27 @@ declare module 'mongoose' {
|
|
|
168
168
|
|
|
169
169
|
export interface PlanCacheStats {
|
|
170
170
|
/** [`$planCacheStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/planCacheStats/) */
|
|
171
|
-
$planCacheStats:
|
|
171
|
+
$planCacheStats: Record<string | number | symbol, never>
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
export interface Project {
|
|
175
175
|
/** [`$project` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/project/) */
|
|
176
|
-
$project: { [field: string]:
|
|
176
|
+
$project: { [field: string]: AnyExpression | Expression | Project['$project'] }
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
export interface Redact {
|
|
180
180
|
/** [`$redact` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/redact/) */
|
|
181
|
-
$redact:
|
|
181
|
+
$redact: Expression;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
export interface ReplaceRoot {
|
|
185
185
|
/** [`$replaceRoot` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceRoot/) */
|
|
186
|
-
$replaceRoot: { newRoot:
|
|
186
|
+
$replaceRoot: { newRoot: AnyExpression }
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
export interface ReplaceWith {
|
|
190
190
|
/** [`$replaceWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/) */
|
|
191
|
-
$replaceWith:
|
|
191
|
+
$replaceWith: ObjectExpressionOperator;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
export interface Sample {
|
|
@@ -206,13 +206,13 @@ declare module 'mongoose' {
|
|
|
206
206
|
maxCharsToExamine?: number;
|
|
207
207
|
maxNumPassages?: number;
|
|
208
208
|
};
|
|
209
|
-
[
|
|
209
|
+
[operator: string]: any;
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
export interface Set {
|
|
214
214
|
/** [`$set` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/set/) */
|
|
215
|
-
$set: Record<string,
|
|
215
|
+
$set: Record<string, AnyExpression>
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
export interface SetWindowFields {
|
|
@@ -222,7 +222,7 @@ declare module 'mongoose' {
|
|
|
222
222
|
sortBy?: Record<string, 1 | -1>
|
|
223
223
|
output: Record<
|
|
224
224
|
string,
|
|
225
|
-
|
|
225
|
+
WindowOperator & {
|
|
226
226
|
window?: {
|
|
227
227
|
documents?: [string | number, string | number]
|
|
228
228
|
range?: [string | number, string | number]
|
|
@@ -240,12 +240,12 @@ declare module 'mongoose' {
|
|
|
240
240
|
|
|
241
241
|
export interface Sort {
|
|
242
242
|
/** [`$sort` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sort/) */
|
|
243
|
-
$sort: Record<string, 1 | -1 |
|
|
243
|
+
$sort: Record<string, 1 | -1 | Expression.Meta>
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
export interface SortByCount {
|
|
247
247
|
/** [`$sortByCount` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sortByCount/) */
|
|
248
|
-
$sortByCount:
|
|
248
|
+
$sortByCount: Expression;
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
export interface UnionWith {
|
|
@@ -264,9 +264,5 @@ declare module 'mongoose' {
|
|
|
264
264
|
/** [`$unwind` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/) */
|
|
265
265
|
$unwind: string | { path: string; includeArrayIndex?: string; preserveNullAndEmptyArrays?: boolean }
|
|
266
266
|
}
|
|
267
|
-
|
|
268
|
-
type AccumulatorOperator = '$accumulator' | '$addToSet' | '$avg' | '$count' | '$first' | '$last' | '$max' | '$mergeObjects' | '$min' | '$push' | '$stdDevPop' | '$stdDevSamp' | '$sum';
|
|
269
|
-
|
|
270
|
-
type WindowOperator = '$addToSet' | '$avg' | '$count' | '$covariancePop' | '$covarianceSamp' | '$derivative' | '$expMovingAvg' | '$integral' | '$max' | '$min' | '$push' | '$stdDevSamp' | '$stdDevPop' | '$sum' | '$first' | '$last' | '$shift' | '$denseRank' | '$documentNumber' | '$rank';
|
|
271
267
|
}
|
|
272
268
|
}
|
package/types/query.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare module 'mongoose' {
|
|
2
2
|
import mongodb = require('mongodb');
|
|
3
3
|
|
|
4
|
-
type ApplyBasicQueryCasting<T> = T | T[] | any;
|
|
4
|
+
export type ApplyBasicQueryCasting<T> = T | T[] | (T extends (infer U)[] ? U : any) | any;
|
|
5
5
|
type Condition<T> = ApplyBasicQueryCasting<T> | QuerySelector<ApplyBasicQueryCasting<T>>;
|
|
6
6
|
|
|
7
7
|
type _FilterQuery<T> = {
|
package/types/schemaoptions.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ declare module 'mongoose' {
|
|
|
7
7
|
currentTime?: () => (NativeDate | number);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
type TypeKeyBaseType = string;
|
|
11
|
+
|
|
12
|
+
type DefaultTypeKey = 'type';
|
|
13
|
+
interface SchemaOptions<PathTypeKey extends TypeKeyBaseType = DefaultTypeKey, DocType = unknown, InstanceMethods = {}, QueryHelpers = {}, StaticMethods = {}, virtuals = {}> {
|
|
11
14
|
/**
|
|
12
15
|
* By default, Mongoose's init() function creates all the indexes defined in your model's schema by
|
|
13
16
|
* calling Model.createIndexes() after you successfully connect to MongoDB. If you want to disable
|
|
@@ -136,7 +139,7 @@ declare module 'mongoose' {
|
|
|
136
139
|
* type declaration. However, for applications like geoJSON, the 'type' property is important. If you want to
|
|
137
140
|
* control which key mongoose uses to find type declarations, set the 'typeKey' schema option.
|
|
138
141
|
*/
|
|
139
|
-
typeKey?:
|
|
142
|
+
typeKey?: PathTypeKey;
|
|
140
143
|
|
|
141
144
|
/**
|
|
142
145
|
* By default, documents are automatically validated before they are saved to the database. This is to
|
|
@@ -183,6 +186,21 @@ declare module 'mongoose' {
|
|
|
183
186
|
* You can suppress the warning by setting { supressReservedKeysWarning: true } schema options. Keep in mind that this
|
|
184
187
|
* can break plugins that rely on these reserved names.
|
|
185
188
|
*/
|
|
186
|
-
supressReservedKeysWarning?: boolean
|
|
189
|
+
supressReservedKeysWarning?: boolean,
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Model Statics methods.
|
|
193
|
+
*/
|
|
194
|
+
statics?: Record<any, (this: Model<DocType>, ...args: any) => unknown> | StaticMethods,
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Document instance methods.
|
|
198
|
+
*/
|
|
199
|
+
methods?: Record<any, (this: HydratedDocument<DocType>, ...args: any) => unknown> | InstanceMethods,
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Query helper functions
|
|
203
|
+
*/
|
|
204
|
+
query?: Record<any, <T extends QueryWithHelpers<unknown, DocType>>(this: T, ...args: any) => T> | QueryHelpers,
|
|
187
205
|
}
|
|
188
206
|
}
|
package/types/types.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
declare module 'mongoose' {
|
|
3
3
|
import mongodb = require('mongodb');
|
|
4
4
|
|
|
5
|
+
class NativeBuffer extends Buffer {}
|
|
6
|
+
|
|
5
7
|
namespace Types {
|
|
6
8
|
class Array<T> extends global.Array<T> {
|
|
7
9
|
/** Pops the array atomically at most one time per document `save()`. */
|
|
@@ -47,7 +49,7 @@ declare module 'mongoose' {
|
|
|
47
49
|
unshift(...args: any[]): number;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
class Buffer extends
|
|
52
|
+
class Buffer extends NativeBuffer {
|
|
51
53
|
/** Sets the subtype option and marks the buffer modified. */
|
|
52
54
|
subtype(subtype: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128 | ToObjectOptions): void;
|
|
53
55
|
|