@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,30 +1,29 @@
1
1
  import { PrivateRefs } from "../contracts/access.mjs";
2
2
  import { pushRefLimitOf } from "../core/push-decide.mjs";
3
- import { millis } from "../contracts/promises.mjs";
3
+ import { millis } from "../contracts/time.mjs";
4
4
  import { fail } from "../contracts/result.mjs";
5
- import { Tokens } from "../contracts/tokens.mjs";
6
5
  import { Authorize } from "../contracts/authorize.mjs";
7
6
  import { RepoRecords } from "../contracts/repo-records.mjs";
8
- import { Git, host } from "../contracts/git.mjs";
7
+ import { host } from "../contracts/git.mjs";
9
8
  import { Refs } from "../contracts/refs.mjs";
10
9
  import { Rules } from "../contracts/rules.mjs";
11
10
  import { accessOf, audienceOf, authorizer } from "../auth/authorize.mjs";
12
- import { authOf, policyOf } from "../auth/bridge.mjs";
13
11
  import { grantFences } from "../auth/fences.mjs";
14
12
  import { grantAgain, heldGrants } from "../auth/grants.mjs";
15
13
  import { identifier } from "../auth/identify.mjs";
16
- import { tokenCalls, tokenCleanupJob } from "../auth/tokens.mjs";
17
- import { TokensBase, noTokens } from "../auth/tokens-layer.mjs";
14
+ import { tokenCleanupJob } from "../auth/token-cleanup.mjs";
15
+ import { TokensBase, noTokens } from "../auth/tokens-base.mjs";
18
16
  import { blobCalls } from "../core/objects/blobs.mjs";
19
17
  import { commitCalls } from "../core/objects/commits.mjs";
20
18
  import { fileCalls } from "../core/objects/files.mjs";
21
19
  import { mergeCalls } from "../core/objects/merges.mjs";
22
20
  import { tagCalls } from "../core/objects/tags.mjs";
23
21
  import { treeCalls } from "../core/objects/trees.mjs";
22
+ import { acting } from "../core/access.mjs";
24
23
  import { refIndexOf } from "../core/ref-index.mjs";
25
24
  import { callNames } from "../core/call-names.mjs";
26
- import { clocksOf } from "../core/clock.mjs";
27
25
  import { deliveryLog, workFailed } from "../core/events/deliver.mjs";
26
+ import { checkRetired, newRetireStart, writeRetired } from "../core/events/retired.mjs";
28
27
  import { servedSources } from "../core/rules/protect.mjs";
29
28
  import { rulesOf } from "../core/rules/service.mjs";
30
29
  import { refsAs, refsCalls } from "../core/refs.mjs";
@@ -38,70 +37,57 @@ import { refIndexJob, refIndexJobRow } from "../core/ref-index-job.mjs";
38
37
  import { forkCalls } from "../core/forks.mjs";
39
38
  import { repoCalls } from "../core/repos.mjs";
40
39
  import { EventStreams } from "../event-streams/event-streams.mjs";
41
- import { MergeParts } from "../core/merge-parts.mjs";
42
40
  import { streamsOver } from "../event-streams/stream.mjs";
43
- import { attachParts, renamedTo, seamAuthorize } from "../core/seam.mjs";
41
+ import { renamedTo, seamAuthorize } from "../core/seam.mjs";
44
42
  import { checkFetchOver } from "./check-fetch.mjs";
45
43
  import { tokenCallsAs } from "../core/tokens.mjs";
46
44
  import { workCalls } from "../core/work.mjs";
47
- import { coreHttpParts } from "../http/core-parts.mjs";
45
+ import { make } from "../http/core-parts.mjs";
48
46
  import { refusal } from "../http/answers.mjs";
49
- import { LfsBase } from "../lfs/base.mjs";
50
- import { UploadsBase, attachUploads } from "./uploads.mjs";
51
- import { lfsCalls } from "../lfs/calls.mjs";
52
- import { lfsRegistration } from "../lfs/layer.mjs";
53
- import { gitHttp } from "../http/handler.mjs";
54
- import { gitUrlOf, normalBase } from "../http/paths.mjs";
55
- import { pushUploads } from "../http/push-uploads.mjs";
56
- import { signInRegistration } from "../signin/layer.mjs";
57
- import { signInPaths } from "../signin/wire.mjs";
47
+ import { LfsBase, lfsCalls } from "../lfs/base.mjs";
48
+ import { UploadsBase } from "./uploads.mjs";
49
+ import { make as make$1 } from "../http/handler.mjs";
50
+ import { normalBase } from "../http/paths.mjs";
51
+ import { pushUploadJob } from "../http/push-upload-job.mjs";
52
+ import { make as make$2 } from "../http/push-uploads.mjs";
58
53
  import { hostRecordOf, pinOf } from "../store/catalogue.mjs";
59
- import { answerOf } from "../contracts/calls-spent.mjs";
60
54
  import { closedError } from "../store/closed.mjs";
61
- import { clientWentAway, resultCall } from "../store/errors.mjs";
55
+ import { clientWentAway } from "../store/errors.mjs";
62
56
  import { cursorSeal } from "../store/cursor-seal.mjs";
63
57
  import { gitStore } from "../store/git-store.mjs";
64
- import { doorBucket, doorLinks, doorRecords, doorUploads, promisesClock, promisesQueue, promisesStore } from "../store/promises.mjs";
58
+ import { doorBucket, doorLinks, doorQueue, doorRecords, doorUploads, throughBridge } from "../store/door.mjs";
65
59
  import { defaultFetchLimits } from "../storage/fetch.mjs";
66
60
  import { countedBucket } from "../storage/counted-bucket.mjs";
67
61
  import { hostFailures, hostLinks, hostUploads } from "../storage/host-bucket.mjs";
68
62
  import { pushUploadUpkeep } from "../storage/push-uploads.mjs";
69
- import { checkedLimits, countedMost, hookCallsBefore, lessBefore, noScope } from "../store/call-count.mjs";
70
- import { gitJob, jobLimitsOf, jobsWithin } from "../store/job-try.mjs";
71
- import { exitOn, noCall, syncIn, uncounted } from "../store/crossing.mjs";
63
+ import { checkedLimits, countedMost, hookCallsBefore, lessBefore } from "../store/call-count.mjs";
64
+ import { jobLimitsOf, jobsWithin } from "../store/job-try.mjs";
72
65
  import { pruneFloor } from "../storage/rows.mjs";
73
- import { queueJobs } from "../queue/advance.mjs";
74
- import { entryAdderOf, queueCalls } from "../queue/calls.mjs";
75
- import { QueueBase, QueueInternals, queueKeysOf, queueOptions } from "../queue/host.mjs";
76
- import { queuePush } from "../queue/push-option.mjs";
77
- import { buildMillisecondsOf } from "../queue/limits.mjs";
78
- import { topicsOptions } from "../topics/host.mjs";
79
- import { TopicsBase, topicsRegistration } from "../topics/layer.mjs";
80
- import { MergeQueue } from "../contracts/queue.mjs";
81
- import { queueService } from "../queue/layer.mjs";
66
+ import { QueueBase, noQueuePush } from "../queue/base.mjs";
67
+ import { TopicsBase } from "../topics/base.mjs";
82
68
  import { listJob } from "../store/list-job.mjs";
