@milaboratories/pl-drivers 1.11.59 → 1.11.61

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.
Files changed (330) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/clients/constructors.cjs +28 -28
  3. package/dist/clients/constructors.cjs.map +1 -1
  4. package/dist/clients/constructors.d.ts +17 -13
  5. package/dist/clients/constructors.js +28 -26
  6. package/dist/clients/constructors.js.map +1 -1
  7. package/dist/clients/crc32c.cjs +8 -13
  8. package/dist/clients/crc32c.cjs.map +1 -1
  9. package/dist/clients/crc32c.js +8 -12
  10. package/dist/clients/crc32c.js.map +1 -1
  11. package/dist/clients/download.cjs +119 -160
  12. package/dist/clients/download.cjs.map +1 -1
  13. package/dist/clients/download.d.ts +45 -41
  14. package/dist/clients/download.js +115 -137
  15. package/dist/clients/download.js.map +1 -1
  16. package/dist/clients/logs.cjs +78 -82
  17. package/dist/clients/logs.cjs.map +1 -1
  18. package/dist/clients/logs.d.ts +34 -24
  19. package/dist/clients/logs.js +77 -80
  20. package/dist/clients/logs.js.map +1 -1
  21. package/dist/clients/ls_api.cjs +62 -68
  22. package/dist/clients/ls_api.cjs.map +1 -1
  23. package/dist/clients/ls_api.d.ts +15 -11
  24. package/dist/clients/ls_api.js +61 -66
  25. package/dist/clients/ls_api.js.map +1 -1
  26. package/dist/clients/progress.cjs +49 -59
  27. package/dist/clients/progress.cjs.map +1 -1
  28. package/dist/clients/progress.d.ts +27 -20
  29. package/dist/clients/progress.js +48 -57
  30. package/dist/clients/progress.js.map +1 -1
  31. package/dist/clients/upload.cjs +189 -250
  32. package/dist/clients/upload.cjs.map +1 -1
  33. package/dist/clients/upload.d.ts +44 -34
  34. package/dist/clients/upload.js +187 -229
  35. package/dist/clients/upload.js.map +1 -1
  36. package/dist/drivers/download_blob/blob_key.cjs +9 -26
  37. package/dist/drivers/download_blob/blob_key.cjs.map +1 -1
  38. package/dist/drivers/download_blob/blob_key.js +7 -5
  39. package/dist/drivers/download_blob/blob_key.js.map +1 -1
  40. package/dist/drivers/download_blob/download_blob.cjs +395 -478
  41. package/dist/drivers/download_blob/download_blob.cjs.map +1 -1
  42. package/dist/drivers/download_blob/download_blob.d.ts +102 -100
  43. package/dist/drivers/download_blob/download_blob.js +388 -453
  44. package/dist/drivers/download_blob/download_blob.js.map +1 -1
  45. package/dist/drivers/download_blob/download_blob_task.cjs +128 -163
  46. package/dist/drivers/download_blob/download_blob_task.cjs.map +1 -1
  47. package/dist/drivers/download_blob/download_blob_task.js +125 -141
  48. package/dist/drivers/download_blob/download_blob_task.js.map +1 -1
  49. package/dist/drivers/download_blob/sparse_cache/cache.cjs +166 -195
  50. package/dist/drivers/download_blob/sparse_cache/cache.cjs.map +1 -1
  51. package/dist/drivers/download_blob/sparse_cache/cache.js +164 -193
  52. package/dist/drivers/download_blob/sparse_cache/cache.js.map +1 -1
  53. package/dist/drivers/download_blob/sparse_cache/file.cjs +29 -50
  54. package/dist/drivers/download_blob/sparse_cache/file.cjs.map +1 -1
  55. package/dist/drivers/download_blob/sparse_cache/file.js +28 -29
  56. package/dist/drivers/download_blob/sparse_cache/file.js.map +1 -1
  57. package/dist/drivers/download_blob/sparse_cache/ranges.cjs +48 -76
  58. package/dist/drivers/download_blob/sparse_cache/ranges.cjs.map +1 -1
  59. package/dist/drivers/download_blob/sparse_cache/ranges.js +47 -54
  60. package/dist/drivers/download_blob/sparse_cache/ranges.js.map +1 -1
  61. package/dist/drivers/download_blob_url/driver.cjs +125 -165
  62. package/dist/drivers/download_blob_url/driver.cjs.map +1 -1
  63. package/dist/drivers/download_blob_url/driver.d.ts +45 -42
  64. package/dist/drivers/download_blob_url/driver.js +123 -144
  65. package/dist/drivers/download_blob_url/driver.js.map +1 -1
  66. package/dist/drivers/download_blob_url/driver_id.cjs +4 -4
  67. package/dist/drivers/download_blob_url/driver_id.cjs.map +1 -1
  68. package/dist/drivers/download_blob_url/driver_id.js +4 -3
  69. package/dist/drivers/download_blob_url/driver_id.js.map +1 -1
  70. package/dist/drivers/download_blob_url/snapshot.cjs +7 -11
  71. package/dist/drivers/download_blob_url/snapshot.cjs.map +1 -1
  72. package/dist/drivers/download_blob_url/snapshot.d.ts +10 -5
  73. package/dist/drivers/download_blob_url/snapshot.js +5 -8
  74. package/dist/drivers/download_blob_url/snapshot.js.map +1 -1
  75. package/dist/drivers/download_blob_url/task.cjs +147 -194
  76. package/dist/drivers/download_blob_url/task.cjs.map +1 -1
  77. package/dist/drivers/download_blob_url/task.d.ts +55 -57
  78. package/dist/drivers/download_blob_url/task.js +140 -170
  79. package/dist/drivers/download_blob_url/task.js.map +1 -1
  80. package/dist/drivers/download_url/driver.cjs +109 -146
  81. package/dist/drivers/download_url/driver.cjs.map +1 -1
  82. package/dist/drivers/download_url/driver.d.ts +59 -57
  83. package/dist/drivers/download_url/driver.js +107 -125
  84. package/dist/drivers/download_url/driver.js.map +1 -1
  85. package/dist/drivers/download_url/task.cjs +104 -137
  86. package/dist/drivers/download_url/task.cjs.map +1 -1
  87. package/dist/drivers/download_url/task.d.ts +33 -37
  88. package/dist/drivers/download_url/task.js +99 -113
  89. package/dist/drivers/download_url/task.js.map +1 -1
  90. package/dist/drivers/helpers/download_local_handle.cjs +13 -14
  91. package/dist/drivers/helpers/download_local_handle.cjs.map +1 -1
  92. package/dist/drivers/helpers/download_local_handle.js +13 -13
  93. package/dist/drivers/helpers/download_local_handle.js.map +1 -1
  94. package/dist/drivers/helpers/download_remote_handle.cjs +23 -24
  95. package/dist/drivers/helpers/download_remote_handle.cjs.map +1 -1
  96. package/dist/drivers/helpers/download_remote_handle.js +22 -22
  97. package/dist/drivers/helpers/download_remote_handle.js.map +1 -1
  98. package/dist/drivers/helpers/files_cache.cjs +53 -64
  99. package/dist/drivers/helpers/files_cache.cjs.map +1 -1
  100. package/dist/drivers/helpers/files_cache.js +52 -62
  101. package/dist/drivers/helpers/files_cache.js.map +1 -1
  102. package/dist/drivers/helpers/helpers.cjs +24 -28
  103. package/dist/drivers/helpers/helpers.cjs.map +1 -1
  104. package/dist/drivers/helpers/helpers.d.ts +10 -7
  105. package/dist/drivers/helpers/helpers.js +24 -27
  106. package/dist/drivers/helpers/helpers.js.map +1 -1
  107. package/dist/drivers/helpers/logs_handle.cjs +24 -33
  108. package/dist/drivers/helpers/logs_handle.cjs.map +1 -1
  109. package/dist/drivers/helpers/logs_handle.js +24 -29
  110. package/dist/drivers/helpers/logs_handle.js.map +1 -1
  111. package/dist/drivers/helpers/ls_remote_import_handle.cjs +20 -20
  112. package/dist/drivers/helpers/ls_remote_import_handle.cjs.map +1 -1
  113. package/dist/drivers/helpers/ls_remote_import_handle.js +20 -18
  114. package/dist/drivers/helpers/ls_remote_import_handle.js.map +1 -1
  115. package/dist/drivers/helpers/ls_storage_entry.cjs +36 -40
  116. package/dist/drivers/helpers/ls_storage_entry.cjs.map +1 -1
  117. package/dist/drivers/helpers/ls_storage_entry.js +36 -37
  118. package/dist/drivers/helpers/ls_storage_entry.js.map +1 -1
  119. package/dist/drivers/helpers/polling_ops.d.ts +6 -5
  120. package/dist/drivers/helpers/read_file.cjs +34 -57
  121. package/dist/drivers/helpers/read_file.cjs.map +1 -1
  122. package/dist/drivers/helpers/read_file.js +30 -34
  123. package/dist/drivers/helpers/read_file.js.map +1 -1
  124. package/dist/drivers/logs.cjs +94 -112
  125. package/dist/drivers/logs.cjs.map +1 -1
  126. package/dist/drivers/logs.d.ts +35 -32
  127. package/dist/drivers/logs.js +93 -110
  128. package/dist/drivers/logs.js.map +1 -1
  129. package/dist/drivers/logs_stream.cjs +210 -242
  130. package/dist/drivers/logs_stream.cjs.map +1 -1
  131. package/dist/drivers/logs_stream.d.ts +55 -53
  132. package/dist/drivers/logs_stream.js +209 -240
  133. package/dist/drivers/logs_stream.js.map +1 -1
  134. package/dist/drivers/ls.cjs +151 -238
  135. package/dist/drivers/ls.cjs.map +1 -1
  136. package/dist/drivers/ls.d.ts +53 -49
  137. package/dist/drivers/ls.js +148 -216
  138. package/dist/drivers/ls.js.map +1 -1
  139. package/dist/drivers/types.cjs +25 -53
  140. package/dist/drivers/types.cjs.map +1 -1
  141. package/dist/drivers/types.d.ts +91 -106
  142. package/dist/drivers/types.js +23 -50
  143. package/dist/drivers/types.js.map +1 -1
  144. package/dist/drivers/upload.cjs +127 -153
  145. package/dist/drivers/upload.cjs.map +1 -1
  146. package/dist/drivers/upload.d.ts +52 -50
  147. package/dist/drivers/upload.js +126 -151
  148. package/dist/drivers/upload.js.map +1 -1
  149. package/dist/drivers/upload_task.cjs +223 -260
  150. package/dist/drivers/upload_task.cjs.map +1 -1
  151. package/dist/drivers/upload_task.d.ts +54 -52
  152. package/dist/drivers/upload_task.js +221 -258
  153. package/dist/drivers/upload_task.js.map +1 -1
  154. package/dist/drivers/urls/url.cjs +30 -35
  155. package/dist/drivers/urls/url.cjs.map +1 -1
  156. package/dist/drivers/urls/url.js +28 -33
  157. package/dist/drivers/urls/url.js.map +1 -1
  158. package/dist/drivers/virtual_storages.cjs +36 -48
  159. package/dist/drivers/virtual_storages.cjs.map +1 -1
  160. package/dist/drivers/virtual_storages.d.ts +6 -2
  161. package/dist/drivers/virtual_storages.js +32 -46
  162. package/dist/drivers/virtual_storages.js.map +1 -1
  163. package/dist/helpers/download.cjs +72 -95
  164. package/dist/helpers/download.cjs.map +1 -1
  165. package/dist/helpers/download.d.ts +13 -9
  166. package/dist/helpers/download.js +71 -93
  167. package/dist/helpers/download.js.map +1 -1
  168. package/dist/helpers/download_errors.cjs +28 -27
  169. package/dist/helpers/download_errors.cjs.map +1 -1
  170. package/dist/helpers/download_errors.d.ts +16 -13
  171. package/dist/helpers/download_errors.js +28 -26
  172. package/dist/helpers/download_errors.js.map +1 -1
  173. package/dist/helpers/validate.cjs +8 -7
  174. package/dist/helpers/validate.cjs.map +1 -1
  175. package/dist/helpers/validate.d.ts +4 -1
  176. package/dist/helpers/validate.js +6 -5
  177. package/dist/helpers/validate.js.map +1 -1
  178. package/dist/index.cjs +75 -79
  179. package/dist/index.d.ts +22 -22
  180. package/dist/index.js +22 -21
  181. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs +238 -249
  182. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs.map +1 -1
  183. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs +27 -27
  184. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs.map +1 -1
  185. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +25 -23
  186. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js +26 -25
  187. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js.map +1 -1
  188. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +51 -87
  189. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js +238 -245
  190. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js.map +1 -1
  191. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs +295 -289
  192. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +1 -1
  193. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs +30 -30
  194. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs.map +1 -1
  195. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js +29 -28
  196. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js.map +1 -1
  197. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +86 -150
  198. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js +295 -285
  199. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js.map +1 -1
  200. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs +385 -393
  201. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +1 -1
  202. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs +34 -34
  203. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs.map +1 -1
  204. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +33 -34
  205. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js +33 -32
  206. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js.map +1 -1
  207. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +78 -129
  208. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js +385 -387
  209. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js.map +1 -1
  210. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs +570 -468
  211. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +1 -1
  212. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs +82 -82
  213. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs.map +1 -1
  214. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +109 -112
  215. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js +81 -80
  216. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js.map +1 -1
  217. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +243 -264
  218. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js +569 -460
  219. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js.map +1 -1
  220. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs +751 -729
  221. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +1 -1
  222. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs +67 -67
  223. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs.map +1 -1
  224. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js +66 -65
  225. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js.map +1 -1
  226. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts +15 -381
  227. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js +749 -718
  228. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js.map +1 -1
  229. package/dist/proto-grpc/google/protobuf/duration.cjs +92 -100
  230. package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -1
  231. package/dist/proto-grpc/google/protobuf/duration.d.ts +38 -43
  232. package/dist/proto-grpc/google/protobuf/duration.js +91 -98
  233. package/dist/proto-grpc/google/protobuf/duration.js.map +1 -1
  234. package/dist/proto-grpc/google/protobuf/timestamp.cjs +117 -128
  235. package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -1
  236. package/dist/proto-grpc/google/protobuf/timestamp.d.ts +50 -55
  237. package/dist/proto-grpc/google/protobuf/timestamp.js +116 -126
  238. package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -1
  239. package/dist/proto-rest/downloadapi.d.ts +85 -91
  240. package/dist/proto-rest/index.d.ts +11 -16
  241. package/dist/proto-rest/progressapi.d.ts +130 -140
  242. package/dist/proto-rest/streamingapi.d.ts +413 -434
  243. package/package.json +12 -12
  244. package/dist/clients/constructors.d.ts.map +0 -1
  245. package/dist/clients/crc32c.d.ts +0 -2
  246. package/dist/clients/crc32c.d.ts.map +0 -1
  247. package/dist/clients/download.d.ts.map +0 -1
  248. package/dist/clients/logs.d.ts.map +0 -1
  249. package/dist/clients/ls_api.d.ts.map +0 -1
  250. package/dist/clients/progress.d.ts.map +0 -1
  251. package/dist/clients/upload.d.ts.map +0 -1
  252. package/dist/drivers/download_blob/blob_key.d.ts +0 -5
  253. package/dist/drivers/download_blob/blob_key.d.ts.map +0 -1
  254. package/dist/drivers/download_blob/download_blob.d.ts.map +0 -1
  255. package/dist/drivers/download_blob/download_blob_task.d.ts +0 -56
  256. package/dist/drivers/download_blob/download_blob_task.d.ts.map +0 -1
  257. package/dist/drivers/download_blob/sparse_cache/cache.d.ts +0 -82
  258. package/dist/drivers/download_blob/sparse_cache/cache.d.ts.map +0 -1
  259. package/dist/drivers/download_blob/sparse_cache/file.d.ts +0 -8
  260. package/dist/drivers/download_blob/sparse_cache/file.d.ts.map +0 -1
  261. package/dist/drivers/download_blob/sparse_cache/ranges.d.ts +0 -46
  262. package/dist/drivers/download_blob/sparse_cache/ranges.d.ts.map +0 -1
  263. package/dist/drivers/download_blob_url/driver.d.ts.map +0 -1
  264. package/dist/drivers/download_blob_url/driver_id.d.ts +0 -6
  265. package/dist/drivers/download_blob_url/driver_id.d.ts.map +0 -1
  266. package/dist/drivers/download_blob_url/snapshot.d.ts.map +0 -1
  267. package/dist/drivers/download_blob_url/task.d.ts.map +0 -1
  268. package/dist/drivers/download_url/driver.d.ts.map +0 -1
  269. package/dist/drivers/download_url/task.d.ts.map +0 -1
  270. package/dist/drivers/helpers/download_local_handle.d.ts +0 -11
  271. package/dist/drivers/helpers/download_local_handle.d.ts.map +0 -1
  272. package/dist/drivers/helpers/download_remote_handle.d.ts +0 -13
  273. package/dist/drivers/helpers/download_remote_handle.d.ts.map +0 -1
  274. package/dist/drivers/helpers/files_cache.d.ts +0 -29
  275. package/dist/drivers/helpers/files_cache.d.ts.map +0 -1
  276. package/dist/drivers/helpers/helpers.d.ts.map +0 -1
  277. package/dist/drivers/helpers/logs_handle.d.ts +0 -15
  278. package/dist/drivers/helpers/logs_handle.d.ts.map +0 -1
  279. package/dist/drivers/helpers/ls_remote_import_handle.d.ts +0 -8
  280. package/dist/drivers/helpers/ls_remote_import_handle.d.ts.map +0 -1
  281. package/dist/drivers/helpers/ls_storage_entry.d.ts +0 -23
  282. package/dist/drivers/helpers/ls_storage_entry.d.ts.map +0 -1
  283. package/dist/drivers/helpers/polling_ops.d.ts.map +0 -1
  284. package/dist/drivers/helpers/read_file.d.ts +0 -12
  285. package/dist/drivers/helpers/read_file.d.ts.map +0 -1
  286. package/dist/drivers/helpers/test_helpers.d.ts +0 -2
  287. package/dist/drivers/helpers/test_helpers.d.ts.map +0 -1
  288. package/dist/drivers/logs.d.ts.map +0 -1
  289. package/dist/drivers/logs_stream.d.ts.map +0 -1
  290. package/dist/drivers/ls.d.ts.map +0 -1
  291. package/dist/drivers/types.d.ts.map +0 -1
  292. package/dist/drivers/upload.d.ts.map +0 -1
  293. package/dist/drivers/upload_task.d.ts.map +0 -1
  294. package/dist/drivers/urls/url.d.ts +0 -13
  295. package/dist/drivers/urls/url.d.ts.map +0 -1
  296. package/dist/drivers/virtual_storages.d.ts.map +0 -1
  297. package/dist/helpers/download.d.ts.map +0 -1
  298. package/dist/helpers/download_errors.d.ts.map +0 -1
  299. package/dist/helpers/validate.d.ts.map +0 -1
  300. package/dist/index.cjs.map +0 -1
  301. package/dist/index.d.ts.map +0 -1
  302. package/dist/index.js.map +0 -1
  303. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +0 -1
  304. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +0 -1
  305. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +0 -46
  306. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +0 -1
  307. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +0 -1
  308. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +0 -1
  309. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +0 -1
  310. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +0 -1
  311. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +0 -1
  312. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts +0 -108
  313. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts.map +0 -1
  314. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts.map +0 -1
  315. package/dist/proto-grpc/google/api/http.d.ts +0 -460
  316. package/dist/proto-grpc/google/api/http.d.ts.map +0 -1
  317. package/dist/proto-grpc/google/protobuf/descriptor.d.ts +0 -2340
  318. package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +0 -1
  319. package/dist/proto-grpc/google/protobuf/duration.d.ts.map +0 -1
  320. package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +0 -1
  321. package/dist/proto-rest/downloadapi.d.ts.map +0 -1
  322. package/dist/proto-rest/index.d.ts.map +0 -1
  323. package/dist/proto-rest/lsapi.d.ts +0 -148
  324. package/dist/proto-rest/lsapi.d.ts.map +0 -1
  325. package/dist/proto-rest/progressapi.d.ts.map +0 -1
  326. package/dist/proto-rest/streamingapi.d.ts.map +0 -1
  327. package/dist/proto-rest/uploadapi.d.ts +0 -355
  328. package/dist/proto-rest/uploadapi.d.ts.map +0 -1
  329. package/dist/test_env.d.ts +0 -6
  330. package/dist/test_env.d.ts.map +0 -1
