mongoose 8.0.2 → 8.0.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.
Files changed (39) hide show
  1. package/dist/browser.umd.js +1 -1
  2. package/lib/cursor/changeStream.js +0 -12
  3. package/lib/document.js +19 -6
  4. package/lib/helpers/clone.js +1 -1
  5. package/lib/helpers/discriminator/applyEmbeddedDiscriminators.js +30 -0
  6. package/lib/helpers/document/applyDefaults.js +3 -1
  7. package/lib/helpers/indexes/getRelatedIndexes.js +5 -1
  8. package/lib/helpers/model/castBulkWrite.js +8 -6
  9. package/lib/helpers/populate/assignVals.js +5 -0
  10. package/lib/helpers/projection/hasIncludedChildren.js +1 -0
  11. package/lib/helpers/projection/isExclusive.js +2 -3
  12. package/lib/helpers/projection/isNestedProjection.js +8 -0
  13. package/lib/helpers/query/castUpdate.js +5 -1
  14. package/lib/model.js +3 -1
  15. package/lib/mongoose.js +3 -0
  16. package/lib/query.js +11 -36
  17. package/lib/queryHelpers.js +3 -2
  18. package/lib/schema/array.js +2 -2
  19. package/lib/schema/bigint.js +11 -4
  20. package/lib/schema/boolean.js +9 -4
  21. package/lib/schema/buffer.js +21 -12
  22. package/lib/schema/date.js +15 -8
  23. package/lib/schema/decimal128.js +7 -8
  24. package/lib/schema/documentArray.js +1 -7
  25. package/lib/schema/number.js +22 -13
  26. package/lib/schema/objectId.js +7 -7
  27. package/lib/schema/string.js +11 -3
  28. package/lib/schema/subdocument.js +3 -7
  29. package/lib/schema/uuid.js +12 -5
  30. package/lib/schema.js +11 -9
  31. package/lib/schemaType.js +8 -1
  32. package/lib/types/subdocument.js +3 -3
  33. package/lib/utils.js +0 -33
  34. package/package.json +8 -8
  35. package/types/document.d.ts +2 -2
  36. package/types/index.d.ts +3 -0
  37. package/types/inferschematype.d.ts +13 -12
  38. package/types/models.d.ts +21 -12
  39. package/types/query.d.ts +57 -39
package/types/query.d.ts CHANGED
@@ -95,81 +95,95 @@ declare module 'mongoose' {
95
95
  updatedAt?: boolean;
96
96
  }
97
97
 
