@ref0/git 0.12.0 → 0.20.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 (436) hide show
  1. package/dist/access/private-refs.mjs +3 -3
  2. package/dist/auth/access-jwt.mjs +2 -2
  3. package/dist/auth/auth.d.mts +2 -2
  4. package/dist/auth/auth.mjs +3 -6
  5. package/dist/auth/authorize.mjs +4 -20
  6. package/dist/auth/fences.d.mts +1 -2
  7. package/dist/auth/fences.mjs +3 -3
  8. package/dist/auth/grants.mjs +4 -4
  9. package/dist/auth/helpers.mjs +3 -11
  10. package/dist/auth/host-function.mjs +18 -1
  11. package/dist/auth/host-services.mjs +11 -0
  12. package/dist/auth/identify.d.mts +1 -1
  13. package/dist/auth/identify.mjs +3 -3
  14. package/dist/auth/policy.d.mts +27 -7
  15. package/dist/auth/policy.mjs +8 -4
  16. package/dist/auth/token-cleanup.mjs +67 -0
  17. package/dist/auth/token-rows.mjs +1 -1
  18. package/dist/auth/token-text.mjs +9 -1
  19. package/dist/auth/tokens-base.d.mts +35 -0
  20. package/dist/auth/tokens-base.mjs +13 -0
  21. package/dist/auth/tokens-layer.d.mts +2 -28
  22. package/dist/auth/tokens-layer.mjs +6 -12
  23. package/dist/auth/tokens-public.d.mts +3 -3
  24. package/dist/auth/tokens.d.mts +7 -17
  25. package/dist/auth/tokens.mjs +9 -87
  26. package/dist/auth.d.mts +1 -4
  27. package/dist/auth.mjs +1 -3
  28. package/dist/client/answer.mjs +21 -42
  29. package/dist/client/client.d.mts +2 -4
  30. package/dist/client/git-http.mjs +35 -11
  31. package/dist/client/local.mjs +14 -13
  32. package/dist/client/push-upload.mjs +39 -12
  33. package/dist/client/remote.mjs +95 -31
  34. package/dist/client/run-remote-helper.d.mts +1 -0
  35. package/dist/client/run-remote-helper.mjs +58 -24
  36. package/dist/client/slice-push.d.mts +1 -1
  37. package/dist/client/transport.mjs +105 -46
  38. package/dist/contracts/access.d.mts +8 -8
  39. package/dist/contracts/actors.d.mts +2 -34
  40. package/dist/contracts/blobs.d.mts +57 -10
  41. package/dist/contracts/blobs.mjs +16 -2
  42. package/dist/contracts/call-allowance.d.mts +13 -0
  43. package/dist/contracts/call-allowance.mjs +44 -0
  44. package/dist/contracts/calls-spent.mjs +8 -3
  45. package/dist/contracts/client.d.mts +23 -19
  46. package/dist/contracts/commits.d.mts +34 -26
  47. package/dist/contracts/commits.mjs +9 -1
  48. package/dist/contracts/engine.d.mts +6 -1
  49. package/dist/contracts/engine.mjs +10 -1
  50. package/dist/contracts/files.d.mts +12 -12
  51. package/dist/contracts/forks.d.mts +27 -17
  52. package/dist/contracts/git-events.d.mts +29 -1
  53. package/dist/contracts/git-hooks.d.mts +1 -1
  54. package/dist/contracts/git.d.mts +39 -7
  55. package/dist/contracts/git.mjs +3 -2
  56. package/dist/contracts/grants.d.mts +24 -4
  57. package/dist/contracts/handlers.d.mts +1 -1
  58. package/dist/contracts/lfs.d.mts +28 -9
  59. package/dist/contracts/merges.d.mts +3 -2
  60. package/dist/contracts/objects.d.mts +103 -35
  61. package/dist/contracts/operations.d.mts +3 -0
  62. package/dist/contracts/operations.mjs +12 -2
  63. package/dist/contracts/push-uploads.d.mts +44 -5
  64. package/dist/contracts/push-uploads.mjs +7 -3
  65. package/dist/contracts/queue.d.mts +40 -12
  66. package/dist/contracts/queue.mjs +3 -4
  67. package/dist/contracts/refs.d.mts +50 -25
  68. package/dist/contracts/remote.d.mts +6 -7
  69. package/dist/contracts/remote.mjs +5 -4
  70. package/dist/contracts/repo-records.d.mts +1 -0
  71. package/dist/contracts/repos.d.mts +106 -127
  72. package/dist/contracts/repos.mjs +33 -4
  73. package/dist/contracts/result.d.mts +49 -25
  74. package/dist/contracts/result.mjs +52 -11
  75. package/dist/contracts/rules.d.mts +22 -22
  76. package/dist/contracts/server.d.mts +37 -111
  77. package/dist/contracts/services.d.mts +1 -1
  78. package/dist/contracts/signin.d.mts +1 -1
  79. package/dist/contracts/store.d.mts +6 -5
  80. package/dist/contracts/sync.d.mts +90 -26
  81. package/dist/contracts/sync.mjs +45 -11
  82. package/dist/contracts/tags.d.mts +10 -10
  83. package/dist/contracts/time.d.mts +3 -0
  84. package/dist/contracts/{promises.mjs → time.mjs} +1 -1
  85. package/dist/contracts/tokens.d.mts +15 -22
  86. package/dist/contracts/tokens.mjs +3 -3
  87. package/dist/contracts/topics.d.mts +1 -6
  88. package/dist/contracts/trees.d.mts +12 -12
  89. package/dist/contracts/work.d.mts +87 -12
  90. package/dist/contracts/work.mjs +8 -1
  91. package/dist/core/access.d.mts +1 -2
  92. package/dist/core/access.mjs +46 -13
  93. package/dist/core/ancestry.d.mts +10 -0
  94. package/dist/core/ancestry.mjs +6 -6
  95. package/dist/core/asked.mjs +43 -5
  96. package/dist/core/call-names.mjs +7 -1
  97. package/dist/core/call-services.mjs +13 -4
  98. package/dist/core/events/deliver.d.mts +1 -2
  99. package/dist/core/events/deliver.mjs +48 -33
  100. package/dist/core/events/retired.mjs +119 -0
  101. package/dist/core/forks.mjs +931 -435
  102. package/dist/core/hooks/groups.mjs +1 -1
  103. package/dist/core/imports.mjs +159 -15
  104. package/dist/core/index-job.mjs +128 -37
  105. package/dist/core/index-lost.d.mts +1 -2
  106. package/dist/core/index-lost.mjs +2 -2
  107. package/dist/core/job-view.mjs +8 -9
  108. package/dist/core/loose-tally.mjs +1 -1
  109. package/dist/core/mirror-rows.mjs +19 -4
  110. package/dist/core/objects/blobs.mjs +129 -3
  111. package/dist/core/objects/commits.mjs +16 -6
  112. package/dist/core/objects/lines.mjs +2 -2
  113. package/dist/core/objects/merges.mjs +4 -1
  114. package/dist/core/objects/objects-layer.d.mts +1 -1
  115. package/dist/core/objects/objects-layer.mjs +3 -3
  116. package/dist/core/objects/reading.mjs +24 -13
  117. package/dist/core/objects/tags.mjs +4 -1
  118. package/dist/core/objects/trees.mjs +2 -2
  119. package/dist/core/objects/writing.mjs +2 -2
  120. package/dist/core/own-writes.mjs +1 -1
  121. package/dist/core/parts.d.mts +10 -6
  122. package/dist/core/parts.mjs +3 -11
  123. package/dist/core/promise.mjs +9 -12
  124. package/dist/core/purge.mjs +316 -42
  125. package/dist/core/push-decide.mjs +3 -1
  126. package/dist/core/push-files.d.mts +12 -0
  127. package/dist/core/push-files.mjs +225 -0
  128. package/dist/core/push-repo.d.mts +8 -0
  129. package/dist/core/push-repo.mjs +56 -0
  130. package/dist/core/push.d.mts +17 -0
  131. package/dist/core/push.mjs +153 -70
  132. package/dist/core/receipts.mjs +34 -13
  133. package/dist/core/ref-index-job.mjs +4 -4
  134. package/dist/core/ref-view.mjs +61 -7
  135. package/dist/core/refs.mjs +18 -13
  136. package/dist/core/registered-rows.mjs +2 -2
  137. package/dist/core/repack.mjs +46 -28
  138. package/dist/core/repo-info.mjs +19 -12
  139. package/dist/core/repos.mjs +50 -22
  140. package/dist/core/rules/commit-changes.d.mts +0 -1
  141. package/dist/core/saved-caller-views.d.mts +7 -2
  142. package/dist/core/saved-caller-views.mjs +2 -2
  143. package/dist/core/saved-callers.d.mts +19 -2
  144. package/dist/core/seam.d.mts +16 -26
  145. package/dist/core/seam.mjs +7 -28
  146. package/dist/core/tokens.mjs +1 -1
  147. package/dist/core/view.d.mts +6 -0
  148. package/dist/core/view.mjs +51 -26
  149. package/dist/core/work.mjs +105 -35
  150. package/dist/effect.d.mts +5 -12
  151. package/dist/effect.mjs +3 -10
  152. package/dist/engine/failures.mjs +2 -1
  153. package/dist/engine/reads.mjs +17 -10
  154. package/dist/engine/walk.mjs +4 -4
  155. package/dist/event-streams/event-streams.d.mts +1 -1
  156. package/dist/event-streams/event-streams.mjs +1 -1
  157. package/dist/event-streams/stream.d.mts +3 -3
  158. package/dist/event-streams/stream.mjs +38 -15
  159. package/dist/extend.d.mts +4 -5
  160. package/dist/extend.mjs +3 -2
  161. package/dist/http/answers.mjs +12 -7
  162. package/dist/http/core-parts.mjs +129 -64
  163. package/dist/http/handler.mjs +36 -9
  164. package/dist/http/node.d.mts +14 -1
  165. package/dist/http/node.mjs +61 -31
  166. package/dist/http/parts.d.mts +2 -0
  167. package/dist/http/push-upload-job.mjs +507 -0
  168. package/dist/http/push-uploads.d.mts +1 -0
  169. package/dist/http/push-uploads.mjs +142 -69
  170. package/dist/http/upload-pack.mjs +10 -9
  171. package/dist/index.d.mts +27 -28
  172. package/dist/index.mjs +5 -8
  173. package/dist/lfs/answer.mjs +37 -0
  174. package/dist/lfs/base.d.mts +9 -3
  175. package/dist/lfs/base.mjs +27 -2
  176. package/dist/lfs/copy.d.mts +60 -0
  177. package/dist/lfs/copy.mjs +109 -0
  178. package/dist/lfs/layer.d.mts +15 -1
  179. package/dist/lfs/layer.mjs +28 -13
  180. package/dist/lfs/locks.mjs +2 -2
  181. package/dist/lfs/objects.d.mts +7 -0
  182. package/dist/lfs/objects.mjs +152 -55
  183. package/dist/lfs/pointers.mjs +2 -2
  184. package/dist/lfs/rows.d.mts +13 -0
  185. package/dist/lfs/rows.mjs +42 -8
  186. package/dist/lfs/service.d.mts +1 -7
  187. package/dist/lfs/service.mjs +1 -9
  188. package/dist/lfs/upkeep.mjs +48 -14
  189. package/dist/lfs/upload-most.mjs +5 -5
  190. package/dist/lfs/wire.mjs +6 -31
  191. package/dist/merges/merges.mjs +2 -2
  192. package/dist/node.d.mts +3 -3
  193. package/dist/protocol/bytes/buffers.mjs +13 -5
  194. package/dist/protocol/bytes/reader.mjs +6 -1
  195. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  196. package/dist/protocol/bytes/sha256.d.mts +32 -0
  197. package/dist/protocol/bytes/sha256.mjs +105 -49
  198. package/dist/protocol/bytes/streams.mjs +27 -1
  199. package/dist/protocol/diff/read.d.mts +4 -3
  200. package/dist/protocol/diff/read.mjs +8 -3
  201. package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
  202. package/dist/protocol/objects/lfs-pointer.mjs +1 -3
  203. package/dist/protocol/objects/links-raw.mjs +24 -10
  204. package/dist/protocol/objects/tag.d.mts +1 -1
  205. package/dist/protocol/objects/tree.mjs +23 -6
  206. package/dist/protocol/packs/delta.d.mts +6 -3
  207. package/dist/protocol/packs/delta.mjs +96 -32
  208. package/dist/protocol/packs/idx.d.mts +2 -1
  209. package/dist/protocol/packs/idx.mjs +22 -3
  210. package/dist/protocol/packs/parts.d.mts +4 -1
  211. package/dist/protocol/packs/parts.mjs +10 -7
  212. package/dist/protocol/packs/reader.d.mts +5 -0
  213. package/dist/protocol/packs/reader.mjs +3 -2
  214. package/dist/protocol/packs/writer.mjs +26 -8
  215. package/dist/protocol/wire/advertisement.mjs +9 -4
  216. package/dist/protocol/wire/lines.d.mts +4 -2
  217. package/dist/protocol/wire/lines.mjs +11 -5
  218. package/dist/protocol/wire/push-uploads.mjs +13 -1
  219. package/dist/protocol/wire/v2.mjs +2 -2
  220. package/dist/protocol.d.mts +3 -1
  221. package/dist/protocol.mjs +3 -1
  222. package/dist/queue/advance.mjs +22 -25
  223. package/dist/queue/base.d.mts +55 -0
  224. package/dist/queue/base.mjs +44 -0
  225. package/dist/queue/calls.mjs +51 -54
  226. package/dist/queue/commit.mjs +1 -1
  227. package/dist/queue/host.d.mts +2 -22
  228. package/dist/queue/host.mjs +2 -13
  229. package/dist/queue/layer.d.mts +2 -1
  230. package/dist/queue/layer.mjs +11 -4
  231. package/dist/queue/limits.mjs +2 -0
  232. package/dist/queue/push-option.mjs +9 -24
  233. package/dist/queue/schedule.mjs +1 -1
  234. package/dist/queue/state.mjs +2 -10
  235. package/dist/queue/trim.mjs +6 -4
  236. package/dist/rest/blobs.mjs +29 -5
  237. package/dist/rest/caller.d.mts +4 -4231
  238. package/dist/rest/caller.mjs +5 -1
  239. package/dist/rest/client.d.mts +15 -5
  240. package/dist/rest/client.mjs +23 -2
  241. package/dist/rest/events.mjs +1 -2
  242. package/dist/rest/handler.mjs +4 -57
  243. package/dist/rest/handlers.mjs +68 -9
  244. package/dist/rest/layer.d.mts +2 -2
  245. package/dist/rest/layer.mjs +7 -13
  246. package/dist/rest/me.d.mts +3 -428
  247. package/dist/rest/paths.mjs +1 -0
  248. package/dist/rest/work.mjs +8 -0
  249. package/dist/server/check-fetch.mjs +3 -3
  250. package/dist/server/edge-node.d.mts +14 -15
  251. package/dist/server/edge-node.mjs +12 -12
  252. package/dist/server/edge.d.mts +21 -7
  253. package/dist/server/edge.mjs +32 -11
  254. package/dist/server/extension.mjs +1 -1
  255. package/dist/server/git-layer.d.mts +6 -11
  256. package/dist/server/git-layer.mjs +29 -23
  257. package/dist/server/git-namespace.d.mts +5 -4
  258. package/dist/server/git-namespace.mjs +3 -2
  259. package/dist/server/joined.d.mts +21 -40
  260. package/dist/server/joined.mjs +11 -62
  261. package/dist/server/lifecycle.mjs +65 -69
  262. package/dist/server/registry.mjs +28 -3
  263. package/dist/server/server.mjs +245 -465
  264. package/dist/signin/context.d.mts +1 -2
  265. package/dist/signin/layer.d.mts +1 -1
  266. package/dist/signin/layer.mjs +1 -1
  267. package/dist/storage/allotted.mjs +18 -3
  268. package/dist/storage/batch-upkeep.mjs +274 -0
  269. package/dist/{core/purge.d.mts → storage/batches.d.mts} +4 -4
  270. package/dist/storage/batches.mjs +344 -0
  271. package/dist/storage/budget.mjs +2 -2
  272. package/dist/storage/calls.d.mts +1 -2
  273. package/dist/storage/calls.mjs +144 -158
  274. package/dist/storage/chunks.d.mts +9 -0
  275. package/dist/storage/chunks.mjs +297 -0
  276. package/dist/storage/clean-up.mjs +85 -19
  277. package/dist/storage/counted-bucket.mjs +4 -4
  278. package/dist/storage/fetch.d.mts +1 -0
  279. package/dist/storage/fetch.mjs +298 -216
  280. package/dist/storage/file-limits.mjs +24 -0
  281. package/dist/storage/host-bucket.mjs +1 -2
  282. package/dist/storage/id-mix.mjs +19 -5
  283. package/dist/storage/index-bitmaps.mjs +9 -2
  284. package/dist/storage/index-build.d.mts +1 -1
  285. package/dist/storage/index-build.mjs +185 -84
  286. package/dist/storage/index-fetch.mjs +128 -74
  287. package/dist/storage/index-files.d.mts +3 -0
  288. package/dist/storage/index-files.mjs +10 -5
  289. package/dist/storage/index-graph.mjs +72 -22
  290. package/dist/storage/index-reach.mjs +33 -5
  291. package/dist/storage/index-remap.mjs +208 -65
  292. package/dist/storage/index-shallow.mjs +5 -3
  293. package/dist/storage/index-whole.mjs +127 -0
  294. package/dist/storage/largest-files.mjs +48 -0
  295. package/dist/storage/layout.mjs +23 -0
  296. package/dist/storage/lfs-pointers.mjs +10 -1
  297. package/dist/storage/loose.d.mts +7 -4
  298. package/dist/storage/loose.mjs +214 -67
  299. package/dist/storage/memory-budget.mjs +44 -8
  300. package/dist/storage/merge-plan.mjs +3 -2
  301. package/dist/storage/merge-row.mjs +7 -1
  302. package/dist/storage/merge-stream.mjs +164 -25
  303. package/dist/storage/merge-walk.mjs +8 -4
  304. package/dist/storage/merge-write.mjs +1 -1
  305. package/dist/storage/merge.d.mts +1 -1
  306. package/dist/storage/merge.mjs +1 -1
  307. package/dist/storage/object-rows.d.mts +1 -0
  308. package/dist/storage/object-rows.mjs +385 -65
  309. package/dist/storage/oid-table.mjs +171 -0
  310. package/dist/storage/pack-order.mjs +8 -4
  311. package/dist/storage/pack-ranges.d.mts +1 -2
  312. package/dist/storage/pack-ranges.mjs +4 -5
  313. package/dist/storage/pack-reads.d.mts +2 -1
  314. package/dist/storage/pack-reads.mjs +165 -49
  315. package/dist/storage/pack-receive.d.mts +1 -1
  316. package/dist/storage/pack-receive.mjs +85 -27
  317. package/dist/storage/packs.d.mts +1 -1
  318. package/dist/storage/packs.mjs +172 -86
  319. package/dist/storage/placed-reads.mjs +1 -1
  320. package/dist/storage/plan-columns.d.mts +4 -0
  321. package/dist/storage/plan-columns.mjs +238 -0
  322. package/dist/storage/prune-keep.mjs +299 -37
  323. package/dist/storage/prune-walk.mjs +240 -62
  324. package/dist/storage/prune.mjs +749 -213
  325. package/dist/storage/push-allotment.mjs +91 -12
  326. package/dist/storage/push-uploads.mjs +40 -16
  327. package/dist/storage/pushed-commits.mjs +4 -2
  328. package/dist/storage/quarantine.d.mts +1 -1
  329. package/dist/storage/quarantine.mjs +9 -9
  330. package/dist/storage/range-cache.mjs +125 -8
  331. package/dist/storage/ready.d.mts +1 -1
  332. package/dist/storage/ready.mjs +55 -25
  333. package/dist/storage/receive-bounds.mjs +51 -15
  334. package/dist/storage/receive-state.mjs +8 -0
  335. package/dist/storage/receive-steps.mjs +71 -18
  336. package/dist/storage/repack-backlog.mjs +6 -3
  337. package/dist/storage/repack.d.mts +2 -2
  338. package/dist/storage/repack.mjs +1 -8
  339. package/dist/storage/rows.d.mts +1 -1
  340. package/dist/storage/rows.mjs +13 -2
  341. package/dist/storage/runs.mjs +195 -43
  342. package/dist/storage/send-list.d.mts +1 -0
  343. package/dist/storage/send-list.mjs +54 -10
  344. package/dist/storage/shallow.d.mts +1 -0
  345. package/dist/storage/shallow.mjs +26 -4
  346. package/dist/storage/single-flight.mjs +13 -7
  347. package/dist/storage/stream-whole.mjs +132 -28
  348. package/dist/storage/unpack.mjs +371 -79
  349. package/dist/storage/visible.mjs +31 -3
  350. package/dist/storage/walk.mjs +194 -39
  351. package/dist/storage/wants.mjs +5 -5
  352. package/dist/store/bodies.mjs +38 -0
  353. package/dist/store/call-count.d.mts +8 -12
  354. package/dist/store/call-count.mjs +34 -46
  355. package/dist/store/catalogue.d.mts +2 -2
  356. package/dist/store/catalogue.mjs +146 -35
  357. package/dist/store/crossing.mjs +1 -3
  358. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  359. package/dist/store/cursor-seal-public.d.mts +5 -0
  360. package/dist/store/cursor-seal-public.mjs +5 -0
  361. package/dist/store/cursor-seal.d.mts +16 -3
  362. package/dist/store/cursor-seal.mjs +40 -18
  363. package/dist/store/door.mjs +183 -0
  364. package/dist/store/errors.d.mts +3 -4
  365. package/dist/store/errors.mjs +24 -34
  366. package/dist/store/git-store.mjs +25 -7
  367. package/dist/store/job-try.mjs +9 -32
  368. package/dist/store/list-job.mjs +44 -8
  369. package/dist/store/records.d.mts +5 -0
  370. package/dist/store/records.mjs +12 -6
  371. package/dist/store/repo-record.d.mts +10 -9
  372. package/dist/store/repo-record.mjs +123 -28
  373. package/dist/store/reservations.mjs +1 -1
  374. package/dist/store/scopes.mjs +21 -2
  375. package/dist/store/settle.mjs +4 -4
  376. package/dist/sync/bound.d.mts +2 -0
  377. package/dist/sync/bound.mjs +11 -2
  378. package/dist/sync/github.d.mts +6 -1
  379. package/dist/sync/github.mjs +56 -44
  380. package/dist/sync/http.mjs +36 -1
  381. package/dist/sync/import.mjs +32 -18
  382. package/dist/sync/layer.mjs +6 -2
  383. package/dist/sync/lfs-batch.mjs +118 -0
  384. package/dist/sync/lfs-copy.mjs +262 -0
  385. package/dist/sync/mirror.mjs +227 -151
  386. package/dist/sync/said.mjs +16 -37
  387. package/dist/sync/smart-http.mjs +4 -2
  388. package/dist/sync/step.mjs +58 -30
  389. package/dist/sync/tries.mjs +52 -21
  390. package/dist/sync.d.mts +2 -2
  391. package/dist/topics/advance.mjs +10 -11
  392. package/dist/topics/base.d.mts +15 -0
  393. package/dist/topics/base.mjs +8 -0
  394. package/dist/topics/host.mjs +2 -20
  395. package/dist/topics/layer.d.mts +4 -9
  396. package/dist/topics/layer.mjs +3 -4
  397. package/dist/topics/members.mjs +4 -4
  398. package/dist/topics/public.d.mts +2 -1
  399. package/dist/topics/topic.mjs +2 -2
  400. package/package.json +5 -9
  401. package/dist/auth/bridge.mjs +0 -30
  402. package/dist/auth/helpers.d.mts +0 -17
  403. package/dist/contracts/promises.d.mts +0 -39
  404. package/dist/core/call-names.d.mts +0 -3
  405. package/dist/core/clock.mjs +0 -18
  406. package/dist/core/registered-rows.d.mts +0 -5
  407. package/dist/core/repack.d.mts +0 -11
  408. package/dist/http/handler.d.mts +0 -2
  409. package/dist/lfs/calls.mjs +0 -26
  410. package/dist/rest/api.d.mts +0 -23
  411. package/dist/rest/blobs.d.mts +0 -825
  412. package/dist/rest/commits.d.mts +0 -3510
  413. package/dist/rest/errors.d.mts +0 -2104
  414. package/dist/rest/events.d.mts +0 -423
  415. package/dist/rest/files.d.mts +0 -1330
  416. package/dist/rest/forks.d.mts +0 -2136
  417. package/dist/rest/handler.d.mts +0 -21
  418. package/dist/rest/handlers.d.mts +0 -8
  419. package/dist/rest/merges.d.mts +0 -473
  420. package/dist/rest/queue.d.mts +0 -5861
  421. package/dist/rest/refs.d.mts +0 -2959
  422. package/dist/rest/repos.d.mts +0 -2539
  423. package/dist/rest/tags.d.mts +0 -1304
  424. package/dist/rest/tokens.d.mts +0 -2590
  425. package/dist/rest/topics.d.mts +0 -2204
  426. package/dist/rest/trees.d.mts +0 -1693
  427. package/dist/rest/work.d.mts +0 -1248
  428. package/dist/rest.d.mts +0 -2
  429. package/dist/rest.mjs +0 -1
  430. package/dist/server/lifecycle.d.mts +0 -2
  431. package/dist/server/registry.d.mts +0 -16
  432. package/dist/server/server.d.mts +0 -36
  433. package/dist/storage/repack-job.d.mts +0 -3
  434. package/dist/store/promises.d.mts +0 -11
  435. package/dist/store/promises.mjs +0 -327
  436. package/dist/topics/host.d.mts +0 -7
