@ref0/git 0.4.0 → 0.7.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 (463) hide show
  1. package/dist/access/namespace.d.mts +2 -0
  2. package/dist/access/private-refs.d.mts +6 -29
  3. package/dist/access/private-refs.mjs +31 -17
  4. package/dist/access/public.d.mts +6 -0
  5. package/dist/access/public.mjs +9 -0
  6. package/dist/auth/access-jwt.d.mts +10 -6
  7. package/dist/auth/access-jwt.mjs +59 -40
  8. package/dist/auth/auth-namespace.d.mts +6 -0
  9. package/dist/auth/auth-namespace.mjs +12 -0
  10. package/dist/auth/auth.d.mts +3 -6
  11. package/dist/auth/auth.mjs +2 -9
  12. package/dist/auth/authorize.mjs +13 -9
  13. package/dist/auth/fences.d.mts +1 -1
  14. package/dist/auth/host-function.mjs +17 -8
  15. package/dist/auth/identify.d.mts +5 -3
  16. package/dist/auth/identify.mjs +2 -1
  17. package/dist/auth/namespaces.d.mts +2 -2
  18. package/dist/auth/token-rows.mjs +1 -1
  19. package/dist/auth/tokens-layer.d.mts +42 -0
  20. package/dist/auth/tokens-layer.mjs +29 -0
  21. package/dist/auth/tokens-namespace.d.mts +2 -0
  22. package/dist/auth/tokens-public.d.mts +6 -0
  23. package/dist/auth/tokens-public.mjs +29 -0
  24. package/dist/auth/tokens.d.mts +13 -6
  25. package/dist/auth/tokens.mjs +13 -12
  26. package/dist/auth.d.mts +2 -2
  27. package/dist/auth.mjs +2 -2
  28. package/dist/client/git-http.mjs +1 -1
  29. package/dist/client/local.mjs +6 -3
  30. package/dist/client/remote-helper.mjs +3 -8
  31. package/dist/client/remote.mjs +26 -7
  32. package/dist/client/run-remote-helper.d.mts +1 -1
  33. package/dist/client/run-remote-helper.mjs +2 -2
  34. package/dist/client/slice-push.d.mts +1 -1
  35. package/dist/contracts/access.d.mts +24 -12
  36. package/dist/contracts/access.mjs +17 -0
  37. package/dist/contracts/actors.d.mts +17 -1
  38. package/dist/contracts/actors.mjs +8 -1
  39. package/dist/contracts/authorize.d.mts +21 -14
  40. package/dist/contracts/blobs.d.mts +1 -1
  41. package/dist/contracts/blobs.mjs +1 -1
  42. package/dist/contracts/calls-spent.d.mts +6 -4
  43. package/dist/contracts/calls-spent.mjs +10 -8
  44. package/dist/contracts/commits.d.mts +2 -2
  45. package/dist/contracts/commits.mjs +1 -1
  46. package/dist/contracts/engine.d.mts +1 -1
  47. package/dist/contracts/events.d.mts +64 -26
  48. package/dist/contracts/events.mjs +26 -6
  49. package/dist/contracts/files.d.mts +2 -2
  50. package/dist/contracts/files.mjs +1 -1
  51. package/dist/contracts/forks.d.mts +58 -58
  52. package/dist/contracts/forks.mjs +1 -1
  53. package/dist/contracts/git-events.d.mts +50 -0
  54. package/dist/contracts/git-events.mjs +23 -0
  55. package/dist/contracts/git-hooks.d.mts +37 -0
  56. package/dist/contracts/git-hooks.mjs +10 -0
  57. package/dist/contracts/git.d.mts +138 -22
  58. package/dist/contracts/git.mjs +6 -5
  59. package/dist/contracts/grants.d.mts +6 -1
  60. package/dist/contracts/ids.d.mts +16 -0
  61. package/dist/contracts/ids.mjs +19 -4
  62. package/dist/contracts/lfs.d.mts +7 -2
  63. package/dist/contracts/namespaces.d.mts +2 -2
  64. package/dist/contracts/objects.d.mts +7 -2
  65. package/dist/contracts/opaque.mjs +9 -0
  66. package/dist/contracts/operations.d.mts +293 -100
  67. package/dist/contracts/promises.d.mts +4 -14
  68. package/dist/contracts/push-uploads.d.mts +5 -2
  69. package/dist/contracts/push-uploads.mjs +9 -4
  70. package/dist/contracts/queue.d.mts +233 -54
  71. package/dist/contracts/queue.mjs +81 -6
  72. package/dist/contracts/refs.d.mts +30 -8
  73. package/dist/contracts/refs.mjs +1 -1
  74. package/dist/contracts/remote.d.mts +42 -21
  75. package/dist/contracts/remote.mjs +22 -0
  76. package/dist/contracts/repo-records.d.mts +2 -2
  77. package/dist/contracts/repos.d.mts +126 -79
  78. package/dist/contracts/repos.mjs +43 -5
  79. package/dist/contracts/result.d.mts +50 -31
  80. package/dist/contracts/result.mjs +48 -16
  81. package/dist/contracts/rules.d.mts +50 -44
  82. package/dist/contracts/rules.mjs +5 -1
  83. package/dist/contracts/server.d.mts +282 -191
  84. package/dist/contracts/services.d.mts +1 -7
  85. package/dist/contracts/services.mjs +1 -3
  86. package/dist/contracts/signin.d.mts +140 -43
  87. package/dist/contracts/signin.mjs +35 -1
  88. package/dist/contracts/store.d.mts +1 -1
  89. package/dist/contracts/sync.d.mts +112 -90
  90. package/dist/contracts/sync.mjs +34 -7
  91. package/dist/contracts/tags.d.mts +1 -1
  92. package/dist/contracts/tags.mjs +1 -1
  93. package/dist/contracts/tokens.d.mts +232 -57
  94. package/dist/contracts/tokens.mjs +80 -19
  95. package/dist/contracts/topics.d.mts +22 -10
  96. package/dist/contracts/topics.mjs +6 -3
  97. package/dist/contracts/trees.d.mts +2 -2
  98. package/dist/contracts/trees.mjs +1 -1
  99. package/dist/contracts/work.d.mts +3 -3
  100. package/dist/contracts/work.mjs +2 -2
  101. package/dist/core/access.d.mts +10 -10
  102. package/dist/core/access.mjs +47 -8
  103. package/dist/core/call-names.d.mts +3 -1
  104. package/dist/core/clock.mjs +1 -1
  105. package/dist/core/events/deliver.d.mts +13 -0
  106. package/dist/core/events/deliver.mjs +475 -175
  107. package/dist/core/events/seen.mjs +17 -3
  108. package/dist/core/forks.mjs +131 -44
  109. package/dist/core/hooks/groups.d.mts +27 -0
  110. package/dist/core/hooks/groups.mjs +74 -0
  111. package/dist/core/hooks/namespace.d.mts +2 -0
  112. package/dist/core/hooks/order.d.mts +2 -2
  113. package/dist/core/hooks/order.mjs +6 -6
  114. package/dist/core/hooks/public.d.mts +7 -0
  115. package/dist/core/hooks/public.mjs +5 -0
  116. package/dist/core/imports.mjs +94 -10
  117. package/dist/core/index-job.mjs +31 -22
  118. package/dist/core/merge-parts.d.mts +1 -1
  119. package/dist/core/merge-parts.mjs +1 -1
  120. package/dist/core/mirror-rows.mjs +18 -0
  121. package/dist/core/names.mjs +1 -1
  122. package/dist/core/namespaces.d.mts +2 -1
  123. package/dist/core/objects/commit-writes.mjs +5 -5
  124. package/dist/core/objects/merges.mjs +1 -1
  125. package/dist/core/objects/objects-layer.mjs +1 -1
  126. package/dist/core/objects/reading.mjs +52 -7
  127. package/dist/core/objects/tree-edits.mjs +13 -28
  128. package/dist/core/objects/trees.mjs +4 -4
  129. package/dist/core/objects/writing.mjs +3 -3
  130. package/dist/core/own-writes.mjs +1 -1
  131. package/dist/core/parts.d.mts +27 -2
  132. package/dist/core/parts.mjs +5 -3
  133. package/dist/core/promise.mjs +23 -3
  134. package/dist/core/purge.d.mts +8 -0
  135. package/dist/core/purge.mjs +91 -46
  136. package/dist/core/push-decide.mjs +26 -4
  137. package/dist/core/push.mjs +104 -86
  138. package/dist/core/receipts.d.mts +2 -2
  139. package/dist/core/receipts.mjs +28 -4
  140. package/dist/core/ref-index-job.mjs +10 -15
  141. package/dist/core/ref-index.d.mts +1 -0
  142. package/dist/core/ref-index.mjs +28 -8
  143. package/dist/core/ref-view.mjs +16 -11
  144. package/dist/core/refs.mjs +54 -21
  145. package/dist/core/registered-records.mjs +30 -0
  146. package/dist/core/registered-rows.d.mts +4 -0
  147. package/dist/core/registered-rows.mjs +53 -0
  148. package/dist/core/repack.d.mts +3 -2
  149. package/dist/core/repack.mjs +70 -120
  150. package/dist/core/repo-info.mjs +59 -25
  151. package/dist/core/repos.mjs +22 -16
  152. package/dist/core/rules/changes.mjs +2 -2
  153. package/dist/core/rules/check.mjs +7 -6
  154. package/dist/core/rules/commit-changes.mjs +1 -1
  155. package/dist/core/rules/context.d.mts +4 -5
  156. package/dist/core/rules/context.mjs +3 -4
  157. package/dist/core/rules/fetch.mjs +74 -21
  158. package/dist/core/saved-caller-views.d.mts +72 -0
  159. package/dist/core/saved-caller-views.mjs +123 -0
  160. package/dist/core/saved-callers-public.d.mts +5 -0
  161. package/dist/core/saved-callers-public.mjs +10 -0
  162. package/dist/core/saved-callers.mjs +95 -0
  163. package/dist/core/seam.d.mts +67 -9
  164. package/dist/core/seam.mjs +11 -3
  165. package/dist/core/still-takes.mjs +75 -0
  166. package/dist/core/tokens.mjs +5 -1
  167. package/dist/core/view.d.mts +2 -1
  168. package/dist/core/view.mjs +9 -10
  169. package/dist/core/work.mjs +6 -5
  170. package/dist/effect.d.mts +2 -2
  171. package/dist/effect.mjs +2 -2
  172. package/dist/engine/content.d.mts +2 -2
  173. package/dist/engine/content.mjs +1 -1
  174. package/dist/engine/diff.mjs +2 -2
  175. package/dist/engine/merge-base-walk.d.mts +2 -2
  176. package/dist/engine/merge-base-walk.mjs +1 -1
  177. package/dist/engine/merge-renames.mjs +1 -1
  178. package/dist/engine/reads.d.mts +2 -2
  179. package/dist/engine/reads.mjs +1 -1
  180. package/dist/engine/xdiff.d.mts +1 -1
  181. package/dist/engine/xdiff.mjs +2 -2
  182. package/dist/event-streams/event-streams.d.mts +6 -2
  183. package/dist/event-streams/event-streams.mjs +6 -2
  184. package/dist/event-streams/stream.mjs +5 -2
  185. package/dist/extend.d.mts +5 -4
  186. package/dist/extend.mjs +3 -2
  187. package/dist/http/answers.mjs +4 -3
  188. package/dist/http/core-parts.mjs +21 -13
  189. package/dist/http/handler.mjs +3 -3
  190. package/dist/http/node.d.mts +2 -23
  191. package/dist/http/parts.d.mts +2 -0
  192. package/dist/http/push-uploads.d.mts +10 -2
  193. package/dist/http/push-uploads.mjs +38 -39
  194. package/dist/http/receive-pack.mjs +8 -6
  195. package/dist/http/upload-pack.mjs +8 -7
  196. package/dist/index.d.mts +36 -19
  197. package/dist/index.mjs +14 -6
  198. package/dist/lfs/base.d.mts +32 -0
  199. package/dist/lfs/base.mjs +8 -0
  200. package/dist/lfs/calls.mjs +22 -12
  201. package/dist/lfs/layer.d.mts +28 -0
  202. package/dist/lfs/layer.mjs +65 -0
  203. package/dist/lfs/locks.mjs +16 -30
  204. package/dist/lfs/namespace.d.mts +2 -0
  205. package/dist/lfs/objects.d.mts +26 -6
  206. package/dist/lfs/objects.mjs +197 -98
  207. package/dist/lfs/pointers.mjs +8 -6
  208. package/dist/lfs/public.d.mts +5 -0
  209. package/dist/lfs/public.mjs +8 -0
  210. package/dist/lfs/purge.mjs +19 -25
  211. package/dist/lfs/rows.mjs +22 -10
  212. package/dist/lfs/service.d.mts +9 -4
  213. package/dist/lfs/service.mjs +3 -12
  214. package/dist/lfs/upkeep.mjs +45 -56
  215. package/dist/lfs/wire.mjs +1 -1
  216. package/dist/node.d.mts +3 -2
  217. package/dist/node.mjs +1 -1
  218. package/dist/protocol/bytes/buffers.d.mts +1 -1
  219. package/dist/protocol/bytes/buffers.mjs +1 -1
  220. package/dist/protocol/bytes/deflate.d.mts +1 -1
  221. package/dist/protocol/bytes/deflate.mjs +1 -1
  222. package/dist/protocol/bytes/hmac-sha256.mjs +3 -6
  223. package/dist/protocol/bytes/inflate.d.mts +1 -1
  224. package/dist/protocol/bytes/inflate.mjs +1 -1
  225. package/dist/protocol/bytes/sha1.d.mts +1 -1
  226. package/dist/protocol/bytes/sha1.mjs +2 -2
  227. package/dist/protocol/diff/read.d.mts +1 -1
  228. package/dist/protocol/diff/read.mjs +1 -1
  229. package/dist/protocol/diff/tree-diff.d.mts +1 -1
  230. package/dist/protocol/diff/tree-diff.mjs +11 -11
  231. package/dist/protocol/objects/lfs-pointer.mjs +6 -1
  232. package/dist/protocol/objects/tag.mjs +1 -1
  233. package/dist/protocol/objects/tree.mjs +1 -1
  234. package/dist/protocol/packs/graph.mjs +1 -1
  235. package/dist/protocol/packs/idx.d.mts +1 -1
  236. package/dist/protocol/packs/idx.mjs +1 -1
  237. package/dist/protocol/packs/parts.mjs +1 -1
  238. package/dist/protocol/packs/reader.d.mts +1 -1
  239. package/dist/protocol/packs/reader.mjs +2 -2
  240. package/dist/protocol/packs/write-error.d.mts +1 -1
  241. package/dist/protocol/packs/write-error.mjs +1 -1
  242. package/dist/protocol/packs/writer.mjs +4 -4
  243. package/dist/protocol/wire/advertisement.d.mts +5 -11
  244. package/dist/protocol/wire/advertisement.mjs +17 -13
  245. package/dist/protocol/wire/fetch.d.mts +1 -1
  246. package/dist/protocol/wire/fetch.mjs +1 -1
  247. package/dist/protocol/wire/lines.d.mts +14 -2
  248. package/dist/protocol/wire/lines.mjs +32 -21
  249. package/dist/protocol/wire/push-uploads.mjs +4 -2
  250. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  251. package/dist/protocol/wire/receive-pack.mjs +1 -1
  252. package/dist/protocol/wire/report-status.d.mts +1 -1
  253. package/dist/protocol/wire/report-status.mjs +1 -1
  254. package/dist/protocol/wire/v2.d.mts +5 -16
  255. package/dist/protocol/wire/v2.mjs +17 -15
  256. package/dist/queue/advance.mjs +227 -112
  257. package/dist/queue/callers.mjs +56 -69
  258. package/dist/queue/calls.mjs +24 -13
  259. package/dist/queue/commit.mjs +20 -7
  260. package/dist/queue/host.d.mts +12 -13
  261. package/dist/queue/host.mjs +15 -7
  262. package/dist/queue/lanes.mjs +9 -18
  263. package/dist/queue/layer.d.mts +6 -4
  264. package/dist/queue/layer.mjs +17 -11
  265. package/dist/queue/limits.mjs +53 -11
  266. package/dist/queue/rows.mjs +19 -15
  267. package/dist/queue/schedule.mjs +6 -5
  268. package/dist/queue/search.mjs +8 -13
  269. package/dist/queue/state.mjs +26 -7
  270. package/dist/queue/steps.mjs +10 -4
  271. package/dist/queue/trim.mjs +289 -0
  272. package/dist/rest/api.d.mts +1 -1
  273. package/dist/rest/blobs.d.mts +35 -35
  274. package/dist/rest/caller.d.mts +22 -20
  275. package/dist/rest/client.mjs +6 -6
  276. package/dist/rest/commits.d.mts +274 -274
  277. package/dist/rest/errors.d.mts +10 -10
  278. package/dist/rest/errors.mjs +1 -1
  279. package/dist/rest/events.d.mts +13 -11
  280. package/dist/rest/events.mjs +3 -1
  281. package/dist/rest/files.d.mts +78 -78
  282. package/dist/rest/forks.d.mts +170 -170
  283. package/dist/rest/handler.mjs +17 -8
  284. package/dist/rest/handlers.mjs +13 -7
  285. package/dist/rest/layer.d.mts +14 -0
  286. package/dist/rest/layer.mjs +53 -0
  287. package/dist/rest/listen.mjs +2 -2
  288. package/dist/rest/me.d.mts +18 -20
  289. package/dist/rest/me.mjs +1 -1
  290. package/dist/rest/merges.d.mts +10 -10
  291. package/dist/rest/namespace.d.mts +2 -0
  292. package/dist/rest/queue.d.mts +320 -320
  293. package/dist/rest/queue.mjs +1 -1
  294. package/dist/rest/refs.d.mts +207 -207
  295. package/dist/rest/refs.mjs +1 -1
  296. package/dist/rest/repos.d.mts +127 -127
  297. package/dist/rest/tags.d.mts +94 -94
  298. package/dist/rest/tokens.d.mts +248 -258
  299. package/dist/rest/tokens.mjs +10 -42
  300. package/dist/rest/topics.d.mts +154 -154
  301. package/dist/rest/topics.mjs +1 -1
  302. package/dist/rest/trees.d.mts +84 -84
  303. package/dist/rest/wire.d.mts +8 -4
  304. package/dist/rest/wire.mjs +3 -2
  305. package/dist/rest/work.d.mts +69 -69
  306. package/dist/rest/work.mjs +1 -1
  307. package/dist/server/check-fetch.mjs +9 -0
  308. package/dist/server/edge-node.d.mts +20 -0
  309. package/dist/server/edge-node.mjs +20 -0
  310. package/dist/server/edge.d.mts +10 -0
  311. package/dist/server/edge.mjs +23 -0
  312. package/dist/server/extension.mjs +3 -115
  313. package/dist/server/git-layer.d.mts +34 -6
  314. package/dist/server/git-layer.mjs +40 -18
  315. package/dist/server/git-namespace.d.mts +5 -4
  316. package/dist/server/git-namespace.mjs +10 -5
  317. package/dist/server/joined.d.mts +83 -0
  318. package/dist/server/joined.mjs +91 -0
  319. package/dist/server/registry.d.mts +9 -2
  320. package/dist/server/registry.mjs +179 -24
  321. package/dist/server/routes.mjs +2 -2
  322. package/dist/server/server.d.mts +11 -1
  323. package/dist/server/server.mjs +331 -201
  324. package/dist/server/uploads.d.mts +14 -0
  325. package/dist/server/uploads.mjs +15 -0
  326. package/dist/signin/context.d.mts +2 -1
  327. package/dist/signin/context.mjs +32 -37
  328. package/dist/signin/device.mjs +5 -5
  329. package/dist/signin/forms.mjs +1 -1
  330. package/dist/signin/grants.d.mts +2 -3
  331. package/dist/signin/grants.mjs +5 -5
  332. package/dist/signin/layer.d.mts +9 -0
  333. package/dist/signin/layer.mjs +41 -0
  334. package/dist/signin/namespace.d.mts +2 -0
  335. package/dist/signin/public.d.mts +6 -0
  336. package/dist/signin/public.mjs +5 -0
  337. package/dist/signin/route.mjs +47 -21
  338. package/dist/signin/web.mjs +3 -3
  339. package/dist/signin/wire.mjs +1 -1
  340. package/dist/storage/calls.d.mts +7 -8
  341. package/dist/storage/calls.mjs +17 -17
  342. package/dist/storage/clean-up.mjs +71 -34
  343. package/dist/storage/counted-bucket.mjs +34 -51
  344. package/dist/storage/fetch.mjs +1 -1
  345. package/dist/storage/host-bucket.mjs +17 -2
  346. package/dist/storage/index-build.d.mts +2 -2
  347. package/dist/storage/index-build.mjs +3 -3
  348. package/dist/storage/index-fetch.mjs +10 -6
  349. package/dist/storage/index-graph.mjs +1 -1
  350. package/dist/storage/index-layers.mjs +1 -1
  351. package/dist/storage/index-visible.mjs +1 -1
  352. package/dist/storage/layout.mjs +5 -0
  353. package/dist/storage/memory-budget.mjs +7 -1
  354. package/dist/storage/merge-cut.mjs +24 -1
  355. package/dist/storage/merge-fence.mjs +1 -1
  356. package/dist/storage/merge-plan.mjs +5 -2
  357. package/dist/storage/merge-row.mjs +1 -1
  358. package/dist/storage/merge-stream.mjs +16 -7
  359. package/dist/storage/merge-write.mjs +1 -1
  360. package/dist/storage/merge.d.mts +2 -2
  361. package/dist/storage/merge.mjs +1 -1
  362. package/dist/storage/object-rows.d.mts +2 -2
  363. package/dist/storage/object-rows.mjs +3 -3
  364. package/dist/storage/pack-ranges.d.mts +3 -1
  365. package/dist/storage/pack-ranges.mjs +168 -69
  366. package/dist/storage/pack-reads.mjs +4 -4
  367. package/dist/storage/pack-receive.d.mts +1 -1
  368. package/dist/storage/pack-receive.mjs +7 -9
  369. package/dist/storage/packs.d.mts +1 -1
  370. package/dist/storage/packs.mjs +45 -52
  371. package/dist/storage/placed-reads.mjs +81 -15
  372. package/dist/storage/prune-seen.mjs +126 -0
  373. package/dist/storage/prune-walk.mjs +87 -99
  374. package/dist/storage/prune.mjs +49 -14
  375. package/dist/storage/push-uploads.mjs +16 -18
  376. package/dist/storage/quarantine.d.mts +2 -2
  377. package/dist/storage/quarantine.mjs +51 -12
  378. package/dist/storage/ready.d.mts +2 -2
  379. package/dist/storage/ready.mjs +3 -3
  380. package/dist/storage/receive-bounds.d.mts +1 -1
  381. package/dist/storage/receive-files.mjs +1 -1
  382. package/dist/storage/receive-links.mjs +1 -1
  383. package/dist/storage/receive-state.d.mts +2 -2
  384. package/dist/storage/receive-state.mjs +1 -1
  385. package/dist/storage/receive-steps.mjs +1 -1
  386. package/dist/storage/repack-contained.mjs +2 -2
  387. package/dist/storage/repack-job.d.mts +2 -2
  388. package/dist/storage/repack-job.mjs +11 -17
  389. package/dist/storage/repack.d.mts +1 -1
  390. package/dist/storage/repack.mjs +9 -3
  391. package/dist/storage/rows.d.mts +2 -2
  392. package/dist/storage/rows.mjs +43 -4
  393. package/dist/storage/runs.d.mts +2 -2
  394. package/dist/storage/runs.mjs +15 -6
  395. package/dist/storage/send-list.mjs +6 -6
  396. package/dist/storage/single-flight.mjs +2 -2
  397. package/dist/storage/swap-walk.mjs +1 -1
  398. package/dist/storage/unpack.mjs +1 -1
  399. package/dist/store/call-count.d.mts +1 -1
  400. package/dist/store/call-count.mjs +125 -34
  401. package/dist/store/catalogue.d.mts +1 -1
  402. package/dist/store/catalogue.mjs +2 -2
  403. package/dist/store/crossing.mjs +2 -6
  404. package/dist/store/cursor-seal.mjs +1 -1
  405. package/dist/store/errors.d.mts +7 -3
  406. package/dist/store/errors.mjs +41 -13
  407. package/dist/store/job-try.mjs +130 -0
  408. package/dist/store/list-job.mjs +22 -16
  409. package/dist/store/outbox.d.mts +2 -2
  410. package/dist/store/outbox.mjs +112 -27
  411. package/dist/store/promises.d.mts +8 -3
  412. package/dist/store/promises.mjs +104 -94
  413. package/dist/store/queue-jobs.mjs +23 -2
  414. package/dist/store/records.d.mts +2 -2
  415. package/dist/store/records.mjs +16 -24
  416. package/dist/store/ref-rows.d.mts +2 -2
  417. package/dist/store/ref-rows.mjs +6 -6
  418. package/dist/store/reservations.mjs +35 -8
  419. package/dist/store/scopes.mjs +6 -14
  420. package/dist/store/topic-jobs.mjs +8 -8
  421. package/dist/sync/bound.d.mts +1 -3
  422. package/dist/sync/bound.mjs +30 -42
  423. package/dist/sync/bridge.d.mts +6 -0
  424. package/dist/sync/bridge.mjs +29 -0
  425. package/dist/sync/github.d.mts +5 -6
  426. package/dist/sync/github.mjs +37 -42
  427. package/dist/sync/http.mjs +15 -0
  428. package/dist/sync/import.mjs +17 -18
  429. package/dist/sync/layer.d.mts +9 -0
  430. package/dist/sync/layer.mjs +68 -0
  431. package/dist/sync/mirror.mjs +138 -59
  432. package/dist/sync/publish.mjs +15 -13
  433. package/dist/sync/step.mjs +221 -79
  434. package/dist/sync/tries.mjs +22 -15
  435. package/dist/sync.d.mts +3 -6
  436. package/dist/sync.mjs +3 -6
  437. package/dist/topics/advance.mjs +205 -90
  438. package/dist/topics/calls.mjs +8 -8
  439. package/dist/topics/directory.mjs +35 -12
  440. package/dist/topics/host.d.mts +5 -8
  441. package/dist/topics/host.mjs +42 -19
  442. package/dist/topics/layer.d.mts +381 -0
  443. package/dist/topics/layer.mjs +62 -0
  444. package/dist/topics/members.mjs +1 -1
  445. package/dist/topics/namespace.d.mts +2 -0
  446. package/dist/topics/public.d.mts +6 -0
  447. package/dist/topics/public.mjs +13 -0
  448. package/dist/topics/rows.mjs +12 -3
  449. package/dist/topics/topic.mjs +11 -10
  450. package/package.json +8 -13
  451. package/dist/access.d.mts +0 -2
  452. package/dist/access.mjs +0 -1
  453. package/dist/core/hooks/post-receive.mjs +0 -213
  454. package/dist/core/hooks/pre-receive.d.mts +0 -12
  455. package/dist/core/hooks/pre-receive.mjs +0 -36
  456. package/dist/lfs/repo.mjs +0 -42
  457. package/dist/server/extension.d.mts +0 -21
  458. package/dist/storage/promise-calls.mjs +0 -29
  459. package/dist/sync/import.d.mts +0 -10
  460. package/dist/sync/jobs.d.mts +0 -9
  461. package/dist/sync/jobs.mjs +0 -75
  462. package/dist/sync/mirror.d.mts +0 -13
  463. package/dist/sync/publish.d.mts +0 -6
