@ref0/git 0.11.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 (262) hide show
  1. package/dist/access/private-refs.mjs +8 -7
  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 +14 -3
  28. package/dist/contracts/git.d.mts +41 -12
  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 +30 -23
  42. package/dist/contracts/result.mjs +24 -9
  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 +90 -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.d.mts +1 -0
  54. package/dist/core/access.mjs +34 -13
  55. package/dist/core/ancestry.d.mts +9 -0
  56. package/dist/core/ancestry.mjs +6 -6
  57. package/dist/core/asked.mjs +68 -0
  58. package/dist/core/call-names.mjs +1 -0
  59. package/dist/core/call-services.mjs +2 -1
  60. package/dist/core/events/deliver.d.mts +1 -0
  61. package/dist/core/events/deliver.mjs +15 -3
  62. package/dist/core/forks.mjs +42 -16
  63. package/dist/core/imports.mjs +156 -13
  64. package/dist/core/index-job.mjs +9 -6
  65. package/dist/core/job-view.mjs +8 -9
  66. package/dist/core/mirror-rows.mjs +19 -4
  67. package/dist/core/objects/commits.mjs +16 -6
  68. package/dist/core/objects/reading.mjs +17 -9
  69. package/dist/core/parts.d.mts +8 -2
  70. package/dist/core/parts.mjs +1 -4
  71. package/dist/core/purge.mjs +76 -6
  72. package/dist/core/push-decide.mjs +1 -1
  73. package/dist/core/push-files.d.mts +12 -0
  74. package/dist/core/push-files.mjs +225 -0
  75. package/dist/core/push-repo.d.mts +8 -0
  76. package/dist/core/push-repo.mjs +56 -0
  77. package/dist/core/push.d.mts +17 -0
  78. package/dist/core/push.mjs +107 -32
  79. package/dist/core/receipts.mjs +26 -10
  80. package/dist/core/ref-view.mjs +59 -5
  81. package/dist/core/refs.mjs +18 -10
  82. package/dist/core/registered-rows.mjs +7 -5
  83. package/dist/core/repack.mjs +16 -11
  84. package/dist/core/repo-info.mjs +16 -9
  85. package/dist/core/repos.mjs +30 -14
  86. package/dist/core/saved-caller-views.d.mts +18 -0
  87. package/dist/core/saved-caller-views.mjs +17 -4
  88. package/dist/core/saved-callers-public.d.mts +3 -3
  89. package/dist/core/saved-callers-public.mjs +3 -2
  90. package/dist/core/saved-callers.d.mts +7 -0
  91. package/dist/core/seam.mjs +2 -2
  92. package/dist/core/view.d.mts +6 -0
  93. package/dist/core/view.mjs +45 -12
  94. package/dist/core/work.mjs +47 -22
  95. package/dist/effect.d.mts +3 -1
  96. package/dist/effect.mjs +3 -1
  97. package/dist/engine/reads.mjs +13 -6
  98. package/dist/engine/walk.mjs +4 -4
  99. package/dist/event-streams/event-streams.d.mts +1 -1
  100. package/dist/event-streams/event-streams.mjs +1 -1
  101. package/dist/event-streams/stream.d.mts +1 -1
  102. package/dist/event-streams/stream.mjs +1 -1
  103. package/dist/extend.d.mts +4 -3
  104. package/dist/extend.mjs +3 -2
  105. package/dist/http/answers.mjs +4 -2
  106. package/dist/http/core-parts.mjs +64 -15
  107. package/dist/http/handler.mjs +2 -2
  108. package/dist/http/node.mjs +5 -4
  109. package/dist/http/parts.d.mts +1 -0
  110. package/dist/http/push-upload-job.mjs +503 -0
  111. package/dist/http/push-uploads.d.mts +1 -0
  112. package/dist/http/push-uploads.mjs +120 -59
  113. package/dist/http/upload-pack.mjs +7 -6
  114. package/dist/index.d.mts +23 -24
  115. package/dist/index.mjs +4 -7
  116. package/dist/lfs/base.d.mts +7 -3
  117. package/dist/lfs/base.mjs +2 -1
  118. package/dist/lfs/copy.d.mts +46 -0
  119. package/dist/lfs/copy.mjs +26 -0
  120. package/dist/lfs/layer.mjs +4 -2
  121. package/dist/lfs/locks.mjs +14 -9
  122. package/dist/lfs/objects.d.mts +6 -0
  123. package/dist/lfs/objects.mjs +95 -61
  124. package/dist/lfs/rows.d.mts +13 -0
  125. package/dist/lfs/service.d.mts +1 -7
  126. package/dist/lfs/service.mjs +1 -9
  127. package/dist/lfs/upload-most.mjs +5 -5
  128. package/dist/node.d.mts +2 -2
  129. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  130. package/dist/protocol/bytes/sha256.d.mts +32 -0
  131. package/dist/protocol/bytes/sha256.mjs +105 -49
  132. package/dist/protocol/wire/advertisement.mjs +9 -4
  133. package/dist/protocol/wire/lines.d.mts +4 -2
  134. package/dist/protocol/wire/lines.mjs +11 -5
  135. package/dist/protocol/wire/push-uploads.mjs +13 -1
  136. package/dist/protocol/wire/v2.mjs +2 -2
  137. package/dist/protocol.d.mts +3 -1
  138. package/dist/protocol.mjs +3 -1
  139. package/dist/queue/advance.mjs +1 -1
  140. package/dist/queue/calls.mjs +21 -1
  141. package/dist/queue/host.d.mts +1 -7
  142. package/dist/queue/host.mjs +1 -7
  143. package/dist/queue/layer.mjs +1 -1
  144. package/dist/queue/trim.mjs +1 -1
  145. package/dist/rest/blobs.d.mts +16 -8
  146. package/dist/rest/blobs.mjs +1 -1
  147. package/dist/rest/caller.d.mts +49 -9
  148. package/dist/rest/caller.mjs +1 -1
  149. package/dist/rest/client.d.mts +10 -3
  150. package/dist/rest/client.mjs +4 -0
  151. package/dist/rest/commits.d.mts +272 -239
  152. package/dist/rest/errors.d.mts +24 -4
  153. package/dist/rest/events.d.mts +9 -6
  154. package/dist/rest/events.mjs +1 -2
  155. package/dist/rest/files.d.mts +112 -100
  156. package/dist/rest/forks.d.mts +146 -122
  157. package/dist/rest/handler.mjs +4 -57
  158. package/dist/rest/handlers.d.mts +1 -1
  159. package/dist/rest/handlers.mjs +18 -4
  160. package/dist/rest/layer.mjs +10 -2
  161. package/dist/rest/me.d.mts +8 -4
  162. package/dist/rest/merges.d.mts +8 -4
  163. package/dist/rest/paths.mjs +1 -0
  164. package/dist/rest/queue.d.mts +292 -236
  165. package/dist/rest/refs.d.mts +98 -69
  166. package/dist/rest/repos.d.mts +133 -105
  167. package/dist/rest/tags.d.mts +100 -88
  168. package/dist/rest/tokens.d.mts +192 -168
  169. package/dist/rest/topics.d.mts +154 -134
  170. package/dist/rest/trees.d.mts +32 -16
  171. package/dist/rest/work.d.mts +467 -20
  172. package/dist/rest/work.mjs +8 -0
  173. package/dist/server/edge-node.d.mts +9 -13
  174. package/dist/server/edge-node.mjs +9 -12
  175. package/dist/server/git-layer.d.mts +1 -6
  176. package/dist/server/git-layer.mjs +2 -2
  177. package/dist/server/git-namespace.d.mts +4 -4
  178. package/dist/server/joined.d.mts +15 -22
  179. package/dist/server/joined.mjs +5 -29
  180. package/dist/server/lifecycle.mjs +107 -23
  181. package/dist/server/registry.mjs +9 -1
  182. package/dist/server/server.mjs +139 -216
  183. package/dist/storage/budget.mjs +2 -2
  184. package/dist/storage/clean-up.mjs +13 -10
  185. package/dist/storage/fetch.mjs +13 -8
  186. package/dist/storage/file-limits.mjs +24 -0
  187. package/dist/storage/index-build.d.mts +1 -0
  188. package/dist/storage/index-build.mjs +106 -62
  189. package/dist/storage/index-fetch.mjs +16 -3
  190. package/dist/storage/index-reach.mjs +33 -5
  191. package/dist/storage/index-remap.mjs +8 -1
  192. package/dist/storage/index-shallow.mjs +5 -3
  193. package/dist/storage/largest-files.mjs +48 -0
  194. package/dist/storage/lfs-pointers.mjs +10 -1
  195. package/dist/storage/loose.mjs +3 -1
  196. package/dist/storage/memory-budget.mjs +154 -8
  197. package/dist/storage/merge-cut.mjs +5 -4
  198. package/dist/storage/pack-reads.mjs +246 -34
  199. package/dist/storage/pack-receive.mjs +83 -25
  200. package/dist/storage/packs.mjs +37 -21
  201. package/dist/storage/prune-keep.mjs +203 -34
  202. package/dist/storage/prune-seen.mjs +11 -6
  203. package/dist/storage/prune-walk.mjs +219 -81
  204. package/dist/storage/prune.mjs +629 -196
  205. package/dist/storage/push-uploads.mjs +36 -12
  206. package/dist/storage/quarantine.mjs +9 -7
  207. package/dist/storage/ready.mjs +47 -19
  208. package/dist/storage/receive-bounds.mjs +29 -8
  209. package/dist/storage/receive-state.mjs +8 -0
  210. package/dist/storage/receive-steps.mjs +71 -18
  211. package/dist/storage/repack.d.mts +1 -1
  212. package/dist/storage/repack.mjs +1 -8
  213. package/dist/storage/rows.mjs +12 -1
  214. package/dist/storage/shallow.d.mts +1 -0
  215. package/dist/storage/shallow.mjs +26 -4
  216. package/dist/storage/stream-whole.mjs +5 -2
  217. package/dist/storage/visible.mjs +29 -1
  218. package/dist/storage/walk.mjs +2 -1
  219. package/dist/store/catalogue.mjs +1 -0
  220. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  221. package/dist/store/cursor-seal-public.d.mts +5 -0
  222. package/dist/store/cursor-seal-public.mjs +5 -0
  223. package/dist/store/cursor-seal.d.mts +16 -2
  224. package/dist/store/cursor-seal.mjs +26 -14
  225. package/dist/store/errors.mjs +9 -1
  226. package/dist/store/records.d.mts +2 -0
  227. package/dist/store/records.mjs +9 -6
  228. package/dist/store/repo-record.d.mts +27 -0
  229. package/dist/store/repo-record.mjs +141 -4
  230. package/dist/store/scopes.mjs +10 -2
  231. package/dist/sync/bound.d.mts +2 -0
  232. package/dist/sync/bound.mjs +11 -2
  233. package/dist/sync/github.d.mts +6 -1
  234. package/dist/sync/github.mjs +63 -42
  235. package/dist/sync/http.mjs +36 -1
  236. package/dist/sync/import.mjs +4 -2
  237. package/dist/sync/layer.mjs +6 -2
  238. package/dist/sync/lfs-batch.mjs +119 -0
  239. package/dist/sync/lfs-copy.mjs +251 -0
  240. package/dist/sync/mirror.mjs +227 -147
  241. package/dist/sync/said.mjs +204 -0
  242. package/dist/sync/smart-http.mjs +4 -2
  243. package/dist/sync/step.mjs +33 -13
  244. package/dist/sync/tries.mjs +71 -24
  245. package/dist/sync.d.mts +2 -2
  246. package/dist/topics/advance.mjs +10 -3
  247. package/dist/topics/host.mjs +1 -19
  248. package/dist/topics/layer.mjs +1 -1
  249. package/package.json +3 -8
  250. package/dist/auth/bridge.mjs +0 -30
  251. package/dist/auth/helpers.d.mts +0 -17
  252. package/dist/core/purge.d.mts +0 -8
  253. package/dist/core/registered-rows.d.mts +0 -4
  254. package/dist/core/repack.d.mts +0 -11
  255. package/dist/http/handler.d.mts +0 -2
  256. package/dist/rest/handler.d.mts +0 -21
  257. package/dist/rest.d.mts +0 -2
  258. package/dist/rest.mjs +0 -1
  259. package/dist/server/registry.d.mts +0 -16
  260. package/dist/server/server.d.mts +0 -36
  261. package/dist/storage/repack-job.d.mts +0 -3
  262. package/dist/topics/host.d.mts +0 -7
