@ref0/git 0.20.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (379) hide show
  1. package/dist/access/private-refs.mjs +1 -1
  2. package/dist/auth/access-jwt.mjs +3 -3
  3. package/dist/auth/auth-namespace.d.mts +3 -3
  4. package/dist/auth/auth-namespace.mjs +3 -2
  5. package/dist/auth/auth.d.mts +3 -3
  6. package/dist/auth/auth.mjs +9 -8
  7. package/dist/auth/authorize.mjs +1 -1
  8. package/dist/auth/fences.d.mts +1 -1
  9. package/dist/auth/host-function.mjs +1 -1
  10. package/dist/auth/host-services.mjs +4 -6
  11. package/dist/auth/identify.d.mts +1 -1
  12. package/dist/auth/identify.mjs +6 -0
  13. package/dist/auth/token-cleanup.mjs +2 -2
  14. package/dist/auth/token-rows.mjs +6 -1
  15. package/dist/auth/token-text.mjs +1 -1
  16. package/dist/auth/tokens-base.d.mts +1 -1
  17. package/dist/auth/tokens.d.mts +1 -1
  18. package/dist/auth/tokens.mjs +1 -1
  19. package/dist/client/client.d.mts +15 -7
  20. package/dist/client/client.mjs +21 -12
  21. package/dist/client/git-http.mjs +1 -1
  22. package/dist/client/local.mjs +60 -24
  23. package/dist/client/negotiate.mjs +3 -3
  24. package/dist/client/push-upload.mjs +26 -10
  25. package/dist/client/remote.mjs +4 -3
  26. package/dist/client/run-remote-helper.d.mts +2 -2
  27. package/dist/client/run-remote-helper.mjs +6 -6
  28. package/dist/client/slice-push.d.mts +1 -1
  29. package/dist/client/transport.mjs +3 -3
  30. package/dist/contracts/blobs.d.mts +3 -3
  31. package/dist/contracts/blobs.mjs +1 -1
  32. package/dist/contracts/calls-spent.mjs +5 -33
  33. package/dist/contracts/client.d.mts +15 -14
  34. package/dist/contracts/commits.d.mts +4 -4
  35. package/dist/contracts/commits.mjs +1 -1
  36. package/dist/contracts/engine.d.mts +2 -2
  37. package/dist/contracts/events.d.mts +1 -1
  38. package/dist/contracts/events.mjs +1 -1
  39. package/dist/contracts/files.d.mts +4 -4
  40. package/dist/contracts/files.mjs +1 -1
  41. package/dist/contracts/forks.d.mts +4 -4
  42. package/dist/contracts/forks.mjs +1 -1
  43. package/dist/contracts/git-hooks.d.mts +1 -1
  44. package/dist/contracts/git.d.mts +9 -5
  45. package/dist/contracts/grants.d.mts +1 -1
  46. package/dist/contracts/merges.d.mts +1 -1
  47. package/dist/contracts/object-values.d.mts +1 -0
  48. package/dist/contracts/object-values.mjs +16 -1
  49. package/dist/contracts/objects.d.mts +30 -18
  50. package/dist/contracts/opaque.mjs +1 -1
  51. package/dist/contracts/operations.mjs +1 -1
  52. package/dist/contracts/queue.d.mts +208 -44
  53. package/dist/contracts/queue.mjs +5 -5
  54. package/dist/contracts/refs.d.mts +5 -5
  55. package/dist/contracts/refs.mjs +1 -1
  56. package/dist/contracts/remote.d.mts +3 -6
  57. package/dist/contracts/repos.d.mts +3 -3
  58. package/dist/contracts/repos.mjs +1 -1
  59. package/dist/contracts/result.d.mts +10 -7
  60. package/dist/contracts/result.mjs +8 -3
  61. package/dist/contracts/rules.d.mts +13 -12
  62. package/dist/contracts/server.d.mts +8 -10
  63. package/dist/contracts/services.d.mts +6 -9
  64. package/dist/contracts/services.mjs +1 -2
  65. package/dist/contracts/signin.d.mts +1 -1
  66. package/dist/contracts/store.d.mts +2 -2
  67. package/dist/contracts/sync.d.mts +63 -6
  68. package/dist/contracts/sync.mjs +3 -2
  69. package/dist/contracts/tags.d.mts +3 -3
  70. package/dist/contracts/tags.mjs +1 -1
  71. package/dist/contracts/tokens.d.mts +2 -2
  72. package/dist/contracts/tokens.mjs +1 -1
  73. package/dist/contracts/topics.d.mts +9 -9
  74. package/dist/contracts/trees.d.mts +4 -4
  75. package/dist/contracts/trees.mjs +1 -1
  76. package/dist/contracts/work.d.mts +4 -4
  77. package/dist/contracts/work.mjs +2 -2
  78. package/dist/core/access.d.mts +1 -1
  79. package/dist/core/ancestry.mjs +30 -34
  80. package/dist/core/{promise.mjs → call-groups.mjs} +7 -30
  81. package/dist/core/call-services.mjs +1 -1
  82. package/dist/core/events/deliver.d.mts +2 -2
  83. package/dist/core/events/deliver.mjs +3 -3
  84. package/dist/core/events/retired.mjs +1 -1
  85. package/dist/core/forks.mjs +5 -5
  86. package/dist/core/hooks/groups.mjs +2 -2
  87. package/dist/core/imports.mjs +101 -21
  88. package/dist/core/index-job.mjs +14 -9
  89. package/dist/core/index-lost.d.mts +1 -1
  90. package/dist/core/loose-tally.mjs +38 -15
  91. package/dist/core/merge-parts.d.mts +17 -4
  92. package/dist/core/merge-parts.mjs +7 -2
  93. package/dist/core/mirror-rows.mjs +31 -1
  94. package/dist/core/objects/blobs.mjs +8 -10
  95. package/dist/core/objects/files.mjs +20 -17
  96. package/dist/core/objects/objects-layer.mjs +1 -1
  97. package/dist/core/objects/peel.mjs +1 -7
  98. package/dist/core/objects/reading.mjs +19 -18
  99. package/dist/core/objects/tree-edits.mjs +1 -1
  100. package/dist/core/objects/trees.mjs +257 -58
  101. package/dist/core/objects/writing.mjs +3 -9
  102. package/dist/core/own-writes.mjs +1 -1
  103. package/dist/core/parts.d.mts +8 -1
  104. package/dist/core/parts.mjs +8 -4
  105. package/dist/core/purge.mjs +31 -18
  106. package/dist/core/push.d.mts +2 -2
  107. package/dist/core/push.mjs +145 -98
  108. package/dist/core/receipts.d.mts +2 -2
  109. package/dist/core/receipts.mjs +9 -2
  110. package/dist/core/ref-index-job.mjs +4 -4
  111. package/dist/core/ref-view.mjs +74 -31
  112. package/dist/core/refs.mjs +3 -3
  113. package/dist/core/repack.mjs +25 -30
  114. package/dist/core/repo-info.mjs +1 -1
  115. package/dist/core/repos.mjs +1 -1
  116. package/dist/core/rules/changes.mjs +18 -40
  117. package/dist/core/rules/check.mjs +6 -5
  118. package/dist/core/rules/commit-changes.mjs +114 -58
  119. package/dist/core/rules/context.d.mts +3 -3
  120. package/dist/core/rules/context.mjs +18 -14
  121. package/dist/core/rules/fetch.mjs +1 -1
  122. package/dist/core/rules/protect.mjs +30 -17
  123. package/dist/core/saved-caller-views.d.mts +1 -1
  124. package/dist/core/saved-caller-views.mjs +3 -3
  125. package/dist/core/saved-callers.d.mts +1 -1
  126. package/dist/core/saved-callers.mjs +1 -1
  127. package/dist/core/seam.d.mts +1 -2
  128. package/dist/core/view.d.mts +6 -3
  129. package/dist/core/view.mjs +11 -10
  130. package/dist/core/work.mjs +2 -2
  131. package/dist/engine/allotted-xdiff.mjs +3 -16
  132. package/dist/engine/combined.d.mts +3 -0
  133. package/dist/engine/combined.mjs +200 -185
  134. package/dist/engine/content.d.mts +2 -2
  135. package/dist/engine/content.mjs +1 -1
  136. package/dist/engine/merge.mjs +7 -9
  137. package/dist/engine/reads.d.mts +2 -2
  138. package/dist/engine/reads.mjs +22 -14
  139. package/dist/engine/xdiff.d.mts +1 -1
  140. package/dist/engine/xdiff.mjs +1 -1
  141. package/dist/event-streams/event-streams.d.mts +1 -1
  142. package/dist/event-streams/event-streams.mjs +1 -1
  143. package/dist/event-streams/stream.d.mts +2 -2
  144. package/dist/event-streams/stream.mjs +3 -3
  145. package/dist/extend.d.mts +2 -6
  146. package/dist/extend.mjs +1 -5
  147. package/dist/http/core-parts.mjs +83 -26
  148. package/dist/http/handler.mjs +54 -9
  149. package/dist/http/parts.d.mts +1 -0
  150. package/dist/http/push-upload-job.mjs +138 -24
  151. package/dist/http/push-uploads.mjs +2 -2
  152. package/dist/http/receive-pack.mjs +14 -53
  153. package/dist/http/request-snapshot.mjs +258 -0
  154. package/dist/http/upload-pack.mjs +23 -18
  155. package/dist/index.d.mts +29 -21
  156. package/dist/index.mjs +11 -2
  157. package/dist/lfs/base.d.mts +1 -1
  158. package/dist/lfs/copy.d.mts +49 -1
  159. package/dist/lfs/copy.mjs +135 -22
  160. package/dist/lfs/layer.d.mts +4 -3
  161. package/dist/lfs/layer.mjs +4 -5
  162. package/dist/lfs/locks.mjs +2 -2
  163. package/dist/lfs/objects.d.mts +1 -1
  164. package/dist/lfs/objects.mjs +3 -3
  165. package/dist/lfs/pointers.mjs +1 -1
  166. package/dist/lfs/rows.d.mts +1 -1
  167. package/dist/lfs/rows.mjs +11 -4
  168. package/dist/lfs/upkeep.mjs +40 -9
  169. package/dist/lfs/uploaded.mjs +1 -1
  170. package/dist/lfs/wire.mjs +1 -1
  171. package/dist/merges/merges.mjs +17 -2
  172. package/dist/protocol/bytes/buffers.d.mts +1 -1
  173. package/dist/protocol/bytes/buffers.mjs +1 -1
  174. package/dist/protocol/bytes/deflate.d.mts +1 -1
  175. package/dist/protocol/bytes/deflate.mjs +1 -1
  176. package/dist/protocol/bytes/inflate.d.mts +1 -1
  177. package/dist/protocol/bytes/inflate.mjs +1 -1
  178. package/dist/protocol/bytes/sha1.d.mts +1 -1
  179. package/dist/protocol/bytes/sha1.mjs +1 -1
  180. package/dist/protocol/diff/read.d.mts +2 -1
  181. package/dist/protocol/diff/read.mjs +102 -8
  182. package/dist/protocol/packs/graph.mjs +1 -1
  183. package/dist/protocol/packs/idx.d.mts +1 -1
  184. package/dist/protocol/packs/idx.mjs +1 -1
  185. package/dist/protocol/packs/parts.mjs +1 -1
  186. package/dist/protocol/packs/reader.d.mts +1 -1
  187. package/dist/protocol/packs/reader.mjs +1 -1
  188. package/dist/protocol/packs/write-error.d.mts +1 -1
  189. package/dist/protocol/packs/write-error.mjs +1 -1
  190. package/dist/protocol/packs/writer.mjs +3 -3
  191. package/dist/protocol/wire/advertisement.d.mts +1 -1
  192. package/dist/protocol/wire/advertisement.mjs +3 -2
  193. package/dist/protocol/wire/fetch.d.mts +1 -1
  194. package/dist/protocol/wire/fetch.mjs +1 -1
  195. package/dist/protocol/wire/lines.d.mts +9 -1
  196. package/dist/protocol/wire/lines.mjs +28 -1
  197. package/dist/protocol/wire/push-uploads.mjs +10 -7
  198. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  199. package/dist/protocol/wire/receive-pack.mjs +1 -1
  200. package/dist/protocol/wire/report-status.d.mts +1 -1
  201. package/dist/protocol/wire/report-status.mjs +1 -1
  202. package/dist/protocol/wire/v2.d.mts +1 -1
  203. package/dist/protocol/wire/v2.mjs +1 -1
  204. package/dist/queue/advance.mjs +31 -24
  205. package/dist/queue/base.d.mts +5 -3
  206. package/dist/queue/calls.mjs +5 -5
  207. package/dist/queue/commit.mjs +1 -1
  208. package/dist/queue/host.d.mts +1 -1
  209. package/dist/queue/layer.d.mts +0 -1
  210. package/dist/queue/layer.mjs +9 -5
  211. package/dist/queue/schedule.mjs +1 -1
  212. package/dist/queue/search.mjs +1 -1
  213. package/dist/queue/state.mjs +1 -1
  214. package/dist/queue/trim.mjs +2 -2
  215. package/dist/rest/client.d.mts +1 -1
  216. package/dist/rest/client.mjs +6 -6
  217. package/dist/rest/errors.mjs +1 -1
  218. package/dist/rest/handler.mjs +2 -2
  219. package/dist/rest/handlers.mjs +16 -6
  220. package/dist/rest/layer.mjs +1 -1
  221. package/dist/rest/listen.mjs +2 -2
  222. package/dist/rest/refs.mjs +1 -1
  223. package/dist/server/edge.mjs +27 -3
  224. package/dist/server/git-layer.d.mts +1 -2
  225. package/dist/server/git-layer.mjs +4 -5
  226. package/dist/server/lifecycle.mjs +1 -1
  227. package/dist/server/registry.mjs +2 -8
  228. package/dist/server/server.mjs +62 -43
  229. package/dist/signin/context.d.mts +1 -1
  230. package/dist/signin/context.mjs +1 -1
  231. package/dist/signin/forms.mjs +1 -1
  232. package/dist/signin/grants.d.mts +2 -2
  233. package/dist/signin/grants.mjs +1 -1
  234. package/dist/signin/wire.mjs +1 -1
  235. package/dist/storage/allotted.mjs +4 -9
  236. package/dist/storage/batch-upkeep.mjs +31 -12
  237. package/dist/storage/batches.d.mts +2 -3
  238. package/dist/storage/batches.mjs +52 -49
  239. package/dist/storage/budget.mjs +23 -1
  240. package/dist/storage/calls.d.mts +1 -1
  241. package/dist/storage/calls.mjs +41 -43
  242. package/dist/storage/charged-cache.mjs +180 -0
  243. package/dist/storage/chunks.d.mts +3 -3
  244. package/dist/storage/chunks.mjs +121 -8
  245. package/dist/storage/counted-bucket.mjs +32 -10
  246. package/dist/storage/fetch-row-cache.d.mts +6 -0
  247. package/dist/storage/fetch-row-cache.mjs +211 -0
  248. package/dist/storage/fetch.d.mts +1 -0
  249. package/dist/storage/fetch.mjs +54 -242
  250. package/dist/storage/held-types.d.mts +0 -1
  251. package/dist/storage/held-types.mjs +13 -4
  252. package/dist/storage/host-bucket.mjs +9 -4
  253. package/dist/storage/index-bitmaps.mjs +340 -65
  254. package/dist/storage/index-build.d.mts +2 -3
  255. package/dist/storage/index-build.mjs +274 -56
  256. package/dist/storage/index-fetch.d.mts +3 -1
  257. package/dist/storage/index-fetch.mjs +60 -21
  258. package/dist/storage/index-graph.mjs +1 -1
  259. package/dist/storage/index-layers.mjs +55 -25
  260. package/dist/storage/index-reach.mjs +15 -22
  261. package/dist/storage/index-whole.d.mts +7 -0
  262. package/dist/storage/index-whole.mjs +145 -37
  263. package/dist/storage/largest-files.mjs +1 -7
  264. package/dist/storage/layout.mjs +17 -1
  265. package/dist/storage/lfs-pointers.mjs +1 -6
  266. package/dist/storage/link-join.mjs +55 -16
  267. package/dist/storage/list-source.d.mts +7 -0
  268. package/dist/storage/list-source.mjs +288 -0
  269. package/dist/storage/loose.d.mts +8 -8
  270. package/dist/storage/loose.mjs +157 -91
  271. package/dist/storage/memory-budget.mjs +226 -22
  272. package/dist/storage/merge-cut.mjs +9 -6
  273. package/dist/storage/merge-fence.mjs +1 -1
  274. package/dist/storage/merge-row.mjs +1 -1
  275. package/dist/storage/merge.d.mts +2 -3
  276. package/dist/storage/merge.mjs +2 -2
  277. package/dist/storage/object-rows.d.mts +3 -3
  278. package/dist/storage/object-rows.mjs +179 -38
  279. package/dist/storage/pack-order.mjs +97 -44
  280. package/dist/storage/pack-ranges.mjs +44 -16
  281. package/dist/storage/pack-reads.d.mts +5 -3
  282. package/dist/storage/pack-reads.mjs +236 -72
  283. package/dist/storage/pack-receive.d.mts +1 -2
  284. package/dist/storage/pack-receive.mjs +24 -18
  285. package/dist/storage/packs.d.mts +1 -1
  286. package/dist/storage/packs.mjs +477 -116
  287. package/dist/storage/placed-reads.mjs +33 -16
  288. package/dist/storage/prune-seen.mjs +1 -1
  289. package/dist/storage/prune-walk.mjs +1 -1
  290. package/dist/storage/prune.mjs +4 -31
  291. package/dist/storage/push-allotment.mjs +26 -14
  292. package/dist/storage/push-uploads.mjs +195 -57
  293. package/dist/storage/pushed-commits.mjs +20 -1
  294. package/dist/storage/quarantine.d.mts +2 -3
  295. package/dist/storage/range-cache.mjs +175 -40
  296. package/dist/storage/raw-ids.mjs +39 -10
  297. package/dist/storage/ready.d.mts +2 -3
  298. package/dist/storage/ready.mjs +114 -38
  299. package/dist/storage/receive-bounds.mjs +31 -9
  300. package/dist/storage/receive-cache.d.mts +7 -0
  301. package/dist/storage/receive-cache.mjs +147 -0
  302. package/dist/storage/receive-files.mjs +1 -1
  303. package/dist/storage/receive-links.mjs +1 -1
  304. package/dist/storage/receive-state.d.mts +2 -2
  305. package/dist/storage/receive-state.mjs +6 -8
  306. package/dist/storage/receive-steps.d.mts +20 -0
  307. package/dist/storage/receive-steps.mjs +298 -13
  308. package/dist/storage/repack-backlog.mjs +1 -6
  309. package/dist/storage/repack-contained.mjs +2 -2
  310. package/dist/storage/repack-job.mjs +1 -1
  311. package/dist/storage/repack.d.mts +2 -3
  312. package/dist/storage/repack.mjs +54 -9
  313. package/dist/storage/request-cache.mjs +57 -0
  314. package/dist/storage/roots.mjs +1 -24
  315. package/dist/storage/rows.d.mts +2 -2
  316. package/dist/storage/rows.mjs +1 -1
  317. package/dist/storage/runs.d.mts +2 -2
  318. package/dist/storage/runs.mjs +1 -1
  319. package/dist/storage/send-list.mjs +62 -25
  320. package/dist/storage/stream-whole.mjs +84 -63
  321. package/dist/storage/swap-walk.mjs +1 -1
  322. package/dist/storage/unpack.mjs +878 -450
  323. package/dist/storage/visible.mjs +110 -32
  324. package/dist/storage/walk.mjs +1 -0
  325. package/dist/storage/wants.mjs +22 -58
  326. package/dist/store/call-count.d.mts +2 -2
  327. package/dist/store/call-count.mjs +24 -11
  328. package/dist/store/catalogue.d.mts +1 -1
  329. package/dist/store/catalogue.mjs +19 -7
  330. package/dist/store/crossing.mjs +1 -7
  331. package/dist/store/cursor-seal.d.mts +1 -1
  332. package/dist/store/cursor-seal.mjs +1 -1
  333. package/dist/store/door.mjs +9 -4
  334. package/dist/store/errors.d.mts +2 -2
  335. package/dist/store/errors.mjs +107 -19
  336. package/dist/store/git-store.mjs +7 -2
  337. package/dist/store/job-try.mjs +90 -9
  338. package/dist/store/list-job.mjs +10 -34
  339. package/dist/store/outbox.d.mts +2 -2
  340. package/dist/store/outbox.mjs +2 -2
  341. package/dist/store/queue-jobs.mjs +6 -12
  342. package/dist/store/records.d.mts +2 -2
  343. package/dist/store/records.mjs +2 -2
  344. package/dist/store/ref-rows.d.mts +2 -2
  345. package/dist/store/ref-rows.mjs +2 -2
  346. package/dist/store/repo-record.d.mts +2 -2
  347. package/dist/store/repo-record.mjs +3 -3
  348. package/dist/store/request-snapshot.mjs +5 -0
  349. package/dist/store/reservations.mjs +2 -2
  350. package/dist/store/topic-jobs.mjs +5 -11
  351. package/dist/sync/bound.d.mts +3 -3
  352. package/dist/sync/bound.mjs +10 -7
  353. package/dist/sync/github.mjs +65 -67
  354. package/dist/sync/http.mjs +1 -1
  355. package/dist/sync/import.mjs +201 -66
  356. package/dist/sync/layer.d.mts +1 -1
  357. package/dist/sync/layer.mjs +6 -6
  358. package/dist/sync/lfs-batch.mjs +1 -1
  359. package/dist/sync/lfs-copy.mjs +175 -15
  360. package/dist/sync/mirror.mjs +5 -10
  361. package/dist/sync/said.mjs +1 -1
  362. package/dist/sync/step.mjs +268 -86
  363. package/dist/sync/tries.mjs +25 -6
  364. package/dist/sync.d.mts +2 -2
  365. package/dist/sync.mjs +2 -2
  366. package/dist/topics/advance.mjs +3 -3
  367. package/dist/topics/calls.mjs +1 -1
  368. package/dist/topics/layer.d.mts +15 -14
  369. package/dist/topics/members.mjs +1 -1
  370. package/dist/topics/topic.mjs +1 -1
  371. package/package.json +3 -13
  372. package/dist/auth/helpers.mjs +0 -17
  373. package/dist/auth.d.mts +0 -5
  374. package/dist/auth.mjs +0 -5
  375. package/dist/core/rules/commit-changes.d.mts +0 -12
  376. package/dist/effect.d.mts +0 -9
  377. package/dist/effect.mjs +0 -7
  378. package/dist/server/joined.d.mts +0 -70
  379. package/dist/server/joined.mjs +0 -41
