@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
@@ -4,14 +4,17 @@ import { runKey, runsPrefix } from "./layout.mjs";
4
4
  import { startPut } from "./merge.mjs";
5
5
  import { readExactly } from "./pack-ranges.mjs";
6
6
  import { receiveDropPage, receiveMergeReadBytes, receiveRunBytes } from "./receive-bounds.mjs";
7
- import * as Effect from "effect/Effect";
8
7
  import * as Schema from "effect/Schema";
8
+ import * as Effect from "effect/Effect";
9
9
  // src/storage/runs.ts
10
10
  /**
11
11
  * Rows of one kind, spilled under a pack's runs: each `width` bytes, ordered as unsigned bytes from
12
12
  * the first, so a kind whose rows start with an ID is in the ID's order. Each run is sorted on its
13
13
  * own, and a merge of them reads every row once, in order. As a row stores them, so a step's next
14
14
  * try merges runs an earlier one put: `lengths` are each run's bytes, a multiple of `width`.
15
+ * `chains` are how many runs each chain holds, in order, when some runs follow on from the one
16
+ * before: a chain's runs are one sorted run cut in parts, each row past every row before it, so a
17
+ * merge reads a chain as one way, a part after the other (#2690). Unset, each run is a chain.
15
18
  */
16
19
  const StoredRuns = /* @__PURE__ */ Schema.Struct({
17
20
  kind: Schema.String,
@@ -27,10 +30,15 @@ const StoredRuns = /* @__PURE__ */ Schema.Struct({
27
30
  rows: Schema.Int.check(Schema.isBetween({
28
31
  minimum: 0,
29
32
  maximum: Number.MAX_SAFE_INTEGER
30
- }))
33
+ })),
34
+ chains: Schema.optionalKey(Schema.Array(Schema.Int.check(Schema.isBetween({
35
+ minimum: 1,
36
+ maximum: Number.MAX_SAFE_INTEGER
37
+ }))))
31
38
  }).check(Schema.makeFilter((runs) => {
32
39
  if (runs.keys.length !== runs.lengths.length) return "its keys and lengths are not one a run";
33
40
  if (runs.lengths.some((length) => length % runs.width !== 0)) return "a run is not whole rows";
41
+ if (runs.chains !== void 0 && runs.chains.reduce((sum, count) => sum + count, 0) !== runs.keys.length) return "its chains are not its runs";
34
42
  return runs.lengths.reduce((sum, length) => sum + length, 0) === runs.rows * runs.width || "its rows are not its runs' rows";
35
43
  }));
36
44
  /** A receive's runs: `receive-bounds.ts`' constants. */
@@ -206,8 +214,60 @@ var ReceiveRoom = class {
206
214
  return this.#grow(more);
207
215
  }
208
216
  };
