@ref0/git 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (607) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +12 -0
  2. package/dist/access/private-refs.d.mts +12 -9
  3. package/dist/access/private-refs.mjs +69 -46
  4. package/dist/auth/access-jwt.mjs +7 -7
  5. package/dist/auth/auth.d.mts +41 -0
  6. package/dist/auth/auth.mjs +39 -0
  7. package/dist/auth/authorize.mjs +57 -80
  8. package/dist/auth/bridge.mjs +30 -0
  9. package/dist/auth/fences.d.mts +22 -2
  10. package/dist/auth/fences.mjs +3 -3
  11. package/dist/auth/grants.d.mts +25 -0
  12. package/dist/auth/grants.mjs +29 -34
  13. package/dist/auth/helpers.mjs +4 -4
  14. package/dist/auth/host-function.d.mts +9 -2
  15. package/dist/auth/host-function.mjs +35 -8
  16. package/dist/auth/identify.d.mts +3 -0
  17. package/dist/auth/identify.mjs +9 -11
  18. package/dist/auth/namespaces.d.mts +3 -0
  19. package/dist/auth/policy.d.mts +57 -0
  20. package/dist/auth/policy.mjs +56 -0
  21. package/dist/auth/token-rows.mjs +6 -6
  22. package/dist/auth/token-text.mjs +16 -4
  23. package/dist/auth/tokens.d.mts +3 -0
  24. package/dist/auth/tokens.mjs +51 -13
  25. package/dist/auth.d.mts +2 -1
  26. package/dist/auth.mjs +2 -1
  27. package/dist/client/answer.mjs +49 -11
  28. package/dist/client/client.d.mts +2 -2
  29. package/dist/client/client.mjs +3 -3
  30. package/dist/client/git-http.d.mts +6 -0
  31. package/dist/client/git-http.mjs +23 -36
  32. package/dist/client/helper-node.d.mts +12 -0
  33. package/dist/client/helper-node.mjs +108 -5
  34. package/dist/client/local.mjs +94 -99
  35. package/dist/client/negotiate.mjs +10 -8
  36. package/dist/client/push-upload.d.mts +14 -0
  37. package/dist/client/push-upload.mjs +12 -12
  38. package/dist/client/remote-helper.mjs +22 -20
  39. package/dist/client/remote.mjs +28 -22
  40. package/dist/client/run-remote-helper.d.mts +40 -16
  41. package/dist/client/run-remote-helper.mjs +147 -154
  42. package/dist/client/scrub.d.mts +8 -2
  43. package/dist/client/scrub.mjs +76 -4
  44. package/dist/client/slice-push.d.mts +77 -0
  45. package/dist/client/slice-push.mjs +169 -0
  46. package/dist/client/slice-report.mjs +188 -0
  47. package/dist/client/slices.d.mts +44 -0
  48. package/dist/client/slices.mjs +131 -0
  49. package/dist/client/transport.d.mts +1 -0
  50. package/dist/client/transport.mjs +30 -26
  51. package/dist/contracts/access.d.mts +36 -9
  52. package/dist/contracts/actors.d.mts +28 -10
  53. package/dist/contracts/actors.mjs +17 -0
  54. package/dist/contracts/authorize.d.mts +77 -0
  55. package/dist/contracts/authorize.mjs +25 -0
  56. package/dist/contracts/blobs.d.mts +48 -15
  57. package/dist/contracts/blobs.mjs +30 -0
  58. package/dist/contracts/calls-spent.d.mts +1 -0
  59. package/dist/contracts/calls-spent.mjs +58 -18
  60. package/dist/contracts/client.d.mts +14 -16
  61. package/dist/contracts/commits.d.mts +558 -76
  62. package/dist/contracts/commits.mjs +147 -0
  63. package/dist/contracts/engine.d.mts +91 -55
  64. package/dist/contracts/engine.mjs +103 -0
  65. package/dist/contracts/events.d.mts +1382 -205
  66. package/dist/contracts/events.mjs +485 -0
  67. package/dist/contracts/files.d.mts +295 -50
  68. package/dist/contracts/files.mjs +100 -0
  69. package/dist/contracts/forks.d.mts +306 -25
  70. package/dist/contracts/forks.mjs +39 -0
  71. package/dist/contracts/git.d.mts +107 -0
  72. package/dist/contracts/git.mjs +23 -0
  73. package/dist/contracts/grants.d.mts +2 -2
  74. package/dist/contracts/ids.d.mts +23 -8
  75. package/dist/contracts/ids.mjs +40 -5
  76. package/dist/contracts/lfs.d.mts +9 -4
  77. package/dist/contracts/merges.d.mts +68 -16
  78. package/dist/contracts/merges.mjs +27 -0
  79. package/dist/contracts/namespaces.d.mts +14 -0
  80. package/dist/contracts/object-values.d.mts +96 -0
  81. package/dist/contracts/object-values.mjs +104 -0
  82. package/dist/contracts/objects.d.mts +323 -87
  83. package/dist/contracts/operations.d.mts +24 -16
  84. package/dist/contracts/promises.d.mts +13 -2
  85. package/dist/contracts/push-uploads.d.mts +39 -24
  86. package/dist/contracts/push-uploads.mjs +54 -0
  87. package/dist/contracts/queue.d.mts +444 -139
  88. package/dist/contracts/queue.mjs +197 -0
  89. package/dist/contracts/refs.d.mts +248 -45
  90. package/dist/contracts/refs.mjs +117 -0
  91. package/dist/contracts/repo-records.d.mts +34 -0
  92. package/dist/contracts/repo-records.mjs +18 -0
  93. package/dist/contracts/repos.d.mts +411 -58
  94. package/dist/contracts/repos.mjs +136 -0
  95. package/dist/contracts/result.d.mts +335 -69
  96. package/dist/contracts/result.mjs +350 -5
  97. package/dist/contracts/rules.d.mts +60 -48
  98. package/dist/contracts/rules.mjs +9 -0
  99. package/dist/contracts/server.d.mts +113 -47
  100. package/dist/contracts/services.d.mts +15 -24
  101. package/dist/contracts/services.mjs +5 -9
  102. package/dist/contracts/signin.d.mts +64 -31
  103. package/dist/contracts/signin.mjs +18 -0
  104. package/dist/contracts/store.d.mts +45 -5
  105. package/dist/contracts/store.mjs +31 -0
  106. package/dist/contracts/sync.d.mts +81 -46
  107. package/dist/contracts/sync.mjs +41 -2
  108. package/dist/contracts/tags.d.mts +204 -22
  109. package/dist/contracts/tags.mjs +51 -1
  110. package/dist/contracts/tokens.d.mts +32 -7
  111. package/dist/contracts/tokens.mjs +31 -1
  112. package/dist/contracts/topics.d.mts +123 -67
  113. package/dist/contracts/topics.mjs +109 -0
  114. package/dist/contracts/trees.d.mts +132 -52
  115. package/dist/contracts/trees.mjs +105 -0
  116. package/dist/contracts/work.d.mts +127 -20
  117. package/dist/contracts/work.mjs +69 -0
  118. package/dist/core/access.d.mts +25 -14
  119. package/dist/core/access.mjs +77 -108
  120. package/dist/core/ancestry.mjs +86 -18
  121. package/dist/core/call-names.mjs +1 -0
  122. package/dist/core/call-services.mjs +73 -0
  123. package/dist/core/changes.d.mts +31 -0
  124. package/dist/core/changes.mjs +5 -0
  125. package/dist/core/clock.mjs +3 -3
  126. package/dist/core/events/deliver.mjs +119 -33
  127. package/dist/core/events/seen.mjs +124 -0
  128. package/dist/core/forks.mjs +371 -159
  129. package/dist/core/hooks/order.d.mts +9 -0
  130. package/dist/core/hooks/order.mjs +25 -0
  131. package/dist/core/hooks/post-receive.mjs +13 -12
  132. package/dist/core/hooks/pre-receive.d.mts +8 -1
  133. package/dist/core/hooks/pre-receive.mjs +8 -6
  134. package/dist/core/imports.mjs +212 -0
  135. package/dist/core/index-job.mjs +131 -38
  136. package/dist/core/merge-parts.d.mts +30 -0
  137. package/dist/core/merge-parts.mjs +31 -0
  138. package/dist/core/names.mjs +4 -16
  139. package/dist/core/namespaces.d.mts +2 -0
  140. package/dist/core/objects/blobs.mjs +4 -4
  141. package/dist/core/objects/commit-writes.mjs +19 -17
  142. package/dist/core/objects/commits.mjs +12 -12
  143. package/dist/core/objects/files.mjs +10 -11
  144. package/dist/core/objects/lines.mjs +15 -32
  145. package/dist/core/objects/merges.mjs +4 -4
  146. package/dist/core/objects/objects-layer.d.mts +21 -0
  147. package/dist/core/objects/objects-layer.mjs +47 -0
  148. package/dist/core/objects/objects-namespace.d.mts +6 -0
  149. package/dist/core/objects/objects-namespace.mjs +13 -0
  150. package/dist/core/objects/objects.d.mts +49 -0
  151. package/dist/core/objects/objects.mjs +18 -0
  152. package/dist/core/objects/peel.mjs +3 -3
  153. package/dist/core/objects/reading.mjs +135 -40
  154. package/dist/core/objects/tags.mjs +7 -7
  155. package/dist/core/objects/tree-edits.mjs +40 -27
  156. package/dist/core/objects/trees.mjs +23 -18
  157. package/dist/core/objects/writing.mjs +43 -44
  158. package/dist/core/own-writes.mjs +3 -3
  159. package/dist/core/parts.d.mts +125 -0
  160. package/dist/core/parts.mjs +59 -0
  161. package/dist/core/promise.mjs +13 -9
  162. package/dist/core/publish.mjs +27 -17
  163. package/dist/core/purge.mjs +242 -0
  164. package/dist/core/push-decide.mjs +93 -28
  165. package/dist/core/push.mjs +300 -156
  166. package/dist/core/receipts.d.mts +4 -3
  167. package/dist/core/receipts.mjs +20 -12
  168. package/dist/core/ref-conflicts.mjs +70 -4
  169. package/dist/core/ref-index-job.mjs +181 -0
  170. package/dist/core/ref-index.d.mts +25 -0
  171. package/dist/core/ref-index.mjs +136 -0
  172. package/dist/core/ref-view.mjs +166 -0
  173. package/dist/core/refs.mjs +313 -95
  174. package/dist/core/repack.d.mts +10 -0
  175. package/dist/core/repack.mjs +261 -81
  176. package/dist/core/repo-info.mjs +99 -0
  177. package/dist/core/repos.mjs +114 -80
  178. package/dist/core/rules/changes.mjs +48 -20
  179. package/dist/core/rules/check.mjs +29 -22
  180. package/dist/core/rules/commit-changes.d.mts +13 -0
  181. package/dist/core/rules/commit-changes.mjs +100 -91
  182. package/dist/core/rules/context.d.mts +67 -8
  183. package/dist/core/rules/context.mjs +88 -51
  184. package/dist/core/rules/facts.mjs +1 -1
  185. package/dist/core/rules/fetch.mjs +24 -26
  186. package/dist/core/rules/files.d.mts +13 -0
  187. package/dist/core/rules/files.mjs +27 -28
  188. package/dist/core/rules/namespace.d.mts +2 -0
  189. package/dist/core/rules/patterns.mjs +29 -5
  190. package/dist/core/rules/protect.d.mts +12 -6
  191. package/dist/core/rules/protect.mjs +22 -20
  192. package/dist/core/rules/rules-layer.d.mts +17 -0
  193. package/dist/core/rules/rules-layer.mjs +26 -0
  194. package/dist/core/rules/rules.d.mts +8 -0
  195. package/dist/core/rules/rules.mjs +16 -0
  196. package/dist/core/rules/service.mjs +18 -0
  197. package/dist/core/seam.d.mts +8 -5
  198. package/dist/core/seam.mjs +19 -15
  199. package/dist/core/tokens.mjs +29 -23
  200. package/dist/core/view.d.mts +105 -6
  201. package/dist/core/view.mjs +211 -109
  202. package/dist/core/work.mjs +40 -14
  203. package/dist/effect.d.mts +3 -4
  204. package/dist/effect.mjs +2 -3
  205. package/dist/engine/allotted-xdiff.d.mts +1 -0
  206. package/dist/engine/allotted-xdiff.mjs +1 -1
  207. package/dist/engine/attributes.mjs +1 -1
  208. package/dist/engine/combined.d.mts +18 -0
  209. package/dist/engine/combined.mjs +39 -44
  210. package/dist/engine/commits.mjs +5 -4
  211. package/dist/engine/content.d.mts +3 -2
  212. package/dist/engine/content.mjs +2 -2
  213. package/dist/engine/failures.d.mts +2 -2
  214. package/dist/engine/failures.mjs +2 -9
  215. package/dist/engine/merge-base-walk.d.mts +3 -2
  216. package/dist/engine/merge-base-walk.mjs +1 -1
  217. package/dist/engine/merge-bases.mjs +3 -2
  218. package/dist/engine/merge.mjs +568 -566
  219. package/dist/engine/parts.d.mts +3 -2
  220. package/dist/engine/parts.mjs +40 -7
  221. package/dist/engine/reads.d.mts +1 -0
  222. package/dist/engine/reads.mjs +5 -5
  223. package/dist/engine/walk.mjs +23 -24
  224. package/dist/engine/xdiff.d.mts +2 -33
  225. package/dist/engine/xdiff.mjs +6 -3
  226. package/dist/event-streams/event-streams.d.mts +25 -0
  227. package/dist/event-streams/event-streams.mjs +22 -0
  228. package/dist/event-streams/namespace.d.mts +2 -0
  229. package/dist/event-streams/stream.d.mts +42 -0
  230. package/dist/{core/events → event-streams}/stream.mjs +106 -49
  231. package/dist/extend.d.mts +4 -2
  232. package/dist/http/answers.mjs +8 -4
  233. package/dist/http/bodies.mjs +84 -56
  234. package/dist/http/core-parts.mjs +206 -60
  235. package/dist/http/handler.d.mts +2 -0
  236. package/dist/http/handler.mjs +17 -11
  237. package/dist/http/node.mjs +10 -6
  238. package/dist/http/parts.d.mts +12 -0
  239. package/dist/http/push-uploads.d.mts +9 -0
  240. package/dist/http/push-uploads.mjs +76 -66
  241. package/dist/http/receive-pack.mjs +162 -28
  242. package/dist/http/upload-pack.mjs +106 -81
  243. package/dist/index.d.mts +48 -28
  244. package/dist/index.mjs +29 -7
  245. package/dist/lfs/calls.mjs +2 -2
  246. package/dist/lfs/locks.mjs +24 -20
  247. package/dist/lfs/objects.d.mts +7 -0
  248. package/dist/lfs/objects.mjs +31 -26
  249. package/dist/lfs/pointers.mjs +7 -7
  250. package/dist/lfs/purge.mjs +50 -0
  251. package/dist/lfs/repo.mjs +5 -5
  252. package/dist/lfs/rows.mjs +8 -8
  253. package/dist/lfs/service.d.mts +9 -0
  254. package/dist/lfs/service.mjs +32 -25
  255. package/dist/lfs/upkeep.mjs +5 -5
  256. package/dist/lfs/wire.mjs +80 -38
  257. package/dist/merges/merges.d.mts +20 -0
  258. package/dist/merges/merges.mjs +32 -0
  259. package/dist/merges/namespace.d.mts +2 -0
  260. package/dist/merges/public.d.mts +6 -0
  261. package/dist/merges/public.mjs +10 -0
  262. package/dist/node.d.mts +1 -2
  263. package/dist/node.mjs +1 -3
  264. package/dist/protocol/bytes/buffers.d.mts +9 -3
  265. package/dist/protocol/bytes/buffers.mjs +11 -5
  266. package/dist/protocol/bytes/deflate.d.mts +7 -5
  267. package/dist/protocol/bytes/deflate.mjs +59 -23
  268. package/dist/protocol/bytes/inflate.d.mts +4 -3
  269. package/dist/protocol/bytes/inflate.mjs +61 -26
  270. package/dist/protocol/bytes/reader.mjs +61 -0
  271. package/dist/protocol/bytes/sha1-hasher.d.mts +3 -1
  272. package/dist/protocol/bytes/sha1-hasher.mjs +13 -3
  273. package/dist/protocol/bytes/sha1.d.mts +1 -1
  274. package/dist/protocol/bytes/sha1.mjs +5 -5
  275. package/dist/protocol/bytes/streams.mjs +16 -6
  276. package/dist/protocol/diff/patch.d.mts +4 -0
  277. package/dist/protocol/diff/patch.mjs +1 -1
  278. package/dist/protocol/diff/paths.mjs +1 -1
  279. package/dist/protocol/diff/read.d.mts +1 -1
  280. package/dist/protocol/diff/read.mjs +102 -90
  281. package/dist/protocol/framing/pkt-line.d.mts +1 -0
  282. package/dist/protocol/framing/pkt-line.mjs +40 -6
  283. package/dist/protocol/objects/checked-blobs.d.mts +1 -0
  284. package/dist/protocol/objects/fsck.mjs +7 -1
  285. package/dist/protocol/objects/held.mjs +5 -11
  286. package/dist/protocol/objects/ident.mjs +1 -1
  287. package/dist/protocol/objects/object-rules.mjs +15 -7
  288. package/dist/protocol/objects/object.d.mts +6 -2
  289. package/dist/protocol/objects/object.mjs +5 -2
  290. package/dist/protocol/objects/tag.d.mts +3 -1
  291. package/dist/protocol/objects/tag.mjs +27 -1
  292. package/dist/protocol/objects/tree.mjs +1 -1
  293. package/dist/protocol/packs/delta.d.mts +1 -1
  294. package/dist/protocol/packs/delta.mjs +2 -2
  295. package/dist/protocol/packs/graph.mjs +55 -56
  296. package/dist/protocol/packs/idx.d.mts +4 -2
  297. package/dist/protocol/packs/idx.mjs +156 -63
  298. package/dist/protocol/packs/indexer.d.mts +22 -4
  299. package/dist/protocol/packs/indexer.mjs +14 -35
  300. package/dist/protocol/packs/parts.mjs +5 -5
  301. package/dist/protocol/packs/pos.mjs +12 -5
  302. package/dist/protocol/packs/reader.d.mts +19 -12
  303. package/dist/protocol/packs/reader.mjs +252 -25
  304. package/dist/protocol/packs/rev.d.mts +1 -1
  305. package/dist/protocol/packs/rev.mjs +42 -24
  306. package/dist/protocol/packs/types-file.mjs +85 -0
  307. package/dist/protocol/packs/write-error.d.mts +1 -1
  308. package/dist/protocol/packs/write-error.mjs +2 -2
  309. package/dist/protocol/packs/writer.d.mts +40 -15
  310. package/dist/protocol/packs/writer.mjs +142 -49
  311. package/dist/protocol/wire/advertisement.d.mts +39 -14
  312. package/dist/protocol/wire/advertisement.mjs +127 -31
  313. package/dist/protocol/wire/fetch.d.mts +57 -19
  314. package/dist/protocol/wire/fetch.mjs +57 -26
  315. package/dist/protocol/wire/json.mjs +25 -0
  316. package/dist/protocol/wire/lines.d.mts +10 -0
  317. package/dist/protocol/wire/lines.mjs +20 -6
  318. package/dist/protocol/wire/push-limits.d.mts +6 -0
  319. package/dist/protocol/wire/push-limits.mjs +88 -0
  320. package/dist/protocol/wire/push-uploads.mjs +3 -28
  321. package/dist/protocol/wire/receive-pack.d.mts +30 -14
  322. package/dist/protocol/wire/receive-pack.mjs +29 -2
  323. package/dist/protocol/wire/report-status.d.mts +30 -11
  324. package/dist/protocol/wire/report-status.mjs +21 -2
  325. package/dist/protocol/wire/v2.d.mts +56 -29
  326. package/dist/protocol/wire/v2.mjs +91 -16
  327. package/dist/protocol.d.mts +4 -3
  328. package/dist/protocol.mjs +7 -6
  329. package/dist/queue/advance.mjs +189 -120
  330. package/dist/queue/callers.mjs +12 -9
  331. package/dist/queue/calls.mjs +311 -155
  332. package/dist/queue/commit.mjs +70 -26
  333. package/dist/queue/host.d.mts +39 -12
  334. package/dist/queue/host.mjs +36 -38
  335. package/dist/queue/lanes.mjs +1 -1
  336. package/dist/queue/layer.d.mts +14 -0
  337. package/dist/queue/layer.mjs +55 -0
  338. package/dist/queue/limits.mjs +13 -2
  339. package/dist/queue/namespace.d.mts +2 -0
  340. package/dist/queue/pages.mjs +1 -1
  341. package/dist/queue/public.d.mts +6 -0
  342. package/dist/queue/public.mjs +21 -0
  343. package/dist/queue/push-option.mjs +49 -30
  344. package/dist/queue/rows.mjs +24 -16
  345. package/dist/queue/schedule.mjs +22 -22
  346. package/dist/queue/search.mjs +8 -7
  347. package/dist/queue/state.mjs +49 -13
  348. package/dist/queue/steps.mjs +6 -3
  349. package/dist/remote-helper.d.mts +5 -2
  350. package/dist/remote-helper.mjs +5 -2
  351. package/dist/rest/api.d.mts +1 -1
  352. package/dist/rest/blobs.d.mts +790 -23
  353. package/dist/rest/blobs.mjs +4 -4
  354. package/dist/rest/caller.d.mts +4163 -36
  355. package/dist/rest/caller.mjs +2 -2
  356. package/dist/rest/client.mjs +80 -70
  357. package/dist/rest/commits.d.mts +3315 -244
  358. package/dist/rest/commits.mjs +18 -64
  359. package/dist/rest/errors.d.mts +2082 -22
  360. package/dist/rest/errors.mjs +46 -89
  361. package/dist/rest/events.d.mts +394 -11
  362. package/dist/rest/events.mjs +13 -9
  363. package/dist/rest/files.d.mts +1265 -114
  364. package/dist/rest/files.mjs +11 -42
  365. package/dist/rest/forks.d.mts +2005 -62
  366. package/dist/rest/forks.mjs +10 -13
  367. package/dist/rest/handler.d.mts +3 -0
  368. package/dist/rest/handler.mjs +22 -14
  369. package/dist/rest/handlers.mjs +53 -60
  370. package/dist/rest/listen.d.mts +5 -8
  371. package/dist/rest/listen.mjs +23 -29
  372. package/dist/rest/me.d.mts +393 -10
  373. package/dist/rest/me.mjs +2 -2
  374. package/dist/rest/merges.d.mts +399 -16
  375. package/dist/rest/merges.mjs +3 -17
  376. package/dist/rest/paths.mjs +1 -0
  377. package/dist/rest/queue.d.mts +5615 -240
  378. package/dist/rest/queue.mjs +15 -130
  379. package/dist/rest/refs.d.mts +2859 -132
  380. package/dist/rest/refs.mjs +19 -39
  381. package/dist/rest/repos.d.mts +2421 -93
  382. package/dist/rest/repos.mjs +10 -33
  383. package/dist/rest/tags.d.mts +1205 -54
  384. package/dist/rest/tags.mjs +6 -34
  385. package/dist/rest/tokens.d.mts +2369 -66
  386. package/dist/rest/tokens.mjs +7 -4
  387. package/dist/rest/topics.d.mts +2060 -113
  388. package/dist/rest/topics.mjs +23 -71
  389. package/dist/rest/trees.d.mts +1610 -75
  390. package/dist/rest/trees.mjs +16 -57
  391. package/dist/rest/wire.d.mts +402 -0
  392. package/dist/rest/wire.mjs +32 -46
  393. package/dist/rest/work.d.mts +1204 -63
  394. package/dist/rest/work.mjs +7 -51
  395. package/dist/rest.d.mts +3 -3
  396. package/dist/server/extension.d.mts +6 -2
  397. package/dist/server/extension.mjs +54 -30
  398. package/dist/server/git-layer.d.mts +23 -0
  399. package/dist/server/git-layer.mjs +107 -0
  400. package/dist/server/git-namespace.d.mts +6 -0
  401. package/dist/server/git-namespace.mjs +15 -0
  402. package/dist/server/lifecycle.d.mts +1 -2
  403. package/dist/server/lifecycle.mjs +8 -15
  404. package/dist/server/namespaces.d.mts +2 -0
  405. package/dist/server/registry.d.mts +9 -0
  406. package/dist/server/registry.mjs +167 -0
  407. package/dist/server/route-match.mjs +88 -0
  408. package/dist/server/routes.d.mts +12 -8
  409. package/dist/server/routes.mjs +27 -18
  410. package/dist/server/server.d.mts +19 -0
  411. package/dist/server/server.mjs +281 -198
  412. package/dist/signin/codes.mjs +9 -6
  413. package/dist/signin/context.d.mts +1 -0
  414. package/dist/signin/context.mjs +4 -4
  415. package/dist/signin/device.mjs +8 -8
  416. package/dist/signin/forms.mjs +11 -29
  417. package/dist/signin/grants.d.mts +4 -2
  418. package/dist/signin/grants.mjs +20 -19
  419. package/dist/signin/route.mjs +2 -2
  420. package/dist/signin/web.mjs +7 -7
  421. package/dist/signin/wire.mjs +6 -6
  422. package/dist/storage/budget.mjs +51 -18
  423. package/dist/storage/calls.d.mts +22 -4
  424. package/dist/storage/calls.mjs +347 -110
  425. package/dist/storage/clean-up.mjs +80 -35
  426. package/dist/storage/counted-bucket.mjs +115 -0
  427. package/dist/storage/fetch.d.mts +2 -0
  428. package/dist/storage/fetch.mjs +243 -100
  429. package/dist/storage/fsck.mjs +56 -7
  430. package/dist/storage/held-types.d.mts +7 -0
  431. package/dist/storage/held-types.mjs +263 -0
  432. package/dist/storage/host-bucket.mjs +28 -0
  433. package/dist/storage/id-mix.d.mts +1 -0
  434. package/dist/storage/id-mix.mjs +55 -0
  435. package/dist/storage/index-bitmaps.d.mts +2 -1
  436. package/dist/storage/index-bitmaps.mjs +233 -101
  437. package/dist/storage/index-build.d.mts +7 -3
  438. package/dist/storage/index-build.mjs +650 -164
  439. package/dist/storage/index-fetch.d.mts +3 -1
  440. package/dist/storage/index-fetch.mjs +297 -195
  441. package/dist/storage/index-files.mjs +25 -27
  442. package/dist/storage/index-graph.d.mts +2 -1
  443. package/dist/storage/index-graph.mjs +127 -91
  444. package/dist/storage/index-layers.d.mts +11 -0
  445. package/dist/storage/index-layers.mjs +258 -78
  446. package/dist/storage/index-reach.mjs +181 -75
  447. package/dist/storage/index-remap.mjs +74 -32
  448. package/dist/storage/index-shallow.mjs +311 -0
  449. package/dist/storage/index-visible.mjs +168 -0
  450. package/dist/storage/layout.d.mts +1 -0
  451. package/dist/storage/layout.mjs +39 -8
  452. package/dist/storage/lfs-pointers.d.mts +3 -1
  453. package/dist/storage/lfs-pointers.mjs +25 -9
  454. package/dist/storage/link-join.d.mts +4 -0
  455. package/dist/storage/link-join.mjs +50 -12
  456. package/dist/storage/links.mjs +89 -4
  457. package/dist/storage/listed-ids.mjs +10 -0
  458. package/dist/storage/loose.d.mts +11 -4
  459. package/dist/storage/loose.mjs +102 -69
  460. package/dist/storage/memory-budget.d.mts +5 -0
  461. package/dist/storage/memory-budget.mjs +530 -102
  462. package/dist/storage/merge-choose.mjs +258 -0
  463. package/dist/storage/merge-cut.mjs +47 -0
  464. package/dist/storage/merge-fence.mjs +89 -0
  465. package/dist/storage/merge-index.mjs +347 -0
  466. package/dist/storage/merge-most.mjs +202 -0
  467. package/dist/storage/merge-plan.mjs +171 -0
  468. package/dist/storage/merge-row.mjs +258 -0
  469. package/dist/storage/merge-stream.mjs +497 -0
  470. package/dist/storage/merge-walk.mjs +199 -0
  471. package/dist/storage/merge-write.mjs +129 -0
  472. package/dist/storage/merge.d.mts +10 -0
  473. package/dist/storage/merge.mjs +82 -306
  474. package/dist/storage/object-rows.d.mts +4 -2
  475. package/dist/storage/object-rows.mjs +101 -17
  476. package/dist/storage/pack-order.d.mts +1 -1
  477. package/dist/storage/pack-order.mjs +69 -54
  478. package/dist/storage/pack-ranges.d.mts +1 -1
  479. package/dist/storage/pack-ranges.mjs +396 -60
  480. package/dist/storage/pack-reads.d.mts +6 -2
  481. package/dist/storage/pack-reads.mjs +598 -126
  482. package/dist/storage/pack-receive.d.mts +5 -0
  483. package/dist/storage/pack-receive.mjs +820 -237
  484. package/dist/storage/packs-memory.d.mts +25 -0
  485. package/dist/storage/packs-memory.mjs +49 -0
  486. package/dist/storage/packs.d.mts +7 -5
  487. package/dist/storage/packs.mjs +554 -213
  488. package/dist/storage/placed-reads.mjs +205 -0
  489. package/dist/storage/promise-calls.mjs +29 -0
  490. package/dist/storage/prune-keep.mjs +164 -0
  491. package/dist/storage/prune-walk.mjs +578 -0
  492. package/dist/storage/prune.mjs +739 -332
  493. package/dist/storage/push-allotment.mjs +3 -3
  494. package/dist/storage/push-uploads.mjs +22 -13
  495. package/dist/storage/pushed-commits.mjs +8 -9
  496. package/dist/storage/quarantine.d.mts +10 -0
  497. package/dist/storage/quarantine.mjs +28 -25
  498. package/dist/storage/range-cache.mjs +71 -0
  499. package/dist/storage/raw-ids.mjs +20 -1
  500. package/dist/storage/ready.d.mts +4 -2
  501. package/dist/storage/ready.mjs +109 -48
  502. package/dist/storage/receive-admission.mjs +67 -0
  503. package/dist/storage/receive-bounds.d.mts +1 -0
  504. package/dist/storage/receive-bounds.mjs +202 -0
  505. package/dist/storage/receive-files.mjs +248 -0
  506. package/dist/storage/receive-links.mjs +281 -244
  507. package/dist/storage/receive-state.d.mts +9 -0
  508. package/dist/storage/receive-state.mjs +150 -0
  509. package/dist/storage/receive-steps.mjs +344 -0
  510. package/dist/storage/receive-sweep.mjs +160 -0
  511. package/dist/storage/receive-table.d.mts +3 -0
  512. package/dist/storage/receive-table.mjs +197 -0
  513. package/dist/storage/repack-backlog.mjs +70 -0
  514. package/dist/storage/repack-contained.mjs +269 -0
  515. package/dist/storage/repack-job.d.mts +3 -0
  516. package/dist/storage/repack-job.mjs +24 -7
  517. package/dist/storage/repack.d.mts +4 -4
  518. package/dist/storage/repack.mjs +156 -77
  519. package/dist/storage/roots.mjs +23 -7
  520. package/dist/storage/rows.d.mts +4 -2
  521. package/dist/storage/rows.mjs +40 -7
  522. package/dist/storage/runs.d.mts +8 -0
  523. package/dist/storage/runs.mjs +731 -0
  524. package/dist/storage/send-list.d.mts +2 -1
  525. package/dist/storage/send-list.mjs +261 -76
  526. package/dist/storage/shallow.d.mts +3 -2
  527. package/dist/storage/shallow.mjs +7 -7
  528. package/dist/storage/single-flight.mjs +47 -0
  529. package/dist/storage/stream-whole.mjs +121 -54
  530. package/dist/storage/swap-walk.mjs +188 -0
  531. package/dist/storage/unpack.mjs +52 -23
  532. package/dist/storage/visible.mjs +58 -39
  533. package/dist/storage/walk.d.mts +2 -0
  534. package/dist/storage/walk.mjs +20 -7
  535. package/dist/storage/wants.mjs +185 -33
  536. package/dist/storage/written-bases.mjs +172 -0
  537. package/dist/store/call-count.d.mts +69 -4
  538. package/dist/store/call-count.mjs +193 -51
  539. package/dist/store/catalogue.d.mts +17 -3
  540. package/dist/store/catalogue.mjs +135 -48
  541. package/dist/store/crossing.mjs +2 -4
  542. package/dist/store/cursor-seal.d.mts +12 -1
  543. package/dist/store/cursor-seal.mjs +7 -6
  544. package/dist/store/errors.d.mts +2 -2
  545. package/dist/store/errors.mjs +112 -24
  546. package/dist/store/git-store.mjs +21 -2
  547. package/dist/store/list-job.mjs +5 -5
  548. package/dist/store/outbox.d.mts +15 -5
  549. package/dist/store/outbox.mjs +106 -28
  550. package/dist/store/promises.d.mts +3 -2
  551. package/dist/store/promises.mjs +94 -35
  552. package/dist/store/queue-jobs.mjs +12 -12
  553. package/dist/store/records.d.mts +64 -1
  554. package/dist/store/records.mjs +101 -32
  555. package/dist/store/ref-rows.d.mts +18 -2
  556. package/dist/store/ref-rows.mjs +62 -5
  557. package/dist/store/repo-record.mjs +11 -9
  558. package/dist/store/reservations.mjs +9 -8
  559. package/dist/store/scopes.mjs +13 -1
  560. package/dist/store/settle.mjs +1 -1
  561. package/dist/store/topic-jobs.mjs +4 -4
  562. package/dist/sync/bound.d.mts +5 -3
  563. package/dist/sync/bound.mjs +32 -3
  564. package/dist/sync/github.mjs +7 -7
  565. package/dist/sync/import.d.mts +2 -0
  566. package/dist/sync/import.mjs +46 -50
  567. package/dist/sync/jobs.mjs +15 -23
  568. package/dist/sync/mirror.d.mts +5 -1
  569. package/dist/sync/mirror.mjs +121 -44
  570. package/dist/sync/publish.d.mts +1 -0
  571. package/dist/sync/publish.mjs +10 -12
  572. package/dist/sync/step.mjs +439 -71
  573. package/dist/sync/tries.mjs +50 -32
  574. package/dist/sync.d.mts +3 -3
  575. package/dist/sync.mjs +2 -2
  576. package/dist/topics/advance.mjs +103 -86
  577. package/dist/topics/calls.mjs +97 -67
  578. package/dist/topics/directory.mjs +31 -11
  579. package/dist/topics/host.d.mts +0 -1
  580. package/dist/topics/host.mjs +2 -12
  581. package/dist/topics/members.mjs +30 -24
  582. package/dist/topics/rows.mjs +10 -9
  583. package/dist/topics/topic.mjs +20 -9
  584. package/package.json +8 -15
  585. package/dist/auth/authorize.d.mts +0 -5
  586. package/dist/contracts/objects.mjs +0 -54
  587. package/dist/core/events/stream.d.mts +0 -19
  588. package/dist/core/rules/define.d.mts +0 -5
  589. package/dist/core/rules/define.mjs +0 -13
  590. package/dist/core/rules/fetch.d.mts +0 -5
  591. package/dist/core/sight.mjs +0 -99
  592. package/dist/engine/engine.d.mts +0 -25
  593. package/dist/engine/engine.mjs +0 -49
  594. package/dist/engine/xdiff/NOTICE.md +0 -63
  595. package/dist/engine/xdiff/compiled.d.mts +0 -7
  596. package/dist/engine/xdiff/compiled.mjs +0 -9
  597. package/dist/engine/xdiff/embedded.mjs +0 -4
  598. package/dist/engine/xdiff/node.d.mts +0 -7
  599. package/dist/engine/xdiff/node.mjs +0 -10
  600. package/dist/engine/xdiff/upstream/LGPL-2.1 +0 -511
  601. package/dist/engine/xdiff/xdiff.wasm +0 -0
  602. package/dist/engine.d.mts +0 -3
  603. package/dist/engine.mjs +0 -3
  604. package/dist/storage/distinct-ids.mjs +0 -39
  605. package/dist/storage/held-memo.mjs +0 -188
  606. package/dist/storage/index-remap.d.mts +0 -8
  607. package/dist/sync/records.mjs +0 -73
