@ref0/git 0.12.0 → 0.14.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 (247) hide show
  1. package/dist/access/private-refs.mjs +3 -3
  2. package/dist/auth/auth.d.mts +2 -2
  3. package/dist/auth/auth.mjs +3 -6
  4. package/dist/auth/authorize.mjs +1 -17
  5. package/dist/auth/helpers.mjs +3 -11
  6. package/dist/auth/host-services.mjs +11 -0
  7. package/dist/auth/policy.d.mts +27 -7
  8. package/dist/auth/policy.mjs +8 -4
  9. package/dist/auth/tokens-layer.d.mts +1 -2
  10. package/dist/auth/tokens-layer.mjs +2 -3
  11. package/dist/auth/tokens-public.d.mts +3 -3
  12. package/dist/auth/tokens.d.mts +1 -8
  13. package/dist/auth/tokens.mjs +1 -8
  14. package/dist/auth.d.mts +1 -4
  15. package/dist/auth.mjs +1 -3
  16. package/dist/client/git-http.mjs +18 -4
  17. package/dist/client/push-upload.mjs +33 -7
  18. package/dist/client/remote.mjs +94 -28
  19. package/dist/client/slice-push.d.mts +1 -1
  20. package/dist/contracts/access.d.mts +8 -8
  21. package/dist/contracts/actors.d.mts +2 -34
  22. package/dist/contracts/blobs.d.mts +2 -2
  23. package/dist/contracts/client.d.mts +8 -3
  24. package/dist/contracts/commits.d.mts +10 -2
  25. package/dist/contracts/commits.mjs +9 -1
  26. package/dist/contracts/files.d.mts +2 -2
  27. package/dist/contracts/forks.d.mts +11 -1
  28. package/dist/contracts/git.d.mts +18 -7
  29. package/dist/contracts/git.mjs +3 -2
  30. package/dist/contracts/lfs.d.mts +0 -7
  31. package/dist/contracts/objects.d.mts +80 -10
  32. package/dist/contracts/operations.d.mts +3 -0
  33. package/dist/contracts/operations.mjs +12 -2
  34. package/dist/contracts/push-uploads.d.mts +44 -5
  35. package/dist/contracts/push-uploads.mjs +7 -3
  36. package/dist/contracts/refs.d.mts +28 -6
  37. package/dist/contracts/remote.mjs +1 -3
  38. package/dist/contracts/repo-records.d.mts +1 -0
  39. package/dist/contracts/repos.d.mts +90 -2
  40. package/dist/contracts/repos.mjs +29 -2
  41. package/dist/contracts/result.d.mts +23 -18
  42. package/dist/contracts/result.mjs +17 -4
  43. package/dist/contracts/rules.d.mts +22 -22
  44. package/dist/contracts/server.d.mts +28 -77
  45. package/dist/contracts/signin.d.mts +1 -1
  46. package/dist/contracts/sync.d.mts +79 -19
  47. package/dist/contracts/sync.mjs +34 -10
  48. package/dist/contracts/tokens.d.mts +1 -6
  49. package/dist/contracts/tokens.mjs +1 -2
  50. package/dist/contracts/topics.d.mts +0 -5
  51. package/dist/contracts/work.d.mts +66 -2
  52. package/dist/contracts/work.mjs +8 -1
  53. package/dist/core/access.mjs +27 -5
  54. package/dist/core/ancestry.d.mts +9 -0
  55. package/dist/core/ancestry.mjs +6 -6
  56. package/dist/core/asked.mjs +42 -4
  57. package/dist/core/call-names.mjs +1 -0
  58. package/dist/core/call-services.mjs +2 -1
  59. package/dist/core/events/deliver.mjs +10 -2
  60. package/dist/core/forks.mjs +3 -3
  61. package/dist/core/imports.mjs +147 -9
  62. package/dist/core/index-job.mjs +9 -6
  63. package/dist/core/job-view.mjs +8 -9
  64. package/dist/core/mirror-rows.mjs +19 -4
  65. package/dist/core/objects/commits.mjs +16 -6
  66. package/dist/core/parts.d.mts +6 -1
  67. package/dist/core/parts.mjs +1 -4
  68. package/dist/core/purge.mjs +76 -6
  69. package/dist/core/push-decide.mjs +1 -1
  70. package/dist/core/push-files.d.mts +12 -0
  71. package/dist/core/push-files.mjs +225 -0
  72. package/dist/core/push-repo.d.mts +8 -0
  73. package/dist/core/push-repo.mjs +56 -0
  74. package/dist/core/push.d.mts +17 -0
  75. package/dist/core/push.mjs +98 -26
  76. package/dist/core/receipts.mjs +26 -10
  77. package/dist/core/ref-view.mjs +59 -5
  78. package/dist/core/refs.mjs +13 -8
  79. package/dist/core/repack.mjs +11 -8
  80. package/dist/core/repo-info.mjs +16 -9
  81. package/dist/core/repos.mjs +30 -14
  82. package/dist/core/seam.mjs +2 -2
  83. package/dist/core/view.d.mts +6 -0
  84. package/dist/core/view.mjs +45 -12
  85. package/dist/core/work.mjs +47 -22
  86. package/dist/effect.d.mts +3 -1
  87. package/dist/effect.mjs +3 -1
  88. package/dist/engine/reads.mjs +13 -6
  89. package/dist/engine/walk.mjs +4 -4
  90. package/dist/event-streams/event-streams.d.mts +1 -1
  91. package/dist/event-streams/event-streams.mjs +1 -1
  92. package/dist/event-streams/stream.d.mts +1 -1
  93. package/dist/event-streams/stream.mjs +1 -1
  94. package/dist/extend.d.mts +3 -3
  95. package/dist/extend.mjs +2 -2
  96. package/dist/http/answers.mjs +4 -2
  97. package/dist/http/core-parts.mjs +64 -15
  98. package/dist/http/handler.mjs +2 -2
  99. package/dist/http/node.mjs +5 -4
  100. package/dist/http/parts.d.mts +1 -0
  101. package/dist/http/push-upload-job.mjs +503 -0
  102. package/dist/http/push-uploads.d.mts +1 -0
  103. package/dist/http/push-uploads.mjs +114 -56
  104. package/dist/http/upload-pack.mjs +7 -6
  105. package/dist/index.d.mts +23 -24
  106. package/dist/index.mjs +4 -7
  107. package/dist/lfs/base.d.mts +7 -3
  108. package/dist/lfs/base.mjs +2 -1
  109. package/dist/lfs/copy.d.mts +46 -0
  110. package/dist/lfs/copy.mjs +26 -0
  111. package/dist/lfs/layer.mjs +4 -2
  112. package/dist/lfs/objects.d.mts +6 -0
  113. package/dist/lfs/objects.mjs +68 -41
  114. package/dist/lfs/rows.d.mts +13 -0
  115. package/dist/lfs/service.d.mts +1 -7
  116. package/dist/lfs/service.mjs +1 -9
  117. package/dist/lfs/upload-most.mjs +5 -5
  118. package/dist/node.d.mts +2 -2
  119. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  120. package/dist/protocol/bytes/sha256.d.mts +32 -0
  121. package/dist/protocol/bytes/sha256.mjs +105 -49
  122. package/dist/protocol/wire/advertisement.mjs +9 -4
  123. package/dist/protocol/wire/lines.d.mts +4 -2
  124. package/dist/protocol/wire/lines.mjs +11 -5
  125. package/dist/protocol/wire/push-uploads.mjs +13 -1
  126. package/dist/protocol/wire/v2.mjs +2 -2
  127. package/dist/protocol.d.mts +3 -1
  128. package/dist/protocol.mjs +3 -1
  129. package/dist/queue/advance.mjs +1 -1
  130. package/dist/queue/host.d.mts +1 -7
  131. package/dist/queue/host.mjs +1 -7
  132. package/dist/queue/layer.mjs +1 -1
  133. package/dist/queue/trim.mjs +1 -1
  134. package/dist/rest/blobs.d.mts +31 -23
  135. package/dist/rest/blobs.mjs +1 -1
  136. package/dist/rest/caller.d.mts +49 -9
  137. package/dist/rest/caller.mjs +1 -1
  138. package/dist/rest/client.d.mts +10 -3
  139. package/dist/rest/client.mjs +4 -0
  140. package/dist/rest/commits.d.mts +273 -240
  141. package/dist/rest/errors.d.mts +24 -4
  142. package/dist/rest/events.d.mts +9 -6
  143. package/dist/rest/events.mjs +1 -2
  144. package/dist/rest/files.d.mts +127 -115
  145. package/dist/rest/forks.d.mts +121 -97
  146. package/dist/rest/handler.mjs +4 -57
  147. package/dist/rest/handlers.d.mts +1 -1
  148. package/dist/rest/handlers.mjs +18 -4
  149. package/dist/rest/layer.mjs +2 -1
  150. package/dist/rest/me.d.mts +8 -4
  151. package/dist/rest/merges.d.mts +8 -4
  152. package/dist/rest/paths.mjs +1 -0
  153. package/dist/rest/queue.d.mts +282 -226
  154. package/dist/rest/refs.d.mts +205 -176
  155. package/dist/rest/repos.d.mts +108 -80
  156. package/dist/rest/tags.d.mts +24 -12
  157. package/dist/rest/tokens.d.mts +235 -211
  158. package/dist/rest/topics.d.mts +53 -33
  159. package/dist/rest/trees.d.mts +105 -89
  160. package/dist/rest/work.d.mts +467 -20
  161. package/dist/rest/work.mjs +8 -0
  162. package/dist/server/edge-node.d.mts +9 -13
  163. package/dist/server/edge-node.mjs +9 -12
  164. package/dist/server/git-layer.d.mts +1 -6
  165. package/dist/server/git-layer.mjs +2 -2
  166. package/dist/server/git-namespace.d.mts +3 -3
  167. package/dist/server/joined.d.mts +15 -22
  168. package/dist/server/joined.mjs +5 -29
  169. package/dist/server/lifecycle.mjs +107 -23
  170. package/dist/server/registry.mjs +9 -1
  171. package/dist/server/server.mjs +133 -212
  172. package/dist/storage/budget.mjs +2 -2
  173. package/dist/storage/clean-up.mjs +13 -10
  174. package/dist/storage/fetch.mjs +13 -8
  175. package/dist/storage/file-limits.mjs +24 -0
  176. package/dist/storage/index-build.d.mts +1 -0
  177. package/dist/storage/index-build.mjs +106 -62
  178. package/dist/storage/index-fetch.mjs +16 -3
  179. package/dist/storage/index-reach.mjs +33 -5
  180. package/dist/storage/index-remap.mjs +8 -1
  181. package/dist/storage/index-shallow.mjs +5 -3
  182. package/dist/storage/largest-files.mjs +48 -0
  183. package/dist/storage/lfs-pointers.mjs +10 -1
  184. package/dist/storage/loose.mjs +3 -1
  185. package/dist/storage/memory-budget.mjs +28 -4
  186. package/dist/storage/pack-reads.mjs +8 -8
  187. package/dist/storage/pack-receive.mjs +83 -25
  188. package/dist/storage/packs.mjs +37 -21
  189. package/dist/storage/prune-keep.mjs +203 -34
  190. package/dist/storage/prune-walk.mjs +54 -16
  191. package/dist/storage/prune.mjs +629 -196
  192. package/dist/storage/push-uploads.mjs +36 -12
  193. package/dist/storage/quarantine.mjs +9 -9
  194. package/dist/storage/ready.mjs +47 -19
  195. package/dist/storage/receive-bounds.mjs +29 -8
  196. package/dist/storage/receive-state.mjs +8 -0
  197. package/dist/storage/receive-steps.mjs +71 -18
  198. package/dist/storage/repack.d.mts +1 -1
  199. package/dist/storage/repack.mjs +1 -8
  200. package/dist/storage/rows.mjs +12 -1
  201. package/dist/storage/shallow.d.mts +1 -0
  202. package/dist/storage/shallow.mjs +26 -4
  203. package/dist/storage/stream-whole.mjs +5 -2
  204. package/dist/storage/visible.mjs +29 -1
  205. package/dist/storage/walk.mjs +2 -1
  206. package/dist/store/catalogue.mjs +1 -0
  207. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  208. package/dist/store/cursor-seal-public.d.mts +5 -0
  209. package/dist/store/cursor-seal-public.mjs +5 -0
  210. package/dist/store/cursor-seal.d.mts +16 -2
  211. package/dist/store/cursor-seal.mjs +26 -14
  212. package/dist/store/errors.mjs +9 -1
  213. package/dist/store/records.d.mts +2 -0
  214. package/dist/store/records.mjs +9 -6
  215. package/dist/store/repo-record.d.mts +9 -7
  216. package/dist/store/repo-record.mjs +102 -19
  217. package/dist/store/scopes.mjs +10 -2
  218. package/dist/sync/bound.d.mts +2 -0
  219. package/dist/sync/bound.mjs +11 -2
  220. package/dist/sync/github.d.mts +6 -1
  221. package/dist/sync/github.mjs +55 -43
  222. package/dist/sync/http.mjs +36 -1
  223. package/dist/sync/import.mjs +1 -0
  224. package/dist/sync/layer.mjs +6 -2
  225. package/dist/sync/lfs-batch.mjs +119 -0
  226. package/dist/sync/lfs-copy.mjs +251 -0
  227. package/dist/sync/mirror.mjs +210 -137
  228. package/dist/sync/smart-http.mjs +4 -2
  229. package/dist/sync/step.mjs +25 -5
  230. package/dist/sync/tries.mjs +45 -14
  231. package/dist/sync.d.mts +2 -2
  232. package/dist/topics/host.mjs +1 -19
  233. package/dist/topics/layer.mjs +1 -1
  234. package/package.json +3 -8
  235. package/dist/auth/bridge.mjs +0 -30
  236. package/dist/auth/helpers.d.mts +0 -17
  237. package/dist/core/purge.d.mts +0 -8
  238. package/dist/core/registered-rows.d.mts +0 -5
  239. package/dist/core/repack.d.mts +0 -11
  240. package/dist/http/handler.d.mts +0 -2
  241. package/dist/rest/handler.d.mts +0 -21
  242. package/dist/rest.d.mts +0 -2
  243. package/dist/rest.mjs +0 -1
  244. package/dist/server/registry.d.mts +0 -16
  245. package/dist/server/server.d.mts +0 -36
  246. package/dist/storage/repack-job.d.mts +0 -3
  247. package/dist/topics/host.d.mts +0 -7
