@ref0/git 0.14.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (492) hide show
  1. package/dist/access/private-refs.mjs +1 -1
  2. package/dist/auth/access-jwt.mjs +4 -4
  3. package/dist/auth/auth-namespace.d.mts +3 -3
  4. package/dist/auth/auth-namespace.mjs +3 -2
  5. package/dist/auth/auth.d.mts +3 -3
  6. package/dist/auth/auth.mjs +9 -8
  7. package/dist/auth/authorize.mjs +4 -4
  8. package/dist/auth/fences.d.mts +1 -2
  9. package/dist/auth/fences.mjs +3 -3
  10. package/dist/auth/grants.mjs +4 -4
  11. package/dist/auth/host-function.mjs +19 -2
  12. package/dist/auth/host-services.mjs +4 -6
  13. package/dist/auth/identify.d.mts +1 -1
  14. package/dist/auth/identify.mjs +9 -3
  15. package/dist/auth/token-cleanup.mjs +67 -0
  16. package/dist/auth/token-rows.mjs +7 -2
  17. package/dist/auth/token-text.mjs +9 -1
  18. package/dist/auth/tokens-base.d.mts +35 -0
  19. package/dist/auth/tokens-base.mjs +13 -0
  20. package/dist/auth/tokens-layer.d.mts +2 -27
  21. package/dist/auth/tokens-layer.mjs +6 -11
  22. package/dist/auth/tokens-public.d.mts +3 -3
  23. package/dist/auth/tokens.d.mts +7 -10
  24. package/dist/auth/tokens.mjs +10 -81
  25. package/dist/client/answer.mjs +21 -42
  26. package/dist/client/client.d.mts +17 -11
  27. package/dist/client/client.mjs +21 -12
  28. package/dist/client/git-http.mjs +18 -8
  29. package/dist/client/local.mjs +74 -37
  30. package/dist/client/negotiate.mjs +3 -3
  31. package/dist/client/push-upload.mjs +34 -17
  32. package/dist/client/remote.mjs +12 -13
  33. package/dist/client/run-remote-helper.d.mts +2 -1
  34. package/dist/client/run-remote-helper.mjs +61 -27
  35. package/dist/client/slice-push.d.mts +1 -1
  36. package/dist/client/transport.mjs +105 -46
  37. package/dist/contracts/blobs.d.mts +58 -11
  38. package/dist/contracts/blobs.mjs +17 -3
  39. package/dist/contracts/call-allowance.d.mts +13 -0
  40. package/dist/contracts/call-allowance.mjs +44 -0
  41. package/dist/contracts/calls-spent.mjs +12 -35
  42. package/dist/contracts/client.d.mts +18 -18
  43. package/dist/contracts/commits.d.mts +28 -28
  44. package/dist/contracts/commits.mjs +1 -1
  45. package/dist/contracts/engine.d.mts +8 -3
  46. package/dist/contracts/engine.mjs +10 -1
  47. package/dist/contracts/events.d.mts +1 -1
  48. package/dist/contracts/events.mjs +1 -1
  49. package/dist/contracts/files.d.mts +14 -14
  50. package/dist/contracts/files.mjs +1 -1
  51. package/dist/contracts/forks.d.mts +21 -21
  52. package/dist/contracts/forks.mjs +1 -1
  53. package/dist/contracts/git-events.d.mts +29 -1
  54. package/dist/contracts/git-hooks.d.mts +2 -2
  55. package/dist/contracts/git.d.mts +30 -5
  56. package/dist/contracts/grants.d.mts +24 -4
  57. package/dist/contracts/handlers.d.mts +1 -1
  58. package/dist/contracts/lfs.d.mts +28 -2
  59. package/dist/contracts/merges.d.mts +3 -2
  60. package/dist/contracts/object-values.d.mts +1 -0
  61. package/dist/contracts/object-values.mjs +16 -1
  62. package/dist/contracts/objects.d.mts +42 -41
  63. package/dist/contracts/opaque.mjs +1 -1
  64. package/dist/contracts/operations.mjs +1 -1
  65. package/dist/contracts/queue.d.mts +247 -55
  66. package/dist/contracts/queue.mjs +8 -9
  67. package/dist/contracts/refs.d.mts +30 -27
  68. package/dist/contracts/refs.mjs +1 -1
  69. package/dist/contracts/remote.d.mts +8 -12
  70. package/dist/contracts/remote.mjs +4 -1
  71. package/dist/contracts/repos.d.mts +32 -141
  72. package/dist/contracts/repos.mjs +6 -4
  73. package/dist/contracts/result.d.mts +40 -18
  74. package/dist/contracts/result.mjs +42 -9
  75. package/dist/contracts/rules.d.mts +2 -2
  76. package/dist/contracts/server.d.mts +25 -52
  77. package/dist/contracts/services.d.mts +6 -9
  78. package/dist/contracts/services.mjs +1 -2
  79. package/dist/contracts/signin.d.mts +1 -1
  80. package/dist/contracts/store.d.mts +7 -6
  81. package/dist/contracts/sync.d.mts +73 -12
  82. package/dist/contracts/sync.mjs +14 -3
  83. package/dist/contracts/tags.d.mts +13 -13
  84. package/dist/contracts/tags.mjs +1 -1
  85. package/dist/contracts/time.d.mts +3 -0
  86. package/dist/contracts/{promises.mjs → time.mjs} +1 -1
  87. package/dist/contracts/tokens.d.mts +17 -19
  88. package/dist/contracts/tokens.mjs +4 -3
  89. package/dist/contracts/topics.d.mts +10 -10
  90. package/dist/contracts/trees.d.mts +16 -16
  91. package/dist/contracts/trees.mjs +1 -1
  92. package/dist/contracts/work.d.mts +28 -17
  93. package/dist/contracts/work.mjs +2 -2
  94. package/dist/core/access.d.mts +1 -2
  95. package/dist/core/access.mjs +20 -9
  96. package/dist/core/ancestry.d.mts +1 -0
  97. package/dist/core/ancestry.mjs +30 -34
  98. package/dist/core/asked.mjs +1 -1
  99. package/dist/core/call-groups.mjs +48 -0
  100. package/dist/core/call-names.mjs +6 -1
  101. package/dist/core/call-services.mjs +11 -3
  102. package/dist/core/events/deliver.d.mts +2 -3
  103. package/dist/core/events/deliver.mjs +45 -38
  104. package/dist/core/events/retired.mjs +119 -0
  105. package/dist/core/forks.mjs +929 -433
  106. package/dist/core/hooks/groups.mjs +3 -3
  107. package/dist/core/imports.mjs +127 -41
  108. package/dist/core/index-job.mjs +131 -38
  109. package/dist/core/index-lost.d.mts +1 -2
  110. package/dist/core/index-lost.mjs +2 -2
  111. package/dist/core/loose-tally.mjs +38 -15
  112. package/dist/core/merge-parts.d.mts +17 -4
  113. package/dist/core/merge-parts.mjs +7 -2
  114. package/dist/core/mirror-rows.mjs +31 -1
  115. package/dist/core/objects/blobs.mjs +127 -3
  116. package/dist/core/objects/files.mjs +20 -17
  117. package/dist/core/objects/lines.mjs +2 -2
  118. package/dist/core/objects/merges.mjs +4 -1
  119. package/dist/core/objects/objects-layer.d.mts +1 -1
  120. package/dist/core/objects/objects-layer.mjs +4 -4
  121. package/dist/core/objects/peel.mjs +1 -7
  122. package/dist/core/objects/reading.mjs +41 -29
  123. package/dist/core/objects/tags.mjs +4 -1
  124. package/dist/core/objects/tree-edits.mjs +1 -1
  125. package/dist/core/objects/trees.mjs +257 -58
  126. package/dist/core/objects/writing.mjs +4 -10
  127. package/dist/core/own-writes.mjs +2 -2
  128. package/dist/core/parts.d.mts +11 -5
  129. package/dist/core/parts.mjs +9 -10
  130. package/dist/core/purge.mjs +310 -93
  131. package/dist/core/push-decide.mjs +2 -0
  132. package/dist/core/push-files.d.mts +1 -1
  133. package/dist/core/push.d.mts +2 -2
  134. package/dist/core/push.mjs +170 -128
  135. package/dist/core/receipts.d.mts +2 -2
  136. package/dist/core/receipts.mjs +17 -5
  137. package/dist/core/ref-index-job.mjs +7 -7
  138. package/dist/core/ref-view.mjs +75 -32
  139. package/dist/core/refs.mjs +7 -7
  140. package/dist/core/registered-rows.mjs +2 -2
  141. package/dist/core/repack.mjs +58 -48
  142. package/dist/core/repo-info.mjs +3 -3
  143. package/dist/core/repos.mjs +21 -9
  144. package/dist/core/rules/changes.mjs +18 -40
  145. package/dist/core/rules/check.mjs +6 -5
  146. package/dist/core/rules/commit-changes.mjs +3 -15
  147. package/dist/core/rules/context.d.mts +3 -3
  148. package/dist/core/rules/context.mjs +18 -14
  149. package/dist/core/rules/fetch.mjs +1 -1
  150. package/dist/core/rules/protect.mjs +30 -17
  151. package/dist/core/saved-caller-views.d.mts +8 -3
  152. package/dist/core/saved-caller-views.mjs +4 -4
  153. package/dist/core/saved-callers.d.mts +19 -2
  154. package/dist/core/saved-callers.mjs +1 -1
  155. package/dist/core/seam.d.mts +17 -28
  156. package/dist/core/seam.mjs +7 -28
  157. package/dist/core/tokens.mjs +1 -1
  158. package/dist/core/view.d.mts +6 -3
  159. package/dist/core/view.mjs +18 -25
  160. package/dist/core/work.mjs +60 -15
  161. package/dist/engine/allotted-xdiff.mjs +3 -16
  162. package/dist/engine/combined.d.mts +3 -0
  163. package/dist/engine/combined.mjs +200 -185
  164. package/dist/engine/content.d.mts +2 -2
  165. package/dist/engine/content.mjs +1 -1
  166. package/dist/engine/failures.mjs +2 -1
  167. package/dist/engine/merge.mjs +7 -9
  168. package/dist/engine/reads.d.mts +2 -2
  169. package/dist/engine/reads.mjs +25 -17
  170. package/dist/engine/xdiff.d.mts +1 -1
  171. package/dist/engine/xdiff.mjs +1 -1
  172. package/dist/event-streams/event-streams.d.mts +1 -1
  173. package/dist/event-streams/event-streams.mjs +1 -1
  174. package/dist/event-streams/stream.d.mts +3 -3
  175. package/dist/event-streams/stream.mjs +39 -16
  176. package/dist/extend.d.mts +2 -7
  177. package/dist/extend.mjs +1 -4
  178. package/dist/http/answers.mjs +8 -5
  179. package/dist/http/core-parts.mjs +169 -96
  180. package/dist/http/handler.mjs +82 -10
  181. package/dist/http/node.d.mts +14 -1
  182. package/dist/http/node.mjs +56 -27
  183. package/dist/http/parts.d.mts +2 -0
  184. package/dist/http/push-upload-job.mjs +165 -47
  185. package/dist/http/push-uploads.mjs +37 -22
  186. package/dist/http/receive-pack.mjs +14 -53
  187. package/dist/http/request-snapshot.mjs +258 -0
  188. package/dist/http/upload-pack.mjs +25 -20
  189. package/dist/index.d.mts +36 -28
  190. package/dist/index.mjs +12 -3
  191. package/dist/lfs/answer.mjs +37 -0
  192. package/dist/lfs/base.d.mts +3 -1
  193. package/dist/lfs/base.mjs +25 -1
  194. package/dist/lfs/copy.d.mts +70 -8
  195. package/dist/lfs/copy.mjs +217 -21
  196. package/dist/lfs/layer.d.mts +19 -4
  197. package/dist/lfs/layer.mjs +25 -13
  198. package/dist/lfs/locks.mjs +3 -3
  199. package/dist/lfs/objects.d.mts +2 -1
  200. package/dist/lfs/objects.mjs +89 -19
  201. package/dist/lfs/pointers.mjs +2 -2
  202. package/dist/lfs/rows.d.mts +1 -1
  203. package/dist/lfs/rows.mjs +50 -9
  204. package/dist/lfs/upkeep.mjs +82 -17
  205. package/dist/lfs/uploaded.mjs +1 -1
  206. package/dist/lfs/wire.mjs +7 -32
  207. package/dist/merges/merges.mjs +19 -4
  208. package/dist/node.d.mts +2 -2
  209. package/dist/protocol/bytes/buffers.d.mts +1 -1
  210. package/dist/protocol/bytes/buffers.mjs +14 -6
  211. package/dist/protocol/bytes/deflate.d.mts +1 -1
  212. package/dist/protocol/bytes/deflate.mjs +1 -1
  213. package/dist/protocol/bytes/inflate.d.mts +1 -1
  214. package/dist/protocol/bytes/inflate.mjs +1 -1
  215. package/dist/protocol/bytes/reader.mjs +6 -1
  216. package/dist/protocol/bytes/sha1.d.mts +1 -1
  217. package/dist/protocol/bytes/sha1.mjs +1 -1
  218. package/dist/protocol/bytes/streams.mjs +27 -1
  219. package/dist/protocol/diff/read.d.mts +6 -4
  220. package/dist/protocol/diff/read.mjs +110 -11
  221. package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
  222. package/dist/protocol/objects/lfs-pointer.mjs +1 -3
  223. package/dist/protocol/objects/links-raw.mjs +24 -10
  224. package/dist/protocol/objects/tag.d.mts +1 -1
  225. package/dist/protocol/objects/tree.mjs +23 -6
  226. package/dist/protocol/packs/delta.d.mts +6 -3
  227. package/dist/protocol/packs/delta.mjs +96 -32
  228. package/dist/protocol/packs/graph.mjs +1 -1
  229. package/dist/protocol/packs/idx.d.mts +3 -2
  230. package/dist/protocol/packs/idx.mjs +23 -4
  231. package/dist/protocol/packs/parts.d.mts +4 -1
  232. package/dist/protocol/packs/parts.mjs +10 -7
  233. package/dist/protocol/packs/reader.d.mts +6 -1
  234. package/dist/protocol/packs/reader.mjs +4 -3
  235. package/dist/protocol/packs/write-error.d.mts +1 -1
  236. package/dist/protocol/packs/write-error.mjs +1 -1
  237. package/dist/protocol/packs/writer.mjs +26 -8
  238. package/dist/protocol/wire/advertisement.d.mts +1 -1
  239. package/dist/protocol/wire/advertisement.mjs +3 -2
  240. package/dist/protocol/wire/fetch.d.mts +1 -1
  241. package/dist/protocol/wire/fetch.mjs +1 -1
  242. package/dist/protocol/wire/lines.d.mts +9 -1
  243. package/dist/protocol/wire/lines.mjs +28 -1
  244. package/dist/protocol/wire/push-uploads.mjs +10 -7
  245. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  246. package/dist/protocol/wire/receive-pack.mjs +1 -1
  247. package/dist/protocol/wire/report-status.d.mts +1 -1
  248. package/dist/protocol/wire/report-status.mjs +1 -1
  249. package/dist/protocol/wire/v2.d.mts +1 -1
  250. package/dist/protocol/wire/v2.mjs +1 -1
  251. package/dist/queue/advance.mjs +48 -44
  252. package/dist/queue/base.d.mts +57 -0
  253. package/dist/queue/base.mjs +44 -0
  254. package/dist/queue/calls.mjs +54 -57
  255. package/dist/queue/commit.mjs +2 -2
  256. package/dist/queue/host.d.mts +2 -16
  257. package/dist/queue/host.mjs +2 -7
  258. package/dist/queue/layer.d.mts +2 -2
  259. package/dist/queue/layer.mjs +19 -8
  260. package/dist/queue/limits.mjs +2 -0
  261. package/dist/queue/push-option.mjs +9 -24
  262. package/dist/queue/schedule.mjs +2 -2
  263. package/dist/queue/search.mjs +1 -1
  264. package/dist/queue/state.mjs +3 -11
  265. package/dist/queue/trim.mjs +6 -4
  266. package/dist/rest/blobs.mjs +29 -5
  267. package/dist/rest/caller.d.mts +4 -4271
  268. package/dist/rest/caller.mjs +4 -0
  269. package/dist/rest/client.d.mts +9 -6
  270. package/dist/rest/client.mjs +25 -8
  271. package/dist/rest/errors.mjs +1 -1
  272. package/dist/rest/handler.mjs +2 -2
  273. package/dist/rest/handlers.mjs +66 -11
  274. package/dist/rest/layer.d.mts +2 -2
  275. package/dist/rest/layer.mjs +6 -13
  276. package/dist/rest/listen.mjs +2 -2
  277. package/dist/rest/me.d.mts +3 -432
  278. package/dist/rest/refs.mjs +1 -1
  279. package/dist/server/check-fetch.mjs +3 -3
  280. package/dist/server/edge-node.d.mts +11 -8
  281. package/dist/server/edge-node.mjs +9 -6
  282. package/dist/server/edge.d.mts +21 -7
  283. package/dist/server/edge.mjs +56 -11
  284. package/dist/server/extension.mjs +1 -1
  285. package/dist/server/git-layer.d.mts +5 -6
  286. package/dist/server/git-layer.mjs +28 -23
  287. package/dist/server/git-namespace.d.mts +4 -3
  288. package/dist/server/git-namespace.mjs +3 -2
  289. package/dist/server/lifecycle.mjs +19 -107
  290. package/dist/server/registry.mjs +24 -13
  291. package/dist/server/server.mjs +249 -371
  292. package/dist/signin/context.d.mts +1 -2
  293. package/dist/signin/context.mjs +1 -1
  294. package/dist/signin/forms.mjs +1 -1
  295. package/dist/signin/grants.d.mts +2 -2
  296. package/dist/signin/grants.mjs +1 -1
  297. package/dist/signin/layer.d.mts +1 -1
  298. package/dist/signin/layer.mjs +1 -1
  299. package/dist/signin/wire.mjs +1 -1
  300. package/dist/storage/allotted.mjs +22 -12
  301. package/dist/storage/batch-upkeep.mjs +293 -0
  302. package/dist/storage/batches.d.mts +7 -0
  303. package/dist/storage/batches.mjs +347 -0
  304. package/dist/storage/budget.mjs +23 -1
  305. package/dist/storage/calls.d.mts +2 -3
  306. package/dist/storage/calls.mjs +166 -182
  307. package/dist/storage/charged-cache.mjs +180 -0
  308. package/dist/storage/chunks.d.mts +9 -0
  309. package/dist/storage/chunks.mjs +410 -0
  310. package/dist/storage/clean-up.mjs +72 -9
  311. package/dist/storage/counted-bucket.mjs +35 -13
  312. package/dist/storage/fetch-row-cache.d.mts +6 -0
  313. package/dist/storage/fetch-row-cache.mjs +211 -0
  314. package/dist/storage/fetch.d.mts +2 -0
  315. package/dist/storage/fetch.mjs +339 -450
  316. package/dist/storage/held-types.d.mts +0 -1
  317. package/dist/storage/host-bucket.mjs +10 -6
  318. package/dist/storage/id-mix.mjs +19 -5
  319. package/dist/storage/index-bitmaps.mjs +86 -51
  320. package/dist/storage/index-build.d.mts +2 -4
  321. package/dist/storage/index-build.mjs +324 -67
  322. package/dist/storage/index-fetch.d.mts +3 -1
  323. package/dist/storage/index-fetch.mjs +163 -83
  324. package/dist/storage/index-files.d.mts +3 -0
  325. package/dist/storage/index-files.mjs +10 -5
  326. package/dist/storage/index-graph.mjs +73 -23
  327. package/dist/storage/index-layers.mjs +55 -25
  328. package/dist/storage/index-reach.mjs +15 -22
  329. package/dist/storage/index-remap.mjs +200 -64
  330. package/dist/storage/index-whole.d.mts +7 -0
  331. package/dist/storage/index-whole.mjs +235 -0
  332. package/dist/storage/largest-files.mjs +1 -7
  333. package/dist/storage/layout.mjs +40 -1
  334. package/dist/storage/lfs-pointers.mjs +1 -6
  335. package/dist/storage/link-join.mjs +55 -16
  336. package/dist/storage/list-source.d.mts +7 -0
  337. package/dist/storage/list-source.mjs +288 -0
  338. package/dist/storage/loose.d.mts +10 -7
  339. package/dist/storage/loose.mjs +293 -82
  340. package/dist/storage/memory-budget.mjs +242 -26
  341. package/dist/storage/merge-cut.mjs +9 -6
  342. package/dist/storage/merge-fence.mjs +1 -1
  343. package/dist/storage/merge-plan.mjs +3 -2
  344. package/dist/storage/merge-row.mjs +8 -2
  345. package/dist/storage/merge-stream.mjs +164 -25
  346. package/dist/storage/merge-walk.mjs +8 -4
  347. package/dist/storage/merge-write.mjs +1 -1
  348. package/dist/storage/merge.d.mts +3 -4
  349. package/dist/storage/merge.mjs +3 -3
  350. package/dist/storage/object-rows.d.mts +4 -3
  351. package/dist/storage/object-rows.mjs +545 -84
  352. package/dist/storage/oid-table.mjs +171 -0
  353. package/dist/storage/pack-order.mjs +104 -47
  354. package/dist/storage/pack-ranges.d.mts +1 -2
  355. package/dist/storage/pack-ranges.mjs +48 -21
  356. package/dist/storage/pack-reads.d.mts +6 -3
  357. package/dist/storage/pack-reads.mjs +378 -98
  358. package/dist/storage/pack-receive.d.mts +2 -3
  359. package/dist/storage/pack-receive.mjs +22 -18
  360. package/dist/storage/packs.d.mts +2 -2
  361. package/dist/storage/packs.mjs +587 -156
  362. package/dist/storage/placed-reads.mjs +34 -17
  363. package/dist/storage/plan-columns.d.mts +4 -0
  364. package/dist/storage/plan-columns.mjs +238 -0
  365. package/dist/storage/prune-keep.mjs +134 -41
  366. package/dist/storage/prune-seen.mjs +1 -1
  367. package/dist/storage/prune-walk.mjs +203 -63
  368. package/dist/storage/prune.mjs +197 -121
  369. package/dist/storage/push-allotment.mjs +116 -25
  370. package/dist/storage/push-uploads.mjs +196 -58
  371. package/dist/storage/pushed-commits.mjs +24 -3
  372. package/dist/storage/quarantine.d.mts +3 -4
  373. package/dist/storage/range-cache.mjs +293 -41
  374. package/dist/storage/raw-ids.mjs +39 -10
  375. package/dist/storage/ready.d.mts +3 -4
  376. package/dist/storage/ready.mjs +121 -43
  377. package/dist/storage/receive-bounds.mjs +50 -13
  378. package/dist/storage/receive-cache.d.mts +7 -0
  379. package/dist/storage/receive-cache.mjs +147 -0
  380. package/dist/storage/receive-files.mjs +1 -1
  381. package/dist/storage/receive-links.mjs +1 -1
  382. package/dist/storage/receive-state.d.mts +2 -2
  383. package/dist/storage/receive-state.mjs +6 -8
  384. package/dist/storage/receive-steps.d.mts +20 -0
  385. package/dist/storage/receive-steps.mjs +298 -13
  386. package/dist/storage/repack-backlog.mjs +1 -3
  387. package/dist/storage/repack-contained.mjs +2 -2
  388. package/dist/storage/repack-job.mjs +1 -1
  389. package/dist/storage/repack.d.mts +3 -4
  390. package/dist/storage/repack.mjs +54 -9
  391. package/dist/storage/request-cache.mjs +57 -0
  392. package/dist/storage/roots.mjs +1 -24
  393. package/dist/storage/rows.d.mts +3 -3
  394. package/dist/storage/rows.mjs +2 -2
  395. package/dist/storage/runs.d.mts +2 -2
  396. package/dist/storage/runs.mjs +196 -44
  397. package/dist/storage/send-list.d.mts +1 -0
  398. package/dist/storage/send-list.mjs +112 -31
  399. package/dist/storage/single-flight.mjs +13 -7
  400. package/dist/storage/stream-whole.mjs +188 -66
  401. package/dist/storage/swap-walk.mjs +1 -1
  402. package/dist/storage/unpack.mjs +919 -199
  403. package/dist/storage/visible.mjs +112 -34
  404. package/dist/storage/walk.mjs +193 -38
  405. package/dist/storage/wants.mjs +27 -63
  406. package/dist/store/bodies.mjs +38 -0
  407. package/dist/store/call-count.d.mts +10 -14
  408. package/dist/store/call-count.mjs +58 -57
  409. package/dist/store/catalogue.d.mts +2 -2
  410. package/dist/store/catalogue.mjs +158 -36
  411. package/dist/store/crossing.mjs +1 -9
  412. package/dist/store/cursor-seal.d.mts +1 -2
  413. package/dist/store/cursor-seal.mjs +17 -7
  414. package/dist/store/door.mjs +188 -0
  415. package/dist/store/errors.d.mts +4 -5
  416. package/dist/store/errors.mjs +119 -49
  417. package/dist/store/git-store.mjs +30 -7
  418. package/dist/store/job-try.mjs +98 -40
  419. package/dist/store/list-job.mjs +32 -20
  420. package/dist/store/outbox.d.mts +2 -2
  421. package/dist/store/outbox.mjs +2 -2
  422. package/dist/store/queue-jobs.mjs +6 -12
  423. package/dist/store/records.d.mts +5 -2
  424. package/dist/store/records.mjs +5 -2
  425. package/dist/store/ref-rows.d.mts +2 -2
  426. package/dist/store/ref-rows.mjs +2 -2
  427. package/dist/store/repo-record.d.mts +2 -3
  428. package/dist/store/repo-record.mjs +34 -22
  429. package/dist/store/request-snapshot.mjs +5 -0
  430. package/dist/store/reservations.mjs +3 -3
  431. package/dist/store/scopes.mjs +11 -0
  432. package/dist/store/settle.mjs +4 -4
  433. package/dist/store/topic-jobs.mjs +5 -11
  434. package/dist/sync/bound.d.mts +3 -3
  435. package/dist/sync/bound.mjs +10 -7
  436. package/dist/sync/github.mjs +67 -69
  437. package/dist/sync/http.mjs +1 -1
  438. package/dist/sync/import.mjs +205 -57
  439. package/dist/sync/layer.d.mts +1 -1
  440. package/dist/sync/layer.mjs +6 -6
  441. package/dist/sync/lfs-batch.mjs +5 -6
  442. package/dist/sync/lfs-copy.mjs +191 -20
  443. package/dist/sync/mirror.mjs +34 -36
  444. package/dist/sync/said.mjs +17 -38
  445. package/dist/sync/step.mjs +292 -102
  446. package/dist/sync/tries.mjs +34 -15
  447. package/dist/sync.d.mts +2 -2
  448. package/dist/sync.mjs +2 -2
  449. package/dist/topics/advance.mjs +12 -13
  450. package/dist/topics/base.d.mts +15 -0
  451. package/dist/topics/base.mjs +8 -0
  452. package/dist/topics/calls.mjs +1 -1
  453. package/dist/topics/host.mjs +1 -1
  454. package/dist/topics/layer.d.mts +17 -21
  455. package/dist/topics/layer.mjs +2 -3
  456. package/dist/topics/members.mjs +4 -4
  457. package/dist/topics/public.d.mts +2 -1
  458. package/dist/topics/topic.mjs +2 -2
  459. package/package.json +5 -14
  460. package/dist/auth/helpers.mjs +0 -17
  461. package/dist/auth.d.mts +0 -5
  462. package/dist/auth.mjs +0 -5
  463. package/dist/contracts/promises.d.mts +0 -39
  464. package/dist/core/call-names.d.mts +0 -3
  465. package/dist/core/clock.mjs +0 -18
  466. package/dist/core/promise.mjs +0 -74
  467. package/dist/core/rules/commit-changes.d.mts +0 -13
  468. package/dist/effect.d.mts +0 -18
  469. package/dist/effect.mjs +0 -16
  470. package/dist/lfs/calls.mjs +0 -26
  471. package/dist/rest/api.d.mts +0 -23
  472. package/dist/rest/blobs.d.mts +0 -833
  473. package/dist/rest/commits.d.mts +0 -3543
  474. package/dist/rest/errors.d.mts +0 -2124
  475. package/dist/rest/events.d.mts +0 -426
  476. package/dist/rest/files.d.mts +0 -1342
  477. package/dist/rest/forks.d.mts +0 -2160
  478. package/dist/rest/handlers.d.mts +0 -8
  479. package/dist/rest/merges.d.mts +0 -477
  480. package/dist/rest/queue.d.mts +0 -5917
  481. package/dist/rest/refs.d.mts +0 -2988
  482. package/dist/rest/repos.d.mts +0 -2567
  483. package/dist/rest/tags.d.mts +0 -1316
  484. package/dist/rest/tokens.d.mts +0 -2614
  485. package/dist/rest/topics.d.mts +0 -2224
  486. package/dist/rest/trees.d.mts +0 -1709
  487. package/dist/rest/work.d.mts +0 -1695
  488. package/dist/server/joined.d.mts +0 -82
  489. package/dist/server/joined.mjs +0 -68
  490. package/dist/server/lifecycle.d.mts +0 -2
  491. package/dist/store/promises.d.mts +0 -11
  492. package/dist/store/promises.mjs +0 -327
