@ref0/git 0.20.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) 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 +20 -17
  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 +2 -2
  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 +125 -94
  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 +3 -15
  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/host-bucket.mjs +9 -4
  252. package/dist/storage/index-bitmaps.mjs +77 -49
  253. package/dist/storage/index-build.d.mts +2 -3
  254. package/dist/storage/index-build.mjs +248 -48
  255. package/dist/storage/index-fetch.d.mts +3 -1
  256. package/dist/storage/index-fetch.mjs +60 -21
  257. package/dist/storage/index-graph.mjs +1 -1
  258. package/dist/storage/index-layers.mjs +55 -25
  259. package/dist/storage/index-reach.mjs +15 -22
  260. package/dist/storage/index-whole.d.mts +7 -0
  261. package/dist/storage/index-whole.mjs +145 -37
  262. package/dist/storage/largest-files.mjs +1 -7
  263. package/dist/storage/layout.mjs +17 -1
  264. package/dist/storage/lfs-pointers.mjs +1 -6
  265. package/dist/storage/link-join.mjs +55 -16
  266. package/dist/storage/list-source.d.mts +7 -0
  267. package/dist/storage/list-source.mjs +288 -0
  268. package/dist/storage/loose.d.mts +8 -8
  269. package/dist/storage/loose.mjs +157 -91
  270. package/dist/storage/memory-budget.mjs +226 -22
  271. package/dist/storage/merge-cut.mjs +9 -6
  272. package/dist/storage/merge-fence.mjs +1 -1
  273. package/dist/storage/merge-row.mjs +1 -1
  274. package/dist/storage/merge.d.mts +2 -3
  275. package/dist/storage/merge.mjs +2 -2
  276. package/dist/storage/object-rows.d.mts +3 -3
  277. package/dist/storage/object-rows.mjs +179 -38
  278. package/dist/storage/pack-order.mjs +97 -44
  279. package/dist/storage/pack-ranges.mjs +44 -16
  280. package/dist/storage/pack-reads.d.mts +5 -3
  281. package/dist/storage/pack-reads.mjs +236 -72
  282. package/dist/storage/pack-receive.d.mts +1 -2
  283. package/dist/storage/pack-receive.mjs +21 -17
  284. package/dist/storage/packs.d.mts +1 -1
  285. package/dist/storage/packs.mjs +477 -116
  286. package/dist/storage/placed-reads.mjs +33 -16
  287. package/dist/storage/prune-seen.mjs +1 -1
  288. package/dist/storage/prune-walk.mjs +1 -1
  289. package/dist/storage/prune.mjs +4 -31
  290. package/dist/storage/push-allotment.mjs +26 -14
  291. package/dist/storage/push-uploads.mjs +195 -57
  292. package/dist/storage/pushed-commits.mjs +20 -1
  293. package/dist/storage/quarantine.d.mts +2 -3
  294. package/dist/storage/range-cache.mjs +175 -40
  295. package/dist/storage/raw-ids.mjs +39 -10
  296. package/dist/storage/ready.d.mts +2 -3
  297. package/dist/storage/ready.mjs +114 -38
  298. package/dist/storage/receive-bounds.mjs +31 -9
  299. package/dist/storage/receive-cache.d.mts +7 -0
  300. package/dist/storage/receive-cache.mjs +147 -0
  301. package/dist/storage/receive-files.mjs +1 -1
  302. package/dist/storage/receive-links.mjs +1 -1
  303. package/dist/storage/receive-state.d.mts +2 -2
  304. package/dist/storage/receive-state.mjs +6 -8
  305. package/dist/storage/receive-steps.d.mts +20 -0
  306. package/dist/storage/receive-steps.mjs +298 -13
  307. package/dist/storage/repack-backlog.mjs +1 -6
  308. package/dist/storage/repack-contained.mjs +2 -2
  309. package/dist/storage/repack-job.mjs +1 -1
  310. package/dist/storage/repack.d.mts +2 -3
  311. package/dist/storage/repack.mjs +54 -9
  312. package/dist/storage/request-cache.mjs +57 -0
  313. package/dist/storage/roots.mjs +1 -24
  314. package/dist/storage/rows.d.mts +2 -2
  315. package/dist/storage/rows.mjs +1 -1
  316. package/dist/storage/runs.d.mts +2 -2
  317. package/dist/storage/runs.mjs +1 -1
  318. package/dist/storage/send-list.mjs +62 -25
  319. package/dist/storage/stream-whole.mjs +84 -63
  320. package/dist/storage/swap-walk.mjs +1 -1
  321. package/dist/storage/unpack.mjs +878 -450
  322. package/dist/storage/visible.mjs +110 -32
  323. package/dist/storage/walk.mjs +1 -0
  324. package/dist/storage/wants.mjs +22 -58
  325. package/dist/store/call-count.d.mts +2 -2
  326. package/dist/store/call-count.mjs +24 -11
  327. package/dist/store/catalogue.d.mts +1 -1
  328. package/dist/store/catalogue.mjs +19 -7
  329. package/dist/store/crossing.mjs +1 -7
  330. package/dist/store/cursor-seal.d.mts +1 -1
  331. package/dist/store/cursor-seal.mjs +1 -1
  332. package/dist/store/door.mjs +9 -4
  333. package/dist/store/errors.d.mts +2 -2
  334. package/dist/store/errors.mjs +107 -19
  335. package/dist/store/git-store.mjs +7 -2
  336. package/dist/store/job-try.mjs +90 -9
  337. package/dist/store/list-job.mjs +10 -34
  338. package/dist/store/outbox.d.mts +2 -2
  339. package/dist/store/outbox.mjs +2 -2
  340. package/dist/store/queue-jobs.mjs +6 -12
  341. package/dist/store/records.d.mts +2 -2
  342. package/dist/store/records.mjs +2 -2
  343. package/dist/store/ref-rows.d.mts +2 -2
  344. package/dist/store/ref-rows.mjs +2 -2
  345. package/dist/store/repo-record.d.mts +2 -2
  346. package/dist/store/repo-record.mjs +3 -3
  347. package/dist/store/request-snapshot.mjs +5 -0
  348. package/dist/store/reservations.mjs +2 -2
  349. package/dist/store/topic-jobs.mjs +5 -11
  350. package/dist/sync/bound.d.mts +3 -3
  351. package/dist/sync/bound.mjs +10 -7
  352. package/dist/sync/github.mjs +65 -67
  353. package/dist/sync/http.mjs +1 -1
  354. package/dist/sync/import.mjs +201 -66
  355. package/dist/sync/layer.d.mts +1 -1
  356. package/dist/sync/layer.mjs +6 -6
  357. package/dist/sync/lfs-batch.mjs +1 -1
  358. package/dist/sync/lfs-copy.mjs +175 -15
  359. package/dist/sync/mirror.mjs +5 -10
  360. package/dist/sync/said.mjs +1 -1
  361. package/dist/sync/step.mjs +268 -86
  362. package/dist/sync/tries.mjs +25 -6
  363. package/dist/sync.d.mts +2 -2
  364. package/dist/sync.mjs +2 -2
  365. package/dist/topics/advance.mjs +3 -3
  366. package/dist/topics/calls.mjs +1 -1
  367. package/dist/topics/layer.d.mts +15 -14
  368. package/dist/topics/members.mjs +1 -1
  369. package/dist/topics/topic.mjs +1 -1
  370. package/package.json +3 -13
  371. package/dist/auth/helpers.mjs +0 -17
  372. package/dist/auth.d.mts +0 -5
  373. package/dist/auth.mjs +0 -5
  374. package/dist/core/rules/commit-changes.d.mts +0 -12
  375. package/dist/effect.d.mts +0 -9
  376. package/dist/effect.mjs +0 -7
  377. package/dist/server/joined.d.mts +0 -70
  378. package/dist/server/joined.mjs +0 -41
