@ref0/git 0.20.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (379) hide show
  1. package/dist/access/private-refs.mjs +1 -1
  2. package/dist/auth/access-jwt.mjs +3 -3
  3. package/dist/auth/auth-namespace.d.mts +3 -3
  4. package/dist/auth/auth-namespace.mjs +3 -2
  5. package/dist/auth/auth.d.mts +3 -3
  6. package/dist/auth/auth.mjs +9 -8
  7. package/dist/auth/authorize.mjs +1 -1
  8. package/dist/auth/fences.d.mts +1 -1
  9. package/dist/auth/host-function.mjs +1 -1
  10. package/dist/auth/host-services.mjs +4 -6
  11. package/dist/auth/identify.d.mts +1 -1
  12. package/dist/auth/identify.mjs +6 -0
  13. package/dist/auth/token-cleanup.mjs +2 -2
  14. package/dist/auth/token-rows.mjs +6 -1
  15. package/dist/auth/token-text.mjs +1 -1
  16. package/dist/auth/tokens-base.d.mts +1 -1
  17. package/dist/auth/tokens.d.mts +1 -1
  18. package/dist/auth/tokens.mjs +1 -1
  19. package/dist/client/client.d.mts +15 -7
  20. package/dist/client/client.mjs +21 -12
  21. package/dist/client/git-http.mjs +1 -1
  22. package/dist/client/local.mjs +60 -24
  23. package/dist/client/negotiate.mjs +3 -3
  24. package/dist/client/push-upload.mjs +26 -10
  25. package/dist/client/remote.mjs +4 -3
  26. package/dist/client/run-remote-helper.d.mts +2 -2
  27. package/dist/client/run-remote-helper.mjs +6 -6
  28. package/dist/client/slice-push.d.mts +1 -1
  29. package/dist/client/transport.mjs +3 -3
  30. package/dist/contracts/blobs.d.mts +3 -3
  31. package/dist/contracts/blobs.mjs +1 -1
  32. package/dist/contracts/calls-spent.mjs +5 -33
  33. package/dist/contracts/client.d.mts +15 -14
  34. package/dist/contracts/commits.d.mts +4 -4
  35. package/dist/contracts/commits.mjs +1 -1
  36. package/dist/contracts/engine.d.mts +2 -2
  37. package/dist/contracts/events.d.mts +1 -1
  38. package/dist/contracts/events.mjs +1 -1
  39. package/dist/contracts/files.d.mts +4 -4
  40. package/dist/contracts/files.mjs +1 -1
  41. package/dist/contracts/forks.d.mts +4 -4
  42. package/dist/contracts/forks.mjs +1 -1
  43. package/dist/contracts/git-hooks.d.mts +1 -1
  44. package/dist/contracts/git.d.mts +9 -5
  45. package/dist/contracts/grants.d.mts +1 -1
  46. package/dist/contracts/merges.d.mts +1 -1
  47. package/dist/contracts/object-values.d.mts +1 -0
  48. package/dist/contracts/object-values.mjs +16 -1
  49. package/dist/contracts/objects.d.mts +30 -18
  50. package/dist/contracts/opaque.mjs +1 -1
  51. package/dist/contracts/operations.mjs +1 -1
  52. package/dist/contracts/queue.d.mts +208 -44
  53. package/dist/contracts/queue.mjs +5 -5
  54. package/dist/contracts/refs.d.mts +5 -5
  55. package/dist/contracts/refs.mjs +1 -1
  56. package/dist/contracts/remote.d.mts +3 -6
  57. package/dist/contracts/repos.d.mts +3 -3
  58. package/dist/contracts/repos.mjs +1 -1
  59. package/dist/contracts/result.d.mts +10 -7
  60. package/dist/contracts/result.mjs +8 -3
  61. package/dist/contracts/rules.d.mts +13 -12
  62. package/dist/contracts/server.d.mts +8 -10
  63. package/dist/contracts/services.d.mts +6 -9
  64. package/dist/contracts/services.mjs +1 -2
  65. package/dist/contracts/signin.d.mts +1 -1
  66. package/dist/contracts/store.d.mts +2 -2
  67. package/dist/contracts/sync.d.mts +63 -6
  68. package/dist/contracts/sync.mjs +3 -2
  69. package/dist/contracts/tags.d.mts +3 -3
  70. package/dist/contracts/tags.mjs +1 -1
  71. package/dist/contracts/tokens.d.mts +2 -2
  72. package/dist/contracts/tokens.mjs +1 -1
  73. package/dist/contracts/topics.d.mts +9 -9
  74. package/dist/contracts/trees.d.mts +4 -4
  75. package/dist/contracts/trees.mjs +1 -1
  76. package/dist/contracts/work.d.mts +4 -4
  77. package/dist/contracts/work.mjs +2 -2
  78. package/dist/core/access.d.mts +1 -1
  79. package/dist/core/ancestry.mjs +30 -34
  80. package/dist/core/{promise.mjs → call-groups.mjs} +7 -30
  81. package/dist/core/call-services.mjs +1 -1
  82. package/dist/core/events/deliver.d.mts +2 -2
  83. package/dist/core/events/deliver.mjs +3 -3
  84. package/dist/core/events/retired.mjs +1 -1
  85. package/dist/core/forks.mjs +5 -5
  86. package/dist/core/hooks/groups.mjs +2 -2
  87. package/dist/core/imports.mjs +101 -21
  88. package/dist/core/index-job.mjs +14 -9
  89. package/dist/core/index-lost.d.mts +1 -1
  90. package/dist/core/loose-tally.mjs +38 -15
  91. package/dist/core/merge-parts.d.mts +17 -4
  92. package/dist/core/merge-parts.mjs +7 -2
  93. package/dist/core/mirror-rows.mjs +31 -1
  94. package/dist/core/objects/blobs.mjs +8 -10
  95. package/dist/core/objects/files.mjs +20 -17
  96. package/dist/core/objects/objects-layer.mjs +1 -1
  97. package/dist/core/objects/peel.mjs +1 -7
  98. package/dist/core/objects/reading.mjs +19 -18
  99. package/dist/core/objects/tree-edits.mjs +1 -1
  100. package/dist/core/objects/trees.mjs +257 -58
  101. package/dist/core/objects/writing.mjs +3 -9
  102. package/dist/core/own-writes.mjs +1 -1
  103. package/dist/core/parts.d.mts +8 -1
  104. package/dist/core/parts.mjs +8 -4
  105. package/dist/core/purge.mjs +31 -18
  106. package/dist/core/push.d.mts +2 -2
  107. package/dist/core/push.mjs +145 -98
  108. package/dist/core/receipts.d.mts +2 -2
  109. package/dist/core/receipts.mjs +9 -2
  110. package/dist/core/ref-index-job.mjs +4 -4
  111. package/dist/core/ref-view.mjs +74 -31
  112. package/dist/core/refs.mjs +3 -3
  113. package/dist/core/repack.mjs +25 -30
  114. package/dist/core/repo-info.mjs +1 -1
  115. package/dist/core/repos.mjs +1 -1
  116. package/dist/core/rules/changes.mjs +18 -40
  117. package/dist/core/rules/check.mjs +6 -5
  118. package/dist/core/rules/commit-changes.mjs +114 -58
  119. package/dist/core/rules/context.d.mts +3 -3
  120. package/dist/core/rules/context.mjs +18 -14
  121. package/dist/core/rules/fetch.mjs +1 -1
  122. package/dist/core/rules/protect.mjs +30 -17
  123. package/dist/core/saved-caller-views.d.mts +1 -1
  124. package/dist/core/saved-caller-views.mjs +3 -3
  125. package/dist/core/saved-callers.d.mts +1 -1
  126. package/dist/core/saved-callers.mjs +1 -1
  127. package/dist/core/seam.d.mts +1 -2
  128. package/dist/core/view.d.mts +6 -3
  129. package/dist/core/view.mjs +11 -10
  130. package/dist/core/work.mjs +2 -2
  131. package/dist/engine/allotted-xdiff.mjs +3 -16
  132. package/dist/engine/combined.d.mts +3 -0
  133. package/dist/engine/combined.mjs +200 -185
  134. package/dist/engine/content.d.mts +2 -2
  135. package/dist/engine/content.mjs +1 -1
  136. package/dist/engine/merge.mjs +7 -9
  137. package/dist/engine/reads.d.mts +2 -2
  138. package/dist/engine/reads.mjs +22 -14
  139. package/dist/engine/xdiff.d.mts +1 -1
  140. package/dist/engine/xdiff.mjs +1 -1
  141. package/dist/event-streams/event-streams.d.mts +1 -1
  142. package/dist/event-streams/event-streams.mjs +1 -1
  143. package/dist/event-streams/stream.d.mts +2 -2
  144. package/dist/event-streams/stream.mjs +3 -3
  145. package/dist/extend.d.mts +2 -6
  146. package/dist/extend.mjs +1 -5
  147. package/dist/http/core-parts.mjs +83 -26
  148. package/dist/http/handler.mjs +54 -9
  149. package/dist/http/parts.d.mts +1 -0
  150. package/dist/http/push-upload-job.mjs +138 -24
  151. package/dist/http/push-uploads.mjs +2 -2
  152. package/dist/http/receive-pack.mjs +14 -53
  153. package/dist/http/request-snapshot.mjs +258 -0
  154. package/dist/http/upload-pack.mjs +23 -18
  155. package/dist/index.d.mts +29 -21
  156. package/dist/index.mjs +11 -2
  157. package/dist/lfs/base.d.mts +1 -1
  158. package/dist/lfs/copy.d.mts +49 -1
  159. package/dist/lfs/copy.mjs +135 -22
  160. package/dist/lfs/layer.d.mts +4 -3
  161. package/dist/lfs/layer.mjs +4 -5
  162. package/dist/lfs/locks.mjs +2 -2
  163. package/dist/lfs/objects.d.mts +1 -1
  164. package/dist/lfs/objects.mjs +3 -3
  165. package/dist/lfs/pointers.mjs +1 -1
  166. package/dist/lfs/rows.d.mts +1 -1
  167. package/dist/lfs/rows.mjs +11 -4
  168. package/dist/lfs/upkeep.mjs +40 -9
  169. package/dist/lfs/uploaded.mjs +1 -1
  170. package/dist/lfs/wire.mjs +1 -1
  171. package/dist/merges/merges.mjs +17 -2
  172. package/dist/protocol/bytes/buffers.d.mts +1 -1
  173. package/dist/protocol/bytes/buffers.mjs +1 -1
  174. package/dist/protocol/bytes/deflate.d.mts +1 -1
  175. package/dist/protocol/bytes/deflate.mjs +1 -1
  176. package/dist/protocol/bytes/inflate.d.mts +1 -1
  177. package/dist/protocol/bytes/inflate.mjs +1 -1
  178. package/dist/protocol/bytes/sha1.d.mts +1 -1
  179. package/dist/protocol/bytes/sha1.mjs +1 -1
  180. package/dist/protocol/diff/read.d.mts +2 -1
  181. package/dist/protocol/diff/read.mjs +102 -8
  182. package/dist/protocol/packs/graph.mjs +1 -1
  183. package/dist/protocol/packs/idx.d.mts +1 -1
  184. package/dist/protocol/packs/idx.mjs +1 -1
  185. package/dist/protocol/packs/parts.mjs +1 -1
  186. package/dist/protocol/packs/reader.d.mts +1 -1
  187. package/dist/protocol/packs/reader.mjs +1 -1
  188. package/dist/protocol/packs/write-error.d.mts +1 -1
  189. package/dist/protocol/packs/write-error.mjs +1 -1
  190. package/dist/protocol/packs/writer.mjs +3 -3
  191. package/dist/protocol/wire/advertisement.d.mts +1 -1
  192. package/dist/protocol/wire/advertisement.mjs +3 -2
  193. package/dist/protocol/wire/fetch.d.mts +1 -1
  194. package/dist/protocol/wire/fetch.mjs +1 -1
  195. package/dist/protocol/wire/lines.d.mts +9 -1
  196. package/dist/protocol/wire/lines.mjs +28 -1
  197. package/dist/protocol/wire/push-uploads.mjs +10 -7
  198. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  199. package/dist/protocol/wire/receive-pack.mjs +1 -1
  200. package/dist/protocol/wire/report-status.d.mts +1 -1
  201. package/dist/protocol/wire/report-status.mjs +1 -1
  202. package/dist/protocol/wire/v2.d.mts +1 -1
  203. package/dist/protocol/wire/v2.mjs +1 -1
  204. package/dist/queue/advance.mjs +31 -24
  205. package/dist/queue/base.d.mts +5 -3
  206. package/dist/queue/calls.mjs +5 -5
  207. package/dist/queue/commit.mjs +1 -1
  208. package/dist/queue/host.d.mts +1 -1
  209. package/dist/queue/layer.d.mts +0 -1
  210. package/dist/queue/layer.mjs +9 -5
  211. package/dist/queue/schedule.mjs +1 -1
  212. package/dist/queue/search.mjs +1 -1
  213. package/dist/queue/state.mjs +1 -1
  214. package/dist/queue/trim.mjs +2 -2
  215. package/dist/rest/client.d.mts +1 -1
  216. package/dist/rest/client.mjs +6 -6
  217. package/dist/rest/errors.mjs +1 -1
  218. package/dist/rest/handler.mjs +2 -2
  219. package/dist/rest/handlers.mjs +16 -6
  220. package/dist/rest/layer.mjs +1 -1
  221. package/dist/rest/listen.mjs +2 -2
  222. package/dist/rest/refs.mjs +1 -1
  223. package/dist/server/edge.mjs +27 -3
  224. package/dist/server/git-layer.d.mts +1 -2
  225. package/dist/server/git-layer.mjs +4 -5
  226. package/dist/server/lifecycle.mjs +1 -1
  227. package/dist/server/registry.mjs +2 -8
  228. package/dist/server/server.mjs +62 -43
  229. package/dist/signin/context.d.mts +1 -1
  230. package/dist/signin/context.mjs +1 -1
  231. package/dist/signin/forms.mjs +1 -1
  232. package/dist/signin/grants.d.mts +2 -2
  233. package/dist/signin/grants.mjs +1 -1
  234. package/dist/signin/wire.mjs +1 -1
  235. package/dist/storage/allotted.mjs +4 -9
  236. package/dist/storage/batch-upkeep.mjs +31 -12
  237. package/dist/storage/batches.d.mts +2 -3
  238. package/dist/storage/batches.mjs +52 -49
  239. package/dist/storage/budget.mjs +23 -1
  240. package/dist/storage/calls.d.mts +1 -1
  241. package/dist/storage/calls.mjs +41 -43
  242. package/dist/storage/charged-cache.mjs +180 -0
  243. package/dist/storage/chunks.d.mts +3 -3
  244. package/dist/storage/chunks.mjs +121 -8
  245. package/dist/storage/counted-bucket.mjs +32 -10
  246. package/dist/storage/fetch-row-cache.d.mts +6 -0
  247. package/dist/storage/fetch-row-cache.mjs +211 -0
  248. package/dist/storage/fetch.d.mts +1 -0
  249. package/dist/storage/fetch.mjs +54 -242
  250. package/dist/storage/held-types.d.mts +0 -1
  251. package/dist/storage/held-types.mjs +13 -4
  252. package/dist/storage/host-bucket.mjs +9 -4
  253. package/dist/storage/index-bitmaps.mjs +340 -65
  254. package/dist/storage/index-build.d.mts +2 -3
  255. package/dist/storage/index-build.mjs +274 -56
  256. package/dist/storage/index-fetch.d.mts +3 -1
  257. package/dist/storage/index-fetch.mjs +60 -21
  258. package/dist/storage/index-graph.mjs +1 -1
  259. package/dist/storage/index-layers.mjs +55 -25
  260. package/dist/storage/index-reach.mjs +15 -22
  261. package/dist/storage/index-whole.d.mts +7 -0
  262. package/dist/storage/index-whole.mjs +145 -37
  263. package/dist/storage/largest-files.mjs +1 -7
  264. package/dist/storage/layout.mjs +17 -1
  265. package/dist/storage/lfs-pointers.mjs +1 -6
  266. package/dist/storage/link-join.mjs +55 -16
  267. package/dist/storage/list-source.d.mts +7 -0
  268. package/dist/storage/list-source.mjs +288 -0
  269. package/dist/storage/loose.d.mts +8 -8
  270. package/dist/storage/loose.mjs +157 -91
  271. package/dist/storage/memory-budget.mjs +226 -22
  272. package/dist/storage/merge-cut.mjs +9 -6
  273. package/dist/storage/merge-fence.mjs +1 -1
  274. package/dist/storage/merge-row.mjs +1 -1
  275. package/dist/storage/merge.d.mts +2 -3
  276. package/dist/storage/merge.mjs +2 -2
  277. package/dist/storage/object-rows.d.mts +3 -3
  278. package/dist/storage/object-rows.mjs +179 -38
  279. package/dist/storage/pack-order.mjs +97 -44
  280. package/dist/storage/pack-ranges.mjs +44 -16
  281. package/dist/storage/pack-reads.d.mts +5 -3
  282. package/dist/storage/pack-reads.mjs +236 -72
  283. package/dist/storage/pack-receive.d.mts +1 -2
  284. package/dist/storage/pack-receive.mjs +24 -18
  285. package/dist/storage/packs.d.mts +1 -1
  286. package/dist/storage/packs.mjs +477 -116
  287. package/dist/storage/placed-reads.mjs +33 -16
  288. package/dist/storage/prune-seen.mjs +1 -1
  289. package/dist/storage/prune-walk.mjs +1 -1
  290. package/dist/storage/prune.mjs +4 -31
  291. package/dist/storage/push-allotment.mjs +26 -14
  292. package/dist/storage/push-uploads.mjs +195 -57
  293. package/dist/storage/pushed-commits.mjs +20 -1
  294. package/dist/storage/quarantine.d.mts +2 -3
  295. package/dist/storage/range-cache.mjs +175 -40
  296. package/dist/storage/raw-ids.mjs +39 -10
  297. package/dist/storage/ready.d.mts +2 -3
  298. package/dist/storage/ready.mjs +114 -38
  299. package/dist/storage/receive-bounds.mjs +31 -9
  300. package/dist/storage/receive-cache.d.mts +7 -0
  301. package/dist/storage/receive-cache.mjs +147 -0
  302. package/dist/storage/receive-files.mjs +1 -1
  303. package/dist/storage/receive-links.mjs +1 -1
  304. package/dist/storage/receive-state.d.mts +2 -2
  305. package/dist/storage/receive-state.mjs +6 -8
  306. package/dist/storage/receive-steps.d.mts +20 -0
  307. package/dist/storage/receive-steps.mjs +298 -13
  308. package/dist/storage/repack-backlog.mjs +1 -6
  309. package/dist/storage/repack-contained.mjs +2 -2
  310. package/dist/storage/repack-job.mjs +1 -1
  311. package/dist/storage/repack.d.mts +2 -3
  312. package/dist/storage/repack.mjs +54 -9
  313. package/dist/storage/request-cache.mjs +57 -0
  314. package/dist/storage/roots.mjs +1 -24
  315. package/dist/storage/rows.d.mts +2 -2
  316. package/dist/storage/rows.mjs +1 -1
  317. package/dist/storage/runs.d.mts +2 -2
  318. package/dist/storage/runs.mjs +1 -1
  319. package/dist/storage/send-list.mjs +62 -25
  320. package/dist/storage/stream-whole.mjs +84 -63
  321. package/dist/storage/swap-walk.mjs +1 -1
  322. package/dist/storage/unpack.mjs +878 -450
  323. package/dist/storage/visible.mjs +110 -32
  324. package/dist/storage/walk.mjs +1 -0
  325. package/dist/storage/wants.mjs +22 -58
  326. package/dist/store/call-count.d.mts +2 -2
  327. package/dist/store/call-count.mjs +24 -11
  328. package/dist/store/catalogue.d.mts +1 -1
  329. package/dist/store/catalogue.mjs +19 -7
  330. package/dist/store/crossing.mjs +1 -7
  331. package/dist/store/cursor-seal.d.mts +1 -1
  332. package/dist/store/cursor-seal.mjs +1 -1
  333. package/dist/store/door.mjs +9 -4
  334. package/dist/store/errors.d.mts +2 -2
  335. package/dist/store/errors.mjs +107 -19
  336. package/dist/store/git-store.mjs +7 -2
  337. package/dist/store/job-try.mjs +90 -9
  338. package/dist/store/list-job.mjs +10 -34
  339. package/dist/store/outbox.d.mts +2 -2
  340. package/dist/store/outbox.mjs +2 -2
  341. package/dist/store/queue-jobs.mjs +6 -12
  342. package/dist/store/records.d.mts +2 -2
  343. package/dist/store/records.mjs +2 -2
  344. package/dist/store/ref-rows.d.mts +2 -2
  345. package/dist/store/ref-rows.mjs +2 -2
  346. package/dist/store/repo-record.d.mts +2 -2
  347. package/dist/store/repo-record.mjs +3 -3
  348. package/dist/store/request-snapshot.mjs +5 -0
  349. package/dist/store/reservations.mjs +2 -2
  350. package/dist/store/topic-jobs.mjs +5 -11
  351. package/dist/sync/bound.d.mts +3 -3
  352. package/dist/sync/bound.mjs +10 -7
  353. package/dist/sync/github.mjs +65 -67
  354. package/dist/sync/http.mjs +1 -1
  355. package/dist/sync/import.mjs +201 -66
  356. package/dist/sync/layer.d.mts +1 -1
  357. package/dist/sync/layer.mjs +6 -6
  358. package/dist/sync/lfs-batch.mjs +1 -1
  359. package/dist/sync/lfs-copy.mjs +175 -15
  360. package/dist/sync/mirror.mjs +5 -10
  361. package/dist/sync/said.mjs +1 -1
  362. package/dist/sync/step.mjs +268 -86
  363. package/dist/sync/tries.mjs +25 -6
  364. package/dist/sync.d.mts +2 -2
  365. package/dist/sync.mjs +2 -2
  366. package/dist/topics/advance.mjs +3 -3
  367. package/dist/topics/calls.mjs +1 -1
  368. package/dist/topics/layer.d.mts +15 -14
  369. package/dist/topics/members.mjs +1 -1
  370. package/dist/topics/topic.mjs +1 -1
  371. package/package.json +3 -13
  372. package/dist/auth/helpers.mjs +0 -17
  373. package/dist/auth.d.mts +0 -5
  374. package/dist/auth.mjs +0 -5
  375. package/dist/core/rules/commit-changes.d.mts +0 -12
  376. package/dist/effect.d.mts +0 -9
  377. package/dist/effect.mjs +0 -7
  378. package/dist/server/joined.d.mts +0 -70
  379. package/dist/server/joined.mjs +0 -41
