@ref0/git 0.0.0 → 0.2.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 (503) hide show
  1. package/dist/LICENSE +202 -0
  2. package/dist/access/private-refs.d.mts +27 -0
  3. package/dist/access/private-refs.mjs +173 -0
  4. package/dist/access.d.mts +2 -0
  5. package/dist/access.mjs +1 -0
  6. package/dist/auth/access-jwt.d.mts +21 -0
  7. package/dist/auth/access-jwt.mjs +102 -0
  8. package/dist/auth/acting.mjs +15 -0
  9. package/dist/auth/authorize.d.mts +5 -0
  10. package/dist/auth/authorize.mjs +292 -0
  11. package/dist/auth/credentials.mjs +57 -0
  12. package/dist/auth/fences.d.mts +5 -0
  13. package/dist/auth/fences.mjs +65 -0
  14. package/dist/auth/grants.mjs +61 -0
  15. package/dist/auth/helpers.d.mts +17 -0
  16. package/dist/auth/helpers.mjs +25 -0
  17. package/dist/auth/host-function.d.mts +4 -0
  18. package/dist/auth/host-function.mjs +69 -0
  19. package/dist/auth/identify.d.mts +6 -0
  20. package/dist/auth/identify.mjs +97 -0
  21. package/dist/auth/token-rows.mjs +100 -0
  22. package/dist/auth/token-text.mjs +66 -0
  23. package/dist/auth/tokens.d.mts +10 -0
  24. package/dist/auth/tokens.mjs +347 -0
  25. package/dist/auth.d.mts +7 -0
  26. package/dist/auth.mjs +6 -0
  27. package/dist/client/answer.mjs +141 -0
  28. package/dist/client/client.d.mts +23 -0
  29. package/dist/client/client.mjs +51 -0
  30. package/dist/client/git-http.mjs +201 -0
  31. package/dist/client/helper-node.mjs +19 -0
  32. package/dist/client/local.mjs +160 -0
  33. package/dist/client/negotiate.mjs +170 -0
  34. package/dist/client/push-upload.mjs +53 -0
  35. package/dist/client/remote-helper.mjs +129 -0
  36. package/dist/client/remote.mjs +398 -0
  37. package/dist/client/run-remote-helper.d.mts +35 -0
  38. package/dist/client/run-remote-helper.mjs +259 -0
  39. package/dist/client/scrub.d.mts +18 -0
  40. package/dist/client/scrub.mjs +38 -0
  41. package/dist/client/transport.d.mts +2 -0
  42. package/dist/client/transport.mjs +211 -0
  43. package/dist/contracts/access.d.mts +87 -0
  44. package/dist/contracts/actors.d.mts +144 -0
  45. package/dist/contracts/blobs.d.mts +38 -0
  46. package/dist/contracts/calls-spent.d.mts +11 -0
  47. package/dist/contracts/calls-spent.mjs +150 -0
  48. package/dist/contracts/client.d.mts +90 -0
  49. package/dist/contracts/commits.d.mts +126 -0
  50. package/dist/contracts/engine.d.mts +134 -0
  51. package/dist/contracts/events.d.mts +276 -0
  52. package/dist/contracts/files.d.mts +75 -0
  53. package/dist/contracts/forks.d.mts +78 -0
  54. package/dist/contracts/grants.d.mts +60 -0
  55. package/dist/contracts/handlers.d.mts +10 -0
  56. package/dist/contracts/ids.d.mts +15 -0
  57. package/dist/contracts/ids.mjs +15 -0
  58. package/dist/contracts/lfs.d.mts +27 -0
  59. package/dist/contracts/merges.d.mts +33 -0
  60. package/dist/contracts/objects.d.mts +645 -0
  61. package/dist/contracts/objects.mjs +54 -0
  62. package/dist/contracts/operations.d.mts +133 -0
  63. package/dist/contracts/promises.d.mts +63 -0
  64. package/dist/contracts/push-uploads.d.mts +44 -0
  65. package/dist/contracts/queue.d.mts +401 -0
  66. package/dist/contracts/refs.d.mts +95 -0
  67. package/dist/contracts/remote.d.mts +50 -0
  68. package/dist/contracts/repos.d.mts +153 -0
  69. package/dist/contracts/result.d.mts +126 -0
  70. package/dist/contracts/result.mjs +34 -0
  71. package/dist/contracts/rules.d.mts +159 -0
  72. package/dist/contracts/server.d.mts +245 -0
  73. package/dist/contracts/services.d.mts +36 -0
  74. package/dist/contracts/services.mjs +13 -0
  75. package/dist/contracts/signin.d.mts +126 -0
  76. package/dist/contracts/store.d.mts +41 -0
  77. package/dist/contracts/sync.d.mts +210 -0
  78. package/dist/contracts/sync.mjs +8 -0
  79. package/dist/contracts/tags.d.mts +50 -0
  80. package/dist/contracts/tags.mjs +6 -0
  81. package/dist/contracts/tokens.d.mts +87 -0
  82. package/dist/contracts/tokens.mjs +15 -0
  83. package/dist/contracts/topics.d.mts +174 -0
  84. package/dist/contracts/trees.d.mts +84 -0
  85. package/dist/contracts/work.d.mts +31 -0
  86. package/dist/core/access.d.mts +22 -0
  87. package/dist/core/access.mjs +262 -0
  88. package/dist/core/ancestry.mjs +235 -0
  89. package/dist/core/clock.mjs +18 -0
  90. package/dist/core/events/deliver.mjs +468 -0
  91. package/dist/core/events/stream.d.mts +19 -0
  92. package/dist/core/events/stream.mjs +290 -0
  93. package/dist/core/forks.mjs +1027 -0
  94. package/dist/core/hooks/post-receive.mjs +204 -0
  95. package/dist/core/hooks/pre-receive.d.mts +5 -0
  96. package/dist/core/hooks/pre-receive.mjs +34 -0
  97. package/dist/core/index-job.mjs +198 -0
  98. package/dist/core/names.mjs +30 -0
  99. package/dist/core/objects/blobs.mjs +60 -0
  100. package/dist/core/objects/commit-writes.mjs +185 -0
  101. package/dist/core/objects/commits.mjs +172 -0
  102. package/dist/core/objects/files.mjs +211 -0
  103. package/dist/core/objects/lines.mjs +42 -0
  104. package/dist/core/objects/merges.mjs +83 -0
  105. package/dist/core/objects/peel.mjs +166 -0
  106. package/dist/core/objects/reading.mjs +284 -0
  107. package/dist/core/objects/tags.mjs +96 -0
  108. package/dist/core/objects/tree-edits.mjs +266 -0
  109. package/dist/core/objects/trees.mjs +229 -0
  110. package/dist/core/objects/writing.mjs +266 -0
  111. package/dist/core/own-writes.mjs +94 -0
  112. package/dist/core/promise.mjs +46 -0
  113. package/dist/core/publish.mjs +142 -0
  114. package/dist/core/push-decide.mjs +206 -0
  115. package/dist/core/push.mjs +1069 -0
  116. package/dist/core/receipts.d.mts +7 -0
  117. package/dist/core/receipts.mjs +234 -0
  118. package/dist/core/ref-conflicts.mjs +27 -0
  119. package/dist/core/refs.mjs +359 -0
  120. package/dist/core/repack.mjs +521 -0
  121. package/dist/core/repos.mjs +752 -0
  122. package/dist/core/rules/changes.mjs +57 -0
  123. package/dist/core/rules/check.mjs +101 -0
  124. package/dist/core/rules/commit-changes.mjs +216 -0
  125. package/dist/core/rules/context.d.mts +9 -0
  126. package/dist/core/rules/context.mjs +120 -0
  127. package/dist/core/rules/define.d.mts +5 -0
  128. package/dist/core/rules/define.mjs +13 -0
  129. package/dist/core/rules/facts.mjs +13 -0
  130. package/dist/core/rules/fetch.d.mts +5 -0
  131. package/dist/core/rules/fetch.mjs +59 -0
  132. package/dist/core/rules/file-globs.mjs +55 -0
  133. package/dist/core/rules/files.mjs +142 -0
  134. package/dist/core/rules/patterns.mjs +23 -0
  135. package/dist/core/rules/protect.d.mts +9 -0
  136. package/dist/core/rules/protect.mjs +116 -0
  137. package/dist/core/seam.d.mts +24 -0
  138. package/dist/core/seam.mjs +41 -0
  139. package/dist/core/sight.mjs +99 -0
  140. package/dist/core/tokens.mjs +95 -0
  141. package/dist/core/view.d.mts +9 -0
  142. package/dist/core/view.mjs +221 -0
  143. package/dist/core/work.mjs +92 -0
  144. package/dist/effect.d.mts +20 -0
  145. package/dist/effect.mjs +18 -0
  146. package/dist/engine/allotted-xdiff.d.mts +4 -0
  147. package/dist/engine/allotted-xdiff.mjs +80 -0
  148. package/dist/engine/attribute-patterns.mjs +163 -0
  149. package/dist/engine/attributes.mjs +226 -0
  150. package/dist/engine/combined.mjs +653 -0
  151. package/dist/engine/commits.mjs +90 -0
  152. package/dist/engine/content.d.mts +4 -0
  153. package/dist/engine/content.mjs +221 -0
  154. package/dist/engine/diff.mjs +49 -0
  155. package/dist/engine/engine.d.mts +25 -0
  156. package/dist/engine/engine.mjs +49 -0
  157. package/dist/engine/failures.d.mts +4 -0
  158. package/dist/engine/failures.mjs +23 -0
  159. package/dist/engine/line-count.mjs +23 -0
  160. package/dist/engine/merge-base-walk.d.mts +2 -0
  161. package/dist/engine/merge-base-walk.mjs +265 -0
  162. package/dist/engine/merge-bases.mjs +27 -0
  163. package/dist/engine/merge-renames.mjs +165 -0
  164. package/dist/engine/merge.mjs +1125 -0
  165. package/dist/engine/parts.d.mts +8 -0
  166. package/dist/engine/parts.mjs +9 -0
  167. package/dist/engine/reads.d.mts +5 -0
  168. package/dist/engine/reads.mjs +105 -0
  169. package/dist/engine/walk.mjs +328 -0
  170. package/dist/engine/xdiff/NOTICE.md +63 -0
  171. package/dist/engine/xdiff/compiled.d.mts +7 -0
  172. package/dist/engine/xdiff/compiled.mjs +9 -0
  173. package/dist/engine/xdiff/embedded.mjs +4 -0
  174. package/dist/engine/xdiff/node.d.mts +7 -0
  175. package/dist/engine/xdiff/node.mjs +10 -0
  176. package/dist/engine/xdiff/upstream/LGPL-2.1 +511 -0
  177. package/dist/engine/xdiff/xdiff.wasm +0 -0
  178. package/dist/engine/xdiff.d.mts +34 -0
  179. package/dist/engine/xdiff.mjs +380 -0
  180. package/dist/engine.d.mts +3 -0
  181. package/dist/engine.mjs +3 -0
  182. package/dist/extend.d.mts +3 -0
  183. package/dist/extend.mjs +1 -0
  184. package/dist/http/answers.mjs +74 -0
  185. package/dist/http/bodies.mjs +143 -0
  186. package/dist/http/core-parts.mjs +252 -0
  187. package/dist/http/fetch-depth.mjs +26 -0
  188. package/dist/http/handler.mjs +94 -0
  189. package/dist/http/node.d.mts +70 -0
  190. package/dist/http/node.mjs +178 -0
  191. package/dist/http/paths.d.mts +9 -0
  192. package/dist/http/paths.mjs +118 -0
  193. package/dist/http/push-uploads.mjs +286 -0
  194. package/dist/http/receive-pack.mjs +235 -0
  195. package/dist/http/upload-pack.mjs +229 -0
  196. package/dist/index.d.mts +46 -0
  197. package/dist/index.mjs +16 -0
  198. package/dist/lfs/calls.mjs +16 -0
  199. package/dist/lfs/locks.mjs +161 -0
  200. package/dist/lfs/objects.mjs +370 -0
  201. package/dist/lfs/pointers.mjs +141 -0
  202. package/dist/lfs/repo.mjs +42 -0
  203. package/dist/lfs/rows.mjs +108 -0
  204. package/dist/lfs/service.mjs +34 -0
  205. package/dist/lfs/upkeep.mjs +162 -0
  206. package/dist/lfs/wire.mjs +102 -0
  207. package/dist/node.d.mts +3 -0
  208. package/dist/node.mjs +3 -0
  209. package/dist/protocol/bytes/buffers.d.mts +38 -0
  210. package/dist/protocol/bytes/buffers.mjs +62 -0
  211. package/dist/protocol/bytes/crc32.d.mts +4 -0
  212. package/dist/protocol/bytes/crc32.mjs +14 -0
  213. package/dist/protocol/bytes/deflate.d.mts +78 -0
  214. package/dist/protocol/bytes/deflate.mjs +175 -0
  215. package/dist/protocol/bytes/errors.d.mts +20 -0
  216. package/dist/protocol/bytes/errors.mjs +19 -0
  217. package/dist/protocol/bytes/hex.mjs +16 -0
  218. package/dist/protocol/bytes/hmac-sha256.mjs +91 -0
  219. package/dist/protocol/bytes/inflate.d.mts +40 -0
  220. package/dist/protocol/bytes/inflate.mjs +109 -0
  221. package/dist/protocol/bytes/joined.d.mts +2 -0
  222. package/dist/protocol/bytes/joined.mjs +25 -0
  223. package/dist/protocol/bytes/sha1-hasher.d.mts +20 -0
  224. package/dist/protocol/bytes/sha1-hasher.mjs +72 -0
  225. package/dist/protocol/bytes/sha1.d.mts +35 -0
  226. package/dist/protocol/bytes/sha1.mjs +409 -0
  227. package/dist/protocol/bytes/sha256.mjs +156 -0
  228. package/dist/protocol/bytes/streams.mjs +11 -0
  229. package/dist/protocol/bytes/text.mjs +19 -0
  230. package/dist/protocol/diff/diff-raw.d.mts +29 -0
  231. package/dist/protocol/diff/diff-raw.mjs +73 -0
  232. package/dist/protocol/diff/patch.mjs +92 -0
  233. package/dist/protocol/diff/paths.mjs +67 -0
  234. package/dist/protocol/diff/read.d.mts +62 -0
  235. package/dist/protocol/diff/read.mjs +342 -0
  236. package/dist/protocol/diff/rename-similarity.mjs +428 -0
  237. package/dist/protocol/diff/text.mjs +12 -0
  238. package/dist/protocol/diff/tree-diff.d.mts +41 -0
  239. package/dist/protocol/diff/tree-diff.mjs +607 -0
  240. package/dist/protocol/framing/band.d.mts +10 -0
  241. package/dist/protocol/framing/band.mjs +16 -0
  242. package/dist/protocol/framing/pkt-line.d.mts +48 -0
  243. package/dist/protocol/framing/pkt-line.mjs +92 -0
  244. package/dist/protocol/objects/checked-blobs.mjs +127 -0
  245. package/dist/protocol/objects/commit.d.mts +25 -0
  246. package/dist/protocol/objects/commit.mjs +138 -0
  247. package/dist/protocol/objects/fsck-gitmodules.mjs +296 -0
  248. package/dist/protocol/objects/fsck-names.mjs +189 -0
  249. package/dist/protocol/objects/fsck.mjs +297 -0
  250. package/dist/protocol/objects/headers.mjs +109 -0
  251. package/dist/protocol/objects/held.mjs +56 -0
  252. package/dist/protocol/objects/iconv.mjs +145 -0
  253. package/dist/protocol/objects/ident.mjs +111 -0
  254. package/dist/protocol/objects/lfs-pointer.d.mts +8 -0
  255. package/dist/protocol/objects/lfs-pointer.mjs +63 -0
  256. package/dist/protocol/objects/links-raw.mjs +89 -0
  257. package/dist/protocol/objects/object-rules.mjs +75 -0
  258. package/dist/protocol/objects/object.d.mts +16 -0
  259. package/dist/protocol/objects/object.mjs +29 -0
  260. package/dist/protocol/objects/tag.d.mts +21 -0
  261. package/dist/protocol/objects/tag.mjs +96 -0
  262. package/dist/protocol/objects/tree.d.mts +43 -0
  263. package/dist/protocol/objects/tree.mjs +162 -0
  264. package/dist/protocol/objects/utf8-verify.mjs +71 -0
  265. package/dist/protocol/packs/delta.d.mts +57 -0
  266. package/dist/protocol/packs/delta.mjs +229 -0
  267. package/dist/protocol/packs/graph.mjs +78 -0
  268. package/dist/protocol/packs/idx.d.mts +54 -0
  269. package/dist/protocol/packs/idx.mjs +274 -0
  270. package/dist/protocol/packs/indexer.d.mts +167 -0
  271. package/dist/protocol/packs/indexer.mjs +507 -0
  272. package/dist/protocol/packs/parts.d.mts +40 -0
  273. package/dist/protocol/packs/parts.mjs +89 -0
  274. package/dist/protocol/packs/pos.mjs +51 -0
  275. package/dist/protocol/packs/reader.d.mts +180 -0
  276. package/dist/protocol/packs/reader.mjs +414 -0
  277. package/dist/protocol/packs/rev.d.mts +32 -0
  278. package/dist/protocol/packs/rev.mjs +99 -0
  279. package/dist/protocol/packs/step.d.mts +10 -0
  280. package/dist/protocol/packs/step.mjs +12 -0
  281. package/dist/protocol/packs/write-error.d.mts +12 -0
  282. package/dist/protocol/packs/write-error.mjs +27 -0
  283. package/dist/protocol/packs/writer.d.mts +157 -0
  284. package/dist/protocol/packs/writer.mjs +353 -0
  285. package/dist/protocol/wire/advertisement.d.mts +72 -0
  286. package/dist/protocol/wire/advertisement.mjs +161 -0
  287. package/dist/protocol/wire/fetch.d.mts +155 -0
  288. package/dist/protocol/wire/fetch.mjs +458 -0
  289. package/dist/protocol/wire/lines.mjs +107 -0
  290. package/dist/protocol/wire/push-uploads.mjs +43 -0
  291. package/dist/protocol/wire/receive-pack.d.mts +71 -0
  292. package/dist/protocol/wire/receive-pack.mjs +157 -0
  293. package/dist/protocol/wire/report-status.d.mts +47 -0
  294. package/dist/protocol/wire/report-status.mjs +119 -0
  295. package/dist/protocol/wire/v2.d.mts +90 -0
  296. package/dist/protocol/wire/v2.mjs +185 -0
  297. package/dist/protocol.d.mts +31 -0
  298. package/dist/protocol.mjs +31 -0
  299. package/dist/queue/advance.mjs +1036 -0
  300. package/dist/queue/callers.mjs +134 -0
  301. package/dist/queue/calls.mjs +1154 -0
  302. package/dist/queue/commit.mjs +85 -0
  303. package/dist/queue/host.d.mts +15 -0
  304. package/dist/queue/host.mjs +88 -0
  305. package/dist/queue/ids.d.mts +5 -0
  306. package/dist/queue/ids.mjs +21 -0
  307. package/dist/queue/lanes.mjs +86 -0
  308. package/dist/queue/limits.mjs +99 -0
  309. package/dist/queue/pages.mjs +76 -0
  310. package/dist/queue/push-option.mjs +62 -0
  311. package/dist/queue/rows.mjs +206 -0
  312. package/dist/queue/schedule.mjs +132 -0
  313. package/dist/queue/search.mjs +315 -0
  314. package/dist/queue/state.mjs +325 -0
  315. package/dist/queue/steps.mjs +317 -0
  316. package/dist/remote-helper.d.mts +3 -0
  317. package/dist/remote-helper.mjs +3 -0
  318. package/dist/rest/api.d.mts +23 -0
  319. package/dist/rest/api.mjs +27 -0
  320. package/dist/rest/blobs.d.mts +58 -0
  321. package/dist/rest/blobs.mjs +41 -0
  322. package/dist/rest/caller.d.mts +102 -0
  323. package/dist/rest/caller.mjs +18 -0
  324. package/dist/rest/client.d.mts +18 -0
  325. package/dist/rest/client.mjs +587 -0
  326. package/dist/rest/commits.d.mts +435 -0
  327. package/dist/rest/commits.mjs +140 -0
  328. package/dist/rest/errors.d.mts +44 -0
  329. package/dist/rest/errors.mjs +186 -0
  330. package/dist/rest/events.d.mts +38 -0
  331. package/dist/rest/events.mjs +74 -0
  332. package/dist/rest/files.d.mts +179 -0
  333. package/dist/rest/files.mjs +92 -0
  334. package/dist/rest/forks.d.mts +205 -0
  335. package/dist/rest/forks.mjs +51 -0
  336. package/dist/rest/handler.d.mts +17 -0
  337. package/dist/rest/handler.mjs +106 -0
  338. package/dist/rest/handlers.d.mts +8 -0
  339. package/dist/rest/handlers.mjs +592 -0
  340. package/dist/rest/listen.d.mts +24 -0
  341. package/dist/rest/listen.mjs +142 -0
  342. package/dist/rest/me.d.mts +55 -0
  343. package/dist/rest/me.mjs +21 -0
  344. package/dist/rest/merges.d.mts +90 -0
  345. package/dist/rest/merges.mjs +39 -0
  346. package/dist/rest/paths.mjs +86 -0
  347. package/dist/rest/queue.d.mts +486 -0
  348. package/dist/rest/queue.mjs +228 -0
  349. package/dist/rest/refs.d.mts +232 -0
  350. package/dist/rest/refs.mjs +86 -0
  351. package/dist/rest/repos.d.mts +223 -0
  352. package/dist/rest/repos.mjs +93 -0
  353. package/dist/rest/tags.d.mts +153 -0
  354. package/dist/rest/tags.mjs +72 -0
  355. package/dist/rest/tokens.d.mts +297 -0
  356. package/dist/rest/tokens.mjs +88 -0
  357. package/dist/rest/topics.d.mts +257 -0
  358. package/dist/rest/topics.mjs +116 -0
  359. package/dist/rest/trees.d.mts +158 -0
  360. package/dist/rest/trees.mjs +118 -0
  361. package/dist/rest/wire.mjs +57 -0
  362. package/dist/rest/work.d.mts +107 -0
  363. package/dist/rest/work.mjs +77 -0
  364. package/dist/rest.d.mts +8 -0
  365. package/dist/rest.mjs +5 -0
  366. package/dist/server/extension.d.mts +14 -0
  367. package/dist/server/extension.mjs +85 -0
  368. package/dist/server/routes.d.mts +25 -0
  369. package/dist/server/routes.mjs +67 -0
  370. package/dist/server/server.d.mts +2 -0
  371. package/dist/server/server.mjs +439 -0
  372. package/dist/signin/codes.mjs +47 -0
  373. package/dist/signin/context.d.mts +9 -0
  374. package/dist/signin/context.mjs +121 -0
  375. package/dist/signin/device.mjs +122 -0
  376. package/dist/signin/forms.mjs +157 -0
  377. package/dist/signin/grants.d.mts +5 -0
  378. package/dist/signin/grants.mjs +257 -0
  379. package/dist/signin/route.mjs +68 -0
  380. package/dist/signin/web.mjs +125 -0
  381. package/dist/signin/wire.d.mts +42 -0
  382. package/dist/signin/wire.mjs +43 -0
  383. package/dist/storage/allotted.mjs +102 -0
  384. package/dist/storage/budget.mjs +96 -0
  385. package/dist/storage/calls.d.mts +18 -0
  386. package/dist/storage/calls.mjs +273 -0
  387. package/dist/storage/clean-up.mjs +124 -0
  388. package/dist/storage/distinct-ids.mjs +39 -0
  389. package/dist/storage/ewah.mjs +97 -0
  390. package/dist/storage/fetch.d.mts +13 -0
  391. package/dist/storage/fetch.mjs +792 -0
  392. package/dist/storage/fsck.mjs +77 -0
  393. package/dist/storage/held-memo.mjs +188 -0
  394. package/dist/storage/index-bitmaps.d.mts +4 -0
  395. package/dist/storage/index-bitmaps.mjs +654 -0
  396. package/dist/storage/index-build.d.mts +15 -0
  397. package/dist/storage/index-build.mjs +1433 -0
  398. package/dist/storage/index-fetch.d.mts +9 -0
  399. package/dist/storage/index-fetch.mjs +756 -0
  400. package/dist/storage/index-files.mjs +232 -0
  401. package/dist/storage/index-graph.d.mts +3 -0
  402. package/dist/storage/index-graph.mjs +1049 -0
  403. package/dist/storage/index-layers.mjs +317 -0
  404. package/dist/storage/index-reach.mjs +216 -0
  405. package/dist/storage/index-remap.d.mts +8 -0
  406. package/dist/storage/index-remap.mjs +592 -0
  407. package/dist/storage/layout.mjs +69 -0
  408. package/dist/storage/lfs-pointers.d.mts +21 -0
  409. package/dist/storage/lfs-pointers.mjs +175 -0
  410. package/dist/storage/link-join.mjs +106 -0
  411. package/dist/storage/links.mjs +105 -0
  412. package/dist/storage/loose.d.mts +15 -0
  413. package/dist/storage/loose.mjs +120 -0
  414. package/dist/storage/memory-budget.d.mts +8 -0
  415. package/dist/storage/memory-budget.mjs +546 -0
  416. package/dist/storage/merge.mjs +416 -0
  417. package/dist/storage/object-rows.d.mts +6 -0
  418. package/dist/storage/object-rows.mjs +211 -0
  419. package/dist/storage/pack-order.d.mts +8 -0
  420. package/dist/storage/pack-order.mjs +779 -0
  421. package/dist/storage/pack-ranges.d.mts +5 -0
  422. package/dist/storage/pack-ranges.mjs +284 -0
  423. package/dist/storage/pack-reads.d.mts +11 -0
  424. package/dist/storage/pack-reads.mjs +990 -0
  425. package/dist/storage/pack-receive.d.mts +11 -0
  426. package/dist/storage/pack-receive.mjs +449 -0
  427. package/dist/storage/packs.d.mts +56 -0
  428. package/dist/storage/packs.mjs +600 -0
  429. package/dist/storage/prune.mjs +506 -0
  430. package/dist/storage/push-allotment.mjs +109 -0
  431. package/dist/storage/push-uploads.mjs +151 -0
  432. package/dist/storage/pushed-commits.mjs +136 -0
  433. package/dist/storage/quarantine.mjs +98 -0
  434. package/dist/storage/raw-ids.mjs +44 -0
  435. package/dist/storage/ready.d.mts +19 -0
  436. package/dist/storage/ready.mjs +328 -0
  437. package/dist/storage/receive-links.mjs +297 -0
  438. package/dist/storage/repack-job.mjs +48 -0
  439. package/dist/storage/repack.d.mts +31 -0
  440. package/dist/storage/repack.mjs +182 -0
  441. package/dist/storage/roots.mjs +42 -0
  442. package/dist/storage/rows.d.mts +3 -0
  443. package/dist/storage/rows.mjs +71 -0
  444. package/dist/storage/shallow.d.mts +5 -0
  445. package/dist/storage/shallow.mjs +128 -0
  446. package/dist/storage/stream-whole.mjs +236 -0
  447. package/dist/storage/unpack.mjs +236 -0
  448. package/dist/storage/visible.mjs +137 -0
  449. package/dist/storage/walk.d.mts +7 -0
  450. package/dist/storage/walk.mjs +170 -0
  451. package/dist/storage/wants.mjs +362 -0
  452. package/dist/store/call-count.d.mts +47 -0
  453. package/dist/store/call-count.mjs +207 -0
  454. package/dist/store/catalogue.d.mts +7 -0
  455. package/dist/store/catalogue.mjs +643 -0
  456. package/dist/store/crossing.mjs +66 -0
  457. package/dist/store/cursor-seal.d.mts +2 -0
  458. package/dist/store/cursor-seal.mjs +85 -0
  459. package/dist/store/errors.d.mts +12 -0
  460. package/dist/store/errors.mjs +129 -0
  461. package/dist/store/git-store.mjs +75 -0
  462. package/dist/store/list-job.mjs +35 -0
  463. package/dist/store/outbox.d.mts +7 -0
  464. package/dist/store/outbox.mjs +295 -0
  465. package/dist/store/queue-jobs.mjs +43 -0
  466. package/dist/store/random.mjs +28 -0
  467. package/dist/store/records.d.mts +4 -0
  468. package/dist/store/records.mjs +192 -0
  469. package/dist/store/ref-rows.d.mts +4 -0
  470. package/dist/store/ref-rows.mjs +30 -0
  471. package/dist/store/repo-record.mjs +100 -0
  472. package/dist/store/reservations.mjs +82 -0
  473. package/dist/store/scopes.mjs +170 -0
  474. package/dist/store/settle.mjs +63 -0
  475. package/dist/store/topic-jobs.mjs +62 -0
  476. package/dist/sync/bound.d.mts +7 -0
  477. package/dist/sync/bound.mjs +29 -0
  478. package/dist/sync/github.d.mts +12 -0
  479. package/dist/sync/github.mjs +297 -0
  480. package/dist/sync/import.d.mts +8 -0
  481. package/dist/sync/import.mjs +154 -0
  482. package/dist/sync/jobs.d.mts +9 -0
  483. package/dist/sync/jobs.mjs +80 -0
  484. package/dist/sync/mirror.d.mts +9 -0
  485. package/dist/sync/mirror.mjs +227 -0
  486. package/dist/sync/publish.d.mts +5 -0
  487. package/dist/sync/publish.mjs +117 -0
  488. package/dist/sync/records.mjs +73 -0
  489. package/dist/sync/smart-http.d.mts +8 -0
  490. package/dist/sync/smart-http.mjs +23 -0
  491. package/dist/sync/step.mjs +334 -0
  492. package/dist/sync/tries.mjs +126 -0
  493. package/dist/sync.d.mts +8 -0
  494. package/dist/sync.mjs +8 -0
  495. package/dist/topics/advance.mjs +554 -0
  496. package/dist/topics/calls.mjs +346 -0
  497. package/dist/topics/directory.mjs +107 -0
  498. package/dist/topics/host.d.mts +11 -0
  499. package/dist/topics/host.mjs +71 -0
  500. package/dist/topics/members.mjs +177 -0
  501. package/dist/topics/rows.mjs +99 -0
  502. package/dist/topics/topic.mjs +126 -0
  503. package/package.json +86 -5
