@ref0/git 0.14.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (492) hide show
  1. package/dist/access/private-refs.mjs +1 -1
  2. package/dist/auth/access-jwt.mjs +4 -4
  3. package/dist/auth/auth-namespace.d.mts +3 -3
  4. package/dist/auth/auth-namespace.mjs +3 -2
  5. package/dist/auth/auth.d.mts +3 -3
  6. package/dist/auth/auth.mjs +9 -8
  7. package/dist/auth/authorize.mjs +4 -4
  8. package/dist/auth/fences.d.mts +1 -2
  9. package/dist/auth/fences.mjs +3 -3
  10. package/dist/auth/grants.mjs +4 -4
  11. package/dist/auth/host-function.mjs +19 -2
  12. package/dist/auth/host-services.mjs +4 -6
  13. package/dist/auth/identify.d.mts +1 -1
  14. package/dist/auth/identify.mjs +9 -3
  15. package/dist/auth/token-cleanup.mjs +67 -0
  16. package/dist/auth/token-rows.mjs +7 -2
  17. package/dist/auth/token-text.mjs +9 -1
  18. package/dist/auth/tokens-base.d.mts +35 -0
  19. package/dist/auth/tokens-base.mjs +13 -0
  20. package/dist/auth/tokens-layer.d.mts +2 -27
  21. package/dist/auth/tokens-layer.mjs +6 -11
  22. package/dist/auth/tokens-public.d.mts +3 -3
  23. package/dist/auth/tokens.d.mts +7 -10
  24. package/dist/auth/tokens.mjs +10 -81
  25. package/dist/client/answer.mjs +21 -42
  26. package/dist/client/client.d.mts +17 -11
  27. package/dist/client/client.mjs +21 -12
  28. package/dist/client/git-http.mjs +18 -8
  29. package/dist/client/local.mjs +74 -37
  30. package/dist/client/negotiate.mjs +3 -3
  31. package/dist/client/push-upload.mjs +34 -17
  32. package/dist/client/remote.mjs +12 -13
  33. package/dist/client/run-remote-helper.d.mts +2 -1
  34. package/dist/client/run-remote-helper.mjs +61 -27
  35. package/dist/client/slice-push.d.mts +1 -1
  36. package/dist/client/transport.mjs +105 -46
  37. package/dist/contracts/blobs.d.mts +58 -11
  38. package/dist/contracts/blobs.mjs +17 -3
  39. package/dist/contracts/call-allowance.d.mts +13 -0
  40. package/dist/contracts/call-allowance.mjs +44 -0
  41. package/dist/contracts/calls-spent.mjs +12 -35
  42. package/dist/contracts/client.d.mts +18 -18
  43. package/dist/contracts/commits.d.mts +28 -28
  44. package/dist/contracts/commits.mjs +1 -1
  45. package/dist/contracts/engine.d.mts +8 -3
  46. package/dist/contracts/engine.mjs +10 -1
  47. package/dist/contracts/events.d.mts +1 -1
  48. package/dist/contracts/events.mjs +1 -1
  49. package/dist/contracts/files.d.mts +14 -14
  50. package/dist/contracts/files.mjs +1 -1
  51. package/dist/contracts/forks.d.mts +21 -21
  52. package/dist/contracts/forks.mjs +1 -1
  53. package/dist/contracts/git-events.d.mts +29 -1
  54. package/dist/contracts/git-hooks.d.mts +2 -2
  55. package/dist/contracts/git.d.mts +30 -5
  56. package/dist/contracts/grants.d.mts +24 -4
  57. package/dist/contracts/handlers.d.mts +1 -1
  58. package/dist/contracts/lfs.d.mts +28 -2
  59. package/dist/contracts/merges.d.mts +3 -2
  60. package/dist/contracts/object-values.d.mts +1 -0
  61. package/dist/contracts/object-values.mjs +16 -1
  62. package/dist/contracts/objects.d.mts +42 -41
  63. package/dist/contracts/opaque.mjs +1 -1
  64. package/dist/contracts/operations.mjs +1 -1
  65. package/dist/contracts/queue.d.mts +247 -55
  66. package/dist/contracts/queue.mjs +8 -9
  67. package/dist/contracts/refs.d.mts +30 -27
  68. package/dist/contracts/refs.mjs +1 -1
  69. package/dist/contracts/remote.d.mts +8 -12
  70. package/dist/contracts/remote.mjs +4 -1
  71. package/dist/contracts/repos.d.mts +32 -141
  72. package/dist/contracts/repos.mjs +6 -4
  73. package/dist/contracts/result.d.mts +40 -18
  74. package/dist/contracts/result.mjs +42 -9
  75. package/dist/contracts/rules.d.mts +2 -2
  76. package/dist/contracts/server.d.mts +25 -52
  77. package/dist/contracts/services.d.mts +6 -9
  78. package/dist/contracts/services.mjs +1 -2
  79. package/dist/contracts/signin.d.mts +1 -1
  80. package/dist/contracts/store.d.mts +7 -6
  81. package/dist/contracts/sync.d.mts +73 -12
  82. package/dist/contracts/sync.mjs +14 -3
  83. package/dist/contracts/tags.d.mts +13 -13
  84. package/dist/contracts/tags.mjs +1 -1
  85. package/dist/contracts/time.d.mts +3 -0
  86. package/dist/contracts/{promises.mjs → time.mjs} +1 -1
  87. package/dist/contracts/tokens.d.mts +17 -19
  88. package/dist/contracts/tokens.mjs +4 -3
  89. package/dist/contracts/topics.d.mts +10 -10
  90. package/dist/contracts/trees.d.mts +16 -16
  91. package/dist/contracts/trees.mjs +1 -1
  92. package/dist/contracts/work.d.mts +28 -17
  93. package/dist/contracts/work.mjs +2 -2
  94. package/dist/core/access.d.mts +1 -2
  95. package/dist/core/access.mjs +20 -9
  96. package/dist/core/ancestry.d.mts +1 -0
  97. package/dist/core/ancestry.mjs +30 -34
  98. package/dist/core/asked.mjs +1 -1
  99. package/dist/core/call-groups.mjs +48 -0
  100. package/dist/core/call-names.mjs +6 -1
  101. package/dist/core/call-services.mjs +11 -3
  102. package/dist/core/events/deliver.d.mts +2 -3
  103. package/dist/core/events/deliver.mjs +45 -38
  104. package/dist/core/events/retired.mjs +119 -0
  105. package/dist/core/forks.mjs +929 -433
  106. package/dist/core/hooks/groups.mjs +3 -3
  107. package/dist/core/imports.mjs +127 -41
  108. package/dist/core/index-job.mjs +131 -38
  109. package/dist/core/index-lost.d.mts +1 -2
  110. package/dist/core/index-lost.mjs +2 -2
  111. package/dist/core/loose-tally.mjs +38 -15
  112. package/dist/core/merge-parts.d.mts +17 -4
  113. package/dist/core/merge-parts.mjs +7 -2
  114. package/dist/core/mirror-rows.mjs +31 -1
  115. package/dist/core/objects/blobs.mjs +127 -3
  116. package/dist/core/objects/files.mjs +20 -17
  117. package/dist/core/objects/lines.mjs +2 -2
  118. package/dist/core/objects/merges.mjs +4 -1
  119. package/dist/core/objects/objects-layer.d.mts +1 -1
  120. package/dist/core/objects/objects-layer.mjs +4 -4
  121. package/dist/core/objects/peel.mjs +1 -7
  122. package/dist/core/objects/reading.mjs +41 -29
  123. package/dist/core/objects/tags.mjs +4 -1
  124. package/dist/core/objects/tree-edits.mjs +1 -1
  125. package/dist/core/objects/trees.mjs +257 -58
  126. package/dist/core/objects/writing.mjs +4 -10
  127. package/dist/core/own-writes.mjs +2 -2
  128. package/dist/core/parts.d.mts +11 -5
  129. package/dist/core/parts.mjs +9 -10
  130. package/dist/core/purge.mjs +310 -93
  131. package/dist/core/push-decide.mjs +2 -0
  132. package/dist/core/push-files.d.mts +1 -1
  133. package/dist/core/push.d.mts +2 -2
  134. package/dist/core/push.mjs +170 -128
  135. package/dist/core/receipts.d.mts +2 -2
  136. package/dist/core/receipts.mjs +17 -5
  137. package/dist/core/ref-index-job.mjs +7 -7
  138. package/dist/core/ref-view.mjs +75 -32
  139. package/dist/core/refs.mjs +7 -7
  140. package/dist/core/registered-rows.mjs +2 -2
  141. package/dist/core/repack.mjs +58 -48
  142. package/dist/core/repo-info.mjs +3 -3
  143. package/dist/core/repos.mjs +21 -9
  144. package/dist/core/rules/changes.mjs +18 -40
  145. package/dist/core/rules/check.mjs +6 -5
  146. package/dist/core/rules/commit-changes.mjs +3 -15
  147. package/dist/core/rules/context.d.mts +3 -3
  148. package/dist/core/rules/context.mjs +18 -14
  149. package/dist/core/rules/fetch.mjs +1 -1
  150. package/dist/core/rules/protect.mjs +30 -17
  151. package/dist/core/saved-caller-views.d.mts +8 -3
  152. package/dist/core/saved-caller-views.mjs +4 -4
  153. package/dist/core/saved-callers.d.mts +19 -2
  154. package/dist/core/saved-callers.mjs +1 -1
  155. package/dist/core/seam.d.mts +17 -28
  156. package/dist/core/seam.mjs +7 -28
  157. package/dist/core/tokens.mjs +1 -1
  158. package/dist/core/view.d.mts +6 -3
  159. package/dist/core/view.mjs +18 -25
  160. package/dist/core/work.mjs +60 -15
  161. package/dist/engine/allotted-xdiff.mjs +3 -16
  162. package/dist/engine/combined.d.mts +3 -0
  163. package/dist/engine/combined.mjs +200 -185
  164. package/dist/engine/content.d.mts +2 -2
  165. package/dist/engine/content.mjs +1 -1
  166. package/dist/engine/failures.mjs +2 -1
  167. package/dist/engine/merge.mjs +7 -9
  168. package/dist/engine/reads.d.mts +2 -2
  169. package/dist/engine/reads.mjs +25 -17
  170. package/dist/engine/xdiff.d.mts +1 -1
  171. package/dist/engine/xdiff.mjs +1 -1
  172. package/dist/event-streams/event-streams.d.mts +1 -1
  173. package/dist/event-streams/event-streams.mjs +1 -1
  174. package/dist/event-streams/stream.d.mts +3 -3
  175. package/dist/event-streams/stream.mjs +39 -16
  176. package/dist/extend.d.mts +2 -7
  177. package/dist/extend.mjs +1 -4
  178. package/dist/http/answers.mjs +8 -5
  179. package/dist/http/core-parts.mjs +169 -96
  180. package/dist/http/handler.mjs +82 -10
  181. package/dist/http/node.d.mts +14 -1
  182. package/dist/http/node.mjs +56 -27
  183. package/dist/http/parts.d.mts +2 -0
  184. package/dist/http/push-upload-job.mjs +165 -47
  185. package/dist/http/push-uploads.mjs +37 -22
  186. package/dist/http/receive-pack.mjs +14 -53
  187. package/dist/http/request-snapshot.mjs +258 -0
  188. package/dist/http/upload-pack.mjs +25 -20
  189. package/dist/index.d.mts +36 -28
  190. package/dist/index.mjs +12 -3
  191. package/dist/lfs/answer.mjs +37 -0
  192. package/dist/lfs/base.d.mts +3 -1
  193. package/dist/lfs/base.mjs +25 -1
  194. package/dist/lfs/copy.d.mts +70 -8
  195. package/dist/lfs/copy.mjs +217 -21
  196. package/dist/lfs/layer.d.mts +19 -4
  197. package/dist/lfs/layer.mjs +25 -13
  198. package/dist/lfs/locks.mjs +3 -3
  199. package/dist/lfs/objects.d.mts +2 -1
  200. package/dist/lfs/objects.mjs +89 -19
  201. package/dist/lfs/pointers.mjs +2 -2
  202. package/dist/lfs/rows.d.mts +1 -1
  203. package/dist/lfs/rows.mjs +50 -9
  204. package/dist/lfs/upkeep.mjs +82 -17
  205. package/dist/lfs/uploaded.mjs +1 -1
  206. package/dist/lfs/wire.mjs +7 -32
  207. package/dist/merges/merges.mjs +19 -4
  208. package/dist/node.d.mts +2 -2
  209. package/dist/protocol/bytes/buffers.d.mts +1 -1
  210. package/dist/protocol/bytes/buffers.mjs +14 -6
  211. package/dist/protocol/bytes/deflate.d.mts +1 -1
  212. package/dist/protocol/bytes/deflate.mjs +1 -1
  213. package/dist/protocol/bytes/inflate.d.mts +1 -1
  214. package/dist/protocol/bytes/inflate.mjs +1 -1
  215. package/dist/protocol/bytes/reader.mjs +6 -1
  216. package/dist/protocol/bytes/sha1.d.mts +1 -1
  217. package/dist/protocol/bytes/sha1.mjs +1 -1
  218. package/dist/protocol/bytes/streams.mjs +27 -1
  219. package/dist/protocol/diff/read.d.mts +6 -4
  220. package/dist/protocol/diff/read.mjs +110 -11
  221. package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
  222. package/dist/protocol/objects/lfs-pointer.mjs +1 -3
  223. package/dist/protocol/objects/links-raw.mjs +24 -10
  224. package/dist/protocol/objects/tag.d.mts +1 -1
  225. package/dist/protocol/objects/tree.mjs +23 -6
  226. package/dist/protocol/packs/delta.d.mts +6 -3
  227. package/dist/protocol/packs/delta.mjs +96 -32
  228. package/dist/protocol/packs/graph.mjs +1 -1
  229. package/dist/protocol/packs/idx.d.mts +3 -2
  230. package/dist/protocol/packs/idx.mjs +23 -4
  231. package/dist/protocol/packs/parts.d.mts +4 -1
  232. package/dist/protocol/packs/parts.mjs +10 -7
  233. package/dist/protocol/packs/reader.d.mts +6 -1
  234. package/dist/protocol/packs/reader.mjs +4 -3
  235. package/dist/protocol/packs/write-error.d.mts +1 -1
  236. package/dist/protocol/packs/write-error.mjs +1 -1
  237. package/dist/protocol/packs/writer.mjs +26 -8
  238. package/dist/protocol/wire/advertisement.d.mts +1 -1
  239. package/dist/protocol/wire/advertisement.mjs +3 -2
  240. package/dist/protocol/wire/fetch.d.mts +1 -1
  241. package/dist/protocol/wire/fetch.mjs +1 -1
  242. package/dist/protocol/wire/lines.d.mts +9 -1
  243. package/dist/protocol/wire/lines.mjs +28 -1
  244. package/dist/protocol/wire/push-uploads.mjs +10 -7
  245. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  246. package/dist/protocol/wire/receive-pack.mjs +1 -1
  247. package/dist/protocol/wire/report-status.d.mts +1 -1
  248. package/dist/protocol/wire/report-status.mjs +1 -1
  249. package/dist/protocol/wire/v2.d.mts +1 -1
  250. package/dist/protocol/wire/v2.mjs +1 -1
  251. package/dist/queue/advance.mjs +48 -44
  252. package/dist/queue/base.d.mts +57 -0
  253. package/dist/queue/base.mjs +44 -0
  254. package/dist/queue/calls.mjs +54 -57
  255. package/dist/queue/commit.mjs +2 -2
  256. package/dist/queue/host.d.mts +2 -16
  257. package/dist/queue/host.mjs +2 -7
  258. package/dist/queue/layer.d.mts +2 -2
  259. package/dist/queue/layer.mjs +19 -8
  260. package/dist/queue/limits.mjs +2 -0
  261. package/dist/queue/push-option.mjs +9 -24
  262. package/dist/queue/schedule.mjs +2 -2
  263. package/dist/queue/search.mjs +1 -1
  264. package/dist/queue/state.mjs +3 -11
  265. package/dist/queue/trim.mjs +6 -4
  266. package/dist/rest/blobs.mjs +29 -5
  267. package/dist/rest/caller.d.mts +4 -4271
  268. package/dist/rest/caller.mjs +4 -0
  269. package/dist/rest/client.d.mts +9 -6
  270. package/dist/rest/client.mjs +25 -8
  271. package/dist/rest/errors.mjs +1 -1
  272. package/dist/rest/handler.mjs +2 -2
  273. package/dist/rest/handlers.mjs +66 -11
  274. package/dist/rest/layer.d.mts +2 -2
  275. package/dist/rest/layer.mjs +6 -13
  276. package/dist/rest/listen.mjs +2 -2
  277. package/dist/rest/me.d.mts +3 -432
  278. package/dist/rest/refs.mjs +1 -1
  279. package/dist/server/check-fetch.mjs +3 -3
  280. package/dist/server/edge-node.d.mts +11 -8
  281. package/dist/server/edge-node.mjs +9 -6
  282. package/dist/server/edge.d.mts +21 -7
  283. package/dist/server/edge.mjs +56 -11
  284. package/dist/server/extension.mjs +1 -1
  285. package/dist/server/git-layer.d.mts +5 -6
  286. package/dist/server/git-layer.mjs +28 -23
  287. package/dist/server/git-namespace.d.mts +4 -3
  288. package/dist/server/git-namespace.mjs +3 -2
  289. package/dist/server/lifecycle.mjs +19 -107
  290. package/dist/server/registry.mjs +24 -13
  291. package/dist/server/server.mjs +249 -371
  292. package/dist/signin/context.d.mts +1 -2
  293. package/dist/signin/context.mjs +1 -1
  294. package/dist/signin/forms.mjs +1 -1
  295. package/dist/signin/grants.d.mts +2 -2
  296. package/dist/signin/grants.mjs +1 -1
  297. package/dist/signin/layer.d.mts +1 -1
  298. package/dist/signin/layer.mjs +1 -1
  299. package/dist/signin/wire.mjs +1 -1
  300. package/dist/storage/allotted.mjs +22 -12
  301. package/dist/storage/batch-upkeep.mjs +293 -0
  302. package/dist/storage/batches.d.mts +7 -0
  303. package/dist/storage/batches.mjs +347 -0
  304. package/dist/storage/budget.mjs +23 -1
  305. package/dist/storage/calls.d.mts +2 -3
  306. package/dist/storage/calls.mjs +166 -182
  307. package/dist/storage/charged-cache.mjs +180 -0
  308. package/dist/storage/chunks.d.mts +9 -0
  309. package/dist/storage/chunks.mjs +410 -0
  310. package/dist/storage/clean-up.mjs +72 -9
  311. package/dist/storage/counted-bucket.mjs +35 -13
  312. package/dist/storage/fetch-row-cache.d.mts +6 -0
  313. package/dist/storage/fetch-row-cache.mjs +211 -0
  314. package/dist/storage/fetch.d.mts +2 -0
  315. package/dist/storage/fetch.mjs +339 -450
  316. package/dist/storage/held-types.d.mts +0 -1
  317. package/dist/storage/host-bucket.mjs +10 -6
  318. package/dist/storage/id-mix.mjs +19 -5
  319. package/dist/storage/index-bitmaps.mjs +86 -51
  320. package/dist/storage/index-build.d.mts +2 -4
  321. package/dist/storage/index-build.mjs +324 -67
  322. package/dist/storage/index-fetch.d.mts +3 -1
  323. package/dist/storage/index-fetch.mjs +163 -83
  324. package/dist/storage/index-files.d.mts +3 -0
  325. package/dist/storage/index-files.mjs +10 -5
  326. package/dist/storage/index-graph.mjs +73 -23
  327. package/dist/storage/index-layers.mjs +55 -25
  328. package/dist/storage/index-reach.mjs +15 -22
  329. package/dist/storage/index-remap.mjs +200 -64
  330. package/dist/storage/index-whole.d.mts +7 -0
  331. package/dist/storage/index-whole.mjs +235 -0
  332. package/dist/storage/largest-files.mjs +1 -7
  333. package/dist/storage/layout.mjs +40 -1
  334. package/dist/storage/lfs-pointers.mjs +1 -6
  335. package/dist/storage/link-join.mjs +55 -16
  336. package/dist/storage/list-source.d.mts +7 -0
  337. package/dist/storage/list-source.mjs +288 -0
  338. package/dist/storage/loose.d.mts +10 -7
  339. package/dist/storage/loose.mjs +293 -82
  340. package/dist/storage/memory-budget.mjs +242 -26
  341. package/dist/storage/merge-cut.mjs +9 -6
  342. package/dist/storage/merge-fence.mjs +1 -1
  343. package/dist/storage/merge-plan.mjs +3 -2
  344. package/dist/storage/merge-row.mjs +8 -2
  345. package/dist/storage/merge-stream.mjs +164 -25
  346. package/dist/storage/merge-walk.mjs +8 -4
  347. package/dist/storage/merge-write.mjs +1 -1
  348. package/dist/storage/merge.d.mts +3 -4
  349. package/dist/storage/merge.mjs +3 -3
  350. package/dist/storage/object-rows.d.mts +4 -3
  351. package/dist/storage/object-rows.mjs +545 -84
  352. package/dist/storage/oid-table.mjs +171 -0
  353. package/dist/storage/pack-order.mjs +104 -47
  354. package/dist/storage/pack-ranges.d.mts +1 -2
  355. package/dist/storage/pack-ranges.mjs +48 -21
  356. package/dist/storage/pack-reads.d.mts +6 -3
  357. package/dist/storage/pack-reads.mjs +378 -98
  358. package/dist/storage/pack-receive.d.mts +2 -3
  359. package/dist/storage/pack-receive.mjs +22 -18
  360. package/dist/storage/packs.d.mts +2 -2
  361. package/dist/storage/packs.mjs +587 -156
  362. package/dist/storage/placed-reads.mjs +34 -17
  363. package/dist/storage/plan-columns.d.mts +4 -0
  364. package/dist/storage/plan-columns.mjs +238 -0
  365. package/dist/storage/prune-keep.mjs +134 -41
  366. package/dist/storage/prune-seen.mjs +1 -1
  367. package/dist/storage/prune-walk.mjs +203 -63
  368. package/dist/storage/prune.mjs +197 -121
  369. package/dist/storage/push-allotment.mjs +116 -25
  370. package/dist/storage/push-uploads.mjs +196 -58
  371. package/dist/storage/pushed-commits.mjs +24 -3
  372. package/dist/storage/quarantine.d.mts +3 -4
  373. package/dist/storage/range-cache.mjs +293 -41
  374. package/dist/storage/raw-ids.mjs +39 -10
  375. package/dist/storage/ready.d.mts +3 -4
  376. package/dist/storage/ready.mjs +121 -43
  377. package/dist/storage/receive-bounds.mjs +50 -13
  378. package/dist/storage/receive-cache.d.mts +7 -0
  379. package/dist/storage/receive-cache.mjs +147 -0
  380. package/dist/storage/receive-files.mjs +1 -1
  381. package/dist/storage/receive-links.mjs +1 -1
  382. package/dist/storage/receive-state.d.mts +2 -2
  383. package/dist/storage/receive-state.mjs +6 -8
  384. package/dist/storage/receive-steps.d.mts +20 -0
  385. package/dist/storage/receive-steps.mjs +298 -13
  386. package/dist/storage/repack-backlog.mjs +1 -3
  387. package/dist/storage/repack-contained.mjs +2 -2
  388. package/dist/storage/repack-job.mjs +1 -1
  389. package/dist/storage/repack.d.mts +3 -4
  390. package/dist/storage/repack.mjs +54 -9
  391. package/dist/storage/request-cache.mjs +57 -0
  392. package/dist/storage/roots.mjs +1 -24
  393. package/dist/storage/rows.d.mts +3 -3
  394. package/dist/storage/rows.mjs +2 -2
  395. package/dist/storage/runs.d.mts +2 -2
  396. package/dist/storage/runs.mjs +196 -44
  397. package/dist/storage/send-list.d.mts +1 -0
  398. package/dist/storage/send-list.mjs +112 -31
  399. package/dist/storage/single-flight.mjs +13 -7
  400. package/dist/storage/stream-whole.mjs +188 -66
  401. package/dist/storage/swap-walk.mjs +1 -1
  402. package/dist/storage/unpack.mjs +919 -199
  403. package/dist/storage/visible.mjs +112 -34
  404. package/dist/storage/walk.mjs +193 -38
  405. package/dist/storage/wants.mjs +27 -63
  406. package/dist/store/bodies.mjs +38 -0
  407. package/dist/store/call-count.d.mts +10 -14
  408. package/dist/store/call-count.mjs +58 -57
  409. package/dist/store/catalogue.d.mts +2 -2
  410. package/dist/store/catalogue.mjs +158 -36
  411. package/dist/store/crossing.mjs +1 -9
  412. package/dist/store/cursor-seal.d.mts +1 -2
  413. package/dist/store/cursor-seal.mjs +17 -7
  414. package/dist/store/door.mjs +188 -0
  415. package/dist/store/errors.d.mts +4 -5
  416. package/dist/store/errors.mjs +119 -49
  417. package/dist/store/git-store.mjs +30 -7
  418. package/dist/store/job-try.mjs +98 -40
  419. package/dist/store/list-job.mjs +32 -20
  420. package/dist/store/outbox.d.mts +2 -2
  421. package/dist/store/outbox.mjs +2 -2
  422. package/dist/store/queue-jobs.mjs +6 -12
  423. package/dist/store/records.d.mts +5 -2
  424. package/dist/store/records.mjs +5 -2
  425. package/dist/store/ref-rows.d.mts +2 -2
  426. package/dist/store/ref-rows.mjs +2 -2
  427. package/dist/store/repo-record.d.mts +2 -3
  428. package/dist/store/repo-record.mjs +34 -22
  429. package/dist/store/request-snapshot.mjs +5 -0
  430. package/dist/store/reservations.mjs +3 -3
  431. package/dist/store/scopes.mjs +11 -0
  432. package/dist/store/settle.mjs +4 -4
  433. package/dist/store/topic-jobs.mjs +5 -11
  434. package/dist/sync/bound.d.mts +3 -3
  435. package/dist/sync/bound.mjs +10 -7
  436. package/dist/sync/github.mjs +67 -69
  437. package/dist/sync/http.mjs +1 -1
  438. package/dist/sync/import.mjs +205 -57
  439. package/dist/sync/layer.d.mts +1 -1
  440. package/dist/sync/layer.mjs +6 -6
  441. package/dist/sync/lfs-batch.mjs +5 -6
  442. package/dist/sync/lfs-copy.mjs +191 -20
  443. package/dist/sync/mirror.mjs +34 -36
  444. package/dist/sync/said.mjs +17 -38
  445. package/dist/sync/step.mjs +292 -102
  446. package/dist/sync/tries.mjs +34 -15
  447. package/dist/sync.d.mts +2 -2
  448. package/dist/sync.mjs +2 -2
  449. package/dist/topics/advance.mjs +12 -13
  450. package/dist/topics/base.d.mts +15 -0
  451. package/dist/topics/base.mjs +8 -0
  452. package/dist/topics/calls.mjs +1 -1
  453. package/dist/topics/host.mjs +1 -1
  454. package/dist/topics/layer.d.mts +17 -21
  455. package/dist/topics/layer.mjs +2 -3
  456. package/dist/topics/members.mjs +4 -4
  457. package/dist/topics/public.d.mts +2 -1
  458. package/dist/topics/topic.mjs +2 -2
  459. package/package.json +5 -14
  460. package/dist/auth/helpers.mjs +0 -17
  461. package/dist/auth.d.mts +0 -5
  462. package/dist/auth.mjs +0 -5
  463. package/dist/contracts/promises.d.mts +0 -39
  464. package/dist/core/call-names.d.mts +0 -3
  465. package/dist/core/clock.mjs +0 -18
  466. package/dist/core/promise.mjs +0 -74
  467. package/dist/core/rules/commit-changes.d.mts +0 -13
  468. package/dist/effect.d.mts +0 -18
  469. package/dist/effect.mjs +0 -16
  470. package/dist/lfs/calls.mjs +0 -26
  471. package/dist/rest/api.d.mts +0 -23
  472. package/dist/rest/blobs.d.mts +0 -833
  473. package/dist/rest/commits.d.mts +0 -3543
  474. package/dist/rest/errors.d.mts +0 -2124
  475. package/dist/rest/events.d.mts +0 -426
  476. package/dist/rest/files.d.mts +0 -1342
  477. package/dist/rest/forks.d.mts +0 -2160
  478. package/dist/rest/handlers.d.mts +0 -8
  479. package/dist/rest/merges.d.mts +0 -477
  480. package/dist/rest/queue.d.mts +0 -5917
  481. package/dist/rest/refs.d.mts +0 -2988
  482. package/dist/rest/repos.d.mts +0 -2567
  483. package/dist/rest/tags.d.mts +0 -1316
  484. package/dist/rest/tokens.d.mts +0 -2614
  485. package/dist/rest/topics.d.mts +0 -2224
  486. package/dist/rest/trees.d.mts +0 -1709
  487. package/dist/rest/work.d.mts +0 -1695
  488. package/dist/server/joined.d.mts +0 -82
  489. package/dist/server/joined.mjs +0 -68
  490. package/dist/server/lifecycle.d.mts +0 -2
  491. package/dist/store/promises.d.mts +0 -11
  492. package/dist/store/promises.mjs +0 -327