@@ -1,51 +1,59 @@
1
- import { streamThen } from "../protocol/bytes/streams.mjs";
2
1
  import { handingOn } from "../protocol/packs/writer.mjs";
3
2
  import { newChangeId } from "../store/scopes.mjs";
4
3
  import { callScope } from "../store/call-count.mjs";
5
4
  import { cancelsBody, objectReader } from "./calls.mjs";
6
5
  import { fetchPack } from "./fetch.mjs";
7
6
  import { pushedCommitsPage } from "./pushed-commits.mjs";
8
- import { copyRowsPage, eachHeldRow, gitObjectOf, heldRows, readsOwnChunks, rowHeaders, rowSizes, rowsStartingWith, startingOf } from "./object-rows.mjs";
7
+ import { copyRowsPage, eachHeldRow, gitObjectOf, heldRows, readStagedRows, readsOwnChunks, rowAt, rowHeaders, rowSizes, rowsStartingWith, startingOf } from "./object-rows.mjs";
9
8
  import { allotmentWithin } from "../contracts/object-values.mjs";
10
9
  import { allottedRows } from "./allotted.mjs";
11
10
  import { looseUpkeep } from "./batch-upkeep.mjs";
12
- import { abandonBatch, openBatch, rowsChange } from "./batches.mjs";
11
+ import { abandonBatch, batchStager, fastPath, openBatch, stageBytes, streamedChange } from "./batches.mjs";
13
12
  import { allottableOf, defaultMemory, readReserveBytes } from "./budget.mjs";
