@ref0/git 0.3.0 → 0.6.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 (631) 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 +70 -48
  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 +65 -83
  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 +7 -2
  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 +63 -24
  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 +96 -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 +41 -10
  52. package/dist/contracts/actors.d.mts +28 -10
  53. package/dist/contracts/actors.mjs +17 -0
  54. package/dist/contracts/authorize.d.mts +81 -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 +1410 -206
  66. package/dist/contracts/events.mjs +496 -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 +172 -0
  72. package/dist/contracts/git.mjs +23 -0
  73. package/dist/contracts/grants.d.mts +7 -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 +12 -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 +329 -88
  83. package/dist/contracts/operations.d.mts +24 -16
  84. package/dist/contracts/promises.d.mts +10 -11
  85. package/dist/contracts/push-uploads.d.mts +40 -25
  86. package/dist/contracts/push-uploads.mjs +54 -0
  87. package/dist/contracts/queue.d.mts +454 -141
  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 +339 -69
  96. package/dist/contracts/result.mjs +355 -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 +124 -51
  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 +128 -21
  117. package/dist/contracts/work.mjs +69 -0
  118. package/dist/core/access.d.mts +25 -14
  119. package/dist/core/access.mjs +93 -108
  120. package/dist/core/ancestry.mjs +86 -18
  121. package/dist/core/call-names.d.mts +3 -1
  122. package/dist/core/call-names.mjs +1 -0
  123. package/dist/core/call-services.mjs +73 -0
  124. package/dist/core/changes.d.mts +31 -0
  125. package/dist/core/changes.mjs +5 -0
  126. package/dist/core/claim-rows.d.mts +4 -0
  127. package/dist/core/claim-rows.mjs +53 -0
  128. package/dist/core/clock.mjs +3 -3
  129. package/dist/core/events/deliver.d.mts +12 -0
  130. package/dist/core/events/deliver.mjs +454 -146
  131. package/dist/core/events/seen.mjs +138 -0
  132. package/dist/core/forks.mjs +435 -161
  133. package/dist/core/hooks/order.d.mts +9 -0
  134. package/dist/core/hooks/order.mjs +25 -0
  135. package/dist/core/hooks/post-receive.mjs +33 -29
  136. package/dist/core/hooks/pre-receive.d.mts +8 -1
  137. package/dist/core/hooks/pre-receive.mjs +8 -6
  138. package/dist/core/imports.mjs +212 -0
  139. package/dist/core/index-job.mjs +152 -53
  140. package/dist/core/merge-parts.d.mts +30 -0
  141. package/dist/core/merge-parts.mjs +31 -0
  142. package/dist/core/names.mjs +4 -16
  143. package/dist/core/namespaces.d.mts +2 -0
  144. package/dist/core/objects/blobs.mjs +4 -4
  145. package/dist/core/objects/commit-writes.mjs +19 -17
  146. package/dist/core/objects/commits.mjs +12 -12
  147. package/dist/core/objects/files.mjs +10 -11
  148. package/dist/core/objects/lines.mjs +15 -32
  149. package/dist/core/objects/merges.mjs +4 -4
  150. package/dist/core/objects/objects-layer.d.mts +21 -0
  151. package/dist/core/objects/objects-layer.mjs +47 -0
  152. package/dist/core/objects/objects-namespace.d.mts +6 -0
  153. package/dist/core/objects/objects-namespace.mjs +13 -0
  154. package/dist/core/objects/objects.d.mts +49 -0
  155. package/dist/core/objects/objects.mjs +18 -0
  156. package/dist/core/objects/peel.mjs +3 -3
  157. package/dist/core/objects/reading.mjs +135 -40
  158. package/dist/core/objects/tags.mjs +7 -7
  159. package/dist/core/objects/tree-edits.mjs +40 -27
  160. package/dist/core/objects/trees.mjs +23 -18
  161. package/dist/core/objects/writing.mjs +43 -44
  162. package/dist/core/own-writes.mjs +3 -3
  163. package/dist/core/parts.d.mts +131 -0
  164. package/dist/core/parts.mjs +59 -0
  165. package/dist/core/promise.mjs +13 -9
  166. package/dist/core/publish.mjs +27 -17
  167. package/dist/core/purge.d.mts +8 -0
  168. package/dist/core/purge.mjs +237 -0
  169. package/dist/core/push-decide.mjs +116 -29
  170. package/dist/core/push.mjs +352 -171
  171. package/dist/core/receipts.d.mts +4 -3
  172. package/dist/core/receipts.mjs +20 -12
  173. package/dist/core/ref-conflicts.mjs +70 -4
  174. package/dist/core/ref-index-job.mjs +176 -0
  175. package/dist/core/ref-index.d.mts +26 -0
  176. package/dist/core/ref-index.mjs +156 -0
  177. package/dist/core/ref-view.mjs +171 -0
  178. package/dist/core/refs.mjs +318 -98
  179. package/dist/core/repack.d.mts +11 -0
  180. package/dist/core/repack.mjs +264 -136
  181. package/dist/core/repo-info.mjs +99 -0
  182. package/dist/core/repos.mjs +114 -80
  183. package/dist/core/rules/changes.mjs +48 -20
  184. package/dist/core/rules/check.mjs +36 -28
  185. package/dist/core/rules/commit-changes.d.mts +13 -0
  186. package/dist/core/rules/commit-changes.mjs +100 -91
  187. package/dist/core/rules/context.d.mts +67 -8
  188. package/dist/core/rules/context.mjs +88 -51
  189. package/dist/core/rules/facts.mjs +1 -1
  190. package/dist/core/rules/fetch.mjs +24 -26
  191. package/dist/core/rules/files.d.mts +13 -0
  192. package/dist/core/rules/files.mjs +27 -28
  193. package/dist/core/rules/namespace.d.mts +2 -0
  194. package/dist/core/rules/patterns.mjs +29 -5
  195. package/dist/core/rules/protect.d.mts +12 -6
  196. package/dist/core/rules/protect.mjs +22 -20
  197. package/dist/core/rules/rules-layer.d.mts +17 -0
  198. package/dist/core/rules/rules-layer.mjs +26 -0
  199. package/dist/core/rules/rules.d.mts +8 -0
  200. package/dist/core/rules/rules.mjs +16 -0
  201. package/dist/core/rules/service.mjs +18 -0
  202. package/dist/core/seam.d.mts +60 -10
  203. package/dist/core/seam.mjs +25 -15
  204. package/dist/core/still-takes.mjs +75 -0
  205. package/dist/core/tokens.mjs +29 -23
  206. package/dist/core/view.d.mts +106 -6
  207. package/dist/core/view.mjs +215 -114
  208. package/dist/core/work.mjs +40 -14
  209. package/dist/effect.d.mts +3 -4
  210. package/dist/effect.mjs +2 -3
  211. package/dist/engine/allotted-xdiff.d.mts +1 -0
  212. package/dist/engine/allotted-xdiff.mjs +1 -1
  213. package/dist/engine/attributes.mjs +1 -1
  214. package/dist/engine/combined.d.mts +18 -0
  215. package/dist/engine/combined.mjs +39 -44
  216. package/dist/engine/commits.mjs +5 -4
  217. package/dist/engine/content.d.mts +3 -2
  218. package/dist/engine/content.mjs +2 -2
  219. package/dist/engine/failures.d.mts +2 -2
  220. package/dist/engine/failures.mjs +2 -9
  221. package/dist/engine/merge-base-walk.d.mts +3 -2
  222. package/dist/engine/merge-base-walk.mjs +1 -1
  223. package/dist/engine/merge-bases.mjs +3 -2
  224. package/dist/engine/merge.mjs +568 -566
  225. package/dist/engine/parts.d.mts +3 -2
  226. package/dist/engine/parts.mjs +40 -7
  227. package/dist/engine/reads.d.mts +1 -0
  228. package/dist/engine/reads.mjs +5 -5
  229. package/dist/engine/walk.mjs +23 -24
  230. package/dist/engine/xdiff.d.mts +2 -33
  231. package/dist/engine/xdiff.mjs +6 -3
  232. package/dist/event-streams/event-streams.d.mts +25 -0
  233. package/dist/event-streams/event-streams.mjs +22 -0
  234. package/dist/event-streams/namespace.d.mts +2 -0
  235. package/dist/event-streams/stream.d.mts +42 -0
  236. package/dist/{core/events → event-streams}/stream.mjs +106 -49
  237. package/dist/extend.d.mts +5 -2
  238. package/dist/http/answers.mjs +8 -4
  239. package/dist/http/bodies.mjs +84 -56
  240. package/dist/http/core-parts.mjs +222 -68
  241. package/dist/http/handler.d.mts +2 -0
  242. package/dist/http/handler.mjs +19 -13
  243. package/dist/http/node.d.mts +2 -23
  244. package/dist/http/node.mjs +10 -6
  245. package/dist/http/parts.d.mts +13 -0
  246. package/dist/http/push-uploads.d.mts +17 -0
  247. package/dist/http/push-uploads.mjs +94 -87
  248. package/dist/http/receive-pack.mjs +165 -29
  249. package/dist/http/upload-pack.mjs +106 -81
  250. package/dist/index.d.mts +52 -28
  251. package/dist/index.mjs +31 -7
  252. package/dist/lfs/base.d.mts +32 -0
  253. package/dist/lfs/base.mjs +8 -0
  254. package/dist/lfs/calls.mjs +21 -12
  255. package/dist/lfs/layer.d.mts +27 -0
  256. package/dist/lfs/layer.mjs +64 -0
  257. package/dist/lfs/locks.mjs +36 -46
  258. package/dist/lfs/namespace.d.mts +2 -0
  259. package/dist/lfs/objects.d.mts +26 -0
  260. package/dist/lfs/objects.mjs +83 -94
  261. package/dist/lfs/pointers.mjs +13 -11
  262. package/dist/lfs/public.d.mts +5 -0
  263. package/dist/lfs/public.mjs +8 -0
  264. package/dist/lfs/purge.mjs +44 -0
  265. package/dist/lfs/rows.mjs +30 -18
  266. package/dist/lfs/service.d.mts +14 -0
  267. package/dist/lfs/service.mjs +26 -28
  268. package/dist/lfs/upkeep.mjs +39 -54
  269. package/dist/lfs/wire.mjs +80 -38
  270. package/dist/merges/merges.d.mts +20 -0
  271. package/dist/merges/merges.mjs +32 -0
  272. package/dist/merges/namespace.d.mts +2 -0
  273. package/dist/merges/public.d.mts +6 -0
  274. package/dist/merges/public.mjs +10 -0
  275. package/dist/node.d.mts +3 -3
  276. package/dist/node.mjs +1 -3
  277. package/dist/protocol/bytes/buffers.d.mts +9 -3
  278. package/dist/protocol/bytes/buffers.mjs +11 -5
  279. package/dist/protocol/bytes/deflate.d.mts +7 -5
  280. package/dist/protocol/bytes/deflate.mjs +59 -23
  281. package/dist/protocol/bytes/inflate.d.mts +4 -3
  282. package/dist/protocol/bytes/inflate.mjs +61 -26
  283. package/dist/protocol/bytes/reader.mjs +61 -0
  284. package/dist/protocol/bytes/sha1-hasher.d.mts +3 -1
  285. package/dist/protocol/bytes/sha1-hasher.mjs +13 -3
  286. package/dist/protocol/bytes/sha1.d.mts +1 -1
  287. package/dist/protocol/bytes/sha1.mjs +5 -5
  288. package/dist/protocol/bytes/streams.mjs +16 -6
  289. package/dist/protocol/diff/patch.d.mts +4 -0
  290. package/dist/protocol/diff/patch.mjs +1 -1
  291. package/dist/protocol/diff/paths.mjs +1 -1
  292. package/dist/protocol/diff/read.d.mts +1 -1
  293. package/dist/protocol/diff/read.mjs +102 -90
  294. package/dist/protocol/framing/pkt-line.d.mts +1 -0
  295. package/dist/protocol/framing/pkt-line.mjs +40 -6
  296. package/dist/protocol/objects/checked-blobs.d.mts +1 -0
  297. package/dist/protocol/objects/fsck.mjs +7 -1
  298. package/dist/protocol/objects/held.mjs +5 -11
  299. package/dist/protocol/objects/ident.mjs +1 -1
  300. package/dist/protocol/objects/object-rules.mjs +15 -7
  301. package/dist/protocol/objects/object.d.mts +6 -2
  302. package/dist/protocol/objects/object.mjs +5 -2
  303. package/dist/protocol/objects/tag.d.mts +3 -1
  304. package/dist/protocol/objects/tag.mjs +27 -1
  305. package/dist/protocol/objects/tree.mjs +1 -1
  306. package/dist/protocol/packs/delta.d.mts +1 -1
  307. package/dist/protocol/packs/delta.mjs +2 -2
  308. package/dist/protocol/packs/graph.mjs +55 -56
  309. package/dist/protocol/packs/idx.d.mts +4 -2
  310. package/dist/protocol/packs/idx.mjs +156 -63
  311. package/dist/protocol/packs/indexer.d.mts +22 -4
  312. package/dist/protocol/packs/indexer.mjs +14 -35
  313. package/dist/protocol/packs/parts.mjs +5 -5
  314. package/dist/protocol/packs/pos.mjs +12 -5
  315. package/dist/protocol/packs/reader.d.mts +19 -12
  316. package/dist/protocol/packs/reader.mjs +252 -25
  317. package/dist/protocol/packs/rev.d.mts +1 -1
  318. package/dist/protocol/packs/rev.mjs +42 -24
  319. package/dist/protocol/packs/types-file.mjs +85 -0
  320. package/dist/protocol/packs/write-error.d.mts +1 -1
  321. package/dist/protocol/packs/write-error.mjs +2 -2
  322. package/dist/protocol/packs/writer.d.mts +40 -15
  323. package/dist/protocol/packs/writer.mjs +142 -49
  324. package/dist/protocol/wire/advertisement.d.mts +34 -15
  325. package/dist/protocol/wire/advertisement.mjs +135 -35
  326. package/dist/protocol/wire/fetch.d.mts +57 -19
  327. package/dist/protocol/wire/fetch.mjs +57 -26
  328. package/dist/protocol/wire/json.mjs +25 -0
  329. package/dist/protocol/wire/lines.d.mts +22 -0
  330. package/dist/protocol/wire/lines.mjs +51 -26
  331. package/dist/protocol/wire/push-limits.d.mts +6 -0
  332. package/dist/protocol/wire/push-limits.mjs +88 -0
  333. package/dist/protocol/wire/push-uploads.mjs +3 -28
  334. package/dist/protocol/wire/receive-pack.d.mts +30 -14
  335. package/dist/protocol/wire/receive-pack.mjs +29 -2
  336. package/dist/protocol/wire/report-status.d.mts +30 -11
  337. package/dist/protocol/wire/report-status.mjs +21 -2
  338. package/dist/protocol/wire/v2.d.mts +45 -29
  339. package/dist/protocol/wire/v2.mjs +95 -18
  340. package/dist/protocol.d.mts +4 -3
  341. package/dist/protocol.mjs +7 -6
  342. package/dist/queue/advance.mjs +240 -148
  343. package/dist/queue/callers.mjs +12 -9
  344. package/dist/queue/calls.mjs +315 -157
  345. package/dist/queue/commit.mjs +86 -35
  346. package/dist/queue/host.d.mts +39 -12
  347. package/dist/queue/host.mjs +36 -38
  348. package/dist/queue/lanes.mjs +1 -1
  349. package/dist/queue/layer.d.mts +16 -0
  350. package/dist/queue/layer.mjs +60 -0
  351. package/dist/queue/limits.mjs +43 -2
  352. package/dist/queue/namespace.d.mts +2 -0
  353. package/dist/queue/pages.mjs +1 -1
  354. package/dist/queue/public.d.mts +6 -0
  355. package/dist/queue/public.mjs +21 -0
  356. package/dist/queue/push-option.mjs +49 -30
  357. package/dist/queue/rows.mjs +38 -21
  358. package/dist/queue/schedule.mjs +22 -22
  359. package/dist/queue/search.mjs +8 -7
  360. package/dist/queue/state.mjs +68 -18
  361. package/dist/queue/steps.mjs +16 -7
  362. package/dist/queue/trim.mjs +284 -0
  363. package/dist/remote-helper.d.mts +5 -2
  364. package/dist/remote-helper.mjs +5 -2
  365. package/dist/rest/api.d.mts +1 -1
  366. package/dist/rest/blobs.d.mts +799 -32
  367. package/dist/rest/blobs.mjs +4 -4
  368. package/dist/rest/caller.d.mts +4163 -36
  369. package/dist/rest/caller.mjs +2 -2
  370. package/dist/rest/client.mjs +80 -70
  371. package/dist/rest/commits.d.mts +3261 -190
  372. package/dist/rest/commits.mjs +18 -64
  373. package/dist/rest/errors.d.mts +2082 -22
  374. package/dist/rest/errors.mjs +46 -89
  375. package/dist/rest/events.d.mts +394 -11
  376. package/dist/rest/events.mjs +13 -9
  377. package/dist/rest/files.d.mts +1265 -114
  378. package/dist/rest/files.mjs +11 -42
  379. package/dist/rest/forks.d.mts +2045 -102
  380. package/dist/rest/forks.mjs +10 -13
  381. package/dist/rest/handler.d.mts +3 -0
  382. package/dist/rest/handler.mjs +35 -19
  383. package/dist/rest/handlers.mjs +53 -60
  384. package/dist/rest/layer.d.mts +14 -0
  385. package/dist/rest/layer.mjs +52 -0
  386. package/dist/rest/listen.d.mts +5 -8
  387. package/dist/rest/listen.mjs +23 -29
  388. package/dist/rest/me.d.mts +393 -10
  389. package/dist/rest/me.mjs +2 -2
  390. package/dist/rest/merges.d.mts +399 -16
  391. package/dist/rest/merges.mjs +3 -17
  392. package/dist/rest/namespace.d.mts +2 -0
  393. package/dist/rest/paths.mjs +1 -0
  394. package/dist/rest/queue.d.mts +5658 -283
  395. package/dist/rest/queue.mjs +15 -130
  396. package/dist/rest/refs.d.mts +2869 -142
  397. package/dist/rest/refs.mjs +19 -39
  398. package/dist/rest/repos.d.mts +2421 -93
  399. package/dist/rest/repos.mjs +10 -33
  400. package/dist/rest/tags.d.mts +1220 -69
  401. package/dist/rest/tags.mjs +6 -34
  402. package/dist/rest/tokens.d.mts +2358 -55
  403. package/dist/rest/tokens.mjs +7 -4
  404. package/dist/rest/topics.d.mts +2053 -106
  405. package/dist/rest/topics.mjs +23 -71
  406. package/dist/rest/trees.d.mts +1616 -81
  407. package/dist/rest/trees.mjs +16 -57
  408. package/dist/rest/wire.d.mts +404 -0
  409. package/dist/rest/wire.mjs +32 -46
  410. package/dist/rest/work.d.mts +1204 -63
  411. package/dist/rest/work.mjs +7 -51
  412. package/dist/rest.d.mts +3 -3
  413. package/dist/server/edge-node.d.mts +20 -0
  414. package/dist/server/edge-node.mjs +20 -0
  415. package/dist/server/edge.d.mts +10 -0
  416. package/dist/server/edge.mjs +23 -0
  417. package/dist/server/extension.d.mts +6 -2
  418. package/dist/server/extension.mjs +54 -30
  419. package/dist/server/git-layer.d.mts +34 -0
  420. package/dist/server/git-layer.mjs +118 -0
  421. package/dist/server/git-namespace.d.mts +7 -0
  422. package/dist/server/git-namespace.mjs +18 -0
  423. package/dist/server/lifecycle.d.mts +1 -2
  424. package/dist/server/lifecycle.mjs +8 -15
  425. package/dist/server/namespaces.d.mts +2 -0
  426. package/dist/server/registry.d.mts +12 -0
  427. package/dist/server/registry.mjs +218 -0
  428. package/dist/server/route-match.mjs +88 -0
  429. package/dist/server/routes.d.mts +12 -8
  430. package/dist/server/routes.mjs +27 -18
  431. package/dist/server/server.d.mts +22 -0
  432. package/dist/server/server.mjs +335 -210
  433. package/dist/server/uploads.d.mts +14 -0
  434. package/dist/server/uploads.mjs +15 -0
  435. package/dist/signin/codes.mjs +9 -6
  436. package/dist/signin/context.d.mts +1 -0
  437. package/dist/signin/context.mjs +4 -4
  438. package/dist/signin/device.mjs +8 -8
  439. package/dist/signin/forms.mjs +11 -29
  440. package/dist/signin/grants.d.mts +4 -2
  441. package/dist/signin/grants.mjs +20 -19
  442. package/dist/signin/route.mjs +2 -2
  443. package/dist/signin/web.mjs +7 -7
  444. package/dist/signin/wire.mjs +6 -6
  445. package/dist/storage/budget.mjs +51 -18
  446. package/dist/storage/calls.d.mts +28 -11
  447. package/dist/storage/calls.mjs +354 -117
  448. package/dist/storage/clean-up.mjs +121 -46
  449. package/dist/storage/counted-bucket.mjs +115 -0
  450. package/dist/storage/fetch.d.mts +2 -0
  451. package/dist/storage/fetch.mjs +243 -100
  452. package/dist/storage/fsck.mjs +56 -7
  453. package/dist/storage/held-types.d.mts +7 -0
  454. package/dist/storage/held-types.mjs +263 -0
  455. package/dist/storage/host-bucket.mjs +43 -0
  456. package/dist/storage/id-mix.d.mts +1 -0
  457. package/dist/storage/id-mix.mjs +55 -0
  458. package/dist/storage/index-bitmaps.d.mts +2 -1
  459. package/dist/storage/index-bitmaps.mjs +233 -101
  460. package/dist/storage/index-build.d.mts +6 -2
  461. package/dist/storage/index-build.mjs +650 -164
  462. package/dist/storage/index-fetch.d.mts +3 -1
  463. package/dist/storage/index-fetch.mjs +297 -195
  464. package/dist/storage/index-files.mjs +25 -27
  465. package/dist/storage/index-graph.d.mts +2 -1
  466. package/dist/storage/index-graph.mjs +127 -91
  467. package/dist/storage/index-layers.d.mts +11 -0
  468. package/dist/storage/index-layers.mjs +258 -78
  469. package/dist/storage/index-reach.mjs +181 -75
  470. package/dist/storage/index-remap.mjs +74 -32
  471. package/dist/storage/index-shallow.mjs +311 -0
  472. package/dist/storage/index-visible.mjs +168 -0
  473. package/dist/storage/layout.d.mts +1 -0
  474. package/dist/storage/layout.mjs +44 -8
  475. package/dist/storage/lfs-pointers.d.mts +3 -1
  476. package/dist/storage/lfs-pointers.mjs +25 -9
  477. package/dist/storage/link-join.d.mts +4 -0
  478. package/dist/storage/link-join.mjs +50 -12
  479. package/dist/storage/links.mjs +89 -4
  480. package/dist/storage/listed-ids.mjs +10 -0
  481. package/dist/storage/loose.d.mts +11 -4
  482. package/dist/storage/loose.mjs +102 -69
  483. package/dist/storage/memory-budget.d.mts +5 -0
  484. package/dist/storage/memory-budget.mjs +530 -102
  485. package/dist/storage/merge-choose.mjs +258 -0
  486. package/dist/storage/merge-cut.mjs +47 -0
  487. package/dist/storage/merge-fence.mjs +89 -0
  488. package/dist/storage/merge-index.mjs +347 -0
  489. package/dist/storage/merge-most.mjs +202 -0
  490. package/dist/storage/merge-plan.mjs +171 -0
  491. package/dist/storage/merge-row.mjs +258 -0
  492. package/dist/storage/merge-stream.mjs +497 -0
  493. package/dist/storage/merge-walk.mjs +199 -0
  494. package/dist/storage/merge-write.mjs +129 -0
  495. package/dist/storage/merge.d.mts +10 -0
  496. package/dist/storage/merge.mjs +82 -306
  497. package/dist/storage/object-rows.d.mts +4 -2
  498. package/dist/storage/object-rows.mjs +101 -17
  499. package/dist/storage/pack-order.d.mts +1 -1
  500. package/dist/storage/pack-order.mjs +69 -54
  501. package/dist/storage/pack-ranges.d.mts +1 -1
  502. package/dist/storage/pack-ranges.mjs +396 -60
  503. package/dist/storage/pack-reads.d.mts +6 -2
  504. package/dist/storage/pack-reads.mjs +598 -126
  505. package/dist/storage/pack-receive.d.mts +5 -0
  506. package/dist/storage/pack-receive.mjs +820 -237
  507. package/dist/storage/packs-memory.d.mts +25 -0
  508. package/dist/storage/packs-memory.mjs +49 -0
  509. package/dist/storage/packs.d.mts +7 -5
  510. package/dist/storage/packs.mjs +554 -213
  511. package/dist/storage/placed-reads.mjs +205 -0
  512. package/dist/storage/prune-keep.mjs +164 -0
  513. package/dist/storage/prune-walk.mjs +578 -0
  514. package/dist/storage/prune.mjs +739 -332
  515. package/dist/storage/push-allotment.mjs +3 -3
  516. package/dist/storage/push-uploads.mjs +31 -26
  517. package/dist/storage/pushed-commits.mjs +8 -9
  518. package/dist/storage/quarantine.d.mts +10 -0
  519. package/dist/storage/quarantine.mjs +71 -29
  520. package/dist/storage/range-cache.mjs +71 -0
  521. package/dist/storage/raw-ids.mjs +20 -1
  522. package/dist/storage/ready.d.mts +4 -2
  523. package/dist/storage/ready.mjs +109 -48
  524. package/dist/storage/receive-admission.mjs +67 -0
  525. package/dist/storage/receive-bounds.d.mts +1 -0
  526. package/dist/storage/receive-bounds.mjs +202 -0
  527. package/dist/storage/receive-files.mjs +248 -0
  528. package/dist/storage/receive-links.mjs +281 -244
  529. package/dist/storage/receive-state.d.mts +9 -0
  530. package/dist/storage/receive-state.mjs +150 -0
  531. package/dist/storage/receive-steps.mjs +344 -0
  532. package/dist/storage/receive-sweep.mjs +160 -0
  533. package/dist/storage/receive-table.d.mts +3 -0
  534. package/dist/storage/receive-table.mjs +197 -0
  535. package/dist/storage/repack-backlog.mjs +70 -0
  536. package/dist/storage/repack-contained.mjs +269 -0
  537. package/dist/storage/repack-job.d.mts +3 -0
  538. package/dist/storage/repack-job.mjs +27 -17
  539. package/dist/storage/repack.d.mts +4 -4
  540. package/dist/storage/repack.mjs +156 -77
  541. package/dist/storage/roots.mjs +23 -7
  542. package/dist/storage/rows.d.mts +4 -2
  543. package/dist/storage/rows.mjs +81 -9
  544. package/dist/storage/runs.d.mts +8 -0
  545. package/dist/storage/runs.mjs +731 -0
  546. package/dist/storage/send-list.d.mts +2 -1
  547. package/dist/storage/send-list.mjs +261 -76
  548. package/dist/storage/shallow.d.mts +3 -2
  549. package/dist/storage/shallow.mjs +7 -7
  550. package/dist/storage/single-flight.mjs +47 -0
  551. package/dist/storage/stream-whole.mjs +121 -54
  552. package/dist/storage/swap-walk.mjs +188 -0
  553. package/dist/storage/unpack.mjs +52 -23
  554. package/dist/storage/visible.mjs +58 -39
  555. package/dist/storage/walk.d.mts +2 -0
  556. package/dist/storage/walk.mjs +20 -7
  557. package/dist/storage/wants.mjs +185 -33
  558. package/dist/storage/written-bases.mjs +172 -0
  559. package/dist/store/call-count.d.mts +69 -4
  560. package/dist/store/call-count.mjs +193 -51
  561. package/dist/store/catalogue.d.mts +17 -3
  562. package/dist/store/catalogue.mjs +135 -48
  563. package/dist/store/crossing.mjs +2 -4
  564. package/dist/store/cursor-seal.d.mts +12 -1
  565. package/dist/store/cursor-seal.mjs +7 -6
  566. package/dist/store/errors.d.mts +2 -2
  567. package/dist/store/errors.mjs +112 -24
  568. package/dist/store/git-store.mjs +21 -2
  569. package/dist/store/job-try.mjs +26 -0
  570. package/dist/store/list-job.mjs +23 -17
  571. package/dist/store/outbox.d.mts +15 -5
  572. package/dist/store/outbox.mjs +143 -39
  573. package/dist/store/promises.d.mts +8 -2
  574. package/dist/store/promises.mjs +129 -85
  575. package/dist/store/queue-jobs.mjs +34 -13
  576. package/dist/store/records.d.mts +64 -1
  577. package/dist/store/records.mjs +101 -32
  578. package/dist/store/ref-rows.d.mts +18 -2
  579. package/dist/store/ref-rows.mjs +62 -5
  580. package/dist/store/repo-record.mjs +11 -9
  581. package/dist/store/reservations.mjs +9 -8
  582. package/dist/store/scopes.mjs +13 -11
  583. package/dist/store/settle.mjs +1 -1
  584. package/dist/store/topic-jobs.mjs +4 -4
  585. package/dist/sync/bound.d.mts +5 -3
  586. package/dist/sync/bound.mjs +32 -3
  587. package/dist/sync/github.mjs +7 -7
  588. package/dist/sync/import.d.mts +2 -0
  589. package/dist/sync/import.mjs +46 -50
  590. package/dist/sync/jobs.mjs +15 -23
  591. package/dist/sync/mirror.d.mts +6 -2
  592. package/dist/sync/mirror.mjs +122 -45
  593. package/dist/sync/publish.d.mts +1 -0
  594. package/dist/sync/publish.mjs +22 -19
  595. package/dist/sync/step.mjs +443 -71
  596. package/dist/sync/tries.mjs +50 -32
  597. package/dist/sync.d.mts +3 -3
  598. package/dist/sync.mjs +2 -2
  599. package/dist/topics/advance.mjs +103 -86
  600. package/dist/topics/calls.mjs +97 -67
  601. package/dist/topics/directory.mjs +31 -11
  602. package/dist/topics/host.d.mts +0 -1
  603. package/dist/topics/host.mjs +2 -12
  604. package/dist/topics/members.mjs +30 -24
  605. package/dist/topics/rows.mjs +10 -9
  606. package/dist/topics/topic.mjs +20 -9
  607. package/package.json +8 -15
  608. package/dist/auth/authorize.d.mts +0 -5
  609. package/dist/contracts/objects.mjs +0 -54
  610. package/dist/core/events/stream.d.mts +0 -19
  611. package/dist/core/rules/define.d.mts +0 -5
  612. package/dist/core/rules/define.mjs +0 -13
  613. package/dist/core/rules/fetch.d.mts +0 -5
  614. package/dist/core/sight.mjs +0 -99
  615. package/dist/engine/engine.d.mts +0 -25
  616. package/dist/engine/engine.mjs +0 -49
  617. package/dist/engine/xdiff/NOTICE.md +0 -63
  618. package/dist/engine/xdiff/compiled.d.mts +0 -7
  619. package/dist/engine/xdiff/compiled.mjs +0 -9
  620. package/dist/engine/xdiff/embedded.mjs +0 -4
  621. package/dist/engine/xdiff/node.d.mts +0 -7
  622. package/dist/engine/xdiff/node.mjs +0 -10
  623. package/dist/engine/xdiff/upstream/LGPL-2.1 +0 -511
  624. package/dist/engine/xdiff/xdiff.wasm +0 -0
  625. package/dist/engine.d.mts +0 -3
  626. package/dist/engine.mjs +0 -3
  627. package/dist/lfs/repo.mjs +0 -42
  628. package/dist/storage/distinct-ids.mjs +0 -39
  629. package/dist/storage/held-memo.mjs +0 -188
  630. package/dist/storage/index-remap.d.mts +0 -8
  631. package/dist/sync/records.mjs +0 -73
