@ref0/git 0.3.0 → 0.4.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 (607) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +12 -0
  2. package/dist/access/private-refs.d.mts +12 -9
  3. package/dist/access/private-refs.mjs +69 -46
  4. package/dist/auth/access-jwt.mjs +7 -7
  5. package/dist/auth/auth.d.mts +41 -0
  6. package/dist/auth/auth.mjs +39 -0
  7. package/dist/auth/authorize.mjs +57 -80
  8. package/dist/auth/bridge.mjs +30 -0
  9. package/dist/auth/fences.d.mts +22 -2
  10. package/dist/auth/fences.mjs +3 -3
  11. package/dist/auth/grants.d.mts +25 -0
  12. package/dist/auth/grants.mjs +29 -34
  13. package/dist/auth/helpers.mjs +4 -4
  14. package/dist/auth/host-function.d.mts +9 -2
  15. package/dist/auth/host-function.mjs +35 -8
  16. package/dist/auth/identify.d.mts +3 -0
  17. package/dist/auth/identify.mjs +9 -11
  18. package/dist/auth/namespaces.d.mts +3 -0
  19. package/dist/auth/policy.d.mts +57 -0
  20. package/dist/auth/policy.mjs +56 -0
  21. package/dist/auth/token-rows.mjs +6 -6
  22. package/dist/auth/token-text.mjs +16 -4
  23. package/dist/auth/tokens.d.mts +3 -0
  24. package/dist/auth/tokens.mjs +51 -13
  25. package/dist/auth.d.mts +2 -1
  26. package/dist/auth.mjs +2 -1
  27. package/dist/client/answer.mjs +49 -11
  28. package/dist/client/client.d.mts +2 -2
  29. package/dist/client/client.mjs +3 -3
  30. package/dist/client/git-http.d.mts +6 -0
  31. package/dist/client/git-http.mjs +23 -36
  32. package/dist/client/helper-node.d.mts +12 -0
  33. package/dist/client/helper-node.mjs +108 -5
  34. package/dist/client/local.mjs +94 -99
  35. package/dist/client/negotiate.mjs +10 -8
  36. package/dist/client/push-upload.d.mts +14 -0
  37. package/dist/client/push-upload.mjs +12 -12
  38. package/dist/client/remote-helper.mjs +22 -20
  39. package/dist/client/remote.mjs +28 -22
  40. package/dist/client/run-remote-helper.d.mts +40 -16
  41. package/dist/client/run-remote-helper.mjs +147 -154
  42. package/dist/client/scrub.d.mts +8 -2
  43. package/dist/client/scrub.mjs +76 -4
  44. package/dist/client/slice-push.d.mts +77 -0
  45. package/dist/client/slice-push.mjs +169 -0
  46. package/dist/client/slice-report.mjs +188 -0
  47. package/dist/client/slices.d.mts +44 -0
  48. package/dist/client/slices.mjs +131 -0
  49. package/dist/client/transport.d.mts +1 -0
  50. package/dist/client/transport.mjs +30 -26
  51. package/dist/contracts/access.d.mts +36 -9
  52. package/dist/contracts/actors.d.mts +28 -10
  53. package/dist/contracts/actors.mjs +17 -0
  54. package/dist/contracts/authorize.d.mts +77 -0
  55. package/dist/contracts/authorize.mjs +25 -0
  56. package/dist/contracts/blobs.d.mts +48 -15
  57. package/dist/contracts/blobs.mjs +30 -0
  58. package/dist/contracts/calls-spent.d.mts +1 -0
  59. package/dist/contracts/calls-spent.mjs +58 -18
  60. package/dist/contracts/client.d.mts +14 -16
  61. package/dist/contracts/commits.d.mts +558 -76
  62. package/dist/contracts/commits.mjs +147 -0
  63. package/dist/contracts/engine.d.mts +91 -55
  64. package/dist/contracts/engine.mjs +103 -0
  65. package/dist/contracts/events.d.mts +1382 -205
  66. package/dist/contracts/events.mjs +485 -0
  67. package/dist/contracts/files.d.mts +295 -50
  68. package/dist/contracts/files.mjs +100 -0
  69. package/dist/contracts/forks.d.mts +306 -25
  70. package/dist/contracts/forks.mjs +39 -0
  71. package/dist/contracts/git.d.mts +107 -0
  72. package/dist/contracts/git.mjs +23 -0
  73. package/dist/contracts/grants.d.mts +2 -2
  74. package/dist/contracts/ids.d.mts +23 -8
  75. package/dist/contracts/ids.mjs +40 -5
  76. package/dist/contracts/lfs.d.mts +9 -4
  77. package/dist/contracts/merges.d.mts +68 -16
  78. package/dist/contracts/merges.mjs +27 -0
  79. package/dist/contracts/namespaces.d.mts +14 -0
  80. package/dist/contracts/object-values.d.mts +96 -0
  81. package/dist/contracts/object-values.mjs +104 -0
  82. package/dist/contracts/objects.d.mts +323 -87
  83. package/dist/contracts/operations.d.mts +24 -16
  84. package/dist/contracts/promises.d.mts +13 -2
  85. package/dist/contracts/push-uploads.d.mts +39 -24
  86. package/dist/contracts/push-uploads.mjs +54 -0
  87. package/dist/contracts/queue.d.mts +444 -139
  88. package/dist/contracts/queue.mjs +197 -0
  89. package/dist/contracts/refs.d.mts +248 -45
  90. package/dist/contracts/refs.mjs +117 -0
  91. package/dist/contracts/repo-records.d.mts +34 -0
  92. package/dist/contracts/repo-records.mjs +18 -0
  93. package/dist/contracts/repos.d.mts +411 -58
  94. package/dist/contracts/repos.mjs +136 -0
  95. package/dist/contracts/result.d.mts +335 -69
  96. package/dist/contracts/result.mjs +350 -5
  97. package/dist/contracts/rules.d.mts +60 -48
  98. package/dist/contracts/rules.mjs +9 -0
  99. package/dist/contracts/server.d.mts +113 -47
  100. package/dist/contracts/services.d.mts +15 -24
  101. package/dist/contracts/services.mjs +5 -9
  102. package/dist/contracts/signin.d.mts +64 -31
  103. package/dist/contracts/signin.mjs +18 -0
  104. package/dist/contracts/store.d.mts +45 -5
  105. package/dist/contracts/store.mjs +31 -0
  106. package/dist/contracts/sync.d.mts +81 -46
  107. package/dist/contracts/sync.mjs +41 -2
  108. package/dist/contracts/tags.d.mts +204 -22
  109. package/dist/contracts/tags.mjs +51 -1
  110. package/dist/contracts/tokens.d.mts +32 -7
  111. package/dist/contracts/tokens.mjs +31 -1
  112. package/dist/contracts/topics.d.mts +123 -67
  113. package/dist/contracts/topics.mjs +109 -0
  114. package/dist/contracts/trees.d.mts +132 -52
  115. package/dist/contracts/trees.mjs +105 -0
  116. package/dist/contracts/work.d.mts +127 -20
  117. package/dist/contracts/work.mjs +69 -0
  118. package/dist/core/access.d.mts +25 -14
  119. package/dist/core/access.mjs +77 -108
  120. package/dist/core/ancestry.mjs +86 -18
  121. package/dist/core/call-names.mjs +1 -0
  122. package/dist/core/call-services.mjs +73 -0
  123. package/dist/core/changes.d.mts +31 -0
  124. package/dist/core/changes.mjs +5 -0
  125. package/dist/core/clock.mjs +3 -3
  126. package/dist/core/events/deliver.mjs +119 -33
  127. package/dist/core/events/seen.mjs +124 -0
  128. package/dist/core/forks.mjs +371 -159
  129. package/dist/core/hooks/order.d.mts +9 -0
  130. package/dist/core/hooks/order.mjs +25 -0
  131. package/dist/core/hooks/post-receive.mjs +13 -12
  132. package/dist/core/hooks/pre-receive.d.mts +8 -1
  133. package/dist/core/hooks/pre-receive.mjs +8 -6
  134. package/dist/core/imports.mjs +212 -0
  135. package/dist/core/index-job.mjs +131 -38
  136. package/dist/core/merge-parts.d.mts +30 -0
  137. package/dist/core/merge-parts.mjs +31 -0
  138. package/dist/core/names.mjs +4 -16
  139. package/dist/core/namespaces.d.mts +2 -0
  140. package/dist/core/objects/blobs.mjs +4 -4
  141. package/dist/core/objects/commit-writes.mjs +19 -17
  142. package/dist/core/objects/commits.mjs +12 -12
  143. package/dist/core/objects/files.mjs +10 -11
  144. package/dist/core/objects/lines.mjs +15 -32
  145. package/dist/core/objects/merges.mjs +4 -4
  146. package/dist/core/objects/objects-layer.d.mts +21 -0
  147. package/dist/core/objects/objects-layer.mjs +47 -0
  148. package/dist/core/objects/objects-namespace.d.mts +6 -0
  149. package/dist/core/objects/objects-namespace.mjs +13 -0
  150. package/dist/core/objects/objects.d.mts +49 -0
  151. package/dist/core/objects/objects.mjs +18 -0
  152. package/dist/core/objects/peel.mjs +3 -3
  153. package/dist/core/objects/reading.mjs +135 -40
  154. package/dist/core/objects/tags.mjs +7 -7
  155. package/dist/core/objects/tree-edits.mjs +40 -27
  156. package/dist/core/objects/trees.mjs +23 -18
  157. package/dist/core/objects/writing.mjs +43 -44
  158. package/dist/core/own-writes.mjs +3 -3
  159. package/dist/core/parts.d.mts +125 -0
  160. package/dist/core/parts.mjs +59 -0
  161. package/dist/core/promise.mjs +13 -9
  162. package/dist/core/publish.mjs +27 -17
  163. package/dist/core/purge.mjs +242 -0
  164. package/dist/core/push-decide.mjs +93 -28
  165. package/dist/core/push.mjs +300 -156
  166. package/dist/core/receipts.d.mts +4 -3
  167. package/dist/core/receipts.mjs +20 -12
  168. package/dist/core/ref-conflicts.mjs +70 -4
  169. package/dist/core/ref-index-job.mjs +181 -0
  170. package/dist/core/ref-index.d.mts +25 -0
  171. package/dist/core/ref-index.mjs +136 -0
  172. package/dist/core/ref-view.mjs +166 -0
  173. package/dist/core/refs.mjs +313 -95
  174. package/dist/core/repack.d.mts +10 -0
  175. package/dist/core/repack.mjs +261 -81
  176. package/dist/core/repo-info.mjs +99 -0
  177. package/dist/core/repos.mjs +114 -80
  178. package/dist/core/rules/changes.mjs +48 -20
  179. package/dist/core/rules/check.mjs +29 -22
  180. package/dist/core/rules/commit-changes.d.mts +13 -0
  181. package/dist/core/rules/commit-changes.mjs +100 -91
  182. package/dist/core/rules/context.d.mts +67 -8
  183. package/dist/core/rules/context.mjs +88 -51
  184. package/dist/core/rules/facts.mjs +1 -1
  185. package/dist/core/rules/fetch.mjs +24 -26
  186. package/dist/core/rules/files.d.mts +13 -0
  187. package/dist/core/rules/files.mjs +27 -28
  188. package/dist/core/rules/namespace.d.mts +2 -0
  189. package/dist/core/rules/patterns.mjs +29 -5
  190. package/dist/core/rules/protect.d.mts +12 -6
  191. package/dist/core/rules/protect.mjs +22 -20
  192. package/dist/core/rules/rules-layer.d.mts +17 -0
  193. package/dist/core/rules/rules-layer.mjs +26 -0
  194. package/dist/core/rules/rules.d.mts +8 -0
  195. package/dist/core/rules/rules.mjs +16 -0
  196. package/dist/core/rules/service.mjs +18 -0
  197. package/dist/core/seam.d.mts +8 -5
  198. package/dist/core/seam.mjs +19 -15
  199. package/dist/core/tokens.mjs +29 -23
  200. package/dist/core/view.d.mts +105 -6
  201. package/dist/core/view.mjs +211 -109
  202. package/dist/core/work.mjs +40 -14
  203. package/dist/effect.d.mts +3 -4
  204. package/dist/effect.mjs +2 -3
  205. package/dist/engine/allotted-xdiff.d.mts +1 -0
  206. package/dist/engine/allotted-xdiff.mjs +1 -1
  207. package/dist/engine/attributes.mjs +1 -1
  208. package/dist/engine/combined.d.mts +18 -0
  209. package/dist/engine/combined.mjs +39 -44
  210. package/dist/engine/commits.mjs +5 -4
  211. package/dist/engine/content.d.mts +3 -2
  212. package/dist/engine/content.mjs +2 -2
  213. package/dist/engine/failures.d.mts +2 -2
  214. package/dist/engine/failures.mjs +2 -9
  215. package/dist/engine/merge-base-walk.d.mts +3 -2
  216. package/dist/engine/merge-base-walk.mjs +1 -1
  217. package/dist/engine/merge-bases.mjs +3 -2
  218. package/dist/engine/merge.mjs +568 -566
  219. package/dist/engine/parts.d.mts +3 -2
  220. package/dist/engine/parts.mjs +40 -7
  221. package/dist/engine/reads.d.mts +1 -0
  222. package/dist/engine/reads.mjs +5 -5
  223. package/dist/engine/walk.mjs +23 -24
  224. package/dist/engine/xdiff.d.mts +2 -33
  225. package/dist/engine/xdiff.mjs +6 -3
  226. package/dist/event-streams/event-streams.d.mts +25 -0
  227. package/dist/event-streams/event-streams.mjs +22 -0
  228. package/dist/event-streams/namespace.d.mts +2 -0
  229. package/dist/event-streams/stream.d.mts +42 -0
  230. package/dist/{core/events → event-streams}/stream.mjs +106 -49
  231. package/dist/extend.d.mts +4 -2
  232. package/dist/http/answers.mjs +8 -4
  233. package/dist/http/bodies.mjs +84 -56
  234. package/dist/http/core-parts.mjs +206 -60
  235. package/dist/http/handler.d.mts +2 -0
  236. package/dist/http/handler.mjs +17 -11
  237. package/dist/http/node.mjs +10 -6
  238. package/dist/http/parts.d.mts +12 -0
  239. package/dist/http/push-uploads.d.mts +9 -0
  240. package/dist/http/push-uploads.mjs +76 -66
  241. package/dist/http/receive-pack.mjs +162 -28
  242. package/dist/http/upload-pack.mjs +106 -81
  243. package/dist/index.d.mts +48 -28
  244. package/dist/index.mjs +29 -7
  245. package/dist/lfs/calls.mjs +2 -2
  246. package/dist/lfs/locks.mjs +24 -20
  247. package/dist/lfs/objects.d.mts +7 -0
  248. package/dist/lfs/objects.mjs +31 -26
  249. package/dist/lfs/pointers.mjs +7 -7
  250. package/dist/lfs/purge.mjs +50 -0
  251. package/dist/lfs/repo.mjs +5 -5
  252. package/dist/lfs/rows.mjs +8 -8
  253. package/dist/lfs/service.d.mts +9 -0
  254. package/dist/lfs/service.mjs +32 -25
  255. package/dist/lfs/upkeep.mjs +5 -5
  256. package/dist/lfs/wire.mjs +80 -38
  257. package/dist/merges/merges.d.mts +20 -0
  258. package/dist/merges/merges.mjs +32 -0
  259. package/dist/merges/namespace.d.mts +2 -0
  260. package/dist/merges/public.d.mts +6 -0
  261. package/dist/merges/public.mjs +10 -0
  262. package/dist/node.d.mts +1 -2
  263. package/dist/node.mjs +1 -3
  264. package/dist/protocol/bytes/buffers.d.mts +9 -3
  265. package/dist/protocol/bytes/buffers.mjs +11 -5
  266. package/dist/protocol/bytes/deflate.d.mts +7 -5
  267. package/dist/protocol/bytes/deflate.mjs +59 -23
  268. package/dist/protocol/bytes/inflate.d.mts +4 -3
  269. package/dist/protocol/bytes/inflate.mjs +61 -26
  270. package/dist/protocol/bytes/reader.mjs +61 -0
  271. package/dist/protocol/bytes/sha1-hasher.d.mts +3 -1
  272. package/dist/protocol/bytes/sha1-hasher.mjs +13 -3
  273. package/dist/protocol/bytes/sha1.d.mts +1 -1
  274. package/dist/protocol/bytes/sha1.mjs +5 -5
  275. package/dist/protocol/bytes/streams.mjs +16 -6
  276. package/dist/protocol/diff/patch.d.mts +4 -0
  277. package/dist/protocol/diff/patch.mjs +1 -1
  278. package/dist/protocol/diff/paths.mjs +1 -1
  279. package/dist/protocol/diff/read.d.mts +1 -1
  280. package/dist/protocol/diff/read.mjs +102 -90
  281. package/dist/protocol/framing/pkt-line.d.mts +1 -0
  282. package/dist/protocol/framing/pkt-line.mjs +40 -6
  283. package/dist/protocol/objects/checked-blobs.d.mts +1 -0
  284. package/dist/protocol/objects/fsck.mjs +7 -1
  285. package/dist/protocol/objects/held.mjs +5 -11
  286. package/dist/protocol/objects/ident.mjs +1 -1
  287. package/dist/protocol/objects/object-rules.mjs +15 -7
  288. package/dist/protocol/objects/object.d.mts +6 -2
  289. package/dist/protocol/objects/object.mjs +5 -2
  290. package/dist/protocol/objects/tag.d.mts +3 -1
  291. package/dist/protocol/objects/tag.mjs +27 -1
  292. package/dist/protocol/objects/tree.mjs +1 -1
  293. package/dist/protocol/packs/delta.d.mts +1 -1
  294. package/dist/protocol/packs/delta.mjs +2 -2
  295. package/dist/protocol/packs/graph.mjs +55 -56
  296. package/dist/protocol/packs/idx.d.mts +4 -2
  297. package/dist/protocol/packs/idx.mjs +156 -63
  298. package/dist/protocol/packs/indexer.d.mts +22 -4
  299. package/dist/protocol/packs/indexer.mjs +14 -35
  300. package/dist/protocol/packs/parts.mjs +5 -5
  301. package/dist/protocol/packs/pos.mjs +12 -5
  302. package/dist/protocol/packs/reader.d.mts +19 -12
  303. package/dist/protocol/packs/reader.mjs +252 -25
  304. package/dist/protocol/packs/rev.d.mts +1 -1
  305. package/dist/protocol/packs/rev.mjs +42 -24
  306. package/dist/protocol/packs/types-file.mjs +85 -0
  307. package/dist/protocol/packs/write-error.d.mts +1 -1
  308. package/dist/protocol/packs/write-error.mjs +2 -2
  309. package/dist/protocol/packs/writer.d.mts +40 -15
  310. package/dist/protocol/packs/writer.mjs +142 -49
  311. package/dist/protocol/wire/advertisement.d.mts +39 -14
  312. package/dist/protocol/wire/advertisement.mjs +127 -31
  313. package/dist/protocol/wire/fetch.d.mts +57 -19
  314. package/dist/protocol/wire/fetch.mjs +57 -26
  315. package/dist/protocol/wire/json.mjs +25 -0
  316. package/dist/protocol/wire/lines.d.mts +10 -0
  317. package/dist/protocol/wire/lines.mjs +20 -6
  318. package/dist/protocol/wire/push-limits.d.mts +6 -0
  319. package/dist/protocol/wire/push-limits.mjs +88 -0
  320. package/dist/protocol/wire/push-uploads.mjs +3 -28
  321. package/dist/protocol/wire/receive-pack.d.mts +30 -14
  322. package/dist/protocol/wire/receive-pack.mjs +29 -2
  323. package/dist/protocol/wire/report-status.d.mts +30 -11
  324. package/dist/protocol/wire/report-status.mjs +21 -2
  325. package/dist/protocol/wire/v2.d.mts +56 -29
  326. package/dist/protocol/wire/v2.mjs +91 -16
  327. package/dist/protocol.d.mts +4 -3
  328. package/dist/protocol.mjs +7 -6
  329. package/dist/queue/advance.mjs +189 -120
  330. package/dist/queue/callers.mjs +12 -9
  331. package/dist/queue/calls.mjs +311 -155
  332. package/dist/queue/commit.mjs +70 -26
  333. package/dist/queue/host.d.mts +39 -12
  334. package/dist/queue/host.mjs +36 -38
  335. package/dist/queue/lanes.mjs +1 -1
  336. package/dist/queue/layer.d.mts +14 -0
  337. package/dist/queue/layer.mjs +55 -0
  338. package/dist/queue/limits.mjs +13 -2
  339. package/dist/queue/namespace.d.mts +2 -0
  340. package/dist/queue/pages.mjs +1 -1
  341. package/dist/queue/public.d.mts +6 -0
  342. package/dist/queue/public.mjs +21 -0
  343. package/dist/queue/push-option.mjs +49 -30
  344. package/dist/queue/rows.mjs +24 -16
  345. package/dist/queue/schedule.mjs +22 -22
  346. package/dist/queue/search.mjs +8 -7
  347. package/dist/queue/state.mjs +49 -13
  348. package/dist/queue/steps.mjs +6 -3
  349. package/dist/remote-helper.d.mts +5 -2
  350. package/dist/remote-helper.mjs +5 -2
  351. package/dist/rest/api.d.mts +1 -1
  352. package/dist/rest/blobs.d.mts +790 -23
  353. package/dist/rest/blobs.mjs +4 -4
  354. package/dist/rest/caller.d.mts +4163 -36
  355. package/dist/rest/caller.mjs +2 -2
  356. package/dist/rest/client.mjs +80 -70
  357. package/dist/rest/commits.d.mts +3315 -244
  358. package/dist/rest/commits.mjs +18 -64
  359. package/dist/rest/errors.d.mts +2082 -22
  360. package/dist/rest/errors.mjs +46 -89
  361. package/dist/rest/events.d.mts +394 -11
  362. package/dist/rest/events.mjs +13 -9
  363. package/dist/rest/files.d.mts +1265 -114
  364. package/dist/rest/files.mjs +11 -42
  365. package/dist/rest/forks.d.mts +2005 -62
  366. package/dist/rest/forks.mjs +10 -13
  367. package/dist/rest/handler.d.mts +3 -0
  368. package/dist/rest/handler.mjs +22 -14
  369. package/dist/rest/handlers.mjs +53 -60
  370. package/dist/rest/listen.d.mts +5 -8
  371. package/dist/rest/listen.mjs +23 -29
  372. package/dist/rest/me.d.mts +393 -10
  373. package/dist/rest/me.mjs +2 -2
  374. package/dist/rest/merges.d.mts +399 -16
  375. package/dist/rest/merges.mjs +3 -17
  376. package/dist/rest/paths.mjs +1 -0
  377. package/dist/rest/queue.d.mts +5615 -240
  378. package/dist/rest/queue.mjs +15 -130
  379. package/dist/rest/refs.d.mts +2859 -132
  380. package/dist/rest/refs.mjs +19 -39
  381. package/dist/rest/repos.d.mts +2421 -93
  382. package/dist/rest/repos.mjs +10 -33
  383. package/dist/rest/tags.d.mts +1205 -54
  384. package/dist/rest/tags.mjs +6 -34
  385. package/dist/rest/tokens.d.mts +2369 -66
  386. package/dist/rest/tokens.mjs +7 -4
  387. package/dist/rest/topics.d.mts +2060 -113
  388. package/dist/rest/topics.mjs +23 -71
  389. package/dist/rest/trees.d.mts +1610 -75
  390. package/dist/rest/trees.mjs +16 -57
  391. package/dist/rest/wire.d.mts +402 -0
  392. package/dist/rest/wire.mjs +32 -46
  393. package/dist/rest/work.d.mts +1204 -63
  394. package/dist/rest/work.mjs +7 -51
  395. package/dist/rest.d.mts +3 -3
  396. package/dist/server/extension.d.mts +6 -2
  397. package/dist/server/extension.mjs +54 -30
  398. package/dist/server/git-layer.d.mts +23 -0
  399. package/dist/server/git-layer.mjs +107 -0
  400. package/dist/server/git-namespace.d.mts +6 -0
  401. package/dist/server/git-namespace.mjs +15 -0
  402. package/dist/server/lifecycle.d.mts +1 -2
  403. package/dist/server/lifecycle.mjs +8 -15
  404. package/dist/server/namespaces.d.mts +2 -0
  405. package/dist/server/registry.d.mts +9 -0
  406. package/dist/server/registry.mjs +167 -0
  407. package/dist/server/route-match.mjs +88 -0
  408. package/dist/server/routes.d.mts +12 -8
  409. package/dist/server/routes.mjs +27 -18
  410. package/dist/server/server.d.mts +19 -0
  411. package/dist/server/server.mjs +281 -198
  412. package/dist/signin/codes.mjs +9 -6
  413. package/dist/signin/context.d.mts +1 -0
  414. package/dist/signin/context.mjs +4 -4
  415. package/dist/signin/device.mjs +8 -8
  416. package/dist/signin/forms.mjs +11 -29
  417. package/dist/signin/grants.d.mts +4 -2
  418. package/dist/signin/grants.mjs +20 -19
  419. package/dist/signin/route.mjs +2 -2
  420. package/dist/signin/web.mjs +7 -7
  421. package/dist/signin/wire.mjs +6 -6
  422. package/dist/storage/budget.mjs +51 -18
  423. package/dist/storage/calls.d.mts +22 -4
  424. package/dist/storage/calls.mjs +347 -110
  425. package/dist/storage/clean-up.mjs +80 -35
  426. package/dist/storage/counted-bucket.mjs +115 -0
  427. package/dist/storage/fetch.d.mts +2 -0
  428. package/dist/storage/fetch.mjs +243 -100
  429. package/dist/storage/fsck.mjs +56 -7
  430. package/dist/storage/held-types.d.mts +7 -0
  431. package/dist/storage/held-types.mjs +263 -0
  432. package/dist/storage/host-bucket.mjs +28 -0
  433. package/dist/storage/id-mix.d.mts +1 -0
  434. package/dist/storage/id-mix.mjs +55 -0
  435. package/dist/storage/index-bitmaps.d.mts +2 -1
  436. package/dist/storage/index-bitmaps.mjs +233 -101
  437. package/dist/storage/index-build.d.mts +7 -3
  438. package/dist/storage/index-build.mjs +650 -164
  439. package/dist/storage/index-fetch.d.mts +3 -1
  440. package/dist/storage/index-fetch.mjs +297 -195
  441. package/dist/storage/index-files.mjs +25 -27
  442. package/dist/storage/index-graph.d.mts +2 -1
  443. package/dist/storage/index-graph.mjs +127 -91
  444. package/dist/storage/index-layers.d.mts +11 -0
  445. package/dist/storage/index-layers.mjs +258 -78
  446. package/dist/storage/index-reach.mjs +181 -75
  447. package/dist/storage/index-remap.mjs +74 -32
  448. package/dist/storage/index-shallow.mjs +311 -0
  449. package/dist/storage/index-visible.mjs +168 -0
  450. package/dist/storage/layout.d.mts +1 -0
  451. package/dist/storage/layout.mjs +39 -8
  452. package/dist/storage/lfs-pointers.d.mts +3 -1
  453. package/dist/storage/lfs-pointers.mjs +25 -9
  454. package/dist/storage/link-join.d.mts +4 -0
  455. package/dist/storage/link-join.mjs +50 -12
  456. package/dist/storage/links.mjs +89 -4
  457. package/dist/storage/listed-ids.mjs +10 -0
  458. package/dist/storage/loose.d.mts +11 -4
  459. package/dist/storage/loose.mjs +102 -69
  460. package/dist/storage/memory-budget.d.mts +5 -0
  461. package/dist/storage/memory-budget.mjs +530 -102
  462. package/dist/storage/merge-choose.mjs +258 -0
  463. package/dist/storage/merge-cut.mjs +47 -0
  464. package/dist/storage/merge-fence.mjs +89 -0
  465. package/dist/storage/merge-index.mjs +347 -0
  466. package/dist/storage/merge-most.mjs +202 -0
  467. package/dist/storage/merge-plan.mjs +171 -0
  468. package/dist/storage/merge-row.mjs +258 -0
  469. package/dist/storage/merge-stream.mjs +497 -0
  470. package/dist/storage/merge-walk.mjs +199 -0
  471. package/dist/storage/merge-write.mjs +129 -0
  472. package/dist/storage/merge.d.mts +10 -0
  473. package/dist/storage/merge.mjs +82 -306
  474. package/dist/storage/object-rows.d.mts +4 -2
  475. package/dist/storage/object-rows.mjs +101 -17
  476. package/dist/storage/pack-order.d.mts +1 -1
  477. package/dist/storage/pack-order.mjs +69 -54
  478. package/dist/storage/pack-ranges.d.mts +1 -1
  479. package/dist/storage/pack-ranges.mjs +396 -60
  480. package/dist/storage/pack-reads.d.mts +6 -2
  481. package/dist/storage/pack-reads.mjs +598 -126
  482. package/dist/storage/pack-receive.d.mts +5 -0
  483. package/dist/storage/pack-receive.mjs +820 -237
  484. package/dist/storage/packs-memory.d.mts +25 -0
  485. package/dist/storage/packs-memory.mjs +49 -0
  486. package/dist/storage/packs.d.mts +7 -5
  487. package/dist/storage/packs.mjs +554 -213
  488. package/dist/storage/placed-reads.mjs +205 -0
  489. package/dist/storage/promise-calls.mjs +29 -0
  490. package/dist/storage/prune-keep.mjs +164 -0
  491. package/dist/storage/prune-walk.mjs +578 -0
  492. package/dist/storage/prune.mjs +739 -332
  493. package/dist/storage/push-allotment.mjs +3 -3
  494. package/dist/storage/push-uploads.mjs +22 -13
  495. package/dist/storage/pushed-commits.mjs +8 -9
  496. package/dist/storage/quarantine.d.mts +10 -0
  497. package/dist/storage/quarantine.mjs +28 -25
  498. package/dist/storage/range-cache.mjs +71 -0
  499. package/dist/storage/raw-ids.mjs +20 -1
  500. package/dist/storage/ready.d.mts +4 -2
  501. package/dist/storage/ready.mjs +109 -48
  502. package/dist/storage/receive-admission.mjs +67 -0
  503. package/dist/storage/receive-bounds.d.mts +1 -0
  504. package/dist/storage/receive-bounds.mjs +202 -0
  505. package/dist/storage/receive-files.mjs +248 -0
  506. package/dist/storage/receive-links.mjs +281 -244
  507. package/dist/storage/receive-state.d.mts +9 -0
  508. package/dist/storage/receive-state.mjs +150 -0
  509. package/dist/storage/receive-steps.mjs +344 -0
  510. package/dist/storage/receive-sweep.mjs +160 -0
  511. package/dist/storage/receive-table.d.mts +3 -0
  512. package/dist/storage/receive-table.mjs +197 -0
  513. package/dist/storage/repack-backlog.mjs +70 -0
  514. package/dist/storage/repack-contained.mjs +269 -0
  515. package/dist/storage/repack-job.d.mts +3 -0
  516. package/dist/storage/repack-job.mjs +24 -7
  517. package/dist/storage/repack.d.mts +4 -4
  518. package/dist/storage/repack.mjs +156 -77
  519. package/dist/storage/roots.mjs +23 -7
  520. package/dist/storage/rows.d.mts +4 -2
  521. package/dist/storage/rows.mjs +40 -7
  522. package/dist/storage/runs.d.mts +8 -0
  523. package/dist/storage/runs.mjs +731 -0
  524. package/dist/storage/send-list.d.mts +2 -1
  525. package/dist/storage/send-list.mjs +261 -76
  526. package/dist/storage/shallow.d.mts +3 -2
  527. package/dist/storage/shallow.mjs +7 -7
  528. package/dist/storage/single-flight.mjs +47 -0
  529. package/dist/storage/stream-whole.mjs +121 -54
  530. package/dist/storage/swap-walk.mjs +188 -0
  531. package/dist/storage/unpack.mjs +52 -23
  532. package/dist/storage/visible.mjs +58 -39
  533. package/dist/storage/walk.d.mts +2 -0
  534. package/dist/storage/walk.mjs +20 -7
  535. package/dist/storage/wants.mjs +185 -33
  536. package/dist/storage/written-bases.mjs +172 -0
  537. package/dist/store/call-count.d.mts +69 -4
  538. package/dist/store/call-count.mjs +193 -51
  539. package/dist/store/catalogue.d.mts +17 -3
  540. package/dist/store/catalogue.mjs +135 -48
  541. package/dist/store/crossing.mjs +2 -4
  542. package/dist/store/cursor-seal.d.mts +12 -1
  543. package/dist/store/cursor-seal.mjs +7 -6
  544. package/dist/store/errors.d.mts +2 -2
  545. package/dist/store/errors.mjs +112 -24
  546. package/dist/store/git-store.mjs +21 -2
  547. package/dist/store/list-job.mjs +5 -5
  548. package/dist/store/outbox.d.mts +15 -5
  549. package/dist/store/outbox.mjs +106 -28
  550. package/dist/store/promises.d.mts +3 -2
  551. package/dist/store/promises.mjs +94 -35
  552. package/dist/store/queue-jobs.mjs +12 -12
  553. package/dist/store/records.d.mts +64 -1
  554. package/dist/store/records.mjs +101 -32
  555. package/dist/store/ref-rows.d.mts +18 -2
  556. package/dist/store/ref-rows.mjs +62 -5
  557. package/dist/store/repo-record.mjs +11 -9
  558. package/dist/store/reservations.mjs +9 -8
  559. package/dist/store/scopes.mjs +13 -1
  560. package/dist/store/settle.mjs +1 -1
  561. package/dist/store/topic-jobs.mjs +4 -4
  562. package/dist/sync/bound.d.mts +5 -3
  563. package/dist/sync/bound.mjs +32 -3
  564. package/dist/sync/github.mjs +7 -7
  565. package/dist/sync/import.d.mts +2 -0
  566. package/dist/sync/import.mjs +46 -50
  567. package/dist/sync/jobs.mjs +15 -23
  568. package/dist/sync/mirror.d.mts +5 -1
  569. package/dist/sync/mirror.mjs +121 -44
  570. package/dist/sync/publish.d.mts +1 -0
  571. package/dist/sync/publish.mjs +10 -12
  572. package/dist/sync/step.mjs +439 -71
  573. package/dist/sync/tries.mjs +50 -32
  574. package/dist/sync.d.mts +3 -3
  575. package/dist/sync.mjs +2 -2
  576. package/dist/topics/advance.mjs +103 -86
  577. package/dist/topics/calls.mjs +97 -67
  578. package/dist/topics/directory.mjs +31 -11
  579. package/dist/topics/host.d.mts +0 -1
  580. package/dist/topics/host.mjs +2 -12
  581. package/dist/topics/members.mjs +30 -24
  582. package/dist/topics/rows.mjs +10 -9
  583. package/dist/topics/topic.mjs +20 -9
  584. package/package.json +8 -15
  585. package/dist/auth/authorize.d.mts +0 -5
  586. package/dist/contracts/objects.mjs +0 -54
  587. package/dist/core/events/stream.d.mts +0 -19
  588. package/dist/core/rules/define.d.mts +0 -5
  589. package/dist/core/rules/define.mjs +0 -13
  590. package/dist/core/rules/fetch.d.mts +0 -5
  591. package/dist/core/sight.mjs +0 -99
  592. package/dist/engine/engine.d.mts +0 -25
  593. package/dist/engine/engine.mjs +0 -49
  594. package/dist/engine/xdiff/NOTICE.md +0 -63
  595. package/dist/engine/xdiff/compiled.d.mts +0 -7
  596. package/dist/engine/xdiff/compiled.mjs +0 -9
  597. package/dist/engine/xdiff/embedded.mjs +0 -4
  598. package/dist/engine/xdiff/node.d.mts +0 -7
  599. package/dist/engine/xdiff/node.mjs +0 -10
  600. package/dist/engine/xdiff/upstream/LGPL-2.1 +0 -511
  601. package/dist/engine/xdiff/xdiff.wasm +0 -0
  602. package/dist/engine.d.mts +0 -3
  603. package/dist/engine.mjs +0 -3
  604. package/dist/storage/distinct-ids.mjs +0 -39
  605. package/dist/storage/held-memo.mjs +0 -188
  606. package/dist/storage/index-remap.d.mts +0 -8
  607. package/dist/sync/records.mjs +0 -73