83
69
  import { openExtensions } from "./extension.mjs";
84
- import { JoinedCalls, attachJoins, joinedOf } from "./joined.mjs";
85
- import { bridgeRefusal, serverLife, throughDoor, unavailable } from "./lifecycle.mjs";
86
- import { aroundCalls, callOrMissing, guardedCalls, heldGroup, lazyGroups, providedCalls, signalOf } from "../core/promise.mjs";
87
- import { CoreParts, ObjectsParts, QueueParts, SyncBase, acting } from "../core/parts.mjs";
70
+ import { joinedOf } from "./joined.mjs";
71
+ import { retireErrors, retryDelay } from "./lifecycle.mjs";
72
+ import { aroundCalls, callOrMissing, guardedCall, guardedCalls, heldGroup, lazyGroups, providedCalls } from "../core/promise.mjs";
73
+ import { CoreParts, ObjectsParts, QueueParts, SyncBase } from "../core/parts.mjs";
88
74
  import { SavedCallers, savedCallersOf } from "../core/saved-caller-views.mjs";
89
75
  import { withAudienceMemo } from "../core/ref-view.mjs";
90
76
  import { Changes } from "../core/changes.mjs";
91
77
  import { changes } from "../core/rules/changes.mjs";
92
78
  import { SealedObjects, View, objectsOverViews, viewOver } from "../core/view.mjs";
93
79
  import { IndexedStorage, Objects, Storage } from "../core/objects/objects.mjs";
94
- import * as Clock$1 from "effect/Clock";
80
+ import { pushFilesOf } from "../core/push-files.mjs";
81
+ import { pushRepoOf } from "../core/push-repo.mjs";
82
+ import * as Clock from "effect/Clock";
95
83
  import * as Effect from "effect/Effect";
96
84
  import * as Option from "effect/Option";
97
85
  import * as Cause from "effect/Cause";
98
- import * as Exit from "effect/Exit";
99
86
  import * as EffectResult from "effect/Result";
100
87
  import { Bucket, BucketLinks, BucketUploads, CallLimits, JobQueue, Records, RequestLimits } from "@ref0/infra";
101
88
  import * as Context from "effect/Context";
102
- import * as Layer from "effect/Layer";
103
89
  import * as References from "effect/References";
104
- import * as ManagedRuntime from "effect/ManagedRuntime";
90
+ import * as Duration from "effect/Duration";
105
91
  // src/server/server.ts
106
92
  /**
107
93
  * The server's `fetchLimits`, or a `TypeError` naming the one that isn't a whole number above 0,
@@ -124,84 +110,31 @@ const fetchLimitsOf = (given) => {
124
110
  milliseconds: given.milliseconds
125
111
  };
126
112
  };
127
- /** `factory`'s objects, as they keep their index: `ServerSetup` takes `access` only with one. */
113
+ /** `factory`'s objects, as they keep their index: `access` is read only over them. */
128
114
  const indexedOpen = (factory, input) => factory.open(input);
129
115
  /** `most` as a count's bound: each kind it leaves out unbound. */
130
116
  const boundOf = (most) => ({
131
117
  bucket: most?.bucket ?? Number.POSITIVE_INFINITY,
132
118
  subrequests: most?.subrequests ?? Number.POSITIVE_INFINITY
133
119
  });
