@ref0/git 0.8.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 (94) hide show
  1. package/dist/contracts/calls-spent.d.mts +2 -12
  2. package/dist/contracts/calls-spent.mjs +4 -5
  3. package/dist/contracts/events.d.mts +70 -4
  4. package/dist/contracts/events.mjs +27 -3
  5. package/dist/contracts/git.d.mts +13 -3
  6. package/dist/contracts/objects.d.mts +18 -0
  7. package/dist/contracts/queue.d.mts +3 -2
  8. package/dist/contracts/queue.mjs +4 -2
  9. package/dist/core/ancestry.mjs +5 -4
  10. package/dist/core/index-job.mjs +23 -1
  11. package/dist/core/index-lost.d.mts +11 -0
  12. package/dist/core/index-lost.mjs +55 -0
  13. package/dist/core/objects/commit-writes.mjs +1 -1
  14. package/dist/core/objects/commits.mjs +10 -9
  15. package/dist/core/objects/merges.mjs +1 -1
  16. package/dist/core/objects/reading.mjs +28 -13
  17. package/dist/core/objects/trees.mjs +1 -1
  18. package/dist/core/parts.d.mts +7 -0
  19. package/dist/core/publish.mjs +9 -5
  20. package/dist/core/purge.mjs +16 -3
  21. package/dist/core/push.mjs +27 -11
  22. package/dist/core/repack.mjs +36 -14
  23. package/dist/core/view.d.mts +10 -1
  24. package/dist/core/view.mjs +15 -6
  25. package/dist/effect.d.mts +2 -3
  26. package/dist/effect.mjs +2 -3
  27. package/dist/engine/commits.mjs +4 -3
  28. package/dist/engine/merge-bases.mjs +5 -3
  29. package/dist/engine/merge.mjs +4 -3
  30. package/dist/engine/parts.d.mts +1 -0
  31. package/dist/engine/parts.mjs +1 -1
  32. package/dist/engine/walk.mjs +15 -11
  33. package/dist/http/core-parts.mjs +17 -8
  34. package/dist/index.d.mts +2 -2
  35. package/dist/lfs/objects.mjs +7 -4
  36. package/dist/lfs/upkeep.mjs +6 -5
  37. package/dist/lfs/upload-most.mjs +7 -1
  38. package/dist/protocol/bytes/streams.mjs +84 -2
  39. package/dist/protocol/diff/read.d.mts +1 -0
  40. package/dist/protocol/diff/read.mjs +5 -2
  41. package/dist/protocol/objects/commit.d.mts +7 -0
  42. package/dist/protocol/objects/commit.mjs +5 -1
  43. package/dist/queue/advance.mjs +39 -10
  44. package/dist/queue/host.d.mts +4 -0
  45. package/dist/queue/layer.mjs +4 -2
  46. package/dist/queue/limits.mjs +18 -2
  47. package/dist/queue/rows.mjs +2 -1
  48. package/dist/queue/trim.mjs +2 -2
  49. package/dist/rest/commits.d.mts +238 -238
  50. package/dist/rest/forks.d.mts +71 -71
  51. package/dist/rest/refs.d.mts +143 -143
  52. package/dist/rest/repos.d.mts +81 -81
  53. package/dist/rest/topics.d.mts +112 -112
  54. package/dist/rest/trees.d.mts +77 -77
  55. package/dist/rest/wire.d.mts +19 -1
  56. package/dist/rest/work.d.mts +39 -39
  57. package/dist/server/joined.d.mts +11 -5
  58. package/dist/server/joined.mjs +3 -2
  59. package/dist/server/registry.mjs +11 -5
  60. package/dist/server/server.mjs +16 -4
  61. package/dist/storage/index-bitmaps.mjs +16 -10
  62. package/dist/storage/index-build.mjs +61 -13
  63. package/dist/storage/index-graph.d.mts +1 -0
  64. package/dist/storage/index-graph.mjs +29 -5
  65. package/dist/storage/index-layers.d.mts +1 -0
  66. package/dist/storage/index-layers.mjs +5 -2
  67. package/dist/storage/index-reach.mjs +7 -5
  68. package/dist/storage/index-remap.mjs +5 -5
  69. package/dist/storage/index-visible.mjs +16 -5
  70. package/dist/storage/links.mjs +3 -3
  71. package/dist/storage/pack-order.d.mts +1 -0
  72. package/dist/storage/pack-order.mjs +18 -1
  73. package/dist/storage/prune-walk.mjs +5 -2
  74. package/dist/storage/prune.mjs +107 -37
  75. package/dist/storage/receive-bounds.mjs +3 -2
  76. package/dist/storage/visible.mjs +3 -2
  77. package/dist/storage/walk.d.mts +1 -0
  78. package/dist/storage/walk.mjs +9 -5
  79. package/dist/storage/wants.mjs +17 -11
  80. package/dist/store/call-count.d.mts +8 -0
  81. package/dist/store/call-count.mjs +15 -7
  82. package/dist/store/errors.d.mts +7 -1
  83. package/dist/store/errors.mjs +7 -1
  84. package/dist/store/job-try.mjs +3 -1
  85. package/dist/store/records.mjs +17 -2
  86. package/dist/store/repo-record.mjs +9 -2
  87. package/dist/store/scopes.mjs +10 -2
  88. package/dist/sync/bound.d.mts +1 -1
  89. package/dist/sync/import.mjs +1 -1
  90. package/dist/sync/layer.mjs +4 -7
  91. package/dist/sync/mirror.mjs +1 -1
  92. package/dist/topics/advance.mjs +4 -4
  93. package/dist/topics/layer.mjs +1 -1
  94. package/package.json +3 -3
@@ -3,6 +3,7 @@ import { joinedBytes } from "../protocol/bytes/joined.mjs";
3
3
  import { streamOf } from "../protocol/bytes/streams.mjs";
4
4
  import { bytesOf, keyOf } from "../protocol/diff/paths.mjs";
5
5
  import { DiffReader } from "../protocol/diff/read.mjs";
6
+ import { noRepoRoots } from "../protocol/objects/commit.mjs";
6
7
  import { isTreeMode, objectId } from "../protocol/objects/object.mjs";
7
8
  import { compareEntries, treeBytes } from "../protocol/objects/tree.mjs";
8
9
  import { attributesFor, parseAttributes, parsedBytes, pathAttributesOf, refusedAttribute } from "./attributes.mjs";