@@ -1,11 +1,13 @@
1
- import { fail } from "../../contracts/result.mjs";
1
+ import { allotmentWithin, grownBy, objectsReadMost } from "../../contracts/object-values.mjs";
2
+ import { fail, gitError } from "../../contracts/result.mjs";
2
3
  import { diffTrees } from "../../engine/diff.mjs";
3
4
  import { fromDiff } from "../../engine/failures.mjs";
4
- import { indexCursor, indexOf, inputDigest, limitOf, limitsOf, timed } from "../../engine/reads.mjs";
5
+ import { badCursor, inputDigest, limitOf, limitsOf, timed, treeCursorDepthMost, treeLimitMost } from "../../engine/reads.mjs";
5
6
  import { joinedBytes } from "../../protocol/bytes/joined.mjs";
6
7
  import { isFolder } from "../../protocol/diff/paths.mjs";
8
+ import { readAheadBytesMost } from "../../protocol/diff/read.mjs";
7
9
  import { pathText } from "../../protocol/diff/tree-diff.mjs";
8
- import { scopedReader } from "../../storage/calls.mjs";
10
+ import "../../protocol/objects/object.mjs";
9
11
  import { isOid } from "../../protocol/bytes/text.mjs";
10
12
  import { callerFor } from "../access.mjs";
11
13
  import { dropped, fitting, jsonSize, openRead, readerOf, withinResponse } from "./reading.mjs";
@@ -13,7 +15,6 @@ import { mergePartsOrOff } from "../merge-parts.mjs";
13
15
  import { callAllot } from "./lines.mjs";
14
16
  import { editTree, editsWithin } from "./tree-edits.mjs";
15
17
  import { objectWrite, oidAnswer, takeWrites } from "./writing.mjs";
16
- import { answerFailed } from "../../contracts/calls-spent.mjs";
17
18
  import { ObjectsParts } from "../parts.mjs";
18
19
  import * as Effect from "effect/Effect";
19
20
  // src/core/objects/trees.ts
@@ -41,69 +42,262 @@ const entryOf = (entry, path) => {
41
42
  if (!full.exact) listed.pathBytes = path;
42
43
  return listed;
43
44
  };
