@ref0/git 0.6.0 → 0.8.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 (476) hide show
  1. package/dist/access/namespace.d.mts +2 -0
  2. package/dist/access/private-refs.d.mts +6 -29
  3. package/dist/access/private-refs.mjs +26 -13
  4. package/dist/access/public.d.mts +6 -0
  5. package/dist/access/public.mjs +9 -0
  6. package/dist/auth/access-jwt.d.mts +10 -6
  7. package/dist/auth/access-jwt.mjs +59 -40
  8. package/dist/auth/auth-namespace.d.mts +6 -0
  9. package/dist/auth/auth-namespace.mjs +12 -0
  10. package/dist/auth/auth.d.mts +3 -6
  11. package/dist/auth/auth.mjs +2 -9
  12. package/dist/auth/authorize.mjs +35 -29
  13. package/dist/auth/bridge.mjs +8 -8
  14. package/dist/auth/fences.d.mts +1 -2
  15. package/dist/auth/fences.mjs +1 -1
  16. package/dist/auth/grants.d.mts +0 -1
  17. package/dist/auth/grants.mjs +2 -2
  18. package/dist/auth/host-function.d.mts +1 -7
  19. package/dist/auth/host-function.mjs +51 -42
  20. package/dist/auth/identify.d.mts +0 -1
  21. package/dist/auth/identify.mjs +3 -2
  22. package/dist/auth/namespaces.d.mts +2 -2
  23. package/dist/auth/policy.d.mts +7 -4
  24. package/dist/auth/policy.mjs +13 -10
  25. package/dist/auth/token-rows.mjs +3 -6
  26. package/dist/auth/tokens-layer.d.mts +40 -0
  27. package/dist/auth/tokens-layer.mjs +29 -0
  28. package/dist/auth/tokens-namespace.d.mts +2 -0
  29. package/dist/auth/tokens-public.d.mts +6 -0
  30. package/dist/auth/tokens-public.mjs +31 -0
  31. package/dist/auth/tokens.d.mts +19 -7
  32. package/dist/auth/tokens.mjs +12 -6
  33. package/dist/auth.d.mts +2 -2
  34. package/dist/auth.mjs +2 -2
  35. package/dist/client/client.d.mts +22 -15
  36. package/dist/client/client.mjs +31 -27
  37. package/dist/client/git-http.mjs +23 -6
  38. package/dist/client/local.mjs +5 -4
  39. package/dist/client/namespace.d.mts +2 -0
  40. package/dist/client/push-upload.d.mts +1 -0
  41. package/dist/client/push-upload.mjs +169 -2
  42. package/dist/client/remote-helper.mjs +5 -12
  43. package/dist/client/remote.mjs +63 -22
  44. package/dist/client/run-remote-helper.d.mts +1 -1
  45. package/dist/client/run-remote-helper.mjs +6 -6
  46. package/dist/client/slice-push.d.mts +1 -1
  47. package/dist/client/transport.mjs +26 -19
  48. package/dist/contracts/access.d.mts +18 -10
  49. package/dist/contracts/access.mjs +17 -0
  50. package/dist/contracts/actors.d.mts +73 -28
  51. package/dist/contracts/actors.mjs +45 -2
  52. package/dist/contracts/authorize.d.mts +26 -17
  53. package/dist/contracts/blobs.d.mts +1 -1
  54. package/dist/contracts/blobs.mjs +1 -1
  55. package/dist/contracts/callers.mjs +40 -0
  56. package/dist/contracts/calls-spent.d.mts +6 -4
  57. package/dist/contracts/calls-spent.mjs +10 -8
  58. package/dist/contracts/client.d.mts +16 -9
  59. package/dist/contracts/commits.d.mts +2 -2
  60. package/dist/contracts/commits.mjs +1 -1
  61. package/dist/contracts/engine.d.mts +1 -1
  62. package/dist/contracts/events.d.mts +45 -32
  63. package/dist/contracts/events.mjs +21 -10
  64. package/dist/contracts/files.d.mts +44 -44
  65. package/dist/contracts/files.mjs +1 -1
  66. package/dist/contracts/forks.d.mts +34 -58
  67. package/dist/contracts/forks.mjs +1 -1
  68. package/dist/contracts/git-events.d.mts +50 -0
  69. package/dist/contracts/git-events.mjs +23 -0
  70. package/dist/contracts/git-hooks.d.mts +254 -0
  71. package/dist/contracts/git-hooks.mjs +12 -0
  72. package/dist/contracts/git.d.mts +93 -42
  73. package/dist/contracts/git.mjs +6 -5
  74. package/dist/contracts/grants.d.mts +46 -27
  75. package/dist/contracts/ids.d.mts +16 -0
  76. package/dist/contracts/ids.mjs +19 -4
  77. package/dist/contracts/lfs.d.mts +19 -4
  78. package/dist/contracts/merges.d.mts +7 -7
  79. package/dist/contracts/namespaces.d.mts +2 -2
  80. package/dist/contracts/objects.d.mts +21 -5
  81. package/dist/contracts/opaque.mjs +27 -0
  82. package/dist/contracts/operations.d.mts +301 -101
  83. package/dist/contracts/operations.mjs +209 -0
  84. package/dist/contracts/promises.d.mts +2 -0
  85. package/dist/contracts/push-uploads.d.mts +4 -1
  86. package/dist/contracts/push-uploads.mjs +9 -4
  87. package/dist/contracts/queue.d.mts +220 -49
  88. package/dist/contracts/queue.mjs +68 -6
  89. package/dist/contracts/refs.d.mts +30 -8
  90. package/dist/contracts/refs.mjs +1 -1
  91. package/dist/contracts/remote.d.mts +53 -23
  92. package/dist/contracts/remote.mjs +22 -0
  93. package/dist/contracts/repo-records.d.mts +2 -2
  94. package/dist/contracts/repos.d.mts +100 -82
  95. package/dist/contracts/repos.mjs +47 -8
  96. package/dist/contracts/result.d.mts +73 -41
  97. package/dist/contracts/result.mjs +74 -17
  98. package/dist/contracts/rules.d.mts +734 -68
  99. package/dist/contracts/rules.mjs +84 -1
  100. package/dist/contracts/server.d.mts +20 -206
  101. package/dist/contracts/services.d.mts +1 -10
  102. package/dist/contracts/services.mjs +1 -5
  103. package/dist/contracts/signin.d.mts +140 -43
  104. package/dist/contracts/signin.mjs +36 -3
  105. package/dist/contracts/store.d.mts +1 -1
  106. package/dist/contracts/sync.d.mts +109 -90
  107. package/dist/contracts/sync.mjs +34 -7
  108. package/dist/contracts/tags.d.mts +1 -1
  109. package/dist/contracts/tags.mjs +1 -1
  110. package/dist/contracts/tokens.d.mts +247 -60
  111. package/dist/contracts/tokens.mjs +93 -21
  112. package/dist/contracts/topics.d.mts +59 -20
  113. package/dist/contracts/topics.mjs +14 -5
  114. package/dist/contracts/trees.d.mts +2 -2
  115. package/dist/contracts/trees.mjs +1 -1
  116. package/dist/contracts/work.d.mts +2 -2
  117. package/dist/contracts/work.mjs +2 -2
  118. package/dist/core/access.d.mts +10 -12
  119. package/dist/core/access.mjs +45 -11
  120. package/dist/core/clock.mjs +1 -1
  121. package/dist/core/events/deliver.d.mts +3 -2
  122. package/dist/core/events/deliver.mjs +188 -92
  123. package/dist/core/forks.mjs +78 -34
  124. package/dist/core/hooks/groups.d.mts +26 -0
  125. package/dist/core/hooks/groups.mjs +73 -0
  126. package/dist/core/hooks/namespace.d.mts +2 -0
  127. package/dist/core/hooks/order.d.mts +2 -2
  128. package/dist/core/hooks/order.mjs +6 -6
  129. package/dist/core/hooks/public.d.mts +7 -0
  130. package/dist/core/hooks/public.mjs +5 -0
  131. package/dist/core/imports.mjs +94 -10
  132. package/dist/core/index-job.mjs +11 -8
  133. package/dist/core/loose-tally.mjs +46 -0
  134. package/dist/core/merge-parts.d.mts +1 -1
  135. package/dist/core/merge-parts.mjs +1 -1
  136. package/dist/core/mirror-rows.mjs +18 -0
  137. package/dist/core/names.mjs +1 -1
  138. package/dist/core/namespaces.d.mts +2 -1
  139. package/dist/core/objects/commit-writes.mjs +5 -5
  140. package/dist/core/objects/merges.mjs +1 -1
  141. package/dist/core/objects/objects-layer.mjs +1 -1
  142. package/dist/core/objects/reading.mjs +52 -7
  143. package/dist/core/objects/tree-edits.mjs +13 -28
  144. package/dist/core/objects/trees.mjs +4 -4
  145. package/dist/core/objects/writing.mjs +4 -3
  146. package/dist/core/own-writes.mjs +1 -1
  147. package/dist/core/parts.d.mts +22 -3
  148. package/dist/core/parts.mjs +5 -3
  149. package/dist/core/promise.mjs +23 -17
  150. package/dist/core/purge.d.mts +2 -2
  151. package/dist/core/purge.mjs +89 -34
  152. package/dist/core/push.mjs +67 -79
  153. package/dist/core/receipts.d.mts +2 -2
  154. package/dist/core/receipts.mjs +28 -4
  155. package/dist/core/ref-index-job.mjs +4 -4
  156. package/dist/core/ref-view.mjs +16 -8
  157. package/dist/core/refs.mjs +41 -10
  158. package/dist/core/registered-records.mjs +30 -0
  159. package/dist/core/{claim-rows.mjs → registered-rows.mjs} +6 -6
  160. package/dist/core/repack.d.mts +2 -2
  161. package/dist/core/repack.mjs +30 -23
  162. package/dist/core/repo-info.mjs +62 -26
  163. package/dist/core/repos.mjs +18 -11
  164. package/dist/core/rules/changes.mjs +2 -2
  165. package/dist/core/rules/check.mjs +10 -10
  166. package/dist/core/rules/commit-changes.mjs +1 -1
  167. package/dist/core/rules/context.d.mts +7 -6
  168. package/dist/core/rules/context.mjs +18 -16
  169. package/dist/core/rules/fetch.mjs +78 -31
  170. package/dist/core/saved-caller-views.d.mts +72 -0
  171. package/dist/core/saved-caller-views.mjs +123 -0
  172. package/dist/core/saved-callers-public.d.mts +5 -0
  173. package/dist/core/saved-callers-public.mjs +10 -0
  174. package/dist/core/saved-callers.mjs +95 -0
  175. package/dist/core/seam.d.mts +12 -1
  176. package/dist/core/seam.mjs +4 -2
  177. package/dist/core/tokens.mjs +7 -2
  178. package/dist/core/view.d.mts +1 -1
  179. package/dist/core/view.mjs +1 -1
  180. package/dist/core/work.mjs +6 -5
  181. package/dist/effect.d.mts +2 -4
  182. package/dist/effect.mjs +2 -4
  183. package/dist/engine/commits.mjs +19 -47
  184. package/dist/engine/content.d.mts +2 -2
  185. package/dist/engine/content.mjs +1 -1
  186. package/dist/engine/diff.mjs +2 -2
  187. package/dist/engine/failures.d.mts +1 -2
  188. package/dist/engine/failures.mjs +1 -3
  189. package/dist/engine/merge-base-walk.mjs +57 -142
  190. package/dist/engine/merge-bases.mjs +5 -5
  191. package/dist/engine/merge-renames.mjs +1 -1
  192. package/dist/engine/merge.mjs +16 -14
  193. package/dist/engine/reads.d.mts +2 -2
  194. package/dist/engine/reads.mjs +1 -1
  195. package/dist/engine/xdiff.d.mts +1 -1
  196. package/dist/engine/xdiff.mjs +2 -2
  197. package/dist/event-streams/event-streams.d.mts +6 -2
  198. package/dist/event-streams/event-streams.mjs +6 -2
  199. package/dist/event-streams/stream.mjs +5 -2
  200. package/dist/extend.d.mts +2 -3
  201. package/dist/extend.mjs +2 -2
  202. package/dist/http/answers.mjs +4 -3
  203. package/dist/http/core-parts.mjs +3 -4
  204. package/dist/http/handler.mjs +12 -32
  205. package/dist/http/parts.d.mts +1 -1
  206. package/dist/http/push-uploads.mjs +7 -5
  207. package/dist/http/receive-pack.mjs +3 -3
  208. package/dist/http/upload-pack.mjs +6 -5
  209. package/dist/index.d.mts +44 -24
  210. package/dist/index.mjs +17 -8
  211. package/dist/lfs/base.d.mts +8 -5
  212. package/dist/lfs/base.mjs +2 -1
  213. package/dist/lfs/calls.mjs +3 -2
  214. package/dist/lfs/layer.d.mts +9 -7
  215. package/dist/lfs/layer.mjs +37 -22
  216. package/dist/lfs/locks.mjs +3 -3
  217. package/dist/lfs/objects.d.mts +3 -2
  218. package/dist/lfs/objects.mjs +235 -71
  219. package/dist/lfs/pointers.mjs +70 -19
  220. package/dist/lfs/purge.mjs +7 -3
  221. package/dist/lfs/rows.mjs +25 -8
  222. package/dist/lfs/service.d.mts +6 -3
  223. package/dist/lfs/service.mjs +8 -2
  224. package/dist/lfs/upkeep.mjs +53 -31
  225. package/dist/lfs/upload-most.mjs +41 -0
  226. package/dist/lfs/uploaded.mjs +59 -0
  227. package/dist/lfs/wire.mjs +1 -1
  228. package/dist/protocol/bytes/buffers.d.mts +1 -1
  229. package/dist/protocol/bytes/buffers.mjs +1 -1
  230. package/dist/protocol/bytes/deflate.d.mts +1 -1
  231. package/dist/protocol/bytes/deflate.mjs +1 -1
  232. package/dist/protocol/bytes/hmac-sha256.mjs +3 -6
  233. package/dist/protocol/bytes/inflate.d.mts +1 -1
  234. package/dist/protocol/bytes/inflate.mjs +1 -1
  235. package/dist/protocol/bytes/sha1.d.mts +1 -1
  236. package/dist/protocol/bytes/sha1.mjs +2 -2
  237. package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
  238. package/dist/protocol/bytes/text.mjs +6 -1
  239. package/dist/protocol/diff/read.d.mts +1 -1
  240. package/dist/protocol/diff/read.mjs +1 -1
  241. package/dist/protocol/diff/tree-diff.d.mts +1 -1
  242. package/dist/protocol/diff/tree-diff.mjs +11 -11
  243. package/dist/protocol/objects/fsck.mjs +6 -3
  244. package/dist/protocol/objects/lfs-pointer.mjs +6 -1
  245. package/dist/protocol/objects/tag.mjs +1 -1
  246. package/dist/protocol/objects/tree.mjs +1 -1
  247. package/dist/protocol/packs/graph.mjs +1 -1
  248. package/dist/protocol/packs/idx.d.mts +1 -1
  249. package/dist/protocol/packs/idx.mjs +1 -1
  250. package/dist/protocol/packs/parts.mjs +1 -1
  251. package/dist/protocol/packs/reader.d.mts +1 -1
  252. package/dist/protocol/packs/reader.mjs +2 -2
  253. package/dist/protocol/packs/write-error.d.mts +1 -1
  254. package/dist/protocol/packs/write-error.mjs +1 -1
  255. package/dist/protocol/packs/writer.mjs +4 -4
  256. package/dist/protocol/wire/advertisement.d.mts +1 -1
  257. package/dist/protocol/wire/advertisement.mjs +1 -1
  258. package/dist/protocol/wire/fetch.d.mts +1 -1
  259. package/dist/protocol/wire/fetch.mjs +1 -1
  260. package/dist/protocol/wire/lines.d.mts +1 -1
  261. package/dist/protocol/wire/lines.mjs +2 -2
  262. package/dist/protocol/wire/push-uploads.mjs +4 -2
  263. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  264. package/dist/protocol/wire/receive-pack.mjs +1 -1
  265. package/dist/protocol/wire/report-status.d.mts +1 -1
  266. package/dist/protocol/wire/report-status.mjs +1 -1
  267. package/dist/protocol/wire/v2.d.mts +2 -2
  268. package/dist/protocol/wire/v2.mjs +2 -2
  269. package/dist/queue/advance.mjs +190 -68
  270. package/dist/queue/callers.mjs +56 -69
  271. package/dist/queue/calls.mjs +10 -11
  272. package/dist/queue/commit.mjs +28 -22
  273. package/dist/queue/host.d.mts +10 -11
  274. package/dist/queue/host.mjs +15 -7
  275. package/dist/queue/lanes.mjs +9 -18
  276. package/dist/queue/layer.d.mts +3 -3
  277. package/dist/queue/layer.mjs +11 -10
  278. package/dist/queue/limits.mjs +17 -5
  279. package/dist/queue/rows.mjs +13 -10
  280. package/dist/queue/schedule.mjs +7 -6
  281. package/dist/queue/search.mjs +11 -17
  282. package/dist/queue/state.mjs +7 -2
  283. package/dist/queue/trim.mjs +10 -5
  284. package/dist/rest/api.d.mts +1 -1
  285. package/dist/rest/blobs.d.mts +20 -20
  286. package/dist/rest/caller.d.mts +22 -20
  287. package/dist/rest/client-namespace.d.mts +2 -0
  288. package/dist/rest/client.d.mts +32 -8
  289. package/dist/rest/client.mjs +314 -388
  290. package/dist/rest/commits.d.mts +284 -284
  291. package/dist/rest/errors.d.mts +10 -10
  292. package/dist/rest/errors.mjs +1 -1
  293. package/dist/rest/events.d.mts +13 -11
  294. package/dist/rest/events.mjs +3 -1
  295. package/dist/rest/files.d.mts +48 -48
  296. package/dist/rest/forks.d.mts +131 -143
  297. package/dist/rest/handler.mjs +4 -3
  298. package/dist/rest/handlers.mjs +15 -8
  299. package/dist/rest/layer.d.mts +3 -3
  300. package/dist/rest/layer.mjs +8 -7
  301. package/dist/rest/listen.d.mts +8 -6
  302. package/dist/rest/listen.mjs +33 -77
  303. package/dist/rest/me.d.mts +18 -20
  304. package/dist/rest/me.mjs +1 -1
  305. package/dist/rest/merges.d.mts +17 -17
  306. package/dist/rest/queue.d.mts +140 -140
  307. package/dist/rest/queue.mjs +1 -1
  308. package/dist/rest/refs.d.mts +214 -214
  309. package/dist/rest/refs.mjs +1 -1
  310. package/dist/rest/repos.d.mts +123 -135
  311. package/dist/rest/tags.d.mts +30 -30
  312. package/dist/rest/tokens.d.mts +250 -260
  313. package/dist/rest/tokens.mjs +10 -42
  314. package/dist/rest/topics.d.mts +162 -162
  315. package/dist/rest/topics.mjs +1 -1
  316. package/dist/rest/trees.d.mts +117 -117
  317. package/dist/rest/wire.d.mts +7 -5
  318. package/dist/rest/wire.mjs +4 -3
  319. package/dist/rest/work.d.mts +69 -69
  320. package/dist/rest/work.mjs +1 -1
  321. package/dist/rest.d.mts +1 -7
  322. package/dist/rest.mjs +1 -5
  323. package/dist/server/check-fetch.mjs +9 -0
  324. package/dist/server/extension.mjs +3 -115
  325. package/dist/server/git-layer.d.mts +30 -5
  326. package/dist/server/git-layer.mjs +59 -29
  327. package/dist/server/git-namespace.d.mts +4 -4
  328. package/dist/server/git-namespace.mjs +6 -4
  329. package/dist/server/joined.d.mts +83 -0
  330. package/dist/server/joined.mjs +91 -0
  331. package/dist/server/registry.d.mts +7 -3
  332. package/dist/server/registry.mjs +135 -31
  333. package/dist/server/server.d.mts +9 -3
  334. package/dist/server/server.mjs +277 -208
  335. package/dist/signin/context.d.mts +2 -2
  336. package/dist/signin/context.mjs +28 -37
  337. package/dist/signin/device.mjs +5 -5
  338. package/dist/signin/forms.mjs +1 -1
  339. package/dist/signin/grants.d.mts +2 -3
  340. package/dist/signin/grants.mjs +5 -5
  341. package/dist/signin/layer.d.mts +9 -0
  342. package/dist/signin/layer.mjs +41 -0
  343. package/dist/signin/namespace.d.mts +2 -0
  344. package/dist/signin/public.d.mts +6 -0
  345. package/dist/signin/public.mjs +5 -0
  346. package/dist/signin/route.mjs +47 -21
  347. package/dist/signin/web.mjs +3 -3
  348. package/dist/signin/wire.mjs +1 -1
  349. package/dist/storage/calls.d.mts +1 -1
  350. package/dist/storage/calls.mjs +4 -4
  351. package/dist/storage/clean-up.mjs +15 -6
  352. package/dist/storage/counted-bucket.mjs +34 -51
  353. package/dist/storage/fetch.mjs +1 -1
  354. package/dist/storage/fsck.mjs +12 -2
  355. package/dist/storage/graph-rebuild.mjs +262 -0
  356. package/dist/storage/host-bucket.mjs +1 -1
  357. package/dist/storage/index-build.d.mts +2 -2
  358. package/dist/storage/index-build.mjs +103 -15
  359. package/dist/storage/index-fetch.mjs +10 -6
  360. package/dist/storage/index-graph.mjs +1 -1
  361. package/dist/storage/index-layers.mjs +1 -1
  362. package/dist/storage/index-visible.mjs +1 -1
  363. package/dist/storage/lfs-pointers.d.mts +5 -5
  364. package/dist/storage/lfs-pointers.mjs +37 -11
  365. package/dist/storage/loose.mjs +4 -1
  366. package/dist/storage/memory-budget.mjs +8 -2
  367. package/dist/storage/merge-cut.mjs +24 -1
  368. package/dist/storage/merge-fence.mjs +82 -20
  369. package/dist/storage/merge-most.mjs +1 -0
  370. package/dist/storage/merge-plan.mjs +5 -2
  371. package/dist/storage/merge-row.mjs +17 -5
  372. package/dist/storage/merge-stream.mjs +25 -13
  373. package/dist/storage/merge-write.mjs +1 -1
  374. package/dist/storage/merge.d.mts +2 -2
  375. package/dist/storage/merge.mjs +1 -1
  376. package/dist/storage/object-rows.d.mts +2 -2
  377. package/dist/storage/object-rows.mjs +20 -4
  378. package/dist/storage/pack-ranges.d.mts +3 -1
  379. package/dist/storage/pack-ranges.mjs +168 -69
  380. package/dist/storage/pack-reads.mjs +4 -4
  381. package/dist/storage/pack-receive.d.mts +1 -1
  382. package/dist/storage/pack-receive.mjs +17 -15
  383. package/dist/storage/packs.d.mts +1 -1
  384. package/dist/storage/packs.mjs +103 -79
  385. package/dist/storage/placed-reads.mjs +81 -15
  386. package/dist/storage/prune-seen.mjs +126 -0
  387. package/dist/storage/prune-walk.mjs +87 -99
  388. package/dist/storage/prune.mjs +113 -50
  389. package/dist/storage/push-uploads.mjs +4 -2
  390. package/dist/storage/quarantine.d.mts +2 -2
  391. package/dist/storage/ready.d.mts +2 -2
  392. package/dist/storage/ready.mjs +15 -6
  393. package/dist/storage/receive-files.mjs +1 -1
  394. package/dist/storage/receive-links.mjs +1 -1
  395. package/dist/storage/receive-state.d.mts +2 -2
  396. package/dist/storage/receive-state.mjs +2 -2
  397. package/dist/storage/receive-steps.mjs +1 -1
  398. package/dist/storage/repack-contained.mjs +24 -16
  399. package/dist/storage/repack-job.d.mts +2 -2
  400. package/dist/storage/repack-job.mjs +5 -4
  401. package/dist/storage/repack.d.mts +2 -2
  402. package/dist/storage/repack.mjs +12 -5
  403. package/dist/storage/rows.d.mts +2 -2
  404. package/dist/storage/rows.mjs +1 -1
  405. package/dist/storage/runs.d.mts +2 -2
  406. package/dist/storage/runs.mjs +15 -6
  407. package/dist/storage/send-list.mjs +6 -6
  408. package/dist/storage/single-flight.mjs +2 -2
  409. package/dist/storage/swap-walk.mjs +1 -1
  410. package/dist/storage/unpack.mjs +8 -1
  411. package/dist/store/call-count.d.mts +24 -4
  412. package/dist/store/call-count.mjs +158 -44
  413. package/dist/store/catalogue.d.mts +1 -1
  414. package/dist/store/catalogue.mjs +2 -2
  415. package/dist/store/crossing.mjs +2 -6
  416. package/dist/store/cursor-seal.mjs +1 -1
  417. package/dist/store/errors.d.mts +7 -3
  418. package/dist/store/errors.mjs +41 -13
  419. package/dist/store/job-try.mjs +119 -15
  420. package/dist/store/list-job.mjs +5 -5
  421. package/dist/store/outbox.d.mts +2 -2
  422. package/dist/store/outbox.mjs +75 -16
  423. package/dist/store/promises.d.mts +2 -2
  424. package/dist/store/promises.mjs +31 -6
  425. package/dist/store/queue-jobs.mjs +1 -1
  426. package/dist/store/records.d.mts +2 -2
  427. package/dist/store/records.mjs +22 -24
  428. package/dist/store/ref-rows.d.mts +2 -2
  429. package/dist/store/ref-rows.mjs +6 -6
  430. package/dist/store/repo-record.mjs +29 -12
  431. package/dist/store/reservations.mjs +35 -8
  432. package/dist/store/scopes.mjs +12 -5
  433. package/dist/store/topic-jobs.mjs +8 -8
  434. package/dist/sync/bound.d.mts +1 -3
  435. package/dist/sync/bound.mjs +30 -42
  436. package/dist/sync/github.d.mts +5 -6
  437. package/dist/sync/github.mjs +37 -42
  438. package/dist/sync/http.mjs +15 -0
  439. package/dist/sync/import.mjs +30 -19
  440. package/dist/sync/layer.d.mts +13 -0
  441. package/dist/sync/layer.mjs +73 -0
  442. package/dist/sync/mirror.mjs +137 -58
  443. package/dist/sync/publish.mjs +3 -6
  444. package/dist/sync/step.mjs +223 -85
  445. package/dist/sync/tries.mjs +22 -15
  446. package/dist/sync.d.mts +3 -6
  447. package/dist/sync.mjs +3 -6
  448. package/dist/topics/advance.mjs +210 -94
  449. package/dist/topics/calls.mjs +8 -8
  450. package/dist/topics/directory.mjs +35 -12
  451. package/dist/topics/host.d.mts +5 -8
  452. package/dist/topics/host.mjs +42 -19
  453. package/dist/topics/layer.d.mts +381 -0
  454. package/dist/topics/layer.mjs +62 -0
  455. package/dist/topics/members.mjs +39 -10
  456. package/dist/topics/namespace.d.mts +2 -0
  457. package/dist/topics/public.d.mts +6 -0
  458. package/dist/topics/public.mjs +13 -0
  459. package/dist/topics/rows.mjs +12 -3
  460. package/dist/topics/topic.mjs +11 -10
  461. package/package.json +8 -13
  462. package/dist/access.d.mts +0 -2
  463. package/dist/access.mjs +0 -1
  464. package/dist/core/hooks/post-receive.mjs +0 -216
  465. package/dist/core/hooks/pre-receive.d.mts +0 -12
  466. package/dist/core/hooks/pre-receive.mjs +0 -36
  467. package/dist/engine/merge-base-walk.d.mts +0 -3
  468. package/dist/server/extension.d.mts +0 -21
  469. package/dist/server/routes.d.mts +0 -32
  470. package/dist/server/routes.mjs +0 -69
  471. package/dist/sync/import.d.mts +0 -10
  472. package/dist/sync/jobs.d.mts +0 -9
  473. package/dist/sync/jobs.mjs +0 -75
  474. package/dist/sync/mirror.d.mts +0 -13
  475. package/dist/sync/publish.d.mts +0 -6
  476. /package/dist/core/{claim-rows.d.mts → registered-rows.d.mts} +0 -0