98
- interface QueryOptions<DocType = unknown> extends
99
- PopulateOption,
100
- SessionOption {
101
- arrayFilters?: { [key: string]: any }[];
102
- batchSize?: number;
103
- collation?: mongodb.CollationOptions;
104
- comment?: any;
105
- context?: string;
106
- explain?: mongodb.ExplainVerbosityLike;
107
- fields?: any | string;
108
- hint?: mongodb.Hint;
98
+ interface MongooseSpecificQueryOptions {
109
99
  /**
110
100
  * If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.
111
101
  */
112
102
  lean?: boolean | Record<string, any>;
113
- limit?: number;
114
- maxTimeMS?: number;
115
- multi?: boolean;
103
+
116
104
  multipleCastError?: boolean;
117
- /**
118
- * By default, `findOneAndUpdate()` returns the document as it was **before**
119
- * `update` was applied. If you set `new: true`, `findOneAndUpdate()` will
120
- * instead give you the object after `update` was applied.
121
- */
122
- new?: boolean;
123
105
 
124
106
  overwriteDiscriminatorKey?: boolean;
125
- projection?: ProjectionType<DocType>;
126
- /**
127
- * if true, returns the full ModifyResult rather than just the document
128
- */
129
- includeResultMetadata?: boolean;
130
- readPreference?: string | mongodb.ReadPreferenceMode;
131
- /**
132
- * An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`.
133
- */
134
- returnOriginal?: boolean;
135
- /**
136
- * Another alias for the `new` option. `returnOriginal` is deprecated so this should be used.
137
- */
138
- returnDocument?: 'before' | 'after';
139
107
  /**
140
108
  * Set to true to enable `update validators`
141
109
  * (https://mongoosejs.com/docs/validation.html#update-validators). Defaults to false.
142
110
  */
143
111
  runValidators?: boolean;
144
- /* Set to `true` to automatically sanitize potentially unsafe user-generated query projections */
145
- sanitizeProjection?: boolean;
146
112
  /**
147
113
  * Set to `true` to automatically sanitize potentially unsafe query filters by stripping out query selectors that
148
114
  * aren't explicitly allowed using `mongoose.trusted()`.
149
115
  */
150
116
  sanitizeFilter?: boolean;
117
+ /* Set to `true` to automatically sanitize potentially unsafe user-generated query projections */
118
+ sanitizeProjection?: boolean;
151
119
  setDefaultsOnInsert?: boolean;
152
- skip?: number;
153
- sort?: any;
154
120
  /** overwrites the schema's strict mode option */
155
121
  strict?: boolean | string;
122
+
156
123
  /**
157
124
  * equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default
158
125
  * [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
159
126
  */
160
127
  strictQuery?: boolean | 'throw';
161
- tailable?: number;
162
128
  /**
163
129
  * If set to `false` and schema-level timestamps are enabled,
164
130
  * skip timestamps for this update. Note that this allows you to overwrite
165
131
  * timestamps. Does nothing if schema-level timestamps are not set.
166
132
  */
167
133
  timestamps?: boolean | QueryTimestampsConfig;
134
+
168
135
  /**
169
136
  * If `true`, convert any aliases in filter, projection, update, and distinct
170
137
  * to their database property names. Defaults to false.
171
138
  */
172
139
  translateAliases?: boolean;
140
+
141
+ [other: string]: any;
142
+ }
143
+
144
+ interface QueryOptions<DocType = unknown> extends
145
+ PopulateOption,
146
+ SessionOption,
147
+ MongooseSpecificQueryOptions {
148
+ arrayFilters?: { [key: string]: any }[];
149
+ batchSize?: number;
150
+ bypassDocumentValidation?: boolean;
151
+ collation?: mongodb.CollationOptions;
152
+ comment?: any;
153
+ context?: string;
154
+ explain?: mongodb.ExplainVerbosityLike;
155
+ fields?: any | string;
156
+ hint?: mongodb.Hint;
157
+
158
+ let?: Record<string, any>;
159
+ limit?: number;
160
+ maxTimeMS?: number;
161
+ multi?: boolean;
162
+ /**
163
+ * By default, `findOneAndUpdate()` returns the document as it was **before**
164
+ * `update` was applied. If you set `new: true`, `findOneAndUpdate()` will
165
+ * instead give you the object after `update` was applied.
166
+ */
167
+ new?: boolean;
168
+ projection?: ProjectionType<DocType>;
169
+ /**
170
+ * if true, returns the full ModifyResult rather than just the document
171
+ */
172
+ includeResultMetadata?: boolean;
173
+ readPreference?: string | mongodb.ReadPreferenceMode;
174
+ /**
175
+ * An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`.
176
+ */
177
+ returnOriginal?: boolean;
178
+ /**
179
+ * Another alias for the `new` option. `returnOriginal` is deprecated so this should be used.
180
+ */
181
+ returnDocument?: 'before' | 'after';
182
+ skip?: number;
183
+ sort?: any;
184
+
185
+ tailable?: number;
186
+
173
187
  upsert?: boolean;
174
188
  useBigInt64?: boolean;
175
189
  writeConcern?: mongodb.WriteConcern;
@@ -415,6 +429,10 @@ declare module 'mongoose' {
415
429
  ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
416
430
 
417
431
  /** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
432
+ findByIdAndDelete(
433
+ id: mongodb.ObjectId | any,
434
+ options: QueryOptions<DocType> & { includeResultMetadata: true }
435
+ ): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
418
436
  findByIdAndDelete(
419
437
  id?: mongodb.ObjectId | any,
420
438
  options?: QueryOptions<DocType> | null