@milaboratories/pl-drivers 1.11.19 → 1.11.21
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 +5 -5
- package/dist/clients/constructors.cjs.map +1 -1
- package/dist/clients/constructors.js +5 -5
- package/dist/clients/constructors.js.map +1 -1
- package/dist/clients/download.cjs +29 -5
- package/dist/clients/download.cjs.map +1 -1
- package/dist/clients/download.d.ts +5 -4
- package/dist/clients/download.d.ts.map +1 -1
- package/dist/clients/download.js +30 -6
- package/dist/clients/download.js.map +1 -1
- package/dist/clients/logs.cjs +57 -16
- package/dist/clients/logs.cjs.map +1 -1
- package/dist/clients/logs.d.ts +6 -5
- package/dist/clients/logs.d.ts.map +1 -1
- package/dist/clients/logs.js +58 -17
- package/dist/clients/logs.js.map +1 -1
- package/dist/clients/ls_api.cjs +44 -8
- package/dist/clients/ls_api.cjs.map +1 -1
- package/dist/clients/ls_api.d.ts +4 -4
- package/dist/clients/ls_api.d.ts.map +1 -1
- package/dist/clients/ls_api.js +45 -9
- package/dist/clients/ls_api.js.map +1 -1
- package/dist/clients/progress.cjs +32 -29
- package/dist/clients/progress.cjs.map +1 -1
- package/dist/clients/progress.d.ts +5 -5
- package/dist/clients/progress.d.ts.map +1 -1
- package/dist/clients/progress.js +33 -30
- package/dist/clients/progress.js.map +1 -1
- package/dist/clients/upload.cjs +96 -30
- package/dist/clients/upload.cjs.map +1 -1
- package/dist/clients/upload.d.ts +8 -11
- package/dist/clients/upload.d.ts.map +1 -1
- package/dist/clients/upload.js +97 -31
- package/dist/clients/upload.js.map +1 -1
- package/dist/drivers/download_blob/download_blob.cjs +2 -2
- package/dist/drivers/download_blob/download_blob.cjs.map +1 -1
- package/dist/drivers/download_blob/download_blob.js +1 -1
- package/dist/drivers/download_blob/download_blob.js.map +1 -1
- package/dist/drivers/download_blob/download_blob_task.cjs +5 -5
- package/dist/drivers/download_blob/download_blob_task.cjs.map +1 -1
- package/dist/drivers/download_blob/download_blob_task.js +2 -2
- package/dist/drivers/download_blob/download_blob_task.js.map +1 -1
- package/dist/drivers/download_blob_url/task.cjs +5 -5
- package/dist/drivers/download_blob_url/task.cjs.map +1 -1
- package/dist/drivers/download_blob_url/task.js +2 -2
- package/dist/drivers/download_blob_url/task.js.map +1 -1
- package/dist/drivers/download_url/task.cjs +2 -2
- package/dist/drivers/download_url/task.cjs.map +1 -1
- package/dist/drivers/download_url/task.js +2 -2
- package/dist/drivers/download_url/task.js.map +1 -1
- package/dist/drivers/logs_stream.cjs.map +1 -1
- package/dist/drivers/logs_stream.js.map +1 -1
- package/dist/helpers/download.cjs +5 -24
- package/dist/helpers/download.cjs.map +1 -1
- package/dist/helpers/download.d.ts +0 -13
- package/dist/helpers/download.d.ts.map +1 -1
- package/dist/helpers/download.js +5 -21
- package/dist/helpers/download.js.map +1 -1
- package/dist/helpers/download_errors.cjs +43 -0
- package/dist/helpers/download_errors.cjs.map +1 -0
- package/dist/helpers/download_errors.d.ts +23 -0
- package/dist/helpers/download_errors.d.ts.map +1 -0
- package/dist/helpers/download_errors.js +36 -0
- package/dist/helpers/download_errors.js.map +1 -0
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs +2 -2
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js +2 -2
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs +2 -2
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js +2 -2
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs +3 -3
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js +3 -3
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs +6 -6
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js +6 -6
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs +84 -84
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts +16 -16
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts +118 -118
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js +76 -76
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js.map +1 -0
- package/dist/proto-grpc/google/api/http.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/google/protobuf/descriptor.d.ts +5 -149
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -0
- package/dist/proto-grpc/google/protobuf/duration.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/duration.js.map +1 -0
- package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -0
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -0
- package/dist/proto-rest/downloadapi.d.ts +105 -0
- package/dist/proto-rest/downloadapi.d.ts.map +1 -0
- package/dist/proto-rest/index.d.ts +17 -0
- package/dist/proto-rest/index.d.ts.map +1 -0
- package/dist/proto-rest/lsapi.d.ts +148 -0
- package/dist/proto-rest/lsapi.d.ts.map +1 -0
- package/dist/proto-rest/progressapi.d.ts +159 -0
- package/dist/proto-rest/progressapi.d.ts.map +1 -0
- package/dist/proto-rest/streamingapi.d.ts +469 -0
- package/dist/proto-rest/streamingapi.d.ts.map +1 -0
- package/dist/proto-rest/uploadapi.d.ts +355 -0
- package/dist/proto-rest/uploadapi.d.ts.map +1 -0
- package/package.json +12 -8
- package/src/clients/constructors.ts +11 -11
- package/src/clients/download.ts +34 -11
- package/src/clients/logs.ts +69 -21
- package/src/clients/ls_api.ts +58 -14
- package/src/clients/progress.ts +41 -44
- package/src/clients/upload.ts +117 -53
- package/src/drivers/download_blob/download_blob.ts +1 -1
- package/src/drivers/download_blob/download_blob_task.ts +2 -2
- package/src/drivers/download_blob_url/task.ts +2 -2
- package/src/drivers/download_url/task.ts +2 -2
- package/src/drivers/logs_stream.ts +1 -1
- package/src/drivers/upload.test.ts +6 -25
- package/src/helpers/download.ts +4 -26
- package/src/helpers/download_errors.ts +40 -0
- package/src/index.ts +1 -0
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.ts +1 -1
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.ts +2 -2
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.ts +1 -1
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.ts +2 -2
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.ts +1 -1
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.ts +3 -3
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.ts +1 -1
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.ts +6 -6
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.ts +21 -21
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.ts +159 -159
- package/src/{proto → proto-grpc}/google/api/http.ts +1 -1
- package/src/{proto → proto-grpc}/google/protobuf/descriptor.ts +9 -217
- package/src/{proto → proto-grpc}/google/protobuf/duration.ts +1 -1
- package/src/{proto → proto-grpc}/google/protobuf/timestamp.ts +1 -1
- package/src/proto-rest/downloadapi.ts +105 -0
- package/src/proto-rest/index.ts +28 -0
- package/src/proto-rest/lsapi.ts +148 -0
- package/src/proto-rest/progressapi.ts +159 -0
- package/src/proto-rest/streamingapi.ts +469 -0
- package/src/proto-rest/uploadapi.ts +355 -0
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts +0 -53
- 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.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs.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.client.js.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/downloadapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs.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.client.js.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/lsapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs.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.client.js.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/progressapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs.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.client.js.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/streamingapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs.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.client.js.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/controllers/shared/grpc/uploadapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +0 -329
- 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 +0 -5358
- 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 +0 -537
- 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 +0 -87
- 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 +0 -106
- 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 +0 -256
- 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 +0 -181
- 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.cjs.map +0 -1
- package/dist/proto/google/protobuf/duration.d.ts.map +0 -1
- package/dist/proto/google/protobuf/duration.js.map +0 -1
- package/dist/proto/google/protobuf/empty.d.ts +0 -32
- package/dist/proto/google/protobuf/empty.d.ts.map +0 -1
- package/dist/proto/google/protobuf/struct.d.ts +0 -187
- package/dist/proto/google/protobuf/struct.d.ts.map +0 -1
- package/dist/proto/google/protobuf/timestamp.cjs.map +0 -1
- package/dist/proto/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/proto/google/protobuf/wrappers.d.ts +0 -335
- package/dist/proto/google/protobuf/wrappers.d.ts.map +0 -1
- package/src/proto/github.com/googleapis/googleapis/google/rpc/status.ts +0 -125
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.ts +0 -406
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/api.ts +0 -14986
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.ts +0 -1474
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.ts +0 -181
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/import.ts +0 -251
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.ts +0 -693
- package/src/proto/google/protobuf/any.ts +0 -326
- package/src/proto/google/protobuf/empty.ts +0 -94
- package/src/proto/google/protobuf/struct.ts +0 -484
- package/src/proto/google/protobuf/wrappers.ts +0 -785
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/google/api/http.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/duration.cjs +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/duration.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/duration.js +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/timestamp.cjs +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/timestamp.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/timestamp.js +0 -0
|
@@ -9,31 +9,31 @@ var ls_api = require('./ls_api.cjs');
|
|
|
9
9
|
function createDownloadClient(logger, client, localProjections) {
|
|
10
10
|
return client.getDriver({
|
|
11
11
|
name: 'DownloadBlob',
|
|
12
|
-
init: (_,
|
|
12
|
+
init: (_, wireClientFactory, httpDispatcher) => new download.ClientDownload(wireClientFactory, httpDispatcher, logger, localProjections),
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
function createLogsClient(client, logger) {
|
|
16
16
|
return client.getDriver({
|
|
17
17
|
name: 'StreamLogs',
|
|
18
|
-
init: (_,
|
|
18
|
+
init: (_, wireClientFactory, httpDispatcher) => new logs.ClientLogs(wireClientFactory, httpDispatcher, logger),
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
function createUploadProgressClient(client, logger) {
|
|
22
22
|
return client.getDriver({
|
|
23
23
|
name: 'UploadProgress',
|
|
24
|
-
init: (_,
|
|
24
|
+
init: (_, wireClientFactory, httpDispatcher) => new progress.ClientProgress(wireClientFactory, httpDispatcher, client, logger),
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
function createUploadBlobClient(client, logger) {
|
|
28
28
|
return client.getDriver({
|
|
29
29
|
name: 'UploadBlob',
|
|
30
|
-
init: (_,
|
|
30
|
+
init: (_, wireClientFactory, httpDispatcher) => new upload.ClientUpload(wireClientFactory, httpDispatcher, client, logger),
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
function createLsFilesClient(client, logger) {
|
|
34
34
|
return client.getDriver({
|
|
35
35
|
name: 'LsFiles',
|
|
36
|
-
init: (_client,
|
|
36
|
+
init: (_client, wireClientFactory, _httpDispatcher) => new ls_api.ClientLs(wireClientFactory, logger),
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constructors.cjs","sources":["../../src/clients/constructors.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"constructors.cjs","sources":["../../src/clients/constructors.ts"],"sourcesContent":["import type { WireClientProviderFactory, PlClient } from '@milaboratories/pl-client';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport type { Dispatcher } from 'undici';\nimport { ClientDownload } from './download';\nimport { ClientLogs } from './logs';\nimport { ClientProgress } from './progress';\nimport { ClientUpload } from './upload';\nimport { ClientLs } from './ls_api';\nimport type { LocalStorageProjection } from '../drivers/types';\n\nexport function createDownloadClient(\n logger: MiLogger,\n client: PlClient,\n localProjections: LocalStorageProjection[],\n) {\n return client.getDriver({\n name: 'DownloadBlob',\n init: (_: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher) =>\n new ClientDownload(wireClientFactory, httpDispatcher, logger, localProjections),\n });\n}\n\nexport function createLogsClient(client: PlClient, logger: MiLogger) {\n return client.getDriver({\n name: 'StreamLogs',\n init: (_: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher) =>\n new ClientLogs(wireClientFactory, httpDispatcher, logger),\n });\n}\n\nexport function createUploadProgressClient(client: PlClient, logger: MiLogger) {\n return client.getDriver({\n name: 'UploadProgress',\n init: (_: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher) =>\n new ClientProgress(wireClientFactory, httpDispatcher, client, logger),\n });\n}\n\nexport function createUploadBlobClient(client: PlClient, logger: MiLogger) {\n return client.getDriver({\n name: 'UploadBlob',\n init: (_: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher) =>\n new ClientUpload(wireClientFactory, httpDispatcher, client, logger),\n });\n}\n\nexport function createLsFilesClient(client: PlClient, logger: MiLogger) {\n return client.getDriver({\n name: 'LsFiles',\n init: (_client: PlClient, wireClientFactory: WireClientProviderFactory, _httpDispatcher: Dispatcher) =>\n new ClientLs(wireClientFactory, logger),\n });\n}\n"],"names":["ClientDownload","ClientLogs","ClientProgress","ClientUpload","ClientLs"],"mappings":";;;;;;;;SAUgB,oBAAoB,CAClC,MAAgB,EAChB,MAAgB,EAChB,gBAA0C,EAAA;IAE1C,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,CAAC,CAAW,EAAE,iBAA4C,EAAE,cAA0B,KAC1F,IAAIA,uBAAc,CAAC,iBAAiB,EAAE,cAAc,EAAE,MAAM,EAAE,gBAAgB,CAAC;AAClF,KAAA,CAAC;AACJ;AAEM,SAAU,gBAAgB,CAAC,MAAgB,EAAE,MAAgB,EAAA;IACjE,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,YAAY;AAClB,QAAA,IAAI,EAAE,CAAC,CAAW,EAAE,iBAA4C,EAAE,cAA0B,KAC1F,IAAIC,eAAU,CAAC,iBAAiB,EAAE,cAAc,EAAE,MAAM,CAAC;AAC5D,KAAA,CAAC;AACJ;AAEM,SAAU,0BAA0B,CAAC,MAAgB,EAAE,MAAgB,EAAA;IAC3E,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,CAAC,CAAW,EAAE,iBAA4C,EAAE,cAA0B,KAC1F,IAAIC,uBAAc,CAAC,iBAAiB,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC;AACxE,KAAA,CAAC;AACJ;AAEM,SAAU,sBAAsB,CAAC,MAAgB,EAAE,MAAgB,EAAA;IACvE,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,CAAC,CAAW,EAAE,iBAA4C,EAAE,cAA0B,KAC1F,IAAIC,mBAAY,CAAC,iBAAiB,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC;AACtE,KAAA,CAAC;AACJ;AAEM,SAAU,mBAAmB,CAAC,MAAgB,EAAE,MAAgB,EAAA;IACpE,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,IAAI,EAAE,CAAC,OAAiB,EAAE,iBAA4C,EAAE,eAA2B,KACjG,IAAIC,eAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;AAC1C,KAAA,CAAC;AACJ;;;;;;;;"}
|
|
@@ -7,31 +7,31 @@ import { ClientLs } from './ls_api.js';
|
|
|
7
7
|
function createDownloadClient(logger, client, localProjections) {
|
|
8
8
|
return client.getDriver({
|
|
9
9
|
name: 'DownloadBlob',
|
|
10
|
-
init: (_,
|
|
10
|
+
init: (_, wireClientFactory, httpDispatcher) => new ClientDownload(wireClientFactory, httpDispatcher, logger, localProjections),
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
function createLogsClient(client, logger) {
|
|
14
14
|
return client.getDriver({
|
|
15
15
|
name: 'StreamLogs',
|
|
16
|
-
init: (_,
|
|
16
|
+
init: (_, wireClientFactory, httpDispatcher) => new ClientLogs(wireClientFactory, httpDispatcher, logger),
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
function createUploadProgressClient(client, logger) {
|
|
20
20
|
return client.getDriver({
|
|
21
21
|
name: 'UploadProgress',
|
|
22
|
-
init: (_,
|
|
22
|
+
init: (_, wireClientFactory, httpDispatcher) => new ClientProgress(wireClientFactory, httpDispatcher, client, logger),
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
function createUploadBlobClient(client, logger) {
|
|
26
26
|
return client.getDriver({
|
|
27
27
|
name: 'UploadBlob',
|
|
28
|
-
init: (_,
|
|
28
|
+
init: (_, wireClientFactory, httpDispatcher) => new ClientUpload(wireClientFactory, httpDispatcher, client, logger),
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
function createLsFilesClient(client, logger) {
|
|
32
32
|
return client.getDriver({
|
|
33
33
|
name: 'LsFiles',
|
|
34
|
-
init: (_client,
|
|
34
|
+
init: (_client, wireClientFactory, _httpDispatcher) => new ClientLs(wireClientFactory, logger),
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constructors.js","sources":["../../src/clients/constructors.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"constructors.js","sources":["../../src/clients/constructors.ts"],"sourcesContent":["import type { WireClientProviderFactory, PlClient } from '@milaboratories/pl-client';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport type { Dispatcher } from 'undici';\nimport { ClientDownload } from './download';\nimport { ClientLogs } from './logs';\nimport { ClientProgress } from './progress';\nimport { ClientUpload } from './upload';\nimport { ClientLs } from './ls_api';\nimport type { LocalStorageProjection } from '../drivers/types';\n\nexport function createDownloadClient(\n logger: MiLogger,\n client: PlClient,\n localProjections: LocalStorageProjection[],\n) {\n return client.getDriver({\n name: 'DownloadBlob',\n init: (_: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher) =>\n new ClientDownload(wireClientFactory, httpDispatcher, logger, localProjections),\n });\n}\n\nexport function createLogsClient(client: PlClient, logger: MiLogger) {\n return client.getDriver({\n name: 'StreamLogs',\n init: (_: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher) =>\n new ClientLogs(wireClientFactory, httpDispatcher, logger),\n });\n}\n\nexport function createUploadProgressClient(client: PlClient, logger: MiLogger) {\n return client.getDriver({\n name: 'UploadProgress',\n init: (_: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher) =>\n new ClientProgress(wireClientFactory, httpDispatcher, client, logger),\n });\n}\n\nexport function createUploadBlobClient(client: PlClient, logger: MiLogger) {\n return client.getDriver({\n name: 'UploadBlob',\n init: (_: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher) =>\n new ClientUpload(wireClientFactory, httpDispatcher, client, logger),\n });\n}\n\nexport function createLsFilesClient(client: PlClient, logger: MiLogger) {\n return client.getDriver({\n name: 'LsFiles',\n init: (_client: PlClient, wireClientFactory: WireClientProviderFactory, _httpDispatcher: Dispatcher) =>\n new ClientLs(wireClientFactory, logger),\n });\n}\n"],"names":[],"mappings":";;;;;;SAUgB,oBAAoB,CAClC,MAAgB,EAChB,MAAgB,EAChB,gBAA0C,EAAA;IAE1C,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,CAAC,CAAW,EAAE,iBAA4C,EAAE,cAA0B,KAC1F,IAAI,cAAc,CAAC,iBAAiB,EAAE,cAAc,EAAE,MAAM,EAAE,gBAAgB,CAAC;AAClF,KAAA,CAAC;AACJ;AAEM,SAAU,gBAAgB,CAAC,MAAgB,EAAE,MAAgB,EAAA;IACjE,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,YAAY;AAClB,QAAA,IAAI,EAAE,CAAC,CAAW,EAAE,iBAA4C,EAAE,cAA0B,KAC1F,IAAI,UAAU,CAAC,iBAAiB,EAAE,cAAc,EAAE,MAAM,CAAC;AAC5D,KAAA,CAAC;AACJ;AAEM,SAAU,0BAA0B,CAAC,MAAgB,EAAE,MAAgB,EAAA;IAC3E,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,CAAC,CAAW,EAAE,iBAA4C,EAAE,cAA0B,KAC1F,IAAI,cAAc,CAAC,iBAAiB,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC;AACxE,KAAA,CAAC;AACJ;AAEM,SAAU,sBAAsB,CAAC,MAAgB,EAAE,MAAgB,EAAA;IACvE,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,CAAC,CAAW,EAAE,iBAA4C,EAAE,cAA0B,KAC1F,IAAI,YAAY,CAAC,iBAAiB,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC;AACtE,KAAA,CAAC;AACJ;AAEM,SAAU,mBAAmB,CAAC,MAAgB,EAAE,MAAgB,EAAA;IACpE,OAAO,MAAM,CAAC,SAAS,CAAC;AACtB,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,IAAI,EAAE,CAAC,OAAiB,EAAE,iBAA4C,EAAE,eAA2B,KACjG,IAAI,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;AAC1C,KAAA,CAAC;AACJ;;;;"}
|
|
@@ -9,7 +9,7 @@ var path = require('node:path');
|
|
|
9
9
|
var node_stream = require('node:stream');
|
|
10
10
|
var download = require('../helpers/download.cjs');
|
|
11
11
|
var validate = require('../helpers/validate.cjs');
|
|
12
|
-
var protocol_client = require('../proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs');
|
|
12
|
+
var protocol_client = require('../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs');
|
|
13
13
|
|
|
14
14
|
function _interopNamespaceDefault(e) {
|
|
15
15
|
var n = Object.create(null);
|
|
@@ -37,18 +37,30 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
|
37
37
|
class ClientDownload {
|
|
38
38
|
httpClient;
|
|
39
39
|
logger;
|
|
40
|
-
|
|
40
|
+
wire;
|
|
41
41
|
remoteFileDownloader;
|
|
42
42
|
/** Helps to find a storage root directory by a storage id from URL scheme. */
|
|
43
43
|
localStorageIdsToRoot;
|
|
44
44
|
/** Concurrency limiter for local file reads - limit to 32 parallel reads */
|
|
45
45
|
localFileReadLimiter = new tsHelpers.ConcurrencyLimitingExecutor(32);
|
|
46
|
-
constructor(
|
|
46
|
+
constructor(wireClientProviderFactory, httpClient, logger,
|
|
47
47
|
/** Pl storages available locally */
|
|
48
48
|
localProjections) {
|
|
49
49
|
this.httpClient = httpClient;
|
|
50
50
|
this.logger = logger;
|
|
51
|
-
this.
|
|
51
|
+
this.wire = wireClientProviderFactory.createWireClientProvider((wireConn) => {
|
|
52
|
+
if (wireConn.type === 'grpc') {
|
|
53
|
+
return new protocol_client.DownloadClient(wireConn.Transport);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return plClient.RestAPI.createClient({
|
|
57
|
+
hostAndPort: wireConn.Config.hostAndPort,
|
|
58
|
+
ssl: wireConn.Config.ssl,
|
|
59
|
+
dispatcher: wireConn.Dispatcher,
|
|
60
|
+
middlewares: wireConn.Middlewares,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
52
64
|
this.remoteFileDownloader = new download.RemoteFileDownloader(httpClient);
|
|
53
65
|
this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);
|
|
54
66
|
}
|
|
@@ -104,7 +116,19 @@ class ClientDownload {
|
|
|
104
116
|
async grpcGetDownloadUrl({ id, type }, options, signal) {
|
|
105
117
|
const withAbort = options ?? {};
|
|
106
118
|
withAbort.abort = signal;
|
|
107
|
-
|
|
119
|
+
const client = this.wire.get();
|
|
120
|
+
if (client instanceof protocol_client.DownloadClient) {
|
|
121
|
+
return await client.getDownloadURL({ resourceId: id, isInternalUse: false }, plClient.addRTypeToMetadata(type, withAbort)).response;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return (await client.POST('/v1/get-download-url', {
|
|
125
|
+
body: {
|
|
126
|
+
resourceId: id.toString(),
|
|
127
|
+
isInternalUse: false,
|
|
128
|
+
},
|
|
129
|
+
headers: { ...plClient.createRTypeRoutingHeader(type) },
|
|
130
|
+
})).data;
|
|
131
|
+
}
|
|
108
132
|
}
|
|
109
133
|
}
|
|
110
134
|
function parseLocalUrl(url) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.cjs","sources":["../../src/clients/download.ts"],"sourcesContent":["/* eslint-disable n/no-unsupported-features/node-builtins */\nimport type { GrpcClientProvider, GrpcClientProviderFactory } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata, stringifyWithResourceId } from '@milaboratories/pl-client';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\nimport { PerfTimer } from '@milaboratories/helpers';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport { ConcurrencyLimitingExecutor } from '@milaboratories/ts-helpers';\nimport type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { Readable } from 'node:stream';\nimport type { Dispatcher } from 'undici';\nimport type { LocalStorageProjection } from '../drivers/types';\nimport { type ContentHandler, RemoteFileDownloader } from '../helpers/download';\nimport { validateAbsolute } from '../helpers/validate';\nimport type { DownloadAPI_GetDownloadURL_Response } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol';\nimport { DownloadClient } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client';\nimport { type GetContentOptions } from '@milaboratories/pl-model-common';\n\n/** Gets URLs for downloading from pl-core, parses them and reads or downloads\n * files locally and from the web. */\nexport class ClientDownload {\n public readonly grpcClient: GrpcClientProvider<DownloadClient>;\n private readonly remoteFileDownloader: RemoteFileDownloader;\n\n /** Helps to find a storage root directory by a storage id from URL scheme. */\n private readonly localStorageIdsToRoot: Map<string, string>;\n\n /** Concurrency limiter for local file reads - limit to 32 parallel reads */\n private readonly localFileReadLimiter = new ConcurrencyLimitingExecutor(32);\n\n constructor(\n grpcClientProviderFactory: GrpcClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n /** Pl storages available locally */\n localProjections: LocalStorageProjection[],\n ) {\n this.grpcClient = grpcClientProviderFactory.createGrpcClientProvider((transport) => new DownloadClient(transport));\n this.remoteFileDownloader = new RemoteFileDownloader(httpClient);\n this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);\n }\n\n close() {}\n\n /**\n * Gets a presign URL and downloads the file.\n * An optional range with 2 numbers from what byte and to what byte to download can be provided.\n * @param fromBytes - from byte including this byte\n * @param toBytes - to byte excluding this byte\n */\n async withBlobContent<T>(\n info: ResourceInfo,\n options: RpcOptions | undefined,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, ops.signal);\n\n const remoteHeaders = Object.fromEntries(headers.map(({ name, value }) => [name, value]));\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download started, `\n + `url: ${downloadUrl}, `\n + `range: ${JSON.stringify(ops.range ?? null)}`,\n );\n\n const timer = PerfTimer.start();\n const result = isLocal(downloadUrl)\n ? await this.withLocalFileContent(downloadUrl, ops, handler)\n : await this.remoteFileDownloader.withContent(downloadUrl, remoteHeaders, ops, handler);\n\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download finished, `\n + `took: ${timer.elapsed()}`,\n );\n return result;\n }\n\n async withLocalFileContent<T>(\n url: string,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { storageId, relativePath } = parseLocalUrl(url);\n const fullPath = getFullPath(storageId, this.localStorageIdsToRoot, relativePath);\n\n return await this.localFileReadLimiter.run(async () => {\n const readOps = {\n start: ops.range?.from,\n end: ops.range?.to !== undefined ? ops.range.to - 1 : undefined,\n signal: ops.signal,\n };\n let stream: fs.ReadStream | undefined;\n let handlerSuccess = false;\n\n try {\n const stat = await fsp.stat(fullPath);\n stream = fs.createReadStream(fullPath, readOps);\n const webStream = Readable.toWeb(stream);\n\n const result = await handler(webStream, stat.size);\n handlerSuccess = true;\n return result;\n } catch (error) {\n // Cleanup on error (including handler errors)\n if (!handlerSuccess && stream && !stream.destroyed) {\n stream.destroy();\n }\n throw error;\n }\n });\n }\n\n private async grpcGetDownloadUrl(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n signal?: AbortSignal,\n ): Promise<DownloadAPI_GetDownloadURL_Response> {\n const withAbort = options ?? {};\n withAbort.abort = signal;\n\n return await this.grpcClient.get().getDownloadURL(\n { resourceId: id, isInternalUse: false },\n addRTypeToMetadata(type, withAbort),\n ).response;\n }\n}\n\nexport function parseLocalUrl(url: string) {\n const parsed = new URL(url);\n if (parsed.pathname == '')\n throw new WrongLocalFileUrl(`url for local filepath ${url} does not match url scheme`);\n\n return {\n storageId: parsed.host,\n relativePath: decodeURIComponent(parsed.pathname.slice(1)),\n };\n}\n\nexport function getFullPath(\n storageId: string,\n localStorageIdsToRoot: Map<string, string>,\n relativePath: string,\n) {\n const root = localStorageIdsToRoot.get(storageId);\n if (root === undefined) throw new UnknownStorageError(`Unknown storage location: ${storageId}`);\n\n if (root === '') return relativePath;\n\n return path.join(root, relativePath);\n}\n\nconst storageProtocol = 'storage://';\nfunction isLocal(url: string) {\n return url.startsWith(storageProtocol);\n}\n\n/** Throws when a local URL have invalid scheme. */\nexport class WrongLocalFileUrl extends Error {\n name = 'WrongLocalFileUrl';\n}\n\n/** Happens when a storage for a local file can't be found. */\nexport class UnknownStorageError extends Error {\n name = 'UnknownStorageError';\n}\n\nexport function newLocalStorageIdsToRoot(projections: LocalStorageProjection[]) {\n const idToRoot: Map<string, string> = new Map();\n for (const lp of projections) {\n // Empty string means no prefix, i.e. any file on this machine can be got from the storage.\n if (lp.localPath !== '') {\n validateAbsolute(lp.localPath);\n }\n idToRoot.set(lp.storageId, lp.localPath);\n }\n\n return idToRoot;\n}\n"],"names":["ConcurrencyLimitingExecutor","DownloadClient","RemoteFileDownloader","stringifyWithResourceId","PerfTimer","fsp","fs","Readable","addRTypeToMetadata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CAAC,CAAC;KAC3D;AACH;SAEgB,WAAW,CACzB,SAAiB,EACjB,qBAA0C,EAC1C,YAAoB,EAAA;IAEpB,MAAM,IAAI,GAAG,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC;IACjD,IAAI,IAAI,KAAK,SAAS;AAAE,QAAA,MAAM,IAAI,mBAAmB,CAAC,6BAA6B,SAAS,CAAA,CAAE,CAAC;IAE/F,IAAI,IAAI,KAAK,EAAE;AAAE,QAAA,OAAO,YAAY;IAEpC,OAAOC,eAAI,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC;AACtC;AAEA,MAAM,eAAe,GAAG,YAAY;AACpC,SAAS,OAAO,CAAC,GAAW,EAAA;AAC1B,IAAA,OAAO,GAAG,CAAC,UAAU,CAAC,eAAe,CAAC;AACxC;AAEA;AACM,MAAO,iBAAkB,SAAQ,KAAK,CAAA;IAC1C,IAAI,GAAG,mBAAmB;AAC3B;AAED;AACM,MAAO,mBAAoB,SAAQ,KAAK,CAAA;IAC5C,IAAI,GAAG,qBAAqB;AAC7B;AAEK,SAAU,wBAAwB,CAAC,WAAqC,EAAA;AAC5E,IAAA,MAAM,QAAQ,GAAwB,IAAI,GAAG,EAAE;AAC/C,IAAA,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE;;AAE5B,QAAA,IAAI,EAAE,CAAC,SAAS,KAAK,EAAE,EAAE;AACvB,YAAAC,yBAAgB,CAAC,EAAE,CAAC,SAAS,CAAC;QAChC;QACA,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC;IAC1C;AAEA,IAAA,OAAO,QAAQ;AACjB;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"download.cjs","sources":["../../src/clients/download.ts"],"sourcesContent":["/* eslint-disable n/no-unsupported-features/node-builtins */\nimport type { WireClientProvider, WireClientProviderFactory } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata, stringifyWithResourceId, RestAPI, createRTypeRoutingHeader } from '@milaboratories/pl-client';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\nimport { PerfTimer } from '@milaboratories/helpers';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport { ConcurrencyLimitingExecutor } from '@milaboratories/ts-helpers';\nimport type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { Readable } from 'node:stream';\nimport type { Dispatcher } from 'undici';\nimport type { LocalStorageProjection } from '../drivers/types';\nimport { type ContentHandler, RemoteFileDownloader } from '../helpers/download';\nimport { validateAbsolute } from '../helpers/validate';\nimport type { DownloadAPI_GetDownloadURL_Response } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol';\nimport { DownloadClient } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client';\nimport type { DownloadApiPaths, DownloadRestClientType } from '../proto-rest';\nimport { type GetContentOptions } from '@milaboratories/pl-model-common';\n\n/** Gets URLs for downloading from pl-core, parses them and reads or downloads\n * files locally and from the web. */\nexport class ClientDownload {\n public readonly wire: WireClientProvider<DownloadRestClientType | DownloadClient>;\n private readonly remoteFileDownloader: RemoteFileDownloader;\n\n /** Helps to find a storage root directory by a storage id from URL scheme. */\n private readonly localStorageIdsToRoot: Map<string, string>;\n\n /** Concurrency limiter for local file reads - limit to 32 parallel reads */\n private readonly localFileReadLimiter = new ConcurrencyLimitingExecutor(32);\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n /** Pl storages available locally */\n localProjections: LocalStorageProjection[],\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wireConn) => {\n if (wireConn.type === 'grpc') {\n return new DownloadClient(wireConn.Transport);\n } else {\n return RestAPI.createClient<DownloadApiPaths>({\n hostAndPort: wireConn.Config.hostAndPort,\n ssl: wireConn.Config.ssl,\n dispatcher: wireConn.Dispatcher,\n middlewares: wireConn.Middlewares,\n });\n }\n });\n this.remoteFileDownloader = new RemoteFileDownloader(httpClient);\n this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);\n }\n\n close() {}\n\n /**\n * Gets a presign URL and downloads the file.\n * An optional range with 2 numbers from what byte and to what byte to download can be provided.\n * @param fromBytes - from byte including this byte\n * @param toBytes - to byte excluding this byte\n */\n async withBlobContent<T>(\n info: ResourceInfo,\n options: RpcOptions | undefined,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, ops.signal);\n\n const remoteHeaders = Object.fromEntries(headers.map(({ name, value }) => [name, value]));\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download started, `\n + `url: ${downloadUrl}, `\n + `range: ${JSON.stringify(ops.range ?? null)}`,\n );\n\n const timer = PerfTimer.start();\n const result = isLocal(downloadUrl)\n ? await this.withLocalFileContent(downloadUrl, ops, handler)\n : await this.remoteFileDownloader.withContent(downloadUrl, remoteHeaders, ops, handler);\n\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download finished, `\n + `took: ${timer.elapsed()}`,\n );\n return result;\n }\n\n async withLocalFileContent<T>(\n url: string,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { storageId, relativePath } = parseLocalUrl(url);\n const fullPath = getFullPath(storageId, this.localStorageIdsToRoot, relativePath);\n\n return await this.localFileReadLimiter.run(async () => {\n const readOps = {\n start: ops.range?.from,\n end: ops.range?.to !== undefined ? ops.range.to - 1 : undefined,\n signal: ops.signal,\n };\n let stream: fs.ReadStream | undefined;\n let handlerSuccess = false;\n\n try {\n const stat = await fsp.stat(fullPath);\n stream = fs.createReadStream(fullPath, readOps);\n const webStream = Readable.toWeb(stream);\n\n const result = await handler(webStream, stat.size);\n handlerSuccess = true;\n return result;\n } catch (error) {\n // Cleanup on error (including handler errors)\n if (!handlerSuccess && stream && !stream.destroyed) {\n stream.destroy();\n }\n throw error;\n }\n });\n }\n\n private async grpcGetDownloadUrl(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n signal?: AbortSignal,\n ): Promise<DownloadAPI_GetDownloadURL_Response> {\n const withAbort = options ?? {};\n withAbort.abort = signal;\n\n const client = this.wire.get();\n if (client instanceof DownloadClient) {\n return await client.getDownloadURL(\n { resourceId: id, isInternalUse: false },\n addRTypeToMetadata(type, withAbort),\n ).response;\n } else {\n return (await client.POST('/v1/get-download-url', {\n body: {\n resourceId: id.toString(),\n isInternalUse: false,\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })).data!;\n }\n }\n}\n\nexport function parseLocalUrl(url: string) {\n const parsed = new URL(url);\n if (parsed.pathname == '')\n throw new WrongLocalFileUrl(`url for local filepath ${url} does not match url scheme`);\n\n return {\n storageId: parsed.host,\n relativePath: decodeURIComponent(parsed.pathname.slice(1)),\n };\n}\n\nexport function getFullPath(\n storageId: string,\n localStorageIdsToRoot: Map<string, string>,\n relativePath: string,\n) {\n const root = localStorageIdsToRoot.get(storageId);\n if (root === undefined) throw new UnknownStorageError(`Unknown storage location: ${storageId}`);\n\n if (root === '') return relativePath;\n\n return path.join(root, relativePath);\n}\n\nconst storageProtocol = 'storage://';\nfunction isLocal(url: string) {\n return url.startsWith(storageProtocol);\n}\n\n/** Throws when a local URL have invalid scheme. */\nexport class WrongLocalFileUrl extends Error {\n name = 'WrongLocalFileUrl';\n}\n\n/** Happens when a storage for a local file can't be found. */\nexport class UnknownStorageError extends Error {\n name = 'UnknownStorageError';\n}\n\nexport function newLocalStorageIdsToRoot(projections: LocalStorageProjection[]) {\n const idToRoot: Map<string, string> = new Map();\n for (const lp of projections) {\n // Empty string means no prefix, i.e. any file on this machine can be got from the storage.\n if (lp.localPath !== '') {\n validateAbsolute(lp.localPath);\n }\n idToRoot.set(lp.storageId, lp.localPath);\n }\n\n return idToRoot;\n}\n"],"names":["ConcurrencyLimitingExecutor","DownloadClient","RestAPI","Remote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O,CAAC,GAAW,EAAA;AAC1B,IAAA,OAAO,GAAG,CAAC,UAAU,CAAC,eAAe,CAAC;AACxC;AAEA;AACM,MAAO,iBAAkB,SAAQ,KAAK,CAAA;IAC1C,IAAI,GAAG,mBAAmB;AAC3B;AAED;AACM,MAAO,mBAAoB,SAAQ,KAAK,CAAA;IAC5C,IAAI,GAAG,qBAAqB;AAC7B;AAEK,SAAU,wBAAwB,CAAC,WAAqC,EAAA;AAC5E,IAAA,MAAM,QAAQ,GAAwB,IAAI,GAAG,EAAE;AAC/C,IAAA,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE;;AAE5B,QAAA,IAAI,EAAE,CAAC,SAAS,KAAK,EAAE,EAAE;AACvB,YAAAC,yBAAgB,CAAC,EAAE,CAAC,SAAS,CAAC;QAChC;QACA,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC;IAC1C;AAEA,IAAA,OAAO,QAAQ;AACjB;;;;;;;;;"}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WireClientProvider, WireClientProviderFactory } from '@milaboratories/pl-client';
|
|
2
2
|
import type { ResourceInfo } from '@milaboratories/pl-tree';
|
|
3
3
|
import type { MiLogger } from '@milaboratories/ts-helpers';
|
|
4
4
|
import type { RpcOptions } from '@protobuf-ts/runtime-rpc';
|
|
5
5
|
import type { Dispatcher } from 'undici';
|
|
6
6
|
import type { LocalStorageProjection } from '../drivers/types';
|
|
7
7
|
import { type ContentHandler } from '../helpers/download';
|
|
8
|
-
import { DownloadClient } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client';
|
|
8
|
+
import { DownloadClient } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client';
|
|
9
|
+
import type { DownloadRestClientType } from '../proto-rest';
|
|
9
10
|
import { type GetContentOptions } from '@milaboratories/pl-model-common';
|
|
10
11
|
/** Gets URLs for downloading from pl-core, parses them and reads or downloads
|
|
11
12
|
* files locally and from the web. */
|
|
12
13
|
export declare class ClientDownload {
|
|
13
14
|
readonly httpClient: Dispatcher;
|
|
14
15
|
readonly logger: MiLogger;
|
|
15
|
-
readonly
|
|
16
|
+
readonly wire: WireClientProvider<DownloadRestClientType | DownloadClient>;
|
|
16
17
|
private readonly remoteFileDownloader;
|
|
17
18
|
/** Helps to find a storage root directory by a storage id from URL scheme. */
|
|
18
19
|
private readonly localStorageIdsToRoot;
|
|
19
20
|
/** Concurrency limiter for local file reads - limit to 32 parallel reads */
|
|
20
21
|
private readonly localFileReadLimiter;
|
|
21
|
-
constructor(
|
|
22
|
+
constructor(wireClientProviderFactory: WireClientProviderFactory, httpClient: Dispatcher, logger: MiLogger,
|
|
22
23
|
/** Pl storages available locally */
|
|
23
24
|
localProjections: LocalStorageProjection[]);
|
|
24
25
|
close(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/clients/download.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAE/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAK3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAGhF,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/clients/download.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,yBAAy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BAAoB,CAAC,CAAC,EAC1B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,CAAC,CAAC;YA+BC,kBAAkB;CAwBjC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM;;;EASxC;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,MAAM,EACjB,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1C,YAAY,EAAE,MAAM,UAQrB;AAOD,mDAAmD;AACnD,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,IAAI,SAAuB;CAC5B;AAED,+DAA+D;AAC/D,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,IAAI,SAAyB;CAC9B;AAED,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,sBAAsB,EAAE,uBAW7E"}
|
package/dist/clients/download.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { stringifyWithResourceId, addRTypeToMetadata } from '@milaboratories/pl-client';
|
|
1
|
+
import { RestAPI, stringifyWithResourceId, addRTypeToMetadata, createRTypeRoutingHeader } from '@milaboratories/pl-client';
|
|
2
2
|
import { PerfTimer } from '@milaboratories/helpers';
|
|
3
3
|
import { ConcurrencyLimitingExecutor } from '@milaboratories/ts-helpers';
|
|
4
4
|
import * as fs from 'node:fs';
|
|
@@ -7,25 +7,37 @@ import * as path from 'node:path';
|
|
|
7
7
|
import { Readable } from 'node:stream';
|
|
8
8
|
import { RemoteFileDownloader } from '../helpers/download.js';
|
|
9
9
|
import { validateAbsolute } from '../helpers/validate.js';
|
|
10
|
-
import { DownloadClient } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js';
|
|
10
|
+
import { DownloadClient } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js';
|
|
11
11
|
|
|
12
12
|
/** Gets URLs for downloading from pl-core, parses them and reads or downloads
|
|
13
13
|
* files locally and from the web. */
|
|
14
14
|
class ClientDownload {
|
|
15
15
|
httpClient;
|
|
16
16
|
logger;
|
|
17
|
-
|
|
17
|
+
wire;
|
|
18
18
|
remoteFileDownloader;
|
|
19
19
|
/** Helps to find a storage root directory by a storage id from URL scheme. */
|
|
20
20
|
localStorageIdsToRoot;
|
|
21
21
|
/** Concurrency limiter for local file reads - limit to 32 parallel reads */
|
|
22
22
|
localFileReadLimiter = new ConcurrencyLimitingExecutor(32);
|
|
23
|
-
constructor(
|
|
23
|
+
constructor(wireClientProviderFactory, httpClient, logger,
|
|
24
24
|
/** Pl storages available locally */
|
|
25
25
|
localProjections) {
|
|
26
26
|
this.httpClient = httpClient;
|
|
27
27
|
this.logger = logger;
|
|
28
|
-
this.
|
|
28
|
+
this.wire = wireClientProviderFactory.createWireClientProvider((wireConn) => {
|
|
29
|
+
if (wireConn.type === 'grpc') {
|
|
30
|
+
return new DownloadClient(wireConn.Transport);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return RestAPI.createClient({
|
|
34
|
+
hostAndPort: wireConn.Config.hostAndPort,
|
|
35
|
+
ssl: wireConn.Config.ssl,
|
|
36
|
+
dispatcher: wireConn.Dispatcher,
|
|
37
|
+
middlewares: wireConn.Middlewares,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
29
41
|
this.remoteFileDownloader = new RemoteFileDownloader(httpClient);
|
|
30
42
|
this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);
|
|
31
43
|
}
|
|
@@ -81,7 +93,19 @@ class ClientDownload {
|
|
|
81
93
|
async grpcGetDownloadUrl({ id, type }, options, signal) {
|
|
82
94
|
const withAbort = options ?? {};
|
|
83
95
|
withAbort.abort = signal;
|
|
84
|
-
|
|
96
|
+
const client = this.wire.get();
|
|
97
|
+
if (client instanceof DownloadClient) {
|
|
98
|
+
return await client.getDownloadURL({ resourceId: id, isInternalUse: false }, addRTypeToMetadata(type, withAbort)).response;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return (await client.POST('/v1/get-download-url', {
|
|
102
|
+
body: {
|
|
103
|
+
resourceId: id.toString(),
|
|
104
|
+
isInternalUse: false,
|
|
105
|
+
},
|
|
106
|
+
headers: { ...createRTypeRoutingHeader(type) },
|
|
107
|
+
})).data;
|
|
108
|
+
}
|
|
85
109
|
}
|
|
86
110
|
}
|
|
87
111
|
function parseLocalUrl(url) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.js","sources":["../../src/clients/download.ts"],"sourcesContent":["/* eslint-disable n/no-unsupported-features/node-builtins */\nimport type { GrpcClientProvider, GrpcClientProviderFactory } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata, stringifyWithResourceId } from '@milaboratories/pl-client';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\nimport { PerfTimer } from '@milaboratories/helpers';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport { ConcurrencyLimitingExecutor } from '@milaboratories/ts-helpers';\nimport type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { Readable } from 'node:stream';\nimport type { Dispatcher } from 'undici';\nimport type { LocalStorageProjection } from '../drivers/types';\nimport { type ContentHandler, RemoteFileDownloader } from '../helpers/download';\nimport { validateAbsolute } from '../helpers/validate';\nimport type { DownloadAPI_GetDownloadURL_Response } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol';\nimport { DownloadClient } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client';\nimport { type GetContentOptions } from '@milaboratories/pl-model-common';\n\n/** Gets URLs for downloading from pl-core, parses them and reads or downloads\n * files locally and from the web. */\nexport class ClientDownload {\n public readonly grpcClient: GrpcClientProvider<DownloadClient>;\n private readonly remoteFileDownloader: RemoteFileDownloader;\n\n /** Helps to find a storage root directory by a storage id from URL scheme. */\n private readonly localStorageIdsToRoot: Map<string, string>;\n\n /** Concurrency limiter for local file reads - limit to 32 parallel reads */\n private readonly localFileReadLimiter = new ConcurrencyLimitingExecutor(32);\n\n constructor(\n grpcClientProviderFactory: GrpcClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n /** Pl storages available locally */\n localProjections: LocalStorageProjection[],\n ) {\n this.grpcClient = grpcClientProviderFactory.createGrpcClientProvider((transport) => new DownloadClient(transport));\n this.remoteFileDownloader = new RemoteFileDownloader(httpClient);\n this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);\n }\n\n close() {}\n\n /**\n * Gets a presign URL and downloads the file.\n * An optional range with 2 numbers from what byte and to what byte to download can be provided.\n * @param fromBytes - from byte including this byte\n * @param toBytes - to byte excluding this byte\n */\n async withBlobContent<T>(\n info: ResourceInfo,\n options: RpcOptions | undefined,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, ops.signal);\n\n const remoteHeaders = Object.fromEntries(headers.map(({ name, value }) => [name, value]));\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download started, `\n + `url: ${downloadUrl}, `\n + `range: ${JSON.stringify(ops.range ?? null)}`,\n );\n\n const timer = PerfTimer.start();\n const result = isLocal(downloadUrl)\n ? await this.withLocalFileContent(downloadUrl, ops, handler)\n : await this.remoteFileDownloader.withContent(downloadUrl, remoteHeaders, ops, handler);\n\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download finished, `\n + `took: ${timer.elapsed()}`,\n );\n return result;\n }\n\n async withLocalFileContent<T>(\n url: string,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { storageId, relativePath } = parseLocalUrl(url);\n const fullPath = getFullPath(storageId, this.localStorageIdsToRoot, relativePath);\n\n return await this.localFileReadLimiter.run(async () => {\n const readOps = {\n start: ops.range?.from,\n end: ops.range?.to !== undefined ? ops.range.to - 1 : undefined,\n signal: ops.signal,\n };\n let stream: fs.ReadStream | undefined;\n let handlerSuccess = false;\n\n try {\n const stat = await fsp.stat(fullPath);\n stream = fs.createReadStream(fullPath, readOps);\n const webStream = Readable.toWeb(stream);\n\n const result = await handler(webStream, stat.size);\n handlerSuccess = true;\n return result;\n } catch (error) {\n // Cleanup on error (including handler errors)\n if (!handlerSuccess && stream && !stream.destroyed) {\n stream.destroy();\n }\n throw error;\n }\n });\n }\n\n private async grpcGetDownloadUrl(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n signal?: AbortSignal,\n ): Promise<DownloadAPI_GetDownloadURL_Response> {\n const withAbort = options ?? {};\n withAbort.abort = signal;\n\n return await this.grpcClient.get().getDownloadURL(\n { resourceId: id, isInternalUse: false },\n addRTypeToMetadata(type, withAbort),\n ).response;\n }\n}\n\nexport function parseLocalUrl(url: string) {\n const parsed = new URL(url);\n if (parsed.pathname == '')\n throw new WrongLocalFileUrl(`url for local filepath ${url} does not match url scheme`);\n\n return {\n storageId: parsed.host,\n relativePath: decodeURIComponent(parsed.pathname.slice(1)),\n };\n}\n\nexport function getFullPath(\n storageId: string,\n localStorageIdsToRoot: Map<string, string>,\n relativePath: string,\n) {\n const root = localStorageIdsToRoot.get(storageId);\n if (root === undefined) throw new UnknownStorageError(`Unknown storage location: ${storageId}`);\n\n if (root === '') return relativePath;\n\n return path.join(root, relativePath);\n}\n\nconst storageProtocol = 'storage://';\nfunction isLocal(url: string) {\n return url.startsWith(storageProtocol);\n}\n\n/** Throws when a local URL have invalid scheme. */\nexport class WrongLocalFileUrl extends Error {\n name = 'WrongLocalFileUrl';\n}\n\n/** Happens when a storage for a local file can't be found. */\nexport class UnknownStorageError extends Error {\n name = 'UnknownStorageError';\n}\n\nexport function newLocalStorageIdsToRoot(projections: LocalStorageProjection[]) {\n const idToRoot: Map<string, string> = new Map();\n for (const lp of projections) {\n // Empty string means no prefix, i.e. any file on this machine can be got from the storage.\n if (lp.localPath !== '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,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC3D;AACH;SAEgB,WAAW,CACzB,SAAiB,EACjB,qBAA0C,EAC1C,YAAoB,EAAA;IAEpB,MAAM,IAAI,GAAG,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC;IACjD,IAAI,IAAI,KAAK,SAAS;AAAE,QAAA,MAAM,IAAI,mBAAmB,CAAC,6BAA6B,SAAS,CAAA,CAAE,CAAC;IAE/F,IAAI,IAAI,KAAK,EAAE;AAAE,QAAA,OAAO,YAAY;IAEpC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC;AACtC;AAEA,MAAM,eAAe,GAAG,YAAY;AACpC,SAAS,OAAO,CAAC,GAAW,EAAA;AAC1B,IAAA,OAAO,GAAG,CAAC,UAAU,CAAC,eAAe,CAAC;AACxC;AAEA;AACM,MAAO,iBAAkB,SAAQ,KAAK,CAAA;IAC1C,IAAI,GAAG,mBAAmB;AAC3B;AAED;AACM,MAAO,mBAAoB,SAAQ,KAAK,CAAA;IAC5C,IAAI,GAAG,qBAAqB;AAC7B;AAEK,SAAU,wBAAwB,CAAC,WAAqC,EAAA;AAC5E,IAAA,MAAM,QAAQ,GAAwB,IAAI,GAAG,EAAE;AAC/C,IAAA,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE;;AAE5B,QAAA,IAAI,EAAE,CAAC,SAAS,KAAK,EAAE,EAAE;AACvB,YAAA,gBAAgB,CAAC,EAAE,CAAC,SAAS,CAAC;QAChC;QACA,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC;IAC1C;AAEA,IAAA,OAAO,QAAQ;AACjB;;;;"}
|
|
1
|
+
{"version":3,"file":"download.js","sources":["../../src/clients/download.ts"],"sourcesContent":["/* eslint-disable n/no-unsupported-features/node-builtins */\nimport type { WireClientProvider, WireClientProviderFactory } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata, stringifyWithResourceId, RestAPI, createRTypeRoutingHeader } from '@milaboratories/pl-client';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\nimport { PerfTimer } from '@milaboratories/helpers';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport { ConcurrencyLimitingExecutor } from '@milaboratories/ts-helpers';\nimport type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { Readable } from 'node:stream';\nimport type { Dispatcher } from 'undici';\nimport type { LocalStorageProjection } from '../drivers/types';\nimport { type ContentHandler, RemoteFileDownloader } from '../helpers/download';\nimport { validateAbsolute } from '../helpers/validate';\nimport type { DownloadAPI_GetDownloadURL_Response } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol';\nimport { DownloadClient } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client';\nimport type { DownloadApiPaths, DownloadRestClientType } from '../proto-rest';\nimport { type GetContentOptions } from '@milaboratories/pl-model-common';\n\n/** Gets URLs for downloading from pl-core, parses them and reads or downloads\n * files locally and from the web. */\nexport class ClientDownload {\n public readonly wire: WireClientProvider<DownloadRestClientType | DownloadClient>;\n private readonly remoteFileDownloader: RemoteFileDownloader;\n\n /** Helps to find a storage root directory by a storage id from URL scheme. */\n private readonly localStorageIdsToRoot: Map<string, string>;\n\n /** Concurrency limiter for local file reads - limit to 32 parallel reads */\n private readonly localFileReadLimiter = new ConcurrencyLimitingExecutor(32);\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n /** Pl storages available locally */\n localProjections: LocalStorageProjection[],\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wireConn) => {\n if (wireConn.type === 'grpc') {\n return new DownloadClient(wireConn.Transport);\n } else {\n return RestAPI.createClient<DownloadApiPaths>({\n hostAndPort: wireConn.Config.hostAndPort,\n ssl: wireConn.Config.ssl,\n dispatcher: wireConn.Dispatcher,\n middlewares: wireConn.Middlewares,\n });\n }\n });\n this.remoteFileDownloader = new RemoteFileDownloader(httpClient);\n this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);\n }\n\n close() {}\n\n /**\n * Gets a presign URL and downloads the file.\n * An optional range with 2 numbers from what byte and to what byte to download can be provided.\n * @param fromBytes - from byte including this byte\n * @param toBytes - to byte excluding this byte\n */\n async withBlobContent<T>(\n info: ResourceInfo,\n options: RpcOptions | undefined,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, ops.signal);\n\n const remoteHeaders = Object.fromEntries(headers.map(({ name, value }) => [name, value]));\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download started, `\n + `url: ${downloadUrl}, `\n + `range: ${JSON.stringify(ops.range ?? null)}`,\n );\n\n const timer = PerfTimer.start();\n const result = isLocal(downloadUrl)\n ? await this.withLocalFileContent(downloadUrl, ops, handler)\n : await this.remoteFileDownloader.withContent(downloadUrl, remoteHeaders, ops, handler);\n\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download finished, `\n + `took: ${timer.elapsed()}`,\n );\n return result;\n }\n\n async withLocalFileContent<T>(\n url: string,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { storageId, relativePath } = parseLocalUrl(url);\n const fullPath = getFullPath(storageId, this.localStorageIdsToRoot, relativePath);\n\n return await this.localFileReadLimiter.run(async () => {\n const readOps = {\n start: ops.range?.from,\n end: ops.range?.to !== undefined ? ops.range.to - 1 : undefined,\n signal: ops.signal,\n };\n let stream: fs.ReadStream | undefined;\n let handlerSuccess = false;\n\n try {\n const stat = await fsp.stat(fullPath);\n stream = fs.createReadStream(fullPath, readOps);\n const webStream = Readable.toWeb(stream);\n\n const result = await handler(webStream, stat.size);\n handlerSuccess = true;\n return result;\n } catch (error) {\n // Cleanup on error (including handler errors)\n if (!handlerSuccess && stream && !stream.destroyed) {\n stream.destroy();\n }\n throw error;\n }\n });\n }\n\n private async grpcGetDownloadUrl(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n signal?: AbortSignal,\n ): Promise<DownloadAPI_GetDownloadURL_Response> {\n const withAbort = options ?? {};\n withAbort.abort = signal;\n\n const client = this.wire.get();\n if (client instanceof DownloadClient) {\n return await client.getDownloadURL(\n { resourceId: id, isInternalUse: false },\n addRTypeToMetadata(type, withAbort),\n ).response;\n } else {\n return (await client.POST('/v1/get-download-url', {\n body: {\n resourceId: id.toString(),\n isInternalUse: false,\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })).data!;\n }\n }\n}\n\nexport function parseLocalUrl(url: string) {\n const parsed = new URL(url);\n if (parsed.pathname == '')\n throw new WrongLocalFileUrl(`url for local filepath ${url} does not match url scheme`);\n\n return {\n storageId: parsed.host,\n relativePath: decodeURIComponent(parsed.pathname.slice(1)),\n };\n}\n\nexport function getFullPath(\n storageId: string,\n localStorageIdsToRoot: Map<string, string>,\n relativePath: string,\n) {\n const root = localStorageIdsToRoot.get(storageId);\n if (root === undefined) throw new UnknownStorageError(`Unknown storage location: ${storageId}`);\n\n if (root === '') return relativePath;\n\n return path.join(root, relativePath);\n}\n\nconst storageProtocol = 'storage://';\nfunction isLocal(url: string) {\n return url.startsWith(storageProtocol);\n}\n\n/** Throws when a local URL have invalid scheme. */\nexport class WrongLocalFileUrl extends Error {\n name = 'WrongLocalFileUrl';\n}\n\n/** Happens when a storage for a local file can't be found. */\nexport class UnknownStorageError extends Error {\n name = 'UnknownStorageError';\n}\n\nexport function newLocalStorageIdsToRoot(projections: LocalStorageProjection[]) {\n const idToRoot: Map<string, string> = new Map();\n for (const lp of projections) {\n // Empty string means no prefix, i.e. any file on this machine can be got from the storage.\n if (lp.localPath !== '') {\n validateAbsolute(lp.localPath);\n }\n idToRoot.set(lp.storageId, lp.localPath);\n }\n\n return idToRoot;\n}\n"],"names":[],"mappings":";;;;;;;;;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mB;AAC3B;AAED;AACM,MAAO,mBAAoB,SAAQ,KAAK,CAAA;IAC5C,IAAI,GAAG,qBAAqB;AAC7B;AAEK,SAAU,wBAAwB,CAAC,WAAqC,EAAA;AAC5E,IAAA,MAAM,QAAQ,GAAwB,IAAI,GAAG,EAAE;AAC/C,IAAA,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE;;AAE5B,QAAA,IAAI,EAAE,CAAC,SAAS,KAAK,EAAE,EAAE;AACvB,YAAA,gBAAgB,CAAC,EAAE,CAAC,SAAS,CAAC;QAChC;QACA,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC;IAC1C;AAEA,IAAA,OAAO,QAAQ;AACjB;;;;"}
|
package/dist/clients/logs.cjs
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var protocol_client = require('../proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs');
|
|
4
3
|
var tsHelpers = require('@milaboratories/ts-helpers');
|
|
5
4
|
var plClient = require('@milaboratories/pl-client');
|
|
5
|
+
var protocol_client = require('../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs');
|
|
6
6
|
|
|
7
7
|
class ClientLogs {
|
|
8
8
|
httpClient;
|
|
9
9
|
logger;
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
10
|
+
wire;
|
|
11
|
+
constructor(wireClientProviderFactory, httpClient, logger) {
|
|
12
12
|
this.httpClient = httpClient;
|
|
13
13
|
this.logger = logger;
|
|
14
|
-
this.
|
|
14
|
+
this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {
|
|
15
|
+
if (wire.type === 'grpc') {
|
|
16
|
+
return new protocol_client.StreamingClient(wire.Transport);
|
|
17
|
+
}
|
|
18
|
+
return plClient.RestAPI.createClient({
|
|
19
|
+
hostAndPort: wire.Config.hostAndPort,
|
|
20
|
+
ssl: wire.Config.ssl,
|
|
21
|
+
dispatcher: wire.Dispatcher,
|
|
22
|
+
middlewares: wire.Middlewares,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
15
25
|
}
|
|
16
26
|
close() { }
|
|
17
27
|
/** Reads text back and returns the text,
|
|
@@ -19,24 +29,55 @@ class ClientLogs {
|
|
|
19
29
|
* and the total size of the (currently existing) file. */
|
|
20
30
|
async lastLines({ id: rId, type: rType }, lineCount, offsetBytes = 0n, // if 0n, then start from the end.
|
|
21
31
|
searchStr, options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
lineCount: lineCount,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
const client = this.wire.get();
|
|
33
|
+
if (client instanceof protocol_client.StreamingClient) {
|
|
34
|
+
return (await client.lastLines({ resourceId: rId, lineCount: lineCount, offset: offsetBytes, search: searchStr }, plClient.addRTypeToMetadata(rType, options))).response;
|
|
35
|
+
}
|
|
36
|
+
const resp = (await client.POST('/v1/last-lines', {
|
|
37
|
+
body: {
|
|
38
|
+
resourceId: rId.toString(),
|
|
39
|
+
lineCount: lineCount,
|
|
40
|
+
offset: offsetBytes.toString(),
|
|
41
|
+
search: searchStr ?? '',
|
|
42
|
+
searchRe: '',
|
|
43
|
+
},
|
|
44
|
+
headers: { ...plClient.createRTypeRoutingHeader(rType) },
|
|
45
|
+
})).data;
|
|
46
|
+
return {
|
|
47
|
+
data: new Uint8Array(Buffer.from(resp.data)),
|
|
48
|
+
size: BigInt(resp.size),
|
|
49
|
+
newOffset: BigInt(resp.newOffset),
|
|
50
|
+
};
|
|
28
51
|
}
|
|
29
52
|
/** Reads the file forward and returns the text,
|
|
30
53
|
* the new offset
|
|
31
54
|
* and the total size of the (currently existing) file. */
|
|
32
55
|
async readText({ id: rId, type: rType }, lineCount, offsetBytes = 0n, // if 0n, then start from the beginning.
|
|
33
56
|
searchStr, options) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
const client = this.wire.get();
|
|
58
|
+
if (client instanceof protocol_client.StreamingClient) {
|
|
59
|
+
return (await client.readText({
|
|
60
|
+
resourceId: tsHelpers.notEmpty(rId),
|
|
61
|
+
readLimit: BigInt(lineCount),
|
|
62
|
+
offset: offsetBytes,
|
|
63
|
+
search: searchStr,
|
|
64
|
+
}, plClient.addRTypeToMetadata(rType, options))).response;
|
|
65
|
+
}
|
|
66
|
+
const resp = (await client.POST('/v1/read/text', {
|
|
67
|
+
body: {
|
|
68
|
+
resourceId: rId.toString(),
|
|
69
|
+
readLimit: lineCount.toString(),
|
|
70
|
+
offset: offsetBytes.toString(),
|
|
71
|
+
search: searchStr ?? '',
|
|
72
|
+
searchRe: '',
|
|
73
|
+
},
|
|
74
|
+
headers: { ...plClient.createRTypeRoutingHeader(rType) },
|
|
75
|
+
})).data;
|
|
76
|
+
return {
|
|
77
|
+
data: new Uint8Array(Buffer.from(resp.data)),
|
|
78
|
+
size: BigInt(resp.size),
|
|
79
|
+
newOffset: BigInt(resp.newOffset),
|
|
80
|
+
};
|
|
40
81
|
}
|
|
41
82
|
}
|
|
42
83
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.cjs","sources":["../../src/clients/logs.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"logs.cjs","sources":["../../src/clients/logs.ts"],"sourcesContent":["import type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport { notEmpty } from '@milaboratories/ts-helpers';\nimport type { Dispatcher } from 'undici';\nimport type { WireClientProvider, WireClientProviderFactory } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata, createRTypeRoutingHeader, RestAPI } from '@milaboratories/pl-client';\nimport type { StreamingAPI_Response } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol';\nimport { StreamingClient } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client';\nimport type { StreamingApiPaths, StreamingRestClientType } from '../proto-rest';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\n\nexport class ClientLogs {\n public readonly wire: WireClientProvider<StreamingRestClientType | StreamingClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider(\n (wire) => {\n if (wire.type === 'grpc') {\n return new StreamingClient(wire.Transport);\n }\n\n return RestAPI.createClient<StreamingApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n /** Reads text back and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async lastLines(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the end.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const client = this.wire.get();\n if (client instanceof StreamingClient) {\n return (\n await client.lastLines(\n { resourceId: rId, lineCount: lineCount, offset: offsetBytes, search: searchStr },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (await client.POST('/v1/last-lines', {\n body: {\n resourceId: rId.toString(),\n lineCount: lineCount,\n offset: offsetBytes.toString(),\n search: searchStr ?? '',\n searchRe: '',\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })).data!;\n\n return {\n data: new Uint8Array(Buffer.from(resp.data)),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n\n /** Reads the file forward and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async readText(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the beginning.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const client = this.wire.get();\n\n if (client instanceof StreamingClient) {\n return (await client.readText(\n {\n resourceId: notEmpty(rId),\n readLimit: BigInt(lineCount),\n offset: offsetBytes,\n search: searchStr,\n },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (await client.POST('/v1/read/text', {\n body: {\n resourceId: rId.toString(),\n readLimit: lineCount.toString(),\n offset: offsetBytes.toString(),\n search: searchStr ?? '',\n searchRe: '',\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })).data!;\n\n return {\n data: new Uint8Array(Buffer.from(resp.data)),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n}\n"],"names":["StreamingClient","RestAPI","addRTypeToMetadata","createRTypeRoutingHeader","notEmpty"],"mappings":";;;;;;MAWa,UAAU,CAAA;AAKH,IAAA,UAAA;AACA,IAAA,MAAA;AALF,IAAA,IAAI;AAEpB,IAAA,WAAA,CACE,yBAAoD,EACpC,UAAsB,EACtB,MAAgB,EAAA;QADhB,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,MAAM,GAAN,MAAM;QAEtB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC,wBAAwB,CAC5D,CAAC,IAAI,KAAI;AACP,YAAA,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;AACxB,gBAAA,OAAO,IAAIA,+BAAe,CAAC,IAAI,CAAC,SAAS,CAAC;YAC5C;YAEA,OAAOC,gBAAO,CAAC,YAAY,CAAoB;AAC7C,gBAAA,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;AACpC,gBAAA,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG;gBACpB,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,WAAW,EAAE,IAAI,CAAC,WAAW;AAC9B,aAAA,CAAC;AACJ,QAAA,CAAC,CAAC;IACN;AAEA,IAAA,KAAK,KAAI;AAET;;AAE0D;AACnD,IAAA,MAAM,SAAS,CACpB,EAAE,EAAE,EAAE,GAAG,EA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client';
|
|
2
1
|
import type { RpcOptions } from '@protobuf-ts/runtime-rpc';
|
|
3
2
|
import type { MiLogger } from '@milaboratories/ts-helpers';
|
|
4
3
|
import type { Dispatcher } from 'undici';
|
|
5
|
-
import type {
|
|
6
|
-
import type { StreamingAPI_Response } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol';
|
|
4
|
+
import type { WireClientProvider, WireClientProviderFactory } from '@milaboratories/pl-client';
|
|
5
|
+
import type { StreamingAPI_Response } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol';
|
|
6
|
+
import { StreamingClient } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client';
|
|
7
|
+
import type { StreamingRestClientType } from '../proto-rest';
|
|
7
8
|
import type { ResourceInfo } from '@milaboratories/pl-tree';
|
|
8
9
|
export declare class ClientLogs {
|
|
9
10
|
readonly httpClient: Dispatcher;
|
|
10
11
|
readonly logger: MiLogger;
|
|
11
|
-
readonly
|
|
12
|
-
constructor(
|
|
12
|
+
readonly wire: WireClientProvider<StreamingRestClientType | StreamingClient>;
|
|
13
|
+
constructor(wireClientProviderFactory: WireClientProviderFactory, httpClient: Dispatcher, logger: MiLogger);
|
|
13
14
|
close(): void;
|
|
14
15
|
/** Reads text back and returns the text,
|
|
15
16
|
* the new offset
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/clients/logs.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/clients/logs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB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