@@ -1,6 +1,15 @@
1
1
  import { fail } from "../contracts/result.mjs";
2
2
  import * as Effect from "effect/Effect";
3
3
  // src/queue/limits.ts
4
+ /** The queue's jobs' retry: a try that fails, as a `contended` write does, runs again after `delay`. */
5
+ const queueJobRetry = {
6
+ limit: 10,
7
+ delay: "1 second",
8
+ backoff: "exponential",
9
+ maxDelay: "5 minutes"
10
+ };
11
+ /** A day, in milliseconds. */
12
+ const day = 864e5;
4
13
  /**
5
14
  * The queue's caps (Q411). Every write of a target reads its whole state in one store read, which
6
15
  * infra refuses past 16 MiB, and commits what it changed in one commit, refused past 8 MiB. So
@@ -43,19 +52,39 @@ import * as Effect from "effect/Effect";
43
52
  * each a row of its own, never a candidate's: 200 of each at most, each read under 8 MiB with the
44
53
  * record. `holds` reads its page's holds the same way. An entry's `holds`, once the entry has left
45
54
  * its key, reads all that key's, since only their rows say which were made on it: 1,000 at most,
46
- * under 1.75 MiB. A restart or a jump, the most a write changes, puts every open entry and
47
- * candidate, each search's failed candidate and the target's row: under 7.8 MiB, within a
48
- * commit's 8 MiB. `limits.test.ts` fills a target to every cap, its candidates stacked or 10
55
+ * under 1.75 MiB. A push, and a repo's delete or rename, read no target's row, which `targets`
56
+ * of would pass 16 MiB: each reads the targets' reservation rows, `reservationRowBytesMost` each,
57
+ * under 230 KB for all of them (#1970, #1971). A restart or a jump, the most a write changes,
58
+ * puts every open entry and candidate, each search's failed candidate and the target's row: under
59
+ * 7.8 MiB, within a commit's 8 MiB. `limits.test.ts` fills a target to every cap, its candidates stacked or 10
49
60
  * searches' groups: its whole read is 7.3 MiB, or 7.7 with the searches, with a small record, and
50
61
  * its restart's commit 5.8 MiB, or 6.2.
51
62
  */
