@ref0/git 0.20.0 → 0.26.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 (379) 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 +30 -18
  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 +13 -12
  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 +145 -98
  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 +114 -58
  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/held-types.mjs +13 -4
  252. package/dist/storage/host-bucket.mjs +9 -4
  253. package/dist/storage/index-bitmaps.mjs +340 -65
  254. package/dist/storage/index-build.d.mts +2 -3
  255. package/dist/storage/index-build.mjs +274 -56
  256. package/dist/storage/index-fetch.d.mts +3 -1
  257. package/dist/storage/index-fetch.mjs +60 -21
  258. package/dist/storage/index-graph.mjs +1 -1
  259. package/dist/storage/index-layers.mjs +55 -25
  260. package/dist/storage/index-reach.mjs +15 -22
  261. package/dist/storage/index-whole.d.mts +7 -0
  262. package/dist/storage/index-whole.mjs +145 -37
  263. package/dist/storage/largest-files.mjs +1 -7
  264. package/dist/storage/layout.mjs +17 -1
  265. package/dist/storage/lfs-pointers.mjs +1 -6
  266. package/dist/storage/link-join.mjs +55 -16
  267. package/dist/storage/list-source.d.mts +7 -0
  268. package/dist/storage/list-source.mjs +288 -0
  269. package/dist/storage/loose.d.mts +8 -8
  270. package/dist/storage/loose.mjs +157 -91
  271. package/dist/storage/memory-budget.mjs +226 -22
  272. package/dist/storage/merge-cut.mjs +9 -6
  273. package/dist/storage/merge-fence.mjs +1 -1
  274. package/dist/storage/merge-row.mjs +1 -1
  275. package/dist/storage/merge.d.mts +2 -3
  276. package/dist/storage/merge.mjs +2 -2
  277. package/dist/storage/object-rows.d.mts +3 -3
  278. package/dist/storage/object-rows.mjs +179 -38
  279. package/dist/storage/pack-order.mjs +97 -44
  280. package/dist/storage/pack-ranges.mjs +44 -16
  281. package/dist/storage/pack-reads.d.mts +5 -3
  282. package/dist/storage/pack-reads.mjs +236 -72
  283. package/dist/storage/pack-receive.d.mts +1 -2
  284. package/dist/storage/pack-receive.mjs +24 -18
  285. package/dist/storage/packs.d.mts +1 -1
  286. package/dist/storage/packs.mjs +477 -116
  287. package/dist/storage/placed-reads.mjs +33 -16
  288. package/dist/storage/prune-seen.mjs +1 -1
  289. package/dist/storage/prune-walk.mjs +1 -1
  290. package/dist/storage/prune.mjs +4 -31
  291. package/dist/storage/push-allotment.mjs +26 -14
  292. package/dist/storage/push-uploads.mjs +195 -57
  293. package/dist/storage/pushed-commits.mjs +20 -1
  294. package/dist/storage/quarantine.d.mts +2 -3
  295. package/dist/storage/range-cache.mjs +175 -40
  296. package/dist/storage/raw-ids.mjs +39 -10
  297. package/dist/storage/ready.d.mts +2 -3
  298. package/dist/storage/ready.mjs +114 -38
  299. package/dist/storage/receive-bounds.mjs +31 -9
  300. package/dist/storage/receive-cache.d.mts +7 -0
  301. package/dist/storage/receive-cache.mjs +147 -0
  302. package/dist/storage/receive-files.mjs +1 -1
  303. package/dist/storage/receive-links.mjs +1 -1
  304. package/dist/storage/receive-state.d.mts +2 -2
  305. package/dist/storage/receive-state.mjs +6 -8
  306. package/dist/storage/receive-steps.d.mts +20 -0
  307. package/dist/storage/receive-steps.mjs +298 -13
  308. package/dist/storage/repack-backlog.mjs +1 -6
  309. package/dist/storage/repack-contained.mjs +2 -2
  310. package/dist/storage/repack-job.mjs +1 -1
  311. package/dist/storage/repack.d.mts +2 -3
  312. package/dist/storage/repack.mjs +54 -9
  313. package/dist/storage/request-cache.mjs +57 -0
  314. package/dist/storage/roots.mjs +1 -24
  315. package/dist/storage/rows.d.mts +2 -2
  316. package/dist/storage/rows.mjs +1 -1
  317. package/dist/storage/runs.d.mts +2 -2
  318. package/dist/storage/runs.mjs +1 -1
  319. package/dist/storage/send-list.mjs +62 -25
  320. package/dist/storage/stream-whole.mjs +84 -63
  321. package/dist/storage/swap-walk.mjs +1 -1
  322. package/dist/storage/unpack.mjs +878 -450
  323. package/dist/storage/visible.mjs +110 -32
  324. package/dist/storage/walk.mjs +1 -0
  325. package/dist/storage/wants.mjs +22 -58
  326. package/dist/store/call-count.d.mts +2 -2
  327. package/dist/store/call-count.mjs +24 -11
  328. package/dist/store/catalogue.d.mts +1 -1
  329. package/dist/store/catalogue.mjs +19 -7
  330. package/dist/store/crossing.mjs +1 -7
  331. package/dist/store/cursor-seal.d.mts +1 -1
  332. package/dist/store/cursor-seal.mjs +1 -1
  333. package/dist/store/door.mjs +9 -4
  334. package/dist/store/errors.d.mts +2 -2
  335. package/dist/store/errors.mjs +107 -19
  336. package/dist/store/git-store.mjs +7 -2
  337. package/dist/store/job-try.mjs +90 -9
  338. package/dist/store/list-job.mjs +10 -34
  339. package/dist/store/outbox.d.mts +2 -2
  340. package/dist/store/outbox.mjs +2 -2
  341. package/dist/store/queue-jobs.mjs +6 -12
  342. package/dist/store/records.d.mts +2 -2
  343. package/dist/store/records.mjs +2 -2
  344. package/dist/store/ref-rows.d.mts +2 -2
  345. package/dist/store/ref-rows.mjs +2 -2
  346. package/dist/store/repo-record.d.mts +2 -2
  347. package/dist/store/repo-record.mjs +3 -3
  348. package/dist/store/request-snapshot.mjs +5 -0
  349. package/dist/store/reservations.mjs +2 -2
  350. package/dist/store/topic-jobs.mjs +5 -11
  351. package/dist/sync/bound.d.mts +3 -3
  352. package/dist/sync/bound.mjs +10 -7
  353. package/dist/sync/github.mjs +65 -67
  354. package/dist/sync/http.mjs +1 -1
  355. package/dist/sync/import.mjs +201 -66
  356. package/dist/sync/layer.d.mts +1 -1
  357. package/dist/sync/layer.mjs +6 -6
  358. package/dist/sync/lfs-batch.mjs +1 -1
  359. package/dist/sync/lfs-copy.mjs +175 -15
  360. package/dist/sync/mirror.mjs +5 -10
  361. package/dist/sync/said.mjs +1 -1
  362. package/dist/sync/step.mjs +268 -86
  363. package/dist/sync/tries.mjs +25 -6
  364. package/dist/sync.d.mts +2 -2
  365. package/dist/sync.mjs +2 -2
  366. package/dist/topics/advance.mjs +3 -3
  367. package/dist/topics/calls.mjs +1 -1
  368. package/dist/topics/layer.d.mts +15 -14
  369. package/dist/topics/members.mjs +1 -1
  370. package/dist/topics/topic.mjs +1 -1
  371. package/package.json +3 -13
  372. package/dist/auth/helpers.mjs +0 -17
  373. package/dist/auth.d.mts +0 -5
  374. package/dist/auth.mjs +0 -5
  375. package/dist/core/rules/commit-changes.d.mts +0 -12
  376. package/dist/effect.d.mts +0 -9
  377. package/dist/effect.mjs +0 -7
  378. package/dist/server/joined.d.mts +0 -70
  379. package/dist/server/joined.mjs +0 -41
