@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
package/src/sort.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { MongoInvalidArgumentError } from './error';
|
|
2
|
+
|
|
3
|
+
/** @public */
|
|
4
|
+
export type SortDirection =
|
|
5
|
+
| 1
|
|
6
|
+
| -1
|
|
7
|
+
| 'asc'
|
|
8
|
+
| 'desc'
|
|
9
|
+
| 'ascending'
|
|
10
|
+
| 'descending'
|
|
11
|
+
| { readonly $meta: string };
|
|
12
|
+
|
|
13
|
+
/** @public */
|
|
14
|
+
export type Sort =
|
|
15
|
+
| string
|
|
16
|
+
| Exclude<SortDirection, { readonly $meta: string }>
|
|
17
|
+
| ReadonlyArray<string>
|
|
18
|
+
| { readonly [key: string]: SortDirection }
|
|
19
|
+
| ReadonlyMap<string, SortDirection>
|
|
20
|
+
| ReadonlyArray<readonly [string, SortDirection]>
|
|
21
|
+
| readonly [string, SortDirection];
|
|
22
|
+
|
|
23
|
+
/** Below stricter types were created for sort that correspond with type that the cmd takes */
|
|
24
|
+
|
|
25
|
+
/** @public */
|
|
26
|
+
export type SortDirectionForCmd = 1 | -1 | { $meta: string };
|
|
27
|
+
|
|
28
|
+
/** @public */
|
|
29
|
+
export type SortForCmd = Map<string, SortDirectionForCmd>;
|
|
30
|
+
|
|
31
|
+
/** @internal */
|
|
32
|
+
type SortPairForCmd = [string, SortDirectionForCmd];
|
|
33
|
+
|
|
34
|
+
/** @internal */
|
|
35
|
+
function prepareDirection(direction: any = 1): SortDirectionForCmd {
|
|
36
|
+
const value = `${direction}`.toLowerCase();
|
|
37
|
+
if (isMeta(direction)) return direction;
|
|
38
|
+
switch (value) {
|
|
39
|
+
case 'ascending':
|
|
40
|
+
case 'asc':
|
|
41
|
+
case '1':
|
|
42
|
+
return 1;
|
|
43
|
+
case 'descending':
|
|
44
|
+
case 'desc':
|
|
45
|
+
case '-1':
|
|
46
|
+
return -1;
|
|
47
|
+
default:
|
|
48
|
+
throw new MongoInvalidArgumentError(`Invalid sort direction: ${JSON.stringify(direction)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @internal */
|
|
53
|
+
function isMeta(t: SortDirection): t is { $meta: string } {
|
|
54
|
+
return typeof t === 'object' && t != null && '$meta' in t && typeof t.$meta === 'string';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @internal */
|
|
58
|
+
function isPair(t: Sort): t is readonly [string, SortDirection] {
|
|
59
|
+
if (Array.isArray(t) && t.length === 2) {
|
|
60
|
+
try {
|
|
61
|
+
prepareDirection(t[1]);
|
|
62
|
+
return true;
|
|
63
|
+
} catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isDeep(t: Sort): t is ReadonlyArray<readonly [string, SortDirection]> {
|
|
71
|
+
return Array.isArray(t) && Array.isArray(t[0]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function isMap(t: Sort): t is ReadonlyMap<string, SortDirection> {
|
|
75
|
+
return t instanceof Map && t.size > 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isReadonlyArray<T>(value: any): value is readonly T[] {
|
|
79
|
+
return Array.isArray(value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** @internal */
|
|
83
|
+
function pairToMap(v: readonly [string, SortDirection]): SortForCmd {
|
|
84
|
+
return new Map([[`${v[0]}`, prepareDirection([v[1]])]]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** @internal */
|
|
88
|
+
function deepToMap(t: ReadonlyArray<readonly [string, SortDirection]>): SortForCmd {
|
|
89
|
+
const sortEntries: SortPairForCmd[] = t.map(([k, v]) => [`${k}`, prepareDirection(v)]);
|
|
90
|
+
return new Map(sortEntries);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @internal */
|
|
94
|
+
function stringsToMap(t: ReadonlyArray<string>): SortForCmd {
|
|
95
|
+
const sortEntries: SortPairForCmd[] = t.map(key => [`${key}`, 1]);
|
|
96
|
+
return new Map(sortEntries);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** @internal */
|
|
100
|
+
function objectToMap(t: { readonly [key: string]: SortDirection }): SortForCmd {
|
|
101
|
+
const sortEntries: SortPairForCmd[] = Object.entries(t).map(([k, v]) => [
|
|
102
|
+
`${k}`,
|
|
103
|
+
prepareDirection(v)
|
|
104
|
+
]);
|
|
105
|
+
return new Map(sortEntries);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** @internal */
|
|
109
|
+
function mapToMap(t: ReadonlyMap<string, SortDirection>): SortForCmd {
|
|
110
|
+
const sortEntries: SortPairForCmd[] = Array.from(t).map(([k, v]) => [
|
|
111
|
+
`${k}`,
|
|
112
|
+
prepareDirection(v)
|
|
113
|
+
]);
|
|
114
|
+
return new Map(sortEntries);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** converts a Sort type into a type that is valid for the server (SortForCmd) */
|
|
118
|
+
export function formatSort(
|
|
119
|
+
sort: Sort | undefined,
|
|
120
|
+
direction?: SortDirection
|
|
121
|
+
): SortForCmd | undefined {
|
|
122
|
+
if (sort == null) return undefined;
|
|
123
|
+
|
|
124
|
+
if (typeof sort === 'string') return new Map([[sort, prepareDirection(direction)]]); // 'fieldName'
|
|
125
|
+
|
|
126
|
+
if (typeof sort !== 'object') {
|
|
127
|
+
throw new MongoInvalidArgumentError(
|
|
128
|
+
`Invalid sort format: ${JSON.stringify(sort)} Sort must be a valid object`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!isReadonlyArray(sort)) {
|
|
133
|
+
if (isMap(sort)) return mapToMap(sort); // Map<fieldName, SortDirection>
|
|
134
|
+
if (Object.keys(sort).length) return objectToMap(sort); // { [fieldName: string]: SortDirection }
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
if (!sort.length) return undefined;
|
|
138
|
+
if (isDeep(sort)) return deepToMap(sort); // [ [fieldName, sortDir], [fieldName, sortDir] ... ]
|
|
139
|
+
if (isPair(sort)) return pairToMap(sort); // [ fieldName, sortDir ]
|
|
140
|
+
return stringsToMap(sort); // [ fieldName, fieldName ]
|
|
141
|
+
}
|
package/src/timeout.ts
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { clearTimeout, setTimeout } from 'timers';
|
|
2
|
+
|
|
3
|
+
import { type Document } from './bson';
|
|
4
|
+
import { MongoInvalidArgumentError, MongoOperationTimeoutError, MongoRuntimeError } from './error';
|
|
5
|
+
import { type ClientSession } from './sessions';
|
|
6
|
+
import { csotMin, noop, squashError } from './utils';
|
|
7
|
+
|
|
8
|
+
/** @internal */
|
|
9
|
+
export class TimeoutError extends Error {
|
|
10
|
+
duration: number;
|
|
11
|
+
override get name(): 'TimeoutError' {
|
|
12
|
+
return 'TimeoutError';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
constructor(message: string, options: { cause?: Error; duration: number }) {
|
|
16
|
+
super(message, options);
|
|
17
|
+
this.duration = options.duration;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static is(error: unknown): error is TimeoutError {
|
|
21
|
+
return (
|
|
22
|
+
error != null && typeof error === 'object' && 'name' in error && error.name === 'TimeoutError'
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type Executor = ConstructorParameters<typeof Promise<never>>[0];
|
|
28
|
+
type Reject = Parameters<ConstructorParameters<typeof Promise<never>>[0]>[1];
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
* This class is an abstraction over timeouts
|
|
32
|
+
* The Timeout class can only be in the pending or rejected states. It is guaranteed not to resolve
|
|
33
|
+
* if interacted with exclusively through its public API
|
|
34
|
+
* */
|
|
35
|
+
export class Timeout extends Promise<never> {
|
|
36
|
+
private id?: NodeJS.Timeout;
|
|
37
|
+
|
|
38
|
+
public readonly start: number;
|
|
39
|
+
public ended: number | null = null;
|
|
40
|
+
public duration: number;
|
|
41
|
+
private timedOut = false;
|
|
42
|
+
public cleared = false;
|
|
43
|
+
|
|
44
|
+
get remainingTime(): number {
|
|
45
|
+
if (this.timedOut) return 0;
|
|
46
|
+
if (this.duration === 0) return Infinity;
|
|
47
|
+
return this.start + this.duration - Math.trunc(performance.now());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get timeElapsed(): number {
|
|
51
|
+
return Math.trunc(performance.now()) - this.start;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Create a new timeout that expires in `duration` ms */
|
|
55
|
+
private constructor(
|
|
56
|
+
executor: Executor = () => null,
|
|
57
|
+
options?: { duration: number; unref?: true; rejection?: Error }
|
|
58
|
+
) {
|
|
59
|
+
const duration = options?.duration ?? 0;
|
|
60
|
+
const unref = !!options?.unref;
|
|
61
|
+
const rejection = options?.rejection;
|
|
62
|
+
|
|
63
|
+
if (duration < 0) {
|
|
64
|
+
throw new MongoInvalidArgumentError('Cannot create a Timeout with a negative duration');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let reject!: Reject;
|
|
68
|
+
super((_, promiseReject) => {
|
|
69
|
+
reject = promiseReject;
|
|
70
|
+
|
|
71
|
+
executor(noop, promiseReject);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
this.duration = duration;
|
|
75
|
+
this.start = Math.trunc(performance.now());
|
|
76
|
+
|
|
77
|
+
if (rejection == null && this.duration > 0) {
|
|
78
|
+
this.id = setTimeout(() => {
|
|
79
|
+
this.ended = Math.trunc(performance.now());
|
|
80
|
+
this.timedOut = true;
|
|
81
|
+
reject(new TimeoutError(`Expired after ${duration}ms`, { duration }));
|
|
82
|
+
}, this.duration);
|
|
83
|
+
if (typeof this.id.unref === 'function' && unref) {
|
|
84
|
+
// Ensure we do not keep the Node.js event loop running
|
|
85
|
+
this.id.unref();
|
|
86
|
+
}
|
|
87
|
+
} else if (rejection != null) {
|
|
88
|
+
this.ended = Math.trunc(performance.now());
|
|
89
|
+
this.timedOut = true;
|
|
90
|
+
reject(rejection);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Clears the underlying timeout. This method is idempotent
|
|
96
|
+
*/
|
|
97
|
+
clear(): void {
|
|
98
|
+
clearTimeout(this.id);
|
|
99
|
+
this.id = undefined;
|
|
100
|
+
this.timedOut = false;
|
|
101
|
+
this.cleared = true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throwIfExpired(): void {
|
|
105
|
+
if (this.timedOut) {
|
|
106
|
+
// This method is invoked when someone wants to throw immediately instead of await the result of this promise
|
|
107
|
+
// Since they won't be handling the rejection from the promise (because we're about to throw here)
|
|
108
|
+
// attach handling to prevent this from bubbling up to Node.js
|
|
109
|
+
this.then(undefined, squashError);
|
|
110
|
+
throw new TimeoutError('Timed out', { duration: this.duration });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public static expires(duration: number, unref?: true): Timeout {
|
|
115
|
+
return new Timeout(undefined, { duration, unref });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static override reject(rejection?: Error): Timeout {
|
|
119
|
+
return new Timeout(undefined, { duration: 0, unref: true, rejection });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** @internal */
|
|
124
|
+
export type TimeoutContextOptions = (LegacyTimeoutContextOptions | CSOTTimeoutContextOptions) & {
|
|
125
|
+
session?: ClientSession;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** @internal */
|
|
129
|
+
export type LegacyTimeoutContextOptions = {
|
|
130
|
+
serverSelectionTimeoutMS: number;
|
|
131
|
+
waitQueueTimeoutMS: number;
|
|
132
|
+
socketTimeoutMS?: number;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** @internal */
|
|
136
|
+
export type CSOTTimeoutContextOptions = {
|
|
137
|
+
timeoutMS: number;
|
|
138
|
+
serverSelectionTimeoutMS: number;
|
|
139
|
+
socketTimeoutMS?: number;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
function isLegacyTimeoutContextOptions(v: unknown): v is LegacyTimeoutContextOptions {
|
|
143
|
+
return (
|
|
144
|
+
v != null &&
|
|
145
|
+
typeof v === 'object' &&
|
|
146
|
+
'serverSelectionTimeoutMS' in v &&
|
|
147
|
+
typeof v.serverSelectionTimeoutMS === 'number' &&
|
|
148
|
+
'waitQueueTimeoutMS' in v &&
|
|
149
|
+
typeof v.waitQueueTimeoutMS === 'number'
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function isCSOTTimeoutContextOptions(v: unknown): v is CSOTTimeoutContextOptions {
|
|
154
|
+
return (
|
|
155
|
+
v != null &&
|
|
156
|
+
typeof v === 'object' &&
|
|
157
|
+
'serverSelectionTimeoutMS' in v &&
|
|
158
|
+
typeof v.serverSelectionTimeoutMS === 'number' &&
|
|
159
|
+
'timeoutMS' in v &&
|
|
160
|
+
typeof v.timeoutMS === 'number'
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** @internal */
|
|
165
|
+
export abstract class TimeoutContext {
|
|
166
|
+
static create(options: TimeoutContextOptions): TimeoutContext {
|
|
167
|
+
if (options.session?.timeoutContext != null) return options.session?.timeoutContext;
|
|
168
|
+
if (isCSOTTimeoutContextOptions(options)) return new CSOTTimeoutContext(options);
|
|
169
|
+
else if (isLegacyTimeoutContextOptions(options)) return new LegacyTimeoutContext(options);
|
|
170
|
+
else throw new MongoRuntimeError('Unrecognized options');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
abstract get maxTimeMS(): number | null;
|
|
174
|
+
|
|
175
|
+
abstract get serverSelectionTimeout(): Timeout | null;
|
|
176
|
+
|
|
177
|
+
abstract get connectionCheckoutTimeout(): Timeout | null;
|
|
178
|
+
|
|
179
|
+
abstract get clearServerSelectionTimeout(): boolean;
|
|
180
|
+
|
|
181
|
+
abstract get timeoutForSocketWrite(): Timeout | null;
|
|
182
|
+
|
|
183
|
+
abstract get timeoutForSocketRead(): Timeout | null;
|
|
184
|
+
|
|
185
|
+
abstract csotEnabled(): this is CSOTTimeoutContext;
|
|
186
|
+
|
|
187
|
+
abstract refresh(): void;
|
|
188
|
+
|
|
189
|
+
abstract clear(): void;
|
|
190
|
+
|
|
191
|
+
/** Returns a new instance of the TimeoutContext, with all timeouts refreshed and restarted. */
|
|
192
|
+
abstract refreshed(): TimeoutContext;
|
|
193
|
+
|
|
194
|
+
abstract addMaxTimeMSToCommand(command: Document, options: { omitMaxTimeMS?: boolean }): void;
|
|
195
|
+
|
|
196
|
+
abstract getSocketTimeoutMS(): number | undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** @internal */
|
|
200
|
+
export class CSOTTimeoutContext extends TimeoutContext {
|
|
201
|
+
timeoutMS: number;
|
|
202
|
+
serverSelectionTimeoutMS: number;
|
|
203
|
+
socketTimeoutMS?: number;
|
|
204
|
+
|
|
205
|
+
clearServerSelectionTimeout: boolean;
|
|
206
|
+
|
|
207
|
+
private _serverSelectionTimeout?: Timeout | null;
|
|
208
|
+
private _connectionCheckoutTimeout?: Timeout | null;
|
|
209
|
+
public minRoundTripTime = 0;
|
|
210
|
+
public start: number;
|
|
211
|
+
|
|
212
|
+
constructor(options: CSOTTimeoutContextOptions) {
|
|
213
|
+
super();
|
|
214
|
+
this.start = Math.trunc(performance.now());
|
|
215
|
+
|
|
216
|
+
this.timeoutMS = options.timeoutMS;
|
|
217
|
+
|
|
218
|
+
this.serverSelectionTimeoutMS = options.serverSelectionTimeoutMS;
|
|
219
|
+
|
|
220
|
+
this.socketTimeoutMS = options.socketTimeoutMS;
|
|
221
|
+
|
|
222
|
+
this.clearServerSelectionTimeout = false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
get maxTimeMS(): number {
|
|
226
|
+
return this.remainingTimeMS - this.minRoundTripTime;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
get remainingTimeMS() {
|
|
230
|
+
const timePassed = Math.trunc(performance.now()) - this.start;
|
|
231
|
+
return this.timeoutMS <= 0 ? Infinity : this.timeoutMS - timePassed;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
csotEnabled(): this is CSOTTimeoutContext {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
get serverSelectionTimeout(): Timeout | null {
|
|
239
|
+
// check for undefined
|
|
240
|
+
if (typeof this._serverSelectionTimeout !== 'object' || this._serverSelectionTimeout?.cleared) {
|
|
241
|
+
const { remainingTimeMS, serverSelectionTimeoutMS } = this;
|
|
242
|
+
if (remainingTimeMS <= 0)
|
|
243
|
+
return Timeout.reject(
|
|
244
|
+
new MongoOperationTimeoutError(`Timed out in server selection after ${this.timeoutMS}ms`)
|
|
245
|
+
);
|
|
246
|
+
const usingServerSelectionTimeoutMS =
|
|
247
|
+
serverSelectionTimeoutMS !== 0 &&
|
|
248
|
+
csotMin(remainingTimeMS, serverSelectionTimeoutMS) === serverSelectionTimeoutMS;
|
|
249
|
+
if (usingServerSelectionTimeoutMS) {
|
|
250
|
+
this._serverSelectionTimeout = Timeout.expires(serverSelectionTimeoutMS);
|
|
251
|
+
} else {
|
|
252
|
+
if (remainingTimeMS > 0 && Number.isFinite(remainingTimeMS)) {
|
|
253
|
+
this._serverSelectionTimeout = Timeout.expires(remainingTimeMS);
|
|
254
|
+
} else {
|
|
255
|
+
this._serverSelectionTimeout = null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return this._serverSelectionTimeout;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
get connectionCheckoutTimeout(): Timeout | null {
|
|
264
|
+
if (
|
|
265
|
+
typeof this._connectionCheckoutTimeout !== 'object' ||
|
|
266
|
+
this._connectionCheckoutTimeout?.cleared
|
|
267
|
+
) {
|
|
268
|
+
if (typeof this._serverSelectionTimeout === 'object') {
|
|
269
|
+
// null or Timeout
|
|
270
|
+
this._connectionCheckoutTimeout = this._serverSelectionTimeout;
|
|
271
|
+
} else {
|
|
272
|
+
throw new MongoRuntimeError(
|
|
273
|
+
'Unreachable. If you are seeing this error, please file a ticket on the NODE driver project on Jira'
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return this._connectionCheckoutTimeout;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
get timeoutForSocketWrite(): Timeout | null {
|
|
281
|
+
const { remainingTimeMS } = this;
|
|
282
|
+
if (!Number.isFinite(remainingTimeMS)) return null;
|
|
283
|
+
if (remainingTimeMS > 0) return Timeout.expires(remainingTimeMS);
|
|
284
|
+
return Timeout.reject(new MongoOperationTimeoutError('Timed out before socket write'));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
get timeoutForSocketRead(): Timeout | null {
|
|
288
|
+
const { remainingTimeMS } = this;
|
|
289
|
+
if (!Number.isFinite(remainingTimeMS)) return null;
|
|
290
|
+
if (remainingTimeMS > 0) return Timeout.expires(remainingTimeMS);
|
|
291
|
+
return Timeout.reject(new MongoOperationTimeoutError('Timed out before socket read'));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
refresh(): void {
|
|
295
|
+
this.start = Math.trunc(performance.now());
|
|
296
|
+
this.minRoundTripTime = 0;
|
|
297
|
+
this._serverSelectionTimeout?.clear();
|
|
298
|
+
this._connectionCheckoutTimeout?.clear();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
clear(): void {
|
|
302
|
+
this._serverSelectionTimeout?.clear();
|
|
303
|
+
this._connectionCheckoutTimeout?.clear();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* @internal
|
|
308
|
+
* Throws a MongoOperationTimeoutError if the context has expired.
|
|
309
|
+
* If the context has not expired, returns the `remainingTimeMS`
|
|
310
|
+
**/
|
|
311
|
+
getRemainingTimeMSOrThrow(message?: string): number {
|
|
312
|
+
const { remainingTimeMS } = this;
|
|
313
|
+
if (remainingTimeMS <= 0)
|
|
314
|
+
throw new MongoOperationTimeoutError(message ?? `Expired after ${this.timeoutMS}ms`);
|
|
315
|
+
return remainingTimeMS;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* @internal
|
|
320
|
+
* This method is intended to be used in situations where concurrent operation are on the same deadline, but cannot share a single `TimeoutContext` instance.
|
|
321
|
+
* Returns a new instance of `CSOTTimeoutContext` constructed with identical options, but setting the `start` property to `this.start`.
|
|
322
|
+
*/
|
|
323
|
+
clone(): CSOTTimeoutContext {
|
|
324
|
+
const timeoutContext = new CSOTTimeoutContext({
|
|
325
|
+
timeoutMS: this.timeoutMS,
|
|
326
|
+
serverSelectionTimeoutMS: this.serverSelectionTimeoutMS
|
|
327
|
+
});
|
|
328
|
+
timeoutContext.start = this.start;
|
|
329
|
+
return timeoutContext;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
override refreshed(): CSOTTimeoutContext {
|
|
333
|
+
return new CSOTTimeoutContext(this);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
override addMaxTimeMSToCommand(command: Document, options: { omitMaxTimeMS?: boolean }): void {
|
|
337
|
+
if (options.omitMaxTimeMS) return;
|
|
338
|
+
const maxTimeMS = this.remainingTimeMS - this.minRoundTripTime;
|
|
339
|
+
if (maxTimeMS > 0 && Number.isFinite(maxTimeMS)) command.maxTimeMS = maxTimeMS;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
override getSocketTimeoutMS(): number | undefined {
|
|
343
|
+
return 0;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** @internal */
|
|
348
|
+
export class LegacyTimeoutContext extends TimeoutContext {
|
|
349
|
+
options: LegacyTimeoutContextOptions;
|
|
350
|
+
clearServerSelectionTimeout: boolean;
|
|
351
|
+
|
|
352
|
+
constructor(options: LegacyTimeoutContextOptions) {
|
|
353
|
+
super();
|
|
354
|
+
this.options = options;
|
|
355
|
+
this.clearServerSelectionTimeout = true;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
csotEnabled(): this is CSOTTimeoutContext {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
get serverSelectionTimeout(): Timeout | null {
|
|
363
|
+
if (this.options.serverSelectionTimeoutMS != null && this.options.serverSelectionTimeoutMS > 0)
|
|
364
|
+
return Timeout.expires(this.options.serverSelectionTimeoutMS);
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
get connectionCheckoutTimeout(): Timeout | null {
|
|
369
|
+
if (this.options.waitQueueTimeoutMS != null && this.options.waitQueueTimeoutMS > 0)
|
|
370
|
+
return Timeout.expires(this.options.waitQueueTimeoutMS);
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
get timeoutForSocketWrite(): Timeout | null {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
get timeoutForSocketRead(): Timeout | null {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
refresh(): void {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
clear(): void {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
get maxTimeMS() {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
override refreshed(): LegacyTimeoutContext {
|
|
395
|
+
return new LegacyTimeoutContext(this.options);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
override addMaxTimeMSToCommand(_command: Document, _options: { omitMaxTimeMS?: boolean }): void {
|
|
399
|
+
// No max timeMS is added to commands in legacy timeout mode.
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
override getSocketTimeoutMS(): number | undefined {
|
|
403
|
+
return this.options.socketTimeoutMS;
|
|
404
|
+
}
|
|
405
|
+
}
|