@ref0/git 0.14.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 (351) hide show
  1. package/dist/auth/access-jwt.mjs +2 -2
  2. package/dist/auth/authorize.mjs +3 -3
  3. package/dist/auth/fences.d.mts +1 -2
  4. package/dist/auth/fences.mjs +3 -3
  5. package/dist/auth/grants.mjs +4 -4
  6. package/dist/auth/host-function.mjs +18 -1
  7. package/dist/auth/identify.d.mts +1 -1
  8. package/dist/auth/identify.mjs +3 -3
  9. package/dist/auth/token-cleanup.mjs +67 -0
  10. package/dist/auth/token-rows.mjs +1 -1
  11. package/dist/auth/token-text.mjs +9 -1
  12. package/dist/auth/tokens-base.d.mts +35 -0
  13. package/dist/auth/tokens-base.mjs +13 -0
  14. package/dist/auth/tokens-layer.d.mts +2 -27
  15. package/dist/auth/tokens-layer.mjs +6 -11
  16. package/dist/auth/tokens-public.d.mts +3 -3
  17. package/dist/auth/tokens.d.mts +7 -10
  18. package/dist/auth/tokens.mjs +9 -80
  19. package/dist/client/answer.mjs +21 -42
  20. package/dist/client/client.d.mts +2 -4
  21. package/dist/client/git-http.mjs +17 -7
  22. package/dist/client/local.mjs +14 -13
  23. package/dist/client/push-upload.mjs +9 -8
  24. package/dist/client/remote.mjs +8 -10
  25. package/dist/client/run-remote-helper.d.mts +1 -0
  26. package/dist/client/run-remote-helper.mjs +58 -24
  27. package/dist/client/slice-push.d.mts +1 -1
  28. package/dist/client/transport.mjs +105 -46
  29. package/dist/contracts/blobs.d.mts +55 -8
  30. package/dist/contracts/blobs.mjs +16 -2
  31. package/dist/contracts/call-allowance.d.mts +13 -0
  32. package/dist/contracts/call-allowance.mjs +44 -0
  33. package/dist/contracts/calls-spent.mjs +8 -3
  34. package/dist/contracts/client.d.mts +15 -16
  35. package/dist/contracts/commits.d.mts +24 -24
  36. package/dist/contracts/engine.d.mts +6 -1
  37. package/dist/contracts/engine.mjs +10 -1
  38. package/dist/contracts/files.d.mts +10 -10
  39. package/dist/contracts/forks.d.mts +17 -17
  40. package/dist/contracts/git-events.d.mts +29 -1
  41. package/dist/contracts/git-hooks.d.mts +1 -1
  42. package/dist/contracts/git.d.mts +21 -0
  43. package/dist/contracts/grants.d.mts +24 -4
  44. package/dist/contracts/handlers.d.mts +1 -1
  45. package/dist/contracts/lfs.d.mts +28 -2
  46. package/dist/contracts/merges.d.mts +3 -2
  47. package/dist/contracts/objects.d.mts +23 -25
  48. package/dist/contracts/queue.d.mts +40 -12
  49. package/dist/contracts/queue.mjs +3 -4
  50. package/dist/contracts/refs.d.mts +26 -23
  51. package/dist/contracts/remote.d.mts +6 -7
  52. package/dist/contracts/remote.mjs +4 -1
  53. package/dist/contracts/repos.d.mts +29 -138
  54. package/dist/contracts/repos.mjs +5 -3
  55. package/dist/contracts/result.d.mts +35 -16
  56. package/dist/contracts/result.mjs +35 -7
  57. package/dist/contracts/server.d.mts +25 -50
  58. package/dist/contracts/services.d.mts +1 -1
  59. package/dist/contracts/store.d.mts +6 -5
  60. package/dist/contracts/sync.d.mts +11 -7
  61. package/dist/contracts/sync.mjs +12 -2
  62. package/dist/contracts/tags.d.mts +10 -10
  63. package/dist/contracts/time.d.mts +3 -0
  64. package/dist/contracts/{promises.mjs → time.mjs} +1 -1
  65. package/dist/contracts/tokens.d.mts +15 -17
  66. package/dist/contracts/tokens.mjs +3 -2
  67. package/dist/contracts/topics.d.mts +1 -1
  68. package/dist/contracts/trees.d.mts +12 -12
  69. package/dist/contracts/work.d.mts +24 -13
  70. package/dist/core/access.d.mts +1 -2
  71. package/dist/core/access.mjs +20 -9
  72. package/dist/core/ancestry.d.mts +1 -0
  73. package/dist/core/asked.mjs +1 -1
  74. package/dist/core/call-names.mjs +6 -1
  75. package/dist/core/call-services.mjs +11 -3
  76. package/dist/core/events/deliver.d.mts +1 -2
  77. package/dist/core/events/deliver.mjs +43 -36
  78. package/dist/core/events/retired.mjs +119 -0
  79. package/dist/core/forks.mjs +928 -432
  80. package/dist/core/hooks/groups.mjs +1 -1
  81. package/dist/core/imports.mjs +29 -23
  82. package/dist/core/index-job.mjs +122 -34
  83. package/dist/core/index-lost.d.mts +1 -2
  84. package/dist/core/index-lost.mjs +2 -2
  85. package/dist/core/loose-tally.mjs +1 -1
  86. package/dist/core/objects/blobs.mjs +129 -3
  87. package/dist/core/objects/lines.mjs +2 -2
  88. package/dist/core/objects/merges.mjs +4 -1
  89. package/dist/core/objects/objects-layer.d.mts +1 -1
  90. package/dist/core/objects/objects-layer.mjs +3 -3
  91. package/dist/core/objects/reading.mjs +24 -13
  92. package/dist/core/objects/tags.mjs +4 -1
  93. package/dist/core/objects/trees.mjs +2 -2
  94. package/dist/core/objects/writing.mjs +2 -2
  95. package/dist/core/own-writes.mjs +1 -1
  96. package/dist/core/parts.d.mts +4 -5
  97. package/dist/core/parts.mjs +3 -8
  98. package/dist/core/promise.mjs +9 -12
  99. package/dist/core/purge.mjs +287 -83
  100. package/dist/core/push-decide.mjs +2 -0
  101. package/dist/core/push-files.d.mts +1 -1
  102. package/dist/core/push.mjs +58 -47
  103. package/dist/core/receipts.mjs +8 -3
  104. package/dist/core/ref-index-job.mjs +4 -4
  105. package/dist/core/ref-view.mjs +2 -2
  106. package/dist/core/refs.mjs +5 -5
  107. package/dist/core/registered-rows.mjs +2 -2
  108. package/dist/core/repack.mjs +36 -21
  109. package/dist/core/repo-info.mjs +3 -3
  110. package/dist/core/repos.mjs +21 -9
  111. package/dist/core/rules/commit-changes.d.mts +0 -1
  112. package/dist/core/saved-caller-views.d.mts +7 -2
  113. package/dist/core/saved-caller-views.mjs +2 -2
  114. package/dist/core/saved-callers.d.mts +19 -2
  115. package/dist/core/seam.d.mts +16 -26
  116. package/dist/core/seam.mjs +7 -28
  117. package/dist/core/tokens.mjs +1 -1
  118. package/dist/core/view.mjs +7 -15
  119. package/dist/core/work.mjs +59 -14
  120. package/dist/effect.d.mts +3 -12
  121. package/dist/effect.mjs +1 -10
  122. package/dist/engine/failures.mjs +2 -1
  123. package/dist/engine/reads.mjs +4 -4
  124. package/dist/event-streams/stream.d.mts +2 -2
  125. package/dist/event-streams/stream.mjs +37 -14
  126. package/dist/extend.d.mts +2 -3
  127. package/dist/extend.mjs +2 -1
  128. package/dist/http/answers.mjs +8 -5
  129. package/dist/http/core-parts.mjs +95 -79
  130. package/dist/http/handler.mjs +34 -7
  131. package/dist/http/node.d.mts +14 -1
  132. package/dist/http/node.mjs +56 -27
  133. package/dist/http/parts.d.mts +1 -0
  134. package/dist/http/push-upload-job.mjs +30 -26
  135. package/dist/http/push-uploads.mjs +36 -21
  136. package/dist/http/upload-pack.mjs +3 -3
  137. package/dist/index.d.mts +14 -14
  138. package/dist/index.mjs +2 -2
  139. package/dist/lfs/answer.mjs +37 -0
  140. package/dist/lfs/base.d.mts +2 -0
  141. package/dist/lfs/base.mjs +25 -1
  142. package/dist/lfs/copy.d.mts +21 -7
  143. package/dist/lfs/copy.mjs +89 -6
  144. package/dist/lfs/layer.d.mts +15 -1
  145. package/dist/lfs/layer.mjs +24 -11
  146. package/dist/lfs/locks.mjs +2 -2
  147. package/dist/lfs/objects.d.mts +1 -0
  148. package/dist/lfs/objects.mjs +87 -17
  149. package/dist/lfs/pointers.mjs +2 -2
  150. package/dist/lfs/rows.mjs +42 -8
  151. package/dist/lfs/upkeep.mjs +48 -14
  152. package/dist/lfs/wire.mjs +6 -31
  153. package/dist/merges/merges.mjs +2 -2
  154. package/dist/node.d.mts +2 -2
  155. package/dist/protocol/bytes/buffers.mjs +13 -5
  156. package/dist/protocol/bytes/reader.mjs +6 -1
  157. package/dist/protocol/bytes/streams.mjs +27 -1
  158. package/dist/protocol/diff/read.d.mts +4 -3
  159. package/dist/protocol/diff/read.mjs +8 -3
  160. package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
  161. package/dist/protocol/objects/lfs-pointer.mjs +1 -3
  162. package/dist/protocol/objects/links-raw.mjs +24 -10
  163. package/dist/protocol/objects/tag.d.mts +1 -1
  164. package/dist/protocol/objects/tree.mjs +23 -6
  165. package/dist/protocol/packs/delta.d.mts +6 -3
  166. package/dist/protocol/packs/delta.mjs +96 -32
  167. package/dist/protocol/packs/idx.d.mts +2 -1
  168. package/dist/protocol/packs/idx.mjs +22 -3
  169. package/dist/protocol/packs/parts.d.mts +4 -1
  170. package/dist/protocol/packs/parts.mjs +10 -7
  171. package/dist/protocol/packs/reader.d.mts +5 -0
  172. package/dist/protocol/packs/reader.mjs +3 -2
  173. package/dist/protocol/packs/writer.mjs +26 -8
  174. package/dist/queue/advance.mjs +21 -24
  175. package/dist/queue/base.d.mts +55 -0
  176. package/dist/queue/base.mjs +44 -0
  177. package/dist/queue/calls.mjs +51 -54
  178. package/dist/queue/commit.mjs +1 -1
  179. package/dist/queue/host.d.mts +1 -15
  180. package/dist/queue/host.mjs +2 -7
  181. package/dist/queue/layer.d.mts +2 -1
  182. package/dist/queue/layer.mjs +10 -3
  183. package/dist/queue/limits.mjs +2 -0
  184. package/dist/queue/push-option.mjs +9 -24
  185. package/dist/queue/schedule.mjs +1 -1
  186. package/dist/queue/state.mjs +2 -10
  187. package/dist/queue/trim.mjs +5 -3
  188. package/dist/rest/blobs.mjs +29 -5
  189. package/dist/rest/caller.d.mts +4 -4271
  190. package/dist/rest/caller.mjs +4 -0
  191. package/dist/rest/client.d.mts +8 -5
  192. package/dist/rest/client.mjs +19 -2
  193. package/dist/rest/handlers.mjs +50 -5
  194. package/dist/rest/layer.d.mts +2 -2
  195. package/dist/rest/layer.mjs +5 -12
  196. package/dist/rest/me.d.mts +3 -432
  197. package/dist/server/check-fetch.mjs +3 -3
  198. package/dist/server/edge-node.d.mts +11 -8
  199. package/dist/server/edge-node.mjs +9 -6
  200. package/dist/server/edge.d.mts +21 -7
  201. package/dist/server/edge.mjs +32 -11
  202. package/dist/server/extension.mjs +1 -1
  203. package/dist/server/git-layer.d.mts +5 -5
  204. package/dist/server/git-layer.mjs +28 -22
  205. package/dist/server/git-namespace.d.mts +4 -3
  206. package/dist/server/git-namespace.mjs +3 -2
  207. package/dist/server/joined.d.mts +6 -18
  208. package/dist/server/joined.mjs +9 -36
  209. package/dist/server/lifecycle.mjs +18 -106
  210. package/dist/server/registry.mjs +24 -7
  211. package/dist/server/server.mjs +205 -346
  212. package/dist/signin/context.d.mts +1 -2
  213. package/dist/signin/layer.d.mts +1 -1
  214. package/dist/signin/layer.mjs +1 -1
  215. package/dist/storage/allotted.mjs +18 -3
  216. package/dist/storage/batch-upkeep.mjs +274 -0
  217. package/dist/storage/batches.d.mts +8 -0
  218. package/dist/storage/batches.mjs +344 -0
  219. package/dist/storage/calls.d.mts +1 -2
  220. package/dist/storage/calls.mjs +144 -158
  221. package/dist/storage/chunks.d.mts +9 -0
  222. package/dist/storage/chunks.mjs +297 -0
  223. package/dist/storage/clean-up.mjs +72 -9
  224. package/dist/storage/counted-bucket.mjs +4 -4
  225. package/dist/storage/fetch.d.mts +1 -0
  226. package/dist/storage/fetch.mjs +287 -210
  227. package/dist/storage/host-bucket.mjs +1 -2
  228. package/dist/storage/id-mix.mjs +19 -5
  229. package/dist/storage/index-bitmaps.mjs +9 -2
  230. package/dist/storage/index-build.d.mts +0 -1
  231. package/dist/storage/index-build.mjs +80 -23
  232. package/dist/storage/index-fetch.mjs +113 -72
  233. package/dist/storage/index-files.d.mts +3 -0
  234. package/dist/storage/index-files.mjs +10 -5
  235. package/dist/storage/index-graph.mjs +72 -22
  236. package/dist/storage/index-remap.mjs +200 -64
  237. package/dist/storage/index-whole.mjs +127 -0
  238. package/dist/storage/largest-files.mjs +1 -1
  239. package/dist/storage/layout.mjs +23 -0
  240. package/dist/storage/loose.d.mts +7 -4
  241. package/dist/storage/loose.mjs +212 -67
  242. package/dist/storage/memory-budget.mjs +16 -4
  243. package/dist/storage/merge-plan.mjs +3 -2
  244. package/dist/storage/merge-row.mjs +7 -1
  245. package/dist/storage/merge-stream.mjs +164 -25
  246. package/dist/storage/merge-walk.mjs +8 -4
  247. package/dist/storage/merge-write.mjs +1 -1
  248. package/dist/storage/merge.d.mts +1 -1
  249. package/dist/storage/merge.mjs +1 -1
  250. package/dist/storage/object-rows.d.mts +1 -0
  251. package/dist/storage/object-rows.mjs +385 -65
  252. package/dist/storage/oid-table.mjs +171 -0
  253. package/dist/storage/pack-order.mjs +8 -4
  254. package/dist/storage/pack-ranges.d.mts +1 -2
  255. package/dist/storage/pack-ranges.mjs +4 -5
  256. package/dist/storage/pack-reads.d.mts +2 -1
  257. package/dist/storage/pack-reads.mjs +158 -42
  258. package/dist/storage/pack-receive.d.mts +1 -1
  259. package/dist/storage/pack-receive.mjs +2 -2
  260. package/dist/storage/packs.d.mts +1 -1
  261. package/dist/storage/packs.mjs +136 -66
  262. package/dist/storage/placed-reads.mjs +1 -1
  263. package/dist/storage/plan-columns.d.mts +4 -0
  264. package/dist/storage/plan-columns.mjs +238 -0
  265. package/dist/storage/prune-keep.mjs +134 -41
  266. package/dist/storage/prune-walk.mjs +202 -62
  267. package/dist/storage/prune.mjs +194 -91
  268. package/dist/storage/push-allotment.mjs +91 -12
  269. package/dist/storage/push-uploads.mjs +4 -4
  270. package/dist/storage/pushed-commits.mjs +4 -2
  271. package/dist/storage/quarantine.d.mts +1 -1
  272. package/dist/storage/range-cache.mjs +125 -8
  273. package/dist/storage/ready.d.mts +1 -1
  274. package/dist/storage/ready.mjs +8 -6
  275. package/dist/storage/receive-bounds.mjs +23 -8
  276. package/dist/storage/repack-backlog.mjs +6 -3
  277. package/dist/storage/repack.d.mts +1 -1
  278. package/dist/storage/rows.d.mts +1 -1
  279. package/dist/storage/rows.mjs +1 -1
  280. package/dist/storage/runs.mjs +195 -43
  281. package/dist/storage/send-list.d.mts +1 -0
  282. package/dist/storage/send-list.mjs +54 -10
  283. package/dist/storage/single-flight.mjs +13 -7
  284. package/dist/storage/stream-whole.mjs +127 -26
  285. package/dist/storage/unpack.mjs +371 -79
  286. package/dist/storage/visible.mjs +2 -2
  287. package/dist/storage/walk.mjs +192 -38
  288. package/dist/storage/wants.mjs +5 -5
  289. package/dist/store/bodies.mjs +38 -0
  290. package/dist/store/call-count.d.mts +8 -12
  291. package/dist/store/call-count.mjs +34 -46
  292. package/dist/store/catalogue.d.mts +2 -2
  293. package/dist/store/catalogue.mjs +145 -35
  294. package/dist/store/crossing.mjs +1 -3
  295. package/dist/store/cursor-seal.d.mts +1 -2
  296. package/dist/store/cursor-seal.mjs +16 -6
  297. package/dist/store/door.mjs +183 -0
  298. package/dist/store/errors.d.mts +3 -4
  299. package/dist/store/errors.mjs +15 -33
  300. package/dist/store/git-store.mjs +25 -7
  301. package/dist/store/job-try.mjs +9 -32
  302. package/dist/store/list-job.mjs +44 -8
  303. package/dist/store/records.d.mts +3 -0
  304. package/dist/store/records.mjs +3 -0
  305. package/dist/store/repo-record.d.mts +1 -2
  306. package/dist/store/repo-record.mjs +32 -20
  307. package/dist/store/reservations.mjs +1 -1
  308. package/dist/store/scopes.mjs +11 -0
  309. package/dist/store/settle.mjs +4 -4
  310. package/dist/sync/github.mjs +3 -3
  311. package/dist/sync/import.mjs +31 -18
  312. package/dist/sync/lfs-batch.mjs +4 -5
  313. package/dist/sync/lfs-copy.mjs +17 -6
  314. package/dist/sync/mirror.mjs +34 -31
  315. package/dist/sync/said.mjs +16 -37
  316. package/dist/sync/step.mjs +33 -25
  317. package/dist/sync/tries.mjs +9 -9
  318. package/dist/topics/advance.mjs +10 -11
  319. package/dist/topics/base.d.mts +15 -0
  320. package/dist/topics/base.mjs +8 -0
  321. package/dist/topics/host.mjs +1 -1
  322. package/dist/topics/layer.d.mts +4 -9
  323. package/dist/topics/layer.mjs +2 -3
  324. package/dist/topics/members.mjs +4 -4
  325. package/dist/topics/public.d.mts +2 -1
  326. package/dist/topics/topic.mjs +2 -2
  327. package/package.json +5 -4
  328. package/dist/contracts/promises.d.mts +0 -39
  329. package/dist/core/call-names.d.mts +0 -3
  330. package/dist/core/clock.mjs +0 -18
  331. package/dist/lfs/calls.mjs +0 -26
  332. package/dist/rest/api.d.mts +0 -23
  333. package/dist/rest/blobs.d.mts +0 -833
  334. package/dist/rest/commits.d.mts +0 -3543
  335. package/dist/rest/errors.d.mts +0 -2124
  336. package/dist/rest/events.d.mts +0 -426
  337. package/dist/rest/files.d.mts +0 -1342
  338. package/dist/rest/forks.d.mts +0 -2160
  339. package/dist/rest/handlers.d.mts +0 -8
  340. package/dist/rest/merges.d.mts +0 -477
  341. package/dist/rest/queue.d.mts +0 -5917
  342. package/dist/rest/refs.d.mts +0 -2988
  343. package/dist/rest/repos.d.mts +0 -2567
  344. package/dist/rest/tags.d.mts +0 -1316
  345. package/dist/rest/tokens.d.mts +0 -2614
  346. package/dist/rest/topics.d.mts +0 -2224
  347. package/dist/rest/trees.d.mts +0 -1709
  348. package/dist/rest/work.d.mts +0 -1695
  349. package/dist/server/lifecycle.d.mts +0 -2
  350. package/dist/store/promises.d.mts +0 -11
  351. package/dist/store/promises.mjs +0 -327
