@ref0/git 0.14.0 → 0.25.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 (492) hide show
  1. package/dist/access/private-refs.mjs +1 -1
  2. package/dist/auth/access-jwt.mjs +4 -4
  3. package/dist/auth/auth-namespace.d.mts +3 -3
  4. package/dist/auth/auth-namespace.mjs +3 -2
  5. package/dist/auth/auth.d.mts +3 -3
  6. package/dist/auth/auth.mjs +9 -8
  7. package/dist/auth/authorize.mjs +4 -4
  8. package/dist/auth/fences.d.mts +1 -2
  9. package/dist/auth/fences.mjs +3 -3
  10. package/dist/auth/grants.mjs +4 -4
  11. package/dist/auth/host-function.mjs +19 -2
  12. package/dist/auth/host-services.mjs +4 -6
  13. package/dist/auth/identify.d.mts +1 -1
  14. package/dist/auth/identify.mjs +9 -3
  15. package/dist/auth/token-cleanup.mjs +67 -0
  16. package/dist/auth/token-rows.mjs +7 -2
  17. package/dist/auth/token-text.mjs +9 -1
  18. package/dist/auth/tokens-base.d.mts +35 -0
  19. package/dist/auth/tokens-base.mjs +13 -0
  20. package/dist/auth/tokens-layer.d.mts +2 -27
  21. package/dist/auth/tokens-layer.mjs +6 -11
  22. package/dist/auth/tokens-public.d.mts +3 -3
  23. package/dist/auth/tokens.d.mts +7 -10
  24. package/dist/auth/tokens.mjs +10 -81
  25. package/dist/client/answer.mjs +21 -42
  26. package/dist/client/client.d.mts +17 -11
  27. package/dist/client/client.mjs +21 -12
  28. package/dist/client/git-http.mjs +18 -8
  29. package/dist/client/local.mjs +74 -37
  30. package/dist/client/negotiate.mjs +3 -3
  31. package/dist/client/push-upload.mjs +34 -17
  32. package/dist/client/remote.mjs +12 -13
  33. package/dist/client/run-remote-helper.d.mts +2 -1
  34. package/dist/client/run-remote-helper.mjs +61 -27
  35. package/dist/client/slice-push.d.mts +1 -1
  36. package/dist/client/transport.mjs +105 -46
  37. package/dist/contracts/blobs.d.mts +58 -11
  38. package/dist/contracts/blobs.mjs +17 -3
  39. package/dist/contracts/call-allowance.d.mts +13 -0
  40. package/dist/contracts/call-allowance.mjs +44 -0
  41. package/dist/contracts/calls-spent.mjs +12 -35
  42. package/dist/contracts/client.d.mts +18 -18
  43. package/dist/contracts/commits.d.mts +28 -28
  44. package/dist/contracts/commits.mjs +1 -1
  45. package/dist/contracts/engine.d.mts +8 -3
  46. package/dist/contracts/engine.mjs +10 -1
  47. package/dist/contracts/events.d.mts +1 -1
  48. package/dist/contracts/events.mjs +1 -1
  49. package/dist/contracts/files.d.mts +14 -14
  50. package/dist/contracts/files.mjs +1 -1
  51. package/dist/contracts/forks.d.mts +21 -21
  52. package/dist/contracts/forks.mjs +1 -1
  53. package/dist/contracts/git-events.d.mts +29 -1
  54. package/dist/contracts/git-hooks.d.mts +2 -2
  55. package/dist/contracts/git.d.mts +30 -5
  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 -2
  59. package/dist/contracts/merges.d.mts +3 -2
  60. package/dist/contracts/object-values.d.mts +1 -0
  61. package/dist/contracts/object-values.mjs +16 -1
  62. package/dist/contracts/objects.d.mts +42 -41
  63. package/dist/contracts/opaque.mjs +1 -1
  64. package/dist/contracts/operations.mjs +1 -1
  65. package/dist/contracts/queue.d.mts +247 -55
  66. package/dist/contracts/queue.mjs +8 -9
  67. package/dist/contracts/refs.d.mts +30 -27
  68. package/dist/contracts/refs.mjs +1 -1
  69. package/dist/contracts/remote.d.mts +8 -12
  70. package/dist/contracts/remote.mjs +4 -1
  71. package/dist/contracts/repos.d.mts +32 -141
  72. package/dist/contracts/repos.mjs +6 -4
  73. package/dist/contracts/result.d.mts +40 -18
  74. package/dist/contracts/result.mjs +42 -9
  75. package/dist/contracts/rules.d.mts +2 -2
  76. package/dist/contracts/server.d.mts +25 -52
  77. package/dist/contracts/services.d.mts +6 -9
  78. package/dist/contracts/services.mjs +1 -2
  79. package/dist/contracts/signin.d.mts +1 -1
  80. package/dist/contracts/store.d.mts +7 -6
  81. package/dist/contracts/sync.d.mts +73 -12
  82. package/dist/contracts/sync.mjs +14 -3
  83. package/dist/contracts/tags.d.mts +13 -13
  84. package/dist/contracts/tags.mjs +1 -1
  85. package/dist/contracts/time.d.mts +3 -0
  86. package/dist/contracts/{promises.mjs → time.mjs} +1 -1
  87. package/dist/contracts/tokens.d.mts +17 -19
  88. package/dist/contracts/tokens.mjs +4 -3
  89. package/dist/contracts/topics.d.mts +10 -10
  90. package/dist/contracts/trees.d.mts +16 -16
  91. package/dist/contracts/trees.mjs +1 -1
  92. package/dist/contracts/work.d.mts +28 -17
  93. package/dist/contracts/work.mjs +2 -2
  94. package/dist/core/access.d.mts +1 -2
  95. package/dist/core/access.mjs +20 -9
  96. package/dist/core/ancestry.d.mts +1 -0
  97. package/dist/core/ancestry.mjs +30 -34
  98. package/dist/core/asked.mjs +1 -1
  99. package/dist/core/call-groups.mjs +48 -0
  100. package/dist/core/call-names.mjs +6 -1
  101. package/dist/core/call-services.mjs +11 -3
  102. package/dist/core/events/deliver.d.mts +2 -3
  103. package/dist/core/events/deliver.mjs +45 -38
  104. package/dist/core/events/retired.mjs +119 -0
  105. package/dist/core/forks.mjs +929 -433
  106. package/dist/core/hooks/groups.mjs +3 -3
  107. package/dist/core/imports.mjs +127 -41
  108. package/dist/core/index-job.mjs +131 -38
  109. package/dist/core/index-lost.d.mts +1 -2
  110. package/dist/core/index-lost.mjs +2 -2
  111. package/dist/core/loose-tally.mjs +38 -15
  112. package/dist/core/merge-parts.d.mts +17 -4
  113. package/dist/core/merge-parts.mjs +7 -2
  114. package/dist/core/mirror-rows.mjs +31 -1
  115. package/dist/core/objects/blobs.mjs +127 -3
  116. package/dist/core/objects/files.mjs +20 -17
  117. package/dist/core/objects/lines.mjs +2 -2
  118. package/dist/core/objects/merges.mjs +4 -1
  119. package/dist/core/objects/objects-layer.d.mts +1 -1
  120. package/dist/core/objects/objects-layer.mjs +4 -4
  121. package/dist/core/objects/peel.mjs +1 -7
  122. package/dist/core/objects/reading.mjs +41 -29
  123. package/dist/core/objects/tags.mjs +4 -1
  124. package/dist/core/objects/tree-edits.mjs +1 -1
  125. package/dist/core/objects/trees.mjs +257 -58
  126. package/dist/core/objects/writing.mjs +4 -10
  127. package/dist/core/own-writes.mjs +2 -2
  128. package/dist/core/parts.d.mts +11 -5
  129. package/dist/core/parts.mjs +9 -10
  130. package/dist/core/purge.mjs +310 -93
  131. package/dist/core/push-decide.mjs +2 -0
  132. package/dist/core/push-files.d.mts +1 -1
  133. package/dist/core/push.d.mts +2 -2
  134. package/dist/core/push.mjs +170 -128
  135. package/dist/core/receipts.d.mts +2 -2
  136. package/dist/core/receipts.mjs +17 -5
  137. package/dist/core/ref-index-job.mjs +7 -7
  138. package/dist/core/ref-view.mjs +75 -32
  139. package/dist/core/refs.mjs +7 -7
  140. package/dist/core/registered-rows.mjs +2 -2
  141. package/dist/core/repack.mjs +58 -48
  142. package/dist/core/repo-info.mjs +3 -3
  143. package/dist/core/repos.mjs +21 -9
  144. package/dist/core/rules/changes.mjs +18 -40
  145. package/dist/core/rules/check.mjs +6 -5
  146. package/dist/core/rules/commit-changes.mjs +3 -15
  147. package/dist/core/rules/context.d.mts +3 -3
  148. package/dist/core/rules/context.mjs +18 -14
  149. package/dist/core/rules/fetch.mjs +1 -1
  150. package/dist/core/rules/protect.mjs +30 -17
  151. package/dist/core/saved-caller-views.d.mts +8 -3
  152. package/dist/core/saved-caller-views.mjs +4 -4
  153. package/dist/core/saved-callers.d.mts +19 -2
  154. package/dist/core/saved-callers.mjs +1 -1
  155. package/dist/core/seam.d.mts +17 -28
  156. package/dist/core/seam.mjs +7 -28
  157. package/dist/core/tokens.mjs +1 -1
  158. package/dist/core/view.d.mts +6 -3
  159. package/dist/core/view.mjs +18 -25
  160. package/dist/core/work.mjs +60 -15
  161. package/dist/engine/allotted-xdiff.mjs +3 -16
  162. package/dist/engine/combined.d.mts +3 -0
  163. package/dist/engine/combined.mjs +200 -185
  164. package/dist/engine/content.d.mts +2 -2
  165. package/dist/engine/content.mjs +1 -1
  166. package/dist/engine/failures.mjs +2 -1
  167. package/dist/engine/merge.mjs +7 -9
  168. package/dist/engine/reads.d.mts +2 -2
  169. package/dist/engine/reads.mjs +25 -17
  170. package/dist/engine/xdiff.d.mts +1 -1
  171. package/dist/engine/xdiff.mjs +1 -1
  172. package/dist/event-streams/event-streams.d.mts +1 -1
  173. package/dist/event-streams/event-streams.mjs +1 -1
  174. package/dist/event-streams/stream.d.mts +3 -3
  175. package/dist/event-streams/stream.mjs +39 -16
  176. package/dist/extend.d.mts +2 -7
  177. package/dist/extend.mjs +1 -4
  178. package/dist/http/answers.mjs +8 -5
  179. package/dist/http/core-parts.mjs +169 -96
  180. package/dist/http/handler.mjs +82 -10
  181. package/dist/http/node.d.mts +14 -1
  182. package/dist/http/node.mjs +56 -27
  183. package/dist/http/parts.d.mts +2 -0
  184. package/dist/http/push-upload-job.mjs +165 -47
  185. package/dist/http/push-uploads.mjs +37 -22
  186. package/dist/http/receive-pack.mjs +14 -53
  187. package/dist/http/request-snapshot.mjs +258 -0
  188. package/dist/http/upload-pack.mjs +25 -20
  189. package/dist/index.d.mts +36 -28
  190. package/dist/index.mjs +12 -3
  191. package/dist/lfs/answer.mjs +37 -0
  192. package/dist/lfs/base.d.mts +3 -1
  193. package/dist/lfs/base.mjs +25 -1
  194. package/dist/lfs/copy.d.mts +70 -8
  195. package/dist/lfs/copy.mjs +217 -21
  196. package/dist/lfs/layer.d.mts +19 -4
  197. package/dist/lfs/layer.mjs +25 -13
  198. package/dist/lfs/locks.mjs +3 -3
  199. package/dist/lfs/objects.d.mts +2 -1
  200. package/dist/lfs/objects.mjs +89 -19
  201. package/dist/lfs/pointers.mjs +2 -2
  202. package/dist/lfs/rows.d.mts +1 -1
  203. package/dist/lfs/rows.mjs +50 -9
  204. package/dist/lfs/upkeep.mjs +82 -17
  205. package/dist/lfs/uploaded.mjs +1 -1
  206. package/dist/lfs/wire.mjs +7 -32
  207. package/dist/merges/merges.mjs +19 -4
  208. package/dist/node.d.mts +2 -2
  209. package/dist/protocol/bytes/buffers.d.mts +1 -1
  210. package/dist/protocol/bytes/buffers.mjs +14 -6
  211. package/dist/protocol/bytes/deflate.d.mts +1 -1
  212. package/dist/protocol/bytes/deflate.mjs +1 -1
  213. package/dist/protocol/bytes/inflate.d.mts +1 -1
  214. package/dist/protocol/bytes/inflate.mjs +1 -1
  215. package/dist/protocol/bytes/reader.mjs +6 -1
  216. package/dist/protocol/bytes/sha1.d.mts +1 -1
  217. package/dist/protocol/bytes/sha1.mjs +1 -1
  218. package/dist/protocol/bytes/streams.mjs +27 -1
  219. package/dist/protocol/diff/read.d.mts +6 -4
  220. package/dist/protocol/diff/read.mjs +110 -11
  221. package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
  222. package/dist/protocol/objects/lfs-pointer.mjs +1 -3
  223. package/dist/protocol/objects/links-raw.mjs +24 -10
  224. package/dist/protocol/objects/tag.d.mts +1 -1
  225. package/dist/protocol/objects/tree.mjs +23 -6
  226. package/dist/protocol/packs/delta.d.mts +6 -3
  227. package/dist/protocol/packs/delta.mjs +96 -32
  228. package/dist/protocol/packs/graph.mjs +1 -1
  229. package/dist/protocol/packs/idx.d.mts +3 -2
  230. package/dist/protocol/packs/idx.mjs +23 -4
  231. package/dist/protocol/packs/parts.d.mts +4 -1
  232. package/dist/protocol/packs/parts.mjs +10 -7
  233. package/dist/protocol/packs/reader.d.mts +6 -1
  234. package/dist/protocol/packs/reader.mjs +4 -3
  235. package/dist/protocol/packs/write-error.d.mts +1 -1
  236. package/dist/protocol/packs/write-error.mjs +1 -1
  237. package/dist/protocol/packs/writer.mjs +26 -8
  238. package/dist/protocol/wire/advertisement.d.mts +1 -1
  239. package/dist/protocol/wire/advertisement.mjs +3 -2
  240. package/dist/protocol/wire/fetch.d.mts +1 -1
  241. package/dist/protocol/wire/fetch.mjs +1 -1
  242. package/dist/protocol/wire/lines.d.mts +9 -1
  243. package/dist/protocol/wire/lines.mjs +28 -1
  244. package/dist/protocol/wire/push-uploads.mjs +10 -7
  245. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  246. package/dist/protocol/wire/receive-pack.mjs +1 -1
  247. package/dist/protocol/wire/report-status.d.mts +1 -1
  248. package/dist/protocol/wire/report-status.mjs +1 -1
  249. package/dist/protocol/wire/v2.d.mts +1 -1
  250. package/dist/protocol/wire/v2.mjs +1 -1
  251. package/dist/queue/advance.mjs +48 -44
  252. package/dist/queue/base.d.mts +57 -0
  253. package/dist/queue/base.mjs +44 -0
  254. package/dist/queue/calls.mjs +54 -57
  255. package/dist/queue/commit.mjs +2 -2
  256. package/dist/queue/host.d.mts +2 -16
  257. package/dist/queue/host.mjs +2 -7
  258. package/dist/queue/layer.d.mts +2 -2
  259. package/dist/queue/layer.mjs +19 -8
  260. package/dist/queue/limits.mjs +2 -0
  261. package/dist/queue/push-option.mjs +9 -24
  262. package/dist/queue/schedule.mjs +2 -2
  263. package/dist/queue/search.mjs +1 -1
  264. package/dist/queue/state.mjs +3 -11
  265. package/dist/queue/trim.mjs +6 -4
  266. package/dist/rest/blobs.mjs +29 -5
  267. package/dist/rest/caller.d.mts +4 -4271
  268. package/dist/rest/caller.mjs +4 -0
  269. package/dist/rest/client.d.mts +9 -6
  270. package/dist/rest/client.mjs +25 -8
  271. package/dist/rest/errors.mjs +1 -1
  272. package/dist/rest/handler.mjs +2 -2
  273. package/dist/rest/handlers.mjs +66 -11
  274. package/dist/rest/layer.d.mts +2 -2
  275. package/dist/rest/layer.mjs +6 -13
  276. package/dist/rest/listen.mjs +2 -2
  277. package/dist/rest/me.d.mts +3 -432
  278. package/dist/rest/refs.mjs +1 -1
  279. package/dist/server/check-fetch.mjs +3 -3
  280. package/dist/server/edge-node.d.mts +11 -8
  281. package/dist/server/edge-node.mjs +9 -6
  282. package/dist/server/edge.d.mts +21 -7
  283. package/dist/server/edge.mjs +56 -11
  284. package/dist/server/extension.mjs +1 -1
  285. package/dist/server/git-layer.d.mts +5 -6
  286. package/dist/server/git-layer.mjs +28 -23
  287. package/dist/server/git-namespace.d.mts +4 -3
  288. package/dist/server/git-namespace.mjs +3 -2
  289. package/dist/server/lifecycle.mjs +19 -107
  290. package/dist/server/registry.mjs +24 -13
  291. package/dist/server/server.mjs +249 -371
  292. package/dist/signin/context.d.mts +1 -2
  293. package/dist/signin/context.mjs +1 -1
  294. package/dist/signin/forms.mjs +1 -1
  295. package/dist/signin/grants.d.mts +2 -2
  296. package/dist/signin/grants.mjs +1 -1
  297. package/dist/signin/layer.d.mts +1 -1
  298. package/dist/signin/layer.mjs +1 -1
  299. package/dist/signin/wire.mjs +1 -1
  300. package/dist/storage/allotted.mjs +22 -12
  301. package/dist/storage/batch-upkeep.mjs +293 -0
  302. package/dist/storage/batches.d.mts +7 -0
  303. package/dist/storage/batches.mjs +347 -0
  304. package/dist/storage/budget.mjs +23 -1
  305. package/dist/storage/calls.d.mts +2 -3
  306. package/dist/storage/calls.mjs +166 -182
  307. package/dist/storage/charged-cache.mjs +180 -0
  308. package/dist/storage/chunks.d.mts +9 -0
  309. package/dist/storage/chunks.mjs +410 -0
  310. package/dist/storage/clean-up.mjs +72 -9
  311. package/dist/storage/counted-bucket.mjs +35 -13
  312. package/dist/storage/fetch-row-cache.d.mts +6 -0
  313. package/dist/storage/fetch-row-cache.mjs +211 -0
  314. package/dist/storage/fetch.d.mts +2 -0
  315. package/dist/storage/fetch.mjs +339 -450
  316. package/dist/storage/held-types.d.mts +0 -1
  317. package/dist/storage/host-bucket.mjs +10 -6
  318. package/dist/storage/id-mix.mjs +19 -5
  319. package/dist/storage/index-bitmaps.mjs +86 -51
  320. package/dist/storage/index-build.d.mts +2 -4
  321. package/dist/storage/index-build.mjs +324 -67
  322. package/dist/storage/index-fetch.d.mts +3 -1
  323. package/dist/storage/index-fetch.mjs +163 -83
  324. package/dist/storage/index-files.d.mts +3 -0
  325. package/dist/storage/index-files.mjs +10 -5
  326. package/dist/storage/index-graph.mjs +73 -23
  327. package/dist/storage/index-layers.mjs +55 -25
  328. package/dist/storage/index-reach.mjs +15 -22
  329. package/dist/storage/index-remap.mjs +200 -64
  330. package/dist/storage/index-whole.d.mts +7 -0
  331. package/dist/storage/index-whole.mjs +235 -0
  332. package/dist/storage/largest-files.mjs +1 -7
  333. package/dist/storage/layout.mjs +40 -1
  334. package/dist/storage/lfs-pointers.mjs +1 -6
  335. package/dist/storage/link-join.mjs +55 -16
  336. package/dist/storage/list-source.d.mts +7 -0
  337. package/dist/storage/list-source.mjs +288 -0
  338. package/dist/storage/loose.d.mts +10 -7
  339. package/dist/storage/loose.mjs +293 -82
  340. package/dist/storage/memory-budget.mjs +242 -26
  341. package/dist/storage/merge-cut.mjs +9 -6
  342. package/dist/storage/merge-fence.mjs +1 -1
  343. package/dist/storage/merge-plan.mjs +3 -2
  344. package/dist/storage/merge-row.mjs +8 -2
  345. package/dist/storage/merge-stream.mjs +164 -25
  346. package/dist/storage/merge-walk.mjs +8 -4
  347. package/dist/storage/merge-write.mjs +1 -1
  348. package/dist/storage/merge.d.mts +3 -4
  349. package/dist/storage/merge.mjs +3 -3
  350. package/dist/storage/object-rows.d.mts +4 -3
  351. package/dist/storage/object-rows.mjs +545 -84
  352. package/dist/storage/oid-table.mjs +171 -0
  353. package/dist/storage/pack-order.mjs +104 -47
  354. package/dist/storage/pack-ranges.d.mts +1 -2
  355. package/dist/storage/pack-ranges.mjs +48 -21
  356. package/dist/storage/pack-reads.d.mts +6 -3
  357. package/dist/storage/pack-reads.mjs +378 -98
  358. package/dist/storage/pack-receive.d.mts +2 -3
  359. package/dist/storage/pack-receive.mjs +22 -18
  360. package/dist/storage/packs.d.mts +2 -2
  361. package/dist/storage/packs.mjs +587 -156
  362. package/dist/storage/placed-reads.mjs +34 -17
  363. package/dist/storage/plan-columns.d.mts +4 -0
  364. package/dist/storage/plan-columns.mjs +238 -0
  365. package/dist/storage/prune-keep.mjs +134 -41
  366. package/dist/storage/prune-seen.mjs +1 -1
  367. package/dist/storage/prune-walk.mjs +203 -63
  368. package/dist/storage/prune.mjs +197 -121
  369. package/dist/storage/push-allotment.mjs +116 -25
  370. package/dist/storage/push-uploads.mjs +196 -58
  371. package/dist/storage/pushed-commits.mjs +24 -3
  372. package/dist/storage/quarantine.d.mts +3 -4
  373. package/dist/storage/range-cache.mjs +293 -41
  374. package/dist/storage/raw-ids.mjs +39 -10
  375. package/dist/storage/ready.d.mts +3 -4
  376. package/dist/storage/ready.mjs +121 -43
  377. package/dist/storage/receive-bounds.mjs +50 -13
  378. package/dist/storage/receive-cache.d.mts +7 -0
  379. package/dist/storage/receive-cache.mjs +147 -0
  380. package/dist/storage/receive-files.mjs +1 -1
  381. package/dist/storage/receive-links.mjs +1 -1
  382. package/dist/storage/receive-state.d.mts +2 -2
  383. package/dist/storage/receive-state.mjs +6 -8
  384. package/dist/storage/receive-steps.d.mts +20 -0
  385. package/dist/storage/receive-steps.mjs +298 -13
  386. package/dist/storage/repack-backlog.mjs +1 -3
  387. package/dist/storage/repack-contained.mjs +2 -2
  388. package/dist/storage/repack-job.mjs +1 -1
  389. package/dist/storage/repack.d.mts +3 -4
  390. package/dist/storage/repack.mjs +54 -9
  391. package/dist/storage/request-cache.mjs +57 -0
  392. package/dist/storage/roots.mjs +1 -24
  393. package/dist/storage/rows.d.mts +3 -3
  394. package/dist/storage/rows.mjs +2 -2
  395. package/dist/storage/runs.d.mts +2 -2
  396. package/dist/storage/runs.mjs +196 -44
  397. package/dist/storage/send-list.d.mts +1 -0
  398. package/dist/storage/send-list.mjs +112 -31
  399. package/dist/storage/single-flight.mjs +13 -7
  400. package/dist/storage/stream-whole.mjs +188 -66
  401. package/dist/storage/swap-walk.mjs +1 -1
  402. package/dist/storage/unpack.mjs +919 -199
  403. package/dist/storage/visible.mjs +112 -34
  404. package/dist/storage/walk.mjs +193 -38
  405. package/dist/storage/wants.mjs +27 -63
  406. package/dist/store/bodies.mjs +38 -0
  407. package/dist/store/call-count.d.mts +10 -14
  408. package/dist/store/call-count.mjs +58 -57
  409. package/dist/store/catalogue.d.mts +2 -2
  410. package/dist/store/catalogue.mjs +158 -36
  411. package/dist/store/crossing.mjs +1 -9
  412. package/dist/store/cursor-seal.d.mts +1 -2
  413. package/dist/store/cursor-seal.mjs +17 -7
  414. package/dist/store/door.mjs +188 -0
  415. package/dist/store/errors.d.mts +4 -5
  416. package/dist/store/errors.mjs +119 -49
  417. package/dist/store/git-store.mjs +30 -7
  418. package/dist/store/job-try.mjs +98 -40
  419. package/dist/store/list-job.mjs +32 -20
  420. package/dist/store/outbox.d.mts +2 -2
  421. package/dist/store/outbox.mjs +2 -2
  422. package/dist/store/queue-jobs.mjs +6 -12
  423. package/dist/store/records.d.mts +5 -2
  424. package/dist/store/records.mjs +5 -2
  425. package/dist/store/ref-rows.d.mts +2 -2
  426. package/dist/store/ref-rows.mjs +2 -2
  427. package/dist/store/repo-record.d.mts +2 -3
  428. package/dist/store/repo-record.mjs +34 -22
  429. package/dist/store/request-snapshot.mjs +5 -0
  430. package/dist/store/reservations.mjs +3 -3
  431. package/dist/store/scopes.mjs +11 -0
  432. package/dist/store/settle.mjs +4 -4
  433. package/dist/store/topic-jobs.mjs +5 -11
  434. package/dist/sync/bound.d.mts +3 -3
  435. package/dist/sync/bound.mjs +10 -7
  436. package/dist/sync/github.mjs +67 -69
  437. package/dist/sync/http.mjs +1 -1
  438. package/dist/sync/import.mjs +205 -57
  439. package/dist/sync/layer.d.mts +1 -1
  440. package/dist/sync/layer.mjs +6 -6
  441. package/dist/sync/lfs-batch.mjs +5 -6
  442. package/dist/sync/lfs-copy.mjs +191 -20
  443. package/dist/sync/mirror.mjs +34 -36
  444. package/dist/sync/said.mjs +17 -38
  445. package/dist/sync/step.mjs +292 -102
  446. package/dist/sync/tries.mjs +34 -15
  447. package/dist/sync.d.mts +2 -2
  448. package/dist/sync.mjs +2 -2
  449. package/dist/topics/advance.mjs +12 -13
  450. package/dist/topics/base.d.mts +15 -0
  451. package/dist/topics/base.mjs +8 -0
  452. package/dist/topics/calls.mjs +1 -1
  453. package/dist/topics/host.mjs +1 -1
  454. package/dist/topics/layer.d.mts +17 -21
  455. package/dist/topics/layer.mjs +2 -3
  456. package/dist/topics/members.mjs +4 -4
  457. package/dist/topics/public.d.mts +2 -1
  458. package/dist/topics/topic.mjs +2 -2
  459. package/package.json +5 -14
  460. package/dist/auth/helpers.mjs +0 -17
  461. package/dist/auth.d.mts +0 -5
  462. package/dist/auth.mjs +0 -5
  463. package/dist/contracts/promises.d.mts +0 -39
  464. package/dist/core/call-names.d.mts +0 -3
  465. package/dist/core/clock.mjs +0 -18
  466. package/dist/core/promise.mjs +0 -74
  467. package/dist/core/rules/commit-changes.d.mts +0 -13
  468. package/dist/effect.d.mts +0 -18
  469. package/dist/effect.mjs +0 -16
  470. package/dist/lfs/calls.mjs +0 -26
  471. package/dist/rest/api.d.mts +0 -23
  472. package/dist/rest/blobs.d.mts +0 -833
  473. package/dist/rest/commits.d.mts +0 -3543
  474. package/dist/rest/errors.d.mts +0 -2124
  475. package/dist/rest/events.d.mts +0 -426
  476. package/dist/rest/files.d.mts +0 -1342
  477. package/dist/rest/forks.d.mts +0 -2160
  478. package/dist/rest/handlers.d.mts +0 -8
  479. package/dist/rest/merges.d.mts +0 -477
  480. package/dist/rest/queue.d.mts +0 -5917
  481. package/dist/rest/refs.d.mts +0 -2988
  482. package/dist/rest/repos.d.mts +0 -2567
  483. package/dist/rest/tags.d.mts +0 -1316
  484. package/dist/rest/tokens.d.mts +0 -2614
  485. package/dist/rest/topics.d.mts +0 -2224
  486. package/dist/rest/trees.d.mts +0 -1709
  487. package/dist/rest/work.d.mts +0 -1695
  488. package/dist/server/joined.d.mts +0 -82
  489. package/dist/server/joined.mjs +0 -68
  490. package/dist/server/lifecycle.d.mts +0 -2
  491. package/dist/store/promises.d.mts +0 -11
  492. package/dist/store/promises.mjs +0 -327
