@nullix/zod-mongoose-studio 1.0.13 → 2.1.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/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/8b851c04-1848-472a-b5cd-0727aaaf90f4.json +1 -0
- package/.output/server/chunks/nitro/nitro.mjs +232 -232
- package/.output/server/chunks/routes/api/parse.post.mjs +54 -11
- package/.output/server/chunks/routes/api/parse.post.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/0d6006db-fbb0-4297-85cf-bf92ceafcb79.json +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
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MongoClient = exports.ServerApiVersion = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
|
+
const _1 = require(".");
|
|
5
6
|
const bson_1 = require("./bson");
|
|
6
7
|
const change_stream_1 = require("./change_stream");
|
|
7
8
|
const mongo_credentials_1 = require("./cmap/auth/mongo_credentials");
|
|
8
9
|
const providers_1 = require("./cmap/auth/providers");
|
|
9
10
|
const client_metadata_1 = require("./cmap/handshake/client_metadata");
|
|
10
|
-
const responses_1 = require("./cmap/wire_protocol/responses");
|
|
11
11
|
const connection_string_1 = require("./connection_string");
|
|
12
12
|
const constants_1 = require("./constants");
|
|
13
13
|
const db_1 = require("./db");
|
|
@@ -16,10 +16,9 @@ const mongo_client_auth_providers_1 = require("./mongo_client_auth_providers");
|
|
|
16
16
|
const mongo_logger_1 = require("./mongo_logger");
|
|
17
17
|
const mongo_types_1 = require("./mongo_types");
|
|
18
18
|
const executor_1 = require("./operations/client_bulk_write/executor");
|
|
19
|
+
const end_sessions_1 = require("./operations/end_sessions");
|
|
19
20
|
const execute_operation_1 = require("./operations/execute_operation");
|
|
20
|
-
const operation_1 = require("./operations/operation");
|
|
21
21
|
const read_preference_1 = require("./read_preference");
|
|
22
|
-
const resource_management_1 = require("./resource_management");
|
|
23
22
|
const server_selection_1 = require("./sdam/server_selection");
|
|
24
23
|
const topology_1 = require("./sdam/topology");
|
|
25
24
|
const sessions_1 = require("./sessions");
|
|
@@ -101,8 +100,11 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
|
|
|
101
100
|
};
|
|
102
101
|
this.checkForNonGenuineHosts();
|
|
103
102
|
}
|
|
104
|
-
/**
|
|
105
|
-
|
|
103
|
+
/**
|
|
104
|
+
* @experimental
|
|
105
|
+
* An alias for {@link MongoClient.close|MongoClient.close()}.
|
|
106
|
+
*/
|
|
107
|
+
async [Symbol.asyncDispose]() {
|
|
106
108
|
await this.close();
|
|
107
109
|
}
|
|
108
110
|
/**
|
|
@@ -114,8 +116,7 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
|
|
|
114
116
|
if (isDuplicateDriverInfo)
|
|
115
117
|
return;
|
|
116
118
|
this.driverInfoList.push(driverInfo);
|
|
117
|
-
this.options.metadata = (0, client_metadata_1.makeClientMetadata)(this.driverInfoList, this.options)
|
|
118
|
-
this.options.extendedMetadata = (0, client_metadata_1.addContainerMetadata)(this.options.metadata)
|
|
119
|
+
this.options.metadata = (0, client_metadata_1.makeClientMetadata)(this.driverInfoList, this.options)
|
|
119
120
|
.then(undefined, utils_1.squashError)
|
|
120
121
|
.then(result => result ?? {}); // ensure Promise<Document>
|
|
121
122
|
}
|
|
@@ -178,20 +179,13 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
|
|
|
178
179
|
return await new executor_1.ClientBulkWriteExecutor(this, models, (0, utils_1.resolveOptions)(this, options)).execute();
|
|
179
180
|
}
|
|
180
181
|
/**
|
|
181
|
-
*
|
|
182
|
+
* An optional method to verify a handful of assumptions that are generally useful at application boot-time before using a MongoClient.
|
|
183
|
+
* For detailed information about the connect process see the MongoClient.connect static method documentation.
|
|
182
184
|
*
|
|
183
|
-
* @
|
|
184
|
-
*
|
|
185
|
-
* `timeoutMS` will bound the time any operation can take before throwing a timeout error.
|
|
186
|
-
* However, when the operation being run is automatically connecting your `MongoClient` the `timeoutMS` will not apply to the time taken to connect the MongoClient.
|
|
187
|
-
* This means the time to setup the `MongoClient` does not count against `timeoutMS`.
|
|
188
|
-
* If you are using `timeoutMS` we recommend connecting your client explicitly in advance of any operation to avoid this inconsistent execution time.
|
|
185
|
+
* @param url - The MongoDB connection string (supports `mongodb://` and `mongodb+srv://` schemes)
|
|
186
|
+
* @param options - Optional configuration options for the client
|
|
189
187
|
*
|
|
190
|
-
* @
|
|
191
|
-
* The driver will look up corresponding SRV and TXT records if the connection string starts with `mongodb+srv://`.
|
|
192
|
-
* If those look ups throw a DNS Timeout error, the driver will retry the look up once.
|
|
193
|
-
*
|
|
194
|
-
* @see docs.mongodb.org/manual/reference/connection-string/
|
|
188
|
+
* @see https://www.mongodb.com/docs/manual/reference/connection-string/
|
|
195
189
|
*/
|
|
196
190
|
async connect() {
|
|
197
191
|
if (this.connectionLock) {
|
|
@@ -355,44 +349,10 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
|
|
|
355
349
|
if (this.topology == null) {
|
|
356
350
|
return;
|
|
357
351
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const serverDescriptions = Array.from(topologyDescription.servers.values());
|
|
363
|
-
const servers = selector(topologyDescription, serverDescriptions);
|
|
364
|
-
if (servers.length !== 0) {
|
|
365
|
-
const endSessions = Array.from(this.s.sessionPool.sessions, ({ id }) => id);
|
|
366
|
-
if (endSessions.length !== 0) {
|
|
367
|
-
try {
|
|
368
|
-
class EndSessionsOperation extends operation_1.AbstractOperation {
|
|
369
|
-
constructor() {
|
|
370
|
-
super(...arguments);
|
|
371
|
-
this.ns = utils_1.MongoDBNamespace.fromString('admin.$cmd');
|
|
372
|
-
this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
|
|
373
|
-
}
|
|
374
|
-
buildCommand(_connection, _session) {
|
|
375
|
-
return {
|
|
376
|
-
endSessions
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
buildOptions(timeoutContext) {
|
|
380
|
-
return {
|
|
381
|
-
timeoutContext,
|
|
382
|
-
readPreference: read_preference_1.ReadPreference.primaryPreferred,
|
|
383
|
-
noResponse: true
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
get commandName() {
|
|
387
|
-
return 'endSessions';
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
await (0, execute_operation_1.executeOperation)(this, new EndSessionsOperation());
|
|
391
|
-
}
|
|
392
|
-
catch (error) {
|
|
393
|
-
(0, utils_1.squashError)(error);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
352
|
+
const supportsSessions = this.topology.description.type === _1.TopologyType.LoadBalanced ||
|
|
353
|
+
this.topology.description.logicalSessionTimeoutMinutes != null;
|
|
354
|
+
if (supportsSessions) {
|
|
355
|
+
await endSessions(this, this.topology);
|
|
396
356
|
}
|
|
397
357
|
// clear out references to old topology
|
|
398
358
|
const topology = this.topology;
|
|
@@ -402,6 +362,24 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
|
|
|
402
362
|
if (encrypter) {
|
|
403
363
|
await encrypter.close(this);
|
|
404
364
|
}
|
|
365
|
+
async function endSessions(client, { description: topologyDescription }) {
|
|
366
|
+
// If we would attempt to select a server and get nothing back we short circuit
|
|
367
|
+
// to avoid the server selection timeout.
|
|
368
|
+
const selector = (0, server_selection_1.readPreferenceServerSelector)(read_preference_1.ReadPreference.primaryPreferred);
|
|
369
|
+
const serverDescriptions = Array.from(topologyDescription.servers.values());
|
|
370
|
+
const servers = selector(topologyDescription, serverDescriptions, new server_selection_1.DeprioritizedServers());
|
|
371
|
+
if (servers.length !== 0) {
|
|
372
|
+
const endSessions = Array.from(client.s.sessionPool.sessions, ({ id }) => id);
|
|
373
|
+
if (endSessions.length !== 0) {
|
|
374
|
+
try {
|
|
375
|
+
await (0, execute_operation_1.executeOperation)(client, new end_sessions_1.EndSessionsOperation(endSessions));
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
(0, utils_1.squashError)(error);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
405
383
|
}
|
|
406
384
|
/**
|
|
407
385
|
* Create a new Db instance sharing the current socket connections.
|
|
@@ -423,21 +401,35 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
|
|
|
423
401
|
return db;
|
|
424
402
|
}
|
|
425
403
|
/**
|
|
426
|
-
*
|
|
404
|
+
* Creates a new MongoClient instance and immediately connects it to MongoDB.
|
|
405
|
+
* This convenience method combines `new MongoClient(url, options)` and `client.connect()` in a single step.
|
|
406
|
+
*
|
|
407
|
+
* Connect can be helpful to detect configuration issues early by validating:
|
|
408
|
+
* - **DNS Resolution**: Verifies that SRV records and hostnames in the connection string resolve DNS entries
|
|
409
|
+
* - **Network Connectivity**: Confirms that host addresses are reachable and ports are open
|
|
410
|
+
* - **TLS Configuration**: Validates SSL/TLS certificates, CA files, and encryption settings are correct
|
|
411
|
+
* - **Authentication**: Verifies that provided credentials are valid
|
|
412
|
+
* - **Server Compatibility**: Ensures the MongoDB server version is supported by this driver version
|
|
413
|
+
* - **Load Balancer Setup**: For load-balanced deployments, confirms the service is properly configured
|
|
414
|
+
*
|
|
415
|
+
* @returns A promise that resolves to the same MongoClient instance once connected
|
|
427
416
|
*
|
|
428
417
|
* @remarks
|
|
429
|
-
* Calling `connect` is optional since
|
|
430
|
-
*
|
|
431
|
-
* However,
|
|
432
|
-
*
|
|
433
|
-
*
|
|
418
|
+
* **Connection is Optional:** Calling `connect` is optional since any operation method (`find`, `insertOne`, etc.)
|
|
419
|
+
* will automatically perform these same validation steps if the client is not already connected.
|
|
420
|
+
* However, explicitly calling `connect` can make sense for:
|
|
421
|
+
* - **Fail-fast Error Detection**: Non-transient connection issues (hostname unresolved, port refused connection) are discovered immediately rather than during your first operation
|
|
422
|
+
* - **Predictable Performance**: Eliminates first connection overhead from your first database operation
|
|
434
423
|
*
|
|
435
424
|
* @remarks
|
|
436
|
-
*
|
|
425
|
+
* **Connection Pooling Impact:** Calling `connect` will populate the connection pool with one connection
|
|
426
|
+
* to a server selected by the client's configured `readPreference` (defaults to primary).
|
|
437
427
|
*
|
|
438
428
|
* @remarks
|
|
439
|
-
*
|
|
440
|
-
*
|
|
429
|
+
* **Timeout Behavior:** When using `timeoutMS`, the connection establishment time does not count against
|
|
430
|
+
* the timeout for subsequent operations. This means `connect` runs without a `timeoutMS` limit, while
|
|
431
|
+
* your database operations will still respect the configured timeout. If you need predictable operation
|
|
432
|
+
* timing with `timeoutMS`, call `connect` explicitly before performing operations.
|
|
441
433
|
*
|
|
442
434
|
* @see https://www.mongodb.com/docs/manual/reference/connection-string/
|
|
443
435
|
*/
|
|
@@ -562,5 +554,4 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
|
|
|
562
554
|
}
|
|
563
555
|
}
|
|
564
556
|
exports.MongoClient = MongoClient;
|
|
565
|
-
(0, resource_management_1.configureResourceManagement)(MongoClient.prototype);
|
|
566
557
|
//# sourceMappingURL=mongo_client.js.map
|
|
@@ -18,12 +18,6 @@ const AUTH_PROVIDERS = new Map([
|
|
|
18
18
|
providers_1.AuthMechanism.MONGODB_AWS,
|
|
19
19
|
({ AWS_CREDENTIAL_PROVIDER }) => new mongodb_aws_1.MongoDBAWS(AWS_CREDENTIAL_PROVIDER)
|
|
20
20
|
],
|
|
21
|
-
[
|
|
22
|
-
providers_1.AuthMechanism.MONGODB_CR,
|
|
23
|
-
() => {
|
|
24
|
-
throw new error_1.MongoInvalidArgumentError('MONGODB-CR is no longer a supported auth mechanism in MongoDB 4.0+');
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
21
|
[providers_1.AuthMechanism.MONGODB_GSSAPI, () => new gssapi_1.GSSAPI()],
|
|
28
22
|
[providers_1.AuthMechanism.MONGODB_OIDC, properties => new mongodb_oidc_1.MongoDBOIDC(getWorkflow(properties))],
|
|
29
23
|
[providers_1.AuthMechanism.MONGODB_PLAIN, () => new plain_1.Plain()],
|
|
@@ -5,6 +5,7 @@ exports.parseSeverityFromString = parseSeverityFromString;
|
|
|
5
5
|
exports.createStdioLogger = createStdioLogger;
|
|
6
6
|
exports.stringifyWithMaxLen = stringifyWithMaxLen;
|
|
7
7
|
exports.defaultLogTransform = defaultLogTransform;
|
|
8
|
+
const process = require("process");
|
|
8
9
|
const util_1 = require("util");
|
|
9
10
|
const bson_1 = require("./bson");
|
|
10
11
|
const constants_1 = require("./constants");
|
|
@@ -84,11 +85,16 @@ function parseSeverityFromString(s) {
|
|
|
84
85
|
/** @internal */
|
|
85
86
|
function createStdioLogger(stream) {
|
|
86
87
|
return {
|
|
87
|
-
write: (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
write: (log) => {
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
const logLine = (0, util_1.inspect)(log, { compact: true, breakLength: Infinity });
|
|
91
|
+
stream.write(`${logLine}\n`, 'utf-8', error => {
|
|
92
|
+
if (error)
|
|
93
|
+
return reject(error);
|
|
94
|
+
resolve(true);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
92
98
|
};
|
|
93
99
|
}
|
|
94
100
|
/**
|
|
@@ -44,8 +44,7 @@ class TypedEventEmitter extends events_1.EventEmitter {
|
|
|
44
44
|
}
|
|
45
45
|
exports.TypedEventEmitter = TypedEventEmitter;
|
|
46
46
|
/**
|
|
47
|
-
* @
|
|
48
|
-
* @deprecated Will be removed in favor of `AbortSignal` in the next major release.
|
|
47
|
+
* @internal
|
|
49
48
|
*/
|
|
50
49
|
class CancellationToken extends TypedEventEmitter {
|
|
51
50
|
constructor(...args) {
|
|
@@ -32,9 +32,6 @@ class AggregateOperation extends command_1.CommandOperation {
|
|
|
32
32
|
if (!this.hasWriteStage) {
|
|
33
33
|
delete this.options.writeConcern;
|
|
34
34
|
}
|
|
35
|
-
if (this.explain && this.writeConcern) {
|
|
36
|
-
throw new error_1.MongoInvalidArgumentError('Option "explain" cannot be used on an aggregate call with writeConcern');
|
|
37
|
-
}
|
|
38
35
|
if (options?.cursor != null && typeof options.cursor !== 'object') {
|
|
39
36
|
throw new error_1.MongoInvalidArgumentError('Cursor options must be an object');
|
|
40
37
|
}
|
|
@@ -27,6 +27,13 @@ class DropCollectionOperation extends command_1.CommandOperation {
|
|
|
27
27
|
handleOk(_response) {
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
|
+
handleError(error) {
|
|
31
|
+
if (!(error instanceof __1.MongoServerError))
|
|
32
|
+
throw error;
|
|
33
|
+
if (Number(error.code) !== error_1.MONGODB_ERROR_CODES.NamespaceNotFound)
|
|
34
|
+
throw error;
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
38
|
exports.DropCollectionOperation = DropCollectionOperation;
|
|
32
39
|
async function dropCollections(db, name, options) {
|
|
@@ -58,15 +65,7 @@ async function dropCollections(db, name, options) {
|
|
|
58
65
|
for (const collectionName of [escCollection, ecocCollection]) {
|
|
59
66
|
// Drop auxilliary collections, ignoring potential NamespaceNotFound errors.
|
|
60
67
|
const dropOp = new DropCollectionOperation(db, collectionName, options);
|
|
61
|
-
|
|
62
|
-
await (0, execute_operation_1.executeOperation)(db.client, dropOp, timeoutContext);
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
if (!(err instanceof __1.MongoServerError) ||
|
|
66
|
-
err.code !== error_1.MONGODB_ERROR_CODES.NamespaceNotFound) {
|
|
67
|
-
throw err;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
68
|
+
await (0, execute_operation_1.executeOperation)(db.client, dropOp, timeoutContext);
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
return await (0, execute_operation_1.executeOperation)(db.client, new DropCollectionOperation(db, name, options), timeoutContext);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EndSessionsOperation = void 0;
|
|
4
|
+
const responses_1 = require("../cmap/wire_protocol/responses");
|
|
5
|
+
const command_1 = require("../operations/command");
|
|
6
|
+
const read_preference_1 = require("../read_preference");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const operation_1 = require("./operation");
|
|
9
|
+
class EndSessionsOperation extends command_1.CommandOperation {
|
|
10
|
+
constructor(sessions) {
|
|
11
|
+
super();
|
|
12
|
+
this.writeConcern = { w: 0 };
|
|
13
|
+
this.ns = utils_1.MongoDBNamespace.fromString('admin.$cmd');
|
|
14
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
|
|
15
|
+
this.sessions = sessions;
|
|
16
|
+
}
|
|
17
|
+
buildCommandDocument(_connection, _session) {
|
|
18
|
+
return {
|
|
19
|
+
endSessions: this.sessions
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
buildOptions(timeoutContext) {
|
|
23
|
+
return {
|
|
24
|
+
timeoutContext,
|
|
25
|
+
readPreference: read_preference_1.ReadPreference.primaryPreferred
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
get commandName() {
|
|
29
|
+
return 'endSessions';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.EndSessionsOperation = EndSessionsOperation;
|
|
33
|
+
(0, operation_1.defineAspects)(EndSessionsOperation, operation_1.Aspect.WRITE_OPERATION);
|
|
34
|
+
//# sourceMappingURL=end_sessions.js.map
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeOperation = executeOperation;
|
|
4
4
|
exports.autoConnect = autoConnect;
|
|
5
|
+
const promises_1 = require("timers/promises");
|
|
6
|
+
const constants_1 = require("../cmap/wire_protocol/constants");
|
|
5
7
|
const error_1 = require("../error");
|
|
6
8
|
const read_preference_1 = require("../read_preference");
|
|
9
|
+
const common_1 = require("../sdam/common");
|
|
7
10
|
const server_selection_1 = require("../sdam/server_selection");
|
|
8
11
|
const timeout_1 = require("../timeout");
|
|
9
12
|
const utils_1 = require("../utils");
|
|
10
13
|
const aggregate_1 = require("./aggregate");
|
|
11
14
|
const operation_1 = require("./operation");
|
|
15
|
+
const run_command_1 = require("./run_command");
|
|
12
16
|
const MMAPv1_RETRY_WRITES_ERROR_CODE = error_1.MONGODB_ERROR_CODES.IllegalOperation;
|
|
13
17
|
const MMAPv1_RETRY_WRITES_ERROR_MESSAGE = 'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.';
|
|
14
18
|
/**
|
|
@@ -23,7 +27,7 @@ const MMAPv1_RETRY_WRITES_ERROR_MESSAGE = 'This MongoDB deployment does not supp
|
|
|
23
27
|
* The expectation is that this function:
|
|
24
28
|
* - Connects the MongoClient if it has not already been connected, see {@link autoConnect}
|
|
25
29
|
* - Creates a session if none is provided and cleans up the session it creates
|
|
26
|
-
* - Tries an operation and retries under certain conditions, see {@link
|
|
30
|
+
* - Tries an operation and retries under certain conditions, see {@link executeOperationWithRetries}
|
|
27
31
|
*
|
|
28
32
|
* @typeParam T - The operation's type
|
|
29
33
|
* @typeParam TResult - The type of the operation's result, calculated from T
|
|
@@ -50,7 +54,8 @@ async function executeOperation(client, operation, timeoutContext) {
|
|
|
50
54
|
else if (session.hasEnded) {
|
|
51
55
|
throw new error_1.MongoExpiredSessionError('Use of expired sessions is not permitted');
|
|
52
56
|
}
|
|
53
|
-
else if (session.snapshotEnabled &&
|
|
57
|
+
else if (session.snapshotEnabled &&
|
|
58
|
+
(0, utils_1.maxWireVersion)(topology) < constants_1.MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION) {
|
|
54
59
|
throw new error_1.MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later');
|
|
55
60
|
}
|
|
56
61
|
else if (session.client !== client) {
|
|
@@ -75,7 +80,7 @@ async function executeOperation(client, operation, timeoutContext) {
|
|
|
75
80
|
timeoutMS: operation.options.timeoutMS
|
|
76
81
|
});
|
|
77
82
|
try {
|
|
78
|
-
return await
|
|
83
|
+
return await executeOperationWithRetries(operation, {
|
|
79
84
|
topology,
|
|
80
85
|
timeoutContext,
|
|
81
86
|
session,
|
|
@@ -111,6 +116,10 @@ async function autoConnect(client) {
|
|
|
111
116
|
}
|
|
112
117
|
return client.topology;
|
|
113
118
|
}
|
|
119
|
+
/** @internal The base backoff duration in milliseconds */
|
|
120
|
+
const BASE_BACKOFF_MS = 100;
|
|
121
|
+
/** @internal The maximum backoff duration in milliseconds */
|
|
122
|
+
const MAX_BACKOFF_MS = 10_000;
|
|
114
123
|
/**
|
|
115
124
|
* Executes an operation and retries as appropriate
|
|
116
125
|
* @internal
|
|
@@ -128,8 +137,8 @@ async function autoConnect(client) {
|
|
|
128
137
|
* @typeParam TResult - The type of the operation's result, calculated from T
|
|
129
138
|
*
|
|
130
139
|
* @param operation - The operation to execute
|
|
131
|
-
|
|
132
|
-
async function
|
|
140
|
+
*/
|
|
141
|
+
async function executeOperationWithRetries(operation, { topology, timeoutContext, session, readPreference }) {
|
|
133
142
|
let selector;
|
|
134
143
|
if (operation.hasAspect(operation_1.Aspect.MUST_SELECT_SAME_SERVER)) {
|
|
135
144
|
// GetMore and KillCursor operations must always select the same server, but run through
|
|
@@ -149,7 +158,8 @@ async function tryOperation(operation, { topology, timeoutContext, session, read
|
|
|
149
158
|
session,
|
|
150
159
|
operationName: operation.commandName,
|
|
151
160
|
timeoutContext,
|
|
152
|
-
signal: operation.options.signal
|
|
161
|
+
signal: operation.options.signal,
|
|
162
|
+
deprioritizedServers: new server_selection_1.DeprioritizedServers()
|
|
153
163
|
});
|
|
154
164
|
const hasReadAspect = operation.hasAspect(operation_1.Aspect.READ_OPERATION);
|
|
155
165
|
const hasWriteAspect = operation.hasAspect(operation_1.Aspect.WRITE_OPERATION);
|
|
@@ -166,71 +176,137 @@ async function tryOperation(operation, { topology, timeoutContext, session, read
|
|
|
166
176
|
operation.options.willRetryWrite = true;
|
|
167
177
|
session.incrementTransactionNumber();
|
|
168
178
|
}
|
|
169
|
-
const
|
|
170
|
-
let
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
const deprioritizedServers = new server_selection_1.DeprioritizedServers();
|
|
180
|
+
let maxAttempts = typeof operation.maxAttempts === 'number'
|
|
181
|
+
? operation.maxAttempts
|
|
182
|
+
: willRetry
|
|
183
|
+
? timeoutContext.csotEnabled()
|
|
184
|
+
? Infinity
|
|
185
|
+
: 2
|
|
186
|
+
: 1;
|
|
187
|
+
let error = null;
|
|
188
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
189
|
+
operation.attemptsMade = attempt + 1;
|
|
190
|
+
operation.server = server;
|
|
191
|
+
try {
|
|
192
|
+
try {
|
|
193
|
+
const result = await server.command(operation, timeoutContext);
|
|
194
|
+
return operation.handleOk(result);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
return operation.handleError(error);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (operationError) {
|
|
201
|
+
// Should never happen but if it does - propagate the error.
|
|
202
|
+
if (!(operationError instanceof error_1.MongoError))
|
|
203
|
+
throw operationError;
|
|
204
|
+
// Preserve the original error once a write has been performed.
|
|
205
|
+
// Only update to the latest error if no writes were performed.
|
|
206
|
+
if (error == null) {
|
|
207
|
+
error = operationError;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
if (!operationError.hasErrorLabel(error_1.MongoErrorLabel.NoWritesPerformed)) {
|
|
211
|
+
error = operationError;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Reset timeouts
|
|
215
|
+
timeoutContext.clear();
|
|
216
|
+
if (hasWriteAspect && operationError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {
|
|
175
217
|
throw new error_1.MongoServerError({
|
|
176
218
|
message: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
|
|
177
219
|
errmsg: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
|
|
178
|
-
originalError:
|
|
220
|
+
originalError: operationError
|
|
179
221
|
});
|
|
180
222
|
}
|
|
181
|
-
if (operation
|
|
182
|
-
throw
|
|
223
|
+
if (!canRetry(operation, operationError)) {
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
if (operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError)) {
|
|
227
|
+
const maxOverloadAttempts = topology.s.options.maxAdaptiveRetries + 1;
|
|
228
|
+
maxAttempts = Math.min(maxOverloadAttempts, operation.maxAttempts ?? maxOverloadAttempts);
|
|
183
229
|
}
|
|
184
|
-
if (
|
|
185
|
-
throw
|
|
186
|
-
if (hasReadAspect && !(0, error_1.isRetryableReadError)(previousOperationError)) {
|
|
187
|
-
throw previousOperationError;
|
|
230
|
+
if (attempt + 1 >= maxAttempts) {
|
|
231
|
+
throw error;
|
|
188
232
|
}
|
|
189
|
-
if (
|
|
233
|
+
if (operationError instanceof error_1.MongoNetworkError &&
|
|
190
234
|
operation.hasAspect(operation_1.Aspect.CURSOR_CREATING) &&
|
|
191
235
|
session != null &&
|
|
192
236
|
session.isPinned &&
|
|
193
237
|
!session.inTransaction()) {
|
|
194
238
|
session.unpin({ force: true, forceClear: true });
|
|
195
239
|
}
|
|
240
|
+
if (operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError) &&
|
|
241
|
+
operation.hasAspect(operation_1.Aspect.CURSOR_CREATING) &&
|
|
242
|
+
session != null &&
|
|
243
|
+
session.isPinned &&
|
|
244
|
+
!session.inTransaction()) {
|
|
245
|
+
session.unpin({ force: true });
|
|
246
|
+
}
|
|
247
|
+
if (operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError)) {
|
|
248
|
+
const backoffMS = Math.random() * Math.min(MAX_BACKOFF_MS, BASE_BACKOFF_MS * 2 ** attempt);
|
|
249
|
+
// if the backoff would exhaust the CSOT timeout, short-circuit.
|
|
250
|
+
if (timeoutContext.csotEnabled() && backoffMS > timeoutContext.remainingTimeMS) {
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
await (0, promises_1.setTimeout)(backoffMS);
|
|
254
|
+
}
|
|
255
|
+
if (topology.description.type === common_1.TopologyType.Sharded ||
|
|
256
|
+
(operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError) &&
|
|
257
|
+
topology.s.options.enableOverloadRetargeting)) {
|
|
258
|
+
deprioritizedServers.add(server.description);
|
|
259
|
+
}
|
|
196
260
|
server = await topology.selectServer(selector, {
|
|
197
261
|
session,
|
|
198
262
|
operationName: operation.commandName,
|
|
199
|
-
|
|
263
|
+
deprioritizedServers,
|
|
200
264
|
signal: operation.options.signal
|
|
201
265
|
});
|
|
202
|
-
if (hasWriteAspect &&
|
|
266
|
+
if (hasWriteAspect &&
|
|
267
|
+
!(0, utils_1.supportsRetryableWrites)(server) &&
|
|
268
|
+
!operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError)) {
|
|
203
269
|
throw new error_1.MongoUnexpectedServerResponseError('Selected server does not support retryable writes');
|
|
204
270
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
// If tries > 0 and we are command batching we need to reset the batch.
|
|
209
|
-
if (tries > 0 && operation.hasAspect(operation_1.Aspect.COMMAND_BATCHING)) {
|
|
271
|
+
// Batched operations must reset the batch before retry,
|
|
272
|
+
// otherwise building a command will build the _next_ batch, not the current batch.
|
|
273
|
+
if (operation.hasAspect(operation_1.Aspect.COMMAND_BATCHING)) {
|
|
210
274
|
operation.resetBatch();
|
|
211
275
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
throw (error ??
|
|
279
|
+
new error_1.MongoRuntimeError('Should never happen: operation execution loop terminated but no error was recorded.'));
|
|
280
|
+
function canRetry(operation, error) {
|
|
281
|
+
// SystemOverloadedError is retryable, but must respect retryReads/retryWrites settings
|
|
282
|
+
// Check topology options directly (not operation.canRetryRead/Write) because backpressure
|
|
283
|
+
// expands retry support beyond traditional retryable reads/writes
|
|
284
|
+
// NOTE: Unlike traditional retries, backpressure retries ARE allowed inside transactions
|
|
285
|
+
if (error.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError) &&
|
|
286
|
+
error.hasErrorLabel(error_1.MongoErrorLabel.RetryableError)) {
|
|
287
|
+
// runCommand requires BOTH retryReads and retryWrites to be enabled (per spec step 2.4)
|
|
288
|
+
if (operation instanceof run_command_1.RunCommandOperation) {
|
|
289
|
+
return topology.s.options.retryReads && topology.s.options.retryWrites;
|
|
215
290
|
}
|
|
216
|
-
|
|
217
|
-
|
|
291
|
+
// Write-stage aggregates ($out/$merge) require retryWrites
|
|
292
|
+
if (operation instanceof aggregate_1.AggregateOperation && operation.hasWriteStage) {
|
|
293
|
+
return topology.s.options.retryWrites;
|
|
218
294
|
}
|
|
295
|
+
// For other operations, check if retries are enabled based on operation type
|
|
296
|
+
const canRetryAsRead = hasReadAspect && topology.s.options.retryReads;
|
|
297
|
+
const canRetryAsWrite = hasWriteAspect && topology.s.options.retryWrites;
|
|
298
|
+
return canRetryAsRead || canRetryAsWrite;
|
|
219
299
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
previousServer = server.description;
|
|
228
|
-
previousOperationError = operationError;
|
|
229
|
-
// Reset timeouts
|
|
230
|
-
timeoutContext.clear();
|
|
300
|
+
// run command is only retryable if we get retryable overload errors
|
|
301
|
+
if (operation instanceof run_command_1.RunCommandOperation) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
// batch operations are only retryable if the batch is retryable
|
|
305
|
+
if (operation.hasAspect(operation_1.Aspect.COMMAND_BATCHING)) {
|
|
306
|
+
return operation.canRetryWrite && (0, error_1.isRetryableWriteError)(error);
|
|
231
307
|
}
|
|
308
|
+
return ((hasWriteAspect && willRetryWrite && (0, error_1.isRetryableWriteError)(error)) ||
|
|
309
|
+
(hasReadAspect && willRetryRead && (0, error_1.isRetryableReadError)(error)));
|
|
232
310
|
}
|
|
233
|
-
throw (previousOperationError ??
|
|
234
|
-
new error_1.MongoRuntimeError('Tried to propagate retryability error, but no error was found.'));
|
|
235
311
|
}
|
|
236
312
|
//# sourceMappingURL=execute_operation.js.map
|
|
@@ -32,6 +32,7 @@ class AbstractOperation {
|
|
|
32
32
|
this._session = options.session != null ? options.session : undefined;
|
|
33
33
|
this.options = options;
|
|
34
34
|
this.bypassPinningCheck = !!options.bypassPinningCheck;
|
|
35
|
+
this.attemptsMade = 0;
|
|
35
36
|
}
|
|
36
37
|
hasAspect(aspect) {
|
|
37
38
|
const ctor = this.constructor;
|