@ref0/git 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (504) hide show
  1. package/dist/LICENSE +202 -0
  2. package/dist/access/private-refs.d.mts +27 -0
  3. package/dist/access/private-refs.mjs +173 -0
  4. package/dist/access.d.mts +2 -0
  5. package/dist/access.mjs +1 -0
  6. package/dist/auth/access-jwt.d.mts +21 -0
  7. package/dist/auth/access-jwt.mjs +102 -0
  8. package/dist/auth/acting.mjs +15 -0
  9. package/dist/auth/authorize.d.mts +5 -0
  10. package/dist/auth/authorize.mjs +292 -0
  11. package/dist/auth/credentials.mjs +57 -0
  12. package/dist/auth/fences.d.mts +5 -0
  13. package/dist/auth/fences.mjs +65 -0
  14. package/dist/auth/grants.mjs +61 -0
  15. package/dist/auth/helpers.d.mts +17 -0
  16. package/dist/auth/helpers.mjs +25 -0
  17. package/dist/auth/host-function.d.mts +4 -0
  18. package/dist/auth/host-function.mjs +69 -0
  19. package/dist/auth/identify.d.mts +6 -0
  20. package/dist/auth/identify.mjs +97 -0
  21. package/dist/auth/token-rows.mjs +100 -0
  22. package/dist/auth/token-text.mjs +66 -0
  23. package/dist/auth/tokens.d.mts +10 -0
  24. package/dist/auth/tokens.mjs +347 -0
  25. package/dist/auth.d.mts +7 -0
  26. package/dist/auth.mjs +6 -0
  27. package/dist/client/answer.mjs +141 -0
  28. package/dist/client/client.d.mts +23 -0
  29. package/dist/client/client.mjs +51 -0
  30. package/dist/client/git-http.mjs +201 -0
  31. package/dist/client/helper-node.mjs +19 -0
  32. package/dist/client/local.mjs +160 -0
  33. package/dist/client/negotiate.mjs +170 -0
  34. package/dist/client/push-upload.mjs +53 -0
  35. package/dist/client/remote-helper.mjs +129 -0
  36. package/dist/client/remote.mjs +398 -0
  37. package/dist/client/run-remote-helper.d.mts +35 -0
  38. package/dist/client/run-remote-helper.mjs +259 -0
  39. package/dist/client/scrub.d.mts +18 -0
  40. package/dist/client/scrub.mjs +38 -0
  41. package/dist/client/transport.d.mts +2 -0
  42. package/dist/client/transport.mjs +211 -0
  43. package/dist/contracts/access.d.mts +87 -0
  44. package/dist/contracts/actors.d.mts +144 -0
  45. package/dist/contracts/blobs.d.mts +38 -0
  46. package/dist/contracts/calls-spent.d.mts +11 -0
  47. package/dist/contracts/calls-spent.mjs +150 -0
  48. package/dist/contracts/client.d.mts +90 -0
  49. package/dist/contracts/commits.d.mts +126 -0
  50. package/dist/contracts/engine.d.mts +134 -0
  51. package/dist/contracts/events.d.mts +276 -0
  52. package/dist/contracts/files.d.mts +75 -0
  53. package/dist/contracts/forks.d.mts +78 -0
  54. package/dist/contracts/grants.d.mts +60 -0
  55. package/dist/contracts/handlers.d.mts +10 -0
  56. package/dist/contracts/ids.d.mts +15 -0
  57. package/dist/contracts/ids.mjs +15 -0
  58. package/dist/contracts/lfs.d.mts +27 -0
  59. package/dist/contracts/merges.d.mts +33 -0
  60. package/dist/contracts/objects.d.mts +645 -0
  61. package/dist/contracts/objects.mjs +54 -0
  62. package/dist/contracts/operations.d.mts +133 -0
  63. package/dist/contracts/promises.d.mts +63 -0
  64. package/dist/contracts/push-uploads.d.mts +44 -0
  65. package/dist/contracts/queue.d.mts +401 -0
  66. package/dist/contracts/refs.d.mts +95 -0
  67. package/dist/contracts/remote.d.mts +50 -0
  68. package/dist/contracts/repos.d.mts +153 -0
  69. package/dist/contracts/result.d.mts +126 -0
  70. package/dist/contracts/result.mjs +34 -0
  71. package/dist/contracts/rules.d.mts +159 -0
  72. package/dist/contracts/server.d.mts +245 -0
  73. package/dist/contracts/services.d.mts +36 -0
  74. package/dist/contracts/services.mjs +13 -0
  75. package/dist/contracts/signin.d.mts +126 -0
  76. package/dist/contracts/store.d.mts +41 -0
  77. package/dist/contracts/sync.d.mts +210 -0
  78. package/dist/contracts/sync.mjs +8 -0
  79. package/dist/contracts/tags.d.mts +50 -0
  80. package/dist/contracts/tags.mjs +6 -0
  81. package/dist/contracts/tokens.d.mts +87 -0
  82. package/dist/contracts/tokens.mjs +15 -0
  83. package/dist/contracts/topics.d.mts +174 -0
  84. package/dist/contracts/trees.d.mts +84 -0
  85. package/dist/contracts/work.d.mts +31 -0
  86. package/dist/core/access.d.mts +22 -0
  87. package/dist/core/access.mjs +262 -0
  88. package/dist/core/ancestry.mjs +235 -0
  89. package/dist/core/clock.mjs +18 -0
  90. package/dist/core/events/deliver.mjs +468 -0
  91. package/dist/core/events/stream.d.mts +19 -0
  92. package/dist/core/events/stream.mjs +290 -0
  93. package/dist/core/forks.mjs +1027 -0
  94. package/dist/core/hooks/post-receive.mjs +204 -0
  95. package/dist/core/hooks/pre-receive.d.mts +5 -0
  96. package/dist/core/hooks/pre-receive.mjs +34 -0
  97. package/dist/core/index-job.mjs +198 -0
  98. package/dist/core/names.mjs +30 -0
  99. package/dist/core/objects/blobs.mjs +60 -0
  100. package/dist/core/objects/commit-writes.mjs +185 -0
  101. package/dist/core/objects/commits.mjs +172 -0
  102. package/dist/core/objects/files.mjs +211 -0
  103. package/dist/core/objects/lines.mjs +42 -0
  104. package/dist/core/objects/merges.mjs +83 -0
  105. package/dist/core/objects/peel.mjs +166 -0
  106. package/dist/core/objects/reading.mjs +284 -0
  107. package/dist/core/objects/tags.mjs +96 -0
  108. package/dist/core/objects/tree-edits.mjs +266 -0
  109. package/dist/core/objects/trees.mjs +229 -0
  110. package/dist/core/objects/writing.mjs +266 -0
  111. package/dist/core/own-writes.mjs +94 -0
  112. package/dist/core/promise.mjs +46 -0
  113. package/dist/core/publish.mjs +142 -0
  114. package/dist/core/push-decide.mjs +206 -0
  115. package/dist/core/push.mjs +1069 -0
  116. package/dist/core/receipts.d.mts +7 -0
  117. package/dist/core/receipts.mjs +234 -0
  118. package/dist/core/ref-conflicts.mjs +27 -0
  119. package/dist/core/refs.mjs +359 -0
  120. package/dist/core/repack.mjs +521 -0
  121. package/dist/core/repos.mjs +752 -0
  122. package/dist/core/rules/changes.mjs +57 -0
  123. package/dist/core/rules/check.mjs +101 -0
  124. package/dist/core/rules/commit-changes.mjs +216 -0
  125. package/dist/core/rules/context.d.mts +9 -0
  126. package/dist/core/rules/context.mjs +120 -0
  127. package/dist/core/rules/define.d.mts +5 -0
  128. package/dist/core/rules/define.mjs +13 -0
  129. package/dist/core/rules/facts.mjs +13 -0
  130. package/dist/core/rules/fetch.d.mts +5 -0
  131. package/dist/core/rules/fetch.mjs +59 -0
  132. package/dist/core/rules/file-globs.mjs +55 -0
  133. package/dist/core/rules/files.mjs +142 -0
  134. package/dist/core/rules/patterns.mjs +23 -0
  135. package/dist/core/rules/protect.d.mts +9 -0
  136. package/dist/core/rules/protect.mjs +116 -0
  137. package/dist/core/seam.d.mts +24 -0
  138. package/dist/core/seam.mjs +41 -0
  139. package/dist/core/sight.mjs +99 -0
  140. package/dist/core/tokens.mjs +95 -0
  141. package/dist/core/view.d.mts +9 -0
  142. package/dist/core/view.mjs +221 -0
  143. package/dist/core/work.mjs +92 -0
  144. package/dist/effect.d.mts +20 -0
  145. package/dist/effect.mjs +18 -0
  146. package/dist/engine/allotted-xdiff.d.mts +4 -0
  147. package/dist/engine/allotted-xdiff.mjs +80 -0
  148. package/dist/engine/attribute-patterns.mjs +163 -0
  149. package/dist/engine/attributes.mjs +226 -0
  150. package/dist/engine/combined.mjs +653 -0
  151. package/dist/engine/commits.mjs +90 -0
  152. package/dist/engine/content.d.mts +4 -0
  153. package/dist/engine/content.mjs +221 -0
  154. package/dist/engine/diff.mjs +49 -0
  155. package/dist/engine/engine.d.mts +25 -0
  156. package/dist/engine/engine.mjs +49 -0
  157. package/dist/engine/failures.d.mts +4 -0
  158. package/dist/engine/failures.mjs +23 -0
  159. package/dist/engine/line-count.mjs +23 -0
  160. package/dist/engine/merge-base-walk.d.mts +2 -0
  161. package/dist/engine/merge-base-walk.mjs +265 -0
  162. package/dist/engine/merge-bases.mjs +27 -0
  163. package/dist/engine/merge-renames.mjs +165 -0
  164. package/dist/engine/merge.mjs +1125 -0
  165. package/dist/engine/parts.d.mts +8 -0
  166. package/dist/engine/parts.mjs +9 -0
  167. package/dist/engine/reads.d.mts +5 -0
  168. package/dist/engine/reads.mjs +105 -0
  169. package/dist/engine/walk.mjs +328 -0
  170. package/dist/engine/xdiff/NOTICE.md +63 -0
  171. package/dist/engine/xdiff/compiled.d.mts +7 -0
  172. package/dist/engine/xdiff/compiled.mjs +9 -0
  173. package/dist/engine/xdiff/embedded.mjs +4 -0
  174. package/dist/engine/xdiff/node.d.mts +7 -0
  175. package/dist/engine/xdiff/node.mjs +10 -0
  176. package/dist/engine/xdiff/upstream/LGPL-2.1 +511 -0
  177. package/dist/engine/xdiff/xdiff.wasm +0 -0
  178. package/dist/engine/xdiff.d.mts +34 -0
  179. package/dist/engine/xdiff.mjs +380 -0
  180. package/dist/engine.d.mts +3 -0
  181. package/dist/engine.mjs +3 -0
  182. package/dist/extend.d.mts +3 -0
  183. package/dist/extend.mjs +1 -0
  184. package/dist/http/answers.mjs +74 -0
  185. package/dist/http/bodies.mjs +143 -0
  186. package/dist/http/core-parts.mjs +252 -0
  187. package/dist/http/fetch-depth.mjs +26 -0
  188. package/dist/http/handler.mjs +94 -0
  189. package/dist/http/node.d.mts +70 -0
  190. package/dist/http/node.mjs +178 -0
  191. package/dist/http/paths.d.mts +9 -0
  192. package/dist/http/paths.mjs +118 -0
  193. package/dist/http/push-uploads.mjs +286 -0
  194. package/dist/http/receive-pack.mjs +235 -0
  195. package/dist/http/upload-pack.mjs +229 -0
  196. package/dist/index.d.mts +46 -0
  197. package/dist/index.mjs +16 -0
  198. package/dist/lfs/calls.mjs +16 -0
  199. package/dist/lfs/locks.mjs +161 -0
  200. package/dist/lfs/objects.mjs +370 -0
  201. package/dist/lfs/pointers.mjs +141 -0
  202. package/dist/lfs/repo.mjs +42 -0
  203. package/dist/lfs/rows.mjs +108 -0
  204. package/dist/lfs/service.mjs +34 -0
  205. package/dist/lfs/upkeep.mjs +162 -0
  206. package/dist/lfs/wire.mjs +102 -0
  207. package/dist/node.d.mts +3 -0
  208. package/dist/node.mjs +3 -0
  209. package/dist/protocol/bytes/buffers.d.mts +38 -0
  210. package/dist/protocol/bytes/buffers.mjs +62 -0
  211. package/dist/protocol/bytes/crc32.d.mts +4 -0
  212. package/dist/protocol/bytes/crc32.mjs +14 -0
  213. package/dist/protocol/bytes/deflate.d.mts +78 -0
  214. package/dist/protocol/bytes/deflate.mjs +175 -0
  215. package/dist/protocol/bytes/errors.d.mts +20 -0
  216. package/dist/protocol/bytes/errors.mjs +19 -0
  217. package/dist/protocol/bytes/hex.mjs +16 -0
  218. package/dist/protocol/bytes/hmac-sha256.mjs +91 -0
  219. package/dist/protocol/bytes/inflate.d.mts +40 -0
  220. package/dist/protocol/bytes/inflate.mjs +109 -0
  221. package/dist/protocol/bytes/joined.d.mts +2 -0
  222. package/dist/protocol/bytes/joined.mjs +25 -0
  223. package/dist/protocol/bytes/sha1-hasher.d.mts +20 -0
  224. package/dist/protocol/bytes/sha1-hasher.mjs +72 -0
  225. package/dist/protocol/bytes/sha1.d.mts +35 -0
  226. package/dist/protocol/bytes/sha1.mjs +409 -0
  227. package/dist/protocol/bytes/sha256.mjs +156 -0
  228. package/dist/protocol/bytes/streams.mjs +11 -0
  229. package/dist/protocol/bytes/text.mjs +19 -0
  230. package/dist/protocol/diff/diff-raw.d.mts +29 -0
  231. package/dist/protocol/diff/diff-raw.mjs +73 -0
  232. package/dist/protocol/diff/patch.mjs +92 -0
  233. package/dist/protocol/diff/paths.mjs +67 -0
  234. package/dist/protocol/diff/read.d.mts +62 -0
  235. package/dist/protocol/diff/read.mjs +342 -0
  236. package/dist/protocol/diff/rename-similarity.mjs +428 -0
  237. package/dist/protocol/diff/text.mjs +12 -0
  238. package/dist/protocol/diff/tree-diff.d.mts +41 -0
  239. package/dist/protocol/diff/tree-diff.mjs +607 -0
  240. package/dist/protocol/framing/band.d.mts +10 -0
  241. package/dist/protocol/framing/band.mjs +16 -0
  242. package/dist/protocol/framing/pkt-line.d.mts +48 -0
  243. package/dist/protocol/framing/pkt-line.mjs +92 -0
  244. package/dist/protocol/objects/checked-blobs.mjs +127 -0
  245. package/dist/protocol/objects/commit.d.mts +25 -0
  246. package/dist/protocol/objects/commit.mjs +138 -0
  247. package/dist/protocol/objects/fsck-gitmodules.mjs +296 -0
  248. package/dist/protocol/objects/fsck-names.mjs +189 -0
  249. package/dist/protocol/objects/fsck.mjs +297 -0
  250. package/dist/protocol/objects/headers.mjs +109 -0
  251. package/dist/protocol/objects/held.mjs +56 -0
  252. package/dist/protocol/objects/iconv.mjs +145 -0
  253. package/dist/protocol/objects/ident.mjs +111 -0
  254. package/dist/protocol/objects/lfs-pointer.d.mts +8 -0
  255. package/dist/protocol/objects/lfs-pointer.mjs +63 -0
  256. package/dist/protocol/objects/links-raw.mjs +89 -0
  257. package/dist/protocol/objects/object-rules.mjs +75 -0
  258. package/dist/protocol/objects/object.d.mts +16 -0
  259. package/dist/protocol/objects/object.mjs +29 -0
  260. package/dist/protocol/objects/tag.d.mts +21 -0
  261. package/dist/protocol/objects/tag.mjs +96 -0
  262. package/dist/protocol/objects/tree.d.mts +43 -0
  263. package/dist/protocol/objects/tree.mjs +162 -0
  264. package/dist/protocol/objects/utf8-verify.mjs +71 -0
  265. package/dist/protocol/packs/delta.d.mts +57 -0
  266. package/dist/protocol/packs/delta.mjs +229 -0
  267. package/dist/protocol/packs/graph.mjs +78 -0
  268. package/dist/protocol/packs/idx.d.mts +54 -0
  269. package/dist/protocol/packs/idx.mjs +274 -0
  270. package/dist/protocol/packs/indexer.d.mts +167 -0
  271. package/dist/protocol/packs/indexer.mjs +507 -0
  272. package/dist/protocol/packs/parts.d.mts +40 -0
  273. package/dist/protocol/packs/parts.mjs +89 -0
  274. package/dist/protocol/packs/pos.mjs +51 -0
  275. package/dist/protocol/packs/reader.d.mts +180 -0
  276. package/dist/protocol/packs/reader.mjs +414 -0
  277. package/dist/protocol/packs/rev.d.mts +32 -0
  278. package/dist/protocol/packs/rev.mjs +99 -0
  279. package/dist/protocol/packs/step.d.mts +10 -0
  280. package/dist/protocol/packs/step.mjs +12 -0
  281. package/dist/protocol/packs/write-error.d.mts +12 -0
  282. package/dist/protocol/packs/write-error.mjs +27 -0
  283. package/dist/protocol/packs/writer.d.mts +157 -0
  284. package/dist/protocol/packs/writer.mjs +353 -0
  285. package/dist/protocol/wire/advertisement.d.mts +72 -0
  286. package/dist/protocol/wire/advertisement.mjs +161 -0
  287. package/dist/protocol/wire/fetch.d.mts +155 -0
  288. package/dist/protocol/wire/fetch.mjs +458 -0
  289. package/dist/protocol/wire/lines.mjs +107 -0
  290. package/dist/protocol/wire/push-uploads.mjs +43 -0
  291. package/dist/protocol/wire/receive-pack.d.mts +71 -0
  292. package/dist/protocol/wire/receive-pack.mjs +157 -0
  293. package/dist/protocol/wire/report-status.d.mts +47 -0
  294. package/dist/protocol/wire/report-status.mjs +119 -0
  295. package/dist/protocol/wire/v2.d.mts +90 -0
  296. package/dist/protocol/wire/v2.mjs +185 -0
  297. package/dist/protocol.d.mts +31 -0
  298. package/dist/protocol.mjs +31 -0
  299. package/dist/queue/advance.mjs +1036 -0
  300. package/dist/queue/callers.mjs +134 -0
  301. package/dist/queue/calls.mjs +1154 -0
  302. package/dist/queue/commit.mjs +85 -0
  303. package/dist/queue/host.d.mts +15 -0
  304. package/dist/queue/host.mjs +88 -0
  305. package/dist/queue/ids.d.mts +5 -0
  306. package/dist/queue/ids.mjs +21 -0
  307. package/dist/queue/lanes.mjs +86 -0
  308. package/dist/queue/limits.mjs +99 -0
  309. package/dist/queue/pages.mjs +76 -0
  310. package/dist/queue/push-option.mjs +62 -0
  311. package/dist/queue/rows.mjs +206 -0
  312. package/dist/queue/schedule.mjs +132 -0
  313. package/dist/queue/search.mjs +315 -0
  314. package/dist/queue/state.mjs +325 -0
  315. package/dist/queue/steps.mjs +317 -0
  316. package/dist/remote-helper.d.mts +3 -0
  317. package/dist/remote-helper.mjs +3 -0
  318. package/dist/rest/api.d.mts +23 -0
  319. package/dist/rest/api.mjs +27 -0
  320. package/dist/rest/blobs.d.mts +58 -0
  321. package/dist/rest/blobs.mjs +41 -0
  322. package/dist/rest/caller.d.mts +102 -0
  323. package/dist/rest/caller.mjs +18 -0
  324. package/dist/rest/client.d.mts +18 -0
  325. package/dist/rest/client.mjs +587 -0
  326. package/dist/rest/commits.d.mts +435 -0
  327. package/dist/rest/commits.mjs +140 -0
  328. package/dist/rest/errors.d.mts +44 -0
  329. package/dist/rest/errors.mjs +186 -0
  330. package/dist/rest/events.d.mts +38 -0
  331. package/dist/rest/events.mjs +74 -0
  332. package/dist/rest/files.d.mts +179 -0
  333. package/dist/rest/files.mjs +92 -0
  334. package/dist/rest/forks.d.mts +205 -0
  335. package/dist/rest/forks.mjs +51 -0
  336. package/dist/rest/handler.d.mts +17 -0
  337. package/dist/rest/handler.mjs +106 -0
  338. package/dist/rest/handlers.d.mts +8 -0
  339. package/dist/rest/handlers.mjs +592 -0
  340. package/dist/rest/listen.d.mts +24 -0
  341. package/dist/rest/listen.mjs +142 -0
  342. package/dist/rest/me.d.mts +55 -0
  343. package/dist/rest/me.mjs +21 -0
  344. package/dist/rest/merges.d.mts +90 -0
  345. package/dist/rest/merges.mjs +39 -0
  346. package/dist/rest/paths.mjs +86 -0
  347. package/dist/rest/queue.d.mts +486 -0
  348. package/dist/rest/queue.mjs +228 -0
  349. package/dist/rest/refs.d.mts +232 -0
  350. package/dist/rest/refs.mjs +86 -0
  351. package/dist/rest/repos.d.mts +223 -0
  352. package/dist/rest/repos.mjs +93 -0
  353. package/dist/rest/tags.d.mts +153 -0
  354. package/dist/rest/tags.mjs +72 -0
  355. package/dist/rest/tokens.d.mts +297 -0
  356. package/dist/rest/tokens.mjs +88 -0
  357. package/dist/rest/topics.d.mts +257 -0
  358. package/dist/rest/topics.mjs +116 -0
  359. package/dist/rest/trees.d.mts +158 -0
  360. package/dist/rest/trees.mjs +118 -0
  361. package/dist/rest/wire.mjs +57 -0
  362. package/dist/rest/work.d.mts +107 -0
  363. package/dist/rest/work.mjs +77 -0
  364. package/dist/rest.d.mts +8 -0
  365. package/dist/rest.mjs +5 -0
  366. package/dist/server/extension.d.mts +14 -0
  367. package/dist/server/extension.mjs +85 -0
  368. package/dist/server/routes.d.mts +25 -0
  369. package/dist/server/routes.mjs +67 -0
  370. package/dist/server/server.d.mts +2 -0
  371. package/dist/server/server.mjs +439 -0
  372. package/dist/signin/codes.mjs +47 -0
  373. package/dist/signin/context.d.mts +9 -0
  374. package/dist/signin/context.mjs +121 -0
  375. package/dist/signin/device.mjs +122 -0
  376. package/dist/signin/forms.mjs +157 -0
  377. package/dist/signin/grants.d.mts +5 -0
  378. package/dist/signin/grants.mjs +257 -0
  379. package/dist/signin/route.mjs +68 -0
  380. package/dist/signin/web.mjs +125 -0
  381. package/dist/signin/wire.d.mts +42 -0
  382. package/dist/signin/wire.mjs +43 -0
  383. package/dist/storage/allotted.mjs +102 -0
  384. package/dist/storage/budget.mjs +96 -0
  385. package/dist/storage/calls.d.mts +18 -0
  386. package/dist/storage/calls.mjs +273 -0
  387. package/dist/storage/clean-up.mjs +124 -0
  388. package/dist/storage/distinct-ids.mjs +39 -0
  389. package/dist/storage/ewah.mjs +97 -0
  390. package/dist/storage/fetch.d.mts +13 -0
  391. package/dist/storage/fetch.mjs +792 -0
  392. package/dist/storage/fsck.mjs +77 -0
  393. package/dist/storage/held-memo.mjs +188 -0
  394. package/dist/storage/index-bitmaps.d.mts +4 -0
  395. package/dist/storage/index-bitmaps.mjs +654 -0
  396. package/dist/storage/index-build.d.mts +15 -0
  397. package/dist/storage/index-build.mjs +1433 -0
  398. package/dist/storage/index-fetch.d.mts +9 -0
  399. package/dist/storage/index-fetch.mjs +756 -0
  400. package/dist/storage/index-files.mjs +232 -0
  401. package/dist/storage/index-graph.d.mts +3 -0
  402. package/dist/storage/index-graph.mjs +1049 -0
  403. package/dist/storage/index-layers.mjs +317 -0
  404. package/dist/storage/index-reach.mjs +216 -0
  405. package/dist/storage/index-remap.d.mts +8 -0
  406. package/dist/storage/index-remap.mjs +592 -0
  407. package/dist/storage/layout.mjs +69 -0
  408. package/dist/storage/lfs-pointers.d.mts +21 -0
  409. package/dist/storage/lfs-pointers.mjs +175 -0
  410. package/dist/storage/link-join.mjs +106 -0
  411. package/dist/storage/links.mjs +105 -0
  412. package/dist/storage/loose.d.mts +15 -0
  413. package/dist/storage/loose.mjs +120 -0
  414. package/dist/storage/memory-budget.d.mts +8 -0
  415. package/dist/storage/memory-budget.mjs +546 -0
  416. package/dist/storage/merge.mjs +416 -0
  417. package/dist/storage/object-rows.d.mts +6 -0
  418. package/dist/storage/object-rows.mjs +211 -0
  419. package/dist/storage/pack-order.d.mts +8 -0
  420. package/dist/storage/pack-order.mjs +779 -0
  421. package/dist/storage/pack-ranges.d.mts +5 -0
  422. package/dist/storage/pack-ranges.mjs +284 -0
  423. package/dist/storage/pack-reads.d.mts +11 -0
  424. package/dist/storage/pack-reads.mjs +990 -0
  425. package/dist/storage/pack-receive.d.mts +11 -0
  426. package/dist/storage/pack-receive.mjs +449 -0
  427. package/dist/storage/packs.d.mts +56 -0
  428. package/dist/storage/packs.mjs +600 -0
  429. package/dist/storage/prune.mjs +506 -0
  430. package/dist/storage/push-allotment.mjs +109 -0
  431. package/dist/storage/push-uploads.mjs +151 -0
  432. package/dist/storage/pushed-commits.mjs +136 -0
  433. package/dist/storage/quarantine.mjs +98 -0
  434. package/dist/storage/raw-ids.mjs +44 -0
  435. package/dist/storage/ready.d.mts +19 -0
  436. package/dist/storage/ready.mjs +328 -0
  437. package/dist/storage/receive-links.mjs +297 -0
  438. package/dist/storage/repack-job.mjs +48 -0
  439. package/dist/storage/repack.d.mts +31 -0
  440. package/dist/storage/repack.mjs +182 -0
  441. package/dist/storage/roots.mjs +42 -0
  442. package/dist/storage/rows.d.mts +3 -0
  443. package/dist/storage/rows.mjs +71 -0
  444. package/dist/storage/shallow.d.mts +5 -0
  445. package/dist/storage/shallow.mjs +128 -0
  446. package/dist/storage/stream-whole.mjs +236 -0
  447. package/dist/storage/unpack.mjs +236 -0
  448. package/dist/storage/visible.mjs +137 -0
  449. package/dist/storage/walk.d.mts +7 -0
  450. package/dist/storage/walk.mjs +170 -0
  451. package/dist/storage/wants.mjs +362 -0
  452. package/dist/store/call-count.d.mts +47 -0
  453. package/dist/store/call-count.mjs +207 -0
  454. package/dist/store/catalogue.d.mts +7 -0
  455. package/dist/store/catalogue.mjs +643 -0
  456. package/dist/store/crossing.mjs +66 -0
  457. package/dist/store/cursor-seal.d.mts +2 -0
  458. package/dist/store/cursor-seal.mjs +85 -0
  459. package/dist/store/errors.d.mts +12 -0
  460. package/dist/store/errors.mjs +129 -0
  461. package/dist/store/git-store.mjs +75 -0
  462. package/dist/store/list-job.mjs +35 -0
  463. package/dist/store/outbox.d.mts +7 -0
  464. package/dist/store/outbox.mjs +295 -0
  465. package/dist/store/queue-jobs.mjs +43 -0
  466. package/dist/store/random.mjs +28 -0
  467. package/dist/store/records.d.mts +4 -0
  468. package/dist/store/records.mjs +192 -0
  469. package/dist/store/ref-rows.d.mts +4 -0
  470. package/dist/store/ref-rows.mjs +30 -0
  471. package/dist/store/repo-record.mjs +100 -0
  472. package/dist/store/reservations.mjs +82 -0
  473. package/dist/store/scopes.mjs +170 -0
  474. package/dist/store/settle.mjs +63 -0
  475. package/dist/store/topic-jobs.mjs +62 -0
  476. package/dist/sync/bound.d.mts +7 -0
  477. package/dist/sync/bound.mjs +29 -0
  478. package/dist/sync/github.d.mts +12 -0
  479. package/dist/sync/github.mjs +297 -0
  480. package/dist/sync/import.d.mts +8 -0
  481. package/dist/sync/import.mjs +154 -0
  482. package/dist/sync/jobs.d.mts +9 -0
  483. package/dist/sync/jobs.mjs +80 -0
  484. package/dist/sync/mirror.d.mts +9 -0
  485. package/dist/sync/mirror.mjs +227 -0
  486. package/dist/sync/publish.d.mts +5 -0
  487. package/dist/sync/publish.mjs +117 -0
  488. package/dist/sync/records.mjs +73 -0
  489. package/dist/sync/smart-http.d.mts +8 -0
  490. package/dist/sync/smart-http.mjs +23 -0
  491. package/dist/sync/step.mjs +334 -0
  492. package/dist/sync/tries.mjs +126 -0
  493. package/dist/sync.d.mts +8 -0
  494. package/dist/sync.mjs +8 -0
  495. package/dist/topics/advance.mjs +554 -0
  496. package/dist/topics/calls.mjs +346 -0
  497. package/dist/topics/directory.mjs +107 -0
  498. package/dist/topics/host.d.mts +11 -0
  499. package/dist/topics/host.mjs +71 -0
  500. package/dist/topics/members.mjs +177 -0
  501. package/dist/topics/rows.mjs +99 -0
  502. package/dist/topics/topic.mjs +126 -0
  503. package/package.json +88 -3
  504. package/README.md +0 -3
