@ref0/git 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (503) hide show
  1. package/dist/LICENSE +202 -0
  2. package/dist/access/private-refs.d.mts +27 -0
  3. package/dist/access/private-refs.mjs +173 -0
  4. package/dist/access.d.mts +2 -0
  5. package/dist/access.mjs +1 -0
  6. package/dist/auth/access-jwt.d.mts +21 -0
  7. package/dist/auth/access-jwt.mjs +102 -0
  8. package/dist/auth/acting.mjs +15 -0
  9. package/dist/auth/authorize.d.mts +5 -0
  10. package/dist/auth/authorize.mjs +292 -0
  11. package/dist/auth/credentials.mjs +57 -0
  12. package/dist/auth/fences.d.mts +5 -0
  13. package/dist/auth/fences.mjs +65 -0
  14. package/dist/auth/grants.mjs +61 -0
  15. package/dist/auth/helpers.d.mts +17 -0
  16. package/dist/auth/helpers.mjs +25 -0
  17. package/dist/auth/host-function.d.mts +4 -0
  18. package/dist/auth/host-function.mjs +69 -0
  19. package/dist/auth/identify.d.mts +6 -0
  20. package/dist/auth/identify.mjs +97 -0
  21. package/dist/auth/token-rows.mjs +100 -0
  22. package/dist/auth/token-text.mjs +66 -0
  23. package/dist/auth/tokens.d.mts +10 -0
  24. package/dist/auth/tokens.mjs +347 -0
  25. package/dist/auth.d.mts +7 -0
  26. package/dist/auth.mjs +6 -0
  27. package/dist/client/answer.mjs +141 -0
  28. package/dist/client/client.d.mts +23 -0
  29. package/dist/client/client.mjs +51 -0
  30. package/dist/client/git-http.mjs +201 -0
  31. package/dist/client/helper-node.mjs +19 -0
  32. package/dist/client/local.mjs +160 -0
  33. package/dist/client/negotiate.mjs +170 -0
  34. package/dist/client/push-upload.mjs +53 -0
  35. package/dist/client/remote-helper.mjs +129 -0
  36. package/dist/client/remote.mjs +398 -0
  37. package/dist/client/run-remote-helper.d.mts +35 -0
  38. package/dist/client/run-remote-helper.mjs +259 -0
  39. package/dist/client/scrub.d.mts +18 -0
  40. package/dist/client/scrub.mjs +38 -0
  41. package/dist/client/transport.d.mts +2 -0
  42. package/dist/client/transport.mjs +211 -0
  43. package/dist/contracts/access.d.mts +87 -0
  44. package/dist/contracts/actors.d.mts +144 -0
  45. package/dist/contracts/blobs.d.mts +38 -0
  46. package/dist/contracts/calls-spent.d.mts +11 -0
  47. package/dist/contracts/calls-spent.mjs +150 -0
  48. package/dist/contracts/client.d.mts +90 -0
  49. package/dist/contracts/commits.d.mts +126 -0
  50. package/dist/contracts/engine.d.mts +134 -0
  51. package/dist/contracts/events.d.mts +276 -0
  52. package/dist/contracts/files.d.mts +75 -0
  53. package/dist/contracts/forks.d.mts +78 -0
  54. package/dist/contracts/grants.d.mts +60 -0
  55. package/dist/contracts/handlers.d.mts +10 -0
  56. package/dist/contracts/ids.d.mts +15 -0
  57. package/dist/contracts/ids.mjs +15 -0
  58. package/dist/contracts/lfs.d.mts +27 -0
  59. package/dist/contracts/merges.d.mts +33 -0
  60. package/dist/contracts/objects.d.mts +645 -0
  61. package/dist/contracts/objects.mjs +54 -0
  62. package/dist/contracts/operations.d.mts +133 -0
  63. package/dist/contracts/promises.d.mts +63 -0
  64. package/dist/contracts/push-uploads.d.mts +44 -0
  65. package/dist/contracts/queue.d.mts +401 -0
  66. package/dist/contracts/refs.d.mts +95 -0
  67. package/dist/contracts/remote.d.mts +50 -0
  68. package/dist/contracts/repos.d.mts +153 -0
  69. package/dist/contracts/result.d.mts +126 -0
  70. package/dist/contracts/result.mjs +34 -0
  71. package/dist/contracts/rules.d.mts +159 -0
  72. package/dist/contracts/server.d.mts +245 -0
  73. package/dist/contracts/services.d.mts +36 -0
  74. package/dist/contracts/services.mjs +13 -0
  75. package/dist/contracts/signin.d.mts +126 -0
  76. package/dist/contracts/store.d.mts +41 -0
  77. package/dist/contracts/sync.d.mts +210 -0
  78. package/dist/contracts/sync.mjs +8 -0
  79. package/dist/contracts/tags.d.mts +50 -0
  80. package/dist/contracts/tags.mjs +6 -0
  81. package/dist/contracts/tokens.d.mts +87 -0
  82. package/dist/contracts/tokens.mjs +15 -0
  83. package/dist/contracts/topics.d.mts +174 -0
  84. package/dist/contracts/trees.d.mts +84 -0
  85. package/dist/contracts/work.d.mts +31 -0
  86. package/dist/core/access.d.mts +22 -0
  87. package/dist/core/access.mjs +262 -0
  88. package/dist/core/ancestry.mjs +235 -0
  89. package/dist/core/clock.mjs +18 -0
  90. package/dist/core/events/deliver.mjs +468 -0
  91. package/dist/core/events/stream.d.mts +19 -0
  92. package/dist/core/events/stream.mjs +290 -0
  93. package/dist/core/forks.mjs +1027 -0
  94. package/dist/core/hooks/post-receive.mjs +204 -0
  95. package/dist/core/hooks/pre-receive.d.mts +5 -0
  96. package/dist/core/hooks/pre-receive.mjs +34 -0
  97. package/dist/core/index-job.mjs +198 -0
  98. package/dist/core/names.mjs +30 -0
  99. package/dist/core/objects/blobs.mjs +60 -0
  100. package/dist/core/objects/commit-writes.mjs +185 -0
  101. package/dist/core/objects/commits.mjs +172 -0
  102. package/dist/core/objects/files.mjs +211 -0
  103. package/dist/core/objects/lines.mjs +42 -0
  104. package/dist/core/objects/merges.mjs +83 -0
  105. package/dist/core/objects/peel.mjs +166 -0
  106. package/dist/core/objects/reading.mjs +284 -0
  107. package/dist/core/objects/tags.mjs +96 -0
  108. package/dist/core/objects/tree-edits.mjs +266 -0
  109. package/dist/core/objects/trees.mjs +229 -0
  110. package/dist/core/objects/writing.mjs +266 -0
  111. package/dist/core/own-writes.mjs +94 -0
  112. package/dist/core/promise.mjs +46 -0
  113. package/dist/core/publish.mjs +142 -0
  114. package/dist/core/push-decide.mjs +206 -0
  115. package/dist/core/push.mjs +1069 -0
  116. package/dist/core/receipts.d.mts +7 -0
  117. package/dist/core/receipts.mjs +234 -0
  118. package/dist/core/ref-conflicts.mjs +27 -0
  119. package/dist/core/refs.mjs +359 -0
  120. package/dist/core/repack.mjs +521 -0
  121. package/dist/core/repos.mjs +752 -0
  122. package/dist/core/rules/changes.mjs +57 -0
  123. package/dist/core/rules/check.mjs +101 -0
  124. package/dist/core/rules/commit-changes.mjs +216 -0
  125. package/dist/core/rules/context.d.mts +9 -0
  126. package/dist/core/rules/context.mjs +120 -0
  127. package/dist/core/rules/define.d.mts +5 -0
  128. package/dist/core/rules/define.mjs +13 -0
  129. package/dist/core/rules/facts.mjs +13 -0
  130. package/dist/core/rules/fetch.d.mts +5 -0
  131. package/dist/core/rules/fetch.mjs +59 -0
  132. package/dist/core/rules/file-globs.mjs +55 -0
  133. package/dist/core/rules/files.mjs +142 -0
  134. package/dist/core/rules/patterns.mjs +23 -0
  135. package/dist/core/rules/protect.d.mts +9 -0
  136. package/dist/core/rules/protect.mjs +116 -0
  137. package/dist/core/seam.d.mts +24 -0
  138. package/dist/core/seam.mjs +41 -0
  139. package/dist/core/sight.mjs +99 -0
  140. package/dist/core/tokens.mjs +95 -0
  141. package/dist/core/view.d.mts +9 -0
  142. package/dist/core/view.mjs +221 -0
  143. package/dist/core/work.mjs +92 -0
  144. package/dist/effect.d.mts +20 -0
  145. package/dist/effect.mjs +18 -0
  146. package/dist/engine/allotted-xdiff.d.mts +4 -0
  147. package/dist/engine/allotted-xdiff.mjs +80 -0
  148. package/dist/engine/attribute-patterns.mjs +163 -0
  149. package/dist/engine/attributes.mjs +226 -0
  150. package/dist/engine/combined.mjs +653 -0
  151. package/dist/engine/commits.mjs +90 -0
  152. package/dist/engine/content.d.mts +4 -0
  153. package/dist/engine/content.mjs +221 -0
  154. package/dist/engine/diff.mjs +49 -0
  155. package/dist/engine/engine.d.mts +25 -0
  156. package/dist/engine/engine.mjs +49 -0
  157. package/dist/engine/failures.d.mts +4 -0
  158. package/dist/engine/failures.mjs +23 -0
  159. package/dist/engine/line-count.mjs +23 -0
  160. package/dist/engine/merge-base-walk.d.mts +2 -0
  161. package/dist/engine/merge-base-walk.mjs +265 -0
  162. package/dist/engine/merge-bases.mjs +27 -0
  163. package/dist/engine/merge-renames.mjs +165 -0
  164. package/dist/engine/merge.mjs +1125 -0
  165. package/dist/engine/parts.d.mts +8 -0
  166. package/dist/engine/parts.mjs +9 -0
  167. package/dist/engine/reads.d.mts +5 -0
  168. package/dist/engine/reads.mjs +105 -0
  169. package/dist/engine/walk.mjs +328 -0
  170. package/dist/engine/xdiff/NOTICE.md +63 -0
  171. package/dist/engine/xdiff/compiled.d.mts +7 -0
  172. package/dist/engine/xdiff/compiled.mjs +9 -0
  173. package/dist/engine/xdiff/embedded.mjs +4 -0
  174. package/dist/engine/xdiff/node.d.mts +7 -0
  175. package/dist/engine/xdiff/node.mjs +10 -0
  176. package/dist/engine/xdiff/upstream/LGPL-2.1 +511 -0
  177. package/dist/engine/xdiff/xdiff.wasm +0 -0
  178. package/dist/engine/xdiff.d.mts +34 -0
  179. package/dist/engine/xdiff.mjs +380 -0
  180. package/dist/engine.d.mts +3 -0
  181. package/dist/engine.mjs +3 -0
  182. package/dist/extend.d.mts +3 -0
  183. package/dist/extend.mjs +1 -0
  184. package/dist/http/answers.mjs +74 -0
  185. package/dist/http/bodies.mjs +143 -0
  186. package/dist/http/core-parts.mjs +252 -0
  187. package/dist/http/fetch-depth.mjs +26 -0
  188. package/dist/http/handler.mjs +94 -0
  189. package/dist/http/node.d.mts +70 -0
  190. package/dist/http/node.mjs +178 -0
  191. package/dist/http/paths.d.mts +9 -0
  192. package/dist/http/paths.mjs +118 -0
  193. package/dist/http/push-uploads.mjs +286 -0
  194. package/dist/http/receive-pack.mjs +235 -0
  195. package/dist/http/upload-pack.mjs +229 -0
  196. package/dist/index.d.mts +46 -0
  197. package/dist/index.mjs +16 -0
  198. package/dist/lfs/calls.mjs +16 -0
  199. package/dist/lfs/locks.mjs +161 -0
  200. package/dist/lfs/objects.mjs +370 -0
  201. package/dist/lfs/pointers.mjs +141 -0
  202. package/dist/lfs/repo.mjs +42 -0
  203. package/dist/lfs/rows.mjs +108 -0
  204. package/dist/lfs/service.mjs +34 -0
  205. package/dist/lfs/upkeep.mjs +162 -0
  206. package/dist/lfs/wire.mjs +102 -0
  207. package/dist/node.d.mts +3 -0
  208. package/dist/node.mjs +3 -0
  209. package/dist/protocol/bytes/buffers.d.mts +38 -0
  210. package/dist/protocol/bytes/buffers.mjs +62 -0
  211. package/dist/protocol/bytes/crc32.d.mts +4 -0
  212. package/dist/protocol/bytes/crc32.mjs +14 -0
  213. package/dist/protocol/bytes/deflate.d.mts +78 -0
  214. package/dist/protocol/bytes/deflate.mjs +175 -0
  215. package/dist/protocol/bytes/errors.d.mts +20 -0
  216. package/dist/protocol/bytes/errors.mjs +19 -0
  217. package/dist/protocol/bytes/hex.mjs +16 -0
  218. package/dist/protocol/bytes/hmac-sha256.mjs +91 -0
  219. package/dist/protocol/bytes/inflate.d.mts +40 -0
  220. package/dist/protocol/bytes/inflate.mjs +109 -0
  221. package/dist/protocol/bytes/joined.d.mts +2 -0
  222. package/dist/protocol/bytes/joined.mjs +25 -0
  223. package/dist/protocol/bytes/sha1-hasher.d.mts +20 -0
  224. package/dist/protocol/bytes/sha1-hasher.mjs +72 -0
  225. package/dist/protocol/bytes/sha1.d.mts +35 -0
  226. package/dist/protocol/bytes/sha1.mjs +409 -0
  227. package/dist/protocol/bytes/sha256.mjs +156 -0
  228. package/dist/protocol/bytes/streams.mjs +11 -0
  229. package/dist/protocol/bytes/text.mjs +19 -0
  230. package/dist/protocol/diff/diff-raw.d.mts +29 -0
  231. package/dist/protocol/diff/diff-raw.mjs +73 -0
  232. package/dist/protocol/diff/patch.mjs +92 -0
  233. package/dist/protocol/diff/paths.mjs +67 -0
  234. package/dist/protocol/diff/read.d.mts +62 -0
  235. package/dist/protocol/diff/read.mjs +342 -0
  236. package/dist/protocol/diff/rename-similarity.mjs +428 -0
  237. package/dist/protocol/diff/text.mjs +12 -0
  238. package/dist/protocol/diff/tree-diff.d.mts +41 -0
  239. package/dist/protocol/diff/tree-diff.mjs +607 -0
  240. package/dist/protocol/framing/band.d.mts +10 -0
  241. package/dist/protocol/framing/band.mjs +16 -0
  242. package/dist/protocol/framing/pkt-line.d.mts +48 -0
  243. package/dist/protocol/framing/pkt-line.mjs +92 -0
  244. package/dist/protocol/objects/checked-blobs.mjs +127 -0
  245. package/dist/protocol/objects/commit.d.mts +25 -0
  246. package/dist/protocol/objects/commit.mjs +138 -0
  247. package/dist/protocol/objects/fsck-gitmodules.mjs +296 -0
  248. package/dist/protocol/objects/fsck-names.mjs +189 -0
  249. package/dist/protocol/objects/fsck.mjs +297 -0
  250. package/dist/protocol/objects/headers.mjs +109 -0
  251. package/dist/protocol/objects/held.mjs +56 -0
  252. package/dist/protocol/objects/iconv.mjs +145 -0
  253. package/dist/protocol/objects/ident.mjs +111 -0
  254. package/dist/protocol/objects/lfs-pointer.d.mts +8 -0
  255. package/dist/protocol/objects/lfs-pointer.mjs +63 -0
  256. package/dist/protocol/objects/links-raw.mjs +89 -0
  257. package/dist/protocol/objects/object-rules.mjs +75 -0
  258. package/dist/protocol/objects/object.d.mts +16 -0
  259. package/dist/protocol/objects/object.mjs +29 -0
  260. package/dist/protocol/objects/tag.d.mts +21 -0
  261. package/dist/protocol/objects/tag.mjs +96 -0
  262. package/dist/protocol/objects/tree.d.mts +43 -0
  263. package/dist/protocol/objects/tree.mjs +162 -0
  264. package/dist/protocol/objects/utf8-verify.mjs +71 -0
  265. package/dist/protocol/packs/delta.d.mts +57 -0
  266. package/dist/protocol/packs/delta.mjs +229 -0
  267. package/dist/protocol/packs/graph.mjs +78 -0
  268. package/dist/protocol/packs/idx.d.mts +54 -0
  269. package/dist/protocol/packs/idx.mjs +274 -0
  270. package/dist/protocol/packs/indexer.d.mts +167 -0
  271. package/dist/protocol/packs/indexer.mjs +507 -0
  272. package/dist/protocol/packs/parts.d.mts +40 -0
  273. package/dist/protocol/packs/parts.mjs +89 -0
  274. package/dist/protocol/packs/pos.mjs +51 -0
  275. package/dist/protocol/packs/reader.d.mts +180 -0
  276. package/dist/protocol/packs/reader.mjs +414 -0
  277. package/dist/protocol/packs/rev.d.mts +32 -0
  278. package/dist/protocol/packs/rev.mjs +99 -0
  279. package/dist/protocol/packs/step.d.mts +10 -0
  280. package/dist/protocol/packs/step.mjs +12 -0
  281. package/dist/protocol/packs/write-error.d.mts +12 -0
  282. package/dist/protocol/packs/write-error.mjs +27 -0
  283. package/dist/protocol/packs/writer.d.mts +157 -0
  284. package/dist/protocol/packs/writer.mjs +353 -0
  285. package/dist/protocol/wire/advertisement.d.mts +72 -0
  286. package/dist/protocol/wire/advertisement.mjs +161 -0
  287. package/dist/protocol/wire/fetch.d.mts +155 -0
  288. package/dist/protocol/wire/fetch.mjs +458 -0
  289. package/dist/protocol/wire/lines.mjs +107 -0
  290. package/dist/protocol/wire/push-uploads.mjs +43 -0
  291. package/dist/protocol/wire/receive-pack.d.mts +71 -0
  292. package/dist/protocol/wire/receive-pack.mjs +157 -0
  293. package/dist/protocol/wire/report-status.d.mts +47 -0
  294. package/dist/protocol/wire/report-status.mjs +119 -0
  295. package/dist/protocol/wire/v2.d.mts +90 -0
  296. package/dist/protocol/wire/v2.mjs +185 -0
  297. package/dist/protocol.d.mts +31 -0
  298. package/dist/protocol.mjs +31 -0
  299. package/dist/queue/advance.mjs +1036 -0
  300. package/dist/queue/callers.mjs +134 -0
  301. package/dist/queue/calls.mjs +1154 -0
  302. package/dist/queue/commit.mjs +85 -0
  303. package/dist/queue/host.d.mts +15 -0
  304. package/dist/queue/host.mjs +88 -0
  305. package/dist/queue/ids.d.mts +5 -0
  306. package/dist/queue/ids.mjs +21 -0
  307. package/dist/queue/lanes.mjs +86 -0
  308. package/dist/queue/limits.mjs +99 -0
  309. package/dist/queue/pages.mjs +76 -0
  310. package/dist/queue/push-option.mjs +62 -0
  311. package/dist/queue/rows.mjs +206 -0
  312. package/dist/queue/schedule.mjs +132 -0
  313. package/dist/queue/search.mjs +315 -0
  314. package/dist/queue/state.mjs +325 -0
  315. package/dist/queue/steps.mjs +317 -0
  316. package/dist/remote-helper.d.mts +3 -0
  317. package/dist/remote-helper.mjs +3 -0
  318. package/dist/rest/api.d.mts +23 -0
  319. package/dist/rest/api.mjs +27 -0
  320. package/dist/rest/blobs.d.mts +58 -0
  321. package/dist/rest/blobs.mjs +41 -0
  322. package/dist/rest/caller.d.mts +102 -0
  323. package/dist/rest/caller.mjs +18 -0
  324. package/dist/rest/client.d.mts +18 -0
  325. package/dist/rest/client.mjs +587 -0
  326. package/dist/rest/commits.d.mts +435 -0
  327. package/dist/rest/commits.mjs +140 -0
  328. package/dist/rest/errors.d.mts +44 -0
  329. package/dist/rest/errors.mjs +186 -0
  330. package/dist/rest/events.d.mts +38 -0
  331. package/dist/rest/events.mjs +74 -0
  332. package/dist/rest/files.d.mts +179 -0
  333. package/dist/rest/files.mjs +92 -0
  334. package/dist/rest/forks.d.mts +205 -0
  335. package/dist/rest/forks.mjs +51 -0
  336. package/dist/rest/handler.d.mts +17 -0
  337. package/dist/rest/handler.mjs +106 -0
  338. package/dist/rest/handlers.d.mts +8 -0
  339. package/dist/rest/handlers.mjs +592 -0
  340. package/dist/rest/listen.d.mts +24 -0
  341. package/dist/rest/listen.mjs +142 -0
  342. package/dist/rest/me.d.mts +55 -0
  343. package/dist/rest/me.mjs +21 -0
  344. package/dist/rest/merges.d.mts +90 -0
  345. package/dist/rest/merges.mjs +39 -0
  346. package/dist/rest/paths.mjs +86 -0
  347. package/dist/rest/queue.d.mts +486 -0
  348. package/dist/rest/queue.mjs +228 -0
  349. package/dist/rest/refs.d.mts +232 -0
  350. package/dist/rest/refs.mjs +86 -0
  351. package/dist/rest/repos.d.mts +223 -0
  352. package/dist/rest/repos.mjs +93 -0
  353. package/dist/rest/tags.d.mts +153 -0
  354. package/dist/rest/tags.mjs +72 -0
  355. package/dist/rest/tokens.d.mts +297 -0
  356. package/dist/rest/tokens.mjs +88 -0
  357. package/dist/rest/topics.d.mts +257 -0
  358. package/dist/rest/topics.mjs +116 -0
  359. package/dist/rest/trees.d.mts +158 -0
  360. package/dist/rest/trees.mjs +118 -0
  361. package/dist/rest/wire.mjs +57 -0
  362. package/dist/rest/work.d.mts +107 -0
  363. package/dist/rest/work.mjs +77 -0
  364. package/dist/rest.d.mts +8 -0
  365. package/dist/rest.mjs +5 -0
  366. package/dist/server/extension.d.mts +14 -0
  367. package/dist/server/extension.mjs +85 -0
  368. package/dist/server/routes.d.mts +25 -0
  369. package/dist/server/routes.mjs +67 -0
  370. package/dist/server/server.d.mts +2 -0
  371. package/dist/server/server.mjs +439 -0
  372. package/dist/signin/codes.mjs +47 -0
  373. package/dist/signin/context.d.mts +9 -0
  374. package/dist/signin/context.mjs +121 -0
  375. package/dist/signin/device.mjs +122 -0
  376. package/dist/signin/forms.mjs +157 -0
  377. package/dist/signin/grants.d.mts +5 -0
  378. package/dist/signin/grants.mjs +257 -0
  379. package/dist/signin/route.mjs +68 -0
  380. package/dist/signin/web.mjs +125 -0
  381. package/dist/signin/wire.d.mts +42 -0
  382. package/dist/signin/wire.mjs +43 -0
  383. package/dist/storage/allotted.mjs +102 -0
  384. package/dist/storage/budget.mjs +96 -0
  385. package/dist/storage/calls.d.mts +18 -0
  386. package/dist/storage/calls.mjs +273 -0
  387. package/dist/storage/clean-up.mjs +124 -0
  388. package/dist/storage/distinct-ids.mjs +39 -0
  389. package/dist/storage/ewah.mjs +97 -0
  390. package/dist/storage/fetch.d.mts +13 -0
  391. package/dist/storage/fetch.mjs +792 -0
  392. package/dist/storage/fsck.mjs +77 -0
  393. package/dist/storage/held-memo.mjs +188 -0
  394. package/dist/storage/index-bitmaps.d.mts +4 -0
  395. package/dist/storage/index-bitmaps.mjs +654 -0
  396. package/dist/storage/index-build.d.mts +15 -0
  397. package/dist/storage/index-build.mjs +1433 -0
  398. package/dist/storage/index-fetch.d.mts +9 -0
  399. package/dist/storage/index-fetch.mjs +756 -0
  400. package/dist/storage/index-files.mjs +232 -0
  401. package/dist/storage/index-graph.d.mts +3 -0
  402. package/dist/storage/index-graph.mjs +1049 -0
  403. package/dist/storage/index-layers.mjs +317 -0
  404. package/dist/storage/index-reach.mjs +216 -0
  405. package/dist/storage/index-remap.d.mts +8 -0
  406. package/dist/storage/index-remap.mjs +592 -0
  407. package/dist/storage/layout.mjs +69 -0
  408. package/dist/storage/lfs-pointers.d.mts +21 -0
  409. package/dist/storage/lfs-pointers.mjs +175 -0
  410. package/dist/storage/link-join.mjs +106 -0
  411. package/dist/storage/links.mjs +105 -0
  412. package/dist/storage/loose.d.mts +15 -0
  413. package/dist/storage/loose.mjs +120 -0
  414. package/dist/storage/memory-budget.d.mts +8 -0
  415. package/dist/storage/memory-budget.mjs +546 -0
  416. package/dist/storage/merge.mjs +416 -0
  417. package/dist/storage/object-rows.d.mts +6 -0
  418. package/dist/storage/object-rows.mjs +211 -0
  419. package/dist/storage/pack-order.d.mts +8 -0
  420. package/dist/storage/pack-order.mjs +779 -0
  421. package/dist/storage/pack-ranges.d.mts +5 -0
  422. package/dist/storage/pack-ranges.mjs +284 -0
  423. package/dist/storage/pack-reads.d.mts +11 -0
  424. package/dist/storage/pack-reads.mjs +990 -0
  425. package/dist/storage/pack-receive.d.mts +11 -0
  426. package/dist/storage/pack-receive.mjs +449 -0
  427. package/dist/storage/packs.d.mts +56 -0
  428. package/dist/storage/packs.mjs +600 -0
  429. package/dist/storage/prune.mjs +506 -0
  430. package/dist/storage/push-allotment.mjs +109 -0
  431. package/dist/storage/push-uploads.mjs +151 -0
  432. package/dist/storage/pushed-commits.mjs +136 -0
  433. package/dist/storage/quarantine.mjs +98 -0
  434. package/dist/storage/raw-ids.mjs +44 -0
  435. package/dist/storage/ready.d.mts +19 -0
  436. package/dist/storage/ready.mjs +328 -0
  437. package/dist/storage/receive-links.mjs +297 -0
  438. package/dist/storage/repack-job.mjs +48 -0
  439. package/dist/storage/repack.d.mts +31 -0
  440. package/dist/storage/repack.mjs +182 -0
  441. package/dist/storage/roots.mjs +42 -0
  442. package/dist/storage/rows.d.mts +3 -0
  443. package/dist/storage/rows.mjs +71 -0
  444. package/dist/storage/shallow.d.mts +5 -0
  445. package/dist/storage/shallow.mjs +128 -0
  446. package/dist/storage/stream-whole.mjs +236 -0
  447. package/dist/storage/unpack.mjs +236 -0
  448. package/dist/storage/visible.mjs +137 -0
  449. package/dist/storage/walk.d.mts +7 -0
  450. package/dist/storage/walk.mjs +170 -0
  451. package/dist/storage/wants.mjs +362 -0
  452. package/dist/store/call-count.d.mts +47 -0
  453. package/dist/store/call-count.mjs +207 -0
  454. package/dist/store/catalogue.d.mts +7 -0
  455. package/dist/store/catalogue.mjs +643 -0
  456. package/dist/store/crossing.mjs +66 -0
  457. package/dist/store/cursor-seal.d.mts +2 -0
  458. package/dist/store/cursor-seal.mjs +85 -0
  459. package/dist/store/errors.d.mts +12 -0
  460. package/dist/store/errors.mjs +129 -0
  461. package/dist/store/git-store.mjs +75 -0
  462. package/dist/store/list-job.mjs +35 -0
  463. package/dist/store/outbox.d.mts +7 -0
  464. package/dist/store/outbox.mjs +295 -0
  465. package/dist/store/queue-jobs.mjs +43 -0
  466. package/dist/store/random.mjs +28 -0
  467. package/dist/store/records.d.mts +4 -0
  468. package/dist/store/records.mjs +192 -0
  469. package/dist/store/ref-rows.d.mts +4 -0
  470. package/dist/store/ref-rows.mjs +30 -0
  471. package/dist/store/repo-record.mjs +100 -0
  472. package/dist/store/reservations.mjs +82 -0
  473. package/dist/store/scopes.mjs +170 -0
  474. package/dist/store/settle.mjs +63 -0
  475. package/dist/store/topic-jobs.mjs +62 -0
  476. package/dist/sync/bound.d.mts +7 -0
  477. package/dist/sync/bound.mjs +29 -0
  478. package/dist/sync/github.d.mts +12 -0
  479. package/dist/sync/github.mjs +297 -0
  480. package/dist/sync/import.d.mts +8 -0
  481. package/dist/sync/import.mjs +154 -0
  482. package/dist/sync/jobs.d.mts +9 -0
  483. package/dist/sync/jobs.mjs +80 -0
  484. package/dist/sync/mirror.d.mts +9 -0
  485. package/dist/sync/mirror.mjs +227 -0
  486. package/dist/sync/publish.d.mts +5 -0
  487. package/dist/sync/publish.mjs +117 -0
  488. package/dist/sync/records.mjs +73 -0
  489. package/dist/sync/smart-http.d.mts +8 -0
  490. package/dist/sync/smart-http.mjs +23 -0
  491. package/dist/sync/step.mjs +334 -0
  492. package/dist/sync/tries.mjs +126 -0
  493. package/dist/sync.d.mts +8 -0
  494. package/dist/sync.mjs +8 -0
  495. package/dist/topics/advance.mjs +554 -0
  496. package/dist/topics/calls.mjs +346 -0
  497. package/dist/topics/directory.mjs +107 -0
  498. package/dist/topics/host.d.mts +11 -0
  499. package/dist/topics/host.mjs +71 -0
  500. package/dist/topics/members.mjs +177 -0
  501. package/dist/topics/rows.mjs +99 -0
  502. package/dist/topics/topic.mjs +126 -0
  503. package/package.json +86 -5
