@ref0/git 0.20.0 → 0.25.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 (378) hide show
  1. package/dist/access/private-refs.mjs +1 -1
  2. package/dist/auth/access-jwt.mjs +3 -3
  3. package/dist/auth/auth-namespace.d.mts +3 -3
  4. package/dist/auth/auth-namespace.mjs +3 -2
  5. package/dist/auth/auth.d.mts +3 -3
  6. package/dist/auth/auth.mjs +9 -8
  7. package/dist/auth/authorize.mjs +1 -1
  8. package/dist/auth/fences.d.mts +1 -1
  9. package/dist/auth/host-function.mjs +1 -1
  10. package/dist/auth/host-services.mjs +4 -6
  11. package/dist/auth/identify.d.mts +1 -1
  12. package/dist/auth/identify.mjs +6 -0
  13. package/dist/auth/token-cleanup.mjs +2 -2
  14. package/dist/auth/token-rows.mjs +6 -1
  15. package/dist/auth/token-text.mjs +1 -1
  16. package/dist/auth/tokens-base.d.mts +1 -1
  17. package/dist/auth/tokens.d.mts +1 -1
  18. package/dist/auth/tokens.mjs +1 -1
  19. package/dist/client/client.d.mts +15 -7
  20. package/dist/client/client.mjs +21 -12
  21. package/dist/client/git-http.mjs +1 -1
  22. package/dist/client/local.mjs +60 -24
  23. package/dist/client/negotiate.mjs +3 -3
  24. package/dist/client/push-upload.mjs +26 -10
  25. package/dist/client/remote.mjs +4 -3
  26. package/dist/client/run-remote-helper.d.mts +2 -2
  27. package/dist/client/run-remote-helper.mjs +6 -6
  28. package/dist/client/slice-push.d.mts +1 -1
  29. package/dist/client/transport.mjs +3 -3
  30. package/dist/contracts/blobs.d.mts +3 -3
  31. package/dist/contracts/blobs.mjs +1 -1
  32. package/dist/contracts/calls-spent.mjs +5 -33
  33. package/dist/contracts/client.d.mts +15 -14
  34. package/dist/contracts/commits.d.mts +4 -4
  35. package/dist/contracts/commits.mjs +1 -1
  36. package/dist/contracts/engine.d.mts +2 -2
  37. package/dist/contracts/events.d.mts +1 -1
  38. package/dist/contracts/events.mjs +1 -1
  39. package/dist/contracts/files.d.mts +4 -4
  40. package/dist/contracts/files.mjs +1 -1
  41. package/dist/contracts/forks.d.mts +4 -4
  42. package/dist/contracts/forks.mjs +1 -1
  43. package/dist/contracts/git-hooks.d.mts +1 -1
  44. package/dist/contracts/git.d.mts +9 -5
  45. package/dist/contracts/grants.d.mts +1 -1
  46. package/dist/contracts/merges.d.mts +1 -1
  47. package/dist/contracts/object-values.d.mts +1 -0
  48. package/dist/contracts/object-values.mjs +16 -1
  49. package/dist/contracts/objects.d.mts +20 -17
  50. package/dist/contracts/opaque.mjs +1 -1
  51. package/dist/contracts/operations.mjs +1 -1
  52. package/dist/contracts/queue.d.mts +208 -44
  53. package/dist/contracts/queue.mjs +5 -5
  54. package/dist/contracts/refs.d.mts +5 -5
  55. package/dist/contracts/refs.mjs +1 -1
  56. package/dist/contracts/remote.d.mts +3 -6
  57. package/dist/contracts/repos.d.mts +3 -3
  58. package/dist/contracts/repos.mjs +1 -1
  59. package/dist/contracts/result.d.mts +10 -7
  60. package/dist/contracts/result.mjs +8 -3
  61. package/dist/contracts/rules.d.mts +2 -2
  62. package/dist/contracts/server.d.mts +8 -10
  63. package/dist/contracts/services.d.mts +6 -9
  64. package/dist/contracts/services.mjs +1 -2
  65. package/dist/contracts/signin.d.mts +1 -1
  66. package/dist/contracts/store.d.mts +2 -2
  67. package/dist/contracts/sync.d.mts +63 -6
  68. package/dist/contracts/sync.mjs +3 -2
  69. package/dist/contracts/tags.d.mts +3 -3
  70. package/dist/contracts/tags.mjs +1 -1
  71. package/dist/contracts/tokens.d.mts +2 -2
  72. package/dist/contracts/tokens.mjs +1 -1
  73. package/dist/contracts/topics.d.mts +9 -9
  74. package/dist/contracts/trees.d.mts +4 -4
  75. package/dist/contracts/trees.mjs +1 -1
  76. package/dist/contracts/work.d.mts +4 -4
  77. package/dist/contracts/work.mjs +2 -2
  78. package/dist/core/access.d.mts +1 -1
  79. package/dist/core/ancestry.mjs +30 -34
  80. package/dist/core/{promise.mjs → call-groups.mjs} +7 -30
  81. package/dist/core/call-services.mjs +1 -1
  82. package/dist/core/events/deliver.d.mts +2 -2
  83. package/dist/core/events/deliver.mjs +3 -3
  84. package/dist/core/events/retired.mjs +1 -1
  85. package/dist/core/forks.mjs +5 -5
  86. package/dist/core/hooks/groups.mjs +2 -2
  87. package/dist/core/imports.mjs +101 -21
  88. package/dist/core/index-job.mjs +14 -9
  89. package/dist/core/index-lost.d.mts +1 -1
  90. package/dist/core/loose-tally.mjs +38 -15
  91. package/dist/core/merge-parts.d.mts +17 -4
  92. package/dist/core/merge-parts.mjs +7 -2
  93. package/dist/core/mirror-rows.mjs +31 -1
  94. package/dist/core/objects/blobs.mjs +8 -10
  95. package/dist/core/objects/files.mjs +20 -17
  96. package/dist/core/objects/objects-layer.mjs +1 -1
  97. package/dist/core/objects/peel.mjs +1 -7
  98. package/dist/core/objects/reading.mjs +19 -18
  99. package/dist/core/objects/tree-edits.mjs +1 -1
  100. package/dist/core/objects/trees.mjs +257 -58
  101. package/dist/core/objects/writing.mjs +3 -9
  102. package/dist/core/own-writes.mjs +1 -1
  103. package/dist/core/parts.d.mts +8 -1
  104. package/dist/core/parts.mjs +8 -4
  105. package/dist/core/purge.mjs +31 -18
  106. package/dist/core/push.d.mts +2 -2
  107. package/dist/core/push.mjs +125 -94
  108. package/dist/core/receipts.d.mts +2 -2
  109. package/dist/core/receipts.mjs +9 -2
  110. package/dist/core/ref-index-job.mjs +4 -4
  111. package/dist/core/ref-view.mjs +74 -31
  112. package/dist/core/refs.mjs +3 -3
  113. package/dist/core/repack.mjs +25 -30
  114. package/dist/core/repo-info.mjs +1 -1
  115. package/dist/core/repos.mjs +1 -1
  116. package/dist/core/rules/changes.mjs +18 -40
  117. package/dist/core/rules/check.mjs +6 -5
  118. package/dist/core/rules/commit-changes.mjs +3 -15
  119. package/dist/core/rules/context.d.mts +3 -3
  120. package/dist/core/rules/context.mjs +18 -14
  121. package/dist/core/rules/fetch.mjs +1 -1
  122. package/dist/core/rules/protect.mjs +30 -17
  123. package/dist/core/saved-caller-views.d.mts +1 -1
  124. package/dist/core/saved-caller-views.mjs +3 -3
  125. package/dist/core/saved-callers.d.mts +1 -1
  126. package/dist/core/saved-callers.mjs +1 -1
  127. package/dist/core/seam.d.mts +1 -2
  128. package/dist/core/view.d.mts +6 -3
  129. package/dist/core/view.mjs +11 -10
  130. package/dist/core/work.mjs +2 -2
  131. package/dist/engine/allotted-xdiff.mjs +3 -16
  132. package/dist/engine/combined.d.mts +3 -0
  133. package/dist/engine/combined.mjs +200 -185
  134. package/dist/engine/content.d.mts +2 -2
  135. package/dist/engine/content.mjs +1 -1
  136. package/dist/engine/merge.mjs +7 -9
  137. package/dist/engine/reads.d.mts +2 -2
  138. package/dist/engine/reads.mjs +22 -14
  139. package/dist/engine/xdiff.d.mts +1 -1
  140. package/dist/engine/xdiff.mjs +1 -1
  141. package/dist/event-streams/event-streams.d.mts +1 -1
  142. package/dist/event-streams/event-streams.mjs +1 -1
  143. package/dist/event-streams/stream.d.mts +2 -2
  144. package/dist/event-streams/stream.mjs +3 -3
  145. package/dist/extend.d.mts +2 -6
  146. package/dist/extend.mjs +1 -5
  147. package/dist/http/core-parts.mjs +83 -26
  148. package/dist/http/handler.mjs +54 -9
  149. package/dist/http/parts.d.mts +1 -0
  150. package/dist/http/push-upload-job.mjs +138 -24
  151. package/dist/http/push-uploads.mjs +2 -2
  152. package/dist/http/receive-pack.mjs +14 -53
  153. package/dist/http/request-snapshot.mjs +258 -0
  154. package/dist/http/upload-pack.mjs +23 -18
  155. package/dist/index.d.mts +29 -21
  156. package/dist/index.mjs +11 -2
  157. package/dist/lfs/base.d.mts +1 -1
  158. package/dist/lfs/copy.d.mts +49 -1
  159. package/dist/lfs/copy.mjs +135 -22
  160. package/dist/lfs/layer.d.mts +4 -3
  161. package/dist/lfs/layer.mjs +4 -5
  162. package/dist/lfs/locks.mjs +2 -2
  163. package/dist/lfs/objects.d.mts +1 -1
  164. package/dist/lfs/objects.mjs +3 -3
  165. package/dist/lfs/pointers.mjs +1 -1
  166. package/dist/lfs/rows.d.mts +1 -1
  167. package/dist/lfs/rows.mjs +11 -4
  168. package/dist/lfs/upkeep.mjs +40 -9
  169. package/dist/lfs/uploaded.mjs +1 -1
  170. package/dist/lfs/wire.mjs +1 -1
  171. package/dist/merges/merges.mjs +17 -2
  172. package/dist/protocol/bytes/buffers.d.mts +1 -1
  173. package/dist/protocol/bytes/buffers.mjs +1 -1
  174. package/dist/protocol/bytes/deflate.d.mts +1 -1
  175. package/dist/protocol/bytes/deflate.mjs +1 -1
  176. package/dist/protocol/bytes/inflate.d.mts +1 -1
  177. package/dist/protocol/bytes/inflate.mjs +1 -1
  178. package/dist/protocol/bytes/sha1.d.mts +1 -1
  179. package/dist/protocol/bytes/sha1.mjs +1 -1
  180. package/dist/protocol/diff/read.d.mts +2 -1
  181. package/dist/protocol/diff/read.mjs +102 -8
  182. package/dist/protocol/packs/graph.mjs +1 -1
  183. package/dist/protocol/packs/idx.d.mts +1 -1
  184. package/dist/protocol/packs/idx.mjs +1 -1
  185. package/dist/protocol/packs/parts.mjs +1 -1
  186. package/dist/protocol/packs/reader.d.mts +1 -1
  187. package/dist/protocol/packs/reader.mjs +1 -1
  188. package/dist/protocol/packs/write-error.d.mts +1 -1
  189. package/dist/protocol/packs/write-error.mjs +1 -1
  190. package/dist/protocol/packs/writer.mjs +3 -3
  191. package/dist/protocol/wire/advertisement.d.mts +1 -1
  192. package/dist/protocol/wire/advertisement.mjs +3 -2
  193. package/dist/protocol/wire/fetch.d.mts +1 -1
  194. package/dist/protocol/wire/fetch.mjs +1 -1
  195. package/dist/protocol/wire/lines.d.mts +9 -1
  196. package/dist/protocol/wire/lines.mjs +28 -1
  197. package/dist/protocol/wire/push-uploads.mjs +10 -7
  198. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  199. package/dist/protocol/wire/receive-pack.mjs +1 -1
  200. package/dist/protocol/wire/report-status.d.mts +1 -1
  201. package/dist/protocol/wire/report-status.mjs +1 -1
  202. package/dist/protocol/wire/v2.d.mts +1 -1
  203. package/dist/protocol/wire/v2.mjs +1 -1
  204. package/dist/queue/advance.mjs +31 -24
  205. package/dist/queue/base.d.mts +5 -3
  206. package/dist/queue/calls.mjs +5 -5
  207. package/dist/queue/commit.mjs +1 -1
  208. package/dist/queue/host.d.mts +1 -1
  209. package/dist/queue/layer.d.mts +0 -1
  210. package/dist/queue/layer.mjs +9 -5
  211. package/dist/queue/schedule.mjs +1 -1
  212. package/dist/queue/search.mjs +1 -1
  213. package/dist/queue/state.mjs +1 -1
  214. package/dist/queue/trim.mjs +2 -2
  215. package/dist/rest/client.d.mts +1 -1
  216. package/dist/rest/client.mjs +6 -6
  217. package/dist/rest/errors.mjs +1 -1
  218. package/dist/rest/handler.mjs +2 -2
  219. package/dist/rest/handlers.mjs +16 -6
  220. package/dist/rest/layer.mjs +1 -1
  221. package/dist/rest/listen.mjs +2 -2
  222. package/dist/rest/refs.mjs +1 -1
  223. package/dist/server/edge.mjs +27 -3
  224. package/dist/server/git-layer.d.mts +1 -2
  225. package/dist/server/git-layer.mjs +4 -5
  226. package/dist/server/lifecycle.mjs +1 -1
  227. package/dist/server/registry.mjs +2 -8
  228. package/dist/server/server.mjs +62 -43
  229. package/dist/signin/context.d.mts +1 -1
  230. package/dist/signin/context.mjs +1 -1
  231. package/dist/signin/forms.mjs +1 -1
  232. package/dist/signin/grants.d.mts +2 -2
  233. package/dist/signin/grants.mjs +1 -1
  234. package/dist/signin/wire.mjs +1 -1
  235. package/dist/storage/allotted.mjs +4 -9
  236. package/dist/storage/batch-upkeep.mjs +31 -12
  237. package/dist/storage/batches.d.mts +2 -3
  238. package/dist/storage/batches.mjs +52 -49
  239. package/dist/storage/budget.mjs +23 -1
  240. package/dist/storage/calls.d.mts +1 -1
  241. package/dist/storage/calls.mjs +41 -43
  242. package/dist/storage/charged-cache.mjs +180 -0
  243. package/dist/storage/chunks.d.mts +3 -3
  244. package/dist/storage/chunks.mjs +121 -8
  245. package/dist/storage/counted-bucket.mjs +32 -10
  246. package/dist/storage/fetch-row-cache.d.mts +6 -0
  247. package/dist/storage/fetch-row-cache.mjs +211 -0
  248. package/dist/storage/fetch.d.mts +1 -0
  249. package/dist/storage/fetch.mjs +54 -242
  250. package/dist/storage/held-types.d.mts +0 -1
  251. package/dist/storage/host-bucket.mjs +9 -4
  252. package/dist/storage/index-bitmaps.mjs +77 -49
  253. package/dist/storage/index-build.d.mts +2 -3
  254. package/dist/storage/index-build.mjs +248 -48
  255. package/dist/storage/index-fetch.d.mts +3 -1
  256. package/dist/storage/index-fetch.mjs +60 -21
  257. package/dist/storage/index-graph.mjs +1 -1
  258. package/dist/storage/index-layers.mjs +55 -25
  259. package/dist/storage/index-reach.mjs +15 -22
  260. package/dist/storage/index-whole.d.mts +7 -0
  261. package/dist/storage/index-whole.mjs +145 -37
  262. package/dist/storage/largest-files.mjs +1 -7
  263. package/dist/storage/layout.mjs +17 -1
  264. package/dist/storage/lfs-pointers.mjs +1 -6
  265. package/dist/storage/link-join.mjs +55 -16
  266. package/dist/storage/list-source.d.mts +7 -0
  267. package/dist/storage/list-source.mjs +288 -0
  268. package/dist/storage/loose.d.mts +8 -8
  269. package/dist/storage/loose.mjs +157 -91
  270. package/dist/storage/memory-budget.mjs +226 -22
  271. package/dist/storage/merge-cut.mjs +9 -6
  272. package/dist/storage/merge-fence.mjs +1 -1
  273. package/dist/storage/merge-row.mjs +1 -1
  274. package/dist/storage/merge.d.mts +2 -3
  275. package/dist/storage/merge.mjs +2 -2
  276. package/dist/storage/object-rows.d.mts +3 -3
  277. package/dist/storage/object-rows.mjs +179 -38
  278. package/dist/storage/pack-order.mjs +97 -44
  279. package/dist/storage/pack-ranges.mjs +44 -16
  280. package/dist/storage/pack-reads.d.mts +5 -3
  281. package/dist/storage/pack-reads.mjs +236 -72
  282. package/dist/storage/pack-receive.d.mts +1 -2
  283. package/dist/storage/pack-receive.mjs +21 -17
  284. package/dist/storage/packs.d.mts +1 -1
  285. package/dist/storage/packs.mjs +477 -116
  286. package/dist/storage/placed-reads.mjs +33 -16
  287. package/dist/storage/prune-seen.mjs +1 -1
  288. package/dist/storage/prune-walk.mjs +1 -1
  289. package/dist/storage/prune.mjs +4 -31
  290. package/dist/storage/push-allotment.mjs +26 -14
  291. package/dist/storage/push-uploads.mjs +195 -57
  292. package/dist/storage/pushed-commits.mjs +20 -1
  293. package/dist/storage/quarantine.d.mts +2 -3
  294. package/dist/storage/range-cache.mjs +175 -40
  295. package/dist/storage/raw-ids.mjs +39 -10
  296. package/dist/storage/ready.d.mts +2 -3
  297. package/dist/storage/ready.mjs +114 -38
  298. package/dist/storage/receive-bounds.mjs +31 -9
  299. package/dist/storage/receive-cache.d.mts +7 -0
  300. package/dist/storage/receive-cache.mjs +147 -0
  301. package/dist/storage/receive-files.mjs +1 -1
  302. package/dist/storage/receive-links.mjs +1 -1
  303. package/dist/storage/receive-state.d.mts +2 -2
  304. package/dist/storage/receive-state.mjs +6 -8
  305. package/dist/storage/receive-steps.d.mts +20 -0
  306. package/dist/storage/receive-steps.mjs +298 -13
  307. package/dist/storage/repack-backlog.mjs +1 -6
  308. package/dist/storage/repack-contained.mjs +2 -2
  309. package/dist/storage/repack-job.mjs +1 -1
  310. package/dist/storage/repack.d.mts +2 -3
  311. package/dist/storage/repack.mjs +54 -9
  312. package/dist/storage/request-cache.mjs +57 -0
  313. package/dist/storage/roots.mjs +1 -24
  314. package/dist/storage/rows.d.mts +2 -2
  315. package/dist/storage/rows.mjs +1 -1
  316. package/dist/storage/runs.d.mts +2 -2
  317. package/dist/storage/runs.mjs +1 -1
  318. package/dist/storage/send-list.mjs +62 -25
  319. package/dist/storage/stream-whole.mjs +84 -63
  320. package/dist/storage/swap-walk.mjs +1 -1
  321. package/dist/storage/unpack.mjs +878 -450
  322. package/dist/storage/visible.mjs +110 -32
  323. package/dist/storage/walk.mjs +1 -0
  324. package/dist/storage/wants.mjs +22 -58
  325. package/dist/store/call-count.d.mts +2 -2
  326. package/dist/store/call-count.mjs +24 -11
  327. package/dist/store/catalogue.d.mts +1 -1
  328. package/dist/store/catalogue.mjs +19 -7
  329. package/dist/store/crossing.mjs +1 -7
  330. package/dist/store/cursor-seal.d.mts +1 -1
  331. package/dist/store/cursor-seal.mjs +1 -1
  332. package/dist/store/door.mjs +9 -4
  333. package/dist/store/errors.d.mts +2 -2
  334. package/dist/store/errors.mjs +107 -19
  335. package/dist/store/git-store.mjs +7 -2
  336. package/dist/store/job-try.mjs +90 -9
  337. package/dist/store/list-job.mjs +10 -34
  338. package/dist/store/outbox.d.mts +2 -2
  339. package/dist/store/outbox.mjs +2 -2
  340. package/dist/store/queue-jobs.mjs +6 -12
  341. package/dist/store/records.d.mts +2 -2
  342. package/dist/store/records.mjs +2 -2
  343. package/dist/store/ref-rows.d.mts +2 -2
  344. package/dist/store/ref-rows.mjs +2 -2
  345. package/dist/store/repo-record.d.mts +2 -2
  346. package/dist/store/repo-record.mjs +3 -3
  347. package/dist/store/request-snapshot.mjs +5 -0
  348. package/dist/store/reservations.mjs +2 -2
  349. package/dist/store/topic-jobs.mjs +5 -11
  350. package/dist/sync/bound.d.mts +3 -3
  351. package/dist/sync/bound.mjs +10 -7
  352. package/dist/sync/github.mjs +65 -67
  353. package/dist/sync/http.mjs +1 -1
  354. package/dist/sync/import.mjs +201 -66
  355. package/dist/sync/layer.d.mts +1 -1
  356. package/dist/sync/layer.mjs +6 -6
  357. package/dist/sync/lfs-batch.mjs +1 -1
  358. package/dist/sync/lfs-copy.mjs +175 -15
  359. package/dist/sync/mirror.mjs +5 -10
  360. package/dist/sync/said.mjs +1 -1
  361. package/dist/sync/step.mjs +268 -86
  362. package/dist/sync/tries.mjs +25 -6
  363. package/dist/sync.d.mts +2 -2
  364. package/dist/sync.mjs +2 -2
  365. package/dist/topics/advance.mjs +3 -3
  366. package/dist/topics/calls.mjs +1 -1
  367. package/dist/topics/layer.d.mts +15 -14
  368. package/dist/topics/members.mjs +1 -1
  369. package/dist/topics/topic.mjs +1 -1
  370. package/package.json +3 -13
  371. package/dist/auth/helpers.mjs +0 -17
  372. package/dist/auth.d.mts +0 -5
  373. package/dist/auth.mjs +0 -5
  374. package/dist/core/rules/commit-changes.d.mts +0 -12
  375. package/dist/effect.d.mts +0 -9
  376. package/dist/effect.mjs +0 -7
  377. package/dist/server/joined.d.mts +0 -70
  378. package/dist/server/joined.mjs +0 -41