@@ -0,0 +1,347 @@
1
+ import { gitError } from "../contracts/result.mjs";
2
+ import { hexOf } from "../protocol/bytes/hex.mjs";
3
+ import { nativeSha1Hasher } from "../protocol/bytes/sha1-hasher.mjs";
4
+ import { graphBytes, graphMagic } from "../protocol/packs/graph.mjs";
5
+ import { indexHeader, isEntryOffset, largeFlag, oidBytes, packIndexBytes, smallMost } from "../protocol/packs/idx.mjs";
6
+ import { packPositionsBytes, positionsHeader } from "../protocol/packs/pos.mjs";
7
+ import { packReverseBytes, reverseHeader } from "../protocol/packs/rev.mjs";
8
+ import { packTypesBytes, typeCode, typesHeader } from "../protocol/packs/types-file.mjs";
9
+ import { mostParents } from "../protocol/objects/object-rules.mjs";
10
+ import { randomText } from "../store/random.mjs";
11
+ import { sizedPutCalls, streamedPutCalls } from "./calls.mjs";
12
+ import { graphSourceBytes, openPackGraph } from "./index-graph.mjs";
13
+ import { packFiles } from "./layout.mjs";
14
+ import { upkeepRuns } from "./memory-budget.mjs";
15
+ import { startPut } from "./merge.mjs";
16
+ import { compareIds } from "./raw-ids.mjs";
17
+ import { mergeHeld, mergeRuns, narrowed, runWriter, writerHeld } from "./runs.mjs";
18
+ import * as Effect from "effect/Effect";
19
+ /** A rev run's row: an object's position, then its rank. */
20
+ const revRowBytes = 8;
21
+ /**
22
+ * The bytes of a rev run at `bounds`: a quarter of an index run's, as its rows are a quarter as
23
+ * wide, so 1 MiB at upkeep's, since a writer holds 21 bytes a row besides its rows to sort.
24
+ */
25
+ const revRunBytes = (bounds = upkeepRuns) => Math.floor(bounds.runBytes / 4);
26
+ /** The bytes a file's put is written at a time. */
27
+ const writeBytes = 65536;
28
+ /** The order a pack holds its kinds in, each kind's entries one after another. */
29
+ const kindOrder = [
30
+ "commit",
31
+ "tag",
32
+ "tree",
33
+ "blob"
34
+ ];
35
+ /** `bytes`, rounded down to whole rows of `width`, one at the least. */
36
+ const wholeRows = (width, bytes) => Math.max(1, Math.floor(bytes / width)) * width;
37
+ /**
38
+ * The bytes a merge-read of `runs` reads of each at a time: the reads `bounds` holds for its
39
+ * `ways`, shared among the runs and the read in flight, never under `bounds.readBytes`. So a
40
+ * merge of few runs reads in larger pieces within the same hold.
41
+ */
42
+ const indexReadBytes = (runs, bounds = upkeepRuns) => Math.max(bounds.readBytes, Math.floor((bounds.ways + 1) * bounds.readBytes / (Math.min(runs, bounds.ways) + 1)));
43
+ /**
44
+ * What the index pass of a merge of `inputs` holds at `bounds`, the same for any pack: a merge's
45
+ * reads; beside them the rev runs' writer or, once it's let go, each input's open `.graph`; and a
46
+ * write beside the one in flight. Its put's parts in flight are the adapter's.
47
+ */
48
+ const indexHeld = (inputs, bounds = upkeepRuns) => mergeHeld(32, bounds) + Math.max(writerHeld(revRowBytes, revRunBytes(bounds)), inputs * graphSourceBytes) + 2 * writeBytes;
49
+ /** The runs of `bytes` of rows put `most` at a time, the last the rest. */
50
+ const runsOf = (bytes, most) => {
51
+ const lengths = [];
52
+ for (let left = bytes; left > 0; left -= most) lengths.push(Math.min(most, left));
53
+ return lengths;
54
+ };
55
+ /** The reads a merge of runs `lengths` makes, `read` bytes a read. */
56
+ const readsOf = (lengths, read) => lengths.reduce((sum, length) => sum + Math.ceil(length / read), 0);
57
+ /**
58
+ * The calls a merge of runs `lengths` of `width`-byte rows makes `passes` times at `bounds`:
59
+ * past `bounds.ways`, a narrowing first, reading every run and putting one a group, then each
60
+ * pass's reads, in pieces of `indexReadBytes`.
61
+ */
62
+ const mergesCalls = (lengths, width, passes, bounds, multipart) => {
63
+ let calls = 0;
64
+ let current = lengths;
65
+ while (current.length > bounds.ways) {
66
+ calls += readsOf(current, wholeRows(width, bounds.readBytes));
67
+ const next = [];
68
+ for (let from = 0; from < current.length; from += bounds.ways) next.push(current.slice(from, from + bounds.ways).reduce((sum, length) => sum + length, 0));
69
+ calls += next.reduce((sum, length) => sum + sizedPutCalls(multipart, length), 0);
70
+ current = next;
71
+ }
72
+ const read = wholeRows(width, indexReadBytes(current.length, bounds));
73
+ return calls + passes * readsOf(current, read);
74
+ };
75
+ /**
76
+ * The most bucket calls `indexPack` makes for a pack of `objects` and `bytes`, whose index runs
77
+ * were all put at `bounds`, with puts charged as `multipart` charges them: six merge-reads of
78
+ * the runs, and a seventh for the large offsets of a pack past `smallMost`; the rev runs' puts and
79
+ * their merge, none for rev rows that fit one run; the four files' puts; and for the `.graph`, a
80
+ * read of each input's and its put, of at most `graphAtMost`, told no size. A try whose calls
81
+ * left are under it doesn't start the pack's index, and the write pass ends a pack before it
82
+ * passes a try's calls. Exact for a pack of `smallMost` bytes or fewer. Past that it's an upper
83
+ * bound: it counts the large offsets' read and an 8-byte slot for every object, which a pack whose
84
+ * entries all start under 2^31 doesn't make.
85
+ */
86
+ const indexCalls = ({ objects, bytes, inputs, commits }, multipart, bounds = upkeepRuns) => {
87
+ const large = bytes > smallMost;
88
+ const index = runsOf(objects * 32, wholeRows(32, bounds.runBytes));
89
+ const revMost = wholeRows(revRowBytes, revRunBytes(bounds));
90
+ const rev = objects * revRowBytes < revMost ? [] : runsOf(objects * revRowBytes, revMost);
91
+ const files = [
92
+ packPositionsBytes(objects),
93
+ packTypesBytes(objects),
94
+ packIndexBytes(objects, large ? objects : 0),
95
+ packReverseBytes(objects)
96
+ ];
97
+ return mergesCalls(index, 32, large ? 7 : 6, bounds, multipart) + rev.reduce((sum, length) => sum + sizedPutCalls(multipart, length), 0) + mergesCalls(rev, revRowBytes, 1, bounds, multipart) + files.reduce((sum, file) => sum + sizedPutCalls(multipart, file), 0) + inputs.length + streamedPutCalls(multipart, graphAtMost(inputs, commits));
98
+ };
99
+ /**
100
+ * The most bytes a pack's `.graph` takes: its sources', each input's `.graph` and the folded
101
+ * commits' own, since it keeps some of their commits once each, under one header and trailer.
102
+ */
103
+ const graphAtMost = (inputs, commits) => inputs.reduce((sum, input) => sum + input.graphBytes, 0) + graphBytes(commits.length, commits.reduce((sum, commit) => sum + commit.parents.length, 0));
104
+ const lost = (message) => gitError("DATA_LOSS", message);
105
+ /** The 4 bytes at `at`, big-endian. */
106
+ const uint32At = (bytes, at) => ((bytes[at] ?? 0) << 24 | (bytes[at + 1] ?? 0) << 16 | (bytes[at + 2] ?? 0) << 8 | (bytes[at + 3] ?? 0)) >>> 0;
107
+ const alreadyThere = (error) => error.code === "ALREADY_EXISTS";
108
+ /**
109
+ * A put of the file `key`, as `body` appends to it, `writeBytes` a write, then `trailer`, the pack's
110
+ * checksum when given, and the SHA-1 of every byte before it, as each file ends. Told its `size`, a
111
+ * body that writes other than it is a bug; told only `atMost`, the bucket refuses one past it. A
112
+ * key that's there already ends the put, and the body runs on uncounted by the bucket.
113
+ */
114
+ const streamedFile = (bucket, key, length, trailer, body) => Effect.scoped(Effect.gen(function* () {
115
+ let there = false;
116
+ const put = yield* Effect.catchIf(startPut(bucket, key, length), alreadyThere, () => Effect.sync(() => {
117
+ there = true;
118
+ return {
119
+ write: () => Effect.void,
120
+ finish: Effect.void
121
+ };
122
+ }));
123
+ const sent = (call) => Effect.suspend(() => there ? Effect.void : Effect.catchIf(call, alreadyThere, () => Effect.sync(() => void (there = true))));
124
+ const hasher = nativeSha1Hasher();
125
+ let chunk = new Uint8Array(writeBytes);
126
+ let view = new DataView(chunk.buffer);
127
+ let filled = 0;
128
+ let written = 0;
129
+ const flush = Effect.suspend(() => {
130
+ const bytes = chunk.subarray(0, filled);
131
+ chunk = new Uint8Array(writeBytes);
132
+ view = new DataView(chunk.buffer);
133
+ written += filled;
134
+ filled = 0;
135
+ return Effect.andThen(hasher.write(bytes), sent(put.write(bytes)));
136
+ });
137
+ /** `length` bytes set at the chunk's end by `set`, after a write when they don't fit. */
138
+ const appended = (length, set) => {
139
+ const place = () => {
140
+ set(filled);
141
+ filled += length;
142
+ };
143
+ if (filled + length > chunk.byteLength) return Effect.andThen(flush, Effect.sync(place));
144
+ place();
145
+ };
146
+ const out = {
147
+ bytes: (from, at, length) => appended(length, (to) => chunk.set(from.subarray(at, at + length), to)),
148
+ word: (value) => appended(4, (to) => view.setUint32(to, value)),
149
+ byte: (value) => appended(1, (to) => void (chunk[to] = value)),
150
+ offset: (value) => appended(8, (to) => {
151
+ view.setUint32(to, 0);
152
+ view.setUint32(to + 4, value);
153
+ })
154
+ };
155
+ yield* body(out);
156
+ if (trailer !== void 0) yield* out.bytes(oidBytes(trailer), 0, 20) ?? Effect.void;
157
+ yield* flush;
158
+ const sum = yield* hasher.digest;
159
+ if ("size" in length && written + sum.byteLength !== length.size) return yield* Effect.die(/* @__PURE__ */ new Error(`${key} wrote ${written + sum.byteLength} of ${length.size} bytes`));
160
+ yield* sent(put.write(sum));
161
+ yield* sent(put.finish);
162
+ return written + sum.byteLength;
163
+ }));
164
+ /**
165
+ * The index pass of `write`'s pack, its runs read at `bounds`: its `.pos` and rev runs, its
166
+ * `.types`, its `.idx`, then its `.rev`, each a put of its own. Refused as `DATA_LOSS` for runs
167
+ * whose IDs repeat or come out of order, an offset no entry has, or positions that aren't each of
168
+ * the pack's once. A refusal leaves files the caller drops with its pack. Its own runs, under
169
+ * `scratch`, take kinds of their own for each call, so a call again over the same runs, in a
170
+ * later try, puts none where an earlier call did; the caller's drop of `scratch` takes them.
171
+ * Answers the `.graph`'s bytes, which the pack's row lists.
172
+ */
173
+ const indexPack = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, write, bounds = upkeepRuns) {
174
+ const { pack, scratch, checksum, objects, kinds, runs } = write;
175
+ const counted = kindOrder.reduce((sum, kind) => sum + kinds[kind], 0);
176
+ if (runs.width !== 32 || runs.rows !== objects || counted !== objects) return yield* Effect.die(/* @__PURE__ */ new Error(`Pack ${pack}'s index runs aren't its ${objects} objects`));
177
+ const files = packFiles(pack);
178
+ const call = randomText(8);
179
+ const few = yield* narrowed(bucket, scratch, {
180
+ ...runs,
181
+ kind: `${runs.kind}.${call}`
182
+ }, bounds);
183
+ const reading = {
184
+ ...bounds,
185
+ readBytes: indexReadBytes(few.keys.length + (few.held === void 0 ? 0 : 1), bounds)
186
+ };
187
+ /** Every index row in ID order, through `each`. */
188
+ const merged = (each) => mergeRuns(bucket, scratch, few, each, reading);
189
+ const firsts = /* @__PURE__ */ new Uint32Array(256);
190
+ const last = /* @__PURE__ */ new Uint8Array(20);
191
+ const revs = runWriter(bucket, scratch, `rev.${call}`, revRowBytes, { bytes: revRunBytes(bounds) });
192
+ const revRow = new Uint8Array(revRowBytes);
193
+ const revView = new DataView(revRow.buffer);
194
+ let large = 0;
195
+ let rank = 0;
196
+ yield* streamedFile(bucket, files.pos, { size: packPositionsBytes(objects) }, checksum, (out) => Effect.gen(function* () {
197
+ yield* out.bytes(positionsHeader(objects), 0, 12) ?? Effect.void;
198
+ yield* merged((bytes, at) => {
199
+ if (rank > 0 && compareIds(bytes, at, last, 0) <= 0) return Effect.fail(lost(`Pack ${pack}'s index runs repeat or misorder an ID`));
200
+ const offset = uint32At(bytes, at + 20);
201
+ const position = uint32At(bytes, at + 28);
202
+ if (!isEntryOffset(offset) || position >= objects) return Effect.fail(lost(`Pack ${pack}'s index runs name offset ${offset}, position ${position}`));
203
+ last.set(bytes.subarray(at, at + 20));
204
+ const first = bytes[at] ?? 0;
205
+ firsts[first] = (firsts[first] ?? 0) + 1;
206
+ if (offset > 2147483647) large += 1;
207
+ revView.setUint32(0, position);
208
+ revView.setUint32(4, rank);
209
+ rank += 1;
210
+ const added = revs.add(revRow);
211
+ const wrote = out.word(position);
212
+ return added === void 0 ? wrote : Effect.andThen(added, wrote ?? Effect.void);
213
+ });
214
+ }));
215
+ const ends = kindOrder.map((_, at) => kindOrder.slice(0, at + 1).reduce((sum, kind) => sum + kinds[kind], 0));
216
+ const codes = kindOrder.map(typeCode);
217
+ const codeAt = (position) => codes[ends.findIndex((end) => position < end)] ?? 0;
218
+ yield* streamedFile(bucket, files.types, { size: packTypesBytes(objects) }, checksum, (out) => Effect.gen(function* () {
219
+ yield* out.bytes(typesHeader(objects), 0, 12) ?? Effect.void;
220
+ yield* merged((bytes, at) => out.byte(codeAt(uint32At(bytes, at + 28))));
221
+ }));
222
+ const fanout = /* @__PURE__ */ new Uint8Array(1024);
223
+ const fanoutView = new DataView(fanout.buffer);
224
+ let below = 0;
225
+ for (let first = 0; first < 256; first += 1) {
226
+ below += firsts[first] ?? 0;
227
+ fanoutView.setUint32(first * 4, below);
228
+ }
229
+ yield* streamedFile(bucket, files.idx, { size: packIndexBytes(objects, large) }, checksum, (out) => Effect.gen(function* () {
230
+ let largeAt = 0;
231
+ yield* out.bytes(indexHeader(), 0, 8) ?? Effect.void;
232
+ yield* out.bytes(fanout, 0, fanout.byteLength) ?? Effect.void;
233
+ yield* merged((bytes, at) => out.bytes(bytes, at, 20));
234
+ yield* merged((bytes, at) => out.bytes(bytes, at + 24, 4));
235
+ yield* merged((bytes, at) => {
236
+ const offset = uint32At(bytes, at + 20);
237
+ if (offset <= 2147483647) return out.word(offset);
238
+ largeAt += 1;
239
+ return out.word((largeFlag | largeAt - 1) >>> 0);
240
+ });
241
+ if (large === 0) return;
242
+ yield* merged((bytes, at) => {
243
+ const offset = uint32At(bytes, at + 20);
244
+ return offset > 2147483647 ? out.offset(offset) : void 0;
245
+ });
246
+ }));
247
+ yield* reverseFile(bucket, write, revs.finish, bounds);
248
+ revs.release();
249
+ return yield* graphFile(bucket, write, merged);
250
+ });
251
+ /**
252
+ * `write`'s `.rev`: each position's rank, from its rev runs, `finished`, merged in position order,
253
+ * narrowed first. Its runs, a held run's rows among them, are unreachable once it ends.
254
+ */
255
+ const reverseFile = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, write, finished, bounds) {
256
+ const { pack, scratch, checksum, objects } = write;
257
+ const revRuns = yield* narrowed(bucket, scratch, yield* finished, bounds);
258
+ const revReading = {
259
+ ...bounds,
260
+ readBytes: indexReadBytes(revRuns.keys.length + (revRuns.held === void 0 ? 0 : 1), bounds)
261
+ };
262
+ let position = 0;
263
+ yield* streamedFile(bucket, packFiles(pack).rev, { size: packReverseBytes(objects) }, checksum, (out) => Effect.gen(function* () {
264
+ yield* out.bytes(reverseHeader(), 0, 12) ?? Effect.void;
265
+ yield* mergeRuns(bucket, scratch, revRuns, (bytes, at) => {
266
+ if (uint32At(bytes, at) !== position) return Effect.fail(lost(`Pack ${pack}'s index runs don't name position ${position} once`));
267
+ position += 1;
268
+ return out.word(uint32At(bytes, at + 4));
269
+ }, revReading);
270
+ }));
271
+ });
272
+ /**
273
+ * An input's `DATA_LOSS`, its `.graph` missing, broken or not the size its pack row records, with
274
+ * the input's pack in its context, so the merge's caller can fence that pack alone.
275
+ */
276
+ const ofInput = (pack) => (effect) => Effect.mapError(effect, (error) => error.code === "DATA_LOSS" ? gitError("DATA_LOSS", error.message, { context: {
277
+ ...error.context,
278
+ pack
279
+ } }) : error);
280
+ /** `commits` as a `.graph` source, one after another, in the order given. */
281
+ const foldedSource = (commits) => {
282
+ let at = 0;
283
+ return Effect.sync(() => {
284
+ const commit = commits[at];
285
+ if (commit === void 0) return void 0;
286
+ at += 1;
287
+ const parents = new Uint8Array(commit.parents.length * 20);
288
+ for (const [each, parent] of commit.parents.entries()) parents.set(oidBytes(parent), each * 20);
289
+ return {
290
+ id: oidBytes(commit.oid),
291
+ parents,
292
+ count: commit.parents.length
293
+ };
294
+ });
295
+ };
296
+ /**
297
+ * `write`'s `.graph`: each commit of the pack, the rows in its runs' commit stretch, `merged` in ID
298
+ * order, with its parents from the first source that holds it, each input's `.graph` in merge order
299
+ * and then `commits`, each streamed beside the runs. A source's commit the pack lacks is left out.
300
+ * A commit no source holds is `DATA_LOSS`, as is an input's `.graph` missing, broken or not its
301
+ * recorded size, whose tail is read to its trailer too: that refusal names the input's pack. So
302
+ * is a commit of more than `mostParents` parents, which no write path takes (#1284): a source only
303
+ * counts its parents, and no `.graph` holds one but a broken one.
304
+ */
305
+ const graphFile = (bucket, write, merged) => Effect.scoped(Effect.gen(function* () {
306
+ const { pack, kinds, inputs, commits } = write;
307
+ const sources = [...yield* Effect.forEach(inputs, (input) => {
308
+ const named = ofInput(input.pack);
309
+ const source = openPackGraph(bucket, packFiles(input.pack).graph, input.graphBytes);
310
+ return Effect.map(named(source), (each) => named(each.next));
311
+ }), foldedSource(commits)];
312
+ const heads = [];
313
+ for (const next of sources) heads.push(yield* next);
314
+ const header = /* @__PURE__ */ new Uint8Array(12);
315
+ const view = new DataView(header.buffer);
316
+ header.set(graphMagic);
317
+ view.setUint32(4, 1);
318
+ view.setUint32(8, kinds.commit);
319
+ /** A commit's row: each source moved up to its ID, and the first holding it written. */
320
+ const kept = Effect.fnUntraced(function* (out, bytes, at) {
321
+ let found;
322
+ let from = 0;
323
+ for (const [each, next] of sources.entries()) {
324
+ let head = heads[each];
325
+ while (head !== void 0 && compareIds(head.id, 0, bytes, at) < 0) head = yield* next;
326
+ heads[each] = head;
327
+ if (found === void 0 && head !== void 0 && compareIds(head.id, 0, bytes, at) === 0) {
328
+ found = head;
329
+ from = each;
330
+ }
331
+ }
332
+ const id = hexOf(bytes.subarray(at, at + 20));
333
+ if (found === void 0) return yield* Effect.fail(lost(`Pack ${pack}'s commit ${id} is in no input's .graph`));
334
+ const input = inputs[from];
335
+ const wide = `The repo's commit ${id} has ${found.count} parents, past ${mostParents}`;
336
+ if (found.count > 4096) return yield* Effect.fail(input === void 0 ? lost(wide) : gitError("DATA_LOSS", wide, { context: { pack: input.pack } }));
337
+ yield* out.bytes(bytes, at, 20) ?? Effect.void;
338
+ yield* out.word(found.count) ?? Effect.void;
339
+ for (let parent = 0; parent < found.count; parent += 1) yield* out.bytes(found.parents, parent * 20, 20) ?? Effect.void;
340
+ });
341
+ return yield* streamedFile(bucket, packFiles(pack).graph, { atMost: graphAtMost(inputs, commits) }, void 0, (out) => Effect.gen(function* () {
342
+ yield* out.bytes(header, 0, 12) ?? Effect.void;
343
+ yield* merged((bytes, at) => uint32At(bytes, at + 28) < kinds.commit ? kept(out, bytes, at) : void 0);
344
+ for (const [each, next] of sources.entries()) while (heads[each] !== void 0) heads[each] = yield* next;
345
+ }));
346
+ }));
347
+ export { graphAtMost, indexCalls, indexHeld, indexPack, indexReadBytes, revRunBytes };
@@ -0,0 +1,202 @@
1
+ import { fanoutBytes, indexHeadBytes } from "../protocol/packs/idx.mjs";
2
+ import { allottableOf, defaultMemory, readerFloors } from "./budget.mjs";
3
+ import { runKey } from "./layout.mjs";
4
+ import { upkeepRuns } from "./memory-budget.mjs";
5
+ import { chooseHeld, chosenMost, foldedRows } from "./merge-choose.mjs";
6
+ import { pairRunBytes } from "./merge-cut.mjs";
7
+ import { indexHeld } from "./merge-index.mjs";
8
+ import { blockBytes, blockHeld } from "./pack-reads.mjs";
9
+ import { keepHeld } from "./prune-keep.mjs";
10
+ import { groupWrites, maxPackSizeMost } from "./repack.mjs";
11
+ import { cursorHeld, sortedWriterHeld, wholeRows, writerHeld } from "./runs.mjs";
12
+ import { writtenBasesHeld } from "./written-bases.mjs";
13
+ import { limits } from "@ref0/infra";
14
+ // src/storage/merge-most.ts
15
+ /**
16
+ * What bounds one streamed merge (maintenance-1m piece 1): the inputs it takes, from what its
17
+ * passes hold, and the packs it writes, from its row, the listing commit and the next prune's keep.
18
+ * Here, apart from the merge, so its row's schema holds the packs' bound.
19
+ */
20
+ /** The blocks a merge's plan and write read through, a pack's readers made new at this room. */
21
+ const mergeBlocksRoom = 8 * blockHeld(blockBytes);
22
+ /** What a write holds beside its walk's readers: its index rows' writer and its pairs'. */
23
+ const writeHeld = (bounds = upkeepRuns) => writerHeld(32, bounds.runBytes) + sortedWriterHeld(8, pairRunBytes);
24
+ /** What a merge's readers and writers hold, whatever its inputs. */
25
+ const readersWritersHeld = mergeBlocksRoom + readerFloors.cache + writeHeld();
26
+ /**
27
+ * The inputs one merge takes at most: those whose choose and index tables fit in what its readers
28
+ * and writers hold, so it holds what a merge of two does (about 38). Choose's tables are let go
29
+ * before the walk, so the walk's own hold doesn't count here.
30
+ */
31
+ const mergeInputsMost = (() => {
32
+ let inputs = 2;
33
+ while (Math.max(chooseHeld(inputs + 1), indexHeld(inputs + 1)) <= readersWritersHeld) inputs += 1;
34
+ return inputs;
35
+ })();
36
+ /** What an input's `.idx`, opened by range, holds: the head it read, and its fanout's table. */
37
+ const indexOpenHeld = indexHeadBytes + fanoutBytes;
38
+ /**
39
+ * What a merge's walk holds beside its readers and writers (#1656): its cursor over the chosen
40
+ * runs, its written-bases table, and each input's `.idx` as opened.
41
+ */
42
+ const walkHeld = cursorHeld(36, upkeepRuns) + writtenBasesHeld() + mergeInputsMost * indexOpenHeld;
43
+ /** The bytes a write gathers to hand its pack's put at once, its entries' together (#1678). */
44
+ const writeChunkBytes = 65536;
45
+ /**
46
+ * What a pass holds as it goes, beside its walk (#1678): the chunk its write gathers and the one it
47
+ * handed last, its index row's and pair's own bytes, its blocks' header across an edge, and the
48
+ * chosen read a pending record's ID still holds as its run reads the next. The put's own parts
49
+ * are its charge's (#1670).
50
+ */
51
+ const goingHeld = 131176 + wholeRows(36, upkeepRuns.readBytes);
52
+ /**
53
+ * What a merge's plan and write passes hold, whatever their inputs: readers, writers, walk, and
54
+ * what they hold as they go.
55
+ */
56
+ const writingHeld = readersWritersHeld + walkHeld + goingHeld;
57
+ /**
58
+ * The objects `mergePacksMost` is counted at: the most a merge's records name, and the rows it
59
+ * folds. So the bound holds for every row the schema takes (Q950).
60
+ */
61
+ const objectsCounted = chosenMost + foldedRows;
62
+ /** A row's JSON bytes: a merge row's are ASCII, a byte a character. */
63
+ const jsonBytes$1 = (value) => JSON.stringify(value).length;
64
+ const numberMost = Number.MAX_SAFE_INTEGER;
65
+ const idLongest = `p_${"A".repeat(16)}`;
66
+ /** `runCallBytes` as `randomText` writes them: base64url, unpadded. */
67
+ const callLongest = "A".repeat(Math.ceil(32 / 3));
68
+ /** A run's kind, as its row holds it: a written pack's are its own, ending in its call. */
69
+ const runKinds = {
70
+ chosen: "chosen",
71
+ index: `index.${callLongest}`,
72
+ pairs: `pairs.${callLongest}`
73
+ };
74
+ /** A run's bytes at most, as its writer puts it: whole rows of `width`, within `bytes`. */
75
+ const runBytesOf = (width, bytes) => Math.floor(bytes / width) * width;
76
+ /** The runs `rows` rows of `width` bytes take, `bytes` a run, as their writer puts them. */
77
+ const runsCounted = (rows, width, bytes) => Math.ceil(rows * width / runBytesOf(width, bytes));
78
+ /** A kind's runs across a merge of `objectsCounted`, and the bytes a run holds at most. */
79
+ const runsAt = (width, bytes) => ({
80
+ bytes: runBytesOf(width, bytes),
81
+ count: runsCounted(objectsCounted, width, bytes)
82
+ });
83
+ /** Each run kind's runs, as the choose and each pack's write put them. */
84
+ const runs = {
85
+ chosen: runsAt(36, upkeepRuns.runBytes),
86
+ index: runsAt(32, upkeepRuns.runBytes),
87
+ pairs: runsAt(8, pairRunBytes)
88
+ };
89
+ /** The longest key of `kind`'s runs: its number the last of its runs. */
90
+ const keyOf = (kind) => runKey(idLongest, runKinds[kind], runs[kind].count - 1);
91
+ /** A key and its length in a run's row, quoted, their commas in, the length a whole run's. */
92
+ const keyBytes = (kind) => keyOf(kind).length + 2 + 1 + String(runs[kind].bytes).length + 1;
93
+ /** `kind`'s runs holding `keys` keys at their longest, every other number at its most. */
94
+ const runsOf = (kind, keys) => ({
95
+ kind: runKinds[kind],
96
+ width: 1024,
97
+ keys: Array.from({ length: keys }, () => keyOf(kind)),
98
+ lengths: Array.from({ length: keys }, () => runs[kind].bytes),
99
+ rows: numberMost
100
+ });
101
+ const kindsMost = {
102
+ commit: chosenMost,
103
+ tag: chosenMost,
104
+ tree: chosenMost,
105
+ blob: chosenMost
106
+ };
107
+ /** A cursor at its longest: its runs' places, one a run the walk merges, each at its most. */
108
+ const cursorMost = {
109
+ kind: "commit",
110
+ position: objectsCounted,
111
+ starts: Array.from({ length: upkeepRuns.ways }, () => chosenMost)
112
+ };
113
+ /**
114
+ * A pack's bytes in its merge's row: its planned and written entries, one key a run, commas in.
115
+ * Its bytes are at most `maxPackSizeMost`, past which a merge refuses.
116
+ */
117
+ const packRowBytes = (() => {
118
+ const objects = objectsCounted;
119
+ const planned = {
120
+ objects,
121
+ start: cursorMost,
122
+ end: {
123
+ kind: "commit",
124
+ position: objects
125
+ },
126
+ bytes: maxPackSizeMost
127
+ };
128
+ const written = {
129
+ id: idLongest,
130
+ objects,
131
+ bytes: maxPackSizeMost,
132
+ kinds: kindsMost,
133
+ checksum: "a".repeat(64),
134
+ index: runsOf("index", 1),
135
+ pairs: runsOf("pairs", 1),
136
+ graphBytes: numberMost
137
+ };
138
+ return jsonBytes$1(planned) + 1 + jsonBytes$1(written) + 1;
139
+ })();
140
+ /** The passes `narrowed` makes to merge `count` runs, `ways` at a time, to at most `ways`. */
141
+ const narrowedPasses = (count, ways) => {
142
+ let passes = 0;
143
+ for (let left = count; left > ways; left = Math.ceil(left / ways)) passes += 1;
144
+ return passes;
145
+ };
146
+ /**
147
+ * Choose's runs as its row saves them, at their longest: `narrowed` leaves at most `ways`, each
148
+ * keyed by its last pass and holding up to every record counted.
149
+ */
150
+ const chosenRuns = (() => {
151
+ const { ways } = upkeepRuns;
152
+ const passes = narrowedPasses(runs.chosen.count, ways);
153
+ const kind = passes === 0 ? runKinds.chosen : `${runKinds.chosen}.${passes}`;
154
+ return {
155
+ kind: runKinds.chosen,
156
+ width: 1024,
157
+ keys: Array.from({ length: ways }, () => runKey(idLongest, kind, ways - 1)),
158
+ lengths: Array.from({ length: ways }, () => objectsCounted * 36),
159
+ rows: numberMost
160
+ };
161
+ })();
162
+ /**
163
+ * A merge row's bytes beside its packs': its inputs, folded rows and chosen runs at their most,
164
+ * and the keys its written packs' runs take past one a run, across every object counted.
165
+ */
166
+ const rowFixedBytes = (() => {
167
+ const row = {
168
+ owner: "repack",
169
+ inputs: Array.from({ length: mergeInputsMost }, () => idLongest),
170
+ rows: Array.from({ length: foldedRows }, () => "a".repeat(64)),
171
+ pass: "commit",
172
+ chosen: chosenRuns,
173
+ winners: chosenMost,
174
+ kinds: kindsMost,
175
+ winnerBytes: numberMost,
176
+ cursor: cursorMost,
177
+ planned: [],
178
+ written: []
179
+ };
180
+ return jsonBytes$1(row) + runs.index.count * keyBytes("index") + runs.pairs.count * keyBytes("pairs");
181
+ })();
182
+ /** Whether a merge of `packs` packs fits each limit its packs meet. */
183
+ const fits = (packs) => {
184
+ const row = rowFixedBytes + packs * packRowBytes <= limits.valueBytes;
185
+ const listing = 3 * packs + 1 + 2 * mergeInputsMost + foldedRows <= groupWrites;
186
+ const listed = Array.from({ length: packs }, (_, at) => ({ objects: at === 0 ? objectsCounted : 1 }));
187
+ const keep = keepHeld(listed) <= allottableOf(defaultMemory);
188
+ return row && listing && keep;
189
+ };
190
+ /**
191
+ * The packs one merge writes at most (#1456): the most whose row fits a row's `valueBytes`, whose
192
+ * listing fits `groupWrites`, and whose next keep fits a Worker's 128 MB, each counted at
193
+ * `objectsCounted`. The keep binds, at 418: the row, its chosen runs as few as `narrowed` leaves
194
+ * them, would hold 446. A plan that would cut past it fences the input at its step, as
195
+ * `packs-past-most`.
196
+ */
197
+ const mergePacksMost = (() => {
198
+ let packs = 1;
199
+ while (fits(packs + 1)) packs += 1;
200
+ return packs;
201
+ })();
202
+ export { goingHeld, mergeBlocksRoom, mergeInputsMost, mergePacksMost, walkHeld, writeChunkBytes, writeHeld, writingHeld };