@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.
Files changed (245) hide show
  1. package/dist/access/private-refs.mjs +0 -2
  2. package/dist/auth/authorize.mjs +31 -24
  3. package/dist/auth/bridge.mjs +8 -8
  4. package/dist/auth/fences.d.mts +0 -1
  5. package/dist/auth/fences.mjs +1 -1
  6. package/dist/auth/grants.d.mts +0 -1
  7. package/dist/auth/grants.mjs +2 -2
  8. package/dist/auth/host-function.d.mts +1 -7
  9. package/dist/auth/host-function.mjs +38 -38
  10. package/dist/auth/identify.d.mts +0 -1
  11. package/dist/auth/identify.mjs +1 -1
  12. package/dist/auth/policy.d.mts +7 -4
  13. package/dist/auth/policy.mjs +13 -10
  14. package/dist/auth/token-rows.mjs +2 -5
  15. package/dist/auth/tokens-layer.d.mts +0 -2
  16. package/dist/auth/tokens-public.d.mts +3 -3
  17. package/dist/auth/tokens-public.mjs +4 -2
  18. package/dist/auth/tokens.d.mts +6 -1
  19. package/dist/auth/tokens.mjs +7 -1
  20. package/dist/client/client.d.mts +22 -15
  21. package/dist/client/client.mjs +31 -27
  22. package/dist/client/git-http.mjs +22 -5
  23. package/dist/client/local.mjs +1 -1
  24. package/dist/client/namespace.d.mts +2 -0
  25. package/dist/client/push-upload.d.mts +1 -0
  26. package/dist/client/push-upload.mjs +169 -2
  27. package/dist/client/remote-helper.mjs +2 -4
  28. package/dist/client/remote.mjs +37 -15
  29. package/dist/client/run-remote-helper.mjs +4 -4
  30. package/dist/client/transport.mjs +26 -19
  31. package/dist/contracts/actors.d.mts +57 -28
  32. package/dist/contracts/actors.mjs +38 -2
  33. package/dist/contracts/authorize.d.mts +21 -15
  34. package/dist/contracts/callers.mjs +40 -0
  35. package/dist/contracts/calls-spent.d.mts +2 -12
  36. package/dist/contracts/calls-spent.mjs +4 -5
  37. package/dist/contracts/client.d.mts +16 -9
  38. package/dist/contracts/events.d.mts +82 -14
  39. package/dist/contracts/events.mjs +35 -9
  40. package/dist/contracts/files.d.mts +42 -42
  41. package/dist/contracts/forks.d.mts +0 -24
  42. package/dist/contracts/git-hooks.d.mts +217 -0
  43. package/dist/contracts/git-hooks.mjs +3 -1
  44. package/dist/contracts/git.d.mts +13 -3
  45. package/dist/contracts/grants.d.mts +46 -27
  46. package/dist/contracts/lfs.d.mts +17 -4
  47. package/dist/contracts/merges.d.mts +7 -7
  48. package/dist/contracts/objects.d.mts +38 -4
  49. package/dist/contracts/opaque.mjs +19 -1
  50. package/dist/contracts/operations.d.mts +8 -1
  51. package/dist/contracts/operations.mjs +209 -0
  52. package/dist/contracts/queue.d.mts +6 -5
  53. package/dist/contracts/queue.mjs +9 -20
  54. package/dist/contracts/remote.d.mts +13 -4
  55. package/dist/contracts/remote.mjs +3 -3
  56. package/dist/contracts/repos.d.mts +11 -40
  57. package/dist/contracts/repos.mjs +11 -10
  58. package/dist/contracts/result.d.mts +28 -11
  59. package/dist/contracts/result.mjs +32 -2
  60. package/dist/contracts/rules.d.mts +706 -46
  61. package/dist/contracts/rules.mjs +81 -2
  62. package/dist/contracts/server.d.mts +5 -275
  63. package/dist/contracts/services.d.mts +0 -3
  64. package/dist/contracts/services.mjs +1 -3
  65. package/dist/contracts/signin.d.mts +2 -2
  66. package/dist/contracts/signin.mjs +4 -5
  67. package/dist/contracts/sync.d.mts +1 -4
  68. package/dist/contracts/tokens.d.mts +29 -17
  69. package/dist/contracts/tokens.mjs +14 -3
  70. package/dist/contracts/topics.d.mts +38 -11
  71. package/dist/contracts/topics.mjs +8 -2
  72. package/dist/core/access.d.mts +0 -2
  73. package/dist/core/access.mjs +15 -4
  74. package/dist/core/ancestry.mjs +5 -4
  75. package/dist/core/events/deliver.mjs +19 -1
  76. package/dist/core/forks.mjs +30 -11
  77. package/dist/core/hooks/groups.d.mts +0 -1
  78. package/dist/core/hooks/groups.mjs +8 -9
  79. package/dist/core/index-job.mjs +23 -1
  80. package/dist/core/index-lost.d.mts +11 -0
  81. package/dist/core/index-lost.mjs +55 -0
  82. package/dist/core/loose-tally.mjs +46 -0
  83. package/dist/core/objects/commit-writes.mjs +1 -1
  84. package/dist/core/objects/commits.mjs +10 -9
  85. package/dist/core/objects/merges.mjs +1 -1
  86. package/dist/core/objects/reading.mjs +28 -13
  87. package/dist/core/objects/trees.mjs +1 -1
  88. package/dist/core/objects/writing.mjs +1 -0
  89. package/dist/core/parts.d.mts +7 -0
  90. package/dist/core/promise.mjs +1 -15
  91. package/dist/core/publish.mjs +9 -5
  92. package/dist/core/purge.mjs +30 -12
  93. package/dist/core/push.mjs +39 -16
  94. package/dist/core/ref-view.mjs +14 -6
  95. package/dist/core/repack.mjs +54 -27
  96. package/dist/core/repo-info.mjs +8 -6
  97. package/dist/core/repos.mjs +1 -0
  98. package/dist/core/rules/check.mjs +10 -10
  99. package/dist/core/rules/context.d.mts +3 -1
  100. package/dist/core/rules/context.mjs +16 -13
  101. package/dist/core/rules/fetch.mjs +17 -23
  102. package/dist/core/tokens.mjs +2 -1
  103. package/dist/core/view.d.mts +10 -1
  104. package/dist/core/view.mjs +15 -6
  105. package/dist/effect.d.mts +3 -6
  106. package/dist/effect.mjs +3 -6
  107. package/dist/engine/commits.mjs +23 -50
  108. package/dist/engine/failures.d.mts +1 -2
  109. package/dist/engine/failures.mjs +1 -3
  110. package/dist/engine/merge-base-walk.mjs +57 -142
  111. package/dist/engine/merge-bases.mjs +9 -7
  112. package/dist/engine/merge.mjs +20 -17
  113. package/dist/engine/parts.d.mts +1 -0
  114. package/dist/engine/parts.mjs +1 -1
  115. package/dist/engine/walk.mjs +15 -11
  116. package/dist/extend.d.mts +1 -2
  117. package/dist/extend.mjs +1 -2
  118. package/dist/http/core-parts.mjs +18 -10
  119. package/dist/http/handler.mjs +11 -31
  120. package/dist/http/parts.d.mts +0 -1
  121. package/dist/index.d.mts +29 -22
  122. package/dist/index.mjs +5 -2
  123. package/dist/lfs/base.d.mts +6 -3
  124. package/dist/lfs/base.mjs +2 -1
  125. package/dist/lfs/layer.d.mts +4 -3
  126. package/dist/lfs/layer.mjs +23 -9
  127. package/dist/lfs/objects.mjs +93 -41
  128. package/dist/lfs/pointers.mjs +69 -18
  129. package/dist/lfs/purge.mjs +6 -2
  130. package/dist/lfs/rows.mjs +24 -7
  131. package/dist/lfs/service.d.mts +6 -3
  132. package/dist/lfs/service.mjs +8 -2
  133. package/dist/lfs/upkeep.mjs +47 -28
  134. package/dist/lfs/upload-most.mjs +47 -0
  135. package/dist/lfs/uploaded.mjs +59 -0
  136. package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
  137. package/dist/protocol/bytes/streams.mjs +84 -2
  138. package/dist/protocol/bytes/text.mjs +6 -1
  139. package/dist/protocol/diff/read.d.mts +1 -0
  140. package/dist/protocol/diff/read.mjs +5 -2
  141. package/dist/protocol/objects/commit.d.mts +7 -0
  142. package/dist/protocol/objects/commit.mjs +5 -1
  143. package/dist/protocol/objects/fsck.mjs +6 -3
  144. package/dist/queue/advance.mjs +77 -18
  145. package/dist/queue/calls.mjs +4 -14
  146. package/dist/queue/host.d.mts +4 -0
  147. package/dist/queue/lanes.mjs +1 -1
  148. package/dist/queue/layer.mjs +4 -2
  149. package/dist/queue/limits.mjs +18 -2
  150. package/dist/queue/rows.mjs +10 -1
  151. package/dist/queue/schedule.mjs +1 -1
  152. package/dist/queue/search.mjs +3 -4
  153. package/dist/queue/trim.mjs +2 -2
  154. package/dist/rest/client-namespace.d.mts +2 -0
  155. package/dist/rest/client.d.mts +32 -8
  156. package/dist/rest/client.mjs +308 -382
  157. package/dist/rest/commits.d.mts +150 -150
  158. package/dist/rest/files.d.mts +18 -18
  159. package/dist/rest/forks.d.mts +77 -89
  160. package/dist/rest/handlers.mjs +2 -1
  161. package/dist/rest/listen.d.mts +8 -6
  162. package/dist/rest/listen.mjs +31 -75
  163. package/dist/rest/me.d.mts +2 -2
  164. package/dist/rest/merges.d.mts +7 -7
  165. package/dist/rest/refs.d.mts +27 -27
  166. package/dist/rest/repos.d.mts +40 -52
  167. package/dist/rest/tokens.d.mts +12 -12
  168. package/dist/rest/topics.d.mts +13 -13
  169. package/dist/rest/trees.d.mts +66 -66
  170. package/dist/rest/wire.d.mts +20 -2
  171. package/dist/rest/work.d.mts +39 -39
  172. package/dist/rest.d.mts +1 -7
  173. package/dist/rest.mjs +1 -5
  174. package/dist/server/git-layer.d.mts +10 -2
  175. package/dist/server/git-layer.mjs +29 -10
  176. package/dist/server/joined.d.mts +12 -6
  177. package/dist/server/joined.mjs +3 -2
  178. package/dist/server/registry.mjs +11 -5
  179. package/dist/server/server.d.mts +0 -1
  180. package/dist/server/server.mjs +42 -49
  181. package/dist/signin/context.d.mts +0 -1
  182. package/dist/signin/context.mjs +5 -9
  183. package/dist/storage/clean-up.mjs +3 -1
  184. package/dist/storage/fsck.mjs +12 -2
  185. package/dist/storage/graph-rebuild.mjs +262 -0
  186. package/dist/storage/index-bitmaps.mjs +16 -10
  187. package/dist/storage/index-build.mjs +160 -24
  188. package/dist/storage/index-graph.d.mts +1 -0
  189. package/dist/storage/index-graph.mjs +29 -5
  190. package/dist/storage/index-layers.d.mts +1 -0
  191. package/dist/storage/index-layers.mjs +5 -2
  192. package/dist/storage/index-reach.mjs +7 -5
  193. package/dist/storage/index-remap.mjs +5 -5
  194. package/dist/storage/index-visible.mjs +16 -5
  195. package/dist/storage/lfs-pointers.d.mts +5 -5
  196. package/dist/storage/lfs-pointers.mjs +37 -11
  197. package/dist/storage/links.mjs +3 -3
  198. package/dist/storage/loose.mjs +4 -1
  199. package/dist/storage/memory-budget.mjs +1 -1
  200. package/dist/storage/merge-fence.mjs +81 -19
  201. package/dist/storage/merge-most.mjs +1 -0
  202. package/dist/storage/merge-row.mjs +16 -4
  203. package/dist/storage/merge-stream.mjs +9 -6
  204. package/dist/storage/object-rows.mjs +17 -1
  205. package/dist/storage/pack-order.d.mts +1 -0
  206. package/dist/storage/pack-order.mjs +18 -1
  207. package/dist/storage/pack-receive.mjs +10 -6
  208. package/dist/storage/packs.mjs +58 -27
  209. package/dist/storage/prune-walk.mjs +5 -2
  210. package/dist/storage/prune.mjs +168 -70
  211. package/dist/storage/ready.d.mts +1 -1
  212. package/dist/storage/ready.mjs +12 -3
  213. package/dist/storage/receive-bounds.mjs +3 -2
  214. package/dist/storage/receive-state.mjs +1 -1
  215. package/dist/storage/repack-contained.mjs +22 -14
  216. package/dist/storage/repack.d.mts +1 -1
  217. package/dist/storage/repack.mjs +3 -2
  218. package/dist/storage/unpack.mjs +7 -0
  219. package/dist/storage/visible.mjs +3 -2
  220. package/dist/storage/walk.d.mts +1 -0
  221. package/dist/storage/walk.mjs +9 -5
  222. package/dist/storage/wants.mjs +17 -11
  223. package/dist/store/call-count.d.mts +31 -3
  224. package/dist/store/call-count.mjs +51 -20
  225. package/dist/store/errors.d.mts +7 -1
  226. package/dist/store/errors.mjs +7 -1
  227. package/dist/store/job-try.mjs +3 -1
  228. package/dist/store/records.mjs +26 -5
  229. package/dist/store/repo-record.mjs +36 -12
  230. package/dist/store/scopes.mjs +15 -2
  231. package/dist/sync/bound.d.mts +1 -1
  232. package/dist/sync/import.mjs +15 -3
  233. package/dist/sync/layer.d.mts +5 -1
  234. package/dist/sync/layer.mjs +11 -9
  235. package/dist/sync/mirror.mjs +1 -1
  236. package/dist/sync/step.mjs +15 -15
  237. package/dist/topics/advance.mjs +11 -10
  238. package/dist/topics/layer.mjs +1 -1
  239. package/dist/topics/members.mjs +38 -9
  240. package/package.json +3 -3
  241. package/dist/engine/merge-base-walk.d.mts +0 -3
  242. package/dist/server/routes.d.mts +0 -32
  243. package/dist/server/routes.mjs +0 -69
  244. package/dist/sync/bridge.d.mts +0 -6
  245. package/dist/sync/bridge.mjs +0 -29