@@ -0,0 +1,990 @@
1
+ import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
2
+ import { hexOf } from "../protocol/bytes/hex.mjs";
3
+ import { Sha1 } from "../protocol/bytes/sha1.mjs";
4
+ import { sha1Now } from "../protocol/bytes/sha1-hasher.mjs";
5
+ import { objectHeader, objectId } from "../protocol/objects/object.mjs";
6
+ import { DeltaError, deltaResultSize } from "../protocol/packs/delta.mjs";
7
+ import { readPackIndex } from "../protocol/packs/idx.mjs";
8
+ import { readPackReverse } from "../protocol/packs/rev.mjs";
9
+ import { IndexerCache, PackIndexer, fixedRoom, readEntryAt } from "../protocol/packs/indexer.mjs";
10
+ import { stepEffect } from "../protocol/packs/step.mjs";
11
+ import { PackError, packReadBytes, readEntryHeader, readPackFrom } from "../protocol/packs/reader.mjs";
12
+ import { callScope } from "../store/call-count.mjs";
13
+ import { forkIn, noCall, runIn } from "../store/crossing.mjs";
14
+ import { gitError } from "../store/errors.mjs";
15
+ import { decodePacks } from "../store/git-store.mjs";
16
+ import { collections, repoScope } from "../store/scopes.mjs";
17
+ import { bucketCall } from "./calls.mjs";
18
+ import { isPackId, objectCollections, packFiles } from "./layout.mjs";
19
+ import { eachHeldRow, gitObjectOf, rowHeaders, rowSizes } from "./object-rows.mjs";
20
+ import { LeavingRow, decodeHeld } from "./rows.mjs";
21
+ import { allotted, keptOrLeft } from "./allotted.mjs";
22
+ import * as Effect from "effect/Effect";
23
+ import * as Option from "effect/Option";
24
+ import * as Cause from "effect/Cause";
25
+ import * as Hex from "effect/encoding/Hex";
26
+ import * as Fiber from "effect/Fiber";
27
+ // src/storage/pack-reads.ts
28
+ /** The largest object `packs()` reads whole: a file past it is stored and sent as it is. */
29
+ const packObjectBytes = 16777216;
30
+ /**
31
+ * The largest file `packs()` takes, GitHub's limit: a blob sent whole, hashed as it streams and
32
+ * never held, and sent back as it is stored.
33
+ */
34
+ const packFileBytes = 104857600;
35
+ /** How `packs()` resolves an entry, on a receive and on a read. */
36
+ const packIndexerLimits = {
37
+ objectBytes: packObjectBytes,
38
+ deltaBytes: packObjectBytes,
39
+ cacheBytes: 33554432,
40
+ nameBytes: 4 * packObjectBytes,
41
+ chainReads: 64
42
+ };
43
+ /** How large an entry's header may say it is, for reads of headers alone: a file's to `packFileBytes`. */
44
+ const headerLimits = {
45
+ ...packIndexerLimits,
46
+ objectBytes: packFileBytes
47
+ };
48
+ /**
49
+ * What one operation's reads keep of the objects they resolve, across every pack it reads: a
50
+ * fetch of a repo of many packs holds no more than one of few.
51
+ */
52
+ const readCacheBytes = 16777216;
53
+ /** What one read of an entry may hold besides its data: its inflater and buffers. */
54
+ const entryReaderBytes = 1048576;
55
+ /** A stored pack's neighbourhood one bucket read fetches: 1 MiB, aligned. */
56
+ const blockBytes = 1048576;
57
+ /** What a block takes as a cache counts it: its bytes and its entry's overhead. */
58
+ const blockHeld = (bytes) => bytes + 384;
59
+ /**
60
+ * The `leaving` rows a read takes at a time, while it still looks for objects: each is small, so a
61
+ * page stays far below a store's answer limit.
62
+ */
63
+ const leavingPageRows = 1e3;
64
+ const lost = (message) => gitError("DATA_LOSS", message);
65
+ /** The whole of a file, or `undefined` when the bucket has none. */
66
+ const readWhole = (bucket, key, range) => bucketCall(async (signal) => {
67
+ const body = await bucket.read(key, range, { signal });
68
+ return body === void 0 ? void 0 : new Uint8Array(await new Response(body).arrayBuffer());
69
+ });
70
+ /**
71
+ * Blocks kept by key, each counted with `blockHeld`, the least recently used let go first: the one
72
+ * rule `PackBlocks` keeps them by, and its forecast replays.
73
+ */
74
+ var KeptBlocks = class {
75
+ #kept = /* @__PURE__ */ new Map();
76
+ held = 0;
77
+ /** The block at `key`, made the most recent, or `undefined`. */
78
+ get(key) {
79
+ const kept = this.#kept.get(key);
80
+ if (kept === void 0) return void 0;
81
+ this.#kept.delete(key);
82
+ this.#kept.set(key, kept);
83
+ return kept.block;
84
+ }
85
+ /**
86
+ * `block` at `key`, the most recent. One already there, as two reads of one block that both
87
+ * missed leave it, is let go first, so `held` is always the sum of the blocks kept.
88
+ */
89
+ add(key, block, length) {
90
+ const bytes = blockHeld(length);
91
+ const displaced = this.#kept.get(key);
92
+ if (displaced !== void 0) {
93
+ this.#kept.delete(key);
94
+ this.held -= displaced.bytes;
95
+ }
96
+ this.#kept.set(key, {
97
+ block,
98
+ bytes
99
+ });
100
+ this.held += bytes;
101
+ }
102
+ evictTo(bytes) {
103
+ for (const [key, each] of this.#kept) {
104
+ if (this.held <= bytes) break;
105
+ this.#kept.delete(key);
106
+ this.held -= each.bytes;
107
+ }
108
+ }
109
+ };
110
+ /** A block's key, by its pack and the offset it starts at. */
111
+ const blockKey = (pack, start) => `${pack.id}@${start}`;
112
+ /** The length of the block at `start`: `blockBytes`, or less at the pack's end. */
113
+ const blockLength = (pack, start) => Math.min(blockBytes, pack.bytes - start);
114
+ /**
115
+ * A stored pack's bytes, a neighbourhood at a time: each read of `blockBytes` from the bucket
116
+ * kept for the operation, so an entry and the bases near it cost one read. Missing or short bytes
117
+ * are `DATA_LOSS`.
118
+ */
119
+ var PackBlocks = class {
120
+ #bucket;
121
+ #room;
122
+ #kept = new KeptBlocks();
123
+ /** `room`: what it may keep, each block counted with `blockHeld`. */
124
+ constructor(bucket, room) {
125
+ this.#bucket = bucket;
126
+ this.#room = room;
127
+ room.watch((bytes) => this.#kept.evictTo(bytes));
128
+ }
129
+ block = (pack, start) => Effect.gen({ self: this }, function* () {
130
+ const key = blockKey(pack, start);
131
+ const kept = this.#kept.get(key);
132
+ if (kept !== void 0) return kept;
133
+ const length = blockLength(pack, start);
134
+ const bytes = yield* readWhole(this.#bucket, packFiles(pack.id).pack, {
135
+ offset: start,
136
+ length
137
+ });
138
+ if (bytes?.byteLength !== length) return yield* Effect.fail(lost(`Pack ${pack.id} is missing its bytes from ${start}`));
139
+ this.#kept.add(key, bytes, length);
140
+ const over = this.#kept.held - this.#room.bytes;
141
+ if (over <= 0 || this.#room.grow(over)) return bytes;
142
+ this.#kept.evictTo(this.#room.bytes);
143
+ return bytes;
144
+ });
145
+ /**
146
+ * The bucket gets reading each of `entries`' bytes in turn would take, with no I/O: their blocks
147
+ * replayed through `KeptBlocks`, in a room left at its floor, which a shrink may leave it at any
148
+ * time and no grow is sure to pass. Blocks this reader keeps now aren't counted as kept.
149
+ */
150
+ gets(entries) {
151
+ const kept = new KeptBlocks();
152
+ const floor = this.#room.floor;
153
+ let gets = 0;
154
+ for (const { pack, offset, bytes } of entries) for (let start = offset - offset % blockBytes; start < offset + bytes; start += blockBytes) {
155
+ const key = blockKey(pack, start);
156
+ if (kept.get(key) !== void 0) continue;
157
+ gets += 1;
158
+ kept.add(key, true, blockLength(pack, start));
159
+ if (kept.held > floor) kept.evictTo(floor);
160
+ }
161
+ return gets;
162
+ }
163
+ /** The pack's bytes from `offset` on, a reader's piece at a time. */
164
+ sourceAt(pack, offset) {
165
+ let next = offset;
166
+ return { read: Effect.gen({ self: this }, function* () {
167
+ if (next >= pack.bytes) return void 0;
168
+ const start = next - next % blockBytes;
169
+ const block = yield* this.block(pack, start);
170
+ const from = next - start;
171
+ const piece = block.subarray(from, Math.min(block.byteLength, from + packReadBytes));
172
+ next += piece.byteLength;
173
+ return piece;
174
+ }) };
175
+ }
176
+ /** Up to `headerBytesMost` bytes of the pack from `offset`, across a neighbourhood's end. */
177
+ headAt = (pack, offset) => Effect.gen({ self: this }, function* () {
178
+ const length = Math.min(64, pack.bytes - offset);
179
+ const head = new Uint8Array(length);
180
+ for (let at = 0; at < length;) {
181
+ const start = offset + at - (offset + at) % blockBytes;
182
+ const piece = (yield* this.block(pack, start)).subarray(offset + at - start, offset + length - start);
183
+ head.set(piece, at);
184
+ at += piece.byteLength;
185
+ }
186
+ return head;
187
+ });
188
+ /**
189
+ * The entry at `offset`, read whole, `before` run on its header before its data is held; a
190
+ * stored pack that won't read is `DATA_LOSS`.
191
+ */
192
+ entryAt = (pack, offset, before) => readEntryAt(this.sourceAt(pack, offset), offset, packIndexerLimits, new BufferMeter(entryReaderBytes), before).pipe(Effect.mapError((error) => error instanceof PackError || error instanceof BufferError ? lost(`Pack ${pack.id} is unreadable at ${offset}: ${error.message}`) : error));
193
+ };
194
+ /**
195
+ * The `.idx` and `.rev` of each pack a server has read, across every repo, by the pack's ID: a
196
+ * pack's files never change, so one is checked once, its trailer against the index's and the
197
+ * reverse index against both, and kept until the cache is full.
198
+ */
199
+ var PackIndexes = class {
200
+ #kept = /* @__PURE__ */ new Map();
201
+ #room;
202
+ #held = 0;
203
+ /**
204
+ * `room`: what it keeps of the `.idx` and `.rev` it reads, across every repo, each pack's
205
+ * counted with `cacheEntryBytes`. A room of 0 that never grows keeps none.
206
+ */
207
+ constructor(room) {
208
+ this.#room = room;
209
+ room.watch((bytes) => this.#evictTo(bytes));
210
+ }
211
+ load = (bucket, listed) => Effect.gen({ self: this }, function* () {
212
+ const { id } = listed;
213
+ if (!isPackId(id)) return yield* Effect.fail(lost(`The pack row '${id}' doesn't name a pack`));
214
+ const pack = {
215
+ id,
216
+ bytes: listed.bytes
217
+ };
218
+ const kept = this.#kept.get(id);
219
+ if (kept !== void 0) {
220
+ this.#kept.delete(id);
221
+ this.#kept.set(id, kept);
222
+ return {
223
+ pack,
224
+ index: kept.index,
225
+ reverse: kept.reverse
226
+ };
227
+ }
228
+ const files = packFiles(id);
229
+ const bytes = yield* readWhole(bucket, files.idx);
230
+ if (bytes === void 0) return yield* Effect.fail(lost(`Pack ${id} has no index`));
231
+ const index = yield* readPackIndex(bytes).pipe(Effect.mapError((error) => lost(`Pack ${id}'s index is unreadable: ${error.message}`)));
232
+ if (index.count !== listed.objects) return yield* Effect.fail(lost(`Pack ${id}'s index lists ${index.count} objects; its row, ${listed.objects}`));
233
+ const trailer = yield* readWhole(bucket, files.pack, {
234
+ offset: listed.bytes - 20,
235
+ length: 20
236
+ });
237
+ if (trailer === void 0 || Hex.encode(trailer) !== index.packChecksum) return yield* Effect.fail(lost(`Pack ${id}'s bytes aren't those its index lists`));
238
+ const reversed = yield* readWhole(bucket, files.rev);
239
+ if (reversed === void 0) return yield* Effect.fail(lost(`Pack ${id} has no reverse index`));
240
+ const reverse = yield* readPackReverse(reversed, index).pipe(Effect.mapError((error) => lost(`Pack ${id}'s reverse index is unreadable: ${error.message}`)));
241
+ const held = 384 + bytes.byteLength + reversed.byteLength;
242
+ this.#remember(id, {
243
+ index,
244
+ reverse,
245
+ bytes: held
246
+ });
247
+ return {
248
+ pack,
249
+ index,
250
+ reverse
251
+ };
252
+ });
253
+ /**
254
+ * `kept` at `id`, the most recent. One already there, as two loads of one pack that both missed
255
+ * leave it, is let go first, so `#held` is always the sum of the indexes kept: a second load
256
+ * costs its reads, never a charge that outlives its entry.
257
+ */
258
+ #remember(id, kept) {
259
+ const displaced = this.#kept.get(id);
260
+ if (displaced !== void 0) {
261
+ this.#kept.delete(id);
262
+ this.#held -= displaced.bytes;
263
+ }
264
+ this.#kept.set(id, kept);
265
+ this.#held += kept.bytes;
266
+ const over = this.#held - this.#room.bytes;
267
+ if (over > 0 && !this.#room.grow(over)) this.#evictTo(this.#room.bytes);
268
+ }
269
+ #evictTo(bytes) {
270
+ for (const [each, kept] of this.#kept) {
271
+ if (this.#held <= bytes) break;
272
+ this.#kept.delete(each);
273
+ this.#held -= kept.bytes;
274
+ }
275
+ }
276
+ };
277
+ /**
278
+ * Where the entry at `offset` ends: the next entry's offset, by the pack's `.rev`, or the trailer's
279
+ * for its last; `undefined` when no entry starts there.
280
+ */
281
+ const entryEnd = (indexed, offset) => {
282
+ const { index, reverse, pack } = indexed;
283
+ const offsetOf = (at) => index.offsetAt(reverse.rankAt(at));
284
+ let low = 0;
285
+ let high = reverse.count;
286
+ while (low < high) {
287
+ const middle = low + high >>> 1;
288
+ const at = offsetOf(middle);
289
+ if (at === offset) return middle + 1 < reverse.count ? offsetOf(middle + 1) : pack.bytes - 20;
290
+ if (at < offset) low = middle + 1;
291
+ else high = middle;
292
+ }
293
+ };
294
+ const delta = (base) => ({
295
+ kind: "delta",
296
+ base
297
+ });
298
+ /** Each pack's entries in the order of their offsets, so its neighbourhoods are read once. */
299
+ const byPlace = (where) => [...where].sort(([, a], [, b]) => a.indexed.pack.id === b.indexed.pack.id ? a.offset - b.offset : a.indexed.pack.id < b.indexed.pack.id ? -1 : 1);
300
+ /** The most bytes an object may hold for its hash check to run at once, not as a promise. */
301
+ const hashedNowMost = 65536;
302
+ /** The most bytes `objects` checks at once in a row, about 1 MiB, before it yields the thread. */
303
+ const hashedRunMost = 1048576;
304
+ /**
305
+ * A turn of the event loop, a macrotask, so the isolate's other requests, whose I/O comes back as
306
+ * macrotasks, run before this one goes on. `Effect.yieldNow`, and `Effect.sleep(0)`, which is it,
307
+ * let only other fibers run, and `Effect.sleep(1)` would wait a millisecond for each.
308
+ */
309
+ const aTurn = Effect.promise(() => new Promise((resolve) => {
310
+ setTimeout(resolve, 0);
311
+ }));
312
+ /** Why an entry that didn't resolve holds no object to check. */
313
+ const unresolvedEntry = (pack, oid, resolved) => resolved.why === "too big" ? gitError("RESOURCE_EXHAUSTED", `Object ${oid} is past the ${packObjectBytes} bytes this server reads whole`, { context: { reason: "object-too-large" } }) : lost(`Object ${oid} in pack ${pack.id} won't resolve: ${resolved.why}`);
314
+ /**
315
+ * `bytes`, copied out of what resolved them, checked against `oid` at once by `sha1Now`: the
316
+ * object, or why it isn't the one the index lists.
317
+ */
318
+ const checkedNow = (pack, oid, type, bytes) => {
319
+ const hashed = hexOf(sha1Now([objectHeader(type, bytes.byteLength), bytes]));
320
+ if (hashed !== oid) return lost(`Object ${oid} in pack ${pack.id} hashes to ${hashed}`);
321
+ return {
322
+ oid,
323
+ type,
324
+ bytes
325
+ };
326
+ };
327
+ /**
328
+ * An object resolved from a stored pack, hashed again against the ID its index lists: at once
329
+ * below `hashedNowMost`, through `objectId` from it up.
330
+ */
331
+ const checkedObject = Effect.fnUntraced(function* (pack, oid, resolved) {
332
+ if (resolved.kind !== "resolved") return yield* Effect.fail(unresolvedEntry(pack, oid, resolved));
333
+ const { kind: type } = resolved.object;
334
+ const bytes = new Uint8Array(resolved.object.bytes);
335
+ if (bytes.byteLength < 65536) {
336
+ const checked = checkedNow(pack, oid, type, bytes);
337
+ return "code" in checked ? yield* Effect.fail(checked) : checked;
338
+ }
339
+ const hashed = yield* objectId({
340
+ type,
341
+ bytes
342
+ });
343
+ if (hashed !== oid) return yield* Effect.fail(lost(`Object ${oid} in pack ${pack.id} hashes to ${hashed}`));
344
+ return {
345
+ oid,
346
+ type,
347
+ bytes
348
+ };
349
+ });
350
+ /**
351
+ * Objects of stored packs, each resolved whole from its offset and hashed again against its ID:
352
+ * one indexer for each pack, and one cache for them all. An indexer holds the pack's index only
353
+ * while a resolve of it runs, so it keeps no `.idx` past its read: a reader keeps its listed
354
+ * packs' indexes itself, and a pack it doesn't list is each read's alone.
355
+ */
356
+ const packObjects = (blocks, room, outside) => {
357
+ const indexers = /* @__PURE__ */ new Map();
358
+ const cache = new IndexerCache(room);
359
+ const indexingOf = (indexed) => {
360
+ const kept = indexers.get(indexed.pack.id);
361
+ if (kept !== void 0) return kept;
362
+ const { pack } = indexed;
363
+ const made = {
364
+ using: void 0,
365
+ resolving: 0,
366
+ indexer: new PackIndexer({
367
+ entryAt: (offset, before) => blocks.entryAt(pack, offset, before),
368
+ offsetOf: (oid) => made.using?.index.find(oid)?.offset,
369
+ ...outside && { allot: outside }
370
+ }, packIndexerLimits, cache)
371
+ };
372
+ indexers.set(pack.id, made);
373
+ return made;
374
+ };
375
+ /** `indexed`'s index lent to its indexer while `resolve` runs, and dropped when the last ends. */
376
+ const lent = (indexing, indexed, resolve) => Effect.acquireUseRelease(Effect.sync(() => {
377
+ indexing.using = indexed;
378
+ indexing.resolving += 1;
379
+ }), () => resolve, () => Effect.sync(() => {
380
+ indexing.resolving -= 1;
381
+ if (indexing.resolving === 0) indexing.using = void 0;
382
+ }));
383
+ /** What the entry at `offset` resolves to, reading its chain as it needs. */
384
+ const resolving = (oid, indexed, offset) => {
385
+ const indexing = indexingOf(indexed);
386
+ return lent(indexing, indexed, stepEffect(indexing.indexer.resolve(offset))).pipe(Effect.catchIf((error) => error instanceof DeltaError, (error) => Effect.fail(lost(`Object ${oid} in pack ${indexed.pack.id} won't resolve: ${error.message}`))));
387
+ };
388
+ const at = Effect.fnUntraced(function* (oid, indexed, offset) {
389
+ return yield* checkedObject(indexed.pack, oid, yield* resolving(oid, indexed, offset));
390
+ });
391
+ /**
392
+ * What the entry at `offset` resolves to at once, from its pack's indexer's cache, with nothing
393
+ * read; `undefined` when `resolving` must read it.
394
+ */
395
+ const recalled = (indexed, offset) => indexingOf(indexed).indexer.recalled(offset);
396
+ /** Lets go of the cache and each pack's indexer. */
397
+ const clear = () => {
398
+ indexers.clear();
399
+ cache.clear();
400
+ };
401
+ return Object.assign(at, {
402
+ clear,
403
+ recalled,
404
+ resolving
405
+ });
406
+ };
407
+ /**
408
+ * A whole entry's object as a stream, which reads nothing until its first pull: then its pack's
409
+ * neighbourhoods, through `blocks`, are inflated a piece at a time and each piece handed on once
410
+ * the reader asks, hashed as it goes. The last piece waits for the hash, so a mismatch, or an
411
+ * entry that won't read, errors the stream with `DATA_LOSS` before its last byte, and a REST body
412
+ * ends short of its `content-length`. A cancel, or `signal`, interrupts the read, which frees its
413
+ * inflater. It holds the blocks kept, the inflater and two pieces of `packReadBytes`.
414
+ */
415
+ const entryStream = (blocks, at, signal, count) => {
416
+ let controller;
417
+ let fiber;
418
+ let pulled;
419
+ let wake;
420
+ let done = false;
421
+ const demand = Effect.callback((resume) => {
422
+ if (pulled !== void 0) return resume(Effect.void);
423
+ wake = () => resume(Effect.void);
424
+ return Effect.sync(() => {
425
+ wake = void 0;
426
+ });
427
+ });
428
+ const hand = (bytes) => Effect.gen(function* () {
429
+ yield* demand;
430
+ const answer = pulled;
431
+ pulled = void 0;
432
+ if (!done) controller?.enqueue(bytes);
433
+ answer?.();
434
+ });
435
+ const read = Effect.gen(function* () {
436
+ const sha = new Sha1();
437
+ sha.update(objectHeader(at.type, at.size));
438
+ let last;
439
+ yield* readPackFrom(blocks.sourceAt(at.pack, at.offset), {
440
+ write: () => Effect.void,
441
+ digest: Effect.succeed(/* @__PURE__ */ new Uint8Array(20))
442
+ }, {
443
+ begin: () => Effect.void,
444
+ entry: () => Effect.void,
445
+ data: (bytes) => Effect.gen(function* () {
446
+ sha.update(bytes);
447
+ if (last !== void 0) yield* hand(last);
448
+ last = bytes.slice();
449
+ }),
450
+ entryEnd: () => Effect.succeed("pause")
451
+ }, headerLimits, new BufferMeter(entryReaderBytes), {
452
+ version: 2,
453
+ count: 2,
454
+ index: 0,
455
+ offset: at.offset
456
+ }).pipe(Effect.mapError((error) => "code" in error ? error : lost(`Pack ${at.pack.id} is unreadable at ${at.offset}: ${error.message}`)));
457
+ const hashed = Hex.encode(sha.digest());
458
+ if (hashed !== at.oid) return yield* Effect.fail(lost(`Object ${at.oid} in pack ${at.pack.id} hashes to ${hashed}`));
459
+ if (last !== void 0) yield* hand(last);
460
+ });
461
+ /** Ends the stream once, erring it with `erred`, and the fiber reading it. */
462
+ const stop = (erred) => {
463
+ if (done) return;
464
+ done = true;
465
+ pulled?.();
466
+ erred();
467
+ if (fiber !== void 0) forkIn(Fiber.interrupt(fiber), noCall);
468
+ };
469
+ const aborted = () => stop(() => controller?.error(signal?.reason));
470
+ const start = () => {
471
+ if (signal?.aborted === true) return aborted();
472
+ signal?.addEventListener("abort", aborted, { once: true });
473
+ fiber = forkIn(read.pipe(Effect.tap(() => Effect.sync(() => {
474
+ if (!done) controller?.close();
475
+ done = true;
476
+ })), Effect.tapCause((cause) => Effect.sync(() => stop(() => controller?.error(Cause.squash(cause))))), Effect.ensuring(Effect.sync(() => signal?.removeEventListener("abort", aborted)))), count);
477
+ };
478
+ return new ReadableStream({
479
+ start: (each) => {
480
+ controller = each;
481
+ if (signal?.aborted === true) aborted();
482
+ },
483
+ pull: () => new Promise((resolve) => {
484
+ if (done) return resolve();
485
+ pulled = resolve;
486
+ if (fiber === void 0) start();
487
+ const waking = wake;
488
+ wake = void 0;
489
+ waking?.();
490
+ }),
491
+ cancel: async () => {
492
+ done = true;
493
+ pulled?.();
494
+ if (fiber !== void 0) await runIn(Fiber.interrupt(fiber), noCall);
495
+ }
496
+ }, { highWaterMark: 0 });
497
+ };
498
+ /**
499
+ * A reader's memory outside any budget: the read cache and every block it may keep, fixed. For
500
+ * maintenance, whose Durable Object runs one step at a time in its own isolate.
501
+ */
502
+ const fixedReaderMemory = () => ({
503
+ cache: fixedRoom(readCacheBytes),
504
+ blocks: fixedRoom(8 * blockHeld(blockBytes)),
505
+ index: () => Effect.void,
506
+ outside: () => void 0
507
+ });
508
+ /**
509
+ * What a pack's `.idx` and `.rev` take, by its objects, as an index read holds them: the `.idx`'s
510
+ * header, fan-out and trailer, its ID, CRC and offset for each object, and a large offset for each
511
+ * past 2 GiB; the `.rev`'s header, trailer and a position for each; and their entry's overhead.
512
+ */
513
+ const indexBytes = (pack) => {
514
+ const n = pack.objects;
515
+ const large = pack.bytes > 2 ** 31 ? 8 * n : 0;
516
+ return 1072 + 28 * n + large + 52 + 4 * n + 384;
517
+ };
518
+ /**
519
+ * One operation's reads of a repo's objects under `packs()`: its rows first, a small push's,
520
+ * then each pack its list names, by the pack's `.idx`. An object is resolved from the pack's
521
+ * neighbourhoods the operation keeps, each delta's base from the same pack, and hashed again
522
+ * against its ID.
523
+ */
524
+ const packReader = (input) => {
525
+ const { store, bucket, indexes, listed, memory } = input;
526
+ const blocks = new PackBlocks(bucket, memory.blocks);
527
+ const { listedOnly } = input;
528
+ const rows = listedOnly === true ? () => Effect.void : eachHeldRow(store, listed);
529
+ const rowsSized = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowSizes(store, listed);
530
+ const rowsHeaders = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowHeaders(store, listed);
531
+ const wholeAt = packObjects(blocks, memory.cache, memory.outside);
532
+ const named = new Set(listed.packs.map((pack) => pack.id));
533
+ const kept = /* @__PURE__ */ new Map();
534
+ const charged = /* @__PURE__ */ new Set();
535
+ const unnamed = (pack) => !named.has(pack.id);
536
+ /** The packs the repo lists now that `listed` didn't, such as a merge's that folded rows. */
537
+ const listedSince = Effect.fnUntraced(function* () {
538
+ const snapshot = yield* store.read({
539
+ scope: repoScope(listed.repo),
540
+ reads: [{ collection: collections.packs }]
541
+ });
542
+ return (yield* decodePacks(snapshot.results[0] ?? [])).filter(unnamed);
543
+ });
544
+ /**
545
+ * A page of the packs the repo's delete let go of, after `after`: a merge that folded rows this
546
+ * read finds gone listed their objects in its own pack, and the delete may have moved that to
547
+ * `leaving`, where its bytes stay until this read's time is up. A step's `leaving` pack is never
548
+ * read: what only it holds, a pass dropped, and a push that found it there would name an object
549
+ * soon gone.
550
+ */
551
+ const leavingPage = Effect.fnUntraced(function* (after) {
552
+ const page = after === void 0 ? {} : { after };
553
+ const rows = (yield* store.read({
554
+ scope: repoScope(listed.repo),
555
+ reads: [{
556
+ collection: objectCollections.leaving,
557
+ limit: leavingPageRows,
558
+ ...page
559
+ }]
560
+ })).results[0] ?? [];
561
+ return {
562
+ packs: (yield* Effect.forEach(rows, (row) => decodeHeld(LeavingRow, row))).filter(({ value }) => value.deleted === true).map(({ pack, value }) => ({
563
+ id: pack,
564
+ objects: value.objects,
565
+ bytes: value.bytes
566
+ })).filter(unnamed),
567
+ next: rows.length < leavingPageRows ? void 0 : rows.at(-1)?.id
568
+ };
569
+ });
570
+ /**
571
+ * Where each of `oids` is in the listed packs, by the first pack that lists it, then in those
572
+ * listed since, then in those the repo's delete let go of, a page at a time, for any not found:
573
+ * each read apart, so neither collection's rows count against the other's answer. Each listed
574
+ * pack's indexes it loads are kept by the pack's ID, in `loaded` when the caller gives one and in
575
+ * the reader's own `kept` otherwise, and read before the server's cache: a reader loads a listed
576
+ * pack's indexes once, however small that cache is. Either holds only what was loaded, each
577
+ * `IndexedPack` until the reader is released or the caller drops its map, outside the index
578
+ * cache: at most every listed pack's `.idx` and `.rev` at once. Each pack's are charged to the
579
+ * reader's allotment before its first load, and stay charged until the allotment ends.
580
+ * A pack `listed` doesn't name, listed since or leaving, is this call's alone, through the
581
+ * server's cache, so a reader holds no more than its listing names.
582
+ */
583
+ const found = Effect.fnUntraced(function* (oids, loaded = kept, listedAlone = false) {
584
+ const where = /* @__PURE__ */ new Map();
585
+ let left = [...new Set(oids)];
586
+ const look = Effect.fnUntraced(function* (packs, held, going = false) {
587
+ for (const listedPack of packs) {
588
+ if (left.length === 0) break;
589
+ const known = held.get(listedPack.id);
590
+ if (known === void 0 && !charged.has(listedPack.id)) {
591
+ yield* memory.index(indexBytes(listedPack));
592
+ charged.add(listedPack.id);
593
+ }
594
+ const indexed = known === void 0 ? yield* indexes.load(bucket, listedPack).pipe(Effect.asSome, Effect.catch((error) => going && error.code === "DATA_LOSS" ? Effect.succeedNone : Effect.fail(error))) : Option.some(known);
595
+ if (Option.isNone(indexed)) continue;
596
+ held.set(listedPack.id, indexed.value);
597
+ left = left.filter((oid) => {
598
+ const object = indexed.value.index.find(oid);
599
+ if (object === void 0) return true;
600
+ where.set(oid, {
601
+ indexed: indexed.value,
602
+ offset: object.offset,
603
+ crc32: object.crc32
604
+ });
605
+ return false;
606
+ });
607
+ }
608
+ });
609
+ yield* look(listed.packs, loaded);
610
+ if (left.length === 0 || listedOnly === true || listedAlone) return where;
611
+ const unlisted = /* @__PURE__ */ new Map();
612
+ yield* look(yield* listedSince(), unlisted);
613
+ let after;
614
+ do {
615
+ if (left.length === 0) break;
616
+ const page = yield* leavingPage(after);
617
+ yield* look(page.packs, unlisted, true);
618
+ after = page.next;
619
+ } while (after !== void 0);
620
+ return where;
621
+ });
622
+ /**
623
+ * Where each of `oids` is, in one order for single reads and batches alike: the listed packs
624
+ * first, by their `.idx`, which reads no record; then the rows of those no listed pack holds,
625
+ * each handed to `row`; then, for what neither holds, the packs listed since and those leaving,
626
+ * as a merge that folded the rows after this read's listing leaves them.
627
+ */
628
+ const located = Effect.fnUntraced(function* (oids, row) {
629
+ const where = yield* found(oids, kept, true);
630
+ const unpacked = oids.filter((oid) => !where.has(oid));
631
+ if (unpacked.length === 0) return where;
632
+ const inRows = /* @__PURE__ */ new Set();
633
+ yield* rows(unpacked, (object) => {
634
+ inRows.add(object.oid);
635
+ return row(object);
636
+ });
637
+ const missing = unpacked.filter((oid) => !inRows.has(oid));
638
+ if (missing.length > 0) for (const [oid, place] of yield* found(missing)) where.set(oid, place);
639
+ return where;
640
+ });
641
+ /**
642
+ * Each of `oids` the repo holds, read whole and handed on before the next, found as `located`
643
+ * finds them: the listed packs first, so a walk over a repo whose objects are all packed asks the
644
+ * store for no row (#647), then the rows, then the packs listed since and those leaving.
645
+ */
646
+ const each = Effect.fnUntraced(function* (oids, take) {
647
+ const where = yield* located(oids, take);
648
+ for (const [oid, { indexed, offset }] of where) yield* take(yield* wholeAt(oid, indexed, offset));
649
+ });
650
+ /** Which of `oids` the repo holds, read whole. */
651
+ const held = Effect.fnUntraced(function* (oids) {
652
+ const objects = /* @__PURE__ */ new Map();
653
+ yield* each(oids, (object) => Effect.sync(() => void objects.set(object.oid, object)));
654
+ return objects;
655
+ });
656
+ /**
657
+ * The size of the object an entry holds, from its header, or a delta's from its instructions'
658
+ * header, its base never read; an entry whose header won't say is resolved whole.
659
+ */
660
+ const sizeAt = Effect.fnUntraced(function* (oid, indexed, offset) {
661
+ const head = yield* blocks.headAt(indexed.pack, offset);
662
+ const header = readEntryHeader(head, head.byteLength, offset, headerLimits);
663
+ if (header.kind === "entry" && header.type !== "ofs" && header.type !== "ref") return header.size;
664
+ if (header.kind === "entry") {
665
+ const read = yield* blocks.entryAt(indexed.pack, offset);
666
+ const size = read === "too big" ? void 0 : deltaResultSize(read.data);
667
+ if (size !== void 0) return size;
668
+ }
669
+ return (yield* wholeAt(oid, indexed, offset)).bytes.byteLength;
670
+ });
671
+ /**
672
+ * The size of each of `oids` the repo holds, none held whole past its own read: each pack's in
673
+ * the order of its offsets, so its neighbourhoods are read once.
674
+ */
675
+ const sizes = Effect.fnUntraced(function* (oids) {
676
+ const sized = /* @__PURE__ */ new Map();
677
+ for (const [oid, size] of yield* rowsSized(oids)) sized.set(oid, size);
678
+ const where = byPlace(yield* found(oids.filter((oid) => !sized.has(oid))));
679
+ for (const [oid, { indexed, offset }] of where) sized.set(oid, yield* sizeAt(oid, indexed, offset));
680
+ return sized;
681
+ });
682
+ /**
683
+ * The type an entry holds, by headers alone: its own, or a delta's base's, followed through
684
+ * offset and ID bases to the first entry that isn't a delta, at most `chainReads` entries deep,
685
+ * the deepest a stored pack holds. An ID base is looked for in the delta's own pack first, then
686
+ * in the other packs' indexes, which the reader loads once, and in the rows only when no pack
687
+ * holds it, which ends the chain: at most one store read a chain.
688
+ * `known` keeps each entry's type, by pack and offset, for one `headers` call, so chains that
689
+ * share a base are walked once. `undefined` past the bound, or for a header that won't say or a
690
+ * base the repo doesn't hold.
691
+ */
692
+ const typeAt = Effect.fnUntraced(function* (indexed, offset, known) {
693
+ const walked = [];
694
+ const answer = (type) => {
695
+ if (type === void 0) return type;
696
+ for (const step of walked) {
697
+ const inPack = known.get(step.pack) ?? /* @__PURE__ */ new Map();
698
+ inPack.set(step.offset, type);
699
+ known.set(step.pack, inPack);
700
+ }
701
+ return type;
702
+ };
703
+ let at = {
704
+ indexed,
705
+ offset
706
+ };
707
+ for (let depth = 0; depth < packIndexerLimits.chainReads; depth += 1) {
708
+ const already = known.get(at.indexed.pack.id)?.get(at.offset);
709
+ if (already !== void 0) return answer(already);
710
+ walked.push({
711
+ pack: at.indexed.pack.id,
712
+ offset: at.offset
713
+ });
714
+ const head = yield* blocks.headAt(at.indexed.pack, at.offset);
715
+ const header = readEntryHeader(head, head.byteLength, at.offset, headerLimits);
716
+ if (header.kind !== "entry") return void 0;
717
+ const { type, base } = header;
718
+ if (type !== "ofs" && type !== "ref") return answer(type);
719
+ if (base?.kind === "offset") {
720
+ at = {
721
+ indexed: at.indexed,
722
+ offset: base.offset
723
+ };
724
+ continue;
725
+ }
726
+ if (base?.kind !== "oid") return void 0;
727
+ const here = at.indexed.index.find(base.oid);
728
+ if (here !== void 0) {
729
+ at = {
730
+ indexed: at.indexed,
731
+ offset: here.offset
732
+ };
733
+ continue;
734
+ }
735
+ const where = (yield* found([base.oid])).get(base.oid);
736
+ if (where === void 0) return answer((yield* rowsHeaders([base.oid])).get(base.oid)?.type);
737
+ at = {
738
+ indexed: where.indexed,
739
+ offset: where.offset
740
+ };
741
+ }
742
+ });
743
+ /**
744
+ * The type and size of each of `oids` the repo holds, as `git cat-file --batch-check` gives
745
+ * them, from headers alone: rows first, then each pack's entries in the order of their offsets.
746
+ * A delta's size is its result's and its type its chain's, as `typeAt` follows it. An entry whose
747
+ * header or chain won't say is read whole.
748
+ */
749
+ const headers = Effect.fnUntraced(function* (oids) {
750
+ const answer = new Map(yield* rowsHeaders(oids));
751
+ const where = byPlace(yield* found(oids.filter((oid) => !answer.has(oid))));
752
+ const known = /* @__PURE__ */ new Map();
753
+ for (const [oid, { indexed, offset }] of where) {
754
+ const type = yield* typeAt(indexed, offset, known);
755
+ if (type === void 0) {
756
+ const whole = yield* wholeAt(oid, indexed, offset);
757
+ answer.set(oid, {
758
+ type: whole.type,
759
+ size: whole.bytes.byteLength
760
+ });
761
+ continue;
762
+ }
763
+ answer.set(oid, {
764
+ type,
765
+ size: yield* sizeAt(oid, indexed, offset)
766
+ });
767
+ }
768
+ return answer;
769
+ });
770
+ /**
771
+ * Which of `oids` the repo holds, and where, by its rows and its packs' indexes, none read: the
772
+ * listed pack an index found it in, by ID, or `undefined` for a row. `loaded`, when given, keeps
773
+ * the packs' indexes it loads, as `found` says, for later calls given it too.
774
+ */
775
+ const heldIn = Effect.fnUntraced(function* (oids, loaded) {
776
+ const there = /* @__PURE__ */ new Map();
777
+ for (const oid of (yield* rowsSized(oids)).keys()) there.set(oid, void 0);
778
+ const packed = yield* found(oids.filter((oid) => !there.has(oid)), loaded);
779
+ for (const [oid, { indexed }] of packed) there.set(oid, indexed.pack.id);
780
+ return there;
781
+ });
782
+ /** Which of `oids` the repo holds, as `heldIn` finds them. */
783
+ const has = (oids, loaded) => Effect.map(heldIn(oids, loaded), (there) => new Set(there.keys()));
784
+ /** What the entry at `offset` holds, by its header, or `undefined` for one that won't say. */
785
+ const holdsAt = Effect.fnUntraced(function* (indexed, offset) {
786
+ const head = yield* blocks.headAt(indexed.pack, offset);
787
+ const header = readEntryHeader(head, head.byteLength, offset, headerLimits);
788
+ if (header.kind !== "entry") return void 0;
789
+ const { type, size, base } = header;
790
+ if (type === "ref") return base?.kind === "oid" ? delta(base.oid) : void 0;
791
+ return type === "ofs" ? void 0 : {
792
+ kind: "whole",
793
+ type,
794
+ size
795
+ };
796
+ });
797
+ /**
798
+ * The entry each of `oids` is stored as, to copy as it is: its length by the pack's `.rev`, its
799
+ * CRC-32 by its `.idx`, and what it holds by its header, a whole object or a delta on a base it
800
+ * names by ID. An entry that won't say, or an offset delta, is left out, to be read whole.
801
+ */
802
+ const storedOf = Effect.fnUntraced(function* (oids, loaded) {
803
+ const entries = /* @__PURE__ */ new Map();
804
+ for (const [oid, { indexed, offset, crc32 }] of byPlace(yield* found(oids, loaded))) {
805
+ const { pack } = indexed;
806
+ const end = entryEnd(indexed, offset);
807
+ if (end === void 0 || end <= offset) return yield* Effect.fail(lost(`Pack ${pack.id}'s reverse index has no entry at ${offset}`));
808
+ const holds = yield* holdsAt(indexed, offset);
809
+ if (holds === void 0) continue;
810
+ entries.set(oid, {
811
+ oid,
812
+ pack,
813
+ offset,
814
+ bytes: end - offset,
815
+ crc32,
816
+ holds
817
+ });
818
+ }
819
+ return entries;
820
+ });
821
+ const read = (entry, at) => {
822
+ const from = entry.offset + at;
823
+ const start = from - from % blockBytes;
824
+ return Effect.map(blocks.block(entry.pack, start), (block) => block.subarray(from - start, Math.min(block.byteLength, from - start + entry.bytes - at)));
825
+ };
826
+ const stored = {
827
+ find: storedOf,
828
+ read,
829
+ gets: (entries) => blocks.gets(entries),
830
+ packed: (oids) => Effect.map(found(oids, kept, true), (where) => new Set(where.keys()))
831
+ };
832
+ /**
833
+ * The object `oid` as `ObjectReader.read` hands it on, rows first: a whole entry past
834
+ * `packObjectBytes` streamed, as `entryStream` says, and any other resolved whole.
835
+ */
836
+ const object = Effect.fnUntraced(function* (oid, signal) {
837
+ let row;
838
+ const place = (yield* located([oid], (each) => Effect.sync(() => void (row = each)))).get(oid);
839
+ if (row !== void 0) return gitObjectOf(row);
840
+ if (place === void 0) return void 0;
841
+ const { indexed, offset } = place;
842
+ const holds = yield* holdsAt(indexed, offset);
843
+ if (holds?.kind === "whole" && holds.size > 16777216) {
844
+ const { type, size } = holds;
845
+ const count = yield* callScope;
846
+ const at = {
847
+ oid,
848
+ type,
849
+ size,
850
+ pack: indexed.pack,
851
+ offset
852
+ };
853
+ return {
854
+ oid,
855
+ type,
856
+ size,
857
+ bytes: entryStream(blocks, at, signal, count)
858
+ };
859
+ }
860
+ return gitObjectOf(yield* wholeAt(oid, indexed, offset));
861
+ });
862
+ /**
863
+ * Each of `entries`, packed, charged to `answer` once resolved, then copied out and checked:
864
+ * at once below `hashedNowMost`, `hashedRunMost` bytes so in a row taking a turn.
865
+ */
866
+ const placed = Effect.fnUntraced(function* (answer, entries, run) {
867
+ for (const [oid, { indexed, offset }] of entries) {
868
+ const resolved = wholeAt.recalled(indexed, offset) ?? (yield* wholeAt.resolving(oid, indexed, offset));
869
+ if (resolved.kind !== "resolved") return yield* Effect.fail(unresolvedEntry(indexed.pack, oid, resolved));
870
+ const size = resolved.object.bytes.byteLength;
871
+ let given = answer.granted(size);
872
+ if (Effect.isEffect(given)) {
873
+ given = yield* given;
874
+ run.at = 0;
875
+ }
876
+ if (given === "left") {
877
+ answer.leave(oid);
878
+ continue;
879
+ }
880
+ if (given !== "kept") return yield* Effect.fail(given.refused);
881
+ if (size >= 65536) {
882
+ answer.keep(yield* checkedObject(indexed.pack, oid, resolved));
883
+ run.at = 0;
884
+ continue;
885
+ }
886
+ const bytes = new Uint8Array(resolved.object.bytes);
887
+ const checked = checkedNow(indexed.pack, oid, resolved.object.kind, bytes);
888
+ if ("code" in checked) return yield* Effect.fail(checked);
889
+ answer.keep(checked);
890
+ run.at += size;
891
+ if (run.at >= 1048576) {
892
+ yield* aTurn;
893
+ run.at = 0;
894
+ }
895
+ }
896
+ });
897
+ /**
898
+ * `ObjectReader.objects`: `asked[0]` read and charged first, a packed entry or a row, then the
899
+ * rest's rows, each charged as it's decoded, then their packed entries in the order of their
900
+ * offsets, each found as `located` finds it: a walk over packed objects asks the store for no
901
+ * row. A batch that fails lets go of every byte it was granted.
902
+ */
903
+ const batch = Effect.fnUntraced(function* (answer, asked) {
904
+ const [first, ...rest] = asked;
905
+ if (first === void 0) return answer.read(asked);
906
+ const run = { at: 0 };
907
+ const keep = (row) => keptOrLeft(answer, row);
908
+ const firstPlace = (yield* located([first], keep)).get(first);
909
+ if (firstPlace !== void 0) yield* placed(answer, [[first, firstPlace]], run);
910
+ if (rest.length > 0) yield* placed(answer, byPlace(yield* located(rest, keep)), run);
911
+ return answer.read(asked);
912
+ });
913
+ /** `batch` over `oids`, each once, its grants let go if it fails. */
914
+ const objects = (oids, allotment) => allotted(allotment, (answer) => batch(answer, [...new Set(oids)]));
915
+ /** Those of `oids` stored as whole blobs, by their entries' headers, none of them read. */
916
+ const wholeBlobs = Effect.fnUntraced(function* (oids) {
917
+ const blobs = /* @__PURE__ */ new Set();
918
+ for (const [oid, { indexed, offset }] of byPlace(yield* found(oids))) {
919
+ const holds = yield* holdsAt(indexed, offset);
920
+ if (holds?.kind === "whole" && holds.type === "blob") blobs.add(oid);
921
+ }
922
+ return blobs;
923
+ });
924
+ /**
925
+ * `oids` in the order whose reads take the fewest blocks: the listed packs' objects by pack and
926
+ * offset, from their `.idx` alone with no header read, then the rest as they came (#662).
927
+ */
928
+ const inPackOrder = Effect.fnUntraced(function* (oids) {
929
+ const where = yield* found(oids, kept, true);
930
+ return [...byPlace(where).map(([oid]) => oid), ...oids.filter((oid) => !where.has(oid))];
931
+ });
932
+ /**
933
+ * Lets go of what the reader holds: its read cache and the indexes it kept. Its blocks stay
934
+ * while a body it handed on still streams from them, and go with the reader once none does. A
935
+ * read after it starts again from nothing, so its caller refuses reads past it, as `GitObjects`'
936
+ * reader does.
937
+ */
938
+ const release = () => {
939
+ wholeAt.clear();
940
+ kept.clear();
941
+ };
942
+ const reads = {
943
+ indexed: Effect.fnUntraced(function* (pack) {
944
+ const known = kept.get(pack.id);
945
+ if (known !== void 0) return known;
946
+ if (!charged.has(pack.id)) {
947
+ yield* memory.index(indexBytes(pack));
948
+ charged.add(pack.id);
949
+ }
950
+ const loaded = yield* indexes.load(bucket, pack);
951
+ kept.set(pack.id, loaded);
952
+ return loaded;
953
+ }),
954
+ held,
955
+ each,
956
+ has,
957
+ heldIn,
958
+ headers,
959
+ sizes,
960
+ stored,
961
+ blocks,
962
+ object,
963
+ objects,
964
+ wholeBlobs,
965
+ inPackOrder,
966
+ release
967
+ };
968
+ return input.visible === void 0 ? reads : narrowedTo(reads, input.visible);
969
+ };
970
+ /** `reads`, each lookup by ID answering only what `visible` holds, as `PackReaderInput` says. */
971
+ const narrowedTo = (reads, visible) => {
972
+ const only = (oids) => Effect.map(visible(oids), (kept) => oids.filter((oid) => kept.has(oid)));
973
+ return {
974
+ ...reads,
975
+ held: (oids) => Effect.flatMap(only(oids), reads.held),
976
+ each: (oids, take) => Effect.flatMap(only(oids), (kept) => reads.each(kept, take)),
977
+ has: (oids, loaded) => Effect.flatMap(only(oids), (kept) => reads.has(kept, loaded)),
978
+ heldIn: (oids, loaded) => Effect.flatMap(only(oids), (kept) => reads.heldIn(kept, loaded)),
979
+ headers: (oids) => Effect.flatMap(only(oids), reads.headers),
980
+ sizes: (oids) => Effect.flatMap(only(oids), reads.sizes),
981
+ stored: {
982
+ ...reads.stored,
983
+ find: (oids, loaded) => Effect.flatMap(only(oids), (kept) => reads.stored.find(kept, loaded))
984
+ },
985
+ object: (oid, signal) => Effect.flatMap(only([oid]), (kept) => kept.length === 0 ? Effect.succeed(void 0) : reads.object(oid, signal)),
986
+ objects: (oids, allotment) => Effect.flatMap(only(oids), (kept) => reads.objects(kept, allotment)),
987
+ wholeBlobs: (oids) => Effect.flatMap(only(oids), reads.wholeBlobs)
988
+ };
989
+ };
990
+ export { PackBlocks, PackIndexes, blockBytes, blockHeld, fixedReaderMemory, hashedNowMost, hashedRunMost, headerLimits, indexBytes, packFileBytes, packIndexerLimits, packObjectBytes, packObjects, packReader, readCacheBytes, readWhole };