@ref0/git 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access/private-refs.mjs +0 -2
- package/dist/auth/authorize.mjs +31 -24
- package/dist/auth/bridge.mjs +8 -8
- package/dist/auth/fences.d.mts +0 -1
- package/dist/auth/fences.mjs +1 -1
- package/dist/auth/grants.d.mts +0 -1
- package/dist/auth/grants.mjs +2 -2
- package/dist/auth/host-function.d.mts +1 -7
- package/dist/auth/host-function.mjs +38 -38
- package/dist/auth/identify.d.mts +0 -1
- package/dist/auth/identify.mjs +1 -1
- package/dist/auth/policy.d.mts +7 -4
- package/dist/auth/policy.mjs +13 -10
- package/dist/auth/token-rows.mjs +2 -5
- package/dist/auth/tokens-layer.d.mts +0 -2
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens-public.mjs +4 -2
- package/dist/auth/tokens.d.mts +6 -1
- package/dist/auth/tokens.mjs +7 -1
- package/dist/client/client.d.mts +22 -15
- package/dist/client/client.mjs +31 -27
- package/dist/client/git-http.mjs +22 -5
- package/dist/client/local.mjs +1 -1
- package/dist/client/namespace.d.mts +2 -0
- package/dist/client/push-upload.d.mts +1 -0
- package/dist/client/push-upload.mjs +169 -2
- package/dist/client/remote-helper.mjs +2 -4
- package/dist/client/remote.mjs +37 -15
- package/dist/client/run-remote-helper.mjs +4 -4
- package/dist/client/transport.mjs +26 -19
- package/dist/contracts/actors.d.mts +57 -28
- package/dist/contracts/actors.mjs +38 -2
- package/dist/contracts/authorize.d.mts +21 -15
- package/dist/contracts/callers.mjs +40 -0
- package/dist/contracts/client.d.mts +16 -9
- package/dist/contracts/events.d.mts +12 -10
- package/dist/contracts/events.mjs +8 -6
- package/dist/contracts/files.d.mts +42 -42
- package/dist/contracts/forks.d.mts +0 -24
- package/dist/contracts/git-hooks.d.mts +217 -0
- package/dist/contracts/git-hooks.mjs +3 -1
- package/dist/contracts/grants.d.mts +46 -27
- package/dist/contracts/lfs.d.mts +17 -4
- package/dist/contracts/merges.d.mts +7 -7
- package/dist/contracts/objects.d.mts +20 -4
- package/dist/contracts/opaque.mjs +19 -1
- package/dist/contracts/operations.d.mts +8 -1
- package/dist/contracts/operations.mjs +209 -0
- package/dist/contracts/queue.d.mts +3 -3
- package/dist/contracts/queue.mjs +5 -18
- package/dist/contracts/remote.d.mts +13 -4
- package/dist/contracts/remote.mjs +3 -3
- package/dist/contracts/repos.d.mts +11 -40
- package/dist/contracts/repos.mjs +11 -10
- package/dist/contracts/result.d.mts +28 -11
- package/dist/contracts/result.mjs +32 -2
- package/dist/contracts/rules.d.mts +706 -46
- package/dist/contracts/rules.mjs +81 -2
- package/dist/contracts/server.d.mts +5 -275
- package/dist/contracts/services.d.mts +0 -3
- package/dist/contracts/services.mjs +1 -3
- package/dist/contracts/signin.d.mts +2 -2
- package/dist/contracts/signin.mjs +4 -5
- package/dist/contracts/sync.d.mts +1 -4
- package/dist/contracts/tokens.d.mts +29 -17
- package/dist/contracts/tokens.mjs +14 -3
- package/dist/contracts/topics.d.mts +38 -11
- package/dist/contracts/topics.mjs +8 -2
- package/dist/core/access.d.mts +0 -2
- package/dist/core/access.mjs +15 -4
- package/dist/core/events/deliver.mjs +19 -1
- package/dist/core/forks.mjs +30 -11
- package/dist/core/hooks/groups.d.mts +0 -1
- package/dist/core/hooks/groups.mjs +8 -9
- package/dist/core/loose-tally.mjs +46 -0
- package/dist/core/objects/writing.mjs +1 -0
- package/dist/core/promise.mjs +1 -15
- package/dist/core/purge.mjs +14 -9
- package/dist/core/push.mjs +13 -6
- package/dist/core/ref-view.mjs +14 -6
- package/dist/core/repack.mjs +19 -14
- package/dist/core/repo-info.mjs +8 -6
- package/dist/core/repos.mjs +1 -0
- package/dist/core/rules/check.mjs +10 -10
- package/dist/core/rules/context.d.mts +3 -1
- package/dist/core/rules/context.mjs +16 -13
- package/dist/core/rules/fetch.mjs +17 -23
- package/dist/core/tokens.mjs +2 -1
- package/dist/effect.d.mts +2 -4
- package/dist/effect.mjs +2 -4
- package/dist/engine/commits.mjs +19 -47
- package/dist/engine/failures.d.mts +1 -2
- package/dist/engine/failures.mjs +1 -3
- package/dist/engine/merge-base-walk.mjs +57 -142
- package/dist/engine/merge-bases.mjs +5 -5
- package/dist/engine/merge.mjs +16 -14
- package/dist/extend.d.mts +1 -2
- package/dist/extend.mjs +1 -2
- package/dist/http/core-parts.mjs +1 -2
- package/dist/http/handler.mjs +11 -31
- package/dist/http/parts.d.mts +0 -1
- package/dist/index.d.mts +28 -21
- package/dist/index.mjs +5 -2
- package/dist/lfs/base.d.mts +6 -3
- package/dist/lfs/base.mjs +2 -1
- package/dist/lfs/layer.d.mts +4 -3
- package/dist/lfs/layer.mjs +23 -9
- package/dist/lfs/objects.mjs +90 -41
- package/dist/lfs/pointers.mjs +69 -18
- package/dist/lfs/purge.mjs +6 -2
- package/dist/lfs/rows.mjs +24 -7
- package/dist/lfs/service.d.mts +6 -3
- package/dist/lfs/service.mjs +8 -2
- package/dist/lfs/upkeep.mjs +44 -26
- package/dist/lfs/upload-most.mjs +41 -0
- package/dist/lfs/uploaded.mjs +59 -0
- package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
- package/dist/protocol/bytes/text.mjs +6 -1
- package/dist/protocol/objects/fsck.mjs +6 -3
- package/dist/queue/advance.mjs +38 -8
- package/dist/queue/calls.mjs +4 -14
- package/dist/queue/lanes.mjs +1 -1
- package/dist/queue/rows.mjs +8 -0
- package/dist/queue/schedule.mjs +1 -1
- package/dist/queue/search.mjs +3 -4
- package/dist/rest/client-namespace.d.mts +2 -0
- package/dist/rest/client.d.mts +32 -8
- package/dist/rest/client.mjs +308 -382
- package/dist/rest/commits.d.mts +240 -240
- package/dist/rest/files.d.mts +18 -18
- package/dist/rest/forks.d.mts +45 -57
- package/dist/rest/handlers.mjs +2 -1
- package/dist/rest/listen.d.mts +8 -6
- package/dist/rest/listen.mjs +31 -75
- package/dist/rest/me.d.mts +2 -2
- package/dist/rest/merges.d.mts +7 -7
- package/dist/rest/refs.d.mts +139 -139
- package/dist/rest/repos.d.mts +54 -66
- package/dist/rest/tokens.d.mts +12 -12
- package/dist/rest/topics.d.mts +110 -110
- package/dist/rest/trees.d.mts +66 -66
- package/dist/rest/wire.d.mts +1 -1
- package/dist/rest.d.mts +1 -7
- package/dist/rest.mjs +1 -5
- package/dist/server/git-layer.d.mts +10 -2
- package/dist/server/git-layer.mjs +29 -10
- package/dist/server/joined.d.mts +1 -1
- package/dist/server/server.d.mts +0 -1
- package/dist/server/server.mjs +26 -45
- package/dist/signin/context.d.mts +0 -1
- package/dist/signin/context.mjs +5 -9
- package/dist/storage/clean-up.mjs +3 -1
- package/dist/storage/fsck.mjs +12 -2
- package/dist/storage/graph-rebuild.mjs +262 -0
- package/dist/storage/index-build.mjs +100 -12
- package/dist/storage/lfs-pointers.d.mts +5 -5
- package/dist/storage/lfs-pointers.mjs +37 -11
- package/dist/storage/loose.mjs +4 -1
- package/dist/storage/memory-budget.mjs +1 -1
- package/dist/storage/merge-fence.mjs +81 -19
- package/dist/storage/merge-most.mjs +1 -0
- package/dist/storage/merge-row.mjs +16 -4
- package/dist/storage/merge-stream.mjs +9 -6
- package/dist/storage/object-rows.mjs +17 -1
- package/dist/storage/pack-receive.mjs +10 -6
- package/dist/storage/packs.mjs +58 -27
- package/dist/storage/prune.mjs +68 -40
- package/dist/storage/ready.d.mts +1 -1
- package/dist/storage/ready.mjs +12 -3
- package/dist/storage/receive-state.mjs +1 -1
- package/dist/storage/repack-contained.mjs +22 -14
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/repack.mjs +3 -2
- package/dist/storage/unpack.mjs +7 -0
- package/dist/store/call-count.d.mts +23 -3
- package/dist/store/call-count.mjs +36 -13
- package/dist/store/records.mjs +10 -4
- package/dist/store/repo-record.mjs +29 -12
- package/dist/store/scopes.mjs +6 -1
- package/dist/sync/import.mjs +14 -2
- package/dist/sync/layer.d.mts +5 -1
- package/dist/sync/layer.mjs +7 -2
- package/dist/sync/step.mjs +15 -15
- package/dist/topics/advance.mjs +7 -6
- package/dist/topics/members.mjs +38 -9
- package/package.json +3 -3
- package/dist/engine/merge-base-walk.d.mts +0 -3
- package/dist/server/routes.d.mts +0 -32
- package/dist/server/routes.mjs +0 -69
- package/dist/sync/bridge.d.mts +0 -6
- package/dist/sync/bridge.mjs +0 -29
package/dist/client/client.mjs
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { guardedCalls, noDoor } from "../core/promise.mjs";
|
|
3
3
|
import { gitHttp } from "./git-http.mjs";
|
|
4
4
|
import { localSide } from "./local.mjs";
|
|
5
5
|
import { fetchInto, pushFrom, remoteRefs } from "./remote.mjs";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Option from "effect/Option";
|
|
8
|
+
import * as Context from "effect/Context";
|
|
9
|
+
import * as Stream from "effect/Stream";
|
|
6
10
|
// src/client/client.ts
|
|
11
|
+
var client_exports = /* @__PURE__ */ __exportAll({
|
|
12
|
+
GitClient: () => GitClient,
|
|
13
|
+
make: () => make,
|
|
14
|
+
paginate: () => paginate
|
|
15
|
+
});
|
|
7
16
|
/**
|
|
8
|
-
* A client of one remote
|
|
9
|
-
*
|
|
10
|
-
* this, as a service. Each is an edge a host calls, as the server's Effect face is: a spent bound,
|
|
11
|
-
* a `CallBudget`'s or the platform's cap, is answered as its refusal, never a defect.
|
|
17
|
+
* A client of one remote as a service, for a program that's handed one: with `GitClient` from
|
|
18
|
+
* `@ref0/git`, `Layer.succeed(GitClient.GitClient, GitClient.make(options))` provides it.
|
|
12
19
|
*/
|
|
13
|
-
|
|
20
|
+
var GitClient = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/GitClient")) {};
|
|
21
|
+
/**
|
|
22
|
+
* A client of `options.url`, as Effects: `remoteRefs`, `fetch` and `push` on the remote over Git's
|
|
23
|
+
* smart HTTP, and the server's calls on its own storage, which a fetch fills and a push reads. Each
|
|
24
|
+
* is an edge a host calls, as the server's Effect face is: a spent bound, a `CallBudget`'s or the
|
|
25
|
+
* platform's cap, fails as its refusal, never a defect. Interrupting a call stops it.
|
|
26
|
+
*/
|
|
27
|
+
const make = (options) => {
|
|
14
28
|
const local = localSide(options);
|
|
15
29
|
const http = gitHttp(options);
|
|
16
30
|
return guardedCalls({
|
|
@@ -21,30 +35,20 @@ const effectGitClient = (options) => {
|
|
|
21
35
|
}, noDoor);
|
|
22
36
|
};
|
|
23
37
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
38
|
+
* Each item `list` answers, a page at a time, from the input's `page` on: the next page asked for
|
|
39
|
+
* only once the last one's items are taken. A refused page fails the stream with its own error,
|
|
40
|
+
* after the items of the pages before it.
|
|
27
41
|
*/
|
|
28
|
-
const
|
|
29
|
-
/**
|
|
30
|
-
* Each item `list` answers, a page at a time, from the input's `page` on: the next page asked
|
|
31
|
-
* for only once the last one's items are taken. A refused page throws its own `GitError`, so a
|
|
32
|
-
* loop over it stops there with the error's `code`.
|
|
33
|
-
*/
|
|
34
|
-
async function* paginate(list, ...args) {
|
|
42
|
+
const paginate = (list, ...args) => {
|
|
35
43
|
const head = args.slice(0, -1);
|
|
36
44
|
const input = args.at(-1);
|
|
37
|
-
|
|
45
|
+
return Stream.paginate(input.page?.after, (after) => {
|
|
38
46
|
const page = { ...input.page };
|
|
39
47
|
if (after !== void 0) page.after = after;
|
|
40
|
-
|
|
48
|
+
return Effect.map(list(...head, {
|
|
41
49
|
...input,
|
|
42
50
|
page
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
after = listed.value.next;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export { createGitClient, effectGitClient, paginate };
|
|
51
|
+
}), (listed) => [listed.items, Option.fromUndefinedOr(listed.next)]);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
export { GitClient, client_exports, make, paginate };
|
package/dist/client/git-http.mjs
CHANGED
|
@@ -166,15 +166,32 @@ const gitHttp = (options) => {
|
|
|
166
166
|
method: "POST",
|
|
167
167
|
...init
|
|
168
168
|
})), answered));
|
|
169
|
+
/** A POST to `path` of a body `open` streams, a request made afresh for each send. */
|
|
170
|
+
const sendStreamed = (path, init, open) => Effect.suspend(() => {
|
|
171
|
+
const at = `${base}/${path}`;
|
|
172
|
+
const made = () => {
|
|
173
|
+
const streamed = {
|
|
174
|
+
method: "POST",
|
|
175
|
+
...init,
|
|
176
|
+
body: open(),
|
|
177
|
+
duplex: "half"
|
|
178
|
+
};
|
|
179
|
+
return new Request(at, streamed);
|
|
180
|
+
};
|
|
181
|
+
return Effect.flatMap(answer(made), answered);
|
|
182
|
+
});
|
|
169
183
|
return {
|
|
170
184
|
advertisement,
|
|
171
|
-
post: (service, protocol, body) =>
|
|
172
|
-
headers: headers(protocol, {
|
|
185
|
+
post: (service, protocol, body) => {
|
|
186
|
+
const init = { headers: headers(protocol, {
|
|
173
187
|
accept: `application/x-${service}-result`,
|
|
174
188
|
"content-type": `application/x-${service}-request`
|
|
175
|
-
})
|
|
176
|
-
body
|
|
177
|
-
|
|
189
|
+
}) };
|
|
190
|
+
return body instanceof Uint8Array ? send(service, {
|
|
191
|
+
...init,
|
|
192
|
+
body
|
|
193
|
+
}) : sendStreamed(service, init, body);
|
|
194
|
+
},
|
|
178
195
|
postJson: (path, body) => Effect.flatMap(requestJson(body), (json) => send(path, {
|
|
179
196
|
headers: { "content-type": "application/json" },
|
|
180
197
|
body: json
|
package/dist/client/local.mjs
CHANGED
|
@@ -120,7 +120,7 @@ const localLayer = (options) => Layer.effect(Local, Effect.gen(function* () {
|
|
|
120
120
|
hiddenRefs: () => gitsOwnRefs,
|
|
121
121
|
publishedRefs: () => [],
|
|
122
122
|
grants: heldGrants(),
|
|
123
|
-
checks: {
|
|
123
|
+
checks: {},
|
|
124
124
|
repackJobRow: (at) => repackJobRow(repack, at),
|
|
125
125
|
jobs: noRepackRetry,
|
|
126
126
|
events: void 0
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GitError } from "../contracts/result.mjs";
|
|
2
2
|
import "./git-http.mjs";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
|
+
import "effect/Context";
|
|
4
5
|
/**
|
|
5
6
|
* A push's pack uploaded straight to the remote's bucket, as `push-upload=<above>` offers: begin,
|
|
6
7
|
* then for each part a signed link and the part PUT to it, then complete, which answers as
|
|
@@ -1,15 +1,182 @@
|
|
|
1
1
|
import { PushUploadPart, PushUploadStarted } from "../contracts/push-uploads.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { tryUnlessSpent } from "../contracts/calls-spent.mjs";
|
|
3
|
+
import { fail, gitError, isGitError } from "../contracts/result.mjs";
|
|
4
|
+
import { scopedReader } from "../protocol/bytes/reader.mjs";
|
|
3
5
|
import { decodeJson } from "../protocol/wire/json.mjs";
|
|
4
6
|
import { pushUploadAbove } from "../protocol/wire/push-uploads.mjs";
|
|
7
|
+
import { readableIn } from "../store/crossing.mjs";
|
|
8
|
+
import { emptyReadsMost } from "./answer.mjs";
|
|
5
9
|
import { heldBody } from "./git-http.mjs";
|
|
6
10
|
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Option from "effect/Option";
|
|
12
|
+
import * as Cause from "effect/Cause";
|
|
7
13
|
import * as Result from "effect/Result";
|
|
14
|
+
import * as Context from "effect/Context";
|
|
15
|
+
import * as Stream from "effect/Stream";
|
|
8
16
|
// src/client/push-upload.ts
|
|
9
17
|
/** The most of a begin's or a part's JSON answer read. */
|
|
10
18
|
const answerMost = 65536;
|
|
11
19
|
/** The most parts a push upload takes, as S3's multipart does. */
|
|
12
20
|
const partsMost = 1e4;
|
|
21
|
+
/**
|
|
22
|
+
* The most of a pack `git-remote-ref0` holds in memory: past it, the pack is spooled to disk and
|
|
23
|
+
* streamed into the push, as Git's own `http.postBuffer` holds 1 MiB before it streams.
|
|
24
|
+
*/
|
|
25
|
+
const packHeldMost = 1048576;
|
|
26
|
+
/** How much of a pack a streamed push reads at a time. */
|
|
27
|
+
const packChunk = 65536;
|
|
28
|
+
/**
|
|
29
|
+
* `start`, then `pack` read `packChunk` at a time from its first byte: a plain push's body,
|
|
30
|
+
* streamed afresh each time it's opened, so a send made again reads the pack again. Its pulls run
|
|
31
|
+
* in no call's context: a client reads its own spool and makes no call through Git's doors.
|
|
32
|
+
*/
|
|
33
|
+
const packBody = (start, pack) => () => {
|
|
34
|
+
const chunks = Stream.paginate(0, (offset) => {
|
|
35
|
+
const length = Math.min(packChunk, pack.bytes - offset);
|
|
36
|
+
if (length <= 0) return Effect.succeed([[], Option.none()]);
|
|
37
|
+
return Effect.map(pack.read(offset, length), (bytes) => {
|
|
38
|
+
const next = offset + length;
|
|
39
|
+
return [[bytes], next < pack.bytes ? Option.some(next) : Option.none()];
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
return readableIn(Stream.concat(Stream.make(start), chunks), Context.empty());
|
|
43
|
+
};
|
|
44
|
+
/** A read of the local repo's pack that failed, for `cause`. */
|
|
45
|
+
const packUnread = (cause) => gitError("UNAVAILABLE", "The local repo's pack couldn't be read", {
|
|
46
|
+
cause,
|
|
47
|
+
hint: "Try again"
|
|
48
|
+
});
|
|
49
|
+
/** A pack read again that came out other than it first did, so an upload of it would be wrong. */
|
|
50
|
+
const packChanged = /* @__PURE__ */ gitError("UNAVAILABLE", "The local repo's pack changed between its reads", { hint: "Push again" });
|
|
51
|
+
/** A read of the local repo's pack that gave more than `emptyReadsMost` empty reads in a row. */
|
|
52
|
+
const packStalled = /* @__PURE__ */ gitError("UNAVAILABLE", `The local repo's pack gave ${emptyReadsMost} empty reads in a row`, { hint: "Push again" });
|
|
53
|
+
/** A read of `reader` that tells a spent call bound from the rest, as `heldBody`'s does. */
|
|
54
|
+
const readOf = (reader) => tryUnlessSpent(() => reader.read(), packUnread);
|
|
55
|
+
/**
|
|
56
|
+
* `pack` read to its end: its chunks held when it ends within `most` bytes, else only counted, the
|
|
57
|
+
* chunks dropped once past `most`, so it holds at most `most` and a chunk. More than
|
|
58
|
+
* `emptyReadsMost` empty reads in a row refuse it.
|
|
59
|
+
*/
|
|
60
|
+
const heldOrCounted = (pack, most) => Effect.scoped(Effect.gen(function* () {
|
|
61
|
+
const reader = yield* scopedReader(pack);
|
|
62
|
+
let held = [];
|
|
63
|
+
let bytes = 0;
|
|
64
|
+
let empties = 0;
|
|
65
|
+
for (;;) {
|
|
66
|
+
const next = yield* readOf(reader);
|
|
67
|
+
if (next.done) break;
|
|
68
|
+
if (next.value.byteLength === 0) {
|
|
69
|
+
empties += 1;
|
|
70
|
+
if (empties > 4096) return yield* Effect.fail(packStalled);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
empties = 0;
|
|
74
|
+
bytes += next.value.byteLength;
|
|
75
|
+
if (bytes > most) held = void 0;
|
|
76
|
+
else held?.push(next.value);
|
|
77
|
+
}
|
|
78
|
+
return held === void 0 ? {
|
|
79
|
+
kind: "counted",
|
|
80
|
+
bytes
|
|
81
|
+
} : {
|
|
82
|
+
kind: "held",
|
|
83
|
+
chunks: held
|
|
84
|
+
};
|
|
85
|
+
}));
|
|
86
|
+
/**
|
|
87
|
+
* `pack`, a run of the same fetch that `bytes` counted, as a `PackSource` read forward only, as an
|
|
88
|
+
* upload reads its parts: each read starts where the last ended. A run that ends short of `bytes`,
|
|
89
|
+
* or runs past it, is `packChanged`. Its reader is the scope's.
|
|
90
|
+
*/
|
|
91
|
+
const packInOrder = /* @__PURE__ */ Effect.fnUntraced(function* (pack, bytes) {
|
|
92
|
+
const reader = yield* scopedReader(pack);
|
|
93
|
+
let at = 0;
|
|
94
|
+
let left = /* @__PURE__ */ new Uint8Array(0);
|
|
95
|
+
return {
|
|
96
|
+
bytes,
|
|
97
|
+
read: Effect.fnUntraced(function* (offset, length) {
|
|
98
|
+
if (offset !== at) return yield* Effect.fail(packChanged);
|
|
99
|
+
const part = new Uint8Array(length);
|
|
100
|
+
let filled = 0;
|
|
101
|
+
let empties = 0;
|
|
102
|
+
while (filled < length) {
|
|
103
|
+
if (left.byteLength === 0) {
|
|
104
|
+
const next = yield* readOf(reader);
|
|
105
|
+
if (next.done) return yield* Effect.fail(packChanged);
|
|
106
|
+
empties = next.value.byteLength === 0 ? empties + 1 : 0;
|
|
107
|
+
if (empties > 4096) return yield* Effect.fail(packStalled);
|
|
108
|
+
left = next.value;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const taken = Math.min(length - filled, left.byteLength);
|
|
112
|
+
part.set(left.subarray(0, taken), filled);
|
|
113
|
+
left = left.subarray(taken);
|
|
114
|
+
filled += taken;
|
|
115
|
+
}
|
|
116
|
+
at += length;
|
|
117
|
+
if (at === bytes && (left.byteLength > 0 || !(yield* endsHere(reader)))) return yield* Effect.fail(packChanged);
|
|
118
|
+
return part;
|
|
119
|
+
})
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
/** Whether `reader` has nothing more but empty reads, within `emptyReadsMost` of them. */
|
|
123
|
+
const endsHere = /* @__PURE__ */ Effect.fnUntraced(function* (reader) {
|
|
124
|
+
for (let empties = 0; empties <= emptyReadsMost; empties += 1) {
|
|
125
|
+
const next = yield* readOf(reader);
|
|
126
|
+
if (next.done) return true;
|
|
127
|
+
if (next.value.byteLength > 0) return false;
|
|
128
|
+
}
|
|
129
|
+
return yield* Effect.fail(packStalled);
|
|
130
|
+
});
|
|
131
|
+
/**
|
|
132
|
+
* `pack` as a stream that keeps the first thing that breaks it in `broke`: a failure, or a defect
|
|
133
|
+
* such as a spent call bound's, which dies past the stream's crossing. An interrupt alone, a
|
|
134
|
+
* send that stopped reading, breaks nothing.
|
|
135
|
+
*/
|
|
136
|
+
const keptBreak = (pack, broke) => Stream.tapCause(pack, (cause) => Effect.sync(() => {
|
|
137
|
+
if (broke.broke || Cause.hasInterruptsOnly(cause)) return;
|
|
138
|
+
broke.broke = true;
|
|
139
|
+
broke.cause = Cause.squash(cause);
|
|
140
|
+
}));
|
|
141
|
+
const streamOf = (pack) => Stream.fromReadableStream({
|
|
142
|
+
evaluate: () => pack,
|
|
143
|
+
onError: (cause) => cause
|
|
144
|
+
});
|
|
145
|
+
/**
|
|
146
|
+
* `start`, then a pack: a plain push's body, made afresh for each send. The first send takes
|
|
147
|
+
* `first`, the fetch already run, and each later one, a retry or a 401's second send, runs `fetch`
|
|
148
|
+
* again. Its pulls run in `context`, the push's own, so the store calls a run makes count where
|
|
149
|
+
* the push's do. What breaks the last body's pack is kept in `broke`, each body opened afresh, and
|
|
150
|
+
* `unsent` cancels `first` when no send took it.
|
|
151
|
+
*/
|
|
152
|
+
const fetchedBody = (start, first, fetch, context) => {
|
|
153
|
+
const broke = {
|
|
154
|
+
broke: false,
|
|
155
|
+
cause: void 0
|
|
156
|
+
};
|
|
157
|
+
let untaken = first;
|
|
158
|
+
const open = () => {
|
|
159
|
+
const taken = untaken;
|
|
160
|
+
untaken = void 0;
|
|
161
|
+
broke.broke = false;
|
|
162
|
+
broke.cause = void 0;
|
|
163
|
+
const pack = taken === void 0 ? Stream.unwrap(Effect.map(fetch, streamOf)) : streamOf(taken);
|
|
164
|
+
return readableIn(Stream.concat(Stream.make(start), keptBreak(pack, broke)), context);
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
open,
|
|
168
|
+
broke,
|
|
169
|
+
unsent: Effect.promise(async () => {
|
|
170
|
+
await untaken?.cancel().catch(() => void 0);
|
|
171
|
+
untaken = void 0;
|
|
172
|
+
})
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* What a push answers when its pack's read broke, whatever its send answered: the read's own
|
|
177
|
+
* failure, a spent call bound dying as it does, not the send's or the remote's report.
|
|
178
|
+
*/
|
|
179
|
+
const brokenBy = (cause) => isGitError(cause) ? Effect.fail(cause) : tryUnlessSpent(() => Promise.reject(cause), packUnread);
|
|
13
180
|
/** `pack` in memory, as a `PackSource`. */
|
|
14
181
|
const packInMemory = (pack) => ({
|
|
15
182
|
bytes: pack.length,
|
|
@@ -50,4 +217,4 @@ const uploadPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, begin, pac
|
|
|
50
217
|
}
|
|
51
218
|
return yield* http.postJson(`${upload}/complete`, { parts });
|
|
52
219
|
});
|
|
53
|
-
export { packInMemory, takesUpload, uploadPush };
|
|
220
|
+
export { brokenBy, fetchedBody, heldOrCounted, packBody, packHeldMost, packInMemory, packInOrder, takesUpload, uploadPush };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { fail } from "../contracts/result.mjs";
|
|
2
|
-
import { joinedBytes } from "../protocol/bytes/joined.mjs";
|
|
3
2
|
import { advertisedSource, pastServiceLine } from "../protocol/wire/advertisement.mjs";
|
|
4
3
|
import { pushReasonsOf } from "../protocol/wire/push-limits.mjs";
|
|
5
4
|
import { readPushStart } from "../protocol/wire/receive-pack.mjs";
|
|
@@ -7,7 +6,7 @@ import { encodePushReport, readPushReport } from "../protocol/wire/report-status
|
|
|
7
6
|
import { advertisementRefused } from "./answer.mjs";
|
|
8
7
|
import { heldBody } from "./git-http.mjs";
|
|
9
8
|
import { decodedBy, encodedBy } from "./negotiate.mjs";
|
|
10
|
-
import { takesUpload, uploadPush } from "./push-upload.mjs";
|
|
9
|
+
import { packBody, takesUpload, uploadPush } from "./push-upload.mjs";
|
|
11
10
|
import * as Effect from "effect/Effect";
|
|
12
11
|
// src/client/remote-helper.ts
|
|
13
12
|
/**
|
|
@@ -119,8 +118,7 @@ const relayPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, capabilitie
|
|
|
119
118
|
const answer = yield* uploadPush(http, beginOf(start, pack.bytes), pack);
|
|
120
119
|
return yield* askedReport(start, yield* heldBody(answer, reportMost, "report"));
|
|
121
120
|
}
|
|
122
|
-
const
|
|
123
|
-
const answer = yield* http.post("git-receive-pack", "v0", joinedBytes([startBytes, packed]));
|
|
121
|
+
const answer = yield* http.post("git-receive-pack", "v0", packBody(startBytes, pack));
|
|
124
122
|
return yield* plainReport(start, yield* heldBody(answer, reportMost, "report"));
|
|
125
123
|
});
|
|
126
124
|
export { helperAdvertisement, pushStartMost, readHelperStart, relayPush };
|
package/dist/client/remote.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { joinedBytes } from "../protocol/bytes/joined.mjs";
|
|
|
11
11
|
import { isOid } from "../protocol/bytes/text.mjs";
|
|
12
12
|
import { advertisedSource } from "../protocol/wire/advertisement.mjs";
|
|
13
13
|
import { encodePushStart, pushOptionsRefusal } from "../protocol/wire/receive-pack.mjs";
|
|
14
|
+
import { pushUploadAbove } from "../protocol/wire/push-uploads.mjs";
|
|
14
15
|
import { readPushReport } from "../protocol/wire/report-status.mjs";
|
|
15
16
|
import { encodeV2Request, lsRefsArguments, readLsRefsAnswer, readV2Capabilities } from "../protocol/wire/v2.mjs";
|
|
16
17
|
import { objectsFace, oneShotReads } from "../storage/calls.mjs";
|
|
@@ -20,7 +21,7 @@ import { collections } from "../store/scopes.mjs";
|
|
|
20
21
|
import { advertisementRefused } from "./answer.mjs";
|
|
21
22
|
import { heldBody } from "./git-http.mjs";
|
|
22
23
|
import { localRepo } from "./local.mjs";
|
|
23
|
-
import {
|
|
24
|
+
import { brokenBy, fetchedBody, heldOrCounted, packInOrder, uploadPush } from "./push-upload.mjs";
|
|
24
25
|
import { decodedBy, encodedBy, negotiate } from "./negotiate.mjs";
|
|
25
26
|
import * as Effect from "effect/Effect";
|
|
26
27
|
// src/client/remote.ts
|
|
@@ -330,7 +331,11 @@ const receiveRefs = (http) => Effect.flatMap(advertisement(http, "git-receive-pa
|
|
|
330
331
|
* Each of `updates`, checked, sent with `from` as the tip it expects, and a pack of what their
|
|
331
332
|
* tips reach and `advertised`'s refs don't, from `source`: to the remote's bucket in parts when it
|
|
332
333
|
* offers `push-upload=<above>` and the pack is larger, else in the push's own body. The remote
|
|
333
|
-
* decides each ref, or all of them with `atomic`, and its report answers each.
|
|
334
|
+
* decides each ref, or all of them with `atomic`, and its report answers each. With no upload
|
|
335
|
+
* offered the pack streams into the body, made again for each send, and a pack whose read broke
|
|
336
|
+
* fails the push for it, whatever the remote answered. With one, it holds at most twice `above`:
|
|
337
|
+
* within it, the pack's chunks and the body they're joined into; past it a first run counts it,
|
|
338
|
+
* since the upload's begin names its size, and a second run's parts go up in order.
|
|
334
339
|
*/
|
|
335
340
|
const sendPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, source, advertised, updates, terms) {
|
|
336
341
|
const pushOptions = terms.pushOptions ?? [];
|
|
@@ -348,19 +353,18 @@ const sendPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, source, adve
|
|
|
348
353
|
shallows: [],
|
|
349
354
|
includeTag: false
|
|
350
355
|
};
|
|
351
|
-
const
|
|
356
|
+
const fetched = Effect.map(objects.fetch(listed, {
|
|
352
357
|
request,
|
|
353
358
|
limits
|
|
354
|
-
}), (answer) =>
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
return yield* reportedPush(answer, true, updates);
|
|
359
|
+
}), (answer) => answer.pack);
|
|
360
|
+
const above = pushUploadAbove(advertised.capabilities);
|
|
361
|
+
let first;
|
|
362
|
+
let chunks = [];
|
|
363
|
+
if (wants.length > 0 && above === void 0) first = yield* fetched;
|
|
364
|
+
else if (wants.length > 0 && above !== void 0) {
|
|
365
|
+
const read = yield* Effect.flatMap(fetched, (pack) => heldOrCounted(pack, above));
|
|
366
|
+
if (read.kind === "counted") return yield* uploaded(http, Effect.flatMap(fetched, (pack) => packInOrder(pack, read.bytes)), updates, terms);
|
|
367
|
+
chunks = read.chunks;
|
|
364
368
|
}
|
|
365
369
|
const sideBand = offered("side-band-64k");
|
|
366
370
|
const capabilities = [
|
|
@@ -381,8 +385,26 @@ const sendPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, source, adve
|
|
|
381
385
|
capabilities,
|
|
382
386
|
pushOptions
|
|
383
387
|
}));
|
|
384
|
-
|
|
385
|
-
|
|
388
|
+
if (first === void 0) {
|
|
389
|
+
const body = yield* http.post("git-receive-pack", "v0", joinedBytes([start, ...chunks]));
|
|
390
|
+
return yield* reportedPush(body, sideBand, updates);
|
|
391
|
+
}
|
|
392
|
+
const streamed = fetchedBody(start, first, fetched, yield* Effect.context());
|
|
393
|
+
const brokeOr = (answer) => streamed.broke.broke ? brokenBy(streamed.broke.cause) : answer;
|
|
394
|
+
return yield* http.post("git-receive-pack", "v0", streamed.open).pipe(Effect.flatMap((body) => reportedPush(body, sideBand, updates)), Effect.ensuring(streamed.unsent), Effect.catch((error) => brokeOr(Effect.fail(error))), Effect.flatMap((updated) => brokeOr(Effect.succeed(updated))));
|
|
395
|
+
});
|
|
396
|
+
/** `pack` uploaded to the remote's bucket for `updates`, as `terms` send them, and its report. */
|
|
397
|
+
const uploaded = /* @__PURE__ */ Effect.fnUntraced(function* (http, pack, updates, terms) {
|
|
398
|
+
const answer = yield* Effect.scoped(Effect.flatMap(pack, (source) => {
|
|
399
|
+
const begin = {
|
|
400
|
+
bytes: source.bytes,
|
|
401
|
+
updates
|
|
402
|
+
};
|
|
403
|
+
if (terms.pushOptions !== void 0 && terms.pushOptions.length > 0) begin.pushOptions = terms.pushOptions;
|
|
404
|
+
if (terms.atomic === true) begin.atomic = true;
|
|
405
|
+
return uploadPush(http, begin, source);
|
|
406
|
+
}));
|
|
407
|
+
return yield* reportedPush(answer, true, updates);
|
|
386
408
|
});
|
|
387
409
|
/** Each of `updates` as the remote's report in `body` answers it, on side-band-64k or bare. */
|
|
388
410
|
const reportedPush = /* @__PURE__ */ Effect.fnUntraced(function* (body, sideBand, updates) {
|
|
@@ -4,7 +4,7 @@ import { onBand } from "../protocol/framing/band.mjs";
|
|
|
4
4
|
import { pushUploadAbove } from "../protocol/wire/push-uploads.mjs";
|
|
5
5
|
import { gitHttp } from "./git-http.mjs";
|
|
6
6
|
import { helperNode, nodeLocalGit, spooled } from "./helper-node.mjs";
|
|
7
|
-
import { packInMemory } from "./push-upload.mjs";
|
|
7
|
+
import { packHeldMost, packInMemory } from "./push-upload.mjs";
|
|
8
8
|
import { helperAdvertisement, readHelperStart, relayPush } from "./remote-helper.mjs";
|
|
9
9
|
import { controlsAllowed, maskedControls, secretScrubber } from "./scrub.mjs";
|
|
10
10
|
import { packPastLimits } from "./slice-push.mjs";
|
|
@@ -78,14 +78,14 @@ const spoolFile = Effect.gen(function* () {
|
|
|
78
78
|
const writeAll = /* @__PURE__ */ Effect.fnUntraced(function* (file, chunk) {
|
|
79
79
|
for (let at = 0; at < chunk.length;) at += (yield* Effect.promise(() => file.write(chunk.subarray(at)))).bytesWritten;
|
|
80
80
|
});
|
|
81
|
-
/** The pack, the input's rest: in memory, or spooled once it's past `spillAbove
|
|
81
|
+
/** The pack, the input's rest: in memory, or spooled once it's past `spillAbove` bytes. */
|
|
82
82
|
const packOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, spillAbove) {
|
|
83
83
|
const chunks = [];
|
|
84
84
|
let bytes = 0;
|
|
85
85
|
let file;
|
|
86
86
|
const add = Effect.fnUntraced(function* (chunk) {
|
|
87
87
|
bytes += chunk.length;
|
|
88
|
-
if (file === void 0 &&
|
|
88
|
+
if (file === void 0 && bytes > spillAbove) {
|
|
89
89
|
file = yield* spoolFile;
|
|
90
90
|
for (const held of chunks.splice(0)) yield* writeAll(file, held);
|
|
91
91
|
}
|
|
@@ -174,7 +174,7 @@ const push = (calls, input, url, { out, err }, hide) => {
|
|
|
174
174
|
const { start, packFollows } = read;
|
|
175
175
|
const startBytes = input.held.subarray(0, start.packOffset);
|
|
176
176
|
input.held = input.held.subarray(start.packOffset);
|
|
177
|
-
const spillAbove = pushUploadAbove(advertised.capabilities);
|
|
177
|
+
const spillAbove = Math.min(pushUploadAbove(advertised.capabilities) ?? Infinity, packHeldMost);
|
|
178
178
|
const pack = packFollows ? yield* packOf(input, spillAbove) : packInMemory(/* @__PURE__ */ new Uint8Array());
|
|
179
179
|
const sliced = packFollows && (yield* packPastLimits(advertised.capabilities, pack));
|
|
180
180
|
const sideBand = start.capabilities.includes("side-band-64k");
|
|
@@ -39,23 +39,33 @@ const authorization = (credential) => "token" in credential ? `Bearer ${credenti
|
|
|
39
39
|
const credentialsFailed = /* @__PURE__ */ gitError("UNAUTHENTICATED", "The credentials function failed, so nothing was sent", { hint: "Check the credential helper or the function the client was given" });
|
|
40
40
|
const credentialOf = (credentials) => Predicate.isFunction(credentials) ? Effect.tryPromise({
|
|
41
41
|
try: async (signal) => credentials({ signal }),
|
|
42
|
-
catch: () =>
|
|
43
|
-
kind: "refused",
|
|
44
|
-
error: credentialsFailed
|
|
45
|
-
})
|
|
42
|
+
catch: () => credentialsFailed
|
|
46
43
|
}) : Effect.succeed(credentials);
|
|
47
44
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
45
|
+
* The `authorization` header `credentials` sends, read afresh from a function: none without
|
|
46
|
+
* credentials. One that fails is `credentialsFailed`, and one no header carries `credentialRefused`,
|
|
47
|
+
* both before anything is sent.
|
|
48
|
+
*/
|
|
49
|
+
const credentialHeader = (credentials) => Effect.flatMap(credentialOf(credentials), (credential) => {
|
|
50
|
+
if (credential === void 0) return Effect.succeed(void 0);
|
|
51
|
+
const value = authorization(credential);
|
|
52
|
+
return unsendable.test(value) ? Effect.fail(credentialRefused) : Effect.succeed(value);
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* The request to send, with the credential's header value, aborted with `signal` or with the
|
|
56
|
+
* request's own: the caller's, which still holds while the answer's body is read. A request is
|
|
57
|
+
* sent as a copy, so it's never read; one made afresh is sent itself.
|
|
50
58
|
*/
|
|
51
59
|
const signed = (request, credential, signal) => {
|
|
52
|
-
const
|
|
60
|
+
const made = request instanceof Request ? request.clone() : request();
|
|
61
|
+
const headers = new Headers(made.headers);
|
|
53
62
|
if (credential !== void 0) headers.set("authorization", credential);
|
|
54
|
-
return new Request(
|
|
63
|
+
return new Request(made, {
|
|
55
64
|
headers,
|
|
56
|
-
signal: AbortSignal.any([
|
|
65
|
+
signal: AbortSignal.any([made.signal, signal])
|
|
57
66
|
});
|
|
58
67
|
};
|
|
68
|
+
/** Whether `retry` sends a request again after `failure`, its try `attempt`. */
|
|
59
69
|
const shouldRetry = (retry, attempt, failure) => {
|
|
60
70
|
if (retry === void 0 || failure.status === 401) return false;
|
|
61
71
|
if (Predicate.isFunction(retry)) return retry({
|
|
@@ -181,7 +191,8 @@ const refusalOf = (response, failureOf) => {
|
|
|
181
191
|
* The remote at `options`: each request sent through `options.transport`, or `fetch`, with the
|
|
182
192
|
* credential, again as `retry` says, and once more with a fresh credential after a 401 when
|
|
183
193
|
* `credentials` is a function. `failureOf` reads what a refused answer said: REST's JSON, or
|
|
184
|
-
* Git's line of text. Each send is a clone, so `request` itself is never read
|
|
194
|
+
* Git's line of text. Each send is a clone, so `request` itself is never read, or a request made
|
|
195
|
+
* afresh, when `request` makes one.
|
|
185
196
|
*/
|
|
186
197
|
const remoteFetch = (options, failureOf) => {
|
|
187
198
|
const send = options.transport ?? (async (request) => fetch(request));
|
|
@@ -202,14 +213,10 @@ const remoteFetch = (options, failureOf) => {
|
|
|
202
213
|
onSuccess: (response) => response.status < 400 ? Effect.succeed(response) : Effect.flatMap(refusalOf(response, failureOf), (failure) => again(failure, Effect.succeed(response), dropped(response)))
|
|
203
214
|
}));
|
|
204
215
|
};
|
|
205
|
-
const signedTries = (request) =>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
error: credentialRefused
|
|
210
|
-
});
|
|
211
|
-
return tries(request, value, 1);
|
|
212
|
-
});
|
|
216
|
+
const signedTries = (request) => credentialHeader(options.credentials).pipe(Effect.mapError((error) => ({
|
|
217
|
+
kind: "refused",
|
|
218
|
+
error
|
|
219
|
+
})), Effect.flatMap((value) => tries(request, value, 1)));
|
|
213
220
|
return (request) => Effect.flatMap(signedTries(request), (response) => response.status === 401 && Predicate.isFunction(options.credentials) ? Effect.andThen(dropped(response), signedTries(request)) : Effect.succeed(response));
|
|
214
221
|
};
|
|
215
|
-
export { abortable, bodyStart, bodyText, credentialRefused, credentialsFailed, dropped, remoteFetch };
|
|
222
|
+
export { abortable, bodyStart, bodyText, credentialHeader, credentialRefused, credentialsFailed, dropped, pauseOf, remoteFetch, shouldRetry, unanswered };
|