@@ -2,15 +2,16 @@ import { fail } from "../contracts/result.mjs";
2
2
  import { streamOf } from "../protocol/bytes/streams.mjs";
3
3
  import { emptyTree, objectId, objectTypes } from "../protocol/objects/object.mjs";
4
4
  import { decodeRow } from "../store/errors.mjs";
5
+ import { RequestSnapshot } from "../store/request-snapshot.mjs";
5
6
  import { repoScope } from "../store/scopes.mjs";
6
- import { SizeMarker, batchesOf, batchesRead, isBatchId, stagedKey, stagedOid, stagedPrefix, stagedRowsOf, stagedSizeKey } from "./batches.mjs";
7
- import { ChunkReader, chunkedOf } from "./chunks.mjs";
7
+ import { SizeMarker, batchesOf, batchesRead, isBatchId, stagedKey, stagedOid, stagedPrefix, stagedSizeKey } from "./batches.mjs";
8
+ import { ChunkReader, chunkCount, chunkedOf } from "./chunks.mjs";
8
9
  import { objectCollections } from "./layout.mjs";
10
+ import { limits } from "@ref0/infra";
11
+ import * as Schema from "effect/Schema";
9
12
  import * as Effect from "effect/Effect";
10
13
  import * as Option from "effect/Option";