@@ -1,28 +1,33 @@
1
+ import { gitError, isGitError } from "../contracts/result.mjs";
1
2
  import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
2
3
  import { hexOf } from "../protocol/bytes/hex.mjs";
3
4
  import { Sha1 } from "../protocol/bytes/sha1.mjs";
4
5
  import { sha1Now } from "../protocol/bytes/sha1-hasher.mjs";
5
6
  import { objectHeader, objectId } from "../protocol/objects/object.mjs";
6
7
  import { DeltaError, deltaResultSize } from "../protocol/packs/delta.mjs";
7
- import { readPackIndex } from "../protocol/packs/idx.mjs";
8
- import { readPackReverse } from "../protocol/packs/rev.mjs";
9
- import { IndexerCache, PackIndexer, fixedRoom, readEntryAt } from "../protocol/packs/indexer.mjs";
8
+ import { oidBytes, ownedPackIndex, readPackIndex } from "../protocol/packs/idx.mjs";
9
+ import { ownedPackReverse, readPackReverse } from "../protocol/packs/rev.mjs";
10
+ import { IndexerCache, PackIndexer } from "../protocol/packs/indexer.mjs";
10
11
  import { stepEffect } from "../protocol/packs/step.mjs";
11
- import { PackError, packReadBytes, readEntryHeader, readPackFrom } from "../protocol/packs/reader.mjs";
12
+ import { PackError, openEntryReader, packReadBytes, readEntryHeader, readPackFrom } from "../protocol/packs/reader.mjs";
12
13
  import { callScope } from "../store/call-count.mjs";
