@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
@@ -1,3 +1,4 @@
1
+ import { dropBody } from "../protocol/bytes/reader.mjs";
1
2
  import { gathered } from "../protocol/bytes/streams.mjs";
2
3
  import { contended, openFor } from "../core/access.mjs";
3
4
  import { ownWriter } from "../core/own-writes.mjs";
@@ -8,14 +9,16 @@ import { utf8 } from "../protocol/bytes/text.mjs";
8
9
  import { objectId } from "../protocol/objects/object.mjs";
9
10
  import { bestEffort, decodeRow } from "../store/errors.mjs";
10
11
  import { randomText } from "../store/random.mjs";
12
+ import { bodyUntilAborted } from "../store/bodies.mjs";
11
13
  import { bucketCall, bucketDo, bucketFailed, bucketStream } from "../storage/calls.mjs";
14
+ import { CallBudget } from "../store/call-count.mjs";
12
15
  import { isLfsOid, lfsPointerText } from "../protocol/objects/lfs-pointer.mjs";
13
16
  import { ListedRow, UploadRow, largestObject, lfsCollections, linkLife, listedKey, listedRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadRead } from "./rows.mjs";
14
17
  import { BatchRequest, VerifyRequest, batchMost, bodyOf, lfsAnswer } from "./wire.mjs";
15
18
  import { uploadedRow } from "./uploaded.mjs";
16
19
  import { pastMost, uploadPieceBytes } from "./upload-most.mjs";
17
20
  import { fail, gitError, httpStatus } from "../contracts/result.mjs";
18
- import * as Clock$1 from "effect/Clock";
21
+ import * as Clock from "effect/Clock";
19
22
  import * as Effect from "effect/Effect";
20
23
  import * as Option from "effect/Option";
21
24
  import * as Result from "effect/Result";
@@ -196,7 +199,7 @@ const downloads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo
196
199
  const chained = yield* chainListed(parts.rows, repo, oids);
197
200
  const listed = yield* seenListed(call.caller, repo, oids, chained);
198
201
  const refused = yield* refusedOf(call, listed);
199
- const expiresAt = (yield* Clock$1.currentTimeMillis) + linkLife;
202
+ const expiresAt = (yield* Clock.currentTimeMillis) + linkLife;
200
203
  const answers = /* @__PURE__ */ new Map();