@@ -1,38 +1,77 @@
1
- import { gitError } from "../contracts/result.mjs";
1
+ import { fail, gitError } from "../contracts/result.mjs";
2
2
  import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
3
+ import { hexOf } from "../protocol/bytes/hex.mjs";
3
4
  import { joinedBytes } from "../protocol/bytes/joined.mjs";
4
5
  import { nativeSha1Hasher } from "../protocol/bytes/sha1-hasher.mjs";
5
6
  import { fsckObject } from "../protocol/objects/fsck.mjs";
6
- import { objectId } from "../protocol/objects/object.mjs";
7
- import { appliedDelta } from "../protocol/packs/delta.mjs";
7
+ import { rawLinks } from "../protocol/objects/links-raw.mjs";
8
+ import { emptyTree, objectId } from "../protocol/objects/object.mjs";
9
+ import { readTagTarget } from "../protocol/objects/tag.mjs";
10
+ import { DeltaRun, appliedDelta, deltaResultSize } from "../protocol/packs/delta.mjs";
8
11
  import { PackError, PackTransportError, boundedSource, readPack } from "../protocol/packs/reader.mjs";
12
+ import { deltaPartBytes, fastPath, stagedBytes, stagedDeltaKey, stagedKey } from "./batches.mjs";
13
+ import { ChunkWriter, chunkRawBytes, chunkedMoved, chunkedOf, fitsRow, wholeObjectId } from "./chunks.mjs";
9
14
  import { checkedFilesRefused, checkedOverflow, fsckRefusal, receiveChecked } from "./fsck.mjs";