@@ -1,463 +1,398 @@
1
- import { Computable, ChangeSource } from '@milaboratories/computable';
2
- import { stringifyWithResourceId, resourceIdToString, isNotFoundError } from '@milaboratories/pl-client';
3
- import { validateRangeBytes } from '@milaboratories/pl-model-common';
4
- import { treeEntryToResourceInfo, isPlTreeEntry, makeResourceSnapshot } from '@milaboratories/pl-tree';
5
- import { TaskProcessor, mapGet, CallersCounter } from '@milaboratories/ts-helpers';
6
- import Denque from 'denque';
7
- import * as fs from 'node:fs';
8
- import { randomUUID } from 'node:crypto';
9
- import * as fsp from 'node:fs/promises';
10
- import * as os from 'node:os';
11
- import * as path from 'node:path';
12
- import * as readline from 'node:readline/promises';
13
- import { buffer } from 'node:stream/consumers';
14
- import { withFileContent } from '../helpers/read_file.js';
15
- import { newLocalHandle, parseLocalHandle, isLocalBlobHandle } from '../helpers/download_local_handle.js';
16
- import { newRemoteHandle, isRemoteBlobHandle, parseRemoteHandle } from '../helpers/download_remote_handle.js';
17
- import { WrongResourceTypeError, Updater } from '../helpers/helpers.js';
18
- import { newLogHandle, getResourceInfoFromLogHandle } from '../helpers/logs_handle.js';
19
- import { OnDemandBlobResourceSnapshot, getSize } from '../types.js';
20
- import { blobKey, pathToKey } from './blob_key.js';
21
- import { DownloadBlobTask, nonRecoverableError } from './download_blob_task.js';
22
- import { FilesCache } from '../helpers/files_cache.js';
23
- import { SparseCacheFsRanges, SparseCacheFsFile, SparseCache } from './sparse_cache/cache.js';
24
- import { isOffByOneError } from '../../helpers/download_errors.js';
1
+ import { isOffByOneError } from "../../helpers/download_errors.js";
2
+ import { withFileContent } from "../helpers/read_file.js";
3
+ import { isLocalBlobHandle, newLocalHandle, parseLocalHandle } from "../helpers/download_local_handle.js";
4
+ import { OnDemandBlobResourceSnapshot, getSize } from "../types.js";
5
+ import { isRemoteBlobHandle, newRemoteHandle, parseRemoteHandle } from "../helpers/download_remote_handle.js";
6
+ import { Updater, WrongResourceTypeError } from "../helpers/helpers.js";
7
+ import { getResourceInfoFromLogHandle, newLogHandle } from "../helpers/logs_handle.js";
8
+ import { blobKey, pathToKey } from "./blob_key.js";
9
+ import { DownloadBlobTask, nonRecoverableError } from "./download_blob_task.js";
10
+ import { FilesCache } from "../helpers/files_cache.js";
11
+ import { SparseCache, SparseCacheFsFile, SparseCacheFsRanges } from "./sparse_cache/cache.js";
12
+ import { isNotFoundError, resourceIdToString, stringifyWithResourceId } from "@milaboratories/pl-client";
13
+ import * as fsp from "node:fs/promises";
14
+ import { CallersCounter, TaskProcessor, mapGet } from "@milaboratories/ts-helpers";
15
+ import * as path$1 from "node:path";
16
+ import { buffer } from "node:stream/consumers";
17
+ import { ChangeSource, Computable } from "@milaboratories/computable";
18
+ import { validateRangeBytes } from "@milaboratories/pl-model-common";
19
+ import { isPlTreeEntry, makeResourceSnapshot, treeEntryToResourceInfo } from "@milaboratories/pl-tree";
20
+ import Denque from "denque";
21
+ import * as fs$1 from "fs";
22
+ import { randomUUID } from "node:crypto";
23
+ import * as os from "node:os";
24
+ import * as readline from "node:readline/promises";
25
25
 
