@ref0/git 0.0.0 → 0.3.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 (515) hide show
  1. package/dist/LICENSE +202 -0
  2. package/dist/access/private-refs.d.mts +27 -0
  3. package/dist/access/private-refs.mjs +173 -0
  4. package/dist/access.d.mts +2 -0
  5. package/dist/access.mjs +1 -0
  6. package/dist/auth/access-jwt.d.mts +21 -0
  7. package/dist/auth/access-jwt.mjs +102 -0
  8. package/dist/auth/acting.mjs +15 -0
  9. package/dist/auth/authorize.d.mts +5 -0
  10. package/dist/auth/authorize.mjs +292 -0
  11. package/dist/auth/credentials.mjs +57 -0
  12. package/dist/auth/fences.d.mts +5 -0
  13. package/dist/auth/fences.mjs +65 -0
  14. package/dist/auth/grants.mjs +61 -0
  15. package/dist/auth/helpers.d.mts +17 -0
  16. package/dist/auth/helpers.mjs +25 -0
  17. package/dist/auth/host-function.d.mts +4 -0
  18. package/dist/auth/host-function.mjs +69 -0
  19. package/dist/auth/identify.d.mts +6 -0
  20. package/dist/auth/identify.mjs +97 -0
  21. package/dist/auth/token-rows.mjs +100 -0
  22. package/dist/auth/token-text.mjs +66 -0
  23. package/dist/auth/tokens.d.mts +10 -0
  24. package/dist/auth/tokens.mjs +347 -0
  25. package/dist/auth.d.mts +7 -0
  26. package/dist/auth.mjs +6 -0
  27. package/dist/client/answer.mjs +141 -0
  28. package/dist/client/client.d.mts +23 -0
  29. package/dist/client/client.mjs +50 -0
  30. package/dist/client/git-http.mjs +201 -0
  31. package/dist/client/helper-node.mjs +19 -0
  32. package/dist/client/local.mjs +170 -0
  33. package/dist/client/negotiate.mjs +170 -0
  34. package/dist/client/push-upload.mjs +53 -0
  35. package/dist/client/remote-helper.mjs +129 -0
  36. package/dist/client/remote.mjs +398 -0
  37. package/dist/client/run-remote-helper.d.mts +35 -0
  38. package/dist/client/run-remote-helper.mjs +259 -0
  39. package/dist/client/scrub.d.mts +18 -0
  40. package/dist/client/scrub.mjs +38 -0
  41. package/dist/client/transport.d.mts +2 -0
  42. package/dist/client/transport.mjs +211 -0
  43. package/dist/contracts/access.d.mts +87 -0
  44. package/dist/contracts/actors.d.mts +144 -0
  45. package/dist/contracts/blobs.d.mts +38 -0
  46. package/dist/contracts/calls-spent.d.mts +11 -0
  47. package/dist/contracts/calls-spent.mjs +151 -0
  48. package/dist/contracts/client.d.mts +90 -0
  49. package/dist/contracts/commits.d.mts +126 -0
  50. package/dist/contracts/engine.d.mts +134 -0
  51. package/dist/contracts/events.d.mts +276 -0
  52. package/dist/contracts/files.d.mts +75 -0
  53. package/dist/contracts/forks.d.mts +78 -0
  54. package/dist/contracts/grants.d.mts +60 -0
  55. package/dist/contracts/handlers.d.mts +11 -0
  56. package/dist/contracts/ids.d.mts +15 -0
  57. package/dist/contracts/ids.mjs +15 -0
  58. package/dist/contracts/lfs.d.mts +27 -0
  59. package/dist/contracts/merges.d.mts +33 -0
  60. package/dist/contracts/objects.d.mts +645 -0
  61. package/dist/contracts/objects.mjs +54 -0
  62. package/dist/contracts/operations.d.mts +133 -0
  63. package/dist/contracts/promises.d.mts +38 -0
  64. package/dist/contracts/promises.mjs +13 -0
  65. package/dist/contracts/push-uploads.d.mts +44 -0
  66. package/dist/contracts/queue.d.mts +402 -0
  67. package/dist/contracts/refs.d.mts +95 -0
  68. package/dist/contracts/remote.d.mts +50 -0
  69. package/dist/contracts/repos.d.mts +153 -0
  70. package/dist/contracts/result.d.mts +133 -0
  71. package/dist/contracts/result.mjs +34 -0
  72. package/dist/contracts/rules.d.mts +159 -0
  73. package/dist/contracts/server.d.mts +272 -0
  74. package/dist/contracts/services.d.mts +36 -0
  75. package/dist/contracts/services.mjs +13 -0
  76. package/dist/contracts/signin.d.mts +126 -0
  77. package/dist/contracts/store.d.mts +41 -0
  78. package/dist/contracts/sync.d.mts +210 -0
  79. package/dist/contracts/sync.mjs +8 -0
  80. package/dist/contracts/tags.d.mts +50 -0
  81. package/dist/contracts/tags.mjs +6 -0
  82. package/dist/contracts/tokens.d.mts +87 -0
  83. package/dist/contracts/tokens.mjs +15 -0
  84. package/dist/contracts/topics.d.mts +180 -0
  85. package/dist/contracts/trees.d.mts +84 -0
  86. package/dist/contracts/work.d.mts +31 -0
  87. package/dist/core/access.d.mts +22 -0
  88. package/dist/core/access.mjs +262 -0
  89. package/dist/core/ancestry.mjs +235 -0
  90. package/dist/core/call-names.d.mts +1 -0
  91. package/dist/core/call-names.mjs +93 -0
  92. package/dist/core/clock.mjs +18 -0
  93. package/dist/core/events/deliver.mjs +475 -0
  94. package/dist/core/events/stream.d.mts +19 -0
  95. package/dist/core/events/stream.mjs +297 -0
  96. package/dist/core/forks.mjs +1027 -0
  97. package/dist/core/hooks/post-receive.mjs +212 -0
  98. package/dist/core/hooks/pre-receive.d.mts +5 -0
  99. package/dist/core/hooks/pre-receive.mjs +34 -0
  100. package/dist/core/index-job.mjs +198 -0
  101. package/dist/core/names.mjs +30 -0
  102. package/dist/core/objects/blobs.mjs +60 -0
  103. package/dist/core/objects/commit-writes.mjs +185 -0
  104. package/dist/core/objects/commits.mjs +172 -0
  105. package/dist/core/objects/files.mjs +211 -0
  106. package/dist/core/objects/lines.mjs +42 -0
  107. package/dist/core/objects/merges.mjs +83 -0
  108. package/dist/core/objects/peel.mjs +166 -0
  109. package/dist/core/objects/reading.mjs +284 -0
  110. package/dist/core/objects/tags.mjs +96 -0
  111. package/dist/core/objects/tree-edits.mjs +266 -0
  112. package/dist/core/objects/trees.mjs +229 -0
  113. package/dist/core/objects/writing.mjs +266 -0
  114. package/dist/core/own-writes.mjs +94 -0
  115. package/dist/core/promise.mjs +64 -0
  116. package/dist/core/publish.mjs +142 -0
  117. package/dist/core/push-decide.mjs +206 -0
  118. package/dist/core/push.mjs +1070 -0
  119. package/dist/core/receipts.d.mts +7 -0
  120. package/dist/core/receipts.mjs +234 -0
  121. package/dist/core/ref-conflicts.mjs +27 -0
  122. package/dist/core/refs.mjs +359 -0
  123. package/dist/core/repack.mjs +521 -0
  124. package/dist/core/repos.mjs +752 -0
  125. package/dist/core/rules/changes.mjs +57 -0
  126. package/dist/core/rules/check.mjs +101 -0
  127. package/dist/core/rules/commit-changes.mjs +216 -0
  128. package/dist/core/rules/context.d.mts +9 -0
  129. package/dist/core/rules/context.mjs +120 -0
  130. package/dist/core/rules/define.d.mts +5 -0
  131. package/dist/core/rules/define.mjs +13 -0
  132. package/dist/core/rules/facts.mjs +13 -0
  133. package/dist/core/rules/fetch.d.mts +5 -0
  134. package/dist/core/rules/fetch.mjs +59 -0
  135. package/dist/core/rules/file-globs.mjs +55 -0
  136. package/dist/core/rules/files.mjs +142 -0
  137. package/dist/core/rules/patterns.mjs +23 -0
  138. package/dist/core/rules/protect.d.mts +9 -0
  139. package/dist/core/rules/protect.mjs +116 -0
  140. package/dist/core/seam.d.mts +26 -0
  141. package/dist/core/seam.mjs +54 -0
  142. package/dist/core/sight.mjs +99 -0
  143. package/dist/core/tokens.mjs +95 -0
  144. package/dist/core/view.d.mts +9 -0
  145. package/dist/core/view.mjs +221 -0
  146. package/dist/core/work.mjs +92 -0
  147. package/dist/effect.d.mts +20 -0
  148. package/dist/effect.mjs +18 -0
  149. package/dist/engine/allotted-xdiff.d.mts +4 -0
  150. package/dist/engine/allotted-xdiff.mjs +80 -0
  151. package/dist/engine/attribute-patterns.mjs +163 -0
  152. package/dist/engine/attributes.mjs +226 -0
  153. package/dist/engine/combined.mjs +653 -0
  154. package/dist/engine/commits.mjs +90 -0
  155. package/dist/engine/content.d.mts +4 -0
  156. package/dist/engine/content.mjs +221 -0
  157. package/dist/engine/diff.mjs +49 -0
  158. package/dist/engine/engine.d.mts +25 -0
  159. package/dist/engine/engine.mjs +49 -0
  160. package/dist/engine/failures.d.mts +4 -0
  161. package/dist/engine/failures.mjs +23 -0
  162. package/dist/engine/line-count.mjs +23 -0
  163. package/dist/engine/merge-base-walk.d.mts +2 -0
  164. package/dist/engine/merge-base-walk.mjs +265 -0
  165. package/dist/engine/merge-bases.mjs +27 -0
  166. package/dist/engine/merge-renames.mjs +165 -0
  167. package/dist/engine/merge.mjs +1125 -0
  168. package/dist/engine/parts.d.mts +8 -0
  169. package/dist/engine/parts.mjs +9 -0
  170. package/dist/engine/reads.d.mts +5 -0
  171. package/dist/engine/reads.mjs +105 -0
  172. package/dist/engine/walk.mjs +328 -0
  173. package/dist/engine/xdiff/NOTICE.md +63 -0
  174. package/dist/engine/xdiff/compiled.d.mts +7 -0
  175. package/dist/engine/xdiff/compiled.mjs +9 -0
  176. package/dist/engine/xdiff/embedded.mjs +4 -0
  177. package/dist/engine/xdiff/node.d.mts +7 -0
  178. package/dist/engine/xdiff/node.mjs +10 -0
  179. package/dist/engine/xdiff/upstream/LGPL-2.1 +511 -0
  180. package/dist/engine/xdiff/xdiff.wasm +0 -0
  181. package/dist/engine/xdiff.d.mts +34 -0
  182. package/dist/engine/xdiff.mjs +380 -0
  183. package/dist/engine.d.mts +3 -0
  184. package/dist/engine.mjs +3 -0
  185. package/dist/extend.d.mts +4 -0
  186. package/dist/extend.mjs +3 -0
  187. package/dist/http/answers.mjs +74 -0
  188. package/dist/http/bodies.mjs +143 -0
  189. package/dist/http/core-parts.mjs +252 -0
  190. package/dist/http/fetch-depth.mjs +26 -0
  191. package/dist/http/handler.mjs +94 -0
  192. package/dist/http/node.d.mts +70 -0
  193. package/dist/http/node.mjs +178 -0
  194. package/dist/http/paths.d.mts +9 -0
  195. package/dist/http/paths.mjs +118 -0
  196. package/dist/http/push-uploads.mjs +286 -0
  197. package/dist/http/receive-pack.mjs +235 -0
  198. package/dist/http/upload-pack.mjs +229 -0
  199. package/dist/index.d.mts +46 -0
  200. package/dist/index.mjs +16 -0
  201. package/dist/lfs/calls.mjs +16 -0
  202. package/dist/lfs/locks.mjs +161 -0
  203. package/dist/lfs/objects.mjs +370 -0
  204. package/dist/lfs/pointers.mjs +141 -0
  205. package/dist/lfs/repo.mjs +42 -0
  206. package/dist/lfs/rows.mjs +108 -0
  207. package/dist/lfs/service.mjs +34 -0
  208. package/dist/lfs/upkeep.mjs +162 -0
  209. package/dist/lfs/wire.mjs +102 -0
  210. package/dist/node.d.mts +3 -0
  211. package/dist/node.mjs +3 -0
  212. package/dist/protocol/bytes/buffers.d.mts +38 -0
  213. package/dist/protocol/bytes/buffers.mjs +62 -0
  214. package/dist/protocol/bytes/crc32.d.mts +4 -0
  215. package/dist/protocol/bytes/crc32.mjs +14 -0
  216. package/dist/protocol/bytes/deflate.d.mts +78 -0
  217. package/dist/protocol/bytes/deflate.mjs +175 -0
  218. package/dist/protocol/bytes/errors.d.mts +20 -0
  219. package/dist/protocol/bytes/errors.mjs +19 -0
  220. package/dist/protocol/bytes/hex.mjs +16 -0
  221. package/dist/protocol/bytes/hmac-sha256.mjs +91 -0
  222. package/dist/protocol/bytes/inflate.d.mts +40 -0
  223. package/dist/protocol/bytes/inflate.mjs +109 -0
  224. package/dist/protocol/bytes/joined.d.mts +2 -0
  225. package/dist/protocol/bytes/joined.mjs +25 -0
  226. package/dist/protocol/bytes/sha1-hasher.d.mts +20 -0
  227. package/dist/protocol/bytes/sha1-hasher.mjs +72 -0
  228. package/dist/protocol/bytes/sha1.d.mts +35 -0
  229. package/dist/protocol/bytes/sha1.mjs +409 -0
  230. package/dist/protocol/bytes/sha256.mjs +156 -0
  231. package/dist/protocol/bytes/streams.mjs +11 -0
  232. package/dist/protocol/bytes/text.mjs +19 -0
  233. package/dist/protocol/diff/diff-raw.d.mts +29 -0
  234. package/dist/protocol/diff/diff-raw.mjs +73 -0
  235. package/dist/protocol/diff/patch.mjs +92 -0
  236. package/dist/protocol/diff/paths.mjs +67 -0
  237. package/dist/protocol/diff/read.d.mts +62 -0
  238. package/dist/protocol/diff/read.mjs +342 -0
  239. package/dist/protocol/diff/rename-similarity.mjs +428 -0
  240. package/dist/protocol/diff/text.mjs +12 -0
  241. package/dist/protocol/diff/tree-diff.d.mts +41 -0
  242. package/dist/protocol/diff/tree-diff.mjs +607 -0
  243. package/dist/protocol/framing/band.d.mts +10 -0
  244. package/dist/protocol/framing/band.mjs +16 -0
  245. package/dist/protocol/framing/pkt-line.d.mts +48 -0
  246. package/dist/protocol/framing/pkt-line.mjs +92 -0
  247. package/dist/protocol/objects/checked-blobs.mjs +127 -0
  248. package/dist/protocol/objects/commit.d.mts +25 -0
  249. package/dist/protocol/objects/commit.mjs +138 -0
  250. package/dist/protocol/objects/fsck-gitmodules.mjs +296 -0
  251. package/dist/protocol/objects/fsck-names.mjs +189 -0
  252. package/dist/protocol/objects/fsck.mjs +297 -0
  253. package/dist/protocol/objects/headers.mjs +109 -0
  254. package/dist/protocol/objects/held.mjs +56 -0
  255. package/dist/protocol/objects/iconv.mjs +145 -0
  256. package/dist/protocol/objects/ident.mjs +111 -0
  257. package/dist/protocol/objects/lfs-pointer.d.mts +8 -0
  258. package/dist/protocol/objects/lfs-pointer.mjs +63 -0
  259. package/dist/protocol/objects/links-raw.mjs +89 -0
  260. package/dist/protocol/objects/object-rules.mjs +75 -0
  261. package/dist/protocol/objects/object.d.mts +16 -0
  262. package/dist/protocol/objects/object.mjs +29 -0
  263. package/dist/protocol/objects/tag.d.mts +21 -0
  264. package/dist/protocol/objects/tag.mjs +96 -0
  265. package/dist/protocol/objects/tree.d.mts +43 -0
  266. package/dist/protocol/objects/tree.mjs +162 -0
  267. package/dist/protocol/objects/utf8-verify.mjs +71 -0
  268. package/dist/protocol/packs/delta.d.mts +57 -0
  269. package/dist/protocol/packs/delta.mjs +229 -0
  270. package/dist/protocol/packs/graph.mjs +78 -0
  271. package/dist/protocol/packs/idx.d.mts +54 -0
  272. package/dist/protocol/packs/idx.mjs +274 -0
  273. package/dist/protocol/packs/indexer.d.mts +167 -0
  274. package/dist/protocol/packs/indexer.mjs +507 -0
  275. package/dist/protocol/packs/parts.d.mts +40 -0
  276. package/dist/protocol/packs/parts.mjs +89 -0
  277. package/dist/protocol/packs/pos.mjs +51 -0
  278. package/dist/protocol/packs/reader.d.mts +180 -0
  279. package/dist/protocol/packs/reader.mjs +414 -0
  280. package/dist/protocol/packs/rev.d.mts +32 -0
  281. package/dist/protocol/packs/rev.mjs +99 -0
  282. package/dist/protocol/packs/step.d.mts +10 -0
  283. package/dist/protocol/packs/step.mjs +12 -0
  284. package/dist/protocol/packs/write-error.d.mts +12 -0
  285. package/dist/protocol/packs/write-error.mjs +27 -0
  286. package/dist/protocol/packs/writer.d.mts +157 -0
  287. package/dist/protocol/packs/writer.mjs +353 -0
  288. package/dist/protocol/wire/advertisement.d.mts +72 -0
  289. package/dist/protocol/wire/advertisement.mjs +161 -0
  290. package/dist/protocol/wire/fetch.d.mts +155 -0
  291. package/dist/protocol/wire/fetch.mjs +458 -0
  292. package/dist/protocol/wire/lines.mjs +107 -0
  293. package/dist/protocol/wire/push-uploads.mjs +43 -0
  294. package/dist/protocol/wire/receive-pack.d.mts +71 -0
  295. package/dist/protocol/wire/receive-pack.mjs +157 -0
  296. package/dist/protocol/wire/report-status.d.mts +47 -0
  297. package/dist/protocol/wire/report-status.mjs +119 -0
  298. package/dist/protocol/wire/v2.d.mts +90 -0
  299. package/dist/protocol/wire/v2.mjs +185 -0
  300. package/dist/protocol.d.mts +31 -0
  301. package/dist/protocol.mjs +31 -0
  302. package/dist/queue/advance.mjs +1037 -0
  303. package/dist/queue/callers.mjs +134 -0
  304. package/dist/queue/calls.mjs +1154 -0
  305. package/dist/queue/commit.mjs +85 -0
  306. package/dist/queue/host.d.mts +15 -0
  307. package/dist/queue/host.mjs +88 -0
  308. package/dist/queue/ids.d.mts +5 -0
  309. package/dist/queue/ids.mjs +21 -0
  310. package/dist/queue/lanes.mjs +86 -0
  311. package/dist/queue/limits.mjs +99 -0
  312. package/dist/queue/pages.mjs +76 -0
  313. package/dist/queue/push-option.mjs +62 -0
  314. package/dist/queue/rows.mjs +206 -0
  315. package/dist/queue/schedule.mjs +132 -0
  316. package/dist/queue/search.mjs +315 -0
  317. package/dist/queue/state.mjs +325 -0
  318. package/dist/queue/steps.mjs +317 -0
  319. package/dist/remote-helper.d.mts +3 -0
  320. package/dist/remote-helper.mjs +3 -0
  321. package/dist/rest/api.d.mts +23 -0
  322. package/dist/rest/api.mjs +27 -0
  323. package/dist/rest/blobs.d.mts +58 -0
  324. package/dist/rest/blobs.mjs +41 -0
  325. package/dist/rest/caller.d.mts +102 -0
  326. package/dist/rest/caller.mjs +18 -0
  327. package/dist/rest/client.d.mts +18 -0
  328. package/dist/rest/client.mjs +587 -0
  329. package/dist/rest/commits.d.mts +435 -0
  330. package/dist/rest/commits.mjs +140 -0
  331. package/dist/rest/errors.d.mts +44 -0
  332. package/dist/rest/errors.mjs +186 -0
  333. package/dist/rest/events.d.mts +38 -0
  334. package/dist/rest/events.mjs +74 -0
  335. package/dist/rest/files.d.mts +179 -0
  336. package/dist/rest/files.mjs +92 -0
  337. package/dist/rest/forks.d.mts +205 -0
  338. package/dist/rest/forks.mjs +51 -0
  339. package/dist/rest/handler.d.mts +18 -0
  340. package/dist/rest/handler.mjs +129 -0
  341. package/dist/rest/handlers.d.mts +8 -0
  342. package/dist/rest/handlers.mjs +592 -0
  343. package/dist/rest/listen.d.mts +24 -0
  344. package/dist/rest/listen.mjs +142 -0
  345. package/dist/rest/me.d.mts +55 -0
  346. package/dist/rest/me.mjs +21 -0
  347. package/dist/rest/merges.d.mts +90 -0
  348. package/dist/rest/merges.mjs +39 -0
  349. package/dist/rest/paths.mjs +86 -0
  350. package/dist/rest/queue.d.mts +486 -0
  351. package/dist/rest/queue.mjs +228 -0
  352. package/dist/rest/refs.d.mts +232 -0
  353. package/dist/rest/refs.mjs +86 -0
  354. package/dist/rest/repos.d.mts +223 -0
  355. package/dist/rest/repos.mjs +93 -0
  356. package/dist/rest/tags.d.mts +153 -0
  357. package/dist/rest/tags.mjs +72 -0
  358. package/dist/rest/tokens.d.mts +297 -0
  359. package/dist/rest/tokens.mjs +88 -0
  360. package/dist/rest/topics.d.mts +257 -0
  361. package/dist/rest/topics.mjs +116 -0
  362. package/dist/rest/trees.d.mts +158 -0
  363. package/dist/rest/trees.mjs +118 -0
  364. package/dist/rest/wire.mjs +57 -0
  365. package/dist/rest/work.d.mts +107 -0
  366. package/dist/rest/work.mjs +77 -0
  367. package/dist/rest.d.mts +8 -0
  368. package/dist/rest.mjs +5 -0
  369. package/dist/server/extension.d.mts +17 -0
  370. package/dist/server/extension.mjs +93 -0
  371. package/dist/server/lifecycle.d.mts +3 -0
  372. package/dist/server/lifecycle.mjs +89 -0
  373. package/dist/server/routes.d.mts +28 -0
  374. package/dist/server/routes.mjs +60 -0
  375. package/dist/server/server.d.mts +8 -0
  376. package/dist/server/server.mjs +615 -0
  377. package/dist/signin/codes.mjs +47 -0
  378. package/dist/signin/context.d.mts +9 -0
  379. package/dist/signin/context.mjs +121 -0
  380. package/dist/signin/device.mjs +122 -0
  381. package/dist/signin/forms.mjs +157 -0
  382. package/dist/signin/grants.d.mts +5 -0
  383. package/dist/signin/grants.mjs +257 -0
  384. package/dist/signin/route.mjs +68 -0
  385. package/dist/signin/web.mjs +125 -0
  386. package/dist/signin/wire.d.mts +42 -0
  387. package/dist/signin/wire.mjs +43 -0
  388. package/dist/storage/allotted.mjs +102 -0
  389. package/dist/storage/bits.mjs +41 -0
  390. package/dist/storage/budget.mjs +96 -0
  391. package/dist/storage/calls.d.mts +18 -0
  392. package/dist/storage/calls.mjs +273 -0
  393. package/dist/storage/clean-up.mjs +124 -0
  394. package/dist/storage/distinct-ids.mjs +39 -0
  395. package/dist/storage/ewah.mjs +97 -0
  396. package/dist/storage/fetch.d.mts +15 -0
  397. package/dist/storage/fetch.mjs +998 -0
  398. package/dist/storage/fsck.mjs +77 -0
  399. package/dist/storage/held-memo.mjs +188 -0
  400. package/dist/storage/index-bitmaps.d.mts +4 -0
  401. package/dist/storage/index-bitmaps.mjs +654 -0
  402. package/dist/storage/index-build.d.mts +15 -0
  403. package/dist/storage/index-build.mjs +1447 -0
  404. package/dist/storage/index-fetch.d.mts +10 -0
  405. package/dist/storage/index-fetch.mjs +677 -0
  406. package/dist/storage/index-files.mjs +232 -0
  407. package/dist/storage/index-graph.d.mts +3 -0
  408. package/dist/storage/index-graph.mjs +1049 -0
  409. package/dist/storage/index-layers.mjs +317 -0
  410. package/dist/storage/index-reach.mjs +216 -0
  411. package/dist/storage/index-remap.d.mts +8 -0
  412. package/dist/storage/index-remap.mjs +592 -0
  413. package/dist/storage/layout.mjs +69 -0
  414. package/dist/storage/lfs-pointers.d.mts +21 -0
  415. package/dist/storage/lfs-pointers.mjs +175 -0
  416. package/dist/storage/link-join.mjs +106 -0
  417. package/dist/storage/links.mjs +105 -0
  418. package/dist/storage/loose.d.mts +15 -0
  419. package/dist/storage/loose.mjs +121 -0
  420. package/dist/storage/memory-budget.d.mts +8 -0
  421. package/dist/storage/memory-budget.mjs +546 -0
  422. package/dist/storage/merge.mjs +416 -0
  423. package/dist/storage/object-rows.d.mts +6 -0
  424. package/dist/storage/object-rows.mjs +211 -0
  425. package/dist/storage/pack-order.d.mts +8 -0
  426. package/dist/storage/pack-order.mjs +781 -0
  427. package/dist/storage/pack-ranges.d.mts +5 -0
  428. package/dist/storage/pack-ranges.mjs +284 -0
  429. package/dist/storage/pack-reads.d.mts +11 -0
  430. package/dist/storage/pack-reads.mjs +1007 -0
  431. package/dist/storage/pack-receive.d.mts +11 -0
  432. package/dist/storage/pack-receive.mjs +449 -0
  433. package/dist/storage/packs.d.mts +56 -0
  434. package/dist/storage/packs.mjs +603 -0
  435. package/dist/storage/prune.mjs +506 -0
  436. package/dist/storage/push-allotment.mjs +109 -0
  437. package/dist/storage/push-uploads.mjs +152 -0
  438. package/dist/storage/pushed-commits.mjs +136 -0
  439. package/dist/storage/quarantine.mjs +98 -0
  440. package/dist/storage/raw-ids.mjs +44 -0
  441. package/dist/storage/ready.d.mts +19 -0
  442. package/dist/storage/ready.mjs +328 -0
  443. package/dist/storage/receive-links.mjs +297 -0
  444. package/dist/storage/repack-job.mjs +48 -0
  445. package/dist/storage/repack.d.mts +31 -0
  446. package/dist/storage/repack.mjs +182 -0
  447. package/dist/storage/roots.mjs +42 -0
  448. package/dist/storage/rows.d.mts +4 -0
  449. package/dist/storage/rows.mjs +71 -0
  450. package/dist/storage/send-list.d.mts +8 -0
  451. package/dist/storage/send-list.mjs +319 -0
  452. package/dist/storage/shallow.d.mts +4 -0
  453. package/dist/storage/shallow.mjs +128 -0
  454. package/dist/storage/stream-whole.mjs +236 -0
  455. package/dist/storage/unpack.mjs +238 -0
  456. package/dist/storage/visible.mjs +137 -0
  457. package/dist/storage/walk.d.mts +8 -0
  458. package/dist/storage/walk.mjs +176 -0
  459. package/dist/storage/wants.mjs +362 -0
  460. package/dist/store/call-count.d.mts +47 -0
  461. package/dist/store/call-count.mjs +207 -0
  462. package/dist/store/catalogue.d.mts +7 -0
  463. package/dist/store/catalogue.mjs +643 -0
  464. package/dist/store/closed.d.mts +21 -0
  465. package/dist/store/closed.mjs +34 -0
  466. package/dist/store/crossing.mjs +69 -0
  467. package/dist/store/cursor-seal.d.mts +2 -0
  468. package/dist/store/cursor-seal.mjs +88 -0
  469. package/dist/store/errors.d.mts +12 -0
  470. package/dist/store/errors.mjs +135 -0
  471. package/dist/store/git-store.mjs +75 -0
  472. package/dist/store/list-job.mjs +35 -0
  473. package/dist/store/outbox.d.mts +7 -0
  474. package/dist/store/outbox.mjs +297 -0
  475. package/dist/store/promises.d.mts +5 -0
  476. package/dist/store/promises.mjs +258 -0
  477. package/dist/store/queue-jobs.mjs +43 -0
  478. package/dist/store/random.mjs +28 -0
  479. package/dist/store/records.d.mts +4 -0
  480. package/dist/store/records.mjs +192 -0
  481. package/dist/store/ref-rows.d.mts +4 -0
  482. package/dist/store/ref-rows.mjs +30 -0
  483. package/dist/store/repo-record.mjs +100 -0
  484. package/dist/store/reservations.mjs +82 -0
  485. package/dist/store/scopes.mjs +170 -0
  486. package/dist/store/settle.mjs +63 -0
  487. package/dist/store/topic-jobs.mjs +62 -0
  488. package/dist/sync/bound.d.mts +7 -0
  489. package/dist/sync/bound.mjs +34 -0
  490. package/dist/sync/github.d.mts +12 -0
  491. package/dist/sync/github.mjs +297 -0
  492. package/dist/sync/import.d.mts +8 -0
  493. package/dist/sync/import.mjs +154 -0
  494. package/dist/sync/jobs.d.mts +9 -0
  495. package/dist/sync/jobs.mjs +83 -0
  496. package/dist/sync/mirror.d.mts +9 -0
  497. package/dist/sync/mirror.mjs +227 -0
  498. package/dist/sync/publish.d.mts +5 -0
  499. package/dist/sync/publish.mjs +117 -0
  500. package/dist/sync/records.mjs +73 -0
  501. package/dist/sync/smart-http.d.mts +8 -0
  502. package/dist/sync/smart-http.mjs +23 -0
  503. package/dist/sync/step.mjs +334 -0
  504. package/dist/sync/tries.mjs +126 -0
  505. package/dist/sync.d.mts +8 -0
  506. package/dist/sync.mjs +8 -0
  507. package/dist/topics/advance.mjs +555 -0
  508. package/dist/topics/calls.mjs +346 -0
  509. package/dist/topics/directory.mjs +107 -0
  510. package/dist/topics/host.d.mts +11 -0
  511. package/dist/topics/host.mjs +71 -0
  512. package/dist/topics/members.mjs +177 -0
  513. package/dist/topics/rows.mjs +99 -0
  514. package/dist/topics/topic.mjs +141 -0
  515. package/package.json +86 -5