11
- import * as Schema from "effect/Schema";
12
14
  import * as Result from "effect/Result";
13
- import { limits } from "@ref0/infra";
14
15
  import * as Base64 from "effect/encoding/Base64";
15
16
  // src/storage/object-rows.ts
16
17
  /** One object as a row, by its ID: its type and its body as base64, the header left out. */
@@ -97,6 +98,22 @@ const headerOfRow = /* @__PURE__ */ Effect.fnUntraced(function* (row) {
97
98
  size: data.length / 4 * 3 - padding
98
99
  };
99
100
  });
101
+ /**
102
+ * A stored object row's inflated body bytes from its base64 length or chunked manifest, without
103
+ * decoding or allocating the body. Returns 0 for an unreadable row.
104
+ */
105
+ const rowInflatedBytes = (row) => {
106
+ const chunked = chunkedOf(row.value);
107
+ if (chunked !== void 0) return chunked.size;
108
+ const stored = decodeObjectRow(row.value);
109
+ if (Option.isNone(stored)) return 0;
110
+ const { data } = stored.value;
111
+ if (data.length === 0 || data.length % 4 !== 0) return 0;
112
+ const padding = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
113
+ return data.length / 4 * 3 - padding;
114
+ };
115
+ /** Total inflated body bytes of `rows`, as `rowInflatedBytes` counts each. */
116
+ const rowsInflatedBytes = (rows) => rows.reduce((sum, row) => sum + rowInflatedBytes(row), 0);
100
117
  /** A whole object as the contract's, its bytes one piece of a stream. */