@@ -1,21 +1,23 @@
1
+ import { Sha1 } from "../protocol/bytes/sha1.mjs";
1
2
  import { noRepoRoots } from "../protocol/objects/commit.mjs";
2
3
  import { checkChurn, decodeRecord, entryOf, project } from "./catalogue.mjs";
3
4
  import { afterCommit } from "./call-count.mjs";
4
5
  import { fail } from "../contracts/result.mjs";
5
- import { afterWrites, decodeRow, storeCall } from "./errors.mjs";
6
+ import { afterWrites, decodeRow, storeCall, storeCommit } from "./errors.mjs";
6
7
  import { listJobRow } from "./list-job.mjs";
7
- import { LooseTally, RepoRootsRow, StatsTime } from "./records.mjs";
8
- import { looseKey, maintainedKey, newChangeId, pushedKey, repoScope, selfKey } from "./scopes.mjs";
9
- import * as Clock$1 from "effect/Clock";
8
+ import { LooseTally, RepoRootsRow, StatsTime, repoRootsMost } from "./records.mjs";
9
+ import { looseKey, maintainedKey, newChangeId, pushedKey, reachedKey, repoRootsKey, repoScope, selfKey } from "./scopes.mjs";
10
+ import * as Clock from "effect/Clock";
10
11
  import * as Effect from "effect/Effect";