@@ -0,0 +1,121 @@
1
+ import { hostCall } from "../auth/host-function.mjs";
2
+ import { readTarget, tokenExpiry } from "../auth/tokens.mjs";
3
+ import { gitError } from "../store/errors.mjs";
4
+ import { oauthAnswer, oauthError } from "./forms.mjs";
5
+ import { approvalOf } from "./grants.mjs";
6
+ import { accessTokenBody } from "./wire.mjs";
7
+ import * as Effect from "effect/Effect";
8
+ import * as Schema from "effect/Schema";
9
+ // src/signin/context.ts
10
+ /** `gh`'s OAuth client ID, which the device flow takes beside the registered clients. */
11
+ const ghClientId = "178c6fc778ccc68e1d6a";
12
+ /** Git's error behind each error `decide` rejected with, so the page that throws it on is known. */
13
+ const decideErrors = /* @__PURE__ */ new WeakMap();
14
+ /** What `decide` rejects with when its work fails: an `Error`, with Git's error as its cause. */
15
+ const decideRejection = (error) => {
16
+ const rejection = new Error(error.message, { cause: error });
17
+ decideErrors.set(rejection, error);
18
+ return rejection;
19
+ };
20
+ /** The `INTERNAL` error behind a throw that is `decide`'s own rejection, which no retry fixes. */
21
+ const setupFailure = (cause) => {
22
+ const error = cause instanceof Error ? decideErrors.get(cause) : void 0;
23
+ return error?.code === "INTERNAL" ? error : void 0;
24
+ };
25
+ /**
26
+ * The host's page, as a host function: a throw is `UNAVAILABLE`, which `onError` hears of, but a
27
+ * page that throws on `decide`'s rejection over a store the host didn't set up fails with that
28
+ * `INTERNAL` error. Each call gets its own copy of `request`, so a page `decide` answers with can
29
+ * read the body again.
30
+ */
31
+ const approvalPage = (signIn, request, input) => hostCall(signIn.reports, "approvalPage", {}, async (signal) => {
32
+ try {
33
+ return await signIn.options.approvalPage({
34
+ ...input,
35
+ request: request.clone(),
36
+ signal
37
+ });
38
+ } catch (cause) {
39
+ const setup = setupFailure(cause);
40
+ if (setup === void 0) throw cause;
41
+ return setup;
42
+ }
43
+ }).pipe(Effect.flatMap((answer) => answer instanceof Response ? Effect.succeed(answer) : Effect.fail(answer)));
44
+ /**
45
+ * What a browser sees when sign-in failed: a 503 to try again, or a 500 for a store the host didn't
46
+ * set up, which no retry fixes, and which says nothing of the setup.
47
+ */
48
+ const unavailablePage = (error) => new Response(error?.code === "INTERNAL" ? "Sign-in is unavailable" : "Sign-in is unavailable: try again", {
49
+ status: error?.code === "INTERNAL" ? 500 : 503,
50
+ headers: {
51
+ "cache-control": "no-store",
52
+ "content-type": "text/plain; charset=utf-8"
53
+ }
54
+ });
55
+ /**
56
+ * `server_error`, for a token endpoint whose store or mint failed: it says to try again unless the
57
+ * store isn't set up, which no retry fixes.
58
+ */
59
+ const serverError = (request, error) => oauthError(request, "server_error", error?.code === "INTERNAL" ? "The server could not finish this sign-in" : "The server could not finish this sign-in: try again");
60
+ /** OAuth's scopes, as the client sent them: spaces or commas between, at most 50. */
61
+ const readScopes = (text) => {
62
+ const scopes = (text ?? "").split(/[\s,]+/).filter((scope) => scope !== "");
63
+ if (scopes.length > 50 || scopes.some((scope) => scope.length > 100)) return void 0;
64
+ return [...new Set(scopes)];
65
+ };
66
+ const isDecision = Schema.is(Schema.Union([Schema.Struct({ kind: Schema.Literal("deny") }), Schema.Struct({
67
+ kind: Schema.Literal("approve"),
68
+ actor: Schema.Struct({ id: Schema.NonEmptyString }),
69
+ target: Schema.Union([Schema.NonEmptyString, Schema.Struct({ prefix: Schema.String })]),
70
+ scope: Schema.Literals([
71
+ "read",
72
+ "report",
73
+ "write"
74
+ ]),
75
+ expiresAt: Schema.Union([Schema.Number, Schema.Date])
76
+ })]));
77
+ /**
78
+ * A host's decision, checked as the token it mints would be: an expiry within a year and a target
79
+ * that exists. A decision Git can't mint is the host's mistake: `decide` rejects with it. A repo's
80
+ * name is kept with the repo it names now, so a repo made later under that name isn't the one minted.
81
+ */
82
+ const checkDecision = Effect.fnUntraced(function* (signIn, decision) {
83
+ if (!isDecision(decision)) return yield* Effect.fail(gitError("INVALID_ARGUMENT", "A decision approves or denies"));
84
+ if (decision.kind === "deny") return { kind: "deny" };
85
+ const expiresAt = yield* tokenExpiry(yield* signIn.now, decision.expiresAt);
86
+ const { place } = yield* readTarget(signIn.store, decision.target, []);
87
+ const repo = place.kind === "repo" ? place.internalId : void 0;
88
+ return approvalOf({
89
+ ...decision,
90
+ repo,
91
+ expiresAt
92
+ });
93
+ });
94
+ /** One `decide` for one validated request: a second call rejects, since one request settles once. */
95
+ const once = (decide) => {
96
+ let used = false;
97
+ return async (decision) => {
98
+ if (used) throw new TypeError("This request was decided already");
99
+ used = true;
100
+ return decide(decision);
101
+ };
102
+ };
103
+ /**
104
+ * Mints an approved grant's token and answers it, once: its secret is in this answer alone. A repo's
105
+ * name that points at another repo since the host decided mints nothing: `server_error`.
106
+ */
107
+ const mintAnswer = (signIn, request, minted) => {
108
+ const { approval, scopes } = minted;
109
+ const target = approval.target;
110
+ const input = {
111
+ scope: approval.scope,
112
+ expiresAt: approval.expiresAt,
113
+ subject: approval.actor
114
+ };
115
+ return signIn.tokens.create(target, input, approval.repo).pipe(Effect.map((token) => oauthAnswer(request, accessTokenBody({
116
+ access_token: token.secret,
117
+ token_type: "bearer",
118
+ scope: scopes.join(",")
119
+ }))), Effect.catch((error) => Effect.succeed(serverError(request, error))));
120
+ };
121
+ export { approvalPage, checkDecision, decideRejection, ghClientId, mintAnswer, once, readScopes, serverError, unavailablePage };
@@ -0,0 +1,122 @@
1
+ import { codeHash, newCode, newUserCode, readUserCode } from "./codes.mjs";
2
+ import { approvalPage, checkDecision, mintAnswer, once, readScopes, serverError } from "./context.mjs";
3
+ import { oauthAnswer, oauthError, plainPage, readFields } from "./forms.mjs";
4
+ import { decideDevice, findUserCode, pollDevice, putGrant } from "./grants.mjs";
5
+ import { accessTokenBody, deviceCodeBody, signInPaths } from "./wire.mjs";
6
+ import * as Effect from "effect/Effect";
7
+ /** The path a person types their user code at, and the `enter-code` page's `action`. */
8
+ const devicePath = signInPaths.device;
9
+ /** How often a new device code is drawn again when its user code is someone else's still. */
10
+ const draws = 3;
11
+ const fieldsOf = (request, query) => Effect.promise(() => readFields(request, { query }));
12
+ const accepts = (signIn, clientId) => clientId === "178c6fc778ccc68e1d6a" || signIn.clients.has(clientId);
13
+ /**
14
+ * `POST /login/device/code`: a device code, its user code to show, where to type it, and how
15
+ * often to poll. Its grant waits in `git/signin` by the codes' hashes alone.
16
+ */
17
+ const deviceCode = Effect.fnUntraced(function* (signIn, request) {
18
+ const read = yield* fieldsOf(request, true);
19
+ if (read.kind === "unreadable") return oauthError(request, "invalid_request", read.reason);
20
+ const clientId = read.fields.get("client_id") ?? "";
21
+ if (!accepts(signIn, clientId)) return oauthError(request, "incorrect_client_credentials", "The client_id is not valid");
22
+ const scopes = readScopes(read.fields.get("scope"));
23
+ if (scopes === void 0) return oauthError(request, "invalid_scope", "Too many scopes");
24
+ for (let draw = 0; draw < draws; draw += 1) {
25
+ const now = yield* signIn.now;
26
+ const device = newCode();
27
+ const user = newUserCode();
28
+ const grant = {
29
+ kind: "device",
30
+ clientId,
31
+ scopes,
32
+ userCode: yield* Effect.promise(() => codeHash(user)),
33
+ expiresAt: now + 9e5,
34
+ interval: 5
35
+ };
36
+ const id = yield* Effect.promise(() => codeHash(device));
37
+ if (!(yield* putGrant(signIn.store, now, id, grant))) continue;
38
+ return oauthAnswer(request, deviceCodeBody({
39
+ device_code: device,
40
+ user_code: user,
41
+ verification_uri: `${new URL(request.url).origin}${devicePath}`,
42
+ expires_in: 900,
43
+ interval: 5
44
+ }));
45
+ }
46
+ return serverError(request);
47
+ });
48
+ const enterCode = (signIn, request, error) => {
49
+ const page = {
50
+ kind: "enter-code",
51
+ action: devicePath
52
+ };
53
+ if (error !== void 0) page.error = error;
54
+ return approvalPage(signIn, request, page);
55
+ };
56
+ const decidedPage = (decision) => new Response(decision.kind === "approve" ? "Device approved: go back to your device" : "Device denied: you can close this window", { headers: {
57
+ "cache-control": "no-store",
58
+ "content-type": "text/plain; charset=utf-8"
59
+ } });
60
+ /**
61
+ * `GET` or `POST /login/device`: `enter-code` until the person sends a `user_code` that's
62
+ * pending, then `confirm`, whose `decide` settles that one grant. A code that's unknown is
63
+ * `invalid-code`; one whose rows are there but that expired or was decided is `expired-code`. A
64
+ * body Git can't read, such as one past the limit, is a plain 400: the host's page never sees it.
65
+ */
66
+ const devicePage = Effect.fnUntraced(function* (signIn, request) {
67
+ const read = yield* fieldsOf(request, true);
68
+ if (read.kind === "unreadable") return plainPage(400, read.reason);
69
+ const typed = read.fields.get("user_code");
70
+ if (typed === void 0 || typed.trim() === "") return yield* enterCode(signIn, request);
71
+ const userCode = readUserCode(typed);
72
+ if (userCode === void 0) return yield* enterCode(signIn, request, "invalid-code");
73
+ const hash = yield* Effect.promise(() => codeHash(userCode));
74
+ const found = yield* findUserCode(signIn.store, yield* signIn.now, hash);
75
+ if (found.kind === "unknown") return yield* enterCode(signIn, request, "invalid-code");
76
+ if (found.kind === "spent") return yield* enterCode(signIn, request, "expired-code");
77
+ const { id, grant } = found;
78
+ const settle = Effect.fnUntraced(function* (decision) {
79
+ const checked = yield* checkDecision(signIn, decision);
80
+ const decided = yield* decideDevice(signIn.store, signIn.now, hash, id, checked);
81
+ if (decided.kind === "unknown") return yield* enterCode(signIn, request, "invalid-code");
82
+ if (decided.kind === "spent") return yield* enterCode(signIn, request, "expired-code");
83
+ return decidedPage(decision);
84
+ });
85
+ return yield* approvalPage(signIn, request, {
86
+ kind: "confirm",
87
+ prompt: {
88
+ kind: "device",
89
+ clientId: grant.clientId,
90
+ scopes: grant.scopes,
91
+ expiresAt: grant.expiresAt,
92
+ userCode
93
+ },
94
+ decide: once((decision) => signIn.runDecide(settle(decision)))
95
+ });
96
+ });
97
+ /**
98
+ * `POST /login/oauth/access_token` with the device grant: GitHub's statuses until the person
99
+ * decides, then the token once, or `access_denied` once. Any code this client can't use is
100
+ * `incorrect_device_code`, as one that never was.
101
+ */
102
+ const devicePoll = Effect.fnUntraced(function* (signIn, request, fields) {
103
+ const clientId = fields.get("client_id") ?? "";
104
+ if (!accepts(signIn, clientId)) return oauthError(request, "incorrect_client_credentials", "The client_id is not valid");
105
+ const deviceCode = fields.get("device_code");
106
+ if (deviceCode === void 0) return oauthError(request, "invalid_request", "No device_code");
107
+ const id = yield* Effect.promise(() => codeHash(deviceCode));
108
+ const polled = yield* pollDevice(signIn.store, signIn.now, clientId, id);
109
+ switch (polled.kind) {
110
+ case "pending": return oauthError(request, "authorization_pending", "The person has not decided yet");
111
+ case "slow-down": return oauthAnswer(request, accessTokenBody({
112
+ error: "slow_down",
113
+ error_description: `Poll at most every ${polled.interval} seconds`,
114
+ interval: polled.interval
115
+ }));
116
+ case "expired": return oauthError(request, "expired_token", "This device code expired: start again");
117
+ case "denied": return oauthError(request, "access_denied", "The person denied this sign-in");
118
+ case "unknown": return oauthError(request, "incorrect_device_code", "The device_code is not valid");
119
+ case "approved": return yield* mintAnswer(signIn, request, polled);
120
+ }
121
+ });
122
+ export { deviceCode, devicePage, devicePoll };
@@ -0,0 +1,157 @@
1
+ import { accessTokenBody } from "./wire.mjs";
2
+ import * as Schema from "effect/Schema";
3
+ import * as Option from "effect/Option";
4
+ // src/signin/forms.ts
5
+ /** The most a sign-in form's body may hold: far more than any of OAuth's needs. */
6
+ const maxBody = 16384;
7
+ const unreadable = (reason) => ({
8
+ kind: "unreadable",
9
+ reason
10
+ });
11
+ /** Up to `maxBody` bytes of a body as text, or `undefined` past it. */
12
+ const boundedText = async (request) => {
13
+ if (request.body === null) return "";
14
+ const reader = request.body.getReader();
15
+ const parts = [];
16
+ let size = 0;
17
+ for (;;) {
18
+ const { done, value } = await reader.read();
19
+ if (done) break;
20
+ size += value.byteLength;
21
+ if (size > maxBody) {
22
+ reader.cancel().catch(() => {});
23
+ return;
24
+ }
25
+ parts.push(value);
26
+ }
27
+ const bytes = new Uint8Array(size);
28
+ let at = 0;
29
+ for (const part of parts) {
30
+ bytes.set(part, at);
31
+ at += part.byteLength;
32
+ }
33
+ return new TextDecoder().decode(bytes);
34
+ };
35
+ /** Fields from `entries`, refused when one names a field twice. */
36
+ const fieldsOf = (entries) => {
37
+ const fields = /* @__PURE__ */ new Map();
38
+ for (const [name, value] of entries) {
39
+ if (fields.has(name)) return unreadable(`'${name}' is sent more than once`);
40
+ fields.set(name, value);
41
+ }
42
+ return {
43
+ kind: "fields",
44
+ fields
45
+ };
46
+ };
47
+ const open = /[ \t\n\r]*\{/y;
48
+ const close = /[ \t\n\r]*\}/y;
49
+ const colon = /[ \t\n\r]*:/y;
50
+ const comma = /[ \t\n\r]*,/y;
51
+ const end = /[ \t\n\r]*$/y;
52
+ const string = /[ \t\n\r]*"(?:[^"\\\u0000-\u001f]|\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4}))*"/y;
53
+ /** One string token's text: the token's escapes are RFC 8259's, which JSON reads. */
54
+ const decodeString = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.String));
55
+ /**
56
+ * A JSON object of strings' fields in order, each name as often as it's sent, or `undefined` for
57
+ * any other JSON. `JSON.parse` keeps only a name's last value, which would hide a field sent twice.
58
+ */
59
+ const jsonEntries = (text) => {
60
+ const entries = [];
61
+ let at = 0;
62
+ const read = (pattern) => {
63
+ pattern.lastIndex = at;
64
+ const found = pattern.exec(text)?.[0];
65
+ if (found !== void 0) at = pattern.lastIndex;
66
+ return found;
67
+ };
68
+ const readString = () => {
69
+ const found = read(string);
70
+ return found === void 0 ? void 0 : Option.getOrUndefined(decodeString(found));
71
+ };
72
+ const closes = () => read(close) !== void 0;
73
+ if (read(open) === void 0) return void 0;
74
+ if (closes()) return read(end) === void 0 ? void 0 : entries;
75
+ for (;;) {
76
+ const name = readString();
77
+ if (name === void 0 || read(colon) === void 0) return void 0;
78
+ const value = readString();
79
+ if (value === void 0) return void 0;
80
+ entries.push([name, value]);
81
+ if (closes()) return read(end) === void 0 ? void 0 : entries;
82
+ if (read(comma) === void 0) return void 0;
83
+ }
84
+ };
85
+ const jsonFields = (text) => {
86
+ const entries = jsonEntries(text);
87
+ return entries === void 0 ? unreadable("The body is not a JSON object of strings") : fieldsOf(entries);
88
+ };
89
+ /**
90
+ * A form's fields from its body, form-encoded or JSON as GitHub takes both, read from a clone so
91
+ * the request's own body is left for the host. `query`: the URL's fields fill in any the body
92
+ * leaves out.
93
+ */
94
+ const readFields = async (request, options) => {
95
+ const url = new URL(request.url);
96
+ const query = options.query ? fieldsOf(url.searchParams) : fieldsOf([]);
97
+ if (query.kind === "unreadable") return query;
98
+ if (request.method === "GET" || request.method === "HEAD") return query;
99
+ const text = await boundedText(request.clone());
100
+ if (text === void 0) return unreadable("The body is too large");
101
+ const body = request.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() === "application/json" ? jsonFields(text) : fieldsOf(new URLSearchParams(text));
102
+ if (body.kind === "unreadable") return body;
103
+ return {
104
+ kind: "fields",
105
+ fields: new Map([...query.fields, ...body.fields])
106
+ };
107
+ };
108
+ /** Whether the URL itself names one of `names`: a secret that would sit in logs and history. */
109
+ const secretInUrl = (request, names) => {
110
+ const { searchParams } = new URL(request.url);
111
+ return names.some((name) => searchParams.has(name));
112
+ };
113
+ /** RFC 6749's headers on anything that holds a secret: no cache keeps it. */
114
+ const noStore = {
115
+ "cache-control": "no-store",
116
+ pragma: "no-cache"
117
+ };
118
+ /**
119
+ * An answer from the device-code or token endpoint: JSON when `Accept` asks for it, else
120
+ * form-encoded, as GitHub answers. Errors are 200s too, as GitHub's are.
121
+ */
122
+ const oauthAnswer = (request, body) => {
123
+ const accept = request.headers.get("accept") ?? "";
124
+ if (/\bapplication\/json\b/i.test(accept)) return Response.json(body, { headers: noStore });
125
+ const form = new URLSearchParams(Object.entries(body).map(([name, value]) => [name, `${value}`]));
126
+ return new Response(form.toString(), { headers: {
127
+ ...noStore,
128
+ "content-type": "application/x-www-form-urlencoded"
129
+ } });
130
+ };
131
+ /** An OAuth error, as `oauthAnswer` sends it, in the access-token answer's shape. */
132
+ const oauthError = (request, error, description) => oauthAnswer(request, accessTokenBody({
133
+ error,
134
+ error_description: description
135
+ }));
136
+ /** A plain page for a request no redirect may answer: an unknown client or callback. */
137
+ const plainPage = (status, text) => new Response(text, {
138
+ status,
139
+ headers: {
140
+ ...noStore,
141
+ "content-type": "text/plain; charset=utf-8"
142
+ }
143
+ });
144
+ /** A 302 to a registered callback, with `fields` added to its query. */
145
+ const redirectTo = (callback, fields) => {
146
+ const url = new URL(callback);
147
+ for (const [name, value] of Object.entries(fields)) url.searchParams.set(name, value);
148
+ return new Response(null, {
149
+ status: 302,
150
+ headers: {
151
+ ...noStore,
152
+ location: url.toString(),
153
+ "referrer-policy": "no-referrer"
154
+ }
155
+ });
156
+ };
157
+ export { oauthAnswer, oauthError, plainPage, readFields, redirectTo, secretInUrl };
@@ -0,0 +1,5 @@
1
+ import "../contracts/tokens.mjs";
2
+ import "../contracts/promises.mjs";
3
+ import { Moment } from "@ref0/infra";
4
+ import "effect/Effect";
5
+ import "effect/Schema";
@@ -0,0 +1,257 @@
1
+ import { decodeRow, fail, storeCall } from "../store/errors.mjs";
2
+ import { InternalRepoId } from "../store/records.mjs";
3
+ import { newChangeId } from "../store/scopes.mjs";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Schema from "effect/Schema";
6
+ // src/signin/grants.ts
7
+ /** Every pending grant's rows, in one scope: each code is found by its hash alone. */
8
+ const signInScope = "git/signin";
9
+ const signInCollections = {
10
+ /** A device code's or a web code's grant, by the code's hash. */
11
+ grants: "signin-grants",
12
+ /** A user code's grant, by the user code's hash. */
13
+ userCodes: "signin-user-codes",
14
+ /** A grant's ID after its padded `expiresAt`, so the sweep reads the oldest first. */
15
+ expiry: "signin-expiry"
16
+ };
17
+ /** How often a write tries again when the scope moved under it, before giving up. */
18
+ const attempts = 5;
19
+ const isPrefix = Schema.is(Schema.Struct({ prefix: Schema.String }));
20
+ const Target = Schema.Union([Schema.String, Schema.Struct({ prefix: Schema.String })]);
21
+ const Approval = Schema.Struct({
22
+ kind: Schema.Literal("approve"),
23
+ actor: Schema.Struct({ id: Schema.String }),
24
+ target: Target,
25
+ /** The repo a repo's name resolved to when the host decided: the token covers that one alone. */
26
+ repo: Schema.optionalKey(InternalRepoId),
27
+ scope: Schema.Literals([
28
+ "read",
29
+ "report",
30
+ "write"
31
+ ]),
32
+ expiresAt: Schema.Number
33
+ });
34
+ const Denial = Schema.Struct({ kind: Schema.Literal("deny") });
35
+ const DeviceGrant = Schema.Struct({
36
+ kind: Schema.Literal("device"),
37
+ clientId: Schema.String,
38
+ scopes: Schema.Array(Schema.String),
39
+ userCode: Schema.String,
40
+ expiresAt: Schema.Number,
41
+ interval: Schema.Number,
42
+ polledAt: Schema.optionalKey(Schema.Number),
43
+ decision: Schema.optionalKey(Schema.Union([Approval, Denial]))
44
+ });
45
+ const WebGrant = Schema.Struct({
46
+ kind: Schema.Literal("web"),
47
+ clientId: Schema.String,
48
+ scopes: Schema.Array(Schema.String),
49
+ redirectUri: Schema.String,
50
+ /** Whether the authorize request named its callback, so the exchange must name it too. */
51
+ redirectSent: Schema.Boolean,
52
+ challenge: Schema.optionalKey(Schema.String),
53
+ expiresAt: Schema.Number,
54
+ decision: Approval
55
+ });
56
+ const Grant = Schema.Union([DeviceGrant, WebGrant]);
57
+ const UserCodeRow = Schema.Struct({ grant: Schema.String });
58
+ const ExpiryRow = Schema.Struct({ userCode: Schema.optionalKey(Schema.String) });
59
+ const approvalOf = (input) => {
60
+ const approval = {
61
+ kind: "approve",
62
+ actor: { id: input.actor.id },
63
+ target: isPrefix(input.target) ? { prefix: input.target.prefix } : input.target,
64
+ scope: input.scope,
65
+ expiresAt: input.expiresAt
66
+ };
67
+ if (input.repo !== void 0) approval.repo = input.repo;
68
+ return approval;
69
+ };
70
+ const grantKey = (id) => ({
71
+ collection: signInCollections.grants,
72
+ id
73
+ });
74
+ const userCodeKey = (hash) => ({
75
+ collection: signInCollections.userCodes,
76
+ id: hash
77
+ });
78
+ /** A row in `signin-expiry`: its grant's padded `expiresAt`, then the grant's ID. */
79
+ const expiryId = (expiresAt, id) => `${String(expiresAt).padStart(16, "0")}.${id}`;
80
+ const expiryKey = (expiresAt, id) => ({
81
+ collection: signInCollections.expiry,
82
+ id: expiryId(expiresAt, id)
83
+ });
84
+ const expiryOf = (row) => Number(row.id.slice(0, 16));
85
+ /** Every row a grant has: itself, its user code's, and its expiry's. */
86
+ const grantRows = (id, grant) => {
87
+ const keys = [grantKey(id), expiryKey(grant.expiresAt, id)];
88
+ if (grant.kind === "device") keys.push(userCodeKey(grant.userCode));
89
+ return keys;
90
+ };
91
+ const contended = () => fail("UNAVAILABLE", "Too many sign-ins reached the server at once", { hint: "Try again" });
92
+ const read = (store, reads) => storeCall(() => store.read(signInScope, reads));
93
+ const commit = (store, version, put, deleted) => Effect.map(storeCall(() => store.commit(signInScope, {
94
+ id: newChangeId(),
95
+ expect: version,
96
+ put,
97
+ delete: deleted
98
+ })), (committed) => committed.ok);
99
+ const decodeGrant = (row) => decodeRow(Grant, row, "A sign-in grant");
100
+ /** The keys of up to `sweepBatch` grants that expired by `now`, read as `rows` from `signin-expiry`. */
101
+ const sweptKeys = Effect.fnUntraced(function* (rows, now) {
102
+ const keys = [];
103
+ for (const row of rows.filter((found) => expiryOf(found) <= now)) {
104
+ const { userCode } = yield* decodeRow(ExpiryRow, row, "A sign-in expiry");
105
+ keys.push({
106
+ collection: row.collection,
107
+ id: row.id
108
+ }, grantKey(row.id.slice(17)));
109
+ if (userCode !== void 0) keys.push(userCodeKey(userCode));
110
+ }
111
+ return keys;
112
+ });
113
+ const sweepRead = {
114
+ collection: signInCollections.expiry,
115
+ limit: 100
116
+ };
117
+ /**
118
+ * Puts a new grant, by its code's hash `id`, and its user code's row if it has one, sweeping up
119
+ * to `sweepBatch` expired grants in the same commit. `false` when another grant's rows hold the
120
+ * user code still, so the caller makes another.
121
+ */
122
+ const putGrant = Effect.fnUntraced(function* (store, now, id, grant) {
123
+ const put = [{
124
+ ...grantKey(id),
125
+ value: grant
126
+ }];
127
+ const expiry = {};
128
+ if (grant.kind === "device") {
129
+ put.push({
130
+ ...userCodeKey(grant.userCode),
131
+ value: { grant: id }
132
+ });
133
+ expiry.userCode = grant.userCode;
134
+ }
135
+ put.push({
136
+ ...expiryKey(grant.expiresAt, id),
137
+ value: expiry
138
+ });
139
+ const reads = grant.kind === "device" ? [sweepRead, { ...userCodeKey(grant.userCode) }] : [sweepRead];
140
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
141
+ const snapshot = yield* read(store, reads);
142
+ const swept = yield* sweptKeys(snapshot.results[0] ?? [], now);
143
+ if ((snapshot.results[1]?.length ?? 0) > 0) return false;
144
+ if (yield* commit(store, snapshot.version, put, swept)) return true;
145
+ }
146
+ return yield* contended();
147
+ });
148
+ const readUserCodeGrant = Effect.fnUntraced(function* (store, userCode) {
149
+ const row = (yield* read(store, [{ ...userCodeKey(userCode) }])).results[0]?.[0];
150
+ if (row === void 0) return void 0;
151
+ const { grant: id } = yield* decodeRow(UserCodeRow, row, "A user code");
152
+ const grants = yield* read(store, [{ ...grantKey(id) }]);
153
+ const found = grants.results[0]?.[0];
154
+ if (found === void 0) return void 0;
155
+ const grant = yield* decodeGrant(found);
156
+ if (grant.kind !== "device" || grant.userCode !== userCode) return void 0;
157
+ return {
158
+ id,
159
+ grant,
160
+ version: grants.version
161
+ };
162
+ });
163
+ const isPending = (grant, now) => grant.decision === void 0 && now < grant.expiresAt;
164
+ /** The grant a user code's hash names, and whether it can still be decided. */
165
+ const findUserCode = Effect.fnUntraced(function* (store, now, userCode) {
166
+ const found = yield* readUserCodeGrant(store, userCode);
167
+ if (found === void 0) return { kind: "unknown" };
168
+ if (!isPending(found.grant, now)) return { kind: "spent" };
169
+ return {
170
+ kind: "pending",
171
+ id: found.id,
172
+ grant: found.grant
173
+ };
174
+ });
175
+ /** Sets a pending device grant's decision, once: fenced on the grant still pending. */
176
+ const decideDevice = Effect.fnUntraced(function* (store, now, userCode, id, decision) {
177
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
178
+ const found = yield* readUserCodeGrant(store, userCode);
179
+ if (found === void 0 || found.id !== id) return { kind: "unknown" };
180
+ if (!isPending(found.grant, yield* now)) return { kind: "spent" };
181
+ const value = {
182
+ ...found.grant,
183
+ decision
184
+ };
185
+ if (yield* commit(store, found.version, [{
186
+ ...grantKey(id),
187
+ value
188
+ }], [])) return { kind: "decided" };
189
+ }
190
+ return yield* contended();
191
+ });
192
+ /**
193
+ * A device's poll for `id`, its device code's hash. Pending, it records the poll, and answers
194
+ * `slow-down` with 5 more seconds sooner than `interval` after the last. Decided, it deletes every
195
+ * row of the grant in a commit fenced on what it read, so one poll alone wins it. Expired, it
196
+ * writes nothing: the sweep deletes it.
197
+ */
198
+ const pollDevice = Effect.fnUntraced(function* (store, now, clientId, id) {
199
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
200
+ const snapshot = yield* read(store, [{ ...grantKey(id) }]);
201
+ const row = snapshot.results[0]?.[0];
202
+ if (row === void 0) return { kind: "unknown" };
203
+ const grant = yield* decodeGrant(row);
204
+ if (grant.kind !== "device" || grant.clientId !== clientId) return { kind: "unknown" };
205
+ const at = yield* now;
206
+ if (at >= grant.expiresAt) return { kind: "expired" };
207
+ const { decision } = grant;
208
+ if (decision !== void 0) {
209
+ if (!(yield* commit(store, snapshot.version, [], grantRows(id, grant)))) continue;
210
+ return decision.kind === "deny" ? { kind: "denied" } : {
211
+ kind: "approved",
212
+ approval: decision,
213
+ scopes: grant.scopes
214
+ };
215
+ }
216
+ const early = grant.polledAt !== void 0 && at - grant.polledAt < grant.interval * 1e3;
217
+ const interval = early ? grant.interval + 5 : grant.interval;
218
+ const value = {
219
+ ...grant,
220
+ polledAt: at,
221
+ interval
222
+ };
223
+ if (!(yield* commit(store, snapshot.version, [{
224
+ ...grantKey(id),
225
+ value
226
+ }], []))) continue;
227
+ return early ? {
228
+ kind: "slow-down",
229
+ interval
230
+ } : { kind: "pending" };
231
+ }
232
+ return yield* contended();
233
+ });
234
+ /**
235
+ * A web code's exchange, by `id`, its hash: once, by deleting its rows in a commit fenced on what
236
+ * it read. `undefined` for any code this exchange can't use, unknown, expired, or another
237
+ * client's, callback's or verifier's alike.
238
+ */
239
+ const exchangeWeb = Effect.fnUntraced(function* (store, now, id, claim) {
240
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
241
+ const snapshot = yield* read(store, [{ ...grantKey(id) }]);
242
+ const row = snapshot.results[0]?.[0];
243
+ if (row === void 0) return void 0;
244
+ const grant = yield* decodeGrant(row);
245
+ if (grant.kind !== "web" || grant.clientId !== claim.clientId) return void 0;
246
+ if ((yield* now) >= grant.expiresAt) return void 0;
247
+ if ((claim.redirectUri ?? (grant.redirectSent ? void 0 : grant.redirectUri)) !== grant.redirectUri) return void 0;
248
+ if (!(yield* claim.proves(grant.challenge))) return void 0;
249
+ if (!(yield* commit(store, snapshot.version, [], grantRows(id, grant)))) continue;
250
+ return {
251
+ approval: grant.decision,
252
+ scopes: grant.scopes
253
+ };
254
+ }
255
+ return yield* contended();
256
+ });
257
+ export { approvalOf, decideDevice, exchangeWeb, findUserCode, pollDevice, putGrant, signInCollections, signInScope };