201
204
  for (const { oid, size } of objects) {
202
205
  const row = listed.get(oid);
@@ -234,7 +237,7 @@ const downloads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo
234
237
  const uploads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo, objects) {
235
238
  const oids = objects.map(({ oid }) => oid);
236
239
  for (let tries = 0; tries < 5; tries += 1) {
237
- const at = yield* Clock$1.currentTimeMillis;
240
+ const at = yield* Clock.currentTimeMillis;
238
241
  const asked = tries === 0 ? repo : void 0;
239
242
  const read = yield* objectRows(parts.rows, call.caller, repo, oids, { asked });
240
243
  const unseen = yield* unseenRows(call.caller, repo, oids, read.rows);
@@ -307,7 +310,7 @@ const verify = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
307
310
  const repo = yield* openFor(call.caller, call.repo, true, void 0, "first-read");
308
311
  const writer = yield* ownWriter(call.caller);
309
312
  for (let tries = 0; tries < 5; tries += 1) {
310
- const at = yield* Clock$1.currentTimeMillis;
313
+ const at = yield* Clock.currentTimeMillis;
311
314
  const asked = tries === 0 ? repo : void 0;
312
315
  const read = yield* objectRows(registered, call.caller, repo, [oid], { asked });
313
316
  const rows = read.rows.get(oid);
@@ -350,7 +353,7 @@ const receive = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
350
353
  if (length > parts.uploadMost.bytes) return lfsAnswer(413, { message: pastMost(parts.uploadMost) });
351
354
  const { rows: registered, bucket } = parts;
352
355
  const repo = yield* openFor(call.caller, call.repo, true, void 0, "first-read");
353
- const started = yield* Clock$1.currentTimeMillis;
356
+ const started = yield* Clock.currentTimeMillis;
354
357
  const read = yield* objectRows(registered, call.caller, repo, [oid], { asked: repo });
355
358
  const rows = read.rows.get(oid);
356
359
  const unseen = (yield* unseenRows(call.caller, repo, [oid], read.rows)).has(oid);
@@ -384,8 +387,8 @@ const receive = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
384
387
  });
385
388
  /**
386
389
  * `count` staging keys in `repo`, each row added with upkeep's wake at `removeAt`: bytes put at a
387
- * key that no commit lists by then are deleted, as `endStages` does. A Worker upload's staging and
388
- * an import's copy's, one way (#2397).
390
+ * key that no commit lists by then are deleted, as `endStages` does. A Worker upload's: an import's
391
+ * copy stages a key per object, as `LfsCopy.stage` says.
389
392
  */
390
393
  const stagedKeys = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, removeAt, count) {
391
394
  const staging = Array.from({ length: count }, () => {
@@ -440,10 +443,7 @@ const shortSize = (size, sent) => gitError("INVALID_ARGUMENT", `The bytes end at
440
443
  * An answer to a request whose body isn't needed: the body is let go first, and a cancel that
441
444
  * rejects is no reason to fail an upload that's done.
442
445
  */
443
- const answered = (request) => Effect.promise(async () => {
444
- await request.body?.cancel();
445
- return lfsAnswer(200, { message: "Already uploaded" });
446
- });
446
+ const answered = (request) => Effect.as(dropBody(request.body), lfsAnswer(200, { message: "Already uploaded" }));
447
447
  /**
448
448
  * `body` as it streams to the bucket, gathered into pieces of `uploadPieceBytes` and counted,
449
449
  * failing past `most` bytes, or at its end short of them, before the bucket checks its hash. No
@@ -475,7 +475,7 @@ const counted = (body, most) => {
475
475
  const listStaged = /* @__PURE__ */ Effect.fnUntraced(function* (registered, caller, repo, staged) {
476
476
  const writer = yield* ownWriter(caller);
477
477
  for (let tries = 0; tries < 5; tries += 1) {
478
- const at = yield* Clock$1.currentTimeMillis;
478
+ const at = yield* Clock.currentTimeMillis;
479
479
  const own = writer === void 0 ? [] : [uploadedRow(writer, staged.oid, at)];
480
480
  const read = yield* objectRows(registered, caller, repo, [staged.oid], { also: [stagingRead(staged.staged)] });
481
481
  if (read.rows.get(staged.oid)?.listed !== void 0) {
@@ -487,7 +487,7 @@ const listStaged = /* @__PURE__ */ Effect.fnUntraced(function* (registered, call
487
487
  })).ok) return answer;
488
488
  continue;
489
489
  }
490
- if ((read.also[0] ?? []).length === 0 || (yield* Clock$1.currentTimeMillis) > staged.deadline) return yield* fail("DEADLINE_EXCEEDED", "The upload ran too long", { hint: "Upload it again" });
490
+ if ((read.also[0] ?? []).length === 0 || (yield* Clock.currentTimeMillis) > staged.deadline) return yield* fail("DEADLINE_EXCEEDED", "The upload ran too long", { hint: "Upload it again" });
491
491
  if ((yield* registered.commit(repo.internalId, read.version, {
492
492
  put: [{
493
493
  ...listedKey(staged.oid),
@@ -527,15 +527,85 @@ const objectOf = /* @__PURE__ */ Effect.fnUntraced(function* (parts, read) {
527
527
  },
528
528
  request: read.request
529
529
  });
530
- const stream = yield* bucketStream(parts.bucket, listed.key);
531
- if (stream === void 0) return yield* fail("DATA_LOSS", `LFS object ${oid}'s bytes are missing`);
532
- const bytes = signal === void 0 ? stream : stream.pipeThrough(new TransformStream(), { signal });
530
+ const bytes = yield* Effect.uninterruptible(Effect.map(bucketStream(parts.bucket, listed.key), (stream) => stream === void 0 || signal === void 0 ? stream : bodyUntilAborted(stream, signal)));
531
+ if (bytes === void 0) return yield* fail("DATA_LOSS", `LFS object ${oid}'s bytes are missing`);
533
532
  return {
534
533
  oid,
535
534
  size: listed.size,
536
535
  bytes
537
536
  };
538
537
  });
538
+ /** `objectsOf`'s handle's refusal once its signal is aborted. */
539
+ const handleEnded = fail("FAILED_PRECONDITION", "The read of many LFS objects has ended", { context: { reason: "handle-ended" } });
540
+ /** Fails as `handleEnded` once `signal` is aborted, and waits until then. */
541
+ const endedBy = (signal) => Effect.callback((resume) => {
542
+ const end = () => resume(handleEnded);
543
+ if (signal.aborted) return end();
544
+ signal.addEventListener("abort", end, { once: true });
545
+ return Effect.sync(() => signal.removeEventListener("abort", end));
546
+ });
547
+ /**
548
+ * Many objects at once, for one caller: every read but the bytes' made before it answers, so a
549
+ * caller that must know its reads before it streams, as an archive's 200, knows them. It opens the
550
+ * repo once, lists the objects up the fork chain once, asks the caller's view of every pointer
551
+ * once and the host's fetch rules of each object it lists, each asked once. `readable` is what
552
+ * the caller may read, in the order asked, each once: an object no repo in the chain lists, of
553
+ * another size, unseen in a narrowed view or that a rule answers `NOT_FOUND` for is left out, and
554
+ * a rule's other refusal fails the call. `open` reads one of `readable`'s from the bucket, one call,
555
+ * in the budget the call was made in; it fails `FAILED_PRECONDITION` for an oid outside
556
+ * `readable`, which this call never answered may be read, or once `signal` is aborted, which
557
+ * also interrupts an open waiting for the bucket and cancels an opened stream. 1 to `batchMost`
558
+ * objects.
559
+ */
560
+ const objectsOf = /* @__PURE__ */ Effect.fnUntraced(function* (parts, read) {
561
+ const { caller, signal } = read;
562
+ if (read.objects.length === 0 || read.objects.length > 1e3) return yield* fail("INVALID_ARGUMENT", `A read of many LFS objects names 1 to ${batchMost}`);
563
+ const repo = yield* openFor(caller, read.repo, false, read.internalId, "first-read");
564
+ const asked = read.objects.filter(({ oid, size }) => isLfsOid(oid) && validSize(size));
565
+ const oids = [...new Set(asked.map(({ oid }) => oid))];
566
+ const chained = yield* chainListed(parts.rows, repo, oids);
567
+ const listed = yield* seenListed(caller, repo, oids, chained);
568
+ const readable = /* @__PURE__ */ new Map();
569
+ const checked = /* @__PURE__ */ new Set();
570
+ for (const { oid, size } of asked) {
571
+ const row = listed.get(oid);
572
+ if (row === void 0 || row.size !== size || checked.has(oid)) continue;
573
+ checked.add(oid);
574
+ const target = {
575
+ kind: "lfs",
576
+ oid,
577
+ size: row.size
578
+ };
579
+ const refusal = yield* readRefusal(read.repo, {
580
+ caller,
581
+ target,
582
+ request: read.request
583
+ });
584
+ if (refusal?.code === "NOT_FOUND") continue;
585
+ if (refusal !== void 0) return yield* Effect.fail(refusal);
586
+ readable.set(oid, row);
587
+ }
588
+ const budget = yield* Effect.serviceOption(CallBudget);
589
+ const opened = (oid, row) => Effect.flatMap(Effect.uninterruptible(Effect.map(bucketStream(parts.bucket, row.key), (stream) => stream === void 0 ? void 0 : bodyUntilAborted(stream, signal))), (bytes) => bytes === void 0 ? fail("DATA_LOSS", `LFS object ${oid}'s bytes are missing`) : Effect.succeed({
590
+ oid,
591
+ size: row.size,
592
+ bytes
593
+ }));
594
+ const open = (oid) => Effect.suspend(() => {
595
+ if (signal.aborted) return handleEnded;
596
+ const row = readable.get(oid);
597
+ if (row === void 0) return fail("FAILED_PRECONDITION", `LFS object ${oid} isn't one this read may open`, { context: { reason: "not-readable" } });
598
+ const opening = Option.isSome(budget) ? Effect.provideService(opened(oid, row), CallBudget, budget.value) : opened(oid, row);
599
+ return Effect.raceFirst(opening, endedBy(signal));
600
+ });
601
+ return {
602
+ readable: [...readable].map(([oid, row]) => ({
603
+ oid,
604
+ size: row.size
605
+ })),
606
+ open
607
+ };
608
+ });
539
609
  /**
540
610
  * `GET objects/<oid>`, a Worker download: a listed object's bytes, the repo's own or a source's,
541
611
  * as `objectOf` reads them. Its fetch rules are asked again, though the batch that gave the link
@@ -557,4 +627,4 @@ const send = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
557
627
  }
558
628
  });
559
629
  });
560
- export { batch, listedOf, objectOf, receive, send, stagedKeys, verify };
630
+ export { batch, listedOf, objectOf, objectsOf, receive, send, stagedKeys, verify };
@@ -10,7 +10,7 @@ import { lfsPointerText } from "../protocol/objects/lfs-pointer.mjs";
10
10
  import { lfsOidAt, lfsSizeAt, pointersOfBlob } from "../storage/lfs-pointers.mjs";
11
11
  import { listedOf } from "./objects.mjs";
12
12
  import { uploadedOf } from "./uploaded.mjs";
13
- import * as Clock$1 from "effect/Clock";
13
+ import * as Clock from "effect/Clock";
14
14
  import * as Effect from "effect/Effect";
15
15
  // src/lfs/pointers.ts
16
16
  /**
@@ -117,7 +117,7 @@ const unprovenOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, input, ent
117
117
  const unseen = [...blobs].flatMap(([blob, oid]) => seen.has(blob) ? [] : [oid]);
118
118
  if (unseen.length === 0) return unproven;
119
119
  const writer = yield* ownWriter(input.caller);
120
- const at = yield* Clock$1.currentTimeMillis;
120
+ const at = yield* Clock.currentTimeMillis;
121
121
  const own = writer === void 0 ? /* @__PURE__ */ new Set() : yield* uploadedOf(rows, repo, writer, unseen, at);
122
122
  for (const oid of unseen) if (!own.has(oid)) unproven.add(oid);
123
123
  return unproven;
package/dist/lfs/rows.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { millis } from "../contracts/promises.mjs";
1
+ import { millis } from "../contracts/time.mjs";
2
2
  import * as Schema from "effect/Schema";
3
3
  // src/lfs/rows.ts
4
4
  /**
@@ -13,9 +13,14 @@ const lfsCollections = {
13
13
  objects: "lfs/objects",
14
14
  /** Each LFS object an upload link was given for, by its oid and its uploader, until listed. */
15
15
  uploads: "lfs/uploads",
16
- /** A Worker upload's staging key, by its due `removeAt` and its ID. */
16
+ /** A Worker upload's or an import copy's staging key, by its due `removeAt` and its ID. */
17
17
  staging: "lfs/staging",
18
- /** An LFS object upkeep is deleting, by its oid, which no verify lists. */
18
+ /** Each object an import's copy staged, by its oid, until the copy lists it or upkeep ends it. */
19
+ copies: "lfs/copies",
20
+ /**
21
+ * Bytes upkeep is deleting, which no listing names: a signed upload's, by its oid and
22
+ * generation, or a stage's, by its staging row's ID.
23
+ */
19
24
  ending: "lfs/ending",
20
25
  /** Each LFS lock, by its path's SHA-256. */
21
26
  locks: "lfs/locks",
@@ -62,19 +67,35 @@ const UploadRow = /* @__PURE__ */ Schema.Struct({
62
67
  */
63
68
  generation: Schema.String
64
69
  });
65
- /** A Worker upload's staging key, which upkeep deletes at `removeAt` unless the upload listed it. */
70
+ /**
71
+ * A staging key, which upkeep deletes at `removeAt` unless a listing names it: a Worker upload's,
72
+ * or an import copy's, which names its `oid`.
73
+ */
66
74
  const StagingRow = /* @__PURE__ */ Schema.Struct({
67
75
  key: Schema.String,
76
+ removeAt: Schema.Int,
77
+ oid: Schema.optionalKey(Schema.String)
78
+ });
79
+ /**
80
+ * The key an import's copy of an object put, or will put, its bytes at, its staging row's ID and
81
+ * that row's `removeAt` (#2397): a try after one that died between its put and its commit finds the
82
+ * bytes there and lists them, downloading nothing. Upkeep drops it with its staging row.
83
+ */
84
+ const CopyRow = /* @__PURE__ */ Schema.Struct({
85
+ key: Schema.String,
86
+ staged: Schema.String,
68
87
  removeAt: Schema.Int
69
88
  });
70
89
  /**
71
90
  * How long a Worker upload may stream: past it, its bytes aren't listed, so upkeep, which deletes
72
- * them only at `removeAt`, a day after it started, never deletes bytes a listing names.
91
+ * them only at `removeAt`, a day after it started, never deletes bytes a listing names. An import's
92
+ * copy puts again to a stage's key only while the stage has this long left, so the put, which its
93
+ * try's lease ends far sooner, lands before upkeep may end the stage.
73
94
  */
74
95
  const streamMost = /* @__PURE__ */ millis("12 hours");
75
96
  /**
76
- * An upload whose bytes upkeep is deleting: nothing lists them, since the commit that put the row
77
- * dropped their upload row. Upkeep drops it once the delete of `key` returns.
97
+ * Bytes upkeep is deleting: nothing lists them, since the commit that put the row dropped their
98
+ * upload row or their staging row. Upkeep drops it once the delete of `key` returns.
78
99
  */
79
100
  const EndingRow = /* @__PURE__ */ Schema.Struct({ key: Schema.String });
80
101
  const LockRow = /* @__PURE__ */ Schema.Struct({
@@ -89,10 +110,19 @@ const LockRow = /* @__PURE__ */ Schema.Struct({
89
110
  const objectKey = (repo, oid, generation) => `lfs/${repo}/${oid}.${generation}`;
90
111
  /** A Worker upload's bytes as they stream, before they're checked. */
91
112
  const stagingKey = (repo, id) => `lfs/${repo}/staging/${id}`;
113
+ /**
114
+ * An import copy's bytes, at a generation of its own: one per copy row, so a delete of an ended
115
+ * stage's key, however late it lands, never reaches the bytes a later copy put and listed.
116
+ */
117
+ const copyKey = (repo, oid, generation) => `lfs/${repo}/copy/${oid}.${generation}`;
92
118
  const listedKey = (oid) => ({
93
119
  collection: lfsCollections.objects,
94
120
  id: oid
95
121
  });
122
+ const copyRowKey = (oid) => ({
123
+ collection: lfsCollections.copies,
124
+ id: oid
125
+ });
96
126
  /**
97
127
  * Who an upload row is for: `ownWriter`'s SHA-256 of the caller's actor ID, or this for a caller
98
128
  * with none. Each uploader's row has its own generation, so its signed links write a key no other
@@ -130,8 +160,12 @@ const listedRead = (oid) => ({
130
160
  collection: lfsCollections.objects,
131
161
  id: oid
132
162
  });
163
+ const copyRead = (oid) => ({
164
+ collection: lfsCollections.copies,
165
+ id: oid
166
+ });
133
167
  const uploadRead = (oid, uploader) => ({
134
168
  collection: lfsCollections.uploads,
135
169
  id: uploadId(oid, uploader)
136
170
  });
137
- export { EndingRow, ListedRow, LockRow, StagingRow, UploadRow, anonymousUploader, endingKey, largestObject, lfsCollections, linkLife, listedKey, listedRead, lockKey, lockRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadOid, uploadRead, uploadedKept };
171
+ export { CopyRow, EndingRow, ListedRow, LockRow, StagingRow, UploadRow, anonymousUploader, copyKey, copyRead, copyRowKey, endingKey, largestObject, lfsCollections, linkLife, listedKey, listedRead, lockKey, lockRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadOid, uploadRead, uploadedKept };
@@ -1,13 +1,15 @@
1
1
  import { bucketDo } from "../storage/calls.mjs";
2
2
  import { decodeRow } from "../store/errors.mjs";
3
- import { EndingRow, ListedRow, StagingRow, UploadRow, endingKey, lfsCollections, listedRead, objectKey, uploadOid } from "./rows.mjs";
3
+ import { CopyRow, EndingRow, ListedRow, StagingRow, UploadRow, copyRead, copyRowKey, endingKey, lfsCollections, listedRead, objectKey, stagingRead, uploadOid } from "./rows.mjs";
4
4
  import { uploadedSweepOf, uploadedSweepRead } from "./uploaded.mjs";
5
5
  import * as Effect from "effect/Effect";
6
6
  // src/lfs/upkeep.ts
7
7
  /**
8
8
  * LFS's part of a repo's `git.repack`: it deletes the bytes no listing will name. A Worker
9
- * upload's staging key goes at its row's `removeAt`, a day after it began, when its stream has
10
- * long ended. A signed upload's object key goes at its upload row's `removeAt`, a day after its
9
+ * upload's or an import copy's staging key goes at its row's `removeAt`, a day after it began, when
10
+ * its stream has long ended: the commit that drops the row, and an import copy's copy row, puts an
11
+ * ending row naming the key, so the import's next copy of the object stages a key of its own. A
12
+ * signed upload's object key goes at its upload row's `removeAt`, a day after its
11
13
  * last link expired, if the object is still unlisted or listed at another key: the commit that
12
14
  * drops the upload row puts
13
15
  * an ending row naming the key, so verify, which lists only the key its upload row names, never
@@ -60,7 +62,7 @@ const upkeepStep = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
60
62
  ...stage
61
63
  })));
62
64
  const dueStages = stages.filter((stage) => stage.removeAt <= upkeep.at);
63
- if (dueStages.length > 0) return yield* endStages(upkeep, snapshot.version, dueStages);
65
+ if (dueStages.length > 0) return yield* endStages(upkeep, dueStages);
64
66
  const uploads = yield* dueUploads(upkeep);
65
67
  if (uploads.ids.length > 0) return yield* endUploads(upkeep, uploads.ids);
66
68
  const sweep = upkeep.deleted ? void 0 : uploadedSweepOf(uploaded, upkeep.at);
@@ -86,17 +88,48 @@ const endObjects = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, version,
86
88
  })) });
87
89
  return did;
88
90
  });
89
- /** Deletes each due staging key, then its row, at `version`. */
90
- const endStages = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, version, stages) {
91
- yield* Effect.forEach(stages, (stage) => bucketDo(upkeep.bucket.remove(stage.key)), {
92
- concurrency: 8,
93
- discard: true
91
+ /**
92
+ * Drops each due staging row, read again at one version with its object's listed and copy rows,
93
+ * and the copy row that names it, and for a key no listing names, puts an ending row in the same
94
+ * commit, then deletes the key as `endObjects` does. A row a listing dropped since is left alone.
95
+ * So a delete, however late it lands, reaches only a key no row names, and a step of the import
96
+ * that staged before the commit fails its own, at the version this one moved.
97
+ */
98
+ const endStages = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, stages) {
99
+ const snapshot = yield* upkeep.rows.read(upkeep.repo, stages.flatMap(({ id, oid }) => oid === void 0 ? [stagingRead(id)] : [
100
+ stagingRead(id),
101
+ listedRead(oid),
102
+ copyRead(oid)
103
+ ]));
104
+ const found = snapshot.results.map((rows) => rows[0]);
105
+ const dropped = [];
106
+ const ended = [];
107
+ for (const { id, key, oid } of stages) {
108
+ const [staged, listedRow, copyRow] = found.splice(0, oid === void 0 ? 1 : 3);
109
+ if (staged === void 0) continue;
110
+ dropped.push({
111
+ collection: lfsCollections.staging,
112
+ id
113
+ });
114
+ const copy = copyRow === void 0 ? void 0 : yield* copyOf(copyRow);
115
+ if (oid !== void 0 && copy?.staged === id) dropped.push(copyRowKey(oid));
116
+ if ((listedRow === void 0 ? void 0 : yield* listedOf(listedRow))?.key !== key) ended.push({
117
+ collection: lfsCollections.ending,
118
+ id,
119
+ key
120
+ });
121
+ }
122
+ if (dropped.length === 0) return did;
123
+ const committed = yield* upkeep.rows.commit(upkeep.repo, snapshot.version, {
124
+ put: ended.map(({ collection, id, key }) => ({
125
+ collection,
126
+ id,
127
+ value: { key }
128
+ })),
129
+ delete: dropped
94
130
  });
95
- yield* upkeep.rows.commit(upkeep.repo, version, { delete: stages.map((stage) => ({
96
- collection: lfsCollections.staging,
97
- id: stage.id
98
- })) });
99
- return did;
131
+ if (!committed.ok || ended.length === 0) return did;
132
+ return yield* endObjects(upkeep, committed.version, ended);
100
133
  });
101
134
  /** Up to a page of the upload rows that are due, by ID, and when the soonest of the rest is. */
102
135
  const dueUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
@@ -126,6 +159,7 @@ const dueUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
126
159
  });
127
160
  const uploadOf = (row) => decodeRow(UploadRow, row, `LFS object ${row.id}'s upload`);
128
161
  const listedOf = (row) => decodeRow(ListedRow, row, `LFS object ${row.id}`);
162
+ const copyOf = (row) => decodeRow(CopyRow, row, `LFS copy ${row.id}`);
129
163
  /**
130
164
  * Drops each due upload row, by its ID, read again at one version. On a signed bucket, an object
131
165
  * still unlisted, or listed at another key, as another uploader's bytes are, gets its ending row in
package/dist/lfs/wire.mjs CHANGED
@@ -1,17 +1,16 @@
1
- import { fail, httpStatus } from "../contracts/result.mjs";
1
+ import { fail } from "../contracts/result.mjs";
2
2
  import { decodeJson } from "../protocol/wire/json.mjs";
3
3
  import { boundedBytes } from "../protocol/bytes/reader.mjs";
4
4
  import { brokenRead, endedEarly, readBody } from "../store/errors.mjs";
5
+ import { lfsResponse } from "./answer.mjs";
5
6
  import * as Effect from "effect/Effect";
6
7
  import * as Schema from "effect/Schema";
7
8
  import * as Result from "effect/Result";
8
9
  // src/lfs/wire.ts
9
10
  /**
10
- * Git LFS's wire: its JSON bodies, as the batch and locking APIs name them, and its answers. A
11
- * refusal is LFS's `{ message }`, and a 401 asks for Basic credentials as `LFS-Authenticate`, so
12
- * the client asks Git's credential helper for the same ones a push sends.
11
+ * Git LFS's wire: its JSON bodies, as the batch and locking APIs name them, and its answers with
12
+ * them. A refusal's is `answer.ts`'s.
13
13
  */
14
- const lfsType = "application/vnd.git-lfs+json";
15
14
  /** The most a JSON body may hold: a batch of 1,000 objects is about 100 KiB. */
16
15
  const bodyMost = 1048576;
17
16
  /** The most objects one batch names: git-lfs sends 100 at a time. */
@@ -73,7 +72,6 @@ const LfsLock = /* @__PURE__ */ Schema.Struct({
73
72
  locked_at: Schema.String,
74
73
  owner: Schema.Struct({ name: Schema.String })
75
74
  });
76
- const noStore = { "cache-control": "no-store" };
77
75
  /**
78
76
  * The bodies LFS's JSON answers carry: a batch's, a lock's, a page of locks, a verify's page split
79
77
  * into the caller's and others', or a refusal's `{ message }`. A union encodes as its first member
@@ -103,30 +101,7 @@ const LfsBody = /* @__PURE__ */ Schema.Union([
103
101
  ]);
104
102
  const lfsJson = /* @__PURE__ */ Schema.encodeSync(Schema.fromJsonString(LfsBody));
105
103
  /** A JSON answer of LFS's. */
106
- const lfsAnswer = (status, body, headers) => {
107
- const answer = new Headers(headers);
108
- answer.set("content-type", lfsType);
109
- answer.set("cache-control", noStore["cache-control"]);
110
- return new Response(lfsJson(body), {
111
- status,
112
- headers: answer
113
- });
114
- };
115
- /**
116
- * A refusal as LFS answers one. An anonymous caller is asked for Basic credentials; a repo a
117
- * caller can't read is a 404, as a missing one is, and so is a write's refusal for a caller
118
- * that can't read the repo, which the caller of `lfsRefusal` arranges. A body LFS can't take is
119
- * its validation error, 422, but one that ended early is a 400, as Git's is.
120
- */
121
- const lfsRefusal = (error) => {
122
- if (error.code === "UNAUTHENTICATED") return lfsAnswer(401, { message: error.message }, { "lfs-authenticate": "Basic realm=\"Git LFS\"" });
123
- if (error.code === "NOT_FOUND") return lfsAnswer(404, { message: error.message });
124
- const status = error.code === "INVALID_ARGUMENT" && error.context?.reason === "body-ended" ? httpStatus[error.code] : lfsStatus[error.code] ?? httpStatus[error.code];
125
- const retry = error.code === "UNAVAILABLE" ? { "retry-after": "1" } : void 0;
126
- return lfsAnswer(status, { message: error.message }, retry);
127
- };
128
- /** Where LFS's status differs from Git's: a body it can't take is its validation error. */
129
- const lfsStatus = { INVALID_ARGUMENT: 422 };
104
+ const lfsAnswer = (status, body, headers) => lfsResponse(status, lfsJson(body), headers);
130
105
  const unreadable = (why) => fail("INVALID_ARGUMENT", `The body is unreadable: ${why}`);
131
106
  /**
132
107
  * `request`'s body, read whole up to 1 MiB, then decoded as `schema`'s JSON. A read that breaks
@@ -141,4 +116,4 @@ const bodyOf = /* @__PURE__ */ Effect.fnUntraced(function* (request, schema) {
141
116
  onSuccess: (value) => Effect.succeed(value)
142
117
  });
143
118
  });
144
- export { BatchRequest, LfsAction, LfsBody, LfsLock, LfsObjectAnswer, LockCreate, LockQuery, LockVerify, Unlock, VerifyRequest, batchMost, bodyOf, lfsAnswer, lfsRefusal, lfsType };
119
+ export { BatchRequest, LfsAction, LfsBody, LfsLock, LfsObjectAnswer, LockCreate, LockQuery, LockVerify, Unlock, VerifyRequest, batchMost, bodyOf, lfsAnswer };
@@ -2,7 +2,7 @@ import { MergeParts, Merges } from "../core/merge-parts.mjs";
2
2
  import { Objects } from "../core/objects/objects.mjs";
3
3
  import { loadedXdiff, mergeParts } from "../engine/parts.mjs";
4
4
  import { defaultXdiffBudget } from "../engine/xdiff.mjs";
5
- import { objectsFace, scopedReader } from "../storage/calls.mjs";
5
+ import { scopedReader } from "../storage/calls.mjs";
6
6
  import * as Effect from "effect/Effect";
7
7
  import * as Context from "effect/Context";
8
8
  import * as Layer from "effect/Layer";
@@ -19,7 +19,7 @@ const mergesContext = /* @__PURE__ */ Effect.fnUntraced(function* (options, obje
19
19
  view,
20
20
  at
21
21
  });
22
- const reader = yield* scopedReader(objectsFace(read), at.listed);
22
+ const reader = yield* scopedReader(read, at.listed);
23
23
  const allot = Effect.succeed((most, refusal) => reader.allotment(most, refusal));
24
24
  return yield* parts.mergeTrees((object) => reader.read(object), input, allot);
25
25
  }));