14
- import { ChunkReader, chunkRawBytes, chunkedReadBytes, chunkedRow, fitsRow, stageChunk } from "./chunks.mjs";
15
- import { MemoryBudget } from "./memory-budget.mjs";
16
- import { pointersOfObjects } from "./lfs-pointers.mjs";
17
- import { largestOf } from "./largest-files.mjs";
18
- import { wholeRoots } from "./roots.mjs";
19
- import { commitBytes, unpackObjects } from "./unpack.mjs";
13
+ import { ChunkReader, chunkPageBytes, chunkRawBytes, chunkStream, chunkedRow, fitsRow, stageChunk } from "./chunks.mjs";
14
+ import { MemoryBudget, withMemoryBudget } from "./memory-budget.mjs";
15
+ import { baseLruBytes, pendingHeldMost, roundReadBytes, unpackObjects } from "./unpack.mjs";
20
16
  import { gitError } from "../contracts/result.mjs";
21
- import * as Clock from "effect/Clock";
17
+ import { limits } from "@ref0/infra";
22
18
  import * as Effect from "effect/Effect";
23
19
  import * as Exit from "effect/Exit";
24
- import * as Scope from "effect/Scope";
20
+ import * as Scope$1 from "effect/Scope";
21
+ import * as Clock from "effect/Clock";
25
22
  // src/storage/loose.ts