@@ -1,38 +1,53 @@
1
- import { grantOf } from "../auth/grants.mjs";
2
- import { effectObjects, oneShotReads } from "../storage/calls.mjs";
1
+ import { isRepoName } from "../contracts/ids.mjs";
2
+ import { fail } from "../contracts/result.mjs";
3
+ import { objectsFace, oneShotReads } from "../storage/calls.mjs";
3
4
  import { indexRowKey, isPackId, objectCollections } from "../storage/layout.mjs";
4
5
  import { noLfsPointers } from "../storage/lfs-pointers.mjs";
5
- import { eachPageAt, heldIdsAt } from "../storage/object-rows.mjs";
6
- import { LeavingRow, decodeHeld, leavingKey, leavingRow } from "../storage/rows.mjs";
6
+ import { holdingsOf, swapsOf } from "../storage/repack.mjs";
7
+ import { SwapsSettled, holdingKey, swapsKey } from "../storage/swap-walk.mjs";
8
+ import { ApartRow, apartAfter, apartKey } from "../storage/repack-contained.mjs";
9
+ import { coverRow, decodeLeft, leavingKey, leavingLate, leavingRow, pruneFloor } from "../storage/rows.mjs";
7
10
  import { entryOf, forkOf, forksCreated, heldNameAt, isCreatedKey, listLimit, namedRecordOf, reconcile } from "../store/catalogue.mjs";
