@backblaze-labs/b2-sdk 0.1.0 → 0.2.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 (701) hide show
  1. package/CHANGELOG.md +110 -5
  2. package/README.md +144 -33
  3. package/dist/_virtual/_b2-sdk-version-json.cjs +4 -0
  4. package/dist/_virtual/_b2-sdk-version-json.js +4 -0
  5. package/dist/auth/account-info.d.cts +32 -0
  6. package/dist/auth/account-info.d.cts.map +1 -1
  7. package/dist/auth/account-info.d.ts +32 -0
  8. package/dist/auth/account-info.d.ts.map +1 -1
  9. package/dist/auth/file.cjs +408 -207
  10. package/dist/auth/file.cjs.map +1 -1
  11. package/dist/auth/file.d.cts +77 -3
  12. package/dist/auth/file.d.cts.map +1 -1
  13. package/dist/auth/file.d.ts +77 -3
  14. package/dist/auth/file.d.ts.map +1 -1
  15. package/dist/auth/file.js +407 -207
  16. package/dist/auth/file.js.map +1 -1
  17. package/dist/auth/in-memory.cjs +212 -183
  18. package/dist/auth/in-memory.cjs.map +1 -1
  19. package/dist/auth/in-memory.d.cts +8 -0
  20. package/dist/auth/in-memory.d.cts.map +1 -1
  21. package/dist/auth/in-memory.d.ts +8 -0
  22. package/dist/auth/in-memory.d.ts.map +1 -1
  23. package/dist/auth/in-memory.js +211 -182
  24. package/dist/auth/in-memory.js.map +1 -1
  25. package/dist/auth/index.cjs +7 -9
  26. package/dist/auth/index.d.cts +3 -2
  27. package/dist/auth/index.d.cts.map +1 -1
  28. package/dist/auth/index.d.ts +3 -2
  29. package/dist/auth/index.d.ts.map +1 -1
  30. package/dist/auth/index.js +2 -8
  31. package/dist/auth/realms.cjs +80 -7
  32. package/dist/auth/realms.cjs.map +1 -1
  33. package/dist/auth/realms.d.cts +27 -4
  34. package/dist/auth/realms.d.cts.map +1 -1
  35. package/dist/auth/realms.d.ts +27 -4
  36. package/dist/auth/realms.d.ts.map +1 -1
  37. package/dist/auth/realms.js +80 -9
  38. package/dist/auth/realms.js.map +1 -1
  39. package/dist/auth/upload-url-pool.cjs +55 -51
  40. package/dist/auth/upload-url-pool.cjs.map +1 -1
  41. package/dist/auth/upload-url-pool.js +55 -51
  42. package/dist/auth/upload-url-pool.js.map +1 -1
  43. package/dist/bucket.cjs +785 -787
  44. package/dist/bucket.cjs.map +1 -1
  45. package/dist/bucket.d.cts +35 -47
  46. package/dist/bucket.d.cts.map +1 -1
  47. package/dist/bucket.d.ts +35 -47
  48. package/dist/bucket.d.ts.map +1 -1
  49. package/dist/bucket.js +780 -782
  50. package/dist/bucket.js.map +1 -1
  51. package/dist/client.cjs +246 -228
  52. package/dist/client.cjs.map +1 -1
  53. package/dist/client.d.cts +25 -17
  54. package/dist/client.d.cts.map +1 -1
  55. package/dist/client.d.ts +25 -17
  56. package/dist/client.d.ts.map +1 -1
  57. package/dist/client.js +243 -225
  58. package/dist/client.js.map +1 -1
  59. package/dist/copy/large.cjs +114 -71
  60. package/dist/copy/large.cjs.map +1 -1
  61. package/dist/copy/large.d.cts +6 -0
  62. package/dist/copy/large.d.cts.map +1 -1
  63. package/dist/copy/large.d.ts +6 -0
  64. package/dist/copy/large.d.ts.map +1 -1
  65. package/dist/copy/large.js +112 -69
  66. package/dist/copy/large.js.map +1 -1
  67. package/dist/download/checksum.cjs +89 -0
  68. package/dist/download/checksum.cjs.map +1 -0
  69. package/dist/download/checksum.d.cts +40 -0
  70. package/dist/download/checksum.d.cts.map +1 -0
  71. package/dist/download/checksum.d.ts +40 -0
  72. package/dist/download/checksum.d.ts.map +1 -0
  73. package/dist/download/checksum.js +87 -0
  74. package/dist/download/checksum.js.map +1 -0
  75. package/dist/download/parallel.cjs +214 -118
  76. package/dist/download/parallel.cjs.map +1 -1
  77. package/dist/download/parallel.d.cts +5 -1
  78. package/dist/download/parallel.d.cts.map +1 -1
  79. package/dist/download/parallel.d.ts +5 -1
  80. package/dist/download/parallel.d.ts.map +1 -1
  81. package/dist/download/parallel.js +212 -116
  82. package/dist/download/parallel.js.map +1 -1
  83. package/dist/download/single.cjs +188 -97
  84. package/dist/download/single.cjs.map +1 -1
  85. package/dist/download/single.d.cts +6 -1
  86. package/dist/download/single.d.cts.map +1 -1
  87. package/dist/download/single.d.ts +6 -1
  88. package/dist/download/single.d.ts.map +1 -1
  89. package/dist/download/single.js +186 -98
  90. package/dist/download/single.js.map +1 -1
  91. package/dist/errors/index.cjs +699 -243
  92. package/dist/errors/index.cjs.map +1 -1
  93. package/dist/errors/index.d.cts +285 -82
  94. package/dist/errors/index.d.cts.map +1 -1
  95. package/dist/errors/index.d.ts +285 -82
  96. package/dist/errors/index.d.ts.map +1 -1
  97. package/dist/errors/index.js +678 -261
  98. package/dist/errors/index.js.map +1 -1
  99. package/dist/http/retry.cjs +45 -28
  100. package/dist/http/retry.cjs.map +1 -1
  101. package/dist/http/retry.d.cts +15 -2
  102. package/dist/http/retry.d.cts.map +1 -1
  103. package/dist/http/retry.d.ts +15 -2
  104. package/dist/http/retry.d.ts.map +1 -1
  105. package/dist/http/retry.js +46 -31
  106. package/dist/http/retry.js.map +1 -1
  107. package/dist/http/transport.cjs +438 -140
  108. package/dist/http/transport.cjs.map +1 -1
  109. package/dist/http/transport.d.cts +21 -2
  110. package/dist/http/transport.d.cts.map +1 -1
  111. package/dist/http/transport.d.ts +21 -2
  112. package/dist/http/transport.d.ts.map +1 -1
  113. package/dist/http/transport.js +437 -140
  114. package/dist/http/transport.js.map +1 -1
  115. package/dist/http/url-guard.cjs +154 -89
  116. package/dist/http/url-guard.cjs.map +1 -1
  117. package/dist/http/url-guard.d.cts +25 -3
  118. package/dist/http/url-guard.d.cts.map +1 -1
  119. package/dist/http/url-guard.d.ts +25 -3
  120. package/dist/http/url-guard.d.ts.map +1 -1
  121. package/dist/http/url-guard.js +152 -90
  122. package/dist/http/url-guard.js.map +1 -1
  123. package/dist/http/user-agent.cjs +84 -44
  124. package/dist/http/user-agent.cjs.map +1 -1
  125. package/dist/http/user-agent.js +84 -46
  126. package/dist/http/user-agent.js.map +1 -1
  127. package/dist/index.cjs +101 -77
  128. package/dist/index.d.cts +27 -21
  129. package/dist/index.d.cts.map +1 -1
  130. package/dist/index.d.ts +27 -21
  131. package/dist/index.d.ts.map +1 -1
  132. package/dist/index.js +15 -71
  133. package/dist/internal/b2-naming.cjs +66 -0
  134. package/dist/internal/b2-naming.cjs.map +1 -0
  135. package/dist/internal/b2-naming.d.cts +43 -0
  136. package/dist/internal/b2-naming.d.cts.map +1 -0
  137. package/dist/internal/b2-naming.d.ts +43 -0
  138. package/dist/internal/b2-naming.d.ts.map +1 -0
  139. package/dist/internal/b2-naming.js +60 -0
  140. package/dist/internal/b2-naming.js.map +1 -0
  141. package/dist/internal/upload-retry-options.cjs +21 -0
  142. package/dist/internal/upload-retry-options.cjs.map +1 -0
  143. package/dist/internal/upload-retry-options.d.cts +12 -0
  144. package/dist/internal/upload-retry-options.d.cts.map +1 -0
  145. package/dist/internal/upload-retry-options.d.ts +12 -0
  146. package/dist/internal/upload-retry-options.d.ts.map +1 -0
  147. package/dist/internal/upload-retry-options.js +21 -0
  148. package/dist/internal/upload-retry-options.js.map +1 -0
  149. package/dist/internal/url-redaction.cjs +31 -0
  150. package/dist/internal/url-redaction.cjs.map +1 -0
  151. package/dist/internal/url-redaction.d.cts +17 -0
  152. package/dist/internal/url-redaction.d.cts.map +1 -0
  153. package/dist/internal/url-redaction.d.ts +17 -0
  154. package/dist/internal/url-redaction.d.ts.map +1 -0
  155. package/dist/internal/url-redaction.js +31 -0
  156. package/dist/internal/url-redaction.js.map +1 -0
  157. package/dist/notifications/index.cjs +4 -6
  158. package/dist/notifications/index.d.cts +1 -1
  159. package/dist/notifications/index.d.cts.map +1 -1
  160. package/dist/notifications/index.d.ts +1 -1
  161. package/dist/notifications/index.d.ts.map +1 -1
  162. package/dist/notifications/index.js +1 -6
  163. package/dist/notifications/webhook.cjs +195 -85
  164. package/dist/notifications/webhook.cjs.map +1 -1
  165. package/dist/notifications/webhook.d.cts.map +1 -1
  166. package/dist/notifications/webhook.d.ts.map +1 -1
  167. package/dist/notifications/webhook.js +195 -87
  168. package/dist/notifications/webhook.js.map +1 -1
  169. package/dist/object.cjs +253 -210
  170. package/dist/object.cjs.map +1 -1
  171. package/dist/object.d.cts +9 -55
  172. package/dist/object.d.cts.map +1 -1
  173. package/dist/object.d.ts +9 -55
  174. package/dist/object.d.ts.map +1 -1
  175. package/dist/object.js +249 -206
  176. package/dist/object.js.map +1 -1
  177. package/dist/raw/encoding.cjs +74 -35
  178. package/dist/raw/encoding.cjs.map +1 -1
  179. package/dist/raw/encoding.js +74 -38
  180. package/dist/raw/encoding.js.map +1 -1
  181. package/dist/raw/index.cjs +678 -587
  182. package/dist/raw/index.cjs.map +1 -1
  183. package/dist/raw/index.d.cts +121 -18
  184. package/dist/raw/index.d.cts.map +1 -1
  185. package/dist/raw/index.d.ts +121 -18
  186. package/dist/raw/index.d.ts.map +1 -1
  187. package/dist/raw/index.js +674 -589
  188. package/dist/raw/index.js.map +1 -1
  189. package/dist/s3/index.cjs +355 -18
  190. package/dist/s3/index.cjs.map +1 -1
  191. package/dist/s3/index.d.cts +233 -5
  192. package/dist/s3/index.d.cts.map +1 -1
  193. package/dist/s3/index.d.ts +233 -5
  194. package/dist/s3/index.d.ts.map +1 -1
  195. package/dist/s3/index.js +351 -22
  196. package/dist/s3/index.js.map +1 -1
  197. package/dist/s3/sigv4.cjs +149 -0
  198. package/dist/s3/sigv4.cjs.map +1 -0
  199. package/dist/s3/sigv4.d.cts +43 -0
  200. package/dist/s3/sigv4.d.cts.map +1 -0
  201. package/dist/s3/sigv4.d.ts +43 -0
  202. package/dist/s3/sigv4.d.ts.map +1 -0
  203. package/dist/s3/sigv4.js +148 -0
  204. package/dist/s3/sigv4.js.map +1 -0
  205. package/dist/s3/validation.cjs +69 -0
  206. package/dist/s3/validation.cjs.map +1 -0
  207. package/dist/s3/validation.d.cts +43 -0
  208. package/dist/s3/validation.d.cts.map +1 -0
  209. package/dist/s3/validation.d.ts +43 -0
  210. package/dist/s3/validation.d.ts.map +1 -0
  211. package/dist/s3/validation.js +66 -0
  212. package/dist/s3/validation.js.map +1 -0
  213. package/dist/simulator/capabilities.cjs +63 -48
  214. package/dist/simulator/capabilities.cjs.map +1 -1
  215. package/dist/simulator/capabilities.js +63 -49
  216. package/dist/simulator/capabilities.js.map +1 -1
  217. package/dist/simulator/index.cjs +2124 -1548
  218. package/dist/simulator/index.cjs.map +1 -1
  219. package/dist/simulator/index.d.cts +79 -11
  220. package/dist/simulator/index.d.cts.map +1 -1
  221. package/dist/simulator/index.d.ts +79 -11
  222. package/dist/simulator/index.d.ts.map +1 -1
  223. package/dist/simulator/index.js +2112 -1546
  224. package/dist/simulator/index.js.map +1 -1
  225. package/dist/simulator/validation.cjs +191 -153
  226. package/dist/simulator/validation.cjs.map +1 -1
  227. package/dist/simulator/validation.d.cts +3 -21
  228. package/dist/simulator/validation.d.cts.map +1 -1
  229. package/dist/simulator/validation.d.ts +3 -21
  230. package/dist/simulator/validation.d.ts.map +1 -1
  231. package/dist/simulator/validation.js +188 -162
  232. package/dist/simulator/validation.js.map +1 -1
  233. package/dist/streams/collect.cjs +74 -24
  234. package/dist/streams/collect.cjs.map +1 -1
  235. package/dist/streams/collect.d.cts +14 -1
  236. package/dist/streams/collect.d.cts.map +1 -1
  237. package/dist/streams/collect.d.ts +14 -1
  238. package/dist/streams/collect.d.ts.map +1 -1
  239. package/dist/streams/collect.js +74 -25
  240. package/dist/streams/collect.js.map +1 -1
  241. package/dist/streams/file-source.cjs +287 -0
  242. package/dist/streams/file-source.cjs.map +1 -0
  243. package/dist/streams/file-source.d.cts +96 -0
  244. package/dist/streams/file-source.d.cts.map +1 -0
  245. package/dist/streams/file-source.d.ts +96 -0
  246. package/dist/streams/file-source.d.ts.map +1 -0
  247. package/dist/streams/file-source.js +286 -0
  248. package/dist/streams/file-source.js.map +1 -0
  249. package/dist/streams/hash.cjs +207 -115
  250. package/dist/streams/hash.cjs.map +1 -1
  251. package/dist/streams/hash.d.cts +5 -4
  252. package/dist/streams/hash.d.cts.map +1 -1
  253. package/dist/streams/hash.d.ts +5 -4
  254. package/dist/streams/hash.d.ts.map +1 -1
  255. package/dist/streams/hash.js +208 -95
  256. package/dist/streams/hash.js.map +1 -1
  257. package/dist/streams/index.cjs +12 -12
  258. package/dist/streams/index.d.cts +3 -3
  259. package/dist/streams/index.d.cts.map +1 -1
  260. package/dist/streams/index.d.ts +3 -3
  261. package/dist/streams/index.d.ts.map +1 -1
  262. package/dist/streams/index.js +2 -10
  263. package/dist/streams/progress.cjs +60 -46
  264. package/dist/streams/progress.cjs.map +1 -1
  265. package/dist/streams/progress.js +60 -46
  266. package/dist/streams/progress.js.map +1 -1
  267. package/dist/streams/source.cjs +316 -146
  268. package/dist/streams/source.cjs.map +1 -1
  269. package/dist/streams/source.d.cts +56 -18
  270. package/dist/streams/source.d.cts.map +1 -1
  271. package/dist/streams/source.d.ts +56 -18
  272. package/dist/streams/source.d.ts.map +1 -1
  273. package/dist/streams/source.js +312 -149
  274. package/dist/streams/source.js.map +1 -1
  275. package/dist/sync/actions/index.cjs +236 -184
  276. package/dist/sync/actions/index.cjs.map +1 -1
  277. package/dist/sync/actions/index.d.cts +29 -21
  278. package/dist/sync/actions/index.d.cts.map +1 -1
  279. package/dist/sync/actions/index.d.ts +29 -21
  280. package/dist/sync/actions/index.d.ts.map +1 -1
  281. package/dist/sync/actions/index.js +236 -190
  282. package/dist/sync/actions/index.js.map +1 -1
  283. package/dist/sync/b2-sha1-reader.cjs +148 -0
  284. package/dist/sync/b2-sha1-reader.cjs.map +1 -0
  285. package/dist/sync/b2-sha1-reader.d.cts +58 -0
  286. package/dist/sync/b2-sha1-reader.d.cts.map +1 -0
  287. package/dist/sync/b2-sha1-reader.d.ts +58 -0
  288. package/dist/sync/b2-sha1-reader.d.ts.map +1 -0
  289. package/dist/sync/b2-sha1-reader.js +145 -0
  290. package/dist/sync/b2-sha1-reader.js.map +1 -0
  291. package/dist/sync/download-staging.cjs +265 -0
  292. package/dist/sync/download-staging.cjs.map +1 -0
  293. package/dist/sync/download-staging.d.cts +54 -0
  294. package/dist/sync/download-staging.d.cts.map +1 -0
  295. package/dist/sync/download-staging.d.ts +54 -0
  296. package/dist/sync/download-staging.d.ts.map +1 -0
  297. package/dist/sync/download-staging.js +259 -0
  298. package/dist/sync/download-staging.js.map +1 -0
  299. package/dist/sync/filesystem-errors.cjs +32 -0
  300. package/dist/sync/filesystem-errors.cjs.map +1 -0
  301. package/dist/sync/filesystem-errors.d.cts +8 -0
  302. package/dist/sync/filesystem-errors.d.cts.map +1 -0
  303. package/dist/sync/filesystem-errors.d.ts +8 -0
  304. package/dist/sync/filesystem-errors.d.ts.map +1 -0
  305. package/dist/sync/filesystem-errors.js +32 -0
  306. package/dist/sync/filesystem-errors.js.map +1 -0
  307. package/dist/sync/filters.cjs +217 -0
  308. package/dist/sync/filters.cjs.map +1 -0
  309. package/dist/sync/filters.d.cts +51 -0
  310. package/dist/sync/filters.d.cts.map +1 -0
  311. package/dist/sync/filters.d.ts +51 -0
  312. package/dist/sync/filters.d.ts.map +1 -0
  313. package/dist/sync/filters.js +213 -0
  314. package/dist/sync/filters.js.map +1 -0
  315. package/dist/sync/index.cjs +39 -22
  316. package/dist/sync/index.d.cts +14 -9
  317. package/dist/sync/index.d.cts.map +1 -1
  318. package/dist/sync/index.d.ts +14 -9
  319. package/dist/sync/index.d.ts.map +1 -1
  320. package/dist/sync/index.js +9 -20
  321. package/dist/sync/local-file-identity.cjs +61 -0
  322. package/dist/sync/local-file-identity.cjs.map +1 -0
  323. package/dist/sync/local-file-identity.d.cts +37 -0
  324. package/dist/sync/local-file-identity.d.cts.map +1 -0
  325. package/dist/sync/local-file-identity.d.ts +37 -0
  326. package/dist/sync/local-file-identity.d.ts.map +1 -0
  327. package/dist/sync/local-file-identity.js +60 -0
  328. package/dist/sync/local-file-identity.js.map +1 -0
  329. package/dist/sync/local-file-io.cjs +364 -0
  330. package/dist/sync/local-file-io.cjs.map +1 -0
  331. package/dist/sync/local-file-io.d.cts +75 -0
  332. package/dist/sync/local-file-io.d.cts.map +1 -0
  333. package/dist/sync/local-file-io.d.ts +75 -0
  334. package/dist/sync/local-file-io.d.ts.map +1 -0
  335. package/dist/sync/local-file-io.js +360 -0
  336. package/dist/sync/local-file-io.js.map +1 -0
  337. package/dist/sync/local-filesystem-root.cjs +27 -0
  338. package/dist/sync/local-filesystem-root.cjs.map +1 -0
  339. package/dist/sync/local-filesystem-root.d.cts +18 -0
  340. package/dist/sync/local-filesystem-root.d.cts.map +1 -0
  341. package/dist/sync/local-filesystem-root.d.ts +18 -0
  342. package/dist/sync/local-filesystem-root.d.ts.map +1 -0
  343. package/dist/sync/local-filesystem-root.js +26 -0
  344. package/dist/sync/local-filesystem-root.js.map +1 -0
  345. package/dist/sync/local-sha1.cjs +119 -0
  346. package/dist/sync/local-sha1.cjs.map +1 -0
  347. package/dist/sync/local-sha1.d.cts +39 -0
  348. package/dist/sync/local-sha1.d.cts.map +1 -0
  349. package/dist/sync/local-sha1.d.ts +39 -0
  350. package/dist/sync/local-sha1.d.ts.map +1 -0
  351. package/dist/sync/local-sha1.js +117 -0
  352. package/dist/sync/local-sha1.js.map +1 -0
  353. package/dist/sync/pairing.cjs +118 -29
  354. package/dist/sync/pairing.cjs.map +1 -1
  355. package/dist/sync/pairing.d.cts +7 -2
  356. package/dist/sync/pairing.d.cts.map +1 -1
  357. package/dist/sync/pairing.d.ts +7 -2
  358. package/dist/sync/pairing.d.ts.map +1 -1
  359. package/dist/sync/pairing.js +120 -31
  360. package/dist/sync/pairing.js.map +1 -1
  361. package/dist/sync/path-order.cjs +30 -0
  362. package/dist/sync/path-order.cjs.map +1 -0
  363. package/dist/sync/path-order.d.cts +28 -0
  364. package/dist/sync/path-order.d.cts.map +1 -0
  365. package/dist/sync/path-order.d.ts +28 -0
  366. package/dist/sync/path-order.d.ts.map +1 -0
  367. package/dist/sync/path-order.js +29 -0
  368. package/dist/sync/path-order.js.map +1 -0
  369. package/dist/sync/path-safety.cjs +111 -0
  370. package/dist/sync/path-safety.cjs.map +1 -0
  371. package/dist/sync/path-safety.d.cts +78 -0
  372. package/dist/sync/path-safety.d.cts.map +1 -0
  373. package/dist/sync/path-safety.d.ts +78 -0
  374. package/dist/sync/path-safety.d.ts.map +1 -0
  375. package/dist/sync/path-safety.js +105 -0
  376. package/dist/sync/path-safety.js.map +1 -0
  377. package/dist/sync/paths.d.cts +19 -0
  378. package/dist/sync/paths.d.cts.map +1 -0
  379. package/dist/sync/paths.d.ts +19 -0
  380. package/dist/sync/paths.d.ts.map +1 -0
  381. package/dist/sync/policies/compare.cjs +389 -11
  382. package/dist/sync/policies/compare.cjs.map +1 -1
  383. package/dist/sync/policies/compare.d.cts +100 -2
  384. package/dist/sync/policies/compare.d.cts.map +1 -1
  385. package/dist/sync/policies/compare.d.ts +100 -2
  386. package/dist/sync/policies/compare.d.ts.map +1 -1
  387. package/dist/sync/policies/compare.js +387 -13
  388. package/dist/sync/policies/compare.js.map +1 -1
  389. package/dist/sync/policies/index.cjs +76 -65
  390. package/dist/sync/policies/index.cjs.map +1 -1
  391. package/dist/sync/policies/index.d.cts +35 -6
  392. package/dist/sync/policies/index.d.cts.map +1 -1
  393. package/dist/sync/policies/index.d.ts +35 -6
  394. package/dist/sync/policies/index.d.ts.map +1 -1
  395. package/dist/sync/policies/index.js +76 -65
  396. package/dist/sync/policies/index.js.map +1 -1
  397. package/dist/sync/prefix.cjs +96 -0
  398. package/dist/sync/prefix.cjs.map +1 -0
  399. package/dist/sync/prefix.d.cts +55 -0
  400. package/dist/sync/prefix.d.cts.map +1 -0
  401. package/dist/sync/prefix.d.ts +55 -0
  402. package/dist/sync/prefix.d.ts.map +1 -0
  403. package/dist/sync/prefix.js +92 -0
  404. package/dist/sync/prefix.js.map +1 -0
  405. package/dist/sync/regexp-safety.cjs +192 -0
  406. package/dist/sync/regexp-safety.cjs.map +1 -0
  407. package/dist/sync/regexp-safety.d.cts +29 -0
  408. package/dist/sync/regexp-safety.d.cts.map +1 -0
  409. package/dist/sync/regexp-safety.d.ts +29 -0
  410. package/dist/sync/regexp-safety.d.ts.map +1 -0
  411. package/dist/sync/regexp-safety.js +190 -0
  412. package/dist/sync/regexp-safety.js.map +1 -0
  413. package/dist/sync/scan-events.cjs +33 -0
  414. package/dist/sync/scan-events.cjs.map +1 -0
  415. package/dist/sync/scan-events.d.cts +17 -0
  416. package/dist/sync/scan-events.d.cts.map +1 -0
  417. package/dist/sync/scan-events.d.ts +17 -0
  418. package/dist/sync/scan-events.d.ts.map +1 -0
  419. package/dist/sync/scan-events.js +32 -0
  420. package/dist/sync/scan-events.js.map +1 -0
  421. package/dist/sync/scan-limit.cjs +33 -0
  422. package/dist/sync/scan-limit.cjs.map +1 -0
  423. package/dist/sync/scan-limit.d.cts +21 -0
  424. package/dist/sync/scan-limit.d.cts.map +1 -0
  425. package/dist/sync/scan-limit.d.ts +21 -0
  426. package/dist/sync/scan-limit.d.ts.map +1 -0
  427. package/dist/sync/scan-limit.js +31 -0
  428. package/dist/sync/scan-limit.js.map +1 -0
  429. package/dist/sync/scanners/b2.cjs +239 -55
  430. package/dist/sync/scanners/b2.cjs.map +1 -1
  431. package/dist/sync/scanners/b2.d.cts +26 -7
  432. package/dist/sync/scanners/b2.d.cts.map +1 -1
  433. package/dist/sync/scanners/b2.d.ts +26 -7
  434. package/dist/sync/scanners/b2.d.ts.map +1 -1
  435. package/dist/sync/scanners/b2.js +239 -55
  436. package/dist/sync/scanners/b2.js.map +1 -1
  437. package/dist/sync/scanners/local.cjs +215 -56
  438. package/dist/sync/scanners/local.cjs.map +1 -1
  439. package/dist/sync/scanners/local.d.cts +22 -7
  440. package/dist/sync/scanners/local.d.cts.map +1 -1
  441. package/dist/sync/scanners/local.d.ts +22 -7
  442. package/dist/sync/scanners/local.d.ts.map +1 -1
  443. package/dist/sync/scanners/local.js +216 -57
  444. package/dist/sync/scanners/local.js.map +1 -1
  445. package/dist/sync/sha1-metadata.cjs +94 -0
  446. package/dist/sync/sha1-metadata.cjs.map +1 -0
  447. package/dist/sync/sha1-metadata.d.cts +82 -0
  448. package/dist/sync/sha1-metadata.d.cts.map +1 -0
  449. package/dist/sync/sha1-metadata.d.ts +82 -0
  450. package/dist/sync/sha1-metadata.d.ts.map +1 -0
  451. package/dist/sync/sha1-metadata.js +89 -0
  452. package/dist/sync/sha1-metadata.js.map +1 -0
  453. package/dist/sync/sha1-options.cjs +23 -0
  454. package/dist/sync/sha1-options.cjs.map +1 -0
  455. package/dist/sync/sha1-options.d.cts +14 -0
  456. package/dist/sync/sha1-options.d.cts.map +1 -0
  457. package/dist/sync/sha1-options.d.ts +14 -0
  458. package/dist/sync/sha1-options.d.ts.map +1 -0
  459. package/dist/sync/sha1-options.js +21 -0
  460. package/dist/sync/sha1-options.js.map +1 -0
  461. package/dist/sync/synchronizer.cjs +782 -197
  462. package/dist/sync/synchronizer.cjs.map +1 -1
  463. package/dist/sync/synchronizer.d.cts +47 -1
  464. package/dist/sync/synchronizer.d.cts.map +1 -1
  465. package/dist/sync/synchronizer.d.ts +47 -1
  466. package/dist/sync/synchronizer.d.ts.map +1 -1
  467. package/dist/sync/synchronizer.js +779 -173
  468. package/dist/sync/synchronizer.js.map +1 -1
  469. package/dist/sync/types.d.cts +208 -16
  470. package/dist/sync/types.d.cts.map +1 -1
  471. package/dist/sync/types.d.ts +208 -16
  472. package/dist/sync/types.d.ts.map +1 -1
  473. package/dist/types/auth.cjs +76 -56
  474. package/dist/types/auth.cjs.map +1 -1
  475. package/dist/types/auth.d.cts +67 -9
  476. package/dist/types/auth.d.cts.map +1 -1
  477. package/dist/types/auth.d.ts +67 -9
  478. package/dist/types/auth.d.ts.map +1 -1
  479. package/dist/types/auth.js +77 -57
  480. package/dist/types/auth.js.map +1 -1
  481. package/dist/types/bucket.cjs +74 -38
  482. package/dist/types/bucket.cjs.map +1 -1
  483. package/dist/types/bucket.js +75 -41
  484. package/dist/types/bucket.js.map +1 -1
  485. package/dist/types/encryption.cjs +364 -327
  486. package/dist/types/encryption.cjs.map +1 -1
  487. package/dist/types/encryption.d.cts +16 -0
  488. package/dist/types/encryption.d.cts.map +1 -1
  489. package/dist/types/encryption.d.ts +16 -0
  490. package/dist/types/encryption.d.ts.map +1 -1
  491. package/dist/types/encryption.js +364 -310
  492. package/dist/types/encryption.js.map +1 -1
  493. package/dist/types/errors.cjs +47 -0
  494. package/dist/types/errors.cjs.map +1 -0
  495. package/dist/types/errors.d.cts +13 -4
  496. package/dist/types/errors.d.cts.map +1 -1
  497. package/dist/types/errors.d.ts +13 -4
  498. package/dist/types/errors.d.ts.map +1 -1
  499. package/dist/types/errors.js +47 -0
  500. package/dist/types/errors.js.map +1 -0
  501. package/dist/types/file.cjs +36 -19
  502. package/dist/types/file.cjs.map +1 -1
  503. package/dist/types/file.d.cts +2 -2
  504. package/dist/types/file.d.cts.map +1 -1
  505. package/dist/types/file.d.ts +2 -2
  506. package/dist/types/file.d.ts.map +1 -1
  507. package/dist/types/file.js +37 -21
  508. package/dist/types/file.js.map +1 -1
  509. package/dist/types/ids.cjs +53 -9
  510. package/dist/types/ids.cjs.map +1 -1
  511. package/dist/types/ids.js +54 -15
  512. package/dist/types/ids.js.map +1 -1
  513. package/dist/types/index.d.cts +12 -11
  514. package/dist/types/index.d.cts.map +1 -1
  515. package/dist/types/index.d.ts +12 -11
  516. package/dist/types/index.d.ts.map +1 -1
  517. package/dist/types/key.d.cts +44 -8
  518. package/dist/types/key.d.cts.map +1 -1
  519. package/dist/types/key.d.ts +44 -8
  520. package/dist/types/key.d.ts.map +1 -1
  521. package/dist/types/lock.cjs +33 -13
  522. package/dist/types/lock.cjs.map +1 -1
  523. package/dist/types/lock.js +34 -15
  524. package/dist/types/lock.js.map +1 -1
  525. package/dist/types/notifications.cjs +44 -22
  526. package/dist/types/notifications.cjs.map +1 -1
  527. package/dist/types/notifications.js +45 -23
  528. package/dist/types/notifications.js.map +1 -1
  529. package/dist/types/upload.d.cts +39 -5
  530. package/dist/types/upload.d.cts.map +1 -1
  531. package/dist/types/upload.d.ts +39 -5
  532. package/dist/types/upload.d.ts.map +1 -1
  533. package/dist/upload/abort-scope.cjs +91 -0
  534. package/dist/upload/abort-scope.cjs.map +1 -0
  535. package/dist/upload/abort-scope.d.cts +48 -0
  536. package/dist/upload/abort-scope.d.cts.map +1 -0
  537. package/dist/upload/abort-scope.d.ts +48 -0
  538. package/dist/upload/abort-scope.d.ts.map +1 -0
  539. package/dist/upload/abort-scope.js +88 -0
  540. package/dist/upload/abort-scope.js.map +1 -0
  541. package/dist/upload/cancel.cjs +183 -8
  542. package/dist/upload/cancel.cjs.map +1 -1
  543. package/dist/upload/cancel.d.cts +110 -2
  544. package/dist/upload/cancel.d.cts.map +1 -1
  545. package/dist/upload/cancel.d.ts +110 -2
  546. package/dist/upload/cancel.d.ts.map +1 -1
  547. package/dist/upload/cancel.js +178 -9
  548. package/dist/upload/cancel.js.map +1 -1
  549. package/dist/upload/concurrency.cjs +79 -52
  550. package/dist/upload/concurrency.cjs.map +1 -1
  551. package/dist/upload/concurrency.js +79 -53
  552. package/dist/upload/concurrency.js.map +1 -1
  553. package/dist/upload/finish.cjs +59 -0
  554. package/dist/upload/finish.cjs.map +1 -0
  555. package/dist/upload/finish.d.cts +26 -0
  556. package/dist/upload/finish.d.cts.map +1 -0
  557. package/dist/upload/finish.d.ts +26 -0
  558. package/dist/upload/finish.d.ts.map +1 -0
  559. package/dist/upload/finish.js +59 -0
  560. package/dist/upload/finish.js.map +1 -0
  561. package/dist/upload/large.cjs +301 -218
  562. package/dist/upload/large.cjs.map +1 -1
  563. package/dist/upload/large.d.cts +76 -9
  564. package/dist/upload/large.d.cts.map +1 -1
  565. package/dist/upload/large.d.ts +76 -9
  566. package/dist/upload/large.d.ts.map +1 -1
  567. package/dist/upload/large.js +301 -218
  568. package/dist/upload/large.js.map +1 -1
  569. package/dist/upload/options.cjs +28 -0
  570. package/dist/upload/options.cjs.map +1 -0
  571. package/dist/upload/options.d.cts +104 -0
  572. package/dist/upload/options.d.cts.map +1 -0
  573. package/dist/upload/options.d.ts +104 -0
  574. package/dist/upload/options.d.ts.map +1 -0
  575. package/dist/upload/options.js +27 -0
  576. package/dist/upload/options.js.map +1 -0
  577. package/dist/upload/resume.cjs +333 -33
  578. package/dist/upload/resume.cjs.map +1 -1
  579. package/dist/upload/resume.d.cts +82 -12
  580. package/dist/upload/resume.d.cts.map +1 -1
  581. package/dist/upload/resume.d.ts +82 -12
  582. package/dist/upload/resume.d.ts.map +1 -1
  583. package/dist/upload/resume.js +330 -33
  584. package/dist/upload/resume.js.map +1 -1
  585. package/dist/upload/retry.cjs +186 -0
  586. package/dist/upload/retry.cjs.map +1 -0
  587. package/dist/upload/retry.d.cts +127 -0
  588. package/dist/upload/retry.d.cts.map +1 -0
  589. package/dist/upload/retry.d.ts +127 -0
  590. package/dist/upload/retry.d.ts.map +1 -0
  591. package/dist/upload/retry.js +182 -0
  592. package/dist/upload/retry.js.map +1 -0
  593. package/dist/upload/single.cjs +68 -44
  594. package/dist/upload/single.cjs.map +1 -1
  595. package/dist/upload/single.d.cts +2 -1
  596. package/dist/upload/single.d.cts.map +1 -1
  597. package/dist/upload/single.d.ts +2 -1
  598. package/dist/upload/single.d.ts.map +1 -1
  599. package/dist/upload/single.js +68 -44
  600. package/dist/upload/single.js.map +1 -1
  601. package/dist/upload/stream.cjs +317 -193
  602. package/dist/upload/stream.cjs.map +1 -1
  603. package/dist/upload/stream.d.cts +3 -1
  604. package/dist/upload/stream.d.cts.map +1 -1
  605. package/dist/upload/stream.d.ts +3 -1
  606. package/dist/upload/stream.d.ts.map +1 -1
  607. package/dist/upload/stream.js +316 -192
  608. package/dist/upload/stream.js.map +1 -1
  609. package/dist/util/best-effort.cjs +42 -8
  610. package/dist/util/best-effort.cjs.map +1 -1
  611. package/dist/util/best-effort.d.cts +2 -1
  612. package/dist/util/best-effort.d.cts.map +1 -1
  613. package/dist/util/best-effort.d.ts +2 -1
  614. package/dist/util/best-effort.d.ts.map +1 -1
  615. package/dist/util/best-effort.js +43 -9
  616. package/dist/util/best-effort.js.map +1 -1
  617. package/dist/util/bytes.cjs +23 -0
  618. package/dist/util/bytes.cjs.map +1 -0
  619. package/dist/util/bytes.d.cts +15 -0
  620. package/dist/util/bytes.d.cts.map +1 -0
  621. package/dist/util/bytes.d.ts +15 -0
  622. package/dist/util/bytes.d.ts.map +1 -0
  623. package/dist/util/bytes.js +23 -0
  624. package/dist/util/bytes.js.map +1 -0
  625. package/dist/util/crypto.cjs +68 -0
  626. package/dist/util/crypto.cjs.map +1 -0
  627. package/dist/util/crypto.d.cts +26 -0
  628. package/dist/util/crypto.d.cts.map +1 -0
  629. package/dist/util/crypto.d.ts +26 -0
  630. package/dist/util/crypto.d.ts.map +1 -0
  631. package/dist/util/crypto.js +66 -0
  632. package/dist/util/crypto.js.map +1 -0
  633. package/dist/util/defaults.cjs +25 -9
  634. package/dist/util/defaults.cjs.map +1 -1
  635. package/dist/util/defaults.js +26 -11
  636. package/dist/util/defaults.js.map +1 -1
  637. package/dist/util/error-reason.cjs +41 -0
  638. package/dist/util/error-reason.cjs.map +1 -0
  639. package/dist/util/error-reason.d.cts +9 -0
  640. package/dist/util/error-reason.d.cts.map +1 -0
  641. package/dist/util/error-reason.d.ts +9 -0
  642. package/dist/util/error-reason.d.ts.map +1 -0
  643. package/dist/util/error-reason.js +41 -0
  644. package/dist/util/error-reason.js.map +1 -0
  645. package/dist/util/http.cjs +23 -0
  646. package/dist/util/http.cjs.map +1 -0
  647. package/dist/util/http.d.cts +13 -0
  648. package/dist/util/http.d.cts.map +1 -0
  649. package/dist/util/http.d.ts +13 -0
  650. package/dist/util/http.d.ts.map +1 -0
  651. package/dist/util/http.js +23 -0
  652. package/dist/util/http.js.map +1 -0
  653. package/dist/util/normalize.cjs +66 -7
  654. package/dist/util/normalize.cjs.map +1 -1
  655. package/dist/util/normalize.js +67 -10
  656. package/dist/util/normalize.js.map +1 -1
  657. package/dist/util/paginator.cjs +63 -14
  658. package/dist/util/paginator.cjs.map +1 -1
  659. package/dist/util/paginator.js +64 -16
  660. package/dist/util/paginator.js.map +1 -1
  661. package/dist/util/plan-ranges.cjs +47 -22
  662. package/dist/util/plan-ranges.cjs.map +1 -1
  663. package/dist/util/plan-ranges.js +48 -24
  664. package/dist/util/plan-ranges.js.map +1 -1
  665. package/dist/util/sha1.cjs +27 -0
  666. package/dist/util/sha1.cjs.map +1 -0
  667. package/dist/util/sha1.d.cts +17 -0
  668. package/dist/util/sha1.d.cts.map +1 -0
  669. package/dist/util/sha1.d.ts +17 -0
  670. package/dist/util/sha1.d.ts.map +1 -0
  671. package/dist/util/sha1.js +26 -0
  672. package/dist/util/sha1.js.map +1 -0
  673. package/dist/util/text-codec.cjs +29 -5
  674. package/dist/util/text-codec.cjs.map +1 -1
  675. package/dist/util/text-codec.js +30 -7
  676. package/dist/util/text-codec.js.map +1 -1
  677. package/dist/util/to-error.cjs +18 -4
  678. package/dist/util/to-error.cjs.map +1 -1
  679. package/dist/util/to-error.js +19 -5
  680. package/dist/util/to-error.js.map +1 -1
  681. package/dist/version.cjs +17 -5
  682. package/dist/version.cjs.map +1 -1
  683. package/dist/version.d.cts +3 -3
  684. package/dist/version.d.ts +3 -3
  685. package/dist/version.js +19 -6
  686. package/dist/version.js.map +1 -1
  687. package/package.json +19 -16
  688. package/dist/auth/index.cjs.map +0 -1
  689. package/dist/auth/index.js.map +0 -1
  690. package/dist/index.cjs.map +0 -1
  691. package/dist/index.js.map +0 -1
  692. package/dist/notifications/index.cjs.map +0 -1
  693. package/dist/notifications/index.js.map +0 -1
  694. package/dist/package.json.cjs +0 -9
  695. package/dist/package.json.cjs.map +0 -1
  696. package/dist/package.json.js +0 -9
  697. package/dist/package.json.js.map +0 -1
  698. package/dist/streams/index.cjs.map +0 -1
  699. package/dist/streams/index.js.map +0 -1
  700. package/dist/sync/index.cjs.map +0 -1
  701. package/dist/sync/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cancel.d.ts","sourceRoot":"","sources":["../../src/up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ACH,wBAAgB,+CAA+C,CAC7D,GAAG,EAAE,gCAAgC,EACrC,OAAO,EAAE,uBAAuB,GAC/B,gCAAgC,CAclC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,SAAS,EACd,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,uBAAuB,EAChC,OAAO,GAAE,6BAAkC,GAC1C,OAAO,CAAC,OAAO,CAAC,CAalB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,0BAA0B,CAC9C,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,SAAS,EACd,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,uBAAuB,EAChC,OAAO,CAAC,EAAE,6BAA6B,GACtC,OAAO,CAAC,KAAK,CAAC,CAEhB"}