@@ -9,6 +9,25 @@ import * as Effect from "effect/Effect";
9
9
  const infiniteDepth = 2147483647;
10
10
  const notACommit = (object) => gitError("INVALID_ARGUMENT", `The shallow line names ${object.oid}, a ${object.type}`, { hint: "A shallow clone names only commits it holds without their parents" });
11
11
  /**
12
+ * `deepened` with the repo's roots its pack sends, `sent`, among its shallow lines: each one the
13
+ * client doesn't already hold without its parents, as Git's server names each of a shallow repo's
14
+ * own its walk reaches. A root the pack doesn't send isn't named, so one only a hidden ref reaches,
15
+ * or one below the haves, never is.
16
+ */
17
+ const withRootsSent = (deepened, sent) => {
18
+ const named = new Set(deepened.shallow);
19
+ const shallow = [...deepened.shallow];
20
+ for (const oid of sent) {
21
+ if (named.has(oid) || deepened.clientShallows.has(oid)) continue;
22
+ named.add(oid);
23
+ shallow.push(oid);
24
+ }
25
+ return shallow.length === deepened.shallow.length ? deepened : {
26
+ ...deepened,
27
+ shallow
28
+ };
29
+ };
30
+ /**
12
31
  * The client's shallow commits this repo holds: one it doesn't hold is passed over,
13
32
  * as Git's server does, and one that isn't a commit is refused.
14
33
  */