101
118
  const gitObjectOf = (object) => ({
102
119
  oid: object.oid,
@@ -105,11 +122,10 @@ const gitObjectOf = (object) => ({
105
122
  bytes: streamOf(object.bytes.slice())
106
123
  });
107
124
  /**
108
- * The object rows a receive's change puts, by ID, readable before the commit that writes them,
109
- * or those it staged as a batch the change publishes: so a push's walk reads the new tips it
110
- * carries.
125
+ * The inline object rows a receive's change puts, by ID, readable before the commit that writes
126
+ * them; staged receives expose their pre-commit rows through `stagedOwnOf`.
111
127
  */
112
- const receivedRows = (change) => stagedRowsOf(change) ?? new Map((change?.put ?? []).flatMap((row) => row.collection === objectCollections.objects ? [[row.id, row]] : []));
128
+ const receivedRows = (change) => new Map((change?.put ?? []).flatMap((row) => row.collection === objectCollections.objects ? [[row.id, row]] : []));
113
129
  /**
114
130
  * How a staged push's own chunked rows are read before its commit, by the change it answered:
115
131
  * its batch isn't published, so no reader of the repo finds them.
@@ -124,6 +140,13 @@ const receivedObject = (change, row) => {
124
140
  return chunked === void 0 || reader === void 0 ? objectOfRow(row) : reader(row.id, chunked).whole();
125
141
  };
126
142
  /**
143
+ * Object rows one `wholePlan` clone page asks for: matches `wholeRowsMost` (1,000) so a rows-only
144
+ * whole clone reads its remaining rows past the preloaded first page in one store read instead of
145
+ * paging `rowReadBatch` (100) at a time. Past one answer's 16 MiB (`limits.answerBytes`),
146
+ * `eachPageAt` falls back to `rowReadBatch` and then `largeBatch`.
147
+ */
148
+ const wholePageRows = 1e3;
149
+ /**
127
150
  * Object rows a store read refused as too large is cut into: as many of the largest as one answer
128
151
  * holds, each row's key and version aside, so no read of them passes its 16 MiB.
129
152
  */
@@ -168,6 +191,18 @@ const asObjectRow = (row) => ({
168
191
  value: row.value
169
192
  });
170
193
  /**
194
+ * Reads already-flushed rows from `stagedObjects` or `stagedDeltas` in key order, normalizing
195
+ * `stagedObjects/<batch>/<oid>` through `asObjectRow` so callers decode object rows with bare OIDs.
196
+ */
197
+ const readStagedRows = (store, repo) => (keys) => keys.length === 0 ? Effect.succeed([]) : Effect.map(store.read({
198
+ scope: repoScope(repo),
199
+ reads: [...keys]
200
+ }), (snapshot) => keys.map((key, index) => {
201
+ const row = snapshot.results[index]?.[0];
202
+ if (row === void 0) return void 0;
203
+ return key.collection === objectCollections.stagedObjects ? asObjectRow(row) : row;
204
+ }));
205
+ /**
171
206
  * The value bytes packed into one staged body read at most (#2521): each row is at most 1 MiB, so
172
207
  * every closed read holds > 13 MiB of values and stays under 16 MiB with its keys and envelope.
173
208
  */
@@ -361,37 +396,70 @@ const heldIdsAt = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, vers
361
396
  }));
