@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
@@ -4,20 +4,26 @@ import { bestEffort } from "../store/errors.mjs";
4
4
  import { randomText } from "../store/random.mjs";
5
5
  import { newChangeId, repoScope } from "../store/scopes.mjs";
6
6
  import { hexOf } from "../protocol/bytes/hex.mjs";
7
+ import { scopedReader } from "../protocol/bytes/reader.mjs";
8
+ import { Sha1, Sha1State } from "../protocol/bytes/sha1.mjs";
7
9
  import { sha1NowHasher } from "../protocol/bytes/sha1-hasher.mjs";
8
- import { bucketDeleteMany, bucketDo, readWhole } from "./calls.mjs";
10
+ import { bucketDeleteMany, bucketDo, bucketStreamScoped, readWhole } from "./calls.mjs";
9
11
  import { putOnce } from "./index-build.mjs";
10
12
  import { packPutOptions, startPut } from "./merge.mjs";
11
13
  import { storeStep } from "./pack-receive.mjs";
14
+ import { pushUploadMost } from "./push-uploads.mjs";
12
15
  import { deletePackFiles, dropRefused, openQuarantine, quarantineOf, quarantineState } from "./quarantine.mjs";
13
16
  import { putStepState, readStepState, stepStateKeys } from "./receive-state.mjs";
14
- import { markerPrefix, objectCollections, packFiles, receivePrefix } from "./layout.mjs";
17
+ import { isPackId, markerPrefix, objectCollections, packFiles, receivePrefix } from "./layout.mjs";
15
18
  import { fileBytesMost } from "./file-limits.mjs";
16
19
  import { receiveCpuShare, receiveDropPage, receiveStepFloor, receiveStepGrace } from "./receive-bounds.mjs";
17
20
  import { decodeHeld, quarantineKey, stagedKey } from "./rows.mjs";
18
- import * as Effect from "effect/Effect";
19
21
  import * as Schema from "effect/Schema";
22
+ import * as Effect from "effect/Effect";
23
+ import * as Predicate from "effect/Predicate";
20
24
  import * as Exit from "effect/Exit";
25
+ import * as Result from "effect/Result";
26
+ import * as Hex from "effect/encoding/Hex";
21
27
  // src/storage/receive-steps.ts
22
28
  /**
23
29
  * A receive run in steps, by its pack: where its next step enters, and when its last step
@@ -152,8 +158,59 @@ const readAnswer = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack) {
152
158
  /** A pack's trailer: the SHA-1 of every byte before it. */
153
159
  const trailerBytes = 20;
154
160
  const badTrailer = (bytes) => fail("INVALID_ARGUMENT", `The staged pack's ${bytes} bytes don't end in the SHA-1 of the rest`, { hint: "Fetch the segment again" });
161
+ const wrongSize = (expected, actual) => fail("INVALID_ARGUMENT", `The staged pack has ${actual} bytes, not the ${expected} bytes declared`, { hint: "Push again" });
162
+ const missingStageSource = () => fail("INVALID_ARGUMENT", "the push's pack is missing or isn't a pack");
155
163
  const stageBroken = (cause) => gitError("UNAVAILABLE", `The segment's pack ended before it was staged: ${String(cause)}`);
