@ref0/git 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/calls-spent.d.mts +2 -12
- package/dist/contracts/calls-spent.mjs +4 -5
- package/dist/contracts/client.d.mts +16 -9
- package/dist/contracts/events.d.mts +82 -14
- package/dist/contracts/events.mjs +35 -9
- 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/git.d.mts +13 -3
- 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 +38 -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 +6 -5
- package/dist/contracts/queue.mjs +9 -20
- 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/ancestry.mjs +5 -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/index-job.mjs +23 -1
- package/dist/core/index-lost.d.mts +11 -0
- package/dist/core/index-lost.mjs +55 -0
- package/dist/core/loose-tally.mjs +46 -0
- package/dist/core/objects/commit-writes.mjs +1 -1
- package/dist/core/objects/commits.mjs +10 -9
- package/dist/core/objects/merges.mjs +1 -1
- package/dist/core/objects/reading.mjs +28 -13
- package/dist/core/objects/trees.mjs +1 -1
- package/dist/core/objects/writing.mjs +1 -0
- package/dist/core/parts.d.mts +7 -0
- package/dist/core/promise.mjs +1 -15
- package/dist/core/publish.mjs +9 -5
- package/dist/core/purge.mjs +30 -12
- package/dist/core/push.mjs +39 -16
- package/dist/core/ref-view.mjs +14 -6
- package/dist/core/repack.mjs +54 -27
- 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/core/view.d.mts +10 -1
- package/dist/core/view.mjs +15 -6
- package/dist/effect.d.mts +3 -6
- package/dist/effect.mjs +3 -6
- package/dist/engine/commits.mjs +23 -50
- 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 +9 -7
- package/dist/engine/merge.mjs +20 -17
- package/dist/engine/parts.d.mts +1 -0
- package/dist/engine/parts.mjs +1 -1
- package/dist/engine/walk.mjs +15 -11
- package/dist/extend.d.mts +1 -2
- package/dist/extend.mjs +1 -2
- package/dist/http/core-parts.mjs +18 -10
- package/dist/http/handler.mjs +11 -31
- package/dist/http/parts.d.mts +0 -1
- package/dist/index.d.mts +29 -22
- 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 +93 -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 +47 -28
- package/dist/lfs/upload-most.mjs +47 -0
- package/dist/lfs/uploaded.mjs +59 -0
- package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
- package/dist/protocol/bytes/streams.mjs +84 -2
- package/dist/protocol/bytes/text.mjs +6 -1
- package/dist/protocol/diff/read.d.mts +1 -0
- package/dist/protocol/diff/read.mjs +5 -2
- package/dist/protocol/objects/commit.d.mts +7 -0
- package/dist/protocol/objects/commit.mjs +5 -1
- package/dist/protocol/objects/fsck.mjs +6 -3
- package/dist/queue/advance.mjs +77 -18
- package/dist/queue/calls.mjs +4 -14
- package/dist/queue/host.d.mts +4 -0
- package/dist/queue/lanes.mjs +1 -1
- package/dist/queue/layer.mjs +4 -2
- package/dist/queue/limits.mjs +18 -2
- package/dist/queue/rows.mjs +10 -1
- package/dist/queue/schedule.mjs +1 -1
- package/dist/queue/search.mjs +3 -4
- package/dist/queue/trim.mjs +2 -2
- 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 +150 -150
- package/dist/rest/files.d.mts +18 -18
- package/dist/rest/forks.d.mts +77 -89
- 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 +27 -27
- package/dist/rest/repos.d.mts +40 -52
- package/dist/rest/tokens.d.mts +12 -12
- package/dist/rest/topics.d.mts +13 -13
- package/dist/rest/trees.d.mts +66 -66
- package/dist/rest/wire.d.mts +20 -2
- package/dist/rest/work.d.mts +39 -39
- 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 +12 -6
- package/dist/server/joined.mjs +3 -2
- package/dist/server/registry.mjs +11 -5
- package/dist/server/server.d.mts +0 -1
- package/dist/server/server.mjs +42 -49
- 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-bitmaps.mjs +16 -10
- package/dist/storage/index-build.mjs +160 -24
- package/dist/storage/index-graph.d.mts +1 -0
- package/dist/storage/index-graph.mjs +29 -5
- package/dist/storage/index-layers.d.mts +1 -0
- package/dist/storage/index-layers.mjs +5 -2
- package/dist/storage/index-reach.mjs +7 -5
- package/dist/storage/index-remap.mjs +5 -5
- package/dist/storage/index-visible.mjs +16 -5
- package/dist/storage/lfs-pointers.d.mts +5 -5
- package/dist/storage/lfs-pointers.mjs +37 -11
- package/dist/storage/links.mjs +3 -3
- 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-order.d.mts +1 -0
- package/dist/storage/pack-order.mjs +18 -1
- package/dist/storage/pack-receive.mjs +10 -6
- package/dist/storage/packs.mjs +58 -27
- package/dist/storage/prune-walk.mjs +5 -2
- package/dist/storage/prune.mjs +168 -70
- package/dist/storage/ready.d.mts +1 -1
- package/dist/storage/ready.mjs +12 -3
- package/dist/storage/receive-bounds.mjs +3 -2
- 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/storage/visible.mjs +3 -2
- package/dist/storage/walk.d.mts +1 -0
- package/dist/storage/walk.mjs +9 -5
- package/dist/storage/wants.mjs +17 -11
- package/dist/store/call-count.d.mts +31 -3
- package/dist/store/call-count.mjs +51 -20
- package/dist/store/errors.d.mts +7 -1
- package/dist/store/errors.mjs +7 -1
- package/dist/store/job-try.mjs +3 -1
- package/dist/store/records.mjs +26 -5
- package/dist/store/repo-record.mjs +36 -12
- package/dist/store/scopes.mjs +15 -2
- package/dist/sync/bound.d.mts +1 -1
- package/dist/sync/import.mjs +15 -3
- package/dist/sync/layer.d.mts +5 -1
- package/dist/sync/layer.mjs +11 -9
- package/dist/sync/mirror.mjs +1 -1
- package/dist/sync/step.mjs +15 -15
- package/dist/topics/advance.mjs +11 -10
- package/dist/topics/layer.mjs +1 -1
- 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/rest/client.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
2
|
import { gitError, gitErrorFrom, isGitError } from "../contracts/result.mjs";
|
|
3
3
|
import { streamOf } from "../protocol/bytes/streams.mjs";
|
|
4
4
|
import { heldBytes } from "../protocol/objects/held.mjs";
|
|
5
5
|
import { queueIdParts } from "../queue/ids.mjs";
|
|
6
6
|
import { GitRestApi } from "./api.mjs";
|
|
7
|
-
import { abortable, credentialRefused,
|
|
7
|
+
import { abortable, credentialHeader, credentialRefused, pauseOf, shouldRetry, unanswered } from "../client/transport.mjs";
|
|
8
8
|
import { jsonError, restFailure } from "./errors.mjs";
|
|
9
9
|
import { listenOver } from "./listen.mjs";
|
|
10
10
|
import { readableUrl } from "./paths.mjs";
|
|
@@ -13,24 +13,38 @@ import * as HttpClient from "effect/http/HttpClient";
|
|
|
13
13
|
import * as HttpClientResponse from "effect/http/HttpClientResponse";
|
|
14
14
|
import * as Option from "effect/Option";
|
|
15
15
|
import * as Schema from "effect/Schema";
|
|
16
|
-
import * as Cause from "effect/Cause";
|
|
17
16
|
import * as Exit from "effect/Exit";
|
|
18
17
|
import * as Predicate from "effect/Predicate";
|
|
19
18
|
import * as Context from "effect/Context";
|
|
19
|
+
import * as Layer from "effect/Layer";
|
|
20
20
|
import * as Stream from "effect/Stream";
|
|
21
|
+
import * as Scope from "effect/Scope";
|
|
21
22
|
import { HttpApiClient } from "effect/http-api";
|
|
22
23
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
23
24
|
import * as HttpClientError from "effect/http/HttpClientError";
|
|
24
25
|
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
25
26
|
// src/rest/client.ts
|
|
27
|
+
var client_exports = /* @__PURE__ */ __exportAll({
|
|
28
|
+
RestClient: () => RestClient,
|
|
29
|
+
layer: () => layer,
|
|
30
|
+
make: () => make
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* A REST client of one remote as a service, for a program that's handed one: with `RestClient`
|
|
34
|
+
* from `@ref0/git`, `RestClient.layer(options)` provides it.
|
|
35
|
+
*/
|
|
36
|
+
var RestClient = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/RestClient")) {};
|
|
26
37
|
const statusError = (status) => {
|
|
27
38
|
if (status === 502 || status === 503) return gitError("UNAVAILABLE", `The remote answered ${status}`);
|
|
28
39
|
if (status === 504) return gitError("DEADLINE_EXCEEDED", "The remote answered 504");
|
|
29
40
|
if (status === 401) return gitError("UNAUTHENTICATED", "The remote answered 401");
|
|
30
41
|
return gitError("INTERNAL", `The remote answered ${status}, which REST doesn't send`);
|
|
31
42
|
};
|
|
32
|
-
/**
|
|
33
|
-
|
|
43
|
+
/**
|
|
44
|
+
* What an `HttpClientError` carries that may be a cause: the transport's or the body's own error,
|
|
45
|
+
* never the error itself, whose request holds the credential.
|
|
46
|
+
*/
|
|
47
|
+
const reasonCause = (error) => Predicate.hasProperty(error.reason, "cause") ? error.reason.cause : void 0;
|
|
34
48
|
/**
|
|
35
49
|
* What the typed client failed with, as a `GitError`: the remote's own, or what kept it away. A
|
|
36
50
|
* schema's failure before the request was `sent` is the call's input REST can't carry. An
|
|
@@ -39,8 +53,11 @@ const transportCause = (error) => Predicate.isTagged(error.reason, "TransportErr
|
|
|
39
53
|
const gitErrorOf = (error, sent) => {
|
|
40
54
|
if (HttpClientError.isHttpClientError(error)) {
|
|
41
55
|
const { reason } = error;
|
|
42
|
-
if (
|
|
43
|
-
|
|
56
|
+
if (Predicate.isTagged(reason, "TransportError")) {
|
|
57
|
+
const cause = reasonCause(error);
|
|
58
|
+
if (cause === credentialRefused) return credentialRefused;
|
|
59
|
+
return gitError("UNAVAILABLE", "The remote didn't answer", { cause });
|
|
60
|
+
}
|
|
44
61
|
if (Predicate.isTagged(reason, "StatusCodeError")) return statusError(reason.response.status);
|
|
45
62
|
return gitError("INTERNAL", "The remote's answer couldn't be read");
|
|
46
63
|
}
|
|
@@ -53,60 +70,86 @@ const updatedOf = (read) => ({ updates: read.updates.map((outcome) => outcome.ki
|
|
|
53
70
|
...outcome,
|
|
54
71
|
error: gitErrorFrom(outcome.error)
|
|
55
72
|
}) });
|
|
56
|
-
/**
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (Option.isSome(failure)) return {
|
|
64
|
-
kind: "error",
|
|
65
|
-
error: gitErrorOf(failure.value, sent)
|
|
66
|
-
};
|
|
67
|
-
if (signal?.aborted === true && Cause.hasInterruptsOnly(exit.cause)) throw signal.reason;
|
|
68
|
-
throw Cause.squash(exit.cause);
|
|
69
|
-
};
|
|
70
|
-
/** An answer's body as a web stream: the response's own when it has one. */
|
|
71
|
-
const bodyStream = (response) => Option.match(HttpClientResponse.toWeb(response), {
|
|
72
|
-
onNone: () => Stream.toReadableStream(response.stream),
|
|
73
|
-
onSome: (web) => web.body ?? new ReadableStream({ start: (controller) => controller.close() })
|
|
73
|
+
/** An answer as `restFailure` reads it: the Web's own, or its body as a Web stream. */
|
|
74
|
+
const webAnswer = (response) => Option.match(HttpClientResponse.toWeb(response), {
|
|
75
|
+
onNone: () => Effect.map(Stream.toReadableStreamEffect(response.stream), (body) => new Response(body, {
|
|
76
|
+
status: response.status,
|
|
77
|
+
headers: response.headers
|
|
78
|
+
})),
|
|
79
|
+
onSome: (web) => Effect.succeed(web)
|
|
74
80
|
});
|
|
75
|
-
/**
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
/** What a refused answer said, read once within `restFailure`'s bound. */
|
|
82
|
+
const failureOf = (response) => Effect.flatMap(webAnswer(response), restFailure);
|
|
83
|
+
/** A refusal as the typed client reads it: what was read, sent on as JSON, or its status alone. */
|
|
84
|
+
const refusedAnswer = (request, failure) => HttpClientResponse.fromWeb(request, failure.error === void 0 ? new Response(null, { status: failure.status }) : jsonError(failure.error));
|
|
85
|
+
/** A failure before anything was sent, as the transport's: `gitErrorOf` answers its cause. */
|
|
86
|
+
const unsent = (request, cause) => new HttpClientError.HttpClientError({ reason: new HttpClientError.TransportError({
|
|
87
|
+
request,
|
|
88
|
+
cause
|
|
89
|
+
}) });
|
|
80
90
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
91
|
+
* The remote at `options` over `base`: each request with the credential, again as `retry` says,
|
|
92
|
+
* and once more with a fresh credential after a 401 when `credentials` is a function. A refused
|
|
93
|
+
* answer is read once, within `restFailure`'s bound, so its body is never read past it.
|
|
83
94
|
*/
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
const remoteHttp = (options, base) => {
|
|
96
|
+
const tries = (request, attempt) => {
|
|
97
|
+
/** The next try when `retry` takes `failure`, after a pause; else `answer`. */
|
|
98
|
+
const again = (failure, answer) => shouldRetry(options.retry, attempt, failure) ? Effect.andThen(Effect.sleep(pauseOf(attempt)), tries(request, attempt + 1)) : answer;
|
|
99
|
+
return base.execute(request).pipe(Effect.matchEffect({
|
|
100
|
+
onFailure: (error) => Predicate.isTagged(error.reason, "TransportError") ? again(unanswered, Effect.fail(error)) : Effect.fail(error),
|
|
101
|
+
onSuccess: (response) => response.status < 400 ? Effect.succeed(response) : Effect.flatMap(failureOf(response), (failure) => again(failure, Effect.succeed(refusedAnswer(request, failure))))
|
|
102
|
+
}));
|
|
103
|
+
};
|
|
104
|
+
const signedTries = (request) => credentialHeader(options.credentials).pipe(Effect.mapError((error) => unsent(request, error)), Effect.flatMap((value) => tries(value === void 0 ? request : HttpClientRequest.setHeader(request, "authorization", value), 1)));
|
|
105
|
+
return HttpClient.makeWith((prepared) => Effect.flatMap(prepared, (request) => Effect.flatMap(signedTries(request), (response) => response.status === 401 && Predicate.isFunction(options.credentials) ? signedTries(request) : Effect.succeed(response))), Effect.succeed).pipe(HttpClient.mapRequest((request) => HttpClientRequest.prependUrl(HttpClientRequest.setUrl(request, readableUrl(request.url)), options.url)));
|
|
90
106
|
};
|
|
91
|
-
/**
|
|
92
|
-
|
|
107
|
+
/**
|
|
108
|
+
* `transport` as an `HttpClient`: `effect/http`'s fetch client, sending through it. Each answer's
|
|
109
|
+
* body ends with its request's signal, as `fetch`'s does, though the transport ignores it.
|
|
110
|
+
*/
|
|
111
|
+
const transportHttp = (transport) => Effect.map(Effect.provide(HttpClient.HttpClient, FetchHttpClient.layer), (fetched) => HttpClient.transform(fetched, (effect) => Effect.provideService(effect, FetchHttpClient.Fetch, async (input, init) => {
|
|
112
|
+
const request = new Request(input, init);
|
|
113
|
+
return abortable(await transport(request), request.signal);
|
|
114
|
+
})));
|
|
115
|
+
/**
|
|
116
|
+
* One call's client: the remote's, which `run` provides to the shared typed client. Each request
|
|
117
|
+
* lives as long as the scope it's sent in, so its answer's body ends once nothing holds it.
|
|
118
|
+
*/
|
|
119
|
+
var RestHttp = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/rest/RestHttp")) {};
|
|
120
|
+
/**
|
|
121
|
+
* `HttpApiClient` over `GitRestApi`: made once for every client, since making it compiles each
|
|
122
|
+
* route's codecs, as long as about 75 calls take. Each request goes through its call's `RestHttp`.
|
|
123
|
+
*/
|
|
124
|
+
const typedApi = () => HttpApiClient.makeWith(GitRestApi, { httpClient: HttpClient.makeWith((prepared) => Effect.flatMap(prepared, (request) => Effect.flatMap(RestHttp, (http) => http.execute(request))), Effect.succeed) });
|
|
125
|
+
let shared;
|
|
126
|
+
/** A blob's body checked against its `content-length`, `size`: short or broken, it's `DATA_LOSS`. */
|
|
127
|
+
const checkedBody = (oid, size, body) => Stream.suspend(() => {
|
|
128
|
+
let seen = 0;
|
|
129
|
+
const lost = () => gitError("DATA_LOSS", `Blob ${oid}'s body ended at ${seen} of its ${size} bytes`);
|
|
130
|
+
return body.pipe(Stream.tap((chunk) => Effect.sync(() => {
|
|
131
|
+
seen += chunk.byteLength;
|
|
132
|
+
})), Stream.mapError((error) => gitErrorFrom(lost(), { cause: reasonCause(error) })), Stream.concat(Stream.suspend(() => seen === size ? Stream.empty : Stream.fail(lost()))));
|
|
133
|
+
});
|
|
134
|
+
/** `stream` as a caller reads bytes: a Web stream that pulls nothing ahead of its reads. */
|
|
135
|
+
const webBytes = (stream) => Stream.toReadableStreamEffect(stream, { strategy: { highWaterMark: 0 } });
|
|
136
|
+
/** A call's input as a GET's query: its page's fields beside its filters. */
|
|
137
|
+
const queryOf = ({ page, ...filters }) => ({
|
|
93
138
|
...filters,
|
|
94
139
|
...page
|
|
95
140
|
});
|
|
96
141
|
/** A read's input as a GET's query: its page's and its limits' fields beside its filters. */
|
|
97
|
-
const readQuery = ({
|
|
142
|
+
const readQuery = ({ page, limits, ...filters }) => ({
|
|
98
143
|
...filters,
|
|
99
144
|
...page,
|
|
100
145
|
...limits
|
|
101
146
|
});
|
|
102
147
|
/** A read of one object's input as a GET's query: its ID goes in the path. */
|
|
103
|
-
const objectQuery = ({
|
|
148
|
+
const objectQuery = ({ oid: _oid, page, limits, ...filters }) => ({
|
|
104
149
|
...filters,
|
|
105
150
|
...page,
|
|
106
151
|
...limits
|
|
107
152
|
});
|
|
108
|
-
/** A call's input as a JSON body: everything but `signal`. */
|
|
109
|
-
const bodyOf = ({ signal: _signal, ...body }) => body;
|
|
110
153
|
/** An edit as a body sends it: bytes as `contentBytes`, base64, and text as `content`. */
|
|
111
154
|
const wireEdit = ({ content, ...edit }) => {
|
|
112
155
|
if (content === void 0) return edit;
|
|
@@ -118,480 +161,363 @@ const wireEdit = ({ content, ...edit }) => {
|
|
|
118
161
|
content
|
|
119
162
|
};
|
|
120
163
|
};
|
|
121
|
-
const tokenBody = ({
|
|
164
|
+
const tokenBody = ({ expiresAt, ...body }) => ({
|
|
122
165
|
...body,
|
|
123
166
|
expiresAt: expiresAt instanceof Date ? expiresAt.getTime() : expiresAt
|
|
124
167
|
});
|
|
125
168
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* one. It carries none of REST's serving code.
|
|
129
|
-
*/
|
|
130
|
-
/** A blob's bytes read whole, up to the most a blob takes: past it `object-too-large`. */
|
|
131
|
-
const heldOf = (bytes, signal) => Effect.runPromise(heldBytes(bytes, "blob").pipe(Effect.match({
|
|
132
|
-
onFailure: (error) => ({
|
|
133
|
-
kind: "error",
|
|
134
|
-
error
|
|
135
|
-
}),
|
|
136
|
-
onSuccess: (value) => ({
|
|
137
|
-
kind: "success",
|
|
138
|
-
value
|
|
139
|
-
})
|
|
140
|
-
})), signal === void 0 ? void 0 : { signal });
|
|
141
|
-
/**
|
|
142
|
-
* A blob's body checked against its `content-length`, `size`: one that ends short of it, or
|
|
143
|
-
* breaks, as a server's does when the bytes it streams fail their ID, errors with `DATA_LOSS`. A
|
|
144
|
-
* break `signal` caused keeps its own error.
|
|
145
|
-
*/
|
|
146
|
-
/**
|
|
147
|
-
* Whether `signal`'s abort ended a read that failed with `cause`: the abort's reason itself, or
|
|
148
|
-
* wrapped as the cause of the HTTP adapter's error.
|
|
149
|
-
*/
|
|
150
|
-
const abortedBy = (signal, cause) => signal?.aborted === true && (cause === signal.reason || Predicate.hasProperty(cause, "cause") && cause.cause === signal.reason);
|
|
151
|
-
const checkedBody = (oid, size, body, signal) => {
|
|
152
|
-
const { reader, close } = ownedReader(body);
|
|
153
|
-
let seen = 0;
|
|
154
|
-
const lost = () => gitError("DATA_LOSS", `Blob ${oid}'s body ended at ${seen} of its ${size} bytes`);
|
|
155
|
-
return new ReadableStream({
|
|
156
|
-
pull: async (controller) => {
|
|
157
|
-
const next = await reader.read().catch((cause) => {
|
|
158
|
-
close();
|
|
159
|
-
throw abortedBy(signal, cause) ? signal?.reason : gitErrorFrom(lost(), { cause });
|
|
160
|
-
});
|
|
161
|
-
if (!next.done) {
|
|
162
|
-
seen += next.value.byteLength;
|
|
163
|
-
return controller.enqueue(next.value);
|
|
164
|
-
}
|
|
165
|
-
close();
|
|
166
|
-
if (seen === size) return controller.close();
|
|
167
|
-
controller.error(lost());
|
|
168
|
-
},
|
|
169
|
-
cancel: (reason) => {
|
|
170
|
-
reader.cancel(reason).catch(() => void 0);
|
|
171
|
-
close();
|
|
172
|
-
}
|
|
173
|
-
}, { highWaterMark: 0 });
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* A stream that reads nothing until its first pull, then `open`'s bytes; a refusal errors it.
|
|
177
|
-
* `open` takes a signal that `signal` and a cancel abort, so a cancel stops its call and ends any
|
|
178
|
-
* body it answers, as `run` does for each call's signal.
|
|
169
|
+
* An events answer's body, as EventSource takes one: a 200 of `text/event-stream`. Any other
|
|
170
|
+
* answer under 400 isn't REST's stream.
|
|
179
171
|
*/
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
return
|
|
185
|
-
|
|
186
|
-
if (held === void 0) {
|
|
187
|
-
const opened = await open(stopped);
|
|
188
|
-
if (opened.kind === "error") return controller.error(opened.error);
|
|
189
|
-
held = ownedReader(opened.value);
|
|
190
|
-
if (stopped.aborted) {
|
|
191
|
-
held.close();
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
const next = await held.reader.read().catch((cause) => {
|
|
196
|
-
held?.close();
|
|
197
|
-
throw cause;
|
|
198
|
-
});
|
|
199
|
-
if (next.done) {
|
|
200
|
-
held.close();
|
|
201
|
-
return controller.close();
|
|
202
|
-
}
|
|
203
|
-
controller.enqueue(next.value);
|
|
204
|
-
},
|
|
205
|
-
cancel: async (reason) => {
|
|
206
|
-
cancelled.abort(reason);
|
|
207
|
-
if (held !== void 0) {
|
|
208
|
-
held.reader.cancel(reason).catch(() => void 0);
|
|
209
|
-
held.close();
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}, { highWaterMark: 0 });
|
|
172
|
+
const eventStreamOf = (response) => {
|
|
173
|
+
const type = response.headers["content-type"] ?? "";
|
|
174
|
+
const media = type.split(";")[0]?.trim().toLowerCase();
|
|
175
|
+
if (response.status === 200 && media === "text/event-stream") return Effect.succeed(Stream.mapError(response.stream, (error) => gitError("UNAVAILABLE", "The remote's event stream broke", { cause: reasonCause(error) })));
|
|
176
|
+
if (response.status >= 400) return Effect.flatMap(failureOf(response), ({ status, error }) => Effect.fail(error ?? statusError(status)));
|
|
177
|
+
return Effect.fail(gitError("INTERNAL", `The remote answered ${response.status} of '${type}', not an event stream`));
|
|
213
178
|
};
|
|
214
|
-
/** The
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
* `HttpApiClient` over `GitRestApi`, and REST's events stream: made once for every client, since
|
|
218
|
-
* making them compiles each route's codecs, as long as about 75 calls take. Each request's path is
|
|
219
|
-
* made readable, then put under the call's `RestBase`, and goes through the `fetch` `run` provides.
|
|
220
|
-
*/
|
|
221
|
-
const shareable = () => Effect.runSync(Effect.gen(function* () {
|
|
222
|
-
const http = (yield* HttpClient.HttpClient).pipe(HttpClient.mapRequest((request) => HttpClientRequest.setUrl(request, readableUrl(request.url))), HttpClient.mapRequestEffect((request) => Effect.map(RestBase, (url) => HttpClientRequest.prependUrl(request, url))));
|
|
223
|
-
return {
|
|
224
|
-
api: yield* HttpApiClient.makeWith(GitRestApi, { httpClient: http }),
|
|
225
|
-
http
|
|
226
|
-
};
|
|
227
|
-
}).pipe(Effect.provide(FetchHttpClient.layer)));
|
|
228
|
-
let shared;
|
|
229
|
-
const createRestClient = (options) => {
|
|
230
|
-
shared ??= shareable();
|
|
231
|
-
const { api: client, http } = shared;
|
|
232
|
-
const remote = remoteFetch(options, restFailure);
|
|
233
|
-
/** `fetch` as the typed client calls it: the remote's sends, rejecting with no answer's cause. */
|
|
234
|
-
const remoteThrough = async (input, init) => {
|
|
235
|
-
const runOptions = init?.signal == null ? void 0 : { signal: init.signal };
|
|
236
|
-
const answer = await Effect.runPromise(remote(new Request(input, init)).pipe(Effect.match({
|
|
237
|
-
onFailure: (failed) => ({
|
|
238
|
-
kind: "unanswered",
|
|
239
|
-
cause: failed.kind === "refused" ? failed.error : failed.cause
|
|
240
|
-
}),
|
|
241
|
-
onSuccess: (response) => ({
|
|
242
|
-
kind: "answered",
|
|
243
|
-
response
|
|
244
|
-
})
|
|
245
|
-
})), runOptions);
|
|
246
|
-
if (answer.kind === "unanswered") throw answer.cause;
|
|
247
|
-
if (answer.response.status < 400) return answer.response;
|
|
248
|
-
const { status, error } = await Effect.runPromise(restFailure(answer.response), runOptions);
|
|
249
|
-
return error === void 0 ? new Response(null, { status }) : jsonError(error);
|
|
250
|
-
};
|
|
179
|
+
/** The REST calls of `remote`, each through `api`, the typed client every remote shares. */
|
|
180
|
+
const callsOf = (api, remote) => {
|
|
181
|
+
const scoped = HttpClient.withScope(remote);
|
|
251
182
|
/**
|
|
252
|
-
* Runs one call, noting once its request is sent, so its input's
|
|
253
|
-
*
|
|
183
|
+
* Runs one call in the scope it's given, noting once its request is sent, so its input's
|
|
184
|
+
* failure is told apart from its answer's.
|
|
254
185
|
*/
|
|
255
|
-
const
|
|
186
|
+
const held = (call) => Effect.suspend(() => {
|
|
256
187
|
let sent = false;
|
|
257
|
-
const noted =
|
|
188
|
+
const noted = HttpClient.tapRequest(scoped, () => Effect.sync(() => {
|
|
258
189
|
sent = true;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
190
|
+
}));
|
|
191
|
+
return call(api).pipe(Effect.provideService(RestHttp, noted), Effect.mapError((error) => gitErrorOf(error, sent)));
|
|
192
|
+
});
|
|
193
|
+
/** One call, its request ended as the call ends, its answer read by then. */
|
|
194
|
+
const run = (call) => Effect.scoped(held(call));
|
|
195
|
+
/**
|
|
196
|
+
* A blob's size and its bytes as a stream, checked against its size as they're read. Its
|
|
197
|
+
* request lives in the scope it's given, which its reader closes.
|
|
198
|
+
*/
|
|
199
|
+
const blobStream = (repo, input) => held((typed) => Effect.map(typed.blobs.get({
|
|
267
200
|
params: {
|
|
268
201
|
repo,
|
|
269
202
|
oid: input.oid
|
|
270
203
|
},
|
|
271
204
|
query: objectQuery(input)
|
|
272
|
-
})
|
|
205
|
+
}), ({ body, headers }) => {
|
|
273
206
|
const size = headers["content-length"];
|
|
274
|
-
const bytes = checkedBody(input.oid, size, Stream.toReadableStream(body), input.signal);
|
|
275
207
|
return {
|
|
276
208
|
oid: input.oid,
|
|
277
209
|
size,
|
|
278
|
-
|
|
210
|
+
stream: checkedBody(input.oid, size, body)
|
|
279
211
|
};
|
|
280
|
-
}))
|
|
212
|
+
}));
|
|
213
|
+
/**
|
|
214
|
+
* A blob's bytes as a Web stream, its request held in a scope of its own: the stream closes it
|
|
215
|
+
* as it ends, is cancelled or fails, and the call does when it fails first.
|
|
216
|
+
*/
|
|
217
|
+
const blobOf = (repo, input) => Effect.uninterruptibleMask((restore) => Effect.flatMap(Scope.make(), (scope) => restore(Scope.provide(blobStream(repo, input), scope)).pipe(Effect.onExit((exit) => Exit.isSuccess(exit) ? Effect.void : Scope.close(scope, exit)), Effect.flatMap(({ oid, size, stream }) => Effect.map(webBytes(Stream.ensuring(stream, Scope.close(scope, Exit.void))), (bytes) => ({
|
|
218
|
+
oid,
|
|
219
|
+
size,
|
|
220
|
+
bytes
|
|
221
|
+
}))))));
|
|
281
222
|
/** `GET <r>/events` after `after`, its `seq` sent as `Last-Event-ID`. */
|
|
282
|
-
const connect = (repo, after
|
|
223
|
+
const connect = (repo, after) => {
|
|
283
224
|
const request = HttpClientRequest.get(`/repos/${encodeURIComponent(repo)}/-/events`).pipe(HttpClientRequest.setHeader("accept", "text/event-stream"), (each) => after === void 0 ? each : HttpClientRequest.setHeader(each, "last-event-id", String(after)));
|
|
284
|
-
return
|
|
225
|
+
return remote.execute(request).pipe(Effect.flatMap(eventStreamOf), Effect.mapError((error) => gitErrorOf(error, true)));
|
|
285
226
|
};
|
|
286
227
|
return {
|
|
287
228
|
repos: {
|
|
288
|
-
list: (input) => run((
|
|
289
|
-
create: (input) => run((
|
|
290
|
-
get: (repo
|
|
291
|
-
update: (repo, input) => run((
|
|
229
|
+
list: (input) => run((typed) => typed.repos.list({ query: queryOf(input) })),
|
|
230
|
+
create: (input) => run((typed) => typed.repos.create({ payload: input })),
|
|
231
|
+
get: (repo) => run((typed) => typed.repos.get({ params: { repo } })),
|
|
232
|
+
update: (repo, input) => run((typed) => typed.repos.update({
|
|
292
233
|
params: { repo },
|
|
293
|
-
payload:
|
|
294
|
-
})
|
|
295
|
-
rename: (repo, input) => run((
|
|
234
|
+
payload: input
|
|
235
|
+
})),
|
|
236
|
+
rename: (repo, input) => run((typed) => typed.repos.rename({
|
|
296
237
|
params: { repo },
|
|
297
|
-
payload:
|
|
298
|
-
})
|
|
299
|
-
delete: (repo, input) => run((
|
|
238
|
+
payload: input
|
|
239
|
+
})),
|
|
240
|
+
delete: (repo, input) => run((typed) => typed.repos.delete({
|
|
300
241
|
params: { repo },
|
|
301
|
-
query:
|
|
302
|
-
})
|
|
242
|
+
query: input
|
|
243
|
+
}))
|
|
303
244
|
},
|
|
304
245
|
forks: {
|
|
305
|
-
create: (repo, input) => run((
|
|
246
|
+
create: (repo, input) => run((typed) => typed.forks.create({
|
|
306
247
|
params: { repo },
|
|
307
|
-
payload:
|
|
308
|
-
})
|
|
309
|
-
get: (repo, input) => run((
|
|
248
|
+
payload: input
|
|
249
|
+
})),
|
|
250
|
+
get: (repo, input) => run((typed) => typed.forks.get({ params: {
|
|
310
251
|
repo,
|
|
311
252
|
holder: input.holder
|
|
312
|
-
} })
|
|
313
|
-
list: (repo, input) => run((
|
|
253
|
+
} })),
|
|
254
|
+
list: (repo, input) => run((typed) => typed.forks.list({
|
|
314
255
|
params: { repo },
|
|
315
256
|
query: queryOf(input)
|
|
316
|
-
})
|
|
317
|
-
sync: (repo, input) => run((
|
|
257
|
+
})),
|
|
258
|
+
sync: (repo, input) => run((typed) => typed.forks.sync({
|
|
318
259
|
params: { repo },
|
|
319
|
-
payload:
|
|
320
|
-
})
|
|
321
|
-
fetch: (repo
|
|
260
|
+
payload: input
|
|
261
|
+
})),
|
|
262
|
+
fetch: (repo) => run((typed) => typed.forks.fetch({ params: { repo } }))
|
|
322
263
|
},
|
|
323
264
|
refs: {
|
|
324
|
-
get: (repo, input) => run((
|
|
265
|
+
get: (repo, input) => run((typed) => typed.refs.get({ params: {
|
|
325
266
|
repo,
|
|
326
267
|
ref: input.ref
|
|
327
|
-
} })
|
|
328
|
-
protection:
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const answer = await run((api) => api.refs.protection({ params }), input.signal);
|
|
334
|
-
if (answer.kind !== "success") return answer;
|
|
335
|
-
return {
|
|
336
|
-
kind: "success",
|
|
337
|
-
value: answer.value ?? void 0
|
|
338
|
-
};
|
|
339
|
-
},
|
|
340
|
-
protections: async (repo, input) => {
|
|
341
|
-
const payload = { refs: input.refs };
|
|
342
|
-
const answer = await run((api) => api.refs.protections({
|
|
343
|
-
params: { repo },
|
|
344
|
-
payload
|
|
345
|
-
}), input.signal);
|
|
346
|
-
if (answer.kind !== "success") return answer;
|
|
347
|
-
return {
|
|
348
|
-
kind: "success",
|
|
349
|
-
value: answer.value.map((guard) => guard ?? void 0)
|
|
350
|
-
};
|
|
351
|
-
},
|
|
352
|
-
sees: (repo, input) => run((api) => api.refs.sees({
|
|
268
|
+
} })),
|
|
269
|
+
protection: (repo, input) => run((typed) => Effect.map(typed.refs.protection({ params: {
|
|
270
|
+
repo,
|
|
271
|
+
ref: input.ref
|
|
272
|
+
} }), (guard) => guard ?? void 0)),
|
|
273
|
+
protections: (repo, input) => run((typed) => Effect.map(typed.refs.protections({
|
|
353
274
|
params: { repo },
|
|
354
275
|
payload: { refs: input.refs }
|
|
355
|
-
}),
|
|
356
|
-
|
|
276
|
+
}), (guards) => guards.map((guard) => guard ?? void 0))),
|
|
277
|
+
sees: (repo, input) => run((typed) => typed.refs.sees({
|
|
357
278
|
params: { repo },
|
|
358
|
-
|
|
359
|
-
})
|
|
360
|
-
|
|
279
|
+
payload: { refs: input.refs }
|
|
280
|
+
})),
|
|
281
|
+
list: (repo, input) => run((typed) => typed.refs.list({
|
|
361
282
|
params: { repo },
|
|
362
283
|
query: queryOf(input)
|
|
363
|
-
})
|
|
364
|
-
|
|
284
|
+
})),
|
|
285
|
+
count: (repo, input) => run((typed) => typed.refs.count({
|
|
365
286
|
params: { repo },
|
|
366
|
-
|
|
367
|
-
})
|
|
287
|
+
query: input
|
|
288
|
+
})),
|
|
289
|
+
update: (repo, input) => run((typed) => Effect.map(typed.refs.update({
|
|
290
|
+
params: { repo },
|
|
291
|
+
payload: input
|
|
292
|
+
}), updatedOf))
|
|
368
293
|
},
|
|
369
294
|
work: {
|
|
370
|
-
list: (repo, input) => run((
|
|
295
|
+
list: (repo, input) => run((typed) => typed.work.list({
|
|
371
296
|
params: { repo },
|
|
372
297
|
query: queryOf(input)
|
|
373
|
-
})
|
|
374
|
-
retry: (repo, input) => run((
|
|
298
|
+
})),
|
|
299
|
+
retry: (repo, input) => run((typed) => typed.work.retry({
|
|
375
300
|
params: { repo },
|
|
376
|
-
payload:
|
|
377
|
-
})
|
|
378
|
-
discard: (repo, input) => run((
|
|
301
|
+
payload: input
|
|
302
|
+
})),
|
|
303
|
+
discard: (repo, input) => run((typed) => typed.work.discard({
|
|
379
304
|
params: { repo },
|
|
380
|
-
payload:
|
|
381
|
-
})
|
|
305
|
+
payload: input
|
|
306
|
+
}))
|
|
382
307
|
},
|
|
383
308
|
tokens: {
|
|
384
|
-
create: (target, input) => run((
|
|
309
|
+
create: (target, input) => run((typed) => Predicate.isString(target) ? typed.tokens.createRepo({
|
|
385
310
|
params: { repo: target },
|
|
386
311
|
payload: tokenBody(input)
|
|
387
|
-
}) :
|
|
312
|
+
}) : typed.tokens.createPrefix({
|
|
388
313
|
query: target,
|
|
389
314
|
payload: tokenBody(input)
|
|
390
|
-
})
|
|
391
|
-
list: (target, input = {}) => run((
|
|
315
|
+
})),
|
|
316
|
+
list: (target, input = {}) => run((typed) => Predicate.isString(target) ? typed.tokens.listRepo({
|
|
392
317
|
params: { repo: target },
|
|
393
318
|
query: queryOf(input)
|
|
394
|
-
}) :
|
|
319
|
+
}) : typed.tokens.listPrefix({ query: {
|
|
395
320
|
...target,
|
|
396
321
|
...queryOf(input)
|
|
397
|
-
} })
|
|
398
|
-
get: (token
|
|
399
|
-
revoke: (token, input = {}) => run((
|
|
322
|
+
} })),
|
|
323
|
+
get: (token) => run((typed) => typed.tokens.get({ params: { id: token } })),
|
|
324
|
+
revoke: (token, input = {}) => run((typed) => typed.tokens.revoke({
|
|
400
325
|
params: { id: token },
|
|
401
|
-
query:
|
|
402
|
-
})
|
|
326
|
+
query: input
|
|
327
|
+
}))
|
|
403
328
|
},
|
|
404
329
|
blobs: {
|
|
405
330
|
get: blobOf,
|
|
406
|
-
create:
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
query,
|
|
412
|
-
payload: Stream.succeed(held.value)
|
|
413
|
-
}), signal);
|
|
414
|
-
}
|
|
331
|
+
create: (repo, { bytes, ...query }) => Effect.flatMap(heldBytes(bytes, "blob"), (held) => run((typed) => typed.blobs.create({
|
|
332
|
+
params: { repo },
|
|
333
|
+
query,
|
|
334
|
+
payload: Stream.succeed(held)
|
|
335
|
+
})))
|
|
415
336
|
},
|
|
416
337
|
trees: {
|
|
417
|
-
get: (repo, input) => run((
|
|
338
|
+
get: (repo, input) => run((typed) => typed.trees.get({
|
|
418
339
|
params: {
|
|
419
340
|
repo,
|
|
420
341
|
oid: input.oid
|
|
421
342
|
},
|
|
422
343
|
query: objectQuery(input)
|
|
423
|
-
})
|
|
424
|
-
diff: (repo, input) => run((
|
|
344
|
+
})),
|
|
345
|
+
diff: (repo, input) => run((typed) => typed.trees.diff({
|
|
425
346
|
params: { repo },
|
|
426
|
-
payload:
|
|
427
|
-
})
|
|
428
|
-
create: (repo, { changes, ...input }) => run((
|
|
347
|
+
payload: input
|
|
348
|
+
})),
|
|
349
|
+
create: (repo, { changes, ...input }) => run((typed) => typed.trees.create({
|
|
429
350
|
params: { repo },
|
|
430
351
|
payload: {
|
|
431
|
-
...
|
|
352
|
+
...input,
|
|
432
353
|
changes: changes.map(wireEdit)
|
|
433
354
|
}
|
|
434
|
-
})
|
|
435
|
-
merge: (repo, input) => run((
|
|
355
|
+
})),
|
|
356
|
+
merge: (repo, input) => run((typed) => typed.trees.merge({
|
|
436
357
|
params: { repo },
|
|
437
|
-
payload:
|
|
438
|
-
})
|
|
358
|
+
payload: input
|
|
359
|
+
}))
|
|
439
360
|
},
|
|
440
361
|
commits: {
|
|
441
|
-
get: (repo, input) => run((
|
|
362
|
+
get: (repo, input) => run((typed) => typed.commits.get({
|
|
442
363
|
params: {
|
|
443
364
|
repo,
|
|
444
365
|
oid: input.oid
|
|
445
366
|
},
|
|
446
367
|
query: objectQuery(input)
|
|
447
|
-
})
|
|
448
|
-
list: (repo, input) => run((
|
|
368
|
+
})),
|
|
369
|
+
list: (repo, input) => run((typed) => typed.commits.list({
|
|
449
370
|
params: { repo },
|
|
450
371
|
query: readQuery(input)
|
|
451
|
-
})
|
|
452
|
-
mergeBase: (repo, input) => run((
|
|
372
|
+
})),
|
|
373
|
+
mergeBase: (repo, input) => run((typed) => typed.commits.mergeBase({
|
|
453
374
|
params: { repo },
|
|
454
|
-
payload:
|
|
455
|
-
})
|
|
456
|
-
diff: (repo, input) => run((
|
|
375
|
+
payload: input
|
|
376
|
+
})),
|
|
377
|
+
diff: (repo, input) => run((typed) => typed.commits.diff({
|
|
457
378
|
params: { repo },
|
|
458
|
-
payload:
|
|
459
|
-
})
|
|
460
|
-
compare: (repo, input) => run((
|
|
379
|
+
payload: input
|
|
380
|
+
})),
|
|
381
|
+
compare: (repo, input) => run((typed) => typed.commits.compare({
|
|
461
382
|
params: { repo },
|
|
462
|
-
payload:
|
|
463
|
-
})
|
|
464
|
-
create: (repo, { changes, ...input }) => run((
|
|
383
|
+
payload: input
|
|
384
|
+
})),
|
|
385
|
+
create: (repo, { changes, ...input }) => run((typed) => typed.commits.create({
|
|
465
386
|
params: { repo },
|
|
466
|
-
payload: changes === void 0 ?
|
|
467
|
-
...
|
|
387
|
+
payload: changes === void 0 ? input : {
|
|
388
|
+
...input,
|
|
468
389
|
changes: changes.map(wireEdit)
|
|
469
390
|
}
|
|
470
|
-
})
|
|
471
|
-
revert: (repo, input) => run((
|
|
391
|
+
})),
|
|
392
|
+
revert: (repo, input) => run((typed) => typed.commits.revert({
|
|
472
393
|
params: { repo },
|
|
473
|
-
payload:
|
|
474
|
-
})
|
|
475
|
-
pick: (repo, input) => run((
|
|
394
|
+
payload: input
|
|
395
|
+
})),
|
|
396
|
+
pick: (repo, input) => run((typed) => typed.commits.pick({
|
|
476
397
|
params: { repo },
|
|
477
|
-
payload:
|
|
478
|
-
})
|
|
398
|
+
payload: input
|
|
399
|
+
}))
|
|
479
400
|
},
|
|
480
401
|
tags: {
|
|
481
|
-
get: (repo, input) => run((
|
|
402
|
+
get: (repo, input) => run((typed) => typed.tags.get({
|
|
482
403
|
params: {
|
|
483
404
|
repo,
|
|
484
405
|
oid: input.oid
|
|
485
406
|
},
|
|
486
407
|
query: objectQuery(input)
|
|
487
|
-
})
|
|
488
|
-
peel: (repo, input) => run((
|
|
408
|
+
})),
|
|
409
|
+
peel: (repo, input) => run((typed) => typed.tags.peel({
|
|
489
410
|
params: { repo },
|
|
490
|
-
payload:
|
|
491
|
-
})
|
|
492
|
-
create: (repo, input) => run((
|
|
411
|
+
payload: input
|
|
412
|
+
})),
|
|
413
|
+
create: (repo, input) => run((typed) => typed.tags.create({
|
|
493
414
|
params: { repo },
|
|
494
|
-
payload:
|
|
495
|
-
})
|
|
415
|
+
payload: input
|
|
416
|
+
}))
|
|
496
417
|
},
|
|
497
|
-
merges: { create: (repo, input) => run((
|
|
418
|
+
merges: { create: (repo, input) => run((typed) => typed.merges.create({
|
|
498
419
|
params: { repo },
|
|
499
|
-
payload:
|
|
500
|
-
})
|
|
420
|
+
payload: input
|
|
421
|
+
})) },
|
|
501
422
|
files: {
|
|
502
|
-
list: (repo, input) => run((
|
|
423
|
+
list: (repo, input) => run((typed) => typed.files.list({
|
|
503
424
|
params: { repo },
|
|
504
425
|
query: readQuery(input)
|
|
505
|
-
})
|
|
506
|
-
read: (repo, input) => run((
|
|
507
|
-
params: { repo },
|
|
508
|
-
payload:
|
|
509
|
-
}).pipe(Effect.map((read) => ({
|
|
426
|
+
})),
|
|
427
|
+
read: (repo, input) => run((typed) => typed.files.read({
|
|
428
|
+
params: { repo },
|
|
429
|
+
payload: input
|
|
430
|
+
})).pipe(Effect.flatMap((read) => Effect.map(Effect.forEach(read.files.items, ({ content, ...file }) => Effect.map(content === void 0 ? webBytes(Stream.unwrap(Effect.map(blobStream(repo, { oid: file.oid }), (blob) => blob.stream))) : Effect.succeed(streamOf(content)), (bytes) => ({
|
|
431
|
+
...file,
|
|
432
|
+
bytes
|
|
433
|
+
}))), (items) => ({
|
|
510
434
|
...read,
|
|
511
435
|
files: {
|
|
512
436
|
...read.files,
|
|
513
|
-
items
|
|
514
|
-
...file,
|
|
515
|
-
bytes: content === void 0 ? lazyBytes(async (signal) => {
|
|
516
|
-
const blob = await blobOf(repo, {
|
|
517
|
-
oid: file.oid,
|
|
518
|
-
signal
|
|
519
|
-
});
|
|
520
|
-
return blob.kind === "error" ? blob : {
|
|
521
|
-
...blob,
|
|
522
|
-
value: blob.value.bytes
|
|
523
|
-
};
|
|
524
|
-
}, input.signal) : streamOf(content)
|
|
525
|
-
}))
|
|
437
|
+
items
|
|
526
438
|
}
|
|
527
|
-
})))
|
|
528
|
-
diff: (repo, input) => run((
|
|
439
|
+
})))),
|
|
440
|
+
diff: (repo, input) => run((typed) => typed.files.diff({
|
|
529
441
|
params: { repo },
|
|
530
|
-
payload:
|
|
531
|
-
})
|
|
442
|
+
payload: input
|
|
443
|
+
}))
|
|
532
444
|
},
|
|
533
445
|
queue: {
|
|
534
|
-
add: (repo, input) => run((
|
|
446
|
+
add: (repo, input) => run((typed) => typed.queue.add({
|
|
535
447
|
params: { repo },
|
|
536
|
-
payload:
|
|
537
|
-
})
|
|
538
|
-
list: (repo, input) => run((
|
|
448
|
+
payload: input
|
|
449
|
+
})),
|
|
450
|
+
list: (repo, input) => run((typed) => typed.queue.list({
|
|
539
451
|
params: { repo },
|
|
540
452
|
query: queryOf(input)
|
|
541
|
-
})
|
|
542
|
-
get: (entry
|
|
543
|
-
candidates: (repo, input) => run((
|
|
453
|
+
})),
|
|
454
|
+
get: (entry) => run((typed) => typed.queue.get({ params: { entry } })),
|
|
455
|
+
candidates: (repo, input) => run((typed) => typed.queue.candidates({
|
|
544
456
|
params: { repo },
|
|
545
457
|
query: queryOf(input)
|
|
546
|
-
})
|
|
547
|
-
candidate: (candidate
|
|
548
|
-
remove: (entry, input) => run((
|
|
458
|
+
})),
|
|
459
|
+
candidate: (candidate) => run((typed) => typed.queue.candidate({ params: { candidate } })),
|
|
460
|
+
remove: (entry, input) => run((typed) => typed.queue.remove({
|
|
549
461
|
params: { entry },
|
|
550
|
-
query:
|
|
551
|
-
})
|
|
552
|
-
hold: (id, input) => run((
|
|
462
|
+
query: input
|
|
463
|
+
})),
|
|
464
|
+
hold: (id, input) => run((typed) => "target" in input ? typed.queue.holdTarget({
|
|
553
465
|
params: { repo: id },
|
|
554
|
-
payload:
|
|
555
|
-
}) :
|
|
466
|
+
payload: input
|
|
467
|
+
}) : typed.queue.holdEntry({
|
|
556
468
|
params: { entry: id },
|
|
557
|
-
payload:
|
|
558
|
-
})
|
|
559
|
-
holds: (id, input) => run((
|
|
469
|
+
payload: input
|
|
470
|
+
})),
|
|
471
|
+
holds: (id, input) => run((typed) => queueIdParts("e", id) !== void 0 ? typed.queue.holdsOfEntry({
|
|
560
472
|
params: { entry: id },
|
|
561
473
|
query: queryOf(input)
|
|
562
|
-
}) :
|
|
474
|
+
}) : typed.queue.holdsOfTarget({
|
|
563
475
|
params: { repo: id },
|
|
564
476
|
query: queryOf(input)
|
|
565
|
-
})
|
|
566
|
-
release: (hold, input) => run((
|
|
477
|
+
})),
|
|
478
|
+
release: (hold, input) => run((typed) => typed.queue.release({
|
|
567
479
|
params: { hold },
|
|
568
|
-
query:
|
|
569
|
-
})
|
|
570
|
-
report: (candidate, input) => run((
|
|
480
|
+
query: input
|
|
481
|
+
})),
|
|
482
|
+
report: (candidate, input) => run((typed) => typed.queue.report({
|
|
571
483
|
params: { candidate },
|
|
572
|
-
payload:
|
|
573
|
-
})
|
|
574
|
-
retry: (candidate, input) => run((
|
|
484
|
+
payload: input
|
|
485
|
+
})),
|
|
486
|
+
retry: (candidate, input) => run((typed) => typed.queue.retry({
|
|
575
487
|
params: { candidate },
|
|
576
|
-
payload:
|
|
577
|
-
})
|
|
578
|
-
restart: (repo, input) => run((
|
|
488
|
+
payload: input
|
|
489
|
+
})),
|
|
490
|
+
restart: (repo, input) => run((typed) => typed.queue.restart({
|
|
579
491
|
params: { repo },
|
|
580
|
-
payload:
|
|
581
|
-
})
|
|
492
|
+
payload: input
|
|
493
|
+
}))
|
|
582
494
|
},
|
|
583
495
|
topics: {
|
|
584
|
-
add: (input) => run((
|
|
585
|
-
list: (input) => run((
|
|
586
|
-
get: (topic
|
|
587
|
-
remove: (topic
|
|
588
|
-
report: (topic, input) => run((
|
|
496
|
+
add: (input) => run((typed) => typed.topics.add({ payload: input })),
|
|
497
|
+
list: (input) => run((typed) => typed.topics.list({ query: queryOf(input) })),
|
|
498
|
+
get: (topic) => run((typed) => typed.topics.get({ params: { topic } })),
|
|
499
|
+
remove: (topic) => run((typed) => typed.topics.remove({ params: { topic } })),
|
|
500
|
+
report: (topic, input) => run((typed) => typed.topics.report({
|
|
589
501
|
params: { topic },
|
|
590
|
-
payload:
|
|
591
|
-
})
|
|
502
|
+
payload: input
|
|
503
|
+
}))
|
|
592
504
|
},
|
|
593
|
-
events: { listen: (repo, input) => listenOver((after
|
|
594
|
-
me: (
|
|
505
|
+
events: { listen: (repo, input) => listenOver((after) => connect(repo, after), input) },
|
|
506
|
+
me: () => run((typed) => typed.me.get())
|
|
595
507
|
};
|
|
596
508
|
};
|
|
597
|
-
|
|
509
|
+
/**
|
|
510
|
+
* A typed client for a Git server's REST at `options.url`: `HttpApiClient` over `GitRestApi`, each
|
|
511
|
+
* call an Effect that fails with the server's own `GitError`. It sends `credentials` on each
|
|
512
|
+
* request, through `options.transport` when given and the `HttpClient` it's provided otherwise. It
|
|
513
|
+
* carries none of REST's serving code.
|
|
514
|
+
*/
|
|
515
|
+
const make = /* @__PURE__ */ Effect.fnUntraced(function* (options) {
|
|
516
|
+
const base = options.transport === void 0 ? yield* HttpClient.HttpClient : yield* transportHttp(options.transport);
|
|
517
|
+
const api = shared ?? (yield* typedApi());
|
|
518
|
+
shared = api;
|
|
519
|
+
return callsOf(api, remoteHttp(options, base));
|
|
520
|
+
});
|
|
521
|
+
/** `RestClient` over `options`' remote, as `make` builds it. */
|
|
522
|
+
const layer = (options) => Layer.effect(RestClient, make(options));
|
|
523
|
+
export { RestClient, client_exports, layer, make };
|