@nullix/zod-mongoose-studio 1.0.12 → 2.0.0
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.
- package/.output/nitro.json +1 -1
- package/.output/public/_nuxt/{Db4IAypj.js → 0J_bLG6U.js} +1 -1
- package/.output/public/_nuxt/{Y39o1QEi.js → 5KLjKHc1.js} +1 -1
- package/.output/public/_nuxt/{B4zoPYF-.js → B2UrsJHg.js} +1 -1
- package/.output/public/_nuxt/{BSqjh6Vk.js → BC5hGokz.js} +1 -1
- package/.output/public/_nuxt/{BS4yU4O0.js → BJwN20Xm.js} +1 -1
- package/.output/public/_nuxt/{D8_n84hl.js → BMgDPqps.js} +1 -1
- package/.output/public/_nuxt/{CqNsQbt9.js → B_sGF2qN.js} +1 -1
- package/.output/public/_nuxt/{NAqlztEN.js → BeaJ7I-K.js} +10 -10
- package/.output/public/_nuxt/{WZ0WK9cR.js → BkE1sm_1.js} +1 -1
- package/.output/public/_nuxt/{kBtP64Rx.js → CADbZwE5.js} +1 -1
- package/.output/public/_nuxt/{B8qGaxNm.js → CB0WRoVi.js} +1 -1
- package/.output/public/_nuxt/{BV6uALfO.js → CCh0PVV0.js} +1 -1
- package/.output/public/_nuxt/{CP9Z7-_9.js → Cr0GW7rA.js} +1 -1
- package/.output/public/_nuxt/{DeCqoVOS.js → DJe7Wxdv.js} +1 -1
- package/.output/public/_nuxt/{dBZQW7JD.js → DRBrUaE5.js} +1 -1
- package/.output/public/_nuxt/{Db19R32y.js → DV2n9B6m.js} +1 -1
- package/.output/public/_nuxt/{CvnpbYw0.js → DVD-jGiv.js} +1 -1
- package/.output/public/_nuxt/{BWajNATZ.js → Dk9qGA5X.js} +3 -3
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/dc761332-547d-4953-b51d-b2d453009b48.json +1 -0
- package/.output/public/_nuxt/error-404.64pZEiDn.css +1 -0
- package/.output/public/_nuxt/error-500.DHOpI0Ir.css +1 -0
- package/.output/public/_nuxt/{BoHhCIKW.js → koEZfutw.js} +3 -3
- package/.output/public/_nuxt/{B_782F4p.js → r6LdR7DN.js} +1 -1
- package/.output/public/_nuxt/{BEI71c6K.js → rEfOp38p.js} +1 -1
- package/.output/server/chunks/_/error-500.mjs.map +1 -1
- package/.output/server/chunks/build/client.precomputed.mjs +1 -1
- package/.output/server/chunks/build/{error-404-8tbBXju4.mjs → error-404-BN-7rNE4.mjs} +4 -4
- package/.output/server/chunks/build/error-404-BN-7rNE4.mjs.map +1 -0
- package/.output/server/chunks/build/error-404-styles.Byx46oLR.mjs +8 -0
- package/.output/server/chunks/build/error-404-styles.Byx46oLR.mjs.map +1 -0
- package/.output/server/chunks/build/{error-500-DxFsom1i.mjs → error-500-DhIQ-2yt.mjs} +4 -4
- package/.output/server/chunks/build/error-500-DhIQ-2yt.mjs.map +1 -0
- package/.output/server/chunks/build/error-500-styles.BL3UT0Wa.mjs +8 -0
- package/.output/server/chunks/build/error-500-styles.BL3UT0Wa.mjs.map +1 -0
- package/.output/server/chunks/build/{index-BB-Clavm.mjs → index-Dnrh1ePF.mjs} +1 -1
- package/.output/server/chunks/build/index-Dnrh1ePF.mjs.map +1 -0
- package/.output/server/chunks/build/server.mjs +9 -9
- package/.output/server/chunks/build/styles.mjs +4 -4
- package/.output/server/chunks/nitro/nitro.mjs +342 -342
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
- package/.output/server/chunks/routes/renderer.mjs.map +1 -1
- package/.output/server/node_modules/bson/lib/bson.cjs +157 -48
- package/.output/server/node_modules/bson/package.json +9 -11
- package/.output/server/node_modules/kareem/index.js +228 -343
- package/.output/server/node_modules/kareem/package.json +3 -3
- package/.output/server/node_modules/mongodb/lib/bson.js +27 -5
- package/.output/server/node_modules/mongodb/lib/bulk/common.js +7 -9
- package/.output/server/node_modules/mongodb/lib/change_stream.js +91 -39
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/auto_encrypter.js +21 -14
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/client_encryption.js +2 -5
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/errors.js +3 -1
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/mongocryptd_manager.js +1 -1
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/state_machine.js +1 -0
- package/.output/server/node_modules/mongodb/lib/cmap/auth/aws4.js +161 -0
- package/.output/server/node_modules/mongodb/lib/cmap/auth/aws_temporary_credentials.js +11 -58
- package/.output/server/node_modules/mongodb/lib/cmap/auth/gssapi.js +4 -6
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongo_credentials.js +2 -16
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_aws.js +14 -23
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +4 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +4 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc.js +4 -4
- package/.output/server/node_modules/mongodb/lib/cmap/auth/plain.js +1 -1
- package/.output/server/node_modules/mongodb/lib/cmap/auth/providers.js +0 -1
- package/.output/server/node_modules/mongodb/lib/cmap/auth/scram.js +53 -40
- package/.output/server/node_modules/mongodb/lib/cmap/commands.js +46 -39
- package/.output/server/node_modules/mongodb/lib/cmap/connect.js +35 -3
- package/.output/server/node_modules/mongodb/lib/cmap/connection.js +36 -32
- package/.output/server/node_modules/mongodb/lib/cmap/connection_pool.js +67 -67
- package/.output/server/node_modules/mongodb/lib/cmap/connection_pool_events.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/errors.js +1 -1
- package/.output/server/node_modules/mongodb/lib/cmap/handshake/client_metadata.js +15 -13
- package/.output/server/node_modules/mongodb/lib/cmap/metrics.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/compression.js +26 -10
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/constants.js +3 -1
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_data.js +0 -1
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_demand/document.js +9 -9
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/responses.js +2 -2
- package/.output/server/node_modules/mongodb/lib/collection.js +1 -1
- package/.output/server/node_modules/mongodb/lib/connection_string.js +30 -15
- package/.output/server/node_modules/mongodb/lib/cursor/abstract_cursor.js +17 -34
- package/.output/server/node_modules/mongodb/lib/cursor/change_stream_cursor.js +2 -2
- package/.output/server/node_modules/mongodb/lib/cursor/find_cursor.js +37 -26
- package/.output/server/node_modules/mongodb/lib/cursor/run_command_cursor.js +1 -1
- package/.output/server/node_modules/mongodb/lib/db.js +6 -7
- package/.output/server/node_modules/mongodb/lib/deps.js +0 -13
- package/.output/server/node_modules/mongodb/lib/error.js +7 -10
- package/.output/server/node_modules/mongodb/lib/gridfs/download.js +7 -6
- package/.output/server/node_modules/mongodb/lib/gridfs/index.js +9 -9
- package/.output/server/node_modules/mongodb/lib/gridfs/upload.js +17 -23
- package/.output/server/node_modules/mongodb/lib/index.js +2 -4
- package/.output/server/node_modules/mongodb/lib/mongo_client.js +58 -67
- package/.output/server/node_modules/mongodb/lib/mongo_client_auth_providers.js +0 -6
- package/.output/server/node_modules/mongodb/lib/mongo_logger.js +11 -5
- package/.output/server/node_modules/mongodb/lib/mongo_types.js +1 -2
- package/.output/server/node_modules/mongodb/lib/operations/aggregate.js +0 -3
- package/.output/server/node_modules/mongodb/lib/operations/create_collection.js +0 -1
- package/.output/server/node_modules/mongodb/lib/operations/drop.js +8 -9
- package/.output/server/node_modules/mongodb/lib/operations/end_sessions.js +34 -0
- package/.output/server/node_modules/mongodb/lib/operations/execute_operation.js +121 -45
- package/.output/server/node_modules/mongodb/lib/operations/operation.js +1 -0
- package/.output/server/node_modules/mongodb/lib/read_preference.js +10 -14
- package/.output/server/node_modules/mongodb/lib/runtime_adapters.js +32 -0
- package/.output/server/node_modules/mongodb/lib/sdam/monitor.js +8 -8
- package/.output/server/node_modules/mongodb/lib/sdam/server.js +55 -43
- package/.output/server/node_modules/mongodb/lib/sdam/server_description.js +1 -1
- package/.output/server/node_modules/mongodb/lib/sdam/server_selection.js +135 -72
- package/.output/server/node_modules/mongodb/lib/sdam/srv_polling.js +3 -3
- package/.output/server/node_modules/mongodb/lib/sdam/topology.js +37 -77
- package/.output/server/node_modules/mongodb/lib/sdam/topology_description.js +1 -1
- package/.output/server/node_modules/mongodb/lib/sessions.js +150 -40
- package/.output/server/node_modules/mongodb/lib/transactions.js +2 -13
- package/.output/server/node_modules/mongodb/lib/utils.js +42 -90
- package/.output/server/node_modules/mongodb/package.json +49 -45
- package/.output/server/node_modules/mongodb-connection-string-url/lib/index.js +45 -19
- package/.output/server/node_modules/mongodb-connection-string-url/lib/redact.js +30 -19
- package/.output/server/node_modules/mongodb-connection-string-url/package.json +25 -16
- package/.output/server/node_modules/mongoose/lib/aggregate.js +108 -127
- package/.output/server/node_modules/mongoose/lib/cast/bigint.js +3 -3
- package/.output/server/node_modules/mongoose/lib/cast/boolean.js +3 -3
- package/.output/server/node_modules/mongoose/lib/cast/double.js +4 -4
- package/.output/server/node_modules/mongoose/lib/cast/int32.js +2 -2
- package/.output/server/node_modules/mongoose/lib/cast/number.js +6 -6
- package/.output/server/node_modules/mongoose/lib/cast/string.js +3 -3
- package/.output/server/node_modules/mongoose/lib/cast/uuid.js +5 -48
- package/.output/server/node_modules/mongoose/lib/cast.js +16 -24
- package/.output/server/node_modules/mongoose/lib/collection.js +6 -6
- package/.output/server/node_modules/mongoose/lib/connection.js +108 -105
- package/.output/server/node_modules/mongoose/lib/cursor/aggregationCursor.js +23 -33
- package/.output/server/node_modules/mongoose/lib/cursor/changeStream.js +60 -40
- package/.output/server/node_modules/mongoose/lib/cursor/queryCursor.js +21 -25
- package/.output/server/node_modules/mongoose/lib/document.js +712 -531
- package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js +85 -130
- package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js +32 -41
- package/.output/server/node_modules/mongoose/lib/error/cast.js +21 -12
- package/.output/server/node_modules/mongoose/lib/error/createCollectionsError.js +2 -2
- package/.output/server/node_modules/mongoose/lib/error/divergentArray.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/eachAsyncMultiError.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/index.js +3 -3
- package/.output/server/node_modules/mongoose/lib/error/invalidSchemaOption.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/messages.js +1 -0
- package/.output/server/node_modules/mongoose/lib/error/missingSchema.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/objectParameter.js +4 -5
- package/.output/server/node_modules/mongoose/lib/error/overwriteModel.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/setOptionError.js +3 -3
- package/.output/server/node_modules/mongoose/lib/error/strict.js +3 -3
- package/.output/server/node_modules/mongoose/lib/error/strictPopulate.js +2 -2
- package/.output/server/node_modules/mongoose/lib/error/syncIndexes.js +2 -2
- package/.output/server/node_modules/mongoose/lib/error/validation.js +2 -10
- package/.output/server/node_modules/mongoose/lib/error/validator.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/version.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/buildMiddlewareFilter.js +24 -0
- package/.output/server/node_modules/mongoose/lib/helpers/clone.js +35 -18
- package/.output/server/node_modules/mongoose/lib/helpers/common.js +5 -5
- package/.output/server/node_modules/mongoose/lib/helpers/cursor/eachAsync.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getConstructor.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/mergeDiscriminatorSchema.js +10 -5
- package/.output/server/node_modules/mongoose/lib/helpers/document/applyDefaults.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/document/applyTimestamps.js +11 -10
- package/.output/server/node_modules/mongoose/lib/helpers/document/applyVirtuals.js +10 -9
- package/.output/server/node_modules/mongoose/lib/helpers/document/cleanModifiedSubpaths.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/document/compile.js +17 -14
- package/.output/server/node_modules/mongoose/lib/helpers/document/getDeepestSubdocumentForPath.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/document/isInPathsToSave.js +24 -0
- package/.output/server/node_modules/mongoose/lib/helpers/get.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/getRelatedIndexes.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexEqual.js +3 -4
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/isBsonType.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/isMongooseObject.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/isObject.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/isSimpleValidator.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/minimize.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyDefaultsToPOJO.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyHooks.js +55 -54
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyMethods.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyStaticHooks.js +1 -48
- package/.output/server/node_modules/mongoose/lib/helpers/model/castBulkWrite.js +8 -12
- package/.output/server/node_modules/mongoose/lib/helpers/model/discriminator.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/parallelLimit.js +18 -36
- package/.output/server/node_modules/mongoose/lib/helpers/pluralize.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -11
- package/.output/server/node_modules/mongoose/lib/helpers/populate/assignVals.js +10 -10
- package/.output/server/node_modules/mongoose/lib/helpers/populate/createPopulateQueryFilter.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js +197 -69
- package/.output/server/node_modules/mongoose/lib/helpers/populate/getSchemaTypes.js +15 -15
- package/.output/server/node_modules/mongoose/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/populate/modelNamesFromRefPath.js +10 -2
- package/.output/server/node_modules/mongoose/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
- package/.output/server/node_modules/mongoose/lib/helpers/printJestWarning.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/processConnectionOptions.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/projection/isPathExcluded.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/projection/isSubpath.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/projection/parseProjection.js +9 -4
- package/.output/server/node_modules/mongoose/lib/helpers/query/cast$expr.js +8 -10
- package/.output/server/node_modules/mongoose/lib/helpers/query/castFilterPath.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/query/castUpdate.js +44 -38
- package/.output/server/node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js +8 -8
- package/.output/server/node_modules/mongoose/lib/helpers/query/handleImmutable.js +8 -8
- package/.output/server/node_modules/mongoose/lib/helpers/schema/applyPlugins.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/schema/applyReadConcern.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/schema/applyWriteConcern.js +4 -2
- package/.output/server/node_modules/mongoose/lib/helpers/schema/getIndexes.js +5 -11
- package/.output/server/node_modules/mongoose/lib/helpers/schema/getSubdocumentStrictValue.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/schema/handleIdOption.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/schema/idGetter.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/schematype/handleImmutable.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/setDefaultsOnInsert.js +26 -13
- package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setDocumentTimestamps.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setupTimestamps.js +60 -38
- package/.output/server/node_modules/mongoose/lib/helpers/update/applyTimestampsToUpdate.js +13 -10
- package/.output/server/node_modules/mongoose/lib/helpers/update/castArrayFilters.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/update/decorateUpdateWithVersionKey.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/update/modifiedPaths.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/update/removeUnusedArrayFilters.js +7 -2
- package/.output/server/node_modules/mongoose/lib/helpers/updateValidators.js +58 -119
- package/.output/server/node_modules/mongoose/lib/model.js +940 -946
- package/.output/server/node_modules/mongoose/lib/mongoose.js +131 -79
- package/.output/server/node_modules/mongoose/lib/options/schemaArrayOptions.js +2 -2
- package/.output/server/node_modules/mongoose/lib/options/schemaBufferOptions.js +1 -1
- package/.output/server/node_modules/mongoose/lib/options/schemaDocumentArrayOptions.js +23 -0
- package/.output/server/node_modules/mongoose/lib/options/schemaNumberOptions.js +3 -3
- package/.output/server/node_modules/mongoose/lib/options/schemaObjectIdOptions.js +2 -2
- package/.output/server/node_modules/mongoose/lib/options/schemaStringOptions.js +6 -6
- package/.output/server/node_modules/mongoose/lib/options/schemaSubdocumentOptions.js +23 -0
- package/.output/server/node_modules/mongoose/lib/options/schemaTypeOptions.js +27 -13
- package/.output/server/node_modules/mongoose/lib/options/virtualOptions.js +12 -12
- package/.output/server/node_modules/mongoose/lib/plugins/index.js +0 -1
- package/.output/server/node_modules/mongoose/lib/plugins/saveSubdocs.js +84 -92
- package/.output/server/node_modules/mongoose/lib/plugins/sharding.js +33 -15
- package/.output/server/node_modules/mongoose/lib/plugins/trackTransaction.js +29 -25
- package/.output/server/node_modules/mongoose/lib/query.js +700 -548
- package/.output/server/node_modules/mongoose/lib/queryHelpers.js +34 -32
- package/.output/server/node_modules/mongoose/lib/schema/array.js +69 -113
- package/.output/server/node_modules/mongoose/lib/schema/bigint.js +18 -20
- package/.output/server/node_modules/mongoose/lib/schema/boolean.js +20 -22
- package/.output/server/node_modules/mongoose/lib/schema/buffer.js +23 -25
- package/.output/server/node_modules/mongoose/lib/schema/date.js +19 -21
- package/.output/server/node_modules/mongoose/lib/schema/decimal128.js +16 -18
- package/.output/server/node_modules/mongoose/lib/schema/documentArray.js +94 -131
- package/.output/server/node_modules/mongoose/lib/schema/documentArrayElement.js +50 -16
- package/.output/server/node_modules/mongoose/lib/schema/double.js +16 -18
- package/.output/server/node_modules/mongoose/lib/schema/index.js +1 -0
- package/.output/server/node_modules/mongoose/lib/schema/int32.js +17 -19
- package/.output/server/node_modules/mongoose/lib/schema/map.js +17 -24
- package/.output/server/node_modules/mongoose/lib/schema/mixed.js +14 -14
- package/.output/server/node_modules/mongoose/lib/schema/number.js +38 -28
- package/.output/server/node_modules/mongoose/lib/schema/objectId.js +18 -20
- package/.output/server/node_modules/mongoose/lib/schema/operators/exists.js +1 -1
- package/.output/server/node_modules/mongoose/lib/schema/operators/geospatial.js +1 -1
- package/.output/server/node_modules/mongoose/lib/schema/operators/text.js +4 -4
- package/.output/server/node_modules/mongoose/lib/schema/string.js +42 -27
- package/.output/server/node_modules/mongoose/lib/schema/subdocument.js +47 -58
- package/.output/server/node_modules/mongoose/lib/schema/union.js +54 -4
- package/.output/server/node_modules/mongoose/lib/schema/uuid.js +17 -40
- package/.output/server/node_modules/mongoose/lib/schema.js +235 -176
- package/.output/server/node_modules/mongoose/lib/schemaType.js +227 -158
- package/.output/server/node_modules/mongoose/lib/stateMachine.js +5 -8
- package/.output/server/node_modules/mongoose/lib/types/array/index.js +5 -5
- package/.output/server/node_modules/mongoose/lib/types/array/methods/index.js +27 -28
- package/.output/server/node_modules/mongoose/lib/types/arraySubdocument.js +11 -11
- package/.output/server/node_modules/mongoose/lib/types/buffer.js +15 -15
- package/.output/server/node_modules/mongoose/lib/types/decimal128.js +1 -1
- package/.output/server/node_modules/mongoose/lib/types/documentArray/index.js +4 -4
- package/.output/server/node_modules/mongoose/lib/types/documentArray/methods/index.js +15 -13
- package/.output/server/node_modules/mongoose/lib/types/double.js +1 -1
- package/.output/server/node_modules/mongoose/lib/types/map.js +20 -71
- package/.output/server/node_modules/mongoose/lib/types/objectid.js +1 -1
- package/.output/server/node_modules/mongoose/lib/types/subdocument.js +32 -81
- package/.output/server/node_modules/mongoose/lib/types/uuid.js +1 -1
- package/.output/server/node_modules/mongoose/lib/utils.js +91 -70
- package/.output/server/node_modules/mongoose/lib/validOptions.js +4 -3
- package/.output/server/node_modules/mongoose/lib/virtualType.js +18 -18
- package/.output/server/node_modules/mongoose/package.json +46 -63
- package/.output/server/node_modules/mquery/lib/collection/collection.js +3 -1
- package/.output/server/node_modules/mquery/lib/collection/node.js +17 -3
- package/.output/server/node_modules/mquery/lib/mquery.js +136 -93
- package/.output/server/node_modules/mquery/lib/permissions.js +21 -6
- package/.output/server/node_modules/mquery/package.json +4 -7
- package/.output/server/package.json +7 -9
- package/package.json +3 -3
- package/.output/public/_nuxt/builds/meta/b59771ef-8e58-4078-9d18-ccc01cba96e9.json +0 -1
- package/.output/public/_nuxt/error-404.CTWLHxjC.css +0 -1
- package/.output/public/_nuxt/error-500.UBfk8-QP.css +0 -1
- package/.output/server/chunks/build/error-404-8tbBXju4.mjs.map +0 -1
- package/.output/server/chunks/build/error-404-styles.BeWfK6Py.mjs +0 -8
- package/.output/server/chunks/build/error-404-styles.BeWfK6Py.mjs.map +0 -1
- package/.output/server/chunks/build/error-500-DxFsom1i.mjs.map +0 -1
- package/.output/server/chunks/build/error-500-styles.CPUUvoY-.mjs +0 -8
- package/.output/server/chunks/build/error-500-styles.CPUUvoY-.mjs.map +0 -1
- package/.output/server/chunks/build/index-BB-Clavm.mjs.map +0 -1
- package/.output/server/node_modules/debug/package.json +0 -64
- package/.output/server/node_modules/debug/src/browser.js +0 -272
- package/.output/server/node_modules/debug/src/common.js +0 -292
- package/.output/server/node_modules/debug/src/index.js +0 -10
- package/.output/server/node_modules/debug/src/node.js +0 -263
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/crypto_callbacks.js +0 -81
- package/.output/server/node_modules/mongodb/lib/resource_management.js +0 -58
- package/.output/server/node_modules/mongoose/lib/browserDocument.js +0 -101
- package/.output/server/node_modules/mongoose/lib/documentProvider.js +0 -30
- package/.output/server/node_modules/mongoose/lib/helpers/createJSONSchemaTypeDefinition.js +0 -24
- package/.output/server/node_modules/mongoose/lib/helpers/promiseOrCallback.js +0 -54
- package/.output/server/node_modules/mongoose/lib/plugins/validateBeforeSave.js +0 -51
- package/.output/server/node_modules/supports-color/index.js +0 -202
- package/.output/server/node_modules/supports-color/package.json +0 -64
|
@@ -23,6 +23,7 @@ const merge = require('./helpers/schema/merge');
|
|
|
23
23
|
const mpath = require('mpath');
|
|
24
24
|
const setPopulatedVirtualValue = require('./helpers/populate/setPopulatedVirtualValue');
|
|
25
25
|
const setupTimestamps = require('./helpers/timestamps/setupTimestamps');
|
|
26
|
+
const symbols = require('./schema/symbols');
|
|
26
27
|
const utils = require('./utils');
|
|
27
28
|
const validateRef = require('./helpers/populate/validateRef');
|
|
28
29
|
|
|
@@ -31,7 +32,7 @@ const hasNumericSubpathRegex = /\.\d+(\.|$)/;
|
|
|
31
32
|
let MongooseTypes;
|
|
32
33
|
|
|
33
34
|
const queryHooks = require('./constants').queryMiddlewareFunctions;
|
|
34
|
-
const documentHooks = require('./
|
|
35
|
+
const documentHooks = require('./constants').documentMiddlewareFunctions;
|
|
35
36
|
const hookNames = queryHooks.concat(documentHooks).
|
|
36
37
|
reduce((s, hook) => s.add(hook), new Set());
|
|
37
38
|
|
|
@@ -58,7 +59,7 @@ const numberRE = /^\d+$/;
|
|
|
58
59
|
* - [autoIndex](https://mongoosejs.com/docs/guide.html#autoIndex): bool - defaults to null (which means use the connection's autoIndex option)
|
|
59
60
|
* - [autoCreate](https://mongoosejs.com/docs/guide.html#autoCreate): bool - defaults to null (which means use the connection's autoCreate option)
|
|
60
61
|
* - [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
|
|
62
|
+
* - [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 established before erroring out.
|
|
62
63
|
* - [capped](https://mongoosejs.com/docs/guide.html#capped): bool | number | object - defaults to false
|
|
63
64
|
* - [collection](https://mongoosejs.com/docs/guide.html#collection): string - no default
|
|
64
65
|
* - [discriminatorKey](https://mongoosejs.com/docs/guide.html#discriminatorKey): string - defaults to `__t`
|
|
@@ -77,7 +78,7 @@ const numberRE = /^\d+$/;
|
|
|
77
78
|
* - [validateBeforeSave](https://mongoosejs.com/docs/guide.html#validateBeforeSave) - bool - defaults to `true`
|
|
78
79
|
* - [validateModifiedOnly](https://mongoosejs.com/docs/api/document.html#Document.prototype.validate()) - bool - defaults to `false`
|
|
79
80
|
* - [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
|
|
81
|
+
* - [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) for all fields. Set to a string array to enable optimistic concurrency only for the specified fields; note that this **replaces** the default array versioning behavior. Set to `{ exclude: string[] }` to enable optimistic concurrency for all fields except the specified ones; this also replaces the default array versioning.
|
|
81
82
|
* - [collation](https://mongoosejs.com/docs/guide.html#collation): object - defaults to null (which means use no collation)
|
|
82
83
|
* - [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
84
|
* - [selectPopulatedPaths](https://mongoosejs.com/docs/guide.html#selectPopulatedPaths): boolean - defaults to `true`
|
|
@@ -86,7 +87,8 @@ const numberRE = /^\d+$/;
|
|
|
86
87
|
* - [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
88
|
* - [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
89
|
* - [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
|
+
* - [encryptionType]: the encryption type for the schema. Valid options are `csfle` or `queryableEncryption`. See https://mongoosejs.com/docs/field-level-encryption.html.
|
|
91
|
+
* - [lean]: boolean - set to true to make all queries use [lean](https://mongoosejs.com/docs/tutorials/lean.html) by default. Defaults to false.
|
|
90
92
|
*
|
|
91
93
|
* #### Options for Nested Schemas:
|
|
92
94
|
*
|
|
@@ -96,8 +98,8 @@ const numberRE = /^\d+$/;
|
|
|
96
98
|
*
|
|
97
99
|
* _When nesting schemas, (`children` in the example above), always declare the child schema first before passing it into its parent._
|
|
98
100
|
*
|
|
99
|
-
* @param {
|
|
100
|
-
* @param {
|
|
101
|
+
* @param {object|Schema|Array} [definition] Can be one of: object describing schema paths, or schema to copy, or array of objects and schemas
|
|
102
|
+
* @param {object} [options]
|
|
101
103
|
* @inherits NodeJS EventEmitter https://nodejs.org/api/events.html#class-eventemitter
|
|
102
104
|
* @event `init`: Emitted after the schema is compiled into a `Model`.
|
|
103
105
|
* @api public
|
|
@@ -119,11 +121,11 @@ function Schema(obj, options) {
|
|
|
119
121
|
this.callQueue = [];
|
|
120
122
|
this._indexes = [];
|
|
121
123
|
this._searchIndexes = [];
|
|
122
|
-
this.methods =
|
|
124
|
+
this.methods = options?.methods || {};
|
|
123
125
|
this.methodOptions = {};
|
|
124
|
-
this.statics =
|
|
126
|
+
this.statics = options?.statics || {};
|
|
125
127
|
this.tree = {};
|
|
126
|
-
this.query =
|
|
128
|
+
this.query = options?.query || {};
|
|
127
129
|
this.childSchemas = [];
|
|
128
130
|
this.plugins = [];
|
|
129
131
|
// For internal debugging. Do not use this to try to save a schema in MDB.
|
|
@@ -146,7 +148,7 @@ function Schema(obj, options) {
|
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
// build virtual paths
|
|
149
|
-
if (options
|
|
151
|
+
if (options?.virtuals) {
|
|
150
152
|
const virtuals = options.virtuals;
|
|
151
153
|
const pathNames = Object.keys(virtuals);
|
|
152
154
|
for (const pathName of pathNames) {
|
|
@@ -164,7 +166,7 @@ function Schema(obj, options) {
|
|
|
164
166
|
}
|
|
165
167
|
|
|
166
168
|
// check if _id's value is a subdocument (gh-2276)
|
|
167
|
-
const _idSubDoc = obj
|
|
169
|
+
const _idSubDoc = obj?._id && utils.isObject(obj._id);
|
|
168
170
|
|
|
169
171
|
// ensure the documents get an auto _id unless disabled
|
|
170
172
|
const auto_id = !this.paths['_id'] &&
|
|
@@ -203,7 +205,7 @@ function aliasFields(schema, paths) {
|
|
|
203
205
|
if (Array.isArray(alias)) {
|
|
204
206
|
for (const a of alias) {
|
|
205
207
|
if (typeof a !== 'string') {
|
|
206
|
-
throw new
|
|
208
|
+
throw new MongooseError('Invalid value for alias option on ' + prop + ', got ' + a);
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
schema.aliases[a] = prop;
|
|
@@ -229,7 +231,7 @@ function aliasFields(schema, paths) {
|
|
|
229
231
|
}
|
|
230
232
|
|
|
231
233
|
if (typeof alias !== 'string') {
|
|
232
|
-
throw new
|
|
234
|
+
throw new MongooseError('Invalid value for alias option on ' + prop + ', got ' + alias);
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
schema.aliases[alias] = prop;
|
|
@@ -372,6 +374,29 @@ Schema.prototype.paths;
|
|
|
372
374
|
|
|
373
375
|
Schema.prototype.tree;
|
|
374
376
|
|
|
377
|
+
/**
|
|
378
|
+
* Creates a new schema with the given definition and options. Equivalent to `new Schema(definition, options)`.
|
|
379
|
+
*
|
|
380
|
+
* `Schema.create()` is primarily useful for automatic schema type inference in TypeScript.
|
|
381
|
+
*
|
|
382
|
+
* #### Example:
|
|
383
|
+
*
|
|
384
|
+
* const schema = Schema.create({ name: String }, { toObject: { virtuals: true } });
|
|
385
|
+
* // Equivalent:
|
|
386
|
+
* const schema2 = new Schema({ name: String }, { toObject: { virtuals: true } });
|
|
387
|
+
*
|
|
388
|
+
* @param {object} definition
|
|
389
|
+
* @param {object} [options]
|
|
390
|
+
* @return {Schema} the new schema
|
|
391
|
+
* @api public
|
|
392
|
+
* @memberOf Schema
|
|
393
|
+
* @static
|
|
394
|
+
*/
|
|
395
|
+
|
|
396
|
+
Schema.create = function create(definition, options) {
|
|
397
|
+
return new Schema(definition, options);
|
|
398
|
+
};
|
|
399
|
+
|
|
375
400
|
/**
|
|
376
401
|
* Returns a deep copy of the schema
|
|
377
402
|
*
|
|
@@ -485,8 +510,8 @@ Schema.prototype._clone = function _clone(Constructor) {
|
|
|
485
510
|
* newSchema.path('name'); // SchemaString { ... }
|
|
486
511
|
* newSchema.path('age'); // undefined
|
|
487
512
|
*
|
|
488
|
-
* @param {
|
|
489
|
-
* @param {
|
|
513
|
+
* @param {string[]} paths List of Paths to pick for the new Schema
|
|
514
|
+
* @param {object} [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`). Defaults to `this.options` if not set.
|
|
490
515
|
* @return {Schema}
|
|
491
516
|
* @api public
|
|
492
517
|
*/
|
|
@@ -540,8 +565,8 @@ Schema.prototype.pick = function(paths, options) {
|
|
|
540
565
|
* newSchema.path('name'); // SchemaString { ... }
|
|
541
566
|
* newSchema.path('age'); // undefined
|
|
542
567
|
*
|
|
543
|
-
* @param {
|
|
544
|
-
* @param {
|
|
568
|
+
* @param {string[]} paths List of Paths to omit for the new Schema
|
|
569
|
+
* @param {object} [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`). Defaults to `this.options` if not set.
|
|
545
570
|
* @return {Schema}
|
|
546
571
|
* @api public
|
|
547
572
|
*/
|
|
@@ -571,20 +596,20 @@ Schema.prototype.omit = function(paths, options) {
|
|
|
571
596
|
/**
|
|
572
597
|
* Returns default options for this schema, merged with `options`.
|
|
573
598
|
*
|
|
574
|
-
* @param {
|
|
575
|
-
* @return {
|
|
599
|
+
* @param {object} [options] Options to overwrite the default options
|
|
600
|
+
* @return {object} The merged options of `options` and the default options
|
|
576
601
|
* @api private
|
|
577
602
|
*/
|
|
578
603
|
|
|
579
604
|
Schema.prototype.defaultOptions = function(options) {
|
|
580
605
|
this._userProvidedOptions = options == null ? {} : clone(options);
|
|
581
|
-
const baseOptions = this.base
|
|
582
|
-
const
|
|
583
|
-
const
|
|
584
|
-
const
|
|
606
|
+
const baseOptions = this.base?.options || {};
|
|
607
|
+
const defaultStrict = baseOptions.strict ?? true;
|
|
608
|
+
const defaultStrictQuery = baseOptions.strictQuery ?? false;
|
|
609
|
+
const defaultId = baseOptions.id ?? true;
|
|
585
610
|
options = {
|
|
586
|
-
strict,
|
|
587
|
-
strictQuery,
|
|
611
|
+
strict: defaultStrict,
|
|
612
|
+
strictQuery: defaultStrictQuery,
|
|
588
613
|
bufferCommands: true,
|
|
589
614
|
capped: false, // { size, max, autoIndexId }
|
|
590
615
|
versionKey: '__v',
|
|
@@ -598,11 +623,16 @@ Schema.prototype.defaultOptions = function(options) {
|
|
|
598
623
|
validateModifiedOnly: false,
|
|
599
624
|
// the following are only applied at construction time
|
|
600
625
|
_id: true,
|
|
601
|
-
id:
|
|
626
|
+
id: defaultId,
|
|
602
627
|
typeKey: 'type',
|
|
603
628
|
...options
|
|
604
629
|
};
|
|
605
630
|
|
|
631
|
+
// Treat `undefined` as "not provided" for these options
|
|
632
|
+
options.strict ??= defaultStrict;
|
|
633
|
+
options.strictQuery ??= defaultStrictQuery;
|
|
634
|
+
options.id ??= defaultId;
|
|
635
|
+
|
|
606
636
|
if (options.versionKey && typeof options.versionKey !== 'string') {
|
|
607
637
|
throw new MongooseError('`versionKey` must be falsy or string, got `' + (typeof options.versionKey) + '`');
|
|
608
638
|
}
|
|
@@ -642,14 +672,14 @@ Schema.prototype.defaultOptions = function(options) {
|
|
|
642
672
|
* doc.element; // '#hero'
|
|
643
673
|
* doc instanceof ClickedModel; // true
|
|
644
674
|
*
|
|
645
|
-
* @param {
|
|
675
|
+
* @param {string} name the name of the discriminator
|
|
646
676
|
* @param {Schema} schema the discriminated Schema
|
|
647
|
-
* @param {
|
|
648
|
-
* @param {
|
|
649
|
-
* @param {
|
|
650
|
-
* @param {
|
|
651
|
-
* @param {
|
|
652
|
-
* @param {
|
|
677
|
+
* @param {object} [options] discriminator options
|
|
678
|
+
* @param {string} [options.value] the string stored in the `discriminatorKey` property. If not specified, Mongoose uses the `name` parameter.
|
|
679
|
+
* @param {boolean} [options.clone=true] By default, `discriminator()` clones the given `schema`. Set to `false` to skip cloning.
|
|
680
|
+
* @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.
|
|
681
|
+
* @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.
|
|
682
|
+
* @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
683
|
* @return {Schema} the Schema instance
|
|
654
684
|
* @api public
|
|
655
685
|
*/
|
|
@@ -660,6 +690,33 @@ Schema.prototype.discriminator = function(name, schema, options) {
|
|
|
660
690
|
return this;
|
|
661
691
|
};
|
|
662
692
|
|
|
693
|
+
/*!
|
|
694
|
+
* Get the document middleware for this schema, filtering out any hooks that are specific to queries.
|
|
695
|
+
*/
|
|
696
|
+
Schema.prototype._getDocumentMiddleware = function _getDocumentMiddleware() {
|
|
697
|
+
return this.s.hooks.
|
|
698
|
+
filter(hook => {
|
|
699
|
+
if (hook.name === 'updateOne' || hook.name === 'deleteOne') {
|
|
700
|
+
return !!hook['document'];
|
|
701
|
+
}
|
|
702
|
+
if (hook.name === 'remove' || hook.name === 'init') {
|
|
703
|
+
return hook['document'] == null || !!hook['document'];
|
|
704
|
+
}
|
|
705
|
+
if (hook.query != null || hook.document != null) {
|
|
706
|
+
return hook.document !== false;
|
|
707
|
+
}
|
|
708
|
+
return true;
|
|
709
|
+
}).
|
|
710
|
+
filter(hook => {
|
|
711
|
+
// If user has overwritten the method, don't apply built-in middleware
|
|
712
|
+
if (this.methods[hook.name]) {
|
|
713
|
+
return !hook.fn[symbols.builtInMiddleware];
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
return true;
|
|
717
|
+
});
|
|
718
|
+
};
|
|
719
|
+
|
|
663
720
|
/*!
|
|
664
721
|
* Get this schema's default toObject/toJSON options, including Mongoose global
|
|
665
722
|
* options.
|
|
@@ -671,9 +728,7 @@ Schema.prototype._defaultToObjectOptions = function(json) {
|
|
|
671
728
|
return this._defaultToObjectOptionsMap[path];
|
|
672
729
|
}
|
|
673
730
|
|
|
674
|
-
const baseOptions = this.base
|
|
675
|
-
this.base.options &&
|
|
676
|
-
this.base.options[path] || {};
|
|
731
|
+
const baseOptions = this.base?.options?.[path] || {};
|
|
677
732
|
const schemaOptions = this.options[path] || {};
|
|
678
733
|
// merge base default options with Schema's set default options if available.
|
|
679
734
|
// `clone` is necessary here because `utils.options` directly modifies the second input.
|
|
@@ -695,7 +750,7 @@ Schema.prototype.encryptionType = function encryptionType(encryptionType) {
|
|
|
695
750
|
return this.options.encryptionType;
|
|
696
751
|
}
|
|
697
752
|
if (!(typeof encryptionType === 'string' || encryptionType === null)) {
|
|
698
|
-
throw new
|
|
753
|
+
throw new MongooseError(`invalid \`encryptionType\`: ${encryptionType}`);
|
|
699
754
|
}
|
|
700
755
|
this.options.encryptionType = encryptionType;
|
|
701
756
|
};
|
|
@@ -713,14 +768,14 @@ Schema.prototype.encryptionType = function encryptionType(encryptionType) {
|
|
|
713
768
|
* // getters, setters, indexes, methods, and statics.
|
|
714
769
|
* TurboManSchema.add(ToySchema).add({ year: Number });
|
|
715
770
|
*
|
|
716
|
-
* @param {
|
|
717
|
-
* @param {
|
|
771
|
+
* @param {object|Schema} obj plain object with paths to add, or another schema
|
|
772
|
+
* @param {string} [prefix] path to prefix the newly added paths with
|
|
718
773
|
* @return {Schema} the Schema instance
|
|
719
774
|
* @api public
|
|
720
775
|
*/
|
|
721
776
|
|
|
722
777
|
Schema.prototype.add = function add(obj, prefix) {
|
|
723
|
-
if (obj instanceof Schema ||
|
|
778
|
+
if (obj instanceof Schema || obj?.instanceOfSchema) {
|
|
724
779
|
merge(this, obj);
|
|
725
780
|
return this;
|
|
726
781
|
}
|
|
@@ -760,7 +815,7 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
760
815
|
let isMongooseTypeString = false;
|
|
761
816
|
if (typeof val === 'string') {
|
|
762
817
|
// Handle the case in which the type is specified as a string (eg. 'date', 'oid', ...)
|
|
763
|
-
const MongooseTypes = this.base
|
|
818
|
+
const MongooseTypes = this.base?.Schema.Types ?? Schema.Types;
|
|
764
819
|
const upperVal = val.charAt(0).toUpperCase() + val.substring(1);
|
|
765
820
|
isMongooseTypeString = MongooseTypes[upperVal] != null;
|
|
766
821
|
}
|
|
@@ -773,7 +828,7 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
773
828
|
`a valid type at path \`${key}\`. See ` +
|
|
774
829
|
'https://bit.ly/mongoose-schematypes for a list of valid schema types.');
|
|
775
830
|
}
|
|
776
|
-
if (val instanceof VirtualType || (val.constructor
|
|
831
|
+
if (val instanceof VirtualType || (val.constructor?.name ?? null) === 'VirtualType') {
|
|
777
832
|
this.virtual(val);
|
|
778
833
|
continue;
|
|
779
834
|
}
|
|
@@ -790,13 +845,13 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
790
845
|
this.nested[prefix.substring(0, prefix.length - 1)] = true;
|
|
791
846
|
}
|
|
792
847
|
this.path(prefix + key, val);
|
|
793
|
-
if (
|
|
848
|
+
if (!val[0]?.instanceOfSchema && utils.isPOJO(val[0]?.discriminators)) {
|
|
794
849
|
const schemaType = this.path(prefix + key);
|
|
795
850
|
for (const key in val[0].discriminators) {
|
|
796
851
|
schemaType.discriminator(key, val[0].discriminators[key]);
|
|
797
852
|
}
|
|
798
853
|
}
|
|
799
|
-
} else if (
|
|
854
|
+
} else if (utils.hasOwnKeys(val) === false) {
|
|
800
855
|
// Special-case: {} always interpreted as Mixed path so leaf at this node
|
|
801
856
|
if (prefix) {
|
|
802
857
|
this.nested[prefix.substring(0, prefix.length - 1)] = true;
|
|
@@ -811,7 +866,7 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
811
866
|
} else {
|
|
812
867
|
// There IS a bona-fide type key that may also be a POJO
|
|
813
868
|
const _typeDef = val[typeKey];
|
|
814
|
-
if (isPOJO(_typeDef) &&
|
|
869
|
+
if (isPOJO(_typeDef) && utils.hasOwnKeys(_typeDef)) {
|
|
815
870
|
// If a POJO is the value of a type key, make it a subdocument
|
|
816
871
|
if (prefix) {
|
|
817
872
|
this.nested[prefix.substring(0, prefix.length - 1)] = true;
|
|
@@ -842,7 +897,7 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
842
897
|
this.nested[prefix.substring(0, prefix.length - 1)] = true;
|
|
843
898
|
}
|
|
844
899
|
this.path(prefix + key, val);
|
|
845
|
-
if (
|
|
900
|
+
if (!val?.instanceOfSchema && utils.isPOJO(val?.discriminators)) {
|
|
846
901
|
const schemaType = this.path(prefix + key);
|
|
847
902
|
for (const key in val.discriminators) {
|
|
848
903
|
schemaType.discriminator(key, val.discriminators[key]);
|
|
@@ -854,7 +909,7 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
854
909
|
if (val.instanceOfSchema && val.encryptionType() != null) {
|
|
855
910
|
// schema.add({ field: <instance of encrypted schema> })
|
|
856
911
|
if (this.encryptionType() != val.encryptionType()) {
|
|
857
|
-
throw new
|
|
912
|
+
throw new MongooseError('encryptionType of a nested schema must match the encryption type of the parent schema.');
|
|
858
913
|
}
|
|
859
914
|
|
|
860
915
|
for (const [encryptedField, encryptedFieldConfig] of Object.entries(val.encryptedFields)) {
|
|
@@ -866,7 +921,7 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
866
921
|
const { encrypt } = val;
|
|
867
922
|
|
|
868
923
|
if (this.encryptionType() == null) {
|
|
869
|
-
throw new
|
|
924
|
+
throw new MongooseError('encryptionType must be provided');
|
|
870
925
|
}
|
|
871
926
|
|
|
872
927
|
this._addEncryptedField(fullPath, encrypt);
|
|
@@ -893,7 +948,7 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
893
948
|
Schema.prototype._addEncryptedField = function _addEncryptedField(path, fieldConfig) {
|
|
894
949
|
const type = this.path(path).autoEncryptionType();
|
|
895
950
|
if (type == null) {
|
|
896
|
-
throw new
|
|
951
|
+
throw new MongooseError(`Invalid BSON type for FLE field: '${path}'`);
|
|
897
952
|
}
|
|
898
953
|
|
|
899
954
|
this.encryptedFields[path] = clone(fieldConfig);
|
|
@@ -914,7 +969,7 @@ Schema.prototype._removeEncryptedField = function _removeEncryptedField(path) {
|
|
|
914
969
|
* @returns {boolean}
|
|
915
970
|
*/
|
|
916
971
|
Schema.prototype._hasEncryptedFields = function _hasEncryptedFields() {
|
|
917
|
-
return
|
|
972
|
+
return utils.hasOwnKeys(this.encryptedFields);
|
|
918
973
|
};
|
|
919
974
|
|
|
920
975
|
/**
|
|
@@ -1018,8 +1073,8 @@ Schema.prototype._buildSchemaMap = function() {
|
|
|
1018
1073
|
* await turboMan.save(); // Saves { _id: ..., n: 'Turbo Man Action Figure' }
|
|
1019
1074
|
*
|
|
1020
1075
|
*
|
|
1021
|
-
* @param {
|
|
1022
|
-
* @param {
|
|
1076
|
+
* @param {string} path real path to alias
|
|
1077
|
+
* @param {string|string[]} alias the path(s) to use as an alias for `path`
|
|
1023
1078
|
* @return {Schema} the Schema instance
|
|
1024
1079
|
* @api public
|
|
1025
1080
|
*/
|
|
@@ -1051,18 +1106,18 @@ Schema.prototype.alias = function alias(path, alias) {
|
|
|
1051
1106
|
* // Remove index by name
|
|
1052
1107
|
* ToySchema.removeIndex('my custom index name');
|
|
1053
1108
|
*
|
|
1054
|
-
* @param {
|
|
1109
|
+
* @param {object|string} index name or index specification
|
|
1055
1110
|
* @return {Schema} the Schema instance
|
|
1056
1111
|
* @api public
|
|
1057
1112
|
*/
|
|
1058
1113
|
|
|
1059
1114
|
Schema.prototype.removeIndex = function removeIndex(index) {
|
|
1060
1115
|
if (arguments.length > 1) {
|
|
1061
|
-
throw new
|
|
1116
|
+
throw new MongooseError('removeIndex() takes only 1 argument');
|
|
1062
1117
|
}
|
|
1063
1118
|
|
|
1064
1119
|
if (typeof index !== 'object' && typeof index !== 'string') {
|
|
1065
|
-
throw new
|
|
1120
|
+
throw new MongooseError('removeIndex() may only take either an object or a string as an argument');
|
|
1066
1121
|
}
|
|
1067
1122
|
|
|
1068
1123
|
if (typeof index === 'object') {
|
|
@@ -1118,9 +1173,9 @@ Schema.prototype.clearIndexes = function clearIndexes() {
|
|
|
1118
1173
|
* const ToySchema = new Schema({ name: String, color: String, price: Number });
|
|
1119
1174
|
* ToySchema.searchIndex({ name: 'test', definition: { mappings: { dynamic: true } } });
|
|
1120
1175
|
*
|
|
1121
|
-
* @param {
|
|
1122
|
-
* @param {
|
|
1123
|
-
* @param {
|
|
1176
|
+
* @param {object} description index options, including `name` and `definition`
|
|
1177
|
+
* @param {string} description.name
|
|
1178
|
+
* @param {object} description.definition
|
|
1124
1179
|
* @return {Schema} the Schema instance
|
|
1125
1180
|
* @api public
|
|
1126
1181
|
*/
|
|
@@ -1206,8 +1261,8 @@ reserved.collection = 1;
|
|
|
1206
1261
|
* schema.path('name') // returns a SchemaType
|
|
1207
1262
|
* schema.path('name', Number) // changes the schemaType of `name` to Number
|
|
1208
1263
|
*
|
|
1209
|
-
* @param {
|
|
1210
|
-
* @param {
|
|
1264
|
+
* @param {string} path The name of the Path to get / set
|
|
1265
|
+
* @param {object} [obj] The Type to set the path to, if provided the path will be SET, otherwise the path will be GET
|
|
1211
1266
|
* @api public
|
|
1212
1267
|
*/
|
|
1213
1268
|
|
|
@@ -1263,7 +1318,7 @@ Schema.prototype.path = function(path, obj) {
|
|
|
1263
1318
|
|
|
1264
1319
|
for (const sub of subpaths) {
|
|
1265
1320
|
if (utils.specialProperties.has(sub)) {
|
|
1266
|
-
throw new
|
|
1321
|
+
throw new MongooseError('Cannot set special property `' + sub + '` on a schema');
|
|
1267
1322
|
}
|
|
1268
1323
|
fullPath = fullPath += (fullPath.length > 0 ? '.' : '') + sub;
|
|
1269
1324
|
if (!branch[sub]) {
|
|
@@ -1276,7 +1331,7 @@ Schema.prototype.path = function(path, obj) {
|
|
|
1276
1331
|
+ fullPath
|
|
1277
1332
|
+ '` already set to type ' + branch[sub].name
|
|
1278
1333
|
+ '.';
|
|
1279
|
-
throw new
|
|
1334
|
+
throw new MongooseError(msg);
|
|
1280
1335
|
}
|
|
1281
1336
|
branch = branch[sub];
|
|
1282
1337
|
}
|
|
@@ -1300,7 +1355,7 @@ Schema.prototype.path = function(path, obj) {
|
|
|
1300
1355
|
if (schemaType.$__schemaType.$isSingleNested) {
|
|
1301
1356
|
this.childSchemas.push({
|
|
1302
1357
|
schema: schemaType.$__schemaType.schema,
|
|
1303
|
-
model: schemaType.$__schemaType.
|
|
1358
|
+
model: schemaType.$__schemaType.Constructor,
|
|
1304
1359
|
path: path
|
|
1305
1360
|
});
|
|
1306
1361
|
}
|
|
@@ -1329,10 +1384,10 @@ Schema.prototype.path = function(path, obj) {
|
|
|
1329
1384
|
value: this.base
|
|
1330
1385
|
});
|
|
1331
1386
|
|
|
1332
|
-
schemaType.
|
|
1387
|
+
schemaType.Constructor.base = this.base;
|
|
1333
1388
|
this.childSchemas.push({
|
|
1334
1389
|
schema: schemaType.schema,
|
|
1335
|
-
model: schemaType.
|
|
1390
|
+
model: schemaType.Constructor,
|
|
1336
1391
|
path: path
|
|
1337
1392
|
});
|
|
1338
1393
|
} else if (schemaType.$isMongooseDocumentArray) {
|
|
@@ -1343,15 +1398,15 @@ Schema.prototype.path = function(path, obj) {
|
|
|
1343
1398
|
value: this.base
|
|
1344
1399
|
});
|
|
1345
1400
|
|
|
1346
|
-
schemaType.
|
|
1401
|
+
schemaType.Constructor.base = this.base;
|
|
1347
1402
|
this.childSchemas.push({
|
|
1348
1403
|
schema: schemaType.schema,
|
|
1349
|
-
model: schemaType.
|
|
1404
|
+
model: schemaType.Constructor,
|
|
1350
1405
|
path: path
|
|
1351
1406
|
});
|
|
1352
1407
|
}
|
|
1353
1408
|
|
|
1354
|
-
if (schemaType.$isMongooseArray && schemaType
|
|
1409
|
+
if (schemaType.$isMongooseArray && !schemaType.$isMongooseDocumentArray) {
|
|
1355
1410
|
let arrayPath = path;
|
|
1356
1411
|
let _schemaType = schemaType;
|
|
1357
1412
|
|
|
@@ -1359,16 +1414,9 @@ Schema.prototype.path = function(path, obj) {
|
|
|
1359
1414
|
while (_schemaType.$isMongooseArray) {
|
|
1360
1415
|
arrayPath = arrayPath + '.$';
|
|
1361
1416
|
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
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
|
-
}
|
|
1417
|
+
_schemaType.embeddedSchemaType._arrayPath = arrayPath;
|
|
1418
|
+
_schemaType.embeddedSchemaType._arrayParentPath = path;
|
|
1419
|
+
_schemaType = _schemaType.embeddedSchemaType;
|
|
1372
1420
|
|
|
1373
1421
|
this.subpaths[arrayPath] = _schemaType;
|
|
1374
1422
|
}
|
|
@@ -1420,13 +1468,13 @@ Schema.prototype._gatherChildSchemas = function _gatherChildSchemas() {
|
|
|
1420
1468
|
if (schematype.$isMongooseDocumentArray || schematype.$isSingleNested) {
|
|
1421
1469
|
childSchemas.push({
|
|
1422
1470
|
schema: schematype.schema,
|
|
1423
|
-
model: schematype.
|
|
1471
|
+
model: schematype.Constructor,
|
|
1424
1472
|
path: path
|
|
1425
1473
|
});
|
|
1426
1474
|
} else if (schematype.$isSchemaMap && schematype.$__schemaType.$isSingleNested) {
|
|
1427
1475
|
childSchemas.push({
|
|
1428
1476
|
schema: schematype.$__schemaType.schema,
|
|
1429
|
-
model: schematype.$__schemaType.
|
|
1477
|
+
model: schematype.$__schemaType.Constructor,
|
|
1430
1478
|
path: path
|
|
1431
1479
|
});
|
|
1432
1480
|
}
|
|
@@ -1523,9 +1571,9 @@ Object.defineProperty(Schema.prototype, 'base', {
|
|
|
1523
1571
|
/**
|
|
1524
1572
|
* Converts type arguments into Mongoose Types.
|
|
1525
1573
|
*
|
|
1526
|
-
* @param {
|
|
1527
|
-
* @param {
|
|
1528
|
-
* @param {
|
|
1574
|
+
* @param {string} path
|
|
1575
|
+
* @param {object} obj constructor
|
|
1576
|
+
* @param {object} options schema options
|
|
1529
1577
|
* @api private
|
|
1530
1578
|
*/
|
|
1531
1579
|
|
|
@@ -1541,8 +1589,8 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1541
1589
|
|
|
1542
1590
|
// If this schema has an associated Mongoose object, use the Mongoose object's
|
|
1543
1591
|
// copy of SchemaTypes re: gh-7158 gh-6933
|
|
1544
|
-
const MongooseTypes = this.base
|
|
1545
|
-
const Types = this.base
|
|
1592
|
+
const MongooseTypes = this.base?.Schema.Types ?? Schema.Types;
|
|
1593
|
+
const Types = this.base?.Types ?? require('./types');
|
|
1546
1594
|
|
|
1547
1595
|
if (!utils.isPOJO(obj) && !(obj instanceof SchemaTypeOptions)) {
|
|
1548
1596
|
const constructorName = utils.getFunctionName(obj.constructor);
|
|
@@ -1582,7 +1630,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1582
1630
|
: type[0];
|
|
1583
1631
|
|
|
1584
1632
|
// new Schema({ path: [new Schema({ ... })] })
|
|
1585
|
-
if (cast
|
|
1633
|
+
if (cast?.instanceOfSchema) {
|
|
1586
1634
|
if (!(cast instanceof Schema)) {
|
|
1587
1635
|
if (this.options._isMerging) {
|
|
1588
1636
|
cast = new Schema(cast);
|
|
@@ -1616,7 +1664,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1616
1664
|
}
|
|
1617
1665
|
if (typeof cast !== 'undefined') {
|
|
1618
1666
|
if (Array.isArray(cast) || cast.type === Array || cast.type == 'Array') {
|
|
1619
|
-
if (cast
|
|
1667
|
+
if (cast?.type == 'Array') {
|
|
1620
1668
|
cast.type = Array;
|
|
1621
1669
|
}
|
|
1622
1670
|
return new MongooseTypes.Array(path, this.interpretAsType(path, cast, options), obj, null, this);
|
|
@@ -1630,7 +1678,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1630
1678
|
if (typeof cast === 'string') {
|
|
1631
1679
|
cast = MongooseTypes[cast.charAt(0).toUpperCase() + cast.substring(1)];
|
|
1632
1680
|
} else if (utils.isPOJO(castFromTypeKey)) {
|
|
1633
|
-
if (
|
|
1681
|
+
if (utils.hasOwnKeys(castFromTypeKey)) {
|
|
1634
1682
|
// The `minimize` and `typeKey` options propagate to child schemas
|
|
1635
1683
|
// declared inline, like `{ arr: [{ val: { $type: String } }] }`.
|
|
1636
1684
|
// See gh-3560
|
|
@@ -1703,7 +1751,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1703
1751
|
return new MongooseTypes.Array(path, cast || MongooseTypes.Mixed, obj, options, this);
|
|
1704
1752
|
}
|
|
1705
1753
|
|
|
1706
|
-
if (type
|
|
1754
|
+
if (type?.instanceOfSchema) {
|
|
1707
1755
|
return new MongooseTypes.Subdocument(type, path, obj, this);
|
|
1708
1756
|
}
|
|
1709
1757
|
|
|
@@ -1792,7 +1840,7 @@ Schema.prototype.eachPath = function(fn) {
|
|
|
1792
1840
|
* s.requiredPaths(); // [ 'age', 'name' ]
|
|
1793
1841
|
*
|
|
1794
1842
|
* @api public
|
|
1795
|
-
* @param {
|
|
1843
|
+
* @param {boolean} invalidate Refresh the cache
|
|
1796
1844
|
* @return {Array}
|
|
1797
1845
|
*/
|
|
1798
1846
|
|
|
@@ -1844,8 +1892,8 @@ Schema.prototype.indexedPaths = function indexedPaths() {
|
|
|
1844
1892
|
* s.pathType('foo'); // "virtual"
|
|
1845
1893
|
* s.pathType('fail'); // "adhocOrUndefined"
|
|
1846
1894
|
*
|
|
1847
|
-
* @param {
|
|
1848
|
-
* @return {
|
|
1895
|
+
* @param {string} path
|
|
1896
|
+
* @return {string}
|
|
1849
1897
|
* @api public
|
|
1850
1898
|
*/
|
|
1851
1899
|
|
|
@@ -1887,8 +1935,8 @@ Schema.prototype.pathType = function(path) {
|
|
|
1887
1935
|
/**
|
|
1888
1936
|
* Returns true iff this path is a child of a mixed schema.
|
|
1889
1937
|
*
|
|
1890
|
-
* @param {
|
|
1891
|
-
* @return {
|
|
1938
|
+
* @param {string} path
|
|
1939
|
+
* @return {boolean}
|
|
1892
1940
|
* @api private
|
|
1893
1941
|
*/
|
|
1894
1942
|
|
|
@@ -1909,7 +1957,7 @@ Schema.prototype.hasMixedParent = function(path) {
|
|
|
1909
1957
|
/**
|
|
1910
1958
|
* Setup updatedAt and createdAt timestamps to documents if enabled
|
|
1911
1959
|
*
|
|
1912
|
-
* @param {
|
|
1960
|
+
* @param {boolean|object} timestamps timestamps options
|
|
1913
1961
|
* @api private
|
|
1914
1962
|
*/
|
|
1915
1963
|
Schema.prototype.setupTimestamp = function(timestamps) {
|
|
@@ -1918,8 +1966,8 @@ Schema.prototype.setupTimestamp = function(timestamps) {
|
|
|
1918
1966
|
|
|
1919
1967
|
/**
|
|
1920
1968
|
* ignore. Deprecated re: #6405
|
|
1921
|
-
* @param {
|
|
1922
|
-
* @param {
|
|
1969
|
+
* @param {any} self
|
|
1970
|
+
* @param {string} path
|
|
1923
1971
|
* @api private
|
|
1924
1972
|
*/
|
|
1925
1973
|
|
|
@@ -1945,10 +1993,10 @@ function getPositionalPathType(self, path, cleanPath) {
|
|
|
1945
1993
|
|
|
1946
1994
|
if (i === last && val && !/\D/.test(subpath)) {
|
|
1947
1995
|
if (val.$isMongooseDocumentArray) {
|
|
1948
|
-
val = val
|
|
1996
|
+
val = val.embeddedSchemaType;
|
|
1949
1997
|
} else if (val instanceof MongooseTypes.Array) {
|
|
1950
1998
|
// StringSchema, NumberSchema, etc
|
|
1951
|
-
val = val.
|
|
1999
|
+
val = val.embeddedSchemaType;
|
|
1952
2000
|
} else {
|
|
1953
2001
|
val = undefined;
|
|
1954
2002
|
}
|
|
@@ -1959,12 +2007,12 @@ function getPositionalPathType(self, path, cleanPath) {
|
|
|
1959
2007
|
if (!/\D/.test(subpath)) {
|
|
1960
2008
|
// Nested array
|
|
1961
2009
|
if (val instanceof MongooseTypes.Array && i !== last) {
|
|
1962
|
-
val = val.
|
|
2010
|
+
val = val.embeddedSchemaType;
|
|
1963
2011
|
}
|
|
1964
2012
|
continue;
|
|
1965
2013
|
}
|
|
1966
2014
|
|
|
1967
|
-
if (!
|
|
2015
|
+
if (!val?.schema) {
|
|
1968
2016
|
val = undefined;
|
|
1969
2017
|
break;
|
|
1970
2018
|
}
|
|
@@ -2005,7 +2053,7 @@ function getPositionalPath(self, path, cleanPath) {
|
|
|
2005
2053
|
* const Model = mongoose.model('Test', schema);
|
|
2006
2054
|
* new Model({ name: 'test' }); // Prints '{"_id": ..., "name": "test" }'
|
|
2007
2055
|
*
|
|
2008
|
-
* @param {
|
|
2056
|
+
* @param {string} name name of the document method to call later
|
|
2009
2057
|
* @param {Array} args arguments to pass to the method
|
|
2010
2058
|
* @api public
|
|
2011
2059
|
*/
|
|
@@ -2022,23 +2070,21 @@ Schema.prototype.queue = function(name, args) {
|
|
|
2022
2070
|
*
|
|
2023
2071
|
* const toySchema = new Schema({ name: String, created: Date });
|
|
2024
2072
|
*
|
|
2025
|
-
* toySchema.pre('save', function(
|
|
2073
|
+
* toySchema.pre('save', function() {
|
|
2026
2074
|
* if (!this.created) this.created = new Date;
|
|
2027
|
-
* next();
|
|
2028
2075
|
* });
|
|
2029
2076
|
*
|
|
2030
|
-
* toySchema.pre('validate', function(
|
|
2077
|
+
* toySchema.pre('validate', function() {
|
|
2031
2078
|
* if (this.name !== 'Woody') this.name = 'Woody';
|
|
2032
|
-
* next();
|
|
2033
2079
|
* });
|
|
2034
2080
|
*
|
|
2035
2081
|
* // Equivalent to calling `pre()` on `find`, `findOne`, `findOneAndUpdate`.
|
|
2036
|
-
* toySchema.pre(/^find/, function(
|
|
2082
|
+
* toySchema.pre(/^find/, function() {
|
|
2037
2083
|
* console.log(this.getFilter());
|
|
2038
2084
|
* });
|
|
2039
2085
|
*
|
|
2040
2086
|
* // Equivalent to calling `pre()` on `updateOne`, `findOneAndUpdate`.
|
|
2041
|
-
* toySchema.pre(['updateOne', 'findOneAndUpdate'], function(
|
|
2087
|
+
* toySchema.pre(['updateOne', 'findOneAndUpdate'], function() {
|
|
2042
2088
|
* console.log(this.getFilter());
|
|
2043
2089
|
* });
|
|
2044
2090
|
*
|
|
@@ -2050,10 +2096,10 @@ Schema.prototype.queue = function(name, args) {
|
|
|
2050
2096
|
* // Runs when you call `doc.deleteOne()`
|
|
2051
2097
|
* });
|
|
2052
2098
|
*
|
|
2053
|
-
* @param {
|
|
2054
|
-
* @param {
|
|
2055
|
-
* @param {
|
|
2056
|
-
* @param {
|
|
2099
|
+
* @param {string|RegExp|string[]} methodName The method name or regular expression to match method name
|
|
2100
|
+
* @param {object} [options]
|
|
2101
|
+
* @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()`.
|
|
2102
|
+
* @param {boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
|
|
2057
2103
|
* @param {Function} callback
|
|
2058
2104
|
* @api public
|
|
2059
2105
|
*/
|
|
@@ -2104,10 +2150,10 @@ Schema.prototype.pre = function(name) {
|
|
|
2104
2150
|
* await m.find();
|
|
2105
2151
|
* console.log('this fires after the post find hook');
|
|
2106
2152
|
*
|
|
2107
|
-
* @param {
|
|
2108
|
-
* @param {
|
|
2109
|
-
* @param {
|
|
2110
|
-
* @param {
|
|
2153
|
+
* @param {string|RegExp|string[]} methodName The method name or regular expression to match method name
|
|
2154
|
+
* @param {object} [options]
|
|
2155
|
+
* @param {boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware.
|
|
2156
|
+
* @param {boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
|
|
2111
2157
|
* @param {Function} fn callback
|
|
2112
2158
|
* @see middleware https://mongoosejs.com/docs/middleware.html
|
|
2113
2159
|
* @see kareem https://npmjs.org/package/kareem
|
|
@@ -2151,20 +2197,20 @@ Schema.prototype.post = function(name) {
|
|
|
2151
2197
|
* mongoose.model('Test', s); // Prints 'Schema Path Name: name'
|
|
2152
2198
|
*
|
|
2153
2199
|
* @param {Function} plugin The Plugin's callback
|
|
2154
|
-
* @param {
|
|
2155
|
-
* @param {
|
|
2200
|
+
* @param {object} [opts] Options to pass to the plugin
|
|
2201
|
+
* @param {boolean} [opts.deduplicate=false] If true, ignore duplicate plugins (same `fn` argument using `===`)
|
|
2156
2202
|
* @see plugins https://mongoosejs.com/docs/plugins.html
|
|
2157
2203
|
* @api public
|
|
2158
2204
|
*/
|
|
2159
2205
|
|
|
2160
2206
|
Schema.prototype.plugin = function(fn, opts) {
|
|
2161
2207
|
if (typeof fn !== 'function') {
|
|
2162
|
-
throw new
|
|
2208
|
+
throw new MongooseError('First param to `schema.plugin()` must be a function, ' +
|
|
2163
2209
|
'got "' + (typeof fn) + '"');
|
|
2164
2210
|
}
|
|
2165
2211
|
|
|
2166
2212
|
|
|
2167
|
-
if (opts
|
|
2213
|
+
if (opts?.deduplicate) {
|
|
2168
2214
|
for (const plugin of this.plugins) {
|
|
2169
2215
|
if (plugin.fn === fn) {
|
|
2170
2216
|
return this;
|
|
@@ -2207,7 +2253,7 @@ Schema.prototype.plugin = function(fn, opts) {
|
|
|
2207
2253
|
*
|
|
2208
2254
|
* 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
2255
|
*
|
|
2210
|
-
* @param {
|
|
2256
|
+
* @param {string|object} name The Method Name for a single function, or an Object of "string-function" pairs.
|
|
2211
2257
|
* @param {Function} [fn] The Function in a single-function definition.
|
|
2212
2258
|
* @api public
|
|
2213
2259
|
*/
|
|
@@ -2252,7 +2298,7 @@ Schema.prototype.method = function(name, fn, options) {
|
|
|
2252
2298
|
*
|
|
2253
2299
|
* If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as statics.
|
|
2254
2300
|
*
|
|
2255
|
-
* @param {
|
|
2301
|
+
* @param {string|object} name The Method Name for a single function, or an Object of "string-function" pairs.
|
|
2256
2302
|
* @param {Function} [fn] The Function in a single-function definition.
|
|
2257
2303
|
* @api public
|
|
2258
2304
|
* @see Statics https://mongoosejs.com/docs/guide.html#statics
|
|
@@ -2276,10 +2322,10 @@ Schema.prototype.static = function(name, fn) {
|
|
|
2276
2322
|
*
|
|
2277
2323
|
* schema.index({ first: 1, last: -1 })
|
|
2278
2324
|
*
|
|
2279
|
-
* @param {
|
|
2280
|
-
* @param {
|
|
2281
|
-
* @param {
|
|
2282
|
-
* @param {
|
|
2325
|
+
* @param {object} fields The Fields to index, with the order, available values: `1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text'`
|
|
2326
|
+
* @param {object} [options] Options to pass to [MongoDB driver's `createIndex()` function](https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#createIndex)
|
|
2327
|
+
* @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.
|
|
2328
|
+
* @param {string} [options.language_override=null] Tells mongodb to use the specified field instead of `language` for parsing text indexes.
|
|
2283
2329
|
* @api public
|
|
2284
2330
|
*/
|
|
2285
2331
|
|
|
@@ -2303,12 +2349,6 @@ Schema.prototype.index = function(fields, options) {
|
|
|
2303
2349
|
}
|
|
2304
2350
|
}
|
|
2305
2351
|
|
|
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
2352
|
this._indexes.push([fields, options]);
|
|
2313
2353
|
return this;
|
|
2314
2354
|
};
|
|
@@ -2322,9 +2362,9 @@ Schema.prototype.index = function(fields, options) {
|
|
|
2322
2362
|
* schema.set('strict', false); // Sets 'strict' to false
|
|
2323
2363
|
* schema.set('strict'); // 'false'
|
|
2324
2364
|
*
|
|
2325
|
-
* @param {
|
|
2326
|
-
* @param {
|
|
2327
|
-
* @param {
|
|
2365
|
+
* @param {string} key The name of the option to set the value to
|
|
2366
|
+
* @param {object} [value] The value to set the option to, if not passed, the option will be reset to default
|
|
2367
|
+
* @param {string[]} [tags] tags to add to read preference if key === 'read'
|
|
2328
2368
|
* @see Schema https://mongoosejs.com/docs/api/schema.html#Schema()
|
|
2329
2369
|
* @api public
|
|
2330
2370
|
*/
|
|
@@ -2415,9 +2455,9 @@ function _propagateOptionsToImplicitlyCreatedSchemas(baseSchema, options) {
|
|
|
2415
2455
|
* schema.set('strict', false);
|
|
2416
2456
|
* schema.get('strict'); // false
|
|
2417
2457
|
*
|
|
2418
|
-
* @param {
|
|
2458
|
+
* @param {string} key The name of the Option to get the current value for
|
|
2419
2459
|
* @api public
|
|
2420
|
-
* @return {
|
|
2460
|
+
* @return {any} the option's value
|
|
2421
2461
|
*/
|
|
2422
2462
|
|
|
2423
2463
|
Schema.prototype.get = function(key) {
|
|
@@ -2429,7 +2469,7 @@ const indexTypes = '2d 2dsphere hashed text'.split(' ');
|
|
|
2429
2469
|
/**
|
|
2430
2470
|
* The allowed index types
|
|
2431
2471
|
*
|
|
2432
|
-
* @property {
|
|
2472
|
+
* @property {string[]} indexTypes
|
|
2433
2473
|
* @memberOf Schema
|
|
2434
2474
|
* @static
|
|
2435
2475
|
* @api public
|
|
@@ -2440,7 +2480,7 @@ Object.defineProperty(Schema, 'indexTypes', {
|
|
|
2440
2480
|
return indexTypes;
|
|
2441
2481
|
},
|
|
2442
2482
|
set: function() {
|
|
2443
|
-
throw new
|
|
2483
|
+
throw new MongooseError('Cannot overwrite Schema.indexTypes');
|
|
2444
2484
|
}
|
|
2445
2485
|
});
|
|
2446
2486
|
|
|
@@ -2455,8 +2495,8 @@ Object.defineProperty(Schema, 'indexTypes', {
|
|
|
2455
2495
|
* registeredAt: { type: Date, index: true }
|
|
2456
2496
|
* });
|
|
2457
2497
|
*
|
|
2458
|
-
* // [ [ { email: 1 }, { unique: true
|
|
2459
|
-
* // [ { registeredAt: 1 }, {
|
|
2498
|
+
* // [ [ { email: 1 }, { unique: true } ],
|
|
2499
|
+
* // [ { registeredAt: 1 }, {} ] ]
|
|
2460
2500
|
* userSchema.indexes();
|
|
2461
2501
|
*
|
|
2462
2502
|
* [Plugins](https://mongoosejs.com/docs/plugins.html) can use the return value of this function to modify a schema's indexes.
|
|
@@ -2481,16 +2521,16 @@ Schema.prototype.indexes = function() {
|
|
|
2481
2521
|
/**
|
|
2482
2522
|
* Creates a virtual type with the given name.
|
|
2483
2523
|
*
|
|
2484
|
-
* @param {
|
|
2485
|
-
* @param {
|
|
2486
|
-
* @param {
|
|
2487
|
-
* @param {
|
|
2488
|
-
* @param {
|
|
2489
|
-
* @param {
|
|
2490
|
-
* @param {
|
|
2524
|
+
* @param {string} name The name of the Virtual
|
|
2525
|
+
* @param {object} [options]
|
|
2526
|
+
* @param {string|Model} [options.ref] model name or model instance. Marks this as a [populate virtual](https://mongoosejs.com/docs/populate.html#populate-virtuals).
|
|
2527
|
+
* @param {string|Function} [options.localField] Required for populate virtuals. See [populate virtual docs](https://mongoosejs.com/docs/populate.html#populate-virtuals) for more information.
|
|
2528
|
+
* @param {string|Function} [options.foreignField] Required for populate virtuals. See [populate virtual docs](https://mongoosejs.com/docs/populate.html#populate-virtuals) for more information.
|
|
2529
|
+
* @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.
|
|
2530
|
+
* @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
2531
|
* @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 {
|
|
2493
|
-
* @param {
|
|
2532
|
+
* @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.
|
|
2533
|
+
* @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
2534
|
* @return {VirtualType}
|
|
2495
2535
|
*/
|
|
2496
2536
|
|
|
@@ -2502,11 +2542,11 @@ Schema.prototype.virtual = function(name, options) {
|
|
|
2502
2542
|
|
|
2503
2543
|
if (utils.hasUserDefinedProperty(options, ['ref', 'refPath'])) {
|
|
2504
2544
|
if (options.localField == null) {
|
|
2505
|
-
throw new
|
|
2545
|
+
throw new MongooseError('Reference virtuals require `localField` option');
|
|
2506
2546
|
}
|
|
2507
2547
|
|
|
2508
2548
|
if (options.foreignField == null) {
|
|
2509
|
-
throw new
|
|
2549
|
+
throw new MongooseError('Reference virtuals require `foreignField` option');
|
|
2510
2550
|
}
|
|
2511
2551
|
|
|
2512
2552
|
const virtual = this.virtual(name);
|
|
@@ -2602,7 +2642,7 @@ Schema.prototype.virtual = function(name, options) {
|
|
|
2602
2642
|
const parts = name.split('.');
|
|
2603
2643
|
|
|
2604
2644
|
if (this.pathType(name) === 'real') {
|
|
2605
|
-
throw new
|
|
2645
|
+
throw new MongooseError('Virtual path "' + name + '"' +
|
|
2606
2646
|
' conflicts with a real path in the schema');
|
|
2607
2647
|
}
|
|
2608
2648
|
|
|
@@ -2613,9 +2653,9 @@ Schema.prototype.virtual = function(name, options) {
|
|
|
2613
2653
|
return mem[part];
|
|
2614
2654
|
}, this.tree);
|
|
2615
2655
|
|
|
2616
|
-
if (options
|
|
2656
|
+
if (options?.applyToArray && parts.length > 1) {
|
|
2617
2657
|
const path = this.path(parts.slice(0, -1).join('.'));
|
|
2618
|
-
if (path
|
|
2658
|
+
if (path?.$isMongooseArray) {
|
|
2619
2659
|
return path.virtual(parts[parts.length - 1], options);
|
|
2620
2660
|
} else {
|
|
2621
2661
|
throw new MongooseError(`Path "${path}" is not an array`);
|
|
@@ -2628,7 +2668,7 @@ Schema.prototype.virtual = function(name, options) {
|
|
|
2628
2668
|
/**
|
|
2629
2669
|
* Returns the virtual type with the given `name`.
|
|
2630
2670
|
*
|
|
2631
|
-
* @param {
|
|
2671
|
+
* @param {string} name The name of the Virtual to get
|
|
2632
2672
|
* @return {VirtualType|null}
|
|
2633
2673
|
*/
|
|
2634
2674
|
|
|
@@ -2652,7 +2692,7 @@ Schema.prototype.virtualpath = function(name) {
|
|
|
2652
2692
|
* schema.path('name'); // Undefined
|
|
2653
2693
|
* schema.path('age'); // Undefined
|
|
2654
2694
|
*
|
|
2655
|
-
* @param {
|
|
2695
|
+
* @param {string|Array} path The Path(s) to remove
|
|
2656
2696
|
* @return {Schema} the Schema instance
|
|
2657
2697
|
* @api public
|
|
2658
2698
|
*/
|
|
@@ -2710,7 +2750,7 @@ function _deletePath(schema, name) {
|
|
|
2710
2750
|
/**
|
|
2711
2751
|
* Removes the given virtual or virtuals from the schema.
|
|
2712
2752
|
*
|
|
2713
|
-
* @param {
|
|
2753
|
+
* @param {string|Array} path The virutal path(s) to remove.
|
|
2714
2754
|
* @returns {Schema} the Schema instance, or a mongoose error if the virtual does not exist.
|
|
2715
2755
|
* @api public
|
|
2716
2756
|
*/
|
|
@@ -2775,7 +2815,7 @@ Schema.prototype.removeVirtual = function(path) {
|
|
|
2775
2815
|
* ```
|
|
2776
2816
|
*
|
|
2777
2817
|
* @param {Function} model The Class to load
|
|
2778
|
-
* @param {
|
|
2818
|
+
* @param {boolean} [virtualsOnly] if truthy, only pulls virtuals from the class, not methods or statics
|
|
2779
2819
|
*/
|
|
2780
2820
|
Schema.prototype.loadClass = function(model, virtualsOnly) {
|
|
2781
2821
|
// Stop copying when hit certain base classes
|
|
@@ -2854,11 +2894,11 @@ Schema.prototype._getSchema = function(path) {
|
|
|
2854
2894
|
if (foundschema) {
|
|
2855
2895
|
resultPath.push(trypath);
|
|
2856
2896
|
|
|
2857
|
-
if (foundschema.
|
|
2897
|
+
if (foundschema.embeddedSchemaType || foundschema.Constructor) {
|
|
2858
2898
|
// array of Mixed?
|
|
2859
|
-
if (foundschema.
|
|
2860
|
-
foundschema.
|
|
2861
|
-
return foundschema.
|
|
2899
|
+
if (foundschema.embeddedSchemaType instanceof MongooseTypes.Mixed) {
|
|
2900
|
+
foundschema.embeddedSchemaType.$fullPath = resultPath.join('.');
|
|
2901
|
+
return foundschema.embeddedSchemaType;
|
|
2862
2902
|
}
|
|
2863
2903
|
|
|
2864
2904
|
// Now that we found the array, we need to check if there
|
|
@@ -2868,8 +2908,8 @@ Schema.prototype._getSchema = function(path) {
|
|
|
2868
2908
|
// If there is no foundschema.schema we are dealing with
|
|
2869
2909
|
// a path like array.$
|
|
2870
2910
|
if (p !== parts.length) {
|
|
2871
|
-
if (p + 1 === parts.length && foundschema
|
|
2872
|
-
return foundschema
|
|
2911
|
+
if (p + 1 === parts.length && foundschema.embeddedSchemaType && (parts[p] === '$' || isArrayFilter(parts[p]))) {
|
|
2912
|
+
return foundschema.embeddedSchemaType;
|
|
2873
2913
|
}
|
|
2874
2914
|
|
|
2875
2915
|
if (foundschema.schema) {
|
|
@@ -2877,7 +2917,7 @@ Schema.prototype._getSchema = function(path) {
|
|
|
2877
2917
|
if (parts[p] === '$' || isArrayFilter(parts[p])) {
|
|
2878
2918
|
if (p + 1 === parts.length) {
|
|
2879
2919
|
// comments.$
|
|
2880
|
-
return foundschema
|
|
2920
|
+
return foundschema.embeddedSchemaType;
|
|
2881
2921
|
}
|
|
2882
2922
|
// comments.$.comments.$.title
|
|
2883
2923
|
ret = search(parts.slice(p + 1), foundschema.schema);
|
|
@@ -2957,9 +2997,9 @@ Schema.prototype._getPathType = function(path) {
|
|
|
2957
2997
|
trypath = parts.slice(0, p).join('.');
|
|
2958
2998
|
foundschema = schema.path(trypath);
|
|
2959
2999
|
if (foundschema) {
|
|
2960
|
-
if (foundschema.
|
|
3000
|
+
if (foundschema.embeddedSchemaType || foundschema.Constructor) {
|
|
2961
3001
|
// array of Mixed?
|
|
2962
|
-
if (foundschema.
|
|
3002
|
+
if (foundschema.embeddedSchemaType instanceof MongooseTypes.Mixed) {
|
|
2963
3003
|
return { schema: foundschema, pathType: 'mixed' };
|
|
2964
3004
|
}
|
|
2965
3005
|
|
|
@@ -3049,8 +3089,27 @@ function isArrayFilter(piece) {
|
|
|
3049
3089
|
|
|
3050
3090
|
Schema.prototype._preCompile = function _preCompile() {
|
|
3051
3091
|
this.plugin(idGetter, { deduplicate: true });
|
|
3092
|
+
_precomputeOptimisticConcurrency(this);
|
|
3052
3093
|
};
|
|
3053
3094
|
|
|
3095
|
+
/*!
|
|
3096
|
+
* Build precomputed sets for optimisticConcurrency include/exclude,
|
|
3097
|
+
* expanding user-specified paths to include all schema subpaths so that
|
|
3098
|
+
* lookups at save time are a simple `Set.has()`.
|
|
3099
|
+
*/
|
|
3100
|
+
|
|
3101
|
+
function _precomputeOptimisticConcurrency(schema) {
|
|
3102
|
+
const opt = schema.options.optimisticConcurrency;
|
|
3103
|
+
if (!opt || opt === true) {
|
|
3104
|
+
return;
|
|
3105
|
+
}
|
|
3106
|
+
if (Array.isArray(opt)) {
|
|
3107
|
+
schema.options._optimisticConcurrencySet = new Set(opt);
|
|
3108
|
+
} else if (Array.isArray(opt.exclude)) {
|
|
3109
|
+
schema.options._optimisticConcurrencyExcludeSet = new Set(opt.exclude);
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3054
3113
|
/**
|
|
3055
3114
|
* Returns a JSON schema representation of this Schema.
|
|
3056
3115
|
*
|
|
@@ -3062,15 +3121,15 @@ Schema.prototype._preCompile = function _preCompile() {
|
|
|
3062
3121
|
* - `enum` for strings and numbers
|
|
3063
3122
|
*
|
|
3064
3123
|
* #### Example:
|
|
3065
|
-
*
|
|
3066
|
-
*
|
|
3067
|
-
*
|
|
3124
|
+
* const schema = new Schema({ name: String });
|
|
3125
|
+
* // { required: ['_id'], properties: { name: { type: ['string', 'null'] }, _id: { type: 'string' } } }
|
|
3126
|
+
* schema.toJSONSchema();
|
|
3068
3127
|
*
|
|
3069
|
-
*
|
|
3070
|
-
*
|
|
3128
|
+
* // { required: ['_id'], properties: { name: { bsonType: ['string', 'null'] }, _id: { bsonType: 'objectId' } } }
|
|
3129
|
+
* schema.toJSONSchema({ useBsonType: true });
|
|
3071
3130
|
*
|
|
3072
|
-
* @param {
|
|
3073
|
-
* @param
|
|
3131
|
+
* @param {object} [options]
|
|
3132
|
+
* @param {boolean} [options.useBsonType=false] if true, specify each path's type using `bsonType` rather than `type` for MongoDB $jsonSchema support
|
|
3074
3133
|
*/
|
|
3075
3134
|
|
|
3076
3135
|
Schema.prototype.toJSONSchema = function toJSONSchema(options) {
|
|
@@ -3079,7 +3138,7 @@ Schema.prototype.toJSONSchema = function toJSONSchema(options) {
|
|
|
3079
3138
|
for (const path of Object.keys(this.paths)) {
|
|
3080
3139
|
const schemaType = this.paths[path];
|
|
3081
3140
|
|
|
3082
|
-
// Skip Map embedded paths, maps will be handled
|
|
3141
|
+
// Skip Map embedded paths, maps will be handled separately.
|
|
3083
3142
|
if (schemaType._presplitPath.indexOf('$*') !== -1) {
|
|
3084
3143
|
continue;
|
|
3085
3144
|
}
|