@@ -8,14 +8,15 @@ import { repoScope } from "../store/scopes.mjs";
8
8
  import { openRepo, repoAccess } from "../core/access.mjs";
9
9
  import { refViewAgain } from "../core/ref-view.mjs";
10
10
  import { knownParts, partsToRead, seenEvents } from "../core/events/seen.mjs";
11
- import { noCall, runIn } from "../store/crossing.mjs";
11
+ import { noCall, readableIn, runIn } from "../store/crossing.mjs";
12
12
  import { Authorize } from "../contracts/authorize.mjs";
13
13
  import { CoreParts } from "../core/parts.mjs";
14
- import { Clock } from "effect/Clock";
14
+ import * as EffectClock from "effect/Clock";
15
15
  import * as Effect from "effect/Effect";
16
16
  import { isInfraError } from "@ref0/infra";
17
17
  import * as Context from "effect/Context";
18
18
  import * as Stream from "effect/Stream";
19
+ import * as EffectDuration from "effect/Duration";
19
20
  // src/event-streams/stream.ts
20
21
  /**
21
22
  * The server's `FeedFields`, which `EventStreams.layer()` builds over beside core's needs.
@@ -27,7 +28,7 @@ const feedContext = Effect.gen(function* () {
27
28
  const parts = yield* CoreParts;
28
29
  const authorize = yield* Authorize;
29
30
  const clock = yield* Effect.clockWith(Effect.succeed);
30
- return Context.make(CoreParts, parts).pipe(Context.add(Authorize, authorize), Context.add(Clock, clock));
31
+ return Context.make(CoreParts, parts).pipe(Context.add(Authorize, authorize), Context.add(EffectClock.Clock, clock));
31
32
  });
32
33
  /** How long a stream goes without a word before it sends a heartbeat, checking access first. */
