@datanimbus/mongoose 6.13.13 → 9.13.2

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 (302) hide show
  1. package/README.md +80 -70
  2. package/eslint.config.mjs +202 -0
  3. package/index.js +2 -1
  4. package/lib/aggregate.js +276 -174
  5. package/lib/cast/bigint.js +46 -0
  6. package/lib/cast/boolean.js +3 -3
  7. package/lib/cast/decimal128.js +4 -1
  8. package/lib/cast/double.js +56 -0
  9. package/lib/cast/int32.js +42 -0
  10. package/lib/cast/number.js +6 -6
  11. package/lib/cast/objectid.js +3 -3
  12. package/lib/cast/string.js +3 -3
  13. package/lib/cast/uuid.js +35 -0
  14. package/lib/cast.js +100 -92
  15. package/lib/collection.js +31 -22
  16. package/lib/connection.js +792 -507
  17. package/lib/constants.js +73 -0
  18. package/lib/cursor/{AggregationCursor.js → aggregationCursor.js} +205 -52
  19. package/lib/cursor/changeStream.js +218 -0
  20. package/lib/cursor/queryCursor.js +676 -0
  21. package/lib/defaults/schemaDefaultsCache.js +62 -0
  22. package/lib/document.js +2419 -1306
  23. package/lib/drivers/node-mongodb-native/bulkWriteResult.js +5 -0
  24. package/lib/drivers/node-mongodb-native/collection.js +101 -135
  25. package/lib/drivers/node-mongodb-native/connection.js +386 -28
  26. package/lib/drivers/node-mongodb-native/index.js +3 -5
  27. package/lib/error/browserMissingSchema.js +5 -4
  28. package/lib/error/bulkSaveIncompleteError.js +44 -0
  29. package/lib/error/cast.js +30 -21
  30. package/lib/error/createCollectionsError.js +26 -0
  31. package/lib/error/divergentArray.js +11 -9
  32. package/lib/error/eachAsyncMultiError.js +2 -2
  33. package/lib/error/index.js +38 -29
  34. package/lib/error/invalidSchemaOption.js +32 -0
  35. package/lib/error/messages.js +4 -3
  36. package/lib/error/missingSchema.js +8 -6
  37. package/lib/error/notFound.js +7 -5
  38. package/lib/error/objectExpected.js +9 -8
  39. package/lib/error/objectParameter.js +12 -11
  40. package/lib/error/overwriteModel.js +7 -6
  41. package/lib/error/parallelSave.js +11 -8
  42. package/lib/error/parallelValidate.js +9 -7
  43. package/lib/error/serverSelection.js +1 -0
  44. package/lib/error/setOptionError.js +11 -9
  45. package/lib/error/strict.js +12 -10
  46. package/lib/error/strictPopulate.js +11 -9
  47. package/lib/error/syncIndexes.js +2 -2
  48. package/lib/error/validation.js +11 -17
  49. package/lib/error/validator.js +9 -8
  50. package/lib/error/version.js +12 -10
  51. package/lib/filters/operators.js +8 -0
  52. package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +4 -4
  53. package/lib/helpers/buildMiddlewareFilter.js +42 -0
  54. package/lib/helpers/clone.js +121 -35
  55. package/lib/helpers/common.js +7 -7
  56. package/lib/helpers/cursor/eachAsync.js +14 -11
  57. package/lib/helpers/cursor/waitForInitialization.js +17 -0
  58. package/lib/helpers/discriminator/applyEmbeddedDiscriminators.js +36 -0
  59. package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
  60. package/lib/helpers/discriminator/getConstructor.js +9 -6
  61. package/lib/helpers/discriminator/getDiscriminatorByKey.js +1 -1
  62. package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
  63. package/lib/helpers/discriminator/getDiscriminatorValueFromFilter.js +30 -0
  64. package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
  65. package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +41 -9
  66. package/lib/helpers/document/applyDefaults.js +82 -14
  67. package/lib/helpers/document/applyTimestamps.js +106 -0
  68. package/lib/helpers/document/applyVirtuals.js +147 -0
  69. package/lib/helpers/document/cleanModifiedSubpaths.js +14 -4
  70. package/lib/helpers/document/compile.js +20 -15
  71. package/lib/helpers/document/getDeepestSubdocumentForPath.js +38 -0
  72. package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +6 -3
  73. package/lib/helpers/document/handleSpreadDoc.js +2 -1
  74. package/lib/helpers/document/isInPathsToSave.js +24 -0
  75. package/lib/helpers/document/toObjectRecursive.js +49 -0
  76. package/lib/helpers/get.js +1 -1
  77. package/lib/helpers/getDefaultBulkwriteResult.js +11 -20
  78. package/lib/helpers/getInheritedProperty.js +28 -0
  79. package/lib/helpers/getOwnProperty.js +19 -0
  80. package/lib/helpers/indexes/applySchemaCollation.js +1 -1
  81. package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
  82. package/lib/helpers/indexes/getRelatedIndexes.js +8 -4
  83. package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
  84. package/lib/helpers/indexes/isIndexEqual.js +13 -12
  85. package/lib/helpers/indexes/isIndexSpecEqual.js +32 -0
  86. package/lib/helpers/indexes/isTimeseriesIndex.js +16 -0
  87. package/lib/helpers/isBsonType.js +3 -6
  88. package/lib/helpers/isMongooseDocument.js +24 -0
  89. package/lib/helpers/isMongooseObject.js +6 -4
  90. package/lib/helpers/isObject.js +2 -2
  91. package/lib/helpers/isPOJO.js +12 -0
  92. package/lib/helpers/isSimpleValidator.js +2 -2
  93. package/lib/helpers/minimize.js +41 -0
  94. package/lib/helpers/model/applyDefaultsToPOJO.js +2 -2
  95. package/lib/helpers/model/applyHooks.js +72 -54
  96. package/lib/helpers/model/applyMethods.js +3 -3
  97. package/lib/helpers/model/applyStaticHooks.js +20 -50
  98. package/lib/helpers/model/castBulkWrite.js +278 -172
  99. package/lib/helpers/model/decorateBulkWriteResult.js +8 -0
  100. package/lib/helpers/model/discriminator.js +77 -21
  101. package/lib/helpers/omitUndefined.js +20 -0
  102. package/lib/helpers/parallelLimit.js +61 -34
  103. package/lib/helpers/path/setDottedPath.js +1 -1
  104. package/lib/helpers/pathTrie.js +167 -0
  105. package/lib/helpers/pluralize.js +5 -4
  106. package/lib/helpers/populate/assignRawDocsToIdStructure.js +12 -7
  107. package/lib/helpers/populate/assignVals.js +46 -21
  108. package/lib/helpers/populate/createPopulateQueryFilter.js +13 -5
  109. package/lib/helpers/populate/getModelsMapForPopulate.js +250 -108
  110. package/lib/helpers/populate/getSchemaTypes.js +27 -30
  111. package/lib/helpers/populate/getVirtual.js +31 -0
  112. package/lib/helpers/populate/markArraySubdocsPopulated.js +6 -4
  113. package/lib/helpers/populate/modelNamesFromRefPath.js +11 -5
  114. package/lib/helpers/populate/removeDeselectedForeignField.js +3 -2
  115. package/lib/helpers/populate/setInheritedReadOptions.js +21 -0
  116. package/lib/helpers/populate/setPopulatedVirtualValue.js +33 -0
  117. package/lib/helpers/populate/splitPopulateQuery.js +81 -0
  118. package/lib/helpers/printJestWarning.js +1 -1
  119. package/lib/helpers/processConnectionOptions.js +7 -2
  120. package/lib/helpers/projection/applyProjection.js +8 -2
  121. package/lib/helpers/projection/hasIncludedChildren.js +1 -1
  122. package/lib/helpers/projection/isExclusive.js +8 -6
  123. package/lib/helpers/projection/isInclusive.js +2 -1
  124. package/lib/helpers/projection/isPathExcluded.js +3 -3
  125. package/lib/helpers/projection/isPathSelectedInclusive.js +1 -11
  126. package/lib/helpers/projection/isSubpath.js +1 -1
  127. package/lib/helpers/projection/parseProjection.js +9 -4
  128. package/lib/helpers/query/applyGlobalOption.js +9 -9
  129. package/lib/helpers/query/cast$expr.js +52 -23
  130. package/lib/helpers/query/castFilterPath.js +22 -22
  131. package/lib/helpers/query/castUpdate.js +207 -79
  132. package/lib/helpers/query/cloneMongooseOptions.js +44 -0
  133. package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +27 -13
  134. package/lib/helpers/query/handleImmutable.js +18 -2
  135. package/lib/helpers/query/handleReadPreferenceAliases.js +23 -0
  136. package/lib/helpers/query/sanitizeFilter.js +3 -2
  137. package/lib/helpers/query/selectPopulatedFields.js +13 -0
  138. package/lib/helpers/query/validOps.js +1 -22
  139. package/lib/helpers/schema/applyPlugins.js +2 -2
  140. package/lib/helpers/schema/applyReadConcern.js +20 -0
  141. package/lib/helpers/schema/applyWriteConcern.js +12 -3
  142. package/lib/helpers/schema/cleanPositionalOperators.js +5 -3
  143. package/lib/helpers/schema/getIndexes.js +20 -13
  144. package/lib/helpers/schema/getKeysInSchemaOrder.js +13 -16
  145. package/lib/helpers/schema/getPath.js +11 -3
  146. package/lib/helpers/schema/getSubdocumentStrictValue.js +32 -0
  147. package/lib/helpers/schema/handleIdOption.js +1 -1
  148. package/lib/helpers/schema/idGetter.js +7 -2
  149. package/lib/helpers/schema/merge.js +9 -1
  150. package/lib/helpers/schematype/getConditionalHandler.js +23 -0
  151. package/lib/helpers/schematype/handleImmutable.js +1 -1
  152. package/lib/helpers/setDefaultsOnInsert.js +85 -43
  153. package/lib/helpers/symbols.js +4 -4
  154. package/lib/helpers/timestamps/setDocumentTimestamps.js +2 -2
  155. package/lib/helpers/timestamps/setupTimestamps.js +69 -37
  156. package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
  157. package/lib/helpers/update/applyTimestampsToUpdate.js +53 -37
  158. package/lib/helpers/update/castArrayFilters.js +68 -29
  159. package/lib/helpers/update/decorateUpdateWithVersionKey.js +35 -0
  160. package/lib/helpers/update/modifiedPaths.js +2 -2
  161. package/lib/helpers/update/removeUnusedArrayFilters.js +11 -2
  162. package/lib/helpers/updateValidators.js +87 -128
  163. package/lib/index.js +6 -1320
  164. package/lib/internal.js +7 -1
  165. package/lib/model.js +2587 -2618
  166. package/lib/modifiedPathsSnapshot.js +9 -0
  167. package/lib/mongoose.js +1456 -0
  168. package/lib/options/saveOptions.js +2 -0
  169. package/lib/options/{SchemaArrayOptions.js → schemaArrayOptions.js} +16 -5
  170. package/lib/options/{SchemaBufferOptions.js → schemaBufferOptions.js} +2 -2
  171. package/lib/options/{SchemaDateOptions.js → schemaDateOptions.js} +1 -1
  172. package/lib/options/{SchemaDocumentArrayOptions.js → schemaDocumentArrayOptions.js} +24 -1
  173. package/lib/options/{SchemaMapOptions.js → schemaMapOptions.js} +1 -1
  174. package/lib/options/{SchemaNumberOptions.js → schemaNumberOptions.js} +5 -5
  175. package/lib/options/{SchemaObjectIdOptions.js → schemaObjectIdOptions.js} +4 -4
  176. package/lib/options/{SchemaStringOptions.js → schemaStringOptions.js} +10 -10
  177. package/lib/options/schemaSubdocumentOptions.js +89 -0
  178. package/lib/options/{SchemaTypeOptions.js → schemaTypeOptions.js} +28 -14
  179. package/lib/options/schemaUnionOptions.js +32 -0
  180. package/lib/options/{VirtualOptions.js → virtualOptions.js} +13 -13
  181. package/lib/options.js +4 -1
  182. package/lib/plugins/index.js +0 -2
  183. package/lib/plugins/saveSubdocs.js +85 -50
  184. package/lib/plugins/sharding.js +43 -15
  185. package/lib/plugins/trackTransaction.js +46 -34
  186. package/lib/query.js +1844 -1909
  187. package/lib/{queryhelpers.js → queryHelpers.js} +184 -81
  188. package/lib/schema/array.js +229 -169
  189. package/lib/schema/bigint.js +281 -0
  190. package/lib/schema/boolean.js +90 -26
  191. package/lib/schema/buffer.js +119 -50
  192. package/lib/schema/date.js +102 -38
  193. package/lib/schema/decimal128.js +88 -37
  194. package/lib/schema/{documentarray.js → documentArray.js} +259 -151
  195. package/lib/schema/documentArrayElement.js +180 -0
  196. package/lib/schema/double.js +244 -0
  197. package/lib/schema/index.js +12 -19
  198. package/lib/schema/int32.js +288 -0
  199. package/lib/schema/map.js +129 -20
  200. package/lib/schema/mixed.js +40 -26
  201. package/lib/schema/number.js +128 -51
  202. package/lib/schema/{objectid.js → objectId.js} +89 -47
  203. package/lib/schema/operators/exists.js +1 -1
  204. package/lib/schema/operators/geospatial.js +2 -2
  205. package/lib/schema/operators/text.js +4 -4
  206. package/lib/schema/string.js +125 -66
  207. package/lib/schema/subdocument.js +443 -0
  208. package/lib/schema/symbols.js +2 -0
  209. package/lib/schema/union.js +167 -0
  210. package/lib/schema/uuid.js +90 -120
  211. package/lib/schema.js +1267 -388
  212. package/lib/{schematype.js → schemaType.js} +481 -246
  213. package/lib/standardSchema/convertErrorToIssues.js +20 -0
  214. package/lib/{statemachine.js → stateMachine.js} +66 -17
  215. package/lib/tracing.js +38 -0
  216. package/lib/types/array/index.js +13 -10
  217. package/lib/types/array/methods/index.js +243 -63
  218. package/lib/types/{ArraySubdocument.js → arraySubdocument.js} +35 -14
  219. package/lib/types/buffer.js +31 -14
  220. package/lib/types/decimal128.js +1 -1
  221. package/lib/types/{DocumentArray → documentArray}/index.js +13 -13
  222. package/lib/types/{DocumentArray → documentArray}/methods/index.js +197 -31
  223. package/lib/types/double.js +13 -0
  224. package/lib/types/index.js +5 -2
  225. package/lib/types/map.js +62 -25
  226. package/lib/types/objectid.js +2 -2
  227. package/lib/types/subdocument.js +79 -58
  228. package/lib/types/uuid.js +13 -0
  229. package/lib/utils.js +201 -155
  230. package/lib/{validoptions.js → validOptions.js} +10 -2
  231. package/lib/{virtualtype.js → virtualType.js} +47 -18
  232. package/package.json +75 -92
  233. package/types/aggregate.d.ts +31 -7
  234. package/types/augmentations.d.ts +2 -2
  235. package/types/collection.d.ts +21 -16
  236. package/types/connection.d.ts +82 -27
  237. package/types/cursor.d.ts +15 -10
  238. package/types/document.d.ts +137 -56
  239. package/types/error.d.ts +11 -6
  240. package/types/expressions.d.ts +33 -2
  241. package/types/index.d.ts +805 -190
  242. package/types/indexes.d.ts +85 -13
  243. package/types/inferhydrateddoctype.d.ts +151 -0
  244. package/types/inferrawdoctype.d.ts +201 -0
  245. package/types/inferschematype.d.ts +287 -128
  246. package/types/middlewares.d.ts +50 -7
  247. package/types/models.d.ts +1555 -268
  248. package/types/mongooseoptions.d.ts +56 -7
  249. package/types/pipelinestage.d.ts +42 -3
  250. package/types/populate.d.ts +63 -1
  251. package/types/query.d.ts +592 -255
  252. package/types/schemaoptions.d.ts +78 -12
  253. package/types/schematypes.d.ts +254 -65
  254. package/types/session.d.ts +0 -4
  255. package/types/tracing.d.ts +10 -0
  256. package/types/types.d.ts +25 -8
  257. package/types/utility.d.ts +329 -30
  258. package/types/validation.d.ts +19 -14
  259. package/types/virtuals.d.ts +10 -10
  260. package/.eslintrc.js +0 -232
  261. package/.mocharc.yml +0 -4
  262. package/browser.js +0 -8
  263. package/lgtm.yml +0 -12
  264. package/lib/browser.js +0 -158
  265. package/lib/browserDocument.js +0 -101
  266. package/lib/cursor/ChangeStream.js +0 -154
  267. package/lib/cursor/QueryCursor.js +0 -545
  268. package/lib/document_provider.js +0 -30
  269. package/lib/drivers/browser/ReadPreference.js +0 -7
  270. package/lib/drivers/browser/binary.js +0 -14
  271. package/lib/drivers/browser/decimal128.js +0 -7
  272. package/lib/drivers/browser/index.js +0 -16
  273. package/lib/drivers/browser/objectid.js +0 -29
  274. package/lib/drivers/node-mongodb-native/ReadPreference.js +0 -47
  275. package/lib/drivers/node-mongodb-native/binary.js +0 -10
  276. package/lib/drivers/node-mongodb-native/decimal128.js +0 -7
  277. package/lib/drivers/node-mongodb-native/objectid.js +0 -16
  278. package/lib/error/disconnected.js +0 -33
  279. package/lib/helpers/printStrictQueryWarning.js +0 -11
  280. package/lib/helpers/promiseOrCallback.js +0 -55
  281. package/lib/helpers/query/applyQueryMiddleware.js +0 -79
  282. package/lib/helpers/query/completeMany.js +0 -52
  283. package/lib/helpers/query/wrapThunk.js +0 -36
  284. package/lib/options/SchemaSubdocumentOptions.js +0 -42
  285. package/lib/options/removeOptions.js +0 -14
  286. package/lib/plugins/removeSubdocs.js +0 -31
  287. package/lib/plugins/validateBeforeSave.js +0 -45
  288. package/lib/promise_provider.js +0 -49
  289. package/lib/schema/DocumentArrayElement.js +0 -100
  290. package/lib/schema/SubdocumentPath.js +0 -369
  291. package/scripts/build-browser.js +0 -18
  292. package/scripts/create-tarball.js +0 -7
  293. package/scripts/generateSearch.js +0 -154
  294. package/scripts/tsc-diagnostics-check.js +0 -15
  295. package/tools/auth.js +0 -31
  296. package/tools/repl.js +0 -35
  297. package/tools/sharded.js +0 -46
  298. package/tsconfig.json +0 -9
  299. /package/lib/{connectionstate.js → connectionState.js} +0 -0
  300. /package/lib/helpers/populate/{SkipPopulateValue.js → skipPopulateValue.js} +0 -0
  301. /package/lib/options/{PopulateOptions.js → populateOptions.js} +0 -0
  302. /package/lib/types/{DocumentArray → documentArray}/isMongooseDocumentArray.js +0 -0
