@nullix/zod-mongoose-studio 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (876) hide show
  1. package/.output/nitro.json +15 -0
  2. package/.output/public/_nuxt/8SOpv6rk.js +1 -0
  3. package/.output/public/_nuxt/9HpZscsL.js +2 -0
  4. package/.output/public/_nuxt/B2KnRiWG.js +4 -0
  5. package/.output/public/_nuxt/B8OfTtLu.js +1 -0
  6. package/.output/public/_nuxt/BBUBE1dy.js +1 -0
  7. package/.output/public/_nuxt/BBc9UKZt.js +1 -0
  8. package/.output/public/_nuxt/BDtDVThU.js +1 -0
  9. package/.output/public/_nuxt/BEgZUVRK.js +1 -0
  10. package/.output/public/_nuxt/BFxVWTOG.js +1 -0
  11. package/.output/public/_nuxt/BG73LgW2.js +1 -0
  12. package/.output/public/_nuxt/BKILRCQU.js +1 -0
  13. package/.output/public/_nuxt/BOtBlQCF.js +1 -0
  14. package/.output/public/_nuxt/BPhDTwHR.js +1 -0
  15. package/.output/public/_nuxt/BTesnYfV.js +298 -0
  16. package/.output/public/_nuxt/BbWJElDN.js +1 -0
  17. package/.output/public/_nuxt/BcvAzS8a.js +3 -0
  18. package/.output/public/_nuxt/Bd8akH9Z.js +1 -0
  19. package/.output/public/_nuxt/Be1F0pOV.js +1 -0
  20. package/.output/public/_nuxt/BeJ5waoc.js +1 -0
  21. package/.output/public/_nuxt/Bf6VGUru.js +1 -0
  22. package/.output/public/_nuxt/BkW5O-1t.js +1 -0
  23. package/.output/public/_nuxt/BlNEE0v7.js +1 -0
  24. package/.output/public/_nuxt/Brw8urJB.js +2 -0
  25. package/.output/public/_nuxt/Bs9aos_-.js +1 -0
  26. package/.output/public/_nuxt/Bs9z6M-B.js +1 -0
  27. package/.output/public/_nuxt/Btyra-wh.js +1 -0
  28. package/.output/public/_nuxt/Bu5POkcn.js +1 -0
  29. package/.output/public/_nuxt/Bw9ernYp.js +1 -0
  30. package/.output/public/_nuxt/BwHxbl9M.js +1 -0
  31. package/.output/public/_nuxt/BxJiqAUM.js +1 -0
  32. package/.output/public/_nuxt/BzKRNQWT.js +1 -0
  33. package/.output/public/_nuxt/CBJaRo0y.js +3 -0
  34. package/.output/public/_nuxt/CFznDFnq.js +2 -0
  35. package/.output/public/_nuxt/CHwy0fLd.js +1 -0
  36. package/.output/public/_nuxt/CJmd_6j2.js +1 -0
  37. package/.output/public/_nuxt/CMQZ64NL.js +1 -0
  38. package/.output/public/_nuxt/COWaemsV.js +1 -0
  39. package/.output/public/_nuxt/CXBNlu9o.js +1 -0
  40. package/.output/public/_nuxt/C_tMU-Nz.js +1 -0
  41. package/.output/public/_nuxt/CiqrrVzr.js +1 -0
  42. package/.output/public/_nuxt/ClhHkBeG.js +1 -0
  43. package/.output/public/_nuxt/CnS9iZB_.js +1 -0
  44. package/.output/public/_nuxt/CnmFD0ga.js +1 -0
  45. package/.output/public/_nuxt/Co3qMtFm.js +1 -0
  46. package/.output/public/_nuxt/CocnycG-.js +1 -0
  47. package/.output/public/_nuxt/CpO_ztTX.js +1 -0
  48. package/.output/public/_nuxt/CqXO7rUv.js +1 -0
  49. package/.output/public/_nuxt/Csy3S7wG.js +1 -0
  50. package/.output/public/_nuxt/CtU7CIYd.js +11 -0
  51. package/.output/public/_nuxt/Cw6BJv9p.js +908 -0
  52. package/.output/public/_nuxt/Cyyb5UIc.js +1 -0
  53. package/.output/public/_nuxt/D-4FJmMZ.js +1 -0
  54. package/.output/public/_nuxt/D9hQfWCl.js +1 -0
  55. package/.output/public/_nuxt/DARyPmWN.js +1 -0
  56. package/.output/public/_nuxt/DA_xQXIa.js +1 -0
  57. package/.output/public/_nuxt/DIpCSwC3.js +1 -0
  58. package/.output/public/_nuxt/DLDM7-KI.js +1 -0
  59. package/.output/public/_nuxt/DNDY2TF8.js +1 -0
  60. package/.output/public/_nuxt/DSgGBnBI.js +1 -0
  61. package/.output/public/_nuxt/DSh2-awV.js +1 -0
  62. package/.output/public/_nuxt/DWLU9E4j.js +7 -0
  63. package/.output/public/_nuxt/Db0IVjzk.js +1 -0
  64. package/.output/public/_nuxt/Db0cS2oM.js +1 -0
  65. package/.output/public/_nuxt/Dcm9cKUX.js +1 -0
  66. package/.output/public/_nuxt/DdJfP1eB.js +3 -0
  67. package/.output/public/_nuxt/DiJ1NA_G.js +1 -0
  68. package/.output/public/_nuxt/Dj0IH4Bd.js +1 -0
  69. package/.output/public/_nuxt/Dm6ycUr_.js +1 -0
  70. package/.output/public/_nuxt/Dm9fPMHo.js +1 -0
  71. package/.output/public/_nuxt/DmeGPVcC.js +1 -0
  72. package/.output/public/_nuxt/Dnu-v4kV.js +1 -0
  73. package/.output/public/_nuxt/DtV1sZF8.js +1 -0
  74. package/.output/public/_nuxt/DtZ0uQbO.js +1 -0
  75. package/.output/public/_nuxt/DuqnmPmx.js +33 -0
  76. package/.output/public/_nuxt/JqRWe2rp.js +1 -0
  77. package/.output/public/_nuxt/Kd9XrMLS.js +1 -0
  78. package/.output/public/_nuxt/OrD6JF1K.js +1 -0
  79. package/.output/public/_nuxt/PahG7c26.js +1 -0
  80. package/.output/public/_nuxt/Ub6l9XKa.js +1 -0
  81. package/.output/public/_nuxt/XOt5hzHz.js +1 -0
  82. package/.output/public/_nuxt/Y6nb8tq_.js +1 -0
  83. package/.output/public/_nuxt/acbASCJo.js +1 -0
  84. package/.output/public/_nuxt/builds/latest.json +1 -0
  85. package/.output/public/_nuxt/builds/meta/5f8bfdb9-d523-4660-afb9-2a5faf918ee2.json +1 -0
  86. package/.output/public/_nuxt/cCwfBBRk.js +59 -0
  87. package/.output/public/_nuxt/cTPe9QuQ.js +1 -0
  88. package/.output/public/_nuxt/c_t8T7LW.js +1 -0
  89. package/.output/public/_nuxt/cl7-CwDS.js +1 -0
  90. package/.output/public/_nuxt/codicon.ngg6Pgfi.ttf +0 -0
  91. package/.output/public/_nuxt/css.worker-DBVD8oXr.js +93 -0
  92. package/.output/public/_nuxt/editor.CdBKkuhR.css +1 -0
  93. package/.output/public/_nuxt/editor.worker-CdQrwHl8.js +26 -0
  94. package/.output/public/_nuxt/entry.V-_Q9qpd.css +1 -0
  95. package/.output/public/_nuxt/error-404.ZEdaMr7r.css +1 -0
  96. package/.output/public/_nuxt/error-500.CPEQ7gwd.css +1 -0
  97. package/.output/public/_nuxt/html.worker-CwpTb9lJ.js +470 -0
  98. package/.output/public/_nuxt/j7ic8hl3.js +1 -0
  99. package/.output/public/_nuxt/json.worker-BoL8UZqY.js +58 -0
  100. package/.output/public/_nuxt/s7OhZKlX.js +1 -0
  101. package/.output/public/_nuxt/tScXyioY.js +1 -0
  102. package/.output/public/_nuxt/ts.worker-CTGvpNXs.js +67718 -0
  103. package/.output/public/_nuxt/vHIfCaH5.js +1 -0
  104. package/.output/public/_nuxt/zBfavPgS.js +1 -0
  105. package/.output/public/android-chrome-192x192.png +0 -0
  106. package/.output/public/android-chrome-512x512.png +0 -0
  107. package/.output/public/apple-touch-icon.png +0 -0
  108. package/.output/public/favicon-16x16.png +0 -0
  109. package/.output/public/favicon-32x32.png +0 -0
  110. package/.output/public/favicon.ico +0 -0
  111. package/.output/public/robots.txt +2 -0
  112. package/.output/public/site.webmanifest +1 -0
  113. package/.output/public/zodmongoose-b.jpg +0 -0
  114. package/.output/public/zodmongoose-b.png +0 -0
  115. package/.output/public/zodmongoose-b.svg +10 -0
  116. package/.output/public/zodmongoose.jpg +0 -0
  117. package/.output/public/zodmongoose.png +0 -0
  118. package/.output/public/zodmongoose.svg +12 -0
  119. package/.output/server/chunks/_/error-500.mjs +19 -0
  120. package/.output/server/chunks/_/error-500.mjs.map +1 -0
  121. package/.output/server/chunks/build/client.precomputed.mjs +4 -0
  122. package/.output/server/chunks/build/client.precomputed.mjs.map +1 -0
  123. package/.output/server/chunks/build/error-404-C01T0Fs3.mjs +93 -0
  124. package/.output/server/chunks/build/error-404-C01T0Fs3.mjs.map +1 -0
  125. package/.output/server/chunks/build/error-404-styles.C9SFt1Pa.mjs +8 -0
  126. package/.output/server/chunks/build/error-404-styles.C9SFt1Pa.mjs.map +1 -0
  127. package/.output/server/chunks/build/error-500-BxPzc_RO.mjs +76 -0
  128. package/.output/server/chunks/build/error-500-BxPzc_RO.mjs.map +1 -0
  129. package/.output/server/chunks/build/error-500-styles.BgBkJrKx.mjs +8 -0
  130. package/.output/server/chunks/build/error-500-styles.BgBkJrKx.mjs.map +1 -0
  131. package/.output/server/chunks/build/index-Cm3PgUzj.mjs +504 -0
  132. package/.output/server/chunks/build/index-Cm3PgUzj.mjs.map +1 -0
  133. package/.output/server/chunks/build/server.mjs +14569 -0
  134. package/.output/server/chunks/build/server.mjs.map +1 -0
  135. package/.output/server/chunks/build/styles.mjs +10 -0
  136. package/.output/server/chunks/build/styles.mjs.map +1 -0
  137. package/.output/server/chunks/nitro/nitro.mjs +6533 -0
  138. package/.output/server/chunks/nitro/nitro.mjs.map +1 -0
  139. package/.output/server/chunks/routes/api/parse.post.mjs +1293 -0
  140. package/.output/server/chunks/routes/api/parse.post.mjs.map +1 -0
  141. package/.output/server/chunks/routes/api/resolve.get.mjs +42 -0
  142. package/.output/server/chunks/routes/api/resolve.get.mjs.map +1 -0
  143. package/.output/server/chunks/routes/renderer.mjs +483 -0
  144. package/.output/server/chunks/routes/renderer.mjs.map +1 -0
  145. package/.output/server/chunks/virtual/_virtual_spa-template.mjs +4 -0
  146. package/.output/server/chunks/virtual/_virtual_spa-template.mjs.map +1 -0
  147. package/.output/server/index.mjs +12 -0
  148. package/.output/server/index.mjs.map +1 -0
  149. package/.output/server/node_modules/@babel/parser/lib/index.js +14582 -0
  150. package/.output/server/node_modules/@babel/parser/package.json +50 -0
  151. package/.output/server/node_modules/@esbuild/darwin-arm64/bin/esbuild +0 -0
  152. package/.output/server/node_modules/@esbuild/darwin-arm64/package.json +20 -0
  153. package/.output/server/node_modules/@iconify/utils/lib/colors/index.js +292 -0
  154. package/.output/server/node_modules/@iconify/utils/lib/colors/keywords.js +702 -0
  155. package/.output/server/node_modules/@iconify/utils/lib/css/common.js +76 -0
  156. package/.output/server/node_modules/@iconify/utils/lib/css/format.js +40 -0
  157. package/.output/server/node_modules/@iconify/utils/lib/css/icon.js +52 -0
  158. package/.output/server/node_modules/@iconify/utils/lib/css/icons.js +133 -0
  159. package/.output/server/node_modules/@iconify/utils/lib/customisations/bool.js +20 -0
  160. package/.output/server/node_modules/@iconify/utils/lib/customisations/defaults.js +15 -0
  161. package/.output/server/node_modules/@iconify/utils/lib/customisations/flip.js +18 -0
  162. package/.output/server/node_modules/@iconify/utils/lib/customisations/merge.js +18 -0
  163. package/.output/server/node_modules/@iconify/utils/lib/customisations/rotate.js +31 -0
  164. package/.output/server/node_modules/@iconify/utils/lib/emoji/cleanup.js +80 -0
  165. package/.output/server/node_modules/@iconify/utils/lib/emoji/convert.js +102 -0
  166. package/.output/server/node_modules/@iconify/utils/lib/emoji/data.js +29 -0
  167. package/.output/server/node_modules/@iconify/utils/lib/emoji/format.js +60 -0
  168. package/.output/server/node_modules/@iconify/utils/lib/emoji/parse.js +50 -0
  169. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/base.js +204 -0
  170. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/create.js +35 -0
  171. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/numbers.js +134 -0
  172. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/similar.js +167 -0
  173. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/tree.js +81 -0
  174. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/find.js +94 -0
  175. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/replace.js +28 -0
  176. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/components.js +78 -0
  177. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/missing.js +68 -0
  178. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/name.js +47 -0
  179. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/parse.js +105 -0
  180. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/similar.js +38 -0
  181. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/tree.js +94 -0
  182. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/variations.js +64 -0
  183. package/.output/server/node_modules/@iconify/utils/lib/icon/defaults.js +26 -0
  184. package/.output/server/node_modules/@iconify/utils/lib/icon/merge.js +18 -0
  185. package/.output/server/node_modules/@iconify/utils/lib/icon/name.js +58 -0
  186. package/.output/server/node_modules/@iconify/utils/lib/icon/square.js +34 -0
  187. package/.output/server/node_modules/@iconify/utils/lib/icon/transformations.js +13 -0
  188. package/.output/server/node_modules/@iconify/utils/lib/icon-set/convert-info.js +126 -0
  189. package/.output/server/node_modules/@iconify/utils/lib/icon-set/expand.js +21 -0
  190. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icon.js +27 -0
  191. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icons.js +38 -0
  192. package/.output/server/node_modules/@iconify/utils/lib/icon-set/minify.js +93 -0
  193. package/.output/server/node_modules/@iconify/utils/lib/icon-set/parse.js +48 -0
  194. package/.output/server/node_modules/@iconify/utils/lib/icon-set/tree.js +24 -0
  195. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate-basic.js +44 -0
  196. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate.js +125 -0
  197. package/.output/server/node_modules/@iconify/utils/lib/index.js +53 -0
  198. package/.output/server/node_modules/@iconify/utils/lib/loader/custom.js +32 -0
  199. package/.output/server/node_modules/@iconify/utils/lib/loader/loader.js +28 -0
  200. package/.output/server/node_modules/@iconify/utils/lib/loader/modern.js +42 -0
  201. package/.output/server/node_modules/@iconify/utils/lib/loader/utils.js +63 -0
  202. package/.output/server/node_modules/@iconify/utils/lib/misc/objects.js +27 -0
  203. package/.output/server/node_modules/@iconify/utils/lib/misc/strings.js +27 -0
  204. package/.output/server/node_modules/@iconify/utils/lib/misc/title.js +10 -0
  205. package/.output/server/node_modules/@iconify/utils/lib/svg/build.js +115 -0
  206. package/.output/server/node_modules/@iconify/utils/lib/svg/defs.js +32 -0
  207. package/.output/server/node_modules/@iconify/utils/lib/svg/encode-svg-for-css.js +15 -0
  208. package/.output/server/node_modules/@iconify/utils/lib/svg/html.js +10 -0
  209. package/.output/server/node_modules/@iconify/utils/lib/svg/id.js +42 -0
  210. package/.output/server/node_modules/@iconify/utils/lib/svg/inner-html.js +23 -0
  211. package/.output/server/node_modules/@iconify/utils/lib/svg/parse.js +69 -0
  212. package/.output/server/node_modules/@iconify/utils/lib/svg/pretty.js +55 -0
  213. package/.output/server/node_modules/@iconify/utils/lib/svg/size.js +28 -0
  214. package/.output/server/node_modules/@iconify/utils/lib/svg/trim.js +8 -0
  215. package/.output/server/node_modules/@iconify/utils/lib/svg/url.js +23 -0
  216. package/.output/server/node_modules/@iconify/utils/lib/svg/viewbox.js +9 -0
  217. package/.output/server/node_modules/@iconify/utils/package.json +118 -0
  218. package/.output/server/node_modules/@mongodb-js/saslprep/dist/code-points-data.js +5 -0
  219. package/.output/server/node_modules/@mongodb-js/saslprep/dist/index.js +65 -0
  220. package/.output/server/node_modules/@mongodb-js/saslprep/dist/memory-code-points.js +32 -0
  221. package/.output/server/node_modules/@mongodb-js/saslprep/dist/node.js +15 -0
  222. package/.output/server/node_modules/@mongodb-js/saslprep/package.json +87 -0
  223. package/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6763 -0
  224. package/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
  225. package/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +689 -0
  226. package/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
  227. package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1413 -0
  228. package/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
  229. package/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1877 -0
  230. package/.output/server/node_modules/@vue/reactivity/package.json +55 -0
  231. package/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6856 -0
  232. package/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
  233. package/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1796 -0
  234. package/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
  235. package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +883 -0
  236. package/.output/server/node_modules/@vue/server-renderer/package.json +55 -0
  237. package/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +604 -0
  238. package/.output/server/node_modules/@vue/shared/package.json +47 -0
  239. package/.output/server/node_modules/bson/lib/bson.cjs +4636 -0
  240. package/.output/server/node_modules/bson/package.json +120 -0
  241. package/.output/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
  242. package/.output/server/node_modules/consola/dist/core.mjs +512 -0
  243. package/.output/server/node_modules/consola/dist/index.mjs +651 -0
  244. package/.output/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
  245. package/.output/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
  246. package/.output/server/node_modules/consola/package.json +136 -0
  247. package/.output/server/node_modules/debug/package.json +64 -0
  248. package/.output/server/node_modules/debug/src/browser.js +272 -0
  249. package/.output/server/node_modules/debug/src/common.js +292 -0
  250. package/.output/server/node_modules/debug/src/index.js +10 -0
  251. package/.output/server/node_modules/debug/src/node.js +263 -0
  252. package/.output/server/node_modules/devalue/index.js +4 -0
  253. package/.output/server/node_modules/devalue/package.json +37 -0
  254. package/.output/server/node_modules/devalue/src/base64.js +110 -0
  255. package/.output/server/node_modules/devalue/src/constants.js +7 -0
  256. package/.output/server/node_modules/devalue/src/parse.js +265 -0
  257. package/.output/server/node_modules/devalue/src/stringify.js +350 -0
  258. package/.output/server/node_modules/devalue/src/uneval.js +490 -0
  259. package/.output/server/node_modules/devalue/src/utils.js +148 -0
  260. package/.output/server/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
  261. package/.output/server/node_modules/entities/dist/commonjs/decode.js +568 -0
  262. package/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-html.js +7 -0
  263. package/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +7 -0
  264. package/.output/server/node_modules/entities/dist/commonjs/internal/bin-trie-flags.js +21 -0
  265. package/.output/server/node_modules/entities/dist/commonjs/internal/decode-shared.js +31 -0
  266. package/.output/server/node_modules/entities/dist/commonjs/package.json +3 -0
  267. package/.output/server/node_modules/entities/package.json +120 -0
  268. package/.output/server/node_modules/esbuild/lib/main.js +2532 -0
  269. package/.output/server/node_modules/esbuild/package.json +74 -0
  270. package/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
  271. package/.output/server/node_modules/estree-walker/package.json +37 -0
  272. package/.output/server/node_modules/hookable/dist/index.mjs +266 -0
  273. package/.output/server/node_modules/hookable/package.json +53 -0
  274. package/.output/server/node_modules/ip-address/dist/address-error.js +12 -0
  275. package/.output/server/node_modules/ip-address/dist/common.js +46 -0
  276. package/.output/server/node_modules/ip-address/dist/ip-address.js +35 -0
  277. package/.output/server/node_modules/ip-address/dist/ipv4.js +360 -0
  278. package/.output/server/node_modules/ip-address/dist/ipv6.js +1003 -0
  279. package/.output/server/node_modules/ip-address/dist/v4/constants.js +8 -0
  280. package/.output/server/node_modules/ip-address/dist/v6/constants.js +76 -0
  281. package/.output/server/node_modules/ip-address/dist/v6/helpers.js +45 -0
  282. package/.output/server/node_modules/ip-address/dist/v6/regular-expressions.js +95 -0
  283. package/.output/server/node_modules/ip-address/package.json +78 -0
  284. package/.output/server/node_modules/kareem/index.js +668 -0
  285. package/.output/server/node_modules/kareem/package.json +28 -0
  286. package/.output/server/node_modules/memory-pager/index.js +160 -0
  287. package/.output/server/node_modules/memory-pager/package.json +24 -0
  288. package/.output/server/node_modules/mongodb/lib/admin.js +136 -0
  289. package/.output/server/node_modules/mongodb/lib/bson.js +84 -0
  290. package/.output/server/node_modules/mongodb/lib/bulk/common.js +837 -0
  291. package/.output/server/node_modules/mongodb/lib/bulk/ordered.js +67 -0
  292. package/.output/server/node_modules/mongodb/lib/bulk/unordered.js +92 -0
  293. package/.output/server/node_modules/mongodb/lib/change_stream.js +465 -0
  294. package/.output/server/node_modules/mongodb/lib/client-side-encryption/auto_encrypter.js +274 -0
  295. package/.output/server/node_modules/mongodb/lib/client-side-encryption/client_encryption.js +610 -0
  296. package/.output/server/node_modules/mongodb/lib/client-side-encryption/crypto_callbacks.js +81 -0
  297. package/.output/server/node_modules/mongodb/lib/client-side-encryption/errors.js +136 -0
  298. package/.output/server/node_modules/mongodb/lib/client-side-encryption/mongocryptd_manager.js +85 -0
  299. package/.output/server/node_modules/mongodb/lib/client-side-encryption/providers/aws.js +23 -0
  300. package/.output/server/node_modules/mongodb/lib/client-side-encryption/providers/azure.js +132 -0
  301. package/.output/server/node_modules/mongodb/lib/client-side-encryption/providers/gcp.js +16 -0
  302. package/.output/server/node_modules/mongodb/lib/client-side-encryption/providers/index.js +43 -0
  303. package/.output/server/node_modules/mongodb/lib/client-side-encryption/state_machine.js +426 -0
  304. package/.output/server/node_modules/mongodb/lib/cmap/auth/auth_provider.js +51 -0
  305. package/.output/server/node_modules/mongodb/lib/cmap/auth/aws_temporary_credentials.js +150 -0
  306. package/.output/server/node_modules/mongodb/lib/cmap/auth/gssapi.js +154 -0
  307. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongo_credentials.js +183 -0
  308. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_aws.js +138 -0
  309. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +84 -0
  310. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +62 -0
  311. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/callback_workflow.js +141 -0
  312. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/command_builders.js +44 -0
  313. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +39 -0
  314. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +122 -0
  315. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +31 -0
  316. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/token_cache.js +52 -0
  317. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +22 -0
  318. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc.js +73 -0
  319. package/.output/server/node_modules/mongodb/lib/cmap/auth/plain.js +26 -0
  320. package/.output/server/node_modules/mongodb/lib/cmap/auth/providers.js +23 -0
  321. package/.output/server/node_modules/mongodb/lib/cmap/auth/scram.js +254 -0
  322. package/.output/server/node_modules/mongodb/lib/cmap/auth/x509.js +36 -0
  323. package/.output/server/node_modules/mongodb/lib/cmap/command_monitoring_events.js +223 -0
  324. package/.output/server/node_modules/mongodb/lib/cmap/commands.js +535 -0
  325. package/.output/server/node_modules/mongodb/lib/cmap/connect.js +366 -0
  326. package/.output/server/node_modules/mongodb/lib/cmap/connection.js +570 -0
  327. package/.output/server/node_modules/mongodb/lib/cmap/connection_pool.js +558 -0
  328. package/.output/server/node_modules/mongodb/lib/cmap/connection_pool_events.js +190 -0
  329. package/.output/server/node_modules/mongodb/lib/cmap/errors.js +108 -0
  330. package/.output/server/node_modules/mongodb/lib/cmap/handshake/client_metadata.js +239 -0
  331. package/.output/server/node_modules/mongodb/lib/cmap/metrics.js +62 -0
  332. package/.output/server/node_modules/mongodb/lib/cmap/stream_description.js +70 -0
  333. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/compression.js +163 -0
  334. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/constants.js +19 -0
  335. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_data.js +112 -0
  336. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_demand/document.js +222 -0
  337. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/responses.js +315 -0
  338. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/shared.js +35 -0
  339. package/.output/server/node_modules/mongodb/lib/collection.js +751 -0
  340. package/.output/server/node_modules/mongodb/lib/connection_string.js +1091 -0
  341. package/.output/server/node_modules/mongodb/lib/constants.js +170 -0
  342. package/.output/server/node_modules/mongodb/lib/cursor/abstract_cursor.js +941 -0
  343. package/.output/server/node_modules/mongodb/lib/cursor/aggregation_cursor.js +164 -0
  344. package/.output/server/node_modules/mongodb/lib/cursor/change_stream_cursor.js +104 -0
  345. package/.output/server/node_modules/mongodb/lib/cursor/client_bulk_write_cursor.js +52 -0
  346. package/.output/server/node_modules/mongodb/lib/cursor/explainable_cursor.js +36 -0
  347. package/.output/server/node_modules/mongodb/lib/cursor/find_cursor.js +388 -0
  348. package/.output/server/node_modules/mongodb/lib/cursor/list_collections_cursor.js +34 -0
  349. package/.output/server/node_modules/mongodb/lib/cursor/list_indexes_cursor.js +32 -0
  350. package/.output/server/node_modules/mongodb/lib/cursor/list_search_indexes_cursor.js +14 -0
  351. package/.output/server/node_modules/mongodb/lib/cursor/run_command_cursor.js +94 -0
  352. package/.output/server/node_modules/mongodb/lib/db.js +420 -0
  353. package/.output/server/node_modules/mongodb/lib/deps.js +125 -0
  354. package/.output/server/node_modules/mongodb/lib/encrypter.js +106 -0
  355. package/.output/server/node_modules/mongodb/lib/error.js +1383 -0
  356. package/.output/server/node_modules/mongodb/lib/explain.js +59 -0
  357. package/.output/server/node_modules/mongodb/lib/gridfs/download.js +305 -0
  358. package/.output/server/node_modules/mongodb/lib/gridfs/index.js +164 -0
  359. package/.output/server/node_modules/mongodb/lib/gridfs/upload.js +364 -0
  360. package/.output/server/node_modules/mongodb/lib/index.js +195 -0
  361. package/.output/server/node_modules/mongodb/lib/mongo_client.js +566 -0
  362. package/.output/server/node_modules/mongodb/lib/mongo_client_auth_providers.js +86 -0
  363. package/.output/server/node_modules/mongodb/lib/mongo_logger.js +649 -0
  364. package/.output/server/node_modules/mongodb/lib/mongo_types.js +57 -0
  365. package/.output/server/node_modules/mongodb/lib/operations/aggregate.js +93 -0
  366. package/.output/server/node_modules/mongodb/lib/operations/client_bulk_write/client_bulk_write.js +51 -0
  367. package/.output/server/node_modules/mongodb/lib/operations/client_bulk_write/command_builder.js +340 -0
  368. package/.output/server/node_modules/mongodb/lib/operations/client_bulk_write/executor.js +120 -0
  369. package/.output/server/node_modules/mongodb/lib/operations/client_bulk_write/results_merger.js +204 -0
  370. package/.output/server/node_modules/mongodb/lib/operations/command.js +83 -0
  371. package/.output/server/node_modules/mongodb/lib/operations/count.js +45 -0
  372. package/.output/server/node_modules/mongodb/lib/operations/create_collection.js +110 -0
  373. package/.output/server/node_modules/mongodb/lib/operations/delete.js +125 -0
  374. package/.output/server/node_modules/mongodb/lib/operations/distinct.js +61 -0
  375. package/.output/server/node_modules/mongodb/lib/operations/drop.js +94 -0
  376. package/.output/server/node_modules/mongodb/lib/operations/estimated_document_count.js +41 -0
  377. package/.output/server/node_modules/mongodb/lib/operations/execute_operation.js +236 -0
  378. package/.output/server/node_modules/mongodb/lib/operations/find.js +148 -0
  379. package/.output/server/node_modules/mongodb/lib/operations/find_and_modify.js +158 -0
  380. package/.output/server/node_modules/mongodb/lib/operations/get_more.js +62 -0
  381. package/.output/server/node_modules/mongodb/lib/operations/indexes.js +186 -0
  382. package/.output/server/node_modules/mongodb/lib/operations/insert.js +70 -0
  383. package/.output/server/node_modules/mongodb/lib/operations/kill_cursors.js +43 -0
  384. package/.output/server/node_modules/mongodb/lib/operations/list_collections.js +53 -0
  385. package/.output/server/node_modules/mongodb/lib/operations/list_databases.js +40 -0
  386. package/.output/server/node_modules/mongodb/lib/operations/operation.js +102 -0
  387. package/.output/server/node_modules/mongodb/lib/operations/profiling_level.js +43 -0
  388. package/.output/server/node_modules/mongodb/lib/operations/remove_user.js +27 -0
  389. package/.output/server/node_modules/mongodb/lib/operations/rename.js +38 -0
  390. package/.output/server/node_modules/mongodb/lib/operations/run_command.js +47 -0
  391. package/.output/server/node_modules/mongodb/lib/operations/search_indexes/create.js +33 -0
  392. package/.output/server/node_modules/mongodb/lib/operations/search_indexes/drop.js +43 -0
  393. package/.output/server/node_modules/mongodb/lib/operations/search_indexes/update.js +35 -0
  394. package/.output/server/node_modules/mongodb/lib/operations/set_profiling_level.js +53 -0
  395. package/.output/server/node_modules/mongodb/lib/operations/stats.js +27 -0
  396. package/.output/server/node_modules/mongodb/lib/operations/update.js +188 -0
  397. package/.output/server/node_modules/mongodb/lib/operations/validate_collection.js +37 -0
  398. package/.output/server/node_modules/mongodb/lib/read_concern.js +73 -0
  399. package/.output/server/node_modules/mongodb/lib/read_preference.js +195 -0
  400. package/.output/server/node_modules/mongodb/lib/resource_management.js +58 -0
  401. package/.output/server/node_modules/mongodb/lib/sdam/common.js +49 -0
  402. package/.output/server/node_modules/mongodb/lib/sdam/events.js +146 -0
  403. package/.output/server/node_modules/mongodb/lib/sdam/monitor.js +544 -0
  404. package/.output/server/node_modules/mongodb/lib/sdam/server.js +392 -0
  405. package/.output/server/node_modules/mongodb/lib/sdam/server_description.js +204 -0
  406. package/.output/server/node_modules/mongodb/lib/sdam/server_selection.js +231 -0
  407. package/.output/server/node_modules/mongodb/lib/sdam/server_selection_events.js +85 -0
  408. package/.output/server/node_modules/mongodb/lib/sdam/srv_polling.js +108 -0
  409. package/.output/server/node_modules/mongodb/lib/sdam/topology.js +694 -0
  410. package/.output/server/node_modules/mongodb/lib/sdam/topology_description.js +383 -0
  411. package/.output/server/node_modules/mongodb/lib/sessions.js +827 -0
  412. package/.output/server/node_modules/mongodb/lib/sort.js +103 -0
  413. package/.output/server/node_modules/mongodb/lib/timeout.js +296 -0
  414. package/.output/server/node_modules/mongodb/lib/transactions.js +146 -0
  415. package/.output/server/node_modules/mongodb/lib/utils.js +1203 -0
  416. package/.output/server/node_modules/mongodb/lib/write_concern.js +100 -0
  417. package/.output/server/node_modules/mongodb/package.json +178 -0
  418. package/.output/server/node_modules/mongodb-connection-string-url/lib/index.js +213 -0
  419. package/.output/server/node_modules/mongodb-connection-string-url/lib/redact.js +86 -0
  420. package/.output/server/node_modules/mongodb-connection-string-url/package.json +62 -0
  421. package/.output/server/node_modules/mongoose/index.js +64 -0
  422. package/.output/server/node_modules/mongoose/lib/aggregate.js +1245 -0
  423. package/.output/server/node_modules/mongoose/lib/browserDocument.js +101 -0
  424. package/.output/server/node_modules/mongoose/lib/cast/bigint.js +46 -0
  425. package/.output/server/node_modules/mongoose/lib/cast/boolean.js +32 -0
  426. package/.output/server/node_modules/mongoose/lib/cast/date.js +41 -0
  427. package/.output/server/node_modules/mongoose/lib/cast/decimal128.js +39 -0
  428. package/.output/server/node_modules/mongoose/lib/cast/double.js +50 -0
  429. package/.output/server/node_modules/mongoose/lib/cast/int32.js +36 -0
  430. package/.output/server/node_modules/mongoose/lib/cast/number.js +42 -0
  431. package/.output/server/node_modules/mongoose/lib/cast/objectid.js +29 -0
  432. package/.output/server/node_modules/mongoose/lib/cast/string.js +37 -0
  433. package/.output/server/node_modules/mongoose/lib/cast/uuid.js +78 -0
  434. package/.output/server/node_modules/mongoose/lib/cast.js +444 -0
  435. package/.output/server/node_modules/mongoose/lib/collection.js +321 -0
  436. package/.output/server/node_modules/mongoose/lib/connection.js +1850 -0
  437. package/.output/server/node_modules/mongoose/lib/connectionState.js +26 -0
  438. package/.output/server/node_modules/mongoose/lib/constants.js +73 -0
  439. package/.output/server/node_modules/mongoose/lib/cursor/aggregationCursor.js +476 -0
  440. package/.output/server/node_modules/mongoose/lib/cursor/changeStream.js +198 -0
  441. package/.output/server/node_modules/mongoose/lib/cursor/queryCursor.js +629 -0
  442. package/.output/server/node_modules/mongoose/lib/document.js +5512 -0
  443. package/.output/server/node_modules/mongoose/lib/documentProvider.js +30 -0
  444. package/.output/server/node_modules/mongoose/lib/driver.js +15 -0
  445. package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/bulkWriteResult.js +5 -0
  446. package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js +471 -0
  447. package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js +528 -0
  448. package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/index.js +10 -0
  449. package/.output/server/node_modules/mongoose/lib/error/bulkSaveIncompleteError.js +44 -0
  450. package/.output/server/node_modules/mongoose/lib/error/bulkWriteError.js +41 -0
  451. package/.output/server/node_modules/mongoose/lib/error/cast.js +158 -0
  452. package/.output/server/node_modules/mongoose/lib/error/createCollectionsError.js +26 -0
  453. package/.output/server/node_modules/mongoose/lib/error/divergentArray.js +40 -0
  454. package/.output/server/node_modules/mongoose/lib/error/eachAsyncMultiError.js +41 -0
  455. package/.output/server/node_modules/mongoose/lib/error/index.js +237 -0
  456. package/.output/server/node_modules/mongoose/lib/error/invalidSchemaOption.js +32 -0
  457. package/.output/server/node_modules/mongoose/lib/error/messages.js +47 -0
  458. package/.output/server/node_modules/mongoose/lib/error/missingSchema.js +33 -0
  459. package/.output/server/node_modules/mongoose/lib/error/mongooseError.js +13 -0
  460. package/.output/server/node_modules/mongoose/lib/error/notFound.js +47 -0
  461. package/.output/server/node_modules/mongoose/lib/error/objectExpected.js +31 -0
  462. package/.output/server/node_modules/mongoose/lib/error/objectParameter.js +32 -0
  463. package/.output/server/node_modules/mongoose/lib/error/overwriteModel.js +31 -0
  464. package/.output/server/node_modules/mongoose/lib/error/parallelSave.js +33 -0
  465. package/.output/server/node_modules/mongoose/lib/error/parallelValidate.js +33 -0
  466. package/.output/server/node_modules/mongoose/lib/error/serverSelection.js +62 -0
  467. package/.output/server/node_modules/mongoose/lib/error/setOptionError.js +103 -0
  468. package/.output/server/node_modules/mongoose/lib/error/strict.js +35 -0
  469. package/.output/server/node_modules/mongoose/lib/error/strictPopulate.js +31 -0
  470. package/.output/server/node_modules/mongoose/lib/error/syncIndexes.js +30 -0
  471. package/.output/server/node_modules/mongoose/lib/error/validation.js +105 -0
  472. package/.output/server/node_modules/mongoose/lib/error/validator.js +100 -0
  473. package/.output/server/node_modules/mongoose/lib/error/version.js +38 -0
  474. package/.output/server/node_modules/mongoose/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +39 -0
  475. package/.output/server/node_modules/mongoose/lib/helpers/aggregate/stringifyFunctionOperators.js +50 -0
  476. package/.output/server/node_modules/mongoose/lib/helpers/arrayDepth.js +33 -0
  477. package/.output/server/node_modules/mongoose/lib/helpers/clone.js +236 -0
  478. package/.output/server/node_modules/mongoose/lib/helpers/common.js +127 -0
  479. package/.output/server/node_modules/mongoose/lib/helpers/createJSONSchemaTypeDefinition.js +24 -0
  480. package/.output/server/node_modules/mongoose/lib/helpers/cursor/eachAsync.js +225 -0
  481. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/applyEmbeddedDiscriminators.js +36 -0
  482. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +16 -0
  483. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +12 -0
  484. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getConstructor.js +29 -0
  485. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getDiscriminatorByValue.js +28 -0
  486. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +27 -0
  487. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/mergeDiscriminatorSchema.js +91 -0
  488. package/.output/server/node_modules/mongoose/lib/helpers/document/applyDefaults.js +132 -0
  489. package/.output/server/node_modules/mongoose/lib/helpers/document/applyTimestamps.js +105 -0
  490. package/.output/server/node_modules/mongoose/lib/helpers/document/applyVirtuals.js +146 -0
  491. package/.output/server/node_modules/mongoose/lib/helpers/document/cleanModifiedSubpaths.js +45 -0
  492. package/.output/server/node_modules/mongoose/lib/helpers/document/compile.js +238 -0
  493. package/.output/server/node_modules/mongoose/lib/helpers/document/getDeepestSubdocumentForPath.js +38 -0
  494. package/.output/server/node_modules/mongoose/lib/helpers/document/getEmbeddedDiscriminatorPath.js +53 -0
  495. package/.output/server/node_modules/mongoose/lib/helpers/document/handleSpreadDoc.js +35 -0
  496. package/.output/server/node_modules/mongoose/lib/helpers/each.js +25 -0
  497. package/.output/server/node_modules/mongoose/lib/helpers/error/combinePathErrors.js +22 -0
  498. package/.output/server/node_modules/mongoose/lib/helpers/firstKey.js +8 -0
  499. package/.output/server/node_modules/mongoose/lib/helpers/get.js +65 -0
  500. package/.output/server/node_modules/mongoose/lib/helpers/getConstructorName.js +16 -0
  501. package/.output/server/node_modules/mongoose/lib/helpers/getDefaultBulkwriteResult.js +18 -0
  502. package/.output/server/node_modules/mongoose/lib/helpers/getFunctionName.js +10 -0
  503. package/.output/server/node_modules/mongoose/lib/helpers/immediate.js +16 -0
  504. package/.output/server/node_modules/mongoose/lib/helpers/indexes/applySchemaCollation.js +13 -0
  505. package/.output/server/node_modules/mongoose/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +14 -0
  506. package/.output/server/node_modules/mongoose/lib/helpers/indexes/getRelatedIndexes.js +63 -0
  507. package/.output/server/node_modules/mongoose/lib/helpers/indexes/isDefaultIdIndex.js +18 -0
  508. package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexEqual.js +96 -0
  509. package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexSpecEqual.js +32 -0
  510. package/.output/server/node_modules/mongoose/lib/helpers/indexes/isTextIndex.js +16 -0
  511. package/.output/server/node_modules/mongoose/lib/helpers/indexes/isTimeseriesIndex.js +16 -0
  512. package/.output/server/node_modules/mongoose/lib/helpers/isAsyncFunction.js +9 -0
  513. package/.output/server/node_modules/mongoose/lib/helpers/isBsonType.js +15 -0
  514. package/.output/server/node_modules/mongoose/lib/helpers/isMongooseObject.js +22 -0
  515. package/.output/server/node_modules/mongoose/lib/helpers/isObject.js +16 -0
  516. package/.output/server/node_modules/mongoose/lib/helpers/isPOJO.js +12 -0
  517. package/.output/server/node_modules/mongoose/lib/helpers/isPromise.js +6 -0
  518. package/.output/server/node_modules/mongoose/lib/helpers/isSimpleValidator.js +22 -0
  519. package/.output/server/node_modules/mongoose/lib/helpers/minimize.js +41 -0
  520. package/.output/server/node_modules/mongoose/lib/helpers/model/applyDefaultsToPOJO.js +52 -0
  521. package/.output/server/node_modules/mongoose/lib/helpers/model/applyHooks.js +150 -0
  522. package/.output/server/node_modules/mongoose/lib/helpers/model/applyMethods.js +70 -0
  523. package/.output/server/node_modules/mongoose/lib/helpers/model/applyStaticHooks.js +80 -0
  524. package/.output/server/node_modules/mongoose/lib/helpers/model/applyStatics.js +13 -0
  525. package/.output/server/node_modules/mongoose/lib/helpers/model/castBulkWrite.js +326 -0
  526. package/.output/server/node_modules/mongoose/lib/helpers/model/decorateBulkWriteResult.js +8 -0
  527. package/.output/server/node_modules/mongoose/lib/helpers/model/discriminator.js +265 -0
  528. package/.output/server/node_modules/mongoose/lib/helpers/model/pushNestedArrayPaths.js +15 -0
  529. package/.output/server/node_modules/mongoose/lib/helpers/omitUndefined.js +20 -0
  530. package/.output/server/node_modules/mongoose/lib/helpers/parallelLimit.js +55 -0
  531. package/.output/server/node_modules/mongoose/lib/helpers/path/parentPaths.js +18 -0
  532. package/.output/server/node_modules/mongoose/lib/helpers/path/setDottedPath.js +33 -0
  533. package/.output/server/node_modules/mongoose/lib/helpers/pluralize.js +95 -0
  534. package/.output/server/node_modules/mongoose/lib/helpers/populate/assignRawDocsToIdStructure.js +136 -0
  535. package/.output/server/node_modules/mongoose/lib/helpers/populate/assignVals.js +360 -0
  536. package/.output/server/node_modules/mongoose/lib/helpers/populate/createPopulateQueryFilter.js +97 -0
  537. package/.output/server/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js +766 -0
  538. package/.output/server/node_modules/mongoose/lib/helpers/populate/getSchemaTypes.js +229 -0
  539. package/.output/server/node_modules/mongoose/lib/helpers/populate/getVirtual.js +103 -0
  540. package/.output/server/node_modules/mongoose/lib/helpers/populate/leanPopulateMap.js +7 -0
  541. package/.output/server/node_modules/mongoose/lib/helpers/populate/lookupLocalFields.js +40 -0
  542. package/.output/server/node_modules/mongoose/lib/helpers/populate/markArraySubdocsPopulated.js +49 -0
  543. package/.output/server/node_modules/mongoose/lib/helpers/populate/modelNamesFromRefPath.js +66 -0
  544. package/.output/server/node_modules/mongoose/lib/helpers/populate/removeDeselectedForeignField.js +31 -0
  545. package/.output/server/node_modules/mongoose/lib/helpers/populate/setPopulatedVirtualValue.js +33 -0
  546. package/.output/server/node_modules/mongoose/lib/helpers/populate/skipPopulateValue.js +10 -0
  547. package/.output/server/node_modules/mongoose/lib/helpers/populate/validateRef.js +19 -0
  548. package/.output/server/node_modules/mongoose/lib/helpers/printJestWarning.js +21 -0
  549. package/.output/server/node_modules/mongoose/lib/helpers/processConnectionOptions.js +65 -0
  550. package/.output/server/node_modules/mongoose/lib/helpers/projection/applyProjection.js +83 -0
  551. package/.output/server/node_modules/mongoose/lib/helpers/projection/hasIncludedChildren.js +41 -0
  552. package/.output/server/node_modules/mongoose/lib/helpers/projection/isDefiningProjection.js +18 -0
  553. package/.output/server/node_modules/mongoose/lib/helpers/projection/isExclusive.js +37 -0
  554. package/.output/server/node_modules/mongoose/lib/helpers/projection/isInclusive.js +39 -0
  555. package/.output/server/node_modules/mongoose/lib/helpers/projection/isNestedProjection.js +8 -0
  556. package/.output/server/node_modules/mongoose/lib/helpers/projection/isPathExcluded.js +40 -0
  557. package/.output/server/node_modules/mongoose/lib/helpers/projection/isPathSelectedInclusive.js +28 -0
  558. package/.output/server/node_modules/mongoose/lib/helpers/projection/isSubpath.js +14 -0
  559. package/.output/server/node_modules/mongoose/lib/helpers/projection/parseProjection.js +33 -0
  560. package/.output/server/node_modules/mongoose/lib/helpers/promiseOrCallback.js +54 -0
  561. package/.output/server/node_modules/mongoose/lib/helpers/query/applyGlobalOption.js +29 -0
  562. package/.output/server/node_modules/mongoose/lib/helpers/query/cast$expr.js +289 -0
  563. package/.output/server/node_modules/mongoose/lib/helpers/query/castFilterPath.js +54 -0
  564. package/.output/server/node_modules/mongoose/lib/helpers/query/castUpdate.js +641 -0
  565. package/.output/server/node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js +103 -0
  566. package/.output/server/node_modules/mongoose/lib/helpers/query/handleImmutable.js +44 -0
  567. package/.output/server/node_modules/mongoose/lib/helpers/query/handleReadPreferenceAliases.js +23 -0
  568. package/.output/server/node_modules/mongoose/lib/helpers/query/hasDollarKeys.js +23 -0
  569. package/.output/server/node_modules/mongoose/lib/helpers/query/isOperator.js +14 -0
  570. package/.output/server/node_modules/mongoose/lib/helpers/query/sanitizeFilter.js +41 -0
  571. package/.output/server/node_modules/mongoose/lib/helpers/query/sanitizeProjection.js +14 -0
  572. package/.output/server/node_modules/mongoose/lib/helpers/query/selectPopulatedFields.js +62 -0
  573. package/.output/server/node_modules/mongoose/lib/helpers/query/trusted.js +13 -0
  574. package/.output/server/node_modules/mongoose/lib/helpers/schema/addAutoId.js +7 -0
  575. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyBuiltinPlugins.js +12 -0
  576. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyPlugins.js +55 -0
  577. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyReadConcern.js +20 -0
  578. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyWriteConcern.js +37 -0
  579. package/.output/server/node_modules/mongoose/lib/helpers/schema/cleanPositionalOperators.js +12 -0
  580. package/.output/server/node_modules/mongoose/lib/helpers/schema/getIndexes.js +177 -0
  581. package/.output/server/node_modules/mongoose/lib/helpers/schema/getKeysInSchemaOrder.js +28 -0
  582. package/.output/server/node_modules/mongoose/lib/helpers/schema/getPath.js +43 -0
  583. package/.output/server/node_modules/mongoose/lib/helpers/schema/getSubdocumentStrictValue.js +32 -0
  584. package/.output/server/node_modules/mongoose/lib/helpers/schema/handleIdOption.js +20 -0
  585. package/.output/server/node_modules/mongoose/lib/helpers/schema/handleTimestampOption.js +24 -0
  586. package/.output/server/node_modules/mongoose/lib/helpers/schema/idGetter.js +34 -0
  587. package/.output/server/node_modules/mongoose/lib/helpers/schema/merge.js +36 -0
  588. package/.output/server/node_modules/mongoose/lib/helpers/schematype/handleImmutable.js +50 -0
  589. package/.output/server/node_modules/mongoose/lib/helpers/setDefaultsOnInsert.js +161 -0
  590. package/.output/server/node_modules/mongoose/lib/helpers/specialProperties.js +3 -0
  591. package/.output/server/node_modules/mongoose/lib/helpers/symbols.js +20 -0
  592. package/.output/server/node_modules/mongoose/lib/helpers/timers.js +3 -0
  593. package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setDocumentTimestamps.js +26 -0
  594. package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setupTimestamps.js +110 -0
  595. package/.output/server/node_modules/mongoose/lib/helpers/topology/allServersUnknown.js +12 -0
  596. package/.output/server/node_modules/mongoose/lib/helpers/topology/isAtlas.js +31 -0
  597. package/.output/server/node_modules/mongoose/lib/helpers/topology/isSSLError.js +16 -0
  598. package/.output/server/node_modules/mongoose/lib/helpers/update/applyTimestampsToChildren.js +193 -0
  599. package/.output/server/node_modules/mongoose/lib/helpers/update/applyTimestampsToUpdate.js +130 -0
  600. package/.output/server/node_modules/mongoose/lib/helpers/update/castArrayFilters.js +113 -0
  601. package/.output/server/node_modules/mongoose/lib/helpers/update/decorateUpdateWithVersionKey.js +35 -0
  602. package/.output/server/node_modules/mongoose/lib/helpers/update/modifiedPaths.js +33 -0
  603. package/.output/server/node_modules/mongoose/lib/helpers/update/moveImmutableProperties.js +53 -0
  604. package/.output/server/node_modules/mongoose/lib/helpers/update/removeUnusedArrayFilters.js +32 -0
  605. package/.output/server/node_modules/mongoose/lib/helpers/update/updatedPathsByArrayFilter.js +27 -0
  606. package/.output/server/node_modules/mongoose/lib/helpers/updateValidators.js +247 -0
  607. package/.output/server/node_modules/mongoose/lib/index.js +17 -0
  608. package/.output/server/node_modules/mongoose/lib/internal.js +46 -0
  609. package/.output/server/node_modules/mongoose/lib/model.js +5208 -0
  610. package/.output/server/node_modules/mongoose/lib/modifiedPathsSnapshot.js +9 -0
  611. package/.output/server/node_modules/mongoose/lib/mongoose.js +1383 -0
  612. package/.output/server/node_modules/mongoose/lib/options/populateOptions.js +36 -0
  613. package/.output/server/node_modules/mongoose/lib/options/propertyOptions.js +8 -0
  614. package/.output/server/node_modules/mongoose/lib/options/saveOptions.js +16 -0
  615. package/.output/server/node_modules/mongoose/lib/options/schemaArrayOptions.js +78 -0
  616. package/.output/server/node_modules/mongoose/lib/options/schemaBufferOptions.js +38 -0
  617. package/.output/server/node_modules/mongoose/lib/options/schemaDateOptions.js +71 -0
  618. package/.output/server/node_modules/mongoose/lib/options/schemaDocumentArrayOptions.js +68 -0
  619. package/.output/server/node_modules/mongoose/lib/options/schemaMapOptions.js +43 -0
  620. package/.output/server/node_modules/mongoose/lib/options/schemaNumberOptions.js +101 -0
  621. package/.output/server/node_modules/mongoose/lib/options/schemaObjectIdOptions.js +64 -0
  622. package/.output/server/node_modules/mongoose/lib/options/schemaStringOptions.js +138 -0
  623. package/.output/server/node_modules/mongoose/lib/options/schemaSubdocumentOptions.js +66 -0
  624. package/.output/server/node_modules/mongoose/lib/options/schemaTypeOptions.js +244 -0
  625. package/.output/server/node_modules/mongoose/lib/options/schemaUnionOptions.js +32 -0
  626. package/.output/server/node_modules/mongoose/lib/options/virtualOptions.js +164 -0
  627. package/.output/server/node_modules/mongoose/lib/options.js +18 -0
  628. package/.output/server/node_modules/mongoose/lib/plugins/index.js +6 -0
  629. package/.output/server/node_modules/mongoose/lib/plugins/saveSubdocs.js +102 -0
  630. package/.output/server/node_modules/mongoose/lib/plugins/sharding.js +83 -0
  631. package/.output/server/node_modules/mongoose/lib/plugins/trackTransaction.js +85 -0
  632. package/.output/server/node_modules/mongoose/lib/plugins/validateBeforeSave.js +51 -0
  633. package/.output/server/node_modules/mongoose/lib/query.js +5693 -0
  634. package/.output/server/node_modules/mongoose/lib/queryHelpers.js +394 -0
  635. package/.output/server/node_modules/mongoose/lib/schema/array.js +744 -0
  636. package/.output/server/node_modules/mongoose/lib/schema/bigint.js +282 -0
  637. package/.output/server/node_modules/mongoose/lib/schema/boolean.js +332 -0
  638. package/.output/server/node_modules/mongoose/lib/schema/buffer.js +343 -0
  639. package/.output/server/node_modules/mongoose/lib/schema/date.js +467 -0
  640. package/.output/server/node_modules/mongoose/lib/schema/decimal128.js +263 -0
  641. package/.output/server/node_modules/mongoose/lib/schema/documentArray.js +701 -0
  642. package/.output/server/node_modules/mongoose/lib/schema/documentArrayElement.js +102 -0
  643. package/.output/server/node_modules/mongoose/lib/schema/double.js +246 -0
  644. package/.output/server/node_modules/mongoose/lib/schema/index.js +31 -0
  645. package/.output/server/node_modules/mongoose/lib/schema/int32.js +289 -0
  646. package/.output/server/node_modules/mongoose/lib/schema/map.js +201 -0
  647. package/.output/server/node_modules/mongoose/lib/schema/mixed.js +146 -0
  648. package/.output/server/node_modules/mongoose/lib/schema/number.js +498 -0
  649. package/.output/server/node_modules/mongoose/lib/schema/objectId.js +333 -0
  650. package/.output/server/node_modules/mongoose/lib/schema/operators/bitwise.js +38 -0
  651. package/.output/server/node_modules/mongoose/lib/schema/operators/exists.js +12 -0
  652. package/.output/server/node_modules/mongoose/lib/schema/operators/geospatial.js +107 -0
  653. package/.output/server/node_modules/mongoose/lib/schema/operators/helpers.js +32 -0
  654. package/.output/server/node_modules/mongoose/lib/schema/operators/text.js +39 -0
  655. package/.output/server/node_modules/mongoose/lib/schema/operators/type.js +20 -0
  656. package/.output/server/node_modules/mongoose/lib/schema/string.js +733 -0
  657. package/.output/server/node_modules/mongoose/lib/schema/subdocument.js +445 -0
  658. package/.output/server/node_modules/mongoose/lib/schema/symbols.js +5 -0
  659. package/.output/server/node_modules/mongoose/lib/schema/union.js +113 -0
  660. package/.output/server/node_modules/mongoose/lib/schema/uuid.js +326 -0
  661. package/.output/server/node_modules/mongoose/lib/schema.js +3185 -0
  662. package/.output/server/node_modules/mongoose/lib/schemaType.js +1853 -0
  663. package/.output/server/node_modules/mongoose/lib/stateMachine.js +232 -0
  664. package/.output/server/node_modules/mongoose/lib/types/array/index.js +119 -0
  665. package/.output/server/node_modules/mongoose/lib/types/array/isMongooseArray.js +5 -0
  666. package/.output/server/node_modules/mongoose/lib/types/array/methods/index.js +1096 -0
  667. package/.output/server/node_modules/mongoose/lib/types/arraySubdocument.js +208 -0
  668. package/.output/server/node_modules/mongoose/lib/types/buffer.js +294 -0
  669. package/.output/server/node_modules/mongoose/lib/types/decimal128.js +13 -0
  670. package/.output/server/node_modules/mongoose/lib/types/documentArray/index.js +113 -0
  671. package/.output/server/node_modules/mongoose/lib/types/documentArray/isMongooseDocumentArray.js +5 -0
  672. package/.output/server/node_modules/mongoose/lib/types/documentArray/methods/index.js +413 -0
  673. package/.output/server/node_modules/mongoose/lib/types/double.js +13 -0
  674. package/.output/server/node_modules/mongoose/lib/types/index.js +23 -0
  675. package/.output/server/node_modules/mongoose/lib/types/map.js +419 -0
  676. package/.output/server/node_modules/mongoose/lib/types/objectid.js +41 -0
  677. package/.output/server/node_modules/mongoose/lib/types/subdocument.js +492 -0
  678. package/.output/server/node_modules/mongoose/lib/types/uuid.js +13 -0
  679. package/.output/server/node_modules/mongoose/lib/utils.js +1043 -0
  680. package/.output/server/node_modules/mongoose/lib/validOptions.js +42 -0
  681. package/.output/server/node_modules/mongoose/lib/virtualType.js +204 -0
  682. package/.output/server/node_modules/mongoose/package.json +156 -0
  683. package/.output/server/node_modules/mpath/index.js +3 -0
  684. package/.output/server/node_modules/mpath/lib/index.js +336 -0
  685. package/.output/server/node_modules/mpath/lib/stringToParts.js +48 -0
  686. package/.output/server/node_modules/mpath/package.json +144 -0
  687. package/.output/server/node_modules/mquery/lib/collection/collection.js +45 -0
  688. package/.output/server/node_modules/mquery/lib/collection/index.js +13 -0
  689. package/.output/server/node_modules/mquery/lib/collection/node.js +114 -0
  690. package/.output/server/node_modules/mquery/lib/env.js +22 -0
  691. package/.output/server/node_modules/mquery/lib/mquery.js +2705 -0
  692. package/.output/server/node_modules/mquery/lib/permissions.js +78 -0
  693. package/.output/server/node_modules/mquery/lib/utils.js +297 -0
  694. package/.output/server/node_modules/mquery/package.json +38 -0
  695. package/.output/server/node_modules/ms/index.js +162 -0
  696. package/.output/server/node_modules/ms/package.json +38 -0
  697. package/.output/server/node_modules/punycode/package.json +58 -0
  698. package/.output/server/node_modules/punycode/punycode.js +443 -0
  699. package/.output/server/node_modules/sift/index.js +4 -0
  700. package/.output/server/node_modules/sift/lib/index.js +781 -0
  701. package/.output/server/node_modules/sift/package.json +61 -0
  702. package/.output/server/node_modules/smart-buffer/build/smartbuffer.js +1233 -0
  703. package/.output/server/node_modules/smart-buffer/build/utils.js +108 -0
  704. package/.output/server/node_modules/smart-buffer/package.json +81 -0
  705. package/.output/server/node_modules/socks/build/client/socksclient.js +793 -0
  706. package/.output/server/node_modules/socks/build/common/constants.js +108 -0
  707. package/.output/server/node_modules/socks/build/common/helpers.js +167 -0
  708. package/.output/server/node_modules/socks/build/common/receivebuffer.js +43 -0
  709. package/.output/server/node_modules/socks/build/common/util.js +25 -0
  710. package/.output/server/node_modules/socks/build/index.js +18 -0
  711. package/.output/server/node_modules/socks/package.json +58 -0
  712. package/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
  713. package/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  714. package/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
  715. package/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
  716. package/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
  717. package/.output/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
  718. package/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
  719. package/.output/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
  720. package/.output/server/node_modules/source-map-js/lib/source-node.js +413 -0
  721. package/.output/server/node_modules/source-map-js/lib/util.js +594 -0
  722. package/.output/server/node_modules/source-map-js/package.json +71 -0
  723. package/.output/server/node_modules/source-map-js/source-map.js +8 -0
  724. package/.output/server/node_modules/sparse-bitfield/index.js +95 -0
  725. package/.output/server/node_modules/sparse-bitfield/package.json +27 -0
  726. package/.output/server/node_modules/supports-color/index.js +202 -0
  727. package/.output/server/node_modules/supports-color/package.json +64 -0
  728. package/.output/server/node_modules/tailwindcss/dist/chunk-X4GG3EDV.mjs +1 -0
  729. package/.output/server/node_modules/tailwindcss/dist/colors.mjs +1 -0
  730. package/.output/server/node_modules/tailwindcss/package.json +89 -0
  731. package/.output/server/node_modules/tr46/index.js +344 -0
  732. package/.output/server/node_modules/tr46/lib/mappingTable.json +1 -0
  733. package/.output/server/node_modules/tr46/lib/regexes.js +29 -0
  734. package/.output/server/node_modules/tr46/lib/statusMapping.js +9 -0
  735. package/.output/server/node_modules/tr46/package.json +44 -0
  736. package/.output/server/node_modules/ufo/dist/index.mjs +645 -0
  737. package/.output/server/node_modules/ufo/package.json +48 -0
  738. package/.output/server/node_modules/unhead/dist/index.mjs +9 -0
  739. package/.output/server/node_modules/unhead/dist/parser.mjs +508 -0
  740. package/.output/server/node_modules/unhead/dist/plugins.mjs +101 -0
  741. package/.output/server/node_modules/unhead/dist/scripts.mjs +30 -0
  742. package/.output/server/node_modules/unhead/dist/server.mjs +180 -0
  743. package/.output/server/node_modules/unhead/dist/shared/unhead.0eF0fa-Y.mjs +236 -0
  744. package/.output/server/node_modules/unhead/dist/shared/unhead.B5FWS6X0.mjs +207 -0
  745. package/.output/server/node_modules/unhead/dist/shared/unhead.BYvz9V1x.mjs +43 -0
  746. package/.output/server/node_modules/unhead/dist/shared/unhead.BnoAbrHA.mjs +269 -0
  747. package/.output/server/node_modules/unhead/dist/shared/unhead.CbpEuj3y.mjs +71 -0
  748. package/.output/server/node_modules/unhead/dist/shared/unhead.Chhckluj.mjs +166 -0
  749. package/.output/server/node_modules/unhead/dist/shared/unhead.Ct24BOby.mjs +182 -0
  750. package/.output/server/node_modules/unhead/dist/shared/unhead.DQc16pHI.mjs +196 -0
  751. package/.output/server/node_modules/unhead/dist/shared/unhead._ybhDo-G.mjs +44 -0
  752. package/.output/server/node_modules/unhead/dist/shared/unhead.yem5I2v_.mjs +38 -0
  753. package/.output/server/node_modules/unhead/dist/utils.mjs +5 -0
  754. package/.output/server/node_modules/unhead/package.json +105 -0
  755. package/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
  756. package/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
  757. package/.output/server/node_modules/vue/index.js +7 -0
  758. package/.output/server/node_modules/vue/index.mjs +1 -0
  759. package/.output/server/node_modules/vue/package.json +112 -0
  760. package/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
  761. package/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +301 -0
  762. package/.output/server/node_modules/vue-bundle-renderer/package.json +55 -0
  763. package/.output/server/node_modules/webidl-conversions/lib/index.js +450 -0
  764. package/.output/server/node_modules/webidl-conversions/package.json +35 -0
  765. package/.output/server/node_modules/whatwg-url/index.js +27 -0
  766. package/.output/server/node_modules/whatwg-url/lib/Function.js +42 -0
  767. package/.output/server/node_modules/whatwg-url/lib/URL-impl.js +233 -0
  768. package/.output/server/node_modules/whatwg-url/lib/URL.js +499 -0
  769. package/.output/server/node_modules/whatwg-url/lib/URLSearchParams-impl.js +135 -0
  770. package/.output/server/node_modules/whatwg-url/lib/URLSearchParams.js +505 -0
  771. package/.output/server/node_modules/whatwg-url/lib/encoding.js +16 -0
  772. package/.output/server/node_modules/whatwg-url/lib/infra.js +26 -0
  773. package/.output/server/node_modules/whatwg-url/lib/percent-encoding.js +142 -0
  774. package/.output/server/node_modules/whatwg-url/lib/url-state-machine.js +1274 -0
  775. package/.output/server/node_modules/whatwg-url/lib/urlencoded.js +89 -0
  776. package/.output/server/node_modules/whatwg-url/lib/utils.js +190 -0
  777. package/.output/server/node_modules/whatwg-url/package.json +53 -0
  778. package/.output/server/node_modules/whatwg-url/webidl2js-wrapper.js +7 -0
  779. package/.output/server/node_modules/zod/index.js +4 -0
  780. package/.output/server/node_modules/zod/package.json +135 -0
  781. package/.output/server/node_modules/zod/v4/classic/checks.js +1 -0
  782. package/.output/server/node_modules/zod/v4/classic/coerce.js +17 -0
  783. package/.output/server/node_modules/zod/v4/classic/compat.js +31 -0
  784. package/.output/server/node_modules/zod/v4/classic/errors.js +48 -0
  785. package/.output/server/node_modules/zod/v4/classic/external.js +20 -0
  786. package/.output/server/node_modules/zod/v4/classic/from-json-schema.js +584 -0
  787. package/.output/server/node_modules/zod/v4/classic/index.js +4 -0
  788. package/.output/server/node_modules/zod/v4/classic/iso.js +30 -0
  789. package/.output/server/node_modules/zod/v4/classic/package.json +6 -0
  790. package/.output/server/node_modules/zod/v4/classic/parse.js +15 -0
  791. package/.output/server/node_modules/zod/v4/classic/schemas.js +1157 -0
  792. package/.output/server/node_modules/zod/v4/core/api.js +1082 -0
  793. package/.output/server/node_modules/zod/v4/core/checks.js +575 -0
  794. package/.output/server/node_modules/zod/v4/core/core.js +76 -0
  795. package/.output/server/node_modules/zod/v4/core/doc.js +35 -0
  796. package/.output/server/node_modules/zod/v4/core/errors.js +182 -0
  797. package/.output/server/node_modules/zod/v4/core/index.js +16 -0
  798. package/.output/server/node_modules/zod/v4/core/json-schema-generator.js +95 -0
  799. package/.output/server/node_modules/zod/v4/core/json-schema-processors.js +605 -0
  800. package/.output/server/node_modules/zod/v4/core/json-schema.js +1 -0
  801. package/.output/server/node_modules/zod/v4/core/package.json +6 -0
  802. package/.output/server/node_modules/zod/v4/core/parse.js +93 -0
  803. package/.output/server/node_modules/zod/v4/core/regexes.js +133 -0
  804. package/.output/server/node_modules/zod/v4/core/registries.js +51 -0
  805. package/.output/server/node_modules/zod/v4/core/schemas.js +2093 -0
  806. package/.output/server/node_modules/zod/v4/core/to-json-schema.js +437 -0
  807. package/.output/server/node_modules/zod/v4/core/util.js +651 -0
  808. package/.output/server/node_modules/zod/v4/core/versions.js +5 -0
  809. package/.output/server/node_modules/zod/v4/index.js +3 -0
  810. package/.output/server/node_modules/zod/v4/locales/ar.js +106 -0
  811. package/.output/server/node_modules/zod/v4/locales/az.js +105 -0
  812. package/.output/server/node_modules/zod/v4/locales/be.js +156 -0
  813. package/.output/server/node_modules/zod/v4/locales/bg.js +120 -0
  814. package/.output/server/node_modules/zod/v4/locales/ca.js +107 -0
  815. package/.output/server/node_modules/zod/v4/locales/cs.js +111 -0
  816. package/.output/server/node_modules/zod/v4/locales/da.js +115 -0
  817. package/.output/server/node_modules/zod/v4/locales/de.js +108 -0
  818. package/.output/server/node_modules/zod/v4/locales/en.js +109 -0
  819. package/.output/server/node_modules/zod/v4/locales/eo.js +109 -0
  820. package/.output/server/node_modules/zod/v4/locales/es.js +132 -0
  821. package/.output/server/node_modules/zod/v4/locales/fa.js +114 -0
  822. package/.output/server/node_modules/zod/v4/locales/fi.js +112 -0
  823. package/.output/server/node_modules/zod/v4/locales/fr-CA.js +107 -0
  824. package/.output/server/node_modules/zod/v4/locales/fr.js +108 -0
  825. package/.output/server/node_modules/zod/v4/locales/he.js +214 -0
  826. package/.output/server/node_modules/zod/v4/locales/hu.js +108 -0
  827. package/.output/server/node_modules/zod/v4/locales/hy.js +147 -0
  828. package/.output/server/node_modules/zod/v4/locales/id.js +106 -0
  829. package/.output/server/node_modules/zod/v4/locales/index.js +49 -0
  830. package/.output/server/node_modules/zod/v4/locales/is.js +109 -0
  831. package/.output/server/node_modules/zod/v4/locales/it.js +108 -0
  832. package/.output/server/node_modules/zod/v4/locales/ja.js +107 -0
  833. package/.output/server/node_modules/zod/v4/locales/ka.js +112 -0
  834. package/.output/server/node_modules/zod/v4/locales/kh.js +5 -0
  835. package/.output/server/node_modules/zod/v4/locales/km.js +110 -0
  836. package/.output/server/node_modules/zod/v4/locales/ko.js +111 -0
  837. package/.output/server/node_modules/zod/v4/locales/lt.js +203 -0
  838. package/.output/server/node_modules/zod/v4/locales/mk.js +109 -0
  839. package/.output/server/node_modules/zod/v4/locales/ms.js +107 -0
  840. package/.output/server/node_modules/zod/v4/locales/nl.js +110 -0
  841. package/.output/server/node_modules/zod/v4/locales/no.js +108 -0
  842. package/.output/server/node_modules/zod/v4/locales/ota.js +109 -0
  843. package/.output/server/node_modules/zod/v4/locales/package.json +6 -0
  844. package/.output/server/node_modules/zod/v4/locales/pl.js +109 -0
  845. package/.output/server/node_modules/zod/v4/locales/ps.js +114 -0
  846. package/.output/server/node_modules/zod/v4/locales/pt.js +108 -0
  847. package/.output/server/node_modules/zod/v4/locales/ru.js +156 -0
  848. package/.output/server/node_modules/zod/v4/locales/sl.js +109 -0
  849. package/.output/server/node_modules/zod/v4/locales/sv.js +110 -0
  850. package/.output/server/node_modules/zod/v4/locales/ta.js +110 -0
  851. package/.output/server/node_modules/zod/v4/locales/th.js +110 -0
  852. package/.output/server/node_modules/zod/v4/locales/tr.js +105 -0
  853. package/.output/server/node_modules/zod/v4/locales/ua.js +5 -0
  854. package/.output/server/node_modules/zod/v4/locales/uk.js +108 -0
  855. package/.output/server/node_modules/zod/v4/locales/ur.js +110 -0
  856. package/.output/server/node_modules/zod/v4/locales/uz.js +109 -0
  857. package/.output/server/node_modules/zod/v4/locales/vi.js +108 -0
  858. package/.output/server/node_modules/zod/v4/locales/yo.js +107 -0
  859. package/.output/server/node_modules/zod/v4/locales/zh-CN.js +109 -0
  860. package/.output/server/node_modules/zod/v4/locales/zh-TW.js +107 -0
  861. package/.output/server/node_modules/zod/v4/package.json +6 -0
  862. package/.output/server/package.json +53 -0
  863. package/README.md +131 -0
  864. package/app/app.vue +7 -0
  865. package/app/assets/css/main.css +2 -0
  866. package/app/components/StudioEditor.vue +114 -0
  867. package/app/components/StudioOutput.vue +43 -0
  868. package/app/components/ZodMongooseStudio.vue +121 -0
  869. package/app/pages/index.vue +3 -0
  870. package/app/plugins/monaco.client.ts +14 -0
  871. package/bin/index.mjs +69 -0
  872. package/nuxt.config.ts +18 -0
  873. package/package.json +49 -0
  874. package/server/api/parse.post.ts +90 -0
  875. package/server/api/resolve.get.ts +38 -0
  876. package/server/middleware/security.ts +40 -0