26
+ //#region src/drivers/download_blob/download_blob.ts
26
27
  /** DownloadDriver holds a queue of downloading tasks,
27
- * and notifies every watcher when a file were downloaded. */
28
- class DownloadDriver {
29
- logger;
30
- clientDownload;
31
- clientLogs;
32
- rangesCacheDir;
33
- signer;
34
- ops;
35
- /** Represents a unique key to the path of a blob as a map. */
36
- keyToDownload = new Map();
37
- /** Writes and removes files to a hard drive and holds a counter for every
38
- * file that should be kept. */
39
- cache;
40
- rangesCache;
41
- /** Downloads files and writes them to the local dir. */
42
- downloadQueue;
43
- keyToOnDemand = new Map();
44
- idToLastLines = new Map();
45
- idToProgressLog = new Map();
46
- saveDir;
47
- constructor(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops) {
48
- this.logger = logger;
49
- this.clientDownload = clientDownload;
50
- this.clientLogs = clientLogs;
51
- this.rangesCacheDir = rangesCacheDir;
52
- this.signer = signer;
53
- this.ops = ops;
54
- this.cache = new FilesCache(this.ops.cacheSoftSizeBytes);
55
- const fsRanges = new SparseCacheFsRanges(this.logger, this.rangesCacheDir);
56
- const fsStorage = new SparseCacheFsFile(this.logger, this.rangesCacheDir);
57
- this.rangesCache = new SparseCache(this.logger, this.ops.rangesCacheMaxSizeBytes, fsRanges, fsStorage);
58
- this.downloadQueue = new TaskProcessor(this.logger, ops.nConcurrentDownloads);
59
- this.saveDir = path.resolve(saveDir);
60
- }
61
- static async init(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops) {
62
- const driver = new DownloadDriver(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops);
63
- await driver.rangesCache.reset();
64
- return driver;
65
- }
66
- getDownloadedBlob(res, ctx) {
67
- if (ctx === undefined) {
68
- return Computable.make((ctx) => this.getDownloadedBlob(res, ctx));
69
- }
70
- const rInfo = treeEntryToResourceInfo(res, ctx);
71
- const callerId = randomUUID();
72
- ctx.addOnDestroy(() => this.releaseBlob(rInfo, callerId));
73
- const result = this.getDownloadedBlobNoCtx(ctx.watcher, rInfo, callerId);
74
- if (result == undefined) {
75
- ctx.markUnstable("download blob is still undefined");
76
- }
77
- return result;
78
- }
79
- getDownloadedBlobNoCtx(w, rInfo, callerId) {
80
- validateDownloadableResourceType("getDownloadedBlob", rInfo.type);
81
- // We don't need to request files with wider limits,
82
- // PFrame's engine does it disk-optimally by itself.
83
- const task = this.getOrSetNewTask(rInfo, callerId);
84
- task.attach(w, callerId);
85
- const result = task.getBlob();
86
- if (!result.done) {
87
- return undefined;
88
- }
89
- if (result.result.ok) {
90
- return result.result.value;
91
- }
92
- throw result.result.error;
93
- }
94
- getOrSetNewTask(rInfo, callerId) {
95
- const key = blobKey(rInfo.id);
96
- const inMemoryTask = this.keyToDownload.get(key);
97
- if (inMemoryTask) {
98
- return inMemoryTask;
99
- }
100
- // schedule the blob downloading, then it'll be added to the cache.
101
- const fPath = path.resolve(this.saveDir, key);
102
- const newTask = new DownloadBlobTask(this.logger, this.clientDownload, rInfo, newLocalHandle(fPath, this.signer), fPath);
103
- this.keyToDownload.set(key, newTask);
104
- this.downloadQueue.push({
105
- fn: () => this.downloadBlob(newTask, callerId),
106
- recoverableErrorPredicate: (e) => !nonRecoverableError(e),
107
- });
108
- return newTask;
109
- }
110
- async downloadBlob(task, callerId) {
111
- await task.download();
112
- const blob = task.getBlob();
113
- if (blob.done && blob.result.ok) {
114
- this.cache.addCache(task, callerId);
115
- }
116
- }
117
- getOnDemandBlob(res, ctx) {
118
- if (ctx === undefined)
119
- return Computable.make((ctx) => this.getOnDemandBlob(res, ctx));
120
- const rInfo = isPlTreeEntry(res)
121
- ? makeResourceSnapshot(res, OnDemandBlobResourceSnapshot, ctx)
122
- : res;
123
- const callerId = randomUUID();
124
- ctx.addOnDestroy(() => this.releaseOnDemandBlob(rInfo.id, callerId));
125
- // note that the watcher is not needed,
126
- // the handler never changes.
127
- const result = this.getOnDemandBlobNoCtx(rInfo, callerId);
128
- return result;
129
- }
130
- getOnDemandBlobNoCtx(info, callerId) {
131
- validateDownloadableResourceType("getOnDemandBlob", info.type);
132
- let blob = this.keyToOnDemand.get(blobKey(info.id));
133
- if (blob === undefined) {
134
- blob = new OnDemandBlobHolder(getSize(info), newRemoteHandle(info, this.signer));
135
- this.keyToOnDemand.set(blobKey(info.id), blob);
136
- }
137
- blob.attach(callerId);
138
- return blob.getHandle();
139
- }
140
- /** Gets a path from a handle. */
141
- getLocalPath(handle) {
142
- const { path } = parseLocalHandle(handle, this.signer);
143
- return path;
144
- }
145
- async getContent(handle, optionsOrRange) {
146
- let options = {};
147
- if (typeof optionsOrRange === "object" && optionsOrRange !== null) {
148
- if ("range" in optionsOrRange) {
149
- options = optionsOrRange;
150
- }
151
- else {
152
- const range = optionsOrRange;
153
- validateRangeBytes(range, `getContent`);
154
- options = { range };
155
- }
156
- }
157
- const request = () => this.withContent(handle, {
158
- ...options,
159
- handler: async (content) => {
160
- const chunks = [];
161
- for await (const chunk of content) {
162
- options.signal?.throwIfAborted();
163
- chunks.push(chunk);
164
- }
165
- return Buffer.concat(chunks);
166
- },
167
- });
168
- try {
169
- return await request();
170
- }
171
- catch (error) {
172
- if (isOffByOneError(error)) {
173
- return await request();
174
- }
175
- throw error;
176
- }
177
- }
178
- /** Gets a content stream of a blob by a handle and calls handler with it. */
179
- async withContent(handle, options) {
180
- const { range, signal, handler } = options;
181
- if (isLocalBlobHandle(handle)) {
182
- return await withFileContent({ path: this.getLocalPath(handle), range, signal, handler });
183
- }
184
- if (isRemoteBlobHandle(handle)) {
185
- const result = parseRemoteHandle(handle, this.signer);
186
- const key = blobKey(result.info.id);
187
- const filePath = await this.rangesCache.get(key, range ?? { from: 0, to: result.size });
188
- signal?.throwIfAborted();
189
- if (filePath)
190
- return await withFileContent({ path: filePath, range, signal, handler });
191
- return await this.clientDownload.withBlobContent(result.info, { signal }, options, async (content, size) => {
192
- const [handlerStream, cacheStream] = content.tee();
193
- const handlerPromise = handler(handlerStream, size);
194
- buffer(cacheStream)
195
- .then((data) => this.rangesCache.set(key, range ?? { from: 0, to: result.size }, data))
196
- .catch(() => {
197
- // Ignore cache errors - they shouldn't affect the main handler result
198
- // This prevents unhandled promise rejections when the stream fails
199
- });
200
- return await handlerPromise;
201
- });
202
- }
203
- throw new Error("Malformed remote handle");
204
- }
205
- /**
206
- * Creates computable that will return blob content once it is downloaded.
207
- * Uses downloaded blob handle under the hood, so stores corresponding blob in file system.
208
- */
209
- getComputableContent(res, range) {
210
- if (range) {
211
- validateRangeBytes(range, `getComputableContent`);
212
- }
213
- return Computable.make((ctx) => this.getDownloadedBlob(res, ctx), {
214
- postprocessValue: (v) => (v ? this.getContent(v.handle, { range }) : undefined),
215
- }).withStableType();
216
- }
217
- getLastLogs(res, lines, ctx) {
218
- if (ctx == undefined)
219
- return Computable.make((ctx) => this.getLastLogs(res, lines, ctx));
220
- const r = treeEntryToResourceInfo(res, ctx);
221
- const callerId = randomUUID();
222
- ctx.addOnDestroy(() => this.releaseBlob(r, callerId));
223
- const result = this.getLastLogsNoCtx(ctx.watcher, r, lines, callerId);
224
- if (result == undefined)
225
- ctx.markUnstable("either a file was not downloaded or logs was not read");
226
- return result;
227
- }
228
- getLastLogsNoCtx(w, rInfo, lines, callerId) {
229
- validateDownloadableResourceType("getLastLogs", rInfo.type);
230
- const blob = this.getDownloadedBlobNoCtx(w, rInfo, callerId);
231
- if (blob == undefined)
232
- return undefined;
233
- const { path } = parseLocalHandle(blob.handle, this.signer);
234
- let logGetter = this.idToLastLines.get(blobKey(rInfo.id));
235
- if (logGetter == undefined) {
236
- const newLogGetter = new LastLinesGetter(path, lines);
237
- this.idToLastLines.set(blobKey(rInfo.id), newLogGetter);
238
- logGetter = newLogGetter;
239
- }
240
- const result = logGetter.getOrSchedule(w);
241
- if (result.error)
242
- throw result.error;
243
- return result.log;
244
- }
245
- getProgressLog(res, patternToSearch, ctx) {
246
- if (ctx == undefined)
247
- return Computable.make((ctx) => this.getProgressLog(res, patternToSearch, ctx));
248
- const r = treeEntryToResourceInfo(res, ctx);
249
- const callerId = randomUUID();
250
- ctx.addOnDestroy(() => this.releaseBlob(r, callerId));
251
- const result = this.getProgressLogNoCtx(ctx.watcher, r, patternToSearch, callerId);
252
- if (result === undefined)
253
- ctx.markUnstable("either a file was not downloaded or a progress log was not read");
254
- return result;
255
- }
256
- getProgressLogNoCtx(w, rInfo, patternToSearch, callerId) {
257
- validateDownloadableResourceType("getProgressLog", rInfo.type);
258
- const blob = this.getDownloadedBlobNoCtx(w, rInfo, callerId);
259
- if (blob == undefined)
260
- return undefined;
261
- const { path } = parseLocalHandle(blob.handle, this.signer);
262
- let logGetter = this.idToProgressLog.get(blobKey(rInfo.id));
263
- if (logGetter == undefined) {
264
- const newLogGetter = new LastLinesGetter(path, 1, patternToSearch);
265
- this.idToProgressLog.set(blobKey(rInfo.id), newLogGetter);
266
- logGetter = newLogGetter;
267
- }
268
- const result = logGetter.getOrSchedule(w);
269
- if (result.error)
270
- throw result.error;
271
- return result.log;
272
- }
273
- getLogHandle(res, ctx) {
274
- if (ctx == undefined)
275
- return Computable.make((ctx) => this.getLogHandle(res, ctx));
276
- const r = treeEntryToResourceInfo(res, ctx);
277
- return this.getLogHandleNoCtx(r);
278
- }
279
- getLogHandleNoCtx(rInfo) {
280
- validateDownloadableResourceType("getLogHandle", rInfo.type);
281
- return newLogHandle(false, rInfo);
282
- }
283
- async lastLines(handle, lineCount, offsetBytes, // if 0n, then start from the end.
284
- searchStr) {
285
- const resp = await this.clientLogs.lastLines(getResourceInfoFromLogHandle(handle), lineCount, BigInt(offsetBytes ?? 0), searchStr);
286
- return {
287
- live: false,
288
- shouldUpdateHandle: false,
289
- data: resp.data,
290
- size: Number(resp.size),
291
- newOffset: Number(resp.newOffset),
292
- };
293
- }
294
- async readText(handle, lineCount, offsetBytes, searchStr) {
295
- const resp = await this.clientLogs.readText(getResourceInfoFromLogHandle(handle), lineCount, BigInt(offsetBytes ?? 0), searchStr);
296
- return {
297
- live: false,
298
- shouldUpdateHandle: false,
299
- data: resp.data,
300
- size: Number(resp.size),
301
- newOffset: Number(resp.newOffset),
302
- };
303
- }
304
- async releaseBlob(rInfo, callerId) {
305
- const task = this.keyToDownload.get(blobKey(rInfo.id));
306
- if (task == undefined) {
307
- return;
308
- }
309
- if (this.cache.existsFile(blobKey(rInfo.id))) {
310
- const toDelete = this.cache.removeFile(blobKey(rInfo.id), callerId);
311
- await Promise.all(toDelete.map(async (cachedFile) => {
312
- await fsp.rm(cachedFile.path);
313
- this.cache.removeCache(cachedFile);
314
- this.removeTask(mapGet(this.keyToDownload, pathToKey(cachedFile.path)), `the task ${stringifyWithResourceId(cachedFile)} was removed` +
315
- `from cache along with ${stringifyWithResourceId(toDelete.map((d) => d.path))}`);
316
- }));
317
- }
318
- else {
319
- // The task is still in a downloading queue.
320
- const deleted = task.counter.dec(callerId);
321
- if (deleted) {
322
- this.removeTask(task, `the task ${stringifyWithResourceId(task.info())} was removed from cache`);
323
- }
324
- }
325
- }
326
- removeTask(task, reason) {
327
- task.abort(reason);
328
- task.change.markChanged(`download task for ${task.path} removed: ${reason}`);
329
- this.keyToDownload.delete(pathToKey(task.path));
330
- this.idToLastLines.delete(blobKey(task.rInfo.id));
331
- this.idToProgressLog.delete(blobKey(task.rInfo.id));
332
- }
333
- async releaseOnDemandBlob(blobId, callerId) {
334
- const deleted = this.keyToOnDemand.get(blobKey(blobId))?.release(callerId) ?? false;
335
- if (deleted)
336
- this.keyToOnDemand.delete(blobKey(blobId));
337
- }
338
- /** Removes all files from a hard drive. */
339
- async releaseAll() {
340
- this.downloadQueue.stop();
341
- this.keyToDownload.forEach((task, key) => {
342
- this.keyToDownload.delete(key);
343
- task.change.markChanged(`task ${resourceIdToString(task.rInfo.id)} released`);
344
- });
345
- }
346
- async dispose() {
347
- await this.rangesCache.dispose();
348
- }
349
- async [Symbol.asyncDispose]() {
350
- await this.dispose();
351
- }
352
- }
28
+ * and notifies every watcher when a file were downloaded. */
29
+ var DownloadDriver = class DownloadDriver {
30
+ /** Represents a unique key to the path of a blob as a map. */
31
+ keyToDownload = /* @__PURE__ */ new Map();
32
+ /** Writes and removes files to a hard drive and holds a counter for every
33
+ * file that should be kept. */
34
+ cache;
35
+ rangesCache;
36
+ /** Downloads files and writes them to the local dir. */
37
+ downloadQueue;
38
+ keyToOnDemand = /* @__PURE__ */ new Map();
39
+ idToLastLines = /* @__PURE__ */ new Map();
40
+ idToProgressLog = /* @__PURE__ */ new Map();
41
+ saveDir;
42
+ constructor(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops) {
43
+ this.logger = logger;
44
+ this.clientDownload = clientDownload;
45
+ this.clientLogs = clientLogs;
46
+ this.rangesCacheDir = rangesCacheDir;
47
+ this.signer = signer;
48
+ this.ops = ops;
49
+ this.cache = new FilesCache(this.ops.cacheSoftSizeBytes);
50
+ const fsRanges = new SparseCacheFsRanges(this.logger, this.rangesCacheDir);
51
+ const fsStorage = new SparseCacheFsFile(this.logger, this.rangesCacheDir);
52
+ this.rangesCache = new SparseCache(this.logger, this.ops.rangesCacheMaxSizeBytes, fsRanges, fsStorage);
53
+ this.downloadQueue = new TaskProcessor(this.logger, ops.nConcurrentDownloads);
54
+ this.saveDir = path$1.resolve(saveDir);
55
+ }
56
+ static async init(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops) {
57
+ const driver = new DownloadDriver(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops);
58
+ await driver.rangesCache.reset();
59
+ return driver;
60
+ }
61
+ getDownloadedBlob(res, ctx) {
62
+ if (ctx === void 0) return Computable.make((ctx) => this.getDownloadedBlob(res, ctx));
63
+ const rInfo = treeEntryToResourceInfo(res, ctx);
64
+ const callerId = randomUUID();
65
+ ctx.addOnDestroy(() => this.releaseBlob(rInfo, callerId));
66
+ const result = this.getDownloadedBlobNoCtx(ctx.watcher, rInfo, callerId);
67
+ if (result == void 0) ctx.markUnstable("download blob is still undefined");
68
+ return result;
69
+ }
70
+ getDownloadedBlobNoCtx(w, rInfo, callerId) {
71
+ validateDownloadableResourceType("getDownloadedBlob", rInfo.type);
72
+ const task = this.getOrSetNewTask(rInfo, callerId);
73
+ task.attach(w, callerId);
74
+ const result = task.getBlob();
75
+ if (!result.done) return;
76
+ if (result.result.ok) return result.result.value;
77
+ throw result.result.error;
78
+ }
79
+ getOrSetNewTask(rInfo, callerId) {
80
+ const key = blobKey(rInfo.id);
81
+ const inMemoryTask = this.keyToDownload.get(key);
82
+ if (inMemoryTask) return inMemoryTask;
83
+ const fPath = path$1.resolve(this.saveDir, key);
84
+ const newTask = new DownloadBlobTask(this.logger, this.clientDownload, rInfo, newLocalHandle(fPath, this.signer), fPath);
85
+ this.keyToDownload.set(key, newTask);
86
+ this.downloadQueue.push({
87
+ fn: () => this.downloadBlob(newTask, callerId),
88
+ recoverableErrorPredicate: (e) => !nonRecoverableError(e)
89
+ });
90
+ return newTask;
91
+ }
92
+ async downloadBlob(task, callerId) {
93
+ await task.download();
94
+ const blob = task.getBlob();
95
+ if (blob.done && blob.result.ok) this.cache.addCache(task, callerId);
96
+ }
97
+ getOnDemandBlob(res, ctx) {
98
+ if (ctx === void 0) return Computable.make((ctx) => this.getOnDemandBlob(res, ctx));
99
+ const rInfo = isPlTreeEntry(res) ? makeResourceSnapshot(res, OnDemandBlobResourceSnapshot, ctx) : res;
100
+ const callerId = randomUUID();
101
+ ctx.addOnDestroy(() => this.releaseOnDemandBlob(rInfo.id, callerId));
102
+ return this.getOnDemandBlobNoCtx(rInfo, callerId);
103
+ }
104
+ getOnDemandBlobNoCtx(info, callerId) {
105
+ validateDownloadableResourceType("getOnDemandBlob", info.type);
106
+ let blob = this.keyToOnDemand.get(blobKey(info.id));
107
+ if (blob === void 0) {
108
+ blob = new OnDemandBlobHolder(getSize(info), newRemoteHandle(info, this.signer));
109
+ this.keyToOnDemand.set(blobKey(info.id), blob);
110
+ }
111
+ blob.attach(callerId);
112
+ return blob.getHandle();
113
+ }
114
+ /** Gets a path from a handle. */
115
+ getLocalPath(handle) {
116
+ const { path } = parseLocalHandle(handle, this.signer);
117
+ return path;
118
+ }
119
+ async getContent(handle, optionsOrRange) {
120
+ let options = {};
121
+ if (typeof optionsOrRange === "object" && optionsOrRange !== null) if ("range" in optionsOrRange) options = optionsOrRange;
122
+ else {
123
+ const range = optionsOrRange;
124
+ validateRangeBytes(range, `getContent`);
125
+ options = { range };
126
+ }
127
+ const request = () => this.withContent(handle, {
128
+ ...options,
129
+ handler: async (content) => {
130
+ const chunks = [];
131
+ for await (const chunk of content) {
132
+ options.signal?.throwIfAborted();
133
+ chunks.push(chunk);
134
+ }
135
+ return Buffer.concat(chunks);
136
+ }
137
+ });
138
+ try {
139
+ return await request();
140
+ } catch (error) {
141
+ if (isOffByOneError(error)) return await request();
142
+ throw error;
143
+ }
144
+ }
145
+ /** Gets a content stream of a blob by a handle and calls handler with it. */
146
+ async withContent(handle, options) {
147
+ const { range, signal, handler } = options;
148
+ if (isLocalBlobHandle(handle)) return await withFileContent({
149
+ path: this.getLocalPath(handle),
150
+ range,
151
+ signal,
152
+ handler
153
+ });
154
+ if (isRemoteBlobHandle(handle)) {
155
+ const result = parseRemoteHandle(handle, this.signer);
156
+ const key = blobKey(result.info.id);
157
+ const filePath = await this.rangesCache.get(key, range ?? {
158
+ from: 0,
159
+ to: result.size
160
+ });
161
+ signal?.throwIfAborted();
162
+ if (filePath) return await withFileContent({
163
+ path: filePath,
164
+ range,
165
+ signal,
166
+ handler
167
+ });
168
+ return await this.clientDownload.withBlobContent(result.info, { signal }, options, async (content, size) => {
169
+ const [handlerStream, cacheStream] = content.tee();
170
+ const handlerPromise = handler(handlerStream, size);
171
+ buffer(cacheStream).then((data) => this.rangesCache.set(key, range ?? {
172
+ from: 0,
173
+ to: result.size
174
+ }, data)).catch(() => {});
175
+ return await handlerPromise;
176
+ });
177
+ }
178
+ throw new Error("Malformed remote handle");
179
+ }
180
+ /**
181
+ * Creates computable that will return blob content once it is downloaded.
182
+ * Uses downloaded blob handle under the hood, so stores corresponding blob in file system.
183
+ */
184
+ getComputableContent(res, range) {
185
+ if (range) validateRangeBytes(range, `getComputableContent`);
186
+ return Computable.make((ctx) => this.getDownloadedBlob(res, ctx), { postprocessValue: (v) => v ? this.getContent(v.handle, { range }) : void 0 }).withStableType();
187
+ }
188
+ getLastLogs(res, lines, ctx) {
189
+ if (ctx == void 0) return Computable.make((ctx) => this.getLastLogs(res, lines, ctx));
190
+ const r = treeEntryToResourceInfo(res, ctx);
191
+ const callerId = randomUUID();
192
+ ctx.addOnDestroy(() => this.releaseBlob(r, callerId));
193
+ const result = this.getLastLogsNoCtx(ctx.watcher, r, lines, callerId);
194
+ if (result == void 0) ctx.markUnstable("either a file was not downloaded or logs was not read");
195
+ return result;
196
+ }
197
+ getLastLogsNoCtx(w, rInfo, lines, callerId) {
198
+ validateDownloadableResourceType("getLastLogs", rInfo.type);
199
+ const blob = this.getDownloadedBlobNoCtx(w, rInfo, callerId);
200
+ if (blob == void 0) return void 0;
201
+ const { path } = parseLocalHandle(blob.handle, this.signer);
202
+ let logGetter = this.idToLastLines.get(blobKey(rInfo.id));
203
+ if (logGetter == void 0) {
204
+ const newLogGetter = new LastLinesGetter(path, lines);
205
+ this.idToLastLines.set(blobKey(rInfo.id), newLogGetter);
206
+ logGetter = newLogGetter;
207
+ }
208
+ const result = logGetter.getOrSchedule(w);
209
+ if (result.error) throw result.error;
210
+ return result.log;
211
+ }
212
+ getProgressLog(res, patternToSearch, ctx) {
213
+ if (ctx == void 0) return Computable.make((ctx) => this.getProgressLog(res, patternToSearch, ctx));
214
+ const r = treeEntryToResourceInfo(res, ctx);
215
+ const callerId = randomUUID();
216
+ ctx.addOnDestroy(() => this.releaseBlob(r, callerId));
217
+ const result = this.getProgressLogNoCtx(ctx.watcher, r, patternToSearch, callerId);
218
+ if (result === void 0) ctx.markUnstable("either a file was not downloaded or a progress log was not read");
219
+ return result;
220
+ }
221
+ getProgressLogNoCtx(w, rInfo, patternToSearch, callerId) {
222
+ validateDownloadableResourceType("getProgressLog", rInfo.type);
223
+ const blob = this.getDownloadedBlobNoCtx(w, rInfo, callerId);
224
+ if (blob == void 0) return void 0;
225
+ const { path } = parseLocalHandle(blob.handle, this.signer);
226
+ let logGetter = this.idToProgressLog.get(blobKey(rInfo.id));
227
+ if (logGetter == void 0) {
228
+ const newLogGetter = new LastLinesGetter(path, 1, patternToSearch);
229
+ this.idToProgressLog.set(blobKey(rInfo.id), newLogGetter);
230
+ logGetter = newLogGetter;
231
+ }
232
+ const result = logGetter.getOrSchedule(w);
233
+ if (result.error) throw result.error;
234
+ return result.log;
235
+ }
236
+ getLogHandle(res, ctx) {
237
+ if (ctx == void 0) return Computable.make((ctx) => this.getLogHandle(res, ctx));
238
+ const r = treeEntryToResourceInfo(res, ctx);
239
+ return this.getLogHandleNoCtx(r);
240
+ }
241
+ getLogHandleNoCtx(rInfo) {
242
+ validateDownloadableResourceType("getLogHandle", rInfo.type);
243
+ return newLogHandle(false, rInfo);
244
+ }
245
+ async lastLines(handle, lineCount, offsetBytes, searchStr) {
246
+ const resp = await this.clientLogs.lastLines(getResourceInfoFromLogHandle(handle), lineCount, BigInt(offsetBytes ?? 0), searchStr);
247
+ return {
248
+ live: false,
249
+ shouldUpdateHandle: false,
250
+ data: resp.data,
251
+ size: Number(resp.size),
252
+ newOffset: Number(resp.newOffset)
253
+ };
254
+ }
255
+ async readText(handle, lineCount, offsetBytes, searchStr) {
256
+ const resp = await this.clientLogs.readText(getResourceInfoFromLogHandle(handle), lineCount, BigInt(offsetBytes ?? 0), searchStr);
257
+ return {
258
+ live: false,
259
+ shouldUpdateHandle: false,
260
+ data: resp.data,
261
+ size: Number(resp.size),
262
+ newOffset: Number(resp.newOffset)
263
+ };
264
+ }
265
+ async releaseBlob(rInfo, callerId) {
266
+ const task = this.keyToDownload.get(blobKey(rInfo.id));
267
+ if (task == void 0) return;
268
+ if (this.cache.existsFile(blobKey(rInfo.id))) {
269
+ const toDelete = this.cache.removeFile(blobKey(rInfo.id), callerId);
270
+ await Promise.all(toDelete.map(async (cachedFile) => {
271
+ await fsp.rm(cachedFile.path);
272
+ this.cache.removeCache(cachedFile);
273
+ this.removeTask(mapGet(this.keyToDownload, pathToKey(cachedFile.path)), `the task ${stringifyWithResourceId(cachedFile)} was removedfrom cache along with ${stringifyWithResourceId(toDelete.map((d) => d.path))}`);
274
+ }));
275
+ } else if (task.counter.dec(callerId)) this.removeTask(task, `the task ${stringifyWithResourceId(task.info())} was removed from cache`);
276
+ }
277
+ removeTask(task, reason) {
278
+ task.abort(reason);
279
+ task.change.markChanged(`download task for ${task.path} removed: ${reason}`);
280
+ this.keyToDownload.delete(pathToKey(task.path));
281
+ this.idToLastLines.delete(blobKey(task.rInfo.id));
282
+ this.idToProgressLog.delete(blobKey(task.rInfo.id));
283
+ }
284
+ async releaseOnDemandBlob(blobId, callerId) {
285
+ if (this.keyToOnDemand.get(blobKey(blobId))?.release(callerId) ?? false) this.keyToOnDemand.delete(blobKey(blobId));
286
+ }
287
+ /** Removes all files from a hard drive. */
288
+ async releaseAll() {
289
+ this.downloadQueue.stop();
290
+ this.keyToDownload.forEach((task, key) => {
291
+ this.keyToDownload.delete(key);
292
+ task.change.markChanged(`task ${resourceIdToString(task.rInfo.id)} released`);
293
+ });
294
+ }
295
+ async dispose() {
296
+ await this.rangesCache.dispose();
297
+ }
298
+ async [Symbol.asyncDispose]() {
299
+ await this.dispose();
300
+ }
301
+ };
353
302
  /** Keeps a counter to the on demand handle. */
