@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,752 @@
1
+ import { isTokenOf } from "../auth/token-text.mjs";
2
+ import { checkChurn, createdKey, createdKeyOf, entryOf, listCreated, listLimit, listNames, listPublic, readEntries, recordAt } from "../store/catalogue.mjs";
3
+ import { listBound } from "../store/cursor-seal.mjs";
4
+ import { fail } from "../store/errors.mjs";
5
+ import { appendEvents, decodeOutbox, dropUnconfirmed, emptyOutbox, outboxReads, repoEnvelope } from "../store/outbox.mjs";
6
+ import { commitRecord, readRecord, writeRecord } from "../store/repo-record.mjs";
7
+ import { keptKey, takenBack } from "../store/records.mjs";
8
+ import { refuseLive, reservationOf, reservedRepo } from "../store/reservations.mjs";
9
+ import { collections, newInternalId, reachedKey, repoScope } from "../store/scopes.mjs";
10
+ import { alreadyExists, callerFor, contended, indexDeleteJobs, keyedRecord, nameMoved, openKeyed, openRepo, repoInfo, statsReads, unlessHidden } from "./access.mjs";
11
+ import { isRefName, isRepoId } from "./names.mjs";
12
+ import { shortRef } from "./rules/patterns.mjs";
13
+ import { heldReceipt, receiptId, receiptKeys, receiptReads, receiptWrites, repoAnswer, withJobs } from "./receipts.mjs";
14
+ import * as Effect from "effect/Effect";
15
+ // src/core/repos.ts
16
+ const defaultBranch = "refs/heads/main";
17
+ /**
18
+ * A new repo's record written at `internalId`, with `write`'s rows, over the name's catalogue
19
+ * `entry`: `made`, or `lost` when another create of the name landed first, which leaves this record
20
+ * aside, so `git.list` agrees, with `unkept`'s rows: what the create mustn't keep, such as its
21
+ * receipt and its event.
22
+ */
23
+ const newRepoRecord = Effect.fnUntraced(function* (store, internalId, entry, write, unkept = {}) {
24
+ yield* checkChurn(internalId, write.record, entry);
25
+ const reached = {
26
+ ...reachedKey,
27
+ value: { since: 0 }
28
+ };
29
+ const put = [...write.put ?? [], reached];
30
+ const written = yield* writeRecord(store, internalId, {
31
+ ...write,
32
+ put,
33
+ expect: 0
34
+ });
35
+ if (written === void 0) return yield* contended();
36
+ if (written.outcome !== "lost") return "made";
37
+ const aside = {
38
+ ...write.record,
39
+ deleted: true
40
+ };
41
+ yield* commitRecord(store, internalId, {
42
+ ...unkept,
43
+ expect: written.version,
44
+ record: aside
45
+ });
46
+ return "lost";
47
+ });
48
+ /**
49
+ * Takes back a rename whose new name a create took between its read and its projection, which
50
+ * left the old name as it was: at a revision past its entry there, without its receipt or its
51
+ * event, so the rename sent again is refused as it was. A write since `lost` moved the scope: it
52
+ * reads again, and stops once `git.list` or a settle took the rename back first.
53
+ */
54
+ const takeBackLost = Effect.fnUntraced(function* (store, internalId, moved, lost) {
55
+ const back = takenBack(moved);
56
+ if (back === void 0) return;
57
+ let { version, head } = lost;
58
+ for (let attempt = 0; attempt < 5; attempt += 1) {
59
+ const dropped = dropUnconfirmed(head);
60
+ const write = {
61
+ expect: version,
62
+ record: back.record,
63
+ put: dropped.put
64
+ };
65
+ const deleted = [...back.delete, ...dropped.delete];
66
+ if ((yield* writeRecord(store, internalId, {
67
+ ...write,
68
+ delete: deleted
69
+ })) !== void 0) return;
70
+ const now = yield* readRecord(store, internalId, outboxReads);
71
+ if (now.record?.name !== moved.name || now.record.revision !== moved.revision) return;
72
+ version = now.snapshot.version;
73
+ ({head} = yield* decodeOutbox(now.snapshot.results.slice(1)));
74
+ }
75
+ return yield* contended();
76
+ });
77
+ const badRepoId = (id) => fail("INVALID_ARGUMENT", `'${id}' isn't a repo ID Git takes`, { hint: "Use up to eight '/'-separated parts of letters, digits, '.', '_' and '-'" });
78
+ const badRefName = (name) => fail("INVALID_ARGUMENT", `'${name}' isn't a full ref name`, { hint: "Name a ref under 'refs/', such as 'refs/heads/main'" });
79
+ /**
80
+ * A default branch `access` would hide from some readers is refused: a clone's `HEAD` would name
81
+ * a branch they can't see. A record that names one, from before a pattern matched it, keeps it,
82
+ * and those readers are served no `HEAD`.
83
+ */
84
+ const privateDefault = (core, branch) => {
85
+ const pattern = core.access?.patternOf(branch);
86
+ if (pattern === void 0) return Effect.void;
87
+ return fail("INVALID_ARGUMENT", `The default branch can't be private: ${shortRef(branch)} matches ${pattern}`, { hint: "Make a branch no private pattern matches the default" });
88
+ };
89
+ /** What `repos.rename` reads besides the record: its stats' rows, then its outbox. */
90
+ const renameReads = [...statsReads, ...outboxReads];
91
+ /** Every merge queue target of a repo, which a delete or rename reads for a topic's reservation. */
92
+ const targetsRead = { collection: collections.queueTargets };
93
+ /**
94
+ * Refused while a topic's live reservation holds one of the repo's targets, `rows`, which a delete
95
+ * or rename would take from under it after its check: the topic is named, and how to release it
96
+ * (Q558).
97
+ */
98
+ const unreserved = Effect.fnUntraced(function* (store, rows) {
99
+ for (const row of rows) {
100
+ const reservation = yield* reservationOf([row]);
101
+ yield* refuseLive(store, reservation, (held, state) => reservedRepo(row.id, held, state));
102
+ }
103
+ });
104
+ /** A create, update or rename's answer, as its receipt keeps it. */
105
+ const repoKept = (info) => ({
106
+ kind: "repo",
107
+ info
108
+ });
109
+ /** The longer of two prefixes when one starts with the other; `undefined` when they part. */
110
+ const narrower = (one, other) => {
111
+ if (one.startsWith(other)) return one;
112
+ return other.startsWith(one) ? other : void 0;
113
+ };
114
+ /**
115
+ * Live names under `prefix` that a token covers (Q122): a prefix token's list is a list under
116
+ * the narrower prefix, so its pages and cursor are a plain list's, and a repo token's is its one
117
+ * repo, when it's live, still the repo the token was made in, and after the page's cursor.
118
+ */
119
+ const coveredNames = Effect.fnUntraced(function* (store, token, prefix, page, descending, tally) {
120
+ const empty = { items: [] };
121
+ if (token.repo === void 0) {
122
+ const under = narrower(token.prefix, prefix);
123
+ return under === void 0 ? empty : yield* listNames(store, under, page, descending, tally);
124
+ }
125
+ const { repo } = token;
126
+ const { after } = page;
127
+ const passed = after !== void 0 && (descending ? repo >= after : repo <= after);
128
+ if (!repo.startsWith(prefix) || passed) return empty;
129
+ const entry = yield* entryOf(store, repo);
130
+ return entry !== void 0 && entry.deleted !== true && isTokenOf(token.id, entry.internalId) ? { items: [repo] } : empty;
131
+ });
132
+ /**
133
+ * What a list reads under: the request's prefix, a prefix token's narrower one, or a repo token's
134
+ * repo; `undefined` when the token covers nothing under the prefix.
135
+ */
136
+ const reachOf = (token, prefix) => {
137
+ if (token === void 0) return prefix;
138
+ return token.repo ?? narrower(token.prefix, prefix);
139
+ };
140
+ /**
141
+ * What a `repos.list` cursor is sealed for: the list's order and the owner and prefix it reads
142
+ * under, so it opens on no list that reads elsewhere, such as a wider token's. A list that reads
143
+ * nowhere seals none, and opens none.
144
+ */
145
+ const reposListBound = (order, reach) => reach === void 0 ? listBound("repos.list", order) : listBound("repos.list", order, reach);
146
+ /**
147
+ * A cursor's text at one length before it's sealed, so a sealed cursor's length tells nothing of
148
+ * the name it holds, such as a hidden one a page's scan stopped at. No name holds a space.
149
+ */
150
+ const padded = (text) => text.padEnd(200, " ");
151
+ /**
152
+ * A cursor's text before it's sealed: how many checks its page's budget has left, in three digits,
153
+ * then the place it reads on from, `padded`. The count rides only in the sealed text, for a
154
+ * `sameBudget` page that goes on spending that budget.
155
+ */
156
+ const cursorText = (left, place) => `${String(left).padStart(3, "0")}${padded(place)}`;
157
+ /** The budget left and the place a cursor's opened text holds, or none when it isn't one. */
158
+ const openedCursor = (text) => {
159
+ const left = /^\d{3}/.exec(text)?.[0];
160
+ return left === void 0 ? void 0 : {
161
+ left: Number(left),
162
+ place: text.slice(3).trimEnd()
163
+ };
164
+ };
165
+ /**
166
+ * How many of the catalogue's rows one page of a caller's `repos.list` reads at most, about, past
167
+ * those it may not read and those gone: a name it lists costs a read of the repo's record and an
168
+ * `authorize` call, and a tombstone or a moved repo's row its read alone, so a page's calls stay
169
+ * within a Worker invocation's however many names it hides or the catalogue holds deleted.
170
+ */
171
+ const listChecks = 300;
172
+ /** How many names a page asks `read` of at once, with one read of their catalogue entries. */
173
+ const checksAtOnce = 8;
174
+ /** How many of the catalogue's pages one page of a caller's `repos.list` reads at most. */
175
+ const listRounds = 4;
176
+ /**
177
+ * How many names a page of `limit` asks the catalogue for in its `round`th read: the page and the
178
+ * one past it at first, never under a batch of checks, and twice as many each read after, so a
179
+ * page among few hidden names spends few checks and `perOwner`'s page of one name each leaves
180
+ * the budget for the owners after it.
181
+ */
182
+ const readSize = (limit, round) => Math.max(limit + 1, checksAtOnce) * 2 ** round;
183
+ const badCursor = (after) => fail("INVALID_ARGUMENT", `'${after}' isn't a cursor of this list of repos`, { hint: "Send the 'next' of the list's last page" });
184
+ const pastOutsideName = () => fail("INVALID_ARGUMENT", "Only a list in 'name' order takes 'past'", { hint: "Page it with the 'next' of its last page" });
185
+ const pastSignedIn = () => fail("INVALID_ARGUMENT", "A signed-in caller's list of repos takes no `past`. Page with the last page's `next`.");
186
+ const sameBudgetWithoutCursor = () => fail("INVALID_ARGUMENT", "Only a list sent a cursor takes 'sameBudget'", { hint: "Send 'sameBudget' with the 'next' of the page whose budget it goes on spending" });
187
+ const perOwnerOutsideName = () => fail("INVALID_ARGUMENT", "Only a list in 'name' order takes 'perOwner'", { hint: "List in 'name' order to read one name for each owner" });
188
+ /** The place past each of `name`'s owner's names, as `~` sorts after each character they take. */
189
+ const pastOwnerOf = (name) => {
190
+ const slash = name.indexOf("/");
191
+ return slash === -1 ? name : `${name.slice(0, slash)}/~`;
192
+ };
193
+ /**
194
+ * One name for each owner in name order past `page.after`, from `pageOf`'s list: the first it
195
+ * shows of an owner, then on past the owner's names. It reads the list a name at a time, as many
196
+ * times as the page holds names and `listRounds` more, and ends at the place it reached.
197
+ */
198
+ const ownersOf = Effect.fnUntraced(function* (pageOf, page) {
199
+ const limit = listLimit(page);
200
+ const items = [];
201
+ let after = page.after;
202
+ for (let round = 0; round < limit + listRounds; round += 1) {
203
+ const found = yield* pageOf(after === void 0 ? { limit: 1 } : {
204
+ limit: 1,
205
+ after
206
+ });
207
+ const [name] = found.items;
208
+ if (name !== void 0 && items.length === limit) return {
209
+ items,
210
+ next: after ?? name
211
+ };
212
+ if (name === void 0 && found.next === void 0) return { items };
213
+ if (name !== void 0) items.push(name);
214
+ after = name === void 0 ? found.next : pastOwnerOf(name);
215
+ }
216
+ return after === void 0 ? { items } : {
217
+ items,
218
+ next: after
219
+ };
220
+ });
221
+ const pastWithCursor = () => fail("INVALID_ARGUMENT", "A list takes 'past' or a cursor, not both", { hint: "Send the 'next' of the list's last page alone" });
222
+ /** A prefix a list in create order takes: none, or one owner's. */
223
+ const isOwnerPrefix = (prefix) => /^(?:[^/]+\/)?$/.test(prefix);
224
+ /** Whether `order` lists by when each repo was created, where a name order lists by name. */
225
+ const isCreateOrder = (order) => order === "oldest" || order === "newest";
226
+ const notOwnerPrefix = (prefix) => fail("INVALID_ARGUMENT", `A list in create order takes no prefix '${prefix}'`, { hint: "Leave the prefix out, or name one owner, such as 'acme/'" });
227
+ /**
228
+ * Public repos under `prefix`, for a signed-out caller (#209): from the public index alone, so
229
+ * its list shows no private repo and reads none, whatever the host's `authorize` let it ask.
230
+ */
231
+ const publicNames = (store, prefix, order, page) => !isCreateOrder(order) || isOwnerPrefix(prefix) ? listPublic(store, prefix, order, page) : notOwnerPrefix(prefix);
232
+ /**
233
+ * Live names in create order under `prefix` that the caller covers. A prefix token's list reads
234
+ * the folder of the narrower prefix, so it reads only rows it may show, and a repo token's is its
235
+ * one repo, as in name order, when its place is past the page's cursor.
236
+ */
237
+ const createdNames = Effect.fnUntraced(function* (store, token, prefix, newest, page = {}, tally) {
238
+ if (!isOwnerPrefix(prefix)) return yield* notOwnerPrefix(prefix);
239
+ const { after } = page;
240
+ const empty = { items: [] };
241
+ if (token === void 0) return yield* listCreated(store, prefix, newest, page, tally);
242
+ if (token.repo === void 0) {
243
+ const under = narrower(token.prefix, prefix);
244
+ if (under === void 0) return empty;
245
+ return yield* listCreated(store, under, newest, page, tally);
246
+ }
247
+ const { repo } = token;
248
+ const entry = yield* entryOf(store, repo);
249
+ if (!(entry !== void 0 && entry.deleted !== true && isTokenOf(token.id, entry.internalId)) || !repo.startsWith(prefix)) return empty;
250
+ const key = after === void 0 ? void 0 : yield* createdKeyOf(store, entry.internalId);
251
+ return after === void 0 || key !== void 0 && (newest ? key < after : key > after) ? { items: [repo] } : empty;
252
+ });
253
+ const createsAlone = {
254
+ input: [],
255
+ put: [],
256
+ jobs: []
257
+ };
258
+ const keyOf = ({ collection, id }) => ({
259
+ collection,
260
+ id
261
+ });
262
+ /**
263
+ * `repos.create` for `caller`, with `also`'s rows and jobs in its commit: the record, its key's
264
+ * receipt and `repo.created`, projected into `git/repos` once it lands. It answers the repo's
265
+ * internal ID beside its info: a key sent again finds the repo under whatever name it has now.
266
+ */
267
+ const createWith = Effect.fnUntraced(function* (core, caller, input, also = createsAlone) {
268
+ const { store } = core;
269
+ const { id } = input;
270
+ const branch = input.defaultBranch ?? "refs/heads/main";
271
+ if (!isRepoId(id)) return yield* badRepoId(id);
272
+ if (!isRefName(branch)) return yield* badRefName(branch);
273
+ yield* privateDefault(core, branch);
274
+ yield* core.authorize({
275
+ caller,
276
+ operation: {
277
+ kind: "repo.create",
278
+ repo: id
279
+ }
280
+ });
281
+ for (let attempt = 0; attempt < 5; attempt += 1) {
282
+ const at = yield* core.now;
283
+ const kept = yield* keptKey(caller, input.key, [
284
+ "create",
285
+ id,
286
+ branch,
287
+ input.public ?? false,
288
+ ...also.input
289
+ ], at);
290
+ const keyed = yield* keyedRecord(store, id, kept, (repo) => core.authorize({
291
+ caller,
292
+ operation: {
293
+ kind: "read",
294
+ repo: repo.id
295
+ },
296
+ repo
297
+ }));
298
+ if (keyed?.kind === "answered") return {
299
+ info: yield* repoAnswer(keyed.receipt),
300
+ internalId: keyed.repo.internalId
301
+ };
302
+ const entry = yield* entryOf(store, id);
303
+ if (nameMoved(keyed, entry)) continue;
304
+ if (entry !== void 0 && entry.deleted !== true) return yield* alreadyExists(id);
305
+ const internalId = newInternalId();
306
+ const record = {
307
+ name: id,
308
+ revision: (entry?.sourceRevision ?? 0) + 1,
309
+ defaultBranch: branch,
310
+ public: input.public ?? false,
311
+ createdAt: at,
312
+ changedAt: at
313
+ };
314
+ const info = yield* repoInfo(core, caller, internalId, record, []);
315
+ const receipt = receiptWrites(kept, repoKept(info), core.repackJobRow);
316
+ const created = {
317
+ type: "repo.created",
318
+ ...repoEnvelope(caller, id),
319
+ public: record.public
320
+ };
321
+ const options = {
322
+ scope: repoScope(internalId),
323
+ at: record.createdAt,
324
+ confirm: id
325
+ };
326
+ if (entry?.nextSeq !== void 0) {
327
+ options.from = entry.nextSeq;
328
+ options.after = entry.internalId;
329
+ }
330
+ const appended = yield* appendEvents(core.events, emptyOutbox, [created], options);
331
+ const dropped = dropUnconfirmed(appended.head);
332
+ if ((yield* newRepoRecord(store, internalId, entry, {
333
+ record,
334
+ put: [
335
+ ...receipt.put,
336
+ ...appended.put,
337
+ ...also.put
338
+ ],
339
+ jobs: withJobs([...appended.jobs, ...also.jobs], receipt.jobs)
340
+ }, {
341
+ put: dropped.put,
342
+ delete: [
343
+ ...receiptKeys(kept),
344
+ ...dropped.delete,
345
+ ...also.put.map(keyOf)
346
+ ]
347
+ })) === "lost") return yield* alreadyExists(id);
348
+ return {
349
+ info,
350
+ internalId
351
+ };
352
+ }
353
+ return yield* contended();
354
+ });
355
+ /**
356
+ * `repos`: each call reads the repo's record, decides the next one, and commits it in the repo's
357
+ * own scope, with `git.list` saved beside it, then projects the record into `git/repos`. The
358
+ * catalogue takes a name's entry only from a newer revision, and from another repo only over a
359
+ * tombstone, so of two creates of one name only the first lands, and no write takes a live name.
360
+ * A write answers with the repo as its read found it, with the write's change, and its `key` keeps
361
+ * that answer: sent again within `keyKept`, the write answers as it first did.
362
+ */
363
+ const repoCalls = (core, bound) => {
364
+ const callerOf = callerFor(bound);
365
+ const { store } = core;
366
+ const create = (input) => Effect.map(createWith(core, callerOf(input), input), (made) => made.info);
367
+ const get = Effect.fnUntraced(function* (repo, input) {
368
+ const operation = {
369
+ kind: "read",
370
+ repo
371
+ };
372
+ const caller = callerOf(input);
373
+ const opened = yield* openRepo(core, caller, operation, statsReads, input.internalId);
374
+ return yield* repoInfo(core, caller, opened.internalId, opened.record, opened.snapshot.results.slice(1));
375
+ });
376
+ const list = Effect.fnUntraced(function* (input) {
377
+ const caller = callerOf(input);
378
+ const operation = { kind: "repo.list" };
379
+ if (input.prefix !== void 0) operation.prefix = input.prefix;
380
+ yield* core.authorize({
381
+ caller,
382
+ operation
383
+ });
384
+ const prefix = input.prefix ?? "";
385
+ const order = input.order ?? "name";
386
+ const { past } = input;
387
+ const sent = input.page?.after;
388
+ if (past !== void 0 && order !== "name") return yield* pastOutsideName();
389
+ if (input.perOwner === true && order !== "name") return yield* perOwnerOutsideName();
390
+ if (past !== void 0 && sent !== void 0) return yield* pastWithCursor();
391
+ if (input.sameBudget === true && sent === void 0) return yield* sameBudgetWithoutCursor();
392
+ const signedOut = core.host !== true && caller.actor.anonymous === true;
393
+ if (past !== void 0 && core.host !== true && !signedOut) return yield* pastSignedIn();
394
+ const bound = signedOut ? listBound("repos.list", "public", order, prefix) : reposListBound(order, reachOf(caller.token, prefix));
395
+ const sealed = sent === void 0 ? void 0 : yield* core.cursors.open(bound, sent);
396
+ const opened = sealed === void 0 ? void 0 : openedCursor(sealed);
397
+ if (sent !== void 0 && opened === void 0) return yield* badCursor(sent);
398
+ const { after: _sent, ...limit } = input.page ?? {};
399
+ const after = opened?.place ?? past;
400
+ const page = after === void 0 ? limit : {
401
+ ...limit,
402
+ after
403
+ };
404
+ const sameBudget = input.sameBudget === true && opened !== void 0;
405
+ const checks = { left: sameBudget ? Math.min(opened.left, listChecks) : listChecks };
406
+ const rounds = sameBudget ? Number.POSITIVE_INFINITY : listRounds;
407
+ const pageOf = (at) => {
408
+ if (signedOut) return publicNames(store, prefix, order, at);
409
+ if (core.host === true) return listed(caller.token, prefix, order, at);
410
+ return readableNames(caller, prefix, order, at, checks, rounds);
411
+ };
412
+ const found = input.perOwner === true ? yield* ownersOf(pageOf, page) : yield* pageOf(page);
413
+ if (found.next === void 0) return found;
414
+ const next = yield* core.cursors.seal(bound, cursorText(checks.left, found.next));
415
+ return {
416
+ items: found.items,
417
+ next
418
+ };
419
+ });
420
+ /**
421
+ * `name`'s place in `order`'s list when `caller` may read the repo the catalogue's `entry` names,
422
+ * as `repos.get` would: its record still live under the name, then `read` asked of `authorize`.
423
+ * `undefined` for a repo it hides, as for one that's gone or moved, so the two cost the same
424
+ * calls past the record and leave the page alike.
425
+ */
426
+ const readablePlace = Effect.fnUntraced(function* (caller, name, entry, created) {
427
+ if (entry === void 0 || entry.deleted === true) return void 0;
428
+ const { internalId } = entry;
429
+ const record = (yield* recordAt(store, internalId))?.record;
430
+ if (record === void 0 || record.deleted === true || record.name !== name) return void 0;
431
+ const repo = {
432
+ id: name,
433
+ public: record.public,
434
+ internalId
435
+ };
436
+ const asked = core.authorize({
437
+ caller,
438
+ operation: {
439
+ kind: "read",
440
+ repo: name
441
+ },
442
+ repo
443
+ });
444
+ if ((yield* unlessHidden(Effect.as(asked, true))) === void 0) return void 0;
445
+ return created ? createdKey(internalId, record.createdAt) : name;
446
+ });
447
+ /**
448
+ * The page of `order`'s list under `prefix` past `page.after` that `caller` may read: each name
449
+ * the catalogue lists is asked `read`, `checksAtOnce` at a time, and one it hides takes no place.
450
+ * The page reads on past those until it holds one name more than its limit, which says another
451
+ * page follows, so its items and `next` are those of a list without them. Each row of the
452
+ * catalogue it reads costs one of the `checks` left, a tombstone's or a moved repo's too, and
453
+ * each read one at least. Once it has spent them, or read `rounds` of the catalogue's pages, it
454
+ * ends at the cursor the catalogue reached, short or empty, with that `next`.
455
+ */
456
+ const readableNames = Effect.fnUntraced(function* (caller, prefix, order, page, checks, rounds) {
457
+ const limit = listLimit(page);
458
+ const created = isCreateOrder(order);
459
+ const items = [];
460
+ let last;
461
+ let after = page.after;
462
+ for (let round = 0; round < rounds && checks.left > 0; round += 1) {
463
+ const read = { limit: Math.min(200, checks.left, readSize(limit, round)) };
464
+ const tally = {
465
+ read: 0,
466
+ most: checks.left
467
+ };
468
+ const found = yield* listed(caller.token, prefix, order, after === void 0 ? read : {
469
+ ...read,
470
+ after
471
+ }, tally);
472
+ checks.left = Math.max(0, checks.left - Math.max(1, tally.read));
473
+ for (let start = 0; start < found.items.length; start += checksAtOnce) {
474
+ const names = found.items.slice(start, start + checksAtOnce);
475
+ const { entries } = yield* readEntries(store, names);
476
+ const places = yield* Effect.forEach(entries, ({ name, entry }) => readablePlace(caller, name, entry, created), { concurrency: checksAtOnce });
477
+ for (const [index, place] of places.entries()) {
478
+ const name = names[index];
479
+ if (place === void 0 || name === void 0) continue;
480
+ if (items.length === limit && last !== void 0) return {
481
+ items,
482
+ next: last
483
+ };
484
+ items.push(name);
485
+ last = place;
486
+ }
487
+ }
488
+ if (found.next === void 0) return { items };
489
+ after = found.next;
490
+ }
491
+ return after === void 0 ? { items } : {
492
+ items,
493
+ next: after
494
+ };
495
+ });
496
+ /** The page of `order`'s list under `prefix` past `page.after`, its cursor still open. */
497
+ const listed = (token, prefix, order, page, tally) => {
498
+ if (isCreateOrder(order)) return createdNames(store, token, prefix, order === "newest", page, tally);
499
+ const descending = order === "nameDescending";
500
+ if (token === void 0) return listNames(store, prefix, page, descending, tally);
501
+ return coveredNames(store, token, prefix, page, descending, tally);
502
+ };
503
+ return {
504
+ create,
505
+ get,
506
+ list,
507
+ update: Effect.fnUntraced(function* (repo, input) {
508
+ if (input.defaultBranch !== void 0 && !isRefName(input.defaultBranch)) return yield* badRefName(input.defaultBranch);
509
+ if (input.defaultBranch !== void 0) yield* privateDefault(core, input.defaultBranch);
510
+ for (let attempt = 0; attempt < 5; attempt += 1) {
511
+ const at = yield* core.now;
512
+ const caller = callerOf(input);
513
+ const kept = yield* keptKey(caller, input.key, [
514
+ "update",
515
+ input.defaultBranch,
516
+ input.public
517
+ ], at);
518
+ const operation = {
519
+ kind: "repo.update",
520
+ repo
521
+ };
522
+ const keyReads = receiptReads(kept);
523
+ const flipReads = input.public === void 0 ? [] : outboxReads;
524
+ const { name, internalId, record, snapshot } = yield* openRepo(core, caller, operation, [
525
+ ...statsReads,
526
+ ...keyReads,
527
+ ...flipReads
528
+ ], input.internalId);
529
+ const results = snapshot.results.slice(1);
530
+ const keyRows = results.slice(statsReads.length, statsReads.length + keyReads.length);
531
+ const held = yield* heldReceipt(keyRows, kept);
532
+ if (held !== void 0) return yield* repoAnswer(held);
533
+ const next = {
534
+ ...record,
535
+ changedAt: at
536
+ };
537
+ if (input.defaultBranch !== void 0) next.defaultBranch = input.defaultBranch;
538
+ const flips = input.public !== void 0 && input.public !== record.public;
539
+ if (input.public !== void 0) next.public = input.public;
540
+ if (flips) next.revision = record.revision + 1;
541
+ const info = yield* repoInfo(core, caller, internalId, next, results);
542
+ const receipt = receiptWrites(kept, repoKept(info), core.repackJobRow);
543
+ if (!flips) {
544
+ const write = {
545
+ expect: snapshot.version,
546
+ record: next,
547
+ ...receipt
548
+ };
549
+ if ((yield* commitRecord(store, internalId, write)).ok) return info;
550
+ continue;
551
+ }
552
+ const outbox = yield* decodeOutbox(results.slice(statsReads.length + keyReads.length));
553
+ const changed = {
554
+ type: "repo.visibility.changed",
555
+ ...repoEnvelope(caller, name),
556
+ public: next.public
557
+ };
558
+ const appended = yield* appendEvents(core.events, outbox, [changed], {
559
+ scope: repoScope(internalId),
560
+ at,
561
+ exempt: !next.public,
562
+ confirmed: name
563
+ });
564
+ if ((yield* writeRecord(store, internalId, {
565
+ expect: snapshot.version,
566
+ record: next,
567
+ put: [...receipt.put, ...appended.put],
568
+ delete: appended.delete,
569
+ jobs: withJobs(appended.jobs, receipt.jobs)
570
+ })) !== void 0) return info;
571
+ }
572
+ return yield* contended();
573
+ }),
574
+ rename: Effect.fnUntraced(function* (repo, input) {
575
+ const { to } = input;
576
+ const caller = callerOf(input);
577
+ if (!isRepoId(to)) return yield* badRepoId(to);
578
+ if (to === repo) return yield* fail("INVALID_ARGUMENT", "A rename names another name");
579
+ for (let attempt = 0; attempt < 5; attempt += 1) {
580
+ const at = yield* core.now;
581
+ const kept = yield* keptKey(caller, input.key, [
582
+ "rename",
583
+ repo,
584
+ to
585
+ ], at);
586
+ const keyed = yield* keyedRecord(store, repo, kept, (access) => Effect.andThen(core.authorize({
587
+ caller,
588
+ operation: {
589
+ kind: "read",
590
+ repo: access.id
591
+ },
592
+ repo: access
593
+ }), core.authorize({
594
+ caller,
595
+ operation: {
596
+ kind: "repo.update",
597
+ repo: access.id
598
+ },
599
+ repo: access
600
+ })), input.internalId);
601
+ if (keyed?.kind === "answered") return yield* repoAnswer(keyed.receipt);
602
+ const operation = {
603
+ kind: "repo.update",
604
+ repo
605
+ };
606
+ const keyReads = receiptReads(kept);
607
+ const reads = [
608
+ ...renameReads,
609
+ ...keyReads,
610
+ targetsRead
611
+ ];
612
+ const opened = yield* openKeyed(core, caller, operation, reads, keyed, input.internalId);
613
+ if (opened === void 0) continue;
614
+ const keyRows = opened.snapshot.results.slice(1 + renameReads.length);
615
+ const held = yield* heldReceipt(keyRows.slice(0, keyReads.length), kept);
616
+ if (held !== void 0) return yield* repoAnswer(held);
617
+ yield* unreserved(store, keyRows[keyReads.length] ?? []);
618
+ yield* core.authorize({
619
+ caller,
620
+ operation: {
621
+ kind: "repo.create",
622
+ repo: to
623
+ }
624
+ });
625
+ const target = yield* entryOf(store, to);
626
+ if (target !== void 0 && target.deleted !== true) return yield* alreadyExists(to);
627
+ const outbox = yield* decodeOutbox(opened.snapshot.results.slice(1 + statsReads.length, 1 + renameReads.length));
628
+ const results = opened.snapshot.results.slice(1, 1 + statsReads.length);
629
+ const renamedFrom = {
630
+ name: repo,
631
+ revision: opened.record.revision + 1
632
+ };
633
+ if (core.events !== void 0) renamedFrom.nextSeq = outbox.head.next;
634
+ if (kept !== void 0) renamedFrom.receipt = receiptId(kept.at, kept.key);
635
+ const moved = {
636
+ ...opened.record,
637
+ name: to,
638
+ revision: (target?.sourceRevision ?? 0) + 1,
639
+ changedAt: at,
640
+ renamedFrom
641
+ };
642
+ const info = yield* repoInfo(core, caller, opened.internalId, moved, results);
643
+ const receipt = receiptWrites(kept, repoKept(info), core.repackJobRow);
644
+ const renamed = {
645
+ type: "repo.renamed",
646
+ ...repoEnvelope(caller, to),
647
+ from: repo
648
+ };
649
+ const options = {
650
+ scope: repoScope(opened.internalId),
651
+ at,
652
+ confirmed: opened.name,
653
+ confirm: to
654
+ };
655
+ if (target?.nextSeq !== void 0) {
656
+ options.from = target.nextSeq;
657
+ options.after = target.internalId;
658
+ }
659
+ const appended = yield* appendEvents(core.events, outbox, [renamed], options);
660
+ const written = yield* writeRecord(store, opened.internalId, {
661
+ expect: opened.snapshot.version,
662
+ record: moved,
663
+ put: [...receipt.put, ...appended.put],
664
+ delete: appended.delete,
665
+ jobs: withJobs(appended.jobs, receipt.jobs)
666
+ });
667
+ if (written === void 0) continue;
668
+ if (written.outcome === "lost") {
669
+ const lost = {
670
+ version: written.version,
671
+ head: appended.head
672
+ };
673
+ yield* takeBackLost(store, opened.internalId, moved, lost);
674
+ return yield* alreadyExists(to);
675
+ }
676
+ return info;
677
+ }
678
+ return yield* contended();
679
+ }),
680
+ delete: Effect.fnUntraced(function* (repo, input) {
681
+ const caller = callerOf(input);
682
+ for (let attempt = 0; attempt < 5; attempt += 1) {
683
+ const at = yield* core.now;
684
+ const kept = yield* keptKey(caller, input.key, ["delete", repo], at);
685
+ const keyed = yield* keyedRecord(store, repo, kept, (access) => Effect.andThen(core.authorize({
686
+ caller,
687
+ operation: {
688
+ kind: "read",
689
+ repo: access.id
690
+ },
691
+ repo: access
692
+ }), core.authorize({
693
+ caller,
694
+ operation: {
695
+ kind: "repo.delete",
696
+ repo: access.id
697
+ },
698
+ repo: access
699
+ })), input.internalId);
700
+ if (keyed?.kind === "answered") return {};
701
+ const operation = {
702
+ kind: "repo.delete",
703
+ repo
704
+ };
705
+ const keyReads = receiptReads(kept);
706
+ const reads = [
707
+ ...outboxReads,
708
+ ...keyReads,
709
+ targetsRead
710
+ ];
711
+ const opened = yield* openKeyed(core, caller, operation, reads, keyed, input.internalId);
712
+ if (opened === void 0) continue;
713
+ const { name, internalId, record, snapshot } = opened;
714
+ const keyRows = snapshot.results.slice(1 + outboxReads.length);
715
+ if ((yield* heldReceipt(keyRows.slice(0, keyReads.length), kept)) !== void 0) return {};
716
+ yield* unreserved(store, keyRows[keyReads.length] ?? []);
717
+ const outbox = yield* decodeOutbox(snapshot.results.slice(1, 1 + outboxReads.length));
718
+ const event = {
719
+ type: "repo.deleted",
720
+ ...repoEnvelope(caller, repo)
721
+ };
722
+ const appended = yield* appendEvents(core.events, outbox, [event], {
723
+ scope: repoScope(internalId),
724
+ at,
725
+ exempt: true,
726
+ confirmed: name
727
+ });
728
+ const deleted = {
729
+ ...record,
730
+ deleted: true,
731
+ revision: record.revision + 1,
732
+ changedAt: at
733
+ };
734
+ if (core.events !== void 0) deleted.nextSeq = appended.head.next;
735
+ const receipt = receiptWrites(kept, { kind: "done" }, core.repackJobRow);
736
+ if ((yield* writeRecord(store, internalId, {
737
+ expect: snapshot.version,
738
+ record: deleted,
739
+ put: [...receipt.put, ...appended.put],
740
+ delete: appended.delete,
741
+ jobs: withJobs([
742
+ core.repackJobRow(),
743
+ ...indexDeleteJobs(core),
744
+ ...appended.jobs
745
+ ], receipt.jobs)
746
+ })) !== void 0) return {};
747
+ }
748
+ return yield* contended();
749
+ })
750
+ };
751
+ };
752
+ export { badRepoId, createWith, defaultBranch, newRepoRecord, repoCalls, repoKept };