156
164
  /**
165
+ * A 20-byte sliding tail for streaming SHA-1 trailer verification without copying incoming chunks:
166
+ * bytes past the trailing 20 feed `hash` directly, so a 1 GiB pack allocates only 20 bytes here.
167
+ */
168
+ var TrailerTail = class TrailerTail {
169
+ #buf = new Uint8Array(trailerBytes);
170
+ #len = 0;
171
+ static fromHex(hex) {
172
+ const tail = new TrailerTail();
173
+ if (hex.length === 0) return tail;
174
+ const bytes = Result.getOrThrow(Hex.decode(hex));
175
+ if (bytes.byteLength > trailerBytes) throw new RangeError("a pack's trailer tail exceeds 20 B");
176
+ tail.#buf.set(bytes, 0);
177
+ tail.#len = bytes.byteLength;
178
+ return tail;
179
+ }
180
+ push(chunk, hash) {
181
+ const n = chunk.byteLength;
182
+ if (n === 0) return;
183
+ if (this.#len + n <= trailerBytes) {
184
+ this.#buf.set(chunk, this.#len);
185
+ this.#len += n;
186
+ return;
187
+ }
188
+ if (n >= trailerBytes) {
189
+ if (this.#len > 0) hash.update(this.#buf.subarray(0, this.#len));
190
+ const bodyEnd = n - trailerBytes;
191
+ if (bodyEnd > 0) hash.update(chunk.subarray(0, bodyEnd));
192
+ this.#buf.set(chunk.subarray(bodyEnd), 0);
193
+ this.#len = trailerBytes;
194
+ return;
195
+ }
196
+ const drop = this.#len + n - trailerBytes;
197
+ hash.update(this.#buf.subarray(0, drop));
198
+ const keep = this.#len - drop;
199
+ if (keep > 0) this.#buf.copyWithin(0, drop, this.#len);
200
+ this.#buf.set(chunk, keep);
201
+ this.#len = trailerBytes;
202
+ }
203
+ get hex() {
204
+ return hexOf(this.#buf.subarray(0, this.#len));
205
+ }
206
+ matches(hash) {
207
+ if (this.#len < trailerBytes) return false;
208
+ const digest = hash.digest();
209
+ for (let i = 0; i < trailerBytes; i += 1) if (digest[i] !== this.#buf[i]) return false;
210
+ return true;
211
+ }
212
+ };
213
+ /**
157
214
  * A segment's pack staged for its steps, in an invocation of its own: a quarantine opened, the
158
215
  * pack put to its `.pack` key as it's read, every byte but its trailer hashed, the trailer
159
216
  * checked, then its answer put. A pack cut short, past `atMost`, or with another trailer is
@@ -165,27 +222,23 @@ const stageReceive = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
165
222
  return yield* Effect.gen(function* () {
166
223
  const reader = yield* Effect.acquireRelease(Effect.sync(() => input.pack.getReader()), (held, exit) => Exit.isSuccess(exit) ? Effect.void : Effect.promise(() => held.cancel().catch(() => void 0)));
167
224
  const hash = sha1NowHasher();
225
+ const tail = new TrailerTail();
168
226
  const put = yield* startPut(bucket, packFiles(pack).pack, packPutOptions(input));
169
- let held = /* @__PURE__ */ new Uint8Array(0);
170
227
  let bytes = 0;
171
228
  for (;;) {
172
229
  const read = yield* tryUnlessSpent(() => reader.read(), stageBroken);
173
230
  if (read.done) break;
174
231
  bytes += read.value.byteLength;
175
- const joined = new Uint8Array(held.byteLength + read.value.byteLength);
176
- joined.set(held, 0);
177
- joined.set(read.value, held.byteLength);
178
- const cut = Math.max(0, joined.byteLength - trailerBytes);
179
- hash.update(joined.subarray(0, cut));
180
- held = joined.slice(cut);
232
+ tail.push(read.value, hash);
181
233
  yield* put.write(read.value);
182
234
  }
183
- if (held.byteLength < trailerBytes || hexOf(hash.digest()) !== hexOf(held)) return yield* badTrailer(bytes);
235
+ if (input.length !== void 0 && bytes !== input.length) return yield* wrongSize(input.length, bytes);
236
+ if (!tail.matches(hash)) return yield* badTrailer(bytes);
184
237
  yield* put.finish;
185
238
  const answer = {
186
239
  ...input.answer,
187
240
  bytes,
188
- checksum: hexOf(held)
241
+ checksum: tail.hex
189
242
  };
190
243
  yield* putAnswer(bucket, pack, answer);
191
244
  return {
@@ -200,6 +253,238 @@ const stageReceive = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
200
253
  pack
201
254
  })));
202
255
  });
