@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,211 @@
|
|
|
1
|
+
import * as zlib from 'zlib';
|
|
2
|
+
|
|
3
|
+
import { LEGACY_HELLO_COMMAND } from '../../constants';
|
|
4
|
+
import { getSnappy, getZstdLibrary, type SnappyLib, type ZStandard } from '../../deps';
|
|
5
|
+
import { MongoDecompressionError, MongoInvalidArgumentError } from '../../error';
|
|
6
|
+
import {
|
|
7
|
+
type MessageHeader,
|
|
8
|
+
OpCompressedRequest,
|
|
9
|
+
type OpCompressesRequestOptions,
|
|
10
|
+
OpMsgResponse,
|
|
11
|
+
OpReply,
|
|
12
|
+
type WriteProtocolMessageType
|
|
13
|
+
} from '../commands';
|
|
14
|
+
import { OP_COMPRESSED, OP_MSG } from './constants';
|
|
15
|
+
|
|
16
|
+
/** @public */
|
|
17
|
+
export const Compressor = Object.freeze({
|
|
18
|
+
none: 0,
|
|
19
|
+
snappy: 1,
|
|
20
|
+
zlib: 2,
|
|
21
|
+
zstd: 3
|
|
22
|
+
} as const);
|
|
23
|
+
|
|
24
|
+
/** @public */
|
|
25
|
+
export type Compressor = (typeof Compressor)[CompressorName];
|
|
26
|
+
|
|
27
|
+
/** @public */
|
|
28
|
+
export type CompressorName = keyof typeof Compressor;
|
|
29
|
+
|
|
30
|
+
export const uncompressibleCommands = new Set([
|
|
31
|
+
LEGACY_HELLO_COMMAND,
|
|
32
|
+
'saslStart',
|
|
33
|
+
'saslContinue',
|
|
34
|
+
'getnonce',
|
|
35
|
+
'authenticate',
|
|
36
|
+
'createUser',
|
|
37
|
+
'updateUser',
|
|
38
|
+
'copydbSaslStart',
|
|
39
|
+
'copydbgetnonce',
|
|
40
|
+
'copydb'
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const ZSTD_COMPRESSION_LEVEL = 3;
|
|
44
|
+
|
|
45
|
+
const zlibInflate = (buf: zlib.InputType) => {
|
|
46
|
+
return new Promise<Buffer>((resolve, reject) => {
|
|
47
|
+
zlib.inflate(buf, (error, result) => {
|
|
48
|
+
if (error) return reject(error);
|
|
49
|
+
resolve(result);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const zlibDeflate = (buf: zlib.InputType, options: zlib.ZlibOptions) => {
|
|
55
|
+
return new Promise<Buffer>((resolve, reject) => {
|
|
56
|
+
zlib.deflate(buf, options, (error, result) => {
|
|
57
|
+
if (error) return reject(error);
|
|
58
|
+
resolve(result);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
let zstd: ZStandard;
|
|
64
|
+
let Snappy: SnappyLib | null = null;
|
|
65
|
+
function loadSnappy() {
|
|
66
|
+
if (Snappy == null) {
|
|
67
|
+
const snappyImport = getSnappy();
|
|
68
|
+
if ('kModuleError' in snappyImport) {
|
|
69
|
+
throw snappyImport.kModuleError;
|
|
70
|
+
}
|
|
71
|
+
Snappy = snappyImport;
|
|
72
|
+
}
|
|
73
|
+
return Snappy;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Facilitate compressing a message using an agreed compressor
|
|
77
|
+
export async function compress(
|
|
78
|
+
options: OpCompressesRequestOptions,
|
|
79
|
+
dataToBeCompressed: Buffer
|
|
80
|
+
): Promise<Buffer> {
|
|
81
|
+
const zlibOptions = {} as zlib.ZlibOptions;
|
|
82
|
+
switch (options.agreedCompressor) {
|
|
83
|
+
case 'snappy': {
|
|
84
|
+
Snappy ??= loadSnappy();
|
|
85
|
+
return await Snappy.compress(dataToBeCompressed);
|
|
86
|
+
}
|
|
87
|
+
case 'zstd': {
|
|
88
|
+
loadZstd();
|
|
89
|
+
if ('kModuleError' in zstd) {
|
|
90
|
+
throw zstd['kModuleError'];
|
|
91
|
+
}
|
|
92
|
+
return await zstd.compress(dataToBeCompressed, ZSTD_COMPRESSION_LEVEL);
|
|
93
|
+
}
|
|
94
|
+
case 'zlib': {
|
|
95
|
+
if (options.zlibCompressionLevel) {
|
|
96
|
+
zlibOptions.level = options.zlibCompressionLevel;
|
|
97
|
+
}
|
|
98
|
+
return await zlibDeflate(dataToBeCompressed, zlibOptions);
|
|
99
|
+
}
|
|
100
|
+
default: {
|
|
101
|
+
throw new MongoInvalidArgumentError(
|
|
102
|
+
`Unknown compressor ${options.agreedCompressor} failed to compress`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Decompress a message using the given compressor
|
|
109
|
+
export async function decompress(compressorID: number, compressedData: Buffer): Promise<Buffer> {
|
|
110
|
+
if (
|
|
111
|
+
compressorID !== Compressor.snappy &&
|
|
112
|
+
compressorID !== Compressor.zstd &&
|
|
113
|
+
compressorID !== Compressor.zlib &&
|
|
114
|
+
compressorID !== Compressor.none
|
|
115
|
+
) {
|
|
116
|
+
throw new MongoDecompressionError(
|
|
117
|
+
`Server sent message compressed using an unsupported compressor. (Received compressor ID ${compressorID})`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
switch (compressorID) {
|
|
122
|
+
case Compressor.snappy: {
|
|
123
|
+
Snappy ??= loadSnappy();
|
|
124
|
+
return await Snappy.uncompress(compressedData, { asBuffer: true });
|
|
125
|
+
}
|
|
126
|
+
case Compressor.zstd: {
|
|
127
|
+
loadZstd();
|
|
128
|
+
if ('kModuleError' in zstd) {
|
|
129
|
+
throw zstd['kModuleError'];
|
|
130
|
+
}
|
|
131
|
+
return await zstd.decompress(compressedData);
|
|
132
|
+
}
|
|
133
|
+
case Compressor.zlib: {
|
|
134
|
+
return await zlibInflate(compressedData);
|
|
135
|
+
}
|
|
136
|
+
default: {
|
|
137
|
+
return compressedData;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Load ZStandard if it is not already set.
|
|
144
|
+
*/
|
|
145
|
+
function loadZstd() {
|
|
146
|
+
if (!zstd) {
|
|
147
|
+
zstd = getZstdLibrary();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const MESSAGE_HEADER_SIZE = 16;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @internal
|
|
155
|
+
*
|
|
156
|
+
* Compresses an OP_MSG or OP_QUERY message, if compression is configured. This method
|
|
157
|
+
* also serializes the command to BSON.
|
|
158
|
+
*/
|
|
159
|
+
export async function compressCommand(
|
|
160
|
+
command: WriteProtocolMessageType,
|
|
161
|
+
description: { agreedCompressor?: CompressorName; zlibCompressionLevel?: number }
|
|
162
|
+
): Promise<Buffer> {
|
|
163
|
+
const finalCommand =
|
|
164
|
+
description.agreedCompressor === 'none' || !OpCompressedRequest.canCompress(command)
|
|
165
|
+
? command
|
|
166
|
+
: new OpCompressedRequest(command, {
|
|
167
|
+
agreedCompressor: description.agreedCompressor ?? 'none',
|
|
168
|
+
zlibCompressionLevel: description.zlibCompressionLevel ?? 0
|
|
169
|
+
});
|
|
170
|
+
const data = await finalCommand.toBin();
|
|
171
|
+
return Buffer.concat(data);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @internal
|
|
176
|
+
*
|
|
177
|
+
* Decompresses an OP_MSG or OP_QUERY response from the server, if compression is configured.
|
|
178
|
+
*
|
|
179
|
+
* This method does not parse the response's BSON.
|
|
180
|
+
*/
|
|
181
|
+
export async function decompressResponse(message: Buffer): Promise<OpMsgResponse | OpReply> {
|
|
182
|
+
const messageHeader: MessageHeader = {
|
|
183
|
+
length: message.readInt32LE(0),
|
|
184
|
+
requestId: message.readInt32LE(4),
|
|
185
|
+
responseTo: message.readInt32LE(8),
|
|
186
|
+
opCode: message.readInt32LE(12)
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
if (messageHeader.opCode !== OP_COMPRESSED) {
|
|
190
|
+
const ResponseType = messageHeader.opCode === OP_MSG ? OpMsgResponse : OpReply;
|
|
191
|
+
const messageBody = message.subarray(MESSAGE_HEADER_SIZE);
|
|
192
|
+
return new ResponseType(message, messageHeader, messageBody);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const header: MessageHeader = {
|
|
196
|
+
...messageHeader,
|
|
197
|
+
fromCompressed: true,
|
|
198
|
+
opCode: message.readInt32LE(MESSAGE_HEADER_SIZE),
|
|
199
|
+
length: message.readInt32LE(MESSAGE_HEADER_SIZE + 4)
|
|
200
|
+
};
|
|
201
|
+
const compressorID = message[MESSAGE_HEADER_SIZE + 8];
|
|
202
|
+
const compressedBuffer = message.slice(MESSAGE_HEADER_SIZE + 9);
|
|
203
|
+
|
|
204
|
+
// recalculate based on wrapped opcode
|
|
205
|
+
const ResponseType = header.opCode === OP_MSG ? OpMsgResponse : OpReply;
|
|
206
|
+
const messageBody = await decompress(compressorID, compressedBuffer);
|
|
207
|
+
if (messageBody.length !== header.length) {
|
|
208
|
+
throw new MongoDecompressionError('Message body and message header must be the same length');
|
|
209
|
+
}
|
|
210
|
+
return new ResponseType(message, header, messageBody);
|
|
211
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const MIN_SUPPORTED_SERVER_VERSION = '4.2';
|
|
2
|
+
export const MAX_SUPPORTED_SERVER_VERSION = '8.2';
|
|
3
|
+
export const MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION = 13;
|
|
4
|
+
export const MIN_SUPPORTED_SNAPSHOT_READS_SERVER_VERSION = '5.0';
|
|
5
|
+
export const MIN_SUPPORTED_WIRE_VERSION = 8;
|
|
6
|
+
export const MAX_SUPPORTED_WIRE_VERSION = 27;
|
|
7
|
+
export const MIN_SUPPORTED_QE_WIRE_VERSION = 21;
|
|
8
|
+
export const MIN_SUPPORTED_QE_SERVER_VERSION = '7.0';
|
|
9
|
+
export const MIN_SUPPORTED_RAW_DATA_WIRE_VERSION = 27;
|
|
10
|
+
export const MIN_SUPPORTED_RAW_DATA_SERVER_VERSION = '8.2';
|
|
11
|
+
export const OP_REPLY = 1;
|
|
12
|
+
export const OP_UPDATE = 2001;
|
|
13
|
+
export const OP_INSERT = 2002;
|
|
14
|
+
export const OP_QUERY = 2004;
|
|
15
|
+
export const OP_DELETE = 2006;
|
|
16
|
+
export const OP_COMPRESSED = 2012;
|
|
17
|
+
export const OP_MSG = 2013;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { type EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
import { type Abortable } from '../../mongo_types';
|
|
4
|
+
import { type TimeoutContext } from '../../timeout';
|
|
5
|
+
import { addAbortListener, kDispose, List, promiseWithResolvers } from '../../utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
* An object holding references to a promise's resolve and reject functions.
|
|
10
|
+
*/
|
|
11
|
+
type PendingPromises = Omit<
|
|
12
|
+
ReturnType<typeof promiseWithResolvers<IteratorResult<Buffer>>>,
|
|
13
|
+
'promise'
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* onData is adapted from Node.js' events.on helper
|
|
18
|
+
* https://nodejs.org/api/events.html#eventsonemitter-eventname-options
|
|
19
|
+
*
|
|
20
|
+
* Returns an AsyncIterator that iterates each 'data' event emitted from emitter.
|
|
21
|
+
* It will reject upon an error event.
|
|
22
|
+
*/
|
|
23
|
+
export function onData(
|
|
24
|
+
emitter: EventEmitter,
|
|
25
|
+
{ timeoutContext, signal }: { timeoutContext?: TimeoutContext } & Abortable
|
|
26
|
+
) {
|
|
27
|
+
signal?.throwIfAborted();
|
|
28
|
+
|
|
29
|
+
// Setup pending events and pending promise lists
|
|
30
|
+
/**
|
|
31
|
+
* When the caller has not yet called .next(), we store the
|
|
32
|
+
* value from the event in this list. Next time they call .next()
|
|
33
|
+
* we pull the first value out of this list and resolve a promise with it.
|
|
34
|
+
*/
|
|
35
|
+
const unconsumedEvents = new List<Buffer>();
|
|
36
|
+
/**
|
|
37
|
+
* When there has not yet been an event, a new promise will be created
|
|
38
|
+
* and implicitly stored in this list. When an event occurs we take the first
|
|
39
|
+
* promise in this list and resolve it.
|
|
40
|
+
*/
|
|
41
|
+
const unconsumedPromises = new List<PendingPromises>();
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Stored an error created by an error event.
|
|
45
|
+
* This error will turn into a rejection for the subsequent .next() call
|
|
46
|
+
*/
|
|
47
|
+
let error: Error | null = null;
|
|
48
|
+
|
|
49
|
+
/** Set to true only after event listeners have been removed. */
|
|
50
|
+
let finished = false;
|
|
51
|
+
|
|
52
|
+
const iterator: AsyncGenerator<Buffer> & AsyncDisposable = {
|
|
53
|
+
next() {
|
|
54
|
+
// First, we consume all unread events
|
|
55
|
+
const value = unconsumedEvents.shift();
|
|
56
|
+
if (value != null) {
|
|
57
|
+
return Promise.resolve({ value, done: false });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Then we error, if an error happened
|
|
61
|
+
// This happens one time if at all, because after 'error'
|
|
62
|
+
// we stop listening
|
|
63
|
+
if (error != null) {
|
|
64
|
+
const p = Promise.reject(error);
|
|
65
|
+
// Only the first element errors
|
|
66
|
+
error = null;
|
|
67
|
+
return p;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// If the iterator is finished, resolve to done
|
|
71
|
+
if (finished) return closeHandler();
|
|
72
|
+
|
|
73
|
+
// Wait until an event happens
|
|
74
|
+
const { promise, resolve, reject } = promiseWithResolvers<IteratorResult<Buffer>>();
|
|
75
|
+
unconsumedPromises.push({ resolve, reject });
|
|
76
|
+
return promise;
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
return() {
|
|
80
|
+
return closeHandler();
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
throw(err: Error) {
|
|
84
|
+
errorHandler(err);
|
|
85
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
[Symbol.asyncIterator]() {
|
|
89
|
+
return this;
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
async [Symbol.asyncDispose]() {
|
|
93
|
+
await closeHandler();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Adding event handlers
|
|
98
|
+
emitter.on('data', eventHandler);
|
|
99
|
+
emitter.on('error', errorHandler);
|
|
100
|
+
const abortListener = addAbortListener(signal, function () {
|
|
101
|
+
errorHandler(this.reason);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const timeoutForSocketRead = timeoutContext?.timeoutForSocketRead;
|
|
105
|
+
timeoutForSocketRead?.throwIfExpired();
|
|
106
|
+
timeoutForSocketRead?.then(undefined, errorHandler);
|
|
107
|
+
|
|
108
|
+
return iterator;
|
|
109
|
+
|
|
110
|
+
function eventHandler(value: Buffer) {
|
|
111
|
+
const promise = unconsumedPromises.shift();
|
|
112
|
+
if (promise != null) promise.resolve({ value, done: false });
|
|
113
|
+
else unconsumedEvents.push(value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function errorHandler(err: Error) {
|
|
117
|
+
const promise = unconsumedPromises.shift();
|
|
118
|
+
|
|
119
|
+
if (promise != null) promise.reject(err);
|
|
120
|
+
else error = err;
|
|
121
|
+
void closeHandler();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function closeHandler() {
|
|
125
|
+
// Adding event handlers
|
|
126
|
+
emitter.off('data', eventHandler);
|
|
127
|
+
emitter.off('error', errorHandler);
|
|
128
|
+
abortListener?.[kDispose]();
|
|
129
|
+
finished = true;
|
|
130
|
+
timeoutForSocketRead?.clear();
|
|
131
|
+
const doneResult = { value: undefined, done: finished } as const;
|
|
132
|
+
|
|
133
|
+
for (const promise of unconsumedPromises) {
|
|
134
|
+
promise.resolve(doneResult);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return Promise.resolve(doneResult);
|
|
138
|
+
}
|
|
139
|
+
}
|