@owlmeans/file-streams 0.0.0-stage → 0.2.0-alpha.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 (475) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -2
  3. package/agent-meta/manifest.json +64 -0
  4. package/agent-meta/skills/file-streams/SKILL.md +183 -0
  5. package/agent-meta/skills/file-streams/parts/network.md +47 -0
  6. package/agent-meta/skills/file-streams/parts/workspaces.md +129 -0
  7. package/build/archive/consts.d.ts +16 -0
  8. package/build/archive/consts.d.ts.map +1 -0
  9. package/build/archive/consts.js +24 -0
  10. package/build/archive/consts.js.map +1 -0
  11. package/build/archive/formats.d.ts +4 -0
  12. package/build/archive/formats.d.ts.map +1 -0
  13. package/build/archive/formats.js +53 -0
  14. package/build/archive/formats.js.map +1 -0
  15. package/build/archive/guard.d.ts +5 -0
  16. package/build/archive/guard.d.ts.map +1 -0
  17. package/build/archive/guard.js +62 -0
  18. package/build/archive/guard.js.map +1 -0
  19. package/build/archive/ratio.d.ts +5 -0
  20. package/build/archive/ratio.d.ts.map +1 -0
  21. package/build/archive/ratio.js +30 -0
  22. package/build/archive/ratio.js.map +1 -0
  23. package/build/archive/tar.d.ts +4 -0
  24. package/build/archive/tar.d.ts.map +1 -0
  25. package/build/archive/tar.js +142 -0
  26. package/build/archive/tar.js.map +1 -0
  27. package/build/archive/types.d.ts +95 -0
  28. package/build/archive/types.d.ts.map +1 -0
  29. package/build/archive/types.js +2 -0
  30. package/build/archive/types.js.map +1 -0
  31. package/build/archive/types.local.d.ts +64 -0
  32. package/build/archive/types.local.d.ts.map +1 -0
  33. package/build/archive/types.local.js +2 -0
  34. package/build/archive/types.local.js.map +1 -0
  35. package/build/archive/zip.d.ts +4 -0
  36. package/build/archive/zip.d.ts.map +1 -0
  37. package/build/archive/zip.js +135 -0
  38. package/build/archive/zip.js.map +1 -0
  39. package/build/archive.d.ts +4 -0
  40. package/build/archive.d.ts.map +1 -0
  41. package/build/archive.js +265 -0
  42. package/build/archive.js.map +1 -0
  43. package/build/backed-workspace/types.d.ts +67 -0
  44. package/build/backed-workspace/types.d.ts.map +1 -0
  45. package/build/backed-workspace/types.js +2 -0
  46. package/build/backed-workspace/types.js.map +1 -0
  47. package/build/backed-workspace.d.ts +4 -0
  48. package/build/backed-workspace.d.ts.map +1 -0
  49. package/build/backed-workspace.js +63 -0
  50. package/build/backed-workspace.js.map +1 -0
  51. package/build/consts.d.ts +3 -0
  52. package/build/consts.d.ts.map +1 -0
  53. package/build/consts.js +3 -0
  54. package/build/consts.js.map +1 -0
  55. package/build/consts.local.d.ts +3 -0
  56. package/build/consts.local.d.ts.map +1 -0
  57. package/build/consts.local.js +3 -0
  58. package/build/consts.local.js.map +1 -0
  59. package/build/errors.d.ts +59 -0
  60. package/build/errors.d.ts.map +1 -0
  61. package/build/errors.js +105 -0
  62. package/build/errors.js.map +1 -0
  63. package/build/http/connector.d.ts +11 -0
  64. package/build/http/connector.d.ts.map +1 -0
  65. package/build/http/connector.js +124 -0
  66. package/build/http/connector.js.map +1 -0
  67. package/build/http/consts.d.ts +9 -0
  68. package/build/http/consts.d.ts.map +1 -0
  69. package/build/http/consts.js +8 -0
  70. package/build/http/consts.js.map +1 -0
  71. package/build/http/source.d.ts +5 -0
  72. package/build/http/source.d.ts.map +1 -0
  73. package/build/http/source.js +76 -0
  74. package/build/http/source.js.map +1 -0
  75. package/build/http/types.d.ts +67 -0
  76. package/build/http/types.d.ts.map +1 -0
  77. package/build/http/types.js +2 -0
  78. package/build/http/types.js.map +1 -0
  79. package/build/http/types.local.d.ts +21 -0
  80. package/build/http/types.local.d.ts.map +1 -0
  81. package/build/http/types.local.js +2 -0
  82. package/build/http/types.local.js.map +1 -0
  83. package/build/http.d.ts +4 -0
  84. package/build/http.d.ts.map +1 -0
  85. package/build/http.js +248 -0
  86. package/build/http.js.map +1 -0
  87. package/build/index.d.ts +53 -0
  88. package/build/index.d.ts.map +1 -0
  89. package/build/index.js +33 -0
  90. package/build/index.js.map +1 -0
  91. package/build/network/consts.d.ts +12 -0
  92. package/build/network/consts.d.ts.map +1 -0
  93. package/build/network/consts.js +20 -0
  94. package/build/network/consts.js.map +1 -0
  95. package/build/network/types.d.ts +43 -0
  96. package/build/network/types.d.ts.map +1 -0
  97. package/build/network/types.js +2 -0
  98. package/build/network/types.js.map +1 -0
  99. package/build/network.d.ts +4 -0
  100. package/build/network.d.ts.map +1 -0
  101. package/build/network.js +165 -0
  102. package/build/network.js.map +1 -0
  103. package/build/proxy/consts.d.ts +7 -0
  104. package/build/proxy/consts.d.ts.map +1 -0
  105. package/build/proxy/consts.js +9 -0
  106. package/build/proxy/consts.js.map +1 -0
  107. package/build/proxy/endpoint.d.ts +4 -0
  108. package/build/proxy/endpoint.d.ts.map +1 -0
  109. package/build/proxy/endpoint.js +27 -0
  110. package/build/proxy/endpoint.js.map +1 -0
  111. package/build/proxy/http.d.ts +5 -0
  112. package/build/proxy/http.d.ts.map +1 -0
  113. package/build/proxy/http.js +95 -0
  114. package/build/proxy/http.js.map +1 -0
  115. package/build/proxy/router.d.ts +4 -0
  116. package/build/proxy/router.d.ts.map +1 -0
  117. package/build/proxy/router.js +85 -0
  118. package/build/proxy/router.js.map +1 -0
  119. package/build/proxy/socks.d.ts +5 -0
  120. package/build/proxy/socks.d.ts.map +1 -0
  121. package/build/proxy/socks.js +44 -0
  122. package/build/proxy/socks.js.map +1 -0
  123. package/build/proxy/types.d.ts +99 -0
  124. package/build/proxy/types.d.ts.map +1 -0
  125. package/build/proxy/types.js +2 -0
  126. package/build/proxy/types.js.map +1 -0
  127. package/build/resolvers/google-drive/consts.d.ts +10 -0
  128. package/build/resolvers/google-drive/consts.d.ts.map +1 -0
  129. package/build/resolvers/google-drive/consts.js +16 -0
  130. package/build/resolvers/google-drive/consts.js.map +1 -0
  131. package/build/resolvers/google-drive/types.d.ts +21 -0
  132. package/build/resolvers/google-drive/types.d.ts.map +1 -0
  133. package/build/resolvers/google-drive/types.js +2 -0
  134. package/build/resolvers/google-drive/types.js.map +1 -0
  135. package/build/resolvers/google-drive.d.ts +10 -0
  136. package/build/resolvers/google-drive.d.ts.map +1 -0
  137. package/build/resolvers/google-drive.js +130 -0
  138. package/build/resolvers/google-drive.js.map +1 -0
  139. package/build/resolvers/types.d.ts +39 -0
  140. package/build/resolvers/types.d.ts.map +1 -0
  141. package/build/resolvers/types.js +2 -0
  142. package/build/resolvers/types.js.map +1 -0
  143. package/build/s3/consts.d.ts +9 -0
  144. package/build/s3/consts.d.ts.map +1 -0
  145. package/build/s3/consts.js +9 -0
  146. package/build/s3/consts.js.map +1 -0
  147. package/build/s3/prefix.d.ts +4 -0
  148. package/build/s3/prefix.d.ts.map +1 -0
  149. package/build/s3/prefix.js +87 -0
  150. package/build/s3/prefix.js.map +1 -0
  151. package/build/s3/sink.d.ts +6 -0
  152. package/build/s3/sink.d.ts.map +1 -0
  153. package/build/s3/sink.js +30 -0
  154. package/build/s3/sink.js.map +1 -0
  155. package/build/s3/source.d.ts +5 -0
  156. package/build/s3/source.d.ts.map +1 -0
  157. package/build/s3/source.js +81 -0
  158. package/build/s3/source.js.map +1 -0
  159. package/build/s3/types.d.ts +66 -0
  160. package/build/s3/types.d.ts.map +1 -0
  161. package/build/s3/types.js +2 -0
  162. package/build/s3/types.js.map +1 -0
  163. package/build/s3/types.local.d.ts +43 -0
  164. package/build/s3/types.local.d.ts.map +1 -0
  165. package/build/s3/types.local.js +2 -0
  166. package/build/s3/types.local.js.map +1 -0
  167. package/build/s3/upload.d.ts +4 -0
  168. package/build/s3/upload.d.ts.map +1 -0
  169. package/build/s3/upload.js +118 -0
  170. package/build/s3/upload.js.map +1 -0
  171. package/build/s3.d.ts +5 -0
  172. package/build/s3.d.ts.map +1 -0
  173. package/build/s3.js +68 -0
  174. package/build/s3.js.map +1 -0
  175. package/build/service/types.d.ts +66 -0
  176. package/build/service/types.d.ts.map +1 -0
  177. package/build/service/types.js +2 -0
  178. package/build/service/types.js.map +1 -0
  179. package/build/service/types.local.d.ts +11 -0
  180. package/build/service/types.local.d.ts.map +1 -0
  181. package/build/service/types.local.js +2 -0
  182. package/build/service/types.local.js.map +1 -0
  183. package/build/service.d.ts +6 -0
  184. package/build/service.d.ts.map +1 -0
  185. package/build/service.js +73 -0
  186. package/build/service.js.map +1 -0
  187. package/build/sinks/buffer/consts.d.ts +2 -0
  188. package/build/sinks/buffer/consts.d.ts.map +1 -0
  189. package/build/sinks/buffer/consts.js +2 -0
  190. package/build/sinks/buffer/consts.js.map +1 -0
  191. package/build/sinks/buffer/types.d.ts +11 -0
  192. package/build/sinks/buffer/types.d.ts.map +1 -0
  193. package/build/sinks/buffer/types.js +2 -0
  194. package/build/sinks/buffer/types.js.map +1 -0
  195. package/build/sinks/buffer.d.ts +4 -0
  196. package/build/sinks/buffer.d.ts.map +1 -0
  197. package/build/sinks/buffer.js +13 -0
  198. package/build/sinks/buffer.js.map +1 -0
  199. package/build/sinks/directory/types.d.ts +7 -0
  200. package/build/sinks/directory/types.d.ts.map +1 -0
  201. package/build/sinks/directory/types.js +2 -0
  202. package/build/sinks/directory/types.js.map +1 -0
  203. package/build/sinks/directory.d.ts +8 -0
  204. package/build/sinks/directory.d.ts.map +1 -0
  205. package/build/sinks/directory.js +43 -0
  206. package/build/sinks/directory.js.map +1 -0
  207. package/build/sinks/file.d.ts +5 -0
  208. package/build/sinks/file.d.ts.map +1 -0
  209. package/build/sinks/file.js +46 -0
  210. package/build/sinks/file.js.map +1 -0
  211. package/build/sinks/types.d.ts +11 -0
  212. package/build/sinks/types.d.ts.map +1 -0
  213. package/build/sinks/types.js +2 -0
  214. package/build/sinks/types.js.map +1 -0
  215. package/build/sinks/workload/consts.d.ts +5 -0
  216. package/build/sinks/workload/consts.d.ts.map +1 -0
  217. package/build/sinks/workload/consts.js +5 -0
  218. package/build/sinks/workload/consts.js.map +1 -0
  219. package/build/sinks/workload/types.d.ts +17 -0
  220. package/build/sinks/workload/types.d.ts.map +1 -0
  221. package/build/sinks/workload/types.js +2 -0
  222. package/build/sinks/workload/types.js.map +1 -0
  223. package/build/sinks/workload.d.ts +8 -0
  224. package/build/sinks/workload.d.ts.map +1 -0
  225. package/build/sinks/workload.js +51 -0
  226. package/build/sinks/workload.js.map +1 -0
  227. package/build/sources/buffer.d.ts +5 -0
  228. package/build/sources/buffer.d.ts.map +1 -0
  229. package/build/sources/buffer.js +20 -0
  230. package/build/sources/buffer.js.map +1 -0
  231. package/build/sources/file.d.ts +5 -0
  232. package/build/sources/file.d.ts.map +1 -0
  233. package/build/sources/file.js +50 -0
  234. package/build/sources/file.js.map +1 -0
  235. package/build/sources/stream.d.ts +5 -0
  236. package/build/sources/stream.d.ts.map +1 -0
  237. package/build/sources/stream.js +19 -0
  238. package/build/sources/stream.js.map +1 -0
  239. package/build/sources/types.d.ts +10 -0
  240. package/build/sources/types.d.ts.map +1 -0
  241. package/build/sources/types.js +2 -0
  242. package/build/sources/types.js.map +1 -0
  243. package/build/sources/workload/types.d.ts +29 -0
  244. package/build/sources/workload/types.d.ts.map +1 -0
  245. package/build/sources/workload/types.js +2 -0
  246. package/build/sources/workload/types.js.map +1 -0
  247. package/build/sources/workload.d.ts +7 -0
  248. package/build/sources/workload.d.ts.map +1 -0
  249. package/build/sources/workload.js +67 -0
  250. package/build/sources/workload.js.map +1 -0
  251. package/build/transfer/consts.d.ts +5 -0
  252. package/build/transfer/consts.d.ts.map +1 -0
  253. package/build/transfer/consts.js +8 -0
  254. package/build/transfer/consts.js.map +1 -0
  255. package/build/transfer/types.d.ts +49 -0
  256. package/build/transfer/types.d.ts.map +1 -0
  257. package/build/transfer/types.js +2 -0
  258. package/build/transfer/types.js.map +1 -0
  259. package/build/transfer.d.ts +4 -0
  260. package/build/transfer.d.ts.map +1 -0
  261. package/build/transfer.js +75 -0
  262. package/build/transfer.js.map +1 -0
  263. package/build/types.d.ts +99 -0
  264. package/build/types.d.ts.map +1 -0
  265. package/build/types.js +2 -0
  266. package/build/types.js.map +1 -0
  267. package/build/utils/names/consts.d.ts +5 -0
  268. package/build/utils/names/consts.d.ts.map +1 -0
  269. package/build/utils/names/consts.js +5 -0
  270. package/build/utils/names/consts.js.map +1 -0
  271. package/build/utils/names/types.d.ts +13 -0
  272. package/build/utils/names/types.d.ts.map +1 -0
  273. package/build/utils/names/types.js +2 -0
  274. package/build/utils/names/types.js.map +1 -0
  275. package/build/utils/names.d.ts +4 -0
  276. package/build/utils/names.d.ts.map +1 -0
  277. package/build/utils/names.js +60 -0
  278. package/build/utils/names.js.map +1 -0
  279. package/build/utils/paths/consts.d.ts +3 -0
  280. package/build/utils/paths/consts.d.ts.map +1 -0
  281. package/build/utils/paths/consts.js +2 -0
  282. package/build/utils/paths/consts.js.map +1 -0
  283. package/build/utils/paths/types.d.ts +20 -0
  284. package/build/utils/paths/types.d.ts.map +1 -0
  285. package/build/utils/paths/types.js +2 -0
  286. package/build/utils/paths/types.js.map +1 -0
  287. package/build/utils/paths.d.ts +4 -0
  288. package/build/utils/paths.d.ts.map +1 -0
  289. package/build/utils/paths.js +67 -0
  290. package/build/utils/paths.js.map +1 -0
  291. package/build/utils/range/types.d.ts +11 -0
  292. package/build/utils/range/types.d.ts.map +1 -0
  293. package/build/utils/range/types.js +2 -0
  294. package/build/utils/range/types.js.map +1 -0
  295. package/build/utils/range.d.ts +4 -0
  296. package/build/utils/range.d.ts.map +1 -0
  297. package/build/utils/range.js +64 -0
  298. package/build/utils/range.js.map +1 -0
  299. package/build/utils/redact/types.d.ts +16 -0
  300. package/build/utils/redact/types.d.ts.map +1 -0
  301. package/build/utils/redact/types.js +2 -0
  302. package/build/utils/redact/types.js.map +1 -0
  303. package/build/utils/redact.d.ts +4 -0
  304. package/build/utils/redact.d.ts.map +1 -0
  305. package/build/utils/redact.js +18 -0
  306. package/build/utils/redact.js.map +1 -0
  307. package/build/utils/signals/types.d.ts +17 -0
  308. package/build/utils/signals/types.d.ts.map +1 -0
  309. package/build/utils/signals/types.js +2 -0
  310. package/build/utils/signals/types.js.map +1 -0
  311. package/build/utils/signals.d.ts +4 -0
  312. package/build/utils/signals.d.ts.map +1 -0
  313. package/build/utils/signals.js +52 -0
  314. package/build/utils/signals.js.map +1 -0
  315. package/build/utils/streams/consts.d.ts +3 -0
  316. package/build/utils/streams/consts.d.ts.map +1 -0
  317. package/build/utils/streams/consts.js +3 -0
  318. package/build/utils/streams/consts.js.map +1 -0
  319. package/build/utils/streams/types.d.ts +59 -0
  320. package/build/utils/streams/types.d.ts.map +1 -0
  321. package/build/utils/streams/types.js +2 -0
  322. package/build/utils/streams/types.js.map +1 -0
  323. package/build/utils/streams.d.ts +4 -0
  324. package/build/utils/streams.d.ts.map +1 -0
  325. package/build/utils/streams.js +167 -0
  326. package/build/utils/streams.js.map +1 -0
  327. package/build/utils/tree/types.d.ts +6 -0
  328. package/build/utils/tree/types.d.ts.map +1 -0
  329. package/build/utils/tree/types.js +2 -0
  330. package/build/utils/tree/types.js.map +1 -0
  331. package/build/utils/tree.d.ts +4 -0
  332. package/build/utils/tree.d.ts.map +1 -0
  333. package/build/utils/tree.js +14 -0
  334. package/build/utils/tree.js.map +1 -0
  335. package/build/workspace/consts.d.ts +12 -0
  336. package/build/workspace/consts.d.ts.map +1 -0
  337. package/build/workspace/consts.js +12 -0
  338. package/build/workspace/consts.js.map +1 -0
  339. package/build/workspace/consts.local.d.ts +3 -0
  340. package/build/workspace/consts.local.d.ts.map +1 -0
  341. package/build/workspace/consts.local.js +3 -0
  342. package/build/workspace/consts.local.js.map +1 -0
  343. package/build/workspace/fs.d.ts +4 -0
  344. package/build/workspace/fs.d.ts.map +1 -0
  345. package/build/workspace/fs.js +45 -0
  346. package/build/workspace/fs.js.map +1 -0
  347. package/build/workspace/scope.d.ts +6 -0
  348. package/build/workspace/scope.d.ts.map +1 -0
  349. package/build/workspace/scope.js +180 -0
  350. package/build/workspace/scope.js.map +1 -0
  351. package/build/workspace/types.d.ts +66 -0
  352. package/build/workspace/types.d.ts.map +1 -0
  353. package/build/workspace/types.js +2 -0
  354. package/build/workspace/types.js.map +1 -0
  355. package/build/workspace/types.local.d.ts +20 -0
  356. package/build/workspace/types.local.d.ts.map +1 -0
  357. package/build/workspace/types.local.js +2 -0
  358. package/build/workspace/types.local.js.map +1 -0
  359. package/build/workspace.d.ts +7 -0
  360. package/build/workspace.d.ts.map +1 -0
  361. package/build/workspace.js +87 -0
  362. package/build/workspace.js.map +1 -0
  363. package/package.json +61 -4
  364. package/src/archive/consts.ts +28 -0
  365. package/src/archive/formats.ts +60 -0
  366. package/src/archive/guard.ts +68 -0
  367. package/src/archive/ratio.ts +35 -0
  368. package/src/archive/tar.ts +147 -0
  369. package/src/archive/types.local.ts +72 -0
  370. package/src/archive/types.ts +107 -0
  371. package/src/archive/zip.ts +142 -0
  372. package/src/archive.ts +298 -0
  373. package/src/backed-workspace/types.ts +72 -0
  374. package/src/backed-workspace.ts +85 -0
  375. package/src/consts.local.ts +2 -0
  376. package/src/consts.ts +2 -0
  377. package/src/errors.ts +128 -0
  378. package/src/http/connector.ts +136 -0
  379. package/src/http/consts.ts +13 -0
  380. package/src/http/source.ts +89 -0
  381. package/src/http/types.local.ts +23 -0
  382. package/src/http/types.ts +74 -0
  383. package/src/http.ts +276 -0
  384. package/src/index.ts +65 -0
  385. package/src/network/consts.ts +22 -0
  386. package/src/network/types.ts +45 -0
  387. package/src/network.ts +179 -0
  388. package/src/proxy/consts.ts +11 -0
  389. package/src/proxy/endpoint.ts +28 -0
  390. package/src/proxy/http.ts +108 -0
  391. package/src/proxy/router.ts +93 -0
  392. package/src/proxy/socks.ts +48 -0
  393. package/src/proxy/types.ts +114 -0
  394. package/src/resolvers/google-drive/consts.ts +22 -0
  395. package/src/resolvers/google-drive/types.ts +22 -0
  396. package/src/resolvers/google-drive.ts +153 -0
  397. package/src/resolvers/types.ts +45 -0
  398. package/src/s3/consts.ts +12 -0
  399. package/src/s3/prefix.ts +100 -0
  400. package/src/s3/sink.ts +36 -0
  401. package/src/s3/source.ts +90 -0
  402. package/src/s3/types.local.ts +49 -0
  403. package/src/s3/types.ts +70 -0
  404. package/src/s3/upload.ts +130 -0
  405. package/src/s3.ts +83 -0
  406. package/src/service/types.local.ts +9 -0
  407. package/src/service/types.ts +71 -0
  408. package/src/service.ts +97 -0
  409. package/src/sinks/buffer/consts.ts +1 -0
  410. package/src/sinks/buffer/types.ts +12 -0
  411. package/src/sinks/buffer.ts +18 -0
  412. package/src/sinks/directory/types.ts +7 -0
  413. package/src/sinks/directory.ts +49 -0
  414. package/src/sinks/file.ts +52 -0
  415. package/src/sinks/types.ts +12 -0
  416. package/src/sinks/workload/consts.ts +5 -0
  417. package/src/sinks/workload/types.ts +17 -0
  418. package/src/sinks/workload.ts +59 -0
  419. package/src/sources/buffer.ts +27 -0
  420. package/src/sources/file.ts +57 -0
  421. package/src/sources/stream.ts +26 -0
  422. package/src/sources/types.ts +12 -0
  423. package/src/sources/workload/types.ts +31 -0
  424. package/src/sources/workload.ts +79 -0
  425. package/src/transfer/consts.ts +10 -0
  426. package/src/transfer/types.ts +55 -0
  427. package/src/transfer.ts +89 -0
  428. package/src/types.ts +106 -0
  429. package/src/utils/names/consts.ts +5 -0
  430. package/src/utils/names/types.ts +12 -0
  431. package/src/utils/names.ts +70 -0
  432. package/src/utils/paths/consts.ts +3 -0
  433. package/src/utils/paths/types.ts +20 -0
  434. package/src/utils/paths.ts +75 -0
  435. package/src/utils/range/types.ts +11 -0
  436. package/src/utils/range.ts +80 -0
  437. package/src/utils/redact/types.ts +16 -0
  438. package/src/utils/redact.ts +23 -0
  439. package/src/utils/signals/types.ts +17 -0
  440. package/src/utils/signals.ts +63 -0
  441. package/src/utils/streams/consts.ts +2 -0
  442. package/src/utils/streams/types.ts +65 -0
  443. package/src/utils/streams.ts +188 -0
  444. package/src/utils/tree/types.ts +6 -0
  445. package/src/utils/tree.ts +18 -0
  446. package/src/workspace/consts.local.ts +2 -0
  447. package/src/workspace/consts.ts +14 -0
  448. package/src/workspace/fs.ts +48 -0
  449. package/src/workspace/scope.ts +196 -0
  450. package/src/workspace/types.local.ts +21 -0
  451. package/src/workspace/types.ts +71 -0
  452. package/src/workspace.ts +102 -0
  453. package/tests/archive.spec.ts +134 -0
  454. package/tests/backed.spec.ts +147 -0
  455. package/tests/context.ts +114 -0
  456. package/tests/fixtures.ts +190 -0
  457. package/tests/google-drive.spec.ts +76 -0
  458. package/tests/harness/drive.ts +92 -0
  459. package/tests/harness/http-proxy.ts +96 -0
  460. package/tests/harness/origin.ts +134 -0
  461. package/tests/harness/socks5.ts +135 -0
  462. package/tests/harness/workload.ts +118 -0
  463. package/tests/http.spec.ts +101 -0
  464. package/tests/inspector.spec.ts +40 -0
  465. package/tests/live.spec.ts +27 -0
  466. package/tests/network.spec.ts +79 -0
  467. package/tests/proxy.spec.ts +149 -0
  468. package/tests/s3.spec.ts +133 -0
  469. package/tests/service.spec.ts +77 -0
  470. package/tests/sources-sinks.spec.ts +96 -0
  471. package/tests/transfer.spec.ts +99 -0
  472. package/tests/tsconfig.json +12 -0
  473. package/tests/workload.spec.ts +140 -0
  474. package/tests/workspace.spec.ts +158 -0
  475. package/tsconfig.json +16 -0