256
+ /** One uploaded multipart receipt kept across staging tries, matching infra's `ListedPart`. */
257
+ const StagePart = /* @__PURE__ */ Schema.Struct({
258
+ part: Schema.Int,
259
+ etag: Schema.String,
260
+ size: Schema.Int
261
+ });
262
+ /**
263
+ * Persisted progress of a stepped staging multipart put (#1931): the quarantine pack ID, its
264
+ * opaque `Bucket.beginPut` token, how many bytes of the uploaded pack have been committed to
265
+ * parts, their receipts, and the incremental SHA-1 + 20-byte tail up to `offset`.
266
+ */
267
+ const StageProgress = /* @__PURE__ */ Schema.Struct({
268
+ pack: Schema.String,
269
+ token: Schema.String,
270
+ offset: Schema.Int,
271
+ parts: Schema.Array(StagePart),
272
+ sha1: Sha1State,
273
+ tail: Schema.String.check(Schema.isPattern(/^(?:[0-9a-f]{2}){0,20}$/))
274
+ });
275
+ /**
276
+ * Opens a quarantine and server-side multipart put at `packs/<pack>.pack`, returning the initial
277
+ * `StageProgress` at offset 0 for the caller to persist before uploading parts. Drops the
278
+ * quarantine if `beginPut` fails or is interrupted.
279
+ */
280
+ const openStageReceive = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
281
+ const { bucket } = input;
282
+ const { pack } = yield* openQuarantine(input);
283
+ return {
284
+ pack,
285
+ token: yield* bucketDo(bucket.beginPut(packFiles(pack).pack)).pipe(Effect.tapError(() => dropRefused({
286
+ ...input,
287
+ pack
288
+ })), Effect.onInterrupt(() => dropRefused({
289
+ ...input,
290
+ pack
291
+ }))),
292
+ offset: 0,
293
+ parts: [],
294
+ sha1: new Sha1().state(),
295
+ tail: ""
296
+ };
297
+ });
298
+ /**
299
+ * Streams the final slice from `sourceBucket` into a restored `Sha1` + `TrailerTail` without
300
+ * uploading parts, verifying exact byte length (EOF+1) and SHA-1 trailer. Used during crash
301
+ * recovery when `completePut` already materialized `packs/<pack>.pack` before a crash prior to
302
+ * `putAnswer`.
303
+ */
304
+ const verifyFinalSlice = /* @__PURE__ */ Effect.fnUntraced(function* (sourceBucket, sourceKey, sliceStart, sliceLen, totalBytes, sha1, tailHex) {
305
+ const stream = yield* bucketStreamScoped(sourceBucket, sourceKey, {
306
+ offset: sliceStart,
307
+ length: sliceLen + 1
308
+ });
309
+ if (stream === void 0) return yield* missingStageSource();
310
+ const reader = yield* scopedReader(stream);
311
+ const hash = new Sha1(sha1);
312
+ const tail = TrailerTail.fromHex(tailHex);
313
+ let sliceRead = 0;
314
+ for (;;) {
315
+ const read = yield* tryUnlessSpent(() => reader.read(), stageBroken);
316
+ if (read.done) break;
317
+ sliceRead += read.value.byteLength;
318
+ if (sliceRead > sliceLen) return yield* wrongSize(totalBytes, sliceStart + sliceRead);
319
+ tail.push(read.value, hash);
320
+ }
321
+ if (sliceRead < sliceLen) return yield* wrongSize(totalBytes, sliceStart + sliceRead);
322
+ if (!tail.matches(hash)) return yield* badTrailer(totalBytes);
323
+ return tail.hex;
324
+ }, Effect.scoped);
325
+ /**
326
+ * Advances a stepped staging multipart put by one bounded slice (`sliceBytes` bytes in `partBytes`
327
+ * parts). On non-final slices, uploads its parts and returns the next `StageProgress` to persist.
328
+ * On the final slice, requests `sliceLen + 1` bytes to detect both truncated and oversized sources,
329
+ * verifies the 20-byte SHA-1 trailer before calling `completePut`, writes `packs/<pack>/answer`,
330
+ * and returns `staged`. Handles crashes after `completePut` (`NotFound` / `AlreadyExists`) by
331
+ * recovering an existing `answer` or verifying and writing it idempotently; treats a missing or
332
+ * expired multipart token with no materialized pack as `stage-gone`.
333
+ */
334
+ const stageReceiveStep = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
335
+ const { store, bucket, sourceBucket, repo, staging } = input;
336
+ if (!isPackId(staging.pack)) return yield* fail("INVALID_ARGUMENT", `No pack is staged as ${staging.pack}`);
337
+ const pack = staging.pack;
338
+ const packKey = packFiles(pack).pack;
339
+ const totalBytes = input.bytes;
340
+ const sliceStart = staging.offset;
341
+ const isFinal = sliceStart + input.sliceBytes >= totalBytes;
342
+ const sliceLen = Math.max(0, Math.min(input.sliceBytes, totalBytes - sliceStart));
343
+ const qState = yield* quarantineState({
344
+ store,
345
+ repo,
346
+ pack
347
+ });
348
+ const abortOpen = bucketDo(bucket.abortPut(packKey, staging.token)).pipe(Effect.catchIf((error) => error.code === "NOT_FOUND", () => Effect.void));
349
+ if (qState !== "open") {
350
+ const aborted = yield* Effect.result(abortOpen);
351
+ if (Result.isFailure(aborted)) return yield* Effect.fail(aborted.failure);
352
+ return yield* stageGone(`A staged pack's quarantine is ${qState}`);
353
+ }
354
+ const abortBad = Effect.fnUntraced(function* (failed) {
355
+ const aborted = yield* Effect.result(abortOpen);
356
+ if (Result.isSuccess(aborted)) yield* dropRefused({
357
+ store,
358
+ bucket,
359
+ indexes: input.indexes,
360
+ repo,
361
+ pack
362
+ });
363
+ return yield* failed;
364
+ });
365
+ const recoverNotFound = Effect.gen(function* () {
366
+ const existing = yield* readAnswer(bucket, pack).pipe(Effect.catchIf((error) => error.context?.reason === "stage-gone", () => Effect.succeed(void 0)));
367
+ if (existing !== void 0) return {
368
+ kind: "staged",
369
+ pack,
370
+ bytes: existing.bytes
371
+ };
372
+ if (isFinal) {
373
+ if ((yield* bucketDo(bucket.list(packKey, { limit: 1 }))).items.find((item) => item.key === packKey)?.size === totalBytes) {
374
+ const checksum = yield* verifyFinalSlice(sourceBucket, input.sourceKey, sliceStart, sliceLen, totalBytes, staging.sha1, staging.tail).pipe(Effect.catchIf((error) => error.code === "INVALID_ARGUMENT", (error) => abortBad(Effect.fail(error))));
375
+ const answer = {
376
+ ...input.answer,
377
+ bytes: totalBytes,
378
+ checksum
379
+ };
380
+ yield* putAnswer(bucket, pack, answer);
381
+ return {
382
+ kind: "staged",
383
+ pack,
384
+ bytes: totalBytes
385
+ };
386
+ }
387
+ }
388
+ yield* dropRefused({
389
+ store,
390
+ bucket,
391
+ indexes: input.indexes,
392
+ repo,
393
+ pack
394
+ });
395
+ return yield* stageGone(`A staged pack's multipart upload is gone at ${packKey}`);
396
+ });
397
+ return yield* Effect.gen(function* () {
398
+ const readLen = isFinal ? sliceLen + 1 : sliceLen;
399
+ const stream = yield* bucketStreamScoped(sourceBucket, input.sourceKey, {
400
+ offset: sliceStart,
401
+ length: Math.max(1, readLen)
402
+ });
403
+ if (stream === void 0) return yield* abortBad(missingStageSource());
404
+ const reader = yield* scopedReader(stream);
405
+ const hash = new Sha1(staging.sha1);
406
+ const tail = TrailerTail.fromHex(staging.tail);
407
+ const partSize = Math.max(1, Math.min(input.partBytes, Math.max(1, sliceLen)));
408
+ const partBuf = new Uint8Array(partSize);
409
+ const parts = [...staging.parts];
410
+ let nextPart = parts.length + 1;
411
+ let partFilled = 0;
412
+ let sliceRead = 0;
413
+ const flushPart = Effect.fnUntraced(function* (body) {
414
+ const part = nextPart;
415
+ const uploaded = yield* bucketDo(bucket.putPart(packKey, staging.token, part, body));
416
+ parts.push({
417
+ part: uploaded.part,
418
+ etag: uploaded.etag,
419
+ size: uploaded.size
420
+ });
421
+ nextPart += 1;
422
+ partFilled = 0;
423
+ });
424
+ for (;;) {
425
+ const read = yield* tryUnlessSpent(() => reader.read(), stageBroken);
426
+ if (read.done) break;
427
+ const chunk = read.value;
428
+ if (chunk.byteLength === 0) continue;
429
+ sliceRead += chunk.byteLength;
430
+ if (sliceRead > sliceLen) return yield* abortBad(wrongSize(totalBytes, sliceStart + sliceRead));
431
+ tail.push(chunk, hash);
432
+ let at = 0;
433
+ while (at < chunk.byteLength) {
434
+ const take = Math.min(partBuf.byteLength - partFilled, chunk.byteLength - at);
435
+ partBuf.set(chunk.subarray(at, at + take), partFilled);
436
+ partFilled += take;
437
+ at += take;
438
+ if (partFilled === partBuf.byteLength) yield* flushPart(partBuf);
439
+ }
440
+ }
441
+ if (sliceRead < sliceLen) return yield* abortBad(wrongSize(totalBytes, sliceStart + sliceRead));
442
+ if (partFilled > 0) yield* flushPart(partBuf.subarray(0, partFilled));
443
+ if (!isFinal) return {
444
+ kind: "more",
445
+ staging: {
446
+ pack,
447
+ token: staging.token,
448
+ offset: sliceStart + sliceRead,
449
+ parts,
450
+ sha1: hash.state(),
451
+ tail: tail.hex
452
+ }
453
+ };
454
+ if (!tail.matches(hash)) return yield* abortBad(badTrailer(totalBytes));
455
+ yield* bucketDo(bucket.completePut(packKey, staging.token, parts, {
456
+ size: input.bytes,
457
+ atMost: pushUploadMost
458
+ })).pipe(Effect.catchIf((error) => error.code === "ALREADY_EXISTS", () => Effect.void), Effect.tapError((error) => error.code === "RESOURCE_EXHAUSTED" || error.code === "INVALID_ARGUMENT" ? dropRefused({
459
+ store,
460
+ bucket,
461
+ indexes: input.indexes,
462
+ repo,
463
+ pack
464
+ }) : Effect.void));
465
+ const answer = {
466
+ ...input.answer,
467
+ bytes: totalBytes,
468
+ checksum: tail.hex
469
+ };
470
+ yield* putAnswer(bucket, pack, answer);
471
+ return {
472
+ kind: "staged",
473
+ pack,
474
+ bytes: totalBytes
475
+ };
476
+ }).pipe(Effect.scoped).pipe(Effect.catchIf((error) => error.code === "NOT_FOUND", () => recoverNotFound));
477
+ });
478
+ /**
479
+ * Internal handle attached to `packs()`' opened `GitObjects` for stepped multipart staging:
480
+ * module-private symbol (never `Symbol.for`, never on the public `GitObjects` contract).
481
+ */
482
+ const stageStepKey = Symbol("ref0/git stage step");
483
+ /** Reads the internal stepped-staging handle from `packs()`' opened `GitObjects`, if present. */
484
+ const stageStepOf = (objects) => {
485
+ if (!Predicate.hasProperty(objects, stageStepKey)) return void 0;
486
+ return objects[stageStepKey];
487
+ };
203
488
  /**
204
489
  * A staged receive no try can land, dropped: every key under its prefix but its markers, then its
205
490
  * record deleted and its `staged` row put, for what a step of an earlier try puts after (#1561),
@@ -394,4 +679,4 @@ const receiveStep = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
394
679
  yield* bestEffort(bucketDeleteMany(bucket, Object.values(keys)));
395
680
  return ended;
396
681
  });
397
- export { ReceiveAnswer, ReceiveRow, answerKey, commitStep, deleteStaged, dropReceive, newAttempt, putAnswer, readAnswer, readReceive, receiveKey, receiveStep, stageReceive, stagedRow, stepEntryMostOf, stepInflatedMostOf, stepShareOf, streamStepsMost };
682
+ export { ReceiveAnswer, ReceiveRow, StagePart, StageProgress, answerKey, commitStep, deleteStaged, dropReceive, newAttempt, openStageReceive, putAnswer, readAnswer, readReceive, receiveKey, receiveStep, stageReceive, stageReceiveStep, stageStepKey, stageStepOf, stagedRow, stepEntryMostOf, stepInflatedMostOf, stepShareOf, streamStepsMost };
@@ -55,11 +55,6 @@ const awaitingRepack = (packs, most) => gitError("UNAVAILABLE", `The repo has ${
55
55
  }
56
56
  });
57
57
  /**
58
- * Whether `error` refuses a push until upkeep runs, by its reason: `awaitingRepack`'s, or
59
- * `awaitingUpkeep`'s for a repo whose published batches are at `batchesMost`.
60
- */
61
- const isAwaitingUpkeep = (error) => error.code === "UNAVAILABLE" && (error.context?.reason === "packs-awaiting-repack" || error.context?.reason === "batches-awaiting-upkeep");
62
- /**
63
58
  * Refuses a push to `listed` past `backlogPacksMost` packs, or whose packs' join would pass
64
59
  * `receiveJoinGetsMost`. Its `most` is below the packs listed, since packs split unevenly can cost
65
60
  * more than an even split's.
@@ -70,4 +65,4 @@ const refuseBacklog = (listed) => {
70
65
  const objects = listed.packs.reduce((sum, pack) => sum + pack.objects, 0);
71
66
  return Effect.fail(awaitingRepack(packs, Math.min(packsMost(objects), packs - 1)));
72
67
  };
73
- export { awaitingRepack, backlogPacksMost, isAwaitingUpkeep, joinGets, packsMost, refuseBacklog };
68
+ export { awaitingRepack, backlogPacksMost, joinGets, packsMost, refuseBacklog };
@@ -6,9 +6,9 @@ import { noRows } from "./object-rows.mjs";
6
6
  import { openIndexRanges } from "./pack-ranges.mjs";
7
7
  import { compareIds } from "./raw-ids.mjs";
8
8
  import { leavingRows, namedOf } from "./repack.mjs";
9
- import * as Effect from "effect/Effect";
10
- import * as Schema from "effect/Schema";
11
9
  import { byBytes } from "@ref0/infra";
10
+ import * as Schema from "effect/Schema";
11
+ import * as Effect from "effect/Effect";
12
12
  // src/storage/repack-contained.ts
13
13
  /**
14
14
  * A listed pack whose every object another listed pack holds, which the step's geometric group
@@ -1,6 +1,6 @@
1
1
  import { collections } from "../store/scopes.mjs";
2
- import * as Schema from "effect/Schema";
3
2
  import { Job } from "@ref0/infra";
3
+ import * as Schema from "effect/Schema";
4
4
  // src/storage/repack-job.ts
5
5
  /**
6
6
  * `missed`: the commits of a step that drops objects that missed in a row, each because the
@@ -1,16 +1,15 @@
1
- import "../index.mjs";
2
1
  import "./merge.mjs";
3
2
  import "../contracts/objects.mjs";
4
3
  import "../contracts/time.mjs";
5
4
  import { RepoStats } from "../contracts/repos.mjs";
6
- import "../contracts/services.mjs";
5
+ import "../contracts/result.mjs";
7
6
  import "../contracts/store.mjs";
8
7
  import "./memory-budget.mjs";
9
8
  import "./object-rows.mjs";
10
9
  import "./pack-reads.mjs";
11
10
  import "./rows.mjs";
12
- import "effect/Effect";
13
11
  import { Key, Moment, Row } from "@ref0/infra";
12
+ import "effect/Effect";
14
13
  /**
15
14
  * How `packs()` merges a repo's packs: as Git's `repack --geometric=<geometric>`, by object
16
15
  * count, so each pack holds at least `geometric` times the objects of all smaller ones together;
@@ -4,10 +4,10 @@ import { backlogPacksMost } from "./repack-backlog.mjs";
4
4
  import { foldedRows } from "./merge-choose.mjs";
5
5
  import "./merge-cut.mjs";
6
6
  import { writeMerged } from "./merge.mjs";
7
- import { largeBatch, objectKey, objectOfRow, rowsMoved, tooLargeRead } from "./object-rows.mjs";
7
+ import { largeBatch, objectKey, objectOfRow, rowsInflatedBytes, rowsMoved, tooLargeRead } from "./object-rows.mjs";
8
8
  import { leavingRow, pruneFloor } from "./rows.mjs";
9
- import * as Effect from "effect/Effect";
10
9
  import { byBytes, limits } from "@ref0/infra";
10
+ import * as Effect from "effect/Effect";
11
11
  import * as Predicate from "effect/Predicate";
12
12
  // src/storage/repack.ts
13
13
  /** Git's `repack.geometric` of 2, and no pack past 1 GiB. */