52
63
  const queueLimits = {
53
64
  /**
54
65
  * Targets a repo's queues hold, each a branch it queued onto, whose first write is refused past
55
- * them as `queue-full`: a push wakes one `git.queue.advance` a target it moves, so these stay
56
- * within the 2,000 writes `pushOtherWrites` leaves (Q1117). No write deletes a target's row.
66
+ * them as `queue-targets-full`: a push wakes one `git.queue.advance` a target it moves, so these stay
67
+ * within the 2,000 writes `pushOtherWrites` leaves (Q1117). An idle target's row counts until
68
+ * `queue.trim` deletes it, `kept` after it went idle.
57
69
  */
58
70
  targets: 100,
71
+ /**
72
+ * How long `queue.trim` keeps what's ended, from when it ended (Q1128): an entry merged, failed
73
+ * or removed, with its `meta` and its key's row; a closed candidate, with its report, once none
74
+ * of its entries is left; a released hold; and an idle target's row, with its last outcomes.
75
+ * Past it, `get`, `candidate`, `retry` and the writes by ID answer `NOT_FOUND`.
76
+ */
77
+ kept: 14 * day,
78
+ /** How long `queue.trim` waits after a pass that found rows before it looks again. */
79
+ sweepEvery: day,
80
+ /**
81
+ * The entries, candidates or holds one step of `queue.trim` reads, and deletes at most: 100
82
+ * candidates of 40 KiB each are 4 MiB, beside the record. A step over candidates reads their
83
+ * entries again, up to `candidateEntries` of them, under 3.5 MiB.
84
+ */
85
+ trimPage: 100,
86
+ /** The targets' rows one step of `queue.trim` reads: a live one is up to 850 KiB. */
87
+ trimTargets: 10,
59
88
  /** Open entries a target holds: past them, `add` is `RESOURCE_EXHAUSTED`, `queue-full`. */
60
89
  openEntries: 1e3,
61
90
  /** Open holds a target holds, its own and its keys': past them, a hold is `queue-full`. */
@@ -72,7 +101,7 @@ const queueLimits = {
72
101
  nameBytes: 256,
73
102
  /**
74
103
  * The distinct callers one candidate lands for: its publish asks each one's `authorize`, rules
75
- * and `hooks.preReceive`. An entry whose caller would be one more waits for the next candidate.
104
+ * and hook groups. An entry whose caller would be one more waits for the next candidate.
76
105
  */
77
106
  candidateCallers: 16,
78
107
  /** A hold's reason. */
@@ -88,7 +117,17 @@ const queueLimits = {
88
117
  /** Entries a candidate carries from other lanes' candidates: past them, it waits to open. */
89
118
  carriedEntries: 100,
90
119
  /** Land conflicts after which an entry is pinned: it opens alone, and holds every lane. */
91
- landRestarts: 3
120
+ landRestarts: 3,
121
+ /**
122
+ * `queue.entryCommits`'s default: the commits an entry's link reads from its head, its own
123
+ * history past the target's tip, in one walk. Past them, it fails `tooManyCommits`.
124
+ */
125
+ entryCommits: 1e3,
126
+ /**
127
+ * The most `queue.entryCommits` may be, so the walk never grows past it: an entry of more
128
+ * commits merges by an admin's direct push.
129
+ */
130
+ entryCommitsMost: 1e4
92
131
  };
93
132
  const encoder = new TextEncoder();
94
133
  /** A value's size as UTF-8 JSON, as infra counts a row's. */
@@ -102,9 +141,12 @@ const checkBytes = (field, value, most) => {
102
141
  };
103
142
  /** `RESOURCE_EXHAUSTED`, `queue-full`: a target holding as many of `what` as it may. */
104
143
  const queueFull = (what, most) => fail("RESOURCE_EXHAUSTED", `The queue holds ${most} ${what}, as many as it may`, { context: { reason: "queue-full" } });
105
- /** `RESOURCE_EXHAUSTED`, `queue-full`: a repo whose queues hold `queueLimits.targets` already. */
144
+ /**
145
+ * `RESOURCE_EXHAUSTED`, `queue-targets-full`: a repo whose queues hold `queueLimits.targets`
146
+ * already, idle ones among them till `queue.trim` deletes their rows.
147
+ */
106
148
  const targetsFull = () => fail("RESOURCE_EXHAUSTED", `The repo's queues hold ${queueLimits.targets} targets, as many as it may`, {
107
- hint: `Queue onto a branch the repo queued onto before: it keeps each of its ${queueLimits.targets} targets`,
108
- context: { reason: "queue-full" }
149
+ hint: `Queue onto a branch the repo queues onto now, or wait: a target's row goes ${queueLimits.kept / day} days after its queue went idle`,
150
+ context: { reason: "queue-targets-full" }
109
151
  });
110
- export { checkBytes, jsonSize, queueFull, queueLimits, targetsFull };
152
+ export { checkBytes, jsonSize, queueFull, queueJobRetry, queueLimits, targetsFull };
@@ -1,3 +1,4 @@
1
+ import { SavedCaller } from "../core/saved-callers.mjs";
1
2
  import { Reservation } from "../store/reservations.mjs";
2
3
  import * as Schema from "effect/Schema";
3
4
  // src/queue/rows.ts
@@ -64,6 +65,9 @@ const PlaceRow = /* @__PURE__ */ Schema.Struct({
64
65
  * candidate merged, `b` for one its report failed and `c` for one closed otherwise; `previous`: the `concurrency` last asked.
65
66
  * `reserved`: the topic holding the target, at its attempt, which refuses every other writer while
66
67
  * that attempt is live, the queue's own publish and `restart` among them (Q557), `since` it took it.
68
+ * `idle`: when the row was put with nothing open, held, searched or reserved, which every later
69
+ * put of an idle row keeps, and one that isn't drops: `queue.trim` deletes it `queueLimits.kept`
70
+ * after.
67
71
  */
68
72
  const TargetRow = /* @__PURE__ */ Schema.Struct({
69
73
  order: Schema.Array(PlaceRow),
@@ -79,7 +83,8 @@ const TargetRow = /* @__PURE__ */ Schema.Struct({
79
83
  reserved: Schema.optionalKey(Schema.Struct({
80
84
  ...Reservation.fields,
81
85
  since: Schema.Int
82
- }))
86
+ })),
87
+ idle: Schema.optionalKey(Schema.Finite)
83
88
  });
84
89
  /**
85
90
  * An entry. Its `meta`, when it has one, is a row of its own, which no write of the target reads;
@@ -93,15 +98,8 @@ const EntryRow = /* @__PURE__ */ Schema.Struct({
93
98
  key: Schema.String,
94
99
  priority: Schema.optionalKey(Schema.Finite),
95
100
  meta: Schema.optionalKey(Schema.Literal(true)),
96
- actor: Schema.String,
97
- subject: Schema.optionalKey(Schema.String),
98
- /** The ID of the token it was added with, identified again when it publishes: never its secret. */
99
- token: Schema.optionalKey(Schema.String),
100
- /** The extension's grant it was added by: its resolver, and the `id` it asks that again with. */
101
- grant: Schema.optionalKey(Schema.Struct({
102
- resolver: Schema.String,
103
- id: Schema.String
104
- })),
101
+ /** Who added it, asked again when it publishes. */
102
+ ...SavedCaller.fields,
105
103
  /**
106
104
  * A rule refused a batch it was in, which may have been another entry's change: it opens in a
107
105
  * candidate of its own, so its next publish judges its own change alone.
@@ -123,7 +121,8 @@ const EntryRow = /* @__PURE__ */ Schema.Struct({
123
121
  "reported",
124
122
  "host-error",
125
123
  "interaction",
126
- "refused"
124
+ "refused",
125
+ "tooManyCommits"
127
126
  ])),
128
127
  /** Its candidates' land conflicts, which a `retry` keeps: at `landRestarts`, it's pinned. */
129
128
  conflicts: Schema.optionalKey(Schema.Int),
@@ -134,7 +133,9 @@ const EntryRow = /* @__PURE__ */ Schema.Struct({
134
133
  joined: Schema.Int,
135
134
  since: Schema.Finite,
136
135
  jumped: Schema.optionalKey(Schema.Int)
137
- }))
136
+ })),
137
+ /** When it merged, failed or was removed, which `queue.trim` counts `queueLimits.kept` from. */
138
+ ended: Schema.optionalKey(Schema.Finite)
138
139
  });