@@ -3,7 +3,7 @@ import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
3
3
  import { hexOf } from "../protocol/bytes/hex.mjs";
4
4
  import { Sha1 } from "../protocol/bytes/sha1.mjs";
5
5
  import { sha1Now } from "../protocol/bytes/sha1-hasher.mjs";
6
- import { objectHeader, objectId } from "../protocol/objects/object.mjs";
6
+ import { emptyTree, objectHeader, objectId } from "../protocol/objects/object.mjs";
7
7
  import { DeltaError, deltaResultSize } from "../protocol/packs/delta.mjs";
8
8
  import { oidBytes, ownedPackIndex, readPackIndex } from "../protocol/packs/idx.mjs";
9
9
  import { ownedPackReverse, readPackReverse } from "../protocol/packs/rev.mjs";
@@ -24,10 +24,12 @@ import { allotted, keptOrLeft } from "./allotted.mjs";
24
24
  import { fileBytesMost } from "./file-limits.mjs";
25
25
  import { packCodes } from "./plan-columns.mjs";
26
26
  import * as Effect from "effect/Effect";
27
+ import * as Predicate from "effect/Predicate";
27
28
  import * as Option from "effect/Option";
28
29
  import * as Cause from "effect/Cause";
30
+ import * as Exit from "effect/Exit";
29
31
  import * as Result from "effect/Result";
30
- import * as Predicate from "effect/Predicate";
32
+ import * as Deferred from "effect/Deferred";
31
33
  import * as Fiber from "effect/Fiber";
32
34
  import * as Hex from "effect/encoding/Hex";
33
35
  // src/storage/pack-reads.ts
@@ -406,48 +408,69 @@ var PackBlocks = class {
406
408
  */
407
409
  const packRun = (bucket, pack, from, to) => {
408
410
  let reader;
411
+ let opening;
412
+ let failed;
413
+ let closed = false;
409
414
  let piece = /* @__PURE__ */ new Uint8Array(0);
410
415
  let pieceAt = from;
411
416
  const missing = (at) => lost(`Pack ${pack.id} is missing its bytes from ${at}`);
412
- const open = Effect.uninterruptible(Effect.flatMap(bucketStream(bucket, packFiles(pack.id).pack, {
413
- offset: from,
414
- length: to - from
415
- }), (body) => {
416
- if (body === void 0) return Effect.fail(missing(from));
417
- const opened = body.getReader();
418
- reader = opened;
419
- return Effect.succeed(opened);
420
- }));
421
- const cancel = (opened) => Effect.promise(() => opened.cancel().catch(() => void 0));
417
+ const cancel = (stream) => Effect.promise(() => stream.cancel().catch(() => void 0));
418
+ const open = Effect.suspend(() => {
419
+ if (reader !== void 0) return Effect.succeed(reader);
420
+ if (failed !== void 0) return Effect.failCause(failed);
421
+ if (opening !== void 0) return Deferred.await(opening);
422
+ const pending = Deferred.makeUnsafe();
423
+ opening = pending;
424
+ return Effect.uninterruptible(Effect.flatMap(bucketStream(bucket, packFiles(pack.id).pack, {
425
+ offset: from,
426
+ length: to - from
427
+ }), (body) => {
428
+ if (body === void 0) return Effect.fail(missing(from));
429
+ if (closed) return Effect.andThen(cancel(body), Effect.interrupt);
430
+ const opened = body.getReader();
431
+ reader = opened;
432
+ return Effect.succeed(opened);
433
+ })).pipe(Effect.onExit((exit) => Effect.sync(() => {
434
+ opening = void 0;
435
+ if (Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)) failed = exit.cause;
436
+ Deferred.doneUnsafe(pending, exit);
437
+ })));
438
+ });
422
439
  /**
423
440
  * The body's next piece, or its end, its failure as `bucketTry` maps one: a closed server's, and
424
441
  * one past a call bound, stay defects. An interruption cancels the body. The read takes no signal,
425
442
  * so it adds no listener to one.
426
443
  */
427
444
  const nextPiece = (opened) => bucketTry(() => opened.read()).pipe(Effect.onInterrupt(() => cancel(opened)));
445
+ const read = Effect.fnUntraced(function* (offset, end) {
446
+ if (offset < pieceAt || end > to) return yield* Effect.die(/* @__PURE__ */ new Error(`a run of ${from} to ${to} can't read ${offset} to ${end}`));
447
+ const opened = reader ?? (yield* open);
448
+ while (offset >= pieceAt + piece.byteLength) {
449
+ pieceAt += piece.byteLength;
450
+ const next = yield* nextPiece(opened);
451
+ if (next.done) return yield* Effect.fail(missing(pieceAt));
452
+ const { value } = next;
453
+ piece = value.buffer instanceof ArrayBuffer ? new Uint8Array(value.buffer, value.byteOffset, value.byteLength) : value.slice();
454
+ }
455
+ return piece.subarray(offset - pieceAt, Math.min(piece.byteLength, end - pieceAt));
456
+ });
428
457
  return {
429
458
  from,
430
459
  to,
431
460
  reads: (offset) => offset >= pieceAt && offset < to,
432
- read: Effect.fnUntraced(function* (offset, end) {
433
- if (offset < pieceAt || end > to) return yield* Effect.die(/* @__PURE__ */ new Error(`a run of ${from} to ${to} can't read ${offset} to ${end}`));
434
- const opened = reader ?? (yield* open);
435
- while (offset >= pieceAt + piece.byteLength) {
436
- pieceAt += piece.byteLength;
437
- const next = yield* nextPiece(opened);
438
- if (next.done) return yield* Effect.fail(missing(pieceAt));
439
- const { value } = next;
440
- piece = value.buffer instanceof ArrayBuffer ? new Uint8Array(value.buffer, value.byteOffset, value.byteLength) : value.slice();
441
- }
442
- return piece.subarray(offset - pieceAt, Math.min(piece.byteLength, end - pieceAt));
443
- }),
461
+ start: Effect.asVoid(open),
462
+ read,
444
463
  close: Effect.suspend(() => {
464
+ closed = true;
445
465
  const opened = reader;
466
+ reader = void 0;
446
467
  piece = /* @__PURE__ */ new Uint8Array(0);
447
468
  return opened === void 0 ? Effect.void : cancel(opened);
448
469
  })
449
470
  };
450
471
  };