362
397
  return moved ? void 0 : held;
363
398
  });
364
- /**
365
- * Each page of a repo's object rows, in ID order, handed to `each` before the next is read, every
366
- * page read at `version`: `rowReadBatch` rows to a read, or `largeBatch` where those passed one
367
- * answer's 16 MiB. `true` once every row is read; `false` once a page answers at another version,
368
- * since the repo moved after the read it joins, once `each` answers `false`, or once a page lists a
369
- * published staged batch, whose rows `objects` doesn't hold yet: a whole-repo pass waits for
370
- * upkeep to promote them, and a clone builds through the readers that read batches.
371
- */
372
- const eachPageAt = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, version, each) {
373
- const page = (after, limit) => {
399
+ const eachPageAt = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, version, each, also, pageSize = 100) {
400
+ const scope = repoScope(repo);
401
+ const page = (after, limit, withAlso) => {
374
402
  const read = {
375
403
  collection: objectCollections.objects,
376
404
  limit
377
405
  };
378
406
  if (after !== void 0) read.after = after;
407
+ const reads = withAlso && also !== void 0 ? [
408
+ read,
409
+ batchesRead,
410
+ ...also.reads
411
+ ] : [read, batchesRead];
379
412
  return Effect.map(store.read({
380
- scope: repoScope(repo),
381
- reads: [read, batchesRead]
413
+ scope,
414
+ reads
382
415
  }), ({ version: at, results }) => ({
383
416
  at,
384
417
  rows: results[0] ?? [],
385
418
  limit,
386
- batched: (results[1] ?? []).length > 0
419
+ batched: (results[1] ?? []).length > 0,
420
+ extra: withAlso && also !== void 0 ? results.slice(2) : void 0
387
421
  }));
388
422
  };
389
423
  let after;
424
+ let needAlso = also !== void 0 && also.reads.length > 0;
425
+ const snapshot = yield* RequestSnapshot;
426
+ if (snapshot !== void 0) {
427
+ const preloadReads = needAlso && also !== void 0 ? [
428
+ {
429
+ collection: objectCollections.objects,
430
+ limit: 100
431
+ },
432
+ batchesRead,
433
+ ...also.reads
434
+ ] : [{
435
+ collection: objectCollections.objects,
436
+ limit: 100
437
+ }, batchesRead];
438
+ const preloaded = snapshot.answer(scope, preloadReads);
439
+ if (preloaded !== void 0 && preloaded.version === version) {
440
+ if ((preloaded.results[1] ?? []).length > 0) return "batched";
441
+ const rows = preloaded.results[0] ?? [];
442
+ if (!(yield* each(rows))) return "moved";
443
+ if (needAlso && also !== void 0) {
444
+ also.take(preloaded.results.slice(2));
445
+ needAlso = false;
446
+ }
447
+ const last = rows.at(-1);
448
+ if (last === void 0 || rows.length < 100) return "done";
449
+ after = last.id;
450
+ }
451
+ }
390
452
  for (;;) {
391
- const { at, rows, limit, batched } = yield* page(after, 100).pipe(Effect.catchIf(tooLargeRead, () => page(after, largeBatch)));
392
- if (at !== version || batched || !(yield* each(rows))) return false;
453
+ const first = needAlso;
454
+ const { at, rows, limit, batched, extra } = yield* page(after, pageSize, first).pipe(Effect.catchIf(tooLargeRead, () => pageSize > 100 ? page(after, 100, first).pipe(Effect.catchIf(tooLargeRead, () => page(after, largeBatch, first))) : page(after, largeBatch, first)));
455
+ if (batched) return "batched";
456
+ if (at !== version || !(yield* each(rows))) return "moved";
457
+ if (first && extra !== void 0 && also !== void 0) {
458
+ also.take(extra);
459
+ needAlso = false;
460
+ }
393
461
  const last = rows.at(-1);
394
- if (last === void 0 || rows.length < limit) return true;
462
+ if (last === void 0 || rows.length < limit) return "done";
395
463
  after = last.id;
396
464
  }
397
465
  });
@@ -486,14 +554,68 @@ const chunkedAgain = (store, listed) => Effect.fnUntraced(function* (oid) {
486
554
  /** A reader of `oid`'s chunks, the repo's row naming them `chunked`. */
487
555
  const chunkReaderOf = (store, listed, oid, chunked) => new ChunkReader(store, listed.repo, oid, chunked, chunkedAgain(store, listed));
488
556
  /**
557
+ * One object's row, `emptyTree` included: an inline row decoded and hashed whole, or a chunked
558
+ * row's `ChunkReader` with no chunks read yet, validated against its size and chunk count (#2522).
559
+ */
560
+ const rowAt = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, oid) {
561
+ if (oid === "4b825dc642cb6eb9a060e54bf8d69288fbee4904") return {
562
+ kind: "whole",
563
+ object: emptyTreeObject
564
+ };
565
+ let found;
566
+ yield* eachRow(store, listed, [oid], Effect.fnUntraced(function* (row) {
567
+ const chunked = chunkedOf(row.value);
568
+ if (chunked === void 0) {
569
+ found = {
570
+ kind: "whole",
571
+ object: yield* objectOfRow(row)
572
+ };
573
+ return;
574
+ }
575
+ if (chunked.size < 1 || chunked.chunks !== chunkCount(chunked.size)) return yield* fail("DATA_LOSS", `Object ${row.id}'s chunked row has invalid size or chunk count`);
576
+ found = {
577
+ kind: "chunked",
578
+ reader: chunkReaderOf(store, listed, row.id, chunked)
579
+ };
580
+ }));
581
+ return found;
582
+ });
583
+ /**
489
584
  * A repo's object rows `oids` names, each handed on as it's read: the empty tree among them. One
490
- * kept as chunks is read whole, `chunkReadMost` chunks a read, once `before` lets it.
585
+ * kept as chunks is read whole, `chunkReadMost` chunks a read, once `before` lets it. When `cache`
586
+ * is provided for a fetch request, inline rows already cached are served (and verified on first
587
+ * decode from raw) without re-reading the store, and newly read inline rows are stored within the
588
+ * cache's bounds (#2899).
491
589
  */
