@ref0/git 0.7.0 → 0.9.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 (245) hide show
  1. package/dist/access/private-refs.mjs +0 -2
  2. package/dist/auth/authorize.mjs +31 -24
  3. package/dist/auth/bridge.mjs +8 -8
  4. package/dist/auth/fences.d.mts +0 -1
  5. package/dist/auth/fences.mjs +1 -1
  6. package/dist/auth/grants.d.mts +0 -1
  7. package/dist/auth/grants.mjs +2 -2
  8. package/dist/auth/host-function.d.mts +1 -7
  9. package/dist/auth/host-function.mjs +38 -38
  10. package/dist/auth/identify.d.mts +0 -1
  11. package/dist/auth/identify.mjs +1 -1
  12. package/dist/auth/policy.d.mts +7 -4
  13. package/dist/auth/policy.mjs +13 -10
  14. package/dist/auth/token-rows.mjs +2 -5
  15. package/dist/auth/tokens-layer.d.mts +0 -2
  16. package/dist/auth/tokens-public.d.mts +3 -3
  17. package/dist/auth/tokens-public.mjs +4 -2
  18. package/dist/auth/tokens.d.mts +6 -1
  19. package/dist/auth/tokens.mjs +7 -1
  20. package/dist/client/client.d.mts +22 -15
  21. package/dist/client/client.mjs +31 -27
  22. package/dist/client/git-http.mjs +22 -5
  23. package/dist/client/local.mjs +1 -1
  24. package/dist/client/namespace.d.mts +2 -0
  25. package/dist/client/push-upload.d.mts +1 -0
  26. package/dist/client/push-upload.mjs +169 -2
  27. package/dist/client/remote-helper.mjs +2 -4
  28. package/dist/client/remote.mjs +37 -15
  29. package/dist/client/run-remote-helper.mjs +4 -4
  30. package/dist/client/transport.mjs +26 -19
  31. package/dist/contracts/actors.d.mts +57 -28
  32. package/dist/contracts/actors.mjs +38 -2
  33. package/dist/contracts/authorize.d.mts +21 -15
  34. package/dist/contracts/callers.mjs +40 -0
  35. package/dist/contracts/calls-spent.d.mts +2 -12
  36. package/dist/contracts/calls-spent.mjs +4 -5
  37. package/dist/contracts/client.d.mts +16 -9
  38. package/dist/contracts/events.d.mts +82 -14
  39. package/dist/contracts/events.mjs +35 -9
  40. package/dist/contracts/files.d.mts +42 -42
  41. package/dist/contracts/forks.d.mts +0 -24
  42. package/dist/contracts/git-hooks.d.mts +217 -0
  43. package/dist/contracts/git-hooks.mjs +3 -1
  44. package/dist/contracts/git.d.mts +13 -3
  45. package/dist/contracts/grants.d.mts +46 -27
  46. package/dist/contracts/lfs.d.mts +17 -4
  47. package/dist/contracts/merges.d.mts +7 -7
  48. package/dist/contracts/objects.d.mts +38 -4
  49. package/dist/contracts/opaque.mjs +19 -1
  50. package/dist/contracts/operations.d.mts +8 -1
  51. package/dist/contracts/operations.mjs +209 -0
  52. package/dist/contracts/queue.d.mts +6 -5
  53. package/dist/contracts/queue.mjs +9 -20
  54. package/dist/contracts/remote.d.mts +13 -4
  55. package/dist/contracts/remote.mjs +3 -3
  56. package/dist/contracts/repos.d.mts +11 -40
  57. package/dist/contracts/repos.mjs +11 -10
  58. package/dist/contracts/result.d.mts +28 -11
  59. package/dist/contracts/result.mjs +32 -2
  60. package/dist/contracts/rules.d.mts +706 -46
  61. package/dist/contracts/rules.mjs +81 -2
  62. package/dist/contracts/server.d.mts +5 -275
  63. package/dist/contracts/services.d.mts +0 -3
  64. package/dist/contracts/services.mjs +1 -3
  65. package/dist/contracts/signin.d.mts +2 -2
  66. package/dist/contracts/signin.mjs +4 -5
  67. package/dist/contracts/sync.d.mts +1 -4
  68. package/dist/contracts/tokens.d.mts +29 -17
  69. package/dist/contracts/tokens.mjs +14 -3
  70. package/dist/contracts/topics.d.mts +38 -11
  71. package/dist/contracts/topics.mjs +8 -2
  72. package/dist/core/access.d.mts +0 -2
  73. package/dist/core/access.mjs +15 -4
  74. package/dist/core/ancestry.mjs +5 -4
  75. package/dist/core/events/deliver.mjs +19 -1
  76. package/dist/core/forks.mjs +30 -11
  77. package/dist/core/hooks/groups.d.mts +0 -1
  78. package/dist/core/hooks/groups.mjs +8 -9
  79. package/dist/core/index-job.mjs +23 -1
  80. package/dist/core/index-lost.d.mts +11 -0
  81. package/dist/core/index-lost.mjs +55 -0
  82. package/dist/core/loose-tally.mjs +46 -0
  83. package/dist/core/objects/commit-writes.mjs +1 -1
  84. package/dist/core/objects/commits.mjs +10 -9
  85. package/dist/core/objects/merges.mjs +1 -1
  86. package/dist/core/objects/reading.mjs +28 -13
  87. package/dist/core/objects/trees.mjs +1 -1
  88. package/dist/core/objects/writing.mjs +1 -0
  89. package/dist/core/parts.d.mts +7 -0
  90. package/dist/core/promise.mjs +1 -15
  91. package/dist/core/publish.mjs +9 -5
  92. package/dist/core/purge.mjs +30 -12
  93. package/dist/core/push.mjs +39 -16
  94. package/dist/core/ref-view.mjs +14 -6
  95. package/dist/core/repack.mjs +54 -27
  96. package/dist/core/repo-info.mjs +8 -6
  97. package/dist/core/repos.mjs +1 -0
  98. package/dist/core/rules/check.mjs +10 -10
  99. package/dist/core/rules/context.d.mts +3 -1
  100. package/dist/core/rules/context.mjs +16 -13
  101. package/dist/core/rules/fetch.mjs +17 -23
  102. package/dist/core/tokens.mjs +2 -1
  103. package/dist/core/view.d.mts +10 -1
  104. package/dist/core/view.mjs +15 -6
  105. package/dist/effect.d.mts +3 -6
  106. package/dist/effect.mjs +3 -6
  107. package/dist/engine/commits.mjs +23 -50
  108. package/dist/engine/failures.d.mts +1 -2
  109. package/dist/engine/failures.mjs +1 -3
  110. package/dist/engine/merge-base-walk.mjs +57 -142
  111. package/dist/engine/merge-bases.mjs +9 -7
  112. package/dist/engine/merge.mjs +20 -17
  113. package/dist/engine/parts.d.mts +1 -0
  114. package/dist/engine/parts.mjs +1 -1
  115. package/dist/engine/walk.mjs +15 -11
  116. package/dist/extend.d.mts +1 -2
  117. package/dist/extend.mjs +1 -2
  118. package/dist/http/core-parts.mjs +18 -10
  119. package/dist/http/handler.mjs +11 -31
  120. package/dist/http/parts.d.mts +0 -1
  121. package/dist/index.d.mts +29 -22
  122. package/dist/index.mjs +5 -2
  123. package/dist/lfs/base.d.mts +6 -3
  124. package/dist/lfs/base.mjs +2 -1
  125. package/dist/lfs/layer.d.mts +4 -3
  126. package/dist/lfs/layer.mjs +23 -9
  127. package/dist/lfs/objects.mjs +93 -41
  128. package/dist/lfs/pointers.mjs +69 -18
  129. package/dist/lfs/purge.mjs +6 -2
  130. package/dist/lfs/rows.mjs +24 -7
  131. package/dist/lfs/service.d.mts +6 -3
  132. package/dist/lfs/service.mjs +8 -2
  133. package/dist/lfs/upkeep.mjs +47 -28
  134. package/dist/lfs/upload-most.mjs +47 -0
  135. package/dist/lfs/uploaded.mjs +59 -0
  136. package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
  137. package/dist/protocol/bytes/streams.mjs +84 -2
  138. package/dist/protocol/bytes/text.mjs +6 -1
  139. package/dist/protocol/diff/read.d.mts +1 -0
  140. package/dist/protocol/diff/read.mjs +5 -2
  141. package/dist/protocol/objects/commit.d.mts +7 -0
  142. package/dist/protocol/objects/commit.mjs +5 -1
  143. package/dist/protocol/objects/fsck.mjs +6 -3
  144. package/dist/queue/advance.mjs +77 -18
  145. package/dist/queue/calls.mjs +4 -14
  146. package/dist/queue/host.d.mts +4 -0
  147. package/dist/queue/lanes.mjs +1 -1
  148. package/dist/queue/layer.mjs +4 -2
  149. package/dist/queue/limits.mjs +18 -2
  150. package/dist/queue/rows.mjs +10 -1
  151. package/dist/queue/schedule.mjs +1 -1
  152. package/dist/queue/search.mjs +3 -4
  153. package/dist/queue/trim.mjs +2 -2
  154. package/dist/rest/client-namespace.d.mts +2 -0
  155. package/dist/rest/client.d.mts +32 -8
  156. package/dist/rest/client.mjs +308 -382
  157. package/dist/rest/commits.d.mts +150 -150
  158. package/dist/rest/files.d.mts +18 -18
  159. package/dist/rest/forks.d.mts +77 -89
  160. package/dist/rest/handlers.mjs +2 -1
  161. package/dist/rest/listen.d.mts +8 -6
  162. package/dist/rest/listen.mjs +31 -75
  163. package/dist/rest/me.d.mts +2 -2
  164. package/dist/rest/merges.d.mts +7 -7
  165. package/dist/rest/refs.d.mts +27 -27
  166. package/dist/rest/repos.d.mts +40 -52
  167. package/dist/rest/tokens.d.mts +12 -12
  168. package/dist/rest/topics.d.mts +13 -13
  169. package/dist/rest/trees.d.mts +66 -66
  170. package/dist/rest/wire.d.mts +20 -2
  171. package/dist/rest/work.d.mts +39 -39
  172. package/dist/rest.d.mts +1 -7
  173. package/dist/rest.mjs +1 -5
  174. package/dist/server/git-layer.d.mts +10 -2
  175. package/dist/server/git-layer.mjs +29 -10
  176. package/dist/server/joined.d.mts +12 -6
  177. package/dist/server/joined.mjs +3 -2
  178. package/dist/server/registry.mjs +11 -5
  179. package/dist/server/server.d.mts +0 -1
  180. package/dist/server/server.mjs +42 -49
  181. package/dist/signin/context.d.mts +0 -1
  182. package/dist/signin/context.mjs +5 -9
  183. package/dist/storage/clean-up.mjs +3 -1
  184. package/dist/storage/fsck.mjs +12 -2
  185. package/dist/storage/graph-rebuild.mjs +262 -0
  186. package/dist/storage/index-bitmaps.mjs +16 -10
  187. package/dist/storage/index-build.mjs +160 -24
  188. package/dist/storage/index-graph.d.mts +1 -0
  189. package/dist/storage/index-graph.mjs +29 -5
  190. package/dist/storage/index-layers.d.mts +1 -0
  191. package/dist/storage/index-layers.mjs +5 -2
  192. package/dist/storage/index-reach.mjs +7 -5
  193. package/dist/storage/index-remap.mjs +5 -5
  194. package/dist/storage/index-visible.mjs +16 -5
  195. package/dist/storage/lfs-pointers.d.mts +5 -5
  196. package/dist/storage/lfs-pointers.mjs +37 -11
  197. package/dist/storage/links.mjs +3 -3
  198. package/dist/storage/loose.mjs +4 -1
  199. package/dist/storage/memory-budget.mjs +1 -1
  200. package/dist/storage/merge-fence.mjs +81 -19
  201. package/dist/storage/merge-most.mjs +1 -0
  202. package/dist/storage/merge-row.mjs +16 -4
  203. package/dist/storage/merge-stream.mjs +9 -6
  204. package/dist/storage/object-rows.mjs +17 -1
  205. package/dist/storage/pack-order.d.mts +1 -0
  206. package/dist/storage/pack-order.mjs +18 -1
  207. package/dist/storage/pack-receive.mjs +10 -6
  208. package/dist/storage/packs.mjs +58 -27
  209. package/dist/storage/prune-walk.mjs +5 -2
  210. package/dist/storage/prune.mjs +168 -70
  211. package/dist/storage/ready.d.mts +1 -1
  212. package/dist/storage/ready.mjs +12 -3
  213. package/dist/storage/receive-bounds.mjs +3 -2
  214. package/dist/storage/receive-state.mjs +1 -1
  215. package/dist/storage/repack-contained.mjs +22 -14
  216. package/dist/storage/repack.d.mts +1 -1
  217. package/dist/storage/repack.mjs +3 -2
  218. package/dist/storage/unpack.mjs +7 -0
  219. package/dist/storage/visible.mjs +3 -2
  220. package/dist/storage/walk.d.mts +1 -0
  221. package/dist/storage/walk.mjs +9 -5
  222. package/dist/storage/wants.mjs +17 -11
  223. package/dist/store/call-count.d.mts +31 -3
  224. package/dist/store/call-count.mjs +51 -20
  225. package/dist/store/errors.d.mts +7 -1
  226. package/dist/store/errors.mjs +7 -1
  227. package/dist/store/job-try.mjs +3 -1
  228. package/dist/store/records.mjs +26 -5
  229. package/dist/store/repo-record.mjs +36 -12
  230. package/dist/store/scopes.mjs +15 -2
  231. package/dist/sync/bound.d.mts +1 -1
  232. package/dist/sync/import.mjs +15 -3
  233. package/dist/sync/layer.d.mts +5 -1
  234. package/dist/sync/layer.mjs +11 -9
  235. package/dist/sync/mirror.mjs +1 -1
  236. package/dist/sync/step.mjs +15 -15
  237. package/dist/topics/advance.mjs +11 -10
  238. package/dist/topics/layer.mjs +1 -1
  239. package/dist/topics/members.mjs +38 -9
  240. package/package.json +3 -3
  241. package/dist/engine/merge-base-walk.d.mts +0 -3
  242. package/dist/server/routes.d.mts +0 -32
  243. package/dist/server/routes.mjs +0 -69
  244. package/dist/sync/bridge.d.mts +0 -6
  245. package/dist/sync/bridge.mjs +0 -29