8
- import { fail, storeCall } from "../store/errors.mjs";
9
- import { decodePacks, gitStore } from "../store/git-store.mjs";
11
+ import { afterWrites, decodeRow, storeCall } from "../store/errors.mjs";
12
+ import { decodePacks, packRow } from "../store/git-store.mjs";
10
13
  import { appendEvents, decodeOutbox, dropUnconfirmed, emptyOutbox, outboxReads, repoEnvelope } from "../store/outbox.mjs";
11
14
  import { keptKey } from "../store/records.mjs";
12
- import { WholeRepo, wholeRef, wholeRefs } from "../store/ref-rows.mjs";
15
+ import { WholeRepo, refBytesOf, storesPeel, wholeRef, wholeRefs } from "../store/ref-rows.mjs";
16
+ import { peeledAll } from "../storage/wants.mjs";
13
17
  import { commitRecord, decodeTimes, readRecord, timeRow, writeRecord } from "../store/repo-record.mjs";
18
+ import { afterCommit } from "../store/call-count.mjs";
14
19
  import { listBound } from "../store/cursor-seal.mjs";
15
20
  import { settleName } from "../store/settle.mjs";
16
- import { collections, newChangeId, newInternalId, pushedKey, repoScope } from "../store/scopes.mjs";
17
- import { alreadyExists, callerFor, contended, hiddenCodes, indexJobs, keyedRecord, nameMoved, openKeyed, openRepo, repoInfo, sizedRead, statsReads, unlessHidden } from "./access.mjs";
21
+ import { collections, newChangeId, newInternalId, pushedKey, repoScope, selfKey } from "../store/scopes.mjs";
22
+ import { alreadyExists, callerFor, contended, contendedAfterWrites, hiddenCodes, indexJobs, keyedRecord, nameMoved, openKeyed, openRepo, refIndexJobs, repoAccess, sizedRead, statsReads, unlessHidden } from "./access.mjs";
23
+ import { infoReads, repoInfo } from "./repo-info.mjs";
18
24
  import { kindsOf } from "./ancestry.mjs";