472
+ /** Bucket-scoped cache key for an immutable index file; disjoint from `PackId` (`p_...`). */
473
+ const fileCacheKey = (bucketId, key) => `file:${bucketId}:${key}`;
451
474
  /**
452
475
  * The most of the index cache's room one receive's seed may take, as a share of `room.most`: a
453
476
  * pack's entry past it is read by a load instead, so one push never fills half of what the cache can
@@ -460,9 +483,10 @@ const indexSeedShare = 1 / 2;
460
483
  */
461
484
  const seedBytes = (files) => 384 + 2 * (files.index.byteLength + files.reverse.byteLength);
462
485
  /**
463
- * The `.idx` and `.rev` of each pack a server has read, across every repo, by the pack's ID: a
464
- * pack's files never change, so one is checked once, its trailer against the index's and the
465
- * reverse index against both, and kept until the cache is full.
486
+ * The `.idx` and `.rev` of each pack a server has read, across every repo, by the pack's ID, and
487
+ * the small immutable index files (`index/<r>/<build>.{graph,types,bitmaps,bases}` and
488
+ * `packs/<p>.{idx,pos}`) read whole by `heldIndex`, scoped to `(bucket, key)`: each is kept in
489
+ * one LRU under the server's index `CacheRoom` until the cache is full or shrinks (#2518).
466
490
  */