10
- import { boundaryNotInPack, linksOf, mistyped, objectMissing, segmentCut, segmentTooLarge, shallowLinks, shallowRoot, tagTargetMissing } from "./links.mjs";
11
- import { objectRow, rowValueBytes } from "./object-rows.mjs";
15
+ import { LargestFiles } from "./largest-files.mjs";
16
+ import { ReceivedPointers } from "./lfs-pointers.mjs";
17
+ import { boundaryNotInPack, linkReader, objectMissing, segmentCut, segmentTooLarge, shallowLinks, shallowRoot, tagTargetMissing, wrongType } from "./links.mjs";
18
+ import { objectOfRow, objectRow, rowValueBytes } from "./object-rows.mjs";
19
+ import "./receive-bounds.mjs";
20
+ import { rootsOf } from "./roots.mjs";
21
+ import { limits } from "@ref0/infra";
12
22
  import * as Effect from "effect/Effect";
23
+ import * as Predicate from "effect/Predicate";
13
24
  import * as Result from "effect/Result";
14
- import { limits } from "@ref0/infra";
25
+ import * as Base64 from "effect/encoding/Base64";
15
26
  // src/storage/unpack.ts
16
- /** One commit's size as JSON, as every store holds it: a push's rows and its refs share it. */
17
- const commitBytes = 8388608;
27
+ /** Internal inflated-byte cap per receive (pack entries, thin bases read once, and delta results). */
28
+ const maxInflatedBytes = 268435456;
29
+ /** The bytes of resolved base objects kept in memory by the receive's LRU. */
30
+ const baseLruBytes = 16777216;
31
+ /** Pending delta instructions held in memory before spilling to `stagedDeltas`. */
32
+ const pendingHeldMost = 25165824;
33
+ /** Maximum known serialized bytes requested in one Phase B round read call. */
34
+ const roundReadBytes = 7340032;
35
+ /** Spilled resolution rounds allowed before refusing `delta-chain-too-deep` (Git's `pack.depth` cap). */
36
+ const deltaRoundsMost = 4095;
37
+ /** Estimated JSON bytes for a base64-encoded row holding `raw` raw bytes. */
38
+ const encodedBytes = (raw) => Math.ceil(raw * 4 / 3) + 64;
39
+ /** Where the large object at `offset` puts its chunks, which a receive's batch holds once. */
40
+ const partAt = (offset) => `p${offset}`;
18
41
  /** What the reader may hold besides the entries it hands on: its inflater and buffers. */
19
42
  const readerBytes = 1048576;
