@ref0/git 0.4.0 → 0.6.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 (167) hide show
  1. package/dist/access/private-refs.mjs +3 -4
  2. package/dist/auth/authorize.mjs +9 -4
  3. package/dist/auth/identify.d.mts +5 -3
  4. package/dist/auth/tokens.mjs +12 -11
  5. package/dist/client/local.mjs +2 -0
  6. package/dist/client/slice-push.d.mts +1 -1
  7. package/dist/contracts/access.d.mts +6 -2
  8. package/dist/contracts/authorize.d.mts +14 -10
  9. package/dist/contracts/events.d.mts +32 -5
  10. package/dist/contracts/events.mjs +14 -3
  11. package/dist/contracts/git.d.mts +68 -3
  12. package/dist/contracts/grants.d.mts +6 -1
  13. package/dist/contracts/lfs.d.mts +5 -2
  14. package/dist/contracts/objects.d.mts +7 -2
  15. package/dist/contracts/promises.d.mts +2 -14
  16. package/dist/contracts/push-uploads.d.mts +1 -1
  17. package/dist/contracts/queue.d.mts +15 -7
  18. package/dist/contracts/refs.d.mts +1 -1
  19. package/dist/contracts/result.d.mts +9 -5
  20. package/dist/contracts/result.mjs +5 -0
  21. package/dist/contracts/server.d.mts +13 -6
  22. package/dist/contracts/work.d.mts +1 -1
  23. package/dist/core/access.mjs +17 -1
  24. package/dist/core/call-names.d.mts +3 -1
  25. package/dist/core/claim-rows.d.mts +4 -0
  26. package/dist/core/claim-rows.mjs +53 -0
  27. package/dist/core/events/deliver.d.mts +12 -0
  28. package/dist/core/events/deliver.mjs +367 -145
  29. package/dist/core/events/seen.mjs +17 -3
  30. package/dist/core/forks.mjs +82 -20
  31. package/dist/core/hooks/post-receive.mjs +20 -17
  32. package/dist/core/index-job.mjs +23 -17
  33. package/dist/core/parts.d.mts +6 -0
  34. package/dist/core/purge.d.mts +8 -0
  35. package/dist/core/purge.mjs +16 -21
  36. package/dist/core/push-decide.mjs +26 -4
  37. package/dist/core/push.mjs +57 -20
  38. package/dist/core/ref-index-job.mjs +9 -14
  39. package/dist/core/ref-index.d.mts +1 -0
  40. package/dist/core/ref-index.mjs +28 -8
  41. package/dist/core/ref-view.mjs +14 -9
  42. package/dist/core/refs.mjs +13 -11
  43. package/dist/core/repack.d.mts +2 -1
  44. package/dist/core/repack.mjs +66 -118
  45. package/dist/core/repos.mjs +5 -5
  46. package/dist/core/rules/check.mjs +7 -6
  47. package/dist/core/rules/context.d.mts +1 -1
  48. package/dist/core/seam.d.mts +56 -9
  49. package/dist/core/seam.mjs +7 -1
  50. package/dist/core/still-takes.mjs +75 -0
  51. package/dist/core/view.d.mts +1 -0
  52. package/dist/core/view.mjs +8 -9
  53. package/dist/core/work.mjs +1 -1
  54. package/dist/extend.d.mts +2 -1
  55. package/dist/http/core-parts.mjs +19 -11
  56. package/dist/http/handler.mjs +2 -2
  57. package/dist/http/node.d.mts +2 -23
  58. package/dist/http/parts.d.mts +1 -0
  59. package/dist/http/push-uploads.d.mts +10 -2
  60. package/dist/http/push-uploads.mjs +31 -34
  61. package/dist/http/receive-pack.mjs +5 -3
  62. package/dist/http/upload-pack.mjs +2 -2
  63. package/dist/index.d.mts +11 -7
  64. package/dist/index.mjs +5 -3
  65. package/dist/lfs/base.d.mts +32 -0
  66. package/dist/lfs/base.mjs +8 -0
  67. package/dist/lfs/calls.mjs +21 -12
  68. package/dist/lfs/layer.d.mts +27 -0
  69. package/dist/lfs/layer.mjs +64 -0
  70. package/dist/lfs/locks.mjs +13 -27
  71. package/dist/lfs/namespace.d.mts +2 -0
  72. package/dist/lfs/objects.d.mts +23 -4
  73. package/dist/lfs/objects.mjs +65 -81
  74. package/dist/lfs/pointers.mjs +8 -6
  75. package/dist/lfs/public.d.mts +5 -0
  76. package/dist/lfs/public.mjs +8 -0
  77. package/dist/lfs/purge.mjs +19 -25
  78. package/dist/lfs/rows.mjs +22 -10
  79. package/dist/lfs/service.d.mts +9 -4
  80. package/dist/lfs/service.mjs +3 -12
  81. package/dist/lfs/upkeep.mjs +34 -49
  82. package/dist/node.d.mts +3 -2
  83. package/dist/node.mjs +1 -1
  84. package/dist/protocol/wire/advertisement.d.mts +4 -10
  85. package/dist/protocol/wire/advertisement.mjs +16 -12
  86. package/dist/protocol/wire/lines.d.mts +14 -2
  87. package/dist/protocol/wire/lines.mjs +32 -21
  88. package/dist/protocol/wire/v2.d.mts +4 -15
  89. package/dist/protocol/wire/v2.mjs +16 -14
  90. package/dist/queue/advance.mjs +78 -55
  91. package/dist/queue/calls.mjs +4 -2
  92. package/dist/queue/commit.mjs +20 -13
  93. package/dist/queue/host.d.mts +2 -2
  94. package/dist/queue/layer.d.mts +4 -2
  95. package/dist/queue/layer.mjs +8 -3
  96. package/dist/queue/limits.mjs +36 -6
  97. package/dist/queue/rows.mjs +14 -5
  98. package/dist/queue/state.mjs +19 -5
  99. package/dist/queue/steps.mjs +10 -4
  100. package/dist/queue/trim.mjs +284 -0
  101. package/dist/rest/blobs.d.mts +19 -19
  102. package/dist/rest/caller.d.mts +4 -4
  103. package/dist/rest/commits.d.mts +96 -96
  104. package/dist/rest/errors.d.mts +2 -2
  105. package/dist/rest/events.d.mts +2 -2
  106. package/dist/rest/files.d.mts +54 -54
  107. package/dist/rest/forks.d.mts +87 -87
  108. package/dist/rest/handler.mjs +13 -5
  109. package/dist/rest/layer.d.mts +14 -0
  110. package/dist/rest/layer.mjs +52 -0
  111. package/dist/rest/me.d.mts +2 -2
  112. package/dist/rest/merges.d.mts +2 -2
  113. package/dist/rest/namespace.d.mts +2 -0
  114. package/dist/rest/queue.d.mts +208 -208
  115. package/dist/rest/refs.d.mts +131 -131
  116. package/dist/rest/repos.d.mts +12 -12
  117. package/dist/rest/tags.d.mts +70 -70
  118. package/dist/rest/tokens.d.mts +23 -23
  119. package/dist/rest/topics.d.mts +111 -111
  120. package/dist/rest/trees.d.mts +57 -57
  121. package/dist/rest/wire.d.mts +2 -0
  122. package/dist/rest/wire.mjs +2 -2
  123. package/dist/rest/work.d.mts +6 -6
  124. package/dist/server/edge-node.d.mts +20 -0
  125. package/dist/server/edge-node.mjs +20 -0
  126. package/dist/server/edge.d.mts +10 -0
  127. package/dist/server/edge.mjs +23 -0
  128. package/dist/server/extension.mjs +1 -1
  129. package/dist/server/git-layer.d.mts +15 -4
  130. package/dist/server/git-layer.mjs +13 -2
  131. package/dist/server/git-namespace.d.mts +5 -4
  132. package/dist/server/git-namespace.mjs +6 -3
  133. package/dist/server/registry.d.mts +3 -0
  134. package/dist/server/registry.mjs +58 -7
  135. package/dist/server/server.d.mts +3 -0
  136. package/dist/server/server.mjs +81 -39
  137. package/dist/server/uploads.d.mts +14 -0
  138. package/dist/server/uploads.mjs +15 -0
  139. package/dist/storage/calls.d.mts +7 -8
  140. package/dist/storage/calls.mjs +14 -14
  141. package/dist/storage/clean-up.mjs +59 -29
  142. package/dist/storage/host-bucket.mjs +16 -1
  143. package/dist/storage/index-build.d.mts +1 -1
  144. package/dist/storage/layout.mjs +5 -0
  145. package/dist/storage/merge.d.mts +1 -1
  146. package/dist/storage/push-uploads.mjs +12 -16
  147. package/dist/storage/quarantine.d.mts +1 -1
  148. package/dist/storage/quarantine.mjs +51 -12
  149. package/dist/storage/receive-bounds.d.mts +1 -1
  150. package/dist/storage/repack-job.d.mts +1 -1
  151. package/dist/storage/repack-job.mjs +7 -14
  152. package/dist/storage/rows.mjs +42 -3
  153. package/dist/storage/runs.d.mts +1 -1
  154. package/dist/store/job-try.mjs +26 -0
  155. package/dist/store/list-job.mjs +22 -16
  156. package/dist/store/outbox.mjs +38 -12
  157. package/dist/store/promises.d.mts +6 -1
  158. package/dist/store/promises.mjs +74 -89
  159. package/dist/store/queue-jobs.mjs +22 -1
  160. package/dist/store/scopes.mjs +0 -10
  161. package/dist/sync/mirror.d.mts +1 -1
  162. package/dist/sync/mirror.mjs +1 -1
  163. package/dist/sync/publish.mjs +12 -7
  164. package/dist/sync/step.mjs +4 -0
  165. package/package.json +3 -3
  166. package/dist/lfs/repo.mjs +0 -42
  167. package/dist/storage/promise-calls.mjs +0 -29
