@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":"validation.js","names":[],"sources":["../../src/simulator/validation.ts"],"sourcesContent":["/**\n * B2 spec-compliance validation helpers for the simulator.\n *\n * Each function mirrors a documented B2 input limit (file name length,\n * bucket name regex, file-info byte budget, etc.). Validators return\n * `null` for valid input or a `{ code, message }` pair that the handler\n * converts into a synthetic `400`/`403` response with the right B2\n * error code.\n *\n * Keeping validation in one module makes the simulator's \"what does B2\n * reject?\" surface auditable in a single file. Doc references inline at\n * each rule so the spec source is immediate.\n *\n * @packageDocumentation\n */\n\nimport {\n BUCKET_NAME_MAX,\n BUCKET_NAME_MIN,\n BUCKET_NAME_RESERVED_PREFIX,\n FILE_NAME_MAX_BYTES,\n getB2FileNameByteLength,\n hasB2FileNameControlCharacter,\n hasValidB2BucketNameShape,\n isB2BucketNameIpv4Address,\n} from '../internal/b2-naming.ts'\nimport { utf8Encoder } from '../util/text-codec.ts'\n\n/** Shape returned by validation functions when input is rejected. */\nexport interface ValidationError {\n readonly code: string\n readonly message: string\n}\n\n// ---------------------------------------------------------------------------\n// Bucket name (`b2_create_bucket`, `b2_update_bucket`)\n// ---------------------------------------------------------------------------\n\nexport { BUCKET_NAME_MAX, BUCKET_NAME_MIN }\n\n/**\n * Validates a bucket name against B2's documented rules.\n *\n * @param name - Caller-supplied bucket name.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-bucket\n */\nexport function validateBucketName(name: string): ValidationError | null {\n if (typeof name !== 'string' || name.length < BUCKET_NAME_MIN || name.length > BUCKET_NAME_MAX) {\n return {\n code: 'invalid_bucket_name',\n message: `bucketName must be ${BUCKET_NAME_MIN}-${BUCKET_NAME_MAX} characters`,\n }\n }\n if (isB2BucketNameIpv4Address(name)) {\n return {\n code: 'invalid_bucket_name',\n message: 'bucketName must not be formatted as an IPv4 address',\n }\n }\n if (!hasValidB2BucketNameShape(name)) {\n return {\n code: 'invalid_bucket_name',\n message:\n 'bucketName must contain only letters, digits, hyphens, and periods; cannot start or end with punctuation or contain consecutive periods',\n }\n }\n if (name.startsWith(BUCKET_NAME_RESERVED_PREFIX)) {\n return {\n code: 'invalid_bucket_name',\n message: `bucketName cannot start with the reserved prefix \"${BUCKET_NAME_RESERVED_PREFIX}\"`,\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// File name (every upload / hide / copy entry point)\n// ---------------------------------------------------------------------------\n\nexport { FILE_NAME_MAX_BYTES }\n\n/**\n * Validates a file name against B2's documented rules. Mirrors the\n * server-side checks B2 runs on `b2_upload_file` / `b2_hide_file` /\n * `b2_start_large_file` / `b2_copy_file` filename inputs.\n *\n * @param name - Caller-supplied file name (raw, unencoded).\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-upload-file\n */\nexport function validateFileName(name: string): ValidationError | null {\n if (typeof name !== 'string' || name.length === 0) {\n return { code: 'invalid_file_name', message: 'fileName must be a non-empty string' }\n }\n const byteLength = getB2FileNameByteLength(name)\n if (byteLength === null) {\n return {\n code: 'invalid_file_name',\n message: 'fileName exceeds the 1024-byte UTF-8 limit',\n }\n }\n if (hasB2FileNameControlCharacter(name)) {\n return {\n code: 'invalid_file_name',\n message: 'fileName must not contain control characters (U+0000-U+001F or U+007F)',\n }\n }\n // Path segments equal to `.` or `..` alone are illegal per B2 docs.\n // Embedded `..` within a segment (e.g. `a..b`) is fine, and a path\n // like `../foo` is fine because the SDK doesn't interpret it; only\n // bare `.` or `..` as a complete name is rejected.\n if (name === '.' || name === '..') {\n return {\n code: 'invalid_file_name',\n message: 'fileName cannot be exactly \".\" or \"..\"',\n }\n }\n // No leading or trailing slash, no `//`.\n if (name.startsWith('/') || name.endsWith('/') || name.includes('//')) {\n return {\n code: 'invalid_file_name',\n message: 'fileName cannot start with \"/\", end with \"/\", or contain \"//\"',\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// File-info / Bucket-info byte budget\n// ---------------------------------------------------------------------------\n\n/** Per-file fileInfo total size cap (sum of key+value bytes). */\nexport const FILE_INFO_TOTAL_MAX = 2048\n/** Per-key fileInfo value byte cap. */\nexport const FILE_INFO_VALUE_MAX = 2048\n/** Allowed key character set (case-insensitive). */\nconst FILE_INFO_KEY_REGEX = /^[a-zA-Z0-9_-]+$/\n\n/**\n * Validates a `fileInfo` record against B2's byte-budget and\n * key-shape rules.\n *\n * @param info - Caller-supplied fileInfo record.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-upload-file\n */\nexport function validateFileInfo(info: Record<string, string>): ValidationError | null {\n let total = 0\n for (const [key, value] of Object.entries(info)) {\n if (!FILE_INFO_KEY_REGEX.test(key)) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo key \"${key}\" must match ^[a-zA-Z0-9_-]+$`,\n }\n }\n if (typeof value !== 'string') {\n return { code: 'invalid_file_info', message: `fileInfo value for \"${key}\" must be a string` }\n }\n const keyBytes = utf8Encoder.encode(key).byteLength\n const valueBytes = utf8Encoder.encode(value).byteLength\n if (valueBytes > FILE_INFO_VALUE_MAX) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo value for \"${key}\" exceeds ${FILE_INFO_VALUE_MAX} bytes`,\n }\n }\n total += keyBytes + valueBytes\n }\n if (total > FILE_INFO_TOTAL_MAX) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo total size ${total} bytes exceeds the ${FILE_INFO_TOTAL_MAX}-byte limit`,\n }\n }\n return null\n}\n\n/** Per-bucket bucketInfo total max keys. */\nexport const BUCKET_INFO_MAX_KEYS = 10\n/** Per-key bucketInfo value byte cap. */\nexport const BUCKET_INFO_VALUE_MAX = 2048\n/** Allowed key character set for bucketInfo. */\nconst BUCKET_INFO_KEY_REGEX = /^[a-zA-Z0-9_-]+$/\n\n/**\n * Validates a `bucketInfo` record against B2's per-bucket metadata rules.\n *\n * @param info - Caller-supplied bucketInfo record.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-bucket\n */\nexport function validateBucketInfo(info: Record<string, string>): ValidationError | null {\n const entries = Object.entries(info)\n if (entries.length > BUCKET_INFO_MAX_KEYS) {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo cannot have more than ${BUCKET_INFO_MAX_KEYS} keys (got ${entries.length})`,\n }\n }\n for (const [key, value] of entries) {\n if (!BUCKET_INFO_KEY_REGEX.test(key)) {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo key \"${key}\" must match ^[a-zA-Z0-9_-]+$`,\n }\n }\n if (typeof value !== 'string') {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo value for \"${key}\" must be a string`,\n }\n }\n const valueBytes = utf8Encoder.encode(value).byteLength\n if (valueBytes > BUCKET_INFO_VALUE_MAX) {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo value for \"${key}\" exceeds ${BUCKET_INFO_VALUE_MAX} bytes`,\n }\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// maxFileCount caps per endpoint\n// ---------------------------------------------------------------------------\n\n/**\n * Per-endpoint upper bound on the `maxFileCount` (or `maxKeyCount` /\n * `maxPartCount`) request field. Sourced from the B2 endpoint docs.\n */\nexport const LIST_ENDPOINT_CAPS = {\n /** `b2_list_file_names.maxFileCount` cap. */\n b2_list_file_names: 10_000,\n /** `b2_list_file_versions.maxFileCount` cap. */\n b2_list_file_versions: 10_000,\n /** `b2_list_unfinished_large_files.maxFileCount` cap. */\n b2_list_unfinished_large_files: 100,\n /** `b2_list_keys.maxKeyCount` cap. */\n b2_list_keys: 10_000,\n /** `b2_list_parts.maxPartCount` cap. */\n b2_list_parts: 10_000,\n} as const\n\n/**\n * Validates a `maxFileCount` (or `maxKeyCount` / `maxPartCount`) value\n * against the per-endpoint cap documented by B2.\n *\n * @param requested - Caller-supplied count.\n * @param endpoint - Which list endpoint this applies to.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n */\nexport function validateMaxCount(\n requested: number | undefined,\n endpoint: keyof typeof LIST_ENDPOINT_CAPS,\n): ValidationError | null {\n if (requested === undefined) return null\n if (!Number.isInteger(requested) || requested < 1) {\n return {\n code: 'bad_request',\n message: `maxFileCount must be a positive integer (got ${requested})`,\n }\n }\n const cap = LIST_ENDPOINT_CAPS[endpoint]\n if (requested > cap) {\n return {\n code: 'bad_request',\n message: `maxFileCount ${requested} exceeds the ${endpoint} cap of ${cap}`,\n }\n }\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,mBAAmB,MAAsC;CACvE,IAAI,OAAO,SAAS,YAAY,KAAK,SAAA,KAA4B,KAAK,SAAA,IACpE,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAEF,IAAI,0BAA0B,IAAI,GAChC,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAEF,IAAI,CAAC,0BAA0B,IAAI,GACjC,OAAO;EACL,MAAM;EACN,SACE;CACJ;CAEF,IAAI,KAAK,WAAA,KAAsC,GAC7C,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAEF,OAAO;AACT;;;;;;;;;;;;AAmBA,SAAgB,iBAAiB,MAAsC;CACrE,IAAI,OAAO,SAAS,YAAY,KAAK,WAAW,GAC9C,OAAO;EAAE,MAAM;EAAqB,SAAS;CAAsC;CAGrF,IADmB,wBAAwB,IACvC,MAAe,MACjB,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAEF,IAAI,8BAA8B,IAAI,GACpC,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAMF,IAAI,SAAS,OAAO,SAAS,MAC3B,OAAO;EACL,MA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;GACL,MAAM;GACN,SAAS,yBAAyB,IAAI;EACxC;EAGF,IADmB,YAAY,OAAO,KAAK,CAAC,CAAC,aAAA,MAE3C,OAAO;GACL,MAAM;GACN,SAAS,yBAAyB,IAAI,YAAY,sBAAsB;EAC1E;CAEJ;CACA,OAAO;AACT;;;;;AAUA,IAAa,qBAAqB;;CAEhC,oBAAoB;;CAEpB,uBAAuB;;CAEvB,gCAAgC;;CAEhC,cAAc;;CAEd,eAAe;AACjB;;;;;;;;;;AAWA,SAAgB,iBACd,WACA,UACwB;CACxB,IAAI,cAAc,KAAA,GAAW,OAAO;CACpC,IAAI,CAAC,OAAO,UAAU,SAAS,KAAK,YAAY,GAC9C,OAAO;EACL,MAAM;EACN,SAAS,gDAAgD,UAAU;CACrE;CAEF,MAAM,MAAM,mBAAmB;CAC/B,IAAI,YAAY,KACd,OAAO;EACL,MAAM;EACN,SAAS,gBAAgB,UAAU,eAAe,SAAS,UAAU;CACvE;CAEF,OAAO;AACT"}
1
+ {"version":3,"file":"validation.js","names":[],"sources":["../../src/simulator/validation.ts"],"sourcesContent":["/**\n * B2 spec-compliance validation helpers for the simulator.\n *\n * Each function mirrors a documented B2 input limit (file name length,\n * bucket name regex, file-info byte budget, etc.). Validators return\n * `null` for valid input or a `{ code, message }` pair that the handler\n * converts into a synthetic `400`/`403` response with the right B2\n * error code.\n *\n * Keeping validation in one module makes the simulator's \"what does B2\n * reject?\" surface auditable in a single file. Doc references inline at\n * each rule so the spec source is immediate.\n *\n * @packageDocumentation\n */\n\nimport {\n assertValidBucketInfo as assertValidClientBucketInfo,\n assertValidCorsRules as assertValidClientCorsRules,\n} from '../bucket-validation.ts'\nimport { B2BucketConfigurationError } from '../errors/index.ts'\nimport {\n BUCKET_NAME_MAX,\n BUCKET_NAME_MIN,\n BUCKET_NAME_RESERVED_PREFIX,\n FILE_NAME_MAX_BYTES,\n getB2FileNameByteLength,\n hasB2FileNameControlCharacter,\n hasValidB2BucketNameShape,\n isB2BucketNameIpv4Address,\n} from '../internal/b2-naming.ts'\nimport { Capability } from '../types/auth.ts'\nimport {\n BUCKET_INFO_VALUES_MAX_BYTES,\n BucketRetentionMode,\n BucketType,\n CORS_MAX_AGE_SECONDS_MAX,\n CorsOperation,\n type CorsRule,\n} from '../types/bucket.ts'\nimport { EventType } from '../types/notifications.ts'\nimport { utf8Encoder } from '../util/text-codec.ts'\n\nexport {\n BUCKET_INFO_KEY_MAX_BYTES,\n BUCKET_INFO_KEY_MIN_BYTES,\n BUCKET_INFO_KEY_PATTERN,\n BUCKET_INFO_RESERVED_PREFIX,\n BUCKET_INFO_VALUES_MAX_BYTES,\n CORS_MAX_AGE_SECONDS_MAX,\n CORS_RULE_MAX_BYTES,\n CORS_RULE_NAME_MAX_LENGTH,\n CORS_RULE_NAME_MIN_LENGTH,\n CORS_RULE_NAME_PATTERN,\n CORS_RULE_NAME_RESERVED_PREFIX,\n CORS_RULES_MAX_COUNT,\n} from '../types/bucket.ts'\n\n/**\n * Deprecated compatibility alias for the former simulator bucketInfo pair-count cap.\n *\n * @deprecated B2 bucketInfo has no documented pair-count cap. Use the byte\n * limit constants instead.\n */\nexport const BUCKET_INFO_MAX_KEYS = Number.POSITIVE_INFINITY\n\n/**\n * Deprecated compatibility alias for the former simulator per-value bucketInfo cap.\n *\n * @deprecated B2 bucketInfo limits aggregate value bytes, not per-value bytes.\n * Use {@link BUCKET_INFO_VALUES_MAX_BYTES}.\n */\nexport const BUCKET_INFO_VALUE_MAX = BUCKET_INFO_VALUES_MAX_BYTES\n\n/** Shape returned by validation functions when input is rejected. */\nexport interface ValidationError {\n readonly code: string\n readonly message: string\n}\n\n// ---------------------------------------------------------------------------\n// Application keys (`b2_create_key`)\n// ---------------------------------------------------------------------------\n\n/** Minimum length for application key names. */\nexport const KEY_NAME_MIN = 1\n/** Maximum length for application key names. */\nexport const KEY_NAME_MAX = 100\n\nconst VALID_CAPABILITIES = new Set<string>(Object.values(Capability))\n\n/**\n * Validates application-key capabilities against B2's supported capability set.\n *\n * @param capabilities - Caller-supplied capabilities array.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-key\n */\nexport function validateCreateKeyCapabilities(capabilities: unknown): ValidationError | null {\n if (!Array.isArray(capabilities)) {\n return { code: 'bad_request', message: 'capabilities must be an array' }\n }\n if (capabilities.length === 0) {\n return { code: 'bad_request', message: 'capabilities must not be empty' }\n }\n const unknownCapabilities = capabilities.filter(\n (capability) => typeof capability !== 'string' || !VALID_CAPABILITIES.has(capability),\n )\n if (unknownCapabilities.length > 0) {\n return {\n code: 'bad_request',\n message: `unknown capabilities: ${unknownCapabilities.map(String).join(', ')}`,\n }\n }\n return null\n}\n\n/**\n * Returns a frozen copy of a previously validated application-key capability list.\n *\n * @param capabilities - Validated caller-supplied capabilities.\n *\n * @returns An immutable capability list safe to store internally.\n */\nexport function normalizeCreateKeyCapabilities(\n capabilities: readonly Capability[],\n): readonly Capability[] {\n return Object.freeze([...capabilities])\n}\n\n/**\n * Validates application-key names against B2's documented length limits.\n *\n * @param keyName - Caller-supplied keyName.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-key\n */\nexport function validateCreateKeyName(keyName: unknown): ValidationError | null {\n if (typeof keyName !== 'string') {\n return { code: 'bad_request', message: 'keyName must be a string' }\n }\n if (keyName.length < KEY_NAME_MIN || keyName.length > KEY_NAME_MAX) {\n return {\n code: 'bad_request',\n message: `keyName must be ${KEY_NAME_MIN}-${KEY_NAME_MAX} characters`,\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Bucket name (`b2_create_bucket`, `b2_update_bucket`)\n// ---------------------------------------------------------------------------\n\nexport { BUCKET_NAME_MAX, BUCKET_NAME_MIN }\n\n/**\n * Validates a bucket name against B2's documented rules.\n *\n * @param name - Caller-supplied bucket name.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-bucket\n */\nexport function validateBucketName(name: string): ValidationError | null {\n if (typeof name !== 'string' || name.length < BUCKET_NAME_MIN || name.length > BUCKET_NAME_MAX) {\n return {\n code: 'invalid_bucket_name',\n message: `bucketName must be ${BUCKET_NAME_MIN}-${BUCKET_NAME_MAX} characters`,\n }\n }\n if (isB2BucketNameIpv4Address(name)) {\n return {\n code: 'invalid_bucket_name',\n message: 'bucketName must not be formatted as an IPv4 address',\n }\n }\n if (!hasValidB2BucketNameShape(name)) {\n return {\n code: 'invalid_bucket_name',\n message:\n 'bucketName must contain only letters, digits, hyphens, and periods; cannot start or end with punctuation or contain consecutive periods',\n }\n }\n if (name.startsWith(BUCKET_NAME_RESERVED_PREFIX)) {\n return {\n code: 'invalid_bucket_name',\n message: `bucketName cannot start with the reserved prefix \"${BUCKET_NAME_RESERVED_PREFIX}\"`,\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// File name (every upload / hide / copy entry point)\n// ---------------------------------------------------------------------------\n\nexport { FILE_NAME_MAX_BYTES }\n\n/**\n * Validates a file name against B2's documented rules. Mirrors the\n * server-side checks B2 runs on `b2_upload_file` / `b2_hide_file` /\n * `b2_start_large_file` / `b2_copy_file` filename inputs.\n *\n * @param name - Caller-supplied file name (raw, unencoded).\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-upload-file\n */\nexport function validateFileName(name: string): ValidationError | null {\n if (typeof name !== 'string' || name.length === 0) {\n return { code: 'invalid_file_name', message: 'fileName must be a non-empty string' }\n }\n const byteLength = getB2FileNameByteLength(name)\n if (byteLength === null) {\n return {\n code: 'invalid_file_name',\n message: 'fileName exceeds the 1024-byte UTF-8 limit',\n }\n }\n if (hasB2FileNameControlCharacter(name)) {\n return {\n code: 'invalid_file_name',\n message: 'fileName must not contain control characters (U+0000-U+001F or U+007F)',\n }\n }\n // Path segments equal to `.` or `..` alone are illegal per B2 docs.\n // Embedded `..` within a segment (e.g. `a..b`) is fine, and a path\n // like `../foo` is fine because the SDK doesn't interpret it; only\n // bare `.` or `..` as a complete name is rejected.\n if (name === '.' || name === '..') {\n return {\n code: 'invalid_file_name',\n message: 'fileName cannot be exactly \".\" or \"..\"',\n }\n }\n // No leading or trailing slash, no `//`.\n if (name.startsWith('/') || name.endsWith('/') || name.includes('//')) {\n return {\n code: 'invalid_file_name',\n message: 'fileName cannot start with \"/\", end with \"/\", or contain \"//\"',\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// File-info / Bucket-info byte budget\n// ---------------------------------------------------------------------------\n\n/** Per-file fileInfo total size cap (sum of key+value bytes). */\nexport const FILE_INFO_TOTAL_MAX = 2048\n/** Per-key fileInfo value byte cap. */\nexport const FILE_INFO_VALUE_MAX = 2048\n/** Allowed key character set (case-insensitive). */\nconst FILE_INFO_KEY_REGEX = /^[a-zA-Z0-9_-]+$/\n\n/**\n * Validates a `fileInfo` record against B2's byte-budget and\n * key-shape rules.\n *\n * @param info - Caller-supplied fileInfo record.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-upload-file\n */\nexport function validateFileInfo(info: Record<string, string>): ValidationError | null {\n let total = 0\n for (const [key, value] of Object.entries(info)) {\n if (!FILE_INFO_KEY_REGEX.test(key)) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo key \"${key}\" must match ^[a-zA-Z0-9_-]+$`,\n }\n }\n if (typeof value !== 'string') {\n return { code: 'invalid_file_info', message: `fileInfo value for \"${key}\" must be a string` }\n }\n const keyBytes = utf8Encoder.encode(key).byteLength\n const valueBytes = utf8Encoder.encode(value).byteLength\n if (valueBytes > FILE_INFO_VALUE_MAX) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo value for \"${key}\" exceeds ${FILE_INFO_VALUE_MAX} bytes`,\n }\n }\n total += keyBytes + valueBytes\n }\n if (total > FILE_INFO_TOTAL_MAX) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo total size ${total} bytes exceeds the ${FILE_INFO_TOTAL_MAX}-byte limit`,\n }\n }\n return null\n}\n\n/**\n * Validates a `bucketInfo` record against B2's per-bucket metadata rules.\n *\n * @param info - Caller-supplied bucketInfo record.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/docs/cloud-storage-buckets\n */\nexport function validateBucketInfo(info: unknown): ValidationError | null {\n try {\n assertValidClientBucketInfo(info as Record<string, string>)\n } catch (err) {\n return bucketConfigurationValidationError(err)\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// maxFileCount caps per endpoint\n// ---------------------------------------------------------------------------\n\n/**\n * Per-endpoint upper bound on the `maxFileCount` (or `maxKeyCount` /\n * `maxPartCount`) request field. Sourced from the B2 endpoint docs.\n */\nexport const LIST_ENDPOINT_CAPS = {\n /** `b2_list_file_names.maxFileCount` cap. */\n b2_list_file_names: 10_000,\n /** `b2_list_file_versions.maxFileCount` cap. */\n b2_list_file_versions: 10_000,\n /** `b2_list_unfinished_large_files.maxFileCount` cap. */\n b2_list_unfinished_large_files: 100,\n /** `b2_list_keys.maxKeyCount` cap. */\n b2_list_keys: 10_000,\n /** `b2_list_parts.maxPartCount` cap. */\n b2_list_parts: 10_000,\n} as const\n\n/**\n * Validates a `maxFileCount` (or `maxKeyCount` / `maxPartCount`) value\n * against the per-endpoint cap documented by B2.\n *\n * @param requested - Caller-supplied count.\n * @param endpoint - Which list endpoint this applies to.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n */\nexport function validateMaxCount(\n requested: number | undefined,\n endpoint: keyof typeof LIST_ENDPOINT_CAPS,\n): ValidationError | null {\n if (requested === undefined) return null\n if (!Number.isInteger(requested) || requested < 1) {\n return {\n code: 'bad_request',\n message: `maxFileCount must be a positive integer (got ${requested})`,\n }\n }\n const cap = LIST_ENDPOINT_CAPS[endpoint]\n if (requested > cap) {\n return {\n code: 'bad_request',\n message: `maxFileCount ${requested} exceeds the ${endpoint} cap of ${cap}`,\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Download authorization duration\n// ---------------------------------------------------------------------------\n\n/** Minimum `b2_get_download_authorization.validDurationInSeconds`. */\nexport const DOWNLOAD_AUTH_DURATION_MIN_SECONDS = 1\n/** Maximum `b2_get_download_authorization.validDurationInSeconds`. */\nexport const DOWNLOAD_AUTH_DURATION_MAX_SECONDS = 604_800\n\n/**\n * Validates a `b2_get_download_authorization` duration against B2's\n * documented inclusive 1-second to 7-day range.\n *\n * @param requested - Caller-supplied duration in seconds.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n */\nexport function validateDownloadAuthorizationDuration(requested: unknown): ValidationError | null {\n if (\n typeof requested !== 'number' ||\n !Number.isInteger(requested) ||\n requested < DOWNLOAD_AUTH_DURATION_MIN_SECONDS ||\n requested > DOWNLOAD_AUTH_DURATION_MAX_SECONDS\n ) {\n return {\n code: 'bad_request',\n message: `validDurationInSeconds must be an integer from ${DOWNLOAD_AUTH_DURATION_MIN_SECONDS} through ${DOWNLOAD_AUTH_DURATION_MAX_SECONDS}`,\n }\n }\n return null\n}\n\n/**\n * Validates a `b2_get_download_authorization` file name prefix.\n *\n * B2 allows an empty prefix, but the field must still be present as a\n * string so later prefix checks cannot crash on malformed request bodies.\n *\n * @param requested - Caller-supplied file name prefix.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n */\nexport function validateDownloadAuthorizationPrefix(requested: unknown): ValidationError | null {\n if (typeof requested !== 'string') {\n return { code: 'bad_request', message: 'fileNamePrefix must be a string' }\n }\n return null\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction validateKnownFields(\n value: Record<string, unknown>,\n allowedFields: ReadonlySet<string>,\n path: string,\n): ValidationError | null {\n for (const field of Object.keys(value)) {\n if (!allowedFields.has(field)) {\n return {\n code: 'bad_request',\n message: `${path}.${field} is not a supported field`,\n }\n }\n }\n return null\n}\n\nfunction validateStringArray(\n value: unknown,\n path: string,\n options: { readonly allowNull?: boolean; readonly requireNonEmpty?: boolean } = {},\n): ValidationError | null {\n if (value === undefined && options.allowNull === true) return null\n if (value === null && options.allowNull === true) return null\n if (!Array.isArray(value)) {\n return { code: 'bad_request', message: `${path} must be an array of strings` }\n }\n if (options.requireNonEmpty === true && value.length === 0) {\n return { code: 'bad_request', message: `${path} must be a non-empty array` }\n }\n for (const [index, item] of value.entries()) {\n if (typeof item !== 'string') {\n return { code: 'bad_request', message: `${path}[${index}] must be a string` }\n }\n }\n return null\n}\n\nfunction validateNonEmptyString(value: unknown, path: string): ValidationError | null {\n if (typeof value !== 'string' || value.length === 0) {\n return { code: 'bad_request', message: `${path} must be a non-empty string` }\n }\n return null\n}\n\nfunction validateNonNegativeInteger(value: unknown, path: string): ValidationError | null {\n if (typeof value !== 'number' || !Number.isInteger(value) || value < 0) {\n return { code: 'bad_request', message: `${path} must be a non-negative integer` }\n }\n return null\n}\n\nfunction validateIntegerAtMost(value: number, max: number, path: string): ValidationError | null {\n if (value > max) {\n return { code: 'bad_request', message: `${path} must not exceed ${max}` }\n }\n return null\n}\n\nfunction validatePositiveInteger(value: unknown, path: string): ValidationError | null {\n if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {\n return { code: 'bad_request', message: `${path} must be a positive integer` }\n }\n return null\n}\n\nfunction validateNullablePositiveInteger(value: unknown, path: string): ValidationError | null {\n if (value === undefined || value === null) return null\n return validatePositiveInteger(value, path)\n}\n\nfunction validateUniqueName(\n names: Set<string>,\n name: string,\n path: string,\n): ValidationError | null {\n if (names.has(name)) {\n return { code: 'bad_request', message: `${path} must be unique` }\n }\n names.add(name)\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Bucket configuration (`b2_create_bucket`, `b2_update_bucket`)\n// ---------------------------------------------------------------------------\n\nconst REQUEST_BUCKET_TYPES = new Set<string>(Object.values(BucketType))\n\n/**\n * Validates a create/update request `bucketType`.\n *\n * @param bucketType - Caller-supplied bucket type.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-bucket\n * @see https://www.backblaze.com/apidocs/b2-update-bucket\n */\nexport function validateBucketType(bucketType: unknown): ValidationError | null {\n if (typeof bucketType !== 'string' || !REQUEST_BUCKET_TYPES.has(bucketType)) {\n return { code: 'bad_request', message: 'bucketType must be a known request bucket type' }\n }\n return null\n}\n\n/**\n * Validates a `b2_list_buckets.bucketTypes` filter.\n *\n * @param bucketTypes - Caller-supplied bucket type filter.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-list-buckets\n */\nexport function validateBucketTypes(bucketTypes: unknown): ValidationError | null {\n if (bucketTypes === undefined) return null\n if (!Array.isArray(bucketTypes)) {\n return { code: 'bad_request', message: 'bucketTypes must be an array' }\n }\n if (bucketTypes.length === 0) {\n return { code: 'bad_request', message: 'bucketTypes must not be empty' }\n }\n if (bucketTypes.length === 1 && bucketTypes[0] === 'all') return null\n if (bucketTypes.includes('all')) {\n return { code: 'bad_request', message: \"bucketTypes may contain 'all' only by itself\" }\n }\n for (const [index, bucketType] of bucketTypes.entries()) {\n if (typeof bucketType !== 'string') {\n return {\n code: 'bad_request',\n message: `bucketTypes[${index}] must be a string`,\n }\n }\n }\n return null\n}\n\nconst CORS_RULE_FIELDS = new Set([\n 'allowedHeaders',\n 'allowedOperations',\n 'allowedOrigins',\n 'corsRuleName',\n 'exposeHeaders',\n 'maxAgeSeconds',\n])\n\nconst KNOWN_CORS_OPERATIONS = new Set<string>(Object.values(CorsOperation))\n\n/**\n * Validates B2 CORS rule structure for bucket create/update requests.\n *\n * @param rules - Caller-supplied CORS rules.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/docs/cloud-storage-cross-origin-resource-sharing-rules\n */\nexport function validateCorsRules(rules: unknown): ValidationError | null {\n try {\n assertValidClientCorsRules(rules as readonly CorsRule[])\n } catch (err) {\n return bucketConfigurationValidationError(err)\n }\n\n if (!Array.isArray(rules)) {\n return { code: 'bad_request', message: 'corsRules must be an array' }\n }\n\n const names = new Set<string>()\n for (const [index, rule] of rules.entries()) {\n const rulePath = `corsRules[${index}]`\n if (!isRecord(rule)) {\n return { code: 'bad_request', message: `${rulePath} must be an object` }\n }\n\n const fieldError = validateKnownFields(rule, CORS_RULE_FIELDS, rulePath)\n if (fieldError) return fieldError\n\n const nameError = validateNonEmptyString(rule['corsRuleName'], `${rulePath}.corsRuleName`)\n if (nameError) return nameError\n const ruleName = rule['corsRuleName'] as string\n const uniqueNameError = validateUniqueName(names, ruleName, `${rulePath}.corsRuleName`)\n if (uniqueNameError) return uniqueNameError\n\n const originsError = validateStringArray(rule['allowedOrigins'], `${rulePath}.allowedOrigins`, {\n requireNonEmpty: true,\n })\n if (originsError) return originsError\n\n const operationsError = validateStringArray(\n rule['allowedOperations'],\n `${rulePath}.allowedOperations`,\n { requireNonEmpty: true },\n )\n if (operationsError) return operationsError\n for (const operation of rule['allowedOperations'] as readonly string[]) {\n if (!KNOWN_CORS_OPERATIONS.has(operation)) {\n return {\n code: 'bad_request',\n message: `${rulePath}.allowedOperations contains an unknown operation`,\n }\n }\n }\n\n const headersError = validateStringArray(rule['allowedHeaders'], `${rulePath}.allowedHeaders`, {\n allowNull: true,\n })\n if (headersError) return headersError\n\n const exposeError = validateStringArray(rule['exposeHeaders'], `${rulePath}.exposeHeaders`, {\n allowNull: true,\n })\n if (exposeError) return exposeError\n\n const ageError = validateNonNegativeInteger(rule['maxAgeSeconds'], `${rulePath}.maxAgeSeconds`)\n if (ageError) return ageError\n const maxAgeError = validateIntegerAtMost(\n rule['maxAgeSeconds'] as number,\n CORS_MAX_AGE_SECONDS_MAX,\n `${rulePath}.maxAgeSeconds`,\n )\n if (maxAgeError) return maxAgeError\n }\n\n return null\n}\n\nfunction bucketConfigurationValidationError(err: unknown): ValidationError {\n if (err instanceof B2BucketConfigurationError) {\n return { code: err.code, message: err.message }\n }\n throw err\n}\n\nconst LIFECYCLE_RULE_FIELDS = new Set([\n 'daysFromHidingToDeleting',\n 'daysFromStartingToCancelingUnfinishedLargeFiles',\n 'daysFromUploadingToHiding',\n 'fileNamePrefix',\n])\n\n/**\n * Validates B2 lifecycle rule structure for bucket create/update requests.\n *\n * @param rules - Caller-supplied lifecycle rules.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/docs/cloud-storage-lifecycle-rules\n */\nexport function validateLifecycleRules(rules: unknown): ValidationError | null {\n if (!Array.isArray(rules)) {\n return { code: 'bad_request', message: 'lifecycleRules must be an array' }\n }\n\n for (const [index, rule] of rules.entries()) {\n const rulePath = `lifecycleRules[${index}]`\n if (!isRecord(rule)) {\n return { code: 'bad_request', message: `${rulePath} must be an object` }\n }\n\n const fieldError = validateKnownFields(rule, LIFECYCLE_RULE_FIELDS, rulePath)\n if (fieldError) return fieldError\n\n const deletingError = validateNullablePositiveInteger(\n rule['daysFromHidingToDeleting'],\n `${rulePath}.daysFromHidingToDeleting`,\n )\n if (deletingError) return deletingError\n\n const hidingError = validateNullablePositiveInteger(\n rule['daysFromUploadingToHiding'],\n `${rulePath}.daysFromUploadingToHiding`,\n )\n if (hidingError) return hidingError\n\n const cancelError = validateNullablePositiveInteger(\n rule['daysFromStartingToCancelingUnfinishedLargeFiles'],\n `${rulePath}.daysFromStartingToCancelingUnfinishedLargeFiles`,\n )\n if (cancelError) return cancelError\n\n if (\n rule['daysFromHidingToDeleting'] == null &&\n rule['daysFromUploadingToHiding'] == null &&\n rule['daysFromStartingToCancelingUnfinishedLargeFiles'] == null\n ) {\n return {\n code: 'bad_request',\n message: `${rulePath} must set at least one lifecycle action`,\n }\n }\n\n if (typeof rule['fileNamePrefix'] !== 'string') {\n return { code: 'bad_request', message: `${rulePath}.fileNamePrefix must be a string` }\n }\n }\n\n return null\n}\n\nconst DEFAULT_RETENTION_FIELDS = new Set(['mode', 'period'])\nconst RETENTION_PERIOD_FIELDS = new Set(['duration', 'unit'])\nconst DEFAULT_RETENTION_MODES = new Set<string>(Object.values(BucketRetentionMode))\nconst OBJECT_LOCK_RETENTION_MAX_DAYS = 3000\n\n/**\n * Validates default Object Lock retention policy structure for bucket requests.\n *\n * @param policy - Caller-supplied default retention policy.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/docs/cloud-storage-object-lock\n */\nexport function validateDefaultRetention(policy: unknown): ValidationError | null {\n if (!isRecord(policy)) {\n return { code: 'bad_request', message: 'defaultRetention must be an object' }\n }\n\n const fieldError = validateKnownFields(policy, DEFAULT_RETENTION_FIELDS, 'defaultRetention')\n if (fieldError) return fieldError\n\n const mode = policy['mode']\n if (typeof mode !== 'string' || !DEFAULT_RETENTION_MODES.has(mode)) {\n return {\n code: 'bad_request',\n message: 'defaultRetention.mode must be \"compliance\", \"governance\", or \"none\"',\n }\n }\n\n const period = policy['period']\n if (mode === BucketRetentionMode.None) {\n if (period !== null) {\n return {\n code: 'bad_request',\n message: 'defaultRetention.period must be null when mode is \"none\"',\n }\n }\n return null\n }\n\n if (!isRecord(period)) {\n return {\n code: 'bad_request',\n message: 'defaultRetention.period must be an object for retention modes',\n }\n }\n\n const periodFieldError = validateKnownFields(\n period,\n RETENTION_PERIOD_FIELDS,\n 'defaultRetention.period',\n )\n if (periodFieldError) return periodFieldError\n\n const durationError = validatePositiveInteger(\n period['duration'],\n 'defaultRetention.period.duration',\n )\n if (durationError) return durationError\n if (!Number.isSafeInteger(period['duration'])) {\n return {\n code: 'bad_request',\n message: 'defaultRetention.period.duration must be a safe integer',\n }\n }\n\n if (period['unit'] !== 'days' && period['unit'] !== 'years') {\n return {\n code: 'bad_request',\n message: 'defaultRetention.period.unit must be \"days\" or \"years\"',\n }\n }\n const durationDays =\n period['unit'] === 'days'\n ? (period['duration'] as number)\n : (period['duration'] as number) * 365\n if (!Number.isFinite(durationDays) || durationDays > OBJECT_LOCK_RETENTION_MAX_DAYS) {\n return {\n code: 'bad_request',\n message: `defaultRetention.period must not exceed ${OBJECT_LOCK_RETENTION_MAX_DAYS} days`,\n }\n }\n\n return null\n}\n\nconst REPLICATION_CONFIG_FIELDS = new Set(['asReplicationSource', 'asReplicationDestination'])\nconst REPLICATION_SOURCE_FIELDS = new Set(['replicationRules', 'sourceApplicationKeyId'])\nconst REPLICATION_DESTINATION_FIELDS = new Set(['sourceToDestinationKeyMapping'])\nconst REPLICATION_RULE_FIELDS = new Set([\n 'destinationBucketId',\n 'fileNamePrefix',\n 'includeExistingFiles',\n 'isEnabled',\n 'priority',\n 'replicationRuleName',\n])\n\nfunction validateReplicationRule(rule: unknown, rulePath: string): ValidationError | null {\n if (!isRecord(rule)) {\n return { code: 'bad_request', message: `${rulePath} must be an object` }\n }\n\n const fieldError = validateKnownFields(rule, REPLICATION_RULE_FIELDS, rulePath)\n if (fieldError) return fieldError\n\n const destinationError = validateNonEmptyString(\n rule['destinationBucketId'],\n `${rulePath}.destinationBucketId`,\n )\n if (destinationError) return destinationError\n\n if (typeof rule['fileNamePrefix'] !== 'string') {\n return { code: 'bad_request', message: `${rulePath}.fileNamePrefix must be a string` }\n }\n\n if (typeof rule['includeExistingFiles'] !== 'boolean') {\n return { code: 'bad_request', message: `${rulePath}.includeExistingFiles must be a boolean` }\n }\n\n if (typeof rule['isEnabled'] !== 'boolean') {\n return { code: 'bad_request', message: `${rulePath}.isEnabled must be a boolean` }\n }\n\n const priorityError = validatePositiveInteger(rule['priority'], `${rulePath}.priority`)\n if (priorityError) return priorityError\n\n const nameError = validateNonEmptyString(\n rule['replicationRuleName'],\n `${rulePath}.replicationRuleName`,\n )\n if (nameError) return nameError\n\n return null\n}\n\nfunction validateReplicationSource(source: unknown): ValidationError | null {\n if (!isRecord(source)) {\n return {\n code: 'bad_request',\n message: 'replicationConfiguration.asReplicationSource must be an object',\n }\n }\n\n const fieldError = validateKnownFields(\n source,\n REPLICATION_SOURCE_FIELDS,\n 'replicationConfiguration.asReplicationSource',\n )\n if (fieldError) return fieldError\n\n const sourceKeyError = validateNonEmptyString(\n source['sourceApplicationKeyId'],\n 'replicationConfiguration.asReplicationSource.sourceApplicationKeyId',\n )\n if (sourceKeyError) return sourceKeyError\n\n const rules = source['replicationRules']\n if (!Array.isArray(rules)) {\n return {\n code: 'bad_request',\n message: 'replicationConfiguration.asReplicationSource.replicationRules must be an array',\n }\n }\n\n const names = new Set<string>()\n for (const [index, rule] of rules.entries()) {\n const rulePath = `replicationConfiguration.asReplicationSource.replicationRules[${index}]`\n const ruleError = validateReplicationRule(rule, rulePath)\n if (ruleError) return ruleError\n const ruleName = (rule as Record<string, unknown>)['replicationRuleName'] as string\n const uniqueNameError = validateUniqueName(names, ruleName, `${rulePath}.replicationRuleName`)\n if (uniqueNameError) return uniqueNameError\n }\n\n return null\n}\n\nfunction validateReplicationDestination(destination: unknown): ValidationError | null {\n if (!isRecord(destination)) {\n return {\n code: 'bad_request',\n message: 'replicationConfiguration.asReplicationDestination must be an object',\n }\n }\n\n const fieldError = validateKnownFields(\n destination,\n REPLICATION_DESTINATION_FIELDS,\n 'replicationConfiguration.asReplicationDestination',\n )\n if (fieldError) return fieldError\n\n const mapping = destination['sourceToDestinationKeyMapping']\n if (!isRecord(mapping)) {\n return {\n code: 'bad_request',\n message:\n 'replicationConfiguration.asReplicationDestination.sourceToDestinationKeyMapping must be an object',\n }\n }\n\n for (const [sourceKey, destinationKey] of Object.entries(mapping)) {\n if (sourceKey.length === 0) {\n return {\n code: 'bad_request',\n message:\n 'replicationConfiguration.asReplicationDestination.sourceToDestinationKeyMapping keys must be non-empty',\n }\n }\n if (typeof destinationKey !== 'string' || destinationKey.length === 0) {\n return {\n code: 'bad_request',\n message:\n 'replicationConfiguration.asReplicationDestination.sourceToDestinationKeyMapping values must be non-empty strings',\n }\n }\n }\n\n return null\n}\n\n/**\n * Validates B2 replication configuration structure for bucket requests.\n *\n * @param config - Caller-supplied replication configuration.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-update-bucket\n */\nexport function validateReplicationConfiguration(config: unknown): ValidationError | null {\n if (!isRecord(config)) {\n return { code: 'bad_request', message: 'replicationConfiguration must be an object' }\n }\n\n const fieldError = validateKnownFields(\n config,\n REPLICATION_CONFIG_FIELDS,\n 'replicationConfiguration',\n )\n if (fieldError) return fieldError\n\n if (!('asReplicationSource' in config) && !('asReplicationDestination' in config)) {\n return {\n code: 'bad_request',\n message:\n 'replicationConfiguration must include asReplicationSource or asReplicationDestination',\n }\n }\n\n const source = config['asReplicationSource']\n if (source !== undefined && source !== null) {\n const sourceError = validateReplicationSource(source)\n if (sourceError) return sourceError\n }\n\n const destination = config['asReplicationDestination']\n if (destination !== undefined && destination !== null) {\n const destinationError = validateReplicationDestination(destination)\n if (destinationError) return destinationError\n }\n\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Event notification rules (`b2_set_bucket_notification_rules`)\n// ---------------------------------------------------------------------------\n\nconst NOTIFICATION_RULE_FIELDS = new Set([\n 'eventTypes',\n 'isEnabled',\n 'isSuspended',\n 'maxEventsPerBatch',\n 'name',\n 'objectNamePrefix',\n 'suspensionReason',\n 'targetConfiguration',\n])\n\nconst NOTIFICATION_TARGET_FIELDS = new Set([\n 'customHeaders',\n 'hmacSha256SigningSecret',\n 'targetType',\n 'url',\n])\n\nconst NOTIFICATION_CUSTOM_HEADER_FIELDS = new Set(['name', 'value'])\nconst NOTIFICATION_CUSTOM_HEADER_MAX_COUNT = 10\nconst NOTIFICATION_CUSTOM_HEADER_MAX_ENCODED_BYTES = 2048\nconst NOTIFICATION_CUSTOM_HEADER_RESERVED_PREFIX = 'x-bz-'\nconst HTTP_HEADER_NAME_RE = /^[!#$%&'*+\\-.^_`|~0-9A-Za-z]+$/\n\nconst KNOWN_NOTIFICATION_EVENT_TYPES = new Set<string>(Object.values(EventType))\n\nfunction encodedHeaderBytes(name: string, value: string): number | null {\n try {\n // B2 counts the URL-encoded name/value plus the `:\\r\\n` separator per header.\n return encodeURIComponent(name).length + encodeURIComponent(value).length + 3\n } catch {\n return null\n }\n}\n\nfunction isValidHeaderValue(value: string): boolean {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i)\n if (code === 9) continue\n if (code < 32 || code === 127) return false\n }\n return true\n}\n\nfunction validateNotificationCustomHeaders(value: unknown, path: string): ValidationError | null {\n if (value === undefined) return null\n if (!Array.isArray(value)) {\n return { code: 'bad_request', message: `${path} must be an array of objects` }\n }\n if (value.length > NOTIFICATION_CUSTOM_HEADER_MAX_COUNT) {\n return {\n code: 'bad_request',\n message: `${path} must contain no more than ${NOTIFICATION_CUSTOM_HEADER_MAX_COUNT} entries`,\n }\n }\n\n const names = new Set<string>()\n let encodedBytes = 0\n for (const [index, header] of value.entries()) {\n const headerPath = `${path}[${index}]`\n if (!isRecord(header)) {\n return { code: 'bad_request', message: `${headerPath} must be an object` }\n }\n const fieldError = validateKnownFields(header, NOTIFICATION_CUSTOM_HEADER_FIELDS, headerPath)\n if (fieldError) return fieldError\n if (typeof header['name'] !== 'string' || header['name'].length === 0) {\n return { code: 'bad_request', message: `${headerPath}.name must be a non-empty string` }\n }\n if (typeof header['value'] !== 'string') {\n return { code: 'bad_request', message: `${headerPath}.value must be a string` }\n }\n\n const name = header['name']\n const normalizedName = name.toLowerCase()\n if (!HTTP_HEADER_NAME_RE.test(name)) {\n return { code: 'bad_request', message: `${headerPath}.name must be a valid HTTP header name` }\n }\n if (normalizedName.startsWith(NOTIFICATION_CUSTOM_HEADER_RESERVED_PREFIX)) {\n return {\n code: 'bad_request',\n message: `${headerPath}.name must not begin with X-Bz-`,\n }\n }\n if (names.has(normalizedName)) {\n return { code: 'bad_request', message: `${headerPath}.name must be unique` }\n }\n names.add(normalizedName)\n\n const headerValue = header['value']\n if (!isValidHeaderValue(headerValue)) {\n return {\n code: 'bad_request',\n message: `${headerPath}.value must be a valid HTTP header value`,\n }\n }\n\n const size = encodedHeaderBytes(name, headerValue)\n if (size === null) {\n return { code: 'bad_request', message: `${headerPath} must be URL-encodable` }\n }\n encodedBytes += size\n if (encodedBytes > NOTIFICATION_CUSTOM_HEADER_MAX_ENCODED_BYTES) {\n return {\n code: 'bad_request',\n message: `${path} URL-encoded name/value bytes must not exceed ${NOTIFICATION_CUSTOM_HEADER_MAX_ENCODED_BYTES}`,\n }\n }\n }\n return null\n}\n\n/**\n * Validates event notification rules for `b2_set_bucket_notification_rules`.\n *\n * @param rules - Caller-supplied event notification rules.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-set-bucket-notification-rules\n */\nexport function validateNotificationRules(rules: unknown): ValidationError | null {\n if (!Array.isArray(rules)) {\n return {\n code: 'bad_request',\n message: 'eventNotificationRules must be an array',\n }\n }\n\n const names = new Set<string>()\n for (const [index, ruleValue] of rules.entries()) {\n const rulePath = `eventNotificationRules[${index}]`\n if (!isRecord(ruleValue)) {\n return { code: 'bad_request', message: `${rulePath} must be an object` }\n }\n\n const fieldError = validateKnownFields(ruleValue, NOTIFICATION_RULE_FIELDS, rulePath)\n if (fieldError) return fieldError\n\n if (typeof ruleValue['isEnabled'] !== 'boolean') {\n return {\n code: 'bad_request',\n message: `${rulePath}.isEnabled must be a boolean`,\n }\n }\n\n const maxEventsPerBatch = ruleValue['maxEventsPerBatch']\n if (\n maxEventsPerBatch !== undefined &&\n (typeof maxEventsPerBatch !== 'number' ||\n !Number.isInteger(maxEventsPerBatch) ||\n maxEventsPerBatch < 1)\n ) {\n return {\n code: 'bad_request',\n message: `${rulePath}.maxEventsPerBatch must be a positive integer`,\n }\n }\n\n const name = ruleValue['name']\n if (typeof name !== 'string' || name.length === 0) {\n return {\n code: 'bad_request',\n message: `${rulePath}.name must be a non-empty string`,\n }\n }\n if (names.has(name)) {\n return {\n code: 'bad_request',\n message: `${rulePath}.name must be unique within eventNotificationRules`,\n }\n }\n names.add(name)\n\n const eventTypes = ruleValue['eventTypes']\n if (!Array.isArray(eventTypes) || eventTypes.length === 0) {\n return {\n code: 'bad_request',\n message: `${rulePath}.eventTypes must be a non-empty array`,\n }\n }\n for (const eventType of eventTypes) {\n if (typeof eventType !== 'string' || !KNOWN_NOTIFICATION_EVENT_TYPES.has(eventType)) {\n return {\n code: 'bad_request',\n message: `${rulePath}.eventTypes contains an unknown event type`,\n }\n }\n }\n\n const targetConfiguration = ruleValue['targetConfiguration']\n if (!isRecord(targetConfiguration)) {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration must be an object`,\n }\n }\n\n const targetFieldError = validateKnownFields(\n targetConfiguration,\n NOTIFICATION_TARGET_FIELDS,\n `${rulePath}.targetConfiguration`,\n )\n if (targetFieldError) return targetFieldError\n\n if (targetConfiguration['targetType'] !== 'webhook') {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration.targetType must be \"webhook\"`,\n }\n }\n\n const url = targetConfiguration['url']\n if (typeof url !== 'string') {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration.url must be a valid https URL`,\n }\n }\n try {\n if (new URL(url).protocol !== 'https:') {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration.url must be a valid https URL`,\n }\n }\n } catch {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration.url must be a valid https URL`,\n }\n }\n\n const customHeadersError = validateNotificationCustomHeaders(\n targetConfiguration['customHeaders'],\n `${rulePath}.targetConfiguration.customHeaders`,\n )\n if (customHeadersError) return customHeadersError\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,IAAa,uBAAuB,OAAO;;;;;;;AAQ3C,IAAa,wBAAwB;;AAarC,IAAa,eAAe;;AAE5B,IAAa,eAAe;AAE5B,IAAM,qBAAqB,IAAI,IAAY,OAAO,OAAO,UAAU,CAAC;;;;;;;;;;AAWpE,SAAgB,8BAA8B,cAA+C;CAC3F,IAAI,CAAC,MAAM,QAAQ,YAAY,GAC7B,OAAO;EAAE,MAAM;EAAe,SAAS;CAAgC;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 1024 * 1024;
2
+ var FILE_STREAM_CHUNK_SIZE = 16777216;
3
3
  var FILE_SOURCE_INTERNAL = Symbol("FileSource.internal");
4
4
  /** @internal */
5
5
  var fileSourceTestHooks = {};
6
6
  function getNodeFsSync() {
7
7
  const fs = globalThis.process?.getBuiltinModule?.("node:fs");
8
- if (!isNodeFsSync(fs)) throw new Error("FileSource constructor requires Node.js 22.3+ synchronous filesystem APIs; use FileSource.fromPath() when synchronous filesystem access is unavailable.");
8
+ if (!isNodeFsSync(fs)) throw new Error("FileSource constructor requires process.getBuiltinModule(\"node:fs\") with synchronous filesystem APIs; use FileSource.fromPath() when synchronous filesystem access is unavailable.");
9
9
  return fs;
10
10
  }
11
11
  function isNodeFsSync(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"file-source.cjs","names":[],"sources":["../../src/streams/file-source.ts"],"sourcesContent":["import type { ContentSource } from './source.ts'\n\nconst FILE_STREAM_CHUNK_SIZE = 16 * 1024 * 1024\n\n/** Filesystem path accepted by {@link FileSource}. */\nexport type FileSourcePath = string | URL\n\ninterface FileStatsLike {\n readonly dev: number\n readonly ino: number\n readonly mode: number\n readonly size: number\n readonly mtimeMs: number\n readonly ctimeMs: number\n isFile(): boolean\n}\n\ninterface FileHandleLike {\n read(\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): Promise<{ bytesRead: number }>\n stat(): Promise<FileStatsLike>\n close(): Promise<void>\n}\n\ninterface NodeFsSync {\n lstatSync(path: FileSourcePath): FileStatsLike\n}\n\ninterface FileIdentity {\n readonly dev: number\n readonly ino: number\n readonly size: number\n readonly mtimeMs: number\n readonly ctimeMs: number\n}\n\ninterface ToArrayBufferOptions {\n readonly signal?: AbortSignal\n}\n\nconst FILE_SOURCE_INTERNAL = Symbol('FileSource.internal')\n\ninterface FileSourceInternalOptions {\n readonly key: typeof FILE_SOURCE_INTERNAL\n readonly identity: FileIdentity\n}\n\n/** @internal */\nexport const fileSourceTestHooks: {\n afterReadIteration?: (filled: number) => Promise<void> | void\n maxReadSize?: number\n openFile?: (path: FileSourcePath, flags: number) => Promise<FileHandleLike>\n platform?: string\n} = {}\n\nfunction getNodeFsSync(): NodeFsSync {\n // FileSource exposes `size` synchronously, so the constructor cannot use the\n // repo's usual `await import('node:...')` pattern for Node-only APIs. Keep the\n // synchronous lookup here; async callers should prefer `FileSource.fromPath()`.\n const processLike = (\n globalThis as {\n process?: { getBuiltinModule?: (id: string) => unknown }\n }\n ).process\n const fs = processLike?.getBuiltinModule?.('node:fs')\n if (!isNodeFsSync(fs)) {\n throw new Error(\n 'FileSource constructor requires Node.js 22.3+ synchronous filesystem APIs; use FileSource.fromPath() when synchronous filesystem access is unavailable.',\n )\n }\n return fs\n}\n\nfunction isNodeFsSync(value: unknown): value is NodeFsSync {\n if (typeof value !== 'object' || value === null) return false\n const candidate = value as Record<string, unknown>\n return typeof candidate['lstatSync'] === 'function'\n}\n\nasync function fileOpenFlags(): Promise<number> {\n const { constants } = await import('node:fs')\n // O_NOFOLLOW and O_NONBLOCK are unavailable on some platforms. When\n // O_NOFOLLOW is absent, the post-open fstat identity check below is the\n // symlink-swap defense. O_NONBLOCK avoids blocking indefinitely if a path is\n // swapped to a FIFO or another blocking special file before fstat rejects it.\n return (\n constants.O_RDONLY |\n (constants.O_NOFOLLOW ?? 0) |\n ((constants as { O_NONBLOCK?: number }).O_NONBLOCK ?? 0)\n )\n}\n\nfunction normalizeSliceOffset(value: number, size: number): number {\n if (!Number.isFinite(value)) throw new RangeError('FileSource slice offsets must be finite.')\n const integer = Math.trunc(value)\n const offset = integer < 0 ? size + integer : integer\n return Math.min(Math.max(offset, 0), size)\n}\n\nfunction formatFilePath(path: FileSourcePath): string {\n return path instanceof URL ? path.href : path\n}\n\nfunction identityFromStats(stats: FileStatsLike): FileIdentity {\n return {\n dev: stats.dev,\n ino: stats.ino,\n size: stats.size,\n mtimeMs: stats.mtimeMs,\n ctimeMs: stats.ctimeMs,\n }\n}\n\nfunction assertStableIdentity(path: FileSourcePath, stats: FileStatsLike): void {\n if (stats.dev === 0 && stats.ino === 0) {\n throw new Error(\n `FileSource: ${formatFilePath(path)} is on a filesystem that does not expose stable file identity.`,\n )\n }\n}\n\nfunction assertRegularFile(path: FileSourcePath, stats: FileStatsLike): void {\n if (!stats.isFile()) {\n throw new Error(`FileSource: ${formatFilePath(path)} is not a regular file.`)\n }\n}\n\nfunction validatedIdentityFromStats(path: FileSourcePath, stats: FileStatsLike): FileIdentity {\n assertRegularFile(path, stats)\n if (shouldComparePosixFileIdentity()) assertStableIdentity(path, stats)\n return identityFromStats(stats)\n}\n\nfunction assertSameIdentity(\n path: FileSourcePath,\n expected: FileIdentity,\n actual: FileStatsLike,\n when: string,\n): void {\n if (shouldComparePosixFileIdentity()) assertStableIdentity(path, actual)\n if (\n shouldComparePosixFileIdentity() &&\n (actual.dev !== expected.dev || actual.ino !== expected.ino)\n ) {\n throw new Error(`FileSource: ${formatFilePath(path)} changed ${when}.`)\n }\n if (actual.size !== expected.size || actual.mtimeMs !== expected.mtimeMs) {\n throw new Error(`FileSource: ${formatFilePath(path)} was modified ${when}.`)\n }\n if (shouldComparePosixChangeTime() && actual.ctimeMs !== expected.ctimeMs) {\n throw new Error(`FileSource: ${formatFilePath(path)} was modified ${when}.`)\n }\n}\n\nfunction isWindows(): boolean {\n if (fileSourceTestHooks.platform !== undefined) return fileSourceTestHooks.platform === 'win32'\n const processLike = (globalThis as { process?: { platform?: string } }).process\n return processLike?.platform === 'win32'\n}\n\nfunction shouldComparePosixFileIdentity(): boolean {\n return !isWindows()\n}\n\nfunction shouldComparePosixChangeTime(): boolean {\n return !isWindows()\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal === undefined || !signal.aborted) return\n throw signal.reason ?? new DOMException('Aborted', 'AbortError')\n}\n\nfunction maxReadSize(): number {\n return fileSourceTestHooks.maxReadSize ?? FILE_STREAM_CHUNK_SIZE\n}\n\n/* v8 ignore start -- Requires a file to pass identity checks and still EOF mid-range. */\nfunction rangeEndedEarlyError(path: FileSourcePath, offset: number, size: number): Error {\n const end = offset + size\n return new Error(\n `FileSource: ${formatFilePath(path)} ended before byte range [${offset}, ${end}) was fully read.`,\n )\n}\n/* v8 ignore stop */\n\nasync function openValidatedFile(\n path: FileSourcePath,\n identity: FileIdentity,\n): Promise<FileHandleLike> {\n const open =\n fileSourceTestHooks.openFile ??\n (\n (await import('node:fs/promises')) as {\n open(path: FileSourcePath, flags: number): Promise<FileHandleLike>\n }\n ).open\n let file: FileHandleLike\n try {\n file = await open(path, await fileOpenFlags())\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`FileSource: ${formatFilePath(path)} could not be opened: ${message}`)\n }\n\n try {\n const stats = await file.stat()\n assertRegularFile(path, stats)\n assertSameIdentity(path, identity, stats, 'before read')\n return file\n } catch (err) {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n throw err\n }\n}\n\nasync function lstatNodeFile(path: FileSourcePath): Promise<FileStatsLike> {\n const { lstat } = (await import('node:fs/promises')) as {\n lstat(path: FileSourcePath): Promise<FileStatsLike>\n }\n return lstat(path)\n}\n\nasync function readFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n signal?: AbortSignal,\n): Promise<Uint8Array> {\n throwIfAborted(signal)\n if (size === 0) {\n await verifyFileIdentityForEmptyRead(path, identity, signal)\n return new Uint8Array(0)\n }\n\n throwIfAborted(signal)\n const file = await openValidatedFile(path, identity)\n const data = new Uint8Array(size)\n let filled = 0\n try {\n while (filled < data.byteLength) {\n throwIfAborted(signal)\n const length = Math.min(maxReadSize(), data.byteLength - filled)\n const { bytesRead } = await file.read(data, filled, length, offset + filled)\n if (bytesRead === 0) throw rangeEndedEarlyError(path, offset, size)\n filled += bytesRead\n await fileSourceTestHooks.afterReadIteration?.(filled)\n }\n throwIfAborted(signal)\n const stats = await file.stat()\n assertSameIdentity(path, identity, stats, 'while being read')\n return data\n } finally {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n }\n}\n\nasync function verifyFileIdentityForEmptyRead(\n path: FileSourcePath,\n identity: FileIdentity,\n signal?: AbortSignal,\n): Promise<void> {\n throwIfAborted(signal)\n const file = await openValidatedFile(path, identity)\n try {\n throwIfAborted(signal)\n return\n } finally {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n }\n}\n\nfunction sliceFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n start: number,\n end: number,\n): ContentSource {\n const normalizedStart = normalizeSliceOffset(start, size)\n const normalizedEnd = normalizeSliceOffset(end, size)\n return new FileSliceSource(\n path,\n identity,\n offset + normalizedStart,\n Math.max(normalizedEnd - normalizedStart, 0),\n )\n}\n\nfunction streamFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n): ReadableStream<Uint8Array> {\n let position = offset\n let remaining = size\n let verifiedEmpty = false\n const abortController = new AbortController()\n\n // Open per pull so abandoned public streams do not strand file handles or\n // retain Windows locks. Each chunk still verifies identity around its read.\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n if (remaining === 0) {\n if (!verifiedEmpty) {\n verifiedEmpty = true\n await verifyFileIdentityForEmptyRead(path, identity)\n }\n controller.close()\n return\n }\n\n const length = Math.min(FILE_STREAM_CHUNK_SIZE, remaining)\n const data = await readFileRange(path, identity, position, length, abortController.signal)\n position += data.byteLength\n remaining -= data.byteLength\n controller.enqueue(data)\n if (remaining === 0) controller.close()\n } catch (err) {\n controller.error(err)\n }\n },\n cancel(reason) {\n abortController.abort(reason)\n },\n })\n}\n\nasync function fileRangeToArrayBuffer(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n options: ToArrayBufferOptions = {},\n): Promise<ArrayBuffer> {\n const data = await readFileRange(path, identity, offset, size, options.signal)\n return data.buffer as ArrayBuffer\n}\n\nclass FileSliceSource implements ContentSource {\n readonly canSlice = true\n\n constructor(\n private readonly path: FileSourcePath,\n private readonly identity: FileIdentity,\n private readonly offset: number,\n readonly size: number,\n ) {}\n\n slice(start: number, end: number): ContentSource {\n return sliceFileRange(this.path, this.identity, this.offset, this.size, start, end)\n }\n\n stream(): ReadableStream<Uint8Array> {\n return streamFileRange(this.path, this.identity, this.offset, this.size)\n }\n\n toArrayBuffer(options: ToArrayBufferOptions = {}): Promise<ArrayBuffer> {\n return fileRangeToArrayBuffer(this.path, this.identity, this.offset, this.size, options)\n }\n}\n\n/**\n * ContentSource backed by a local filesystem path.\n *\n * `FileSource` is Node-only but safe to import in browser builds: it touches\n * Node filesystem APIs only when constructed or read. The constructor performs\n * synchronous filesystem validation so `size` is immediately available; request\n * handlers, sync loops, and other latency-sensitive code should use\n * {@link FileSource.fromPath}. Both paths capture a best-effort regular file\n * identity and reject a symlink as the final path component; parent directory\n * symlinks are followed by the operating system, so callers that constrain\n * paths under a trusted root should validate those parents separately. Reads\n * reject if the path is replaced, if the filesystem cannot report stable\n * identity on POSIX platforms, or if size/mtime/ctime changes before the\n * configured byte range is read. On Windows, reads avoid unreliable dev/inode\n * identity comparisons and validate size/mtime instead.\n * Slices preserve the captured identity, so multipart uploads can read\n * disjoint ranges without materialising the whole file in memory or following\n * later leaf path swaps.\n */\nexport class FileSource implements ContentSource {\n /** Random-access: file ranges are read by absolute byte offset. */\n readonly canSlice = true\n /** File size captured at construction time. */\n readonly size: number\n private readonly path: FileSourcePath\n private readonly identity: FileIdentity\n\n /**\n * Create a FileSource for a local file path.\n * @param path - Local filesystem path or file URL.\n *\n * @throws If the runtime has no Node-compatible filesystem API.\n * @throws If the path does not reference a regular non-symlink file.\n * @throws If a POSIX filesystem cannot report stable file identity.\n */\n constructor(path: FileSourcePath)\n /**\n * Internal constructor path for async validation.\n * @param path - Local filesystem path or file URL.\n * @param internal - Module-private validated identity payload.\n *\n * @internal\n */\n constructor(path: FileSourcePath, internal?: FileSourceInternalOptions) {\n const resolvedIdentity =\n internal?.key === FILE_SOURCE_INTERNAL\n ? internal.identity\n : validatedIdentityFromStats(path, getNodeFsSync().lstatSync(path))\n this.path = path\n this.identity = resolvedIdentity\n this.size = resolvedIdentity.size\n }\n\n /**\n * Return a new file-backed source covering the specified byte range.\n * @param start - The zero-based byte offset to begin the slice.\n * @param end - The exclusive byte offset where the slice ends.\n *\n * @returns A new ContentSource representing the requested sub-range.\n */\n slice(start: number, end: number): ContentSource {\n return sliceFileRange(this.path, this.identity, 0, this.size, start, end)\n }\n\n /**\n * Open this file as a Web ReadableStream.\n * @returns A ReadableStream that reads the file lazily.\n */\n stream(): ReadableStream<Uint8Array> {\n return streamFileRange(this.path, this.identity, 0, this.size)\n }\n\n /**\n * Read this file into an ArrayBuffer.\n * @param options - Optional abort signal used while reading.\n *\n * @returns A promise resolving with the file bytes.\n */\n toArrayBuffer(options: { readonly signal?: AbortSignal } = {}): Promise<ArrayBuffer> {\n return fileRangeToArrayBuffer(this.path, this.identity, 0, this.size, options)\n }\n\n /**\n * Create a FileSource using asynchronous filesystem validation.\n * @param path - Local filesystem path or file URL.\n *\n * @returns A FileSource bound to the validated file identity.\n *\n * @throws If the path does not reference a regular non-symlink file.\n * @throws If a POSIX filesystem cannot report stable file identity.\n */\n static async fromPath(path: FileSourcePath): Promise<FileSource> {\n const identity = validatedIdentityFromStats(path, await lstatNodeFile(path))\n return constructFileSourceFromIdentity(path, identity)\n }\n}\n\nfunction constructFileSourceFromIdentity(path: FileSourcePath, identity: FileIdentity): FileSource {\n // The public overload is intentionally single-argument; Reflect.construct\n // lets fromPath pass the module-private validated identity without exposing\n // that constructor shape in the public type surface.\n return Reflect.construct(FileSource, [\n path,\n { key: FILE_SOURCE_INTERNAL, identity },\n ]) as FileSource\n}\n"],"mappings":";AAEA,IAAM,yBAAyB,KAAK,OAAO;AA0C3C,IAAM,uBAAuB,OAAO,qBAAqB;;AAQzD,IAAa,sBAKT,CAAC;AAEL,SAAS,gBAA4B;CASnC,MAAM,KAJJ,WAGA,SACsB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ams/file-source.ts"],"sourcesContent":["import type { ContentSource } from './source.ts'\n\nconst FILE_STREAM_CHUNK_SIZE = 16 * 1024 * 1024\n\n/** Filesystem path accepted by {@link FileSource}. */\nexport type FileSourcePath = string | URL\n\ninterface FileStatsLike {\n readonly dev: number\n readonly ino: number\n readonly mode: number\n readonly size: number\n readonly mtimeMs: number\n readonly ctimeMs: number\n isFile(): boolean\n}\n\ninterface FileHandleLike {\n read(\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): Promise<{ bytesRead: number }>\n stat(): Promise<FileStatsLike>\n close(): Promise<void>\n}\n\ninterface NodeFsSync {\n lstatSync(path: FileSourcePath): FileStatsLike\n}\n\ninterface FileIdentity {\n readonly dev: number\n readonly ino: number\n readonly size: number\n readonly mtimeMs: number\n readonly ctimeMs: number\n}\n\ninterface ToArrayBufferOptions {\n readonly signal?: AbortSignal\n}\n\nconst FILE_SOURCE_INTERNAL = Symbol('FileSource.internal')\n\ninterface FileSourceInternalOptions {\n readonly key: typeof FILE_SOURCE_INTERNAL\n readonly identity: FileIdentity\n}\n\n/** @internal */\nexport const fileSourceTestHooks: {\n afterReadIteration?: (filled: number) => Promise<void> | void\n maxReadSize?: number\n openFile?: (path: FileSourcePath, flags: number) => Promise<FileHandleLike>\n platform?: string\n} = {}\n\nfunction getNodeFsSync(): NodeFsSync {\n // FileSource exposes `size` synchronously, so the constructor cannot use the\n // repo's usual `await import('node:...')` pattern for Node-only APIs. Keep the\n // synchronous lookup here; async callers should prefer `FileSource.fromPath()`.\n const processLike = (\n globalThis as {\n process?: { getBuiltinModule?: (id: string) => unknown }\n }\n ).process\n const fs = processLike?.getBuiltinModule?.('node:fs')\n if (!isNodeFsSync(fs)) {\n throw new Error(\n 'FileSource constructor requires process.getBuiltinModule(\"node:fs\") with synchronous filesystem APIs; use FileSource.fromPath() when synchronous filesystem access is unavailable.',\n )\n }\n return fs\n}\n\nfunction isNodeFsSync(value: unknown): value is NodeFsSync {\n if (typeof value !== 'object' || value === null) return false\n const candidate = value as Record<string, unknown>\n return typeof candidate['lstatSync'] === 'function'\n}\n\nasync function fileOpenFlags(): Promise<number> {\n const { constants } = await import('node:fs')\n // O_NOFOLLOW and O_NONBLOCK are unavailable on some platforms. When\n // O_NOFOLLOW is absent, the post-open fstat identity check below is the\n // symlink-swap defense. O_NONBLOCK avoids blocking indefinitely if a path is\n // swapped to a FIFO or another blocking special file before fstat rejects it.\n return (\n constants.O_RDONLY |\n (constants.O_NOFOLLOW ?? 0) |\n ((constants as { O_NONBLOCK?: number }).O_NONBLOCK ?? 0)\n )\n}\n\nfunction normalizeSliceOffset(value: number, size: number): number {\n if (!Number.isFinite(value)) throw new RangeError('FileSource slice offsets must be finite.')\n const integer = Math.trunc(value)\n const offset = integer < 0 ? size + integer : integer\n return Math.min(Math.max(offset, 0), size)\n}\n\nfunction formatFilePath(path: FileSourcePath): string {\n return path instanceof URL ? path.href : path\n}\n\nfunction identityFromStats(stats: FileStatsLike): FileIdentity {\n return {\n dev: stats.dev,\n ino: stats.ino,\n size: stats.size,\n mtimeMs: stats.mtimeMs,\n ctimeMs: stats.ctimeMs,\n }\n}\n\nfunction assertStableIdentity(path: FileSourcePath, stats: FileStatsLike): void {\n if (stats.dev === 0 && stats.ino === 0) {\n throw new Error(\n `FileSource: ${formatFilePath(path)} is on a filesystem that does not expose stable file identity.`,\n )\n }\n}\n\nfunction assertRegularFile(path: FileSourcePath, stats: FileStatsLike): void {\n if (!stats.isFile()) {\n throw new Error(`FileSource: ${formatFilePath(path)} is not a regular file.`)\n }\n}\n\nfunction validatedIdentityFromStats(path: FileSourcePath, stats: FileStatsLike): FileIdentity {\n assertRegularFile(path, stats)\n if (shouldComparePosixFileIdentity()) assertStableIdentity(path, stats)\n return identityFromStats(stats)\n}\n\nfunction assertSameIdentity(\n path: FileSourcePath,\n expected: FileIdentity,\n actual: FileStatsLike,\n when: string,\n): void {\n if (shouldComparePosixFileIdentity()) assertStableIdentity(path, actual)\n if (\n shouldComparePosixFileIdentity() &&\n (actual.dev !== expected.dev || actual.ino !== expected.ino)\n ) {\n throw new Error(`FileSource: ${formatFilePath(path)} changed ${when}.`)\n }\n if (actual.size !== expected.size || actual.mtimeMs !== expected.mtimeMs) {\n throw new Error(`FileSource: ${formatFilePath(path)} was modified ${when}.`)\n }\n if (shouldComparePosixChangeTime() && actual.ctimeMs !== expected.ctimeMs) {\n throw new Error(`FileSource: ${formatFilePath(path)} was modified ${when}.`)\n }\n}\n\nfunction isWindows(): boolean {\n if (fileSourceTestHooks.platform !== undefined) return fileSourceTestHooks.platform === 'win32'\n const processLike = (globalThis as { process?: { platform?: string } }).process\n return processLike?.platform === 'win32'\n}\n\nfunction shouldComparePosixFileIdentity(): boolean {\n return !isWindows()\n}\n\nfunction shouldComparePosixChangeTime(): boolean {\n return !isWindows()\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal === undefined || !signal.aborted) return\n throw signal.reason ?? new DOMException('Aborted', 'AbortError')\n}\n\nfunction maxReadSize(): number {\n return fileSourceTestHooks.maxReadSize ?? FILE_STREAM_CHUNK_SIZE\n}\n\n/* v8 ignore start -- Requires a file to pass identity checks and still EOF mid-range. */\nfunction rangeEndedEarlyError(path: FileSourcePath, offset: number, size: number): Error {\n const end = offset + size\n return new Error(\n `FileSource: ${formatFilePath(path)} ended before byte range [${offset}, ${end}) was fully read.`,\n )\n}\n/* v8 ignore stop */\n\nasync function openValidatedFile(\n path: FileSourcePath,\n identity: FileIdentity,\n): Promise<FileHandleLike> {\n const open =\n fileSourceTestHooks.openFile ??\n (\n (await import('node:fs/promises')) as {\n open(path: FileSourcePath, flags: number): Promise<FileHandleLike>\n }\n ).open\n let file: FileHandleLike\n try {\n file = await open(path, await fileOpenFlags())\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`FileSource: ${formatFilePath(path)} could not be opened: ${message}`)\n }\n\n try {\n const stats = await file.stat()\n assertRegularFile(path, stats)\n assertSameIdentity(path, identity, stats, 'before read')\n return file\n } catch (err) {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n throw err\n }\n}\n\nasync function lstatNodeFile(path: FileSourcePath): Promise<FileStatsLike> {\n const { lstat } = (await import('node:fs/promises')) as {\n lstat(path: FileSourcePath): Promise<FileStatsLike>\n }\n return lstat(path)\n}\n\nasync function readFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n signal?: AbortSignal,\n): Promise<Uint8Array> {\n throwIfAborted(signal)\n if (size === 0) {\n await verifyFileIdentityForEmptyRead(path, identity, signal)\n return new Uint8Array(0)\n }\n\n throwIfAborted(signal)\n const file = await openValidatedFile(path, identity)\n const data = new Uint8Array(size)\n let filled = 0\n try {\n while (filled < data.byteLength) {\n throwIfAborted(signal)\n const length = Math.min(maxReadSize(), data.byteLength - filled)\n const { bytesRead } = await file.read(data, filled, length, offset + filled)\n if (bytesRead === 0) throw rangeEndedEarlyError(path, offset, size)\n filled += bytesRead\n await fileSourceTestHooks.afterReadIteration?.(filled)\n }\n throwIfAborted(signal)\n const stats = await file.stat()\n assertSameIdentity(path, identity, stats, 'while being read')\n return data\n } finally {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n }\n}\n\nasync function verifyFileIdentityForEmptyRead(\n path: FileSourcePath,\n identity: FileIdentity,\n signal?: AbortSignal,\n): Promise<void> {\n throwIfAborted(signal)\n const file = await openValidatedFile(path, identity)\n try {\n throwIfAborted(signal)\n return\n } finally {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n }\n}\n\nfunction sliceFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n start: number,\n end: number,\n): ContentSource {\n const normalizedStart = normalizeSliceOffset(start, size)\n const normalizedEnd = normalizeSliceOffset(end, size)\n return new FileSliceSource(\n path,\n identity,\n offset + normalizedStart,\n Math.max(normalizedEnd - normalizedStart, 0),\n )\n}\n\nfunction streamFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n): ReadableStream<Uint8Array> {\n let position = offset\n let remaining = size\n let verifiedEmpty = false\n const abortController = new AbortController()\n\n // Open per pull so abandoned public streams do not strand file handles or\n // retain Windows locks. Each chunk still verifies identity around its read.\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n if (remaining === 0) {\n if (!verifiedEmpty) {\n verifiedEmpty = true\n await verifyFileIdentityForEmptyRead(path, identity)\n }\n controller.close()\n return\n }\n\n const length = Math.min(FILE_STREAM_CHUNK_SIZE, remaining)\n const data = await readFileRange(path, identity, position, length, abortController.signal)\n position += data.byteLength\n remaining -= data.byteLength\n controller.enqueue(data)\n if (remaining === 0) controller.close()\n } catch (err) {\n controller.error(err)\n }\n },\n cancel(reason) {\n abortController.abort(reason)\n },\n })\n}\n\nasync function fileRangeToArrayBuffer(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n options: ToArrayBufferOptions = {},\n): Promise<ArrayBuffer> {\n const data = await readFileRange(path, identity, offset, size, options.signal)\n return data.buffer as ArrayBuffer\n}\n\nclass FileSliceSource implements ContentSource {\n readonly canSlice = true\n\n constructor(\n private readonly path: FileSourcePath,\n private readonly identity: FileIdentity,\n private readonly offset: number,\n readonly size: number,\n ) {}\n\n slice(start: number, end: number): ContentSource {\n return sliceFileRange(this.path, this.identity, this.offset, this.size, start, end)\n }\n\n stream(): ReadableStream<Uint8Array> {\n return streamFileRange(this.path, this.identity, this.offset, this.size)\n }\n\n toArrayBuffer(options: ToArrayBufferOptions = {}): Promise<ArrayBuffer> {\n return fileRangeToArrayBuffer(this.path, this.identity, this.offset, this.size, options)\n }\n}\n\n/**\n * ContentSource backed by a local filesystem path.\n *\n * `FileSource` is Node-only but safe to import in browser builds: it touches\n * Node filesystem APIs only when constructed or read. The constructor performs\n * synchronous filesystem validation so `size` is immediately available; request\n * handlers, sync loops, and other latency-sensitive code should use\n * {@link FileSource.fromPath}. Both paths capture a best-effort regular file\n * identity and reject a symlink as the final path component; parent directory\n * symlinks are followed by the operating system, so callers that constrain\n * paths under a trusted root should validate those parents separately. Reads\n * reject if the path is replaced, if the filesystem cannot report stable\n * identity on POSIX platforms, or if size/mtime/ctime changes before the\n * configured byte range is read. On Windows, reads avoid unreliable dev/inode\n * identity comparisons and validate size/mtime instead.\n * Slices preserve the captured identity, so multipart uploads can read\n * disjoint ranges without materialising the whole file in memory or following\n * later leaf path swaps.\n */\nexport class FileSource implements ContentSource {\n /** Random-access: file ranges are read by absolute byte offset. */\n readonly canSlice = true\n /** File size captured at construction time. */\n readonly size: number\n private readonly path: FileSourcePath\n private readonly identity: FileIdentity\n\n /**\n * Create a FileSource for a local file path.\n * @param path - Local filesystem path or file URL.\n *\n * @throws If the runtime has no Node-compatible filesystem API.\n * @throws If the path does not reference a regular non-symlink file.\n * @throws If a POSIX filesystem cannot report stable file identity.\n */\n constructor(path: FileSourcePath)\n /**\n * Internal constructor path for async validation.\n * @param path - Local filesystem path or file URL.\n * @param internal - Module-private validated identity payload.\n *\n * @internal\n */\n constructor(path: FileSourcePath, internal?: FileSourceInternalOptions) {\n const resolvedIdentity =\n internal?.key === FILE_SOURCE_INTERNAL\n ? internal.identity\n : validatedIdentityFromStats(path, getNodeFsSync().lstatSync(path))\n this.path = path\n this.identity = resolvedIdentity\n this.size = resolvedIdentity.size\n }\n\n /**\n * Return a new file-backed source covering the specified byte range.\n * @param start - The zero-based byte offset to begin the slice.\n * @param end - The exclusive byte offset where the slice ends.\n *\n * @returns A new ContentSource representing the requested sub-range.\n */\n slice(start: number, end: number): ContentSource {\n return sliceFileRange(this.path, this.identity, 0, this.size, start, end)\n }\n\n /**\n * Open this file as a Web ReadableStream.\n * @returns A ReadableStream that reads the file lazily.\n */\n stream(): ReadableStream<Uint8Array> {\n return streamFileRange(this.path, this.identity, 0, this.size)\n }\n\n /**\n * Read this file into an ArrayBuffer.\n * @param options - Optional abort signal used while reading.\n *\n * @returns A promise resolving with the file bytes.\n */\n toArrayBuffer(options: { readonly signal?: AbortSignal } = {}): Promise<ArrayBuffer> {\n return fileRangeToArrayBuffer(this.path, this.identity, 0, this.size, options)\n }\n\n /**\n * Create a FileSource using asynchronous filesystem validation.\n * @param path - Local filesystem path or file URL.\n *\n * @returns A FileSource bound to the validated file identity.\n *\n * @throws If the path does not reference a regular non-symlink file.\n * @throws If a POSIX filesystem cannot report stable file identity.\n */\n static async fromPath(path: FileSourcePath): Promise<FileSource> {\n const identity = validatedIdentityFromStats(path, await lstatNodeFile(path))\n return constructFileSourceFromIdentity(path, identity)\n }\n}\n\nfunction constructFileSourceFromIdentity(path: FileSourcePath, identity: FileIdentity): FileSource {\n // The public overload is intentionally single-argument; Reflect.construct\n // lets fromPath pass the module-private validated identity without exposing\n // that constructor shape in the public type surface.\n return Reflect.construct(FileSource, [\n path,\n { key: FILE_SOURCE_INTERNAL, identity },\n ]) as FileSource\n}\n"],"mappings":";AAEA,IAAM,yBAAyB;AA0C/B,IAAM,uBAAuB,OAAO,qBAAqB;;AAQzD,IAAa,sBAKT,CAAC;AAEL,SAAS,gBAA4B;CASnC,MAAM,KAJJ,WAGA,SACsB,mBAAmB,SAAS;CACpD,IAAI,CAAC,aAAa,EAAE,GAClB,MAAM,IAAI,MACR,sLACF;CAEF,OAAO;AACT;AAEA,SAAS,aAAa,OAAqC;CACzD,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CAExD,OAAO,OAAO,MAAU,iBAAiB;AAC3C;AAEA,eAAe,gBAAiC;CAC9C,MAAM,EAAE,cAAc,MAAM,OAAO;CAKnC,OACE,UAAU,YACT,UAAU,cAAc,MACvB,UAAsC,cAAc;AAE1D;AAEA,SAAS,qBAAqB,OAAe,MAAsB;CACjE,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,MAAM,IAAI,WAAW,0CAA0C;CAC5F,MAAM,UAAU,KAAK,MAAM,KAAK;CAChC,MAAM,SAAS,UAAU,IAAI,OAAO,UAAU;CAC9C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A2B,MAAM,cAAc,CAAC,CAAC,UAAU,IAAI,CAAC;EACtE,KAAK,OAAO;EACZ,KAAK,WAAW;EAChB,KAAK,OAAO,iBAAiB;CAC/B;;;;;;;;CASA,MAAM,OAAe,KAA4B;EAC/C,OAAO,eAAe,KAAK,MAAM,KAAK,UAAU,GAAG,KAAK,MAAM,OAAO,GAAG;CAC1E;;;;;CAMA,SAAqC;EACnC,OAAO,gBAAgB,KAAK,MAAM,KAAK,UAAU,GAAG,KAAK,IAAI;CAC/D;;;;;;;CAQA,cAAc,UAA6C,CAAC,GAAyB;EACnF,OAAO,uBAAuB,KAAK,MAAM,KAAK,UAAU,GAAG,KAAK,MAAM,OAAO;CAC/E;;;;;;;;;;CAWA,aAAa,SAAS,MAA2C;EAE/D,OAAO,gCAAgC,MADtB,2BAA2B,MAAM,MAAM,cAAc,IAAI,CAC7B,CAAQ;CACvD;AACF;AAEA,SAAS,gCAAgC,MAAsB,UAAoC;CAIjG,OAAO,QAAQ,UAAU,YAAY,CACnC,MACA;EAAE,KAAK;EAAsB;CAAS,CACxC,CAAC;AACH"}
@@ -1,11 +1,11 @@
1
1
  //#region src/streams/file-source.ts
2
- var FILE_STREAM_CHUNK_SIZE = 16 * 1024 * 1024;
2
+ var FILE_STREAM_CHUNK_SIZE = 16777216;
3
3
  var FILE_SOURCE_INTERNAL = Symbol("FileSource.internal");
4
4
  /** @internal */
5
5
  var fileSourceTestHooks = {};
6
6
  function getNodeFsSync() {
7
7
  const fs = globalThis.process?.getBuiltinModule?.("node:fs");
8
- if (!isNodeFsSync(fs)) throw new Error("FileSource constructor requires Node.js 22.3+ synchronous filesystem APIs; use FileSource.fromPath() when synchronous filesystem access is unavailable.");
8
+ if (!isNodeFsSync(fs)) throw new Error("FileSource constructor requires process.getBuiltinModule(\"node:fs\") with synchronous filesystem APIs; use FileSource.fromPath() when synchronous filesystem access is unavailable.");
9
9
  return fs;
10
10
  }
11
11
  function isNodeFsSync(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"file-source.js","names":[],"sources":["../../src/streams/file-source.ts"],"sourcesContent":["import type { ContentSource } from './source.ts'\n\nconst FILE_STREAM_CHUNK_SIZE = 16 * 1024 * 1024\n\n/** Filesystem path accepted by {@link FileSource}. */\nexport type FileSourcePath = string | URL\n\ninterface FileStatsLike {\n readonly dev: number\n readonly ino: number\n readonly mode: number\n readonly size: number\n readonly mtimeMs: number\n readonly ctimeMs: number\n isFile(): boolean\n}\n\ninterface FileHandleLike {\n read(\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): Promise<{ bytesRead: number }>\n stat(): Promise<FileStatsLike>\n close(): Promise<void>\n}\n\ninterface NodeFsSync {\n lstatSync(path: FileSourcePath): FileStatsLike\n}\n\ninterface FileIdentity {\n readonly dev: number\n readonly ino: number\n readonly size: number\n readonly mtimeMs: number\n readonly ctimeMs: number\n}\n\ninterface ToArrayBufferOptions {\n readonly signal?: AbortSignal\n}\n\nconst FILE_SOURCE_INTERNAL = Symbol('FileSource.internal')\n\ninterface FileSourceInternalOptions {\n readonly key: typeof FILE_SOURCE_INTERNAL\n readonly identity: FileIdentity\n}\n\n/** @internal */\nexport const fileSourceTestHooks: {\n afterReadIteration?: (filled: number) => Promise<void> | void\n maxReadSize?: number\n openFile?: (path: FileSourcePath, flags: number) => Promise<FileHandleLike>\n platform?: string\n} = {}\n\nfunction getNodeFsSync(): NodeFsSync {\n // FileSource exposes `size` synchronously, so the constructor cannot use the\n // repo's usual `await import('node:...')` pattern for Node-only APIs. Keep the\n // synchronous lookup here; async callers should prefer `FileSource.fromPath()`.\n const processLike = (\n globalThis as {\n process?: { getBuiltinModule?: (id: string) => unknown }\n }\n ).process\n const fs = processLike?.getBuiltinModule?.('node:fs')\n if (!isNodeFsSync(fs)) {\n throw new Error(\n 'FileSource constructor requires Node.js 22.3+ synchronous filesystem APIs; use FileSource.fromPath() when synchronous filesystem access is unavailable.',\n )\n }\n return fs\n}\n\nfunction isNodeFsSync(value: unknown): value is NodeFsSync {\n if (typeof value !== 'object' || value === null) return false\n const candidate = value as Record<string, unknown>\n return typeof candidate['lstatSync'] === 'function'\n}\n\nasync function fileOpenFlags(): Promise<number> {\n const { constants } = await import('node:fs')\n // O_NOFOLLOW and O_NONBLOCK are unavailable on some platforms. When\n // O_NOFOLLOW is absent, the post-open fstat identity check below is the\n // symlink-swap defense. O_NONBLOCK avoids blocking indefinitely if a path is\n // swapped to a FIFO or another blocking special file before fstat rejects it.\n return (\n constants.O_RDONLY |\n (constants.O_NOFOLLOW ?? 0) |\n ((constants as { O_NONBLOCK?: number }).O_NONBLOCK ?? 0)\n )\n}\n\nfunction normalizeSliceOffset(value: number, size: number): number {\n if (!Number.isFinite(value)) throw new RangeError('FileSource slice offsets must be finite.')\n const integer = Math.trunc(value)\n const offset = integer < 0 ? size + integer : integer\n return Math.min(Math.max(offset, 0), size)\n}\n\nfunction formatFilePath(path: FileSourcePath): string {\n return path instanceof URL ? path.href : path\n}\n\nfunction identityFromStats(stats: FileStatsLike): FileIdentity {\n return {\n dev: stats.dev,\n ino: stats.ino,\n size: stats.size,\n mtimeMs: stats.mtimeMs,\n ctimeMs: stats.ctimeMs,\n }\n}\n\nfunction assertStableIdentity(path: FileSourcePath, stats: FileStatsLike): void {\n if (stats.dev === 0 && stats.ino === 0) {\n throw new Error(\n `FileSource: ${formatFilePath(path)} is on a filesystem that does not expose stable file identity.`,\n )\n }\n}\n\nfunction assertRegularFile(path: FileSourcePath, stats: FileStatsLike): void {\n if (!stats.isFile()) {\n throw new Error(`FileSource: ${formatFilePath(path)} is not a regular file.`)\n }\n}\n\nfunction validatedIdentityFromStats(path: FileSourcePath, stats: FileStatsLike): FileIdentity {\n assertRegularFile(path, stats)\n if (shouldComparePosixFileIdentity()) assertStableIdentity(path, stats)\n return identityFromStats(stats)\n}\n\nfunction assertSameIdentity(\n path: FileSourcePath,\n expected: FileIdentity,\n actual: FileStatsLike,\n when: string,\n): void {\n if (shouldComparePosixFileIdentity()) assertStableIdentity(path, actual)\n if (\n shouldComparePosixFileIdentity() &&\n (actual.dev !== expected.dev || actual.ino !== expected.ino)\n ) {\n throw new Error(`FileSource: ${formatFilePath(path)} changed ${when}.`)\n }\n if (actual.size !== expected.size || actual.mtimeMs !== expected.mtimeMs) {\n throw new Error(`FileSource: ${formatFilePath(path)} was modified ${when}.`)\n }\n if (shouldComparePosixChangeTime() && actual.ctimeMs !== expected.ctimeMs) {\n throw new Error(`FileSource: ${formatFilePath(path)} was modified ${when}.`)\n }\n}\n\nfunction isWindows(): boolean {\n if (fileSourceTestHooks.platform !== undefined) return fileSourceTestHooks.platform === 'win32'\n const processLike = (globalThis as { process?: { platform?: string } }).process\n return processLike?.platform === 'win32'\n}\n\nfunction shouldComparePosixFileIdentity(): boolean {\n return !isWindows()\n}\n\nfunction shouldComparePosixChangeTime(): boolean {\n return !isWindows()\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal === undefined || !signal.aborted) return\n throw signal.reason ?? new DOMException('Aborted', 'AbortError')\n}\n\nfunction maxReadSize(): number {\n return fileSourceTestHooks.maxReadSize ?? FILE_STREAM_CHUNK_SIZE\n}\n\n/* v8 ignore start -- Requires a file to pass identity checks and still EOF mid-range. */\nfunction rangeEndedEarlyError(path: FileSourcePath, offset: number, size: number): Error {\n const end = offset + size\n return new Error(\n `FileSource: ${formatFilePath(path)} ended before byte range [${offset}, ${end}) was fully read.`,\n )\n}\n/* v8 ignore stop */\n\nasync function openValidatedFile(\n path: FileSourcePath,\n identity: FileIdentity,\n): Promise<FileHandleLike> {\n const open =\n fileSourceTestHooks.openFile ??\n (\n (await import('node:fs/promises')) as {\n open(path: FileSourcePath, flags: number): Promise<FileHandleLike>\n }\n ).open\n let file: FileHandleLike\n try {\n file = await open(path, await fileOpenFlags())\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`FileSource: ${formatFilePath(path)} could not be opened: ${message}`)\n }\n\n try {\n const stats = await file.stat()\n assertRegularFile(path, stats)\n assertSameIdentity(path, identity, stats, 'before read')\n return file\n } catch (err) {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n throw err\n }\n}\n\nasync function lstatNodeFile(path: FileSourcePath): Promise<FileStatsLike> {\n const { lstat } = (await import('node:fs/promises')) as {\n lstat(path: FileSourcePath): Promise<FileStatsLike>\n }\n return lstat(path)\n}\n\nasync function readFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n signal?: AbortSignal,\n): Promise<Uint8Array> {\n throwIfAborted(signal)\n if (size === 0) {\n await verifyFileIdentityForEmptyRead(path, identity, signal)\n return new Uint8Array(0)\n }\n\n throwIfAborted(signal)\n const file = await openValidatedFile(path, identity)\n const data = new Uint8Array(size)\n let filled = 0\n try {\n while (filled < data.byteLength) {\n throwIfAborted(signal)\n const length = Math.min(maxReadSize(), data.byteLength - filled)\n const { bytesRead } = await file.read(data, filled, length, offset + filled)\n if (bytesRead === 0) throw rangeEndedEarlyError(path, offset, size)\n filled += bytesRead\n await fileSourceTestHooks.afterReadIteration?.(filled)\n }\n throwIfAborted(signal)\n const stats = await file.stat()\n assertSameIdentity(path, identity, stats, 'while being read')\n return data\n } finally {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n }\n}\n\nasync function verifyFileIdentityForEmptyRead(\n path: FileSourcePath,\n identity: FileIdentity,\n signal?: AbortSignal,\n): Promise<void> {\n throwIfAborted(signal)\n const file = await openValidatedFile(path, identity)\n try {\n throwIfAborted(signal)\n return\n } finally {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n }\n}\n\nfunction sliceFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n start: number,\n end: number,\n): ContentSource {\n const normalizedStart = normalizeSliceOffset(start, size)\n const normalizedEnd = normalizeSliceOffset(end, size)\n return new FileSliceSource(\n path,\n identity,\n offset + normalizedStart,\n Math.max(normalizedEnd - normalizedStart, 0),\n )\n}\n\nfunction streamFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n): ReadableStream<Uint8Array> {\n let position = offset\n let remaining = size\n let verifiedEmpty = false\n const abortController = new AbortController()\n\n // Open per pull so abandoned public streams do not strand file handles or\n // retain Windows locks. Each chunk still verifies identity around its read.\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n if (remaining === 0) {\n if (!verifiedEmpty) {\n verifiedEmpty = true\n await verifyFileIdentityForEmptyRead(path, identity)\n }\n controller.close()\n return\n }\n\n const length = Math.min(FILE_STREAM_CHUNK_SIZE, remaining)\n const data = await readFileRange(path, identity, position, length, abortController.signal)\n position += data.byteLength\n remaining -= data.byteLength\n controller.enqueue(data)\n if (remaining === 0) controller.close()\n } catch (err) {\n controller.error(err)\n }\n },\n cancel(reason) {\n abortController.abort(reason)\n },\n })\n}\n\nasync function fileRangeToArrayBuffer(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n options: ToArrayBufferOptions = {},\n): Promise<ArrayBuffer> {\n const data = await readFileRange(path, identity, offset, size, options.signal)\n return data.buffer as ArrayBuffer\n}\n\nclass FileSliceSource implements ContentSource {\n readonly canSlice = true\n\n constructor(\n private readonly path: FileSourcePath,\n private readonly identity: FileIdentity,\n private readonly offset: number,\n readonly size: number,\n ) {}\n\n slice(start: number, end: number): ContentSource {\n return sliceFileRange(this.path, this.identity, this.offset, this.size, start, end)\n }\n\n stream(): ReadableStream<Uint8Array> {\n return streamFileRange(this.path, this.identity, this.offset, this.size)\n }\n\n toArrayBuffer(options: ToArrayBufferOptions = {}): Promise<ArrayBuffer> {\n return fileRangeToArrayBuffer(this.path, this.identity, this.offset, this.size, options)\n }\n}\n\n/**\n * ContentSource backed by a local filesystem path.\n *\n * `FileSource` is Node-only but safe to import in browser builds: it touches\n * Node filesystem APIs only when constructed or read. The constructor performs\n * synchronous filesystem validation so `size` is immediately available; request\n * handlers, sync loops, and other latency-sensitive code should use\n * {@link FileSource.fromPath}. Both paths capture a best-effort regular file\n * identity and reject a symlink as the final path component; parent directory\n * symlinks are followed by the operating system, so callers that constrain\n * paths under a trusted root should validate those parents separately. Reads\n * reject if the path is replaced, if the filesystem cannot report stable\n * identity on POSIX platforms, or if size/mtime/ctime changes before the\n * configured byte range is read. On Windows, reads avoid unreliable dev/inode\n * identity comparisons and validate size/mtime instead.\n * Slices preserve the captured identity, so multipart uploads can read\n * disjoint ranges without materialising the whole file in memory or following\n * later leaf path swaps.\n */\nexport class FileSource implements ContentSource {\n /** Random-access: file ranges are read by absolute byte offset. */\n readonly canSlice = true\n /** File size captured at construction time. */\n readonly size: number\n private readonly path: FileSourcePath\n private readonly identity: FileIdentity\n\n /**\n * Create a FileSource for a local file path.\n * @param path - Local filesystem path or file URL.\n *\n * @throws If the runtime has no Node-compatible filesystem API.\n * @throws If the path does not reference a regular non-symlink file.\n * @throws If a POSIX filesystem cannot report stable file identity.\n */\n constructor(path: FileSourcePath)\n /**\n * Internal constructor path for async validation.\n * @param path - Local filesystem path or file URL.\n * @param internal - Module-private validated identity payload.\n *\n * @internal\n */\n constructor(path: FileSourcePath, internal?: FileSourceInternalOptions) {\n const resolvedIdentity =\n internal?.key === FILE_SOURCE_INTERNAL\n ? internal.identity\n : validatedIdentityFromStats(path, getNodeFsSync().lstatSync(path))\n this.path = path\n this.identity = resolvedIdentity\n this.size = resolvedIdentity.size\n }\n\n /**\n * Return a new file-backed source covering the specified byte range.\n * @param start - The zero-based byte offset to begin the slice.\n * @param end - The exclusive byte offset where the slice ends.\n *\n * @returns A new ContentSource representing the requested sub-range.\n */\n slice(start: number, end: number): ContentSource {\n return sliceFileRange(this.path, this.identity, 0, this.size, start, end)\n }\n\n /**\n * Open this file as a Web ReadableStream.\n * @returns A ReadableStream that reads the file lazily.\n */\n stream(): ReadableStream<Uint8Array> {\n return streamFileRange(this.path, this.identity, 0, this.size)\n }\n\n /**\n * Read this file into an ArrayBuffer.\n * @param options - Optional abort signal used while reading.\n *\n * @returns A promise resolving with the file bytes.\n */\n toArrayBuffer(options: { readonly signal?: AbortSignal } = {}): Promise<ArrayBuffer> {\n return fileRangeToArrayBuffer(this.path, this.identity, 0, this.size, options)\n }\n\n /**\n * Create a FileSource using asynchronous filesystem validation.\n * @param path - Local filesystem path or file URL.\n *\n * @returns A FileSource bound to the validated file identity.\n *\n * @throws If the path does not reference a regular non-symlink file.\n * @throws If a POSIX filesystem cannot report stable file identity.\n */\n static async fromPath(path: FileSourcePath): Promise<FileSource> {\n const identity = validatedIdentityFromStats(path, await lstatNodeFile(path))\n return constructFileSourceFromIdentity(path, identity)\n }\n}\n\nfunction constructFileSourceFromIdentity(path: FileSourcePath, identity: FileIdentity): FileSource {\n // The public overload is intentionally single-argument; Reflect.construct\n // lets fromPath pass the module-private validated identity without exposing\n // that constructor shape in the public type surface.\n return Reflect.construct(FileSource, [\n path,\n { key: FILE_SOURCE_INTERNAL, identity },\n ]) as FileSource\n}\n"],"mappings":";AAEA,IAAM,yBAAyB,KAAK,OAAO;AA0C3C,IAAM,uBAAuB,OAAO,qBAAqB;;AAQzD,IAAa,sBAKT,CAAC;AAEL,SAAS,gBAA4B;CASnC,MAAM,KAJJ,WAGA,SACsB,mBAAmB,SAAS;CACpD,IAAI,CAAC,aAAa,EAAE,GAClB,MAAM,IAAI,MACR,yJACF;CAEF,OAAO;AACT;AAEA,SAAS,aAAa,OAAqC;CACzD,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CAExD,OAAO,OAAO,MAAU,iBAAiB;AAC3C;AAEA,eAAe,gBAAiC;CAC9C,MAAM,EAAE,cAAc,MAAM,OAAO;CAKnC,OACE,UAAU,YACT,UAAU,cAAc,MACvB,UAAsC,cAAc;AAE1D;AAEA,SAAS,qBAAqB,OAAe,MAAsB;CACjE,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,MAAM,IAAI,WAAW,0CAA0C;CAC5F,MAAM,UAAU,KAAK,MAAM,KAAK;CAChC,MAAM,SAAS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AU,QAAQ,uBACd,SAAS,WACT,2BAA2B,MAAM,cAAc,CAAC,CAAC,UAAU,IAAI,CAAC;EACtE,KAAK,OAAO;EACZ,KAAK,WAAW;EAChB,KAAK,OAAO,iBAAiB;CAC/B;;;;;;;;CASA,MAAM,OAAe,KAA4B;EAC/C,OAAO,eAAe,KAAK,MAAM,KAAK,UAAU,GAAG,KAAK,MAAM,OAAO,GAAG;CAC1E;;;;;CAMA,SAAqC;EACnC,OAAO,gBAAgB,KAAK,MAAM,KAAK,UAAU,GAAG,KAAK,IAAI;CAC/D;;;;;;;CAQA,cAAc,UAA6C,CAAC,GAAyB;EACnF,OAAO,uBAAuB,KAAK,MAAM,KAAK,UAAU,GAAG,KAAK,MAAM,OAAO;CAC/E;;;;;;;;;;CAWA,aAAa,SAAS,MAA2C;EAE/D,OAAO,gCAAgC,MADtB,2BAA2B,MAAM,MAAM,cAAc,IAAI,CAC7B,CAAQ;CACvD;AACF;AAEA,SAAS,gCAAgC,MAAsB,UAAoC;CAIjG,OAAO,QAAQ,UAAU,YAAY,CACnC,MACA;EAAE,KAAK;EAAsB;CAAS,CACxC,CAAC;AACH"}
1
+ {"version":3,"file":"file-source.js","names":[],"sources":["../../src/streams/file-source.ts"],"sourcesContent":["import type { ContentSource } from './source.ts'\n\nconst FILE_STREAM_CHUNK_SIZE = 16 * 1024 * 1024\n\n/** Filesystem path accepted by {@link FileSource}. */\nexport type FileSourcePath = string | URL\n\ninterface FileStatsLike {\n readonly dev: number\n readonly ino: number\n readonly mode: number\n readonly size: number\n readonly mtimeMs: number\n readonly ctimeMs: number\n isFile(): boolean\n}\n\ninterface FileHandleLike {\n read(\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): Promise<{ bytesRead: number }>\n stat(): Promise<FileStatsLike>\n close(): Promise<void>\n}\n\ninterface NodeFsSync {\n lstatSync(path: FileSourcePath): FileStatsLike\n}\n\ninterface FileIdentity {\n readonly dev: number\n readonly ino: number\n readonly size: number\n readonly mtimeMs: number\n readonly ctimeMs: number\n}\n\ninterface ToArrayBufferOptions {\n readonly signal?: AbortSignal\n}\n\nconst FILE_SOURCE_INTERNAL = Symbol('FileSource.internal')\n\ninterface FileSourceInternalOptions {\n readonly key: typeof FILE_SOURCE_INTERNAL\n readonly identity: FileIdentity\n}\n\n/** @internal */\nexport const fileSourceTestHooks: {\n afterReadIteration?: (filled: number) => Promise<void> | void\n maxReadSize?: number\n openFile?: (path: FileSourcePath, flags: number) => Promise<FileHandleLike>\n platform?: string\n} = {}\n\nfunction getNodeFsSync(): NodeFsSync {\n // FileSource exposes `size` synchronously, so the constructor cannot use the\n // repo's usual `await import('node:...')` pattern for Node-only APIs. Keep the\n // synchronous lookup here; async callers should prefer `FileSource.fromPath()`.\n const processLike = (\n globalThis as {\n process?: { getBuiltinModule?: (id: string) => unknown }\n }\n ).process\n const fs = processLike?.getBuiltinModule?.('node:fs')\n if (!isNodeFsSync(fs)) {\n throw new Error(\n 'FileSource constructor requires process.getBuiltinModule(\"node:fs\") with synchronous filesystem APIs; use FileSource.fromPath() when synchronous filesystem access is unavailable.',\n )\n }\n return fs\n}\n\nfunction isNodeFsSync(value: unknown): value is NodeFsSync {\n if (typeof value !== 'object' || value === null) return false\n const candidate = value as Record<string, unknown>\n return typeof candidate['lstatSync'] === 'function'\n}\n\nasync function fileOpenFlags(): Promise<number> {\n const { constants } = await import('node:fs')\n // O_NOFOLLOW and O_NONBLOCK are unavailable on some platforms. When\n // O_NOFOLLOW is absent, the post-open fstat identity check below is the\n // symlink-swap defense. O_NONBLOCK avoids blocking indefinitely if a path is\n // swapped to a FIFO or another blocking special file before fstat rejects it.\n return (\n constants.O_RDONLY |\n (constants.O_NOFOLLOW ?? 0) |\n ((constants as { O_NONBLOCK?: number }).O_NONBLOCK ?? 0)\n )\n}\n\nfunction normalizeSliceOffset(value: number, size: number): number {\n if (!Number.isFinite(value)) throw new RangeError('FileSource slice offsets must be finite.')\n const integer = Math.trunc(value)\n const offset = integer < 0 ? size + integer : integer\n return Math.min(Math.max(offset, 0), size)\n}\n\nfunction formatFilePath(path: FileSourcePath): string {\n return path instanceof URL ? path.href : path\n}\n\nfunction identityFromStats(stats: FileStatsLike): FileIdentity {\n return {\n dev: stats.dev,\n ino: stats.ino,\n size: stats.size,\n mtimeMs: stats.mtimeMs,\n ctimeMs: stats.ctimeMs,\n }\n}\n\nfunction assertStableIdentity(path: FileSourcePath, stats: FileStatsLike): void {\n if (stats.dev === 0 && stats.ino === 0) {\n throw new Error(\n `FileSource: ${formatFilePath(path)} is on a filesystem that does not expose stable file identity.`,\n )\n }\n}\n\nfunction assertRegularFile(path: FileSourcePath, stats: FileStatsLike): void {\n if (!stats.isFile()) {\n throw new Error(`FileSource: ${formatFilePath(path)} is not a regular file.`)\n }\n}\n\nfunction validatedIdentityFromStats(path: FileSourcePath, stats: FileStatsLike): FileIdentity {\n assertRegularFile(path, stats)\n if (shouldComparePosixFileIdentity()) assertStableIdentity(path, stats)\n return identityFromStats(stats)\n}\n\nfunction assertSameIdentity(\n path: FileSourcePath,\n expected: FileIdentity,\n actual: FileStatsLike,\n when: string,\n): void {\n if (shouldComparePosixFileIdentity()) assertStableIdentity(path, actual)\n if (\n shouldComparePosixFileIdentity() &&\n (actual.dev !== expected.dev || actual.ino !== expected.ino)\n ) {\n throw new Error(`FileSource: ${formatFilePath(path)} changed ${when}.`)\n }\n if (actual.size !== expected.size || actual.mtimeMs !== expected.mtimeMs) {\n throw new Error(`FileSource: ${formatFilePath(path)} was modified ${when}.`)\n }\n if (shouldComparePosixChangeTime() && actual.ctimeMs !== expected.ctimeMs) {\n throw new Error(`FileSource: ${formatFilePath(path)} was modified ${when}.`)\n }\n}\n\nfunction isWindows(): boolean {\n if (fileSourceTestHooks.platform !== undefined) return fileSourceTestHooks.platform === 'win32'\n const processLike = (globalThis as { process?: { platform?: string } }).process\n return processLike?.platform === 'win32'\n}\n\nfunction shouldComparePosixFileIdentity(): boolean {\n return !isWindows()\n}\n\nfunction shouldComparePosixChangeTime(): boolean {\n return !isWindows()\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal === undefined || !signal.aborted) return\n throw signal.reason ?? new DOMException('Aborted', 'AbortError')\n}\n\nfunction maxReadSize(): number {\n return fileSourceTestHooks.maxReadSize ?? FILE_STREAM_CHUNK_SIZE\n}\n\n/* v8 ignore start -- Requires a file to pass identity checks and still EOF mid-range. */\nfunction rangeEndedEarlyError(path: FileSourcePath, offset: number, size: number): Error {\n const end = offset + size\n return new Error(\n `FileSource: ${formatFilePath(path)} ended before byte range [${offset}, ${end}) was fully read.`,\n )\n}\n/* v8 ignore stop */\n\nasync function openValidatedFile(\n path: FileSourcePath,\n identity: FileIdentity,\n): Promise<FileHandleLike> {\n const open =\n fileSourceTestHooks.openFile ??\n (\n (await import('node:fs/promises')) as {\n open(path: FileSourcePath, flags: number): Promise<FileHandleLike>\n }\n ).open\n let file: FileHandleLike\n try {\n file = await open(path, await fileOpenFlags())\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`FileSource: ${formatFilePath(path)} could not be opened: ${message}`)\n }\n\n try {\n const stats = await file.stat()\n assertRegularFile(path, stats)\n assertSameIdentity(path, identity, stats, 'before read')\n return file\n } catch (err) {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n throw err\n }\n}\n\nasync function lstatNodeFile(path: FileSourcePath): Promise<FileStatsLike> {\n const { lstat } = (await import('node:fs/promises')) as {\n lstat(path: FileSourcePath): Promise<FileStatsLike>\n }\n return lstat(path)\n}\n\nasync function readFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n signal?: AbortSignal,\n): Promise<Uint8Array> {\n throwIfAborted(signal)\n if (size === 0) {\n await verifyFileIdentityForEmptyRead(path, identity, signal)\n return new Uint8Array(0)\n }\n\n throwIfAborted(signal)\n const file = await openValidatedFile(path, identity)\n const data = new Uint8Array(size)\n let filled = 0\n try {\n while (filled < data.byteLength) {\n throwIfAborted(signal)\n const length = Math.min(maxReadSize(), data.byteLength - filled)\n const { bytesRead } = await file.read(data, filled, length, offset + filled)\n if (bytesRead === 0) throw rangeEndedEarlyError(path, offset, size)\n filled += bytesRead\n await fileSourceTestHooks.afterReadIteration?.(filled)\n }\n throwIfAborted(signal)\n const stats = await file.stat()\n assertSameIdentity(path, identity, stats, 'while being read')\n return data\n } finally {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n }\n}\n\nasync function verifyFileIdentityForEmptyRead(\n path: FileSourcePath,\n identity: FileIdentity,\n signal?: AbortSignal,\n): Promise<void> {\n throwIfAborted(signal)\n const file = await openValidatedFile(path, identity)\n try {\n throwIfAborted(signal)\n return\n } finally {\n /* v8 ignore next -- Cleanup failure is deliberately best-effort. */\n await file.close().catch(() => {})\n }\n}\n\nfunction sliceFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n start: number,\n end: number,\n): ContentSource {\n const normalizedStart = normalizeSliceOffset(start, size)\n const normalizedEnd = normalizeSliceOffset(end, size)\n return new FileSliceSource(\n path,\n identity,\n offset + normalizedStart,\n Math.max(normalizedEnd - normalizedStart, 0),\n )\n}\n\nfunction streamFileRange(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n): ReadableStream<Uint8Array> {\n let position = offset\n let remaining = size\n let verifiedEmpty = false\n const abortController = new AbortController()\n\n // Open per pull so abandoned public streams do not strand file handles or\n // retain Windows locks. Each chunk still verifies identity around its read.\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n if (remaining === 0) {\n if (!verifiedEmpty) {\n verifiedEmpty = true\n await verifyFileIdentityForEmptyRead(path, identity)\n }\n controller.close()\n return\n }\n\n const length = Math.min(FILE_STREAM_CHUNK_SIZE, remaining)\n const data = await readFileRange(path, identity, position, length, abortController.signal)\n position += data.byteLength\n remaining -= data.byteLength\n controller.enqueue(data)\n if (remaining === 0) controller.close()\n } catch (err) {\n controller.error(err)\n }\n },\n cancel(reason) {\n abortController.abort(reason)\n },\n })\n}\n\nasync function fileRangeToArrayBuffer(\n path: FileSourcePath,\n identity: FileIdentity,\n offset: number,\n size: number,\n options: ToArrayBufferOptions = {},\n): Promise<ArrayBuffer> {\n const data = await readFileRange(path, identity, offset, size, options.signal)\n return data.buffer as ArrayBuffer\n}\n\nclass FileSliceSource implements ContentSource {\n readonly canSlice = true\n\n constructor(\n private readonly path: FileSourcePath,\n private readonly identity: FileIdentity,\n private readonly offset: number,\n readonly size: number,\n ) {}\n\n slice(start: number, end: number): ContentSource {\n return sliceFileRange(this.path, this.identity, this.offset, this.size, start, end)\n }\n\n stream(): ReadableStream<Uint8Array> {\n return streamFileRange(this.path, this.identity, this.offset, this.size)\n }\n\n toArrayBuffer(options: ToArrayBufferOptions = {}): Promise<ArrayBuffer> {\n return fileRangeToArrayBuffer(this.path, this.identity, this.offset, this.size, options)\n }\n}\n\n/**\n * ContentSource backed by a local filesystem path.\n *\n * `FileSource` is Node-only but safe to import in browser builds: it touches\n * Node filesystem APIs only when constructed or read. The constructor performs\n * synchronous filesystem validation so `size` is immediately available; request\n * handlers, sync loops, and other latency-sensitive code should use\n * {@link FileSource.fromPath}. Both paths capture a best-effort regular file\n * identity and reject a symlink as the final path component; parent directory\n * symlinks are followed by the operating system, so callers that constrain\n * paths under a trusted root should validate those parents separately. Reads\n * reject if the path is replaced, if the filesystem cannot report stable\n * identity on POSIX platforms, or if size/mtime/ctime changes before the\n * configured byte range is read. On Windows, reads avoid unreliable dev/inode\n * identity comparisons and validate size/mtime instead.\n * Slices preserve the captured identity, so multipart uploads can read\n * disjoint ranges without materialising the whole file in memory or following\n * later leaf path swaps.\n */\nexport class FileSource implements ContentSource {\n /** Random-access: file ranges are read by absolute byte offset. */\n readonly canSlice = true\n /** File size captured at construction time. */\n readonly size: number\n private readonly path: FileSourcePath\n private readonly identity: FileIdentity\n\n /**\n * Create a FileSource for a local file path.\n * @param path - Local filesystem path or file URL.\n *\n * @throws If the runtime has no Node-compatible filesystem API.\n * @throws If the path does not reference a regular non-symlink file.\n * @throws If a POSIX filesystem cannot report stable file identity.\n */\n constructor(path: FileSourcePath)\n /**\n * Internal constructor path for async validation.\n * @param path - Local filesystem path or file URL.\n * @param internal - Module-private validated identity payload.\n *\n * @internal\n */\n constructor(path: FileSourcePath, internal?: FileSourceInternalOptions) {\n const resolvedIdentity =\n internal?.key === FILE_SOURCE_INTERNAL\n ? internal.identity\n : validatedIdentityFromStats(path, getNodeFsSync().lstatSync(path))\n this.path = path\n this.identity = resolvedIdentity\n this.size = resolvedIdentity.size\n }\n\n /**\n * Return a new file-backed source covering the specified byte range.\n * @param start - The zero-based byte offset to begin the slice.\n * @param end - The exclusive byte offset where the slice ends.\n *\n * @returns A new ContentSource representing the requested sub-range.\n */\n slice(start: number, end: number): ContentSource {\n return sliceFileRange(this.path, this.identity, 0, this.size, start, end)\n }\n\n /**\n * Open this file as a Web ReadableStream.\n * @returns A ReadableStream that reads the file lazily.\n */\n stream(): ReadableStream<Uint8Array> {\n return streamFileRange(this.path, this.identity, 0, this.size)\n }\n\n /**\n * Read this file into an ArrayBuffer.\n * @param options - Optional abort signal used while reading.\n *\n * @returns A promise resolving with the file bytes.\n */\n toArrayBuffer(options: { readonly signal?: AbortSignal } = {}): Promise<ArrayBuffer> {\n return fileRangeToArrayBuffer(this.path, this.identity, 0, this.size, options)\n }\n\n /**\n * Create a FileSource using asynchronous filesystem validation.\n * @param path - Local filesystem path or file URL.\n *\n * @returns A FileSource bound to the validated file identity.\n *\n * @throws If the path does not reference a regular non-symlink file.\n * @throws If a POSIX filesystem cannot report stable file identity.\n */\n static async fromPath(path: FileSourcePath): Promise<FileSource> {\n const identity = validatedIdentityFromStats(path, await lstatNodeFile(path))\n return constructFileSourceFromIdentity(path, identity)\n }\n}\n\nfunction constructFileSourceFromIdentity(path: FileSourcePath, identity: FileIdentity): FileSource {\n // The public overload is intentionally single-argument; Reflect.construct\n // lets fromPath pass the module-private validated identity without exposing\n // that constructor shape in the public type surface.\n return Reflect.construct(FileSource, [\n path,\n { key: FILE_SOURCE_INTERNAL, identity },\n ]) as FileSource\n}\n"],"mappings":";AAEA,IAAM,yBAAyB;AA0C/B,IAAM,uBAAuB,OAAO,qBAAqB;;AAQzD,IAAa,sBAKT,CAAC;AAEL,SAAS,gBAA4B;CASnC,MAAM,KAJJ,WAGA,SACsB,mBAAmB,SAAS;CACpD,IAAI,CAAC,aAAa,EAAE,GAClB,MAAM,IAAI,MACR,sLACF;CAEF,OAAO;AACT;AAEA,SAAS,aAAa,OAAqC;CACzD,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CAExD,OAAO,OAAO,MAAU,iBAAiB;AAC3C;AAEA,eAAe,gBAAiC;CAC9C,MAAM,EAAE,cAAc,MAAM,OAAO;CAKnC,OACE,UAAU,YACT,UAAU,cAAc,MACvB,UAAsC,cAAc;AAE1D;AAEA,SAAS,qBAAqB,OAAe,MAAsB;CACjE,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,MAAM,IAAI,WAAW,0CAA0C;CAC5F,MAAM,UAAU,KAAK,MAAM,KAAK;CAChC,MAAM,SAAS,UAAU,IAAI,OAAO,UAAU;CAC9C,OAAO,KAAK,IAAI,KAAK,IAAI,QAAQ,CAAC,GAAG,IAAI;AAC3C;AAEA,SAAS,eAAe,MAA8B;CACpD,OAAO,gBAAgB,MAAM,KAAK,OAAO;AAC3C;AAEA,SAAS,kBAAkB,OAAoC;CAC7D,OAAO;EACL,KAAK,MAAM;EACX,KAAK,MAAM;EACX,MAAM,MAAM;EACZ,SAAS,MAAM;EACf,SAAS,MAAM;CACjB;AACF;AAEA,SAAS,qBAAqB,MAAsB,OAA4B;CAC9E,IAAI,MAAM,QAAQ,KAAK,MAAM,QAAQ,GACnC,MAAM,IAAI,MACR,eAAe,eAAe,IAAI,EAAE,+DACtC;AAEJ;AAEA,SAAS,kBAAkB,MAAsB,OAA4B;CAC3E,IAAI,CAAC,MAAM,OAAO,GA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