26
- /** The most objects one push may carry into `loose()` storage, each a row of its commit. */
27
- const looseObjectsMost = 1e4;
23
+ /** The most objects one push may carry into `loose()` storage. */
24
+ const looseObjectsMost = 5e4;
25
+ /** The most pack wire bytes one push may carry into `loose()` storage, before inflation. */
26
+ const looseBytesMost = 67108864;
28
27
  /** The bytes one object takes in `loose()` storage at most, as Cloudflare Artifacts takes a file. */
29
28
  const looseFileBytesMost = 33554432;
30
29
  /**
31
- * What one push may carry into `loose()` storage: its `objects`, the `bytes` of its rows as JSON,
32
- * which its commit holds, and the bytes of each object, `fileBytes`, one past a row kept as chunks.
30
+ * What one push may carry into `loose()` storage: its `objects`, its pack's `bytes` on the wire
31
+ * before inflation, and the bytes of each object, `fileBytes`, one past a row kept as chunks.
33
32
  */
34
33
  const looseLimits = {
35
34
  objects: looseObjectsMost,
36
- bytes: commitBytes,
35
+ bytes: looseBytesMost,
37
36
  fileBytes: looseFileBytesMost
38
37
  };
39
- /**
40
- * The bytes a push's objects past one row take in all, a delta's results among them: eight of the
41
- * largest. Without it, a pack of small deltas, each making a large object, could make gigabytes.
42
- */
43
- const largeBytesMost = 8 * looseFileBytesMost;
44
- /**
45
- * What a receive holds before any object past a row: its entries, their objects read whole and
46
- * their rows, each within `bytes`, its reader's buffers, and a chunk filling, waiting and encoded.
47
- */
48
- const receiveFloorOf = (bytes) => 3 * bytes + 1048576 + 3 * chunkRawBytes;
38
+ /** A receive's memory caps and floor, scaled by `bytes` and `objects` so fixed buffers fit admission. */
39
+ const receiveCapsOf = (bytes, objects) => {
40
+ const full = baseLruBytes + pendingHeldMost + roundReadBytes + stageBytes;
41
+ const oneRow = limits.valueBytes;
42
+ const most = Math.min(bytes, Math.max(0, objects) * oneRow);
43
+ const scale = Math.min(3 * most, full) / full;
44
+ const lruBytes = Math.floor(baseLruBytes * scale);
45
+ const pendingHeld = Math.floor(pendingHeldMost * scale);
46
+ const roundBytes = Math.max(Math.floor(roundReadBytes * scale), oneRow);
47
+ const stagerBytes = Math.min(stageBytes, Math.max(Math.floor(stageBytes * scale), most, oneRow));
48
+ return {
49
+ lruBytes,
50
+ pendingHeld,
51
+ roundBytes,
52
+ stagerBytes,
53
+ inlineBytes: 3 * bytes < full ? stagerBytes >> 1 : fastPath.bytes,
54
+ floor: lruBytes + pendingHeld + roundBytes + stagerBytes + 1048576 + 3 * chunkRawBytes
55
+ };
56
+ };
49
57
  /** `limits` checked, each a whole number from 1 to `looseLimits`' own, or a `RangeError`. */