@@ -1,10 +1,10 @@
1
- import { ownedReader } from "../protocol/bytes/reader.mjs";
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, remoteFetch } from "../client/transport.mjs";
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
- /** What the transport threw when no answer came: never the request, which holds the credential. */
33
- const transportCause = (error) => Predicate.isTagged(error.reason, "TransportError") ? error.reason.cause : void 0;
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 (transportCause(error) === credentialRefused) return credentialRefused;
43
- if (Predicate.isTagged(reason, "TransportError")) return gitError("UNAVAILABLE", "The remote didn't answer", { cause: transportCause(error) });
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
- /** The call's `Result`; a cancelled call throws its signal's reason, and a defect its cause. */
57
- const resultOf = (exit, signal, sent) => {
58
- if (Exit.isSuccess(exit)) return {
59
- kind: "success",
60
- value: exit.value
61
- };
62
- const failure = Cause.findErrorOption(exit.cause);
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
- /** A refused answer as its `GitError`: the remote's own, or what its status says. */
76
- const refusalOf = (response) => Effect.flatMap(Option.match(HttpClientResponse.toWeb(response), {
77
- onNone: () => Effect.succeed({ status: response.status }),
78
- onSome: restFailure
79
- }), ({ status, error }) => Effect.fail(error ?? statusError(status)));
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
- * An events answer's body, as EventSource takes one: a 200 of `text/event-stream`. Any other
82
- * answer under 400 isn't REST's stream.
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 eventStreamOf = (response) => {
85
- if (response.status >= 400) return refusalOf(response);
86
- const type = response.headers["content-type"] ?? "";
87
- const media = type.split(";")[0]?.trim().toLowerCase();
88
- if (response.status === 200 && media === "text/event-stream") return Effect.succeed(bodyStream(response));
89
- return Effect.fail(gitError("INTERNAL", `The remote answered ${response.status} of '${type}', not an event stream`));
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
- /** A call's input as a GET's query: its page's fields beside its filters, and no `signal`. */
92
- const queryOf = ({ signal: _signal, page, ...filters }) => ({
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 = ({ signal: _signal, page, limits, ...filters }) => ({
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 = ({ signal: _signal, oid: _oid, page, limits, ...filters }) => ({
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 = ({ signal: _signal, expiresAt, ...body }) => ({
164
+ const tokenBody = ({ expiresAt, ...body }) => ({
122
165
  ...body,
123
166
  expiresAt: expiresAt instanceof Date ? expiresAt.getTime() : expiresAt
124
167
  });
125
168
  /**
126
- * A typed client for a Git server's REST: `HttpApiClient` over `GitRestApi`, every call answering
127
- * `Result` as the server's own does. It sends `credentials` on each request and `signal` cancels
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 lazyBytes = (open, signal) => {
181
- const cancelled = new AbortController();
182
- const stopped = signal === void 0 ? cancelled.signal : AbortSignal.any([signal, cancelled.signal]);
183
- let held;
184
- return new ReadableStream({
185
- pull: async (controller) => {
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 remote a call goes to, each client's `url`, which `run` provides to the shared client. */
215
- var RestBase = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/rest/RestBase")) {};
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 failure is told apart. Each
253
- * answer's body ends when `signal` aborts, wherever the call has it then.
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 run = (call, signal) => {
186
+ const held = (call) => Effect.suspend(() => {
256
187
  let sent = false;
257
- const noted = async (input, init) => {
188
+ const noted = HttpClient.tapRequest(scoped, () => Effect.sync(() => {
258
189
  sent = true;
259
- const response = await remoteThrough(input, init);
260
- return signal === void 0 ? response : abortable(response, signal);
261
- };
262
- const effect = call(client).pipe(Effect.provideService(FetchHttpClient.Fetch, noted), Effect.provideService(RestBase, options.url));
263
- const runOptions = signal === void 0 ? void 0 : { signal };
264
- return Effect.runPromiseExit(effect, runOptions).then((exit) => resultOf(exit, signal, sent));
265
- };
266
- const blobOf = (repo, input) => run((api) => api.blobs.get({
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
- }).pipe(Effect.map(({ body, headers }) => {
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
- bytes
210
+ stream: checkedBody(input.oid, size, body)
279
211
  };
280
- })), input.signal);
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, signal) => {
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 run(() => http.execute(request).pipe(Effect.flatMap(eventStreamOf)), signal);
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((api) => api.repos.list({ query: queryOf(input) }), input.signal),
289
- create: (input) => run((api) => api.repos.create({ payload: bodyOf(input) }), input.signal),
290
- get: (repo, input) => run((api) => api.repos.get({ params: { repo } }), input.signal),
291
- update: (repo, input) => run((api) => api.repos.update({
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: bodyOf(input)
294
- }), input.signal),
295
- rename: (repo, input) => run((api) => api.repos.rename({
234
+ payload: input
235
+ })),
236
+ rename: (repo, input) => run((typed) => typed.repos.rename({
296
237
  params: { repo },
297
- payload: bodyOf(input)
298
- }), input.signal),
299
- delete: (repo, input) => run((api) => api.repos.delete({
238
+ payload: input
239
+ })),
240
+ delete: (repo, input) => run((typed) => typed.repos.delete({
300
241
  params: { repo },
301
- query: bodyOf(input)
302
- }), input.signal)
242
+ query: input
243
+ }))
303
244
  },
304
245
  forks: {
305
- create: (repo, input) => run((api) => api.forks.create({
246
+ create: (repo, input) => run((typed) => typed.forks.create({
306
247
  params: { repo },
307
- payload: bodyOf(input)
308
- }), input.signal),
309
- get: (repo, input) => run((api) => api.forks.get({ params: {
248
+ payload: input
249
+ })),
250
+ get: (repo, input) => run((typed) => typed.forks.get({ params: {
310
251
  repo,
311
252
  holder: input.holder
312
- } }), input.signal),
313
- list: (repo, input) => run((api) => api.forks.list({
253
+ } })),
254
+ list: (repo, input) => run((typed) => typed.forks.list({
314
255
  params: { repo },
315
256
  query: queryOf(input)
316
- }), input.signal),
317
- sync: (repo, input) => run((api) => api.forks.sync({
257
+ })),
258
+ sync: (repo, input) => run((typed) => typed.forks.sync({
318
259
  params: { repo },
319
- payload: bodyOf(input)
320
- }), input.signal),
321
- fetch: (repo, input) => run((api) => api.forks.fetch({ params: { repo } }), input.signal)
260
+ payload: input
261
+ })),
262
+ fetch: (repo) => run((typed) => typed.forks.fetch({ params: { repo } }))
322
263
  },
323
264
  refs: {
324
- get: (repo, input) => run((api) => api.refs.get({ params: {
265
+ get: (repo, input) => run((typed) => typed.refs.get({ params: {
325
266
  repo,
326
267
  ref: input.ref
327
- } }), input.signal),
328
- protection: async (repo, input) => {
329
- const params = {
330
- repo,
331
- ref: input.ref
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
- }), input.signal),
356
- list: (repo, input) => run((api) => api.refs.list({
276
+ }), (guards) => guards.map((guard) => guard ?? void 0))),
277
+ sees: (repo, input) => run((typed) => typed.refs.sees({
357
278
  params: { repo },
358
- query: queryOf(input)
359
- }), input.signal),
360
- count: (repo, input) => run((api) => api.refs.count({
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
- }), input.signal),
364
- update: (repo, input) => run((api) => Effect.map(api.refs.update({
284
+ })),
285
+ count: (repo, input) => run((typed) => typed.refs.count({
365
286
  params: { repo },
366
- payload: bodyOf(input)
367
- }), updatedOf), input.signal)
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((api) => api.work.list({
295
+ list: (repo, input) => run((typed) => typed.work.list({
371
296
  params: { repo },
372
297
  query: queryOf(input)
373
- }), input.signal),
374
- retry: (repo, input) => run((api) => api.work.retry({
298
+ })),
299
+ retry: (repo, input) => run((typed) => typed.work.retry({
375
300
  params: { repo },
376
- payload: bodyOf(input)
377
- }), input.signal),
378
- discard: (repo, input) => run((api) => api.work.discard({
301
+ payload: input
302
+ })),
303
+ discard: (repo, input) => run((typed) => typed.work.discard({
379
304
  params: { repo },
380
- payload: bodyOf(input)
381
- }), input.signal)
305
+ payload: input
306
+ }))
382
307
  },
383
308
  tokens: {
384
- create: (target, input) => run((api) => Predicate.isString(target) ? api.tokens.createRepo({
309
+ create: (target, input) => run((typed) => Predicate.isString(target) ? typed.tokens.createRepo({
385
310
  params: { repo: target },
386
311
  payload: tokenBody(input)
387
- }) : api.tokens.createPrefix({
312
+ }) : typed.tokens.createPrefix({
388
313
  query: target,
389
314
  payload: tokenBody(input)
390
- }), input.signal),
391
- list: (target, input = {}) => run((api) => Predicate.isString(target) ? api.tokens.listRepo({
315
+ })),
316
+ list: (target, input = {}) => run((typed) => Predicate.isString(target) ? typed.tokens.listRepo({
392
317
  params: { repo: target },
393
318
  query: queryOf(input)
394
- }) : api.tokens.listPrefix({ query: {
319
+ }) : typed.tokens.listPrefix({ query: {
395
320
  ...target,
396
321
  ...queryOf(input)
397
- } }), input.signal),
398
- get: (token, input = {}) => run((api) => api.tokens.get({ params: { id: token } }), input.signal),
399
- revoke: (token, input = {}) => run((api) => api.tokens.revoke({
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: bodyOf(input)
402
- }), input.signal)
326
+ query: input
327
+ }))
403
328
  },
404
329
  blobs: {
405
330
  get: blobOf,
406
- create: async (repo, { bytes, signal, ...query }) => {
407
- const held = await heldOf(bytes, signal);
408
- if (held.kind === "error") return held;
409
- return run((api) => api.blobs.create({
410
- params: { repo },
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((api) => api.trees.get({
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
- }), input.signal),
424
- diff: (repo, input) => run((api) => api.trees.diff({
344
+ })),
345
+ diff: (repo, input) => run((typed) => typed.trees.diff({
425
346
  params: { repo },
426
- payload: bodyOf(input)
427
- }), input.signal),
428
- create: (repo, { changes, ...input }) => run((api) => api.trees.create({
347
+ payload: input
348
+ })),
349
+ create: (repo, { changes, ...input }) => run((typed) => typed.trees.create({
429
350
  params: { repo },
430
351
  payload: {
431
- ...bodyOf(input),
352
+ ...input,
432
353
  changes: changes.map(wireEdit)
433
354
  }
434
- }), input.signal),
435
- merge: (repo, input) => run((api) => api.trees.merge({
355
+ })),
356
+ merge: (repo, input) => run((typed) => typed.trees.merge({
436
357
  params: { repo },
437
- payload: bodyOf(input)
438
- }), input.signal)
358
+ payload: input
359
+ }))
439
360
  },
440
361
  commits: {
441
- get: (repo, input) => run((api) => api.commits.get({
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
- }), input.signal),
448
- list: (repo, input) => run((api) => api.commits.list({
368
+ })),
369
+ list: (repo, input) => run((typed) => typed.commits.list({
449
370
  params: { repo },
450
371
  query: readQuery(input)
451
- }), input.signal),
452
- mergeBase: (repo, input) => run((api) => api.commits.mergeBase({
372
+ })),
373
+ mergeBase: (repo, input) => run((typed) => typed.commits.mergeBase({
453
374
  params: { repo },
454
- payload: bodyOf(input)
455
- }), input.signal),
456
- diff: (repo, input) => run((api) => api.commits.diff({
375
+ payload: input
376
+ })),
377
+ diff: (repo, input) => run((typed) => typed.commits.diff({
457
378
  params: { repo },
458
- payload: bodyOf(input)
459
- }), input.signal),
460
- compare: (repo, input) => run((api) => api.commits.compare({
379
+ payload: input
380
+ })),
381
+ compare: (repo, input) => run((typed) => typed.commits.compare({
461
382
  params: { repo },
462
- payload: bodyOf(input)
463
- }), input.signal),
464
- create: (repo, { changes, ...input }) => run((api) => api.commits.create({
383
+ payload: input
384
+ })),
385
+ create: (repo, { changes, ...input }) => run((typed) => typed.commits.create({
465
386
  params: { repo },
466
- payload: changes === void 0 ? bodyOf(input) : {
467
- ...bodyOf(input),
387
+ payload: changes === void 0 ? input : {
388
+ ...input,
468
389
  changes: changes.map(wireEdit)
469
390
  }
470
- }), input.signal),
471
- revert: (repo, input) => run((api) => api.commits.revert({
391
+ })),
392
+ revert: (repo, input) => run((typed) => typed.commits.revert({
472
393
  params: { repo },
473
- payload: bodyOf(input)
474
- }), input.signal),
475
- pick: (repo, input) => run((api) => api.commits.pick({
394
+ payload: input
395
+ })),
396
+ pick: (repo, input) => run((typed) => typed.commits.pick({
476
397
  params: { repo },
477
- payload: bodyOf(input)
478
- }), input.signal)
398
+ payload: input
399
+ }))
479
400
  },
480
401
  tags: {
481
- get: (repo, input) => run((api) => api.tags.get({
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
- }), input.signal),
488
- peel: (repo, input) => run((api) => api.tags.peel({
408
+ })),
409
+ peel: (repo, input) => run((typed) => typed.tags.peel({
489
410
  params: { repo },
490
- payload: bodyOf(input)
491
- }), input.signal),
492
- create: (repo, input) => run((api) => api.tags.create({
411
+ payload: input
412
+ })),
413
+ create: (repo, input) => run((typed) => typed.tags.create({
493
414
  params: { repo },
494
- payload: bodyOf(input)
495
- }), input.signal)
415
+ payload: input
416
+ }))
496
417
  },
497
- merges: { create: (repo, input) => run((api) => api.merges.create({
418
+ merges: { create: (repo, input) => run((typed) => typed.merges.create({
498
419
  params: { repo },
499
- payload: bodyOf(input)
500
- }), input.signal) },
420
+ payload: input
421
+ })) },
501
422
  files: {
502
- list: (repo, input) => run((api) => api.files.list({
423
+ list: (repo, input) => run((typed) => typed.files.list({
503
424
  params: { repo },
504
425
  query: readQuery(input)
505
- }), input.signal),
506
- read: (repo, input) => run((api) => api.files.read({
507
- params: { repo },
508
- payload: bodyOf(input)
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: read.files.items.map(({ content, ...file }) => ({
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
- }))), input.signal),
528
- diff: (repo, input) => run((api) => api.files.diff({
439
+ })))),
440
+ diff: (repo, input) => run((typed) => typed.files.diff({
529
441
  params: { repo },
530
- payload: bodyOf(input)
531
- }), input.signal)
442
+ payload: input
443
+ }))
532
444
  },
533
445
  queue: {
534
- add: (repo, input) => run((api) => api.queue.add({
446
+ add: (repo, input) => run((typed) => typed.queue.add({
535
447
  params: { repo },
536
- payload: bodyOf(input)
537
- }), input.signal),
538
- list: (repo, input) => run((api) => api.queue.list({
448
+ payload: input
449
+ })),
450
+ list: (repo, input) => run((typed) => typed.queue.list({
539
451
  params: { repo },
540
452
  query: queryOf(input)
541
- }), input.signal),
542
- get: (entry, input) => run((api) => api.queue.get({ params: { entry } }), input.signal),
543
- candidates: (repo, input) => run((api) => api.queue.candidates({
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
- }), input.signal),
547
- candidate: (candidate, input) => run((api) => api.queue.candidate({ params: { candidate } }), input.signal),
548
- remove: (entry, input) => run((api) => api.queue.remove({
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: bodyOf(input)
551
- }), input.signal),
552
- hold: (id, input) => run((api) => "target" in input ? api.queue.holdTarget({
462
+ query: input
463
+ })),
464
+ hold: (id, input) => run((typed) => "target" in input ? typed.queue.holdTarget({
553
465
  params: { repo: id },
554
- payload: bodyOf(input)
555
- }) : api.queue.holdEntry({
466
+ payload: input
467
+ }) : typed.queue.holdEntry({
556
468
  params: { entry: id },
557
- payload: bodyOf(input)
558
- }), input.signal),
559
- holds: (id, input) => run((api) => queueIdParts("e", id) !== void 0 ? api.queue.holdsOfEntry({
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
- }) : api.queue.holdsOfTarget({
474
+ }) : typed.queue.holdsOfTarget({
563
475
  params: { repo: id },
564
476
  query: queryOf(input)
565
- }), input.signal),
566
- release: (hold, input) => run((api) => api.queue.release({
477
+ })),
478
+ release: (hold, input) => run((typed) => typed.queue.release({
567
479
  params: { hold },
568
- query: bodyOf(input)
569
- }), input.signal),
570
- report: (candidate, input) => run((api) => api.queue.report({
480
+ query: input
481
+ })),
482
+ report: (candidate, input) => run((typed) => typed.queue.report({
571
483
  params: { candidate },
572
- payload: bodyOf(input)
573
- }), input.signal),
574
- retry: (candidate, input) => run((api) => api.queue.retry({
484
+ payload: input
485
+ })),
486
+ retry: (candidate, input) => run((typed) => typed.queue.retry({
575
487
  params: { candidate },
576
- payload: bodyOf(input)
577
- }), input.signal),
578
- restart: (repo, input) => run((api) => api.queue.restart({
488
+ payload: input
489
+ })),
490
+ restart: (repo, input) => run((typed) => typed.queue.restart({
579
491
  params: { repo },
580
- payload: bodyOf(input)
581
- }), input.signal)
492
+ payload: input
493
+ }))
582
494
  },
583
495
  topics: {
584
- add: (input) => run((api) => api.topics.add({ payload: bodyOf(input) }), input.signal),
585
- list: (input) => run((api) => api.topics.list({ query: queryOf(input) }), input.signal),
586
- get: (topic, input) => run((api) => api.topics.get({ params: { topic } }), input.signal),
587
- remove: (topic, input) => run((api) => api.topics.remove({ params: { topic } }), input.signal),
588
- report: (topic, input) => run((api) => api.topics.report({
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: bodyOf(input)
591
- }), input.signal)
502
+ payload: input
503
+ }))
592
504
  },
593
- events: { listen: (repo, input) => listenOver((after, signal) => connect(repo, after, signal), input) },
594
- me: (input = {}) => run((api) => api.me.get(), input.signal)
505
+ events: { listen: (repo, input) => listenOver((after) => connect(repo, after), input) },
506
+ me: () => run((typed) => typed.me.get())
595
507
  };
596
508
  };
597
- export { createRestClient };
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 };