@ref0/git 0.14.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 (492) hide show
  1. package/dist/access/private-refs.mjs +1 -1
  2. package/dist/auth/access-jwt.mjs +4 -4
  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 +4 -4
  8. package/dist/auth/fences.d.mts +1 -2
  9. package/dist/auth/fences.mjs +3 -3
  10. package/dist/auth/grants.mjs +4 -4
  11. package/dist/auth/host-function.mjs +19 -2
  12. package/dist/auth/host-services.mjs +4 -6
  13. package/dist/auth/identify.d.mts +1 -1
  14. package/dist/auth/identify.mjs +9 -3
  15. package/dist/auth/token-cleanup.mjs +67 -0
  16. package/dist/auth/token-rows.mjs +7 -2
  17. package/dist/auth/token-text.mjs +9 -1
  18. package/dist/auth/tokens-base.d.mts +35 -0
  19. package/dist/auth/tokens-base.mjs +13 -0
  20. package/dist/auth/tokens-layer.d.mts +2 -27
  21. package/dist/auth/tokens-layer.mjs +6 -11
  22. package/dist/auth/tokens-public.d.mts +3 -3
  23. package/dist/auth/tokens.d.mts +7 -10
  24. package/dist/auth/tokens.mjs +10 -81
  25. package/dist/client/answer.mjs +21 -42
  26. package/dist/client/client.d.mts +17 -11
  27. package/dist/client/client.mjs +21 -12
  28. package/dist/client/git-http.mjs +18 -8
  29. package/dist/client/local.mjs +74 -37
  30. package/dist/client/negotiate.mjs +3 -3
  31. package/dist/client/push-upload.mjs +34 -17
  32. package/dist/client/remote.mjs +12 -13
  33. package/dist/client/run-remote-helper.d.mts +2 -1
  34. package/dist/client/run-remote-helper.mjs +61 -27
  35. package/dist/client/slice-push.d.mts +1 -1
  36. package/dist/client/transport.mjs +105 -46
  37. package/dist/contracts/blobs.d.mts +58 -11
  38. package/dist/contracts/blobs.mjs +17 -3
  39. package/dist/contracts/call-allowance.d.mts +13 -0
  40. package/dist/contracts/call-allowance.mjs +44 -0
  41. package/dist/contracts/calls-spent.mjs +12 -35
  42. package/dist/contracts/client.d.mts +18 -18
  43. package/dist/contracts/commits.d.mts +28 -28
  44. package/dist/contracts/commits.mjs +1 -1
  45. package/dist/contracts/engine.d.mts +8 -3
  46. package/dist/contracts/engine.mjs +10 -1
  47. package/dist/contracts/events.d.mts +1 -1
  48. package/dist/contracts/events.mjs +1 -1
  49. package/dist/contracts/files.d.mts +14 -14
  50. package/dist/contracts/files.mjs +1 -1
  51. package/dist/contracts/forks.d.mts +21 -21
  52. package/dist/contracts/forks.mjs +1 -1
  53. package/dist/contracts/git-events.d.mts +29 -1
  54. package/dist/contracts/git-hooks.d.mts +2 -2
  55. package/dist/contracts/git.d.mts +30 -5
  56. package/dist/contracts/grants.d.mts +24 -4
  57. package/dist/contracts/handlers.d.mts +1 -1
  58. package/dist/contracts/lfs.d.mts +28 -2
  59. package/dist/contracts/merges.d.mts +3 -2
  60. package/dist/contracts/object-values.d.mts +1 -0
  61. package/dist/contracts/object-values.mjs +16 -1
  62. package/dist/contracts/objects.d.mts +42 -41
  63. package/dist/contracts/opaque.mjs +1 -1
  64. package/dist/contracts/operations.mjs +1 -1
  65. package/dist/contracts/queue.d.mts +247 -55
  66. package/dist/contracts/queue.mjs +8 -9
  67. package/dist/contracts/refs.d.mts +30 -27
  68. package/dist/contracts/refs.mjs +1 -1
  69. package/dist/contracts/remote.d.mts +8 -12
  70. package/dist/contracts/remote.mjs +4 -1
  71. package/dist/contracts/repos.d.mts +32 -141
  72. package/dist/contracts/repos.mjs +6 -4
  73. package/dist/contracts/result.d.mts +40 -18
  74. package/dist/contracts/result.mjs +42 -9
  75. package/dist/contracts/rules.d.mts +2 -2
  76. package/dist/contracts/server.d.mts +25 -52
  77. package/dist/contracts/services.d.mts +6 -9
  78. package/dist/contracts/services.mjs +1 -2
  79. package/dist/contracts/signin.d.mts +1 -1
  80. package/dist/contracts/store.d.mts +7 -6
  81. package/dist/contracts/sync.d.mts +73 -12
  82. package/dist/contracts/sync.mjs +14 -3
  83. package/dist/contracts/tags.d.mts +13 -13
  84. package/dist/contracts/tags.mjs +1 -1
  85. package/dist/contracts/time.d.mts +3 -0
  86. package/dist/contracts/{promises.mjs → time.mjs} +1 -1
  87. package/dist/contracts/tokens.d.mts +17 -19
  88. package/dist/contracts/tokens.mjs +4 -3
  89. package/dist/contracts/topics.d.mts +10 -10
  90. package/dist/contracts/trees.d.mts +16 -16
  91. package/dist/contracts/trees.mjs +1 -1
  92. package/dist/contracts/work.d.mts +28 -17
  93. package/dist/contracts/work.mjs +2 -2
  94. package/dist/core/access.d.mts +1 -2
  95. package/dist/core/access.mjs +20 -9
  96. package/dist/core/ancestry.d.mts +1 -0
  97. package/dist/core/ancestry.mjs +30 -34
  98. package/dist/core/asked.mjs +1 -1
  99. package/dist/core/call-groups.mjs +48 -0
  100. package/dist/core/call-names.mjs +6 -1
  101. package/dist/core/call-services.mjs +11 -3
  102. package/dist/core/events/deliver.d.mts +2 -3
  103. package/dist/core/events/deliver.mjs +45 -38
  104. package/dist/core/events/retired.mjs +119 -0
  105. package/dist/core/forks.mjs +929 -433
  106. package/dist/core/hooks/groups.mjs +3 -3
  107. package/dist/core/imports.mjs +127 -41
  108. package/dist/core/index-job.mjs +131 -38
  109. package/dist/core/index-lost.d.mts +1 -2
  110. package/dist/core/index-lost.mjs +2 -2
  111. package/dist/core/loose-tally.mjs +38 -15
  112. package/dist/core/merge-parts.d.mts +17 -4
  113. package/dist/core/merge-parts.mjs +7 -2
  114. package/dist/core/mirror-rows.mjs +31 -1
  115. package/dist/core/objects/blobs.mjs +127 -3
  116. package/dist/core/objects/files.mjs +20 -17
  117. package/dist/core/objects/lines.mjs +2 -2
  118. package/dist/core/objects/merges.mjs +4 -1
  119. package/dist/core/objects/objects-layer.d.mts +1 -1
  120. package/dist/core/objects/objects-layer.mjs +4 -4
  121. package/dist/core/objects/peel.mjs +1 -7
  122. package/dist/core/objects/reading.mjs +41 -29
  123. package/dist/core/objects/tags.mjs +4 -1
  124. package/dist/core/objects/tree-edits.mjs +1 -1
  125. package/dist/core/objects/trees.mjs +257 -58
  126. package/dist/core/objects/writing.mjs +4 -10
  127. package/dist/core/own-writes.mjs +2 -2
  128. package/dist/core/parts.d.mts +11 -5
  129. package/dist/core/parts.mjs +9 -10
  130. package/dist/core/purge.mjs +310 -93
  131. package/dist/core/push-decide.mjs +2 -0
  132. package/dist/core/push-files.d.mts +1 -1
  133. package/dist/core/push.d.mts +2 -2
  134. package/dist/core/push.mjs +170 -128
  135. package/dist/core/receipts.d.mts +2 -2
  136. package/dist/core/receipts.mjs +17 -5
  137. package/dist/core/ref-index-job.mjs +7 -7
  138. package/dist/core/ref-view.mjs +75 -32
  139. package/dist/core/refs.mjs +7 -7
  140. package/dist/core/registered-rows.mjs +2 -2
  141. package/dist/core/repack.mjs +58 -48
  142. package/dist/core/repo-info.mjs +3 -3
  143. package/dist/core/repos.mjs +21 -9
  144. package/dist/core/rules/changes.mjs +18 -40
  145. package/dist/core/rules/check.mjs +6 -5
  146. package/dist/core/rules/commit-changes.mjs +3 -15
  147. package/dist/core/rules/context.d.mts +3 -3
  148. package/dist/core/rules/context.mjs +18 -14
  149. package/dist/core/rules/fetch.mjs +1 -1
  150. package/dist/core/rules/protect.mjs +30 -17
  151. package/dist/core/saved-caller-views.d.mts +8 -3
  152. package/dist/core/saved-caller-views.mjs +4 -4
  153. package/dist/core/saved-callers.d.mts +19 -2
  154. package/dist/core/saved-callers.mjs +1 -1
  155. package/dist/core/seam.d.mts +17 -28
  156. package/dist/core/seam.mjs +7 -28
  157. package/dist/core/tokens.mjs +1 -1
  158. package/dist/core/view.d.mts +6 -3
  159. package/dist/core/view.mjs +18 -25
  160. package/dist/core/work.mjs +60 -15
  161. package/dist/engine/allotted-xdiff.mjs +3 -16
  162. package/dist/engine/combined.d.mts +3 -0
  163. package/dist/engine/combined.mjs +200 -185
  164. package/dist/engine/content.d.mts +2 -2
  165. package/dist/engine/content.mjs +1 -1
  166. package/dist/engine/failures.mjs +2 -1
  167. package/dist/engine/merge.mjs +7 -9
  168. package/dist/engine/reads.d.mts +2 -2
  169. package/dist/engine/reads.mjs +25 -17
  170. package/dist/engine/xdiff.d.mts +1 -1
  171. package/dist/engine/xdiff.mjs +1 -1
  172. package/dist/event-streams/event-streams.d.mts +1 -1
  173. package/dist/event-streams/event-streams.mjs +1 -1
  174. package/dist/event-streams/stream.d.mts +3 -3
  175. package/dist/event-streams/stream.mjs +39 -16
  176. package/dist/extend.d.mts +2 -7
  177. package/dist/extend.mjs +1 -4
  178. package/dist/http/answers.mjs +8 -5
  179. package/dist/http/core-parts.mjs +169 -96
  180. package/dist/http/handler.mjs +82 -10
  181. package/dist/http/node.d.mts +14 -1
  182. package/dist/http/node.mjs +56 -27
  183. package/dist/http/parts.d.mts +2 -0
  184. package/dist/http/push-upload-job.mjs +165 -47
  185. package/dist/http/push-uploads.mjs +37 -22
  186. package/dist/http/receive-pack.mjs +14 -53
  187. package/dist/http/request-snapshot.mjs +258 -0
  188. package/dist/http/upload-pack.mjs +25 -20
  189. package/dist/index.d.mts +36 -28
  190. package/dist/index.mjs +12 -3
  191. package/dist/lfs/answer.mjs +37 -0
  192. package/dist/lfs/base.d.mts +3 -1
  193. package/dist/lfs/base.mjs +25 -1
  194. package/dist/lfs/copy.d.mts +70 -8
  195. package/dist/lfs/copy.mjs +217 -21
  196. package/dist/lfs/layer.d.mts +19 -4
  197. package/dist/lfs/layer.mjs +25 -13
  198. package/dist/lfs/locks.mjs +3 -3
  199. package/dist/lfs/objects.d.mts +2 -1
  200. package/dist/lfs/objects.mjs +89 -19
  201. package/dist/lfs/pointers.mjs +2 -2
  202. package/dist/lfs/rows.d.mts +1 -1
  203. package/dist/lfs/rows.mjs +50 -9
  204. package/dist/lfs/upkeep.mjs +82 -17
  205. package/dist/lfs/uploaded.mjs +1 -1
  206. package/dist/lfs/wire.mjs +7 -32
  207. package/dist/merges/merges.mjs +19 -4
  208. package/dist/node.d.mts +2 -2
  209. package/dist/protocol/bytes/buffers.d.mts +1 -1
  210. package/dist/protocol/bytes/buffers.mjs +14 -6
  211. package/dist/protocol/bytes/deflate.d.mts +1 -1
  212. package/dist/protocol/bytes/deflate.mjs +1 -1
  213. package/dist/protocol/bytes/inflate.d.mts +1 -1
  214. package/dist/protocol/bytes/inflate.mjs +1 -1
  215. package/dist/protocol/bytes/reader.mjs +6 -1
  216. package/dist/protocol/bytes/sha1.d.mts +1 -1
  217. package/dist/protocol/bytes/sha1.mjs +1 -1
  218. package/dist/protocol/bytes/streams.mjs +27 -1
  219. package/dist/protocol/diff/read.d.mts +6 -4
  220. package/dist/protocol/diff/read.mjs +110 -11
  221. package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
  222. package/dist/protocol/objects/lfs-pointer.mjs +1 -3
  223. package/dist/protocol/objects/links-raw.mjs +24 -10
  224. package/dist/protocol/objects/tag.d.mts +1 -1
  225. package/dist/protocol/objects/tree.mjs +23 -6
  226. package/dist/protocol/packs/delta.d.mts +6 -3
  227. package/dist/protocol/packs/delta.mjs +96 -32
  228. package/dist/protocol/packs/graph.mjs +1 -1
  229. package/dist/protocol/packs/idx.d.mts +3 -2
  230. package/dist/protocol/packs/idx.mjs +23 -4
  231. package/dist/protocol/packs/parts.d.mts +4 -1
  232. package/dist/protocol/packs/parts.mjs +10 -7
  233. package/dist/protocol/packs/reader.d.mts +6 -1
  234. package/dist/protocol/packs/reader.mjs +4 -3
  235. package/dist/protocol/packs/write-error.d.mts +1 -1
  236. package/dist/protocol/packs/write-error.mjs +1 -1
  237. package/dist/protocol/packs/writer.mjs +26 -8
  238. package/dist/protocol/wire/advertisement.d.mts +1 -1
  239. package/dist/protocol/wire/advertisement.mjs +3 -2
  240. package/dist/protocol/wire/fetch.d.mts +1 -1
  241. package/dist/protocol/wire/fetch.mjs +1 -1
  242. package/dist/protocol/wire/lines.d.mts +9 -1
  243. package/dist/protocol/wire/lines.mjs +28 -1
  244. package/dist/protocol/wire/push-uploads.mjs +10 -7
  245. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  246. package/dist/protocol/wire/receive-pack.mjs +1 -1
  247. package/dist/protocol/wire/report-status.d.mts +1 -1
  248. package/dist/protocol/wire/report-status.mjs +1 -1
  249. package/dist/protocol/wire/v2.d.mts +1 -1
  250. package/dist/protocol/wire/v2.mjs +1 -1
  251. package/dist/queue/advance.mjs +48 -44
  252. package/dist/queue/base.d.mts +57 -0
  253. package/dist/queue/base.mjs +44 -0
  254. package/dist/queue/calls.mjs +54 -57
  255. package/dist/queue/commit.mjs +2 -2
  256. package/dist/queue/host.d.mts +2 -16
  257. package/dist/queue/host.mjs +2 -7
  258. package/dist/queue/layer.d.mts +2 -2
  259. package/dist/queue/layer.mjs +19 -8
  260. package/dist/queue/limits.mjs +2 -0
  261. package/dist/queue/push-option.mjs +9 -24
  262. package/dist/queue/schedule.mjs +2 -2
  263. package/dist/queue/search.mjs +1 -1
  264. package/dist/queue/state.mjs +3 -11
  265. package/dist/queue/trim.mjs +6 -4
  266. package/dist/rest/blobs.mjs +29 -5
  267. package/dist/rest/caller.d.mts +4 -4271
  268. package/dist/rest/caller.mjs +4 -0
  269. package/dist/rest/client.d.mts +9 -6
  270. package/dist/rest/client.mjs +25 -8
  271. package/dist/rest/errors.mjs +1 -1
  272. package/dist/rest/handler.mjs +2 -2
  273. package/dist/rest/handlers.mjs +66 -11
  274. package/dist/rest/layer.d.mts +2 -2
  275. package/dist/rest/layer.mjs +6 -13
  276. package/dist/rest/listen.mjs +2 -2
  277. package/dist/rest/me.d.mts +3 -432
  278. package/dist/rest/refs.mjs +1 -1
  279. package/dist/server/check-fetch.mjs +3 -3
  280. package/dist/server/edge-node.d.mts +11 -8
  281. package/dist/server/edge-node.mjs +9 -6
  282. package/dist/server/edge.d.mts +21 -7
  283. package/dist/server/edge.mjs +56 -11
  284. package/dist/server/extension.mjs +1 -1
  285. package/dist/server/git-layer.d.mts +5 -6
  286. package/dist/server/git-layer.mjs +28 -23
  287. package/dist/server/git-namespace.d.mts +4 -3
  288. package/dist/server/git-namespace.mjs +3 -2
  289. package/dist/server/lifecycle.mjs +19 -107
  290. package/dist/server/registry.mjs +24 -13
  291. package/dist/server/server.mjs +249 -371
  292. package/dist/signin/context.d.mts +1 -2
  293. package/dist/signin/context.mjs +1 -1
  294. package/dist/signin/forms.mjs +1 -1
  295. package/dist/signin/grants.d.mts +2 -2
  296. package/dist/signin/grants.mjs +1 -1
  297. package/dist/signin/layer.d.mts +1 -1
  298. package/dist/signin/layer.mjs +1 -1
  299. package/dist/signin/wire.mjs +1 -1
  300. package/dist/storage/allotted.mjs +22 -12
  301. package/dist/storage/batch-upkeep.mjs +293 -0
  302. package/dist/storage/batches.d.mts +7 -0
  303. package/dist/storage/batches.mjs +347 -0
  304. package/dist/storage/budget.mjs +23 -1
  305. package/dist/storage/calls.d.mts +2 -3
  306. package/dist/storage/calls.mjs +166 -182
  307. package/dist/storage/charged-cache.mjs +180 -0
  308. package/dist/storage/chunks.d.mts +9 -0
  309. package/dist/storage/chunks.mjs +410 -0
  310. package/dist/storage/clean-up.mjs +72 -9
  311. package/dist/storage/counted-bucket.mjs +35 -13
  312. package/dist/storage/fetch-row-cache.d.mts +6 -0
  313. package/dist/storage/fetch-row-cache.mjs +211 -0
  314. package/dist/storage/fetch.d.mts +2 -0
  315. package/dist/storage/fetch.mjs +339 -450
  316. package/dist/storage/held-types.d.mts +0 -1
  317. package/dist/storage/host-bucket.mjs +10 -6
  318. package/dist/storage/id-mix.mjs +19 -5
  319. package/dist/storage/index-bitmaps.mjs +86 -51
  320. package/dist/storage/index-build.d.mts +2 -4
  321. package/dist/storage/index-build.mjs +324 -67
  322. package/dist/storage/index-fetch.d.mts +3 -1
  323. package/dist/storage/index-fetch.mjs +163 -83
  324. package/dist/storage/index-files.d.mts +3 -0
  325. package/dist/storage/index-files.mjs +10 -5
  326. package/dist/storage/index-graph.mjs +73 -23
  327. package/dist/storage/index-layers.mjs +55 -25
  328. package/dist/storage/index-reach.mjs +15 -22
  329. package/dist/storage/index-remap.mjs +200 -64
  330. package/dist/storage/index-whole.d.mts +7 -0
  331. package/dist/storage/index-whole.mjs +235 -0
  332. package/dist/storage/largest-files.mjs +1 -7
  333. package/dist/storage/layout.mjs +40 -1
  334. package/dist/storage/lfs-pointers.mjs +1 -6
  335. package/dist/storage/link-join.mjs +55 -16
  336. package/dist/storage/list-source.d.mts +7 -0
  337. package/dist/storage/list-source.mjs +288 -0
  338. package/dist/storage/loose.d.mts +10 -7
  339. package/dist/storage/loose.mjs +293 -82
  340. package/dist/storage/memory-budget.mjs +242 -26
  341. package/dist/storage/merge-cut.mjs +9 -6
  342. package/dist/storage/merge-fence.mjs +1 -1
  343. package/dist/storage/merge-plan.mjs +3 -2
  344. package/dist/storage/merge-row.mjs +8 -2
  345. package/dist/storage/merge-stream.mjs +164 -25
  346. package/dist/storage/merge-walk.mjs +8 -4
  347. package/dist/storage/merge-write.mjs +1 -1
  348. package/dist/storage/merge.d.mts +3 -4
  349. package/dist/storage/merge.mjs +3 -3
  350. package/dist/storage/object-rows.d.mts +4 -3
  351. package/dist/storage/object-rows.mjs +545 -84
  352. package/dist/storage/oid-table.mjs +171 -0
  353. package/dist/storage/pack-order.mjs +104 -47
  354. package/dist/storage/pack-ranges.d.mts +1 -2
  355. package/dist/storage/pack-ranges.mjs +48 -21
  356. package/dist/storage/pack-reads.d.mts +6 -3
  357. package/dist/storage/pack-reads.mjs +378 -98
  358. package/dist/storage/pack-receive.d.mts +2 -3
  359. package/dist/storage/pack-receive.mjs +22 -18
  360. package/dist/storage/packs.d.mts +2 -2
  361. package/dist/storage/packs.mjs +587 -156
  362. package/dist/storage/placed-reads.mjs +34 -17
  363. package/dist/storage/plan-columns.d.mts +4 -0
  364. package/dist/storage/plan-columns.mjs +238 -0
  365. package/dist/storage/prune-keep.mjs +134 -41
  366. package/dist/storage/prune-seen.mjs +1 -1
  367. package/dist/storage/prune-walk.mjs +203 -63
  368. package/dist/storage/prune.mjs +197 -121
  369. package/dist/storage/push-allotment.mjs +116 -25
  370. package/dist/storage/push-uploads.mjs +196 -58
  371. package/dist/storage/pushed-commits.mjs +24 -3
  372. package/dist/storage/quarantine.d.mts +3 -4
  373. package/dist/storage/range-cache.mjs +293 -41
  374. package/dist/storage/raw-ids.mjs +39 -10
  375. package/dist/storage/ready.d.mts +3 -4
  376. package/dist/storage/ready.mjs +121 -43
  377. package/dist/storage/receive-bounds.mjs +50 -13
  378. package/dist/storage/receive-cache.d.mts +7 -0
  379. package/dist/storage/receive-cache.mjs +147 -0
  380. package/dist/storage/receive-files.mjs +1 -1
  381. package/dist/storage/receive-links.mjs +1 -1
  382. package/dist/storage/receive-state.d.mts +2 -2
  383. package/dist/storage/receive-state.mjs +6 -8
  384. package/dist/storage/receive-steps.d.mts +20 -0
  385. package/dist/storage/receive-steps.mjs +298 -13
  386. package/dist/storage/repack-backlog.mjs +1 -3
  387. package/dist/storage/repack-contained.mjs +2 -2
  388. package/dist/storage/repack-job.mjs +1 -1
  389. package/dist/storage/repack.d.mts +3 -4
  390. package/dist/storage/repack.mjs +54 -9
  391. package/dist/storage/request-cache.mjs +57 -0
  392. package/dist/storage/roots.mjs +1 -24
  393. package/dist/storage/rows.d.mts +3 -3
  394. package/dist/storage/rows.mjs +2 -2
  395. package/dist/storage/runs.d.mts +2 -2
  396. package/dist/storage/runs.mjs +196 -44
  397. package/dist/storage/send-list.d.mts +1 -0
  398. package/dist/storage/send-list.mjs +112 -31
  399. package/dist/storage/single-flight.mjs +13 -7
  400. package/dist/storage/stream-whole.mjs +188 -66
  401. package/dist/storage/swap-walk.mjs +1 -1
  402. package/dist/storage/unpack.mjs +919 -199
  403. package/dist/storage/visible.mjs +112 -34
  404. package/dist/storage/walk.mjs +193 -38
  405. package/dist/storage/wants.mjs +27 -63
  406. package/dist/store/bodies.mjs +38 -0
  407. package/dist/store/call-count.d.mts +10 -14
  408. package/dist/store/call-count.mjs +58 -57
  409. package/dist/store/catalogue.d.mts +2 -2
  410. package/dist/store/catalogue.mjs +158 -36
  411. package/dist/store/crossing.mjs +1 -9
  412. package/dist/store/cursor-seal.d.mts +1 -2
  413. package/dist/store/cursor-seal.mjs +17 -7
  414. package/dist/store/door.mjs +188 -0
  415. package/dist/store/errors.d.mts +4 -5
  416. package/dist/store/errors.mjs +119 -49
  417. package/dist/store/git-store.mjs +30 -7
  418. package/dist/store/job-try.mjs +98 -40
  419. package/dist/store/list-job.mjs +32 -20
  420. package/dist/store/outbox.d.mts +2 -2
  421. package/dist/store/outbox.mjs +2 -2
  422. package/dist/store/queue-jobs.mjs +6 -12
  423. package/dist/store/records.d.mts +5 -2
  424. package/dist/store/records.mjs +5 -2
  425. package/dist/store/ref-rows.d.mts +2 -2
  426. package/dist/store/ref-rows.mjs +2 -2
  427. package/dist/store/repo-record.d.mts +2 -3
  428. package/dist/store/repo-record.mjs +34 -22
  429. package/dist/store/request-snapshot.mjs +5 -0
  430. package/dist/store/reservations.mjs +3 -3
  431. package/dist/store/scopes.mjs +11 -0
  432. package/dist/store/settle.mjs +4 -4
  433. package/dist/store/topic-jobs.mjs +5 -11
  434. package/dist/sync/bound.d.mts +3 -3
  435. package/dist/sync/bound.mjs +10 -7
  436. package/dist/sync/github.mjs +67 -69
  437. package/dist/sync/http.mjs +1 -1
  438. package/dist/sync/import.mjs +205 -57
  439. package/dist/sync/layer.d.mts +1 -1
  440. package/dist/sync/layer.mjs +6 -6
  441. package/dist/sync/lfs-batch.mjs +5 -6
  442. package/dist/sync/lfs-copy.mjs +191 -20
  443. package/dist/sync/mirror.mjs +34 -36
  444. package/dist/sync/said.mjs +17 -38
  445. package/dist/sync/step.mjs +292 -102
  446. package/dist/sync/tries.mjs +34 -15
  447. package/dist/sync.d.mts +2 -2
  448. package/dist/sync.mjs +2 -2
  449. package/dist/topics/advance.mjs +12 -13
  450. package/dist/topics/base.d.mts +15 -0
  451. package/dist/topics/base.mjs +8 -0
  452. package/dist/topics/calls.mjs +1 -1
  453. package/dist/topics/host.mjs +1 -1
  454. package/dist/topics/layer.d.mts +17 -21
  455. package/dist/topics/layer.mjs +2 -3
  456. package/dist/topics/members.mjs +4 -4
  457. package/dist/topics/public.d.mts +2 -1
  458. package/dist/topics/topic.mjs +2 -2
  459. package/package.json +5 -14
  460. package/dist/auth/helpers.mjs +0 -17
  461. package/dist/auth.d.mts +0 -5
  462. package/dist/auth.mjs +0 -5
  463. package/dist/contracts/promises.d.mts +0 -39
  464. package/dist/core/call-names.d.mts +0 -3
  465. package/dist/core/clock.mjs +0 -18
  466. package/dist/core/promise.mjs +0 -74
  467. package/dist/core/rules/commit-changes.d.mts +0 -13
  468. package/dist/effect.d.mts +0 -18
  469. package/dist/effect.mjs +0 -16
  470. package/dist/lfs/calls.mjs +0 -26
  471. package/dist/rest/api.d.mts +0 -23
  472. package/dist/rest/blobs.d.mts +0 -833
  473. package/dist/rest/commits.d.mts +0 -3543
  474. package/dist/rest/errors.d.mts +0 -2124
  475. package/dist/rest/events.d.mts +0 -426
  476. package/dist/rest/files.d.mts +0 -1342
  477. package/dist/rest/forks.d.mts +0 -2160
  478. package/dist/rest/handlers.d.mts +0 -8
  479. package/dist/rest/merges.d.mts +0 -477
  480. package/dist/rest/queue.d.mts +0 -5917
  481. package/dist/rest/refs.d.mts +0 -2988
  482. package/dist/rest/repos.d.mts +0 -2567
  483. package/dist/rest/tags.d.mts +0 -1316
  484. package/dist/rest/tokens.d.mts +0 -2614
  485. package/dist/rest/topics.d.mts +0 -2224
  486. package/dist/rest/trees.d.mts +0 -1709
  487. package/dist/rest/work.d.mts +0 -1695
  488. package/dist/server/joined.d.mts +0 -82
  489. package/dist/server/joined.mjs +0 -68
  490. package/dist/server/lifecycle.d.mts +0 -2
  491. package/dist/store/promises.d.mts +0 -11
  492. package/dist/store/promises.mjs +0 -327
