mongoose 7.3.4 → 7.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/dist/browser.umd.js +1 -1
- package/lib/cast.js +2 -2
- package/lib/connection.js +32 -200
- package/lib/document.js +34 -42
- package/lib/drivers/node-mongodb-native/connection.js +247 -0
- package/lib/error/cast.js +10 -9
- package/lib/error/messages.js +1 -1
- package/lib/helpers/schema/applyWriteConcern.js +3 -0
- package/lib/helpers/schema/getPath.js +0 -1
- package/lib/helpers/schema/idGetter.js +12 -1
- package/lib/model.js +49 -18
- package/lib/query.js +36 -22
- package/lib/schema/SubdocumentPath.js +10 -4
- package/lib/schema/array.js +2 -0
- package/lib/schema/bigint.js +2 -0
- package/lib/schema/boolean.js +2 -0
- package/lib/schema/buffer.js +2 -0
- package/lib/schema/date.js +2 -0
- package/lib/schema/decimal128.js +2 -0
- package/lib/schema/documentarray.js +2 -0
- package/lib/schema/mixed.js +2 -0
- package/lib/schema/number.js +2 -0
- package/lib/schema/objectid.js +2 -0
- package/lib/schema/string.js +2 -0
- package/lib/schema/uuid.js +2 -0
- package/lib/schema.js +9 -7
- package/lib/schematype.js +20 -4
- package/lib/types/ArraySubdocument.js +9 -1
- package/lib/types/DocumentArray/methods/index.js +2 -2
- package/lib/types/array/methods/index.js +1 -1
- package/lib/types/subdocument.js +4 -0
- package/package.json +3 -3
- package/types/augmentations.d.ts +9 -0
- package/types/index.d.ts +12 -0
- package/types/inferschematype.d.ts +8 -7
- package/types/models.d.ts +7 -2
- package/types/query.d.ts +5 -1
- package/types/schemaoptions.d.ts +3 -0
- package/types/schematypes.d.ts +5 -1
- package/types/types.d.ts +0 -1
- package/lib/helpers/path/flattenObjectWithDottedPaths.js +0 -39
package/types/query.d.ts
CHANGED
|
@@ -136,6 +136,10 @@ declare module 'mongoose' {
|
|
|
136
136
|
* Another alias for the `new` option. `returnOriginal` is deprecated so this should be used.
|
|
137
137
|
*/
|
|
138
138
|
returnDocument?: 'before' | 'after';
|
|
139
|
+
/**
|
|
140
|
+
* Set to true to enable `update validators`
|
|
141
|
+
* (https://mongoosejs.com/docs/validation.html#update-validators). Defaults to false.
|
|
142
|
+
*/
|
|
139
143
|
runValidators?: boolean;
|
|
140
144
|
/* Set to `true` to automatically sanitize potentially unsafe user-generated query projections */
|
|
141
145
|
sanitizeProjection?: boolean;
|
|
@@ -691,7 +695,7 @@ declare module 'mongoose' {
|
|
|
691
695
|
slice(val: number | Array<number>): this;
|
|
692
696
|
|
|
693
697
|
/** Sets the sort order. If an object is passed, values allowed are `asc`, `desc`, `ascending`, `descending`, `1`, and `-1`. */
|
|
694
|
-
sort(arg?: string | { [key: string]: SortOrder | { $meta:
|
|
698
|
+
sort(arg?: string | { [key: string]: SortOrder | { $meta: any } } | [string, SortOrder][] | undefined | null): this;
|
|
695
699
|
|
|
696
700
|
/** Sets the tailable option (for use with capped collections). */
|
|
697
701
|
tailable(bool?: boolean, opts?: {
|
package/types/schemaoptions.d.ts
CHANGED
|
@@ -49,6 +49,9 @@ declare module 'mongoose' {
|
|
|
49
49
|
/** Sets a default collation for every query and aggregation. */
|
|
50
50
|
collation?: mongodb.CollationOptions;
|
|
51
51
|
|
|
52
|
+
/** Arbitrary options passed to `createCollection()` */
|
|
53
|
+
collectionOptions?: mongodb.CreateCollectionOptions;
|
|
54
|
+
|
|
52
55
|
/** The timeseries option to use when creating the model's collection. */
|
|
53
56
|
timeseries?: mongodb.TimeSeriesCollectionOptions;
|
|
54
57
|
|
package/types/schematypes.d.ts
CHANGED
|
@@ -63,7 +63,11 @@ declare module 'mongoose' {
|
|
|
63
63
|
validate?: SchemaValidator<T> | AnyArray<SchemaValidator<T>>;
|
|
64
64
|
|
|
65
65
|
/** Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message. */
|
|
66
|
-
cast?: string
|
|
66
|
+
cast?: string |
|
|
67
|
+
boolean |
|
|
68
|
+
((value: any) => T) |
|
|
69
|
+
[(value: any) => T, string] |
|
|
70
|
+
[((value: any) => T) | null, (value: any, path: string, model: Model<any>, kind: string) => string];
|
|
67
71
|
|
|
68
72
|
/**
|
|
69
73
|
* If true, attach a required validator to this path, which ensures this path
|
package/types/types.d.ts
CHANGED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const MongooseError = require('../../error/mongooseError');
|
|
4
|
-
const isMongooseObject = require('../isMongooseObject');
|
|
5
|
-
const setDottedPath = require('../path/setDottedPath');
|
|
6
|
-
const util = require('util');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Given an object that may contain dotted paths, flatten the paths out.
|
|
10
|
-
* For example: `flattenObjectWithDottedPaths({ a: { 'b.c': 42 } })` => `{ a: { b: { c: 42 } } }`
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
module.exports = function flattenObjectWithDottedPaths(obj) {
|
|
14
|
-
if (obj == null || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
// Avoid Mongoose docs, like docs and maps, because these may cause infinite recursion
|
|
18
|
-
if (isMongooseObject(obj)) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const keys = Object.keys(obj);
|
|
22
|
-
for (const key of keys) {
|
|
23
|
-
const val = obj[key];
|
|
24
|
-
if (key.indexOf('.') !== -1) {
|
|
25
|
-
try {
|
|
26
|
-
delete obj[key];
|
|
27
|
-
setDottedPath(obj, key, val);
|
|
28
|
-
} catch (err) {
|
|
29
|
-
if (!(err instanceof TypeError)) {
|
|
30
|
-
throw err;
|
|
31
|
-
}
|
|
32
|
-
throw new MongooseError(`Conflicting dotted paths when setting document path, key: "${key}", value: ${util.inspect(val)}`);
|
|
33
|
-
}
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
flattenObjectWithDottedPaths(obj[key]);
|
|
38
|
-
}
|
|
39
|
-
};
|