33
34
  const heartbeatMs = 9e3;
@@ -37,6 +38,28 @@ const batchSize = 100;
37
38
  const firstHold = 100;
38
39
  /** Only a create's and a rename's events are ever dropped and their `seq` written again. */
39
40
  const droppable = (event) => event.type === "repo.created" || event.type === "repo.renamed";
41
+ /** The longest one timer waits: a longer sleep is taken in turns. */
42
+ const longestTimer = 2 ** 31 - 1;
43
+ /** Sleeps on `clock` until `until`, in turns of at most `longestTimer`. */
44
+ const turnsUntil = /* @__PURE__ */ Effect.fnUntraced(function* (clock, until) {
45
+ for (let left = until - clock.currentTimeMillisUnsafe(); left > 0;) {
46
+ const slept = Math.min(left, longestTimer);
47
+ yield* clock.sleep(EffectDuration.millis(slept));
48
+ left -= slept;
49
+ }
50
+ });
51
+ /** Ends once `signal` aborts, at once for one already aborted. */
52
+ const abortOf = (signal) => Effect.callback((resume) => {
53
+ const end = () => resume(Effect.void);
54
+ if (signal.aborted) return end();
55
+ signal.addEventListener("abort", end, { once: true });
56
+ return Effect.sync(() => signal.removeEventListener("abort", end));
57
+ });
58
+ /**
59
+ * Sleeps until `until` on `clock`, or until `signal` aborts: one run, whose abort interrupts the
60
+ * turn it's in, so no timer is left behind.
61
+ */
62
+ const sleepUntil = (clock, until, signal) => runIn(Effect.raceFirst(turnsUntil(clock, until), abortOf(signal)), noCall);
40
63
  /** A turn of the event loop: what's already written arrives before it ends. */