@@ -1,5 +1,6 @@
1
- declare module 'mongoose' {
1
+ import { BSON } from 'mongodb';
2
2
 
3
+ declare module 'mongoose' {
3
4
  /** The Mongoose Date [SchemaType](/docs/schematypes.html). */
4
5
  type Date = Schema.Types.Date;
5
6
 
@@ -12,6 +13,15 @@ declare module 'mongoose' {
12
13
  */
13
14
  type Decimal128 = Schema.Types.Decimal128;
14
15
 
16
+ /**
17
+ * The Mongoose Int32 [SchemaType](/docs/schematypes.html). Used for
18
+ * declaring paths in your schema that should be
19
+ * 32-bit integers
20
+ * Do not use this to create a new Int32 instance, use `mongoose.Types.Int32`
21
+ * instead.
22
+ */
23
+ type Int32 = Schema.Types.Int32;
24
+
15
25
  /**
16
26
  * The Mongoose Mixed [SchemaType](/docs/schematypes.html). Used for
17
27
  * declaring paths in your schema that Mongoose's change tracking, casting,
@@ -25,6 +35,12 @@ declare module 'mongoose' {
25
35
  */
26
36
  type Number = Schema.Types.Number;
27
37
 
38
+ /**
39
+ * The Mongoose Double [SchemaType](/docs/schematypes.html). Used for
40
+ * declaring paths in your schema that Mongoose should cast to doubles (IEEE 754-2008)/
41
+ */
42
+ type Double = Schema.Types.Double;
43
+
28
44
  /**
29
45
  * The Mongoose ObjectId [SchemaType](/docs/schematypes.html). Used for
30
46
  * declaring paths in your schema that should be
@@ -39,49 +55,72 @@ declare module 'mongoose' {
39
55
 
40
56
  type DefaultType<T> = T extends Schema.Types.Mixed ? any : Partial<ExtractMongooseArray<T>>;
41
57
 
42
- class SchemaTypeOptions<T> {
43
- type?:
44
- T extends string ? StringSchemaDefinition :
45
- T extends number ? NumberSchemaDefinition :
46
- T extends boolean ? BooleanSchemaDefinition :
47
- T extends NativeDate ? DateSchemaDefinition :
48
- T extends Map<any, any> ? SchemaDefinition<typeof Map> :
49
- T extends Buffer ? SchemaDefinition<typeof Buffer> :
50
- T extends Types.ObjectId ? ObjectIdSchemaDefinition :
51
- T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId>> :
52
- T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>>>) :
53
- T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string>> :
54
- T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number>> :
55
- T extends boolean[] ? AnyArray<BooleanSchemaDefinition> | AnyArray<SchemaTypeOptions<boolean>> :
56
- T extends Function[] ? AnyArray<Function | string> | AnyArray<SchemaTypeOptions<Unpacked<T>>> :
57
- T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T> | Function | AnyArray<Function>;
58
+ class SchemaTypeOptions<T, EnforcedDocType = any, THydratedDocumentType = HydratedDocument<EnforcedDocType>> {
59
+ type?: T extends string ? StringSchemaDefinition
60
+ : T extends number ? NumberSchemaDefinition
61
+ : T extends boolean ? BooleanSchemaDefinition
62
+ : T extends NativeDate ? DateSchemaDefinition
63
+ : T extends Map<any, any> ? SchemaDefinition<typeof Map>
64
+ : T extends Buffer ? SchemaDefinition<typeof Buffer>
65
+ : T extends Types.ObjectId ? ObjectIdSchemaDefinition
66
+ : T extends Types.ObjectId[] ?
67
+ AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId, EnforcedDocType, THydratedDocumentType>>
68
+ : T extends object[] ?
69
+ | AnyArray<Schema<any, any, any>>
70
+ | AnyArray<SchemaDefinition<Unpacked<T>, EnforcedDocType, THydratedDocumentType>>
71
+ | AnyArray<SchemaTypeOptions<Unpacked<T>, EnforcedDocType, THydratedDocumentType>>
72
+ : T extends string[] ?
73
+ AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string, EnforcedDocType, THydratedDocumentType>>
74
+ : T extends number[] ?
75
+ AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number, EnforcedDocType, THydratedDocumentType>>
76
+ : T extends boolean[] ?
77
+ AnyArray<BooleanSchemaDefinition> | AnyArray<SchemaTypeOptions<boolean, EnforcedDocType, THydratedDocumentType>>
78
+ : T extends Function[] ?
79
+ AnyArray<Function | string> | AnyArray<SchemaTypeOptions<Unpacked<T>, EnforcedDocType, THydratedDocumentType>>
80
+ : T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T, EnforcedDocType, THydratedDocumentType> | Function | AnyArray<Function>;
58
81
 
59
82
  /** Defines a virtual with the given name that gets/sets this path. */
60
83
  alias?: string | string[];
61
84
 
62
85
  /** Function or object describing how to validate this schematype. See [validation docs](https://mongoosejs.com/docs/validation.html). */
63
- validate?: SchemaValidator<T> | AnyArray<SchemaValidator<T>>;
86
+ validate?: SchemaValidator<T, THydratedDocumentType> | AnyArray<SchemaValidator<T, THydratedDocumentType>>;
64
87
 
65
88
  /** Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message. */
66
- cast?: string;
89
+ cast?:
90
+ | string
91
+ | boolean
92
+ | ((value: any) => T)
93
+ | [(value: any) => T, string]
94
+ | [((value: any) => T) | null, (value: any, path: string, model: Model<any>, kind: string) => string];
67
95
 
68
96
  /**
69
97
  * If true, attach a required validator to this path, which ensures this path
70
- * path cannot be set to a nullish value. If a function, Mongoose calls the
98
+ * cannot be set to a nullish value. If a function, Mongoose calls the
71
99
  * function and only checks for nullish values if the function returns a truthy value.
72
100
  */
73
- required?: boolean | (() => boolean) | [boolean, string] | [() => boolean, string];
101
+ required?:
102
+ | boolean
103
+ | ((this: THydratedDocumentType) => boolean)
104
+ | [boolean, string]
105
+ | [(this: THydratedDocumentType) => boolean, string];
106
+
107
+ /**
108
+ * Controls whether this path may be set to `null`. By default, Mongoose allows
109
+ * `null` for non-required paths. Set `allowNull: false` to allow `undefined`
110
+ * but disallow `null`.
111
+ */
112
+ allowNull?: boolean;
74
113
 
75
114
  /**
76
115
  * The default value for this path. If a function, Mongoose executes the function
77
116
  * and uses the return value as the default.
78
117
  */
79
- default?: DefaultType<T> | ((this: any, doc: any) => DefaultType<T>) | null;
118
+ default?: DefaultType<T> | ((this: THydratedDocumentType, doc: THydratedDocumentType) => DefaultType<T> | null | undefined) | null | undefined;
80
119
 
81
120
  /**
82
121
  * The model that `populate()` should use if populating this path.
83
122
  */
84
- ref?: string | Model<any> | ((this: any, doc: any) => string | Model<any>);
123
+ ref?: string | Model<any, any, any, any> | ((this: any, doc: any) => string | Model<any, any, any, any>);
85
124
 
86
125
  /**
87
126
  * The path in the document that `populate()` should use to find the model
@@ -107,7 +146,7 @@ declare module 'mongoose' {
107
146
  * will build a unique index on this path when the
108
147
  * model is compiled. [The `unique` option is **not** a validator](/docs/validation.html#the-unique-option-is-not-a-validator).
109
148
  */
110
- unique?: boolean | number;
149
+ unique?: boolean | number | [true, string];
111
150
 
112
151
  /**
113
152
  * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
@@ -141,16 +180,35 @@ declare module 'mongoose' {
141
180
  set?: (value: any, priorVal?: T, doc?: this) => any;
142
181
 
143
182
  /** array of allowed values for this path. Allowed for strings, numbers, and arrays of strings */
144
- enum?: Array<string | number | null> | ReadonlyArray<string | number | null> | { values: Array<string | number | null> | ReadonlyArray<string | number | null>, message?: string } | { [path: string]: string | number | null };
183
+ enum?:
184
+ | Array<string | number | null>
185
+ | ReadonlyArray<string | number | null>
186
+ | { values: Array<string | number | null> | ReadonlyArray<string | number | null>; message?: string }
187
+ | { [path: string]: string | number | null };
145
188
 
146
189
  /** The default [subtype](http://bsonspec.org/spec.html) associated with this buffer when it is stored in MongoDB. Only allowed for buffer paths */
147
190
  subtype?: number;
148
191
 
149
192
  /** The minimum value allowed for this path. Only allowed for numbers and dates. */
150
- min?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string];
193
+ min?:
194
+ | number
195
+ | NativeDate
196
+ | [number, string | ValidatorMessageFn]
197
+ | [NativeDate, string]
198
+ | readonly [number, string | ValidatorMessageFn]
199
+ | readonly [NativeDate, string];
151
200
 
152
201
  /** The maximum value allowed for this path. Only allowed for numbers and dates. */
153
- max?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string];
202
+ max?:
203
+ | number
204
+ | NativeDate
205
+ | [number, string | ValidatorMessageFn]
206
+ | [NativeDate, string]
207
+ | readonly [number, string | ValidatorMessageFn]
208
+ | readonly [NativeDate, string];
209
+
210
+ /** Set to false to disable minimizing empty single nested subdocuments by default */
211
+ minimize?: boolean;
154
212
 
155
213
  /** Defines a TTL index on this path. Only allowed for dates. */
156
214
  expires?: string | number;
@@ -161,8 +219,11 @@ declare module 'mongoose' {
161
219
  /** If set, overrides the child schema's `_id` option. Only allowed for subdocuments and subdocument arrays. */
162
220
  _id?: boolean;
163
221
 
222
+ /** Embedded discriminators for this path. Only allowed for subdocuments and subdocument arrays. */
223
+ discriminators?: Record<string, Schema<unknown>>;
224
+
164
225
  /** If set, specifies the type of this map's values. Mongoose will cast this map's values to the given type. */
165
- of?: Function | SchemaDefinitionProperty<any>;
226
+ of?: Function | SchemaDefinitionProperty<any> | (Function | SchemaDefinitionProperty<any>)[];
166
227
 
167
228
  /** If true, uses Mongoose's default `_id` settings. Only allowed for ObjectIds */
168
229
  auto?: boolean;
@@ -170,28 +231,62 @@ declare module 'mongoose' {
170
231
  /** Attaches a validator that succeeds if the data string matches the given regular expression, and fails otherwise. */
171
232
  match?: RegExp | [RegExp, string] | readonly [RegExp, string];
172
233
 
173
- /** If truthy, Mongoose will add a custom setter that lowercases this string using JavaScript's built-in `String#toLowerCase()`. */
234
+ /** If truthy, Mongoose will add a [custom setter](https://mongoosejs.com/docs/api/schematype.html#SchemaType.prototype.set()) that lowercases this string using JavaScript's built-in `String#toLowerCase()`. */
174
235
  lowercase?: boolean;
175
236
 
176
- /** If truthy, Mongoose will add a custom setter that removes leading and trailing whitespace using JavaScript's built-in `String#trim()`. */
237
+ /** If truthy, Mongoose will add a [custom setter](https://mongoosejs.com/docs/api/schematype.html#SchemaType.prototype.set()) that removes leading and trailing whitespace using JavaScript's built-in `String#trim()`. */
177
238
  trim?: boolean;
178
239
 
179
- /** If truthy, Mongoose will add a custom setter that uppercases this string using JavaScript's built-in `String#toUpperCase()`. */
240
+ /** If truthy, Mongoose will add a [custom setter](https://mongoosejs.com/docs/api/schematype.html#SchemaType.prototype.set()) that uppercases this string using JavaScript's built-in `String#toUpperCase()`. */
180
241
  uppercase?: boolean;
181
242
 
182
243
  /** If set, Mongoose will add a custom validator that ensures the given string's `length` is at least the given number. */
183
- minlength?: number | [number, string] | readonly [number, string];
244
+ minlength?: number | [number, string | ValidatorMessageFn] | readonly [number, string | ValidatorMessageFn];
245
+ minLength?: number | [number, string | ValidatorMessageFn] | readonly [number, string | ValidatorMessageFn];
184
246
 
185
247
  /** If set, Mongoose will add a custom validator that ensures the given string's `length` is at most the given number. */
186
- maxlength?: number | [number, string] | readonly [number, string];
248
+ maxlength?: number | [number, string | ValidatorMessageFn] | readonly [number, string | ValidatorMessageFn];
249
+ maxLength?: number | [number, string | ValidatorMessageFn] | readonly [number, string | ValidatorMessageFn];
187
250
 
188
251
  [other: string]: any;
252
+
253
+ /**
254
+ * If set, configures the field for automatic encryption.
255
+ */
256
+ encrypt?: EncryptSchemaTypeOptions;
257
+ }
258
+
259
+ interface Validator<DocType = any> {
260
+ message?: string | ((props: ValidatorProps) => string);
261
+ type?: string;
262
+ validator?: ValidatorFunction<DocType>;
263
+ reason?: Error;
264
+ }
265
+
266
+ type ValidatorFunction<DocType = any> = (this: DocType, value: any, validatorProperties?: Validator) => any;
267
+
268
+ interface QueryEncryptionEncryptOptions {
269
+ /** The id of the dataKey to use for encryption. Must be a BSON binary subtype 4 (UUID). */
270
+ keyId: BSON.Binary;
271
+
272
+ /**
273
+ * Specifies the type of queries that the field can be queried on the encrypted field.
274
+ */
275
+ queries?: 'equality' | 'range';
189
276
  }
190
277
 
191
- interface Validator {
192
- message?: string; type?: string; validator?: Function
278
+ interface ClientSideEncryptionEncryptOptions {
279
+ /** The id of the dataKey to use for encryption. Must be a BSON binary subtype 4 (UUID). */
280
+ keyId: [BSON.Binary];
281
+
282
+ /**
283
+ * The algorithm to use for encryption.
284
+ */
285
+ algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' | 'AEAD_AES_256_CBC_HMAC_SHA_512-Random';
193
286
  }
194
287
 
288
+ export type EncryptSchemaTypeOptions = QueryEncryptionEncryptOptions | ClientSideEncryptionEncryptOptions;
289
+
195
290
  class SchemaType<T = any, DocType = any> {
196
291
  /** SchemaType constructor */
197
292
  constructor(path: string, options?: AnyObject, instance?: string);
@@ -207,11 +302,23 @@ declare module 'mongoose' {
207
302
  /** Attaches a getter for all instances of this schema type. */
208
303
  static get(getter: (value: any) => any): void;
209
304
 
305
+ /** Array containing default setters for all instances of this SchemaType */
306
+ static setters: ((
307
+ val?: unknown,
308
+ priorVal?: unknown,
309
+ doc?: Document<unknown>,
310
+ options?: Record<string, any> | null
311
+ ) => unknown)[];
312
+
313
+ /** Contains the handlers for different query operators for this schema type. */
314
+ $conditionalHandlers: { [op: string]: (val: any, context: any) => any };
315
+
210
316
  /** The class that Mongoose uses internally to instantiate this SchemaType's `options` property. */
211
317
  OptionsConstructor: SchemaTypeOptions<T>;
212
318
 
213
319
  /** Cast `val` to this schema type. Each class that inherits from schema type should implement this function. */
214
- cast(val: any, doc: Document<any>, init: boolean, prev?: any, options?: any): any;
320
+ cast(val: any, doc?: Document<any>, init?: boolean, prev?: any, options?: any): any;
321
+ cast<ResultType>(val: any, doc?: Document<any>, init?: boolean, prev?: any, options?: any): ResultType;
215
322
 
216
323
  /** Sets a default value for this SchemaType. */
217
324
  default(val: any): any;
@@ -219,6 +326,9 @@ declare module 'mongoose' {
219
326
  /** Adds a getter to this schematype. */
220
327
  get(fn: Function): this;
221
328
 
329
+ /** Gets this SchemaType's embedded SchemaType, if any */
330
+ getEmbeddedSchemaType<T = any, DocType = any>(): SchemaType<T, DocType> | undefined;
331
+
222
332
  /**
223
333
  * Defines this path as immutable. Mongoose prevents you from changing
224
334
  * immutable paths unless the parent document has [`isNew: true`](/docs/api/document.html#document_Document-isNew).
@@ -244,7 +354,7 @@ declare module 'mongoose' {
244
354
  * Set the model that this path refers to. This is the option that [populate](https://mongoosejs.com/docs/populate.html)
245
355
  * looks at to determine the foreign collection it should query.
246
356
  */
247
- ref(ref: string | boolean | Model<any>): this;
357
+ ref(ref: string | boolean | Model<any, any, any, any>): this;
248
358
 
249
359
  /**
250
360
  * Adds a required validator to this SchemaType. The validator gets added
@@ -252,8 +362,11 @@ declare module 'mongoose' {
252
362
  */
253
363
  required(required: boolean, message?: string): this;
254
364
 
255
- /** The schema this SchemaType instance is part of */
256
- schema: Schema<any>;
365
+ /** Adds or removes a validator that disallows `null` without making this path required. */
366
+ allowNull(allowNull: boolean): this;
367
+
368
+ /** If the SchemaType is a subdocument or document array, this is the schema of that subdocument */
369
+ schema?: Schema<any>;
257
370
 
258
371
  /** Sets default select() behavior for this path. */
259
372
  select(val: boolean): this;
@@ -267,6 +380,8 @@ declare module 'mongoose' {
267
380
  /** Declares a full text index. */
268
381
  text(bool: boolean): this;
269
382
 
383
+ toJSONSchema(options?: { useBsonType?: boolean }): Record<string, any>;
384
+
270
385
  /** Defines a custom function for transforming this path when converting a document to JSON. */
271
386
  transform(fn: (value: any) => any): this;
272
387
 
@@ -277,10 +392,13 @@ declare module 'mongoose' {
277
392
  validators: Validator[];
278
393
 
279
394
  /** Adds validator(s) for this document path. */
280
- validate(obj: RegExp | ((this: DocType, value: any, validatorProperties?: Validator) => any), errorMsg?: string, type?: string): this;
395
+ validate(obj: RegExp | ValidatorFunction<DocType> | Validator<DocType>, errorMsg?: string, type?: string): this;
396
+
397
+ /** Adds multiple validators for this document path. */
398
+ validateAll(validators: Array<RegExp | ValidatorFunction<DocType> | Validator<DocType>>): this;
281
399
 
282
400
  /** Default options for this SchemaType */
283
- defaultOptions?: Record<string, any>;
401
+ static defaultOptions?: Record<string, any>;
284
402
  }
285
403
 
286
404
  namespace Schema {
@@ -288,17 +406,18 @@ declare module 'mongoose' {
288
406
  class Array extends SchemaType implements AcceptsDiscriminator {
289
407
  /** This schema type's name, to defend against minifiers that mangle function names. */
290
408
  static schemaName: 'Array';
409
+ readonly schemaName: 'Array';
291
410
 
292
- static options: { castNonArrays: boolean; };
411
+ static options: { castNonArrays: boolean };
293
412
 
294
413
  discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
295
414
  discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
296
415
 
297
416
  /** The schematype embedded in this array */
298
- caster?: SchemaType;
417
+ embeddedSchemaType: SchemaType;
299
418
 
300
419
  /** Default options for this SchemaType */
301
- defaultOptions: Record<string, any>;
420
+ static defaultOptions: Record<string, any>;
302
421
 
303
422
  /**
304
423
  * Adds an enum validator if this is an array of strings or numbers. Equivalent to
@@ -307,9 +426,19 @@ declare module 'mongoose' {
307
426
  enum(vals: string[] | number[]): this;
308
427
  }
309
428
 
429
+ class BigInt extends SchemaType {
430
+ /** This schema type's name, to defend against minifiers that mangle function names. */
431
+ static schemaName: 'BigInt';
432
+ readonly schemaName: 'BigInt';
433
+
434
+ /** Default options for this SchemaType */
435
+ static defaultOptions: Record<string, any>;
436
+ }
437
+
310
438
  class Boolean extends SchemaType {
311
439
  /** This schema type's name, to defend against minifiers that mangle function names. */
312
440
  static schemaName: 'Boolean';
441
+ readonly schemaName: 'Boolean';
313
442
 
314
443
  /** Configure which values get casted to `true`. */
315
444
  static convertToTrue: Set<any>;
@@ -318,12 +447,13 @@ declare module 'mongoose' {
318
447
  static convertToFalse: Set<any>;
319
448
 
320
449
  /** Default options for this SchemaType */
321
- defaultOptions: Record<string, any>;
450
+ static defaultOptions: Record<string, any>;
322
451
  }
323
452
 
324
453
  class Buffer extends SchemaType {
325
454
  /** This schema type's name, to defend against minifiers that mangle function names. */
326
455
  static schemaName: 'Buffer';
456
+ readonly schemaName: 'Buffer';
327
457
 
328
458
  /**
329
459
  * Sets the default [subtype](https://studio3t.com/whats-new/best-practices-uuid-mongodb/)
@@ -332,39 +462,53 @@ declare module 'mongoose' {
332
462
  subtype(subtype: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128): this;
333
463
 
334
464
  /** Default options for this SchemaType */
335
- defaultOptions: Record<string, any>;
465
+ static defaultOptions: Record<string, any>;
336
466
  }
337
467
 
338
468
  class Date extends SchemaType {
339
469
  /** This schema type's name, to defend against minifiers that mangle function names. */
340
470
  static schemaName: 'Date';
471
+ readonly schemaName: 'Date';
341
472
 
342
473
  /** Declares a TTL index (rounded to the nearest second) for _Date_ types only. */
343
474
  expires(when: number | string): this;
344
475
 
345
476
  /** Sets a maximum date validator. */
346
- max(value: NativeDate, message: string): this;
477
+ max(value: NativeDate, message?: string): this;
347
478
 
348
479
  /** Sets a minimum date validator. */
349
- min(value: NativeDate, message: string): this;
480
+ min(value: NativeDate, message?: string): this;
350
481
 
351
482
  /** Default options for this SchemaType */
352
- defaultOptions: Record<string, any>;
483
+ static defaultOptions: Record<string, any>;
353
484
  }
354
485
 
355
486
  class Decimal128 extends SchemaType {
356
487
  /** This schema type's name, to defend against minifiers that mangle function names. */
357
488
  static schemaName: 'Decimal128';
489
+ readonly schemaName: 'Decimal128';
358
490
 
359
491
  /** Default options for this SchemaType */
360
- defaultOptions: Record<string, any>;
492
+ static defaultOptions: Record<string, any>;
493
+ }
494
+
495
+ class Int32 extends SchemaType {
496
+ /** This schema type's name, to defend against minifiers that mangle function names. */
497
+ static schemaName: 'Int32';
498
+ readonly schemaName: 'Int32';
499
+
500
+ /** Default options for this SchemaType */
501
+ static defaultOptions: Record<string, any>;
361
502
  }
362
503
 
363
504
  class DocumentArray extends SchemaType implements AcceptsDiscriminator {
364
505
  /** This schema type's name, to defend against minifiers that mangle function names. */
365
506
  static schemaName: 'DocumentArray';
507
+ readonly schemaName: 'DocumentArray';
508
+
509
+ static options: { castNonArrays: boolean };
366
510
 
367
- static options: { castNonArrays: boolean; };
511
+ schemaOptions?: SchemaOptions;
368
512
 
369
513
  discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
370
514
  discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
@@ -372,74 +516,111 @@ declare module 'mongoose' {
372
516
  /** The schema used for documents in this array */
373
517
  schema: Schema;
374
518
 
519
+ /** The schematype embedded in this array */
520
+ embeddedSchemaType: Subdocument;
521
+
375
522
  /** The constructor used for subdocuments in this array */
376
- caster?: typeof Types.Subdocument;
523
+ Constructor: typeof Types.Subdocument;
377
524
 
378
525
  /** Default options for this SchemaType */
379
- defaultOptions: Record<string, any>;
526
+ static defaultOptions: Record<string, any>;
527
+ }
528
+
529
+ class DocumentArrayElement extends SchemaType {
530
+ /** This schema type's name, to defend against minifiers that mangle function names. */
531
+ static schemaName: 'DocumentArrayElement';
532
+ readonly schemaName: 'DocumentArrayElement';
533
+
534
+ /** Default options for this SchemaType */
535
+ static defaultOptions: Record<string, any>;
380
536
  }
381
537
 
382
538
  class Map extends SchemaType {
383
539
  /** This schema type's name, to defend against minifiers that mangle function names. */
384
540
  static schemaName: 'Map';
541
+ readonly schemaName: 'Map';
385
542
 
386
543
  /** Default options for this SchemaType */
387
- defaultOptions: Record<string, any>;
544
+ static defaultOptions: Record<string, any>;
388
545
  }
389
546
 
390
547
  class Mixed extends SchemaType {
391
548
  /** This schema type's name, to defend against minifiers that mangle function names. */
392
549
  static schemaName: 'Mixed';
550
+ readonly schemaName: 'Mixed';
393
551
 
394
552
  /** Default options for this SchemaType */
395
- defaultOptions: Record<string, any>;
553
+ static defaultOptions: Record<string, any>;
396
554
  }
397
555
 
398
556
  class Number extends SchemaType {
399
557
  /** This schema type's name, to defend against minifiers that mangle function names. */
400
558
  static schemaName: 'Number';
559
+ readonly schemaName: 'Number';
401
560
 
402
561
  /** Sets a enum validator */
403
562
  enum(vals: number[]): this;
404
563
 
405
564
  /** Sets a maximum number validator. */
406
- max(value: number, message: string): this;
565
+ max(value: number, message?: string | ValidatorMessageFn): this;
407
566
 
408
567
  /** Sets a minimum number validator. */
409
- min(value: number, message: string): this;
568
+ min(value: number, message?: string | ValidatorMessageFn): this;
569
+
570
+ /** Default options for this SchemaType */
571
+ static defaultOptions: Record<string, any>;
572
+ }
573
+
574
+ class Double extends SchemaType {
575
+ /** This schema type's name, to defend against minifiers that mangle function names. */
576
+ static schemaName: 'Double';
577
+ readonly schemaName: 'Double';
410
578
 
411
579
  /** Default options for this SchemaType */
412
- defaultOptions: Record<string, any>;
580
+ static defaultOptions: Record<string, any>;
413
581
  }
414
582
 
415
583
  class ObjectId extends SchemaType {
416
584
  /** This schema type's name, to defend against minifiers that mangle function names. */
417
585
  static schemaName: 'ObjectId';
586
+ readonly schemaName: 'ObjectId';
418
587
 
419
588
  /** Adds an auto-generated ObjectId default if turnOn is true. */
420
589
  auto(turnOn: boolean): this;
421
590
 
422
591
  /** Default options for this SchemaType */
423
- defaultOptions: Record<string, any>;
592
+ static defaultOptions: Record<string, any>;
424
593
  }
425
594
 
426
- class Subdocument extends SchemaType implements AcceptsDiscriminator {
595
+ class Subdocument<DocType = unknown> extends SchemaType implements AcceptsDiscriminator {
427
596
  /** This schema type's name, to defend against minifiers that mangle function names. */
428
597
  static schemaName: string;
429
598
 
430
599
  /** The document's schema */
431
600
  schema: Schema;
432
601
 
602
+ /** The constructor used to create subdocuments based on this schematype */
603
+ Constructor: typeof Types.Subdocument;
604
+
433
605
  /** Default options for this SchemaType */
434
- defaultOptions: Record<string, any>;
606
+ static defaultOptions: Record<string, any>;
435
607
 
436
608
  discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
437
609
  discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
610
+
611
+ cast(
612
+ val: any,
613
+ doc?: Document<any>,
614
+ init?: boolean,
615
+ prev?: any,
616
+ options?: any
617
+ ): HydratedSingleSubdocument<DocType>;
438
618
  }
439
619
 
440
620
  class String extends SchemaType {
441
621
  /** This schema type's name, to defend against minifiers that mangle function names. */
442
622
  static schemaName: 'String';
623
+ readonly schemaName: 'String';
443
624
 
444
625
  /** Adds an enum validator */
445
626
  enum(vals: string[] | any): this;
@@ -451,10 +632,10 @@ declare module 'mongoose' {
451
632
  match(value: RegExp, message: string): this;
452
633
 
453
634
  /** Sets a maximum length validator. */
454
- maxlength(value: number, message: string): this;
635
+ maxlength(value: number, message: string | ValidatorMessageFn): this;
455
636
 
456
637
  /** Sets a minimum length validator. */
457
- minlength(value: number, message: string): this;
638
+ minlength(value: number, message: string | ValidatorMessageFn): this;
458
639
 
459
640
  /** Adds a trim [setter](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-set). */
460
641
  trim(shouldTrim?: boolean): this;
@@ -463,15 +644,23 @@ declare module 'mongoose' {
463
644
  uppercase(shouldApply?: boolean): this;
464
645
 
465
646
  /** Default options for this SchemaType */
466
- defaultOptions: Record<string, any>;
647
+ static defaultOptions: Record<string, any>;
648
+ }
649
+
650
+ class Union extends SchemaType {
651
+ static schemaName: 'Union';
652
+
653
+ /** Default options for this SchemaType */
654
+ static defaultOptions: Record<string, any>;
467
655
  }
468
656
 
469
657
  class UUID extends SchemaType {
470
658
  /** This schema type's name, to defend against minifiers that mangle function names. */
471
659
  static schemaName: 'UUID';
660
+ readonly schemaName: 'UUID';
472
661
 
473
662
  /** Default options for this SchemaType */
474
- defaultOptions: Record<string, any>;
663
+ static defaultOptions: Record<string, any>;
475
664
  }
476
665
  }
477
666
  }
@@ -9,8 +9,6 @@ declare module 'mongoose' {
9
9
  * for benefits like causal consistency, [retryable writes](https://www.mongodb.com/docs/manual/core/retryable-writes/),
10
10
  * and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
11
11
  */
12
- function startSession(options: ClientSessionOptions | undefined | null, callback: Callback<ClientSession>): void;
13
- function startSession(callback: Callback<ClientSession>): void;
14
12
  function startSession(options?: ClientSessionOptions): Promise<ClientSession>;
15
13
 
16
14
  interface SessionOperation {
@@ -25,8 +23,6 @@ declare module 'mongoose' {
25
23
  * for benefits like causal consistency, [retryable writes](https://www.mongodb.com/docs/manual/core/retryable-writes/),
26
24
  * and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
27
25
  */
28
- startSession(options: ClientSessionOptions | undefined | null, callback: Callback<ClientSession>): void;
29
- startSession(callback: Callback<ClientSession>): void;
30
26
  startSession(options?: ClientSessionOptions): Promise<ClientSession>;
31
27
  }
32
28
 
@@ -0,0 +1,10 @@
1
+ declare module 'mongoose' {
2
+ interface TracingContext {
3
+ operation: string;
4
+ collection: string;
5
+ database: string;
6
+ serverAddress: string;
7
+ serverPort: number;
8
+ args: Record<string, any>;
9
+ }
10
+ }