@@ -1069,9 +1070,9 @@ const basesRoot = /* @__PURE__ */ Effect.fnUntraced(function* (call, input, attr
1069
1070
  * `base`, `ours` and `theirs`, each a tree or what peels to one, merged: a tree, or a conflict.
1070
1071
  * Without `base`, two commits merge over their merge bases. `load` gives xdiff for the merge's
1071
1072
  * scope, loaded once the first file's content merges. A `step` of a longer call reads within that
1072
- * call's tally and deadline.
1073
+ * call's tally and deadline. The merge bases' walk sees each of `repoRoots` as having no parents.
1073
1074
  */
1074
- const mergeTrees = (read, input, load, step) => Effect.scoped(Effect.gen(function* () {
1075
+ const mergeTrees = (read, input, load, step, repoRoots = noRepoRoots) => Effect.scoped(Effect.gen(function* () {
1075
1076
  const limits = yield* limitsOf(input.limits);
1076
1077
  const scope = yield* Effect.scope;
1077
1078
  const xdiff = yield* Effect.cached(Effect.provideService(load, Scope.Scope, scope));
@@ -1079,7 +1080,7 @@ const mergeTrees = (read, input, load, step) => Effect.scoped(Effect.gen(functio
1079
1080
  const run = Effect.gen(function* () {
1080
1081
  const known = /* @__PURE__ */ new Map();
1081
1082
  const call = {
1082
- reader: new DiffReader(knownFirst(known, readThrough(read, deadline)), limits.reads, step?.tally),
1083
+ reader: new DiffReader(knownFirst(known, readThrough(read, deadline)), limits.reads, step?.tally, void 0, repoRoots),
1083
1084
  xdiff,
1084
1085
  deadline,
1085
1086
  known,
@@ -3,6 +3,7 @@ import "../contracts/objects.mjs";
3
3
  import "../contracts/result.mjs";
4
4
  import "../protocol/diff/patch.mjs";
5
5
  import "../protocol/diff/tree-diff.mjs";
6
+ import "../protocol/objects/commit.mjs";
6
7
  import "./reads.mjs";
7
8
  import "./xdiff.mjs";
8
9
  import "effect/Effect";
@@ -32,7 +32,7 @@ const refusedAs = (run) => (one, two) => Effect.catch(run(one, two), (error) =>
32
32
  const mergeParts = (load) => {
33
33
  const allotted = (allot) => Effect.flatMap(allot, (allotment) => loadAllotted(load, allotment, xdiffTooLarge));
34
34
  return {
35
- mergeTrees: (read, input, allot, call) => mergeTrees(read, input, allotted(allot), call),
35
+ mergeTrees: (read, input, allot, call, roots) => mergeTrees(read, input, allotted(allot), call, roots),
36
36
  lineDiff: (allot) => Effect.map(allotted(allot), (xdiff) => ({
37
37
  lines: refusedAs(xdiffLines(xdiff, "myers")),
38
38
  patcher: refusedAs(xdiffPatcher(xdiff, "myers"))
@@ -1,6 +1,7 @@
1
1
  import { fail } from "../contracts/result.mjs";
2
2
  import { entryAt, pathParts } from "../protocol/diff/paths.mjs";
3
3
  import { DiffReader } from "../protocol/diff/read.mjs";
4
+ import { noRepoRoots } from "../protocol/objects/commit.mjs";
4
5
  import { commitAt, namedCommit, timeOf } from "./commits.mjs";
5
6
  import { fromDiff } from "./failures.mjs";
6
7
  import { badCursor, inputDigest, limitOf, limitsOf, readThrough, stepDeadline, timed } from "./reads.mjs";
@@ -182,8 +183,11 @@ const started = /* @__PURE__ */ Effect.fnUntraced(function* (reader, wants, have
182
183
  }
183
184
  return walk;
184
185
  });
185
- /** `rev-list <wants> ^<haves>`, a page at a time. */
186
- const walkHistory = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, call) {
186
+ /**
187
+ * `rev-list <wants> ^<haves>`, a page at a time. Each walk here sees each of `roots` as having no
188
+ * parents, as Git's shallow grafts make a repo's roots.
189
+ */
190
+ const walkHistory = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, call, roots = noRepoRoots) {
187
191
  const haves = input.haves ?? [];
188
192
  if (input.wants.length === 0) return yield* fail("INVALID_ARGUMENT", "A walk needs a want");
189
193
  const digest = yield* inputDigest([
@@ -192,16 +196,16 @@ const walkHistory = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, ca
192
196
  "^",
193
197
  ...haves
194
198
  ]);
195
- return yield* paged(read, input, digest, (walk, take) => (haves.length > 0 ? limited : unlimited)(walk, take), call);
199
+ return yield* paged(read, input, digest, (walk, take) => (haves.length > 0 ? limited : unlimited)(walk, take), call, roots);
196
200
  });
197
201
  /** `rev-list --count <wants> ^<haves>`: how many commits the walk lists, within its limits. */
198
- const countHistory = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, call) {
202
+ const countHistory = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, call, roots = noRepoRoots) {
199
203
  const limits = yield* limitsOf(input.limits);
200
204
  const haves = input.haves ?? [];
201
205
  const deadline = yield* stepDeadline(limits.milliseconds, "walk-limit", call);
202
206
  let count = 0;
203
207
  const run = Effect.gen(function* () {
204
- const reader = new DiffReader(readThrough(read, deadline), limits.reads, call?.tally);
208
+ const reader = new DiffReader(readThrough(read, deadline), limits.reads, call?.tally, void 0, roots);
205
209
  const walk = yield* started(reader, input.wants, haves);
206
210
  yield* (haves.length > 0 ? limited : unlimited)(walk, () => {
207
211
  count += 1;
@@ -215,13 +219,13 @@ const countHistory = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, c
215
219
  * `rev-list --max-count=<most> <wants> ^<haves>`: the first `most` commits the walk lists, in one
216
220
  * walk within its limits, for a caller that reads them all, where each page would walk again.
217
221
  */
218
- const historyUpTo = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, most, call) {
222
+ const historyUpTo = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, most, call, roots = noRepoRoots) {
219
223
  const limits = yield* limitsOf(input.limits);
220
224
  const haves = input.haves ?? [];
221
225
  const deadline = yield* stepDeadline(limits.milliseconds, "walk-limit", call);
222
226
  const commits = [];
223
227
  const run = Effect.gen(function* () {
224
- const reader = new DiffReader(readThrough(read, deadline), limits.reads, call?.tally);
228
+ const reader = new DiffReader(readThrough(read, deadline), limits.reads, call?.tally, void 0, roots);
225
229
  const walk = yield* started(reader, input.wants, haves);
226
230
  yield* (haves.length > 0 ? limited : unlimited)(walk, (commit) => {
227
231
  if (commits.length === most) return false;
@@ -238,7 +242,7 @@ const historyUpTo = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, mo
238
242
  * `path`, a root when `path` is absent from it; a merge TREESAME to a parent is followed only
239
243
  * through the first such parent, and one TREESAME to none through every parent.
240
244
  */
241
- const walkPath = /* @__PURE__ */ Effect.fnUntraced(function* (read, input) {
245
+ const walkPath = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, roots = noRepoRoots) {
242
246
  const parts = pathParts(input.path);
243
247
  if (parts === void 0) return yield* fail("INVALID_ARGUMENT", `'${input.path}' isn't a path`);
244
248
  const digest = yield* inputDigest([
@@ -249,7 +253,7 @@ const walkPath = /* @__PURE__ */ Effect.fnUntraced(function* (read, input) {
249
253
  return yield* paged(read, {
250
254
  ...input,
251
255
  wants: [input.want]
252
- }, digest, (walk, take) => simplified(walk, parts, take));
256
+ }, digest, (walk, take) => simplified(walk, parts, take), void 0, roots);
253
257
  });
254
258
  /** The walk without `haves`, each commit's parents simplified at `parts` as `walkPath` says. */
255
259
  const simplified = /* @__PURE__ */ Effect.fnUntraced(function* (walk, parts, take) {
@@ -285,7 +289,7 @@ const simplified = /* @__PURE__ */ Effect.fnUntraced(function* (walk, parts, tak
285
289
  * page, within the call's limits, and lists after its cursor's commit, so a cursor holds the
286
290
  * input's digest and that commit.
287
291
  */
288
- const paged = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, digest, run, call) {
292
+ const paged = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, digest, run, call, roots) {
289
293
  const limits = yield* limitsOf(input.limits);
290
294
  const limit = yield* limitOf(input.page);
291
295
  const after = yield* afterOf(input.page?.after, digest);
@@ -306,7 +310,7 @@ const paged = /* @__PURE__ */ Effect.fnUntraced(function* (read, input, digest,
306
310
  };
307
311
  const deadline = yield* stepDeadline(limits.milliseconds, "walk-limit", call);
308
312
  const walked = Effect.gen(function* () {
309
- const reader = new DiffReader(readThrough(read, deadline), limits.reads, call?.tally);
313
+ const reader = new DiffReader(readThrough(read, deadline), limits.reads, call?.tally, void 0, roots);
310
314
  yield* run(yield* started(reader, input.wants, input.haves ?? []), take);
311
315
  });
312
316
  yield* timed(walked, deadline);
@@ -15,8 +15,8 @@ import { answerSpent, decodeRow } from "../store/errors.mjs";
15
15
  import { refPageRows, storedPeel } from "../store/ref-rows.mjs";
16
16
  import { decodePacks } from "../store/git-store.mjs";
17
17
  import { ReachedMark, markHolds } from "../store/records.mjs";
18
- import { readRecord } from "../store/repo-record.mjs";
19
- import { collections, reachedKey } from "../store/scopes.mjs";
18
+ import { readRecord, rootsOf } from "../store/repo-record.mjs";
19
+ import { collections, reachedKey, repoRootsKey } from "../store/scopes.mjs";
20
20
  import { fetchReaches, hiddenUnder } from "../protocol/wire/lines.mjs";
21
21
  import { read } from "../core/objects/objects.mjs";
22
22
  import * as Effect from "effect/Effect";
@@ -114,12 +114,14 @@ const coreHttpParts = (parts, options = {}) => {
114
114
  refsRead,
115
115
  packsRead,
116
116
  indexRowKey,
117
- reachedKey
117
+ reachedKey,
118
+ repoRootsKey
118
119
  ]);
119
120
  const { record, snapshot } = read$1;
120
121
  if (record === void 0 || record.deleted === true) return yield* fail("NOT_FOUND", `No repo '${operation.repo}'`);
121
- const [, refRows = [], packRows = [], indexRows = [], markRows = []] = snapshot.results;
122
+ const [, refRows = [], packRows = [], indexRows = [], markRows = [], rootRows] = snapshot.results;
122
123
  const packs = yield* decodePacks(packRows);
124
+ const roots = yield* rootsOf(rootRows);
123
125
  const listed = {
124
126
  repo: resolved.internalId,
125
127
  version: snapshot.version,
@@ -134,13 +136,17 @@ const coreHttpParts = (parts, options = {}) => {
134
136
  listed,
135
137
  refs: seen,
136
138
  refRows,
137
- index: row
139
+ index: row,
140
+ roots
138
141
  }
139
142
  });
140
143
  const objects = objectsFace(viewed);
144
+ const [stored] = indexRows;
145
+ const lost = stored === void 0 ? void 0 : core.indexLost?.(resolved.internalId, stored, listed);
141
146
  const index = viewed.index === void 0 ? void 0 : {
142
147
  calls: viewed.index,
143
- row
148
+ row,
149
+ ...lost !== void 0 && { lost }
144
150
  };
145
151
  const refs = peel ? yield* advertised(refRows, seen) : [...seen].map(([name, oid]) => ({
146
152
  name,
@@ -163,13 +169,15 @@ const coreHttpParts = (parts, options = {}) => {
163
169
  refs: served,
164
170
  objects,
165
171
  whole,
166
- seesAll
172
+ seesAll,
173
+ roots
167
174
  } : {
168
175
  listed,
169
176
  refs: served,
170
177
  objects,
171
178
  whole,
172
179
  seesAll,
180
+ roots,
173
181
  index
174
182
  };
175
183
  });
@@ -277,7 +285,8 @@ const coreHttpParts = (parts, options = {}) => {
277
285
  listed: at.listed,
278
286
  tips,
279
287
  wants: request.wants,
280
- signal
288
+ signal,
289
+ roots: at.roots
281
290
  };
282
291
  if (at.index !== void 0) input.index = at.index;
283
292
  const missing = yield* unreachableWant(input);
package/dist/index.d.mts CHANGED
@@ -22,7 +22,7 @@ import "./lfs/namespace.mjs";
22
22
  import { QueueInternals, mergeQueue } from "./queue/host.mjs";
23
23
  import { CommitCalls, CommitCreateInput, CommitDiffInput, Compare, CompareInput, ComparisonFile, LineCounts, LogInput, RefPublication, Revision, commits_d_exports } from "./contracts/commits.mjs";
24
24
  import { Commit, DiffListing, MergeBaseInput, MergeBases, MergeLabels, MergeTree, ObjectWrite, ObjectWrites, PathObject, ReadOptions, ReadPage, RenamesSkipped, Signature, Tag, TagFields, TreeChange, TreeChanges, TreeDiffInput, TreeMergeInput, WalkInput } from "./contracts/engine.mjs";
25
- import { BeforeAfter, CandidateClosed, CandidateClosedFields, CandidateOpened, CandidateReported, EntryAdded, EntryFailed, EntryMerged, EntryRemoved, EntryRetried, EventEnvelope, EventFeature, FeedItem, FenceReason, FencedPack, GitEvent, HoldEvent, HoldEventFields, IndexRefusal, QueueEvent, QueueRestarted, RefPush, RefUpdated, RepoCreated, RepoDeletedEvent, RepoEnvelope, RepoEvent, RepoIndexRefused, RepoJobFailed, RepoMaintained, RepoRenamed, RepoVisibilityChanged, RepoWorkFailed, TokenEvent, TokenEventFields, TopicAdded, TopicEnvelope, TopicEvent, TopicFailed, TopicMerged, TopicOpened, TopicRemoved, TopicReported, TopicWorkFailed, events_d_exports } from "./contracts/events.mjs";
25
+ import { BeforeAfter, CandidateClosed, CandidateClosedFields, CandidateOpened, CandidateReported, EntryAdded, EntryFailed, EntryMerged, EntryRemoved, EntryRetried, EventEnvelope, EventFeature, FeedItem, FenceReason, FencedPack, GitEvent, HoldEvent, HoldEventFields, IndexRefusal, QueueEvent, QueueRestarted, RefPush, RefUpdated, RepoCreated, RepoDeletedEvent, RepoEnvelope, RepoEvent, RepoIndexRefused, RepoJobFailed, RepoMaintained, RepoPruneRefused, RepoRenamed, RepoVisibilityChanged, RepoWorkFailed, TokenEvent, TokenEventFields, TopicAdded, TopicEnvelope, TopicEvent, TopicFailed, TopicMerged, TopicOpened, TopicRemoved, TopicReported, TopicWorkFailed, events_d_exports } from "./contracts/events.mjs";
26
26
  import { File, FileCalls, FileDiff, FileReadInput, FilesDiffInput, FilesListInput, FilesRead, files_d_exports } from "./contracts/files.mjs";
27
27
  import { ForkCalls, ForkCreateInput, ForkFetched, ForkGetInput, ForkHolder, ForkListInput, forks_d_exports } from "./contracts/forks.mjs";
28
28
  import { LfsCalls, LfsFeature, LfsGetInput, LfsObject, LfsOptions } from "./contracts/lfs.mjs";
@@ -87,4 +87,4 @@ import { PushHookInput } from "./contracts/git-hooks.mjs";
87
87
  import { public_d_exports as public_d_exports$5 } from "./signin/public.mjs";
88
88
  import "./signin/namespace.mjs";
89
89
  import { jobStates } from "@ref0/infra";
90
- export { type Accepted, type AccessOption, type Acting, type Actor, type ActorId, type ActorInput, type AddResult, type Added, type Allotment, type AnonymousActor, type ApprovalBase, type ApprovalDecision, type ApprovalPageContext, type ApprovalPageInput, type ApprovalPrompt, type ApprovedGrant, auth_namespace_d_exports as Auth, type AuthInput, authorize_d_exports as Authorize, type AuthorizeAnswer, type AuthorizeInput, type Awaitable, type BasicCredential, type BatchOptions, type BearerCredential, type BeforeAfter, BeginPushUpload, type Bisect, type Blob, type BlobCalls, type BlobCreateInput, BlobLimit, BlobNone, blobs_d_exports as Blobs, type BypassOperation, type Bytes, type CallInput, type Caller, type CallerGrant, type Candidate, type CandidateCloseReason, type CandidateClosed, type CandidateClosedFields, type CandidateId, type CandidateOpened, type CandidateReportInput, type CandidateReported, type CandidateResult, type CandidateState, type CandidatesResult, type ClientAdapter, type ClientCredential, type ClientCredentials, type ClientFetchInput, type ClientFetchResult, type ClientPushInput, type Commit, type CommitCalls, type CommitCreateInput, type CommitDiffInput, commits_d_exports as Commits, type Compare, type CompareInput, type ComparisonFile, type ConfirmApprovalPage, ContextValue, type CopyRow, type CopyRowsInput, type CopyRowsPage, type CreatedObject, type CreatedToken, type CredentialInput, type Credentials, type CredentialsBasic, type CredentialsBearer, DataLossContext, DataLossReason, type DecisionAnswer, type DeniedGrant, type DeviceApproval, type DeviceCodePage, type DeviceCodeRequest, type DeviceCodeResponse, type DeviceExchange, type DiffListing, type EffectiveLimits, type Entry, type EntryAdded, type EntryFailed, type EntryFailureReason, type EntryFields, type EntryGroups, type EntryHoldInput, type EntryHoldsInput, type EntryId, type EntryMerged, type EntryRemoved, type EntryResult, type EntryRetried, type EntryState, ErrorContext, type EventEnvelope, type EventFeature, event_streams_d_exports as EventStreams, events_d_exports as Events, ExistingContext, ExistingReason, type FailureResult, type FeedItem, type FenceReason, type FencedPack, type FetchAdjustment, type FetchAnswer, type FetchReadInput, type FetchReadTarget, FetchRequest, type FetchRule, type FetchRuleInput, type File, type FileCalls, type FileDiff, type FileReadInput, type FileRuleOptions, files_d_exports as Files, type FilesAllowOperation, type FilesDiffInput, type FilesListInput, type FilesRead, Filter, FinishPushUpload, type ForkCalls, type ForkCreateInput, type ForkFetched, type ForkGetInput, type ForkHolder, type ForkListInput, type ForkOperation, forks_d_exports as Forks, git_namespace_d_exports as Git, type GitAdapter, type GitAuth, type GitAuthorize, client_d_exports as GitClient, type GitClientCalls, type GitClientOptions, type GitError, GitErrorBody, type GitErrorCode, type GitErrorContexts, type GitErrorFields, type GitErrorInput, type GitErrorTagged, type GitEvent, git_events_d_exports as GitEvents, public_d_exports as GitHooks, type GitNeeds, type GitObject, type GitObjects, type GitScope, type GitServer, type GitServerOptions, type GitStore, type GitStoreAddInput, type GitStoreCommitInput, type GitStoreReadInput, type Grant, type GrantAgainInput, type GrantAgainRequest, type GrantInput, type GrantReachInput, type GrantResolver, type GrantScope, type HandlerOptions, type Held, type HeldPack, type HiddenSpan, type Hold, type HoldEvent, type HoldEventFields, type HoldFields, type HoldId, type HoldResult, type Holding, type HoldingsInput, type HoldingsWalked, type HoldsResult, HostErrorContext, type HostFunctionName, type ImportState, type IndexCalls, type IndexReachInput, type IndexReached, type IndexRefusal, type IndexStatus, type IndexTip, type IndexTry, type IndexTryInput, InternalRepoId, InvalidInputContext, InvalidInputReason, type JoinInput, type Judged, type LanesInput, public_d_exports$1 as Lfs, type LfsCalls, type LfsFeature, type LfsGetInput, type LfsObject, type LfsOptions, type LfsPointers, type LfsPointersBuilder, type LineCounts, type LinkedObjects, type Listed, type ListedInput, type ListenInput, type Localize, type LogInput, type MaintainInput, type Me, type MeOperation, type MergeAnswer, type MergeBaseInput, type MergeBases, type MergeCalls, type MergeCreateInput, type MergeInput, type MergeLabels, type MergeMethod, type MergePlan, public_d_exports$2 as MergeQueue, type MergeQueueCalls, type MergeQueueLayerOptions, type MergeQueueOptions, type MergeTree, public_d_exports$3 as Merges, type MetaValue, MissingContext, MissingReason, type NamedActor, NotAllowedContext, NotAllowedReason, type OAuthClient, type OAuthError, type OAuthTokenResponse, type ObjectHeader, type ObjectHeadersInput, type ObjectInput, type ObjectReadInput, type ObjectReadResult, type ObjectReader, type ObjectReaderInput, type ObjectSizesInput, type ObjectType, type ObjectWrite, type ObjectWrites, objects_namespace_d_exports as Objects, type ObjectsChange, type ObjectsFactory, type ObjectsFetchInput, type ObjectsOpenInput, type ObjectsRead, type ObjectsReadInput, type ObjectsStarting, type ObjectsStartingInput, type ObjectsStep, type Oid, type Operation, type OperationKind, type Option, type Pack, type PacksMemory, type PacksOptions, type PagedInput, type PathObject, type PeelInput, type Peeled, type PinnedRepo, policy_d_exports as Policy, PreconditionContext, PreconditionReason, type PrefixTarget, type Prepare, type PrepareInput, type PreviousQueueSchedule, public_d_exports$4 as PrivateRefs, type ProtectOptions, type ProvidedBy, type PushContext, type PushFacts, type PushHookInput, type PushOperation, type PushOptions, type PushRule, type PushRuleInput, type PushUploadOptions, PushUploadPart, PushUploadStarted, type PushedCommit, type PushedCommitsInput, type Quarantine, type QueueAddInput, type QueueAddOperation, type QueueCandidateOperation, type QueueEntryOperation, type QueueEvent, type QueueFailureCounts, type QueueInternals, type QueueKeys, type QueueListInput, type QueueListResult, type QueueMeta, type QueueOf, type QueueRecent, type QueueReleaseOperation, type QueueRestarted, type QueueTargetInput, type QueueTargetOperation, type QueueView, type ReadLimits, type ReadObject, type ReadObjects, type ReadOptions, type ReadPage, type ReceiveInput, type Ref, type RefAudience, type RefCalls, type RefCount, type RefCountInput, type RefEdit, type RefForced, type RefInput, type RefListInput, type RefName, type RefPatterns, type RefProtection, type RefPublication, type RefPush, type RefSource, type RefUpdate, type RefUpdateKind, type RefUpdated, type RefView, refs_d_exports as Refs, type RefsPrivateOperation, type RefsUpdateInput, type RefsUpdated, type RefusalReason, type RejectInput, type Rejected, type ReleaseResult, type Released, type RemoteCalls, type RemoteOptions, type RemoteRefsInput, type RemoveResult, type Removed, type RenamesSkipped, type RepackOptions, type RepoAccess, type RepoCalls, type RepoCatalogueEntry, type RepoCreateInput, type RepoCreated, type RepoDeleted, type RepoDeletedEvent, type RepoEnvelope, type RepoEvent, type RepoGetInput, type RepoIndexHold, type RepoIndexRefused, type RepoInfo, type RepoInfoStats, type RepoInput, type RepoJobFailed, type RepoListInput, type RepoListOperation, type RepoListOrder, type RepoMaintained, type RepoName, type RepoOperation, type RepoRecord, repo_records_d_exports as RepoRecords, type RepoRenameInput, type RepoRenamed, type RepoStats, type RepoStreamEvent, type RepoUpdateInput, type RepoVisibilityChanged, type RepoWork, type RepoWorkFailed, type Report, type ReportDetails, type ReportOptions, type ReportResult, type Reported, repos_d_exports as Repos, ResourceContext, ResourceReason, layer_d_exports as Rest, client_d_exports$1 as RestClient, type RestClientCalls, type RestEvents, type RestTokenCalls, type RestartResult, type Restarted, type Result, type Retried, type RetryResult, type Revision, type RowsMoved, type RuleOperation, rules_d_exports as Rules, saved_callers_public_d_exports as SavedCallers, type SavedHandlerOptions, type ScheduleOption, type ServerCalls, type ServerSetup, type ShareInput, public_d_exports$5 as SignIn, type Signature, type SliceRefusal, type StageInput, type Staged, type StepAnswer, type StepInput, type Success, type Tag, type TagCalls, type TagCreateInput, type TagFields, tags_d_exports as Tags, type TargetHoldInput, type TokenCalls, type TokenCoverage, type TokenCreateInput, type TokenCreateOperation, type TokenEvent, type TokenEventFields, type TokenFields, type TokenId, type TokenInfo, type TokenListInput, type TokenOperation, type TokenParties, type TokenRecord, type TokenScope, type TokenState, type TokenTarget, tokens_public_d_exports as Tokens, type TokensFeature, type Topic, type TopicAddInput, type TopicAdded, type TopicCalls, type TopicCandidate, type TopicEntry, type TopicEntryInput, type TopicEnvelope, type TopicEvent, type TopicFailed, type TopicFailure, type TopicFailureReason, type TopicId, type TopicListInput, type TopicMerged, type TopicMergedEntry, type TopicOpened, type TopicOperation, type TopicRemoved, type TopicReportInput, type TopicReportOptions, type TopicReportQuestion, type TopicReported, type TopicState, type TopicTarget, type TopicWait, type TopicWorkFailed, public_d_exports$6 as Topics, type TopicsFactory, type TransportFailure, type TransportRetry, type TreeCalls, type TreeChange, type TreeChanges, type TreeCreateInput, type TreeDiffInput, type TreeEdit, type TreeEntry, TreeFilter, type TreeInput, type TreeMergeInput, trees_d_exports as Trees, type TrustedWriteInput, UnavailableContext, UnavailableReason, type UnpackOptions, Verdict, type VerifiedToken, type WalkInput, type WebApproval, type WebAuthorize, type WebExchange, type WholeObject, type WithoutActor, type WithoutSignal, work_d_exports as Work, type WorkCalls, type WorkItem, type WorkListInput, type WorkOperation, type WorkWriteInput, type WriteInput, accept, allotmentWithin, branchRef, createGitServer, gitError, gitPathOf, grantScopes, httpStatus, isGitError, isInternalId, isRefusalReason, jobStates, lfs, lfsPointerOid, lfsPointers, loose, looseLimits, maxActorIdLength, maxLfsPointerBytes, maxRefNameLength, mergeQueue, objectsReadMost, packs, packsMemory, peelMost, peelTagsMost, reject, shortTarget, tokenScopes, tokenStates, topics };
90
+ export { type Accepted, type AccessOption, type Acting, type Actor, type ActorId, type ActorInput, type AddResult, type Added, type Allotment, type AnonymousActor, type ApprovalBase, type ApprovalDecision, type ApprovalPageContext, type ApprovalPageInput, type ApprovalPrompt, type ApprovedGrant, auth_namespace_d_exports as Auth, type AuthInput, authorize_d_exports as Authorize, type AuthorizeAnswer, type AuthorizeInput, type Awaitable, type BasicCredential, type BatchOptions, type BearerCredential, type BeforeAfter, BeginPushUpload, type Bisect, type Blob, type BlobCalls, type BlobCreateInput, BlobLimit, BlobNone, blobs_d_exports as Blobs, type BypassOperation, type Bytes, type CallInput, type Caller, type CallerGrant, type Candidate, type CandidateCloseReason, type CandidateClosed, type CandidateClosedFields, type CandidateId, type CandidateOpened, type CandidateReportInput, type CandidateReported, type CandidateResult, type CandidateState, type CandidatesResult, type ClientAdapter, type ClientCredential, type ClientCredentials, type ClientFetchInput, type ClientFetchResult, type ClientPushInput, type Commit, type CommitCalls, type CommitCreateInput, type CommitDiffInput, commits_d_exports as Commits, type Compare, type CompareInput, type ComparisonFile, type ConfirmApprovalPage, ContextValue, type CopyRow, type CopyRowsInput, type CopyRowsPage, type CreatedObject, type CreatedToken, type CredentialInput, type Credentials, type CredentialsBasic, type CredentialsBearer, DataLossContext, DataLossReason, type DecisionAnswer, type DeniedGrant, type DeviceApproval, type DeviceCodePage, type DeviceCodeRequest, type DeviceCodeResponse, type DeviceExchange, type DiffListing, type EffectiveLimits, type Entry, type EntryAdded, type EntryFailed, type EntryFailureReason, type EntryFields, type EntryGroups, type EntryHoldInput, type EntryHoldsInput, type EntryId, type EntryMerged, type EntryRemoved, type EntryResult, type EntryRetried, type EntryState, ErrorContext, type EventEnvelope, type EventFeature, event_streams_d_exports as EventStreams, events_d_exports as Events, ExistingContext, ExistingReason, type FailureResult, type FeedItem, type FenceReason, type FencedPack, type FetchAdjustment, type FetchAnswer, type FetchReadInput, type FetchReadTarget, FetchRequest, type FetchRule, type FetchRuleInput, type File, type FileCalls, type FileDiff, type FileReadInput, type FileRuleOptions, files_d_exports as Files, type FilesAllowOperation, type FilesDiffInput, type FilesListInput, type FilesRead, Filter, FinishPushUpload, type ForkCalls, type ForkCreateInput, type ForkFetched, type ForkGetInput, type ForkHolder, type ForkListInput, type ForkOperation, forks_d_exports as Forks, git_namespace_d_exports as Git, type GitAdapter, type GitAuth, type GitAuthorize, client_d_exports as GitClient, type GitClientCalls, type GitClientOptions, type GitError, GitErrorBody, type GitErrorCode, type GitErrorContexts, type GitErrorFields, type GitErrorInput, type GitErrorTagged, type GitEvent, git_events_d_exports as GitEvents, public_d_exports as GitHooks, type GitNeeds, type GitObject, type GitObjects, type GitScope, type GitServer, type GitServerOptions, type GitStore, type GitStoreAddInput, type GitStoreCommitInput, type GitStoreReadInput, type Grant, type GrantAgainInput, type GrantAgainRequest, type GrantInput, type GrantReachInput, type GrantResolver, type GrantScope, type HandlerOptions, type Held, type HeldPack, type HiddenSpan, type Hold, type HoldEvent, type HoldEventFields, type HoldFields, type HoldId, type HoldResult, type Holding, type HoldingsInput, type HoldingsWalked, type HoldsResult, HostErrorContext, type HostFunctionName, type ImportState, type IndexCalls, type IndexReachInput, type IndexReached, type IndexRefusal, type IndexStatus, type IndexTip, type IndexTry, type IndexTryInput, InternalRepoId, InvalidInputContext, InvalidInputReason, type JoinInput, type Judged, type LanesInput, public_d_exports$1 as Lfs, type LfsCalls, type LfsFeature, type LfsGetInput, type LfsObject, type LfsOptions, type LfsPointers, type LfsPointersBuilder, type LineCounts, type LinkedObjects, type Listed, type ListedInput, type ListenInput, type Localize, type LogInput, type MaintainInput, type Me, type MeOperation, type MergeAnswer, type MergeBaseInput, type MergeBases, type MergeCalls, type MergeCreateInput, type MergeInput, type MergeLabels, type MergeMethod, type MergePlan, public_d_exports$2 as MergeQueue, type MergeQueueCalls, type MergeQueueLayerOptions, type MergeQueueOptions, type MergeTree, public_d_exports$3 as Merges, type MetaValue, MissingContext, MissingReason, type NamedActor, NotAllowedContext, NotAllowedReason, type OAuthClient, type OAuthError, type OAuthTokenResponse, type ObjectHeader, type ObjectHeadersInput, type ObjectInput, type ObjectReadInput, type ObjectReadResult, type ObjectReader, type ObjectReaderInput, type ObjectSizesInput, type ObjectType, type ObjectWrite, type ObjectWrites, objects_namespace_d_exports as Objects, type ObjectsChange, type ObjectsFactory, type ObjectsFetchInput, type ObjectsOpenInput, type ObjectsRead, type ObjectsReadInput, type ObjectsStarting, type ObjectsStartingInput, type ObjectsStep, type Oid, type Operation, type OperationKind, type Option, type Pack, type PacksMemory, type PacksOptions, type PagedInput, type PathObject, type PeelInput, type Peeled, type PinnedRepo, policy_d_exports as Policy, PreconditionContext, PreconditionReason, type PrefixTarget, type Prepare, type PrepareInput, type PreviousQueueSchedule, public_d_exports$4 as PrivateRefs, type ProtectOptions, type ProvidedBy, type PushContext, type PushFacts, type PushHookInput, type PushOperation, type PushOptions, type PushRule, type PushRuleInput, type PushUploadOptions, PushUploadPart, PushUploadStarted, type PushedCommit, type PushedCommitsInput, type Quarantine, type QueueAddInput, type QueueAddOperation, type QueueCandidateOperation, type QueueEntryOperation, type QueueEvent, type QueueFailureCounts, type QueueInternals, type QueueKeys, type QueueListInput, type QueueListResult, type QueueMeta, type QueueOf, type QueueRecent, type QueueReleaseOperation, type QueueRestarted, type QueueTargetInput, type QueueTargetOperation, type QueueView, type ReadLimits, type ReadObject, type ReadObjects, type ReadOptions, type ReadPage, type ReceiveInput, type Ref, type RefAudience, type RefCalls, type RefCount, type RefCountInput, type RefEdit, type RefForced, type RefInput, type RefListInput, type RefName, type RefPatterns, type RefProtection, type RefPublication, type RefPush, type RefSource, type RefUpdate, type RefUpdateKind, type RefUpdated, type RefView, refs_d_exports as Refs, type RefsPrivateOperation, type RefsUpdateInput, type RefsUpdated, type RefusalReason, type RejectInput, type Rejected, type ReleaseResult, type Released, type RemoteCalls, type RemoteOptions, type RemoteRefsInput, type RemoveResult, type Removed, type RenamesSkipped, type RepackOptions, type RepoAccess, type RepoCalls, type RepoCatalogueEntry, type RepoCreateInput, type RepoCreated, type RepoDeleted, type RepoDeletedEvent, type RepoEnvelope, type RepoEvent, type RepoGetInput, type RepoIndexHold, type RepoIndexRefused, type RepoInfo, type RepoInfoStats, type RepoInput, type RepoJobFailed, type RepoListInput, type RepoListOperation, type RepoListOrder, type RepoMaintained, type RepoName, type RepoOperation, type RepoPruneRefused, type RepoRecord, repo_records_d_exports as RepoRecords, type RepoRenameInput, type RepoRenamed, type RepoStats, type RepoStreamEvent, type RepoUpdateInput, type RepoVisibilityChanged, type RepoWork, type RepoWorkFailed, type Report, type ReportDetails, type ReportOptions, type ReportResult, type Reported, repos_d_exports as Repos, ResourceContext, ResourceReason, layer_d_exports as Rest, client_d_exports$1 as RestClient, type RestClientCalls, type RestEvents, type RestTokenCalls, type RestartResult, type Restarted, type Result, type Retried, type RetryResult, type Revision, type RowsMoved, type RuleOperation, rules_d_exports as Rules, saved_callers_public_d_exports as SavedCallers, type SavedHandlerOptions, type ScheduleOption, type ServerCalls, type ServerSetup, type ShareInput, public_d_exports$5 as SignIn, type Signature, type SliceRefusal, type StageInput, type Staged, type StepAnswer, type StepInput, type Success, type Tag, type TagCalls, type TagCreateInput, type TagFields, tags_d_exports as Tags, type TargetHoldInput, type TokenCalls, type TokenCoverage, type TokenCreateInput, type TokenCreateOperation, type TokenEvent, type TokenEventFields, type TokenFields, type TokenId, type TokenInfo, type TokenListInput, type TokenOperation, type TokenParties, type TokenRecord, type TokenScope, type TokenState, type TokenTarget, tokens_public_d_exports as Tokens, type TokensFeature, type Topic, type TopicAddInput, type TopicAdded, type TopicCalls, type TopicCandidate, type TopicEntry, type TopicEntryInput, type TopicEnvelope, type TopicEvent, type TopicFailed, type TopicFailure, type TopicFailureReason, type TopicId, type TopicListInput, type TopicMerged, type TopicMergedEntry, type TopicOpened, type TopicOperation, type TopicRemoved, type TopicReportInput, type TopicReportOptions, type TopicReportQuestion, type TopicReported, type TopicState, type TopicTarget, type TopicWait, type TopicWorkFailed, public_d_exports$6 as Topics, type TopicsFactory, type TransportFailure, type TransportRetry, type TreeCalls, type TreeChange, type TreeChanges, type TreeCreateInput, type TreeDiffInput, type TreeEdit, type TreeEntry, TreeFilter, type TreeInput, type TreeMergeInput, trees_d_exports as Trees, type TrustedWriteInput, UnavailableContext, UnavailableReason, type UnpackOptions, Verdict, type VerifiedToken, type WalkInput, type WebApproval, type WebAuthorize, type WebExchange, type WholeObject, type WithoutActor, type WithoutSignal, work_d_exports as Work, type WorkCalls, type WorkItem, type WorkListInput, type WorkOperation, type WorkWriteInput, type WriteInput, accept, allotmentWithin, branchRef, createGitServer, gitError, gitPathOf, grantScopes, httpStatus, isGitError, isInternalId, isRefusalReason, jobStates, lfs, lfsPointerOid, lfsPointers, loose, looseLimits, maxActorIdLength, maxLfsPointerBytes, maxRefNameLength, mergeQueue, objectsReadMost, packs, packsMemory, peelMost, peelTagsMost, reject, shortTarget, tokenScopes, tokenStates, topics };
@@ -1,4 +1,5 @@
1
1
  import { nativeSha256Hasher } from "../protocol/bytes/sha256-hasher.mjs";
2
+ import { gathered } from "../protocol/bytes/streams.mjs";
2
3
  import { contended, openFor } from "../core/access.mjs";
3
4
  import { ownWriter } from "../core/own-writes.mjs";
4
5
  import { sweepDue } from "../core/receipts.mjs";
@@ -13,7 +14,7 @@ import { isLfsOid, lfsPointerText } from "../protocol/objects/lfs-pointer.mjs";
13
14
  import { ListedRow, UploadRow, largestObject, lfsCollections, linkLife, listedKey, listedRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadRead } from "./rows.mjs";
14
15
  import { BatchRequest, VerifyRequest, batchMost, bodyOf, lfsAnswer } from "./wire.mjs";
15
16
  import { uploadedRow } from "./uploaded.mjs";
16
- import { pastMost } from "./upload-most.mjs";
17
+ import { pastMost, uploadPieceBytes } from "./upload-most.mjs";
17
18
  import { fail, gitError, httpStatus } from "../contracts/result.mjs";
18
19
  import * as Clock$1 from "effect/Clock";
19
20
  import * as Effect from "effect/Effect";
@@ -411,14 +412,16 @@ const answered = (request) => Effect.promise(async () => {
411
412
  return lfsAnswer(200, { message: "Already uploaded" });
412
413
  });
413
414
  /**
414
- * `body` as it streams to the bucket, counted, and hashed through the runtime's own SHA-256, each
415
- * chunk's write awaited before it goes on, failing past `most` bytes.
415
+ * `body` as it streams to the bucket, gathered into pieces of `uploadPieceBytes`, counted, and
416
+ * hashed through the runtime's own SHA-256, each piece's write awaited before it goes on, failing
417
+ * past `most` bytes. No piece reaches more than one byte past what `most` leaves, so a body that
418
+ * runs past it is read no further than that byte's chunk.
416
419
  */
417
420
  const hashing = (body, most) => {
418
421
  const hasher = nativeSha256Hasher();
419
422
  let size = 0;
420
423
  const read = Stream.fromReadableStream({
421
- evaluate: () => body ?? new ReadableStream({ start: (controller) => controller.close() }),
424
+ evaluate: () => body === null ? new ReadableStream({ start: (controller) => controller.close() }) : gathered(body, (given) => Math.min(uploadPieceBytes, Math.max(1, most - given + 1))),
422
425
  onError: (cause) => new Unavailable({
423
426
  message: bucketFailed,
424
427
  cause
@@ -22,12 +22,13 @@ const upkeepPage = 500;
22
22
  * LFS's registration's upkeep over its `rows` and `bucket`'s objects: `bucket` charges each call, and
23
23
  * `signed` says the host signs LFS's links, so its uploads have upload rows to end.
24
24
  */
25
- const lfsUpkeep = (rows, bucket, signed) => ({ repo, at }) => upkeepStep({
25
+ const lfsUpkeep = (rows, bucket, signed) => ({ repo, at, deleted }) => upkeepStep({
26
26
  rows,
27
27
  bucket,
28
28
  signed,
29
29
  repo,
30
- at
30
+ at,
31
+ deleted
31
32
  });
32
33
  const did = { more: true };
33
34
  const earliest = (a, b) => a === void 0 ? b : b === void 0 ? a : Math.min(a, b);
@@ -62,12 +63,12 @@ const upkeepStep = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
62
63
  if (dueStages.length > 0) return yield* endStages(upkeep, snapshot.version, dueStages);
63
64
  const uploads = yield* dueUploads(upkeep);
64
65
  if (uploads.ids.length > 0) return yield* endUploads(upkeep, uploads.ids);
65
- const sweep = uploadedSweepOf(uploaded, upkeep.at);
66
- if (sweep.delete.length > 0) {
66
+ const sweep = upkeep.deleted ? void 0 : uploadedSweepOf(uploaded, upkeep.at);
67
+ if (sweep !== void 0 && sweep.delete.length > 0) {
67
68
  yield* upkeep.rows.commit(upkeep.repo, snapshot.version, { delete: sweep.delete });
68
69
  return did;
69
70
  }
70
- const due = stages.map((stage) => stage.removeAt).reduce(earliest, earliest(uploads.next, sweep.due));
71
+ const due = stages.map((stage) => stage.removeAt).reduce(earliest, earliest(uploads.next, sweep?.due));
71
72
  return due === void 0 ? { more: false } : {
72
73
  more: false,
73
74
  due
@@ -8,6 +8,12 @@ import { largestObject } from "./rows.mjs";
8
8
  */
9
9
  /** The share of a request's CPU an upload may spend: the rest is its rows', its put's and the runtime's. */
10
10
  const cpuShare = .8;
11
+ /**
12
+ * The bytes an upload through a Worker gathers from its body's chunks before each goes on to its
13
+ * hash and its put, since a client's body reaches a Worker in chunks of at most 4,096 B, each
14
+ * paid for once over (run 46342279485, #2296): one piece an upload, held as it streams.
15
+ */
16
+ const uploadPieceBytes = 1024 ** 2;
11
17
  /** The bytes `cpuMs` of CPU hashes and stores, at `uploadMsPerMiB` within `cpuShare` of it. */
12
18
  const cpuBytes = (cpuMs) => Math.floor(cpuShare * cpuMs / 64 * 1024 ** 2);
13
19
  /** The largest upload `caps` let finish: `largestObject` where neither binds below it. */
@@ -38,4 +44,4 @@ const setBy = {
38
44
  };
39
45
  /** Why an upload of more than `most` is refused, and what takes it. */
40
46
  const pastMost = (most) => `An upload through this server is at most ${most.bytes} bytes, ${setBy[most.by]}: a bucket that signs its links takes a larger one straight`;
41
- export { capsRefusal, cpuShare, pastMost, uploadMostOf };
47
+ export { capsRefusal, cpuShare, pastMost, uploadMostOf, uploadPieceBytes };
@@ -1,4 +1,8 @@
1
1
  // src/protocol/bytes/streams.ts
2
+ /** Refuses a `piece` under 1 byte, or not a whole number, since its stream would never reach the end. */
3
+ const wholePiece = (piece) => {
4
+ if (!Number.isSafeInteger(piece) || piece < 1) throw new RangeError(`a stream's pieces hold a whole number of bytes, at least 1, not ${piece}`);
5
+ };
2
6
  /**
3
7
  * `bytes` as a stream read once, in pieces of at most `piece` bytes: one piece by default. Each
4
8
  * smaller piece is a copy, made when its reader asks for it, so a reader that holds a piece's
@@ -6,7 +10,7 @@
6
10
  * byte, or not a whole number, is refused, since it would never reach the end.
7
11
  */
8
12
  const streamOf = (bytes, piece = Math.max(1, bytes.length)) => {
9
- if (!Number.isSafeInteger(piece) || piece < 1) throw new RangeError(`a stream's pieces hold a whole number of bytes, at least 1, not ${piece}`);
13
+ wholePiece(piece);
10
14
  if (piece >= bytes.length) return new ReadableStream({ start: (controller) => {
11
15
  controller.enqueue(bytes);
12
16
  controller.close();
@@ -18,4 +22,82 @@ const streamOf = (bytes, piece = Math.max(1, bytes.length)) => {
18
22
  if (at >= bytes.length) controller.close();
19
23
  } });
20
24
  };
21
- export { streamOf };
25
+ /**
26
+ * `body` gathered into pieces, each `pieceAt(given)` bytes, `given` the bytes it has handed on,
27
+ * its last smaller, each copied from its chunks as they come, so code that pays for each chunk pays
28
+ * once a piece: a client's body reaches a deployed Worker in chunks of at most 4,096 B (run
29
+ * 46342279485, #2296). A chunk of a piece's bytes or more, or what's left of one, that comes with
30
+ * nothing gathered goes on as it is, uncopied. It's read only as its reader asks, so it holds at
31
+ * most the piece it gathers and the rest of the chunk that filled the last, and it lets go of
32
+ * `body` once it ends, fails or is cancelled, a cancel reaching it. A piece under 1 byte, or not a
33
+ * whole number, fails the stream.
34
+ */
35
+ const gathered = (body, pieceAt) => {
36
+ const reader = body.getReader();
37
+ let rest;
38
+ let given = 0;
39
+ /** Lets go of `body`, which a reader still waiting on it may already have. */
40
+ const release = () => {
41
+ try {
42
+ reader.releaseLock();
43
+ } catch {}
44
+ };
45
+ /** The next piece's bytes, gathered from as many chunks as it takes, or `body`'s end. */
46
+ const next = async (controller) => {
47
+ const piece = pieceAt(given);
48
+ wholePiece(piece);
49
+ let gathering;
50
+ let filled = 0;
51
+ /** `bytes` handed on as the next piece, counted. */
52
+ const hand = (bytes) => {
53
+ given += bytes.length;
54
+ controller.enqueue(bytes);
55
+ };
56
+ for (;;) {
57
+ const read = rest === void 0 ? await reader.read() : {
58
+ done: false,
59
+ value: rest
60
+ };
61
+ rest = void 0;
62
+ if (read.done) {
63
+ if (gathering !== void 0) hand(gathering.subarray(0, filled));
64
+ controller.close();
65
+ release();
66
+ return;
67
+ }
68
+ const chunk = read.value;
69
+ if (chunk.length === 0) continue;
70
+ if (gathering === void 0 && chunk.length >= piece) {
71
+ hand(chunk);
72
+ return;
73
+ }
74
+ gathering ??= new Uint8Array(piece);
75
+ const moved = Math.min(chunk.length, piece - filled);
76
+ gathering.set(chunk.subarray(0, moved), filled);
77
+ filled += moved;
78
+ if (moved < chunk.length) rest = chunk.subarray(moved);
79
+ if (filled === piece) {
80
+ hand(gathering);
81
+ return;
82
+ }
83
+ }
84
+ };
85
+ return new ReadableStream({
86
+ pull: async (controller) => {
87
+ try {
88
+ await next(controller);
89
+ } catch (cause) {
90
+ release();
91
+ throw cause;
92
+ }
93
+ },
94
+ cancel: async (reason) => {
95
+ try {
96
+ await reader.cancel(reason);
97
+ } finally {
98
+ release();
99
+ }
100
+ }
101
+ }, { highWaterMark: 0 });
102
+ };
103
+ export { gathered, streamOf };
@@ -1,5 +1,6 @@
1
1
  import { Allotment, GitObject, ObjectsRead } from "../../contracts/objects.mjs";
2
2
  import { Oid } from "../../contracts/ids.mjs";
3
+ import "../objects/commit.mjs";
3
4
  import "../objects/tree.mjs";
4
5
  import * as Effect from "effect/Effect";
5
6
  import * as Schema from "effect/Schema";
@@ -1,6 +1,6 @@
1
1
  import { allotmentWithin, objectsReadMost } from "../../contracts/object-values.mjs";
2
2
  import { gitError } from "../../contracts/result.mjs";
3
- import { decodeCommit } from "../objects/commit.mjs";
3
+ import { decodeCommit, noRepoRoots } from "../objects/commit.mjs";
4
4
  import { emptyTree } from "../objects/object.mjs";
5
5
  import { decodeTag } from "../objects/tag.mjs";
6
6
  import { parseTreeBytes, treeEntriesIn } from "../objects/tree.mjs";
@@ -143,11 +143,14 @@ var DiffReader = class {
143
143
  limits;
144
144
  tally;
145
145
  batch;
146
- constructor(read, limits = defaultDiffLimits, tally, batch) {
146
+ /** The repo's roots, each of which a walk through this reader sees as having no parents. */
147
+ roots;
148
+ constructor(read, limits = defaultDiffLimits, tally, batch, roots = noRepoRoots) {
147
149
  this.read = read;
148
150
  this.limits = limits;
149
151
  this.tally = tally;
150
152
  this.batch = batch;
153
+ this.roots = roots;
151
154
  }
152
155
  /** The objects read so far. */
153
156
  get objects() {
@@ -1,4 +1,5 @@
1
1
  import { Commit } from "../../contracts/engine.mjs";
2
+ import { Oid } from "../../contracts/ids.mjs";
2
3
  import { WireDecodeError, WireEncodeError } from "../bytes/errors.mjs";
3
4
  import * as Effect from "effect/Effect";
4
5
  import "effect/Result";
@@ -7,6 +8,12 @@ import "effect/Result";
7
8
  * paragraph, each line's trailing space off, joined by spaces.
8
9
  */
9
10
  export declare function subjectOf(message: string): string;
11
+ /**
12
+ * A repo's roots: the commits it holds without their parents, as Git's `shallow` file names them.
13
+ * Every walk of the repo sees a root as having no parents, as Git's shallow grafts make it, and
14
+ * still follows its tree.
15
+ */
16
+ export type RepoRoots = ReadonlySet<Oid>;
10
17
  /**
11
18
  * A commit read from its bytes, as Git reads it: a `tree` line first, then its `parent` lines,
12
19
  * and an `author` and a `committer` among the headers after them, read leniently, as
@@ -37,6 +37,10 @@ function subjectOf(message) {
37
37
  }
38
38
  return paragraph.join(" ");
39
39
  }
40
+ /** A repo with no roots, as every repo without a `repo/roots` row is. */
41
+ const noRepoRoots = /* @__PURE__ */ new Set();
42
+ /** The parents a walk of a repo with `roots` follows from the commit `oid`: none from a root. */
43
+ const parentsWithin = (roots, oid, parents) => roots.has(oid) ? [] : parents;
40
44
  /**
41
45
  * A commit read from its bytes, as Git reads it: a `tree` line first, then its `parent` lines,
42
46
  * and an `author` and a `committer` among the headers after them, read leniently, as
@@ -135,4 +139,4 @@ const encodeCommit = (commit) => Effect.suspend(() => {
135
139
  ];
136
140
  return Effect.succeed(asCommitTreeStores(utf8(`${lines.join("\n")}\n\n${commit.message}`)));
137
141
  });
138
- export { decodeCommit, encodeCommit, readCommit, subjectOf };
142
+ export { decodeCommit, encodeCommit, noRepoRoots, parentsWithin, readCommit, subjectOf };