@ref0/git 0.0.0 → 0.3.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 (515) 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 +50 -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 +170 -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 +151 -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 +11 -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 +38 -0
  64. package/dist/contracts/promises.mjs +13 -0
  65. package/dist/contracts/push-uploads.d.mts +44 -0
  66. package/dist/contracts/queue.d.mts +402 -0
  67. package/dist/contracts/refs.d.mts +95 -0
  68. package/dist/contracts/remote.d.mts +50 -0
  69. package/dist/contracts/repos.d.mts +153 -0
  70. package/dist/contracts/result.d.mts +133 -0
  71. package/dist/contracts/result.mjs +34 -0
  72. package/dist/contracts/rules.d.mts +159 -0
  73. package/dist/contracts/server.d.mts +272 -0
  74. package/dist/contracts/services.d.mts +36 -0
  75. package/dist/contracts/services.mjs +13 -0
  76. package/dist/contracts/signin.d.mts +126 -0
  77. package/dist/contracts/store.d.mts +41 -0
  78. package/dist/contracts/sync.d.mts +210 -0
  79. package/dist/contracts/sync.mjs +8 -0
  80. package/dist/contracts/tags.d.mts +50 -0
  81. package/dist/contracts/tags.mjs +6 -0
  82. package/dist/contracts/tokens.d.mts +87 -0
  83. package/dist/contracts/tokens.mjs +15 -0
  84. package/dist/contracts/topics.d.mts +180 -0
  85. package/dist/contracts/trees.d.mts +84 -0
  86. package/dist/contracts/work.d.mts +31 -0
  87. package/dist/core/access.d.mts +22 -0
  88. package/dist/core/access.mjs +262 -0
  89. package/dist/core/ancestry.mjs +235 -0
  90. package/dist/core/call-names.d.mts +1 -0
  91. package/dist/core/call-names.mjs +93 -0
  92. package/dist/core/clock.mjs +18 -0
  93. package/dist/core/events/deliver.mjs +475 -0
  94. package/dist/core/events/stream.d.mts +19 -0
  95. package/dist/core/events/stream.mjs +297 -0
  96. package/dist/core/forks.mjs +1027 -0
  97. package/dist/core/hooks/post-receive.mjs +212 -0
  98. package/dist/core/hooks/pre-receive.d.mts +5 -0
  99. package/dist/core/hooks/pre-receive.mjs +34 -0
  100. package/dist/core/index-job.mjs +198 -0
  101. package/dist/core/names.mjs +30 -0
  102. package/dist/core/objects/blobs.mjs +60 -0
  103. package/dist/core/objects/commit-writes.mjs +185 -0
  104. package/dist/core/objects/commits.mjs +172 -0
  105. package/dist/core/objects/files.mjs +211 -0
  106. package/dist/core/objects/lines.mjs +42 -0
  107. package/dist/core/objects/merges.mjs +83 -0
  108. package/dist/core/objects/peel.mjs +166 -0
  109. package/dist/core/objects/reading.mjs +284 -0
  110. package/dist/core/objects/tags.mjs +96 -0
  111. package/dist/core/objects/tree-edits.mjs +266 -0
  112. package/dist/core/objects/trees.mjs +229 -0
  113. package/dist/core/objects/writing.mjs +266 -0
  114. package/dist/core/own-writes.mjs +94 -0
  115. package/dist/core/promise.mjs +64 -0
  116. package/dist/core/publish.mjs +142 -0
  117. package/dist/core/push-decide.mjs +206 -0
  118. package/dist/core/push.mjs +1070 -0
  119. package/dist/core/receipts.d.mts +7 -0
  120. package/dist/core/receipts.mjs +234 -0
  121. package/dist/core/ref-conflicts.mjs +27 -0
  122. package/dist/core/refs.mjs +359 -0
  123. package/dist/core/repack.mjs +521 -0
  124. package/dist/core/repos.mjs +752 -0
  125. package/dist/core/rules/changes.mjs +57 -0
  126. package/dist/core/rules/check.mjs +101 -0
  127. package/dist/core/rules/commit-changes.mjs +216 -0
  128. package/dist/core/rules/context.d.mts +9 -0
  129. package/dist/core/rules/context.mjs +120 -0
  130. package/dist/core/rules/define.d.mts +5 -0
  131. package/dist/core/rules/define.mjs +13 -0
  132. package/dist/core/rules/facts.mjs +13 -0
  133. package/dist/core/rules/fetch.d.mts +5 -0
  134. package/dist/core/rules/fetch.mjs +59 -0
  135. package/dist/core/rules/file-globs.mjs +55 -0
  136. package/dist/core/rules/files.mjs +142 -0
  137. package/dist/core/rules/patterns.mjs +23 -0
  138. package/dist/core/rules/protect.d.mts +9 -0
  139. package/dist/core/rules/protect.mjs +116 -0
  140. package/dist/core/seam.d.mts +26 -0
  141. package/dist/core/seam.mjs +54 -0
  142. package/dist/core/sight.mjs +99 -0
  143. package/dist/core/tokens.mjs +95 -0
  144. package/dist/core/view.d.mts +9 -0
  145. package/dist/core/view.mjs +221 -0
  146. package/dist/core/work.mjs +92 -0
  147. package/dist/effect.d.mts +20 -0
  148. package/dist/effect.mjs +18 -0
  149. package/dist/engine/allotted-xdiff.d.mts +4 -0
  150. package/dist/engine/allotted-xdiff.mjs +80 -0
  151. package/dist/engine/attribute-patterns.mjs +163 -0
  152. package/dist/engine/attributes.mjs +226 -0
  153. package/dist/engine/combined.mjs +653 -0
  154. package/dist/engine/commits.mjs +90 -0
  155. package/dist/engine/content.d.mts +4 -0
  156. package/dist/engine/content.mjs +221 -0
  157. package/dist/engine/diff.mjs +49 -0
  158. package/dist/engine/engine.d.mts +25 -0
  159. package/dist/engine/engine.mjs +49 -0
  160. package/dist/engine/failures.d.mts +4 -0
  161. package/dist/engine/failures.mjs +23 -0
  162. package/dist/engine/line-count.mjs +23 -0
  163. package/dist/engine/merge-base-walk.d.mts +2 -0
  164. package/dist/engine/merge-base-walk.mjs +265 -0
  165. package/dist/engine/merge-bases.mjs +27 -0
  166. package/dist/engine/merge-renames.mjs +165 -0
  167. package/dist/engine/merge.mjs +1125 -0
  168. package/dist/engine/parts.d.mts +8 -0
  169. package/dist/engine/parts.mjs +9 -0
  170. package/dist/engine/reads.d.mts +5 -0
  171. package/dist/engine/reads.mjs +105 -0
  172. package/dist/engine/walk.mjs +328 -0
  173. package/dist/engine/xdiff/NOTICE.md +63 -0
  174. package/dist/engine/xdiff/compiled.d.mts +7 -0
  175. package/dist/engine/xdiff/compiled.mjs +9 -0
  176. package/dist/engine/xdiff/embedded.mjs +4 -0
  177. package/dist/engine/xdiff/node.d.mts +7 -0
  178. package/dist/engine/xdiff/node.mjs +10 -0
  179. package/dist/engine/xdiff/upstream/LGPL-2.1 +511 -0
  180. package/dist/engine/xdiff/xdiff.wasm +0 -0
  181. package/dist/engine/xdiff.d.mts +34 -0
  182. package/dist/engine/xdiff.mjs +380 -0
  183. package/dist/engine.d.mts +3 -0
  184. package/dist/engine.mjs +3 -0
  185. package/dist/extend.d.mts +4 -0
  186. package/dist/extend.mjs +3 -0
  187. package/dist/http/answers.mjs +74 -0
  188. package/dist/http/bodies.mjs +143 -0
  189. package/dist/http/core-parts.mjs +252 -0
  190. package/dist/http/fetch-depth.mjs +26 -0
  191. package/dist/http/handler.mjs +94 -0
  192. package/dist/http/node.d.mts +70 -0
  193. package/dist/http/node.mjs +178 -0
  194. package/dist/http/paths.d.mts +9 -0
  195. package/dist/http/paths.mjs +118 -0
  196. package/dist/http/push-uploads.mjs +286 -0
  197. package/dist/http/receive-pack.mjs +235 -0
  198. package/dist/http/upload-pack.mjs +229 -0
  199. package/dist/index.d.mts +46 -0
  200. package/dist/index.mjs +16 -0
  201. package/dist/lfs/calls.mjs +16 -0
  202. package/dist/lfs/locks.mjs +161 -0
  203. package/dist/lfs/objects.mjs +370 -0
  204. package/dist/lfs/pointers.mjs +141 -0
  205. package/dist/lfs/repo.mjs +42 -0
  206. package/dist/lfs/rows.mjs +108 -0
  207. package/dist/lfs/service.mjs +34 -0
  208. package/dist/lfs/upkeep.mjs +162 -0
  209. package/dist/lfs/wire.mjs +102 -0
  210. package/dist/node.d.mts +3 -0
  211. package/dist/node.mjs +3 -0
  212. package/dist/protocol/bytes/buffers.d.mts +38 -0
  213. package/dist/protocol/bytes/buffers.mjs +62 -0
  214. package/dist/protocol/bytes/crc32.d.mts +4 -0
  215. package/dist/protocol/bytes/crc32.mjs +14 -0
  216. package/dist/protocol/bytes/deflate.d.mts +78 -0
  217. package/dist/protocol/bytes/deflate.mjs +175 -0
  218. package/dist/protocol/bytes/errors.d.mts +20 -0
  219. package/dist/protocol/bytes/errors.mjs +19 -0
  220. package/dist/protocol/bytes/hex.mjs +16 -0
  221. package/dist/protocol/bytes/hmac-sha256.mjs +91 -0
  222. package/dist/protocol/bytes/inflate.d.mts +40 -0
  223. package/dist/protocol/bytes/inflate.mjs +109 -0
  224. package/dist/protocol/bytes/joined.d.mts +2 -0
  225. package/dist/protocol/bytes/joined.mjs +25 -0
  226. package/dist/protocol/bytes/sha1-hasher.d.mts +20 -0
  227. package/dist/protocol/bytes/sha1-hasher.mjs +72 -0
  228. package/dist/protocol/bytes/sha1.d.mts +35 -0
  229. package/dist/protocol/bytes/sha1.mjs +409 -0
  230. package/dist/protocol/bytes/sha256.mjs +156 -0
  231. package/dist/protocol/bytes/streams.mjs +11 -0
  232. package/dist/protocol/bytes/text.mjs +19 -0
  233. package/dist/protocol/diff/diff-raw.d.mts +29 -0
  234. package/dist/protocol/diff/diff-raw.mjs +73 -0
  235. package/dist/protocol/diff/patch.mjs +92 -0
  236. package/dist/protocol/diff/paths.mjs +67 -0
  237. package/dist/protocol/diff/read.d.mts +62 -0
  238. package/dist/protocol/diff/read.mjs +342 -0
  239. package/dist/protocol/diff/rename-similarity.mjs +428 -0
  240. package/dist/protocol/diff/text.mjs +12 -0
  241. package/dist/protocol/diff/tree-diff.d.mts +41 -0
  242. package/dist/protocol/diff/tree-diff.mjs +607 -0
  243. package/dist/protocol/framing/band.d.mts +10 -0
  244. package/dist/protocol/framing/band.mjs +16 -0
  245. package/dist/protocol/framing/pkt-line.d.mts +48 -0
  246. package/dist/protocol/framing/pkt-line.mjs +92 -0
  247. package/dist/protocol/objects/checked-blobs.mjs +127 -0
  248. package/dist/protocol/objects/commit.d.mts +25 -0
  249. package/dist/protocol/objects/commit.mjs +138 -0
  250. package/dist/protocol/objects/fsck-gitmodules.mjs +296 -0
  251. package/dist/protocol/objects/fsck-names.mjs +189 -0
  252. package/dist/protocol/objects/fsck.mjs +297 -0
  253. package/dist/protocol/objects/headers.mjs +109 -0
  254. package/dist/protocol/objects/held.mjs +56 -0
  255. package/dist/protocol/objects/iconv.mjs +145 -0
  256. package/dist/protocol/objects/ident.mjs +111 -0
  257. package/dist/protocol/objects/lfs-pointer.d.mts +8 -0
  258. package/dist/protocol/objects/lfs-pointer.mjs +63 -0
  259. package/dist/protocol/objects/links-raw.mjs +89 -0
  260. package/dist/protocol/objects/object-rules.mjs +75 -0
  261. package/dist/protocol/objects/object.d.mts +16 -0
  262. package/dist/protocol/objects/object.mjs +29 -0
  263. package/dist/protocol/objects/tag.d.mts +21 -0
  264. package/dist/protocol/objects/tag.mjs +96 -0
  265. package/dist/protocol/objects/tree.d.mts +43 -0
  266. package/dist/protocol/objects/tree.mjs +162 -0
  267. package/dist/protocol/objects/utf8-verify.mjs +71 -0
  268. package/dist/protocol/packs/delta.d.mts +57 -0
  269. package/dist/protocol/packs/delta.mjs +229 -0
  270. package/dist/protocol/packs/graph.mjs +78 -0
  271. package/dist/protocol/packs/idx.d.mts +54 -0
  272. package/dist/protocol/packs/idx.mjs +274 -0
  273. package/dist/protocol/packs/indexer.d.mts +167 -0
  274. package/dist/protocol/packs/indexer.mjs +507 -0
  275. package/dist/protocol/packs/parts.d.mts +40 -0
  276. package/dist/protocol/packs/parts.mjs +89 -0
  277. package/dist/protocol/packs/pos.mjs +51 -0
  278. package/dist/protocol/packs/reader.d.mts +180 -0
  279. package/dist/protocol/packs/reader.mjs +414 -0
  280. package/dist/protocol/packs/rev.d.mts +32 -0
  281. package/dist/protocol/packs/rev.mjs +99 -0
  282. package/dist/protocol/packs/step.d.mts +10 -0
  283. package/dist/protocol/packs/step.mjs +12 -0
  284. package/dist/protocol/packs/write-error.d.mts +12 -0
  285. package/dist/protocol/packs/write-error.mjs +27 -0
  286. package/dist/protocol/packs/writer.d.mts +157 -0
  287. package/dist/protocol/packs/writer.mjs +353 -0
  288. package/dist/protocol/wire/advertisement.d.mts +72 -0
  289. package/dist/protocol/wire/advertisement.mjs +161 -0
  290. package/dist/protocol/wire/fetch.d.mts +155 -0
  291. package/dist/protocol/wire/fetch.mjs +458 -0
  292. package/dist/protocol/wire/lines.mjs +107 -0
  293. package/dist/protocol/wire/push-uploads.mjs +43 -0
  294. package/dist/protocol/wire/receive-pack.d.mts +71 -0
  295. package/dist/protocol/wire/receive-pack.mjs +157 -0
  296. package/dist/protocol/wire/report-status.d.mts +47 -0
  297. package/dist/protocol/wire/report-status.mjs +119 -0
  298. package/dist/protocol/wire/v2.d.mts +90 -0
  299. package/dist/protocol/wire/v2.mjs +185 -0
  300. package/dist/protocol.d.mts +31 -0
  301. package/dist/protocol.mjs +31 -0
  302. package/dist/queue/advance.mjs +1037 -0
  303. package/dist/queue/callers.mjs +134 -0
  304. package/dist/queue/calls.mjs +1154 -0
  305. package/dist/queue/commit.mjs +85 -0
  306. package/dist/queue/host.d.mts +15 -0
  307. package/dist/queue/host.mjs +88 -0
  308. package/dist/queue/ids.d.mts +5 -0
  309. package/dist/queue/ids.mjs +21 -0
  310. package/dist/queue/lanes.mjs +86 -0
  311. package/dist/queue/limits.mjs +99 -0
  312. package/dist/queue/pages.mjs +76 -0
  313. package/dist/queue/push-option.mjs +62 -0
  314. package/dist/queue/rows.mjs +206 -0
  315. package/dist/queue/schedule.mjs +132 -0
  316. package/dist/queue/search.mjs +315 -0
  317. package/dist/queue/state.mjs +325 -0
  318. package/dist/queue/steps.mjs +317 -0
  319. package/dist/remote-helper.d.mts +3 -0
  320. package/dist/remote-helper.mjs +3 -0
  321. package/dist/rest/api.d.mts +23 -0
  322. package/dist/rest/api.mjs +27 -0
  323. package/dist/rest/blobs.d.mts +58 -0
  324. package/dist/rest/blobs.mjs +41 -0
  325. package/dist/rest/caller.d.mts +102 -0
  326. package/dist/rest/caller.mjs +18 -0
  327. package/dist/rest/client.d.mts +18 -0
  328. package/dist/rest/client.mjs +587 -0
  329. package/dist/rest/commits.d.mts +435 -0
  330. package/dist/rest/commits.mjs +140 -0
  331. package/dist/rest/errors.d.mts +44 -0
  332. package/dist/rest/errors.mjs +186 -0
  333. package/dist/rest/events.d.mts +38 -0
  334. package/dist/rest/events.mjs +74 -0
  335. package/dist/rest/files.d.mts +179 -0
  336. package/dist/rest/files.mjs +92 -0
  337. package/dist/rest/forks.d.mts +205 -0
  338. package/dist/rest/forks.mjs +51 -0
  339. package/dist/rest/handler.d.mts +18 -0
  340. package/dist/rest/handler.mjs +129 -0
  341. package/dist/rest/handlers.d.mts +8 -0
  342. package/dist/rest/handlers.mjs +592 -0
  343. package/dist/rest/listen.d.mts +24 -0
  344. package/dist/rest/listen.mjs +142 -0
  345. package/dist/rest/me.d.mts +55 -0
  346. package/dist/rest/me.mjs +21 -0
  347. package/dist/rest/merges.d.mts +90 -0
  348. package/dist/rest/merges.mjs +39 -0
  349. package/dist/rest/paths.mjs +86 -0
  350. package/dist/rest/queue.d.mts +486 -0
  351. package/dist/rest/queue.mjs +228 -0
  352. package/dist/rest/refs.d.mts +232 -0
  353. package/dist/rest/refs.mjs +86 -0
  354. package/dist/rest/repos.d.mts +223 -0
  355. package/dist/rest/repos.mjs +93 -0
  356. package/dist/rest/tags.d.mts +153 -0
  357. package/dist/rest/tags.mjs +72 -0
  358. package/dist/rest/tokens.d.mts +297 -0
  359. package/dist/rest/tokens.mjs +88 -0
  360. package/dist/rest/topics.d.mts +257 -0
  361. package/dist/rest/topics.mjs +116 -0
  362. package/dist/rest/trees.d.mts +158 -0
  363. package/dist/rest/trees.mjs +118 -0
  364. package/dist/rest/wire.mjs +57 -0
  365. package/dist/rest/work.d.mts +107 -0
  366. package/dist/rest/work.mjs +77 -0
  367. package/dist/rest.d.mts +8 -0
  368. package/dist/rest.mjs +5 -0
  369. package/dist/server/extension.d.mts +17 -0
  370. package/dist/server/extension.mjs +93 -0
  371. package/dist/server/lifecycle.d.mts +3 -0
  372. package/dist/server/lifecycle.mjs +89 -0
  373. package/dist/server/routes.d.mts +28 -0
  374. package/dist/server/routes.mjs +60 -0
  375. package/dist/server/server.d.mts +8 -0
  376. package/dist/server/server.mjs +615 -0
  377. package/dist/signin/codes.mjs +47 -0
  378. package/dist/signin/context.d.mts +9 -0
  379. package/dist/signin/context.mjs +121 -0
  380. package/dist/signin/device.mjs +122 -0
  381. package/dist/signin/forms.mjs +157 -0
  382. package/dist/signin/grants.d.mts +5 -0
  383. package/dist/signin/grants.mjs +257 -0
  384. package/dist/signin/route.mjs +68 -0
  385. package/dist/signin/web.mjs +125 -0
  386. package/dist/signin/wire.d.mts +42 -0
  387. package/dist/signin/wire.mjs +43 -0
  388. package/dist/storage/allotted.mjs +102 -0
  389. package/dist/storage/bits.mjs +41 -0
  390. package/dist/storage/budget.mjs +96 -0
  391. package/dist/storage/calls.d.mts +18 -0
  392. package/dist/storage/calls.mjs +273 -0
  393. package/dist/storage/clean-up.mjs +124 -0
  394. package/dist/storage/distinct-ids.mjs +39 -0
  395. package/dist/storage/ewah.mjs +97 -0
  396. package/dist/storage/fetch.d.mts +15 -0
  397. package/dist/storage/fetch.mjs +998 -0
  398. package/dist/storage/fsck.mjs +77 -0
  399. package/dist/storage/held-memo.mjs +188 -0
  400. package/dist/storage/index-bitmaps.d.mts +4 -0
  401. package/dist/storage/index-bitmaps.mjs +654 -0
  402. package/dist/storage/index-build.d.mts +15 -0
  403. package/dist/storage/index-build.mjs +1447 -0
  404. package/dist/storage/index-fetch.d.mts +10 -0
  405. package/dist/storage/index-fetch.mjs +677 -0
  406. package/dist/storage/index-files.mjs +232 -0
  407. package/dist/storage/index-graph.d.mts +3 -0
  408. package/dist/storage/index-graph.mjs +1049 -0
  409. package/dist/storage/index-layers.mjs +317 -0
  410. package/dist/storage/index-reach.mjs +216 -0
  411. package/dist/storage/index-remap.d.mts +8 -0
  412. package/dist/storage/index-remap.mjs +592 -0
  413. package/dist/storage/layout.mjs +69 -0
  414. package/dist/storage/lfs-pointers.d.mts +21 -0
  415. package/dist/storage/lfs-pointers.mjs +175 -0
  416. package/dist/storage/link-join.mjs +106 -0
  417. package/dist/storage/links.mjs +105 -0
  418. package/dist/storage/loose.d.mts +15 -0
  419. package/dist/storage/loose.mjs +121 -0
  420. package/dist/storage/memory-budget.d.mts +8 -0
  421. package/dist/storage/memory-budget.mjs +546 -0
  422. package/dist/storage/merge.mjs +416 -0
  423. package/dist/storage/object-rows.d.mts +6 -0
  424. package/dist/storage/object-rows.mjs +211 -0
  425. package/dist/storage/pack-order.d.mts +8 -0
  426. package/dist/storage/pack-order.mjs +781 -0
  427. package/dist/storage/pack-ranges.d.mts +5 -0
  428. package/dist/storage/pack-ranges.mjs +284 -0
  429. package/dist/storage/pack-reads.d.mts +11 -0
  430. package/dist/storage/pack-reads.mjs +1007 -0
  431. package/dist/storage/pack-receive.d.mts +11 -0
  432. package/dist/storage/pack-receive.mjs +449 -0
  433. package/dist/storage/packs.d.mts +56 -0
  434. package/dist/storage/packs.mjs +603 -0
  435. package/dist/storage/prune.mjs +506 -0
  436. package/dist/storage/push-allotment.mjs +109 -0
  437. package/dist/storage/push-uploads.mjs +152 -0
  438. package/dist/storage/pushed-commits.mjs +136 -0
  439. package/dist/storage/quarantine.mjs +98 -0
  440. package/dist/storage/raw-ids.mjs +44 -0
  441. package/dist/storage/ready.d.mts +19 -0
  442. package/dist/storage/ready.mjs +328 -0
  443. package/dist/storage/receive-links.mjs +297 -0
  444. package/dist/storage/repack-job.mjs +48 -0
  445. package/dist/storage/repack.d.mts +31 -0
  446. package/dist/storage/repack.mjs +182 -0
  447. package/dist/storage/roots.mjs +42 -0
  448. package/dist/storage/rows.d.mts +4 -0
  449. package/dist/storage/rows.mjs +71 -0
  450. package/dist/storage/send-list.d.mts +8 -0
  451. package/dist/storage/send-list.mjs +319 -0
  452. package/dist/storage/shallow.d.mts +4 -0
  453. package/dist/storage/shallow.mjs +128 -0
  454. package/dist/storage/stream-whole.mjs +236 -0
  455. package/dist/storage/unpack.mjs +238 -0
  456. package/dist/storage/visible.mjs +137 -0
  457. package/dist/storage/walk.d.mts +8 -0
  458. package/dist/storage/walk.mjs +176 -0
  459. package/dist/storage/wants.mjs +362 -0
  460. package/dist/store/call-count.d.mts +47 -0
  461. package/dist/store/call-count.mjs +207 -0
  462. package/dist/store/catalogue.d.mts +7 -0
  463. package/dist/store/catalogue.mjs +643 -0
  464. package/dist/store/closed.d.mts +21 -0
  465. package/dist/store/closed.mjs +34 -0
  466. package/dist/store/crossing.mjs +69 -0
  467. package/dist/store/cursor-seal.d.mts +2 -0
  468. package/dist/store/cursor-seal.mjs +88 -0
  469. package/dist/store/errors.d.mts +12 -0
  470. package/dist/store/errors.mjs +135 -0
  471. package/dist/store/git-store.mjs +75 -0
  472. package/dist/store/list-job.mjs +35 -0
  473. package/dist/store/outbox.d.mts +7 -0
  474. package/dist/store/outbox.mjs +297 -0
  475. package/dist/store/promises.d.mts +5 -0
  476. package/dist/store/promises.mjs +258 -0
  477. package/dist/store/queue-jobs.mjs +43 -0
  478. package/dist/store/random.mjs +28 -0
  479. package/dist/store/records.d.mts +4 -0
  480. package/dist/store/records.mjs +192 -0
  481. package/dist/store/ref-rows.d.mts +4 -0
  482. package/dist/store/ref-rows.mjs +30 -0
  483. package/dist/store/repo-record.mjs +100 -0
  484. package/dist/store/reservations.mjs +82 -0
  485. package/dist/store/scopes.mjs +170 -0
  486. package/dist/store/settle.mjs +63 -0
  487. package/dist/store/topic-jobs.mjs +62 -0
  488. package/dist/sync/bound.d.mts +7 -0
  489. package/dist/sync/bound.mjs +34 -0
  490. package/dist/sync/github.d.mts +12 -0
  491. package/dist/sync/github.mjs +297 -0
  492. package/dist/sync/import.d.mts +8 -0
  493. package/dist/sync/import.mjs +154 -0
  494. package/dist/sync/jobs.d.mts +9 -0
  495. package/dist/sync/jobs.mjs +83 -0
  496. package/dist/sync/mirror.d.mts +9 -0
  497. package/dist/sync/mirror.mjs +227 -0
  498. package/dist/sync/publish.d.mts +5 -0
  499. package/dist/sync/publish.mjs +117 -0
  500. package/dist/sync/records.mjs +73 -0
  501. package/dist/sync/smart-http.d.mts +8 -0
  502. package/dist/sync/smart-http.mjs +23 -0
  503. package/dist/sync/step.mjs +334 -0
  504. package/dist/sync/tries.mjs +126 -0
  505. package/dist/sync.d.mts +8 -0
  506. package/dist/sync.mjs +8 -0
  507. package/dist/topics/advance.mjs +555 -0
  508. package/dist/topics/calls.mjs +346 -0
  509. package/dist/topics/directory.mjs +107 -0
  510. package/dist/topics/host.d.mts +11 -0
  511. package/dist/topics/host.mjs +71 -0
  512. package/dist/topics/members.mjs +177 -0
  513. package/dist/topics/rows.mjs +99 -0
  514. package/dist/topics/topic.mjs +141 -0
  515. package/package.json +86 -5