@@ -18,9 +18,10 @@ import { indexEligible } from "./index-fetch.mjs";
18
18
  import { listedIds } from "./listed-ids.mjs";
19
19
  import { indexHolds } from "./index-remap.mjs";
20
20
  import { indexRowKey, isPackId } from "./layout.mjs";
21
- import { ReachCache, indexReach } from "./index-reach.mjs";
21
+ import { ReachCache, indexReach, reachedRoots } from "./index-reach.mjs";
22
22
  import { indexedVisible, setReachOf } from "./index-visible.mjs";
23
23
  import { pointersOfObjects } from "./lfs-pointers.mjs";
24
+ import { largestOf } from "./largest-files.mjs";
24
25
  import { PackIndexes, packReader, seedBytes } from "./pack-reads.mjs";
25
26
  import { copyRowsPage, noRows } from "./object-rows.mjs";
26
27
  import { pushedCommitsPage } from "./pushed-commits.mjs";
@@ -38,11 +39,11 @@ import { burstOptions, defaultRepack, optionFor, readObjectRows } from "./repack
38
39
  import { containedPlan, containedWalk, countedMerge } from "./repack-contained.mjs";
39
40
  import { refuseBacklog } from "./repack-backlog.mjs";
40
41
  import { defaultShallow, readyAnswer, readyBytesOf, readyKey, readyStep, untilEnded } from "./ready.mjs";
