@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,1036 @@
1
+ import { hostCall } from "../auth/host-function.mjs";
2
+ import { retriedCodes } from "../core/push.mjs";
3
+ import { mergedTree } from "../core/objects/commit-writes.mjs";
4
+ import { openRead, readerOf } from "../core/objects/reading.mjs";
5
+ import { MadeObjects, madeCommit } from "../core/objects/writing.mjs";
6
+ import { mergeBases } from "../engine/merge-bases.mjs";
7
+ import { limitsOf } from "../engine/reads.mjs";
8
+ import { historyUpTo } from "../engine/walk.mjs";
9
+ import "../protocol/objects/object.mjs";
10
+ import { memoryPack } from "../storage/fetch.mjs";
11
+ import { gitObjectOf } from "../storage/object-rows.mjs";
12
+ import { decodeRow, fail, gitError } from "../store/errors.mjs";
13
+ import { runJobTry } from "../store/crossing.mjs";
14
+ import { readRecord } from "../store/repo-record.mjs";
15
+ import { isLive, liveState } from "../store/reservations.mjs";
16
+ import { collections, jobRepo } from "../store/scopes.mjs";
17
+ import { openCandidate, pinnedEvent, restartTarget } from "./calls.mjs";
18
+ import { queueWrite } from "./commit.mjs";
19
+ import { queueRef } from "./ids.mjs";
20
+ import { askCallers, callerKey, callersOf, entryEnvelope } from "./callers.mjs";
21
+ import { CandidateRow } from "./rows.mjs";
22
+ import { queueLimits } from "./limits.mjs";
23
+ import { lanesOf, opensAlone, placeOf, placed } from "./lanes.mjs";
24
+ import { concurrencyOf, roomFor, schedulesOf } from "./schedule.mjs";
25
+ import { blameGroup, failEntries, groupsOf, openSearched, passGroup, reportDetails, splitGroup, splitMost, startSearch } from "./search.mjs";
26
+ import { QueuePlan, entryNotes, loadTarget, openHolds, orderOf } from "./state.mjs";
27
+ import { AdvanceData, CandidateData, advanceName, buildName, buildRow, timeoutName, timeoutRow } from "../store/queue-jobs.mjs";
28
+ import { addTargetHold, advanceAfter, closeAll, closeCandidate, endEntry, entryOf, isOpen, movedOutside, releaseHold, removeEntry, stackOf, workHolds } from "./steps.mjs";
29
+ import { defineJob, millis } from "@ref0/infra";
30
+ import * as Effect from "effect/Effect";
31
+ import * as Schema from "effect/Schema";
32
+ import * as Predicate from "effect/Predicate";
33
+ import * as Clock from "effect/Clock";
34
+ // src/queue/advance.ts
35
+ /**
36
+ * The queue's three jobs. `git.queue.advance`, one per target, moves it on a step at a time: a
37
+ * tip moved by anything but the queue restarts its candidates, a passed candidate publishes, a
38
+ * failed one fails its entries, and with none open the next entry opens one. `git.queue.build`
39
+ * writes a candidate's commits; `git.queue.report-timeout` closes one whose report is late.
40
+ */
41
+ /** Steps one advance run takes before it asks for another, due now, for the rest. */
42
+ const stepsMost = 10;
43
+ /** Commits one entry's link reads from its head, its own history past the target's tip. */
44
+ const linkCommitsMost = 1e3;
45
+ const idleStep = { moved: false };
46
+ const againStep = { moved: true };
47
+ const liftedStep = {
48
+ moved: true,
49
+ lifted: true
50
+ };
51
+ /** The core a job writes with: the server's, its store the job's claim-fenced one. */
52
+ const fenced = (core, context) => ({
53
+ ...core,
54
+ store: context.store
55
+ });
56
+ /** A plan's write by the queue itself, its rules skipped: the calls that led to it were checked. */
57
+ const queueOwn = (host, context, plan, answer) => ({
58
+ kind: "write",
59
+ core: fenced(host.hostCore, context),
60
+ caller: host.caller,
61
+ repo: plan.state.record.name,
62
+ plan,
63
+ answer,
64
+ signal: context.signal
65
+ });
66
+ /**
67
+ * A plan that lifts the target's `work-failed` holds waiting on `work`, the job running again
68
+ * after a retry or a wake: `undefined` with none. Its job's next step runs after it.
69
+ */
70
+ const liftWork = (state, work, now) => {
71
+ const holds = workHolds(state, work);
72
+ if (holds.length === 0) return void 0;
73
+ const plan = new QueuePlan(state, now);
74
+ for (const [id, row] of holds) releaseHold(plan, id, row);
75
+ return plan;
76
+ };
77
+ /**
78
+ * A passed candidate's publish: the target to `commit`, and its entries merged, in one push. Each
79
+ * entry's `queue.entry.merged` names its own caller; the push's other events, the first's.
80
+ * `judged`: `tree` for the commit it checked, built on the tip with only its own entries, and
81
+ * `lane` for its land's, its entries linked again onto a tip that moved, or past what it carried. A
82
+ * commit the target is at already moves nothing: its entries added nothing the target lacks.
83
+ */
84
+ const publishPlan = (state, now, id, row, commit, judged, callers) => {
85
+ const plan = new QueuePlan(state, now);
86
+ if (commit !== state.tip) plan.edits.push({
87
+ ref: state.target,
88
+ from: state.tip,
89
+ to: commit
90
+ });
91
+ const heads = row.entries.flatMap((entry) => {
92
+ const its = state.entries.get(entry);
93
+ const caller = callers.get(entry);
94
+ return its === void 0 || caller === void 0 ? [] : [{
95
+ entry,
96
+ head: its.head,
97
+ caller
98
+ }];
99
+ });
100
+ const whole = heads.length === row.entries.length;
101
+ if (commit !== state.tip) plan.publishes.set(state.target, whole ? heads : []);
102
+ for (const entry of row.entries) {
103
+ const own = state.entries.get(entry);
104
+ endEntry(plan, entry, "merged");
105
+ plan.event((envelope) => ({
106
+ type: "queue.entry.merged",
107
+ ...own === void 0 ? envelope : entryEnvelope(envelope, own),
108
+ entry,
109
+ candidate: id,
110
+ commit
111
+ }));
112
+ }
113
+ closeCandidate(plan, id, "merged");
114
+ plan.event((envelope) => ({
115
+ type: "queue.candidate.closed",
116
+ ...envelope,
117
+ candidate: id,
118
+ reason: "merged",
119
+ commit,
120
+ judged
121
+ }));
122
+ plan.setTarget({
123
+ ...plan.row,
124
+ tip: commit
125
+ });
126
+ return plan;
127
+ };
128
+ /**
129
+ * The entries of `candidate` whose callers, asked again, no longer hold: failed `refused`, each
130
+ * with its own reason, the candidate closed and its other entries waiting again, so they land only
131
+ * on a candidate built without them. `held` when every caller holds, with each one's caller and
132
+ * each entry's.
133
+ */
134
+ const askedPlan = Effect.fnUntraced(function* (host, context, state, now, id, candidate, edits) {
135
+ const callers = callersOf(state, candidate.entries);
136
+ const asked = yield* askCallers(host, state, callers, edits, now, context.signal);
137
+ const plan = new QueuePlan(state, now);
138
+ let refused = false;
139
+ for (const one of asked) {
140
+ if (one.asked.kind === "caller") continue;
141
+ failEntries(plan, id, one.entries, "refused", { summary: one.asked.error.message });
142
+ refused = true;
143
+ }
144
+ if (refused) return {
145
+ kind: "refused",
146
+ plan
147
+ };
148
+ const held = asked.flatMap((one) => one.asked.kind === "caller" ? [one.asked.caller] : []);
149
+ const byEntry = new Map(asked.flatMap(({ asked: its, entries }) => its.kind === "caller" ? entries.map((entry) => [entry, its.caller]) : []));
150
+ return {
151
+ kind: "held",
152
+ callers: held,
153
+ entries: asked.map((one) => one.entries),
154
+ byEntry
155
+ };
156
+ });
157
+ /**
158
+ * The plan for a failed candidate in the row, as `search.ts` says: its blamed entries fail, or
159
+ * its one entry, or a recheck's all, `interaction`; else its bisect starts, while the target has
160
+ * room for one, and with none its entries wait again, none failed.
161
+ */
162
+ const failedPlan = Effect.fnUntraced(function* (host, state, now, options, { id, candidate }) {
163
+ const plan = new QueuePlan(state, now);
164
+ const details = reportDetails(candidate.report);
165
+ const blame = candidate.blame ?? [];
166
+ const { entries } = candidate;
167
+ if (blame.length > 0 || entries.length === 1) failEntries(plan, id, blame.length > 0 ? blame : entries, "reported", details);
168
+ else if (candidate.recheck === true) failEntries(plan, id, entries, "interaction", details);
169
+ else if ((state.row.searches ?? []).length >= queueLimits.searches) closeCandidate(plan, id, "failed");
170
+ else startSearch(plan, id, yield* groupsOf(host, state, options, id, candidate, 2 * entries.length));
171
+ return plan;
172
+ });
173
+ /** The plan for a bisect group's report: a pass, a failure of what it blamed or held, or a split. */
174
+ const judgedPlan = Effect.fnUntraced(function* (host, state, now, options, { id, candidate }) {
175
+ const plan = new QueuePlan(state, now);
176
+ const blame = candidate.blame ?? [];
177
+ const { entries } = candidate;
178
+ if (candidate.report?.verdict === "pass") passGroup(plan, id);
179
+ else if (blame.length > 0 || entries.length === 1) blameGroup(plan, id, blame.length > 0 ? blame : entries, reportDetails(candidate.report));
180
+ else splitGroup(plan, id, yield* groupsOf(host, state, options, id, candidate, splitMost(plan, id)));
181
+ return plan;
182
+ });
183
+ /**
184
+ * One step of the target's advance, planned over what it reads: `again` once it moved the target
185
+ * on, so the next step may too, and `idle` once nothing's left until a report, a build or a
186
+ * batch's `wait`, when `at`. Its open candidates stand in lanes, each on the tip or the newest
187
+ * ahead of it in its lanes, and one publishes at a time, as `publishOf` says; bisect groups stand
188
+ * beside them, on their failed candidate's base. A plan that publishes names its candidate in
189
+ * `tried`.
190
+ */
191
+ const advanceStep = (host, context, internalId, target, tried) => Effect.gen(function* () {
192
+ delete tried.candidate;
193
+ const state = yield* loadTarget(context.store, internalId, target);
194
+ const { row } = state;
195
+ const idle = {
196
+ kind: "done",
197
+ answer: idleStep
198
+ };
199
+ const options = yield* host.options(state.record.name);
200
+ if (options === void 0) return idle;
201
+ const now = yield* host.core.now;
202
+ const lifted = liftWork(state, {
203
+ name: advanceName,
204
+ key: target
205
+ }, now);
206
+ if (lifted !== void 0) return queueOwn(host, context, lifted, againStep);
207
+ const moved = movedOutside(state);
208
+ const searching = (row.searches ?? []).length > 0;
209
+ if (moved && state.tip === null) {
210
+ const plan = new QueuePlan(state, now);
211
+ closeAll(plan, "restarted");
212
+ plan.setTarget({
213
+ ...plan.row,
214
+ tip: null,
215
+ stalled: true,
216
+ deleted: true
217
+ });
218
+ return queueOwn(host, context, plan, againStep);
219
+ }
220
+ if (moved && state.tip !== null && (row.open.length > 0 || searching || row.stalled === true)) {
221
+ const plan = new QueuePlan(state, now);
222
+ restartTarget(plan, state.tip);
223
+ return queueOwn(host, context, plan, againStep);
224
+ }
225
+ const opened = (ids) => ids.flatMap((id) => {
226
+ const candidate = state.candidates.get(id);
227
+ return candidate === void 0 ? [] : [{
228
+ id,
229
+ candidate
230
+ }];
231
+ });
232
+ const stack = opened(stackOf(state));
233
+ const failed = stack.find(({ candidate }) => candidate.report?.verdict === "fail");
234
+ if (failed !== void 0) {
235
+ const plan = yield* failedPlan(host, state, now, options, failed);
236
+ return queueOwn(host, context, plan, againStep);
237
+ }
238
+ const judged = opened(row.open).find(({ candidate }) => candidate.group !== void 0 && candidate.report !== void 0);
239
+ if (judged !== void 0) {
240
+ const plan = yield* judgedPlan(host, state, now, options, judged);
241
+ return queueOwn(host, context, plan, againStep);
242
+ }
243
+ const { reserved } = row;
244
+ const holder = reserved === void 0 ? void 0 : yield* liveState(context.store, reserved);
245
+ const decided = holder === "publishing" ? reserved : void 0;
246
+ const publish = row.holds.length === 0 && (holder === void 0 || decided !== void 0) ? publishOf(state, stack, decided) : void 0;
247
+ if (publish?.kind === "land") {
248
+ const plan = new QueuePlan(state, now);
249
+ const { built: _built, ...passed } = publish.open.candidate;
250
+ plan.setCandidate(publish.open.id, {
251
+ ...passed,
252
+ landing: true
253
+ });
254
+ plan.jobs.push(buildRow(publish.open.id));
255
+ return queueOwn(host, context, plan, againStep);
256
+ }
257
+ if (publish?.kind === "publish") {
258
+ const { id, candidate } = publish.open;
259
+ const edits = publish.commit === state.tip ? [] : [{
260
+ ref: state.target,
261
+ from: state.tip,
262
+ to: publish.commit
263
+ }];
264
+ const asked = yield* askedPlan(host, context, state, now, id, candidate, edits);
265
+ if (asked.kind === "refused") return queueOwn(host, context, asked.plan, againStep);
266
+ const [caller] = asked.callers;
267
+ if (caller === void 0) return idle;
268
+ const plan = publishPlan(state, now, id, candidate, publish.commit, publish.judged, asked.byEntry);
269
+ if (decided !== void 0) {
270
+ const { reserved: _released, ...released } = plan.row;
271
+ plan.setTarget(released);
272
+ }
273
+ const published = queueOwn(host, context, plan, againStep);
274
+ const refused = [];
275
+ tried.candidate = id;
276
+ tried.callers = asked.entries;
277
+ tried.refused = refused;
278
+ return {
279
+ ...published,
280
+ core: fenced(host.core, context),
281
+ caller,
282
+ queued: {
283
+ callers: asked.callers,
284
+ refused: (at, error, by) => refused.push({
285
+ at,
286
+ error,
287
+ by
288
+ })
289
+ }
290
+ };
291
+ }
292
+ const ended = yield* Effect.filter(row.order, ({ entry }) => {
293
+ const topic = state.entries.get(entry)?.topic;
294
+ return topic === void 0 ? Effect.succeed(false) : Effect.map(isLive(context.store, topic), (live) => !live);
295
+ });
296
+ if (ended.length > 0) {
297
+ const plan = new QueuePlan(state, now);
298
+ for (const { entry } of ended) {
299
+ const topic = state.entries.get(entry)?.topic?.topic ?? "";
300
+ removeEntry(plan, entry, {
301
+ reason: "topic-ended",
302
+ topic
303
+ });
304
+ }
305
+ return queueOwn(host, context, plan, againStep);
306
+ }
307
+ if (row.stalled === true) return idle;
308
+ const schedules = schedulesOf(host, state, options);
309
+ const plan = new QueuePlan(state, now);
310
+ if (yield* openSearched(plan, schedules)) return queueOwn(host, context, plan, againStep);
311
+ const scanned = yield* scan(plan, schedules, stack, holder === void 0 ? void 0 : reserved);
312
+ if (scanned === "opened") return queueOwn(host, context, plan, idleStep);
313
+ return scanned === void 0 ? idle : {
314
+ kind: "done",
315
+ answer: {
316
+ moved: false,
317
+ at: scanned
318
+ }
319
+ };
320
+ });
321
+ /** The topic attempt a candidate's member entry belongs to, if it's a member's. */
322
+ const memberOf = (state, candidate) => candidate.entries.map((entry) => state.entries.get(entry)?.topic).find(Predicate.isNotUndefined);
323
+ /**
324
+ * Whether a candidate may publish under `decided`, the topic whose publish decision holds the
325
+ * target, if one does: only that topic's member then, and otherwise only a candidate of no topic.
326
+ */
327
+ const mayPublish = (state, candidate, decided) => {
328
+ const member = memberOf(state, candidate);
329
+ if (member === void 0 || decided === void 0) return member === decided;
330
+ return member.topic === decided.topic;
331
+ };
332
+ /**
333
+ * The next publish of the target's candidates, bisect groups aside, of those `mayPublish` lets. One
334
+ * landing publishes alone, once its land is built on the tip: it holds the rest. Else a pinned
335
+ * one or a topic's member publishes alone while open, and otherwise the first that passed with
336
+ * none it's built over still open. Built on the tip with only its own entries, it publishes the
337
+ * commit it checked; else it lands first, but for a member, which checked the commit it publishes
338
+ * or none.
339
+ */
340
+ const publishOf = (state, stack, decided) => {
341
+ const landing = stack.find(({ candidate }) => candidate.landing === true);
342
+ if (landing !== void 0) {
343
+ if (!mayPublish(state, landing.candidate, decided)) return void 0;
344
+ const { landed } = landing.candidate;
345
+ if (landed === void 0 || landed.tip !== state.tip) return void 0;
346
+ return {
347
+ kind: "publish",
348
+ open: landing,
349
+ commit: landed.commit,
350
+ judged: "lane"
351
+ };
352
+ }
353
+ const pinned = pinnedOf(state, stack);
354
+ const passed = (pinned.length > 0 ? pinned : stack).find(({ candidate }) => mayPublish(state, candidate, decided) && candidate.report?.verdict === "pass" && candidate.commit !== void 0 && !(candidate.over ?? []).some((over) => state.row.open.includes(over)));
355
+ const commit = passed?.candidate.commit;
356
+ if (passed === void 0 || commit === void 0) return void 0;
357
+ if (passed.candidate.base === state.tip && passed.candidate.carried === void 0) return {
358
+ kind: "publish",
359
+ open: passed,
360
+ commit,
361
+ judged: "tree"
362
+ };
363
+ return memberOf(state, passed.candidate) === void 0 ? {
364
+ kind: "land",
365
+ open: passed
366
+ } : void 0;
367
+ };
368
+ /** The open candidates holding a pinned entry: one at most, which holds every lane while open. */
369
+ const pinnedOf = (state, stack) => stack.filter(({ candidate }) => candidate.entries.some((entry) => {
370
+ const row = state.entries.get(entry);
371
+ return row !== void 0 && opensAlone(row);
372
+ }));
373
+ /**
374
+ * Opens the next candidate in the target's order, lane by lane: the oldest waiting entry whose
375
+ * lanes have room and a place, with the waiting entries after it in no other lane, up to the
376
+ * smallest `maxSize` among its lanes. An entry that can't open blocks its lanes, and every entry
377
+ * after it in any of them waits, so each lane opens in order. A pinned entry opens alone, on the
378
+ * tip, with nothing landing and no other pinned one open, so nothing moves the tip under it till it
379
+ * ends. A topic's member waits, blocking its lanes, till its topic reserves the target, and while
380
+ * `live`, a topic's reservation, holds it, only that topic's member opens, wherever it is in the
381
+ * order. `opened` once it opened one, else when a short batch's `wait` ends.
382
+ */
383
+ const scan = Effect.fnUntraced(function* (plan, schedules, stack, live) {
384
+ const { state } = plan;
385
+ const held = stack.some(({ candidate }) => candidate.landing === true) || pinnedOf(state, stack).length > 0;
386
+ const waiting = orderOf(state.row.order).filter((place) => state.entries.get(place.entry)?.state === "waiting");
387
+ const blocked = /* @__PURE__ */ new Set();
388
+ let soonest;
389
+ for (const [at, place] of waiting.entries()) {
390
+ const row = state.entries.get(place.entry);
391
+ if (row === void 0) continue;
392
+ const lanes = new Set(lanesOf(row));
393
+ const block = () => lanes.forEach((lane) => blocked.add(lane));
394
+ const { topic } = row;
395
+ if (live !== void 0 && topic?.topic !== live.topic) continue;
396
+ if (live === void 0 && topic !== void 0) {
397
+ block();
398
+ continue;
399
+ }
400
+ if (live === void 0 && [...lanes].some((lane) => blocked.has(lane))) {
401
+ block();
402
+ continue;
403
+ }
404
+ const placement = placeOf(plan, lanes);
405
+ const room = yield* roomFor(schedules, plan, lanes);
406
+ if (opensAlone(row)) {
407
+ if (held || placement.at !== "tip" || !room) {
408
+ block();
409
+ continue;
410
+ }
411
+ openCandidate(plan, [place.entry], placement, yield* concurrencyOf(schedules, lanes));
412
+ return "opened";
413
+ }
414
+ if (!room || !placed(placement)) {
415
+ block();
416
+ continue;
417
+ }
418
+ let maxSize = queueLimits.candidateEntries;
419
+ let wait = Number.POSITIVE_INFINITY;
420
+ for (const lane of lanes) {
421
+ const schedule = yield* schedules.of(lane);
422
+ maxSize = Math.min(maxSize, schedule.maxSize);
423
+ wait = Math.min(wait, schedule.wait);
424
+ }
425
+ const batch = [place];
426
+ const callers = /* @__PURE__ */ new Set([callerKey(row)]);
427
+ let closed = row.alone === true;
428
+ for (const later of waiting.slice(at + 1)) {
429
+ if (closed || batch.length >= maxSize) break;
430
+ const laterRow = state.entries.get(later.entry);
431
+ const own = laterRow === void 0 ? [] : lanesOf(laterRow);
432
+ if (laterRow === void 0 || !own.some((lane) => lanes.has(lane))) continue;
433
+ if (opensAlone(laterRow) || !own.every((lane) => lanes.has(lane))) break;
434
+ const key = callerKey(laterRow);
435
+ const past = !callers.has(key) && callers.size >= queueLimits.candidateCallers;
436
+ closed = laterRow.alone === true || past;
437
+ if (closed) break;
438
+ callers.add(key);
439
+ batch.push(later);
440
+ }
441
+ const due = Math.min(...batch.map((open) => open.since)) + wait;
442
+ if (!closed && batch.length < maxSize && due > plan.now) {
443
+ block();
444
+ soonest = Math.min(soonest ?? Number.MAX_SAFE_INTEGER, due);
445
+ continue;
446
+ }
447
+ const entries = batch.map((open) => open.entry);
448
+ openCandidate(plan, entries, placement, yield* concurrencyOf(schedules, lanes));
449
+ return "opened";
450
+ }
451
+ return soonest;
452
+ });
453
+ /**
454
+ * A publish of `id` the push refused for good, while it's still open with its pass: a call since,
455
+ * such as a remove or a restart, may have closed it. The candidate closes, and its entries each
456
+ * end as their caller's refusal says, the rest waiting again for a candidate built without them:
457
+ *
458
+ * - A caller refused its sight or its credential fails its entries `refused`, with why.
459
+ * - A caller a rule or the hook refused fails its entries `refused` in a candidate of one entry.
460
+ * In a batch, the rule judged the whole move, which may have been another entry's change: its
461
+ * entries wait again, each to open alone, so their next publish judges their own change.
462
+ * - A refusal no caller was told of fails every entry `refused`.
463
+ */
464
+ const refusePublish = (host, context, internalId, target, tried, error) => queueWrite(Effect.gen(function* () {
465
+ const id = tried.candidate;
466
+ const state = yield* loadTarget(context.store, internalId, target);
467
+ const candidate = state.candidates.get(id);
468
+ if (!(state.row.open.includes(id) && candidate?.report?.verdict === "pass") || candidate === void 0) return {
469
+ kind: "done",
470
+ answer: againStep
471
+ };
472
+ const plan = new QueuePlan(state, yield* host.core.now);
473
+ const blamed = error.context?.["reason"] === "entry-unpublishable" ? error.context["entries"] : void 0;
474
+ if (Array.isArray(blamed)) {
475
+ const failing = candidate.entries.filter((entry) => blamed.includes(entry));
476
+ failEntries(plan, id, failing, "refused", { summary: error.message });
477
+ return queueOwn(host, context, plan, againStep);
478
+ }
479
+ const refused = tried.refused ?? [];
480
+ if (refused.length === 0) {
481
+ failEntries(plan, id, candidate.entries, "refused", { summary: error.message });
482
+ return queueOwn(host, context, plan, againStep);
483
+ }
484
+ const batched = candidate.entries.length > 1;
485
+ closeCandidate(plan, id, "failed");
486
+ for (const { at, error: why, by } of refused) {
487
+ const entries = tried.callers?.[at] ?? [];
488
+ if (by === "access" || !batched) {
489
+ failEntries(plan, id, entries, "refused", { summary: why.message });
490
+ continue;
491
+ }
492
+ for (const entry of entries) {
493
+ const row = plan.entries.get(entry);
494
+ if (row !== void 0 && isOpen(row)) plan.setEntry(entry, {
495
+ ...row,
496
+ alone: true
497
+ });
498
+ }
499
+ }
500
+ return queueOwn(host, context, plan, againStep);
501
+ }));
502
+ const advance = (host, job, context) => Effect.gen(function* () {
503
+ const internalId = jobRepo(job);
504
+ const { target } = job.data;
505
+ for (let step = 0; step < stepsMost; step += 1) {
506
+ const tried = {};
507
+ const moved = yield* queueWrite(advanceStep(host, context, internalId, target, tried)).pipe(Effect.catch((error) => retriedCodes.has(error.code) || tried.candidate === void 0 ? Effect.fail(error) : refusePublish(host, context, internalId, target, {
508
+ ...tried,
509
+ candidate: tried.candidate
510
+ }, error)));
511
+ if (!moved.moved) return moved.at === void 0 ? void 0 : {
512
+ kind: "more",
513
+ at: moved.at
514
+ };
515
+ }
516
+ return { kind: "more" };
517
+ });
518
+ /** A candidate's row and its target's state, read together: `undefined` once it's gone. */
519
+ const loadCandidate = Effect.fnUntraced(function* (context, internalId, id) {
520
+ const read = {
521
+ collection: collections.queueCandidates,
522
+ id
523
+ };
524
+ const { snapshot } = yield* readRecord(context.store, internalId, [read]);
525
+ const [found] = snapshot.results[1] ?? [];
526
+ if (found === void 0) return void 0;
527
+ const first = yield* decodeRow(CandidateRow, found, `The candidate '${id}'`);
528
+ const also = {
529
+ candidates: [id],
530
+ entries: first.carried ?? []
531
+ };
532
+ const state = yield* loadTarget(context.store, internalId, first.target, also);
533
+ const row = state.candidates.get(id);
534
+ return row === void 0 ? void 0 : {
535
+ state,
536
+ row
537
+ };
538
+ });
539
+ /**
540
+ * A candidate job's lift of its `work-failed` holds, which wakes advance for the target they held:
541
+ * its job then runs its step again. A job doesn't know a retry from a first try, which both have
542
+ * attempt 1, so every try reads the target for them, in the read its step makes anyway.
543
+ */
544
+ const liftCandidateWork = (host, context, state, now, name, key) => {
545
+ const plan = liftWork(state, {
546
+ name,
547
+ key
548
+ }, now);
549
+ if (plan === void 0) return void 0;
550
+ advanceAfter(plan);
551
+ return queueOwn(host, context, plan, liftedStep);
552
+ };
553
+ var LinkFailed = class {
554
+ failure;
555
+ entry;
556
+ constructor(entry, failure) {
557
+ this.entry = entry;
558
+ this.failure = failure;
559
+ }
560
+ };
561
+ /**
562
+ * What `head` adds past `tip`, oldest first, read in one walk; more than a link reads fails the
563
+ * entry, so the walk stops one past it.
564
+ */
565
+ const commitsPast = (linking, entry, head, tip) => historyUpTo(linking.opened.read, {
566
+ wants: [head],
567
+ haves: [tip]
568
+ }, 1001, linking.call).pipe(Effect.flatMap((walked) => {
569
+ if (walked.length <= linkCommitsMost) return Effect.succeed([...walked].reverse());
570
+ const summary = `${entry} adds more than ${linkCommitsMost} commits, more than a link reads`;
571
+ return Effect.fail(new LinkFailed(entry, {
572
+ kind: "conflict",
573
+ summary
574
+ }));
575
+ }));
576
+ const isConflict = (error) => error.code === "FAILED_PRECONDITION" && error.context?.reason === "merge-conflict";
577
+ /** A merge's tree onto `ours`, or the entry's `conflict` when it doesn't merge. */
578
+ const treeOf = (linking, entry, sides) => mergedTree(linking.core, linking.opened, linking.made, sides, {}, linking.call).pipe(Effect.mapError((error) => isConflict(error) ? new LinkFailed(entry, {
579
+ kind: "conflict",
580
+ summary: error.message
581
+ }) : error));
582
+ /** The host's plan for an entry's link: a throw fails it `host-error`, with the failure's ID. */
583
+ const planOf = (linking, entry, row, commits) => hostCall(linking.core.checks.reports, "queue.merge", { repo: linking.repo }, () => linking.options.merge({
584
+ entry: entryOf(linking.repo, entry, row, linking.notes.get(entry) ?? {}),
585
+ commits
586
+ })).pipe(Effect.catch((error) => {
587
+ const id = error.code === "UNAVAILABLE" || error.code === "DEADLINE_EXCEEDED" ? error.context?.id ?? "" : "";
588
+ return Effect.fail(new LinkFailed(entry, {
589
+ kind: "host-error",
590
+ error: id
591
+ }));
592
+ }));
593
+ /** One entry's link onto `tip`, as its plan's method says: the commit the candidate is at after. */
594
+ const linkOnto = (linking, entry, row, tip) => Effect.gen(function* () {
595
+ const { head } = row;
596
+ const { bases } = yield* mergeBases(linking.opened.read, { commits: [tip, head] }, linking.call);
597
+ if (bases.includes(head)) return tip;
598
+ const [base] = bases;
599
+ if (base === void 0 || bases.length > 1) {
600
+ const summary = base === void 0 ? `${row.source} shares no history with ${row.target}` : `${row.source} and ${row.target} have ${bases.length} merge bases`;
601
+ return yield* Effect.fail(new LinkFailed(entry, {
602
+ kind: "conflict",
603
+ summary
604
+ }));
605
+ }
606
+ const commits = yield* commitsPast(linking, entry, head, tip);
607
+ const plan = yield* planOf(linking, entry, row, commits);
608
+ const { author, message } = plan;
609
+ if (plan.method === "rebase") {
610
+ let onto = tip;
611
+ for (const commit of commits) {
612
+ if (commit.parents.length > 1) {
613
+ const summary = `${commit.oid} is a merge commit, which a rebase can't replay`;
614
+ return yield* Effect.fail(new LinkFailed(entry, {
615
+ kind: "conflict",
616
+ summary
617
+ }));
618
+ }
619
+ const sides = {
620
+ base: commit.parents[0] ?? "4b825dc642cb6eb9a060e54bf8d69288fbee4904",
621
+ ours: onto,
622
+ theirs: commit.oid
623
+ };
624
+ const fields = {
625
+ tree: yield* treeOf(linking, entry, sides),
626
+ parents: [onto],
627
+ author: commit.author,
628
+ committer: author,
629
+ message: commit.message
630
+ };
631
+ onto = yield* madeCommit(linking.made, fields);
632
+ }
633
+ return onto;
634
+ }
635
+ const tree = yield* treeOf(linking, entry, {
636
+ base,
637
+ ours: tip,
638
+ theirs: head
639
+ });
640
+ const parents = plan.method === "merge" ? [tip, head] : [tip];
641
+ return yield* madeCommit(linking.made, {
642
+ tree,
643
+ parents,
644
+ author,
645
+ committer: author,
646
+ message
647
+ });
648
+ });
649
+ /** The reasons a link stops at a bound its try shares with the links before it. */
650
+ const sharedLimits = /* @__PURE__ */ new Set([
651
+ "walk-limit",
652
+ "diff-limit",
653
+ "too-large"
654
+ ]);
655
+ /** A failure at one of a try's shared limits: its time, its reads or its write. */
656
+ const atLimit = (error) => error.code === "RESOURCE_EXHAUSTED" && sharedLimits.has(error.context?.reason);
657
+ /**
658
+ * Whether a build should stop after this link and go on in a try of its own: past half of what
659
+ * one write holds, half its reads, or half its time.
660
+ */
661
+ const spent = (made, call) => Effect.map(Clock.currentTimeMillis, (now) => {
662
+ const { tally, deadline } = call;
663
+ return made.bytes > 33554432 || tally.objects > tally.limits.objects / 2 || tally.bytes > tally.limits.bytes / 2 || now > deadline.at - deadline.milliseconds / 2;
664
+ });
665
+ /**
666
+ * A candidate's commits, one link per entry onto its base, those it carries first, and its ref
667
+ * created at the last, in one push with its objects; an entry that won't link fails, and the
668
+ * candidate closes. A build past half its limits, or one whose later link runs past them, saves
669
+ * its finished links' objects and where they got to, `built`, and goes on in its job's next try.
670
+ * A bisect group never publishes here: it only judges.
671
+ *
672
+ * A passed candidate `landing` links its own entries again, onto the tip, and keeps the commit as
673
+ * `landed`, which advance publishes. One that won't link closes `restarted`, its entries waiting
674
+ * again, each a land conflict nearer to pinned; a `merge` that fails fails its entry.
675
+ */
676
+ const buildStep = (host, context, internalId, id, tried) => Effect.gen(function* () {
677
+ delete tried.candidate;
678
+ delete tried.callers;
679
+ delete tried.refused;
680
+ const done = {
681
+ kind: "done",
682
+ answer: idleStep
683
+ };
684
+ const loaded = yield* loadCandidate(context, internalId, id);
685
+ if (loaded === void 0) return done;
686
+ const now = yield* host.core.now;
687
+ const lifted = liftCandidateWork(host, context, loaded.state, now, buildName, id);
688
+ if (lifted !== void 0) return lifted;
689
+ const { state, row } = loaded;
690
+ const landing = row.state === "checking" && row.landing === true && row.landed === void 0;
691
+ if (row.state !== "building" && !landing) return done;
692
+ const repo = state.record.name;
693
+ const options = yield* host.options(repo);
694
+ if (options === void 0) return done;
695
+ const core = fenced(host.hostCore, context);
696
+ const opened = yield* openRead(core, host.caller, repo);
697
+ const limits = yield* limitsOf();
698
+ const { call } = yield* readerOf(opened, limits, "walk-limit");
699
+ const made = new MadeObjects();
700
+ const read = (input) => {
701
+ const object = made.get(input.oid);
702
+ return object === void 0 ? opened.read(input) : Promise.resolve({
703
+ kind: "success",
704
+ value: gitObjectOf(object)
705
+ });
706
+ };
707
+ const links = landing ? row.entries : [...row.carried ?? [], ...row.entries];
708
+ const from = row.built?.linked ?? 0;
709
+ const rows = links.slice(from).flatMap((entry) => {
710
+ const entryRow = state.entries.get(entry);
711
+ return entryRow === void 0 ? [] : [[entry, entryRow]];
712
+ });
713
+ const notes = yield* entryNotes(context.store, internalId, rows);
714
+ const linking = {
715
+ core,
716
+ opened: {
717
+ ...opened,
718
+ read
719
+ },
720
+ made,
721
+ limits,
722
+ call,
723
+ options,
724
+ repo,
725
+ notes
726
+ };
727
+ let reached = {
728
+ commit: row.built?.commit ?? (landing ? state.tip : row.base),
729
+ at: from,
730
+ objects: 0
731
+ };
732
+ const built = yield* Effect.gen(function* () {
733
+ for (const [entry, entryRow] of rows) {
734
+ const onto = reached.commit;
735
+ reached = {
736
+ commit: onto === null ? entryRow.head : yield* linkOnto(linking, entry, entryRow, onto),
737
+ at: reached.at + 1,
738
+ objects: made.count
739
+ };
740
+ if (reached.at < links.length && (yield* spent(made, call))) break;
741
+ }
742
+ return reached;
743
+ }).pipe(Effect.catchIf((error) => error instanceof LinkFailed, (failed) => Effect.succeed({ failed })), Effect.catchIf((error) => atLimit(error) && reached.at > from, () => Effect.succeed(reached)));
744
+ const plan = new QueuePlan(state, now);
745
+ if ("failed" in built) {
746
+ const { entry, failure } = built.failed;
747
+ const details = failure.kind === "conflict" ? { summary: failure.summary } : { error: failure.error };
748
+ if (landing && failure.kind === "conflict") landConflict(plan, id, row.entries);
749
+ else failEntries(plan, id, [entry], failure.kind, details);
750
+ advanceAfter(plan);
751
+ return queueOwn(host, context, plan, idleStep);
752
+ }
753
+ const { commit, at } = built;
754
+ if (commit === null) return yield* fail("INTERNAL", `The candidate ${id} has no entries`);
755
+ const packed = (own) => Effect.gen(function* () {
756
+ const objects = made.objects.slice(0, built.objects);
757
+ if (objects.length === 0) return own;
758
+ const bytes = objects.reduce((sum, object) => sum + object.bytes.byteLength, 0);
759
+ const pack = yield* memoryPack(objects, {
760
+ bytes,
761
+ milliseconds: limits.milliseconds
762
+ }).pipe(Effect.mapError((error) => gitError("RESOURCE_EXHAUSTED", error.message, { context: { reason: "too-large" } })));
763
+ return {
764
+ ...own,
765
+ pack: {
766
+ bytes: pack.stream,
767
+ objects: objects.length
768
+ }
769
+ };
770
+ });
771
+ if (at < links.length) {
772
+ plan.setCandidate(id, {
773
+ ...row,
774
+ built: {
775
+ linked: at,
776
+ commit
777
+ }
778
+ });
779
+ plan.jobs.push(buildRow(id));
780
+ return yield* packed(queueOwn(host, context, plan, idleStep));
781
+ }
782
+ if (landing) {
783
+ const { built: _built, ...passed } = row;
784
+ plan.setCandidate(id, {
785
+ ...passed,
786
+ landed: {
787
+ tip: state.tip,
788
+ commit
789
+ }
790
+ });
791
+ advanceAfter(plan);
792
+ return yield* packed(queueOwn(host, context, plan, idleStep));
793
+ }
794
+ const alone = memberOf(state, row) === void 0 && row.group === void 0 && row.carried === void 0 && !(row.over ?? []).some((over) => state.row.open.includes(over));
795
+ if (commit === state.tip && row.base === state.tip && alone) {
796
+ const asked = yield* askedPlan(host, context, state, now, id, row, []);
797
+ if (asked.kind === "refused") {
798
+ advanceAfter(asked.plan);
799
+ return queueOwn(host, context, asked.plan, idleStep);
800
+ }
801
+ const [caller] = asked.callers;
802
+ const merged = publishPlan(state, now, id, row, commit, "tree", asked.byEntry);
803
+ advanceAfter(merged);
804
+ const own = queueOwn(host, context, merged, idleStep);
805
+ if (caller === void 0) return own;
806
+ const refused = [];
807
+ tried.candidate = id;
808
+ tried.callers = asked.entries;
809
+ tried.refused = refused;
810
+ return {
811
+ ...own,
812
+ core: fenced(host.core, context),
813
+ caller,
814
+ queued: {
815
+ callers: asked.callers,
816
+ refused: (at, error, by) => refused.push({
817
+ at,
818
+ error,
819
+ by
820
+ })
821
+ }
822
+ };
823
+ }
824
+ advanceAfter(plan);
825
+ const ref = queueRef(state.target, id);
826
+ const { built: _built, ...checking } = row;
827
+ plan.setCandidate(id, {
828
+ ...checking,
829
+ state: "checking",
830
+ ref,
831
+ commit
832
+ });
833
+ plan.edits.push({
834
+ ref,
835
+ from: null,
836
+ to: commit
837
+ });
838
+ plan.event((envelope) => ({
839
+ type: "queue.candidate.opened",
840
+ ...envelope,
841
+ candidate: id,
842
+ ref,
843
+ commit,
844
+ entries: row.entries
845
+ }));
846
+ const timeout = options.report?.timeout ?? "60 minutes";
847
+ plan.jobs.push(timeoutRow(id, now + millis(timeout)));
848
+ return yield* packed(queueOwn(host, context, plan, idleStep));
849
+ });
850
+ /**
851
+ * A land that won't link: the candidate closes `restarted`, its entries waiting to open again, and
852
+ * each one's land conflicts count one more, which a `retry` keeps. The one that reaches
853
+ * `landRestarts` pins it, which `queue.entry.pinned` says, naming the candidate.
854
+ */
855
+ const landConflict = (plan, id, entries) => {
856
+ closeCandidate(plan, id, "restarted");
857
+ for (const entry of entries) {
858
+ const row = plan.entries.get(entry);
859
+ if (row === void 0) continue;
860
+ const conflicts = (row.conflicts ?? 0) + 1;
861
+ plan.setEntry(entry, {
862
+ ...row,
863
+ conflicts
864
+ });
865
+ if (conflicts === queueLimits.landRestarts) pinnedEvent(plan, entry, id);
866
+ }
867
+ };
868
+ /** A candidate whose report is late: closed `timeout`, and its target stalled. */
869
+ const timeoutStep = (host, context, internalId, id) => Effect.gen(function* () {
870
+ const loaded = yield* loadCandidate(context, internalId, id);
871
+ if (loaded === void 0) return {
872
+ kind: "done",
873
+ answer: idleStep
874
+ };
875
+ const now = yield* host.core.now;
876
+ const lifted = liftCandidateWork(host, context, loaded.state, now, timeoutName, id);
877
+ if (lifted !== void 0) return lifted;
878
+ if (loaded.row.state !== "checking" || loaded.row.report !== void 0) return {
879
+ kind: "done",
880
+ answer: idleStep
881
+ };
882
+ const plan = new QueuePlan(loaded.state, now);
883
+ closeCandidate(plan, id, "timeout");
884
+ plan.setTarget({
885
+ ...plan.row,
886
+ stalled: true
887
+ });
888
+ return queueOwn(host, context, plan, idleStep);
889
+ });
890
+ /**
891
+ * A completion of entries the target holds already, which its callers' push refused: each caller
892
+ * it names has its entries fail `refused`, or every entry with none named, the candidate closed.
893
+ */
894
+ const refuseCompletion = (host, context, internalId, tried, error) => queueWrite(Effect.gen(function* () {
895
+ const id = tried.candidate;
896
+ const loaded = yield* loadCandidate(context, internalId, id);
897
+ if (loaded?.row.state !== "building") return {
898
+ kind: "done",
899
+ answer: idleStep
900
+ };
901
+ const plan = new QueuePlan(loaded.state, yield* host.core.now);
902
+ const refused = tried.refused ?? [];
903
+ const summary = { summary: error.message };
904
+ if (refused.length === 0) failEntries(plan, id, loaded.row.entries, "refused", summary);
905
+ for (const { at, error: why } of refused) failEntries(plan, id, tried.callers?.[at] ?? [], "refused", { summary: why.message });
906
+ advanceAfter(plan);
907
+ return queueOwn(host, context, plan, idleStep);
908
+ }));
909
+ const candidateJob = (step) => (host, job, context) => Effect.gen(function* () {
910
+ const tried = {};
911
+ const internalId = jobRepo(job);
912
+ const run = queueWrite(step(host, context, internalId, job.data.candidate, tried)).pipe(Effect.catch((error) => retriedCodes.has(error.code) || tried.candidate === void 0 ? Effect.fail(error) : refuseCompletion(host, context, internalId, {
913
+ ...tried,
914
+ candidate: tried.candidate
915
+ }, error)));
916
+ const first = yield* run;
917
+ return first.lifted === true ? yield* run : first;
918
+ });
919
+ /**
920
+ * The batch of several callers an advance out of tries stood to publish: closed, each entry to
921
+ * open alone. Its callers' checks run one after another, and may outrun every try (#716).
922
+ */
923
+ const unbatch = (plan, state) => {
924
+ const stack = stackOf(state).flatMap((id) => {
925
+ const candidate = state.candidates.get(id);
926
+ return candidate === void 0 ? [] : [{
927
+ id,
928
+ candidate
929
+ }];
930
+ });
931
+ const publish = publishOf(state, stack);
932
+ if (publish?.kind !== "publish") return false;
933
+ const { id, candidate } = publish.open;
934
+ if (callersOf(state, candidate.entries).length < 2) return false;
935
+ closeCandidate(plan, id, "failed");
936
+ for (const entry of candidate.entries) {
937
+ const row = plan.entries.get(entry);
938
+ if (row !== void 0 && isOpen(row)) plan.setEntry(entry, {
939
+ ...row,
940
+ alone: true
941
+ });
942
+ }
943
+ return true;
944
+ };
945
+ /** Why a batch `unbatch` closed failed, when its try ran past `seconds`: what's known, no cause. */
946
+ const batchTooSlow = (seconds) => /* @__PURE__ */ new Error(`This batch's try ran past a job's ${seconds} seconds, and its callers' checks run one after another. Lower \`batch.maxSize\`, or speed up \`preReceive\`.`);
947
+ /**
948
+ * A queue job out of tries holds its target `work-failed`, naming the job, so nothing merges until
949
+ * a `release` or the job's next run lifts it, then passes the failure on to `then`. A job holds it
950
+ * once, a later claim's failure moving the hold to that claim, and a target at its holds takes
951
+ * none, where `then`'s `repo.work.failed` alone says so. `more` adds to the plan, as `unbatch`
952
+ * does, and a batch it closed on a try's timeout reaches `then` as `batchTooSlow`.
953
+ */
954
+ const holdOnFailure = (host, stateOf, then, more) => async (job, failure, context) => {
955
+ let unbatched = false;
956
+ const hold = Effect.gen(function* () {
957
+ const done = {
958
+ kind: "done",
959
+ answer: idleStep
960
+ };
961
+ const state = yield* stateOf(job, context);
962
+ const work = {
963
+ name: job.name,
964
+ key: job.key,
965
+ claim: job.claim
966
+ };
967
+ if (state === void 0) return done;
968
+ const holds = workHolds(state, work);
969
+ const stale = holds.filter(([, row]) => row.work?.claim !== work.claim);
970
+ if (holds.length > 0 && stale.length === 0) return done;
971
+ const full = holds.length === 0 && openHolds(state.row).length >= queueLimits.holds;
972
+ const plan = new QueuePlan(state, yield* host.core.now);
973
+ if (holds.length === 0 && !full) addTargetHold(plan, "work-failed", work);
974
+ for (const [id, row] of stale) plan.setHold(id, {
975
+ ...row,
976
+ work
977
+ });
978
+ unbatched = more?.(plan, state) ?? false;
979
+ if (full && !unbatched) return done;
980
+ return queueOwn(host, context, plan, idleStep);
981
+ });
982
+ try {
983
+ await runJobTry(queueWrite(hold));
984
+ } finally {
985
+ const { error, timeout } = failure;
986
+ const timedOut = error instanceof DOMException && error.name === "TimeoutError";
987
+ await then?.(job, unbatched && timeout !== void 0 && timedOut ? {
988
+ ...failure,
989
+ error: batchTooSlow(timeout / 1e3)
990
+ } : failure, context);
991
+ }
992
+ };
993
+ /**
994
+ * The queue's jobs over `host`, which `createGitServer` registers beside its own, each passing its
995
+ * last failure on to `onFailure` once it holds its target.
996
+ */
997
+ const queueJobs = (host, onFailure) => {
998
+ const build = candidateJob(buildStep);
999
+ const timeout = candidateJob(timeoutStep);
1000
+ const targetOf = (job, context) => loadTarget(context.store, jobRepo(job), job.data.target);
1001
+ const candidateOf = (job, context) => loadCandidate(context, jobRepo(job), job.data.candidate).pipe(Effect.map((loaded) => loaded?.state));
1002
+ const retry = {
1003
+ limit: 10,
1004
+ delay: "1 second",
1005
+ backoff: "exponential",
1006
+ maxDelay: "5 minutes"
1007
+ };
1008
+ return [
1009
+ defineJob({
1010
+ name: advanceName,
1011
+ schema: Schema.toStandardSchemaV1(AdvanceData),
1012
+ retry,
1013
+ handler: (job, context) => runJobTry(advance(host, job, context)),
1014
+ onFailure: holdOnFailure(host, targetOf, onFailure, unbatch)
1015
+ }),
1016
+ defineJob({
1017
+ name: buildName,
1018
+ schema: Schema.toStandardSchemaV1(CandidateData),
1019
+ retry,
1020
+ handler: async (job, context) => {
1021
+ await runJobTry(build(host, job, context));
1022
+ },
1023
+ onFailure: holdOnFailure(host, candidateOf, onFailure)
1024
+ }),
1025
+ defineJob({
1026
+ name: timeoutName,
1027
+ schema: Schema.toStandardSchemaV1(CandidateData),
1028
+ retry,
1029
+ handler: async (job, context) => {
1030
+ await runJobTry(timeout(host, job, context));
1031
+ },
1032
+ onFailure: holdOnFailure(host, candidateOf, onFailure)
1033
+ })
1034
+ ];
1035
+ };
1036
+ export { queueJobs };