@@ -0,0 +1,3185 @@
1
+ 'use strict';
2
+
3
+ /*!
4
+ * Module dependencies.
5
+ */
6
+
7
+ const EventEmitter = require('events').EventEmitter;
8
+ const Kareem = require('kareem');
9
+ const MongooseError = require('./error/mongooseError');
10
+ const SchemaType = require('./schemaType');
11
+ const SchemaTypeOptions = require('./options/schemaTypeOptions');
12
+ const VirtualOptions = require('./options/virtualOptions');
13
+ const VirtualType = require('./virtualType');
14
+ const addAutoId = require('./helpers/schema/addAutoId');
15
+ const clone = require('./helpers/clone');
16
+ const get = require('./helpers/get');
17
+ const getConstructorName = require('./helpers/getConstructorName');
18
+ const getIndexes = require('./helpers/schema/getIndexes');
19
+ const handleReadPreferenceAliases = require('./helpers/query/handleReadPreferenceAliases');
20
+ const idGetter = require('./helpers/schema/idGetter');
21
+ const isIndexSpecEqual = require('./helpers/indexes/isIndexSpecEqual');
22
+ const merge = require('./helpers/schema/merge');
23
+ const mpath = require('mpath');
24
+ const setPopulatedVirtualValue = require('./helpers/populate/setPopulatedVirtualValue');
25
+ const setupTimestamps = require('./helpers/timestamps/setupTimestamps');
26
+ const utils = require('./utils');
27
+ const validateRef = require('./helpers/populate/validateRef');
28
+
29
+ const hasNumericSubpathRegex = /\.\d+(\.|$)/;
30
+
31
+ let MongooseTypes;
32
+
33
+ const queryHooks = require('./constants').queryMiddlewareFunctions;
34
+ const documentHooks = require('./helpers/model/applyHooks').middlewareFunctions;
35
+ const hookNames = queryHooks.concat(documentHooks).
36
+ reduce((s, hook) => s.add(hook), new Set());
37
+
38
+ const isPOJO = utils.isPOJO;
39
+
40
+ let id = 0;
41
+
42
+ const numberRE = /^\d+$/;
43
+
44
+ /**
45
+ * Schema constructor.
46
+ *
47
+ * #### Example:
48
+ *
49
+ * const child = new Schema({ name: String });
50
+ * const schema = new Schema({ name: String, age: Number, children: [child] });
51
+ * const Tree = mongoose.model('Tree', schema);
52
+ *
53
+ * // setting schema options
54
+ * new Schema({ name: String }, { id: false, autoIndex: false })
55
+ *
56
+ * #### Options:
57
+ *
58
+ * - [autoIndex](https://mongoosejs.com/docs/guide.html#autoIndex): bool - defaults to null (which means use the connection's autoIndex option)
59
+ * - [autoCreate](https://mongoosejs.com/docs/guide.html#autoCreate): bool - defaults to null (which means use the connection's autoCreate option)
60
+ * - [bufferCommands](https://mongoosejs.com/docs/guide.html#bufferCommands): bool - defaults to true
61
+ * - [bufferTimeoutMS](https://mongoosejs.com/docs/guide.html#bufferTimeoutMS): number - defaults to 10000 (10 seconds). If `bufferCommands` is enabled, the amount of time Mongoose will wait for connectivity to be restablished before erroring out.
62
+ * - [capped](https://mongoosejs.com/docs/guide.html#capped): bool | number | object - defaults to false
63
+ * - [collection](https://mongoosejs.com/docs/guide.html#collection): string - no default
64
+ * - [discriminatorKey](https://mongoosejs.com/docs/guide.html#discriminatorKey): string - defaults to `__t`
65
+ * - [id](https://mongoosejs.com/docs/guide.html#id): bool - defaults to true
66
+ * - [_id](https://mongoosejs.com/docs/guide.html#_id): bool - defaults to true
67
+ * - [minimize](https://mongoosejs.com/docs/guide.html#minimize): bool - controls [document#toObject](https://mongoosejs.com/docs/api/document.html#Document.prototype.toObject()) behavior when called manually - defaults to true
68
+ * - [read](https://mongoosejs.com/docs/guide.html#read): string
69
+ * - [readConcern](https://mongoosejs.com/docs/guide.html#readConcern): object - defaults to null, use to set a default [read concern](https://www.mongodb.com/docs/manual/reference/read-concern/) for all queries.
70
+ * - [writeConcern](https://mongoosejs.com/docs/guide.html#writeConcern): object - defaults to null, use to override [the MongoDB server's default write concern settings](https://www.mongodb.com/docs/manual/reference/write-concern/)
71
+ * - [shardKey](https://mongoosejs.com/docs/guide.html#shardKey): object - defaults to `null`
72
+ * - [strict](https://mongoosejs.com/docs/guide.html#strict): bool - defaults to true
73
+ * - [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery): bool - defaults to false
74
+ * - [toJSON](https://mongoosejs.com/docs/guide.html#toJSON) - object - no default
75
+ * - [toObject](https://mongoosejs.com/docs/guide.html#toObject) - object - no default
76
+ * - [typeKey](https://mongoosejs.com/docs/guide.html#typeKey) - string - defaults to 'type'
77
+ * - [validateBeforeSave](https://mongoosejs.com/docs/guide.html#validateBeforeSave) - bool - defaults to `true`
78
+ * - [validateModifiedOnly](https://mongoosejs.com/docs/api/document.html#Document.prototype.validate()) - bool - defaults to `false`
79
+ * - [versionKey](https://mongoosejs.com/docs/guide.html#versionKey): string or object - defaults to "__v"
80
+ * - [optimisticConcurrency](https://mongoosejs.com/docs/guide.html#optimisticConcurrency): bool or string[] or { exclude: string[] } - defaults to false. Set to true to enable [optimistic concurrency](https://thecodebarbarian.com/whats-new-in-mongoose-5-10-optimistic-concurrency.html). Set to string array to enable optimistic concurrency for only certain fields, or `{ exclude: string[] }` to define a list of fields to ignore for optimistic concurrency.
81
+ * - [collation](https://mongoosejs.com/docs/guide.html#collation): object - defaults to null (which means use no collation)
82
+ * - [timeseries](https://mongoosejs.com/docs/guide.html#timeseries): object - defaults to null (which means this schema's collection won't be a timeseries collection)
83
+ * - [selectPopulatedPaths](https://mongoosejs.com/docs/guide.html#selectPopulatedPaths): boolean - defaults to `true`
84
+ * - [skipVersioning](https://mongoosejs.com/docs/guide.html#skipVersioning): object - paths to exclude from versioning
85
+ * - [timestamps](https://mongoosejs.com/docs/guide.html#timestamps): object or boolean - defaults to `false`. If true, Mongoose adds `createdAt` and `updatedAt` properties to your schema and manages those properties for you.
86
+ * - [pluginTags](https://mongoosejs.com/docs/guide.html#pluginTags): array of strings - defaults to `undefined`. If set and plugin called with `tags` option, will only apply that plugin to schemas with a matching tag.
87
+ * - [virtuals](https://mongoosejs.com/docs/tutorials/virtuals.html#virtuals-via-schema-options): object - virtuals to define, alias for [`.virtual`](https://mongoosejs.com/docs/api/schema.html#Schema.prototype.virtual())
88
+ * - [collectionOptions]: object with options passed to [`createCollection()`](https://www.mongodb.com/docs/manual/reference/method/db.createCollection/) when calling `Model.createCollection()` or `autoCreate` set to true.
89
+ * - [encryptionType]: the encryption type for the schema. Valid options are `csfle` or `queryableEncryption`. See https://mongoosejs.com/docs/field-level-encryption.
90
+ *
91
+ * #### Options for Nested Schemas:
92
+ *
93
+ * - `excludeIndexes`: bool - defaults to `false`. If `true`, skip building indexes on this schema's paths.
94
+ *
95
+ * #### Note:
96
+ *
97
+ * _When nesting schemas, (`children` in the example above), always declare the child schema first before passing it into its parent._
98
+ *
99
+ * @param {Object|Schema|Array} [definition] Can be one of: object describing schema paths, or schema to copy, or array of objects and schemas
100
+ * @param {Object} [options]
101
+ * @inherits NodeJS EventEmitter https://nodejs.org/api/events.html#class-eventemitter
102
+ * @event `init`: Emitted after the schema is compiled into a `Model`.
103
+ * @api public
104
+ */
105
+
106
+ function Schema(obj, options) {
107
+ if (!(this instanceof Schema)) {
108
+ return new Schema(obj, options);
109
+ }
110
+
111
+ this.obj = obj;
112
+ this.paths = {};
113
+ this.aliases = {};
114
+ this.subpaths = {};
115
+ this.virtuals = {};
116
+ this.singleNestedPaths = {};
117
+ this.nested = {};
118
+ this.inherits = {};
119
+ this.callQueue = [];
120
+ this._indexes = [];
121
+ this._searchIndexes = [];
122
+ this.methods = (options && options.methods) || {};
123
+ this.methodOptions = {};
124
+ this.statics = (options && options.statics) || {};
125
+ this.tree = {};
126
+ this.query = (options && options.query) || {};
127
+ this.childSchemas = [];
128
+ this.plugins = [];
129
+ // For internal debugging. Do not use this to try to save a schema in MDB.
130
+ this.$id = ++id;
131
+ this.mapPaths = [];
132
+ this.encryptedFields = {};
133
+
134
+ this.s = {
135
+ hooks: new Kareem()
136
+ };
137
+ this.options = this.defaultOptions(options);
138
+
139
+ // build paths
140
+ if (Array.isArray(obj)) {
141
+ for (const definition of obj) {
142
+ this.add(definition);
143
+ }
144
+ } else if (obj) {
145
+ this.add(obj);
146
+ }
147
+
148
+ // build virtual paths
149
+ if (options && options.virtuals) {
150
+ const virtuals = options.virtuals;
151
+ const pathNames = Object.keys(virtuals);
152
+ for (const pathName of pathNames) {
153
+ const pathOptions = virtuals[pathName].options ? virtuals[pathName].options : undefined;
154
+ const virtual = this.virtual(pathName, pathOptions);
155
+
156
+ if (virtuals[pathName].get) {
157
+ virtual.get(virtuals[pathName].get);
158
+ }
159
+
160
+ if (virtuals[pathName].set) {
161
+ virtual.set(virtuals[pathName].set);
162
+ }
163
+ }
164
+ }
165
+
166
+ // check if _id's value is a subdocument (gh-2276)
167
+ const _idSubDoc = obj && obj._id && utils.isObject(obj._id);
168
+
169
+ // ensure the documents get an auto _id unless disabled
170
+ const auto_id = !this.paths['_id'] &&
171
+ (this.options._id) && !_idSubDoc;
172
+
173
+ if (auto_id) {
174
+ addAutoId(this);
175
+ }
176
+
177
+ this.setupTimestamp(this.options.timestamps);
178
+ }
179
+
180
+ /**
181
+ * Create virtual properties with alias field
182
+ * @api private
183
+ */
184
+ function aliasFields(schema, paths) {
185
+ for (const path of Object.keys(paths)) {
186
+ let alias = null;
187
+ if (paths[path] != null) {
188
+ alias = paths[path];
189
+ } else {
190
+ const options = get(schema.paths[path], 'options');
191
+ if (options == null) {
192
+ continue;
193
+ }
194
+
195
+ alias = options.alias;
196
+ }
197
+
198
+ if (!alias) {
199
+ continue;
200
+ }
201
+
202
+ const prop = schema.paths[path].path;
203
+ if (Array.isArray(alias)) {
204
+ for (const a of alias) {
205
+ if (typeof a !== 'string') {
206
+ throw new Error('Invalid value for alias option on ' + prop + ', got ' + a);
207
+ }
208
+
209
+ schema.aliases[a] = prop;
210
+
211
+ schema.
212
+ virtual(a).
213
+ get((function(p) {
214
+ return function() {
215
+ if (typeof this.get === 'function') {
216
+ return this.get(p);
217
+ }
218
+ return this[p];
219
+ };
220
+ })(prop)).
221
+ set((function(p) {
222
+ return function(v) {
223
+ return this.$set(p, v);
224
+ };
225
+ })(prop));
226
+ }
227
+
228
+ continue;
229
+ }
230
+
231
+ if (typeof alias !== 'string') {
232
+ throw new Error('Invalid value for alias option on ' + prop + ', got ' + alias);
233
+ }
234
+
235
+ schema.aliases[alias] = prop;
236
+
237
+ schema.
238
+ virtual(alias).
239
+ get((function(p) {
240
+ return function() {
241
+ if (typeof this.get === 'function') {
242
+ return this.get(p);
243
+ }
244
+ return this[p];
245
+ };
246
+ })(prop)).
247
+ set((function(p) {
248
+ return function(v) {
249
+ return this.$set(p, v);
250
+ };
251
+ })(prop));
252
+ }
253
+ }
254
+
255
+ /*!
256
+ * Inherit from EventEmitter.
257
+ */
258
+ Schema.prototype = Object.create(EventEmitter.prototype);
259
+ Schema.prototype.constructor = Schema;
260
+ Schema.prototype.instanceOfSchema = true;
261
+
262
+ /*!
263
+ * ignore
264
+ */
265
+
266
+ Object.defineProperty(Schema.prototype, '$schemaType', {
267
+ configurable: false,
268
+ enumerable: false,
269
+ writable: true
270
+ });
271
+
272
+ /**
273
+ * Array of child schemas (from document arrays and single nested subdocs)
274
+ * and their corresponding compiled models. Each element of the array is
275
+ * an object with 2 properties: `schema` and `model`.
276
+ *
277
+ * This property is typically only useful for plugin authors and advanced users.
278
+ * You do not need to interact with this property at all to use mongoose.
279
+ *
280
+ * @api public
281
+ * @property childSchemas
282
+ * @memberOf Schema
283
+ * @instance
284
+ */
285
+
286
+ Object.defineProperty(Schema.prototype, 'childSchemas', {
287
+ configurable: false,
288
+ enumerable: true,
289
+ writable: true
290
+ });
291
+
292
+ /**
293
+ * Object containing all virtuals defined on this schema.
294
+ * The objects' keys are the virtual paths and values are instances of `VirtualType`.
295
+ *
296
+ * This property is typically only useful for plugin authors and advanced users.
297
+ * You do not need to interact with this property at all to use mongoose.
298
+ *
299
+ * #### Example:
300
+ *
301
+ * const schema = new Schema({});
302
+ * schema.virtual('answer').get(() => 42);
303
+ *
304
+ * console.log(schema.virtuals); // { answer: VirtualType { path: 'answer', ... } }
305
+ * console.log(schema.virtuals['answer'].getters[0].call()); // 42
306
+ *
307
+ * @api public
308
+ * @property virtuals
309
+ * @memberOf Schema
310
+ * @instance
311
+ */
312
+
313
+ Object.defineProperty(Schema.prototype, 'virtuals', {
314
+ configurable: false,
315
+ enumerable: true,
316
+ writable: true
317
+ });
318
+
319
+ /**
320
+ * The original object passed to the schema constructor
321
+ *
322
+ * #### Example:
323
+ *
324
+ * const schema = new Schema({ a: String }).add({ b: String });
325
+ * schema.obj; // { a: String }
326
+ *
327
+ * @api public
328
+ * @property obj
329
+ * @memberOf Schema
330
+ * @instance
331
+ */
332
+
333
+ Schema.prototype.obj;
334
+
335
+ /**
336
+ * The paths defined on this schema. The keys are the top-level paths
337
+ * in this schema, and the values are instances of the SchemaType class.
338
+ *
339
+ * #### Example:
340
+ *
341
+ * const schema = new Schema({ name: String }, { _id: false });
342
+ * schema.paths; // { name: SchemaString { ... } }
343
+ *
344
+ * schema.add({ age: Number });
345
+ * schema.paths; // { name: SchemaString { ... }, age: SchemaNumber { ... } }
346
+ *
347
+ * @api public
348
+ * @property paths
349
+ * @memberOf Schema
350
+ * @instance
351
+ */
352
+
353
+ Schema.prototype.paths;
354
+
355
+ /**
356
+ * Schema as a tree
357
+ *
358
+ * #### Example:
359
+ *
360
+ * {
361
+ * '_id' : ObjectId
362
+ * , 'nested' : {
363
+ * 'key' : String
364
+ * }
365
+ * }
366
+ *
367
+ * @api private
368
+ * @property tree
369
+ * @memberOf Schema
370
+ * @instance
371
+ */
372
+
373
+ Schema.prototype.tree;
374
+
375
+ /**
376
+ * Returns a deep copy of the schema
377
+ *
378
+ * #### Example:
379
+ *
380
+ * const schema = new Schema({ name: String });
381
+ * const clone = schema.clone();
382
+ * clone === schema; // false
383
+ * clone.path('name'); // SchemaString { ... }
384
+ *
385
+ * @return {Schema} the cloned schema
386
+ * @api public
387
+ * @memberOf Schema
388
+ * @instance
389
+ */
390
+
391
+ Schema.prototype.clone = function() {
392
+ const s = this._clone();
393
+
394
+ // Bubble up `init` for backwards compat
395
+ s.on('init', v => this.emit('init', v));
396
+
397
+ return s;
398
+ };
399
+
400
+ /*!
401
+ * ignore
402
+ */
403
+
404
+ Schema.prototype._clone = function _clone(Constructor) {
405
+ Constructor = Constructor || (this.base == null ? Schema : this.base.Schema);
406
+
407
+ const s = new Constructor({}, this._userProvidedOptions);
408
+ s.base = this.base;
409
+ s.obj = this.obj;
410
+ s.options = clone(this.options);
411
+ s.callQueue = this.callQueue.map(function(f) { return f; });
412
+ s.methods = clone(this.methods);
413
+ s.methodOptions = clone(this.methodOptions);
414
+ s.statics = clone(this.statics);
415
+ s.query = clone(this.query);
416
+ s.plugins = Array.prototype.slice.call(this.plugins);
417
+ s._indexes = clone(this._indexes);
418
+ s._searchIndexes = clone(this._searchIndexes);
419
+ s.s.hooks = this.s.hooks.clone();
420
+
421
+ s.tree = clone(this.tree);
422
+ s.paths = Object.fromEntries(
423
+ Object.entries(this.paths).map(([key, value]) => ([key, value.clone()]))
424
+ );
425
+ s.nested = clone(this.nested);
426
+ s.subpaths = clone(this.subpaths);
427
+ for (const schemaType of Object.values(s.paths)) {
428
+ if (schemaType.$isSingleNested) {
429
+ const path = schemaType.path;
430
+ for (const key of Object.keys(schemaType.schema.paths)) {
431
+ s.singleNestedPaths[path + '.' + key] = schemaType.schema.paths[key];
432
+ }
433
+ for (const key of Object.keys(schemaType.schema.singleNestedPaths)) {
434
+ s.singleNestedPaths[path + '.' + key] =
435
+ schemaType.schema.singleNestedPaths[key];
436
+ }
437
+ for (const key of Object.keys(schemaType.schema.subpaths)) {
438
+ s.singleNestedPaths[path + '.' + key] =
439
+ schemaType.schema.subpaths[key];
440
+ }
441
+ for (const key of Object.keys(schemaType.schema.nested)) {
442
+ s.singleNestedPaths[path + '.' + key] = 'nested';
443
+ }
444
+ }
445
+ }
446
+ s._gatherChildSchemas();
447
+
448
+ s.virtuals = clone(this.virtuals);
449
+ s.$globalPluginsApplied = this.$globalPluginsApplied;
450
+ s.$isRootDiscriminator = this.$isRootDiscriminator;
451
+ s.$implicitlyCreated = this.$implicitlyCreated;
452
+ s.$id = ++id;
453
+ s.$originalSchemaId = this.$id;
454
+ s.mapPaths = [].concat(this.mapPaths);
455
+
456
+ if (this.discriminatorMapping != null) {
457
+ s.discriminatorMapping = Object.assign({}, this.discriminatorMapping);
458
+ }
459
+ if (this.discriminators != null) {
460
+ s.discriminators = Object.assign({}, this.discriminators);
461
+ }
462
+ if (this._applyDiscriminators != null) {
463
+ s._applyDiscriminators = new Map(this._applyDiscriminators);
464
+ }
465
+
466
+ s.aliases = Object.assign({}, this.aliases);
467
+
468
+ s.encryptedFields = clone(this.encryptedFields);
469
+
470
+ return s;
471
+ };
472
+
473
+ /**
474
+ * Returns a new schema that has the picked `paths` from this schema.
475
+ *
476
+ * This method is analagous to [Lodash's `pick()` function](https://lodash.com/docs/4.17.15#pick) for Mongoose schemas.
477
+ *
478
+ * #### Example:
479
+ *
480
+ * const schema = Schema({ name: String, age: Number });
481
+ * // Creates a new schema with the same `name` path as `schema`,
482
+ * // but no `age` path.
483
+ * const newSchema = schema.pick(['name']);
484
+ *
485
+ * newSchema.path('name'); // SchemaString { ... }
486
+ * newSchema.path('age'); // undefined
487
+ *
488
+ * @param {String[]} paths List of Paths to pick for the new Schema
489
+ * @param {Object} [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`). Defaults to `this.options` if not set.
490
+ * @return {Schema}
491
+ * @api public
492
+ */
493
+
494
+ Schema.prototype.pick = function(paths, options) {
495
+ const newSchema = new Schema({}, options || this.options);
496
+ if (!Array.isArray(paths)) {
497
+ throw new MongooseError('Schema#pick() only accepts an array argument, ' +
498
+ 'got "' + typeof paths + '"');
499
+ }
500
+
501
+ for (const path of paths) {
502
+ if (this._hasEncryptedField(path)) {
503
+ const encrypt = this.encryptedFields[path];
504
+ const schemaType = this.path(path);
505
+ newSchema.add({
506
+ [path]: {
507
+ encrypt,
508
+ [this.options.typeKey]: schemaType
509
+ }
510
+ });
511
+ } else if (this.nested[path]) {
512
+ newSchema.add({ [path]: get(this.tree, path) });
513
+ } else {
514
+ const schematype = this.path(path);
515
+ if (schematype == null) {
516
+ throw new MongooseError('Path `' + path + '` is not in the schema');
517
+ }
518
+ newSchema.add({ [path]: schematype });
519
+ }
520
+ }
521
+
522
+ if (!this._hasEncryptedFields()) {
523
+ newSchema.options.encryptionType = null;
524
+ }
525
+
526
+ return newSchema;
527
+ };
528
+
529
+ /**
530
+ * Returns a new schema that has the `paths` from the original schema, minus the omitted ones.
531
+ *
532
+ * This method is analagous to [Lodash's `omit()` function](https://lodash.com/docs/#omit) for Mongoose schemas.
533
+ *
534
+ * #### Example:
535
+ *
536
+ * const schema = Schema({ name: String, age: Number });
537
+ * // Creates a new schema omitting the `age` path
538
+ * const newSchema = schema.omit(['age']);
539
+ *
540
+ * newSchema.path('name'); // SchemaString { ... }
541
+ * newSchema.path('age'); // undefined
542
+ *
543
+ * @param {String[]} paths List of Paths to omit for the new Schema
544
+ * @param {Object} [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`). Defaults to `this.options` if not set.
545
+ * @return {Schema}
546
+ * @api public
547
+ */
548
+
549
+ Schema.prototype.omit = function(paths, options) {
550
+ const newSchema = new Schema(this, options || this.options);
551
+ if (!Array.isArray(paths)) {
552
+ throw new MongooseError(
553
+ 'Schema#omit() only accepts an array argument, ' +
554
+ 'got "' +
555
+ typeof paths +
556
+ '"'
557
+ );
558
+ }
559
+
560
+ newSchema.remove(paths);
561
+
562
+ for (const nested in newSchema.singleNestedPaths) {
563
+ if (paths.includes(nested)) {
564
+ delete newSchema.singleNestedPaths[nested];
565
+ }
566
+ }
567
+
568
+ return newSchema;
569
+ };
570
+
571
+ /**
572
+ * Returns default options for this schema, merged with `options`.
573
+ *
574
+ * @param {Object} [options] Options to overwrite the default options
575
+ * @return {Object} The merged options of `options` and the default options
576
+ * @api private
577
+ */
578
+
579
+ Schema.prototype.defaultOptions = function(options) {
580
+ this._userProvidedOptions = options == null ? {} : clone(options);
581
+ const baseOptions = this.base && this.base.options || {};
582
+ const strict = 'strict' in baseOptions ? baseOptions.strict : true;
583
+ const strictQuery = 'strictQuery' in baseOptions ? baseOptions.strictQuery : false;
584
+ const id = 'id' in baseOptions ? baseOptions.id : true;
585
+ options = {
586
+ strict,
587
+ strictQuery,
588
+ bufferCommands: true,
589
+ capped: false, // { size, max, autoIndexId }
590
+ versionKey: '__v',
591
+ optimisticConcurrency: false,
592
+ minimize: true,
593
+ autoIndex: null,
594
+ discriminatorKey: '__t',
595
+ shardKey: null,
596
+ read: null,
597
+ validateBeforeSave: true,
598
+ validateModifiedOnly: false,
599
+ // the following are only applied at construction time
600
+ _id: true,
601
+ id: id,
602
+ typeKey: 'type',
603
+ ...options
604
+ };
605
+
606
+ if (options.versionKey && typeof options.versionKey !== 'string') {
607
+ throw new MongooseError('`versionKey` must be falsy or string, got `' + (typeof options.versionKey) + '`');
608
+ }
609
+
610
+ if (typeof options.read === 'string') {
611
+ options.read = handleReadPreferenceAliases(options.read);
612
+ } else if (Array.isArray(options.read) && typeof options.read[0] === 'string') {
613
+ options.read = {
614
+ mode: handleReadPreferenceAliases(options.read[0]),
615
+ tags: options.read[1]
616
+ };
617
+ }
618
+
619
+ if (options.optimisticConcurrency && !options.versionKey) {
620
+ throw new MongooseError('Must set `versionKey` if using `optimisticConcurrency`');
621
+ }
622
+
623
+ return options;
624
+ };
625
+
626
+ /**
627
+ * Inherit a Schema by applying a discriminator on an existing Schema.
628
+ *
629
+ *
630
+ * #### Example:
631
+ *
632
+ * const eventSchema = new mongoose.Schema({ timestamp: Date }, { discriminatorKey: 'kind' });
633
+ *
634
+ * const clickedEventSchema = new mongoose.Schema({ element: String }, { discriminatorKey: 'kind' });
635
+ * const ClickedModel = eventSchema.discriminator('clicked', clickedEventSchema);
636
+ *
637
+ * const Event = mongoose.model('Event', eventSchema);
638
+ *
639
+ * Event.discriminators['clicked']; // Model { clicked }
640
+ *
641
+ * const doc = await Event.create({ kind: 'clicked', element: '#hero' });
642
+ * doc.element; // '#hero'
643
+ * doc instanceof ClickedModel; // true
644
+ *
645
+ * @param {String} name the name of the discriminator
646
+ * @param {Schema} schema the discriminated Schema
647
+ * @param {Object} [options] discriminator options
648
+ * @param {String} [options.value] the string stored in the `discriminatorKey` property. If not specified, Mongoose uses the `name` parameter.
649
+ * @param {Boolean} [options.clone=true] By default, `discriminator()` clones the given `schema`. Set to `false` to skip cloning.
650
+ * @param {Boolean} [options.overwriteModels=false] by default, Mongoose does not allow you to define a discriminator with the same name as another discriminator. Set this to allow overwriting discriminators with the same name.
651
+ * @param {Boolean} [options.mergeHooks=true] By default, Mongoose merges the base schema's hooks with the discriminator schema's hooks. Set this option to `false` to make Mongoose use the discriminator schema's hooks instead.
652
+ * @param {Boolean} [options.mergePlugins=true] By default, Mongoose merges the base schema's plugins with the discriminator schema's plugins. Set this option to `false` to make Mongoose use the discriminator schema's plugins instead.
653
+ * @return {Schema} the Schema instance
654
+ * @api public
655
+ */
656
+ Schema.prototype.discriminator = function(name, schema, options) {
657
+ this._applyDiscriminators = this._applyDiscriminators || new Map();
658
+ this._applyDiscriminators.set(name, { schema, options });
659
+
660
+ return this;
661
+ };
662
+
663
+ /*!
664
+ * Get this schema's default toObject/toJSON options, including Mongoose global
665
+ * options.
666
+ */
667
+
668
+ Schema.prototype._defaultToObjectOptions = function(json) {
669
+ const path = json ? 'toJSON' : 'toObject';
670
+ if (this._defaultToObjectOptionsMap && this._defaultToObjectOptionsMap[path]) {
671
+ return this._defaultToObjectOptionsMap[path];
672
+ }
673
+
674
+ const baseOptions = this.base &&
675
+ this.base.options &&
676
+ this.base.options[path] || {};
677
+ const schemaOptions = this.options[path] || {};
678
+ // merge base default options with Schema's set default options if available.
679
+ // `clone` is necessary here because `utils.options` directly modifies the second input.
680
+ const defaultOptions = Object.assign({}, baseOptions, schemaOptions);
681
+
682
+ this._defaultToObjectOptionsMap = this._defaultToObjectOptionsMap || {};
683
+ this._defaultToObjectOptionsMap[path] = defaultOptions;
684
+ return defaultOptions;
685
+ };
686
+
687
+ /**
688
+ * Sets the encryption type of the schema, if a value is provided, otherwise
689
+ * returns the encryption type.
690
+ *
691
+ * @param {'csfle' | 'queryableEncryption' | null | undefined} encryptionType plain object with paths to add, or another schema
692
+ */
693
+ Schema.prototype.encryptionType = function encryptionType(encryptionType) {
694
+ if (arguments.length === 0) {
695
+ return this.options.encryptionType;
696
+ }
697
+ if (!(typeof encryptionType === 'string' || encryptionType === null)) {
698
+ throw new Error('invalid `encryptionType`: ${encryptionType}');
699
+ }
700
+ this.options.encryptionType = encryptionType;
701
+ };
702
+
703
+ /**
704
+ * Adds key path / schema type pairs to this schema.
705
+ *
706
+ * #### Example:
707
+ *
708
+ * const ToySchema = new Schema();
709
+ * ToySchema.add({ name: 'string', color: 'string', price: 'number' });
710
+ *
711
+ * const TurboManSchema = new Schema();
712
+ * // You can also `add()` another schema and copy over all paths, virtuals,
713
+ * // getters, setters, indexes, methods, and statics.
714
+ * TurboManSchema.add(ToySchema).add({ year: Number });
715
+ *
716
+ * @param {Object|Schema} obj plain object with paths to add, or another schema
717
+ * @param {String} [prefix] path to prefix the newly added paths with
718
+ * @return {Schema} the Schema instance
719
+ * @api public
720
+ */
721
+
722
+ Schema.prototype.add = function add(obj, prefix) {
723
+ if (obj instanceof Schema || (obj != null && obj.instanceOfSchema)) {
724
+ merge(this, obj);
725
+ return this;
726
+ }
727
+
728
+ // Special case: setting top-level `_id` to false should convert to disabling
729
+ // the `_id` option. This behavior never worked before 5.4.11 but numerous
730
+ // codebases use it (see gh-7516, gh-7512).
731
+ if (obj._id === false && prefix == null) {
732
+ this.options._id = false;
733
+ }
734
+
735
+ prefix = prefix || '';
736
+ // avoid prototype pollution
737
+ if (prefix === '__proto__.' || prefix === 'constructor.' || prefix === 'prototype.') {
738
+ return this;
739
+ }
740
+
741
+ const keys = Object.keys(obj);
742
+ const typeKey = this.options.typeKey;
743
+ for (const key of keys) {
744
+ if (utils.specialProperties.has(key)) {
745
+ continue;
746
+ }
747
+
748
+ const fullPath = prefix + key;
749
+ const val = obj[key];
750
+
751
+ if (val == null) {
752
+ throw new TypeError('Invalid value for schema path `' + fullPath +
753
+ '`, got value "' + val + '"');
754
+ }
755
+ // Retain `_id: false` but don't set it as a path, re: gh-8274.
756
+ if (key === '_id' && val === false) {
757
+ continue;
758
+ }
759
+ // Deprecate setting schema paths to primitive types (gh-7558)
760
+ let isMongooseTypeString = false;
761
+ if (typeof val === 'string') {
762
+ // Handle the case in which the type is specified as a string (eg. 'date', 'oid', ...)
763
+ const MongooseTypes = this.base != null ? this.base.Schema.Types : Schema.Types;
764
+ const upperVal = val.charAt(0).toUpperCase() + val.substring(1);
765
+ isMongooseTypeString = MongooseTypes[upperVal] != null;
766
+ }
767
+ if (
768
+ key !== '_id' &&
769
+ ((typeof val !== 'object' && typeof val !== 'function' && !isMongooseTypeString) ||
770
+ val == null)
771
+ ) {
772
+ throw new TypeError(`Invalid schema configuration: \`${val}\` is not ` +
773
+ `a valid type at path \`${key}\`. See ` +
774
+ 'https://bit.ly/mongoose-schematypes for a list of valid schema types.');
775
+ }
776
+ if (val instanceof VirtualType || (val.constructor && val.constructor.name || null) === 'VirtualType') {
777
+ this.virtual(val);
778
+ continue;
779
+ }
780
+
781
+ if (Array.isArray(val) && val.length === 1 && val[0] == null) {
782
+ throw new TypeError('Invalid value for schema Array path `' + fullPath +
783
+ '`, got value "' + val[0] + '"');
784
+ }
785
+
786
+ if (!(isPOJO(val) || val instanceof SchemaTypeOptions)) {
787
+ // Special-case: Non-options definitely a path so leaf at this node
788
+ // Examples: Schema instances, SchemaType instances
789
+ if (prefix) {
790
+ this.nested[prefix.substring(0, prefix.length - 1)] = true;
791
+ }
792
+ this.path(prefix + key, val);
793
+ if (val[0] != null && !(val[0].instanceOfSchema) && utils.isPOJO(val[0].discriminators)) {
794
+ const schemaType = this.path(prefix + key);
795
+ for (const key in val[0].discriminators) {
796
+ schemaType.discriminator(key, val[0].discriminators[key]);
797
+ }
798
+ }
799
+ } else if (Object.keys(val).length < 1) {
800
+ // Special-case: {} always interpreted as Mixed path so leaf at this node
801
+ if (prefix) {
802
+ this.nested[prefix.substring(0, prefix.length - 1)] = true;
803
+ }
804
+ this.path(fullPath, val); // mixed type
805
+ } else if (!val[typeKey] || (typeKey === 'type' && isPOJO(val.type) && val.type.type)) {
806
+ // Special-case: POJO with no bona-fide type key - interpret as tree of deep paths so recurse
807
+ // nested object `{ last: { name: String } }`. Avoid functions with `.type` re: #10807 because
808
+ // NestJS sometimes adds `Date.type`.
809
+ this.nested[fullPath] = true;
810
+ this.add(val, fullPath + '.');
811
+ } else {
812
+ // There IS a bona-fide type key that may also be a POJO
813
+ const _typeDef = val[typeKey];
814
+ if (isPOJO(_typeDef) && Object.keys(_typeDef).length > 0) {
815
+ // If a POJO is the value of a type key, make it a subdocument
816
+ if (prefix) {
817
+ this.nested[prefix.substring(0, prefix.length - 1)] = true;
818
+ }
819
+
820
+ const childSchemaOptions = {};
821
+ if (this._userProvidedOptions.typeKey) {
822
+ childSchemaOptions.typeKey = this._userProvidedOptions.typeKey;
823
+ }
824
+ // propagate 'strict' option to child schema
825
+ if (this._userProvidedOptions.strict != null) {
826
+ childSchemaOptions.strict = this._userProvidedOptions.strict;
827
+ }
828
+ if (this._userProvidedOptions.toObject != null) {
829
+ childSchemaOptions.toObject = utils.omit(this._userProvidedOptions.toObject, ['transform']);
830
+ }
831
+ if (this._userProvidedOptions.toJSON != null) {
832
+ childSchemaOptions.toJSON = utils.omit(this._userProvidedOptions.toJSON, ['transform']);
833
+ }
834
+
835
+ const _schema = new Schema(_typeDef, childSchemaOptions);
836
+ _schema.$implicitlyCreated = true;
837
+ const schemaWrappedPath = Object.assign({}, val, { [typeKey]: _schema });
838
+ this.path(prefix + key, schemaWrappedPath);
839
+ } else {
840
+ // Either the type is non-POJO or we interpret it as Mixed anyway
841
+ if (prefix) {
842
+ this.nested[prefix.substring(0, prefix.length - 1)] = true;
843
+ }
844
+ this.path(prefix + key, val);
845
+ if (val != null && !(val.instanceOfSchema) && utils.isPOJO(val.discriminators)) {
846
+ const schemaType = this.path(prefix + key);
847
+ for (const key in val.discriminators) {
848
+ schemaType.discriminator(key, val.discriminators[key]);
849
+ }
850
+ }
851
+ }
852
+ }
853
+
854
+ if (val.instanceOfSchema && val.encryptionType() != null) {
855
+ // schema.add({ field: <instance of encrypted schema> })
856
+ if (this.encryptionType() != val.encryptionType()) {
857
+ throw new Error('encryptionType of a nested schema must match the encryption type of the parent schema.');
858
+ }
859
+
860
+ for (const [encryptedField, encryptedFieldConfig] of Object.entries(val.encryptedFields)) {
861
+ const path = fullPath + '.' + encryptedField;
862
+ this._addEncryptedField(path, encryptedFieldConfig);
863
+ }
864
+ } else if (typeof val === 'object' && 'encrypt' in val) {
865
+ // schema.add({ field: { type: <schema type>, encrypt: { ... }}})
866
+ const { encrypt } = val;
867
+
868
+ if (this.encryptionType() == null) {
869
+ throw new Error('encryptionType must be provided');
870
+ }
871
+
872
+ this._addEncryptedField(fullPath, encrypt);
873
+ } else {
874
+ // if the field was already encrypted and we re-configure it to be unencrypted, remove
875
+ // the encrypted field configuration
876
+ this._removeEncryptedField(fullPath);
877
+ }
878
+ }
879
+
880
+ const aliasObj = Object.fromEntries(
881
+ Object.entries(obj).map(([key]) => ([prefix + key, null]))
882
+ );
883
+ aliasFields(this, aliasObj);
884
+ return this;
885
+ };
886
+
887
+ /**
888
+ * @param {string} path
889
+ * @param {object} fieldConfig
890
+ *
891
+ * @api private
892
+ */
893
+ Schema.prototype._addEncryptedField = function _addEncryptedField(path, fieldConfig) {
894
+ const type = this.path(path).autoEncryptionType();
895
+ if (type == null) {
896
+ throw new Error(`Invalid BSON type for FLE field: '${path}'`);
897
+ }
898
+
899
+ this.encryptedFields[path] = clone(fieldConfig);
900
+ };
901
+
902
+ /**
903
+ * @param {string} path
904
+ *
905
+ * @api private
906
+ */
907
+ Schema.prototype._removeEncryptedField = function _removeEncryptedField(path) {
908
+ delete this.encryptedFields[path];
909
+ };
910
+
911
+ /**
912
+ * @api private
913
+ *
914
+ * @returns {boolean}
915
+ */
916
+ Schema.prototype._hasEncryptedFields = function _hasEncryptedFields() {
917
+ return Object.keys(this.encryptedFields).length > 0;
918
+ };
919
+
920
+ /**
921
+ * @param {string} path
922
+ * @returns {boolean}
923
+ *
924
+ * @api private
925
+ */
926
+ Schema.prototype._hasEncryptedField = function _hasEncryptedField(path) {
927
+ return path in this.encryptedFields;
928
+ };
929
+
930
+
931
+ /**
932
+ * Builds an encryptedFieldsMap for the schema.
933
+ *
934
+ * @api private
935
+ */
936
+ Schema.prototype._buildEncryptedFields = function() {
937
+ const fields = Object.entries(this.encryptedFields).map(
938
+ ([path, config]) => {
939
+ const bsonType = this.path(path).autoEncryptionType();
940
+ // { path, bsonType, keyId, queries? }
941
+ return { path, bsonType, ...config };
942
+ });
943
+
944
+ return { fields };
945
+ };
946
+
947
+ /**
948
+ * Builds a schemaMap for the schema, if the schema is configured for client-side field level encryption.
949
+ *
950
+ * @api private
951
+ */
952
+ Schema.prototype._buildSchemaMap = function() {
953
+ /**
954
+ * `schemaMap`s are JSON schemas, which use the following structure to represent objects:
955
+ * { field: { bsonType: 'object', properties: { ... } } }
956
+ *
957
+ * for example, a schema that looks like this `{ a: { b: int32 } }` would be encoded as
958
+ * `{ a: { bsonType: 'object', properties: { b: < encryption configuration > } } }`
959
+ *
960
+ * This function takes an array of path segments, an output object (that gets mutated) and
961
+ * a value to be associated with the full path, and constructs a valid CSFLE JSON schema path for
962
+ * the object. This works for deeply nested properties as well.
963
+ *
964
+ * @param {string[]} path array of path components
965
+ * @param {object} object the object in which to build a JSON schema of `path`'s properties
966
+ * @param {object} value the value to associate with the path in object
967
+ */
968
+ function buildNestedPath(path, object, value) {
969
+ let i = 0, component = path[i];
970
+ for (; i < path.length - 1; ++i, component = path[i]) {
971
+ object[component] = object[component] == null ? {
972
+ bsonType: 'object',
973
+ properties: {}
974
+ } : object[component];
975
+ object = object[component].properties;
976
+ }
977
+ object[component] = value;
978
+ }
979
+
980
+ const schemaMapPropertyReducer = (accum, [path, propertyConfig]) => {
981
+ const bsonType = this.path(path).autoEncryptionType();
982
+ const pathComponents = path.split('.');
983
+ const configuration = { encrypt: { ...propertyConfig, bsonType } };
984
+ buildNestedPath(pathComponents, accum, configuration);
985
+ return accum;
986
+ };
987
+
988
+ const properties = Object.entries(this.encryptedFields).reduce(
989
+ schemaMapPropertyReducer,
990
+ {});
991
+
992
+ return {
993
+ bsonType: 'object',
994
+ properties
995
+ };
996
+ };
997
+
998
+ /**
999
+ * Add an alias for `path`. This means getting or setting the `alias`
1000
+ * is equivalent to getting or setting the `path`.
1001
+ *
1002
+ * #### Example:
1003
+ *
1004
+ * const toySchema = new Schema({ n: String });
1005
+ *
1006
+ * // Make 'name' an alias for 'n'
1007
+ * toySchema.alias('n', 'name');
1008
+ *
1009
+ * const Toy = mongoose.model('Toy', toySchema);
1010
+ * const turboMan = new Toy({ n: 'Turbo Man' });
1011
+ *
1012
+ * turboMan.name; // 'Turbo Man'
1013
+ * turboMan.n; // 'Turbo Man'
1014
+ *
1015
+ * turboMan.name = 'Turbo Man Action Figure';
1016
+ * turboMan.n; // 'Turbo Man Action Figure'
1017
+ *
1018
+ * await turboMan.save(); // Saves { _id: ..., n: 'Turbo Man Action Figure' }
1019
+ *
1020
+ *
1021
+ * @param {String} path real path to alias
1022
+ * @param {String|String[]} alias the path(s) to use as an alias for `path`
1023
+ * @return {Schema} the Schema instance
1024
+ * @api public
1025
+ */
1026
+
1027
+ Schema.prototype.alias = function alias(path, alias) {
1028
+ aliasFields(this, { [path]: alias });
1029
+ return this;
1030
+ };
1031
+
1032
+ /**
1033
+ * Remove an index by name or index specification.
1034
+ *
1035
+ * removeIndex only removes indexes from your schema object. Does **not** affect the indexes
1036
+ * in MongoDB.
1037
+ *
1038
+ * #### Example:
1039
+ *
1040
+ * const ToySchema = new Schema({ name: String, color: String, price: Number });
1041
+ *
1042
+ * // Add a new index on { name, color }
1043
+ * ToySchema.index({ name: 1, color: 1 });
1044
+ *
1045
+ * // Remove index on { name, color }
1046
+ * // Keep in mind that order matters! `removeIndex({ color: 1, name: 1 })` won't remove the index
1047
+ * ToySchema.removeIndex({ name: 1, color: 1 });
1048
+ *
1049
+ * // Add an index with a custom name
1050
+ * ToySchema.index({ color: 1 }, { name: 'my custom index name' });
1051
+ * // Remove index by name
1052
+ * ToySchema.removeIndex('my custom index name');
1053
+ *
1054
+ * @param {Object|string} index name or index specification
1055
+ * @return {Schema} the Schema instance
1056
+ * @api public
1057
+ */
1058
+
1059
+ Schema.prototype.removeIndex = function removeIndex(index) {
1060
+ if (arguments.length > 1) {
1061
+ throw new Error('removeIndex() takes only 1 argument');
1062
+ }
1063
+
1064
+ if (typeof index !== 'object' && typeof index !== 'string') {
1065
+ throw new Error('removeIndex() may only take either an object or a string as an argument');
1066
+ }
1067
+
1068
+ if (typeof index === 'object') {
1069
+ for (let i = this._indexes.length - 1; i >= 0; --i) {
1070
+ if (isIndexSpecEqual(this._indexes[i][0], index)) {
1071
+ this._indexes.splice(i, 1);
1072
+ }
1073
+ }
1074
+ } else {
1075
+ for (let i = this._indexes.length - 1; i >= 0; --i) {
1076
+ if (this._indexes[i][1] != null && this._indexes[i][1].name === index) {
1077
+ this._indexes.splice(i, 1);
1078
+ }
1079
+ }
1080
+ }
1081
+
1082
+ return this;
1083
+ };
1084
+
1085
+ /**
1086
+ * Remove all indexes from this schema.
1087
+ *
1088
+ * clearIndexes only removes indexes from your schema object. Does **not** affect the indexes
1089
+ * in MongoDB.
1090
+ *
1091
+ * #### Example:
1092
+ *
1093
+ * const ToySchema = new Schema({ name: String, color: String, price: Number });
1094
+ * ToySchema.index({ name: 1 });
1095
+ * ToySchema.index({ color: 1 });
1096
+ *
1097
+ * // Remove all indexes on this schema
1098
+ * ToySchema.clearIndexes();
1099
+ *
1100
+ * ToySchema.indexes(); // []
1101
+ *
1102
+ * @return {Schema} the Schema instance
1103
+ * @api public
1104
+ */
1105
+
1106
+ Schema.prototype.clearIndexes = function clearIndexes() {
1107
+ this._indexes.length = 0;
1108
+
1109
+ return this;
1110
+ };
1111
+
1112
+ /**
1113
+ * Add an [Atlas search index](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) that Mongoose will create using `Model.createSearchIndex()`.
1114
+ * This function only works when connected to MongoDB Atlas.
1115
+ *
1116
+ * #### Example:
1117
+ *
1118
+ * const ToySchema = new Schema({ name: String, color: String, price: Number });
1119
+ * ToySchema.searchIndex({ name: 'test', definition: { mappings: { dynamic: true } } });
1120
+ *
1121
+ * @param {Object} description index options, including `name` and `definition`
1122
+ * @param {String} description.name
1123
+ * @param {Object} description.definition
1124
+ * @return {Schema} the Schema instance
1125
+ * @api public
1126
+ */
1127
+
1128
+ Schema.prototype.searchIndex = function searchIndex(description) {
1129
+ this._searchIndexes.push(description);
1130
+
1131
+ return this;
1132
+ };
1133
+
1134
+ /**
1135
+ * Reserved document keys.
1136
+ *
1137
+ * Keys in this object are names that are warned in schema declarations
1138
+ * because they have the potential to break Mongoose/ Mongoose plugins functionality. If you create a schema
1139
+ * using `new Schema()` with one of these property names, Mongoose will log a warning.
1140
+ *
1141
+ * - _posts
1142
+ * - _pres
1143
+ * - collection
1144
+ * - emit
1145
+ * - errors
1146
+ * - get
1147
+ * - init
1148
+ * - isModified
1149
+ * - isNew
1150
+ * - listeners
1151
+ * - modelName
1152
+ * - on
1153
+ * - once
1154
+ * - populated
1155
+ * - prototype
1156
+ * - remove
1157
+ * - removeListener
1158
+ * - save
1159
+ * - schema
1160
+ * - toObject
1161
+ * - validate
1162
+ *
1163
+ * _NOTE:_ Use of these terms as method names is permitted, but play at your own risk, as they may be existing mongoose document methods you are stomping on.
1164
+ *
1165
+ * const schema = new Schema(..);
1166
+ * schema.methods.init = function () {} // potentially breaking
1167
+ *
1168
+ * @property reserved
1169
+ * @memberOf Schema
1170
+ * @static
1171
+ */
1172
+
1173
+ Schema.reserved = Object.create(null);
1174
+ Schema.prototype.reserved = Schema.reserved;
1175
+
1176
+ const reserved = Schema.reserved;
1177
+ // Core object
1178
+ reserved['prototype'] =
1179
+ // EventEmitter
1180
+ reserved.emit =
1181
+ reserved.listeners =
1182
+ reserved.removeListener =
1183
+
1184
+ // document properties and functions
1185
+ reserved.collection =
1186
+ reserved.errors =
1187
+ reserved.get =
1188
+ reserved.init =
1189
+ reserved.isModified =
1190
+ reserved.isNew =
1191
+ reserved.populated =
1192
+ reserved.remove =
1193
+ reserved.save =
1194
+ reserved.toObject =
1195
+ reserved.validate = 1;
1196
+ reserved.collection = 1;
1197
+
1198
+ /**
1199
+ * Gets/sets schema paths.
1200
+ *
1201
+ * Sets a path (if arity 2)
1202
+ * Gets a path (if arity 1)
1203
+ *
1204
+ * #### Example:
1205
+ *
1206
+ * schema.path('name') // returns a SchemaType
1207
+ * schema.path('name', Number) // changes the schemaType of `name` to Number
1208
+ *
1209
+ * @param {String} path The name of the Path to get / set
1210
+ * @param {Object} [obj] The Type to set the path to, if provided the path will be SET, otherwise the path will be GET
1211
+ * @api public
1212
+ */
1213
+
1214
+ Schema.prototype.path = function(path, obj) {
1215
+ if (obj === undefined) {
1216
+ if (this.paths[path] != null) {
1217
+ return this.paths[path];
1218
+ }
1219
+ // Convert to '.$' to check subpaths re: gh-6405
1220
+ const cleanPath = _pathToPositionalSyntax(path);
1221
+ let schematype = _getPath(this, path, cleanPath);
1222
+ if (schematype != null) {
1223
+ return schematype;
1224
+ }
1225
+
1226
+ // Look for maps
1227
+ const mapPath = getMapPath(this, path);
1228
+ if (mapPath != null) {
1229
+ return mapPath;
1230
+ }
1231
+
1232
+ // Look if a parent of this path is mixed
1233
+ schematype = this.hasMixedParent(cleanPath);
1234
+ if (schematype != null) {
1235
+ return schematype;
1236
+ }
1237
+
1238
+ // subpaths?
1239
+ return hasNumericSubpathRegex.test(path)
1240
+ ? getPositionalPath(this, path, cleanPath)
1241
+ : undefined;
1242
+ }
1243
+
1244
+ // some path names conflict with document methods
1245
+ const firstPieceOfPath = path.split('.')[0];
1246
+ if (reserved[firstPieceOfPath] && !this.options.suppressReservedKeysWarning) {
1247
+ const errorMessage = `\`${firstPieceOfPath}\` is a reserved schema pathname and may break some functionality. ` +
1248
+ 'You are allowed to use it, but use at your own risk. ' +
1249
+ 'To disable this warning pass `suppressReservedKeysWarning` as a schema option.';
1250
+
1251
+ utils.warn(errorMessage);
1252
+ }
1253
+
1254
+ if (typeof obj === 'object' && utils.hasUserDefinedProperty(obj, 'ref')) {
1255
+ validateRef(obj.ref, path);
1256
+ }
1257
+
1258
+ // update the tree
1259
+ const subpaths = path.split(/\./);
1260
+ const last = subpaths.pop();
1261
+ let branch = this.tree;
1262
+ let fullPath = '';
1263
+
1264
+ for (const sub of subpaths) {
1265
+ if (utils.specialProperties.has(sub)) {
1266
+ throw new Error('Cannot set special property `' + sub + '` on a schema');
1267
+ }
1268
+ fullPath = fullPath += (fullPath.length > 0 ? '.' : '') + sub;
1269
+ if (!branch[sub]) {
1270
+ this.nested[fullPath] = true;
1271
+ branch[sub] = {};
1272
+ }
1273
+ if (typeof branch[sub] !== 'object') {
1274
+ const msg = 'Cannot set nested path `' + path + '`. '
1275
+ + 'Parent path `'
1276
+ + fullPath
1277
+ + '` already set to type ' + branch[sub].name
1278
+ + '.';
1279
+ throw new Error(msg);
1280
+ }
1281
+ branch = branch[sub];
1282
+ }
1283
+
1284
+ branch[last] = clone(obj);
1285
+
1286
+ this.paths[path] = this.interpretAsType(path, obj, this.options);
1287
+ const schemaType = this.paths[path];
1288
+
1289
+ // If overwriting an existing path, make sure to clear the childSchemas
1290
+ this.childSchemas = this.childSchemas.filter(childSchema => childSchema.path !== path);
1291
+
1292
+ if (schemaType.$isSchemaMap) {
1293
+ // Maps can have arbitrary keys, so `$*` is internal shorthand for "any key"
1294
+ // The '$' is to imply this path should never be stored in MongoDB so we
1295
+ // can easily build a regexp out of this path, and '*' to imply "any key."
1296
+ const mapPath = path + '.$*';
1297
+
1298
+ this.paths[mapPath] = schemaType.$__schemaType;
1299
+ this.mapPaths.push(this.paths[mapPath]);
1300
+ if (schemaType.$__schemaType.$isSingleNested) {
1301
+ this.childSchemas.push({
1302
+ schema: schemaType.$__schemaType.schema,
1303
+ model: schemaType.$__schemaType.caster,
1304
+ path: path
1305
+ });
1306
+ }
1307
+ }
1308
+
1309
+ if (schemaType.$isSingleNested) {
1310
+ for (const key of Object.keys(schemaType.schema.paths)) {
1311
+ this.singleNestedPaths[path + '.' + key] = schemaType.schema.paths[key];
1312
+ }
1313
+ for (const key of Object.keys(schemaType.schema.singleNestedPaths)) {
1314
+ this.singleNestedPaths[path + '.' + key] =
1315
+ schemaType.schema.singleNestedPaths[key];
1316
+ }
1317
+ for (const key of Object.keys(schemaType.schema.subpaths)) {
1318
+ this.singleNestedPaths[path + '.' + key] =
1319
+ schemaType.schema.subpaths[key];
1320
+ }
1321
+ for (const key of Object.keys(schemaType.schema.nested)) {
1322
+ this.singleNestedPaths[path + '.' + key] = 'nested';
1323
+ }
1324
+
1325
+ Object.defineProperty(schemaType.schema, 'base', {
1326
+ configurable: true,
1327
+ enumerable: false,
1328
+ writable: false,
1329
+ value: this.base
1330
+ });
1331
+
1332
+ schemaType.caster.base = this.base;
1333
+ this.childSchemas.push({
1334
+ schema: schemaType.schema,
1335
+ model: schemaType.caster,
1336
+ path: path
1337
+ });
1338
+ } else if (schemaType.$isMongooseDocumentArray) {
1339
+ Object.defineProperty(schemaType.schema, 'base', {
1340
+ configurable: true,
1341
+ enumerable: false,
1342
+ writable: false,
1343
+ value: this.base
1344
+ });
1345
+
1346
+ schemaType.casterConstructor.base = this.base;
1347
+ this.childSchemas.push({
1348
+ schema: schemaType.schema,
1349
+ model: schemaType.casterConstructor,
1350
+ path: path
1351
+ });
1352
+ }
1353
+
1354
+ if (schemaType.$isMongooseArray && schemaType.caster instanceof SchemaType) {
1355
+ let arrayPath = path;
1356
+ let _schemaType = schemaType;
1357
+
1358
+ const toAdd = [];
1359
+ while (_schemaType.$isMongooseArray) {
1360
+ arrayPath = arrayPath + '.$';
1361
+
1362
+ // Skip arrays of document arrays
1363
+ if (_schemaType.$isMongooseDocumentArray) {
1364
+ _schemaType.$embeddedSchemaType._arrayPath = arrayPath;
1365
+ _schemaType.$embeddedSchemaType._arrayParentPath = path;
1366
+ _schemaType = _schemaType.$embeddedSchemaType;
1367
+ } else {
1368
+ _schemaType.caster._arrayPath = arrayPath;
1369
+ _schemaType.caster._arrayParentPath = path;
1370
+ _schemaType = _schemaType.caster;
1371
+ }
1372
+
1373
+ this.subpaths[arrayPath] = _schemaType;
1374
+ }
1375
+
1376
+ for (const _schemaType of toAdd) {
1377
+ this.subpaths[_schemaType.path] = _schemaType;
1378
+ }
1379
+ }
1380
+
1381
+ if (schemaType.$isMongooseDocumentArray) {
1382
+ for (const key of Object.keys(schemaType.schema.paths)) {
1383
+ const _schemaType = schemaType.schema.paths[key];
1384
+ this.subpaths[path + '.' + key] = _schemaType;
1385
+ if (typeof _schemaType === 'object' && _schemaType != null && _schemaType.$parentSchemaDocArray == null) {
1386
+ _schemaType.$parentSchemaDocArray = schemaType;
1387
+ }
1388
+ }
1389
+ for (const key of Object.keys(schemaType.schema.subpaths)) {
1390
+ const _schemaType = schemaType.schema.subpaths[key];
1391
+ this.subpaths[path + '.' + key] = _schemaType;
1392
+ if (typeof _schemaType === 'object' && _schemaType != null && _schemaType.$parentSchemaDocArray == null) {
1393
+ _schemaType.$parentSchemaDocArray = schemaType;
1394
+ }
1395
+ }
1396
+ for (const key of Object.keys(schemaType.schema.singleNestedPaths)) {
1397
+ const _schemaType = schemaType.schema.singleNestedPaths[key];
1398
+ this.subpaths[path + '.' + key] = _schemaType;
1399
+ if (typeof _schemaType === 'object' && _schemaType != null && _schemaType.$parentSchemaDocArray == null) {
1400
+ _schemaType.$parentSchemaDocArray = schemaType;
1401
+ }
1402
+ }
1403
+ }
1404
+
1405
+ return this;
1406
+ };
1407
+
1408
+ /*!
1409
+ * ignore
1410
+ */
1411
+
1412
+ Schema.prototype._gatherChildSchemas = function _gatherChildSchemas() {
1413
+ const childSchemas = [];
1414
+
1415
+ for (const path of Object.keys(this.paths)) {
1416
+ if (typeof path !== 'string') {
1417
+ continue;
1418
+ }
1419
+ const schematype = this.paths[path];
1420
+ if (schematype.$isMongooseDocumentArray || schematype.$isSingleNested) {
1421
+ childSchemas.push({
1422
+ schema: schematype.schema,
1423
+ model: schematype.caster,
1424
+ path: path
1425
+ });
1426
+ } else if (schematype.$isSchemaMap && schematype.$__schemaType.$isSingleNested) {
1427
+ childSchemas.push({
1428
+ schema: schematype.$__schemaType.schema,
1429
+ model: schematype.$__schemaType.caster,
1430
+ path: path
1431
+ });
1432
+ }
1433
+ }
1434
+
1435
+ this.childSchemas = childSchemas;
1436
+ return childSchemas;
1437
+ };
1438
+
1439
+ /*!
1440
+ * ignore
1441
+ */
1442
+
1443
+ function _getPath(schema, path, cleanPath) {
1444
+ if (Object.hasOwn(schema.paths, path)) {
1445
+ return schema.paths[path];
1446
+ }
1447
+ if (Object.hasOwn(schema.subpaths, cleanPath)) {
1448
+ const subpath = schema.subpaths[cleanPath];
1449
+ if (subpath === 'nested') {
1450
+ return undefined;
1451
+ }
1452
+ return subpath;
1453
+ }
1454
+ if (Object.hasOwn(schema.singleNestedPaths, cleanPath) && typeof schema.singleNestedPaths[cleanPath] === 'object') {
1455
+ const singleNestedPath = schema.singleNestedPaths[cleanPath];
1456
+ if (singleNestedPath === 'nested') {
1457
+ return undefined;
1458
+ }
1459
+ return singleNestedPath;
1460
+ }
1461
+
1462
+ return null;
1463
+ }
1464
+
1465
+ /*!
1466
+ * ignore
1467
+ */
1468
+
1469
+ function _pathToPositionalSyntax(path) {
1470
+ if (!/\.\d+/.test(path)) {
1471
+ return path;
1472
+ }
1473
+ return path.replace(/\.\d+\./g, '.$.').replace(/\.\d+$/, '.$');
1474
+ }
1475
+
1476
+ /*!
1477
+ * ignore
1478
+ */
1479
+
1480
+ function getMapPath(schema, path) {
1481
+ if (schema.mapPaths.length === 0) {
1482
+ return null;
1483
+ }
1484
+ for (const val of schema.mapPaths) {
1485
+ const cleanPath = val.path.replace(/\.\$\*/g, '');
1486
+ if (path === cleanPath || (path.startsWith(cleanPath + '.') && path.slice(cleanPath.length + 1).indexOf('.') === -1)) {
1487
+ return val;
1488
+ } else if (val.schema && path.startsWith(cleanPath + '.')) {
1489
+ let remnant = path.slice(cleanPath.length + 1);
1490
+ remnant = remnant.slice(remnant.indexOf('.') + 1);
1491
+ return val.schema.paths[remnant];
1492
+ } else if (val.$isSchemaMap && path.startsWith(cleanPath + '.')) {
1493
+ let remnant = path.slice(cleanPath.length + 1);
1494
+ remnant = remnant.slice(remnant.indexOf('.') + 1);
1495
+ const presplitPath = val.$__schemaType._presplitPath;
1496
+ if (remnant.indexOf('.') === -1 && presplitPath[presplitPath.length - 1] === '$*') {
1497
+ // Handle map of map of primitives
1498
+ return val.$__schemaType;
1499
+ } else if (remnant.indexOf('.') !== -1 && val.$__schemaType.schema && presplitPath[presplitPath.length - 1] === '$*') {
1500
+ // map of map of subdocs (recursive)
1501
+ return val.$__schemaType.schema.path(remnant.slice(remnant.indexOf('.') + 1));
1502
+ }
1503
+ }
1504
+ }
1505
+
1506
+ return null;
1507
+ }
1508
+
1509
+ /**
1510
+ * The Mongoose instance this schema is associated with
1511
+ *
1512
+ * @property base
1513
+ * @api private
1514
+ */
1515
+
1516
+ Object.defineProperty(Schema.prototype, 'base', {
1517
+ configurable: true,
1518
+ enumerable: false,
1519
+ writable: true,
1520
+ value: null
1521
+ });
1522
+
1523
+ /**
1524
+ * Converts type arguments into Mongoose Types.
1525
+ *
1526
+ * @param {String} path
1527
+ * @param {Object} obj constructor
1528
+ * @param {Object} options schema options
1529
+ * @api private
1530
+ */
1531
+
1532
+ Schema.prototype.interpretAsType = function(path, obj, options) {
1533
+ if (obj instanceof SchemaType) {
1534
+ if (obj.path === path) {
1535
+ return obj;
1536
+ }
1537
+ const clone = obj.clone();
1538
+ clone.path = path;
1539
+ return clone;
1540
+ }
1541
+
1542
+ // If this schema has an associated Mongoose object, use the Mongoose object's
1543
+ // copy of SchemaTypes re: gh-7158 gh-6933
1544
+ const MongooseTypes = this.base != null ? this.base.Schema.Types : Schema.Types;
1545
+ const Types = this.base != null ? this.base.Types : require('./types');
1546
+
1547
+ if (!utils.isPOJO(obj) && !(obj instanceof SchemaTypeOptions)) {
1548
+ const constructorName = utils.getFunctionName(obj.constructor);
1549
+ if (constructorName !== 'Object') {
1550
+ const oldObj = obj;
1551
+ obj = {};
1552
+ obj[options.typeKey] = oldObj;
1553
+ }
1554
+ }
1555
+
1556
+ // Get the type making sure to allow keys named "type"
1557
+ // and default to mixed if not specified.
1558
+ // { type: { type: String, default: 'freshcut' } }
1559
+ let type = obj[options.typeKey] && (obj[options.typeKey] instanceof Function || options.typeKey !== 'type' || !obj.type.type)
1560
+ ? obj[options.typeKey]
1561
+ : {};
1562
+
1563
+ if (type instanceof SchemaType) {
1564
+ if (type.path === path) {
1565
+ return type;
1566
+ }
1567
+ const clone = type.clone();
1568
+ clone.path = path;
1569
+ return clone;
1570
+ }
1571
+
1572
+ let name;
1573
+
1574
+ if (utils.isPOJO(type) || type === 'mixed') {
1575
+ return new MongooseTypes.Mixed(path, obj, null, this);
1576
+ }
1577
+
1578
+ if (Array.isArray(type) || type === Array || type === 'array' || type === MongooseTypes.Array) {
1579
+ // if it was specified through { type } look for `cast`
1580
+ let cast = (type === Array || type === 'array')
1581
+ ? obj.cast || obj.of
1582
+ : type[0];
1583
+
1584
+ // new Schema({ path: [new Schema({ ... })] })
1585
+ if (cast && cast.instanceOfSchema) {
1586
+ if (!(cast instanceof Schema)) {
1587
+ if (this.options._isMerging) {
1588
+ cast = new Schema(cast);
1589
+ } else {
1590
+ throw new TypeError('Schema for array path `' + path +
1591
+ '` is from a different copy of the Mongoose module. ' +
1592
+ 'Please make sure you\'re using the same version ' +
1593
+ 'of Mongoose everywhere with `npm list mongoose`. If you are still ' +
1594
+ 'getting this error, please add `new Schema()` around the path: ' +
1595
+ `${path}: new Schema(...)`);
1596
+ }
1597
+ }
1598
+ return new MongooseTypes.DocumentArray(path, cast, obj, null, this);
1599
+ }
1600
+ if (cast &&
1601
+ cast[options.typeKey] &&
1602
+ cast[options.typeKey].instanceOfSchema) {
1603
+ if (!(cast[options.typeKey] instanceof Schema)) {
1604
+ if (this.options._isMerging) {
1605
+ cast[options.typeKey] = new Schema(cast[options.typeKey]);
1606
+ } else {
1607
+ throw new TypeError('Schema for array path `' + path +
1608
+ '` is from a different copy of the Mongoose module. ' +
1609
+ 'Please make sure you\'re using the same version ' +
1610
+ 'of Mongoose everywhere with `npm list mongoose`. If you are still ' +
1611
+ 'getting this error, please add `new Schema()` around the path: ' +
1612
+ `${path}: new Schema(...)`);
1613
+ }
1614
+ }
1615
+ return new MongooseTypes.DocumentArray(path, cast[options.typeKey], obj, cast, this);
1616
+ }
1617
+ if (typeof cast !== 'undefined') {
1618
+ if (Array.isArray(cast) || cast.type === Array || cast.type == 'Array') {
1619
+ if (cast && cast.type == 'Array') {
1620
+ cast.type = Array;
1621
+ }
1622
+ return new MongooseTypes.Array(path, this.interpretAsType(path, cast, options), obj, null, this);
1623
+ }
1624
+ }
1625
+
1626
+ // Handle both `new Schema({ arr: [{ subpath: String }] })` and `new Schema({ arr: [{ type: { subpath: string } }] })`
1627
+ const castFromTypeKey = (cast != null && cast[options.typeKey] && (options.typeKey !== 'type' || !cast.type.type)) ?
1628
+ cast[options.typeKey] :
1629
+ cast;
1630
+ if (typeof cast === 'string') {
1631
+ cast = MongooseTypes[cast.charAt(0).toUpperCase() + cast.substring(1)];
1632
+ } else if (utils.isPOJO(castFromTypeKey)) {
1633
+ if (Object.keys(castFromTypeKey).length) {
1634
+ // The `minimize` and `typeKey` options propagate to child schemas
1635
+ // declared inline, like `{ arr: [{ val: { $type: String } }] }`.
1636
+ // See gh-3560
1637
+ const childSchemaOptions = { minimize: options.minimize };
1638
+ if (options.typeKey) {
1639
+ childSchemaOptions.typeKey = options.typeKey;
1640
+ }
1641
+ // propagate 'strict' option to child schema
1642
+ if (Object.hasOwn(options, 'strict')) {
1643
+ childSchemaOptions.strict = options.strict;
1644
+ }
1645
+ if (Object.hasOwn(options, 'strictQuery')) {
1646
+ childSchemaOptions.strictQuery = options.strictQuery;
1647
+ }
1648
+ if (Object.hasOwn(options, 'toObject')) {
1649
+ childSchemaOptions.toObject = utils.omit(options.toObject, ['transform']);
1650
+ }
1651
+ if (Object.hasOwn(options, 'toJSON')) {
1652
+ childSchemaOptions.toJSON = utils.omit(options.toJSON, ['transform']);
1653
+ }
1654
+
1655
+ if (Object.hasOwn(this._userProvidedOptions, '_id')) {
1656
+ childSchemaOptions._id = this._userProvidedOptions._id;
1657
+ } else if (Schema.Types.DocumentArray.defaultOptions._id != null) {
1658
+ childSchemaOptions._id = Schema.Types.DocumentArray.defaultOptions._id;
1659
+ }
1660
+
1661
+ const childSchema = new Schema(castFromTypeKey, childSchemaOptions);
1662
+ childSchema.$implicitlyCreated = true;
1663
+ return new MongooseTypes.DocumentArray(path, childSchema, obj, null, this);
1664
+ } else {
1665
+ // Special case: empty object becomes mixed
1666
+ return new MongooseTypes.Array(path, MongooseTypes.Mixed, obj, null, this);
1667
+ }
1668
+ }
1669
+
1670
+ if (cast) {
1671
+ type = cast[options.typeKey] && (options.typeKey !== 'type' || !cast.type.type)
1672
+ ? cast[options.typeKey]
1673
+ : cast;
1674
+ if (Array.isArray(type)) {
1675
+ return new MongooseTypes.Array(path, this.interpretAsType(path, type, options), obj, null, this);
1676
+ }
1677
+
1678
+ name = typeof type === 'string'
1679
+ ? type
1680
+ : type.schemaName || utils.getFunctionName(type);
1681
+
1682
+ // For Jest 26+, see #10296
1683
+ if (name === 'ClockDate') {
1684
+ name = 'Date';
1685
+ }
1686
+
1687
+ if (name === void 0) {
1688
+ throw new TypeError('Invalid schema configuration: ' +
1689
+ `Could not determine the embedded type for array \`${path}\`. ` +
1690
+ 'See https://mongoosejs.com/docs/guide.html#definition for more info on supported schema syntaxes.');
1691
+ }
1692
+ if (!Object.hasOwn(MongooseTypes, name)) {
1693
+ throw new TypeError('Invalid schema configuration: ' +
1694
+ `\`${name}\` is not a valid type within the array \`${path}\`.` +
1695
+ 'See https://bit.ly/mongoose-schematypes for a list of valid schema types.');
1696
+ }
1697
+
1698
+ if (name === 'Union' && typeof cast === 'object') {
1699
+ cast.parentSchema = this;
1700
+ }
1701
+ }
1702
+
1703
+ return new MongooseTypes.Array(path, cast || MongooseTypes.Mixed, obj, options, this);
1704
+ }
1705
+
1706
+ if (type && type.instanceOfSchema) {
1707
+ return new MongooseTypes.Subdocument(type, path, obj, this);
1708
+ }
1709
+
1710
+ if (Buffer.isBuffer(type)) {
1711
+ name = 'Buffer';
1712
+ } else if (typeof type === 'function' || typeof type === 'object') {
1713
+ name = type.schemaName || utils.getFunctionName(type);
1714
+ } else if (type === Types.ObjectId) {
1715
+ name = 'ObjectId';
1716
+ } else if (type === Types.Decimal128) {
1717
+ name = 'Decimal128';
1718
+ } else {
1719
+ name = type == null ? '' + type : type.toString();
1720
+ }
1721
+
1722
+ if (name) {
1723
+ name = name.charAt(0).toUpperCase() + name.substring(1);
1724
+ }
1725
+ // Special case re: gh-7049 because the bson `ObjectID` class' capitalization
1726
+ // doesn't line up with Mongoose's.
1727
+ if (name === 'ObjectID') {
1728
+ name = 'ObjectId';
1729
+ }
1730
+ // For Jest 26+, see #10296
1731
+ if (name === 'ClockDate') {
1732
+ name = 'Date';
1733
+ }
1734
+
1735
+ if (name === void 0) {
1736
+ throw new TypeError(`Invalid schema configuration: \`${path}\` schematype definition is ` +
1737
+ 'invalid. See ' +
1738
+ 'https://mongoosejs.com/docs/guide.html#definition for more info on supported schema syntaxes.');
1739
+ }
1740
+ if (MongooseTypes[name] == null) {
1741
+ throw new TypeError(`Invalid schema configuration: \`${name}\` is not ` +
1742
+ `a valid type at path \`${path}\`. See ` +
1743
+ 'https://bit.ly/mongoose-schematypes for a list of valid schema types.');
1744
+ }
1745
+
1746
+ const schemaType = new MongooseTypes[name](path, obj, options, this);
1747
+
1748
+ return schemaType;
1749
+ };
1750
+
1751
+ /**
1752
+ * Iterates the schemas paths similar to Array#forEach.
1753
+ *
1754
+ * The callback is passed the pathname and the schemaType instance.
1755
+ *
1756
+ * #### Example:
1757
+ *
1758
+ * const userSchema = new Schema({ name: String, registeredAt: Date });
1759
+ * userSchema.eachPath((pathname, schematype) => {
1760
+ * // Prints twice:
1761
+ * // name SchemaString { ... }
1762
+ * // registeredAt SchemaDate { ... }
1763
+ * console.log(pathname, schematype);
1764
+ * });
1765
+ *
1766
+ * @param {Function} fn callback function
1767
+ * @return {Schema} this
1768
+ * @api public
1769
+ */
1770
+
1771
+ Schema.prototype.eachPath = function(fn) {
1772
+ const keys = Object.keys(this.paths);
1773
+ const len = keys.length;
1774
+
1775
+ for (let i = 0; i < len; ++i) {
1776
+ fn(keys[i], this.paths[keys[i]]);
1777
+ }
1778
+
1779
+ return this;
1780
+ };
1781
+
1782
+ /**
1783
+ * Returns an Array of path strings that are required by this schema.
1784
+ *
1785
+ * #### Example:
1786
+ *
1787
+ * const s = new Schema({
1788
+ * name: { type: String, required: true },
1789
+ * age: { type: String, required: true },
1790
+ * notes: String
1791
+ * });
1792
+ * s.requiredPaths(); // [ 'age', 'name' ]
1793
+ *
1794
+ * @api public
1795
+ * @param {Boolean} invalidate Refresh the cache
1796
+ * @return {Array}
1797
+ */
1798
+
1799
+ Schema.prototype.requiredPaths = function requiredPaths(invalidate) {
1800
+ if (this._requiredpaths && !invalidate) {
1801
+ return this._requiredpaths;
1802
+ }
1803
+
1804
+ const paths = Object.keys(this.paths);
1805
+ let i = paths.length;
1806
+ const ret = [];
1807
+
1808
+ while (i--) {
1809
+ const path = paths[i];
1810
+ if (this.paths[path].isRequired) {
1811
+ ret.push(path);
1812
+ }
1813
+ }
1814
+ this._requiredpaths = ret;
1815
+ return this._requiredpaths;
1816
+ };
1817
+
1818
+ /**
1819
+ * Returns indexes from fields and schema-level indexes (cached).
1820
+ *
1821
+ * @api private
1822
+ * @return {Array}
1823
+ */
1824
+
1825
+ Schema.prototype.indexedPaths = function indexedPaths() {
1826
+ if (this._indexedpaths) {
1827
+ return this._indexedpaths;
1828
+ }
1829
+ this._indexedpaths = this.indexes();
1830
+ return this._indexedpaths;
1831
+ };
1832
+
1833
+ /**
1834
+ * Returns the pathType of `path` for this schema.
1835
+ *
1836
+ * Given a path, returns whether it is a real, virtual, nested, or ad-hoc/undefined path.
1837
+ *
1838
+ * #### Example:
1839
+ *
1840
+ * const s = new Schema({ name: String, nested: { foo: String } });
1841
+ * s.virtual('foo').get(() => 42);
1842
+ * s.pathType('name'); // "real"
1843
+ * s.pathType('nested'); // "nested"
1844
+ * s.pathType('foo'); // "virtual"
1845
+ * s.pathType('fail'); // "adhocOrUndefined"
1846
+ *
1847
+ * @param {String} path
1848
+ * @return {String}
1849
+ * @api public
1850
+ */
1851
+
1852
+ Schema.prototype.pathType = function(path) {
1853
+ if (Object.hasOwn(this.paths, path)) {
1854
+ return 'real';
1855
+ }
1856
+ if (Object.hasOwn(this.virtuals, path)) {
1857
+ return 'virtual';
1858
+ }
1859
+ if (Object.hasOwn(this.nested, path)) {
1860
+ return 'nested';
1861
+ }
1862
+
1863
+ // Convert to '.$' to check subpaths re: gh-6405
1864
+ const cleanPath = _pathToPositionalSyntax(path);
1865
+
1866
+ if (Object.hasOwn(this.subpaths, cleanPath) || Object.hasOwn(this.subpaths, path)) {
1867
+ return 'real';
1868
+ }
1869
+
1870
+ const singleNestedPath = Object.hasOwn(this.singleNestedPaths, cleanPath) || Object.hasOwn(this.singleNestedPaths, path);
1871
+ if (singleNestedPath) {
1872
+ return singleNestedPath === 'nested' ? 'nested' : 'real';
1873
+ }
1874
+
1875
+ // Look for maps
1876
+ const mapPath = getMapPath(this, path);
1877
+ if (mapPath != null) {
1878
+ return 'real';
1879
+ }
1880
+
1881
+ if (/\.\d+\.|\.\d+$/.test(path)) {
1882
+ return getPositionalPathType(this, path, cleanPath);
1883
+ }
1884
+ return 'adhocOrUndefined';
1885
+ };
1886
+
1887
+ /**
1888
+ * Returns true iff this path is a child of a mixed schema.
1889
+ *
1890
+ * @param {String} path
1891
+ * @return {Boolean}
1892
+ * @api private
1893
+ */
1894
+
1895
+ Schema.prototype.hasMixedParent = function(path) {
1896
+ const subpaths = path.split(/\./g);
1897
+ path = '';
1898
+ for (let i = 0; i < subpaths.length; ++i) {
1899
+ path = i > 0 ? path + '.' + subpaths[i] : subpaths[i];
1900
+ if (Object.hasOwn(this.paths, path) &&
1901
+ this.paths[path] instanceof MongooseTypes.Mixed) {
1902
+ return this.paths[path];
1903
+ }
1904
+ }
1905
+
1906
+ return null;
1907
+ };
1908
+
1909
+ /**
1910
+ * Setup updatedAt and createdAt timestamps to documents if enabled
1911
+ *
1912
+ * @param {Boolean|Object} timestamps timestamps options
1913
+ * @api private
1914
+ */
1915
+ Schema.prototype.setupTimestamp = function(timestamps) {
1916
+ return setupTimestamps(this, timestamps);
1917
+ };
1918
+
1919
+ /**
1920
+ * ignore. Deprecated re: #6405
1921
+ * @param {Any} self
1922
+ * @param {String} path
1923
+ * @api private
1924
+ */
1925
+
1926
+ function getPositionalPathType(self, path, cleanPath) {
1927
+ const subpaths = path.split(/\.(\d+)\.|\.(\d+)$/).filter(Boolean);
1928
+ if (subpaths.length < 2) {
1929
+ return Object.hasOwn(self.paths, subpaths[0]) ?
1930
+ self.paths[subpaths[0]] :
1931
+ 'adhocOrUndefined';
1932
+ }
1933
+
1934
+ let val = self.path(subpaths[0]);
1935
+ let isNested = false;
1936
+ if (!val) {
1937
+ return 'adhocOrUndefined';
1938
+ }
1939
+
1940
+ const last = subpaths.length - 1;
1941
+
1942
+ for (let i = 1; i < subpaths.length; ++i) {
1943
+ isNested = false;
1944
+ const subpath = subpaths[i];
1945
+
1946
+ if (i === last && val && !/\D/.test(subpath)) {
1947
+ if (val.$isMongooseDocumentArray) {
1948
+ val = val.$embeddedSchemaType;
1949
+ } else if (val instanceof MongooseTypes.Array) {
1950
+ // StringSchema, NumberSchema, etc
1951
+ val = val.caster;
1952
+ } else {
1953
+ val = undefined;
1954
+ }
1955
+ break;
1956
+ }
1957
+
1958
+ // ignore if its just a position segment: path.0.subpath
1959
+ if (!/\D/.test(subpath)) {
1960
+ // Nested array
1961
+ if (val instanceof MongooseTypes.Array && i !== last) {
1962
+ val = val.caster;
1963
+ }
1964
+ continue;
1965
+ }
1966
+
1967
+ if (!(val && val.schema)) {
1968
+ val = undefined;
1969
+ break;
1970
+ }
1971
+
1972
+ const type = val.schema.pathType(subpath);
1973
+ isNested = (type === 'nested');
1974
+ val = val.schema.path(subpath);
1975
+ }
1976
+
1977
+ self.subpaths[cleanPath] = val;
1978
+ if (val) {
1979
+ return 'real';
1980
+ }
1981
+ if (isNested) {
1982
+ return 'nested';
1983
+ }
1984
+ return 'adhocOrUndefined';
1985
+ }
1986
+
1987
+
1988
+ /*!
1989
+ * ignore
1990
+ */
1991
+
1992
+ function getPositionalPath(self, path, cleanPath) {
1993
+ getPositionalPathType(self, path, cleanPath);
1994
+ return self.subpaths[cleanPath];
1995
+ }
1996
+
1997
+ /**
1998
+ * Adds a method call to the queue.
1999
+ *
2000
+ * #### Example:
2001
+ *
2002
+ * schema.methods.print = function() { console.log(this); };
2003
+ * schema.queue('print', []); // Print the doc every one is instantiated
2004
+ *
2005
+ * const Model = mongoose.model('Test', schema);
2006
+ * new Model({ name: 'test' }); // Prints '{"_id": ..., "name": "test" }'
2007
+ *
2008
+ * @param {String} name name of the document method to call later
2009
+ * @param {Array} args arguments to pass to the method
2010
+ * @api public
2011
+ */
2012
+
2013
+ Schema.prototype.queue = function(name, args) {
2014
+ this.callQueue.push([name, args]);
2015
+ return this;
2016
+ };
2017
+
2018
+ /**
2019
+ * Defines a pre hook for the model.
2020
+ *
2021
+ * #### Example:
2022
+ *
2023
+ * const toySchema = new Schema({ name: String, created: Date });
2024
+ *
2025
+ * toySchema.pre('save', function(next) {
2026
+ * if (!this.created) this.created = new Date;
2027
+ * next();
2028
+ * });
2029
+ *
2030
+ * toySchema.pre('validate', function(next) {
2031
+ * if (this.name !== 'Woody') this.name = 'Woody';
2032
+ * next();
2033
+ * });
2034
+ *
2035
+ * // Equivalent to calling `pre()` on `find`, `findOne`, `findOneAndUpdate`.
2036
+ * toySchema.pre(/^find/, function(next) {
2037
+ * console.log(this.getFilter());
2038
+ * });
2039
+ *
2040
+ * // Equivalent to calling `pre()` on `updateOne`, `findOneAndUpdate`.
2041
+ * toySchema.pre(['updateOne', 'findOneAndUpdate'], function(next) {
2042
+ * console.log(this.getFilter());
2043
+ * });
2044
+ *
2045
+ * toySchema.pre('deleteOne', function() {
2046
+ * // Runs when you call `Toy.deleteOne()`
2047
+ * });
2048
+ *
2049
+ * toySchema.pre('deleteOne', { document: true }, function() {
2050
+ * // Runs when you call `doc.deleteOne()`
2051
+ * });
2052
+ *
2053
+ * @param {String|RegExp|String[]} methodName The method name or regular expression to match method name
2054
+ * @param {Object} [options]
2055
+ * @param {Boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware. For example, set `options.document` to `true` to apply this hook to `Document#deleteOne()` rather than `Query#deleteOne()`.
2056
+ * @param {Boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
2057
+ * @param {Function} callback
2058
+ * @api public
2059
+ */
2060
+
2061
+ Schema.prototype.pre = function(name) {
2062
+ if (name instanceof RegExp) {
2063
+ const remainingArgs = Array.prototype.slice.call(arguments, 1);
2064
+ for (const fn of hookNames) {
2065
+ if (name.test(fn)) {
2066
+ this.pre.apply(this, [fn].concat(remainingArgs));
2067
+ }
2068
+ }
2069
+ return this;
2070
+ }
2071
+ if (Array.isArray(name)) {
2072
+ const remainingArgs = Array.prototype.slice.call(arguments, 1);
2073
+ for (const el of name) {
2074
+ this.pre.apply(this, [el].concat(remainingArgs));
2075
+ }
2076
+ return this;
2077
+ }
2078
+ this.s.hooks.pre.apply(this.s.hooks, arguments);
2079
+ return this;
2080
+ };
2081
+
2082
+ /**
2083
+ * Defines a post hook for the document
2084
+ *
2085
+ * const schema = new Schema(..);
2086
+ * schema.post('save', function (doc) {
2087
+ * console.log('this fired after a document was saved');
2088
+ * });
2089
+ *
2090
+ * schema.post('find', function(docs) {
2091
+ * console.log('this fired after you ran a find query');
2092
+ * });
2093
+ *
2094
+ * schema.post(/Many$/, function(res) {
2095
+ * console.log('this fired after you ran `updateMany()` or `deleteMany()`');
2096
+ * });
2097
+ *
2098
+ * const Model = mongoose.model('Model', schema);
2099
+ *
2100
+ * const m = new Model(..);
2101
+ * await m.save();
2102
+ * console.log('this fires after the `post` hook');
2103
+ *
2104
+ * await m.find();
2105
+ * console.log('this fires after the post find hook');
2106
+ *
2107
+ * @param {String|RegExp|String[]} methodName The method name or regular expression to match method name
2108
+ * @param {Object} [options]
2109
+ * @param {Boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware.
2110
+ * @param {Boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
2111
+ * @param {Function} fn callback
2112
+ * @see middleware https://mongoosejs.com/docs/middleware.html
2113
+ * @see kareem https://npmjs.org/package/kareem
2114
+ * @api public
2115
+ */
2116
+
2117
+ Schema.prototype.post = function(name) {
2118
+ if (name instanceof RegExp) {
2119
+ const remainingArgs = Array.prototype.slice.call(arguments, 1);
2120
+ for (const fn of hookNames) {
2121
+ if (name.test(fn)) {
2122
+ this.post.apply(this, [fn].concat(remainingArgs));
2123
+ }
2124
+ }
2125
+ return this;
2126
+ }
2127
+ if (Array.isArray(name)) {
2128
+ const remainingArgs = Array.prototype.slice.call(arguments, 1);
2129
+ for (const el of name) {
2130
+ this.post.apply(this, [el].concat(remainingArgs));
2131
+ }
2132
+ return this;
2133
+ }
2134
+ this.s.hooks.post.apply(this.s.hooks, arguments);
2135
+ return this;
2136
+ };
2137
+
2138
+ /**
2139
+ * Registers a plugin for this schema.
2140
+ *
2141
+ * #### Example:
2142
+ *
2143
+ * const s = new Schema({ name: String });
2144
+ * s.plugin(schema => console.log(schema.path('name').path));
2145
+ * mongoose.model('Test', s); // Prints 'name'
2146
+ *
2147
+ * Or with Options:
2148
+ *
2149
+ * const s = new Schema({ name: String });
2150
+ * s.plugin((schema, opts) => console.log(opts.text, schema.path('name').path), { text: "Schema Path Name:" });
2151
+ * mongoose.model('Test', s); // Prints 'Schema Path Name: name'
2152
+ *
2153
+ * @param {Function} plugin The Plugin's callback
2154
+ * @param {Object} [opts] Options to pass to the plugin
2155
+ * @param {Boolean} [opts.deduplicate=false] If true, ignore duplicate plugins (same `fn` argument using `===`)
2156
+ * @see plugins https://mongoosejs.com/docs/plugins.html
2157
+ * @api public
2158
+ */
2159
+
2160
+ Schema.prototype.plugin = function(fn, opts) {
2161
+ if (typeof fn !== 'function') {
2162
+ throw new Error('First param to `schema.plugin()` must be a function, ' +
2163
+ 'got "' + (typeof fn) + '"');
2164
+ }
2165
+
2166
+
2167
+ if (opts && opts.deduplicate) {
2168
+ for (const plugin of this.plugins) {
2169
+ if (plugin.fn === fn) {
2170
+ return this;
2171
+ }
2172
+ }
2173
+ }
2174
+ this.plugins.push({ fn: fn, opts: opts });
2175
+
2176
+ fn(this, opts);
2177
+ return this;
2178
+ };
2179
+
2180
+ /**
2181
+ * Adds an instance method to documents constructed from Models compiled from this schema.
2182
+ *
2183
+ * #### Example:
2184
+ *
2185
+ * const schema = kittySchema = new Schema(..);
2186
+ *
2187
+ * schema.method('meow', function () {
2188
+ * console.log('meeeeeoooooooooooow');
2189
+ * })
2190
+ *
2191
+ * const Kitty = mongoose.model('Kitty', schema);
2192
+ *
2193
+ * const fizz = new Kitty;
2194
+ * fizz.meow(); // meeeeeooooooooooooow
2195
+ *
2196
+ * If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as methods.
2197
+ *
2198
+ * schema.method({
2199
+ * purr: function () {}
2200
+ * , scratch: function () {}
2201
+ * });
2202
+ *
2203
+ * // later
2204
+ * const fizz = new Kitty;
2205
+ * fizz.purr();
2206
+ * fizz.scratch();
2207
+ *
2208
+ * NOTE: `Schema.method()` adds instance methods to the `Schema.methods` object. You can also add instance methods directly to the `Schema.methods` object as seen in the [guide](https://mongoosejs.com/docs/guide.html#methods)
2209
+ *
2210
+ * @param {String|Object} name The Method Name for a single function, or a Object of "string-function" pairs.
2211
+ * @param {Function} [fn] The Function in a single-function definition.
2212
+ * @api public
2213
+ */
2214
+
2215
+ Schema.prototype.method = function(name, fn, options) {
2216
+ if (typeof name !== 'string') {
2217
+ for (const i in name) {
2218
+ this.methods[i] = name[i];
2219
+ this.methodOptions[i] = clone(options);
2220
+ }
2221
+ } else {
2222
+ this.methods[name] = fn;
2223
+ this.methodOptions[name] = clone(options);
2224
+ }
2225
+ return this;
2226
+ };
2227
+
2228
+ /**
2229
+ * Adds static "class" methods to Models compiled from this schema.
2230
+ *
2231
+ * #### Example:
2232
+ *
2233
+ * const schema = new Schema(..);
2234
+ * // Equivalent to `schema.statics.findByName = function(name) {}`;
2235
+ * schema.static('findByName', function(name) {
2236
+ * return this.find({ name: name });
2237
+ * });
2238
+ *
2239
+ * const Drink = mongoose.model('Drink', schema);
2240
+ * await Drink.findByName('LaCroix');
2241
+ *
2242
+ * If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as methods.
2243
+ *
2244
+ * schema.static({
2245
+ * findByName: function () {..}
2246
+ * , findByCost: function () {..}
2247
+ * });
2248
+ *
2249
+ * const Drink = mongoose.model('Drink', schema);
2250
+ * await Drink.findByName('LaCroix');
2251
+ * await Drink.findByCost(3);
2252
+ *
2253
+ * If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as statics.
2254
+ *
2255
+ * @param {String|Object} name The Method Name for a single function, or a Object of "string-function" pairs.
2256
+ * @param {Function} [fn] The Function in a single-function definition.
2257
+ * @api public
2258
+ * @see Statics https://mongoosejs.com/docs/guide.html#statics
2259
+ */
2260
+
2261
+ Schema.prototype.static = function(name, fn) {
2262
+ if (typeof name !== 'string') {
2263
+ for (const i in name) {
2264
+ this.statics[i] = name[i];
2265
+ }
2266
+ } else {
2267
+ this.statics[name] = fn;
2268
+ }
2269
+ return this;
2270
+ };
2271
+
2272
+ /**
2273
+ * Defines an index (most likely compound) for this schema.
2274
+ *
2275
+ * #### Example:
2276
+ *
2277
+ * schema.index({ first: 1, last: -1 })
2278
+ *
2279
+ * @param {Object} fields The Fields to index, with the order, available values: `1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text'`
2280
+ * @param {Object} [options] Options to pass to [MongoDB driver's `createIndex()` function](https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#createIndex)
2281
+ * @param {String | number} [options.expires=null] Mongoose-specific syntactic sugar, uses [ms](https://www.npmjs.com/package/ms) to convert `expires` option into seconds for the `expireAfterSeconds` in the above link.
2282
+ * @param {String} [options.language_override=null] Tells mongodb to use the specified field instead of `language` for parsing text indexes.
2283
+ * @api public
2284
+ */
2285
+
2286
+ Schema.prototype.index = function(fields, options) {
2287
+ fields || (fields = {});
2288
+ options || (options = {});
2289
+
2290
+ if (options.expires) {
2291
+ utils.expires(options);
2292
+ }
2293
+ for (const key in fields) {
2294
+ if (this.aliases[key]) {
2295
+ fields = utils.renameObjKey(fields, key, this.aliases[key]);
2296
+ }
2297
+ }
2298
+ for (const field of Object.keys(fields)) {
2299
+ if (fields[field] === 'ascending' || fields[field] === 'asc') {
2300
+ fields[field] = 1;
2301
+ } else if (fields[field] === 'descending' || fields[field] === 'desc') {
2302
+ fields[field] = -1;
2303
+ }
2304
+ }
2305
+
2306
+ for (const existingIndex of this.indexes()) {
2307
+ if (options.name == null && existingIndex[1].name == null && isIndexSpecEqual(existingIndex[0], fields)) {
2308
+ utils.warn(`Duplicate schema index on ${JSON.stringify(fields)} found. This is often due to declaring an index using both "index: true" and "schema.index()". Please remove the duplicate index definition.`);
2309
+ }
2310
+ }
2311
+
2312
+ this._indexes.push([fields, options]);
2313
+ return this;
2314
+ };
2315
+
2316
+ /**
2317
+ * Sets a schema option.
2318
+ *
2319
+ * #### Example:
2320
+ *
2321
+ * schema.set('strict'); // 'true' by default
2322
+ * schema.set('strict', false); // Sets 'strict' to false
2323
+ * schema.set('strict'); // 'false'
2324
+ *
2325
+ * @param {String} key The name of the option to set the value to
2326
+ * @param {Object} [value] The value to set the option to, if not passed, the option will be reset to default
2327
+ * @param {Array<string>} [tags] tags to add to read preference if key === 'read'
2328
+ * @see Schema https://mongoosejs.com/docs/api/schema.html#Schema()
2329
+ * @api public
2330
+ */
2331
+
2332
+ Schema.prototype.set = function(key, value, tags) {
2333
+ if (arguments.length === 1) {
2334
+ return this.options[key];
2335
+ }
2336
+
2337
+ switch (key) {
2338
+ case 'read':
2339
+ if (typeof value === 'string') {
2340
+ this.options[key] = { mode: handleReadPreferenceAliases(value), tags };
2341
+ } else if (Array.isArray(value) && typeof value[0] === 'string') {
2342
+ this.options[key] = {
2343
+ mode: handleReadPreferenceAliases(value[0]),
2344
+ tags: value[1]
2345
+ };
2346
+ } else {
2347
+ this.options[key] = value;
2348
+ }
2349
+ this._userProvidedOptions[key] = this.options[key];
2350
+ break;
2351
+ case 'timestamps':
2352
+ this.setupTimestamp(value);
2353
+ this.options[key] = value;
2354
+ this._userProvidedOptions[key] = this.options[key];
2355
+ break;
2356
+ case '_id':
2357
+ this.options[key] = value;
2358
+ this._userProvidedOptions[key] = this.options[key];
2359
+
2360
+ if (value && !this.paths['_id']) {
2361
+ addAutoId(this);
2362
+ } else if (!value && this.paths['_id'] != null && this.paths['_id'].auto) {
2363
+ this.remove('_id');
2364
+ }
2365
+ break;
2366
+ default:
2367
+ this.options[key] = value;
2368
+ this._userProvidedOptions[key] = this.options[key];
2369
+ break;
2370
+ }
2371
+
2372
+ // Propagate `strict` and `strictQuery` changes down to implicitly created schemas
2373
+ if (key === 'strict') {
2374
+ _propagateOptionsToImplicitlyCreatedSchemas(this, { strict: value });
2375
+ }
2376
+ if (key === 'strictQuery') {
2377
+ _propagateOptionsToImplicitlyCreatedSchemas(this, { strictQuery: value });
2378
+ }
2379
+ if (key === 'toObject') {
2380
+ value = { ...value };
2381
+ // Avoid propagating transform to implicitly created schemas re: gh-3279
2382
+ delete value.transform;
2383
+ _propagateOptionsToImplicitlyCreatedSchemas(this, { toObject: value });
2384
+ }
2385
+ if (key === 'toJSON') {
2386
+ value = { ...value };
2387
+ // Avoid propagating transform to implicitly created schemas re: gh-3279
2388
+ delete value.transform;
2389
+ _propagateOptionsToImplicitlyCreatedSchemas(this, { toJSON: value });
2390
+ }
2391
+
2392
+ return this;
2393
+ };
2394
+
2395
+ /*!
2396
+ * Recursively set options on implicitly created schemas
2397
+ */
2398
+
2399
+ function _propagateOptionsToImplicitlyCreatedSchemas(baseSchema, options) {
2400
+ for (const { schema } of baseSchema.childSchemas) {
2401
+ if (!schema.$implicitlyCreated) {
2402
+ continue;
2403
+ }
2404
+ Object.assign(schema.options, options);
2405
+ _propagateOptionsToImplicitlyCreatedSchemas(schema, options);
2406
+ }
2407
+ }
2408
+
2409
+ /**
2410
+ * Gets a schema option.
2411
+ *
2412
+ * #### Example:
2413
+ *
2414
+ * schema.get('strict'); // true
2415
+ * schema.set('strict', false);
2416
+ * schema.get('strict'); // false
2417
+ *
2418
+ * @param {String} key The name of the Option to get the current value for
2419
+ * @api public
2420
+ * @return {Any} the option's value
2421
+ */
2422
+
2423
+ Schema.prototype.get = function(key) {
2424
+ return this.options[key];
2425
+ };
2426
+
2427
+ const indexTypes = '2d 2dsphere hashed text'.split(' ');
2428
+
2429
+ /**
2430
+ * The allowed index types
2431
+ *
2432
+ * @property {String[]} indexTypes
2433
+ * @memberOf Schema
2434
+ * @static
2435
+ * @api public
2436
+ */
2437
+
2438
+ Object.defineProperty(Schema, 'indexTypes', {
2439
+ get: function() {
2440
+ return indexTypes;
2441
+ },
2442
+ set: function() {
2443
+ throw new Error('Cannot overwrite Schema.indexTypes');
2444
+ }
2445
+ });
2446
+
2447
+ /**
2448
+ * Returns a list of indexes that this schema declares, via `schema.index()` or by `index: true` in a path's options.
2449
+ * Indexes are expressed as an array `[spec, options]`.
2450
+ *
2451
+ * #### Example:
2452
+ *
2453
+ * const userSchema = new Schema({
2454
+ * email: { type: String, required: true, unique: true },
2455
+ * registeredAt: { type: Date, index: true }
2456
+ * });
2457
+ *
2458
+ * // [ [ { email: 1 }, { unique: true, background: true } ],
2459
+ * // [ { registeredAt: 1 }, { background: true } ] ]
2460
+ * userSchema.indexes();
2461
+ *
2462
+ * [Plugins](https://mongoosejs.com/docs/plugins.html) can use the return value of this function to modify a schema's indexes.
2463
+ * For example, the below plugin makes every index unique by default.
2464
+ *
2465
+ * function myPlugin(schema) {
2466
+ * for (const index of schema.indexes()) {
2467
+ * if (index[1].unique === undefined) {
2468
+ * index[1].unique = true;
2469
+ * }
2470
+ * }
2471
+ * }
2472
+ *
2473
+ * @api public
2474
+ * @return {Array} list of indexes defined in the schema
2475
+ */
2476
+
2477
+ Schema.prototype.indexes = function() {
2478
+ return getIndexes(this);
2479
+ };
2480
+
2481
+ /**
2482
+ * Creates a virtual type with the given name.
2483
+ *
2484
+ * @param {String} name The name of the Virtual
2485
+ * @param {Object} [options]
2486
+ * @param {String|Model} [options.ref] model name or model instance. Marks this as a [populate virtual](https://mongoosejs.com/docs/populate.html#populate-virtuals).
2487
+ * @param {String|Function} [options.localField] Required for populate virtuals. See [populate virtual docs](https://mongoosejs.com/docs/populate.html#populate-virtuals) for more information.
2488
+ * @param {String|Function} [options.foreignField] Required for populate virtuals. See [populate virtual docs](https://mongoosejs.com/docs/populate.html#populate-virtuals) for more information.
2489
+ * @param {Boolean|Function} [options.justOne=false] Only works with populate virtuals. If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), will be a single doc or `null`. Otherwise, the populate virtual will be an array.
2490
+ * @param {Boolean} [options.count=false] Only works with populate virtuals. If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), this populate virtual will contain the number of documents rather than the documents themselves when you `populate()`.
2491
+ * @param {Function|null} [options.get=null] Adds a [getter](https://mongoosejs.com/docs/tutorials/getters-setters.html) to this virtual to transform the populated doc.
2492
+ * @param {Object|Function} [options.match=null] Apply a default [`match` option to populate](https://mongoosejs.com/docs/populate.html#match), adding an additional filter to the populate query.
2493
+ * @param {Boolean} [options.applyToArray=false] If true and the given `name` is a direct child of an array, apply the virtual to the array rather than the elements.
2494
+ * @return {VirtualType}
2495
+ */
2496
+
2497
+ Schema.prototype.virtual = function(name, options) {
2498
+ if (name instanceof VirtualType || getConstructorName(name) === 'VirtualType') {
2499
+ return this.virtual(name.path, name.options);
2500
+ }
2501
+ options = new VirtualOptions(options);
2502
+
2503
+ if (utils.hasUserDefinedProperty(options, ['ref', 'refPath'])) {
2504
+ if (options.localField == null) {
2505
+ throw new Error('Reference virtuals require `localField` option');
2506
+ }
2507
+
2508
+ if (options.foreignField == null) {
2509
+ throw new Error('Reference virtuals require `foreignField` option');
2510
+ }
2511
+
2512
+ const virtual = this.virtual(name);
2513
+ virtual.options = options;
2514
+
2515
+ this.pre('init', function virtualPreInit(obj, opts) {
2516
+ if (mpath.has(name, obj)) {
2517
+ const _v = mpath.get(name, obj);
2518
+ if (!this.$$populatedVirtuals) {
2519
+ this.$$populatedVirtuals = {};
2520
+ }
2521
+
2522
+ if (options.justOne || options.count) {
2523
+ this.$$populatedVirtuals[name] = Array.isArray(_v) ?
2524
+ _v[0] :
2525
+ _v;
2526
+ } else {
2527
+ this.$$populatedVirtuals[name] = Array.isArray(_v) ?
2528
+ _v :
2529
+ _v == null ? [] : [_v];
2530
+ }
2531
+
2532
+ if (opts?.hydratedPopulatedDocs && !options.count) {
2533
+ const modelNames = virtual._getModelNamesForPopulate(this);
2534
+ const populatedVal = this.$$populatedVirtuals[name];
2535
+ if (!Array.isArray(populatedVal) && !populatedVal.$__ && modelNames?.length === 1) {
2536
+ const PopulateModel = this.db.model(modelNames[0]);
2537
+ this.$$populatedVirtuals[name] = PopulateModel.hydrate(populatedVal);
2538
+ } else if (Array.isArray(populatedVal) && modelNames?.length === 1) {
2539
+ const PopulateModel = this.db.model(modelNames[0]);
2540
+ for (let i = 0; i < populatedVal.length; ++i) {
2541
+ if (!populatedVal[i].$__) {
2542
+ populatedVal[i] = PopulateModel.hydrate(populatedVal[i], null, { hydratedPopulatedDocs: true });
2543
+ }
2544
+ }
2545
+ const foreignField = options.foreignField;
2546
+ this.$populated(
2547
+ name,
2548
+ populatedVal.map(doc => doc == null ? doc : doc.get(typeof foreignField === 'function' ? foreignField.call(doc, doc) : foreignField)),
2549
+ { populateModelSymbol: PopulateModel }
2550
+ );
2551
+ }
2552
+ }
2553
+
2554
+ mpath.unset(name, obj);
2555
+ }
2556
+ });
2557
+
2558
+ virtual.
2559
+ set(function(v) {
2560
+ if (!this.$$populatedVirtuals) {
2561
+ this.$$populatedVirtuals = {};
2562
+ }
2563
+
2564
+ return setPopulatedVirtualValue(
2565
+ this.$$populatedVirtuals,
2566
+ name,
2567
+ v,
2568
+ options
2569
+ );
2570
+ });
2571
+
2572
+ if (typeof options.get === 'function') {
2573
+ virtual.get(options.get);
2574
+ }
2575
+
2576
+ // Workaround for gh-8198: if virtual is under document array, make a fake
2577
+ // virtual. See gh-8210, gh-13189
2578
+ const parts = name.split('.');
2579
+ let cur = parts[0];
2580
+ for (let i = 0; i < parts.length - 1; ++i) {
2581
+ if (this.paths[cur] == null) {
2582
+ continue;
2583
+ }
2584
+
2585
+ if (this.paths[cur].$isMongooseDocumentArray || this.paths[cur].$isSingleNested) {
2586
+ const remnant = parts.slice(i + 1).join('.');
2587
+ this.paths[cur].schema.virtual(remnant, options);
2588
+ break;
2589
+ } else if (this.paths[cur].$isSchemaMap) {
2590
+ const remnant = parts.slice(i + 2).join('.');
2591
+ this.paths[cur].$__schemaType.schema.virtual(remnant, options);
2592
+ break;
2593
+ }
2594
+
2595
+ cur += '.' + parts[i + 1];
2596
+ }
2597
+
2598
+ return virtual;
2599
+ }
2600
+
2601
+ const virtuals = this.virtuals;
2602
+ const parts = name.split('.');
2603
+
2604
+ if (this.pathType(name) === 'real') {
2605
+ throw new Error('Virtual path "' + name + '"' +
2606
+ ' conflicts with a real path in the schema');
2607
+ }
2608
+
2609
+ virtuals[name] = parts.reduce(function(mem, part, i) {
2610
+ mem[part] || (mem[part] = (i === parts.length - 1)
2611
+ ? new VirtualType(options, name)
2612
+ : {});
2613
+ return mem[part];
2614
+ }, this.tree);
2615
+
2616
+ if (options && options.applyToArray && parts.length > 1) {
2617
+ const path = this.path(parts.slice(0, -1).join('.'));
2618
+ if (path && path.$isMongooseArray) {
2619
+ return path.virtual(parts[parts.length - 1], options);
2620
+ } else {
2621
+ throw new MongooseError(`Path "${path}" is not an array`);
2622
+ }
2623
+ }
2624
+
2625
+ return virtuals[name];
2626
+ };
2627
+
2628
+ /**
2629
+ * Returns the virtual type with the given `name`.
2630
+ *
2631
+ * @param {String} name The name of the Virtual to get
2632
+ * @return {VirtualType|null}
2633
+ */
2634
+
2635
+ Schema.prototype.virtualpath = function(name) {
2636
+ return Object.hasOwn(this.virtuals, name) ? this.virtuals[name] : null;
2637
+ };
2638
+
2639
+ /**
2640
+ * Removes the given `path` (or [`paths`]).
2641
+ *
2642
+ * #### Example:
2643
+ *
2644
+ * const schema = new Schema({ name: String, age: Number });
2645
+ * schema.remove('name');
2646
+ * schema.path('name'); // Undefined
2647
+ * schema.path('age'); // SchemaNumber { ... }
2648
+ *
2649
+ * Or as a Array:
2650
+ *
2651
+ * schema.remove(['name', 'age']);
2652
+ * schema.path('name'); // Undefined
2653
+ * schema.path('age'); // Undefined
2654
+ *
2655
+ * @param {String|Array} path The Path(s) to remove
2656
+ * @return {Schema} the Schema instance
2657
+ * @api public
2658
+ */
2659
+ Schema.prototype.remove = function(path) {
2660
+ if (typeof path === 'string') {
2661
+ path = [path];
2662
+ }
2663
+ if (Array.isArray(path)) {
2664
+ path.forEach(function(name) {
2665
+ if (this.path(name) == null && !this.nested[name]) {
2666
+ return;
2667
+ }
2668
+ if (this.nested[name]) {
2669
+ const allKeys = Object.keys(this.paths).
2670
+ concat(Object.keys(this.nested));
2671
+ for (const path of allKeys) {
2672
+ if (path.startsWith(name + '.')) {
2673
+ delete this.paths[path];
2674
+ delete this.nested[path];
2675
+ _deletePath(this, path);
2676
+ }
2677
+ }
2678
+
2679
+ delete this.nested[name];
2680
+ _deletePath(this, name);
2681
+ return;
2682
+ }
2683
+
2684
+ delete this.paths[name];
2685
+ _deletePath(this, name);
2686
+
2687
+ this._removeEncryptedField(name);
2688
+ }, this);
2689
+ }
2690
+ return this;
2691
+ };
2692
+
2693
+ /*!
2694
+ * ignore
2695
+ */
2696
+
2697
+ function _deletePath(schema, name) {
2698
+ const pieces = name.split('.');
2699
+ const last = pieces.pop();
2700
+
2701
+ let branch = schema.tree;
2702
+
2703
+ for (const piece of pieces) {
2704
+ branch = branch[piece];
2705
+ }
2706
+
2707
+ delete branch[last];
2708
+ }
2709
+
2710
+ /**
2711
+ * Removes the given virtual or virtuals from the schema.
2712
+ *
2713
+ * @param {String|Array} path The virutal path(s) to remove.
2714
+ * @returns {Schema} the Schema instance, or a mongoose error if the virtual does not exist.
2715
+ * @api public
2716
+ */
2717
+
2718
+ Schema.prototype.removeVirtual = function(path) {
2719
+ if (typeof path === 'string') {
2720
+ path = [path];
2721
+ }
2722
+ if (Array.isArray(path)) {
2723
+ for (const virtual of path) {
2724
+ if (this.virtuals[virtual] == null) {
2725
+ throw new MongooseError(`Attempting to remove virtual "${virtual}" that does not exist.`);
2726
+ }
2727
+ }
2728
+
2729
+ for (const virtual of path) {
2730
+ delete this.paths[virtual];
2731
+ delete this.virtuals[virtual];
2732
+ if (virtual.indexOf('.') !== -1) {
2733
+ mpath.unset(virtual, this.tree);
2734
+ } else {
2735
+ delete this.tree[virtual];
2736
+ }
2737
+ }
2738
+ }
2739
+ return this;
2740
+ };
2741
+
2742
+ /**
2743
+ * Loads an ES6 class into a schema. Maps [setters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set) + [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get), [static methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static),
2744
+ * and [instance methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Class_body_and_method_definitions)
2745
+ * to schema [virtuals](https://mongoosejs.com/docs/guide.html#virtuals),
2746
+ * [statics](https://mongoosejs.com/docs/guide.html#statics), and
2747
+ * [methods](https://mongoosejs.com/docs/guide.html#methods).
2748
+ *
2749
+ * #### Example:
2750
+ *
2751
+ * ```javascript
2752
+ * const md5 = require('md5');
2753
+ * const userSchema = new Schema({ email: String });
2754
+ * class UserClass {
2755
+ * // `gravatarImage` becomes a virtual
2756
+ * get gravatarImage() {
2757
+ * const hash = md5(this.email.toLowerCase());
2758
+ * return `https://www.gravatar.com/avatar/${hash}`;
2759
+ * }
2760
+ *
2761
+ * // `getProfileUrl()` becomes a document method
2762
+ * getProfileUrl() {
2763
+ * return `https://mysite.com/${this.email}`;
2764
+ * }
2765
+ *
2766
+ * // `findByEmail()` becomes a static
2767
+ * static findByEmail(email) {
2768
+ * return this.findOne({ email });
2769
+ * }
2770
+ * }
2771
+ *
2772
+ * // `schema` will now have a `gravatarImage` virtual, a `getProfileUrl()` method,
2773
+ * // and a `findByEmail()` static
2774
+ * userSchema.loadClass(UserClass);
2775
+ * ```
2776
+ *
2777
+ * @param {Function} model The Class to load
2778
+ * @param {Boolean} [virtualsOnly] if truthy, only pulls virtuals from the class, not methods or statics
2779
+ */
2780
+ Schema.prototype.loadClass = function(model, virtualsOnly) {
2781
+ // Stop copying when hit certain base classes
2782
+ if (model === Object.prototype ||
2783
+ model === Function.prototype ||
2784
+ Object.hasOwn(model.prototype, '$isMongooseModelPrototype') ||
2785
+ Object.hasOwn(model.prototype, '$isMongooseDocumentPrototype')) {
2786
+ return this;
2787
+ }
2788
+
2789
+ this.loadClass(Object.getPrototypeOf(model), virtualsOnly);
2790
+
2791
+ // Add static methods
2792
+ if (!virtualsOnly) {
2793
+ Object.getOwnPropertyNames(model).forEach(function(name) {
2794
+ if (name.match(/^(length|name|prototype|constructor|__proto__)$/)) {
2795
+ return;
2796
+ }
2797
+ const prop = Object.getOwnPropertyDescriptor(model, name);
2798
+ if (Object.hasOwn(prop, 'value')) {
2799
+ this.static(name, prop.value);
2800
+ }
2801
+ }, this);
2802
+ }
2803
+
2804
+ // Add methods and virtuals
2805
+ Object.getOwnPropertyNames(model.prototype).forEach(function(name) {
2806
+ if (name.match(/^(constructor)$/)) {
2807
+ return;
2808
+ }
2809
+ const method = Object.getOwnPropertyDescriptor(model.prototype, name);
2810
+ if (!virtualsOnly) {
2811
+ if (typeof method.value === 'function') {
2812
+ this.method(name, method.value);
2813
+ }
2814
+ }
2815
+ if (typeof method.get === 'function') {
2816
+ if (this.virtuals[name]) {
2817
+ this.virtuals[name].getters = [];
2818
+ }
2819
+ this.virtual(name).get(method.get);
2820
+ }
2821
+ if (typeof method.set === 'function') {
2822
+ if (this.virtuals[name]) {
2823
+ this.virtuals[name].setters = [];
2824
+ }
2825
+ this.virtual(name).set(method.set);
2826
+ }
2827
+ }, this);
2828
+
2829
+ return this;
2830
+ };
2831
+
2832
+ /*!
2833
+ * ignore
2834
+ */
2835
+
2836
+ Schema.prototype._getSchema = function(path) {
2837
+ const _this = this;
2838
+ const pathschema = _this.path(path);
2839
+ const resultPath = [];
2840
+
2841
+ if (pathschema) {
2842
+ pathschema.$fullPath = path;
2843
+ return pathschema;
2844
+ }
2845
+
2846
+ function search(parts, schema) {
2847
+ let p = parts.length + 1;
2848
+ let foundschema;
2849
+ let trypath;
2850
+
2851
+ while (p--) {
2852
+ trypath = parts.slice(0, p).join('.');
2853
+ foundschema = schema.path(trypath);
2854
+ if (foundschema) {
2855
+ resultPath.push(trypath);
2856
+
2857
+ if (foundschema.caster) {
2858
+ // array of Mixed?
2859
+ if (foundschema.caster instanceof MongooseTypes.Mixed) {
2860
+ foundschema.caster.$fullPath = resultPath.join('.');
2861
+ return foundschema.caster;
2862
+ }
2863
+
2864
+ // Now that we found the array, we need to check if there
2865
+ // are remaining document paths to look up for casting.
2866
+ // Also we need to handle array.$.path since schema.path
2867
+ // doesn't work for that.
2868
+ // If there is no foundschema.schema we are dealing with
2869
+ // a path like array.$
2870
+ if (p !== parts.length) {
2871
+ if (p + 1 === parts.length && foundschema.$embeddedSchemaType && (parts[p] === '$' || isArrayFilter(parts[p]))) {
2872
+ return foundschema.$embeddedSchemaType;
2873
+ }
2874
+
2875
+ if (foundschema.schema) {
2876
+ let ret;
2877
+ if (parts[p] === '$' || isArrayFilter(parts[p])) {
2878
+ if (p + 1 === parts.length) {
2879
+ // comments.$
2880
+ return foundschema.$embeddedSchemaType;
2881
+ }
2882
+ // comments.$.comments.$.title
2883
+ ret = search(parts.slice(p + 1), foundschema.schema);
2884
+ if (ret) {
2885
+ ret.$parentSchemaDocArray = ret.$parentSchemaDocArray ||
2886
+ (foundschema.schema.$isSingleNested ? null : foundschema);
2887
+ }
2888
+ return ret;
2889
+ }
2890
+ // this is the last path of the selector
2891
+ ret = search(parts.slice(p), foundschema.schema);
2892
+ if (ret) {
2893
+ ret.$parentSchemaDocArray = ret.$parentSchemaDocArray ||
2894
+ (foundschema.schema.$isSingleNested ? null : foundschema);
2895
+ }
2896
+ return ret;
2897
+ }
2898
+ }
2899
+ } else if (foundschema.$isSchemaMap) {
2900
+ if (p >= parts.length) {
2901
+ return foundschema;
2902
+ }
2903
+ // Any path in the map will be an instance of the map's embedded schematype
2904
+ if (p + 1 >= parts.length) {
2905
+ return foundschema.$__schemaType;
2906
+ }
2907
+
2908
+ if (foundschema.$__schemaType instanceof MongooseTypes.Mixed) {
2909
+ return foundschema.$__schemaType;
2910
+ }
2911
+ if (foundschema.$__schemaType.schema != null) {
2912
+ // Map of docs
2913
+ const ret = search(parts.slice(p + 1), foundschema.$__schemaType.schema);
2914
+ return ret;
2915
+ }
2916
+ }
2917
+
2918
+ foundschema.$fullPath = resultPath.join('.');
2919
+
2920
+ return foundschema;
2921
+ }
2922
+ }
2923
+ }
2924
+
2925
+ // look for arrays
2926
+ const parts = path.split('.');
2927
+ for (let i = 0; i < parts.length; ++i) {
2928
+ if (parts[i] === '$' || isArrayFilter(parts[i])) {
2929
+ // Re: gh-5628, because `schema.path()` doesn't take $ into account.
2930
+ parts[i] = '0';
2931
+ }
2932
+ if (numberRE.test(parts[i])) {
2933
+ parts[i] = '$';
2934
+ }
2935
+ }
2936
+ return search(parts, _this);
2937
+ };
2938
+
2939
+ /*!
2940
+ * ignore
2941
+ */
2942
+
2943
+ Schema.prototype._getPathType = function(path) {
2944
+ const _this = this;
2945
+ const pathschema = _this.path(path);
2946
+
2947
+ if (pathschema) {
2948
+ return 'real';
2949
+ }
2950
+
2951
+ function search(parts, schema) {
2952
+ let p = parts.length + 1,
2953
+ foundschema,
2954
+ trypath;
2955
+
2956
+ while (p--) {
2957
+ trypath = parts.slice(0, p).join('.');
2958
+ foundschema = schema.path(trypath);
2959
+ if (foundschema) {
2960
+ if (foundschema.caster) {
2961
+ // array of Mixed?
2962
+ if (foundschema.caster instanceof MongooseTypes.Mixed) {
2963
+ return { schema: foundschema, pathType: 'mixed' };
2964
+ }
2965
+
2966
+ // Now that we found the array, we need to check if there
2967
+ // are remaining document paths to look up for casting.
2968
+ // Also we need to handle array.$.path since schema.path
2969
+ // doesn't work for that.
2970
+ // If there is no foundschema.schema we are dealing with
2971
+ // a path like array.$
2972
+ if (p !== parts.length && foundschema.schema) {
2973
+ if (parts[p] === '$' || isArrayFilter(parts[p])) {
2974
+ if (p === parts.length - 1) {
2975
+ return { schema: foundschema, pathType: 'nested' };
2976
+ }
2977
+ // comments.$.comments.$.title
2978
+ return search(parts.slice(p + 1), foundschema.schema);
2979
+ }
2980
+ // this is the last path of the selector
2981
+ return search(parts.slice(p), foundschema.schema);
2982
+ }
2983
+ return {
2984
+ schema: foundschema,
2985
+ pathType: foundschema.$isSingleNested ? 'nested' : 'array'
2986
+ };
2987
+ }
2988
+ return { schema: foundschema, pathType: 'real' };
2989
+ } else if (p === parts.length && schema.nested[trypath]) {
2990
+ return { schema: schema, pathType: 'nested' };
2991
+ }
2992
+ }
2993
+ return { schema: foundschema || schema, pathType: 'undefined' };
2994
+ }
2995
+
2996
+ // look for arrays
2997
+ return search(path.split('.'), _this);
2998
+ };
2999
+
3000
+ /**
3001
+ * Transforms the duplicate key error by checking for duplicate key error messages by path.
3002
+ * If no duplicate key error messages are found, returns the original error.
3003
+ *
3004
+ * @param {Error} error The error to transform
3005
+ * @returns {Error} The transformed error
3006
+ * @api private
3007
+ */
3008
+
3009
+ Schema.prototype._transformDuplicateKeyError = function _transformDuplicateKeyError(error) {
3010
+ if (!this._duplicateKeyErrorMessagesByPath) {
3011
+ return error;
3012
+ }
3013
+ if (error.code !== 11000 && error.code !== 11001) {
3014
+ return error;
3015
+ }
3016
+
3017
+ if (error.keyPattern != null) {
3018
+ const keyPattern = error.keyPattern;
3019
+ const keys = Object.keys(keyPattern);
3020
+ if (keys.length !== 1) {
3021
+ return error;
3022
+ }
3023
+ const firstKey = keys[0];
3024
+ if (!Object.hasOwn(this._duplicateKeyErrorMessagesByPath, firstKey)) {
3025
+ return error;
3026
+ }
3027
+ return new MongooseError(this._duplicateKeyErrorMessagesByPath[firstKey], { cause: error });
3028
+ }
3029
+
3030
+ return error;
3031
+ };
3032
+
3033
+ /*!
3034
+ * ignore
3035
+ */
3036
+
3037
+ function isArrayFilter(piece) {
3038
+ return piece.startsWith('$[') && piece.endsWith(']');
3039
+ }
3040
+
3041
+ /**
3042
+ * Called by `compile()` _right before_ compiling. Good for making any changes to
3043
+ * the schema that should respect options set by plugins, like `id`
3044
+ * @method _preCompile
3045
+ * @memberOf Schema
3046
+ * @instance
3047
+ * @api private
3048
+ */
3049
+
3050
+ Schema.prototype._preCompile = function _preCompile() {
3051
+ this.plugin(idGetter, { deduplicate: true });
3052
+ };
3053
+
3054
+ /**
3055
+ * Returns a JSON schema representation of this Schema.
3056
+ *
3057
+ * By default, returns normal [JSON schema representation](https://json-schema.org/learn/getting-started-step-by-step), which is not typically what you want to use with
3058
+ * [MongoDB's `$jsonSchema` collection option](https://www.mongodb.com/docs/manual/core/schema-validation/specify-json-schema/).
3059
+ * Use the `useBsonType: true` option to return MongoDB `$jsonSchema` syntax instead.
3060
+ *
3061
+ * In addition to types, `jsonSchema()` supports the following Mongoose validators:
3062
+ * - `enum` for strings and numbers
3063
+ *
3064
+ * #### Example:
3065
+ * const schema = new Schema({ name: String });
3066
+ * // { required: ['_id'], properties: { name: { type: ['string', 'null'] }, _id: { type: 'string' } } }
3067
+ * schema.toJSONSchema();
3068
+ *
3069
+ * // { required: ['_id'], properties: { name: { bsonType: ['string', 'null'] }, _id: { bsonType: 'objectId' } } }
3070
+ * schema.toJSONSchema({ useBsonType: true });
3071
+ *
3072
+ * @param {Object} [options]
3073
+ * @param [Boolean] [options.useBsonType=false] if true, specify each path's type using `bsonType` rather than `type` for MongoDB $jsonSchema support
3074
+ */
3075
+
3076
+ Schema.prototype.toJSONSchema = function toJSONSchema(options) {
3077
+ const useBsonType = options?.useBsonType ?? false;
3078
+ const result = useBsonType ? { required: [], properties: {} } : { type: 'object', required: [], properties: {} };
3079
+ for (const path of Object.keys(this.paths)) {
3080
+ const schemaType = this.paths[path];
3081
+
3082
+ // Skip Map embedded paths, maps will be handled seperately.
3083
+ if (schemaType._presplitPath.indexOf('$*') !== -1) {
3084
+ continue;
3085
+ }
3086
+
3087
+ // Nested paths are stored as `nested.path` in the schema type, so create nested paths in the json schema
3088
+ // when necessary.
3089
+ const isNested = schemaType._presplitPath.length > 1;
3090
+ let jsonSchemaForPath = result;
3091
+ if (isNested) {
3092
+ for (let i = 0; i < schemaType._presplitPath.length - 1; ++i) {
3093
+ const subpath = schemaType._presplitPath[i];
3094
+ if (jsonSchemaForPath.properties[subpath] == null) {
3095
+ jsonSchemaForPath.properties[subpath] = useBsonType
3096
+ ? {
3097
+ bsonType: ['object', 'null'],
3098
+ properties: {}
3099
+ }
3100
+ : {
3101
+ type: ['object', 'null'],
3102
+ properties: {}
3103
+ };
3104
+ }
3105
+ jsonSchemaForPath = jsonSchemaForPath.properties[subpath];
3106
+ }
3107
+ }
3108
+
3109
+ const lastSubpath = schemaType._presplitPath[schemaType._presplitPath.length - 1];
3110
+ let isRequired = false;
3111
+ if (path === '_id') {
3112
+ if (!jsonSchemaForPath.required) {
3113
+ jsonSchemaForPath.required = [];
3114
+ }
3115
+ jsonSchemaForPath.required.push('_id');
3116
+ isRequired = true;
3117
+ } else if (schemaType.options.required && typeof schemaType.options.required !== 'function') {
3118
+ if (!jsonSchemaForPath.required) {
3119
+ jsonSchemaForPath.required = [];
3120
+ }
3121
+ // Only `required: true` paths are required, conditional required is not required
3122
+ jsonSchemaForPath.required.push(lastSubpath);
3123
+ isRequired = true;
3124
+ }
3125
+ jsonSchemaForPath.properties[lastSubpath] = schemaType.toJSONSchema(options);
3126
+ if (schemaType.options.enum) {
3127
+ jsonSchemaForPath.properties[lastSubpath].enum = isRequired
3128
+ ? schemaType.options.enum
3129
+ : [...schemaType.options.enum, null];
3130
+ }
3131
+ }
3132
+
3133
+ // Otherwise MongoDB errors with "$jsonSchema keyword 'required' cannot be an empty array"
3134
+ if (result.required.length === 0) {
3135
+ delete result.required;
3136
+ }
3137
+ return result;
3138
+ };
3139
+
3140
+ /*!
3141
+ * Module exports.
3142
+ */
3143
+
3144
+ module.exports = exports = Schema;
3145
+
3146
+ // require down here because of reference issues
3147
+
3148
+ /**
3149
+ * The various built-in Mongoose Schema Types.
3150
+ *
3151
+ * #### Example:
3152
+ *
3153
+ * const mongoose = require('mongoose');
3154
+ * const ObjectId = mongoose.Schema.Types.ObjectId;
3155
+ *
3156
+ * #### Types:
3157
+ *
3158
+ * - [String](https://mongoosejs.com/docs/schematypes.html#strings)
3159
+ * - [Number](https://mongoosejs.com/docs/schematypes.html#numbers)
3160
+ * - [Boolean](https://mongoosejs.com/docs/schematypes.html#booleans) | Bool
3161
+ * - [Array](https://mongoosejs.com/docs/schematypes.html#arrays)
3162
+ * - [Buffer](https://mongoosejs.com/docs/schematypes.html#buffers)
3163
+ * - [Date](https://mongoosejs.com/docs/schematypes.html#dates)
3164
+ * - [ObjectId](https://mongoosejs.com/docs/schematypes.html#objectids) | Oid
3165
+ * - [Mixed](https://mongoosejs.com/docs/schematypes.html#mixed)
3166
+ * - [UUID](https://mongoosejs.com/docs/schematypes.html#uuid)
3167
+ * - [BigInt](https://mongoosejs.com/docs/schematypes.html#bigint)
3168
+ * - [Double] (https://mongoosejs.com/docs/schematypes.html#double)
3169
+ * - [Int32](https://mongoosejs.com/docs/schematypes.html#int32)
3170
+ *
3171
+ * Using this exposed access to the `Mixed` SchemaType, we can use them in our schema.
3172
+ *
3173
+ * const Mixed = mongoose.Schema.Types.Mixed;
3174
+ * new mongoose.Schema({ _user: Mixed })
3175
+ *
3176
+ * @api public
3177
+ */
3178
+
3179
+ Schema.Types = MongooseTypes = require('./schema/index');
3180
+
3181
+ /*!
3182
+ * ignore
3183
+ */
3184
+
3185
+ exports.ObjectId = MongooseTypes.ObjectId;