@@ -1,9 +1,13 @@
1
+ import "../contracts/ids.mjs";
1
2
  import { gitError, gitErrorFrom } from "../contracts/result.mjs";
3
+ import { partialImporter } from "./import.mjs";
2
4
  import { importedPullRefs } from "../contracts/sync.mjs";
3
5
  import { push } from "../core/push.mjs";
4
6
  import { refusedLead } from "../client/answer.mjs";
7
+ import { isRefName } from "../core/names.mjs";
8
+ import { cutWords, utf8 } from "../protocol/bytes/text.mjs";
5
9
  import { negotiate } from "../client/negotiate.mjs";
6
- import { discover, fetchTerms, remoteRefsOf } from "../client/remote.mjs";
10
+ import { discover, fetchTerms, remoteRefsAndHeadOf } from "../client/remote.mjs";
7
11
  import { objectsFace, oneShotReads, scopedReceiveStep } from "../storage/calls.mjs";
8
12
  import { isPackId } from "../storage/layout.mjs";
9
13
  import { receiveCutParentsMost } from "../storage/receive-bounds.mjs";
@@ -12,41 +16,60 @@ import { decodeHeld } from "../storage/rows.mjs";
12
16
  import { infiniteDepth } from "../storage/shallow.mjs";
13
17
  import { decodeRow, storeCall } from "../store/errors.mjs";