354
- class OnDemandBlobHolder {
355
- size;
356
- handle;
357
- counter = new CallersCounter();
358
- constructor(size, handle) {
359
- this.size = size;
360
- this.handle = handle;
361
- }
362
- getHandle() {
363
- return { handle: this.handle, size: this.size };
364
- }
365
- attach(callerId) {
366
- this.counter.inc(callerId);
367
- }
368
- release(callerId) {
369
- return this.counter.dec(callerId);
370
- }
371
- }
372
- class LastLinesGetter {
373
- path;
374
- lines;
375
- patternToSearch;
376
- updater;
377
- log;
378
- change = new ChangeSource();
379
- error = undefined;
380
- constructor(path, lines, patternToSearch) {
381
- this.path = path;
382
- this.lines = lines;
383
- this.patternToSearch = patternToSearch;
384
- this.updater = new Updater(async () => this.update());
385
- }
386
- getOrSchedule(w) {
387
- this.change.attachWatcher(w);
388
- this.updater.schedule();
389
- return {
390
- log: this.log,
391
- error: this.error,
392
- };
393
- }
394
- async update() {
395
- try {
396
- const newLogs = await getLastLines(this.path, this.lines, this.patternToSearch);
397
- if (this.log != newLogs)
398
- this.change.markChanged(`logs for ${this.path} updated`);
399
- this.log = newLogs;
400
- }
401
- catch (e) {
402
- if (isNotFoundError(e)) {
403
- // No resource
404
- this.log = "";
405
- this.error = e;
406
- this.change.markChanged(`log update for ${this.path} failed, resource not found`);
407
- return;
408
- }
409
- throw e;
410
- }
411
- }
412
- }
303
+ var OnDemandBlobHolder = class {
304
+ counter = new CallersCounter();
305
+ constructor(size, handle) {
306
+ this.size = size;
307
+ this.handle = handle;
308
+ }
309
+ getHandle() {
310
+ return {
311
+ handle: this.handle,
312
+ size: this.size
313
+ };
314
+ }
315
+ attach(callerId) {
316
+ this.counter.inc(callerId);
317
+ }
318
+ release(callerId) {
319
+ return this.counter.dec(callerId);
320
+ }
321
+ };
322
+ var LastLinesGetter = class {
323
+ updater;
324
+ log;
325
+ change = new ChangeSource();
326
+ error = void 0;
327
+ constructor(path, lines, patternToSearch) {
328
+ this.path = path;
329
+ this.lines = lines;
330
+ this.patternToSearch = patternToSearch;
331
+ this.updater = new Updater(async () => this.update());
332
+ }
333
+ getOrSchedule(w) {
334
+ this.change.attachWatcher(w);
335
+ this.updater.schedule();
336
+ return {
337
+ log: this.log,
338
+ error: this.error
339
+ };
340
+ }
341
+ async update() {
342
+ try {
343
+ const newLogs = await getLastLines(this.path, this.lines, this.patternToSearch);
344
+ if (this.log != newLogs) this.change.markChanged(`logs for ${this.path} updated`);
345
+ this.log = newLogs;
346
+ } catch (e) {
347
+ if (isNotFoundError(e)) {
348
+ this.log = "";
349
+ this.error = e;
350
+ this.change.markChanged(`log update for ${this.path} failed, resource not found`);
351
+ return;
352
+ }
353
+ throw e;
354
+ }
355
+ }
356
+ };
413
357
  /** Gets last lines from a file by reading the file from the top and keeping
414
- * last N lines in a window queue. */
358
+ * last N lines in a window queue. */
415
359
  async function getLastLines(fPath, nLines, patternToSearch) {
416
- let inStream;
417
- let rl;
418
- try {
419
- inStream = fs.createReadStream(fPath);
420
- rl = readline.createInterface({ input: inStream, crlfDelay: Infinity });
421
- const lines = new Denque();
422
- for await (const line of rl) {
423
- if (patternToSearch != undefined && !line.includes(patternToSearch))
424
- continue;
425
- lines.push(line);
426
- if (lines.length > nLines) {
427
- lines.shift();
428
- }
429
- }
430
- // last EOL is for keeping backward compat with platforma implementation.
431
- return lines.toArray().join(os.EOL) + os.EOL;
432
- }
433
- finally {
434
- // Cleanup resources in finally block to ensure they're always cleaned up
435
- try {
436
- if (rl) {
437
- rl.close();
438
- }
439
- }
440
- catch (cleanupError) {
441
- console.error("Error closing readline interface:", cleanupError);
442
- }
443
- try {
444
- if (inStream && !inStream.destroyed) {
445
- inStream.destroy();
446
- }
447
- }
448
- catch (cleanupError) {
449
- console.error("Error destroying read stream:", cleanupError);
450
- }
451
- }
360
+ let inStream;
361
+ let rl;
362
+ try {
363
+ inStream = fs$1.createReadStream(fPath);
364
+ rl = readline.createInterface({
365
+ input: inStream,
366
+ crlfDelay: Infinity
367
+ });
368
+ const lines = new Denque();
369
+ for await (const line of rl) {
370
+ if (patternToSearch != void 0 && !line.includes(patternToSearch)) continue;
371
+ lines.push(line);
372
+ if (lines.length > nLines) lines.shift();
373
+ }
374
+ return lines.toArray().join(os.EOL) + os.EOL;
375
+ } finally {
376
+ try {
377
+ if (rl) rl.close();
378
+ } catch (cleanupError) {
379
+ console.error("Error closing readline interface:", cleanupError);
380
+ }
381
+ try {
382
+ if (inStream && !inStream.destroyed) inStream.destroy();
383
+ } catch (cleanupError) {
384
+ console.error("Error destroying read stream:", cleanupError);
385
+ }
386
+ }
452
387
  }
453
388
  function validateDownloadableResourceType(methodName, rType) {
454
- if (!rType.name.startsWith("Blob/")) {
455
- let message = `${methodName}: wrong resource type: ${rType.name}, expected: a resource of type that starts with 'Blob/'.`;
456
- if (rType.name == "Blob")
457
- message += ` If it's called from workflow, should a file be exported with 'file.exportFile' function?`;
458
- throw new WrongResourceTypeError(message);
459
- }
389
+ if (!rType.name.startsWith("Blob/")) {
390
+ let message = `${methodName}: wrong resource type: ${rType.name}, expected: a resource of type that starts with 'Blob/'.`;
391
+ if (rType.name == "Blob") message += ` If it's called from workflow, should a file be exported with 'file.exportFile' function?`;
392
+ throw new WrongResourceTypeError(message);
393
+ }
460
394
  }
461
395
 
396
+ //#endregion
462
397
  export { DownloadDriver };
463
- //# sourceMappingURL=download_blob.js.map
398
+ //# sourceMappingURL=download_blob.js.map