@datanimbus/mongoose 6.13.10

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 (292) hide show
  1. package/.eslintrc.js +232 -0
  2. package/.mocharc.yml +4 -0
  3. package/LICENSE.md +22 -0
  4. package/README.md +387 -0
  5. package/SECURITY.md +1 -0
  6. package/browser.js +8 -0
  7. package/dist/browser.umd.js +2 -0
  8. package/index.js +63 -0
  9. package/lgtm.yml +12 -0
  10. package/lib/aggregate.js +1164 -0
  11. package/lib/browser.js +158 -0
  12. package/lib/browserDocument.js +101 -0
  13. package/lib/cast/boolean.js +32 -0
  14. package/lib/cast/date.js +41 -0
  15. package/lib/cast/decimal128.js +36 -0
  16. package/lib/cast/number.js +42 -0
  17. package/lib/cast/objectid.js +29 -0
  18. package/lib/cast/string.js +37 -0
  19. package/lib/cast.js +418 -0
  20. package/lib/collection.js +311 -0
  21. package/lib/connection.js +1574 -0
  22. package/lib/connectionstate.js +26 -0
  23. package/lib/cursor/AggregationCursor.js +380 -0
  24. package/lib/cursor/ChangeStream.js +154 -0
  25. package/lib/cursor/QueryCursor.js +538 -0
  26. package/lib/document.js +4771 -0
  27. package/lib/document_provider.js +30 -0
  28. package/lib/driver.js +15 -0
  29. package/lib/drivers/SPEC.md +4 -0
  30. package/lib/drivers/browser/ReadPreference.js +7 -0
  31. package/lib/drivers/browser/binary.js +14 -0
  32. package/lib/drivers/browser/decimal128.js +7 -0
  33. package/lib/drivers/browser/index.js +16 -0
  34. package/lib/drivers/browser/objectid.js +29 -0
  35. package/lib/drivers/node-mongodb-native/ReadPreference.js +47 -0
  36. package/lib/drivers/node-mongodb-native/binary.js +10 -0
  37. package/lib/drivers/node-mongodb-native/collection.js +460 -0
  38. package/lib/drivers/node-mongodb-native/connection.js +166 -0
  39. package/lib/drivers/node-mongodb-native/decimal128.js +7 -0
  40. package/lib/drivers/node-mongodb-native/index.js +12 -0
  41. package/lib/drivers/node-mongodb-native/objectid.js +16 -0
  42. package/lib/error/browserMissingSchema.js +28 -0
  43. package/lib/error/bulkWriteError.js +41 -0
  44. package/lib/error/cast.js +158 -0
  45. package/lib/error/disconnected.js +33 -0
  46. package/lib/error/divergentArray.js +38 -0
  47. package/lib/error/eachAsyncMultiError.js +41 -0
  48. package/lib/error/index.js +228 -0
  49. package/lib/error/messages.js +47 -0
  50. package/lib/error/missingSchema.js +31 -0
  51. package/lib/error/mongooseError.js +13 -0
  52. package/lib/error/notFound.js +45 -0
  53. package/lib/error/objectExpected.js +30 -0
  54. package/lib/error/objectParameter.js +30 -0
  55. package/lib/error/overwriteModel.js +30 -0
  56. package/lib/error/parallelSave.js +30 -0
  57. package/lib/error/parallelValidate.js +31 -0
  58. package/lib/error/serverSelection.js +61 -0
  59. package/lib/error/setOptionError.js +101 -0
  60. package/lib/error/strict.js +33 -0
  61. package/lib/error/strictPopulate.js +29 -0
  62. package/lib/error/syncIndexes.js +30 -0
  63. package/lib/error/validation.js +103 -0
  64. package/lib/error/validator.js +99 -0
  65. package/lib/error/version.js +36 -0
  66. package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +39 -0
  67. package/lib/helpers/aggregate/stringifyFunctionOperators.js +50 -0
  68. package/lib/helpers/arrayDepth.js +33 -0
  69. package/lib/helpers/clone.js +177 -0
  70. package/lib/helpers/common.js +127 -0
  71. package/lib/helpers/cursor/eachAsync.js +222 -0
  72. package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +16 -0
  73. package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +12 -0
  74. package/lib/helpers/discriminator/getConstructor.js +26 -0
  75. package/lib/helpers/discriminator/getDiscriminatorByValue.js +28 -0
  76. package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +27 -0
  77. package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +64 -0
  78. package/lib/helpers/document/applyDefaults.js +128 -0
  79. package/lib/helpers/document/cleanModifiedSubpaths.js +35 -0
  80. package/lib/helpers/document/compile.js +237 -0
  81. package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +50 -0
  82. package/lib/helpers/document/handleSpreadDoc.js +35 -0
  83. package/lib/helpers/each.js +25 -0
  84. package/lib/helpers/error/combinePathErrors.js +22 -0
  85. package/lib/helpers/firstKey.js +8 -0
  86. package/lib/helpers/get.js +65 -0
  87. package/lib/helpers/getConstructorName.js +16 -0
  88. package/lib/helpers/getDefaultBulkwriteResult.js +27 -0
  89. package/lib/helpers/getFunctionName.js +10 -0
  90. package/lib/helpers/immediate.js +16 -0
  91. package/lib/helpers/indexes/applySchemaCollation.js +13 -0
  92. package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +14 -0
  93. package/lib/helpers/indexes/getRelatedIndexes.js +59 -0
  94. package/lib/helpers/indexes/isDefaultIdIndex.js +18 -0
  95. package/lib/helpers/indexes/isIndexEqual.js +96 -0
  96. package/lib/helpers/indexes/isTextIndex.js +16 -0
  97. package/lib/helpers/isAsyncFunction.js +9 -0
  98. package/lib/helpers/isBsonType.js +16 -0
  99. package/lib/helpers/isMongooseObject.js +22 -0
  100. package/lib/helpers/isObject.js +16 -0
  101. package/lib/helpers/isPromise.js +6 -0
  102. package/lib/helpers/isSimpleValidator.js +22 -0
  103. package/lib/helpers/model/applyDefaultsToPOJO.js +52 -0
  104. package/lib/helpers/model/applyHooks.js +149 -0
  105. package/lib/helpers/model/applyMethods.js +70 -0
  106. package/lib/helpers/model/applyStaticHooks.js +71 -0
  107. package/lib/helpers/model/applyStatics.js +13 -0
  108. package/lib/helpers/model/castBulkWrite.js +240 -0
  109. package/lib/helpers/model/discriminator.js +218 -0
  110. package/lib/helpers/model/pushNestedArrayPaths.js +15 -0
  111. package/lib/helpers/once.js +12 -0
  112. package/lib/helpers/parallelLimit.js +55 -0
  113. package/lib/helpers/path/parentPaths.js +18 -0
  114. package/lib/helpers/path/setDottedPath.js +33 -0
  115. package/lib/helpers/pluralize.js +94 -0
  116. package/lib/helpers/populate/SkipPopulateValue.js +10 -0
  117. package/lib/helpers/populate/assignRawDocsToIdStructure.js +124 -0
  118. package/lib/helpers/populate/assignVals.js +337 -0
  119. package/lib/helpers/populate/createPopulateQueryFilter.js +97 -0
  120. package/lib/helpers/populate/getModelsMapForPopulate.js +756 -0
  121. package/lib/helpers/populate/getSchemaTypes.js +233 -0
  122. package/lib/helpers/populate/getVirtual.js +72 -0
  123. package/lib/helpers/populate/leanPopulateMap.js +7 -0
  124. package/lib/helpers/populate/lookupLocalFields.js +40 -0
  125. package/lib/helpers/populate/markArraySubdocsPopulated.js +47 -0
  126. package/lib/helpers/populate/modelNamesFromRefPath.js +68 -0
  127. package/lib/helpers/populate/removeDeselectedForeignField.js +31 -0
  128. package/lib/helpers/populate/validateRef.js +19 -0
  129. package/lib/helpers/printJestWarning.js +21 -0
  130. package/lib/helpers/printStrictQueryWarning.js +11 -0
  131. package/lib/helpers/processConnectionOptions.js +65 -0
  132. package/lib/helpers/projection/applyProjection.js +77 -0
  133. package/lib/helpers/projection/hasIncludedChildren.js +41 -0
  134. package/lib/helpers/projection/isDefiningProjection.js +18 -0
  135. package/lib/helpers/projection/isExclusive.js +35 -0
  136. package/lib/helpers/projection/isInclusive.js +38 -0
  137. package/lib/helpers/projection/isNestedProjection.js +8 -0
  138. package/lib/helpers/projection/isPathExcluded.js +40 -0
  139. package/lib/helpers/projection/isPathSelectedInclusive.js +28 -0
  140. package/lib/helpers/projection/isSubpath.js +14 -0
  141. package/lib/helpers/projection/parseProjection.js +33 -0
  142. package/lib/helpers/promiseOrCallback.js +55 -0
  143. package/lib/helpers/query/applyGlobalOption.js +29 -0
  144. package/lib/helpers/query/applyQueryMiddleware.js +79 -0
  145. package/lib/helpers/query/cast$expr.js +282 -0
  146. package/lib/helpers/query/castFilterPath.js +54 -0
  147. package/lib/helpers/query/castUpdate.js +560 -0
  148. package/lib/helpers/query/completeMany.js +52 -0
  149. package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +90 -0
  150. package/lib/helpers/query/handleImmutable.js +28 -0
  151. package/lib/helpers/query/hasDollarKeys.js +23 -0
  152. package/lib/helpers/query/isOperator.js +14 -0
  153. package/lib/helpers/query/sanitizeFilter.js +38 -0
  154. package/lib/helpers/query/sanitizeProjection.js +14 -0
  155. package/lib/helpers/query/selectPopulatedFields.js +49 -0
  156. package/lib/helpers/query/trusted.js +13 -0
  157. package/lib/helpers/query/validOps.js +24 -0
  158. package/lib/helpers/query/wrapThunk.js +31 -0
  159. package/lib/helpers/schema/addAutoId.js +7 -0
  160. package/lib/helpers/schema/applyBuiltinPlugins.js +12 -0
  161. package/lib/helpers/schema/applyPlugins.js +55 -0
  162. package/lib/helpers/schema/applyWriteConcern.js +30 -0
  163. package/lib/helpers/schema/cleanPositionalOperators.js +12 -0
  164. package/lib/helpers/schema/getIndexes.js +164 -0
  165. package/lib/helpers/schema/getKeysInSchemaOrder.js +28 -0
  166. package/lib/helpers/schema/getPath.js +37 -0
  167. package/lib/helpers/schema/handleIdOption.js +20 -0
  168. package/lib/helpers/schema/handleTimestampOption.js +24 -0
  169. package/lib/helpers/schema/idGetter.js +32 -0
  170. package/lib/helpers/schema/merge.js +28 -0
  171. package/lib/helpers/schematype/handleImmutable.js +50 -0
  172. package/lib/helpers/setDefaultsOnInsert.js +132 -0
  173. package/lib/helpers/specialProperties.js +3 -0
  174. package/lib/helpers/symbols.js +20 -0
  175. package/lib/helpers/timers.js +3 -0
  176. package/lib/helpers/timestamps/setDocumentTimestamps.js +26 -0
  177. package/lib/helpers/timestamps/setupTimestamps.js +101 -0
  178. package/lib/helpers/topology/allServersUnknown.js +12 -0
  179. package/lib/helpers/topology/isAtlas.js +31 -0
  180. package/lib/helpers/topology/isSSLError.js +16 -0
  181. package/lib/helpers/update/applyTimestampsToChildren.js +193 -0
  182. package/lib/helpers/update/applyTimestampsToUpdate.js +117 -0
  183. package/lib/helpers/update/castArrayFilters.js +109 -0
  184. package/lib/helpers/update/modifiedPaths.js +33 -0
  185. package/lib/helpers/update/moveImmutableProperties.js +53 -0
  186. package/lib/helpers/update/removeUnusedArrayFilters.js +32 -0
  187. package/lib/helpers/update/updatedPathsByArrayFilter.js +27 -0
  188. package/lib/helpers/updateValidators.js +249 -0
  189. package/lib/index.js +1338 -0
  190. package/lib/internal.js +46 -0
  191. package/lib/model.js +5474 -0
  192. package/lib/options/PopulateOptions.js +36 -0
  193. package/lib/options/SchemaArrayOptions.js +78 -0
  194. package/lib/options/SchemaBufferOptions.js +38 -0
  195. package/lib/options/SchemaDateOptions.js +71 -0
  196. package/lib/options/SchemaDocumentArrayOptions.js +68 -0
  197. package/lib/options/SchemaMapOptions.js +43 -0
  198. package/lib/options/SchemaNumberOptions.js +101 -0
  199. package/lib/options/SchemaObjectIdOptions.js +64 -0
  200. package/lib/options/SchemaStringOptions.js +138 -0
  201. package/lib/options/SchemaSubdocumentOptions.js +42 -0
  202. package/lib/options/SchemaTypeOptions.js +244 -0
  203. package/lib/options/VirtualOptions.js +164 -0
  204. package/lib/options/propertyOptions.js +8 -0
  205. package/lib/options/removeOptions.js +14 -0
  206. package/lib/options/saveOptions.js +14 -0
  207. package/lib/options.js +15 -0
  208. package/lib/plugins/index.js +7 -0
  209. package/lib/plugins/removeSubdocs.js +31 -0
  210. package/lib/plugins/saveSubdocs.js +66 -0
  211. package/lib/plugins/sharding.js +83 -0
  212. package/lib/plugins/trackTransaction.js +92 -0
  213. package/lib/plugins/validateBeforeSave.js +45 -0
  214. package/lib/promise_provider.js +49 -0
  215. package/lib/query.js +5982 -0
  216. package/lib/queryhelpers.js +353 -0
  217. package/lib/schema/DocumentArrayElement.js +100 -0
  218. package/lib/schema/SubdocumentPath.js +369 -0
  219. package/lib/schema/array.js +663 -0
  220. package/lib/schema/boolean.js +267 -0
  221. package/lib/schema/buffer.js +269 -0
  222. package/lib/schema/date.js +404 -0
  223. package/lib/schema/decimal128.js +210 -0
  224. package/lib/schema/documentarray.js +598 -0
  225. package/lib/schema/index.js +39 -0
  226. package/lib/schema/map.js +84 -0
  227. package/lib/schema/mixed.js +132 -0
  228. package/lib/schema/number.js +438 -0
  229. package/lib/schema/objectid.js +295 -0
  230. package/lib/schema/operators/bitwise.js +38 -0
  231. package/lib/schema/operators/exists.js +12 -0
  232. package/lib/schema/operators/geospatial.js +107 -0
  233. package/lib/schema/operators/helpers.js +32 -0
  234. package/lib/schema/operators/text.js +39 -0
  235. package/lib/schema/operators/type.js +20 -0
  236. package/lib/schema/string.js +694 -0
  237. package/lib/schema/symbols.js +5 -0
  238. package/lib/schema/uuid.js +334 -0
  239. package/lib/schema.js +2665 -0
  240. package/lib/schematype.js +1727 -0
  241. package/lib/statemachine.js +207 -0
  242. package/lib/types/ArraySubdocument.js +189 -0
  243. package/lib/types/DocumentArray/index.js +113 -0
  244. package/lib/types/DocumentArray/isMongooseDocumentArray.js +5 -0
  245. package/lib/types/DocumentArray/methods/index.js +383 -0
  246. package/lib/types/array/index.js +116 -0
  247. package/lib/types/array/isMongooseArray.js +5 -0
  248. package/lib/types/array/methods/index.js +1014 -0
  249. package/lib/types/buffer.js +277 -0
  250. package/lib/types/decimal128.js +13 -0
  251. package/lib/types/index.js +20 -0
  252. package/lib/types/map.js +354 -0
  253. package/lib/types/objectid.js +41 -0
  254. package/lib/types/subdocument.js +432 -0
  255. package/lib/utils.js +1011 -0
  256. package/lib/validoptions.js +36 -0
  257. package/lib/virtualtype.js +175 -0
  258. package/package.json +164 -0
  259. package/scripts/build-browser.js +18 -0
  260. package/scripts/create-tarball.js +7 -0
  261. package/scripts/generateSearch.js +154 -0
  262. package/scripts/tsc-diagnostics-check.js +15 -0
  263. package/tools/auth.js +31 -0
  264. package/tools/repl.js +35 -0
  265. package/tools/sharded.js +46 -0
  266. package/tsconfig.json +9 -0
  267. package/types/aggregate.d.ts +174 -0
  268. package/types/augmentations.d.ts +9 -0
  269. package/types/callback.d.ts +8 -0
  270. package/types/collection.d.ts +44 -0
  271. package/types/connection.d.ts +242 -0
  272. package/types/cursor.d.ts +62 -0
  273. package/types/document.d.ts +266 -0
  274. package/types/error.d.ts +138 -0
  275. package/types/expressions.d.ts +2936 -0
  276. package/types/helpers.d.ts +32 -0
  277. package/types/index.d.ts +627 -0
  278. package/types/indexes.d.ts +98 -0
  279. package/types/inferschematype.d.ts +228 -0
  280. package/types/middlewares.d.ts +32 -0
  281. package/types/models.d.ts +488 -0
  282. package/types/mongooseoptions.d.ts +206 -0
  283. package/types/pipelinestage.d.ts +297 -0
  284. package/types/populate.d.ts +45 -0
  285. package/types/query.d.ts +659 -0
  286. package/types/schemaoptions.d.ts +231 -0
  287. package/types/schematypes.d.ts +478 -0
  288. package/types/session.d.ts +36 -0
  289. package/types/types.d.ts +104 -0
  290. package/types/utility.d.ts +43 -0
  291. package/types/validation.d.ts +34 -0
  292. package/types/virtuals.d.ts +14 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,232 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ extends: [
5
+ 'eslint:recommended'
6
+ ],
7
+ ignorePatterns: [
8
+ 'tools',
9
+ 'dist',
10
+ 'website.js',
11
+ 'test/files/*',
12
+ 'benchmarks',
13
+ '*.min.js',
14
+ 'docs/js/native.js'
15
+ ],
16
+ overrides: [
17
+ {
18
+ files: [
19
+ '**/*.{ts,tsx}',
20
+ '**/*.md/*.ts',
21
+ '**/*.md/*.typescript'
22
+ ],
23
+ extends: [
24
+ 'plugin:@typescript-eslint/eslint-recommended',
25
+ 'plugin:@typescript-eslint/recommended'
26
+ ],
27
+ plugins: [
28
+ '@typescript-eslint'
29
+ ],
30
+ rules: {
31
+ '@typescript-eslint/triple-slash-reference': 'off',
32
+ '@typescript-eslint/no-non-null-assertion': 'off',
33
+ '@typescript-eslint/no-empty-function': 'off',
34
+ 'spaced-comment': [
35
+ 'error',
36
+ 'always',
37
+ {
38
+ block: {
39
+ markers: [
40
+ '!'
41
+ ],
42
+ balanced: true
43
+ },
44
+ markers: [
45
+ '/'
46
+ ]
47
+ }
48
+ ],
49
+ '@typescript-eslint/no-explicit-any': 'off',
50
+ '@typescript-eslint/ban-types': 'off',
51
+ '@typescript-eslint/no-unused-vars': 'off',
52
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
53
+ '@typescript-eslint/indent': [
54
+ 'warn',
55
+ 2,
56
+ {
57
+ SwitchCase: 1,
58
+ ignoredNodes: ['TSTypeParameterInstantiation']
59
+ }
60
+ ],
61
+ '@typescript-eslint/prefer-optional-chain': 'error',
62
+ '@typescript-eslint/brace-style': 'error',
63
+ '@typescript-eslint/no-dupe-class-members': 'error',
64
+ '@typescript-eslint/no-redeclare': 'error',
65
+ '@typescript-eslint/type-annotation-spacing': 'error',
66
+ '@typescript-eslint/object-curly-spacing': [
67
+ 'error',
68
+ 'always'
69
+ ],
70
+ '@typescript-eslint/semi': 'error',
71
+ '@typescript-eslint/space-before-function-paren': [
72
+ 'error',
73
+ 'never'
74
+ ],
75
+ '@typescript-eslint/space-infix-ops': 'off'
76
+ }
77
+ },
78
+ {
79
+ files: [
80
+ 'docs/js/**/*.js'
81
+ ],
82
+ env: {
83
+ node: false,
84
+ browser: true
85
+ }
86
+ }
87
+ // // eslint-plugin-markdown has been disabled because of out-standing issues, see https://github.com/eslint/eslint-plugin-markdown/issues/214
88
+ // {
89
+ // files: ['**/*.md'],
90
+ // processor: 'markdown/markdown'
91
+ // },
92
+ // {
93
+ // files: ['**/*.md/*.js', '**/*.md/*.javascript', '**/*.md/*.ts', '**/*.md/*.typescript'],
94
+ // parserOptions: {
95
+ // ecmaFeatures: {
96
+ // impliedStrict: true
97
+ // },
98
+ // sourceType: 'module', // required to allow "import" statements
99
+ // ecmaVersion: 'latest' // required to allow top-level await
100
+ // },
101
+ // rules: {
102
+ // 'no-undef': 'off',
103
+ // 'no-unused-expressions': 'off',
104
+ // 'no-unused-vars': 'off',
105
+ // 'no-redeclare': 'off',
106
+ // '@typescript-eslint/no-redeclare': 'off'
107
+ // }
108
+ // }
109
+ ],
110
+ plugins: [
111
+ 'mocha-no-only'
112
+ // 'markdown'
113
+ ],
114
+ parserOptions: {
115
+ ecmaVersion: 2020
116
+ },
117
+ env: {
118
+ node: true,
119
+ es6: true
120
+ },
121
+ rules: {
122
+ 'comma-style': 'error',
123
+ indent: [
124
+ 'error',
125
+ 2,
126
+ {
127
+ SwitchCase: 1,
128
+ VariableDeclarator: 2
129
+ }
130
+ ],
131
+ 'keyword-spacing': 'error',
132
+ 'no-whitespace-before-property': 'error',
133
+ 'no-buffer-constructor': 'warn',
134
+ 'no-console': 'off',
135
+ 'no-constant-condition': 'off',
136
+ 'no-multi-spaces': 'error',
137
+ 'func-call-spacing': 'error',
138
+ 'no-trailing-spaces': 'error',
139
+ 'no-undef': 'error',
140
+ 'no-unneeded-ternary': 'error',
141
+ 'no-const-assign': 'error',
142
+ 'no-useless-rename': 'error',
143
+ 'no-dupe-keys': 'error',
144
+ 'space-in-parens': [
145
+ 'error',
146
+ 'never'
147
+ ],
148
+ 'spaced-comment': [
149
+ 'error',
150
+ 'always',
151
+ {
152
+ block: {
153
+ markers: [
154
+ '!'
155
+ ],
156
+ balanced: true
157
+ }
158
+ }
159
+ ],
160
+ 'key-spacing': [
161
+ 'error',
162
+ {
163
+ beforeColon: false,
164
+ afterColon: true
165
+ }
166
+ ],
167
+ 'comma-spacing': [
168
+ 'error',
169
+ {
170
+ before: false,
171
+ after: true
172
+ }
173
+ ],
174
+ 'array-bracket-spacing': 1,
175
+ 'arrow-spacing': [
176
+ 'error',
177
+ {
178
+ before: true,
179
+ after: true
180
+ }
181
+ ],
182
+ 'object-curly-spacing': [
183
+ 'error',
184
+ 'always'
185
+ ],
186
+ 'comma-dangle': [
187
+ 'error',
188
+ 'never'
189
+ ],
190
+ 'no-unreachable': 'error',
191
+ quotes: [
192
+ 'error',
193
+ 'single'
194
+ ],
195
+ 'quote-props': [
196
+ 'error',
197
+ 'as-needed'
198
+ ],
199
+ semi: 'error',
200
+ 'no-extra-semi': 'error',
201
+ 'semi-spacing': 'error',
202
+ 'no-spaced-func': 'error',
203
+ 'no-throw-literal': 'error',
204
+ 'space-before-blocks': 'error',
205
+ 'space-before-function-paren': [
206
+ 'error',
207
+ 'never'
208
+ ],
209
+ 'space-infix-ops': 'error',
210
+ 'space-unary-ops': 'error',
211
+ 'no-var': 'warn',
212
+ 'prefer-const': 'warn',
213
+ strict: [
214
+ 'error',
215
+ 'global'
216
+ ],
217
+ 'no-restricted-globals': [
218
+ 'error',
219
+ {
220
+ name: 'context',
221
+ message: 'Don\'t use Mocha\'s global context'
222
+ }
223
+ ],
224
+ 'no-prototype-builtins': 'off',
225
+ 'mocha-no-only/mocha-no-only': [
226
+ 'error'
227
+ ],
228
+ 'no-empty': 'off',
229
+ 'eol-last': 'warn',
230
+ 'no-multiple-empty-lines': ['warn', { max: 2 }]
231
+ }
232
+ };
package/.mocharc.yml ADDED
@@ -0,0 +1,4 @@
1
+ reporter: spec # better to identify failing / slow tests than "dot"
2
+ ui: bdd # explicitly setting, even though it is mocha default
3
+ require:
4
+ - test/mocha-fixtures.js
package/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2010-2013 LearnBoost <dev@learnboost.com>
4
+ Copyright (c) 2013-2021 Automattic
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,387 @@
1
+ # Mongoose
2
+
3
+ Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed to work in an asynchronous environment. Mongoose supports [Node.js](https://nodejs.org/en/) and [Deno](https://deno.land/) (alpha).
4
+
5
+ [![Build Status](https://github.com/Automattic/mongoose/workflows/Test/badge.svg)](https://github.com/Automattic/mongoose)
6
+ [![NPM version](https://badge.fury.io/js/mongoose.svg)](http://badge.fury.io/js/mongoose)
7
+ [![Deno version](https://deno.land/badge/mongoose/version)](https://deno.land/x/mongoose)
8
+ [![Deno popularity](https://deno.land/badge/mongoose/popularity)](https://deno.land/x/mongoose)
9
+
10
+ [![npm](https://nodei.co/npm/mongoose.png)](https://www.npmjs.com/package/mongoose)
11
+
12
+ ## Documentation
13
+
14
+ The official documentation website is [mongoosejs.com](http://mongoosejs.com/).
15
+
16
+ Mongoose 6.0.0 was released on August 24, 2021. You can find more details on [backwards breaking changes in 6.0.0 on our docs site](https://mongoosejs.com/docs/migrating_to_6.html).
17
+
18
+ ## Support
19
+
20
+ - [Stack Overflow](http://stackoverflow.com/questions/tagged/mongoose)
21
+ - [Bug Reports](https://github.com/Automattic/mongoose/issues/)
22
+ - [Mongoose Slack Channel](http://slack.mongoosejs.io/)
23
+ - [Help Forum](http://groups.google.com/group/mongoose-orm)
24
+ - [MongoDB Support](https://www.mongodb.com/docs/manual/support/)
25
+
26
+ ## Plugins
27
+
28
+ Check out the [plugins search site](http://plugins.mongoosejs.io/) to see hundreds of related modules from the community. Next, learn how to write your own plugin from the [docs](http://mongoosejs.com/docs/plugins.html) or [this blog post](http://thecodebarbarian.com/2015/03/06/guide-to-mongoose-plugins).
29
+
30
+ ## Contributors
31
+
32
+ Pull requests are always welcome! Please base pull requests against the `master`
33
+ branch and follow the [contributing guide](https://github.com/Automattic/mongoose/blob/master/CONTRIBUTING.md).
34
+
35
+ If your pull requests makes documentation changes, please do **not**
36
+ modify any `.html` files. The `.html` files are compiled code, so please make
37
+ your changes in `docs/*.pug`, `lib/*.js`, or `test/docs/*.js`.
38
+
39
+ View all 400+ [contributors](https://github.com/Automattic/mongoose/graphs/contributors).
40
+
41
+ ## Installation
42
+
43
+ First install [Node.js](http://nodejs.org/) and [MongoDB](https://www.mongodb.org/downloads). Then:
44
+
45
+ ```sh
46
+ $ npm install mongoose
47
+ ```
48
+
49
+ Mongoose 6.8.0 also includes alpha support for [Deno](https://deno.land/).
50
+
51
+ ## Importing
52
+
53
+ ```javascript
54
+ // Using Node.js `require()`
55
+ const mongoose = require('mongoose');
56
+
57
+ // Using ES6 imports
58
+ import mongoose from 'mongoose';
59
+ ```
60
+
61
+ Or, using [Deno's `createRequire()` for CommonJS support](https://deno.land/std@0.113.0/node/README.md?source=#commonjs-modules-loading) as follows.
62
+
63
+ ```javascript
64
+ import { createRequire } from 'https://deno.land/std/node/module.ts';
65
+ const require = createRequire(import.meta.url);
66
+
67
+ const mongoose = require('mongoose');
68
+
69
+ mongoose.connect('mongodb://127.0.0.1:27017/test')
70
+ .then(() => console.log('Connected!'));
71
+ ```
72
+
73
+ You can then run the above script using the following.
74
+
75
+ ```
76
+ deno run --allow-net --allow-read --allow-sys --allow-env mongoose-test.js
77
+ ```
78
+
79
+ ## Mongoose for Enterprise
80
+
81
+ Available as part of the Tidelift Subscription
82
+
83
+ The maintainers of mongoose and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-mongoose?utm_source=npm-mongoose&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
84
+
85
+ ## Overview
86
+
87
+ ### Connecting to MongoDB
88
+
89
+ First, we need to define a connection. If your app uses only one database, you should use `mongoose.connect`. If you need to create additional connections, use `mongoose.createConnection`.
90
+
91
+ Both `connect` and `createConnection` take a `mongodb://` URI, or the parameters `host, database, port, options`.
92
+
93
+ ```js
94
+ await mongoose.connect('mongodb://127.0.0.1/my_database');
95
+ ```
96
+
97
+ Once connected, the `open` event is fired on the `Connection` instance. If you're using `mongoose.connect`, the `Connection` is `mongoose.connection`. Otherwise, `mongoose.createConnection` return value is a `Connection`.
98
+
99
+ **Note:** _If the local connection fails then try using 127.0.0.1 instead of localhost. Sometimes issues may arise when the local hostname has been changed._
100
+
101
+ **Important!** Mongoose buffers all the commands until it's connected to the database. This means that you don't have to wait until it connects to MongoDB in order to define models, run queries, etc.
102
+
103
+ ### Defining a Model
104
+
105
+ Models are defined through the `Schema` interface.
106
+
107
+ ```js
108
+ const Schema = mongoose.Schema;
109
+ const ObjectId = Schema.ObjectId;
110
+
111
+ const BlogPost = new Schema({
112
+ author: ObjectId,
113
+ title: String,
114
+ body: String,
115
+ date: Date
116
+ });
117
+ ```
118
+
119
+ Aside from defining the structure of your documents and the types of data you're storing, a Schema handles the definition of:
120
+
121
+ * [Validators](http://mongoosejs.com/docs/validation.html) (async and sync)
122
+ * [Defaults](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-default)
123
+ * [Getters](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-get)
124
+ * [Setters](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-set)
125
+ * [Indexes](http://mongoosejs.com/docs/guide.html#indexes)
126
+ * [Middleware](http://mongoosejs.com/docs/middleware.html)
127
+ * [Methods](http://mongoosejs.com/docs/guide.html#methods) definition
128
+ * [Statics](http://mongoosejs.com/docs/guide.html#statics) definition
129
+ * [Plugins](http://mongoosejs.com/docs/plugins.html)
130
+ * [pseudo-JOINs](http://mongoosejs.com/docs/populate.html)
131
+
132
+ The following example shows some of these features:
133
+
134
+ ```js
135
+ const Comment = new Schema({
136
+ name: { type: String, default: 'hahaha' },
137
+ age: { type: Number, min: 18, index: true },
138
+ bio: { type: String, match: /[a-z]/ },
139
+ date: { type: Date, default: Date.now },
140
+ buff: Buffer
141
+ });
142
+
143
+ // a setter
144
+ Comment.path('name').set(function(v) {
145
+ return capitalize(v);
146
+ });
147
+
148
+ // middleware
149
+ Comment.pre('save', function(next) {
150
+ notify(this.get('email'));
151
+ next();
152
+ });
153
+ ```
154
+
155
+ Take a look at the example in [`examples/schema/schema.js`](https://github.com/Automattic/mongoose/blob/master/examples/schema/schema.js) for an end-to-end example of a typical setup.
156
+
157
+ ### Accessing a Model
158
+
159
+ Once we define a model through `mongoose.model('ModelName', mySchema)`, we can access it through the same function
160
+
161
+ ```js
162
+ const MyModel = mongoose.model('ModelName');
163
+ ```
164
+
165
+ Or just do it all at once
166
+
167
+ ```js
168
+ const MyModel = mongoose.model('ModelName', mySchema);
169
+ ```
170
+
171
+ The first argument is the _singular_ name of the collection your model is for. **Mongoose automatically looks for the _plural_ version of your model name.** For example, if you use
172
+
173
+ ```js
174
+ const MyModel = mongoose.model('Ticket', mySchema);
175
+ ```
176
+
177
+ Then `MyModel` will use the __tickets__ collection, not the __ticket__ collection. For more details read the [model docs](https://mongoosejs.com/docs/api/mongoose.html#mongoose_Mongoose-model).
178
+
179
+ Once we have our model, we can then instantiate it, and save it:
180
+
181
+ ```js
182
+ const instance = new MyModel();
183
+ instance.my.key = 'hello';
184
+ instance.save(function(err) {
185
+ //
186
+ });
187
+ ```
188
+
189
+ Or we can find documents from the same collection
190
+
191
+ ```js
192
+ MyModel.find({}, function(err, docs) {
193
+ // docs.forEach
194
+ });
195
+ ```
196
+
197
+ You can also `findOne`, `findById`, `update`, etc.
198
+
199
+ ```js
200
+ const instance = await MyModel.findOne({ /* ... */ });
201
+ console.log(instance.my.key); // 'hello'
202
+ ```
203
+
204
+ For more details check out [the docs](http://mongoosejs.com/docs/queries.html).
205
+
206
+ **Important!** If you opened a separate connection using `mongoose.createConnection()` but attempt to access the model through `mongoose.model('ModelName')` it will not work as expected since it is not hooked up to an active db connection. In this case access your model through the connection you created:
207
+
208
+ ```js
209
+ const conn = mongoose.createConnection('your connection string');
210
+ const MyModel = conn.model('ModelName', schema);
211
+ const m = new MyModel;
212
+ m.save(); // works
213
+ ```
214
+
215
+ vs
216
+
217
+ ```js
218
+ const conn = mongoose.createConnection('your connection string');
219
+ const MyModel = mongoose.model('ModelName', schema);
220
+ const m = new MyModel;
221
+ m.save(); // does not work b/c the default connection object was never connected
222
+ ```
223
+
224
+ ### Embedded Documents
225
+
226
+ In the first example snippet, we defined a key in the Schema that looks like:
227
+
228
+ ```
229
+ comments: [Comment]
230
+ ```
231
+
232
+ Where `Comment` is a `Schema` we created. This means that creating embedded documents is as simple as:
233
+
234
+ ```js
235
+ // retrieve my model
236
+ const BlogPost = mongoose.model('BlogPost');
237
+
238
+ // create a blog post
239
+ const post = new BlogPost();
240
+
241
+ // create a comment
242
+ post.comments.push({ title: 'My comment' });
243
+
244
+ post.save(function(err) {
245
+ if (!err) console.log('Success!');
246
+ });
247
+ ```
248
+
249
+ The same goes for removing them:
250
+
251
+ ```js
252
+ BlogPost.findById(myId, function(err, post) {
253
+ if (!err) {
254
+ post.comments[0].remove();
255
+ post.save(function(err) {
256
+ // do something
257
+ });
258
+ }
259
+ });
260
+ ```
261
+
262
+ Embedded documents enjoy all the same features as your models. Defaults, validators, middleware. Whenever an error occurs, it's bubbled to the `save()` error callback, so error handling is a snap!
263
+
264
+
265
+ ### Middleware
266
+
267
+ See the [docs](http://mongoosejs.com/docs/middleware.html) page.
268
+
269
+ #### Intercepting and mutating method arguments
270
+
271
+ You can intercept method arguments via middleware.
272
+
273
+ For example, this would allow you to broadcast changes about your Documents every time someone `set`s a path in your Document to a new value:
274
+
275
+ ```js
276
+ schema.pre('set', function(next, path, val, typel) {
277
+ // `this` is the current Document
278
+ this.emit('set', path, val);
279
+
280
+ // Pass control to the next pre
281
+ next();
282
+ });
283
+ ```
284
+
285
+ Moreover, you can mutate the incoming `method` arguments so that subsequent middleware see different values for those arguments. To do so, just pass the new values to `next`:
286
+
287
+ ```js
288
+ schema.pre(method, function firstPre(next, methodArg1, methodArg2) {
289
+ // Mutate methodArg1
290
+ next('altered-' + methodArg1.toString(), methodArg2);
291
+ });
292
+
293
+ // pre declaration is chainable
294
+ schema.pre(method, function secondPre(next, methodArg1, methodArg2) {
295
+ console.log(methodArg1);
296
+ // => 'altered-originalValOfMethodArg1'
297
+
298
+ console.log(methodArg2);
299
+ // => 'originalValOfMethodArg2'
300
+
301
+ // Passing no arguments to `next` automatically passes along the current argument values
302
+ // i.e., the following `next()` is equivalent to `next(methodArg1, methodArg2)`
303
+ // and also equivalent to, with the example method arg
304
+ // values, `next('altered-originalValOfMethodArg1', 'originalValOfMethodArg2')`
305
+ next();
306
+ });
307
+ ```
308
+
309
+ #### Schema gotcha
310
+
311
+ `type`, when used in a schema has special meaning within Mongoose. If your schema requires using `type` as a nested property you must use object notation:
312
+
313
+ ```js
314
+ new Schema({
315
+ broken: { type: Boolean },
316
+ asset: {
317
+ name: String,
318
+ type: String // uh oh, it broke. asset will be interpreted as String
319
+ }
320
+ });
321
+
322
+ new Schema({
323
+ works: { type: Boolean },
324
+ asset: {
325
+ name: String,
326
+ type: { type: String } // works. asset is an object with a type property
327
+ }
328
+ });
329
+ ```
330
+
331
+ ### Driver Access
332
+
333
+ Mongoose is built on top of the [official MongoDB Node.js driver](https://github.com/mongodb/node-mongodb-native). Each mongoose model keeps a reference to a [native MongoDB driver collection](http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html). The collection object can be accessed using `YourModel.collection`. However, using the collection object directly bypasses all mongoose features, including hooks, validation, etc. The one
334
+ notable exception that `YourModel.collection` still buffers
335
+ commands. As such, `YourModel.collection.find()` will **not**
336
+ return a cursor.
337
+
338
+ ## API Docs
339
+
340
+ Find the API docs [here](http://mongoosejs.com/docs/api/mongoose.html), generated using [dox](https://github.com/tj/dox)
341
+ and [acquit](https://github.com/vkarpov15/acquit).
342
+
343
+ ## Related Projects
344
+
345
+ #### MongoDB Runners
346
+
347
+ - [run-rs](https://www.npmjs.com/package/run-rs)
348
+ - [mongodb-memory-server](https://www.npmjs.com/package/mongodb-memory-server)
349
+ - [mongodb-topology-manager](https://www.npmjs.com/package/mongodb-topology-manager)
350
+
351
+ #### Unofficial CLIs
352
+
353
+ - [mongoosejs-cli](https://www.npmjs.com/package/mongoosejs-cli)
354
+
355
+ #### Data Seeding
356
+
357
+ - [dookie](https://www.npmjs.com/package/dookie)
358
+ - [seedgoose](https://www.npmjs.com/package/seedgoose)
359
+ - [mongoose-data-seed](https://www.npmjs.com/package/mongoose-data-seed)
360
+
361
+ #### Express Session Stores
362
+
363
+ - [connect-mongodb-session](https://www.npmjs.com/package/connect-mongodb-session)
364
+ - [connect-mongo](https://www.npmjs.com/package/connect-mongo)
365
+
366
+ ## License
367
+
368
+ Copyright (c) 2010 LearnBoost &lt;dev@learnboost.com&gt;
369
+
370
+ Permission is hereby granted, free of charge, to any person obtaining
371
+ a copy of this software and associated documentation files (the
372
+ 'Software'), to deal in the Software without restriction, including
373
+ without limitation the rights to use, copy, modify, merge, publish,
374
+ distribute, sublicense, and/or sell copies of the Software, and to
375
+ permit persons to whom the Software is furnished to do so, subject to
376
+ the following conditions:
377
+
378
+ The above copyright notice and this permission notice shall be
379
+ included in all copies or substantial portions of the Software.
380
+
381
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
382
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
383
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
384
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
385
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
386
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
387
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/SECURITY.md ADDED
@@ -0,0 +1 @@
1
+ Please follow the instructions on [Tidelift's security page](https://tidelift.com/docs/security) to report a security issue.
package/browser.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Export lib/mongoose
3
+ *
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ module.exports = require('./lib/browser');