package/dist/node.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { toNodeHandler, toNodeMiddleware } from "./server/edge-node.mjs";
2
- import { NodeHandler, NodeMiddleware, NodeNext, NodeRequest, NodeResponse } from "./http/node.mjs";
3
- export { type NodeHandler, type NodeMiddleware, type NodeNext, type NodeRequest, type NodeResponse, toNodeHandler, toNodeMiddleware };
2
+ import { NodeHandler, NodeMiddleware, NodeNext, NodeRequest, NodeResponse, NodeServeOptions } from "./http/node.mjs";
3
+ export { type NodeHandler, type NodeMiddleware, type NodeNext, type NodeRequest, type NodeResponse, type NodeServeOptions, toNodeHandler, toNodeMiddleware };
@@ -49,15 +49,23 @@ var BufferError = class extends Schema.TaggedError()("BufferError", {
49
49
  message: Schema.String
50
50
  }) {};
51
51
  /**
52
- * An allotment that fails by name past the meter's ceiling, made each time it runs: one built and
53
- * never run allots nothing, and one run twice allots twice.
52
+ * `bytes` allotted to `part` at once: nothing when they fit, or the error naming the ceiling they'd
53
+ * pass, with nothing allotted.
54
54
  */
55
- const allotOrFail = (meter, part, bytes) => Effect.suspend(() => meter.allot(part, bytes) ? Effect.void : Effect.fail(new BufferError({
55
+ const allotNow = (meter, part, bytes) => meter.allot(part, bytes) ? void 0 : new BufferError({
56
56
  part,
57
57
  bytes,
58
58
  ceiling: meter.ceiling,
59
59
  message: `${part} would retain ${bytes} bytes past ${meter.ceiling}`
60
- })));
60
+ });
61
+ /**
62
+ * An allotment that fails by name past the meter's ceiling, made each time it runs: one built and
63
+ * never run allots nothing, and one run twice allots twice.
64
+ */
65
+ const allotOrFail = (meter, part, bytes) => Effect.suspend(() => {
66
+ const refused = allotNow(meter, part, bytes);
67
+ return refused === void 0 ? Effect.void : Effect.fail(refused);
68
+ });
61
69
  /**
62
70
  * `bytes` allotted to `part` until the scope closes, failing by name past the meter's ceiling: each
63
71
  * run allots when it runs and lets go when its own scope closes.
@@ -65,4 +73,4 @@ const allotOrFail = (meter, part, bytes) => Effect.suspend(() => meter.allot(par
65
73
  const allotScoped = (meter, part, bytes) => Effect.acquireRelease(allotOrFail(meter, part, bytes), () => Effect.sync(() => meter.free(part)));
66
74
  /** The capacity a view keeps alive: its whole buffer's. */
