@ref0/git 0.0.0-stage → 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 (504) 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 +88 -3
  504. package/README.md +0 -3
@@ -0,0 +1,99 @@
1
+ import { hexOf } from "../bytes/hex.mjs";
2
+ import { byOid, isSealed, oidBytes, refuse, sealed, writeIdx } from "./idx.mjs";
3
+ import { writePositions } from "./pos.mjs";
4
+ import * as Effect from "effect/Effect";
5
+ // src/protocol/packs/rev.ts
6
+ /**
7
+ * A pack's reverse index, Git's `.rev` version 1 byte for byte, as `git index-pack --rev-index`
8
+ * writes it and `gitformat-pack` defines it: its `.idx`'s objects in the pack's order, so a
9
+ * reader walking the pack by offset goes from an entry to its object's rank by ID. Big-endian:
10
+ *
11
+ * - `RIDX`, version 1, then hash function 1, SHA-1;
12
+ * - for each entry in the pack's order, its object's rank in the `.idx`, 4 bytes;
13
+ * - the pack's own trailer, then the SHA-1 of every byte before it.
14
+ */
15
+ const magic = [
16
+ 82,
17
+ 73,
18
+ 68,
19
+ 88
20
+ ];
21
+ const version = 1;
22
+ const sha1Function = 1;
23
+ const headerBytes = 12;
24
+ const trailerBytes = 40;
25
+ /** How many bytes a `.rev` of `objects` takes. */
26
+ const packReverseBytes = (objects) => headerBytes + objects * 4 + trailerBytes;
27
+ /**
28
+ * The `.rev` of `sorted`, ranked by ID as their `.idx` ranks them: `ranks`, each rank in the order
29
+ * of its offset in the pack. Refused for two objects at one offset.
30
+ */
31
+ const writeRev = (sorted, ranks, packChecksum) => Effect.gen(function* () {
32
+ const bytes = new Uint8Array(packReverseBytes(sorted.length));
33
+ const view = new DataView(bytes.buffer);
34
+ let previous = -1;
35
+ for (const [at, rank] of ranks.entries()) {
36
+ const offset = sorted[rank]?.offset ?? 0;
37
+ if (offset === previous) return yield* refuse("offset", `two objects are at ${offset}`);
38
+ view.setUint32(headerBytes + at * 4, rank);
39
+ previous = offset;
40
+ }
41
+ bytes.set(magic);
42
+ view.setUint32(4, version);
43
+ view.setUint32(8, sha1Function);
44
+ bytes.set(oidBytes(packChecksum), bytes.byteLength - trailerBytes);
45
+ return sealed(bytes);
46
+ });
47
+ /** A pack's `.rev` as read and checked against its `.idx`. */
48
+ var PackReverse = class {
49
+ #view;
50
+ /** How many objects it lists, as its `.idx` does. */
51
+ count;
52
+ constructor(bytes, count) {
53
+ this.#view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
54
+ this.count = count;
55
+ }
56
+ /** The `.idx` rank of the pack's `at`th entry, in offset order. */
57
+ rankAt(at) {
58
+ return this.#view.getUint32(headerBytes + at * 4);
59
+ }
60
+ };
61
+ /**
62
+ * A `.rev` from its bytes, checked against `index`, the `.idx` of the same pack: its header,
63
+ * version, hash function and length, its own SHA-1, the same pack's trailer, and ranks that name
64
+ * every object once, in strictly ascending offsets, so no two objects share one.
65
+ */
66
+ const readPackReverse = (bytes, index) => Effect.gen(function* () {
67
+ if (bytes.byteLength < headerBytes || magic.some((byte, at) => bytes[at] !== byte)) return yield* refuse("header", "the reverse index doesn't start as one");
68
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
69
+ if (view.getUint32(4) !== version || view.getUint32(8) !== sha1Function) return yield* refuse("version", `reverse index version ${view.getUint32(4)}, hash ${view.getUint32(8)} isn't read`);
70
+ if (bytes.byteLength !== packReverseBytes(index.count)) return yield* refuse("length", `a reverse index of ${index.count} objects isn't ${bytes.byteLength} bytes`);
71
+ if (!isSealed(bytes)) return yield* refuse("checksum", "the reverse index's trailer isn't its SHA-1");
72
+ const end = bytes.byteLength - trailerBytes;
73
+ const pack = hexOf(bytes.subarray(end, end + 20));
74
+ if (pack !== index.packChecksum) return yield* refuse("checksum", `the reverse index is of pack ${pack}, not ${index.packChecksum}`);
75
+ let previous = -1;
76
+ for (let at = 0; at < index.count; at += 1) {
77
+ const rank = view.getUint32(headerBytes + at * 4);
78
+ if (rank >= index.count) return yield* refuse("order", `rank ${rank} isn't an object's`);
79
+ const offset = index.offsetAt(rank);
80
+ if (offset <= previous) return yield* refuse("order", `offset ${offset} isn't past ${previous}`);
81
+ previous = offset;
82
+ }
83
+ return new PackReverse(bytes.slice(), index.count);
84
+ });
85
+ /**
86
+ * The `.idx`, `.rev` and `.pos` of a pack's `objects`, in any order, for the pack whose trailer is
87
+ * `packChecksum`: the first two byte for byte what Git writes for that pack. Every object the pack
88
+ * holds is listed, or the index isn't the pack's.
89
+ */
90
+ const writePackIndex = (objects, packChecksum) => Effect.gen(function* () {
91
+ const sorted = [...objects].sort(byOid);
92
+ const ranks = Array.from(sorted.keys()).sort((a, b) => (sorted[a]?.offset ?? 0) - (sorted[b]?.offset ?? 0));
93
+ return {
94
+ index: yield* writeIdx(sorted, packChecksum),
95
+ reverse: yield* writeRev(sorted, ranks, packChecksum),
96
+ positions: writePositions(ranks, packChecksum)
97
+ };
98
+ });
99
+ export { PackReverse, packReverseBytes, readPackReverse, writePackIndex };
@@ -0,0 +1,10 @@
1
+ import * as Effect from "effect/Effect";
2
+ /**
3
+ * Work's answer: its value when it's done at once, or an Effect when it has I/O to wait on. A
4
+ * plain value is always a success, and a failure is always an Effect, so a caller awaits only an
5
+ * Effect, and work done at once costs it no Effect step. `A` is never an Effect itself, nor a
6
+ * tagged error, which is one: `Effect.isEffect` would read it as the step to await.
7
+ */
8
+ export type Step<A, E = never, R = never> = A | Effect.Effect<A, E, R>;
9
+ /** A step as an Effect, for code that stays one: its own Effect, or one that succeeds with its value. */
10
+ export declare const stepEffect: <A, E = never, R = never>(step: Step<A, E, R>) => Effect.Effect<A, E, R>;
@@ -0,0 +1,12 @@
1
+ import * as Effect from "effect/Effect";
2
+ // src/protocol/packs/step.ts
3
+ /** Whether a step is an Effect to await, rather than a value. */
4
+ const isEffectStep = (step) => Effect.isEffect(step);
5
+ /** A step as an Effect, for code that stays one: its own Effect, or one that succeeds with its value. */
6
+ const stepEffect = (step) => isEffectStep(step) ? step : Effect.succeed(step);
7
+ /**
8
+ * A step, then the step its value leads to: a value at once when both are, and one Effect when
9
+ * either is. The package's own, not exported from `@ref0/git/protocol`.
10
+ */
11
+ const stepFlatMap = (step, then) => isEffectStep(step) ? Effect.flatMap(step, (value) => stepEffect(then(value))) : then(step);
12
+ export { stepEffect, stepFlatMap };
@@ -0,0 +1,12 @@
1
+ import "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ /** Why a pack wasn't written, named. */
4
+ export declare const PackWriteFault: Schema.Literals<readonly ["count", "kind", "oid", "size", "duplicate", "length", "hash", "too big", "time", "cancelled"]>;
5
+ export type PackWriteFault = typeof PackWriteFault.Type;
6
+ declare const PackWriteError_base: Schema.Class<PackWriteError, Schema.TaggedStruct<"PackWriteError", {
7
+ readonly fault: Schema.Literals<readonly ["count", "kind", "oid", "size", "duplicate", "length", "hash", "too big", "time", "cancelled"]>;
8
+ readonly message: Schema.String;
9
+ }>, import("effect/Cause").YieldableError>;
10
+ /** A pack the writer refused to write, or to go on writing, for its `fault`. */
11
+ export declare class PackWriteError extends PackWriteError_base {}
12
+ export {};
@@ -0,0 +1,27 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ // src/protocol/packs/write-error.ts
4
+ /** Why a pack wasn't written, named. */
5
+ const PackWriteFault = Schema.Literals([
6
+ "count",
7
+ "kind",
8
+ "oid",
9
+ "size",
10
+ "duplicate",
11
+ "length",
12
+ "hash",
13
+ "too big",
14
+ "time",
15
+ "cancelled"
16
+ ]);
17
+ /** A pack the writer refused to write, or to go on writing, for its `fault`. */
18
+ var PackWriteError = class extends Schema.TaggedError()("PackWriteError", {
19
+ fault: PackWriteFault,
20
+ message: Schema.String
21
+ }) {};
22
+ /** A writing refused for `fault`. */
23
+ const refuseWrite = (fault, message) => Effect.fail(new PackWriteError({
24
+ fault,
25
+ message
26
+ }));
27
+ export { PackWriteError, PackWriteFault, refuseWrite };
@@ -0,0 +1,157 @@
1
+ import { ObjectType } from "../../contracts/objects.mjs";
2
+ import { Oid } from "../../contracts/ids.mjs";
3
+ import { BufferError, BufferMeter } from "../bytes/buffers.mjs";
4
+ import { DeflateError } from "../bytes/deflate.mjs";
5
+ import { IndexedObject } from "./idx.mjs";
6
+ import { PackEnd, PackParts } from "./parts.mjs";
7
+ import { PackHasher } from "./reader.mjs";
8
+ import { PackWriteError } from "./write-error.mjs";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Exit from "effect/Exit";
11
+ /**
12
+ * A Git pack written as it streams, never held whole: PACK version 2, its count, then each
13
+ * object whole, as Git's `gitformat-pack` defines an undeltified entry, its type and inflated
14
+ * size as a varint, then its own zlib member, and last a SHA-1 of every byte before it. No entry
15
+ * it writes itself is a delta, so none needs another of the pack as its base. Objects come from a source a
16
+ * page at a time, and each object's body a range at a time, so what the writer retains, counted
17
+ * by a `BufferMeter`, never grows with the pack's length, its count or its objects' sizes. An
18
+ * object up to `wholeObjectBytes` is read whole and deflated in one call, with nothing awaited; a
19
+ * larger one is deflated as it streams.
20
+ *
21
+ * Every object written whole is hashed as Git names it as it goes, and the trailer is written only
22
+ * once every object matched its ID and length: a pack whose source lied ends with no trailer, so
23
+ * no receiver takes it. Each entry's offset and CRC-32 are handed out as it ends, so a caller can
24
+ * write the pack's `.idx`, `.rev` and `.pos` with `writePackIndex` without reading it again. The writer
25
+ * never retries; a caller that tries again starts at byte zero.
26
+ *
27
+ * A source may hand an object's stored entry instead, through `copy`, as Git's pack-objects reuses
28
+ * one: its bytes go out as they are, its header and its zlib member or delta with them, neither
29
+ * inflated nor deflated, so the writer can't hash it. Checking a copied entry is the source's: it
30
+ * fails a read rather than hand over bytes it hasn't checked, and the trailer is never written.
31
+ */
32
+ /** One object a pack holds: its ID, its kind and its body's length. */
33
+ export interface PackObject {
34
+ readonly oid: Oid;
35
+ readonly kind: ObjectType;
36
+ readonly size: number;
37
+ }
38
+ /**
39
+ * An object's entry as another pack stores it, `bytes` long from its header to its member's end,
40
+ * copied a range at a time. A delta's base must be an object the same pack sends before it.
41
+ */
42
+ export interface PackCopy<E, R> {
43
+ readonly bytes: number;
44
+ /**
45
+ * The entry's bytes from `at`: at least one, and none past `bytes`. Each is counted on the meter
46
+ * by its whole buffer until the next, as an object's body is.
47
+ */
48
+ readonly read: (at: number) => Effect.Effect<Uint8Array<ArrayBuffer>, E, R>;
49
+ }
50
+ /**
51
+ * Where a pack's objects come from: exactly `count` of them, in order, a page at a time, and each
52
+ * object's body a range at a time. Both are repeatable: a second write of the same source reads
53
+ * the same objects in the same order and the same bytes. Uniqueness is the source's: a page with
54
+ * an ID twice, or an ID of the page before, is refused, but no set of every ID is kept.
55
+ */
56
+ export interface PackObjects<E, R> {
57
+ readonly count: number;
58
+ /**
59
+ * At most `most` objects from the `from`th: fewer only at the end. Asked once more from `count`
60
+ * when the last is written, which a source of exactly `count` answers with none.
61
+ */
62
+ readonly page: (from: number, most: number) => Effect.Effect<ReadonlyArray<PackObject>, E, R>;
63
+ /**
64
+ * Bytes of `object`'s body from `at`: at least one, and none past its size. Each is counted on
65
+ * the meter by its whole buffer until the next, so a small view of a large one may not fit.
66
+ */
67
+ readonly read: (object: PackObject, at: number) => Effect.Effect<Uint8Array<ArrayBuffer>, E, R>;
68
+ /** Asked once every object is written and checked, before the trailer: fails to withhold it. */
69
+ readonly end: Effect.Effect<void, E, R>;
70
+ /**
71
+ * The entry to copy for `object` as it's reached, or `undefined` to write it whole from `read`.
72
+ * Asked once per object; a source that answers checks the entry's bytes as it reads them.
73
+ */
74
+ readonly copy?: (object: PackObject) => PackCopy<E, R> | undefined;
75
+ }
76
+ /**
77
+ * Where a pack's bytes go, each write awaited before the next, so a slow output slows the write.
78
+ * A piece is the writer's own buffer, good only until the call returns: an output that keeps it
79
+ * copies it.
80
+ */
81
+ export interface PackOutput<E, R> {
82
+ readonly write: (bytes: Uint8Array) => Effect.Effect<void, E, R>;
83
+ }
84
+ /** A SHA-1 of its own, and its letting go at once after a failure: one per pack, one per object. */
85
+ export interface PackDigest<E, R> {
86
+ readonly hasher: PackHasher<E, R>;
87
+ readonly abort: () => void;
88
+ }
89
+ /** A pack's limits: its bytes, header to trailer, one object's body, and the time it may take. */
90
+ export interface PackWriteLimits {
91
+ readonly packBytes: number;
92
+ /** The largest body written whole: a copied entry's is never inflated, so has no such bound. */
93
+ readonly objectBytes: number;
94
+ readonly elapsedMillis: number;
95
+ /**
96
+ * The bound a refusal for time names, when `elapsedMillis` is what's left of a larger one, such
97
+ * as a fetch's past its plan; `elapsedMillis` when absent.
98
+ */
99
+ readonly namedMillis?: number;
100
+ }
101
+ /** What a written pack came to. */
102
+ export interface PackWritten {
103
+ readonly count: number;
104
+ /** Its bytes, header to trailer. */
105
+ readonly bytes: number;
106
+ /** Its trailer, as hex. */
107
+ readonly checksum: Oid;
108
+ /** Its objects' bodies' bytes, before compression. */
109
+ readonly bodyBytes: number;
110
+ /** The source's reads: pages and ranges. */
111
+ readonly pages: number;
112
+ readonly ranges: number;
113
+ /** The most bytes its writing retained at once, as the meter counted them. */
114
+ readonly retainedMost: number;
115
+ }
116
+ /** The writer's output buffer, and the most bytes it hands its compressor at once. */
117
+ export declare const packPieceBytes: number;
118
+ /** Objects a page asks of its source at a time. */
119
+ export declare const packPageObjects = 64;
120
+ /** What one object of a page is counted as holding: its ID, kind and size, with room to spare. */
121
+ export declare const packObjectBytes = 512;
122
+ /**
123
+ * An undeltified entry's header: its type in bits 4 to 6 of the first byte, its size's low four
124
+ * bits below them, then the rest of its size seven bits a byte, low first, each byte but the
125
+ * last with its top bit set. Sizes past 32 bits are split by arithmetic, never by `>>>`.
126
+ */
127
+ export declare const entryHeader: (kind: ObjectType, size: number) => Uint8Array<ArrayBuffer>;
128
+ /**
129
+ * Writes the pack of `objects` to `output`, hashing every byte before it's written, each object
130
+ * checked against its ID as it goes, within `limits` and the meter's ceiling. Each object's
131
+ * compressor and digest is let go before the next starts, and every one on any failure or
132
+ * interruption, without waiting on any of them. `placed`, if given, is told each object once its
133
+ * entry is written and its ID checked, with its offset in the pack and its entry's CRC-32, so the
134
+ * caller can index it. `parts`, if given, counts where its time goes, and what it had written and
135
+ * how it ended however it ends.
136
+ */
137
+ export declare const writePack: <SE, SR, OE, OR, HE, HR>(objects: PackObjects<SE, SR>, output: PackOutput<OE, OR>, digest: () => PackDigest<HE, HR>, limits: PackWriteLimits, meter: BufferMeter, placed?: (object: IndexedObject) => void, parts?: PackParts) => Effect.Effect<PackWritten, PackWriteError | BufferError | DeflateError | SE | OE | HE, SR | OR | HR>;
138
+ /**
139
+ * How a writing ended, as its parts keep it: `written`, the writer's fault, `failed` for any other
140
+ * failure, or `interrupted`.
141
+ */
142
+ export declare const packEnd: (exit: Exit.Exit<unknown, unknown>) => PackEnd;
143
+ /** A pack's bytes as a stream, and what its writing came to once the stream is closed. */
144
+ export interface PackStream<A, E> {
145
+ readonly stream: ReadableStream<Uint8Array>;
146
+ readonly done: Effect.Effect<A, E | PackWriteError>;
147
+ }
148
+ /**
149
+ * A pack's bytes as a stream someone pulls, such as a push's body: `write` runs in a fiber of
150
+ * its own, each piece copied and queued only once the stream asks for one, so at most one piece
151
+ * waits in its queue and one in the writer. Cancelling the stream interrupts the writing, its
152
+ * pending reads and finalizers with it. `done` answers what the writing came to once the last
153
+ * byte is queued and the stream closed, or how it failed; an interrupted writing fails as
154
+ * `cancelled`. The fiber outlives the effect that made the stream, so a caller can hand the
155
+ * stream on and await `done` later; one nobody reads stops at `write`'s own time bound.
156
+ */
157
+ export declare const packStream: <A, E, R>(write: (output: PackOutput<never, never>) => Effect.Effect<A, E, R>, meter: BufferMeter) => Effect.Effect<PackStream<A, E>, BufferError, R>;
@@ -0,0 +1,353 @@
1
+ import { allotOrFail, allotScoped, capacityOf } from "../bytes/buffers.mjs";
2
+ import { crc32Update } from "../bytes/crc32.mjs";
3
+ import { deflateWhole, deflatedMost, deflaterBytes, memberDeflater } from "../bytes/deflate.mjs";
4
+ import { hexOf } from "../bytes/hex.mjs";
5
+ import { isOid } from "../bytes/text.mjs";
6
+ import { isObjectType, objectHeader } from "../objects/object.mjs";
7
+ import { PackParts } from "./parts.mjs";
8
+ import { PackWriteError, refuseWrite } from "./write-error.mjs";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Option from "effect/Option";
11
+ import * as Cause from "effect/Cause";
12
+ import * as Exit from "effect/Exit";
13
+ import * as Hex from "effect/encoding/Hex";
14
+ import * as Clock from "effect/Clock";
15
+ import * as Fiber from "effect/Fiber";
16
+ import * as Scheduler from "effect/Scheduler";
17
+ // src/protocol/packs/writer.ts
18
+ /** The writer's output buffer, and the most bytes it hands its compressor at once. */
19
+ const packPieceBytes = 65536;
20
+ /**
21
+ * The steps taken between turns of the event loop, each a timer's, so an interruption gets a turn,
22
+ * and between looks at the clock against the writer's time bound: a step is an object begun, or a
23
+ * piece of at most `packPieceBytes` of its body read or deflated, so both come at least every MiB
24
+ * and every 16 objects, however small. An object deflated whole waits on no compressor, only on
25
+ * its source and digest, which resume as microtasks, so among such objects the turn is the only
26
+ * one a timer gets. The writing's own steps resume as microtasks, never timers: in workerd a
27
+ * timer's turn costs milliseconds, which at one a piece held a pack to 3 MB/s. A timer for the
28
+ * bound alone isn't enough: in workerd one never fired while 1,500 tiny objects were written, the
29
+ * writing always ready to go on, so the writer looks at the clock itself.
30
+ */
31
+ const turnSteps = 16;
32
+ /** Objects a page asks of its source at a time. */
33
+ const packPageObjects = 64;
34
+ /** What one object of a page is counted as holding: its ID, kind and size, with room to spare. */
35
+ const packObjectBytes = 512;
36
+ /** A PACK's count is four bytes. */
37
+ const mostCount = 2 ** 32 - 1;
38
+ /** Each kind's type number in an entry's header. */
39
+ const typeNumbers = {
40
+ commit: 1,
41
+ tree: 2,
42
+ blob: 3,
43
+ tag: 4
44
+ };
45
+ /**
46
+ * An undeltified entry's header: its type in bits 4 to 6 of the first byte, its size's low four
47
+ * bits below them, then the rest of its size seven bits a byte, low first, each byte but the
48
+ * last with its top bit set. Sizes past 32 bits are split by arithmetic, never by `>>>`.
49
+ */
50
+ const entryHeader = (kind, size) => {
51
+ const bytes = [];
52
+ let rest = Math.floor(size / 16);
53
+ let byte = typeNumbers[kind] << 4 | size % 16;
54
+ while (rest > 0) {
55
+ bytes.push(byte | 128);
56
+ byte = rest % 128;
57
+ rest = Math.floor(rest / 128);
58
+ }
59
+ bytes.push(byte);
60
+ return Uint8Array.from(bytes);
61
+ };
62
+ /**
63
+ * `object`'s ID, kind and size, checked before its entry is written; its size against
64
+ * `objectBytes` only when it's written whole, since a copied entry's body is never inflated.
65
+ */
66
+ const checkObject = (object, limits, copying) => {
67
+ if (!isOid(object.oid)) return refuseWrite("oid", `${object.oid} isn't a SHA-1 ID`);
68
+ if (!isObjectType(object.kind)) return refuseWrite("kind", `${object.oid} is a ${String(object.kind)}`);
69
+ if (!Number.isSafeInteger(object.size) || object.size < 0) return refuseWrite("size", `${object.oid}'s size ${object.size} isn't a byte count`);
70
+ if (!copying && object.size > limits.objectBytes) return refuseWrite("too big", `${object.oid} is ${object.size} bytes, past ${limits.objectBytes}`);
71
+ return Effect.void;
72
+ };
73
+ /**
74
+ * Writes the pack of `objects` to `output`, hashing every byte before it's written, each object
75
+ * checked against its ID as it goes, within `limits` and the meter's ceiling. Each object's
76
+ * compressor and digest is let go before the next starts, and every one on any failure or
77
+ * interruption, without waiting on any of them. `placed`, if given, is told each object once its
78
+ * entry is written and its ID checked, with its offset in the pack and its entry's CRC-32, so the
79
+ * caller can index it. `parts`, if given, counts where its time goes, and what it had written and
80
+ * how it ended however it ends.
81
+ */
82
+ const writePack = (objects, output, digest, limits, meter, placed, parts = new PackParts()) => {
83
+ const live = {
84
+ pack: void 0,
85
+ object: void 0
86
+ };
87
+ const letGo = Effect.sync(() => {
88
+ live.pack?.abort();
89
+ live.object?.abort();
90
+ meter.free("output");
91
+ meter.free("page");
92
+ });
93
+ return Effect.gen(function* () {
94
+ const count = objects.count;
95
+ if (!Number.isSafeInteger(count) || count < 0 || count > mostCount) return yield* refuseWrite("count", `a pack can't count ${count} objects`);
96
+ yield* allotOrFail(meter, "output", packPieceBytes);
97
+ yield* allotOrFail(meter, "page", 32768);
98
+ const pack = digest();
99
+ live.pack = pack;
100
+ const out = new Uint8Array(packPieceBytes);
101
+ let filled = 0;
102
+ let written = 0;
103
+ let crc = 0;
104
+ let bodyBytes = 0;
105
+ let pages = 0;
106
+ let ranges = 0;
107
+ let sinceTurn = 0;
108
+ const deadline = (yield* Clock.currentTimeMillis) + limits.elapsedMillis;
109
+ /** One step taken; once `turnSteps` are, the time bound checked and a timer's turn taken. */
110
+ const stepped = Effect.suspend(() => {
111
+ sinceTurn += 1;
112
+ if (sinceTurn < turnSteps) return Effect.void;
113
+ sinceTurn = 0;
114
+ return Effect.flatMap(Clock.currentTimeMillis, (now) => now >= deadline ? refuseWrite("time", `the pack took past ${limits.namedMillis ?? limits.elapsedMillis} ms`) : parts.timed("turn", Effect.sleep(0)));
115
+ });
116
+ /** Hashes and writes what the buffer holds, refused if it and the trailer pass the bound. */
117
+ const flush = Effect.gen(function* () {
118
+ if (filled === 0) return;
119
+ if (written + filled + 20 > limits.packBytes) return yield* refuseWrite("too big", `the pack would pass ${limits.packBytes} bytes`);
120
+ const bytes = out.subarray(0, filled);
121
+ yield* parts.timed("pack_hash", pack.hasher.write(bytes));
122
+ yield* parts.timed("output", output.write(bytes));
123
+ written += filled;
124
+ parts.bytes += filled;
125
+ filled = 0;
126
+ });
127
+ /** Buffers `bytes`, folded into the open entry's CRC-32, writing each buffer as it fills. */
128
+ const put = (bytes) => Effect.gen(function* () {
129
+ crc = crc32Update(crc, bytes);
130
+ for (let at = 0; at < bytes.byteLength;) {
131
+ const take = Math.min(packPieceBytes - filled, bytes.byteLength - at);
132
+ out.set(bytes.subarray(at, at + take), filled);
133
+ filled += take;
134
+ at += take;
135
+ if (filled === 65536) yield* flush;
136
+ }
137
+ });
138
+ /** A stored entry's bytes put as they are, each range refused past its length. */
139
+ const copied = (object, copy) => Effect.scoped(Effect.gen(function* () {
140
+ if (!Number.isSafeInteger(copy.bytes) || copy.bytes < 1) return yield* refuseWrite("length", `${object.oid}'s copy is ${copy.bytes} bytes`);
141
+ yield* allotScoped(meter, "range", 0);
142
+ yield* stepped;
143
+ for (let at = 0; at < copy.bytes;) {
144
+ const bytes = yield* parts.timed("body", copy.read(at));
145
+ ranges += 1;
146
+ if (bytes.byteLength === 0 || bytes.byteLength > copy.bytes - at) return yield* refuseWrite("length", `${object.oid}'s copy gave ${bytes.byteLength} bytes at ${at} of ${copy.bytes}`);
147
+ yield* allotOrFail(meter, "range", capacityOf(bytes));
148
+ yield* put(bytes);
149
+ at += bytes.byteLength;
150
+ for (let from = 0; from < bytes.byteLength; from += packPieceBytes) yield* stepped;
151
+ }
152
+ }));
153
+ const head = /* @__PURE__ */ new Uint8Array(12);
154
+ head.set([
155
+ 80,
156
+ 65,
157
+ 67,
158
+ 75,
159
+ 0,
160
+ 0,
161
+ 0,
162
+ 2
163
+ ]);
164
+ new DataView(head.buffer).setUint32(8, count);
165
+ yield* put(head);
166
+ let page = [];
167
+ let before = /* @__PURE__ */ new Set();
168
+ let pageAt = 0;
169
+ for (let index = 0; index < count; index += 1) {
170
+ if (index - pageAt >= page.length) {
171
+ const from = index;
172
+ const most = Math.min(64, count - from);
173
+ const next = yield* parts.timed("page", objects.page(from, most));
174
+ pages += 1;
175
+ if (next.length === 0 || next.length < most && from + next.length < count) return yield* refuseWrite("count", `the source ended at ${from + next.length} of ${count}`);
176
+ if (next.length > most) return yield* refuseWrite("count", `the source gave ${next.length} of ${most} asked`);
177
+ const seen = /* @__PURE__ */ new Set();
178
+ for (const object of next) {
179
+ if (seen.has(object.oid) || before.has(object.oid)) return yield* refuseWrite("duplicate", `${object.oid} is in the pack twice`);
180
+ seen.add(object.oid);
181
+ }
182
+ before = seen;
183
+ page = next;
184
+ pageAt = from;
185
+ }
186
+ const object = page[index - pageAt];
187
+ if (object === void 0) return yield* refuseWrite("count", `no object at ${index}`);
188
+ const copy = objects.copy?.(object);
189
+ yield* checkObject(object, limits, copy !== void 0);
190
+ const offset = written + filled;
191
+ crc = 0;
192
+ if (copy !== void 0) {
193
+ yield* copied(object, copy);
194
+ placed?.({
195
+ oid: object.oid,
196
+ offset,
197
+ crc32: crc
198
+ });
199
+ bodyBytes += object.size;
200
+ parts.objects += 1;
201
+ continue;
202
+ }
203
+ yield* put(entryHeader(object.kind, object.size));
204
+ yield* stepped;
205
+ const named = digest();
206
+ live.object = named;
207
+ yield* parts.timed("object_hash", named.hasher.write(objectHeader(object.kind, object.size)));
208
+ /**
209
+ * The body's range at `at`, refused past its length, hashed as Git names the object. It's
210
+ * counted as `range`, its whole buffer, until the next replaces it or the object ends.
211
+ */
212
+ const range = (at) => Effect.gen(function* () {
213
+ const bytes = yield* parts.timed("body", objects.read(object, at));
214
+ ranges += 1;
215
+ if (bytes.byteLength === 0 || bytes.byteLength > object.size - at) return yield* refuseWrite("length", `${object.oid}'s source gave ${bytes.byteLength} bytes at ${at} of ${object.size}`);
216
+ yield* allotOrFail(meter, "range", capacityOf(bytes));
217
+ yield* parts.timed("object_hash", named.hasher.write(bytes));
218
+ return bytes;
219
+ });
220
+ if (object.size <= 262144) yield* Effect.scoped(Effect.gen(function* () {
221
+ yield* allotScoped(meter, "range", 0);
222
+ yield* allotScoped(meter, "deflater", deflaterBytes);
223
+ yield* allotScoped(meter, "whole", object.size + deflatedMost(object.size));
224
+ const body = new Uint8Array(object.size);
225
+ for (let at = 0; at < object.size;) {
226
+ const bytes = yield* range(at);
227
+ body.set(bytes, at);
228
+ at += bytes.byteLength;
229
+ for (let from = 0; from < bytes.byteLength; from += packPieceBytes) yield* stepped;
230
+ }
231
+ yield* put(yield* parts.timed("deflate", deflateWhole(body)));
232
+ }));
233
+ else yield* Effect.scoped(Effect.gen(function* () {
234
+ yield* allotScoped(meter, "range", 0);
235
+ const member = yield* memberDeflater(meter, put);
236
+ for (let at = 0; at < object.size;) {
237
+ const bytes = yield* range(at);
238
+ for (let from = 0; from < bytes.byteLength; from += packPieceBytes) {
239
+ yield* parts.timed("deflate", member.write(bytes.subarray(from, from + packPieceBytes)));
240
+ yield* stepped;
241
+ }
242
+ at += bytes.byteLength;
243
+ }
244
+ yield* parts.timed("deflate_end", member.finish);
245
+ }));
246
+ const sum = hexOf(yield* parts.timed("object_digest", named.hasher.digest));
247
+ live.object = void 0;
248
+ if (sum !== object.oid) return yield* refuseWrite("hash", `${object.oid}'s bytes hash to ${sum}`);
249
+ placed?.({
250
+ oid: object.oid,
251
+ offset,
252
+ crc32: crc
253
+ });
254
+ bodyBytes += object.size;
255
+ parts.objects += 1;
256
+ }
257
+ const extra = yield* parts.timed("page", objects.page(count, 1));
258
+ pages += 1;
259
+ if (extra.length > 0) return yield* refuseWrite("count", `the source holds more than ${count} objects`);
260
+ yield* objects.end;
261
+ yield* flush;
262
+ const trailer = yield* parts.timed("pack_hash", pack.hasher.digest);
263
+ live.pack = void 0;
264
+ if (written + 20 > limits.packBytes) return yield* refuseWrite("too big", `the pack would pass ${limits.packBytes} bytes`);
265
+ yield* parts.timed("output", output.write(trailer));
266
+ parts.bytes += 20;
267
+ return {
268
+ count,
269
+ bytes: written + 20,
270
+ checksum: Hex.encode(trailer),
271
+ bodyBytes,
272
+ pages,
273
+ ranges,
274
+ retainedMost: meter.most
275
+ };
276
+ }).pipe(Effect.provideService(Scheduler.Scheduler, new Scheduler.MixedScheduler("sync")), Effect.timeoutOrElse({
277
+ duration: limits.elapsedMillis,
278
+ orElse: () => refuseWrite("time", `the pack took past ${limits.namedMillis ?? limits.elapsedMillis} ms`)
279
+ }), Effect.onExit((exit) => Effect.sync(() => {
280
+ parts.ended = packEnd(exit);
281
+ })), Effect.ensuring(letGo));
282
+ };
283
+ /**
284
+ * How a writing ended, as its parts keep it: `written`, the writer's fault, `failed` for any other
285
+ * failure, or `interrupted`.
286
+ */
287
+ const packEnd = (exit) => {
288
+ if (Exit.isSuccess(exit)) return "written";
289
+ const failure = Cause.findErrorOption(exit.cause);
290
+ if (Option.isNone(failure)) return "interrupted";
291
+ return failure.value instanceof PackWriteError ? failure.value.fault : "failed";
292
+ };
293
+ /**
294
+ * A pack's bytes as a stream someone pulls, such as a push's body: `write` runs in a fiber of
295
+ * its own, each piece copied and queued only once the stream asks for one, so at most one piece
296
+ * waits in its queue and one in the writer. Cancelling the stream interrupts the writing, its
297
+ * pending reads and finalizers with it. `done` answers what the writing came to once the last
298
+ * byte is queued and the stream closed, or how it failed; an interrupted writing fails as
299
+ * `cancelled`. The fiber outlives the effect that made the stream, so a caller can hand the
300
+ * stream on and await `done` later; one nobody reads stops at `write`'s own time bound.
301
+ */
302
+ const packStream = (write, meter) => Effect.gen(function* () {
303
+ yield* allotOrFail(meter, "stream", 2 * packPieceBytes);
304
+ let controller;
305
+ let pulled;
306
+ let wake;
307
+ let fiber;
308
+ let cancelled = false;
309
+ const stream = new ReadableStream({
310
+ start: (each) => {
311
+ controller = each;
312
+ },
313
+ pull: () => new Promise((resolve) => {
314
+ pulled = resolve;
315
+ const waking = wake;
316
+ wake = void 0;
317
+ waking?.();
318
+ }),
319
+ cancel: async () => {
320
+ cancelled = true;
321
+ pulled?.();
322
+ if (fiber !== void 0) await Effect.runPromise(Fiber.interrupt(fiber));
323
+ }
324
+ }, { highWaterMark: 1 });
325
+ const demand = Effect.callback((resume) => {
326
+ if (pulled !== void 0) {
327
+ resume(Effect.void);
328
+ return;
329
+ }
330
+ wake = () => resume(Effect.void);
331
+ return Effect.sync(() => {
332
+ wake = void 0;
333
+ });
334
+ });
335
+ const running = yield* Effect.forkDetach(write({ write: (bytes) => Effect.gen(function* () {
336
+ const copy = bytes.slice();
337
+ yield* demand;
338
+ const answer = pulled;
339
+ pulled = void 0;
340
+ if (!cancelled) controller?.enqueue(copy);
341
+ answer?.();
342
+ }) }).pipe(Effect.tap(() => Effect.sync(() => {
343
+ if (!cancelled) controller?.close();
344
+ })), Effect.tapCause((cause) => Effect.sync(() => {
345
+ if (!cancelled) controller?.error(Cause.squash(cause));
346
+ })), Effect.ensuring(Effect.sync(() => meter.free("stream")))));
347
+ fiber = running;
348
+ return {
349
+ stream,
350
+ done: Effect.flatMap(Fiber.await(running), (exit) => Exit.isSuccess(exit) ? Effect.succeed(exit.value) : Cause.hasInterruptsOnly(exit.cause) ? refuseWrite("cancelled", "the pack's stream was cancelled") : Effect.failCause(exit.cause))
351
+ };
352
+ });
353
+ export { entryHeader, packEnd, packObjectBytes, packPageObjects, packPieceBytes, packStream, writePack };