@backblaze-labs/b2-sdk 0.2.0 → 0.4.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 (590) hide show
  1. package/CHANGELOG.md +86 -1
  2. package/README.md +38 -7
  3. package/dist/_virtual/_b2-sdk-version-json.cjs +1 -1
  4. package/dist/_virtual/_b2-sdk-version-json.js +1 -1
  5. package/dist/auth/file.cjs.map +1 -1
  6. package/dist/auth/reauth-coalescer.cjs +65 -0
  7. package/dist/auth/reauth-coalescer.cjs.map +1 -0
  8. package/dist/auth/reauth-coalescer.d.cts +34 -0
  9. package/dist/auth/reauth-coalescer.d.cts.map +1 -0
  10. package/dist/auth/reauth-coalescer.d.ts +34 -0
  11. package/dist/auth/reauth-coalescer.d.ts.map +1 -0
  12. package/dist/auth/reauth-coalescer.js +65 -0
  13. package/dist/auth/reauth-coalescer.js.map +1 -0
  14. package/dist/backup/client.cjs +206 -0
  15. package/dist/backup/client.cjs.map +1 -0
  16. package/dist/backup/client.d.cts +238 -0
  17. package/dist/backup/client.d.cts.map +1 -0
  18. package/dist/backup/client.d.ts +238 -0
  19. package/dist/backup/client.d.ts.map +1 -0
  20. package/dist/backup/client.js +206 -0
  21. package/dist/backup/client.js.map +1 -0
  22. package/dist/backup/index.cjs +15 -0
  23. package/dist/backup/index.d.cts +22 -0
  24. package/dist/backup/index.d.cts.map +1 -0
  25. package/dist/backup/index.d.ts +22 -0
  26. package/dist/backup/index.d.ts.map +1 -0
  27. package/dist/backup/index.js +7 -0
  28. package/dist/backup/raw.cjs +168 -0
  29. package/dist/backup/raw.cjs.map +1 -0
  30. package/dist/backup/raw.d.cts +122 -0
  31. package/dist/backup/raw.d.cts.map +1 -0
  32. package/dist/backup/raw.d.ts +122 -0
  33. package/dist/backup/raw.d.ts.map +1 -0
  34. package/dist/backup/raw.js +168 -0
  35. package/dist/backup/raw.js.map +1 -0
  36. package/dist/bucket-validation.cjs +111 -0
  37. package/dist/bucket-validation.cjs.map +1 -0
  38. package/dist/bucket-validation.d.cts +27 -0
  39. package/dist/bucket-validation.d.cts.map +1 -0
  40. package/dist/bucket-validation.d.ts +27 -0
  41. package/dist/bucket-validation.d.ts.map +1 -0
  42. package/dist/bucket-validation.js +109 -0
  43. package/dist/bucket-validation.js.map +1 -0
  44. package/dist/bucket.cjs +125 -74
  45. package/dist/bucket.cjs.map +1 -1
  46. package/dist/bucket.d.cts +156 -61
  47. package/dist/bucket.d.cts.map +1 -1
  48. package/dist/bucket.d.ts +156 -61
  49. package/dist/bucket.d.ts.map +1 -1
  50. package/dist/bucket.js +125 -74
  51. package/dist/bucket.js.map +1 -1
  52. package/dist/client.cjs +29 -8
  53. package/dist/client.cjs.map +1 -1
  54. package/dist/client.d.cts +30 -9
  55. package/dist/client.d.cts.map +1 -1
  56. package/dist/client.d.ts +30 -9
  57. package/dist/client.d.ts.map +1 -1
  58. package/dist/client.js +29 -8
  59. package/dist/client.js.map +1 -1
  60. package/dist/copy/large.cjs +5 -3
  61. package/dist/copy/large.cjs.map +1 -1
  62. package/dist/copy/large.d.cts.map +1 -1
  63. package/dist/copy/large.d.ts.map +1 -1
  64. package/dist/copy/large.js +5 -3
  65. package/dist/copy/large.js.map +1 -1
  66. package/dist/download/checksum.cjs +6 -2
  67. package/dist/download/checksum.cjs.map +1 -1
  68. package/dist/download/checksum.js +6 -2
  69. package/dist/download/checksum.js.map +1 -1
  70. package/dist/download/parallel.cjs +52 -15
  71. package/dist/download/parallel.cjs.map +1 -1
  72. package/dist/download/parallel.d.cts +8 -1
  73. package/dist/download/parallel.d.cts.map +1 -1
  74. package/dist/download/parallel.d.ts +8 -1
  75. package/dist/download/parallel.d.ts.map +1 -1
  76. package/dist/download/parallel.js +52 -15
  77. package/dist/download/parallel.js.map +1 -1
  78. package/dist/download/single.cjs +179 -19
  79. package/dist/download/single.cjs.map +1 -1
  80. package/dist/download/single.d.cts +10 -4
  81. package/dist/download/single.d.cts.map +1 -1
  82. package/dist/download/single.d.ts +10 -4
  83. package/dist/download/single.d.ts.map +1 -1
  84. package/dist/download/single.js +179 -19
  85. package/dist/download/single.js.map +1 -1
  86. package/dist/errors/index.cjs +196 -3
  87. package/dist/errors/index.cjs.map +1 -1
  88. package/dist/errors/index.d.cts +134 -0
  89. package/dist/errors/index.d.cts.map +1 -1
  90. package/dist/errors/index.d.ts +134 -0
  91. package/dist/errors/index.d.ts.map +1 -1
  92. package/dist/errors/index.js +183 -4
  93. package/dist/errors/index.js.map +1 -1
  94. package/dist/http/non-idempotent-mutations.cjs +38 -0
  95. package/dist/http/non-idempotent-mutations.cjs.map +1 -0
  96. package/dist/http/non-idempotent-mutations.d.cts +25 -0
  97. package/dist/http/non-idempotent-mutations.d.cts.map +1 -0
  98. package/dist/http/non-idempotent-mutations.d.ts +25 -0
  99. package/dist/http/non-idempotent-mutations.d.ts.map +1 -0
  100. package/dist/http/non-idempotent-mutations.js +35 -0
  101. package/dist/http/non-idempotent-mutations.js.map +1 -0
  102. package/dist/http/retry.cjs +1 -1
  103. package/dist/http/retry.cjs.map +1 -1
  104. package/dist/http/retry.js +1 -1
  105. package/dist/http/retry.js.map +1 -1
  106. package/dist/http/transport.cjs +62 -23
  107. package/dist/http/transport.cjs.map +1 -1
  108. package/dist/http/transport.d.cts +30 -3
  109. package/dist/http/transport.d.cts.map +1 -1
  110. package/dist/http/transport.d.ts +30 -3
  111. package/dist/http/transport.d.ts.map +1 -1
  112. package/dist/http/transport.js +60 -22
  113. package/dist/http/transport.js.map +1 -1
  114. package/dist/http/user-agent.cjs +12 -1
  115. package/dist/http/user-agent.cjs.map +1 -1
  116. package/dist/http/user-agent.d.cts +8 -0
  117. package/dist/http/user-agent.d.cts.map +1 -1
  118. package/dist/http/user-agent.d.ts +8 -0
  119. package/dist/http/user-agent.d.ts.map +1 -1
  120. package/dist/http/user-agent.js +13 -3
  121. package/dist/http/user-agent.js.map +1 -1
  122. package/dist/index.cjs +50 -2
  123. package/dist/index.d.cts +15 -12
  124. package/dist/index.d.cts.map +1 -1
  125. package/dist/index.d.ts +15 -12
  126. package/dist/index.d.ts.map +1 -1
  127. package/dist/index.js +13 -10
  128. package/dist/notifications/index.cjs +3 -0
  129. package/dist/notifications/index.d.cts +2 -0
  130. package/dist/notifications/index.d.cts.map +1 -1
  131. package/dist/notifications/index.d.ts +2 -0
  132. package/dist/notifications/index.d.ts.map +1 -1
  133. package/dist/notifications/index.js +2 -1
  134. package/dist/object.cjs +13 -2
  135. package/dist/object.cjs.map +1 -1
  136. package/dist/object.d.cts +11 -3
  137. package/dist/object.d.cts.map +1 -1
  138. package/dist/object.d.ts +11 -3
  139. package/dist/object.d.ts.map +1 -1
  140. package/dist/object.js +13 -2
  141. package/dist/object.js.map +1 -1
  142. package/dist/partner/account-info.d.cts +43 -0
  143. package/dist/partner/account-info.d.cts.map +1 -0
  144. package/dist/partner/account-info.d.ts +43 -0
  145. package/dist/partner/account-info.d.ts.map +1 -0
  146. package/dist/partner/auth-clone.cjs +64 -0
  147. package/dist/partner/auth-clone.cjs.map +1 -0
  148. package/dist/partner/auth-clone.d.cts +27 -0
  149. package/dist/partner/auth-clone.d.cts.map +1 -0
  150. package/dist/partner/auth-clone.d.ts +27 -0
  151. package/dist/partner/auth-clone.d.ts.map +1 -0
  152. package/dist/partner/auth-clone.js +63 -0
  153. package/dist/partner/auth-clone.js.map +1 -0
  154. package/dist/partner/auth-core.cjs +156 -0
  155. package/dist/partner/auth-core.cjs.map +1 -0
  156. package/dist/partner/auth-core.d.cts +111 -0
  157. package/dist/partner/auth-core.d.cts.map +1 -0
  158. package/dist/partner/auth-core.d.ts +111 -0
  159. package/dist/partner/auth-core.d.ts.map +1 -0
  160. package/dist/partner/auth-core.js +156 -0
  161. package/dist/partner/auth-core.js.map +1 -0
  162. package/dist/partner/auth-shape.cjs +36 -0
  163. package/dist/partner/auth-shape.cjs.map +1 -0
  164. package/dist/partner/auth-shape.d.cts +12 -0
  165. package/dist/partner/auth-shape.d.cts.map +1 -0
  166. package/dist/partner/auth-shape.d.ts +12 -0
  167. package/dist/partner/auth-shape.d.ts.map +1 -0
  168. package/dist/partner/auth-shape.js +36 -0
  169. package/dist/partner/auth-shape.js.map +1 -0
  170. package/dist/partner/client.cjs +270 -0
  171. package/dist/partner/client.cjs.map +1 -0
  172. package/dist/partner/client.d.cts +357 -0
  173. package/dist/partner/client.d.cts.map +1 -0
  174. package/dist/partner/client.d.ts +357 -0
  175. package/dist/partner/client.d.ts.map +1 -0
  176. package/dist/partner/client.js +270 -0
  177. package/dist/partner/client.js.map +1 -0
  178. package/dist/partner/endpoint-url.cjs +109 -0
  179. package/dist/partner/endpoint-url.cjs.map +1 -0
  180. package/dist/partner/endpoint-url.d.cts +74 -0
  181. package/dist/partner/endpoint-url.d.cts.map +1 -0
  182. package/dist/partner/endpoint-url.d.ts +74 -0
  183. package/dist/partner/endpoint-url.d.ts.map +1 -0
  184. package/dist/partner/endpoint-url.js +106 -0
  185. package/dist/partner/endpoint-url.js.map +1 -0
  186. package/dist/partner/in-memory.cjs +135 -0
  187. package/dist/partner/in-memory.cjs.map +1 -0
  188. package/dist/partner/in-memory.d.cts +99 -0
  189. package/dist/partner/in-memory.d.cts.map +1 -0
  190. package/dist/partner/in-memory.d.ts +99 -0
  191. package/dist/partner/in-memory.d.ts.map +1 -0
  192. package/dist/partner/in-memory.js +135 -0
  193. package/dist/partner/in-memory.js.map +1 -0
  194. package/dist/partner/index.cjs +27 -0
  195. package/dist/partner/index.d.cts +32 -0
  196. package/dist/partner/index.d.cts.map +1 -0
  197. package/dist/partner/index.d.ts +32 -0
  198. package/dist/partner/index.d.ts.map +1 -0
  199. package/dist/partner/index.js +9 -0
  200. package/dist/partner/raw.cjs +400 -0
  201. package/dist/partner/raw.cjs.map +1 -0
  202. package/dist/partner/raw.d.cts +220 -0
  203. package/dist/partner/raw.d.cts.map +1 -0
  204. package/dist/partner/raw.d.ts +220 -0
  205. package/dist/partner/raw.d.ts.map +1 -0
  206. package/dist/partner/raw.js +398 -0
  207. package/dist/partner/raw.js.map +1 -0
  208. package/dist/partner/redaction-placeholders.cjs +10 -0
  209. package/dist/partner/redaction-placeholders.cjs.map +1 -0
  210. package/dist/partner/redaction-placeholders.d.cts +5 -0
  211. package/dist/partner/redaction-placeholders.d.cts.map +1 -0
  212. package/dist/partner/redaction-placeholders.d.ts +5 -0
  213. package/dist/partner/redaction-placeholders.d.ts.map +1 -0
  214. package/dist/partner/redaction-placeholders.js +9 -0
  215. package/dist/partner/redaction-placeholders.js.map +1 -0
  216. package/dist/partner/redaction.cjs +292 -0
  217. package/dist/partner/redaction.cjs.map +1 -0
  218. package/dist/partner/redaction.d.cts +158 -0
  219. package/dist/partner/redaction.d.cts.map +1 -0
  220. package/dist/partner/redaction.d.ts +158 -0
  221. package/dist/partner/redaction.d.ts.map +1 -0
  222. package/dist/partner/redaction.js +281 -0
  223. package/dist/partner/redaction.js.map +1 -0
  224. package/dist/raw/encoding.cjs +29 -10
  225. package/dist/raw/encoding.cjs.map +1 -1
  226. package/dist/raw/encoding.d.cts +3 -2
  227. package/dist/raw/encoding.d.cts.map +1 -1
  228. package/dist/raw/encoding.d.ts +3 -2
  229. package/dist/raw/encoding.d.ts.map +1 -1
  230. package/dist/raw/encoding.js +29 -10
  231. package/dist/raw/encoding.js.map +1 -1
  232. package/dist/raw/index.cjs +131 -44
  233. package/dist/raw/index.cjs.map +1 -1
  234. package/dist/raw/index.d.cts +21 -15
  235. package/dist/raw/index.d.cts.map +1 -1
  236. package/dist/raw/index.d.ts +21 -15
  237. package/dist/raw/index.d.ts.map +1 -1
  238. package/dist/raw/index.js +114 -45
  239. package/dist/raw/index.js.map +1 -1
  240. package/dist/raw/url.cjs +111 -0
  241. package/dist/raw/url.cjs.map +1 -0
  242. package/dist/raw/url.d.cts +41 -0
  243. package/dist/raw/url.d.cts.map +1 -0
  244. package/dist/raw/url.d.ts +41 -0
  245. package/dist/raw/url.d.ts.map +1 -0
  246. package/dist/raw/url.js +110 -0
  247. package/dist/raw/url.js.map +1 -0
  248. package/dist/s3/sigv4.cjs +15 -10
  249. package/dist/s3/sigv4.cjs.map +1 -1
  250. package/dist/s3/sigv4.js +15 -10
  251. package/dist/s3/sigv4.js.map +1 -1
  252. package/dist/simulator/index.cjs +1579 -257
  253. package/dist/simulator/index.cjs.map +1 -1
  254. package/dist/simulator/index.d.cts +124 -11
  255. package/dist/simulator/index.d.cts.map +1 -1
  256. package/dist/simulator/index.d.ts +124 -11
  257. package/dist/simulator/index.d.ts.map +1 -1
  258. package/dist/simulator/index.js +1568 -262
  259. package/dist/simulator/index.js.map +1 -1
  260. package/dist/simulator/partner-capabilities.cjs +77 -0
  261. package/dist/simulator/partner-capabilities.cjs.map +1 -0
  262. package/dist/simulator/partner-capabilities.d.cts +53 -0
  263. package/dist/simulator/partner-capabilities.d.cts.map +1 -0
  264. package/dist/simulator/partner-capabilities.d.ts +53 -0
  265. package/dist/simulator/partner-capabilities.d.ts.map +1 -0
  266. package/dist/simulator/partner-capabilities.js +73 -0
  267. package/dist/simulator/partner-capabilities.js.map +1 -0
  268. package/dist/simulator/partner.cjs +713 -0
  269. package/dist/simulator/partner.cjs.map +1 -0
  270. package/dist/simulator/partner.d.cts +186 -0
  271. package/dist/simulator/partner.d.cts.map +1 -0
  272. package/dist/simulator/partner.d.ts +186 -0
  273. package/dist/simulator/partner.d.ts.map +1 -0
  274. package/dist/simulator/partner.js +713 -0
  275. package/dist/simulator/partner.js.map +1 -0
  276. package/dist/simulator/validation.cjs +732 -25
  277. package/dist/simulator/validation.cjs.map +1 -1
  278. package/dist/simulator/validation.d.cts +145 -6
  279. package/dist/simulator/validation.d.cts.map +1 -1
  280. package/dist/simulator/validation.d.ts +145 -6
  281. package/dist/simulator/validation.d.ts.map +1 -1
  282. package/dist/simulator/validation.js +705 -26
  283. package/dist/simulator/validation.js.map +1 -1
  284. package/dist/streams/file-source.cjs +2 -2
  285. package/dist/streams/file-source.cjs.map +1 -1
  286. package/dist/streams/file-source.js +2 -2
  287. package/dist/streams/file-source.js.map +1 -1
  288. package/dist/streams/hash.cjs +246 -13
  289. package/dist/streams/hash.cjs.map +1 -1
  290. package/dist/streams/hash.d.cts +37 -12
  291. package/dist/streams/hash.d.cts.map +1 -1
  292. package/dist/streams/hash.d.ts +37 -12
  293. package/dist/streams/hash.d.ts.map +1 -1
  294. package/dist/streams/hash.js +246 -15
  295. package/dist/streams/hash.js.map +1 -1
  296. package/dist/streams/index.cjs +3 -1
  297. package/dist/streams/index.d.cts +1 -1
  298. package/dist/streams/index.d.cts.map +1 -1
  299. package/dist/streams/index.d.ts +1 -1
  300. package/dist/streams/index.d.ts.map +1 -1
  301. package/dist/streams/index.js +3 -3
  302. package/dist/streams/progress.cjs +63 -4
  303. package/dist/streams/progress.cjs.map +1 -1
  304. package/dist/streams/progress.d.cts +28 -2
  305. package/dist/streams/progress.d.cts.map +1 -1
  306. package/dist/streams/progress.d.ts +28 -2
  307. package/dist/streams/progress.d.ts.map +1 -1
  308. package/dist/streams/progress.js +63 -4
  309. package/dist/streams/progress.js.map +1 -1
  310. package/dist/streams/source.cjs +2 -1
  311. package/dist/streams/source.cjs.map +1 -1
  312. package/dist/streams/source.js +2 -1
  313. package/dist/streams/source.js.map +1 -1
  314. package/dist/sync/b2-sha1-reader.cjs +6 -2
  315. package/dist/sync/b2-sha1-reader.cjs.map +1 -1
  316. package/dist/sync/b2-sha1-reader.d.cts.map +1 -1
  317. package/dist/sync/b2-sha1-reader.d.ts.map +1 -1
  318. package/dist/sync/b2-sha1-reader.js +6 -2
  319. package/dist/sync/b2-sha1-reader.js.map +1 -1
  320. package/dist/sync/download-staging.cjs +156 -43
  321. package/dist/sync/download-staging.cjs.map +1 -1
  322. package/dist/sync/download-staging.d.cts +26 -2
  323. package/dist/sync/download-staging.d.cts.map +1 -1
  324. package/dist/sync/download-staging.d.ts +26 -2
  325. package/dist/sync/download-staging.d.ts.map +1 -1
  326. package/dist/sync/download-staging.js +155 -44
  327. package/dist/sync/download-staging.js.map +1 -1
  328. package/dist/sync/filters.cjs.map +1 -1
  329. package/dist/sync/filters.js.map +1 -1
  330. package/dist/sync/index.d.cts +1 -1
  331. package/dist/sync/index.d.cts.map +1 -1
  332. package/dist/sync/index.d.ts +1 -1
  333. package/dist/sync/index.d.ts.map +1 -1
  334. package/dist/sync/local-file-io.cjs +15 -6
  335. package/dist/sync/local-file-io.cjs.map +1 -1
  336. package/dist/sync/local-file-io.d.cts +3 -0
  337. package/dist/sync/local-file-io.d.cts.map +1 -1
  338. package/dist/sync/local-file-io.d.ts +3 -0
  339. package/dist/sync/local-file-io.d.ts.map +1 -1
  340. package/dist/sync/local-file-io.js +15 -6
  341. package/dist/sync/local-file-io.js.map +1 -1
  342. package/dist/sync/local-sha1.cjs +6 -15
  343. package/dist/sync/local-sha1.cjs.map +1 -1
  344. package/dist/sync/local-sha1.d.cts +0 -8
  345. package/dist/sync/local-sha1.d.cts.map +1 -1
  346. package/dist/sync/local-sha1.d.ts +0 -8
  347. package/dist/sync/local-sha1.d.ts.map +1 -1
  348. package/dist/sync/local-sha1.js +7 -15
  349. package/dist/sync/local-sha1.js.map +1 -1
  350. package/dist/sync/pairing.cjs +1 -0
  351. package/dist/sync/pairing.cjs.map +1 -1
  352. package/dist/sync/pairing.js +1 -0
  353. package/dist/sync/pairing.js.map +1 -1
  354. package/dist/sync/policies/compare.cjs +5 -3
  355. package/dist/sync/policies/compare.cjs.map +1 -1
  356. package/dist/sync/policies/compare.d.cts.map +1 -1
  357. package/dist/sync/policies/compare.d.ts.map +1 -1
  358. package/dist/sync/policies/compare.js +6 -4
  359. package/dist/sync/policies/compare.js.map +1 -1
  360. package/dist/sync/policies/index.cjs +4 -10
  361. package/dist/sync/policies/index.cjs.map +1 -1
  362. package/dist/sync/policies/index.js +4 -10
  363. package/dist/sync/policies/index.js.map +1 -1
  364. package/dist/sync/scanners/b2.cjs +4 -2
  365. package/dist/sync/scanners/b2.cjs.map +1 -1
  366. package/dist/sync/scanners/b2.d.cts.map +1 -1
  367. package/dist/sync/scanners/b2.d.ts.map +1 -1
  368. package/dist/sync/scanners/b2.js +4 -2
  369. package/dist/sync/scanners/b2.js.map +1 -1
  370. package/dist/sync/scanners/local.cjs +150 -33
  371. package/dist/sync/scanners/local.cjs.map +1 -1
  372. package/dist/sync/scanners/local.d.cts +6 -0
  373. package/dist/sync/scanners/local.d.cts.map +1 -1
  374. package/dist/sync/scanners/local.d.ts +6 -0
  375. package/dist/sync/scanners/local.d.ts.map +1 -1
  376. package/dist/sync/scanners/local.js +150 -33
  377. package/dist/sync/scanners/local.js.map +1 -1
  378. package/dist/sync/synchronizer.cjs +79 -31
  379. package/dist/sync/synchronizer.cjs.map +1 -1
  380. package/dist/sync/synchronizer.d.cts +1 -0
  381. package/dist/sync/synchronizer.d.cts.map +1 -1
  382. package/dist/sync/synchronizer.d.ts +1 -0
  383. package/dist/sync/synchronizer.d.ts.map +1 -1
  384. package/dist/sync/synchronizer.js +79 -31
  385. package/dist/sync/synchronizer.js.map +1 -1
  386. package/dist/sync/types.d.cts +19 -3
  387. package/dist/sync/types.d.cts.map +1 -1
  388. package/dist/sync/types.d.ts +19 -3
  389. package/dist/sync/types.d.ts.map +1 -1
  390. package/dist/types/auth.cjs +4 -0
  391. package/dist/types/auth.cjs.map +1 -1
  392. package/dist/types/auth.d.cts +4 -0
  393. package/dist/types/auth.d.cts.map +1 -1
  394. package/dist/types/auth.d.ts +4 -0
  395. package/dist/types/auth.d.ts.map +1 -1
  396. package/dist/types/auth.js +4 -0
  397. package/dist/types/auth.js.map +1 -1
  398. package/dist/types/backup.d.cts +85 -0
  399. package/dist/types/backup.d.cts.map +1 -0
  400. package/dist/types/backup.d.ts +85 -0
  401. package/dist/types/backup.d.ts.map +1 -0
  402. package/dist/types/bucket.cjs +81 -11
  403. package/dist/types/bucket.cjs.map +1 -1
  404. package/dist/types/bucket.d.cts +194 -41
  405. package/dist/types/bucket.d.cts.map +1 -1
  406. package/dist/types/bucket.d.ts +194 -41
  407. package/dist/types/bucket.d.ts.map +1 -1
  408. package/dist/types/bucket.js +67 -12
  409. package/dist/types/bucket.js.map +1 -1
  410. package/dist/types/download.cjs +62 -0
  411. package/dist/types/download.cjs.map +1 -0
  412. package/dist/types/download.d.cts +100 -16
  413. package/dist/types/download.d.cts.map +1 -1
  414. package/dist/types/download.d.ts +100 -16
  415. package/dist/types/download.d.ts.map +1 -1
  416. package/dist/types/download.js +61 -0
  417. package/dist/types/download.js.map +1 -0
  418. package/dist/types/encryption.cjs +76 -229
  419. package/dist/types/encryption.cjs.map +1 -1
  420. package/dist/types/encryption.d.cts +48 -6
  421. package/dist/types/encryption.d.cts.map +1 -1
  422. package/dist/types/encryption.d.ts +48 -6
  423. package/dist/types/encryption.d.ts.map +1 -1
  424. package/dist/types/encryption.js +74 -229
  425. package/dist/types/encryption.js.map +1 -1
  426. package/dist/types/errors.cjs +9 -0
  427. package/dist/types/errors.cjs.map +1 -1
  428. package/dist/types/errors.d.cts +1 -1
  429. package/dist/types/errors.d.cts.map +1 -1
  430. package/dist/types/errors.d.ts +1 -1
  431. package/dist/types/errors.d.ts.map +1 -1
  432. package/dist/types/errors.js +9 -0
  433. package/dist/types/errors.js.map +1 -1
  434. package/dist/types/file.cjs +3 -0
  435. package/dist/types/file.cjs.map +1 -1
  436. package/dist/types/file.d.cts +140 -18
  437. package/dist/types/file.d.cts.map +1 -1
  438. package/dist/types/file.d.ts +140 -18
  439. package/dist/types/file.d.ts.map +1 -1
  440. package/dist/types/file.js +3 -1
  441. package/dist/types/file.js.map +1 -1
  442. package/dist/types/ids.cjs +30 -0
  443. package/dist/types/ids.cjs.map +1 -1
  444. package/dist/types/ids.d.cts +32 -0
  445. package/dist/types/ids.d.cts.map +1 -1
  446. package/dist/types/ids.d.ts +32 -0
  447. package/dist/types/ids.d.ts.map +1 -1
  448. package/dist/types/ids.js +28 -1
  449. package/dist/types/ids.js.map +1 -1
  450. package/dist/types/index.d.cts +16 -12
  451. package/dist/types/index.d.cts.map +1 -1
  452. package/dist/types/index.d.ts +16 -12
  453. package/dist/types/index.d.ts.map +1 -1
  454. package/dist/types/key.d.cts +4 -3
  455. package/dist/types/key.d.cts.map +1 -1
  456. package/dist/types/key.d.ts +4 -3
  457. package/dist/types/key.d.ts.map +1 -1
  458. package/dist/types/lock.cjs.map +1 -1
  459. package/dist/types/lock.d.cts +14 -0
  460. package/dist/types/lock.d.cts.map +1 -1
  461. package/dist/types/lock.d.ts +14 -0
  462. package/dist/types/lock.d.ts.map +1 -1
  463. package/dist/types/lock.js.map +1 -1
  464. package/dist/types/notifications.cjs +31 -1
  465. package/dist/types/notifications.cjs.map +1 -1
  466. package/dist/types/notifications.d.cts +31 -4
  467. package/dist/types/notifications.d.cts.map +1 -1
  468. package/dist/types/notifications.d.ts +31 -4
  469. package/dist/types/notifications.d.ts.map +1 -1
  470. package/dist/types/notifications.js +30 -2
  471. package/dist/types/notifications.js.map +1 -1
  472. package/dist/types/partner.cjs +32 -0
  473. package/dist/types/partner.cjs.map +1 -0
  474. package/dist/types/partner.d.cts +386 -0
  475. package/dist/types/partner.d.cts.map +1 -0
  476. package/dist/types/partner.d.ts +386 -0
  477. package/dist/types/partner.d.ts.map +1 -0
  478. package/dist/types/partner.js +29 -0
  479. package/dist/types/partner.js.map +1 -0
  480. package/dist/types/upload.d.cts +35 -18
  481. package/dist/types/upload.d.cts.map +1 -1
  482. package/dist/types/upload.d.ts +35 -18
  483. package/dist/types/upload.d.ts.map +1 -1
  484. package/dist/upload/abort-scope.cjs +0 -45
  485. package/dist/upload/abort-scope.cjs.map +1 -1
  486. package/dist/upload/abort-scope.d.cts +0 -22
  487. package/dist/upload/abort-scope.d.cts.map +1 -1
  488. package/dist/upload/abort-scope.d.ts +0 -22
  489. package/dist/upload/abort-scope.d.ts.map +1 -1
  490. package/dist/upload/abort-scope.js +1 -44
  491. package/dist/upload/abort-scope.js.map +1 -1
  492. package/dist/upload/finish.cjs +3 -8
  493. package/dist/upload/finish.cjs.map +1 -1
  494. package/dist/upload/finish.d.cts.map +1 -1
  495. package/dist/upload/finish.d.ts.map +1 -1
  496. package/dist/upload/finish.js +1 -6
  497. package/dist/upload/finish.js.map +1 -1
  498. package/dist/upload/large.cjs +15 -8
  499. package/dist/upload/large.cjs.map +1 -1
  500. package/dist/upload/large.d.cts +31 -8
  501. package/dist/upload/large.d.cts.map +1 -1
  502. package/dist/upload/large.d.ts +31 -8
  503. package/dist/upload/large.d.ts.map +1 -1
  504. package/dist/upload/large.js +15 -8
  505. package/dist/upload/large.js.map +1 -1
  506. package/dist/upload/options.cjs.map +1 -1
  507. package/dist/upload/options.d.cts +24 -0
  508. package/dist/upload/options.d.cts.map +1 -1
  509. package/dist/upload/options.d.ts +24 -0
  510. package/dist/upload/options.d.ts.map +1 -1
  511. package/dist/upload/options.js.map +1 -1
  512. package/dist/upload/resume.cjs +6 -4
  513. package/dist/upload/resume.cjs.map +1 -1
  514. package/dist/upload/resume.d.cts +9 -5
  515. package/dist/upload/resume.d.cts.map +1 -1
  516. package/dist/upload/resume.d.ts +9 -5
  517. package/dist/upload/resume.d.ts.map +1 -1
  518. package/dist/upload/resume.js +6 -4
  519. package/dist/upload/resume.js.map +1 -1
  520. package/dist/upload/retry.cjs +25 -13
  521. package/dist/upload/retry.cjs.map +1 -1
  522. package/dist/upload/retry.d.cts.map +1 -1
  523. package/dist/upload/retry.d.ts.map +1 -1
  524. package/dist/upload/retry.js +25 -13
  525. package/dist/upload/retry.js.map +1 -1
  526. package/dist/upload/single.cjs +35 -30
  527. package/dist/upload/single.cjs.map +1 -1
  528. package/dist/upload/single.d.cts +12 -0
  529. package/dist/upload/single.d.cts.map +1 -1
  530. package/dist/upload/single.d.ts +12 -0
  531. package/dist/upload/single.d.ts.map +1 -1
  532. package/dist/upload/single.js +35 -30
  533. package/dist/upload/single.js.map +1 -1
  534. package/dist/upload/stream.cjs +18 -5
  535. package/dist/upload/stream.cjs.map +1 -1
  536. package/dist/upload/stream.d.cts +12 -0
  537. package/dist/upload/stream.d.cts.map +1 -1
  538. package/dist/upload/stream.d.ts +12 -0
  539. package/dist/upload/stream.d.ts.map +1 -1
  540. package/dist/upload/stream.js +15 -2
  541. package/dist/upload/stream.js.map +1 -1
  542. package/dist/util/abort.cjs +114 -0
  543. package/dist/util/abort.cjs.map +1 -0
  544. package/dist/util/abort.d.cts +65 -0
  545. package/dist/util/abort.d.cts.map +1 -0
  546. package/dist/util/abort.d.ts +65 -0
  547. package/dist/util/abort.d.ts.map +1 -0
  548. package/dist/util/abort.js +109 -0
  549. package/dist/util/abort.js.map +1 -0
  550. package/dist/util/defaults.cjs +3 -0
  551. package/dist/util/defaults.cjs.map +1 -1
  552. package/dist/util/defaults.d.cts +2 -0
  553. package/dist/util/defaults.d.cts.map +1 -1
  554. package/dist/util/defaults.d.ts +2 -0
  555. package/dist/util/defaults.d.ts.map +1 -1
  556. package/dist/util/defaults.js +3 -1
  557. package/dist/util/defaults.js.map +1 -1
  558. package/dist/util/md5.cjs +211 -0
  559. package/dist/util/md5.cjs.map +1 -0
  560. package/dist/util/md5.d.cts +43 -0
  561. package/dist/util/md5.d.cts.map +1 -0
  562. package/dist/util/md5.d.ts +43 -0
  563. package/dist/util/md5.d.ts.map +1 -0
  564. package/dist/util/md5.js +209 -0
  565. package/dist/util/md5.js.map +1 -0
  566. package/dist/util/normalize.cjs +5 -5
  567. package/dist/util/normalize.cjs.map +1 -1
  568. package/dist/util/normalize.d.cts +7 -7
  569. package/dist/util/normalize.d.cts.map +1 -1
  570. package/dist/util/normalize.d.ts +7 -7
  571. package/dist/util/normalize.d.ts.map +1 -1
  572. package/dist/util/normalize.js +5 -5
  573. package/dist/util/normalize.js.map +1 -1
  574. package/dist/util/paginator.cjs +7 -1
  575. package/dist/util/paginator.cjs.map +1 -1
  576. package/dist/util/paginator.d.cts +3 -1
  577. package/dist/util/paginator.d.cts.map +1 -1
  578. package/dist/util/paginator.d.ts +3 -1
  579. package/dist/util/paginator.d.ts.map +1 -1
  580. package/dist/util/paginator.js +7 -1
  581. package/dist/util/paginator.js.map +1 -1
  582. package/dist/version.cjs +56 -4
  583. package/dist/version.cjs.map +1 -1
  584. package/dist/version.d.cts +53 -4
  585. package/dist/version.d.cts.map +1 -1
  586. package/dist/version.d.ts +53 -4
  587. package/dist/version.d.ts.map +1 -1
  588. package/dist/version.js +52 -5
  589. package/dist/version.js.map +1 -1
  590. package/package.json +47 -18
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/util/normalize.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAG3E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACxF,EAAE,EAAE,CAAC,GACJ,CAAC,CAEH;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAC1C,CAAC,SAAS;IAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACjD,CAAC,SAAS;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAA;CAAE,EAC1C,IAAI,EAAE,CAAC,GAAG,CAAC,CAEZ"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/util/normalize.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAG3E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACzF,EAAE,EAAE,CAAC,GACJ,CAAC,CAEH;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAC1C,CAAC,SAAS;IAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAClD,CAAC,SAAS;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAA;CAAE,EAC1C,IAAI,EAAE,CAAC,GAAG,CAAC,CAEZ"}
@@ -36,7 +36,7 @@ function normalizeSha1(raw) {
36
36
  * substitution was needed, so callers paying for change detection
37
37
  * (e.g. React memo) see referential stability.
38
38
  *
39
- * @typeParam T - Any object with a `contentSha1: string | null` field.
39
+ * @typeParam T - Any object with a `contentSha1?: string | null` field.
40
40
  *
41
41
  * @param fv - The wire-shape file-version object.
42
42
  *
@@ -50,11 +50,11 @@ function normalizeFileVersionSha1(fv) {
50
50
  }
51
51
  /**
52
52
  * Returns a new list-response object with `normalizeFileVersionSha1`
53
- * applied to every entry in `files`. Used at the `b2_list_file_names` /
54
- * `b2_list_file_versions` boundary so list output shares the same
55
- * SHA-1 semantics as the singular endpoints.
53
+ * applied to every entry in `files`. Used at file-version and unfinished
54
+ * large-file list boundaries so list output shares the same SHA-1 semantics
55
+ * as the singular endpoints.
56
56
  *
57
- * @typeParam F - Any object with a `contentSha1: string | null` field.
57
+ * @typeParam F - Any object with a `contentSha1?: string | null` field.
58
58
  * @typeParam R - The list-response shape (must have a `files` array of `F`).
59
59
  *
60
60
  * @param resp - The wire-shape list response.
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.js","names":[],"sources":["../../src/util/normalize.ts"],"sourcesContent":["/**\n * Wire-shape → SDK-shape normalization helpers.\n *\n * B2 occasionally uses sentinel strings on the wire where a missing\n * value would be more idiomatic in TypeScript. The biggest offender is\n * `contentSha1: 'none'` on files completed via `b2_finish_large_file`\n * (multipart-finished files don't have a whole-file SHA-1; B2 sends the\n * literal three-letter string). The SDK's `FileVersion.contentSha1` is\n * typed `string | null` to signal that absence — this module collapses\n * the wire sentinel to `null` so callers can write\n * `if (fv.contentSha1) { ... }` without an extra `=== 'none'` guard.\n *\n * Normalization happens at the RawClient boundary so every SDK consumer\n * (RawClient direct users, the high-level facade, the simulator-driven\n * tests, generated docs) sees the same `null` value.\n *\n * @packageDocumentation\n */\n\n/**\n * Collapses the B2 wire sentinel `'none'` (and `undefined`) to `null` for\n * SHA-1-shaped fields. Any other string passes through unchanged.\n *\n * @param raw - SHA-1 string from the wire, or `null`/`undefined`.\n *\n * @returns A hex SHA-1 string, or `null` when the wire said \"no hash\".\n */\nexport function normalizeSha1(raw: string | null | undefined): string | null {\n if (raw === null || raw === undefined || raw === 'none') return null\n return raw\n}\n\n/**\n * Returns a new file-version-shaped object with the `contentSha1: 'none'`\n * sentinel collapsed to `null`. Pass-through when the value is already\n * `null` or a real hash. The object reference is preserved if no\n * substitution was needed, so callers paying for change detection\n * (e.g. React memo) see referential stability.\n *\n * @typeParam T - Any object with a `contentSha1: string | null` field.\n *\n * @param fv - The wire-shape file-version object.\n *\n * @returns Either `fv` unchanged or a shallow copy with `contentSha1: null`.\n */\nexport function normalizeFileVersionSha1<T extends { readonly contentSha1: string | null }>(\n fv: T,\n): T {\n return fv.contentSha1 === 'none' ? { ...fv, contentSha1: null } : fv\n}\n\n/**\n * Returns a new list-response object with `normalizeFileVersionSha1`\n * applied to every entry in `files`. Used at the `b2_list_file_names` /\n * `b2_list_file_versions` boundary so list output shares the same\n * SHA-1 semantics as the singular endpoints.\n *\n * @typeParam F - Any object with a `contentSha1: string | null` field.\n * @typeParam R - The list-response shape (must have a `files` array of `F`).\n *\n * @param resp - The wire-shape list response.\n *\n * @returns A response with normalized `files`. `resp.files` is a new array.\n */\nexport function normalizeFileVersionListSha1<\n F extends { readonly contentSha1: string | null },\n R extends { readonly files: readonly F[] },\n>(resp: R): R {\n return { ...resp, files: resp.files.map(normalizeFileVersionSha1) }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,cAAc,KAA+C;CAC3E,IAAI,QAAQ,QAAQ,QAAQ,KAAA,KAAa,QAAQ,QAAQ,OAAO;CAChE,OAAO;AACT;;;;;;;;;;;;;;AAeA,SAAgB,yBACd,IACG;CACH,OAAO,GAAG,gBAAgB,SAAS;EAAE,GAAG;EAAI,aAAa;CAAK,IAAI;AACpE;;;;;;;;;;;;;;AAeA,SAAgB,6BAGd,MAAY;CACZ,OAAO;EAAE,GAAG;EAAM,OAAO,KAAK,MAAM,IAAI,wBAAwB;CAAE;AACpE"}
1
+ {"version":3,"file":"normalize.js","names":[],"sources":["../../src/util/normalize.ts"],"sourcesContent":["/**\n * Wire-shape → SDK-shape normalization helpers.\n *\n * B2 occasionally uses sentinel strings on the wire where a missing\n * value would be more idiomatic in TypeScript. The biggest offender is\n * `contentSha1: 'none'` on files completed via `b2_finish_large_file`\n * (multipart-finished files don't have a whole-file SHA-1; B2 sends the\n * literal three-letter string). The SDK's `FileVersion.contentSha1` is\n * typed `string | null` to signal that absence — this module collapses\n * the wire sentinel to `null` so callers can write\n * `if (fv.contentSha1) { ... }` without an extra `=== 'none'` guard.\n *\n * Normalization happens at the RawClient boundary so every SDK consumer\n * (RawClient direct users, the high-level facade, the simulator-driven\n * tests, generated docs) sees the same `null` value.\n *\n * @packageDocumentation\n */\n\n/**\n * Collapses the B2 wire sentinel `'none'` (and `undefined`) to `null` for\n * SHA-1-shaped fields. Any other string passes through unchanged.\n *\n * @param raw - SHA-1 string from the wire, or `null`/`undefined`.\n *\n * @returns A hex SHA-1 string, or `null` when the wire said \"no hash\".\n */\nexport function normalizeSha1(raw: string | null | undefined): string | null {\n if (raw === null || raw === undefined || raw === 'none') return null\n return raw\n}\n\n/**\n * Returns a new file-version-shaped object with the `contentSha1: 'none'`\n * sentinel collapsed to `null`. Pass-through when the value is already\n * `null` or a real hash. The object reference is preserved if no\n * substitution was needed, so callers paying for change detection\n * (e.g. React memo) see referential stability.\n *\n * @typeParam T - Any object with a `contentSha1?: string | null` field.\n *\n * @param fv - The wire-shape file-version object.\n *\n * @returns Either `fv` unchanged or a shallow copy with `contentSha1: null`.\n */\nexport function normalizeFileVersionSha1<T extends { readonly contentSha1?: string | null }>(\n fv: T,\n): T {\n return fv.contentSha1 === 'none' ? { ...fv, contentSha1: null } : fv\n}\n\n/**\n * Returns a new list-response object with `normalizeFileVersionSha1`\n * applied to every entry in `files`. Used at file-version and unfinished\n * large-file list boundaries so list output shares the same SHA-1 semantics\n * as the singular endpoints.\n *\n * @typeParam F - Any object with a `contentSha1?: string | null` field.\n * @typeParam R - The list-response shape (must have a `files` array of `F`).\n *\n * @param resp - The wire-shape list response.\n *\n * @returns A response with normalized `files`. `resp.files` is a new array.\n */\nexport function normalizeFileVersionListSha1<\n F extends { readonly contentSha1?: string | null },\n R extends { readonly files: readonly F[] },\n>(resp: R): R {\n return { ...resp, files: resp.files.map(normalizeFileVersionSha1) }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,cAAc,KAA+C;CAC3E,IAAI,QAAQ,QAAQ,QAAQ,KAAA,KAAa,QAAQ,QAAQ,OAAO;CAChE,OAAO;AACT;;;;;;;;;;;;;;AAeA,SAAgB,yBACd,IACG;CACH,OAAO,GAAG,gBAAgB,SAAS;EAAE,GAAG;EAAI,aAAa;CAAK,IAAI;AACpE;;;;;;;;;;;;;;AAeA,SAAgB,6BAGd,MAAY;CACZ,OAAO;EAAE,GAAG;EAAM,OAAO,KAAK,MAAM,IAAI,wBAAwB;CAAE;AACpE"}
@@ -1,7 +1,12 @@
1
1
  //#region src/util/paginator.ts
2
+ function isPrimitiveCursor(cursor) {
3
+ return cursor === null || typeof cursor !== "object" && typeof cursor !== "function";
4
+ }
2
5
  /**
3
6
  * Async-iterates one page at a time. Stops when `fetcher` returns
4
- * `nextCursor: undefined`.
7
+ * `nextCursor: undefined` or a primitive cursor that is identical to the
8
+ * cursor just used, which prevents non-advancing server cursors from looping
9
+ * forever.
5
10
  *
6
11
  * @typeParam Page - The per-page response shape.
7
12
  * @typeParam Cursor - The cursor type used to request the next page.
@@ -33,6 +38,7 @@ async function* paginatePages(fetcher, signal) {
33
38
  const { page, nextCursor } = await fetcher(cursor);
34
39
  yield page;
35
40
  if (nextCursor === void 0) return;
41
+ if (cursor !== void 0 && isPrimitiveCursor(cursor) && isPrimitiveCursor(nextCursor) && Object.is(nextCursor, cursor)) return;
36
42
  cursor = nextCursor;
37
43
  }
38
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"paginator.cjs","names":[],"sources":["../../src/util/paginator.ts"],"sourcesContent":["/**\n * Generic pagination helpers for B2 list endpoints.\n *\n * B2 returns paginated results as `{ items, nextCursor }` shapes that differ\n * per endpoint (`nextFileName`, `nextFileId`, `nextPartNumber`,\n * `nextApplicationKeyId`, etc.). These helpers let callers iterate without\n * threading the cursor by hand.\n *\n * Two flavours:\n * - {@link paginatePages} yields each page as the server returned it.\n * Useful when the caller wants the per-page response object (e.g. for\n * access to per-page metadata or to control item-iteration order).\n * - {@link paginateItems} flattens pages and yields individual items.\n * Useful for the common \"iterate everything\" case.\n *\n * Both helpers honour an optional {@link AbortSignal} that aborts the\n * iteration **between fetches**. They do NOT abort an in-flight network\n * request: the underlying list call has its own `signal` parameter and\n * each consumer must wire that through if mid-flight cancellation is\n * required.\n *\n * @packageDocumentation\n *\n * @example\n * ```ts\n * for await (const file of bucket.paginateFileNames({ prefix: 'photos/' })) {\n * console.log(file.fileName, file.contentLength)\n * }\n * ```\n *\n */\n\n/**\n * Options accepted by every `paginateX` method on `Bucket` and `B2Client`.\n */\nexport interface PaginatorOptions {\n /**\n * Maximum items per page. Forwarded to the underlying list call's\n * `maxFileCount` / `maxKeyCount` / `maxPartCount` parameter. B2 caps this\n * at endpoint-specific limits (typically 10000 for files, 100 for parts).\n */\n pageSize?: number\n /**\n * Aborts the iteration between fetches. When already aborted at call time,\n * the iterator throws immediately on its first `next()` call.\n *\n * Note: this does NOT abort an in-flight HTTP request mid-page. The\n * iterator checks `signal.throwIfAborted()` only between fetches.\n */\n signal?: AbortSignal\n}\n\n/**\n * Function that fetches a single page given a cursor.\n *\n * The cursor is `undefined` for the first page, then takes the value of the\n * previous page's `nextCursor` on subsequent calls. Iteration stops when\n * `nextCursor` is `undefined` (or any other falsy value the caller maps to\n * `undefined`).\n *\n * @typeParam Page - The per-page response shape returned by the B2 endpoint.\n * @typeParam Cursor - The cursor type (typically `string` or a `{name, id}` pair).\n */\nexport type PageFetcher<Page, Cursor> = (cursor: Cursor | undefined) => Promise<{\n /** The page just fetched. */\n page: Page\n /** Cursor for the next page, or `undefined` if there are no more pages. */\n nextCursor: Cursor | undefined\n}>\n\n/**\n * Async-iterates one page at a time. Stops when `fetcher` returns\n * `nextCursor: undefined`.\n *\n * @typeParam Page - The per-page response shape.\n * @typeParam Cursor - The cursor type used to request the next page.\n *\n * @param fetcher - Function that fetches one page given the current cursor.\n * @param signal - Optional abort signal. Checked before each fetch.\n *\n * @returns An async iterable of pages.\n *\n * @throws DOMException When `signal` is aborted between fetches.\n *\n * @example\n * ```ts\n * for await (const page of paginatePages(\n * async (cursor) => {\n * const resp = await bucket.listFileNames({ startFileName: cursor })\n * return { page: resp, nextCursor: resp.nextFileName ?? undefined }\n * },\n * abortSignal,\n * )) {\n * for (const file of page.files) { ... }\n * }\n * ```\n */\nexport async function* paginatePages<Page, Cursor>(\n fetcher: PageFetcher<Page, Cursor>,\n signal: AbortSignal | undefined,\n): AsyncIterableIterator<Page> {\n let cursor: Cursor | undefined\n while (true) {\n signal?.throwIfAborted()\n const { page, nextCursor } = await fetcher(cursor)\n yield page\n if (nextCursor === undefined) return\n cursor = nextCursor\n }\n}\n\n/**\n * Async-iterates items by flattening pages. The `extractItems` function\n * pulls the relevant array out of each page (e.g. `page.files`,\n * `page.keys`, `page.parts`). Each item is yielded individually so the\n * caller can `for await (const item of paginator)` rather than nest loops.\n *\n * Aborts between **pages**, not between items: if `signal` is aborted while\n * the caller is processing the items of page N, the iterator will still\n * yield all of page N's remaining items before checking the signal before\n * fetching page N+1.\n *\n * @typeParam Page - The per-page response shape.\n * @typeParam Cursor - The cursor type used to request the next page.\n * @typeParam Item - The item type the caller wants to iterate.\n *\n * @param fetcher - Function that fetches one page given the current cursor.\n * @param extractItems - Pulls the iterable items out of a page.\n * @param signal - Optional abort signal. Checked before each fetch.\n *\n * @returns An async iterable of individual items.\n *\n * @throws DOMException When `signal` is aborted between fetches.\n */\nexport async function* paginateItems<Page, Cursor, Item>(\n fetcher: PageFetcher<Page, Cursor>,\n extractItems: (page: Page) => Iterable<Item>,\n signal: AbortSignal | undefined,\n): AsyncIterableIterator<Item> {\n for await (const page of paginatePages(fetcher, signal)) {\n yield* extractItems(page)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,gBAAuB,cACrB,SACA,QAC6B;CAC7B,IAAI;CACJ,OAAO,MAAM;EACX,QAAQ,eAAe;EACvB,MAAM,EAAE,MAAM,eAAe,MAAM,QAAQ,MAAM;EACjD,MAAM;EACN,IAAI,eAAe,KAAA,GAAW;EAC9B,SAAS;CACX;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,gBAAuB,cACrB,SACA,cACA,QAC6B;CAC7B,WAAW,MAAM,QAAQ,cAAc,SAAS,MAAM,GACpD,OAAO,aAAa,IAAI;AAE5B"}
1
+ {"version":3,"file":"paginator.cjs","names":[],"sources":["../../src/util/paginator.ts"],"sourcesContent":["/**\n * Generic pagination helpers for B2 list endpoints.\n *\n * B2 returns paginated results as `{ items, nextCursor }` shapes that differ\n * per endpoint (`nextFileName`, `nextFileId`, `nextPartNumber`,\n * `nextApplicationKeyId`, etc.). These helpers let callers iterate without\n * threading the cursor by hand.\n *\n * Two flavours:\n * - {@link paginatePages} yields each page as the server returned it.\n * Useful when the caller wants the per-page response object (e.g. for\n * access to per-page metadata or to control item-iteration order).\n * - {@link paginateItems} flattens pages and yields individual items.\n * Useful for the common \"iterate everything\" case.\n *\n * Both helpers honour an optional {@link AbortSignal} that aborts the\n * iteration **between fetches**. They do NOT abort an in-flight network\n * request: the underlying list call has its own `signal` parameter and\n * each consumer must wire that through if mid-flight cancellation is\n * required.\n *\n * @packageDocumentation\n *\n * @example\n * ```ts\n * for await (const file of bucket.paginateFileNames({ prefix: 'photos/' })) {\n * console.log(file.fileName, file.contentLength)\n * }\n * ```\n *\n */\n\n/**\n * Options accepted by every `paginateX` method on `Bucket` and `B2Client`.\n */\nexport interface PaginatorOptions {\n /**\n * Maximum items per page. Forwarded to the underlying list call's\n * `maxFileCount` / `maxKeyCount` / `maxPartCount` parameter. B2 caps this\n * at endpoint-specific limits (typically 10000 for files, 100 for parts).\n */\n pageSize?: number\n /**\n * Aborts the iteration between fetches. When already aborted at call time,\n * the iterator throws immediately on its first `next()` call.\n *\n * Note: this does NOT abort an in-flight HTTP request mid-page. The\n * iterator checks `signal.throwIfAborted()` only between fetches.\n */\n signal?: AbortSignal\n}\n\n/**\n * Function that fetches a single page given a cursor.\n *\n * The cursor is `undefined` for the first page, then takes the value of the\n * previous page's `nextCursor` on subsequent calls. Iteration stops when\n * `nextCursor` is `undefined` (or any other falsy value the caller maps to\n * `undefined`).\n *\n * @typeParam Page - The per-page response shape returned by the B2 endpoint.\n * @typeParam Cursor - The cursor type (typically `string` or a `{name, id}` pair).\n */\nexport type PageFetcher<Page, Cursor> = (cursor: Cursor | undefined) => Promise<{\n /** The page just fetched. */\n page: Page\n /** Cursor for the next page, or `undefined` if there are no more pages. */\n nextCursor: Cursor | undefined\n}>\n\nfunction isPrimitiveCursor(cursor: unknown): boolean {\n return cursor === null || (typeof cursor !== 'object' && typeof cursor !== 'function')\n}\n\n/**\n * Async-iterates one page at a time. Stops when `fetcher` returns\n * `nextCursor: undefined` or a primitive cursor that is identical to the\n * cursor just used, which prevents non-advancing server cursors from looping\n * forever.\n *\n * @typeParam Page - The per-page response shape.\n * @typeParam Cursor - The cursor type used to request the next page.\n *\n * @param fetcher - Function that fetches one page given the current cursor.\n * @param signal - Optional abort signal. Checked before each fetch.\n *\n * @returns An async iterable of pages.\n *\n * @throws DOMException When `signal` is aborted between fetches.\n *\n * @example\n * ```ts\n * for await (const page of paginatePages(\n * async (cursor) => {\n * const resp = await bucket.listFileNames({ startFileName: cursor })\n * return { page: resp, nextCursor: resp.nextFileName ?? undefined }\n * },\n * abortSignal,\n * )) {\n * for (const file of page.files) { ... }\n * }\n * ```\n */\nexport async function* paginatePages<Page, Cursor>(\n fetcher: PageFetcher<Page, Cursor>,\n signal: AbortSignal | undefined,\n): AsyncIterableIterator<Page> {\n let cursor: Cursor | undefined\n while (true) {\n signal?.throwIfAborted()\n const { page, nextCursor } = await fetcher(cursor)\n yield page\n if (nextCursor === undefined) return\n if (\n cursor !== undefined &&\n isPrimitiveCursor(cursor) &&\n isPrimitiveCursor(nextCursor) &&\n Object.is(nextCursor, cursor)\n ) {\n return\n }\n cursor = nextCursor\n }\n}\n\n/**\n * Async-iterates items by flattening pages. The `extractItems` function\n * pulls the relevant array out of each page (e.g. `page.files`,\n * `page.keys`, `page.parts`). Each item is yielded individually so the\n * caller can `for await (const item of paginator)` rather than nest loops.\n *\n * Aborts between **pages**, not between items: if `signal` is aborted while\n * the caller is processing the items of page N, the iterator will still\n * yield all of page N's remaining items before checking the signal before\n * fetching page N+1.\n *\n * @typeParam Page - The per-page response shape.\n * @typeParam Cursor - The cursor type used to request the next page.\n * @typeParam Item - The item type the caller wants to iterate.\n *\n * @param fetcher - Function that fetches one page given the current cursor.\n * @param extractItems - Pulls the iterable items out of a page.\n * @param signal - Optional abort signal. Checked before each fetch.\n *\n * @returns An async iterable of individual items.\n *\n * @throws DOMException When `signal` is aborted between fetches.\n */\nexport async function* paginateItems<Page, Cursor, Item>(\n fetcher: PageFetcher<Page, Cursor>,\n extractItems: (page: Page) => Iterable<Item>,\n signal: AbortSignal | undefined,\n): AsyncIterableIterator<Item> {\n for await (const page of paginatePages(fetcher, signal)) {\n yield* extractItems(page)\n }\n}\n"],"mappings":";AAsEA,SAAS,kBAAkB,QAA0B;CACnD,OAAO,WAAW,QAAS,OAAO,WAAW,YAAY,OAAO,WAAW;AAC7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,gBAAuB,cACrB,SACA,QAC6B;CAC7B,IAAI;CACJ,OAAO,MAAM;EACX,QAAQ,eAAe;EACvB,MAAM,EAAE,MAAM,eAAe,MAAM,QAAQ,MAAM;EACjD,MAAM;EACN,IAAI,eAAe,KAAA,GAAW;EAC9B,IACE,WAAW,KAAA,KACX,kBAAkB,MAAM,KACxB,kBAAkB,UAAU,KAC5B,OAAO,GAAG,YAAY,MAAM,GAE5B;EAEF,SAAS;CACX;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,gBAAuB,cACrB,SACA,cACA,QAC6B;CAC7B,WAAW,MAAM,QAAQ,cAAc,SAAS,MAAM,GACpD,OAAO,aAAa,IAAI;AAE5B"}
@@ -67,7 +67,9 @@ export type PageFetcher<Page, Cursor> = (cursor: Cursor | undefined) => Promise<
67
67
  }>;
68
68
  /**
69
69
  * Async-iterates one page at a time. Stops when `fetcher` returns
70
- * `nextCursor: undefined`.
70
+ * `nextCursor: undefined` or a primitive cursor that is identical to the
71
+ * cursor just used, which prevents non-advancing server cursors from looping
72
+ * forever.
71
73
  *
72
74
  * @typeParam Page - The per-page response shape.
73
75
  * @typeParam Cursor - The cursor type used to request the next page.
@@ -1 +1 @@
1
- {"version":3,"file":"paginator.d.ts","sourceRoot":"","sources":["../../src/util/paginator.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;IAC9E,6BAA6B;IAC7B,IAAI,EAAE,IAAI,CAAA;IACV,2EAA2E;IAC3E,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAC/B,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAuB,aAAa,CAAC,IAAI,EAAE,MAAM,EAC/C,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EAClC,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,qBAAqB,CAAC,IAAI,CAAC,CAS7B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAuB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EACrD,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EAClC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC,EAC5C,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,qBAAqB,CAAC,IAAI,CAAC,CAI7B"}
1
+ {"version":3,"file":"paginator.d.ts","sourceRoot":"","sources":["../../src/util/paginator.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;IAC9E,6BAA6B;IAC7B,IAAI,EAAE,IAAI,CAAA;IACV,2EAA2E;IAC3E,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAC/B,CAAC,CAAA;AAMF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAuB,aAAa,CAAC,IAAI,EAAE,MAAM,EAC/C,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EAClC,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,qBAAqB,CAAC,IAAI,CAAC,CAiB7B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAuB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EACrD,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EAClC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC,EAC5C,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,qBAAqB,CAAC,IAAI,CAAC,CAI7B"}
@@ -67,7 +67,9 @@ export type PageFetcher<Page, Cursor> = (cursor: Cursor | undefined) => Promise<
67
67
  }>;
68
68
  /**
69
69
  * Async-iterates one page at a time. Stops when `fetcher` returns
70
- * `nextCursor: undefined`.
70
+ * `nextCursor: undefined` or a primitive cursor that is identical to the
71
+ * cursor just used, which prevents non-advancing server cursors from looping
72
+ * forever.
71
73
  *
72
74
  * @typeParam Page - The per-page response shape.
73
75
  * @typeParam Cursor - The cursor type used to request the next page.
@@ -1 +1 @@
1
- {"version":3,"file":"paginator.d.ts","sourceRoot":"","sources":["../../src/util/paginator.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;IAC9E,6BAA6B;IAC7B,IAAI,EAAE,IAAI,CAAA;IACV,2EAA2E;IAC3E,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAC/B,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAuB,aAAa,CAAC,IAAI,EAAE,MAAM,EAC/C,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EAClC,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,qBAAqB,CAAC,IAAI,CAAC,CAS7B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAuB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EACrD,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EAClC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC,EAC5C,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,qBAAqB,CAAC,IAAI,CAAC,CAI7B"}
1
+ {"version":3,"file":"paginator.d.ts","sourceRoot":"","sources":["../../src/util/paginator.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;IAC9E,6BAA6B;IAC7B,IAAI,EAAE,IAAI,CAAA;IACV,2EAA2E;IAC3E,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAC/B,CAAC,CAAA;AAMF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAuB,aAAa,CAAC,IAAI,EAAE,MAAM,EAC/C,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EAClC,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,qBAAqB,CAAC,IAAI,CAAC,CAiB7B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAuB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EACrD,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EAClC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC,EAC5C,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,qBAAqB,CAAC,IAAI,CAAC,CAI7B"}
@@ -1,7 +1,12 @@
1
1
  //#region src/util/paginator.ts
2
+ function isPrimitiveCursor(cursor) {
3
+ return cursor === null || typeof cursor !== "object" && typeof cursor !== "function";
4
+ }
2
5
  /**
3
6
  * Async-iterates one page at a time. Stops when `fetcher` returns
4
- * `nextCursor: undefined`.
7
+ * `nextCursor: undefined` or a primitive cursor that is identical to the
8
+ * cursor just used, which prevents non-advancing server cursors from looping
9
+ * forever.
5
10
  *
6
11
  * @typeParam Page - The per-page response shape.
7
12
  * @typeParam Cursor - The cursor type used to request the next page.
@@ -33,6 +38,7 @@ async function* paginatePages(fetcher, signal) {
33
38
  const { page, nextCursor } = await fetcher(cursor);
34
39
  yield page;
35
40
  if (nextCursor === void 0) return;
41
+ if (cursor !== void 0 && isPrimitiveCursor(cursor) && isPrimitiveCursor(nextCursor) && Object.is(nextCursor, cursor)) return;
36
42
  cursor = nextCursor;
37
43
  }
38
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"paginator.js","names":[],"sources":["../../src/util/paginator.ts"],"sourcesContent":["/**\n * Generic pagination helpers for B2 list endpoints.\n *\n * B2 returns paginated results as `{ items, nextCursor }` shapes that differ\n * per endpoint (`nextFileName`, `nextFileId`, `nextPartNumber`,\n * `nextApplicationKeyId`, etc.). These helpers let callers iterate without\n * threading the cursor by hand.\n *\n * Two flavours:\n * - {@link paginatePages} yields each page as the server returned it.\n * Useful when the caller wants the per-page response object (e.g. for\n * access to per-page metadata or to control item-iteration order).\n * - {@link paginateItems} flattens pages and yields individual items.\n * Useful for the common \"iterate everything\" case.\n *\n * Both helpers honour an optional {@link AbortSignal} that aborts the\n * iteration **between fetches**. They do NOT abort an in-flight network\n * request: the underlying list call has its own `signal` parameter and\n * each consumer must wire that through if mid-flight cancellation is\n * required.\n *\n * @packageDocumentation\n *\n * @example\n * ```ts\n * for await (const file of bucket.paginateFileNames({ prefix: 'photos/' })) {\n * console.log(file.fileName, file.contentLength)\n * }\n * ```\n *\n */\n\n/**\n * Options accepted by every `paginateX` method on `Bucket` and `B2Client`.\n */\nexport interface PaginatorOptions {\n /**\n * Maximum items per page. Forwarded to the underlying list call's\n * `maxFileCount` / `maxKeyCount` / `maxPartCount` parameter. B2 caps this\n * at endpoint-specific limits (typically 10000 for files, 100 for parts).\n */\n pageSize?: number\n /**\n * Aborts the iteration between fetches. When already aborted at call time,\n * the iterator throws immediately on its first `next()` call.\n *\n * Note: this does NOT abort an in-flight HTTP request mid-page. The\n * iterator checks `signal.throwIfAborted()` only between fetches.\n */\n signal?: AbortSignal\n}\n\n/**\n * Function that fetches a single page given a cursor.\n *\n * The cursor is `undefined` for the first page, then takes the value of the\n * previous page's `nextCursor` on subsequent calls. Iteration stops when\n * `nextCursor` is `undefined` (or any other falsy value the caller maps to\n * `undefined`).\n *\n * @typeParam Page - The per-page response shape returned by the B2 endpoint.\n * @typeParam Cursor - The cursor type (typically `string` or a `{name, id}` pair).\n */\nexport type PageFetcher<Page, Cursor> = (cursor: Cursor | undefined) => Promise<{\n /** The page just fetched. */\n page: Page\n /** Cursor for the next page, or `undefined` if there are no more pages. */\n nextCursor: Cursor | undefined\n}>\n\n/**\n * Async-iterates one page at a time. Stops when `fetcher` returns\n * `nextCursor: undefined`.\n *\n * @typeParam Page - The per-page response shape.\n * @typeParam Cursor - The cursor type used to request the next page.\n *\n * @param fetcher - Function that fetches one page given the current cursor.\n * @param signal - Optional abort signal. Checked before each fetch.\n *\n * @returns An async iterable of pages.\n *\n * @throws DOMException When `signal` is aborted between fetches.\n *\n * @example\n * ```ts\n * for await (const page of paginatePages(\n * async (cursor) => {\n * const resp = await bucket.listFileNames({ startFileName: cursor })\n * return { page: resp, nextCursor: resp.nextFileName ?? undefined }\n * },\n * abortSignal,\n * )) {\n * for (const file of page.files) { ... }\n * }\n * ```\n */\nexport async function* paginatePages<Page, Cursor>(\n fetcher: PageFetcher<Page, Cursor>,\n signal: AbortSignal | undefined,\n): AsyncIterableIterator<Page> {\n let cursor: Cursor | undefined\n while (true) {\n signal?.throwIfAborted()\n const { page, nextCursor } = await fetcher(cursor)\n yield page\n if (nextCursor === undefined) return\n cursor = nextCursor\n }\n}\n\n/**\n * Async-iterates items by flattening pages. The `extractItems` function\n * pulls the relevant array out of each page (e.g. `page.files`,\n * `page.keys`, `page.parts`). Each item is yielded individually so the\n * caller can `for await (const item of paginator)` rather than nest loops.\n *\n * Aborts between **pages**, not between items: if `signal` is aborted while\n * the caller is processing the items of page N, the iterator will still\n * yield all of page N's remaining items before checking the signal before\n * fetching page N+1.\n *\n * @typeParam Page - The per-page response shape.\n * @typeParam Cursor - The cursor type used to request the next page.\n * @typeParam Item - The item type the caller wants to iterate.\n *\n * @param fetcher - Function that fetches one page given the current cursor.\n * @param extractItems - Pulls the iterable items out of a page.\n * @param signal - Optional abort signal. Checked before each fetch.\n *\n * @returns An async iterable of individual items.\n *\n * @throws DOMException When `signal` is aborted between fetches.\n */\nexport async function* paginateItems<Page, Cursor, Item>(\n fetcher: PageFetcher<Page, Cursor>,\n extractItems: (page: Page) => Iterable<Item>,\n signal: AbortSignal | undefined,\n): AsyncIterableIterator<Item> {\n for await (const page of paginatePages(fetcher, signal)) {\n yield* extractItems(page)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,gBAAuB,cACrB,SACA,QAC6B;CAC7B,IAAI;CACJ,OAAO,MAAM;EACX,QAAQ,eAAe;EACvB,MAAM,EAAE,MAAM,eAAe,MAAM,QAAQ,MAAM;EACjD,MAAM;EACN,IAAI,eAAe,KAAA,GAAW;EAC9B,SAAS;CACX;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,gBAAuB,cACrB,SACA,cACA,QAC6B;CAC7B,WAAW,MAAM,QAAQ,cAAc,SAAS,MAAM,GACpD,OAAO,aAAa,IAAI;AAE5B"}
1
+ {"version":3,"file":"paginator.js","names":[],"sources":["../../src/util/paginator.ts"],"sourcesContent":["/**\n * Generic pagination helpers for B2 list endpoints.\n *\n * B2 returns paginated results as `{ items, nextCursor }` shapes that differ\n * per endpoint (`nextFileName`, `nextFileId`, `nextPartNumber`,\n * `nextApplicationKeyId`, etc.). These helpers let callers iterate without\n * threading the cursor by hand.\n *\n * Two flavours:\n * - {@link paginatePages} yields each page as the server returned it.\n * Useful when the caller wants the per-page response object (e.g. for\n * access to per-page metadata or to control item-iteration order).\n * - {@link paginateItems} flattens pages and yields individual items.\n * Useful for the common \"iterate everything\" case.\n *\n * Both helpers honour an optional {@link AbortSignal} that aborts the\n * iteration **between fetches**. They do NOT abort an in-flight network\n * request: the underlying list call has its own `signal` parameter and\n * each consumer must wire that through if mid-flight cancellation is\n * required.\n *\n * @packageDocumentation\n *\n * @example\n * ```ts\n * for await (const file of bucket.paginateFileNames({ prefix: 'photos/' })) {\n * console.log(file.fileName, file.contentLength)\n * }\n * ```\n *\n */\n\n/**\n * Options accepted by every `paginateX` method on `Bucket` and `B2Client`.\n */\nexport interface PaginatorOptions {\n /**\n * Maximum items per page. Forwarded to the underlying list call's\n * `maxFileCount` / `maxKeyCount` / `maxPartCount` parameter. B2 caps this\n * at endpoint-specific limits (typically 10000 for files, 100 for parts).\n */\n pageSize?: number\n /**\n * Aborts the iteration between fetches. When already aborted at call time,\n * the iterator throws immediately on its first `next()` call.\n *\n * Note: this does NOT abort an in-flight HTTP request mid-page. The\n * iterator checks `signal.throwIfAborted()` only between fetches.\n */\n signal?: AbortSignal\n}\n\n/**\n * Function that fetches a single page given a cursor.\n *\n * The cursor is `undefined` for the first page, then takes the value of the\n * previous page's `nextCursor` on subsequent calls. Iteration stops when\n * `nextCursor` is `undefined` (or any other falsy value the caller maps to\n * `undefined`).\n *\n * @typeParam Page - The per-page response shape returned by the B2 endpoint.\n * @typeParam Cursor - The cursor type (typically `string` or a `{name, id}` pair).\n */\nexport type PageFetcher<Page, Cursor> = (cursor: Cursor | undefined) => Promise<{\n /** The page just fetched. */\n page: Page\n /** Cursor for the next page, or `undefined` if there are no more pages. */\n nextCursor: Cursor | undefined\n}>\n\nfunction isPrimitiveCursor(cursor: unknown): boolean {\n return cursor === null || (typeof cursor !== 'object' && typeof cursor !== 'function')\n}\n\n/**\n * Async-iterates one page at a time. Stops when `fetcher` returns\n * `nextCursor: undefined` or a primitive cursor that is identical to the\n * cursor just used, which prevents non-advancing server cursors from looping\n * forever.\n *\n * @typeParam Page - The per-page response shape.\n * @typeParam Cursor - The cursor type used to request the next page.\n *\n * @param fetcher - Function that fetches one page given the current cursor.\n * @param signal - Optional abort signal. Checked before each fetch.\n *\n * @returns An async iterable of pages.\n *\n * @throws DOMException When `signal` is aborted between fetches.\n *\n * @example\n * ```ts\n * for await (const page of paginatePages(\n * async (cursor) => {\n * const resp = await bucket.listFileNames({ startFileName: cursor })\n * return { page: resp, nextCursor: resp.nextFileName ?? undefined }\n * },\n * abortSignal,\n * )) {\n * for (const file of page.files) { ... }\n * }\n * ```\n */\nexport async function* paginatePages<Page, Cursor>(\n fetcher: PageFetcher<Page, Cursor>,\n signal: AbortSignal | undefined,\n): AsyncIterableIterator<Page> {\n let cursor: Cursor | undefined\n while (true) {\n signal?.throwIfAborted()\n const { page, nextCursor } = await fetcher(cursor)\n yield page\n if (nextCursor === undefined) return\n if (\n cursor !== undefined &&\n isPrimitiveCursor(cursor) &&\n isPrimitiveCursor(nextCursor) &&\n Object.is(nextCursor, cursor)\n ) {\n return\n }\n cursor = nextCursor\n }\n}\n\n/**\n * Async-iterates items by flattening pages. The `extractItems` function\n * pulls the relevant array out of each page (e.g. `page.files`,\n * `page.keys`, `page.parts`). Each item is yielded individually so the\n * caller can `for await (const item of paginator)` rather than nest loops.\n *\n * Aborts between **pages**, not between items: if `signal` is aborted while\n * the caller is processing the items of page N, the iterator will still\n * yield all of page N's remaining items before checking the signal before\n * fetching page N+1.\n *\n * @typeParam Page - The per-page response shape.\n * @typeParam Cursor - The cursor type used to request the next page.\n * @typeParam Item - The item type the caller wants to iterate.\n *\n * @param fetcher - Function that fetches one page given the current cursor.\n * @param extractItems - Pulls the iterable items out of a page.\n * @param signal - Optional abort signal. Checked before each fetch.\n *\n * @returns An async iterable of individual items.\n *\n * @throws DOMException When `signal` is aborted between fetches.\n */\nexport async function* paginateItems<Page, Cursor, Item>(\n fetcher: PageFetcher<Page, Cursor>,\n extractItems: (page: Page) => Iterable<Item>,\n signal: AbortSignal | undefined,\n): AsyncIterableIterator<Item> {\n for await (const page of paginatePages(fetcher, signal)) {\n yield* extractItems(page)\n }\n}\n"],"mappings":";AAsEA,SAAS,kBAAkB,QAA0B;CACnD,OAAO,WAAW,QAAS,OAAO,WAAW,YAAY,OAAO,WAAW;AAC7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,gBAAuB,cACrB,SACA,QAC6B;CAC7B,IAAI;CACJ,OAAO,MAAM;EACX,QAAQ,eAAe;EACvB,MAAM,EAAE,MAAM,eAAe,MAAM,QAAQ,MAAM;EACjD,MAAM;EACN,IAAI,eAAe,KAAA,GAAW;EAC9B,IACE,WAAW,KAAA,KACX,kBAAkB,MAAM,KACxB,kBAAkB,UAAU,KAC5B,OAAO,GAAG,YAAY,MAAM,GAE5B;EAEF,SAAS;CACX;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,gBAAuB,cACrB,SACA,cACA,QAC6B;CAC7B,WAAW,MAAM,QAAQ,cAAc,SAAS,MAAM,GACpD,OAAO,aAAa,IAAI;AAE5B"}
package/dist/version.cjs CHANGED
@@ -1,18 +1,70 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
2
  //#region src/version.ts
2
3
  /**
3
4
  * Current SDK version. Read directly from package.json so there is no
4
5
  * second-source-of-truth to keep in sync — bumping `version` in package.json
5
- * automatically propagates here, into the SDK's User-Agent header, and into
6
- * the published artifact.
6
+ * automatically propagates here and into the published artifact. The outbound
7
+ * SDK User-Agent uses the resolved product version segment so source, CI,
8
+ * `npm pack`, and prerelease builds advertise `dev` instead of a real-looking
9
+ * release number.
7
10
  *
8
11
  * Works in every runtime the SDK targets:
9
12
  * - Node 22.3+, Bun, Deno: native JSON import attributes.
10
- * - Vite builds: the JSON import is replaced with a version-only shim so
11
- * published runtime chunks do not carry unrelated package metadata.
13
+ * - Vite builds: the JSON import is replaced with a version-only shim, and
14
+ * the publish path injects the release-channel define as `published`.
15
+ * Other builds leave the define absent, so runtime chunks do not carry
16
+ * unrelated package metadata.
12
17
  * - Vitest browser mode: Vite handles the import the same way as build.
13
18
  */
14
19
  var VERSION = require("./_virtual/_b2-sdk-version-json.cjs").default.version;
20
+ var configuredReleaseSignal = "published";
21
+ function isStableSemver(version) {
22
+ return !(version.split("+", 1)[0] ?? version).includes("-");
23
+ }
24
+ /**
25
+ * Resolve build version metadata from a version and positive release signal.
26
+ *
27
+ * @param version - Build semver read from package.json.
28
+ * @param releaseSignal - Build-time release signal. Only `published` enables
29
+ * the published channel, and prerelease semvers still resolve to `dev`.
30
+ *
31
+ * @returns The release-channel decision and User-Agent version segment.
32
+ */
33
+ function resolveVersion(version, releaseSignal = "dev") {
34
+ const isStableVersion = isStableSemver(version);
35
+ const isRelease = releaseSignal === "published" && isStableVersion;
36
+ return {
37
+ version,
38
+ releaseChannel: isRelease ? "published" : "dev",
39
+ isPublishedRelease: isRelease,
40
+ productVersion: isRelease ? version : "dev"
41
+ };
42
+ }
43
+ var resolvedVersion = resolveVersion(VERSION, configuredReleaseSignal);
44
+ /**
45
+ * Current release channel. Defaults to `dev` unless the publish path injected
46
+ * the positive release signal for a stable semver.
47
+ */
48
+ var RELEASE_CHANNEL = resolvedVersion.releaseChannel;
49
+ /**
50
+ * Whether the current artifact is a stable package built through the publish path.
51
+ */
52
+ var isPublishedRelease = resolvedVersion.isPublishedRelease;
53
+ /**
54
+ * Version segment for the SDK User-Agent product token.
55
+ * Kept as a function because it is derived resolver output consumed by the
56
+ * User-Agent builder, not a second version constant for callers to maintain.
57
+ *
58
+ * @returns The package semver for stable published releases, otherwise `dev`.
59
+ */
60
+ function productVersion() {
61
+ return resolvedVersion.productVersion;
62
+ }
15
63
  //#endregion
64
+ exports.RELEASE_CHANNEL = RELEASE_CHANNEL;
16
65
  exports.VERSION = VERSION;
66
+ exports.isPublishedRelease = isPublishedRelease;
67
+ exports.productVersion = productVersion;
68
+ exports.resolveVersion = resolveVersion;
17
69
 
18
70
  //# sourceMappingURL=version.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["import pkg from '../package.json' with { type: 'json' }\n\n/**\n * Current SDK version. Read directly from package.json so there is no\n * second-source-of-truth to keep in sync — bumping `version` in package.json\n * automatically propagates here, into the SDK's User-Agent header, and into\n * the published artifact.\n *\n * Works in every runtime the SDK targets:\n * - Node 22.3+, Bun, Deno: native JSON import attributes.\n * - Vite builds: the JSON import is replaced with a version-only shim so\n * published runtime chunks do not carry unrelated package metadata.\n * - Vitest browser mode: Vite handles the import the same way as build.\n */\nexport const VERSION: string = pkg.version\n"],"mappings":";;;;;;;;;;;;;AAcA,IAAa,uDAAkB,CAAA,CAAA,QAAI"}
1
+ {"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["import pkg from '../package.json' with { type: 'json' }\n\ndeclare const __B2_SDK_RELEASE_CHANNEL__: string | undefined\n\n/**\n * Release channel used to decide what the SDK advertises in its User-Agent\n * product token.\n */\nexport type ReleaseChannel = 'dev' | 'published'\n\n/**\n * Resolved version metadata for the current build.\n */\nexport interface VersionResolution {\n /** Build semver read from package.json. */\n readonly version: string\n /** Release channel after applying the positive release signal. */\n readonly releaseChannel: ReleaseChannel\n /** Whether this build is a stable package published through the release path. */\n readonly isPublishedRelease: boolean\n /** Version segment for the SDK User-Agent product token. */\n readonly productVersion: string\n}\n\n/**\n * Current SDK version. Read directly from package.json so there is no\n * second-source-of-truth to keep in sync — bumping `version` in package.json\n * automatically propagates here and into the published artifact. The outbound\n * SDK User-Agent uses the resolved product version segment so source, CI,\n * `npm pack`, and prerelease builds advertise `dev` instead of a real-looking\n * release number.\n *\n * Works in every runtime the SDK targets:\n * - Node 22.3+, Bun, Deno: native JSON import attributes.\n * - Vite builds: the JSON import is replaced with a version-only shim, and\n * the publish path injects the release-channel define as `published`.\n * Other builds leave the define absent, so runtime chunks do not carry\n * unrelated package metadata.\n * - Vitest browser mode: Vite handles the import the same way as build.\n */\nexport const VERSION: string = pkg.version\n\nconst configuredReleaseSignal =\n typeof __B2_SDK_RELEASE_CHANNEL__ === 'string' ? __B2_SDK_RELEASE_CHANNEL__ : 'dev'\n\nfunction isStableSemver(version: string): boolean {\n const versionWithoutBuildMetadata = version.split('+', 1)[0] ?? version\n return !versionWithoutBuildMetadata.includes('-')\n}\n\n/**\n * Resolve build version metadata from a version and positive release signal.\n *\n * @param version - Build semver read from package.json.\n * @param releaseSignal - Build-time release signal. Only `published` enables\n * the published channel, and prerelease semvers still resolve to `dev`.\n *\n * @returns The release-channel decision and User-Agent version segment.\n */\nexport function resolveVersion(\n version: string,\n releaseSignal: string | undefined = 'dev',\n): VersionResolution {\n const isStableVersion = isStableSemver(version)\n const isRelease = releaseSignal === 'published' && isStableVersion\n const releaseChannel = isRelease ? 'published' : 'dev'\n\n return {\n version,\n releaseChannel,\n isPublishedRelease: isRelease,\n productVersion: isRelease ? version : 'dev',\n }\n}\n\nconst resolvedVersion = resolveVersion(VERSION, configuredReleaseSignal)\n\n/**\n * Current release channel. Defaults to `dev` unless the publish path injected\n * the positive release signal for a stable semver.\n */\nexport const RELEASE_CHANNEL: ReleaseChannel = resolvedVersion.releaseChannel\n\n/**\n * Whether the current artifact is a stable package built through the publish path.\n */\nexport const isPublishedRelease: boolean = resolvedVersion.isPublishedRelease\n\n/**\n * Version segment for the SDK User-Agent product token.\n * Kept as a function because it is derived resolver output consumed by the\n * User-Agent builder, not a second version constant for callers to maintain.\n *\n * @returns The package semver for stable published releases, otherwise `dev`.\n */\nexport function productVersion(): string {\n return resolvedVersion.productVersion\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwCA,IAAa,uDAAkB,CAAA,CAAA,QAAI;AAEnC,IAAM,0BAAA;AAGN,SAAS,eAAe,SAA0B;CAEhD,OAAO,EAD6B,QAAQ,MAAM,KAAK,CAAC,CAAC,CAAC,MAAM,QAAA,CAC5B,SAAS,GAAG;AAClD;;;;;;;;;;AAWA,SAAgB,eACd,SACA,gBAAoC,OACjB;CACnB,MAAM,kBAAkB,eAAe,OAAO;CAC9C,MAAM,YAAY,kBAAkB,eAAe;CAGnD,OAAO;EACL;EACA,gBAJqB,YAAY,cAAc;EAK/C,oBAAoB;EACpB,gBAAgB,YAAY,UAAU;CACxC;AACF;AAEA,IAAM,kBAAkB,eAAe,SAAS,uBAAuB;;;;;AAMvE,IAAa,kBAAkC,gBAAgB;;;;AAK/D,IAAa,qBAA8B,gBAAgB;;;;;;;;AAS3D,SAAgB,iBAAyB;CACvC,OAAO,gBAAgB;AACzB"}
@@ -1,14 +1,63 @@
1
+ /**
2
+ * Release channel used to decide what the SDK advertises in its User-Agent
3
+ * product token.
4
+ */
5
+ export type ReleaseChannel = 'dev' | 'published';
6
+ /**
7
+ * Resolved version metadata for the current build.
8
+ */
9
+ export interface VersionResolution {
10
+ /** Build semver read from package.json. */
11
+ readonly version: string;
12
+ /** Release channel after applying the positive release signal. */
13
+ readonly releaseChannel: ReleaseChannel;
14
+ /** Whether this build is a stable package published through the release path. */
15
+ readonly isPublishedRelease: boolean;
16
+ /** Version segment for the SDK User-Agent product token. */
17
+ readonly productVersion: string;
18
+ }
1
19
  /**
2
20
  * Current SDK version. Read directly from package.json so there is no
3
21
  * second-source-of-truth to keep in sync — bumping `version` in package.json
4
- * automatically propagates here, into the SDK's User-Agent header, and into
5
- * the published artifact.
22
+ * automatically propagates here and into the published artifact. The outbound
23
+ * SDK User-Agent uses the resolved product version segment so source, CI,
24
+ * `npm pack`, and prerelease builds advertise `dev` instead of a real-looking
25
+ * release number.
6
26
  *
7
27
  * Works in every runtime the SDK targets:
8
28
  * - Node 22.3+, Bun, Deno: native JSON import attributes.
9
- * - Vite builds: the JSON import is replaced with a version-only shim so
10
- * published runtime chunks do not carry unrelated package metadata.
29
+ * - Vite builds: the JSON import is replaced with a version-only shim, and
30
+ * the publish path injects the release-channel define as `published`.
31
+ * Other builds leave the define absent, so runtime chunks do not carry
32
+ * unrelated package metadata.
11
33
  * - Vitest browser mode: Vite handles the import the same way as build.
12
34
  */
13
35
  export declare const VERSION: string;
36
+ /**
37
+ * Resolve build version metadata from a version and positive release signal.
38
+ *
39
+ * @param version - Build semver read from package.json.
40
+ * @param releaseSignal - Build-time release signal. Only `published` enables
41
+ * the published channel, and prerelease semvers still resolve to `dev`.
42
+ *
43
+ * @returns The release-channel decision and User-Agent version segment.
44
+ */
45
+ export declare function resolveVersion(version: string, releaseSignal?: string | undefined): VersionResolution;
46
+ /**
47
+ * Current release channel. Defaults to `dev` unless the publish path injected
48
+ * the positive release signal for a stable semver.
49
+ */
50
+ export declare const RELEASE_CHANNEL: ReleaseChannel;
51
+ /**
52
+ * Whether the current artifact is a stable package built through the publish path.
53
+ */
54
+ export declare const isPublishedRelease: boolean;
55
+ /**
56
+ * Version segment for the SDK User-Agent product token.
57
+ * Kept as a function because it is derived resolver output consumed by the
58
+ * User-Agent builder, not a second version constant for callers to maintain.
59
+ *
60
+ * @returns The package semver for stable published releases, otherwise `dev`.
61
+ */
62
+ export declare function productVersion(): string;
14
63
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,EAAE,MAAoB,CAAA"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.js"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,WAAW,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,kEAAkE;IAClE,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAA;IACvC,iFAAiF;IACjF,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAA;IACpC,4DAA4D;IAC5D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;CAChC;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,OAAO,EAAE,MAAoB,CAAA;AAU1C;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,MAAM,GAAG,SAAiB,GACxC,iBAAiB,CAWnB;AAID;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,cAA+C,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAA4C,CAAA;AAE7E;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
package/dist/version.d.ts CHANGED
@@ -1,14 +1,63 @@
1
+ /**
2
+ * Release channel used to decide what the SDK advertises in its User-Agent
3
+ * product token.
4
+ */
5
+ export type ReleaseChannel = 'dev' | 'published';
6
+ /**
7
+ * Resolved version metadata for the current build.
8
+ */
9
+ export interface VersionResolution {
10
+ /** Build semver read from package.json. */
11
+ readonly version: string;
12
+ /** Release channel after applying the positive release signal. */
13
+ readonly releaseChannel: ReleaseChannel;
14
+ /** Whether this build is a stable package published through the release path. */
15
+ readonly isPublishedRelease: boolean;
16
+ /** Version segment for the SDK User-Agent product token. */
17
+ readonly productVersion: string;
18
+ }
1
19
  /**
2
20
  * Current SDK version. Read directly from package.json so there is no
3
21
  * second-source-of-truth to keep in sync — bumping `version` in package.json
4
- * automatically propagates here, into the SDK's User-Agent header, and into
5
- * the published artifact.
22
+ * automatically propagates here and into the published artifact. The outbound
23
+ * SDK User-Agent uses the resolved product version segment so source, CI,
24
+ * `npm pack`, and prerelease builds advertise `dev` instead of a real-looking
25
+ * release number.
6
26
  *
7
27
  * Works in every runtime the SDK targets:
8
28
  * - Node 22.3+, Bun, Deno: native JSON import attributes.
9
- * - Vite builds: the JSON import is replaced with a version-only shim so
10
- * published runtime chunks do not carry unrelated package metadata.
29
+ * - Vite builds: the JSON import is replaced with a version-only shim, and
30
+ * the publish path injects the release-channel define as `published`.
31
+ * Other builds leave the define absent, so runtime chunks do not carry
32
+ * unrelated package metadata.
11
33
  * - Vitest browser mode: Vite handles the import the same way as build.
12
34
  */
13
35
  export declare const VERSION: string;
36
+ /**
37
+ * Resolve build version metadata from a version and positive release signal.
38
+ *
39
+ * @param version - Build semver read from package.json.
40
+ * @param releaseSignal - Build-time release signal. Only `published` enables
41
+ * the published channel, and prerelease semvers still resolve to `dev`.
42
+ *
43
+ * @returns The release-channel decision and User-Agent version segment.
44
+ */
45
+ export declare function resolveVersion(version: string, releaseSignal?: string | undefined): VersionResolution;
46
+ /**
47
+ * Current release channel. Defaults to `dev` unless the publish path injected
48
+ * the positive release signal for a stable semver.
49
+ */
50
+ export declare const RELEASE_CHANNEL: ReleaseChannel;
51
+ /**
52
+ * Whether the current artifact is a stable package built through the publish path.
53
+ */
54
+ export declare const isPublishedRelease: boolean;
55
+ /**
56
+ * Version segment for the SDK User-Agent product token.
57
+ * Kept as a function because it is derived resolver output consumed by the
58
+ * User-Agent builder, not a second version constant for callers to maintain.
59
+ *
60
+ * @returns The package semver for stable published releases, otherwise `dev`.
61
+ */
62
+ export declare function productVersion(): string;
14
63
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,EAAE,MAAoB,CAAA"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.js"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,WAAW,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,kEAAkE;IAClE,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAA;IACvC,iFAAiF;IACjF,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAA;IACpC,4DAA4D;IAC5D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;CAChC;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,OAAO,EAAE,MAAoB,CAAA;AAU1C;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,MAAM,GAAG,SAAiB,GACxC,iBAAiB,CAWnB;AAID;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,cAA+C,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAA4C,CAAA;AAE7E;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
package/dist/version.js CHANGED
@@ -3,17 +3,64 @@ import _b2_sdk_version_json_default from "./_virtual/_b2-sdk-version-json.js";
3
3
  /**
4
4
  * Current SDK version. Read directly from package.json so there is no
5
5
  * second-source-of-truth to keep in sync — bumping `version` in package.json
6
- * automatically propagates here, into the SDK's User-Agent header, and into
7
- * the published artifact.
6
+ * automatically propagates here and into the published artifact. The outbound
7
+ * SDK User-Agent uses the resolved product version segment so source, CI,
8
+ * `npm pack`, and prerelease builds advertise `dev` instead of a real-looking
9
+ * release number.
8
10
  *
9
11
  * Works in every runtime the SDK targets:
10
12
  * - Node 22.3+, Bun, Deno: native JSON import attributes.
11
- * - Vite builds: the JSON import is replaced with a version-only shim so
12
- * published runtime chunks do not carry unrelated package metadata.
13
+ * - Vite builds: the JSON import is replaced with a version-only shim, and
14
+ * the publish path injects the release-channel define as `published`.
15
+ * Other builds leave the define absent, so runtime chunks do not carry
16
+ * unrelated package metadata.
13
17
  * - Vitest browser mode: Vite handles the import the same way as build.
14
18
  */
15
19
  var VERSION = _b2_sdk_version_json_default.version;
20
+ var configuredReleaseSignal = "published";
21
+ function isStableSemver(version) {
22
+ return !(version.split("+", 1)[0] ?? version).includes("-");
23
+ }
24
+ /**
25
+ * Resolve build version metadata from a version and positive release signal.
26
+ *
27
+ * @param version - Build semver read from package.json.
28
+ * @param releaseSignal - Build-time release signal. Only `published` enables
29
+ * the published channel, and prerelease semvers still resolve to `dev`.
30
+ *
31
+ * @returns The release-channel decision and User-Agent version segment.
32
+ */
33
+ function resolveVersion(version, releaseSignal = "dev") {
34
+ const isStableVersion = isStableSemver(version);
35
+ const isRelease = releaseSignal === "published" && isStableVersion;
36
+ return {
37
+ version,
38
+ releaseChannel: isRelease ? "published" : "dev",
39
+ isPublishedRelease: isRelease,
40
+ productVersion: isRelease ? version : "dev"
41
+ };
42
+ }
43
+ var resolvedVersion = resolveVersion(VERSION, configuredReleaseSignal);
44
+ /**
45
+ * Current release channel. Defaults to `dev` unless the publish path injected
46
+ * the positive release signal for a stable semver.
47
+ */
48
+ var RELEASE_CHANNEL = resolvedVersion.releaseChannel;
49
+ /**
50
+ * Whether the current artifact is a stable package built through the publish path.
51
+ */
52
+ var isPublishedRelease = resolvedVersion.isPublishedRelease;
53
+ /**
54
+ * Version segment for the SDK User-Agent product token.
55
+ * Kept as a function because it is derived resolver output consumed by the
56
+ * User-Agent builder, not a second version constant for callers to maintain.
57
+ *
58
+ * @returns The package semver for stable published releases, otherwise `dev`.
59
+ */
60
+ function productVersion() {
61
+ return resolvedVersion.productVersion;
62
+ }
16
63
  //#endregion
17
- export { VERSION };
64
+ export { RELEASE_CHANNEL, VERSION, isPublishedRelease, productVersion, resolveVersion };
18
65
 
19
66
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../src/version.ts"],"sourcesContent":["import pkg from '../package.json' with { type: 'json' }\n\n/**\n * Current SDK version. Read directly from package.json so there is no\n * second-source-of-truth to keep in sync — bumping `version` in package.json\n * automatically propagates here, into the SDK's User-Agent header, and into\n * the published artifact.\n *\n * Works in every runtime the SDK targets:\n * - Node 22.3+, Bun, Deno: native JSON import attributes.\n * - Vite builds: the JSON import is replaced with a version-only shim so\n * published runtime chunks do not carry unrelated package metadata.\n * - Vitest browser mode: Vite handles the import the same way as build.\n */\nexport const VERSION: string = pkg.version\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,UAAkB,6BAAI"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../src/version.ts"],"sourcesContent":["import pkg from '../package.json' with { type: 'json' }\n\ndeclare const __B2_SDK_RELEASE_CHANNEL__: string | undefined\n\n/**\n * Release channel used to decide what the SDK advertises in its User-Agent\n * product token.\n */\nexport type ReleaseChannel = 'dev' | 'published'\n\n/**\n * Resolved version metadata for the current build.\n */\nexport interface VersionResolution {\n /** Build semver read from package.json. */\n readonly version: string\n /** Release channel after applying the positive release signal. */\n readonly releaseChannel: ReleaseChannel\n /** Whether this build is a stable package published through the release path. */\n readonly isPublishedRelease: boolean\n /** Version segment for the SDK User-Agent product token. */\n readonly productVersion: string\n}\n\n/**\n * Current SDK version. Read directly from package.json so there is no\n * second-source-of-truth to keep in sync — bumping `version` in package.json\n * automatically propagates here and into the published artifact. The outbound\n * SDK User-Agent uses the resolved product version segment so source, CI,\n * `npm pack`, and prerelease builds advertise `dev` instead of a real-looking\n * release number.\n *\n * Works in every runtime the SDK targets:\n * - Node 22.3+, Bun, Deno: native JSON import attributes.\n * - Vite builds: the JSON import is replaced with a version-only shim, and\n * the publish path injects the release-channel define as `published`.\n * Other builds leave the define absent, so runtime chunks do not carry\n * unrelated package metadata.\n * - Vitest browser mode: Vite handles the import the same way as build.\n */\nexport const VERSION: string = pkg.version\n\nconst configuredReleaseSignal =\n typeof __B2_SDK_RELEASE_CHANNEL__ === 'string' ? __B2_SDK_RELEASE_CHANNEL__ : 'dev'\n\nfunction isStableSemver(version: string): boolean {\n const versionWithoutBuildMetadata = version.split('+', 1)[0] ?? version\n return !versionWithoutBuildMetadata.includes('-')\n}\n\n/**\n * Resolve build version metadata from a version and positive release signal.\n *\n * @param version - Build semver read from package.json.\n * @param releaseSignal - Build-time release signal. Only `published` enables\n * the published channel, and prerelease semvers still resolve to `dev`.\n *\n * @returns The release-channel decision and User-Agent version segment.\n */\nexport function resolveVersion(\n version: string,\n releaseSignal: string | undefined = 'dev',\n): VersionResolution {\n const isStableVersion = isStableSemver(version)\n const isRelease = releaseSignal === 'published' && isStableVersion\n const releaseChannel = isRelease ? 'published' : 'dev'\n\n return {\n version,\n releaseChannel,\n isPublishedRelease: isRelease,\n productVersion: isRelease ? version : 'dev',\n }\n}\n\nconst resolvedVersion = resolveVersion(VERSION, configuredReleaseSignal)\n\n/**\n * Current release channel. Defaults to `dev` unless the publish path injected\n * the positive release signal for a stable semver.\n */\nexport const RELEASE_CHANNEL: ReleaseChannel = resolvedVersion.releaseChannel\n\n/**\n * Whether the current artifact is a stable package built through the publish path.\n */\nexport const isPublishedRelease: boolean = resolvedVersion.isPublishedRelease\n\n/**\n * Version segment for the SDK User-Agent product token.\n * Kept as a function because it is derived resolver output consumed by the\n * User-Agent builder, not a second version constant for callers to maintain.\n *\n * @returns The package semver for stable published releases, otherwise `dev`.\n */\nexport function productVersion(): string {\n return resolvedVersion.productVersion\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwCA,IAAa,UAAkB,6BAAI;AAEnC,IAAM,0BAAA;AAGN,SAAS,eAAe,SAA0B;CAEhD,OAAO,EAD6B,QAAQ,MAAM,KAAK,CAAC,CAAC,CAAC,MAAM,QAAA,CAC5B,SAAS,GAAG;AAClD;;;;;;;;;;AAWA,SAAgB,eACd,SACA,gBAAoC,OACjB;CACnB,MAAM,kBAAkB,eAAe,OAAO;CAC9C,MAAM,YAAY,kBAAkB,eAAe;CAGnD,OAAO;EACL;EACA,gBAJqB,YAAY,cAAc;EAK/C,oBAAoB;EACpB,gBAAgB,YAAY,UAAU;CACxC;AACF;AAEA,IAAM,kBAAkB,eAAe,SAAS,uBAAuB;;;;;AAMvE,IAAa,kBAAkC,gBAAgB;;;;AAK/D,IAAa,qBAA8B,gBAAgB;;;;;;;;AAS3D,SAAgB,iBAAyB;CACvC,OAAO,gBAAgB;AACzB"}