@ref0/git 0.7.0 → 0.8.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 (191) 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/client.d.mts +16 -9
  36. package/dist/contracts/events.d.mts +12 -10
  37. package/dist/contracts/events.mjs +8 -6
  38. package/dist/contracts/files.d.mts +42 -42
  39. package/dist/contracts/forks.d.mts +0 -24
  40. package/dist/contracts/git-hooks.d.mts +217 -0
  41. package/dist/contracts/git-hooks.mjs +3 -1
  42. package/dist/contracts/grants.d.mts +46 -27
  43. package/dist/contracts/lfs.d.mts +17 -4
  44. package/dist/contracts/merges.d.mts +7 -7
  45. package/dist/contracts/objects.d.mts +20 -4
  46. package/dist/contracts/opaque.mjs +19 -1
  47. package/dist/contracts/operations.d.mts +8 -1
  48. package/dist/contracts/operations.mjs +209 -0
  49. package/dist/contracts/queue.d.mts +3 -3
  50. package/dist/contracts/queue.mjs +5 -18
  51. package/dist/contracts/remote.d.mts +13 -4
  52. package/dist/contracts/remote.mjs +3 -3
  53. package/dist/contracts/repos.d.mts +11 -40
  54. package/dist/contracts/repos.mjs +11 -10
  55. package/dist/contracts/result.d.mts +28 -11
  56. package/dist/contracts/result.mjs +32 -2
  57. package/dist/contracts/rules.d.mts +706 -46
  58. package/dist/contracts/rules.mjs +81 -2
  59. package/dist/contracts/server.d.mts +5 -275
  60. package/dist/contracts/services.d.mts +0 -3
  61. package/dist/contracts/services.mjs +1 -3
  62. package/dist/contracts/signin.d.mts +2 -2
  63. package/dist/contracts/signin.mjs +4 -5
  64. package/dist/contracts/sync.d.mts +1 -4
  65. package/dist/contracts/tokens.d.mts +29 -17
  66. package/dist/contracts/tokens.mjs +14 -3
  67. package/dist/contracts/topics.d.mts +38 -11
  68. package/dist/contracts/topics.mjs +8 -2
  69. package/dist/core/access.d.mts +0 -2
  70. package/dist/core/access.mjs +15 -4
  71. package/dist/core/events/deliver.mjs +19 -1
  72. package/dist/core/forks.mjs +30 -11
  73. package/dist/core/hooks/groups.d.mts +0 -1
  74. package/dist/core/hooks/groups.mjs +8 -9
  75. package/dist/core/loose-tally.mjs +46 -0
  76. package/dist/core/objects/writing.mjs +1 -0
  77. package/dist/core/promise.mjs +1 -15
  78. package/dist/core/purge.mjs +14 -9
  79. package/dist/core/push.mjs +13 -6
  80. package/dist/core/ref-view.mjs +14 -6
  81. package/dist/core/repack.mjs +19 -14
  82. package/dist/core/repo-info.mjs +8 -6
  83. package/dist/core/repos.mjs +1 -0
  84. package/dist/core/rules/check.mjs +10 -10
  85. package/dist/core/rules/context.d.mts +3 -1
  86. package/dist/core/rules/context.mjs +16 -13
  87. package/dist/core/rules/fetch.mjs +17 -23
  88. package/dist/core/tokens.mjs +2 -1
  89. package/dist/effect.d.mts +2 -4
  90. package/dist/effect.mjs +2 -4
  91. package/dist/engine/commits.mjs +19 -47
  92. package/dist/engine/failures.d.mts +1 -2
  93. package/dist/engine/failures.mjs +1 -3
  94. package/dist/engine/merge-base-walk.mjs +57 -142
  95. package/dist/engine/merge-bases.mjs +5 -5
  96. package/dist/engine/merge.mjs +16 -14
  97. package/dist/extend.d.mts +1 -2
  98. package/dist/extend.mjs +1 -2
  99. package/dist/http/core-parts.mjs +1 -2
  100. package/dist/http/handler.mjs +11 -31
  101. package/dist/http/parts.d.mts +0 -1
  102. package/dist/index.d.mts +28 -21
  103. package/dist/index.mjs +5 -2
  104. package/dist/lfs/base.d.mts +6 -3
  105. package/dist/lfs/base.mjs +2 -1
  106. package/dist/lfs/layer.d.mts +4 -3
  107. package/dist/lfs/layer.mjs +23 -9
  108. package/dist/lfs/objects.mjs +90 -41
  109. package/dist/lfs/pointers.mjs +69 -18
  110. package/dist/lfs/purge.mjs +6 -2
  111. package/dist/lfs/rows.mjs +24 -7
  112. package/dist/lfs/service.d.mts +6 -3
  113. package/dist/lfs/service.mjs +8 -2
  114. package/dist/lfs/upkeep.mjs +44 -26
  115. package/dist/lfs/upload-most.mjs +41 -0
  116. package/dist/lfs/uploaded.mjs +59 -0
  117. package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
  118. package/dist/protocol/bytes/text.mjs +6 -1
  119. package/dist/protocol/objects/fsck.mjs +6 -3
  120. package/dist/queue/advance.mjs +38 -8
  121. package/dist/queue/calls.mjs +4 -14
  122. package/dist/queue/lanes.mjs +1 -1
  123. package/dist/queue/rows.mjs +8 -0
  124. package/dist/queue/schedule.mjs +1 -1
  125. package/dist/queue/search.mjs +3 -4
  126. package/dist/rest/client-namespace.d.mts +2 -0
  127. package/dist/rest/client.d.mts +32 -8
  128. package/dist/rest/client.mjs +308 -382
  129. package/dist/rest/commits.d.mts +240 -240
  130. package/dist/rest/files.d.mts +18 -18
  131. package/dist/rest/forks.d.mts +45 -57
  132. package/dist/rest/handlers.mjs +2 -1
  133. package/dist/rest/listen.d.mts +8 -6
  134. package/dist/rest/listen.mjs +31 -75
  135. package/dist/rest/me.d.mts +2 -2
  136. package/dist/rest/merges.d.mts +7 -7
  137. package/dist/rest/refs.d.mts +139 -139
  138. package/dist/rest/repos.d.mts +54 -66
  139. package/dist/rest/tokens.d.mts +12 -12
  140. package/dist/rest/topics.d.mts +110 -110
  141. package/dist/rest/trees.d.mts +66 -66
  142. package/dist/rest/wire.d.mts +1 -1
  143. package/dist/rest.d.mts +1 -7
  144. package/dist/rest.mjs +1 -5
  145. package/dist/server/git-layer.d.mts +10 -2
  146. package/dist/server/git-layer.mjs +29 -10
  147. package/dist/server/joined.d.mts +1 -1
  148. package/dist/server/server.d.mts +0 -1
  149. package/dist/server/server.mjs +26 -45
  150. package/dist/signin/context.d.mts +0 -1
  151. package/dist/signin/context.mjs +5 -9
  152. package/dist/storage/clean-up.mjs +3 -1
  153. package/dist/storage/fsck.mjs +12 -2
  154. package/dist/storage/graph-rebuild.mjs +262 -0
  155. package/dist/storage/index-build.mjs +100 -12
  156. package/dist/storage/lfs-pointers.d.mts +5 -5
  157. package/dist/storage/lfs-pointers.mjs +37 -11
  158. package/dist/storage/loose.mjs +4 -1
  159. package/dist/storage/memory-budget.mjs +1 -1
  160. package/dist/storage/merge-fence.mjs +81 -19
  161. package/dist/storage/merge-most.mjs +1 -0
  162. package/dist/storage/merge-row.mjs +16 -4
  163. package/dist/storage/merge-stream.mjs +9 -6
  164. package/dist/storage/object-rows.mjs +17 -1
  165. package/dist/storage/pack-receive.mjs +10 -6
  166. package/dist/storage/packs.mjs +58 -27
  167. package/dist/storage/prune.mjs +68 -40
  168. package/dist/storage/ready.d.mts +1 -1
  169. package/dist/storage/ready.mjs +12 -3
  170. package/dist/storage/receive-state.mjs +1 -1
  171. package/dist/storage/repack-contained.mjs +22 -14
  172. package/dist/storage/repack.d.mts +1 -1
  173. package/dist/storage/repack.mjs +3 -2
  174. package/dist/storage/unpack.mjs +7 -0
  175. package/dist/store/call-count.d.mts +23 -3
  176. package/dist/store/call-count.mjs +36 -13
  177. package/dist/store/records.mjs +10 -4
  178. package/dist/store/repo-record.mjs +29 -12
  179. package/dist/store/scopes.mjs +6 -1
  180. package/dist/sync/import.mjs +14 -2
  181. package/dist/sync/layer.d.mts +5 -1
  182. package/dist/sync/layer.mjs +7 -2
  183. package/dist/sync/step.mjs +15 -15
  184. package/dist/topics/advance.mjs +7 -6
  185. package/dist/topics/members.mjs +38 -9
  186. package/package.json +3 -3
  187. package/dist/engine/merge-base-walk.d.mts +0 -3
  188. package/dist/server/routes.d.mts +0 -32
  189. package/dist/server/routes.mjs +0 -69
  190. package/dist/sync/bridge.d.mts +0 -6
  191. package/dist/sync/bridge.mjs +0 -29