@@ -0,0 +1,1027 @@
1
+ import { grantOf } from "../auth/grants.mjs";
2
+ import { effectObjects, oneShotReads } from "../storage/calls.mjs";
3
+ import { indexRowKey, isPackId, objectCollections } from "../storage/layout.mjs";
4
+ 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";
7
+ 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";
10
+ import { appendEvents, decodeOutbox, dropUnconfirmed, emptyOutbox, outboxReads, repoEnvelope } from "../store/outbox.mjs";
11
+ import { keptKey } from "../store/records.mjs";
12
+ import { WholeRepo, wholeRef, wholeRefs } from "../store/ref-rows.mjs";
13
+ import { commitRecord, decodeTimes, readRecord, timeRow, writeRecord } from "../store/repo-record.mjs";
14
+ import { listBound } from "../store/cursor-seal.mjs";
15
+ 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";
18
+ import { kindsOf } from "./ancestry.mjs";
19
+ import { isHolder, isRepoId } from "./names.mjs";
20
+ import { decidePush } from "./push-decide.mjs";
21
+ import { heldReceipt, receiptKeys, receiptReads, receiptWrites, repoAnswer, withJobs } from "./receipts.mjs";
22
+ import { badRepoId, repoKept } from "./repos.mjs";
23
+ import { sightIn } from "./sight.mjs";
24
+ import { SealedObjects } from "./view.mjs";
25
+ import { jsonBytes, limits } from "@ref0/infra";
26
+ import * as Effect from "effect/Effect";
27
+ // src/core/forks.ts
28
+ /**
29
+ * A fork copies every ref and object of its source, private or not, until piece 3 copies only
30
+ * what its caller sees: see `before-production.md`.
31
+ */
32
+ const forkWhole = WholeRepo.mint();
33
+ const refsRead = { collection: collections.refs };
34
+ const packsRead = { collection: collections.packs };
35
+ const leavingRead = { collection: objectCollections.leaving };
36
+ /**
37
+ * What a fork reads of its source, after its `self`: refs and packs. Its object rows are read
38
+ * apart, a page at a time, by `sourceRows`, and only by a copy.
39
+ */
40
+ const sourceReads = [refsRead, packsRead];
41
+ const sourceGone = () => fail("NOT_FOUND", "The fork's source is gone");
42
+ const cleaningUp = (fork) => fail("UNAVAILABLE", `'${fork}' is cleaning up a pack its source still lists`, { hint: "Try again in a few minutes, once its clean-up has run" });
43
+ /**
44
+ * The source's record, refs and packs at one version, named as the catalogue names it, so a
45
+ * source whose rename lost its new name is authorized and refused under the old name it still
46
+ * holds, never the one another repo took. While the catalogue gives it neither, its projection is
47
+ * finished, as `namedRecordOf` does, and it's read again; still neither at the version it
48
+ * reconciled, and the source is gone, as one no name reaches.
49
+ */
50
+ const forkRead = Effect.fnUntraced(function* (store, internalId) {
51
+ let reconciledAt;
52
+ for (let attempt = 0; attempt < 5; attempt += 1) {
53
+ const { record, snapshot } = yield* readRecord(store, internalId, sourceReads);
54
+ if (record === void 0 || record.deleted === true) return yield* sourceGone();
55
+ const name = yield* heldNameAt(store, internalId, record, snapshot.version);
56
+ if (name === "moved") continue;
57
+ if (name === void 0 && reconciledAt === snapshot.version) return yield* sourceGone();
58
+ if (name === void 0) {
59
+ yield* reconcile(store, internalId);
60
+ reconciledAt = snapshot.version;
61
+ continue;
62
+ }
63
+ const [, refs = [], packs = []] = snapshot.results;
64
+ return {
65
+ internalId,
66
+ record,
67
+ name,
68
+ listed: {
69
+ repo: internalId,
70
+ version: snapshot.version,
71
+ packs: yield* decodePacks(packs)
72
+ },
73
+ refs,
74
+ packs
75
+ };
76
+ }
77
+ return yield* contended();
78
+ });
79
+ /**
80
+ * Puts a marker named `into` on each pack the source lists that `marked` doesn't hold, then reads
81
+ * the source again, until a read lists no pack without one: that read is the one a fork commits,
82
+ * so no pack it lists can lose its bytes to the source's upkeep between the read and the commit.
83
+ */
84
+ const markPacks = Effect.fnUntraced(function* (core, first, into, marked, signal) {
85
+ const objects = effectObjects(SealedObjects.whole(core.objects, forkWhole));
86
+ let read = first;
87
+ for (let attempt = 0; attempt < 5; attempt += 1) {
88
+ const unmarked = read.listed.packs.filter((pack) => !marked.has(pack.id));
89
+ if (unmarked.length === 0) return read;
90
+ const share = signal === void 0 ? { into } : {
91
+ into,
92
+ signal
93
+ };
94
+ yield* objects.share({
95
+ ...read.listed,
96
+ packs: unmarked
97
+ }, share);
98
+ for (const pack of unmarked) marked.set(pack.id, pack);
99
+ read = yield* forkRead(core.store, read.internalId);
100
+ }
101
+ return yield* contended();
102
+ });
103
+ /** A row as a commit puts it again, in another scope. */
104
+ const copied = (row) => ({
105
+ collection: row.collection,
106
+ id: row.id,
107
+ value: row.value
108
+ });
109
+ const headOf = (branch) => branch.startsWith("refs/") ? branch : `refs/heads/${branch}`;
110
+ /**
111
+ * A `leaving` row, due at `at`, for each pack `marked` names that the fork doesn't list: one its
112
+ * source stopped listing between reads. The fork's clean-up drops its marker, and the bytes only
113
+ * once no other repo's marker is left.
114
+ */
115
+ const unlisted = (marked, listed, at) => [...marked.values()].flatMap(({ id, ...size }) => !listed.has(id) && isPackId(id) ? [leavingRow({
116
+ id,
117
+ ...size
118
+ }, at)] : []);
119
+ /** The default branch's tip in `refs`, or `null` when it has none. */
120
+ const tipOf = Effect.fnUntraced(function* (refs, head) {
121
+ const row = refs.find(({ id }) => id === head);
122
+ if (row === void 0) return null;
123
+ return yield* wholeRef(forkWhole, row);
124
+ });
125
+ 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 '-'" });
127
+ const ownRepo = (repo) => fail("FAILED_PRECONDITION", `'${repo}' is its holder's own: it can't be forked into itself`, {
128
+ hint: "Pass the fork another id",
129
+ context: { reason: "own-repo" }
130
+ });
131
+ const badCursor = (after) => fail("INVALID_ARGUMENT", `'${after}' isn't a cursor of a list of forks`, { hint: "Send the 'next' of the list's last page" });
132
+ /**
133
+ * The folder `forks.list` reads a source's forks under, by the caller's credential (#298, #311):
134
+ * a prefix token's prefix, or a grant's `reach`, so its scan passes no fork the credential can't
135
+ * reach; `undefined` for a repo token, which covers no fork of its repo; `''` with neither, or a
136
+ * grant with no `reach`, where `authorize` decides each fork.
137
+ */
138
+ const forksReach = (caller) => {
139
+ const { token } = caller;
140
+ if (token !== void 0) return token.repo === void 0 ? token.prefix : void 0;
141
+ return grantOf(caller)?.reach ?? "";
142
+ };
143
+ /**
144
+ * What a `forks.list` cursor is sealed for: the list of `source`'s forks under `reach`, and no
145
+ * other, so it opens on no wider token's list. A list that reads nowhere seals none.
146
+ */
147
+ const forksListBound = (source, reach) => reach === void 0 ? listBound("forks.list", source) : listBound("forks.list", source, reach);
148
+ /** The reads of dated rows one `forks.list` makes at most, past the forks its caller may not read. */
149
+ const forkScanReads = 4;
150
+ /**
151
+ * What a fork's commit keeps free beside its copy: its record, receipt, events and jobs, and the
152
+ * rows a retry adds for the packs it marked.
153
+ */
154
+ const copyRoom = {
155
+ writes: 500,
156
+ bytes: 524288
157
+ };
158
+ const mib = 1048576;
159
+ /** `RESOURCE_EXHAUSTED` for a copy of `source` whose commit takes `writes` and `bytes`, past one's. */
160
+ const refuseCopy = (source, writes, bytes) => {
161
+ const past = writes > limits.writes ? `${limits.writes} writes` : bytes > limits.bytes ? `${limits.bytes / mib} MiB` : void 0;
162
+ if (past === void 0) return Effect.void;
163
+ return fail("RESOURCE_EXHAUSTED", `'${source}' is too large to fork: its copy passes one commit's ${past}`, {
164
+ hint: "Forks of repos this large aren't supported yet",
165
+ context: { reason: "too-large" }
166
+ });
167
+ };
168
+ /**
169
+ * `refuseCopy` for a copy of `source` whose rows, with `copyRoom`, pass one commit's. A create or
170
+ * sync checks its first read, before any marker, so a refusal there leaves none.
171
+ */
172
+ const checkCopy = (source, rows) => refuseCopy(source, rows.length + copyRoom.writes, jsonBytes(rows) + copyRoom.bytes);
173
+ /**
174
+ * `refuseCopy` for the change a create or sync commits, its puts, deletes and jobs counted as the
175
+ * store counts them, with `room` for what the write adds beside: the read it lists may be a
176
+ * larger one than its first, which `checkCopy` checked.
177
+ */
178
+ const checkChange = (source, change, room = {
179
+ writes: 0,
180
+ bytes: 0
181
+ }) => {
182
+ const writes = (change.put?.length ?? 0) + (change.delete?.length ?? 0) + (change.jobs?.length ?? 0);
183
+ return refuseCopy(source, writes + room.writes, jsonBytes(change) + room.bytes);
184
+ };
185
+ /** Whether `record` is a live fork of `source`. */
186
+ const isForkOf = (record, source) => record !== void 0 && record.deleted !== true && record.fork?.upstreamInternalId === source;
187
+ 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
+ const notAFork = (repo) => fail("FAILED_PRECONDITION", `'${repo}' isn't a fork`, { context: { reason: "not-a-fork" } });
189
+ const diverged = (repo) => fail("FAILED_PRECONDITION", `'${repo}' has commits its source's default branch lacks`, {
190
+ hint: "Merge its source's branch into it, or reset it to the source's",
191
+ context: { reason: "diverged" }
192
+ });
193
+ /** `<holder>/<the source's last segment>`, as GitHub names a fork (Q327). */
194
+ const defaultId = (source, holder) => `${holder}/${source.split("/").at(-1) ?? source}`;
195
+ /** 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),
198
+ ...read.packs.map(copied),
199
+ ...objects
200
+ ];
201
+ /**
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.
206
+ */
207
+ const sourceRows = Effect.fnUntraced(function* (store, read, keep) {
208
+ const rows = [];
209
+ 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);
216
+ yield* refuseCopy(read.name, rows.length + copyRoom.writes, bytes + copyRoom.bytes);
217
+ return true;
218
+ }))) ? rows : void 0;
219
+ });
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
+ /** 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
+ });
235
+ /**
236
+ * `forks`: a fork is a new repo whose first commit lists its source's packs, refs and rows, once
237
+ * each pack carries a marker of the fork's own, so the source's upkeep never takes bytes the fork
238
+ * 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).
240
+ */
241
+ const forkCalls = (core, bound) => {
242
+ const callerOf = callerFor(bound);
243
+ const { store } = core;
244
+ const rowStore = gitStore(store);
245
+ /**
246
+ * `internalId` as a live fork of `source`, once `caller` may read it: `undefined` for a repo
247
+ * that's deleted or no fork of `source`, and a refusal as `authorize` answers it. It's named and
248
+ * authorized by the name the catalogue gives it, as `hostRecordOf` names a repo, so a rename
249
+ * that lost its new name to another repo answers the name it kept, with events or without. Its
250
+ * refs and packs are read only once `authorize` lets the caller read it, so a fork the caller
251
+ * may not read costs its record and its names' entries, and read again while its name or
252
+ * visibility moved between.
253
+ */
254
+ const forkInfo = Effect.fnUntraced(function* (caller, source, internalId) {
255
+ for (let attempt = 0; attempt < 5; attempt += 1) {
256
+ const named = yield* namedRecordOf(store, internalId);
257
+ 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,
262
+ internalId
263
+ };
264
+ yield* core.authorize({
265
+ caller,
266
+ operation: {
267
+ kind: "read",
268
+ repo: name
269
+ },
270
+ repo
271
+ });
272
+ const { record, snapshot } = yield* readRecord(store, internalId, statsReads);
273
+ if (!isForkOf(record, source)) return void 0;
274
+ if ((yield* heldNameAt(store, internalId, record, snapshot.version)) !== name || record.public !== seen.public) continue;
275
+ const stats = snapshot.results.slice(1);
276
+ return yield* repoInfo(core, caller, internalId, {
277
+ ...record,
278
+ name
279
+ }, stats);
280
+ }
281
+ return yield* contended();
282
+ });
283
+ /** The holder's live fork of `source`, as `caller` may read it, or `undefined` for none. */
284
+ const existingFork = Effect.fnUntraced(function* (caller, source, holder) {
285
+ const internalId = yield* forkOf(store, source, holder);
286
+ if (internalId === void 0) return void 0;
287
+ return yield* forkInfo(caller, source, internalId);
288
+ });
289
+ /**
290
+ * The holder's fork for a create: one `caller` may not read is refused as taken, unnamed, so a
291
+ * create tells no one a fork's name that a get or a list hides from them.
292
+ */
293
+ const holdersFork = (caller, name, source, holder) => Effect.catchIf(existingFork(caller, source, holder), (error) => hiddenCodes.has(error.code), () => holderHasOne(name, holder));
294
+ /**
295
+ * `operation` on the source as `read` found it, asked of `authorize`: a fork copies only a read
296
+ * its caller may still take, so a source made private since the open is refused, as `gone`, and
297
+ * no refusal names it.
298
+ */
299
+ 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({
306
+ caller,
307
+ operation,
308
+ repo
309
+ }), (error) => error.code === "NOT_FOUND", gone);
310
+ };
311
+ /**
312
+ * `operation` on the source's record alone, named as the catalogue names it, asked of
313
+ * `authorize` before a call reads its rows: a source too large for one read is refused as
314
+ * `gone` to a caller who may not read it, so its size reaches no one who may not.
315
+ */
316
+ const authorizeRecord = Effect.fnUntraced(function* (caller, source, operation, gone) {
317
+ const named = yield* namedRecordOf(store, source);
318
+ if (named === void 0) return yield* gone();
319
+ const repo = {
320
+ id: named.name,
321
+ public: named.record.public,
322
+ internalId: source
323
+ };
324
+ yield* Effect.catchIf(core.authorize({
325
+ caller,
326
+ operation: operation(named.name),
327
+ repo
328
+ }), (error) => error.code === "NOT_FOUND", gone);
329
+ });
330
+ /**
331
+ * `read`, a read of the source's rows, refused for size only to a caller who may still do
332
+ * `operation` on the source's record as it is now: one who may not since `authorizeRecord`
333
+ * asked is told the source is `gone`, so the size of a source made private since reaches no one.
334
+ */
335
+ const sourceSized = (read, caller, source, operation, gone) => sizedRead(read, authorizeRecord(caller, source, operation, gone));
336
+ /**
337
+ * `read` with only the refs `caller` sees in the source, so a fork copies, fetches and syncs no
338
+ * ref the caller couldn't read there: a private one it doesn't see is missing, as on every
339
+ * other surface. A source's packs are still shared whole, and the fork's reads by ID follow its
340
+ * own tips' reach (`objectsFollowRefs`), so no hidden commit is read through it.
341
+ */
342
+ const seenSource = Effect.fnUntraced(function* (caller, read) {
343
+ const repo = {
344
+ id: read.name,
345
+ public: read.record.public,
346
+ internalId: read.internalId
347
+ };
348
+ const sight = yield* sightIn(core, caller, repo);
349
+ if (sight.whole) return read;
350
+ return {
351
+ ...read,
352
+ refs: read.refs.filter(({ id }) => sight.sees(id))
353
+ };
354
+ });
355
+ /**
356
+ * The receipt `kept` already answered with, or the name's entry, as a repo's create looks them
357
+ * up: again while the entry changed after the key's lookup, perhaps by this create, sent before.
358
+ */
359
+ const lookUp = Effect.fnUntraced(function* (id, kept, caller) {
360
+ for (let attempt = 0; attempt < 5; attempt += 1) {
361
+ const keyed = yield* keyedRecord(store, id, kept, (held) => core.authorize({
362
+ caller,
363
+ operation: {
364
+ kind: "read",
365
+ repo: held.id
366
+ },
367
+ repo: held
368
+ }));
369
+ if (keyed?.kind === "answered") return keyed;
370
+ const entry = yield* entryOf(store, id);
371
+ if (!nameMoved(keyed, entry)) return {
372
+ kind: "entry",
373
+ entry
374
+ };
375
+ }
376
+ return yield* contended();
377
+ });
378
+ const create = Effect.fnUntraced(function* (repo, input) {
379
+ const { holder } = input;
380
+ if (!isHolder(holder)) return yield* badHolder(holder);
381
+ if (input.id !== void 0 && !isRepoId(input.id)) return yield* badRepoId(input.id);
382
+ const caller = callerOf(input);
383
+ const opened = yield* openRepo(core, caller, {
384
+ kind: "fork.create",
385
+ repo,
386
+ holder
387
+ }, [], input.internalId);
388
+ const source = opened.internalId;
389
+ const id = input.id ?? defaultId(opened.name, holder);
390
+ yield* core.authorize({
391
+ caller,
392
+ operation: {
393
+ kind: "repo.create",
394
+ repo: id
395
+ }
396
+ });
397
+ const at = yield* core.now;
398
+ const kept = yield* keptKey(caller, input.key, [
399
+ "fork",
400
+ source,
401
+ holder,
402
+ id
403
+ ], at);
404
+ const looked = yield* lookUp(id, kept, caller);
405
+ if (looked.kind === "answered") return yield* repoAnswer(looked.receipt);
406
+ const { entry } = looked;
407
+ const existing = yield* holdersFork(caller, opened.name, source, holder);
408
+ if (existing !== void 0) return existing;
409
+ if (id === opened.name) return yield* ownRepo(opened.name);
410
+ if (entry !== void 0 && entry.deleted !== true) return yield* alreadyExists(id);
411
+ const internalId = newInternalId();
412
+ const revision = (entry?.sourceRevision ?? 0) + 1;
413
+ const forkingName = (name) => ({
414
+ kind: "fork.create",
415
+ repo: name,
416
+ holder
417
+ });
418
+ const forking = (read) => forkingName(read.name);
419
+ const gone = () => fail("NOT_FOUND", `No repo '${repo}'`);
420
+ yield* authorizeRecord(caller, source, forkingName, gone);
421
+ const marked = /* @__PURE__ */ new Map();
422
+ let taken;
423
+ for (let attempt = 0; taken === void 0 && attempt < 5; attempt += 1) {
424
+ const first = yield* sourceSized(forkRead(store, source), caller, source, forkingName, gone);
425
+ yield* authorizeSource(caller, first, forking(first), gone);
426
+ const firstRows = yield* sourceRows(rowStore, first, keepAll);
427
+ 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);
430
+ yield* authorizeSource(caller, checked, forking(checked), gone);
431
+ const objects = checked.listed.version === first.listed.version ? firstRows : yield* sourceRows(rowStore, checked, keepAll);
432
+ if (objects !== void 0) taken = {
433
+ read: checked,
434
+ objects
435
+ };
436
+ }
437
+ if (taken === void 0) return yield* contended();
438
+ const { objects } = taken;
439
+ const read = yield* seenSource(caller, taken.read);
440
+ const record = forkRecord(read, id, revision, holder, at);
441
+ const listing = new Set(read.listed.packs.map((pack) => pack.id));
442
+ const pushed = read.refs.length === 0 ? [] : [timeRow(pushedKey, void 0, at)];
443
+ const rows = [
444
+ ...forkRows(read, objects),
445
+ ...pushed,
446
+ ...unlisted(marked, listing, at)
447
+ ];
448
+ const info = yield* repoInfo(core, caller, internalId, record, [
449
+ read.refs,
450
+ read.packs,
451
+ pushed
452
+ ]);
453
+ const receipt = receiptWrites(kept, repoKept(info), core.repackJobRow);
454
+ const created = {
455
+ type: "repo.created",
456
+ ...repoEnvelope(caller, id),
457
+ public: record.public,
458
+ upstream: read.name,
459
+ upstreamInternalId: source
460
+ };
461
+ const options = {
462
+ scope: repoScope(internalId),
463
+ at,
464
+ confirm: id
465
+ };
466
+ if (entry?.nextSeq !== void 0) {
467
+ options.from = entry.nextSeq;
468
+ options.after = entry.internalId;
469
+ }
470
+ const appended = yield* appendEvents(core.events, emptyOutbox, [created], options);
471
+ const put = [
472
+ ...rows,
473
+ ...receipt.put,
474
+ ...appended.put
475
+ ];
476
+ const indexing = read.refs.length === 0 ? [] : indexJobs(core, { state: "unbuilt" });
477
+ const jobs = withJobs([
478
+ core.repackJobRow(),
479
+ ...indexing,
480
+ ...appended.jobs
481
+ ], receipt.jobs);
482
+ const room = {
483
+ writes: 2,
484
+ bytes: jsonBytes(record) + 1024
485
+ };
486
+ yield* checkChange(opened.name, {
487
+ put,
488
+ jobs
489
+ }, room);
490
+ const written = yield* writeRecord(store, internalId, {
491
+ expect: 0,
492
+ record,
493
+ put,
494
+ jobs
495
+ });
496
+ if (written === void 0) return yield* contended();
497
+ if (written.outcome === "won") return info;
498
+ const dropped = dropUnconfirmed(appended.head);
499
+ yield* commitRecord(store, internalId, {
500
+ expect: written.version,
501
+ record: {
502
+ ...record,
503
+ deleted: true
504
+ },
505
+ put: dropped.put,
506
+ delete: [...receiptKeys(kept), ...dropped.delete]
507
+ });
508
+ const theirs = yield* holdersFork(caller, opened.name, source, holder);
509
+ if (theirs !== void 0) return theirs;
510
+ return yield* written.outcome === "lost" ? alreadyExists(id) : contended();
511
+ });
512
+ const get = Effect.fnUntraced(function* (repo, input) {
513
+ const caller = callerOf(input);
514
+ const opened = yield* openRepo(core, caller, {
515
+ kind: "read",
516
+ repo
517
+ }, [], input.internalId);
518
+ const found = yield* unlessHidden(existingFork(caller, opened.internalId, input.holder));
519
+ if (found === void 0) return yield* fail("NOT_FOUND", `'${repo}' has no fork for '${input.holder}'`);
520
+ return found;
521
+ });
522
+ /**
523
+ * `source`'s forks under `reach` that `caller` may read after `after`, up to `limit`, as a page
524
+ * names them. It reads on past the forks it leaves out, as many dated rows as `forkScanReads` reads take, so a short
525
+ * page, its cursor and whether it has one come only from forks the caller may read. The cursor is
526
+ * a read fork's key, or the last row read when the scan stops first, which `list` seals, so the
527
+ * caller reads neither.
528
+ */
529
+ const visibleForks = Effect.fnUntraced(function* (caller, source, reach, limit, after) {
530
+ const items = [];
531
+ let cursor = after;
532
+ let last = after;
533
+ for (let read = 0; read < forkScanReads; read += 1) {
534
+ const page = yield* forksCreated(store, source, reach, 200, cursor);
535
+ for (const { internalId, key } of page.forks) {
536
+ const info = yield* unlessHidden(forkInfo(caller, source, internalId));
537
+ if (info === void 0) continue;
538
+ if (items.length === limit) return {
539
+ items,
540
+ next: last
541
+ };
542
+ items.push(info);
543
+ cursor = key;
544
+ last = key;
545
+ }
546
+ if (page.next === void 0) return {
547
+ items,
548
+ next: void 0
549
+ };
550
+ cursor = page.next;
551
+ }
552
+ return {
553
+ items,
554
+ next: cursor
555
+ };
556
+ });
557
+ const list = Effect.fnUntraced(function* (repo, input) {
558
+ const caller = callerOf(input);
559
+ const sent = input.page?.after;
560
+ const opened = yield* openRepo(core, caller, {
561
+ kind: "read",
562
+ repo
563
+ }, [], input.internalId);
564
+ const reach = forksReach(caller);
565
+ const bound = forksListBound(opened.internalId, reach);
566
+ const after = sent === void 0 ? void 0 : yield* core.cursors.open(bound, sent);
567
+ if (sent !== void 0 && (after === void 0 || !isCreatedKey(after))) return yield* badCursor(sent);
568
+ const limit = listLimit(input.page);
569
+ if (reach === void 0) return { items: [] };
570
+ const found = yield* visibleForks(caller, opened.internalId, reach, limit, after);
571
+ const listing = { items: found.items };
572
+ if (found.next !== void 0) listing.next = yield* core.cursors.seal(bound, found.next);
573
+ return listing;
574
+ });
575
+ /** `fork.sync` asked of `authorize` for `repo`, the fork as its record names its holder now. */
576
+ const authorizeSync = Effect.fnUntraced(function* (caller, repo, record) {
577
+ const of = record?.fork;
578
+ if (of === void 0) return yield* notAFork(repo.id);
579
+ const operation = {
580
+ kind: "fork.sync",
581
+ repo: repo.id,
582
+ holder: of.holder
583
+ };
584
+ yield* core.authorize({
585
+ caller,
586
+ operation,
587
+ repo
588
+ });
589
+ });
590
+ /**
591
+ * The fork a sync by `fork` opens, or the receipt its key answered with, looked up by name as a
592
+ * rename's is: a keyed sync sent again after the fork was renamed, and the name forked again,
593
+ * finds its receipt in the repo it moved, and never syncs the new one.
594
+ */
595
+ const openSync = Effect.fnUntraced(function* (fork, caller, kept, internalId) {
596
+ for (let attempt = 0; attempt < 5; attempt += 1) {
597
+ const keyed = yield* keyedRecord(store, fork, kept, (repo) => Effect.andThen(core.authorize({
598
+ caller,
599
+ operation: {
600
+ kind: "read",
601
+ repo: repo.id
602
+ },
603
+ repo
604
+ }), Effect.flatMap(readRecord(store, repo.internalId), ({ record }) => authorizeSync(caller, repo, record))), internalId);
605
+ if (keyed?.kind === "answered") return keyed;
606
+ const opened = yield* openKeyed(core, caller, {
607
+ kind: "read",
608
+ repo: fork
609
+ }, [], keyed, internalId);
610
+ if (opened !== void 0) return {
611
+ kind: "opened",
612
+ opened
613
+ };
614
+ }
615
+ return yield* contended();
616
+ });
617
+ /**
618
+ * One try's read of the fork opened as `fork`: its record and rows, settled and named as the
619
+ * catalogue names it now, with `may` asked of `authorize` under that name. `undefined` when the
620
+ * try must read again.
621
+ */
622
+ const forkTry = Effect.fnUntraced(function* (fork, caller, internalId, kept, may) {
623
+ const reads = [
624
+ ...statsReads,
625
+ leavingRead,
626
+ indexRowKey
627
+ ];
628
+ const hiddenFork = () => fail("NOT_FOUND", `No repo '${fork}'`);
629
+ const fence = core.fences(caller, {
630
+ internalId,
631
+ name: fork
632
+ });
633
+ const { record, snapshot } = yield* sourceSized(readRecord(store, internalId, [
634
+ ...reads,
635
+ ...outboxReads,
636
+ ...receiptReads(kept),
637
+ ...fence.reads
638
+ ]), caller, internalId, (name) => ({
639
+ kind: "read",
640
+ repo: name
641
+ }), hiddenFork);
642
+ if (record === void 0 || record.deleted === true) return yield* fail("NOT_FOUND", `No repo '${fork}'`);
643
+ const [, refRows = [], packRows = [], timeRows = [], leavingRows = [], indexRows = []] = snapshot.results;
644
+ const [headRows = [], cursorRows = [], ...afterOutbox] = snapshot.results.slice(1 + reads.length);
645
+ const keyed = receiptReads(kept).length;
646
+ yield* fence.check(afterOutbox.slice(keyed));
647
+ const outbox = yield* decodeOutbox([headRows, cursorRows]);
648
+ const settling = {
649
+ version: snapshot.version,
650
+ head: outbox.head,
651
+ record
652
+ };
653
+ if (yield* settleName(store, repoScope(internalId), settling)) return void 0;
654
+ const name = yield* heldNameAt(store, internalId, record, snapshot.version);
655
+ if (name === "moved") return void 0;
656
+ if (name === void 0) {
657
+ yield* reconcile(store, internalId);
658
+ return;
659
+ }
660
+ const target = {
661
+ id: name,
662
+ public: record.public,
663
+ internalId
664
+ };
665
+ yield* Effect.catchIf(core.authorize({
666
+ caller,
667
+ operation: {
668
+ kind: "read",
669
+ repo: name
670
+ },
671
+ repo: target
672
+ }), (error) => hiddenCodes.has(error.code), hiddenFork);
673
+ yield* may(target, record);
674
+ return {
675
+ record,
676
+ snapshot,
677
+ name,
678
+ outbox,
679
+ rows: {
680
+ refRows,
681
+ packRows,
682
+ timeRows,
683
+ leavingRows,
684
+ indexRow: indexRows[0]
685
+ },
686
+ receipts: afterOutbox.slice(0, keyed)
687
+ };
688
+ });
689
+ /**
690
+ * The source's first read, as one who may read it: one who may not is told it's gone, as a
691
+ * deleted source's fork is, before its rows are read.
692
+ */
693
+ const readSource = Effect.fnUntraced(function* (caller, upstream) {
694
+ const readingName = (name) => ({
695
+ kind: "read",
696
+ repo: name
697
+ });
698
+ yield* authorizeRecord(caller, upstream, readingName, sourceGone);
699
+ const first = yield* sourceSized(forkRead(store, upstream), caller, upstream, readingName, sourceGone);
700
+ yield* authorizeSource(caller, first, readingName(first.name), sourceGone);
701
+ return yield* seenSource(caller, first);
702
+ });
703
+ /**
704
+ * The source's packs and object rows the fork lacks, from `first`, as a quarantine the fork's
705
+ * commit takes, with the checked read it's from: each pack marked for the fork, then read again
706
+ * until a read lists none without one. `checked` decides that read, or `undefined` reads again.
707
+ */
708
+ const copyInto = Effect.fnUntraced(function* (caller, fork, into, first, checked, signal) {
709
+ const { listing, rows, marked, shared } = into;
710
+ const held = yield* Effect.forEach(rows.leavingRows, (row) => decodeHeld(LeavingRow, row));
711
+ const relistedOf = (packs) => {
712
+ const ids = new Set(packs.flatMap(({ id }) => listing.has(id) ? [] : [id]));
713
+ return held.filter(({ pack }) => ids.has(pack));
714
+ };
715
+ const due = (packs) => relistedOf(packs).some(({ value }) => value.taken === true);
716
+ 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);
719
+ if (firstRows === void 0) return void 0;
720
+ const addedRows = first.packs.filter(({ id }) => !listing.has(id));
721
+ yield* checkCopy(first.name, [...firstRows, ...addedRows]);
722
+ const readingName = (name) => ({
723
+ kind: "read",
724
+ repo: name
725
+ });
726
+ const marking = yield* sourceSized(markPacks(core, first, into.internalId, marked, signal), caller, first.internalId, readingName, sourceGone);
727
+ yield* authorizeSource(caller, marking, readingName(marking.name), sourceGone);
728
+ const source = yield* seenSource(caller, marking);
729
+ for (const [id, pack] of marked) if (!listing.has(id)) shared.set(id, pack);
730
+ if (!(yield* checked(source))) return void 0;
731
+ const lacked = source.listed.version === first.listed.version ? firstRows : yield* sourceRows(rowStore, source, lacking);
732
+ if (lacked === void 0) return void 0;
733
+ const added = source.listed.packs.filter(({ id }) => !listing.has(id));
734
+ const adding = new Set(added.map(({ id }) => id));
735
+ const relisted = relistedOf(added);
736
+ if (due(added)) return yield* cleaningUp(fork);
737
+ const covered = /* @__PURE__ */ new Set([
738
+ ...listing,
739
+ ...adding,
740
+ ...rows.leavingRows.map(({ id }) => id)
741
+ ]);
742
+ return {
743
+ source,
744
+ added,
745
+ received: {
746
+ id: newChangeId(),
747
+ change: {
748
+ add: added,
749
+ put: [...lacked, ...unlisted(shared, covered, into.at)],
750
+ delete: relisted.map(({ pack }) => leavingKey(pack))
751
+ },
752
+ bytes: added.reduce((sum, pack) => sum + pack.bytes, 0),
753
+ objects: added.reduce((sum, pack) => sum + pack.objects, 0),
754
+ lfsPointers: noLfsPointers
755
+ }
756
+ };
757
+ });
758
+ return {
759
+ create,
760
+ get,
761
+ list,
762
+ sync: Effect.fnUntraced(function* (fork, input) {
763
+ const caller = callerOf(input);
764
+ const started = yield* core.now;
765
+ const kept = yield* keptKey(caller, input.key, ["fork.sync", fork], started);
766
+ const looked = yield* openSync(fork, caller, kept, input.internalId);
767
+ if (looked.kind === "answered") return yield* repoAnswer(looked.receipt);
768
+ const { opened } = looked;
769
+ const of = opened.record.fork;
770
+ if (of === void 0) return yield* notAFork(fork);
771
+ const { internalId } = opened;
772
+ const objects = effectObjects(SealedObjects.whole(core.objects, forkWhole));
773
+ const reads = oneShotReads(objects);
774
+ const scope = repoScope(internalId);
775
+ const shared = /* @__PURE__ */ new Map();
776
+ const signal = input.signal === void 0 ? {} : { signal: input.signal };
777
+ for (let attempt = 0; attempt < 5; attempt += 1) {
778
+ const at = yield* core.now;
779
+ const read = yield* forkTry(fork, caller, internalId, kept, (target, record) => authorizeSync(caller, target, record));
780
+ if (read === void 0) continue;
781
+ const { record, snapshot, name, outbox, rows } = read;
782
+ const { refRows, packRows, timeRows, leavingRows } = rows;
783
+ const receipt = yield* heldReceipt(read.receipts, kept);
784
+ if (receipt !== void 0) return yield* repoAnswer(receipt);
785
+ const named = {
786
+ ...record,
787
+ name
788
+ };
789
+ const listing = new Set(packRows.map(({ id }) => id));
790
+ const owned = yield* decodePacks(packRows);
791
+ const marked = new Map(owned.map((pack) => [pack.id, pack]));
792
+ const first = yield* readSource(caller, of.upstreamInternalId);
793
+ const sourceHead = headOf(first.record.defaultBranch);
794
+ const head = headOf(record.defaultBranch);
795
+ const from = yield* tipOf(refRows, head);
796
+ const to = yield* tipOf(first.refs, sourceHead);
797
+ const unchanged = Effect.gen(function* () {
798
+ const info = yield* repoInfo(core, caller, internalId, named, [
799
+ refRows,
800
+ packRows,
801
+ timeRows
802
+ ]);
803
+ const left = unlisted(shared, /* @__PURE__ */ new Set([...listing, ...leavingRows.map(({ id }) => id)]), at);
804
+ if (kept === void 0 && left.length === 0) return info;
805
+ const receipt = receiptWrites(kept, repoKept(info), core.repackJobRow);
806
+ const upkeep = left.length === 0 ? [] : [core.repackJobRow()];
807
+ return (yield* storeCall(() => store.commit(scope, {
808
+ id: newChangeId(),
809
+ expect: snapshot.version,
810
+ put: [...receipt.put, ...left],
811
+ jobs: withJobs(upkeep, receipt.jobs)
812
+ }))).ok ? info : void 0;
813
+ });
814
+ if (to === null || to === from) {
815
+ const info = yield* unchanged;
816
+ if (info !== void 0) return info;
817
+ continue;
818
+ }
819
+ const edits = [{
820
+ ref: head,
821
+ from,
822
+ to
823
+ }];
824
+ const kinds = yield* kindsOf({
825
+ objects: reads,
826
+ listed: first.listed,
827
+ pushed: () => Effect.succeed(void 0),
828
+ edits,
829
+ ...signal
830
+ });
831
+ const [update] = kinds.updates;
832
+ const refusal = kinds.refused.get(head);
833
+ if (update === void 0) {
834
+ const info = yield* unchanged;
835
+ if (info !== void 0) return info;
836
+ continue;
837
+ }
838
+ if (refusal !== void 0) return yield* Effect.fail(refusal);
839
+ const kind = update.kind === "force" ? yield* kinds.exact(update) : update.kind;
840
+ if (kind === "force") return yield* diverged(fork);
841
+ const into = {
842
+ internalId,
843
+ version: snapshot.version,
844
+ listing,
845
+ rows,
846
+ marked,
847
+ shared,
848
+ at
849
+ };
850
+ const tipHeld = (source) => Effect.map(tipOf(source.refs, headOf(source.record.defaultBranch)), (tip) => tip === to);
851
+ const copy = yield* copyInto(caller, fork, into, first, tipHeld, input.signal);
852
+ if (copy === void 0) continue;
853
+ const { source, added, received } = copy;
854
+ const refs = yield* decodeRefs(refRows);
855
+ const decision = decidePush({
856
+ read: {
857
+ version: snapshot.version,
858
+ refs,
859
+ head
860
+ },
861
+ command: {
862
+ source: "api",
863
+ updates: [{
864
+ ...update,
865
+ kind
866
+ }],
867
+ atomic: true,
868
+ received,
869
+ refused: /* @__PURE__ */ new Map()
870
+ }
871
+ });
872
+ if (decision.kind === "answer") {
873
+ const { answer } = decision;
874
+ if (answer.kind === "error") return yield* Effect.fail(answer.error);
875
+ const [applied] = answer.value.updates;
876
+ if (applied?.kind === "rejected") return yield* Effect.fail(applied.error);
877
+ const info = yield* unchanged;
878
+ if (info !== void 0) return info;
879
+ continue;
880
+ }
881
+ const moved = [...refRows.filter(({ id }) => id !== head), {
882
+ collection: collections.refs,
883
+ id: head,
884
+ value: { oid: to }
885
+ }];
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
+ }))];
894
+ const times = yield* decodeTimes(timeRows);
895
+ const pushed = timeRow(pushedKey, times.pushed, at);
896
+ const timed = [...timeRows.filter(({ id }) => id !== pushedKey.id), pushed];
897
+ const info = yield* repoInfo(core, caller, internalId, named, [
898
+ moved,
899
+ listedRows,
900
+ timed
901
+ ]);
902
+ const keptWrites = receiptWrites(kept, repoKept(info), core.repackJobRow);
903
+ const write = newChangeId();
904
+ const events = decision.moved.map((move) => ({
905
+ type: "ref.updated",
906
+ ...repoEnvelope(caller, name),
907
+ ...move,
908
+ push: {
909
+ id: write,
910
+ branches: head.startsWith("refs/heads/") ? 1 : 0,
911
+ tags: 0,
912
+ source: "api"
913
+ }
914
+ }));
915
+ const appended = yield* appendEvents(core.events, outbox, events, {
916
+ scope,
917
+ at
918
+ });
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)];
922
+ const change = {
923
+ put: [
924
+ ...decision.change.put,
925
+ pushed,
926
+ ...keptWrites.put,
927
+ ...appended.put
928
+ ],
929
+ delete: [...decision.change.delete, ...appended.delete],
930
+ jobs: withJobs([...jobs, ...appended.jobs], keptWrites.jobs)
931
+ };
932
+ yield* checkChange(source.name, change);
933
+ if (!(yield* storeCall(() => store.commit(scope, {
934
+ id: write,
935
+ expect: decision.expect,
936
+ ...change
937
+ }))).ok) continue;
938
+ return info;
939
+ }
940
+ return yield* contended();
941
+ }),
942
+ fetch: Effect.fnUntraced(function* (fork, input) {
943
+ const caller = callerOf(input);
944
+ const opened = yield* openRepo(core, caller, {
945
+ kind: "read",
946
+ repo: fork
947
+ }, [], input.internalId);
948
+ const of = opened.record.fork;
949
+ if (of === void 0) return yield* notAFork(fork);
950
+ const { internalId } = opened;
951
+ const shared = /* @__PURE__ */ new Map();
952
+ const may = (target) => core.authorize({
953
+ caller,
954
+ operation: {
955
+ kind: "object.create",
956
+ repo: target.id
957
+ },
958
+ repo: target
959
+ });
960
+ for (let attempt = 0; attempt < 5; attempt += 1) {
961
+ const at = yield* core.now;
962
+ const read = yield* forkTry(fork, caller, internalId, void 0, may);
963
+ if (read === void 0) continue;
964
+ const { record, snapshot, rows } = read;
965
+ const listing = new Set(rows.packRows.map(({ id }) => id));
966
+ const owned = yield* decodePacks(rows.packRows);
967
+ const marked = new Map(owned.map((pack) => [pack.id, pack]));
968
+ const into = {
969
+ internalId,
970
+ version: snapshot.version,
971
+ listing,
972
+ rows,
973
+ marked,
974
+ shared,
975
+ at
976
+ };
977
+ const first = yield* readSource(caller, of.upstreamInternalId);
978
+ const copy = yield* copyInto(caller, fork, into, first, () => Effect.succeed(true), input.signal);
979
+ if (copy === void 0) continue;
980
+ const { source, added, received } = copy;
981
+ const tips = yield* decodeRefs(source.refs);
982
+ const fetched = {
983
+ source: source.name,
984
+ head: headOf(source.record.defaultBranch),
985
+ tips: [...tips].map(([ref, oid]) => ({
986
+ name: ref,
987
+ oid
988
+ }))
989
+ };
990
+ const { put = [], delete: drop = [] } = received.change;
991
+ if (added.length === 0 && put.length === 0 && drop.length === 0) return fetched;
992
+ const refs = yield* decodeRefs(rows.refRows);
993
+ const head = headOf(record.defaultBranch);
994
+ const decision = decidePush({
995
+ read: {
996
+ version: snapshot.version,
997
+ refs,
998
+ head
999
+ },
1000
+ command: {
1001
+ source: "api",
1002
+ updates: [],
1003
+ atomic: true,
1004
+ received,
1005
+ refused: /* @__PURE__ */ new Map()
1006
+ }
1007
+ });
1008
+ if (decision.kind === "answer") {
1009
+ const { answer } = decision;
1010
+ return answer.kind === "error" ? yield* Effect.fail(answer.error) : fetched;
1011
+ }
1012
+ const change = {
1013
+ ...decision.change,
1014
+ jobs: [core.repackJobRow()]
1015
+ };
1016
+ yield* checkChange(source.name, change);
1017
+ if ((yield* storeCall(() => store.commit(repoScope(internalId), {
1018
+ id: newChangeId(),
1019
+ expect: decision.expect,
1020
+ ...change
1021
+ }))).ok) return fetched;
1022
+ }
1023
+ return yield* contended();
1024
+ })
1025
+ };
1026
+ };
1027
+ export { forkCalls, forksListBound, forksReach };