@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,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientBulkWriteCursorResponse = exports.ExplainedCursorResponse = exports.CursorResponse = exports.MongoDBResponse = void 0;
|
|
4
|
+
exports.isErrorResponse = isErrorResponse;
|
|
5
|
+
const bson_1 = require("../../bson");
|
|
6
|
+
const error_1 = require("../../error");
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const document_1 = require("./on_demand/document");
|
|
9
|
+
const BSONElementOffset = {
|
|
10
|
+
type: 0,
|
|
11
|
+
nameOffset: 1,
|
|
12
|
+
nameLength: 2,
|
|
13
|
+
offset: 3,
|
|
14
|
+
length: 4
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Accepts a BSON payload and checks for na "ok: 0" element.
|
|
18
|
+
* This utility is intended to prevent calling response class constructors
|
|
19
|
+
* that expect the result to be a success and demand certain properties to exist.
|
|
20
|
+
*
|
|
21
|
+
* For example, a cursor response always expects a cursor embedded document.
|
|
22
|
+
* In order to write the class such that the properties reflect that assertion (non-null)
|
|
23
|
+
* we cannot invoke the subclass constructor if the BSON represents an error.
|
|
24
|
+
*
|
|
25
|
+
* @param bytes - BSON document returned from the server
|
|
26
|
+
*/
|
|
27
|
+
function isErrorResponse(bson, elements) {
|
|
28
|
+
for (let eIdx = 0; eIdx < elements.length; eIdx++) {
|
|
29
|
+
const element = elements[eIdx];
|
|
30
|
+
if (element[BSONElementOffset.nameLength] === 2) {
|
|
31
|
+
const nameOffset = element[BSONElementOffset.nameOffset];
|
|
32
|
+
// 111 == "o", 107 == "k"
|
|
33
|
+
if (bson[nameOffset] === 111 && bson[nameOffset + 1] === 107) {
|
|
34
|
+
const valueOffset = element[BSONElementOffset.offset];
|
|
35
|
+
const valueLength = element[BSONElementOffset.length];
|
|
36
|
+
// If any byte in the length of the ok number (works for any type) is non zero,
|
|
37
|
+
// then it is considered "ok: 1"
|
|
38
|
+
for (let i = valueOffset; i < valueOffset + valueLength; i++) {
|
|
39
|
+
if (bson[i] !== 0x00)
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
/** @internal */
|
|
49
|
+
class MongoDBResponse extends document_1.OnDemandDocument {
|
|
50
|
+
get(name, as, required) {
|
|
51
|
+
try {
|
|
52
|
+
return super.get(name, as, required);
|
|
53
|
+
}
|
|
54
|
+
catch (cause) {
|
|
55
|
+
throw new error_1.MongoUnexpectedServerResponseError(cause.message, { cause });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
static is(value) {
|
|
59
|
+
return value instanceof MongoDBResponse;
|
|
60
|
+
}
|
|
61
|
+
static make(bson) {
|
|
62
|
+
const elements = (0, bson_1.parseToElementsToArray)(bson, 0);
|
|
63
|
+
const isError = isErrorResponse(bson, elements);
|
|
64
|
+
return isError
|
|
65
|
+
? new MongoDBResponse(bson, 0, false, elements)
|
|
66
|
+
: new this(bson, 0, false, elements);
|
|
67
|
+
}
|
|
68
|
+
// {ok:1}
|
|
69
|
+
static { this.empty = new MongoDBResponse(new Uint8Array([13, 0, 0, 0, 16, 111, 107, 0, 1, 0, 0, 0, 0])); }
|
|
70
|
+
/**
|
|
71
|
+
* Returns true iff:
|
|
72
|
+
* - ok is 0 and the top-level code === 50
|
|
73
|
+
* - ok is 1 and the writeErrors array contains a code === 50
|
|
74
|
+
* - ok is 1 and the writeConcern object contains a code === 50
|
|
75
|
+
*/
|
|
76
|
+
get isMaxTimeExpiredError() {
|
|
77
|
+
// {ok: 0, code: 50 ... }
|
|
78
|
+
const isTopLevel = this.ok === 0 && this.code === error_1.MONGODB_ERROR_CODES.MaxTimeMSExpired;
|
|
79
|
+
if (isTopLevel)
|
|
80
|
+
return true;
|
|
81
|
+
if (this.ok === 0)
|
|
82
|
+
return false;
|
|
83
|
+
// {ok: 1, writeConcernError: {code: 50 ... }}
|
|
84
|
+
const isWriteConcern = this.get('writeConcernError', bson_1.BSONType.object)?.getNumber('code') ===
|
|
85
|
+
error_1.MONGODB_ERROR_CODES.MaxTimeMSExpired;
|
|
86
|
+
if (isWriteConcern)
|
|
87
|
+
return true;
|
|
88
|
+
const writeErrors = this.get('writeErrors', bson_1.BSONType.array);
|
|
89
|
+
if (writeErrors?.size()) {
|
|
90
|
+
for (let i = 0; i < writeErrors.size(); i++) {
|
|
91
|
+
const isWriteError = writeErrors.get(i, bson_1.BSONType.object)?.getNumber('code') ===
|
|
92
|
+
error_1.MONGODB_ERROR_CODES.MaxTimeMSExpired;
|
|
93
|
+
// {ok: 1, writeErrors: [{code: 50 ... }]}
|
|
94
|
+
if (isWriteError)
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Drivers can safely assume that the `recoveryToken` field is always a BSON document but drivers MUST NOT modify the
|
|
102
|
+
* contents of the document.
|
|
103
|
+
*/
|
|
104
|
+
get recoveryToken() {
|
|
105
|
+
return (this.get('recoveryToken', bson_1.BSONType.object)?.toObject({
|
|
106
|
+
promoteValues: false,
|
|
107
|
+
promoteLongs: false,
|
|
108
|
+
promoteBuffers: false,
|
|
109
|
+
validation: { utf8: true }
|
|
110
|
+
}) ?? null);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The server creates a cursor in response to a snapshot find/aggregate command and reports atClusterTime within the cursor field in the response.
|
|
114
|
+
* For the distinct command the server adds a top-level atClusterTime field to the response.
|
|
115
|
+
* The atClusterTime field represents the timestamp of the read and is guaranteed to be majority committed.
|
|
116
|
+
*/
|
|
117
|
+
get atClusterTime() {
|
|
118
|
+
return (this.get('cursor', bson_1.BSONType.object)?.get('atClusterTime', bson_1.BSONType.timestamp) ??
|
|
119
|
+
this.get('atClusterTime', bson_1.BSONType.timestamp));
|
|
120
|
+
}
|
|
121
|
+
get operationTime() {
|
|
122
|
+
return this.get('operationTime', bson_1.BSONType.timestamp);
|
|
123
|
+
}
|
|
124
|
+
/** Normalizes whatever BSON value is "ok" to a JS number 1 or 0. */
|
|
125
|
+
get ok() {
|
|
126
|
+
return this.getNumber('ok') ? 1 : 0;
|
|
127
|
+
}
|
|
128
|
+
get $err() {
|
|
129
|
+
return this.get('$err', bson_1.BSONType.string);
|
|
130
|
+
}
|
|
131
|
+
get errmsg() {
|
|
132
|
+
return this.get('errmsg', bson_1.BSONType.string);
|
|
133
|
+
}
|
|
134
|
+
get code() {
|
|
135
|
+
return this.getNumber('code');
|
|
136
|
+
}
|
|
137
|
+
get $clusterTime() {
|
|
138
|
+
if (!('clusterTime' in this)) {
|
|
139
|
+
const clusterTimeDoc = this.get('$clusterTime', bson_1.BSONType.object);
|
|
140
|
+
if (clusterTimeDoc == null) {
|
|
141
|
+
this.clusterTime = null;
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const clusterTime = clusterTimeDoc.get('clusterTime', bson_1.BSONType.timestamp, true);
|
|
145
|
+
const signature = clusterTimeDoc.get('signature', bson_1.BSONType.object)?.toObject();
|
|
146
|
+
// @ts-expect-error: `signature` is incorrectly typed. It is public API.
|
|
147
|
+
this.clusterTime = { clusterTime, signature };
|
|
148
|
+
}
|
|
149
|
+
return this.clusterTime ?? null;
|
|
150
|
+
}
|
|
151
|
+
toObject(options) {
|
|
152
|
+
const exactBSONOptions = {
|
|
153
|
+
...(0, bson_1.pluckBSONSerializeOptions)(options ?? {}),
|
|
154
|
+
validation: (0, bson_1.parseUtf8ValidationOption)(options)
|
|
155
|
+
};
|
|
156
|
+
return super.toObject(exactBSONOptions);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.MongoDBResponse = MongoDBResponse;
|
|
160
|
+
/** @internal */
|
|
161
|
+
class CursorResponse extends MongoDBResponse {
|
|
162
|
+
constructor() {
|
|
163
|
+
super(...arguments);
|
|
164
|
+
this._batch = null;
|
|
165
|
+
this.iterated = 0;
|
|
166
|
+
this._encryptedBatch = null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* This supports a feature of the FindCursor.
|
|
170
|
+
* It is an optimization to avoid an extra getMore when the limit has been reached
|
|
171
|
+
*/
|
|
172
|
+
static get emptyGetMore() {
|
|
173
|
+
return new CursorResponse((0, bson_1.serialize)({ ok: 1, cursor: { id: 0n, nextBatch: [] } }));
|
|
174
|
+
}
|
|
175
|
+
static is(value) {
|
|
176
|
+
return value instanceof CursorResponse || value === CursorResponse.emptyGetMore;
|
|
177
|
+
}
|
|
178
|
+
get cursor() {
|
|
179
|
+
return this.get('cursor', bson_1.BSONType.object, true);
|
|
180
|
+
}
|
|
181
|
+
get id() {
|
|
182
|
+
try {
|
|
183
|
+
return bson_1.Long.fromBigInt(this.cursor.get('id', bson_1.BSONType.long, true));
|
|
184
|
+
}
|
|
185
|
+
catch (cause) {
|
|
186
|
+
throw new error_1.MongoUnexpectedServerResponseError(cause.message, { cause });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
get ns() {
|
|
190
|
+
const namespace = this.cursor.get('ns', bson_1.BSONType.string);
|
|
191
|
+
if (namespace != null)
|
|
192
|
+
return (0, utils_1.ns)(namespace);
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
get length() {
|
|
196
|
+
return Math.max(this.batchSize - this.iterated, 0);
|
|
197
|
+
}
|
|
198
|
+
get encryptedBatch() {
|
|
199
|
+
if (this.encryptedResponse == null)
|
|
200
|
+
return null;
|
|
201
|
+
if (this._encryptedBatch != null)
|
|
202
|
+
return this._encryptedBatch;
|
|
203
|
+
const cursor = this.encryptedResponse?.get('cursor', bson_1.BSONType.object);
|
|
204
|
+
if (cursor?.has('firstBatch'))
|
|
205
|
+
this._encryptedBatch = cursor.get('firstBatch', bson_1.BSONType.array, true);
|
|
206
|
+
else if (cursor?.has('nextBatch'))
|
|
207
|
+
this._encryptedBatch = cursor.get('nextBatch', bson_1.BSONType.array, true);
|
|
208
|
+
else
|
|
209
|
+
throw new error_1.MongoUnexpectedServerResponseError('Cursor document did not contain a batch');
|
|
210
|
+
return this._encryptedBatch;
|
|
211
|
+
}
|
|
212
|
+
get batch() {
|
|
213
|
+
if (this._batch != null)
|
|
214
|
+
return this._batch;
|
|
215
|
+
const cursor = this.cursor;
|
|
216
|
+
if (cursor.has('firstBatch'))
|
|
217
|
+
this._batch = cursor.get('firstBatch', bson_1.BSONType.array, true);
|
|
218
|
+
else if (cursor.has('nextBatch'))
|
|
219
|
+
this._batch = cursor.get('nextBatch', bson_1.BSONType.array, true);
|
|
220
|
+
else
|
|
221
|
+
throw new error_1.MongoUnexpectedServerResponseError('Cursor document did not contain a batch');
|
|
222
|
+
return this._batch;
|
|
223
|
+
}
|
|
224
|
+
get batchSize() {
|
|
225
|
+
return this.batch?.size();
|
|
226
|
+
}
|
|
227
|
+
get postBatchResumeToken() {
|
|
228
|
+
return (this.cursor.get('postBatchResumeToken', bson_1.BSONType.object)?.toObject({
|
|
229
|
+
promoteValues: false,
|
|
230
|
+
promoteLongs: false,
|
|
231
|
+
promoteBuffers: false,
|
|
232
|
+
validation: { utf8: true }
|
|
233
|
+
}) ?? null);
|
|
234
|
+
}
|
|
235
|
+
shift(options) {
|
|
236
|
+
if (this.iterated >= this.batchSize) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
const result = this.batch.get(this.iterated, bson_1.BSONType.object, true) ?? null;
|
|
240
|
+
const encryptedResult = this.encryptedBatch?.get(this.iterated, bson_1.BSONType.object, true) ?? null;
|
|
241
|
+
this.iterated += 1;
|
|
242
|
+
if (options?.raw) {
|
|
243
|
+
return result.toBytes();
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
const object = result.toObject(options);
|
|
247
|
+
if (encryptedResult) {
|
|
248
|
+
(0, utils_1.decorateDecryptionResult)(object, encryptedResult.toObject(options), true);
|
|
249
|
+
}
|
|
250
|
+
return object;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
clear() {
|
|
254
|
+
this.iterated = this.batchSize;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
exports.CursorResponse = CursorResponse;
|
|
258
|
+
/**
|
|
259
|
+
* Explain responses have nothing to do with cursor responses
|
|
260
|
+
* This class serves to temporarily avoid refactoring how cursors handle
|
|
261
|
+
* explain responses which is to detect that the response is not cursor-like and return the explain
|
|
262
|
+
* result as the "first and only" document in the "batch" and end the "cursor"
|
|
263
|
+
*/
|
|
264
|
+
class ExplainedCursorResponse extends CursorResponse {
|
|
265
|
+
constructor() {
|
|
266
|
+
super(...arguments);
|
|
267
|
+
this.isExplain = true;
|
|
268
|
+
this._length = 1;
|
|
269
|
+
}
|
|
270
|
+
get id() {
|
|
271
|
+
return bson_1.Long.fromBigInt(0n);
|
|
272
|
+
}
|
|
273
|
+
get batchSize() {
|
|
274
|
+
return 0;
|
|
275
|
+
}
|
|
276
|
+
get ns() {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
get length() {
|
|
280
|
+
return this._length;
|
|
281
|
+
}
|
|
282
|
+
shift(options) {
|
|
283
|
+
if (this._length === 0)
|
|
284
|
+
return null;
|
|
285
|
+
this._length -= 1;
|
|
286
|
+
return this.toObject(options);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
exports.ExplainedCursorResponse = ExplainedCursorResponse;
|
|
290
|
+
/**
|
|
291
|
+
* Client bulk writes have some extra metadata at the top level that needs to be
|
|
292
|
+
* included in the result returned to the user.
|
|
293
|
+
*/
|
|
294
|
+
class ClientBulkWriteCursorResponse extends CursorResponse {
|
|
295
|
+
get insertedCount() {
|
|
296
|
+
return this.get('nInserted', bson_1.BSONType.int, true);
|
|
297
|
+
}
|
|
298
|
+
get upsertedCount() {
|
|
299
|
+
return this.get('nUpserted', bson_1.BSONType.int, true);
|
|
300
|
+
}
|
|
301
|
+
get matchedCount() {
|
|
302
|
+
return this.get('nMatched', bson_1.BSONType.int, true);
|
|
303
|
+
}
|
|
304
|
+
get modifiedCount() {
|
|
305
|
+
return this.get('nModified', bson_1.BSONType.int, true);
|
|
306
|
+
}
|
|
307
|
+
get deletedCount() {
|
|
308
|
+
return this.get('nDeleted', bson_1.BSONType.int, true);
|
|
309
|
+
}
|
|
310
|
+
get writeConcernError() {
|
|
311
|
+
return this.get('writeConcernError', bson_1.BSONType.object, false);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
exports.ClientBulkWriteCursorResponse = ClientBulkWriteCursorResponse;
|
|
315
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../src/cmap/wire_protocol/responses.ts"],"names":[],"mappings":";;;AAyCA,0CAwBC;AAjED,qCAYoB;AACpB,uCAAsF;AAEtF,uCAA2D;AAC3D,mDAI8B;AAE9B,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,CAAC;IACP,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;CACD,CAAC;AAEX;;;;;;;;;;GAUG;AACH,SAAgB,eAAe,CAAC,IAAgB,EAAE,QAAuB;IACvE,KAAK,IAAI,IAAI,GAAG,CAAC,E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AO,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,eAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,eAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,iBAAiB;QACnB,OAAO,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,eAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;CACF;AAxBD,sEAwBC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getReadPreference = getReadPreference;
|
|
4
|
+
exports.isSharded = isSharded;
|
|
5
|
+
const error_1 = require("../../error");
|
|
6
|
+
const read_preference_1 = require("../../read_preference");
|
|
7
|
+
const common_1 = require("../../sdam/common");
|
|
8
|
+
const topology_description_1 = require("../../sdam/topology_description");
|
|
9
|
+
function getReadPreference(options) {
|
|
10
|
+
// Default to command version of the readPreference.
|
|
11
|
+
let readPreference = options?.readPreference ?? read_preference_1.ReadPreference.primary;
|
|
12
|
+
if (typeof readPreference === 'string') {
|
|
13
|
+
readPreference = read_preference_1.ReadPreference.fromString(readPreference);
|
|
14
|
+
}
|
|
15
|
+
if (!(readPreference instanceof read_preference_1.ReadPreference)) {
|
|
16
|
+
throw new error_1.MongoInvalidArgumentError('Option "readPreference" must be a ReadPreference instance');
|
|
17
|
+
}
|
|
18
|
+
return readPreference;
|
|
19
|
+
}
|
|
20
|
+
function isSharded(topologyOrServer) {
|
|
21
|
+
if (topologyOrServer == null) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (topologyOrServer.description && topologyOrServer.description.type === common_1.ServerType.Mongos) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
// NOTE: This is incredibly inefficient, and should be removed once command construction
|
|
28
|
+
// happens based on `Server` not `Topology`.
|
|
29
|
+
if (topologyOrServer.description && topologyOrServer.description instanceof topology_description_1.TopologyDescription) {
|
|
30
|
+
const servers = Array.from(topologyOrServer.description.servers.values());
|
|
31
|
+
return servers.some((server) => server.type === common_1.ServerType.Mongos);
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/cmap/wire_protocol/shared.ts"],"names":[],"mappings":";;AAaA,8CAeC;AAED,8BAiBC;AA/CD,uCAAwD;AACxD,2DAAgF;AAChF,8CAA+C;AAI/C,0EAAsE;AAOtE,SAAgB,iBAAiB,CAAC,OAA8B;IAC9D,oDAAoD;IACpD,IAAI,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,gCAAc,CAAC,OAAO,CAAC;IAEvE,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;QACvC,cAAc,GAAG,gCAAc,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,CAAC,CAAC,cAAc,YAAY,gCAAc,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,iCAAyB,CACjC,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,SAAgB,SAAS,CAAC,gBAAiD;IACzE,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,WAAW,CAAC,IAAI,KAAK,mBAAU,CAAC,MAAM,EAAE,CAAC;QAC5F,OAAO,IAAI,CAAC;IACd,CAAC;IAED,wFAAwF;IACxF,4CAA4C;IAC5C,IAAI,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,WAAW,YAAY,0CAAmB,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