package/src/archive.ts ADDED
@@ -0,0 +1,298 @@
1
+ import { basename } from 'node:path'
2
+ import { PassThrough, pipeline } from 'node:stream'
3
+ import type { Readable } from 'node:stream'
4
+ import { createGunzip, createGzip } from 'node:zlib'
5
+ import { logger } from '@owlmeans/log'
6
+ import { DEFAULT_SAMPLE_BYTES, fileInspector } from '@owlmeans/file-inspector'
7
+ import type { FileVerdict } from '@owlmeans/file-inspector'
8
+ import { ArchiveFormat, DEFAULT_ARCHIVE_LIMITS, NESTED_ARCHIVE_EXTENSIONS } from './archive/consts.js'
9
+ import { createFormatSniffer } from './archive/formats.js'
10
+ import { makeEntryGuard } from './archive/guard.js'
11
+ import { makeRatioGuard } from './archive/ratio.js'
12
+ import { createTarCodec } from './archive/tar.js'
13
+ import { createZipCodec } from './archive/zip.js'
14
+ import type {
15
+ ArchiveEntryInfo, ArchiveExtractOptions, ArchiveHelper, ArchiveHelperOptions, ArchiveLimits, ArchiveListOptions,
16
+ ArchivePackOptions, ExtractResult, PackEntry,
17
+ } from './archive/types.js'
18
+ import type { AcquiredArchive, ArchiveEntryHandle, EntryGuard } from './archive/types.local.js'
19
+ import { ArchiveError, LimitError, PathError } from './errors.js'
20
+ import { createFileSource } from './sources/file.js'
21
+ import { createStreamSource } from './sources/stream.js'
22
+ import type { FileInfo, FileSource, OpenedFile, OpenOptions, SignalOptions, TreeSink } from './types.js'
23
+ import { nameUtils } from './utils/names.js'
24
+ import { rangeUtils } from './utils/range.js'
25
+ import { streamUtils } from './utils/streams.js'
26
+ import { treeUtils } from './utils/tree.js'
27
+
28
+ const log = logger('file-streams:archive')
29
+
30
+ export const createArchiveHelper = (options: ArchiveHelperOptions = {}): ArchiveHelper => {
31
+ const baseLimits: ArchiveLimits = { ...DEFAULT_ARCHIVE_LIMITS, ...options.limits }
32
+ const inspector = options.inspector ?? fileInspector
33
+ const sniffer = createFormatSniffer()
34
+ const zip = createZipCodec()
35
+ const tar = createTarCodec()
36
+ const headBytes = 8 * 1024
37
+
38
+ const limitsOf = (listOptions?: ArchiveListOptions): ArchiveLimits => ({ ...baseLimits, ...listOptions?.limits })
39
+
40
+ const chain = (...streams: Array<NodeJS.ReadableStream | NodeJS.WritableStream>): Readable =>
41
+ (pipeline as unknown as (...parts: unknown[]) => Readable)(...streams, () => undefined)
42
+
43
+ const acquire = async (source: FileSource, format: ArchiveFormat | undefined, limits: ArchiveLimits, signal?: AbortSignal): Promise<AcquiredArchive> => {
44
+ const reader = await source.ranges({ signal })
45
+ if (reader != null) {
46
+ const head = await reader.read(0, Math.min(headBytes, reader.size), signal)
47
+ const detected = format ?? sniffer.formatOf(head)
48
+ if (detected === ArchiveFormat.Zip) {
49
+ return { format: detected, head, reader, dispose: async () => await reader.close() }
50
+ }
51
+ await reader.close()
52
+ const opened = await source.open({ signal })
53
+ return { format: detected, head, stream: opened.stream, dispose: async () => streamUtils.discard(opened.stream) }
54
+ }
55
+
56
+ const opened = await source.open({ signal })
57
+ const peeked = await streamUtils.peek(opened.stream, headBytes)
58
+ const detected = format ?? sniffer.formatOf(peeked.head)
59
+ if (detected !== ArchiveFormat.Zip) {
60
+ return { format: detected, head: peeked.head, stream: peeked.stream, dispose: async () => streamUtils.discard(peeked.stream) }
61
+ }
62
+ const spooled = await streamUtils.spool(peeked.stream, { maxBytes: limits.maxTotalBytes, signal })
63
+ const fileReader = rangeUtils.ofFile(spooled.path, spooled.size)
64
+ log.debug('Spooled a zip without random access', { bytes: spooled.size })
65
+
66
+ return {
67
+ format: detected,
68
+ head: peeked.head,
69
+ reader: fileReader,
70
+ dispose: async () => {
71
+ await fileReader.close()
72
+ await spooled.dispose()
73
+ },
74
+ }
75
+ }
76
+
77
+ const gzipEntryName = (head: Uint8Array, info: FileInfo): string => {
78
+ const fromHeader = nameUtils.sanitize(sniffer.gzipName(head))
79
+ if (fromHeader != null) {
80
+ return fromHeader
81
+ }
82
+ const name = info.name ?? 'data.gz'
83
+ return name.toLowerCase().endsWith('.gz') && name.length > 3 ? name.slice(0, -3) : `${name}.out`
84
+ }
85
+
86
+ const handlesOf = async function * (acquired: AcquiredArchive, info: FileInfo, limits: ArchiveLimits): AsyncGenerator<ArchiveEntryHandle> {
87
+ switch (acquired.format) {
88
+ case ArchiveFormat.Zip:
89
+ yield * zip.entries(acquired.reader!, limits)
90
+ return
91
+ case ArchiveFormat.Tar:
92
+ yield * tar.entries(acquired.stream!)
93
+ return
94
+ case ArchiveFormat.TarGz: {
95
+ const ratio = makeRatioGuard(limits)
96
+ yield * tar.entries(chain(acquired.stream!, ratio.input, createGunzip(), ratio.output))
97
+ return
98
+ }
99
+ case ArchiveFormat.Gzip: {
100
+ const ratio = makeRatioGuard(limits)
101
+ const stream = chain(acquired.stream!, ratio.input, createGunzip(), ratio.output)
102
+ yield {
103
+ info: { path: gzipEntryName(acquired.head, info), type: 'file' },
104
+ open: async () => stream,
105
+ drain: async () => streamUtils.discard(stream),
106
+ }
107
+ return
108
+ }
109
+ default:
110
+ throw new ArchiveError('format')
111
+ }
112
+ }
113
+
114
+ const detect = async (source: FileSource, detectOptions: SignalOptions = {}): Promise<ArchiveFormat | null> => {
115
+ const acquired = await acquire(source, undefined, baseLimits, detectOptions.signal)
116
+ await acquired.dispose()
117
+ return acquired.format
118
+ }
119
+
120
+ const list = async (source: FileSource, listOptions: ArchiveListOptions = {}): Promise<ArchiveEntryInfo[]> => {
121
+ const limits = limitsOf(listOptions)
122
+ const acquired = await acquire(source, listOptions.format, limits, listOptions.signal)
123
+ const entries: ArchiveEntryInfo[] = []
124
+ try {
125
+ for await (const handle of handlesOf(acquired, await source.info(), limits)) {
126
+ entries.push(handle.info)
127
+ if (entries.length > limits.maxEntries) {
128
+ throw new LimitError('entries')
129
+ }
130
+ await handle.drain()
131
+ }
132
+ } finally {
133
+ await acquired.dispose()
134
+ }
135
+
136
+ return entries
137
+ }
138
+
139
+ const isNested = (path: string): boolean => {
140
+ const ext = nameUtils.extOf(path)
141
+ return ext != null && NESTED_ARCHIVE_EXTENSIONS.includes(ext)
142
+ }
143
+
144
+ const nestedPrefix = (path: string): string => {
145
+ const ext = nameUtils.extOf(path) ?? ''
146
+ return path.slice(0, path.length - ext.length - 1) || path
147
+ }
148
+
149
+ const extractInto = async (
150
+ source: FileSource, tree: TreeSink, extractOptions: ArchiveExtractOptions, depth: number, result: ExtractResult
151
+ ): Promise<void> => {
152
+ const signal = extractOptions.signal
153
+ const limits = limitsOf(extractOptions)
154
+ const guard: EntryGuard = makeEntryGuard(limits, extractOptions.links ?? 'skip', extractOptions.strip ?? 0)
155
+ const info = await source.info({ signal })
156
+ const acquired = await acquire(source, depth === 1 ? extractOptions.format : undefined, limits, signal)
157
+ if (acquired.format == null) {
158
+ await acquired.dispose()
159
+ throw new ArchiveError('format')
160
+ }
161
+ if (depth === 1) {
162
+ result.format = acquired.format
163
+ }
164
+
165
+ try {
166
+ for await (const handle of handlesOf(acquired, info, limits)) {
167
+ signal?.throwIfAborted()
168
+ const admission = guard.admit(handle.info)
169
+ if (admission.path == null) {
170
+ result.skipped.push({ entry: handle.info, reason: admission.skip ?? 'skipped' })
171
+ await handle.drain()
172
+ continue
173
+ }
174
+ if (extractOptions.filter != null && !extractOptions.filter(handle.info)) {
175
+ result.skipped.push({ entry: handle.info, reason: 'filtered' })
176
+ await handle.drain()
177
+ continue
178
+ }
179
+ if (handle.info.type === 'directory') {
180
+ await tree.directory(admission.path, { signal })
181
+ continue
182
+ }
183
+
184
+ const path = admission.path
185
+ try {
186
+ let stream = chain(await handle.open(), guard.meter())
187
+ let verdict: FileVerdict | undefined
188
+ if (extractOptions.verify != null) {
189
+ const peeked = await streamUtils.peek(stream, extractOptions.verify.sampleBytes ?? DEFAULT_SAMPLE_BYTES)
190
+ stream = peeked.stream
191
+ verdict = inspector.enforce(await inspector.inspect(peeked.head, { name: path }, { complete: peeked.ended }), extractOptions.verify)
192
+ }
193
+ if (depth < limits.maxDepth && isNested(path)) {
194
+ const spooled = await streamUtils.spool(stream, { maxBytes: limits.maxEntryBytes, signal })
195
+ try {
196
+ await extractInto(
197
+ createFileSource(spooled.path, { name: basename(path) }), treeUtils.prefixed(tree, nestedPrefix(path)),
198
+ { ...extractOptions, format: undefined }, depth + 1, result
199
+ )
200
+ } finally {
201
+ await spooled.dispose()
202
+ }
203
+ continue
204
+ }
205
+ const written = await tree.entry(path).write({
206
+ stream,
207
+ info: { origin: `${info.origin}#${path}`, name: nameUtils.sanitize(basename(path)), size: handle.info.size },
208
+ verdict,
209
+ }, { signal })
210
+ result.extracted.push({ entry: handle.info, path, result: written })
211
+ result.bytes += written.bytes
212
+ extractOptions.onEntry?.(handle.info, written)
213
+ } catch (error) {
214
+ await handle.drain().catch(() => undefined)
215
+ const fatal = error instanceof LimitError || error instanceof ArchiveError || error instanceof PathError || signal?.aborted === true
216
+ if (extractOptions.onEntryError === 'skip' && !fatal) {
217
+ result.skipped.push({ entry: handle.info, reason: (error as Error).message })
218
+ continue
219
+ }
220
+ throw error
221
+ }
222
+ }
223
+ } finally {
224
+ await acquired.dispose()
225
+ }
226
+ }
227
+
228
+ const extract = async (source: FileSource, tree: TreeSink, extractOptions: ArchiveExtractOptions = {}): Promise<ExtractResult> => {
229
+ const result: ExtractResult = { format: extractOptions.format ?? ArchiveFormat.Zip, extracted: [], skipped: [], bytes: 0 }
230
+ await extractInto(source, tree, extractOptions, 1, result)
231
+ log.debug('Extracted', { format: result.format, entries: result.extracted.length, skipped: result.skipped.length, bytes: result.bytes })
232
+
233
+ return result
234
+ }
235
+
236
+ const pack = (format: ArchiveFormat, entries: Iterable<PackEntry> | AsyncIterable<PackEntry>, packOptions: ArchivePackOptions = {}): FileSource => {
237
+ const level = packOptions.level != null ? { level: packOptions.level } : {}
238
+ const name = packOptions.name
239
+ switch (format) {
240
+ case ArchiveFormat.Zip:
241
+ return createStreamSource(zip.pack(entries, packOptions), { name, mime: 'application/zip' })
242
+ case ArchiveFormat.Tar:
243
+ return createStreamSource(tar.pack(entries, packOptions), { name, mime: 'application/x-tar' })
244
+ case ArchiveFormat.TarGz:
245
+ return createStreamSource(chain(tar.pack(entries, packOptions), createGzip(level)), { name, mime: 'application/gzip' })
246
+ case ArchiveFormat.Gzip: {
247
+ const output = new PassThrough()
248
+ const run = async (): Promise<void> => {
249
+ const all: PackEntry[] = []
250
+ for await (const entry of entries) {
251
+ all.push(entry)
252
+ }
253
+ if (all.length !== 1) {
254
+ throw new ArchiveError('gzip-entries')
255
+ }
256
+ const source = all[0].source
257
+ const input = source instanceof Uint8Array ? streamUtils.toReadable(source) : (await source.open()).stream
258
+ chain(input, createGzip(level), output)
259
+ }
260
+ run().catch(error => output.destroy(error as Error))
261
+ return createStreamSource(output, { name, mime: 'application/gzip' })
262
+ }
263
+ default:
264
+ throw new ArchiveError('format')
265
+ }
266
+ }
267
+
268
+ const gzip = (source: FileSource, packOptions: ArchivePackOptions = {}): FileSource => {
269
+ const info = async (infoOptions?: SignalOptions): Promise<FileInfo> => {
270
+ const base = await source.info(infoOptions)
271
+ return { origin: base.origin, name: packOptions.name ?? (base.name != null ? `${base.name}.gz` : undefined), mime: 'application/gzip' }
272
+ }
273
+ const open = async (openOptions: OpenOptions = {}): Promise<OpenedFile> => {
274
+ const opened = await source.open({ signal: openOptions.signal })
275
+ return { stream: chain(opened.stream, createGzip(packOptions.level != null ? { level: packOptions.level } : {})), info: await info() }
276
+ }
277
+ return { kind: 'gzip', info, open, ranges: async () => null }
278
+ }
279
+
280
+ const gunzip = (source: FileSource, listOptions: ArchiveListOptions = {}): FileSource => {
281
+ const limits = limitsOf(listOptions)
282
+ const info = async (infoOptions?: SignalOptions): Promise<FileInfo> => {
283
+ const base = await source.info(infoOptions)
284
+ const name = base.name?.toLowerCase().endsWith('.gz') === true ? base.name.slice(0, -3) : base.name
285
+ return { origin: base.origin, name }
286
+ }
287
+ const open = async (openOptions: OpenOptions = {}): Promise<OpenedFile> => {
288
+ const opened = await source.open({ signal: openOptions.signal })
289
+ const ratio = makeRatioGuard(limits)
290
+ return { stream: chain(opened.stream, ratio.input, createGunzip(), ratio.output), info: await info() }
291
+ }
292
+ return { kind: 'gzip', info, open, ranges: async () => null }
293
+ }
294
+
295
+ return { detect, list, extract, pack, gzip, gunzip }
296
+ }
297
+
298
+ export const archiveHelper = createArchiveHelper()
@@ -0,0 +1,72 @@
1
+ import type { FileScope } from '@owlmeans/storage-common'
2
+ import type { S3Bucket, S3ListedObject, S3SinkOptions } from '../s3/types.js'
3
+ import type { ConflictPolicy } from '../sinks/types.js'
4
+ import type { TransferHelper, TransferOptions, TransferResult } from '../transfer/types.js'
5
+ import type { FileSource, SignalOptions, SinkResult } from '../types.js'
6
+ import type { Workspace, WorkspaceScope } from '../workspace/types.js'
7
+
8
+ export interface BackedWorkspaceOptions {
9
+ workspace: Workspace
10
+ bucket: S3Bucket
11
+ /** Objects land at `<prefix>/<organization>/<project?>/<purpose>/<path>` under the bucket's base prefix. */
12
+ prefix?: string
13
+ /** Moves every file; default `transferHelper` (a service hands its configured one). */
14
+ transfer?: TransferHelper
15
+ /** How objects are written; Content-Type and disposition come from the local copy's verdict. */
16
+ sink?: S3SinkOptions
17
+ }
18
+
19
+ export interface BackedPutOptions extends TransferOptions {
20
+ /** What the local write does when the entry exists. Default `overwrite`, like the bucket. */
21
+ onConflict?: ConflictPolicy
22
+ }
23
+
24
+ export interface BackedPutResult {
25
+ local: SinkResult
26
+ remote: SinkResult
27
+ /** The verified move into the local entry: verdict, counted bytes, digest. */
28
+ transfer: TransferResult
29
+ }
30
+
31
+ export interface BackedRestoreResult {
32
+ /** Paths downloaded because they were missing locally or had another size. */
33
+ restored: string[]
34
+ /** Paths already present locally with the listed size. */
35
+ kept: string[]
36
+ }
37
+
38
+ /**
39
+ * One scope kept in a local workspace and mirrored to a bucket. The bucket is the authority:
40
+ * a put that cannot reach it leaves nothing local, a restore brings back what the listing names.
41
+ */
42
+ export interface BackedScope {
43
+ readonly scope: FileScope
44
+ readonly local: WorkspaceScope
45
+ /** The object key of a path: `<basePrefix>/<prefix?>/<scope path>/<path>`. */
46
+ key: (path: string) => string
47
+ /** The bucket prefix of a path — what `bucket.source`, `sink`, `head` and `urlOf` take. */
48
+ prefixOf: (path: string) => string
49
+ /**
50
+ * Copies `source` into the local entry through the transfer helper (verified by `options.verify`),
51
+ * then uploads the LOCAL file. A failed upload removes the local copy and rethrows.
52
+ */
53
+ put: (path: string, source: FileSource, options?: BackedPutOptions) => Promise<BackedPutResult>
54
+ /** Downloads every listed object missing locally or of another size (byte-identical, unverified). */
55
+ restore: (options?: SignalOptions) => Promise<BackedRestoreResult>
56
+ /** The remote listing; `path` is relative to the scope. */
57
+ list: (options?: SignalOptions) => Promise<S3ListedObject[]>
58
+ /** Removes a file (or a folder) locally and remotely. */
59
+ remove: (path: string, options?: SignalOptions) => Promise<void>
60
+ /** Drops the local copy only; `restore` brings it back. */
61
+ evict: () => Promise<void>
62
+ /** Drops the local copy and every object under the scope's prefix. */
63
+ drop: (options?: SignalOptions) => Promise<void>
64
+ }
65
+
66
+ /** A workspace whose scopes are mirrored to one bucket. */
67
+ export interface BackedWorkspace {
68
+ readonly workspace: Workspace
69
+ readonly bucket: S3Bucket
70
+ /** @throws {FileScopeError} for an invalid scope. */
71
+ scope: (scope: FileScope) => BackedScope
72
+ }
@@ -0,0 +1,85 @@
1
+ import { logger } from '@owlmeans/log'
2
+ import { fileScopeHelper } from '@owlmeans/storage-common'
3
+ import type { FileScope } from '@owlmeans/storage-common'
4
+ import type {
5
+ BackedPutOptions, BackedPutResult, BackedRestoreResult, BackedScope, BackedWorkspace, BackedWorkspaceOptions,
6
+ } from './backed-workspace/types.js'
7
+ import type { S3ListedObject } from './s3/types.js'
8
+ import { transferHelper } from './transfer.js'
9
+ import type { FileSource, SignalOptions } from './types.js'
10
+ import { pathUtils } from './utils/paths.js'
11
+
12
+ const log = logger('file-streams:workspace')
13
+
14
+ /** A workspace mirrored to a bucket under the same nesting, so a restarted pod restores its scopes. */
15
+ export const createBackedWorkspace = (options: BackedWorkspaceOptions): BackedWorkspace => {
16
+ const { workspace, bucket } = options
17
+ const transfer = options.transfer ?? transferHelper
18
+ const prefix = options.prefix != null && options.prefix.replace(/^\/+|\/+$/g, '') !== '' ? pathUtils.entry(options.prefix) : ''
19
+
20
+ const scope = (value: FileScope): BackedScope => {
21
+ const local = workspace.scope(value)
22
+ const base = prefix === '' ? fileScopeHelper.pathOf(value) : `${prefix}/${fileScopeHelper.pathOf(value)}`
23
+
24
+ const prefixOf = (path: string): string => `${base}/${pathUtils.entry(path)}`
25
+
26
+ const key = (path: string): string => bucket.keyOf(prefixOf(path))
27
+
28
+ const put = async (path: string, source: FileSource, putOptions: BackedPutOptions = {}): Promise<BackedPutResult> => {
29
+ const { onConflict = 'overwrite', ...transferOptions } = putOptions
30
+ const remotePrefix = prefixOf(path)
31
+ const copied = await transfer.copy(source, local.entry(path, { onConflict }), transferOptions)
32
+ try {
33
+ const opened = await local.source(path, { name: copied.info.name, mime: copied.sink.mime }).open({ signal: putOptions.signal })
34
+ const remote = await bucket.sink(remotePrefix, options.sink).write(
35
+ { stream: opened.stream, info: { ...opened.info, mime: copied.sink.mime ?? opened.info.mime }, verdict: copied.verdict },
36
+ { signal: putOptions.signal }
37
+ )
38
+ return { local: copied.sink, remote, transfer: copied }
39
+ } catch (error) {
40
+ await local.remove(path).catch(removeError => log.warn('Local copy left after a failed upload', removeError as Error))
41
+ throw error
42
+ }
43
+ }
44
+
45
+ const list = async (listOptions: SignalOptions = {}): Promise<S3ListedObject[]> =>
46
+ (await bucket.list(base, listOptions)).filter(item => !item.path.endsWith('/'))
47
+
48
+ const restore = async (restoreOptions: SignalOptions = {}): Promise<BackedRestoreResult> => {
49
+ const remote = await list(restoreOptions)
50
+ const present = new Map((await local.list()).map(file => [file.path, file.size]))
51
+ const result: BackedRestoreResult = { restored: [], kept: [] }
52
+ for (const item of remote) {
53
+ if (present.get(item.path) === item.size) {
54
+ result.kept.push(item.path)
55
+ continue
56
+ }
57
+ await transfer.copy(bucket.source(prefixOf(item.path)), local.entry(item.path, { onConflict: 'overwrite' }), {
58
+ verify: false, signal: restoreOptions.signal,
59
+ })
60
+ result.restored.push(item.path)
61
+ }
62
+ log.debug('Workspace scope restored', { restored: result.restored.length, kept: result.kept.length })
63
+
64
+ return result
65
+ }
66
+
67
+ const remove = async (path: string, removeOptions: SignalOptions = {}): Promise<void> => {
68
+ await local.remove(path)
69
+ await bucket.remove(prefixOf(path), removeOptions)
70
+ await bucket.removePrefix(prefixOf(path), removeOptions)
71
+ }
72
+
73
+ const evict = async (): Promise<void> => { await local.drop() }
74
+
75
+ const drop = async (dropOptions: SignalOptions = {}): Promise<void> => {
76
+ await local.drop()
77
+ const removed = await bucket.removePrefix(base, dropOptions)
78
+ log.debug('Backed workspace scope dropped', { objects: removed })
79
+ }
80
+
81
+ return { scope: local.scope, local, key, prefixOf, put, restore, list, remove, evict, drop }
82
+ }
83
+
84
+ return { workspace, bucket, scope }
85
+ }
@@ -0,0 +1,2 @@
1
+ /** The `User-Agent` requests carry unless the caller names one. */
2
+ export const PACKAGE_USER_AGENT = 'owlmeans-file-streams'
package/src/consts.ts ADDED
@@ -0,0 +1,2 @@
1
+ /** The alias the file-streams service registers under. */
2
+ export const FILE_STREAMS_SERVICE = 'file-streams'
package/src/errors.ts ADDED
@@ -0,0 +1,128 @@
1
+ import { ResilientError } from '@owlmeans/error'
2
+ import { StorageApiError } from '@owlmeans/storage-common'
3
+
4
+ export class FileStreamsError extends ResilientError {
5
+ public static override typeName: string = 'FileStreamsError'
6
+
7
+ constructor(message: string = 'error') {
8
+ super(FileStreamsError.typeName, `file-streams:${message}`)
9
+ }
10
+ }
11
+
12
+ /** A URL or address the network policy refuses. */
13
+ export class NetworkPolicyError extends FileStreamsError {
14
+ public static override typeName: string = `${FileStreamsError.typeName}NetworkPolicy`
15
+
16
+ constructor(message: string = 'error') {
17
+ super(`policy:${message}`)
18
+ this.type = NetworkPolicyError.typeName
19
+ }
20
+ }
21
+
22
+ /** A request that failed: `status:<code>`, `redirects`, `connect`, `headers-timeout`, `truncated`… */
23
+ export class HttpError extends FileStreamsError {
24
+ public static override typeName: string = `${FileStreamsError.typeName}Http`
25
+
26
+ constructor(message: string = 'error') {
27
+ super(`http:${message}`)
28
+ this.type = HttpError.typeName
29
+ }
30
+
31
+ /** The HTTP status of a `status:<code>` failure. */
32
+ public get status(): number | undefined {
33
+ const match = /http:status:(\d+)/.exec(this.message)
34
+ return match != null ? Number(match[1]) : undefined
35
+ }
36
+ }
37
+
38
+ /** A proxy that could not be used: `no-plugin`, `connect`, `auth-failed`, `refused:<code>`… */
39
+ export class ProxyError extends FileStreamsError {
40
+ public static override typeName: string = `${FileStreamsError.typeName}Proxy`
41
+
42
+ constructor(message: string = 'error') {
43
+ super(`proxy:${message}`)
44
+ this.type = ProxyError.typeName
45
+ }
46
+ }
47
+
48
+ /** A size, time or count ceiling crossed: `max-bytes`, `timeout`, `idle-timeout`, `ratio`… */
49
+ export class LimitError extends FileStreamsError {
50
+ public static override typeName: string = `${FileStreamsError.typeName}Limit`
51
+
52
+ constructor(message: string = 'error') {
53
+ super(`limit:${message}`)
54
+ this.type = LimitError.typeName
55
+ }
56
+ }
57
+
58
+ /** A source that cannot serve: `consumed`, `changed`, `not-found`, `not-a-file`… */
59
+ export class SourceError extends FileStreamsError {
60
+ public static override typeName: string = `${FileStreamsError.typeName}Source`
61
+
62
+ constructor(message: string = 'error') {
63
+ super(`source:${message}`)
64
+ this.type = SourceError.typeName
65
+ }
66
+ }
67
+
68
+ /** A path refused: `absolute`, `traversal`, `invalid-char`, `too-long`, `symlink`, `exists`… */
69
+ export class PathError extends FileStreamsError {
70
+ public static override typeName: string = `${FileStreamsError.typeName}Path`
71
+
72
+ constructor(message: string = 'error') {
73
+ super(`path:${message}`)
74
+ this.type = PathError.typeName
75
+ }
76
+ }
77
+
78
+ /** An archive that cannot be read safely: `format`, `encrypted`, `method:<n>`, `overlap`… */
79
+ export class ArchiveError extends FileStreamsError {
80
+ public static override typeName: string = `${FileStreamsError.typeName}Archive`
81
+
82
+ constructor(message: string = 'error') {
83
+ super(`archive:${message}`)
84
+ this.type = ArchiveError.typeName
85
+ }
86
+ }
87
+
88
+ /** A URL resolver that could not reach the bytes: `<resolver>:<reason>`. */
89
+ export class ResolverError extends FileStreamsError {
90
+ public static override typeName: string = `${FileStreamsError.typeName}Resolver`
91
+
92
+ constructor(message: string = 'error') {
93
+ super(`resolver:${message}`)
94
+ this.type = ResolverError.typeName
95
+ }
96
+ }
97
+
98
+ /** A Viable workload write refused or failed: `too-large`, `write-failed`. */
99
+ export class WorkloadError extends FileStreamsError {
100
+ public static override typeName: string = `${FileStreamsError.typeName}Workload`
101
+
102
+ constructor(message: string = 'error') {
103
+ super(`workload:${message}`)
104
+ this.type = WorkloadError.typeName
105
+ }
106
+ }
107
+
108
+ /** An S3 operation that failed: `s3:<op>`. A storage `StorageApiError`. */
109
+ export class S3TransferError extends StorageApiError {
110
+ public static override typeName: string = `${StorageApiError.typeName}S3`
111
+
112
+ constructor(message: string = 'error') {
113
+ super(`s3:${message}`)
114
+ this.type = S3TransferError.typeName
115
+ }
116
+ }
117
+
118
+ ResilientError.registerErrorClass(FileStreamsError)
119
+ ResilientError.registerErrorClass(NetworkPolicyError)
120
+ ResilientError.registerErrorClass(HttpError)
121
+ ResilientError.registerErrorClass(ProxyError)
122
+ ResilientError.registerErrorClass(LimitError)
123
+ ResilientError.registerErrorClass(SourceError)
124
+ ResilientError.registerErrorClass(PathError)
125
+ ResilientError.registerErrorClass(ArchiveError)
126
+ ResilientError.registerErrorClass(ResolverError)
127
+ ResilientError.registerErrorClass(WorkloadError)
128
+ ResilientError.registerErrorClass(S3TransferError)