@@ -95,9 +95,10 @@ import * as Option from "effect/Option";
95
95
  import * as Cause from "effect/Cause";
96
96
  import * as Exit from "effect/Exit";
97
97
  import * as EffectResult from "effect/Result";
98
- import { Bucket, BucketLinks, BucketUploads, CallLimits, JobQueue, Records } from "@ref0/infra";
98
+ import { Bucket, BucketLinks, BucketUploads, CallLimits, JobQueue, Records, RequestLimits } from "@ref0/infra";
99
99
  import * as Context from "effect/Context";
100
100
  import * as Layer from "effect/Layer";
101
+ import * as References from "effect/References";
101
102
  import * as ManagedRuntime from "effect/ManagedRuntime";
102
103
  // src/server/server.ts
103
104
  /**
@@ -162,7 +163,7 @@ const bridged = (setup) => ({
162
163
  features: Effect.fnUntraced(function* (services, registry) {
163
164
  if (setup.lfs !== void 0) {
164
165
  const registration = yield* registry.register({ name: "lfs" });
165
- yield* Effect.provideContext(lfsRegistration(registration), services);
166
+ yield* Effect.provideContext(lfsRegistration(registration, setup.lfs), services);
166
167
  }
167
168
  if (setup.topics !== void 0) {
168
169
  const registration = yield* registry.register({
@@ -186,7 +187,7 @@ const bridged = (setup) => ({
186
187
  });
187
188
  /** Git's own wiring over the adapter's services, as the runtime's build runs it. */