@@ -1,7 +1,7 @@
1
1
  import { hostEffect, logRefusal, rejectedError } from "../../auth/host-function.mjs";
2
2
  import { register } from "../../contracts/git.mjs";
3
3
  import { handlersOf } from "../../contracts/git-hooks.mjs";
4
- import { millis } from "../../contracts/promises.mjs";
4
+ import { millis } from "../../contracts/time.mjs";
5
5
  import { checkedAnswer, plainAnswer, pushContextOf } from "../rules/context.mjs";
6
6
  import * as Effect from "effect/Effect";
7
7
  import * as Layer from "effect/Layer";
@@ -46,7 +46,7 @@ const runHookGroups = /* @__PURE__ */ Effect.fnUntraced(function* (groups, check
46
46
  const lost = left.length < write.updates.length;
47
47
  if (left.length === 0 || write.atomic && lost) return void 0;
48
48
  const { about } = checking;
49
- const input = pushContextOf(checking, left, {
49
+ const { input, provide } = pushContextOf(checking, left, {
50
50
  key: "",
51
51
  updates: left
52
52
  }, { atomic: write.atomic });
@@ -58,7 +58,7 @@ const runHookGroups = /* @__PURE__ */ Effect.fnUntraced(function* (groups, check
58
58
  label,
59
59
  timeout: handler.timeout
60
60
  };
61
- const call = hostEffect("hooks", about, checkedAnswer(label, plainAnswer, () => check(input)), options);
61
+ const call = hostEffect("hooks", about, provide(checkedAnswer(label, plainAnswer, () => check(input))), options);
62
62
  const refusal = yield* Effect.matchEffect(call, {
63
63
  onFailure: (error) => Effect.succeed(error),
64
64
  onSuccess: (answer) => {
@@ -1,20 +1,21 @@
1
- import { ImportLfsReason, SyncSource } from "../contracts/sync.mjs";
1
+ import { fail, gitError } from "../contracts/result.mjs";
2
+ import { ImportDepth, ImportLfsReason, SyncSource } from "../contracts/sync.mjs";
2
3
  import { readAsked } from "./asked.mjs";
3
- import { KeptError, keptError } from "./receipts.mjs";
4
+ import { KeptError } from "./receipts.mjs";
4
5
  import { SavedCaller } from "./saved-callers.mjs";
5
6
  import { hexOf } from "../protocol/bytes/hex.mjs";
7
+ import { Sha256State } from "../protocol/bytes/sha256.mjs";
6
8
  import { oidBytes } from "../protocol/packs/idx.mjs";
7
- import { decodeRow, storeCall } from "../store/errors.mjs";
8
- import { importJobName } from "../store/records.mjs";
9
+ import { decodeRow, storeCall, storeCommit } from "../store/errors.mjs";
10
+ import { RepoRootsRow, importJobName } from "../store/records.mjs";
9
11
  import { refRowBytes, storesPeel } from "../store/ref-rows.mjs";
10
12
  import { isPackId } from "../storage/layout.mjs";
11
- import { receiveKey } from "../storage/receive-steps.mjs";
13
+ import { StagePart, receiveKey } from "../storage/receive-steps.mjs";
12
14
  import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
13
- import { gitError } from "../contracts/result.mjs";
14
- import * as Effect from "effect/Effect";
15
+ import { jsonBytes } from "@ref0/infra";
15
16
  import * as Schema from "effect/Schema";
17
+ import * as Effect from "effect/Effect";
16
18
  import * as Result from "effect/Result";
17
- import { jsonBytes } from "@ref0/infra";
18
19
  import * as Base64 from "effect/encoding/Base64";
19
20
  // src/core/imports.ts
20
21
  /**
@@ -29,7 +30,9 @@ import * as Base64 from "effect/encoding/Base64";
29
30
  * the tips, which `publish` makes the repo's default branch, in the last page's commit;
30
31
  * - `roots`: where the history copied so far stops, the remote's `shallow` lines; `deepest`, how
31
32
  * many commits from each tip it holds; `step`, how many more the next segment asks for;
32
- * - `copied`: whether the history is whole, so the next step publishes;
33
+ * - `depth`: how many commits from each tip the import asked for, none for the whole history;
34
+ * - `copied`: whether the history is whole, as deep as `depth` asks, or as deep as the remote
35
+ * holds it, so the next step publishes, writing `roots`, when any, as the repo's own;
33
36
  * - `objects` and `bytes`: what the steps have received;
34
37
  * - `receiving`: a segment staged and received in steps, as `ImportReceiving` says;
35
38
  * - `restaged`: whether clean-up ended the stage of the segment the import fetches or receives
@@ -57,11 +60,28 @@ const ImportReceiving = /* @__PURE__ */ Schema.Struct({
57
60
  })
58
61
  });
59
62
  /**
63
+ * The copy of one object past a step's bytes, in parts across tries (#2989): its `oid` and `size`,
64
+ * its stage's `key` and staging row `staged`, the multipart upload's `token`, the `offset` its
65
+ * `parts` reach, and SHA-256's running state over those bytes, so a try goes on from the last part
66
+ * and the whole is checked against the oid before the upload completes.
67
+ */
68
+ const ImportLfsCopying = /* @__PURE__ */ Schema.Struct({
69
+ oid: Schema.String,
70
+ size: Schema.Int,
71
+ key: Schema.String,
72
+ staged: Schema.String,
73
+ token: Schema.String,
74
+ offset: Schema.Int,
75
+ parts: Schema.Array(StagePart),
76
+ sha256: Sha256State
77
+ });
78
+ /**
60
79
  * An import's copy of the Git LFS objects its history points at: `pages` of pointers, which each
61
80
  * segment's landing writes beside the record as its receive found them, as `lfsPageKey` says; the
62
- * copy's cursor, entry `entry` of page `page`; and what it has done so far, `copied` objects of
81
+ * copy's cursor, entry `entry` of page `page`; what it has done so far, `copied` objects of
63
82
  * `bytes`, `missing`, those the source didn't give, and `named`, how many of them the record
64
- * names, as `missedCounted` counts them.
83
+ * names, as `missedCounted` counts them; and `copying`, the object at the cursor while it goes in
84
+ * parts.
65
85
  */
66
86
  const ImportLfs = /* @__PURE__ */ Schema.Struct({
67
87
  pages: Schema.Int,
@@ -70,7 +90,8 @@ const ImportLfs = /* @__PURE__ */ Schema.Struct({
70
90
  copied: Schema.Int,
71
91
  bytes: Schema.Int,
72
92
  missing: Schema.Int,
73
- named: Schema.Int
93
+ named: Schema.Int,
94
+ copying: Schema.optionalKey(ImportLfsCopying)
74
95
  });
75
96
  /** An import's LFS copy before its first page. */
76
97
  const noImportLfs = {
@@ -82,6 +103,23 @@ const noImportLfs = {
82
103
  missing: 0,
83
104
  named: 0
84
105
  };
106
+ /** Keyed deepen receipt reference stored on `ImportDeepen` so publish, fail, and cancel update it atomically. */
107
+ const DeepenReceipt = /* @__PURE__ */ Schema.Struct({
108
+ id: Schema.String,
109
+ input: Schema.String,
110
+ at: Schema.Int
111
+ });
112
+ /**
113
+ * A deepen's own state on `imports/self`, absent for an initial import: `run`, the execution's
114
+ * unique ID; `more`, how many commits deeper to fetch past the starting roots (left out for an
115
+ * unshallow); and `receipt`, the keyed receipt to record the terminal outcome in. The starting
116
+ * roots themselves live in `imports/start-roots` so `imports/self` holds at most two root arrays.
117
+ */
118
+ const ImportDeepen = /* @__PURE__ */ Schema.Struct({
119
+ run: Schema.String,
120
+ more: Schema.optionalKey(ImportDepth),
121
+ receipt: Schema.optionalKey(DeepenReceipt)
122
+ });
85
123
  /**
86
124
  * An import's record. `by`: who started it, as `SavedCaller` keeps them, asked again before each
87
125
  * step, so the import fetches, publishes and offers the remote only what they may still see.
@@ -89,6 +127,8 @@ const noImportLfs = {
89
127
  const ImportRow = /* @__PURE__ */ Schema.Struct({
90
128
  source: SyncSource,
91
129
  by: SavedCaller,
130
+ depth: Schema.optionalKey(ImportDepth),
131
+ deepen: Schema.optionalKey(ImportDeepen),
92
132
  state: Schema.Literals([
93
133
  "running",
94
134
  "done",
@@ -124,6 +164,38 @@ const cancelKey = {
124
164
  collection: collections.imports,
125
165
  id: "cancel"
126
166
  };
167
+ /**
168
+ * A deepen's immutable starting shallow roots, stored beside `imports/self` so staged `ImportRow`
169
+ * commits hold at most two root arrays (`row.roots` and `receiving.lands.roots`) and fit infra's
170
+ * 1 MiB value limit across the full supported root frontier.
171
+ */
172
+ const startRootsKey = {
173
+ collection: collections.imports,
174
+ id: "start-roots"
175
+ };
176
+ const startRootsRow = (roots) => ({
177
+ ...startRootsKey,
178
+ value: { roots: [...roots] }
179
+ });
180
+ /** Decodes a deepen's starting shallow roots row read from `imports/start-roots`. */
181
+ const startRootsOf = (rows) => {
182
+ const held = rows?.[0];
183
+ return held === void 0 ? fail("DATA_LOSS", "Deepen start roots missing", { hint: failedHint }) : Effect.map(decodeRow(RepoRootsRow, held, "Deepen start roots"), (row) => row.roots);
184
+ };
185
+ /** Optional receipt row updating a keyed deepen's receipt with its terminal `info` or `error`. */
186
+ const deepenReceiptPut = (deepen, outcome) => deepen?.receipt === void 0 ? [] : [{
187
+ collection: collections.receipts,
188
+ id: deepen.receipt.id,
189
+ value: {
190
+ input: deepen.receipt.input,
191
+ at: deepen.receipt.at,
192
+ answer: {
193
+ kind: "deepen",
194
+ run: deepen.run,
195
+ ...outcome
196
+ }
197
+ }
198
+ }];
127
199
  const importRow = (value) => ({
128
200
  ...importKey,
129
201
  value
@@ -227,13 +299,13 @@ const missedCounted = (lfs, missed, held) => {
227
299
  */
228
300
  const lfsMissedHeld = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, oids) {
229
301
  if (oids.length === 0) return /* @__PURE__ */ new Set();
230
- const snapshot = yield* storeCall(() => store.read(repoScope(internalId), oids.map(lfsMissedKey)));
302
+ const snapshot = yield* storeCall(store.read(repoScope(internalId), oids.map(lfsMissedKey)));
231
303
  return new Set(snapshot.results.flatMap(([row]) => row === void 0 ? [] : [row.id.slice(12)]));
232
304
  });
233
305
  const lfsPageGone = (page) => gitError("DATA_LOSS", `The import's page ${page} of LFS pointers is gone`, { hint: failedHint });
234
306
  /** Page `page` of the import's LFS pointers, as the table lays them out. */
235
307
  const readLfsPage = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, page) {
236
- const [[held] = []] = (yield* storeCall(() => store.read(repoScope(internalId), [lfsPageKey(page)]))).results;
308
+ const [[held] = []] = (yield* storeCall(store.read(repoScope(internalId), [lfsPageKey(page)]))).results;
237
309
  if (held === void 0) return yield* Effect.fail(lfsPageGone(page));
238
310
  const { pointers } = yield* decodeRow(LfsPage, held, `The import's LFS page ${page}`);
239
311
  const bytes = Base64.decode(pointers);
@@ -245,8 +317,9 @@ const readLfsPage = /* @__PURE__ */ Effect.fnUntraced(function* (store, internal
245
317
  * receiving in steps, whose keys the quarantine's clean-up takes, and the pages of tips it hasn't
246
318
  * published.
247
319
  */
248
- const importEndDeletes = (row) => [
320
+ const importEndDeletes = (row, keepStartRoots = false) => [
249
321
  { ...cutKey },
322
+ ...keepStartRoots ? [] : [{ ...startRootsKey }],
250
323
  ...row?.receiving === void 0 ? [] : [receiveKey(row.receiving.pack)],
251
324
  ...tipPageKeys(row?.publishedPages ?? 0, row?.tipPages ?? 0),
252
325
  ...lfsPageKeys(row?.lfs?.page ?? 0, row?.lfs?.pages ?? 0)
@@ -256,7 +329,7 @@ const pageMissing = (page) => gitError("DATA_LOSS", `The import's page ${page} o
256
329
  const readTipPages = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, from, to) {
257
330
  const keys = tipPageKeys(from, to);
258
331
  if (keys.length === 0) return [];
259
- const snapshot = yield* storeCall(() => store.read(repoScope(internalId), keys));
332
+ const snapshot = yield* storeCall(store.read(repoScope(internalId), keys));
260
333
  return yield* Effect.forEach(snapshot.results, ([held], at) => held === void 0 ? Effect.fail(pageMissing(from + at)) : decodeRow(TipPage, held, "Import tip page"));
261
334
  });
262
335
  /**
@@ -337,16 +410,26 @@ const failedRow = (row, error) => ({
337
410
  });
338
411
  /** What a failed import's error says to do: no try comes after the last, whatever it said. */
339
412
  const failedHint = "Delete the repo, then import it again";
340
- const stoppedTry = keptError(gitError("UNAVAILABLE", "The import's last try stopped", { hint: failedHint }));
413
+ const stoppedTry = {
414
+ code: "UNAVAILABLE",
415
+ message: "The import's last try stopped",
416
+ hint: failedHint
417
+ };
418
+ const stoppedDeepen = {
419
+ code: "UNAVAILABLE",
420
+ message: "The deepen's last try stopped",
421
+ hint: "Deepen again with a new key"
422
+ };
341
423
  /**
342
424
  * The repo's import row, cancel row and cut, in one read: with `asked`, its record too, held to it
343
- * as `asAsked` says.
425
+ * as `asAsked` says, and any `extra` reads in the same snapshot.
344
426
  */
345
- const readImport = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, asked) {
427
+ const readImport = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, asked, extra = []) {
346
428
  const reads = [
347
429
  { ...importKey },
348
430
  { ...cancelKey },
349
- { ...cutKey }
431
+ { ...cutKey },
432
+ ...extra
350
433
  ];
351
434
  const snapshot = yield* readAsked(store, internalId, reads, [], asked);
352
435
  const [[own] = [], [cancel] = [], [held] = []] = snapshot.results;
@@ -356,25 +439,27 @@ const readImport = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalI
356
439
  row,
357
440
  cancelled: cancel !== void 0,
358
441
  cut,
359
- version: snapshot.version
442
+ version: snapshot.version,
443
+ extra: snapshot.results.slice(3)
360
444
  };
361
445
  });
446
+ /** What a repo's import's state reads of its scope: its row, its cancel row and its missed LFS objects. */
447
+ const importReads = [
448
+ { ...importKey },
449
+ { ...cancelKey },
450
+ {
451
+ collection: collections.imports,
452
+ prefix: lfsMissedPrefix,
453
+ limit: importLfsMissedMost
454
+ }
455
+ ];
362
456
  /**
363
- * `JoinedCalls.importState`: the repo's import as its row, cancel row and missed LFS objects hold
364
- * it, in one read, or `undefined` for a repo no import made. A running row whose job has gone
365
- * stays `running`: this read writes nothing, where `importLive` commits it `failed`.
457
+ * The repo's import as `importReads`' `results` hold it, its row, cancel row and missed LFS
458
+ * objects, or `undefined` for a repo no import made. A running row whose job has gone stays
459
+ * `running`: this read writes nothing, where `importLive` commits it `failed`.
366
460
  */
367
- const importStateOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId) {
368
- const reads = [
369
- { ...importKey },
370
- { ...cancelKey },
371
- {
372
- collection: collections.imports,
373
- prefix: lfsMissedPrefix,
374
- limit: importLfsMissedMost
375
- }
376
- ];
377
- const [[own] = [], [cancel] = [], missedRows = []] = (yield* readAsked(store, internalId, reads, [])).results;
461
+ const importStatusOf = /* @__PURE__ */ Effect.fnUntraced(function* (results) {
462
+ const [[own] = [], [cancel] = [], missedRows = []] = results;
378
463
  if (own === void 0) return void 0;
379
464
  const row = yield* decodeRow(ImportRow, own, "Import");
380
465
  const state = row.state === "running" && cancel !== void 0 ? "cancelled" : row.state;
@@ -400,12 +485,12 @@ const importStateOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, intern
400
485
  };
401
486
  });
402
487
  /** Whether the repo's `sync.import` job is waiting or running: a try is due or under way. */
403
- const jobLive = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId) {
488
+ const importJobLive = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId) {
404
489
  const scope = repoScope(internalId);
405
490
  let after;
406
491
  for (;;) {
407
492
  const page = after === void 0 ? {} : { page: { after } };
408
- const listing = yield* storeCall(() => store.list(scope, page));
493
+ const listing = yield* storeCall(store.jobs.list(scope, page));
409
494
  const job = listing.items.find((item) => item.name === importJobName);
410
495
  if (job !== void 0) return job.state !== "failed";
411
496
  if (listing.next === void 0) return false;
@@ -426,14 +511,15 @@ const importLive = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalI
426
511
  const read = yield* readImport(store, internalId);
427
512
  const { row } = read;
428
513
  if (row?.state !== "running" || read.cancelled) return false;
429
- if (yield* jobLive(store, internalId)) return true;
430
- if ((yield* storeCall(() => store.commit(repoScope(internalId), {
514
+ if (yield* importJobLive(store, internalId)) return true;
515
+ const stopped = row.deepen !== void 0 ? stoppedDeepen : stoppedTry;
516
+ if ((yield* storeCommit(store.commit(repoScope(internalId), {
431
517
  id: newChangeId(),
432
518
  expect: read.version,
433
- put: [importRow(failedRow(row, stoppedTry))],
519
+ put: [importRow(failedRow(row, stopped)), ...deepenReceiptPut(row.deepen, { error: stopped })],
434
520
  delete: importEndDeletes(row)
435
521
  }))).ok) return false;
436
522
  }
437
523
  return true;
438
524
  });
439
- export { ImportLfs, ImportReceiving, ImportRow, cancelKey, cutKey, cutRow, failedHint, failedRow, importEndDeletes, importKey, importLfsMissedMost, importLfsPagesMost, importLive, importRow, importStateOf, lfsMissedHeld, lfsPageKey, lfsPageRow, missedCounted, noImportLfs, readImport, readLfsPage, readTipPages, stoppedTry, tipPageKey, tipPageRow, tipPagesOf, tipRowBytes };
525
+ export { DeepenReceipt, ImportDeepen, ImportLfs, ImportLfsCopying, ImportReceiving, ImportRow, cancelKey, cutKey, cutRow, deepenReceiptPut, failedHint, failedRow, importEndDeletes, importJobLive, importKey, importLfsMissedMost, importLfsPagesMost, importLive, importReads, importRow, importStatusOf, lfsMissedHeld, lfsPageKey, lfsPageRow, missedCounted, noImportLfs, readImport, readLfsPage, readTipPages, startRootsKey, startRootsOf, startRootsRow, stoppedDeepen, stoppedTry, tipPageKey, tipPageRow, tipPagesOf, tipRowBytes };
@@ -1,26 +1,33 @@
1
1
  import { keepsEvents } from "../contracts/events.mjs";
2
- import { indexRowOf } from "../storage/index-build.mjs";
2
+ import { indexRowOf, sliceBounds } from "../storage/index-build.mjs";
3
+ import "../storage/receive-bounds.mjs";
3
4
  import { liftsHolds } from "../storage/index-remap.mjs";
4
5
  import { indexRowKey } from "../storage/layout.mjs";
5
- import { resultCall, storeCall } from "../store/errors.mjs";
6
+ import { decodeRow, storeCommit } from "../store/errors.mjs";
6
7
  import { decodePacks } from "../store/git-store.mjs";
8
+ import { LooseTally } from "../store/records.mjs";
7
9
  import { appendEvents, decodeOutbox, outboxReads, repoEnvelope } from "../store/outbox.mjs";
8
10
  import { WholeRepo, wholeRefs } from "../store/ref-rows.mjs";
9
11
  import { readRecord, rootsOf } from "../store/repo-record.mjs";
10
- import { budgetedInput } from "../store/call-count.mjs";
11
- import { gitJob } from "../store/job-try.mjs";
12
- import { collections, jobRepo, newChangeId, repoRootsKey, repoScope } from "../store/scopes.mjs";
12
+ import { budgetMade, budgetMost, budgetedInput, callScope, nestsIn, spentBudget } from "../store/call-count.mjs";
13
+ import { ownSpentOf, spentOf } from "../contracts/calls-spent.mjs";
14
+ import { gitJob, jobTryTimeout } from "../store/job-try.mjs";
15
+ import { collections, jobRepo, looseKey, newChangeId, repoRootsKey, repoScope } from "../store/scopes.mjs";
13
16
  import { settleName } from "../store/settle.mjs";
14
17
  import { SealedObjects } from "./view.mjs";
15
18
  import { fail } from "../contracts/result.mjs";
16
- import * as Effect from "effect/Effect";
17
- import * as Schema from "effect/Schema";
18
19
  import { CurrentJob, Job } from "@ref0/infra";
20
+ import * as Schema from "effect/Schema";
21
+ import * as Effect from "effect/Effect";
22
+ import * as Cause from "effect/Cause";
23
+ import * as Exit from "effect/Exit";
24
+ import * as Equal from "effect/Equal";
19
25
  import * as DateTime from "effect/DateTime";
20
26
  // src/core/index-job.ts
21
27
  /**
22
28
  * `git.index`, the reachability index's build (#597) and its upkeep (#596): one step a try, as
23
- * the objects' `index` says, its cursor in the row's data, until the `index` row the core
29
+ * the objects' `index` says, or on a small repo several back to back while the try's calls and
30
+ * CPU allow (#2525), its cursor in the row's data, until the `index` row the core
24
31
  * commits, then a try that builds again if what it covers moved since, or prunes what the build
25
32
  * replaced. Every commit that moves a ref saves it, but while a refusal at the server's bound
26
33
  * stands: a push, an API write, an import, a sync or a fork's. A repo's delete saves it too, and
@@ -56,7 +63,8 @@ const tryReads = [
56
63
  { collection: collections.refs },
57
64
  { collection: collections.packs },
58
65
  indexRowKey,
59
- repoRootsKey
66
+ repoRootsKey,
67
+ looseKey
60
68
  ];
61
69
  /** A try's reads with `events`: the outbox a refusal's event goes to, too. */
62
70
  const eventReads = [...tryReads, ...outboxReads];
@@ -69,6 +77,12 @@ const refusalOf = (landed, before) => {
69
77
  if (landed.state === "too-large") return "too-large";
70
78
  return landed.state === "refused" ? "spent" : void 0;
71
79
  };
80
+ /** The states a row that holds a refusal reads as: a refused row's, or a built one's refused update. */
81
+ const refusing = /* @__PURE__ */ new Set([
82
+ "refused",
83
+ "retry",
84
+ "too-large"
85
+ ]);
72
86
  /**
73
87
  * What a refusal's event says, in the core's words alone: a row's reason may name the host's
74
88
  * step, which no event carries (Q851).
@@ -82,9 +96,12 @@ const refusalError = (refusal) => refusal === "spent" ? `git.index ran out of it
82
96
  * `round` is the job's, from its key. With `failed`, the round's tries are spent: the step
83
97
  * answers a refused row with that reason, and builds nothing. A step that answers `moved` is
84
98
  * asked once more over a fresh read, with `lastCheck`, and its answer is the try's: no `moved`
85
- * leaves the job.
99
+ * leaves the job. A `chained` step, one after another in the same try, commits no refusal: its
100
+ * calls are what the steps before it left, so its row ends `withheld`, and the try ends with the
101
+ * step before it kept, for the next try to run first with the whole budget (#2525).
86
102
  */
87
- const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, internalId, data, signal, round, failed) {
103
+ const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, internalId, data, signal, round, options = {}) {
104
+ const { failed, chained } = options;
88
105
  const index = SealedObjects.whole(parts.objects, indexWhole).index;
89
106
  if (index === void 0) return {
90
107
  ended: "none",
@@ -99,7 +116,7 @@ const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
99
116
  at,
100
117
  lastCheck
101
118
  });
102
- const stepOf = (asked) => Effect.flatMap(budgetedInput(asked.input), (input) => resultCall(() => index.step(asked.listed, input)));
119
+ const stepOf = (asked) => Effect.flatMap(budgetedInput(asked.input), (input) => index.step(asked.listed, input));
103
120
  const first = yield* read();
104
121
  if (first === void 0) return {
105
122
  ended: "none",
@@ -113,13 +130,15 @@ const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
113
130
  };
114
131
  const step = tried === first ? asked : yield* stepOf(tried);
115
132
  if (step.kind === "moved") return yield* fail("INTERNAL", "The host's IndexCalls answered moved to a last check");
116
- const { record, snapshot, listed, packs, row, headRows, cursorRows } = tried;
133
+ const { record, snapshot, listed, packs, loose, row, headRows, cursorRows } = tried;
134
+ const small = smallRepo(packs, loose);
117
135
  if (step.kind === "more") return {
118
136
  ended: "more",
119
137
  next: {
120
138
  kind: "more",
121
139
  data: { build: step.data }
122
- }
140
+ },
141
+ small
123
142
  };
124
143
  if (step.kind === "pruned") return {
125
144
  ended: "pruned",
@@ -127,11 +146,16 @@ const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
127
146
  kind: "more",
128
147
  at: step.due,
129
148
  data: {}
130
- }
149
+ },
150
+ small
131
151
  };
132
152
  const scope = repoScope(internalId);
133
153
  const ids = packs.map(({ id }) => id);
134
154
  const landed = index.status(step.row, at, ids);
155
+ if (chained === true && refusing.has(landed.state)) return {
156
+ ended: "withheld",
157
+ next: void 0
158
+ };
135
159
  const refusal = refusalOf(landed, index.status(row, at, ids));
136
160
  const sends = refusal !== void 0 && keepsEvents(parts.events) && record.deleted !== true;
137
161
  const events = sends ? [refusedEvent(record.name, refusal)] : [];
@@ -156,7 +180,7 @@ const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
156
180
  });
157
181
  const repack = parts.repackJobRow !== void 0 && liftsHolds(indexRowOf(row), indexRowOf(step.row), listed) ? [parts.repackJobRow()] : [];
158
182
  const retry = yield* uncoveredRetry(step.row, landed, (when) => index.status(step.row, when, ids));
159
- const committed = yield* storeCall(() => store.commit(scope, {
183
+ const committed = yield* storeCommit(store.commit(scope, {
160
184
  id: newChangeId(),
161
185
  expect: snapshot.version,
162
186
  put: [step.row, ...appended.put],
@@ -172,7 +196,8 @@ const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
172
196
  next: {
173
197
  kind: "more",
174
198
  data: committed.ok ? {} : kept
175
- }
199
+ },
200
+ small
176
201
  };
177
202
  });
178
203
  /**
@@ -209,7 +234,7 @@ const readTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, inter
209
234
  const reads = keepsEvents(parts.events) ? eventReads : tryReads;
210
235
  const { record, snapshot } = yield* readRecord(store, internalId, reads);
211
236
  if (record === void 0) return void 0;
212
- const [, refRows = [], packRows = [], indexRows = [], rootRows, headRows = [], cursorRows = []] = snapshot.results;
237
+ const [, refRows = [], packRows = [], indexRows = [], rootRows, looseRows = [], headRows = [], cursorRows = []] = snapshot.results;
213
238
  const refs = yield* wholeRefs(indexWhole, refRows);
214
239
  const packs = yield* decodePacks(packRows);
215
240
  const roots = yield* rootsOf(rootRows);
@@ -231,28 +256,99 @@ const readTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, inter
231
256
  if (row !== void 0) input.row = row.value;
232
257
  if (roots.size > 0) input.roots = [...roots];
233
258
  if (of.lastCheck === true) input.lastCheck = true;
259
+ const [looseRow] = looseRows;
234
260
  return {
235
261
  record,
236
262
  snapshot,
237
263
  listed,
238
264
  packs,
265
+ loose: looseRow === void 0 ? void 0 : yield* decodeRow(LooseTally, looseRow, "The repo's object rows' tally"),
239
266
  row,
240
267
  headRows,
241
268
  cursorRows,
242
269
  input
243
270
  };
244
271
  });
245
- /** `indexAttempt`, as the queue takes it. */
246
- const indexTry = (...args) => Effect.map(indexAttempt(...args), (attempt) => attempt.next);
272
+ /**
273
+ * The most a repo's packs hold for a try to run its steps back to back: an eighth of a read
274
+ * slice's bytes and links, so each step over it does at most about an eighth of the work a step
275
+ * is sized to fit a whole try with (#2525).
276
+ */
277
+ const chainedMost = {
278
+ bytes: sliceBounds.bytes / 8,
279
+ objects: sliceBounds.links / 8
280
+ };
281
+ /**
282
+ * The share of a try's CPU, and of its calls, its steps may have used and still start another:
283
+ * a quarter, so one more step at an eighth of a try's work stays well inside both.
284
+ */
285
+ const chainedShare = 1 / 4;
286
+ /**
287
+ * Whether `packs` and the repo's object rows, `loose`, are small enough together, as
288
+ * `chainedMost` says, for steps back to back: a step reads both.
289
+ */
290
+ const smallRepo = (packs, loose) => {
291
+ const bytes = packs.reduce((sum, pack) => sum + pack.bytes, loose?.bytes ?? 0);
292
+ const objects = packs.reduce((sum, pack) => sum + pack.objects, loose?.objects ?? 0);
293
+ return bytes <= chainedMost.bytes && objects <= chainedMost.objects;
294
+ };
295
+ /** Whether `made` is no more than `chainedShare` of `most`, bucket calls and subrequests each. */
296
+ const chainsWithin = (made, most) => made.bucket <= .25 * most.bucket && made.subrequests <= .25 * most.subrequests;
297
+ /** Whether the try's budget in scope, if any, has used no more than `chainedShare` of each kind. */
298
+ const callsLeft = Effect.map(callScope, ({ budget }) => budget === void 0 ? true : chainsWithin(budgetMade(budget), budgetMost(budget)));
299
+ /**
300
+ * Whether a try that started at `start` runs another step after `attempt`: one that ended with
301
+ * the next step due now, a `more` that moved on from `given`, the data its step was given, or a
302
+ * landed row's prune, over a small repo, with the try's wall time so far, which its CPU is no more
303
+ * than, and its calls each within `chainedShare`.
304
+ */
305
+ const chainsOn = (parts, attempt, given, start, signal) => {
306
+ if (!(attempt.ended === "more" || attempt.ended === "landed") || attempt.small !== true || signal.aborted) return Effect.succeed(false);
307
+ if (attempt.ended === "more" && Equal.equals(attempt.next?.data, given)) return Effect.succeed(false);
308
+ const cpuMs = parts.cpuMs ?? 3e4;
309
+ return Effect.flatMap(parts.now, (now) => now - start >= .25 * cpuMs ? Effect.succeed(false) : callsLeft);
310
+ };
311
+ /**
312
+ * Whether `cause` holds a spent bound that's no budget the try's own nests: the platform's cap,
313
+ * or a request's count.
314
+ */
315
+ const spentElsewhere = (cause) => Effect.map(callScope, ({ budget }) => {
316
+ if (spentOf(cause) === void 0) return false;
317
+ const owns = (spent) => {
318
+ const at = spentBudget(spent);
319
+ return budget !== void 0 && at !== void 0 && nestsIn(at, budget);
320
+ };
321
+ return ownSpentOf(cause, owns) === void 0;
322
+ });
323
+ /**
324
+ * `indexAttempt`, as the queue takes it: with `chains`, more steps after it in the same try while
325
+ * `chainsOn` allows, each committing what it commits on its own, as a try of its own would. Only
326
+ * the last step's `next` is kept, so a try lost between steps runs them again from its own data,
327
+ * as a try lost mid-step does; the next try, past a lost one, runs one step (#2525).
328
+ */
329
+ const indexTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, internalId, data, signal, round, chains) {
330
+ const start = yield* parts.now;
331
+ let given = data;
332
+ let attempt = yield* indexAttempt(parts, store, internalId, data, signal, round);
333
+ while (chains && attempt.next !== void 0 && (yield* chainsOn(parts, attempt, given, start, signal))) {
334
+ const next = attempt.next;
335
+ given = next.data ?? {};
336
+ const chained = yield* Effect.exit(indexAttempt(parts, store, internalId, given, signal, round, { chained: true }));
337
+ if (Exit.isFailure(chained)) {
338
+ if (Cause.hasInterrupts(chained.cause) || (yield* spentElsewhere(chained.cause))) return yield* Effect.failCause(chained.cause);
339
+ yield* Effect.logDebug("git.index ends a try at a step that failed after another", chained.cause);
340
+ return next;
341
+ }
342
+ if (chained.value.ended === "withheld") return next;
343
+ attempt = chained.value;
344
+ }
345
+ return attempt.next;
346
+ });
247
347
  /** `git.index`'s try, in the repo's scope: a step of the build, or past its tries, the refusal. */
248
- const indexStep = (parts) => (data) => Effect.flatMap(Effect.all([
249
- CurrentJob.current,
250
- CurrentJob.store,
251
- CurrentJob.signal
252
- ]), ([job, store, signal]) => job.attempt > 20 ? refusalTry(parts, job, {
253
- store,
348
+ const indexStep = (parts) => (data) => Effect.flatMap(Effect.all([CurrentJob.current, CurrentJob.signal]), ([job, signal]) => job.attempt > 20 ? refusalTry(parts, job, {
349
+ store: parts.store,
254
350
  signal
255
- }, data, spentReason(lastOf(job))) : indexTry(parts, store, jobRepo(job), data, signal, roundOf(job.key)));
351
+ }, data, spentReason(lastOf(job))) : indexTry(parts, parts.store, jobRepo(job), data, signal, roundOf(job.key), job.attempt === 1));
256
352
  /** How the build's last try ended, as the first refusal try's claim says: later ones can't. */
257
353
  const lastOf = (job) => {
258
354
  if (job.attempt > 21) return "its refusal tried again";
@@ -274,7 +370,7 @@ const refusalTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, job, cont
274
370
  const internalId = jobRepo(job);
275
371
  const round = roundOf(job.key);
276
372
  for (let write = 0; write < refusalWrites; write += 1) {
277
- const tried = yield* indexAttempt(parts, context.store, internalId, data, context.signal, round, { reason });
373
+ const tried = yield* indexAttempt(parts, context.store, internalId, data, context.signal, round, { failed: { reason } });
278
374
  if (tried.ended === "missed") continue;
279
375
  if (tried.ended !== "landed") return tried.next;
280
376
  const { snapshot } = yield* readRecord(context.store, internalId, [indexRowKey, { collection: collections.packs }]);
@@ -291,25 +387,22 @@ const refusalTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, job, cont
291
387
  * its failure logged. A round left failed with no refused row is one an operator's `retry` starts
292
388
  * again, since no refusal stands for its try to prune against.
293
389
  */
294
- const indexFailed = (parts) => (data, failure) => Effect.flatMap(Effect.all([
295
- CurrentJob.current,
296
- CurrentJob.store,
297
- CurrentJob.signal
298
- ]), ([job, store, signal]) => Effect.catch(refusalTry(parts, job, {
299
- store,
390
+ const indexFailed = (parts) => (data, failure) => Effect.flatMap(Effect.all([CurrentJob.current, CurrentJob.signal]), ([job, signal]) => Effect.catch(refusalTry(parts, job, {
391
+ store: parts.store,
300
392
  signal
301
393
  }, data, spentReason(failure.error instanceof Error ? failure.error.message : String(failure.error))), (error) => Effect.logError(`git.index left repo ${jobRepo(job)} failed, with no refusal: ${error.message}`)).pipe(Effect.asVoid));
302
394
  /** How many times a refusal's try reads and writes the refused row before it fails. */
303
395
  const refusalWrites = 3;
304
396
  /**
305
- * `git.index`, over one server's objects. A try is one step, so a large repo is many tries; each
306
- * `more` puts the row back due now, and starts its tries' count again. Past `indexTries` in a
397
+ * `git.index`, over one server's objects. A try is one step, or a small repo's several back to
398
+ * back, so a large repo is many tries; each `more` puts the row back due now, and starts its
399
+ * tries' count again. Past `indexTries` in a
307
400
  * row, the next tries leave a refused row, and `indexFailed` is their last chance. One at a time
308
401
  * in each process, as `git.repack` runs.
309
402
  */
310
403
  const IndexJob = /* @__PURE__ */ Job.make(indexJobName, {
311
404
  payload: IndexJobData,
312
- timeout: "13 minutes",
405
+ timeout: jobTryTimeout,
313
406
  concurrency: 1,
314
407
  retry: {
315
408
  limit: 25,
@@ -324,4 +417,4 @@ const indexJobRow = (job, round = 0) => job.job({
324
417
  key: indexJobKeyOf(round),
325
418
  data: {}
326
419
  });
327
- export { IndexJobData, indexDeletedKey, indexJob, indexJobKey, indexJobKeyOf, indexJobName, indexJobRow };
420
+ export { IndexJobData, chainedMost, chainedShare, chainsWithin, indexDeletedKey, indexJob, indexJobKey, indexJobKeyOf, indexJobName, indexJobRow, smallRepo };
@@ -1,9 +1,8 @@
1
1
  import { InternalRepoId } from "../contracts/ids.mjs";
2
2
  import "../contracts/objects.mjs";
3
- import "../contracts/promises.mjs";
4
3
  import { Listed } from "../contracts/store.mjs";
4
+ import { JobInput, Moment, Records, Row } from "@ref0/infra";
5
5
  import * as Effect from "effect/Effect";
6
- import { JobInput, Moment, Row } from "@ref0/infra";
7
6
  /**
8
7
  * A read's ask for the rebuild of the `index` row it read, `row`, once the index it names failed
9
8
  * its own checks: `listed` is the listing the read was at.
@@ -1,4 +1,4 @@
1
- import { bestEffort, storeCall } from "../store/errors.mjs";
1
+ import { bestEffort, storeCommit } from "../store/errors.mjs";
2
2
  import { newChangeId, repoScope } from "../store/scopes.mjs";
3
3
  import { lostIndexRow } from "../storage/index-build.mjs";
4
4
  import { indexJobs } from "./access.mjs";
@@ -45,7 +45,7 @@ const indexLostAsk = (parts) => {
45
45
  put: [marked],
46
46
  jobs
47
47
  };
48
- const committed = yield* bestEffort(storeCall(() => parts.store.commit(repoScope(repo), change)), failed).pipe(Effect.onInterrupt(() => Effect.sync(() => asked.delete(key))));
48
+ const committed = yield* bestEffort(storeCommit(parts.store.commit(repoScope(repo), change)), failed).pipe(Effect.onInterrupt(() => Effect.sync(() => asked.delete(key))));
49
49
  if (committed !== void 0 && !committed.ok) asked.delete(key);
50
50
  });
51
51
  };