@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,1070 @@
1
+ import { openTreeBytes } from "../storage/budget.mjs";
2
+ import { effectObjects, scopedReceive, walkObjects } from "../storage/calls.mjs";
3
+ import { openTreesRefusal } from "../storage/push-allotment.mjs";
4
+ import { isLoose } from "../storage/loose.mjs";
5
+ import { indexRowKey, objectCollections } from "../storage/layout.mjs";
6
+ import { noLfsPointers } from "../storage/lfs-pointers.mjs";
7
+ import { isShallowRoot } from "../storage/links.mjs";
8
+ import { allottedRows } from "../storage/allotted.mjs";
9
+ import { gitObjectOf, objectOfRow, receivedRows } from "../storage/object-rows.mjs";
10
+ import { QuarantineRow, decodeHeld } from "../storage/rows.mjs";
11
+ import { decodeRow, fail, gitError, storeCall, thrownError } from "../store/errors.mjs";
12
+ import { callScope } from "../store/call-count.mjs";
13
+ import { runIn } from "../store/crossing.mjs";
14
+ import { decodePacks } from "../store/git-store.mjs";
15
+ import { WholeRepo, wholeRefs } from "../store/ref-rows.mjs";
16
+ import { gitsOwnMove, hiddenUnder } from "../protocol/wire/lines.mjs";
17
+ import { sightIn } from "./sight.mjs";
18
+ import { appendEvents, decodeOutbox, firstSeq, outboxReads, repoEnvelope } from "../store/outbox.mjs";
19
+ import { MirrorRow, PrunedMark, mirrorJobName } from "../store/records.mjs";
20
+ import { decodeTimes, readRecord, repoStats, timeRow } from "../store/repo-record.mjs";
21
+ import { advanceRow } from "../store/queue-jobs.mjs";
22
+ import { liveReservations, reservedTarget } from "../store/reservations.mjs";
23
+ import { settleName } from "../store/settle.mjs";
24
+ import { collections, newChangeId, prunedKey, pushedKey, pushedUnder, repoScope } from "../store/scopes.mjs";
25
+ import { headOf, indexJobs, openKeyed, openRepo } from "./access.mjs";
26
+ import { kindsOf } from "./ancestry.mjs";
27
+ import { savedPushRow } from "./hooks/post-receive.mjs";
28
+ import { runPreReceive } from "./hooks/pre-receive.mjs";
29
+ import { changesOf } from "./rules/changes.mjs";
30
+ import { commitChangesOf, coveredTips } from "./rules/commit-changes.mjs";
31
+ import { gitsOwnRef, runPushRules, unseenRef } from "./rules/check.mjs";
32
+ import { checking } from "./rules/context.mjs";
33
+ import { changedWhileChecked, factsHeld, tipsOf } from "./rules/facts.mjs";
34
+ import { decidePush } from "./push-decide.mjs";
35
+ import { heldReceipt, receiptReads, receiptWrites, refsAnswer, refsKept, withJobs } from "./receipts.mjs";
36
+ import { SealedObjects, viewOf } from "./view.mjs";
37
+ import { ownWriter, ownWritesOf } from "./own-writes.mjs";
38
+ import { publishable, unpublished } from "./publish.mjs";
39
+ import { peeledOf } from "../storage/wants.mjs";
40
+ import { checkWrites } from "@ref0/infra";
41
+ import * as Effect from "effect/Effect";
42
+ import * as Result from "effect/Result";
43
+ // src/core/push.ts
44
+ /**
45
+ * The push decide reads every ref, private or not: a move's `from`, a folder conflict and a
46
+ * topic's reservation are checked against the repo as it is. What it answers the caller about a
47
+ * name it can't write is `unseenRef`'s, the same whatever is there.
48
+ */
49
+ const pushWhole = WholeRepo.mint();
50
+ const packsRead = { collection: collections.packs };
51
+ const refsRead = { collection: collections.refs };
52
+ const timesRead = { collection: collections.stats };
53
+ /** The repo's cruft packs' rows, up to one past what the decide names, as `PushRead.packs` says. */
54
+ const cruftRead = {
55
+ collection: objectCollections.cruft,
56
+ limit: 65
57
+ };
58
+ const mirrorsRead = { collection: collections.mirrors };
59
+ /**
60
+ * A queue publish refused for `entries`, whose heads would publish commits their own callers may
61
+ * not: each fails alone, and the queue builds the rest again.
62
+ */
63
+ const entriesUnpublishable = (ref, entries) => gitError("NOT_ALLOWED", `Moving ${ref} would publish commits an entry's caller may not publish`, {
64
+ hint: "Ask someone who may publish them to queue it",
65
+ context: {
66
+ reason: "entry-unpublishable",
67
+ entries: [...entries]
68
+ }
69
+ });
70
+ const noHeadJudged = (ref) => gitError("NOT_ALLOWED", `Moving ${ref} would publish commits no entry's caller was judged for`, { hint: "Queue the entries again" });
71
+ /** Codes a push fails with when it may succeed sent again: nothing refused it. */
72
+ const retriedCodes = /* @__PURE__ */ new Set([
73
+ "UNAVAILABLE",
74
+ "DEADLINE_EXCEEDED",
75
+ "INTERNAL",
76
+ "DATA_LOSS"
77
+ ]);
78
+ /** The callers a push decides for: a queue's publish's every one, or its own. */
79
+ const decidingFor = (request) => request.queued?.callers ?? [request.caller];
80
+ /**
81
+ * Each caller's refusal, by its place, told to a queue's publish, which then fails with the first.
82
+ * A push for one caller refuses its refs one by one, in the decide: nothing is told or failed.
83
+ */
84
+ const refuseQueued = (request, refusals, by) => {
85
+ const { queued } = request;
86
+ if (queued === void 0) return Effect.void;
87
+ for (const [at, error] of refusals.entries()) if (error !== void 0) queued.refused(at, error, by);
88
+ const first = refusals.find((error) => error !== void 0);
89
+ return first === void 0 ? Effect.void : Effect.fail(first);
90
+ };
91
+ /** The edits `sight` refuses: each name its caller can't write, as for a name with no ref there. */
92
+ const unseenOf = (sight, edits) => new Map(sight.whole ? [] : edits.flatMap((edit) => (edit.from === null ? sight.creates(edit.ref) : sight.sees(edit.ref)) ? [] : [[edit.ref, unseenRef(edit.ref)]]));
93
+ /**
94
+ * One fence over `fences`, each caller's, in the push's final read: their reads together, and each
95
+ * check on its own results. A queue's publish hears every credential that ended, by its place.
96
+ */
97
+ const fenceAll = (request, fences) => {
98
+ const [only] = fences;
99
+ if (only !== void 0 && fences.length === 1) return only;
100
+ return {
101
+ reads: fences.flatMap((fence) => fence.reads),
102
+ check: Effect.fnUntraced(function* (results) {
103
+ const refusals = [];
104
+ let from = 0;
105
+ for (const fence of fences) {
106
+ const own = results.slice(from, from + fence.reads.length);
107
+ from += fence.reads.length;
108
+ const held = yield* Effect.result(fence.check(own));
109
+ const error = Result.isFailure(held) ? held.failure : void 0;
110
+ if (error !== void 0 && retriedCodes.has(error.code)) return yield* Effect.fail(error);
111
+ refusals.push(error);
112
+ }
113
+ return yield* refuseQueued(request, refusals, "access");
114
+ })
115
+ };
116
+ };
117
+ const moved = { queueMoved: true };
118
+ /** A queue's push whose repo moved past the version it planned at: `UNAVAILABLE`. */
119
+ const queueMoved = (repo) => gitError("UNAVAILABLE", `'${repo}' moved while its merge queue wrote`, {
120
+ hint: "Try again",
121
+ cause: moved
122
+ });
123
+ const atomicHint = "Another ref in this atomic push was refused";
124
+ /** A queue push's refused ref, the cause's before the rest's, so its writes commit with none. */
125
+ const refusalOf = (updated) => {
126
+ const refused = updated.updates.flatMap((update) => update.kind === "rejected" ? [update.error] : []);
127
+ return refused.find((error) => error.hint !== atomicHint) ?? refused[0];
128
+ };
129
+ /** Whether a push failed only since its repo moved past the queue's plan. */
130
+ const isQueueMoved = (error) => error.cause === moved;
131
+ /** `refs.update`'s answers: the decide's, kept as they are. */
132
+ const refsAnswers = {
133
+ answer: Effect.succeed,
134
+ kept: refsKept,
135
+ held: refsAnswer
136
+ };
137
+ /** No rule lifted on any ref. */
138
+ const none = /* @__PURE__ */ new Map();
139
+ /** Rules' names as a line reads them: `a`, `a and b`, `a, b and c`. */
140
+ const ruleList = (rules) => rules.length <= 1 ? rules.join("") : `${rules.slice(0, -1).join(", ")} and ${rules.at(-1)}`;
141
+ /** The lines a `git push` prints for the rules `authorize` lifted on the refs it moved. */
142
+ const bypassNotes = (updated, bypassed) => updated.updates.flatMap((update) => {
143
+ const rules = update.kind === "applied" ? bypassed.get(update.ref) ?? [] : [];
144
+ return rules.length === 0 ? [] : [`Bypassed ${ruleList(rules)} on ${update.ref}`];
145
+ });
146
+ /** A `git push`'s answers: unkeyed, so never kept or held but as `refs.update`'s are. */
147
+ const gitAnswers = {
148
+ answer: (updated, _, bypassed) => Effect.succeed({
149
+ updated,
150
+ notes: bypassNotes(updated, bypassed)
151
+ }),
152
+ kept: ({ updated }) => refsKept(updated),
153
+ held: (receipt) => Effect.map(refsAnswer(receipt), (updated) => ({
154
+ updated,
155
+ notes: []
156
+ }))
157
+ };
158
+ /**
159
+ * A commit's `pushed` times: one for the repo, or, with `access`, one for its public refs and one
160
+ * for each pattern whose refs it moved, so a hidden push moves no time its readers don't see.
161
+ */
162
+ const pushedRows = (access, moved, times, at) => {
163
+ if (moved.length === 0) return [];
164
+ if (access === void 0) return [timeRow(pushedKey, times.pushed, at)];
165
+ return [...new Set(moved.map((move) => access.patternOf(move.ref)))].map((pattern) => pattern === void 0 ? timeRow(pushedKey, times.pushed, at) : timeRow(pushedUnder(pattern), times.privately?.get(pattern), at));
166
+ };
167
+ /** The repo's `pruned` mark's ID, or `undefined` before its first prune drops anything. */
168
+ const markOf = (rows) => {
169
+ const [row] = rows;
170
+ return row === void 0 ? Effect.succeed(void 0) : Effect.map(decodeRow(PrunedMark, row, "The prune mark"), ({ id }) => id);
171
+ };
172
+ /**
173
+ * The first read: the repo, by name, once `authorize` lets the caller read it, with its packs and
174
+ * its `pruned` mark. A
175
+ * caller who can't read the repo gets the read's answer, as for a name with no repo, before a byte
176
+ * of the pack is read: only a caller who can read it is told a push is refused.
177
+ */
178
+ const firstRead = (core, caller, operation, internalId) => openRepo(core, caller, {
179
+ kind: "read",
180
+ repo: operation.repo
181
+ }, [packsRead, prunedKey], internalId);
182
+ /** `firstRead` for a keyed push: `undefined` once `missed`'s repo moved, as `openKeyed` says. */
183
+ const keyedRead = (core, caller, operation, missed, internalId) => openKeyed(core, caller, {
184
+ kind: "read",
185
+ repo: operation.repo
186
+ }, [packsRead, prunedKey], missed, internalId);
187
+ /**
188
+ * The first read's repo once `authorize` lets the caller push to it: its list, for the pack to be
189
+ * received against, its default branch, whose move rebuilds the ready shallow pack, and its
190
+ * `pruned` mark.
191
+ */
192
+ const listedFor = Effect.fnUntraced(function* (core, request, operation, resolved) {
193
+ const { caller, source } = request;
194
+ const repo = {
195
+ id: resolved.name,
196
+ public: resolved.record.public,
197
+ internalId: resolved.internalId
198
+ };
199
+ if (request.queued === void 0) yield* core.authorize({
200
+ caller,
201
+ operation,
202
+ repo
203
+ });
204
+ const packs = yield* decodePacks(resolved.snapshot.results[1] ?? []);
205
+ const listed = {
206
+ repo: resolved.internalId,
207
+ version: resolved.snapshot.version,
208
+ packs
209
+ };
210
+ const mark = yield* markOf(resolved.snapshot.results[2] ?? []);
211
+ const views = decidingFor(request).map((one) => viewOf(core, one, resolved, source));
212
+ const [view = viewOf(core, caller, resolved, source)] = views;
213
+ return {
214
+ listed,
215
+ defaultBranch: headOf(resolved.record.defaultBranch),
216
+ mark,
217
+ repo,
218
+ view,
219
+ views
220
+ };
221
+ });
222
+ /**
223
+ * The refs a push's objects follow, for its view: none read when the view's objects are whole, as
224
+ * for a caller who sees every ref of a repo that isn't a fork under `access`; else every ref the
225
+ * caller sees, read after `authorize` let the caller in, at a version of their own, which the
226
+ * push's objects read at too.
227
+ */
228
+ const seenRefsOf = Effect.fnUntraced(function* (core, view, listed) {
229
+ if (!(yield* view.narrowed)) return {
230
+ listed,
231
+ refs: /* @__PURE__ */ new Map()
232
+ };
233
+ const { snapshot } = yield* readRecord(core.store, listed.repo, [refsRead, packsRead]);
234
+ const packs = yield* decodePacks(snapshot.results[2] ?? []);
235
+ const refs = yield* view.refs(snapshot.results[1] ?? []);
236
+ return {
237
+ listed: {
238
+ ...listed,
239
+ version: snapshot.version,
240
+ packs
241
+ },
242
+ refs
243
+ };
244
+ });
245
+ /**
246
+ * The push's own objects, readable before the commit that lists them: the rows a receive puts,
247
+ * then its pack, read `listedOnly`, so nothing the repo held before is the push's: not its rows,
248
+ * not a pack it lists and not one it's letting go of (#547).
249
+ */
250
+ const pushedOf = (objects, listed, received) => {
251
+ if (received === void 0) return () => Effect.succeed(void 0);
252
+ const rows = receivedRows(received.change);
253
+ const own = {
254
+ ...listed,
255
+ packs: received.change.add ?? []
256
+ };
257
+ return (input) => {
258
+ const row = rows.get(input.oid);
259
+ if (row !== void 0) return Effect.map(objectOfRow(row), gitObjectOf);
260
+ return own.packs.length === 0 ? Effect.succeed(void 0) : objects.read(own, {
261
+ ...input,
262
+ listedOnly: true
263
+ });
264
+ };
265
+ };
266
+ /**
267
+ * Whether the push brings commit `oid`, for the file rules' walk: its own object, read as `pushed`
268
+ * reads one, its bytes let go unread. A read that fails throws, so the walk trusts nothing.
269
+ */
270
+ const broughtCommit = (pushed, scope) => async (oid) => {
271
+ const object = await runIn(Effect.mapError(pushed({ oid }), thrownError), scope);
272
+ await object?.bytes.cancel().catch(() => void 0);
273
+ return object?.type === "commit";
274
+ };
275
+ /** The refs the repo mirrors, among `rows` of `mirrors`: each one an active mirror names. */
276
+ const activeMirrors = Effect.fnUntraced(function* (rows) {
277
+ const active = /* @__PURE__ */ new Set();
278
+ for (const row of rows) if ((yield* decodeRow(MirrorRow, row, `Mirror '${row.id}'`)).state === "active") active.add(row.id);
279
+ return active;
280
+ });
281
+ /**
282
+ * `git.sync.mirror`'s row for each ref the commit moves that an active mirror names, found by
283
+ * name among the jobs the server knows: none until `syncJobs` has bound them.
284
+ */
285
+ const mirrorJobs = (core, moved, mirrored) => {
286
+ const definition = core.jobOf?.(mirrorJobName);
287
+ if (definition === void 0) return [];
288
+ return moved.flatMap(({ ref }) => mirrored.has(ref) ? [definition.job({
289
+ key: ref,
290
+ data: { ref }
291
+ })] : []);
292
+ };
293
+ /** The repo's stored packs and the received pack's, before the commit lists it: a push's changes read both. */
294
+ const withReceived = (listed, received) => received === void 0 ? listed : {
295
+ ...listed,
296
+ packs: [...listed.packs, ...received.change.add ?? []]
297
+ };
298
+ /** The objects, with the rows a receive puts read first: they're written only by the commit. */
299
+ const withReceivedRows = (objects, received) => {
300
+ const rows = receivedRows(received?.change);
301
+ if (rows.size === 0) return objects;
302
+ const rowsOf = (oids, each) => Effect.forEach(oids, (oid) => {
303
+ const row = rows.get(oid);
304
+ return row === void 0 ? Effect.void : Effect.flatMap(objectOfRow(row), each);
305
+ }, { discard: true });
306
+ return {
307
+ ...objects,
308
+ read: (listed, input) => {
309
+ const row = rows.get(input.oid);
310
+ return row === void 0 ? objects.read(listed, input) : Effect.map(objectOfRow(row), gitObjectOf);
311
+ },
312
+ objects: (listed, input) => Effect.gen(function* () {
313
+ const asked = [...new Set(input.oids)];
314
+ const [first] = asked;
315
+ if (first === void 0 || !asked.some((oid) => rows.has(oid))) return yield* objects.objects(listed, {
316
+ ...input,
317
+ oids: asked
318
+ });
319
+ const fromRows = rows.has(first);
320
+ const own = asked.filter((oid) => rows.has(oid) === fromRows);
321
+ const answered = fromRows ? yield* allottedRows(rowsOf, own, input.bytes) : yield* objects.objects(listed, {
322
+ ...input,
323
+ oids: own
324
+ });
325
+ const left = /* @__PURE__ */ new Set([...answered.left, ...asked.filter((oid) => rows.has(oid) !== fromRows)]);
326
+ return {
327
+ objects: answered.objects,
328
+ left: asked.filter((oid) => left.has(oid))
329
+ };
330
+ })
331
+ };
332
+ };
333
+ /**
334
+ * The decide's read, one of the repo's scope: its refs, its outbox, the push's own `quarantine` row
335
+ * if it has one, its key's receipt if it has a key, the queue's row of each branch in `branches`,
336
+ * with the live reservation each holds, and the caller's grant fence, checked on what it read. A revoke after it moves the version, as
337
+ * does a write with the same key that commits first. A prune that dropped objects since the first
338
+ * read moved the `pruned` mark: the push may name one it dropped, so unless its key's receipt
339
+ * answers, it fails, to be sent again (Q270).
340
+ */
341
+ const finalRead = Effect.fnUntraced(function* (store, repo, fence, received, kept, mark, branches) {
342
+ const own = received?.quarantine === void 0 ? [] : [received.quarantine];
343
+ const keyed = receiptReads(kept);
344
+ const targets = branches.map((id) => ({
345
+ collection: collections.queueTargets,
346
+ id
347
+ }));
348
+ const linkedRows = received?.linked?.rows ?? [];
349
+ const rowCounts = linkedRows.map((oid) => ({
350
+ collection: objectCollections.objects,
351
+ prefix: oid
352
+ }));
353
+ const { record, snapshot } = yield* readRecord(store, repo.internalId, [
354
+ refsRead,
355
+ mirrorsRead,
356
+ ...outboxReads,
357
+ packsRead,
358
+ prunedKey,
359
+ timesRead,
360
+ cruftRead,
361
+ indexRowKey,
362
+ ...own,
363
+ ...keyed,
364
+ ...targets,
365
+ ...fence.reads
366
+ ], rowCounts);
367
+ if (record === void 0 || record.deleted === true) return yield* fail("NOT_FOUND", `No repo '${repo.name}'`);
368
+ const [, refRows = [], mirrorRows = [], headRows = [], cursorRows = [], packRows = [], ...more] = snapshot.results;
369
+ const [markRows = [], timeRows = [], cruftRows = [], indexRows = [], ...rest] = more;
370
+ const receipt = yield* heldReceipt(rest.slice(own.length, own.length + keyed.length), kept);
371
+ if (receipt === void 0 && (yield* markOf(markRows)) !== mark) return yield* fail("UNAVAILABLE", "The repo was pruned during the push", { hint: "Push again" });
372
+ const targeted = rest.slice(own.length + keyed.length, own.length + keyed.length + targets.length);
373
+ const queued = new Set(branches.filter((_, index) => (targeted[index] ?? []).length > 0));
374
+ const live = yield* liveReservations(store, targeted);
375
+ const reserved = new Map(branches.flatMap((branch, index) => {
376
+ const reservation = live[index];
377
+ return reservation === void 0 ? [] : [[branch, reservedTarget(branch, reservation)]];
378
+ }));
379
+ const fenced = rest.slice(own.length + keyed.length + targets.length);
380
+ const packs = yield* decodePacks(packRows);
381
+ const times = yield* decodeTimes(timeRows);
382
+ const [ownRow] = own.length === 0 ? [] : rest[0] ?? [];
383
+ const refs = yield* wholeRefs(pushWhole, refRows);
384
+ const outbox = yield* decodeOutbox([headRows, cursorRows]);
385
+ const held = ownRow === void 0 ? void 0 : yield* decodeHeld(QuarantineRow, ownRow);
386
+ const mirrored = yield* activeMirrors(mirrorRows);
387
+ const revoked = yield* Effect.match(fence.check(fenced), {
388
+ onFailure: (error) => error,
389
+ onSuccess: () => void 0
390
+ });
391
+ const read = {
392
+ version: snapshot.version,
393
+ refs,
394
+ head: headOf(record.defaultBranch)
395
+ };
396
+ const at = {
397
+ repo: repo.internalId,
398
+ version: snapshot.version,
399
+ packs
400
+ };
401
+ if (held !== void 0) read.quarantine = held.value.state;
402
+ if (revoked !== void 0) read.revoked = revoked;
403
+ if (cruftRows.length <= 64) read.packs = {
404
+ listed: new Set(packs.map(({ id }) => id)),
405
+ cruft: new Set(cruftRows.map(({ id }) => id)),
406
+ rows: new Set(linkedRows.filter((_, at) => (snapshot.counts[at] ?? 0) > 0))
407
+ };
408
+ const facts = {
409
+ settings: settingsOf(record),
410
+ tips: /* @__PURE__ */ new Map(),
411
+ revoked: revoked !== void 0
412
+ };
413
+ const stats = repoStats(record, refs.size, packs, times);
414
+ const [indexRow] = indexRows;
415
+ return {
416
+ read,
417
+ at,
418
+ receipt,
419
+ outbox,
420
+ record,
421
+ mirrored,
422
+ facts,
423
+ stats,
424
+ times,
425
+ queued,
426
+ reserved,
427
+ indexRow
428
+ };
429
+ });
430
+ const settingsOf = (record) => ({
431
+ name: record.name,
432
+ public: record.public,
433
+ defaultBranch: record.defaultBranch
434
+ });
435
+ /** `objects`' batches as the engine's `ReadObjects`, over `listed`, each run in `scope`. */
436
+ const batchOf = (objects, listed, scope) => (input) => runIn(Effect.match(objects.objects(listed, input), {
437
+ onSuccess: (value) => ({
438
+ kind: "success",
439
+ value
440
+ }),
441
+ onFailure: (error) => ({
442
+ kind: "error",
443
+ error
444
+ })
445
+ }), scope);
446
+ /** `objects`' reads as the engine's `ReadObject`, over `listed`, each run in `scope`. */
447
+ const readerOf = (objects, listed, scope) => (input) => runIn(Effect.match(objects.read(listed, input), {
448
+ onSuccess: (value) => ({
449
+ kind: "success",
450
+ value
451
+ }),
452
+ onFailure: (error) => ({
453
+ kind: "error",
454
+ error
455
+ })
456
+ }), scope);
457
+ /** The rules, then `hooks.preReceive`, once, at the first read the push decides on. */
458
+ const runChecks = Effect.fnUntraced(function* (checks, input, facts) {
459
+ const context = checking(input);
460
+ const ruled = yield* builtInAfter(checks, input, yield* runPushRules(checks, input, context));
461
+ const whole = yield* runPreReceive(checks.reports, checks.preReceive, context, {
462
+ atomic: input.atomic,
463
+ updates: ruled.updates,
464
+ refused: ruled.refused
465
+ });
466
+ const checked = {
467
+ facts,
468
+ updates: ruled.updates,
469
+ refused: ruled.refused,
470
+ filesAllowed: ruled.filesAllowed,
471
+ bypassed: ruled.bypassed
472
+ };
473
+ if (whole !== void 0) checked.whole = whole;
474
+ return checked;
475
+ });
476
+ /**
477
+ * The checks for every caller the push decides for: `runChecks` once for a push's own caller, and
478
+ * for a queue's publish once for each, as itself, with its own `authorize`. A caller a rule or the
479
+ * hook refuses, on a ref none refused before, is told by its place, and the push fails. Passed, the
480
+ * answer is the first caller's, with the files allowed and the rules lifted for any of them.
481
+ */
482
+ const checkAll = Effect.fnUntraced(function* (checks, request, input, facts, authorizeAs) {
483
+ if (request.queued === void 0) return yield* runChecks(checks, input, facts);
484
+ const each = [];
485
+ for (const caller of request.queued.callers) each.push(yield* runChecks(checks, {
486
+ ...input,
487
+ caller,
488
+ authorize: authorizeAs(caller)
489
+ }, facts));
490
+ const refusals = each.map((one) => one.whole ?? [...one.refused].find(([ref]) => !input.refused.has(ref))?.[1]);
491
+ const retried = refusals.find((error) => error !== void 0 && retriedCodes.has(error.code));
492
+ if (retried !== void 0) return yield* Effect.fail(retried);
493
+ yield* refuseQueued(request, refusals, "rules");
494
+ const union = (pick) => {
495
+ const merged = /* @__PURE__ */ new Map();
496
+ for (const one of each) for (const [ref, names] of pick(one)) {
497
+ const kept = merged.get(ref) ?? [];
498
+ for (const name of names) if (!kept.includes(name)) kept.push(name);
499
+ merged.set(ref, kept);
500
+ }
501
+ return merged;
502
+ };
503
+ const [first] = each;
504
+ if (first === void 0) return yield* fail("INTERNAL", "A queued publish names no caller");
505
+ return {
506
+ ...first,
507
+ filesAllowed: union((one) => one.filesAllowed),
508
+ bypassed: union((one) => one.bypassed)
509
+ };
510
+ });
511
+ /** The rules' answer, with each ref the server's built-in check refuses among the rest. */
512
+ const builtInAfter = Effect.fnUntraced(function* (checks, input, ruled) {
513
+ const { builtIn } = checks;
514
+ if (builtIn === void 0) return ruled;
515
+ const refused = yield* builtIn({
516
+ updates: ruled.updates.filter((update) => !ruled.refused.has(update.ref)),
517
+ objects: input.objects
518
+ });
519
+ return {
520
+ ...ruled,
521
+ refused: new Map([...ruled.refused, ...refused])
522
+ };
523
+ });
524
+ /** Whether a push has anything to check: a rule, the built-in check, or `hooks.preReceive`. */
525
+ const checksOf = (core) => {
526
+ const { checks } = core;
527
+ if (checks === void 0) return void 0;
528
+ return checks.rules().length > 0 || checks.preReceive !== void 0 || checks.builtIn !== void 0 ? checks : void 0;
529
+ };
530
+ /**
531
+ * The repo's objects with the push's own, for the built-in check: `objects` and `listed` read
532
+ * both, and `received` is the push's alone.
533
+ */
534
+ const pushedObjectsOf = (objects, listed, received, own) => {
535
+ return {
536
+ repo: listed.repo,
537
+ read: (oid) => objects.read(listed, { oid }),
538
+ peeled: (oid) => peeledOf(objects, listed, oid),
539
+ pushed: (oid) => own({ oid }),
540
+ lfsPointers: received?.lfsPointers ?? noLfsPointers
541
+ };
542
+ };
543
+ /**
544
+ * What a decision commits: its writes and jobs at `expect`, or, for an answer that moves no ref,
545
+ * nothing, which a keyed write's receipt still commits at the read's version. A refusal fails.
546
+ */
547
+ const planOf = (decision, version, jobs) => {
548
+ if (decision.kind === "commit") return Effect.succeed({
549
+ ...decision,
550
+ jobs,
551
+ moves: true
552
+ });
553
+ const { answer } = decision;
554
+ if (answer.kind === "error") return Effect.fail(answer.error);
555
+ return Effect.succeed({
556
+ answer: answer.value,
557
+ expect: version,
558
+ change: {
559
+ put: [],
560
+ delete: []
561
+ },
562
+ jobs: [],
563
+ moves: false,
564
+ moved: []
565
+ });
566
+ };
567
+ /**
568
+ * Each force among `kinds.updates` that its exact walk agrees is one, as a `diverged` refusal in
569
+ * `diverged`, or the walk's own error past its bound in `refused`.
570
+ */
571
+ const divergedOf = Effect.fnUntraced(function* (kinds) {
572
+ const refused = /* @__PURE__ */ new Map();
573
+ const diverged = /* @__PURE__ */ new Map();
574
+ for (const update of kinds.updates) {
575
+ if (update.kind !== "force" || kinds.refused.has(update.ref)) continue;
576
+ const exact = yield* Effect.result(kinds.exact(update));
577
+ if (Result.isFailure(exact)) refused.set(update.ref, exact.failure);
578
+ else if (exact.success === "force" && update.to !== null) {
579
+ const tip = update.to;
580
+ const message = `'${update.ref}' holds commits the fetched tip ${tip} doesn't`;
581
+ const hint = `Merge or rebase onto ${tip}, or fetch with force to move it there anyway`;
582
+ diverged.set(update.ref, gitError("FAILED_PRECONDITION", message, {
583
+ hint,
584
+ context: {
585
+ reason: "diverged",
586
+ tip
587
+ }
588
+ }));
589
+ }
590
+ }
591
+ return {
592
+ refused,
593
+ diverged
594
+ };
595
+ });
596
+ /**
597
+ * What the checks refused, and for a fetch, each diverged ref: refused, or with `force`, among
598
+ * `forced`.
599
+ */
600
+ const fetchedRefused = Effect.fnUntraced(function* (kinds, request) {
601
+ const { fetched } = request;
602
+ if (fetched === void 0) return {
603
+ refused: kinds.refused,
604
+ forced: /* @__PURE__ */ new Set()
605
+ };
606
+ const { refused, diverged } = yield* divergedOf(kinds);
607
+ const forced = new Set(fetched.force ? diverged.keys() : []);
608
+ const unforced = fetched.force ? [] : diverged;
609
+ return {
610
+ refused: new Map([
611
+ ...kinds.refused,
612
+ ...refused,
613
+ ...unforced
614
+ ]),
615
+ forced
616
+ };
617
+ });
618
+ /**
619
+ * A commit the store refuses as too large, before it applies any write, for a `loose()` push whose
620
+ * objects are rows of it: its objects fit `loose()`'s limits, but not beside the push's own
621
+ * writes. It gets the hint those limits give. A refusal the push's own writes earn alone, as a
622
+ * saved push of many long ref names, keeps the store's message: fewer objects wouldn't help it.
623
+ * So does `packs()`'s, whose small pushes are rows too: it's on `packs()` already. `loose()` is
624
+ * known by the quarantine it received, so a wrapper that passes it on, as Git's HTTP does, keeps it.
625
+ */
626
+ const commitTooLarge = (received, body) => (error) => {
627
+ const rows = received?.change.put ?? [];
628
+ if (received === void 0 || !isLoose(received) || rows.length === 0) return error;
629
+ if (error.code !== "RESOURCE_EXHAUSTED" || error.context?.reason !== "too-large") return error;
630
+ const keys = new Set(rows.map((row) => `${row.collection}\0${row.id}`));
631
+ const own = (body.put ?? []).filter((row) => !keys.has(`${row.collection}\0${row.id}`));
632
+ if (!fits({
633
+ ...body,
634
+ put: own
635
+ })) return error;
636
+ return gitError("RESOURCE_EXHAUSTED", `push's objects don't fit one commit: ${error.message}`, {
637
+ cause: error,
638
+ hint: "Push fewer objects at a time",
639
+ hostHint: "Use packs() storage, which keeps a push's objects in the bucket",
640
+ context: { reason: "too-large" }
641
+ });
642
+ };
643
+ /** Whether the store's own limits take `change`, as its commit checks them. */
644
+ const fits = (change) => {
645
+ try {
646
+ checkWrites(change);
647
+ return true;
648
+ } catch {
649
+ return false;
650
+ }
651
+ };
652
+ /** The request's pack into its quarantine, or `undefined` for a push with none. */
653
+ const receive = (objects, listed, request) => {
654
+ const { pack, shallow, signal } = request;
655
+ if (pack === void 0) return Effect.succeed({
656
+ received: void 0,
657
+ rooted: void 0
658
+ });
659
+ const input = {
660
+ pack: pack.bytes,
661
+ objects: pack.objects
662
+ };
663
+ if (pack.length !== void 0) input.length = pack.length;
664
+ if (pack.atMost !== void 0) input.atMost = pack.atMost;
665
+ if (shallow !== void 0 && shallow.length > 0) input.shallow = shallow;
666
+ if (signal !== void 0) input.signal = signal;
667
+ if (pack.partial === true) input.partial = true;
668
+ return scopedReceive(objects, listed, input).pipe(Effect.map((received) => ({
669
+ received,
670
+ rooted: void 0
671
+ })), Effect.catchIf(isShallowRoot, (rooted) => Effect.succeed({
672
+ received: void 0,
673
+ rooted
674
+ })));
675
+ };
676
+ /** `ref.updated`'s `push`: the write, how many branches and tags it moved (Q222), and its source. */
677
+ const pushOf = (id, moved, source) => {
678
+ const under = (prefix) => moved.filter((move) => move.ref.startsWith(prefix)).length;
679
+ return {
680
+ id,
681
+ branches: under("refs/heads/"),
682
+ tags: under("refs/tags/"),
683
+ source
684
+ };
685
+ };
686
+ /**
687
+ * What a push's commit saves for `hooks.postReceive`, when the host passed one: the push, with
688
+ * the refs it moved and their kinds, at the version the commit makes, and the repo's
689
+ * `git.post-receive` row. Its ID is the commit's own.
690
+ */
691
+ const savedPush = (checks, push) => {
692
+ const jobRow = checks?.postReceiveJobRow;
693
+ if (jobRow === void 0 || push.moved.length === 0) return {
694
+ put: [],
695
+ jobs: []
696
+ };
697
+ const kinds = new Map(push.updates.map((update) => [update.ref, update.kind]));
698
+ const updates = push.moved.map((move) => ({
699
+ ...move,
700
+ kind: kinds.get(move.ref) ?? "force"
701
+ }));
702
+ const { pushOptions, source } = push.request;
703
+ const saved = {
704
+ pushId: push.id,
705
+ repo: push.name,
706
+ caller: push.caller,
707
+ source,
708
+ updates
709
+ };
710
+ if (pushOptions !== void 0) saved.pushOptions = pushOptions;
711
+ return {
712
+ put: [savedPushRow(push.version, saved)],
713
+ jobs: [jobRow()]
714
+ };
715
+ };
716
+ /**
717
+ * The push decide's loop past its first read, onto `listed`, keeping its answer under `key`:
718
+ * the pack received into its quarantine; each edit's kind from the objects; then a read of the
719
+ * refs, the push's `quarantine` row and the caller's fence; a held receipt's answer; the rules and
720
+ * `preReceive`, for a write that moves a ref; the pure decide, and one commit at that read's
721
+ * version, with the ref moves, the receipt, the events and the push `hooks.postReceive` owes.
722
+ * `answers` says what the call answers and keeps.
723
+ */
724
+ const pushOnto = (core, request, { listed, defaultBranch, mark, repo: checkedRepo, view, views }, key, answers) => Effect.scoped(Effect.gen(function* () {
725
+ const { store } = core;
726
+ const { caller, repo, signal } = request;
727
+ const call = signal === void 0 ? {} : { signal };
728
+ const seen = yield* seenRefsOf(core, view, listed);
729
+ const { received, rooted } = yield* receive(yield* view.objectsAt(seen), listed, request);
730
+ const viewed = received === void 0 ? seen : {
731
+ ...seen,
732
+ pushed: received
733
+ };
734
+ const objects = yield* walkObjects(effectObjects(yield* view.objectsAt(viewed)), received?.allotment);
735
+ const pushedObjects = withReceivedRows(objects, received);
736
+ const pushedListed = withReceived(listed, received);
737
+ const pushed = pushedOf(objects, listed, received);
738
+ const kindsInput = {
739
+ objects: pushedObjects,
740
+ listed: pushedListed,
741
+ pushed,
742
+ edits: request.edits,
743
+ ...call
744
+ };
745
+ if (rooted !== void 0) kindsInput.missing = rooted;
746
+ const kinds = yield* kindsOf(kindsInput);
747
+ const fetchedOff = yield* fetchedRefused(kinds, request);
748
+ const { forced } = fetchedOff;
749
+ const refused = new Map(fetchedOff.refused);
750
+ for (const update of kinds.updates) {
751
+ const own = gitsOwnRef(update.ref, request.source);
752
+ if (own !== void 0 && !refused.has(update.ref)) refused.set(update.ref, own);
753
+ }
754
+ const sights = yield* Effect.forEach(views, (one) => one.sight);
755
+ const unseens = sights.map((sight) => unseenOf(sight, request.edits));
756
+ yield* refuseQueued(request, unseens.map((one) => one.values().next().value), "access");
757
+ const unseen = unseens[0] ?? /* @__PURE__ */ new Map();
758
+ const { updates } = kinds;
759
+ for (const [ref, error] of unseen) refused.set(ref, error);
760
+ const { access } = core;
761
+ const barred = access?.patterns.some((pattern) => sights.some((sight) => !publishable(sight, pattern))) === true;
762
+ const whole = effectObjects(SealedObjects.whole(core.objects, pushWhole));
763
+ const wholePushed = access === void 0 || !barred && request.publishes === void 0 ? void 0 : withReceivedRows(yield* walkObjects(whole, received?.allotment), received);
764
+ const sight = sights[0] ?? (yield* view.sight);
765
+ const publishedRefs = (refs) => new Map([...refs].filter(([ref]) => hiddenUnder(ref) === void 0));
766
+ const writer = access === void 0 ? void 0 : yield* ownWriter(caller);
767
+ const made = new Set(request.own);
768
+ const ownOf = writer === void 0 ? void 0 : (oids) => {
769
+ const here = oids.filter((oid) => made.has(oid));
770
+ const stored = oids.filter((oid) => !made.has(oid));
771
+ if (stored.length === 0) return Effect.succeed(new Set(here));
772
+ return Effect.map(Effect.flatMap(core.now, (now) => ownWritesOf(core.store, listed.repo, writer, stored, now)), (kept) => /* @__PURE__ */ new Set([...here, ...kept]));
773
+ };
774
+ const unpublishedAt = (refs, at, judging, edits, own) => access === void 0 || wholePushed === void 0 ? Effect.succeed(/* @__PURE__ */ new Map()) : unpublished({
775
+ access,
776
+ sight: judging,
777
+ refs: publishedRefs(refs),
778
+ objects: whole,
779
+ listed: at,
780
+ pushed: wholePushed,
781
+ pushedListed: withReceived(at, received),
782
+ edits,
783
+ own,
784
+ ...call
785
+ });
786
+ const headsOf = (edit) => edit.to === null ? void 0 : request.publishes?.get(edit.ref);
787
+ const publishedAt = (refs, at) => Effect.gen(function* () {
788
+ const plain = request.edits.filter((edit) => headsOf(edit) === void 0);
789
+ const refused = new Map(yield* unpublishedAt(refs, at, sight, plain, ownOf));
790
+ for (const edit of request.edits) {
791
+ const heads = headsOf(edit);
792
+ if (heads === void 0) continue;
793
+ if (heads.length === 0) {
794
+ refused.set(edit.ref, noHeadJudged(edit.ref));
795
+ continue;
796
+ }
797
+ const failed = [];
798
+ for (const { entry, head, caller: its } of heads) {
799
+ const judging = yield* sightIn(core, its, checkedRepo);
800
+ if ((yield* unpublishedAt(refs, at, judging, [{
801
+ ...edit,
802
+ to: head
803
+ }])).has(edit.ref)) failed.push(entry);
804
+ }
805
+ if (failed.length > 0) refused.set(edit.ref, entriesUnpublishable(edit.ref, failed));
806
+ }
807
+ return refused;
808
+ });
809
+ const command = {
810
+ source: request.source,
811
+ updates,
812
+ atomic: request.atomic,
813
+ refused
814
+ };
815
+ if (received !== void 0) command.received = received;
816
+ const target = {
817
+ internalId: listed.repo,
818
+ name: repo
819
+ };
820
+ const fence = fenceAll(request, decidingFor(request).map((one) => core.fences(one, target)));
821
+ const ready = objects.readyShallow && request.edits.some((edit) => edit.ref === defaultBranch || edit.ref.startsWith("refs/tags/"));
822
+ const jobs = (received?.change.add?.length ?? 0) > 0 || ready ? [core.repackJobRow()] : [];
823
+ const own = updates.filter((update) => gitsOwnMove(request.source, update.ref));
824
+ const outside = updates.filter((update) => !gitsOwnMove(request.source, update.ref));
825
+ const checks = outside.length === 0 ? void 0 : checksOf(core);
826
+ const branches = request.source === "queue" ? [] : outside.map((update) => update.ref).filter((ref) => ref.startsWith("refs/heads/"));
827
+ const scope = yield* callScope;
828
+ const reader = readerOf(pushedObjects, pushedListed, scope);
829
+ const batch = batchOf(pushedObjects, pushedListed, scope);
830
+ const unaborted = signal ?? new AbortController().signal;
831
+ const base = {
832
+ caller,
833
+ repo,
834
+ source: request.source,
835
+ atomic: request.atomic,
836
+ ...call,
837
+ push: {
838
+ bytes: received?.bytes ?? 0,
839
+ objects: received?.objects ?? 0
840
+ },
841
+ exact: kinds.exact,
842
+ scope,
843
+ changes: (updates) => changesOf(reader, updates, unaborted, batch),
844
+ objects: pushedObjectsOf(pushedObjects, pushedListed, received, pushed),
845
+ authorize: (operation) => core.authorize({
846
+ caller,
847
+ operation,
848
+ repo: checkedRepo
849
+ })
850
+ };
851
+ const changing = {
852
+ objects,
853
+ listed,
854
+ received,
855
+ read: reader,
856
+ batch,
857
+ source: request.source,
858
+ allotment: received?.allotment,
859
+ readerAllotment: pushedObjects.allotment(pushedListed, openTreeBytes, openTreesRefusal),
860
+ brought: broughtCommit(pushed, scope),
861
+ scope
862
+ };
863
+ if (request.pushOptions !== void 0) base.pushOptions = request.pushOptions;
864
+ if (request.request !== void 0) base.request = request.request;
865
+ let checked;
866
+ for (let tries = 0; tries < 10; tries += 1) {
867
+ const at = yield* core.now;
868
+ const decide = yield* finalRead(store, target, fence, received, key, mark, branches);
869
+ const { read, receipt, outbox, record, mirrored, facts, stats, times, queued, reserved, indexRow } = decide;
870
+ const indexed = SealedObjects.whole(core.objects, pushWhole).index?.status(indexRow, at);
871
+ if (receipt !== void 0) return yield* answers.held(receipt);
872
+ const published = yield* publishedAt(read.refs, decide.at);
873
+ const { writes } = request;
874
+ if (writes !== void 0 && read.version !== writes.version) return yield* Effect.fail(queueMoved(repo));
875
+ const seen = {
876
+ ...facts,
877
+ tips: tipsOf(read.refs, outside)
878
+ };
879
+ if (checks !== void 0 && checked === void 0 && read.revoked === void 0) {
880
+ const input = {
881
+ ...base,
882
+ updates: outside,
883
+ refused: new Map([
884
+ ...published,
885
+ ...refused,
886
+ ...reserved,
887
+ ...unseen
888
+ ]),
889
+ stats,
890
+ commitChanges: (updates, by) => {
891
+ const judging = {
892
+ ...changing,
893
+ signal: unaborted
894
+ };
895
+ if (by !== void 0) judging.covered = coveredTips(read.refs, by.covers);
896
+ if (by !== void 0) judging.refuses = by.refuses;
897
+ if (by?.covers(read.head) === true) judging.defaultTip = read.refs.get(read.head);
898
+ return commitChangesOf(judging, updates);
899
+ }
900
+ };
901
+ checked = yield* checkAll(checks, request, input, seen, (one) => (operation) => core.authorize({
902
+ caller: one,
903
+ operation,
904
+ repo: checkedRepo
905
+ }));
906
+ } else if (checked !== void 0 && !factsHeld(checked.facts, seen)) return yield* Effect.fail(changedWhileChecked());
907
+ if (checked?.whole !== void 0) return yield* Effect.fail(checked.whole);
908
+ const decided = checked === void 0 ? {
909
+ ...command,
910
+ refused: new Map([
911
+ ...published,
912
+ ...refused,
913
+ ...reserved,
914
+ ...unseen
915
+ ])
916
+ } : {
917
+ ...command,
918
+ updates: [...checked.updates, ...own],
919
+ refused: new Map([
920
+ ...published,
921
+ ...checked.refused,
922
+ ...reserved,
923
+ ...unseen
924
+ ])
925
+ };
926
+ const planned = yield* planOf(decidePush({
927
+ read,
928
+ command: decided
929
+ }), read.version, jobs);
930
+ const { change } = planned;
931
+ const refusal = writes === void 0 ? void 0 : refusalOf(planned.answer);
932
+ if (refusal !== void 0) return yield* Effect.fail(refusal);
933
+ const movedRefs = new Set(planned.moved.map((move) => move.ref));
934
+ const liftedOnMoves = [...checked?.bypassed ?? none].filter(([ref]) => movedRefs.has(ref));
935
+ const answer = yield* answers.answer(planned.answer, forced, new Map(liftedOnMoves));
936
+ const also = planned.answer.updates.some((update) => update.kind === "rejected") || request.also === void 0 ? void 0 : request.also(yield* core.now);
937
+ const quiet = key === void 0 && (also?.put.length ?? 0) === 0 && writes === void 0;
938
+ if (!planned.moves && quiet) return answer;
939
+ const scope = repoScope(listed.repo);
940
+ const { name } = record;
941
+ const settling = {
942
+ version: read.version,
943
+ head: outbox.head,
944
+ record
945
+ };
946
+ if (yield* settleName(store, scope, settling)) continue;
947
+ const envelope = repoEnvelope(caller, name);
948
+ const id = newChangeId();
949
+ const shown = planned.moved.filter((move) => !gitsOwnMove(request.source, move.ref));
950
+ const push = pushOf(id, shown, request.source);
951
+ const events = shown.map((move) => {
952
+ const updated = {
953
+ type: "ref.updated",
954
+ ...envelope,
955
+ ...move,
956
+ push
957
+ };
958
+ const allowed = checked?.filesAllowed.get(move.ref);
959
+ if (allowed !== void 0) updated.filesAllowed = allowed;
960
+ const lifted = checked?.bypassed.get(move.ref);
961
+ if (lifted !== void 0) updated.bypassed = lifted;
962
+ return updated;
963
+ });
964
+ const first = firstSeq(outbox, {}) + events.length;
965
+ events.push(...writes?.events(envelope, first) ?? []);
966
+ const appended = yield* appendEvents(core.events, outbox, events, {
967
+ scope,
968
+ at
969
+ });
970
+ const final = answers.committed?.(answer, appended.head.next - 1) ?? answer;
971
+ const kept = receiptWrites(key, answers.kept(final), core.repackJobRow);
972
+ const saved = savedPush(core.checks, {
973
+ id,
974
+ version: planned.expect + 1,
975
+ caller,
976
+ name,
977
+ request,
978
+ updates: decided.updates,
979
+ moved: shown
980
+ });
981
+ const woken = shown.filter((move) => queued.has(move.ref)).map((move) => advanceRow(move.ref));
982
+ const pushed = pushedRows(core.access, shown, times, at);
983
+ const body = {
984
+ id,
985
+ expect: planned.expect,
986
+ put: [
987
+ ...change.put,
988
+ ...pushed,
989
+ ...kept.put,
990
+ ...also?.put ?? [],
991
+ ...appended.put,
992
+ ...saved.put,
993
+ ...writes?.put ?? []
994
+ ],
995
+ delete: [
996
+ ...change.delete,
997
+ ...appended.delete,
998
+ ...writes?.delete ?? []
999
+ ],
1000
+ jobs: withJobs([
1001
+ ...planned.jobs,
1002
+ ...appended.jobs,
1003
+ ...saved.jobs,
1004
+ ...mirrorJobs(core, planned.moved, mirrored),
1005
+ ...writes?.jobs ?? [],
1006
+ ...woken,
1007
+ ...shown.length > 0 ? indexJobs(core, indexed) : []
1008
+ ], [...kept.jobs, ...also?.jobs ?? []])
1009
+ };
1010
+ if ((yield* storeCall(() => store.commit(scope, body)).pipe(Effect.mapError(commitTooLarge(received, body)))).ok) return final;
1011
+ }
1012
+ return yield* fail("UNAVAILABLE", `Other writes kept moving '${repo}' through 10 tries`, { hint: "Push again" });
1013
+ }));
1014
+ const operationOf = ({ repo, edits }) => edits.length === 0 ? {
1015
+ kind: "object.create",
1016
+ repo
1017
+ } : {
1018
+ kind: "push",
1019
+ repo,
1020
+ updates: edits
1021
+ };
1022
+ /**
1023
+ * The push decide's loop. One read of the repo and its packs; `authorize` of the ref edits, or of
1024
+ * creating objects for a write that names no ref; then `pushOnto`. A commit another write beat
1025
+ * reads and decides again. A push cut before its commit leaves an unlisted pack for clean-up, and
1026
+ * no ref moved.
1027
+ */
1028
+ const pushWith = (core, request, answers, key) => Effect.gen(function* () {
1029
+ const operation = operationOf(request);
1030
+ const resolved = yield* firstRead(core, request.caller, operation, request.internalId).pipe(Effect.tapError((error) => retriedCodes.has(error.code) ? Effect.void : refuseQueued(request, [error], "access")));
1031
+ const opened = yield* listedFor(core, request, operation, resolved);
1032
+ return yield* pushOnto(core, request, opened, key, answers);
1033
+ });
1034
+ /** A push or an unkeyed `refs.update`, answering the decide's ref answer. */
1035
+ const push = (core, request) => pushWith(core, request, refsAnswers);
1036
+ /** A `git push`, as `push`, with the lines Git prints for the rules `authorize` lifted. */
1037
+ const gitPush = (core, request) => pushWith(core, request, gitAnswers);
1038
+ /** A ref a forced fetch moved past its diverged tip, answered `force`; the rest as they are. */
1039
+ const forcedOf = (forced) => (update) => update.kind === "applied" && forced.has(update.ref) ? {
1040
+ kind: "force",
1041
+ ref: update.ref
1042
+ } : update;
1043
+ /** A forced ref kept as applied, as `refs.update` answers it. */
1044
+ const appliedOf = (update) => update.kind === "force" ? {
1045
+ kind: "applied",
1046
+ ref: update.ref
1047
+ } : update;
1048
+ /**
1049
+ * A client's fetch into its own refs, as `push`, each diverged ref a forced fetch moved answered
1050
+ * `force`. Its refs move in one commit, so a fetch stopped before it moves none.
1051
+ */
1052
+ const pushFetched = (core, request) => pushWith(core, request, {
1053
+ answer: (updated, forced) => Effect.succeed(updated.updates.map(forcedOf(forced))),
1054
+ kept: (updates) => refsKept({ updates: updates.map(appliedOf) }),
1055
+ held: (receipt) => Effect.map(refsAnswer(receipt), (held) => held.updates)
1056
+ });
1057
+ /**
1058
+ * `pushWith` for a write's key, which keeps its answer. `undefined`, with nothing written or
1059
+ * asked of `authorize`, when the name holds a repo other than the one its key's lookup saw.
1060
+ */
1061
+ const keyedPushWith = (core, request, answers, keyed) => Effect.gen(function* () {
1062
+ const operation = operationOf(request);
1063
+ const resolved = yield* keyedRead(core, request.caller, operation, keyed.missed, request.internalId);
1064
+ if (resolved === void 0) return void 0;
1065
+ const opened = yield* listedFor(core, request, operation, resolved);
1066
+ return yield* pushOnto(core, request, opened, keyed.key, answers);
1067
+ });
1068
+ /** `keyedPushWith` for `refs.update`, answering the decide's ref answer. */
1069
+ const keyedPush = (core, request, keyed) => keyedPushWith(core, request, refsAnswers, keyed);
1070
+ export { gitPush, isQueueMoved, keyedPush, keyedPushWith, push, pushFetched, pushWith, retriedCodes };