45
+ const walkLimit = (message) => gitError("RESOURCE_EXHAUSTED", message, { context: { reason: "walk-limit" } });
46
+ const childPathOf = (base, name) => base === void 0 ? name : joinedBytes([
47
+ base,
48
+ slash,
49
+ name
50
+ ]);
51
+ /** Materializes the full root-to-entry index path once, when `pageOf` emits `next`. */
52
+ const treeNodePosition = (node) => {
53
+ const indices = [];
54
+ for (let at = node; at !== void 0; at = at.parent) indices.push(at.index);
55
+ return indices.reverse();
56
+ };
57
+ /** Encodes a tree position as `/`-separated non-negative integers (no `.` or `-`, safe in `HeldCursor`). */
58
+ const treePositionText = (position) => position.join("/");
59
+ /**
60
+ * Decodes a tree position from `text`, refusing anything `treePositionText` couldn't write:
61
+ * empty strings, oversized tokens (checked before splitting), leading/trailing slashes, leading
62
+ * zeros, non-digits, unsafe integers, depth past `treeCursorDepthMost`, or multi-segment paths
63
+ * when `recursive` is false.
64
+ */
65
+ const treePositionOf = (text, recursive) => {
66
+ if (text === void 0) return Effect.succeed(void 0);
67
+ const maxDepth = recursive ? treeCursorDepthMost : 1;
68
+ if (text.length === 0 || text.length > maxDepth * 17) return badCursor();
69
+ const parts = text.split("/");
70
+ if (parts.length > maxDepth) return badCursor();
71
+ const position = [];
72
+ for (const part of parts) {
73
+ const index = Number(part);
74
+ if (!/^(?:0|[1-9]\d*)$/.test(part) || !Number.isSafeInteger(index)) return badCursor();
75
+ position.push(index);
76
+ }
77
+ return Effect.succeed(position);
78
+ };
79
+ /** A `trees.get` cursor: `<digest>.<i0>/<i1>/...`, bound to the content-addressed root OID and mode. */
80
+ const treeCursor = (digest, position) => `${digest}.${treePositionText(position)}`;
81
+ /** Decodes a `trees.get` cursor bound to `digest` and `recursive`, or fails `badCursor()`. */
82
+ const treeAfterOf = (after, digest, recursive) => {
83
+ if (after === void 0) return Effect.succeed(void 0);
84
+ return after.startsWith(`${digest}.`) ? treePositionOf(after.slice(digest.length + 1), recursive) : badCursor();
85
+ };
86
+ /** Opens a scoped allotment for a tree listing's retained stack frames and path bytes. */
87
+ const walkAllotment = (opened, most) => Effect.acquireRelease(Effect.sync(() => opened.allotment(most, walkLimit(`The walk holds past ${most} bytes`))), (allotment) => Effect.sync(() => allotment.release()));
88
+ /** Sentinel refusal for speculative tree read-ahead: stops reading ahead without failing the walk. */
89
+ const readAheadRefused = /* @__PURE__ */ gitError("RESOURCE_EXHAUSTED", `The tree read-ahead holds past ${readAheadBytesMost} bytes`, { context: { reason: "walk-limit" } });
44
90
  /**
45
- * A tree's entries, from `start`, at most `most`: in the tree's order, and with `recursive` each
46
- * folder before what it holds, as `ls-tree -r -t` lists them, a submodule not entered. Paths start
47
- * with `prefix`. Reads stop once `most` are found, past which `more` says entries follow.
91
+ * Opens a scoped allotment out of the request's memory budget (`opened.allotment`) for speculative
92
+ * tree read-ahead, capped at `min(readAheadBytesMost, most)`.
93
+ */
94
+ const readAheadAllotment = (opened, most = readAheadBytesMost) => Effect.acquireRelease(Effect.sync(() => opened.allotment(Math.min(readAheadBytesMost, most), readAheadRefused)), (allotment) => Effect.sync(() => allotment.release()));
95
+ const tooDeep = () => Effect.fail(walkLimit(`The tree nests past ${treeCursorDepthMost} levels`));
96
+ /** How many more object reads `reader` and its call tally allow before hitting `objects`. */
97
+ const objectsLeft = (reader) => Math.min(reader.limits.objects - reader.objects, reader.tally === void 0 ? Infinity : reader.tally.limits.objects - reader.tally.objects);
98
+ /**
99
+ * A tree's entries, after `after` (from the start when `undefined`), at most `most`: in the tree's
100
+ * order, and with `recursive` each folder before what it holds, as `ls-tree -r -t` lists them, a
101
+ * submodule not entered. Paths start with `prefix`. Seeking through `after` reads only the
102
+ * ancestor trees along that path, never earlier siblings (#2960). When `reader` supports batch
103
+ * reads, recursive walks probe one subtree at each depth to estimate entries per folder, then
104
+ * prefetch upcoming folders at that depth (across already-prefetched sibling parents) strictly
105
+ * from object allowance above what the rest of the page could still need without prefetch (#2974).
106
+ * Refuses to descend past `treeCursorDepthMost` with `walk-limit`, so every emitted `next`
107
+ * decodes. Frames keep one parent link (`TreeNode`), charged per level through both `reader` and
108
+ * `allotment`, and `pageOf` materializes the cut entry's full position once when a page ends.
48
109
  */