@@ -1,7 +1,7 @@
1
1
  import { PrivateRefs } from "../contracts/access.mjs";
2
2
  import { pushRefLimitOf } from "../core/push-decide.mjs";
3
- import { millis } from "../contracts/promises.mjs";
4
- import { fail } from "../contracts/result.mjs";
3
+ import { millis } from "../contracts/time.mjs";
4
+ import { fail, gitError } from "../contracts/result.mjs";
5
5
  import { Authorize } from "../contracts/authorize.mjs";
6
6
  import { RepoRecords } from "../contracts/repo-records.mjs";
7
7
  import { host } from "../contracts/git.mjs";
@@ -11,19 +11,19 @@ import { accessOf, audienceOf, authorizer } from "../auth/authorize.mjs";
11
11
  import { grantFences } from "../auth/fences.mjs";
12
12
  import { grantAgain, heldGrants } from "../auth/grants.mjs";
13
13
  import { identifier } from "../auth/identify.mjs";
14
- import { tokenCalls, tokenCleanupJob } from "../auth/tokens.mjs";
15
- import { TokensBase, noTokens } from "../auth/tokens-layer.mjs";
14
+ import { tokenCleanupJob } from "../auth/token-cleanup.mjs";
15
+ import { TokensBase } from "../auth/tokens-base.mjs";
16
16
  import { blobCalls } from "../core/objects/blobs.mjs";