13
14
  import { forkIn, noCall, runIn } from "../store/crossing.mjs";
14
- import { gitError } from "../store/errors.mjs";
15
15
  import { decodePacks } from "../store/git-store.mjs";
16
16
  import { collections, repoScope } from "../store/scopes.mjs";
17
- import { bucketCall } from "./calls.mjs";
17
+ import { bucketDo, bucketStream, bucketTry, readWhole } from "./calls.mjs";
18
18
  import { isPackId, objectCollections, packFiles } from "./layout.mjs";
19
- import { eachHeldRow, gitObjectOf, rowHeaders, rowSizes } from "./object-rows.mjs";
19
+ import { idsStartingWith, openRanges, rankOf } from "./pack-ranges.mjs";
20
+ import { eachHeldRow, gitObjectOf, rowHeaders, rowSizes, rowsStartingWith, startingOf } from "./object-rows.mjs";
20
21
  import { LeavingRow, decodeHeld } from "./rows.mjs";
22
+ import { SingleFlight } from "./single-flight.mjs";
21
23
  import { allotted, keptOrLeft } from "./allotted.mjs";
22
24
  import * as Effect from "effect/Effect";
23
- import * as Option from "effect/Option";
24
- import * as Cause from "effect/Cause";
25
+ import * as Predicate from "effect/Predicate";
25
26
  import * as Hex from "effect/encoding/Hex";
