@ref0/git 0.27.0 → 0.29.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 (79) hide show
  1. package/dist/client/git-http.mjs +29 -12
  2. package/dist/client/push-upload.mjs +13 -12
  3. package/dist/client/remote-helper.mjs +1 -1
  4. package/dist/client/remote.mjs +1 -1
  5. package/dist/client/run-remote-helper.mjs +7 -14
  6. package/dist/client/slice-push.d.mts +13 -9
  7. package/dist/client/slice-push.mjs +16 -5
  8. package/dist/client/slice-report.mjs +6 -8
  9. package/dist/client/transport.mjs +27 -5
  10. package/dist/contracts/git.d.mts +17 -2
  11. package/dist/contracts/store.d.mts +1 -1
  12. package/dist/core/forks.mjs +1 -1
  13. package/dist/core/purge.mjs +1 -1
  14. package/dist/http/push-uploads.mjs +10 -15
  15. package/dist/lfs/copy.d.mts +4 -1
  16. package/dist/lfs/copy.mjs +7 -6
  17. package/dist/lfs/layer.mjs +1 -1
  18. package/dist/lfs/objects.mjs +127 -8
  19. package/dist/lfs/upload-most.mjs +19 -3
  20. package/dist/merges/merges.d.mts +3 -2
  21. package/dist/protocol/bytes/buffers.mjs +5 -5
  22. package/dist/protocol/bytes/crc32.mjs +39 -6
  23. package/dist/protocol/bytes/deflate.d.mts +11 -31
  24. package/dist/protocol/bytes/deflate.mjs +133 -72
  25. package/dist/protocol/bytes/inflate.mjs +2 -2
  26. package/dist/protocol/bytes/sha1-hasher.mjs +12 -12
  27. package/dist/protocol/bytes/zlib-ng/README.md +65 -38
  28. package/dist/protocol/bytes/zlib-ng/compile.d.mts +5 -4
  29. package/dist/protocol/bytes/zlib-ng/compile.mjs +5 -4
  30. package/dist/protocol/bytes/zlib-ng/embedded.mjs +1 -1
  31. package/dist/protocol/bytes/zlib-ng/instance.mjs +14 -8
  32. package/dist/protocol/bytes/zlib-ng/zlib-ng.wasm +0 -0
  33. package/dist/protocol/objects/fsck-names.mjs +27 -7
  34. package/dist/protocol/objects/fsck.mjs +100 -88
  35. package/dist/protocol/objects/object-rules.d.mts +1 -0
  36. package/dist/protocol/objects/tree.d.mts +1 -0
  37. package/dist/protocol/objects/tree.mjs +55 -6
  38. package/dist/protocol/wire/push-uploads.mjs +12 -1
  39. package/dist/server/registry.mjs +12 -0
  40. package/dist/server/server.mjs +7 -1
  41. package/dist/storage/budget.d.mts +2 -1
  42. package/dist/storage/budget.mjs +25 -9
  43. package/dist/storage/calls.d.mts +1 -1
  44. package/dist/storage/calls.mjs +4 -2
  45. package/dist/storage/host-bucket.mjs +15 -5
  46. package/dist/storage/index-bitmaps.d.mts +1 -0
  47. package/dist/storage/index-bitmaps.mjs +15 -14
  48. package/dist/storage/index-build.d.mts +2 -1
  49. package/dist/storage/index-build.mjs +14 -16
  50. package/dist/storage/index-files.mjs +3 -3
  51. package/dist/storage/index-graph.mjs +3 -3
  52. package/dist/storage/index-remap.mjs +6 -7
  53. package/dist/storage/links.mjs +34 -2
  54. package/dist/storage/memory-budget.mjs +12 -3
  55. package/dist/storage/merge-stream.mjs +4 -3
  56. package/dist/storage/merge-write.mjs +2 -2
  57. package/dist/storage/pack-receive.mjs +24 -8
  58. package/dist/storage/packs.d.mts +3 -1
  59. package/dist/storage/packs.mjs +33 -11
  60. package/dist/storage/put-holds.d.mts +1 -0
  61. package/dist/storage/put-holds.mjs +20 -0
  62. package/dist/storage/ready.mjs +4 -2
  63. package/dist/storage/receive-bounds.d.mts +1 -1
  64. package/dist/storage/receive-bounds.mjs +4 -4
  65. package/dist/storage/receive-links.mjs +31 -15
  66. package/dist/storage/receive-steps.mjs +21 -1
  67. package/dist/storage/runs.d.mts +1 -1
  68. package/dist/storage/runs.mjs +7 -5
  69. package/dist/store/door.mjs +9 -1
  70. package/dist/store/job-try.mjs +5 -5
  71. package/dist/store/repo-record.mjs +1 -1
  72. package/dist/sync/step.mjs +3 -4
  73. package/package.json +3 -9
  74. package/dist/http/node.d.mts +0 -62
  75. package/dist/http/node.mjs +0 -212
  76. package/dist/node.d.mts +0 -3
  77. package/dist/node.mjs +0 -1
  78. package/dist/server/edge-node.d.mts +0 -19
  79. package/dist/server/edge-node.mjs +0 -20
@@ -92,19 +92,36 @@ const waitOf = (response) => {
92
92
  };
93
93
  /** A bucket's refusal, as `retry` sees it: its status alone, its body never read. */
94
94
  const statusOnly = (response) => Effect.succeed({ status: response.status });