209
- /** The reads a merge of `runs` holds, `readBytes` of each run at most: a held run's are its writer's. */
210
- const readsOf = (runs, readBytes) => runs.lengths.reduce((sum, length) => sum + Math.min(readBytes, length), 0);
217
+ /** How many runs each of `runs`' chains holds, in order: one each, unless `chains` says. */
218
+ const chainsOf = (runs) => runs.chains ?? runs.keys.map(() => 1);
219
+ /** `lengths` a chain at a time, as `chains` counts them: a run a chain unless it's set. */
220
+ const partsOf = (lengths, chains) => {
221
+ if (chains === void 0) return lengths.map((length) => [length]);
222
+ let from = 0;
223
+ return chains.map((count) => {
224
+ from += count;
225
+ return lengths.slice(from - count, from);
226
+ });
227
+ };
228
+ /** The bytes each of `runs`' chains holds, in order: a merge's ways, as it reads them. */
229
+ const wayLengths = (runs) => partsOf(runs.lengths, runs.chains).map((parts) => parts.reduce((sum, each) => sum + each, 0));
230
+ /** `runs` with `chains`, or without when each run is its own, as a store keeps them. */
231
+ const withChains = (runs, chains) => {
232
+ const { chains: _dropped, ...rest } = runs;
233
+ return chains.every((count) => count === 1) ? rest : {
234
+ ...rest,
235
+ chains
236
+ };
237
+ };
238
+ /**
239
+ * `put`'s runs after `before`'s, as one chain: `put` a `sorted` writer's, which refuses a row out
240
+ * of order, each of its rows past every row of `before`'s, as a writer that goes on past a save's
241
+ * last row puts them. `before` is one chain already, or none.
242
+ */
243
+ const chained = (before, put) => {
244
+ const parts = [...before === void 0 ? [] : [before], put];
245
+ if (put.held !== void 0 || before !== void 0 && chainsOf(before).length > 1) throw new Error(`${put.kind}'s runs are held, or follow more than one chain`);
246
+ const keys = parts.flatMap((runs) => runs.keys);
247
+ const joined = {
248
+ ...put,
249
+ keys,
250
+ lengths: parts.flatMap((runs) => runs.lengths),
251
+ rows: parts.reduce((sum, runs) => sum + runs.rows, 0)
252
+ };
253
+ return withChains(joined, keys.length === 0 ? [] : [keys.length]);
254
+ };
255
+ /**
256
+ * `a`'s runs and then `b`'s, of one width, as one: their chains side by side, `kind` naming where
257
+ * a merge of them narrows.
258
+ */
259
+ const joinedChains = (a, b, kind = a.kind) => withChains({
260
+ ...a,
261
+ kind,
262
+ keys: [...a.keys, ...b.keys],
263
+ lengths: [...a.lengths, ...b.lengths],
264
+ rows: a.rows + b.rows
265
+ }, [...chainsOf(a), ...chainsOf(b)]);
266
+ /**
267
+ * The reads a merge of `runs` holds: of each chain, `readBytes` of its longest run at most. A held
268
+ * run's are its writer's.
269
+ */
270
+ const readsOf = (runs, readBytes) => partsOf(runs.lengths, runs.chains).reduce((sum, parts) => sum + Math.min(readBytes, parts.reduce((most, each) => Math.max(most, each), 0)), 0);
211
271
  /**
212
272
  * The first `order.length` rows of `bytes` put in `order`, in place: one cycle of the order at a
213
273
  * time, through one spare row and a mark a row, so the sort holds no second copy of the rows.
@@ -432,7 +492,33 @@ const runWriter = (bucket, pack, kind, width, { bytes = receiveRunBytes, first =
432
492
  most
433
493
  };
434
494
  };
495
+ /** `cursor` on its chain's `part`th run, nothing of it read. */
496
+ const onPart = (cursor, part) => {
497
+ for (; cursor.part < part; cursor.part += 1) cursor.before += cursor.lengths[cursor.part] ?? 0;
498
+ cursor.key = cursor.keys[part] ?? "";
499
+ cursor.length = cursor.lengths[part] ?? 0;
500
+ cursor.read = 0;
501
+ cursor.chunk = /* @__PURE__ */ new Uint8Array(0);
502
+ cursor.at = 0;
503
+ };
435
504
  const lost = (message) => gitError("DATA_LOSS", message);
505
+ /** A chain's run `key` that starts before the run ahead of it ends: no chain, its rows not in order. */
506
+ const outOfOrder = (key) => lost(`A chain's run ${key} starts before the one ahead of it ends`);
507
+ /**
508
+ * The reads a merge of `runs` from `starts` makes besides each chain's first: one for each chain
509
+ * whose start is a run's first row past the chain's first, which reads the last row of the run
510
+ * ahead to check their order.
511
+ */
512
+ const seekChecks = (runs, starts) => partsOf(runs.lengths, runs.chains).filter((lengths, way) => {
513
+ const start = (starts[way] ?? 0) * runs.width;
514
+ let bytes = 0;
515
+ for (const length of lengths.slice(0, -1)) {
516
+ bytes += length;
517
+ if (bytes === start) return true;
518
+ if (bytes > start) return false;
519
+ }
520
+ return false;
521
+ }).length;
436
522
  /** The next chunk of `cursor`'s run, or an empty one at its end. */
437
523
  const refill = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, cursor, readBytes) {
438
524
  const length = Math.min(readBytes, cursor.length - cursor.read);
@@ -442,10 +528,12 @@ const refill = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, cursor, read
442
528
  cursor.at = 0;
443
529
  });
444
530
  /**
445
- * The rows of `runs`, `bounds.ways` of them at most, in order, a row each `next`: a heap of
446
- * one cursor a run, each holding one read, taken from `room` until the last row is passed. A row's
447
- * bytes stay as they are after the next `next`, since a read takes new bytes, never the old ones.
448
- * Its reads are ⌈length / read⌉ a run. Each run is read from its row of `starts`, when it's given.
531
+ * The rows of `runs`, `bounds.ways` chains of them at most, in order, a row each `next`: a heap of
532
+ * one cursor a chain, each holding one read, taken from `room` until the last row is passed. A
533
+ * chain's runs are read one after the other, the next one's first read as the one before ends. A
534
+ * row's bytes stay as they are after the next `next`, since a read takes new bytes, never the old
535
+ * ones. Its reads are ⌈length / read⌉ a run. Each chain is read from its row of `starts`, when
536
+ * it's given.
449
537
  */