41
64
  const tick = () => runIn(Effect.as(Effect.sleep(0), "tick"), noCall);
42
65
  /** The watch a stream opens: after the row of `after`, from position 0, or the oldest retained. */
@@ -69,7 +92,7 @@ const settled = /* @__PURE__ */ Effect.fnUntraced(function* (scope, candidates)
69
92
  collection: outboxCollections.events,
70
93
  id: eventId(event.seq)
71
94
  }))];
72
- const snapshot = yield* storeCall(() => core.store.read(scope, reads));
95
+ const snapshot = yield* storeCall(core.store.read(scope, reads));
73
96
  const { head } = yield* decodeOutbox([snapshot.results[0] ?? [], []]);
74
97
  const rows = snapshot.results.slice(1).flat();
75
98
  const reread = new Map((yield* decodeEvents(rows)).map((event) => [event.seq, event]));
@@ -97,7 +120,7 @@ const partsFor = /* @__PURE__ */ Effect.fnUntraced(function* (scope, events, kno
97
120
  collection: outboxCollections.events,
98
121
  id: eventId(seq)
99
122
  }));
100
- const snapshot = yield* storeCall(() => core.store.read(scope, reads));
123
+ const snapshot = yield* storeCall(core.store.read(scope, reads));
101
124
  const found = knownParts(yield* decodeEvents(snapshot.results.flat()), here);
102
125
  for (const id of asked.values()) if (!found.has(id)) found.set(id, void 0);
103
126
  return found;
