mongoose 6.1.10 → 6.2.3

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 (81) hide show
  1. package/.eslintrc.json +154 -0
  2. package/CHANGELOG.md +73 -0
  3. package/dist/browser.umd.js +233 -222
  4. package/index.js +5 -1
  5. package/lib/aggregate.js +23 -28
  6. package/lib/browserDocument.js +1 -1
  7. package/lib/cast/number.js +2 -3
  8. package/lib/cast.js +9 -7
  9. package/lib/connection.js +76 -24
  10. package/lib/cursor/AggregationCursor.js +12 -7
  11. package/lib/cursor/QueryCursor.js +11 -6
  12. package/lib/document.js +131 -122
  13. package/lib/drivers/node-mongodb-native/collection.js +12 -4
  14. package/lib/drivers/node-mongodb-native/connection.js +11 -0
  15. package/lib/error/cast.js +3 -2
  16. package/lib/error/index.js +11 -0
  17. package/lib/error/syncIndexes.js +30 -0
  18. package/lib/helpers/clone.js +51 -29
  19. package/lib/helpers/common.js +2 -2
  20. package/lib/helpers/cursor/eachAsync.js +18 -15
  21. package/lib/helpers/document/compile.js +7 -4
  22. package/lib/helpers/getFunctionName.js +6 -4
  23. package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +14 -0
  24. package/lib/helpers/indexes/getRelatedIndexes.js +59 -0
  25. package/lib/helpers/isMongooseObject.js +9 -8
  26. package/lib/helpers/isObject.js +4 -4
  27. package/lib/helpers/model/discriminator.js +2 -1
  28. package/lib/helpers/path/parentPaths.js +10 -5
  29. package/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -2
  30. package/lib/helpers/populate/assignVals.js +12 -4
  31. package/lib/helpers/populate/getModelsMapForPopulate.js +4 -4
  32. package/lib/helpers/populate/markArraySubdocsPopulated.js +3 -1
  33. package/lib/helpers/populate/modelNamesFromRefPath.js +4 -3
  34. package/lib/helpers/printJestWarning.js +2 -2
  35. package/lib/helpers/projection/applyProjection.js +77 -0
  36. package/lib/helpers/projection/hasIncludedChildren.js +36 -0
  37. package/lib/helpers/projection/isExclusive.js +5 -2
  38. package/lib/helpers/projection/isInclusive.js +5 -1
  39. package/lib/helpers/query/cast$expr.js +279 -0
  40. package/lib/helpers/query/castUpdate.js +6 -2
  41. package/lib/helpers/query/hasDollarKeys.js +7 -3
  42. package/lib/helpers/query/isOperator.js +5 -2
  43. package/lib/helpers/schema/applyPlugins.js +11 -0
  44. package/lib/helpers/schema/getIndexes.js +6 -2
  45. package/lib/helpers/schema/getPath.js +4 -2
  46. package/lib/helpers/timestamps/setupTimestamps.js +3 -8
  47. package/lib/index.js +26 -19
  48. package/lib/internal.js +10 -2
  49. package/lib/model.js +196 -171
  50. package/lib/options/SchemaTypeOptions.js +1 -1
  51. package/lib/plugins/trackTransaction.js +5 -4
  52. package/lib/query.js +159 -146
  53. package/lib/queryhelpers.js +10 -10
  54. package/lib/schema/SubdocumentPath.js +4 -3
  55. package/lib/schema/array.js +30 -21
  56. package/lib/schema/buffer.js +1 -1
  57. package/lib/schema/date.js +1 -1
  58. package/lib/schema/decimal128.js +1 -1
  59. package/lib/schema/documentarray.js +9 -11
  60. package/lib/schema/number.js +1 -1
  61. package/lib/schema/objectid.js +2 -2
  62. package/lib/schema/string.js +4 -4
  63. package/lib/schema.js +13 -8
  64. package/lib/schematype.js +86 -40
  65. package/lib/types/ArraySubdocument.js +2 -1
  66. package/lib/types/DocumentArray/index.js +10 -27
  67. package/lib/types/DocumentArray/isMongooseDocumentArray.js +5 -0
  68. package/lib/types/DocumentArray/methods/index.js +15 -3
  69. package/lib/types/array/index.js +22 -21
  70. package/lib/types/array/isMongooseArray.js +5 -0
  71. package/lib/types/array/methods/index.js +22 -23
  72. package/lib/types/buffer.js +3 -3
  73. package/lib/types/map.js +3 -4
  74. package/lib/utils.js +19 -10
  75. package/package.json +34 -168
  76. package/tools/repl.js +1 -1
  77. package/tsconfig.json +8 -0
  78. package/types/Error.d.ts +129 -0
  79. package/types/PipelineStage.d.ts +272 -0
  80. package/{index.d.ts → types/index.d.ts} +169 -481
  81. package/lib/types/array/ArrayWrapper.js +0 -981