@@ -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";
@@ -14,7 +14,7 @@ import { callScope } from "../store/call-count.mjs";
14
14
  import { forkIn, noCall, runIn } from "../store/crossing.mjs";
15
15
  import { decodePacks } from "../store/git-store.mjs";
16
16
  import { collections, repoScope } from "../store/scopes.mjs";
17
- import { bucketDo, bucketStream, bucketTry, readWhole } from "./calls.mjs";
17
+ import { bucketDo, bucketStream, bucketTry, readEach, readWhole } from "./calls.mjs";
18
18
  import { isPackId, objectCollections, packFiles } from "./layout.mjs";
19
19
  import { idsStartingWith, openRanges, rankOf } from "./pack-ranges.mjs";
20
20
  import { eachHeldRow, gitObjectOf, rowHeaders, rowSizes, rowsStartingWith, startingOf } from "./object-rows.mjs";
@@ -22,14 +22,16 @@ import { LeavingRow, decodeHeld } from "./rows.mjs";
22
22
  import { SingleFlight } from "./single-flight.mjs";
23
23
  import { allotted, keptOrLeft } from "./allotted.mjs";
24
24
  import { fileBytesMost } from "./file-limits.mjs";
25
+ import { packCodes } from "./plan-columns.mjs";
25
26
  import * as Effect from "effect/Effect";