27
+ import * as Result from "effect/Result";
28
+ import * as Cause from "effect/Cause";
29
+ import * as Option from "effect/Option";
30
+ import * as Stream from "effect/Stream";
26
31
  import * as Fiber from "effect/Fiber";
27
32
  // src/storage/pack-reads.ts
28
33
  /** The largest object `packs()` reads whole: a file past it is stored and sent as it is. */
@@ -57,16 +62,20 @@ const blockBytes = 1048576;
57
62
  /** What a block takes as a cache counts it: its bytes and its entry's overhead. */
58
63
  const blockHeld = (bytes) => bytes + 384;
59
64
  /**
65
+ * What `count` blocks take as a cache counts them, of a pack of `length` bytes when it's shorter:
66
+ * each block's `blockHeld`, so a floor of `count` blocks keeps that many, its entries included.
67
+ */
68
+ const blocksHeld = (count, length = count * blockBytes) => {
69
+ let held = 0;
70
+ for (let at = 0; at < count * 1048576 && at < length; at += blockBytes) held += blockHeld(Math.min(blockBytes, length - at));
71
+ return held;
72
+ };
73
+ /**
60
74
  * The `leaving` rows a read takes at a time, while it still looks for objects: each is small, so a
61
75
  * page stays far below a store's answer limit.
62
76
  */
63
77
  const leavingPageRows = 1e3;
64
78
  const lost = (message) => gitError("DATA_LOSS", message);
65
- /** The whole of a file, or `undefined` when the bucket has none. */
66
- const readWhole = (bucket, key, range) => bucketCall(async (signal) => {
67
- const body = await bucket.read(key, range, { signal });
68
- return body === void 0 ? void 0 : new Uint8Array(await new Response(body).arrayBuffer());
69
- });
70
79
  /**
71
80
  * Blocks kept by key, each counted with `blockHeld`, the least recently used let go first: the one
72
81
  * rule `PackBlocks` keeps them by, and its forecast replays.
@@ -74,6 +83,10 @@ const readWhole = (bucket, key, range) => bucketCall(async (signal) => {
74
83
  var KeptBlocks = class {
75
84
  #kept = /* @__PURE__ */ new Map();
76
85
  held = 0;
86
+ /** Whether the block at `key` is kept, its recency left as it is. */
87
+ has(key) {
88
+ return this.#kept.has(key);
89
+ }
77
90
  /** The block at `key`, made the most recent, or `undefined`. */
78
91
  get(key) {
79
92
  const kept = this.#kept.get(key);
@@ -99,14 +112,18 @@ var KeptBlocks = class {
99
112
  });
100
113
  this.held += bytes;
101
114
  }
102
- evictTo(bytes) {
115
+ /** Lets the least recent go until it holds `bytes`, telling `evicted` each key it let go. */
116
+ evictTo(bytes, evicted) {
103
117
  for (const [key, each] of this.#kept) {
104
118
  if (this.held <= bytes) break;
105
119
  this.#kept.delete(key);
106
120
  this.held -= each.bytes;
121
+ evicted?.(key);
107
122
  }
108
123
  }
109
124
  };
125
+ /** The keys of blocks a reader let go that it remembers, to know a read of one again (#1197). */
126
+ const evictedKept = 64;
110
127
  /** A block's key, by its pack and the offset it starts at. */
111
128
  const blockKey = (pack, start) => `${pack.id}@${start}`;
112
129
  /** The length of the block at `start`: `blockBytes`, or less at the pack's end. */
