mongoose 6.2.10 → 6.3.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 (46) hide show
  1. package/.eslintrc.json +157 -157
  2. package/dist/browser.umd.js +2 -1693
  3. package/lib/aggregate.js +23 -31
  4. package/lib/collection.js +0 -7
  5. package/lib/cursor/ChangeStream.js +42 -2
  6. package/lib/cursor/QueryCursor.js +2 -0
  7. package/lib/document.js +13 -19
  8. package/lib/error/cast.js +7 -2
  9. package/lib/error/eachAsyncMultiError.js +41 -0
  10. package/lib/helpers/cursor/eachAsync.js +44 -12
  11. package/lib/helpers/indexes/applySchemaCollation.js +13 -0
  12. package/lib/helpers/indexes/isTextIndex.js +16 -0
  13. package/lib/helpers/model/discriminator.js +1 -3
  14. package/lib/helpers/populate/getModelsMapForPopulate.js +13 -10
  15. package/lib/helpers/query/applyGlobalOption.js +29 -0
  16. package/lib/helpers/query/castUpdate.js +3 -1
  17. package/lib/helpers/schematype/handleImmutable.js +4 -1
  18. package/lib/helpers/timestamps/setupTimestamps.js +2 -2
  19. package/lib/helpers/update/applyTimestampsToChildren.js +2 -2
  20. package/lib/helpers/update/applyTimestampsToUpdate.js +0 -1
  21. package/lib/index.js +11 -4
  22. package/lib/model.js +36 -36
  23. package/lib/query.js +59 -26
  24. package/lib/queryhelpers.js +11 -1
  25. package/lib/schema/SubdocumentPath.js +2 -1
  26. package/lib/schema/documentarray.js +2 -4
  27. package/lib/schema/objectid.js +0 -3
  28. package/lib/schema/string.js +24 -2
  29. package/lib/schema.js +117 -3
  30. package/lib/schematype.js +2 -3
  31. package/lib/types/DocumentArray/methods/index.js +1 -1
  32. package/lib/types/array/methods/index.js +9 -10
  33. package/lib/types/subdocument.js +29 -0
  34. package/lib/validoptions.js +1 -0
  35. package/package.json +13 -7
  36. package/tools/repl.js +2 -1
  37. package/tsconfig.json +2 -1
  38. package/types/aggregate.d.ts +223 -0
  39. package/types/connection.d.ts +2 -2
  40. package/types/cursor.d.ts +10 -4
  41. package/types/document.d.ts +3 -3
  42. package/types/index.d.ts +200 -215
  43. package/types/mongooseoptions.d.ts +10 -4
  44. package/CHANGELOG.md +0 -7227
  45. package/History.md +0 -1
  46. package/lib/helpers/query/applyGlobalMaxTimeMS.js +0 -15
@@ -197,7 +197,7 @@ declare module 'mongoose' {
197
197
  * async function executes successfully and attempt to retry if
198
198
  * there was a retryable error.
199
199
  */
200
- transaction<U = any>(fn: (session: mongodb.ClientSession) => Promise<U>): Promise<U>;
200
+ transaction(fn: (session: mongodb.ClientSession) => Promise<any>): Promise<void>;
201
201
 
202
202
  /** Switches to a different database using the same connection pool. */
203
203
  useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;
@@ -206,7 +206,7 @@ declare module 'mongoose' {
206
206
  readonly user: string;
207
207
 
208
208
  /** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model.watch). */
209
- watch<ResultType = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
209
+ watch<ResultType extends mongodb.Document = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
210
210
  }
211
211
 
212
212
  }
package/types/cursor.d.ts CHANGED
@@ -3,6 +3,12 @@ import stream = require('stream');
3
3
  declare module 'mongoose' {
4
4
  type CursorFlag = 'tailable' | 'oplogReplay' | 'noCursorTimeout' | 'awaitData' | 'partial';
5
5
 
6
+ interface EachAsyncOptions {
7
+ parallel?: number;
8
+ batchSize?: number;
9
+ continueOnError?: boolean;
10
+ }
11
+
6
12
  class Cursor<DocType = any, Options = never> extends stream.Readable {
7
13
  [Symbol.asyncIterator](): AsyncIterableIterator<DocType>;
8
14
 
@@ -25,10 +31,10 @@ declare module 'mongoose' {
25
31
  * will wait for the promise to resolve before iterating on to the next one.
26
32
  * Returns a promise that resolves when done.
27
33
  */
28
- eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }, callback: CallbackWithoutResult): void;
29
- eachAsync(fn: (doc: DocType) => any, options: { parallel?: number }, callback: CallbackWithoutResult): void;
30
- eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }): Promise<void>;
31
- eachAsync(fn: (doc: DocType) => any, options?: { parallel?: number }): Promise<void>;
34
+ eachAsync(fn: (doc: DocType[]) => any, options: EachAsyncOptions & { batchSize: number }, callback: CallbackWithoutResult): void;
35
+ eachAsync(fn: (doc: DocType) => any, options: EachAsyncOptions, callback: CallbackWithoutResult): void;
36
+ eachAsync(fn: (doc: DocType[]) => any, options: EachAsyncOptions & { batchSize: number }): Promise<void>;
37
+ eachAsync(fn: (doc: DocType) => any, options?: EachAsyncOptions): Promise<void>;
32
38
 
33
39
  /**
34
40
  * Registers a transform function which subsequently maps documents retrieved
@@ -49,6 +49,9 @@ declare module 'mongoose' {
49
49
  /** Marks a path as valid, removing existing validation errors. */
50
50
  $markValid(path: string): void;
51
51
 
52
+ /** Returns the model with the given name on this document's associated connection. */
53
+ $model<ModelType = Model<unknown>>(name: string): ModelType;
54
+
52
55
  /**
53
56
  * A string containing the current operation that Mongoose is executing
54
57
  * on this document. Can be `null`, `'save'`, `'validate'`, or `'remove'`.
@@ -169,9 +172,6 @@ declare module 'mongoose' {
169
172
  /** The name of the model */
170
173
  modelName: string;
171
174
 
172
- /** Returns the model with the given name on this document's associated connection. */
173
- model<ModelType = Model<unknown>>(name: string): ModelType;
174
-
175
175
  /**
176
176
  * Overwrite all values in this document with the values of `obj`, except
177
177
  * for immutable properties. Behaves similarly to `set()`, except for it