67
75
  const capacityOf = (bytes) => bytes.buffer.byteLength;
68
- export { BufferError, BufferMeter, allotOrFail, allotScoped, capacityOf };
76
+ export { BufferError, BufferMeter, allotNow, allotOrFail, allotScoped, capacityOf };
@@ -12,6 +12,11 @@ const scopedReader = (body) => Effect.acquireRelease(Effect.sync(() => body.getR
12
12
  reader.releaseLock();
13
13
  }));
14
14
  /**
15
+ * `body` cancelled, unread, its cancel's own failure dropped: a body no one will read, let go so
16
+ * its sender stops. A `null` or `undefined` body has nothing to let go.
17
+ */
18
+ const dropBody = (body) => body === null || body === void 0 ? Effect.void : Effect.promise(() => body.cancel().catch(() => void 0));
19
+ /**
15
20
  * A whole body within `most` bytes, or undefined past it. Chunks are checked before they are
16
21
  * retained. The caller owns the byte bound and the errors; this scope owns the reader on every
17
22
  * exit, including a failure between reads. Without an explicit empty-chunk policy, a run of
@@ -58,4 +63,4 @@ const ownedReader = (body) => {
58
63
  }
59
64
  };
60
65
  };
61
- export { boundedBytes, ownedReader, scopedReader };
66
+ export { boundedBytes, dropBody, ownedReader, scopedReader };
@@ -23,6 +23,32 @@ const streamOf = (bytes, piece = Math.max(1, bytes.length)) => {
23
23
  } });
24
24
  };
25
25
  /**
26
+ * `bytes` as a body read once, in one piece, `done` run once it's read to its end, cancelled, or
27
+ * ended unread by `expired`, which fails it with the signal's reason: what holds the bytes, such as
28
+ * a charge to a budget, is let go only then. No piece is pulled before a reader asks, since a pull
29
+ * on its own would end it unread.
30
+ */
31
+ const streamThen = (bytes, done, expired) => {
32
+ let ended = false;
33
+ const end = () => {
34
+ if (ended) return false;
35
+ ended = true;
36
+ done();
37
+ return true;
38
+ };
39
+ return new ReadableStream({
40
+ start: (controller) => {
41
+ expired?.addEventListener("abort", () => end() && controller.error(expired.reason), { once: true });
42
+ },
43
+ pull: (controller) => {
44
+ controller.enqueue(bytes);
45
+ controller.close();
46
+ end();
47
+ },
48
+ cancel: () => void end()
49
+ }, { highWaterMark: 0 });
50
+ };
51
+ /**
26
52
  * `body` gathered into pieces, each `pieceAt(given)` bytes, `given` the bytes it has handed on,
27
53
  * its last smaller, each copied from its chunks as they come, so code that pays for each chunk pays
28
54
  * once a piece: a client's body reaches a deployed Worker in chunks of at most 4,096 B (run
@@ -100,4 +126,4 @@ const gathered = (body, pieceAt) => {
100
126
  }
101
127
  }, { highWaterMark: 0 });
102
128
  };
103
- export { gathered, streamOf };
129
+ export { gathered, streamOf, streamThen };
@@ -33,13 +33,14 @@ export interface DiffLimits {
33
33
  */