@@ -87,10 +106,13 @@ const byDepth = /* @__PURE__ */ Effect.fnUntraced(function* (read, starts, depth
87
106
  * - `deepen 2147483647`, without `deepen-relative`, unshallows every one the wants reach, one
88
107
  * behind another too. Git's unshallows every one it holds, but the history behind one no
89
108
  * want reaches isn't the caller's to fetch.
109
+ * A client's shallow commit that is one of the repo's roots is never unshallowed: the repo holds
110
+ * no parents of it to send, so it stays a cut.
90
111
  */
91
112
  const planShallow = /* @__PURE__ */ Effect.fnUntraced(function* (read, request) {
92
- const shallows = yield* clientShallowsOf(read, request.shallows);
93
- const clientShallows = new Set(shallows.keys());
113
+ const held = yield* clientShallowsOf(read, request.shallows);
114
+ const clientShallows = new Set(held.keys());
115
+ const shallows = new Map([...held].filter(([oid]) => !read.roots.has(oid)));
94
116
  const depth = request.depth;
95
117
  if (depth === void 0) return {
96
118
  shallow: [],
@@ -116,7 +138,7 @@ const planShallow = /* @__PURE__ */ Effect.fnUntraced(function* (read, request)
116
138
  const from = relative ? (yield* reachedShallows(read, wants, shallows, false)).map((commit) => commit.oid) : wants;
117
139
  const levels = yield* byDepth(read, from, relative ? depth + 1 : depth);
118
140
  const unshallowed = [...shallows.values()].filter((commit) => levels.within.has(commit.oid));
119
- const kept = [...clientShallows].filter((oid) => !levels.within.has(oid));
141
+ const kept = [...clientShallows].filter((oid) => !shallows.has(oid) || !levels.within.has(oid));
120
142
  return {
121
143
  shallow: levels.edge.filter((oid) => !clientShallows.has(oid)),
122
144
  unshallow: unshallowed.map((commit) => commit.oid),
@@ -125,4 +147,4 @@ const planShallow = /* @__PURE__ */ Effect.fnUntraced(function* (read, request)
125
147
  starts: parentsOf(unshallowed)
126
148
  };
127
149
  });
128
- export { infiniteDepth, notACommit, planShallow };
150
+ export { infiniteDepth, notACommit, planShallow, withRootsSent };
@@ -151,9 +151,12 @@ const wholePlan = /* @__PURE__ */ Effect.fnUntraced(function* (store, bucket, in
151
151
  const unique = yield* copies(packs, rows, charge);
152
152
  const spans = unique.packs.reduce((sum, { cut }) => sum + cut.length / 2, 0);
153
153
  const skipped = rows.length - unique.rows.length + spans;
154
+ const rowIds = (input.roots?.length ?? 0) === 0 ? void 0 : new Set(rows.map(({ oid }) => oid));
155
+ const roots = (input.roots ?? []).filter((oid) => rowIds?.has(oid) === true || packs.some(({ index }) => index.find(oid) !== void 0));
154
156
  return {
155
157
  ...unique,
156
- objects: objects - skipped
158
+ objects: objects - skipped,
159
+ roots
157
160
  };
158
161
  });
159
162
  /**
@@ -295,7 +298,7 @@ const wholeStream = (bucket, plan, signal, done = () => {}, count) => {
295
298
  };
296
299
  /** The whole clone's answer, its stream ended by the call's signal and the fetch's deadline. */
297
300
  const wholeAnswer = (plan, pack) => ({
298
- shallow: [],
301
+ shallow: plan.roots,
299
302
  unshallow: [],
300
303
  objects: plan.objects,
301
304
  pack
@@ -99,6 +99,34 @@ const walkedVisible = (objects, listed, input, walk = {}) => {
99
99
  shown
100
100
  };
101
101
  };
102
+ /**
103
+ * Which of `input.roots` the commits `input.tips` reach in `listed`, read through `objects`, the
104
+ * repo's whole objects: a walk of the commits and tags from the tips to its end, following no
105
+ * root's parents, which never stops once the roots it's met are all it's asked. So its reads are
106
+ * the tips' history's, whatever roots it doesn't reach, as one only a hidden ref reaches. Past
107
+ * `most` objects, `wantWalkMost` unless given, it refuses as `walkedVisible` does, never a guess.
108
+ */
109
+ const walkedRoots = /* @__PURE__ */ Effect.fnUntraced(function* (objects, listed, input, most = wantWalkMost) {
110
+ const roots = input.roots ?? /* @__PURE__ */ new Set();
111
+ const walk = yield* walkObjects(objects);
112
+ const passed = new Set(input.tips);
113
+ let frontier = [...passed];
114
+ let reads = 0;
115
+ while (frontier.length > 0) {
116
+ const batch = frontier.slice(0, walkBatch);
117
+ if (reads + batch.length > most) return yield* Effect.fail(visibleTooLong(most));
118
+ const stepped = (oid) => Effect.flatMap(walk.read(listed, { oid }), (object) => object === void 0 ? Effect.succeed(void 0) : stepsOf(object, false, roots));
119
+ const found = yield* Effect.forEach(batch, stepped, { concurrency: 16 });
120
+ frontier = frontier.slice(walkBatch);
121
+ reads += batch.length;
122
+ for (const oid of found.flatMap((steps) => steps === void 0 ? [] : onward(steps))) {
123
+ if (passed.has(oid)) continue;
124
+ passed.add(oid);
125
+ frontier.push(oid);
126
+ }
127
+ }
128
+ return new Set([...roots].filter((root) => passed.has(root)));
129
+ }, Effect.scoped);
102
130
  /** `set`'s answers as a `packReader`'s `visible`, its ask interrupted when the read is. */
103
131
  const visibleOf = (set) => {
104
132
  const asked = (answer) => (oids) => oids.length === 0 ? Effect.succeed(/* @__PURE__ */ new Set()) : answer(oids);
@@ -154,4 +182,4 @@ const withPushed = (set, objects, own) => {
154
182
  shown: (oids, call) => hasEffect(oids, set.shown, call?.signal)
155
183
  };
156
184
  };
157
- export { isVisibleTooLong, notReachable, seenFetch, visibleOf, walkedVisible, withPushed };
185
+ export { isVisibleTooLong, notReachable, seenFetch, visibleOf, walkedRoots, walkedVisible, withPushed };
@@ -154,7 +154,8 @@ const countedReads = (reads, readsMost, charge, calls, release) => {
154
154
  letGo,
155
155
  letGoReads,
156
156
  release: given,
157
- through: readThrough
157
+ through: readThrough,
158
+ roots
158
159
  }, placed);
159
160
  };
160
161
  /**
@@ -495,6 +495,7 @@ const hostRecordOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, interna
495
495
  const upstream = yield* upstreamOf(store, record);
496
496
  if (upstream !== void 0) read.upstream = upstream;
497
497
  if (record.fork !== void 0) read.upstreamInternalId = record.fork.upstreamInternalId;
498
+ if (record.renamedSeq !== void 0) read.renamedSeq = record.renamedSeq;
498
499
  return read;
499
500
  });
500
501
  /**
@@ -0,0 +1,2 @@
1
+ import { cursor_seal_public_d_exports } from "./cursor-seal-public.mjs";
2
+ export { cursor_seal_public_d_exports as CursorSeal };
@@ -0,0 +1,5 @@
1
+ import { CursorSeal, SealRecords, make } from "./cursor-seal.mjs";
2
+ declare namespace cursor_seal_public_d_exports {
3
+ export { CursorSeal, SealRecords, make };
4
+ }
5
+ export { type CursorSeal, type SealRecords, cursor_seal_public_d_exports, make };
@@ -0,0 +1,5 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { make } from "./cursor-seal.mjs";
3
+ // src/store/cursor-seal-public.ts
4
+ var cursor_seal_public_exports = /* @__PURE__ */ __exportAll({ make: () => make });
5
+ export { cursor_seal_public_exports, make };
@@ -1,13 +1,27 @@
1
1
  import "../contracts/promises.mjs";
2
2
  import { GitError } from "../contracts/result.mjs";
3
3
  import * as Effect from "effect/Effect";
4
+ import { Addition, Read, Scope, Snapshot } from "@ref0/infra";
5
+ /** What a seal keeps its key with: a store's reads and adds in its scope, failing as `GitError`. */
6
+ export interface SealRecords {
7
+ readonly read: (scope: Scope, reads: readonly Read[]) => Effect.Effect<Snapshot, GitError>;
8
+ readonly add: (scope: Scope, addition: Addition) => Effect.Effect<void, GitError>;
9
+ }
4
10
  /**
5
11
  * Seals list cursors, so a cursor names nothing its caller may not read, such as a row the list
6
- * skipped: AES-GCM under the server's key in `git/repos`, with a fresh nonce for each cursor and the
12
+ * skipped: AES-GCM under its scope's key, with a fresh nonce for each cursor and the scope and the
7
13
  * list's `bound` as its additional data. A cursor opens only on the list it was sealed for.
8
14
  */
9
15
  export interface CursorSeal {
10
16
  readonly seal: (bound: string, text: string) => Effect.Effect<string, GitError>;
11
17
  /** The text `cursor` was sealed over for `bound`, or `undefined` for any other text. */
12
18
  readonly open: (bound: string, cursor: string) => Effect.Effect<string | undefined, GitError>;
13
- }
19
+ }
20
+ /**
21
+ * Seals list cursors with a key kept in `scope`: a row there, read through `records`, or made and
22
+ * added on the seal's first use, then kept. `scope` is where the key lives and whose cursors these
23
+ * are: a feature passes a scope it registered, so its key is its own and never Git's in
24
+ * `git/repos`. Each cursor is sealed for `scope` as well as its list's `bound`, so one sealed in
25
+ * another scope opens to `undefined`, as a forged or tampered one does, even under the same key.
26
+ */
27
+ export declare const make: (records: SealRecords, scope: Scope) => CursorSeal;
@@ -6,7 +6,7 @@ import * as Effect from "effect/Effect";
6
6
  import * as Schema from "effect/Schema";
7
7
  import * as Semaphore from "effect/Semaphore";
8
8
  // src/store/cursor-seal.ts
9
- /** The row in `git/repos` that holds the key every list cursor is sealed with. */
9
+ /** The row in a seal's scope that holds the key its cursors are sealed with: `git/repos`' for Git's lists. */
10
10
  const cursorKeyRow = {
11
11
  collection: collections.keys,
12
12
  id: "cursor"
@@ -21,42 +21,49 @@ const keyOf = /* @__PURE__ */ Effect.fnUntraced(function* (row) {
21
21
  if (bytes?.length !== 32) return yield* fail("DATA_LOSS", "The server's cursor key is unreadable");
22
22
  return bytes;
23
23
  });
24
- const readKey = /* @__PURE__ */ Effect.fnUntraced(function* (store) {
25
- const row = (yield* storeCall(() => store.read(catalogueScope, [{ ...cursorKeyRow }]))).results[0]?.[0];
24
+ const readKey = /* @__PURE__ */ Effect.fnUntraced(function* (records, scope) {
25
+ const row = (yield* records.read(scope, [{ ...cursorKeyRow }])).results[0]?.[0];
26
26
  return row === void 0 ? void 0 : yield* keyOf(row);
27
27
  });
28
28
  /**
29
- * The server's cursor key: the row's, or one it makes and adds. Two servers that make one at once
29
+ * The scope's cursor key: the row's, or one it makes and adds. Two servers that make one at once
30
30
  * both end with the key that was added first, since the second's add is refused and it reads again.
31
31
  */
32
- const loadKey = /* @__PURE__ */ Effect.fnUntraced(function* (store) {
33
- const held = yield* readKey(store);
32
+ const loadKey = /* @__PURE__ */ Effect.fnUntraced(function* (records, scope) {
33
+ const held = yield* readKey(records, scope);
34
34
  if (held !== void 0) return held;
35
35
  const made = randomText(32);
36
36
  const row = {
37
37
  ...cursorKeyRow,
38
38
  value: { key: made }
39
39
  };
40
- if (yield* storeCall(() => store.add("git/repos", { put: [row] })).pipe(Effect.as(true), Effect.catchIf((error) => error.code === "ALREADY_EXISTS", () => Effect.succeed(false)))) return yield* keyOf(row);
41
- const won = yield* readKey(store);
40
+ if (yield* records.add(scope, { put: [row] }).pipe(Effect.as(true), Effect.catchIf((error) => error.code === "ALREADY_EXISTS", () => Effect.succeed(false)))) return yield* keyOf(row);
41
+ const won = yield* readKey(records, scope);
42
42
  if (won === void 0) return yield* fail("UNAVAILABLE", "The server's cursor key went missing");
43
43
  return won;
44
44
  });
45
45
  const utf8 = (text) => new TextEncoder().encode(text);
46
46
  /** What a cursor is sealed for: its list and what names that list, which no other list matches. */
47
47
  const listBound = (list, ...parts) => JSON.stringify([list, ...parts]);
48
- /** One server's seal over `store`: it reads or makes the key on its first use, then keeps it. */
49
- const cursorSeal = (store) => {
48
+ /**
49
+ * Seals list cursors with a key kept in `scope`: a row there, read through `records`, or made and
50
+ * added on the seal's first use, then kept. `scope` is where the key lives and whose cursors these
51
+ * are: a feature passes a scope it registered, so its key is its own and never Git's in
52
+ * `git/repos`. Each cursor is sealed for `scope` as well as its list's `bound`, so one sealed in
53
+ * another scope opens to `undefined`, as a forged or tampered one does, even under the same key.
54
+ */
55
+ const make = (records, scope) => {
50
56
  let key;
51
57
  const turn = Semaphore.makeUnsafe(1).withPermits(1);
52
58
  const load = Effect.fnUntraced(function* () {
53
59
  if (key !== void 0) return key;
54
- const bytes = yield* loadKey(store);
60
+ const bytes = yield* loadKey(records, scope);
55
61
  const imported = yield* Effect.promise(() => crypto.subtle.importKey("raw", bytes, "AES-GCM", false, ["encrypt", "decrypt"]));
56
62
  key = imported;
57
63
  return imported;
58
64
  });
59
65
  const keyNow = () => key === void 0 ? turn(load()) : Effect.succeed(key);
66
+ const sealedFor = (bound) => utf8(JSON.stringify([scope, bound]));
60
67
  return {
61
68
  seal: Effect.fnUntraced(function* (bound, text) {
62
69
  const using = yield* keyNow();
@@ -64,7 +71,7 @@ const cursorSeal = (store) => {
64
71
  const params = {
65
72
  name: "AES-GCM",
66
73
  iv,
67
- additionalData: utf8(bound)
74
+ additionalData: sealedFor(bound)
68
75
  };
69
76
  const sealed = yield* Effect.promise(() => crypto.subtle.encrypt(params, using, utf8(text)));
70
77
  const bytes = new Uint8Array(nonceBytes + sealed.byteLength);
@@ -79,11 +86,16 @@ const cursorSeal = (store) => {
79
86
  const params = {
80
87
  name: "AES-GCM",
81
88
  iv: bytes.subarray(0, nonceBytes),
82
- additionalData: utf8(bound)
89
+ additionalData: sealedFor(bound)
83
90
  };
84
91
  const opened = yield* Effect.promise(() => crypto.subtle.decrypt(params, using, bytes.subarray(nonceBytes)).then((plain) => new Uint8Array(plain), () => void 0));
85
92
  return opened === void 0 ? void 0 : utf8Of(opened);
86
93
  })
87
94
  };
88
95
  };
89
- export { cursorSeal, listBound };
96
+ /** Git's own seal for its lists, its key in `git/repos`, over the server's store. */
97
+ const cursorSeal = (store) => make({
98
+ read: (scope, reads) => storeCall(() => store.read(scope, reads)),
99
+ add: (scope, addition) => storeCall(() => store.add(scope, addition))
100
+ }, catalogueScope);
101
+ export { cursorSeal, listBound, make };
@@ -14,6 +14,8 @@ import * as Data from "effect/Data";
14
14
  // src/store/errors.ts
15
15
  const savedHint = "Read it back before you try again";
16
16
  const savedContext = { reason: "may-have-saved" };
17
+ /** What a caller does with a write that landed past its `by`: it wrote nothing, so read again. */
18
+ const lateHint = "Try again";
17
19
  /**
18
20
  * `error`, met once a write of the call's own has landed: any `UNAVAILABLE` is `may-have-saved`,
19
21
  * since what another reason says about sending the same call again holds only for a call that
@@ -42,7 +44,9 @@ const afterWrites = (error) => {
42
44
  * infra's refusal kept as its cause, which `pastCallLimit` reads, and a hint any caller can follow:
43
45
  * a door fails with it as the defect `CallsSpent` instead, which an edge answers with this. A commit
44
46
  * that never got a reply, and the platform failing `after` the request's deciding commit, may have
45
- * saved the write, so a caller reads it back before it tries again (#1308).
47
+ * saved the write, so a caller reads it back before it tries again (#1308). A write that landed
48
+ * past its `by` is `UNAVAILABLE` too, having written nothing: the read it was held to is old, so a
49
+ * caller reads again (#2331).
46
50
  */
47
51
  const fromInfra = (cause, after = false) => {
48
52
  const failed = !isInfraError(cause) || Predicate.isTagged(cause, "Unavailable");
@@ -64,6 +68,10 @@ const fromInfra = (cause, after = false) => {
64
68
  hint: callLimitTry
65
69
  });
66
70
  if (cause.code === "INTERNAL") return gitError("INTERNAL", "The server can't reach its store", { cause });
71
+ if (cause.reason === "late") return gitError("UNAVAILABLE", cause.message, {
72
+ cause,
73
+ hint: lateHint
74
+ });
67
75
  return gitError(cause.code, cause.message, { cause });
68
76
  };
69
77
  /** The smaller fetch a client is told to try, when its fetch was too much for one response. */
@@ -37,6 +37,7 @@ export type CatalogueEntry = typeof CatalogueEntry.Type;
37
37
  * what it was made from. `refIndex` is the stamp of the patterns its `refIndex` rows were written
38
38
  * under, as `core/ref-index.ts` says: a repo made on a server that keeps an index takes its stamp.
39
39
  * `refIndexBuilding` is the rebuild mark, `git.ref-index`'s, while it builds another stamp's rows.
40
+ * `renamedSeq` is the `seq` of the `repo.renamed` that gave the repo its name, when events are kept.
40
41
  */
41
42
  export declare const StoredRepo: Schema.Struct<{
42
43
  readonly name: Schema.String;
@@ -56,6 +57,7 @@ export declare const StoredRepo: Schema.Struct<{
56
57
  readonly nextSeq: Schema.optionalKey<Schema.Int>;
57
58
  readonly receipt: Schema.optionalKey<Schema.String>;
58
59
  }>>;
60
+ readonly renamedSeq: Schema.optionalKey<Schema.Int>;
59
61
  readonly nextSeq: Schema.optionalKey<Schema.Int>;
60
62
  readonly refIndex: Schema.optionalKey<Schema.String>;
61
63
  readonly refIndexBuilding: Schema.optionalKey<Schema.Struct<{
@@ -58,6 +58,7 @@ const KeptRepoInfo = /* @__PURE__ */ Schema.Struct({
58
58
  defaultBranch: Schema.optionalKey(Schema.String),
59
59
  public: Schema.Boolean,
60
60
  upstream: Schema.optionalKey(Schema.String),
61
+ shallow: Schema.Boolean,
61
62
  stats: Schema.Struct({
62
63
  repo: Schema.String,
63
64
  refs: Schema.Int,
@@ -151,6 +152,7 @@ const ForkRow = /* @__PURE__ */ Schema.Struct({ internalId: InternalRepoId });
151
152
  * what it was made from. `refIndex` is the stamp of the patterns its `refIndex` rows were written
152
153
  * under, as `core/ref-index.ts` says: a repo made on a server that keeps an index takes its stamp.
153
154
  * `refIndexBuilding` is the rebuild mark, `git.ref-index`'s, while it builds another stamp's rows.
155
+ * `renamedSeq` is the `seq` of the `repo.renamed` that gave the repo its name, when events are kept.
154
156
  */
155
157
  const StoredRepo = /* @__PURE__ */ Schema.Struct({
156
158
  name: Schema.String,
@@ -162,22 +164,23 @@ const StoredRepo = /* @__PURE__ */ Schema.Struct({
162
164
  changedAt: Schema.Int,
163
165
  deleted: Schema.optionalKey(Schema.Literal(true)),
164
166
  renamedFrom: Schema.optionalKey(RenamedFrom),
167
+ renamedSeq: Schema.optionalKey(Schema.Int),
165
168
  nextSeq: Schema.optionalKey(NextSeq),
166
169
  refIndex: Schema.optionalKey(Schema.String),
167
170
  refIndexBuilding: Schema.optionalKey(RefIndexBuilding)
168
171
  });
169
172
  /**
170
- * The most roots a repo keeps in its `repo/roots` row, 10,000: an import's last segment's boundary
171
- * is what becomes the repo's roots when it lands, the row's only writer, so `receiveBoundaryMost`
172
- * is this bound too. At 43 B an ID as JSON, its quotes and comma with it, the row is at most 430 KB.
173
+ * The most roots a repo keeps in its `repo/roots` row, 10,000, as `rootsMoved`, the row's one
174
+ * writer, holds them for a client's fetch and an import alike: an import's last segment's boundary
175
+ * becomes the repo's roots when it lands, so `receiveBoundaryMost` is this bound too. At 43 B an ID as JSON, its quotes and comma with it, the row is at most 430 KB.
173
176
  */
174
177
  const repoRootsMost = 1e4;
175
178
  /** A root's ID as the row keeps it: 40 lowercase hex digits. */
176
179
  const RootId = Oid.check(Schema.isPattern(/^[0-9a-f]{40}$/));
177
180
  /**
178
181
  * A repo's roots, `repo/roots` in its scope: the commits it holds without their parents, as Git's
179
- * `shallow` file names them, at most `repoRootsMost`, which their only writer, an import's landing,
180
- * holds them to. Every walk sees a root as having no parents (`RepoRoots`). A row of any other ID,
182
+ * `shallow` file names them, at most `repoRootsMost`, which their one writer, `rootsMoved`, holds
183
+ * them to. Every walk sees a root as having no parents (`RepoRoots`). A row of any other ID,
181
184
  * or past the bound, doesn't decode, so its read is `DATA_LOSS`.
182
185
  */
183
186
  const RepoRootsRow = /* @__PURE__ */ Schema.Struct({ roots: Schema.Array(RootId).check(Schema.isMaxLength(repoRootsMost)) });
@@ -245,7 +248,7 @@ const ReachedMark = /* @__PURE__ */ Schema.Struct({
245
248
  });
246
249
  /** Whether a mark's row holds both halves: there, and no proof under way. */
247
250
  const markHolds = (mark) => mark !== void 0 && mark.pending === void 0;
248
- /** The job a push saves for each ref an active mirror names, keyed by the ref. */
251
+ /** The job a push saves for each destination an active mirror of a ref it moves names. */
249
252
  const mirrorJobName = "sync.mirror";
250
253
  /** The job a repo's import runs as: one a repo, in its scope. */
251
254
  const importJobName = "sync.import";
@@ -0,0 +1,27 @@
1
+ import "../contracts/promises.mjs";
2
+ import "../contracts/access.mjs";
3
+ import { EffectiveLimits } from "../contracts/objects.mjs";
4
+ import "../contracts/ids.mjs";
5
+ import "../contracts/repos.mjs";
6
+ import "../contracts/store.mjs";
7
+ import "../protocol/objects/commit.mjs";
8
+ import "../contracts/result.mjs";
9
+ import "./records.mjs";
10
+ import * as Effect from "effect/Effect";
11
+ import "effect/Schema";
12
+ import { Addition, Count, JobInput, Key, Moment, Read, Row, Scope, Snapshot } from "@ref0/infra";
13
+ import "effect/Context";
14
+ import "effect/Types";
15
+ /**
16
+ * When a write to a repo's scope must land by, after a read at `heldAt` found the repo's record
17
+ * live: `heldAt` plus `fetchLimits.milliseconds`, less `jobLeaseMargin`. The repo was live at that
18
+ * read, so its delete committed later, and its purge drops its scopes no sooner than `fetchLimits`
19
+ * past the delete's stamp, the record's `changedAt`, which the delete commits within
20
+ * `deleteCommitWithin` of (#1911). The write sends it as its `by`, which the store checks on its
21
+ * own clock as the write lands, so one that stalls in the store lands nothing past it, however
22
+ * long the stall (#2331). The margin covers the delete's commit and the store's clock, as
23
+ * `deleteCommitWithin` splits it, and `HeldWrite.tla` checks that no held write lands after the drop.
24
+ */
25
+ export declare const heldUntil: (heldAt: Moment, fetchLimits: EffectiveLimits) => Moment;
26
+ /** Whether a write may still send its store call, by `heldUntil`'s `by`, at the clock's now. */
27
+ export declare const inTime: (by: Moment) => Effect.Effect<boolean>;
@@ -1,11 +1,18 @@
1
+ import { Sha1 } from "../protocol/bytes/sha1.mjs";
1
2
  import { noRepoRoots } from "../protocol/objects/commit.mjs";
2
3
  import { checkChurn, decodeRecord, entryOf, project } from "./catalogue.mjs";
3
4
  import { afterCommit } from "./call-count.mjs";
5
+ import { fail } from "../contracts/result.mjs";
4
6
  import { afterWrites, decodeRow, storeCall } from "./errors.mjs";
5
7
  import { listJobRow } from "./list-job.mjs";
6
- import { LooseTally, RepoRootsRow, StatsTime } from "./records.mjs";
7
- import { looseKey, maintainedKey, newChangeId, pushedKey, repoScope, selfKey } from "./scopes.mjs";
8
+ import { LooseTally, RepoRootsRow, StatsTime, repoRootsMost } from "./records.mjs";
9
+ import { looseKey, maintainedKey, newChangeId, pushedKey, reachedKey, repoRootsKey, repoScope, selfKey } from "./scopes.mjs";
10
+ import * as Clock$1 from "effect/Clock";
8
11
  import * as Effect from "effect/Effect";
12
+ import * as Schema from "effect/Schema";
13
+ import { jobLeaseMargin } from "@ref0/infra";
14
+ import * as Context from "effect/Context";
15
+ import * as Hex from "effect/encoding/Hex";
9
16
  // src/store/repo-record.ts
10
17
  /** A repo's record and its scope's rows, read at one version: `results[0]` is `self`. */
11
18
  const readRecord = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, reads = [], counts = []) {
@@ -23,6 +30,132 @@ const rootsOf = (rows) => {
23
30
  return Effect.map(decodeRow(RepoRootsRow, row, "The repo's roots"), ({ roots }) => new Set(roots));
24
31
  };
25
32
  /**
33
+ * The write of a repo's roots once `moves` lands on `held`, the roots its commit reads: those of
34
+ * `shallow` added, and those of `unshallow` taken away, each once, in order. `undefined` when they
35
+ * don't change. It is the roots' one writer (#2202, and #2198's import), and it does three things
36
+ * on a change: its row, or the row's delete once none is left; the reached mark's delete, so a
37
+ * whole clone never streams past a root that moved; and `indexed`, the repo's `git.index` rows,
38
+ * which queue a build over the new roots: an index keeps `rootsDigest` of the roots it's over, so
39
+ * one over others answers no read and is built again whole (#2462). Prune keys its saved work on
40
+ * them too: its walks keep `rootsKeyOf` of the roots they walked under, and its classes' reads
41
+ * digest takes them, so a pass whose roots moved walks and reads again under the new ones (#2485).
42
+ * Past `repoRootsMost` it's refused, so a fetch lands nothing. An answer that moves the roots
43
+ * lands only on the roots it was made against, `sent`: once another fetch moved them, its lines
44
+ * no longer say where the history stops, and it's refused `changed-while-checked`, landing
45
+ * nothing, for the fetch to ask again.
46
+ */
47
+ const rootsMoved = (held, moves, indexed) => {
48
+ const moving = moves.shallow.length > 0 || moves.unshallow.length > 0;
49
+ const asked = new Set(moves.sent);
50
+ const moved = asked.size !== held.size || [...asked].some((oid) => !held.has(oid));
51
+ if (moving && moved) return fail("FAILED_PRECONDITION", "The repo's roots moved since this fetch sent them", {
52
+ hint: "Fetch again",
53
+ context: { reason: "changed-while-checked" }
54
+ });
55
+ const after = new Set(held);
56
+ for (const oid of moves.shallow) after.add(oid);
57
+ for (const oid of moves.unshallow) after.delete(oid);
58
+ if (after.size === held.size && [...after].every((oid) => held.has(oid))) return Effect.succeed(void 0);
59
+ if (after.size > 1e4) return fail("RESOURCE_EXHAUSTED", `A repo holds at most ${repoRootsMost} shallow commits`, {
60
+ hint: "Fetch with a smaller depth, or from fewer branches",
61
+ context: {
62
+ reason: "too-large",
63
+ most: repoRootsMost
64
+ }
65
+ });
66
+ const roots = [...after].sort();
67
+ const value = { roots };
68
+ const put = roots.length === 0 ? [] : [{
69
+ ...repoRootsKey,
70
+ value
71
+ }];
72
+ const gone = roots.length === 0 ? [repoRootsKey] : [];
73
+ return Effect.succeed({
74
+ roots,
75
+ put,
76
+ delete: [...gone, reachedKey],
77
+ jobs: indexed
78
+ });
79
+ };
80
+ /**
81
+ * The repo's roots as one digest: their IDs sorted, each once, hashed. What was built over the
82
+ * roots, such as the ready shallow pack, keeps it, so a change of roots is seen as one.
83
+ */
84
+ const rootsDigest = (roots) => {
85
+ const sha = new Sha1();
86
+ sha.update(new TextEncoder().encode([...new Set(roots)].sort().join("\n")));
87
+ return Hex.encode(sha.digest());
88
+ };
89
+ /**
90
+ * How long a repo's delete may commit after the time it stamps, from which its purge's guard
91
+ * counts: half of `jobLeaseMargin`. The delete's commit sends it past that time as its `by`, and
92
+ * the margin's other half covers how far the store's clock may run from Git's, which a held write
93
+ * meets twice, at the delete's commit and at its own: a quarter of the margin each way (#2331).
94
+ */
95
+ const deleteCommitWithin = jobLeaseMargin / 2;
96
+ /**
97
+ * When a write to a repo's scope must land by, after a read at `heldAt` found the repo's record
98
+ * live: `heldAt` plus `fetchLimits.milliseconds`, less `jobLeaseMargin`. The repo was live at that
99
+ * read, so its delete committed later, and its purge drops its scopes no sooner than `fetchLimits`
100
+ * past the delete's stamp, the record's `changedAt`, which the delete commits within
101
+ * `deleteCommitWithin` of (#1911). The write sends it as its `by`, which the store checks on its
102
+ * own clock as the write lands, so one that stalls in the store lands nothing past it, however
103
+ * long the stall (#2331). The margin covers the delete's commit and the store's clock, as
104
+ * `deleteCommitWithin` splits it, and `HeldWrite.tla` checks that no held write lands after the drop.
105
+ */
106
+ const heldUntil = (heldAt, fetchLimits) => heldAt + fetchLimits.milliseconds - jobLeaseMargin;
107
+ /** Whether a write may still send its store call, by `heldUntil`'s `by`, at the clock's now. */
108
+ const inTime = (by) => Effect.map(Clock$1.currentTimeMillis, (now) => now < by);
109
+ /**
110
+ * When the writes in scope must land by, as `heldUntil` answered for the caller's own read of the
111
+ * repo's record: a push sets it around its receive, so the pack's quarantine row, an add at no
112
+ * version, is refused once the push waited past it, at its authorize or its memory's admission,
113
+ * or in the store, as long as the repo's purge may take (#1911, #2331). `undefined` outside one,
114
+ * as for `git.repack`'s own packs, which the purge waits for.
115
+ */
116
+ const HeldBy = Context.Reference("@ref0/git/HeldBy", { defaultValue: () => void 0 });
117
+ /**
118
+ * `addition` with `HeldBy` as its `by`, so the store refuses it as it lands past it: fails
119
+ * `UNAVAILABLE` already once the clock is at or past it, so a write that waited reads again.
120
+ */
121
+ const heldAddition = (what, addition) => Effect.flatMap(HeldBy, (by) => by === void 0 ? Effect.succeed(addition) : Effect.flatMap(inTime(by), (on) => on ? Effect.succeed({
122
+ ...addition,
123
+ by
124
+ }) : fail("UNAVAILABLE", `${what} came late: read the repo again`, { hint: "Push again" })));
125
+ /**
126
+ * A write to a repo's scope refused because the repo is gone: no record, or one deleted, so its
127
+ * purge may drop the scope, or has, and the write would make it again (#1911).
128
+ */
129
+ var RepoGone = class extends Schema.TaggedError()("RepoGone", { repo: Schema.String }) {};
130
+ /** `store` as `heldAdd` calls it, each call a `storeCall`. */
131
+ const heldStore = (store) => ({
132
+ read: (scope, reads) => storeCall(() => store.read(scope, reads)),
133
+ add: (scope, addition) => storeCall(() => store.add(scope, addition))
134
+ });
135
+ /**
136
+ * `addition` to `repo`'s scope, an add at no version, only while the repo is live: it reads the
137
+ * record first and fails `RepoGone` when there's none or it's deleted, so a late write, a wake or
138
+ * a job after the delete never makes a purged scope again, nor on Turso its database. One whose
139
+ * read stalled past `heldUntil` is `UNAVAILABLE`, for a try that reads again, and so is one whose
140
+ * add the store found past it as it landed, `heldUntil` being the add's `by`. A wake, a job, an
141
+ * upload or a sync's cover made apart from the repo's own read goes through here, and a push's
142
+ * quarantine is held to its first read by `HeldBy`. The adds that don't are a fork create's cover
143
+ * rows, which come with its record, and a try's rows in its own scope, which its claim fences.
144
+ */
145
+ const heldAdd = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, fetchLimits, addition) {
146
+ const scope = repoScope(repo);
147
+ const heldAt = yield* Clock$1.currentTimeMillis;
148
+ const snapshot = yield* store.read(scope, [selfKey]);
149
+ const record = yield* decodeRecord(snapshot.results[0]?.[0]);
150
+ if (record === void 0 || record.deleted === true) return yield* new RepoGone({ repo });
151
+ const by = heldUntil(heldAt, fetchLimits);
152
+ if (!(yield* inTime(by))) return yield* fail("UNAVAILABLE", `The add to repo ${repo} came late: read it again`);
153
+ yield* store.add(scope, {
154
+ ...addition,
155
+ by
156
+ });
157
+ });
158
+ /**
26
159
  * The first of a repo write's two commits: its record, in its own scope, with `git.list` saved
27
160
  * beside it, so the catalogue's projection happens even if the second never does.
28
161
  */
@@ -37,7 +170,11 @@ const commitRecord = (store, internalId, write) => {
37
170
  delete: [...write.delete ?? []],
38
171
  jobs: [listJobRow(), ...write.jobs ?? []]
39
172
  };
40
- return storeCall(() => store.commit(repoScope(internalId), change));
173
+ const sent = write.by === void 0 ? change : {
174
+ ...change,
175
+ by: write.by
176
+ };
177
+ return storeCall(() => store.commit(repoScope(internalId), sent));
41
178
  };
42
179
  /**
43
180
  * A repo write's two commits: its record, then its projection into `git/repos`. Answers
@@ -123,4 +260,4 @@ const repoStats = (record, refs, packs, times, readyBytes) => {
123
260
  if (times.maintained !== void 0) stats.maintainedAt = times.maintained;
124
261
  return stats;
125
262
  };
126
- export { commitRecord, decodeStats, looseRows, readRecord, repoStats, rootsOf, seenTimes, timeRow, writeRecord };
263
+ export { HeldBy, RepoGone, commitRecord, decodeStats, deleteCommitWithin, heldAdd, heldAddition, heldStore, heldUntil, inTime, looseRows, readRecord, repoStats, rootsDigest, rootsMoved, rootsOf, seenTimes, timeRow, writeRecord };
@@ -80,6 +80,13 @@ const collections = {
80
80
  * pushed or upkeep ends it.
81
81
  */
82
82
  pushUploads: "push-uploads",
83
+ /**
84
+ * In a repo's scope: each receiving push upload's steps, by its handle: who completed it, as
85
+ * `SavedCaller` keeps them, and once its first try staged it, its pack's ID.
86
+ */
87
+ pushUploadSteps: "push-upload-steps",
88
+ /** In a repo's scope: each ended push upload's answer, by its handle, for its report. */
89
+ pushUploadAnswers: "push-upload-answers",
83
90
  /** In a topic's scope: its own row, `self`, with its state. */
84
91
  topic: "topic",
85
92
  /** In `git/topics`: each key's topic, claimed by the first `topics.add` that names the key. */
@@ -123,8 +130,9 @@ const selfKey = {
123
130
  id: "self"
124
131
  };
125
132
  /**
126
- * A repo's roots, its `RepoRootsRow`, read with every open whose reads walk parents. Only an
127
- * import's landing writes it, before its first ref page publishes; a repo with no row has none.
133
+ * A repo's roots, its `RepoRootsRow`, read with every open whose reads walk parents. Only
134
+ * `rootsMoved` writes it, for a client's fetch or an import, in the commit that lands what the
135
+ * answer sent; a repo with no row has none.
128
136
  */
129
137
  const repoRootsKey = {
130
138
  collection: collections.repo,
@@ -2,6 +2,8 @@ import "../contracts/authorize.mjs";
2
2
  import "../contracts/actors.mjs";
3
3
  import "../contracts/sync.mjs";
4
4
  import "../core/parts.mjs";
5
+ import "../lfs/copy.mjs";
6
+ import "effect/Effect";
5
7
  import "effect/http/HttpClient";
6
8
  import { Job } from "@ref0/infra";
7
9
  import "effect/Context";