@@ -1,6 +1,7 @@
1
1
  import { fail } from "../contracts/result.mjs";
2
2
  import { bestEffort, decodeRow, resultCall, storeCall, thrownError } from "../store/errors.mjs";
3
- import { runJobTry, untilAborted } from "../store/crossing.mjs";
3
+ import { untilAborted } from "../store/crossing.mjs";
4
+ import { madeJob } from "../store/job-try.mjs";
4
5
  import { decodePacks, featureChange, gitStore, packRow } from "../store/git-store.mjs";
5
6
  import { appendEvents, decodeOutbox, outboxReads, repoEnvelope } from "../store/outbox.mjs";
6
7
  import { decodeTimes, readRecord, repoStats, timeRow } from "../store/repo-record.mjs";
@@ -11,24 +12,23 @@ import { listedIds } from "../storage/listed-ids.mjs";
11
12
  import { ReadyRow } from "../storage/ready.mjs";
12
13
  import { ApartRow, apartAfter, apartKey } from "../storage/repack-contained.mjs";
13
14
  import { SwapsSettled, swapsKey, swapsLeft } from "../storage/swap-walk.mjs";
14
- import { LeavingRow, QuarantineRow, decodeHeld, leavingLate, leavingRow } from "../storage/rows.mjs";
15
+ import { QuarantineRow, decodeHeld, decodeLeft, isLeftKey, leavingKey, leavingLate, leavingRow, leftPack } from "../storage/rows.mjs";
15
16
  import { WholeRepo, wholeRefs } from "../store/ref-rows.mjs";
16
17
  import { collections, jobRepo, maintainedKey, newChangeId, prunedKey, reachedKey, repoScope } from "../store/scopes.mjs";
17
- import { MaintenanceRun, RepackData, maintenanceRunKey, parksPass, pruneJobKey, pruneJobRow, repackJobKey, repackJobName, repackJobRow as repackJobRow$1, repackJobSchema } from "../storage/repack-job.mjs";
18
+ import { MaintenanceRun, RepackData, maintenanceRunKey, parksPass, pruneJobKey, pruneJobRow, repackJobKey, repackJobName, repackJobRow as repackJobRow$1 } from "../storage/repack-job.mjs";
18
19
  import { headOf, indexJobs, statsReads } from "./access.mjs";
19
20
  import { notFailed } from "./events/deliver.mjs";
20
21
  import { importLive } from "./imports.mjs";
21
22
  import { ownSweepOf, ownSweepRead } from "./own-writes.mjs";
22
23
  import { sweepOf, sweepRead } from "./receipts.mjs";