95
+ /** `bytes` as a PUT to `url`, carried as `body` says; it throws as `Request` does on a link it can't take. */
96
+ const partPut = (url, bytes, body) => {
97
+ if (body === "bytes") return new Request(url, {
98
+ method: "PUT",
99
+ body: bytes
100
+ });
101
+ new Request(url, { method: "PUT" });
102
+ return () => {
103
+ const streamed = {
104
+ method: "PUT",
105
+ headers: { "content-length": `${bytes.byteLength}` },
106
+ body: new ReadableStream({ start: (controller) => {
107
+ controller.enqueue(bytes);
108
+ controller.close();
109
+ } }),
110
+ duplex: "half"
111
+ };
112
+ return new Request(url, streamed);
113
+ };
114
+ };
95
115
  /**
96
116
  * `bytes` PUT to `url` through `options`' transport and `retry`, with no credential, as
97
- * `GitHttp.putSigned`. Neither the link nor what the transport threw goes in its errors: a link
98
- * signs its bytes in its query.
117
+ * `GitHttp.putSigned`, carried as `body` says. Neither the link nor what the transport threw goes
118
+ * in its errors: a link signs its bytes in its query.
99
119
  */
100
- const putSigned = ({ credentials: _credentials, ...options }, fetchWith) => {
120
+ const putSigned = ({ credentials: _credentials, ...options }, fetchWith, body) => {
101
121
  const bucket = fetchWith(options, statusOnly);
102
122
  return Effect.fnUntraced(function* (url, bytes, what) {
103
123
  const request = yield* Effect.try({
104
- try: () => new Request(url, {
105
- method: "PUT",
106
- body: bytes
107
- }),
124
+ try: () => partPut(url, bytes, body),
108
125
  catch: () => gitError("INTERNAL", `The remote signed ${what} a link that can't be sent`)
109
126
  });
110
127
  const response = yield* bucket(request).pipe(Effect.mapError(() => gitError("UNAVAILABLE", `The bucket didn't answer ${what}`, { hint: "Push again" })));
@@ -143,7 +160,7 @@ const movedRepo = (from, to) => {
143
160
  * the credential. Any other request's redirect is its refusal, as Git's
144
161
  * `http.followRedirects=initial` has it.
145
162
  */
146
- const gitHttpWith = (options, fetchWith) => {
163
+ const gitHttpWith = (options, fetchWith, partBody) => {
147
164
  let base = options.url.replace(/\/+$/, "");
148
165
  const remote = fetchWith(options, gitFailure);
149
166
  const answer = (request) => remote(request).pipe(Effect.mapError((failed) => failed.kind === "refused" ? failed.error : unanswered(failed.cause)));
@@ -210,19 +227,19 @@ const gitHttpWith = (options, fetchWith) => {
210
227
  kind: "answered",
211
228
  body: read
212
229
  })))),
213
- putSigned: putSigned(options, fetchWith)
230
+ putSigned: putSigned(options, fetchWith, partBody)
214
231
  };
215
232
  };
216
233
  /**
217
234
  * The remote's smart HTTP at `options.url`, through `options.transport` when it's given, or
218
- * `HttpClient` otherwise.
235
+ * `HttpClient` otherwise, its signed PUTs carried as `partBody` says.
219
236
  */
220
- const gitHttp = (options) => gitHttpWith(options, remoteFetch);
237
+ const gitHttp = (options, partBody = "bytes") => gitHttpWith(options, remoteFetch, partBody);
221
238
  /** `gitHttp` over a given `transport`, keeping `FetchHttpClient` out of callers that supply one. */
222
239
  const gitHttpOver = (options) => gitHttpWith(options, (opts, reader) => remoteFetchOver({
223
240
  ...opts,
224
241
  transport: options.transport
225
- }, reader));
242
+ }, reader), "bytes");
226
243
  const encodeRequest = /* @__PURE__ */ Schema.encodeEffect(Schema.fromJsonString(PushUploadRequest));
227
244
  /** `body` as `PushUploadRequest`'s JSON; a body it refuses, such as a two-line push option, sends nothing. */
228
245
  const requestJson = (body) => encodeRequest(body).pipe(Effect.mapError((issue) => gitError("INVALID_ARGUMENT", `The push upload's body won't do: ${jsonIssue(issue)}`)));
@@ -216,26 +216,27 @@ const jsonOf = /* @__PURE__ */ Effect.fnUntraced(function* (answer, schema, what
216
216
  });
217
217
  });
218
218
  /**
219
- * `pack` uploaded for `begin`'s push: begin, each part's link and PUT in order, then complete,
220
- * sent again each time it answers 202, after the wait its `Retry-After` asks, for `completeMost`
221
- * at most. Complete's last answer, unread: `git-receive-pack`'s report on side-band-64k.
219
+ * `pack` uploaded for `begin`'s push: begin, then each part's link, read and PUT, `partsAtOnce`
220
+ * parts at once, then complete, naming the parts in order, sent again each time it answers 202,
221
+ * after the wait its `Retry-After` asks, for `completeMost` at most. Complete's last answer, unread:
222
+ * `git-receive-pack`'s report on side-band-64k. Past one part at once, parts are read out of order,
223
+ * so `pack` must read at any offset, as a helper's spool and `packInMemory` do, not `packInOrder`.
222
224
  */
223
- const uploadPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, begin, pack) {
225
+ const uploadPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, begin, pack, partsAtOnce) {
224
226
  const started = yield* jsonOf(yield* http.postJson("push-uploads", begin), PushUploadStarted, "push upload");
225
227
  const count = started.partSize > 0 ? Math.ceil(pack.bytes / started.partSize) : 0;
226
228
  if (count < 1 || count > partsMost) return yield* fail("UNAVAILABLE", `The remote's part size, ${started.partSize}, won't do`);
227
229
  const upload = `push-uploads/${encodeURIComponent(started.upload)}`;
228
- const parts = [];
229
- for (let part = 1; part <= count; part += 1) {
230
- const offset = (part - 1) * started.partSize;
230
+ const parts = yield* Effect.forEach(Array.from({ length: count }), Effect.fnUntraced(function* (_, at) {
231
+ const part = at + 1;
232
+ const offset = at * started.partSize;
231
233
  const link = yield* jsonOf(yield* http.postJson(`${upload}/parts/${part}`, {}), PushUploadPart, `link for part ${part}`);
232
234
  const bytes = yield* pack.read(offset, Math.min(started.partSize, pack.bytes - offset));
233
- const etag = yield* http.putSigned(link.url, bytes, `part ${part}`);
234
- parts.push({
235
+ return {
235
236
  part,
236
- etag
237
- });
238
- }
237
+ etag: yield* http.putSigned(link.url, bytes, `part ${part}`)
238
+ };
239
+ }), { concurrency: partsAtOnce });
239
240
  return yield* completed(http, `${upload}/complete`, { parts });
240
241
  });