11
12
  import * as Schema from "effect/Schema";
12
13
  import { jobLeaseMargin } from "@ref0/infra";
13
14
  import * as Context from "effect/Context";
15
+ import * as Hex from "effect/encoding/Hex";
14
16
  // src/store/repo-record.ts
15
17
  /** A repo's record and its scope's rows, read at one version: `results[0]` is `self`. */
16
18
  const readRecord = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, reads = [], counts = []) {
17
19
  const scope = repoScope(internalId);
18
- const snapshot = yield* storeCall(() => store.read(scope, [selfKey, ...reads], [...counts]));
20
+ const snapshot = yield* storeCall(store.read(scope, [selfKey, ...reads], [...counts]));
19
21
  return {
20
22
  record: yield* decodeRecord(snapshot.results[0]?.[0]),
21
23
  snapshot
@@ -27,27 +29,109 @@ const rootsOf = (rows) => {
27
29
  if (row === void 0) return Effect.succeed(noRepoRoots);
28
30
  return Effect.map(decodeRow(RepoRootsRow, row, "The repo's roots"), ({ roots }) => new Set(roots));
29
31
  };
32
+ /** `held` once `moves` lands, as `rootsMoved` writes it: `shallow` added, then `unshallow` taken away. */
33
+ const movedRoots = (held, moves) => {
34
+ const after = new Set(held);
35
+ for (const oid of moves.shallow) after.add(oid);
36
+ for (const oid of moves.unshallow) after.delete(oid);
37
+ return after;
38
+ };
39
+ /**
40
+ * The write of a repo's roots once `moves` lands on `held`, the roots its commit reads: those of
41
+ * `shallow` added, and those of `unshallow` taken away, each once, in order. `undefined` when they
42
+ * don't change. It is the roots' one writer (#2202, and #2198's import), and it does three things
43
+ * on a change: its row, or the row's delete once none is left; the reached mark's delete, so a
44
+ * whole clone never streams past a root that moved; and `indexed`, the repo's `git.index` rows,
45
+ * which queue a build over the new roots: an index keeps `rootsDigest` of the roots it's over, so
46
+ * one over others answers no read and is built again whole (#2462). Prune keys its saved work on
47
+ * them too: its walks keep `rootsKeyOf` of the roots they walked under, and its classes' reads
48
+ * digest takes them, so a pass whose roots moved walks and reads again under the new ones (#2485).
49
+ * Past `repoRootsMost` it's refused, so a fetch lands nothing. An answer that moves the roots
50
+ * lands only on the roots it was made against, `sent`: once another fetch moved them, its lines
51
+ * no longer say where the history stops, and it's refused `changed-while-checked`, landing
52
+ * nothing, for the fetch to ask again.
53
+ */
54
+ const rootsMoved = (held, moves, indexed) => {
55
+ const moving = moves.shallow.length > 0 || moves.unshallow.length > 0;
56
+ const asked = new Set(moves.sent);
57
+ const moved = asked.size !== held.size || [...asked].some((oid) => !held.has(oid));
58
+ if (moving && moved) return fail("FAILED_PRECONDITION", "The repo's roots moved since this fetch sent them", {
59
+ hint: "Fetch again",
60
+ context: { reason: "changed-while-checked" }
61
+ });
62
+ const after = movedRoots(held, moves);
63
+ if (after.size === held.size && [...after].every((oid) => held.has(oid))) return Effect.succeed(void 0);
64
+ if (after.size > 1e4) return fail("RESOURCE_EXHAUSTED", `A repo holds at most ${repoRootsMost} shallow commits`, {
65
+ hint: "Fetch with a smaller depth, or from fewer branches",
66
+ context: {
67
+ reason: "too-large",
68
+ most: repoRootsMost
69
+ }
70
+ });
71
+ const roots = [...after].sort();
72
+ const value = { roots };
73
+ const put = roots.length === 0 ? [] : [{
74
+ ...repoRootsKey,
75
+ value
76
+ }];
77
+ const gone = roots.length === 0 ? [repoRootsKey] : [];
78
+ return Effect.succeed({
79
+ roots,
80
+ put,
81
+ delete: [...gone, reachedKey],
82
+ jobs: indexed
83
+ });
84
+ };
85
+ /**
86
+ * The repo's roots as one digest: their IDs sorted, each once, hashed. What was built over the
87
+ * roots, such as the ready shallow pack, keeps it, so a change of roots is seen as one.
88
+ */
89
+ const rootsDigest = (roots) => {
90
+ const sha = new Sha1();
91
+ sha.update(new TextEncoder().encode([...new Set(roots)].sort().join("\n")));
92
+ return Hex.encode(sha.digest());
93
+ };
94
+ /**
95
+ * How long a repo's delete may commit after the time it stamps, from which its purge's guard
96
+ * counts: half of `jobLeaseMargin`. The delete's commit sends it past that time as its `by`, and
97
+ * the margin's other half covers how far the store's clock may run from Git's, which a held write
98
+ * meets twice, at the delete's commit and at its own: a quarter of the margin each way (#2331).
99
+ */
100
+ const deleteCommitWithin = jobLeaseMargin / 2;
30
101
  /**
31
- * When a write to a repo's scope must begin its store call by, after a read at `heldAt` found the
32
- * repo's record live: `heldAt` plus `fetchLimits.milliseconds`, less `jobLeaseMargin`. The repo
33
- * was live at that read, so its delete came later, and its purge drops its scopes no sooner than
34
- * `fetchLimits` past the delete, the record's `changedAt`: a call begun by then lands before the
35
- * drop, with the lease margin for the call itself, as `git.repack`'s `remapLate` keeps it (#1911).
36
- * It assumes the store call ends inside that margin: no store call is bounded below it yet (#2331).
102
+ * When a write to a repo's scope must land by, after a read at `heldAt` found the repo's record
103
+ * live: `heldAt` plus `fetchLimits.milliseconds`, less `jobLeaseMargin`. The repo was live at that
104
+ * read, so its delete committed later, and its purge drops its scopes no sooner than `fetchLimits`
105
+ * past the delete's stamp, the record's `changedAt`, which the delete commits within
106
+ * `deleteCommitWithin` of (#1911). The write sends it as its `by`, which the store checks on its
107
+ * own clock as the write lands, so one that stalls in the store lands nothing past it, however
108
+ * long the stall (#2331). The margin covers the delete's commit and the store's clock, as
109
+ * `deleteCommitWithin` splits it, and `HeldWrite.tla` checks that no held write lands after the drop.
37
110
  */
38
111
  const heldUntil = (heldAt, fetchLimits) => heldAt + fetchLimits.milliseconds - jobLeaseMargin;
39
- /** Whether a write may still begin its store call, by `heldUntil`'s `by`, at the clock's now. */
40
- const inTime = (by) => Effect.map(Clock$1.currentTimeMillis, (now) => now < by);
112
+ /** Whether a write may still send its store call, by `heldUntil`'s `by`, at the clock's now. */
113
+ const inTime = (by) => Effect.map(Clock.currentTimeMillis, (now) => now < by);
41
114
  /**
42
- * When the writes in scope must begin by, as `heldUntil` answered for the caller's own read of the
115
+ * When the writes in scope must land by, as `heldUntil` answered for the caller's own read of the
43
116
  * repo's record: a push sets it around its receive, so the pack's quarantine row, an add at no
44
117
  * version, is refused once the push waited past it, at its authorize or its memory's admission,
45
- * as long as the repo's purge may take (#1911). `undefined` outside one, as for `git.repack`'s
46
- * own packs, which the purge waits for.
118
+ * or in the store, as long as the repo's purge may take (#1911, #2331). `undefined` outside one,
119
+ * as for `git.repack`'s own packs, which the purge waits for.
47
120
  */
48
121
  const HeldBy = Context.Reference("@ref0/git/HeldBy", { defaultValue: () => void 0 });
49
- /** Fails `UNAVAILABLE` once the clock is at or past `HeldBy`, so a write that waited reads again. */
50
- const heldInTime = (what) => Effect.flatMap(HeldBy, (by) => by === void 0 ? Effect.void : Effect.flatMap(inTime(by), (on) => on ? Effect.void : fail("UNAVAILABLE", `${what} came late: read the repo again`, { hint: "Push again" })));
122
+ /**
123
+ * `addition` with the sooner of `HeldBy` and its own `by` as its `by`, the value it sends, so the
124
+ * store refuses it as it lands past either: fails `UNAVAILABLE` already once the clock is at or
125
+ * past it, so a write that waited reads again. A staged batch's add carries its `removeAt`, which
126
+ * its sweep's end counts on.
127
+ */
128
+ const heldAddition = (what, addition) => Effect.flatMap(HeldBy, (held) => {
129
+ const by = held === void 0 ? addition.by : Math.min(held, addition.by ?? Number.POSITIVE_INFINITY);
130
+ return by === void 0 ? Effect.succeed(addition) : Effect.flatMap(inTime(by), (on) => on ? Effect.succeed({
131
+ ...addition,
132
+ by
133
+ }) : fail("UNAVAILABLE", `${what} came late: read the repo again`, { hint: "Push again" }));
134
+ });
51
135
  /**
52
136
  * A write to a repo's scope refused because the repo is gone: no record, or one deleted, so its
53
137
  * purge may drop the scope, or has, and the write would make it again (#1911).
@@ -55,26 +139,33 @@ const heldInTime = (what) => Effect.flatMap(HeldBy, (by) => by === void 0 ? Effe
55
139
  var RepoGone = class extends Schema.TaggedError()("RepoGone", { repo: Schema.String }) {};
56
140
  /** `store` as `heldAdd` calls it, each call a `storeCall`. */
57
141
  const heldStore = (store) => ({
58
- read: (scope, reads) => storeCall(() => store.read(scope, reads)),
59
- add: (scope, addition) => storeCall(() => store.add(scope, addition))
142
+ read: (scope, reads) => storeCall(store.read(scope, reads)),
143
+ add: (scope, addition) => storeCall(store.add(scope, addition))
60
144
  });
61
145
  /**
62
146
  * `addition` to `repo`'s scope, an add at no version, only while the repo is live: it reads the
63
147
  * record first and fails `RepoGone` when there's none or it's deleted, so a late write, a wake or
64
148
  * a job after the delete never makes a purged scope again, nor on Turso its database. One whose
65
- * read stalled past `heldUntil` is `UNAVAILABLE`, for a try that reads again. A wake, a job, an
149
+ * read stalled past `heldUntil` is `UNAVAILABLE`, for a try that reads again, and so is one whose
150
+ * add the store found past it as it landed, `heldUntil` being the add's `by`. A wake, a job, an
66
151
  * upload or a sync's cover made apart from the repo's own read goes through here, and a push's
67
- * quarantine is held to its first read by `HeldBy`. The adds that don't are a fork create's cover
68
- * rows, which come with its record, and a try's rows in its own scope, which its claim fences.
152
+ * quarantine is held to its first read by `HeldBy`. The adds that don't are a fork create's
153
+ * staging, after its opener commits its record aside, by the `removeAt` its purge waits out, and a
154
+ * try's rows in its own scope, which its claim fences. A create's cover rows are commits at its
155
+ * version.
69
156
  */
70
157
  const heldAdd = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, fetchLimits, addition) {
71
158
  const scope = repoScope(repo);
72
- const heldAt = yield* Clock$1.currentTimeMillis;
159
+ const heldAt = yield* Clock.currentTimeMillis;
73
160
  const snapshot = yield* store.read(scope, [selfKey]);
74
161
  const record = yield* decodeRecord(snapshot.results[0]?.[0]);
75
162
  if (record === void 0 || record.deleted === true) return yield* new RepoGone({ repo });
76
- if (!(yield* inTime(heldUntil(heldAt, fetchLimits)))) return yield* fail("UNAVAILABLE", `The add to repo ${repo} came late: read it again`);
77
- yield* store.add(scope, addition);
163
+ const by = heldUntil(heldAt, fetchLimits);
164
+ if (!(yield* inTime(by))) return yield* fail("UNAVAILABLE", `The add to repo ${repo} came late: read it again`);
165
+ yield* store.add(scope, {
166
+ ...addition,
167
+ by
168
+ });
78
169
  });