50
58
  const checkedLoose = (limits) => {
51
59
  const each = (kind) => {
@@ -81,29 +89,41 @@ const isLoose = (quarantine) => received.has(quarantine);
81
89
  * once its first chunk opens one. A receive that fails after it opened one abandons it.
82
90
  */
83
91
  const receiveRows = (store, listed, receive, limits, budget) => Effect.scoped(Effect.gen(function* () {
84
- const allotment = yield* budget.admit(receiveFloorOf(limits.bytes));
92
+ const caps = receiveCapsOf(limits.bytes, receive.objects);
93
+ const allotment = yield* budget.admit(caps.floor);
85
94
  const { repo } = listed;
86
95
  let opened;
96
+ let stager;
97
+ const ensureOpened = Effect.fnUntraced(function* () {
98
+ opened ??= yield* openBatch({
99
+ store,
100
+ repo,
101
+ at: yield* Clock.currentTimeMillis
102
+ });
103
+ return opened;
104
+ });
105
+ const staging = {
106
+ stager: Effect.fnUntraced(function* () {
107
+ stager ??= batchStager(store, repo, yield* ensureOpened(), caps.stagerBytes);
108
+ return stager;
109
+ }),
110
+ readStaged: readStagedRows(store, repo)
111
+ };
87
112
  const large = {
88
113
  fileBytes: limits.fileBytes,
89
- totalBytes: largeBytesMost,
90
114
  stage: Effect.fnUntraced(function* (part, index, bytes) {
91
- opened ??= yield* openBatch({
92
- store,
93
- repo,
94
- at: yield* Clock.currentTimeMillis
95
- });
96
- yield* stageChunk(store, repo, opened, part, index, bytes);
115
+ const batch = yield* ensureOpened();
116
+ yield* stageChunk(store, repo, batch, part, index, bytes);
97
117
  }),
98
118
  hold: (bytes) => allotment.grow(bytes),
99
119
  staged: (object) => Effect.map(new ChunkReader(store, repo, object.oid, rowOf(object).value, () => Effect.succeed(void 0)).whole(), ({ bytes }) => bytes),
100
120
  row: (object) => rowOf(object)
101
121
  };
102
122
  const rowOf = (object) => chunkedRow(object.oid, object.type, object.size, opened.batch, object.part);
103
- return yield* receivedRows(store, listed, receive, limits, large, () => opened).pipe(Effect.onError(() => opened === void 0 ? Effect.void : abandonBatch(store, repo, opened.batch)));
123
+ return yield* receivedRows(store, listed, receive, limits, caps, large, staging, () => opened).pipe(Effect.onError(() => opened === void 0 ? Effect.void : abandonBatch(store, repo, opened.batch)));
104
124
  }));
105
- /** `receiveRows`' receive, its batch `opened()` once its first chunk is staged. */
106
- const receivedRows = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, receive, limits, large, opened) {
125
+ /** `receiveRows`' receive, its batch `opened()` once staging or a chunk opens one. */
126
+ const receivedRows = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, receive, limits, caps, large, staging, opened) {
107
127
  const heldWhole = heldRows(store, listed);
108
128
  const unpacked = yield* unpackObjects({
109
129
  receive,
@@ -114,41 +134,46 @@ const receivedRows = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed,
114
134
  yield* large.hold(chunked.reduce((sum, { size }) => sum + size, 0));
115
135
  return yield* heldWhole(oids);
116
136
  }),
137
+ eachHeld: (oids, take) => eachHeldRow(store, listed, (_, size) => Effect.as(large.hold(size), true))(oids, take),
117
138
  headers: rowHeaders(store, listed),
118
139
  offsetDeltas: "resolve",
119
- large
140
+ large,
141
+ staging,
142
+ lruBytes: caps.lruBytes,
143
+ pendingHeld: caps.pendingHeld,
144
+ roundBytes: caps.roundBytes,
145
+ stageBytes: caps.inlineBytes
120
146
  });