241
242
  /**
@@ -115,7 +115,7 @@ const plainReport = /* @__PURE__ */ Effect.fnUntraced(function* (start, answer)
115
115
  */
116
116
  const relayPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, capabilities, start, startBytes, pack) {
117
117
  if (forUpload(capabilities, start, pack.bytes)) {
118
- const answer = yield* uploadPush(http, beginOf(start, pack.bytes), pack);
118
+ const answer = yield* uploadPush(http, beginOf(start, pack.bytes), pack, 8);
119
119
  return yield* askedReport(start, yield* heldBody(answer, reportMost, "report"));
120
120
  }
121
121
  const answer = yield* http.post("git-receive-pack", "v0", packBody(startBytes, pack));
@@ -467,7 +467,7 @@ const uploaded = /* @__PURE__ */ Effect.fnUntraced(function* (http, pack, update
467
467
  };
468
468
  if (terms.pushOptions !== void 0 && terms.pushOptions.length > 0) begin.pushOptions = terms.pushOptions;
469
469
  if (terms.atomic === true) begin.atomic = true;
470
- return uploadPush(http, begin, source);
470
+ return uploadPush(http, begin, source, 1);
471
471
  }));
472
472
  return yield* reportedPush(answer, true, updates);
473
473
  });
@@ -8,6 +8,7 @@ import { helperNode, nodeLocalGit, spooled } from "./helper-node.mjs";
8
8
  import { packHeldMost, packInMemory } from "./push-upload.mjs";
9
9
  import { helperAdvertisement, readHelperStart, relayPush } from "./remote-helper.mjs";
10
10
  import { controlsAllowed, maskedControls, secretScrubber } from "./scrub.mjs";
11
+ import { lengthKept } from "./transport.mjs";
11
12
  import { packPastLimits } from "./slice-push.mjs";
12
13
  import { slicedHelperPush } from "./slice-report.mjs";
13
14
  import { LocalGit } from "./slices.mjs";
@@ -20,7 +21,6 @@ import * as Result from "effect/Result";
20
21
  import * as HttpClient from "effect/http/HttpClient";
21
22
  import * as Base64 from "effect/encoding/Base64";
22
23
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
23
- import * as HttpBody from "effect/http/HttpBody";
24
24
  import * as HttpClientRequest from "effect/http/HttpClientRequest";
25
25
  import * as HttpClientResponse from "effect/http/HttpClientResponse";
26
26
  import * as Redacted from "effect/Redacted";
@@ -125,16 +125,10 @@ const movedTo = (moved, url) => {
125
125
  return at;
126
126
  };
127
127
  /**
128
- * `request` as an `HttpClientRequest`: `GET` and `POST` stream through `fromWeb`, while a `PUT`
129
- * (signed bucket part uploads) sends raw bytes so `FetchHttpClient` preserves `Content-Length`
130
- * rather than sending a chunked `ReadableStream`.
128
+ * `request` sent through `client`, its body streamed as `fromWeb` reads it, with the
129
+ * `content-length` it carries, as a signed part's PUT does.
131
130
  */