139
140
  /**
140
141
  * A failed candidate's bisect: its groups not yet judged, each with the candidate open for it once
@@ -193,11 +194,13 @@ const CandidateRow = /* @__PURE__ */ Schema.Struct({
193
194
  landed: Schema.optionalKey(Schema.Struct({
194
195
  tip: Schema.NullOr(Schema.String),
195
196
  commit: Schema.String
196
- }))
197
+ })),
198
+ /** When it closed, or its bisect ended after: what `queue.trim` counts `queueLimits.kept` from. */
199
+ ended: Schema.optionalKey(Schema.Finite)
197
200
  });
198
201
  /**
199
202
  * An entry's hold names its `key` too, which it follows, and a `work-failed` hold the queue job it
200
- * waits on, with the claim it last failed under; `released` once it's let go.
203
+ * waits on, with the claim it last failed under; `released` once it's let go, `ended` when.
201
204
  */
202
205
  const HoldRow = /* @__PURE__ */ Schema.Struct({
203
206
  target: Schema.String,
@@ -209,6 +212,7 @@ const HoldRow = /* @__PURE__ */ Schema.Struct({
209
212
  key: Schema.String,
210
213
  claim: Schema.Int
211
214
  })),
212
- released: Schema.optionalKey(Schema.Literal(true))
215
+ released: Schema.optionalKey(Schema.Literal(true)),
216
+ ended: Schema.optionalKey(Schema.Finite)
213
217
  });