14
18
  import { gitStore } from "../store/git-store.mjs";
15
- import { jobRepo, newChangeId, repoScope } from "../store/scopes.mjs";
19
+ import { decodeRecord, hostRecordOf } from "../store/catalogue.mjs";
20
+ import { listJobRow } from "../store/list-job.mjs";
21
+ import { StoredRepo } from "../store/records.mjs";
22
+ import { newChangeId, repoScope, selfKey } from "../store/scopes.mjs";
16
23
  import { asSync } from "./bound.mjs";
17
- import { ImportRow, cancelKey, cutKey, cutRow, failedHint, failedRow, importEndDeletes, importKey, importRow, readImport, stoppedTry } from "../core/imports.mjs";
18
- import { ForGood, SyncTryError, forGood, fromRemote, httpOf, openedFor, remoteOf, runTry, syncObjects, thrownOf } from "./tries.mjs";
19
- import { runIn, uncounted } from "../store/crossing.mjs";
24
+ import { ImportRow, cancelKey, cutKey, cutRow, failedHint, failedRow, importEndDeletes, importKey, importRow, readImport, readTipPages, stoppedTry, tipPageKey, tipPageRow, tipPagesOf, tipRowBytes } from "../core/imports.mjs";
25
+ import { ForGood, SyncTryError, forGood, fromRemote, httpOf, openedFor, remoteOf, syncObjects, thrownOf, tried } from "./tries.mjs";
26
+ import { currentRepo } from "../store/job-try.mjs";
20
27
  import { CoreParts, ObjectsParts, overStore } from "../core/parts.mjs";