24
+ import { heldId, isAbandon, isReadyPut, isTake, ownRows, stillTakes } from "./still-takes.mjs";
23
25
  import { SealedObjects } from "./view.mjs";
24
- import { defineJob, jobLeaseMargin } from "@ref0/infra";
25
- import * as Schema from "effect/Schema";
26
+ import { CurrentJob, Job, jobLeaseMargin } from "@ref0/infra";
26
27
  import * as Effect from "effect/Effect";
27
28
  import * as Predicate from "effect/Predicate";
28
- import * as Option from "effect/Option";
29
29
  // src/core/repack.ts
30
30
  /** Upkeep keeps every ref's objects, private or not: it reads the repo whole. */
31
- const upkeepWhole = WholeRepo.mint();
31
+ const upkeepWhole = /* @__PURE__ */ WholeRepo.mint();
32
32
  /**
33
33
  * `upkeeps` as one, in order: the first that did some answers `more`, so a step stays short;
34
34
  * else the soonest any is due.
@@ -60,7 +60,6 @@ const changeOf = (expect, change) => ({
60
60
  id
61
61
  })), ...change.delete ?? []]
62
62
  });
63
- const isLeaving = Schema.is(LeavingRow);
64
63
  /** `change` with each leaving row due `late` later, as `leavingLate` says. */
65
64
  const startedLate = (change, late) => change.put === void 0 ? change : {
66
65
  ...change,
@@ -180,12 +179,6 @@ const leavingOf = /* @__PURE__ */ Effect.fnUntraced(function* (parts, packs, at)
180
179
  more: true
181
180
  };
182
181
  });
183
- const heldId = (key) => `${key.collection}/${key.id}`;
184
- const isQuarantine = Schema.is(QuarantineRow);
185
- /** Clean-up's put: a `quarantine` row it commits abandoned. */
186
- const isAbandon = (row) => row.collection === objectCollections.quarantine && isQuarantine(row.value) && row.value.state === "abandoned";
187
- /** Clean-up's put: a `leaving` row it commits taken (#394). */
188
- const isTake = (row) => row.collection === objectCollections.leaving && isLeaving(row.value) && row.value.taken === true;
189
182
  /** Clean-up's put: a row it abandons or takes. */
190
183
  const isCleanUpPut = (row) => isAbandon(row) || isTake(row);
191
184
  /**
@@ -193,31 +186,21 @@ const isCleanUpPut = (row) => isAbandon(row) || isTake(row);
193
186
  * drop writes the key, and each pack is received once, so a reread puts it again unchecked.
194
187
  */
195
188
  const isStagedPut = (row) => row.collection === objectCollections.staged;
196
- /** The ready shallow pack's step's put: its row. */
197
- const isReadyPut = (row) => row.collection === objectCollections.ready;
198
189
  /** A row a step may put at a newer version than it read: a prune pass's, or a walk's `apart`. */
199
190
  const isUpkeepMark = (row) => row.collection === objectCollections.prune || row.collection === objectCollections.apart;
200
191
  /**
201
- * Clean-up's delete: an ended `quarantine` row and its receive's record, a taken `leaving` row, or
202
- * a swept `staged` row.
192
+ * Clean-up's delete: an ended `quarantine` row and its receive's record, a taken `leaving` or
193
+ * `cover` row, or a swept `staged` row.
203
194
  */
204
- const isEnded = (key) => key.collection === objectCollections.quarantine || key.collection === objectCollections.receive || key.collection === objectCollections.leaving || key.collection === objectCollections.staged;
205
- /**
206
- * A listing step's own `quarantine` rows: `step.quarantine`, then each other `quarantine` row its
207
- * change ends, such as a streaming merge's packs past its first (maintenance-1m B5).
208
- */
209
- const ownRows = (step) => {
210
- const own = step.quarantine;
211
- if (own === void 0) return [];
212
- return [own, ...(step.change.delete ?? []).filter((key) => key.collection === objectCollections.quarantine && key.id !== own.id)];
213
- };
195
+ const isEnded = (key) => key.collection === objectCollections.quarantine || key.collection === objectCollections.receive || isLeftKey(key) || key.collection === objectCollections.staged;
214
196
  /**
215
197
  * The rows a missed step's reread checks, or `undefined` for a step that never reads again: its
216
198
  * own `quarantine` rows (Q269), every one its change ends, and the ready row a ready pack's step puts; none for a prune
217
199
  * pass's row alone, or a walk's `apart` row alone, which keeps only what the next step checks
218
200
  * against its listing again (#1148); and, for clean-up's change
219
201
  * alone, the `quarantine` rows it abandons (#326), the `leaving` rows it takes (#394) and the
220
- * `leaving` rows it deletes (#1490), with the `staged` rows it puts and sweeps unchecked (#1558).
202
+ * `leaving` rows it deletes (#1490), each as a `cover` row too (#1582), and the `leaving` row of
203
+ * each `cover` row's pack it takes, with the `staged` rows it puts and sweeps unchecked (#1558).
221
204
  * A step that abandons a row and also prunes or merges commits only at its first read's version
222
205
  * (Q438).
223
206
  */
@@ -234,20 +217,45 @@ const rereadKeys = (step) => {
234
217
  if (deleted.length === 0 && put.every(isUpkeepMark)) return [];
235
218
  const checked = put.filter((row) => !isStagedPut(row));
236
219
  if (!checked.every(isCleanUpPut) || !deleted.every(isEnded)) return void 0;
237
- const leaving = deleted.filter((key) => key.collection === objectCollections.leaving);
238
- return [...checked.map(({ collection, id }) => ({
239
- collection,
240
- id
241
- })), ...leaving];
220
+ const leaving = deleted.filter(isLeftKey);
221
+ const covered = checked.flatMap((row) => {
222
+ const pack = row.collection === objectCollections.cover ? leftPack(row) : void 0;
223
+ return pack === void 0 ? [] : [leavingKey(pack)];
224
+ });
225
+ return [
226
+ ...checked.map(({ collection, id }) => ({
227
+ collection,
228
+ id
229
+ })),
230
+ ...leaving,
231
+ ...covered
232
+ ];
242
233
  };