17
17
  import { commitCalls } from "../core/objects/commits.mjs";
18
18
  import { fileCalls } from "../core/objects/files.mjs";
19
19
  import { mergeCalls } from "../core/objects/merges.mjs";
20
+ import { MergesBase } from "../core/merge-parts.mjs";
20
21
  import { tagCalls } from "../core/objects/tags.mjs";
21
22
  import { treeCalls } from "../core/objects/trees.mjs";
22
23
  import { acting } from "../core/access.mjs";
23
24
  import { refIndexOf } from "../core/ref-index.mjs";
24
- import { callNames } from "../core/call-names.mjs";
25
- import { clocksOf } from "../core/clock.mjs";
26
- import { deliveryLog, workFailed } from "../core/events/deliver.mjs";
25
+ import { deliveryLog, deliveryOf, workFailed } from "../core/events/deliver.mjs";
26
+ import { checkRetired, newRetireStart, writeRetired } from "../core/events/retired.mjs";
27
27
  import { servedSources } from "../core/rules/protect.mjs";
28
28
  import { rulesOf } from "../core/rules/service.mjs";
29
29
  import { refsAs, refsCalls } from "../core/refs.mjs";
@@ -38,44 +38,44 @@ import { forkCalls } from "../core/forks.mjs";
38
38
  import { repoCalls } from "../core/repos.mjs";