21
28
  import { importOwner } from "../protocol/wire/lines.mjs";
29
+ import { repoAccess } from "../core/access.mjs";
30
+ import { viewAgainOf } from "../core/saved-caller-views.mjs";
22
31
  import * as Effect from "effect/Effect";
32
+ import * as Schema from "effect/Schema";
23
33
  import * as Result from "effect/Result";
34
+ import { CurrentJob } from "@ref0/infra";
24
35
  // src/sync/step.ts
25
36
  /**
26
- * One try of `git.sync.import`: one step of the import, committed with its record, so a try after
37
+ * One try of `sync.import`: one step of the import, committed with its record, so a try after
27
38
  * a crash goes on from the last step that landed. The steps, in order:
28
- * 1. list the remote's branches and tags, and keep their tips, with as many pull requests' heads,
29
- * newest first, as fit in the room they leave under the limits, each under `importedPullRefs`;
39
+ * 1. list the remote's branches and tags, and keep their tips in pages beside the record, with as
40
+ * many pull requests' heads, newest first, as fit in the bytes they leave under the limits,
41
+ * each under `importedPullRefs`;
30
42
  * 2. fetch the history behind them a segment at a time, each deeper than the last, as
31
43
  * `git fetch --deepen` does, and receive it as a push of objects alone: a segment whose pack
32
44
  * runs past the limit, or that the storage refuses for a reason in `halvedReasons`, is fetched
33
45
  * again at half the depth, and one holding an object the storage refuses as `object-too-large`
34
46
  * fails the job on that try, with that refusal;
35
- * 3. publish: move each ref to its tip, in one atomic commit, `source: 'import'`, then mark the
36
- * import done.
47
+ * 3. publish: move each page's refs to their tips, a page a try, each in one atomic commit,
48
+ * `source: 'import'`, that moves the record's cursor past it, and mark the import done with
49
+ * the last.
37
50
  * A step reads the import's record first, and ends the job for a cancelled import or one that
38
- * isn't running. The provider makes the remote's credentials afresh for every try.
51
+ * isn't running. Then it asks who started the import again, as `viewAgainOf` asks, and fails the
52
+ * import for good once they may no longer fetch the repo; only after that does it decide as host
53
+ * code does, `asSync`. The provider makes the remote's credentials afresh for every try.
39
54
  */
40
55
  /** The deepest a segment's step grows: past it, a segment's history is whole anyway. */
41
56
  const stepMost = 1 << 20;
42
57
  const shallowRemote = () => gitError("FAILED_PRECONDITION", "The remote is a shallow clone, without its oldest parents", { hint: "Import from a full clone, or run `git fetch --unshallow` in the remote first" });