41
- import { defaultPrune, pruneWait, quarantineKey } from "./rows.mjs";
42
+ import { defaultPrune, deletedLeaveAt, pruneWait, quarantineKey } from "./rows.mjs";
42
43
  import { readAnswer, receiveStep, stageReceive } from "./receive-steps.mjs";
43
44
  import { memoryOf, openBudget } from "./packs-memory.mjs";
44
- import { fetchFloorBytes, headroomBytes, idleHeapBytes, pushAdmissionOf, pushRulesOf, readReserveBytes, readerFloorBytes, receiveObjectsMostOf } from "./budget.mjs";
45
- import { AllottedPointers, allottedWithin, fetchBusy, growWaitMs, pushMemoryOf, readBusy, readerMemoryOf, upkeepMemoryOf, upkeepTooLarge } from "./memory-budget.mjs";
45
+ import { fetchFloorBytes, headroomBytes, idleHeapBytes, pushAdmissionOf, pushRulesOf, readReserveBytes, readerFloorBytes } from "./budget.mjs";
46
+ import { AllottedPointers, allottedWithin, fetchBusy, growWaitMs, pushMemoryOf, pushObjectsMostOf, readBusy, readerMemoryOf, upkeepMemoryOf, upkeepTooLarge } from "./memory-budget.mjs";
46
47
  import { PacksAllotment, treesBusy } from "./push-allotment.mjs";