234
+ /**
235
+ * The rows a reread holds at `rereadKeys`' keys, each decoded as its collection's, for
236
+ * `stillTakes`. One that doesn't decode fails the try with `DATA_LOSS`, whichever check would
237
+ * have reached it.
238
+ */
239
+ const heldRows = /* @__PURE__ */ Effect.fnUntraced(function* (keyed) {
240
+ const quarantine = /* @__PURE__ */ new Map();
241
+ const left = /* @__PURE__ */ new Map();
242
+ const ready = /* @__PURE__ */ new Map();
243
+ for (const row of keyed) if (row.collection === objectCollections.quarantine) quarantine.set(heldId(row), (yield* decodeHeld(QuarantineRow, row)).value);
244
+ else if (isLeftKey(row)) left.set(heldId(row), (yield* decodeLeft(row)).value);
245
+ else if (row.collection === objectCollections.ready) ready.set(heldId(row), yield* decodeRow(ReadyRow, row, "The ready shallow pack's row"));
246
+ return {
247
+ quarantine,
248
+ left,
249
+ ready
250
+ };
251
+ });
243
252
  /** A step's read, decoded, with the rows of `keys` it holds: `undefined` when the repo has none. */
244
253
  const readStep = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, keys = []) {
245
254
  const { record, snapshot } = yield* readRecord(store, internalId, [...stepReads, ...keys]);
246
255
  if (record === void 0) return void 0;
247
256
  const [refRows = [], packRows = [], timeRows = [], ...rest] = snapshot.results.slice(1);
248
257
  const [headRows = [], cursorRows = [], runRows = [], receipts = [], own = [], indexRows = [], apartRows = [], swapsRows = []] = rest;
249
- const keyed = snapshot.results.slice(stepReads.length + 1).flat();
250
- const held = new Map(keyed.map((row) => [heldId(row), row]));
258
+ const held = yield* heldRows(snapshot.results.slice(stepReads.length + 1).flat());
251
259
  const packs = yield* decodePacks(packRows);
252
260
  const refs = yield* wholeRefs(upkeepWhole, refRows);
253
261
  const times = yield* decodeTimes(timeRows);
@@ -270,72 +278,12 @@ const readStep = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId,
270
278
  outbox,
271
279
  saved,
272
280
  sweep,
273
- held,
281
+ ...held,
274
282
  index,
275
283
  apart,
276
284
  swaps
277
285
  };
278
286
  });
279
- /** The reread's `quarantine` row at `key`, or `undefined` when it holds none. */
280
- const heldQuarantine = /* @__PURE__ */ Effect.fnUntraced(function* (again, key) {
281
- const row = again.held.get(heldId(key));
282
- return row === void 0 ? void 0 : (yield* decodeHeld(QuarantineRow, row)).value;
283
- });
284
- /** The reread's `leaving` row at `key`, or `undefined` when it holds none. */
285
- const heldLeaving = /* @__PURE__ */ Effect.fnUntraced(function* (again, key) {
286
- const row = again.held.get(heldId(key));
287
- return row === void 0 ? void 0 : (yield* decodeHeld(LeavingRow, row)).value;
288
- });
289
- /** The reread's ready row at `key`, or `undefined` when it holds none. */
290
- const heldReady = /* @__PURE__ */ Effect.fnUntraced(function* (again, key) {
291
- const row = again.held.get(heldId(key));
292
- return row === void 0 ? void 0 : yield* decodeRow(ReadyRow, row, "The ready shallow pack's row");
293
- });
294
- /**
295
- * Whether a step's reread still takes its commit, as `rereadKeys` let it read again: the repo
296
- * isn't deleted, and each of the step's own `quarantine` rows is open and every pack it removes is
297
- * still listed (Q269). A ready pack's step takes it too while the reread's ready row names the pack the
298
- * step moves out, or none when it moves none: its pack answers its tip whatever moved since, and
299
- * a tip that moved builds again at the next step. A prune pass's row alone takes any version: it
300
- * adds no object and lets none go.
301
- * Clean-up's change takes the reread's version only as its decision would there (#326): each
302
- * `quarantine` row it abandons is still `open`, its `removeAt` unchanged, and its pack unlisted,
303
- * so a push that listed the pack since refuses it (#318); and each `leaving` row it takes is still
304
- * there, not taken, its `removeAt` unchanged and its pack unlisted, so a sync or a fetch that
305
- * listed the pack again since refuses it (#394, #1490); and each `leaving` row it deletes untaken
306
- * still has its pack listed. The rows it ends were abandoned or taken, which no later write undoes,
307
- * so they need no check.
308
- */
309
- const stillTakes = /* @__PURE__ */ Effect.fnUntraced(function* (again, step) {
310
- if (again.record.deleted === true) return false;
311
- const { remove = [], put = [] } = step.change;
312
- const listed = new Set(again.packs.map((pack) => pack.id));
313
- if (step.quarantine !== void 0) {
314
- if ((yield* heldQuarantine(again, step.quarantine))?.state !== "open" || !remove.every((id) => listed.has(id))) return false;
315
- for (const key of ownRows(step).slice(1)) if ((yield* heldQuarantine(again, key))?.state !== "open") return false;
316
- const leaving = put.find((row) => row.collection === objectCollections.leaving)?.id;
317
- for (const row of put.filter(isReadyPut)) if ((yield* heldReady(again, row))?.pack?.id !== leaving) return false;
318
- return true;
319
- }
320
- for (const row of put.filter(isAbandon)) {
321
- const held = yield* heldQuarantine(again, row);
322
- if (held?.state !== "open") return false;
323
- if (held.removeAt !== row.value.removeAt) return false;
324
- if (listed.has(row.id)) return false;
325
- }
326
- for (const row of put.filter(isTake)) {
327
- const held = yield* heldLeaving(again, row);
328
- if (held === void 0 || held.taken === true) return false;
329
- if (held.removeAt !== row.value.removeAt) return false;
330
- if (listed.has(row.id)) return false;
331
- }
332
- for (const key of step.change.delete ?? []) {
333
- if (key.collection !== objectCollections.leaving) continue;
334
- const held = yield* heldLeaving(again, key);
335
- if (held !== void 0 && held.taken !== true && !listed.has(key.id)) return false;
336
- }
337
- return true;
338
- });
339
287
  /**
340
288
  * Whether a commit at `writing` is too late for a remap's row: within the queue's lease margin of
341
289
  * prune's grace, `fetchLimits`' time, since the try's `at`. The remap starts only when its claim's
@@ -583,7 +531,7 @@ const repackStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, in
583
531
  const keys = rereadKeys(step);
584
532
  if (keys === void 0) return again;
585
533
  const reread = yield* readStep(store, internalId, keys);
586
- if (reread === void 0 || !(yield* stillTakes(reread, step))) return again;
534
+ if (reread === void 0 || !stillTakes(reread, step)) return again;
587
535
  if (yield* settles(parts, store, internalId, reread)) return again;
588
536
  read = reread;
589
537
  }
@@ -606,20 +554,22 @@ const rewalking = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, int
606
554
  }
607
555
  return false;
608
556
  });
609
- const decodeRepackData = Schema.decodeUnknownOption(RepackData);
610
557
  /**
611
558
  * `git.repack`'s try, in the repo's scope: one step, as `repackStep` says, given the dropping
612
559
  * commits its data says missed, and whether the try before it died or failed: a step that ends
613
560
  * with `more` starts its row's tries again at 1, so a later attempt follows one that never settled.
614
561
  */