134
- /** A build's failure as the legacy server's `Error`, until `createGitServer` is removed in 2c. */
135
- const legacyError = (error) => new Error(error.message, { cause: error });
136
- /** The server's wiring, in its runtime: built once, with the runtime. */
137
- const Wired = /* @__PURE__ */ Context.Service("@ref0/git/server/Wired");
138
- /**
139
- * The groups a face names: every group, less the optional ones `optional` leaves off, `tokens`
140
- * unless `tokensOn`, and `queue` unless `queueOn` or `optional` names one.
141
- */
142
- const namesOf = (optional, tokensOn, queueOn) => {
120
+ /** The groups a joined face names: every group less `topics`, which is the `Topics` service's. */
121
+ const joinedNamesOf = () => {
143
122
  const names = { ...callNames };
144
- if (!tokensOn) delete names.tokens;
145
- if (!queueOn && optional.queue === void 0) delete names.queue;
146
- if (optional.topics === void 0) delete names.topics;
123
+ delete names.topics;
147
124
  return names;
148
125
  };
149
- /** `Merges`' part over the one `loaded` makes: each call waits on that load, which runs once. */
150
- const partsOnce = (loaded) => {
151
- const parts = Effect.map(loaded, (context) => Context.get(context, MergeParts));
152
- return {
153
- mergeTrees: (read, input, allot, call, roots) => Effect.flatMap(parts, (one) => one.mergeTrees(read, input, allot, call, roots)),
154
- lineDiff: (allot) => Effect.flatMap(parts, (one) => one.lineDiff(allot))
155
- };
156
- };
157
- /**
158
- * `createGitServer`'s options onto the Layers that replace them, run once its wiring is built and
159
- * before the seal, in one list: core's inputs first, then the features, `lfs` building
160
- * `Lfs.layer()`, `topics` `Topics.layer` and `pushes.upload` `Git.layerUploads`. 2c-3b deletes
161
- * it, with `createGitServer`.
162
- */
163
- const bridged = (setup) => ({
164
- inputs: setup.access === void 0 ? Layer.empty : Layer.succeed(PrivateRefs, setup.access),
165
- features: Effect.fnUntraced(function* (services, registry) {
166
- if (setup.lfs !== void 0) {
167
- const registration = yield* registry.register({ name: "lfs" });
168
- yield* Effect.provideContext(lfsRegistration(registration, setup.lfs), services);
169
- }
170
- if (setup.topics !== void 0) {
171
- const registration = yield* registry.register({
172
- name: "topics",
173
- scopes: ["git/topic/", "git/topics"]
174
- });
175
- const queue = Context.getOrUndefined(services, QueueInternals);
176
- if (queue === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("The topics bridge requires a queue"));
177
- yield* Effect.provideContext(topicsRegistration(registration, topicsOptions(setup.topics)).pipe(Effect.provideService(QueueInternals, queue), Effect.provideService(MergeQueue, queueService(queue))), services);
178
- }
179
- if (setup.signIn !== void 0) {
180
- const registration = yield* registry.register({
181
- name: "signin",
182
- scopes: ["git/signin"]
183
- });
184
- yield* Effect.provideContext(signInRegistration(registration, setup.signIn), services);
185
- }
186
- const upload = setup.pushes?.upload;
187
- if (upload !== void 0 && Context.get(services, UploadsBase).staging !== void 0) yield* Effect.provideContext(attachUploads(upload), services);
188
- })
189
- });
190
126
  /** Git's own wiring over the adapter's services, as the runtime's build runs it. */
191
127
  const wireServer = (options, wiring) => {
192
- const { adapter, merges, optional, fetchLimits, deciders, grants, extensions, guard, through, closing } = wiring;
128
+ const { adapter, fetchLimits, files, repo, deciders, grants, extensions, guard, through, closing } = wiring;
193
129
  const runtimeClock = wiring.clock;
194
- const queueOf = optional.queue;
195
- const { store, jobs, records: rawRecords } = adapter;
196
- const { clock, now } = clocksOf(adapter.clock);
130
+ const { jobs, records: store } = adapter;
131
+ const now = Effect.sync(() => runtimeClock.currentTimeMillisUnsafe());
197
132
  const counted = adapter.bucket === void 0 ? void 0 : countedBucket(adapter.bucket);
198
- if (options.lfs !== void 0 && counted === void 0) throw new TypeError("lfs() keeps its objects in the adapter's bucket: give the adapter a bucket");
199
133
  const callLimits = lessBefore(checkedLimits(adapter.callLimits, "The adapter's callLimits."));
200
- const jobLimits = jobLimitsOf(adapter.callLimits);
201
134
  const opening = {
202
135
  store: gitStore(store),
203
136
  bucket: adapter.objectsBucket,
204
- clock,
137
+ clock: runtimeClock,
205
138
  fetchLimits,
206
139
  callLimits
207
140
  };
@@ -209,24 +142,31 @@ const wireServer = (options, wiring) => {
209
142
  const indexed = wiring.access === void 0 ? void 0 : indexedOpen(options.objects, opening);
210
143
  const objects = indexed ?? options.objects.open(opening);
211
144
  const sealed = indexed === void 0 ? new SealedObjects(objects) : SealedObjects.indexed(indexed);
212
- const cleanup = tokenCleanupJob(now);
145
+ const cleanup = tokenCleanupJob(store, now);
213
146
  const { registry } = extensions;
214
147
  const events = deliveryLog({
215
148
  store,
216
149
  now,
217
150
  fetchLimits
218
151
  });
219
- registry.bindDeliveries((registered) => events.fill(registered));
220
- const onFailure = workFailed(events, now);
152
+ const retired = options.events?.retired ?? [];
153
+ registry.bindDeliveries((registered) => {
154
+ checkRetired(registered.map((delivery) => delivery.name), retired);
155
+ return events.fill(registered);
156
+ });
157
+ const onFailure = workFailed(store, events, now);
221
158
  const upkeep = upkeepsOf([...counted === void 0 ? [] : [pushUploadUpkeep(counted, adapter.uploads)], registry.upkeep]);
222
159
  const index = objects.index === void 0 ? void 0 : indexJob({
160
+ store,
223
161
  objects: sealed,
224
162
  now,
225
163
  events,
226
- repackJobRow: () => repackJobRow(repack)
164
+ repackJobRow: () => repackJobRow(repack),
165
+ cpuMs: adapter.requestLimits.cpuMs
227
166
  });
228
167
  const indexRow = index === void 0 ? void 0 : (round) => indexJobRow(index, round);
229
168
  const repack = repackJob({
169
+ store,
230
170
  objects: sealed,
231
171
  now,
232
172
  fetchLimits,
@@ -236,15 +176,20 @@ const wireServer = (options, wiring) => {
236
176
  indexJobRow: indexRow
237
177
  });
238
178
  const refIndex = refIndexOf(wiring.access, registry.hiddenRefs);
239
- const rebuild = refIndex === void 0 ? void 0 : refIndexJob({ index: refIndex });
179
+ const rebuild = refIndex === void 0 ? void 0 : refIndexJob({
180
+ store,
181
+ index: refIndex
182
+ });
240
183
  const purge = purgeJob({
184
+ store,
241
185
  now,
242
186
  fetchLimits,
243
187
  parts: [registry.purge],
244
- scopes: registry.repoScopes
188
+ scopes: registry.repoScopes,
189
+ deliveries: events.deliveries
245
190
  });
246
191
  const own = [
247
- listJob,
192
+ listJob(store),
248
193
  repack,
249
194
  purge
250
195
  ];
@@ -253,7 +198,6 @@ const wireServer = (options, wiring) => {
253
198
  own.push(cleanup);
254
199
  const gits = registry.bridge("git");
255
200
  gits.knowJobs(own);
256
- jobs.register(...jobsWithin(jobLimits, own));
257
201
  const decides = {
258
202
  policy: deciders.policy,
259
203
  grants
@@ -314,35 +258,28 @@ const wireServer = (options, wiring) => {
314
258
  });
315
259
  const stored = Context.make(Storage, objects).pipe(Context.add(ObjectsParts, {
316
260
  objects: sealed,
317
- fetchLimits
261
+ fetchLimits,
262
+ files,
263
+ repo
318
264
  }), Context.add(Objects, objectsOverViews), Context.add(Changes, changes));
319
- const base = Context.make(CoreParts, parts).pipe(Context.add(Rules, wiring.rules), Context.merge(indexed === void 0 ? stored : Context.add(stored, IndexedStorage, indexed)), Context.add(QueueParts, { jobs }), Context.add(Authorize, decider), Context.add(Clock$1.Clock, runtimeClock), Context.merge(wiring.logging));
320
- const merging = merges === void 0 ? base : Context.merge(base, merges);
321
- const viewed = Context.add(merging, View, viewOver(merging));
265
+ const base = Context.make(CoreParts, parts).pipe(Context.add(Rules, wiring.rules), Context.merge(indexed === void 0 ? stored : Context.add(stored, IndexedStorage, indexed)), Context.add(QueueParts, { jobs }), Context.add(Authorize, decider), Context.add(Clock.Clock, runtimeClock), Context.merge(wiring.logging));
266
+ const viewed = Context.add(base, View, viewOver(base));
322
267
  const needs = Context.add(viewed, Refs, providedCalls(refsCalls, viewed));
323
268
  const streams = streamsOver({
324
- clock,
269
+ clock: runtimeClock,
325
270
  guard,
326
271
  closing,
327
272
  through
328
273
  }, needs);
329
- const queueHost = queueOf === void 0 ? void 0 : {
330
- needs,
331
- records: rawRecords,
332
- options: queueOf,
333
- keys: wiring.optional.queueKeys,
334
- buildMilliseconds: buildMillisecondsOf(adapter.requestLimits.cpuMs)
335
- };
336
274
  const queueHeld = wiring.queue;
337
- queueHeld.host = queueHost;
338
275
  const queueBase = QueueBase.of({
339
- records: rawRecords,
276
+ records: store,
340
277
  needs,
341
278
  onFailure,
342
279
  cpuMs: adapter.requestLimits.cpuMs,
343
- attach: (host) => Effect.suspend(() => {
344
- if (queueHeld.host !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server has a merge queue: provide MergeQueue.layer once"));
345
- queueHeld.host = host;
280
+ attach: (queue) => Effect.suspend(() => {
281
+ if (queueHeld.attached !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server has a merge queue: provide MergeQueue.layer once"));
282
+ queueHeld.attached = queue;
346
283
  return Effect.void;
347
284
  })
348
285
  });
@@ -356,43 +293,52 @@ const wireServer = (options, wiring) => {
356
293
  if (lfsAttached !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server has Git LFS: provide Lfs.layer once"));
357
294
  lfsAttached = lfs;
358
295
  return registry.addCheck(lfs.check);
359
- })
296
+ }),
297
+ copy: Effect.sync(() => lfsAttached?.copy)
360
298
  });
361
299
  const { uploads } = adapter;
362
300
  const staging = counted === void 0 || uploads === void 0 ? void 0 : {
363
301
  bucket: counted,
364
302
  uploads
365
303
  };
304
+ let httpParts;
305
+ const stepping = staging !== void 0 && objects.stage !== void 0 && objects.receiveStep !== void 0;
306
+ if (stepping) {
307
+ const stepJobs = [pushUploadJob({
308
+ ...staging,
309
+ needs,
310
+ cpuMs: adapter.requestLimits.cpuMs,
311
+ http: () => {
312
+ if (httpParts === void 0) throw new TypeError("A push upload landed before its server was built");
313
+ return httpParts;
314
+ }
315
+ })];
316
+ gits.knowJobs(stepJobs);
317
+ own.push(...stepJobs);
318
+ }
366
319
  let uploadsAttached;
367
320
  const uploadsBase = UploadsBase.of({
368
321
  staging,
369
322
  attach: (above) => Effect.suspend(() => {
370
323
  if (staging === void 0 || uploadsAttached !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server takes push uploads: provide Git.layerUploads once"));
371
- uploadsAttached = pushUploads(needs, staging, above);
324
+ uploadsAttached = make$2(needs, staging, above, adapter.requestLimits.cpuMs);
372
325
  return Effect.void;
373
326
  })
374
327
  });
375
- if (queueHost !== void 0) {
376
- registry.bridge("queue", "refs/queue/");
377
- const queueJobList = queueJobs(queueHost, onFailure).map((job) => job(gitJob));
378
- gits.knowJobs(queueJobList);
379
- jobs.register(...jobsWithin(jobLimits, queueJobList));
380
- }
381
328
  let topicsAttached;
382
329
  const topicsBase = TopicsBase.of({ attach: (service) => Effect.sync(() => {
383
330
  topicsAttached = service;
384
331
  }) });
385
332
  const tokensHeld = wiring.tokens;
386
333
  const tokensBase = TokensBase.of({
387
- attach: Effect.suspend(() => {
334
+ store,
335
+ now,
336
+ cleanup,
337
+ events,
338
+ attach: (calls) => Effect.suspend(() => {
388
339
  if (tokensHeld.calls !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server has Git's own tokens: provide Tokens.layer() once"));
389
- tokensHeld.calls = tokenCalls({
390
- store,
391
- now,
392
- cleanup,
393
- events
394
- });
395
- return Effect.succeed(tokensHeld.calls);
340
+ tokensHeld.calls = calls;
341
+ return Effect.void;
396
342
  }),
397
343
  held: Effect.sync(() => tokensHeld.calls === void 0 ? void 0 : {
398
344
  tokens: tokensHeld.calls,
@@ -402,15 +348,6 @@ const wireServer = (options, wiring) => {
402
348
  refuse: (error) => refusal(error, true)
403
349
  })
404
350
  });
405
- if (optional.tokens !== void 0) {
406
- registry.bridge("tokens");
407
- tokensHeld.calls = tokenCalls({
408
- store,
409
- now,
410
- cleanup,
411
- events
412
- });
413
- }
414
351
  const identify = identifier({
415
352
  store,
416
353
  tokens: () => tokensHeld.calls !== void 0,
@@ -419,20 +356,17 @@ const wireServer = (options, wiring) => {
419
356
  held: grants,
420
357
  now
421
358
  });
422
- const decided = Context.add(records, Authorize, decider).pipe(Context.add(Refs, Context.get(needs, Refs)), Context.add(Rules, wiring.rules), Context.add(Objects, objectsOverViews), Context.merge(callServices(needs)), Context.add(Events, { log: events }), Context.add(QueueBase, queueBase), Context.add(SyncBase, {
359
+ const decided = Context.add(records, Authorize, decider).pipe(Context.add(Refs, Context.get(needs, Refs)), Context.add(Rules, wiring.rules), Context.add(Objects, objectsOverViews), Context.merge(callServices(needs, (effect) => withAudienceMemo(guardedCall(wiring.through)(effect)))), Context.add(Events, { log: events }), Context.add(QueueBase, queueBase), Context.add(SyncBase, {
423
360
  needs,
424
361
  pushRefsMost: pushRefLimitOf(refIndex),
425
362
  through: wiring.through
426
- }), Context.add(SavedCallers, savedCallersOf(needs, entryAdderOf)), Context.add(LfsBase, lfsBase), Context.add(UploadsBase, uploadsBase), Context.add(TopicsBase, topicsBase), Context.add(TokensBase, tokensBase));
427
- const queuedServices = queueHost === void 0 ? decided : decided.pipe(Context.add(QueueInternals, queueHost), Context.add(MergeQueue, queueService(queueHost)));
428
- const withTokens = tokensHeld.calls === void 0 ? queuedServices : Context.add(queuedServices, Tokens, tokensHeld.calls);
429
- const streamed = Context.add(withTokens, EventStreams, { feed: streams.feed });
430
- const services = merges === void 0 ? streamed : Context.merge(streamed, merges);
363
+ }), Context.add(SavedCallers, savedCallersOf(needs, (entry) => queueHeld.attached === void 0 ? Effect.succeed(void 0) : queueHeld.attached.entryAdder(entry))), Context.add(LfsBase, lfsBase), Context.add(UploadsBase, uploadsBase), Context.add(TopicsBase, topicsBase), Context.add(TokensBase, tokensBase));
364
+ const services = Context.add(decided, EventStreams, { feed: streams.feed });
431
365
  /**
432
366
  * Every group of the server's calls deciding for `bound`, over `needs`: the one list `callsAs`
433
367
  * and `hostCalls` both build from, so a group added to one is in the other. `Git.host`'s are host
434
- * code's, as `asHost` says. An optional group is there when its host is, which `optional` alone
435
- * decides, as it does the server's face's names.
368
+ * code's, as `asHost` says. An optional group is there once its feature attached, as
369
+ * `tokensHeld` and `queueHeld` hold it.
436
370
  */
437
371
  const groupsOf = (bound) => {
438
372
  const over = (calls) => aroundCalls(calls, (effect) => Effect.provideContext(acting(bound, effect), needs));
@@ -449,8 +383,8 @@ const wireServer = (options, wiring) => {
449
383
  merges: over(mergeCalls(bound)),
450
384
  lfs: over(lfsCalls(() => lfsAttached?.read, bound))
451
385
  };
452
- const queue = queueHeld.host;
453
- if (queue !== void 0) groups.queue = aroundCalls(queueCalls(queue, bound), (effect) => Effect.provideContext(acting(bound, effect), queue.needs));
386
+ const queue = queueHeld.attached;
387
+ if (queue !== void 0) groups.queue = aroundCalls(queue.calls(bound), (effect) => Effect.provideContext(acting(bound, effect), queue.host.needs));
454
388
  if (topicsAttached !== void 0) {
455
389
  const topics = topicsAttached;
456
390
  groups.topics = {
@@ -468,18 +402,18 @@ const wireServer = (options, wiring) => {
468
402
  const callsAs = (bound) => groupsOf(bound);
469
403
  const { basePath } = wiring;
470
404
  const requestMost = boundOf(adapter.callLimits);
471
- const served = {
405
+ const clockedIdentify = (request) => Effect.provideService(identify(request), Clock.Clock, runtimeClock);
406
+ const rest = {
472
407
  basePath,
473
- needs,
474
408
  callsFor: (caller) => aroundCalls(guardedCalls(callsAs(caller), through), withAudienceMemo),
475
- tokensOn: Effect.sync(() => tokensHeld.calls !== void 0),
476
- identify: (request) => through(identify(request)),
409
+ tokensOn: through(Effect.sync(() => tokensHeld.calls !== void 0)),
410
+ identify: (request) => through(clockedIdentify(request)),
477
411
  authorize: (input) => through(Effect.provideContext(seamAuthorize(input), needs)),
478
412
  renamedTo: (caller, repo) => through(Effect.provideContext(renamedTo(caller, repo), needs)),
479
413
  listen: (caller, repo, after) => through(Effect.suspend(() => !keepsEvents(events) ? fail("FAILED_PRECONDITION", "This server keeps no events", { hostHint: "Its host registers a delivery, with Git.register, to keep them" }) : streams.open(caller, repo, after))),
480
414
  requestMost
481
415
  };
482
- const httpOptions = { queue: queuePush(() => queueHeld.host) };
416
+ const httpOptions = { queue: (...push) => (queueHeld.attached?.push ?? noQueuePush)(...push) };
483
417
  if (options.maxDuration !== void 0) httpOptions.maxDuration = millis(options.maxDuration);
484
418
  if (objects.pushObjectsMost !== void 0) httpOptions.pushObjectsMost = objects.pushObjectsMost;
485
419
  const fetchHooks = wiring.rules.fetch.length === 0 ? 0 : 1;
@@ -490,334 +424,180 @@ const wireServer = (options, wiring) => {
490
424
  httpOptions.calls = before(fetchHooks)(countedMost(objects) ?? callLimits);
491
425
  httpOptions.pushCalls = before(0)(callLimits);
492
426
  httpOptions.lfs = () => lfsAttached?.service;
493
- httpOptions.uploads = () => uploadsAttached;
494
- const http = gitHttp(coreHttpParts(served, httpOptions));
427
+ httpOptions.uploads = () => stepping ? uploadsAttached : void 0;
428
+ httpParts = make({
429
+ basePath,
430
+ identify: rest.identify,
431
+ renamedTo: rest.renamedTo
432
+ }, httpOptions);
433
+ const http = make$1(httpParts);
495
434
  return {
496
- parts: served,
497
- adapter: {
498
- store,
499
- bucket: adapter.bucket,
500
- clock: adapter.clock
501
- },
502
- get calls() {
503
- return callsAs();
504
- },
435
+ rest,
436
+ needs,
437
+ requestMost,
438
+ adapter: { bucket: adapter.bucket },
505
439
  callsAs,
506
440
  get hostCalls() {
507
441
  return groupsOf(host);
508
442
  },
509
- identify,
443
+ identify: clockedIdentify,
510
444
  http,
511
445
  services,
512
446
  checkSources: () => {
513
- if (queueHeld.host === void 0) servedSources(wiring.rules.push);
514
- }
447
+ if (queueHeld.attached === void 0) servedSources(wiring.rules.push);
448
+ },
449
+ retire: Effect.map(newRetireStart(), (start) => writeRetired(store, retired, start)),
450
+ ownJobs: own
515
451
  };
516
452
  };
517
- /** Whether `adapter` is several Layers. */
518
- const signInPathSet = new Set(Object.values(signInPaths));
519
- const isLayers = (adapter) => Array.isArray(adapter);
520
- /**
521
- * A Git server over one adapter: its calls, `identify`, and `fetch` and `route`, Git's Smart HTTP
522
- * over its core and its sign-in, which answer `404` and `undefined` outside their URLs. Its
523
- * runtime builds the adapter's Layers and Git's wiring once the tick that made it ends, which
524
- * registers Git's jobs on the adapter's queue, and never runs them: the host starts them.
525
- */
526
- const createGitServer = (options) => serverWith(options, () => ({
527
- policy: policyOf(options.authorize),
528
- auth: authOf(options.auth)
529
- }));
530
- /**
531
- * `createGitServer` deciding with `decidersOf`'s answer, which it asks once as the server builds:
532
- * `createGitServer` gives its options' hooks. Internal: no entry exports it, so a host
533
- * gives a `Policy` only through `Git.layer`.
534
- */
535
- const serverWith = (options, decidersOf, features) => openServer(options, decidersOf, "build", features).server;
453
+ /** Interrupts as `signal` aborts, as a client that went away or a server that closed stops its run. */
454
+ const interruptedBy = (signal) => Effect.callback((resume) => {
455
+ const interrupt = () => resume(Effect.interrupt);
456
+ if (signal.aborted) return interrupt();
457
+ signal.addEventListener("abort", interrupt, { once: true });
458
+ return Effect.sync(() => signal.removeEventListener("abort", interrupt));
459
+ });
536
460
  /**
537
- * `serverWith`, sealing as its build ends, or `later`, when `Git.layer` seals once its features
538
- * have registered, after this build.
461
+ * The server, built in the host's own build: its wiring over the host's services, with no runtime
462
+ * of its own, so its build's failure is the host's, and its close is the host's scope's. A call in
463
+ * flight as the scope closes dies with the closed error, as a joined package's does.
539
464
  */
540
- const openServer = (options, decidersOf, sealing, features) => {
541
- const setup = options;
542
- const bridges = bridged(setup);
543
- if (setup.signIn !== void 0 && setup.tokens === void 0) throw new TypeError("signIn mints tokens: pass tokens() too");
544
- if (setup.access !== void 0 && setup.objects.indexed !== true) throw new TypeError("access hides refs, which needs objects that follow them: pass packs()");
545
- const queueOf = setup.queue === void 0 ? void 0 : queueOptions(setup.queue);
546
- const listed = (setup.rules ?? []).filter((rule) => !Effect.isEffect(rule) && rule.kind === "push");
547
- if (queueOf === void 0 && sealing === "build") servedSources(listed);
548
- if (setup.topics !== void 0 && queueOf === void 0) throw new TypeError("topics merge through each repo’s queue: pass queue too");
549
- if (queueOf !== void 0 && setup.xdiff === void 0) throw new TypeError("the merge queue merges trees: pass xdiff too");
465
+ const buildServer = /* @__PURE__ */ Effect.fnUntraced(function* (setup, decidersOf) {
550
466
  const fetchLimits = fetchLimitsOf(setup.fetchLimits);
467
+ const files = pushFilesOf(setup.pushes?.files);
468
+ const repo = pushRepoOf(setup.pushes?.repo);
551
469
  const grants = heldGrants();
552
470
  const basePath = normalBase(setup.basePath ?? "");
553
- const extensions = openExtensions(basePath);
554
- const joins = [];
555
- const life = serverLife();
556
- const isClosed = () => life.admit("call") === "closed";
471
+ const closer = new AbortController();
472
+ const closing = closer.signal;
473
+ yield* Effect.addFinalizer(() => Effect.sync(() => closer.abort(closedError())));
474
+ const isClosed = () => closing.aborted;
557
475
  const guard = Effect.suspend(() => isClosed() ? Effect.die(closedError()) : Effect.void);
558
476
  const door = {
559
- refusal: () => bridgeRefusal(life),
560
- closing: life.closing
561
- };
562
- const through = throughDoor(life);
563
- const closingWith = (signal) => signal === void 0 ? life.closing : AbortSignal.any([signal, life.closing]);
564
- const optional = {
565
- queue: queueOf,
566
- queueKeys: setup.queue === void 0 ? void 0 : queueKeysOf(setup.queue),
567
- topics: setup.topics,
568
- tokens: setup.tokens
477
+ refusal: () => isClosed() ? closedError() : void 0,
478
+ closing
569
479
  };
480
+ const through = throughBridge(door);
481
+ const closingWith = (signal) => signal === void 0 ? closing : AbortSignal.any([signal, closing]);
570
482
  const tokensHeld = { calls: void 0 };
571
- const queueHeld = { host: void 0 };
572
- const names = namesOf(optional, optional.tokens !== void 0, false);
573
- const joinedNames = namesOf(optional, true, true);
574
- const queueOn = () => queueOf !== void 0 || queueHeld.host !== void 0;
483
+ const queueHeld = { attached: void 0 };
484
+ const joinedNames = joinedNamesOf();
485
+ const queueOn = () => queueHeld.attached !== void 0;
575
486
  const joinedCall = (calls, group, name) => callOrMissing(calls, group, name, () => Effect.fail(noTokens));
576
- const runCall = async (effect, crossing, signal) => {
577
- if (isClosed()) throw closedError();
578
- const exit = await exitOn(runtime, Effect.result(withAudienceMemo(effect)), crossing, closingWith(signal));
579
- if (isClosed()) throw closedError();
580
- const answer = Exit.isFailure(exit) ? Exit.failCause(Cause.map(exit.cause, (error) => unavailable(Cause.fail(error)))) : EffectResult.isSuccess(exit.value) ? Exit.succeed(exit.value.success) : Exit.fail(exit.value.failure);
581
- return answerOf(answer, signal);
582
- };
583
- let registerLater;
584
- let checkLater;
585
- const seal = Effect.suspend(() => {
586
- const register = registerLater;
587
- const check = checkLater;
588
- if (register === void 0 || check === void 0) return Effect.die(/* @__PURE__ */ new Error("Git's registry seals after the server's build"));
589
- return Effect.flatMap(extensions.registry.seal(), (jobs) => Effect.sync(() => {
590
- check();
591
- register(jobs);
592
- }));
487
+ const records = yield* Records.Records;
488
+ const queue = yield* JobQueue.JobQueue;
489
+ const callLimits = yield* CallLimits.CallLimits;
490
+ const extensions = openExtensions({
491
+ basePath,
492
+ fetchWindow: Duration.millis(fetchLimits.milliseconds),
493
+ requestMost: boundOf(callLimits)
593
494
  });
594
- const wiring = Layer.effectContext(Effect.gen(function* () {
595
- const records = yield* Records.Records;
596
- const queue = yield* JobQueue.JobQueue;
597
- const callLimits = yield* CallLimits.CallLimits;
598
- const requestLimits = yield* Effect.serviceOption(RequestLimits.RequestLimits);
599
- const bucket = yield* Effect.serviceOption(Bucket.Bucket);
600
- const links = yield* Effect.serviceOption(BucketLinks.BucketLinks);
601
- const uploads = yield* Effect.serviceOption(BucketUploads.BucketUploads);
602
- const clock = yield* Effect.clockWith(Effect.succeed);
603
- const logging = Context.make(References.CurrentLoggers, yield* References.CurrentLoggers).pipe(Context.add(References.MinimumLogLevel, yield* References.MinimumLogLevel));
604
- const xdiff = setup.xdiff;
605
- const loaded = xdiff === void 0 ? void 0 : yield* Effect.cached(Effect.flatMap(Effect.promise(() => import("../merges/merges.mjs")), ({ mergesContext }) => mergesContext({ xdiff }, objectsOverViews)));
606
- const merges = loaded === void 0 ? void 0 : Context.make(MergeParts, partsOnce(loaded));
607
- if (Option.isSome(yield* Effect.serviceOption(Rules))) return yield* Effect.die(/* @__PURE__ */ new TypeError("The adapter provides Rules; pass rules through createGitServer's rules option"));
608
- const rules = yield* rulesOf(setup.rules ?? []);
609
- const context = yield* Effect.context();
610
- const guardedRecords = doorRecords(records, context, door);
611
- extensions.registry.bindRecords(guardedRecords);
612
- const adapter = {
613
- records: guardedRecords,
614
- store: promisesStore(records, context, door),
615
- jobs: promisesQueue(queue, context, door),
616
- bucket: Option.isSome(bucket) ? doorBucket(hostFailures(bucket.value), context, door) : void 0,
617
- objectsBucket: Option.isSome(bucket) ? doorBucket(bucket.value, context, door) : void 0,
618
- links: Option.isSome(links) ? doorLinks(hostLinks(links.value), context, door) : void 0,
619
- uploads: Option.isSome(uploads) ? doorUploads(hostUploads(uploads.value), context, door) : void 0,
620
- clock: promisesClock(clock, context, door),
621
- callLimits,
622
- requestLimits: Option.getOrElse(requestLimits, () => ({}))
623
- };
624
- const given = {
625
- adapter,
626
- merges,
627
- rules,
628
- optional,
629
- tokens: tokensHeld,
630
- queue: queueHeld,
631
- fetchLimits,
632
- deciders: decidersOf(),
633
- grants,
634
- extensions,
635
- basePath,
636
- clock,
637
- logging,
638
- access: Option.getOrUndefined(yield* Effect.serviceOption(PrivateRefs))
639
- };
640
- const wired = yield* Effect.sync(() => wireServer(setup, {
641
- ...given,
642
- guard,
643
- closing: life.closing,
644
- through,
645
- runtime
646
- }));
647
- yield* bridges.features(wired.services, extensions.registry);
648
- const over = wired.services.pipe(Context.add(Git, {
649
- register: extensions.registry.register,
650
- route: (request) => Effect.map(Effect.promise(() => server.route(request)), Option.fromUndefinedOr),
651
- handle: (request) => Effect.promise(() => server.fetch(request)),
652
- identify: (request) => resultCall(() => server.identify(request)),
653
- checkFetch: checkFetchOver(Effect.succeed(wired.parts))
654
- }), Context.add(JoinedCalls, joinedOf(server, wired)));
655
- const featureServices = features === void 0 ? Context.empty() : yield* Layer.build(features).pipe(Effect.provide(over), Effect.mapError(legacyError));
656
- const joinedOver = Context.merge(over, featureServices).pipe(Context.merge(loaded === void 0 ? Context.empty() : yield* loaded));
657
- for (const join of joins) {
658
- const exit = yield* join.build(joinedOver);
659
- if (Exit.isFailure(exit)) return yield* Effect.mapError(Effect.failCause(exit.cause), legacyError);
660
- }
661
- const jobLimits = jobLimitsOf(callLimits);
662
- const register = (jobs) => adapter.jobs.register(...jobsWithin(jobLimits, jobs));
663
- if (sealing === "build") {
664
- yield* Effect.sync(wired.checkSources);
665
- register(yield* extensions.registry.seal());
666
- } else {
667
- registerLater = register;
668
- checkLater = wired.checkSources;
669
- }
670
- const built = Context.merge(Context.add(wired.services, Wired, wired), featureServices);
671
- return loaded === void 0 ? built : Context.merge(built, yield* loaded);
672
- }));
673
- const { adapter } = setup;
674
- const merged = isLayers(adapter) ? Layer.mergeAll(Layer.empty, ...adapter) : adapter;
675
- const host = Layer.provideMerge(bridges.inputs, merged);
676
- const runtime = ManagedRuntime.make(Layer.suspend(() => {
677
- life.move({ kind: "building" });
678
- return Layer.provideMerge(wiring, host);
679
- }).pipe(Layer.tap((built) => Effect.sync(() => {
680
- life.move({
681
- kind: "built",
682
- wired: Context.get(built, Wired)
683
- });
684
- })), Layer.tapCause((cause) => life.move({
685
- kind: "failed",
686
- cause
687
- }) ? Effect.logError("The Git server failed to start", cause) : Effect.void)));
688
- /**
689
- * The server's build as the door answers it, every call's way in: built, or failed, starting or
690
- * joining the build while it isn't settled. A closed server throws, before the build or after.
691
- */
692
- const enter = async () => {
693
- const settled = () => {
694
- const admitted = life.admit("call");
695
- if (admitted === "closed") throw closedError();
696
- const now = life.now();
697
- if (admitted === "run" && now.kind === "built") return Exit.succeed(now.wired);
698
- return admitted === "unavailable" && now.kind === "failed" ? Exit.failCause(now.cause) : void 0;
699
- };
700
- const before = settled();
701
- if (before !== void 0) return before;
702
- const exit = await exitOn(runtime, Effect.service(Wired), noCall);
703
- return settled() ?? exit;
495
+ const requestLimits = yield* Effect.serviceOption(RequestLimits.RequestLimits);
496
+ const bucket = yield* Effect.serviceOption(Bucket.Bucket);
497
+ const links = yield* Effect.serviceOption(BucketLinks.BucketLinks);
498
+ const uploads = yield* Effect.serviceOption(BucketUploads.BucketUploads);
499
+ const clock = yield* Effect.clockWith(Effect.succeed);
500
+ const logging = Context.make(References.CurrentLoggers, yield* References.CurrentLoggers).pipe(Context.add(References.MinimumLogLevel, yield* References.MinimumLogLevel));
501
+ const rules = yield* rulesOf(setup.rules ?? []);
502
+ const host = Context.omit(Rules)(yield* Effect.context());
503
+ const guardedRecords = doorRecords(records, host, door);
504
+ extensions.registry.bindRecords(guardedRecords);
505
+ const adapter = {
506
+ records: guardedRecords,
507
+ jobs: doorQueue(queue, host, door, () => clock.currentTimeMillisUnsafe()),
508
+ bucket: Option.isSome(bucket) ? doorBucket(hostFailures(bucket.value), host, door) : void 0,
509
+ objectsBucket: Option.isSome(bucket) ? doorBucket(bucket.value, host, door) : void 0,
510
+ links: Option.isSome(links) ? doorLinks(hostLinks(links.value), host, door) : void 0,
511
+ uploads: Option.isSome(uploads) ? doorUploads(hostUploads(uploads.value), host, door) : void 0,
512
+ callLimits,
513
+ requestLimits: Option.getOrElse(requestLimits, () => ({}))
704
514
  };
705
- const wired = Effect.flatMap(Effect.promise(enter), (exit) => Exit.isSuccess(exit) ? Effect.succeed(exit.value) : Effect.fail(unavailable(exit.cause)));
706
- /** `use`'s Effect over the built server, its `Result`, or `UNAVAILABLE` once the build failed. */
707
- const run = async (use, crossing, signal) => {
708
- const built = await enter();
709
- if (Exit.isFailure(built)) return {
710
- kind: "error",
711
- error: unavailable(built.cause)
712
- };
713
- return runCall(use(built.value), crossing, signal);
714
- };
715
- /**
716
- * The calls over the built server's `calls`, made before it's built: a host's, each counted into
717
- * `budget` when given, and into no request's scope otherwise.
718
- */
719
- const callsOver = (calls, budget, given = names) => lazyGroups(given, (group, name, args) => run((built) => joinedCall(calls(built), group, name)(...args), budget === void 0 ? noScope : {
720
- calls: void 0,
721
- budget
722
- }, signalOf(args)));
515
+ const access = Option.getOrUndefined(yield* Effect.serviceOption(PrivateRefs));
516
+ const wired = yield* Effect.sync(() => wireServer(setup, {
517
+ adapter,
518
+ rules,
519
+ tokens: tokensHeld,
520
+ queue: queueHeld,
521
+ fetchLimits,
522
+ files,
523
+ repo,
524
+ deciders: decidersOf(),
525
+ grants,
526
+ extensions,
527
+ basePath,
528
+ clock,
529
+ logging,
530
+ access,
531
+ guard,
532
+ closing,
533
+ through
534
+ }));
535
+ const jobLimits = jobLimitsOf(callLimits);
536
+ yield* Effect.orDie(adapter.jobs.addJobs(...jobsWithin(jobLimits, wired.ownJobs)));
537
+ const seal = Effect.flatMap(extensions.registry.seal(), (jobs) => Effect.sync(wired.checkSources).pipe(Effect.andThen(Effect.all(extensions.registry.sealChecks(), { discard: true })), Effect.andThen(Effect.orDie(adapter.jobs.addJobs(...jobsWithin(jobLimits, jobs))))));
723
538
  /**
724
- * `answering`'s answer to `request`. A client that went away, by its signal or mid-body, gets an
725
- * empty 499, as Effect's HTTP server answers one, logged once at info with the path alone: an
726
- * archive's link carries its token in the query. Any other interrupt throws, as it did before.
539
+ * `answering`'s answer to `request`, in the caller's fiber, stopped as the client goes away or the
540
+ * server closes. A client that went away, by its signal or mid-body, gets an empty 499, as
541
+ * Effect's HTTP server answers one, logged once at info with the path alone: an archive's link
542
+ * carries its token in the query. A closed server dies with the closed error.
727
543
  */
728
- const answerTo = async (request, answering) => {
729
- if (isClosed()) throw closedError();
730
- const exit = await exitOn(runtime, withAudienceMemo(answering), uncounted("a request: each Git route sets its own count, and sign-in's and the event stream's none"), closingWith(request.signal));
731
- if (isClosed()) throw closedError();
732
- if (Exit.isSuccess(exit)) return exit.value;
733
- if (!Cause.hasInterruptsOnly(exit.cause) || !clientWentAway(request)) throw Cause.squash(exit.cause);
734
- const path = new URL(request.url).pathname;
735
- syncIn(Effect.logInfo("The client went away before its answer").pipe(Effect.annotateLogs({
544
+ const answering = (request, effect) => {
545
+ const gone = Effect.suspend(() => Effect.logInfo("The client went away before its answer").pipe(Effect.annotateLogs({
736
546
  method: request.method,
737
- path
738
- })), noCall);
739
- return new Response(null, { status: 499 });
740
- };
741
- /** Git's HTTP answer to `request`, else sign-in's, or `undefined` outside both's URLs. */
742
- const route = async (request) => {
743
- const built = await enter();
744
- if (Exit.isFailure(built)) {
745
- const url = new URL(request.url);
746
- return gitUrlOf(url, basePath) !== void 0 || setup.signIn !== void 0 && signInPathSet.has(url.pathname) || extensions.registry.routeOf(/* @__PURE__ */ new Set([
747
- "pre",
748
- "plain",
749
- "post"
750
- ]), request, url.pathname) !== void 0 ? refusal(unavailable(built.cause)) : void 0;
751
- }
752
- const path = new URL(request.url).pathname;
753
- const first = extensions.registry.routeOf(/* @__PURE__ */ new Set(["pre", "plain"]), request, path);
754
- if (first !== void 0) return answerTo(request, first.handle(first.request));
755
- const { http } = built.value;
756
- const answered = await answerTo(request, http.route(request));
757
- if (answered !== void 0) return answered;
758
- const last = extensions.registry.routeOf(/* @__PURE__ */ new Set(["post"]), request, path);
759
- return last === void 0 ? void 0 : answerTo(request, last.handle(last.request));
547
+ path: new URL(request.url).pathname
548
+ })));
549
+ return Effect.suspend(() => isClosed() ? Effect.die(closedError()) : Effect.void).pipe(Effect.andThen(Effect.raceFirst(withAudienceMemo(effect), interruptedBy(closingWith(request.signal)))), Effect.catchCause((cause) => {
550
+ if (isClosed()) return Effect.die(closedError());
551
+ if (!Cause.hasInterruptsOnly(cause) || !clientWentAway(request)) return Effect.die(Cause.squash(cause));
552
+ return Effect.as(gone, new Response(null, { status: 499 }));
553
+ }), Effect.onInterrupt(() => Effect.andThen(Effect.yieldNow, Effect.suspend(() => !isClosed() && clientWentAway(request) ? gone : Effect.void))), Effect.tap(() => isClosed() ? Effect.die(closedError()) : Effect.void));
760
554
  };
761
- const server = {
762
- ...callsOver((built) => built.calls),
763
- fetch: async (request) => await route(request) ?? new Response("Not found", { status: 404 }),
764
- route,
765
- identify: (request) => run((built) => built.identify(request), uncounted("a host's identify: no Git request"), request.signal),
766
- runtime,
767
- close: async () => {
768
- life.move({ kind: "closed" });
769
- await runtime.dispose();
770
- }
771
- };
772
- attachJoins(server, {
773
- admit: life.admit,
555
+ const joined = joinedOf({
556
+ addSealCheck: extensions.registry.addSealCheck,
774
557
  basePath,
775
558
  fetchLimits,
776
559
  get queueKeys() {
777
- return queueHeld.host?.keys;
560
+ return queueHeld.attached?.host.keys;
778
561
  },
779
- built: wired,
780
562
  through,
781
- failed: () => {
782
- const now = life.now();
783
- return now.kind === "failed" ? unavailable(now.cause) : void 0;
784
- },
785
- callsFor: (caller, budget) => {
786
- let calls;
787
- return heldGroup(callsOver((built) => {
788
- const tokens = tokensHeld.calls !== void 0;
789
- const queue = queueOn();
790
- if (calls?.tokens !== tokens || calls.queue !== queue) calls = {
791
- tokens,
792
- queue,
793
- made: built.callsAs(caller)
794
- };
795
- return calls.made;
796
- }, budget, joinedNames), "queue", queueOn);
797
- },
798
- hostCalls: heldGroup(callsOver((built) => built.hostCalls, void 0, joinedNames), "queue", queueOn),
799
- effectHostCalls: heldGroup(aroundCalls(guardedCalls(lazyGroups(joinedNames, (group, name, args) => Effect.flatMap(wired, (built) => joinedCall(built.hostCalls, group, name)(...args))), through), withAudienceMemo), "queue", queueOn),
800
- identify: (request, budget) => run((built) => built.identify(request), {
801
- calls: void 0,
802
- budget
803
- }, request.signal),
804
- joins
805
- });
806
- attachParts(server, {
807
- basePath,
808
- names: joinedNames,
809
- queueOn,
810
- door,
811
- parts: Effect.map(wired, (built) => built.parts)
812
- });
813
- queueMicrotask(() => {
814
- if (life.admit("join") === "join") exitOn(runtime, Effect.void, noCall);
815
- });
563
+ effectHostCalls: heldGroup(aroundCalls(guardedCalls(lazyGroups(joinedNames, (group, name, args) => Effect.suspend(() => joinedCall(wired.hostCalls, group, name)(...args))), through), withAudienceMemo), "queue", queueOn),
564
+ effectCallsFor: (caller) => heldGroup(lazyGroups(joinedNames, (group, name, args) => guardedCall(through)(Effect.suspend(() => joinedCall(wired.rest.callsFor(caller), group, name)(...args)))), "queue", queueOn)
565
+ }, wired);
816
566
  return {
817
- server,
818
- built: wired,
567
+ services: wired.services,
819
568
  registry: extensions.registry,
820
- seal
569
+ seal,
570
+ retire: Effect.flatMap(wired.retire, retiring),
571
+ rest: wired.rest,
572
+ needs: wired.needs,
573
+ checkFetch: (repo, input) => through(checkFetchOver(wired.needs)(repo, input)),
574
+ bucket: wired.adapter.bucket,
575
+ joined,
576
+ answer: (request) => answering(request, Effect.provideContext(wired.http.route(request), wired.needs)),
577
+ identify: (request) => guardedCall(through)(withAudienceMemo(wired.identify(request)))
821
578
  };
822
- };
823
- export { createGitServer, openServer, serverWith };
579
+ });
580
+ /**
581
+ * `write`, the host's `events.retired` as rows for one start, till it lands or a later start's
582
+ * has, which is logged once. A failure is logged with its error, a warning, or
583
+ * an error as `retireErrors` picks, and tried again `retryDelay` later, with no end. A defect, a
584
+ * spent call bound among them, isn't a failure to try again: it ends the write, and `Git.layer`'s
585
+ * fork logs it.
586
+ */
587
+ const retiring = /* @__PURE__ */ Effect.fnUntraced(function* (write) {
588
+ for (let failures = 1;; failures += 1) {
589
+ const result = yield* Effect.result(write);
590
+ if (EffectResult.isSuccess(result)) {
591
+ if (result.success !== "superseded") return;
592
+ return yield* Effect.logInfo("events.retired's rows weren't written: a later start wrote its own");
593
+ }
594
+ const next = retryDelay(failures);
595
+ const loud = (failures - retireErrors.first) % retireErrors.every === 0;
596
+ yield* (failures >= retireErrors.first && loud ? Effect.logError : Effect.logWarning)("events.retired's rows weren't written, and are written again", Cause.fail(result.failure)).pipe(Effect.annotateLogs({
597
+ failures,
598
+ next
599
+ }));
600
+ yield* Effect.sleep(next);
601
+ }
602
+ });
603
+ export { buildServer };