467
491
  var PackIndexes = class {
468
492
  #kept = /* @__PURE__ */ new Map();
@@ -471,16 +495,25 @@ var PackIndexes = class {
471
495
  * caller alone is loaded again by a waiter, and a failed one is never kept.
472
496
  */
473
497
  #loading = new SingleFlight();
498
+ /** Each index file's read under way, keyed by `(bucket, key[, range])`, sharing one bucket get. */
499
+ #reading = new SingleFlight();
500
+ /** Opaque per-bucket IDs scoping cached file keys to the bucket they were read from. */
501
+ #buckets = /* @__PURE__ */ new WeakMap();
474
502
  #room;
503
+ #nextBucket = 0;
475
504
  #held = 0;
476
505
  /**
477
- * `room`: what it keeps of the `.idx` and `.rev` it reads, across every repo, each pack's
506
+ * `room`: what it keeps of the `.idx`, `.rev` and immutable index files it reads, each entry
478
507
  * counted with `cacheEntryBytes`. A room of 0 that never grows keeps none.
479
508
  */
480
509
  constructor(room) {
481
510
  this.#room = room;
482
511
  room.watch((bytes) => this.#evictTo(bytes));
483
512
  }
513
+ /** Total bytes currently held by kept entries (each with `cacheEntryBytes`). */
514
+ get heldBytes() {
515
+ return this.#held;
516
+ }
484
517
  /**
485
518
  * `listed`'s `.idx` and `.rev`, kept or read. One load of a pack runs at a time, whoever asks:
486
519
  * the cache owns it, and every other caller waits on it, so 16 cold reads of one pack make one
@@ -497,7 +530,7 @@ var PackIndexes = class {
497
530
  bytes: listed.bytes
498
531
  };
499
532
  const kept = this.#kept.get(id);
500
- if (kept !== void 0) {
533
+ if (kept !== void 0 && kept.kind === "pack") {
501
534
  this.#kept.delete(id);
502
535
  this.#kept.set(id, kept);
503
536
  return {
@@ -529,6 +562,7 @@ var PackIndexes = class {
529
562
  const reverse = yield* ownedPackReverse(reversed, index).pipe(Effect.mapError((error) => lost(`Pack ${id}'s reverse index is unreadable: ${error.message}`)));
530
563
  const held = 384 + bytes.buffer.byteLength + reversed.buffer.byteLength;
531
564
  this.#remember(id, {
565
+ kind: "pack",
532
566
  index,
533
567
  reverse,
534
568
  bytes: held
@@ -568,23 +602,32 @@ var PackIndexes = class {
568
602
  const over = this.#held + held - this.#room.bytes;
569
603
  if (over > 0 && !this.#room.grow(over)) return;
570
604
  this.#remember(id, {
605
+ kind: "pack",
571
606
  index: index.value,
572
607
  reverse: reverse.value,
573
608
  bytes: held
574
609
  });
575
610
  });
576
611
  /**
577
- * Lets go of pack `id`'s kept `.idx` and `.rev`, for a pack whose files were deleted. A load of it
578
- * under way when it's called keeps what it reads once it ends, so a pack is forgotten only once
579
- * no load of it is running.
612
+ * Lets go of pack `id`'s kept `.idx` and `.rev`, and any kept raw `packs/<id>.{idx,pos}` files,
613
+ * for a pack whose files were deleted. A load of it under way when it's called keeps what it
614
+ * reads once it ends, so a pack is forgotten only once no load of it is running.
580
615
  */
581
616
  forget = (id) => {
582
617
  if (!isPackId(id)) return;
583
618
  const kept = this.#kept.get(id);
584
- if (kept === void 0) return;
585
- this.#kept.delete(id);
586
- this.#held -= kept.bytes;
619
+ if (kept !== void 0) {
620
+ this.#kept.delete(id);
621
+ this.#held -= kept.bytes;
622
+ }
623
+ const { idx, pos } = packFiles(id);
624
+ for (const [each, entry] of this.#kept) if (entry.kind === "file" && (entry.key === idx || entry.key === pos)) {
625
+ this.#kept.delete(each);
626
+ this.#held -= entry.bytes;
627
+ }
587
628
  };
629
+ /** Whether the cache currently keeps pack `id`'s `.idx` and `.rev`, without changing recency. */
630
+ has = (id) => isPackId(id) && this.#kept.has(id);
588
631
  /**
589
632
  * The `.idx` the cache keeps for pack `id`, read by no call and made the most recent, or
590
633
  * `undefined` when it keeps none: a lookup that must hold no `.idx` of its own reads one held
@@ -593,26 +636,98 @@ var PackIndexes = class {
593
636
  peek = (id) => {
594
637
  if (!isPackId(id)) return void 0;
595
638
  const kept = this.#kept.get(id);
596
- if (kept === void 0) return void 0;
639
+ if (kept === void 0 || kept.kind !== "pack") return void 0;
597
640
  this.#kept.delete(id);
598
641
  this.#kept.set(id, kept);
599
642
  return kept.index;
600
643
  };
601
644
  /**
602
- * `kept` at `id`, the most recent. One already there, which one load of a pack at a time leaves
603
- * none of, would be let go first, so `#held` is always the sum of the indexes kept: a second load
604
- * costs its reads, never a charge that outlives its entry.
645
+ * Kept bytes of immutable file `key` read from `bucket`, made the most recent, or `undefined`.
646
+ * Scoped to `bucket`'s identity so one bucket's bytes never answer another's.
647
+ */
648
+ peekFile(bucket, key) {
649
+ const bucketId = this.#buckets.get(bucket);
650
+ if (bucketId === void 0) return void 0;
651
+ const cacheKey = fileCacheKey(bucketId, key);
652
+ const kept = this.#kept.get(cacheKey);
653
+ if (kept === void 0 || kept.kind !== "file") return void 0;
654
+ this.#kept.delete(cacheKey);
655
+ this.#kept.set(cacheKey, kept);
656
+ return kept.data;
657
+ }
658
+ /**
659
+ * Reads `file` from `bucket` through `read`, sharing one in-flight read per `(bucket, key[, range])`
660
+ * across concurrent callers and keeping immutable whole files within this cache's room.
661
+ */
662
+ readFile = Effect.fnUntraced({ self: this }, function* (bucket, file, read, limit) {
663
+ const bucketId = this.#bucketIdOf(bucket);
664
+ const cacheKey = fileCacheKey(bucketId, file.key);
665
+ if (file.immutable === true && file.range === void 0) {
666
+ const kept = this.#kept.get(cacheKey);
667
+ if (kept !== void 0 && kept.kind === "file") {
668
+ this.#kept.delete(cacheKey);
669
+ this.#kept.set(cacheKey, kept);
670
+ return {
671
+ kind: "file",
672
+ bytes: kept.data,
673
+ charged: kept.data.byteLength
674
+ };
675
+ }
676
+ }
677
+ const flightKey = file.range === void 0 ? cacheKey : `${cacheKey}@${file.range.offset}:${file.range.length}`;
678
+ let led = false;
679
+ const loaded = yield* this.#reading.run(flightKey, Effect.suspend(() => {
680
+ led = true;
681
+ return this.#readFile(file, cacheKey, read);
682
+ }));
683
+ if (Option.isNone(loaded)) return yield* this.readFile(bucket, file, read, limit);
684
+ const result = loaded.value;
685
+ if (!led && result.kind === "past" && limit() > result.limit) return yield* this.readFile(bucket, file, read, limit);
686
+ return result;
687
+ });
688
+ #readFile = Effect.fnUntraced({ self: this }, function* (file, cacheKey, read) {
689
+ const result = yield* read();
690
+ if (result.kind === "file" && file.immutable === true && file.range === void 0) {
691
+ const { bytes } = result;
692
+ const owned = bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength ? bytes : bytes.slice();
693
+ this.#remember(cacheKey, {
694
+ kind: "file",
695
+ key: file.key,
696
+ data: owned,
697
+ bytes: 384 + owned.buffer.byteLength
698
+ });
699
+ return {
700
+ kind: "file",
701
+ bytes: owned,
702
+ charged: result.charged
703
+ };
704
+ }
705
+ return result;
706
+ });
707
+ #bucketIdOf(bucket) {
708
+ const existing = this.#buckets.get(bucket);
709
+ if (existing !== void 0) return existing;
710
+ const id = this.#nextBucket += 1;
711
+ this.#buckets.set(bucket, id);
712
+ return id;
713
+ }
714
+ /**
715
+ * `kept` at `key`, the most recent. Entries larger than the room's most (or larger than its
716
+ * current bytes when growth is refused) aren't kept, leaving entries that fit untouched. One
717
+ * already there is let go first, so `#held` is always the sum of the entries kept.
605
718
  */
