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.
Files changed (41) hide show
  1. package/dist/browser.umd.js +1 -1
  2. package/lib/cast.js +2 -2
  3. package/lib/connection.js +32 -200
  4. package/lib/document.js +34 -42
  5. package/lib/drivers/node-mongodb-native/connection.js +247 -0
  6. package/lib/error/cast.js +10 -9
  7. package/lib/error/messages.js +1 -1
  8. package/lib/helpers/schema/applyWriteConcern.js +3 -0
  9. package/lib/helpers/schema/getPath.js +0 -1
  10. package/lib/helpers/schema/idGetter.js +12 -1
  11. package/lib/model.js +49 -18
  12. package/lib/query.js +36 -22
  13. package/lib/schema/SubdocumentPath.js +10 -4
  14. package/lib/schema/array.js +2 -0
  15. package/lib/schema/bigint.js +2 -0
  16. package/lib/schema/boolean.js +2 -0
  17. package/lib/schema/buffer.js +2 -0
  18. package/lib/schema/date.js +2 -0
  19. package/lib/schema/decimal128.js +2 -0
  20. package/lib/schema/documentarray.js +2 -0
  21. package/lib/schema/mixed.js +2 -0
  22. package/lib/schema/number.js +2 -0
  23. package/lib/schema/objectid.js +2 -0
  24. package/lib/schema/string.js +2 -0
  25. package/lib/schema/uuid.js +2 -0
  26. package/lib/schema.js +9 -7
  27. package/lib/schematype.js +20 -4
  28. package/lib/types/ArraySubdocument.js +9 -1
  29. package/lib/types/DocumentArray/methods/index.js +2 -2
  30. package/lib/types/array/methods/index.js +1 -1
  31. package/lib/types/subdocument.js +4 -0
  32. package/package.json +3 -3
  33. package/types/augmentations.d.ts +9 -0
  34. package/types/index.d.ts +12 -0
  35. package/types/inferschematype.d.ts +8 -7
  36. package/types/models.d.ts +7 -2
  37. package/types/query.d.ts +5 -1
  38. package/types/schemaoptions.d.ts +3 -0
  39. package/types/schematypes.d.ts +5 -1
  40. package/types/types.d.ts +0 -1
  41. 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: 'textScore' } } | [string, SortOrder][] | undefined | null): this;
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?: {
@@ -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
 
@@ -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
@@ -80,7 +80,6 @@ declare module 'mongoose' {
80
80
  }
81
81
 
82
82
  class ObjectId extends mongodb.ObjectId {
83
- _id: this;
84
83
  }
85
84
 
86
85
  class Subdocument<IdType = any> extends Document<IdType> {
@@ -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
- };