615
- const repackHandler = (parts) => (job, context) => {
562
+ const repackTry = (parts) => ({ missed = 0 }) => Effect.flatMap(Effect.all([
563
+ CurrentJob.current,
564
+ CurrentJob.store,
565
+ CurrentJob.signal,
566
+ CurrentJob.deadline
567
+ ]), ([job, store, signal, deadline]) => {
616
568
  const pass = job.key === pruneJobKey;
617
- const step = Option.match(decodeRepackData(job.data), {
618
- onNone: () => fail("DATA_LOSS", "The repack job's data is unreadable"),
619
- onSome: ({ missed = 0 }) => repackStep(parts, context.store, jobRepo(job), context.signal, context.deadline, missed, job.attempt > 1, pass ? "prune" : "others")
620
- });
621
- return runJobTry(pass ? Effect.catchIf(step, parksPass, (error) => Effect.die(parked(error))) : step);
622
- };
569
+ const steps = pass ? "prune" : "others";
570
+ const step = repackStep(parts, store, jobRepo(job), signal, deadline, missed, job.attempt > 1, steps);
571
+ return pass ? Effect.catchIf(step, parksPass, (error) => Effect.die(parked(error))) : step;
572
+ });
623
573
  /**
624
574
  * The name a `prune` try's refusal that `parksPass` names is thrown under: `repackRetry` fails its
625
575
  * row at once, and it stays failed till a `repack` run's revive once a period, as `reviveParked`
@@ -658,18 +608,16 @@ const repackRetry = (failure) => {
658
608
  */
659
609
  /** A `git.repack` try's timeout, in ms. */
660
610
  const repackTimeout = 78e4;
611
+ const RepackJob = /* @__PURE__ */ Job.make(repackJobName, {
612
+ payload: RepackData,
613
+ timeout: repackTimeout,
614
+ concurrency: 1,
615
+ retry: repackRetry,
616
+ rebuild: () => ({})
617
+ });
661
618
  const repackJob = (parts) => {
662
- const options = {
663
- name: repackJobName,
664
- schema: repackJobSchema,
665
- timeout: repackTimeout,
666
- concurrency: 1,
667
- retry: repackRetry,
668
- handler: repackHandler(parts),
669
- rebuild: () => ({})
670
- };
671
- if (parts.onFailure !== void 0) options.onFailure = parts.onFailure;
672
- return defineJob(options);
619
+ const { onFailure } = parts;
620
+ return madeJob(RepackJob.definition(repackTry(parts), onFailure === void 0 ? {} : { onFailure }));
673
621
  };
674
622
  /** The repo's one `git.repack` row, due at `at` or now. */