39
39
  import { EventStreams } from "../event-streams/event-streams.mjs";
40
40
  import { streamsOver } from "../event-streams/stream.mjs";
41
- import { attachParts, renamedTo, seamAuthorize } from "../core/seam.mjs";
41
+ import { renamedTo, seamAuthorize } from "../core/seam.mjs";
42
+ import { checkFetchOver } from "./check-fetch.mjs";
42
43
  import { tokenCallsAs } from "../core/tokens.mjs";
43
44
  import { workCalls } from "../core/work.mjs";
44
- import { coreHttpParts } from "../http/core-parts.mjs";
45
+ import { make } from "../http/core-parts.mjs";
45
46
  import { refusal } from "../http/answers.mjs";
46
- import { LfsBase } from "../lfs/base.mjs";
47
+ import { LfsBase, lfsCalls } from "../lfs/base.mjs";
47
48
  import { UploadsBase } from "./uploads.mjs";
48
- import { lfsCalls } from "../lfs/calls.mjs";
49
- import { gitHttp } from "../http/handler.mjs";
50
- import { gitUrlOf, normalBase } from "../http/paths.mjs";
49
+ import { make as make$1 } from "../http/handler.mjs";
50
+ import { normalBase } from "../http/paths.mjs";
51
51
  import { pushUploadJob } from "../http/push-upload-job.mjs";
52
- import { pushUploads } from "../http/push-uploads.mjs";
52
+ import { make as make$2 } from "../http/push-uploads.mjs";
53
53
  import { hostRecordOf, pinOf } from "../store/catalogue.mjs";
54
- import { answerOf } from "../contracts/calls-spent.mjs";
55
54
  import { closedError } from "../store/closed.mjs";
56
55
  import { clientWentAway } from "../store/errors.mjs";
57
56
  import { cursorSeal } from "../store/cursor-seal.mjs";
58
57
  import { gitStore } from "../store/git-store.mjs";
59
- import { doorBucket, doorLinks, doorRecords, doorUploads, promisesClock, promisesQueue, promisesStore } from "../store/promises.mjs";
58
+ import { doorBucket, doorLinks, doorQueue, doorRecords, doorUploads, throughBridge } from "../store/door.mjs";
60
59
  import { defaultFetchLimits } from "../storage/fetch.mjs";
61
60
  import { countedBucket } from "../storage/counted-bucket.mjs";
62
61
  import { hostFailures, hostLinks, hostUploads } from "../storage/host-bucket.mjs";
63
- import { pushUploadUpkeep } from "../storage/push-uploads.mjs";
64
- import { checkedLimits, countedMost, hookCallsBefore, lessBefore, noScope } from "../store/call-count.mjs";
62
+ import { pushUploadMost, pushUploadUpkeep } from "../storage/push-uploads.mjs";
63
+ import { stageStepOf } from "../storage/receive-steps.mjs";
64
+ import { checkedLimits, countedMost, hookCallsBefore, lessBefore } from "../store/call-count.mjs";
65
65
  import { jobLimitsOf, jobsWithin } from "../store/job-try.mjs";
66
- import { exitOn, noCall, syncIn, uncounted } from "../store/crossing.mjs";
66
+ import { budgetOfObjects, requestBudgetOf } from "../storage/memory-budget.mjs";
67
+ import { RequestMemoryBudget, serverRequestBudget } from "../storage/request-cache.mjs";
67
68
  import { pruneFloor } from "../storage/rows.mjs";
68
- import { entryAdderOf, queueCalls } from "../queue/calls.mjs";
69
- import { QueueBase } from "../queue/host.mjs";
70
- import { queuePush } from "../queue/push-option.mjs";
71
- import { TopicsBase } from "../topics/layer.mjs";
69
+ import { QueueBase, noQueuePush } from "../queue/base.mjs";
70
+ import { TopicsBase } from "../topics/base.mjs";
72
71
  import { listJob } from "../store/list-job.mjs";
72
+ import "../store/topic-jobs.mjs";
73
73
  import { openExtensions } from "./extension.mjs";
74
- import { attachJoins } from "./joined.mjs";
75
- import { afterFailure, bridgeRefusal, refusedNow, serverLife, throughDoor, unavailable } from "./lifecycle.mjs";
76
- import { aroundCalls, callOrMissing, guardedCalls, heldGroup, lazyGroups, providedCalls, signalOf } from "../core/promise.mjs";
74
+ import { retireErrors, retryDelay } from "./lifecycle.mjs";
75
+ import { aroundCalls, guardedCall, providedCalls } from "../core/call-groups.mjs";
77
76
  import { CoreParts, ObjectsParts, QueueParts, SyncBase } from "../core/parts.mjs";
78
77
  import { SavedCallers, savedCallersOf } from "../core/saved-caller-views.mjs";
78
+ import { mirrorJobsOf } from "../core/mirror-rows.mjs";
79
79
  import { withAudienceMemo } from "../core/ref-view.mjs";
80
80
  import { Changes } from "../core/changes.mjs";
81
81
  import { changes } from "../core/rules/changes.mjs";
@@ -83,17 +83,15 @@ import { SealedObjects, View, objectsOverViews, viewOver } from "../core/view.mj
83
83
  import { IndexedStorage, Objects, Storage } from "../core/objects/objects.mjs";
84
84
  import { pushFilesOf } from "../core/push-files.mjs";
85
85
  import { pushRepoOf } from "../core/push-repo.mjs";
86
- import * as Clock$1 from "effect/Clock";
86
+ import { Bucket, BucketLinks, BucketUploads, CallLimits, InvalidArgument, JobQueue, Records, RequestLimits } from "@ref0/infra";
87
87
  import * as Effect from "effect/Effect";
88
+ import * as Context from "effect/Context";
88
89
  import * as Option from "effect/Option";
89
90
  import * as Cause from "effect/Cause";
90
- import * as Exit from "effect/Exit";
91
91
  import * as EffectResult from "effect/Result";