@@ -0,0 +1,128 @@
1
+ import { gitError } from "../store/errors.mjs";
2
+ import { historyOf, lost, unreadable, walk } from "./walk.mjs";
3
+ import * as Effect from "effect/Effect";
4
+ // src/storage/shallow.ts
5
+ /**
6
+ * A depth this large deepens a shallow clone to its whole history, as `git fetch --unshallow`
7
+ * asks with `deepen 2147483647`, Git's `INFINITE_DEPTH`.
8
+ */
9
+ const infiniteDepth = 2147483647;
10
+ const notACommit = (object) => gitError("INVALID_ARGUMENT", `The shallow line names ${object.oid}, a ${object.type}`, { hint: "A shallow clone names only commits it holds without their parents" });
11
+ /**
12
+ * The client's shallow commits this repo holds: one it doesn't hold is passed over,
13
+ * as Git's server does, and one that isn't a commit is refused.
14
+ */
15
+ const clientShallowsOf = Effect.fnUntraced(function* (read, shallows) {
16
+ const held = [...(yield* read([...new Set(shallows)])).values()];
17
+ const odd = held.find((object) => object.type !== "commit");
18
+ if (odd !== void 0) return yield* Effect.fail(notACommit(odd));
19
+ return new Map(held.map((object) => [object.oid, object]));
20
+ });
21
+ /**
22
+ * The parents of `commits`, in order: each taken one at a time, as a merge can name more parents
23
+ * than a call takes arguments.
24
+ */
25
+ const parentsOf = (commits) => {
26
+ const parents = [];
27
+ for (const commit of commits) for (const parent of historyOf(commit)) parents.push(parent);
28
+ return parents;
29
+ };
30
+ /** The commits `wants` name, a tag peeled to what it tags: a want of a tree or a blob has none. */
31
+ const wantedCommits = Effect.fnUntraced(function* (read, wants) {
32
+ const commits = /* @__PURE__ */ new Set();
33
+ let frontier = [...new Set(wants)];
34
+ while (frontier.length > 0) {
35
+ const found = yield* read(frontier);
36
+ const next = [];
37
+ for (const object of found.values()) if (object.type === "commit") commits.add(object.oid);
38
+ else if (object.type === "tag") next.push(...historyOf(object));
39
+ frontier = next.filter((oid) => !commits.has(oid));
40
+ }
41
+ return [...commits];
42
+ });
43
+ /**
44
+ * The client's shallow commits the wants reach, walking down from the wants: those
45
+ * `deepen-relative` deepens from, and the only ones a deepen unshallows, so a fetch never sends
46
+ * history a want doesn't reach. `past` walks on below each one, as an infinite deepen sends that
47
+ * history anyway, so one behind another is reached too; without it the walk stops at each, so
48
+ * `deepen-relative` reads no more than the client holds.
49
+ */
50
+ const reachedShallows = Effect.fnUntraced(function* (read, wants, shallows, past) {
51
+ const reached = yield* walk(read, wants, (object) => !past && shallows.has(object.oid) ? [] : historyOf(object), /* @__PURE__ */ new Set(), lost);
52
+ return [...shallows.values()].filter((commit) => reached.has(commit.oid));
53
+ });
54
+ /**
55
+ * The commits within `depth` of `starts`, each at its least depth over every path, a start at 1:
56
+ * `within` those under `depth`, whose parents the pack follows, and `edge` those at it, whose
57
+ * parents it leaves out.
58
+ */
59
+ const byDepth = Effect.fnUntraced(function* (read, starts, depth) {
60
+ const within = /* @__PURE__ */ new Map();
61
+ let frontier = [...new Set(starts)];
62
+ for (let level = 1; level < depth && frontier.length > 0; level += 1) {
63
+ const found = yield* read(frontier);
64
+ const next = /* @__PURE__ */ new Set();
65
+ for (const oid of frontier) {
66
+ const commit = found.get(oid);
67
+ if (commit === void 0) return yield* Effect.fail(lost(oid));
68
+ if (commit.type !== "commit") return yield* Effect.fail(unreadable(commit, "a commit names it as a parent"));
69
+ within.set(oid, commit);
70
+ for (const parent of historyOf(commit)) if (!within.has(parent)) next.add(parent);
71
+ }
72
+ frontier = [...next].filter((oid) => !within.has(oid));
73
+ }
74
+ return {
75
+ within,
76
+ edge: frontier
77
+ };
78
+ });
79
+ /**
80
+ * A fetch's shallow lines and where its history stops, as Git's `upload-pack` works them out from
81
+ * `gitprotocol-v2`'s `deepen` and `deepen-relative`:
82
+ * - with no depth, the client's shallow commits stay so, and the pack stops at them;
83
+ * - `deepen <n>` keeps the commits fewer than `n` from a want, by their nearest path, and cuts at
84
+ * those `n` away: one at the cut is `shallow` unless the client already holds it so, and a
85
+ * client's shallow commit inside it is `unshallow`;
86
+ * - `deepen-relative` counts `n` more from the client's shallow commits the wants reach;
87
+ * - `deepen 2147483647`, without `deepen-relative`, unshallows every one the wants reach, one
88
+ * behind another too. Git's unshallows every one it holds, but the history behind one no
89
+ * want reaches isn't the caller's to fetch.
90
+ */
91
+ const planShallow = Effect.fnUntraced(function* (read, request) {
92
+ const shallows = yield* clientShallowsOf(read, request.shallows);
93
+ const clientShallows = new Set(shallows.keys());
94
+ const depth = request.depth;
95
+ if (depth === void 0) return {
96
+ shallow: [],
97
+ unshallow: [],
98
+ cut: clientShallows,
99
+ clientShallows,
100
+ starts: []
101
+ };
102
+ const relative = request.deepenRelative === true;
103
+ const wants = yield* wantedCommits(read, request.wants);
104
+ if (!relative && depth >= 2147483647) {
105
+ const reached = yield* reachedShallows(read, wants, shallows, true);
106
+ const unshallow = reached.map((commit) => commit.oid);
107
+ const unshallowed = new Set(unshallow);
108
+ return {
109
+ shallow: [],
110
+ unshallow,
111
+ cut: new Set([...clientShallows].filter((oid) => !unshallowed.has(oid))),
112
+ clientShallows,
113
+ starts: parentsOf(reached)
114
+ };
115
+ }
116
+ const from = relative ? (yield* reachedShallows(read, wants, shallows, false)).map((commit) => commit.oid) : wants;
117
+ const levels = yield* byDepth(read, from, relative ? depth + 1 : depth);
118
+ const unshallowed = [...shallows.values()].filter((commit) => levels.within.has(commit.oid));
119
+ const kept = [...clientShallows].filter((oid) => !levels.within.has(oid));
120
+ return {
121
+ shallow: levels.edge.filter((oid) => !clientShallows.has(oid)),
122
+ unshallow: unshallowed.map((commit) => commit.oid),
123
+ cut: /* @__PURE__ */ new Set([...levels.edge, ...kept]),
124
+ clientShallows,
125
+ starts: parentsOf(unshallowed)
126
+ };
127
+ });
128
+ export { infiniteDepth, planShallow };
@@ -0,0 +1,236 @@
1
+ import { deflateWhole } from "../protocol/bytes/deflate.mjs";
2
+ import { nativeSha1Hasher } from "../protocol/bytes/sha1-hasher.mjs";
3
+ import { entryHeader } from "../protocol/packs/writer.mjs";
4
+ import { gitError, thrownError } from "../store/errors.mjs";
5
+ import { callsAhead } from "./fetch.mjs";
6
+ import { repoScope } from "../store/scopes.mjs";
7
+ import { bucketCall } from "./calls.mjs";
8
+ import { noCall, runIn } from "../store/crossing.mjs";
9
+ import { objectCollections, packFiles } from "./layout.mjs";
10
+ import { eachPageAt, objectOfRow } from "./object-rows.mjs";
11
+ import { rowsBytes } from "./repack.mjs";
12
+ import * as Effect from "effect/Effect";
13
+ import * as Hex from "effect/encoding/Hex";
14
+ // src/storage/stream-whole.ts
15
+ /**
16
+ * The most object rows a streamed clone writes whole after the packs. Past it the clone builds, as
17
+ * it did before: a prune pass folds the rows into its pack.
18
+ */
19
+ const wholeRowsMost = 1e3;
20
+ /** A stored pack's header, `PACK`, its version and its count, before its entries. */
21
+ const headerBytes = 12;
22
+ /** A pack's trailer, the SHA-1 of every byte before it. */
23
+ const trailerBytes = 20;
24
+ /** A PACK's header: `PACK`, version 2, and `count`, four bytes big-endian. */
25
+ const packHeader = (count) => {
26
+ const bytes = new Uint8Array(headerBytes);
27
+ bytes.set([
28
+ 80,
29
+ 65,
30
+ 67,
31
+ 75
32
+ ]);
33
+ const view = new DataView(bytes.buffer);
34
+ view.setUint32(4, 2);
35
+ view.setUint32(8, count);
36
+ return bytes;
37
+ };
38
+ /**
39
+ * Whether two of `packs`, or a row and a pack, or two rows, hold the same object: a merge of the
40
+ * packs' sorted `.idx` tables, then each row looked up in them. Git's `index-pack` takes no object
41
+ * twice, so a clone over a duplicate builds instead.
42
+ */
43
+ const duplicated = (packs, rows) => {
44
+ const ranks = packs.map(() => 0);
45
+ let last;
46
+ for (;;) {
47
+ let least = -1;
48
+ let oid;
49
+ for (const [at, { index }] of packs.entries()) {
50
+ const rank = ranks[at] ?? index.count;
51
+ if (rank >= index.count) continue;
52
+ const next = index.oidAt(rank);
53
+ if (oid === void 0 || next < oid) {
54
+ oid = next;
55
+ least = at;
56
+ }
57
+ }
58
+ if (oid === void 0) break;
59
+ if (oid === last) return true;
60
+ last = oid;
61
+ ranks[least] = (ranks[least] ?? 0) + 1;
62
+ }
63
+ const seen = /* @__PURE__ */ new Set();
64
+ for (const { oid } of rows) {
65
+ if (seen.has(oid) || packs.some(({ index }) => index.find(oid) !== void 0)) return true;
66
+ seen.add(oid);
67
+ }
68
+ return false;
69
+ };
70
+ /**
71
+ * What a whole clone of `listed` streams, read at its version: its packs but the cruft ones, each
72
+ * index loaded, and its object rows, read a page at a time so no answer passes the store's. Its
73
+ * packs' bytes and its rows' count toward `limits.bytes`, as a plan's would. `undefined` when the
74
+ * repo moved since `listed` was read, when it holds more rows than `wholeRowsMost`, when the clone
75
+ * is past `limits`, or when an object is stored twice: then the clone builds, as before. Refused
76
+ * by `tooManyCalls` when the calls it made, through `store` and `bucket`, and a ranged get a pack
77
+ * still to come pass `calls`, checked before each index load and once loaded, so it stops before
78
+ * the stream's first byte. Each page of rows is charged before it's kept, its values and the
79
+ * objects decoded from them, so the rows it holds are within the fetch's allotment.
80
+ */
81
+ const wholePlan = Effect.fnUntraced(function* (store, bucket, indexes, listed, input, calls, charge = () => Effect.void) {
82
+ const snapshot = yield* store.read({
83
+ scope: repoScope(listed.repo),
84
+ reads: [{ collection: objectCollections.cruft }]
85
+ });
86
+ if (snapshot.version !== listed.version) return void 0;
87
+ const objectRows = [];
88
+ if (!(yield* eachPageAt(store, listed.repo, listed.version, (page) => {
89
+ objectRows.push(...page);
90
+ if (objectRows.length > 1e3) return Effect.succeed(false);
91
+ return Effect.as(charge(2 * rowsBytes(page)), true);
92
+ }))) return void 0;
93
+ const cruft = new Set((snapshot.results[0] ?? []).map(({ id }) => id));
94
+ const kept = listed.packs.filter(({ id }) => !cruft.has(id));
95
+ const rows = yield* Effect.forEach(objectRows, (row) => objectOfRow(row));
96
+ const objects = kept.reduce((sum, pack) => sum + pack.objects, rows.length);
97
+ const packBytes = kept.reduce((sum, pack) => sum + pack.bytes, 0);
98
+ const bytes = rows.reduce((sum, row) => sum + row.bytes.byteLength, packBytes);
99
+ const { limits } = input;
100
+ if (objects > limits.objects || bytes > limits.bytes) return void 0;
101
+ const gets = callsAhead(calls, {
102
+ bucket: kept.length,
103
+ store: 0
104
+ }, true);
105
+ const packs = yield* Effect.forEach(kept, (pack) => Effect.andThen(gets, indexes.load(bucket, pack)));
106
+ yield* gets;
107
+ if (duplicated(packs, rows)) return void 0;
108
+ return {
109
+ packs,
110
+ rows,
111
+ objects
112
+ };
113
+ });
114
+ const changed = (pack) => gitError("DATA_LOSS", `Pack ${pack.pack.id}'s bytes aren't those its index lists`);
115
+ const gone = (pack) => gitError("DATA_LOSS", `Pack ${pack.pack.id} was listed when this clone began, and isn't now`);
116
+ /**
117
+ * One stored pack's entries: one ranged get from its header's end to its trailer, each piece
118
+ * hashed with the header it was stored under and checked against its index's checksum before the
119
+ * last piece is handed on. A pack whose bytes changed ends the clone with `DATA_LOSS` and no
120
+ * trailer, so Git keeps no clone of it, as the planned writer's CRC-32 check does.
121
+ */
122
+ async function* packEntries(bucket, pack, signal, count) {
123
+ const length = pack.pack.bytes - headerBytes - trailerBytes;
124
+ const hash = nativeSha1Hasher();
125
+ await runIn(hash.write(packHeader(pack.index.count)), noCall);
126
+ const opening = bucketCall((fiber) => bucket.read(packFiles(pack.pack.id).pack, {
127
+ offset: headerBytes,
128
+ length
129
+ }, { signal: fiber }));
130
+ const stream = await runIn(Effect.mapError(opening, thrownError), count, signal);
131
+ if (stream === void 0) throw gone(pack);
132
+ const reader = stream.getReader();
133
+ const onAbort = () => void reader.cancel(signal?.reason).catch(() => void 0);
134
+ if (signal?.aborted === true) onAbort();
135
+ signal?.throwIfAborted();
136
+ signal?.addEventListener("abort", onAbort, { once: true });
137
+ let held;
138
+ let read = 0;
139
+ let done = false;
140
+ try {
141
+ for (;;) {
142
+ const next = await reader.read();
143
+ if (next.done) break;
144
+ read += next.value.byteLength;
145
+ await runIn(hash.write(next.value), noCall);
146
+ if (held !== void 0) yield held;
147
+ held = next.value;
148
+ }
149
+ done = true;
150
+ } finally {
151
+ signal?.removeEventListener("abort", onAbort);
152
+ if (!done) await reader.cancel(signal?.reason).catch(() => void 0);
153
+ }
154
+ signal?.throwIfAborted();
155
+ const digest = Hex.encode(await runIn(hash.digest, noCall));
156
+ if (read !== length || digest !== pack.index.packChecksum) throw changed(pack);
157
+ if (held !== void 0) yield held;
158
+ }
159
+ /** A whole object's entry: its header, then its bytes deflated. */
160
+ const wholeEntry = Effect.fnUntraced(function* (object) {
161
+ const body = yield* deflateWhole(object.bytes);
162
+ const header = entryHeader(object.type, object.bytes.byteLength);
163
+ const entry = new Uint8Array(header.byteLength + body.byteLength);
164
+ entry.set(header);
165
+ entry.set(body, header.byteLength);
166
+ return entry;
167
+ });
168
+ /** The clone's pieces: the header, each pack's entries, each row's object, then the trailer. */
169
+ async function* wholePieces(bucket, plan, signal, hash, count) {
170
+ const sent = async function* (pieces) {
171
+ for await (const piece of pieces) {
172
+ await runIn(hash.write(piece), noCall);
173
+ yield piece;
174
+ }
175
+ };
176
+ yield* sent([packHeader(plan.objects)]);
177
+ for (const pack of plan.packs) {
178
+ signal?.throwIfAborted();
179
+ yield* sent(packEntries(bucket, pack, signal, count));
180
+ }
181
+ for (const row of plan.rows) {
182
+ signal?.throwIfAborted();
183
+ yield* sent([await runIn(wholeEntry(row), noCall)]);
184
+ }
185
+ signal?.throwIfAborted();
186
+ yield await runIn(hash.digest, noCall);
187
+ }
188
+ /**
189
+ * `plan`'s pack as one stream: a header counting every object, each pack's entries by one ranged
190
+ * get, the rows' objects written whole, and a SHA-1 of the bytes sent. A stored pack is never thin,
191
+ * since a receive refuses one, so each delta's base moves with it: an `OFS_DELTA`'s by its offset
192
+ * in the pack's entries, a `REF_DELTA`'s by its ID. Cancelled, or its call's `signal` aborted, it
193
+ * cancels the bucket's read first: the pieces' `return` waits on a read that may never come. Its
194
+ * reads count into `count`, the clone's request's, if any.
195
+ */
196
+ const wholeStream = (bucket, plan, signal, done = () => {}, count) => {
197
+ const stop = new AbortController();
198
+ const aborted = () => stop.abort(signal?.reason);
199
+ if (signal?.aborted === true) aborted();
200
+ else signal?.addEventListener("abort", aborted, { once: true });
201
+ const pieces = wholePieces(bucket, plan, stop.signal, nativeSha1Hasher(), count);
202
+ let over = false;
203
+ const ended = () => {
204
+ signal?.removeEventListener("abort", aborted);
205
+ if (over) return;
206
+ over = true;
207
+ done();
208
+ };
209
+ return new ReadableStream({
210
+ pull: async (controller) => {
211
+ let next;
212
+ try {
213
+ next = await pieces.next();
214
+ } finally {
215
+ if (next === void 0) ended();
216
+ }
217
+ if (next.done === true) {
218
+ ended();
219
+ controller.close();
220
+ } else controller.enqueue(next.value);
221
+ },
222
+ cancel: async (reason) => {
223
+ ended();
224
+ stop.abort(reason);
225
+ await pieces.return(void 0);
226
+ }
227
+ });
228
+ };
229
+ /** The whole clone's answer, its stream ended by the call's signal and the fetch's deadline. */
230
+ const wholeAnswer = (plan, pack) => ({
231
+ shallow: [],
232
+ unshallow: [],
233
+ objects: plan.objects,
234
+ pack
235
+ });
236
+ export { wholeAnswer, wholePlan, wholeRowsMost, wholeStream };
@@ -0,0 +1,238 @@
1
+ import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
2
+ import { joinedBytes } from "../protocol/bytes/joined.mjs";
3
+ import { nativeSha1Hasher } from "../protocol/bytes/sha1-hasher.mjs";
4
+ import { fsckObject } from "../protocol/objects/fsck.mjs";
5
+ import { objectId } from "../protocol/objects/object.mjs";
6
+ import { appliedDelta } from "../protocol/packs/delta.mjs";
7
+ import { PackError, PackTransportError, boundedSource, readPack } from "../protocol/packs/reader.mjs";
8
+ import { gitError } from "../store/errors.mjs";
9
+ import { checkedFilesRefused, checkedOverflow, fsckRefusal, receiveChecked } from "./fsck.mjs";
10
+ import { linksOf, mistyped, shallowLinks, shallowRoot } from "./links.mjs";
11
+ import { objectRow, rowValueBytes } from "./object-rows.mjs";
12
+ import { limits } from "@ref0/infra";
13
+ import * as Effect from "effect/Effect";
14
+ import * as Result from "effect/Result";
15
+ // src/storage/unpack.ts
16
+ /** One commit's size as JSON, as every store holds it: a push's rows and its refs share it. */
17
+ const commitBytes = 8388608;
18
+ /** What the reader may hold besides the entries it hands on: its inflater and buffers. */
19
+ const readerBytes = 1048576;
20
+ const tooLarge = (bytes, most) => gitError("RESOURCE_EXHAUSTED", `push takes ${bytes.toLocaleString("en-US")} bytes as rows; one commit holds ${most.toLocaleString("en-US")}`, {
21
+ hint: "Push fewer objects at a time",
22
+ hostHint: "Use packs() storage, which keeps a push's objects in the bucket",
23
+ context: { reason: "too-large" }
24
+ });
25
+ /** A push whose objects, resolved whole, pass a commit before their rows are made: as `tooLarge`. */
26
+ const resolvedTooLarge = (bytes, most) => gitError("RESOURCE_EXHAUSTED", `push's objects take more than ${bytes.toLocaleString("en-US")} bytes whole; one commit holds ${most.toLocaleString("en-US")}`, {
27
+ hint: "Push fewer objects at a time",
28
+ hostHint: "Use packs() storage, which keeps a push's objects in the bucket",
29
+ context: { reason: "too-large" }
30
+ });
31
+ /** An object whose row passes one row's 1 MiB: `RESOURCE_EXHAUSTED`, reason `object-too-large`. */
32
+ const rowTooLarge = (oid, bytes) => gitError("RESOURCE_EXHAUSTED", `object ${oid} takes ${bytes.toLocaleString("en-US")} bytes as a row; one row holds ${limits.valueBytes.toLocaleString("en-US")}`, {
33
+ hostHint: "Use packs() storage, which keeps a large object in the bucket",
34
+ context: { reason: "object-too-large" }
35
+ });
36
+ const malformedPack = (message) => gitError("INVALID_ARGUMENT", `The pack is malformed: ${message}`, { hint: "Push again" });
37
+ /** No pack or retry carries one object past what the storage takes, so the hint is to drop it. */
38
+ const objectPastHint = "Remove the file from history, or track it with Git LFS";
39
+ /** The reader's failures as Git's: a malformed pack, one too large, or a broken body. */
40
+ const readFailure = (error) => {
41
+ if (error instanceof PackError) return error.fault === "too big" ? gitError("RESOURCE_EXHAUSTED", error.message, {
42
+ hint: objectPastHint,
43
+ context: { reason: "object-too-large" }
44
+ }) : malformedPack(error.message);
45
+ if (error instanceof BufferError) return gitError("RESOURCE_EXHAUSTED", error.message, { context: { reason: "too-large" } });
46
+ if (error instanceof PackTransportError) return gitError("UNAVAILABLE", "The push's body broke off", {
47
+ cause: error.cause,
48
+ hint: "Push again"
49
+ });
50
+ return error;
51
+ };
52
+ /**
53
+ * Every entry of the pack, read whole, within `most` inflated bytes in all; a pack whose header
54
+ * counts more than `objects` entries is refused before its first.
55
+ */
56
+ const readEntries = (input, most) => Effect.gen(function* () {
57
+ const entries = [];
58
+ let current;
59
+ let pieces = [];
60
+ let held = 0;
61
+ const sink = {
62
+ begin: ({ count }) => count > input.limits.objects ? Effect.fail(input.tooMany(count)) : Effect.void,
63
+ entry: (entry) => Effect.sync(() => {
64
+ current = entry;
65
+ pieces = [];
66
+ }),
67
+ data: (bytes) => {
68
+ held += bytes.byteLength;
69
+ if (held > most) return Effect.fail(tooLarge(held, most));
70
+ pieces.push(bytes.slice());
71
+ return Effect.void;
72
+ },
73
+ entryEnd: () => Effect.sync(() => {
74
+ if (current !== void 0) entries.push({
75
+ entry: current,
76
+ data: joinedBytes(pieces)
77
+ });
78
+ current = void 0;
79
+ pieces = [];
80
+ })
81
+ };
82
+ const meter = new BufferMeter(readerBytes);
83
+ const source = boundedSource(input.receive.pack, /* @__PURE__ */ new Uint8Array(0), meter);
84
+ return {
85
+ entries,
86
+ bytes: (yield* readPack(source, nativeSha1Hasher(), sink, {
87
+ objectBytes: most,
88
+ deltaBytes: most
89
+ }, meter).pipe(Effect.mapError(readFailure), Effect.ensuring(source.cancel))).bytes
90
+ };
91
+ });
92
+ /** Where a delta waits: its base's offset in the pack, or its base's ID. */
93
+ const waitKey = (entry) => {
94
+ if (entry.base === void 0) return void 0;
95
+ return entry.base.kind === "offset" ? `o:${entry.base.offset}` : `r:${entry.base.oid}`;
96
+ };
97
+ /**
98
+ * Each entry as a whole object: a whole entry hashed, a delta applied to its base, an earlier
99
+ * entry by offset, one by ID in the pack, or one the repo holds. A delta left without its base
100
+ * refuses the pack, and so do objects past `most` bytes in all, as each delta's is made.
101
+ */
102
+ const resolve = Effect.fnUntraced(function* (input, entries, most) {
103
+ const objects = /* @__PURE__ */ new Map();
104
+ const waiting = /* @__PURE__ */ new Map();
105
+ const ready = [];
106
+ let unresolved = 0;
107
+ let made = 0;
108
+ for (const each of entries) {
109
+ const key = waitKey(each.entry);
110
+ if (key === void 0) {
111
+ const type = each.entry.kind;
112
+ const bytes = new Uint8Array(each.data);
113
+ made += bytes.byteLength;
114
+ ready.push({
115
+ offset: each.entry.offset,
116
+ object: {
117
+ oid: yield* objectId({
118
+ type,
119
+ bytes
120
+ }),
121
+ type,
122
+ bytes
123
+ }
124
+ });
125
+ } else {
126
+ waiting.set(key, [...waiting.get(key) ?? [], each]);
127
+ unresolved += 1;
128
+ }
129
+ }
130
+ const settle = Effect.fnUntraced(function* () {
131
+ for (let next = ready.pop(); next !== void 0; next = ready.pop()) {
132
+ const { offset, object } = next;
133
+ if (offset !== void 0) objects.set(object.oid, object);
134
+ const keys = offset === void 0 ? [`r:${object.oid}`] : [`o:${offset}`, `r:${object.oid}`];
135
+ for (const key of keys) {
136
+ for (const delta of waiting.get(key) ?? []) {
137
+ const applied = appliedDelta(object.bytes, delta.data, most);
138
+ if (Result.isFailure(applied)) return yield* Effect.fail(malformedPack(`the delta at ${delta.entry.offset}: ${applied.failure.message}`));
139
+ const bytes = applied.success;
140
+ made += bytes.byteLength;
141
+ if (made > most) return yield* Effect.fail(resolvedTooLarge(made, most));
142
+ const type = object.type;
143
+ const whole = new Uint8Array(bytes);
144
+ ready.push({
145
+ offset: delta.entry.offset,
146
+ object: {
147
+ oid: yield* objectId({
148
+ type,
149
+ bytes: whole
150
+ }),
151
+ type,
152
+ bytes: whole
153
+ }
154
+ });
155
+ unresolved -= 1;
156
+ }
157
+ waiting.delete(key);
158
+ }
159
+ }
160
+ });
161
+ yield* settle();
162
+ const outside = [...waiting.keys()].flatMap((key) => key.startsWith("r:") ? [key.slice(2)] : []);
163
+ const bases = outside.length === 0 ? /* @__PURE__ */ new Map() : yield* input.held(outside);
164
+ for (const base of bases.values()) ready.push({
165
+ offset: void 0,
166
+ object: base
167
+ });
168
+ yield* settle();
169
+ if (unresolved > 0) return yield* Effect.fail(gitError("INVALID_ARGUMENT", `pack has ${unresolved} unresolved deltas`, { hint: "Push again, with every object the pack needs" }));
170
+ return objects;
171
+ });
172
+ /**
173
+ * `INVALID_ARGUMENT` for the first object Git 2.53's fsck refuses a push for: one of the pack's
174
+ * own, or a `.gitmodules` or `.gitattributes` one of its trees names, in the pack or the repo.
175
+ */
176
+ const fscked = Effect.fnUntraced(function* (input, objects) {
177
+ const checked = receiveChecked();
178
+ for (const object of objects.values()) {
179
+ const fault = fsckObject(object, checked);
180
+ if (fault !== void 0) return yield* Effect.fail(fsckRefusal(object.oid, fault));
181
+ const overflow = checkedOverflow(checked);
182
+ if (overflow !== void 0) return yield* Effect.fail(overflow);
183
+ }
184
+ yield* checkedFilesRefused(checked, (oid) => Effect.succeed(objects.get(oid)), input.held);
185
+ });
186
+ /**
187
+ * `INVALID_ARGUMENT` unless every object the pack's own name is in it or the repo, of the type its
188
+ * link says, and `shallowRoot` when a shallow client's commit names parents neither holds. A
189
+ * partial pack may leave out both.
190
+ */
191
+ const connected = Effect.fnUntraced(function* (input, objects) {
192
+ if (input.receive.partial === true) return;
193
+ const shallow = new Set(input.receive.shallow);
194
+ const links = [];
195
+ const parents = [];
196
+ for (const object of objects.values()) {
197
+ const split = shallowLinks(object, yield* Effect.fromResult(linksOf(object)), shallow);
198
+ for (const link of split.needed) links.push(link);
199
+ for (const parent of split.parents) parents.push(parent);
200
+ }
201
+ const outside = (link) => link.oid !== "4b825dc642cb6eb9a060e54bf8d69288fbee4904" && !objects.has(link.oid);
202
+ const asked = new Set([...links, ...parents].flatMap((link) => outside(link) ? [link.oid] : []));
203
+ const held = asked.size === 0 ? /* @__PURE__ */ new Map() : yield* input.held([...asked]);
204
+ const missing = links.find((link) => outside(link) && !held.has(link.oid));
205
+ if (missing !== void 0) return yield* Effect.fail(gitError("INVALID_ARGUMENT", "missing necessary objects", { hint: `Push ${missing.oid} and every object it needs` }));
206
+ if (parents.some((link) => outside(link) && !held.has(link.oid))) return yield* Effect.fail(shallowRoot());
207
+ const typeOf = (oid) => oid === "4b825dc642cb6eb9a060e54bf8d69288fbee4904" ? "tree" : (objects.get(oid) ?? held.get(oid))?.type;
208
+ const wrong = mistyped([...links, ...parents], typeOf);
209
+ if (wrong !== void 0) return yield* Effect.fail(wrong);
210
+ });
211
+ /**
212
+ * A received pack as rows, one per object, for its push's commit: each entry read and resolved,
213
+ * each object checked as Git's fsck checks it and parsed, and every object they name present, of
214
+ * the type its link says. Refused whole, before any row, past `limits` or for an object whose row
215
+ * passes 1 MiB, for a malformed or unresolved pack, an object fsck refuses, or a missing or
216
+ * mistyped object.
217
+ */
218
+ const unpackObjects = Effect.fnUntraced(function* (input) {
219
+ const { receive, limits: limits$1 } = input;
220
+ if (receive.objects > limits$1.objects) return yield* Effect.fail(input.tooMany(receive.objects));
221
+ const { entries, bytes } = yield* readEntries(input, limits$1.bytes);
222
+ const objects = yield* resolve(input, entries, limits$1.bytes);
223
+ yield* fscked(input, objects);
224
+ yield* connected(input, objects);
225
+ const rows = [...objects.values()].map(objectRow);
226
+ for (const row of rows) {
227
+ const valueBytes = rowValueBytes(row.value);
228
+ if (valueBytes > limits.valueBytes) return yield* Effect.fail(rowTooLarge(row.id, valueBytes));
229
+ }
230
+ const rowBytes = rows.reduce((sum, row) => sum + JSON.stringify(row).length, 0);
231
+ if (rowBytes > limits$1.bytes) return yield* Effect.fail(tooLarge(rowBytes, limits$1.bytes));
232
+ return {
233
+ objects: [...objects.values()],
234
+ rows,
235
+ bytes
236
+ };
237
+ });
238
+ export { commitBytes, malformedPack, readFailure, rowTooLarge, unpackObjects };