47
48
  import { wholeRoots } from "./roots.mjs";
48
49
  import { wholeAnswer, wholePlan, wholeStream } from "./stream-whole.mjs";
@@ -178,7 +179,7 @@ const fetchCount = (most) => Effect.map(requestCount, (calls) => calls !== void
178
179
  * A fetch's bound on its calls: each kind's the lower of the adapter's and `packs()`' own, with no
179
180
  * bound for a kind neither names. `undefined` when neither names any. A limit of either that's
180
181
  * `Infinity` is no bound, and one that isn't a whole number of calls, 0 or more, is a `RangeError`:
181
- * one that's no number would compare as no bound. `createGitServer` checks the adapter's first;
182
+ * one that's no number would compare as no bound. A server checks the adapter's first;
182
183
  * a host that opens `packs()` itself reaches this check alone.
183
184
  */
184
185
  const fetchCallsMost = (platform, own) => {
@@ -238,7 +239,8 @@ const receiveRows = /* @__PURE__ */ Effect.fnUntraced(function* (reader, unpack,
238
239
  },
239
240
  bytes: unpacked.bytes,
240
241
  objects: unpacked.objects.length,
241
- lfsPointers: yield* pointersOfObjects(unpacked.objects, pointers)
242
+ lfsPointers: yield* pointersOfObjects(unpacked.objects, pointers),
243
+ ...largestOf(unpacked.objects)
242
244
  };
243
245
  if (unpacked.cut.length > 0) quarantine.cut = unpacked.cut;
244
246
  const whole = receive.partial === true || receive.boundary !== void 0 ? void 0 : wholeRoots(unpacked.objects);
@@ -370,13 +372,14 @@ const packs = (options = {}) => {
370
372
  at: clock.now(),
371
373
  prune,
372
374
  receive: input,
373
- memory
375
+ memory,
376
+ objectsMost: pushObjectsMostOf(memoryTotal, input)
374
377
  };
375
378
  if (visible !== void 0) packed.visible = visible;
376
379
  return receivePack(packed);
377
380
  };
378
381
  /**
379
- * A push, admitted to the budget first: past `receiveObjectsMostOf` its memory it's refused
382
+ * A push, admitted to the budget first: past `pushObjectsMostOf` its memory it's refused
380
383
  * before it waits, since it could never be stored. Its answer carries its allotment, the rules'
381
384
  * share of what it was allotted and what its pointers hold, owned from its split by
382
385
  * `answered`, which gives it back on any exit but success, and handed to `made` in the step
@@ -384,7 +387,7 @@ const packs = (options = {}) => {
384
387
  * the scope ends. A push with no pack keeps no allotment.
385
388
  */
386
389
  const receive = Effect.fnUntraced(function* (listed, input, answered, made, visible) {
387
- const most = receiveObjectsMostOf(memoryTotal, input);
390
+ const most = pushObjectsMostOf(memoryTotal, input);
388
391
  if (input.objects > most) return yield* Effect.fail(tooMany(input.objects, most));
389
392
  const past = segmentTooLarge(input);
390
393
  if (past !== void 0) return yield* Effect.fail(past);
@@ -439,7 +442,7 @@ const packs = (options = {}) => {
439
442
  const past = segmentTooLarge(input);
440
443
  if (past !== void 0) return yield* Effect.fail(past);
441
444
  const { quarantine: prune } = optionsFor(chosen ? yield* statsOf(calls, listed.repo) : void 0);
442
- const { boundary = [], needs = [], cutMost, length, atMost } = input;
445
+ const { boundary = [], needs = [], cutMost, length, atMost, shallow = [] } = input;
443
446
  return yield* stageReceive({
444
447
  store: calls,
445
448
  bucket,
@@ -453,7 +456,8 @@ const packs = (options = {}) => {
453
456
  answer: {
454
457
  boundary,
455
458
  needs,
456
- ...cutMost !== void 0 && { cutMost }
459
+ ...cutMost !== void 0 && { cutMost },
460
+ ...shallow.length > 0 && { shallow }
457
461
  }
458
462
  });
459
463
  });
@@ -463,7 +467,7 @@ const packs = (options = {}) => {
463
467
  * `receive`'s is. A try whose commit another try's beat is `UNAVAILABLE`, to be tried again.
464
468
  */
465
469
  const step = Effect.fnUntraced(function* (listed, input, answered, made, visible) {
466
- const most = receiveObjectsMostOf(memoryTotal, input);
470
+ const most = pushObjectsMostOf(memoryTotal, input);
467
471
  if (input.objects > most) return yield* Effect.fail(tooMany(input.objects, most));
468
472
  const { pack } = input;
469
473
  if (!isPackId(pack)) return yield* fail("INVALID_ARGUMENT", `No pack is staged as ${pack}`);
@@ -498,7 +502,8 @@ const packs = (options = {}) => {
498
502
  objects,
499
503
  ...needs !== void 0 && { needs }
500
504
  },
501
- memory
505
+ memory,
506
+ objectsMost: pushObjectsMostOf(memoryTotal, input)
502
507
  };
503
508
  if (visible !== void 0) receiving.visible = visible;
504
509
  const opened = {
@@ -509,7 +514,9 @@ const packs = (options = {}) => {
509
514
  receiving,
510
515
  opened,
511
516
  pointers: new AllottedPointers(allotment),
512
- answer
517
+ answer,
518
+ ...input.share !== void 0 && { share: input.share },
519
+ ...input.largest === true && { largest: true }
513
520
  });
514
521
  if ("committed" in stepped) {
515
522
  if (stepped.committed === "lost") return yield* stepLost;
@@ -687,16 +694,22 @@ const packs = (options = {}) => {
687
694
  const maintain = (listed, input) => callsMost === void 0 ? upkeepOf(listed, input, void 0) : Effect.flatMap(stepBudget(callsMost, "upkeep"), (own) => Effect.provideService(upkeepOf(listed, input, own), CallBudget, own));
688
695
  /** `maintain`'s step, its calls counted into `own`, the step's budget, when bounded. */
689
696
  const upkeepOf = Effect.fnUntraced(function* (listed, input, own) {
690
- const { at } = input;
697
+ const { at, deleted } = input;
691
698
  const raw = {
692
699
  store: input.store,
693
700
  bucket
694
701
  };
695
- const cleaned = input.steps === "prune" ? void 0 : yield* cleanUp({
702
+ const cleaning = deleted === void 0 ? {
696
703
  ...raw,
697
704
  listed,
698
705
  at
699
- });
706
+ } : {
707
+ ...raw,
708
+ listed,
709
+ at,
710
+ leaveAt: deletedLeaveAt(deleted, fetchLimits)
711
+ };
712
+ const cleaned = input.steps === "prune" ? void 0 : yield* cleanUp(cleaning);
700
713
  if (cleaned !== void 0 && (cleaned.more || hasChange(cleaned))) return {
701
714
  ...cleaned,
702
715
  more: true
@@ -732,7 +745,7 @@ const packs = (options = {}) => {
732
745
  refused: fences.refused
733
746
  };
734
747
  const { repack: merging, prune: pruning } = read.merges;
735
- const orphan = prune === false || input.deleted === true ? pruning : void 0;
748
+ const orphan = prune === false || input.deleted !== void 0 ? pruning : void 0;
736
749
  if (orphan === void 0 && merging !== void 0 && pruning === void 0 && input.steps === "prune") return {
737
750
  change: { rows: noRows },
738
751
  more: false,
@@ -753,7 +766,7 @@ const packs = (options = {}) => {
753
766
  };
754
767
  const step = yield* Effect.gen(function* () {
755
768
  if (orphan !== void 0) return ending(droppedStep(orphan));
756
- if (input.deleted === true && read.started !== void 0) return (yield* passScratch(upkeep, read.started.at)) === "more" ? {
769
+ if (input.deleted !== void 0 && read.started !== void 0) return (yield* passScratch(upkeep, read.started.at)) === "more" ? {
757
770
  change: { rows: noRows },
758
771
  more: true
759
772
  } : {
@@ -830,6 +843,7 @@ const packs = (options = {}) => {
830
843
  tags: input.tags
831
844
  };
832
845
  if (input.tip !== void 0) step.tip = input.tip;
846
+ if (input.deleted !== void 0) step.leaveAt = deletedLeaveAt(input.deleted, fetchLimits);
833
847
  const ready = yield* readyStep(step);
834
848
  const due = earliest(earliest(earliest(cleaned?.due, pruned?.next), ready?.due), heldUntil);
835
849
  const next = prune === false || input.steps !== "others" ? void 0 : passDue(upkeep, prune, read, objectRows);
@@ -952,15 +966,17 @@ const packs = (options = {}) => {
952
966
  reach: answering(face.index.reach)
953
967
  },
954
968
  readyShallow: shallow !== false,
955
- pushObjectsMost: receiveObjectsMostOf(memoryTotal)
969
+ pushObjectsMost: pushObjectsMostOf(memoryTotal)
956
970
  };
957
971
  };
958
972
  const visible = (listed, input, fallback = () => walkedVisible(objectsFace(over()), listed, input)) => indexedVisible(reachParts, listed, input, fallback);
959
973
  const seen = (set) => over(visibleOf(set), setReachOf(set));
974
+ const rootsReached = (listed, input) => reachedRoots(reachParts, listed, input);
960
975
  return withBound({
961
976
  ...over(),
962
977
  visible,
963
- seen
978
+ seen,
979
+ rootsReached
964
980
  }, callsMost);
965
981
  }
966
982
  };
@@ -6,8 +6,9 @@ import { isPackId } from "./layout.mjs";
6
6
  import { upkeepRuns, upkeepTooLarge } from "./memory-budget.mjs";
7
7
  import { openIndexRanges } from "./pack-ranges.mjs";
8
8
  import { compareIds } from "./raw-ids.mjs";
9
- import { mergeHeld, mergeRuns } from "./runs.mjs";
9
+ import { mergeHeld, mergeRuns, narrowed, narrowedCalls, wholeRows } from "./runs.mjs";
10
10
  import * as Effect from "effect/Effect";
11
+ import * as Data from "effect/Data";
11
12
  // src/storage/prune-keep.ts
12
13
  /**
13
14
  * What a prune pass keeps, as a bit a position: one merge of the walk's reached runs, in ID order,
@@ -32,17 +33,29 @@ const bitsBytes = (objects) => Math.ceil(objects / 8);
32
33
  * upkeep's bounds. The bits are the caller's until its scope ends; the rest only while it merges.
33
34
  */
34
35
  const keepHeld = (packs) => packs.reduce((sum, pack) => sum + bitsBytes(pack.objects), 0) + packs.length * keepChunkRanks(packs.length) * 20 + mergeHeld(21, upkeepRuns);
35
- /** Whether `bits` is set at `rank`. */
36
- const hasBit = (bits, rank) => ((bits[rank >> 3] ?? 0) & 1 << (rank & 7)) !== 0;
37
36
  /**
38
- * Whether `keep` keeps the object at `rank` of `pack`'s `.idx`. A pack it has no bits for, one
39
- * listed mid-walk, after its first merge, is kept whole: the runs don't speak for what came after
40
- * the walk began, so its objects are reachable, never cruft.
37
+ * The gets a keep of `packs` makes of their `.idx`s: each one's header and fanout, then its IDs a
38
+ * chunk at a time. The reached runs' reads are the merge's, as `mergeRuns` makes them.
39
+ */
40
+ const keepIndexGets = (packs) => {
41
+ const ranks = keepChunkRanks(packs.length);
42
+ return packs.reduce((sum, pack) => sum + 1 + Math.ceil(pack.objects / ranks), 0);
43
+ };
44
+ /**
45
+ * The calls a keep's merge of `packs` makes, a forecast: `keepIndexGets`, and with `runs`, the
46
+ * reached runs' reads, narrowed past `upkeepRuns.ways` first, as `mergeRuns` reads them. A holders
47
+ * merge, which reads no runs, makes the gets alone.
41
48
  */
42
- const keptAt = (keep, pack, rank) => {
43
- const bits = keep.packs.find((each) => each.pack === pack);
44
- return bits === void 0 || hasBit(bits.bits, rank);
49
+ const keepMergeCalls = (input, packs, runs) => {
50
+ const gets = keepIndexGets(packs);
51
+ if (runs === void 0) return gets;
52
+ const narrowing = narrowedCalls(runs.lengths, runs.width, upkeepRuns, input.bucket.multipart);
53
+ const bytes = runs.lengths.reduce((sum, length) => sum + length, 0);
54
+ const reads = Math.ceil(bytes / wholeRows(runs.width, upkeepRuns.readBytes)) + narrowing.runs;
55
+ return gets + narrowing.calls + reads;
45
56
  };
57
+ /** Whether `bits` is set at `rank`. */
58
+ const hasBit = (bits, rank) => ((bits[rank >> 3] ?? 0) & 1 << (rank & 7)) !== 0;
46
59
  /** Sets `bits` at `rank`. */
47
60
  const setBit = (bits, rank) => {
48
61
  bits[rank >> 3] = (bits[rank >> 3] ?? 0) | 1 << (rank & 7);
@@ -79,6 +92,8 @@ const refill = (cursor) => Effect.map(cursor.ranges.ids(cursor.rank, Math.min(cu
79
92
  cursor.from = cursor.rank;
80
93
  cursor.chunk = chunk;
81
94
  });
95
+ /** A bits merge stopped before an ID, each run's place at it, for its next try. */
96
+ var BitsStopped = class extends Data.TaggedError("BitsStopped") {};
82
97
  /**
83
98
  * The bits of `ranges` and `rows` that `reached`'s rows reach, merged in ID order: `reached` from
84
99
  * `bucket` under `pack`'s runs, each `ranges`' IDs a chunk of `ranks` at a time. Into `into`, when
@@ -86,22 +101,29 @@ const refill = (cursor) => Effect.map(cursor.ranges.ids(cursor.rank, Math.min(cu
86
101
  * packs', by ID, so a pack listed since is read for what it holds and given no bits, which
87
102
  * `keptAt` reads as kept whole. A reached ID
88
103
  * that no pack or row holds is `missing`, but for the empty tree, which the walk's reader serves
89
- * from no pack (`eachHeldRow` yields it), so the walk never asks its `missing` either.
104
+ * from no pack (`eachHeldRow` yields it), so the walk never asks its `missing` either. With
105
+ * `going`, it goes on from where a try stopped, and stops before a pack's read `goesOn` says
106
+ * doesn't fit, once it has visited an ID whole: so each try moves it on.
90
107
  */
91
- const mergeBits = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, reached, ranges, rows, missing, ranks, into) {
108
+ const mergeBits = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, reached, ranges, rows, missing, ranks, into, going = {}) {
109
+ const from = going.from;
110
+ into ??= from?.bits;
92
111
  const packs = into?.packs ?? ranges.map((each) => ({
93
112
  pack: each.pack.id,
94
113
  count: each.count,
95
114
  bits: new Uint8Array(bitsBytes(each.count))
96
115
  }));
97
- const cursors = ranges.map((each) => ({
98
- ranges: each,
99
- bits: packs.find((bits) => bits.pack === each.pack.id)?.bits ?? new Uint8Array(bitsBytes(each.count)),
100
- ranks,
101
- from: 0,
102
- chunk: /* @__PURE__ */ new Uint8Array(0),
103
- rank: 0
104
- }));
116
+ const cursors = ranges.map((each, at) => {
117
+ const rank = from?.place.ranks[at] ?? 0;
118
+ return {
119
+ ranges: each,
120
+ bits: packs.find((bits) => bits.pack === each.pack.id)?.bits ?? new Uint8Array(bitsBytes(each.count)),
121
+ ranks,
122
+ from: rank,
123
+ chunk: /* @__PURE__ */ new Uint8Array(0),
124
+ rank
125
+ };
126
+ });
105
127
  const rowIds = [...new Set(rows)].map(oidBytes).toSorted((a, b) => compareIds(a, 0, b, 0));
106
128
  const kept = new Set(into?.rows);
107
129
  let row = 0;
@@ -126,39 +148,186 @@ const mergeBits = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, rea
126
148
  if (id !== void 0 && compareIds(id, 0, bytes, at) === 0) held = keep(id);
127
149
  return held || compareIds(emptyTreeId, 0, bytes, at) === 0 ? "held" : "past";
128
150
  };
129
- yield* mergeRuns(bucket, pack, reached, (bytes, at) => {
151
+ const few = from?.place.runs ?? (yield* narrowed(bucket, pack, reached, upkeepRuns));
152
+ const last = from === void 0 ? /* @__PURE__ */ new Uint8Array(20) : oidBytes(from.place.last);
153
+ let met = from !== void 0;
154
+ let moved = false;
155
+ const reads = 1 + few.keys.length;
156
+ const runRows = few.lengths.map((length) => length / few.width);
157
+ const refillStop = (bytes, at, run, places) => {
158
+ const place = run < 0 ? void 0 : places()[run];
159
+ const refills = place !== void 0 && at + few.width === bytes.byteLength && place + 1 < (runRows[run] ?? 0);
160
+ if (!moved || !refills || going.goesOn === void 0 || going.goesOn(1)) return void 0;
161
+ const past = places().map((each, index) => index === run ? each + 1 : each);
162
+ return Effect.fail(new BitsStopped({ places: past }));
163
+ };
164
+ const visited = (bytes, at, run, places) => {
165
+ met = true;
166
+ moved = true;
167
+ last.set(bytes.subarray(at, at + 20));
168
+ return refillStop(bytes, at, run, places);
169
+ };
170
+ const merged = mergeRuns(bucket, pack, few, (bytes, at, run, places) => {
171
+ if (met && compareIds(bytes, at, last, 0) <= 0) return refillStop(bytes, at, run, places);
130
172
  const first = visit(bytes, at);
131
- if (first === "held") return void 0;
173
+ if (first === "held") return visited(bytes, at, run, places);
132
174
  return Effect.gen(function* () {
133
175
  let found = first;
134
- for (; found === "read" && waiting !== void 0; found = visit(bytes, at)) yield* refill(waiting);
135
- if (found === "held") return;
136
- const error = missing(hexOf(bytes.subarray(at, at + 20)));
137
- if (error !== void 0) return yield* Effect.fail(error);
176
+ for (; found === "read" && waiting !== void 0; found = visit(bytes, at)) {
177
+ if (moved && going.goesOn !== void 0 && !going.goesOn(reads)) return yield* new BitsStopped({ places: places() });
178
+ yield* refill(waiting);
179
+ }
180
+ if (found !== "held") {
181
+ const error = missing(hexOf(bytes.subarray(at, at + 20)));
182
+ if (error !== void 0) return yield* Effect.fail(error);
183
+ }
184
+ const stop = visited(bytes, at, run, places);
185
+ if (stop !== void 0) return yield* stop;
138
186
  });
139
- }, upkeepRuns);
140
- return {
187
+ }, upkeepRuns, void 0, from?.place.places);
188
+ const stopped = yield* Effect.as(merged, void 0).pipe(Effect.catchTag("BitsStopped", (stop) => Effect.succeed(stop)));
189
+ const bits = {
141
190
  packs,
142
191
  rows: kept
143
192
  };
193
+ if (stopped === void 0) return { bits };
194
+ return {
195
+ stopped: {
196
+ runs: few,
197
+ places: stopped.places,
198
+ last: hexOf(last),
199
+ ranks: cursors.map((cursor) => cursor.rank)
200
+ },
201
+ bits
202
+ };
144
203
  });
145
204
  /**
205
+ * What a holders merge of `packs` holds while it merges: a chunk of IDs each, as a keep's
206
+ * `keepChunkRanks` sizes it, at most all of its own, so together at most `keepIdsBytes`. Its gets
207
+ * are a keep's, `keepIndexGets`.
208
+ */
209
+ const holdersHeld = (packs) => {
210
+ const ranks = keepChunkRanks(packs.length);
211
+ return packs.reduce((sum, pack) => sum + Math.min(pack.objects, ranks) * 20, 0);
212
+ };
213
+ /**
214
+ * Each ID `ranges` hold, once, in ID order, with every one that holds it, in `ranges`' order, and
215
+ * its rank there: one merge of their `.idx` ID tables, each read `ranks` IDs at a time, never
216
+ * whole. `visit`'s ID and holders are only its own until it returns. IDs out of order in one, or
217
+ * one named twice, are `DATA_LOSS`. From `from`'s places, its first reads each pack's from there.
218
+ * Before each ID past the first it visits whose moves need reads, a pack's next rank past its
219
+ * read, `goesOn` is asked for them: when they don't fit, it stops there, that ID unvisited, and
220
+ * answers each pack's place. So each try moves it on by an ID at least.
221
+ */
222
+ const mergeHolders = /* @__PURE__ */ Effect.fnUntraced(function* (ranges, ranks, visit, going = {}) {
223
+ const cursors = ranges.map((each, pack) => {
224
+ const rank = going.from?.[pack] ?? 0;
225
+ return {
226
+ ranges: each,
227
+ pack,
228
+ from: rank,
229
+ chunk: /* @__PURE__ */ new Uint8Array(0),
230
+ rank
231
+ };
232
+ });
233
+ const placeOf = (cursor) => (cursor.rank - cursor.from) * 20;
234
+ const heap = [];
235
+ const before = (a, b) => {
236
+ const order = compareIds(a.chunk, placeOf(a), b.chunk, placeOf(b));
237
+ return order === 0 ? a.pack < b.pack : order < 0;
238
+ };
239
+ const swap = (a, b) => {
240
+ [heap[a], heap[b]] = [heap[b], heap[a]];
241
+ };
242
+ const sift = () => {
243
+ for (let at = 0;;) {
244
+ const left = 2 * at + 1;
245
+ let least = at;
246
+ if (left < heap.length && before(heap[left], heap[least])) least = left;
247
+ if (left + 1 < heap.length && before(heap[left + 1], heap[least])) least = left + 1;
248
+ if (least === at) return;
249
+ swap(at, least);
250
+ at = least;
251
+ }
252
+ };
253
+ const push = (cursor) => {
254
+ heap.push(cursor);
255
+ for (let at = heap.length - 1; at > 0 && before(heap[at], heap[at - 1 >> 1]);) {
256
+ swap(at, at - 1 >> 1);
257
+ at = at - 1 >> 1;
258
+ }
259
+ };
260
+ const advance = Effect.fnUntraced(function* (cursor) {
261
+ if (cursor.rank >= cursor.ranges.count) return;
262
+ if (placeOf(cursor) >= cursor.chunk.byteLength) {
263
+ cursor.chunk = yield* cursor.ranges.ids(cursor.rank, Math.min(ranks, cursor.ranges.count - cursor.rank));
264
+ cursor.from = cursor.rank;
265
+ }
266
+ push(cursor);
267
+ });
268
+ for (const cursor of cursors) yield* advance(cursor);
269
+ const id = /* @__PURE__ */ new Uint8Array(20);
270
+ const holders = [];
271
+ const disordered = (cursor) => lost(`Pack ${cursor.ranges.pack.id}'s index lists its IDs out of order`);
272
+ let met = false;
273
+ let moved = false;
274
+ const group = [];
275
+ const reads = (cursor) => cursor.rank + 1 < cursor.ranges.count && placeOf(cursor) + 20 >= cursor.chunk.byteLength;
276
+ while (heap.length > 0) {
277
+ const first = heap[0];
278
+ if (met && compareIds(first.chunk, placeOf(first), id, 0) <= 0) return yield* Effect.fail(disordered(first));
279
+ id.set(first.chunk.subarray(placeOf(first), placeOf(first) + 20));
280
+ met = true;
281
+ holders.length = 0;
282
+ group.length = 0;
283
+ while (heap.length > 0 && compareIds(heap[0].chunk, placeOf(heap[0]), id, 0) === 0) {
284
+ group.push(heap[0]);
285
+ heap[0] = heap.at(-1);
286
+ heap.pop();
287
+ sift();
288
+ }
289
+ const needs = group.filter(reads).length;
290
+ if (moved && needs > 0 && going.goesOn !== void 0 && !going.goesOn(needs)) return { places: cursors.map((cursor) => cursor.rank) };
291
+ moved = true;
292
+ for (const cursor of group) {
293
+ holders.push({
294
+ pack: cursor.pack,
295
+ rank: cursor.rank
296
+ });
297
+ cursor.rank += 1;
298
+ yield* advance(cursor);
299
+ }
300
+ visit(id, holders);
301
+ }
302
+ });
303
+ /**
304
+ * Each ID `packs` hold, with its holders, as `mergeHolders` merges their `.idx`s, each opened by
305
+ * range and read a keep's chunk at a time: `holdersHeld` charged to the step's allotment while it
306
+ * merges, and `keepIndexGets` made. Past the allotment, it's refused too large before a read.
307
+ */
308
+ const eachHolders = (input, packs, visit, going) => Effect.scoped(Effect.gen(function* () {
309
+ const bytes = holdersHeld(packs);
310
+ yield* Effect.acquireRelease(input.allotment.grow(bytes, upkeepTooLarge), () => Effect.sync(() => input.allotment.shrink(bytes)));
311
+ const ranges = yield* Effect.forEach(packs, (each) => Effect.flatMap(storedOf(each), (stored) => openIndexRanges(input.bucket, stored, each.objects)));
312
+ return yield* mergeHolders(ranges, keepChunkRanks(packs.length), visit, going);
313
+ }));
314
+ /**
146
315
  * What a prune pass keeps of `input`'s listed packs and `rows`: the bits `reached` sets, as
147
316
  * `mergeBits` merges them, each pack's `.idx` opened by range. Its bits are charged to the step's
148
317
  * allotment until the caller's scope ends; its chunks and the merge's reads only while it merges.
149
- * With `into`, the bits of a first keep, it adds what a few more runs reach, as a catch-up's do:
150
- * to the packs `into` has alone. A pack listed since is read for what it holds, its bits charged
151
- * while it merges and then let go, and `keptAt` keeps it whole.
318
+ * Given `going.from`, a try that stopped over the same packs, it goes on from there into its bits,
319
+ * the caller's, and stops as `mergeBits` says: where it stopped, or its bits.
152
320
  */
153
- const keepBits = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, reached, rows, missing, into) {
321
+ const keepBitsOn = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, reached, rows, missing, going = {}) {
322
+ const into = going.from?.bits;
154
323
  const listed = input.listed.packs;
155
- const bits = (into === void 0 ? listed : listed.filter((each) => into.packs.some((bits) => bits.pack === each.id))).reduce((sum, each) => sum + bitsBytes(each.objects), 0);
324
+ const bits = listed.reduce((sum, each) => sum + bitsBytes(each.objects), 0);
156
325
  if (into === void 0) yield* Effect.acquireRelease(input.allotment.grow(bits, upkeepTooLarge), () => Effect.sync(() => input.allotment.shrink(bits)));
157
326
  return yield* Effect.scoped(Effect.gen(function* () {
158
327
  const merging = keepHeld(listed) - bits;
159
328
  yield* Effect.acquireRelease(input.allotment.grow(merging, upkeepTooLarge), () => Effect.sync(() => input.allotment.shrink(merging)));
160
329
  const ranges = yield* Effect.forEach(listed, (each) => Effect.flatMap(storedOf(each), (stored) => openIndexRanges(input.bucket, stored, each.objects)));
161
- return yield* mergeBits(input.bucket, pack, reached, ranges, rows, missing, keepChunkRanks(listed.length), into);
330
+ return yield* mergeBits(input.bucket, pack, reached, ranges, rows, missing, keepChunkRanks(listed.length), into, going);
162
331
  }));
163
332
  });
164
- export { bitsBytes, hasBit, keepBits, keepChunkRanks, keepHeld, keepIdsBytes, keepRanksLeast, keptAt, mergeBits, setBit };
333
+ export { bitsBytes, eachHolders, hasBit, holdersHeld, keepBitsOn, keepChunkRanks, keepHeld, keepIdsBytes, keepIndexGets, keepMergeCalls, keepRanksLeast, mergeBits, mergeHolders, setBit };