79
170
  /**
80
171
  * The first of a repo write's two commits: its record, in its own scope, with `git.list` saved
@@ -91,7 +182,11 @@ const commitRecord = (store, internalId, write) => {
91
182
  delete: [...write.delete ?? []],
92
183
  jobs: [listJobRow(), ...write.jobs ?? []]
93
184
  };
94
- return storeCall(() => store.commit(repoScope(internalId), change));
185
+ const sent = write.by === void 0 ? change : {
186
+ ...change,
187
+ by: write.by
188
+ };
189
+ return storeCommit(store.commit(repoScope(internalId), sent));
95
190
  };
96
191
  /**
97
192
  * A repo write's two commits: its record, then its projection into `git/repos`. Answers
@@ -177,4 +272,4 @@ const repoStats = (record, refs, packs, times, readyBytes) => {
177
272
  if (times.maintained !== void 0) stats.maintainedAt = times.maintained;
178
273
  return stats;
179
274
  };
180
- export { HeldBy, RepoGone, commitRecord, decodeStats, heldAdd, heldInTime, heldStore, heldUntil, inTime, looseRows, readRecord, repoStats, rootsOf, seenTimes, timeRow, writeRecord };
275
+ export { HeldBy, RepoGone, commitRecord, decodeStats, deleteCommitWithin, heldAdd, heldAddition, heldStore, heldUntil, inTime, looseRows, movedRoots, readRecord, repoStats, rootsDigest, rootsMoved, rootsOf, seenTimes, timeRow, writeRecord };
@@ -76,7 +76,7 @@ const reservationOf = (rows) => {
76
76
  * nothing.
77
77
  */