450
538
  const fewCursor = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, runs, bounds, room, starts) {
451
539
  const { width } = runs;
@@ -485,38 +573,66 @@ const fewCursor = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, runs, bou
485
573
  const { held } = runs;
486
574
  const length = held.byteLength;
487
575
  heap.push({
488
- key: "",
489
576
  run: -1,
577
+ keys: [""],
578
+ lengths: [length],
579
+ part: 0,
580
+ before: 0,
581
+ key: "",
490
582
  length,
491
583
  read: length,
492
584
  chunk: held,
493
585
  at: 0
494
586
  });
495
587
  }
496
- if (starts !== void 0 && (starts.length !== runs.keys.length || runs.held !== void 0)) return yield* Effect.fail(lost(`A merge seeks ${starts.length} of ${runs.keys.length} runs`));
497
- for (const [index, key] of runs.keys.entries()) {
588
+ const chains = partsOf(runs.lengths, runs.chains);
589
+ if (starts !== void 0 && (starts.length !== chains.length || runs.held !== void 0)) return yield* Effect.fail(lost(`A merge seeks ${starts.length} of ${chains.length} chains`));
590
+ let first = 0;
591
+ for (const [index, lengths] of chains.entries()) {
592
+ const keys = runs.keys.slice(first, first + lengths.length);
593
+ first += lengths.length;
498
594
  const start = (starts?.[index] ?? 0) * width;
499
595
  const cursor = {
500
- key,
501
596
  run: index,
502
- length: runs.lengths[index] ?? 0,
503
- read: start - start % readBytes,
597
+ keys,
598
+ lengths,
599
+ part: 0,
600
+ before: 0,
601
+ key: "",
602
+ length: 0,
603
+ read: 0,
504
604
  chunk: /* @__PURE__ */ new Uint8Array(0),
505
605
  at: 0
506
606
  };
507
607
  cursors.push(cursor);
508
- if (start > cursor.length) return yield* Effect.fail(lost(`A merge seeks past its run ${key}'s rows`));
509
- if (start === cursor.length) {
510
- cursor.read = start;
608
+ let part = 0;
609
+ for (let bytes = 0; part < lengths.length - 1; part += 1) {
610
+ bytes += lengths[part] ?? 0;
611
+ if (bytes > start) break;
612
+ }
613
+ onPart(cursor, part);
614
+ const inPart = start - cursor.before;
615
+ if (inPart > cursor.length) return yield* Effect.fail(lost(`A merge seeks past its chain ${keys[0] ?? ""}'s rows`));
616
+ if (inPart === cursor.length) {
617
+ cursor.read = inPart;
511
618
  continue;
512
619
  }
620
+ cursor.read = inPart - inPart % readBytes;
513
621
  yield* refill(bucket, cursor, readBytes);
514
- cursor.at = start % readBytes;
622
+ cursor.at = inPart % readBytes;
623
+ if (inPart === 0 && part > 0) {
624
+ const ahead = lengths[part - 1] ?? 0;
625
+ const ended = yield* readExactly(bucket, keys[part - 1] ?? "", ahead - width, width);
626
+ if (compare(cursor.chunk, 0, ended, 0, width) < 0) return yield* Effect.fail(outOfOrder(cursor.key));
627
+ }
515
628
  heap.push(cursor);
516
629
  }
517
630
  for (let at = Math.floor(heap.length / 2) - 1; at >= 0; at -= 1) down(at);
518
- const places = () => cursors.map((cursor) => (cursor.read - cursor.chunk.byteLength + cursor.at) / width);
519
- /** The least cursor moved past the row it answered: refilled, or out of the heap at its end. */
631
+ const places = () => cursors.map((cursor) => (cursor.before + cursor.read - cursor.chunk.byteLength + cursor.at) / width);
632
+ /**
633
+ * The least cursor moved past the row it answered: refilled, on to its chain's next run, or out
634
+ * of the heap at its chain's end.
635
+ */
520
636
  const passed = () => {
521
637
  const least = heap[0];
522
638
  if (least === void 0) return void 0;
@@ -528,6 +644,15 @@ const fewCursor = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, runs, bou
528
644
  if (least.read < least.length) return Effect.map(refill(bucket, least, readBytes), () => {
529
645
  down(0);
530
646
  });
647
+ if (least.part + 1 < least.lengths.length) {
648
+ const ended = least.chunk.subarray(least.chunk.byteLength - width);
649
+ onPart(least, least.part + 1);
650
+ return Effect.flatMap(refill(bucket, least, readBytes), () => {
651
+ if (compare(least.chunk, 0, ended, 0, width) < 0) return Effect.fail(outOfOrder(least.key));
652
+ down(0);
653
+ return Effect.void;
654
+ });
655
+ }
531
656
  const last = heap.pop();
532
657
  if (last === void 0 || heap.length === 0) return void 0;
533
658
  heap[0] = last;
@@ -571,22 +696,27 @@ const eachRow = /* @__PURE__ */ Effect.fnUntraced(function* (cursor, places, eac
571
696
  /** Every row of `runs`, at most `bounds.ways` of them, in order, through `each`, from `starts`. */
572
697
  const mergeFew = (bucket, runs, each, bounds, room, starts) => Effect.flatMap(fewCursor(bucket, runs, bounds, room, starts), ({ next, places }) => eachRow(next, places, each));
573
698
  /**
574
- * `runs` merged `bounds.ways` at a time into fewer, longer runs under `pack`, until no more than
575
- * that many are left: each pass reads and puts every row once, its reads and its chunk taken from
576
- * `room` as it merges. A caller merging the same runs more than once narrows them once first.
699
+ * `runs` merged `bounds.ways` chains at a time into fewer, longer runs under `pack`, until no more
700
+ * than that many chains are left: each pass reads and puts every row once, its reads and its chunk
701
+ * taken from `room` as it merges. Each run it puts is a chain of its own. A caller merging the
702
+ * same runs more than once narrows them once first.
577
703
  */
578
704
  const narrowed = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, runs, bounds, room) {
579
705
  const { ways } = bounds;
580
706
  let current = runs;
581
- for (let pass = 1; current.keys.length > ways; pass += 1) {
707
+ for (let pass = 1; chainsOf(current).length > ways; pass += 1) {
582
708
  const keys = [];
583
709
  const lengths = [];
584
- for (let from = 0; from < current.keys.length; from += ways) {
585
- const group = {
710
+ const chains = chainsOf(current);
711
+ for (let from = 0, first = 0; from < chains.length; from += ways) {
712
+ const counts = chains.slice(from, from + ways);
713
+ const count = counts.reduce((sum, each) => sum + each, 0);
714
+ const group = withChains({
586
715
  ...current,
587
- keys: current.keys.slice(from, from + ways),
588
- lengths: current.lengths.slice(from, from + ways)
589
- };
716
+ keys: current.keys.slice(first, first + count),
717
+ lengths: current.lengths.slice(first, first + count)
718
+ }, counts);
719
+ first += count;
590
720
  const length = group.lengths.reduce((sum, each) => sum + each, 0);
591
721
  const key = runKey(pack, `${runs.kind}.${pass}`, keys.length);
592
722
  const chunkBytes = Math.max(1, Math.floor(writeBytes / runs.width)) * runs.width;
@@ -615,40 +745,61 @@ const narrowed = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, runs
615
745
  keys.push(key);
616
746
  lengths.push(length);
617
747
  }
618
- current = {
748
+ current = withChains({
619
749
  ...current,
620
750
  keys,
621
751
  lengths
622
- };
752
+ }, []);
623
753
  }
624
754
  return current;
625
755
  });
626
756
  /**
627
- * The bucket calls `narrowed` makes over runs of `lengths` bytes of `width`-byte rows, and the runs
628
- * it leaves: each pass's read of every `readBytes` of each run it merges, and the put of each run it
629
- * merges them to.
757
+ * The bucket calls `narrowed` makes over runs of `lengths` bytes of `width`-byte rows, in `chains`
758
+ * when set, and the runs and ways it leaves: each pass's read of every `readBytes` of each run it
759
+ * merges, and the put of each run it merges a group of chains to.
630
760
  */
631
- const narrowedCalls = (lengths, width, bounds, multipart) => {
761
+ const narrowedCalls = (lengths, width, bounds, multipart, chains) => {
632
762
  const readBytes = wholeRows(width, bounds.readBytes);
633
- let current = lengths;
763
+ let current = partsOf(lengths, chains);
634
764
  let calls = 0;
635
765
  while (current.length > bounds.ways) {
636
766
  const next = [];
637
767
  for (let from = 0; from < current.length; from += bounds.ways) {
638
- const group = current.slice(from, from + bounds.ways);
768
+ const group = current.slice(from, from + bounds.ways).flat();
639
769
  const length = group.reduce((sum, each) => sum + each, 0);
640
770
  calls += group.reduce((sum, each) => sum + Math.ceil(each / readBytes), 0);
641
771
  calls += sizedPutCalls(multipart, length);
642
- next.push(length);
772
+ next.push([length]);
643
773
  }
644
774
  current = next;
645
775
  }
646
776
  return {
647
777
  calls,
648
- runs: current.length
778
+ runs: current.flat().length,
779
+ ways: current.length
649
780
  };
650
781
  };
651
782
  /**
783
+ * The bucket calls `mergeRuns` makes over `runs`, a forecast: `narrowedCalls`, then a read of each
784
+ * `readBytes` of the runs it leaves.
785
+ */
786
+ const mergeRunsCalls = (runs, bounds, multipart) => {
787
+ const narrowing = narrowedCalls(runs.lengths, runs.width, bounds, multipart, runs.chains);
788
+ const bytes = runs.lengths.reduce((sum, length) => sum + length, 0);
789
+ return narrowing.calls + Math.ceil(bytes / wholeRows(runs.width, bounds.readBytes)) + narrowing.runs;
790
+ };
791
+ /**
792
+ * The reads a merge of runs of `lengths` bytes of `width`-byte rows makes, at most, to pass `rows`
793
+ * of their rows from `places` and look at the one after: each run it hasn't read out, once at its
794
+ * place and once more as its cursor passes that read's end, and a read for each `readBytes` the
795
+ * rows it passes take beyond those. A run's cursor reads on as soon as it passes a read's end, so
796
+ * many runs read from their places may each read again within a few rows.
797
+ */
798
+ const passedReads = (lengths, width, places, rows, bounds) => {
799
+ const readBytes = wholeRows(width, bounds.readBytes);
800
+ return 2 * lengths.filter((length, run) => (places?.[run] ?? 0) * width < length).length + Math.floor((rows + 1) * width / readBytes);
801
+ };
802
+ /**
652
803
  * Every row of `runs` in order, through `each`, however many runs there are: past `bounds.ways`,
653
804
  * they're first merged into that many under `pack`'s runs. Its reads are taken from `room` as it
654
805
  * reads. Given `starts`, the places an earlier merge of the same runs passed, each run it merges
@@ -668,20 +819,21 @@ const mergedCursor = (bucket, pack, runs, bounds = receiveRuns, room) => Effect.
668
819
  */
669
820
  const stepRunKind = (kind, step, attempt) => `${kind}-${step}-${attempt}`;
670
821
  /**
671
- * The runs of one kind its steps put, as one writer's: each step's keys in order, so a merge reads
672
- * them as it reads one writer's. A step's runs are put always, so none holds rows. Its rows are
673
- * those its runs hold: a deduping writer's `rows` counts the repeats it dropped too.
822
+ * The runs of one kind its steps put, as one writer's: each step's keys in order, and its chains,
823
+ * so a merge reads them as it reads one writer's. A step's runs are put always, so none holds rows.
824
+ * Its rows are those its runs hold: a deduping writer's `rows` counts the repeats it dropped too.
674
825
  */
675
826
  const joinedRuns = (kind, width, steps) => {
676
827
  if (steps.some((runs) => runs.width !== width || runs.held !== void 0)) throw new Error(`a step's ${kind} runs are held, or not ${width}-byte rows`);
677
828
  const lengths = steps.flatMap((runs) => runs.lengths);
678
- return {
829
+ const joined = {
679
830
  kind,
680
831
  width,
681
832
  keys: steps.flatMap((runs) => runs.keys),
682
833
  lengths,
683
834
  rows: lengths.reduce((sum, length) => sum + length, 0) / width
684
835
  };
836
+ return withChains(joined, steps.flatMap(chainsOf));
685
837
  };
686
838
  /**
687
839
  * `runWriter`, or with `step`, one step's of a writer that spans steps: its runs put always under
@@ -737,4 +889,4 @@ const dropRuns = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, kept
737
889
  }
738
890
  return "more";
739
891
  });
740
- export { ReceiveRoom, StoredRuns, cursorHeld, dedupeTableBytes, dropRuns, firstBytesOf, joinedRuns, mergeHeld, mergeRuns, mergedCursor, narrowed, narrowedCalls, receiveRuns, runWriter, sortedWriterHeld, stepRunKind, steppedWriter, wholeRows, writerHeld, writersHeld };
892
+ export { ReceiveRoom, StoredRuns, chained, chainsOf, cursorHeld, dedupeTableBytes, dropRuns, firstBytesOf, joinedChains, joinedRuns, mergeHeld, mergeRuns, mergeRunsCalls, mergedCursor, narrowed, narrowedCalls, passedReads, receiveRuns, runWriter, seekChecks, sortedWriterHeld, stepRunKind, steppedWriter, wayLengths, wholeRows, writerHeld, writersHeld };
@@ -3,6 +3,7 @@ import "../contracts/result.mjs";
3
3
  import "../contracts/store.mjs";
4
4
  import "./fetch.mjs";
5
5
  import "./index-build.mjs";
6
+ import "./index-files.mjs";
6
7
  import "./pack-reads.mjs";
7
8
  import "./pack-ranges.mjs";
8
9
  import "./walk.mjs";
@@ -4,7 +4,7 @@ import { bitmapWords } from "./ewah.mjs";
4
4
  import { basesBlock, openBases } from "./index-files.mjs";
5
5
  import { indexFiles } from "./layout.mjs";
6
6
  import { indexBytes, loadedLookup, rangedLookup } from "./pack-reads.mjs";
7
- import { openPlacedTables, placedEntries, placedEntriesBytes, placedEntriesGets, searchReads } from "./pack-ranges.mjs";
7
+ import { placedEntries, placedEntriesBytes, placedEntriesGets, placedTablesOf, searchReads } from "./pack-ranges.mjs";
8
8
  import { hexOf } from "../protocol/bytes/hex.mjs";
9
9
  import { stepEffect } from "../protocol/packs/step.mjs";
10
10
  import * as Effect from "effect/Effect";
@@ -183,6 +183,14 @@ const basesReadBytes = (positions) => positions * 8 * 6;
183
183
  /** What a run of `.bases` rows holds as it's read, charged once before the first. */
184
184
  const basesRunBytes = basesReadBytes(basesRun * basesBlock);
185
185
  const loss = (message) => gitError("DATA_LOSS", message);
186
+ /**
187
+ * `input`'s forecasts of the index's own reads, its `.bases` and a covered pack's `.idx`: none
188
+ * when it's held whole, as `bucket` then serves them with no call (#2523).
189
+ */
190
+ const indexAheadOf = (input) => input.indexHeld === true ? (forecast) => input.ahead({
191
+ bucket: 0,
192
+ store: forecast.store
193
+ }) : input.ahead;
186
194
  /** The runs of `.bases` blocks in `[from, to)` that hold a position of `wanted`, as read ranges. */
187
195
  const basesRuns = (wanted, from, to) => {
188
196
  const runs = [];
@@ -199,6 +207,14 @@ const basesRuns = (wanted, from, to) => {
199
207
  }
200
208
  return runs;
201
209
  };
210
+ /** `got`, the rows of a `.bases` read over `reading`, into `rows` by block: each its own pairs. */
211
+ const keepBlocks = (rows, reading, got) => {
212
+ for (let block = Math.floor(reading.from / basesBlock), row = 0; block * basesBlock < reading.to; block += 1) {
213
+ const from = row;
214
+ while (row < got.length && (got[row] ?? 0) < (block + 1) * 4096) row += 2;
215
+ rows.set(block, got.subarray(from, row));
216
+ }
217
+ };
202
218
  /** What a list keeps of an entry read by place: its place, ID, offset, CRC-32 and end. */
203
219
  const placedKeptBytes = 44;
204
220
  /**
@@ -220,7 +236,7 @@ const readPlaces = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, pla
220
236
  if (places.length === 0) return;
221
237
  const held = placedHeldBytes(places.length, pack.table.places.length);
222
238
  yield* input.ahead({
223
- bucket: placedEntriesGets(pack.count, pack.pack.bytes, places),
239
+ bucket: (pack.tables.headerChecked ? 0 : 1) + placedEntriesGets(pack.count, pack.pack.bytes, places),
224
240
  store: 0
225
241
  });
226
242
  yield* input.read.hold(held);
@@ -271,26 +287,35 @@ const listOf = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
271
287
  const indexed = read.indexed;
272
288
  const sizesAt = read.sizesAt;
273
289
  if (indexed === void 0 || sizesAt === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("a send list needs the reader to have loaded its packs"));
274
- const packs = [];
275
- const ranged = [];
290
+ const active = [];
276
291
  for (const ranges of input.ranges) {
277
292
  const places = placesIn(send, ranges.base, ranges.count);
278
293
  if (places.length === 0) continue;
279
294
  const pack = input.listed.packs.find(({ id }) => id === ranges.pack.id);
280
295
  if (pack === void 0) return yield* Effect.fail(loss(`Pack ${ranges.pack.id} isn't listed`));
296
+ active.push({
297
+ ranges,
298
+ places,
299
+ pack
300
+ });
301
+ }
302
+ const loadedPacks = yield* Effect.forEach(active, Effect.fnUntraced(function* ({ ranges, places, pack }) {
281
303
  if (ranges.reverse !== void 0 || indexBytes(pack) <= placedHeldBytes(places.length, 0)) {
282
- packs.push(loadedPack(ranges.base, yield* indexed(pack)));
283
- continue;
304
+ const from = input.indexHeld === true ? input.bucket : void 0;
305
+ return {
306
+ pack: loadedPack(ranges.base, yield* indexed(pack, from)),
307
+ ranged: void 0
308
+ };
284
309
  }
285
- yield* ahead({
286
- bucket: 1,
287
- store: 0
288
- });
289
- const placed = new RangedPack(ranges, yield* openPlacedTables(input.bucket, ranges.pack, ranges.count), ahead);
310
+ const placed = new RangedPack(ranges, placedTablesOf(input.bucket, ranges.pack, ranges.count), indexAheadOf(input));
290
311
  yield* readPlaces(input, placed, places);
291
- packs.push(placed);
292
- ranged.push(placed);
293
- }
312
+ return {
313
+ pack: placed,
314
+ ranged: placed
315
+ };
316
+ }), { concurrency: 5 });
317
+ const packs = loadedPacks.map(({ pack }) => pack);
318
+ const ranged = loadedPacks.flatMap(({ ranged }) => ranged === void 0 ? [] : [ranged]);
294
319
  /** The size of each of `list`'s objects `wanted` picks, by its header, a pack's batch at a time. */
295
320
  const headerSizes = Effect.fnUntraced(function* (list, wanted, sized) {
296
321
  const cursor = new ListCursor(list);
@@ -370,7 +395,10 @@ const listOf = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
370
395
  bases,
371
396
  chains
372
397
  };
373
- for (const pack of ranged) yield* readChains(input, list, pack);
398
+ yield* Effect.forEach(ranged, (pack) => readChains(input, list, pack), {
399
+ concurrency: 5,
400
+ discard: true
401
+ });
374
402
  for (const cursor = new ListCursor(list); !cursor.done; cursor.next()) if (isSet(copied, cursor.ordinal)) sized(cursor.ordinal, cursor.inPack.at(cursor.position).bytes);
375
403
  yield* headerSizes(list, (ordinal) => !isSet(copied, ordinal) && !isBlob(ordinal), sized);
376
404
  let bytes = 0;
@@ -402,13 +430,14 @@ const emptyList = (input, packs) => {
402
430
  * written-whole delta's chain of bases down to a whole entry.
403
431
  */
404
432
  const copiesOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, list) {
405
- const { send, held, read, ahead } = input;
433
+ const { send, held, read } = input;
434
+ const ahead = indexAheadOf(input);
406
435
  const copiesAgainst = (base) => isSet(send, base) || held !== void 0 && isSet(held, base);
407
436
  const deltas = new Uint32Array(bitmapWords(list.count));
408
437
  const copied = new Uint32Array(bitmapWords(list.count));
409
438
  const bases = new Uint32Array(list.count);
410
439
  const chains = /* @__PURE__ */ new Map();
411
- const opened = /* @__PURE__ */ new Map();
440
+ const opened = new Map(input.bases);
412
441
  const packOf = (position) => list.packs.find((pack) => position >= pack.base && position < pack.base + pack.count);
413
442
  yield* read.hold(basesRunBytes);
414
443
  const basesOf = Effect.fnUntraced(function* (layer) {
@@ -428,29 +457,69 @@ const copiesOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, list) {
428
457
  const pack = packOf(position);
429
458
  return pack === void 0 || base >= position || base < pack.base ? Effect.fail(loss(`The index's .bases names ${base} as ${position}'s base, not before it in its pack`)) : Effect.succeed(base);
430
459
  };
460
+ const kept = /* @__PURE__ */ new Map();
461
+ const keptOf = (layer) => {
462
+ const rows = kept.get(layer) ?? /* @__PURE__ */ new Map();
463
+ kept.set(layer, rows);
464
+ return rows;
465
+ };
466
+ let keptBytes = 0;
467
+ const keepRun = Effect.fnUntraced(function* (layer, reading, got) {
468
+ const bytes = basesReadBytes(reading.to - reading.from);
469
+ yield* read.hold(bytes);
470
+ keptBytes += bytes;
471
+ keepBlocks(keptOf(layer), reading, got);
472
+ });
431
473
  let pending = [];
432
474
  const cursor = new ListCursor(list);
433
475
  for (const layer of input.layers) {
434
476
  const end = layer.first + layer.positions;
435
477
  if (cursor.done || cursor.position >= end) continue;
436
478
  const runs = layer.deltas === 0 ? [] : basesRuns((block) => anySet(send, block * basesBlock, (block + 1) * basesBlock), layer.first, end);
479
+ const batchOfRun = new Int32Array(runs.length);
480
+ const batches = [];
481
+ for (const [at, reading] of runs.entries()) {
482
+ const last = batches.at(-1);
483
+ const lastPositions = last?.reduce((sum, item) => sum + (item.to - item.from), 0) ?? Number.POSITIVE_INFINITY;
484
+ if (last !== void 0 && last.length < 16 && lastPositions + (reading.to - reading.from) <= basesRun * 4096) {
485
+ last.push(reading);
486
+ batchOfRun[at] = batches.length - 1;
487
+ } else {
488
+ batches.push([reading]);
489
+ batchOfRun[at] = batches.length - 1;
490
+ }
491
+ }
437
492
  let rows = /* @__PURE__ */ new Uint32Array(0);
438
493
  let row = 0;
439
494
  let run = 0;
440
495
  let readRun = -1;
496
+ let readBatch = -1;
497
+ let batchRows = [];
498
+ let batchStart = 0;
499
+ let chainsBefore = 0;
441
500
  for (; !cursor.done && cursor.position < end; cursor.next()) {
442
501
  const { position, ordinal } = cursor;
443
502
  while (run < runs.length && (runs[run]?.to ?? 0) <= position) run += 1;
444
503
  const reading = runs[run];
445
504
  if (reading !== void 0 && reading.from <= position && run !== readRun) {
446
- const bases = yield* basesOf(layer);
447
- yield* ahead({
448
- bucket: 1,
449
- store: 0
450
- });
451
- rows = yield* bases.rowsOf(reading.from, reading.to);
505
+ const done = runs[readRun];
506
+ if (done !== void 0 && pending.length > chainsBefore) yield* keepRun(layer, done, rows);
507
+ const batchIndex = batchOfRun[run] ?? 0;
508
+ if (batchIndex !== readBatch) {
509
+ const bases = yield* basesOf(layer);
510
+ const batch = batches[batchIndex] ?? [];
511
+ yield* ahead({
512
+ bucket: batch.length,
513
+ store: 0
514
+ });
515
+ batchRows = yield* Effect.forEach(batch, (each) => bases.rowsOf(each.from, each.to), { concurrency: 16 });
516
+ readBatch = batchIndex;
517
+ batchStart = run;
518
+ }
519
+ rows = batchRows[run - batchStart] ?? /* @__PURE__ */ new Uint32Array(0);
452
520
  row = 0;
453
521
  readRun = run;
522
+ chainsBefore = pending.length;
454
523
  }
455
524
  while (row < rows.length && (rows[row] ?? 0) < position) row += 2;
456
525
  if (row < rows.length && rows[row] === position) {
@@ -466,6 +535,8 @@ const copiesOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, list) {
466
535
  }
467
536
  } else setBit(copied, ordinal);
468
537
  }
538
+ const done = runs[readRun];
539
+ if (done !== void 0 && pending.length > chainsBefore) yield* keepRun(layer, done, rows);
469
540
  }
470
541
  while (pending.length > 0) {
471
542
  const asked = [...new Set(pending)].filter((base) => !chains.has(base)).sort((a, b) => a - b);
@@ -474,26 +545,36 @@ const copiesOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, list) {
474
545
  const end = layer.first + layer.positions;
475
546
  const inLayer = asked.filter((base) => base >= layer.first && base < end);
476
547
  if (inLayer.length === 0 || layer.deltas === 0) continue;
548
+ const rows = keptOf(layer);
477
549
  const blocks = new Set(inLayer.map((base) => Math.floor(base / basesBlock)));
478
550
  const bases = yield* basesOf(layer);
479
- for (const reading of basesRuns((block) => blocks.has(block), layer.first, end)) {
551
+ const unread = (block) => blocks.has(block) && !rows.has(block);
552
+ const readings = basesRuns(unread, layer.first, end);
553
+ if (readings.length > 0) {
554
+ const bytes = readings.reduce((sum, reading) => sum + basesReadBytes(reading.to - reading.from), 0);
555
+ yield* read.hold(bytes);
556
+ keptBytes += bytes;
480
557
  yield* ahead({
481
- bucket: 1,
558
+ bucket: readings.length,
482
559
  store: 0
483
560
  });
484
- const rows = yield* bases.rowsOf(reading.from, reading.to);
485
- const wanted = new Set(inLayer.filter((base) => base >= reading.from && base < reading.to));
486
- for (let row = 0; row < rows.length; row += 2) {
487
- const position = rows[row] ?? 0;
488
- if (!wanted.has(position)) continue;
489
- const base = yield* baseOf(position, rows[row + 1] ?? 0);
561
+ const fetched = yield* Effect.forEach(readings, (reading) => bases.rowsOf(reading.from, reading.to), { concurrency: 16 });
562
+ for (const [at, reading] of readings.entries()) keepBlocks(rows, reading, fetched[at] ?? /* @__PURE__ */ new Uint32Array(0));
563
+ }
564
+ for (const position of inLayer) {
565
+ const found = rows.get(Math.floor(position / 4096)) ?? /* @__PURE__ */ new Uint32Array(0);
566
+ for (let row = 0; row < found.length; row += 2) {
567
+ if (found[row] !== position) continue;
568
+ const base = yield* baseOf(position, found[row + 1] ?? 0);
490
569
  yield* read.hold(64);
491
570
  chains.set(position, base);
492
571
  pending.push(base);
572
+ break;
493
573
  }
494
574
  }
495
575
  }
496
576
  }
577
+ if (keptBytes > 0) yield* read.release(keptBytes);
497
578
  return {
498
579
  deltas,
499
580
  copied,