@@ -120,17 +137,67 @@ var PackBlocks = class {
120
137
  #bucket;
121
138
  #room;
122
139
  #kept = new KeptBlocks();
140
+ /** `headIn`'s bytes across a blocks' edge, filled again by its next such read. */
141
+ #head = /* @__PURE__ */ new Uint8Array(64);
142
+ /** Bounded meter for this instance's reused entry reader: inflater, 64 KiB output and header. */
143
+ #entryMeter = new BufferMeter(entryReaderBytes);
144
+ #entryReader;
145
+ #entryReaderInUse = false;
146
+ #closeReaderOnFinish = false;
147
+ /** The last `evictedKept` blocks it let go, oldest first. */
148
+ #evicted = /* @__PURE__ */ new Set();
149
+ #forget = (key) => {
150
+ this.#evicted.add(key);
151
+ for (const oldest of this.#evicted) {
152
+ if (this.#evicted.size <= evictedKept) break;
153
+ this.#evicted.delete(oldest);
154
+ }
155
+ };
123
156
  /** `room`: what it may keep, each block counted with `blockHeld`. */
124
157
  constructor(bucket, room) {
125
158
  this.#bucket = bucket;
126
159
  this.#room = room;
127
- room.watch((bytes) => this.#kept.evictTo(bytes));
160
+ room.watch((bytes) => {
161
+ this.#kept.evictTo(bytes, this.#forget);
162
+ if (this.#entryReaderInUse) this.#closeReaderOnFinish = true;
163
+ else this.#releaseEntryReader();
164
+ });
165
+ }
166
+ /** Releases the reused entry reader's inflater, buffers and meter allotments once idle. */
167
+ close() {
168
+ if (this.#entryReaderInUse) {
169
+ this.#closeReaderOnFinish = true;
170
+ return;
171
+ }
172
+ this.#releaseEntryReader();
173
+ }
174
+ /** Bytes currently held on this instance's entry-reader meter (for memory verification). */
175
+ get entryReaderHeld() {
176
+ return this.#entryMeter.held;
177
+ }
178
+ /** Peak bytes held on this instance's entry-reader meter (for memory verification). */
179
+ get entryReaderMost() {
180
+ return this.#entryMeter.most;
181
+ }
182
+ #releaseEntryReader() {
183
+ this.#closeReaderOnFinish = false;
184
+ this.#entryReader?.close();
185
+ this.#entryReader = void 0;
128
186
  }
129
- block = (pack, start) => Effect.gen({ self: this }, function* () {
187
+ /**
188
+ * The block at `start`, kept or read. One it let go and reads again first waits for its room to
189
+ * grow by it, before its get, where the room waits: so a reader whose blocks rotate past a floor
190
+ * that a live operation's caches hold it to waits for that operation, and is refused its busy,
191
+ * spending no get, rather than reading the same blocks until its calls run out (#1197). A first
192
+ * read never waits: one that doesn't fit evicts, so a reader streaming through a pack goes on.
193
+ */
194
+ block = Effect.fnUntraced({ self: this }, function* (pack, start) {
130
195
  const key = blockKey(pack, start);
131
196
  const kept = this.#kept.get(key);
132
197
  if (kept !== void 0) return kept;
133
198
  const length = blockLength(pack, start);
199
+ const short = this.#kept.held + blockHeld(length) - this.#room.bytes;
200
+ if (this.#evicted.delete(key) && short > 0 && !this.#room.grow(short)) yield* this.#room.growWithin?.(short) ?? Effect.void;
134
201
  const bytes = yield* readWhole(this.#bucket, packFiles(pack.id).pack, {
135
202
  offset: start,
136
203
  length
@@ -139,9 +206,13 @@ var PackBlocks = class {
139
206
  this.#kept.add(key, bytes, length);
140
207
  const over = this.#kept.held - this.#room.bytes;
141
208
  if (over <= 0 || this.#room.grow(over)) return bytes;
142
- this.#kept.evictTo(this.#room.bytes);
209
+ this.#kept.evictTo(this.#room.bytes, this.#forget);
143
210
  return bytes;
144
211
  });
212
+ /** Whether the block holding `pack`'s byte at `offset` is kept now, so reading it takes no get. */
213
+ keeps(pack, offset) {
214
+ return this.#kept.has(blockKey(pack, offset - offset % blockBytes));
215
+ }
145
216
  /**
146
217
  * The bucket gets reading each of `entries`' bytes in turn would take, with no I/O: their blocks
147
218
  * replayed through `KeptBlocks`, in a room left at its floor, which a shrink may leave it at any
@@ -174,9 +245,39 @@ var PackBlocks = class {
174
245
  }) };
175
246
  }
176
247
  /** Up to `headerBytesMost` bytes of the pack from `offset`, across a neighbourhood's end. */
177
- headAt = (pack, offset) => Effect.gen({ self: this }, function* () {
248
+ headAt = (pack, offset) => this.#fill(pack, offset, new Uint8Array(Math.min(64, pack.bytes - offset)));
249
+ /**
250
+ * `headAt`'s bytes, borrowed for a serial walk (#1678), which reads its `headerBytesMost` at most
251
+ * before its next read: a view of the kept block holding them, or else this reader's own scratch,
252
+ * filled across the blocks' edge again by its next such read. At once when its block is kept.
253
+ */
254
+ headIn(pack, offset) {
178
255
  const length = Math.min(64, pack.bytes - offset);
179
- const head = new Uint8Array(length);
256
+ const start = offset - offset % blockBytes;
257
+ if (offset + length > start + 1048576) return this.#fill(pack, offset, this.#head.subarray(0, length));
258
+ const block = this.#blockStep(pack, start);
259
+ return Effect.isEffect(block) ? Effect.map(block, (bytes) => bytes.subarray(offset - start, offset - start + length)) : block.subarray(offset - start, offset - start + length);
260
+ }
261
+ /**
262
+ * `[from, to)` of the pack, each block's piece handed to `each` as the kept block, where in it the
263
+ * piece starts and its length, borrowed until `each` answers: the blocks `sourceAt` reads, in its
264
+ * order, at once while each is kept.
265
+ */
266
+ spans(pack, from, to, each) {
267
+ for (let at = from; at < to;) {
268
+ const start = at - at % blockBytes;
269
+ const block = this.#blockStep(pack, start);
270
+ const here = at;
271
+ const end = Math.min(start + blockBytes, to);
272
+ const piece = (bytes) => each(bytes, here - start, end - here);
273
+ const handed = Effect.isEffect(block) ? Effect.flatMap(block, (bytes) => stepEffect(piece(bytes))) : piece(block);
274
+ if (Effect.isEffect(handed)) return Effect.flatMap(handed, () => stepEffect(this.spans(pack, end, to, each)));
275
+ at = end;
276
+ }
277
+ }
278
+ /** `head` filled with the pack's bytes from `offset`, across a neighbourhood's end. */
279
+ #fill = Effect.fnUntraced({ self: this }, function* (pack, offset, head) {
280
+ const length = head.byteLength;
180
281
  for (let at = 0; at < length;) {
181
282
  const start = offset + at - (offset + at) % blockBytes;
182
283
  const piece = (yield* this.block(pack, start)).subarray(offset + at - start, offset + length - start);
@@ -185,19 +286,160 @@ var PackBlocks = class {
185
286
  }
186
287
  return head;
187
288
  });
289
+ #blockStep(pack, start) {
290
+ const kept = this.#kept.get(blockKey(pack, start));
291
+ if (kept !== void 0) return kept;
292
+ return this.block(pack, start);
293
+ }
294
+ #stepSourceAt(pack, offset) {
295
+ let next = offset;
296
+ return () => {
297
+ if (next >= pack.bytes) return void 0;
298
+ const start = next - next % blockBytes;
299
+ const loaded = this.#blockStep(pack, start);
300
+ const slice = (bytes) => {
301
+ const from = next - start;
302
+ const piece = bytes.subarray(from, Math.min(bytes.byteLength, from + packReadBytes));
303
+ next += piece.byteLength;
304
+ return piece;
305
+ };
306
+ return Effect.isEffect(loaded) ? Effect.map(loaded, slice) : slice(loaded);
307
+ };
308
+ }
309
+ #ensureEntryReader() {
310
+ if (this.#entryReader !== void 0 && !this.#entryReader.closed) return Result.succeed(this.#entryReader);
311
+ const opened = openEntryReader(this.#entryMeter);
312
+ if (Result.isSuccess(opened)) this.#entryReader = opened.success;
313
+ return opened;
314
+ }
315
+ #syncSourceAt(pack, offset) {
316
+ let next = offset;
317
+ return () => {
318
+ if (next >= pack.bytes) return void 0;
319
+ const start = next - next % blockBytes;
320
+ const kept = this.#kept.get(blockKey(pack, start));
321
+ if (kept === void 0) return "miss";
322
+ const from = next - start;
323
+ const piece = kept.subarray(from, Math.min(kept.byteLength, from + packReadBytes));
324
+ next += piece.byteLength;
325
+ return piece;
326
+ };
327
+ }
188
328
  /**
189
329
  * The entry at `offset`, read whole, `before` run on its header before its data is held; a
190
330
  * stored pack that won't read is `DATA_LOSS`.
191
331
  */
192
- entryAt = (pack, offset, before) => readEntryAt(this.sourceAt(pack, offset), offset, packIndexerLimits, new BufferMeter(entryReaderBytes), before).pipe(Effect.mapError((error) => error instanceof PackError || error instanceof BufferError ? lost(`Pack ${pack.id} is unreadable at ${offset}: ${error.message}`) : error));
332
+ entryAt = (pack, offset, before) => Effect.suspend(() => {
333
+ const mapUnreadable = (error) => error instanceof PackError || error instanceof BufferError ? lost(`Pack ${pack.id} is unreadable at ${offset}: ${error.message}`) : error;
334
+ let resume;
335
+ const firstStart = offset - offset % blockBytes;
336
+ if (!this.#entryReaderInUse && (offset >= pack.bytes || this.#kept.has(blockKey(pack, firstStart)))) {
337
+ const ensured = this.#ensureEntryReader();
338
+ if (Result.isFailure(ensured)) return Effect.fail(mapUnreadable(ensured.failure));
339
+ const sync = ensured.success.tryReadSync(this.#syncSourceAt(pack, offset), offset, packIndexerLimits, before);
340
+ if (sync instanceof PackError) return Effect.fail(mapUnreadable(sync));
341
+ if (sync === "too big" || !("async" in sync)) return Effect.succeed(sync);
342
+ resume = sync.async;
343
+ }
344
+ const startOffset = resume === void 0 ? offset : offset + resume.headerLength;
345
+ const runAsync = Effect.acquireUseRelease(Effect.suspend(() => {
346
+ if (this.#entryReaderInUse) {
347
+ const opened = openEntryReader(new BufferMeter(entryReaderBytes));
348
+ return Result.isFailure(opened) ? Effect.fail(opened.failure) : Effect.succeed({
349
+ reader: opened.success,
350
+ shared: false
351
+ });
352
+ }
353
+ const ensured = this.#ensureEntryReader();
354
+ if (Result.isFailure(ensured)) return Effect.fail(ensured.failure);
355
+ this.#entryReaderInUse = true;
356
+ return Effect.succeed({
357
+ reader: ensured.success,
358
+ shared: true
359
+ });
360
+ }), ({ reader }) => reader.read(this.#stepSourceAt(pack, startOffset), offset, packIndexerLimits, resume === void 0 ? before : void 0, resume), ({ reader, shared }) => Effect.sync(() => {
361
+ if (!shared) {
362
+ reader.close();
363
+ return;
364
+ }
365
+ reader.reset();
366
+ this.#entryReaderInUse = false;
367
+ if (this.#closeReaderOnFinish || reader.closed) this.#releaseEntryReader();
368
+ })).pipe(Effect.mapError(mapUnreadable));
369
+ return resume?.before === void 0 ? runAsync : Effect.flatMap(resume.before, () => runAsync);
370
+ });
371
+ };
372
+ /**
373
+ * `pack`'s bytes `[from, to)` as a `PackRun`, its get counted on the operation's calls, as every
374
+ * bucket call is. Each read of its body waits for a piece, and an interruption cancels the body
375
+ * through the read's own canceller, so it adds no listener to any signal.
376
+ */
377
+ const packRun = (bucket, pack, from, to) => {
378
+ let reader;
379
+ let piece = /* @__PURE__ */ new Uint8Array(0);
380
+ let pieceAt = from;
381
+ 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, {
384
+ offset: from,
385
+ length: to - from
386
+ });
387
+ if (body === void 0) return yield* Effect.fail(missing(from));
388
+ return body.getReader();
389
+ });
390
+ const cancel = (opened) => Effect.promise(() => opened.cancel().catch(() => void 0));
391
+ /**
392
+ * The body's next piece, or its end, its failure as `bucketTry` maps one: a closed server's, and
393
+ * one past a call bound, stay defects. An interruption cancels the body. The read takes no signal,
394
+ * so it adds no listener to one.
395
+ */
396
+ const nextPiece = (opened) => bucketTry(() => opened.read()).pipe(Effect.onInterrupt(() => cancel(opened)));
397
+ return {
398
+ from,
399
+ to,
400
+ 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
+ }),
413
+ close: Effect.suspend(() => {
414
+ const opened = reader;
415
+ piece = /* @__PURE__ */ new Uint8Array(0);
416
+ return opened === void 0 ? Effect.void : cancel(opened);
417
+ })
418
+ };
193
419
  };
194
420
  /**
421
+ * The most of the index cache's room one receive's seed may take, as a share of `room.most`: a
422
+ * pack's entry past it is read by a load instead, so one push never fills half of what the cache can
423
+ * ever hold. 1b's largest receive, about 1.24M objects, holds about 40 MiB of `.idx` and `.rev`.
424
+ */
425
+ const indexSeedShare = 1 / 2;
426
+ /**
427
+ * What a seed holds at once, which its charge covers: the files as written, and the entry `seed`
428
+ * parses from them, a copy of each with its overhead.
429
+ */
430
+ const seedBytes = (files) => 384 + 2 * (files.index.byteLength + files.reverse.byteLength);
431
+ /**
195
432
  * The `.idx` and `.rev` of each pack a server has read, across every repo, by the pack's ID: a
196
433
  * pack's files never change, so one is checked once, its trailer against the index's and the
197
434
  * reverse index against both, and kept until the cache is full.
198
435
  */
199
436
  var PackIndexes = class {
200
437
  #kept = /* @__PURE__ */ new Map();
438
+ /**
439
+ * Each pack's load under way, which every other load of it waits on. One that stopped for its
440
+ * caller alone is loaded again by a waiter, and a failed one is never kept.
441
+ */
442
+ #loading = new SingleFlight();
201
443
  #room;
202
444
  #held = 0;
203
445
  /**
@@ -208,7 +450,15 @@ var PackIndexes = class {
208
450
  this.#room = room;
209
451
  room.watch((bytes) => this.#evictTo(bytes));
210
452
  }
211
- load = (bucket, listed) => Effect.gen({ self: this }, function* () {
453
+ /**
454
+ * `listed`'s `.idx` and `.rev`, kept or read. One load of a pack runs at a time, whoever asks:
455
+ * the cache owns it, and every other caller waits on it, so 16 cold reads of one pack make one
456
+ * load's calls, and its bytes are kept, and charged to the room, once. A failed load fails each
457
+ * caller waiting on it, and nothing keeps it; one interrupted, or past its caller's own call
458
+ * bound, is loaded again by a waiter under the waiter's, so no waiter hangs on a caller that went
459
+ * away or answers for another's calls.
460
+ */
461
+ load = Effect.fnUntraced({ self: this }, function* (bucket, listed) {
212
462
  const { id } = listed;
213
463
  if (!isPackId(id)) return yield* Effect.fail(lost(`The pack row '${id}' doesn't name a pack`));
214
464
  const pack = {
@@ -225,20 +475,26 @@ var PackIndexes = class {
225
475
  reverse: kept.reverse
226
476
  };
227
477
  }
478
+ const loaded = yield* this.#loading.run(id, this.#read(bucket, listed, pack));
479
+ return Option.isSome(loaded) ? loaded.value : yield* this.load(bucket, listed);
480
+ });
481
+ /** `load`'s reads of `listed`'s files, its checks, and the cache's keep of them. */
482
+ #read = Effect.fnUntraced({ self: this }, function* (bucket, listed, pack) {
483
+ const { id } = pack;
228
484
  const files = packFiles(id);
229
- const bytes = yield* readWhole(bucket, files.idx);
485
+ const bytes = yield* readInto(bucket, files.idx, idxMostBytes(listed), `Pack ${id}'s index`);
230
486
  if (bytes === void 0) return yield* Effect.fail(lost(`Pack ${id} has no index`));
231
- const index = yield* readPackIndex(bytes).pipe(Effect.mapError((error) => lost(`Pack ${id}'s index is unreadable: ${error.message}`)));
487
+ const index = yield* ownedPackIndex(bytes).pipe(Effect.mapError((error) => lost(`Pack ${id}'s index is unreadable: ${error.message}`)));
232
488
  if (index.count !== listed.objects) return yield* Effect.fail(lost(`Pack ${id}'s index lists ${index.count} objects; its row, ${listed.objects}`));
233
489
  const trailer = yield* readWhole(bucket, files.pack, {
234
490
  offset: listed.bytes - 20,
235
491
  length: 20
236
492
  });
237
493
  if (trailer === void 0 || Hex.encode(trailer) !== index.packChecksum) return yield* Effect.fail(lost(`Pack ${id}'s bytes aren't those its index lists`));
238
- const reversed = yield* readWhole(bucket, files.rev);
494
+ const reversed = yield* readInto(bucket, files.rev, revBytes(listed), `Pack ${id}'s reverse index`);
239
495
  if (reversed === void 0) return yield* Effect.fail(lost(`Pack ${id} has no reverse index`));
240
- const reverse = yield* readPackReverse(reversed, index).pipe(Effect.mapError((error) => lost(`Pack ${id}'s reverse index is unreadable: ${error.message}`)));
241
- const held = 384 + bytes.byteLength + reversed.byteLength;
496
+ const reverse = yield* ownedPackReverse(reversed, index).pipe(Effect.mapError((error) => lost(`Pack ${id}'s reverse index is unreadable: ${error.message}`)));
497
+ const held = 384 + bytes.buffer.byteLength + reversed.buffer.byteLength;
242
498
  this.#remember(id, {
243
499
  index,
244
500
  reverse,
@@ -251,8 +507,67 @@ var PackIndexes = class {
251
507
  };
252
508
  });
253
509
  /**
254
- * `kept` at `id`, the most recent. One already there, as two loads of one pack that both missed
255
- * leave it, is let go first, so `#held` is always the sum of the indexes kept: a second load
510
+ * A receive's `.idx` and `.rev` kept from the bytes it just wrote, with `load`'s checks and no
511
+ * call: its count, its pack checksum, and the reverse index against both. It runs once the
512
+ * receive's rooms are released, on `seed.charge`, which covers the written bytes and the parsed
513
+ * entry until the parse ends; then the charge goes back, and the entry is kept only when the
514
+ * room grows to it, evicting nothing. Skipped when the cache keeps the pack already, a load of it
515
+ * is under way, which keeps what it reads, the charge falls short of `seedBytes`, or the entry
516
+ * is past `indexSeedShare` of the room's most. A failed check keeps nothing and is logged by
517
+ * name, since the writer's own bytes failing them is a bug in it, not bad input; it never fails
518
+ * the receive.
519
+ */
520
+ seed = (seed) => Effect.ensuring(this.#seed(seed), Effect.sync(() => seed.charge.release()));
521
+ #seed = Effect.fnUntraced({ self: this }, function* ({ listed, files, charge }) {
522
+ const { id } = listed;
523
+ if (!isPackId(id) || this.#kept.has(id) || this.#loading.running(id)) return;
524
+ if (charge.bytes < seedBytes(files)) return;
525
+ const held = 384 + files.index.byteLength + files.reverse.byteLength;
526
+ if (held > .5 * this.#room.most) return;
527
+ const failed = (check, counts) => Effect.logWarning(`Pack ${id}'s seed failed its ${check} check (${counts}); nothing kept`);
528
+ const index = yield* Effect.option(readPackIndex(files.index));
529
+ if (Option.isNone(index)) return yield* failed("index", `${files.index.byteLength} bytes`);
530
+ if (index.value.count !== listed.objects) return yield* failed("count", `${index.value.count} listed, ${listed.objects} on its row`);
531
+ if (index.value.packChecksum !== files.checksum) return yield* failed("trailer", `${index.value.packChecksum} against ${files.checksum}`);
532
+ const reverse = yield* Effect.option(readPackReverse(files.reverse, index.value));
533
+ if (Option.isNone(reverse)) return yield* failed("reverse index", `${files.reverse.byteLength} bytes`);
534
+ charge.release();
535
+ const over = this.#held + held - this.#room.bytes;
536
+ if (over > 0 && !this.#room.grow(over)) return;
537
+ this.#remember(id, {
538
+ index: index.value,
539
+ reverse: reverse.value,
540
+ bytes: held
541
+ });
542
+ });
543
+ /**
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.
547
+ */
548
+ forget = (id) => {
549
+ if (!isPackId(id)) return;
550
+ const kept = this.#kept.get(id);
551
+ if (kept === void 0) return;
552
+ this.#kept.delete(id);
553
+ this.#held -= kept.bytes;
554
+ };
555
+ /**
556
+ * The `.idx` the cache keeps for pack `id`, read by no call and made the most recent, or
557
+ * `undefined` when it keeps none: a lookup that must hold no `.idx` of its own reads one held
558
+ * here, and reads any other by range.
559
+ */
560
+ peek = (id) => {
561
+ if (!isPackId(id)) return void 0;
562
+ const kept = this.#kept.get(id);
563
+ if (kept === void 0) return void 0;
564
+ this.#kept.delete(id);
565
+ this.#kept.set(id, kept);
566
+ return kept.index;
567
+ };
568
+ /**
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
256
571
  * costs its reads, never a charge that outlives its entry.
257
572
  */
258
573
  #remember(id, kept) {
@@ -328,13 +643,13 @@ const checkedNow = (pack, oid, type, bytes) => {
328
643
  * An object resolved from a stored pack, hashed again against the ID its index lists: at once
329
644
  * below `hashedNowMost`, through `objectId` from it up.
330
645
  */
331
- const checkedObject = Effect.fnUntraced(function* (pack, oid, resolved) {
646
+ const checkedObject = /* @__PURE__ */ Effect.fnUntraced(function* (pack, oid, resolved) {
332
647
  if (resolved.kind !== "resolved") return yield* Effect.fail(unresolvedEntry(pack, oid, resolved));
333
648
  const { kind: type } = resolved.object;
334
649
  const bytes = new Uint8Array(resolved.object.bytes);
335
650
  if (bytes.byteLength < 65536) {
336
651
  const checked = checkedNow(pack, oid, type, bytes);
337
- return "code" in checked ? yield* Effect.fail(checked) : checked;
652
+ return isGitError(checked) ? yield* Effect.fail(checked) : checked;
338
653
  }
339
654
  const hashed = yield* objectId({
340
655
  type,
@@ -347,6 +662,19 @@ const checkedObject = Effect.fnUntraced(function* (pack, oid, resolved) {
347
662
  bytes
348
663
  };
349
664
  });
665
+ const loadedLookup = (indexed) => ({
666
+ pack: indexed.pack,
667
+ find: (oid) => indexed.index.find(oid)?.offset
668
+ });
669
+ /** A lookup of `ranges`: `rankOf`'s reads, then the offset's. */
670
+ const rangedLookup = (ranges) => ({
671
+ pack: ranges.pack,
672
+ find: Effect.fnUntraced(function* (oid) {
673
+ const rank = yield* rankOf(ranges, oidBytes(oid));
674
+ if (rank === void 0) return void 0;
675
+ return (yield* ranges.offsets(rank, 1))[0];
676
+ })
677
+ });
350
678
  /**
351
679
  * Objects of stored packs, each resolved whole from its offset and hashed again against its ID:
352
680
  * one indexer for each pack, and one cache for them all. An indexer holds the pack's index only
@@ -356,50 +684,58 @@ const checkedObject = Effect.fnUntraced(function* (pack, oid, resolved) {
356
684
  const packObjects = (blocks, room, outside) => {
357
685
  const indexers = /* @__PURE__ */ new Map();
358
686
  const cache = new IndexerCache(room);
359
- const indexingOf = (indexed) => {
360
- const kept = indexers.get(indexed.pack.id);
687
+ const indexingOf = (pack) => {
688
+ const kept = indexers.get(pack.id);
361
689
  if (kept !== void 0) return kept;
362
- const { pack } = indexed;
363
690
  const made = {
364
691
  using: void 0,
365
692
  resolving: 0,
366
693
  indexer: new PackIndexer({
367
694
  entryAt: (offset, before) => blocks.entryAt(pack, offset, before),
368
- offsetOf: (oid) => made.using?.index.find(oid)?.offset,
369
- ...outside && { allot: outside }
695
+ offsetOf: (oid) => made.using === void 0 ? void 0 : made.using.find(oid),
696
+ allot: outside
370
697
  }, packIndexerLimits, cache)
371
698
  };
372
699
  indexers.set(pack.id, made);
373
700
  return made;
374
701
  };
375
- /** `indexed`'s index lent to its indexer while `resolve` runs, and dropped when the last ends. */
376
- const lent = (indexing, indexed, resolve) => Effect.acquireUseRelease(Effect.sync(() => {
377
- indexing.using = indexed;
702
+ /** `lookup` lent to its pack's indexer while `resolve` runs, and dropped when the last ends. */
703
+ const lent = (indexing, lookup, resolve) => Effect.acquireUseRelease(Effect.sync(() => {
704
+ indexing.using = lookup;
378
705
  indexing.resolving += 1;
379
706
  }), () => resolve, () => Effect.sync(() => {
380
707
  indexing.resolving -= 1;
381
708
  if (indexing.resolving === 0) indexing.using = void 0;
382
709
  }));
383
- /** What the entry at `offset` resolves to, reading its chain as it needs. */
384
- const resolving = (oid, indexed, offset) => {
385
- const indexing = indexingOf(indexed);
386
- return lent(indexing, indexed, stepEffect(indexing.indexer.resolve(offset))).pipe(Effect.catchIf((error) => error instanceof DeltaError, (error) => Effect.fail(lost(`Object ${oid} in pack ${indexed.pack.id} won't resolve: ${error.message}`))));
710
+ /** What the entry at `offset` resolves to, reading its chain as it needs, its bases found by `lookup`. */
711
+ const resolvingIn = (oid, lookup, offset) => {
712
+ const indexing = indexingOf(lookup.pack);
713
+ return lent(indexing, lookup, stepEffect(indexing.indexer.resolve(offset))).pipe(Effect.catchIf((error) => error instanceof DeltaError, (error) => Effect.fail(lost(`Object ${oid} in pack ${lookup.pack.id} won't resolve: ${error.message}`))));
387
714
  };
715
+ const resolving = (oid, indexed, offset) => resolvingIn(oid, loadedLookup(indexed), offset);
388
716
  const at = Effect.fnUntraced(function* (oid, indexed, offset) {
389
717
  return yield* checkedObject(indexed.pack, oid, yield* resolving(oid, indexed, offset));
390
718
  });
719
+ /** `at` with each base found through `lookup`, as a read by place finds them. */
720
+ const atIn = Effect.fnUntraced(function* (oid, lookup, offset) {
721
+ return yield* checkedObject(lookup.pack, oid, yield* resolvingIn(oid, lookup, offset));
722
+ });
723
+ /** `at` for a pack whose `.idx` isn't loaded: each base found through its `ranges`. */
724
+ const inRanges = (oid, ranges, offset) => atIn(oid, rangedLookup(ranges), offset);
391
725
  /**
392
726
  * What the entry at `offset` resolves to at once, from its pack's indexer's cache, with nothing
393
727
  * read; `undefined` when `resolving` must read it.
394
728
  */
395
- const recalled = (indexed, offset) => indexingOf(indexed).indexer.recalled(offset);
729
+ const recalled = (indexed, offset) => indexingOf(indexed.pack).indexer.recalled(offset);
396
730
  /** Lets go of the cache and each pack's indexer. */
397
731
  const clear = () => {
398
732
  indexers.clear();
399
733
  cache.clear();
400
734
  };
401
735
  return Object.assign(at, {
736
+ atIn,
402
737
  clear,
738
+ inRanges,
403
739
  recalled,
404
740
  resolving
405
741
  });
@@ -425,7 +761,7 @@ const entryStream = (blocks, at, signal, count) => {
425
761
  wake = void 0;
426
762
  });
427
763
  });
428
- const hand = (bytes) => Effect.gen(function* () {
764
+ const hand = Effect.fnUntraced(function* (bytes) {
429
765
  yield* demand;
430
766
  const answer = pulled;
431
767
  pulled = void 0;
@@ -442,7 +778,7 @@ const entryStream = (blocks, at, signal, count) => {
442
778
  }, {
443
779
  begin: () => Effect.void,
444
780
  entry: () => Effect.void,
445
- data: (bytes) => Effect.gen(function* () {
781
+ data: Effect.fnUntraced(function* (bytes) {
446
782
  sha.update(bytes);
447
783
  if (last !== void 0) yield* hand(last);
448
784
  last = bytes.slice();
@@ -453,7 +789,7 @@ const entryStream = (blocks, at, signal, count) => {
453
789
  count: 2,
454
790
  index: 0,
455
791
  offset: at.offset
456
- }).pipe(Effect.mapError((error) => "code" in error ? error : lost(`Pack ${at.pack.id} is unreadable at ${at.offset}: ${error.message}`)));
792
+ }).pipe(Effect.mapError((error) => isGitError(error) ? error : lost(`Pack ${at.pack.id} is unreadable at ${at.offset}: ${error.message}`)));
457
793
  const hashed = Hex.encode(sha.digest());
458
794
  if (hashed !== at.oid) return yield* Effect.fail(lost(`Object ${at.oid} in pack ${at.pack.id} hashes to ${hashed}`));
459
795
  if (last !== void 0) yield* hand(last);
@@ -496,25 +832,36 @@ const entryStream = (blocks, at, signal, count) => {
496
832
  }, { highWaterMark: 0 });
497
833
  };
498
834
  /**
499
- * A reader's memory outside any budget: the read cache and every block it may keep, fixed. For
500
- * maintenance, whose Durable Object runs one step at a time in its own isolate.
501
- */
502
- const fixedReaderMemory = () => ({
503
- cache: fixedRoom(readCacheBytes),
504
- blocks: fixedRoom(8 * blockHeld(blockBytes)),
505
- index: () => Effect.void,
506
- outside: () => void 0
507
- });
508
- /**
509
835
  * What a pack's `.idx` and `.rev` take, by its objects, as an index read holds them: the `.idx`'s
510
836
  * header, fan-out and trailer, its ID, CRC and offset for each object, and a large offset for each
511
837
  * past 2 GiB; the `.rev`'s header, trailer and a position for each; and their entry's overhead.
512
838
  */
513
- const indexBytes = (pack) => {
514
- const n = pack.objects;
515
- const large = pack.bytes > 2 ** 31 ? 8 * n : 0;
516
- return 1072 + 28 * n + large + 52 + 4 * n + 384;
517
- };
839
+ const indexBytes = (pack) => idxMostBytes(pack) + revBytes(pack) + 384;
840
+ /**
841
+ * The most a pack's `.idx` takes: its header, fan-out and trailer, and each object's fields. Only
842
+ * a pack past 2 GiB gets large offsets, since this server's writers put no offset under 2^31 in
843
+ * the table (`sortedIndex`). A Git-made index that puts smaller offsets there
844
+ * (`--index-version=2,<offset>`) is longer, and its read refuses it as `DATA_LOSS`. No path
845
+ * stores one.
846
+ */
847
+ const idxMostBytes = (pack) => 1072 + 28 * pack.objects + (pack.bytes > 2 ** 31 ? 8 * pack.objects : 0);
848
+ /** A pack's `.rev`: its header and trailer, and a position for each object. */
849
+ const revBytes = (pack) => 52 + 4 * pack.objects;
850
+ /**
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.
854
+ */
855
+ const readInto = (bucket, key, most, named) => bucketDo(Effect.suspend(() => {
856
+ const bytes = new Uint8Array(most);
857
+ let at = 0;
858
+ return bucket.read(key).pipe(Stream.runForEach((chunk) => {
859
+ if (chunk.byteLength > most - at) return Effect.fail(lost(`${named} is unreadable: it's past the ${most} bytes its objects take`));
860
+ bytes.set(chunk, at);
861
+ at += chunk.byteLength;
862
+ return Effect.void;
863
+ }), Effect.map(() => bytes.subarray(0, at)), Effect.catchIf((error) => Predicate.isTagged(error, "NotFound"), () => Effect.succeed(void 0)));
864
+ }));
518
865
  /**
519
866
  * One operation's reads of a repo's objects under `packs()`: its rows first, a small push's,
520
867
  * then each pack its list names, by the pack's `.idx`. An object is resolved from the pack's
@@ -532,6 +879,21 @@ const packReader = (input) => {
532
879
  const named = new Set(listed.packs.map((pack) => pack.id));
533
880
  const kept = /* @__PURE__ */ new Map();
534
881
  const charged = /* @__PURE__ */ new Set();
882
+ const charging = new SingleFlight();
883
+ const loadings = /* @__PURE__ */ new Set();
884
+ /**
885
+ * `pack`'s `.idx` and `.rev` charged to the reader's allotment, once a reader: marked only once
886
+ * granted, so a read at once on the reader waits on the charge before it loads, and a refused or
887
+ * interrupted charge is asked again by the next read, never skipped.
888
+ */
889
+ const charge = Effect.fnUntraced(function* (pack) {
890
+ if (charged.has(pack.id)) return;
891
+ const granted = yield* charging.run(pack.id, Effect.tap(memory.index(indexBytes(pack)), () => Effect.sync(() => {
892
+ charged.add(pack.id);
893
+ for (const told of loadings) told(pack.id);
894
+ })));
895
+ if (Option.isNone(granted)) yield* charge(pack);
896
+ });
535
897
  const unnamed = (pack) => !named.has(pack.id);
536
898
  /** The packs the repo lists now that `listed` didn't, such as a merge's that folded rows. */
537
899
  const listedSince = Effect.fnUntraced(function* () {
@@ -570,27 +932,25 @@ const packReader = (input) => {
570
932
  /**
571
933
  * Where each of `oids` is in the listed packs, by the first pack that lists it, then in those
572
934
  * listed since, then in those the repo's delete let go of, a page at a time, for any not found:
573
- * each read apart, so neither collection's rows count against the other's answer. Each listed
574
- * pack's indexes it loads are kept by the pack's ID, in `loaded` when the caller gives one and in
575
- * the reader's own `kept` otherwise, and read before the server's cache: a reader loads a listed
576
- * pack's indexes once, however small that cache is. Either holds only what was loaded, each
577
- * `IndexedPack` until the reader is released or the caller drops its map, outside the index
578
- * cache: at most every listed pack's `.idx` and `.rev` at once. Each pack's are charged to the
579
- * reader's allotment before its first load, and stay charged until the allotment ends.
935
+ * each read apart, so neither collection's rows count against the other's answer. `from` says
936
+ * which of them it looks in: `listed` the listed packs alone, `beyond` all but them. Each listed
937
+ * pack's indexes it loads are kept by the pack's ID, in the reader's own `kept`, and read before
938
+ * the server's cache: a reader loads a listed pack's indexes once, however small that cache is.
939
+ * It holds only what was loaded, each `IndexedPack` until the reader is released, outside the
940
+ * index cache: at most every listed pack's `.idx` and `.rev` at once. Each pack's are charged to
941
+ * the reader's allotment before its first load, and stay charged until the allotment ends.
580
942
  * A pack `listed` doesn't name, listed since or leaving, is this call's alone, through the
581
- * server's cache, so a reader holds no more than its listing names.
943
+ * server's cache, so a reader holds no more than its listing names. A listed pack in `skip`
944
+ * isn't looked in, its indexes never loaded: an index proves it holds none of `oids` (#522).
582
945
  */
583
- const found = Effect.fnUntraced(function* (oids, loaded = kept, listedAlone = false) {
946
+ const found = Effect.fnUntraced(function* (oids, from = "all", skip) {
584
947
  const where = /* @__PURE__ */ new Map();
585
948
  let left = [...new Set(oids)];
586
949
  const look = Effect.fnUntraced(function* (packs, held, going = false) {
587
950
  for (const listedPack of packs) {
588
951
  if (left.length === 0) break;
589
952
  const known = held.get(listedPack.id);
590
- if (known === void 0 && !charged.has(listedPack.id)) {
591
- yield* memory.index(indexBytes(listedPack));
592
- charged.add(listedPack.id);
593
- }
953
+ if (known === void 0) yield* charge(listedPack);
594
954
  const indexed = 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);
595
955
  if (Option.isNone(indexed)) continue;
596
956
  held.set(listedPack.id, indexed.value);
@@ -606,8 +966,9 @@ const packReader = (input) => {
606
966
  });
607
967
  }
608
968
  });
609
- yield* look(listed.packs, loaded);
610
- if (left.length === 0 || listedOnly === true || listedAlone) return where;
969
+ const looked = skip === void 0 ? listed.packs : listed.packs.filter((pack) => !skip.has(pack.id));
970
+ yield* look(from === "beyond" ? [] : looked, kept);
971
+ if (left.length === 0 || listedOnly === true || from === "listed") return where;
611
972
  const unlisted = /* @__PURE__ */ new Map();
612
973
  yield* look(yield* listedSince(), unlisted);
613
974
  let after;
@@ -625,8 +986,8 @@ const packReader = (input) => {
625
986
  * each handed to `row`; then, for what neither holds, the packs listed since and those leaving,
626
987
  * as a merge that folded the rows after this read's listing leaves them.
627
988
  */
628
- const located = Effect.fnUntraced(function* (oids, row) {
629
- const where = yield* found(oids, kept, true);
989
+ const located = Effect.fnUntraced(function* (oids, row, skip) {
990
+ const where = yield* found(oids, "listed", skip);
630
991
  const unpacked = oids.filter((oid) => !where.has(oid));
631
992
  if (unpacked.length === 0) return where;
632
993
  const inRows = /* @__PURE__ */ new Set();
@@ -635,7 +996,9 @@ const packReader = (input) => {
635
996
  return row(object);
636
997
  });
637
998
  const missing = unpacked.filter((oid) => !inRows.has(oid));
638
- if (missing.length > 0) for (const [oid, place] of yield* found(missing)) where.set(oid, place);
999
+ if (missing.length > 0) for (const [oid, place] of yield* found(missing, "all", skip)) where.set(oid, place);
1000
+ const skipped = skip === void 0 ? [] : missing.filter((oid) => !where.has(oid));
1001
+ if (skipped.length > 0) for (const [oid, place] of yield* found(skipped)) where.set(oid, place);
639
1002
  return where;
640
1003
  });
641
1004
  /**
@@ -643,48 +1006,55 @@ const packReader = (input) => {
643
1006
  * finds them: the listed packs first, so a walk over a repo whose objects are all packed asks the
644
1007
  * store for no row (#647), then the rows, then the packs listed since and those leaving.
645
1008
  */
646
- const each = Effect.fnUntraced(function* (oids, take) {
647
- const where = yield* located(oids, take);
1009
+ const eachOf = (skip) => Effect.fnUntraced(function* (oids, take) {
1010
+ const where = yield* located(oids, take, skip);
648
1011
  for (const [oid, { indexed, offset }] of where) yield* take(yield* wholeAt(oid, indexed, offset));
649
1012
  });
650
- /** Which of `oids` the repo holds, read whole. */
651
- const held = Effect.fnUntraced(function* (oids) {
1013
+ const each = eachOf();
1014
+ /** Which of `oids` the repo holds, read whole, through `take`'s reads. */
1015
+ const heldOf = (take) => Effect.fnUntraced(function* (oids) {
652
1016
  const objects = /* @__PURE__ */ new Map();
653
- yield* each(oids, (object) => Effect.sync(() => void objects.set(object.oid, object)));
1017
+ yield* take(oids, (object) => Effect.sync(() => void objects.set(object.oid, object)));
654
1018
  return objects;
655
1019
  });
1020
+ /** Which of `oids` the repo holds, read whole. */
1021
+ const held = heldOf(each);
656
1022
  /** Each of `entries` read whole where the index placed it, as `held` reads one it found. */
657
1023
  const heldAt = Effect.fnUntraced(function* (entries) {
658
1024
  const objects = /* @__PURE__ */ new Map();
659
- for (const { oid, indexed, offset } of entries) objects.set(oid, yield* wholeAt(oid, indexed, offset));
1025
+ for (const { oid, lookup, offset } of entries) objects.set(oid, yield* wholeAt.atIn(oid, lookup, offset));
660
1026
  return objects;
661
1027
  });
662
1028
  /**
663
1029
  * The size of the object an entry holds, from its header, or a delta's from its instructions'
664
1030
  * header, its base never read; an entry whose header won't say is resolved whole.
665
1031
  */
666
- const sizeAt = Effect.fnUntraced(function* (oid, indexed, offset) {
667
- const head = yield* blocks.headAt(indexed.pack, offset);
1032
+ const sizeAt = Effect.fnUntraced(function* (oid, lookup, offset) {
1033
+ const head = yield* blocks.headAt(lookup.pack, offset);
668
1034
  const header = readEntryHeader(head, head.byteLength, offset, headerLimits);
669
1035
  if (header.kind === "entry" && header.type !== "ofs" && header.type !== "ref") return header.size;
670
1036
  if (header.kind === "entry") {
671
- const read = yield* blocks.entryAt(indexed.pack, offset);
1037
+ const read = yield* blocks.entryAt(lookup.pack, offset);
672
1038
  const size = read === "too big" ? void 0 : deltaResultSize(read.data);
673
1039
  if (size !== void 0) return size;
674
1040
  }
675
- return (yield* wholeAt(oid, indexed, offset)).bytes.byteLength;
1041
+ return (yield* wholeAt.atIn(oid, lookup, offset)).bytes.byteLength;
676
1042
  });
677
1043
  /**
678
1044
  * The size of each of `oids` the repo holds, none held whole past its own read: each pack's in
679
1045
  * the order of its offsets, so its neighbourhoods are read once.
680
1046
  */
681
- const sizes = Effect.fnUntraced(function* (oids) {
1047
+ const sizesOf = (skip) => Effect.fnUntraced(function* (oids) {
682
1048
  const sized = /* @__PURE__ */ new Map();
683
1049
  for (const [oid, size] of yield* rowsSized(oids)) sized.set(oid, size);
684
- const where = byPlace(yield* found(oids.filter((oid) => !sized.has(oid))));
685
- for (const [oid, { indexed, offset }] of where) sized.set(oid, yield* sizeAt(oid, indexed, offset));
1050
+ const unsized = oids.filter((oid) => !sized.has(oid));
1051
+ const where = yield* found(unsized, "all", skip);
1052
+ const skipped = skip === void 0 ? [] : unsized.filter((oid) => !where.has(oid));
1053
+ if (skipped.length > 0) for (const [oid, place] of yield* found(skipped)) where.set(oid, place);
1054
+ for (const [oid, { indexed, offset }] of byPlace(where)) sized.set(oid, yield* sizeAt(oid, loadedLookup(indexed), offset));
686
1055
  return sized;
687
1056
  });
1057
+ const sizes = sizesOf();
688
1058
  /**
689
1059
  * The size of each of `at`'s entries of `pack`, in its order, as `sizes` sizes them, with no
690
1060
  * look-up by ID: a fetch's send list knows each entry's place from the index (#522).
@@ -757,13 +1127,19 @@ const packReader = (input) => {
757
1127
  });
758
1128
  /**
759
1129
  * The type and size of each of `oids` the repo holds, as `git cat-file --batch-check` gives
760
- * them, from headers alone: rows first, then each pack's entries in the order of their offsets.
761
- * A delta's size is its result's and its type its chain's, as `typeAt` follows it. An entry whose
762
- * header or chain won't say is read whole.
1130
+ * them, from headers alone, found in `located`'s order: the listed packs first, so a repo whose
1131
+ * objects are all packed asks the store for no row (#647), then the rows, then the packs listed
1132
+ * since and those leaving, each pack's entries in the order of their offsets. A delta's size is
1133
+ * its result's and its type its chain's, as `typeAt` follows it. An entry whose header or chain
1134
+ * won't say is read whole.
763
1135
  */
764
1136
  const headers = Effect.fnUntraced(function* (oids) {
765
- const answer = new Map(yield* rowsHeaders(oids));
766
- const where = byPlace(yield* found(oids.filter((oid) => !answer.has(oid))));
1137
+ const listedAt = yield* found(oids, "listed");
1138
+ const unpacked = oids.filter((oid) => !listedAt.has(oid));
1139
+ const answer = new Map(unpacked.length === 0 ? [] : yield* rowsHeaders(unpacked));
1140
+ const missing = unpacked.filter((oid) => !answer.has(oid));
1141
+ const later = missing.length === 0 ? [] : yield* found(missing, "beyond");
1142
+ const where = byPlace(new Map([...listedAt, ...later]));
767
1143
  const known = /* @__PURE__ */ new Map();
768
1144
  for (const [oid, { indexed, offset }] of where) {
769
1145
  const type = yield* typeAt(indexed, offset, known);
@@ -777,25 +1153,30 @@ const packReader = (input) => {
777
1153
  }
778
1154
  answer.set(oid, {
779
1155
  type,
780
- size: yield* sizeAt(oid, indexed, offset)
1156
+ size: yield* sizeAt(oid, loadedLookup(indexed), offset)
781
1157
  });
782
1158
  }
783
1159
  return answer;
784
1160
  });
785
1161
  /**
786
1162
  * Which of `oids` the repo holds, and where, by its rows and its packs' indexes, none read: the
787
- * listed pack an index found it in, by ID, or `undefined` for a row. `loaded`, when given, keeps
788
- * the packs' indexes it loads, as `found` says, for later calls given it too.
1163
+ * listed pack an index found it in, by ID, or `undefined` for a row.
789
1164
  */
790
- const heldIn = Effect.fnUntraced(function* (oids, loaded) {
1165
+ const heldIn = Effect.fnUntraced(function* (oids) {
791
1166
  const there = /* @__PURE__ */ new Map();
792
1167
  for (const oid of (yield* rowsSized(oids)).keys()) there.set(oid, void 0);
793
- const packed = yield* found(oids.filter((oid) => !there.has(oid)), loaded);
1168
+ const packed = yield* found(oids.filter((oid) => !there.has(oid)));
794
1169
  for (const [oid, { indexed }] of packed) there.set(oid, indexed.pack.id);
795
1170
  return there;
796
1171
  });
797
1172
  /** Which of `oids` the repo holds, as `heldIn` finds them. */
798
- const has = (oids, loaded) => Effect.map(heldIn(oids, loaded), (there) => new Set(there.keys()));
1173
+ const has = (oids) => Effect.map(heldIn(oids), (there) => new Set(there.keys()));
1174
+ /**
1175
+ * Where each of `oids` is in the packs listed since this read's listing and those its delete let
1176
+ * go of, as `found` looks in them, the listed packs left out: a lookup that read the listed ones
1177
+ * by range asks these for what they didn't hold.
1178
+ */
1179
+ const beyond = (oids) => found(oids, "beyond");
799
1180
  /** What the entry at `offset` holds, by its header, or `undefined` for one that won't say. */
800
1181
  const holdsAt = Effect.fnUntraced(function* (indexed, offset) {
801
1182
  const head = yield* blocks.headAt(indexed.pack, offset);
@@ -813,10 +1194,11 @@ const packReader = (input) => {
813
1194
  * The entry each of `oids` is stored as, to copy as it is: its length by the pack's `.rev`, its
814
1195
  * CRC-32 by its `.idx`, and what it holds by its header, a whole object or a delta on a base it
815
1196
  * names by ID. An entry that won't say, or an offset delta, is left out, to be read whole.
1197
+ * A listed pack in `skip` isn't looked in, as `found` says.
816
1198
  */
817
- const storedOf = Effect.fnUntraced(function* (oids, loaded) {
1199
+ const storedOf = Effect.fnUntraced(function* (oids, skip) {
818
1200
  const entries = /* @__PURE__ */ new Map();
819
- for (const [oid, { indexed, offset, crc32 }] of byPlace(yield* found(oids, loaded))) {
1201
+ for (const [oid, { indexed, offset, crc32 }] of byPlace(yield* found(oids, "all", skip))) {
820
1202
  const { pack } = indexed;
821
1203
  const end = entryEnd(indexed, offset);
822
1204
  if (end === void 0 || end <= offset) return yield* Effect.fail(lost(`Pack ${pack.id}'s reverse index has no entry at ${offset}`));
@@ -839,10 +1221,12 @@ const packReader = (input) => {
839
1221
  return Effect.map(blocks.block(entry.pack, start), (block) => block.subarray(from - start, Math.min(block.byteLength, from - start + entry.bytes - at)));
840
1222
  };
841
1223
  const stored = {
842
- find: storedOf,
1224
+ find: (oids) => storedOf(oids),
843
1225
  read,
844
1226
  gets: (entries) => blocks.gets(entries),
845
- packed: (oids) => Effect.map(found(oids, kept, true), (where) => new Set(where.keys()))
1227
+ run: (pack, from, to) => packRun(bucket, pack, from, to),
1228
+ kept: (pack, offset) => blocks.keeps(pack, offset),
1229
+ packed: (oids) => Effect.map(found(oids, "listed"), (where) => new Set(where.keys()))
846
1230
  };
847
1231
  /**
848
1232
  * The object `oid` as `ObjectReader.read` hands it on, rows first: a whole entry past
@@ -900,7 +1284,7 @@ const packReader = (input) => {
900
1284
  }
901
1285
  const bytes = new Uint8Array(resolved.object.bytes);
902
1286
  const checked = checkedNow(indexed.pack, oid, resolved.object.kind, bytes);
903
- if ("code" in checked) return yield* Effect.fail(checked);
1287
+ if (isGitError(checked)) return yield* Effect.fail(checked);
904
1288
  answer.keep(checked);
905
1289
  run.at += size;
906
1290
  if (run.at >= 1048576) {
@@ -941,7 +1325,7 @@ const packReader = (input) => {
941
1325
  * offset, from their `.idx` alone with no header read, then the rest as they came (#662).
942
1326
  */
943
1327
  const inPackOrder = Effect.fnUntraced(function* (oids) {
944
- const where = yield* found(oids, kept, true);
1328
+ const where = yield* found(oids, "listed");
945
1329
  return [...byPlace(where).map(([oid]) => oid), ...oids.filter((oid) => !where.has(oid))];
946
1330
  });
947
1331
  /**
@@ -954,23 +1338,84 @@ const packReader = (input) => {
954
1338
  wholeAt.clear();
955
1339
  kept.clear();
956
1340
  };
957
- const reads = {
958
- indexed: Effect.fnUntraced(function* (pack) {
959
- const known = kept.get(pack.id);
960
- if (known !== void 0) return known;
961
- if (!charged.has(pack.id)) {
962
- yield* memory.index(indexBytes(pack));
963
- charged.add(pack.id);
1341
+ /**
1342
+ * A listed pack's `.idx` and `.rev` as this reader holds them: loaded and charged as its own
1343
+ * lookups load them, once a pack, through the server's cache, so a fetch's index path and its
1344
+ * walk read them once between them, and none when the cache holds them.
1345
+ */
1346
+ const indexed = Effect.fnUntraced(function* (pack) {
1347
+ const known = kept.get(pack.id);
1348
+ if (known !== void 0) return known;
1349
+ yield* charge(pack);
1350
+ const loaded = yield* indexes.load(bucket, pack);
1351
+ kept.set(pack.id, loaded);
1352
+ return loaded;
1353
+ });
1354
+ /**
1355
+ * `ObjectReader.startingWith`: the IDs that start with `prefix` in the listed packs and the rows;
1356
+ * then, unless the rows were read at the listing's own version, in the packs listed since and
1357
+ * those leaving, where a merge that folded rows after this read's listing put them. Each pack is
1358
+ * opened by range, as `openRanges` opens it, and only its IDs under the prefix's first byte read,
1359
+ * never loaded whole; each place gives at most `most + 1`, so `more` holds past `most`.
1360
+ */
1361
+ const startingWith = Effect.fnUntraced(function* (prefix, most) {
1362
+ const found = [];
1363
+ const look = Effect.fnUntraced(function* (packs, going) {
1364
+ for (const { id, bytes, objects } of packs) {
1365
+ if (!isPackId(id)) return yield* Effect.fail(lost(`The pack row '${id}' doesn't name a pack`));
1366
+ const ids = yield* Effect.flatMap(openRanges(bucket, {
1367
+ id,
1368
+ bytes
1369
+ }, objects, 0), (ranges) => idsStartingWith(ranges, prefix, most)).pipe(Effect.catch((error) => going && error.code === "DATA_LOSS" ? Effect.succeed([]) : Effect.fail(error)));
1370
+ found.push(ids);
964
1371
  }
965
- const loaded = yield* indexes.load(bucket, pack);
966
- kept.set(pack.id, loaded);
967
- return loaded;
968
- }),
1372
+ });
1373
+ yield* look(listed.packs, false);
1374
+ if (listedOnly === true) return startingOf(found, most);
1375
+ const inRows = yield* rowsStartingWith(store, listed.repo, prefix, most + 1);
1376
+ found.push(inRows.oids);
1377
+ if (inRows.version === listed.version) return startingOf(found, most);
1378
+ yield* look(yield* listedSince(), false);
1379
+ let after;
1380
+ do {
1381
+ const page = yield* leavingPage(after);
1382
+ yield* look(page.packs, true);
1383
+ after = page.next;
1384
+ } while (after !== void 0);
1385
+ return startingOf(found, most);
1386
+ });
1387
+ /**
1388
+ * Reads of IDs a reachability index proves none of `covered`'s packs holds, as `UnplacedReads`
1389
+ * says: the rows and the other packs, never a covered pack's `.idx` and `.rev` (#522).
1390
+ */
1391
+ const unplaced = (covered) => {
1392
+ const take = eachOf(covered);
1393
+ return {
1394
+ each: take,
1395
+ held: heldOf(take),
1396
+ sizes: sizesOf(covered),
1397
+ find: (oids) => storedOf(oids, covered),
1398
+ packed: (oids) => Effect.map(found(oids, "listed", covered), (where) => new Set(where.keys()))
1399
+ };
1400
+ };
1401
+ const reads = {
1402
+ indexed,
1403
+ loadedOf: (pack) => kept.get(pack.id),
1404
+ onLoading: (told) => {
1405
+ loadings.add(told);
1406
+ return () => {
1407
+ loadings.delete(told);
1408
+ };
1409
+ },
969
1410
  held,
1411
+ unplaced,
970
1412
  heldAt,
971
1413
  each,
972
1414
  has,
1415
+ seenHeld: has,
1416
+ startingWith,
973
1417
  heldIn,
1418
+ beyond,
974
1419
  headers,
975
1420
  sizes,
976
1421
  sizesAt,
@@ -984,24 +1429,51 @@ const packReader = (input) => {
984
1429
  };
985
1430
  return input.visible === void 0 ? reads : narrowedTo(reads, input.visible);
986
1431
  };
1432
+ /**
1433
+ * The IDs a narrowed short-ID read asks its view about: `found`, then IDs that start with
1434
+ * `prefix` past them, up to `most` in all, so the view's reads turn on how many are asked, never
1435
+ * on how many the repo holds. A short ID of 39 digits starts 16, so it asks at most those.
1436
+ */
1437
+ const askedOf = (found, prefix, most) => {
1438
+ const asked = new Set(found);
1439
+ const free = 40 - prefix.length;
1440
+ for (let at = 0; free > 0 && asked.size < most && at < 16 ** free; at += 1) asked.add(`${prefix}${at.toString(16).padStart(free, "0")}`);
1441
+ return [...asked];
1442
+ };
987
1443
  /** `reads`, each lookup by ID answering only what `visible` holds, as `PackReaderInput` says. */
988
1444
  const narrowedTo = (reads, visible) => {
989
- const only = (oids) => Effect.map(visible(oids), (kept) => oids.filter((oid) => kept.has(oid)));
1445
+ const only = (oids, asked = visible) => Effect.map(asked(oids), (kept) => oids.filter((oid) => kept.has(oid)));
990
1446
  return {
991
1447
  ...reads,
992
1448
  held: (oids) => Effect.flatMap(only(oids), reads.held),
993
1449
  each: (oids, take) => Effect.flatMap(only(oids), (kept) => reads.each(kept, take)),
994
- has: (oids, loaded) => Effect.flatMap(only(oids), (kept) => reads.has(kept, loaded)),
995
- heldIn: (oids, loaded) => Effect.flatMap(only(oids), (kept) => reads.heldIn(kept, loaded)),
1450
+ unplaced: (covered) => {
1451
+ const outside = reads.unplaced(covered);
1452
+ return {
1453
+ each: (oids, take) => Effect.flatMap(only(oids), (kept) => outside.each(kept, take)),
1454
+ held: (oids) => Effect.flatMap(only(oids), outside.held),
1455
+ sizes: (oids) => Effect.flatMap(only(oids), outside.sizes),
1456
+ find: (oids) => Effect.flatMap(only(oids), outside.find),
1457
+ packed: (oids) => Effect.flatMap(only(oids), outside.packed)
1458
+ };
1459
+ },
1460
+ has: (oids) => Effect.flatMap(only(oids), reads.has),
1461
+ seenHeld: (oids) => Effect.flatMap(only(oids, visible.shown), (kept) => reads.has(kept)),
1462
+ startingWith: (prefix, most) => Effect.flatMap(reads.startingWith(prefix, most), (found) => Effect.map(only(askedOf(found.oids, prefix, most)), (kept) => ({
1463
+ oids: found.oids.filter((oid) => kept.includes(oid)),
1464
+ more: found.more
1465
+ }))),
1466
+ heldIn: (oids) => Effect.flatMap(only(oids), reads.heldIn),
1467
+ beyond: (oids) => Effect.flatMap(only(oids), reads.beyond),
996
1468
  headers: (oids) => Effect.flatMap(only(oids), reads.headers),
997
1469
  sizes: (oids) => Effect.flatMap(only(oids), reads.sizes),
998
1470
  stored: {
999
1471
  ...reads.stored,
1000
- find: (oids, loaded) => Effect.flatMap(only(oids), (kept) => reads.stored.find(kept, loaded))
1472
+ find: (oids) => Effect.flatMap(only(oids), reads.stored.find)
1001
1473
  },
1002
1474
  object: (oid, signal) => Effect.flatMap(only([oid]), (kept) => kept.length === 0 ? Effect.succeed(void 0) : reads.object(oid, signal)),
1003
1475
  objects: (oids, allotment) => Effect.flatMap(only(oids), (kept) => reads.objects(kept, allotment)),
1004
1476
  wholeBlobs: (oids) => Effect.flatMap(only(oids), reads.wholeBlobs)
1005
1477
  };
1006
1478
  };
1007
- export { PackBlocks, PackIndexes, blockBytes, blockHeld, fixedReaderMemory, hashedNowMost, hashedRunMost, headerLimits, indexBytes, packFileBytes, packIndexerLimits, packObjectBytes, packObjects, packReader, readCacheBytes, readWhole };
1479
+ export { PackBlocks, PackIndexes, blockBytes, blockHeld, blocksHeld, entryEnd, hashedNowMost, hashedRunMost, headerLimits, indexBytes, indexSeedShare, loadedLookup, packFileBytes, packIndexerLimits, packObjectBytes, packObjects, packReader, rangedLookup, readCacheBytes, seedBytes };