@@ -122,15 +122,20 @@ const swapsOf = (listed, added, held) => {
122
122
  };
123
123
  /**
124
124
  * The repo's object rows, a small push's each, which a merge folds into its pack: the first
125
- * `foldedRows` of them, or as many of the largest as one read's 16 MiB answer holds. They're
126
- * `whole` when the read came back short of its limit.
125
+ * `foldedRows` of them (or those after `after` when scanning past page 1), falling back to
126
+ * `rowReadBatch` then `largeBatch` when one read's 16 MiB answer overflows. They're `whole` when
127
+ * the read came back short of its limit.
127
128
  */
128
- const readObjectRows = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
129
+ const readObjectRows = (input, after) => {
129
130
  const scope = repoScope(input.listed.repo);
130
131
  const page = (limit) => Effect.map(input.store.read({
131
132
  scope,
132
- reads: [{
133
+ reads: [after === void 0 ? {
134
+ collection: objectCollections.objects,
135
+ limit
136
+ } : {
133
137
  collection: objectCollections.objects,
138
+ after,
134
139
  limit
135
140
  }]
136
141
  }), (snapshot) => {
@@ -140,7 +145,47 @@ const readObjectRows = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
140
145
  whole: rows.length < limit
141
146
  };
142
147
  });
143
- return yield* page(foldedRows).pipe(Effect.catchIf(tooLargeRead, () => page(largeBatch)));
148
+ return page(foldedRows).pipe(Effect.catchIf(tooLargeRead, () => page(100).pipe(Effect.catchIf(tooLargeRead, () => page(largeBatch)))));
149
+ };
150
+ /**
151
+ * Whether the repo's object rows total more than `limit` inflated bytes: exact from `first` when
152
+ * it read every row, short-circuited when `stats` already shows loose row JSON bytes at or under
153
+ * `limit` (JSON base64 is always larger than inflated), else scanning subsequent pages past
154
+ * `first`'s last ID up to `rowsScanPagesMost` until the running inflated total passes `limit` or
155
+ * the rows end. If the scan hits `rowsScanPagesMost` without reaching the end, it returns `true`
156
+ * so upkeep folds a bounded page rather than stalling under a small-row prefix.
157
+ */
158
+ const rowsPastInflated = /* @__PURE__ */ Effect.fnUntraced(function* (input, first, limit, stats) {
159
+ const looseBytes = stats === void 0 ? 0 : stats.ownBytes - stats.packBytes;
160
+ if (looseBytes > 0 && looseBytes <= limit) return false;
161
+ let total = rowsInflatedBytes(first.rows);
162
+ if (total > limit || first.whole) return total > limit;
163
+ let after = first.rows.at(-1)?.id;
164
+ for (let scanned = 0; scanned < 32 && after !== void 0; scanned += 1) {
165
+ const read = yield* readObjectRows(input, after);
166
+ total += rowsInflatedBytes(read.rows);
167
+ if (total > limit) return true;
168
+ if (read.whole) return false;
169
+ after = read.rows.at(-1)?.id;
170
+ }
171
+ return true;
172
+ });
173
+ /**
174
+ * Folds `objectRows` into a pack of their own, with no walk: shared by prune passes whose first
175
+ * read didn't hold every row and by `git.repack` when accumulated rows pass `unpackInflatedMost`.
176
+ */
177
+ const foldStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, objectRows, most) {
178
+ const rows = yield* wholeRows(objectRows);
179
+ const merged = yield* mergeWith(input, {
180
+ rows,
181
+ most
182
+ });
183
+ if (merged === void 0 || merged === "too big") return void 0;
184
+ return {
185
+ change: replacing(input, merged, [], rows),
186
+ more: true,
187
+ quarantine: merged.quarantine
188
+ };
144
189
  });