20
- const tooLarge = (bytes, most) => gitError("RESOURCE_EXHAUSTED", `push takes ${bytes.toLocaleString("en-US")} bytes as rows; this server takes ${most.toLocaleString("en-US")}`, {
43
+ const fmtBytes = (bytes) => bytes.toLocaleString("en-US");
44
+ const packBucketHint = "Use Objects.layer() storage, which keeps a push's objects in the bucket";
45
+ const largeBucketHint = "Use Objects.layer() storage, which keeps a large object in the bucket";
46
+ const tooLarge = (bytes, most) => gitError("RESOURCE_EXHAUSTED", `push takes ${fmtBytes(bytes)} bytes; this server takes ${fmtBytes(most)}`, {
21
47
  hint: "Push fewer objects at a time",
22
- hostHint: "Use Objects.layer() storage, which keeps a push's objects in the bucket",
48
+ hostHint: packBucketHint,
23
49
  context: { reason: "too-large" }
24
50
  });
25
- /** A push whose objects, resolved whole, pass a commit before their rows are made: as `tooLarge`. */
26
- const resolvedTooLarge = (bytes, most) => gitError("RESOURCE_EXHAUSTED", `push's objects take more than ${bytes.toLocaleString("en-US")} bytes whole; this server takes ${most.toLocaleString("en-US")}`, {
27
- hint: "Push fewer objects at a time",
28
- hostHint: "Use Objects.layer() storage, which keeps a push's objects in the bucket",
29
- context: { reason: "too-large" }
51
+ /** A push whose spilled pending deltas need more than `most` resolution rounds. */
52
+ const deltaChainTooDeep = (most) => gitError("RESOURCE_EXHAUSTED", `push's delta chain needs more than ${fmtBytes(most)} resolution rounds`, {
53
+ hint: "Repack with a lower pack.depth and push again",
54
+ hostHint: packBucketHint,
55
+ context: {
56
+ reason: "delta-chain-too-deep",
57
+ most
58
+ }
30
59
  });
31
60
  /** An object whose row passes one row's 1 MiB: `RESOURCE_EXHAUSTED`, reason `object-too-large`. */
32
- const rowTooLarge = (oid, bytes) => gitError("RESOURCE_EXHAUSTED", `object ${oid} takes ${bytes.toLocaleString("en-US")} bytes as a row; one row holds ${limits.valueBytes.toLocaleString("en-US")}`, {
33
- hostHint: "Use Objects.layer() storage, which keeps a large object in the bucket",
61
+ const rowTooLarge = (oid, bytes) => gitError("RESOURCE_EXHAUSTED", `object ${oid} takes ${fmtBytes(bytes)} bytes as a row; one row holds ${fmtBytes(limits.valueBytes)}`, {
62
+ hostHint: largeBucketHint,
34
63
  context: { reason: "object-too-large" }
35
64
  });
65
+ /** An object past `most`, the bytes one object takes: `RESOURCE_EXHAUSTED`, reason `object-too-large`. */
66
+ const fileTooLarge = (bytes, most) => gitError("RESOURCE_EXHAUSTED", `push has an object of ${fmtBytes(bytes)} bytes; this server takes ${fmtBytes(most)} per object`, {
67
+ hint: objectPastHint,
68
+ hostHint: largeBucketHint,
69
+ context: { reason: "object-too-large" }
70
+ });
71
+ /** A pack whose header counts more objects than its push declared or its unpack cap allows. */
72
+ const pastDeclared = (count) => gitError("INVALID_ARGUMENT", `The pack's header counts ${count} objects, past what its push said`, { hint: "Push again" });
73
+ /** A pack holding an object twice, refused as Git's receive with fsck refuses it, by `index-pack --strict`. */
74
+ const twiceInPack = (oid) => gitError("INVALID_ARGUMENT", `The pack is malformed: the same object ${oid} appears twice in the pack`, { hint: "Push again, with each object once" });
36
75
  /** An `OFS_DELTA` entry where a storage takes `REF_DELTA` only, the same at any size of push. */
37
76
  const ofsRefused = /* @__PURE__ */ gitError("INVALID_ARGUMENT", "The pack has an OFS_DELTA entry", {
38
77
  hint: "This server takes REF_DELTA only, as its capabilities say: push with a client that doesn't send ofs-delta",
@@ -54,221 +93,902 @@ const readFailure = (error) => {
54
93
  });
55
94
  return error;
56
95
  };
96
+ /** Bounded byte-size LRU cache of resolved whole objects used as delta bases. */
97
+ var BaseLru = class {
98
+ #entries = /* @__PURE__ */ new Map();
99
+ #limit;
100
+ #used = 0;
101
+ constructor(limit) {
102
+ this.#limit = limit;
103
+ }
104
+ has(oid) {
105
+ return this.#entries.has(oid);
106
+ }
107
+ get(oid) {
108
+ const got = this.#entries.get(oid);
109
+ if (got !== void 0) {
110
+ this.#entries.delete(oid);
111
+ this.#entries.set(oid, got);
112
+ }
113
+ return got;
114
+ }
115
+ set(oid, object) {
116
+ const size = object.bytes.byteLength;
117
+ if (size > this.#limit) return;
118
+ const existing = this.#entries.get(oid);
119
+ if (existing !== void 0) {
120
+ this.#used -= existing.bytes.byteLength;
121
+ this.#entries.delete(oid);
122
+ }
123
+ this.#entries.set(oid, object);
124
+ this.#used += size;
125
+ for (const [evictedOid, oldest] of this.#entries) {
126
+ if (this.#used <= this.#limit) break;
127
+ this.#entries.delete(evictedOid);
128
+ this.#used -= oldest.bytes.byteLength;
129
+ }
130
+ }
131
+ clear() {
132
+ this.#entries.clear();
133
+ this.#used = 0;
134
+ }
135
+ };
136
+ const stagedLoss = (id) => fail("DATA_LOSS", `Staged row '${id}' is missing`);
137
+ /** Decodes one `stagedDeltas` row `{ data: base64 }` back to raw delta instructions. */
138
+ const decodeDeltaPart = (row, id) => {
139
+ const value = row?.value;
140
+ const decoded = Predicate.isObject(value) && "data" in value && Predicate.isString(value.data) ? Base64.decode(value.data) : void 0;
141
+ return decoded !== void 0 && Result.isSuccess(decoded) ? Effect.succeed(decoded.success) : stagedLoss(id);
142
+ };
57
143
  /**
58
- * Every entry of the pack, read whole, within `most` inflated bytes in all; a pack whose header
59
- * counts more than `objects` entries is refused before its first.
144
+ * The links of a commit or a tag, from its first lines alone, never its message: a commit's tree
145
+ * and parents by `rawLinks`, which reads what `linksOf` does of any object fsck passes
146
+ * (`receive-fsck.git.test.ts`), and a tag's object by `readTagTarget`, from its first two lines and
147
+ * the third's first byte. A blob names none.
60
148
  */
61
- const readEntries = /* @__PURE__ */ Effect.fnUntraced(function* (input, most) {
62
- const entries = [];
63
- let current;
149
+ const headLinks = (object) => {
150
+ const malformed = (message) => Result.fail(gitError("INVALID_ARGUMENT", `The ${object.type} ${object.oid} is malformed: ${message}`));
151
+ if (object.type === "tag") {
152
+ const first = object.bytes.indexOf(10);
153
+ const second = first < 0 ? -1 : object.bytes.indexOf(10, first + 1);
154
+ const start = second < 0 ? object.bytes : object.bytes.subarray(0, second + 2);
155
+ const target = readTagTarget(start);
156
+ if (Result.isFailure(target)) return malformed(target.failure.message);
157
+ return Result.succeed([{
158
+ oid: target.success.object,
159
+ type: target.success.type
160
+ }]);
161
+ }
162
+ const oids = [];
163
+ const fault = rawLinks(object.type, object.bytes, (bytes, at) => oids.push(hexOf(bytes.subarray(at, at + 20))));
164
+ if (fault !== void 0) return malformed(fault);
165
+ return Result.succeed(oids.map((oid, at) => ({
166
+ oid,
167
+ type: at === 0 ? "tree" : "commit"
168
+ })));
169
+ };
170
+ /**
171
+ * A received pack unpacked in a streaming pass (Phase A) plus bounded delta resolution (Phase B):
172
+ * - Wire bytes are counted before inflation against `limits.bytes`.
173
+ * - Inflated bytes (pack entries, thin bases read once, and delta results) are counted against
174
+ * `maxInflatedBytes` (256 MiB); delta result sizes are checked before allocation.
175
+ * - Whole objects and ready deltas are hashed, fsck'd, and streamed to the single `BatchStager`
176
+ * once the push passes `fastPath` (keeping inline pushes under `fastPath` batch-free).
177
+ * - Pending deltas stay in memory up to `pendingHeld` (24 MiB) and spill past it to `stagedDeltas`
178
+ * through the same `BatchStager`.
179
+ * - Phase B resolves in-memory subtrees with zero calls, streams thin bases via `eachHeld`, and
180
+ * resolves spilled deltas in rounds of <= 7 MiB with OFS descendant prefetch, capped at
181
+ * `deltaRoundsMost` (4,095) rounds before refusing `delta-chain-too-deep`.
182
+ */
183
+ const unpackObjects = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
184
+ const { receive, limits: limits$1, large, staging, memory } = input;
185
+ if (receive.objects > limits$1.objects) return yield* Effect.fail(input.tooMany(receive.objects));
186
+ const past = segmentTooLarge(receive);
187
+ if (past !== void 0) return yield* Effect.fail(past);
188
+ const inflatedCap = input.inflatedBytes ?? 268435456;
189
+ const pendingCap = input.pendingHeld ?? 25165824;
190
+ const roundCap = input.roundBytes ?? 7340032;
191
+ const inlineBytesCap = input.stageBytes ?? fastPath.bytes;
192
+ const roundsCap = input.roundsMost ?? 4095;
193
+ const lru = memory?.lru ?? new BaseLru(input.lruBytes ?? 16777216);
194
+ const growMem = (bytes) => memory === void 0 ? Effect.void : memory.grow(bytes);
195
+ const shrinkMem = (bytes) => memory?.shrink(bytes);
196
+ const pageCap = () => memory?.page(roundCap) ?? roundCap;
197
+ const stagedRowKey = (oid) => stagedKey(activeStager.opened.batch, oid);
198
+ const eachExternal = (oids, take) => input.eachHeld !== void 0 ? input.eachHeld(oids, take) : Effect.flatMap(input.held(oids), (m) => Effect.forEach(m.values(), take, { discard: true }));
199
+ let inflated = 0;
200
+ const chargeInflated = (bytes) => {
201
+ inflated += bytes;
202
+ return inflated > inflatedCap ? Effect.fail(tooLarge(inflated, inflatedCap)) : Effect.void;
203
+ };
204
+ const headers = /* @__PURE__ */ new Map();
205
+ const offsetToOid = /* @__PURE__ */ new Map();
206
+ const chunked = /* @__PURE__ */ new Map();
207
+ const commits = [];
208
+ const headEntries = [];
209
+ const packTrees = [];
210
+ const largest = new LargestFiles();
211
+ const pointers = new ReceivedPointers();
212
+ const checked = receiveChecked();
213
+ let inlineRows = [];
214
+ const inlineByOid = /* @__PURE__ */ new Map();
215
+ let inlineStagedBytes = 0;
216
+ let inlineHeld = 0;
217
+ let activeStager;
218
+ const moved = {
219
+ objects: 0,
220
+ bytes: 0
221
+ };
222
+ const ensureStager = Effect.fnUntraced(function* () {
223
+ if (activeStager !== void 0) return activeStager;
224
+ if (staging === void 0) return yield* Effect.fail(tooLarge(inlineStagedBytes, fastPath.bytes));
225
+ const stager = yield* staging.stager();
226
+ activeStager = stager;
227
+ shrinkMem(inlineHeld);
228
+ inlineHeld = 0;
229
+ for (const row of inlineRows) yield* stager.push(row);
230
+ inlineRows = [];
231
+ inlineByOid.clear();
232
+ inlineStagedBytes = 0;
233
+ return stager;
234
+ });
235
+ const emitChunkedManifest = (item) => {
236
+ const row = large.row(item);
237
+ const counted = chunkedMoved(chunkedOf(row.value));
238
+ moved.objects += counted.objects;
239
+ moved.bytes += counted.bytes;
240
+ return Effect.flatMap(ensureStager(), (stager) => stager.push(row));
241
+ };
242
+ const waitingByOffset = /* @__PURE__ */ new Map();
243
+ const waitingByOid = /* @__PURE__ */ new Map();
244
+ let nextSeq = 0;
245
+ let pendingBytes = 0;
246
+ let unresolved = 0;
247
+ const enqueuePending = (delta) => {
248
+ unresolved += 1;
249
+ const put = (map, key) => {
250
+ const list = map.get(key);
251
+ if (list === void 0) map.set(key, [delta]);
252
+ else list.push(delta);
253
+ };
254
+ if (delta.base.kind === "offset") put(waitingByOffset, delta.base.offset);
255
+ else put(waitingByOid, delta.base.oid);
256
+ };
257
+ /** Looks up an already-resolved object in memory (LRU, inline buffer, or unflushed stager buffer). */
258
+ const readInMemory = (oid) => {
259
+ const cached = lru.get(oid) ?? inlineByOid.get(oid);
260
+ if (cached !== void 0) return Effect.succeed(cached);
261
+ const buffered = activeStager?.bufferedRow(oid);
262
+ return buffered !== void 0 && chunkedOf(buffered.value) === void 0 ? objectOfRow(buffered) : Effect.succeed(void 0);
263
+ };
264
+ const readChunked = (item) => {
265
+ const takes = large;
266
+ lru.clear();
267
+ return Effect.flatMap(takes.hold(item.size), () => Effect.map(takes.staged(item), (bytes) => ({
268
+ oid: item.oid,
269
+ type: item.type,
270
+ bytes
271
+ })));
272
+ };
273
+ const readLocal = (oid) => Effect.flatMap(readInMemory(oid), (inMem) => {
274
+ if (inMem !== void 0) return Effect.succeed(inMem);
275
+ const largeObj = chunked.get(oid);
276
+ return largeObj !== void 0 && large !== void 0 ? readChunked(largeObj) : Effect.succeed(void 0);
277
+ });
278
+ /** Reads an already-resolved own object from memory, `large.staged`, or flushed `stagedObjects`. */
279
+ const readOwnObject = (oid) => Effect.flatMap(readLocal(oid), (local) => local !== void 0 || activeStager === void 0 || staging === void 0 || !headers.has(oid) ? Effect.succeed(local) : Effect.flatMap(staging.readStaged([stagedRowKey(oid)]), ([row]) => row === void 0 ? Effect.succeed(void 0) : objectOfRow(row)));
280
+ const recordWhole = Effect.fnUntraced(function* (offset, object, isChunkedNonBlob) {
281
+ const { oid, type, bytes } = object;
282
+ if (headers.has(oid)) return yield* Effect.fail(twiceInPack(oid));
283
+ const fault = fsckObject(object, checked);
284
+ if (fault !== void 0) return yield* Effect.fail(fsckRefusal(oid, fault));
285
+ const overflow = checkedOverflow(checked);
286
+ if (overflow !== void 0) return yield* Effect.fail(overflow);
287
+ const size = bytes.byteLength;
288
+ headers.set(oid, {
289
+ type,
290
+ size
291
+ });
292
+ offsetToOid.set(offset, oid);
293
+ if (type === "blob") {
294
+ largest.add(oid, size);
295
+ yield* pointers.add(oid, bytes);
296
+ } else if (type === "tree") packTrees.push(oid);
297
+ else {
298
+ const links = yield* Effect.fromResult(headLinks(object));
299
+ headEntries.push({
300
+ oid,
301
+ type,
302
+ links
303
+ });
304
+ if (type === "commit") commits.push({
305
+ oid,
306
+ parents: links.slice(1).map((link) => link.oid)
307
+ });
308
+ }
309
+ if (isChunkedNonBlob) {
310
+ const part = partAt(offset);
311
+ const writer = yield* ChunkWriter.make(type, size, part, large.stage);
312
+ yield* writer.write(bytes);
313
+ yield* writer.end();
314
+ const item = {
315
+ oid,
316
+ type,
317
+ size,
318
+ part
319
+ };
320
+ chunked.set(oid, item);
321
+ yield* emitChunkedManifest(item);
322
+ } else {
323
+ const row = objectRow(object);
324
+ const valueBytes = rowValueBytes(row.value);
325
+ if (valueBytes > limits.valueBytes) return yield* Effect.fail(rowTooLarge(oid, valueBytes));
326
+ moved.objects += 1;
327
+ moved.bytes += valueBytes;
328
+ if (activeStager !== void 0) yield* activeStager.push(row);
329
+ else {
330
+ const rowSize = stagedBytes(row);
331
+ const inlineDelta = rowSize + size;
332
+ if (staging !== void 0 && (inlineRows.length + 1 > fastPath.rows || inlineStagedBytes + rowSize > inlineBytesCap || memory?.tryGrow(inlineDelta) === false)) yield* (yield* ensureStager()).push(row);
333
+ else {
334
+ if (staging === void 0) yield* growMem(inlineDelta);
335
+ inlineRows.push(row);
336
+ inlineByOid.set(oid, object);
337
+ inlineStagedBytes += rowSize;
338
+ inlineHeld += inlineDelta;
339
+ }
340
+ }
341
+ }
342
+ lru.set(oid, object);
343
+ return {
344
+ oid,
345
+ offset,
346
+ object
347
+ };
348
+ });
349
+ const recordChunkedBlob = (offset, item) => {
350
+ const { oid, type, size } = item;
351
+ if (headers.has(oid)) return Effect.fail(twiceInPack(oid));
352
+ headers.set(oid, {
353
+ type,
354
+ size
355
+ });
356
+ offsetToOid.set(offset, oid);
357
+ chunked.set(oid, item);
358
+ largest.add(oid, size);
359
+ return Effect.as(emitChunkedManifest(item), {
360
+ oid,
361
+ offset,
362
+ item
363
+ });
364
+ };
365
+ const resolveDelta = Effect.fnUntraced(function* (base, offset, instructions, shrinkBytes) {
366
+ const malformed = (message) => malformedPack(`the delta at ${offset}: ${message}`);
367
+ const type = base.type;
368
+ const size = deltaResultSize(instructions);
369
+ if (size !== void 0) {
370
+ if (large !== void 0 && size > large.fileBytes) return yield* Effect.fail(fileTooLarge(size, large.fileBytes));
371
+ if (inflated + size > inflatedCap) return yield* Effect.fail(tooLarge(inflated + size, inflatedCap));
372
+ if (large !== void 0 && !fitsRow(type, size)) {
373
+ yield* chargeInflated(size);
374
+ if (type === "blob") {
375
+ const part = partAt(offset);
376
+ const writer = yield* ChunkWriter.make("blob", size, part, large.stage);
377
+ let waitingBytes = [];
378
+ let waitingSize = 0;
379
+ let given = false;
380
+ const run = new DeltaRun({
381
+ instructions: () => given ? void 0 : (given = true, instructions),
382
+ baseSize: base.bytes.byteLength,
383
+ base: (at, length) => base.bytes.subarray(at, at + length)
384
+ }, {
385
+ size: () => {},
386
+ write: (bytes) => {
387
+ waitingBytes.push(bytes.slice());
388
+ waitingSize += bytes.byteLength;
389
+ return waitingSize >= chunkRawBytes;
390
+ }
391
+ }, large.fileBytes);
392
+ for (;;) {
393
+ const ran = run.run();
394
+ for (const bytes of waitingBytes) yield* writer.write(bytes);
395
+ waitingBytes = [];
396
+ waitingSize = 0;
397
+ if (ran === "paused") continue;
398
+ if (Result.isFailure(ran)) return yield* Effect.fail(malformed(ran.failure.message));
399
+ const oid = yield* writer.end();
400
+ shrinkMem(shrinkBytes);
401
+ return yield* recordChunkedBlob(offset, {
402
+ oid,
403
+ type,
404
+ size,
405
+ part
406
+ });
407
+ }
408
+ }
409
+ lru.clear();
410
+ yield* large.hold(size);
411
+ const whole = appliedDelta(base.bytes, instructions, large.fileBytes);
412
+ if (Result.isFailure(whole)) return yield* Effect.fail(malformed(whole.failure.message));
413
+ const bytes = whole.success;
414
+ const oid = yield* wholeObjectId(type, bytes);
415
+ shrinkMem(shrinkBytes);
416
+ return yield* recordWhole(offset, {
417
+ oid,
418
+ type,
419
+ bytes
420
+ }, true);
421
+ }
422
+ }
423
+ const remaining = Math.max(0, inflatedCap - inflated);
424
+ const maxResult = large === void 0 ? Math.min(remaining, limits.valueBytes) : remaining;
425
+ const result = appliedDelta(base.bytes, instructions, maxResult);
426
+ if (Result.isFailure(result)) {
427
+ if (result.failure.fault === "too big" && size !== void 0) {
428
+ if (large === void 0 && !fitsRow(type, size)) return yield* Effect.fail(rowTooLarge(emptyTree, size));
429
+ return yield* Effect.fail(tooLarge(inflated + size, inflatedCap));
430
+ }
431
+ return yield* Effect.fail(malformed(result.failure.message));
432
+ }
433
+ const bytes = result.success;
434
+ yield* chargeInflated(bytes.byteLength);
435
+ const oid = yield* objectId({
436
+ type,
437
+ bytes
438
+ });
439
+ if (large === void 0 && !fitsRow(type, bytes.byteLength)) return yield* Effect.fail(rowTooLarge(oid, rowValueBytes(objectRow({
440
+ oid,
441
+ type,
442
+ bytes
443
+ }).value)));
444
+ shrinkMem(shrinkBytes);
445
+ return yield* recordWhole(offset, {
446
+ oid,
447
+ type,
448
+ bytes
449
+ }, false);
450
+ });
451
+ const readyForSpilled = /* @__PURE__ */ new Set();
452
+ const readyOffsetsForSpilled = /* @__PURE__ */ new Set();
453
+ /** Takes in-memory pending children of `base`, leaving any spilled children in the waiting maps. */
454
+ const takeInMemoryChildren = (oid, offset) => {
455
+ const taken = [];
456
+ const pull = (map, key, ready) => {
457
+ const list = map.get(key);
458
+ if (list === void 0) return;
459
+ const kept = [];
460
+ for (const delta of list) if (delta.data !== void 0) {
461
+ pendingBytes -= delta.data.byteLength;
462
+ unresolved -= 1;
463
+ taken.push(delta);
464
+ } else kept.push(delta);
465
+ if (kept.length === 0) map.delete(key);
466
+ else {
467
+ map.set(key, kept);
468
+ ready.add(key);
469
+ }
470
+ };
471
+ pull(waitingByOid, oid, readyForSpilled);
472
+ if (offset !== void 0) pull(waitingByOffset, offset, readyOffsetsForSpilled);
473
+ return taken;
474
+ };
475
+ const baseOfSeed = (seed) => "object" in seed ? Effect.succeed(seed.object) : readChunked(seed.item);
476
+ /** Zero-call iterative DFS over in-memory pending descendants, materializing one sibling at a time. */
477
+ const resolveInMemoryTree = Effect.fnUntraced(function* (seed) {
478
+ const first = takeInMemoryChildren(seed.oid, seed.offset);
479
+ if (first.length === 0) return;
480
+ const stack = [{
481
+ oid: seed.oid,
482
+ base: yield* baseOfSeed(seed),
483
+ list: first,
484
+ at: 0
485
+ }];
486
+ while (stack.length > 0) {
487
+ const frame = stack[stack.length - 1];
488
+ if (frame.at >= frame.list.length) {
489
+ stack.pop();
490
+ continue;
491
+ }
492
+ const base = frame.base ?? (yield* readOwnObject(frame.oid));
493
+ if (base === void 0) {
494
+ stack.pop();
495
+ continue;
496
+ }
497
+ frame.base = base;
498
+ const delta = frame.list[frame.at++];
499
+ const data = delta.data;
500
+ const recorded = yield* resolveDelta(base, delta.offset, data, data.byteLength);
501
+ const grandkids = takeInMemoryChildren(recorded.oid, recorded.offset);
502
+ if (grandkids.length === 0) continue;
503
+ if (frame.at >= frame.list.length) stack.pop();
504
+ else if (headers.has(frame.oid)) frame.base = void 0;
505
+ stack.push({
506
+ oid: recorded.oid,
507
+ base: yield* baseOfSeed(recorded),
508
+ list: grandkids,
509
+ at: 0
510
+ });
511
+ }
512
+ });
513
+ const walk = (seed) => Effect.flatMap(seed, resolveInMemoryTree);
64
514
  let pieces = [];
65
- let held = 0;
515
+ let chunkWriter;
516
+ let wholeBuf;
517
+ let spill;
518
+ let directBase;
519
+ const resetEntry = () => {
520
+ pieces = [];
521
+ chunkWriter = void 0;
522
+ wholeBuf = void 0;
523
+ spill = void 0;
524
+ directBase = void 0;
525
+ };
526
+ const flushSpillPart = Effect.fnUntraced(function* (active, force) {
527
+ while (active.bytes >= 768e3 || force && active.bytes > 0) {
528
+ const joined = joinedBytes(active.buf);
529
+ const take = Math.min(joined.byteLength, deltaPartBytes);
530
+ const rest = joined.subarray(take);
531
+ yield* (yield* ensureStager()).pushDelta(active.seq, active.parts.length, joined.subarray(0, take));
532
+ active.parts.push(take);
533
+ active.buf = rest.byteLength > 0 ? [rest] : [];
534
+ active.bytes = rest.byteLength;
535
+ }
536
+ });
537
+ memory?.free?.(ensureStager, [waitingByOid, waitingByOffset], (bytes) => {
538
+ pendingBytes -= bytes;
539
+ }, () => inlineHeld > 0);
66
540
  const sink = {
67
- begin: ({ count }) => count > input.limits.objects ? Effect.fail(input.tooMany(count)) : Effect.void,
541
+ begin: ({ count }) => count > limits$1.objects ? Effect.fail(input.tooMany(count)) : count > receive.objects ? Effect.fail(pastDeclared(count)) : Effect.void,
68
542
  entry: (entry) => {
69
543
  if (entry.kind === "ofs" && input.offsetDeltas === "refuse") return Effect.fail(ofsRefused);
70
- current = entry;
71
- pieces = [];
544
+ resetEntry();
545
+ if (entry.base !== void 0) {
546
+ if (large === void 0 && entry.size > 7340032) return Effect.fail(rowTooLarge(emptyTree, entry.size));
547
+ const base = entry.base;
548
+ const baseOid = base.kind === "offset" ? offsetToOid.get(base.offset) : base.oid;
549
+ return Effect.flatMap(baseOid === void 0 ? Effect.succeed(void 0) : readInMemory(baseOid), (inMem) => {
550
+ if (inMem !== void 0) {
551
+ directBase = inMem;
552
+ return growMem(entry.size);
553
+ }
554
+ const canHold = pendingBytes + entry.size <= pendingCap;
555
+ return Effect.map(memory === void 0 ? Effect.succeed(canHold) : memory.delta(entry.size, canHold, Math.min(entry.size, deltaPartBytes)), (hold) => {
556
+ if (!hold) spill = {
557
+ seq: nextSeq++,
558
+ offset: entry.offset,
559
+ base,
560
+ size: entry.size,
561
+ parts: [],
562
+ buf: [],
563
+ bytes: 0
564
+ };
565
+ });
566
+ });
567
+ }
568
+ const type = entry.kind;
569
+ if (large !== void 0) {
570
+ if (entry.size > large.fileBytes) return Effect.fail(fileTooLarge(entry.size, large.fileBytes));
571
+ if (!fitsRow(type, entry.size)) {
572
+ if (inflated + entry.size > inflatedCap) return Effect.fail(tooLarge(inflated + entry.size, inflatedCap));
573
+ if (type === "blob") return Effect.map(ChunkWriter.make(type, entry.size, partAt(entry.offset), large.stage), (writer) => {
574
+ chunkWriter = writer;
575
+ });
576
+ lru.clear();
577
+ return Effect.map(large.hold(entry.size), () => {
578
+ wholeBuf = {
579
+ bytes: new Uint8Array(entry.size),
580
+ at: 0
581
+ };
582
+ });
583
+ }
584
+ } else if (!fitsRow(type, entry.size)) return Effect.fail(rowTooLarge(emptyTree, entry.size));
72
585
  },
73
586
  data: (bytes) => {
74
- held += bytes.byteLength;
75
- if (held > most) return Effect.fail(tooLarge(held, most));
587
+ const over = chargeInflated(bytes.byteLength);
588
+ if (inflated > inflatedCap) return over;
589
+ if (chunkWriter !== void 0) return chunkWriter.write(bytes);
590
+ if (wholeBuf !== void 0) {
591
+ if (wholeBuf.at + bytes.byteLength > wholeBuf.bytes.byteLength) return Effect.fail(malformedPack("an object passes its size"));
592
+ wholeBuf.bytes.set(bytes, wholeBuf.at);
593
+ wholeBuf.at += bytes.byteLength;
594
+ return Effect.void;
595
+ }
596
+ if (spill !== void 0) {
597
+ spill.buf.push(bytes.slice());
598
+ spill.bytes += bytes.byteLength;
599
+ return spill.bytes >= 768e3 ? flushSpillPart(spill, false) : Effect.void;
600
+ }
76
601
  pieces.push(bytes.slice());
77
602
  return Effect.void;
78
603
  },
79
- entryEnd: () => Effect.sync(() => {
80
- if (current !== void 0) entries.push({
81
- entry: current,
82
- data: joinedBytes(pieces)
604
+ entryEnd: Effect.fnUntraced(function* (entry) {
605
+ const streamed = chunkWriter;
606
+ const body = wholeBuf;
607
+ const spilling = spill;
608
+ const baseReady = directBase;
609
+ const entryPieces = pieces;
610
+ resetEntry();
611
+ if (streamed !== void 0) {
612
+ const oid = yield* streamed.end();
613
+ return yield* walk(recordChunkedBlob(entry.offset, {
614
+ oid,
615
+ type: streamed.type,
616
+ size: streamed.size,
617
+ part: streamed.part
618
+ }));
619
+ }
620
+ if (body !== void 0) {
621
+ if (body.at !== body.bytes.byteLength) return yield* Effect.fail(malformedPack(`an object of ${body.bytes.byteLength} bytes ended at ${body.at}`));
622
+ const type = entry.kind;
623
+ const oid = yield* wholeObjectId(type, body.bytes);
624
+ return yield* walk(recordWhole(entry.offset, {
625
+ oid,
626
+ type,
627
+ bytes: body.bytes
628
+ }, true));
629
+ }
630
+ if (spilling !== void 0) {
631
+ yield* flushSpillPart(spilling, true);
632
+ shrinkMem(Math.min(spilling.size, deltaPartBytes));
633
+ enqueuePending(spilling);
634
+ if (spilling.base.kind === "offset") {
635
+ if (offsetToOid.has(spilling.base.offset)) readyOffsetsForSpilled.add(spilling.base.offset);
636
+ } else if (headers.has(spilling.base.oid)) readyForSpilled.add(spilling.base.oid);
637
+ return;
638
+ }
639
+ if (entry.base !== void 0) {
640
+ const data = joinedBytes(entryPieces);
641
+ if (baseReady !== void 0) return yield* walk(resolveDelta(baseReady, entry.offset, data, data.byteLength));
642
+ pendingBytes += data.byteLength;
643
+ enqueuePending({
644
+ seq: nextSeq++,
645
+ offset: entry.offset,
646
+ base: entry.base,
647
+ size: data.byteLength,
648
+ data
649
+ });
650
+ return;
651
+ }
652
+ const type = entry.kind;
653
+ const bytes = joinedBytes(entryPieces);
654
+ const oid = yield* objectId({
655
+ type,
656
+ bytes
83
657
  });
84
- current = void 0;
85
- pieces = [];
658
+ return yield* walk(recordWhole(entry.offset, {
659
+ oid,
660
+ type,
661
+ bytes
662
+ }, false));
86
663
  })
87
664
  };
88
665
  const meter = new BufferMeter(readerBytes);
89
- const source = boundedSource(input.receive.pack, /* @__PURE__ */ new Uint8Array(0), meter);
90
- return {
91
- entries,
92
- bytes: (yield* readPack(source, nativeSha1Hasher(), sink, {
93
- objectBytes: most,
94
- deltaBytes: most
95
- }, meter).pipe(Effect.mapError(readFailure), Effect.ensuring(source.cancel))).bytes
96
- };
97
- });
98
- /** Where a delta waits: its base's offset in the pack, or its base's ID. */
99
- const waitKey = (entry) => {
100
- if (entry.base === void 0) return void 0;
101
- return entry.base.kind === "offset" ? `o:${entry.base.offset}` : `r:${entry.base.oid}`;
102
- };
103
- /**
104
- * Each entry as a whole object: a whole entry hashed, a delta applied to its base, an earlier
105
- * entry by offset, one by ID in the pack, or one the repo holds. A delta left without its base
106
- * refuses the pack, and so do objects past `most` bytes in all, as each delta's is made.
107
- */
108
- const resolve = /* @__PURE__ */ Effect.fnUntraced(function* (input, entries, most) {
109
- const objects = /* @__PURE__ */ new Map();
110
- const waiting = /* @__PURE__ */ new Map();
111
- const ready = [];
112
- let unresolved = 0;
113
- let made = 0;
114
- for (const each of entries) {
115
- const key = waitKey(each.entry);
116
- if (key === void 0) {
117
- const type = each.entry.kind;
118
- const bytes = new Uint8Array(each.data);
119
- made += bytes.byteLength;
120
- ready.push({
121
- offset: each.entry.offset,
122
- object: {
123
- oid: yield* objectId({
124
- type,
125
- bytes
126
- }),
127
- type,
128
- bytes
666
+ const rawSource = boundedSource(receive.pack, /* @__PURE__ */ new Uint8Array(0), meter);
667
+ const wireCap = receive.objects === 0 ? Math.max(limits$1.bytes, 32) : limits$1.bytes;
668
+ let wireBytes = 0;
669
+ const objectBytes = large === void 0 ? inflatedCap : Math.max(inflatedCap, large.fileBytes);
670
+ const packRead = yield* readPack({ read: Effect.flatMap(rawSource.read, (chunk) => {
671
+ if (chunk === void 0) return Effect.succeed(void 0);
672
+ const total = wireBytes += chunk.byteLength;
673
+ return total > wireCap ? Effect.fail(tooLarge(total, wireCap)) : Effect.succeed(chunk);
674
+ }) }, nativeSha1Hasher(), sink, {
675
+ objectBytes,
676
+ deltaBytes: inflatedCap
677
+ }, meter).pipe(Effect.mapError(readFailure), Effect.ensuring(rawSource.cancel));
678
+ const externalBases = /* @__PURE__ */ new Map();
679
+ const baseOf = (item) => item.oid ?? offsetToOid.get(item.offset);
680
+ let rounds = 0;
681
+ const drainSpilledRounds = Effect.fnUntraced(function* () {
682
+ while (readyForSpilled.size > 0 || readyOffsetsForSpilled.size > 0) {
683
+ const wave = [];
684
+ let needsSpillRound = false;
685
+ const take = (delta, item) => {
686
+ if (delta.data !== void 0) pendingBytes -= delta.data.byteLength;
687
+ else needsSpillRound = true;
688
+ unresolved -= 1;
689
+ wave.push(item);
690
+ };
691
+ const drainReady = (ready, map, oidOf) => {
692
+ for (const key of ready) {
693
+ const list = map.get(key);
694
+ const baseOid = oidOf(key);
695
+ if (list === void 0 || baseOid === void 0) continue;
696
+ map.delete(key);
697
+ const start = wave.length;
698
+ for (const delta of list) take(delta, {
699
+ delta,
700
+ oid: baseOid
701
+ });
702
+ for (let i = start; i < wave.length; i++) {
703
+ const parent = wave[i].delta;
704
+ const kids = waitingByOffset.get(parent.offset);
705
+ if (kids === void 0) continue;
706
+ waitingByOffset.delete(parent.offset);
707
+ for (const kid of kids) take(kid, {
708
+ delta: kid,
709
+ offset: parent.offset
710
+ });
711
+ }
129
712
  }
130
- });
131
- } else {
132
- waiting.set(key, [...waiting.get(key) ?? [], each]);
133
- unresolved += 1;
134
- }
135
- }
136
- const settle = Effect.fnUntraced(function* () {
137
- for (let next = ready.pop(); next !== void 0; next = ready.pop()) {
138
- const { offset, object } = next;
139
- if (offset !== void 0) objects.set(object.oid, object);
140
- const keys = offset === void 0 ? [`r:${object.oid}`] : [`o:${offset}`, `r:${object.oid}`];
141
- for (const key of keys) {
142
- for (const delta of waiting.get(key) ?? []) {
143
- const applied = appliedDelta(object.bytes, delta.data, most);
144
- if (Result.isFailure(applied)) return yield* Effect.fail(malformedPack(`the delta at ${delta.entry.offset}: ${applied.failure.message}`));
145
- const bytes = applied.success;
146
- made += bytes.byteLength;
147
- if (made > most) return yield* Effect.fail(resolvedTooLarge(made, most));
148
- const type = object.type;
149
- const whole = new Uint8Array(bytes);
150
- ready.push({
151
- offset: delta.entry.offset,
152
- object: {
153
- oid: yield* objectId({
154
- type,
155
- bytes: whole
156
- }),
157
- type,
158
- bytes: whole
159
- }
713
+ ready.clear();
714
+ };
715
+ drainReady(readyForSpilled, waitingByOid, (oid) => oid);
716
+ drainReady(readyOffsetsForSpilled, waitingByOffset, (offset) => offsetToOid.get(offset));
717
+ if (wave.length === 0) break;
718
+ if (needsSpillRound) {
719
+ rounds += 1;
720
+ if (rounds > roundsCap) return yield* Effect.fail(deltaChainTooDeep(roundsCap));
721
+ }
722
+ for (let waveAt = 0; waveAt < wave.length;) {
723
+ const page = [];
724
+ const pageBases = /* @__PURE__ */ new Set();
725
+ let pageBytes = 0;
726
+ while (waveAt < wave.length) {
727
+ const item = wave[waveAt];
728
+ const oid = baseOf(item);
729
+ let bytes = item.delta.data === void 0 ? encodedBytes(item.delta.size) : 0;
730
+ if (oid !== void 0 && !pageBases.has(oid) && !lru.has(oid) && !chunked.has(oid) && !inlineByOid.has(oid) && activeStager?.bufferedRow(oid) === void 0) {
731
+ const size = headers.get(oid)?.size ?? externalBases.get(oid) ?? 0;
732
+ if (size > 0) bytes += encodedBytes(size);
733
+ }
734
+ if (page.length > 0 && pageBytes + bytes > pageCap()) break;
735
+ page.push(item);
736
+ if (oid !== void 0) pageBases.add(oid);
737
+ pageBytes += bytes;
738
+ waveAt += 1;
739
+ }
740
+ let pageHeld = 0;
741
+ if (page.length === 1 && large !== void 0) {
742
+ const only = page[0].delta;
743
+ if (only.data === void 0 && only.size > roundCap) yield* large.hold(only.size - roundCap);
744
+ }
745
+ const fetchedBases = /* @__PURE__ */ new Map();
746
+ const fetchedInstructions = /* @__PURE__ */ new Map();
747
+ const missingExternal = [];
748
+ const toRead = [];
749
+ for (const { delta } of page) {
750
+ if (delta.data !== void 0) {
751
+ fetchedInstructions.set(delta.seq, delta.data);
752
+ continue;
753
+ }
754
+ yield* growMem(delta.size);
755
+ pageHeld += delta.size;
756
+ const buf = new Uint8Array(delta.size);
757
+ fetchedInstructions.set(delta.seq, buf);
758
+ let at = 0;
759
+ for (const [partIdx, rawSize] of (delta.parts ?? []).entries()) {
760
+ const buffered = activeStager?.bufferedDelta(delta.seq, partIdx);
761
+ if (buffered !== void 0) buf.set(buffered, at);
762
+ else toRead.push({
763
+ key: stagedDeltaKey(activeStager.opened.batch, delta.seq, partIdx),
764
+ bytes: encodedBytes(rawSize),
765
+ buf,
766
+ offset: at
767
+ });
768
+ at += rawSize;
769
+ }
770
+ }
771
+ for (const oid of pageBases) {
772
+ const local = yield* readLocal(oid);
773
+ if (local !== void 0) {
774
+ fetchedBases.set(oid, local);
775
+ continue;
776
+ }
777
+ if (externalBases.has(oid)) {
778
+ missingExternal.push(oid);
779
+ continue;
780
+ }
781
+ const header = headers.get(oid);
782
+ if (header !== void 0 && activeStager !== void 0) toRead.push({
783
+ key: stagedRowKey(oid),
784
+ bytes: encodedBytes(header.size),
785
+ oid
160
786
  });
161
- unresolved -= 1;
162
787
  }
163
- waiting.delete(key);
788
+ if (toRead.length > 0 && staging !== void 0) for (let at = 0; at < toRead.length;) {
789
+ const batch = [];
790
+ let bytes = 0;
791
+ while (at < toRead.length) {
792
+ const item = toRead[at];
793
+ if (batch.length > 0 && bytes + item.bytes > roundCap) break;
794
+ batch.push(item);
795
+ bytes += item.bytes;
796
+ at += 1;
797
+ }
798
+ const rows = yield* staging.readStaged(batch.map(({ key }) => key));
799
+ for (const [i, item] of batch.entries()) {
800
+ const row = rows[i];
801
+ if ("oid" in item) {
802
+ if (row === void 0) return yield* stagedLoss(item.oid);
803
+ const obj = yield* objectOfRow(row);
804
+ yield* growMem(obj.bytes.byteLength);
805
+ pageHeld += obj.bytes.byteLength;
806
+ fetchedBases.set(obj.oid, obj);
807
+ lru.set(obj.oid, obj);
808
+ } else item.buf.set(yield* decodeDeltaPart(row, item.key.id), item.offset);
809
+ }
810
+ }
811
+ const runItem = (item, base) => {
812
+ const instructions = fetchedInstructions.get(item.delta.seq);
813
+ if (instructions === void 0) return Effect.void;
814
+ fetchedInstructions.delete(item.delta.seq);
815
+ return walk(resolveDelta(base, item.delta.offset, instructions, item.delta.data?.byteLength ?? 0));
816
+ };
817
+ if (missingExternal.length > 0) yield* eachExternal(missingExternal, (base) => {
818
+ lru.set(base.oid, base);
819
+ return Effect.forEach(page, (item) => baseOf(item) === base.oid ? runItem(item, base) : Effect.void, { discard: true });
820
+ });
821
+ for (const item of page) {
822
+ if (!fetchedInstructions.has(item.delta.seq)) continue;
823
+ const baseOid = baseOf(item);
824
+ const base = baseOid === void 0 ? void 0 : fetchedBases.get(baseOid) ?? (yield* readOwnObject(baseOid));
825
+ if (base !== void 0) yield* runItem(item, base);
826
+ }
827
+ shrinkMem(pageHeld);
164
828
  }
165
829
  }
166
830
  });
167
- yield* settle();
168
- const outside = [...waiting.keys()].flatMap((key) => key.startsWith("r:") ? [key.slice(2)] : []);
169
- const bases = outside.length === 0 ? /* @__PURE__ */ new Map() : yield* input.held(outside);
170
- for (const base of bases.values()) ready.push({
171
- offset: void 0,
172
- object: base
173
- });
174
- yield* settle();
175
- if (unresolved > 0) return yield* Effect.fail(gitError("INVALID_ARGUMENT", `pack has ${unresolved} unresolved deltas`, { hint: "Push again, with every object the pack needs" }));
176
- return objects;
177
- });
178
- /**
179
- * `INVALID_ARGUMENT` for the first object Git 2.53's fsck refuses a push for: one of the pack's
180
- * own, or a `.gitmodules` or `.gitattributes` one of its trees names, in the pack or the repo.
181
- */
182
- const fscked = /* @__PURE__ */ Effect.fnUntraced(function* (input, objects) {
183
- const checked = receiveChecked();
184
- for (const object of objects.values()) {
185
- const fault = fsckObject(object, checked);
186
- if (fault !== void 0) return yield* Effect.fail(fsckRefusal(object.oid, fault));
187
- const overflow = checkedOverflow(checked);
188
- if (overflow !== void 0) return yield* Effect.fail(overflow);
831
+ for (const offset of waitingByOffset.keys()) if (offsetToOid.has(offset)) readyOffsetsForSpilled.add(offset);
832
+ for (const oid of waitingByOid.keys()) if (headers.has(oid)) readyForSpilled.add(oid);
833
+ yield* drainSpilledRounds();
834
+ const outsideOids = [...waitingByOid.keys()].filter((oid) => !headers.has(oid));
835
+ if (outsideOids.length > 0) {
836
+ yield* eachExternal(outsideOids, (base) => Effect.flatMap(chargeInflated(base.bytes.byteLength), () => {
837
+ externalBases.set(base.oid, base.bytes.byteLength);
838
+ lru.set(base.oid, base);
839
+ return Effect.map(resolveInMemoryTree({
840
+ oid: base.oid,
841
+ offset: void 0,
842
+ object: base
843
+ }), () => {
844
+ if (waitingByOid.has(base.oid)) readyForSpilled.add(base.oid);
845
+ });
846
+ }));
847
+ yield* drainSpilledRounds();
189
848
  }
190
- yield* checkedFilesRefused(checked, (oid) => Effect.succeed(objects.get(oid)), input.held);
191
- });
192
- /**
193
- * `INVALID_ARGUMENT` unless every object the pack's own name is in it or the repo, of the type its
194
- * link says, and `shallowRoot` when a shallow client's commit names parents neither holds. A
195
- * partial pack may leave out both, but for its tags' objects, which Git's server sends with them
196
- * through any depth or filter: a missing one is `tagTargetMissing`, as the stored receive says. An
197
- * import segment's boundary is its own commits, and their parents it leaves out are never asked of
198
- * the repo; those it holds are checked as any link is.
199
- */
200
- const connected = /* @__PURE__ */ Effect.fnUntraced(function* (input, objects) {
201
- const partial = input.receive.partial === true;
202
- const shallow = new Set(input.receive.shallow);
203
- const boundary = new Set(input.receive.boundary);
204
- const links = [];
849
+ if (unresolved > 0) return yield* Effect.fail(gitError("INVALID_ARGUMENT", `pack has ${unresolved} unresolved deltas`, { hint: "Push again, with every object the pack needs" }));
850
+ yield* checkedFilesRefused(checked, readOwnObject, input.held);
851
+ const partial = receive.partial === true;
852
+ const shallow = new Set(receive.shallow);
853
+ const boundary = new Set(receive.boundary);
205
854
  const parents = [];
206
855
  const tagged = /* @__PURE__ */ new Map();
207
- for (const oid of boundary) if (objects.get(oid)?.type !== "commit") return yield* Effect.fail(boundaryNotInPack(oid));
208
- const segment = segmentCut(input.receive.cutMost);
209
- for (const oid of input.receive.needs ?? []) links.push({
856
+ for (const oid of boundary) if (headers.get(oid)?.type !== "commit") return yield* Effect.fail(boundaryNotInPack(oid));
857
+ const segment = segmentCut(receive.cutMost);
858
+ const inPack = (oid) => headers.has(oid);
859
+ let wrong;
860
+ let linkCount = 0;
861
+ let waitingLinks = [];
862
+ const asked = /* @__PURE__ */ new Map();
863
+ const typed = (at, link, type) => {
864
+ if (type !== link.type && (wrong === void 0 || at < wrong.at)) wrong = {
865
+ at,
866
+ error: wrongType(link, type)
867
+ };
868
+ };
869
+ const checkLinks = Effect.fnUntraced(function* (missing) {
870
+ if (waitingLinks.length === 0) return;
871
+ const batch = waitingLinks;
872
+ waitingLinks = [];
873
+ const repoHeaders = yield* input.headers([...new Set(batch.map(({ link }) => link.oid))]);
874
+ for (const { at, link } of batch) {
875
+ const type = repoHeaders.get(link.oid)?.type;
876
+ if (type === void 0) return yield* Effect.fail(missing(link));
877
+ typed(at, link, type);
878
+ }
879
+ for (const [oid, { type }] of repoHeaders) if (asked.size < 1e5) asked.set(oid, type);
880
+ });
881
+ const missingLink = (link) => partial ? tagTargetMissing(link.oid, tagged.get(link.oid)) : objectMissing(link.oid);
882
+ const queueLink = (link, missing = missingLink) => {
883
+ const at = linkCount++;
884
+ const type = link.oid === "4b825dc642cb6eb9a060e54bf8d69288fbee4904" ? "tree" : headers.get(link.oid)?.type ?? asked.get(link.oid);
885
+ if (type !== void 0) typed(at, link, type);
886
+ else waitingLinks.push({
887
+ at,
888
+ link
889
+ });
890
+ return waitingLinks.length >= 1e3 ? checkLinks(missing) : Effect.void;
891
+ };
892
+ const trackRoots = !partial && receive.boundary === void 0;
893
+ const namedInPack = /* @__PURE__ */ new Set();
894
+ let outside = trackRoots ? /* @__PURE__ */ new Set() : void 0;
895
+ const trackLink = (oid) => {
896
+ if (headers.has(oid)) namedInPack.add(oid);
897
+ else if (oid !== "4b825dc642cb6eb9a060e54bf8d69288fbee4904" && outside !== void 0) {
898
+ if (outside.size >= 1e5) outside = void 0;
899
+ else outside.add(oid);
900
+ }
901
+ };
902
+ for (const oid of receive.needs ?? []) yield* queueLink({
210
903
  oid,
211
904
  type: "commit"
212
905
  });
213
- for (const object of objects.values()) {
214
- if (partial && object.type !== "tag") continue;
215
- const split = shallowLinks(object, yield* Effect.fromResult(linksOf(object)), shallow);
216
- if (partial) for (const link of split.needed) tagged.set(link.oid, object.oid);
217
- const cut = shallowLinks(object, split.needed, boundary);
218
- for (const link of cut.needed) links.push(link);
906
+ for (const entry of headEntries) {
907
+ if (partial && entry.type !== "tag") continue;
908
+ if (trackRoots) for (const link of entry.links) trackLink(link.oid);
909
+ const split = shallowLinks(entry, entry.links, shallow);
910
+ if (partial) for (const link of split.needed) tagged.set(link.oid, entry.oid);
911
+ const cut = shallowLinks(entry, split.needed, boundary);
912
+ for (const link of cut.needed) yield* queueLink(link);
219
913
  for (const parent of cut.parents) {
220
- const past = segment.add(object.oid, parent.oid);
221
- if (past !== void 0) return yield* Effect.fail(past);
222
- if (objects.has(parent.oid)) links.push(parent);
914
+ const pastCut = segment.add(entry.oid, parent.oid);
915
+ if (pastCut !== void 0) return yield* Effect.fail(pastCut);
916
+ if (inPack(parent.oid)) yield* queueLink(parent);
223
917
  }
224
918
  for (const parent of split.parents) parents.push(parent);
225
919
  }
226
- const outside = (link) => link.oid !== "4b825dc642cb6eb9a060e54bf8d69288fbee4904" && !objects.has(link.oid);
227
- const asked = new Set([...links, ...parents].flatMap((link) => outside(link) ? [link.oid] : []));
228
- const held = asked.size === 0 ? /* @__PURE__ */ new Map() : yield* input.held([...asked]);
229
- const missing = links.find((link) => outside(link) && !held.has(link.oid));
230
- if (missing !== void 0) return yield* Effect.fail(partial ? tagTargetMissing(missing.oid, tagged.get(missing.oid)) : objectMissing(missing.oid));
231
- if (parents.some((link) => outside(link) && !held.has(link.oid))) return yield* Effect.fail(shallowRoot());
232
- const typeOf = (oid) => oid === "4b825dc642cb6eb9a060e54bf8d69288fbee4904" ? "tree" : (objects.get(oid) ?? held.get(oid))?.type;
233
- const wrong = mistyped([...links, ...parents], typeOf);
234
- if (wrong !== void 0) return yield* Effect.fail(wrong);
235
- return segment.leftOut((oid) => objects.has(oid));
236
- });
237
- /**
238
- * A received pack as rows, one per object, for its push's commit: each entry read and resolved,
239
- * each object checked as Git's fsck checks it and parsed, and every object they name present, of
240
- * the type its link says. Refused whole, before any row, past `limits` or for an object whose row
241
- * passes 1 MiB, for a malformed or unresolved pack, an `OFS_DELTA` where `offsetDeltas` refuses
242
- * one, an object fsck refuses, or a missing or mistyped object.
243
- */
244
- const unpackObjects = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
245
- const { receive, limits: limits$1 } = input;
246
- if (receive.objects > limits$1.objects) return yield* Effect.fail(input.tooMany(receive.objects));
247
- const past = segmentTooLarge(receive);
248
- if (past !== void 0) return yield* Effect.fail(past);
249
- const { entries, bytes } = yield* readEntries(input, limits$1.bytes);
250
- const objects = yield* resolve(input, entries, limits$1.bytes);
251
- yield* fscked(input, objects);
252
- const cut = yield* connected(input, objects);
253
- const rows = [...objects.values()].map(objectRow);
254
- let valuesBytes = 0;
255
- for (const row of rows) {
256
- const valueBytes = rowValueBytes(row.value);
257
- if (valueBytes > limits.valueBytes) return yield* Effect.fail(rowTooLarge(row.id, valueBytes));
258
- valuesBytes += valueBytes;
920
+ if (!partial && packTrees.length > 0) {
921
+ const checkTreeObject = Effect.fnUntraced(function* (tree) {
922
+ const next = linkReader(tree);
923
+ for (let read = next();; read = next()) {
924
+ if (Result.isFailure(read)) return yield* Effect.fail(read.failure);
925
+ if (read.success === void 0) break;
926
+ if (trackRoots) trackLink(read.success.oid);
927
+ yield* queueLink(read.success);
928
+ }
929
+ });
930
+ const evictedTrees = [];
931
+ for (const oid of packTrees) {
932
+ const largeTree = chunked.get(oid);
933
+ const tree = (yield* readInMemory(oid)) ?? (largeTree !== void 0 && large !== void 0 ? {
934
+ oid,
935
+ type: "tree",
936
+ bytes: yield* large.staged(largeTree)
937
+ } : void 0);
938
+ if (tree !== void 0) yield* checkTreeObject(tree);
939
+ else evictedTrees.push(oid);
940
+ }
941
+ if (evictedTrees.length > 0 && activeStager !== void 0 && staging !== void 0) for (let at = 0; at < evictedTrees.length;) {
942
+ const page = [];
943
+ let pageBytes = 0;
944
+ while (at < evictedTrees.length) {
945
+ const oid = evictedTrees[at];
946
+ const est = encodedBytes(headers.get(oid)?.size ?? 0);
947
+ if (page.length > 0 && pageBytes + est > pageCap()) break;
948
+ page.push(oid);
949
+ pageBytes += est;
950
+ at += 1;
951
+ }
952
+ yield* growMem(pageBytes);
953
+ const rows = yield* staging.readStaged(page.map(stagedRowKey));
954
+ for (const [i, oid] of page.entries()) {
955
+ const row = rows[i];
956
+ if (row === void 0) return yield* stagedLoss(oid);
957
+ yield* checkTreeObject(yield* objectOfRow(row));
958
+ }
959
+ shrinkMem(pageBytes);
960
+ }
259
961
  }
260
- const rowBytes = rows.reduce((sum, row) => sum + JSON.stringify(row).length, 0);
261
- if (rowBytes > limits$1.bytes) return yield* Effect.fail(tooLarge(rowBytes, limits$1.bytes));
262
- const moved = {
263
- objects: rows.length,
264
- bytes: valuesBytes
962
+ yield* checkLinks(missingLink);
963
+ for (const parent of parents) yield* queueLink(parent, shallowRoot);
964
+ yield* checkLinks(shallowRoot);
965
+ if (wrong !== void 0) return yield* Effect.fail(wrong.error);
966
+ if (activeStager !== void 0) yield* activeStager.flush();
967
+ const readRows = (oids) => activeStager === void 0 || staging === void 0 || oids.length === 0 ? Effect.succeed(oids.map(() => void 0)) : staging.readStaged(oids.map(stagedRowKey));
968
+ const own = {
969
+ headers,
970
+ commits,
971
+ readRow: (oid) => headers.has(oid) ? Effect.map(readRows([oid]), ([row]) => row) : Effect.succeed(void 0),
972
+ readRows
265
973
  };
266
- return {
267
- objects: [...objects.values()],
268
- rows,
974
+ const roots = trackRoots ? rootsOf(headers.keys(), (oid) => namedInPack.has(oid)) : void 0;
975
+ const unpacked = {
976
+ inlineObjects: [...inlineByOid.values()],
977
+ inlineRows,
978
+ staged: activeStager !== void 0,
979
+ own,
980
+ chunked: [...chunked.values()],
981
+ count: headers.size,
269
982
  moved,
270
- bytes,
271
- cut
983
+ bytes: packRead.bytes,
984
+ cut: segment.leftOut(inPack),
985
+ lfsPointers: pointers.finish(),
986
+ largest: largest.finish()
272
987
  };
988
+ if (roots !== void 0) {
989
+ unpacked.roots = roots;
990
+ if (outside !== void 0) unpacked.outside = [...outside];
991
+ }
992
+ return unpacked;
273
993
  });
274
- export { commitBytes, malformedPack, ofsRefused, readFailure, rowTooLarge, unpackObjects };
994
+ export { baseLruBytes, deltaChainTooDeep, deltaRoundsMost, malformedPack, maxInflatedBytes, ofsRefused, pastDeclared, pendingHeldMost, readFailure, roundReadBytes, rowTooLarge, unpackObjects };