@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,537 @@
|
|
|
1
|
+
import { Writable } from 'stream';
|
|
2
|
+
|
|
3
|
+
import { type Document, ObjectId } from '../bson';
|
|
4
|
+
import type { Collection } from '../collection';
|
|
5
|
+
import { CursorTimeoutMode } from '../cursor/abstract_cursor';
|
|
6
|
+
import {
|
|
7
|
+
MongoAPIError,
|
|
8
|
+
MONGODB_ERROR_CODES,
|
|
9
|
+
MongoError,
|
|
10
|
+
MongoOperationTimeoutError
|
|
11
|
+
} from '../error';
|
|
12
|
+
import { CSOTTimeoutContext } from '../timeout';
|
|
13
|
+
import { type Callback, resolveTimeoutOptions, squashError } from '../utils';
|
|
14
|
+
import type { WriteConcernOptions } from '../write_concern';
|
|
15
|
+
import { WriteConcern } from './../write_concern';
|
|
16
|
+
import type { GridFSFile } from './download';
|
|
17
|
+
import type { GridFSBucket } from './index';
|
|
18
|
+
|
|
19
|
+
/** @public */
|
|
20
|
+
export interface GridFSChunk {
|
|
21
|
+
_id: ObjectId;
|
|
22
|
+
files_id: ObjectId;
|
|
23
|
+
n: number;
|
|
24
|
+
data: Buffer | Uint8Array;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @public */
|
|
28
|
+
export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
|
|
29
|
+
/** Overwrite this bucket's chunkSizeBytes for this file */
|
|
30
|
+
chunkSizeBytes?: number;
|
|
31
|
+
/** Custom file id for the GridFS file. */
|
|
32
|
+
id?: ObjectId;
|
|
33
|
+
/** Object to store in the file document's `metadata` field */
|
|
34
|
+
metadata?: Document;
|
|
35
|
+
/**
|
|
36
|
+
* @experimental
|
|
37
|
+
* Specifies the time an operation will run until it throws a timeout error
|
|
38
|
+
*/
|
|
39
|
+
timeoutMS?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A writable stream that enables you to write buffers to GridFS.
|
|
44
|
+
*
|
|
45
|
+
* Do not instantiate this class directly. Use `openUploadStream()` instead.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export class GridFSBucketWriteStream extends Writable {
|
|
49
|
+
bucket: GridFSBucket;
|
|
50
|
+
/** A Collection instance where the file's chunks are stored */
|
|
51
|
+
chunks: Collection<GridFSChunk>;
|
|
52
|
+
/** A Collection instance where the file's GridFSFile document is stored */
|
|
53
|
+
files: Collection<GridFSFile>;
|
|
54
|
+
/** The name of the file */
|
|
55
|
+
filename: string;
|
|
56
|
+
/** Options controlling the metadata inserted along with the file */
|
|
57
|
+
options: GridFSBucketWriteStreamOptions;
|
|
58
|
+
/** Indicates the stream is finished uploading */
|
|
59
|
+
done: boolean;
|
|
60
|
+
/** The ObjectId used for the `_id` field on the GridFSFile document */
|
|
61
|
+
id: ObjectId;
|
|
62
|
+
/** The number of bytes that each chunk will be limited to */
|
|
63
|
+
chunkSizeBytes: number;
|
|
64
|
+
/** Space used to store a chunk currently being inserted */
|
|
65
|
+
bufToStore: Buffer;
|
|
66
|
+
/** Accumulates the number of bytes inserted as the stream uploads chunks */
|
|
67
|
+
length: number;
|
|
68
|
+
/** Accumulates the number of chunks inserted as the stream uploads file contents */
|
|
69
|
+
n: number;
|
|
70
|
+
/** Tracks the current offset into the buffered bytes being uploaded */
|
|
71
|
+
pos: number;
|
|
72
|
+
/** Contains a number of properties indicating the current state of the stream */
|
|
73
|
+
state: {
|
|
74
|
+
/** If set the stream has ended */
|
|
75
|
+
streamEnd: boolean;
|
|
76
|
+
/** Indicates the number of chunks that still need to be inserted to exhaust the current buffered data */
|
|
77
|
+
outstandingRequests: number;
|
|
78
|
+
/** If set an error occurred during insertion */
|
|
79
|
+
errored: boolean;
|
|
80
|
+
/** If set the stream was intentionally aborted */
|
|
81
|
+
aborted: boolean;
|
|
82
|
+
};
|
|
83
|
+
/** The write concern setting to be used with every insert operation */
|
|
84
|
+
writeConcern?: WriteConcern;
|
|
85
|
+
/**
|
|
86
|
+
* The document containing information about the inserted file.
|
|
87
|
+
* This property is defined _after_ the finish event has been emitted.
|
|
88
|
+
* It will remain `null` if an error occurs.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* fs.createReadStream('file.txt')
|
|
93
|
+
* .pipe(bucket.openUploadStream('file.txt'))
|
|
94
|
+
* .on('finish', function () {
|
|
95
|
+
* console.log(this.gridFSFile)
|
|
96
|
+
* })
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
gridFSFile: GridFSFile | null = null;
|
|
100
|
+
/** @internal */
|
|
101
|
+
timeoutContext?: CSOTTimeoutContext;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param bucket - Handle for this stream's corresponding bucket
|
|
105
|
+
* @param filename - The value of the 'filename' key in the files doc
|
|
106
|
+
* @param options - Optional settings.
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
constructor(bucket: GridFSBucket, filename: string, options?: GridFSBucketWriteStreamOptions) {
|
|
110
|
+
super();
|
|
111
|
+
|
|
112
|
+
options = options ?? {};
|
|
113
|
+
this.bucket = bucket;
|
|
114
|
+
this.chunks = bucket.s._chunksCollection;
|
|
115
|
+
this.filename = filename;
|
|
116
|
+
this.files = bucket.s._filesCollection;
|
|
117
|
+
this.options = options;
|
|
118
|
+
this.writeConcern = WriteConcern.fromOptions(options) || bucket.s.options.writeConcern;
|
|
119
|
+
// Signals the write is all done
|
|
120
|
+
this.done = false;
|
|
121
|
+
|
|
122
|
+
this.id = options.id ? options.id : new ObjectId();
|
|
123
|
+
// properly inherit the default chunksize from parent
|
|
124
|
+
this.chunkSizeBytes = options.chunkSizeBytes || this.bucket.s.options.chunkSizeBytes;
|
|
125
|
+
this.bufToStore = Buffer.alloc(this.chunkSizeBytes);
|
|
126
|
+
this.length = 0;
|
|
127
|
+
this.n = 0;
|
|
128
|
+
this.pos = 0;
|
|
129
|
+
this.state = {
|
|
130
|
+
streamEnd: false,
|
|
131
|
+
outstandingRequests: 0,
|
|
132
|
+
errored: false,
|
|
133
|
+
aborted: false
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
if (options.timeoutMS != null)
|
|
137
|
+
this.timeoutContext = new CSOTTimeoutContext({
|
|
138
|
+
timeoutMS: options.timeoutMS,
|
|
139
|
+
serverSelectionTimeoutMS: resolveTimeoutOptions(this.bucket.s.db.client, {})
|
|
140
|
+
.serverSelectionTimeoutMS
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
*
|
|
147
|
+
* The stream is considered constructed when the indexes are done being created
|
|
148
|
+
*/
|
|
149
|
+
override _construct(callback: (error?: Error | null) => void): void {
|
|
150
|
+
if (!this.bucket.s.calledOpenUploadStream) {
|
|
151
|
+
this.bucket.s.calledOpenUploadStream = true;
|
|
152
|
+
|
|
153
|
+
checkIndexes(this).then(
|
|
154
|
+
() => {
|
|
155
|
+
this.bucket.s.checkedIndexes = true;
|
|
156
|
+
this.bucket.emit('index');
|
|
157
|
+
callback();
|
|
158
|
+
},
|
|
159
|
+
error => {
|
|
160
|
+
if (error instanceof MongoOperationTimeoutError) {
|
|
161
|
+
return handleError(this, error, callback);
|
|
162
|
+
}
|
|
163
|
+
squashError(error);
|
|
164
|
+
callback();
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
return queueMicrotask(callback);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @internal
|
|
174
|
+
* Write a buffer to the stream.
|
|
175
|
+
*
|
|
176
|
+
* @param chunk - Buffer to write
|
|
177
|
+
* @param encoding - Optional encoding for the buffer
|
|
178
|
+
* @param callback - Function to call when the chunk was added to the buffer, or if the entire chunk was persisted to MongoDB if this chunk caused a flush.
|
|
179
|
+
*/
|
|
180
|
+
override _write(
|
|
181
|
+
chunk: Buffer | string,
|
|
182
|
+
encoding: BufferEncoding,
|
|
183
|
+
callback: Callback<void>
|
|
184
|
+
): void {
|
|
185
|
+
doWrite(this, chunk, encoding, callback);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** @internal */
|
|
189
|
+
override _final(callback: (error?: Error | null) => void): void {
|
|
190
|
+
if (this.state.streamEnd) {
|
|
191
|
+
return queueMicrotask(callback);
|
|
192
|
+
}
|
|
193
|
+
this.state.streamEnd = true;
|
|
194
|
+
writeRemnant(this, callback);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Places this write stream into an aborted state (all future writes fail)
|
|
199
|
+
* and deletes all chunks that have already been written.
|
|
200
|
+
*/
|
|
201
|
+
async abort(): Promise<void> {
|
|
202
|
+
if (this.state.streamEnd) {
|
|
203
|
+
// TODO(NODE-3485): Replace with MongoGridFSStreamClosed
|
|
204
|
+
throw new MongoAPIError('Cannot abort a stream that has already completed');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (this.state.aborted) {
|
|
208
|
+
// TODO(NODE-3485): Replace with MongoGridFSStreamClosed
|
|
209
|
+
throw new MongoAPIError('Cannot call abort() on a stream twice');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
this.state.aborted = true;
|
|
213
|
+
const remainingTimeMS = this.timeoutContext?.getRemainingTimeMSOrThrow(
|
|
214
|
+
`Upload timed out after ${this.timeoutContext?.timeoutMS}ms`
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
await this.chunks.deleteMany({ files_id: this.id }, { timeoutMS: remainingTimeMS });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function handleError(stream: GridFSBucketWriteStream, error: Error, callback: Callback): void {
|
|
222
|
+
if (stream.state.errored) {
|
|
223
|
+
queueMicrotask(callback);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
stream.state.errored = true;
|
|
227
|
+
queueMicrotask(() => callback(error));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function createChunkDoc(filesId: ObjectId, n: number, data: Buffer): GridFSChunk {
|
|
231
|
+
return {
|
|
232
|
+
_id: new ObjectId(),
|
|
233
|
+
files_id: filesId,
|
|
234
|
+
n,
|
|
235
|
+
data
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function checkChunksIndex(stream: GridFSBucketWriteStream): Promise<void> {
|
|
240
|
+
const index = { files_id: 1, n: 1 };
|
|
241
|
+
|
|
242
|
+
let remainingTimeMS;
|
|
243
|
+
remainingTimeMS = stream.timeoutContext?.getRemainingTimeMSOrThrow(
|
|
244
|
+
`Upload timed out after ${stream.timeoutContext?.timeoutMS}ms`
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
let indexes;
|
|
248
|
+
try {
|
|
249
|
+
indexes = await stream.chunks
|
|
250
|
+
.listIndexes({
|
|
251
|
+
timeoutMode: remainingTimeMS != null ? CursorTimeoutMode.LIFETIME : undefined,
|
|
252
|
+
timeoutMS: remainingTimeMS
|
|
253
|
+
})
|
|
254
|
+
.toArray();
|
|
255
|
+
} catch (error) {
|
|
256
|
+
if (error instanceof MongoError && error.code === MONGODB_ERROR_CODES.NamespaceNotFound) {
|
|
257
|
+
indexes = [];
|
|
258
|
+
} else {
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const hasChunksIndex = !!indexes.find(index => {
|
|
264
|
+
const keys = Object.keys(index.key);
|
|
265
|
+
if (keys.length === 2 && index.key.files_id === 1 && index.key.n === 1) {
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
if (!hasChunksIndex) {
|
|
272
|
+
remainingTimeMS = stream.timeoutContext?.getRemainingTimeMSOrThrow(
|
|
273
|
+
`Upload timed out after ${stream.timeoutContext?.timeoutMS}ms`
|
|
274
|
+
);
|
|
275
|
+
await stream.chunks.createIndex(index, {
|
|
276
|
+
...stream.writeConcern,
|
|
277
|
+
background: true,
|
|
278
|
+
unique: true,
|
|
279
|
+
timeoutMS: remainingTimeMS
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function checkDone(stream: GridFSBucketWriteStream, callback: Callback): void {
|
|
285
|
+
if (stream.done) {
|
|
286
|
+
return queueMicrotask(callback);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (stream.state.streamEnd && stream.state.outstandingRequests === 0 && !stream.state.errored) {
|
|
290
|
+
// Set done so we do not trigger duplicate createFilesDoc
|
|
291
|
+
stream.done = true;
|
|
292
|
+
// Create a new files doc
|
|
293
|
+
const gridFSFile = createFilesDoc(
|
|
294
|
+
stream.id,
|
|
295
|
+
stream.length,
|
|
296
|
+
stream.chunkSizeBytes,
|
|
297
|
+
stream.filename,
|
|
298
|
+
stream.options.metadata
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
if (isAborted(stream, callback)) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const remainingTimeMS = stream.timeoutContext?.remainingTimeMS;
|
|
306
|
+
if (remainingTimeMS != null && remainingTimeMS <= 0) {
|
|
307
|
+
return handleError(
|
|
308
|
+
stream,
|
|
309
|
+
new MongoOperationTimeoutError(
|
|
310
|
+
`Upload timed out after ${stream.timeoutContext?.timeoutMS}ms`
|
|
311
|
+
),
|
|
312
|
+
callback
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
stream.files
|
|
317
|
+
.insertOne(gridFSFile, { writeConcern: stream.writeConcern, timeoutMS: remainingTimeMS })
|
|
318
|
+
.then(
|
|
319
|
+
() => {
|
|
320
|
+
stream.gridFSFile = gridFSFile;
|
|
321
|
+
callback();
|
|
322
|
+
},
|
|
323
|
+
error => {
|
|
324
|
+
return handleError(stream, error, callback);
|
|
325
|
+
}
|
|
326
|
+
);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
queueMicrotask(callback);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async function checkIndexes(stream: GridFSBucketWriteStream): Promise<void> {
|
|
334
|
+
let remainingTimeMS = stream.timeoutContext?.getRemainingTimeMSOrThrow(
|
|
335
|
+
`Upload timed out after ${stream.timeoutContext?.timeoutMS}ms`
|
|
336
|
+
);
|
|
337
|
+
const doc = await stream.files.findOne(
|
|
338
|
+
{},
|
|
339
|
+
{
|
|
340
|
+
projection: { _id: 1 },
|
|
341
|
+
timeoutMS: remainingTimeMS
|
|
342
|
+
}
|
|
343
|
+
);
|
|
344
|
+
if (doc != null) {
|
|
345
|
+
// If at least one document exists assume the collection has the required index
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const index = { filename: 1, uploadDate: 1 };
|
|
350
|
+
|
|
351
|
+
let indexes;
|
|
352
|
+
remainingTimeMS = stream.timeoutContext?.getRemainingTimeMSOrThrow(
|
|
353
|
+
`Upload timed out after ${stream.timeoutContext?.timeoutMS}ms`
|
|
354
|
+
);
|
|
355
|
+
const listIndexesOptions = {
|
|
356
|
+
timeoutMode: remainingTimeMS != null ? CursorTimeoutMode.LIFETIME : undefined,
|
|
357
|
+
timeoutMS: remainingTimeMS
|
|
358
|
+
};
|
|
359
|
+
try {
|
|
360
|
+
indexes = await stream.files.listIndexes(listIndexesOptions).toArray();
|
|
361
|
+
} catch (error) {
|
|
362
|
+
if (error instanceof MongoError && error.code === MONGODB_ERROR_CODES.NamespaceNotFound) {
|
|
363
|
+
indexes = [];
|
|
364
|
+
} else {
|
|
365
|
+
throw error;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const hasFileIndex = !!indexes.find(index => {
|
|
370
|
+
const keys = Object.keys(index.key);
|
|
371
|
+
if (keys.length === 2 && index.key.filename === 1 && index.key.uploadDate === 1) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
return false;
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
if (!hasFileIndex) {
|
|
378
|
+
remainingTimeMS = stream.timeoutContext?.getRemainingTimeMSOrThrow(
|
|
379
|
+
`Upload timed out after ${stream.timeoutContext?.timeoutMS}ms`
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
await stream.files.createIndex(index, { background: false, timeoutMS: remainingTimeMS });
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
await checkChunksIndex(stream);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function createFilesDoc(
|
|
389
|
+
_id: ObjectId,
|
|
390
|
+
length: number,
|
|
391
|
+
chunkSize: number,
|
|
392
|
+
filename: string,
|
|
393
|
+
metadata?: Document
|
|
394
|
+
): GridFSFile {
|
|
395
|
+
const ret: GridFSFile = {
|
|
396
|
+
_id,
|
|
397
|
+
length,
|
|
398
|
+
chunkSize,
|
|
399
|
+
uploadDate: new Date(),
|
|
400
|
+
filename
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
if (metadata) {
|
|
404
|
+
ret.metadata = metadata;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return ret;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function doWrite(
|
|
411
|
+
stream: GridFSBucketWriteStream,
|
|
412
|
+
chunk: Buffer | string,
|
|
413
|
+
encoding: BufferEncoding,
|
|
414
|
+
callback: Callback<void>
|
|
415
|
+
): void {
|
|
416
|
+
if (isAborted(stream, callback)) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const inputBuf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding);
|
|
421
|
+
|
|
422
|
+
stream.length += inputBuf.length;
|
|
423
|
+
|
|
424
|
+
// Input is small enough to fit in our buffer
|
|
425
|
+
if (stream.pos + inputBuf.length < stream.chunkSizeBytes) {
|
|
426
|
+
inputBuf.copy(stream.bufToStore, stream.pos);
|
|
427
|
+
stream.pos += inputBuf.length;
|
|
428
|
+
queueMicrotask(callback);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Otherwise, buffer is too big for current chunk, so we need to flush
|
|
433
|
+
// to MongoDB.
|
|
434
|
+
let inputBufRemaining = inputBuf.length;
|
|
435
|
+
let spaceRemaining: number = stream.chunkSizeBytes - stream.pos;
|
|
436
|
+
let numToCopy = Math.min(spaceRemaining, inputBuf.length);
|
|
437
|
+
let outstandingRequests = 0;
|
|
438
|
+
while (inputBufRemaining > 0) {
|
|
439
|
+
const inputBufPos = inputBuf.length - inputBufRemaining;
|
|
440
|
+
inputBuf.copy(stream.bufToStore, stream.pos, inputBufPos, inputBufPos + numToCopy);
|
|
441
|
+
stream.pos += numToCopy;
|
|
442
|
+
spaceRemaining -= numToCopy;
|
|
443
|
+
let doc: GridFSChunk;
|
|
444
|
+
if (spaceRemaining === 0) {
|
|
445
|
+
doc = createChunkDoc(stream.id, stream.n, Buffer.from(stream.bufToStore));
|
|
446
|
+
|
|
447
|
+
const remainingTimeMS = stream.timeoutContext?.remainingTimeMS;
|
|
448
|
+
if (remainingTimeMS != null && remainingTimeMS <= 0) {
|
|
449
|
+
return handleError(
|
|
450
|
+
stream,
|
|
451
|
+
new MongoOperationTimeoutError(
|
|
452
|
+
`Upload timed out after ${stream.timeoutContext?.timeoutMS}ms`
|
|
453
|
+
),
|
|
454
|
+
callback
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
++stream.state.outstandingRequests;
|
|
459
|
+
++outstandingRequests;
|
|
460
|
+
|
|
461
|
+
if (isAborted(stream, callback)) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
stream.chunks
|
|
466
|
+
.insertOne(doc, { writeConcern: stream.writeConcern, timeoutMS: remainingTimeMS })
|
|
467
|
+
.then(
|
|
468
|
+
() => {
|
|
469
|
+
--stream.state.outstandingRequests;
|
|
470
|
+
--outstandingRequests;
|
|
471
|
+
|
|
472
|
+
if (!outstandingRequests) {
|
|
473
|
+
checkDone(stream, callback);
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
error => {
|
|
477
|
+
return handleError(stream, error, callback);
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
spaceRemaining = stream.chunkSizeBytes;
|
|
482
|
+
stream.pos = 0;
|
|
483
|
+
++stream.n;
|
|
484
|
+
}
|
|
485
|
+
inputBufRemaining -= numToCopy;
|
|
486
|
+
numToCopy = Math.min(spaceRemaining, inputBufRemaining);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function writeRemnant(stream: GridFSBucketWriteStream, callback: Callback): void {
|
|
491
|
+
// Buffer is empty, so don't bother to insert
|
|
492
|
+
if (stream.pos === 0) {
|
|
493
|
+
return checkDone(stream, callback);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Create a new buffer to make sure the buffer isn't bigger than it needs
|
|
497
|
+
// to be.
|
|
498
|
+
const remnant = Buffer.alloc(stream.pos);
|
|
499
|
+
stream.bufToStore.copy(remnant, 0, 0, stream.pos);
|
|
500
|
+
const doc = createChunkDoc(stream.id, stream.n, remnant);
|
|
501
|
+
|
|
502
|
+
// If the stream was aborted, do not write remnant
|
|
503
|
+
if (isAborted(stream, callback)) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const remainingTimeMS = stream.timeoutContext?.remainingTimeMS;
|
|
508
|
+
if (remainingTimeMS != null && remainingTimeMS <= 0) {
|
|
509
|
+
return handleError(
|
|
510
|
+
stream,
|
|
511
|
+
new MongoOperationTimeoutError(
|
|
512
|
+
`Upload timed out after ${stream.timeoutContext?.timeoutMS}ms`
|
|
513
|
+
),
|
|
514
|
+
callback
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
++stream.state.outstandingRequests;
|
|
518
|
+
stream.chunks
|
|
519
|
+
.insertOne(doc, { writeConcern: stream.writeConcern, timeoutMS: remainingTimeMS })
|
|
520
|
+
.then(
|
|
521
|
+
() => {
|
|
522
|
+
--stream.state.outstandingRequests;
|
|
523
|
+
checkDone(stream, callback);
|
|
524
|
+
},
|
|
525
|
+
error => {
|
|
526
|
+
return handleError(stream, error, callback);
|
|
527
|
+
}
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function isAborted(stream: GridFSBucketWriteStream, callback: Callback<void>): boolean {
|
|
532
|
+
if (stream.state.aborted) {
|
|
533
|
+
queueMicrotask(() => callback(new MongoAPIError('Stream has been aborted')));
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
return false;
|
|
537
|
+
}
|