214
218
  export { CandidateRow, CounterRow, EntryRow, HoldRow, KeyRow, MetaRow, PlaceRow, ReportRow, SearchRow, TargetRow };
@@ -1,4 +1,5 @@
1
1
  import { millis } from "../contracts/promises.mjs";
2
+ import { ScheduleAnswer } from "../contracts/queue.mjs";
2
3
  import { hostCall } from "../auth/host-function.mjs";
3
4
  import { queueLimits } from "./limits.mjs";
4
5
  import { lanesNamed } from "./lanes.mjs";
@@ -6,6 +7,7 @@ import { entryNotes, orderOf } from "./state.mjs";
6
7
  import { candidateOf, entryOf } from "./steps.mjs";
7
8
  import { CoreParts } from "../core/parts.mjs";
8
9
  import * as Effect from "effect/Effect";
10
+ import * as Schema from "effect/Schema";
9
11
  import * as Predicate from "effect/Predicate";
10
12
  // src/queue/schedule.ts
11
13
  /** A target's last outcomes, as its row keeps them, oldest first. */
@@ -28,14 +30,13 @@ const defaultMaxSize = (recent) => Math.max(1, Math.floor(Math.log(.5) / Math.lo
28
30
  const reportTimeout = "60 minutes";
29
31
  /** The longest `report.timeout`, so its deadline is a moment every store takes. */
30
32
  const reportTimeoutMost = "365 days";
33
+ /** A numeric schedule answer decoded as a finite number: a host in plain JS may answer any value. */
34
+ const decodeSchedule = /* @__PURE__ */ Schema.decodeUnknownSync(ScheduleAnswer);
31
35
  /**
32
36
  * A function's count, rounded down and held from 1 to `most`. One not a finite number throws: a
33
- * host in plain JavaScript may answer any value, and `Number.isFinite` takes no other type.
37
+ * host in plain JavaScript may answer any value.
34
38
  */
35
- const countOf = (answer, most) => {
36
- if (!Number.isFinite(answer)) throw new TypeError(`A schedule answered ${String(answer)}, not a finite number`);
37
- return Math.min(most, Math.max(1, Math.floor(answer)));
38
- };
39
+ const countOf = (answer, most) => Math.min(most, Math.max(1, Math.floor(decodeSchedule(answer))));
39
40
  /**
40
41
  * What scheduling and `bisect` see of a target: its waiting entries in order, with their `meta`
41
42
  * and reports, its open candidates, bisect groups among them, its outcomes and its last schedule.
@@ -1,3 +1,4 @@
1
+ import { EntryGroups } from "../contracts/queue.mjs";
1
2
  import { hostCall } from "../auth/host-function.mjs";
2
3
  import { buildRow } from "../store/queue-jobs.mjs";
3
4
  import { openCandidate } from "./calls.mjs";
@@ -5,8 +6,8 @@ import { lanesNamed, placeOf, placed } from "./lanes.mjs";
5
6
  import { concurrencyOf, roomFor, schedulesOf } from "./schedule.mjs";
6
7
  import { candidateOf, closeCandidate, endEntry, endSearch, isOpen, releaseEntry, setChecking } from "./steps.mjs";
7
8
  import { CoreParts } from "../core/parts.mjs";
8
- import * as Schema from "effect/Schema";
9
9
  import * as Effect from "effect/Effect";
10
+ import * as Schema from "effect/Schema";
10
11
  // src/queue/search.ts
11
12
  /** A report's summary and URL, for the events of the entries it failed. */
12
13
  const reportDetails = (report) => {
@@ -65,27 +66,21 @@ const halve = (entries) => {
65
66
  return [entries.slice(0, half), entries.slice(half)];
66
67
  };
67
68
  /** A bisect's answer read as groups of IDs: a host in plain JavaScript may answer any value. */
68
- const decodeGroups = /* @__PURE__ */ Schema.decodeUnknownSync(Schema.Array(Schema.Array(Schema.String)));
69
+ const decodeGroups = /* @__PURE__ */ Schema.decodeUnknownSync(EntryGroups);
69
70
  /**
70
- * A bisect's answer as a search keeps it: at least one group, each of entries of `entries`, none
71
- * twice, and fewer than all of them, naming at most `most` in all. Any other throws why.
71
+ * A bisect's answer against the failed candidate: each group strictly smaller than `entries`, each
72
+ * ID one of `entries`, and naming at most `most` in all. Any other throws why.
72
73
  */
73
74
  const checkGroups = (answer, entries, most) => {
74
- if (answer.length === 0) throw new TypeError("A bisect answered no groups");
75
75
  const inside = new Set(entries);
76
76
  const groups = [];
77
77
  let named = 0;
78
78
  for (const group of answer) {
79
79
  if (group.length === 0 || group.length >= entries.length) throw new TypeError(`A bisect group holds from 1 to ${entries.length - 1} entries`);
80
- const ids = /* @__PURE__ */ new Set();
81
- for (const id of group) {
82
- if (!inside.has(id)) throw new TypeError(`A bisect named ${id}, not an entry of the failed candidate`);
83
- if (ids.has(id)) throw new TypeError(`A bisect named ${id} twice in one group`);
84
- ids.add(id);
85
- }
86
- named += ids.size;
80
+ for (const id of group) if (!inside.has(id)) throw new TypeError(`A bisect named ${id}, not an entry of the failed candidate`);
81
+ named += group.length;
87
82
  if (named > most) throw new TypeError(`A bisect named more than the ${most} entries it may`);
88
- groups.push([...ids]);
83
+ groups.push([...group]);
89
84
  }
90
85
  return groups;
91
86
  };
@@ -4,12 +4,13 @@ import { decodeRow } from "../store/errors.mjs";
4
4
  import { decodeOutbox, outboxReads } from "../store/outbox.mjs";
5
5
  import { WholeRepo, wholeRef } from "../store/ref-rows.mjs";
6
6
  import { readRecord } from "../store/repo-record.mjs";
7
+ import { reservationRow } from "../store/reservations.mjs";
7
8
  import { collections, prunedKey } from "../store/scopes.mjs";
8
9
  import { queueId, shortTarget } from "./ids.mjs";
9
10
  import { placeOrder } from "./pages.mjs";
10
11
  import { CandidateRow, CounterRow, EntryRow, HoldRow, KeyRow, MetaRow, ReportRow, TargetRow } from "./rows.mjs";
11
- import * as Schema from "effect/Schema";
12
12
  import * as Effect from "effect/Effect";
13
+ import * as Schema from "effect/Schema";
13
14
  // src/queue/state.ts
14
15
  /** The queue merges onto its target's tip whoever added the entry: it reads the repo whole. */
15
16
  const queueWhole = /* @__PURE__ */ WholeRepo.mint();
@@ -41,6 +42,17 @@ const named = (row, reading) => ({
41
42
  });
42
43
  /** The IDs of a target's open holds: its own, then each key's. */
43
44
  const openHolds = (row) => [...row.holds, ...Object.values(row.keyHolds).flat()];
45
+ /**
46
+ * A target's row as it's put: `idle` since the first put that left it with nothing open, held,
47
+ * searched or reserved, and no `idle` once it has any.
48
+ */
49
+ const idleStamped = (row, now) => {
50
+ const { idle, ...rest } = row;
51
+ return row.order.length > 0 || row.open.length > 0 || openHolds(row).length > 0 || (row.searches ?? []).length > 0 || row.reserved !== void 0 ? rest : {
52
+ ...rest,
53
+ idle: idle ?? now
54
+ };
55
+ };
44
56
  const idReads = (collection, ids) => ids.map((id) => ({
45
57
  collection,
46
58
  id
@@ -251,11 +263,15 @@ var QueuePlan = class {
251
263
  });
252
264
  for (const changed of this.#changed) {
253
265
  const [kind, id = ""] = changed.split(/:(.*)/s);
254
- if (kind === "target") put.push({
255
- collection: collections.queueTargets,
256
- id: this.state.target,
257
- value: this.#row
258
- });
266
+ if (kind === "target") {
267
+ const value = idleStamped(this.#row, this.now);
268
+ put.push({
269
+ collection: collections.queueTargets,
270
+ id: this.state.target,
271
+ value
272
+ });
273
+ put.push(reservationRow(this.state.target, value.reserved));
274
+ }
259
275
  if (kind === "e") put.push({
260
276
  collection: collections.queueEntries,
261
277
  id,
@@ -292,7 +308,10 @@ var QueuePlan = class {
292
308
  }
293
309
  return put;
294
310
  }
295
- /** The events in `envelope`, the first at `first`. */
311
+ /**
312
+ * The events in `envelope`, the first at `first`, each at the `seq` it takes: an event can name
313
+ * its own, as `queue.restarted`'s `revision` does.
314
+ */
296
315
  eventsAt(envelope, first) {
297
316
  return this.events.map((made, index) => made(envelope, first + index));
298
317
  }
@@ -110,7 +110,8 @@ const closeCandidate = (plan, id, reason, extra = {}) => {
110
110
  const closed = {
111
111
  ...open,
112
112
  state: "closed",
113
- reason
113
+ reason,
114
+ ended: plan.now
114
115
  };
115
116
  if (extra.report !== void 0) closed.report = extra.report;
116
117
  plan.setCandidate(id, closed);
@@ -143,7 +144,10 @@ const endSearch = (plan, failed) => {
143
144
  const row = plan.candidates.get(failed);
144
145
  if (row?.search === void 0) return;
145
146
  const { search, ...ended } = row;
146
- plan.setCandidate(failed, ended);
147
+ plan.setCandidate(failed, {
148
+ ...ended,
149
+ ended: plan.now
150
+ });
147
151
  plan.setTarget({
148
152
  ...plan.row,
149
153
  searches: (plan.row.searches ?? []).filter((open) => open !== failed)
@@ -210,7 +214,8 @@ const endEntry = (plan, id, state, extra = {}) => {
210
214
  plan.setEntry(id, {
211
215
  ...rest,
212
216
  state,
213
- ...extra
217
+ ...extra,
218
+ ended: plan.now
214
219
  });
215
220
  plan.setTarget({
216
221
  ...plan.row,
@@ -297,7 +302,8 @@ const releaseKey = (plan, key, hold) => {
297
302
  const releaseHold = (plan, hold, row) => {
298
303
  plan.setHold(hold, {
299
304
  ...row,
300
- released: true
305
+ released: true,
306
+ ended: plan.now
301
307
  });
302
308
  if (row.key === void 0) plan.setTarget({
303
309
  ...plan.row,
@@ -0,0 +1,289 @@
1
+ import { decodeRow, storeCall } from "../store/errors.mjs";
2
+ import { gitJob } from "../store/job-try.mjs";
3
+ import { TrimData, trimName } from "../store/queue-jobs.mjs";
4
+ import { readRecord } from "../store/repo-record.mjs";
5
+ import { collections, jobRepo, newChangeId, repoScope } from "../store/scopes.mjs";
6
+ import { queueJobRetry, queueLimits } from "./limits.mjs";
7
+ import { CandidateRow, EntryRow, HoldRow, KeyRow, TargetRow } from "./rows.mjs";
8
+ import { keyRowId } from "./state.mjs";
9
+ import * as Clock$1 from "effect/Clock";
10
+ import * as Effect from "effect/Effect";
11
+ import { CurrentJob, Job } from "@ref0/infra";
12
+ // src/queue/trim.ts
13
+ const phases = [
14
+ "targets",
15
+ "entries",
16
+ "candidates",
17
+ "holds"
18
+ ];
19
+ /** Whether a row that ended at `ended` is past `queueLimits.kept` at `now`. */
20
+ const past = (ended, now) => ended !== void 0 && ended + queueLimits.kept <= now;
21
+ const idReads = (collection, ids) => ids.map((id) => ({
22
+ collection,
23
+ id
24
+ }));
25
+ /** The rows of `results` from `results[from]` on, one each, by ID. */
26
+ const byId = (results, from, count) => new Map(results.slice(from, from + count).flatMap((rows) => rows.map((row) => [row.id, row])));
27
+ /** A page of `phase`'s rows after `after`: `undefined` once the repo is gone. */
28
+ const readPage = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, collection, limit, after) {
29
+ const { record, snapshot } = yield* readRecord(store, internalId, [after === void 0 ? {
30
+ collection,
31
+ limit
32
+ } : {
33
+ collection,
34
+ limit,
35
+ after
36
+ }]);
37
+ if (record === void 0 || record.deleted === true) return void 0;
38
+ const rows = snapshot.results[1] ?? [];
39
+ return {
40
+ rows,
41
+ version: snapshot.version,
42
+ after: rows.length < limit ? void 0 : rows.at(-1)?.id
43
+ };
44
+ });
45
+ /** Idle targets' rows past `kept`, read and deleted at one version. */
46
+ const trimTargets = /* @__PURE__ */ Effect.fnUntraced(function* (rows, now) {
47
+ const gone = [];
48
+ for (const row of rows) {
49
+ const target = yield* decodeRow(TargetRow, row, `The queue of '${row.id}'`);
50
+ if (!past(target.idle, now)) continue;
51
+ gone.push({
52
+ collection: row.collection,
53
+ id: row.id
54
+ });
55
+ gone.push({
56
+ collection: collections.queueReservations,
57
+ id: row.id
58
+ });
59
+ }
60
+ return { delete: gone };
61
+ });
62
+ /** Released holds past `kept`: no write opens one again. */
63
+ const trimHolds = /* @__PURE__ */ Effect.fnUntraced(function* (rows, now) {
64
+ const gone = [];
65
+ for (const row of rows) {
66
+ const hold = yield* decodeRow(HoldRow, row, `The hold '${row.id}'`);
67
+ if (hold.released === true && past(hold.ended, now)) gone.push({
68
+ collection: row.collection,
69
+ id: row.id
70
+ });
71
+ }
72
+ return { delete: gone };
73
+ });
74
+ /** Whether `entry` ended past `kept`: merged, failed or removed, and not revived since. */
75
+ const endedPast = (entry, now) => (entry.state === "merged" || entry.state === "failed" || entry.state === "removed") && past(entry.ended, now);
76
+ /**
77
+ * Ended entries past `kept`, read again with their keys' rows at one version, so a revival since
78
+ * the page keeps its entry: each with its `meta`, and its key's row when it's the key's latest,
79
+ * or that row without `merged` when only its merge was.
80
+ */
81
+ const trimEntries = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, rows, now) {
82
+ const due = [];
83
+ const ids = [];
84
+ for (const row of rows) {
85
+ const entry = yield* decodeRow(EntryRow, row, `The queue entry '${row.id}'`);
86
+ if (!endedPast(entry, now)) continue;
87
+ due.push(entry);
88
+ ids.push(row.id);
89
+ }
90
+ if (ids.length === 0) return void 0;
91
+ const keys = [...new Set(due.map((entry) => keyRowId(entry.target, entry.key)))];
92
+ const reads = [...idReads(collections.queueEntries, ids), ...idReads(collections.queueKeys, keys)];
93
+ const { record, snapshot } = yield* readRecord(store, internalId, reads);
94
+ if (record === void 0 || record.deleted === true) return void 0;
95
+ const entries = byId(snapshot.results, 1, ids.length);
96
+ const keyRows = byId(snapshot.results, 1 + ids.length, keys.length);
97
+ const gone = /* @__PURE__ */ new Set();
98
+ const remove = [];
99
+ for (const id of ids) {
100
+ const row = entries.get(id);
101
+ if (row === void 0) continue;
102
+ const entry = yield* decodeRow(EntryRow, row, `The queue entry '${id}'`);
103
+ if (!endedPast(entry, now)) continue;
104
+ gone.add(id);
105
+ remove.push({
106
+ collection: collections.queueEntries,
107
+ id
108
+ });
109
+ if (entry.meta === true) remove.push({
110
+ collection: collections.queueMeta,
111
+ id
112
+ });
113
+ }
114
+ const put = [];
115
+ for (const [id, row] of keyRows) {
116
+ const key = yield* decodeRow(KeyRow, row, `The queue key '${id}'`);
117
+ if (gone.has(key.latest)) remove.push({
118
+ collection: collections.queueKeys,
119
+ id
120
+ });
121
+ else if (key.merged !== void 0 && gone.has(key.merged.entry)) put.push({
122
+ collection: collections.queueKeys,
123
+ id,
124
+ value: { latest: key.latest }
125
+ });
126
+ }
127
+ return {
128
+ delete: remove,
129
+ put,
130
+ version: snapshot.version
131
+ };
132
+ });
133
+ /** Whether `candidate` closed past `kept`, its bisect, if it had one, ended. */
134
+ const closedPast = (candidate, now) => candidate.state === "closed" && candidate.search === void 0 && past(candidate.ended, now);
135
+ /**
136
+ * Closed candidates past `kept`, read again with their entries at one version, up to
137
+ * `candidateEntries` entries: each with its report, once none of its entries is left, so an entry
138
+ * waiting with the report that judged it keeps both. `after` is the last it decided on, when it
139
+ * left some of the page for the next try.
140
+ */
141
+ const trimCandidates = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, rows, now) {
142
+ const due = [];
143
+ let entryCount = 0;
144
+ let stopped;
145
+ for (const row of rows) {
146
+ const candidate = yield* decodeRow(CandidateRow, row, `The candidate '${row.id}'`);
147
+ if (!closedPast(candidate, now)) continue;
148
+ if (entryCount + candidate.entries.length > queueLimits.candidateEntries) {
149
+ stopped = due.at(-1)?.[0];
150
+ break;
151
+ }
152
+ entryCount += candidate.entries.length;
153
+ due.push([row.id, candidate]);
154
+ }
155
+ if (due.length === 0) return void 0;
156
+ const ids = due.map(([id]) => id);
157
+ const entryIds = [...new Set(due.flatMap(([, candidate]) => candidate.entries))];
158
+ const reads = [...idReads(collections.queueCandidates, ids), ...idReads(collections.queueEntries, entryIds)];
159
+ const { record, snapshot } = yield* readRecord(store, internalId, reads);
160
+ if (record === void 0 || record.deleted === true) return void 0;
161
+ const candidates = byId(snapshot.results, 1, ids.length);
162
+ const left = byId(snapshot.results, 1 + ids.length, entryIds.length);
163
+ const remove = [];
164
+ for (const id of ids) {
165
+ const row = candidates.get(id);
166
+ if (row === void 0) continue;
167
+ const candidate = yield* decodeRow(CandidateRow, row, `The candidate '${id}'`);
168
+ if (!closedPast(candidate, now) || candidate.entries.some((entry) => left.has(entry))) continue;
169
+ remove.push({
170
+ collection: collections.queueCandidates,
171
+ id
172
+ });
173
+ remove.push({
174
+ collection: collections.queueReports,
175
+ id
176
+ });
177
+ }
178
+ return {
179
+ delete: remove,
180
+ version: snapshot.version,
181
+ stopped
182
+ };
183
+ });
184
+ /** The collections a pass reads, each read for its first row at its end: one row says one is left. */
185
+ const firstRows = [
186
+ {
187
+ collection: collections.queueTargets,
188
+ limit: 1
189
+ },
190
+ {
191
+ collection: collections.queueEntries,
192
+ limit: 1
193
+ },
194
+ {
195
+ collection: collections.queueCandidates,
196
+ limit: 1
197
+ },
198
+ {
199
+ collection: collections.queueHolds,
200
+ limit: 1
201
+ }
202
+ ];
203
+ /** Whether the repo's queues hold any row a pass reads: `false` once the repo is gone too. */
204
+ const rowsLeft = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId) {
205
+ const { record, snapshot } = yield* readRecord(store, internalId, firstRows);
206
+ if (record === void 0 || record.deleted === true) return false;
207
+ return snapshot.results.slice(1).some((rows) => rows.length > 0);
208
+ });
209
+ /**
210
+ * One try of `queue.trim` at `cursor`: one page of its phase, read, decided on and committed.
211
+ * Due again now while the pass goes on, or with the same cursor when its commit lost; a day on
212
+ * once a pass ends with queue rows left, and done once none are, till a target's first write
213
+ * saves it again.
214
+ */
215
+ const trimStep = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, cursor, now) {
216
+ const targets = cursor.phase === "targets";
217
+ const collection = {
218
+ targets: collections.queueTargets,
219
+ entries: collections.queueEntries,
220
+ candidates: collections.queueCandidates,
221
+ holds: collections.queueHolds
222
+ }[cursor.phase];
223
+ const limit = targets ? queueLimits.trimTargets : queueLimits.trimPage;
224
+ const page = yield* readPage(store, internalId, collection, limit, cursor.after);
225
+ if (page === void 0) return void 0;
226
+ let step;
227
+ if (cursor.phase === "targets" || cursor.phase === "holds") step = {
228
+ ...yield* (targets ? trimTargets : trimHolds)(page.rows, now),
229
+ after: page.after,
230
+ version: page.version
231
+ };
232
+ else if (cursor.phase === "entries") {
233
+ const decided = yield* trimEntries(store, internalId, page.rows, now);
234
+ step = decided === void 0 ? void 0 : {
235
+ ...decided,
236
+ after: page.after
237
+ };
238
+ } else {
239
+ const decided = yield* trimCandidates(store, internalId, page.rows, now);
240
+ const after = decided?.stopped ?? page.after;
241
+ step = decided === void 0 ? void 0 : {
242
+ ...decided,
243
+ after
244
+ };
245
+ }
246
+ if (step !== void 0 && step.delete.length + (step.put?.length ?? 0) > 0) {
247
+ const change = {
248
+ id: newChangeId(),
249
+ expect: step.version,
250
+ delete: [...step.delete],
251
+ put: [...step.put ?? []]
252
+ };
253
+ if (!(yield* storeCall(() => store.commit(repoScope(internalId), change))).ok) return {
254
+ kind: "more",
255
+ data: cursor
256
+ };
257
+ }
258
+ const after = step?.after ?? page.after;
259
+ if (after !== void 0) return {
260
+ kind: "more",
261
+ data: {
262
+ phase: cursor.phase,
263
+ after
264
+ }
265
+ };
266
+ const next = phases[phases.indexOf(cursor.phase) + 1];
267
+ if (next !== void 0) return {
268
+ kind: "more",
269
+ data: { phase: next }
270
+ };
271
+ if (!(yield* rowsLeft(store, internalId))) return void 0;
272
+ return {
273
+ kind: "more",
274
+ at: now + queueLimits.sweepEvery,
275
+ data: { phase: "targets" }
276
+ };
277
+ });
278
+ const TrimJob = /* @__PURE__ */ Job.make(trimName, {
279
+ payload: TrimData,
280
+ retry: queueJobRetry
281
+ });
282
+ /**
283
+ * `queue.trim` over `host`, which `createGitServer` registers beside the queue's other jobs: its
284
+ * time is the host's clock, as the other jobs' is. A try that fails its last retry passes its
285
+ * failure to `onFailure`, so the host's `repo.work.failed` names it and `work.retry` runs it again:
286
+ * a failed job's row stays failed whatever a target's first write saves.
287
+ */
288
+ const queueTrimJob = (host, onFailure) => gitJob(TrimJob, (cursor) => Effect.flatMap(Effect.all([CurrentJob.store, CurrentJob.current]), ([store, job]) => Effect.flatMap(Effect.provideContext(Clock$1.currentTimeMillis, host.needs), (now) => trimStep(store, jobRepo(job), cursor, now))), onFailure === void 0 ? {} : { onFailure });
289
+ export { queueTrimJob };