19
- import { isHolder, isRepoId } from "./names.mjs";
25
+ import { isHolder } from "./names.mjs";
20
26
  import { decidePush } from "./push-decide.mjs";
27
+ import { gitsOwnRef } from "./rules/check.mjs";
28
+ import { refCopies } from "./ref-index.mjs";
21
29
  import { heldReceipt, receiptKeys, receiptReads, receiptWrites, repoAnswer, withJobs } from "./receipts.mjs";
22
- import { badRepoId, repoKept } from "./repos.mjs";
23
- import { sightIn } from "./sight.mjs";
30
+ import { badRepoName, repoKept } from "./repos.mjs";
31
+ import { pushCounts } from "./events/seen.mjs";
32
+ import { refViewIn } from "./ref-view.mjs";
24
33
  import { SealedObjects } from "./view.mjs";
34
+ import { CoreParts, ObjectsParts } from "./parts.mjs";
35
+ import { check } from "../contracts/authorize.mjs";
25
36
  import { jsonBytes, limits } from "@ref0/infra";
26
37
  import * as Effect from "effect/Effect";
38
+ import * as Clock$1 from "effect/Clock";
27
39
  // src/core/forks.ts
28
40
  /**
29
41
  * A fork copies every ref and object of its source, private or not, until piece 3 copies only
30
42
  * what its caller sees: see `before-production.md`.
31
43
  */
32
- const forkWhole = WholeRepo.mint();
44
+ const forkWhole = /* @__PURE__ */ WholeRepo.mint();
45
+ /** A fork's `index` row as `repoInfo` reads it, by its place after `statsReads`'. */
46
+ const indexRowsOf = (rows) => rows.indexRow === void 0 ? [] : [rows.indexRow];
33
47
  const refsRead = { collection: collections.refs };
34
48
  const packsRead = { collection: collections.packs };
35
49
  const leavingRead = { collection: objectCollections.leaving };
50
+ const coverRead = { collection: objectCollections.cover };
36
51
  /**
37
52
  * What a fork reads of its source, after its `self`: refs and packs. Its object rows are read
38
53
  * apart, a page at a time, by `sourceRows`, and only by a copy.
@@ -47,7 +62,7 @@ const cleaningUp = (fork) => fail("UNAVAILABLE", `'${fork}' is cleaning up a pac
47
62
  * finished, as `namedRecordOf` does, and it's read again; still neither at the version it
48
63
  * reconciled, and the source is gone, as one no name reaches.
49
64
  */
50
- const forkRead = Effect.fnUntraced(function* (store, internalId) {
65
+ const forkRead = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId) {
51
66
  let reconciledAt;
52
67
  for (let attempt = 0; attempt < 5; attempt += 1) {
53
68
  const { record, snapshot } = yield* readRecord(store, internalId, sourceReads);
@@ -76,17 +91,96 @@ const forkRead = Effect.fnUntraced(function* (store, internalId) {
76
91
  }
77
92
  return yield* contended();
78
93
  });
94
+ const isAlreadyThere = (error) => error.code === "ALREADY_EXISTS";
95
+ /**
96
+ * Adds, outside the version, a `leaving` row in `into`'s scope for each of `packs`, due at
97
+ * `removeAt`, with `git.repack` due then, before their markers are put: so a marker no commit of
98
+ * the fork claims, one a call that lost, gave up or stopped left, goes with the fork's clean-up
99
+ * (#1490). `first`, a create's record, deleted, goes with them, so a fork whose create never
100
+ * commits has upkeep to take its rows. The commit that lists a pack deletes its row. A row
101
+ * another call of the fork's added first covers its marker as well, so each is added alone then.
102
+ */
103
+ const coverMarks = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs, removeAt, first = []) {
104
+ const core = yield* CoreParts;
105
+ const leaving = packs.flatMap(({ id, ...size }) => isPackId(id) ? [leavingRow({
106
+ id,
107
+ ...size
108
+ }, removeAt)] : []);
109
+ const put = [...first, ...leaving];
110
+ if (put.length === 0) return;
111
+ const scope = repoScope(into);
112
+ const jobs = [core.repackJobRow(removeAt)];
113
+ const add = (rows) => storeCall(() => core.store.add(scope, {
114
+ put: rows,
115
+ jobs
116
+ }));
117
+ if (yield* add(put).pipe(Effect.as(true), Effect.catchIf(isAlreadyThere, () => Effect.succeed(false)))) return;
118
+ const alone = (row) => add([row]).pipe(Effect.catchIf(isAlreadyThere, () => Effect.void));
119
+ yield* Effect.forEach(put, alone, { discard: true });
120
+ });
121
+ /**
122
+ * Adds, outside the version, a `cover` row in `into`'s scope for each of `packs`, due at
123
+ * `removeAt`, with `git.repack` due then, under a try of its own: a marker a reread found unheld,
124
+ * which the fork's clean-up then lets go as a `leaving` row's (#1582). The row holds the marker,
125
+ * never the try, so the try never deletes it.
126
+ */
127
+ const coverLost = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs, removeAt) {
128
+ const core = yield* CoreParts;
129
+ const tried = newChangeId();
130
+ const put = packs.flatMap(({ id, ...size }) => isPackId(id) ? [coverRow({
131
+ id,
132
+ ...size
133
+ }, tried, removeAt)] : []);
134
+ if (put.length === 0) return;
135
+ const jobs = [core.repackJobRow(removeAt)];
136
+ yield* storeCall(() => core.store.add(repoScope(into), {
137
+ put,
138
+ jobs
139
+ }));
140
+ });
141
+ /**
142
+ * Of `packs`, just marked for `into`, those whose marker no row of `into` holds now: the fork
143
+ * doesn't list the pack, and its `leaving` row is gone or taken. Clean-up took or ended that row
144
+ * before the marker may have landed, so its end may have missed the marker (#1582).
145
+ */
146
+ const unheldOf = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs) {
147
+ const core = yield* CoreParts;
148
+ const named = packs.filter(({ id }) => isPackId(id));
149
+ if (named.length === 0) return [];
150
+ const reads = named.flatMap(({ id }) => [{
151
+ collection: collections.packs,
152
+ id
153
+ }, {
154
+ collection: objectCollections.leaving,
155
+ id
156
+ }]);
157
+ const snapshot = yield* storeCall(() => core.store.read(repoScope(into), reads));
158
+ const unheld = [];
159
+ for (const [index, pack] of named.entries()) {
160
+ const listed = (snapshot.results[2 * index]?.length ?? 0) > 0;
161
+ const row = snapshot.results[2 * index + 1]?.[0];
162
+ const left = row === void 0 ? void 0 : yield* decodeLeft(row);
163
+ if (!listed && (left === void 0 || left.value.taken === true)) unheld.push(pack);
164
+ }
165
+ return unheld;
166
+ });
79
167
  /**
80
168
  * Puts a marker named `into` on each pack the source lists that `marked` doesn't hold, then reads
81
169
  * the source again, until a read lists no pack without one: that read is the one a fork commits,
82
170
  * so no pack it lists can lose its bytes to the source's upkeep between the read and the commit.
171
+ * `cover` adds each pack's `leaving` row before its marker. After each share, the rows are read
172
+ * again: a marker none holds gets a `cover` row and the call fails, keeping the marker (#1582).
83
173
  */