@@ -0,0 +1,654 @@
1
+ import { Sha1 } from "../protocol/bytes/sha1.mjs";
2
+ import { gitError } from "../store/errors.mjs";
3
+ import { bucketCall } from "./calls.mjs";
4
+ import { bitmapOf, bitmapWords, ewahExtent, ewahOf, mostDirty, orEwah } from "./ewah.mjs";
5
+ import "./link-join.mjs";
6
+ import { uploadPartBytes } from "./budget.mjs";
7
+ import { startPut } from "./merge.mjs";
8
+ import { readExactly } from "./pack-ranges.mjs";
9
+ import { readWhole } from "./pack-reads.mjs";
10
+ import * as Effect from "effect/Effect";
11
+ import * as Exit from "effect/Exit";
12
+ // src/storage/index-bitmaps.ts
13
+ /**
14
+ * The reachability index's bitmaps, built from the links the read slices left: each slice's
15
+ * edges file, then a walk for each chosen commit over those edges, oldest first, so a walk stops
16
+ * at a commit already chosen and ORs its bitmap. What it holds is two bitmaps of the repo's
17
+ * positions, a bounded cache of edges files and one of bitmaps already made. Big-endian:
18
+ *
19
+ * `index/<repo>/<build>/edges/<n>`, one read slice's links, scratch:
20
+ * - `R0ED`, then version 1, then the slice's first position, its positions, its sources S and
21
+ * its links L;
22
+ * - each source's position, ascending, then where each one's links start, S + 1 of them, then
23
+ * each link's position, 4 bytes each.
24
+ *
25
+ * `index/<repo>/<build>.bitmaps`:
26
+ * - `R0BM`, then version 1, then the positions N, then the bitmaps K;
27
+ * - each bitmap's EWAH words;
28
+ * - the table, K entries by position ascending: position, graph number or `noNumber`, XOR base
29
+ * or `noBase`, its offset in the file and its length, 4 bytes each;
30
+ * - the SHA-1 of every byte before it.
31
+ *
32
+ * The table's offset is the index row's, since the payloads before it are written as they're
33
+ * made.
34
+ */
35
+ const lost = (message) => gitError("DATA_LOSS", message);
36
+ /**
37
+ * A remap's own check that its merge is incomplete, an object the merged pack doesn't place: the
38
+ * pack may be missing it, so a remap never declines on one and commits that merge, as it does on
39
+ * a stored file lost or corrupt. It fails the step.
40
+ */
41
+ const mergeIncomplete = (message) => gitError("DATA_LOSS", message, { context: { reason: "merge-incomplete" } });
42
+ /** Whether `error` is `mergeIncomplete`'s. */
43
+ const isMergeIncomplete = (error) => error.code === "DATA_LOSS" && error.context?.reason === "merge-incomplete";
44
+ /** A bitmap whose commit its copy's move gives no position. */
45
+ const moved = (position) => mergeIncomplete(`The bitmap at ${position} has no position where it's copied to`);
46
+ const edgesMagic = [
47
+ 82,
48
+ 48,
49
+ 69,
50
+ 68
51
+ ];
52
+ const bitmapsMagic = [
53
+ 82,
54
+ 48,
55
+ 66,
56
+ 77
57
+ ];
58
+ const edgesHeaderBytes = 24;
59
+ /** A tip that is no commit has no graph number. */
60
+ const noNumber = 4294967295;
61
+ /** A bitmap kept whole, not as the XOR of another. */
62
+ const noBase = 4294967295;
63
+ /**
64
+ * A slice's edges file from its links and their joined `targets`, those a shallow commit lacks
65
+ * left out: what it covers, and its bytes.
66
+ */
67
+ const edgesFileOf = (key, first, positions, links, targets) => {
68
+ let kept = 0;
69
+ for (const target of targets) if (target !== 4294967295) kept += 1;
70
+ const sources = links.sources;
71
+ const bytes = new Uint8Array(edgesHeaderBytes + sources * 8 + 4 + kept * 4);
72
+ const view = new DataView(bytes.buffer);
73
+ bytes.set(edgesMagic);
74
+ view.setUint32(4, 1);
75
+ view.setUint32(8, first);
76
+ view.setUint32(12, positions);
77
+ view.setUint32(16, sources);
78
+ view.setUint32(20, kept);
79
+ const starts = edgesHeaderBytes + sources * 4;
80
+ const ends = starts + (sources + 1) * 4;
81
+ let link = 0;
82
+ for (let source = 0; source < sources; source += 1) {
83
+ view.setUint32(edgesHeaderBytes + source * 4, links.positionOf(source));
84
+ view.setUint32(starts + source * 4, link);
85
+ const [from, to] = links.linksOf(source);
86
+ for (let at = from; at < to; at += 1) {
87
+ const target = targets[at] ?? 4294967295;
88
+ if (target === 4294967295) continue;
89
+ view.setUint32(ends + link * 4, target);
90
+ link += 1;
91
+ }
92
+ }
93
+ view.setUint32(starts + sources * 4, link);
94
+ return {
95
+ slice: {
96
+ key,
97
+ first,
98
+ positions,
99
+ sources,
100
+ links: kept
101
+ },
102
+ bytes
103
+ };
104
+ };
105
+ /** The bytes `slice`'s edges file takes. */
106
+ const edgesBytesOf = (slice) => edgesHeaderBytes + slice.sources * 8 + 4 + slice.links * 4;
107
+ const wordsOf = (bytes, at, count) => {
108
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
109
+ return Uint32Array.from({ length: count }, (_, each) => view.getUint32(at + each * 4));
110
+ };
111
+ /**
112
+ * `slice`'s edges file, checked whole before a walk trusts it: its header, its sources ascending
113
+ * within the slice, its starts from 0 to its links, never falling, and each link a position of
114
+ * the repo's `positions`. Anything else is `undefined`.
115
+ */
116
+ const parseEdges = (slice, bytes, positions) => {
117
+ const { sources, links } = slice;
118
+ if (bytes.byteLength !== edgesBytesOf(slice)) return void 0;
119
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
120
+ const header = [
121
+ view.getUint32(4),
122
+ view.getUint32(8),
123
+ view.getUint32(12),
124
+ view.getUint32(16),
125
+ view.getUint32(20)
126
+ ];
127
+ const expected = [
128
+ 1,
129
+ slice.first,
130
+ slice.positions,
131
+ sources,
132
+ links
133
+ ];
134
+ if (edgesMagic.some((byte, at) => bytes[at] !== byte) || header.some((v, at) => v !== expected[at])) return void 0;
135
+ const starts = edgesHeaderBytes + sources * 4;
136
+ const targets = starts + (sources + 1) * 4;
137
+ let last = -1;
138
+ for (let source = 0; source < sources; source += 1) {
139
+ const position = view.getUint32(edgesHeaderBytes + source * 4);
140
+ if (position <= last || position >= slice.first + slice.positions || position < slice.first) return void 0;
141
+ last = position;
142
+ }
143
+ if (view.getUint32(starts) !== 0 || view.getUint32(starts + sources * 4) !== links) return void 0;
144
+ for (let source = 0; source < sources; source += 1) if (view.getUint32(starts + source * 4) > view.getUint32(starts + (source + 1) * 4)) return void 0;
145
+ for (let link = 0; link < links; link += 1) if (view.getUint32(targets + link * 4) >= positions) return void 0;
146
+ return {
147
+ view,
148
+ sources,
149
+ starts,
150
+ targets,
151
+ bytes: bytes.byteLength
152
+ };
153
+ };
154
+ /**
155
+ * Every slice's edges, by position, each file read whole when a walk first needs it and kept
156
+ * while `room` bytes hold it, the least lately used let go first, before the next is read. A
157
+ * walk asks `links`, which answers at once from a file it holds, or `false` with `missing` set,
158
+ * for `load` to read it. `room` is `most`, or the largest file when one is larger: a walk needs
159
+ * one file held, and its caller allots `room`.
160
+ */
161
+ var EdgeFiles = class {
162
+ #bucket;
163
+ #slices;
164
+ #positions;
165
+ #held = /* @__PURE__ */ new Map();
166
+ #bytes = 0;
167
+ /** What it holds at most. */
168
+ room;
169
+ /** The slice a walk waits for. */
170
+ missing;
171
+ /** Files read, for a test to count. */
172
+ reads = 0;
173
+ constructor(bucket, slices, most, positions) {
174
+ this.#bucket = bucket;
175
+ this.#slices = slices;
176
+ this.#positions = positions;
177
+ this.room = slices.reduce((room, slice) => Math.max(room, edgesBytesOf(slice)), most);
178
+ }
179
+ /** The bytes it holds now, for a test to check against `room`. */
180
+ get held() {
181
+ return this.#bytes;
182
+ }
183
+ #sliceOf(position) {
184
+ let low = 0;
185
+ let high = this.#slices.length;
186
+ while (low < high) {
187
+ const middle = low + high >>> 1;
188
+ const slice = this.#slices[middle];
189
+ if (slice === void 0) return -1;
190
+ if (position < slice.first) high = middle;
191
+ else if (position >= slice.first + slice.positions) low = middle + 1;
192
+ else return middle;
193
+ }
194
+ return -1;
195
+ }
196
+ /** `visit` for each link of the object at `position`; `false` when its file must load first. */
197
+ links(position, visit) {
198
+ const at = this.#sliceOf(position);
199
+ if (at < 0) return true;
200
+ const edges = this.#held.get(at);
201
+ if (edges === void 0) {
202
+ this.missing = at;
203
+ return false;
204
+ }
205
+ this.#held.delete(at);
206
+ this.#held.set(at, edges);
207
+ const { view } = edges;
208
+ let low = 0;
209
+ let high = edges.sources;
210
+ while (low < high) {
211
+ const middle = low + high >>> 1;
212
+ const source = view.getUint32(edgesHeaderBytes + middle * 4);
213
+ if (source === position) {
214
+ const to = view.getUint32(edges.starts + (middle + 1) * 4);
215
+ for (let link = view.getUint32(edges.starts + middle * 4); link < to; link += 1) visit(view.getUint32(edges.targets + link * 4));
216
+ return true;
217
+ }
218
+ if (source < position) low = middle + 1;
219
+ else high = middle;
220
+ }
221
+ return true;
222
+ }
223
+ /**
224
+ * The file `missing` names, read whole once the least lately used are let go for its room, so
225
+ * what it holds never passes `room`, even as it reads.
226
+ */
227
+ load = Effect.suspend(() => {
228
+ const at = this.missing;
229
+ const slice = at === void 0 ? void 0 : this.#slices[at];
230
+ if (at === void 0 || slice === void 0) return Effect.void;
231
+ const size = edgesBytesOf(slice);
232
+ for (const [held, kept] of this.#held) {
233
+ if (this.#bytes + size <= this.room) break;
234
+ this.#held.delete(held);
235
+ this.#bytes -= kept.bytes;
236
+ }
237
+ return Effect.flatMap(readWhole(this.#bucket, slice.key), (bytes) => this.#keep(at, slice, bytes));
238
+ });
239
+ #keep(at, slice, bytes) {
240
+ const edges = bytes === void 0 ? void 0 : parseEdges(slice, bytes, this.#positions);
241
+ if (edges === void 0) return Effect.fail(lost(`${slice.key} isn't the edges file the build wrote`));
242
+ this.reads += 1;
243
+ this.#held.set(at, edges);
244
+ this.#bytes += edges.bytes;
245
+ this.missing = void 0;
246
+ return Effect.void;
247
+ }
248
+ };
249
+ /** `from` ORed into `into`; `from` may be shorter, its positions past its own unset. */
250
+ const orInto = (from, into) => {
251
+ const length = Math.min(from.length, into.length);
252
+ for (let at = 0; at < length; at += 1) into[at] = ((into[at] ?? 0) | (from[at] ?? 0)) >>> 0;
253
+ };
254
+ /** What the writer turns words into bytes through, a piece at a time. */
255
+ const pieceBytes = 65536;
256
+ /**
257
+ * The most words an EWAH of `words` words takes: each marker but the first covers a clean word
258
+ * or ends a run of `mostDirty` dirty ones, so it never outgrows its bitmap by more than those.
259
+ */
260
+ const ewahMostWords = (words) => words + 2 + Math.ceil(words / mostDirty);
261
+ /** The most bytes a `.bitmaps` of `count` bitmaps of `positions` takes. */
262
+ const bitmapsMostBytes = (positions, count) => 16 + count * (ewahMostWords(bitmapWords(positions)) * 4 + 20) + 20;
263
+ /**
264
+ * What a walk holds beside its edges and the bitmaps it keeps: its two bitmaps of the positions,
265
+ * the EWAH it makes of one, and the piece it writes through.
266
+ */
267
+ const walkBytes = (positions) => {
268
+ const words = bitmapWords(positions);
269
+ return words * 8 + ewahMostWords(words) * 4 + pieceBytes;
270
+ };
271
+ /**
272
+ * A `.bitmaps` put of `count` bitmaps of `positions`, its header written: each bitmap's EWAH
273
+ * words through one piece, then the table and the SHA-1 once every bitmap is in. A failed write
274
+ * aborts the put; one the caller gives up on it aborts itself, through `abort`.
275
+ */
276
+ const bitmapsPut = (bucket, key, positions, count) => Effect.gen(function* () {
277
+ const put = yield* startPut(bucket, key, { atMost: bitmapsMostBytes(positions, count) });
278
+ yield* Effect.addFinalizer((exit) => Exit.isFailure(exit) ? put.abort : Effect.void);
279
+ const sha = new Sha1();
280
+ const entries = [];
281
+ let offset = 0;
282
+ const write = (bytes) => {
283
+ sha.update(bytes);
284
+ offset += bytes.byteLength;
285
+ return put.write(bytes);
286
+ };
287
+ const head = /* @__PURE__ */ new Uint8Array(16);
288
+ const view = new DataView(head.buffer);
289
+ head.set(bitmapsMagic);
290
+ view.setUint32(4, 1);
291
+ view.setUint32(8, positions);
292
+ view.setUint32(12, count);
293
+ yield* write(head);
294
+ const add = (position, number, ewah) => Effect.gen(function* () {
295
+ entries.push({
296
+ position,
297
+ number,
298
+ base: noBase,
299
+ offset,
300
+ length: ewah.byteLength
301
+ });
302
+ for (let from = 0; from < ewah.length; from += pieceBytes / 4) {
303
+ const length = Math.min(pieceBytes / 4, ewah.length - from);
304
+ const piece = new Uint8Array(length * 4);
305
+ const words = new DataView(piece.buffer);
306
+ for (let at = 0; at < length; at += 1) words.setUint32(at * 4, ewah[from + at] ?? 0);
307
+ yield* write(piece);
308
+ }
309
+ });
310
+ return {
311
+ add,
312
+ finish: Effect.gen(function* () {
313
+ entries.sort((a, b) => a.position - b.position);
314
+ const table = offset;
315
+ const tableBytes = new Uint8Array(entries.length * 20);
316
+ const tableView = new DataView(tableBytes.buffer);
317
+ for (const [at, entry] of entries.entries()) {
318
+ const fields = [
319
+ entry.position,
320
+ entry.number,
321
+ entry.base,
322
+ entry.offset,
323
+ entry.length
324
+ ];
325
+ for (const [field, value] of fields.entries()) tableView.setUint32(at * 20 + field * 4, value);
326
+ }
327
+ yield* write(tableBytes);
328
+ const digest = sha.digest();
329
+ yield* put.write(digest);
330
+ yield* put.finish;
331
+ return {
332
+ count: entries.length,
333
+ table,
334
+ bytes: offset + digest.byteLength
335
+ };
336
+ }),
337
+ abort: put.abort
338
+ };
339
+ });
340
+ /**
341
+ * A bitmap for each of `input.chosen`, oldest first, each the set of positions its object
342
+ * reaches: forward sweeps over the positions, each taking the links of every set position not
343
+ * yet taken, until one sets nothing behind it. A position with a bitmap already made is ORed
344
+ * whole and not walked. The bitmaps go to the bucket as they're made, the table after them.
345
+ */
346
+ const writeBitmaps = (input) => Effect.gen(function* () {
347
+ const { edges, positions, below } = input;
348
+ const words = bitmapWords(positions);
349
+ const order = [...input.chosen].sort((a, b) => a.generation - b.generation || a.position - b.position);
350
+ const count = new Set(order.map((chosen) => chosen.position)).size;
351
+ const atMost = bitmapsMostBytes(positions, count);
352
+ const held = walkBytes(positions) + input.kept + Math.min(atMost, uploadPartBytes) + (below === void 0 ? 0 : words * 4);
353
+ yield* input.allotment.grow(held);
354
+ const put = yield* bitmapsPut(input.bucket, input.key, positions, count);
355
+ const reached = new Uint32Array(words);
356
+ const taken = new Uint32Array(words);
357
+ const made = /* @__PURE__ */ new Map();
358
+ let madeBytes = 0;
359
+ const done = /* @__PURE__ */ new Set();
360
+ let again = false;
361
+ let word = 0;
362
+ const reach = (target) => {
363
+ const at = target >>> 5;
364
+ const bit = 1 << (target & 31);
365
+ if ((reached[at] ?? 0) & bit) return;
366
+ reached[at] = (reached[at] ?? 0) | bit;
367
+ if (at < word) again = true;
368
+ };
369
+ for (const chosen of order) {
370
+ if (done.has(chosen.position)) continue;
371
+ done.add(chosen.position);
372
+ reached.fill(0);
373
+ taken.fill(0);
374
+ reach(chosen.position);
375
+ do {
376
+ again = false;
377
+ for (word = 0; word < words; word += 1) {
378
+ let open = ((reached[word] ?? 0) & ~(taken[word] ?? 0)) >>> 0;
379
+ while (open !== 0) {
380
+ const bit = 31 - Math.clz32(open & -open);
381
+ const position = word * 32 + bit;
382
+ const stored = position === chosen.position ? void 0 : made.get(position);
383
+ if (below !== void 0 && position < below.first) {
384
+ const closed = yield* below.reach(position);
385
+ if (closed === void 0) {
386
+ yield* put.abort;
387
+ input.allotment.shrink(held);
388
+ return;
389
+ }
390
+ orInto(closed, reached);
391
+ orInto(closed, taken);
392
+ } else if (stored !== void 0) {
393
+ orEwah(stored, reached);
394
+ orEwah(stored, taken);
395
+ } else if (!edges.links(position, reach)) {
396
+ yield* edges.load;
397
+ continue;
398
+ }
399
+ taken[word] = (taken[word] ?? 0) | 1 << bit;
400
+ open = ((reached[word] ?? 0) & ~(taken[word] ?? 0)) >>> 0;
401
+ }
402
+ }
403
+ } while (again);
404
+ const ewah = ewahOf(reached);
405
+ yield* put.add(chosen.position, chosen.number, ewah);
406
+ made.set(chosen.position, ewah);
407
+ madeBytes += ewah.byteLength;
408
+ for (const [position, kept] of made) {
409
+ if (madeBytes <= input.kept) break;
410
+ made.delete(position);
411
+ madeBytes -= kept.byteLength;
412
+ }
413
+ }
414
+ const written = yield* put.finish;
415
+ input.allotment.shrink(held);
416
+ return written;
417
+ }).pipe(Effect.scoped);
418
+ /** How many bytes of a layer's `.bitmaps` a merge reads as one range, an entry past it alone. */
419
+ const copyRunBytes = 1048576;
420
+ /**
421
+ * What `copyBitmaps` holds to copy `count` bitmaps over `positions` from files of `from`'s
422
+ * positions: what `eachBitmap` holds of one file, the merged words and their EWAH, the piece it
423
+ * writes through and the put's part. Its lists of the bitmaps are its caller's to charge.
424
+ */
425
+ const copyHeldBytes = (positions, count, from) => {
426
+ const words = bitmapWords(positions);
427
+ const reading = Math.max(0, ...from.map((each) => eachBitmapBytes(each, copyRunBytes)));
428
+ const part = Math.min(bitmapsMostBytes(positions, count), uploadPartBytes);
429
+ return reading + words * 4 + ewahMostWords(words) * 4 + pieceBytes + part;
430
+ };
431
+ /**
432
+ * A layer merge's `.bitmaps` (#596): each of `copied`, read from its layer and written again over
433
+ * the merged layer's `positions`, its bits where they were, or as `move` puts them, and its number
434
+ * the merged graph's. Each
435
+ * layer's are read in runs of `copyRunBytes` through `eachBitmap`, so its reads are its runs, not
436
+ * its bitmaps. It holds one run, its layer's words, the merged words and their EWAH, charged to
437
+ * `allotment` before any is read.
438
+ */
439
+ const copyBitmaps = (input) => Effect.gen(function* () {
440
+ const { positions, copied } = input;
441
+ const words = bitmapWords(positions);
442
+ const byFile = /* @__PURE__ */ new Map();
443
+ for (const each of copied) {
444
+ const of = byFile.get(each.from) ?? [];
445
+ of.push(each);
446
+ byFile.set(each.from, of);
447
+ }
448
+ const held = copyHeldBytes(positions, copied.length, [...byFile.keys()].map((from) => from.positions));
449
+ yield* input.allotment.grow(held);
450
+ const put = yield* bitmapsPut(input.bucket, input.key, positions, copied.length);
451
+ const all = new Uint32Array(words);
452
+ for (const [from, each] of byFile) {
453
+ const numbers = new Map(each.map(({ entry, number }) => [entry.position, number]));
454
+ const entries = each.map(({ entry }) => entry);
455
+ yield* from.eachBitmap(entries, copyRunBytes, (entry, bits) => {
456
+ const { move } = input;
457
+ const position = move === void 0 ? entry.position : move.position(entry.position);
458
+ if (position === void 0) return Effect.fail(moved(entry.position));
459
+ all.fill(0);
460
+ if (move === void 0) all.set(bits.subarray(0, words));
461
+ else move.bits(bits, all);
462
+ return put.add(position, numbers.get(entry.position) ?? 4294967295, ewahOf(all));
463
+ });
464
+ }
465
+ const written = yield* put.finish;
466
+ input.allotment.shrink(held);
467
+ return written;
468
+ }).pipe(Effect.scoped);
469
+ /**
470
+ * What `IndexBitmaps.eachBitmap` holds of a file of `positions`, its runs at most `mostBytes`:
471
+ * a run's bytes, or one EWAH alone past them; the EWAH it decodes from them, a copy; and its
472
+ * array of the file's words.
473
+ */
474
+ const eachBitmapBytes = (positions, mostBytes) => {
475
+ const words = bitmapWords(positions);
476
+ const ewah = ewahMostWords(words) * 4;
477
+ return Math.max(mostBytes, ewah) + ewah + words * 4;
478
+ };
479
+ /** Entries of one `.bitmaps` closer than this are read as one range, the bytes between dropped. */
480
+ const runGapBytes = 262144;
481
+ /**
482
+ * `entries` in runs by offset, each run's next entry starting after the one before it ends, under
483
+ * `runGapBytes` on, and each run's range at most `mostBytes` unless it's one entry alone.
484
+ */
485
+ const runsOf = (entries, mostBytes = Number.POSITIVE_INFINITY) => {
486
+ const runs = [];
487
+ for (const entry of [...entries].sort((a, b) => a.offset - b.offset)) {
488
+ const run = runs[runs.length - 1];
489
+ const [first] = run ?? [];
490
+ const last = run?.[run.length - 1];
491
+ const end = last === void 0 ? 0 : last.offset + last.length;
492
+ const span = first === void 0 ? 0 : entry.offset + entry.length - first.offset;
493
+ if (run !== void 0 && entry.offset >= end && entry.offset - end < 262144 && span <= mostBytes) run.push(entry);
494
+ else runs.push([entry]);
495
+ }
496
+ return runs;
497
+ };
498
+ /**
499
+ * The most runs `runsOf` makes of a file's entries whose payloads end at `table`, each run at
500
+ * most `mostBytes`, a forecast of their reads from the row alone. A run ends at a gap of
501
+ * `runGapBytes` or more, each skipping bytes no other does, so at most `table / runGapBytes` of
502
+ * them; or where the next entry would take it past `mostBytes`, so that run, its gap and the next
503
+ * one's first entry pass `mostBytes`, every byte in at most two such spans: at most
504
+ * `2 * table / mostBytes` of them.
505
+ */
506
+ const runsMost = (table, count, mostBytes = Number.POSITIVE_INFINITY) => Math.min(count, 1 + Math.floor(table / runGapBytes) + (mostBytes === Number.POSITIVE_INFINITY ? 0 : Math.floor(2 * table / mostBytes)));
507
+ /** The `.bitmaps` at `key`, of `positions` and `count` bitmaps, its table at `table`. */
508
+ const openBitmaps = (bucket, key, written) => Effect.gen(function* () {
509
+ const head = yield* readExactly(bucket, key, 0, 16);
510
+ const view = new DataView(head.buffer, head.byteOffset, head.byteLength);
511
+ if (bitmapsMagic.some((byte, at) => head[at] !== byte) || view.getUint32(4) !== 1 || view.getUint32(8) !== written.positions || view.getUint32(12) !== written.count) return yield* Effect.fail(lost(`${key} isn't the ${written.count} bitmaps of ${written.positions}`));
512
+ if (written.table < 16) return yield* Effect.fail(lost(`${key}'s table at ${written.table} is inside its header`));
513
+ const table = yield* readExactly(bucket, key, written.table, written.count * 20);
514
+ yield* readExactly(bucket, key, written.table + written.count * 20, 20);
515
+ const fields = wordsOf(table, 0, written.count * 5);
516
+ const entries = Array.from({ length: written.count }, (_, at) => ({
517
+ position: fields[at * 5] ?? 0,
518
+ number: fields[at * 5 + 1] ?? 0,
519
+ base: fields[at * 5 + 2] ?? 0,
520
+ offset: fields[at * 5 + 3] ?? 0,
521
+ length: fields[at * 5 + 4] ?? 0
522
+ }));
523
+ const mostBytes = ewahMostWords(bitmapWords(written.positions)) * 4;
524
+ for (const [at, entry] of entries.entries()) {
525
+ const before = entries[at - 1];
526
+ if (entry.position >= written.positions || before !== void 0 && entry.position <= before.position || entry.offset < 16 || entry.length === 0 || entry.length % 4 !== 0 || entry.length > mostBytes || entry.offset + entry.length > written.table) return yield* Effect.fail(lost(`${key}'s entry ${at} isn't a bitmap of ${written.positions} before its table`));
527
+ }
528
+ const words = bitmapWords(written.positions);
529
+ const spare = written.positions % 32;
530
+ const xor = lost(`${key} has an XOR bitmap this reader doesn't take`);
531
+ const unread = (entry) => lost(`${key}'s bitmap at ${entry.position} won't read`);
532
+ /**
533
+ * Whether `ewah` is a bitmap of the file's positions: as many words, and no bit at or past
534
+ * the positions, which names no object, so a bitmap with one is refused whole.
535
+ */
536
+ const fits = (ewah) => {
537
+ const extent = ewahExtent(ewah);
538
+ return extent?.words === words && (spare === 0 || extent.last >>> spare === 0);
539
+ };
540
+ const bitmapOfEntry = (entry) => Effect.gen(function* () {
541
+ if (entry.base !== 4294967295) return yield* Effect.fail(xor);
542
+ const bytes = yield* readExactly(bucket, key, entry.offset, entry.length);
543
+ const ewah = wordsOf(bytes, 0, entry.length / 4);
544
+ const bitmap = fits(ewah) ? bitmapOf(ewah, words) : void 0;
545
+ if (bitmap === void 0) return yield* Effect.fail(unread(entry));
546
+ return bitmap;
547
+ });
548
+ /** `run`'s entries ORed into `into`, read as one streamed range: the first that won't read, if any. */
549
+ const orRun = (run, into) => bucketCall(async (signal) => {
550
+ const [first] = run;
551
+ const last = run[run.length - 1];
552
+ if (first === void 0 || last === void 0) return void 0;
553
+ const from = first.offset;
554
+ const body = await bucket.read(key, {
555
+ offset: from,
556
+ length: last.offset + last.length - from
557
+ }, { signal });
558
+ if (body === void 0) return lost(`${key} is missing its bytes from ${from}`);
559
+ const reader = body.getReader();
560
+ let at = from;
561
+ let next = 0;
562
+ let held;
563
+ try {
564
+ for (let read = await reader.read(); !read.done; read = await reader.read()) {
565
+ const chunk = read.value;
566
+ let offset = 0;
567
+ while (offset < chunk.length) {
568
+ const entry = run[next];
569
+ if (entry === void 0) return void 0;
570
+ if (at < entry.offset) {
571
+ const skip = Math.min(entry.offset - at, chunk.length - offset);
572
+ at += skip;
573
+ offset += skip;
574
+ continue;
575
+ }
576
+ const taken = at - entry.offset;
577
+ const length = Math.min(entry.length - taken, chunk.length - offset);
578
+ const whole = taken === 0 && length === entry.length;
579
+ if (!whole) {
580
+ held ??= new Uint8Array(entry.length);
581
+ held.set(chunk.subarray(offset, offset + length), taken);
582
+ }
583
+ at += length;
584
+ offset += length;
585
+ if (at < entry.offset + entry.length) continue;
586
+ const bytes = whole ? chunk.subarray(offset - length, offset) : held;
587
+ held = void 0;
588
+ next += 1;
589
+ const ewah = bytes === void 0 ? void 0 : wordsOf(bytes, 0, entry.length / 4);
590
+ if (ewah === void 0 || !fits(ewah)) return unread(entry);
591
+ orEwah(ewah, into);
592
+ }
593
+ }
594
+ return run[next] === void 0 ? void 0 : lost(`${key} is missing its bytes from ${at}`);
595
+ } finally {
596
+ await reader.cancel();
597
+ }
598
+ });
599
+ const orEntries = (entries, into, atOnce) => Effect.gen(function* () {
600
+ if (into.length < words) return yield* Effect.fail(lost(`${key}'s bitmaps are past what they're ORed into`));
601
+ if (entries.some((entry) => entry.base !== 4294967295)) return yield* Effect.fail(xor);
602
+ const target = into.subarray(0, words);
603
+ const refused = (yield* Effect.forEach(runsOf(entries), (run) => orRun(run, target), { concurrency: atOnce })).find((each) => each !== void 0);
604
+ if (refused !== void 0) return yield* Effect.fail(refused);
605
+ });
606
+ const eachBitmap = (chosen, mostBytes, visit) => Effect.gen(function* () {
607
+ if (chosen.some((entry) => entry.base !== 4294967295)) return yield* Effect.fail(xor);
608
+ const bits = new Uint32Array(words);
609
+ for (const run of runsOf(chosen, mostBytes)) {
610
+ const [first] = run;
611
+ const last = run[run.length - 1];
612
+ if (first === void 0 || last === void 0) continue;
613
+ const span = last.offset + last.length - first.offset;
614
+ const bytes = yield* readExactly(bucket, key, first.offset, span);
615
+ for (const entry of run) {
616
+ const ewah = wordsOf(bytes, entry.offset - first.offset, entry.length / 4);
617
+ bits.fill(0);
618
+ if (!fits(ewah) || !orEwah(ewah, bits)) return yield* Effect.fail(unread(entry));
619
+ yield* visit(entry, bits);
620
+ }
621
+ }
622
+ });
623
+ return {
624
+ positions: written.positions,
625
+ entries,
626
+ bitmapOf: bitmapOfEntry,
627
+ orInto: orEntries,
628
+ eachBitmap
629
+ };
630
+ });
631
+ /** The size of the file at `key`, or `undefined` when there's none. */
632
+ const storedSize = (bucket, key) => Effect.map(bucketCall((signal) => bucket.list(key, void 0, { signal })), (page) => page.items.find((item) => item.key === key)?.size);
633
+ /**
634
+ * What a `.bitmaps` of `size` bytes already at `key` holds, for a try that finds it there after
635
+ * the one that wrote it died: its count from its header, its table from its size, and opened to
636
+ * check both.
637
+ */
638
+ const storedBitmaps = (bucket, key, positions, size) => Effect.gen(function* () {
639
+ const head = yield* readExactly(bucket, key, 0, 16);
640
+ const count = new DataView(head.buffer, head.byteOffset, head.byteLength).getUint32(12);
641
+ const table = size - 20 - count * 20;
642
+ if (table < 16) return yield* Effect.fail(lost(`${key} is too short for its ${count} bitmaps`));
643
+ yield* openBitmaps(bucket, key, {
644
+ positions,
645
+ count,
646
+ table
647
+ });
648
+ return {
649
+ count,
650
+ table,
651
+ bytes: size
652
+ };
653
+ });
654
+ export { EdgeFiles, bitmapsMostBytes, bitmapsPut, copyBitmaps, copyHeldBytes, copyRunBytes, eachBitmapBytes, edgesBytesOf, edgesFileOf, ewahMostWords, isMergeIncomplete, mergeIncomplete, noBase, noNumber, openBitmaps, runGapBytes, runsMost, storedBitmaps, storedSize, walkBytes, writeBitmaps };
@@ -0,0 +1,15 @@
1
+ import "./index-bitmaps.mjs";
2
+ import "../contracts/objects.mjs";
3
+ import "../contracts/services.mjs";
4
+ import "../contracts/store.mjs";
5
+ import "../store/call-count.mjs";
6
+ import "./fetch.mjs";
7
+ import "./index-graph.mjs";
8
+ import "./memory-budget.mjs";
9
+ import "./pack-order.mjs";
10
+ import "../contracts/promises.mjs";
11
+ import { Moment, Row } from "@ref0/infra";
12
+ import "effect/Effect";
13
+ import "effect/Schema";
14
+ import "effect/Option";
15
+ import "effect/Scope";