@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,74 @@
|
|
|
1
|
+
import { type Document } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
4
|
+
import type { Db } from '../db';
|
|
5
|
+
import { MongoInvalidArgumentError } from '../error';
|
|
6
|
+
import { enumToString } from '../utils';
|
|
7
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
8
|
+
|
|
9
|
+
const levelValues = new Set(['off', 'slow_only', 'all']);
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
export const ProfilingLevel = Object.freeze({
|
|
13
|
+
off: 'off',
|
|
14
|
+
slowOnly: 'slow_only',
|
|
15
|
+
all: 'all'
|
|
16
|
+
} as const);
|
|
17
|
+
|
|
18
|
+
/** @public */
|
|
19
|
+
export type ProfilingLevel = (typeof ProfilingLevel)[keyof typeof ProfilingLevel];
|
|
20
|
+
|
|
21
|
+
/** @public */
|
|
22
|
+
export type SetProfilingLevelOptions = Omit<CommandOperationOptions, 'rawData'>;
|
|
23
|
+
|
|
24
|
+
/** @internal */
|
|
25
|
+
export class SetProfilingLevelOperation extends CommandOperation<ProfilingLevel> {
|
|
26
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
27
|
+
override options: SetProfilingLevelOptions;
|
|
28
|
+
level: ProfilingLevel;
|
|
29
|
+
profile: 0 | 1 | 2;
|
|
30
|
+
|
|
31
|
+
constructor(db: Db, level: ProfilingLevel, options: SetProfilingLevelOptions) {
|
|
32
|
+
super(db, options);
|
|
33
|
+
this.options = options;
|
|
34
|
+
switch (level) {
|
|
35
|
+
case ProfilingLevel.off:
|
|
36
|
+
this.profile = 0;
|
|
37
|
+
break;
|
|
38
|
+
case ProfilingLevel.slowOnly:
|
|
39
|
+
this.profile = 1;
|
|
40
|
+
break;
|
|
41
|
+
case ProfilingLevel.all:
|
|
42
|
+
this.profile = 2;
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
this.profile = 0;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.level = level;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
override get commandName() {
|
|
53
|
+
return 'profile' as const;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override buildCommandDocument(_connection: Connection): Document {
|
|
57
|
+
const level = this.level;
|
|
58
|
+
|
|
59
|
+
if (!levelValues.has(level)) {
|
|
60
|
+
// TODO(NODE-3483): Determine error to put here
|
|
61
|
+
throw new MongoInvalidArgumentError(
|
|
62
|
+
`Profiling level must be one of "${enumToString(ProfilingLevel)}"`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return { profile: this.profile };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
override handleOk(
|
|
70
|
+
_response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
71
|
+
): ProfilingLevel {
|
|
72
|
+
return this.level;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
4
|
+
import type { Db } from '../db';
|
|
5
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
6
|
+
import { Aspect, defineAspects } from './operation';
|
|
7
|
+
|
|
8
|
+
/** @public */
|
|
9
|
+
export interface DbStatsOptions extends Omit<CommandOperationOptions, 'rawData'> {
|
|
10
|
+
/** Divide the returned sizes by scale value. */
|
|
11
|
+
scale?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
export class DbStatsOperation extends CommandOperation<Document> {
|
|
16
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
17
|
+
override options: DbStatsOptions;
|
|
18
|
+
|
|
19
|
+
constructor(db: Db, options: DbStatsOptions) {
|
|
20
|
+
super(db, options);
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override get commandName() {
|
|
25
|
+
return 'dbStats' as const;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override buildCommandDocument(_connection: Connection): Document {
|
|
29
|
+
const command: Document = { dbStats: true };
|
|
30
|
+
if (this.options.scale != null) {
|
|
31
|
+
command.scale = this.options.scale;
|
|
32
|
+
}
|
|
33
|
+
return command;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
defineAspects(DbStatsOperation, [Aspect.READ_OPERATION]);
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
4
|
+
import { MongoInvalidArgumentError, MongoServerError } from '../error';
|
|
5
|
+
import type { InferIdType } from '../mongo_types';
|
|
6
|
+
import type { ClientSession } from '../sessions';
|
|
7
|
+
import { formatSort, type Sort, type SortForCmd } from '../sort';
|
|
8
|
+
import {
|
|
9
|
+
hasAtomicOperators,
|
|
10
|
+
type MongoDBCollectionNamespace,
|
|
11
|
+
type MongoDBNamespace
|
|
12
|
+
} from '../utils';
|
|
13
|
+
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
|
|
14
|
+
import { Aspect, defineAspects, type Hint } from './operation';
|
|
15
|
+
|
|
16
|
+
/** @public */
|
|
17
|
+
export interface UpdateOptions extends CommandOperationOptions {
|
|
18
|
+
/** A set of filters specifying to which array elements an update should apply */
|
|
19
|
+
arrayFilters?: Document[];
|
|
20
|
+
/** If true, allows the write to opt-out of document level validation */
|
|
21
|
+
bypassDocumentValidation?: boolean;
|
|
22
|
+
/** Specifies a collation */
|
|
23
|
+
collation?: CollationOptions;
|
|
24
|
+
/** Specify that the update query should only consider plans using the hinted index */
|
|
25
|
+
hint?: Hint;
|
|
26
|
+
/** When true, creates a new document if no document matches the query */
|
|
27
|
+
upsert?: boolean;
|
|
28
|
+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
29
|
+
let?: Document;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
* `TSchema` is the schema of the collection
|
|
35
|
+
*/
|
|
36
|
+
export interface UpdateResult<TSchema extends Document = Document> {
|
|
37
|
+
/** Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined */
|
|
38
|
+
acknowledged: boolean;
|
|
39
|
+
/** The number of documents that matched the filter */
|
|
40
|
+
matchedCount: number;
|
|
41
|
+
/** The number of documents that were modified */
|
|
42
|
+
modifiedCount: number;
|
|
43
|
+
/** The number of documents that were upserted */
|
|
44
|
+
upsertedCount: number;
|
|
45
|
+
/** The identifier of the inserted document if an upsert took place */
|
|
46
|
+
upsertedId: InferIdType<TSchema> | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @public */
|
|
50
|
+
export interface UpdateStatement {
|
|
51
|
+
/** The query that matches documents to update. */
|
|
52
|
+
q: Document;
|
|
53
|
+
/** The modifications to apply. */
|
|
54
|
+
u: Document | Document[];
|
|
55
|
+
/** If true, perform an insert if no documents match the query. */
|
|
56
|
+
upsert?: boolean;
|
|
57
|
+
/** If true, updates all documents that meet the query criteria. */
|
|
58
|
+
multi?: boolean;
|
|
59
|
+
/** Specifies the collation to use for the operation. */
|
|
60
|
+
collation?: CollationOptions;
|
|
61
|
+
/** An array of filter documents that determines which array elements to modify for an update operation on an array field. */
|
|
62
|
+
arrayFilters?: Document[];
|
|
63
|
+
/** A document or string that specifies the index to use to support the query predicate. */
|
|
64
|
+
hint?: Hint;
|
|
65
|
+
/** Specifies the sort order for the documents matched by the filter. */
|
|
66
|
+
sort?: SortForCmd;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
* UpdateOperation is used in bulk write, while UpdateOneOperation and UpdateManyOperation are only used in the collections API
|
|
72
|
+
*/
|
|
73
|
+
export class UpdateOperation extends CommandOperation<Document> {
|
|
74
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
75
|
+
override options: UpdateOptions & { ordered?: boolean };
|
|
76
|
+
statements: UpdateStatement[];
|
|
77
|
+
|
|
78
|
+
constructor(
|
|
79
|
+
ns: MongoDBNamespace,
|
|
80
|
+
statements: UpdateStatement[],
|
|
81
|
+
options: UpdateOptions & { ordered?: boolean }
|
|
82
|
+
) {
|
|
83
|
+
super(undefined, options);
|
|
84
|
+
this.options = options;
|
|
85
|
+
this.ns = ns;
|
|
86
|
+
|
|
87
|
+
this.statements = statements;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
override get commandName() {
|
|
91
|
+
return 'update' as const;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
override get canRetryWrite(): boolean {
|
|
95
|
+
if (super.canRetryWrite === false) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return this.statements.every(op => op.multi == null || op.multi === false);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
|
|
103
|
+
const options = this.options;
|
|
104
|
+
const command: Document = {
|
|
105
|
+
update: this.ns.collection,
|
|
106
|
+
updates: this.statements,
|
|
107
|
+
ordered: options.ordered ?? true
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
if (typeof options.bypassDocumentValidation === 'boolean') {
|
|
111
|
+
command.bypassDocumentValidation = options.bypassDocumentValidation;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (options.let) {
|
|
115
|
+
command.let = options.let;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// we check for undefined specifically here to allow falsy values
|
|
119
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
120
|
+
if (options.comment !== undefined) {
|
|
121
|
+
command.comment = options.comment;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return command;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @internal */
|
|
129
|
+
export class UpdateOneOperation extends UpdateOperation {
|
|
130
|
+
constructor(
|
|
131
|
+
ns: MongoDBCollectionNamespace,
|
|
132
|
+
filter: Document,
|
|
133
|
+
update: Document,
|
|
134
|
+
options: UpdateOptions
|
|
135
|
+
) {
|
|
136
|
+
super(ns, [makeUpdateStatement(filter, update, { ...options, multi: false })], options);
|
|
137
|
+
|
|
138
|
+
if (!hasAtomicOperators(update, options)) {
|
|
139
|
+
throw new MongoInvalidArgumentError('Update document requires atomic operators');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
override handleOk(
|
|
144
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
145
|
+
): UpdateResult {
|
|
146
|
+
const res = super.handleOk(response);
|
|
147
|
+
|
|
148
|
+
// @ts-expect-error Explain typing is broken
|
|
149
|
+
if (this.explain != null) return res;
|
|
150
|
+
|
|
151
|
+
if (res.code) throw new MongoServerError(res);
|
|
152
|
+
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
acknowledged: this.writeConcern?.w !== 0,
|
|
156
|
+
modifiedCount: res.nModified ?? res.n,
|
|
157
|
+
upsertedId:
|
|
158
|
+
Array.isArray(res.upserted) && res.upserted.length > 0 ? res.upserted[0]._id : null,
|
|
159
|
+
upsertedCount: Array.isArray(res.upserted) && res.upserted.length ? res.upserted.length : 0,
|
|
160
|
+
matchedCount: Array.isArray(res.upserted) && res.upserted.length > 0 ? 0 : res.n
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** @internal */
|
|
166
|
+
export class UpdateManyOperation extends UpdateOperation {
|
|
167
|
+
constructor(
|
|
168
|
+
ns: MongoDBCollectionNamespace,
|
|
169
|
+
filter: Document,
|
|
170
|
+
update: Document,
|
|
171
|
+
options: UpdateOptions
|
|
172
|
+
) {
|
|
173
|
+
super(ns, [makeUpdateStatement(filter, update, { ...options, multi: true })], options);
|
|
174
|
+
|
|
175
|
+
if (!hasAtomicOperators(update, options)) {
|
|
176
|
+
throw new MongoInvalidArgumentError('Update document requires atomic operators');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
override handleOk(
|
|
181
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
182
|
+
): UpdateResult {
|
|
183
|
+
const res = super.handleOk(response);
|
|
184
|
+
|
|
185
|
+
// @ts-expect-error Explain typing is broken
|
|
186
|
+
if (this.explain != null) return res;
|
|
187
|
+
if (res.code) throw new MongoServerError(res);
|
|
188
|
+
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
acknowledged: this.writeConcern?.w !== 0,
|
|
192
|
+
modifiedCount: res.nModified ?? res.n,
|
|
193
|
+
upsertedId:
|
|
194
|
+
Array.isArray(res.upserted) && res.upserted.length > 0 ? res.upserted[0]._id : null,
|
|
195
|
+
upsertedCount: Array.isArray(res.upserted) && res.upserted.length ? res.upserted.length : 0,
|
|
196
|
+
matchedCount: Array.isArray(res.upserted) && res.upserted.length > 0 ? 0 : res.n
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** @public */
|
|
202
|
+
export interface ReplaceOptions extends CommandOperationOptions {
|
|
203
|
+
/** If true, allows the write to opt-out of document level validation */
|
|
204
|
+
bypassDocumentValidation?: boolean;
|
|
205
|
+
/** Specifies a collation */
|
|
206
|
+
collation?: CollationOptions;
|
|
207
|
+
/** Specify that the update query should only consider plans using the hinted index */
|
|
208
|
+
hint?: string | Document;
|
|
209
|
+
/** When true, creates a new document if no document matches the query */
|
|
210
|
+
upsert?: boolean;
|
|
211
|
+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
212
|
+
let?: Document;
|
|
213
|
+
/** Specifies the sort order for the documents matched by the filter. */
|
|
214
|
+
sort?: Sort;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** @internal */
|
|
218
|
+
export class ReplaceOneOperation extends UpdateOperation {
|
|
219
|
+
constructor(
|
|
220
|
+
ns: MongoDBCollectionNamespace,
|
|
221
|
+
filter: Document,
|
|
222
|
+
replacement: Document,
|
|
223
|
+
options: ReplaceOptions
|
|
224
|
+
) {
|
|
225
|
+
super(ns, [makeUpdateStatement(filter, replacement, { ...options, multi: false })], options);
|
|
226
|
+
|
|
227
|
+
if (hasAtomicOperators(replacement)) {
|
|
228
|
+
throw new MongoInvalidArgumentError('Replacement document must not contain atomic operators');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
override handleOk(
|
|
233
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
234
|
+
): UpdateResult {
|
|
235
|
+
const res = super.handleOk(response);
|
|
236
|
+
|
|
237
|
+
// @ts-expect-error Explain typing is broken
|
|
238
|
+
if (this.explain != null) return res;
|
|
239
|
+
if (res.code) throw new MongoServerError(res);
|
|
240
|
+
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
acknowledged: this.writeConcern?.w !== 0,
|
|
244
|
+
modifiedCount: res.nModified ?? res.n,
|
|
245
|
+
upsertedId:
|
|
246
|
+
Array.isArray(res.upserted) && res.upserted.length > 0 ? res.upserted[0]._id : null,
|
|
247
|
+
upsertedCount: Array.isArray(res.upserted) && res.upserted.length ? res.upserted.length : 0,
|
|
248
|
+
matchedCount: Array.isArray(res.upserted) && res.upserted.length > 0 ? 0 : res.n
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function makeUpdateStatement(
|
|
254
|
+
filter: Document,
|
|
255
|
+
update: Document | Document[],
|
|
256
|
+
options: UpdateOptions & { multi?: boolean } & { sort?: Sort }
|
|
257
|
+
): UpdateStatement {
|
|
258
|
+
if (filter == null || typeof filter !== 'object') {
|
|
259
|
+
throw new MongoInvalidArgumentError('Selector must be a valid JavaScript object');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (update == null || typeof update !== 'object') {
|
|
263
|
+
throw new MongoInvalidArgumentError('Document must be a valid JavaScript object');
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const op: UpdateStatement = { q: filter, u: update };
|
|
267
|
+
if (typeof options.upsert === 'boolean') {
|
|
268
|
+
op.upsert = options.upsert;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (options.multi) {
|
|
272
|
+
op.multi = options.multi;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (options.hint) {
|
|
276
|
+
op.hint = options.hint;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (options.arrayFilters) {
|
|
280
|
+
op.arrayFilters = options.arrayFilters;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (options.collation) {
|
|
284
|
+
op.collation = options.collation;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (!options.multi && options.sort != null) {
|
|
288
|
+
op.sort = formatSort(options.sort);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return op;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
defineAspects(UpdateOperation, [
|
|
295
|
+
Aspect.RETRYABLE,
|
|
296
|
+
Aspect.WRITE_OPERATION,
|
|
297
|
+
Aspect.SKIP_COLLATION,
|
|
298
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
299
|
+
]);
|
|
300
|
+
defineAspects(UpdateOneOperation, [
|
|
301
|
+
Aspect.RETRYABLE,
|
|
302
|
+
Aspect.WRITE_OPERATION,
|
|
303
|
+
Aspect.EXPLAINABLE,
|
|
304
|
+
Aspect.SKIP_COLLATION,
|
|
305
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
306
|
+
]);
|
|
307
|
+
defineAspects(UpdateManyOperation, [
|
|
308
|
+
Aspect.WRITE_OPERATION,
|
|
309
|
+
Aspect.EXPLAINABLE,
|
|
310
|
+
Aspect.SKIP_COLLATION,
|
|
311
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
312
|
+
]);
|
|
313
|
+
defineAspects(ReplaceOneOperation, [
|
|
314
|
+
Aspect.RETRYABLE,
|
|
315
|
+
Aspect.WRITE_OPERATION,
|
|
316
|
+
Aspect.SKIP_COLLATION,
|
|
317
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
318
|
+
]);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Connection } from '..';
|
|
2
|
+
import type { Admin } from '../admin';
|
|
3
|
+
import { type Document } from '../bson';
|
|
4
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
5
|
+
import { MongoUnexpectedServerResponseError } from '../error';
|
|
6
|
+
import type { ClientSession } from '../sessions';
|
|
7
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
8
|
+
|
|
9
|
+
/** @public */
|
|
10
|
+
export interface ValidateCollectionOptions extends Omit<CommandOperationOptions, 'rawData'> {
|
|
11
|
+
/** Validates a collection in the background, without interrupting read or write traffic (only in MongoDB 4.4+) */
|
|
12
|
+
background?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @internal */
|
|
16
|
+
export class ValidateCollectionOperation extends CommandOperation<Document> {
|
|
17
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
18
|
+
override options: ValidateCollectionOptions;
|
|
19
|
+
collectionName: string;
|
|
20
|
+
|
|
21
|
+
constructor(admin: Admin, collectionName: string, options: ValidateCollectionOptions) {
|
|
22
|
+
super(admin.s.db, options);
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.collectionName = collectionName;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override get commandName() {
|
|
28
|
+
return 'validate' as const;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
|
|
32
|
+
// Decorate command with extra options
|
|
33
|
+
return {
|
|
34
|
+
validate: this.collectionName,
|
|
35
|
+
...Object.fromEntries(Object.entries(this.options).filter(entry => entry[0] !== 'session'))
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
|
|
40
|
+
const result = super.handleOk(response);
|
|
41
|
+
if (result.result != null && typeof result.result !== 'string')
|
|
42
|
+
throw new MongoUnexpectedServerResponseError('Error with validation data');
|
|
43
|
+
if (result.result != null && result.result.match(/exception|corrupt/) != null)
|
|
44
|
+
throw new MongoUnexpectedServerResponseError(`Invalid collection ${this.collectionName}`);
|
|
45
|
+
if (result.valid != null && !result.valid)
|
|
46
|
+
throw new MongoUnexpectedServerResponseError(`Invalid collection ${this.collectionName}`);
|
|
47
|
+
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Document } from './bson';
|
|
2
|
+
|
|
3
|
+
/** @public */
|
|
4
|
+
export const ReadConcernLevel = Object.freeze({
|
|
5
|
+
local: 'local',
|
|
6
|
+
majority: 'majority',
|
|
7
|
+
linearizable: 'linearizable',
|
|
8
|
+
available: 'available',
|
|
9
|
+
snapshot: 'snapshot'
|
|
10
|
+
} as const);
|
|
11
|
+
|
|
12
|
+
/** @public */
|
|
13
|
+
export type ReadConcernLevel = (typeof ReadConcernLevel)[keyof typeof ReadConcernLevel];
|
|
14
|
+
|
|
15
|
+
/** @public */
|
|
16
|
+
export type ReadConcernLike = ReadConcern | { level: ReadConcernLevel } | ReadConcernLevel;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The MongoDB ReadConcern, which allows for control of the consistency and isolation properties
|
|
20
|
+
* of the data read from replica sets and replica set shards.
|
|
21
|
+
* @public
|
|
22
|
+
*
|
|
23
|
+
* @see https://www.mongodb.com/docs/manual/reference/read-concern/index.html
|
|
24
|
+
*/
|
|
25
|
+
export class ReadConcern {
|
|
26
|
+
level: ReadConcernLevel | string;
|
|
27
|
+
|
|
28
|
+
/** Constructs a ReadConcern from the read concern level.*/
|
|
29
|
+
constructor(level: ReadConcernLevel) {
|
|
30
|
+
/**
|
|
31
|
+
* A spec test exists that allows level to be any string.
|
|
32
|
+
* "invalid readConcern with out stage"
|
|
33
|
+
* @see ./test/spec/crud/v2/aggregate-out-readConcern.json
|
|
34
|
+
* @see https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.md#unknown-levels-and-additional-options-for-string-based-readconcerns
|
|
35
|
+
*/
|
|
36
|
+
this.level = ReadConcernLevel[level] ?? level;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Construct a ReadConcern given an options object.
|
|
41
|
+
*
|
|
42
|
+
* @param options - The options object from which to extract the write concern.
|
|
43
|
+
*/
|
|
44
|
+
static fromOptions(options?: {
|
|
45
|
+
readConcern?: ReadConcernLike;
|
|
46
|
+
level?: ReadConcernLevel;
|
|
47
|
+
}): ReadConcern | undefined {
|
|
48
|
+
if (options == null) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (options.readConcern) {
|
|
53
|
+
const { readConcern } = options;
|
|
54
|
+
if (readConcern instanceof ReadConcern) {
|
|
55
|
+
return readConcern;
|
|
56
|
+
} else if (typeof readConcern === 'string') {
|
|
57
|
+
return new ReadConcern(readConcern);
|
|
58
|
+
} else if ('level' in readConcern && readConcern.level) {
|
|
59
|
+
return new ReadConcern(readConcern.level);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (options.level) {
|
|
64
|
+
return new ReadConcern(options.level);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static get MAJORITY(): 'majority' {
|
|
70
|
+
return ReadConcernLevel.majority;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static get AVAILABLE(): 'available' {
|
|
74
|
+
return ReadConcernLevel.available;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static get LINEARIZABLE(): 'linearizable' {
|
|
78
|
+
return ReadConcernLevel.linearizable;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static get SNAPSHOT(): 'snapshot' {
|
|
82
|
+
return ReadConcernLevel.snapshot;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
toJSON(): Document {
|
|
86
|
+
return { level: this.level };
|
|
87
|
+
}
|
|
88
|
+
}
|