@@ -10,6 +10,7 @@ import { builtIndexOf, builtOver, coveredPacks, coversAll, decodeIndexValue } fr
10
10
  import { openBases, openTypes, typeOfCode } from "./index-files.mjs";
11
11
  import { indexShallow, numberIn, numbersIn } from "./index-shallow.mjs";
12
12
  import { oidTable } from "./oid-table.mjs";
13
+ import { listCalls, listSource } from "./list-source.mjs";
13
14
  import { listOf } from "./send-list.mjs";
14
15
  import { ByGeneration, graphChunk, graphRows, keptIdsBytes, openGraphLayers, openIndexGraph } from "./index-graph.mjs";
15
16
  import { openLayerBitmaps, openLayout, orWords } from "./index-layers.mjs";
@@ -131,16 +132,41 @@ const regionBytes = (layers) => {
131
132
  const heldIndex = /* @__PURE__ */ Effect.fnUntraced(function* (source, row, covered, ahead, read) {
132
133
  const most = source.wholeMost ?? 1048576;
133
134
  const packs = source.listed.packs.filter(({ id }) => covered.has(id));
134
- const files = indexFilesOf(source.listed.repo, row.layers, packs);
135
+ const files = indexFilesOf(source.listed.repo, row.layers, packs, read.cachedIndex);
135
136
  if (files === void 0 || files.reduce((sum, file) => sum + file.least, 0) > most) return void 0;
137
+ const { indexes } = source;
138
+ const cached = /* @__PURE__ */ new Map();
139
+ let cachedBytes = 0;
140
+ const misses = [];
141
+ for (const file of files) {
142
+ const kept = indexes !== void 0 && file.immutable === true && file.range === void 0 ? indexes.peekFile(source.bucket, file.key) : void 0;
143
+ if (kept !== void 0) {
144
+ cached.set(file.key, kept);
145
+ cachedBytes += kept.byteLength;
146
+ } else misses.push(file);
147
+ }
148
+ if (cachedBytes + misses.reduce((sum, file) => sum + file.least, 0) > most) return void 0;
149
+ if (misses.length === 0) {
150
+ if (cachedBytes > 0) yield* read.hold(cachedBytes);
151
+ return {
152
+ bucket: heldFiles(source.bucket, cached),
153
+ heldRevs: /* @__PURE__ */ new Set()
154
+ };
155
+ }
136
156
  yield* ahead({
137
- bucket: files.length,
157
+ bucket: misses.length,
138
158
  store: 0
139
159
  });
140
160
  yield* read.hold(most);
141
- const whole = yield* wholeFiles(source.bucket, files, most);
142
- yield* read.release(most - (whole?.bytes ?? 0));
143
- return whole === void 0 ? void 0 : heldFiles(source.bucket, whole.files);
161
+ const whole = yield* wholeFiles(source.bucket, misses, most - cachedBytes, indexes);
162
+ yield* read.release(whole === void 0 ? most : most - (cachedBytes + whole.bytes));
163
+ if (whole === void 0) return void 0;
164
+ for (const [key, bytes] of cached) whole.files.set(key, bytes);
165
+ const heldRevs = new Set([...whole.files.keys()].filter((key) => key.endsWith(".rev")));
166
+ return {
167
+ bucket: heldFiles(source.bucket, whole.files, whole.ranges, whole.missing),
168
+ heldRevs
169
+ };
144
170
  });
145
171
  /**
146
172
  * The repo's index, opened: its row read through the request's store, 1 call, then its layers'
@@ -151,20 +177,24 @@ const heldIndex = /* @__PURE__ */ Effect.fnUntraced(function* (source, row, cove
151
177
  const openFetchIndex = /* @__PURE__ */ Effect.fnUntraced(function* (source, ahead, read) {
152
178
  const { hold } = read;
153
179
  const { store, listed } = source;
154
- yield* ahead({
155
- bucket: 0,
156
- store: 1
157
- });
158
- const snapshot = yield* store.read({
159
- scope: repoScope(listed.repo),
160
- reads: [indexRowKey]
161
- });
162
- const row = builtIndexOf(decodeIndexValue(snapshot.results[0]?.[0]?.value));
180
+ let stored;
181
+ if (source.indexRow !== void 0) stored = source.indexRow.row;
182
+ else {
183
+ yield* ahead({
184
+ bucket: 0,
185
+ store: 1
186
+ });
187
+ stored = (yield* store.read({
188
+ scope: repoScope(listed.repo),
189
+ reads: [indexRowKey]
190
+ })).results[0]?.[0];
191
+ }
192
+ const row = builtIndexOf(decodeIndexValue(stored?.value));
163
193
  if (row === void 0 || !builtOver(row, read.roots) || !coversAll(row.layers, listed)) return void 0;
164
194
  if (source.opened !== void 0) source.opened.opened = true;
165
195
  const covered = coveredPacks(row.layers);
166
196
  const held = yield* heldIndex(source, row, covered, ahead, read);
167
- const bucket = held ?? source.bucket;
197
+ const bucket = held?.bucket ?? source.bucket;
168
198
  yield* ahead(held === void 0 ? fetchOpenCalls(row.layers) : noCalls);
169
199
  yield* hold(regionBytes(row.layers));
170
200
  yield* hold(openedBitmapBytes * row.layers.reduce((sum, layer) => sum + layer.bitmaps, 0));
@@ -216,7 +246,8 @@ const openFetchIndex = /* @__PURE__ */ Effect.fnUntraced(function* (source, ahea
216
246
  letRangesGo,
217
247
  bucket,
218
248
  bases,
219
- held: held !== void 0
249
+ held: held !== void 0,
250
+ heldRevs: held?.heldRevs ?? /* @__PURE__ */ new Set()
220
251
  };
221
252
  });
222
253
  /**
@@ -264,7 +295,9 @@ const indexSendSet = (input) => indexSendSetOrNot(input).pipe(Effect.catchTag("U
264
295
  /** The index path over `source`. */
265
296
  const indexPath = (source) => ({
266
297
  source,
267
- send: indexSendSet
298
+ send: indexSendSet,
299
+ calls: listCalls,
300
+ sourceOf: listSource
268
301
  });
269
302
  const indexSendSetOrNot = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
270
303
  const { source, read, request, ahead } = input;
@@ -285,7 +318,8 @@ const indexSendSetOrNot = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
285
318
  heldAt,
286
319
  outside,
287
320
  ahead,
288
- bases: index.bases
321
+ bases: index.bases,
322
+ indexHeld: index.held
289
323
  });
290
324
  /** `placed`'s objects read at their positions, and `beside`'s, which the index doesn't place, past it. */
291
325
  const readSplit = Effect.fnUntraced(function* (placed, beside, newLevel = true) {
@@ -710,9 +744,14 @@ const indexSendSetOrNot = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
710
744
  }
711
745
  const rootsSent = /* @__PURE__ */ new Set();
712
746
  const rootsAt = row.layers.flatMap((layer) => (layer.roots ?? []).filter((position) => isSet(send, position)));
713
- const packed = rootsAt.filter((position) => layout.ranges.some((pack) => position >= pack.base && position < pack.base + pack.count));
714
- if (packed.length > 0) yield* ahead({
715
- bucket: index.held ? packed.length : 2 * packed.length,
747
+ const rootGets = rootsAt.reduce((sum, position) => {
748
+ const pack = layout.ranges.find((each) => position >= each.base && position < each.base + each.count);
749
+ if (pack === void 0) return sum;
750
+ if (!index.held) return sum + 2;
751
+ return sum + (index.heldRevs.has(packFiles(pack.pack.id).rev) ? 0 : 1);
752
+ }, 0);
753
+ if (rootGets > 0) yield* ahead({
754
+ bucket: rootGets,
716
755
  store: 0
717
756
  });
718
757
  for (const position of rootsAt) {
@@ -11,9 +11,9 @@ import { startPut } from "./merge.mjs";
11
11
  import { keepUnclosed } from "./index-bitmaps.mjs";
12
12
  import { readExactly } from "./pack-ranges.mjs";
13
13
  import { compareIds, idsBytes, orderById } from "./raw-ids.mjs";
14
+ import { limits } from "@ref0/infra";
14
15
  import * as Effect from "effect/Effect";
15
16
  import * as Result from "effect/Result";
16
- import { limits } from "@ref0/infra";
17
17
  // src/storage/index-graph.ts
18
18
  /**
19
19
  * The reachability index's commit graph, `index/<repo>/<build>.graph`: every commit the repo's packs
@@ -1,5 +1,6 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
2
  import { hexOf } from "../protocol/bytes/hex.mjs";
3
+ import { boundedBytes, dropBody } from "../protocol/bytes/reader.mjs";
3
4
  import { rawLinks } from "../protocol/objects/links-raw.mjs";
4
5
  import { isTreeMode } from "../protocol/objects/object.mjs";
5
6
  import { parseTreeBytes } from "../protocol/objects/tree.mjs";
@@ -14,9 +15,9 @@ import { readWhole } from "./calls.mjs";
14
15
  import { compareIds } from "./raw-ids.mjs";
15
16
  import { levelTooLarge } from "./wants.mjs";
16
17
  import { tryUnlessSpent } from "../contracts/calls-spent.mjs";
18
+ import { limits } from "@ref0/infra";
17
19
  import * as Effect from "effect/Effect";
18
20
  import * as Exit from "effect/Exit";
19
- import { limits } from "@ref0/infra";
20
21
  import * as Deferred from "effect/Deferred";
21
22
  // src/storage/index-layers.ts
22
23
  /**
@@ -97,42 +98,62 @@ const revHeaderBytes = 12;
97
98
  */
98
99
  const openLayout = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, listed, spans, indexed, options = {}) {
99
100
  const byId = new Map(listed.packs.map((pack) => [pack.id, pack]));
100
- const ranges = [];
101
- const heldNow = [];
102
- const runs = [];
101
+ const regionTasks = [];
102
+ const packTasks = [];
103
103
  let position = 0;
104
104
  for (const span of spans) {
105
105
  if (span.first !== position) return yield* Effect.fail(lost(`The index's layer ${span.build} starts at ${span.first}, not ${position}`));
106
106
  const rows = span.groups.reduce((sum, group) => sum + group.rows, 0);
107
107
  const key = indexFiles(listed.repo, span.build).region;
108
- const ids = rows === 0 ? /* @__PURE__ */ new Uint8Array(0) : yield* readWhole(bucket, key);
109
- if (ids?.byteLength !== rows * 20) return yield* Effect.fail(lost(`${key} doesn't hold its layer's ${rows} rows`));
108
+ const groups = [];
110
109
  let row = 0;
111
110
  for (const group of span.groups) {
112
111
  for (const id of group.packs) {
113
112
  const pack = byId.get(id);
114
113
  if (pack === void 0) return yield* Effect.fail(lost(`The index's pack ${id} isn't listed`));
115
- if (indexed !== void 0) ranges.push(yield* indexedRanges(bucket, yield* indexed(pack), pack.objects, position));
116
- else {
117
- const opened = yield* openRanges(bucket, yield* storedOf(pack), pack.objects, position);
118
- const { loadedOf } = options;
119
- if (loadedOf === void 0) ranges.push(opened);
120
- else {
121
- ranges.push(heldOrRanges(opened, () => loadedOf(pack)?.index));
122
- heldNow.push(() => loadedOf(pack) !== void 0);
123
- }
124
- }
114
+ packTasks.push({
115
+ pack,
116
+ stored: yield* storedOf(pack),
117
+ position
118
+ });
125
119
  position += pack.objects;
126
120
  }
127
121
  if (group.rows > 0) {
128
- runs.push({
122
+ groups.push({
129
123
  first: position,
130
- ids: ids.subarray(row * 20, (row + group.rows) * 20)
124
+ row,
125
+ rows: group.rows
131
126
  });
132
127
  row += group.rows;
133
128
  position += group.rows;
134
129
  }
135
130
  }
131
+ if (rows > 0) regionTasks.push({
132
+ key,
133
+ rows,
134
+ groups
135
+ });
136
+ }
137
+ const packsAtOnce = Math.max(1, Math.floor(8));
138
+ const { loadedOf } = options;
139
+ const [regionIds, openedPacks] = yield* Effect.all([Effect.forEach(regionTasks, Effect.fnUntraced(function* ({ key, rows }) {
140
+ const ids = yield* readWhole(bucket, key);
141
+ if (ids?.byteLength !== rows * 20) return yield* Effect.fail(lost(`${key} doesn't hold its layer's ${rows} rows`));
142
+ return ids;
143
+ }), { concurrency: 16 }), Effect.forEach(packTasks, Effect.fnUntraced(function* ({ pack, stored, position: base }) {
144
+ if (indexed !== void 0) return yield* indexedRanges(bucket, yield* indexed(pack), pack.objects, base);
145
+ const opened = yield* openRanges(bucket, stored, pack.objects, base);
146
+ return loadedOf === void 0 ? opened : heldOrRanges(opened, () => loadedOf(pack)?.index);
147
+ }), { concurrency: packsAtOnce })], { concurrency: "unbounded" });
148
+ const ranges = openedPacks;
149
+ const heldNow = indexed === void 0 && loadedOf !== void 0 ? packTasks.map(({ pack }) => () => loadedOf(pack) !== void 0) : [];
150
+ const runs = [];
151
+ for (const [at, task] of regionTasks.entries()) {
152
+ const ids = regionIds[at];
153
+ for (const group of task.groups) runs.push({
154
+ first: group.first,
155
+ ids: ids.subarray(group.row * 20, (group.row + group.rows) * 20)
156
+ });
136
157
  }
137
158
  const total = position;
138
159
  const idAt = Effect.fnUntraced(function* (at) {
@@ -165,7 +186,7 @@ const layoutOver = (ranges, runs, idAt, loaded, { cached = false, allotment, too
165
186
  const total = ranges.reduce((sum, pack) => sum + pack.count, 0) + runs.reduce((sum, run) => sum + run.ids.length / 20, 0);
166
187
  const searched = Effect.fnUntraced(function* (ids, count) {
167
188
  const out = new Uint32Array(count).fill(missing);
168
- for (let at = 0; at < count; at += 1) {
189
+ const searchOne = Effect.fnUntraced(function* (at) {
169
190
  const id = ids.subarray(at * 20, at * 20 + 20);
170
191
  for (const pack of ranges) {
171
192
  const rank = yield* rankOf(pack, id);
@@ -174,7 +195,12 @@ const layoutOver = (ranges, runs, idAt, loaded, { cached = false, allotment, too
174
195
  break;
175
196
  }
176
197
  out[at] = Math.min(out[at] ?? 4294967295, regionPosition(region, id));
177
- }
198
+ });
199
+ if (count === 1) yield* searchOne(0);
200
+ else if (count > 1) yield* Effect.forEach(Array.from({ length: count }, (_, at) => at), searchOne, {
201
+ concurrency: 16,
202
+ discard: true
203
+ });
178
204
  return out;
179
205
  });
180
206
  const charged = (count, join) => {
@@ -347,10 +373,14 @@ const orWords = (from, into) => {
347
373
  const length = Math.min(from.length, into.length);
348
374
  for (let at = 0; at < length; at += 1) into[at] = ((into[at] ?? 0) | (from[at] ?? 0)) >>> 0;
349
375
  };
350
- const bytesOf = (object) => tryUnlessSpent(async () => new Uint8Array(await new Response(object.bytes).arrayBuffer()), (cause) => gitError("UNAVAILABLE", `Object ${object.oid} couldn't be read`, {
351
- cause,
352
- hint: "Try again"
353
- }));
376
+ const bytesOf = /* @__PURE__ */ Effect.fnUntraced(function* (object) {
377
+ const bytes = yield* boundedBytes(object.bytes, object.size, (reader) => tryUnlessSpent(() => reader.read(), (cause) => gitError("UNAVAILABLE", `Object ${object.oid} couldn't be read`, {
378
+ cause,
379
+ hint: "Try again"
380
+ })));
381
+ if (bytes === void 0) return yield* Effect.fail(lost(`The ${object.type} ${object.oid} is unreadable: it has more than its ${object.size} bytes`));
382
+ return bytes;
383
+ });
354
384
  /** A gitlink names a commit of another repo, no object of this one. */
355
385
  const gitlinkMode = "160000";
356
386
  /** What a walk holds for each link a read object's parse makes: its ID, entry and join's place. */
@@ -436,7 +466,7 @@ const reachOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, starts, carr
436
466
  for (const object of objects) {
437
467
  if (object === void 0) return false;
438
468
  if (object.type === "blob") {
439
- yield* Effect.promise(() => object.bytes.cancel());
469
+ yield* dropBody(object.bytes);
440
470
  continue;
441
471
  }
442
472
  const bytes = yield* bytesOf(object);
@@ -4,6 +4,7 @@ import { builtIndexOf, builtOver, coversAll, decodeIndexValue } from "./index-bu
4
4
  import { hasBit, idsOf, openLayerBitmaps, openLayout, orIntoAtOnce, orIntoBytes, orIntoFiles, orWords, reachOf, whileFollowed } from "./index-layers.mjs";
5
5
  import { readReserveBytes } from "./budget.mjs";
6
6
  import { missing } from "./link-join.mjs";
7
+ import { chargedCache } from "./charged-cache.mjs";
7
8
  import { readBusy } from "./memory-budget.mjs";
8
9
  import { indexBytes } from "./pack-reads.mjs";
9
10
  import { levelTooLarge, onward, stepsOf } from "./wants.mjs";
@@ -36,33 +37,25 @@ const positionsIn = (bits) => {
36
37
  };
37
38
  /** The most bytes of walked reaches an instance keeps. */
38
39
  const reachCacheBytes = 8388608;
39
- /** The reaches a read walked for tips with no stored bitmap, by build and position, least lately used gone first. */
40
+ /**
41
+ * The reaches a read walked for tips with no stored bitmap, by build and position, least lately
42
+ * used gone first, charged to a per-instance `MemoryBudget` room (`instanceRoomOf(...)`).
43
+ */
40
44
  var ReachCache = class {
41
- #kept = /* @__PURE__ */ new Map();
42
- #most;
43
- #bytes = 0;
44
- constructor(most = reachCacheBytes) {
45
- this.#most = most;
45
+ #kept;
46
+ constructor(charge, most = reachCacheBytes) {
47
+ this.#kept = chargedCache(charge, {
48
+ maxBytes: most,
49
+ entryOverhead: 96,
50
+ weight: (bits) => bits.byteLength,
51
+ evict: "lru"
52
+ });
46
53
  }
47
54
  get(key) {
48
- const found = this.#kept.get(key);
49
- if (found === void 0) return void 0;
50
- this.#kept.delete(key);
51
- this.#kept.set(key, found);
52
- return found;
55
+ return this.#kept.get(key);
53
56
  }
54
57
  set(key, bits) {
55
- if (bits.byteLength > this.#most) return;
56
- const old = this.#kept.get(key);
57
- if (old !== void 0) this.#bytes -= old.byteLength;
58
- this.#kept.delete(key);
59
- this.#kept.set(key, bits);
60
- this.#bytes += bits.byteLength;
61
- for (const [first, kept] of this.#kept) {
62
- if (this.#bytes <= this.#most) break;
63
- this.#kept.delete(first);
64
- this.#bytes -= kept.byteLength;
65
- }
58
+ return this.#kept.set(key, bits);
66
59
  }
67
60
  };
68
61
  /** What a reach's union may hold beside it while `orInto` reads ranges into it: a quarter of a read's reserve. */
@@ -0,0 +1,7 @@
1
+ import "../contracts/objects.mjs";
2
+ import "../contracts/result.mjs";
3
+ import "../contracts/store.mjs";
4
+ import "../contracts/ids.mjs";
5
+ import "./index-build.mjs";
6
+ import "@ref0/infra";
7
+ import "effect/Effect";
@@ -1,10 +1,13 @@
1
1
  import { packIndexBytes } from "../protocol/packs/idx.mjs";
2
2
  import { packPositionsBytes } from "../protocol/packs/pos.mjs";
3
+ import { packReverseBytes } from "../protocol/packs/rev.mjs";
3
4
  import { bodyOfBytes, bucketDo, readEach } from "./calls.mjs";
4
5
  import { indexBasesBytes, indexTypesBytes } from "./index-files.mjs";
5
6
  import { indexGraphBytes } from "./index-graph.mjs";
6
7
  import { indexFiles, isPackId, packFiles } from "./layout.mjs";
8
+ import { NotFound } from "@ref0/infra";
7
9
  import * as Effect from "effect/Effect";
10
+ import * as Predicate from "effect/Predicate";
8
11
  // src/storage/index-whole.ts
9
12
  /**
10
13
  * The most a fetch reads of a small index's files whole, all at once, before its walk: 1 MiB, the
@@ -12,21 +15,19 @@ import * as Effect from "effect/Effect";
12
15
  * for a small fetch, at about 70 ms a get on R2. Past it, they're read by range as before.
13
16
  */
14
17
  const wholeIndexMost = 1048576;
15
- /**
16
- * The files read at once, as the bitmaps' reads are: a small index's 6 in one round, and one over
17
- * many packs in rounds of 16, never one get a file all open together.
18
- */
19
- const filesAtOnce = 16;
20
18
  /** The packs whose `.idx` holds no 8-byte offsets: under 2 GiB. */
21
19
  const smallPackBytes = 2 ** 31;
20
+ /** A pack's 20-byte SHA-1 trailer, read beside its `.idx` and `.rev` on a cold open. */
21
+ const packTrailerBytes = 20;
22
22
  /**
23
23
  * The files a fetch's walk and send list read of an index of `layers` over `packs`: each layer's
24
24
  * `.graph`, `.bitmaps` when it has any, `.types` and `.bases` when it has deltas, and each pack's
25
- * `.idx` and `.pos`, with the least each can be from the row and the listing, no call made: a
26
- * graph's octopus rows aren't in the row, so its least counts none. An index with a region's rows
27
- * or a pack past 2 GiB is none of these: `undefined`, so it's read by range.
25
+ * `.idx` and `.pos` — plus its `.rev` and 20-byte `.pack` trailer when `cached` says the server's
26
+ * index cache doesn't hold the pack yet — with the least each can be from the row and the listing,
27
+ * no call made: a graph's octopus rows aren't in the row, so its least counts none. An index with
28
+ * a region's rows or a pack past 2 GiB is none of these: `undefined`, so it's read by range.
28
29
  */
29
- const indexFilesOf = (repo, layers, packs) => {
30
+ const indexFilesOf = (repo, layers, packs, cached) => {
30
31
  const files = [];
31
32
  for (const layer of layers) {
32
33
  if (layer.groups.some((group) => group.rows > 0)) return void 0;
@@ -34,19 +35,23 @@ const indexFilesOf = (repo, layers, packs) => {
34
35
  const positions = layer.first + layer.positions;
35
36
  files.push({
36
37
  key: at.graph,
37
- least: indexGraphBytes(layer.commits, 0)
38
+ least: indexGraphBytes(layer.commits, 0),
39
+ immutable: true
38
40
  });
39
41
  files.push({
40
42
  key: at.types,
41
- least: indexTypesBytes(layer.positions)
43
+ least: indexTypesBytes(layer.positions),
44
+ immutable: true
42
45
  });
43
46
  if (layer.bitmaps > 0) files.push({
44
47
  key: at.bitmaps,
45
- least: layer.table + layer.bitmaps * 20 + 20
48
+ least: layer.table + layer.bitmaps * 20 + 20,
49
+ immutable: true
46
50
  });
47
51
  if (layer.deltas > 0) files.push({
48
52
  key: at.bases,
49
- least: indexBasesBytes(positions, layer.deltas)
53
+ least: indexBasesBytes(positions, layer.deltas),
54
+ immutable: true
50
55
  });
51
56
  }
52
57
  for (const pack of packs) {
@@ -54,12 +59,30 @@ const indexFilesOf = (repo, layers, packs) => {
54
59
  const at = packFiles(pack.id);
55
60
  files.push({
56
61
  key: at.idx,
57
- least: packIndexBytes(pack.objects, 0)
62
+ least: packIndexBytes(pack.objects, 0),
63
+ immutable: true
58
64
  });
59
65
  files.push({
60
66
  key: at.pos,
61
- least: packPositionsBytes(pack.objects)
67
+ least: packPositionsBytes(pack.objects),
68
+ immutable: true
62
69
  });
70
+ if (cached?.(pack) !== true) {
71
+ files.push({
72
+ key: at.rev,
73
+ least: packReverseBytes(pack.objects),
74
+ deferNotFound: true
75
+ });
76
+ if (pack.bytes >= packTrailerBytes) files.push({
77
+ key: at.pack,
78
+ range: {
79
+ offset: pack.bytes - packTrailerBytes,
80
+ length: packTrailerBytes
81
+ },
82
+ least: packTrailerBytes,
83
+ deferNotFound: true
84
+ });
85
+ }
63
86
  }
64
87
  return files;
65
88
  };
@@ -68,16 +91,17 @@ var PastBound = class {
68
91
  _tag = "PastBound";
69
92
  };
70
93
  /**
71
- * Each of `files` read whole, `filesAtOnce` at a time, their buffers together at most `most`:
72
- * `undefined` when they pass it, so the caller reads by range, as before. Each file's chunks are
73
- * copied as they come into one buffer, the file's least to start, charged before it's made, so
74
- * no chunk is kept and nothing live goes uncharged: one too small for a chunk is made again, at
75
- * twice its size or the chunk's need, both charged while the copy runs, and the old one given
76
- * back after. An empty chunk is skipped. A read's failure is the fetch's, as one by range is.
94
+ * Each of `files` read whole (or by its `range`), `fetchReadsAtOnce` at a time, their buffers
95
+ * together at most `most`: `undefined` when they pass it, so the caller reads by range, as before.
96
+ * Each file's chunks are copied as they come into one buffer, the file's least to start, charged
97
+ * before it's made, so no chunk is kept and nothing live goes uncharged: one too small for a chunk
98
+ * is made again, at twice its size or the chunk's need, both charged while the copy runs, and the
99
+ * old one given back after. An empty chunk is skipped. A read's failure is the fetch's, as one by
100
+ * range is.
77
101
  */
78
- const wholeFiles = (bucket, files, most) => Effect.suspend(() => {
102
+ const wholeFiles = (bucket, files, most, cache) => Effect.suspend(() => {
79
103
  let left = most;
80
- const read = (file) => Effect.suspend(() => {
104
+ const readDirect = (file) => Effect.suspend(() => {
81
105
  let held = /* @__PURE__ */ new Uint8Array(0);
82
106
  let length = 0;
83
107
  /** `held` made again with room for `need`, charged first: false past the bound. */
@@ -98,30 +122,114 @@ const wholeFiles = (bucket, files, most) => Effect.suspend(() => {
98
122
  length += chunk.byteLength;
99
123
  return Effect.void;
100
124
  };
101
- if (!grow(file.least)) return Effect.succeed(void 0);
102
- return bucketDo(readEach(bucket, file.key, void 0, take).pipe(Effect.map(() => [file.key, held.subarray(0, length)]), Effect.catchTag("PastBound", () => Effect.succeed(void 0))));
125
+ const available = left;
126
+ if (!grow(file.least)) return Effect.succeed({
127
+ kind: "past",
128
+ limit: available
129
+ });
130
+ return bucketDo(readEach(bucket, file.key, file.range, take).pipe(Effect.map(() => ({
131
+ kind: "file",
132
+ bytes: held.subarray(0, length),
133
+ charged: held.byteLength
134
+ })), Effect.catchTag("PastBound", () => {
135
+ const limit = held.byteLength + left;
136
+ left += held.byteLength;
137
+ held = /* @__PURE__ */ new Uint8Array(0);
138
+ return Effect.succeed({
139
+ kind: "past",
140
+ limit
141
+ });
142
+ }), Effect.catchIf((error) => file.deferNotFound === true && Predicate.isTagged(error, "NotFound"), () => {
143
+ left += held.byteLength;
144
+ held = /* @__PURE__ */ new Uint8Array(0);
145
+ return Effect.succeed({ kind: "missing" });
146
+ })));
103
147
  });
104
- return Effect.map(Effect.forEach(files, read, { concurrency: filesAtOnce }), (read) => {
105
- const held = read.filter((file) => file !== void 0);
106
- return held.length === files.length ? {
107
- files: new Map(held),
148
+ const read = (file) => Effect.suspend(() => {
149
+ if (cache === void 0) return Effect.map(readDirect(file), (result) => {
150
+ if (result.kind === "past") return void 0;
151
+ if (result.kind === "missing") return {
152
+ file,
153
+ bytes: /* @__PURE__ */ new Uint8Array(0),
154
+ missing: true
155
+ };
156
+ return {
157
+ file,
158
+ bytes: result.bytes,
159
+ missing: false
160
+ };
161
+ });
162
+ let ranDirect = false;
163
+ const runDirect = () => {
164
+ ranDirect = true;
165
+ return readDirect(file);
166
+ };
167
+ return Effect.map(cache.readFile(bucket, file, runDirect, () => left), (result) => {
168
+ if (result.kind === "past") return void 0;
169
+ if (result.kind === "missing") return {
170
+ file,
171
+ bytes: /* @__PURE__ */ new Uint8Array(0),
172
+ missing: true
173
+ };
174
+ if (!ranDirect) {
175
+ const need = result.bytes.byteLength;
176
+ if (need > left) return void 0;
177
+ left -= need;
178
+ }
179
+ return {
180
+ file,
181
+ bytes: result.bytes,
182
+ missing: false
183
+ };
184
+ });
185
+ });
186
+ return Effect.map(Effect.forEach(files, read, { concurrency: 16 }), (read) => {
187
+ const held = read.filter((entry) => entry !== void 0);
188
+ if (held.length !== files.length) return void 0;
189
+ const whole = /* @__PURE__ */ new Map();
190
+ const ranges = /* @__PURE__ */ new Map();
191
+ const missing = /* @__PURE__ */ new Set();
192
+ for (const { file, bytes, missing: isMissing } of held) if (isMissing) missing.add(file.key);
193
+ else if (file.range === void 0) whole.set(file.key, bytes);
194
+ else ranges.set(file.key, {
195
+ range: file.range,
196
+ bytes
197
+ });
198
+ return {
199
+ files: whole,
200
+ ranges,
201
+ missing,
108
202
  bytes: most - left
109
- } : void 0;
203
+ };
110
204
  });
111
205
  });
112
206
  /**
113
207
  * `bucket`, each of `files` read from the bytes held, with no call: a range as the bucket answers
114
- * it, cut at the file's end, and the whole file without one. Every other key reads through.
208
+ * it, cut at the file's end, and the whole file without one. A ranged entry in `ranges` serves
209
+ * reads falling inside its held range (such as a pack's 20-byte trailer), while any other range
210
+ * on that key reads through to `bucket`. A key in `missing` fails with `NotFound` with no call.
211
+ * Every other key reads through.
115
212
  */
116
- const heldFiles = (bucket, files) => ({
213
+ const heldFiles = (bucket, files, ranges, missing) => ({
117
214
  ...bucket,
118
215
  read: (key, range) => {
216
+ if (missing?.has(key) === true) return Effect.fail(new NotFound({ message: key }));
119
217
  const whole = files.get(key);
120
- if (whole === void 0) return bucket.read(key, range);
121
- if (range === void 0) return bodyOfBytes(whole);
122
- const from = Math.min(range.offset, whole.byteLength);
123
- const to = Math.max(from, Math.min(range.offset + range.length, whole.byteLength));
124
- return bodyOfBytes(whole.subarray(from, to));
218
+ if (whole !== void 0) {
219
+ if (range === void 0) return bodyOfBytes(whole);
220
+ const from = Math.min(range.offset, whole.byteLength);
221
+ const to = Math.max(from, Math.min(range.offset + range.length, whole.byteLength));
222
+ return bodyOfBytes(whole.subarray(from, to));
223
+ }
224
+ if (range !== void 0) {
225
+ const held = ranges?.get(key);
226
+ if (held !== void 0 && range.offset >= held.range.offset && range.offset + range.length <= held.range.offset + held.range.length) {
227
+ const from = Math.min(range.offset - held.range.offset, held.bytes.byteLength);
228
+ const to = Math.max(from, Math.min(from + range.length, held.bytes.byteLength));
229
+ return bodyOfBytes(held.bytes.subarray(from, to));
230
+ }
231
+ }
232
+ return bucket.read(key, range);
125
233
  }
126
234
  });
127
235
  export { heldFiles, indexFilesOf, wholeFiles, wholeIndexMost };
@@ -39,10 +39,4 @@ var LargestFiles = class {
39
39
  } : { largest };
40
40
  }
41
41
  };
42
- /** The largest of `objects`' blobs, as `LargestFiles` keeps them: a receive kept as rows. */
43
- const largestOf = (objects) => {
44
- const largest = new LargestFiles();
45
- for (const object of objects) if (object.type === "blob") largest.add(object.oid, "size" in object ? object.size : object.bytes.byteLength);
46
- return largest.finish();
47
- };
48
- export { LargestFiles, largestOf };
42
+ export { LargestFiles };