@milaboratories/pl-drivers 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/dist/clients/constructors.cjs +45 -0
  2. package/dist/clients/constructors.cjs.map +1 -0
  3. package/dist/clients/constructors.d.ts +0 -1
  4. package/dist/clients/constructors.js +39 -0
  5. package/dist/clients/constructors.js.map +1 -0
  6. package/dist/clients/download.cjs +149 -0
  7. package/dist/clients/download.cjs.map +1 -0
  8. package/dist/clients/download.d.ts +0 -1
  9. package/dist/clients/download.js +121 -0
  10. package/dist/clients/download.js.map +1 -0
  11. package/dist/clients/logs.cjs +44 -0
  12. package/dist/clients/logs.cjs.map +1 -0
  13. package/dist/clients/logs.d.ts +0 -1
  14. package/dist/clients/logs.js +42 -0
  15. package/dist/clients/logs.js.map +1 -0
  16. package/dist/clients/ls_api.cjs +23 -0
  17. package/dist/clients/ls_api.cjs.map +1 -0
  18. package/dist/clients/ls_api.d.ts +0 -1
  19. package/dist/clients/ls_api.js +21 -0
  20. package/dist/clients/ls_api.js.map +1 -0
  21. package/dist/clients/progress.cjs +58 -0
  22. package/dist/clients/progress.cjs.map +1 -0
  23. package/dist/clients/progress.d.ts +1 -3
  24. package/dist/clients/progress.js +56 -0
  25. package/dist/clients/progress.js.map +1 -0
  26. package/dist/clients/upload.cjs +209 -0
  27. package/dist/clients/upload.cjs.map +1 -0
  28. package/dist/clients/upload.d.ts +8 -4
  29. package/dist/clients/upload.js +183 -0
  30. package/dist/clients/upload.js.map +1 -0
  31. package/dist/drivers/download_blob/blob_key.cjs +34 -0
  32. package/dist/drivers/download_blob/blob_key.cjs.map +1 -0
  33. package/dist/drivers/download_blob/blob_key.d.ts +0 -1
  34. package/dist/drivers/download_blob/blob_key.js +12 -0
  35. package/dist/drivers/download_blob/blob_key.js.map +1 -0
  36. package/dist/drivers/download_blob/download_blob.cjs +442 -0
  37. package/dist/drivers/download_blob/download_blob.cjs.map +1 -0
  38. package/dist/drivers/download_blob/download_blob.d.ts +0 -1
  39. package/dist/drivers/download_blob/download_blob.js +417 -0
  40. package/dist/drivers/download_blob/download_blob.js.map +1 -0
  41. package/dist/drivers/download_blob/download_blob_task.cjs +170 -0
  42. package/dist/drivers/download_blob/download_blob_task.cjs.map +1 -0
  43. package/dist/drivers/download_blob/download_blob_task.d.ts +0 -1
  44. package/dist/drivers/download_blob/download_blob_task.js +146 -0
  45. package/dist/drivers/download_blob/download_blob_task.js.map +1 -0
  46. package/dist/drivers/download_blob/sparse_cache/cache.cjs +202 -0
  47. package/dist/drivers/download_blob/sparse_cache/cache.cjs.map +1 -0
  48. package/dist/drivers/download_blob/sparse_cache/cache.d.ts +0 -1
  49. package/dist/drivers/download_blob/sparse_cache/cache.js +197 -0
  50. package/dist/drivers/download_blob/sparse_cache/cache.js.map +1 -0
  51. package/dist/drivers/download_blob/sparse_cache/file.cjs +61 -0
  52. package/dist/drivers/download_blob/sparse_cache/file.cjs.map +1 -0
  53. package/dist/drivers/download_blob/sparse_cache/file.d.ts +0 -1
  54. package/dist/drivers/download_blob/sparse_cache/file.js +39 -0
  55. package/dist/drivers/download_blob/sparse_cache/file.js.map +1 -0
  56. package/dist/drivers/download_blob/sparse_cache/ranges.cjs +104 -0
  57. package/dist/drivers/download_blob/sparse_cache/ranges.cjs.map +1 -0
  58. package/dist/drivers/download_blob/sparse_cache/ranges.d.ts +0 -1
  59. package/dist/drivers/download_blob/sparse_cache/ranges.js +76 -0
  60. package/dist/drivers/download_blob/sparse_cache/ranges.js.map +1 -0
  61. package/dist/drivers/download_blob_url/driver.cjs +169 -0
  62. package/dist/drivers/download_blob_url/driver.cjs.map +1 -0
  63. package/dist/drivers/download_blob_url/driver.d.ts +0 -1
  64. package/dist/drivers/download_blob_url/driver.js +148 -0
  65. package/dist/drivers/download_blob_url/driver.js.map +1 -0
  66. package/dist/drivers/download_blob_url/driver_id.cjs +9 -0
  67. package/dist/drivers/download_blob_url/driver_id.cjs.map +1 -0
  68. package/dist/drivers/download_blob_url/driver_id.d.ts +0 -1
  69. package/dist/drivers/download_blob_url/driver_id.js +7 -0
  70. package/dist/drivers/download_blob_url/driver_id.js.map +1 -0
  71. package/dist/drivers/download_blob_url/snapshot.cjs +18 -0
  72. package/dist/drivers/download_blob_url/snapshot.cjs.map +1 -0
  73. package/dist/drivers/download_blob_url/snapshot.d.ts +2 -3
  74. package/dist/drivers/download_blob_url/snapshot.js +15 -0
  75. package/dist/drivers/download_blob_url/snapshot.js.map +1 -0
  76. package/dist/drivers/download_blob_url/task.cjs +209 -0
  77. package/dist/drivers/download_blob_url/task.cjs.map +1 -0
  78. package/dist/drivers/download_blob_url/task.d.ts +0 -1
  79. package/dist/drivers/download_blob_url/task.js +184 -0
  80. package/dist/drivers/download_blob_url/task.js.map +1 -0
  81. package/dist/drivers/download_blob_url/url.d.ts +1 -1
  82. package/dist/drivers/download_url/driver.cjs +149 -0
  83. package/dist/drivers/download_url/driver.cjs.map +1 -0
  84. package/dist/drivers/download_url/driver.d.ts +0 -1
  85. package/dist/drivers/download_url/driver.js +128 -0
  86. package/dist/drivers/download_url/driver.js.map +1 -0
  87. package/dist/drivers/download_url/task.cjs +150 -0
  88. package/dist/drivers/download_url/task.cjs.map +1 -0
  89. package/dist/drivers/download_url/task.d.ts +0 -1
  90. package/dist/drivers/download_url/task.js +124 -0
  91. package/dist/drivers/download_url/task.js.map +1 -0
  92. package/dist/drivers/helpers/download_local_handle.cjs +26 -0
  93. package/dist/drivers/helpers/download_local_handle.cjs.map +1 -0
  94. package/dist/drivers/helpers/download_local_handle.d.ts +0 -1
  95. package/dist/drivers/helpers/download_local_handle.js +22 -0
  96. package/dist/drivers/helpers/download_local_handle.js.map +1 -0
  97. package/dist/drivers/helpers/download_remote_handle.cjs +36 -0
  98. package/dist/drivers/helpers/download_remote_handle.cjs.map +1 -0
  99. package/dist/drivers/helpers/download_remote_handle.d.ts +0 -1
  100. package/dist/drivers/helpers/download_remote_handle.js +32 -0
  101. package/dist/drivers/helpers/download_remote_handle.js.map +1 -0
  102. package/dist/drivers/helpers/files_cache.cjs +68 -0
  103. package/dist/drivers/helpers/files_cache.cjs.map +1 -0
  104. package/dist/drivers/helpers/files_cache.d.ts +0 -1
  105. package/dist/drivers/helpers/files_cache.js +66 -0
  106. package/dist/drivers/helpers/files_cache.js.map +1 -0
  107. package/dist/drivers/helpers/helpers.cjs +34 -0
  108. package/dist/drivers/helpers/helpers.cjs.map +1 -0
  109. package/dist/drivers/helpers/helpers.d.ts +0 -1
  110. package/dist/drivers/helpers/helpers.js +31 -0
  111. package/dist/drivers/helpers/helpers.js.map +1 -0
  112. package/dist/drivers/helpers/logs_handle.cjs +50 -0
  113. package/dist/drivers/helpers/logs_handle.cjs.map +1 -0
  114. package/dist/drivers/helpers/logs_handle.d.ts +0 -1
  115. package/dist/drivers/helpers/logs_handle.js +43 -0
  116. package/dist/drivers/helpers/logs_handle.js.map +1 -0
  117. package/dist/drivers/helpers/ls_remote_import_handle.cjs +34 -0
  118. package/dist/drivers/helpers/ls_remote_import_handle.cjs.map +1 -0
  119. package/dist/drivers/helpers/ls_remote_import_handle.d.ts +0 -1
  120. package/dist/drivers/helpers/ls_remote_import_handle.js +29 -0
  121. package/dist/drivers/helpers/ls_remote_import_handle.js.map +1 -0
  122. package/dist/drivers/helpers/ls_storage_entry.cjs +64 -0
  123. package/dist/drivers/helpers/ls_storage_entry.cjs.map +1 -0
  124. package/dist/drivers/helpers/ls_storage_entry.d.ts +0 -1
  125. package/dist/drivers/helpers/ls_storage_entry.js +58 -0
  126. package/dist/drivers/helpers/ls_storage_entry.js.map +1 -0
  127. package/dist/drivers/helpers/polling_ops.d.ts +0 -1
  128. package/dist/drivers/helpers/read_file.cjs +54 -0
  129. package/dist/drivers/helpers/read_file.cjs.map +1 -0
  130. package/dist/drivers/helpers/read_file.d.ts +0 -1
  131. package/dist/drivers/helpers/read_file.js +33 -0
  132. package/dist/drivers/helpers/read_file.js.map +1 -0
  133. package/dist/drivers/helpers/test_helpers.d.ts +0 -1
  134. package/dist/drivers/logs.cjs +118 -0
  135. package/dist/drivers/logs.cjs.map +1 -0
  136. package/dist/drivers/logs.d.ts +0 -1
  137. package/dist/drivers/logs.js +116 -0
  138. package/dist/drivers/logs.js.map +1 -0
  139. package/dist/drivers/logs_stream.cjs +238 -0
  140. package/dist/drivers/logs_stream.cjs.map +1 -0
  141. package/dist/drivers/logs_stream.d.ts +0 -1
  142. package/dist/drivers/logs_stream.js +236 -0
  143. package/dist/drivers/logs_stream.js.map +1 -0
  144. package/dist/drivers/ls.cjs +236 -0
  145. package/dist/drivers/ls.cjs.map +1 -0
  146. package/dist/drivers/ls.d.ts +0 -1
  147. package/dist/drivers/ls.js +214 -0
  148. package/dist/drivers/ls.js.map +1 -0
  149. package/dist/drivers/types.cjs +72 -0
  150. package/dist/drivers/types.cjs.map +1 -0
  151. package/dist/drivers/types.d.ts +4 -5
  152. package/dist/drivers/types.js +64 -0
  153. package/dist/drivers/types.js.map +1 -0
  154. package/dist/drivers/upload.cjs +154 -0
  155. package/dist/drivers/upload.cjs.map +1 -0
  156. package/dist/drivers/upload.d.ts +0 -1
  157. package/dist/drivers/upload.js +151 -0
  158. package/dist/drivers/upload.js.map +1 -0
  159. package/dist/drivers/upload_task.cjs +297 -0
  160. package/dist/drivers/upload_task.cjs.map +1 -0
  161. package/dist/drivers/upload_task.d.ts +2 -3
  162. package/dist/drivers/upload_task.js +289 -0
  163. package/dist/drivers/upload_task.js.map +1 -0
  164. package/dist/drivers/urls/url.cjs +59 -0
  165. package/dist/drivers/urls/url.cjs.map +1 -0
  166. package/dist/drivers/urls/url.d.ts +0 -1
  167. package/dist/drivers/urls/url.js +54 -0
  168. package/dist/drivers/urls/url.js.map +1 -0
  169. package/dist/drivers/virtual_storages.cjs +53 -0
  170. package/dist/drivers/virtual_storages.cjs.map +1 -0
  171. package/dist/drivers/virtual_storages.d.ts +0 -1
  172. package/dist/drivers/virtual_storages.js +51 -0
  173. package/dist/drivers/virtual_storages.js.map +1 -0
  174. package/dist/helpers/download.cjs +63 -0
  175. package/dist/helpers/download.cjs.map +1 -0
  176. package/dist/helpers/download.d.ts +0 -1
  177. package/dist/helpers/download.js +60 -0
  178. package/dist/helpers/download.js.map +1 -0
  179. package/dist/helpers/validate.cjs +12 -0
  180. package/dist/helpers/validate.cjs.map +1 -0
  181. package/dist/helpers/validate.d.ts +0 -1
  182. package/dist/helpers/validate.js +10 -0
  183. package/dist/helpers/validate.js.map +1 -0
  184. package/dist/index.cjs +73 -0
  185. package/dist/index.cjs.map +1 -0
  186. package/dist/index.d.ts +0 -1
  187. package/dist/index.js +19 -2
  188. package/dist/index.js.map +1 -1
  189. package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts +0 -1
  190. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs +261 -0
  191. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs.map +1 -0
  192. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs +31 -0
  193. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs.map +1 -0
  194. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +3 -5
  195. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js +29 -0
  196. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js.map +1 -0
  197. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +0 -1
  198. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js +256 -0
  199. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js.map +1 -0
  200. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs +301 -0
  201. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +1 -0
  202. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs +34 -0
  203. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs.map +1 -0
  204. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +3 -5
  205. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js +32 -0
  206. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js.map +1 -0
  207. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +0 -1
  208. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js +296 -0
  209. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js.map +1 -0
  210. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs +410 -0
  211. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +1 -0
  212. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs +38 -0
  213. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs.map +1 -0
  214. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +3 -5
  215. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js +36 -0
  216. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js.map +1 -0
  217. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +0 -1
  218. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js +403 -0
  219. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js.map +1 -0
  220. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs +486 -0
  221. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +1 -0
  222. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs +86 -0
  223. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs.map +1 -0
  224. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +3 -5
  225. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js +84 -0
  226. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js.map +1 -0
  227. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +0 -1
  228. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js +478 -0
  229. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js.map +1 -0
  230. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs +758 -0
  231. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +1 -0
  232. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs +71 -0
  233. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs.map +1 -0
  234. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts +3 -5
  235. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js +69 -0
  236. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js.map +1 -0
  237. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts +36 -1
  238. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js +747 -0
  239. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js.map +1 -0
  240. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +3 -5
  241. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +0 -1
  242. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +0 -1
  243. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +0 -1
  244. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -1
  245. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +0 -1
  246. package/dist/proto/google/api/http.d.ts +0 -1
  247. package/dist/proto/google/protobuf/any.d.ts +0 -1
  248. package/dist/proto/google/protobuf/descriptor.d.ts +0 -1
  249. package/dist/proto/google/protobuf/duration.cjs +105 -0
  250. package/dist/proto/google/protobuf/duration.cjs.map +1 -0
  251. package/dist/proto/google/protobuf/duration.d.ts +0 -1
  252. package/dist/proto/google/protobuf/duration.js +103 -0
  253. package/dist/proto/google/protobuf/duration.js.map +1 -0
  254. package/dist/proto/google/protobuf/empty.d.ts +0 -1
  255. package/dist/proto/google/protobuf/struct.d.ts +0 -1
  256. package/dist/proto/google/protobuf/timestamp.cjs +133 -0
  257. package/dist/proto/google/protobuf/timestamp.cjs.map +1 -0
  258. package/dist/proto/google/protobuf/timestamp.d.ts +0 -1
  259. package/dist/proto/google/protobuf/timestamp.js +131 -0
  260. package/dist/proto/google/protobuf/timestamp.js.map +1 -0
  261. package/dist/proto/google/protobuf/wrappers.d.ts +0 -1
  262. package/dist/test_env.d.ts +0 -1
  263. package/package.json +17 -15
  264. package/src/clients/upload.ts +38 -14
  265. package/src/drivers/upload_task.ts +10 -3
  266. package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.ts +69 -1
  267. package/dist/clients/constructors.d.ts.map +0 -1
  268. package/dist/clients/download.d.ts.map +0 -1
  269. package/dist/clients/logs.d.ts.map +0 -1
  270. package/dist/clients/ls_api.d.ts.map +0 -1
  271. package/dist/clients/progress.d.ts.map +0 -1
  272. package/dist/clients/upload.d.ts.map +0 -1
  273. package/dist/drivers/download_blob/blob_key.d.ts.map +0 -1
  274. package/dist/drivers/download_blob/download_blob.d.ts.map +0 -1
  275. package/dist/drivers/download_blob/download_blob_task.d.ts.map +0 -1
  276. package/dist/drivers/download_blob/sparse_cache/cache.d.ts.map +0 -1
  277. package/dist/drivers/download_blob/sparse_cache/file.d.ts.map +0 -1
  278. package/dist/drivers/download_blob/sparse_cache/ranges.d.ts.map +0 -1
  279. package/dist/drivers/download_blob_url/driver.d.ts.map +0 -1
  280. package/dist/drivers/download_blob_url/driver_id.d.ts.map +0 -1
  281. package/dist/drivers/download_blob_url/snapshot.d.ts.map +0 -1
  282. package/dist/drivers/download_blob_url/task.d.ts.map +0 -1
  283. package/dist/drivers/download_blob_url/url.d.ts.map +0 -1
  284. package/dist/drivers/download_url/driver.d.ts.map +0 -1
  285. package/dist/drivers/download_url/task.d.ts.map +0 -1
  286. package/dist/drivers/helpers/download_local_handle.d.ts.map +0 -1
  287. package/dist/drivers/helpers/download_remote_handle.d.ts.map +0 -1
  288. package/dist/drivers/helpers/files_cache.d.ts.map +0 -1
  289. package/dist/drivers/helpers/helpers.d.ts.map +0 -1
  290. package/dist/drivers/helpers/logs_handle.d.ts.map +0 -1
  291. package/dist/drivers/helpers/ls_remote_import_handle.d.ts.map +0 -1
  292. package/dist/drivers/helpers/ls_storage_entry.d.ts.map +0 -1
  293. package/dist/drivers/helpers/polling_ops.d.ts.map +0 -1
  294. package/dist/drivers/helpers/read_file.d.ts.map +0 -1
  295. package/dist/drivers/helpers/test_helpers.d.ts.map +0 -1
  296. package/dist/drivers/logs.d.ts.map +0 -1
  297. package/dist/drivers/logs_stream.d.ts.map +0 -1
  298. package/dist/drivers/ls.d.ts.map +0 -1
  299. package/dist/drivers/types.d.ts.map +0 -1
  300. package/dist/drivers/upload.d.ts.map +0 -1
  301. package/dist/drivers/upload_task.d.ts.map +0 -1
  302. package/dist/drivers/urls/url.d.ts.map +0 -1
  303. package/dist/drivers/virtual_storages.d.ts.map +0 -1
  304. package/dist/helpers/download.d.ts.map +0 -1
  305. package/dist/helpers/validate.d.ts.map +0 -1
  306. package/dist/index.d.ts.map +0 -1
  307. package/dist/index.mjs +0 -4892
  308. package/dist/index.mjs.map +0 -1
  309. package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
  310. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +0 -1
  311. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +0 -1
  312. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +0 -1
  313. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +0 -1
  314. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +0 -1
  315. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +0 -1
  316. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +0 -1
  317. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +0 -1
  318. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts.map +0 -1
  319. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts.map +0 -1
  320. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
  321. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
  322. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
  323. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
  324. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
  325. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
  326. package/dist/proto/google/api/http.d.ts.map +0 -1
  327. package/dist/proto/google/protobuf/any.d.ts.map +0 -1
  328. package/dist/proto/google/protobuf/descriptor.d.ts.map +0 -1
  329. package/dist/proto/google/protobuf/duration.d.ts.map +0 -1
  330. package/dist/proto/google/protobuf/empty.d.ts.map +0 -1
  331. package/dist/proto/google/protobuf/struct.d.ts.map +0 -1
  332. package/dist/proto/google/protobuf/timestamp.d.ts.map +0 -1
  333. package/dist/proto/google/protobuf/wrappers.d.ts.map +0 -1
  334. package/dist/test_env.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.js","sources":["../../src/clients/upload.ts"],"sourcesContent":["import type { GrpcClientProvider, GrpcClientProviderFactory, PlClient, ResourceId, ResourceType } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata } from '@milaboratories/pl-client';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport * as fs from 'node:fs/promises';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { crc32c } from '@node-rs/crc32';\nimport { uploadapi_ChecksumAlgorithm, type uploadapi_GetPartURL_Response } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol';\nimport { UploadClient } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client';\n\nimport type { IncomingHttpHeaders } from 'undici/types/header';\n\nexport class MTimeError extends Error {\n name = 'MTimeError';\n}\n\nexport class UnexpectedEOF extends Error {\n name = 'UnexpectedEOF';\n}\n\nexport class NetworkError extends Error {\n name = 'NetworkError';\n}\n\n/** Happens when the file doesn't exist */\nexport class NoFileForUploading extends Error {\n name = 'NoFileForUploading';\n}\n\nexport class BadRequestError extends Error {\n name = 'BadRequestError';\n}\n\n/** Low-level client for grpc uploadapi.\n * The user should pass here a concrete BlobUpload/<storageId> resource,\n * it can be got from handle field of BlobUpload. */\nexport class ClientUpload {\n private readonly grpcClient: GrpcClientProvider<UploadClient>;\n\n constructor(\n grpcClientProviderFactory: GrpcClientProviderFactory,\n public readonly httpClient: Dispatcher,\n _: PlClient,\n public readonly logger: MiLogger,\n ) {\n this.grpcClient = grpcClientProviderFactory.createGrpcClientProvider((transport) => new UploadClient(transport));\n }\n\n close() {}\n\n public async initUpload(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n ): Promise<{\n overall: bigint;\n toUpload: bigint[];\n checksumAlgorithm: uploadapi_ChecksumAlgorithm;\n checksumHeader: string;\n }> {\n const init = await this.grpcInit(id, type, options);\n return {\n overall: init.partsCount,\n toUpload: this.partsToUpload(init.partsCount, init.uploadedParts),\n checksumAlgorithm: init.checksumAlgorithm,\n checksumHeader: init.checksumHeader,\n };\n }\n\n public async partUpload(\n { id, type }: ResourceInfo,\n path: string,\n expectedMTimeUnix: bigint,\n partNumber: bigint,\n checksumAlgorithm: uploadapi_ChecksumAlgorithm,\n checksumHeader: string,\n options?: RpcOptions,\n ) {\n const info = await this.grpcGetPartUrl(\n { id, type },\n partNumber,\n 0n, // we update progress as a separate call later.\n options,\n );\n\n const chunk = await readFileChunk(path, info.chunkStart, info.chunkEnd);\n await checkExpectedMTime(path, expectedMTimeUnix);\n\n const crc32cChecksum = calculateCrc32cChecksum(chunk);\n if (checksumAlgorithm === uploadapi_ChecksumAlgorithm.CRC32C) {\n info.headers.push({ name: checksumHeader, value: crc32cChecksum });\n }\n\n const contentLength = Number(info.chunkEnd - info.chunkStart);\n if (chunk.length !== contentLength) {\n throw new Error(\n `Chunk size mismatch: expected ${contentLength} bytes, but read ${chunk.length} bytes from file`,\n );\n }\n\n const headers = Object.fromEntries(info.headers.map(({ name, value }) => [name, value]));\n\n try {\n const {\n body: rawBody,\n statusCode,\n headers: responseHeaders,\n } = await request(info.uploadUrl, {\n dispatcher: this.httpClient,\n body: chunk,\n // We got headers only after we send\n // the whole body (in case of S3 PUT requests it's 5 MB).\n // It might be slow with a slow connection (or with SSH),\n // that's why we got big timeout here.\n headersTimeout: 60000,\n bodyTimeout: 60000,\n // Prevent connection reuse by setting \"Connection: close\" header.\n // This works around an issue with the backend's built-in S3 implementation\n // that caused HTTP/1.1 protocol lines to be included in the uploaded file content.\n reset: true,\n headers,\n method: info.method.toUpperCase() as Dispatcher.HttpMethod,\n });\n\n // always read the body for resources to be garbage collected.\n const body = await rawBody.text();\n checkStatusCodeOk(statusCode, body, responseHeaders, info);\n } catch (e: unknown) {\n if (e instanceof NetworkError)\n throw e;\n\n if (e instanceof BadRequestError)\n throw e;\n\n throw new Error(`partUpload: error ${JSON.stringify(e)} happened while trying to do part upload to the url ${info.uploadUrl}, headers: ${JSON.stringify(info.headers)}`);\n }\n\n await this.grpcUpdateProgress({ id, type }, BigInt(info.chunkEnd - info.chunkStart), options);\n }\n\n public async finalize(info: ResourceInfo, options?: RpcOptions) {\n return await this.grpcFinalize(info, options);\n }\n\n /** Calculates parts that need to be uploaded from the parts that were\n * already uploaded. */\n private partsToUpload(partsCount: bigint, uploadedParts: bigint[]): bigint[] {\n const toUpload: bigint[] = [];\n const uploaded = new Set(uploadedParts);\n\n for (let i = 1n; i <= partsCount; i++) {\n if (!uploaded.has(i)) toUpload.push(i);\n }\n\n return toUpload;\n }\n\n private async grpcInit(id: ResourceId, type: ResourceType, options?: RpcOptions) {\n return await this.grpcClient.get().init({ resourceId: id }, addRTypeToMetadata(type, options))\n .response;\n }\n\n private async grpcGetPartUrl(\n { id, type }: ResourceInfo,\n partNumber: bigint,\n uploadedPartSize: bigint,\n options?: RpcOptions,\n ) {\n // partChecksum isn't used for now but protoc requires it to be set\n return await this.grpcClient.get().getPartURL(\n { resourceId: id, partNumber, uploadedPartSize, isInternalUse: false, partChecksum: '' },\n addRTypeToMetadata(type, options),\n ).response;\n }\n\n private async grpcUpdateProgress(\n { id, type }: ResourceInfo,\n bytesProcessed: bigint,\n options?: RpcOptions,\n ) {\n await this.grpcClient.get().updateProgress(\n {\n resourceId: id,\n bytesProcessed,\n },\n addRTypeToMetadata(type, options),\n ).response;\n }\n\n private async grpcFinalize({ id, type }: ResourceInfo, options?: RpcOptions) {\n return await this.grpcClient.get().finalize({ resourceId: id }, addRTypeToMetadata(type, options))\n .response;\n }\n}\n\nasync function readFileChunk(path: string, chunkStart: bigint, chunkEnd: bigint): Promise<Buffer> {\n let f: fs.FileHandle | undefined;\n try {\n f = await fs.open(path);\n const len = Number(chunkEnd - chunkStart);\n const pos = Number(chunkStart);\n const b = Buffer.alloc(len);\n const bytesRead = await readBytesFromPosition(f, b, len, pos);\n\n return b.subarray(0, bytesRead);\n } catch (e: unknown) {\n if (e && typeof e === 'object' && ('code' in e) && e.code == 'ENOENT') throw new NoFileForUploading(`there is no file ${path} for uploading`);\n throw e;\n } finally {\n await f?.close();\n }\n}\n\n/** Read len bytes from a given position.\n * Without this, `FileHandle.read` can read less bytes than needed. */\nasync function readBytesFromPosition(f: fs.FileHandle, b: Buffer, len: number, position: number) {\n let bytesReadTotal = 0;\n while (bytesReadTotal < len) {\n const { bytesRead } = await f.read(\n b,\n bytesReadTotal,\n len - bytesReadTotal,\n position + bytesReadTotal,\n );\n if (bytesRead === 0) {\n throw new UnexpectedEOF('file ended earlier than expected.');\n }\n bytesReadTotal += bytesRead;\n }\n\n return bytesReadTotal;\n}\n\nasync function checkExpectedMTime(path: string, expectedMTimeUnix: bigint) {\n const mTime = BigInt(Math.floor((await fs.stat(path)).mtimeMs / 1000));\n if (mTime > expectedMTimeUnix) {\n throw new MTimeError(`file was modified, expected mtime: ${expectedMTimeUnix}, got: ${mTime}.`);\n }\n}\n\nfunction checkStatusCodeOk(\n statusCode: number,\n body: string,\n headers: IncomingHttpHeaders,\n info: uploadapi_GetPartURL_Response,\n) {\n if (statusCode == 400) {\n throw new BadRequestError(`response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`);\n }\n\n if (statusCode != 200) {\n throw new NetworkError(\n `response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`,\n );\n }\n}\n\n/** Calculate CRC32C checksum of a buffer and return as base64 string */\nfunction calculateCrc32cChecksum(data: Buffer): string {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const checksum = crc32c(data);\n // Convert to unsigned 32-bit integer and then to base64\n const buffer = Buffer.alloc(4);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n buffer.writeUInt32BE(checksum, 0);\n return buffer.toString('base64');\n}\n"],"names":["fs"],"mappings":";;;;;;;AAcM,MAAO,UAAW,SAAQ,KAAK,CAAA;IACnC,IAAI,GAAG,YAAY;AACpB;AAEK,MAAO,aAAc,SAAQ,KAAK,CAAA;IACtC,IAAI,GAAG,eAAe;AACvB;AAEK,MAAO,YAAa,SAAQ,KAAK,CAAA;IACrC,IAAI,GAAG,cAAc;AACtB;AAED;AACM,MAAO,kBAAmB,SAAQ,KAAK,CAAA;IAC3C,IAAI,GAAG,oBAAoB;AAC5B;AAEK,MAAO,eAAgB,SAAQ,KAAK,CAAA;IACxC,IAAI,GAAG,iBAAiB;AACzB;AAED;;AAEoD;MACvC,YAAY,CAAA;AAKL,IAAA,UAAA;AAEA,IAAA,MAAA;AAND,IAAA,UAAU;AAE3B,IAAA,WAAA,CACE,yBAAoD,EACpC,UAAsB,EACtC,CAAW,EACK,MAAgB,EAAA;QAFhB,IAAA,CAAA,UAAU,GAAV,UAAU;QAEV,IAAA,CAAA,MAAM,GAAN,MAAM;AAEtB,QAAA,IAAI,CAAC,UAAU,GAAG,yBAAyB,CAAC,wBAAwB,CAAC,CAAC,SAAS,KAAK,IAAI,YAAY,CAAC,SAAS,CAAC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AAA,OAAA,EAAU,IAAI,CAAA,WAAA,EAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAA,EAAU,IAAI,CAAC,SAAS,CAAA,CAAE,CAAC;IACpF;AAEA,IAAA,IAAI,UAAU,IAAI,GAAG,EAAE;AACrB,QAAA,MAAM,IAAI,YAAY,CACpB,CAAA,iCAAA,EAAoC,UAAU,CAAA,CAAA;AAC5C,cAAA,CAAA,OAAA,EAAU,IAAI,CAAA,WAAA,EAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAA,EAAU,IAAI,CAAC,SAAS,CAAA,CAAE,CAChF;IACH;AACF;AAEA;AACA,SAAS,uBAAuB,CAAC,IAAY,EAAA;;AAE3C,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC;;IAE7B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;;AAE9B,IAAA,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;AACjC,IAAA,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAClC;;;;"}
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ require('@milaboratories/pl-client');
4
+ var path = require('node:path');
5
+
6
+ function _interopNamespaceDefault(e) {
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
24
+
25
+ function blobKey(rId) {
26
+ return `${BigInt(rId)}`;
27
+ }
28
+ function pathToKey(fPath) {
29
+ return path__namespace.basename(fPath);
30
+ }
31
+
32
+ exports.blobKey = blobKey;
33
+ exports.pathToKey = pathToKey;
34
+ //# sourceMappingURL=blob_key.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob_key.cjs","sources":["../../../src/drivers/download_blob/blob_key.ts"],"sourcesContent":["import { bigintToResourceId, ResourceId } from \"@milaboratories/pl-client\";\nimport * as path from 'node:path';\n\nexport function blobKey(rId: ResourceId): string {\n return `${BigInt(rId)}`;\n}\n\nexport function pathToKey(fPath: string): string {\n return path.basename(fPath);\n}\n\nexport function pathToBlobInfo(fPath: string): ResourceId | undefined {\n const base = path.basename(fPath);\n return bigintToResourceId(BigInt(base));\n}\n"],"names":["path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGM,SAAU,OAAO,CAAC,GAAe,EAAA;AACrC,IAAA,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE;AACzB;AAEM,SAAU,SAAS,CAAC,KAAa,EAAA;AACrC,IAAA,OAAOA,eAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC7B;;;;;"}
@@ -2,4 +2,3 @@ import { ResourceId } from '@milaboratories/pl-client';
2
2
  export declare function blobKey(rId: ResourceId): string;
3
3
  export declare function pathToKey(fPath: string): string;
4
4
  export declare function pathToBlobInfo(fPath: string): ResourceId | undefined;
5
- //# sourceMappingURL=blob_key.d.ts.map
@@ -0,0 +1,12 @@
1
+ import '@milaboratories/pl-client';
2
+ import * as path from 'node:path';
3
+
4
+ function blobKey(rId) {
5
+ return `${BigInt(rId)}`;
6
+ }
7
+ function pathToKey(fPath) {
8
+ return path.basename(fPath);
9
+ }
10
+
11
+ export { blobKey, pathToKey };
12
+ //# sourceMappingURL=blob_key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob_key.js","sources":["../../../src/drivers/download_blob/blob_key.ts"],"sourcesContent":["import { bigintToResourceId, ResourceId } from \"@milaboratories/pl-client\";\nimport * as path from 'node:path';\n\nexport function blobKey(rId: ResourceId): string {\n return `${BigInt(rId)}`;\n}\n\nexport function pathToKey(fPath: string): string {\n return path.basename(fPath);\n}\n\nexport function pathToBlobInfo(fPath: string): ResourceId | undefined {\n const base = path.basename(fPath);\n return bigintToResourceId(BigInt(base));\n}\n"],"names":[],"mappings":";;;AAGM,SAAU,OAAO,CAAC,GAAe,EAAA;AACrC,IAAA,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE;AACzB;AAEM,SAAU,SAAS,CAAC,KAAa,EAAA;AACrC,IAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC7B;;;;"}
@@ -0,0 +1,442 @@
1
+ 'use strict';
2
+
3
+ var computable = require('@milaboratories/computable');
4
+ var plClient = require('@milaboratories/pl-client');
5
+ var plModelCommon = require('@milaboratories/pl-model-common');
6
+ var plTree = require('@milaboratories/pl-tree');
7
+ var tsHelpers = require('@milaboratories/ts-helpers');
8
+ var Denque = require('denque');
9
+ var fs = require('node:fs');
10
+ var node_crypto = require('node:crypto');
11
+ var fsp = require('node:fs/promises');
12
+ var os = require('node:os');
13
+ var path = require('node:path');
14
+ var readline = require('node:readline/promises');
15
+ var consumers = require('node:stream/consumers');
16
+ var read_file = require('../helpers/read_file.cjs');
17
+ var download_local_handle = require('../helpers/download_local_handle.cjs');
18
+ var download_remote_handle = require('../helpers/download_remote_handle.cjs');
19
+ var helpers = require('../helpers/helpers.cjs');
20
+ var logs_handle = require('../helpers/logs_handle.cjs');
21
+ var types = require('../types.cjs');
22
+ var blob_key = require('./blob_key.cjs');
23
+ var download_blob_task = require('./download_blob_task.cjs');
24
+ var files_cache = require('../helpers/files_cache.cjs');
25
+ var cache = require('./sparse_cache/cache.cjs');
26
+
27
+ function _interopNamespaceDefault(e) {
28
+ var n = Object.create(null);
29
+ if (e) {
30
+ Object.keys(e).forEach(function (k) {
31
+ if (k !== 'default') {
32
+ var d = Object.getOwnPropertyDescriptor(e, k);
33
+ Object.defineProperty(n, k, d.get ? d : {
34
+ enumerable: true,
35
+ get: function () { return e[k]; }
36
+ });
37
+ }
38
+ });
39
+ }
40
+ n.default = e;
41
+ return Object.freeze(n);
42
+ }
43
+
44
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
45
+ var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
46
+ var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
47
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
48
+ var readline__namespace = /*#__PURE__*/_interopNamespaceDefault(readline);
49
+
50
+ /** DownloadDriver holds a queue of downloading tasks,
51
+ * and notifies every watcher when a file were downloaded. */
52
+ class DownloadDriver {
53
+ logger;
54
+ clientDownload;
55
+ clientLogs;
56
+ rangesCacheDir;
57
+ signer;
58
+ ops;
59
+ /** Represents a unique key to the path of a blob as a map. */
60
+ keyToDownload = new Map();
61
+ /** Writes and removes files to a hard drive and holds a counter for every
62
+ * file that should be kept. */
63
+ cache;
64
+ rangesCache;
65
+ /** Downloads files and writes them to the local dir. */
66
+ downloadQueue;
67
+ keyToOnDemand = new Map();
68
+ idToLastLines = new Map();
69
+ idToProgressLog = new Map();
70
+ saveDir;
71
+ constructor(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops) {
72
+ this.logger = logger;
73
+ this.clientDownload = clientDownload;
74
+ this.clientLogs = clientLogs;
75
+ this.rangesCacheDir = rangesCacheDir;
76
+ this.signer = signer;
77
+ this.ops = ops;
78
+ this.cache = new files_cache.FilesCache(this.ops.cacheSoftSizeBytes);
79
+ const fsRanges = new cache.SparseCacheFsRanges(this.logger, this.rangesCacheDir);
80
+ const fsStorage = new cache.SparseCacheFsFile(this.logger, this.rangesCacheDir);
81
+ this.rangesCache = new cache.SparseCache(this.logger, this.ops.rangesCacheMaxSizeBytes, fsRanges, fsStorage);
82
+ this.downloadQueue = new tsHelpers.TaskProcessor(this.logger, ops.nConcurrentDownloads);
83
+ this.saveDir = path__namespace.resolve(saveDir);
84
+ }
85
+ static async init(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops) {
86
+ const driver = new DownloadDriver(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops);
87
+ await driver.rangesCache.reset();
88
+ return driver;
89
+ }
90
+ getDownloadedBlob(res, ctx) {
91
+ if (ctx === undefined) {
92
+ return computable.Computable.make((ctx) => this.getDownloadedBlob(res, ctx));
93
+ }
94
+ const rInfo = plTree.treeEntryToResourceInfo(res, ctx);
95
+ const callerId = node_crypto.randomUUID();
96
+ ctx.addOnDestroy(() => this.releaseBlob(rInfo, callerId));
97
+ const result = this.getDownloadedBlobNoCtx(ctx.watcher, rInfo, callerId);
98
+ if (result == undefined) {
99
+ ctx.markUnstable('download blob is still undefined');
100
+ }
101
+ return result;
102
+ }
103
+ getDownloadedBlobNoCtx(w, rInfo, callerId) {
104
+ validateDownloadableResourceType('getDownloadedBlob', rInfo.type);
105
+ // We don't need to request files with wider limits,
106
+ // PFrame's engine does it disk-optimally by itself.
107
+ const task = this.getOrSetNewTask(rInfo, callerId);
108
+ task.attach(w, callerId);
109
+ const result = task.getBlob();
110
+ if (!result.done) {
111
+ return undefined;
112
+ }
113
+ if (result.result.ok) {
114
+ return result.result.value;
115
+ }
116
+ throw result.result.error;
117
+ }
118
+ getOrSetNewTask(rInfo, callerId) {
119
+ const key = blob_key.blobKey(rInfo.id);
120
+ const inMemoryTask = this.keyToDownload.get(key);
121
+ if (inMemoryTask) {
122
+ return inMemoryTask;
123
+ }
124
+ // schedule the blob downloading, then it'll be added to the cache.
125
+ const fPath = path__namespace.resolve(this.saveDir, key);
126
+ const newTask = new download_blob_task.DownloadBlobTask(this.logger, this.clientDownload, rInfo, download_local_handle.newLocalHandle(fPath, this.signer), fPath);
127
+ this.keyToDownload.set(key, newTask);
128
+ this.downloadQueue.push({
129
+ fn: () => this.downloadBlob(newTask, callerId),
130
+ recoverableErrorPredicate: (e) => !download_blob_task.nonRecoverableError(e),
131
+ });
132
+ return newTask;
133
+ }
134
+ async downloadBlob(task, callerId) {
135
+ await task.download();
136
+ const blob = task.getBlob();
137
+ if (blob.done && blob.result.ok) {
138
+ this.cache.addCache(task, callerId);
139
+ }
140
+ }
141
+ getOnDemandBlob(res, ctx) {
142
+ if (ctx === undefined)
143
+ return computable.Computable.make((ctx) => this.getOnDemandBlob(res, ctx));
144
+ const rInfo = plTree.isPlTreeEntry(res)
145
+ ? plTree.makeResourceSnapshot(res, types.OnDemandBlobResourceSnapshot, ctx)
146
+ : res;
147
+ const callerId = node_crypto.randomUUID();
148
+ ctx.addOnDestroy(() => this.releaseOnDemandBlob(rInfo.id, callerId));
149
+ // note that the watcher is not needed,
150
+ // the handler never changes.
151
+ const result = this.getOnDemandBlobNoCtx(rInfo, callerId);
152
+ return result;
153
+ }
154
+ getOnDemandBlobNoCtx(info, callerId) {
155
+ validateDownloadableResourceType('getOnDemandBlob', info.type);
156
+ let blob = this.keyToOnDemand.get(blob_key.blobKey(info.id));
157
+ if (blob === undefined) {
158
+ blob = new OnDemandBlobHolder(types.getSize(info), download_remote_handle.newRemoteHandle(info, this.signer));
159
+ this.keyToOnDemand.set(blob_key.blobKey(info.id), blob);
160
+ }
161
+ blob.attach(callerId);
162
+ return blob.getHandle();
163
+ }
164
+ /** Gets a path from a handle. */
165
+ getLocalPath(handle) {
166
+ const { path } = download_local_handle.parseLocalHandle(handle, this.signer);
167
+ return path;
168
+ }
169
+ /** Gets a content of a blob by a handle. */
170
+ async getContent(handle, range) {
171
+ if (range) {
172
+ plModelCommon.validateRangeBytes(range, `getContent`);
173
+ }
174
+ if (download_local_handle.isLocalBlobHandle(handle)) {
175
+ return await read_file.readFileContent(this.getLocalPath(handle), range);
176
+ }
177
+ if (download_remote_handle.isRemoteBlobHandle(handle)) {
178
+ const result = download_remote_handle.parseRemoteHandle(handle, this.signer);
179
+ const key = blob_key.blobKey(result.info.id);
180
+ const filePath = await this.rangesCache.get(key, range ?? { from: 0, to: result.size });
181
+ if (filePath) {
182
+ return await read_file.readFileContent(filePath, range);
183
+ }
184
+ const data = await this.clientDownload.withBlobContent({ id: result.info.id, type: result.info.type }, undefined, { range }, async (content) => await consumers.buffer(content));
185
+ await this.rangesCache.set(key, range ?? { from: 0, to: result.size }, data);
186
+ return data;
187
+ }
188
+ throw new Error('Malformed remote handle');
189
+ }
190
+ /**
191
+ * Creates computable that will return blob content once it is downloaded.
192
+ * Uses downloaded blob handle under the hood, so stores corresponding blob in file system.
193
+ */
194
+ getComputableContent(res, range) {
195
+ if (range) {
196
+ plModelCommon.validateRangeBytes(range, `getComputableContent`);
197
+ }
198
+ return computable.Computable.make((ctx) => this.getDownloadedBlob(res, ctx), {
199
+ postprocessValue: (v) => v ? this.getContent(v.handle, range) : undefined
200
+ }).withStableType();
201
+ }
202
+ getLastLogs(res, lines, ctx) {
203
+ if (ctx == undefined)
204
+ return computable.Computable.make((ctx) => this.getLastLogs(res, lines, ctx));
205
+ const r = plTree.treeEntryToResourceInfo(res, ctx);
206
+ const callerId = node_crypto.randomUUID();
207
+ ctx.addOnDestroy(() => this.releaseBlob(r, callerId));
208
+ const result = this.getLastLogsNoCtx(ctx.watcher, r, lines, callerId);
209
+ if (result == undefined)
210
+ ctx.markUnstable('either a file was not downloaded or logs was not read');
211
+ return result;
212
+ }
213
+ getLastLogsNoCtx(w, rInfo, lines, callerId) {
214
+ validateDownloadableResourceType('getLastLogs', rInfo.type);
215
+ const blob = this.getDownloadedBlobNoCtx(w, rInfo, callerId);
216
+ if (blob == undefined)
217
+ return undefined;
218
+ const { path } = download_local_handle.parseLocalHandle(blob.handle, this.signer);
219
+ let logGetter = this.idToLastLines.get(blob_key.blobKey(rInfo.id));
220
+ if (logGetter == undefined) {
221
+ const newLogGetter = new LastLinesGetter(path, lines);
222
+ this.idToLastLines.set(blob_key.blobKey(rInfo.id), newLogGetter);
223
+ logGetter = newLogGetter;
224
+ }
225
+ const result = logGetter.getOrSchedule(w);
226
+ if (result.error)
227
+ throw result.error;
228
+ return result.log;
229
+ }
230
+ getProgressLog(res, patternToSearch, ctx) {
231
+ if (ctx == undefined)
232
+ return computable.Computable.make((ctx) => this.getProgressLog(res, patternToSearch, ctx));
233
+ const r = plTree.treeEntryToResourceInfo(res, ctx);
234
+ const callerId = node_crypto.randomUUID();
235
+ ctx.addOnDestroy(() => this.releaseBlob(r, callerId));
236
+ const result = this.getProgressLogNoCtx(ctx.watcher, r, patternToSearch, callerId);
237
+ if (result === undefined)
238
+ ctx.markUnstable('either a file was not downloaded or a progress log was not read');
239
+ return result;
240
+ }
241
+ getProgressLogNoCtx(w, rInfo, patternToSearch, callerId) {
242
+ validateDownloadableResourceType('getProgressLog', rInfo.type);
243
+ const blob = this.getDownloadedBlobNoCtx(w, rInfo, callerId);
244
+ if (blob == undefined)
245
+ return undefined;
246
+ const { path } = download_local_handle.parseLocalHandle(blob.handle, this.signer);
247
+ let logGetter = this.idToProgressLog.get(blob_key.blobKey(rInfo.id));
248
+ if (logGetter == undefined) {
249
+ const newLogGetter = new LastLinesGetter(path, 1, patternToSearch);
250
+ this.idToProgressLog.set(blob_key.blobKey(rInfo.id), newLogGetter);
251
+ logGetter = newLogGetter;
252
+ }
253
+ const result = logGetter.getOrSchedule(w);
254
+ if (result.error)
255
+ throw result.error;
256
+ return result.log;
257
+ }
258
+ getLogHandle(res, ctx) {
259
+ if (ctx == undefined)
260
+ return computable.Computable.make((ctx) => this.getLogHandle(res, ctx));
261
+ const r = plTree.treeEntryToResourceInfo(res, ctx);
262
+ return this.getLogHandleNoCtx(r);
263
+ }
264
+ getLogHandleNoCtx(rInfo) {
265
+ validateDownloadableResourceType('getLogHandle', rInfo.type);
266
+ return logs_handle.newLogHandle(false, rInfo);
267
+ }
268
+ async lastLines(handle, lineCount, offsetBytes, // if 0n, then start from the end.
269
+ searchStr) {
270
+ const resp = await this.clientLogs.lastLines(logs_handle.getResourceInfoFromLogHandle(handle), lineCount, BigInt(offsetBytes ?? 0), searchStr);
271
+ return {
272
+ live: false,
273
+ shouldUpdateHandle: false,
274
+ data: resp.data,
275
+ size: Number(resp.size),
276
+ newOffset: Number(resp.newOffset),
277
+ };
278
+ }
279
+ async readText(handle, lineCount, offsetBytes, searchStr) {
280
+ const resp = await this.clientLogs.readText(logs_handle.getResourceInfoFromLogHandle(handle), lineCount, BigInt(offsetBytes ?? 0), searchStr);
281
+ return {
282
+ live: false,
283
+ shouldUpdateHandle: false,
284
+ data: resp.data,
285
+ size: Number(resp.size),
286
+ newOffset: Number(resp.newOffset),
287
+ };
288
+ }
289
+ async releaseBlob(rInfo, callerId) {
290
+ const task = this.keyToDownload.get(blob_key.blobKey(rInfo.id));
291
+ if (task == undefined) {
292
+ return;
293
+ }
294
+ if (this.cache.existsFile(blob_key.blobKey(rInfo.id))) {
295
+ const toDelete = this.cache.removeFile(blob_key.blobKey(rInfo.id), callerId);
296
+ await Promise.all(toDelete.map(async (cachedFile) => {
297
+ await fsp__namespace.rm(cachedFile.path);
298
+ this.cache.removeCache(cachedFile);
299
+ this.removeTask(tsHelpers.mapGet(this.keyToDownload, blob_key.pathToKey(cachedFile.path)), `the task ${plClient.stringifyWithResourceId(cachedFile)} was removed`
300
+ + `from cache along with ${plClient.stringifyWithResourceId(toDelete.map((d) => d.path))}`);
301
+ }));
302
+ }
303
+ else {
304
+ // The task is still in a downloading queue.
305
+ const deleted = task.counter.dec(callerId);
306
+ if (deleted) {
307
+ this.removeTask(task, `the task ${plClient.stringifyWithResourceId(task.info())} was removed from cache`);
308
+ }
309
+ }
310
+ }
311
+ removeTask(task, reason) {
312
+ task.abort(reason);
313
+ task.change.markChanged(`download task for ${task.path} removed: ${reason}`);
314
+ this.keyToDownload.delete(blob_key.pathToKey(task.path));
315
+ this.idToLastLines.delete(blob_key.blobKey(task.rInfo.id));
316
+ this.idToProgressLog.delete(blob_key.blobKey(task.rInfo.id));
317
+ }
318
+ async releaseOnDemandBlob(blobId, callerId) {
319
+ const deleted = this.keyToOnDemand.get(blob_key.blobKey(blobId))?.release(callerId) ?? false;
320
+ if (deleted)
321
+ this.keyToOnDemand.delete(blob_key.blobKey(blobId));
322
+ }
323
+ /** Removes all files from a hard drive. */
324
+ async releaseAll() {
325
+ this.downloadQueue.stop();
326
+ this.keyToDownload.forEach((task, key) => {
327
+ this.keyToDownload.delete(key);
328
+ task.change.markChanged(`task ${plClient.resourceIdToString(task.rInfo.id)} released`);
329
+ });
330
+ }
331
+ }
332
+ /** Keeps a counter to the on demand handle. */
333
+ class OnDemandBlobHolder {
334
+ size;
335
+ handle;
336
+ counter = new tsHelpers.CallersCounter();
337
+ constructor(size, handle) {
338
+ this.size = size;
339
+ this.handle = handle;
340
+ }
341
+ getHandle() {
342
+ return { handle: this.handle, size: this.size };
343
+ }
344
+ attach(callerId) {
345
+ this.counter.inc(callerId);
346
+ }
347
+ release(callerId) {
348
+ return this.counter.dec(callerId);
349
+ }
350
+ }
351
+ class LastLinesGetter {
352
+ path;
353
+ lines;
354
+ patternToSearch;
355
+ updater;
356
+ log;
357
+ change = new computable.ChangeSource();
358
+ error = undefined;
359
+ constructor(path, lines, patternToSearch) {
360
+ this.path = path;
361
+ this.lines = lines;
362
+ this.patternToSearch = patternToSearch;
363
+ this.updater = new helpers.Updater(async () => this.update());
364
+ }
365
+ getOrSchedule(w) {
366
+ this.change.attachWatcher(w);
367
+ this.updater.schedule();
368
+ return {
369
+ log: this.log,
370
+ error: this.error,
371
+ };
372
+ }
373
+ async update() {
374
+ try {
375
+ const newLogs = await getLastLines(this.path, this.lines, this.patternToSearch);
376
+ if (this.log != newLogs)
377
+ this.change.markChanged(`logs for ${this.path} updated`);
378
+ this.log = newLogs;
379
+ }
380
+ catch (e) {
381
+ if (e.name == 'RpcError' && e.code == 'NOT_FOUND') {
382
+ // No resource
383
+ this.log = '';
384
+ this.error = e;
385
+ this.change.markChanged(`log update for ${this.path} failed, resource not found`);
386
+ return;
387
+ }
388
+ throw e;
389
+ }
390
+ }
391
+ }
392
+ /** Gets last lines from a file by reading the file from the top and keeping
393
+ * last N lines in a window queue. */
394
+ async function getLastLines(fPath, nLines, patternToSearch) {
395
+ let inStream;
396
+ let rl;
397
+ try {
398
+ inStream = fs__namespace.createReadStream(fPath);
399
+ rl = readline__namespace.createInterface({ input: inStream, crlfDelay: Infinity });
400
+ const lines = new Denque();
401
+ for await (const line of rl) {
402
+ if (patternToSearch != undefined && !line.includes(patternToSearch))
403
+ continue;
404
+ lines.push(line);
405
+ if (lines.length > nLines) {
406
+ lines.shift();
407
+ }
408
+ }
409
+ // last EOL is for keeping backward compat with platforma implementation.
410
+ return lines.toArray().join(os__namespace.EOL) + os__namespace.EOL;
411
+ }
412
+ finally {
413
+ // Cleanup resources in finally block to ensure they're always cleaned up
414
+ try {
415
+ if (rl) {
416
+ rl.close();
417
+ }
418
+ }
419
+ catch (cleanupError) {
420
+ console.error('Error closing readline interface:', cleanupError);
421
+ }
422
+ try {
423
+ if (inStream && !inStream.destroyed) {
424
+ inStream.destroy();
425
+ }
426
+ }
427
+ catch (cleanupError) {
428
+ console.error('Error destroying read stream:', cleanupError);
429
+ }
430
+ }
431
+ }
432
+ function validateDownloadableResourceType(methodName, rType) {
433
+ if (!rType.name.startsWith('Blob/')) {
434
+ let message = `${methodName}: wrong resource type: ${rType.name}, expected: a resource of type that starts with 'Blob/'.`;
435
+ if (rType.name == 'Blob')
436
+ message += ` If it's called from workflow, should a file be exported with 'file.exportFile' function?`;
437
+ throw new helpers.WrongResourceTypeError(message);
438
+ }
439
+ }
440
+
441
+ exports.DownloadDriver = DownloadDriver;
442
+ //# sourceMappingURL=download_blob.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download_blob.cjs","sources":["../../../src/drivers/download_blob/download_blob.ts"],"sourcesContent":["import type {\n ComputableCtx,\n ComputableStableDefined,\n Watcher,\n} from '@milaboratories/computable';\nimport {\n ChangeSource,\n Computable,\n} from '@milaboratories/computable';\nimport type { ResourceId, ResourceType } from '@milaboratories/pl-client';\nimport { resourceIdToString, stringifyWithResourceId } from '@milaboratories/pl-client';\nimport type {\n AnyLogHandle,\n BlobDriver,\n LocalBlobHandle,\n LocalBlobHandleAndSize,\n ReadyLogHandle,\n RemoteBlobHandle,\n RemoteBlobHandleAndSize,\n StreamingApiResponse,\n} from '@milaboratories/pl-model-common';\nimport { type RangeBytes, validateRangeBytes } from '@milaboratories/pl-model-common';\nimport type {\n PlTreeEntry,\n ResourceInfo,\n ResourceSnapshot\n} from '@milaboratories/pl-tree';\nimport {\n isPlTreeEntry,\n makeResourceSnapshot,\n treeEntryToResourceInfo,\n} from '@milaboratories/pl-tree';\nimport type { MiLogger, Signer } from '@milaboratories/ts-helpers';\nimport { CallersCounter, mapGet, TaskProcessor } from '@milaboratories/ts-helpers';\nimport Denque from 'denque';\nimport * as fs from 'fs';\nimport { randomUUID } from 'node:crypto';\nimport * as fsp from 'node:fs/promises';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport * as readline from 'node:readline/promises';\nimport { Writable } from 'node:stream';\nimport { buffer } from 'node:stream/consumers';\nimport type { ClientDownload } from '../../clients/download';\nimport type { ClientLogs } from '../../clients/logs';\nimport { readFileContent } from '../helpers/read_file';\nimport {\n isLocalBlobHandle,\n newLocalHandle,\n parseLocalHandle,\n} from '../helpers/download_local_handle';\nimport {\n isRemoteBlobHandle,\n newRemoteHandle,\n parseRemoteHandle,\n} from '../helpers/download_remote_handle';\nimport { Updater, WrongResourceTypeError } from '../helpers/helpers';\nimport { getResourceInfoFromLogHandle, newLogHandle } from '../helpers/logs_handle';\nimport { getSize, OnDemandBlobResourceSnapshot } from '../types';\nimport { blobKey, pathToKey } from './blob_key';\nimport { DownloadBlobTask, nonRecoverableError } from './download_blob_task';\nimport { FilesCache } from '../helpers/files_cache';\nimport { SparseCache, SparseCacheFsFile, SparseCacheFsRanges } from './sparse_cache/cache';\n\nexport type DownloadDriverOps = {\n /**\n * A soft limit of the amount of blob storage, in bytes.\n * Once exceeded, the download driver will start deleting blobs one by one\n * when they become unneeded.\n * */\n cacheSoftSizeBytes: number;\n\n /**\n * A hard limit of the amount of sparse cache, in bytes.\n * Once exceeded, the download driver will start deleting blobs one by one.\n *\n * The sparse cache is used to store ranges of blobs.\n * */\n rangesCacheMaxSizeBytes: number;\n\n /**\n * Max number of concurrent downloads while calculating computable states\n * derived from this driver\n * */\n nConcurrentDownloads: number;\n};\n\n/** DownloadDriver holds a queue of downloading tasks,\n * and notifies every watcher when a file were downloaded. */\nexport class DownloadDriver implements BlobDriver {\n /** Represents a unique key to the path of a blob as a map. */\n private keyToDownload: Map<string, DownloadBlobTask> = new Map();\n\n /** Writes and removes files to a hard drive and holds a counter for every\n * file that should be kept. */\n private cache: FilesCache<DownloadBlobTask>;\n private rangesCache: SparseCache;\n\n /** Downloads files and writes them to the local dir. */\n private downloadQueue: TaskProcessor;\n\n private keyToOnDemand: Map<string, OnDemandBlobHolder> = new Map();\n\n private idToLastLines: Map<string, LastLinesGetter> = new Map();\n private idToProgressLog: Map<string, LastLinesGetter> = new Map();\n\n private readonly saveDir: string;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly clientDownload: ClientDownload,\n private readonly clientLogs: ClientLogs,\n saveDir: string,\n private readonly rangesCacheDir: string,\n private readonly signer: Signer,\n private readonly ops: DownloadDriverOps,\n ) {\n this.cache = new FilesCache(this.ops.cacheSoftSizeBytes);\n\n const fsRanges = new SparseCacheFsRanges(this.logger, this.rangesCacheDir);\n const fsStorage = new SparseCacheFsFile(this.logger, this.rangesCacheDir);\n this.rangesCache = new SparseCache(this.logger, this.ops.rangesCacheMaxSizeBytes, fsRanges, fsStorage);\n\n this.downloadQueue = new TaskProcessor(this.logger, ops.nConcurrentDownloads);\n\n this.saveDir = path.resolve(saveDir);\n }\n\n static async init(\n logger: MiLogger,\n clientDownload: ClientDownload,\n clientLogs: ClientLogs,\n saveDir: string,\n rangesCacheDir: string,\n signer: Signer,\n ops: DownloadDriverOps,\n ): Promise<DownloadDriver> {\n const driver = new DownloadDriver(logger, clientDownload, clientLogs, saveDir, rangesCacheDir, signer, ops);\n await driver.rangesCache.reset();\n\n return driver;\n }\n\n /** Gets a blob or part of the blob by its resource id or downloads a blob and sets it in a cache. */\n public getDownloadedBlob(\n res: ResourceInfo | PlTreeEntry,\n ctx: ComputableCtx,\n ): LocalBlobHandleAndSize | undefined;\n public getDownloadedBlob(\n res: ResourceInfo | PlTreeEntry,\n ): ComputableStableDefined<LocalBlobHandleAndSize>;\n public getDownloadedBlob(\n res: ResourceInfo | PlTreeEntry,\n ctx?: ComputableCtx,\n ): Computable<LocalBlobHandleAndSize | undefined> | LocalBlobHandleAndSize | undefined {\n if (ctx === undefined) {\n return Computable.make((ctx) => this.getDownloadedBlob(res, ctx));\n }\n\n const rInfo = treeEntryToResourceInfo(res, ctx);\n\n const callerId = randomUUID();\n ctx.addOnDestroy(() => this.releaseBlob(rInfo, callerId));\n\n const result = this.getDownloadedBlobNoCtx(ctx.watcher, rInfo as ResourceSnapshot, callerId);\n if (result == undefined) {\n ctx.markUnstable('download blob is still undefined');\n }\n\n return result;\n }\n\n private getDownloadedBlobNoCtx(\n w: Watcher,\n rInfo: ResourceSnapshot,\n callerId: string,\n ): LocalBlobHandleAndSize | undefined {\n validateDownloadableResourceType('getDownloadedBlob', rInfo.type);\n\n // We don't need to request files with wider limits,\n // PFrame's engine does it disk-optimally by itself.\n\n const task = this.getOrSetNewTask(rInfo, callerId);\n task.attach(w, callerId);\n\n const result = task.getBlob();\n if (!result.done) {\n return undefined;\n }\n if (result.result.ok) {\n return result.result.value;\n }\n throw result.result.error;\n }\n\n private getOrSetNewTask(\n rInfo: ResourceSnapshot,\n callerId: string,\n ): DownloadBlobTask {\n const key = blobKey(rInfo.id);\n\n const inMemoryTask = this.keyToDownload.get(key);\n if (inMemoryTask) {\n return inMemoryTask;\n }\n\n // schedule the blob downloading, then it'll be added to the cache.\n const fPath = path.resolve(this.saveDir, key);\n\n const newTask = new DownloadBlobTask(\n this.logger,\n this.clientDownload,\n rInfo,\n newLocalHandle(fPath, this.signer),\n fPath,\n );\n this.keyToDownload.set(key, newTask);\n\n this.downloadQueue.push({\n fn: () => this.downloadBlob(newTask, callerId),\n recoverableErrorPredicate: (e) => !nonRecoverableError(e),\n });\n\n return newTask;\n }\n\n private async downloadBlob(task: DownloadBlobTask, callerId: string) {\n await task.download();\n const blob = task.getBlob();\n if (blob.done && blob.result.ok) {\n this.cache.addCache(task, callerId);\n }\n }\n\n /** Gets on demand blob. */\n public getOnDemandBlob(\n res: OnDemandBlobResourceSnapshot | PlTreeEntry,\n ): Computable<RemoteBlobHandleAndSize>;\n public getOnDemandBlob(\n res: OnDemandBlobResourceSnapshot | PlTreeEntry,\n ctx?: undefined,\n fromBytes?: number,\n toBytes?: number,\n ): Computable<RemoteBlobHandleAndSize>;\n public getOnDemandBlob(\n res: OnDemandBlobResourceSnapshot | PlTreeEntry,\n ctx: ComputableCtx,\n fromBytes?: number,\n toBytes?: number,\n ): RemoteBlobHandleAndSize;\n public getOnDemandBlob(\n res: OnDemandBlobResourceSnapshot | PlTreeEntry,\n ctx?: ComputableCtx,\n ): ComputableStableDefined<RemoteBlobHandleAndSize> | RemoteBlobHandleAndSize | undefined {\n if (ctx === undefined) return Computable.make((ctx) => this.getOnDemandBlob(res, ctx));\n\n const rInfo: OnDemandBlobResourceSnapshot = isPlTreeEntry(res)\n ? makeResourceSnapshot(res, OnDemandBlobResourceSnapshot, ctx)\n : res;\n\n const callerId = randomUUID();\n ctx.addOnDestroy(() => this.releaseOnDemandBlob(rInfo.id, callerId));\n\n // note that the watcher is not needed,\n // the handler never changes.\n const result = this.getOnDemandBlobNoCtx(rInfo, callerId);\n\n return result;\n }\n\n private getOnDemandBlobNoCtx(\n info: OnDemandBlobResourceSnapshot,\n callerId: string,\n ): RemoteBlobHandleAndSize {\n validateDownloadableResourceType('getOnDemandBlob', info.type);\n\n let blob = this.keyToOnDemand.get(blobKey(info.id));\n\n if (blob === undefined) {\n blob = new OnDemandBlobHolder(getSize(info), newRemoteHandle(info, this.signer));\n this.keyToOnDemand.set(blobKey(info.id), blob);\n }\n\n blob.attach(callerId);\n\n return blob.getHandle();\n }\n\n /** Gets a path from a handle. */\n public getLocalPath(handle: LocalBlobHandle): string {\n const { path } = parseLocalHandle(handle, this.signer);\n return path;\n }\n\n /** Gets a content of a blob by a handle. */\n public async getContent(handle: LocalBlobHandle | RemoteBlobHandle, range?: RangeBytes): Promise<Uint8Array> {\n if (range) {\n validateRangeBytes(range, `getContent`);\n }\n\n if (isLocalBlobHandle(handle)) {\n return await readFileContent(this.getLocalPath(handle), range);\n }\n\n if (isRemoteBlobHandle(handle)) {\n const result = parseRemoteHandle(handle, this.signer);\n\n const key = blobKey(result.info.id);\n const filePath = await this.rangesCache.get(key, range ?? { from: 0, to: result.size });\n if (filePath) {\n return await readFileContent(filePath, range);\n }\n\n const data = await this.clientDownload.withBlobContent(\n { id: result.info.id, type: result.info.type },\n undefined,\n { range },\n async (content) => await buffer(content)\n );\n await this.rangesCache.set(key, range ?? { from: 0, to: result.size }, data);\n\n return data;\n }\n\n throw new Error('Malformed remote handle');\n }\n\n /**\n * Creates computable that will return blob content once it is downloaded.\n * Uses downloaded blob handle under the hood, so stores corresponding blob in file system.\n */\n public getComputableContent(\n res: ResourceInfo | PlTreeEntry,\n range?: RangeBytes,\n ): ComputableStableDefined<Uint8Array> {\n if (range) {\n validateRangeBytes(range, `getComputableContent`);\n }\n\n return Computable.make((ctx) =>\n this.getDownloadedBlob(res, ctx), {\n postprocessValue: (v) => v ? this.getContent(v.handle, range) : undefined\n }\n ).withStableType()\n }\n\n /** Returns all logs and schedules a job that reads remain logs.\n * Notifies when a new portion of the log appeared. */\n public getLastLogs(\n res: ResourceInfo | PlTreeEntry,\n lines: number\n ): Computable<string | undefined>;\n public getLastLogs(\n res: ResourceInfo | PlTreeEntry,\n lines: number,\n ctx: ComputableCtx\n ): Computable<string | undefined>;\n public getLastLogs(\n res: ResourceInfo | PlTreeEntry,\n lines: number,\n ctx?: ComputableCtx,\n ): Computable<string | undefined> | string | undefined {\n if (ctx == undefined) return Computable.make((ctx) => this.getLastLogs(res, lines, ctx));\n\n const r = treeEntryToResourceInfo(res, ctx);\n const callerId = randomUUID();\n ctx.addOnDestroy(() => this.releaseBlob(r, callerId));\n\n const result = this.getLastLogsNoCtx(ctx.watcher, r as ResourceSnapshot, lines, callerId);\n if (result == undefined)\n ctx.markUnstable('either a file was not downloaded or logs was not read');\n\n return result;\n }\n\n private getLastLogsNoCtx(\n w: Watcher,\n rInfo: ResourceSnapshot,\n lines: number,\n callerId: string,\n ): string | undefined {\n validateDownloadableResourceType('getLastLogs', rInfo.type);\n const blob = this.getDownloadedBlobNoCtx(w, rInfo, callerId);\n if (blob == undefined) return undefined;\n\n const { path } = parseLocalHandle(blob.handle, this.signer);\n\n let logGetter = this.idToLastLines.get(blobKey(rInfo.id));\n\n if (logGetter == undefined) {\n const newLogGetter = new LastLinesGetter(path, lines);\n this.idToLastLines.set(blobKey(rInfo.id), newLogGetter);\n logGetter = newLogGetter;\n }\n\n const result = logGetter.getOrSchedule(w);\n if (result.error) throw result.error;\n\n return result.log;\n }\n\n /** Returns a last line that has patternToSearch.\n * Notifies when a new line appeared or EOF reached. */\n public getProgressLog(\n res: ResourceInfo | PlTreeEntry,\n patternToSearch: string\n ): Computable<string | undefined>;\n public getProgressLog(\n res: ResourceInfo | PlTreeEntry,\n patternToSearch: string,\n ctx: ComputableCtx\n ): string | undefined;\n public getProgressLog(\n res: ResourceInfo | PlTreeEntry,\n patternToSearch: string,\n ctx?: ComputableCtx,\n ): Computable<string | undefined> | string | undefined {\n if (ctx == undefined)\n return Computable.make((ctx) => this.getProgressLog(res, patternToSearch, ctx));\n\n const r = treeEntryToResourceInfo(res, ctx);\n const callerId = randomUUID();\n ctx.addOnDestroy(() => this.releaseBlob(r, callerId));\n\n const result = this.getProgressLogNoCtx(\n ctx.watcher,\n r as ResourceSnapshot,\n patternToSearch,\n callerId,\n );\n if (result === undefined)\n ctx.markUnstable('either a file was not downloaded or a progress log was not read');\n\n return result;\n }\n\n private getProgressLogNoCtx(\n w: Watcher,\n rInfo: ResourceSnapshot,\n patternToSearch: string,\n callerId: string,\n ): string | undefined {\n validateDownloadableResourceType('getProgressLog', rInfo.type);\n\n const blob = this.getDownloadedBlobNoCtx(w, rInfo, callerId);\n if (blob == undefined) return undefined;\n const { path } = parseLocalHandle(blob.handle, this.signer);\n\n let logGetter = this.idToProgressLog.get(blobKey(rInfo.id));\n\n if (logGetter == undefined) {\n const newLogGetter = new LastLinesGetter(path, 1, patternToSearch);\n this.idToProgressLog.set(blobKey(rInfo.id), newLogGetter);\n\n logGetter = newLogGetter;\n }\n\n const result = logGetter.getOrSchedule(w);\n if (result.error) throw result.error;\n\n return result.log;\n }\n\n /** Returns an Id of a smart object, that can read logs directly from\n * the platform. */\n public getLogHandle(res: ResourceInfo | PlTreeEntry): Computable<AnyLogHandle>;\n public getLogHandle(res: ResourceInfo | PlTreeEntry, ctx: ComputableCtx): AnyLogHandle;\n public getLogHandle(\n res: ResourceInfo | PlTreeEntry,\n ctx?: ComputableCtx,\n ): Computable<AnyLogHandle> | AnyLogHandle {\n if (ctx == undefined) return Computable.make((ctx) => this.getLogHandle(res, ctx));\n\n const r = treeEntryToResourceInfo(res, ctx);\n\n return this.getLogHandleNoCtx(r as ResourceSnapshot);\n }\n\n private getLogHandleNoCtx(rInfo: ResourceSnapshot): AnyLogHandle {\n validateDownloadableResourceType('getLogHandle', rInfo.type);\n return newLogHandle(false, rInfo);\n }\n\n public async lastLines(\n handle: ReadyLogHandle,\n lineCount: number,\n offsetBytes?: number, // if 0n, then start from the end.\n searchStr?: string,\n ): Promise<StreamingApiResponse> {\n const resp = await this.clientLogs.lastLines(\n getResourceInfoFromLogHandle(handle),\n lineCount,\n BigInt(offsetBytes ?? 0),\n searchStr,\n );\n\n return {\n live: false,\n shouldUpdateHandle: false,\n data: resp.data,\n size: Number(resp.size),\n newOffset: Number(resp.newOffset),\n };\n }\n\n public async readText(\n handle: ReadyLogHandle,\n lineCount: number,\n offsetBytes?: number,\n searchStr?: string,\n ): Promise<StreamingApiResponse> {\n const resp = await this.clientLogs.readText(\n getResourceInfoFromLogHandle(handle),\n lineCount,\n BigInt(offsetBytes ?? 0),\n searchStr,\n );\n\n return {\n live: false,\n shouldUpdateHandle: false,\n data: resp.data,\n size: Number(resp.size),\n newOffset: Number(resp.newOffset),\n };\n }\n\n private async releaseBlob(rInfo: ResourceInfo, callerId: string) {\n const task = this.keyToDownload.get(blobKey(rInfo.id));\n if (task == undefined) {\n return;\n }\n\n if (this.cache.existsFile(blobKey(rInfo.id))) {\n const toDelete = this.cache.removeFile(blobKey(rInfo.id), callerId);\n\n await Promise.all(\n toDelete.map(async (cachedFile) => {\n await fsp.rm(cachedFile.path);\n\n this.cache.removeCache(cachedFile);\n\n this.removeTask(\n mapGet(this.keyToDownload, pathToKey(cachedFile.path)),\n `the task ${stringifyWithResourceId(cachedFile)} was removed`\n + `from cache along with ${stringifyWithResourceId(toDelete.map((d) => d.path))}`,\n );\n }),\n );\n } else {\n // The task is still in a downloading queue.\n const deleted = task.counter.dec(callerId);\n if (deleted) {\n this.removeTask(\n task,\n `the task ${stringifyWithResourceId(task.info())} was removed from cache`,\n );\n }\n }\n }\n\n private removeTask(task: DownloadBlobTask, reason: string) {\n task.abort(reason);\n task.change.markChanged(`download task for ${task.path} removed: ${reason}`);\n this.keyToDownload.delete(pathToKey(task.path));\n this.idToLastLines.delete(blobKey(task.rInfo.id));\n this.idToProgressLog.delete(blobKey(task.rInfo.id));\n }\n\n private async releaseOnDemandBlob(blobId: ResourceId, callerId: string) {\n const deleted = this.keyToOnDemand.get(blobKey(blobId))?.release(callerId) ?? false;\n if (deleted) this.keyToOnDemand.delete(blobKey(blobId));\n }\n\n /** Removes all files from a hard drive. */\n async releaseAll() {\n this.downloadQueue.stop();\n\n this.keyToDownload.forEach((task, key) => {\n this.keyToDownload.delete(key);\n task.change.markChanged(`task ${resourceIdToString(task.rInfo.id)} released`);\n });\n }\n}\n\n/** Keeps a counter to the on demand handle. */\nclass OnDemandBlobHolder {\n private readonly counter = new CallersCounter();\n\n constructor(\n private readonly size: number,\n private readonly handle: RemoteBlobHandle,\n ) {}\n\n public getHandle(): RemoteBlobHandleAndSize {\n return { handle: this.handle, size: this.size };\n }\n\n public attach(callerId: string) {\n this.counter.inc(callerId);\n }\n\n public release(callerId: string): boolean {\n return this.counter.dec(callerId);\n }\n}\n\nclass LastLinesGetter {\n private updater: Updater;\n private log: string | undefined;\n private readonly change: ChangeSource = new ChangeSource();\n private error: any | undefined = undefined;\n\n constructor(\n private readonly path: string,\n private readonly lines: number,\n private readonly patternToSearch?: string,\n ) {\n this.updater = new Updater(async () => this.update());\n }\n\n getOrSchedule(w: Watcher): {\n log: string | undefined;\n error?: any | undefined;\n } {\n this.change.attachWatcher(w);\n\n this.updater.schedule();\n\n return {\n log: this.log,\n error: this.error,\n };\n }\n\n async update(): Promise<void> {\n try {\n const newLogs = await getLastLines(this.path, this.lines, this.patternToSearch);\n\n if (this.log != newLogs) this.change.markChanged(`logs for ${this.path} updated`);\n this.log = newLogs;\n } catch (e: any) {\n if (e.name == 'RpcError' && e.code == 'NOT_FOUND') {\n // No resource\n this.log = '';\n this.error = e;\n this.change.markChanged(`log update for ${this.path} failed, resource not found`);\n return;\n }\n\n throw e;\n }\n }\n}\n\n/** Gets last lines from a file by reading the file from the top and keeping\n * last N lines in a window queue. */\nasync function getLastLines(fPath: string, nLines: number, patternToSearch?: string): Promise<string> {\n let inStream: fs.ReadStream | undefined;\n let rl: readline.Interface | undefined;\n\n try {\n inStream = fs.createReadStream(fPath);\n rl = readline.createInterface({ input: inStream, crlfDelay: Infinity });\n\n const lines = new Denque();\n\n for await (const line of rl) {\n if (patternToSearch != undefined && !line.includes(patternToSearch)) continue;\n\n lines.push(line);\n if (lines.length > nLines) {\n lines.shift();\n }\n }\n\n // last EOL is for keeping backward compat with platforma implementation.\n return lines.toArray().join(os.EOL) + os.EOL;\n } finally {\n // Cleanup resources in finally block to ensure they're always cleaned up\n try {\n if (rl) {\n rl.close();\n }\n } catch (cleanupError) {\n console.error('Error closing readline interface:', cleanupError);\n }\n\n try {\n if (inStream && !inStream.destroyed) {\n inStream.destroy();\n }\n } catch (cleanupError) {\n console.error('Error destroying read stream:', cleanupError);\n }\n }\n}\n\nfunction validateDownloadableResourceType(methodName: string, rType: ResourceType) {\n if (!rType.name.startsWith('Blob/')) {\n let message = `${methodName}: wrong resource type: ${rType.name}, expected: a resource of type that starts with 'Blob/'.`;\n if (rType.name == 'Blob')\n message += ` If it's called from workflow, should a file be exported with 'file.exportFile' function?`;\n\n throw new WrongResourceTypeError(message);\n }\n}\n"],"names":["FilesCache","SparseCacheFsRanges","SparseCacheFsFile","SparseCache","TaskProcessor","path","Computable","treeEntryToResourceInfo","randomUUID","blobKey","DownloadBlobTask","newLocalHandle","nonRecoverableError","isPlTreeEntry","makeResourceSnapshot","OnDemandBlobResourceSnapshot","getSize","newRemoteHandle","parseLocalHandle","validateRangeBytes","isLocalBlobHandle","readFileContent","isRemoteBlobHandle","parseRemoteHandle","buffer","newLogHandle","getResourceInfoFromLogHandle","fsp","mapGet","pathToKey","stringifyWithResourceId","resourceIdToString","CallersCounter","ChangeSource","Updater","fs","readline","os","WrongResourceTypeError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuFA;AAC6D;MAChD,cAAc,CAAA;AAoBN,IAAA,MAAA;AACA,IAAA,cAAA;AACA,IAAA,UAAA;AAEA,IAAA,cAAA;AACA,IAAA,MAAA;AACA,IAAA,GAAA;;AAxBX,IAAA,aAAa,GAAkC,IAAI,GAAG,EAAE;AAEhE;AAC+B;AACvB,IAAA,KAAK;AACL,IAAA,WAAW;;AAGX,IAAA,aAAa;AAEb,IAAA,aAAa,GAAoC,IAAI,GAAG,EAAE;AAE1D,IAAA,aAAa,GAAiC,IAAI,GAAG,EAAE;AACvD,IAAA,eAAe,GAAiC,IAAI,GAAG,EAAE;AAEhD,IAAA,OAAO;AAExB,IAAA,WAAA,CACmB,MAAgB,EAChB,cAA8B,EAC9B,UAAsB,EACvC,OAAe,EAC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es all files from a hard drive. */
93
93
  releaseAll(): Promise<void>;
94
94
  }
95
- //# sourceMappingURL=download_blob.d.ts.map