675
623
  const repackJobRow = (job, at) => job.job(at === void 0 ? {
@@ -698,4 +646,4 @@ const ensureRepack = /* @__PURE__ */ Effect.fnUntraced(function* (core, jobs, sc
698
646
  * is nothing to revive, and `ensureRepack`'s add alone is what it keeps.
699
647
  */
700
648
  const noRepackRetry = { retry: async () => {} };
701
- export { ensureRepack, leavingPage, noRepackRetry, passParked, repackHandler, repackJob, repackJobRow, repackSlowJitter, repackSlowWait, repackTimeout, upkeepsOf };
649
+ export { ensureRepack, leavingPage, noRepackRetry, passParked, repackJob, repackJobRow, repackSlowJitter, repackSlowWait, repackTimeout, upkeepsOf };
@@ -82,11 +82,11 @@ const badRefName = (name) => fail("INVALID_ARGUMENT", `'${name}' isn't a full re
82
82
  * A default branch under a prefix Git moves itself, such as the merge queue's or an import's, is
83
83
  * refused: a clone's `HEAD` would check out a ref no push names.
84
84
  */
85
- const hiddenDefault = (branch) => {
86
- const hidden = hiddenUnder(branch);
87
- if (hidden === void 0) return Effect.void;
88
- return fail("INVALID_ARGUMENT", `The default branch can't be a ref Git moves: ${branch} is under ${hidden.prefix}, which ${hidden.mover} moves`, { hint: "Name a branch under 'refs/heads/', such as 'refs/heads/main'" });
89
- };
85
+ const hiddenDefault = /* @__PURE__ */ Effect.fnUntraced(function* (branch) {
86
+ const hidden = hiddenUnder((yield* CoreParts).hiddenRefs(), branch);
87
+ if (hidden === void 0) return;
88
+ return yield* fail("INVALID_ARGUMENT", `The default branch can't be a ref Git moves: ${branch} is under ${hidden.owner.prefix}, which ${hidden.mover} moves`, { hint: "Name a branch under 'refs/heads/', such as 'refs/heads/main'" });
89
+ });
90
90
  /**
91
91
  * A default branch `access` would hide from some readers is refused: a clone's `HEAD` would name
92
92
  * a branch they can't see. A record that names one, from before a pattern matched it, keeps it,
@@ -25,13 +25,14 @@ const ruleAnswer = (reports, checking, rule, reached, update) => {
25
25
  return hostEffect(reports, "rules.push", checking.about, answer);
26
26
  };
27
27
  /**
28
- * Whether `source` may change `ref`: a ref under a `hiddenRefs` prefix is its owner's own, the
29
- * merge queue's or an import's, and no push or API call moves it, whatever the rules say.
28
+ * Whether a push `as` an owner may change `ref`: a ref under one of `table`'s prefixes is its
29
+ * owner's own, the merge queue's or an import's, and no other push or API call moves it, whatever
30
+ * the rules say.
30
31
  */
31
- const gitsOwnRef = (ref, source) => {
32
- const hidden = hiddenUnder(ref);
33
- if (hidden === void 0 || hidden.owner === source) return void 0;
34
- return gitError("NOT_ALLOWED", `'${ref}' is Git's own: only ${hidden.mover} moves it`, { hint: `Push to a branch, not under ${hidden.prefix}` });
32
+ const gitsOwnRef = (table, ref, as) => {
33
+ const hidden = hiddenUnder(table, ref);
34
+ if (hidden === void 0 || hidden.owner === as) return void 0;
35
+ return gitError("NOT_ALLOWED", `'${ref}' is Git's own: only ${hidden.mover} moves it`, { hint: `Push to a branch, not under ${hidden.owner.prefix}` });
35
36
  };
36
37
  /**
37
38
  * A write to a name the caller can't write, as `RefView.writes` says: one it doesn't see, or one
@@ -58,7 +58,7 @@ export interface PushedObjects {
58
58
  }
59
59
  /**
60
60
  * A check after the host's rules, in its claim's band: the refs it refuses among `updates`, those
61
- * no earlier check refused. A claim's push check is one, and LFS's pointer check too.
61
+ * no earlier check refused. A claim's push check is one, LFS's pointer check among them.
62
62
  */
63
63
  export type ClaimedCheck = Ordered<(input: CheckInput, updates: readonly RefUpdate[]) => Effect.Effect<ReadonlyMap<RefName, GitError>, GitError>>;
64
64
  /** What a rule such as `Rules.files` tells the walk: the refs it covers, and a path it refuses. */
@@ -2,18 +2,18 @@ import { Caller } from "../contracts/actors.mjs";
2
2
  import { RepoName } from "../contracts/ids.mjs";
3
3
  import { Operation } from "../contracts/operations.mjs";
4
4
  import { GitError } from "../contracts/result.mjs";
5
- import "../contracts/server.mjs";
6
- import "../contracts/services.mjs";
5
+ import { ServerCalls } from "../contracts/server.mjs";
6
+ import { EffectCalls } from "../contracts/services.mjs";
7
7
  import { TokenId } from "../contracts/tokens.mjs";
8
- import "../auth/identify.mjs";
9
- import "../store/call-count.mjs";
10
- import "../store/promises.mjs";
11
- import "./call-names.mjs";
8
+ import { Identify } from "../auth/identify.mjs";
9
+ import { CallCount } from "../store/call-count.mjs";
10
+ import { BridgeDoor } from "../store/promises.mjs";
11
+ import { CallNames } from "./call-names.mjs";
12
12
  import { FeedItem } from "../contracts/events.mjs";
13
13
  import "../contracts/authorize.mjs";
14
- import "./parts.mjs";
14
+ import { QueueNeeds } from "./parts.mjs";
15
15
  import * as Effect from "effect/Effect";
16
- import "effect/Context";
16
+ import * as Context from "effect/Context";
17
17
  /** A revoke over HTTP names only the token: `authorize` is asked about what the token covers. */
18
18
  export interface TokenRevokeCheck {
19
19
  readonly kind: 'token.revoke';
@@ -25,5 +25,52 @@ export interface SeamAuthorizeInput {
25
25
  readonly operation: Operation | TokenRevokeCheck;
26
26
  readonly repo?: RepoName;
27
27
  }
28
+ /**
29
+ * What a server's own routes, such as REST's, reach under `GitServer`'s Promise surface: its
30
+ * `identify` and `authorize`, its Effect calls for one caller, and where a renamed repo went. The
31
+ * layers put REST below the server, so the seam sits here. Each of them dies once the server is
32
+ * closed; the server's door alone decides the rest.
33
+ */
34
+ export interface ServerParts {
35
+ readonly basePath: string;
36
+ /** The context the server's calls run over, which its jobs and routes provide. */
37
+ readonly needs: Context.Context<QueueNeeds>;
38
+ /**
39
+ * The Effect calls, each deciding for `caller`, the one `identify` answered: its token's scope or
40
+ * its grant is the ceiling, whatever actor an input names.
41
+ */
42
+ readonly callsFor: (caller: Caller) => EffectCalls<ServerCalls>;
43
+ readonly identify: Identify;
44
+ readonly authorize: (input: SeamAuthorizeInput) => Effect.Effect<void, GitError>;
45
+ /**
46
+ * The name a renamed repo moved to, while nothing has been made under its old one, told only to
47
+ * a `caller` that may read the repo there: `undefined` for anyone else.
48
+ */
49
+ readonly renamedTo: (caller: Caller, repo: RepoName) => Effect.Effect<RepoName | undefined, GitError>;
50
+ /** A repo's events for `caller`, after `after` or from the oldest kept, as `openFeed` streams them. */
51
+ readonly listen: Listen;
52
+ /**
53
+ * The adapter's whole `callLimits`, as the bound of a request that counts from its first call, as
54
+ * Git's REST does: an extension's route, which counts after `identify`, takes
55
+ * `requestCallsBefore` off it (#725).
56
+ */
57
+ readonly requestMost: CallCount;
58
+ }
28
59
  /** Opens a repo's event stream for `caller`: `openFeed` over the server's core and clock. */
29
- export type Listen = (caller: Caller, repo: RepoName, after: number | undefined) => Effect.Effect<ReadableStream<FeedItem>, GitError>;
60
+ export type Listen = (caller: Caller, repo: RepoName, after: number | undefined) => Effect.Effect<ReadableStream<FeedItem>, GitError>;
61
+ /** A server's parts before its runtime is built: where it serves, its groups, and its build. */
62
+ export interface Seam {
63
+ readonly basePath: string;
64
+ readonly names: CallNames;
65
+ /** The server's door, which a route outside its runtime, such as REST's, asks before and after. */
66
+ readonly door: BridgeDoor;
67
+ /** The parts once the build is done: `UNAVAILABLE`, naming its failure, once it failed. */
68
+ readonly parts: Effect.Effect<ServerParts, GitError>;
69
+ }
70
+ declare const ServerSeam_base: Context.ServiceClass<ServerSeam, "@ref0/git/ServerSeam", Seam>;
71
+ /**
72
+ * The seam of the server `Git.layer` built, which a feature that serves the server's calls, as
73
+ * `Rest.layer` does, reads as it builds. Internal: no entry exports it.
74
+ */
75
+ export declare class ServerSeam extends /* @__PURE__ */ ServerSeam_base {}
76
+ export {};
@@ -5,7 +5,13 @@ import { revokeCheck } from "./tokens.mjs";
5
5
  import { check } from "../contracts/authorize.mjs";
6
6
  import { CoreParts } from "./parts.mjs";
7
7
  import * as Effect from "effect/Effect";
8
+ import * as Context from "effect/Context";
8
9
  // src/core/seam.ts
10
+ /**
11
+ * The seam of the server `Git.layer` built, which a feature that serves the server's calls, as
12
+ * `Rest.layer` does, reads as it builds. Internal: no entry exports it.
13
+ */
14
+ var ServerSeam = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/ServerSeam")) {};
9
15
  const seamByServer = /* @__PURE__ */ new WeakMap();
10
16
  /** Called once, by `createGitServer`, for the server it returns. */
11
17
  const attachParts = (server, seam) => {
@@ -55,4 +61,4 @@ const renamedTo = /* @__PURE__ */ Effect.fnUntraced(function* (caller, repo) {
55
61
  const to = yield* redirectOf(store, repo);
56
62
  return to === void 0 ? void 0 : yield* readableRedirect(caller, to);
57
63
  });
58
- export { attachParts, lazyParts, renamedTo, seamAuthorize, seamOf };
64
+ export { ServerSeam, attachParts, lazyParts, renamedTo, seamAuthorize, seamOf };
@@ -0,0 +1,75 @@
1
+ import { objectCollections } from "../storage/layout.mjs";
2
+ import { LeavingRow, QuarantineRow, isLeftKey, leavingKey, leftPack } from "../storage/rows.mjs";
3
+ import * as Schema from "effect/Schema";
4
+ // src/core/still-takes.ts
5
+ /** A row's place in a reread's maps: its collection and its ID. */
6
+ const heldId = (key) => `${key.collection}/${key.id}`;
7
+ const isQuarantine = /* @__PURE__ */ Schema.is(QuarantineRow);
8
+ const isLeaving = /* @__PURE__ */ Schema.is(LeavingRow);
9
+ /** Clean-up's put: a `quarantine` row it commits abandoned. */
10
+ const isAbandon = (row) => row.collection === objectCollections.quarantine && isQuarantine(row.value) && row.value.state === "abandoned";
11
+ /** Clean-up's put: a `leaving` or `cover` row it commits taken (#394, #1582). */
12
+ const isTake = (row) => isLeftKey(row) && isLeaving(row.value) && row.value.taken === true;
13
+ /** The ready shallow pack's step's put: its row. */
14
+ const isReadyPut = (row) => row.collection === objectCollections.ready;
15
+ /**
16
+ * A listing step's own `quarantine` rows: `step.quarantine`, then each other `quarantine` row its
17
+ * change ends, such as a streaming merge's packs past its first (maintenance-1m B5).
18
+ */
19
+ const ownRows = (step) => {
20
+ const own = step.quarantine;
21
+ if (own === void 0) return [];
22
+ return [own, ...(step.change.delete ?? []).filter((key) => key.collection === objectCollections.quarantine && key.id !== own.id)];
23
+ };
24
+ /**
25
+ * Whether a step's reread still takes its commit, as `rereadKeys` let it read again: the repo
26
+ * isn't deleted, and each of the step's own `quarantine` rows is open and every pack it removes is
27
+ * still listed (Q269). A ready pack's step takes it too while the reread's ready row names the pack the
28
+ * step moves out, or none when it moves none: its pack answers its tip whatever moved since, and
29
+ * a tip that moved builds again at the next step. A prune pass's row alone takes any version: it
30
+ * adds no object and lets none go.
31
+ * Clean-up's change takes the reread's version only as its decision would there (#326): each
32
+ * `quarantine` row it abandons is still `open`, its `removeAt` unchanged, and its pack unlisted,
33
+ * so a push that listed the pack since refuses it (#318); and each `leaving` row it takes is still
34
+ * there, not taken, its `removeAt` unchanged and its pack unlisted, so a sync or a fetch that
35
+ * listed the pack again since refuses it (#394, #1490); and each `leaving` row it deletes untaken
36
+ * still has its pack listed. A `cover` row is checked as a `leaving` row is (#1582), and is taken
37
+ * only while its pack has no `leaving` row, which a replace may have put since with a later
38
+ * `removeAt` for the same marker. The rows it ends were abandoned or taken, which no later write undoes,
39
+ * so they need no check.
40
+ */
41
+ const stillTakes = (again, step) => {
42
+ if (again.record.deleted === true) return false;
43
+ const { remove = [], put = [] } = step.change;
44
+ const listed = new Set(again.packs.map((pack) => pack.id));
45
+ const quarantine = (key) => again.quarantine.get(heldId(key));
46
+ const left = (key) => again.left.get(heldId(key));
47
+ if (step.quarantine !== void 0) {
48
+ if (quarantine(step.quarantine)?.state !== "open" || !remove.every((id) => listed.has(id))) return false;
49
+ if (ownRows(step).slice(1).some((key) => quarantine(key)?.state !== "open")) return false;
50
+ const leaving = put.find((row) => row.collection === objectCollections.leaving)?.id;
51
+ return put.filter(isReadyPut).every((row) => again.ready.get(heldId(row))?.pack?.id === leaving);
52
+ }
53
+ for (const row of put.filter(isAbandon)) {
54
+ const held = quarantine(row);
55
+ if (held?.state !== "open") return false;
56
+ if (held.removeAt !== row.value.removeAt) return false;
57
+ if (listed.has(row.id)) return false;
58
+ }
59
+ for (const row of put.filter(isTake)) {
60
+ const held = left(row);
61
+ if (held === void 0 || held.taken === true) return false;
62
+ if (held.removeAt !== row.value.removeAt) return false;
63
+ const pack = leftPack(row);
64
+ if (pack === void 0 || listed.has(pack)) return false;
65
+ if (row.collection === objectCollections.cover && left(leavingKey(pack)) !== void 0) return false;
66
+ }
67
+ for (const key of step.change.delete ?? []) {
68
+ const pack = leftPack(key);
69
+ if (pack === void 0) continue;
70
+ const held = left(key);
71
+ if (held !== void 0 && held.taken !== true && !listed.has(pack)) return false;
72
+ }
73
+ return true;
74
+ };
75
+ export { heldId, isAbandon, isReadyPut, isTake, ownRows, stillTakes };
@@ -1,6 +1,7 @@
1
1
  import { RefView } from "../contracts/access.mjs";
2
2
  import "../contracts/actors.mjs";
3
3
  import { Oid, RefName } from "../contracts/ids.mjs";
4
+ import "../contracts/git.mjs";
4
5
  import "../contracts/repos.mjs";
5
6
  import { GitObjects, IndexCalls, IndexedObjects, Quarantine, VisibleInput, VisibleSet } from "../contracts/objects.mjs";
6
7
  import { Listed } from "../contracts/store.mjs";
@@ -1,4 +1,4 @@
1
- import { gitsOwnMove, hiddenRefs } from "../protocol/wire/lines.mjs";
1
+ import { gitsOwnMove } from "../protocol/wire/lines.mjs";
2
2
  import { answerSpent, resultCall } from "../store/errors.mjs";
3
3
  import { upstreamOf } from "../store/catalogue.mjs";
4
4
  import { collections } from "../store/scopes.mjs";
@@ -169,9 +169,9 @@ const objectsOverViews = { read: ({ view, at }) => {
169
169
  * `refView`, with the refs under a prefix `owner` owns seen too: the merge queue's publish, which
170
170
  * runs as the entry's caller, deletes its candidate and moves its target to the candidate's commit.
171
171
  */
172
- const ownersView = (refView, owner) => {
172
+ const ownersView = (refView, table, owner) => {
173
173
  if (refView.whole) return refView;
174
- const owns = (ref) => gitsOwnMove(owner, ref);
174
+ const owns = (ref) => gitsOwnMove(table, owner, ref);
175
175
  return {
176
176
  ...refView,
177
177
  sees: (ref) => owns(ref) || refView.sees(ref),
@@ -179,17 +179,16 @@ const ownersView = (refView, owner) => {
179
179
  };
180
180
  };
181
181
  /**
182
- * `resolved`, opened for `caller`, as the caller sees it: for a push from `source`, the merge
183
- * queue or an import, with Git's own refs that source moves seen as well.
182
+ * `resolved`, opened for `caller`, as the caller sees it: for a push `as` a prefix's owner, the
183
+ * merge queue's or an import's, with the refs under that prefix seen as well.
184
184
  */
185
- const viewOf = /* @__PURE__ */ Effect.fnUntraced(function* (caller, resolved, source, options = {}) {
185
+ const viewOf = /* @__PURE__ */ Effect.fnUntraced(function* (caller, resolved, owner, options = {}) {
186
186
  const core = yield* CoreParts;
187
187
  const { objects: sealed } = yield* ObjectsParts;
188
188
  const needs = yield* coreContext;
189
189
  const held = Effect.provideContext(refViewIn(caller, repoAccess(resolved)), needs);
190
190
  const asked = options.fresh === true ? Effect.provideService(held, AudienceMemo, /* @__PURE__ */ new Map()) : held;
191
- const owner = hiddenRefs.find((hidden) => hidden.owner === source)?.owner;
192
- const refView = owner === void 0 ? asked : Effect.map(asked, (seen) => ownersView(seen, owner));
191
+ const refView = owner === void 0 ? asked : Effect.map(asked, (seen) => ownersView(seen, core.hiddenRefs(), owner));
193
192
  const whole = SealedObjects.whole(sealed, viewWhole);
194
193
  const followsRefs = objectsFollowRefs(core, resolved);
195
194
  const narrowed = Effect.map(refView, (seen) => !seen.whole || followsRefs);
@@ -220,7 +219,7 @@ const viewOf = /* @__PURE__ */ Effect.fnUntraced(function* (caller, resolved, so
220
219
  };
221
220
  const read = at.pushed === void 0 ? `${at.listed.version}` : `${at.listed.version}+${at.pushed.id}`;
222
221
  const reach = options.ownWrites === false ? `${read}:refs` : read;
223
- const key = owner === void 0 ? reach : `${reach}:${owner}`;
222
+ const key = owner === void 0 ? reach : `${reach}:${owner.prefix}`;
224
223
  const from = (asked) => () => SealedObjects.seen(sealed, viewWhole, at.listed, asked, at.pushed);
225
224
  const writer = options.ownWrites === false ? void 0 : yield* ownWriter(caller);
226
225
  const clock = yield* Effect.clockWith(Effect.succeed);
@@ -84,7 +84,7 @@ const workCalls = (bound) => {
84
84
  }
85
85
  const scope = repoScope(internalId);
86
86
  if (!seen && kind === "work.retry") return yield* fail("NOT_FOUND", `No job '${job.name}' '${job.key}'`);
87
- if (!seen) {} else if (kind === "work.discard" && isDeliverJob(job)) yield* skipFailed(core.store, jobs, scope);
87
+ if (!seen) {} else if (kind === "work.discard" && isDeliverJob(job) && core.events !== void 0) yield* skipFailed(core.store, jobs, scope, job, core.events.deliveries);
88
88
  else yield* storeCall(() => kind === "work.retry" ? jobs.retry(scope, job) : jobs.discard(scope, job));
89
89
  if (kept !== void 0) yield* afterCommit(keepAnswer(internalId, kept));
90
90
  return;
package/dist/extend.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { extendGit } from "./server/extension.mjs";
2
2
  import { isServerClosed } from "./store/closed.mjs";
3
3
  import { ExtendedGit, GitExtension, GitRequest } from "./contracts/server.mjs";
4
- import { Bucket, Clock, RecordStore, Store } from "./contracts/promises.mjs";
4
+ import { Bucket } from "./contracts/objects.mjs";
5
+ import { Clock, RecordStore, Store } from "./contracts/promises.mjs";
5
6
  import { ImportState } from "./contracts/sync.mjs";
6
7
  export { type Bucket, type Clock, type ExtendedGit, type GitExtension, type GitRequest, type ImportState, type RecordStore, type Store, extendGit, isServerClosed };