@@ -7,12 +7,23 @@ import * as Schema from "effect/Schema";
7
7
  import * as Context from "effect/Context";
8
8
  // src/contracts/tokens.ts
9
9
  const TokenId = Schema.String;
10
- /** Each scope a token can have, a ceiling `authorize` can narrow: `read`, then `report`, then `write`. */
11
- const tokenScopes = [
10
+ /**
11
+ * The scopes a grant may hold, a sign-in's or an extension's, and what Git's ceiling on a repo
12
+ * answers: `read`, then `report`, then `write`.
13
+ */
14
+ const grantScopes = [
12
15
  "read",
13
16
  "report",
14
17
  "write"
15
18
  ];
19
+ const GrantScope = /* @__PURE__ */ Schema.Literals(grantScopes);
20
+ /**
21
+ * Each scope a token can have, a ceiling `authorize` can narrow: the grant scopes, then `admin`.
22
+ * An `admin` token reaches every operation kind, as a host's own sign-in does, and covers only
23
+ * the whole host, `{ prefix: '' }`. Its ceiling never opens past the host's `Policy`: a policy
24
+ * that doesn't accept `admin` refuses it, as `Policy.signedIn` does.
25
+ */
26
+ const tokenScopes = [...grantScopes, "admin"];
16
27
  const TokenScope = /* @__PURE__ */ Schema.Literals(tokenScopes);
17
28
  const repoCoverage = {
18
29
  repo: RepoName,
@@ -103,4 +114,4 @@ const list = (target, input) => Effect.flatMap(Effect.service(Tokens), (tokens)
103
114
  const get = (token, input) => Effect.flatMap(Effect.service(Tokens), (tokens) => tokens.get(token, input));
104
115
  const revoke = (token, input) => Effect.flatMap(Effect.service(Tokens), (tokens) => tokens.revoke(token, input));
105
116
  const revokeKey = (target, key, input) => Effect.flatMap(Effect.service(Tokens), (tokens) => tokens.revokeKey(target, key, input));
106
- export { CreatedToken, PrefixTarget, TokenCoverage, TokenCreate, TokenFields, TokenId, TokenInfo, TokenKey, TokenList, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, create, get, list, revoke, revokeKey, tokenScopes, tokenStates };
117
+ export { CreatedToken, GrantScope, PrefixTarget, TokenCoverage, TokenCreate, TokenFields, TokenId, TokenInfo, TokenKey, TokenList, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, create, get, grantScopes, list, revoke, revokeKey, tokenScopes, tokenStates };
@@ -187,22 +187,47 @@ export interface TopicCalls {
187
187
  report(topic: TopicId, input: TopicReportInput): Promise<ReportResult>;
188
188
  }
189
189
  /** What the topic report and `prepare` are asked about. */
190
- export interface TopicReportQuestion {
191
- readonly topic: TopicId;
192
- readonly entries: readonly TopicEntry[];
193
- }
194
- export interface PrepareInput extends TopicReportQuestion {
195
- readonly candidates: readonly TopicCandidate[];
190
+ export declare const TopicReportQuestion: Schema.Struct<{
191
+ readonly topic: Schema.String;
192
+ readonly entries: Schema.$Array<Schema.Struct<{
193
+ readonly repo: Schema.String;
194
+ readonly target: Schema.String;
195
+ readonly entry: Schema.String;
196
+ readonly key: Schema.String;
197
+ readonly source: Schema.String;
198
+ readonly head: Schema.String;
199
+ }>>;
200
+ }>;
201
+ export type TopicReportQuestion = typeof TopicReportQuestion.Type;
202
+ export declare const PrepareInput: Schema.Struct<{
203
+ readonly topic: Schema.String;
204
+ readonly entries: Schema.$Array<Schema.Struct<{
205
+ readonly repo: Schema.String;
206
+ readonly target: Schema.String;
207
+ readonly entry: Schema.String;
208
+ readonly key: Schema.String;
209
+ readonly source: Schema.String;
210
+ readonly head: Schema.String;
211
+ }>>;
212
+ readonly candidates: Schema.$Array<Schema.Struct<{
213
+ readonly repo: Schema.String;
214
+ readonly target: Schema.String;
215
+ readonly candidate: Schema.String;
216
+ readonly ref: Schema.String;
217
+ readonly commit: Schema.String;
218
+ }>>;
196
219
  /** The set key of these exact candidates: the same for the same set, whatever the call's try. */
197
- readonly key: string;
220
+ readonly key: Schema.String;
198
221
  /** This call's try, from 1: a try the server died in runs again. Not a topic's attempt (Q624). */
199
- readonly attempt: number;
200
- }
222
+ readonly attempt: Schema.Number;
223
+ }>;
224
+ export type PrepareInput = typeof PrepareInput.Type;
201
225
  /**
202
226
  * Called once a set has passed, while every target is reserved, before the publish decision: it
203
227
  * must be repeatable and reversible, since `topics.remove` may let go of the targets while it runs,
204
228
  * and its answer then counts for nothing. An accept lets the topic decide; a reject fails it
205
- * `prepare-rejected`, and a throw or a timeout `host-error`, both final (Q648).
229
+ * `prepare-rejected`, and a throw, a timeout or an answer that is neither `accept()` nor
230
+ * `reject()` `host-error`, all final (Q648).
206
231
  * A typed `GitError` failure also ends as `host-error`; a timeout interrupts the Effect.
207
232
  *
208
233
  * The call is never made again once it answered, a throw or a timeout included: only a call the
@@ -237,7 +262,9 @@ export interface TopicsLayerOptions {
237
262
  * How long a topic that holds no target yet waits for its first, from when it first waits: 1
238
263
  * millisecond to 365 days, and no longer than `timeout`. By default it's the shorter of 2 hours
239
264
  * and `timeout`, so with a `timeout` of 30 minutes a topic waits 30 minutes at most. Past it,
240
- * the topic fails `timeout`, naming what it waited for.
265
+ * the topic fails `timeout`, naming what it waited for. Halfway, a member freezes the target it
266
+ * waits on: its queue opens nothing new in another lane or at a higher priority, so the target
267
+ * drains of what's open.
241
268
  */
242
269
  readonly waitTimeout?: Duration;
243
270
  }
@@ -1,4 +1,4 @@
1
- import { Oid, RefName, RepoName } from "./ids.mjs";
1
+ import { Oid, RefName, RepoName, TopicId } from "./ids.mjs";
2
2
  import { Judged } from "./queue.mjs";
3
3
  import * as Schema from "effect/Schema";
4
4
  // src/contracts/topics.ts
@@ -109,4 +109,10 @@ const Topic = /* @__PURE__ */ Schema.Struct({
109
109
  failure: Schema.optionalKey(TopicFailure),
110
110
  waitingOn: Schema.optionalKey(TopicWait)
111
111
  });
112
- export { Topic, TopicCandidate, TopicEntry, TopicEntryInput, TopicFailure, TopicFailureReason, TopicMergedEntry, TopicState, TopicTarget, TopicWait };
112
+ /** What the topic report and `prepare` are asked about. */
113
+ const TopicReportQuestion = /* @__PURE__ */ Schema.Struct({
114
+ topic: TopicId,
115
+ entries: Schema.Array(TopicEntry)
116
+ });
117
+ ({ ...TopicReportQuestion.fields }), Schema.Array(TopicCandidate), Schema.String, Schema.Number;
118
+ export { Topic, TopicCandidate, TopicEntry, TopicEntryInput, TopicFailure, TopicFailureReason, TopicMergedEntry, TopicReportQuestion, TopicState, TopicTarget, TopicWait };
@@ -6,7 +6,6 @@ import "../contracts/operations.mjs";
6
6
  import "../contracts/result.mjs";
7
7
  import { PushRule } from "../contracts/rules.mjs";
8
8
  import "../contracts/authorize.mjs";
9
- import { HostReports } from "../auth/host-function.mjs";
10
9
  import { HookGroup } from "./hooks/groups.mjs";
11
10
  import { Ordered } from "./hooks/order.mjs";
12
11
  import { RegisteredCheck } from "./rules/context.mjs";
@@ -21,7 +20,6 @@ import { JobInput, Moment, Read } from "@ref0/infra";
21
20
  * `Rules`, and the host's hook groups, where their refusals and failures are told.
22
21
  */
23
22
  export interface PushChecks {
24
- readonly reports: HostReports;
25
23
  readonly added?: () => readonly PushRule[];
26
24
  /**
27
25
  * The checks after the host's rules, by band then registration name: each registration's push check, and LFS's
@@ -4,6 +4,7 @@ import { entryOf, nameOf, namedRecordOf, redirectOf, resolveRepo } from "../stor
4
4
  import { afterWrites, isLimitRefusal } from "../store/errors.mjs";
5
5
  import { readRecord } from "../store/repo-record.mjs";
6
6
  import { collections } from "../store/scopes.mjs";
7
+ import { readyKey } from "../storage/ready.mjs";
7
8
  import { liveReceipt, matchedReceipt, receiptReads } from "./receipts.mjs";
8
9
  import { rebuildDue } from "./ref-index.mjs";
9
10
  import { CoreParts } from "./parts.mjs";
@@ -39,11 +40,15 @@ const indexDeleteJobs = (core) => core.indexJobRow === void 0 ? [] : [core.index
39
40
  const purgeJobs = (core, at) => core.purgeJobRow === void 0 ? [] : [core.purgeJobRow(at)];
40
41
  /** The `git.ref-index` row a commit over `record` saves: one while its stamp is stale. */
41
42
  const refIndexJobs = (core, record) => core.refIndexJobRow !== void 0 && rebuildDue(core.refIndex, record) ? [core.refIndexJobRow()] : [];
42
- /** The reads `RepoInfo`'s stats are counted from, after a repo's `self`. */
43
+ /**
44
+ * The reads `RepoInfo`'s stats are counted from, after a repo's `self`: its refs, its packs, its
45
+ * `stats` times and its ready shallow pack's row.
46
+ */
43
47
  const statsReads = [
44
48
  { collection: collections.refs },
45
49
  { collection: collections.packs },
46
- { collection: collections.stats }
50
+ { collection: collections.stats },
51
+ readyKey
47
52
  ];
48
53
  /**
49
54
  * The repo `operation` names, read with `reads`, once `authorize` lets `caller` do it. A name with
@@ -83,6 +88,11 @@ const sizedRead = (read, check) => Effect.catchIf(read, isLimitRefusal, (error)
83
88
  * so the open answers as for one, asking `authorize` without the repo there (Q705).
84
89
  */
85
90
  const pinnedTo = (resolved, name, internalId) => internalId === void 0 ? resolved : Effect.flatMap(resolved, (repo) => repo.internalId === internalId ? Effect.succeed(repo) : fail("NOT_FOUND", `No repo '${name}'`));
91
+ /**
92
+ * The repo `name` names while it's still `internalId`, else `NOT_FOUND`: no `authorize`, for a
93
+ * check inside a call that asked it already, as a push's rules are.
94
+ */
95
+ const resolvedAs = (name, internalId) => Effect.flatMap(Effect.service(CoreParts), ({ store }) => pinnedTo(resolveRepo(store, name, []), name, internalId));
86
96
  /** `operation`'s repo read with `reads`, refused for size only to a caller who may open its record. */
87
97
  const sizedOpen = (caller, operation, reads, internalId) => sizedRead(Effect.flatMap(Effect.service(CoreParts), ({ store }) => pinnedTo(resolveRepo(store, operation.repo, reads), operation.repo, internalId)), openRepo(caller, operation, [], internalId));
88
98
  /**
@@ -220,7 +230,8 @@ const keyedRecord = /* @__PURE__ */ Effect.fnUntraced(function* (store, name, ke
220
230
  return {
221
231
  kind: "answered",
222
232
  receipt: yield* matchedReceipt(live, kept),
223
- repo
233
+ repo,
234
+ deleted: record.deleted === true
224
235
  };
225
236
  }
226
237
  return {
@@ -267,4 +278,4 @@ const contended = () => fail("UNAVAILABLE", "Too many writes reached this repo a
267
278
  * it back before it sends the same call again (#1462).
268
279
  */
269
280
  const contendedAfterWrites = () => Effect.fail(afterWrites(gitError("UNAVAILABLE", "Too many writes reached this repo at once")));
270
- export { alreadyExists, callerFor, confirmed, contended, contendedAfterWrites, headOf, hiddenCodes, indexDeleteJobs, indexJobs, keyedRecord, liveAsAsked, nameMoved, openFor, openKeyed, openRepo, purgeJobs, readableRedirect, refIndexJobs, repoAccess, sizedRead, statsReads, unlessHidden };
281
+ export { alreadyExists, callerFor, confirmed, contended, contendedAfterWrites, headOf, hiddenCodes, indexDeleteJobs, indexJobs, keyedRecord, liveAsAsked, nameMoved, openFor, openKeyed, openRepo, purgeJobs, readableRedirect, refIndexJobs, repoAccess, resolvedAs, sizedRead, statsReads, unlessHidden };
@@ -3,7 +3,7 @@ import { catchSpent, ownSpentOf } from "../contracts/calls-spent.mjs";
3
3
  import { fromDiff } from "../engine/failures.mjs";
4
4
  import { walkHistory } from "../engine/walk.mjs";
5
5
  import { ReadTally, defaultDiffLimits, drained } from "../protocol/diff/read.mjs";
6
- import { decodeCommit } from "../protocol/objects/commit.mjs";
6
+ import { decodeCommit, noRepoRoots, parentsWithin } from "../protocol/objects/commit.mjs";
7
7
  import { CallBudget, budgetedOn, callScope, spentBudget } from "../store/call-count.mjs";
8
8
  import { isLimitRefusal } from "../store/errors.mjs";
9
9
  import { runIn } from "../store/crossing.mjs";
@@ -182,6 +182,7 @@ const seenOf = (input, limit, walk, scope) => {
182
182
  }), scope, signal);
183
183
  return {
184
184
  read,
185
+ roots: input.roots ?? noRepoRoots,
185
186
  object: (oid) => object(oid),
186
187
  type
187
188
  };
@@ -221,7 +222,7 @@ const isBehind = (seen, from, to) => walkHistory(seen.read, {
221
222
  wants: [from],
222
223
  haves: [to],
223
224
  page: { limit: 1 }
224
- }, unclocked()).pipe(Effect.map((listed) => listed.items.length === 0), Effect.catchIf((error) => error.code === "NOT_FOUND", () => Effect.succeed(false)));
225
+ }, unclocked(), seen.roots).pipe(Effect.map((listed) => listed.items.length === 0), Effect.catchIf((error) => error.code === "NOT_FOUND", () => Effect.succeed(false)));
225
226
  /**
226
227
  * One edit's kind, or why its ref is refused. As Git's `receive-pack` does, a move is a
227
228
  * fast-forward only when both tips are commits, not tags, and the old one is behind the new.
@@ -242,7 +243,7 @@ const kindOf = /* @__PURE__ */ Effect.fnUntraced(function* (seen, edit, absent)
242
243
  }, (kind, _seen, edit) => Effect.catchIf(kind, isLimitRefusal, (error) => Effect.succeed(refusal(error.cause instanceof WalkCallsSpent ? callsPast(error.cause, edit.ref) : error))));
243
244
  /**
244
245
  * `Kinds.exact`: every parent from the new tip, depth first, until the old tip or the history's
245
- * end. A parent the repo lacks ends its line, as a missing old tip makes a force. Past the push's
246
+ * end, a root of the repo's being one. A parent the repo lacks ends its line, as a missing old tip makes a force. Past the push's
246
247
  * distinct objects, at an object past `ancestryBytes`, or past the walks' calls, `walk-limit`.
247
248
  */
248
249
  const exactOf = (seen, limit) => Effect.fnUntraced(function* (update) {
@@ -256,7 +257,7 @@ const exactOf = (seen, limit) => Effect.fnUntraced(function* (update) {
256
257
  const found = yield* seen.object(oid);
257
258
  if (found === void 0) continue;
258
259
  const commit = yield* decodeCommit(found.bytes).pipe(Effect.catch((error) => fail("DATA_LOSS", `${oid} is unreadable: ${error.message}`)));
259
- for (const parent of commit.parents) {
260
+ for (const parent of parentsWithin(seen.roots, oid, commit.parents)) {
260
261
  if (met.has(parent)) continue;
261
262
  met.add(parent);
262
263
  todo.push(parent);
@@ -700,6 +700,24 @@ const sameJob = (a, b) => a.name === b.name && a.key === b.key;
700
700
  /** Whether `job` is a scope's job of a delivery, `git.deliver.<name>`. */
701
701
  const isDeliverJob = (job) => deliveryOf(job.name) !== void 0 && job.key === "deliver";
702
702
  /**
703
+ * Whether `job`'s delivery has sent the event at `seq` in `scope`: its newest cursor row is at
704
+ * `seq` or past it, or the event is gone, which a trim deletes only once every delivery has passed
705
+ * it and a purge only once none holds it. Else one with no cursor row yet has sent none, and a
706
+ * job no delivery's sends nothing.
707
+ */
708
+ const sentThrough = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, job, seq) {
709
+ const delivery = deliveryOf(job.name);
710
+ if (delivery === void 0) return false;
711
+ const event = {
712
+ collection: outboxCollections.events,
713
+ id: eventId(seq)
714
+ };
715
+ const [cursorRows, eventRows = []] = (yield* storeCall(() => store.read(scope, [cursorRead(delivery), event]))).results;
716
+ if (eventRows.length === 0) return true;
717
+ const cursor = yield* decodeCursor(cursorRows);
718
+ return cursor !== void 0 && cursor.seq >= seq;
719
+ });
720
+ /**
703
721
  * A discard's event that has gone since it read the cursor: `delivery` passed it, by a retry, and
704
722
  * a trim deleted it, so there is nothing to skip. A trim deletes only events every delivery has
705
723
  * passed, so one gone that the cursor hasn't passed is `DATA_LOSS`.
@@ -858,4 +876,4 @@ const deliveryJob = (parts, log, delivery) => {
858
876
  const onFailure = workFailed(log, parts.now, tried);
859
877
  return gitJob(DeliverJob, handler, { onFailure });
860
878
  };
861
- export { DeliverData, checkDeliveries, checkDeliveryTimeout, defaultDeliverRetry, deliverJobKey, deliverJobName, deliverTry, deliveryLog, drainCeiling, isDeliverJob, keptFor, notFailed, skipFailed, workFailed };
879
+ export { DeliverData, checkDeliveries, checkDeliveryTimeout, defaultDeliverRetry, deliverJobKey, deliverJobName, deliverTry, deliveryLog, drainCeiling, isDeliverJob, keptFor, notFailed, sentThrough, skipFailed, workFailed };
@@ -3,6 +3,7 @@ import { fail } from "../contracts/result.mjs";
3
3
  import { objectsFace, oneShotReads } from "../storage/calls.mjs";
4
4
  import { indexRowKey, isPackId, objectCollections } from "../storage/layout.mjs";
5
5
  import { noLfsPointers } from "../storage/lfs-pointers.mjs";
6
+ import { noRows } from "../storage/object-rows.mjs";
6
7
  import { holdingsOf, swapsOf } from "../storage/repack.mjs";
7
8
  import { SwapsSettled, holdingKey, swapsKey } from "../storage/swap-walk.mjs";
8
9
  import { ApartRow, apartAfter, apartKey } from "../storage/repack-contained.mjs";
@@ -14,11 +15,12 @@ import { appendEvents, decodeOutbox, dropUnconfirmed, emptyOutbox, outboxReads,
14
15
  import { keptKey } from "../store/records.mjs";
15
16
  import { WholeRepo, refBytesOf, storesPeel, wholeRef, wholeRefs } from "../store/ref-rows.mjs";
16
17
  import { peeledAll } from "../storage/wants.mjs";
17
- import { commitRecord, decodeTimes, readRecord, timeRow, writeRecord } from "../store/repo-record.mjs";
18
+ import { commitRecord, decodeStats, looseRows, readRecord, timeRow, writeRecord } from "../store/repo-record.mjs";
18
19
  import { afterCommit } from "../store/call-count.mjs";
19
20
  import { listBound } from "../store/cursor-seal.mjs";
20
21
  import { settleName } from "../store/settle.mjs";
21
- import { collections, newChangeId, newInternalId, pushedKey, repoScope, selfKey } from "../store/scopes.mjs";
22
+ import { rowsPut } from "./loose-tally.mjs";
23
+ import { collections, looseKey, newChangeId, newInternalId, pushedKey, repoScope, selfKey } from "../store/scopes.mjs";
22
24
  import { alreadyExists, callerFor, contended, contendedAfterWrites, hiddenCodes, indexJobs, keyedRecord, nameMoved, openKeyed, openRepo, refIndexJobs, repoAccess, sizedRead, statsReads, unlessHidden } from "./access.mjs";
23
25
  import { infoReads, repoInfo } from "./repo-info.mjs";
24
26
  import { kindsOf } from "./ancestry.mjs";
@@ -42,7 +44,7 @@ import { jsonBytes, limits } from "@ref0/infra";
42
44
  * (`seenSource`): the packs are shared whole, and its reads by ID follow its own tips' reach.
43
45
  */
44
46
  const forkWhole = /* @__PURE__ */ WholeRepo.mint();
45
- /** A fork's `index` row as `repoInfo` reads it, by its place after `statsReads`'. */
47
+ /** A fork's `index` row as `repoInfo` reads it, by its place after `statsReads`' four. */
46
48
  const indexRowsOf = (rows) => rows.indexRow === void 0 ? [] : [rows.indexRow];
47
49
  const refsRead = { collection: collections.refs };
48
50
  const packsRead = { collection: collections.packs };
@@ -641,9 +643,11 @@ const forkCalls = (bound) => {
641
643
  const listing = new Set(read.listed.packs.map((pack) => pack.id));
642
644
  const covered = read.listed.packs.flatMap(({ id }) => isPackId(id) ? [leavingKey(id)] : []);
643
645
  const pushed = read.refs.length === 0 ? [] : [timeRow(pushedKey, void 0, at)];
646
+ const loose = looseRows(void 0, rowsPut(objects));
644
647
  const rows = [
645
648
  ...forkRows(core.refIndex, read, objects),
646
649
  ...pushed,
650
+ ...loose,
647
651
  ...unlisted(marked, listing, at)
648
652
  ];
649
653
  const created = {
@@ -695,7 +699,7 @@ const forkCalls = (bound) => {
695
699
  if (written.outcome === "won") return yield* afterCommit(repoInfo(caller, internalId, record, [
696
700
  read.refs,
697
701
  read.packs,
698
- pushed
702
+ [...pushed, ...loose]
699
703
  ]));
700
704
  const dropped = dropUnconfirmed(appended.head);
701
705
  const aside = commitRecord(store, internalId, {
@@ -856,7 +860,7 @@ const forkCalls = (bound) => {
856
860
  repo: name
857
861
  }), hiddenFork);
858
862
  if (record === void 0 || record.deleted === true) return yield* fail("NOT_FOUND", `No repo '${fork}'`);
859
- const [, refRows = [], packRows = [], timeRows = [], leavingRows = [], coverRows = [], indexRows = [], apartRows = [], swapsRows = []] = snapshot.results;
863
+ const [, refRows = [], packRows = [], timeRows = [], readyRows = [], leavingRows = [], coverRows = [], indexRows = [], apartRows = [], swapsRows = []] = snapshot.results;
860
864
  const [headRows = [], cursorRows = [], ...afterOutbox] = snapshot.results.slice(1 + reads.length);
861
865
  const keyed = receiptReads(kept).length;
862
866
  yield* fence.check(afterOutbox.slice(keyed));
@@ -896,6 +900,7 @@ const forkCalls = (bound) => {
896
900
  refRows,
897
901
  packRows,
898
902
  timeRows,
903
+ readyRows,
899
904
  leavingRows,
900
905
  coverRows,
901
906
  apartRows,
@@ -1000,10 +1005,14 @@ const forkCalls = (bound) => {
1000
1005
  ...lacked,
1001
1006
  ...unlisted(shared, covered, into.at),
1002
1007
  ...swapped,
1003
- ...apartAfter(found, { remove }),
1008
+ ...apartAfter(found, {
1009
+ remove,
1010
+ rows: noRows
1011
+ }),
1004
1012
  ...swapsAfter(/* @__PURE__ */ new Set([...kept, ...source.listed.packs.map(({ id }) => id)]), swapsBefore, into.walks)
1005
1013
  ],
1006
- delete: [...added.flatMap(({ id }) => isPackId(id) ? [leavingKey(id)] : []), ...held.flatMap(({ key, pack }) => key.collection === objectCollections.cover && adding.has(pack) ? [key] : [])]
1014
+ delete: [...added.flatMap(({ id }) => isPackId(id) ? [leavingKey(id)] : []), ...held.flatMap(({ key, pack }) => key.collection === objectCollections.cover && adding.has(pack) ? [key] : [])],
1015
+ rows: rowsPut(lacked)
1007
1016
  },
1008
1017
  bytes: added.reduce((sum, pack) => sum + pack.bytes, 0),
1009
1018
  objects: added.reduce((sum, pack) => sum + pack.objects, 0),
@@ -1042,7 +1051,7 @@ const forkCalls = (bound) => {
1042
1051
  const read = yield* forkTry(fork, caller, internalId, kept, (target, record) => authorizeSync(caller, target, record));
1043
1052
  if (read === void 0) continue;
1044
1053
  const { record, snapshot, name, outbox, rows } = read;
1045
- const { refRows, packRows, timeRows, leavingRows } = rows;
1054
+ const { refRows, packRows, timeRows, readyRows, leavingRows } = rows;
1046
1055
  const receipt = yield* heldReceipt(read.receipts, kept);
1047
1056
  if (receipt !== void 0) return yield* repoAnswer(receipt);
1048
1057
  const named = {
@@ -1068,6 +1077,7 @@ const forkCalls = (bound) => {
1068
1077
  refRows,
1069
1078
  packRows,
1070
1079
  timeRows,
1080
+ readyRows,
1071
1081
  indexRowsOf(rows)
1072
1082
  ]);
1073
1083
  const left = unlisted(shared, /* @__PURE__ */ new Set([...listing, ...leavingRows.map(({ id }) => id)]), at);
@@ -1165,13 +1175,19 @@ const forkCalls = (bound) => {
1165
1175
  value: { oid: to }
1166
1176
  }];
1167
1177
  const listedRows = [...packRows.filter(({ id }) => !removing.has(id)), ...added.map(packRow)];
1168
- const times = yield* decodeTimes(timeRows);
1178
+ const times = yield* decodeStats(timeRows);
1169
1179
  const pushed = timeRow(pushedKey, times.pushed, at);
1170
- const timed = [...timeRows.filter(({ id }) => id !== pushedKey.id), pushed];
1180
+ const loose = looseRows(times.loose, received.change.rows);
1181
+ const timed = [
1182
+ ...timeRows.filter(({ id }) => id !== pushedKey.id && (loose.length === 0 || id !== looseKey.id)),
1183
+ pushed,
1184
+ ...loose
1185
+ ];
1171
1186
  const info = yield* repoInfo(caller, internalId, named, [
1172
1187
  moved,
1173
1188
  listedRows,
1174
1189
  timed,
1190
+ readyRows,
1175
1191
  indexRowsOf(rows)
1176
1192
  ]);
1177
1193
  const keptWrites = receiptWrites(kept, repoKept(info), core.repackJobRow);
@@ -1204,6 +1220,7 @@ const forkCalls = (bound) => {
1204
1220
  put: leavingLate([
1205
1221
  ...decision.change.put,
1206
1222
  pushed,
1223
+ ...loose,
1207
1224
  ...keptWrites.put,
1208
1225
  ...appended.put
1209
1226
  ], late),
@@ -1307,9 +1324,11 @@ const forkCalls = (bound) => {
1307
1324
  return answer.kind === "error" ? yield* Effect.fail(answer.error) : fetched;
1308
1325
  }
1309
1326
  const late = (yield* Clock$1.currentTimeMillis) - at;
1327
+ const times = yield* decodeStats(rows.timeRows);
1328
+ const loose = looseRows(times.loose, received.change.rows);
1310
1329
  const change = {
1311
1330
  ...decision.change,
1312
- put: leavingLate(decision.change.put, late),
1331
+ put: [...leavingLate(decision.change.put, late), ...loose],
1313
1332
  jobs: [core.repackJobRow()]
1314
1333
  };
1315
1334
  yield* checkChange(source.name, change);
@@ -1,4 +1,3 @@
1
- import "../../auth/host-function.mjs";
2
1
  import { Git } from "../../contracts/git.mjs";
3
2
  import { GroupOptions, Handlers, HookPoint, PushCheckHandler } from "../../contracts/git-hooks.mjs";
4
3
  import "../../contracts/ids.mjs";
@@ -1,8 +1,8 @@
1
- import { hostEffect, rejectedError, reportRefusal } from "../../auth/host-function.mjs";
1
+ import { hostEffect, logRefusal, rejectedError } from "../../auth/host-function.mjs";
2
2
  import { register } from "../../contracts/git.mjs";
3
3
  import { handlersOf } from "../../contracts/git-hooks.mjs";
4
4
  import { millis } from "../../contracts/promises.mjs";
5
- import { checkedAnswer, pushContextOf } from "../rules/context.mjs";
5
+ import { checkedAnswer, plainAnswer, pushContextOf } from "../rules/context.mjs";
6
6
  import * as Effect from "effect/Effect";
7
7
  import * as Layer from "effect/Layer";
8
8
  // src/core/hooks/groups.ts
@@ -41,7 +41,7 @@ const group = (name, ...input) => Layer.effectDiscard(Effect.gen(function* () {
41
41
  * checks before left, unless none is left, or an atomic push already lost one. The first refusal,
42
42
  * failure or run past its timeout is the answer, which refuses every ref; `undefined` lets it on.
43
43
  */
44
- const runHookGroups = /* @__PURE__ */ Effect.fnUntraced(function* (reports, groups, checking, write) {
44
+ const runHookGroups = /* @__PURE__ */ Effect.fnUntraced(function* (groups, checking, write) {
45
45
  const left = write.updates.filter((update) => !write.refused.has(update.ref));
46
46
  const lost = left.length < write.updates.length;
47
47
  if (left.length === 0 || write.atomic && lost) return void 0;
@@ -58,14 +58,13 @@ const runHookGroups = /* @__PURE__ */ Effect.fnUntraced(function* (reports, grou
58
58
  label,
59
59
  timeout: handler.timeout
60
60
  };
61
- const call = hostEffect(reports, "hooks", about, checkedAnswer(label, () => check(input)), options);
62
- const refusal = yield* Effect.match(call, {
63
- onFailure: (error) => error,
61
+ const call = hostEffect("hooks", about, checkedAnswer(label, plainAnswer, () => check(input)), options);
62
+ const refusal = yield* Effect.matchEffect(call, {
63
+ onFailure: (error) => Effect.succeed(error),
64
64
  onSuccess: (answer) => {
65
- if (answer.kind === "accept") return void 0;
65
+ if (answer.kind === "accept") return Effect.succeed(void 0);
66
66
  const error = rejectedError(answer);
67
- reportRefusal(reports, "hooks", about, error);
68
- return error;
67
+ return Effect.as(logRefusal("hooks", about, error), error);
69
68
  }
70
69
  });
71
70
  if (refusal !== void 0) return refusal;
@@ -154,12 +154,17 @@ const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
154
154
  exempt: true
155
155
  });
156
156
  const repack = parts.repackJobRow !== void 0 && liftsHolds(indexRowOf(row), indexRowOf(step.row), listed) ? [parts.repackJobRow()] : [];
157
+ const retry = yield* lostRetry(step.row, landed, (when) => index.status(step.row, when, ids));
157
158
  const committed = yield* storeCall(() => store.commit(scope, {
158
159
  id: newChangeId(),
159
160
  expect: snapshot.version,
160
161
  put: [step.row, ...appended.put],
161
162
  delete: appended.delete,
162
- jobs: [...appended.jobs, ...repack]
163
+ jobs: [
164
+ ...appended.jobs,
165
+ ...repack,
166
+ ...retry
167
+ ]
163
168
  }));
164
169
  return {
165
170
  ended: committed.ok ? "landed" : "missed",
@@ -169,6 +174,23 @@ const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
169
174
  }
170
175
  };
171
176
  });
177
+ /**
178
+ * The try a refused row a read marked lost gets, `landed` its status: when it waits for its
179
+ * tries' wait, the next round's, due at its end; else none.
180
+ */
181
+ const lostRetry = (row, landed, statusAt) => {
182
+ const built = indexRowOf(row);
183
+ if (landed.state !== "refused" || built === void 0 || "refused" in built) return Effect.succeed([]);
184
+ if (built.lost !== true) return Effect.succeed([]);
185
+ const due = statusAt(landed.retryAt);
186
+ if (due.state !== "retry") return Effect.succeed([]);
187
+ const job = IndexJob.job({
188
+ key: indexJobKeyOf(due.round),
189
+ data: {},
190
+ at: landed.retryAt
191
+ });
192
+ return Effect.map(Effect.orDie(job), (made) => [made]);
193
+ };
172
194
  /** `repo.work.failed` for a round of index builds `refusal` stopped, in the repo's name now. */
173
195
  const refusedEvent = (repo, refusal) => ({
174
196
  type: "repo.work.failed",
@@ -0,0 +1,11 @@
1
+ import { InternalRepoId } from "../contracts/ids.mjs";
2
+ import "../contracts/objects.mjs";
3
+ import "../contracts/promises.mjs";
4
+ import { Listed } from "../contracts/store.mjs";
5
+ import * as Effect from "effect/Effect";
6
+ import { JobInput, Moment, Row } from "@ref0/infra";
7
+ /**
8
+ * A read's ask for the rebuild of the `index` row it read, `row`, once the index it names failed
9
+ * its own checks: `listed` is the listing the read was at.
10
+ */
11
+ export type IndexLost = (repo: InternalRepoId, row: Row, listed: Listed) => Effect.Effect<void>;
@@ -0,0 +1,55 @@
1
+ import { bestEffort, storeCall } from "../store/errors.mjs";
2
+ import { newChangeId, repoScope } from "../store/scopes.mjs";
3
+ import { lostIndexRow } from "../storage/index-build.mjs";
4
+ import { indexJobs } from "./access.mjs";
5
+ import * as Effect from "effect/Effect";
6
+ // src/core/index-lost.ts
7
+ /** The rows a server keeps asked, past which it forgets the oldest: each a repo's row it read. */
8
+ const lostRowsMost = 1024;
9
+ /**
10
+ * A server's ask for the rebuild of an `index` row whose files fail their own checks, as a
11
+ * `.bitmaps` lost, cut short or with a bitmap that won't decode (Q839 (5)): one commit, at the
12
+ * version the read was at, of the row marked lost (`lostIndexRow`) and the row's own `git.index`
13
+ * round. Marked, the row covers nothing, so the reads after it walk with no error, and the try
14
+ * builds it again whole, its new row unmarked; the commit's job makes a waiting row due now. So the
15
+ * walk lasts one rebuild, not until the next push. A server asks once a row while it runs.
16
+ *
17
+ * The ask is best effort: a read never fails on it. A commit that fails, a store's refusal or the
18
+ * read's calls spent, is a warning in the log, and one that loses its version to another commit,
19
+ * as a push's, is dropped quietly: either way, the row is left to the next read that meets it. A
20
+ * row whose round `indexJobs` saves none for, a refusal's, is left as it is.
21
+ */
22
+ const indexLostAsk = (parts) => {
23
+ const asked = /* @__PURE__ */ new Set();
24
+ return (repo, row, listed) => {
25
+ const key = rowKey(repo, row);
26
+ return Effect.gen(function* () {
27
+ if (asked.has(key)) return;
28
+ asked.add(key);
29
+ for (const old of asked) {
30
+ if (asked.size <= 1024) break;
31
+ asked.delete(old);
32
+ }
33
+ const marked = lostIndexRow(row);
34
+ const at = yield* parts.now;
35
+ const packs = listed.packs.map((pack) => pack.id);
36
+ const jobs = indexJobs({ indexJobRow: parts.indexJobRow }, parts.status(row, at, packs));
37
+ if (marked === void 0 || jobs.length === 0) return;
38
+ const failed = (error) => {
39
+ asked.delete(key);
40
+ return Effect.logWarning(`The rebuild of repo ${repo}'s unreadable index wasn't saved, so a later read asks again: ${error.message}`);
41
+ };
42
+ const change = {
43
+ id: newChangeId(),
44
+ expect: listed.version,
45
+ put: [marked],
46
+ jobs
47
+ };
48
+ const committed = yield* bestEffort(storeCall(() => parts.store.commit(repoScope(repo), change)), failed).pipe(Effect.onInterrupt(() => Effect.sync(() => asked.delete(key))));
49
+ if (committed !== void 0 && !committed.ok) asked.delete(key);
50
+ });
51
+ };
52
+ };
53
+ /** A repo's `index` row, as the set of rows asked keeps it. */
54
+ const rowKey = (repo, row) => `${repo}\u0000${JSON.stringify(row.value)}`;
55
+ export { indexLostAsk, lostRowsMost };
@@ -0,0 +1,46 @@
1
+ import { objectCollections } from "../storage/layout.mjs";
2
+ import { storeCall } from "../store/errors.mjs";
3
+ import { rowBytes } from "../store/outbox.mjs";
4
+ import { repoScope } from "../store/scopes.mjs";
5
+ import * as Effect from "effect/Effect";
6
+ import { limits } from "@ref0/infra";
7
+ // src/core/loose-tally.ts
8
+ /**
9
+ * How `change` moves the repo's object rows committed at `version`: its `rows`, less each object
10
+ * row it puts that the repo holds already, which the put only writes again (#2237). Each row is
11
+ * counted by its ID, a store read of `limits.counts` at a time: `undefined` when one answers past
12
+ * `version`, since a commit that expects it then misses anyway, and its next try counts again.
13
+ */
14
+ const rowsAtCommit = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, change, version) {
15
+ const puts = (change.put ?? []).filter((row) => row.collection === objectCollections.objects);
16
+ const scope = repoScope(internalId);
17
+ let objects = change.rows.objects;
18
+ let bytes = change.rows.bytes;
19
+ for (let at = 0; at < puts.length; at += limits.counts) {
20
+ const batch = puts.slice(at, at + limits.counts);
21
+ const counts = batch.map((row) => ({
22
+ collection: row.collection,
23
+ prefix: row.id
24
+ }));
25
+ const snapshot = yield* storeCall(() => store.read(scope, [], counts));
26
+ if (snapshot.version !== version) return void 0;
27
+ for (const [index, row] of batch.entries()) {
28
+ if ((snapshot.counts[index] ?? 0) === 0) continue;
29
+ objects -= 1;
30
+ bytes -= rowBytes(row);
31
+ }
32
+ }
33
+ return {
34
+ objects,
35
+ bytes
36
+ };
37
+ });
38
+ /** `rows`' object rows as `ObjectsChange.rows` counts a put of them: each as new. */
39
+ const rowsPut = (rows) => rows.reduce((moved, row) => row.collection === objectCollections.objects ? {
40
+ objects: moved.objects + 1,
41
+ bytes: moved.bytes + rowBytes(row)
42
+ } : moved, {
43
+ objects: 0,
44
+ bytes: 0
45
+ });
46
+ export { rowsAtCommit, rowsPut };
@@ -30,7 +30,7 @@ const mergedTree = /* @__PURE__ */ Effect.fnUntraced(function* (opened, made, si
30
30
  const input = { ...sides };
31
31
  if (options.limits !== void 0) input.limits = options.limits;
32
32
  if (options.signal !== void 0) input.signal = options.signal;
33
- const merged = yield* parts.mergeTrees(opened.read, input, callAllot(opened), call);
33
+ const merged = yield* parts.mergeTrees(opened.read, input, callAllot(opened), call, opened.roots);
34
34
  yield* takeWrites(made, merged.objects);
35
35
  return merged.tree;
36
36
  });