78
78
  const liveState = /* @__PURE__ */ Effect.fnUntraced(function* (store, reservation) {
79
- const [row] = (yield* storeCall(() => store.read(topicScope(reservation.topic), [topicKey]))).results[0] ?? [];
79
+ const [row] = (yield* storeCall(store.read(topicScope(reservation.topic), [topicKey]))).results[0] ?? [];
80
80
  if (row === void 0) return void 0;
81
81
  const life = yield* decodeRow(TopicLife, row, `Topic ${reservation.topic}`);
82
82
  return ended.has(life.state) ? void 0 : life.state;
@@ -43,6 +43,17 @@ const collections = {
43
43
  publicCreated: "public-created",
44
44
  /** In `git/repos`: the server's own keys, by use: `cursor`, which seals every list's cursor. */
45
45
  keys: "keys",
46
+ /**
47
+ * In `git/repos`: a row for each delivery the host has retired, by its name, which each start
48
+ * writes from `events.retired`, so a deleted repo's purge may end that delivery's job.
49
+ */
50
+ retired: "retired-deliveries",
51
+ /**
52
+ * In `git/repos`: `head`, the stamp of the start that last wrote the `retired` rows, `gen`, how
53
+ * many starts' writes have landed, and `start`, its ID, so a start's write behind a later
54
+ * start's landing is refused.
55
+ */
56
+ retiredStamp: "retired-stamp",
46
57
  /** In a repo's scope: its own record, `self`, and its roots, `roots`. */
47
58
  repo: "repo",
48
59
  /** In a repo's scope: each ref's `RefRow`, by its full name. */
@@ -80,6 +91,13 @@ const collections = {
80
91
  * pushed or upkeep ends it.
81
92
  */
82
93
  pushUploads: "push-uploads",
94
+ /**
95
+ * In a repo's scope: each receiving push upload's steps, by its handle: who completed it, as
96
+ * `SavedCaller` keeps them, and once its first try staged it, its pack's ID.
97
+ */
98
+ pushUploadSteps: "push-upload-steps",
99
+ /** In a repo's scope: each ended push upload's answer, by its handle, for its report. */
100
+ pushUploadAnswers: "push-upload-answers",
83
101
  /** In a topic's scope: its own row, `self`, with its state. */
84
102
  topic: "topic",
85
103
  /** In `git/topics`: each key's topic, claimed by the first `topics.add` that names the key. */
@@ -123,8 +141,9 @@ const selfKey = {
123
141
  id: "self"
124
142
  };
125
143
  /**
126
- * A repo's roots, its `RepoRootsRow`, read with every open whose reads walk parents. Only an
127
- * import's landing writes it, before its first ref page publishes; a repo with no row has none.
144
+ * A repo's roots, its `RepoRootsRow`, read with every open whose reads walk parents. Only
145
+ * `rootsMoved` writes it, for a client's fetch or an import, in the commit that lands what the
146
+ * answer sent; a repo with no row has none.
128
147
  */
129
148
  const repoRootsKey = {
130
149
  collection: collections.repo,
@@ -1,4 +1,4 @@
1
- import { storeCall } from "./errors.mjs";
1
+ import { storeCall, storeCommit } from "./errors.mjs";
2
2
  import { entryOf, project } from "./catalogue.mjs";
3
3
  import { dropUnconfirmed, headKey } from "./outbox.mjs";
4
4
  import { takenBack } from "./records.mjs";
@@ -30,11 +30,11 @@ const settleName = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, re
30
30
  ...headKey,
31
31
  value: confirmed
32
32
  }];
33
- yield* storeCall(() => store.commit(scope, {
33
+ yield* storeCall(store.commit(scope, {
34
34
  id: newChangeId(),
35
35
  expect: version,
36
36
  put
37
- }));
37
+ }), { resend: true });
38
38
  return true;
39
39
  }
40
40
  if (back !== void 0) {
@@ -55,7 +55,7 @@ const settleName = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, re
55
55
  expect: version,
56
56
  ...dropUnconfirmed(head)
57
57
  };
58
- yield* storeCall(() => store.commit(scope, change));
58
+ yield* storeCommit(store.commit(scope, change));
59
59
  return true;
60
60
  });