49
110
  const listTree = /* @__PURE__ */ Effect.fnUntraced(function* (reader, tree, options) {
111
+ const { allotment, recursive } = options;
112
+ const readAhead = options.readAhead ?? allotmentWithin(Math.min(524288, reader.limits.bytes), readAheadRefused);
50
113
  const entries = [];
51
- const stack = [{
52
- children: yield* reader.treeOf(tree),
53
- at: 0,
54
- path: options.prefix
55
- }];
56
- let index = 0;
57
- for (let frame = stack.at(-1); frame !== void 0; frame = stack.at(-1)) {
58
- const child = frame.children[frame.at];
59
- if (child === void 0) {
60
- stack.pop();
61
- continue;
114
+ const nodes = [];
115
+ const enter = (child) => recursive && isFolder(child) && child.oid !== "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
116
+ const prefetched = /* @__PURE__ */ new Set();
117
+ const depthStats = /* @__PURE__ */ new Map();
118
+ let readAheadStopped = false;
119
+ const recordDepth = (depth, children) => {
120
+ let cost = 1 + children.length;
121
+ for (const child of children) if (enter(child)) cost += 1;
122
+ const stat = depthStats.get(depth);
123
+ if (stat === void 0) depthStats.set(depth, {
124
+ trees: 1,
125
+ entries: cost
126
+ });
127
+ else {
128
+ stat.trees += 1;
129
+ stat.entries += cost;
130
+ }
131
+ };
132
+ const readSubtree = Effect.fnUntraced(function* (oid, depth) {
133
+ const children = yield* reader.treeOf(oid);
134
+ prefetched.add(oid);
135
+ recordDepth(depth, children);
136
+ return children;
137
+ });
138
+ const charge = (bytes) => allotment === void 0 ? reader.charge(bytes) : Effect.flatMap(reader.charge(bytes), () => Effect.flatMap(grownBy(allotment, bytes), (refused) => refused === void 0 ? Effect.void : Effect.fail(refused)));
139
+ const stack = [];
140
+ /**
141
+ * Batches upcoming unprefetched folder trees at `targetDepth` in DFS order, starting with
142
+ * `firstOid`. Waits for one probed subtree at `targetDepth` so fat-directory pages never
143
+ * over-read past `options.most`, inspects prefetched parent folders without charging `bytes`,
144
+ * and holds read-ahead trees under `readAhead` so bytes are charged only when the walk takes
145
+ * each tree. A read-ahead refusal drops the batch and stops reading ahead for the rest of the
146
+ * page without failing the walk.
147
+ */
148
+ const prefetchLevel = Effect.fnUntraced(function* (targetDepth, firstOid, remaining) {
149
+ if (readAheadStopped || reader.batch === void 0 || prefetched.has(firstOid) || remaining < 2) return;
150
+ const stat = depthStats.get(targetDepth);
151
+ if (stat === void 0) return;
152
+ const left = objectsLeft(reader);
153
+ const allowed = left - Math.min(left, remaining);
154
+ const estimated = Math.max(1, Math.ceil((remaining + 1) / (stat.entries / stat.trees)));
155
+ const want = Math.min(estimated, objectsReadMost, allowed);
156
+ if (want <= 1) return;
157
+ const batch = [firstOid];
158
+ const seen = /* @__PURE__ */ new Set([firstOid]);
159
+ let budgetEntries = remaining - 1;
160
+ const collect = Effect.fnUntraced(function* (list, from, childDepth) {
161
+ for (let at = from; at < list.length && batch.length < want && budgetEntries > 0; at += 1) {
162
+ const entry = list[at];
163
+ if (entry === void 0) continue;
164
+ if (!enter(entry)) {
165
+ budgetEntries -= 1;
166
+ continue;
167
+ }
168
+ if (childDepth === targetDepth) {
169
+ if (!prefetched.has(entry.oid) && !seen.has(entry.oid)) {
170
+ seen.add(entry.oid);
171
+ batch.push(entry.oid);
172
+ }
173
+ budgetEntries -= 2;
174
+ continue;
175
+ }
176
+ budgetEntries -= 1;
177
+ if (budgetEntries <= 0 || !prefetched.has(entry.oid)) return false;
178
+ const sub = yield* reader.peekTree(entry.oid);
179
+ if (sub === void 0) return false;
180
+ if (!(yield* collect(sub, 0, childDepth + 1))) return false;
181
+ }
182
+ return batch.length < want && budgetEntries > 0;
183
+ });
184
+ for (let level = targetDepth - 1; level >= 0; level -= 1) {
185
+ const ancestor = stack[level];
186
+ if (ancestor === void 0) break;
187
+ if (!(yield* collect(ancestor.c, ancestor.at, level + 1))) break;
188
+ }
189
+ if (batch.length <= 1) return;
190
+ if (!(yield* reader.prefetchAhead(batch, readAhead, readAheadRefused))) {
191
+ readAheadStopped = true;
192
+ return;
193
+ }
194
+ for (const oid of batch) prefetched.add(oid);
195
+ });
196
+ return yield* Effect.gen(function* () {
197
+ const rootHeld = 64 + (options.prefix?.length ?? 0);
198
+ yield* charge(rootHeld);
199
+ if (options.after === void 0) stack.push({
200
+ c: yield* reader.treeOf(tree),
201
+ at: 0,
202
+ p: options.prefix,
203
+ n: void 0,
204
+ h: rootHeld
205
+ });
206
+ else {
207
+ if (options.after.length === 0 || options.after.length > (recursive ? 4096 : 1)) return yield* badCursor();
208
+ let children = yield* reader.treeOf(tree);
209
+ let path = options.prefix;
210
+ let node;
211
+ let held = rootHeld;
212
+ for (let depth = 0; depth < options.after.length; depth += 1) {
213
+ const index = options.after[depth] ?? -1;
214
+ const child = Number.isSafeInteger(index) && index >= 0 ? children[index] : void 0;
215
+ const last = depth === options.after.length - 1;
216
+ if (child === void 0 || !last && !isFolder(child)) return yield* badCursor();
217
+ stack.push({
218
+ c: children,
219
+ at: index + 1,
220
+ p: path,
221
+ n: node,
222
+ h: held
223
+ });
224
+ node = {
225
+ index,
226
+ parent: node
227
+ };
228
+ if (!last || enter(child)) {
229
+ if (stack.length >= 4096) return yield* tooDeep();
230
+ path = childPathOf(path, child.name);
231
+ held = 64 + path.length;
232
+ yield* charge(held);
233
+ children = yield* readSubtree(child.oid, stack.length);
234
+ if (last) stack.push({
235
+ c: children,
236
+ at: 0,
237
+ p: path,
238
+ n: node,
239
+ h: held
240
+ });
241
+ }
242
+ }
62
243
  }
63
- frame.at += 1;
64
- const path = frame.path === void 0 ? child.name : joinedBytes([
65
- frame.path,
66
- slash,
67
- child.name
68
- ]);
69
- yield* reader.charge(path.length);
70
- if (index >= options.start) {
244
+ for (let frame = stack.at(-1); frame !== void 0; frame = stack.at(-1)) {
245
+ const childIndex = frame.at;
246
+ const child = frame.c[childIndex];
247
+ if (child === void 0) {
248
+ stack.pop();
249
+ allotment?.shrink(frame.h);
250
+ continue;
251
+ }
71
252
  if (entries.length === options.most) return {
72
253
  entries,
254
+ nodes,
73
255
  more: true
74
256
  };
257
+ frame.at += 1;
258
+ const path = childPathOf(frame.p, child.name);
259
+ yield* charge(64 + path.length);
260
+ const node = {
261
+ index: childIndex,
262
+ parent: frame.n
263
+ };
75
264
  entries.push(entryOf(child, path));
265
+ nodes.push(node);
266
+ if (enter(child)) {
267
+ if (stack.length >= 4096) return yield* tooDeep();
268
+ yield* charge(64);
269
+ const targetDepth = stack.length;
270
+ yield* prefetchLevel(targetDepth, child.oid, options.most - entries.length);
271
+ stack.push({
272
+ c: yield* readSubtree(child.oid, targetDepth),
273
+ at: 0,
274
+ p: path,
275
+ n: node,
276
+ h: 64
277
+ });
278
+ }
76
279
  }
77
- index += 1;
78
- if (options.recursive && isFolder(child)) stack.push({
79
- children: yield* reader.treeOf(child.oid),
80
- at: 0,
81
- path
82
- });
83
- }
84
- return {
85
- entries,
86
- more: false
87
- };
280
+ return {
281
+ entries,
282
+ nodes,
283
+ more: false
284
+ };
285
+ }).pipe(Effect.ensuring(Effect.sync(() => reader.releaseReadAhead())));
88
286
  });
89
287
  /**
90
288
  * `listed`'s entries, each blob with its size, as `ls-tree -l` gives it: read from the object's
91
- * header, through `objects.sizes`, the blob's bytes never read. A blob the repo lacks is
92
- * `NOT_FOUND`, as reading it would be, unless the core is `partial`: then it has no `size`, since
93
- * the client fetches no blob to size it.
289
+ * header, through `opened.sizes` on the call's scoped reader, the blob's bytes never read. A blob
290
+ * the repo lacks is `NOT_FOUND`, as reading it would be, unless the core is `partial`: then it has
291
+ * no `size`, since the client fetches no blob to size it.
94
292
  */
95
293
  const sized = /* @__PURE__ */ Effect.fnUntraced(function* (opened, listed) {
96
294
  const { partial } = yield* ObjectsParts;
97
295
  const blobs = [...new Set(listed.entries.filter((entry) => entry.type === "blob").map((entry) => entry.oid))];
98
296
  if (blobs.length === 0) return listed;
99
- const answer = yield* Effect.scoped(Effect.flatMap(scopedReader(opened.objects, opened.listed), (reader) => Effect.promise((signal) => reader.sizes({
100
- oids: blobs,
101
- signal
102
- }))));
103
- if (answer.kind === "error") return yield* answerFailed(answer.error);
297
+ const sizes = yield* opened.sizes({ oids: blobs });
104
298
  const entries = yield* Effect.forEach(listed.entries, (entry) => {
105
299
  if (entry.type !== "blob") return Effect.succeed(entry);
106
- const size = answer.value.get(entry.oid);
300
+ const size = sizes.get(entry.oid);
107
301
  if (size === void 0 && partial === true) return Effect.succeed(entry);
108
302
  if (size === void 0) return fail("NOT_FOUND", `object ${entry.oid} is missing`);
109
303
  return Effect.succeed({
@@ -121,7 +315,7 @@ const treeCalls = (bound) => {
121
315
  return {
122
316
  get: Effect.fnUntraced(function* (repo, input) {
123
317
  const limits = yield* limitsOf(input.limits);
124
- const limit = yield* limitOf(input.page);
318
+ const limit = yield* limitOf(input.page, treeLimitMost);
125
319
  const recursive = input.recursive === true;
126
320
  if (!isOid(input.oid)) return yield* notAnOid(input.oid);
127
321
  const digest = yield* inputDigest([
@@ -129,15 +323,18 @@ const treeCalls = (bound) => {
129
323
  input.oid,
130
324
  String(recursive)
131
325
  ]);
132
- const start = yield* indexOf(input.page?.after, digest);
326
+ const after = yield* treeAfterOf(input.page?.after, digest, recursive);
133
327
  const opened = yield* openRead(callerOf(input), repo, [], input.internalId);
134
328
  const { reader, deadline } = yield* readerOf(opened, limits, "walk-limit");
329
+ const allotment = yield* walkAllotment(opened, limits.reads.bytes);
330
+ const readAhead = yield* readAheadAllotment(opened, limits.reads.bytes);
135
331
  const listing = treeish(reader, input.oid).pipe(Effect.andThen(listTree(reader, input.oid, {
136
- prefix: void 0,
137
332
  recursive,
138
- start,
139
- most: limit
140
- })), Effect.mapError(fromDiff("walk-limit")), Effect.flatMap((listed) => sized(opened, listed)), Effect.flatMap((listed) => pageOf(listed, start, "The tree page", (index) => indexCursor(digest, index))));
333
+ after,
334
+ most: limit,
335
+ allotment,
336
+ readAhead
337
+ })), Effect.mapError(fromDiff("walk-limit")), Effect.flatMap((listed) => sized(opened, listed)), Effect.flatMap((listed) => pageOf(listed, "The tree page", (position) => treeCursor(digest, position))));
141
338
  return yield* timed(listing, deadline);
142
339
  }, Effect.scoped),
143
340
  diff: Effect.fnUntraced(function* (repo, input) {
@@ -221,14 +418,16 @@ const treeish = (reader, oid) => Effect.flatMap(reader.object(oid), (object) =>
221
418
  return fail("INVALID_ARGUMENT", `${oid} names a blob, not a tree`);
222
419
  });
223
420
  /**
224
- * A listing of entries found from `start`, cut to the response bound: `next` the cursor of the
225
- * index after the last entry kept, when more follow it.
421
+ * A listing of entries cut to the response bound: `next` the cursor of the last entry kept, when
422
+ * more follow it.
226
423
  */
227
- const pageOf = (listed, start, what, cursorOf) => Effect.map(fitting(listed.entries.map(jsonSize), what), (kept) => {
424
+ const pageOf = (listed, what, cursorOf) => Effect.map(fitting(listed.entries.map(jsonSize), what), (kept) => {
228
425
  const items = listed.entries.slice(0, kept);
229
- return listed.more || kept < listed.entries.length ? {
426
+ const more = listed.more || kept < listed.entries.length;
427
+ const last = listed.nodes[kept - 1];
428
+ return more && last !== void 0 ? {
230
429
  items,
231
- next: cursorOf(start + kept)
430
+ next: cursorOf(treeNodePosition(last))
232
431
  } : { items };
233
432
  });
234
- export { listTree, notAnOid, pageOf, sized, treeCalls, treeish };
433
+ export { listTree, notAnOid, pageOf, readAheadAllotment, readAheadRefused, sized, treeCalls, treeNodePosition, treePositionOf, treePositionText, treeish, walkAllotment };
@@ -13,13 +13,12 @@ import { keyedPushWith, pushWith } from "../push.mjs";
13
13
  import { ownWriter, ownWrites } from "../own-writes.mjs";
14
14
  import { objectAnswer } from "../receipts.mjs";
15
15
  import { objectIn, openKeyedRead } from "./reading.mjs";
16
- import { tryUnlessSpent } from "../../contracts/calls-spent.mjs";
17
16
  import { CoreParts } from "../parts.mjs";
18
17
  import { check } from "../../contracts/authorize.mjs";
19
- import * as Clock from "effect/Clock";
20
- import * as Effect from "effect/Effect";
21
18
  import { limits } from "@ref0/infra";
19
+ import * as Effect from "effect/Effect";
22
20
  import * as Predicate from "effect/Predicate";
21
+ import * as Clock from "effect/Clock";
23
22
  import * as Hex from "effect/encoding/Hex";
24
23
  /** The most the objects one write makes hold together. */
25
24
  const writeBytesMost = 67108864;
@@ -112,12 +111,7 @@ const writeDigest = (call, parts) => Effect.promise(async () => {
112
111
  });
113
112
  /** The objects a merge made, read whole into `made`. */
114
113
  const takeWrites = /* @__PURE__ */ Effect.fnUntraced(function* (made, writes) {
115
- const held = yield* tryUnlessSpent(async () => {
116
- const all = [];
117
- for await (const write of writes) all.push(write);
118
- return all;
119
- }, (cause) => gitError("INTERNAL", `The merge's objects failed mid-read: ${String(cause)}`));
120
- for (const write of held) {
114
+ for (const write of writes) {
121
115
  const bytes = yield* Effect.mapError(drained(write, objectBytesMost, { copy: true }), fromDiff("diff-limit"));
122
116
  yield* made.add(write.type, new Uint8Array(bytes));
123
117
  }
@@ -1,8 +1,8 @@
1
1
  import { decodeRow, storeCall } from "../store/errors.mjs";
2
2
  import { collections, repoScope } from "../store/scopes.mjs";
3
3
  import { dayMs, dayOf, sweepDue, sweepOf } from "./receipts.mjs";
4
- import * as Effect from "effect/Effect";
5
4
  import * as Schema from "effect/Schema";
5
+ import * as Effect from "effect/Effect";
6
6
  import * as Hex from "effect/encoding/Hex";
7
7
  // src/core/own-writes.ts
8
8
  /**
@@ -5,6 +5,8 @@ import { GrantFences } from "../auth/fences.mjs";
5
5
  import { HeldGrants } from "../auth/grants.mjs";
6
6
  import { CursorSeal } from "../store/cursor-seal.mjs";
7
7
  import { EventLog } from "../contracts/events.mjs";
8
+ import { RefEdit } from "../contracts/refs.mjs";
9
+ import { GitError } from "../contracts/result.mjs";
8
10
  import { HiddenRefs } from "../protocol/wire/lines.mjs";
9
11
  import { IndexLost } from "./index-lost.mjs";
10
12
  import { PushChecks } from "./access.mjs";
@@ -14,8 +16,8 @@ import { RefIndex } from "./ref-index.mjs";
14
16
  import { SealedObjects } from "./view.mjs";
15
17
  import { Changes } from "./changes.mjs";
16
18
  import { Objects } from "./objects/objects.mjs";
19
+ import { JobDefinition, JobInput, JobQueue, Moment, Records, Row } from "@ref0/infra";
17
20
  import * as Effect from "effect/Effect";
18
- import { JobDefinition, JobInput, JobQueue, Moment, Records } from "@ref0/infra";
19
21
  import * as Context from "effect/Context";
20
22
  /**
21
23
  * A prefix a registration publishes, `RegisterInput.publishes`: refs `Git.host` writes under it on
@@ -101,6 +103,11 @@ export interface CoreFields {
101
103
  * another package's job in its commit, as a push saves `sync.mirror`. None on a client.
102
104
  */
103
105
  readonly jobOf?: (name: string) => JobDefinition | undefined;
106
+ /**
107
+ * Decodes the repo's `mirrors` rows for a push and answers the `sync.mirror` jobs for the refs
108
+ * the commit moves: wired by the server, none on a client, which holds no mirrors.
109
+ */
110
+ readonly mirrorJobs?: (rows: readonly Row[], jobOf: (name: string) => JobDefinition | undefined) => Effect.Effect<(moved: readonly RefEdit[]) => readonly JobInput[], GitError>;
104
111
  /**
105
112
  * `true` on host code's parts (Q223), as `asHost` makes them for `Git.host`'s calls: its list
106
113
  * reads every repo, where a signed-out caller's reads only public ones.
@@ -3,10 +3,11 @@ import { hostAuthorize } from "../auth/authorize.mjs";
3
3
  import { Changes } from "./changes.mjs";
4
4
  import { Objects } from "./objects/objects.mjs";
5
5
  import { Rules } from "../contracts/rules.mjs";
6
- import * as Clock from "effect/Clock";
6
+ import { RequestMemoryBudget } from "../storage/request-cache.mjs";
7
7
  import * as Effect from "effect/Effect";
8
- import * as Option from "effect/Option";
9
8
  import * as Context from "effect/Context";
9
+ import * as Option from "effect/Option";
10
+ import * as Clock from "effect/Clock";
10
11
  import * as Struct from "effect/Struct";
11
12
  // src/core/parts.ts
12
13
  /** The server's sealed objects, which each boundary provides beside `CoreParts`. */
@@ -31,8 +32,11 @@ const coreContext = Effect.gen(function* () {
31
32
  const authorize = yield* Authorize;
32
33
  const clock = yield* Effect.clockWith(Effect.succeed);
33
34
  const rules = yield* Effect.serviceOption(Rules);
34
- const needs = Context.make(CoreParts, parts).pipe(Context.add(ObjectsParts, objects), Context.add(Objects, reads), Context.add(Changes, changes), Context.add(Authorize, authorize), Context.add(Clock.Clock, clock));
35
- return Option.isSome(rules) ? Context.add(needs, Rules, rules.value) : needs;
35
+ const budget = yield* RequestMemoryBudget;
36
+ let needs = Context.make(CoreParts, parts).pipe(Context.add(ObjectsParts, objects), Context.add(Objects, reads), Context.add(Changes, changes), Context.add(Authorize, authorize), Context.add(Clock.Clock, clock));
37
+ if (Option.isSome(rules)) needs = Context.add(needs, Rules, rules.value);
38
+ if (budget !== void 0) needs = Context.add(needs, RequestMemoryBudget, budget);
39
+ return needs;
36
40
  });
37
41
  /** `effect` deciding with `check` in `Authorize`'s place, its other answers kept. */
38
42
  const decidingWith = (check) => (effect) => Effect.updateService(effect, Authorize, (decider) => ({
@@ -12,9 +12,9 @@ import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
12
12
  import { droppedDelivery, isDeliverJob, notFailed, sentThrough } from "./events/deliver.mjs";
13
13
  import { retiredAmong } from "./events/retired.mjs";
14
14
  import { indexJobName } from "./index-job.mjs";
15
- import * as Effect from "effect/Effect";
15
+ import { Job, limits } from "@ref0/infra";
16
16
  import * as Schema from "effect/Schema";
17
- import { Job, defineJob, limits } from "@ref0/infra";
17
+ import * as Effect from "effect/Effect";
18
18
  // src/core/purge.ts
19
19
  /**
20
20
  * `git.purge`, a deleted repo's last job (L61, L130). Not before its delete's `fetchLimits` has
@@ -129,6 +129,7 @@ const purgeCollections = [
129
129
  objectCollections.objects,
130
130
  objectCollections.stagedObjects,
131
131
  objectCollections.stagedSizes,
132
+ objectCollections.stagedDeltas,
132
133
  objectCollections.objectChunks,
133
134
  objectCollections.batches,
134
135
  objectCollections.batchQuarantine,
@@ -158,6 +159,24 @@ const PurgeData = /* @__PURE__ */ Schema.Struct({
158
159
  wait: Schema.optionalKey(WaitKind),
159
160
  spins: Schema.optionalKey(Schema.Int)
160
161
  });
162
+ /**
163
+ * `parts` as one step, in order: the first that did some answers `did`, and one that waits holds
164
+ * none after it, since each deletes only its own rows and bytes. A deleted repo's drop-in sweep
165
+ * can wait days on its own jobs, and LFS's bytes, behind it by name, would wait with it. Once none
166
+ * did, it waits, naming each part that waits, until every one is done.
167
+ */
168
+ const stepParts = (parts) => Effect.fnUntraced(function* (store, repo) {
169
+ const named = [];
170
+ let waits = false;
171
+ for (const part of parts) {
172
+ const step = yield* part(store, repo);
173
+ if (step === "did") return step;
174
+ if (step === "waits") waits = true;
175
+ else if (step !== "done") named.push(step.waits);
176
+ }
177
+ if (named.length > 0) return { waits: named.join("', '") };
178
+ return waits ? "waits" : "done";
179
+ });
161
180
  const again = { kind: "more" };
162
181
  const hasStuckState = (data) => data.since !== void 0 || data.wait !== void 0 || data.spins !== void 0;
163
182
  /** Genuine progress made: clears prior stall/spin tracking when any was set. */
@@ -390,13 +409,7 @@ const dropScopes = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, in
390
409
  * A dropped delivery's waiting job made due at `at`: a save moves a waiting job's due only earlier,
391
410
  * so a claim takes it. Its handler never runs, since no queue of this server runs its delivery.
392
411
  */
393
- const droppedDueAt = (item, at) => defineJob({
394
- name: item.name,
395
- schema: Schema.toStandardSchemaV1(Schema.Unknown),
396
- handler: () => {
397
- throw new TypeError(`${item.name} is a delivery this server doesn't run`);
398
- }
399
- }).job({
412
+ const droppedDueAt = (item, at) => Job.make(item.name, { payload: Schema.Unknown }).encodedJob({
400
413
  key: item.key,
401
414
  data: item.data,
402
415
  at
@@ -429,11 +442,12 @@ const endDropped = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at
429
442
  const waiting = dropped.filter((item) => item.state === "waiting");
430
443
  const later = waiting.flatMap((item) => item.due > at ? [droppedDueAt(item, at)] : []);
431
444
  if (later.length > 0) yield* storeCall(store.add(scope, { jobs: later }));
432
- const names = waiting.map((item) => item.name);
433
445
  const request = {
434
- lease: droppedLease,
435
- names,
436
- limit: names.length
446
+ names: [...new Set(waiting.map((item) => item.name))].map((name) => ({
447
+ name,
448
+ lease: droppedLease
449
+ })),
450
+ limit: waiting.length
437
451
  };
438
452
  const { claims } = waiting.length === 0 ? { claims: [] } : yield* storeCall(store.jobs.claim(scope, request));
439
453
  const retired = yield* retiredAmong(store, droppedNames(dropped, deliveries));
@@ -532,10 +546,9 @@ const purgeStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, int
532
546
  return yield* waitOrFail(scope, data, at, at + purgeBackstop, waiting.kind, "fork-hold", waiting.detail);
533
547
  }
534
548
  if (drain.dropped && !(yield* endDropped(store, scope, at, deleted, parts.deliveries))) return yield* spinOrFail(scope, data, "end-dropped", "ending dropped delivery jobs");
535
- for (const part of parts.parts) {
536
- const step = yield* part(store, internalId);
537
- if (step === "done") continue;
538
- if (step === "did") return progressed(data);
549
+ const step = yield* stepParts(parts.parts)(store, internalId);
550
+ if (step === "did") return progressed(data);
551
+ if (step !== "done") {
539
552
  const detail = step === "waits" ? "a purge part waiting" : `purge part '${step.waits}' waiting`;
540
553
  return yield* waitOrFail(scope, data, at, at + purgeBackstop, "drain", "part", detail);
541
554
  }
@@ -576,4 +589,4 @@ const purgeJobRow = (job, at) => job.job({
576
589
  data: {},
577
590
  at
578
591
  });
579
- export { purgeBackstop, purgeCollections, purgeDrainLimit, purgeJob, purgeJobKey, purgeJobName, purgeJobRow, purgePage, purgeRunningRelook, purgeStallLimit };
592
+ export { purgeBackstop, purgeCollections, purgeDrainLimit, purgeJob, purgeJobKey, purgeJobName, purgeJobRow, purgePage, purgeRunningRelook, purgeStallLimit, stepParts };
@@ -13,5 +13,5 @@ import "../store/records.mjs";
13
13
  import "../store/repo-record.mjs";
14
14
  import "./access.mjs";
15
15
  import "./receipts.mjs";
16
- import "effect/Effect";
17
- import { JobInput, Key, Row } from "@ref0/infra";
16
+ import { JobInput, JobQueue, Key, Moment, Records, Row } from "@ref0/infra";
17
+ import "effect/Effect";