121
- const staged = yield* rowsChange(store, listed.repo, unpacked.rows, unpacked.moved, opened());
147
+ const staged = streamedChange(opened(), unpacked.inlineRows, unpacked.own, unpacked.moved, yield* Clock.currentTimeMillis);
122
148
  readsOwnChunks(staged.change, (oid, chunked) => new ChunkReader(store, listed.repo, oid, chunked, () => Effect.succeed(void 0)));
123
149
  const quarantine = {
124
150
  id: newChangeId(),
125
151
  change: staged.change,
126
152
  bytes: unpacked.bytes,
127
153
  objects: unpacked.count,
128
- lfsPointers: yield* pointersOfObjects(unpacked.objects),
129
- ...largestOf([...unpacked.objects, ...unpacked.chunked])
154
+ lfsPointers: unpacked.lfsPointers,
155
+ ...unpacked.largest
130
156
  };
131
157
  if (unpacked.cut.length > 0) quarantine.cut = unpacked.cut;
132
158
  if (staged.quarantine !== void 0) quarantine.quarantine = staged.quarantine;
133
159
  received.add(quarantine);
134
- const whole = receive.partial === true || receive.boundary !== void 0 || unpacked.chunked.length > 0 ? void 0 : wholeRoots(unpacked.objects);
135
- if (whole === void 0) return quarantine;
136
- quarantine.roots = whole.roots;
137
- if (whole.outside.length > 64) return quarantine;
138
- const held = yield* rowHeaders(store, listed)(whole.outside);
139
- if (whole.outside.every((oid) => held.has(oid))) quarantine.linked = {
160
+ if (unpacked.roots === void 0) return quarantine;
161
+ quarantine.roots = unpacked.roots;
162
+ if (unpacked.outside === void 0 || unpacked.outside.length > 64) return quarantine;
163
+ const held = yield* rowHeaders(store, listed)(unpacked.outside);
164
+ if (unpacked.outside.every((oid) => held.has(oid))) quarantine.linked = {
140
165
  packs: [],
141
- rows: whole.outside
166
+ rows: unpacked.outside
142
167
  };
143
168
  return quarantine;
144
169
  });