61
61
  /** Whether a name's entry is still this repo's own, and live: the name a lost rename left. */
@@ -2,6 +2,8 @@ import "../contracts/authorize.mjs";
2
2
  import "../contracts/actors.mjs";
3
3
  import "../contracts/sync.mjs";
4
4
  import "../core/parts.mjs";
5
+ import "../lfs/copy.mjs";
6
+ import "effect/Effect";
5
7
  import "effect/http/HttpClient";
6
8
  import { Job } from "@ref0/infra";
7
9
  import "effect/Context";
@@ -29,13 +29,22 @@ const importLimits = {
29
29
  rootsMost
30
30
  };
31
31
  /**
32
+ * The most bytes of Git LFS objects one try of an import copies: the copy's step takes a batch's
33
+ * objects until the next would pass it, and an object past it alone, so a try's downloads end
34
+ * well within `importTryTimeout`, and one object, at most LFS's `largestObject`, always fits.
35
+ */
36
+ const lfsCopyBytes = 2 * 1024 ** 3;
37
+ /**
32
38
  * The most mirrors a repo holds, and the most bytes one mirror's row takes, the row whole as UTF-8
33
39
  * JSON, measured as its largest state, paused `diverged`, so a pause never takes it past.
34
40
  * `mirrors` reads every row in one store call, beside the repo's record, at most 1 MiB, so 1,000
35
41
  * rows of 4 KiB, 4 MiB, keep its read and its answer within one answer's 16 MiB `answerBytes`. The
36
42
  * longest ref, 768 bytes of `"`, takes 1,536 escaped, and its saver's actor ID, which `authorize`
37
43
  * holds to `maxActorIdLength`, 256 bytes, takes 512 so, which leaves its destination about 1,880
38
- * bytes.
44
+ * bytes. `mirrors` bounds a destination's job too, one a destination: a push saves at most
45
+ * that many, and each try reads every row in one call, asks each distinct saver among them again
46
+ * once, makes one `provider.remote` call, reads the advertisement once, and twice when an update is
47
+ * refused, and sends one push of at most that many refs.
39
48
  */