@@ -169,7 +192,7 @@ const feedStream = (parts, core, needs, caller, internalId, after, counted) => {
169
192
  let known = /* @__PURE__ */ new Map();
170
193
  let hold = firstHold;
171
194
  let holdUntil;
172
- let beatAt = clock.now() + heartbeatMs;
195
+ let beatAt = clock.currentTimeMillisUnsafe() + heartbeatMs;
173
196
  const end = () => {
174
197
  parts.closing.removeEventListener("abort", end);
175
198
  ending.abort();
@@ -184,7 +207,7 @@ const feedStream = (parts, core, needs, caller, internalId, after, counted) => {
184
207
  * life, which marks it `landed` and wakes the wait then, so an idle stream's waits add none.
185
208
  */
186
209
  const next = () => {
187
- reader ??= core.store.watch(scope, watchOf(after)).getReader();
210
+ reader ??= readableIn(core.store.watch(scope, watchOf(after)), needs).getReader();
188
211
  if (pending !== void 0) return pending;
189
212
  const read = reader.read();
190
213
  const land = () => {
@@ -206,7 +229,7 @@ const feedStream = (parts, core, needs, caller, internalId, after, counted) => {
206
229
  ending.signal.addEventListener("abort", onEnd, { once: true });
207
230
  const woke = new Promise((resolve) => woken = () => resolve());
208
231
  try {
209
- await Promise.race([woke, clock.sleep(Math.min(beatAt, holdUntil ?? beatAt), waking.signal)]);
232
+ await Promise.race([woke, sleepUntil(clock, Math.min(beatAt, holdUntil ?? beatAt), waking.signal)]);
210
233
  } finally {
211
234
  woken = () => void 0;
212
235
  waking.abort();
@@ -256,7 +279,7 @@ const feedStream = (parts, core, needs, caller, internalId, after, counted) => {
256
279
  return [];
257
280
  }
258
281
  held = waiting.held;
259
- holdUntil = held.length === 0 ? void 0 : clock.now() + hold;
282
+ holdUntil = held.length === 0 ? void 0 : clock.currentTimeMillisUnsafe() + hold;
260
283
  hold = held.length === 0 ? firstHold : Math.min(hold * 2, heartbeatMs);
261
284
  const deleted = ready.findIndex((event) => event.type === "repo.deleted");
262
285
  return deleted === -1 ? ready : ready.slice(0, deleted + 1);
@@ -277,9 +300,9 @@ const feedStream = (parts, core, needs, caller, internalId, after, counted) => {
277
300
  if (ending.signal.aborted) return;
278
301
  const woke = await wait();
279
302
  if (parts.closing.aborted) throw closedError();
280
- if (woke === "slept" && clock.now() >= beatAt) {
303
+ if (woke === "slept" && clock.currentTimeMillisUnsafe() >= beatAt) {
281
304
  await run(recheck(parts, caller, internalId));
282
- beatAt = clock.now() + heartbeatMs;
305
+ beatAt = clock.currentTimeMillisUnsafe() + heartbeatMs;
283
306
  controller.enqueue({ kind: "heartbeat" });
284
307
  return;
285
308
  }
@@ -303,12 +326,12 @@ const feedStream = (parts, core, needs, caller, internalId, after, counted) => {
303
326
  known = lastWrite(events, writes);
304
327
  last = events.at(-1)?.seq;
305
328
  if (seen.length === 0) {
306
- if (clock.now() < beatAt) continue;
307
- beatAt = clock.now() + heartbeatMs;
329
+ if (clock.currentTimeMillisUnsafe() < beatAt) continue;
330
+ beatAt = clock.currentTimeMillisUnsafe() + heartbeatMs;
308
331
  controller.enqueue({ kind: "heartbeat" });
309
332
  return;
310
333
  }
311
- beatAt = clock.now() + heartbeatMs;
334
+ beatAt = clock.currentTimeMillisUnsafe() + heartbeatMs;
312
335
  controller.enqueue({
313
336
  kind: "events",
314
337
  events: seen
package/dist/extend.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { isServerClosed } from "./store/closed.mjs";
2
2
  import { Joined, JoinedAdapter, JoinedCalls } from "./server/joined.mjs";
3
- import { Bucket } from "./contracts/objects.mjs";
4
- import { Clock, RecordStore, Store } from "./contracts/promises.mjs";
5
3
  import { ImportLfsMissed, ImportLfsReason, ImportState, ImportStatus } from "./contracts/sync.mjs";
6
4
  import { heldUntil, inTime } from "./store/repo-record.mjs";
7
- export { type Bucket, type Clock, type ImportLfsMissed, type ImportLfsReason, type ImportState, type ImportStatus, type Joined, type JoinedAdapter, JoinedCalls, type RecordStore, type Store, heldUntil, inTime, isServerClosed };
5
+ import { Addition, AlreadyExists, Behind, Bucket, BucketLinks, BucketUploads, CallLimit, CallLimits, Change, Claim, ClaimLost, ClaimRequest, ClaimResult, Committed, Compacted, Count, Duration, Expired, InfraFailure, Internal, InvalidArgument, JobCounts, JobInput, JobItem, JobListRequest, JobProgress, JobQueue, JobRef, JobState, Key, Late, Listing, Moment, NotFailed, NotFound, Outcome, ProgressSample, ProgressStored, ProgressWrite, Read, Records, RetryInput, Row, Scope, Settled, Setup, Snapshot, TooLarge, Unavailable, Wake, Watch, WatchedRow, WorkMeasure, checkWrites } from "@ref0/infra";
6
+ export { type Addition, AlreadyExists, Behind, Bucket, BucketLinks, BucketUploads, CallLimit, CallLimits, type Change, type Claim, ClaimLost, type ClaimRequest, type ClaimResult, type Committed, Compacted, type Count, type Duration, Expired, type ImportLfsMissed, type ImportLfsReason, type ImportState, type ImportStatus, type InfraFailure, Internal, InvalidArgument, type JobCounts, type JobInput, type JobItem, type JobListRequest, type JobProgress, JobQueue, type JobRef, type JobState, type Joined, type JoinedAdapter, JoinedCalls, type Key, Late, type Listing, type Moment, NotFailed, NotFound, type Outcome, type ProgressSample, type ProgressStored, type ProgressWrite, type Read, Records, type RetryInput, type Row, type Scope, type Settled, Setup, type Snapshot, TooLarge, Unavailable, Wake, type Watch, type WatchedRow, type WorkMeasure, checkWrites, heldUntil, inTime, isServerClosed };
package/dist/extend.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { isServerClosed } from "./store/closed.mjs";
2
2
  import { JoinedCalls } from "./server/joined.mjs";
3
3
  import { heldUntil, inTime } from "./store/repo-record.mjs";
4
- export { JoinedCalls, heldUntil, inTime, isServerClosed };
4
+ import { AlreadyExists, Behind, Bucket, BucketLinks, BucketUploads, CallLimit, CallLimits, ClaimLost, Compacted, Expired, Internal, InvalidArgument, JobQueue, Late, NotFailed, NotFound, Records, Setup, TooLarge, Unavailable, Wake, checkWrites } from "@ref0/infra";
5
+ export { AlreadyExists, Behind, Bucket, BucketLinks, BucketUploads, CallLimit, CallLimits, ClaimLost, Compacted, Expired, Internal, InvalidArgument, JobQueue, JoinedCalls, Late, NotFailed, NotFound, Records, Setup, TooLarge, Unavailable, Wake, checkWrites, heldUntil, inTime, isServerClosed };
@@ -2,7 +2,7 @@ import { httpStatus, refusalCodeHeader } from "../contracts/result.mjs";
2
2
  // src/http/answers.ts
3
3
  /**
4
4
  * Smart HTTP's answers outside the protocol's own bytes: a refusal's status and code, the
5
- * challenges a 401 carries, and the headers `gitprotocol-http` asks of every answer, which no cache may keep.
5
+ * challenge a 401 carries, and the headers `gitprotocol-http` asks of every answer, which no cache may keep.
6
6
  */
7
7
  /** `gitprotocol-http`'s headers for a dynamic answer: never cached. */
8
8
  const noCache = {
@@ -10,8 +10,11 @@ const noCache = {
10
10
  pragma: "no-cache",
11
11
  "cache-control": "no-cache, max-age=0, must-revalidate"
12
12
  };
13
- /** The two schemes a 401 offers, in the order Git's credential helpers try them. */
14
- const challenges = ["Basic realm=\"Git\"", "Bearer realm=\"Git\""];
13
+ /**
14
+ * The scheme a 401 offers: Basic alone, as GitHub's does. Advertising Bearer beside it makes
15
+ * libcurl see multi-scheme auth and send a second anonymous GET before retrying with Basic (#2524).
16
+ */
17
+ const challenges = ["Basic realm=\"Git\""];
15
18
  /** A refusal's hint as Git prints it, on band 2 or in a refusal's body: a `hint:` line for each. */
16
19
  const hintLines = (hint) => hint?.split(/\r?\n/).map((line) => `hint: ${line}`) ?? [];
17
20
  /** A plain-text answer, uncached: `message`, then a newline. */
@@ -30,7 +33,7 @@ const refused = (status, code, message, headers) => {
30
33
  answer.set(refusalCodeHeader, code);
31
34
  return told(status, message, answer);
32
35
  };
33
- /** A 401 that asks for `Basic`, then `Bearer`. */
36
+ /** A 401 that asks for `Basic`. */
34
37
  const signIn = (message) => {
35
38
  const headers = new Headers();
36
39
  for (const challenge of challenges) headers.append("www-authenticate", challenge);
@@ -39,7 +42,7 @@ const signIn = (message) => {
39
42
  /** The answer for a repo a caller can't find, whether it's missing or hidden from them. */
40
43
  const notFound = () => refused(404, "NOT_FOUND", "Repository not found");
41
44
  /**
42
- * A refusal before any protocol bytes: a caller to sign in gets the challenges; one refused a
45
+ * A refusal before any protocol bytes: a caller to sign in gets the challenge; one refused a
43
46
  * read gets the 404 a missing repo gets, so the repo's existence stays hidden. Pass `true` for an
44
47
  * answer that isn't a repo read, such as a push, a feature route or an approval page, so
45
48
  * `NOT_ALLOWED` keeps its 403. Any other refusal's body is its message, then its `hintLines`, which
@@ -1,5 +1,6 @@
1
1
  import { fail, gitError, gitErrorFrom } from "../contracts/result.mjs";
2
- import { contended, openRepo, repoAccess } from "../core/access.mjs";
2
+ import { contended, openRepo, readersFirst, repoAccess } from "../core/access.mjs";
3
+ import { asAsked } from "../core/asked.mjs";
3
4
  import { accessAgain } from "../core/ref-view.mjs";
4
5
  import { gitPush, keyedGitPush } from "../core/push.mjs";
5
6
  import { runFetchRules } from "../core/rules/fetch.mjs";
@@ -8,19 +9,18 @@ import { CoreParts, ObjectsParts } from "../core/parts.mjs";
8
9
  import { SealedObjects, rootsSeen, viewOf } from "../core/view.mjs";
9
10
  import { isVisibleTooLong, notReachable } from "../storage/visible.mjs";
10
11
  import { heldOf, unreachableWant, wantWalkMost } from "../storage/wants.mjs";
11
- import { objectsFace } from "../storage/calls.mjs";
12
12
  import { indexRowKey } from "../storage/layout.mjs";
13
13
  import { spentIn } from "../contracts/calls-spent.mjs";
14
14
  import { answerSpent, decodeRow } from "../store/errors.mjs";
15
15
  import { refPageRows, storedPeel } from "../store/ref-rows.mjs";
16
16
  import { decodePacks } from "../store/git-store.mjs";
17
17
  import { ReachedMark, markHolds } from "../store/records.mjs";
18
+ import { entryOf } from "../store/catalogue.mjs";
18
19
  import { readRecord, rootsOf } from "../store/repo-record.mjs";
19
20
  import { collections, reachedKey, repoRootsKey } from "../store/scopes.mjs";
20
21
  import { fetchReaches, hiddenUnder } from "../protocol/wire/lines.mjs";
21
22
  import { read } from "../core/objects/objects.mjs";
22
23
  import * as Effect from "effect/Effect";
23
- import * as Context from "effect/Context";
24
24
  // src/http/core-parts.ts
25
25
  /**
26
26
  * Git's HTTP over a server's core: who a request is and where a renamed repo went, from the
@@ -78,17 +78,17 @@ const rootsPastWalk = () => gitError("RESOURCE_EXHAUSTED", `Can't tell which of
78
78
  hint: "Fetch with Git protocol v2",
79
79
  context: { reason: "walk-limit" }
80
80
  });
81
- const coreHttpParts = (parts, options = {}) => {
82
- const { needs } = parts;
83
- const core = Context.get(needs, CoreParts);
84
- const stored = Context.get(needs, ObjectsParts);
81
+ const make = (input, options = {}) => {
85
82
  /**
86
83
  * `resolved` as `at`'s record has it, read in the same call as the refs `caller` is shown, its
87
84
  * access asked again by `accessAgain` and its ref view afresh (Q884): a fetch's open answers before
88
85
  * its body is read, and a listing's pages are read as its client asks, so each read decides
89
- * access from the record it comes with. A repo deleted or renamed since is `NOT_FOUND`.
86
+ * access from the record it comes with. A repo deleted or renamed since is `NOT_FOUND`. With
87
+ * `asked`, the open's confirm is on this read, as `Confirm`'s `first-read` says: after access is
88
+ * asked again, so a caller it now refuses is answered as a call after the move would be, and
89
+ * before the view, whose host lookup is made only of the repo the open was asked of.
90
90
  */
91
- const current = Effect.fnUntraced(function* (caller, repo, resolved, at) {
91
+ const current = Effect.fnUntraced(function* (caller, repo, resolved, at, asked) {
92
92
  const { record, snapshot } = at;
93
93
  if (record === void 0 || record.deleted === true || record.name !== resolved.name) return yield* fail("NOT_FOUND", `No repo '${repo}'`);
94
94
  const { internalId } = resolved;
@@ -97,6 +97,7 @@ const coreHttpParts = (parts, options = {}) => {
97
97
  record,
98
98
  internalId
99
99
  }));
100
+ if (asked !== void 0) yield* asAsked(asked, record);
100
101
  const now = {
101
102
  ...resolved,
102
103
  record,
@@ -119,7 +120,8 @@ const coreHttpParts = (parts, options = {}) => {
119
120
  * asked again of the record read here, by `current`.
120
121
  */
121
122
  const opened = Effect.fnUntraced(function* (caller, operation, { peel = true } = {}, given) {
122
- const resolved = given ?? (yield* openRepo(caller, operation));
123
+ const core = yield* CoreParts;
124
+ const resolved = given ?? (yield* openRepo(caller, operation, [], void 0, "first-read"));
123
125
  const read$1 = yield* readRecord(core.store, resolved.internalId, [
124
126
  refsRead,
125
127
  packsRead,
@@ -128,6 +130,7 @@ const coreHttpParts = (parts, options = {}) => {
128
130
  repoRootsKey
129
131
  ]);
130
132
  const { record, snapshot } = read$1;
133
+ if (given === void 0) yield* asAsked(resolved, record);
131
134
  if (record === void 0 || record.deleted === true) return yield* fail("NOT_FOUND", `No repo '${operation.repo}'`);
132
135
  const [, refRows = [], packRows = [], indexRows = [], markRows = [], rootRows] = snapshot.results;
133
136
  const packs = yield* decodePacks(packRows);
@@ -137,7 +140,7 @@ const coreHttpParts = (parts, options = {}) => {
137
140
  version: snapshot.version,
138
141
  packs
139
142
  };
140
- const view = given === void 0 ? yield* viewOf(caller, resolved, void 0, { ownWrites: false }) : (yield* current(caller, operation.repo, given, read$1)).view;
143
+ const view = given === void 0 ? yield* viewOf(caller, resolved, void 0, { ownWrites: false }) : (yield* current(caller, operation.repo, given, read$1, given)).view;
141
144
  const seen = yield* view.refs(refRows);
142
145
  const row = indexRows[0]?.value;
143
146
  const viewed = yield* read({
@@ -150,7 +153,7 @@ const coreHttpParts = (parts, options = {}) => {
150
153
  roots
151
154
  }
152
155
  });
153
- const objects = objectsFace(viewed);
156
+ const objects = viewed;
154
157
  const [stored] = indexRows;
155
158
  const lost = stored === void 0 ? void 0 : core.indexLost?.(resolved.internalId, stored, listed);
156
159
  const index = viewed.index === void 0 ? void 0 : {
@@ -193,19 +196,21 @@ const coreHttpParts = (parts, options = {}) => {
193
196
  });
194
197
  /**
195
198
  * The refs a listing streams of `resolved`, which `authorize` let `caller` fetch: the record and
196
- * the first page in one read, `HEAD`'s row with the record again, then each page past the last
197
- * as it's asked,
199
+ * the first page in one read, `HEAD`'s row with the record again only when page 1 filled
200
+ * `refPageRows` without holding `HEAD` (#2518), then each page past the last as it's asked,
198
201
  * `refPageRows` at a time, so a listing holds one page whatever the repo's refs, and reads no
199
202
  * object: each tag's row stores its peel (Q884). Each page is read by `after` at its own version,
200
203
  * so a ref is listed once, at a value some version held, and one there throughout is never
201
204
  * skipped: Git's own `ls-refs` reads loose refs with no snapshot, and a fetch reads its refs again
202
205
  * at its own. Each later page reads the record in its own call and asks `current`, and the first
203
- * page and `HEAD` ask it of `HEAD`'s read, the later of theirs, so a repo deleted, renamed or made
204
- * private, a right lost or a token revoked since the open, a POST's body read between, ends the
205
- * listing. The repo's roots are read with page 1, and those `caller` may be told are asked once
206
- * the last page is listed, as `ListedRefs.roots` says.
206
+ * page and `HEAD` ask it of `HEAD`'s read (or page 1's when `HEAD` came from page 1), the later
207
+ * of theirs, so a repo deleted, renamed or made private, a right lost or a token revoked since
208
+ * the open, a POST's body read between, ends the listing. The repo's roots are read with page 1,
209
+ * and those `caller` may be told are asked once the last page is listed, as `ListedRefs.roots`
210
+ * says.
207
211
  */
208
212
  const listsAt = Effect.fnUntraced(function* (caller, repo, resolved) {
213
+ const core = yield* CoreParts;
209
214
  const { internalId } = resolved;
210
215
  /** The ref past which the page after `rows` starts, unless `rows` was the last page. */
211
216
  const lastOf = (rows) => rows.length === 1024 ? rows.at(-1)?.id : void 0;
@@ -224,23 +229,25 @@ const coreHttpParts = (parts, options = {}) => {
224
229
  const refsOf = ({ rows, view }) => Effect.flatMap(view.refs(rows), (seen) => advertised(rows, seen));
225
230
  const page = yield* readRecord(core.store, internalId, [refPage(), repoRootsKey]);
226
231
  if (page.record === void 0) return yield* fail("NOT_FOUND", `No repo '${repo}'`);
232
+ const rows = page.snapshot.results[1] ?? [];
233
+ const last = lastOf(rows);
227
234
  const roots = yield* rootsOf(page.snapshot.results[2]);
228
235
  const head = headOf(page.record.defaultBranch);
229
- const headRead = {
236
+ const headInPage = rows.find((row) => row.id === head);
237
+ const needHead = headInPage === void 0 && last !== void 0;
238
+ const atHead = needHead ? yield* readRecord(core.store, internalId, [{
230
239
  collection: collections.refs,
231
240
  id: head
232
- };
233
- const atHead = yield* readRecord(core.store, internalId, [headRead]);
234
- const { view } = yield* current(caller, repo, resolved, atHead);
235
- const rows = page.snapshot.results[1] ?? [];
241
+ }]) : page;
242
+ const { view } = yield* current(caller, repo, resolved, atHead, resolved);
236
243
  const first = {
237
244
  view,
238
245
  rows,
239
- last: lastOf(rows)
246
+ last
240
247
  };
241
248
  const refView = yield* view.refView;
242
249
  const [headRef] = yield* refsOf({
243
- rows: atHead.snapshot.results[1] ?? [],
250
+ rows: needHead ? atHead.snapshot.results[1] ?? [] : headInPage === void 0 ? [] : [headInPage],
244
251
  view
245
252
  });
246
253
  let pending = first;
@@ -255,42 +262,40 @@ const coreHttpParts = (parts, options = {}) => {
255
262
  });
256
263
  return refs;
257
264
  });
258
- const next = Effect.gen(function* () {
259
- const page = pending;
260
- pending = void 0;
261
- if (page !== void 0) return yield* shownOf(page);
262
- if (after === void 0) return void 0;
263
- const later = yield* pageAt(after);
264
- after = later.last;
265
- return yield* shownOf(later);
266
- });
267
- const told = Effect.gen(function* () {
268
- if (roots.size === 0) return [];
269
- const read = yield* readRecord(core.store, internalId, [
270
- packsRead,
271
- indexRowKey,
272
- repoRootsKey
273
- ]);
274
- const { view } = yield* current(caller, repo, resolved, read);
275
- const seen = yield* view.refView;
276
- const [, packRows = [], indexRows = [], rootRows] = read.snapshot.results;
277
- const packs = yield* decodePacks(packRows);
278
- const at = {
279
- listed: {
280
- repo: internalId,
281
- version: read.snapshot.version,
282
- packs
283
- },
284
- index: indexRows[0]?.value,
285
- roots: yield* rootsOf(rootRows),
286
- tips: [...new Set(tips.flatMap(({ name, oid }) => seen.sees(name) ? [oid] : []))]
287
- };
288
- return [...yield* Effect.catchIf(rootsSeen(view, at), isVisibleTooLong, () => Effect.fail(rootsPastWalk()))].toSorted();
289
- });
290
265
  const listed = {
291
- next: Effect.provideContext(next, needs),
266
+ next: Effect.gen(function* () {
267
+ const page = pending;
268
+ pending = void 0;
269
+ if (page !== void 0) return yield* shownOf(page);
270
+ if (after === void 0) return void 0;
271
+ const later = yield* pageAt(after);
272
+ after = later.last;
273
+ return yield* shownOf(later);
274
+ }),
292
275
  hidden,
293
- roots: Effect.provideContext(told, needs)
276
+ roots: Effect.gen(function* () {
277
+ if (roots.size === 0) return [];
278
+ const read = yield* readRecord(core.store, internalId, [
279
+ packsRead,
280
+ indexRowKey,
281
+ repoRootsKey
282
+ ]);
283
+ const { view } = yield* current(caller, repo, resolved, read);
284
+ const seen = yield* view.refView;
285
+ const [, packRows = [], indexRows = [], rootRows] = read.snapshot.results;
286
+ const packs = yield* decodePacks(packRows);
287
+ const at = {
288
+ listed: {
289
+ repo: internalId,
290
+ version: read.snapshot.version,
291
+ packs
292
+ },
293
+ index: indexRows[0]?.value,
294
+ roots: yield* rootsOf(rootRows),
295
+ tips: [...new Set(tips.flatMap(({ name, oid }) => seen.sees(name) ? [oid] : []))]
296
+ };
297
+ return [...yield* Effect.catchIf(rootsSeen(view, at), isVisibleTooLong, () => Effect.fail(rootsPastWalk()))].toSorted();
298
+ })
294
299
  };
295
300
  const shown = hiddenUnder(hidden, head) === void 0;
296
301
  if (shown && refView.sees(head)) listed.head = head;
@@ -301,14 +306,17 @@ const coreHttpParts = (parts, options = {}) => {
301
306
  * A refused push, told as `refused` only to a caller that may read the repo: anyone else gets
302
307
  * the read's own refusal, as a fetch or a REST read would. By default that's the `NOT_FOUND` a
303
308
  * repo that isn't there gets, so a push can't tell a stranger a private repo exists; a host's
304
- * `authorize` that refuses the read with a code of its own is answered with it, as everywhere. A
305
- * push past a call bound never reaches it: the bound stops the request whole.
309
+ * `authorize` that refuses the read with a code of its own is answered with it, as everywhere.
310
+ * A signed-out caller's push is answered as `readersFirst` says. A push past a call bound never
311
+ * reaches it: the bound stops the request whole.
306
312
  */
307
- const readersOnly = (caller, repo, refused) => Effect.andThen(openRepo(caller, {
313
+ const readersOnly = (caller, repo, refused) => readersFirst(caller, refused, openRepo(caller, {
308
314
  kind: "read",
309
315
  repo
310
- }), Effect.fail(refused));
311
- const served = (caller, repo, at) => {
316
+ }));
317
+ const served = Effect.fnUntraced(function* (caller, repo, at) {
318
+ const core = yield* CoreParts;
319
+ const stored = yield* ObjectsParts;
312
320
  const hidden = core.hiddenRefs();
313
321
  const tips = new Set(at.refs.refs.flatMap((ref) => {
314
322
  if (!fetchReaches(hidden, ref.name)) return [];
@@ -349,34 +357,42 @@ const coreHttpParts = (parts, options = {}) => {
349
357
  return yield* at.objects.fetch(at.listed, fetching);
350
358
  })
351
359
  };
352
- };
353
- const receiving = (caller, repo, at) => ({
354
- refs: at.refs,
355
- hidden: core.hiddenRefs(),
356
- push: (input) => Effect.provideContext(pushed(stored, caller, repo, input, options.queue), needs)
360
+ });
361
+ const receiving = Effect.fnUntraced(function* (caller, repo, at) {
362
+ const core = yield* CoreParts;
363
+ const stored = yield* ObjectsParts;
364
+ return {
365
+ refs: at.refs,
366
+ hidden: core.hiddenRefs(),
367
+ push: (input) => pushed(stored, caller, repo, input, options.queue)
368
+ };
357
369
  });
358
370
  const http = {
359
- basePath: parts.basePath,
371
+ basePath: input.basePath,
360
372
  agent: serverAgent,
361
373
  lfs: options.lfs ?? (() => void 0),
362
374
  uploads: options.uploads ?? (() => void 0),
363
- identify: parts.identify,
364
- renamedTo: parts.renamedTo,
365
- fetchOpen: (caller, repo, confirm) => Effect.map(openRepo(caller, {
375
+ identify: input.identify,
376
+ entryAhead: Effect.fnUntraced(function* (repo) {
377
+ const core = yield* CoreParts;
378
+ return yield* entryOf(core.store, repo);
379
+ }),
380
+ renamedTo: input.renamedTo,
381
+ fetchOpen: (caller, repo, confirm = "first-read") => Effect.map(openRepo(caller, {
366
382
  kind: "fetch",
367
383
  repo
368
384
  }, [], void 0, confirm), (resolved) => ({
369
- serve: Effect.map(opened(caller, {
385
+ serve: Effect.flatMap(opened(caller, {
370
386
  kind: "fetch",
371
387
  repo
372
- }, {}, resolved), (at) => served(caller, repo, at)).pipe(Effect.provideContext(needs)),
373
- lists: Effect.provideContext(listsAt(caller, repo, resolved), needs)
374
- })).pipe(Effect.provideContext(needs)),
388
+ }, {}, resolved), (at) => served(caller, repo, at)),
389
+ lists: listsAt(caller, repo, resolved)
390
+ })),
375
391
  receive: (caller, repo) => opened(caller, {
376
392
  kind: "push",
377
393
  repo,
378
394
  updates: []
379
- }, { peel: false }).pipe(Effect.map((at) => receiving(caller, repo, at)), Effect.catch((error) => readersOnly(caller, repo, error)), Effect.provideContext(needs))
395
+ }, { peel: false }).pipe(Effect.flatMap((at) => receiving(caller, repo, at)), Effect.catch((error) => readersOnly(caller, repo, error)))
380
396
  };
381
397
  if (options.pushObjectsMost !== void 0) http.pushObjectsMost = options.pushObjectsMost;
382
398
  if (options.maxDuration !== void 0) http.maxDuration = options.maxDuration;
@@ -460,4 +476,4 @@ const landed = (stored, objects, caller, repo, input, internalId) => {
460
476
  objects
461
477
  });
462
478
  };
463
- export { coreHttpParts, serverAgent };
479
+ export { make, serverAgent };
@@ -1,13 +1,16 @@
1
+ import { EntryAhead } from "../store/catalogue.mjs";
1
2
  import { routeEdge } from "../store/errors.mjs";
2
3
  import { moved, refusal, requestType, told } from "./answers.mjs";
3
- import { lfsAnswer, lfsRefusal } from "../lfs/wire.mjs";
4
+ import { lfsMessage, lfsRefusal } from "../lfs/answer.mjs";
4
5
  import { gitUrlOf, infoRefsPath, isGitService, normalBase } from "./paths.mjs";
5
6
  import { receivePack, receivePackRefs, routeCounted } from "./receive-pack.mjs";
6
7
  import { uploadPack, uploadPackRefs } from "./upload-pack.mjs";
7
- import * as Clock$1 from "effect/Clock";
8
+ import * as Clock from "effect/Clock";
8
9
  import * as Effect from "effect/Effect";
10
+ import * as Fiber from "effect/Fiber";
9
11
  // src/http/handler.ts
10
- const gitHttp = (parts) => {
12
+ /** Git's smart HTTP over `parts`, whose Effects need `R`. */
13
+ const make = (parts) => {
11
14
  const base = normalBase(parts.basePath);
12
15
  return { route: (request) => {
13
16
  const url = new URL(request.url);
@@ -28,7 +31,7 @@ const lfsOff = "This server has no Git LFS: its host turns it on";
28
31
  /** A request to Git LFS's API: its refusals are LFS's JSON, as git-lfs reads them. */
29
32
  const lfsRoute = /* @__PURE__ */ Effect.fnUntraced(function* (parts, git, request) {
30
33
  const lfs = parts.lfs();
31
- if (lfs === void 0) return lfsAnswer(404, { message: lfsOff });
34
+ if (lfs === void 0) return lfsMessage(404, lfsOff);
32
35
  const caller = yield* parts.identify(request);
33
36
  const repo = git.path;
34
37
  return yield* routeCounted(parts, lfs({
@@ -62,10 +65,34 @@ const malformedRequest = (git, request) => {
62
65
  if (request.method !== "POST") return told(405, "Method not allowed", { allow: "POST" });
63
66
  return (request.headers.get("content-type") ?? "").split(";")[0]?.trim().toLowerCase() === requestType(git.service) ? void 0 : told(415, "Unsupported media type");
64
67
  };
68
+ /**
69
+ * Whether `git`'s route has a call to spare for its repo's catalogue entry: on main's order that's
70
+ * its count's first call, which a bound of none refuses before it starts, so the entry isn't read
71
+ * ahead under one (#2518).
72
+ */
73
+ const roomForEntry = (parts, git) => {
74
+ const most = git.service === "git-receive-pack" ? parts.pushCalls : parts.fetchCalls;
75
+ return most === void 0 || most.subrequests > 0;
76
+ };
65
77
  const answer = /* @__PURE__ */ Effect.fnUntraced(function* (parts, base, git, request) {
66
- const started = yield* Clock$1.currentTimeMillis;
78
+ const started = yield* Clock.currentTimeMillis;
79
+ const { entryAhead } = parts;
80
+ if (entryAhead === void 0 || !roomForEntry(parts, git)) {
81
+ const caller = yield* parts.identify(request);
82
+ return yield* serve(parts, base, git, caller, git.path, request, started);
83
+ }
84
+ const reading = yield* Effect.forkChild(Effect.exit(entryAhead(git.path)), { startImmediately: true });
67
85
  const caller = yield* parts.identify(request);
68
- return yield* serve(parts, base, git, caller, git.path, request, started);
86
+ let left = reading;
87
+ const ahead = {
88
+ name: git.path,
89
+ take: () => {
90
+ const taken = left;
91
+ left = void 0;
92
+ return taken === void 0 ? void 0 : Effect.flatten(Fiber.join(taken));
93
+ }
94
+ };
95
+ return yield* Effect.provideService(serve(parts, base, git, caller, git.path, request, started), EntryAhead, ahead);
69
96
  }, (route, _parts, _base, git) => routeEdge(route, (error) => refusal(error, git.service === "git-receive-pack")));
70
97
  /** A refusal a repo that isn't there gets, which a renamed repo's old name may answer instead. */
71
98
  const isMissing = (error) => error.code === "NOT_FOUND" || error.code === "UNAUTHENTICATED" || error.code === "NOT_ALLOWED";
@@ -77,4 +104,4 @@ const serve = (parts, base, git, caller, repo, request, started) => {
77
104
  }
78
105
  return git.service === "git-receive-pack" ? receivePack(parts, caller, repo, request) : uploadPack(parts, caller, repo, request, started);
79
106
  };
80
- export { gitHttp };
107
+ export { make };
@@ -1,4 +1,3 @@
1
- import "../contracts/server.mjs";
2
1
  /**
3
2
  * What `toNodeHandler` reads of `node:http`'s request, which Express's extends: this package has
4
3
  * no Node types, so the few members used are typed here.
@@ -43,6 +42,20 @@ export interface NodeResponse {
43
42
  }
44
43
  /** A listener for `node:http`'s `createServer`, or an Express route. */
45
44
  export type NodeHandler = (request: NodeRequest, response: NodeResponse) => void;
45
+ /**
46
+ * What a Node host serves under, its public origin, when a proxy in front of it serves one its
47
+ * socket can't tell, as one that ends TLS does: every link Git gives out, a clone's, a redirect's
48
+ * and LFS's, is built from it. A request's own `Host`, `X-Forwarded-Host` and `X-Forwarded-Proto`
49
+ * never are: a client can send any of them.
50
+ */
51
+ export interface NodeServeOptions {
52
+ /**
53
+ * The origin the host is reached at, such as `'https://git.example.com'`: a scheme, a host and a
54
+ * port, with no path, query or trailing slash. A `basePath` stays the runtime's. Unset, each
55
+ * request's is the connection's, its scheme from the socket and its host from its `Host`.
56
+ */
57
+ readonly origin?: string | undefined;
58
+ }
46
59
  /** Express's `next`: the request goes on to the app's own middleware and routes. */
47
60
  export type NodeNext = () => void;
48
61
  /** An Express middleware, or `next` for a request it doesn't answer. */