145
170
  /**
146
- * What reading a chunked object of `size` bytes whole holds, allotted from `budget` before its
147
- * first chunk, and handed to `own` in the step the allot ends in: held until its allotment's
148
- * `release`, which no scope makes for it. The allot's scope is closed by its failure, so an
149
- * interrupt or a refusal leaves nothing allotted that no one owns.
171
+ * Allots `bytes` from `budget` before a chunked object's chunks are read, handing it to `own` in
172
+ * the step the allot ends in: held until its allotment's `release`, which no scope makes for it.
173
+ * The allot's scope is closed by its failure, so an interrupt or a refusal leaves nothing allotted
174
+ * that no one owns.
150
175
  */
151
- const chunkedCharge = (budget, size, own) => Effect.uninterruptibleMask((restore) => Effect.flatMap(Scope.make(), (scope) => restore(Scope.provide(scope)(budget.allot(chunkedReadBytes(size)))).pipe(Effect.onError(() => Scope.close(scope, Exit.void)), Effect.map((allotment) => {
176
+ const chunkedCharge = (budget, bytes, own) => Effect.uninterruptibleMask((restore) => Effect.flatMap(Scope$1.make(), (scope) => restore(Scope$1.provide(scope)(budget.allot(bytes))).pipe(Effect.onError(() => Scope$1.close(scope, Exit.void)), Effect.map((allotment) => {
152
177
  own(allotment);
153
178
  return allotment;
154
179
  }))));
@@ -158,7 +183,7 @@ const chunkedCharge = (budget, size, own) => Effect.uninterruptibleMask((restore
158
183
  */
159
184
  const readerCharges = (budget) => {
160
185
  const held = /* @__PURE__ */ new Set();
161
- const charge = (size) => chunkedCharge(budget, size, (allotment) => void held.add(allotment));
186
+ const charge = (size) => chunkedCharge(budget, size + chunkPageBytes, (allotment) => void held.add(allotment));
162
187
  const give = (allotment) => {
163
188
  held.delete(allotment);
164
189
  allotment.release();
@@ -174,47 +199,58 @@ const readerCharges = (budget) => {
174
199
  };
175
200
  };
176
201
  /**
177
- * `oid`'s object, or `undefined`. One kept as chunks is read whole once `budget` allots what that
178
- * holds, and handed on as its body, uncopied, its charge given back once the body is read to its
179
- * end or cancelled, as every caller does with a body it leaves: not at the reader's release, which
180
- * comes before a caller streams the body on.
202
+ * `oid`'s object, or `undefined`. One kept as chunks streams a page of `chunkReadMost` chunks at
203
+ * a time once `budget` allots `chunkPageBytes`, releasing that charge once the stream ends, fails,
204
+ * cancels, or `signal` aborts: not at the reader's release, which comes before a caller streams
205
+ * the body on (#2522).
181
206
  */
182
- const readObject = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, oid, budget) {
183
- const read = {};
184
- const before = (_, size) => Effect.as(chunkedCharge(budget, size, (allotment) => void (read.charged = allotment)), true);
185
- yield* eachHeldRow(store, listed, before)([oid], (object) => Effect.sync(() => void (read.object = object))).pipe(Effect.onError(() => Effect.sync(() => read.charged?.release())));
186
- const { object, charged } = read;
187
- if (object === void 0) return void 0;
188
- if (charged === void 0) return gitObjectOf(object);
189
- return {
190
- oid: object.oid,
191
- type: object.type,
192
- size: object.bytes.byteLength,
193
- bytes: streamThen(object.bytes, () => charged.release())
194
- };
207
+ const readObject = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, oid, budget, signal) {
208
+ const found = yield* rowAt(store, listed, oid);
209
+ if (found === void 0) return void 0;
210
+ if (found.kind === "whole") return gitObjectOf(found.object);
211
+ const count = yield* callScope;
212
+ let charged;
213
+ return yield* chunkedCharge(budget, chunkPageBytes, (allotment) => void (charged = allotment)).pipe(Effect.map((allotment) => {
214
+ const { type, size } = found.reader.chunked;
215
+ return {
216
+ oid,
217
+ type,
218
+ size,
219
+ bytes: chunkStream(found.reader, () => allotment.release(), signal, count)
220
+ };
221
+ }), Effect.onError(() => Effect.sync(() => charged?.release())));
195
222
  });
196
223
  /**
197
224
  * `before`, with each chunked object's bytes charged to `charges` first: given back if `before`
198
225
  * leaves it, and held, if it keeps it, until the reader's release.
199
226
  */
200
227
  const chargedFirst = (charges, before) => (oid, size) => Effect.flatMap(charges.charge(size), (allotment) => before(oid, size).pipe(Effect.tap((kept) => kept ? Effect.void : Effect.sync(() => charges.give(allotment))), Effect.onError(() => Effect.sync(() => charges.give(allotment)))));
228
+ const closeScope = (scope) => scope === void 0 ? Effect.void : Scope$1.close(scope, Exit.void);
201
229
  /**
202
- * A fetch's reads of `listed`'s rows. A chunked object is read whole, what that holds allotted
203
- * from `budget` before its first chunk: for a window, until the writer's next window or the fetch's
204
- * end, which `ended` gives back; for `each`, until its callback ends, so a walk past several holds
205
- * one at a time.
230
+ * A fetch's reads of `listed`'s rows. Objects past one row stream through `ranged` a page of
231
+ * `chunkReadMost` chunks at a time under a constant `chunkPageBytes` allotment, released when each
232
+ * object ends, on error, or via `ended`; `each` (for walk commits/trees/tags) holds one chunked
233
+ * object at a time until its callback ends (#2522).
206
234
  */
207
235
  const fetchReads = (calls, listed, budget) => {
208
236
  let window;
209
- const ended = Effect.suspend(() => {
237
+ let active;
238
+ const closeWindow = Effect.suspend(() => {
210
239
  const open = window;
211
240
  window = void 0;
212
- return open === void 0 ? Effect.void : Scope.close(open, Exit.void);
241
+ return closeScope(open);
213
242
  });
214
- const allotted = (scope) => (_, size) => Effect.as(Scope.provide(scope)(budget.allot(chunkedReadBytes(size))), true);
243
+ const closeActive = Effect.sync(() => {
244
+ const current = active;
245
+ active = void 0;
246
+ current?.reader.dropPage();
247
+ current?.allotment.release();
248
+ });
249
+ const ended = Effect.andThen(closeActive, closeWindow);
250
+ const allotted = (scope) => (_, size) => Effect.as(Scope$1.provide(scope)(budget.allot(size + chunkPageBytes)), true);
215
251
  const held = Effect.fnUntraced(function* (oids) {
216
- yield* ended;
217
- const scope = yield* Scope.make();
252
+ yield* closeWindow;
253
+ const scope = yield* Scope$1.make();
218
254
  window = scope;
219
255
  const objects = /* @__PURE__ */ new Map();
220
256
  yield* eachHeldRow(calls, listed, allotted(scope))(oids, (object) => Effect.sync(() => void objects.set(object.oid, object)));
@@ -225,30 +261,59 @@ const fetchReads = (calls, listed, budget) => {
225
261
  const closed = Effect.suspend(() => {
226
262
  const scope = open;
227
263
  open = void 0;
228
- return scope === void 0 ? Effect.void : Scope.close(scope, Exit.void);
264
+ return closeScope(scope);
229
265
  });
230
- const before = (oid, size) => Effect.flatMap(closed, () => Effect.flatMap(Scope.make(), (scope) => {
266
+ const before = (oid, size) => Effect.flatMap(closed, () => Effect.flatMap(Scope$1.make(), (scope) => {
231
267
  open = scope;
232
268
  return allotted(scope)(oid, size);
233
269
  }));
234
270
  return Effect.ensuring(eachHeldRow(calls, listed, before)(oids, (object) => Effect.ensuring(take(object), closed)), closed);
235
271
  };
272
+ const ranged = {
273
+ handles: ({ kind, size }) => !fitsRow(kind, size),
274
+ read: Effect.fnUntraced(function* (oid, at) {
275
+ let current = active;
276
+ if (current === void 0 || current.oid !== oid) {
277
+ yield* closeActive;
278
+ const found = yield* rowAt(calls, listed, oid);
279
+ if (found === void 0) return void 0;
280
+ if (found.kind === "whole") return found.object.bytes.slice(at, at + chunkRawBytes);
281
+ const allotment = yield* chunkedCharge(budget, chunkPageBytes, (charged) => void (active = {
282
+ oid,
283
+ reader: found.reader,
284
+ allotment: charged
285
+ }));
286
+ current = {
287
+ oid,
288
+ reader: found.reader,
289
+ allotment
290
+ };
291
+ }
292
+ const index = Math.floor(at / chunkRawBytes);
293
+ const inside = at - index * chunkRawBytes;
294
+ const chunk = yield* current.reader.chunkAt(index).pipe(Effect.onError(() => closeActive));
295
+ const out = inside === 0 ? chunk : chunk.slice(inside);
296
+ if (at + out.byteLength >= current.reader.chunked.size) yield* closeActive;
297
+ return out;
298
+ })
299
+ };
236
300
  return {
237
301
  reads: {
238
302
  held,
239
303
  each,
240
- sizes: rowSizes(calls, listed)
304
+ sizes: rowSizes(calls, listed),
305
+ ranged
241
306
  },
242
307
  ended
243
308
  };
244
309
  };
245
310
  /**
246
311
  * `loose()`: each object a row of the repo's scope, with no bucket. A push of more than
247
- * `options.objects` objects, 10,000 by default, is refused whole, and so is one whose rows pass
248
- * `options.bytes`, one commit's 8 MiB by default, of rows within one row's 1 MiB. An object past
249
- * one row is kept as chunk rows, to `options.fileBytes`, 32 MiB by default, and one past that is
250
- * refused as `object-too-large`. A whole push names its roots and the rows it links to, so it can
251
- * keep a repo's whole-clone mark. The client's default.
312
+ * `options.objects` objects, 50,000 by default, is refused whole, and so is one whose pack passes
313
+ * `options.bytes`, 64 MiB on the wire by default, before inflation. An object past one row is kept
314
+ * as chunk rows, to `options.fileBytes`, 32 MiB by default, and one past that is refused as
315
+ * `object-too-large`. A whole inline push names its roots and the rows it links to, so it can keep
316
+ * a repo's whole-clone mark. The client's default.
252
317
  */
253
318
  const loose = (options = {}) => {
254
319
  const limits = checkedLoose(options);
@@ -274,7 +339,7 @@ const loose = (options = {}) => {
274
339
  allotment: allotmentWithin,
275
340
  release: () => {}
276
341
  } : {
277
- object: (oid) => readObject(calls, listed, oid, budget),
342
+ object: (oid, signal) => readObject(calls, listed, oid, budget, signal),
278
343
  sizes: rowSizes(calls, listed),
279
344
  headers: rowHeaders(calls, listed),
280
345
  has: (oids) => Effect.map(rowHeaders(calls, listed)(oids), (headers) => new Set(headers.keys())),
@@ -284,7 +349,7 @@ const loose = (options = {}) => {
284
349
  release: charges.release
285
350
  }, scope);
286
351
  };
287
- return {
352
+ const objects = {
288
353
  reader: (listed, input) => Effect.map(callScope, (scope) => openReader(listed, scope, input?.listedOnly)),
289
354
  pushedCommits: (_, input) => pushedCommitsPage(void 0, input),
290
355
  receive: (listed, input) => cancelsBody(input.pack, receiveRows(calls, listed, input, limits, budget)),
@@ -298,7 +363,8 @@ const loose = (options = {}) => {
298
363
  readyShallow: false,
299
364
  pushObjectsMost: limits.objects
300
365
  };
366
+ return withMemoryBudget(objects, budget);
301
367
  }
302
368
  };
303
369
  };
304
- export { isLoose, loose, looseFileBytesMost, looseLimits, looseObjectsMost };
370
+ export { isLoose, loose, looseBytesMost, looseFileBytesMost, looseLimits, looseObjectsMost };