package/.eslintrc.json ADDED
@@ -0,0 +1,154 @@
1
+ {
2
+ "extends": [
3
+ "eslint:recommended"
4
+ ],
5
+ "ignorePatterns": [
6
+ "docs",
7
+ "tools",
8
+ "dist",
9
+ "website.js",
10
+ "test/files/*",
11
+ "benchmarks"
12
+ ],
13
+ "overrides": [
14
+ {
15
+ "files": [
16
+ "**/*.{ts,tsx}"
17
+ ],
18
+ "extends": [
19
+ "plugin:@typescript-eslint/eslint-recommended",
20
+ "plugin:@typescript-eslint/recommended"
21
+ ],
22
+ "plugins": [
23
+ "@typescript-eslint"
24
+ ],
25
+ "rules": {
26
+ "@typescript-eslint/triple-slash-reference": "off",
27
+ "spaced-comment": ["error", "always", { "markers": ["/"] }],
28
+ "@typescript-eslint/no-explicit-any": "off",
29
+ "@typescript-eslint/ban-types": "off",
30
+ "@typescript-eslint/no-unused-vars": "off",
31
+ "@typescript-eslint/explicit-module-boundary-types": "off"
32
+ }
33
+ }
34
+ ],
35
+ "plugins": [
36
+ "mocha-no-only"
37
+ ],
38
+ "parserOptions": {
39
+ "ecmaVersion": 2020
40
+ },
41
+ "env": {
42
+ "node": true,
43
+ "es6": true
44
+ },
45
+ "rules": {
46
+ "comma-style": "error",
47
+ "indent": [
48
+ "error",
49
+ 2,
50
+ {
51
+ "SwitchCase": 1,
52
+ "VariableDeclarator": 2
53
+ }
54
+ ],
55
+ "keyword-spacing": "error",
56
+ "no-whitespace-before-property": "error",
57
+ "no-buffer-constructor": "warn",
58
+ "no-console": "off",
59
+ "no-constant-condition": "off",
60
+ "no-multi-spaces": "error",
61
+ "func-call-spacing": "error",
62
+ "no-trailing-spaces": "error",
63
+ "no-undef": "error",
64
+ "no-unneeded-ternary": "error",
65
+ "no-const-assign": "error",
66
+ "no-useless-rename": "error",
67
+ "no-dupe-keys": "error",
68
+ "space-in-parens": [
69
+ "error",
70
+ "never"
71
+ ],
72
+ "spaced-comment": [
73
+ "error",
74
+ "always",
75
+ {
76
+ "block": {
77
+ "markers": [
78
+ "!"
79
+ ],
80
+ "balanced": true
81
+ }
82
+ }
83
+ ],
84
+ "key-spacing": [
85
+ "error",
86
+ {
87
+ "beforeColon": false,
88
+ "afterColon": true
89
+ }
90
+ ],
91
+ "comma-spacing": [
92
+ "error",
93
+ {
94
+ "before": false,
95
+ "after": true
96
+ }
97
+ ],
98
+ "array-bracket-spacing": 1,
99
+ "arrow-spacing": [
100
+ "error",
101
+ {
102
+ "before": true,
103
+ "after": true
104
+ }
105
+ ],
106
+ "object-curly-spacing": [
107
+ "error",
108
+ "always"
109
+ ],
110
+ "comma-dangle": [
111
+ "error",
112
+ "never"
113
+ ],
114
+ "no-unreachable": "error",
115
+ "quotes": [
116
+ "error",
117
+ "single"
118
+ ],
119
+ "quote-props": [
120
+ "error",
121
+ "as-needed"
122
+ ],
123
+ "semi": "error",
124
+ "no-extra-semi": "error",
125
+ "semi-spacing": "error",
126
+ "no-spaced-func": "error",
127
+ "no-throw-literal": "error",
128
+ "space-before-blocks": "error",
129
+ "space-before-function-paren": [
130
+ "error",
131
+ "never"
132
+ ],
133
+ "space-infix-ops": "error",
134
+ "space-unary-ops": "error",
135
+ "no-var": "warn",
136
+ "prefer-const": "warn",
137
+ "strict": [
138
+ "error",
139
+ "global"
140
+ ],
141
+ "no-restricted-globals": [
142
+ "error",
143
+ {
144
+ "name": "context",
145
+ "message": "Don't use Mocha's global context"
146
+ }
147
+ ],
148
+ "no-prototype-builtins": "off",
149
+ "mocha-no-only/mocha-no-only": [
150
+ "error"
151
+ ],
152
+ "no-empty": "off"
153
+ }
154
+ }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,76 @@
1
+ 6.2.3 / 2022-02-21
2
+ ==================
3
+ * fix(model): avoid dropping base model indexes when using discriminators with `Connection.prototype.syncIndexes()` #11424 #11421 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
4
+ * fix(document): handle array defaults when selecting element underneath array #11376
5
+ * fix(populate): correctly handle depopulating populated subdocuments #11436
6
+ * fix(utils): improve deepEqual() handling for comparing objects with non-objects #11417
7
+ * fix(schema): allow declaring array of arrays using `[{ type: [String] }]` #11252
8
+ * perf: improve validation sync and async by replacing forEach with classic for loops #11414 [Uzlopak](https://github.com/Uzlopak)
9
+ * perf: make hasDollarKeys faster #11401 [Uzlopak](https://github.com/Uzlopak)
10
+ * fix(index.d.ts): ValidationError `errors` only contains CastError or ValidationError #11369 [Uzlopak](https://github.com/Uzlopak)
11
+ * fix(index.d.ts): make InsertManyResult.insertedIds return an array of Types.ObjectId by default #11197
12
+ * fix(index.d.ts): allow pre('save') middleware with pre options #11257
13
+ * docs(connections): improve replica set hostname docs with correct error message and info about `err.reason.servers` #11200
14
+ * docs(populate): add virtual populate match option documentation #11411 [remirobichet](https://github.com/remirobichet)
15
+ * docs(document): add note to API docs that flattenMaps defaults to `true` for `toJSON()` but not `toObject()` #11213
16
+ * docs(document+model): add populate option to populate() API docs #11170
17
+ * docs(migrating_to_6): add additional info about removing omitUndefined #11038
18
+ * docs(migrating_to_6): add model.exists breaking change returning doument instead of boolean [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
19
+
20
+ 6.2.2 / 2022-02-16
21
+ ==================
22
+ * fix: fix QueryCursor and AggregationCursor compatibility with Node v17.5 #11381 [benjamingr](https://github.com/benjamingr)
23
+ * fix: better esm support, no necessity for setting allowSyntheticDefaultImports and esModuleInterop #11343 [Uzlopak](https://github.com/Uzlopak)
24
+ * fix(model): apply projection parameter to hydrate() #11375
25
+ * fix: fix issue with creating arrays of length > 10000 #11405 [Uzlopak](https://github.com/Uzlopak)
26
+ * fix(document): minimize single nested subdocs #11247
27
+ * fix(connection): handle reopening base connection with useDb() #11240
28
+ * perf: use property access instead of `get()` helper where possible #11389 [Uzlopak](https://github.com/Uzlopak)
29
+ * fix: use `isArray()` instead of `instanceof Array` #11393 [Uzlopak](https://github.com/Uzlopak)
30
+ * perf: improve performance of `cast$expr()` #11388 [Uzlopak](https://github.com/Uzlopak)
31
+ * perf: remove `startsWith()` from `isOperator()` #11400 [Uzlopak](https://github.com/Uzlopak)
32
+ * fix(index.d.ts): extract `PipelineStage` into separate file #11368 [Uzlopak](https://github.com/Uzlopak)
33
+ * fix(index.d.ts): fix $search highlight path option type #11373 [lmX2015](https://github.com/lmX2015)
34
+ * docs: update changelog file to CHANGELOG.md #11365 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
35
+ * docs: fix broken links #11388 #11377 [saibbyweb](https://github.com/saibbyweb)
36
+ * docs: remove double determiners in connections docs #11340 [Erma32](https://github.com/Erma32)
37
+
38
+ 6.2.1 / 2022-02-07
39
+ ==================
40
+ * perf: improve performance especially of validate and clone #11298 [Uzlopak](https://github.com/Uzlopak)
41
+ * perf: remove regexp-clone #11327 [Uzlopak](https://github.com/Uzlopak)
42
+ * fix(document): handle initing nested properties in non-strict documents #11309
43
+ * fix(query): cast $elemMatch underneath $all #11314
44
+ * fix(populate): respect schema-level strictPopulate option #11290
45
+ * fix: set default for dotted path projection #11293 [noseworthy](https://github.com/noseworthy)
46
+ * fix(model): correctly handle writeConcern.w = 0 when saving #11300
47
+ * fix(model): throw VersionError when saving with no changes and optimisticConcurrency = true #11295
48
+ * fix(query): avoid adding $each to $addToSet on mixed arrays #11284
49
+ * fix(index.d.ts): allow using type: [Schema.Types.ObjectId] for ObjectId arrays #11194
50
+ * fix(index.d.ts): make Types.DocumentArray<> convert type to subdoc, rename TMethods -> TMethodsAndOverrides #11061
51
+ * fix(index.d.ts): support passing generic to createCollection() and `collection()` for integration with MongoDB Node driver's collection class #11131
52
+ * fix(index.d.ts): add strictPopulate to MongooseOptions #11276
53
+ * docs: mark Mongoose 6 as compatible with MongoDB 4 #11320 [JavaScriptBach](https://github.com/JavaScriptBach)
54
+ * docs: remove documentation for useNestedStrict #11313 [mark-langer](https://github.com/mark-langer)
55
+ * docs: add "new" to ObjectId class in aggregate.js docs #11322 [JavanPoirier](https://github.com/JavanPoirier)
56
+ * chore: handle eslint configuration in .eslintrc.json #11326 [Uzlopak](https://github.com/Uzlopak)
57
+ * refactor: add parenthesis for constructors in tests #11330 [apeltop](https://github.com/apeltop)
58
+
59
+ 6.2.0 / 2022-02-02
60
+ ==================
61
+ * feat: upgrade MongoDB driver to 4.3.1
62
+ * feat(connection+mongoose): add support for continueOnError for syncIndexes #11266 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
63
+ * feat(query): cast literals in `$expr` where possible #10663
64
+ * feat(schema+mongoose): add pluginTags to allow applying global plugins to only schemas with matching tags #9780
65
+ * feat(discriminator): support overwriteModels:true to reuse discriminator names #11244 #10931 [IslandRhythms](https://github.com/IslandRhythms)
66
+ * feat(index.d.ts): add DocType generic param to Model functions that return queries to better support projections #11156
67
+ * feat(error): export MongooseServerSelectionError #11202
68
+ * feat(schematype): add validators, path, isRequired to public API and TypeScript types #11139
69
+ * fix(model): make exists(...) return lean document with _id or null instead of boolean #11142 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
70
+ * fix(model): support storing versionKey in nested paths #10980
71
+ * fix(index.d.ts): add options to `bulkSave()` type def #11201 [Uzlopak](https://github.com/Uzlopak)
72
+ * fix(index.d.ts): better support for query projections #11210 [EugeneKorshenko](https://github.com/EugeneKorshenko)
73
+
1
74
  6.1.10 / 2022-02-01
2
75
  ===================
3
76
  * fix(mongoose): correctly handle destructured isValidObjectId #11304