145
190
  /** Each object row, read whole. */
146
191
  const wholeRows = (rows) => Effect.forEach(rows, (row) => objectOfRow(row));
@@ -246,7 +291,7 @@ const geometricGroup = (members, options, inputsMost = Number.POSITIVE_INFINITY,
246
291
  for (const member of sorted.slice(0, split)) {
247
292
  const share = shareOf(member, seen);
248
293
  if (most < packMost && share > most && share <= packMost) continue;
249
- if (taken.objects + member.objects > 15e5) break;
294
+ if (taken.objects + member.objects > 5e5) break;
250
295
  if (taken.bytes + share > most) break;
251
296
  if (taken.writes + member.writes > groupWrites || group.length === inputsMost) break;
252
297
  if (!fits([...group, member])) break;
@@ -258,4 +303,4 @@ const geometricGroup = (members, options, inputsMost = Number.POSITIVE_INFINITY,
258
303
  }
259
304
  return group.length < 2 ? [] : group;
260
305
  };
261
- export { burstGroupBytes, burstOptions, burstPacksMost, burstQuietMs, defaultRepack, geometricGroup, groupWrites, holdingsOf, holdsOf, leavingRows, maxPackSizeMost, mergeWith, namedOf, optionFor, readObjectRows, replacing, rowsBytes, shareOf, swapsOf, wholeRows };
306
+ export { burstGroupBytes, burstOptions, burstPacksMost, burstQuietMs, defaultRepack, foldStep, geometricGroup, groupWrites, holdingsOf, holdsOf, leavingRows, maxPackSizeMost, mergeWith, namedOf, optionFor, readObjectRows, replacing, rowsBytes, rowsPastInflated, shareOf, swapsOf, wholeRows };
@@ -0,0 +1,57 @@
1
+ import { chargedFixedCache } from "./charged-cache.mjs";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Context from "effect/Context";
4
+ // src/storage/request-cache.ts
5
+ /** Registers a per-request `ChargedCache` on `hold` so it releases when the request ends; releases at once if already closed. */
6
+ const keepRequestCache = (hold, cache) => {
7
+ if (hold.keep(Effect.sync(() => cache.release()))) return true;
8
+ cache.release();
9
+ return false;
10
+ };
11
+ /** Wraps a `RequestCacheBudget` (`MemoryBudget`) with the server-side `chargedFixedCache` opener. */
12
+ const serverRequestBudget = (budget) => {
13
+ const openWalkPassed = (most, entryBytes, maxEntries, hold, onEvict) => {
14
+ const cache = chargedFixedCache(budget.requestRoom(most), entryBytes, maxEntries, onEvict);
15
+ return {
16
+ passed: {
17
+ has: (key) => cache.has(key),
18
+ add: (key) => cache.set(key, true),
19
+ release: () => cache.release()
20
+ },
21
+ kept: hold === void 0 || keepRequestCache(hold, cache)
22
+ };
23
+ };
24
+ return {
25
+ requestRoom: (most) => budget.requestRoom(most),
26
+ openWalkPassed
27
+ };
28
+ };
29
+ /** Standalone request charge capped at `most` bytes, used only when no `MemoryBudget` is attached. */
30
+ const localRequestCharge = (most) => {
31
+ let used = 0;
32
+ let closed = false;
33
+ return {
34
+ lifetime: "request",
35
+ released: () => closed,
36
+ tryGrow: (bytes) => {
37
+ if (closed || used + bytes > most) return false;
38
+ used += bytes;
39
+ return true;
40
+ },
41
+ shrink: (bytes) => {
42
+ used = Math.max(0, used - bytes);
43
+ },
44
+ close: () => {
45
+ closed = true;
46
+ used = 0;
47
+ }
48
+ };
49
+ };
50
+ /** Returns a request room on `budget`, or a standalone capped charge when no budget is attached. */
51
+ const requestChargeOf = (budget, most) => budget === void 0 ? localRequestCharge(most) : budget.requestRoom(most);
52
+ /**
53
+ * The active storage `MemoryBudget` in request context, so per-request caches (`AudienceMemo`,
54
+ * `ViewedMemo`, `walkedVisible`) charge the server's budget directly without altering public types.
55
+ */
56
+ const RequestMemoryBudget = Context.Reference("@ref0/git/RequestMemoryBudget", { defaultValue: () => void 0 });
57
+ export { RequestMemoryBudget, keepRequestCache, localRequestCharge, requestChargeOf, serverRequestBudget };
@@ -1,7 +1,4 @@
1
1
  import "../contracts/object-values.mjs";
2
- import "../protocol/objects/object.mjs";
3
- import { linksOf } from "./links.mjs";
4
- import * as Result from "effect/Result";
5
2
  // src/storage/roots.ts
6
3
  /**
7
4
  * Of a receive's objects, in `oids`, those `named` says none of the others names: its roots. Links
@@ -35,24 +32,4 @@ const rootsCollected = (named) => {
35
32
  roots: () => past ? void 0 : roots
36
33
  };
37
34
  };
38
- /**
39
- * Of whole objects, a small push's rows, their links read again: their roots, and each object they
40
- * name outside them but the empty tree, which the repo needn't store. `undefined` past the most
41
- * roots, which proves nothing.
42
- */
43
- const wholeRoots = (objects) => {
44
- const named = /* @__PURE__ */ new Set();
45
- for (const object of objects) {
46
- const links = linksOf(object);
47
- if (Result.isFailure(links)) return void 0;
48
- for (const link of links.success) named.add(link.oid);
49
- }
50
- const own = new Set(objects.map(({ oid }) => oid));
51
- const roots = rootsOf(own, (oid) => named.has(oid));
52
- if (roots === void 0) return void 0;
53
- return {
54
- roots,
55
- outside: [...named].filter((oid) => !own.has(oid) && oid !== "4b825dc642cb6eb9a060e54bf8d69288fbee4904")
56
- };
57
- };
58
- export { rootsCollected, rootsOf, wholeRoots };
35
+ export { rootsCollected, rootsOf };
@@ -1,6 +1,6 @@
1
1
  import "../contracts/time.mjs";
2
2
  import "../contracts/result.mjs";
3
3
  import "./layout.mjs";
4
- import "effect/Effect";
4
+ import { Key, Moment, Row } from "@ref0/infra";
5
5
  import "effect/Schema";
6
- import { Key, Moment, Row } from "@ref0/infra";
6
+ import "effect/Effect";
@@ -2,8 +2,8 @@ import { millis } from "../contracts/time.mjs";
2
2
  import { fail } from "../contracts/result.mjs";
3
3
  import { decodeRow } from "../store/errors.mjs";
4
4
  import { isPackId, objectCollections } from "./layout.mjs";
5
- import * as Effect from "effect/Effect";
6
5
  import * as Schema from "effect/Schema";
6
+ import * as Effect from "effect/Effect";
7
7
  // src/storage/rows.ts
8
8
  /**
9
9
  * A pack being written, added before its first byte. `open` while its writer may still list it;
@@ -3,6 +3,6 @@ import "../contracts/result.mjs";
3
3
  import "../protocol/packs/step.mjs";
4
4
  import "./layout.mjs";
5
5
  import "./receive-bounds.mjs";
6
- import "effect/Effect";
6
+ import { Page } from "@ref0/infra";
7
7
  import "effect/Schema";
8
- import { Page } from "@ref0/infra";
8
+ import "effect/Effect";
@@ -4,8 +4,8 @@ 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