27
+ import * as Predicate from "effect/Predicate";
26
28
  import * as Option from "effect/Option";
27
29
  import * as Cause from "effect/Cause";
30
+ import * as Exit from "effect/Exit";
28
31
  import * as Result from "effect/Result";
29
- import * as Predicate from "effect/Predicate";
30
- import * as Stream from "effect/Stream";
31
- import * as Hex from "effect/encoding/Hex";
32
+ import * as Deferred from "effect/Deferred";
32
33
  import * as Fiber from "effect/Fiber";
34
+ import * as Hex from "effect/encoding/Hex";
33
35
  // src/storage/pack-reads.ts
34
36
  /** The largest object `packs()` reads whole: a file past it is stored and sent as it is. */
35
37
  const packObjectBytes = 16777216;
@@ -137,6 +139,8 @@ var PackBlocks = class {
137
139
  #bucket;
138
140
  #room;
139
141
  #kept = new KeptBlocks();
142
+ /** Each block's get while it's out: a second ask for it, as a push's other reader's, waits on it. */
143
+ #getting = new SingleFlight();
140
144
  /** `headIn`'s bytes across a blocks' edge, filled again by its next such read. */
141
145
  #head = /* @__PURE__ */ new Uint8Array(64);
142
146
  /** Bounded meter for this instance's reused entry reader: inflater, 64 KiB output and header. */
@@ -144,6 +148,8 @@ var PackBlocks = class {
144
148
  #entryReader;
145
149
  #entryReaderInUse = false;
146
150
  #closeReaderOnFinish = false;
151
+ /** Whether its room's owner ended: it keeps no block after. */
152
+ #released = false;
147
153
  /** The last `evictedKept` blocks it let go, oldest first. */
148
154
  #evicted = /* @__PURE__ */ new Set();
149
155
  #forget = (key) => {
@@ -179,6 +185,27 @@ var PackBlocks = class {
179
185
  get entryReaderMost() {
180
186
  return this.#entryMeter.most;
181
187
  }
188
+ /**
189
+ * Lets every kept block go and keeps none it reads after, for an owner that ends its room while
190
+ * a reader may still hold these blocks: a push's allotment, which its two readers share (#2525).
191
+ */
192
+ release() {
193
+ this.#released = true;
194
+ this.#kept.evictTo(0, this.#forget);
195
+ this.close();
196
+ }
197
+ /**
198
+ * Keeps `bytes` as `pack`'s one block, a pack no larger than `blockBytes` whose receive just
199
+ * streamed and checked them, so no read gets them from the bucket again (#2525). Bytes of any
200
+ * other length, or a pack of more than one block, keep nothing.
201
+ */
202
+ seed(pack, bytes) {
203
+ const length = blockLength(pack, 0);
204
+ if (this.#released || length !== pack.bytes || bytes.byteLength !== length) return;
205
+ this.#kept.add(blockKey(pack, 0), bytes, length);
206
+ const over = this.#kept.held - this.#room.bytes;
207
+ if (over > 0 && !this.#room.grow(over)) this.#kept.evictTo(this.#room.bytes, this.#forget);
208
+ }
182
209
  #releaseEntryReader() {
183
210
  this.#closeReaderOnFinish = false;
184
211
  this.#entryReader?.close();
@@ -191,10 +218,14 @@ var PackBlocks = class {
191
218
  * spending no get, rather than reading the same blocks until its calls run out (#1197). A first
192
219
  * read never waits: one that doesn't fit evicts, so a reader streaming through a pack goes on.
193
220
  */
194
- block = Effect.fnUntraced({ self: this }, function* (pack, start) {
221
+ block = (pack, start) => Effect.suspend(() => {
195
222
  const key = blockKey(pack, start);
196
223
  const kept = this.#kept.get(key);
197
- if (kept !== void 0) return kept;
224
+ if (kept !== void 0) return Effect.succeed(kept);
225
+ return Effect.flatMap(this.#getting.run(key, this.#get(pack, start, key)), (got) => Option.isSome(got) ? Effect.succeed(got.value) : this.block(pack, start));
226
+ });
227
+ /** `block`'s get of the block at `start`, and its keep, after a wait for its room if it was let go. */
228
+ #get = Effect.fnUntraced({ self: this }, function* (pack, start, key) {
198
229
  const length = blockLength(pack, start);
199
230
  const short = this.#kept.held + blockHeld(length) - this.#room.bytes;
200
231
  if (this.#evicted.delete(key) && short > 0 && !this.#room.grow(short)) yield* this.#room.growWithin?.(short) ?? Effect.void;
@@ -203,6 +234,7 @@ var PackBlocks = class {
203
234
  length
204
235
  });
205
236
  if (bytes?.byteLength !== length) return yield* Effect.fail(lost(`Pack ${pack.id} is missing its bytes from ${start}`));
237
+ if (this.#released) return bytes;
206
238
  this.#kept.add(key, bytes, length);
207
239
  const over = this.#kept.held - this.#room.bytes;
208
240
  if (over <= 0 || this.#room.grow(over)) return bytes;
@@ -376,47 +408,69 @@ var PackBlocks = class {
376
408
  */
377
409
  const packRun = (bucket, pack, from, to) => {
378
410
  let reader;
411
+ let opening;
412
+ let failed;
413
+ let closed = false;
379
414
  let piece = /* @__PURE__ */ new Uint8Array(0);
380
415
  let pieceAt = from;
381
416
  const missing = (at) => lost(`Pack ${pack.id} is missing its bytes from ${at}`);
382
- const open = Effect.gen(function* () {
383
- const body = yield* bucketStream(bucket, packFiles(pack.id).pack, {
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, {
384
425
  offset: from,
385
426
  length: to - from
386
- });
387
- if (body === void 0) return yield* Effect.fail(missing(from));
388
- return body.getReader();
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
+ })));
389
438
  });
390
- const cancel = (opened) => Effect.promise(() => opened.cancel().catch(() => void 0));
391
439
  /**
392
440
  * The body's next piece, or its end, its failure as `bucketTry` maps one: a closed server's, and
393
441
  * one past a call bound, stay defects. An interruption cancels the body. The read takes no signal,
394
442
  * so it adds no listener to one.
395
443
  */
396
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
+ });
397
457
  return {
398
458
  from,
399
459
  to,
400
460
  reads: (offset) => offset >= pieceAt && offset < to,
401
- read: Effect.fnUntraced(function* (offset, end) {
402
- if (offset < pieceAt || end > to) return yield* Effect.die(/* @__PURE__ */ new Error(`a run of ${from} to ${to} can't read ${offset} to ${end}`));
403
- reader ??= yield* open;
404
- while (offset >= pieceAt + piece.byteLength) {
405
- pieceAt += piece.byteLength;
406
- const next = yield* nextPiece(reader);
407
- if (next.done) return yield* Effect.fail(missing(pieceAt));
408
- const { value } = next;
409
- piece = value.buffer instanceof ArrayBuffer ? new Uint8Array(value.buffer, value.byteOffset, value.byteLength) : value.slice();
410
- }
411
- return piece.subarray(offset - pieceAt, Math.min(piece.byteLength, end - pieceAt));
412
- }),
461
+ start: Effect.asVoid(open),
462
+ read,
413
463
  close: Effect.suspend(() => {
464
+ closed = true;
414
465
  const opened = reader;
466
+ reader = void 0;
415
467
  piece = /* @__PURE__ */ new Uint8Array(0);
416
468
  return opened === void 0 ? Effect.void : cancel(opened);
417
469
  })
418
470
  };
419
471
  };
472
+ /** Bucket-scoped cache key for an immutable index file; disjoint from `PackId` (`p_...`). */
473
+ const fileCacheKey = (bucketId, key) => `file:${bucketId}:${key}`;
420
474
  /**
421
475
  * The most of the index cache's room one receive's seed may take, as a share of `room.most`: a
422
476
  * pack's entry past it is read by a load instead, so one push never fills half of what the cache can
@@ -429,9 +483,10 @@ const indexSeedShare = 1 / 2;
429
483
  */
430
484
  const seedBytes = (files) => 384 + 2 * (files.index.byteLength + files.reverse.byteLength);
431
485
  /**
432
- * The `.idx` and `.rev` of each pack a server has read, across every repo, by the pack's ID: a
433
- * pack's files never change, so one is checked once, its trailer against the index's and the
434
- * 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).
435
490
  */
436
491
  var PackIndexes = class {
437
492
  #kept = /* @__PURE__ */ new Map();
@@ -440,16 +495,25 @@ var PackIndexes = class {
440
495
  * caller alone is loaded again by a waiter, and a failed one is never kept.
441
496
  */
442
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();
443
502
  #room;
503
+ #nextBucket = 0;
444
504
  #held = 0;
445
505
  /**
446
- * `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
447
507
  * counted with `cacheEntryBytes`. A room of 0 that never grows keeps none.
448
508
  */
449
509
  constructor(room) {
450
510
  this.#room = room;
451
511
  room.watch((bytes) => this.#evictTo(bytes));
452
512
  }
513
+ /** Total bytes currently held by kept entries (each with `cacheEntryBytes`). */
514
+ get heldBytes() {
515
+ return this.#held;
516
+ }
453
517
  /**
454
518
  * `listed`'s `.idx` and `.rev`, kept or read. One load of a pack runs at a time, whoever asks:
455
519
  * the cache owns it, and every other caller waits on it, so 16 cold reads of one pack make one
@@ -466,7 +530,7 @@ var PackIndexes = class {
466
530
  bytes: listed.bytes
467
531
  };
468
532
  const kept = this.#kept.get(id);
469
- if (kept !== void 0) {
533
+ if (kept !== void 0 && kept.kind === "pack") {
470
534
  this.#kept.delete(id);
471
535
  this.#kept.set(id, kept);
472
536
  return {
@@ -482,20 +546,23 @@ var PackIndexes = class {
482
546
  #read = Effect.fnUntraced({ self: this }, function* (bucket, listed, pack) {
483
547
  const { id } = pack;
484
548
  const files = packFiles(id);
485
- const bytes = yield* readInto(bucket, files.idx, idxMostBytes(listed), `Pack ${id}'s index`);
549
+ const [bytes, trailer, reversed] = yield* Effect.all([
550
+ readInto(bucket, files.idx, idxMostBytes(listed), `Pack ${id}'s index`),
551
+ readWhole(bucket, files.pack, {
552
+ offset: listed.bytes - 20,
553
+ length: 20
554
+ }),
555
+ readInto(bucket, files.rev, revBytes(listed), `Pack ${id}'s reverse index`)
556
+ ], { concurrency: "unbounded" });
486
557
  if (bytes === void 0) return yield* Effect.fail(lost(`Pack ${id} has no index`));
487
558
  const index = yield* ownedPackIndex(bytes).pipe(Effect.mapError((error) => lost(`Pack ${id}'s index is unreadable: ${error.message}`)));
488
559
  if (index.count !== listed.objects) return yield* Effect.fail(lost(`Pack ${id}'s index lists ${index.count} objects; its row, ${listed.objects}`));
489
- const trailer = yield* readWhole(bucket, files.pack, {
490
- offset: listed.bytes - 20,
491
- length: 20
492
- });
493
560
  if (trailer === void 0 || Hex.encode(trailer) !== index.packChecksum) return yield* Effect.fail(lost(`Pack ${id}'s bytes aren't those its index lists`));
494
- const reversed = yield* readInto(bucket, files.rev, revBytes(listed), `Pack ${id}'s reverse index`);
495
561
  if (reversed === void 0) return yield* Effect.fail(lost(`Pack ${id} has no reverse index`));
496
562
  const reverse = yield* ownedPackReverse(reversed, index).pipe(Effect.mapError((error) => lost(`Pack ${id}'s reverse index is unreadable: ${error.message}`)));
497
563
  const held = 384 + bytes.buffer.byteLength + reversed.buffer.byteLength;
498
564
  this.#remember(id, {
565
+ kind: "pack",
499
566
  index,
500
567
  reverse,
501
568
  bytes: held
@@ -535,23 +602,32 @@ var PackIndexes = class {
535
602
  const over = this.#held + held - this.#room.bytes;
536
603
  if (over > 0 && !this.#room.grow(over)) return;
537
604
  this.#remember(id, {
605
+ kind: "pack",
538
606
  index: index.value,
539
607
  reverse: reverse.value,
540
608
  bytes: held
541
609
  });
542
610
  });
543
611
  /**
544
- * Lets go of pack `id`'s kept `.idx` and `.rev`, for a pack whose files were deleted. A load of it
545
- * under way when it's called keeps what it reads once it ends, so a pack is forgotten only once
546
- * 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.
547
615
  */
548
616
  forget = (id) => {
549
617
  if (!isPackId(id)) return;
550
618
  const kept = this.#kept.get(id);
551
- if (kept === void 0) return;
552
- this.#kept.delete(id);
553
- 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
+ }
554
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);
555
631
  /**
556
632
  * The `.idx` the cache keeps for pack `id`, read by no call and made the most recent, or
557
633
  * `undefined` when it keeps none: a lookup that must hold no `.idx` of its own reads one held
@@ -560,26 +636,98 @@ var PackIndexes = class {
560
636
  peek = (id) => {
561
637
  if (!isPackId(id)) return void 0;
562
638
  const kept = this.#kept.get(id);
563
- if (kept === void 0) return void 0;
639
+ if (kept === void 0 || kept.kind !== "pack") return void 0;
564
640
  this.#kept.delete(id);
565
641
  this.#kept.set(id, kept);
566
642
  return kept.index;
567
643
  };
568
644
  /**
569
- * `kept` at `id`, the most recent. One already there, which one load of a pack at a time leaves
570
- * none of, would be let go first, so `#held` is always the sum of the indexes kept: a second load
571
- * 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.
572
718
  */
573
- #remember(id, kept) {
574
- 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;
575
724
  if (displaced !== void 0) {
576
- this.#kept.delete(id);
725
+ this.#kept.delete(key);
577
726
  this.#held -= displaced.bytes;
578
727
  }
579
- this.#kept.set(id, kept);
728
+ this.#kept.set(key, kept);
580
729
  this.#held += kept.bytes;
581
- const over = this.#held - this.#room.bytes;
582
- if (over > 0 && !this.#room.grow(over)) this.#evictTo(this.#room.bytes);
730
+ if (this.#held > this.#room.bytes) this.#evictTo(this.#room.bytes);
583
731
  }
584
732
  #evictTo(bytes) {
585
733
  for (const [each, kept] of this.#kept) {
@@ -848,19 +996,19 @@ const idxMostBytes = (pack) => 1072 + 28 * pack.objects + (pack.bytes > 2 ** 31
848
996
  /** A pack's `.rev`: its header and trailer, and a position for each object. */
849
997
  const revBytes = (pack) => 52 + 4 * pack.objects;
850
998
  /**
851
- * `key`'s whole file in one array of `most` bytes, as `indexBytes` charges it, or `undefined` when
852
- * the bucket has none: each chunk is copied in as it comes, never joined after, so the file is
853
- * never held twice (#1132). One past `most` is `lost`, as `named`'s, unreadable.
999
+ * `key`'s whole file, or `range` of it, in one array of `most` bytes, as its caller charges it, or
1000
+ * `undefined` when the bucket has none: each chunk is copied in as it comes, never joined after,
1001
+ * so the bytes are never held twice (#1132). One past `most` is `lost`, as `named`'s, unreadable.
854
1002
  */
855
- const readInto = (bucket, key, most, named) => bucketDo(Effect.suspend(() => {
1003
+ const readInto = (bucket, key, most, named, range) => bucketDo(Effect.suspend(() => {
856
1004
  const bytes = new Uint8Array(most);
857
1005
  let at = 0;
858
- return bucket.read(key).pipe(Stream.runForEach((chunk) => {
1006
+ return readEach(bucket, key, range, (chunk) => {
859
1007
  if (chunk.byteLength > most - at) return Effect.fail(lost(`${named} is unreadable: it's past the ${most} bytes its objects take`));
860
1008
  bytes.set(chunk, at);
861
1009
  at += chunk.byteLength;
862
1010
  return Effect.void;
863
- }), Effect.map(() => bytes.subarray(0, at)), Effect.catchIf((error) => Predicate.isTagged(error, "NotFound"), () => Effect.succeed(void 0)));
1011
+ }).pipe(Effect.map(() => bytes.subarray(0, at)), Effect.catchIf((error) => Predicate.isTagged(error, "NotFound"), () => Effect.succeed(void 0)));
864
1012
  }));
865
1013
  /**
866
1014
  * Why a reader under `indexFloor` refused: a lookup needed a pack whose index its room let go of,
@@ -885,12 +1033,16 @@ const isIndexShort = (error) => error.cause instanceof IndexShort;
885
1033
  * against its ID.
886
1034
  */
887
1035
  const packReader = (input) => {
888
- const { store, bucket, indexes, listed, memory } = input;
889
- const blocks = new PackBlocks(bucket, memory.blocks);
890
- const { listedOnly } = input;
891
- const rows = listedOnly === true ? () => Effect.void : eachHeldRow(store, listed);
892
- const rowsSized = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowSizes(store, listed);
893
- const rowsHeaders = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowHeaders(store, listed);
1036
+ const { store, bucket, indexes, listed, memory, observe } = input;
1037
+ const blocks = input.blocks ?? new PackBlocks(bucket, memory.blocks);
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);
894
1046
  const wholeAt = packObjects(blocks, memory.cache, memory.outside);
895
1047
  const named = new Set(listed.packs.map((pack) => pack.id));
896
1048
  const kept = /* @__PURE__ */ new Map();
@@ -934,7 +1086,7 @@ const packReader = (input) => {
934
1086
  * until it fits, before the load, so the reader never holds past the floor while it reads. One
935
1087
  * the room let go of fails as `indexReloaded`, and one past `canLoad` as `indexShort`.
936
1088
  */
937
- const roomed = Effect.fnUntraced(function* (pack, { bytes: floor, canLoad }) {
1089
+ const roomed = Effect.fnUntraced(function* (pack, { bytes: floor, canLoad }, from = bucket) {
938
1090
  const known = kept.get(pack.id);
939
1091
  if (known !== void 0) {
940
1092
  kept.delete(pack.id);
@@ -950,7 +1102,7 @@ const packReader = (input) => {
950
1102
  const bytes = indexBytes(pack);
951
1103
  makeRoom(bytes, floor);
952
1104
  for (const told of loadings) told(pack.id);
953
- const loaded = yield* indexes.load(bucket, pack);
1105
+ const loaded = yield* indexes.load(from, pack);
954
1106
  const raced = kept.get(pack.id);
955
1107
  if (raced !== void 0) return raced;
956
1108
  makeRoom(bytes, floor);
@@ -1031,7 +1183,7 @@ const packReader = (input) => {
1031
1183
  scope: repoScope(listed.repo),
1032
1184
  reads: [{
1033
1185
  collection: objectCollections.leaving,
1034
- limit: leavingPageRows,
1186
+ limit: 1e3,
1035
1187
  ...page
1036
1188
  }]
1037
1189
  })).results[0] ?? [];
@@ -1041,11 +1193,11 @@ const packReader = (input) => {
1041
1193
  objects: value.objects,
1042
1194
  bytes: value.bytes
1043
1195
  })).filter(unnamed),
1044
- next: rows.length < leavingPageRows ? void 0 : rows.at(-1)?.id
1196
+ next: rows.length < 1e3 ? void 0 : rows.at(-1)?.id
1045
1197
  };
1046
1198
  });
1047
1199
  /**
1048
- * Where each of `oids` is in the listed packs, by the first pack that lists it, then in those
1200
+ * Where each of `asked`'s IDs is, each told to it once: in the listed packs, by the first pack that lists it, then in those
1049
1201
  * listed since, then in those the repo's delete let go of, a page at a time, for any not found:
1050
1202
  * each read apart, so neither collection's rows count against the other's answer. `from` says
1051
1203
  * which of them it looks in: `listed` the listed packs alone, `beyond` all but them. Each listed
@@ -1056,11 +1208,11 @@ const packReader = (input) => {
1056
1208
  * the reader's allotment before its first load, and stay charged until the allotment ends.
1057
1209
  * A pack `listed` doesn't name, listed since or leaving, is this call's alone, through the
1058
1210
  * server's cache, so a reader holds no more than its listing names. A listed pack in `skip`
1059
- * isn't looked in, its indexes never loaded: an index proves it holds none of `oids` (#522).
1211
+ * isn't looked in, its indexes never loaded: an index proves it holds none of them (#522). It
1212
+ * holds only the places still unfound, 4 bytes each, so a plan's columns are looked up as they are.
1060
1213
  */
1061
- const found = Effect.fnUntraced(function* (oids, from = "all", skip) {
1062
- const where = /* @__PURE__ */ new Map();
1063
- let left = [...new Set(oids)];
1214
+ const lookFor = Effect.fnUntraced(function* (asked, from = "all", skip) {
1215
+ let left = Uint32Array.from({ length: asked.count }, (_, at) => at);
1064
1216
  const look = Effect.fnUntraced(function* (packs, held, going = false) {
1065
1217
  for (const listedPack of packs) {
1066
1218
  if (left.length === 0) break;
@@ -1070,21 +1222,22 @@ const packReader = (input) => {
1070
1222
  const indexed = room !== void 0 ? Option.some(yield* roomed(listedPack, room)) : known === void 0 ? yield* indexes.load(bucket, listedPack).pipe(Effect.asSome, Effect.catch((error) => going && error.code === "DATA_LOSS" ? Effect.succeedNone : Effect.fail(error))) : Option.some(known);
1071
1223
  if (Option.isNone(indexed)) continue;
1072
1224
  if (room === void 0) held.set(listedPack.id, indexed.value);
1073
- left = left.filter((oid) => {
1074
- const object = indexed.value.index.find(oid);
1075
- if (object === void 0) return true;
1076
- where.set(oid, {
1225
+ let unfound = 0;
1226
+ for (const at of left) {
1227
+ const object = indexed.value.index.find(asked.oidAt(at));
1228
+ if (object === void 0) left[unfound++] = at;
1229
+ else asked.place(at, {
1077
1230
  indexed: indexed.value,
1078
1231
  offset: object.offset,
1079
1232
  crc32: object.crc32
1080
1233
  });
1081
- return false;
1082
- });
1234
+ }
1235
+ left = left.subarray(0, unfound);
1083
1236
  }
1084
1237
  });
1085
1238
  const looked = skip === void 0 ? listed.packs : listed.packs.filter((pack) => !skip.has(pack.id));
1086
1239
  yield* look(from === "beyond" ? [] : looked, kept);
1087
- if (left.length === 0 || listedOnly === true || from === "listed") return where;
1240
+ if (left.length === 0 || listedOnly === true || from === "listed") return;
1088
1241
  const unlisted = /* @__PURE__ */ new Map();
1089
1242
  yield* look(yield* listedSince(), unlisted);
1090
1243
  let after;
@@ -1094,6 +1247,16 @@ const packReader = (input) => {
1094
1247
  yield* look(page.packs, unlisted, true);
1095
1248
  after = page.next;
1096
1249
  } while (after !== void 0);
1250
+ });
1251
+ /** `lookFor` of `oids`, each once: where each found one is, by its ID. */
1252
+ const found = Effect.fnUntraced(function* (oids, from = "all", skip) {
1253
+ const unique = [...new Set(oids)];
1254
+ const where = /* @__PURE__ */ new Map();
1255
+ yield* lookFor({
1256
+ count: unique.length,
1257
+ oidAt: (at) => unique[at] ?? "",
1258
+ place: (at, entry) => where.set(unique[at] ?? "", entry)
1259
+ }, from, skip);
1097
1260
  return where;
1098
1261
  });
1099
1262
  /**
@@ -1109,12 +1272,15 @@ const packReader = (input) => {
1109
1272
  const inRows = /* @__PURE__ */ new Set();
1110
1273
  yield* rows(unpacked, (object) => {
1111
1274
  inRows.add(object.oid);
1275
+ observe?.located(object.oid, void 0);
1276
+ observe?.whole(object);
1112
1277
  return row(object);
1113
1278
  });
1114
1279
  const missing = unpacked.filter((oid) => !inRows.has(oid));
1115
1280
  if (missing.length > 0) for (const [oid, place] of yield* found(missing, "all", skip)) where.set(oid, place);
1116
1281
  const skipped = skip === void 0 ? [] : missing.filter((oid) => !where.has(oid));
1117
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);
1118
1284
  return where;
1119
1285
  });
1120
1286
  /**
@@ -1124,7 +1290,11 @@ const packReader = (input) => {
1124
1290
  */
1125
1291
  const eachOf = (skip) => Effect.fnUntraced(function* (oids, take) {
1126
1292
  const where = yield* located(oids, take, skip);
1127
- 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
+ }
1128
1298
  });
1129
1299
  /**
1130
1300
  * `each` under `indexFloor`: the listed packs' objects a pack at a time, each read whole while its
@@ -1132,16 +1302,21 @@ const packReader = (input) => {
1132
1302
  * holds, then the packs listed since and those leaving.
1133
1303
  */
1134
1304
  const eachInRoom = Effect.fnUntraced(function* (oids, take) {
1135
- 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 }));
1136
1311
  if (left.length === 0) return;
1137
1312
  const inRows = /* @__PURE__ */ new Set();
1138
1313
  yield* rows(left, (object) => {
1139
1314
  inRows.add(object.oid);
1140
- return take(object);
1315
+ return deliver(object, void 0);
1141
1316
  });
1142
1317
  const missing = left.filter((oid) => !inRows.has(oid));
1143
1318
  if (missing.length === 0) return;
1144
- 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);
1145
1320
  });
1146
1321
  const each = indexFloor === void 0 ? eachOf() : eachInRoom;
1147
1322
  /** Which of `oids` the repo holds, read whole, through `take`'s reads. */
@@ -1174,16 +1349,39 @@ const packReader = (input) => {
1174
1349
  return (yield* wholeAt.atIn(oid, lookup, offset)).bytes.byteLength;
1175
1350
  });
1176
1351
  /**
1177
- * The size of each of `oids` the repo holds, none held whole past its own read: each pack's in
1178
- * 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).
1179
1357
  */
1180
1358
  const sizesOf = (skip) => Effect.fnUntraced(function* (oids) {
1181
1359
  const sized = /* @__PURE__ */ new Map();
1182
- for (const [oid, size] of yield* rowsSized(oids)) sized.set(oid, size);
1183
- const unsized = oids.filter((oid) => !sized.has(oid));
1184
- const where = yield* found(unsized, "all", skip);
1185
- const skipped = skip === void 0 ? [] : unsized.filter((oid) => !where.has(oid));
1186
- 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
+ }
1187
1385
  for (const [oid, { indexed, offset }] of byPlace(where)) sized.set(oid, yield* sizeAt(oid, loadedLookup(indexed), offset));
1188
1386
  return sized;
1189
1387
  });
@@ -1268,16 +1466,20 @@ const packReader = (input) => {
1268
1466
  */
1269
1467
  const headers = Effect.fnUntraced(function* (oids) {
1270
1468
  const listedAt = yield* found(oids, "listed");
1469
+ if (observe !== void 0) for (const [oid, { indexed }] of listedAt) observe.located(oid, indexed.pack.id);
1271
1470
  const unpacked = oids.filter((oid) => !listedAt.has(oid));
1272
- 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);
1273
1473
  const missing = unpacked.filter((oid) => !answer.has(oid));
1274
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);
1275
1476
  const where = byPlace(new Map([...listedAt, ...later]));
1276
1477
  const known = /* @__PURE__ */ new Map();
1277
1478
  for (const [oid, { indexed, offset }] of where) {
1278
1479
  const type = yield* typeAt(indexed, offset, known);
1279
1480
  if (type === void 0) {
1280
1481
  const whole = yield* wholeAt(oid, indexed, offset);
1482
+ observe?.whole(whole);
1281
1483
  answer.set(oid, {
1282
1484
  type: whole.type,
1283
1485
  size: whole.bytes.byteLength
@@ -1354,6 +1556,71 @@ const packReader = (input) => {
1354
1556
  });
1355
1557
  return entries;
1356
1558
  });
1559
+ /**
1560
+ * `storedOf` into a plan's `columns`, for `ordinals` of them: each found where `lookFor` finds
1561
+ * it, then read in each pack's order of offsets, as `byPlace` sorts them, so a pack's headers are
1562
+ * read a neighbourhood at a time. What it holds beside the columns is each asked ordinal's pack
1563
+ * and place, 4 and 2 bytes, and the order they're read in, 4. A listed pack in `skip` isn't
1564
+ * looked in, as `found` says. Under `indexFloor`, which reads the listed packs a pack at a time,
1565
+ * it's `storedOf`'s answer set in the columns.
1566
+ */
1567
+ const storedInto = Effect.fnUntraced(function* (columns, ordinals, skip) {
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;
1570
+ if (indexFloor !== void 0 && skip === void 0) {
1571
+ const entries = yield* storedOf(Array.from(asking, (ordinal) => columns.oidAt(ordinal)));
1572
+ for (const ordinal of asking) {
1573
+ const entry = entries.get(columns.oidAt(ordinal));
1574
+ if (entry === void 0) continue;
1575
+ const { holds } = entry;
1576
+ columns.setEntry(ordinal, entry, holds.kind === "delta" ? {
1577
+ kind: "delta",
1578
+ base: columns.based(holds.base)
1579
+ } : holds);
1580
+ }
1581
+ return;
1582
+ }
1583
+ const packOf = new Uint16Array(asking.length);
1584
+ const coded = packCodes();
1585
+ const { offset, crc32 } = columns.columns;
1586
+ yield* lookFor({
1587
+ count: asking.length,
1588
+ oidAt: (at) => columns.oidAt(asking[at] ?? 0),
1589
+ place: (at, entry) => {
1590
+ const ordinal = asking[at] ?? 0;
1591
+ packOf[at] = coded.codeOf(entry.indexed, entry.indexed);
1592
+ offset[ordinal] = entry.offset;
1593
+ crc32[ordinal] = entry.crc32;
1594
+ }
1595
+ }, "all", skip);
1596
+ const placed = Uint32Array.from({ length: asking.length }, (_, at) => at).filter((at) => (packOf[at] ?? 0) !== 0);
1597
+ const idOf = (at) => coded.at(packOf[at] ?? 0)?.pack.id ?? "";
1598
+ placed.sort((a, b) => {
1599
+ const [packA, packB] = [idOf(a), idOf(b)];
1600
+ return packA === packB ? (offset[asking[a] ?? 0] ?? 0) - (offset[asking[b] ?? 0] ?? 0) : packA < packB ? -1 : 1;
1601
+ });
1602
+ for (const at of placed) {
1603
+ const ordinal = asking[at] ?? 0;
1604
+ const indexed = coded.at(packOf[at] ?? 0);
1605
+ if (indexed === void 0) continue;
1606
+ const held = columns.columns;
1607
+ const start = held.offset[ordinal] ?? 0;
1608
+ const end = entryEnd(indexed, start);
1609
+ if (end === void 0 || end <= start) return yield* Effect.fail(lost(`Pack ${indexed.pack.id}'s reverse index has no entry at ${start}`));
1610
+ const holds = yield* holdsAt(indexed, start);
1611
+ if (holds === void 0) continue;
1612
+ const entry = {
1613
+ pack: indexed.pack,
1614
+ offset: start,
1615
+ bytes: end - start,
1616
+ crc32: held.crc32[ordinal] ?? 0
1617
+ };
1618
+ columns.setEntry(ordinal, entry, holds.kind === "delta" ? {
1619
+ kind: "delta",
1620
+ base: columns.based(holds.base)
1621
+ } : holds);
1622
+ }
1623
+ });
1357
1624
  const read = (entry, at) => {
1358
1625
  const from = entry.offset + at;
1359
1626
  const start = from - from % blockBytes;
@@ -1361,11 +1628,16 @@ const packReader = (input) => {
1361
1628
  };
1362
1629
  const stored = {
1363
1630
  find: (oids) => storedOf(oids),
1631
+ into: storedInto,
1364
1632
  read,
1365
1633
  gets: (entries) => blocks.gets(entries),
1366
1634
  run: (pack, from, to) => packRun(bucket, pack, from, to),
1367
1635
  kept: (pack, offset) => blocks.keeps(pack, offset),
1368
- 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
+ }
1369
1641
  };
1370
1642
  /**
1371
1643
  * The object `oid` as `ObjectReader.read` hands it on, rows first: a whole entry past
@@ -1494,12 +1766,12 @@ const packReader = (input) => {
1494
1766
  * lookups load them, once a pack, through the server's cache, so a fetch's index path and its
1495
1767
  * walk read them once between them, and none when the cache holds them.
1496
1768
  */
1497
- const indexed = Effect.fnUntraced(function* (pack) {
1498
- 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);
1499
1771
  const known = kept.get(pack.id);
1500
1772
  if (known !== void 0) return known;
1501
1773
  yield* charge(pack);
1502
- const loaded = yield* indexes.load(bucket, pack);
1774
+ const loaded = yield* indexes.load(from, pack);
1503
1775
  kept.set(pack.id, loaded);
1504
1776
  return loaded;
1505
1777
  });
@@ -1605,11 +1877,13 @@ const packReader = (input) => {
1605
1877
  held: heldOf(take),
1606
1878
  sizes: sizesOf(covered),
1607
1879
  find: (oids) => storedOf(oids, covered),
1880
+ into: (columns, ordinals) => storedInto(columns, ordinals, covered),
1608
1881
  packed: (oids) => Effect.map(found(oids, "listed", covered), (where) => new Set(where.keys()))
1609
1882
  };
1610
1883
  };
1611
1884
  const reads = {
1612
1885
  indexed,
1886
+ cachedIndex: (pack) => kept.has(pack.id) || indexes.has(pack.id),
1613
1887
  loadedOf: (pack) => kept.get(pack.id),
1614
1888
  onLoading: (told) => {
1615
1889
  loadings.add(told);
@@ -1655,6 +1929,10 @@ const askedOf = (found, prefix, most) => {
1655
1929
  /** `reads`, each lookup by ID answering only what `visible` holds, as `PackReaderInput` says. */
1656
1930
  const narrowedTo = (reads, visible) => {
1657
1931
  const only = (oids, asked = visible) => Effect.map(asked(oids), (kept) => oids.filter((oid) => kept.has(oid)));
1932
+ const onlyOrdinals = (columns, ordinals) => {
1933
+ const asked = Array.from(ordinals);
1934
+ return Effect.map(visible(asked.map((ordinal) => columns.oidAt(ordinal))), (kept) => asked.filter((ordinal) => kept.has(columns.oidAt(ordinal))));
1935
+ };
1658
1936
  return {
1659
1937
  ...reads,
1660
1938
  held: (oids) => Effect.flatMap(only(oids), reads.held),
@@ -1666,6 +1944,7 @@ const narrowedTo = (reads, visible) => {
1666
1944
  held: (oids) => Effect.flatMap(only(oids), outside.held),
1667
1945
  sizes: (oids) => Effect.flatMap(only(oids), outside.sizes),
1668
1946
  find: (oids) => Effect.flatMap(only(oids), outside.find),
1947
+ into: (columns, ordinals) => Effect.flatMap(onlyOrdinals(columns, ordinals), (kept) => outside.into(columns, kept)),
1669
1948
  packed: (oids) => Effect.flatMap(only(oids), outside.packed)
1670
1949
  };
1671
1950
  },
@@ -1681,11 +1960,12 @@ const narrowedTo = (reads, visible) => {
1681
1960
  sizes: (oids) => Effect.flatMap(only(oids), reads.sizes),
1682
1961
  stored: {
1683
1962
  ...reads.stored,
1684
- find: (oids) => Effect.flatMap(only(oids), reads.stored.find)
1963
+ find: (oids) => Effect.flatMap(only(oids), reads.stored.find),
1964
+ into: (columns, ordinals) => Effect.flatMap(onlyOrdinals(columns, ordinals), (kept) => reads.stored.into(columns, kept))
1685
1965
  },
1686
1966
  object: (oid, signal) => Effect.flatMap(only([oid]), (kept) => kept.length === 0 ? Effect.succeed(void 0) : reads.object(oid, signal)),
1687
1967
  objects: (oids, allotment) => Effect.flatMap(only(oids), (kept) => reads.objects(kept, allotment)),
1688
1968
  wholeBlobs: (oids) => Effect.flatMap(only(oids), reads.wholeBlobs)
1689
1969
  };
1690
1970
  };
1691
- export { IndexReloaded, IndexShort, PackBlocks, PackIndexes, blockBytes, blockHeld, blocksHeld, entryEnd, hashedNowMost, hashedRunMost, headerLimits, indexBytes, indexSeedShare, isIndexReloaded, isIndexShort, loadedLookup, packIndexerLimits, packObjectBytes, packObjects, packReader, rangedLookup, readCacheBytes, 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 };