92
- import { Bucket, BucketLinks, BucketUploads, CallLimits, JobQueue, Records, RequestLimits } from "@ref0/infra";
93
- import * as Context from "effect/Context";
94
- import * as Layer from "effect/Layer";
95
92
  import * as References from "effect/References";
96
- import * as ManagedRuntime from "effect/ManagedRuntime";
93
+ import * as Clock from "effect/Clock";
94
+ import * as Duration from "effect/Duration";
97
95
  // src/server/server.ts
98
96
  /**
99
97
  * The server's `fetchLimits`, or a `TypeError` naming the one that isn't a whole number above 0,
@@ -123,57 +121,52 @@ const boundOf = (most) => ({
123
121
  bucket: most?.bucket ?? Number.POSITIVE_INFINITY,
124
122
  subrequests: most?.subrequests ?? Number.POSITIVE_INFINITY
125
123
  });
126
- /** The server's wiring, in its runtime: built once, with the runtime. */
127
- const Wired = /* @__PURE__ */ Context.Service("@ref0/git/server/Wired");
128
- /**
129
- * The groups a face names: every group less `topics`, which is the `Topics` service's, `tokens`
130
- * unless `tokensOn`, and `queue` unless `queueOn`.
131
- */
132
- const namesOf = (tokensOn, queueOn) => {
133
- const names = { ...callNames };
134
- delete names.topics;
135
- if (!tokensOn) delete names.tokens;
136
- if (!queueOn) delete names.queue;
137
- return names;
138
- };
139
124
  /** Git's own wiring over the adapter's services, as the runtime's build runs it. */
140
125
  const wireServer = (options, wiring) => {
141
126
  const { adapter, fetchLimits, files, repo, deciders, grants, extensions, guard, through, closing } = wiring;
142
127
  const runtimeClock = wiring.clock;
143
- const { store, jobs, records: rawRecords } = adapter;
144
- const { clock, now } = clocksOf(adapter.clock);
128
+ const { jobs, records: store } = adapter;
129
+ const now = Effect.sync(() => runtimeClock.currentTimeMillisUnsafe());
145
130
  const counted = adapter.bucket === void 0 ? void 0 : countedBucket(adapter.bucket);
146
131
  const callLimits = lessBefore(checkedLimits(adapter.callLimits, "The adapter's callLimits."));
147
- const jobLimits = jobLimitsOf(adapter.callLimits);
148
132
  const opening = {
149
133
  store: gitStore(store),
150
134
  bucket: adapter.objectsBucket,
151
- clock,
135
+ clock: runtimeClock,
152
136
  fetchLimits,
153
137
  callLimits
154
138
  };
155
139
  if (wiring.access !== void 0 && options.objects.indexed !== true) throw new TypeError("access hides refs, which needs objects that follow them: pass packs()");
156
140
  const indexed = wiring.access === void 0 ? void 0 : indexedOpen(options.objects, opening);
157
141
  const objects = indexed ?? options.objects.open(opening);
142
+ const rawBudget = budgetOfObjects(objects);
143
+ const memoryBudget = rawBudget === void 0 ? void 0 : serverRequestBudget(requestBudgetOf(rawBudget));
158
144
  const sealed = indexed === void 0 ? new SealedObjects(objects) : SealedObjects.indexed(indexed);
159
- const cleanup = tokenCleanupJob(now);
145
+ const cleanup = tokenCleanupJob(store, now);
160
146
  const { registry } = extensions;
161
147
  const events = deliveryLog({
162
148
  store,
163
149
  now,
164
150
  fetchLimits
165
151
  });
166
- registry.bindDeliveries((registered) => events.fill(registered));
167
- const onFailure = workFailed(events, now);
168
- const upkeep = upkeepsOf([...counted === void 0 ? [] : [pushUploadUpkeep(counted, adapter.uploads)], registry.upkeep]);
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);
158
+ const upkeep = upkeepsOf([...counted === void 0 ? [] : [pushUploadUpkeep(counted, adapter.uploads, stageStepOf(objects))], registry.upkeep]);
169
159
  const index = objects.index === void 0 ? void 0 : indexJob({
160
+ store,
170
161
  objects: sealed,
171
162
  now,
172
163
  events,
173
- repackJobRow: () => repackJobRow(repack)
164
+ repackJobRow: () => repackJobRow(repack),
165
+ cpuMs: adapter.requestLimits.cpuMs
174
166
  });
175
167
  const indexRow = index === void 0 ? void 0 : (round) => indexJobRow(index, round);
176
168
  const repack = repackJob({
169
+ store,
177
170
  objects: sealed,
178
171
  now,
179
172
  fetchLimits,
@@ -183,8 +176,12 @@ const wireServer = (options, wiring) => {
183
176
  indexJobRow: indexRow
184
177
  });
185
178
  const refIndex = refIndexOf(wiring.access, registry.hiddenRefs);
186
- 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
+ });
187
183
  const purge = purgeJob({
184
+ store,
188
185
  now,
189
186
  fetchLimits,
190
187
  parts: [registry.purge],
@@ -192,7 +189,7 @@ const wireServer = (options, wiring) => {
192
189
  deliveries: events.deliveries
193
190
  });
194
191
  const own = [
195
- listJob,
192
+ listJob(store),
196
193
  repack,
197
194
  purge
198
195
  ];
@@ -201,7 +198,6 @@ const wireServer = (options, wiring) => {
201
198
  own.push(cleanup);
202
199
  const gits = registry.bridge("git");
203
200
  gits.knowJobs(own);
204
- jobs.register(...jobsWithin(jobLimits, own));
205
201
  const decides = {
206
202
  policy: deciders.policy,
207
203
  grants
@@ -235,6 +231,7 @@ const wireServer = (options, wiring) => {
235
231
  repackJobRow: repackRow,
236
232
  events,
237
233
  jobOf: registry.jobOf,
234
+ mirrorJobs: mirrorJobsOf,
238
235
  cursors: cursorSeal(store)
239
236
  };
240
237
  if (indexRow !== void 0) parts.indexJobRow = indexRow;
@@ -256,34 +253,32 @@ const wireServer = (options, wiring) => {
256
253
  grantOf: grants.nameOf,
257
254
  grantAgain: ({ resolver, request }) => grantAgain(grants, registry.grants(), resolver, request)
258
255
  };
259
- const records = Context.make(RepoRecords, {
260
- pin: (name) => pinOf(store, name),
261
- record: (repo) => hostRecordOf(store, repo)
262
- });
263
256
  const stored = Context.make(Storage, objects).pipe(Context.add(ObjectsParts, {
264
257
  objects: sealed,
265
258
  fetchLimits,
266
259
  files,
267
260
  repo
268
261
  }), Context.add(Objects, objectsOverViews), Context.add(Changes, changes));
269
- 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));
270
- const viewed = Context.add(base, View, viewOver(base));
262
+ 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));
263
+ const budgetedBase = memoryBudget === void 0 ? base : Context.add(base, RequestMemoryBudget, memoryBudget);
264
+ const viewed = Context.add(budgetedBase, View, viewOver(budgetedBase));
271
265
  const needs = Context.add(viewed, Refs, providedCalls(refsCalls, viewed));
272
266
  const streams = streamsOver({
273
- clock,
267
+ clock: runtimeClock,
274
268
  guard,
275
269
  closing,
276
270
  through
277
271
  }, needs);
278
272
  const queueHeld = wiring.queue;
279
273
  const queueBase = QueueBase.of({
280
- records: rawRecords,
274
+ records: store,
281
275
  needs,
282
276
  onFailure,
283
277
  cpuMs: adapter.requestLimits.cpuMs,
284
- attach: (host) => Effect.suspend(() => {
285
- if (queueHeld.host !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server has a merge queue: provide MergeQueue.layer once"));
286
- queueHeld.host = host;
278
+ door: guardedCall(wiring.through),
279
+ attach: (queue) => Effect.suspend(() => {
280
+ if (queueHeld.attached !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server has a merge queue: provide MergeQueue.layer once"));
281
+ queueHeld.attached = queue;
287
282
  return Effect.void;
288
283
  })
289
284
  });
@@ -318,14 +313,14 @@ const wireServer = (options, wiring) => {
318
313
  }
319
314
  })];
320
315
  gits.knowJobs(stepJobs);
321
- jobs.register(...jobsWithin(jobLimits, stepJobs));
316
+ own.push(...stepJobs);
322
317
  }
323
318
  let uploadsAttached;
324
319
  const uploadsBase = UploadsBase.of({
325
320
  staging,
326
321
  attach: (above) => Effect.suspend(() => {
327
322
  if (staging === void 0 || uploadsAttached !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server takes push uploads: provide Git.layerUploads once"));
328
- uploadsAttached = pushUploads(needs, staging, above, adapter.requestLimits.cpuMs);
323
+ uploadsAttached = make$2(needs, staging, above, adapter.requestLimits.cpuMs);
329
324
  return Effect.void;
330
325
  })
331
326
  });
@@ -335,15 +330,14 @@ const wireServer = (options, wiring) => {
335
330
  }) });
336
331
  const tokensHeld = wiring.tokens;
