@milaboratories/pl-drivers 1.8.3 → 1.9.1
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/dist/clients/constructors.cjs +45 -0
- package/dist/clients/constructors.cjs.map +1 -0
- package/dist/clients/constructors.d.ts +0 -1
- package/dist/clients/constructors.js +39 -0
- package/dist/clients/constructors.js.map +1 -0
- package/dist/clients/download.cjs +149 -0
- package/dist/clients/download.cjs.map +1 -0
- package/dist/clients/download.d.ts +0 -1
- package/dist/clients/download.js +121 -0
- package/dist/clients/download.js.map +1 -0
- package/dist/clients/logs.cjs +44 -0
- package/dist/clients/logs.cjs.map +1 -0
- package/dist/clients/logs.d.ts +0 -1
- package/dist/clients/logs.js +42 -0
- package/dist/clients/logs.js.map +1 -0
- package/dist/clients/ls_api.cjs +23 -0
- package/dist/clients/ls_api.cjs.map +1 -0
- package/dist/clients/ls_api.d.ts +0 -1
- package/dist/clients/ls_api.js +21 -0
- package/dist/clients/ls_api.js.map +1 -0
- package/dist/clients/progress.cjs +58 -0
- package/dist/clients/progress.cjs.map +1 -0
- package/dist/clients/progress.d.ts +1 -3
- package/dist/clients/progress.js +56 -0
- package/dist/clients/progress.js.map +1 -0
- package/dist/clients/upload.cjs +188 -0
- package/dist/clients/upload.cjs.map +1 -0
- package/dist/clients/upload.d.ts +1 -3
- package/dist/clients/upload.js +163 -0
- package/dist/clients/upload.js.map +1 -0
- package/dist/drivers/download_blob/blob_key.cjs +34 -0
- package/dist/drivers/download_blob/blob_key.cjs.map +1 -0
- package/dist/drivers/download_blob/blob_key.d.ts +0 -1
- package/dist/drivers/download_blob/blob_key.js +12 -0
- package/dist/drivers/download_blob/blob_key.js.map +1 -0
- package/dist/drivers/download_blob/download_blob.cjs +442 -0
- package/dist/drivers/download_blob/download_blob.cjs.map +1 -0
- package/dist/drivers/download_blob/download_blob.d.ts +0 -1
- package/dist/drivers/download_blob/download_blob.js +417 -0
- package/dist/drivers/download_blob/download_blob.js.map +1 -0
- package/dist/drivers/download_blob/download_blob_task.cjs +170 -0
- package/dist/drivers/download_blob/download_blob_task.cjs.map +1 -0
- package/dist/drivers/download_blob/download_blob_task.d.ts +0 -1
- package/dist/drivers/download_blob/download_blob_task.js +146 -0
- package/dist/drivers/download_blob/download_blob_task.js.map +1 -0
- package/dist/drivers/download_blob/sparse_cache/cache.cjs +202 -0
- package/dist/drivers/download_blob/sparse_cache/cache.cjs.map +1 -0
- package/dist/drivers/download_blob/sparse_cache/cache.d.ts +0 -1
- package/dist/drivers/download_blob/sparse_cache/cache.js +197 -0
- package/dist/drivers/download_blob/sparse_cache/cache.js.map +1 -0
- package/dist/drivers/download_blob/sparse_cache/file.cjs +61 -0
- package/dist/drivers/download_blob/sparse_cache/file.cjs.map +1 -0
- package/dist/drivers/download_blob/sparse_cache/file.d.ts +0 -1
- package/dist/drivers/download_blob/sparse_cache/file.js +39 -0
- package/dist/drivers/download_blob/sparse_cache/file.js.map +1 -0
- package/dist/drivers/download_blob/sparse_cache/ranges.cjs +104 -0
- package/dist/drivers/download_blob/sparse_cache/ranges.cjs.map +1 -0
- package/dist/drivers/download_blob/sparse_cache/ranges.d.ts +0 -1
- package/dist/drivers/download_blob/sparse_cache/ranges.js +76 -0
- package/dist/drivers/download_blob/sparse_cache/ranges.js.map +1 -0
- package/dist/drivers/download_blob_url/driver.cjs +169 -0
- package/dist/drivers/download_blob_url/driver.cjs.map +1 -0
- package/dist/drivers/download_blob_url/driver.d.ts +0 -1
- package/dist/drivers/download_blob_url/driver.js +148 -0
- package/dist/drivers/download_blob_url/driver.js.map +1 -0
- package/dist/drivers/download_blob_url/driver_id.cjs +9 -0
- package/dist/drivers/download_blob_url/driver_id.cjs.map +1 -0
- package/dist/drivers/download_blob_url/driver_id.d.ts +0 -1
- package/dist/drivers/download_blob_url/driver_id.js +7 -0
- package/dist/drivers/download_blob_url/driver_id.js.map +1 -0
- package/dist/drivers/download_blob_url/snapshot.cjs +18 -0
- package/dist/drivers/download_blob_url/snapshot.cjs.map +1 -0
- package/dist/drivers/download_blob_url/snapshot.d.ts +2 -3
- package/dist/drivers/download_blob_url/snapshot.js +15 -0
- package/dist/drivers/download_blob_url/snapshot.js.map +1 -0
- package/dist/drivers/download_blob_url/task.cjs +209 -0
- package/dist/drivers/download_blob_url/task.cjs.map +1 -0
- package/dist/drivers/download_blob_url/task.d.ts +0 -1
- package/dist/drivers/download_blob_url/task.js +184 -0
- package/dist/drivers/download_blob_url/task.js.map +1 -0
- package/dist/drivers/download_blob_url/url.d.ts +1 -1
- package/dist/drivers/download_url/driver.cjs +149 -0
- package/dist/drivers/download_url/driver.cjs.map +1 -0
- package/dist/drivers/download_url/driver.d.ts +0 -1
- package/dist/drivers/download_url/driver.js +128 -0
- package/dist/drivers/download_url/driver.js.map +1 -0
- package/dist/drivers/download_url/task.cjs +150 -0
- package/dist/drivers/download_url/task.cjs.map +1 -0
- package/dist/drivers/download_url/task.d.ts +0 -1
- package/dist/drivers/download_url/task.js +124 -0
- package/dist/drivers/download_url/task.js.map +1 -0
- package/dist/drivers/helpers/download_local_handle.cjs +26 -0
- package/dist/drivers/helpers/download_local_handle.cjs.map +1 -0
- package/dist/drivers/helpers/download_local_handle.d.ts +0 -1
- package/dist/drivers/helpers/download_local_handle.js +22 -0
- package/dist/drivers/helpers/download_local_handle.js.map +1 -0
- package/dist/drivers/helpers/download_remote_handle.cjs +36 -0
- package/dist/drivers/helpers/download_remote_handle.cjs.map +1 -0
- package/dist/drivers/helpers/download_remote_handle.d.ts +0 -1
- package/dist/drivers/helpers/download_remote_handle.js +32 -0
- package/dist/drivers/helpers/download_remote_handle.js.map +1 -0
- package/dist/drivers/helpers/files_cache.cjs +68 -0
- package/dist/drivers/helpers/files_cache.cjs.map +1 -0
- package/dist/drivers/helpers/files_cache.d.ts +0 -1
- package/dist/drivers/helpers/files_cache.js +66 -0
- package/dist/drivers/helpers/files_cache.js.map +1 -0
- package/dist/drivers/helpers/helpers.cjs +34 -0
- package/dist/drivers/helpers/helpers.cjs.map +1 -0
- package/dist/drivers/helpers/helpers.d.ts +0 -1
- package/dist/drivers/helpers/helpers.js +31 -0
- package/dist/drivers/helpers/helpers.js.map +1 -0
- package/dist/drivers/helpers/logs_handle.cjs +50 -0
- package/dist/drivers/helpers/logs_handle.cjs.map +1 -0
- package/dist/drivers/helpers/logs_handle.d.ts +0 -1
- package/dist/drivers/helpers/logs_handle.js +43 -0
- package/dist/drivers/helpers/logs_handle.js.map +1 -0
- package/dist/drivers/helpers/ls_remote_import_handle.cjs +34 -0
- package/dist/drivers/helpers/ls_remote_import_handle.cjs.map +1 -0
- package/dist/drivers/helpers/ls_remote_import_handle.d.ts +0 -1
- package/dist/drivers/helpers/ls_remote_import_handle.js +29 -0
- package/dist/drivers/helpers/ls_remote_import_handle.js.map +1 -0
- package/dist/drivers/helpers/ls_storage_entry.cjs +64 -0
- package/dist/drivers/helpers/ls_storage_entry.cjs.map +1 -0
- package/dist/drivers/helpers/ls_storage_entry.d.ts +0 -1
- package/dist/drivers/helpers/ls_storage_entry.js +58 -0
- package/dist/drivers/helpers/ls_storage_entry.js.map +1 -0
- package/dist/drivers/helpers/polling_ops.d.ts +0 -1
- package/dist/drivers/helpers/read_file.cjs +54 -0
- package/dist/drivers/helpers/read_file.cjs.map +1 -0
- package/dist/drivers/helpers/read_file.d.ts +0 -1
- package/dist/drivers/helpers/read_file.js +33 -0
- package/dist/drivers/helpers/read_file.js.map +1 -0
- package/dist/drivers/helpers/test_helpers.d.ts +0 -1
- package/dist/drivers/logs.cjs +118 -0
- package/dist/drivers/logs.cjs.map +1 -0
- package/dist/drivers/logs.d.ts +0 -1
- package/dist/drivers/logs.js +116 -0
- package/dist/drivers/logs.js.map +1 -0
- package/dist/drivers/logs_stream.cjs +238 -0
- package/dist/drivers/logs_stream.cjs.map +1 -0
- package/dist/drivers/logs_stream.d.ts +0 -1
- package/dist/drivers/logs_stream.js +236 -0
- package/dist/drivers/logs_stream.js.map +1 -0
- package/dist/drivers/ls.cjs +236 -0
- package/dist/drivers/ls.cjs.map +1 -0
- package/dist/drivers/ls.d.ts +0 -1
- package/dist/drivers/ls.js +214 -0
- package/dist/drivers/ls.js.map +1 -0
- package/dist/drivers/types.cjs +72 -0
- package/dist/drivers/types.cjs.map +1 -0
- package/dist/drivers/types.d.ts +4 -5
- package/dist/drivers/types.js +64 -0
- package/dist/drivers/types.js.map +1 -0
- package/dist/drivers/upload.cjs +154 -0
- package/dist/drivers/upload.cjs.map +1 -0
- package/dist/drivers/upload.d.ts +0 -1
- package/dist/drivers/upload.js +151 -0
- package/dist/drivers/upload.js.map +1 -0
- package/dist/drivers/upload_task.cjs +293 -0
- package/dist/drivers/upload_task.cjs.map +1 -0
- package/dist/drivers/upload_task.d.ts +0 -1
- package/dist/drivers/upload_task.js +285 -0
- package/dist/drivers/upload_task.js.map +1 -0
- package/dist/drivers/urls/url.cjs +59 -0
- package/dist/drivers/urls/url.cjs.map +1 -0
- package/dist/drivers/urls/url.d.ts +0 -1
- package/dist/drivers/urls/url.js +54 -0
- package/dist/drivers/urls/url.js.map +1 -0
- package/dist/drivers/virtual_storages.cjs +53 -0
- package/dist/drivers/virtual_storages.cjs.map +1 -0
- package/dist/drivers/virtual_storages.d.ts +0 -1
- package/dist/drivers/virtual_storages.js +51 -0
- package/dist/drivers/virtual_storages.js.map +1 -0
- package/dist/helpers/download.cjs +63 -0
- package/dist/helpers/download.cjs.map +1 -0
- package/dist/helpers/download.d.ts +0 -1
- package/dist/helpers/download.js +60 -0
- package/dist/helpers/download.js.map +1 -0
- package/dist/helpers/validate.cjs +12 -0
- package/dist/helpers/validate.cjs.map +1 -0
- package/dist/helpers/validate.d.ts +0 -1
- package/dist/helpers/validate.js +10 -0
- package/dist/helpers/validate.js.map +1 -0
- package/dist/index.cjs +72 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs +261 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs +31 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js +29 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js +256 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs +301 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs +34 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js +32 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js +296 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs +410 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs +38 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js +36 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js +403 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs +486 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs +86 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js +84 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js +478 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs +712 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs +71 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js +69 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js +701 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +0 -1
- package/dist/proto/google/api/http.d.ts +0 -1
- package/dist/proto/google/protobuf/any.d.ts +0 -1
- package/dist/proto/google/protobuf/descriptor.d.ts +0 -1
- package/dist/proto/google/protobuf/duration.cjs +105 -0
- package/dist/proto/google/protobuf/duration.cjs.map +1 -0
- package/dist/proto/google/protobuf/duration.d.ts +0 -1
- package/dist/proto/google/protobuf/duration.js +103 -0
- package/dist/proto/google/protobuf/duration.js.map +1 -0
- package/dist/proto/google/protobuf/empty.d.ts +0 -1
- package/dist/proto/google/protobuf/struct.d.ts +0 -1
- package/dist/proto/google/protobuf/timestamp.cjs +133 -0
- package/dist/proto/google/protobuf/timestamp.cjs.map +1 -0
- package/dist/proto/google/protobuf/timestamp.d.ts +0 -1
- package/dist/proto/google/protobuf/timestamp.js +131 -0
- package/dist/proto/google/protobuf/timestamp.js.map +1 -0
- package/dist/proto/google/protobuf/wrappers.d.ts +0 -1
- package/dist/test_env.d.ts +0 -1
- package/package.json +21 -20
- package/src/clients/upload.ts +28 -3
- package/dist/clients/constructors.d.ts.map +0 -1
- package/dist/clients/download.d.ts.map +0 -1
- package/dist/clients/logs.d.ts.map +0 -1
- package/dist/clients/ls_api.d.ts.map +0 -1
- package/dist/clients/progress.d.ts.map +0 -1
- package/dist/clients/upload.d.ts.map +0 -1
- package/dist/drivers/download_blob/blob_key.d.ts.map +0 -1
- package/dist/drivers/download_blob/download_blob.d.ts.map +0 -1
- package/dist/drivers/download_blob/download_blob_task.d.ts.map +0 -1
- package/dist/drivers/download_blob/sparse_cache/cache.d.ts.map +0 -1
- package/dist/drivers/download_blob/sparse_cache/file.d.ts.map +0 -1
- package/dist/drivers/download_blob/sparse_cache/ranges.d.ts.map +0 -1
- package/dist/drivers/download_blob_url/driver.d.ts.map +0 -1
- package/dist/drivers/download_blob_url/driver_id.d.ts.map +0 -1
- package/dist/drivers/download_blob_url/snapshot.d.ts.map +0 -1
- package/dist/drivers/download_blob_url/task.d.ts.map +0 -1
- package/dist/drivers/download_blob_url/url.d.ts.map +0 -1
- package/dist/drivers/download_url/driver.d.ts.map +0 -1
- package/dist/drivers/download_url/task.d.ts.map +0 -1
- package/dist/drivers/helpers/download_local_handle.d.ts.map +0 -1
- package/dist/drivers/helpers/download_remote_handle.d.ts.map +0 -1
- package/dist/drivers/helpers/files_cache.d.ts.map +0 -1
- package/dist/drivers/helpers/helpers.d.ts.map +0 -1
- package/dist/drivers/helpers/logs_handle.d.ts.map +0 -1
- package/dist/drivers/helpers/ls_remote_import_handle.d.ts.map +0 -1
- package/dist/drivers/helpers/ls_storage_entry.d.ts.map +0 -1
- package/dist/drivers/helpers/polling_ops.d.ts.map +0 -1
- package/dist/drivers/helpers/read_file.d.ts.map +0 -1
- package/dist/drivers/helpers/test_helpers.d.ts.map +0 -1
- package/dist/drivers/logs.d.ts.map +0 -1
- package/dist/drivers/logs_stream.d.ts.map +0 -1
- package/dist/drivers/ls.d.ts.map +0 -1
- package/dist/drivers/types.d.ts.map +0 -1
- package/dist/drivers/upload.d.ts.map +0 -1
- package/dist/drivers/upload_task.d.ts.map +0 -1
- package/dist/drivers/urls/url.d.ts.map +0 -1
- package/dist/drivers/virtual_storages.d.ts.map +0 -1
- package/dist/helpers/download.d.ts.map +0 -1
- package/dist/helpers/validate.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.mjs +0 -4875
- package/dist/index.mjs.map +0 -1
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
- package/dist/proto/google/api/http.d.ts.map +0 -1
- package/dist/proto/google/protobuf/any.d.ts.map +0 -1
- package/dist/proto/google/protobuf/descriptor.d.ts.map +0 -1
- package/dist/proto/google/protobuf/duration.d.ts.map +0 -1
- package/dist/proto/google/protobuf/empty.d.ts.map +0 -1
- package/dist/proto/google/protobuf/struct.d.ts.map +0 -1
- package/dist/proto/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/proto/google/protobuf/wrappers.d.ts.map +0 -1
- package/dist/test_env.d.ts.map +0 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Writable, Transform } from 'node:stream';
|
|
2
|
+
import * as zlib from 'node:zlib';
|
|
3
|
+
import * as tar from 'tar-fs';
|
|
4
|
+
import path__default from 'node:path';
|
|
5
|
+
import fs__default from 'node:fs';
|
|
6
|
+
import * as fsp from 'node:fs/promises';
|
|
7
|
+
import { NetworkError400 } from '../../helpers/download.js';
|
|
8
|
+
import { ChangeSource } from '@milaboratories/computable';
|
|
9
|
+
import { CallersCounter, ensureDirExists, fileExists, createPathAtomically, notEmpty } from '@milaboratories/ts-helpers';
|
|
10
|
+
import { UnknownStorageError, WrongLocalFileUrl } from '../../clients/download.js';
|
|
11
|
+
import { newFolderURL } from '../urls/url.js';
|
|
12
|
+
import decompress from 'decompress';
|
|
13
|
+
import { assertNever } from '@protobuf-ts/runtime';
|
|
14
|
+
import { resourceIdToString, stringifyWithResourceId } from '@milaboratories/pl-client';
|
|
15
|
+
|
|
16
|
+
/** Downloads and extracts an archive to a directory. */
|
|
17
|
+
class DownloadAndUnarchiveTask {
|
|
18
|
+
logger;
|
|
19
|
+
signer;
|
|
20
|
+
saveDir;
|
|
21
|
+
path;
|
|
22
|
+
rInfo;
|
|
23
|
+
format;
|
|
24
|
+
clientDownload;
|
|
25
|
+
counter = new CallersCounter();
|
|
26
|
+
change = new ChangeSource();
|
|
27
|
+
signalCtl = new AbortController();
|
|
28
|
+
error;
|
|
29
|
+
done = false;
|
|
30
|
+
size = 0;
|
|
31
|
+
url;
|
|
32
|
+
state;
|
|
33
|
+
constructor(logger, signer, saveDir, path, rInfo, format, clientDownload) {
|
|
34
|
+
this.logger = logger;
|
|
35
|
+
this.signer = signer;
|
|
36
|
+
this.saveDir = saveDir;
|
|
37
|
+
this.path = path;
|
|
38
|
+
this.rInfo = rInfo;
|
|
39
|
+
this.format = format;
|
|
40
|
+
this.clientDownload = clientDownload;
|
|
41
|
+
}
|
|
42
|
+
/** A debug info of the task. */
|
|
43
|
+
info() {
|
|
44
|
+
return {
|
|
45
|
+
rInfo: this.rInfo,
|
|
46
|
+
format: this.format,
|
|
47
|
+
path: this.path,
|
|
48
|
+
done: this.done,
|
|
49
|
+
size: this.size,
|
|
50
|
+
error: this.error,
|
|
51
|
+
taskHistory: this.state,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
attach(w, callerId) {
|
|
55
|
+
this.counter.inc(callerId);
|
|
56
|
+
if (!this.done)
|
|
57
|
+
this.change.attachWatcher(w);
|
|
58
|
+
}
|
|
59
|
+
async download() {
|
|
60
|
+
try {
|
|
61
|
+
const size = await this.downloadAndDecompress(this.signalCtl.signal);
|
|
62
|
+
this.setDone(size);
|
|
63
|
+
this.change.markChanged(`download and decompress for ${resourceIdToString(this.rInfo.id)} finished`);
|
|
64
|
+
this.logger.info(`blob to URL task is done: ${stringifyWithResourceId(this.info())}`);
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
this.logger.warn(`a error was produced: ${e} for blob to URL task: ${stringifyWithResourceId(this.info())}`);
|
|
68
|
+
if (nonRecoverableError(e)) {
|
|
69
|
+
this.setError(e);
|
|
70
|
+
this.change.markChanged(`download and decompress for ${resourceIdToString(this.rInfo.id)} failed`);
|
|
71
|
+
// Just in case we were half-way extracting an archive.
|
|
72
|
+
await rmRFDir(this.path);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Does the download part and keeps a state of the process. */
|
|
79
|
+
async downloadAndDecompress(signal) {
|
|
80
|
+
this.state = {};
|
|
81
|
+
this.state.parentDir = path__default.dirname(this.path);
|
|
82
|
+
await ensureDirExists(this.state.parentDir);
|
|
83
|
+
this.state.fileExisted = await fileExists(this.path);
|
|
84
|
+
if (this.state.fileExisted) {
|
|
85
|
+
return await dirSize(this.path);
|
|
86
|
+
}
|
|
87
|
+
const size = await this.clientDownload.withBlobContent(this.rInfo, {}, { signal }, async (content, size) => {
|
|
88
|
+
this.state.downloaded = true;
|
|
89
|
+
await createPathAtomically(this.logger, this.path, async (fPath) => {
|
|
90
|
+
this.state.tempPath = fPath;
|
|
91
|
+
this.state.archiveFormat = this.format;
|
|
92
|
+
switch (this.format) {
|
|
93
|
+
case 'tar':
|
|
94
|
+
await fsp.mkdir(fPath); // throws if a directory already exists.
|
|
95
|
+
const simpleUntar = Writable.toWeb(tar.extract(fPath));
|
|
96
|
+
await content.pipeTo(simpleUntar, { signal });
|
|
97
|
+
return;
|
|
98
|
+
case 'tgz':
|
|
99
|
+
await fsp.mkdir(fPath); // throws if a directory already exists.
|
|
100
|
+
const gunzip = Transform.toWeb(zlib.createGunzip());
|
|
101
|
+
const untar = Writable.toWeb(tar.extract(fPath));
|
|
102
|
+
await content
|
|
103
|
+
.pipeThrough(gunzip, { signal })
|
|
104
|
+
.pipeTo(untar, { signal });
|
|
105
|
+
return;
|
|
106
|
+
case 'zip':
|
|
107
|
+
this.state.zipPath = this.path + '.zip';
|
|
108
|
+
const f = Writable.toWeb(fs__default.createWriteStream(this.state.zipPath));
|
|
109
|
+
await content.pipeTo(f, { signal });
|
|
110
|
+
this.state.zipPathCreated = true;
|
|
111
|
+
// Without this filter it fails with
|
|
112
|
+
// "EISDIR: illegal operation on a directory".
|
|
113
|
+
// The workaround is from
|
|
114
|
+
// https://github.com/kevva/decompress/issues/46#issuecomment-525048104
|
|
115
|
+
await decompress(this.state.zipPath, fPath, {
|
|
116
|
+
filter: file => !file.path.endsWith('/'),
|
|
117
|
+
});
|
|
118
|
+
this.state.zipDecompressed = true;
|
|
119
|
+
await fs__default.promises.rm(this.state.zipPath);
|
|
120
|
+
this.state.zipPathDeleted = true;
|
|
121
|
+
return;
|
|
122
|
+
default:
|
|
123
|
+
assertNever(this.format);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
this.state.pathCreated = true;
|
|
127
|
+
return size;
|
|
128
|
+
});
|
|
129
|
+
return size;
|
|
130
|
+
}
|
|
131
|
+
getURL() {
|
|
132
|
+
if (this.done)
|
|
133
|
+
return { url: notEmpty(this.url) };
|
|
134
|
+
if (this.error)
|
|
135
|
+
return { error: this.error };
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
setDone(size) {
|
|
139
|
+
this.done = true;
|
|
140
|
+
this.size = size;
|
|
141
|
+
this.url = newFolderURL(this.signer, this.saveDir, this.path);
|
|
142
|
+
}
|
|
143
|
+
setError(e) {
|
|
144
|
+
this.error = String(e);
|
|
145
|
+
}
|
|
146
|
+
abort(reason) {
|
|
147
|
+
this.signalCtl.abort(new URLAborted(reason));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Gets a directory size by calculating sizes recursively. */
|
|
151
|
+
async function dirSize(dir) {
|
|
152
|
+
const files = await fsp.readdir(dir, { withFileTypes: true });
|
|
153
|
+
const sizes = await Promise.all(files.map(async (file) => {
|
|
154
|
+
const fPath = path__default.join(dir, file.name);
|
|
155
|
+
if (file.isDirectory())
|
|
156
|
+
return await dirSize(fPath);
|
|
157
|
+
const stat = await fsp.stat(fPath);
|
|
158
|
+
return stat.size;
|
|
159
|
+
}));
|
|
160
|
+
return sizes.reduce((sum, size) => sum + size, 0);
|
|
161
|
+
}
|
|
162
|
+
/** Do rm -rf on dir. */
|
|
163
|
+
async function rmRFDir(path) {
|
|
164
|
+
await fsp.rm(path, { recursive: true, force: true });
|
|
165
|
+
}
|
|
166
|
+
/** Throws when a downloading aborts. */
|
|
167
|
+
class URLAborted extends Error {
|
|
168
|
+
name = 'URLAborted';
|
|
169
|
+
}
|
|
170
|
+
function nonRecoverableError(e) {
|
|
171
|
+
return (e instanceof URLAborted
|
|
172
|
+
|| e instanceof NetworkError400
|
|
173
|
+
|| e instanceof UnknownStorageError
|
|
174
|
+
|| e instanceof WrongLocalFileUrl
|
|
175
|
+
// file that we downloads from was moved or deleted.
|
|
176
|
+
|| e?.code == 'ENOENT'
|
|
177
|
+
// A resource was deleted.
|
|
178
|
+
|| (e.name == 'RpcError' && (e.code == 'NOT_FOUND' || e.code == 'ABORTED'))
|
|
179
|
+
// wrong archive format
|
|
180
|
+
|| (String(e).includes('incorrect header check')));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export { DownloadAndUnarchiveTask, nonRecoverableError, rmRFDir };
|
|
184
|
+
//# sourceMappingURL=task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.js","sources":["../../../src/drivers/download_blob_url/task.ts"],"sourcesContent":["import { Transform, Writable } from 'node:stream';\nimport * as zlib from 'node:zlib';\nimport * as tar from 'tar-fs';\nimport path from 'path';\nimport fs from 'fs';\nimport * as fsp from 'fs/promises';\nimport { NetworkError400 } from '../../helpers/download';\nimport type { Watcher } from '@milaboratories/computable';\nimport { ChangeSource } from '@milaboratories/computable';\nimport type { MiLogger, Signer } from '@milaboratories/ts-helpers';\nimport { CallersCounter, createPathAtomically, ensureDirExists, fileExists, notEmpty } from '@milaboratories/ts-helpers';\nimport type { DownloadableBlobSnapshot } from './snapshot';\nimport { UnknownStorageError, WrongLocalFileUrl, type ClientDownload } from '../../clients/download';\nimport type { ArchiveFormat, FolderURL } from '@milaboratories/pl-model-common';\nimport { newFolderURL } from '../urls/url';\nimport decompress from 'decompress';\nimport { assertNever } from '@protobuf-ts/runtime';\nimport { resourceIdToString, stringifyWithResourceId } from '@milaboratories/pl-client';\n\nexport type URLResult = {\n url?: FolderURL;\n error?: string;\n};\n\n/** Downloads and extracts an archive to a directory. */\nexport class DownloadAndUnarchiveTask {\n readonly counter = new CallersCounter();\n readonly change = new ChangeSource();\n private readonly signalCtl = new AbortController();\n error: string | undefined;\n done = false;\n size = 0;\n private url: FolderURL | undefined;\n private state: DownloadCtx | undefined;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly signer: Signer,\n readonly saveDir: string,\n readonly path: string,\n readonly rInfo: DownloadableBlobSnapshot,\n readonly format: ArchiveFormat,\n private readonly clientDownload: ClientDownload,\n ) {}\n\n /** A debug info of the task. */\n public info() {\n return {\n rInfo: this.rInfo,\n format: this.format,\n path: this.path,\n done: this.done,\n size: this.size,\n error: this.error,\n taskHistory: this.state,\n };\n }\n\n attach(w: Watcher, callerId: string) {\n this.counter.inc(callerId);\n if (!this.done) this.change.attachWatcher(w);\n }\n\n async download() {\n try {\n const size = await this.downloadAndDecompress(this.signalCtl.signal);\n this.setDone(size);\n this.change.markChanged(`download and decompress for ${resourceIdToString(this.rInfo.id)} finished`);\n\n this.logger.info(`blob to URL task is done: ${stringifyWithResourceId(this.info())}`);\n } catch (e: any) {\n this.logger.warn(`a error was produced: ${e} for blob to URL task: ${stringifyWithResourceId(this.info())}`);\n\n if (nonRecoverableError(e)) {\n this.setError(e);\n this.change.markChanged(`download and decompress for ${resourceIdToString(this.rInfo.id)} failed`);\n // Just in case we were half-way extracting an archive.\n await rmRFDir(this.path);\n return;\n }\n\n throw e;\n }\n }\n\n /** Does the download part and keeps a state of the process. */\n private async downloadAndDecompress(signal: AbortSignal): Promise<number> {\n this.state = {};\n\n this.state.parentDir = path.dirname(this.path);\n await ensureDirExists(this.state.parentDir);\n\n this.state.fileExisted = await fileExists(this.path);\n if (this.state.fileExisted) {\n return await dirSize(this.path);\n }\n\n const size = await this.clientDownload.withBlobContent(\n this.rInfo, \n {}, \n { signal },\n async (content, size) => {\n this.state!.downloaded = true;\n\n await createPathAtomically(this.logger, this.path, async (fPath: string) => {\n this.state!.tempPath = fPath;\n this.state!.archiveFormat = this.format;\n\n switch (this.format) {\n case 'tar':\n await fsp.mkdir(fPath); // throws if a directory already exists.\n const simpleUntar = Writable.toWeb(tar.extract(fPath));\n await content.pipeTo(simpleUntar, { signal });\n return;\n\n case 'tgz':\n await fsp.mkdir(fPath); // throws if a directory already exists.\n const gunzip = Transform.toWeb(zlib.createGunzip());\n const untar = Writable.toWeb(tar.extract(fPath));\n\n await content\n .pipeThrough(gunzip, { signal })\n .pipeTo(untar, { signal });\n return;\n\n case 'zip':\n this.state!.zipPath = this.path + '.zip';\n\n const f = Writable.toWeb(fs.createWriteStream(this.state!.zipPath));\n await content.pipeTo(f, { signal });\n this.state!.zipPathCreated = true;\n\n // Without this filter it fails with\n // \"EISDIR: illegal operation on a directory\".\n // The workaround is from\n // https://github.com/kevva/decompress/issues/46#issuecomment-525048104\n await decompress(this.state!.zipPath, fPath, {\n filter: file => !file.path.endsWith('/'),\n });\n this.state!.zipDecompressed = true;\n\n await fs.promises.rm(this.state!.zipPath);\n this.state!.zipPathDeleted = true;\n\n return;\n\n default:\n assertNever(this.format);\n }\n });\n\n this.state!.pathCreated = true;\n return size;\n }\n );\n\n return size;\n }\n\n getURL(): URLResult | undefined {\n if (this.done) return { url: notEmpty(this.url) };\n\n if (this.error) return { error: this.error };\n\n return undefined;\n }\n\n private setDone(size: number) {\n this.done = true;\n this.size = size;\n this.url = newFolderURL(this.signer, this.saveDir, this.path);\n }\n\n private setError(e: any) {\n this.error = String(e);\n }\n\n abort(reason: string) {\n this.signalCtl.abort(new URLAborted(reason));\n }\n}\n\n/** Gets a directory size by calculating sizes recursively. */\nasync function dirSize(dir: string): Promise<number> {\n const files = await fsp.readdir(dir, { withFileTypes: true });\n const sizes = await Promise.all(\n files.map(async (file: any) => {\n const fPath = path.join(dir, file.name);\n\n if (file.isDirectory()) return await dirSize(fPath);\n\n const stat = await fsp.stat(fPath);\n return stat.size;\n }),\n );\n\n return sizes.reduce((sum: any, size: any) => sum + size, 0);\n}\n\n/** Do rm -rf on dir. */\nexport async function rmRFDir(path: string) {\n await fsp.rm(path, { recursive: true, force: true });\n}\n\n/** Just a type that adds lots of context when the error happens. */\ntype DownloadCtx = {\n parentDir?: string;\n fileExisted?: boolean;\n downloaded?: boolean;\n archiveFormat?: ArchiveFormat;\n tempPath?: string;\n zipPath?: string;\n zipPathCreated?: boolean;\n zipDecompressed?: boolean;\n zipPathDeleted?: boolean;\n pathCreated?: boolean;\n};\n\n/** Throws when a downloading aborts. */\nclass URLAborted extends Error {\n name = 'URLAborted';\n}\n\nexport function nonRecoverableError(e: any) {\n return (\n e instanceof URLAborted\n || e instanceof NetworkError400\n || e instanceof UnknownStorageError\n || e instanceof WrongLocalFileUrl\n // file that we downloads from was moved or deleted.\n || e?.code == 'ENOENT'\n // A resource was deleted.\n || (e.name == 'RpcError' && (e.code == 'NOT_FOUND' || e.code == 'ABORTED'))\n // wrong archive format\n || (String(e).includes('incorrect header check'))\n );\n}\n"],"names":["path","fs"],"mappings":";;;;;;;;;;;;;;;AAwBA;MACa,wBAAwB,CAAA;AAWhB,IAAA,MAAA;AACA,IAAA,MAAA;AACR,IAAA,OAAA;AACA,IAAA,IAAA;AACA,IAAA,KAAA;AACA,IAAA,MAAA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AK,EAAE,IAAI,EAAE,CAAC;AACtD;AAgBA;AACA,MAAM,UAAW,SAAQ,KAAK,CAAA;IAC5B,IAAI,GAAG,YAAY;AACpB;AAEK,SAAU,mBAAmB,CAAC,CAAM,EAAA;IACxC,QACE,CAAC,YAAY;AACV,WAAA,CAAC,YAAY;AACb,WAAA,CAAC,YAAY;AACb,WAAA,CAAC,YAAY;;WAEb,CAAC,EAAE,IAAI,IAAI;;AAEX,YAAC,CAAC,CAAC,IAAI,IAAI,UAAU,KAAK,CAAC,CAAC,IAAI,IAAI,WAAW,IAAI,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC;;YAEtE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;AAErD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var computable = require('@milaboratories/computable');
|
|
4
|
+
var tsHelpers = require('@milaboratories/ts-helpers');
|
|
5
|
+
var node_crypto = require('node:crypto');
|
|
6
|
+
var path = require('node:path');
|
|
7
|
+
var download = require('../../helpers/download.cjs');
|
|
8
|
+
var files_cache = require('../helpers/files_cache.cjs');
|
|
9
|
+
var plClient = require('@milaboratories/pl-client');
|
|
10
|
+
var plModelCommon = require('@milaboratories/pl-model-common');
|
|
11
|
+
var url = require('../urls/url.cjs');
|
|
12
|
+
var task = require('./task.cjs');
|
|
13
|
+
|
|
14
|
+
function _interopNamespaceDefault(e) {
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
32
|
+
|
|
33
|
+
/** Downloads .tar or .tar.gz archives by given URLs
|
|
34
|
+
* and extracts them into saveDir. */
|
|
35
|
+
class DownloadUrlDriver {
|
|
36
|
+
logger;
|
|
37
|
+
saveDir;
|
|
38
|
+
signer;
|
|
39
|
+
opts;
|
|
40
|
+
downloadHelper;
|
|
41
|
+
urlToDownload = new Map();
|
|
42
|
+
downloadQueue;
|
|
43
|
+
/** Writes and removes files to a hard drive and holds a counter for every
|
|
44
|
+
* file that should be kept. */
|
|
45
|
+
cache;
|
|
46
|
+
constructor(logger, httpClient, saveDir, signer, opts = {
|
|
47
|
+
cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB
|
|
48
|
+
withGunzip: true,
|
|
49
|
+
nConcurrentDownloads: 50,
|
|
50
|
+
}) {
|
|
51
|
+
this.logger = logger;
|
|
52
|
+
this.saveDir = saveDir;
|
|
53
|
+
this.signer = signer;
|
|
54
|
+
this.opts = opts;
|
|
55
|
+
this.downloadQueue = new tsHelpers.TaskProcessor(this.logger, this.opts.nConcurrentDownloads);
|
|
56
|
+
this.cache = new files_cache.FilesCache(this.opts.cacheSoftSizeBytes);
|
|
57
|
+
this.downloadHelper = new download.RemoteFileDownloader(httpClient);
|
|
58
|
+
}
|
|
59
|
+
/** Returns a computable that returns a custom protocol URL to the downloaded and unarchived path. */
|
|
60
|
+
getUrl(url, ctx) {
|
|
61
|
+
// wrap result as computable, if we were not given an existing computable context
|
|
62
|
+
if (ctx === undefined)
|
|
63
|
+
return computable.Computable.make((c) => this.getUrl(url, c));
|
|
64
|
+
const callerId = node_crypto.randomUUID();
|
|
65
|
+
// read as ~ golang's defer
|
|
66
|
+
ctx.addOnDestroy(() => this.releasePath(url, callerId));
|
|
67
|
+
const result = this.getUrlNoCtx(url, ctx.watcher, callerId);
|
|
68
|
+
if (result?.url === undefined)
|
|
69
|
+
ctx.markUnstable(`a path to the downloaded and untared archive might be undefined. The current result: ${result}`);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
getUrlNoCtx(url, w, callerId) {
|
|
73
|
+
const key = url.toString();
|
|
74
|
+
const task = this.urlToDownload.get(key);
|
|
75
|
+
if (task !== undefined) {
|
|
76
|
+
task.attach(w, callerId);
|
|
77
|
+
return task.getUrl();
|
|
78
|
+
}
|
|
79
|
+
const newTask = this.setNewTask(w, url, callerId);
|
|
80
|
+
this.downloadQueue.push({
|
|
81
|
+
fn: async () => this.downloadUrl(newTask, callerId),
|
|
82
|
+
recoverableErrorPredicate: (e) => true,
|
|
83
|
+
});
|
|
84
|
+
return newTask.getUrl();
|
|
85
|
+
}
|
|
86
|
+
getPathForBlockUI(url$1) {
|
|
87
|
+
if (!plModelCommon.isBlockUIURL(url$1)) {
|
|
88
|
+
throw new Error(`getPathForBlockUI: ${url$1} is invalid`);
|
|
89
|
+
}
|
|
90
|
+
return url.getPathForBlockUIURL(this.signer, url$1, this.saveDir);
|
|
91
|
+
}
|
|
92
|
+
/** Downloads and extracts a tar archive if it wasn't downloaded yet. */
|
|
93
|
+
async downloadUrl(task, callerId) {
|
|
94
|
+
await task.download(this.downloadHelper, this.opts.withGunzip);
|
|
95
|
+
// Might be undefined if a error happened
|
|
96
|
+
if (task.getUrl()?.url !== undefined)
|
|
97
|
+
this.cache.addCache(task, callerId);
|
|
98
|
+
}
|
|
99
|
+
/** Removes a directory and aborts a downloading task when all callers
|
|
100
|
+
* are not interested in it. */
|
|
101
|
+
async releasePath(url, callerId) {
|
|
102
|
+
const key = url.toString();
|
|
103
|
+
const task$1 = this.urlToDownload.get(key);
|
|
104
|
+
if (task$1 == undefined)
|
|
105
|
+
return;
|
|
106
|
+
if (this.cache.existsFile(task$1.path)) {
|
|
107
|
+
const toDelete = this.cache.removeFile(task$1.path, callerId);
|
|
108
|
+
await Promise.all(toDelete.map(async (task$1) => {
|
|
109
|
+
await task.rmRFDir(task$1.path);
|
|
110
|
+
this.cache.removeCache(task$1);
|
|
111
|
+
this.removeTask(task$1, `the task ${plClient.stringifyWithResourceId(task$1.info())} was removed`
|
|
112
|
+
+ `from cache along with ${plClient.stringifyWithResourceId(toDelete.map((t) => t.info()))}`);
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// The task is still in a downloading queue.
|
|
117
|
+
const deleted = task$1.counter.dec(callerId);
|
|
118
|
+
if (deleted)
|
|
119
|
+
this.removeTask(task$1, `the task ${plClient.stringifyWithResourceId(task$1.info())} was removed from cache`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Removes all files from a hard drive. */
|
|
123
|
+
async releaseAll() {
|
|
124
|
+
this.downloadQueue.stop();
|
|
125
|
+
await Promise.all(Array.from(this.urlToDownload.entries()).map(async ([id, task$1]) => {
|
|
126
|
+
await task.rmRFDir(task$1.path);
|
|
127
|
+
this.cache.removeCache(task$1);
|
|
128
|
+
this.removeTask(task$1, `the task ${plClient.stringifyWithResourceId(task$1.info())} was released when the driver was closed`);
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
setNewTask(w, url, callerId) {
|
|
132
|
+
const result = new task.DownloadByUrlTask(this.logger, this.getFilePath(url), url, this.signer, this.saveDir);
|
|
133
|
+
result.attach(w, callerId);
|
|
134
|
+
this.urlToDownload.set(url.toString(), result);
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
removeTask(task, reason) {
|
|
138
|
+
task.abort(reason);
|
|
139
|
+
task.change.markChanged(`task for url ${task.url} removed: ${reason}`);
|
|
140
|
+
this.urlToDownload.delete(task.url.toString());
|
|
141
|
+
}
|
|
142
|
+
getFilePath(url) {
|
|
143
|
+
const sha256 = node_crypto.createHash('sha256').update(url.toString()).digest('hex');
|
|
144
|
+
return path__namespace.join(this.saveDir, sha256);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
exports.DownloadUrlDriver = DownloadUrlDriver;
|
|
149
|
+
//# sourceMappingURL=driver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.cjs","sources":["../../../src/drivers/download_url/driver.ts"],"sourcesContent":["import type { ComputableCtx, Watcher } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport type {\n MiLogger,\n Signer,\n} from '@milaboratories/ts-helpers';\nimport {\n TaskProcessor,\n} from '@milaboratories/ts-helpers';\nimport { createHash, randomUUID } from 'node:crypto';\nimport * as path from 'node:path';\nimport type { Dispatcher } from 'undici';\nimport { RemoteFileDownloader } from '../../helpers/download';\nimport { FilesCache } from '../helpers/files_cache';\nimport { stringifyWithResourceId } from '@milaboratories/pl-client';\nimport type { BlockUIURL, FrontendDriver } from '@milaboratories/pl-model-common';\nimport { isBlockUIURL } from '@milaboratories/pl-model-common';\nimport { getPathForBlockUIURL } from '../urls/url';\nimport { DownloadByUrlTask, rmRFDir } from './task';\n\nexport interface DownloadUrlSyncReader {\n /** Returns a Computable that (when the time will come)\n * downloads an archive from an URL,\n * extracts it to the local dir and returns a path to that dir. */\n getUrl(url: URL): Computable<UrlResult | undefined>;\n}\n\nexport interface UrlResult {\n /** Path to the downloadable blob along with the signature and a custom protocol,\n * might be undefined when the error happened. */\n url?: BlockUIURL;\n /** Error that happened when the archive were downloaded. */\n error?: string;\n}\n\nexport type DownloadUrlDriverOps = {\n /** A soft limit of the amount of blob storage, in bytes.\n * Once exceeded, the download driver will start deleting blobs one by one\n * when they become unneeded.\n * */\n cacheSoftSizeBytes: number;\n\n /** Whether to gunzip the downloaded archive (it will be untared automatically). */\n withGunzip: boolean;\n\n /** Max number of concurrent downloads while calculating computable states\n * derived from this driver.\n * */\n nConcurrentDownloads: number;\n};\n\n/** Downloads .tar or .tar.gz archives by given URLs\n * and extracts them into saveDir. */\nexport class DownloadUrlDriver implements DownloadUrlSyncReader, FrontendDriver {\n private readonly downloadHelper: RemoteFileDownloader;\n\n private urlToDownload: Map<string, DownloadByUrlTask> = new Map();\n private downloadQueue: TaskProcessor;\n\n /** Writes and removes files to a hard drive and holds a counter for every\n * file that should be kept. */\n private cache: FilesCache<DownloadByUrlTask>;\n\n constructor(\n private readonly logger: MiLogger,\n httpClient: Dispatcher,\n private readonly saveDir: string,\n private readonly signer: Signer,\n private readonly opts: DownloadUrlDriverOps = {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n withGunzip: true,\n nConcurrentDownloads: 50,\n },\n ) {\n this.downloadQueue = new TaskProcessor(this.logger, this.opts.nConcurrentDownloads);\n this.cache = new FilesCache(this.opts.cacheSoftSizeBytes);\n this.downloadHelper = new RemoteFileDownloader(httpClient);\n }\n\n /** Use to get a path result inside a computable context */\n getUrl(url: URL, ctx: ComputableCtx): UrlResult | undefined;\n\n /** Returns a Computable that do the work */\n getUrl(url: URL): Computable<UrlResult | undefined>;\n\n /** Returns a computable that returns a custom protocol URL to the downloaded and unarchived path. */\n getUrl(\n url: URL,\n ctx?: ComputableCtx,\n ): Computable<UrlResult | undefined> | UrlResult | undefined {\n // wrap result as computable, if we were not given an existing computable context\n if (ctx === undefined) return Computable.make((c) => this.getUrl(url, c));\n\n const callerId = randomUUID();\n\n // read as ~ golang's defer\n ctx.addOnDestroy(() => this.releasePath(url, callerId));\n\n const result = this.getUrlNoCtx(url, ctx.watcher, callerId);\n if (result?.url === undefined)\n ctx.markUnstable(\n `a path to the downloaded and untared archive might be undefined. The current result: ${result}`,\n );\n\n return result;\n }\n\n getUrlNoCtx(url: URL, w: Watcher, callerId: string) {\n const key = url.toString();\n const task = this.urlToDownload.get(key);\n\n if (task !== undefined) {\n task.attach(w, callerId);\n return task.getUrl();\n }\n\n const newTask = this.setNewTask(w, url, callerId);\n this.downloadQueue.push({\n fn: async () => this.downloadUrl(newTask, callerId),\n recoverableErrorPredicate: (e) => true,\n });\n\n return newTask.getUrl();\n }\n\n getPathForBlockUI(url: string): string {\n if (!isBlockUIURL(url)) {\n throw new Error(`getPathForBlockUI: ${url} is invalid`);\n }\n\n return getPathForBlockUIURL(this.signer, url, this.saveDir);\n }\n\n /** Downloads and extracts a tar archive if it wasn't downloaded yet. */\n async downloadUrl(task: DownloadByUrlTask, callerId: string) {\n await task.download(this.downloadHelper, this.opts.withGunzip);\n // Might be undefined if a error happened\n if (task.getUrl()?.url !== undefined) this.cache.addCache(task, callerId);\n }\n\n /** Removes a directory and aborts a downloading task when all callers\n * are not interested in it. */\n async releasePath(url: URL, callerId: string): Promise<void> {\n const key = url.toString();\n const task = this.urlToDownload.get(key);\n if (task == undefined) return;\n\n if (this.cache.existsFile(task.path)) {\n const toDelete = this.cache.removeFile(task.path, callerId);\n\n await Promise.all(\n toDelete.map(async (task: DownloadByUrlTask) => {\n await rmRFDir(task.path);\n this.cache.removeCache(task);\n\n this.removeTask(\n task,\n `the task ${stringifyWithResourceId(task.info())} was removed`\n + `from cache along with ${stringifyWithResourceId(toDelete.map((t) => t.info()))}`,\n );\n }),\n );\n } else {\n // The task is still in a downloading queue.\n const deleted = task.counter.dec(callerId);\n if (deleted)\n this.removeTask(\n task,\n `the task ${stringifyWithResourceId(task.info())} was removed from cache`,\n );\n }\n }\n\n /** Removes all files from a hard drive. */\n async releaseAll() {\n this.downloadQueue.stop();\n\n await Promise.all(\n Array.from(this.urlToDownload.entries()).map(async ([id, task]) => {\n await rmRFDir(task.path);\n this.cache.removeCache(task);\n\n this.removeTask(\n task,\n `the task ${stringifyWithResourceId(task.info())} was released when the driver was closed`,\n );\n }),\n );\n }\n\n private setNewTask(w: Watcher, url: URL, callerId: string) {\n const result = new DownloadByUrlTask(\n this.logger,\n this.getFilePath(url),\n url,\n this.signer,\n this.saveDir,\n );\n result.attach(w, callerId);\n this.urlToDownload.set(url.toString(), result);\n\n return result;\n }\n\n private removeTask(task: DownloadByUrlTask, reason: string) {\n task.abort(reason);\n task.change.markChanged(`task for url ${task.url} removed: ${reason}`);\n this.urlToDownload.delete(task.url.toString());\n }\n\n private getFilePath(url: URL): string {\n const sha256 = createHash('sha256').update(url.toString()).digest('hex');\n return path.join(this.saveDir, sha256);\n }\n}\n"],"names":["TaskProcessor","FilesCache","RemoteFileDownloader","Computable","randomUUID","url","isBlockUIURL","getPathForBlockUIURL","task","rmRFDir","stringifyWithResourceId","DownloadByUrlTask","createHash","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA;AACqC;MACxB,iBAAiB,CAAA;AAWT,IAAA,MAAA;AAEA,IAAA,OAAA;AACA,IAAA,MAAA;AACA,IAAA,IAAA;AAdF,IAAA,cAAc;AAEvB,IAAA,aAAa,GAAmC,IAAI,GAAG,EAAE;AACzD,IAAA,aAAa;AAErB;AAC+B;AACvB,IAAA,KAAK;IAEb,WAAA,CACmB,MAAgB,EACjC,UAAsB,EACL,OAAe,EACf,MAAc,EACd,IAAA,GAA6B;QAC5C,kBAAkB,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI;AAC1C,QAAA,UAAU,EAAE,IAAI;AAChB,QAAA,oBAAoB,EAAE,EAAE;AACzB,KAAA,EAAA;QARgB,IAAA,CAAA,MAAM,GAAN,MAAM;QAEN,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,IAAI,GAAJ,IAAI;AAMrB,QAAA,IAAI,CAAC,aAAa,GAAG,IAAIA,uBAAa,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC;AACnF,QAAA,IAAI,CAAC,KAAK,GAAG,IAAIC,sBAAU,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC;QACzD,IAAI,CAAC,cAAc,GAAG,IAAIC,6BAAoB,CAAC,UAAU,CAAC;IAC5D;;IASA,MAAM,CACJ,GAAQ,EACR,GAAmB,EAAA;;QAGnB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EACH,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,CACb;AACD,QAAA,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC;AAC1B,QAAA,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC;AAE9C,QAAA,OAAO,MAAM;IACf;IAEQ,UAAU,CAAC,IAAuB,EAAE,MAAc,EAAA;AACxD,QAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;AAClB,QAAA,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA,aAAA,EAAgB,IAAI,CAAC,GAAG,CAAA,UAAA,EAAa,MAAM,CAAA,CAAE,CAAC;AACtE,QAAA,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAChD;AAEQ,IAAA,WAAW,CAAC,GAAQ,EAAA;AAC1B,QAAA,MAAM,MAAM,GAAGC,sBAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QACxE,OAAOC,eAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;IACxC;AACD;;;;"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Computable } from '@milaboratories/computable';
|
|
2
|
+
import { TaskProcessor } from '@milaboratories/ts-helpers';
|
|
3
|
+
import { randomUUID, createHash } from 'node:crypto';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { RemoteFileDownloader } from '../../helpers/download.js';
|
|
6
|
+
import { FilesCache } from '../helpers/files_cache.js';
|
|
7
|
+
import { stringifyWithResourceId } from '@milaboratories/pl-client';
|
|
8
|
+
import { isBlockUIURL } from '@milaboratories/pl-model-common';
|
|
9
|
+
import { getPathForBlockUIURL } from '../urls/url.js';
|
|
10
|
+
import { rmRFDir, DownloadByUrlTask } from './task.js';
|
|
11
|
+
|
|
12
|
+
/** Downloads .tar or .tar.gz archives by given URLs
|
|
13
|
+
* and extracts them into saveDir. */
|
|
14
|
+
class DownloadUrlDriver {
|
|
15
|
+
logger;
|
|
16
|
+
saveDir;
|
|
17
|
+
signer;
|
|
18
|
+
opts;
|
|
19
|
+
downloadHelper;
|
|
20
|
+
urlToDownload = new Map();
|
|
21
|
+
downloadQueue;
|
|
22
|
+
/** Writes and removes files to a hard drive and holds a counter for every
|
|
23
|
+
* file that should be kept. */
|
|
24
|
+
cache;
|
|
25
|
+
constructor(logger, httpClient, saveDir, signer, opts = {
|
|
26
|
+
cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB
|
|
27
|
+
withGunzip: true,
|
|
28
|
+
nConcurrentDownloads: 50,
|
|
29
|
+
}) {
|
|
30
|
+
this.logger = logger;
|
|
31
|
+
this.saveDir = saveDir;
|
|
32
|
+
this.signer = signer;
|
|
33
|
+
this.opts = opts;
|
|
34
|
+
this.downloadQueue = new TaskProcessor(this.logger, this.opts.nConcurrentDownloads);
|
|
35
|
+
this.cache = new FilesCache(this.opts.cacheSoftSizeBytes);
|
|
36
|
+
this.downloadHelper = new RemoteFileDownloader(httpClient);
|
|
37
|
+
}
|
|
38
|
+
/** Returns a computable that returns a custom protocol URL to the downloaded and unarchived path. */
|
|
39
|
+
getUrl(url, ctx) {
|
|
40
|
+
// wrap result as computable, if we were not given an existing computable context
|
|
41
|
+
if (ctx === undefined)
|
|
42
|
+
return Computable.make((c) => this.getUrl(url, c));
|
|
43
|
+
const callerId = randomUUID();
|
|
44
|
+
// read as ~ golang's defer
|
|
45
|
+
ctx.addOnDestroy(() => this.releasePath(url, callerId));
|
|
46
|
+
const result = this.getUrlNoCtx(url, ctx.watcher, callerId);
|
|
47
|
+
if (result?.url === undefined)
|
|
48
|
+
ctx.markUnstable(`a path to the downloaded and untared archive might be undefined. The current result: ${result}`);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
getUrlNoCtx(url, w, callerId) {
|
|
52
|
+
const key = url.toString();
|
|
53
|
+
const task = this.urlToDownload.get(key);
|
|
54
|
+
if (task !== undefined) {
|
|
55
|
+
task.attach(w, callerId);
|
|
56
|
+
return task.getUrl();
|
|
57
|
+
}
|
|
58
|
+
const newTask = this.setNewTask(w, url, callerId);
|
|
59
|
+
this.downloadQueue.push({
|
|
60
|
+
fn: async () => this.downloadUrl(newTask, callerId),
|
|
61
|
+
recoverableErrorPredicate: (e) => true,
|
|
62
|
+
});
|
|
63
|
+
return newTask.getUrl();
|
|
64
|
+
}
|
|
65
|
+
getPathForBlockUI(url) {
|
|
66
|
+
if (!isBlockUIURL(url)) {
|
|
67
|
+
throw new Error(`getPathForBlockUI: ${url} is invalid`);
|
|
68
|
+
}
|
|
69
|
+
return getPathForBlockUIURL(this.signer, url, this.saveDir);
|
|
70
|
+
}
|
|
71
|
+
/** Downloads and extracts a tar archive if it wasn't downloaded yet. */
|
|
72
|
+
async downloadUrl(task, callerId) {
|
|
73
|
+
await task.download(this.downloadHelper, this.opts.withGunzip);
|
|
74
|
+
// Might be undefined if a error happened
|
|
75
|
+
if (task.getUrl()?.url !== undefined)
|
|
76
|
+
this.cache.addCache(task, callerId);
|
|
77
|
+
}
|
|
78
|
+
/** Removes a directory and aborts a downloading task when all callers
|
|
79
|
+
* are not interested in it. */
|
|
80
|
+
async releasePath(url, callerId) {
|
|
81
|
+
const key = url.toString();
|
|
82
|
+
const task = this.urlToDownload.get(key);
|
|
83
|
+
if (task == undefined)
|
|
84
|
+
return;
|
|
85
|
+
if (this.cache.existsFile(task.path)) {
|
|
86
|
+
const toDelete = this.cache.removeFile(task.path, callerId);
|
|
87
|
+
await Promise.all(toDelete.map(async (task) => {
|
|
88
|
+
await rmRFDir(task.path);
|
|
89
|
+
this.cache.removeCache(task);
|
|
90
|
+
this.removeTask(task, `the task ${stringifyWithResourceId(task.info())} was removed`
|
|
91
|
+
+ `from cache along with ${stringifyWithResourceId(toDelete.map((t) => t.info()))}`);
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// The task is still in a downloading queue.
|
|
96
|
+
const deleted = task.counter.dec(callerId);
|
|
97
|
+
if (deleted)
|
|
98
|
+
this.removeTask(task, `the task ${stringifyWithResourceId(task.info())} was removed from cache`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Removes all files from a hard drive. */
|
|
102
|
+
async releaseAll() {
|
|
103
|
+
this.downloadQueue.stop();
|
|
104
|
+
await Promise.all(Array.from(this.urlToDownload.entries()).map(async ([id, task]) => {
|
|
105
|
+
await rmRFDir(task.path);
|
|
106
|
+
this.cache.removeCache(task);
|
|
107
|
+
this.removeTask(task, `the task ${stringifyWithResourceId(task.info())} was released when the driver was closed`);
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
setNewTask(w, url, callerId) {
|
|
111
|
+
const result = new DownloadByUrlTask(this.logger, this.getFilePath(url), url, this.signer, this.saveDir);
|
|
112
|
+
result.attach(w, callerId);
|
|
113
|
+
this.urlToDownload.set(url.toString(), result);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
removeTask(task, reason) {
|
|
117
|
+
task.abort(reason);
|
|
118
|
+
task.change.markChanged(`task for url ${task.url} removed: ${reason}`);
|
|
119
|
+
this.urlToDownload.delete(task.url.toString());
|
|
120
|
+
}
|
|
121
|
+
getFilePath(url) {
|
|
122
|
+
const sha256 = createHash('sha256').update(url.toString()).digest('hex');
|
|
123
|
+
return path.join(this.saveDir, sha256);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { DownloadUrlDriver };
|
|
128
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.js","sources":["../../../src/drivers/download_url/driver.ts"],"sourcesContent":["import type { ComputableCtx, Watcher } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport type {\n MiLogger,\n Signer,\n} from '@milaboratories/ts-helpers';\nimport {\n TaskProcessor,\n} from '@milaboratories/ts-helpers';\nimport { createHash, randomUUID } from 'node:crypto';\nimport * as path from 'node:path';\nimport type { Dispatcher } from 'undici';\nimport { RemoteFileDownloader } from '../../helpers/download';\nimport { FilesCache } from '../helpers/files_cache';\nimport { stringifyWithResourceId } from '@milaboratories/pl-client';\nimport type { BlockUIURL, FrontendDriver } from '@milaboratories/pl-model-common';\nimport { isBlockUIURL } from '@milaboratories/pl-model-common';\nimport { getPathForBlockUIURL } from '../urls/url';\nimport { DownloadByUrlTask, rmRFDir } from './task';\n\nexport interface DownloadUrlSyncReader {\n /** Returns a Computable that (when the time will come)\n * downloads an archive from an URL,\n * extracts it to the local dir and returns a path to that dir. */\n getUrl(url: URL): Computable<UrlResult | undefined>;\n}\n\nexport interface UrlResult {\n /** Path to the downloadable blob along with the signature and a custom protocol,\n * might be undefined when the error happened. */\n url?: BlockUIURL;\n /** Error that happened when the archive were downloaded. */\n error?: string;\n}\n\nexport type DownloadUrlDriverOps = {\n /** A soft limit of the amount of blob storage, in bytes.\n * Once exceeded, the download driver will start deleting blobs one by one\n * when they become unneeded.\n * */\n cacheSoftSizeBytes: number;\n\n /** Whether to gunzip the downloaded archive (it will be untared automatically). */\n withGunzip: boolean;\n\n /** Max number of concurrent downloads while calculating computable states\n * derived from this driver.\n * */\n nConcurrentDownloads: number;\n};\n\n/** Downloads .tar or .tar.gz archives by given URLs\n * and extracts them into saveDir. */\nexport class DownloadUrlDriver implements DownloadUrlSyncReader, FrontendDriver {\n private readonly downloadHelper: RemoteFileDownloader;\n\n private urlToDownload: Map<string, DownloadByUrlTask> = new Map();\n private downloadQueue: TaskProcessor;\n\n /** Writes and removes files to a hard drive and holds a counter for every\n * file that should be kept. */\n private cache: FilesCache<DownloadByUrlTask>;\n\n constructor(\n private readonly logger: MiLogger,\n httpClient: Dispatcher,\n private readonly saveDir: string,\n private readonly signer: Signer,\n private readonly opts: DownloadUrlDriverOps = {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n withGunzip: true,\n nConcurrentDownloads: 50,\n },\n ) {\n this.downloadQueue = new TaskProcessor(this.logger, this.opts.nConcurrentDownloads);\n this.cache = new FilesCache(this.opts.cacheSoftSizeBytes);\n this.downloadHelper = new RemoteFileDownloader(httpClient);\n }\n\n /** Use to get a path result inside a computable context */\n getUrl(url: URL, ctx: ComputableCtx): UrlResult | undefined;\n\n /** Returns a Computable that do the work */\n getUrl(url: URL): Computable<UrlResult | undefined>;\n\n /** Returns a computable that returns a custom protocol URL to the downloaded and unarchived path. */\n getUrl(\n url: URL,\n ctx?: ComputableCtx,\n ): Computable<UrlResult | undefined> | UrlResult | undefined {\n // wrap result as computable, if we were not given an existing computable context\n if (ctx === undefined) return Computable.make((c) => this.getUrl(url, c));\n\n const callerId = randomUUID();\n\n // read as ~ golang's defer\n ctx.addOnDestroy(() => this.releasePath(url, callerId));\n\n const result = this.getUrlNoCtx(url, ctx.watcher, callerId);\n if (result?.url === undefined)\n ctx.markUnstable(\n `a path to the downloaded and untared archive might be undefined. The current result: ${result}`,\n );\n\n return result;\n }\n\n getUrlNoCtx(url: URL, w: Watcher, callerId: string) {\n const key = url.toString();\n const task = this.urlToDownload.get(key);\n\n if (task !== undefined) {\n task.attach(w, callerId);\n return task.getUrl();\n }\n\n const newTask = this.setNewTask(w, url, callerId);\n this.downloadQueue.push({\n fn: async () => this.downloadUrl(newTask, callerId),\n recoverableErrorPredicate: (e) => true,\n });\n\n return newTask.getUrl();\n }\n\n getPathForBlockUI(url: string): string {\n if (!isBlockUIURL(url)) {\n throw new Error(`getPathForBlockUI: ${url} is invalid`);\n }\n\n return getPathForBlockUIURL(this.signer, url, this.saveDir);\n }\n\n /** Downloads and extracts a tar archive if it wasn't downloaded yet. */\n async downloadUrl(task: DownloadByUrlTask, callerId: string) {\n await task.download(this.downloadHelper, this.opts.withGunzip);\n // Might be undefined if a error happened\n if (task.getUrl()?.url !== undefined) this.cache.addCache(task, callerId);\n }\n\n /** Removes a directory and aborts a downloading task when all callers\n * are not interested in it. */\n async releasePath(url: URL, callerId: string): Promise<void> {\n const key = url.toString();\n const task = this.urlToDownload.get(key);\n if (task == undefined) return;\n\n if (this.cache.existsFile(task.path)) {\n const toDelete = this.cache.removeFile(task.path, callerId);\n\n await Promise.all(\n toDelete.map(async (task: DownloadByUrlTask) => {\n await rmRFDir(task.path);\n this.cache.removeCache(task);\n\n this.removeTask(\n task,\n `the task ${stringifyWithResourceId(task.info())} was removed`\n + `from cache along with ${stringifyWithResourceId(toDelete.map((t) => t.info()))}`,\n );\n }),\n );\n } else {\n // The task is still in a downloading queue.\n const deleted = task.counter.dec(callerId);\n if (deleted)\n this.removeTask(\n task,\n `the task ${stringifyWithResourceId(task.info())} was removed from cache`,\n );\n }\n }\n\n /** Removes all files from a hard drive. */\n async releaseAll() {\n this.downloadQueue.stop();\n\n await Promise.all(\n Array.from(this.urlToDownload.entries()).map(async ([id, task]) => {\n await rmRFDir(task.path);\n this.cache.removeCache(task);\n\n this.removeTask(\n task,\n `the task ${stringifyWithResourceId(task.info())} was released when the driver was closed`,\n );\n }),\n );\n }\n\n private setNewTask(w: Watcher, url: URL, callerId: string) {\n const result = new DownloadByUrlTask(\n this.logger,\n this.getFilePath(url),\n url,\n this.signer,\n this.saveDir,\n );\n result.attach(w, callerId);\n this.urlToDownload.set(url.toString(), result);\n\n return result;\n }\n\n private removeTask(task: DownloadByUrlTask, reason: string) {\n task.abort(reason);\n task.change.markChanged(`task for url ${task.url} removed: ${reason}`);\n this.urlToDownload.delete(task.url.toString());\n }\n\n private getFilePath(url: URL): string {\n const sha256 = createHash('sha256').update(url.toString()).digest('hex');\n return path.join(this.saveDir, sha256);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAmDA;AACqC;MACxB,iBAAiB,CAAA;AAWT,IAAA,MAAA;AAEA,IAAA,OAAA;AACA,IAAA,MAAA;AACA,IAAA,IAAA;AAdF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