492
- const eachHeldRow = (store, listed, before) => Effect.fnUntraced(function* (oids, each) {
493
- if (oids.includes("4b825dc642cb6eb9a060e54bf8d69288fbee4904")) yield* each(emptyTreeObject);
494
- yield* eachRow(store, listed, oids, Effect.fnUntraced(function* (row) {
590
+ const eachHeldRow = (store, listed, before, cache) => Effect.fnUntraced(function* (oids, each) {
591
+ const unique = [...new Set(oids)];
592
+ const missed = [];
593
+ for (const oid of unique) {
594
+ if (oid === "4b825dc642cb6eb9a060e54bf8d69288fbee4904") {
595
+ yield* each(emptyTreeObject);
596
+ continue;
597
+ }
598
+ const cached = cache?.get(oid);
599
+ if (cached === void 0) {
600
+ missed.push(oid);
601
+ continue;
602
+ }
603
+ if (cached.kind === "whole") {
604
+ yield* each(cached.object);
605
+ continue;
606
+ }
607
+ const object = yield* objectOfRow(cached.row);
608
+ cache?.putWhole(object);
609
+ yield* each(object);
610
+ }
611
+ if (missed.length === 0) return;
612
+ yield* eachRow(store, listed, missed, Effect.fnUntraced(function* (row) {
495
613
  const chunked = chunkedOf(row.value);
496
- if (chunked === void 0) return yield* Effect.flatMap(objectOfRow(row), each);
614
+ if (chunked === void 0) {
615
+ const object = yield* objectOfRow(row);
616
+ cache?.putWhole(object);
617
+ return yield* each(object);
618
+ }
497
619
  if (before !== void 0 && !(yield* before(row.id, chunked.size))) return;
498
620
  yield* each(yield* chunkReaderOf(store, listed, row.id, chunked).whole());
499
621
  }));
@@ -507,19 +629,38 @@ const heldRows = (store, listed) => Effect.fnUntraced(function* (oids) {
507
629
  /**
508
630
  * The type and size of each of `oids`' rows the repo holds, the empty tree's among them, the size
509
631
  * from each row's base64: no body decoded or hashed, though each row is read whole, as the store
510
- * has no part read.
632
+ * has no part read. When `cache` is provided, cached headers are returned without a store read and
633
+ * newly read inline rows are stored raw within the cache's bounds (#2899).
511
634
  */
512
- const rowHeaders = (store, listed) => Effect.fnUntraced(function* (oids) {
635
+ const rowHeaders = (store, listed, onRow, cache) => Effect.fnUntraced(function* (oids) {
513
636
  const headers = /* @__PURE__ */ new Map();
514
- if (oids.includes("4b825dc642cb6eb9a060e54bf8d69288fbee4904")) headers.set(emptyTree, {
515
- type: "tree",
516
- size: 0
517
- });
518
- yield* eachRow(store, listed, oids, (row) => Effect.map(headerOfRow(row), (header) => void headers.set(row.id, header)));
637
+ const missed = [];
638
+ for (const oid of new Set(oids)) {
639
+ if (oid === "4b825dc642cb6eb9a060e54bf8d69288fbee4904") {
640
+ headers.set(emptyTree, {
641
+ type: "tree",
642
+ size: 0
643
+ });
644
+ continue;
645
+ }
646
+ const cached = cache?.headerOf(oid);
647
+ if (cached !== void 0) {
648
+ headers.set(oid, cached);
649
+ continue;
650
+ }
651
+ missed.push(oid);
652
+ }
653
+ if (missed.length === 0) return headers;
654
+ yield* eachRow(store, listed, missed, Effect.fnUntraced(function* (row) {
655
+ const header = yield* headerOfRow(row);
656
+ if (cache !== void 0 && chunkedOf(row.value) === void 0) cache.putRaw(row, header);
657
+ headers.set(row.id, header);
658
+ onRow?.(row, header);
659
+ }));
519
660
  return headers;
520
661
  });
521
662
  /** The size of each of `oids`' rows the repo holds, as `rowHeaders` reads it. */
522
- const rowSizes = (store, listed) => (oids) => Effect.map(rowHeaders(store, listed)(oids), (headers) => new Map([...headers].map(([oid, { size }]) => [oid, size])));
663
+ const rowSizes = (store, listed, cache) => (oids) => Effect.map(rowHeaders(store, listed, void 0, cache)(oids), (headers) => new Map([...headers].map(([oid, { size }]) => [oid, size])));
523
664
  /**
524
665
  * The IDs of `repo`'s object rows that start with `prefix`, at most `count` from each place it
525
666
  * reads, lowest first, deduplicated, and the version they're read at: `objects` and every published
@@ -628,4 +769,4 @@ const startingOf = (found, most) => {
628
769
  more: all.length > most
629
770
  };
630
771
  };
631
- export { ObjectRow, bodyPackBytes, copyRowsPage, eachHeldRow, eachPageAt, emptyTreeObject, gitObjectOf, headerOfRow, heldIdsAt, heldRows, largeBatch, noRows, objectKey, objectOfRow, objectRow, readsOwnChunks, receivedObject, receivedRows, rowHeaders, rowSizes, rowValueBytes, rowsMoved, rowsStartingWith, startingOf, tooLargeRead };
772
+ export { ObjectRow, bodyPackBytes, copyRowsPage, eachHeldRow, eachPageAt, emptyTreeObject, gitObjectOf, headerOfRow, heldIdsAt, heldRows, largeBatch, noRows, objectKey, objectOfRow, objectRow, readStagedRows, readsOwnChunks, receivedObject, receivedRows, rowAt, rowHeaders, rowInflatedBytes, rowSizes, rowValueBytes, rowsInflatedBytes, rowsMoved, rowsStartingWith, startingOf, tooLargeRead, wholePageRows };
@@ -1,7 +1,7 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
2
  import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
3
3
  import { DeltaError } from "../protocol/packs/delta.mjs";
4
- import { oidBytes } from "../protocol/packs/idx.mjs";
4
+ import { oidBytes, writeOidBytes } from "../protocol/packs/idx.mjs";
5
5
  import { PackIndexer } from "../protocol/packs/indexer.mjs";
6
6
  import { PackError, PackTransportError, boundedSource, readEntryHeader, readPackFrom } from "../protocol/packs/reader.mjs";
7
7
  import { stepEffect } from "../protocol/packs/step.mjs";
@@ -12,7 +12,7 @@ import { typeCodes } from "./index-files.mjs";
12
12
  import { packFiles } from "./layout.mjs";
13
13
  import { headerLimits, packIndexerLimits } from "./pack-reads.mjs";
14
14
  import { locateAll, locateAllBytes, rangeRanks, readExactly } from "./pack-ranges.mjs";
15
- import { compareIds, idsBytes, orderById } from "./raw-ids.mjs";
15
+ import { compareIdsFrom, idsBytes, orderByIdWithFanout } from "./raw-ids.mjs";
16
16
  import * as Effect from "effect/Effect";
17
17
  import * as Result from "effect/Result";
18
18
  // src/storage/pack-order.ts
@@ -139,9 +139,9 @@ var SliceLinks = class SliceLinks {
139
139
  }
140
140
  /** One link of the object begun last: the 20 bytes of `bytes` from `at`. */
141
141
  add = (bytes, at) => {
142
- if (!this.#fit(this.sources, this.size + 1)) return;
143
- const ids = this.#ids;
144
142
  const to = this.size * 20;
143
+ if (this.#refused || to + 20 > this.#ids.length && !this.#fit(this.sources, this.size + 1)) return;
144
+ const ids = this.#ids;
145
145
  for (let each = 0; each < 20; each += 1) ids[to + each] = bytes[at + each] ?? 0;
146
146
  this.size += 1;
147
147
  this.#starts[this.sources] = this.size;
@@ -191,6 +191,14 @@ var SliceLinks = class SliceLinks {
191
191
  linksOf(at) {
192
192
  return [this.#starts[at] ?? 0, this.#starts[at + 1] ?? 0];
193
193
  }
194
+ /** Where the `at`th object's links start in `ids`. */
195
+ linkStart(at) {
196
+ return this.#starts[at] ?? 0;
197
+ }
198
+ /** Where the `at`th object's links end in `ids` (exclusive). */
199
+ linkEnd(at) {
200
+ return this.#starts[at + 1] ?? 0;
201
+ }
194
202
  /** Whether the `at`th object's `link`th link may name an object the repo lacks. */
195
203
  mayLack(at, link) {
196
204
  return mayLack(this.#kinds[at] ?? 0, link);
@@ -295,11 +303,14 @@ const sliceEntries = /* @__PURE__ */ Effect.fnUntraced(function* (ranges, at, by
295
303
  const places = new Uint32Array(length);
296
304
  for (let each = 0; each < length; each += 1) places[each] = placeOf(sorted, offsets[each] ?? 0);
297
305
  const ids = yield* idsOf(ranges, ranks.subarray(0, length), places);
306
+ const end = Number.isFinite(next) ? next : ranges.pack.bytes - 20;
307
+ const ordered = orderByIdWithFanout(ids, length);
298
308
  return {
299
309
  offsets: sorted,
300
- end: Number.isFinite(next) ? next : ranges.pack.bytes - 20,
310
+ end,
301
311
  ids,
302
- byId: orderById(ids, length),
312
+ byId: ordered.order,
313
+ fanout: ordered.fanout,
303
314
  held: capacity * 104
304
315
  };
305
316
  });
@@ -333,14 +344,19 @@ const idsOf = /* @__PURE__ */ Effect.fnUntraced(function* (ranges, ranks, places
333
344
  }
334
345
  return ids;
335
346
  });
336
- /** The entry of the slice whose ID is `id`'s 20 bytes, by a search of `byId`, or -1. */
347
+ /** The entry of the slice whose ID is `id`'s 20 bytes, narrowed by its 12-bit prefix fanout, or -1. */
337
348
  const entryById = (entries, id) => {
338
- let low = 0;
339
- let high = entries.byId.length;
349
+ const b0 = id[0] ?? 0;
350
+ const b1 = id[1] ?? 0;
351
+ const bucket = b0 << 4 | b1 >>> 4;
352
+ let low = entries.fanout[bucket] ?? 0;
353
+ let high = entries.fanout[bucket + 1] ?? entries.byId.length;
340
354
  while (low < high) {
341
355
  const middle = low + high >>> 1;
342
356
  const each = entries.byId[middle] ?? 0;
343
- const compared = compareIds(entries.ids, each * 20, id, 0);
357
+ const off = each * 20;
358
+ const diff1 = (entries.ids[off + 1] ?? 0) - b1;
359
+ const compared = diff1 !== 0 ? diff1 : compareIdsFrom(entries.ids, off, id, 0, 2);
344
360
  if (compared === 0) return each;
345
361
  if (compared < 0) low = middle + 1;
346
362
  else high = middle;
@@ -568,18 +584,26 @@ const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
568
584
  asked = bytes;
569
585
  return allot(held + asked);
570
586
  };
571
- const holdingMore = (bytes) => {
587
+ const holdingMoreStep = (bytes) => {
572
588
  held += bytes;
573
- return stepEffect(holding(asked));
589
+ return holding(asked);
574
590
  };
591
+ const holdingMore = (bytes) => stepEffect(holdingMoreStep(bytes));
575
592
  const known = new Uint8Array(entries.offsets.length).fill(unknown);
576
593
  const last = entries.offsets.length - 1;
577
- const withinOf = (oid) => entryById(entries, oidBytes(oid));
594
+ const lookupId = /* @__PURE__ */ new Uint8Array(20);
595
+ const withinOf = (oid) => {
596
+ writeOidBytes(oid, lookupId, 0);
597
+ return entryById(entries, lookupId);
598
+ };
578
599
  const outside = outsideBases(bucket, ranges, withinOf, holdingMore, {
579
600
  before: at.position,
580
601
  types: input.storedTypes
581
602
  });
603
+ let cachedBaseOid;
604
+ let cachedBaseOffset = 0;
582
605
  const offsetOf = (oid) => {
606
+ if (oid === cachedBaseOid) return cachedBaseOffset;
583
607
  const within = withinOf(oid);
584
608
  return within >= 0 ? entries.offsets[within] ?? 0 : outside.offsetOf(oid);
585
609
  };
@@ -598,18 +622,22 @@ const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
598
622
  };
599
623
  let read = 0;
600
624
  let skipped = 0;
601
- const settled = Effect.fnUntraced(function* (entry, within, target) {
602
- read += 1;
603
- const resolved = yield* stepEffect(indexer.settle()).pipe(Effect.mapError((error) => error instanceof DeltaError ? lost(`Pack ${pack.id}'s delta at ${entry.offset} won't apply: ${error.message}`) : error));
604
- if (resolved.kind === "unindexable") return yield* Effect.fail(lost(`Pack ${pack.id}'s entry at ${entry.offset} won't resolve: ${resolved.why}`));
625
+ const finishSettled = (entry, within, target, resolved) => {
626
+ if (resolved.kind === "unindexable") return Effect.fail(lost(`Pack ${pack.id}'s entry at ${entry.offset} won't resolve: ${resolved.why}`));
605
627
  const { kind, bytes } = resolved.object;
606
628
  known[within] = typeCodes[kind];
607
- if (kind === "blob") return;
629
+ if (kind === "blob") return void 0;
608
630
  target.begin(ranges.base + entry.index, kind);
609
631
  const malformed = rawLinks(kind, bytes, target.add);
610
- if (malformed !== void 0) return yield* Effect.fail(lost(`Pack ${pack.id}'s ${kind} at ${entry.offset} is malformed: ${malformed}`));
611
- if (target.refused) return yield* Effect.fail(linksPastMemory());
612
- });
632
+ if (malformed !== void 0) return Effect.fail(lost(`Pack ${pack.id}'s ${kind} at ${entry.offset} is malformed: ${malformed}`));
633
+ if (target.refused) return Effect.fail(linksPastMemory());
634
+ };
635
+ const settled = (entry, within, target) => {
636
+ read += 1;
637
+ const resolved = indexer.settle();
638
+ if (!Effect.isEffect(resolved)) return finishSettled(entry, within, target, resolved);
639
+ return Effect.flatMap(Effect.mapError(resolved, (error) => error instanceof DeltaError ? lost(`Pack ${pack.id}'s delta at ${entry.offset} won't apply: ${error.message}`) : error), (done) => finishSettled(entry, within, target, done) ?? Effect.void);
640
+ };
613
641
  let current = 0;
614
642
  let spentMost;
615
643
  let skip = false;
@@ -622,8 +650,13 @@ const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
622
650
  if (entry.base?.kind !== "oid") return Effect.fail(lost(`Pack ${pack.id}'s entry at ${entry.offset} is an offset delta, which no stored pack holds`));
623
651
  const oid = entry.base.oid;
624
652
  const within = withinOf(oid);
625
- if (within < 0 || within < current && known[within] === unknown) return { base: oid };
653
+ if (within < 0 || within < current && known[within] === unknown) return {
654
+ base: oid,
655
+ inSlice: within
656
+ };
626
657
  baseAt(entry.index, at.position + within);
658
+ cachedBaseOid = oid;
659
+ cachedBaseOffset = entries.offsets[within] ?? 0;
627
660
  return { type: within < current ? known[within] ?? unknown : unknown };
628
661
  };
629
662
  const sink = {
@@ -640,12 +673,14 @@ const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
640
673
  deferring = {
641
674
  entry,
642
675
  oid: typed.base,
676
+ inSlice: typed.inSlice,
643
677
  within: current,
644
678
  pieces: keeps ? [] : void 0
645
679
  };
646
680
  const bytes = deferredEntryBytes + (keeps ? entry.size : 0);
647
681
  deferredBytes += bytes;
648
- return holdingMore(bytes);
682
+ const step = holdingMoreStep(bytes);
683
+ return Effect.isEffect(step) ? step : void 0;
649
684
  }
650
685
  skip = typed.type === typeCodes.blob;
651
686
  if (skip) return void 0;
@@ -662,13 +697,21 @@ const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
662
697
  if (deferring === void 0) indexer.data(bytes);
663
698
  else deferring.pieces?.push(bytes.slice());
664
699
  },
665
- entryEnd: Effect.fnUntraced(function* (ended) {
666
- if (deferring === void 0) yield* settled(ended, current, links);
667
- else deferred.push(deferring);
700
+ entryEnd: (ended) => {
701
+ const active = deferring;
702
+ const within = current;
668
703
  deferring = void 0;
669
- const full = deferred.length >= 16384 || deferredBytes >= 16777216;
670
- return current === last || full || links.size >= input.bounds.links ? "pause" : void 0;
671
- })
704
+ const pauseAfter = () => {
705
+ const full = deferred.length >= 16384 || deferredBytes >= 16777216;
706
+ return within === last || full || links.size >= input.bounds.links ? "pause" : void 0;
707
+ };
708
+ if (active !== void 0) {
709
+ deferred.push(active);
710
+ return pauseAfter();
711
+ }
712
+ const done = settled(ended, within, links);
713
+ return done === void 0 ? pauseAfter() : Effect.map(done, pauseAfter);
714
+ }
672
715
  };
673
716
  const reading = yield* Effect.uninterruptibleMask((restore) => Effect.flatMap(refusedIfSpent(bucketStream(bucket, packFiles(pack.id).pack, {
674
717
  offset: at.offset,
@@ -706,24 +749,31 @@ const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
706
749
  if (counted + later.size >= input.bounds.links) return links.positionOf(streamed) - ranges.base - at.position + 1;
707
750
  }
708
751
  };
709
- const settleDeferred = Effect.fnUntraced(function* (each, types) {
710
- const { entry, within } = each;
711
- const inSlice = withinOf(each.oid);
752
+ const settleDeferred = (each, types) => {
753
+ const { entry, within, inSlice } = each;
712
754
  const base = inSlice >= 0 ? {
713
755
  offset: entries.offsets[inSlice] ?? 0,
714
756
  position: at.position + inSlice
715
757
  } : outside.placeOf(each.oid);
716
- if (base === void 0) return yield* Effect.fail(lost(`Pack ${pack.id}'s delta at ${entry.offset} names ${each.oid}, which the pack lacks`));
758
+ if (base === void 0) return Effect.fail(lost(`Pack ${pack.id}'s delta at ${entry.offset} names ${each.oid}, which the pack lacks`));
717
759
  baseAt(entry.index, base.position);
718
760
  if ((inSlice >= 0 ? inSlice < within ? known[inSlice] ?? unknown : unknown : types.get(each.oid) ?? unknown) === typeCodes.blob) {
719
761
  known[within] = typeCodes.blob;
720
762
  skipped += 1;
721
763
  return;
722
764
  }
723
- yield* stepEffect(indexer.entry(entry));
724
- for (const piece of each.pieces ?? []) indexer.data(piece);
725
- yield* settled(entry, within, later);
726
- });
765
+ cachedBaseOid = each.oid;
766
+ cachedBaseOffset = base.offset;
767
+ const began = indexer.entry(entry);
768
+ if (!Effect.isEffect(began)) {
769
+ for (const piece of each.pieces ?? []) indexer.data(piece);
770
+ return settled(entry, within, later);
771
+ }
772
+ return Effect.flatMap(began, () => {
773
+ for (const piece of each.pieces ?? []) indexer.data(piece);
774
+ return settled(entry, within, later) ?? Effect.void;
775
+ });
776
+ };
727
777
  const types = /* @__PURE__ */ new Map();
728
778
  let size = input.calls === void 0 ? deferred.length : 16;
729
779
  let perBaseLast = 0;
@@ -731,7 +781,7 @@ const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
731
781
  if (from > 0) size = nextChunk(input.calls, perBaseLast, size, deferred.length - from);
732
782
  const made = input.calls?.made() ?? 0;
733
783
  const chunk = deferred.slice(from, from + size);
734
- const named = idsBytes(chunk.flatMap((each) => withinOf(each.oid) < 0 && !types.has(each.oid) ? [each.oid] : []));
784
+ const named = idsBytes(chunk.flatMap((each) => each.inSlice < 0 && !types.has(each.oid) ? [each.oid] : []));
735
785
  const found = yield* Effect.result(cutAtSpent(outside.find(named.sorted, named.bytes)));
736
786
  if (Result.isFailure(found)) {
737
787
  spentMost = spentOf(found.failure)?.most;
@@ -748,12 +798,15 @@ const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
748
798
  const { within } = each;
749
799
  cut = cutBefore(within);
750
800
  if (cut !== void 0) break chunks;
751
- const done = yield* Effect.result(cutAtSpent(settleDeferred(each, types)));
752
- if (Result.isFailure(done)) {
753
- spentMost = spentOf(done.failure)?.most;
754
- if (spentMost === void 0) return yield* Effect.fail(done.failure);
755
- cut = within;
756
- break chunks;
801
+ const step = settleDeferred(each, types);
802
+ if (step !== void 0) {
803
+ const done = yield* Effect.result(cutAtSpent(step));
804
+ if (Result.isFailure(done)) {
805
+ spentMost = spentOf(done.failure)?.most;
806
+ if (spentMost === void 0) return yield* Effect.fail(done.failure);
807
+ cut = within;
808
+ break chunks;
809
+ }
757
810
  }
758
811
  each.pieces = void 0;
759
812
  if (counted + later.size >= input.bounds.links) {