84
- const markPacks = Effect.fnUntraced(function* (core, first, into, marked, signal) {
85
- const objects = effectObjects(SealedObjects.whole(core.objects, forkWhole));
174
+ const markPacks = /* @__PURE__ */ Effect.fnUntraced(function* (first, into, marked, cover, signal) {
175
+ const core = yield* CoreParts;
176
+ const { objects: sealed } = yield* ObjectsParts;
177
+ const objects = objectsFace(SealedObjects.whole(sealed, forkWhole));
86
178
  let read = first;
87
179
  for (let attempt = 0; attempt < 5; attempt += 1) {
88
180
  const unmarked = read.listed.packs.filter((pack) => !marked.has(pack.id));
89
181
  if (unmarked.length === 0) return read;
182
+ for (const pack of unmarked) marked.set(pack.id, pack);
183
+ yield* cover.add(unmarked);
90
184
  const share = signal === void 0 ? { into } : {
91
185
  into,
92
186
  signal
@@ -95,11 +189,50 @@ const markPacks = Effect.fnUntraced(function* (core, first, into, marked, signal
95
189
  ...read.listed,
96
190
  packs: unmarked
97
191
  }, share);
98
- for (const pack of unmarked) marked.set(pack.id, pack);
192
+ const unheld = yield* unheldOf(into, unmarked);
193
+ if (unheld.length > 0) return yield* cover.lost(unheld);
99
194
  read = yield* forkRead(core.store, read.internalId);
100
195
  }
101
- return yield* contended();
196
+ return yield* contendedAfterWrites();
197
+ });
198
+ /**
199
+ * Walks each of `holdings` no try settled and no sync found apart, in order, within what's left of
200
+ * `swapReadsMost`, keeping what it settles in `walks`: none from objects that keep no packs, so a
201
+ * sync swaps nothing.
202
+ */
203
+ const walkHoldings = /* @__PURE__ */ Effect.fnUntraced(function* (listed, holdings, walks, signal) {
204
+ const { objects: sealed } = yield* ObjectsParts;
205
+ const left = holdings.filter((holding) => !walks.settled.has(holdingKey(holding)));
206
+ const { holdings: walk } = objectsFace(SealedObjects.whole(sealed, forkWhole));
207
+ const most = 200 - walks.reads;
208
+ if (left.length === 0 || walk === void 0 || most <= 0) return;
209
+ const input = {
210
+ holdings: left,
211
+ most
212
+ };
213
+ if (signal !== void 0) input.signal = signal;
214
+ const walked = yield* walk(listed, input);
215
+ walks.reads += walked.reads;
216
+ for (const [key, settled] of walked.walked) walks.settled.set(key, settled);
102
217
  });
218
+ /**
219
+ * The `swaps` row after a copy, when it changes: the holdings walked, by syncs before and this one,
220
+ * of packs `keeps` names, the ones the fork goes on listing and its source's.
221
+ */
222
+ const swapsAfter = (keeps, before, walks) => {
223
+ const settled = [...walks.settled].filter(([key]) => key.split(" ").every((id) => keeps.has(id)));
224
+ const of = (kind) => settled.flatMap(([key, each]) => each === kind ? [key] : []).toSorted();
225
+ const value = {
226
+ apart: of("apart"),
227
+ held: of("held")
228
+ };
229
+ return ["apart", "held"].every((kind) => value[kind].join("\n") === before[kind].toSorted().join("\n")) ? [] : [{
230
+ ...swapsKey,
231
+ value
232
+ }];
233
+ };
234
+ /** Whether `row` is a `leaving` row, which the fork's clean-up takes. */
235
+ const isLeavingRow = ({ collection }) => collection === objectCollections.leaving;
103
236
  /** A row as a commit puts it again, in another scope. */
104
237
  const copied = (row) => ({
105
238
  collection: row.collection,
@@ -117,13 +250,17 @@ const unlisted = (marked, listed, at) => [...marked.values()].flatMap(({ id, ...
117
250
  ...size
118
251
  }, at)] : []);
119
252
  /** The default branch's tip in `refs`, or `null` when it has none. */
120
- const tipOf = Effect.fnUntraced(function* (refs, head) {
253
+ const tipOf = /* @__PURE__ */ Effect.fnUntraced(function* (refs, head) {
121
254
  const row = refs.find(({ id }) => id === head);
122
255
  if (row === void 0) return null;
123
256
  return yield* wholeRef(forkWhole, row);
124
257
  });
125
258
  const decodeRefs = (rows) => wholeRefs(forkWhole, rows);
126
- const badHolder = (holder) => fail("INVALID_ARGUMENT", `'${holder}' isn't a fork's holder Git takes`, { hint: "Use one part of a repo ID: letters, digits, '.', '_' and '-'" });
259
+ const badHolder = (holder) => fail("INVALID_ARGUMENT", `'${holder}' isn't a fork's holder Git takes`, { hint: "Use one part of a repo name: letters, digits, '.', '_' and '-'" });
260
+ const noCopyRows = (repo) => fail("FAILED_PRECONDITION", `'${repo}''s rows can't be copied into a fork: the server's objects have no copyRows`, {
261
+ hostHint: "Give the GitObjects that ObjectsFactory.open answers a copyRows, as packs() and loose() do",
262
+ context: { reason: "no-copy-rows" }
263
+ });
127
264
  const ownRepo = (repo) => fail("FAILED_PRECONDITION", `'${repo}' is its holder's own: it can't be forked into itself`, {
128
265
  hint: "Pass the fork another id",
129
266
  context: { reason: "own-repo" }
@@ -135,10 +272,10 @@ const badCursor = (after) => fail("INVALID_ARGUMENT", `'${after}' isn't a cursor
135
272
  * reach; `undefined` for a repo token, which covers no fork of its repo; `''` with neither, or a
136
273
  * grant with no `reach`, where `authorize` decides each fork.
137
274
  */
138
- const forksReach = (caller) => {
275
+ const forksReach = (grants, caller) => {
139
276
  const { token } = caller;
140
277
  if (token !== void 0) return token.repo === void 0 ? token.prefix : void 0;
141
- return grantOf(caller)?.reach ?? "";
278
+ return grants.grantOf(caller)?.reach ?? "";
142
279
  };
143
280
  /**
144
281
  * What a `forks.list` cursor is sealed for: the list of `source`'s forks under `reach`, and no
@@ -186,62 +323,79 @@ const checkChange = (source, change, room = {
186
323
  const isForkOf = (record, source) => record !== void 0 && record.deleted !== true && record.fork?.upstreamInternalId === source;
187
324
  const holderHasOne = (source, holder) => fail("ALREADY_EXISTS", `'${holder}' has a fork of '${source}' already`, { hint: "Ask its holder for it, or fork for another holder" });
188
325
  const notAFork = (repo) => fail("FAILED_PRECONDITION", `'${repo}' isn't a fork`, { context: { reason: "not-a-fork" } });
326
+ /**
327
+ * A sync whose caller can't see the fork's default branch or its source's: named as neither, as
328
+ * `repos.get` leaves a hidden default out, and the same whether or not the branch exists.
329
+ */
330
+ const unseenHead = (repo) => fail("FAILED_PRECONDITION", `'${repo}' has no default branch you can sync`, { hint: "Ask someone who sees both default branches to sync it" });
189
331
  const diverged = (repo) => fail("FAILED_PRECONDITION", `'${repo}' has commits its source's default branch lacks`, {
190
332
  hint: "Merge its source's branch into it, or reset it to the source's",
191
333
  context: { reason: "diverged" }
192
334
  });
193
335
  /** `<holder>/<the source's last segment>`, as GitHub names a fork (Q327). */
336
+ const longDefaultName = (id) => fail("INVALID_ARGUMENT", `The fork's default name '${id}' is longer than 200 characters`, { hint: "Give the fork a shorter 'name', or use a shorter holder" });
194
337
  const defaultId = (source, holder) => `${holder}/${source.split("/").at(-1) ?? source}`;
195
338
  /** The fork's rows, from the read its commit takes: refs, packs and the object rows it copies. */
196
- const forkRows = (read, objects) => [
197
- ...read.refs.map(copied),
339
+ const forkRows = (index, read, objects) => [
340
+ ...refCopies(index, read.refs),
198
341
  ...read.packs.map(copied),
199
342
  ...objects
200
343
  ];
201
344
  /**
202
- * The source's object rows at `read`'s version that `keep` keeps, a page at a time, so no read
203
- * passes one answer's 16 MiB and only the copy is held: refused once those pass one commit's, as
204
- * `checkCopy` refuses. `undefined` once a page answers at another version, or `keep` finds the
205
- * fork moved: the read is taken again.
345
+ * The source's object rows at `read`'s version, of those the ones the fork at `lacking` doesn't
346
+ * hold when it's given, a page at a time through the objects' `copyRows`, so no read passes one
347
+ * answer's 16 MiB and only the copy is held: refused once those pass one commit's, as `checkCopy`
348
+ * refuses. `undefined` once a page answers `moved`: the read is taken again.
206
349
  */
207
- const sourceRows = Effect.fnUntraced(function* (store, read, keep) {
350
+ const sourceRows = /* @__PURE__ */ Effect.fnUntraced(function* (read, lacking, signal) {
351
+ const { objects: sealed } = yield* ObjectsParts;
352
+ const { copyRows } = objectsFace(SealedObjects.whole(sealed, forkWhole));
353
+ if (copyRows === void 0) return yield* noCopyRows(read.name);
208
354
  const rows = [];
209
355
  let bytes = 0;
210
- return (yield* eachPageAt(store, read.internalId, read.listed.version, (page) => Effect.gen(function* () {
211
- const kept = yield* keep(page);
212
- if (kept === void 0) return false;
213
- const copies = kept.map(copied);
214
- rows.push(...copies);
215
- bytes += jsonBytes(copies);
356
+ let after;
357
+ for (;;) {
358
+ const input = {};
359
+ if (after !== void 0) input.after = after;
360
+ if (lacking !== void 0) input.lacking = {
361
+ repo: lacking.internalId,
362
+ version: lacking.version
363
+ };
364
+ if (signal !== void 0) input.signal = signal;
365
+ const page = yield* copyRows(read.listed, input);
366
+ if ("moved" in page) return void 0;
367
+ rows.push(...page.rows);
368
+ bytes += jsonBytes(page.rows);
216
369
  yield* refuseCopy(read.name, rows.length + copyRoom.writes, bytes + copyRoom.bytes);
217
- return true;
218
- }))) ? rows : void 0;
370
+ if (page.next === void 0) return rows;
371
+ after = page.next;
372
+ }
219
373
  });
220
- /** Every row of a page, as a copy into a new fork, which holds none, keeps. */
221
- const keepAll = (rows) => Effect.succeed(rows);
222
374
  /** A fork's record, from its source's read: its branch and visibility, and what it's made from. */
223
- const forkRecord = (read, name, revision, holder, at) => ({
224
- name,
225
- revision,
226
- defaultBranch: read.record.defaultBranch,
227
- public: read.record.public,
228
- fork: {
229
- upstreamInternalId: read.internalId,
230
- holder
231
- },
232
- createdAt: at,
233
- changedAt: at
234
- });
375
+ const forkRecord = (read, name, revision, holder, at, index) => {
376
+ const record = {
377
+ name,
378
+ revision,
379
+ defaultBranch: read.record.defaultBranch,
380
+ public: read.record.public,
381
+ fork: {
382
+ upstreamInternalId: read.internalId,
383
+ holder
384
+ },
385
+ createdAt: at,
386
+ changedAt: at
387
+ };
388
+ if (index !== void 0) record.refIndex = index.stamp;
389
+ return record;
390
+ };
235
391
  /**
236
392
  * `forks`: a fork is a new repo whose first commit lists its source's packs, refs and rows, once
237
393
  * each pack carries a marker of the fork's own, so the source's upkeep never takes bytes the fork
238
394
  * lists. The fork's catalogue row, by its source and holder, commits with its name, so a source
239
- * has one fork a holder, whatever `id` each create asks for (Q327).
395
+ * has one fork a holder, whatever `name` each create asks for (Q327).
240
396
  */
241
- const forkCalls = (core, bound) => {
397
+ const forkCalls = (bound) => {
242
398
  const callerOf = callerFor(bound);
243
- const { store } = core;
244
- const rowStore = gitStore(store);
245
399
  /**
246
400
  * `internalId` as a live fork of `source`, once `caller` may read it: `undefined` for a repo
247
401
  * that's deleted or no fork of `source`, and a refusal as `authorize` answers it. It's named and
@@ -252,16 +406,16 @@ const forkCalls = (core, bound) => {
252
406
  * visibility moved between.
253
407
  */
254
408
  const forkInfo = Effect.fnUntraced(function* (caller, source, internalId) {
409
+ const { store } = yield* CoreParts;
255
410
  for (let attempt = 0; attempt < 5; attempt += 1) {
256
411
  const named = yield* namedRecordOf(store, internalId);
257
412
  if (named === void 0 || !isForkOf(named.record, source)) return void 0;
258
- const { name, record: seen } = named;
259
- const repo = {
260
- id: name,
261
- public: seen.public,
413
+ const { name } = named;
414
+ const repo = repoAccess({
415
+ ...named,
262
416
  internalId
263
- };
264
- yield* core.authorize({
417
+ });
418
+ yield* check({
265
419
  caller,
266
420
  operation: {
267
421
  kind: "read",
@@ -269,11 +423,11 @@ const forkCalls = (core, bound) => {
269
423
  },
270
424
  repo
271
425
  });
272
- const { record, snapshot } = yield* readRecord(store, internalId, statsReads);
426
+ const { record, snapshot } = yield* readRecord(store, internalId, infoReads);
273
427
  if (!isForkOf(record, source)) return void 0;
274
- if ((yield* heldNameAt(store, internalId, record, snapshot.version)) !== name || record.public !== seen.public) continue;
428
+ if ((yield* heldNameAt(store, internalId, record, snapshot.version)) !== name || record.public !== repo.public) continue;
275
429
  const stats = snapshot.results.slice(1);
276
- return yield* repoInfo(core, caller, internalId, {
430
+ return yield* repoInfo(caller, internalId, {
277
431
  ...record,
278
432
  name
279
433
  }, stats);
@@ -282,6 +436,7 @@ const forkCalls = (core, bound) => {
282
436
  });
283
437
  /** The holder's live fork of `source`, as `caller` may read it, or `undefined` for none. */
284
438
  const existingFork = Effect.fnUntraced(function* (caller, source, holder) {
439
+ const { store } = yield* CoreParts;
285
440
  const internalId = yield* forkOf(store, source, holder);
286
441
  if (internalId === void 0) return void 0;
287
442
  return yield* forkInfo(caller, source, internalId);
@@ -297,12 +452,8 @@ const forkCalls = (core, bound) => {
297
452
  * no refusal names it.
298
453
  */
299
454
  const authorizeSource = (caller, read, operation, gone) => {
300
- const repo = {
301
- id: read.name,
302
- public: read.record.public,
303
- internalId: read.internalId
304
- };
305
- return Effect.catchIf(core.authorize({
455
+ const repo = repoAccess(read);
456
+ return Effect.catchIf(check({
306
457
  caller,
307
458
  operation,
308
459
  repo
@@ -314,14 +465,14 @@ const forkCalls = (core, bound) => {
314
465
  * `gone` to a caller who may not read it, so its size reaches no one who may not.
315
466
  */
316
467
  const authorizeRecord = Effect.fnUntraced(function* (caller, source, operation, gone) {
468
+ const { store } = yield* CoreParts;
317
469
  const named = yield* namedRecordOf(store, source);
318
470
  if (named === void 0) return yield* gone();
319
- const repo = {
320
- id: named.name,
321
- public: named.record.public,
471
+ const repo = repoAccess({
472
+ ...named,
322
473
  internalId: source
323
- };
324
- yield* Effect.catchIf(core.authorize({
474
+ });
475
+ yield* Effect.catchIf(check({
325
476
  caller,
326
477
  operation: operation(named.name),
327
478
  repo
@@ -340,16 +491,17 @@ const forkCalls = (core, bound) => {
340
491
  * own tips' reach (`objectsFollowRefs`), so no hidden commit is read through it.
341
492
  */
342
493
  const seenSource = Effect.fnUntraced(function* (caller, read) {
343
- const repo = {
344
- id: read.name,
345
- public: read.record.public,
346
- internalId: read.internalId
494
+ const refView = yield* refViewIn(caller, repoAccess(read));
495
+ if (refView.whole) return {
496
+ ...read,
497
+ headSeen: true
347
498
  };
348
- const sight = yield* sightIn(core, caller, repo);
349
- if (sight.whole) return read;
499
+ const refs = read.refs.filter(({ id }) => refView.sees(id));
500
+ const headSeen = refView.sees(headOf(read.record.defaultBranch));
350
501
  return {
351
502
  ...read,
352
- refs: read.refs.filter(({ id }) => sight.sees(id))
503
+ refs,
504
+ headSeen
353
505
  };
354
506
  });
355
507
  /**
@@ -357,12 +509,13 @@ const forkCalls = (core, bound) => {
357
509
  * up: again while the entry changed after the key's lookup, perhaps by this create, sent before.
358
510
  */
359
511
  const lookUp = Effect.fnUntraced(function* (id, kept, caller) {
512
+ const { store } = yield* CoreParts;
360
513
  for (let attempt = 0; attempt < 5; attempt += 1) {
361
- const keyed = yield* keyedRecord(store, id, kept, (held) => core.authorize({
514
+ const keyed = yield* keyedRecord(store, id, kept, (held) => check({
362
515
  caller,
363
516
  operation: {
364
517
  kind: "read",
365
- repo: held.id
518
+ repo: held.name
366
519
  },
367
520
  repo: held
368
521
  }));
@@ -375,26 +528,31 @@ const forkCalls = (core, bound) => {
375
528
  }
376
529
  return yield* contended();
377
530
  });
378
- const create = Effect.fnUntraced(function* (repo, input) {
531
+ /** `create`'s steps, which share the source's packs into `marked` as they go. */
532
+ const createMarking = Effect.fnUntraced(function* (marked, repo, input) {
533
+ const core = yield* CoreParts;
534
+ const { store } = core;
535
+ const { fetchLimits } = yield* ObjectsParts;
379
536
  const { holder } = input;
380
537
  if (!isHolder(holder)) return yield* badHolder(holder);
381
- if (input.id !== void 0 && !isRepoId(input.id)) return yield* badRepoId(input.id);
538
+ if (input.name !== void 0 && !isRepoName(input.name)) return yield* badRepoName(input.name);
382
539
  const caller = callerOf(input);
383
- const opened = yield* openRepo(core, caller, {
540
+ const opened = yield* openRepo(caller, {
384
541
  kind: "fork.create",
385
542
  repo,
386
543
  holder
387
544
  }, [], input.internalId);
388
545
  const source = opened.internalId;
389
- const id = input.id ?? defaultId(opened.name, holder);
390
- yield* core.authorize({
546
+ const id = input.name ?? defaultId(opened.name, holder);
547
+ if (!isRepoName(id)) return yield* longDefaultName(id);
548
+ yield* check({
391
549
  caller,
392
550
  operation: {
393
551
  kind: "repo.create",
394
552
  repo: id
395
553
  }
396
554
  });
397
- const at = yield* core.now;
555
+ const at = yield* Clock$1.currentTimeMillis;
398
556
  const kept = yield* keptKey(caller, input.key, [
399
557
  "fork",
400
558
  source,
@@ -418,17 +576,33 @@ const forkCalls = (core, bound) => {
418
576
  const forking = (read) => forkingName(read.name);
419
577
  const gone = () => fail("NOT_FOUND", `No repo '${repo}'`);
420
578
  yield* authorizeRecord(caller, source, forkingName, gone);
421
- const marked = /* @__PURE__ */ new Map();
422
579
  let taken;
580
+ const removeAt = at + Math.max(pruneFloor, fetchLimits.milliseconds);
581
+ let asideFirst = true;
582
+ const cover = (read) => ({
583
+ add: (packs) => {
584
+ const aside = {
585
+ ...forkRecord(read, id, revision, holder, at, core.refIndex),
586
+ deleted: true
587
+ };
588
+ const first = asideFirst ? [{
589
+ ...selfKey,
590
+ value: aside
591
+ }] : [];
592
+ asideFirst = false;
593
+ return coverMarks(internalId, packs, removeAt, first);
594
+ },
595
+ lost: (packs) => Effect.andThen(coverLost(internalId, packs, removeAt), () => cleaningUp(repo))
596
+ });
423
597
  for (let attempt = 0; taken === void 0 && attempt < 5; attempt += 1) {
424
598
  const first = yield* sourceSized(forkRead(store, source), caller, source, forkingName, gone);
425
599
  yield* authorizeSource(caller, first, forking(first), gone);
426
- const firstRows = yield* sourceRows(rowStore, first, keepAll);
600
+ const firstRows = yield* sourceRows(first, void 0, input.signal);
427
601
  if (firstRows === void 0) continue;
428
- yield* checkCopy(opened.name, forkRows(first, firstRows));
429
- const checked = yield* sourceSized(markPacks(core, first, internalId, marked, input.signal), caller, source, forkingName, gone);
602
+ yield* checkCopy(opened.name, forkRows(core.refIndex, first, firstRows));
603
+ const checked = yield* sourceSized(markPacks(first, internalId, marked, cover(first), input.signal), caller, source, forkingName, gone);
430
604
  yield* authorizeSource(caller, checked, forking(checked), gone);
431
- const objects = checked.listed.version === first.listed.version ? firstRows : yield* sourceRows(rowStore, checked, keepAll);
605
+ const objects = checked.listed.version === first.listed.version ? firstRows : yield* sourceRows(checked, void 0, input.signal);
432
606
  if (objects !== void 0) taken = {
433
607
  read: checked,
434
608
  objects
@@ -437,15 +611,16 @@ const forkCalls = (core, bound) => {
437
611
  if (taken === void 0) return yield* contended();
438
612
  const { objects } = taken;
439
613
  const read = yield* seenSource(caller, taken.read);
440
- const record = forkRecord(read, id, revision, holder, at);
614
+ const record = forkRecord(read, id, revision, holder, at, core.refIndex);
441
615
  const listing = new Set(read.listed.packs.map((pack) => pack.id));
616
+ const covered = read.listed.packs.flatMap(({ id }) => isPackId(id) ? [leavingKey(id)] : []);
442
617
  const pushed = read.refs.length === 0 ? [] : [timeRow(pushedKey, void 0, at)];
443
618
  const rows = [
444
- ...forkRows(read, objects),
619
+ ...forkRows(core.refIndex, read, objects),
445
620
  ...pushed,
446
621
  ...unlisted(marked, listing, at)
447
622
  ];
448
- const info = yield* repoInfo(core, caller, internalId, record, [
623
+ const info = yield* repoInfo(caller, internalId, record, [
449
624
  read.refs,
450
625
  read.packs,
451
626
  pushed
@@ -485,18 +660,20 @@ const forkCalls = (core, bound) => {
485
660
  };
486
661
  yield* checkChange(opened.name, {
487
662
  put,
663
+ delete: covered,
488
664
  jobs
489
665
  }, room);
490
666
  const written = yield* writeRecord(store, internalId, {
491
667
  expect: 0,
492
668
  record,
493
669
  put,
670
+ delete: covered,
494
671
  jobs
495
672
  });
496
673
  if (written === void 0) return yield* contended();
497
674
  if (written.outcome === "won") return info;
498
675
  const dropped = dropUnconfirmed(appended.head);
499
- yield* commitRecord(store, internalId, {
676
+ const aside = commitRecord(store, internalId, {
500
677
  expect: written.version,
501
678
  record: {
502
679
  ...record,
@@ -505,13 +682,19 @@ const forkCalls = (core, bound) => {
505
682
  put: dropped.put,
506
683
  delete: [...receiptKeys(kept), ...dropped.delete]
507
684
  });
508
- const theirs = yield* holdersFork(caller, opened.name, source, holder);
685
+ const after = Effect.andThen(aside, holdersFork(caller, opened.name, source, holder));
686
+ const theirs = yield* afterCommit(after);
509
687
  if (theirs !== void 0) return theirs;
510
- return yield* written.outcome === "lost" ? alreadyExists(id) : contended();
688
+ return yield* written.outcome === "lost" ? alreadyExists(id) : contendedAfterWrites();
511
689
  });
690
+ const create = (repo, input) => {
691
+ const marked = /* @__PURE__ */ new Map();
692
+ const shared = (error) => marked.size > 0 ? afterWrites(error) : error;
693
+ return Effect.mapError(createMarking(marked, repo, input), shared);
694
+ };
512
695
  const get = Effect.fnUntraced(function* (repo, input) {
513
696
  const caller = callerOf(input);
514
- const opened = yield* openRepo(core, caller, {
697
+ const opened = yield* openRepo(caller, {
515
698
  kind: "read",
516
699
  repo
517
700
  }, [], input.internalId);
@@ -527,6 +710,7 @@ const forkCalls = (core, bound) => {
527
710
  * caller reads neither.
528
711
  */
529
712
  const visibleForks = Effect.fnUntraced(function* (caller, source, reach, limit, after) {
713
+ const { store } = yield* CoreParts;
530
714
  const items = [];
531
715
  let cursor = after;
532
716
  let last = after;
@@ -555,13 +739,14 @@ const forkCalls = (core, bound) => {
555
739
  };
556
740
  });
557
741
  const list = Effect.fnUntraced(function* (repo, input) {
742
+ const core = yield* CoreParts;
558
743
  const caller = callerOf(input);
559
744
  const sent = input.page?.after;
560
- const opened = yield* openRepo(core, caller, {
745
+ const opened = yield* openRepo(caller, {
561
746
  kind: "read",
562
747
  repo
563
748
  }, [], input.internalId);
564
- const reach = forksReach(caller);
749
+ const reach = forksReach(core.grants, caller);
565
750
  const bound = forksListBound(opened.internalId, reach);
566
751
  const after = sent === void 0 ? void 0 : yield* core.cursors.open(bound, sent);
567
752
  if (sent !== void 0 && (after === void 0 || !isCreatedKey(after))) return yield* badCursor(sent);
@@ -575,13 +760,13 @@ const forkCalls = (core, bound) => {
575
760
  /** `fork.sync` asked of `authorize` for `repo`, the fork as its record names its holder now. */
576
761
  const authorizeSync = Effect.fnUntraced(function* (caller, repo, record) {
577
762
  const of = record?.fork;
578
- if (of === void 0) return yield* notAFork(repo.id);
763
+ if (of === void 0) return yield* notAFork(repo.name);
579
764
  const operation = {
580
765
  kind: "fork.sync",
581
- repo: repo.id,
766
+ repo: repo.name,
582
767
  holder: of.holder
583
768
  };
584
- yield* core.authorize({
769
+ yield* check({
585
770
  caller,
586
771
  operation,
587
772
  repo
@@ -593,17 +778,18 @@ const forkCalls = (core, bound) => {
593
778
  * finds its receipt in the repo it moved, and never syncs the new one.
594
779
  */
595
780
  const openSync = Effect.fnUntraced(function* (fork, caller, kept, internalId) {
781
+ const { store } = yield* CoreParts;
596
782
  for (let attempt = 0; attempt < 5; attempt += 1) {
597
- const keyed = yield* keyedRecord(store, fork, kept, (repo) => Effect.andThen(core.authorize({
783
+ const keyed = yield* keyedRecord(store, fork, kept, (repo) => Effect.andThen(check({
598
784
  caller,
599
785
  operation: {
600
786
  kind: "read",
601
- repo: repo.id
787
+ repo: repo.name
602
788
  },
603
789
  repo
604
790
  }), Effect.flatMap(readRecord(store, repo.internalId), ({ record }) => authorizeSync(caller, repo, record))), internalId);
605
791
  if (keyed?.kind === "answered") return keyed;
606
- const opened = yield* openKeyed(core, caller, {
792
+ const opened = yield* openKeyed(caller, {
607
793
  kind: "read",
608
794
  repo: fork
609
795
  }, [], keyed, internalId);
@@ -620,10 +806,15 @@ const forkCalls = (core, bound) => {
620
806
  * try must read again.
621
807
  */
622
808
  const forkTry = Effect.fnUntraced(function* (fork, caller, internalId, kept, may) {
809
+ const core = yield* CoreParts;
810
+ const { store } = core;
623
811
  const reads = [
624
812
  ...statsReads,
625
813
  leavingRead,
626
- indexRowKey
814
+ coverRead,
815
+ indexRowKey,
816
+ apartKey,
817
+ swapsKey
627
818
  ];
628
819
  const hiddenFork = () => fail("NOT_FOUND", `No repo '${fork}'`);
629
820
  const fence = core.fences(caller, {
@@ -640,7 +831,7 @@ const forkCalls = (core, bound) => {
640
831
  repo: name
641
832
  }), hiddenFork);
642
833
  if (record === void 0 || record.deleted === true) return yield* fail("NOT_FOUND", `No repo '${fork}'`);
643
- const [, refRows = [], packRows = [], timeRows = [], leavingRows = [], indexRows = []] = snapshot.results;
834
+ const [, refRows = [], packRows = [], timeRows = [], leavingRows = [], coverRows = [], indexRows = [], apartRows = [], swapsRows = []] = snapshot.results;
644
835
  const [headRows = [], cursorRows = [], ...afterOutbox] = snapshot.results.slice(1 + reads.length);
645
836
  const keyed = receiptReads(kept).length;
646
837
  yield* fence.check(afterOutbox.slice(keyed));
@@ -657,12 +848,12 @@ const forkCalls = (core, bound) => {
657
848
  yield* reconcile(store, internalId);
658
849
  return;
659
850
  }
660
- const target = {
661
- id: name,
662
- public: record.public,
851
+ const target = repoAccess({
852
+ name,
853
+ record,
663
854
  internalId
664
- };
665
- yield* Effect.catchIf(core.authorize({
855
+ });
856
+ yield* Effect.catchIf(check({
666
857
  caller,
667
858
  operation: {
668
859
  kind: "read",
@@ -681,6 +872,9 @@ const forkCalls = (core, bound) => {
681
872
  packRows,
682
873
  timeRows,
683
874
  leavingRows,
875
+ coverRows,
876
+ apartRows,
877
+ swapsRows,
684
878
  indexRow: indexRows[0]
685
879
  },
686
880
  receipts: afterOutbox.slice(0, keyed)
@@ -691,6 +885,7 @@ const forkCalls = (core, bound) => {
691
885
  * deleted source's fork is, before its rows are read.
692
886
  */
693
887
  const readSource = Effect.fnUntraced(function* (caller, upstream) {
888
+ const { store } = yield* CoreParts;
694
889
  const readingName = (name) => ({
695
890
  kind: "read",
696
891
  repo: name
@@ -706,48 +901,84 @@ const forkCalls = (core, bound) => {
706
901
  * until a read lists none without one. `checked` decides that read, or `undefined` reads again.
707
902
  */
708
903
  const copyInto = Effect.fnUntraced(function* (caller, fork, into, first, checked, signal) {
904
+ const { fetchLimits } = yield* ObjectsParts;
709
905
  const { listing, rows, marked, shared } = into;
710
- const held = yield* Effect.forEach(rows.leavingRows, (row) => decodeHeld(LeavingRow, row));
906
+ const held = yield* Effect.forEach([...rows.leavingRows, ...rows.coverRows], decodeLeft);
711
907
  const relistedOf = (packs) => {
712
908
  const ids = new Set(packs.flatMap(({ id }) => listing.has(id) ? [] : [id]));
713
909
  return held.filter(({ pack }) => ids.has(pack));
714
910
  };
715
911
  const due = (packs) => relistedOf(packs).some(({ value }) => value.taken === true);
716
912
  if (due(first.listed.packs)) return yield* cleaningUp(fork);
717
- const lacking = (page) => Effect.map(heldIdsAt(rowStore, into.internalId, into.version, page.map(({ id }) => id)), (owns) => owns && page.filter(({ id }) => !owns.has(id)));
718
- const firstRows = yield* sourceRows(rowStore, first, lacking);
913
+ const firstRows = yield* sourceRows(first, into, signal);
719
914
  if (firstRows === void 0) return void 0;
720
915
  const addedRows = first.packs.filter(({ id }) => !listing.has(id));
721
916
  yield* checkCopy(first.name, [...firstRows, ...addedRows]);
917
+ const removeAt = into.at + Math.max(pruneFloor, fetchLimits.milliseconds);
918
+ const cover = {
919
+ add: (packs) => coverMarks(into.internalId, packs, removeAt),
920
+ lost: (packs) => Effect.andThen(coverLost(into.internalId, packs, removeAt), () => cleaningUp(fork))
921
+ };
722
922
  const readingName = (name) => ({
723
923
  kind: "read",
724
924
  repo: name
725
925
  });
726
- const marking = yield* sourceSized(markPacks(core, first, into.internalId, marked, signal), caller, first.internalId, readingName, sourceGone);
926
+ const marking = yield* sourceSized(markPacks(first, into.internalId, marked, cover, signal), caller, first.internalId, readingName, sourceGone);
727
927
  yield* authorizeSource(caller, marking, readingName(marking.name), sourceGone);
728
928
  const source = yield* seenSource(caller, marking);
729
929
  for (const [id, pack] of marked) if (!listing.has(id)) shared.set(id, pack);
730
930
  if (!(yield* checked(source))) return void 0;
731
- const lacked = source.listed.version === first.listed.version ? firstRows : yield* sourceRows(rowStore, source, lacking);
931
+ const lacked = source.listed.version === first.listed.version ? firstRows : yield* sourceRows(source, into, signal);
732
932
  if (lacked === void 0) return void 0;
733
- const added = source.listed.packs.filter(({ id }) => !listing.has(id));
933
+ const addable = source.listed.packs.filter(({ id }) => !listing.has(id));
934
+ const weighed = [...into.owned, ...addable];
935
+ const holdings = holdingsOf(weighed);
936
+ const [swapsRow] = rows.swapsRows;
937
+ const swapsBefore = swapsRow === void 0 ? {
938
+ apart: [],
939
+ held: []
940
+ } : yield* decodeRow(SwapsSettled, swapsRow, "The holdings walked");
941
+ for (const key of swapsBefore.apart) into.walks.settled.set(key, "apart");
942
+ for (const key of swapsBefore.held) into.walks.settled.set(key, "held");
943
+ yield* walkHoldings(source.listed, holdings, into.walks, signal);
944
+ const proved = holdings.filter((holding) => into.walks.settled.get(holdingKey(holding)) === "held");
945
+ const swaps = swapsOf(into.owned, addable, proved);
946
+ const added = [...swaps.add];
734
947
  const adding = new Set(added.map(({ id }) => id));
735
- const relisted = relistedOf(added);
736
948
  if (due(added)) return yield* cleaningUp(fork);
949
+ const removing = new Set(swaps.remove);
950
+ const leaving = new Set(rows.leavingRows.map(({ id }) => id));
951
+ const kept = [...listing].filter((id) => !removing.has(id));
737
952
  const covered = /* @__PURE__ */ new Set([
738
- ...listing,
953
+ ...kept,
739
954
  ...adding,
740
- ...rows.leavingRows.map(({ id }) => id)
955
+ ...leaving
741
956
  ]);
957
+ const swapped = into.owned.flatMap(({ id, objects, bytes }) => removing.has(id) && isPackId(id) ? [leavingRow({
958
+ id,
959
+ objects,
960
+ bytes
961
+ }, removeAt)] : []);
962
+ const [apartRow] = rows.apartRows;
963
+ const found = apartRow === void 0 ? void 0 : yield* decodeRow(ApartRow, apartRow, "The packs found apart");
964
+ const remove = [...removing];
742
965
  return {
743
966
  source,
744
967
  added,
968
+ removing,
745
969
  received: {
746
970
  id: newChangeId(),
747
971
  change: {
748
972
  add: added,
749
- put: [...lacked, ...unlisted(shared, covered, into.at)],
750
- delete: relisted.map(({ pack }) => leavingKey(pack))
973
+ remove,
974
+ put: [
975
+ ...lacked,
976
+ ...unlisted(shared, covered, into.at),
977
+ ...swapped,
978
+ ...apartAfter(found, { remove }),
979
+ ...swapsAfter(/* @__PURE__ */ new Set([...kept, ...source.listed.packs.map(({ id }) => id)]), swapsBefore, into.walks)
980
+ ],
981
+ delete: [...added.flatMap(({ id }) => isPackId(id) ? [leavingKey(id)] : []), ...held.flatMap(({ key, pack }) => key.collection === objectCollections.cover && adding.has(pack) ? [key] : [])]
751
982
  },
752
983
  bytes: added.reduce((sum, pack) => sum + pack.bytes, 0),
753
984
  objects: added.reduce((sum, pack) => sum + pack.objects, 0),
@@ -760,8 +991,11 @@ const forkCalls = (core, bound) => {
760
991
  get,
761
992
  list,
762
993
  sync: Effect.fnUntraced(function* (fork, input) {
994
+ const core = yield* CoreParts;
995
+ const { objects: sealed } = yield* ObjectsParts;
996
+ const { store } = core;
763
997
  const caller = callerOf(input);
764
- const started = yield* core.now;
998
+ const started = yield* Clock$1.currentTimeMillis;
765
999
  const kept = yield* keptKey(caller, input.key, ["fork.sync", fork], started);
766
1000
  const looked = yield* openSync(fork, caller, kept, input.internalId);
767
1001
  if (looked.kind === "answered") return yield* repoAnswer(looked.receipt);
@@ -769,13 +1003,17 @@ const forkCalls = (core, bound) => {
769
1003
  const of = opened.record.fork;
770
1004
  if (of === void 0) return yield* notAFork(fork);
771
1005
  const { internalId } = opened;
772
- const objects = effectObjects(SealedObjects.whole(core.objects, forkWhole));
1006
+ const objects = objectsFace(SealedObjects.whole(sealed, forkWhole));
773
1007
  const reads = oneShotReads(objects);
774
1008
  const scope = repoScope(internalId);
775
1009
  const shared = /* @__PURE__ */ new Map();
1010
+ const walks = {
1011
+ settled: /* @__PURE__ */ new Map(),
1012
+ reads: 0
1013
+ };
776
1014
  const signal = input.signal === void 0 ? {} : { signal: input.signal };
777
1015
  for (let attempt = 0; attempt < 5; attempt += 1) {
778
- const at = yield* core.now;
1016
+ const at = yield* Clock$1.currentTimeMillis;
779
1017
  const read = yield* forkTry(fork, caller, internalId, kept, (target, record) => authorizeSync(caller, target, record));
780
1018
  if (read === void 0) continue;
781
1019
  const { record, snapshot, name, outbox, rows } = read;
@@ -792,13 +1030,20 @@ const forkCalls = (core, bound) => {
792
1030
  const first = yield* readSource(caller, of.upstreamInternalId);
793
1031
  const sourceHead = headOf(first.record.defaultBranch);
794
1032
  const head = headOf(record.defaultBranch);
1033
+ const forkView = yield* refViewIn(caller, {
1034
+ name,
1035
+ public: record.public,
1036
+ internalId
1037
+ });
1038
+ if (!first.headSeen || !forkView.sees(head)) return yield* unseenHead(fork);
795
1039
  const from = yield* tipOf(refRows, head);
796
1040
  const to = yield* tipOf(first.refs, sourceHead);
797
1041
  const unchanged = Effect.gen(function* () {
798
- const info = yield* repoInfo(core, caller, internalId, named, [
1042
+ const info = yield* repoInfo(caller, internalId, named, [
799
1043
  refRows,
800
1044
  packRows,
801
- timeRows
1045
+ timeRows,
1046
+ indexRowsOf(rows)
802
1047
  ]);
803
1048
  const left = unlisted(shared, /* @__PURE__ */ new Set([...listing, ...leavingRows.map(({ id }) => id)]), at);
804
1049
  if (kept === void 0 && left.length === 0) return info;
@@ -816,6 +1061,8 @@ const forkCalls = (core, bound) => {
816
1061
  if (info !== void 0) return info;
817
1062
  continue;
818
1063
  }
1064
+ const gitsOwn = gitsOwnRef(core.hiddenRefs(), head, void 0);
1065
+ if (gitsOwn !== void 0) return yield* Effect.fail(gitsOwn);
819
1066
  const edits = [{
820
1067
  ref: head,
821
1068
  from,
@@ -838,25 +1085,33 @@ const forkCalls = (core, bound) => {
838
1085
  if (refusal !== void 0) return yield* Effect.fail(refusal);
839
1086
  const kind = update.kind === "force" ? yield* kinds.exact(update) : update.kind;
840
1087
  if (kind === "force") return yield* diverged(fork);
1088
+ const peeling = storesPeel(head) ? yield* peeledAll(reads, first.listed, [to]) : void 0;
1089
+ const unpeelable = peeling?.refused.get(to);
1090
+ if (unpeelable !== void 0) return yield* Effect.fail(unpeelable);
841
1091
  const into = {
842
1092
  internalId,
843
1093
  version: snapshot.version,
844
1094
  listing,
845
1095
  rows,
1096
+ owned,
846
1097
  marked,
847
1098
  shared,
1099
+ walks,
848
1100
  at
849
1101
  };
850
1102
  const tipHeld = (source) => Effect.map(tipOf(source.refs, headOf(source.record.defaultBranch)), (tip) => tip === to);
851
1103
  const copy = yield* copyInto(caller, fork, into, first, tipHeld, input.signal);
852
1104
  if (copy === void 0) continue;
853
- const { source, added, received } = copy;
1105
+ const { source, added, removing, received } = copy;
854
1106
  const refs = yield* decodeRefs(refRows);
855
1107
  const decision = decidePush({
1108
+ index: core.refIndex,
856
1109
  read: {
857
1110
  version: snapshot.version,
858
1111
  refs,
859
- head
1112
+ refBytes: refBytesOf(refRows),
1113
+ head,
1114
+ record
860
1115
  },
861
1116
  command: {
862
1117
  source: "api",
@@ -866,7 +1121,8 @@ const forkCalls = (core, bound) => {
866
1121
  }],
867
1122
  atomic: true,
868
1123
  received,
869
- refused: /* @__PURE__ */ new Map()
1124
+ refused: /* @__PURE__ */ new Map(),
1125
+ peels: /* @__PURE__ */ new Map([[to, peeling?.peeled.get(to) ?? null]])
870
1126
  }
871
1127
  });
872
1128
  if (decision.kind === "answer") {
@@ -883,21 +1139,15 @@ const forkCalls = (core, bound) => {
883
1139
  id: head,
884
1140
  value: { oid: to }
885
1141
  }];
886
- const listedRows = [...packRows, ...added.map(({ id, objects: count, bytes }) => ({
887
- collection: collections.packs,
888
- id,
889
- value: {
890
- objects: count,
891
- bytes
892
- }
893
- }))];
1142
+ const listedRows = [...packRows.filter(({ id }) => !removing.has(id)), ...added.map(packRow)];
894
1143
  const times = yield* decodeTimes(timeRows);
895
1144
  const pushed = timeRow(pushedKey, times.pushed, at);
896
1145
  const timed = [...timeRows.filter(({ id }) => id !== pushedKey.id), pushed];
897
- const info = yield* repoInfo(core, caller, internalId, named, [
1146
+ const info = yield* repoInfo(caller, internalId, named, [
898
1147
  moved,
899
1148
  listedRows,
900
- timed
1149
+ timed,
1150
+ indexRowsOf(rows)
901
1151
  ]);
902
1152
  const keptWrites = receiptWrites(kept, repoKept(info), core.repackJobRow);
903
1153
  const write = newChangeId();
@@ -905,10 +1155,10 @@ const forkCalls = (core, bound) => {
905
1155
  type: "ref.updated",
906
1156
  ...repoEnvelope(caller, name),
907
1157
  ...move,
1158
+ kind,
908
1159
  push: {
909
1160
  id: write,
910
- branches: head.startsWith("refs/heads/") ? 1 : 0,
911
- tags: 0,
1161
+ ...pushCounts(core.access, decision.moved),
912
1162
  source: "api"
913
1163
  }
914
1164
  }));
@@ -916,16 +1166,22 @@ const forkCalls = (core, bound) => {
916
1166
  scope,
917
1167
  at
918
1168
  });
919
- const upkeep = added.length > 0 || objects.readyShallow ? [core.repackJobRow()] : [];
920
- const indexed = SealedObjects.whole(core.objects, forkWhole).index?.status(rows.indexRow, at);
921
- const jobs = [...upkeep, ...indexJobs(core, indexed)];
1169
+ const leaves = received.change.put?.some(isLeavingRow) === true;
1170
+ const upkeep = added.length > 0 || leaves || objects.readyShallow ? [core.repackJobRow()] : [];
1171
+ const indexed = SealedObjects.whole(sealed, forkWhole).index?.status(rows.indexRow, at, listedRows.map(({ id }) => id));
1172
+ const jobs = [
1173
+ ...upkeep,
1174
+ ...indexJobs(core, indexed),
1175
+ ...refIndexJobs(core, record)
1176
+ ];
1177
+ const late = (yield* Clock$1.currentTimeMillis) - at;
922
1178
  const change = {
923
- put: [
1179
+ put: leavingLate([
924
1180
  ...decision.change.put,
925
1181
  pushed,
926
1182
  ...keptWrites.put,
927
1183
  ...appended.put
928
- ],
1184
+ ], late),
929
1185
  delete: [...decision.change.delete, ...appended.delete],
930
1186
  jobs: withJobs([...jobs, ...appended.jobs], keptWrites.jobs)
931
1187
  };
@@ -940,8 +1196,10 @@ const forkCalls = (core, bound) => {
940
1196
  return yield* contended();
941
1197
  }),
942
1198
  fetch: Effect.fnUntraced(function* (fork, input) {
1199
+ const core = yield* CoreParts;
1200
+ const { store } = core;
943
1201
  const caller = callerOf(input);
944
- const opened = yield* openRepo(core, caller, {
1202
+ const opened = yield* openRepo(caller, {
945
1203
  kind: "read",
946
1204
  repo: fork
947
1205
  }, [], input.internalId);
@@ -949,16 +1207,20 @@ const forkCalls = (core, bound) => {
949
1207
  if (of === void 0) return yield* notAFork(fork);
950
1208
  const { internalId } = opened;
951
1209
  const shared = /* @__PURE__ */ new Map();
952
- const may = (target) => core.authorize({
1210
+ const walks = {
1211
+ settled: /* @__PURE__ */ new Map(),
1212
+ reads: 0
1213
+ };
1214
+ const may = (target) => check({
953
1215
  caller,
954
1216
  operation: {
955
1217
  kind: "object.create",
956
- repo: target.id
1218
+ repo: target.name
957
1219
  },
958
1220
  repo: target
959
1221
  });
960
1222
  for (let attempt = 0; attempt < 5; attempt += 1) {
961
- const at = yield* core.now;
1223
+ const at = yield* Clock$1.currentTimeMillis;
962
1224
  const read = yield* forkTry(fork, caller, internalId, void 0, may);
963
1225
  if (read === void 0) continue;
964
1226
  const { record, snapshot, rows } = read;
@@ -970,8 +1232,10 @@ const forkCalls = (core, bound) => {
970
1232
  version: snapshot.version,
971
1233
  listing,
972
1234
  rows,
1235
+ owned,
973
1236
  marked,
974
1237
  shared,
1238
+ walks,
975
1239
  at
976
1240
  };
977
1241
  const first = yield* readSource(caller, of.upstreamInternalId);
@@ -981,21 +1245,29 @@ const forkCalls = (core, bound) => {
981
1245
  const tips = yield* decodeRefs(source.refs);
982
1246
  const fetched = {
983
1247
  source: source.name,
984
- head: headOf(source.record.defaultBranch),
985
1248
  tips: [...tips].map(([ref, oid]) => ({
986
1249
  name: ref,
987
1250
  oid
988
1251
  }))
989
1252
  };
990
- const { put = [], delete: drop = [] } = received.change;
991
- if (added.length === 0 && put.length === 0 && drop.length === 0) return fetched;
1253
+ if (source.headSeen) fetched.head = headOf(source.record.defaultBranch);
1254
+ const { put = [], delete: drop = [], remove = [] } = received.change;
1255
+ if ([
1256
+ added,
1257
+ remove,
1258
+ put,
1259
+ drop
1260
+ ].every(({ length }) => length === 0)) return fetched;
992
1261
  const refs = yield* decodeRefs(rows.refRows);
993
1262
  const head = headOf(record.defaultBranch);
994
1263
  const decision = decidePush({
1264
+ index: core.refIndex,
995
1265
  read: {
996
1266
  version: snapshot.version,
997
1267
  refs,
998
- head
1268
+ refBytes: refBytesOf(rows.refRows),
1269
+ head,
1270
+ record
999
1271
  },
1000
1272
  command: {
1001
1273
  source: "api",
@@ -1009,8 +1281,10 @@ const forkCalls = (core, bound) => {
1009
1281
  const { answer } = decision;
1010
1282
  return answer.kind === "error" ? yield* Effect.fail(answer.error) : fetched;
1011
1283
  }
1284
+ const late = (yield* Clock$1.currentTimeMillis) - at;
1012
1285
  const change = {
1013
1286
  ...decision.change,
1287
+ put: leavingLate(decision.change.put, late),
1014
1288
  jobs: [core.repackJobRow()]
1015
1289
  };
1016
1290
  yield* checkChange(source.name, change);