34
34
  export declare const defaultDiffLimits: DiffLimits;
35
35
  declare const DiffError_base: Schema.Class<DiffError, Schema.TaggedStruct<"DiffError", {
36
- readonly reason: Schema.Literals<readonly ["missing", "malformed", "unreadable", "diff-limit", "object-too-large"]>;
36
+ readonly reason: Schema.Literals<readonly ["missing", "past-roots", "malformed", "unreadable", "diff-limit", "object-too-large"]>;
37
37
  readonly oid: Schema.optionalKey<Schema.String>;
38
38
  readonly message: Schema.String;
39
39
  }>, import("effect/Cause").YieldableError>;
40
40
  /**
41
- * Why a diff stopped: an object `missing`, `malformed` or `unreadable`, a read or a charge past
42
- * the diff's limits, `diff-limit`, or one object past its own, `object-too-large`.
41
+ * Why a diff stopped: an object `missing`, or `past-roots`, missing from a repo that holds roots,
42
+ * so it may be history past them; `malformed` or `unreadable`; a read or a charge past the diff's
43
+ * limits, `diff-limit`; or one object past its own, `object-too-large`.
43
44
  */
44
45
  export declare class DiffError extends DiffError_base {}
45
46
  /**
@@ -22,12 +22,14 @@ const defaultDiffLimits = {
22
22
  fileBytes: 16 * mebibyte
23
23
  };
24
24
  /**
25
- * Why a diff stopped: an object `missing`, `malformed` or `unreadable`, a read or a charge past
26
- * the diff's limits, `diff-limit`, or one object past its own, `object-too-large`.
25
+ * Why a diff stopped: an object `missing`, or `past-roots`, missing from a repo that holds roots,
26
+ * so it may be history past them; `malformed` or `unreadable`; a read or a charge past the diff's
27
+ * limits, `diff-limit`; or one object past its own, `object-too-large`.
27
28
  */
28
29
  var DiffError = class extends Schema.TaggedError()("DiffError", {
29
30
  reason: Schema.Literals([
30
31
  "missing",
32
+ "past-roots",
31
33
  "malformed",
32
34
  "unreadable",
33
35
  "diff-limit",
@@ -177,7 +179,10 @@ var DiffReader = class {
177
179
  if (this.#objects > this.limits.objects) return yield* failed("diff-limit", `the diff reads past ${this.limits.objects} objects`);
178
180
  if (this.tally?.object() === false) return yield* failed("diff-limit", `the call reads past ${this.tally.limits.objects} objects`);
179
181
  const object = yield* this.read(oid);
180
- if (object === void 0) return yield* failed("missing", `object ${oid} is missing`, oid);
182
+ if (object === void 0) {
183
+ const reason = this.roots.size === 0 ? "missing" : "past-roots";
184
+ return yield* failed(reason, `object ${oid} is missing`, oid);
185
+ }
181
186
  this.#sizes.set(oid, object.size);
182
187
  if (type !== void 0 && object.type !== type) {
183
188
  object.bytes.cancel().catch(() => void 0);