40
49
  const mirrorLimits = {
41
50
  mirrors: 1e3,
@@ -48,4 +57,4 @@ const mirrorLimits = {
48
57
  const asSync = decidingWith(hostAuthorize);
49
58
  /** The build's internal binding, including the definitions test worlds hand to their queue. */
50
59
  var SyncState = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/SyncState")) {};
51
- export { SyncState, asSync, importLimits, mirrorLimits };
60
+ export { SyncState, asSync, importLimits, lfsCopyBytes, mirrorLimits };
@@ -7,5 +7,10 @@ import * as HttpClient from "effect/http/HttpClient";
7
7
  * refused before more of it is read.
8
8
  */
9
9
  export declare const webhookBodyBytes: number;
10
- /** A GitHub App provider over the host's HTTP client and clock, captured at construction. */
10
+ /**
11
+ * A GitHub App provider over the host's HTTP client, captured at construction: each call it makes
12
+ * runs in the fiber that yields it, a try's, so the token's mint and each read sent again while
13
+ * GitHub's Git doesn't know the token are charged to the try's budget, and the first send of a
14
+ * request is the one `httpOf` charges, as it charges every transport's.
15
+ */
11
16
  export declare const github: (options: SyncGitHubOptions) => Effect.Effect<SyncProvider, GitError, HttpClient.HttpClient>;
@@ -1,16 +1,15 @@
1
- import { runnerIn } from "../store/crossing.mjs";
1
+ import { CallBudget } from "../store/call-count.mjs";
2
2
  import { responseToWeb } from "./http.mjs";
3
- import { fail, gitError } from "../contracts/result.mjs";
3
+ import { fail, gitError, gitErrorFrom } from "../contracts/result.mjs";
4
4
  import { sameHash } from "../auth/token-text.mjs";
5
5
  import { ProviderRefused, saidOf } from "./said.mjs";
6
6
  import { hmacSha256 } from "../protocol/bytes/hmac-sha256.mjs";
7
- import * as Clock$1 from "effect/Clock";
7
+ import * as Clock from "effect/Clock";
8
8
  import * as Effect from "effect/Effect";
9
9
  import * as HttpClient from "effect/http/HttpClient";
10
10
  import * as Option from "effect/Option";
11
11
  import * as Schema from "effect/Schema";
12
12
  import * as Result from "effect/Result";
13
- import * as Context from "effect/Context";
14
13
  import * as Hex from "effect/encoding/Hex";
15
14
  import * as Base64 from "effect/encoding/Base64";
16
15
  import * as HttpClientRequest from "effect/http/HttpClientRequest";
@@ -48,13 +47,18 @@ const tokenPermissions = (access) => ({
48
47
  metadata: "read"
49
48
  });
50
49
  const ownerAndName = /^[\w.-]+\/[\w.-]+$/;
50
+ /** The mint's body: a token for `name` alone, with `access`'s permissions. */
51
+ const tokenRequest = (name, access) => JSON.stringify({
52
+ repositories: [name],
53
+ permissions: tokenPermissions(access)
54
+ });
51
55
  /**
52
56
  * The fields of GitHub's JSON refusal kept: its `message` alone. `documentation_url` links a page
53
57
  * of the docs, which says nothing of this failure, and is a URL, where userinfo could ride.
54
58
  */
55
59
  const githubKept = ["message"];
56
60
  /** A failure of the provider's own: its message names the call and the status, never a token. */
57
- const failed = (call, status) => /* @__PURE__ */ new Error(status === void 0 ? `GitHub didn't answer to ${call}` : `GitHub answered ${status} to ${call}`);
61
+ const failed = (call, status) => gitError("UNAVAILABLE", status === void 0 ? `GitHub didn't answer to ${call}` : `GitHub answered ${status} to ${call}`, { hint: "The job tries again" });
58
62
  /** The DER length of `size` bytes. */
59
63
  const derLength = (size) => {
60
64
  if (size < 128) return [size];
@@ -174,23 +178,28 @@ const signedBody = async (request, mac) => {
174
178
  reader.releaseLock();
175
179
  }
176
180
  };
177
- /** A GitHub App provider over the host's HTTP client and clock, captured at construction. */
181
+ /**
182
+ * A GitHub App provider over the host's HTTP client, captured at construction: each call it makes
183
+ * runs in the fiber that yields it, a try's, so the token's mint and each read sent again while
184
+ * GitHub's Git doesn't know the token are charged to the try's budget, and the first send of a
185
+ * request is the one `httpOf` charges, as it charges every transport's.
186
+ */
178
187
  const github = /* @__PURE__ */ Effect.fnUntraced(function* (options) {
179
188
  if (options.app.webhookSecret === "") return yield* fail("INVALID_ARGUMENT", "app.webhookSecret is empty, and anyone could sign a webhook with it: leave it out, or set GitHub's");
180
189
  const client = yield* HttpClient.HttpClient;
181
- const clock = yield* Effect.clockWith(Effect.succeed);
182
- const context = Context.make(Clock$1.Clock, clock);
183
- const run = runnerIn(context);
184
- const fetch = (request) => run(client.execute(HttpClientRequest.fromWeb(request)).pipe(Effect.flatMap(responseToWeb)), request.signal);
190
+ const sender = (http) => (request) => http.execute(HttpClientRequest.fromWeb(request)).pipe(Effect.flatMap(responseToWeb), Effect.mapError(() => failed("send a request")));
191
+ const send = sender(client);
192
+ const sendCharged = sender(CallBudget.charged(client));
185
193
  const { app } = options;
186
194
  const api = (options.apiUrl ?? "https://api.github.com").replace(/\/$/, "");
187
195
  const git = (options.gitUrl ?? "https://github.com").replace(/\/$/, "");
188
- const signer = () => crypto.subtle.importKey("pkcs8", keyBytes(app.privateKey), rsaSigning, false, ["sign"]).catch(() => {
189
- throw new Error("The GitHub App's private key isn't an RSA key Web Crypto takes");
196
+ const signer = Effect.tryPromise({
197
+ try: () => crypto.subtle.importKey("pkcs8", keyBytes(app.privateKey), rsaSigning, false, ["sign"]),
198
+ catch: () => gitError("INVALID_ARGUMENT", "The GitHub App's private key isn't an RSA key Web Crypto takes")
190
199
  });
191
200
  /** The App's own JWT, signed with its key, for a minute short of 10. */
192
- const jwt = async () => {
193
- const now = Math.floor(await run(Clock$1.currentTimeMillis) / 1e3);
201
+ const jwt = Effect.gen(function* () {
202
+ const now = Math.floor((yield* Clock.currentTimeMillis) / 1e3);
194
203
  const unsigned = `${encodeJson({
195
204
  alg: "RS256",
196
205
  typ: "JWT"
@@ -199,57 +208,60 @@ const github = /* @__PURE__ */ Effect.fnUntraced(function* (options) {
199
208
  exp: now + jwtSeconds,
200
209
  iss: app.appId
201
210
  })}`;
202
- const key = await signer();
203
- const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, encoder.encode(unsigned));
211
+ const key = yield* signer;
212
+ const signature = yield* Effect.tryPromise({
213
+ try: () => crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, encoder.encode(unsigned)),
214
+ catch: () => failed("sign the App's JWT")
215
+ });
204
216
  return `${unsigned}.${Base64Url.encode(new Uint8Array(signature))}`;
205
- };
217
+ });
206
218
  /** A token for the installation, limited to `name`, one of its account's repos, and its Git. */
207
- const tokenFor = async (name, access, signal) => {
219
+ const tokenFor = Effect.fnUntraced(function* (name, access) {
208
220
  const call = "mint a repo's installation token";
209
221
  const init = {
210
222
  method: "POST",
211
223
  headers: {
212
224
  accept: "application/vnd.github+json",
213
- authorization: `Bearer ${await jwt()}`,
225
+ authorization: `Bearer ${yield* jwt}`,
214
226
  "content-type": "application/json",
215
227
  "user-agent": "ref0-git",
216
228
  "x-github-api-version": "2022-11-28"
217
229
  },
218
- body: JSON.stringify({
219
- repositories: [name],
220
- permissions: tokenPermissions(access)
221
- })
230
+ body: tokenRequest(name, access)
222
231
  };
223
- if (signal !== void 0) init.signal = signal;
224
232
  const url = `${api}/app/installations/${encodeURIComponent(app.installationId)}/access_tokens`;
225
233
  const request = new Request(url, init);
226
- const response = await fetch(request).catch(() => {
227
- throw failed(call);
228
- });
234
+ const response = yield* sendCharged(request).pipe(Effect.mapError(() => failed(call)));
229
235
  if (response.status !== 201) {
230
- const said = await saidOf(request, response, githubKept);
231
- throw new ProviderRefused(failed(call, response.status).message, said);
236
+ const said = yield* saidOf(request, response, githubKept);
237
+ const refused = failed(call, response.status);
238
+ return yield* Effect.fail(gitErrorFrom(refused, { cause: new ProviderRefused(refused.message, said) }));
232
239
  }
233
- const answer = decodeToken(await response.json().catch(() => void 0));
234
- if (Option.isNone(answer)) throw failed(call, response.status);
240
+ const body = yield* Effect.promise(() => response.json().catch(() => void 0));
241
+ const answer = decodeToken(body);
242
+ if (Option.isNone(answer)) return yield* Effect.fail(failed(call, response.status));
235
243
  return answer.value.token;
236
- };
237
- /** `fetch`, a read sent again while GitHub's Git doesn't know the new token yet. */
238
- const transport = async (request) => {
239
- if (request.method !== "GET") return fetch(request);
244
+ });
245
+ /**
246
+ * `send`, a read sent again while GitHub's Git doesn't know the new token yet: each send after
247
+ * the first charged here, as `httpOf` charged the first.
248
+ */
249
+ const transport = Effect.fnUntraced(function* (request) {
250
+ if (request.method !== "GET") return yield* send(request);
251
+ let response = yield* send(request.clone());
240
252
  for (const wait of propagationWaits) {
241
- const response = await fetch(request.clone());
242
253
  if (response.status !== 401) return response;
243
- await response.body?.cancel();
244
- await run(Effect.sleep(wait), request.signal);
254
+ yield* Effect.promise(async () => response.body?.cancel());
255
+ yield* Effect.sleep(wait);
256
+ response = yield* sendCharged(request.clone());
245
257
  }
246
- return fetch(request);
247
- };
248
- const remote = async (repo, access, signal) => {
258
+ return response;
259
+ });
260
+ const remote = Effect.fnUntraced(function* (repo, access) {
249
261
  const parts = repo.split("/");
250
- if (!ownerAndName.test(repo) || parts.some((part) => /^\.+$/.test(part))) throw new TypeError(`'${repo}' isn't a GitHub repo's owner/name`);
262
+ if (!ownerAndName.test(repo) || parts.some((part) => /^\.+$/.test(part))) return yield* fail("INVALID_ARGUMENT", `'${repo}' isn't a GitHub repo's owner/name`);
251
263
  const [, name = ""] = parts;
252
- const token = await tokenFor(name, access, signal);
264
+ const token = yield* tokenFor(name, access);
253
265
  return {
254
266
  url: `${git}/${repo}.git`,
255
267
  credentials: {
@@ -258,7 +270,7 @@ const github = /* @__PURE__ */ Effect.fnUntraced(function* (options) {
258
270
  },
259
271
  transport
260
272
  };
261
- };
273
+ });
262
274
  const provider = {
263
275
  name: githubName,
264
276
  remote
@@ -12,4 +12,39 @@ const responseToWeb = (response) => Effect.suspend(() => {
12
12
  headers: response.headers
13
13
  }));
14
14
  });
15
- export { responseToWeb };
15
+ /**
16
+ * `body`, cut once `signal` aborts: it errors with the signal's reason, and its source is
17
+ * cancelled, so no read of it waits past the try that sent it (#2397). A Web body outlives the
18
+ * fiber that took its response, since Effect's request drops a Web request's signal and its client
19
+ * hands the fetch's body over whole, so an interrupt never reaches a read that waits on it. The
20
+ * response is left as it came, its `redirected` and `url` with it, for the callers that read them.
21
+ */
22
+ const bodyUntil = (body, signal) => {
23
+ const reader = body.getReader();
24
+ let stop = () => {};
25
+ return new ReadableStream({
26
+ start: (controller) => {
27
+ stop = () => {
28
+ controller.error(signal.reason);
29
+ reader.cancel(signal.reason).catch(() => void 0);
30
+ };
31
+ if (signal.aborted) stop();
32
+ else signal.addEventListener("abort", stop, { once: true });
33
+ },
34
+ pull: async (controller) => {
35
+ const piece = await reader.read().catch((cause) => {
36
+ signal.removeEventListener("abort", stop);
37
+ throw cause;
38
+ });
39
+ if (signal.aborted) return;
40
+ if (!piece.done) return controller.enqueue(piece.value);
41
+ signal.removeEventListener("abort", stop);
42
+ controller.close();
43
+ },
44
+ cancel: (reason) => {
45
+ signal.removeEventListener("abort", stop);
46
+ return reader.cancel(reason);
47
+ }
48
+ });
49
+ };
50
+ export { bodyUntil, responseToWeb };