188
189
  const wireServer = (options, wiring) => {
189
- const { adapter, merges, optional, fetchLimits, reports, deciders, grants, extensions, guard, through, closing } = wiring;
190
+ const { adapter, merges, optional, fetchLimits, deciders, grants, extensions, guard, through, closing } = wiring;
190
191
  const runtimeClock = wiring.clock;
191
192
  const queueOf = optional.queue;
192
193
  const { store, jobs, records: rawRecords } = adapter;
@@ -212,16 +213,7 @@ const wireServer = (options, wiring) => {
212
213
  store,
213
214
  now
214
215
  });
215
- const seen = {
216
- deliveries: 0,
217
- sealed: false
218
- };
219
- registry.bindDeliveries((registered) => {
220
- const made = events.fill(registered);
221
- seen.sealed = true;
222
- seen.deliveries = events.deliveries.length;
223
- return made;
224
- });
216
+ registry.bindDeliveries((registered) => events.fill(registered));
225
217
  const onFailure = workFailed(events, now);
226
218
  const upkeep = upkeepsOf([...counted === void 0 ? [] : [pushUploadUpkeep(counted, adapter.uploads)], registry.upkeep]);
227
219
  const index = objects.index === void 0 ? void 0 : indexJob({
@@ -261,12 +253,10 @@ const wireServer = (options, wiring) => {
261
253
  jobs.register(...jobsWithin(jobLimits, own));
262
254
  const decides = {
263
255
  policy: deciders.policy,
264
- reports,
265
256
  grants
266
257
  };
267
258
  const authorize = authorizer(decides);
268
259
  const checks = {
269
- reports,
270
260
  added: () => registry.pushRules(),
271
261
  registered: () => registry.pushChecks(),
272
262
  groups: () => registry.hookGroups()
@@ -274,7 +264,6 @@ const wireServer = (options, wiring) => {
274
264
  const fences = grantFences({
275
265
  store,
276
266
  now,
277
- reports,
278
267
  grants
279
268
  });
280
269
  const repackRow = (at) => repackJobRow(repack, at);
@@ -304,9 +293,9 @@ const wireServer = (options, wiring) => {
304
293
  const decider = {
305
294
  check: authorize,
306
295
  audience: audienceOf(decides),
307
- ceiling: ({ caller, repo, internalId }) => accessOf(reports, grants, store, caller, repo, internalId),
296
+ ceiling: ({ caller, repo, internalId }) => accessOf(grants, store, caller, repo, internalId),
308
297
  grantOf: grants.nameOf,
309
- grantAgain: ({ resolver, request }) => grantAgain(grants, reports, registry.grants(), resolver, request)
298
+ grantAgain: ({ resolver, request }) => grantAgain(grants, registry.grants(), resolver, request)
310
299
  };
311
300
  const records = Context.make(RepoRecords, {
312
301
  pin: (name) => pinOf(store, name),
@@ -316,7 +305,7 @@ const wireServer = (options, wiring) => {
316
305
  objects: sealed,
317
306
  fetchLimits
318
307
  }), Context.add(Objects, objectsOverViews), Context.add(Changes, changes));
319
- const base = Context.make(CoreParts, parts).pipe(Context.add(Rules, wiring.rules), Context.merge(indexed === void 0 ? stored : Context.add(stored, IndexedStorage, indexed)), Context.add(QueueParts, { jobs }), Context.add(Authorize, decider), Context.add(Clock$1.Clock, runtimeClock));
308
+ const base = Context.make(CoreParts, parts).pipe(Context.add(Rules, wiring.rules), Context.merge(indexed === void 0 ? stored : Context.add(stored, IndexedStorage, indexed)), Context.add(QueueParts, { jobs }), Context.add(Authorize, decider), Context.add(Clock$1.Clock, runtimeClock), Context.merge(wiring.logging));
320
309
  const merging = merges === void 0 ? base : Context.merge(base, merges);
321
310
  const viewed = Context.add(merging, View, viewOver(merging));
322
311
  const needs = Context.add(viewed, Refs, providedCalls(refsCalls, viewed));
@@ -349,6 +338,7 @@ const wireServer = (options, wiring) => {
349
338
  needs,
350
339
  bucket: counted,
351
340
  links: adapter.links,
341
+ requestLimits: adapter.requestLimits,
352
342
  attach: (lfs) => Effect.suspend(() => {
353
343
  if (lfsAttached !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server has Git LFS: provide Lfs.layer once"));
354
344
  lfsAttached = lfs;
@@ -395,7 +385,6 @@ const wireServer = (options, wiring) => {
395
385
  tokens: tokensHeld.calls,
396
386
  store,
397
387
  now,
398
- reports,
399
388
  through,
400
389
  refuse: (error) => refusal(error, true)
401
390
  })
@@ -415,7 +404,6 @@ const wireServer = (options, wiring) => {
415
404
  auth: deciders.auth,
416
405
  grants: registry.grants,
417
406
  held: grants,
418
- reports,
419
407
  now
420
408
  });
421
409
  const decided = Context.add(records, Authorize, decider).pipe(Context.add(Refs, Context.get(needs, Refs)), Context.add(Rules, wiring.rules), Context.add(Objects, objectsOverViews), Context.merge(callServices(needs)), Context.add(Events, { log: events }), Context.add(QueueBase, queueBase), Context.add(SyncBase, {
@@ -475,24 +463,19 @@ const wireServer = (options, wiring) => {
475
463
  identify: (request) => through(identify(request)),
476
464
  authorize: (input) => through(Effect.provideContext(seamAuthorize(input), needs)),
477
465
  renamedTo: (caller, repo) => through(Effect.provideContext(renamedTo(caller, repo), needs)),
478
- listen: (caller, repo, after) => through(Effect.suspend(() => !keepsEvents(events) ? fail("FAILED_PRECONDITION", "This server keeps no events", {
479
- hostHint: "Its host registers a delivery, with Git.register, to keep them",
480
- hint: `Deliveries: ${seen.deliveries}. Sealed: ${seen.sealed ? "yes" : "no"}.`
481
- }) : streams.open(caller, repo, after))),
466
+ listen: (caller, repo, after) => through(Effect.suspend(() => !keepsEvents(events) ? fail("FAILED_PRECONDITION", "This server keeps no events", { hostHint: "Its host registers a delivery, with Git.register, to keep them" }) : streams.open(caller, repo, after))),
482
467
  requestMost
483
468
  };
484
469
  const httpOptions = { queue: queuePush(() => queueHeld.host) };
485
- if (options.resolve !== void 0) httpOptions.resolve = options.resolve;
486
470
  if (options.maxDuration !== void 0) httpOptions.maxDuration = millis(options.maxDuration);
487
471
  if (objects.pushObjectsMost !== void 0) httpOptions.pushObjectsMost = objects.pushObjectsMost;
488
- const resolves = options.resolve === void 0 ? 0 : 1;
489
- const fetchHooks = resolves + (wiring.rules.fetch.length === 0 ? 0 : 1);
472
+ const fetchHooks = wiring.rules.fetch.length === 0 ? 0 : 1;
490
473
  const before = (hooks) => (most) => boundOf(lessBefore(most, {
491
474
  bucket: hooks * hookCallsBefore.bucket,
492
475
  subrequests: hooks * hookCallsBefore.subrequests
493
476
  }));
494
477
  httpOptions.calls = before(fetchHooks)(countedMost(objects) ?? callLimits);
495
- httpOptions.pushCalls = before(resolves)(callLimits);
478
+ httpOptions.pushCalls = before(0)(callLimits);
496
479
  httpOptions.lfs = () => lfsAttached?.service;
497
480
  httpOptions.uploads = () => uploadsAttached;
498
481
  const http = gitHttp(coreHttpParts(served, httpOptions));
@@ -527,16 +510,14 @@ const isLayers = (adapter) => Array.isArray(adapter);
527
510
  * runtime builds the adapter's Layers and Git's wiring once the tick that made it ends, which
528
511
  * registers Git's jobs on the adapter's queue, and never runs them: the host starts them.
529
512
  */
530
- const createGitServer = (options) => serverWithFeatures(options);
531
- /** Internal features argument for legacy test worlds; 2c-1b removes it with their bridge. */
532
- const serverWithFeatures = (options, features) => serverWith(options, (reports) => ({
533
- policy: policyOf(options.authorize, reports),
534
- auth: authOf(options.auth, reports)
535
- }), features);
513
+ const createGitServer = (options) => serverWith(options, () => ({
514
+ policy: policyOf(options.authorize),
515
+ auth: authOf(options.auth)
516
+ }));
536
517
  /**
537
- * `createGitServer` deciding with `decidersOf`'s answer, which it asks once with the server's
538
- * reports: `GitServer.routes` gives its host's services, and `createGitServer` its options' hooks.
539
- * Internal: no entry exports it, so a host gives a `Policy` only through `GitServer.routes`.
518
+ * `createGitServer` deciding with `decidersOf`'s answer, which it asks once as the server builds:
519
+ * `createGitServer` gives its options' hooks. Internal: no entry exports it, so a host
520
+ * gives a `Policy` only through `Git.layer`.
540
521
  */
541
522
  const serverWith = (options, decidersOf, features) => openServer(options, decidersOf, "build", features).server;
542
523
  /**
@@ -554,10 +535,7 @@ const openServer = (options, decidersOf, sealing, features) => {
554
535
  if (setup.topics !== void 0 && queueOf === void 0) throw new TypeError("topics merge through each repo’s queue: pass queue too");
555
536
  if (queueOf !== void 0 && setup.xdiff === void 0) throw new TypeError("the merge queue merges trees: pass xdiff too");
556
537
  const fetchLimits = fetchLimitsOf(setup.fetchLimits);
557
- const reports = {};
558
538
  const grants = heldGrants();
559
- if (setup.onError !== void 0) reports.onError = setup.onError;
560
- if (setup.onRefused !== void 0) reports.onRefused = setup.onRefused;
561
539
  const basePath = normalBase(setup.basePath ?? "");
562
540
  const extensions = openExtensions(basePath);
563
541
  const joins = [];
@@ -604,10 +582,12 @@ const openServer = (options, decidersOf, sealing, features) => {
604
582
  const records = yield* Records.Records;
605
583
  const queue = yield* JobQueue.JobQueue;
606
584
  const callLimits = yield* CallLimits.CallLimits;
585
+ const requestLimits = yield* Effect.serviceOption(RequestLimits.RequestLimits);
607
586
  const bucket = yield* Effect.serviceOption(Bucket.Bucket);
608
587
  const links = yield* Effect.serviceOption(BucketLinks.BucketLinks);
609
588
  const uploads = yield* Effect.serviceOption(BucketUploads.BucketUploads);
610
589
  const clock = yield* Effect.clockWith(Effect.succeed);
590
+ const logging = Context.make(References.CurrentLoggers, yield* References.CurrentLoggers).pipe(Context.add(References.MinimumLogLevel, yield* References.MinimumLogLevel));
611
591
  const xdiff = setup.xdiff;
612
592
  const loaded = xdiff === void 0 ? void 0 : yield* Effect.cached(Effect.flatMap(Effect.promise(() => import("../merges/merges.mjs")), ({ mergesContext }) => mergesContext({ xdiff }, objectsOverViews)));
613
593
  const merges = loaded === void 0 ? void 0 : Context.make(MergeParts, partsOnce(loaded));
@@ -625,7 +605,8 @@ const openServer = (options, decidersOf, sealing, features) => {
625
605
  links: Option.isSome(links) ? doorLinks(hostLinks(links.value), context, door) : void 0,
626
606
  uploads: Option.isSome(uploads) ? doorUploads(hostUploads(uploads.value), context, door) : void 0,
627
607
  clock: promisesClock(clock, context, door),
628
- callLimits
608
+ callLimits,
609
+ requestLimits: Option.getOrElse(requestLimits, () => ({}))
629
610
  };
630
611
  const given = {
631
612
  adapter,
@@ -635,12 +616,12 @@ const openServer = (options, decidersOf, sealing, features) => {
635
616
  tokens: tokensHeld,
636
617
  queue: queueHeld,
637
618
  fetchLimits,
638
- reports,
639
- deciders: decidersOf(reports),
619
+ deciders: decidersOf(),
640
620
  grants,
641
621
  extensions,
642
622
  basePath,
643
623
  clock,
624
+ logging,
644
625
  access: Option.getOrUndefined(yield* Effect.serviceOption(PrivateRefs))
645
626
  };
646
627
  const wired = yield* Effect.sync(() => wireServer(setup, {
@@ -825,4 +806,4 @@ const openServer = (options, decidersOf, sealing, features) => {
825
806
  seal
826
807
  };
827
808
  };
828
- export { createGitServer, openServer, serverWith, serverWithFeatures };
809
+ export { createGitServer, openServer, serverWith };
@@ -2,7 +2,6 @@ import "../contracts/git.mjs";
2
2
  import "../contracts/promises.mjs";
3
3
  import "../contracts/result.mjs";
4
4
  import "../contracts/signin.mjs";
5
- import "../auth/host-function.mjs";
6
5
  import "../auth/tokens.mjs";
7
6
  import "./grants.mjs";
8
7
  import "effect/Effect";
@@ -1,5 +1,5 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
- import { hostEffect, reportRefusal } from "../auth/host-function.mjs";
2
+ import { hostEffect, logRefusal } from "../auth/host-function.mjs";
3
3
  import { readTarget, tokenExpiry } from "../auth/tokens.mjs";
4
4
  import { oauthAnswer, oauthError } from "./forms.mjs";
5
5
  import { approvalOf } from "./grants.mjs";
@@ -10,8 +10,8 @@ import * as Schema from "effect/Schema";
10
10
  /** `gh`'s OAuth client ID, which the device flow takes beside the registered clients. */
11
11
  const ghClientId = "178c6fc778ccc68e1d6a";
12
12
  /**
13
- * The page in the caller's fiber: explicit failures keep Git's status and code, and reach
14
- * `onRefused` as every host function's refusal does. A decide's store failure keeps the plain
13
+ * The page in the caller's fiber: explicit failures keep Git's status and code, and are logged at
14
+ * `Debug` as every host function's refusal is. A decide's store failure keeps the plain
15
15
  * unavailable page; a defect is reported as a host failure. Each invocation receives its own
16
16
  * unread request body.
17
17
  */
@@ -29,12 +29,8 @@ const approvalPage = /* @__PURE__ */ Effect.fnUntraced(function* (signIn, reques
29
29
  ...page,
30
30
  request: request.clone(),
31
31
  signal
32
- })).pipe(Effect.catch((error) => Effect.sync(() => {
33
- if (failedDecisions.has(error)) return unavailablePage(error);
34
- reportRefusal(signIn.reports, "approvalPage", {}, error);
35
- return signIn.refuse(error);
36
- })));
37
- return yield* hostEffect(signIn.reports, "approvalPage", {}, answer).pipe(Effect.onInterrupt(() => Effect.sync(() => controller.abort())));
32
+ })).pipe(Effect.catch((error) => failedDecisions.has(error) ? Effect.sync(() => unavailablePage(error)) : Effect.map(logRefusal("approvalPage", {}, error), () => signIn.refuse(error))));
33
+ return yield* hostEffect("approvalPage", {}, answer).pipe(Effect.onInterrupt(() => Effect.sync(() => controller.abort())));
38
34
  });
39
35
  /**
40
36
  * What a browser sees when sign-in failed: a 503 to try again, or a 500 for a store the host didn't
@@ -2,6 +2,7 @@ import { repoScope } from "../store/scopes.mjs";
2
2
  import { bucketDo } from "./calls.mjs";
3
3
  import { markerKey, markerPrefix, objectCollections } from "./layout.mjs";
4
4
  import { mergeKey } from "./merge-row.mjs";
5
+ import { noRows } from "./object-rows.mjs";
5
6
  import { deletePackFiles } from "./quarantine.mjs";
6
7
  import { deleteStaged, receiveKey, stagedRow } from "./receive-steps.mjs";
7
8
  import { QuarantineRow, StagedRow, decodeHeld, decodeLeft, quarantineKey, quarantineRow, stagedKey } from "./rows.mjs";
@@ -187,7 +188,8 @@ const cleanUp = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
187
188
  const step = {
188
189
  change: {
189
190
  put,
190
- delete: ended
191
+ delete: ended,
192
+ rows: noRows
191
193
  },
192
194
  more
193
195
  };
@@ -1,6 +1,7 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
2
  import { checkedBlobs, checkedTableBytes } from "../protocol/objects/checked-blobs.mjs";
3
3
  import { checkedBlobFault } from "../protocol/objects/fsck.mjs";
4
+ import { cutWords, quoted } from "../protocol/bytes/text.mjs";
4
5
  import { mostParents } from "../protocol/objects/object-rules.mjs";
5
6
  import { oidBytes } from "../protocol/packs/idx.mjs";
6
7
  import * as Effect from "effect/Effect";
@@ -17,14 +18,23 @@ const tooManyParents = (what, parents) => gitError("INVALID_ARGUMENT", `${what}
17
18
  given: parents
18
19
  }
19
20
  });
20
- /** A push refused for an object Git 2.53 would refuse it for, under git-fsck's msg-id. */
21
- const fsckRefusal = (oid, fault) => fault.parents === void 0 ? gitError("INVALID_ARGUMENT", `object ${oid}: ${fault.msgId}: ${fault.message}`, {
21
+ /**
22
+ * A push refused for an object Git 2.53 would refuse it for, under git-fsck's msg-id. A tree that
23
+ * names an entry twice is named with the entry's name too, which Git's message leaves out.
24
+ */
25
+ const fsckRefusal = (oid, fault) => fault.parents === void 0 ? gitError("INVALID_ARGUMENT", `object ${oid}: ${fault.msgId}: ${fault.message}${namedIn(fault)}`, {
22
26
  hint: "Fix the object, then push again",
23
27
  context: {
24
28
  reason: "fsck",
25
29
  msgId: fault.msgId
26
30
  }
27
31
  }) : tooManyParents(`object ${oid}`, fault.parents);
32
+ const namedIn = (fault) => {
33
+ if (fault.name === void 0) return "";
34
+ const shown = cutWords(fault.name, 256);
35
+ const cut = shown.length < fault.name.length ? ` (its first ${shown.length} characters)` : "";
36
+ return `, ${quoted(shown)}${cut} twice`;
37
+ };
28
38
  /**
29
39
  * What a push's `.gitmodules` and `.gitattributes` hold, however many its trees name: each blob
30
40
  * they name as one is kept to check once the pack is read, at most `most` of them. A tree naming
@@ -0,0 +1,262 @@
1
+ import { gitError } from "../contracts/result.mjs";
2
+ import { hexOf } from "../protocol/bytes/hex.mjs";
3
+ import { graphBytes, sortedGraph } from "../protocol/packs/graph.mjs";
4
+ import { mostParents } from "../protocol/objects/object-rules.mjs";
5
+ import { oidBytes } from "../protocol/packs/idx.mjs";
6
+ import { typeOfByte } from "../protocol/packs/types-file.mjs";
7
+ import { packRow } from "../store/git-store.mjs";
8
+ import { bucketDeleteMany, bucketPut, deleteCharge, readWhole, sizedPutCalls } from "./calls.mjs";
9
+ import { openTypes } from "./held-types.mjs";
10
+ import { isPackId, packFiles, runKey } from "./layout.mjs";
11
+ import { linksOf } from "./links.mjs";
12
+ import { noRows } from "./object-rows.mjs";
13
+ import { upkeepTooLarge } from "./memory-budget.mjs";
14
+ import { refusedKey } from "./merge-fence.mjs";
15
+ import { readersOf } from "./merge-stream.mjs";
16
+ import { openIndexRanges, readExactly } from "./pack-ranges.mjs";
17
+ import { dropRunsCalls } from "./receive-bounds.mjs";
18
+ import { dropRuns } from "./runs.mjs";
19
+ import * as Effect from "effect/Effect";
20
+ // src/storage/graph-rebuild.ts
21
+ /**
22
+ * The rebuild of a graph-fenced pack's `.graph` (#2227): a merge that found the file broken, or not
23
+ * the size its row records, fenced the pack, and nothing else writes a `.graph` from a pack alone.
24
+ *
25
+ * The `.idx` lists the pack's objects in ID order, the order the `.graph` holds its commits in, so
26
+ * each step reads the commits of the ranks from its cursor, as far as its calls go, and puts their
27
+ * part of the file's body as a run, `graph-<n>`, under the pack's runs. The `refused` row carries
28
+ * the cursor. The last step joins the parts into the `.graph`, puts it, then commits the pack's row
29
+ * with the file's size beside the `refused` row's delete. A step that crashes first commits
30
+ * nothing, and the next does its work again: a part put again over itself, or the file put again.
31
+ * A part found missing, as when the last step dropped the runs and crashed before its commit,
32
+ * starts the rebuild over. While the `refused` row stands, no merge reads the pack's `.graph`.
33
+ *
34
+ * Its parts stay within `rebuildPartsMost`: a step that finds that many puts them again as one,
35
+ * under the next number, and the next step deletes the ones it replaced. So the last step's calls,
36
+ * its reads of the parts, the `.graph`'s put and the runs' drop, are forecast before it starts,
37
+ * and a step whose calls don't fit them marks the pack failed. A job's try runs one step, each
38
+ * after the same reads, so a step that doesn't fit now would fit no later try either.
39
+ */
40
+ /** The ranks a step reads at a time: one get of IDs, one of offsets and one of types. */
41
+ const rebuildWindowRanks = 4096;
42
+ /** A commit's head in a part: its ID and its parents' count, as the `.graph` lays it. */
43
+ const headBytes = 24;
44
+ const started = {
45
+ rank: 0,
46
+ commits: 0,
47
+ parents: 0,
48
+ first: 0,
49
+ parts: 0,
50
+ swept: 0
51
+ };
52
+ /** Whether `made` and `extra` more calls leave the reserve within `most`. */
53
+ const within = (made, extra, most) => made.bucket + extra + 64 < most.bucket && made.subrequests + extra + 64 < most.subrequests;
54
+ /** Whether a step with `calls` has room for `extra` calls, and one more commit's read. */
55
+ const roomFor = (calls, extra = 0) => calls === void 0 || within(calls.made(), extra, calls.most);
56
+ /** The first listed pack, by ID, whose `.graph` a merge refused and no rebuild failed on. */
57
+ const rebuildable = (packs, refused) => packs.filter((pack) => {
58
+ const row = refused.get(pack.id);
59
+ return row !== void 0 && (row.reason === "graph-length" || row.reason === "graph-broken") && row.rebuilt === void 0;
60
+ }).toSorted((a, b) => a.id < b.id ? -1 : 1)[0];
61
+ /** The `refused` row of `pack`, as `row` but with `fields`. */
62
+ const rowOf = (pack, row, fields) => {
63
+ const { rebuild: _, ...rest } = row;
64
+ return {
65
+ ...refusedKey(pack),
66
+ value: {
67
+ ...rest,
68
+ ...fields
69
+ }
70
+ };
71
+ };
72
+ /** The keys of `pack`'s parts from `from` up to `to`. */
73
+ const partKeys = (pack, from, to) => Array.from({ length: Math.max(0, to - from) }, (_, at) => runKey(pack, "graph", from + at));
74
+ /** Each commit of `pack` from `cursor`'s rank, as a part's bytes, till the window or the calls end. */
75
+ const readPart = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, cursor, calls) {
76
+ const chunks = [];
77
+ let { rank, commits, parents } = cursor;
78
+ const stored = {
79
+ id: pack.id,
80
+ bytes: pack.bytes
81
+ };
82
+ const ranges = yield* openIndexRanges(input.bucket, stored, pack.objects);
83
+ const checksum = hexOf(yield* readExactly(input.bucket, packFiles(pack.id).pack, pack.bytes - 20, 20));
84
+ const typed = yield* openTypes(input.bucket, stored, ranges.count, checksum);
85
+ const reader = readersOf(input)();
86
+ while (rank < ranges.count && roomFor(calls, 3)) {
87
+ const length = Math.min(rebuildWindowRanks, ranges.count - rank);
88
+ const ids = yield* ranges.ids(rank, length);
89
+ const offsets = yield* ranges.offsets(rank, length);
90
+ const types = yield* typed.types(rank, length);
91
+ let at = 0;
92
+ for (; at < length; at += 1) {
93
+ if (typeOfByte(types[at] ?? 0) !== "commit") continue;
94
+ if (!roomFor(calls)) break;
95
+ const oid = hexOf(ids.subarray(at * 20, at * 20 + 20));
96
+ const object = yield* reader.wholeAt.inRanges(oid, ranges, offsets[at] ?? 0);
97
+ const ofCommit = (yield* Effect.fromResult(linksOf(object))).slice(1);
98
+ if (ofCommit.length > 4096) return yield* Effect.fail(gitError("DATA_LOSS", `Commit ${oid} has ${ofCommit.length} parents, past ${mostParents}`));
99
+ const chunk = new Uint8Array(headBytes + ofCommit.length * 20);
100
+ chunk.set(ids.subarray(at * 20, at * 20 + 20), 0);
101
+ new DataView(chunk.buffer).setUint32(20, ofCommit.length);
102
+ for (const [place, link] of ofCommit.entries()) chunk.set(oidBytes(link.oid), headBytes + place * 20);
103
+ chunks.push(chunk);
104
+ commits += 1;
105
+ parents += ofCommit.length;
106
+ }
107
+ rank += at;
108
+ if (at < length) break;
109
+ }
110
+ return {
111
+ chunks,
112
+ cursor: {
113
+ ...cursor,
114
+ rank,
115
+ commits,
116
+ parents
117
+ }
118
+ };
119
+ });
120
+ /** Each of `cursor`'s parts, read back in order, or `undefined` when one is missing. */
121
+ const readParts = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, cursor) {
122
+ const parts = [];
123
+ for (const key of partKeys(pack, cursor.first, cursor.first + cursor.parts)) {
124
+ const bytes = yield* readWhole(input.bucket, key);
125
+ if (bytes === void 0) return void 0;
126
+ parts.push(bytes);
127
+ }
128
+ return parts;
129
+ });
130
+ /** The `.graph` of `cursor`'s parts, read back in order, or `undefined` when one is missing. */
131
+ const joinedGraph = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, cursor) {
132
+ const graph = sortedGraph(cursor.commits, cursor.parents);
133
+ for (const key of partKeys(pack, cursor.first, cursor.first + cursor.parts)) {
134
+ const bytes = yield* readWhole(input.bucket, key);
135
+ if (bytes === void 0) return void 0;
136
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
137
+ let at = 0;
138
+ while (at < bytes.byteLength) {
139
+ const count = view.getUint32(at + 20);
140
+ graph.commit(bytes, at);
141
+ at += headBytes;
142
+ for (let each = 0; each < count; each += 1, at += 20) graph.parent(bytes, at);
143
+ }
144
+ }
145
+ return graph.finish();
146
+ });
147
+ /**
148
+ * Whether a step that reads all of `cursor`'s parts, deletes `swept` keys, then deletes and puts
149
+ * `bytes` bytes and drops `dropped` keys, fits `calls`, past the reserve.
150
+ */
151
+ const finishing = (input, cursor, calls, swept, bytes, dropped) => {
152
+ const { multipart, deleteBatch } = input.bucket;
153
+ const forecast = swept + cursor.parts + deleteCharge(deleteBatch, 1) + sizedPutCalls(multipart, bytes) + (dropped === 0 ? 0 : dropRunsCalls(dropped, deleteBatch));
154
+ return roomFor(calls, forecast);
155
+ };
156
+ /** The step that marks `pack`'s rebuild failed, so it stays fenced and none runs again. */
157
+ const failed = (pack, row, why) => Effect.as(Effect.logWarning(`pack ${pack} stays fenced: its .graph can't be rebuilt (${why})`), {
158
+ change: {
159
+ put: [rowOf(pack, row, { rebuilt: "failed" })],
160
+ rows: noRows
161
+ },
162
+ more: true
163
+ });
164
+ /**
165
+ * One step of the rebuild of the first graph-fenced pack of `packs`, or `undefined` when there's
166
+ * none: its part put and its cursor saved; with
167
+ * `rebuildPartsMost` parts, those put again as one; or at its end the `.graph` put and its pack's
168
+ * row committed with the `refused` row's delete. A pack whose commits can't be read, or whose step
169
+ * has no room for its reads, stays fenced, marked so none rebuilds it again.
170
+ */
171
+ const rebuildStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, refused, calls) {
172
+ const pack = rebuildable(input.listed.packs, refused);
173
+ if (pack === void 0 || !isPackId(pack.id)) return void 0;
174
+ const id = pack.id;
175
+ const row = refused.get(id);
176
+ const cursor = row.rebuild ?? started;
177
+ const stale = partKeys(id, cursor.swept, cursor.first);
178
+ const sweep = deleteCharge(input.bucket.deleteBatch, stale.length);
179
+ const held = headBytes * cursor.commits + 20 * cursor.parents;
180
+ if (cursor.rank < pack.objects && cursor.parts < 16) {
181
+ if (!roomFor(calls, sweep + 4 + 3)) return yield* failed(id, row, `its step has no room to open it`);
182
+ yield* bucketDeleteMany(input.bucket, stale);
183
+ const read = yield* readPart(input, {
184
+ ...pack,
185
+ id
186
+ }, cursor, calls).pipe(Effect.map((part) => ({ part })), Effect.catchIf((error) => error.code === "DATA_LOSS", (error) => Effect.succeed({ lost: error.message })));
187
+ if ("lost" in read) return yield* failed(id, row, read.lost);
188
+ const { chunks, cursor: next } = read.part;
189
+ if (next.rank === cursor.rank) return yield* failed(id, row, `its step's calls read no window past opening it`);
190
+ const swept = {
191
+ ...next,
192
+ swept: cursor.first
193
+ };
194
+ if (chunks.length === 0) return {
195
+ change: {
196
+ put: [rowOf(id, row, { rebuild: swept })],
197
+ rows: noRows
198
+ },
199
+ more: true
200
+ };
201
+ const part = runKey(id, "graph", cursor.first + cursor.parts);
202
+ yield* bucketDeleteMany(input.bucket, [part]);
203
+ yield* bucketPut(input.bucket, part, chunks);
204
+ return {
205
+ change: {
206
+ put: [rowOf(id, row, { rebuild: {
207
+ ...swept,
208
+ parts: cursor.parts + 1
209
+ } })],
210
+ rows: noRows
211
+ },
212
+ more: true
213
+ };
214
+ }
215
+ if (cursor.rank < pack.objects) {
216
+ if (!finishing(input, cursor, calls, sweep, held, 0)) return yield* failed(id, row, `its parts take past a step's calls`);
217
+ yield* bucketDeleteMany(input.bucket, stale);
218
+ const rebuild = (yield* Effect.acquireUseRelease(input.allotment.grow(held, upkeepTooLarge), () => Effect.flatMap(readParts(input, id, cursor), (read) => {
219
+ if (read === void 0) return Effect.succeed(false);
220
+ const one = runKey(id, "graph", cursor.first + cursor.parts);
221
+ return Effect.as(Effect.andThen(bucketDeleteMany(input.bucket, [one]), bucketPut(input.bucket, one, read)), true);
222
+ }), () => Effect.sync(() => input.allotment.shrink(held)))) ? {
223
+ ...cursor,
224
+ first: cursor.first + cursor.parts,
225
+ parts: 1,
226
+ swept: cursor.first
227
+ } : started;
228
+ return {
229
+ change: {
230
+ put: [rowOf(id, row, { rebuild })],
231
+ rows: noRows
232
+ },
233
+ more: true
234
+ };
235
+ }
236
+ const bytes = graphBytes(cursor.commits, cursor.parents);
237
+ const dropped = cursor.first + cursor.parts - cursor.swept;
238
+ if (!finishing(input, cursor, calls, 0, bytes, dropped)) return yield* failed(id, row, `its .graph takes past a step's calls`);
239
+ const graph = yield* Effect.acquireUseRelease(input.allotment.grow(bytes + held, upkeepTooLarge), () => joinedGraph(input, id, cursor), () => Effect.sync(() => input.allotment.shrink(bytes + held)));
240
+ if (graph === void 0) return {
241
+ change: {
242
+ put: [rowOf(id, row, { rebuild: started })],
243
+ rows: noRows
244
+ },
245
+ more: true
246
+ };
247
+ yield* bucketDeleteMany(input.bucket, [packFiles(id).graph]);
248
+ yield* bucketPut(input.bucket, packFiles(id).graph, graph);
249
+ yield* dropRuns(input.bucket, id);
250
+ return {
251
+ change: {
252
+ put: [packRow({
253
+ ...pack,
254
+ graphBytes: graph.byteLength
255
+ })],
256
+ delete: [refusedKey(id)],
257
+ rows: noRows
258
+ },
259
+ more: true
260
+ };
261
+ });
262
+ export { rebuildStep, rebuildWindowRanks, rebuildable };