@depup/mongodb 7.1.0-depup.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/LICENSE.md +201 -0
- package/README.md +33 -0
- package/etc/prepare.js +12 -0
- package/lib/admin.js +136 -0
- package/lib/admin.js.map +1 -0
- package/lib/bson.js +85 -0
- package/lib/bson.js.map +1 -0
- package/lib/bulk/common.js +835 -0
- package/lib/bulk/common.js.map +1 -0
- package/lib/bulk/ordered.js +67 -0
- package/lib/bulk/ordered.js.map +1 -0
- package/lib/bulk/unordered.js +92 -0
- package/lib/bulk/unordered.js.map +1 -0
- package/lib/change_stream.js +513 -0
- package/lib/change_stream.js.map +1 -0
- package/lib/client-side-encryption/auto_encrypter.js +272 -0
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -0
- package/lib/client-side-encryption/client_encryption.js +609 -0
- package/lib/client-side-encryption/client_encryption.js.map +1 -0
- package/lib/client-side-encryption/errors.js +138 -0
- package/lib/client-side-encryption/errors.js.map +1 -0
- package/lib/client-side-encryption/mongocryptd_manager.js +85 -0
- package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -0
- package/lib/client-side-encryption/providers/aws.js +23 -0
- package/lib/client-side-encryption/providers/aws.js.map +1 -0
- package/lib/client-side-encryption/providers/azure.js +132 -0
- package/lib/client-side-encryption/providers/azure.js.map +1 -0
- package/lib/client-side-encryption/providers/gcp.js +16 -0
- package/lib/client-side-encryption/providers/gcp.js.map +1 -0
- package/lib/client-side-encryption/providers/index.js +43 -0
- package/lib/client-side-encryption/providers/index.js.map +1 -0
- package/lib/client-side-encryption/state_machine.js +427 -0
- package/lib/client-side-encryption/state_machine.js.map +1 -0
- package/lib/cmap/auth/auth_provider.js +51 -0
- package/lib/cmap/auth/auth_provider.js.map +1 -0
- package/lib/cmap/auth/aws4.js +161 -0
- package/lib/cmap/auth/aws4.js.map +1 -0
- package/lib/cmap/auth/aws_temporary_credentials.js +103 -0
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
- package/lib/cmap/auth/gssapi.js +155 -0
- package/lib/cmap/auth/gssapi.js.map +1 -0
- package/lib/cmap/auth/mongo_credentials.js +169 -0
- package/lib/cmap/auth/mongo_credentials.js.map +1 -0
- package/lib/cmap/auth/mongodb_aws.js +128 -0
- package/lib/cmap/auth/mongodb_aws.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +84 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +62 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +141 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js +44 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +39 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +122 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +32 -0
- package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js +52 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +23 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +73 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -0
- package/lib/cmap/auth/plain.js +26 -0
- package/lib/cmap/auth/plain.js.map +1 -0
- package/lib/cmap/auth/providers.js +22 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +254 -0
- package/lib/cmap/auth/scram.js.map +1 -0
- package/lib/cmap/auth/x509.js +36 -0
- package/lib/cmap/auth/x509.js.map +1 -0
- package/lib/cmap/command_monitoring_events.js +223 -0
- package/lib/cmap/command_monitoring_events.js.map +1 -0
- package/lib/cmap/commands.js +535 -0
- package/lib/cmap/commands.js.map +1 -0
- package/lib/cmap/connect.js +381 -0
- package/lib/cmap/connect.js.map +1 -0
- package/lib/cmap/connection.js +571 -0
- package/lib/cmap/connection.js.map +1 -0
- package/lib/cmap/connection_pool.js +558 -0
- package/lib/cmap/connection_pool.js.map +1 -0
- package/lib/cmap/connection_pool_events.js +190 -0
- package/lib/cmap/connection_pool_events.js.map +1 -0
- package/lib/cmap/errors.js +108 -0
- package/lib/cmap/errors.js.map +1 -0
- package/lib/cmap/handshake/client_metadata.js +242 -0
- package/lib/cmap/handshake/client_metadata.js.map +1 -0
- package/lib/cmap/metrics.js +62 -0
- package/lib/cmap/metrics.js.map +1 -0
- package/lib/cmap/stream_description.js +70 -0
- package/lib/cmap/stream_description.js.map +1 -0
- package/lib/cmap/wire_protocol/compression.js +178 -0
- package/lib/cmap/wire_protocol/compression.js.map +1 -0
- package/lib/cmap/wire_protocol/constants.js +21 -0
- package/lib/cmap/wire_protocol/constants.js.map +1 -0
- package/lib/cmap/wire_protocol/on_data.js +111 -0
- package/lib/cmap/wire_protocol/on_data.js.map +1 -0
- package/lib/cmap/wire_protocol/on_demand/document.js +222 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/cmap/wire_protocol/responses.js +315 -0
- package/lib/cmap/wire_protocol/responses.js.map +1 -0
- package/lib/cmap/wire_protocol/shared.js +35 -0
- package/lib/cmap/wire_protocol/shared.js.map +1 -0
- package/lib/collection.js +751 -0
- package/lib/collection.js.map +1 -0
- package/lib/connection_string.js +1090 -0
- package/lib/connection_string.js.map +1 -0
- package/lib/constants.js +170 -0
- package/lib/constants.js.map +1 -0
- package/lib/cursor/abstract_cursor.js +924 -0
- package/lib/cursor/abstract_cursor.js.map +1 -0
- package/lib/cursor/aggregation_cursor.js +164 -0
- package/lib/cursor/aggregation_cursor.js.map +1 -0
- package/lib/cursor/change_stream_cursor.js +104 -0
- package/lib/cursor/change_stream_cursor.js.map +1 -0
- package/lib/cursor/client_bulk_write_cursor.js +52 -0
- package/lib/cursor/client_bulk_write_cursor.js.map +1 -0
- package/lib/cursor/explainable_cursor.js +36 -0
- package/lib/cursor/explainable_cursor.js.map +1 -0
- package/lib/cursor/find_cursor.js +399 -0
- package/lib/cursor/find_cursor.js.map +1 -0
- package/lib/cursor/list_collections_cursor.js +34 -0
- package/lib/cursor/list_collections_cursor.js.map +1 -0
- package/lib/cursor/list_indexes_cursor.js +32 -0
- package/lib/cursor/list_indexes_cursor.js.map +1 -0
- package/lib/cursor/list_search_indexes_cursor.js +14 -0
- package/lib/cursor/list_search_indexes_cursor.js.map +1 -0
- package/lib/cursor/run_command_cursor.js +94 -0
- package/lib/cursor/run_command_cursor.js.map +1 -0
- package/lib/db.js +419 -0
- package/lib/db.js.map +1 -0
- package/lib/deps.js +112 -0
- package/lib/deps.js.map +1 -0
- package/lib/encrypter.js +106 -0
- package/lib/encrypter.js.map +1 -0
- package/lib/error.js +1380 -0
- package/lib/error.js.map +1 -0
- package/lib/explain.js +59 -0
- package/lib/explain.js.map +1 -0
- package/lib/gridfs/download.js +305 -0
- package/lib/gridfs/download.js.map +1 -0
- package/lib/gridfs/index.js +164 -0
- package/lib/gridfs/index.js.map +1 -0
- package/lib/gridfs/upload.js +358 -0
- package/lib/gridfs/upload.js.map +1 -0
- package/lib/index.js +193 -0
- package/lib/index.js.map +1 -0
- package/lib/mongo_client.js +557 -0
- package/lib/mongo_client.js.map +1 -0
- package/lib/mongo_client_auth_providers.js +80 -0
- package/lib/mongo_client_auth_providers.js.map +1 -0
- package/lib/mongo_logger.js +655 -0
- package/lib/mongo_logger.js.map +1 -0
- package/lib/mongo_types.js +56 -0
- package/lib/mongo_types.js.map +1 -0
- package/lib/operations/aggregate.js +90 -0
- package/lib/operations/aggregate.js.map +1 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js +51 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -0
- package/lib/operations/client_bulk_write/command_builder.js +340 -0
- package/lib/operations/client_bulk_write/command_builder.js.map +1 -0
- package/lib/operations/client_bulk_write/common.js +3 -0
- package/lib/operations/client_bulk_write/common.js.map +1 -0
- package/lib/operations/client_bulk_write/executor.js +120 -0
- package/lib/operations/client_bulk_write/executor.js.map +1 -0
- package/lib/operations/client_bulk_write/results_merger.js +204 -0
- package/lib/operations/client_bulk_write/results_merger.js.map +1 -0
- package/lib/operations/command.js +83 -0
- package/lib/operations/command.js.map +1 -0
- package/lib/operations/count.js +45 -0
- package/lib/operations/count.js.map +1 -0
- package/lib/operations/create_collection.js +109 -0
- package/lib/operations/create_collection.js.map +1 -0
- package/lib/operations/delete.js +125 -0
- package/lib/operations/delete.js.map +1 -0
- package/lib/operations/distinct.js +61 -0
- package/lib/operations/distinct.js.map +1 -0
- package/lib/operations/drop.js +93 -0
- package/lib/operations/drop.js.map +1 -0
- package/lib/operations/end_sessions.js +34 -0
- package/lib/operations/end_sessions.js.map +1 -0
- package/lib/operations/estimated_document_count.js +41 -0
- package/lib/operations/estimated_document_count.js.map +1 -0
- package/lib/operations/execute_operation.js +239 -0
- package/lib/operations/execute_operation.js.map +1 -0
- package/lib/operations/find.js +148 -0
- package/lib/operations/find.js.map +1 -0
- package/lib/operations/find_and_modify.js +158 -0
- package/lib/operations/find_and_modify.js.map +1 -0
- package/lib/operations/get_more.js +62 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +186 -0
- package/lib/operations/indexes.js.map +1 -0
- package/lib/operations/insert.js +70 -0
- package/lib/operations/insert.js.map +1 -0
- package/lib/operations/kill_cursors.js +43 -0
- package/lib/operations/kill_cursors.js.map +1 -0
- package/lib/operations/list_collections.js +53 -0
- package/lib/operations/list_collections.js.map +1 -0
- package/lib/operations/list_databases.js +40 -0
- package/lib/operations/list_databases.js.map +1 -0
- package/lib/operations/operation.js +102 -0
- package/lib/operations/operation.js.map +1 -0
- package/lib/operations/profiling_level.js +43 -0
- package/lib/operations/profiling_level.js.map +1 -0
- package/lib/operations/remove_user.js +27 -0
- package/lib/operations/remove_user.js.map +1 -0
- package/lib/operations/rename.js +38 -0
- package/lib/operations/rename.js.map +1 -0
- package/lib/operations/run_command.js +47 -0
- package/lib/operations/run_command.js.map +1 -0
- package/lib/operations/search_indexes/create.js +33 -0
- package/lib/operations/search_indexes/create.js.map +1 -0
- package/lib/operations/search_indexes/drop.js +43 -0
- package/lib/operations/search_indexes/drop.js.map +1 -0
- package/lib/operations/search_indexes/update.js +35 -0
- package/lib/operations/search_indexes/update.js.map +1 -0
- package/lib/operations/set_profiling_level.js +53 -0
- package/lib/operations/set_profiling_level.js.map +1 -0
- package/lib/operations/stats.js +27 -0
- package/lib/operations/stats.js.map +1 -0
- package/lib/operations/update.js +188 -0
- package/lib/operations/update.js.map +1 -0
- package/lib/operations/validate_collection.js +37 -0
- package/lib/operations/validate_collection.js.map +1 -0
- package/lib/read_concern.js +73 -0
- package/lib/read_concern.js.map +1 -0
- package/lib/read_preference.js +191 -0
- package/lib/read_preference.js.map +1 -0
- package/lib/sdam/common.js +49 -0
- package/lib/sdam/common.js.map +1 -0
- package/lib/sdam/events.js +146 -0
- package/lib/sdam/events.js.map +1 -0
- package/lib/sdam/monitor.js +544 -0
- package/lib/sdam/monitor.js.map +1 -0
- package/lib/sdam/server.js +404 -0
- package/lib/sdam/server.js.map +1 -0
- package/lib/sdam/server_description.js +204 -0
- package/lib/sdam/server_description.js.map +1 -0
- package/lib/sdam/server_selection.js +294 -0
- package/lib/sdam/server_selection.js.map +1 -0
- package/lib/sdam/server_selection_events.js +85 -0
- package/lib/sdam/server_selection_events.js.map +1 -0
- package/lib/sdam/srv_polling.js +108 -0
- package/lib/sdam/srv_polling.js.map +1 -0
- package/lib/sdam/topology.js +652 -0
- package/lib/sdam/topology.js.map +1 -0
- package/lib/sdam/topology_description.js +383 -0
- package/lib/sdam/topology_description.js.map +1 -0
- package/lib/sessions.js +892 -0
- package/lib/sessions.js.map +1 -0
- package/lib/sort.js +103 -0
- package/lib/sort.js.map +1 -0
- package/lib/timeout.js +296 -0
- package/lib/timeout.js.map +1 -0
- package/lib/transactions.js +135 -0
- package/lib/transactions.js.map +1 -0
- package/lib/utils.js +1163 -0
- package/lib/utils.js.map +1 -0
- package/lib/write_concern.js +100 -0
- package/lib/write_concern.js.map +1 -0
- package/mongodb.d.ts +9018 -0
- package/package.json +197 -0
- package/src/admin.ts +173 -0
- package/src/bson.ts +149 -0
- package/src/bulk/common.ts +1251 -0
- package/src/bulk/ordered.ts +83 -0
- package/src/bulk/unordered.ts +115 -0
- package/src/change_stream.ts +1160 -0
- package/src/client-side-encryption/auto_encrypter.ts +469 -0
- package/src/client-side-encryption/client_encryption.ts +1150 -0
- package/src/client-side-encryption/errors.ts +144 -0
- package/src/client-side-encryption/mongocryptd_manager.ts +100 -0
- package/src/client-side-encryption/providers/aws.ts +33 -0
- package/src/client-side-encryption/providers/azure.ts +181 -0
- package/src/client-side-encryption/providers/gcp.ts +16 -0
- package/src/client-side-encryption/providers/index.ts +207 -0
- package/src/client-side-encryption/state_machine.ts +651 -0
- package/src/cmap/auth/auth_provider.ts +77 -0
- package/src/cmap/auth/aws4.ts +207 -0
- package/src/cmap/auth/aws_temporary_credentials.ts +129 -0
- package/src/cmap/auth/gssapi.ts +203 -0
- package/src/cmap/auth/mongo_credentials.ts +292 -0
- package/src/cmap/auth/mongodb_aws.ts +179 -0
- package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +88 -0
- package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +73 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +188 -0
- package/src/cmap/auth/mongodb_oidc/command_builders.ts +53 -0
- package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +46 -0
- package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +141 -0
- package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +31 -0
- package/src/cmap/auth/mongodb_oidc/token_cache.ts +62 -0
- package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +22 -0
- package/src/cmap/auth/mongodb_oidc.ts +185 -0
- package/src/cmap/auth/plain.ts +25 -0
- package/src/cmap/auth/providers.ts +22 -0
- package/src/cmap/auth/scram.ts +344 -0
- package/src/cmap/auth/x509.ts +43 -0
- package/src/cmap/command_monitoring_events.ts +316 -0
- package/src/cmap/commands.ts +788 -0
- package/src/cmap/connect.ts +518 -0
- package/src/cmap/connection.ts +931 -0
- package/src/cmap/connection_pool.ts +831 -0
- package/src/cmap/connection_pool_events.ts +300 -0
- package/src/cmap/errors.ts +119 -0
- package/src/cmap/handshake/client_metadata.ts +353 -0
- package/src/cmap/metrics.ts +58 -0
- package/src/cmap/stream_description.ts +96 -0
- package/src/cmap/wire_protocol/compression.ts +211 -0
- package/src/cmap/wire_protocol/constants.ts +17 -0
- package/src/cmap/wire_protocol/on_data.ts +139 -0
- package/src/cmap/wire_protocol/on_demand/document.ts +358 -0
- package/src/cmap/wire_protocol/responses.ts +393 -0
- package/src/cmap/wire_protocol/shared.ts +48 -0
- package/src/collection.ts +1314 -0
- package/src/connection_string.ts +1297 -0
- package/src/constants.ts +176 -0
- package/src/cursor/abstract_cursor.ts +1247 -0
- package/src/cursor/aggregation_cursor.ts +245 -0
- package/src/cursor/change_stream_cursor.ts +171 -0
- package/src/cursor/client_bulk_write_cursor.ts +83 -0
- package/src/cursor/explainable_cursor.ts +51 -0
- package/src/cursor/find_cursor.ts +497 -0
- package/src/cursor/list_collections_cursor.ts +50 -0
- package/src/cursor/list_indexes_cursor.ts +37 -0
- package/src/cursor/list_search_indexes_cursor.ts +20 -0
- package/src/cursor/run_command_cursor.ts +178 -0
- package/src/db.ts +621 -0
- package/src/deps.ts +227 -0
- package/src/encrypter.ts +127 -0
- package/src/error.ts +1567 -0
- package/src/explain.ts +124 -0
- package/src/gridfs/download.ts +483 -0
- package/src/gridfs/index.ts +264 -0
- package/src/gridfs/upload.ts +537 -0
- package/src/index.ts +633 -0
- package/src/mongo_client.ts +1155 -0
- package/src/mongo_client_auth_providers.ts +87 -0
- package/src/mongo_logger.ts +1081 -0
- package/src/mongo_types.ts +678 -0
- package/src/operations/aggregate.ts +153 -0
- package/src/operations/client_bulk_write/client_bulk_write.ts +72 -0
- package/src/operations/client_bulk_write/command_builder.ts +487 -0
- package/src/operations/client_bulk_write/common.ts +276 -0
- package/src/operations/client_bulk_write/executor.ts +149 -0
- package/src/operations/client_bulk_write/results_merger.ts +260 -0
- package/src/operations/command.ts +171 -0
- package/src/operations/count.ts +74 -0
- package/src/operations/create_collection.ts +218 -0
- package/src/operations/delete.ts +183 -0
- package/src/operations/distinct.ts +92 -0
- package/src/operations/drop.ts +130 -0
- package/src/operations/end_sessions.ts +44 -0
- package/src/operations/estimated_document_count.ts +61 -0
- package/src/operations/execute_operation.ts +319 -0
- package/src/operations/find.ts +254 -0
- package/src/operations/find_and_modify.ts +319 -0
- package/src/operations/get_more.ts +108 -0
- package/src/operations/indexes.ts +418 -0
- package/src/operations/insert.ts +108 -0
- package/src/operations/kill_cursors.ts +64 -0
- package/src/operations/list_collections.ts +108 -0
- package/src/operations/list_databases.ts +68 -0
- package/src/operations/operation.ts +181 -0
- package/src/operations/profiling_level.ts +46 -0
- package/src/operations/remove_user.ts +36 -0
- package/src/operations/rename.ts +60 -0
- package/src/operations/run_command.ts +79 -0
- package/src/operations/search_indexes/create.ts +56 -0
- package/src/operations/search_indexes/drop.ts +58 -0
- package/src/operations/search_indexes/update.ts +45 -0
- package/src/operations/set_profiling_level.ts +74 -0
- package/src/operations/stats.ts +37 -0
- package/src/operations/update.ts +318 -0
- package/src/operations/validate_collection.ts +50 -0
- package/src/read_concern.ts +88 -0
- package/src/read_preference.ts +256 -0
- package/src/sdam/common.ts +74 -0
- package/src/sdam/events.ts +219 -0
- package/src/sdam/monitor.ts +771 -0
- package/src/sdam/server.ts +595 -0
- package/src/sdam/server_description.ts +297 -0
- package/src/sdam/server_selection.ts +415 -0
- package/src/sdam/server_selection_events.ts +142 -0
- package/src/sdam/srv_polling.ts +146 -0
- package/src/sdam/topology.ts +1100 -0
- package/src/sdam/topology_description.ts +548 -0
- package/src/sessions.ts +1244 -0
- package/src/sort.ts +141 -0
- package/src/timeout.ts +405 -0
- package/src/transactions.ts +181 -0
- package/src/utils.ts +1434 -0
- package/src/write_concern.ts +183 -0
- package/tsconfig.json +46 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeleteManyOperation = exports.DeleteOneOperation = exports.DeleteOperation = void 0;
|
|
4
|
+
exports.makeDeleteStatement = makeDeleteStatement;
|
|
5
|
+
const responses_1 = require("../cmap/wire_protocol/responses");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const command_1 = require("./command");
|
|
9
|
+
const operation_1 = require("./operation");
|
|
10
|
+
/** @internal */
|
|
11
|
+
class DeleteOperation extends command_1.CommandOperation {
|
|
12
|
+
constructor(ns, statements, options) {
|
|
13
|
+
super(undefined, options);
|
|
14
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.ns = ns;
|
|
17
|
+
this.statements = statements;
|
|
18
|
+
}
|
|
19
|
+
get commandName() {
|
|
20
|
+
return 'delete';
|
|
21
|
+
}
|
|
22
|
+
get canRetryWrite() {
|
|
23
|
+
if (super.canRetryWrite === false) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return this.statements.every(op => (op.limit != null ? op.limit > 0 : true));
|
|
27
|
+
}
|
|
28
|
+
buildCommandDocument(connection, _session) {
|
|
29
|
+
const options = this.options;
|
|
30
|
+
const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
|
|
31
|
+
const command = {
|
|
32
|
+
delete: this.ns.collection,
|
|
33
|
+
deletes: this.statements,
|
|
34
|
+
ordered
|
|
35
|
+
};
|
|
36
|
+
if (options.let) {
|
|
37
|
+
command.let = options.let;
|
|
38
|
+
}
|
|
39
|
+
// we check for undefined specifically here to allow falsy values
|
|
40
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
41
|
+
if (options.comment !== undefined) {
|
|
42
|
+
command.comment = options.comment;
|
|
43
|
+
}
|
|
44
|
+
const unacknowledgedWrite = this.writeConcern && this.writeConcern.w === 0;
|
|
45
|
+
if (unacknowledgedWrite && (0, utils_1.maxWireVersion)(connection) < 9) {
|
|
46
|
+
if (this.statements.find((o) => o.hint)) {
|
|
47
|
+
throw new error_1.MongoCompatibilityError(`hint for the delete command is only supported on MongoDB 4.4+`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return command;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.DeleteOperation = DeleteOperation;
|
|
54
|
+
class DeleteOneOperation extends DeleteOperation {
|
|
55
|
+
constructor(ns, filter, options) {
|
|
56
|
+
super(ns, [makeDeleteStatement(filter, { ...options, limit: 1 })], options);
|
|
57
|
+
}
|
|
58
|
+
handleOk(response) {
|
|
59
|
+
const res = super.handleOk(response);
|
|
60
|
+
// @ts-expect-error Explain commands have broken TS
|
|
61
|
+
if (this.explain)
|
|
62
|
+
return res;
|
|
63
|
+
if (res.code)
|
|
64
|
+
throw new error_1.MongoServerError(res);
|
|
65
|
+
if (res.writeErrors)
|
|
66
|
+
throw new error_1.MongoServerError(res.writeErrors[0]);
|
|
67
|
+
return {
|
|
68
|
+
acknowledged: this.writeConcern?.w !== 0,
|
|
69
|
+
deletedCount: res.n
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.DeleteOneOperation = DeleteOneOperation;
|
|
74
|
+
class DeleteManyOperation extends DeleteOperation {
|
|
75
|
+
constructor(ns, filter, options) {
|
|
76
|
+
super(ns, [makeDeleteStatement(filter, options)], options);
|
|
77
|
+
}
|
|
78
|
+
handleOk(response) {
|
|
79
|
+
const res = super.handleOk(response);
|
|
80
|
+
// @ts-expect-error Explain commands have broken TS
|
|
81
|
+
if (this.explain)
|
|
82
|
+
return res;
|
|
83
|
+
if (res.code)
|
|
84
|
+
throw new error_1.MongoServerError(res);
|
|
85
|
+
if (res.writeErrors)
|
|
86
|
+
throw new error_1.MongoServerError(res.writeErrors[0]);
|
|
87
|
+
return {
|
|
88
|
+
acknowledged: this.writeConcern?.w !== 0,
|
|
89
|
+
deletedCount: res.n
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.DeleteManyOperation = DeleteManyOperation;
|
|
94
|
+
function makeDeleteStatement(filter, options) {
|
|
95
|
+
const op = {
|
|
96
|
+
q: filter,
|
|
97
|
+
limit: typeof options.limit === 'number' ? options.limit : 0
|
|
98
|
+
};
|
|
99
|
+
if (options.collation) {
|
|
100
|
+
op.collation = options.collation;
|
|
101
|
+
}
|
|
102
|
+
if (options.hint) {
|
|
103
|
+
op.hint = options.hint;
|
|
104
|
+
}
|
|
105
|
+
return op;
|
|
106
|
+
}
|
|
107
|
+
(0, operation_1.defineAspects)(DeleteOperation, [
|
|
108
|
+
operation_1.Aspect.RETRYABLE,
|
|
109
|
+
operation_1.Aspect.WRITE_OPERATION,
|
|
110
|
+
operation_1.Aspect.SUPPORTS_RAW_DATA
|
|
111
|
+
]);
|
|
112
|
+
(0, operation_1.defineAspects)(DeleteOneOperation, [
|
|
113
|
+
operation_1.Aspect.RETRYABLE,
|
|
114
|
+
operation_1.Aspect.WRITE_OPERATION,
|
|
115
|
+
operation_1.Aspect.EXPLAINABLE,
|
|
116
|
+
operation_1.Aspect.SKIP_COLLATION,
|
|
117
|
+
operation_1.Aspect.SUPPORTS_RAW_DATA
|
|
118
|
+
]);
|
|
119
|
+
(0, operation_1.defineAspects)(DeleteManyOperation, [
|
|
120
|
+
operation_1.Aspect.WRITE_OPERATION,
|
|
121
|
+
operation_1.Aspect.EXPLAINABLE,
|
|
122
|
+
operation_1.Aspect.SKIP_COLLATION,
|
|
123
|
+
operation_1.Aspect.SUPPORTS_RAW_DATA
|
|
124
|
+
]);
|
|
125
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../src/operations/delete.ts"],"names":[],"mappings":";;;AAiJA,kDAkBC;AAjKD,+DAAkE;AAClE,oCAAqE;AAErE,oCAAkG;AAElG,uCAAkG;AAClG,2CAA+D;AAkC/D,gBAAgB;AAChB,MAAa,eAAgB,SAAQ,0BAA0B;IAK7D,YAAY,EAAoB,EAAE,UAA6B,EAAE,OAAsB;QACrF,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QALnB,iCAA4B,GAAG,2BAAe,CAAC;QAMtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,IAAa,WAAW;QACtB,OAAO,QAAiB,CAAC;IAC3B,CAAC;IAED,IAAa,aAAa;QACxB,IAAI,KAAK,CAAC,aAAa,KAAK,KAAK,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/E,CAAC;IAEQ,oBAAoB,CAAC,UAAsB,EAAE,QAAwB;QAC5E,MAAM,OAAO,GAAG,IA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OAA2C;IAE3C,MAAM,EAAE,GAAoB;QAC1B,CAAC,EAAE,MAAM;QACT,KAAK,EAAE,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC7D,CAAC;IAEF,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACnC,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,EAAE,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,IAAA,yBAAa,EAAC,eAAe,EAAE;IAC7B,kBAAM,CAAC,SAAS;IAChB,kBAAM,CAAC,eAAe;IACtB,kBAAM,CAAC,iBAAiB;CACzB,CAAC,CAAC;AACH,IAAA,yBAAa,EAAC,kBAAkB,EAAE;IAChC,kBAAM,CAAC,SAAS;IAChB,kBAAM,CAAC,eAAe;IACtB,kBAAM,CAAC,WAAW;IAClB,kBAAM,CAAC,cAAc;IACrB,kBAAM,CAAC,iBAAiB;CACzB,CAAC,CAAC;AACH,IAAA,yBAAa,EAAC,mBAAmB,EAAE;IACjC,kBAAM,CAAC,eAAe;IACtB,kBAAM,CAAC,WAAW;IAClB,kBAAM,CAAC,cAAc;IACrB,kBAAM,CAAC,iBAAiB;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DistinctOperation = void 0;
|
|
4
|
+
const responses_1 = require("../cmap/wire_protocol/responses");
|
|
5
|
+
const command_1 = require("./command");
|
|
6
|
+
const operation_1 = require("./operation");
|
|
7
|
+
/**
|
|
8
|
+
* Return a list of distinct values for the given key across a collection.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
class DistinctOperation extends command_1.CommandOperation {
|
|
12
|
+
/**
|
|
13
|
+
* Construct a Distinct operation.
|
|
14
|
+
*
|
|
15
|
+
* @param collection - Collection instance.
|
|
16
|
+
* @param key - Field of the document to find distinct values for.
|
|
17
|
+
* @param query - The query for filtering the set of documents to which we apply the distinct filter.
|
|
18
|
+
* @param options - Optional settings. See Collection.prototype.distinct for a list of options.
|
|
19
|
+
*/
|
|
20
|
+
constructor(collection, key, query, options) {
|
|
21
|
+
super(collection, options);
|
|
22
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
|
|
23
|
+
this.options = options ?? {};
|
|
24
|
+
this.collection = collection;
|
|
25
|
+
this.key = key;
|
|
26
|
+
this.query = query;
|
|
27
|
+
}
|
|
28
|
+
get commandName() {
|
|
29
|
+
return 'distinct';
|
|
30
|
+
}
|
|
31
|
+
buildCommandDocument(_connection) {
|
|
32
|
+
const command = {
|
|
33
|
+
distinct: this.collection.collectionName,
|
|
34
|
+
key: this.key,
|
|
35
|
+
query: this.query
|
|
36
|
+
};
|
|
37
|
+
// we check for undefined specifically here to allow falsy values
|
|
38
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
39
|
+
if (this.options.comment !== undefined) {
|
|
40
|
+
command.comment = this.options.comment;
|
|
41
|
+
}
|
|
42
|
+
if (this.options.hint != null) {
|
|
43
|
+
command.hint = this.options.hint;
|
|
44
|
+
}
|
|
45
|
+
return command;
|
|
46
|
+
}
|
|
47
|
+
handleOk(response) {
|
|
48
|
+
if (this.explain) {
|
|
49
|
+
return response.toObject(this.bsonOptions);
|
|
50
|
+
}
|
|
51
|
+
return response.toObject(this.bsonOptions).values;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.DistinctOperation = DistinctOperation;
|
|
55
|
+
(0, operation_1.defineAspects)(DistinctOperation, [
|
|
56
|
+
operation_1.Aspect.READ_OPERATION,
|
|
57
|
+
operation_1.Aspect.RETRYABLE,
|
|
58
|
+
operation_1.Aspect.EXPLAINABLE,
|
|
59
|
+
operation_1.Aspect.SUPPORTS_RAW_DATA
|
|
60
|
+
]);
|
|
61
|
+
//# sourceMappingURL=distinct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distinct.js","sourceRoot":"","sources":["../../src/operations/distinct.ts"],"names":[],"mappings":";;;AAEA,+DAAkE;AAElE,uCAA2E;AAC3E,2CAAoD;AAkBpD;;;GAGG;AACH,MAAa,iBAAkB,SAAQ,0BAAkC;IASvE;;;;;;;OAOG;IACH,YAAY,UAAsB,EAAE,GAAW,EAAE,KAAe,EAAE,OAAyB;QACzF,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAjBpB,iCAA4B,GAAG,2BAAe,CAAC;QAmBtD,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,IAAa,WAAW;QACtB,OAAO,UAAmB,CAAC;IAC7B,CAAC;IAEQ,oBAAoB,CAAC,WAAuB;QACnD,MAAM,OAAO,GAAa;YACxB,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,cAAc;YACxC,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC;QACF,iEAAiE;QACjE,gDAAgD;QAChD,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACvC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QACzC,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QACnC,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAEQ,QAAQ,CACf,QAAgE;QAEhE,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC;IACpD,CAAC;CACF;AAzDD,8CAyDC;AAED,IAAA,yBAAa,EAAC,iBAAiB,EAAE;IAC/B,kBAAM,CAAC,cAAc;IACrB,kBAAM,CAAC,SAAS;IAChB,kBAAM,CAAC,WAAW;IAClB,kBAAM,CAAC,iBAAiB;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DropDatabaseOperation = exports.DropCollectionOperation = void 0;
|
|
4
|
+
exports.dropCollections = dropCollections;
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const responses_1 = require("../cmap/wire_protocol/responses");
|
|
7
|
+
const abstract_cursor_1 = require("../cursor/abstract_cursor");
|
|
8
|
+
const error_1 = require("../error");
|
|
9
|
+
const timeout_1 = require("../timeout");
|
|
10
|
+
const command_1 = require("./command");
|
|
11
|
+
const execute_operation_1 = require("./execute_operation");
|
|
12
|
+
const operation_1 = require("./operation");
|
|
13
|
+
/** @internal */
|
|
14
|
+
class DropCollectionOperation extends command_1.CommandOperation {
|
|
15
|
+
constructor(db, name, options = {}) {
|
|
16
|
+
super(db, options);
|
|
17
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.name = name;
|
|
20
|
+
}
|
|
21
|
+
get commandName() {
|
|
22
|
+
return 'drop';
|
|
23
|
+
}
|
|
24
|
+
buildCommandDocument(_connection, _session) {
|
|
25
|
+
return { drop: this.name };
|
|
26
|
+
}
|
|
27
|
+
handleOk(_response) {
|
|
28
|
+
return true;
|
|
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
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.DropCollectionOperation = DropCollectionOperation;
|
|
39
|
+
async function dropCollections(db, name, options) {
|
|
40
|
+
const timeoutContext = timeout_1.TimeoutContext.create({
|
|
41
|
+
session: options.session,
|
|
42
|
+
serverSelectionTimeoutMS: db.client.s.options.serverSelectionTimeoutMS,
|
|
43
|
+
waitQueueTimeoutMS: db.client.s.options.waitQueueTimeoutMS,
|
|
44
|
+
timeoutMS: options.timeoutMS
|
|
45
|
+
});
|
|
46
|
+
const encryptedFieldsMap = db.client.s.options.autoEncryption?.encryptedFieldsMap;
|
|
47
|
+
let encryptedFields = options.encryptedFields ?? encryptedFieldsMap?.[`${db.databaseName}.${name}`];
|
|
48
|
+
if (!encryptedFields && encryptedFieldsMap) {
|
|
49
|
+
// If the MongoClient was configured with an encryptedFieldsMap,
|
|
50
|
+
// and no encryptedFields config was available in it or explicitly
|
|
51
|
+
// passed as an argument, the spec tells us to look one up using
|
|
52
|
+
// listCollections().
|
|
53
|
+
const listCollectionsResult = await db
|
|
54
|
+
.listCollections({ name }, {
|
|
55
|
+
nameOnly: false,
|
|
56
|
+
session: options.session,
|
|
57
|
+
timeoutContext: new abstract_cursor_1.CursorTimeoutContext(timeoutContext, Symbol())
|
|
58
|
+
})
|
|
59
|
+
.toArray();
|
|
60
|
+
encryptedFields = listCollectionsResult?.[0]?.options?.encryptedFields;
|
|
61
|
+
}
|
|
62
|
+
if (encryptedFields) {
|
|
63
|
+
const escCollection = encryptedFields.escCollection || `enxcol_.${name}.esc`;
|
|
64
|
+
const ecocCollection = encryptedFields.ecocCollection || `enxcol_.${name}.ecoc`;
|
|
65
|
+
for (const collectionName of [escCollection, ecocCollection]) {
|
|
66
|
+
// Drop auxilliary collections, ignoring potential NamespaceNotFound errors.
|
|
67
|
+
const dropOp = new DropCollectionOperation(db, collectionName, options);
|
|
68
|
+
await (0, execute_operation_1.executeOperation)(db.client, dropOp, timeoutContext);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return await (0, execute_operation_1.executeOperation)(db.client, new DropCollectionOperation(db, name, options), timeoutContext);
|
|
72
|
+
}
|
|
73
|
+
/** @internal */
|
|
74
|
+
class DropDatabaseOperation extends command_1.CommandOperation {
|
|
75
|
+
constructor(db, options) {
|
|
76
|
+
super(db, options);
|
|
77
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
|
|
78
|
+
this.options = options;
|
|
79
|
+
}
|
|
80
|
+
get commandName() {
|
|
81
|
+
return 'dropDatabase';
|
|
82
|
+
}
|
|
83
|
+
buildCommandDocument(_connection, _session) {
|
|
84
|
+
return { dropDatabase: 1 };
|
|
85
|
+
}
|
|
86
|
+
handleOk(_response) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.DropDatabaseOperation = DropDatabaseOperation;
|
|
91
|
+
(0, operation_1.defineAspects)(DropCollectionOperation, [operation_1.Aspect.WRITE_OPERATION]);
|
|
92
|
+
(0, operation_1.defineAspects)(DropDatabaseOperation, [operation_1.Aspect.WRITE_OPERATION]);
|
|
93
|
+
//# sourceMappingURL=drop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop.js","sourceRoot":"","sources":["../../src/operations/drop.ts"],"names":[],"mappings":";;;AAmDA,0CAkDC;AArGD,0BAAwE;AAExE,+DAAkE;AAClE,+DAAiE;AAEjE,oCAA+C;AAE/C,wCAA4C;AAC5C,uCAA2E;AAC3E,2DAAuD;AACvD,2CAAoD;AAQpD,gBAAgB;AAChB,MAAa,uBAAwB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9C,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAJZ,iCAA4B,GAAG,2BAAe,CAAC;QAKtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IACD,IAAa,WAAW;QACtB,OAAO,cAAuB,CAAC;IACjC,CAAC;IAEQ,oBAAoB,CAAC,WAAuB,EAAE,QAAwB;QAC7E,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IAC7B,CAAC;IAEQ,QAAQ,CAAC,SAAiE;QACjF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAnBD,sDAmBC;AAED,IAAA,yBAAa,EAAC,uBAAuB,EAAE,CAAC,kBAAM,CAAC,eAAe,CAAC,CAAC,CAAC;AACjE,IAAA,yBAAa,EAAC,qBAAqB,EAAE,CAAC,kBAAM,CAAC,eAAe,CAAC,CAAC,CAAC"}
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"end_sessions.js","sourceRoot":"","sources":["../../src/operations/end_sessions.ts"],"names":[],"mappings":";;;AASA,+DAAkE;AAClE,mDAAyD;AACzD,wDAAoD;AACpD,oCAA4C;AAC5C,2CAAoD;AAEpD,MAAa,oBAAqB,SAAQ,0BAAsB;IAO9D,YAAY,QAAgC;QAC1C,KAAK,EAAE,CAAC;QAPD,iBAAY,GAAiB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACtC,OAAE,GAAG,wBAAgB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;QAC/C,iCAA4B,GAAG,2BAAe,CAAC;QAMtD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEQ,oBAAoB,CAAC,WAAuB,EAAE,QAAwB;QAC7E,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,QAAQ;SAC3B,CAAC;IACJ,CAAC;IACQ,YAAY,CAAC,cAA8B;QAClD,OAAO;YACL,cAAc;YACd,cAAc,EAAE,gCAAc,CAAC,gBAAgB;SAChD,CAAC;IACJ,CAAC;IACD,IAAa,WAAW;QACtB,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AA1BD,oDA0BC;AAED,IAAA,yBAAa,EAAC,oBAAoB,EAAE,kBAAM,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EstimatedDocumentCountOperation = void 0;
|
|
4
|
+
const responses_1 = require("../cmap/wire_protocol/responses");
|
|
5
|
+
const command_1 = require("./command");
|
|
6
|
+
const operation_1 = require("./operation");
|
|
7
|
+
/** @internal */
|
|
8
|
+
class EstimatedDocumentCountOperation extends command_1.CommandOperation {
|
|
9
|
+
constructor(collection, options = {}) {
|
|
10
|
+
super(collection, options);
|
|
11
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.collectionName = collection.collectionName;
|
|
14
|
+
}
|
|
15
|
+
get commandName() {
|
|
16
|
+
return 'count';
|
|
17
|
+
}
|
|
18
|
+
buildCommandDocument(_connection, _session) {
|
|
19
|
+
const cmd = { count: this.collectionName };
|
|
20
|
+
if (typeof this.options.maxTimeMS === 'number') {
|
|
21
|
+
cmd.maxTimeMS = this.options.maxTimeMS;
|
|
22
|
+
}
|
|
23
|
+
// we check for undefined specifically here to allow falsy values
|
|
24
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
25
|
+
if (this.options.comment !== undefined) {
|
|
26
|
+
cmd.comment = this.options.comment;
|
|
27
|
+
}
|
|
28
|
+
return cmd;
|
|
29
|
+
}
|
|
30
|
+
handleOk(response) {
|
|
31
|
+
return response.getNumber('n') ?? 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.EstimatedDocumentCountOperation = EstimatedDocumentCountOperation;
|
|
35
|
+
(0, operation_1.defineAspects)(EstimatedDocumentCountOperation, [
|
|
36
|
+
operation_1.Aspect.READ_OPERATION,
|
|
37
|
+
operation_1.Aspect.RETRYABLE,
|
|
38
|
+
operation_1.Aspect.CURSOR_CREATING,
|
|
39
|
+
operation_1.Aspect.SUPPORTS_RAW_DATA
|
|
40
|
+
]);
|
|
41
|
+
//# sourceMappingURL=estimated_document_count.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimated_document_count.js","sourceRoot":"","sources":["../../src/operations/estimated_document_count.ts"],"names":[],"mappings":";;;AAEA,+DAAkE;AAGlE,uCAA2E;AAC3E,2CAAoD;AAYpD,gBAAgB;AAChB,MAAa,+BAAgC,SAAQ,0BAAwB;IAK3E,YAAY,UAAsB,EAAE,UAAyC,EAAE;QAC7E,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QALpB,iCAA4B,GAAG,2BAAe,CAAC;QAMtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;IAClD,CAAC;IAED,IAAa,WAAW;QACtB,OAAO,OAAgB,CAAC;IAC1B,CAAC;IAEQ,oBAAoB,CAAC,WAAuB,EAAE,QAAwB;QAC7E,MAAM,GAAG,GAAa,EAAE,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC;QAErD,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC/C,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;QACzC,CAAC;QAED,iEAAiE;QACjE,gDAAgD;QAChD,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACvC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QACrC,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;IAEQ,QAAQ,CAAC,QAAgE;QAChF,OAAO,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACF;AAlCD,0EAkCC;AAED,IAAA,yBAAa,EAAC,+BAA+B,EAAE;IAC7C,kBAAM,CAAC,cAAc;IACrB,kBAAM,CAAC,SAAS;IAChB,kBAAM,CAAC,eAAe;IACtB,kBAAM,CAAC,iBAAiB;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeOperation = executeOperation;
|
|
4
|
+
exports.autoConnect = autoConnect;
|
|
5
|
+
const constants_1 = require("../cmap/wire_protocol/constants");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const read_preference_1 = require("../read_preference");
|
|
8
|
+
const server_selection_1 = require("../sdam/server_selection");
|
|
9
|
+
const timeout_1 = require("../timeout");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
const aggregate_1 = require("./aggregate");
|
|
12
|
+
const operation_1 = require("./operation");
|
|
13
|
+
const MMAPv1_RETRY_WRITES_ERROR_CODE = error_1.MONGODB_ERROR_CODES.IllegalOperation;
|
|
14
|
+
const MMAPv1_RETRY_WRITES_ERROR_MESSAGE = 'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.';
|
|
15
|
+
/**
|
|
16
|
+
* Executes the given operation with provided arguments.
|
|
17
|
+
* @internal
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Allows for a single point of entry to provide features such as implicit sessions, which
|
|
21
|
+
* are required by the Driver Sessions specification in the event that a ClientSession is
|
|
22
|
+
* not provided.
|
|
23
|
+
*
|
|
24
|
+
* The expectation is that this function:
|
|
25
|
+
* - Connects the MongoClient if it has not already been connected, see {@link autoConnect}
|
|
26
|
+
* - Creates a session if none is provided and cleans up the session it creates
|
|
27
|
+
* - Tries an operation and retries under certain conditions, see {@link tryOperation}
|
|
28
|
+
*
|
|
29
|
+
* @typeParam T - The operation's type
|
|
30
|
+
* @typeParam TResult - The type of the operation's result, calculated from T
|
|
31
|
+
*
|
|
32
|
+
* @param client - The MongoClient to execute this operation with
|
|
33
|
+
* @param operation - The operation to execute
|
|
34
|
+
*/
|
|
35
|
+
async function executeOperation(client, operation, timeoutContext) {
|
|
36
|
+
if (!(operation instanceof operation_1.AbstractOperation)) {
|
|
37
|
+
// TODO(NODE-3483): Extend MongoRuntimeError
|
|
38
|
+
throw new error_1.MongoRuntimeError('This method requires a valid operation instance');
|
|
39
|
+
}
|
|
40
|
+
const topology = client.topology == null
|
|
41
|
+
? await (0, utils_1.abortable)(autoConnect(client), operation.options)
|
|
42
|
+
: client.topology;
|
|
43
|
+
// The driver sessions spec mandates that we implicitly create sessions for operations
|
|
44
|
+
// that are not explicitly provided with a session.
|
|
45
|
+
let session = operation.session;
|
|
46
|
+
let owner;
|
|
47
|
+
if (session == null) {
|
|
48
|
+
owner = Symbol();
|
|
49
|
+
session = client.startSession({ owner, explicit: false });
|
|
50
|
+
}
|
|
51
|
+
else if (session.hasEnded) {
|
|
52
|
+
throw new error_1.MongoExpiredSessionError('Use of expired sessions is not permitted');
|
|
53
|
+
}
|
|
54
|
+
else if (session.snapshotEnabled &&
|
|
55
|
+
(0, utils_1.maxWireVersion)(topology) < constants_1.MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION) {
|
|
56
|
+
throw new error_1.MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later');
|
|
57
|
+
}
|
|
58
|
+
else if (session.client !== client) {
|
|
59
|
+
throw new error_1.MongoInvalidArgumentError('ClientSession must be from the same MongoClient');
|
|
60
|
+
}
|
|
61
|
+
operation.session ??= session;
|
|
62
|
+
const readPreference = operation.readPreference ?? read_preference_1.ReadPreference.primary;
|
|
63
|
+
const inTransaction = !!session?.inTransaction();
|
|
64
|
+
const hasReadAspect = operation.hasAspect(operation_1.Aspect.READ_OPERATION);
|
|
65
|
+
if (inTransaction &&
|
|
66
|
+
!readPreference.equals(read_preference_1.ReadPreference.primary) &&
|
|
67
|
+
(hasReadAspect || operation.commandName === 'runCommand')) {
|
|
68
|
+
throw new error_1.MongoTransactionError(`Read preference in a transaction must be primary, not: ${readPreference.mode}`);
|
|
69
|
+
}
|
|
70
|
+
if (session?.isPinned && session.transaction.isCommitted && !operation.bypassPinningCheck) {
|
|
71
|
+
session.unpin();
|
|
72
|
+
}
|
|
73
|
+
timeoutContext ??= timeout_1.TimeoutContext.create({
|
|
74
|
+
session,
|
|
75
|
+
serverSelectionTimeoutMS: client.s.options.serverSelectionTimeoutMS,
|
|
76
|
+
waitQueueTimeoutMS: client.s.options.waitQueueTimeoutMS,
|
|
77
|
+
timeoutMS: operation.options.timeoutMS
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
return await tryOperation(operation, {
|
|
81
|
+
topology,
|
|
82
|
+
timeoutContext,
|
|
83
|
+
session,
|
|
84
|
+
readPreference
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
if (session?.owner != null && session.owner === owner) {
|
|
89
|
+
await session.endSession();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Connects a client if it has not yet been connected
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
async function autoConnect(client) {
|
|
98
|
+
if (client.topology == null) {
|
|
99
|
+
if (client.s.hasBeenClosed) {
|
|
100
|
+
throw new error_1.MongoNotConnectedError('Client must be connected before running operations');
|
|
101
|
+
}
|
|
102
|
+
client.s.options.__skipPingOnConnect = true;
|
|
103
|
+
try {
|
|
104
|
+
await client.connect();
|
|
105
|
+
if (client.topology == null) {
|
|
106
|
+
throw new error_1.MongoRuntimeError('client.connect did not create a topology but also did not throw');
|
|
107
|
+
}
|
|
108
|
+
return client.topology;
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
delete client.s.options.__skipPingOnConnect;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return client.topology;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Executes an operation and retries as appropriate
|
|
118
|
+
* @internal
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* Implements behaviour described in [Retryable Reads](https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.md) and [Retryable
|
|
122
|
+
* Writes](https://github.com/mongodb/specifications/blob/master/source/retryable-writes/retryable-writes.md) specification
|
|
123
|
+
*
|
|
124
|
+
* This function:
|
|
125
|
+
* - performs initial server selection
|
|
126
|
+
* - attempts to execute an operation
|
|
127
|
+
* - retries the operation if it meets the criteria for a retryable read or a retryable write
|
|
128
|
+
*
|
|
129
|
+
* @typeParam T - The operation's type
|
|
130
|
+
* @typeParam TResult - The type of the operation's result, calculated from T
|
|
131
|
+
*
|
|
132
|
+
* @param operation - The operation to execute
|
|
133
|
+
* */
|
|
134
|
+
async function tryOperation(operation, { topology, timeoutContext, session, readPreference }) {
|
|
135
|
+
let selector;
|
|
136
|
+
if (operation.hasAspect(operation_1.Aspect.MUST_SELECT_SAME_SERVER)) {
|
|
137
|
+
// GetMore and KillCursor operations must always select the same server, but run through
|
|
138
|
+
// server selection to potentially force monitor checks if the server is
|
|
139
|
+
// in an unknown state.
|
|
140
|
+
selector = (0, server_selection_1.sameServerSelector)(operation.server?.description);
|
|
141
|
+
}
|
|
142
|
+
else if (operation instanceof aggregate_1.AggregateOperation && operation.hasWriteStage) {
|
|
143
|
+
// If operation should try to write to secondary use the custom server selector
|
|
144
|
+
// otherwise provide the read preference.
|
|
145
|
+
selector = (0, server_selection_1.secondaryWritableServerSelector)(topology.commonWireVersion, readPreference);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
selector = readPreference;
|
|
149
|
+
}
|
|
150
|
+
let server = await topology.selectServer(selector, {
|
|
151
|
+
session,
|
|
152
|
+
operationName: operation.commandName,
|
|
153
|
+
timeoutContext,
|
|
154
|
+
signal: operation.options.signal,
|
|
155
|
+
deprioritizedServers: new server_selection_1.DeprioritizedServers()
|
|
156
|
+
});
|
|
157
|
+
const hasReadAspect = operation.hasAspect(operation_1.Aspect.READ_OPERATION);
|
|
158
|
+
const hasWriteAspect = operation.hasAspect(operation_1.Aspect.WRITE_OPERATION);
|
|
159
|
+
const inTransaction = session?.inTransaction() ?? false;
|
|
160
|
+
const willRetryRead = topology.s.options.retryReads && !inTransaction && operation.canRetryRead;
|
|
161
|
+
const willRetryWrite = topology.s.options.retryWrites &&
|
|
162
|
+
!inTransaction &&
|
|
163
|
+
(0, utils_1.supportsRetryableWrites)(server) &&
|
|
164
|
+
operation.canRetryWrite;
|
|
165
|
+
const willRetry = operation.hasAspect(operation_1.Aspect.RETRYABLE) &&
|
|
166
|
+
session != null &&
|
|
167
|
+
((hasReadAspect && willRetryRead) || (hasWriteAspect && willRetryWrite));
|
|
168
|
+
if (hasWriteAspect && willRetryWrite && session != null) {
|
|
169
|
+
operation.options.willRetryWrite = true;
|
|
170
|
+
session.incrementTransactionNumber();
|
|
171
|
+
}
|
|
172
|
+
const maxTries = willRetry ? (timeoutContext.csotEnabled() ? Infinity : 2) : 1;
|
|
173
|
+
let previousOperationError;
|
|
174
|
+
const deprioritizedServers = new server_selection_1.DeprioritizedServers();
|
|
175
|
+
for (let tries = 0; tries < maxTries; tries++) {
|
|
176
|
+
if (previousOperationError) {
|
|
177
|
+
if (hasWriteAspect && previousOperationError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {
|
|
178
|
+
throw new error_1.MongoServerError({
|
|
179
|
+
message: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
|
|
180
|
+
errmsg: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
|
|
181
|
+
originalError: previousOperationError
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (operation.hasAspect(operation_1.Aspect.COMMAND_BATCHING) && !operation.canRetryWrite) {
|
|
185
|
+
throw previousOperationError;
|
|
186
|
+
}
|
|
187
|
+
if (hasWriteAspect && !(0, error_1.isRetryableWriteError)(previousOperationError))
|
|
188
|
+
throw previousOperationError;
|
|
189
|
+
if (hasReadAspect && !(0, error_1.isRetryableReadError)(previousOperationError)) {
|
|
190
|
+
throw previousOperationError;
|
|
191
|
+
}
|
|
192
|
+
if (previousOperationError instanceof error_1.MongoNetworkError &&
|
|
193
|
+
operation.hasAspect(operation_1.Aspect.CURSOR_CREATING) &&
|
|
194
|
+
session != null &&
|
|
195
|
+
session.isPinned &&
|
|
196
|
+
!session.inTransaction()) {
|
|
197
|
+
session.unpin({ force: true, forceClear: true });
|
|
198
|
+
}
|
|
199
|
+
server = await topology.selectServer(selector, {
|
|
200
|
+
session,
|
|
201
|
+
operationName: operation.commandName,
|
|
202
|
+
deprioritizedServers,
|
|
203
|
+
signal: operation.options.signal
|
|
204
|
+
});
|
|
205
|
+
if (hasWriteAspect && !(0, utils_1.supportsRetryableWrites)(server)) {
|
|
206
|
+
throw new error_1.MongoUnexpectedServerResponseError('Selected server does not support retryable writes');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
operation.server = server;
|
|
210
|
+
try {
|
|
211
|
+
// If tries > 0 and we are command batching we need to reset the batch.
|
|
212
|
+
if (tries > 0 && operation.hasAspect(operation_1.Aspect.COMMAND_BATCHING)) {
|
|
213
|
+
operation.resetBatch();
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
const result = await server.command(operation, timeoutContext);
|
|
217
|
+
return operation.handleOk(result);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
return operation.handleError(error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (operationError) {
|
|
224
|
+
if (!(operationError instanceof error_1.MongoError))
|
|
225
|
+
throw operationError;
|
|
226
|
+
if (previousOperationError != null &&
|
|
227
|
+
operationError.hasErrorLabel(error_1.MongoErrorLabel.NoWritesPerformed)) {
|
|
228
|
+
throw previousOperationError;
|
|
229
|
+
}
|
|
230
|
+
deprioritizedServers.add(server.description);
|
|
231
|
+
previousOperationError = operationError;
|
|
232
|
+
// Reset timeouts
|
|
233
|
+
timeoutContext.clear();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
throw (previousOperationError ??
|
|
237
|
+
new error_1.MongoRuntimeError('Tried to propagate retryability error, but no error was found.'));
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=execute_operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute_operation.js","sourceRoot":"","sources":["../../src/operations/execute_operation.ts"],"names":[],"mappings":";;AA4DA,4CAyEC;AAMD,kCAmBC;AA9JD,+DAA4F;AAC5F,oCAekB;AAElB,wDAAoD;AACpD,+DAKkC;AAGlC,wCAA4C;AAC5C,oCAA8E;AAC9E,2CAAiD;AACjD,2CAAwD;AAExD,MAAM,8BAA8B,GAAG,2BAAmB,CAAC,gBAAgB,CAAC;AAC5E,MAAM,iCAAiC,GACrC,oHAAoH,CAAC;AAMvH;;;;;;;;;;;;;;;;;;;GAmBG;AACI,KAAK,UAAU,gBAAgB,CAGpC,MAAmB,EAAE,SAAY,EAAE,cAAsC;IACzE,IAAI,CAAC,CAAC,SAAS,YAAY,6BAAiB,CAAC,EAAE,CAAC;QAC9C,4CAA4C;QAC5C,MAAM,IAAI,yBAAiB,CAAC,iDAAiD,CAAC,CAAC;IACjF,CAAC;IAED,MAAM,QAAQ,GACZ,MAAM,CAAC,QAAQ,IAAI,IAAI;QACrB,CAAC,CAAC,MAAM,IAAA,iBAAS,EAAC,WAAW,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC;QACzD,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAEtB,sFAAsF;IACtF,mDAAmD;IACnD,IAAI,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;IAChC,IAAI,KAAyB,CAAC;IAE9B,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,KAAK,GAAG,MAAM,EAAE,CAAC;QACjB,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5D,CAAC;SAAM,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,gCAAwB,CAAC,0CAA0C,CAAC,CAAC;IACjF,CAAC;SAAM,IACL,OAAO,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