337
332
  const tokensBase = TokensBase.of({
338
- attach: Effect.suspend(() => {
333
+ store,
334
+ now,
335
+ cleanup,
336
+ events,
337
+ attach: (calls) => Effect.suspend(() => {
339
338
  if (tokensHeld.calls !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server has Git's own tokens: provide Tokens.layer() once"));
340
- tokensHeld.calls = tokenCalls({
341
- store,
342
- now,
343
- cleanup,
344
- events
345
- });
346
- return Effect.succeed(tokensHeld.calls);
339
+ tokensHeld.calls = calls;
340
+ return Effect.void;
347
341
  }),
348
342
  held: Effect.sync(() => tokensHeld.calls === void 0 ? void 0 : {
349
343
  tokens: tokensHeld.calls,
@@ -361,11 +355,26 @@ const wireServer = (options, wiring) => {
361
355
  held: grants,
362
356
  now
363
357
  });
364
- 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, {
358
+ const door = guardedCall(wiring.through);
359
+ const doorRecords = RepoRecords.of({
360
+ pin: (name) => door(Effect.suspend(() => pinOf(store, name))),
361
+ record: (repo) => door(Effect.suspend(() => hostRecordOf(store, repo)))
362
+ });
363
+ const doorDecider = {
364
+ check: (request) => door(Effect.suspend(() => decider.check(request))),
365
+ audience: (input) => door(Effect.suspend(() => decider.audience(input))),
366
+ ceiling: (input) => door(Effect.suspend(() => decider.ceiling(input))),
367
+ grantOf: decider.grantOf,
368
+ grantAgain: (input) => door(Effect.suspend(() => decider.grantAgain(input)))
369
+ };
370
+ const decided = Context.make(RepoRecords, doorRecords).pipe(Context.add(Authorize, doorDecider), Context.add(Refs, aroundCalls(Context.get(needs, Refs), (effect) => withAudienceMemo(door(effect), memoryBudget))), Context.add(Rules, wiring.rules), Context.add(Objects, objectsOverViews), Context.merge(callServices(needs, (effect) => withAudienceMemo(guardedCall(wiring.through)(effect), memoryBudget))), Context.add(Events, { log: events }), Context.add(QueueBase, queueBase), Context.add(MergesBase, {
371
+ needs,
372
+ door
373
+ }), Context.add(SyncBase, {
365
374
  needs,
366
375
  pushRefsMost: pushRefLimitOf(refIndex),
367
- through: wiring.through
368
- }), Context.add(SavedCallers, savedCallersOf(needs, entryAdderOf)), Context.add(LfsBase, lfsBase), Context.add(UploadsBase, uploadsBase), Context.add(TopicsBase, topicsBase), Context.add(TokensBase, tokensBase));
376
+ through: (effect) => wiring.through(withAudienceMemo(effect, memoryBudget))
377
+ }), 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));
369
378
  const services = Context.add(decided, EventStreams, { feed: streams.feed });
370
379
  /**
371
380
  * Every group of the server's calls deciding for `bound`, over `needs`: the one list `callsAs`
@@ -388,8 +397,8 @@ const wireServer = (options, wiring) => {
388
397
  merges: over(mergeCalls(bound)),
389
398
  lfs: over(lfsCalls(() => lfsAttached?.read, bound))
390
399
  };
391
- const queue = queueHeld.host;
392
- if (queue !== void 0) groups.queue = aroundCalls(queueCalls(queue, bound), (effect) => Effect.provideContext(acting(bound, effect), queue.needs));
400
+ const queue = queueHeld.attached;
401
+ if (queue !== void 0) groups.queue = aroundCalls(queue.calls(bound), (effect) => Effect.provideContext(acting(bound, effect), queue.host.needs));
393
402
  if (topicsAttached !== void 0) {
394
403
  const topics = topicsAttached;
395
404
  groups.topics = {
@@ -407,20 +416,21 @@ const wireServer = (options, wiring) => {
407
416
  const callsAs = (bound) => groupsOf(bound);
408
417
  const { basePath } = wiring;
409
418
  const requestMost = boundOf(adapter.callLimits);
410
- const served = {
419
+ const clockedIdentify = (request) => Effect.provideService(identify(request), Clock.Clock, runtimeClock);
420
+ const rest = {
411
421
  basePath,
412
- needs,
413
- callsFor: (caller) => aroundCalls(guardedCalls(callsAs(caller), through), withAudienceMemo),
414
- tokensOn: Effect.sync(() => tokensHeld.calls !== void 0),
415
- identify: (request) => through(identify(request)),
422
+ callsFor: (caller) => aroundCalls(callsAs(caller), (effect) => withAudienceMemo(door(effect), memoryBudget)),
423
+ tokensOn: through(Effect.sync(() => tokensHeld.calls !== void 0)),
424
+ identify: (request) => through(clockedIdentify(request)),
416
425
  authorize: (input) => through(Effect.provideContext(seamAuthorize(input), needs)),
417
426
  renamedTo: (caller, repo) => through(Effect.provideContext(renamedTo(caller, repo), needs)),
418
427
  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))),
419
428
  requestMost
420
429
  };
421
- const httpOptions = { queue: queuePush(() => queueHeld.host) };
430
+ const httpOptions = { queue: (...push) => (queueHeld.attached?.push ?? noQueuePush)(...push) };
422
431
  if (options.maxDuration !== void 0) httpOptions.maxDuration = millis(options.maxDuration);
423
432
  if (objects.pushObjectsMost !== void 0) httpOptions.pushObjectsMost = objects.pushObjectsMost;
433
+ if (objects.stage !== void 0) httpOptions.pushBytesMost = pushUploadMost;
424
434
  const fetchHooks = wiring.rules.fetch.length === 0 ? 0 : 1;
425
435
  const before = (hooks) => (most) => boundOf(lessBefore(most, {
426
436
  bucket: hooks * hookCallsBefore.bucket,
@@ -430,315 +440,183 @@ const wireServer = (options, wiring) => {
430
440
  httpOptions.pushCalls = before(0)(callLimits);
431
441
  httpOptions.lfs = () => lfsAttached?.service;
432
442
  httpOptions.uploads = () => stepping ? uploadsAttached : void 0;
433
- httpParts = coreHttpParts(served, httpOptions);
434
- const http = gitHttp(httpParts);
443
+ if (rawBudget !== void 0) httpOptions.snapshotBudget = rawBudget;
444
+ httpParts = make({
445
+ basePath,
446
+ identify: rest.identify,
447
+ renamedTo: rest.renamedTo
448
+ }, httpOptions);
449
+ const http = make$1(httpParts);
435
450
  return {
436
- parts: served,
437
- adapter: {
438
- store,
439
- bucket: adapter.bucket,
440
- clock: adapter.clock
441
- },
442
- get calls() {
443
- return callsAs();
444
- },
451
+ rest,
452
+ needs,
453
+ memoryBudget,
454
+ requestMost,
455
+ adapter: { bucket: adapter.bucket },
445
456
  callsAs,
446
457
  get hostCalls() {
447
458
  return groupsOf(host);
448
459
  },
449
- identify,
460
+ identify: clockedIdentify,
450
461
  http,
451
462
  services,
452
463
  checkSources: () => {
453
- if (queueHeld.host === void 0) servedSources(wiring.rules.push);
454
- }
464
+ if (queueHeld.attached === void 0) servedSources(wiring.rules.push);
465
+ },
466
+ retire: Effect.map(newRetireStart(), (start) => writeRetired(store, retired, start)),
467
+ ownJobs: own
455
468
  };
456
469
  };
457
- /** Whether `adapter` is several Layers. */
458
- const isLayers = (adapter) => Array.isArray(adapter);
470
+ /** The option a host lowers for the job named `name`, where the host sets its timeout. */
471
+ const hostTimeoutOf = (name) => {
472
+ if (name === "topics.prepare") return "topics' `prepare` timeout";
473
+ const delivery = deliveryOf(name);
474
+ return delivery === void 0 ? void 0 : `delivery '${delivery}''s timeout`;
475
+ };
459
476
  /**
460
- * The server `Git.layer` builds on: its wiring builds over `options`, and `Git.layer` seals its
461
- * registry once its features have registered, after this build.
477
+ * `definitions` added to `jobs`, each whose timeout the host sets in a call of its own: a queue
478
+ * whose `longestTry` one passes refuses it as it's added, and the refusal then names what to lower,
479
+ * as an `INVALID_ARGUMENT` whose cause is the queue's (#2900).
462
480
  */
463
- const openServer = (options, decidersOf) => {
464
- const setup = options;
481
+ const addSealed = (jobs, definitions) => {
482
+ const hosts = definitions.filter(({ name }) => hostTimeoutOf(name) !== void 0);
483
+ const rest = definitions.filter(({ name }) => hostTimeoutOf(name) === void 0);
484
+ const named = (definition) => Effect.catchIf(jobs.addJobs(definition), (error) => error instanceof InvalidArgument, (cause) => Effect.fail(gitError("INVALID_ARGUMENT", `Lower ${hostTimeoutOf(definition.name)}: ${cause.message}`, { cause })));
485
+ return Effect.andThen(jobs.addJobs(...rest), Effect.forEach(hosts, named, { discard: true }));
486
+ };
487
+ /** Interrupts as `signal` aborts, as a client that went away or a server that closed stops its run. */
488
+ const interruptedBy = (signal) => Effect.callback((resume) => {
489
+ const interrupt = () => resume(Effect.interrupt);
490
+ if (signal.aborted) return interrupt();
491
+ signal.addEventListener("abort", interrupt, { once: true });
492
+ return Effect.sync(() => signal.removeEventListener("abort", interrupt));
493
+ });
494
+ /**
495
+ * The server, built in the host's own build: its wiring over the host's services, with no runtime
496
+ * of its own, so its build's failure is the host's, and its close is the host's scope's. A call in
497
+ * flight as the scope closes dies with the closed error, as a joined package's does.
498
+ */
499
+ const buildServer = /* @__PURE__ */ Effect.fnUntraced(function* (setup, decidersOf) {
465
500
  const fetchLimits = fetchLimitsOf(setup.fetchLimits);
466
501
  const files = pushFilesOf(setup.pushes?.files);
467
502
  const repo = pushRepoOf(setup.pushes?.repo);
468
503
  const grants = heldGrants();
469
504
  const basePath = normalBase(setup.basePath ?? "");
470
- const extensions = openExtensions(basePath);
471
- const life = serverLife();
472
- const isClosed = () => life.admit("call") === "closed";
505
+ const closer = new AbortController();
506
+ const closing = closer.signal;
507
+ yield* Effect.addFinalizer(() => Effect.sync(() => closer.abort(closedError())));
508
+ const isClosed = () => closing.aborted;
473
509
  const guard = Effect.suspend(() => isClosed() ? Effect.die(closedError()) : Effect.void);
474
510
  const door = {
475
- refusal: () => bridgeRefusal(life),
476
- closing: life.closing
511
+ refusal: () => isClosed() ? closedError() : void 0,
512
+ closing
477
513
  };
478
- const through = throughDoor(life);
479
- const closingWith = (signal) => signal === void 0 ? life.closing : AbortSignal.any([signal, life.closing]);
514
+ const through = throughBridge(door);
515
+ const closingWith = (signal) => signal === void 0 ? closing : AbortSignal.any([signal, closing]);
480
516
  const tokensHeld = { calls: void 0 };
481
- const queueHeld = { host: void 0 };
482
- const names = namesOf(false, false);
483
- const joinedNames = namesOf(true, true);
484
- const queueOn = () => queueHeld.host !== void 0;
485
- const joinedCall = (calls, group, name) => callOrMissing(calls, group, name, () => Effect.fail(noTokens));
486
- const runCall = async (effect, crossing, signal) => {
487
- if (isClosed()) throw closedError();
488
- const exit = await exitOn(runtime, Effect.result(withAudienceMemo(effect)), crossing, closingWith(signal));
489
- if (isClosed()) throw closedError();
490
- 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);
491
- return answerOf(answer, signal);
492
- };
493
- let registerLater;
494
- let checkLater;
495
- const seal = Effect.suspend(() => {
496
- const register = registerLater;
497
- const check = checkLater;
498
- if (register === void 0 || check === void 0) return Effect.die(/* @__PURE__ */ new Error("Git's registry seals after the server's build"));
499
- return Effect.flatMap(extensions.registry.seal(), (jobs) => Effect.sync(check).pipe(Effect.andThen(Effect.all(extensions.registry.sealChecks(), { discard: true })), Effect.andThen(Effect.sync(() => register(jobs)))));
517
+ const queueHeld = { attached: void 0 };
518
+ const records = yield* Records.Records;
519
+ const queue = yield* JobQueue.JobQueue;
520
+ const callLimits = yield* CallLimits.CallLimits;
521
+ const extensions = openExtensions({
522
+ basePath,
523
+ fetchWindow: Duration.millis(fetchLimits.milliseconds),
524
+ requestMost: boundOf(callLimits)
500
525
  });
501
- const wiring = Layer.effectContext(Effect.gen(function* () {
502
- const records = yield* Records.Records;
503
- const queue = yield* JobQueue.JobQueue;
504
- const callLimits = yield* CallLimits.CallLimits;
505
- const requestLimits = yield* Effect.serviceOption(RequestLimits.RequestLimits);
506
- const bucket = yield* Effect.serviceOption(Bucket.Bucket);
507
- const links = yield* Effect.serviceOption(BucketLinks.BucketLinks);
508
- const uploads = yield* Effect.serviceOption(BucketUploads.BucketUploads);
509
- const clock = yield* Effect.clockWith(Effect.succeed);
510
- const logging = Context.make(References.CurrentLoggers, yield* References.CurrentLoggers).pipe(Context.add(References.MinimumLogLevel, yield* References.MinimumLogLevel));
511
- const rules = yield* rulesOf(setup.rules ?? []);
512
- const context = yield* Effect.context();
513
- const guardedRecords = doorRecords(records, context, door);
514
- extensions.registry.bindRecords(guardedRecords);
515
- const adapter = {
516
- records: guardedRecords,
517
- store: promisesStore(records, context, door),
518
- jobs: promisesQueue(queue, context, door),
519
- bucket: Option.isSome(bucket) ? doorBucket(hostFailures(bucket.value), context, door) : void 0,
520
- objectsBucket: Option.isSome(bucket) ? doorBucket(bucket.value, context, door) : void 0,
521
- links: Option.isSome(links) ? doorLinks(hostLinks(links.value), context, door) : void 0,
522
- uploads: Option.isSome(uploads) ? doorUploads(hostUploads(uploads.value), context, door) : void 0,
523
- clock: promisesClock(clock, context, door),
524
- callLimits,
525
- requestLimits: Option.getOrElse(requestLimits, () => ({}))
526
- };
527
- const given = {
528
- adapter,
529
- rules,
530
- tokens: tokensHeld,
531
- queue: queueHeld,
532
- fetchLimits,
533
- files,
534
- repo,
535
- deciders: decidersOf(),
536
- grants,
537
- extensions,
538
- basePath,
539
- clock,
540
- logging,
541
- access: Option.getOrUndefined(yield* Effect.serviceOption(PrivateRefs))
542
- };
543
- const wired = yield* Effect.sync(() => wireServer(setup, {
544
- ...given,
545
- guard,
546
- closing: life.closing,
547
- through,
548
- runtime
549
- }));
550
- const jobLimits = jobLimitsOf(callLimits);
551
- const register = (jobs) => adapter.jobs.register(...jobsWithin(jobLimits, jobs));
552
- registerLater = register;
553
- checkLater = wired.checkSources;
554
- return Context.add(wired.services, Wired, wired);
555
- }));
556
- const { adapter } = setup;
557
- const host = isLayers(adapter) ? Layer.mergeAll(Layer.empty, ...adapter) : adapter;
558
- const makeRuntime = () => ManagedRuntime.make(Layer.suspend(() => {
559
- life.move({
560
- kind: "building",
561
- failures: 0
562
- });
563
- return Layer.provideMerge(wiring, host);
564
- }).pipe(Layer.tap((built) => Effect.sync(() => {
565
- life.move({
566
- kind: "built",
567
- wired: Context.get(built, Wired)
568
- });
569
- })), Layer.tapCause((cause) => {
570
- const building = life.now();
571
- if (building.kind !== "building") return Effect.void;
572
- const failures = building.failures + 1;
573
- const next = afterFailure(cause, failures, life.clock());
574
- if (!life.move(next)) return Effect.void;
575
- if (failures === 1) return Effect.logError("The Git server failed to start", cause);
576
- return Effect.logWarning("The Git server failed to start again", cause).pipe(Effect.annotateLogs({
577
- failures,
578
- next: next.kind === "waiting" ? next.at : "none"
579
- }));
580
- })));
581
- let runtime = makeRuntime();
582
- /**
583
- * The next build, once a call comes at or after `waiting`'s `at`: the call that wins the move to
584
- * `building` makes a fresh runtime, and disposes the failed one, and a call that loses it waits on
585
- * that build.
586
- */
587
- const rebuild = () => {
588
- const now = life.now();
589
- if (now.kind !== "waiting" || life.admit("call") !== "wait") return;
590
- if (!life.move({
591
- kind: "building",
592
- failures: now.failures
593
- })) return;
594
- const failed = runtime;
595
- runtime = makeRuntime();
596
- failed.dispose();
526
+ const requestLimits = yield* Effect.serviceOption(RequestLimits.RequestLimits);
527
+ const bucket = yield* Effect.serviceOption(Bucket.Bucket);
528
+ const links = yield* Effect.serviceOption(BucketLinks.BucketLinks);
529
+ const uploads = yield* Effect.serviceOption(BucketUploads.BucketUploads);
530
+ const clock = yield* Effect.clockWith(Effect.succeed);
531
+ const logging = Context.make(References.CurrentLoggers, yield* References.CurrentLoggers).pipe(Context.add(References.MinimumLogLevel, yield* References.MinimumLogLevel));
532
+ const rules = yield* rulesOf(setup.rules ?? []);
533
+ const host = Context.omit(Rules)(yield* Effect.context());
534
+ const guardedRecords = doorRecords(records, host, door);
535
+ extensions.registry.bindRecords(guardedRecords);
536
+ const adapter = {
537
+ records: guardedRecords,
538
+ jobs: doorQueue(queue, host, door, () => clock.currentTimeMillisUnsafe()),
539
+ bucket: Option.isSome(bucket) ? doorBucket(hostFailures(bucket.value), host, door) : void 0,
540
+ objectsBucket: Option.isSome(bucket) ? doorBucket(bucket.value, host, door) : void 0,
541
+ links: Option.isSome(links) ? doorLinks(hostLinks(links.value), host, door) : void 0,
542
+ uploads: Option.isSome(uploads) ? doorUploads(hostUploads(uploads.value), host, door) : void 0,
543
+ callLimits,
544
+ requestLimits: Option.getOrElse(requestLimits, () => ({}))
597
545
  };
546
+ const access = Option.getOrUndefined(yield* Effect.serviceOption(PrivateRefs));
547
+ const wired = yield* Effect.sync(() => wireServer(setup, {
548
+ adapter,
549
+ rules,
550
+ tokens: tokensHeld,
551
+ queue: queueHeld,
552
+ fetchLimits,
553
+ files,
554
+ repo,
555
+ deciders: decidersOf(),
556
+ grants,
557
+ extensions,
558
+ basePath,
559
+ clock,
560
+ logging,
561
+ access,
562
+ guard,
563
+ closing,
564
+ through
565
+ }));
566
+ const jobLimits = jobLimitsOf(callLimits);
567
+ yield* Effect.orDie(adapter.jobs.addJobs(...jobsWithin(jobLimits, wired.ownJobs)));
568
+ 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(addSealed(adapter.jobs, jobsWithin(jobLimits, jobs))))));
598
569
  /**
599
- * The server's build as the door answers it, every call's way in: built, or refused while it
600
- * failed or waits to build again, starting or joining the build while it isn't settled. A closed
601
- * server throws, before the build or after.
602
- */
603
- const enter = async () => {
604
- const settled = () => {
605
- const admitted = life.admit("call");
606
- if (admitted === "closed") throw closedError();
607
- const now = life.now();
608
- if (admitted === "run" && now.kind === "built") return {
609
- kind: "success",
610
- value: now.wired
611
- };
612
- const refused = admitted === "unavailable" ? refusedNow(life) : void 0;
613
- return refused === void 0 ? void 0 : {
614
- kind: "error",
615
- error: refused
616
- };
617
- };
618
- const before = settled();
619
- if (before !== void 0) return before;
620
- rebuild();
621
- const exit = await exitOn(runtime, Effect.service(Wired), noCall);
622
- return settled() ?? (Exit.isSuccess(exit) ? {
623
- kind: "success",
624
- value: exit.value
625
- } : {
626
- kind: "error",
627
- error: unavailable(exit.cause)
628
- });
629
- };
630
- const wired = Effect.flatMap(Effect.promise(enter), (built) => built.kind === "success" ? Effect.succeed(built.value) : Effect.fail(built.error));
631
- /** `use`'s Effect over the built server, its `Result`, or the `UNAVAILABLE` `enter` refuses with. */
632
- const run = async (use, crossing, signal) => {
633
- const built = await enter();
634
- if (built.kind === "error") return built;
635
- return runCall(use(built.value), crossing, signal);
636
- };
637
- /**
638
- * The calls over the built server's `calls`, made before it's built: a host's, each counted into
639
- * `budget` when given, and into no request's scope otherwise.
640
- */
641
- const callsOver = (calls, budget, given = names) => lazyGroups(given, (group, name, args) => run((built) => joinedCall(calls(built), group, name)(...args), budget === void 0 ? noScope : {
642
- calls: void 0,
643
- budget
644
- }, signalOf(args)));
645
- /**
646
- * `answering`'s answer to `request`. A client that went away, by its signal or mid-body, gets an
647
- * empty 499, as Effect's HTTP server answers one, logged once at info with the path alone: an
648
- * archive's link carries its token in the query. Any other interrupt throws, as it did before.
570
+ * `answering`'s answer to `request`, in the caller's fiber, stopped as the client goes away or the
571
+ * server closes. A client that went away, by its signal or mid-body, gets an empty 499, as
572
+ * Effect's HTTP server answers one, logged once at info with the path alone: an archive's link
573
+ * carries its token in the query. A closed server dies with the closed error.
649
574
  */
650
- const answerTo = async (request, answering) => {
651
- if (isClosed()) throw closedError();
652
- 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));
653
- if (isClosed()) throw closedError();
654
- if (Exit.isSuccess(exit)) return exit.value;
655
- if (!Cause.hasInterruptsOnly(exit.cause) || !clientWentAway(request)) throw Cause.squash(exit.cause);
656
- const path = new URL(request.url).pathname;
657
- syncIn(Effect.logInfo("The client went away before its answer").pipe(Effect.annotateLogs({
575
+ const answering = (request, effect) => {
576
+ const gone = Effect.suspend(() => Effect.logInfo("The client went away before its answer").pipe(Effect.annotateLogs({
658
577
  method: request.method,
659
- path
660
- })), noCall);
661
- return new Response(null, { status: 499 });
662
- };
663
- /** Git's HTTP answer to `request`, else sign-in's, or `undefined` outside both's URLs. */
664
- const route = async (request) => {
665
- const built = await enter();
666
- if (built.kind === "error") {
667
- const url = new URL(request.url);
668
- return gitUrlOf(url, basePath) !== void 0 || extensions.registry.routeOf(/* @__PURE__ */ new Set([
669
- "pre",
670
- "plain",
671
- "post"
672
- ]), request, url.pathname) !== void 0 ? refusal(built.error) : void 0;
673
- }
674
- const path = new URL(request.url).pathname;
675
- const first = extensions.registry.routeOf(/* @__PURE__ */ new Set(["pre", "plain"]), request, path);
676
- if (first !== void 0) return answerTo(request, first.handle(first.request));
677
- const { http } = built.value;
678
- const answered = await answerTo(request, http.route(request));
679
- if (answered !== void 0) return answered;
680
- const last = extensions.registry.routeOf(/* @__PURE__ */ new Set(["post"]), request, path);
681
- return last === void 0 ? void 0 : answerTo(request, last.handle(last.request));
682
- };
683
- const server = {
684
- ...callsOver((built) => built.calls),
685
- fetch: async (request) => await route(request) ?? new Response("Not found", { status: 404 }),
686
- route,
687
- identify: (request) => run((built) => built.identify(request), uncounted("a host's identify: no Git request"), request.signal),
688
- get runtime() {
689
- return runtime;
690
- },
691
- close: async () => {
692
- life.move({ kind: "closed" });
693
- await runtime.dispose();
694
- }
578
+ path: new URL(request.url).pathname
579
+ })));
580
+ return Effect.suspend(() => isClosed() ? Effect.die(closedError()) : Effect.void).pipe(Effect.andThen(Effect.raceFirst(withAudienceMemo(effect, wired.memoryBudget), interruptedBy(closingWith(request.signal)))), Effect.catchCause((cause) => {
581
+ if (isClosed()) return Effect.die(closedError());
582
+ if (!Cause.hasInterruptsOnly(cause) || !clientWentAway(request)) return Effect.die(Cause.squash(cause));
583
+ return Effect.as(gone, new Response(null, { status: 499 }));
584
+ }), Effect.onInterrupt(() => Effect.andThen(Effect.yieldNow, Effect.suspend(() => !isClosed() && clientWentAway(request) ? gone : Effect.void))), Effect.tap(() => isClosed() ? Effect.die(closedError()) : Effect.void));
695
585
  };
696
- attachJoins(server, {
697
- admit: life.admit,
698
- addSealCheck: extensions.registry.addSealCheck,
699
- basePath,
700
- fetchLimits,
701
- get queueKeys() {
702
- return queueHeld.host?.keys;
703
- },
704
- built: wired,
705
- through,
706
- failed: () => refusedNow(life),
707
- callsFor: (caller, budget) => {
708
- let calls;
709
- return heldGroup(callsOver((built) => {
710
- const tokens = tokensHeld.calls !== void 0;
711
- const queue = queueOn();
712
- if (calls?.tokens !== tokens || calls.queue !== queue) calls = {
713
- tokens,
714
- queue,
715
- made: built.callsAs(caller)
716
- };
717
- return calls.made;
718
- }, budget, joinedNames), "queue", queueOn);
719
- },
720
- hostCalls: heldGroup(callsOver((built) => built.hostCalls, void 0, joinedNames), "queue", queueOn),
721
- effectHostCalls: heldGroup(aroundCalls(guardedCalls(lazyGroups(joinedNames, (group, name, args) => Effect.flatMap(wired, (built) => joinedCall(built.hostCalls, group, name)(...args))), through), withAudienceMemo), "queue", queueOn),
722
- identify: (request, budget) => run((built) => built.identify(request), {
723
- calls: void 0,
724
- budget
725
- }, request.signal)
726
- });
727
- attachParts(server, {
728
- basePath,
729
- names: joinedNames,
730
- queueOn,
731
- door,
732
- parts: Effect.map(wired, (built) => built.parts)
733
- });
734
- queueMicrotask(() => {
735
- if (life.now().kind === "unbuilt") exitOn(runtime, Effect.void, noCall);
736
- });
737
586
  return {
738
- server,
739
- built: wired,
587
+ services: wired.services,
740
588
  registry: extensions.registry,
741
- seal
589
+ seal,
590
+ retire: Effect.flatMap(wired.retire, retiring),
591
+ rest: wired.rest,
592
+ needs: wired.needs,
593
+ checkFetch: (repo, input) => through(checkFetchOver(wired.needs)(repo, input)),
594
+ bucket: wired.adapter.bucket,
595
+ answer: (request) => answering(request, Effect.provideContext(wired.http.route(request), wired.needs)),
596
+ identify: (request) => guardedCall(through)(withAudienceMemo(wired.identify(request), wired.memoryBudget))
742
597
  };
743
- };
744
- export { openServer };
598
+ });
599
+ /**
600
+ * `write`, the host's `events.retired` as rows for one start, till it lands or a later start's
601
+ * has, which is logged once. A failure is logged with its error, a warning, or
602
+ * an error as `retireErrors` picks, and tried again `retryDelay` later, with no end. A defect, a
603
+ * spent call bound among them, isn't a failure to try again: it ends the write, and `Git.layer`'s
604
+ * fork logs it.
605
+ */
606
+ const retiring = /* @__PURE__ */ Effect.fnUntraced(function* (write) {
607
+ for (let failures = 1;; failures += 1) {
608
+ const result = yield* Effect.result(write);
609
+ if (EffectResult.isSuccess(result)) {
610
+ if (result.success !== "superseded") return;
611
+ return yield* Effect.logInfo("events.retired's rows weren't written: a later start wrote its own");
612
+ }
613
+ const next = retryDelay(failures);
614
+ const loud = (failures - retireErrors.first) % retireErrors.every === 0;
615
+ 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({
616
+ failures,
617
+ next
618
+ }));
619
+ yield* Effect.sleep(next);
620
+ }
621
+ });
622
+ export { buildServer };