@@ -1,10 +1,179 @@
1
+ import { FinishLargeFileResponseBodyError } from "../errors/index.js";
1
2
  import { bestEffort } from "../util/best-effort.js";
2
- async function cancelLargeFileBestEffort(raw, accountInfo, fileId) {
3
- await bestEffort(
4
- () => raw.cancelLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), { fileId })
5
- );
6
- }
7
- export {
8
- cancelLargeFileBestEffort
9
- };
10
- //# sourceMappingURL=cancel.js.map
3
+ //#region src/upload/cancel.ts
4
+ /** Default wall-clock bound for best-effort cleanup calls after upload failure. */
5
+ var DEFAULT_CLEANUP_TIMEOUT_MS = 3e4;
6
+ var fallbackCleanupDisposers = /* @__PURE__ */ new WeakMap();
7
+ /**
8
+ * Cancels an unfinished large file on a best-effort basis. Used at every
9
+ * error-handling boundary in the multipart upload, write-stream, and
10
+ * server-side copy paths to roll back in-progress uploads without
11
+ * letting a cancellation failure mask the underlying error the caller
12
+ * is about to see.
13
+ *
14
+ * Centralising the call removes a five-line `bestEffort` block that
15
+ * recurred at six sites with identical shape — the only thing that
16
+ * changed was the captured `fileId` and the surrounding error trail.
17
+ *
18
+ * @param raw - Low-level B2 API client.
19
+ * @param accountInfo - Authorized account state for the API URL + token.
20
+ * @param fileId - The in-progress large file ID to cancel.
21
+ * @param options - Optional request controls and cleanup-failure observer.
22
+ *
23
+ * @returns A promise that always resolves, regardless of the cancel
24
+ * call's outcome.
25
+ */
26
+ async function cancelLargeFileBestEffort(raw, accountInfo, fileId, options) {
27
+ await bestEffort(async () => {
28
+ const requestOptions = cleanupRequestOptions(options?.signal);
29
+ await waitForCleanup(raw.cancelLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), { fileId }, requestOptions), requestOptions.signal);
30
+ }, (error) => options?.onCleanupFailure?.({
31
+ fileId,
32
+ error,
33
+ reason: "cancel-failed"
34
+ }));
35
+ }
36
+ /**
37
+ * Returns cleanup request controls with a live timeout signal.
38
+ *
39
+ * @param signal - Caller-provided abort signal, if any.
40
+ * @param timeoutMs - Maximum time to spend waiting for cleanup.
41
+ *
42
+ * @returns Request controls with a signal independent of an already-aborted caller signal.
43
+ */
44
+ function cleanupRequestOptions(signal, timeoutMs = DEFAULT_CLEANUP_TIMEOUT_MS) {
45
+ return { signal: createCleanupSignal(signal, timeoutMs) };
46
+ }
47
+ function createCleanupSignal(signal, timeoutMs) {
48
+ if (typeof AbortSignal.timeout === "function") {
49
+ if (signal === void 0 || signal.aborted) return AbortSignal.timeout(timeoutMs);
50
+ if (typeof AbortSignal.any === "function") return AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]);
51
+ }
52
+ return createFallbackCleanupSignal(signal, timeoutMs);
53
+ }
54
+ function createFallbackCleanupSignal(signal, timeoutMs) {
55
+ const controller = new AbortController();
56
+ const timeout = setTimeout(() => {
57
+ abortFallbackCleanup(controller, cleanupTimeoutReason(), cleanup);
58
+ }, timeoutMs);
59
+ const onAbort = () => {
60
+ const reason = signal === void 0 ? cleanupDomException("Cleanup aborted", "AbortError") : cleanupAbortReason(signal);
61
+ abortFallbackCleanup(controller, reason, cleanup);
62
+ };
63
+ const cleanup = () => {
64
+ clearTimeout(timeout);
65
+ signal?.removeEventListener("abort", onAbort);
66
+ fallbackCleanupDisposers.delete(controller.signal);
67
+ };
68
+ fallbackCleanupDisposers.set(controller.signal, cleanup);
69
+ if (signal === void 0 || signal.aborted) return controller.signal;
70
+ signal.addEventListener("abort", onAbort, { once: true });
71
+ controller.signal.addEventListener("abort", cleanup, { once: true });
72
+ return controller.signal;
73
+ }
74
+ function abortFallbackCleanup(controller, reason, cleanup) {
75
+ if (!controller.signal.aborted) controller.abort(reason);
76
+ cleanup();
77
+ }
78
+ async function waitForCleanup(request, signal) {
79
+ if (signal.aborted) throw cleanupAbortReason(signal);
80
+ let removeAbortListener;
81
+ const aborted = new Promise((_resolve, reject) => {
82
+ const onAbort = () => reject(cleanupAbortReason(signal));
83
+ signal.addEventListener("abort", onAbort, { once: true });
84
+ removeAbortListener = () => signal.removeEventListener("abort", onAbort);
85
+ });
86
+ try {
87
+ await Promise.race([request, aborted]);
88
+ } finally {
89
+ removeAbortListener?.();
90
+ fallbackCleanupDisposers.get(signal)?.();
91
+ request.catch(() => {});
92
+ }
93
+ }
94
+ function cleanupAbortReason(signal) {
95
+ return signal.reason ?? cleanupDomException("Cleanup aborted", "AbortError");
96
+ }
97
+ function cleanupTimeoutReason() {
98
+ return cleanupDomException("Cleanup timed out", "TimeoutError");
99
+ }
100
+ function cleanupDomException(message, name) {
101
+ if (typeof DOMException === "function") return new DOMException(message, name);
102
+ const error = new Error(message);
103
+ error.name = name;
104
+ return error;
105
+ }
106
+ /**
107
+ * Emits an observable cleanup event when cancellation is deliberately skipped
108
+ * because `b2_finish_large_file` may already have committed the file.
109
+ * @param fileId - Large file whose final state is ambiguous.
110
+ * @param error - Ambiguous finish error that will be thrown to the caller.
111
+ * @param onCleanupFailure - Optional observer for cleanup-related events.
112
+ */
113
+ function notifyAmbiguousLargeFileCleanupSkipped(fileId, error, onCleanupFailure) {
114
+ try {
115
+ onCleanupFailure?.({
116
+ fileId,
117
+ error,
118
+ reason: "finish-ambiguous"
119
+ });
120
+ } catch {}
121
+ }
122
+ /**
123
+ * Adds high-level reconciliation metadata to an ambiguous finish response-body
124
+ * error and notifies the cleanup observer that cancellation was skipped.
125
+ *
126
+ * @param err - Raw finish response-body error from the low-level client.
127
+ * @param options - Large-file context used for reconciliation.
128
+ *
129
+ * @returns The enriched {@link FinishLargeFileResponseBodyError}.
130
+ */
131
+ function handleAmbiguousFinishLargeFileResponseBodyError(err, options) {
132
+ const enriched = err.fileId === options.fileId && err.bucketId === options.bucketId && err.fileName === options.fileName ? err : new FinishLargeFileResponseBodyError(err.message, {
133
+ cause: err.cause ?? err,
134
+ fileId: options.fileId,
135
+ bucketId: options.bucketId,
136
+ fileName: options.fileName
137
+ });
138
+ notifyAmbiguousLargeFileCleanupSkipped(options.fileId, enriched, options.onCleanupFailure);
139
+ return enriched;
140
+ }
141
+ /**
142
+ * Performs the shared large-file failure policy: ambiguous finish-body errors
143
+ * are enriched and left uncancelled, while all pre-finish errors trigger
144
+ * best-effort cancellation.
145
+ *
146
+ * @param err - Error from a multipart upload/copy/write-stream path.
147
+ * @param raw - Low-level B2 API client.
148
+ * @param accountInfo - Authorized account state.
149
+ * @param context - Large file metadata used for cleanup and diagnostics.
150
+ * @param options - Cleanup policy controls.
151
+ *
152
+ * @returns The error that should be surfaced to the caller.
153
+ */
154
+ async function resolveLargeFileErrorAfterCleanup(err, raw, accountInfo, context, options = {}) {
155
+ if (err instanceof FinishLargeFileResponseBodyError) return handleAmbiguousFinishLargeFileResponseBodyError(err, context);
156
+ if (options.cancelOnError ?? true) await cancelLargeFileBestEffort(raw, accountInfo, context.fileId, {
157
+ ...context.signal !== void 0 ? { signal: context.signal } : {},
158
+ ...context.onCleanupFailure !== void 0 ? { onCleanupFailure: context.onCleanupFailure } : {}
159
+ });
160
+ return err;
161
+ }
162
+ /**
163
+ * Throwing wrapper around {@link resolveLargeFileErrorAfterCleanup} for paths
164
+ * that can surface the error directly.
165
+ * @param err - Error from a multipart upload/copy/write-stream path.
166
+ * @param raw - Low-level B2 API client.
167
+ * @param accountInfo - Authorized account state.
168
+ * @param context - Large file metadata used for cleanup and diagnostics.
169
+ * @param options - Cleanup policy controls.
170
+ *
171
+ * @throws The resolved large-file error after cleanup policy is applied.
172
+ */
173
+ async function cleanupAfterLargeFileError(err, raw, accountInfo, context, options) {
174
+ throw await resolveLargeFileErrorAfterCleanup(err, raw, accountInfo, context, options);
175
+ }
176
+ //#endregion
177
+ export { DEFAULT_CLEANUP_TIMEOUT_MS, cancelLargeFileBestEffort, cleanupAfterLargeFileError, cleanupRequestOptions, handleAmbiguousFinishLargeFileResponseBodyError, notifyAmbiguousLargeFileCleanupSkipped, resolveLargeFileErrorAfterCleanup };
178
+
179
+ //# sourceMappingURL=cancel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cancel.js","sources":["../../src/upload/cancel.ts"],"sourcesContent":["import type { AccountInfo } from '../auth/account-info.ts'\nimport type { RawClient } from '../raw/index.ts'\nimport type { LargeFileId } from '../types/ids.ts'\nimport { bestEffort } from '../util/best-effort.ts'\n\n/**\n * Cancels an unfinished large file on a best-effort basis. Used at every\n * error-handling boundary in the multipart upload, write-stream, and\n * server-side copy paths to roll back in-progress uploads without\n * letting a cancellation failure mask the underlying error the caller\n * is about to see.\n *\n * Centralising the call removes a five-line `bestEffort` block that\n * recurred at six sites with identical shape — the only thing that\n * changed was the captured `fileId` and the surrounding error trail.\n *\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state for the API URL + token.\n * @param fileId - The in-progress large file ID to cancel.\n *\n * @returns A promise that always resolves, regardless of the cancel\n * call's outcome.\n */\nexport async function cancelLargeFileBestEffort(\n raw: RawClient,\n accountInfo: AccountInfo,\n fileId: LargeFileId,\n): Promise<void> {\n await bestEffort(() =>\n raw.cancelLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), { fileId }),\n )\n}\n"],"names":[],"mappings":";AAuBA,eAAsB,0BACpB,KACA,aACA,QACe;AACf,QAAM;AAAA,IAAW,MACf,IAAI,gBAAgB,YAAY,UAAA,GAAa,YAAY,gBAAgB,EAAE,OAAA,CAAQ;AAAA,EAAA;AAEvF;"}
1
+ {"version":3,"file":"cancel.js","names":[],"sources":["../../src/upload/cancel.ts"],"sourcesContent":["import type { AccountInfo } from '../auth/account-info.ts'\nimport { FinishLargeFileResponseBodyError } from '../errors/index.ts'\nimport type { RawClient } from '../raw/index.ts'\nimport type { BucketId, LargeFileId } from '../types/ids.ts'\nimport { bestEffort } from '../util/best-effort.ts'\n\n/** Event emitted when best-effort `b2_cancel_large_file` cleanup fails. */\nexport interface CancelLargeFileCleanupFailureEvent {\n /** Unfinished large file that may remain orphaned. */\n readonly fileId: LargeFileId\n /** Error thrown by `b2_cancel_large_file`. */\n readonly error: unknown\n /** Cleanup phase that produced the observable event. */\n readonly reason: 'cancel-failed'\n}\n\n/** Event emitted when cleanup is skipped because finish may have committed. */\nexport interface AmbiguousFinishCleanupFailureEvent {\n /** Large file whose final server-side state is ambiguous. */\n readonly fileId: LargeFileId\n /** Error thrown to the caller with reconciliation metadata. */\n readonly error: FinishLargeFileResponseBodyError\n /** Cleanup phase that produced the observable event. */\n readonly reason: 'finish-ambiguous'\n}\n\n/** Event emitted when large-file cleanup fails or is deliberately skipped. */\nexport type CleanupFailureEvent =\n | CancelLargeFileCleanupFailureEvent\n | AmbiguousFinishCleanupFailureEvent\n\n/** Callback invoked when best-effort cancellation fails or finish cleanup is skipped. */\nexport type CleanupFailureListener = (event: CleanupFailureEvent) => void\n\n/** Shared option for observing large-file cleanup failures or skipped cleanup. */\nexport interface CleanupFailureOptions {\n /**\n * Callback invoked if best-effort cancellation fails, or if cancellation is\n * skipped because `b2_finish_large_file` may already have committed.\n */\n readonly onCleanupFailure?: CleanupFailureListener\n}\n\n/** Default wall-clock bound for best-effort cleanup calls after upload failure. */\nexport const DEFAULT_CLEANUP_TIMEOUT_MS = 30_000\n\nconst fallbackCleanupDisposers = new WeakMap<AbortSignal, () => void>()\n\n/** Context needed to reconcile or cancel an unfinished large file after an error. */\nexport interface LargeFileCleanupContext {\n readonly fileId: LargeFileId\n readonly bucketId: BucketId\n readonly fileName: string\n readonly signal?: AbortSignal | undefined\n readonly onCleanupFailure?: CleanupFailureListener | undefined\n}\n\n/** Options for applying the shared large-file cleanup policy. */\nexport interface LargeFileCleanupPolicyOptions {\n /**\n * Whether non-ambiguous failures should cancel the unfinished large file.\n * Defaults to true. Explicit resume callers can disable this so the SDK does\n * not cancel a large file that it did not create.\n */\n readonly cancelOnError?: boolean\n}\n\n/**\n * Cancels an unfinished large file on a best-effort basis. Used at every\n * error-handling boundary in the multipart upload, write-stream, and\n * server-side copy paths to roll back in-progress uploads without\n * letting a cancellation failure mask the underlying error the caller\n * is about to see.\n *\n * Centralising the call removes a five-line `bestEffort` block that\n * recurred at six sites with identical shape — the only thing that\n * changed was the captured `fileId` and the surrounding error trail.\n *\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state for the API URL + token.\n * @param fileId - The in-progress large file ID to cancel.\n * @param options - Optional request controls and cleanup-failure observer.\n *\n * @returns A promise that always resolves, regardless of the cancel\n * call's outcome.\n */\nexport async function cancelLargeFileBestEffort(\n raw: RawClient,\n accountInfo: AccountInfo,\n fileId: LargeFileId,\n options?: { readonly signal?: AbortSignal } & CleanupFailureOptions,\n): Promise<void> {\n await bestEffort(\n async () => {\n const requestOptions = cleanupRequestOptions(options?.signal)\n const request = raw.cancelLargeFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n { fileId },\n requestOptions,\n )\n await waitForCleanup(request, requestOptions.signal)\n },\n (error) => options?.onCleanupFailure?.({ fileId, error, reason: 'cancel-failed' }),\n )\n}\n\n/**\n * Returns cleanup request controls with a live timeout signal.\n *\n * @param signal - Caller-provided abort signal, if any.\n * @param timeoutMs - Maximum time to spend waiting for cleanup.\n *\n * @returns Request controls with a signal independent of an already-aborted caller signal.\n */\nexport function cleanupRequestOptions(\n signal: AbortSignal | undefined,\n timeoutMs = DEFAULT_CLEANUP_TIMEOUT_MS,\n): { readonly signal: AbortSignal } {\n return { signal: createCleanupSignal(signal, timeoutMs) }\n}\n\nfunction createCleanupSignal(signal: AbortSignal | undefined, timeoutMs: number): AbortSignal {\n if (typeof AbortSignal.timeout === 'function') {\n if (signal === undefined || signal.aborted) return AbortSignal.timeout(timeoutMs)\n if (typeof AbortSignal.any === 'function') {\n return AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)])\n }\n }\n\n return createFallbackCleanupSignal(signal, timeoutMs)\n}\n\nfunction createFallbackCleanupSignal(\n signal: AbortSignal | undefined,\n timeoutMs: number,\n): AbortSignal {\n const controller = new AbortController()\n const timeout = setTimeout(() => {\n abortFallbackCleanup(controller, cleanupTimeoutReason(), cleanup)\n }, timeoutMs)\n\n const onAbort = () => {\n const reason =\n signal === undefined\n ? cleanupDomException('Cleanup aborted', 'AbortError')\n : cleanupAbortReason(signal)\n abortFallbackCleanup(controller, reason, cleanup)\n }\n const cleanup = () => {\n clearTimeout(timeout)\n signal?.removeEventListener('abort', onAbort)\n fallbackCleanupDisposers.delete(controller.signal)\n }\n fallbackCleanupDisposers.set(controller.signal, cleanup)\n\n if (signal === undefined || signal.aborted) {\n return controller.signal\n }\n\n signal.addEventListener('abort', onAbort, { once: true })\n controller.signal.addEventListener('abort', cleanup, { once: true })\n return controller.signal\n}\n\nfunction abortFallbackCleanup(\n controller: AbortController,\n reason: unknown,\n cleanup: () => void,\n): void {\n if (!controller.signal.aborted) controller.abort(reason)\n cleanup()\n}\n\nasync function waitForCleanup(request: Promise<unknown>, signal: AbortSignal): Promise<void> {\n if (signal.aborted) throw cleanupAbortReason(signal)\n\n let removeAbortListener: (() => void) | undefined\n const aborted = new Promise<never>((_resolve, reject) => {\n const onAbort = () => reject(cleanupAbortReason(signal))\n signal.addEventListener('abort', onAbort, { once: true })\n removeAbortListener = () => signal.removeEventListener('abort', onAbort)\n })\n\n try {\n await Promise.race([request, aborted])\n } finally {\n removeAbortListener?.()\n fallbackCleanupDisposers.get(signal)?.()\n void request.catch(() => {})\n }\n}\n\nfunction cleanupAbortReason(signal: AbortSignal): unknown {\n return signal.reason ?? cleanupDomException('Cleanup aborted', 'AbortError')\n}\n\nfunction cleanupTimeoutReason(): unknown {\n return cleanupDomException('Cleanup timed out', 'TimeoutError')\n}\n\nfunction cleanupDomException(message: string, name: string): Error {\n if (typeof DOMException === 'function') return new DOMException(message, name)\n const error = new Error(message)\n error.name = name\n return error\n}\n\n/**\n * Emits an observable cleanup event when cancellation is deliberately skipped\n * because `b2_finish_large_file` may already have committed the file.\n * @param fileId - Large file whose final state is ambiguous.\n * @param error - Ambiguous finish error that will be thrown to the caller.\n * @param onCleanupFailure - Optional observer for cleanup-related events.\n */\nexport function notifyAmbiguousLargeFileCleanupSkipped(\n fileId: LargeFileId,\n error: FinishLargeFileResponseBodyError,\n onCleanupFailure?: CleanupFailureListener,\n): void {\n try {\n onCleanupFailure?.({ fileId, error, reason: 'finish-ambiguous' })\n } catch {\n // Observer failures are secondary and must not hide the finish ambiguity.\n }\n}\n\n/**\n * Adds high-level reconciliation metadata to an ambiguous finish response-body\n * error and notifies the cleanup observer that cancellation was skipped.\n *\n * @param err - Raw finish response-body error from the low-level client.\n * @param options - Large-file context used for reconciliation.\n *\n * @returns The enriched {@link FinishLargeFileResponseBodyError}.\n */\nexport function handleAmbiguousFinishLargeFileResponseBodyError(\n err: FinishLargeFileResponseBodyError,\n options: LargeFileCleanupContext,\n): FinishLargeFileResponseBodyError {\n const enriched =\n err.fileId === options.fileId &&\n err.bucketId === options.bucketId &&\n err.fileName === options.fileName\n ? err\n : new FinishLargeFileResponseBodyError(err.message, {\n cause: err.cause ?? err,\n fileId: options.fileId,\n bucketId: options.bucketId,\n fileName: options.fileName,\n })\n notifyAmbiguousLargeFileCleanupSkipped(options.fileId, enriched, options.onCleanupFailure)\n return enriched\n}\n\n/**\n * Performs the shared large-file failure policy: ambiguous finish-body errors\n * are enriched and left uncancelled, while all pre-finish errors trigger\n * best-effort cancellation.\n *\n * @param err - Error from a multipart upload/copy/write-stream path.\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state.\n * @param context - Large file metadata used for cleanup and diagnostics.\n * @param options - Cleanup policy controls.\n *\n * @returns The error that should be surfaced to the caller.\n */\nexport async function resolveLargeFileErrorAfterCleanup(\n err: unknown,\n raw: RawClient,\n accountInfo: AccountInfo,\n context: LargeFileCleanupContext,\n options: LargeFileCleanupPolicyOptions = {},\n): Promise<unknown> {\n if (err instanceof FinishLargeFileResponseBodyError) {\n return handleAmbiguousFinishLargeFileResponseBodyError(err, context)\n }\n if (options.cancelOnError ?? true) {\n await cancelLargeFileBestEffort(raw, accountInfo, context.fileId, {\n ...(context.signal !== undefined ? { signal: context.signal } : {}),\n ...(context.onCleanupFailure !== undefined\n ? { onCleanupFailure: context.onCleanupFailure }\n : {}),\n })\n }\n return err\n}\n\n/**\n * Throwing wrapper around {@link resolveLargeFileErrorAfterCleanup} for paths\n * that can surface the error directly.\n * @param err - Error from a multipart upload/copy/write-stream path.\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state.\n * @param context - Large file metadata used for cleanup and diagnostics.\n * @param options - Cleanup policy controls.\n *\n * @throws The resolved large-file error after cleanup policy is applied.\n */\nexport async function cleanupAfterLargeFileError(\n err: unknown,\n raw: RawClient,\n accountInfo: AccountInfo,\n context: LargeFileCleanupContext,\n options?: LargeFileCleanupPolicyOptions,\n): Promise<never> {\n throw await resolveLargeFileErrorAfterCleanup(err, raw, accountInfo, context, options)\n}\n"],"mappings":";;;;AA4CA,IAAa,6BAA6B;AAE1C,IAAM,2CAA2B,IAAI,QAAiC;;;;;;;;;;;;;;;;;;;;AAwCtE,eAAsB,0BACpB,KACA,aACA,QACA,SACe;CACf,MAAM,WACJ,YAAY;EACV,MAAM,iBAAiB,sBAAsB,SAAS,MAAM;EAO5D,MAAM,eANU,IAAI,gBAClB,YAAY,UAAU,GACtB,YAAY,aAAa,GACzB,EAAE,OAAO,GACT,cAEmB,GAAS,eAAe,MAAM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,eAAsB,kCACpB,KACA,KACA,aACA,SACA,UAAyC,CAAC,GACxB;CAClB,IAAI,eAAe,kCACjB,OAAO,gDAAgD,KAAK,OAAO;CAErE,IAAI,QAAQ,iBAAiB,MAC3B,MAAM,0BAA0B,KAAK,aAAa,QAAQ,QAAQ;EAChE,GAAI,QAAQ,WAAW,KAAA,IAAY,EAAE,QAAQ,QAAQ,OAAO,IAAI,CAAC;EACjE,GAAI,QAAQ,qBAAqB,KAAA,IAC7B,EAAE,kBAAkB,QAAQ,iBAAiB,IAC7C,CAAC;CACP,CAAC;CAEH,OAAO;AACT;;;;;;;;;;;;AAaA,eAAsB,2BACpB,KACA,KACA,aACA,SACA,SACgB;CAChB,MAAM,MAAM,kCAAkC,KAAK,KAAK,aAAa,SAAS,OAAO;AACvF"}
@@ -1,54 +1,81 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- class Semaphore {
4
- /**
5
- * @param limit - Maximum number of concurrent acquisitions. Must be a
6
- * positive integer; values `<= 0` would create a semaphore that
7
- * never lets anything through (all `acquire()` calls would queue
8
- * forever), so the constructor throws fast instead.
9
- *
10
- * @throws `RangeError` when `limit` is not a positive integer.
11
- */
12
- constructor(limit) {
13
- this.limit = limit;
14
- if (!Number.isInteger(limit) || limit <= 0) {
15
- throw new RangeError(
16
- `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`
17
- );
18
- }
19
- }
20
- current = 0;
21
- queue = [];
22
- /**
23
- * Acquires a slot, waiting if the limit has been reached.
24
- * @returns A promise that resolves when a slot is available.
25
- */
26
- async acquire() {
27
- if (this.current < this.limit) {
28
- this.current++;
29
- return;
30
- }
31
- return new Promise((resolve) => {
32
- this.queue.push(resolve);
33
- });
34
- }
35
- /** Releases a slot, unblocking the next queued caller if any. */
36
- release() {
37
- const next = this.queue.shift();
38
- if (next) {
39
- next();
40
- } else {
41
- this.current--;
42
- }
43
- }
44
- /**
45
- * Number of slots currently available.
46
- *
47
- * @returns The count of free concurrency slots.
48
- */
49
- get available() {
50
- return this.limit - this.current;
51
- }
1
+ //#region src/upload/concurrency.ts
2
+ /**
3
+ * Bounded concurrency primitive.
4
+ *
5
+ * Limits the number of concurrent operations to a fixed maximum. Callers
6
+ * {@link acquire} a slot before starting work and {@link release} it when done.
7
+ * If all slots are taken, `acquire` returns a promise that resolves when a slot
8
+ * becomes available.
9
+ */
10
+ var Semaphore = class {
11
+ limit;
12
+ current = 0;
13
+ queue = [];
14
+ /**
15
+ * @param limit - Maximum number of concurrent acquisitions. Must be a
16
+ * positive integer; values `<= 0` would create a semaphore that
17
+ * never lets anything through (all `acquire()` calls would queue
18
+ * forever), so the constructor throws fast instead.
19
+ *
20
+ * @throws `RangeError` when `limit` is not a positive integer.
21
+ */
22
+ constructor(limit) {
23
+ this.limit = limit;
24
+ if (!Number.isInteger(limit) || limit <= 0) throw new RangeError(`Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`);
25
+ }
26
+ /**
27
+ * Acquires a slot, waiting if the limit has been reached.
28
+ * @returns A promise that resolves when a slot is available.
29
+ */
30
+ async acquire() {
31
+ if (this.current < this.limit) {
32
+ this.current++;
33
+ return;
34
+ }
35
+ return new Promise((resolve) => {
36
+ this.queue.push(resolve);
37
+ });
38
+ }
39
+ /** Releases a slot, unblocking the next queued caller if any. */
40
+ release() {
41
+ const next = this.queue.shift();
42
+ if (next) next();
43
+ else this.current--;
44
+ }
45
+ /**
46
+ * Number of slots currently available.
47
+ *
48
+ * @returns The count of free concurrency slots.
49
+ */
50
+ get available() {
51
+ return this.limit - this.current;
52
+ }
53
+ };
54
+ /**
55
+ * Maps over an array with bounded concurrency.
56
+ *
57
+ * @param items - Input items to process.
58
+ * @param concurrency - Maximum number of items processed in parallel.
59
+ * @param fn - Async function applied to each item.
60
+ *
61
+ * @returns Results in the same order as the input items.
62
+ */
63
+ async function mapConcurrent(items, concurrency, fn) {
64
+ const sem = new Semaphore(concurrency);
65
+ const results = new Array(items.length);
66
+ const tasks = items.map(async (item, i) => {
67
+ await sem.acquire();
68
+ try {
69
+ results[i] = await fn(item, i);
70
+ } finally {
71
+ sem.release();
72
+ }
73
+ });
74
+ await Promise.all(tasks);
75
+ return results;
52
76
  }
77
+ //#endregion
53
78
  exports.Semaphore = Semaphore;
54
- //# sourceMappingURL=concurrency.cjs.map
79
+ exports.mapConcurrent = mapConcurrent;
80
+
81
+ //# sourceMappingURL=concurrency.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"concurrency.cjs","sources":["../../src/upload/concurrency.ts"],"sourcesContent":["/**\n * Bounded concurrency primitive.\n *\n * Limits the number of concurrent operations to a fixed maximum. Callers\n * {@link acquire} a slot before starting work and {@link release} it when done.\n * If all slots are taken, `acquire` returns a promise that resolves when a slot\n * becomes available.\n */\nexport class Semaphore {\n private current = 0\n private readonly queue: (() => void)[] = []\n\n /**\n * @param limit - Maximum number of concurrent acquisitions. Must be a\n * positive integer; values `<= 0` would create a semaphore that\n * never lets anything through (all `acquire()` calls would queue\n * forever), so the constructor throws fast instead.\n *\n * @throws `RangeError` when `limit` is not a positive integer.\n */\n constructor(private readonly limit: number) {\n if (!Number.isInteger(limit) || limit <= 0) {\n throw new RangeError(\n `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`,\n )\n }\n }\n\n /**\n * Acquires a slot, waiting if the limit has been reached.\n * @returns A promise that resolves when a slot is available.\n */\n async acquire(): Promise<void> {\n if (this.current < this.limit) {\n this.current++\n return\n }\n return new Promise<void>((resolve) => {\n this.queue.push(resolve)\n })\n }\n\n /** Releases a slot, unblocking the next queued caller if any. */\n release(): void {\n const next = this.queue.shift()\n if (next) {\n next()\n } else {\n this.current--\n }\n }\n\n /**\n * Number of slots currently available.\n *\n * @returns The count of free concurrency slots.\n */\n get available(): number {\n return this.limit - this.current\n }\n}\n\n/**\n * Maps over an array with bounded concurrency.\n *\n * @param items - Input items to process.\n * @param concurrency - Maximum number of items processed in parallel.\n * @param fn - Async function applied to each item.\n *\n * @returns Results in the same order as the input items.\n */\nexport async function mapConcurrent<T, R>(\n items: readonly T[],\n concurrency: number,\n fn: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const sem = new Semaphore(concurrency)\n const results: R[] = new Array(items.length)\n const tasks = items.map(async (item, i) => {\n await sem.acquire()\n try {\n results[i] = await fn(item, i)\n } finally {\n sem.release()\n }\n })\n await Promise.all(tasks)\n return results\n}\n"],"names":[],"mappings":";;AAQO,MAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYrB,YAA6B,OAAe;AAAf,SAAA,QAAA;AAC3B,QAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GAAG;AAC1C,YAAM,IAAI;AAAA,QACR,wDAAwD,KAAK;AAAA,MAAA;AAAA,IAEjE;AAAA,EACF;AAAA,EAjBQ,UAAU;AAAA,EACD,QAAwB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBzC,MAAM,UAAyB;AAC7B,QAAI,KAAK,UAAU,KAAK,OAAO;AAC7B,WAAK;AACL;AAAA,IACF;AACA,WAAO,IAAI,QAAc,CAAC,YAAY;AACpC,WAAK,MAAM,KAAK,OAAO;AAAA,IACzB,CAAC;AAAA,EACH;AAAA;AAAA,EAGA,UAAgB;AACd,UAAM,OAAO,KAAK,MAAM,MAAA;AACxB,QAAI,MAAM;AACR,WAAA;AAAA,IACF,OAAO;AACL,WAAK;AAAA,IACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,YAAoB;AACtB,WAAO,KAAK,QAAQ,KAAK;AAAA,EAC3B;AACF;;"}
1
+ {"version":3,"file":"concurrency.cjs","names":[],"sources":["../../src/upload/concurrency.ts"],"sourcesContent":["/**\n * Bounded concurrency primitive.\n *\n * Limits the number of concurrent operations to a fixed maximum. Callers\n * {@link acquire} a slot before starting work and {@link release} it when done.\n * If all slots are taken, `acquire` returns a promise that resolves when a slot\n * becomes available.\n */\nexport class Semaphore {\n private current = 0\n private readonly queue: (() => void)[] = []\n\n /**\n * @param limit - Maximum number of concurrent acquisitions. Must be a\n * positive integer; values `<= 0` would create a semaphore that\n * never lets anything through (all `acquire()` calls would queue\n * forever), so the constructor throws fast instead.\n *\n * @throws `RangeError` when `limit` is not a positive integer.\n */\n constructor(private readonly limit: number) {\n if (!Number.isInteger(limit) || limit <= 0) {\n throw new RangeError(\n `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`,\n )\n }\n }\n\n /**\n * Acquires a slot, waiting if the limit has been reached.\n * @returns A promise that resolves when a slot is available.\n */\n async acquire(): Promise<void> {\n if (this.current < this.limit) {\n this.current++\n return\n }\n return new Promise<void>((resolve) => {\n this.queue.push(resolve)\n })\n }\n\n /** Releases a slot, unblocking the next queued caller if any. */\n release(): void {\n const next = this.queue.shift()\n if (next) {\n next()\n } else {\n this.current--\n }\n }\n\n /**\n * Number of slots currently available.\n *\n * @returns The count of free concurrency slots.\n */\n get available(): number {\n return this.limit - this.current\n }\n}\n\n/**\n * Maps over an array with bounded concurrency.\n *\n * @param items - Input items to process.\n * @param concurrency - Maximum number of items processed in parallel.\n * @param fn - Async function applied to each item.\n *\n * @returns Results in the same order as the input items.\n */\nexport async function mapConcurrent<T, R>(\n items: readonly T[],\n concurrency: number,\n fn: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const sem = new Semaphore(concurrency)\n const results: R[] = new Array(items.length)\n const tasks = items.map(async (item, i) => {\n await sem.acquire()\n try {\n results[i] = await fn(item, i)\n } finally {\n sem.release()\n }\n })\n await Promise.all(tasks)\n return results\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,YAAb,MAAuB;CAYQ;CAX7B,UAAkB;CAClB,QAAyC,CAAC;;;;;;;;;CAU1C,YAAY,OAAgC;EAAf,KAAA,QAAA;EAC3B,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GACvC,MAAM,IAAI,WACR,wDAAwD,MAAM,4FAChE;CAEJ;;;;;CAMA,MAAM,UAAyB;EAC7B,IAAI,KAAK,UAAU,KAAK,OAAO;GAC7B,KAAK;GACL;EACF;EACA,OAAO,IAAI,SAAe,YAAY;GACpC,KAAK,MAAM,KAAK,OAAO;EACzB,CAAC;CACH;;CAGA,UAAgB;EACd,MAAM,OAAO,KAAK,MAAM,MAAM;EAC9B,IAAI,MACF,KAAK;OAEL,KAAK;CAET;;;;;;CAOA,IAAI,YAAoB;EACtB,OAAO,KAAK,QAAQ,KAAK;CAC3B;AACF;;;;;;;;;;AAWA,eAAsB,cACpB,OACA,aACA,IACc;CACd,MAAM,MAAM,IAAI,UAAU,WAAW;CACrC,MAAM,UAAe,IAAI,MAAM,MAAM,MAAM;CAC3C,MAAM,QAAQ,MAAM,IAAI,OAAO,MAAM,MAAM;EACzC,MAAM,IAAI,QAAQ;EAClB,IAAI;GACF,QAAQ,KAAK,MAAM,GAAG,MAAM,CAAC;EAC/B,UAAU;GACR,IAAI,QAAQ;EACd;CACF,CAAC;CACD,MAAM,QAAQ,IAAI,KAAK;CACvB,OAAO;AACT"}
@@ -1,54 +1,80 @@
1
- class Semaphore {
2
- /**
3
- * @param limit - Maximum number of concurrent acquisitions. Must be a
4
- * positive integer; values `<= 0` would create a semaphore that
5
- * never lets anything through (all `acquire()` calls would queue
6
- * forever), so the constructor throws fast instead.
7
- *
8
- * @throws `RangeError` when `limit` is not a positive integer.
9
- */
10
- constructor(limit) {
11
- this.limit = limit;
12
- if (!Number.isInteger(limit) || limit <= 0) {
13
- throw new RangeError(
14
- `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`
15
- );
16
- }
17
- }
18
- current = 0;
19
- queue = [];
20
- /**
21
- * Acquires a slot, waiting if the limit has been reached.
22
- * @returns A promise that resolves when a slot is available.
23
- */
24
- async acquire() {
25
- if (this.current < this.limit) {
26
- this.current++;
27
- return;
28
- }
29
- return new Promise((resolve) => {
30
- this.queue.push(resolve);
31
- });
32
- }
33
- /** Releases a slot, unblocking the next queued caller if any. */
34
- release() {
35
- const next = this.queue.shift();
36
- if (next) {
37
- next();
38
- } else {
39
- this.current--;
40
- }
41
- }
42
- /**
43
- * Number of slots currently available.
44
- *
45
- * @returns The count of free concurrency slots.
46
- */
47
- get available() {
48
- return this.limit - this.current;
49
- }
50
- }
51
- export {
52
- Semaphore
1
+ //#region src/upload/concurrency.ts
2
+ /**
3
+ * Bounded concurrency primitive.
4
+ *
5
+ * Limits the number of concurrent operations to a fixed maximum. Callers
6
+ * {@link acquire} a slot before starting work and {@link release} it when done.
7
+ * If all slots are taken, `acquire` returns a promise that resolves when a slot
8
+ * becomes available.
9
+ */
10
+ var Semaphore = class {
11
+ limit;
12
+ current = 0;
13
+ queue = [];
14
+ /**
15
+ * @param limit - Maximum number of concurrent acquisitions. Must be a
16
+ * positive integer; values `<= 0` would create a semaphore that
17
+ * never lets anything through (all `acquire()` calls would queue
18
+ * forever), so the constructor throws fast instead.
19
+ *
20
+ * @throws `RangeError` when `limit` is not a positive integer.
21
+ */
22
+ constructor(limit) {
23
+ this.limit = limit;
24
+ if (!Number.isInteger(limit) || limit <= 0) throw new RangeError(`Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`);
25
+ }
26
+ /**
27
+ * Acquires a slot, waiting if the limit has been reached.
28
+ * @returns A promise that resolves when a slot is available.
29
+ */
30
+ async acquire() {
31
+ if (this.current < this.limit) {
32
+ this.current++;
33
+ return;
34
+ }
35
+ return new Promise((resolve) => {
36
+ this.queue.push(resolve);
37
+ });
38
+ }
39
+ /** Releases a slot, unblocking the next queued caller if any. */
40
+ release() {
41
+ const next = this.queue.shift();
42
+ if (next) next();
43
+ else this.current--;
44
+ }
45
+ /**
46
+ * Number of slots currently available.
47
+ *
48
+ * @returns The count of free concurrency slots.
49
+ */
50
+ get available() {
51
+ return this.limit - this.current;
52
+ }
53
53
  };
54
- //# sourceMappingURL=concurrency.js.map
54
+ /**
55
+ * Maps over an array with bounded concurrency.
56
+ *
57
+ * @param items - Input items to process.
58
+ * @param concurrency - Maximum number of items processed in parallel.
59
+ * @param fn - Async function applied to each item.
60
+ *
61
+ * @returns Results in the same order as the input items.
62
+ */
63
+ async function mapConcurrent(items, concurrency, fn) {
64
+ const sem = new Semaphore(concurrency);
65
+ const results = new Array(items.length);
66
+ const tasks = items.map(async (item, i) => {
67
+ await sem.acquire();
68
+ try {
69
+ results[i] = await fn(item, i);
70
+ } finally {
71
+ sem.release();
72
+ }
73
+ });
74
+ await Promise.all(tasks);
75
+ return results;
76
+ }
77
+ //#endregion
78
+ export { Semaphore, mapConcurrent };
79
+
80
+ //# sourceMappingURL=concurrency.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"concurrency.js","sources":["../../src/upload/concurrency.ts"],"sourcesContent":["/**\n * Bounded concurrency primitive.\n *\n * Limits the number of concurrent operations to a fixed maximum. Callers\n * {@link acquire} a slot before starting work and {@link release} it when done.\n * If all slots are taken, `acquire` returns a promise that resolves when a slot\n * becomes available.\n */\nexport class Semaphore {\n private current = 0\n private readonly queue: (() => void)[] = []\n\n /**\n * @param limit - Maximum number of concurrent acquisitions. Must be a\n * positive integer; values `<= 0` would create a semaphore that\n * never lets anything through (all `acquire()` calls would queue\n * forever), so the constructor throws fast instead.\n *\n * @throws `RangeError` when `limit` is not a positive integer.\n */\n constructor(private readonly limit: number) {\n if (!Number.isInteger(limit) || limit <= 0) {\n throw new RangeError(\n `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`,\n )\n }\n }\n\n /**\n * Acquires a slot, waiting if the limit has been reached.\n * @returns A promise that resolves when a slot is available.\n */\n async acquire(): Promise<void> {\n if (this.current < this.limit) {\n this.current++\n return\n }\n return new Promise<void>((resolve) => {\n this.queue.push(resolve)\n })\n }\n\n /** Releases a slot, unblocking the next queued caller if any. */\n release(): void {\n const next = this.queue.shift()\n if (next) {\n next()\n } else {\n this.current--\n }\n }\n\n /**\n * Number of slots currently available.\n *\n * @returns The count of free concurrency slots.\n */\n get available(): number {\n return this.limit - this.current\n }\n}\n\n/**\n * Maps over an array with bounded concurrency.\n *\n * @param items - Input items to process.\n * @param concurrency - Maximum number of items processed in parallel.\n * @param fn - Async function applied to each item.\n *\n * @returns Results in the same order as the input items.\n */\nexport async function mapConcurrent<T, R>(\n items: readonly T[],\n concurrency: number,\n fn: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const sem = new Semaphore(concurrency)\n const results: R[] = new Array(items.length)\n const tasks = items.map(async (item, i) => {\n await sem.acquire()\n try {\n results[i] = await fn(item, i)\n } finally {\n sem.release()\n }\n })\n await Promise.all(tasks)\n return results\n}\n"],"names":[],"mappings":"AAQO,MAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYrB,YAA6B,OAAe;AAAf,SAAA,QAAA;AAC3B,QAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GAAG;AAC1C,YAAM,IAAI;AAAA,QACR,wDAAwD,KAAK;AAAA,MAAA;AAAA,IAEjE;AAAA,EACF;AAAA,EAjBQ,UAAU;AAAA,EACD,QAAwB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBzC,MAAM,UAAyB;AAC7B,QAAI,KAAK,UAAU,KAAK,OAAO;AAC7B,WAAK;AACL;AAAA,IACF;AACA,WAAO,IAAI,QAAc,CAAC,YAAY;AACpC,WAAK,MAAM,KAAK,OAAO;AAAA,IACzB,CAAC;AAAA,EACH;AAAA;AAAA,EAGA,UAAgB;AACd,UAAM,OAAO,KAAK,MAAM,MAAA;AACxB,QAAI,MAAM;AACR,WAAA;AAAA,IACF,OAAO;AACL,WAAK;AAAA,IACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,YAAoB;AACtB,WAAO,KAAK,QAAQ,KAAK;AAAA,EAC3B;AACF;"}
1
+ {"version":3,"file":"concurrency.js","names":[],"sources":["../../src/upload/concurrency.ts"],"sourcesContent":["/**\n * Bounded concurrency primitive.\n *\n * Limits the number of concurrent operations to a fixed maximum. Callers\n * {@link acquire} a slot before starting work and {@link release} it when done.\n * If all slots are taken, `acquire` returns a promise that resolves when a slot\n * becomes available.\n */\nexport class Semaphore {\n private current = 0\n private readonly queue: (() => void)[] = []\n\n /**\n * @param limit - Maximum number of concurrent acquisitions. Must be a\n * positive integer; values `<= 0` would create a semaphore that\n * never lets anything through (all `acquire()` calls would queue\n * forever), so the constructor throws fast instead.\n *\n * @throws `RangeError` when `limit` is not a positive integer.\n */\n constructor(private readonly limit: number) {\n if (!Number.isInteger(limit) || limit <= 0) {\n throw new RangeError(\n `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`,\n )\n }\n }\n\n /**\n * Acquires a slot, waiting if the limit has been reached.\n * @returns A promise that resolves when a slot is available.\n */\n async acquire(): Promise<void> {\n if (this.current < this.limit) {\n this.current++\n return\n }\n return new Promise<void>((resolve) => {\n this.queue.push(resolve)\n })\n }\n\n /** Releases a slot, unblocking the next queued caller if any. */\n release(): void {\n const next = this.queue.shift()\n if (next) {\n next()\n } else {\n this.current--\n }\n }\n\n /**\n * Number of slots currently available.\n *\n * @returns The count of free concurrency slots.\n */\n get available(): number {\n return this.limit - this.current\n }\n}\n\n/**\n * Maps over an array with bounded concurrency.\n *\n * @param items - Input items to process.\n * @param concurrency - Maximum number of items processed in parallel.\n * @param fn - Async function applied to each item.\n *\n * @returns Results in the same order as the input items.\n */\nexport async function mapConcurrent<T, R>(\n items: readonly T[],\n concurrency: number,\n fn: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const sem = new Semaphore(concurrency)\n const results: R[] = new Array(items.length)\n const tasks = items.map(async (item, i) => {\n await sem.acquire()\n try {\n results[i] = await fn(item, i)\n } finally {\n sem.release()\n }\n })\n await Promise.all(tasks)\n return results\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,YAAb,MAAuB;CAYQ;CAX7B,UAAkB;CAClB,QAAyC,CAAC;;;;;;;;;CAU1C,YAAY,OAAgC;EAAf,KAAA,QAAA;EAC3B,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GACvC,MAAM,IAAI,WACR,wDAAwD,MAAM,4FAChE;CAEJ;;;;;CAMA,MAAM,UAAyB;EAC7B,IAAI,KAAK,UAAU,KAAK,OAAO;GAC7B,KAAK;GACL;EACF;EACA,OAAO,IAAI,SAAe,YAAY;GACpC,KAAK,MAAM,KAAK,OAAO;EACzB,CAAC;CACH;;CAGA,UAAgB;EACd,MAAM,OAAO,KAAK,MAAM,MAAM;EAC9B,IAAI,MACF,KAAK;OAEL,KAAK;CAET;;;;;;CAOA,IAAI,YAAoB;EACtB,OAAO,KAAK,QAAQ,KAAK;CAC3B;AACF;;;;;;;;;;AAWA,eAAsB,cACpB,OACA,aACA,IACc;CACd,MAAM,MAAM,IAAI,UAAU,WAAW;CACrC,MAAM,UAAe,IAAI,MAAM,MAAM,MAAM;CAC3C,MAAM,QAAQ,MAAM,IAAI,OAAO,MAAM,MAAM;EACzC,MAAM,IAAI,QAAQ;EAClB,IAAI;GACF,QAAQ,KAAK,MAAM,GAAG,MAAM,CAAC;EAC/B,UAAU;GACR,IAAI,QAAQ;EACd;CACF,CAAC;CACD,MAAM,QAAQ,IAAI,KAAK;CACvB,OAAO;AACT"}
@@ -0,0 +1,59 @@
1
+ const require_errors_index = require("../errors/index.cjs");
2
+ //#region src/upload/finish.ts
3
+ /**
4
+ * Calls `b2_finish_large_file` and classifies failures after dispatch that can
5
+ * hide an already-committed file as ambiguous finish failures.
6
+ *
7
+ * @param raw - Low-level B2 API client.
8
+ * @param accountInfo - Authorized account state.
9
+ * @param context - Finish request data and reconciliation metadata.
10
+ *
11
+ * @returns The completed file version metadata.
12
+ */
13
+ async function finishLargeFileWithAbortReconciliation(raw, accountInfo, context) {
14
+ context.signal?.throwIfAborted();
15
+ try {
16
+ return await raw.finishLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {
17
+ fileId: context.fileId,
18
+ partSha1Array: context.partSha1s
19
+ }, context.signal === void 0 && context.retry === void 0 ? void 0 : {
20
+ ...context.signal !== void 0 ? { signal: context.signal } : {},
21
+ ...context.retry !== void 0 ? { retry: context.retry } : {}
22
+ });
23
+ } catch (err) {
24
+ if (err instanceof require_errors_index.FinishLargeFileResponseBodyError) throw finishLargeFileResponseBodyErrorWithContext(err, context);
25
+ if (isAmbiguousFinishDispatchFailure(err, context.signal)) throw new require_errors_index.FinishLargeFileResponseBodyError("b2_finish_large_file failed after dispatch; final file state is ambiguous.", {
26
+ cause: err,
27
+ fileId: context.fileId,
28
+ bucketId: context.bucketId,
29
+ fileName: context.fileName
30
+ });
31
+ throw err;
32
+ }
33
+ }
34
+ function finishLargeFileResponseBodyErrorWithContext(err, context) {
35
+ if (err.fileId === context.fileId && err.bucketId === context.bucketId && err.fileName === context.fileName) return err;
36
+ return new require_errors_index.FinishLargeFileResponseBodyError(err.message, {
37
+ cause: err.cause ?? err,
38
+ fileId: context.fileId,
39
+ bucketId: context.bucketId,
40
+ fileName: context.fileName
41
+ });
42
+ }
43
+ function isAmbiguousFinishDispatchFailure(err, signal) {
44
+ if (err instanceof require_errors_index.NetworkError) return true;
45
+ if (isTimeoutError(err)) return true;
46
+ if (signal?.aborted !== true) return false;
47
+ if (signal.reason !== void 0 && Object.is(err, signal.reason)) return true;
48
+ return isAbortError(err);
49
+ }
50
+ function isAbortError(err) {
51
+ return err instanceof DOMException && err.name === "AbortError" || err instanceof Error && err.name === "AbortError";
52
+ }
53
+ function isTimeoutError(err) {
54
+ return err instanceof DOMException && err.name === "TimeoutError" || err instanceof Error && err.name === "TimeoutError";
55
+ }
56
+ //#endregion
57
+ exports.finishLargeFileWithAbortReconciliation = finishLargeFileWithAbortReconciliation;
58
+
59
+ //# sourceMappingURL=finish.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finish.cjs","names":[],"sources":["../../src/upload/finish.ts"],"sourcesContent":["import type { AccountInfo } from '../auth/account-info.ts'\nimport { FinishLargeFileResponseBodyError, NetworkError } from '../errors/index.ts'\nimport type { RetryOptions } from '../http/retry.ts'\nimport type { RawClient } from '../raw/index.ts'\nimport type { FileVersion } from '../types/file.ts'\nimport type { BucketId, LargeFileId } from '../types/ids.ts'\n\n/** Context for safely finalizing a large file. */\nexport interface FinishLargeFileContext {\n readonly fileId: LargeFileId\n readonly bucketId: BucketId\n readonly fileName: string\n readonly partSha1s: readonly string[]\n readonly signal?: AbortSignal\n readonly retry?: Partial<RetryOptions>\n}\n\n/**\n * Calls `b2_finish_large_file` and classifies failures after dispatch that can\n * hide an already-committed file as ambiguous finish failures.\n *\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state.\n * @param context - Finish request data and reconciliation metadata.\n *\n * @returns The completed file version metadata.\n */\nexport async function finishLargeFileWithAbortReconciliation(\n raw: RawClient,\n accountInfo: AccountInfo,\n context: FinishLargeFileContext,\n): Promise<FileVersion> {\n context.signal?.throwIfAborted()\n try {\n return await raw.finishLargeFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n {\n fileId: context.fileId,\n partSha1Array: context.partSha1s,\n },\n context.signal === undefined && context.retry === undefined\n ? undefined\n : {\n ...(context.signal !== undefined ? { signal: context.signal } : {}),\n ...(context.retry !== undefined ? { retry: context.retry } : {}),\n },\n )\n } catch (err) {\n if (err instanceof FinishLargeFileResponseBodyError) {\n throw finishLargeFileResponseBodyErrorWithContext(err, context)\n }\n if (isAmbiguousFinishDispatchFailure(err, context.signal)) {\n throw new FinishLargeFileResponseBodyError(\n 'b2_finish_large_file failed after dispatch; final file state is ambiguous.',\n {\n cause: err,\n fileId: context.fileId,\n bucketId: context.bucketId,\n fileName: context.fileName,\n },\n )\n }\n throw err\n }\n}\n\nfunction finishLargeFileResponseBodyErrorWithContext(\n err: FinishLargeFileResponseBodyError,\n context: FinishLargeFileContext,\n): FinishLargeFileResponseBodyError {\n if (\n err.fileId === context.fileId &&\n err.bucketId === context.bucketId &&\n err.fileName === context.fileName\n ) {\n return err\n }\n return new FinishLargeFileResponseBodyError(err.message, {\n cause: err.cause ?? err,\n fileId: context.fileId,\n bucketId: context.bucketId,\n fileName: context.fileName,\n })\n}\n\nfunction isAmbiguousFinishDispatchFailure(err: unknown, signal: AbortSignal | undefined): boolean {\n if (err instanceof NetworkError) return true\n if (isTimeoutError(err)) return true\n if (signal?.aborted !== true) return false\n if (signal.reason !== undefined && Object.is(err, signal.reason)) return true\n return isAbortError(err)\n}\n\nfunction isAbortError(err: unknown): boolean {\n return (\n (err instanceof DOMException && err.name === 'AbortError') ||\n (err instanceof Error && err.name === 'AbortError')\n )\n}\n\nfunction isTimeoutError(err: unknown): boolean {\n return (\n (err instanceof DOMException && err.name === 'TimeoutError') ||\n (err instanceof Error && err.name === 'TimeoutError')\n )\n}\n"],"mappings":";;;;;;;;;;;;AA2BA,eAAsB,uCACpB,KACA,aACA,SACsB;CACtB,QAAQ,QAAQ,eAAe;CAC/B,IAAI;EACF,OAAO,MAAM,IAAI,gBACf,YAAY,UAAU,GACtB,YAAY,aAAa,GACzB;GACE,QAAQ,QAAQ;GAChB,eAAe,QAAQ;EACzB,GACA,QAAQ,WAAW,KAAA,KAAa,QAAQ,UAAU,KAAA,IAC9C,KAAA,IACA;GACE,GAAI,QAAQ,WAAW,KAAA,IAAY,EAAE,QAAQ,QAAQ,OAAO,IAAI,CAAC;GACjE,GAAI,QAAQ,UAAU,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,IAAI,CAAC;EAChE,CACN;CACF,SAAS,KAAK;EACZ,IAAI,eAAe,qBAAA,kCACjB,MAAM,4CAA4C,KAAK,OAAO;EAEhE,IAAI,iCAAiC,KAAK,QAAQ,MAAM,GACtD,MAAM,IAAI,qBAAA,iCACR,8E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