132
- const httpRequestOf = async (request) => {
133
- const base = HttpClientRequest.fromWeb(request);
134
- if (request.method !== "PUT" || request.body === null) return base;
135
- const bytes = new Uint8Array(await request.arrayBuffer());
136
- return HttpClientRequest.makeWith(base.method, base.url, base.urlParams, base.hash, base.headers, HttpBody.raw(bytes));
137
- };
131
+ const sentThrough = (client, request) => lengthKept(client.execute(HttpClientRequest.fromWeb(request)), request.headers.get("content-length"));
138
132
  /**
139
133
  * What an `HttpClientError` carries that may be a cause: the transport's own error, never the
140
134
  * `HttpClientError` or its `reason`, whose request holds the `authorization` header.
@@ -161,8 +155,7 @@ const push = (calls, input, url, { out, err }, hide) => {
161
155
  const client = yield* Effect.provide(HttpClient.HttpClient, FetchHttpClient.layer);
162
156
  const run = runnerIn(context);
163
157
  const transport = async (request) => {
164
- const prepared = await httpRequestOf(request);
165
- const answered = await run(client.execute(prepared).pipe(Effect.provideService(FetchHttpClient.RequestInit, { redirect: "follow" }), Effect.mapError(transportCause)), request.signal);
158
+ const answered = await run(sentThrough(client, request).pipe(Effect.provideService(FetchHttpClient.RequestInit, { redirect: "follow" }), Effect.mapError(transportCause)), request.signal);
166
159
  const response = Option.getOrElse(HttpClientResponse.toWeb(answered), () => {
167
160
  throw new Error("The remote didn't answer");
168
161
  });
@@ -186,7 +179,7 @@ const push = (calls, input, url, { out, err }, hide) => {
186
179
  retry: 3
187
180
  };
188
181
  };
189
- const httpAt = () => gitHttp(remoteAt());
182
+ const httpAt = () => gitHttp(remoteAt(), "stream");
190
183
  const anonymous = yield* Effect.result(helperAdvertisement(httpAt()));
191
184
  if (Result.isFailure(anonymous) && !challenged) return yield* Effect.fail(anonymous.failure);
192
185
  at = movedTo(moved, url);
@@ -217,7 +210,7 @@ const push = (calls, input, url, { out, err }, hide) => {
217
210
  const line = new TextEncoder().encode(`slice ${at} of ${of} landed\n`);
218
211
  return sideBand ? out(onBand(2, line)) : err(line);
219
212
  };
220
- const answered = sliced ? yield* slicedHelperPush(remoteAt(), advertised, start, landed).pipe(Effect.provideService(LocalGit, nodeLocalGit())) : yield* relayPush(http, advertised.capabilities, start, startBytes, pack);
213
+ const answered = sliced ? yield* slicedHelperPush(http, advertised, start, landed).pipe(Effect.provideService(LocalGit, nodeLocalGit())) : yield* relayPush(http, advertised.capabilities, start, startBytes, pack);
221
214
  yield* out(answered.report);
222
215
  if (answered.unpacked && credential !== void 0) yield* calls.approve(at, credential).pipe(Effect.mapError(() => failed));
223
216
  }).pipe(Effect.tapError(() => refused && credential !== void 0 ? calls.reject(at, credential).pipe(Effect.mapError(() => failed)) : Effect.void));
@@ -3,6 +3,7 @@ import { Oid } from "../contracts/ids.mjs";
3
3
  import { RemoteOptions } from "../contracts/remote.mjs";
4
4
  import { GitError, RefusalReason } from "../contracts/result.mjs";
5
5
  import { PushReport } from "../protocol/wire/report-status.mjs";
6
+ import "./git-http.mjs";
6
7
  import "./push-upload.mjs";
7
8
  import * as Effect from "effect/Effect";
8
9
  /**
@@ -38,20 +39,22 @@ export type SlicedPush = {
38
39
  readonly landed: readonly Slice[];
39
40
  readonly refusal: SliceRefusal;
40
41
  };
41
- /**
42
- * `refs` pushed to the remote `remote` names, in slices that each fit what `capabilities` advertise,
43
- * past `serverTips`, the tips of the refs the server has. `pushOptions` go with every slice, and
44
- * `atomic`, when asked, needs the push to be one slice: a push that needs more sends nothing.
45
- * `landed`, when given, is told each slice that lands: its place, and the slices planned in all.
46
- */
47
- export declare const pushSlices: (push: {
48
- readonly remote: RemoteOptions;
42
+ /** A push to send in slices, but for the remote it goes to. */
43
+ interface Slicing {
49
44
  readonly capabilities: readonly string[];
50
45
  readonly serverTips: ReadonlyArray<Oid>;
51
46
  readonly refs: ReadonlyArray<SlicedRef>;
52
47
  readonly pushOptions: readonly string[];
53
48
  readonly atomic: boolean;
54
49
  readonly landed?: (at: number, of: number) => Effect.Effect<void, GitError>;
50
+ }
51
+ /**
52
+ * `slicesThrough` to the remote `remote` names, as `git-remote-ref0` sends: each part of an upload
53
+ * streamed from its own buffer with its `content-length`, which a `transport` of `remote`'s must
54
+ * send, as Node's `fetch` does, since a bucket refuses a part sent chunked.
55
+ */
56
+ export declare const pushSlices: (push: Slicing & {
57
+ readonly remote: RemoteOptions;
55
58
  }) => Effect.Effect<{
56
59
  kind: "refused";
57
60
  landed: Slice[];
@@ -74,4 +77,5 @@ export declare const pushSlices: (push: {
74
77
  refusal?: never;
75
78
  kind: "pushed";
76
79
  landed: Slice[];
77
- }, GitError, LocalGitRun>;
80
+ }, GitError, LocalGitRun>;
81
+ export {};
@@ -59,15 +59,14 @@ const halved = (slice) => {
59
59
  });
60
60
  };
61
61
  /**
62
- * `refs` pushed to the remote `remote` names, in slices that each fit what `capabilities` advertise,
62
+ * `refs` pushed to the remote through `http`, in slices that each fit what `capabilities` advertise,
63
63
  * past `serverTips`, the tips of the refs the server has. `pushOptions` go with every slice, and
64
64
  * `atomic`, when asked, needs the push to be one slice: a push that needs more sends nothing.
65
65
  * `landed`, when given, is told each slice that lands: its place, and the slices planned in all.
66
66
  */
67
- const pushSlices = /* @__PURE__ */ Effect.fnUntraced(function* (push) {
67
+ const slicesThrough = /* @__PURE__ */ Effect.fnUntraced(function* (push) {
68
68
  const git = yield* LocalGit;
69
- const http = gitHttp(push.remote);
70
- const { capabilities } = push;
69
+ const { http, capabilities } = push;
71
70
  const limits = pushLimitsOf(capabilities);
72
71
  const plan = yield* planSlices(push);
73
72
  const landed = [];
@@ -166,4 +165,16 @@ const pushSlices = /* @__PURE__ */ Effect.fnUntraced(function* (push) {
166
165
  landed
167
166
  };
168
167
  });
169
- export { atomicRefusal, packPastLimits, pushSlices };
168
+ /**
169
+ * `slicesThrough` to the remote `remote` names, as `git-remote-ref0` sends: each part of an upload
170
+ * streamed from its own buffer with its `content-length`, which a `transport` of `remote`'s must
171
+ * send, as Node's `fetch` does, since a bucket refuses a part sent chunked.
172
+ */
173
+ const pushSlices = (push) => {
174
+ const { remote, ...slicing } = push;
175
+ return slicesThrough({
176
+ ...slicing,
177
+ http: gitHttp(remote, "stream")
178
+ });
179
+ };
180
+ export { atomicRefusal, packPastLimits, pushSlices, slicesThrough };
@@ -2,17 +2,16 @@ import { fail, gitError } from "../contracts/result.mjs";
2
2
  import { pushLimitsOf } from "../protocol/wire/push-limits.mjs";
3
3
  import { encodePushStart } from "../protocol/wire/receive-pack.mjs";
4
4
  import { encodePushReport, readPushReport } from "../protocol/wire/report-status.mjs";
5
- import { gitHttp } from "./git-http.mjs";
6
5
  import { decodedBy, encodedBy } from "./negotiate.mjs";
7
6
  import { packInMemory } from "./push-upload.mjs";
8
7
  import { relayPush } from "./remote-helper.mjs";
9
- import { atomicRefusal, packPastLimits, pushSlices } from "./slice-push.mjs";
8
+ import { atomicRefusal, packPastLimits, slicesThrough } from "./slice-push.mjs";
10
9
  import { LocalGit, pastLimits, sizeOf } from "./slices.mjs";
11
10
  import * as Effect from "effect/Effect";
12
11
  // src/client/slice-report.ts
13
12
  /**
14
13
  * Git's push as `git-remote-ref0` takes it over once its pack passes what the remote advertises
15
- * one push may carry (Q901): its branches' moves sent through `pushSlices`, then its tags and
14
+ * one push may carry (Q901): its branches' moves sent through `slicesThrough`, then its tags and
16
15
  * deletes, in pushes of the tags' own objects that each fit, and one report back in the form Git's
17
16
  * start asked for, so `git push` prints each ref `ok`, or rejected with the server's reason or the
18
17
  * reason it wasn't sent.
@@ -70,13 +69,13 @@ const reportOf = (start, sliced, told) => {
70
69
  };
71
70
  };
72
71
  /**
73
- * Git's push of `start` sent in slices to `remote`, as `advertised` says it may carry: what Git
72
+ * Git's push of `start` sent in slices through `http`, as `advertised` says it may carry: what Git
74
73
  * reads back, and whether the remote unpacked any of it, which approves the credential. A shallow
75
74
  * push is refused, since the slices' plan walks history the clone lacks, an atomic one, which goes
76
75
  * only as one push, and a tag whose own objects, past the branches and the server's tips, pass
77
76
  * what one push may carry, since a tag never moves through the commits before it.
78
77
  */
79
- const slicedHelperPush = /* @__PURE__ */ Effect.fnUntraced(function* (remote, advertised, start, landed) {
78
+ const slicedHelperPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, advertised, start, landed) {
80
79
  if (start.shallow.length > 0) return yield* fail("FAILED_PRECONDITION", "A shallow push can't go in slices", {
81
80
  context: { reason: "shallow-upload" },
82
81
  hint: "Push without the helper: a plain push still works, under the platform's request limit"
@@ -124,8 +123,8 @@ const slicedHelperPush = /* @__PURE__ */ Effect.fnUntraced(function* (remote, ad
124
123
  else batches.push([tag]);
125
124
  }
126
125
  batches.at(-1)?.push(...start.commands.filter((command) => command.after === noObject));
127
- const sliced = yield* pushSlices({
128
- remote,
126
+ const sliced = yield* slicesThrough({
127
+ http,
129
128
  capabilities: advertised.capabilities,
130
129
  serverTips: tips,
131
130
  refs: branches.map(({ ref, after, before }) => ({
@@ -137,7 +136,6 @@ const slicedHelperPush = /* @__PURE__ */ Effect.fnUntraced(function* (remote, ad
137
136
  atomic: false,
138
137
  landed
139
138
  });
140
- const http = gitHttp(remote);
141
139
  const packed = [
142
140
  "pack-objects",
143
141
  "--revs",
@@ -4,6 +4,7 @@ import { joinedBytes } from "../protocol/bytes/joined.mjs";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as Predicate from "effect/Predicate";
6
6
  import * as Stream from "effect/Stream";
7
+ import * as Context from "effect/Context";
7
8
  import * as Option from "effect/Option";
8
9
  import * as HttpClient from "effect/http/HttpClient";
9
10
  import * as Base64 from "effect/encoding/Base64";
@@ -210,7 +211,8 @@ const transportSend = (transport) => (request, credential) => Effect.tryPromise(
210
211
  },
211
212
  catch: unansweredOf
212
213
  });
213
- const httpRequest = (request, sent) => {
214
+ /** `sent` as `HttpClient` takes it: its body read whole when `whole`, else streamed as it's read. */
215
+ const httpRequest = (sent, whole) => {
214
216
  const upper = sent.method.toUpperCase();
215
217
  const method = HttpMethod.allShort.find(([name]) => name === upper)?.[0] ?? "GET";
216
218
  const make = HttpClientRequest.make(method);
@@ -224,7 +226,7 @@ const httpRequest = (request, sent) => {
224
226
  });
225
227
  return contentType === null ? HttpClientRequest.removeHeader(built, "content-type") : built;
226
228
  };
227
- if (request instanceof Request) return Effect.tryPromise({
229
+ if (whole) return Effect.tryPromise({
228
230
  try: () => sent.arrayBuffer(),
229
231
  catch: unansweredOf
230
232
  }).pipe(Effect.map((bytes) => withBody(HttpBody.uint8Array(new Uint8Array(bytes), contentType ?? void 0))));
@@ -233,14 +235,34 @@ const httpRequest = (request, sent) => {
233
235
  onError: (cause) => cause
234
236
  }), contentType ?? void 0)));
235
237
  };
238
+ /**
239
+ * `sent`, with `length`, when there is one, set again on what `FetchHttpClient`'s `fetch` is given:
240
+ * it drops a `content-length`, and would send a streamed body chunked, which a bucket's signed PUT
241
+ * refuses. Node's `fetch` sends a stream whole with its length; workerd sends it chunked anyway.
242
+ */
243
+ const lengthKept = (sent, length) => {
244
+ if (length === null) return sent;
245
+ return Effect.flatMap(Effect.context(), (context) => {
246
+ const fetch = Context.getOrUndefined(context, FetchHttpClient.Fetch) ?? globalThis.fetch;
247
+ return Effect.provideService(sent, FetchHttpClient.Fetch, (input, init) => {
248
+ const headers = new Headers(init?.headers);
249
+ headers.set("content-length", length);
250
+ return fetch(input, {
251
+ ...init,
252
+ headers
253
+ });
254
+ });
255
+ });
256
+ };
236
257
  const httpSend = /* @__PURE__ */ Effect.fnUntraced(function* (request, credential) {
237
258
  const sent = yield* Effect.try({
238
259
  try: () => signed(request, credential),
239
260
  catch: unansweredOf
240
261
  });
241
- const built = yield* httpRequest(request, sent);
242
262
  const found = yield* Effect.serviceOption(HttpClient.HttpClient);
243
- const executed = Option.isSome(found) ? found.value.execute(built) : Effect.flatMap(Effect.provide(HttpClient.HttpClient, FetchHttpClient.layer), (client) => client.execute(built)).pipe(Effect.provideService(HttpClient.TracerPropagationEnabled, false));
263
+ const length = request instanceof Request ? null : sent.headers.get("content-length");
264
+ const built = yield* httpRequest(sent, request instanceof Request || Option.isSome(found) && length !== null);
265
+ const executed = Option.isSome(found) ? found.value.execute(built) : lengthKept(Effect.flatMap(Effect.provide(HttpClient.HttpClient, FetchHttpClient.layer), (client) => client.execute(built)), length).pipe(Effect.provideService(HttpClient.TracerPropagationEnabled, false));
244
266
  const response = yield* Effect.raceFirst(executed.pipe(Effect.mapError((error) => unansweredOf(Predicate.hasProperty(error.reason, "cause") ? error.reason.cause : error.message)), Effect.flatMap((answer) => {
245
267
  const web = HttpClientResponse.toWeb(answer);
246
268
  if (Option.isSome(web)) return Effect.succeed(web.value);
@@ -278,4 +300,4 @@ const remoteFetchWith = (options, failureOf, send) => {
278
300
  const remoteFetch = (options, failureOf) => remoteFetchWith(options, failureOf, options.transport === void 0 ? httpSend : transportSend(options.transport));
279
301
  /** `remoteFetch` over a given `transport`, keeping `FetchHttpClient` out of callers that supply one. */
280
302
  const remoteFetchOver = (options, failureOf) => remoteFetchWith(options, failureOf, transportSend(options.transport));
281
- export { abortable, bodyStart, bodyText, credentialHeader, credentialRefused, credentialsFailed, dropped, pauseOf, remoteFetch, remoteFetchOver, shouldRetry, unanswered };
303
+ export { abortable, bodyStart, bodyText, credentialHeader, credentialRefused, credentialsFailed, dropped, lengthKept, pauseOf, remoteFetch, remoteFetchOver, shouldRetry, unanswered };
@@ -8,11 +8,12 @@ import { RefSource, RefUpdate } from "./refs.mjs";
8
8
  import { FetchReadInput } from "./rules.mjs";
9
9
  import { PinnedRepo } from "./repos.mjs";
10
10
  import { GitError } from "./result.mjs";
11
- import { Committed, CurrentJob, Job, Key, Moment, Read, Records, Row, WatchedRow } from "@ref0/infra";
11
+ import { Committed, CurrentJob, Job, Key, Moment, Multipart, Read, Records, Row, WatchedRow } from "@ref0/infra";
12
12
  import * as Effect from "effect/Effect";
13
13
  import * as Stream from "effect/Stream";
14
14
  import * as Context from "effect/Context";
15
15
  import * as Option from "effect/Option";
16
+ import * as Scope$1 from "effect/Scope";
16
17
  import * as Duration from "effect/Duration";
17
18
  /**
18
19
  * The host, acting as itself (Q223): the caller host code's calls name, as `hostCalls()` do. A
@@ -37,7 +38,7 @@ export interface RegisterInput {
37
38
  readonly scopes?: readonly string[];
38
39
  /**
39
40
  * The scopes a repo has of the registration's own, by its internal ID, each inside `scopes`. Once a
40
- * deleted repo's purge has deleted its record, it frees each with `Store.drop`, then Git's own:
41
+ * deleted repo's purge has deleted its record, it frees each with `Records.drop`, then Git's own:
41
42
  * name only a scope nothing reads or writes once the repo is gone. One outside `scopes` is a defect,
42
43
  * and so are more across the registrations than the purge's bound: it then drops none.
43
44
  */
@@ -237,6 +238,20 @@ export interface Registration {
237
238
  * every call the request makes.
238
239
  */
239
240
  readonly allowance: () => CallAllowance;
241
+ /**
242
+ * A charge, for the scope, of what a put to a bucket of `multipart` holds in memory: its body
243
+ * told its `size`, or at most `atMost` bytes, or neither. Its call budget's sibling, against the
244
+ * server's own memory budget, which `packs()` shares across the instance: nothing for a body the
245
+ * bucket sends whole, as R2 does one told its size; else the bucket's `buffersMost` buffers. The
246
+ * server refuses to build over objects whose upkeep can't hold one put to the host's bucket, so a
247
+ * charge past all upkeep may hold is a defect. It waits for room beside pushes, then fails
248
+ * `UNAVAILABLE`, so a job's try ends and comes again, and does nothing over objects with no
249
+ * budget, a host's own that attach none. Run the put inside its scope.
250
+ */
251
+ readonly putCharge: (multipart: Multipart, body?: {
252
+ readonly size?: number | undefined;
253
+ readonly atMost?: number | undefined;
254
+ }) => Effect.Effect<void, GitError, Scope$1.Scope>;
240
255
  readonly addPushCheck: (check: Hook<PushCheck>) => Effect.Effect<void>;
241
256
  /**
242
257
  * The registration's one delivery, named after it, its job `git.deliver.<registration name>`: `group`'s
@@ -71,7 +71,7 @@ export interface GitStoreAddInput extends CallInput {
71
71
  export interface ListedInput extends CallInput {
72
72
  readonly repo: string;
73
73
  }
74
- /** Git's records over infra's `Store`, under Git's commit rules. Features never get the raw store. */
74
+ /** Git's records over infra's `Records`, under Git's commit rules. Features never get the raw store. */
75
75
  export interface GitStore {
76
76
  readonly read: (input: GitStoreReadInput) => Effect.Effect<Snapshot, GitError>;
77
77
  /** Fenced by the current job's claim inside a job's try. */
@@ -123,7 +123,7 @@ const isAlreadyThere = (error) => error.code === "ALREADY_EXISTS";
123
123
  /**
124
124
  * A create's cover rows, after its opener, as a commit, with no `by` (#1911): a purge's drop resets
125
125
  * the scope to 0 and its deletes are commits at a version, so one that lands after them is refused
126
- * in store order, whatever the clocks say, and on Turso, at a version past 0, makes no database.
126
+ * in store order, whatever the clocks say.
127
127
  * - One the create goes on from commits at the version its own last commit left, and hands it the
128
128
  * version it leaves: a commit of anyone else's between, a purge's above all, refuses it, as it
129
129
  * would the create's publishing commit. One that took the version it read instead would hand
@@ -23,7 +23,7 @@ import * as Effect from "effect/Effect";
23
23
  * its rows name, then its record last, so a late try of any other job reads no record and ends.
24
24
  * A source waits while a fork holds it, deleted or not, since a fork's LFS reads through its
25
25
  * source; a fork's purge releases its hold just before its record goes. Then it drops the repo's
26
- * scopes, the registrations' and its own, so a store frees each, as Turso's deletes its database
26
+ * scopes, the registrations' and its own, so a store frees each, as Cloudflare's wipes its object
27
27
  * (#1911, Q1160, Q1161).
28
28
  */
29
29
  /** The most rows a step deletes: inside one commit's `limits.writes`. */
@@ -5,10 +5,9 @@ import { readAsked } from "../core/asked.mjs";
5
5
  import { CoreParts, ObjectsParts } from "../core/parts.mjs";
6
6
  import { pushOptionsRefusal } from "../protocol/wire/receive-pack.mjs";
7
7
  import { pushReasonsCapability } from "../protocol/wire/push-limits.mjs";
8
- import { retryAfterOf } from "../protocol/wire/push-uploads.mjs";
8
+ import { retryAfterSince } from "../protocol/wire/push-uploads.mjs";
9
9
  import { decodeJson } from "../protocol/wire/json.mjs";
10
10
  import { bucketCall, readWhole } from "../storage/calls.mjs";
11
- import "../storage/receive-bounds.mjs";
12
11
  import { PushUploadRow, claimLapsed, completingMost, endUpload, partBytes, partLinkLife, partSizeOf, partsOf, pushPackTooLarge, pushUploadGrace, pushUploadKey, pushUploadLife, pushUploadMost, pushUploadRead, pushUploadRowKey } from "../storage/push-uploads.mjs";
13
12
  import { afterWrites, bestEffort, decodeRow, storeCommit } from "../store/errors.mjs";
14
13
  import { randomText } from "../store/random.mjs";
@@ -29,11 +28,8 @@ const bodyMost = 1048576;
29
28
  /** A pack's header: `PACK`, its version, and how many objects it holds. */
30
29
  const packHeader = 12;
31
30
  const zero = "0".repeat(40);
32
- /**
33
- * Push uploads over `needs`, the server's, staged in `staging`, offered above `above` bytes, on a
34
- * host whose requests get `cpuMs` of CPU: complete's 202 asks a client to wait that long.
35
- */
36
- const make = (needs, staging, above, cpuMs) => ({
31
+ /** Push uploads over `needs`, the server's, staged in `staging`, offered above `above` bytes. */
32
+ const make = (needs, staging, above) => ({
37
33
  above,
38
34
  serve: (parts, call) => {
39
35
  const { route } = call;
@@ -42,8 +38,7 @@ const make = (needs, staging, above, cpuMs) => ({
42
38
  const parted = part(staging.uploads, call, route.upload, route.part);
43
39
  return routeCounted(parts, Effect.provideContext(parted, needs));
44
40
  }
45
- const retryAfter = retryAfterOf((cpuMs ?? 3e4) / 1e3);
46
- return routeCounted(parts, complete(staging, call, route.upload, retryAfter).pipe(Effect.tapError((error) => refusalLog(call.repo, error)), Effect.provideContext(needs)));
41
+ return routeCounted(parts, complete(staging, call, route.upload).pipe(Effect.tapError((error) => refusalLog(call.repo, error)), Effect.provideContext(needs)));
47
42
  }
48
43
  });
49
44
  /** `body` as `schema`'s JSON, the answer a push upload's route gives, with `headers` beside. */
@@ -229,18 +224,18 @@ const startOf = (row) => ({
229
224
  /**
230
225
  * `POST <repo>/push-uploads/{upload}/complete`: an open upload claimed, its parts joined, and
231
226
  * handed to `git.push-upload`'s steps, which check the caller's grant again each try; then the
232
- * same complete sent again answers 202 while they receive it, asking the client to wait
233
- * `retryAfter` seconds, and once the upload ended, the report its push answered, as
227
+ * same complete sent again answers 202 while they receive it, asking the client to wait a share of
228
+ * the time since the claim, and once the upload ended, the report its push answered, as
234
229
  * `git-receive-pack` does. Upkeep at its `removeAt` deletes the upload, and its answer with it.
235
230
  */
236
- const complete = /* @__PURE__ */ Effect.fnUntraced(function* (staging, call, upload, retryAfter) {
231
+ const complete = /* @__PURE__ */ Effect.fnUntraced(function* (staging, call, upload) {
237
232
  const finish = yield* bodyOf(call.request, FinishPushUpload);
238
233
  const repo = yield* openFor(call.caller, call.repo, true, void 0, "first-read");
239
234
  const actor = yield* actorOf(call.caller);
240
235
  const first = yield* uploadOf(repo.internalId, upload, actor, repo);
241
- const receiving = (step) => jsonAnswer(PushUploadReceiving, { step }, 202, { "retry-after": String(retryAfter) });
236
+ const receiving = (step, claimedMs) => jsonAnswer(PushUploadReceiving, { step }, 202, { "retry-after": String(retryAfterSince(claimedMs)) });
242
237
  const handed = first.row.state === "open" ? yield* handOff(staging, repo.internalId, upload, call.caller, finish.parts) : void 0;
243
- if (handed?.kind === "handed") return receiving(0);
238
+ if (handed?.kind === "handed") return receiving(0, 0);
244
239
  const refused = handed?.kind === "refused" ? Result.fail(handed.error) : void 0;
245
240
  if (refused !== void 0) yield* thrownLog(call.repo, refused);
246
241
  const read = first.row.state === "open" ? yield* uploadOf(repo.internalId, upload, actor) : first;
@@ -256,7 +251,7 @@ const complete = /* @__PURE__ */ Effect.fnUntraced(function* (staging, call, upl
256
251
  const { row, steps, answer } = lapsed ? yield* uploadOf(repo.internalId, upload, actor) : read;
257
252
  if (row.state === "ended" && answer !== void 0) return yield* report(row, pushedOf(answer));
258
253
  if (refused !== void 0) return yield* report(first.row, refused);
259
- if (row.state === "completing" || row.state === "receiving") return receiving(steps?.step ?? 0);
254
+ if (row.state === "completing" || row.state === "receiving") return receiving(steps?.step ?? 0, at - (row.claimedAt ?? at));
260
255
  return yield* ended(upload);
261
256
  });
262
257
  /** `pushed` as receive-pack's report on the start `row` names. */
@@ -31,7 +31,10 @@ export interface LfsCopy {
31
31
  * `body`, `size` bytes whose SHA-256 is `oid`, put at `staging`'s key with nothing buffered, the
32
32
  * bucket checking the SHA-256: other bytes fail `INVALID_ARGUMENT`, keeping nothing. No
33
33
  * interrupt cuts it short, for the reason `bucketPut` gives, so `body` must end or fail of
34
- * itself, as import's download does once its try's signal aborts.
34
+ * itself, as import's download does once its try's signal aborts. It runs inside the
35
+ * registration's `putCharge` for its size, which holds what the bucket's put holds in the
36
+ * server's memory while it runs, and fails `UNAVAILABLE`, so the job tries again, when no room
37
+ * came.
35
38
  */
36
39
  readonly put: (staging: LfsStaging, body: Stream.Stream<Uint8Array, GitError>, size: number, oid: string) => Effect.Effect<void, GitError>;
37
40
  /**
package/dist/lfs/copy.mjs CHANGED
@@ -192,16 +192,17 @@ const partsPut = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, partBytes,
192
192
  yield* Stream.runForEachWhile(input.body, took);
193
193
  return ending;
194
194
  });
195
- /** The copy over LFS's registration's rows and its bucket. */
196
- const lfsCopy = (rows, bucket) => {
195
+ /** The copy over LFS's registration's rows and its bucket, each put inside `charge`, its `putCharge`. */
196
+ const lfsCopy = (rows, bucket, charge) => {
197
197
  const partBytes = Math.max(Number.isFinite(bucket.multipart.partSize) ? bucket.multipart.partSize : 0, copyPartDefault);
198
+ const put = (staging, body, size, oid) => Effect.scoped(Effect.andThen(charge(bucket.multipart, { size }), Effect.asVoid(Effect.uninterruptible(bucketDo(bucket.put(staging.key, body, {
199
+ size,
200
+ sha256: oid
201
+ }))))));
198
202
  return {
199
203
  listed: (repo, oids) => listedOf(rows, repo, oids),
200
204
  stage: (repo, objects) => copyStages(rows, bucket, repo, objects),
201
- put: (staging, body, size, oid) => Effect.asVoid(Effect.uninterruptible(bucketDo(bucket.put(staging.key, body, {
202
- size,
203
- sha256: oid
204
- })))),
205
+ put,
205
206
  listing: (landed) => ({
206
207
  put: landed.map(({ oid, size, staging }) => ({
207
208
  ...listedKey(oid),
@@ -52,7 +52,7 @@ const lfsRegistration = /* @__PURE__ */ Effect.fnUntraced(function* (registratio
52
52
  })
53
53
  },
54
54
  read,
55
- copy: lfsCopy(registration.rows, bucket)
55
+ copy: lfsCopy(registration.rows, bucket, registration.putCharge)
56
56
  });
57
57
  yield* registration.addUpkeep(lfsUpkeep(registration.rows, bucket, links !== void 0));
58
58
  yield* registration.addPurge(lfsPurge(registration.rows, bucket));