43
- const tooManyTips = (limits, count) => gitError("RESOURCE_EXHAUSTED", `The remote has ${count} branches and tags`, {
44
- hint: `An import takes at most ${limits.tips} branches and tags, and ${limits.tipNameBytes} bytes of their names`,
58
+ const tooManyTips = (limits, bytes) => gitError("RESOURCE_EXHAUSTED", `The remote's branches and tags take ${bytes} bytes as refs`, {
59
+ hint: `An import takes branches and tags of at most ${limits.tipBytes} bytes together, as a repo's refs count them`,
45
60
  context: {
46
61
  reason: "too-large",
47
- limit: limits.tips
62
+ limit: limits.tipBytes
48
63
  }
49
64
  });
65
+ /** A listed branch or tag `isRefName` refuses, which no push could publish: by its length, or not. */
66
+ const unnamedTip = (ref) => utf8(ref).length > 768 ? gitError("RESOURCE_EXHAUSTED", `A branch or tag on the remote has a name over 768 bytes`, {
67
+ hint: "Rename it on the remote, then import again",
68
+ context: {
69
+ reason: "too-large",
70
+ limit: 768
71
+ }
72
+ }) : gitError("FAILED_PRECONDITION", "A branch or tag on the remote has a name Git doesn't take", { hint: "Rename it on the remote, then import again" });
50
73
  /** Why a segment can't be made smaller: it's one commit, or the remote takes no deepen. */
51
74
  const leastHint = (shallow) => shallow ? "A segment of one commit is the least an import fetches" : "The remote takes no shallow fetch, so an import fetches its history in one segment";
52
75
  const overBudget = (most) => gitError("RESOURCE_EXHAUSTED", `One commit's history alone is over ${most} bytes`, {
@@ -102,10 +125,13 @@ const finalRefusal = (failure) => {
102
125
  if (failure.code === "RESOURCE_EXHAUSTED" && failure.context?.reason === "object-too-large") return failure;
103
126
  if (failure.code !== "INVALID_ARGUMENT") return void 0;
104
127
  const { context } = failure;
105
- if (context?.reason === "fsck") return gitErrorFrom(failure, {
106
- message: `An object of the import fails Git's ${context.msgId} check`,
107
- hint: `An object in the source's history fails Git's checks (${context.msgId}), so this repo can't be imported as it is. Delete this repo to clear it.`
108
- });
128
+ if (context?.reason === "fsck") {
129
+ const named = context.msgId === "duplicateEntries";
130
+ return gitErrorFrom(failure, {
131
+ message: named ? failure.message : `An object of the import fails Git's ${context.msgId} check`,
132
+ hint: `An object in the source's history fails Git's checks (${context.msgId}), so this repo can't be imported as it is. Delete this repo to clear it.`
133
+ });
134
+ }
109
135
  if (context?.reason === "ofs-delta") return gitErrorFrom(failure, { hint: "The remote sent OFS_DELTA entries without being asked, so this repo can't be imported from that remote. Delete this repo to clear it." });
110
136
  if (finalReasons.has(context?.reason)) return failure;
111
137
  };
@@ -116,11 +142,6 @@ const refusedWordsMost = 512;
116
142
  * bytes as UTF-8, well under a record's 1 MiB, so no refusal's words keep a record from failing.
117
143
  */
118
144
  const failedMessageMost = 1024;
119
- /** `text`'s first `most` UTF-16 units, the first half of a surrogate pair the cut splits dropped. */
120
- const cutWords = (text, most) => {
121
- const cut = text.slice(0, most);
122
- return /[\uD800-\uDBFF]$/u.test(cut) ? cut.slice(0, -1) : cut;
123
- };
124
145
  /**
125
146
  * Whether a remote's words may be shown: the import reached `remote` through the platform's own
126
147
  * `fetch` with no credential, its own or in its URL. A remote's words may echo a credential, and a
@@ -153,7 +174,7 @@ const remoteRefused = (remote, message) => {
153
174
  */
154
175
  const advertisedFrom = (remote, call) => (error) => error.code === "FAILED_PRECONDITION" && error.context?.reason === "remote-refused" ? new ForGood({ error: remoteRefused(remote, error.message) }) : fromRemote(call)(error);
155
176
  /** `context.progress`, which a claim taken again refuses: the sample's dropped, and the try goes on. */
156
- const report = (context, phase, row) => Effect.promise(() => context.progress({
177
+ const report = (context, phase, row) => context.progress({
157
178
  phase,
158
179
  measures: [{
159
180
  unit: "objects",
@@ -162,7 +183,7 @@ const report = (context, phase, row) => Effect.promise(() => context.progress({
162
183
  unit: "bytes",
163
184
  completed: row.bytes
164
185
  }]
165
- }).catch(() => void 0));
186
+ });
166
187
  /** The repo as this try opens it: `undefined` once it's gone. */
167
188
  const openedRepo = (attempt) => openedFor(attempt.bound.caller, attempt.internalId);
168
189
  /** The import's record, read through this try's store. */
@@ -171,51 +192,58 @@ const readOwn = (attempt) => Effect.flatMap(Effect.service(CoreParts), ({ store
171
192
  * The import's record at `row`, committed at `version` with `deletes`: a commit another beat is read
172
193
  * next try.
173
194
  */
174
- const saved = (attempt, version, row, deletes = []) => Effect.flatMap(Effect.service(CoreParts), ({ store }) => storeCall(() => store.commit(repoScope(attempt.internalId), {
195
+ const saved = (attempt, version, row, deletes = [], puts = []) => Effect.flatMap(Effect.service(CoreParts), ({ store }) => storeCall(() => store.commit(repoScope(attempt.internalId), {
175
196
  id: newChangeId(),
176
197
  expect: version,
177
- put: [importRow(row)],
198
+ put: [importRow(row), ...puts],
178
199
  delete: deletes
179
200
  })));
180
201
  const more = { kind: "more" };
181
202
  const endedUnder = () => gitError("FAILED_PRECONDITION", "The import ended while its step ran", { hint: "Its record is no longer running, so the step writes nothing" });
203
+ /** The import's record as a guard's read finds it, failing `endedUnder` unless it's running. */
204
+ const runningIn = /* @__PURE__ */ Effect.fnUntraced(function* (rows) {
205
+ const [own] = rows ?? [];
206
+ const row = own === void 0 ? void 0 : yield* decodeRow(ImportRow, own, "Import");
207
+ if (row?.state !== "running") return yield* Effect.fail(endedUnder());
208
+ return row;
209
+ });
182
210
  /**
183
211
  * A step's push guard: the import's record still `running` in the push's own read, so a step whose
184
212
  * import another write ended since, such as the core's `failed` for a job gone, writes nothing.
185
213
  */
186
214
  const stillRunning = {
187
215
  reads: [importKey],
188
- check: /* @__PURE__ */ Effect.fnUntraced(function* (results) {
189
- const [own] = results[0] ?? [];
190
- if ((own === void 0 ? void 0 : yield* decodeRow(ImportRow, own, "Import"))?.state !== "running") return yield* Effect.fail(endedUnder());
191
- })
216
+ check: (results) => Effect.asVoid(runningIn(results[0]))
192
217
  };
193
- const cancelledUnder = () => gitError("FAILED_PRECONDITION", "The import was cancelled while it published", { hint: "It moves no ref, and answers as cancelled" });
218
+ const cancelledUnder = () => gitError("FAILED_PRECONDITION", "The import was cancelled while it published", { hint: "It moves no more refs, and answers as cancelled" });
219
+ const pageMovedUnder = () => gitError("UNAVAILABLE", "Another try moved the import's publish past this page first", { hint: "The job tries again, from the page its record names then" });
194
220
  /**
195
- * Publish's push guard: `stillRunning`, and no cancel saved beside the record, so a cancel saved
196
- * since the try read the import moves no ref, and `import` answers `import-cancelled`. A landing
221
+ * Publish's push guard for `page`: `stillRunning`, the record's cursor still at `page`, and no
222
+ * cancel saved beside the record. So a try that read the record before another's page landed
223
+ * never moves the cursor back, and a cancel saved since the try read the import moves no more
224
+ * refs, the pages published before it staying, and `import` answers `import-cancelled`. A landing
197
225
  * keeps `stillRunning` alone: a segment in flight as a cancel commits still lands, and its objects
198
226
  * stay readable, as `CancelImport` says.
199
227
  */
200
- const uncancelled = {
228
+ const uncancelled = (page) => ({
201
229
  reads: [...stillRunning.reads, cancelKey],
202
230
  check: /* @__PURE__ */ Effect.fnUntraced(function* (results) {
203
- yield* stillRunning.check(results.slice(0, 1));
231
+ if (((yield* runningIn(results[0])).publishedPages ?? 0) !== page) return yield* Effect.fail(pageMovedUnder());
204
232
  const [cancel] = results[1] ?? [];
205
233
  if (cancel !== void 0) return yield* Effect.fail(cancelledUnder());
206
234
  })
207
- };
235
+ });
208
236
  /** A pull request's head as the remote names it, `refs/pull/N/head`: its number, or `undefined`. */
209
237
  const pullHead = (ref) => {
210
238
  const number = /^refs\/pull\/([1-9][0-9]*)\/head$/.exec(ref)?.[1];
211
239
  return number === void 0 ? void 0 : Number(number);
212
240
  };
213
241
  /**
214
- * The pull requests' heads that fit in what `own`, the branches and tags, leave of the limits,
215
- * newest first, each under `importedPullRefs`. The rest aren't fetched: their pulls import with no
216
- * head.
242
+ * The pull requests' heads that fit in the bytes `own`, the branches' and tags' rows, leave of
243
+ * `tipBytes`, newest first, each under `importedPullRefs`. The rest aren't fetched: their pulls
244
+ * import with no head.
217
245
  */
218
- const pullTips = (refs, own, names, limits) => {
246
+ const pullTips = (refs, own, limits) => {
219
247
  const heads = [...refs].flatMap(([ref, oid]) => {
220
248
  const number = pullHead(ref);
221
249
  return number === void 0 ? [] : [{
@@ -224,39 +252,50 @@ const pullTips = (refs, own, names, limits) => {
224
252
  }];
225
253
  });
226
254
  const kept = [];
227
- let bytes = names;
255
+ let bytes = own;
228
256
  for (const { number, oid } of heads.sort((a, b) => b.number - a.number)) {
229
257
  const ref = `${importedPullRefs}${number}/head`;
230
- if (own + kept.length >= limits.tips || bytes + ref.length > limits.tipNameBytes) break;
231
- bytes += ref.length;
258
+ const size = tipRowBytes(ref, oid);
259
+ if (bytes + size > limits.tipBytes) break;
260
+ bytes += size;
232
261
  kept.push([ref, oid]);
233
262
  }
234
263
  return kept;
235
264
  };
236
265
  /**
237
- * Step 1: the remote's branches and tags, and their tips, kept in the import's record, with the
238
- * pull requests' heads that fit beside them.
266
+ * Step 1: the remote's branches and tags, and their tips, kept in pages beside the import's
267
+ * record, with the pull requests' heads that fit beside them, in the commit that moves the record
268
+ * past the listing.
239
269
  */
240
270
  const listTips = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version, row, remote) {
241
271
  yield* report(attempt.context, "fetch", row);
242
- const http = httpOf(remote);
243
- const listed = Effect.flatMap(discover(http), (upload) => remoteRefsOf(http, upload, [
272
+ const http = yield* httpOf(remote);
273
+ const listed = Effect.flatMap(discover(http), (upload) => remoteRefsAndHeadOf(http, upload, [
244
274
  "refs/heads/",
245
275
  "refs/tags/",
246
276
  "refs/pull/"
247
277
  ]));
248
- const listing = yield* Effect.mapError(listed, advertisedFrom(remote, "list its branches and tags"));
278
+ const { refs: listing, head } = yield* Effect.mapError(listed, advertisedFrom(remote, "list its branches and tags"));
249
279
  const refs = new Map([...listing].filter(([ref]) => !ref.startsWith("refs/pull/")));
250
- const names = [...refs.keys()].reduce((bytes, ref) => bytes + ref.length, 0);
280
+ const unnamed = [...refs.keys()].find((ref) => !isRefName(ref));
281
+ if (unnamed !== void 0) return yield* forGood(unnamedTip(unnamed));
282
+ const own = [...refs].reduce((bytes, [ref, oid]) => bytes + tipRowBytes(ref, oid), 0);
251
283
  const { limits } = attempt.bound;
252
- if (refs.size > limits.tips || names > limits.tipNameBytes) return yield* forGood(tooManyTips(limits, refs.size));
253
- const all = [...refs, ...pullTips(listing, refs.size, names, limits)];
254
- const tips = Object.fromEntries(all.sort(([a], [b]) => a < b ? -1 : 1));
255
- yield* saved(attempt, version, {
284
+ if (own > limits.tipBytes) return yield* forGood(tooManyTips(limits, own));
285
+ const all = [...refs, ...pullTips(listing, own, limits)];
286
+ const adopts = head?.startsWith("refs/heads/") === true && refs.has(head) ? head : void 0;
287
+ const pages = tipPagesOf(all.sort(([a], [b]) => a < b ? -1 : 1), adopts, {
288
+ bytes: limits.tipPageBytes,
289
+ most: limits.publishBatch
290
+ });
291
+ const listedRow = {
256
292
  ...row,
257
- tips,
293
+ tipPages: pages.length,
294
+ publishedPages: 0,
258
295
  copied: all.length === 0
259
- });
296
+ };
297
+ if (adopts !== void 0) listedRow.head = adopts;
298
+ yield* saved(attempt, version, listedRow, [], pages.map((tips, page) => tipPageRow(page, tips)));
260
299
  return more;
261
300
  });
262
301
  /**
@@ -340,12 +379,14 @@ const stepAfter = (step, bytes, most) => bytes < most / 4 ? Math.min(step * 2, s
340
379
  const fetchSegment = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row, cut, remote) {
341
380
  const { bound, context } = attempt;
342
381
  const most = bound.limits.packBytes;
343
- const tips = [...new Set(Object.values(row.tips ?? {}))];
382
+ const { store } = yield* CoreParts;
383
+ const listed = yield* readTipPages(store, attempt.internalId, 0, row.tipPages ?? 0);
384
+ const tips = [...new Set(listed.flatMap((page) => Object.values(page)))];
344
385
  const opened = yield* openedRepo(attempt);
345
386
  if (opened === void 0) return void 0;
346
387
  const objects = objectsFace(syncObjects(yield* ObjectsParts));
347
388
  yield* report(context, "fetch", row);
348
- const http = httpOf(remote);
389
+ const http = yield* httpOf(remote);
349
390
  const upload = yield* Effect.mapError(discover(http), advertisedFrom(remote, "advertise its refs"));
350
391
  const shallow = yield* deepens(upload);
351
392
  const wanted = row.deepest + row.step;
@@ -371,6 +412,13 @@ const fetchSegment = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row,
371
412
  const { pack } = negotiated;
372
413
  const { stream, seen } = counted(pack.bytes, most);
373
414
  const roots = shallow ? rootsAfter(row.roots, negotiated) : [];
415
+ if (roots.length > bound.limits.rootsMost) {
416
+ pack.cancel();
417
+ return yield* forGood(gitError("RESOURCE_EXHAUSTED", `An import takes at most ${bound.limits.rootsMost} shallow roots`, { context: {
418
+ reason: "too-large",
419
+ limit: bound.limits.rootsMost
420
+ } }));
421
+ }
374
422
  if (roots.length > 0 && row.roots.length > 0 && sameRoots(roots, row.roots)) {
375
423
  pack.cancel();
376
424
  return yield* forGood(shallowRemote());
@@ -593,18 +641,63 @@ const unstaged = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row, next
593
641
  return more;
594
642
  });
595
643
  const movedUnder = (ref) => gitError("UNAVAILABLE", `Another write moved '${ref}' while the import published it`, { hint: "The job tries again, from the refs as they are then" });
644
+ const recordMovedUnder = () => gitError("UNAVAILABLE", "Another write changed the repo's record while the import published", { hint: "The job tries again, from the record as it is then" });
596
645
  /**
597
- * Step 3: each ref moved to its tip and the import marked done, in one atomic commit. A ref another
598
- * write moved first fails the try, and the next moves every ref from where it is then; a refusal
599
- * of another kind fails it with that ref's own error.
646
+ * The repo's record as the try read it, and the remote's default branch, `head`, as the import
647
+ * listed it, to adopt: `undefined` when it listed none, the record names it already, or a private
648
+ * pattern matches it, which `repos.update` refuses for a default, so the repo keeps its own.
649
+ */
650
+ const adopted = /* @__PURE__ */ Effect.fnUntraced(function* (record, head) {
651
+ const { access } = yield* CoreParts;
652
+ if (head === void 0 || head === record.defaultBranch) return void 0;
653
+ if (access?.patternOf(head) !== void 0) return void 0;
654
+ return {
655
+ read: record,
656
+ head
657
+ };
658
+ });
659
+ const sameRecord = /* @__PURE__ */ Schema.toEquivalence(StoredRepo);
660
+ /**
661
+ * Publish's guard for `page`, `uncancelled(page)`, and, once it adopts a default branch, the repo's
662
+ * record as the try read it, so the record `also` puts never writes over another write's.
663
+ */
664
+ const publishGuard = (read, page) => {
665
+ if (read === void 0) return uncancelled(page);
666
+ const { reads } = uncancelled(page);
667
+ const own = reads.length;
668
+ return {
669
+ reads: [...reads, selfKey],
670
+ check: /* @__PURE__ */ Effect.fnUntraced(function* (results) {
671
+ yield* uncancelled(page).check(results.slice(0, own));
672
+ const now = yield* decodeRecord(results[own]?.[0]);
673
+ if (now === void 0 || !sameRecord(now, read)) return yield* Effect.fail(recordMovedUnder());
674
+ })
675
+ };
676
+ };
677
+ /**
678
+ * Step 3: the next page's refs moved to their tips, in one atomic commit that moves the record's
679
+ * cursor past the page and deletes it. The last page's marks the import done instead, with the
680
+ * remote's default branch made the repo's when it's one of the tips, which the listing put on that
681
+ * page. A ref another write moved first fails the try, and the next moves the page's refs from
682
+ * where they are then; a refusal of another kind fails it with that ref's own error.
600
683
  */
601
684
  const publish = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row) {
602
685
  const opened = yield* openedRepo(attempt);
603
686
  if (opened === void 0) return void 0;
687
+ const { store } = yield* CoreParts;
688
+ const page = row.publishedPages ?? 0;
689
+ const pages = row.tipPages ?? 0;
690
+ const last = page + 1 >= pages;
691
+ const [tips = {}] = yield* readTipPages(store, attempt.internalId, page, Math.min(page + 1, pages));
692
+ const next = {
693
+ ...row,
694
+ publishedPages: Math.min(page + 1, pages)
695
+ };
604
696
  yield* report(attempt.context, "publish", row);
605
- const edits = Object.entries(row.tips ?? {}).flatMap(([ref, to]) => {
697
+ const adopting = last ? yield* adopted(opened.record, row.head) : void 0;
698
+ const edits = Object.entries(tips).flatMap(([ref, to]) => {
606
699
  const from = opened.refs.get(ref) ?? null;
607
- return from === to ? [] : [{
700
+ return from === to && ref !== adopting?.head ? [] : [{
608
701
  ref,
609
702
  from,
610
703
  to
@@ -618,18 +711,36 @@ const publish = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row) {
618
711
  as: importOwner,
619
712
  edits,
620
713
  atomic: true,
621
- also: () => ({
622
- put: [importRow({
623
- ...row,
714
+ also: (at) => {
715
+ const cursor = importRow(last ? {
716
+ ...next,
624
717
  state: "done"
625
- })],
626
- delete: importEndDeletes(row),
627
- jobs: []
628
- }),
629
- guard: uncancelled
718
+ } : next);
719
+ const deletes = last ? importEndDeletes(row) : [tipPageKey(page)];
720
+ if (adopting === void 0) return {
721
+ put: [cursor],
722
+ delete: deletes,
723
+ jobs: []
724
+ };
725
+ const { read, head } = adopting;
726
+ const record = {
727
+ ...read,
728
+ defaultBranch: head,
729
+ changedAt: at
730
+ };
731
+ return {
732
+ put: [cursor, {
733
+ ...selfKey,
734
+ value: record
735
+ }],
736
+ delete: deletes,
737
+ jobs: [listJobRow()]
738
+ };
739
+ },
740
+ guard: publishGuard(adopting?.read, page)
630
741
  })).updates.flatMap((update) => update.kind === "rejected" ? [update] : []);
631
742
  const [first] = rejected;
632
- if (first === void 0) return void 0;
743
+ if (first === void 0) return last ? void 0 : more;
633
744
  const now = (yield* openedRepo(attempt))?.refs;
634
745
  const moved = edits.find((edit) => (now?.get(edit.ref) ?? null) !== edit.from);
635
746
  if (moved !== void 0) return yield* Effect.fail(movedUnder(moved.ref));
@@ -638,10 +749,10 @@ const publish = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row) {
638
749
  });
639
750
  /** One try's step, as the import's record says it's next. */
640
751
  const stepIn = /* @__PURE__ */ Effect.fnUntraced(function* (attempt) {
752
+ const { store } = yield* CoreParts;
641
753
  const read = yield* readOwn(attempt);
642
754
  const { row } = read;
643
755
  if (read.cancelled && (Object.keys(read.cut).length > 0 || row?.receiving !== void 0)) {
644
- const { store } = yield* CoreParts;
645
756
  if (!(yield* storeCall(() => store.commit(repoScope(attempt.internalId), {
646
757
  id: newChangeId(),
647
758
  expect: read.version,
@@ -649,35 +760,62 @@ const stepIn = /* @__PURE__ */ Effect.fnUntraced(function* (attempt) {
649
760
  }))).ok) return yield* Effect.fail(cutRaced());
650
761
  }
651
762
  if (row === void 0 || read.cancelled || row.state !== "running") return void 0;
763
+ const viewed = yield* importerView(attempt, row.by);
764
+ if (viewed === void 0) return void 0;
765
+ if (viewed.kind === "refused") return yield* forGood(viewed.error);
766
+ if (!viewed.view.whole) return yield* forGood(partialImporter());
767
+ return yield* asSync(stepAs(attempt, read, row));
768
+ });
769
+ /** The step the record says is next, once who started the import is asked again. */
770
+ const stepAs = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, read, row) {
652
771
  if (row.receiving !== void 0) return yield* resumed(attempt, row, row.receiving, read.cut);
653
772
  if (row.copied) return yield* publish(attempt, row);
654
- const remote = yield* remoteOf(attempt.bound, row.source, attempt.context.signal);
655
- if (row.tips === void 0) return yield* listTips(attempt, read.version, row, remote);
773
+ const remote = yield* remoteOf(attempt.bound, row.source, attempt.context.signal, "read");
774
+ if (row.tipPages === void 0) return yield* listTips(attempt, read.version, row, remote);
656
775
  return yield* fetchSegment(attempt, row, read.cut, remote);
657
776
  });
658
777
  /**
778
+ * Who started the import, asked again as they are now, as `viewAgainOf` asks: their view of the
779
+ * repo for a fetch, under its current name and visibility, or why they no longer hold there. So a
780
+ * right lost since fails the import for good, with the words their own fetch would get, before a
781
+ * step fetches or publishes anything. `undefined` for a repo gone since. A host that failed fails
782
+ * the try.
783
+ */
784
+ const importerView = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, by) {
785
+ const { internalId, context } = attempt;
786
+ const record = yield* hostRecordOf((yield* CoreParts).store, internalId);
787
+ if (record === void 0) return void 0;
788
+ const repo = repoAccess({
789
+ name: record.name,
790
+ record,
791
+ internalId
792
+ });
793
+ return yield* viewAgainOf(by, repo, "fetch", context.signal);
794
+ });
795
+ /**
659
796
  * `stepIn`, with the record read again after a step that failed: once another write ended the
660
797
  * import, the step ends with it, having written nothing, rather than count a try.
661
798
  */
662
799
  const stepOf = (attempt) => Effect.catch(stepIn(attempt), (error) => Effect.flatMap(readOwn(attempt), ({ row }) => row === void 0 || row.state === "running" ? Effect.fail(error) : Effect.void));
663
- /** `git.sync.import`'s handler over `bound`: a try's failure thrown as `SyncTryError`. */
664
- const importTry = (bound) => (job, context) => {
800
+ /** `sync.import`'s handler over `bound`: a try's failure thrown as `SyncTryError`. */
801
+ const importTry = /* @__PURE__ */ Effect.fnUntraced(function* (bound) {
802
+ const context = yield* CurrentJob.CurrentJob;
665
803
  const attempt = {
666
804
  bound,
667
- internalId: jobRepo(job),
805
+ internalId: yield* currentRepo,
668
806
  context
669
807
  };
670
- const step = asSync(overStore(context.store)(stepOf(attempt)));
671
- return runTry(Effect.provideContext(step, bound.needs), context.signal);
672
- };
808
+ return yield* tried(Effect.provideContext(overStore(context.store)(stepOf(attempt)), bound.needs));
809
+ });
673
810
  /**
674
811
  * The import's record marked failed with the last try's error, once the job is failed: read again
675
812
  * after a commit another write beat, until the queue's bound on `onFailure` aborts the signal. A
676
813
  * cancelled import keeps its record as the cancel left it, which reads as `cancelled`, even when
677
814
  * the cancel is what failed the last try: only the keys its run kept go.
678
815
  */
679
- const importFailed = async (job, { error }, context) => {
680
- const internalId = jobRepo(job);
816
+ const importFailed = /* @__PURE__ */ Effect.fnUntraced(function* (bound, { error }) {
817
+ const context = yield* CurrentJob.CurrentJob;
818
+ const internalId = yield* currentRepo;
681
819
  const passing = error instanceof SyncTryError && !error.permanent;
682
820
  const last = error instanceof SyncTryError ? error.kept : stoppedTry;
683
821
  const cut = {
@@ -701,6 +839,6 @@ const importFailed = async (job, { error }, context) => {
701
839
  }))).ok) return;
702
840
  }
703
841
  });
704
- await runIn(marked.pipe(Effect.mapError(thrownOf)), uncounted("a sync job's step: no request's, so only the platform's cap bounds it"), context.signal);
705
- };
842
+ yield* Effect.provideContext(marked, bound.needs).pipe(Effect.mapError(thrownOf));
843
+ });
706
844
  export { advertisedFrom, importFailed, importTry };
@@ -1,3 +1,4 @@
1
+ import { runnerIn } from "../store/crossing.mjs";
1
2
  import { gitError, gitErrorFrom, isGitError } from "../contracts/result.mjs";
2
3
  import { openRepo } from "../core/access.mjs";
3
4
  import { CoreParts } from "../core/parts.mjs";
@@ -9,13 +10,18 @@ import { answerSpent } from "../store/errors.mjs";
9
10
  import { decodePacks } from "../store/git-store.mjs";
10
11
  import { WholeRepo, wholeRefs } from "../store/ref-rows.mjs";
11
12
  import { collections } from "../store/scopes.mjs";
12
- import { runIn, uncounted } from "../store/crossing.mjs";
13
+ import { responseToWeb } from "./http.mjs";
13
14
  import { callLimitIn, spentRefusalOf, tryUnlessSpent } from "../contracts/calls-spent.mjs";
14
- import * as Schema from "effect/Schema";
15
15
  import * as Effect from "effect/Effect";
16
+ import * as HttpClient from "effect/http/HttpClient";
17
+ import * as Schema from "effect/Schema";
16
18
  import * as Predicate from "effect/Predicate";
19
+ import * as HttpClientRequest from "effect/http/HttpClientRequest";
17
20
  // src/sync/tries.ts
18
- /** A sync mirrors every ref of the repo it keeps, private or not: it reads the repo whole. */
21
+ /**
22
+ * A sync reads the repo whole: an import writes every ref it fetches, and a mirror reads its ref's
23
+ * tip only once the caller who saved it, asked again, still sees the ref.
24
+ */
19
25
  const syncWhole = /* @__PURE__ */ WholeRepo.mint();
20
26
  /** The server's objects, every one, as a sync reads them. */
21
27
  const syncObjects = (parts) => SealedObjects.whole(parts.objects, syncWhole);
@@ -48,8 +54,8 @@ const syncTryError = (error, permanent) => new SyncTryError({
48
54
  const thrownOf = (error) => Predicate.isTagged(error, "ForGood") ? syncTryError(error.error, true) : syncTryError(error, false);
49
55
  /** A defect's failure, such as a credentials function that threw: its message may hold a secret. */
50
56
  const defected = syncTryError(gitError("INTERNAL", "The try failed with an error sync keeps no text of", { hint: "The job tries again" }), false);
51
- /** One try of a sync job, its failure thrown as a `SyncTryError` that names no secret. */
52
- const runTry = (effect, signal) => runIn(effect.pipe(answerSpent, Effect.mapError(thrownOf), Effect.catchDefect(() => Effect.fail(defected))), uncounted("a sync job's try: no request's, so only the platform's cap bounds it"), signal);
57
+ /** A try's failure kept without credentials; spent bounds are answered at this job edge. */
58
+ const tried = (effect) => effect.pipe(answerSpent, Effect.mapError(thrownOf), Effect.catchDefect(() => Effect.fail(defected)));
53
59
  /**
54
60
  * Retries for a try that failed: none for one `SyncTryError` calls permanent, nor for a second try
55
61
  * the platform's call cap stopped, which would stop there on every try (#1084); else backing off.
@@ -59,9 +65,9 @@ const syncRetry = ({ attempt, error }) => {
59
65
  if (attempt >= 20) return false;
60
66
  return Math.min(1e3 * 2 ** (attempt - 1), 6e5);
61
67
  };
62
- /** A source naming a provider `syncJobs` wasn't given: refused as it's asked for. */
68
+ /** A source naming a provider `Sync.layer` wasn't given: refused as it's asked for. */
63
69
  const unknownProvider = (name) => gitError("INVALID_ARGUMENT", `No provider named '${name}'`, {
64
- hostHint: `Pass the '${name}' provider to syncJobs`,
70
+ hostHint: `Pass the '${name}' provider to Sync.layer`,
65
71
  context: { reason: "provider-unknown" }
66
72
  });
67
73
  const providerFailed = (name) => gitError("UNAVAILABLE", `The '${name}' provider made no remote for this try`, { hint: "The job tries again" });
@@ -69,14 +75,12 @@ const providerFailed = (name) => gitError("UNAVAILABLE", `The '${name}' provider
69
75
  * The provider's remote for this try: a provider that has gone since fails the job for good,
70
76
  * naming it, and one that throws fails this try with a message that names no secret.
71
77
  */
72
- const remoteOf = /* @__PURE__ */ Effect.fnUntraced(function* (bound, source, signal) {
78
+ const remoteOf = /* @__PURE__ */ Effect.fnUntraced(function* (bound, source, signal, access = "read") {
73
79
  const { provider: name, repo } = source;
74
80
  const provider = bound.providers.get(name);
75
81
  if (provider === void 0) return yield* forGood(unknownProvider(name));
76
- return yield* tryUnlessSpent(() => provider.remote(repo, signal), () => providerFailed(name));
82
+ return yield* tryUnlessSpent(() => provider.remote(repo, access, signal), () => providerFailed(name));
77
83
  });
78
- /** The platform's `fetch`, for a remote with no transport of its own. */
79
- const platformFetch = (request) => fetch(request);
80
84
  /**
81
85
  * `send`, each refusal's body dropped: its text is the remote's, or a gateway's, which may echo the
82
86
  * request's credential, and a try's error is kept where the job's readers see it.
@@ -102,14 +106,17 @@ const fromRemote = (call) => (error) => spentRefusalOf(error) ?? gitErrorFrom(er
102
106
  hint: "The job tries again"
103
107
  });
104
108
  /** The client's smart HTTP to `remote`, with its credentials and transport. */
105
- const httpOf = (remote) => {
109
+ const httpOf = /* @__PURE__ */ Effect.fnUntraced(function* (remote) {
110
+ const client = yield* HttpClient.HttpClient;
111
+ const context = yield* Effect.context();
112
+ const send = (request) => runnerIn(context)(client.execute(HttpClientRequest.fromWeb(request)).pipe(Effect.flatMap(responseToWeb)), request.signal);
106
113
  const options = {
107
114
  url: remote.url,
108
- transport: bodiless(remote.transport ?? platformFetch)
115
+ transport: bodiless(remote.transport ?? send)
109
116
  };
110
117
  if (remote.credentials !== void 0) options.credentials = remote.credentials;
111
118
  return gitHttp(options);
112
- };
119
+ });
113
120
  const refsRead = { collection: collections.refs };
114
121
  const packsRead = { collection: collections.packs };
115
122
  /**
@@ -141,4 +148,4 @@ const openedFor = /* @__PURE__ */ Effect.fnUntraced(function* (caller, internalI
141
148
  refs
142
149
  };
143
150
  });
144
- export { ForGood, SyncTryError, forGood, fromRemote, httpOf, openedFor, remoteOf, runTry, syncObjects, syncRetry, syncTryError, syncWhole, thrownOf, unknownProvider };
151
+ export { ForGood, SyncTryError, forGood, fromRemote, httpOf, openedFor, remoteOf, syncObjects, syncRetry, syncTryError, syncWhole, thrownOf, tried, unknownProvider };
package/dist/sync.d.mts CHANGED
@@ -1,8 +1,5 @@
1
- import { CancelImport, GitHubAppCredentials, ImportJobData, ImportPhase, ImportProgress, ImportRepo, ImportState, ImportedMove, Mirror, MirrorJobData, MirrorPause, MirrorState, Mirrors, PublishImported, RemoveMirror, ReportImportProgress, SyncCancelInput, SyncGitHubOptions, SyncImportInput, SyncJobs, SyncJobsOptions, SyncMirrorInput, SyncMirrorsInput, SyncProvider, SyncPublishInput, SyncRemote, SyncRemoveMirrorInput, SyncSource, SyncTrigger, importedPullRefs } from "./contracts/sync.mjs";
1
+ import { GitHubAppCredentials, ImportJobData, ImportPhase, ImportProgress, ImportState, ImportedMove, MirrorJobData, MirrorPause, MirrorState, ReportImportProgress, Sync, SyncCancelInput, SyncGitHubOptions, SyncImportInput, SyncLayerOptions, SyncMirrorInput, SyncMirrorsInput, SyncProvider, SyncPublishInput, SyncRemote, SyncRemoveMirrorInput, SyncSource, SyncTrigger, cancelImport, importRepo, importedPullRefs, mirror, mirrors, publishImported, removeMirror } from "./contracts/sync.mjs";
2
2
  import { github, webhookBodyBytes } from "./sync/github.mjs";
3
- import { cancelImport, importRepo } from "./sync/import.mjs";
4
- import { publishImported } from "./sync/publish.mjs";
5
- import { syncJobs } from "./sync/jobs.mjs";
6
- import { mirror, mirrors, removeMirror } from "./sync/mirror.mjs";
3
+ import { layer } from "./sync/layer.mjs";
7
4
  import { smartHttp } from "./sync/smart-http.mjs";
8
- export { type CancelImport, type GitHubAppCredentials, type ImportJobData, type ImportPhase, type ImportProgress, type ImportRepo, type ImportState, type ImportedMove, type Mirror, type MirrorJobData, type MirrorPause, type MirrorState, type Mirrors, type PublishImported, type RemoveMirror, type ReportImportProgress, type SyncCancelInput, type SyncGitHubOptions, type SyncImportInput, type SyncJobs, type SyncJobsOptions, type SyncMirrorInput, type SyncMirrorsInput, type SyncProvider, type SyncPublishInput, type SyncRemote, type SyncRemoveMirrorInput, type SyncSource, type SyncTrigger, cancelImport, github, importRepo as import, importedPullRefs, mirror, mirrors, publishImported, removeMirror, smartHttp, syncJobs, webhookBodyBytes };
5
+ export { type GitHubAppCredentials, type ImportJobData, type ImportPhase, type ImportProgress, type ImportState, type ImportedMove, type MirrorJobData, type MirrorPause, type MirrorState, type ReportImportProgress, Sync, type SyncCancelInput, type SyncGitHubOptions, type SyncImportInput, type SyncLayerOptions, type SyncMirrorInput, type SyncMirrorsInput, type SyncProvider, type SyncPublishInput, type SyncRemote, type SyncRemoveMirrorInput, type SyncSource, type SyncTrigger, cancelImport, github, importRepo as import, importedPullRefs, layer, mirror, mirrors, publishImported, removeMirror, smartHttp, webhookBodyBytes };
package/dist/sync.mjs CHANGED
@@ -1,8 +1,5 @@
1
- import { importedPullRefs } from "./contracts/sync.mjs";
1
+ import { Sync, cancelImport, importRepo, importedPullRefs, mirror, mirrors, publishImported, removeMirror } from "./contracts/sync.mjs";
2
2
  import { github, webhookBodyBytes } from "./sync/github.mjs";
3
- import { cancelImport, importRepo } from "./sync/import.mjs";
4
- import { publishImported } from "./sync/publish.mjs";
5
- import { syncJobs } from "./sync/jobs.mjs";
6
- import { mirror, mirrors, removeMirror } from "./sync/mirror.mjs";
3
+ import { layer } from "./sync/layer.mjs";
7
4
  import { smartHttp } from "./sync/smart-http.mjs";
8
- export { cancelImport, github, importRepo as import, importedPullRefs, mirror, mirrors, publishImported, removeMirror, smartHttp, syncJobs, webhookBodyBytes };
5
+ export { Sync, cancelImport, github, importRepo as import, importedPullRefs, layer, mirror, mirrors, publishImported, removeMirror, smartHttp, webhookBodyBytes };