606
- #remember(id, kept) {
607
- const displaced = this.#kept.get(id);
719
+ #remember(key, kept) {
720
+ if (kept.bytes > this.#room.most) return;
721
+ const displaced = this.#kept.get(key);
722
+ const over = this.#held - (displaced?.bytes ?? 0) + kept.bytes - this.#room.bytes;
723
+ if (over > 0 && !this.#room.grow(over) && kept.bytes > this.#room.bytes) return;
608
724
  if (displaced !== void 0) {
609
- this.#kept.delete(id);
725
+ this.#kept.delete(key);
610
726
  this.#held -= displaced.bytes;
611
727
  }
612
- this.#kept.set(id, kept);
728
+ this.#kept.set(key, kept);
613
729
  this.#held += kept.bytes;
614
- const over = this.#held - this.#room.bytes;
615
- if (over > 0 && !this.#room.grow(over)) this.#evictTo(this.#room.bytes);
730
+ if (this.#held > this.#room.bytes) this.#evictTo(this.#room.bytes);
616
731
  }
617
732
  #evictTo(bytes) {
618
733
  for (const [each, kept] of this.#kept) {
@@ -918,12 +1033,16 @@ const isIndexShort = (error) => error.cause instanceof IndexShort;
918
1033
  * against its ID.
919
1034
  */
920
1035
  const packReader = (input) => {
921
- const { store, bucket, indexes, listed, memory } = input;
1036
+ const { store, bucket, indexes, listed, memory, observe } = input;
922
1037
  const blocks = input.blocks ?? new PackBlocks(bucket, memory.blocks);
923
- const { listedOnly } = input;
924
- const rows = listedOnly === true ? () => Effect.void : eachHeldRow(store, listed);
925
- const rowsSized = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowSizes(store, listed);
926
- const rowsHeaders = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowHeaders(store, listed);
1038
+ const { listedOnly, rowCache } = input;
1039
+ const rows = listedOnly === true ? () => Effect.void : eachHeldRow(store, listed, void 0, rowCache);
1040
+ const rowsSized = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowSizes(store, listed, rowCache);
1041
+ const rowsHeaders = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowHeaders(store, listed, void 0, rowCache);
1042
+ const observedRowHeaders = listedOnly === true || observe === void 0 ? rowsHeaders : rowHeaders(store, listed, (row, header) => {
1043
+ observe.located(row.id, void 0);
1044
+ observe.row(row, header);
1045
+ }, rowCache);
927
1046
  const wholeAt = packObjects(blocks, memory.cache, memory.outside);
928
1047
  const named = new Set(listed.packs.map((pack) => pack.id));
929
1048
  const kept = /* @__PURE__ */ new Map();
@@ -967,7 +1086,7 @@ const packReader = (input) => {
967
1086
  * until it fits, before the load, so the reader never holds past the floor while it reads. One
968
1087
  * the room let go of fails as `indexReloaded`, and one past `canLoad` as `indexShort`.
969
1088
  */
970
- const roomed = Effect.fnUntraced(function* (pack, { bytes: floor, canLoad }) {
1089
+ const roomed = Effect.fnUntraced(function* (pack, { bytes: floor, canLoad }, from = bucket) {
971
1090
  const known = kept.get(pack.id);
972
1091
  if (known !== void 0) {
973
1092
  kept.delete(pack.id);
@@ -983,7 +1102,7 @@ const packReader = (input) => {
983
1102
  const bytes = indexBytes(pack);
984
1103
  makeRoom(bytes, floor);
985
1104
  for (const told of loadings) told(pack.id);
986
- const loaded = yield* indexes.load(bucket, pack);
1105
+ const loaded = yield* indexes.load(from, pack);
987
1106
  const raced = kept.get(pack.id);
988
1107
  if (raced !== void 0) return raced;
989
1108
  makeRoom(bytes, floor);
@@ -1064,7 +1183,7 @@ const packReader = (input) => {
1064
1183
  scope: repoScope(listed.repo),
1065
1184
  reads: [{
1066
1185
  collection: objectCollections.leaving,
1067
- limit: leavingPageRows,
1186
+ limit: 1e3,
1068
1187
  ...page
1069
1188
  }]
1070
1189
  })).results[0] ?? [];
@@ -1074,7 +1193,7 @@ const packReader = (input) => {
1074
1193
  objects: value.objects,
1075
1194
  bytes: value.bytes
1076
1195
  })).filter(unnamed),
1077
- next: rows.length < leavingPageRows ? void 0 : rows.at(-1)?.id
1196
+ next: rows.length < 1e3 ? void 0 : rows.at(-1)?.id
1078
1197
  };
1079
1198
  });
1080
1199
  /**
@@ -1153,12 +1272,15 @@ const packReader = (input) => {
1153
1272
  const inRows = /* @__PURE__ */ new Set();
1154
1273
  yield* rows(unpacked, (object) => {
1155
1274
  inRows.add(object.oid);
1275
+ observe?.located(object.oid, void 0);
1276
+ observe?.whole(object);
1156
1277
  return row(object);
1157
1278
  });
1158
1279
  const missing = unpacked.filter((oid) => !inRows.has(oid));
1159
1280
  if (missing.length > 0) for (const [oid, place] of yield* found(missing, "all", skip)) where.set(oid, place);
1160
1281
  const skipped = skip === void 0 ? [] : missing.filter((oid) => !where.has(oid));
1161
1282
  if (skipped.length > 0) for (const [oid, place] of yield* found(skipped)) where.set(oid, place);
1283
+ if (observe !== void 0) for (const [oid, { indexed }] of where) observe.located(oid, indexed.pack.id);
1162
1284
  return where;
1163
1285
  });
1164
1286
  /**
@@ -1168,7 +1290,11 @@ const packReader = (input) => {
1168
1290
  */
1169
1291
  const eachOf = (skip) => Effect.fnUntraced(function* (oids, take) {
1170
1292
  const where = yield* located(oids, take, skip);
1171
- for (const [oid, { indexed, offset }] of where) yield* take(yield* wholeAt(oid, indexed, offset));
1293
+ for (const [oid, { indexed, offset }] of where) {
1294
+ const whole = yield* wholeAt(oid, indexed, offset);
1295
+ observe?.whole(whole);
1296
+ yield* take(whole);
1297
+ }
1172
1298
  });
1173
1299
  /**
1174
1300
  * `each` under `indexFloor`: the listed packs' objects a pack at a time, each read whole while its
@@ -1176,16 +1302,21 @@ const packReader = (input) => {
1176
1302
  * holds, then the packs listed since and those leaving.
1177
1303
  */
1178
1304
  const eachInRoom = Effect.fnUntraced(function* (oids, take) {
1179
- const left = yield* byPacks(oids, (indexed, entries) => Effect.forEach(entries, ({ oid, offset }) => Effect.flatMap(wholeAt(oid, indexed, offset), take), { discard: true }));
1305
+ const deliver = (whole, pack) => {
1306
+ observe?.located(whole.oid, pack);
1307
+ observe?.whole(whole);
1308
+ return take(whole);
1309
+ };
1310
+ const left = yield* byPacks(oids, (indexed, entries) => Effect.forEach(entries, ({ oid, offset }) => Effect.flatMap(wholeAt(oid, indexed, offset), (whole) => deliver(whole, indexed.pack.id)), { discard: true }));
1180
1311
  if (left.length === 0) return;
1181
1312
  const inRows = /* @__PURE__ */ new Set();
1182
1313
  yield* rows(left, (object) => {
1183
1314
  inRows.add(object.oid);
1184
- return take(object);
1315
+ return deliver(object, void 0);
1185
1316
  });
1186
1317
  const missing = left.filter((oid) => !inRows.has(oid));
1187
1318
  if (missing.length === 0) return;
1188
- for (const [oid, { indexed, offset }] of yield* found(missing, "beyond")) yield* take(yield* wholeAt(oid, indexed, offset));
1319
+ for (const [oid, { indexed, offset }] of yield* found(missing, "beyond")) yield* deliver(yield* wholeAt(oid, indexed, offset), indexed.pack.id);
1189
1320
  });
1190
1321
  const each = indexFloor === void 0 ? eachOf() : eachInRoom;
1191
1322
  /** Which of `oids` the repo holds, read whole, through `take`'s reads. */
@@ -1218,16 +1349,39 @@ const packReader = (input) => {
1218
1349
  return (yield* wholeAt.atIn(oid, lookup, offset)).bytes.byteLength;
1219
1350
  });
1220
1351
  /**
1221
- * The size of each of `oids` the repo holds, none held whole past its own read: each pack's in
1222
- * the order of its offsets, so its neighbourhoods are read once.
1352
+ * The size of each of `oids` the repo holds, none held whole past its own read: in-memory cached
1353
+ * rows first (no call), then listed packs by their `.idx` (so a fully packed repo asks the store
1354
+ * for no row, as `located` does), then loose/staged rows for any left, then packs listed since
1355
+ * and those leaving. Each pack's entries are read in offset order so its neighbourhoods are read
1356
+ * once (#2960).
1223
1357
  */
1224
1358
  const sizesOf = (skip) => Effect.fnUntraced(function* (oids) {
1225
1359
  const sized = /* @__PURE__ */ new Map();
1226
- for (const [oid, size] of yield* rowsSized(oids)) sized.set(oid, size);
1227
- const unsized = oids.filter((oid) => !sized.has(oid));
1228
- const where = yield* found(unsized, "all", skip);
1229
- const skipped = skip === void 0 ? [] : unsized.filter((oid) => !where.has(oid));
1230
- if (skipped.length > 0) for (const [oid, place] of yield* found(skipped)) where.set(oid, place);
1360
+ const needed = [];
1361
+ for (const oid of new Set(oids)) {
1362
+ if (listedOnly !== true && oid === "4b825dc642cb6eb9a060e54bf8d69288fbee4904") {
1363
+ sized.set(emptyTree, 0);
1364
+ continue;
1365
+ }
1366
+ const cached = listedOnly === true ? void 0 : rowCache?.headerOf(oid);
1367
+ if (cached !== void 0) {
1368
+ sized.set(oid, cached.size);
1369
+ continue;
1370
+ }
1371
+ needed.push(oid);
1372
+ }
1373
+ if (needed.length === 0) return sized;
1374
+ const where = yield* found(needed, "listed", skip);
1375
+ const unpacked = needed.filter((oid) => !where.has(oid));
1376
+ if (unpacked.length > 0) {
1377
+ for (const [oid, size] of yield* rowsSized(unpacked)) sized.set(oid, size);
1378
+ const missing = unpacked.filter((oid) => !sized.has(oid));
1379
+ if (missing.length > 0) {
1380
+ for (const [oid, place] of yield* found(missing, "beyond", skip)) where.set(oid, place);
1381
+ const skipped = skip === void 0 ? [] : missing.filter((oid) => !where.has(oid));
1382
+ if (skipped.length > 0) for (const [oid, place] of yield* found(skipped)) where.set(oid, place);
1383
+ }
1384
+ }
1231
1385
  for (const [oid, { indexed, offset }] of byPlace(where)) sized.set(oid, yield* sizeAt(oid, loadedLookup(indexed), offset));
1232
1386
  return sized;
1233
1387
  });
@@ -1312,16 +1466,20 @@ const packReader = (input) => {
1312
1466
  */
1313
1467
  const headers = Effect.fnUntraced(function* (oids) {
1314
1468
  const listedAt = yield* found(oids, "listed");
1469
+ if (observe !== void 0) for (const [oid, { indexed }] of listedAt) observe.located(oid, indexed.pack.id);
1315
1470
  const unpacked = oids.filter((oid) => !listedAt.has(oid));
1316
- const answer = new Map(unpacked.length === 0 ? [] : yield* rowsHeaders(unpacked));
1471
+ const answer = new Map(unpacked.length === 0 ? [] : yield* observedRowHeaders(unpacked));
1472
+ if (observe !== void 0) for (const oid of answer.keys()) observe.located(oid, void 0);
1317
1473
  const missing = unpacked.filter((oid) => !answer.has(oid));
1318
1474
  const later = missing.length === 0 ? [] : yield* found(missing, "beyond");
1475
+ if (observe !== void 0) for (const [oid, { indexed }] of later) observe.located(oid, indexed.pack.id);
1319
1476
  const where = byPlace(new Map([...listedAt, ...later]));
1320
1477
  const known = /* @__PURE__ */ new Map();
1321
1478
  for (const [oid, { indexed, offset }] of where) {
1322
1479
  const type = yield* typeAt(indexed, offset, known);
1323
1480
  if (type === void 0) {
1324
1481
  const whole = yield* wholeAt(oid, indexed, offset);
1482
+ observe?.whole(whole);
1325
1483
  answer.set(oid, {
1326
1484
  type: whole.type,
1327
1485
  size: whole.bytes.byteLength
@@ -1407,7 +1565,8 @@ const packReader = (input) => {
1407
1565
  * it's `storedOf`'s answer set in the columns.
1408
1566
  */
1409
1567
  const storedInto = Effect.fnUntraced(function* (columns, ordinals, skip) {
1410
- const asking = Uint32Array.from(ordinals);
1568
+ const asking = rowCache === void 0 ? Uint32Array.from(ordinals) : Uint32Array.from(ordinals).filter((ordinal) => !rowCache.has(columns.oidAt(ordinal)));
1569
+ if (asking.length === 0) return;
1411
1570
  if (indexFloor !== void 0 && skip === void 0) {
1412
1571
  const entries = yield* storedOf(Array.from(asking, (ordinal) => columns.oidAt(ordinal)));
1413
1572
  for (const ordinal of asking) {
@@ -1474,7 +1633,11 @@ const packReader = (input) => {
1474
1633
  gets: (entries) => blocks.gets(entries),
1475
1634
  run: (pack, from, to) => packRun(bucket, pack, from, to),
1476
1635
  kept: (pack, offset) => blocks.keeps(pack, offset),
1477
- packed: (oids) => Effect.map(found(oids, "listed"), (where) => new Set(where.keys()))
1636
+ packed: (oids) => Effect.map(found(oids, "listed"), (where) => new Set(where.keys())),
1637
+ ...rowCache !== void 0 && {
1638
+ cachedRow: (oid) => rowCache.has(oid),
1639
+ pinCachedRows: (reserveBytes) => rowCache.pin(reserveBytes)
1640
+ }
1478
1641
  };
1479
1642
  /**
1480
1643
  * The object `oid` as `ObjectReader.read` hands it on, rows first: a whole entry past
@@ -1603,12 +1766,12 @@ const packReader = (input) => {
1603
1766
  * lookups load them, once a pack, through the server's cache, so a fetch's index path and its
1604
1767
  * walk read them once between them, and none when the cache holds them.
1605
1768
  */
1606
- const indexed = Effect.fnUntraced(function* (pack) {
1607
- if (indexFloor !== void 0) return yield* roomed(pack, indexFloor);
1769
+ const indexed = Effect.fnUntraced(function* (pack, from = bucket) {
1770
+ if (indexFloor !== void 0) return yield* roomed(pack, indexFloor, from);
1608
1771
  const known = kept.get(pack.id);
1609
1772
  if (known !== void 0) return known;
1610
1773
  yield* charge(pack);
1611
- const loaded = yield* indexes.load(bucket, pack);
1774
+ const loaded = yield* indexes.load(from, pack);
1612
1775
  kept.set(pack.id, loaded);
1613
1776
  return loaded;
1614
1777
  });
@@ -1720,6 +1883,7 @@ const packReader = (input) => {
1720
1883
  };
1721
1884
  const reads = {
1722
1885
  indexed,
1886
+ cachedIndex: (pack) => kept.has(pack.id) || indexes.has(pack.id),
1723
1887
  loadedOf: (pack) => kept.get(pack.id),
1724
1888
  onLoading: (told) => {
1725
1889
  loadings.add(told);
@@ -1804,4 +1968,4 @@ const narrowedTo = (reads, visible) => {
1804
1968
  wholeBlobs: (oids) => Effect.flatMap(only(oids), reads.wholeBlobs)
1805
1969
  };
1806
1970
  };
1807
- export { IndexReloaded, IndexShort, PackBlocks, PackIndexes, blockBytes, blockHeld, blocksHeld, entryEnd, hashedNowMost, hashedRunMost, headerLimits, indexBytes, indexSeedShare, isIndexReloaded, isIndexShort, loadedLookup, packIndexerLimits, packObjectBytes, packObjects, packReader, rangedLookup, readCacheBytes, readInto, seedBytes };
1971
+ export { IndexReloaded, IndexShort, PackBlocks, PackIndexes, blockBytes, blockHeld, blocksHeld, entryEnd, hashedNowMost, hashedRunMost, headerLimits, indexBytes, indexSeedShare, isIndexReloaded, isIndexShort, leavingPageRows, loadedLookup, packIndexerLimits, packObjectBytes, packObjects, packReader, rangedLookup, readCacheBytes, readInto, seedBytes };
@@ -1,7 +1,6 @@
1
1
  import "../contracts/time.mjs";
2
2
  import "../contracts/objects.mjs";
3
3
  import "../contracts/result.mjs";
4
- import "../contracts/services.mjs";
5
4
  import "../contracts/store.mjs";
6
5
  import "../protocol/packs/indexer.mjs";
7
6
  import "../protocol/packs/step.mjs";
@@ -11,6 +10,6 @@ import "./runs.mjs";
11
10
  import "./receive-state.mjs";
12
11
  import "./pack-reads.mjs";
13
12
  import "./quarantine.mjs";
14
- import "effect/Effect";
15
13
  import { Moment } from "@ref0/infra";
14
+ import "effect/Effect";
16
15
  import "effect/Types";
@@ -13,7 +13,7 @@ import { catchSpent, ownSpentOf } from "../contracts/calls-spent.mjs";
13
13
  import { bestEffort } from "../store/errors.mjs";
14
14
  import { CallBudget, requestCount, spentBudget } from "../store/call-count.mjs";
15
15
  import { newChangeId } from "../store/scopes.mjs";
16
- import { bucketPut, bucketReading, bucketStreamScoped } from "./calls.mjs";
16
+ import { bucketPut, bucketReading, bucketStreamScoped, bucketTry } from "./calls.mjs";
17
17
  import { packPutOptions, startPut } from "./merge.mjs";
18
18
  import { repoTypes } from "./held-types.mjs";
19
19
  import { checkedFilesRefused, checkedOverflow, checkedRecords, fsckRefusal, receiveChecked } from "./fsck.mjs";
@@ -37,8 +37,8 @@ import { dropRefused, openQuarantine, stillOpen } from "./quarantine.mjs";
37
37
  import { malformedPack, ofsRefused, readFailure } from "./unpack.mjs";
38
38
  import { oidBytes } from "../protocol/packs/idx.mjs";
39
39
  import * as Effect from "effect/Effect";
40
- import * as Result from "effect/Result";
41
40
  import * as Data from "effect/Data";
41
+ import * as Result from "effect/Result";
42
42
  // src/storage/pack-receive.ts
43
43
  /**
44
44
  * How large the reader lets an entry be: a whole one to `fileBytesMost`, kept only if it's a blob,
@@ -216,7 +216,10 @@ const unindexable = (offset, why, most = packObjectBytes) => {
216
216
  hint: deepHint,
217
217
  context: { reason: "too-large" }
218
218
  });
219
- return gitError("INVALID_ARGUMENT", `The delta at ${offset} has no base before it in the pack`, { hint: "Push again, with every object the pack needs: this server asks for no thin packs" });
219
+ return gitError("INVALID_ARGUMENT", `The delta at ${offset} has no base before it in the pack`, {
220
+ hint: "Push again, with every object the pack needs: this server asks for no thin packs",
221
+ context: { reason: "base-not-before" }
222
+ });
220
223
  };
221
224
  /**
222
225
  * The pack's bytes on their way to the bucket as they're read, through `startPut`, the last
@@ -315,20 +318,16 @@ const spentRuns = {
315
318
  */
316
319
  const putAgain = (bucket, key, bytes, put) => put.pipe(Effect.catchIf((error) => error.code === "ALREADY_EXISTS", (error) => Effect.flatMap(sameFile(bucket, key, bytes), (same) => same ? Effect.void : Effect.fail(error))));
317
320
  /** Whether the file at `key` holds exactly `bytes`. */
318
- const sameFile = (bucket, key, bytes) => bucketReading(bucket, key, void 0, async (body) => {
319
- if (body === void 0) return false;
320
- const reader = body.getReader();
321
+ const sameFile = (bucket, key, bytes) => bucketReading(bucket, key, void 0, Effect.fnUntraced(function* (reader) {
322
+ if (reader === void 0) return false;
321
323
  let at = 0;
322
- for (let piece = await reader.read(); !piece.done; piece = await reader.read()) {
324
+ for (let piece = yield* bucketTry(() => reader.read()); !piece.done; piece = yield* bucketTry(() => reader.read())) {
323
325
  const { value } = piece;
324
- if (at + value.byteLength > bytes.byteLength || value.some((byte, index) => byte !== bytes[at + index])) {
325
- await reader.cancel();
326
- return false;
327
- }
326
+ if (at + value.byteLength > bytes.byteLength || value.some((byte, index) => byte !== bytes[at + index])) return false;
328
327
  at += value.byteLength;
329
328
  }
330
329
  return at === bytes.byteLength;
331
- });
330
+ }));
332
331
  /** The pack's bytes and files under its opened row, as `receivePack` says. */
333
332
  const storePack = /* @__PURE__ */ Effect.fnUntraced(function* (input, opened, step) {
334
333
  const { store, bucket, indexes, listed, receive, memory } = input;
@@ -411,10 +410,12 @@ const storePack = /* @__PURE__ */ Effect.fnUntraced(function* (input, opened, st
411
410
  const boundary = new Set(joining === void 0 ? receive.boundary : []);
412
411
  yield* room.take(boundary.size * 120) ?? Effect.void;
413
412
  const named = !partial && new Set(receive.boundary).size === 0;
413
+ const looseRows = receive.hasLooseRows === false ? { hasLooseRows: false } : {};
414
414
  const typesHeld = repoTypes({
415
415
  ...reading,
416
416
  memory: memory.join,
417
- reader
417
+ reader,
418
+ ...looseRows
418
419
  });
419
420
  const linkedTypes = (there) => {
420
421
  const types = /* @__PURE__ */ new Map();
@@ -1016,11 +1017,16 @@ const storePack = /* @__PURE__ */ Effect.fnUntraced(function* (input, opened, st
1016
1017
  const put = bucketPut(bucket, key, bytes);
1017
1018
  return step === void 0 ? put : putAgain(bucket, key, bytes, put);
1018
1019
  };
1019
- yield* putFile(files.idx, written.index);
1020
- yield* putFile(files.rev, written.reverse);
1021
- yield* putFile(files.pos, written.positions);
1022
- yield* putFile(files.graph, graph);
1023
- yield* putFile(files.types, written.types);
1020
+ yield* Effect.all([
1021
+ putFile(files.idx, written.index),
1022
+ putFile(files.rev, written.reverse),
1023
+ putFile(files.pos, written.positions),
1024
+ putFile(files.graph, graph),
1025
+ putFile(files.types, written.types)
1026
+ ], {
1027
+ concurrency: 5,
1028
+ discard: true
1029
+ });
1024
1030
  if (step === void 0 && (received.spilled() || ended.spilled || links.spilled())) yield* dropRuns(bucket, opened.pack);
1025
1031
  yield* stillOpen({
1026
1032
  store,