ref0-git 0.3.0 → 0.6.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 (210) hide show
  1. package/app/apps/github/.dev.vars.example +2 -1
  2. package/app/apps/github/generated/git-rest.ts +191 -25
  3. package/app/apps/github/generated/routeTree.gen.ts +21 -0
  4. package/app/apps/github/package.json +1 -1
  5. package/app/apps/github/src/branches/branch-list.tsx +8 -4
  6. package/app/apps/github/src/branches/branches.ts +10 -5
  7. package/app/apps/github/src/camo/addresses.ts +120 -0
  8. package/app/apps/github/src/camo/client.ts +125 -0
  9. package/app/apps/github/src/camo/fetch.ts +201 -0
  10. package/app/apps/github/src/camo/lookup.ts +23 -0
  11. package/app/apps/github/src/camo/node.ts +50 -0
  12. package/app/apps/github/src/camo/proxy.ts +116 -0
  13. package/app/apps/github/src/camo/sign-images.ts +307 -0
  14. package/app/apps/github/src/camo/signing.ts +80 -0
  15. package/app/apps/github/src/clients/allowed.ts +111 -18
  16. package/app/apps/github/src/clients/clients.ts +76 -61
  17. package/app/apps/github/src/clients/transport.ts +13 -0
  18. package/app/apps/github/src/code/code-tree.tsx +3 -1
  19. package/app/apps/github/src/code/file-view.tsx +15 -6
  20. package/app/apps/github/src/code/files.ts +26 -19
  21. package/app/apps/github/src/code/go-to-file.tsx +2 -1
  22. package/app/apps/github/src/code/load.ts +41 -23
  23. package/app/apps/github/src/code/markdown-files.ts +13 -2
  24. package/app/apps/github/src/code/ref-pages.ts +14 -5
  25. package/app/apps/github/src/code/ref-switcher.tsx +4 -3
  26. package/app/apps/github/src/code/refs.ts +42 -8
  27. package/app/apps/github/src/code/repo-home.tsx +6 -2
  28. package/app/apps/github/src/code/repo.ts +12 -6
  29. package/app/apps/github/src/code/saved.ts +5 -3
  30. package/app/apps/github/src/code/trees.ts +11 -9
  31. package/app/apps/github/src/components/markdown/markdown.css +6 -0
  32. package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
  33. package/app/apps/github/src/components/owner-card.tsx +3 -1
  34. package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
  35. package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
  36. package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
  37. package/app/apps/github/src/components/signin/device-card.tsx +9 -2
  38. package/app/apps/github/src/components/user-avatar.tsx +2 -1
  39. package/app/apps/github/src/context/context.ts +13 -0
  40. package/app/apps/github/src/diffs/blobs.ts +37 -14
  41. package/app/apps/github/src/diffs/diff-job.ts +53 -0
  42. package/app/apps/github/src/diffs/diff-worker.ts +6 -0
  43. package/app/apps/github/src/diffs/diffing.ts +136 -0
  44. package/app/apps/github/src/diffs/files.ts +4 -3
  45. package/app/apps/github/src/diffs/hunks.tsx +101 -53
  46. package/app/apps/github/src/diffs/patch.ts +20 -11
  47. package/app/apps/github/src/history/commit-diff.ts +10 -5
  48. package/app/apps/github/src/history/commit-list.tsx +3 -1
  49. package/app/apps/github/src/history/commit-page.tsx +4 -2
  50. package/app/apps/github/src/history/history.ts +12 -10
  51. package/app/apps/github/src/hooks/allowed.ts +9 -9
  52. package/app/apps/github/src/hooks/avatars.ts +3 -3
  53. package/app/apps/github/src/hooks/open-counts.ts +5 -4
  54. package/app/apps/github/src/hooks/profiles.ts +26 -12
  55. package/app/apps/github/src/hooks/repos.ts +78 -25
  56. package/app/apps/github/src/inbox/count.ts +30 -29
  57. package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
  58. package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
  59. package/app/apps/github/src/inbox/marks.ts +26 -15
  60. package/app/apps/github/src/inbox/release-tags.ts +7 -6
  61. package/app/apps/github/src/inbox/subjects.ts +5 -4
  62. package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
  63. package/app/apps/github/src/inbox/subscriptions.ts +95 -35
  64. package/app/apps/github/src/inbox/threads.ts +6 -6
  65. package/app/apps/github/src/issues/changes.ts +40 -16
  66. package/app/apps/github/src/issues/counts.ts +8 -5
  67. package/app/apps/github/src/issues/issue-list.tsx +20 -6
  68. package/app/apps/github/src/issues/issue-page.tsx +30 -14
  69. package/app/apps/github/src/issues/issues.ts +195 -46
  70. package/app/apps/github/src/issues/label-dialog.tsx +8 -11
  71. package/app/apps/github/src/issues/labels-page.tsx +35 -3
  72. package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
  73. package/app/apps/github/src/issues/milestones-page.tsx +269 -0
  74. package/app/apps/github/src/issues/new-issue.tsx +3 -1
  75. package/app/apps/github/src/issues/sidebar.tsx +8 -6
  76. package/app/apps/github/src/markdown/README.md +22 -17
  77. package/app/apps/github/src/markdown/context.ts +83 -10
  78. package/app/apps/github/src/markdown/images.ts +3 -2
  79. package/app/apps/github/src/markdown/lookup.ts +9 -8
  80. package/app/apps/github/src/markdown/page-budget.ts +50 -0
  81. package/app/apps/github/src/markdown/patches.ts +74 -32
  82. package/app/apps/github/src/markdown/query.ts +7 -2
  83. package/app/apps/github/src/markdown/remote.ts +106 -0
  84. package/app/apps/github/src/markdown/render.ts +101 -24
  85. package/app/apps/github/src/markdown/texts.ts +43 -0
  86. package/app/apps/github/src/markdown/words-module.d.ts +5 -0
  87. package/app/apps/github/src/markdown/words-plugin.ts +135 -0
  88. package/app/apps/github/src/names/repos.ts +1 -1
  89. package/app/apps/github/src/palette/palette.tsx +7 -4
  90. package/app/apps/github/src/palette/rows.tsx +54 -33
  91. package/app/apps/github/src/palette/server.ts +5 -5
  92. package/app/apps/github/src/palette/targets.ts +1 -0
  93. package/app/apps/github/src/policy.ts +165 -66
  94. package/app/apps/github/src/private-repos.ts +2 -2
  95. package/app/apps/github/src/pulls/compare-page.tsx +6 -3
  96. package/app/apps/github/src/pulls/files-tab.tsx +480 -214
  97. package/app/apps/github/src/pulls/held-summary.ts +178 -0
  98. package/app/apps/github/src/pulls/live.ts +6 -4
  99. package/app/apps/github/src/pulls/merge-box.tsx +17 -10
  100. package/app/apps/github/src/pulls/pull-list.tsx +6 -3
  101. package/app/apps/github/src/pulls/pull-page.tsx +19 -10
  102. package/app/apps/github/src/pulls/pull.ts +68 -40
  103. package/app/apps/github/src/pulls/pulls.ts +39 -22
  104. package/app/apps/github/src/pulls/review-drafts.ts +131 -0
  105. package/app/apps/github/src/pulls/review.ts +374 -99
  106. package/app/apps/github/src/pulls/threads.tsx +152 -0
  107. package/app/apps/github/src/queue/queue-page.tsx +15 -8
  108. package/app/apps/github/src/queue/queue.ts +35 -20
  109. package/app/apps/github/src/releases/latest-release.tsx +3 -1
  110. package/app/apps/github/src/releases/overview.tsx +4 -2
  111. package/app/apps/github/src/releases/release-form.tsx +8 -5
  112. package/app/apps/github/src/releases/release-list.tsx +8 -5
  113. package/app/apps/github/src/releases/release-view.tsx +1 -0
  114. package/app/apps/github/src/releases/releases.ts +33 -23
  115. package/app/apps/github/src/releases/tag-list.tsx +3 -1
  116. package/app/apps/github/src/router.tsx +5 -2
  117. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
  118. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
  119. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
  120. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
  121. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
  122. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
  123. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
  124. package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
  125. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
  126. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
  127. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
  128. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
  129. package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
  130. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
  131. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
  132. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
  133. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
  134. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
  135. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
  136. package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
  137. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
  138. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
  139. package/app/apps/github/src/routes/-nav.tsx +10 -2
  140. package/app/apps/github/src/routes/-root-testing.ts +29 -6
  141. package/app/apps/github/src/routes/__root.tsx +9 -4
  142. package/app/apps/github/src/routes/index.tsx +3 -1
  143. package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
  144. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
  145. package/app/apps/github/src/seed/acme.ts +1 -1
  146. package/app/apps/github/src/seed/seed.ts +199 -110
  147. package/app/apps/github/src/server.ts +24 -15
  148. package/app/apps/github/src/settings/account-avatar.tsx +4 -1
  149. package/app/apps/github/src/settings/general-settings.tsx +3 -1
  150. package/app/apps/github/src/settings/general.ts +4 -4
  151. package/app/apps/github/src/settings/hook-form.tsx +3 -1
  152. package/app/apps/github/src/settings/hook-list.tsx +5 -2
  153. package/app/apps/github/src/settings/hooks.ts +7 -7
  154. package/app/apps/github/src/settings/org-settings.tsx +3 -1
  155. package/app/apps/github/src/settings/orgs.ts +21 -11
  156. package/app/apps/github/src/settings/settings-layout.tsx +3 -1
  157. package/app/apps/github/src/signin/approval.ts +4 -3
  158. package/app/apps/github/src/signin/auth.ts +9 -2
  159. package/app/apps/github/src/signin/device-code.ts +8 -3
  160. package/app/apps/github/src/signin/device-prompt.ts +28 -3
  161. package/app/apps/github/src/signin/revoke.ts +36 -0
  162. package/app/apps/github/tsconfig.json +4 -1
  163. package/app/apps/github/vite.config.ts +8 -0
  164. package/app/pnpm-workspace.yaml +12 -5
  165. package/app/tsconfig.base.json +1 -0
  166. package/dist/cli/child.mjs +1 -1
  167. package/dist/cli/credentials.mjs +4 -4
  168. package/dist/cli/documents.mjs +32 -22
  169. package/dist/cli/events.mjs +1 -1
  170. package/dist/cli/failure.mjs +20 -7
  171. package/dist/cli/folders.mjs +2 -2
  172. package/dist/cli/git-remote-ref0.mjs +47 -22
  173. package/dist/cli/git.mjs +1 -1
  174. package/dist/cli/helpers.mjs +2 -2
  175. package/dist/cli/hosts.mjs +3 -3
  176. package/dist/cli/output.mjs +2 -2
  177. package/dist/cli/prompt.mjs +1 -1
  178. package/dist/cli/queue.mjs +7 -7
  179. package/dist/cli/ref0-git.mjs +2 -2
  180. package/dist/cli/repos.mjs +35 -18
  181. package/dist/cli/resources.mjs +5 -5
  182. package/dist/cli/retry-after.mjs +8 -0
  183. package/dist/cli/setup.mjs +172 -66
  184. package/dist/cli/sign-in.mjs +65 -23
  185. package/dist/cli/sign-ins.mjs +4 -4
  186. package/dist/cli/sqlite.mjs +2 -2
  187. package/dist/cli/tokens.mjs +3 -3
  188. package/dist/cli/vendor.mjs +1 -1
  189. package/dist/init/app.mjs +20 -21
  190. package/dist/init/choices.mjs +1 -1
  191. package/dist/init/cloudflare.mjs +15 -19
  192. package/dist/init/create.mjs +3 -2
  193. package/dist/init/detect.mjs +4 -4
  194. package/dist/init/files.mjs +120 -13
  195. package/dist/init/frameworks.mjs +16 -0
  196. package/dist/init/git-module.mjs +22 -7
  197. package/dist/init/jsonc.mjs +9 -7
  198. package/dist/init/metadata.mjs +9 -3
  199. package/dist/init/mounts.mjs +13 -10
  200. package/dist/init/next.mjs +2 -2
  201. package/dist/init/node-app.mjs +3 -3
  202. package/dist/init/node.mjs +42 -45
  203. package/dist/init/nuxt.mjs +153 -27
  204. package/dist/init/stores.mjs +14 -9
  205. package/dist/init/sveltekit.mjs +4 -2
  206. package/dist/init/template.mjs +9 -6
  207. package/dist/init/templates.mjs +63 -47
  208. package/dist/init/vercel.mjs +37 -37
  209. package/dist/init/versions.mjs +3 -3
  210. package/package.json +6 -5
@@ -1,82 +1,97 @@
1
1
  import type { paths as GitHubPaths } from '@octokit/openapi-types';
2
+ import { useRouteContext } from '@tanstack/react-router';
2
3
  import createClient from 'openapi-fetch';
3
- import createQueryHooks from 'openapi-react-query';
4
4
  import type * as Schema from 'effect/Schema';
5
5
 
6
6
  import type { paths as GitPaths } from '../../generated/git-rest.ts';
7
- import { apiBases, callOf, type ApiName } from './calls.ts';
7
+ import type { Ask, PageOperation } from './allowed.ts';
8
+ import { type ApiCall, apiBases, callOf, type ApiName } from './calls.ts';
8
9
  import { answered, graphqlRequest, mutated, type Variables } from './graphql.ts';
9
- import { callApi } from './proxy.ts';
10
10
  import { endedHeader, sessionEnded } from './session-ended.ts';
11
11
 
12
12
  /**
13
- * The clients' URLs name only a path: this origin is a placeholder `callApi` drops, so one client
14
- * builds the same calls in the browser and on the server.
13
+ * How the app's calls reach the server: each API call, made as the session's holder and answered
14
+ * with the API's own response, and the operations the viewer may make. The app's own sends both
15
+ * through Start's server functions (`clients/transport.ts`); a mounted test answers them itself.
15
16
  */
16
- const placeholder = 'http://api.invalid';
17
+ export interface Transport {
18
+ readonly call: (call: ApiCall, signal: AbortSignal) => Promise<Response>;
19
+ readonly allowed: (ask: Ask) => Promise<readonly PageOperation[]>;
20
+ }
17
21
 
18
22
  /**
19
- * openapi-fetch's `fetch`, sending each request through `callApi` to the server. Aborting the
20
- * request aborts the call, and with it a stream the API was sending. An answer whose session
21
- * ended tells the shell, which reloads the page's data as a visitor's.
23
+ * The clients' URLs name only a path: this origin is a placeholder the transport drops, so one
24
+ * client builds the same calls in the browser and on the server.
22
25
  */
23
- const viaServer = (api: ApiName) => async (request: Request) => {
24
- const answer = await callApi({ data: await callOf(api, request), signal: request.signal });
25
- if (answer.headers.has(endedHeader)) sessionEnded();
26
-
27
- return answer;
28
- };
29
-
30
- /** GitHub's REST, typed by `@octokit/openapi-types`, through the drop-in. */
31
- export const github = createClient<GitHubPaths>({
32
- baseUrl: `${placeholder}${apiBases.github}`,
33
- fetch: viaServer('github'),
34
- });
35
-
36
- /** Git's REST, typed from its OpenAPI document. */
37
- export const git = createClient<GitPaths>({
38
- baseUrl: `${placeholder}${apiBases.git}`,
39
- fetch: viaServer('git'),
40
- });
26
+ const placeholder = 'http://api.invalid';
41
27
 
42
28
  /**
43
- * A call to `path` under `api`'s base that no client types: an Event Stream's, whose URLs the
44
- * drop-in names in its answers, and a stream's body, which the caller reads as it comes.
29
+ * The clients every page reads and writes through, over `transport`: the router's context holds
30
+ * one, which loaders read from `context.clients` and components from `useClients`.
45
31
  */
46
- export const callAt = (api: ApiName, path: string, init?: RequestInit) =>
47
- viaServer(api)(new Request(`${placeholder}${apiBases[api]}${path}`, init));
32
+ export const createClients = (transport: Transport) => {
33
+ /**
34
+ * openapi-fetch's `fetch`, sending each request through the transport. Aborting the request
35
+ * aborts the call, and with it a stream the API was sending. An answer whose session ended
36
+ * tells the shell, which reloads the page's data as a visitor's.
37
+ */
38
+ const viaServer = (api: ApiName) => async (request: Request) => {
39
+ const answer = await transport.call(await callOf(api, request), request.signal);
40
+ if (answer.headers.has(endedHeader)) sessionEnded();
48
41
 
49
- /**
50
- * The drop-in's raw route at `path`, `/{owner}/{repo}/raw/{ref}/{path}`, read as the viewer: an
51
- * LFS file's object, or its pointer when the bucket lacks it (Q506). The page reads the bytes and
52
- * shows or saves them itself, so nothing points the browser at the route (Q310).
53
- */
54
- export const raw = (path: string) => callAt('raw', path);
42
+ return answer;
43
+ };
55
44
 
56
- /**
57
- * `operation`, a GraphQL mutation the drop-in serves at `/api/graphql`, sent with `variables`. A
58
- * refusal throws `what` with GitHub's words for its first error, or the status.
59
- */
60
- export const mutate = async (what: string, operation: string, variables: Variables) =>
61
- mutated(what, await callAt('graphql', '/api/graphql', graphqlRequest(operation, variables)));
45
+ /**
46
+ * A call to `path` under `api`'s base that no client types: an Event Stream's, whose URLs the
47
+ * drop-in names in its answers, and a stream's body, which the caller reads as it comes.
48
+ */
49
+ const callAt = (api: ApiName, path: string, init?: RequestInit) =>
50
+ viaServer(api)(new Request(`${placeholder}${apiBases[api]}${path}`, init));
62
51
 
63
- /**
64
- * `operation`, a GraphQL query the drop-in serves at `/api/graphql`, sent with `variables`: its
65
- * answer's `data`, as `schema` reads it, or `answered`'s throw.
66
- */
67
- export const query = async <A>(
68
- what: string,
69
- operation: string,
70
- variables: Variables,
71
- schema: Schema.Decoder<A>,
72
- ) =>
73
- answered(
74
- what,
75
- await callAt('graphql', '/api/graphql', graphqlRequest(operation, variables)),
76
- schema,
77
- );
52
+ const graphql = (operation: string, variables: Variables) =>
53
+ callAt('graphql', '/api/graphql', graphqlRequest(operation, variables));
54
+
55
+ return {
56
+ /** GitHub's REST, typed by `@octokit/openapi-types`, through the drop-in. */
57
+ github: createClient<GitHubPaths>({
58
+ baseUrl: `${placeholder}${apiBases.github}`,
59
+ fetch: viaServer('github'),
60
+ }),
61
+ /** Git's REST, typed from its OpenAPI document. */
62
+ git: createClient<GitPaths>({
63
+ baseUrl: `${placeholder}${apiBases.git}`,
64
+ fetch: viaServer('git'),
65
+ }),
66
+ callAt,
67
+ /**
68
+ * The drop-in's raw route at `path`, `/{owner}/{repo}/raw/{ref}/{path}`, read as the viewer:
69
+ * an LFS file's object, or its pointer when the bucket lacks it (Q506). The page reads the
70
+ * bytes and shows or saves them itself, so nothing points the browser at the route (Q310).
71
+ */
72
+ raw: (path: string) => callAt('raw', path),
73
+ /**
74
+ * `operation`, a GraphQL mutation the drop-in serves at `/api/graphql`, sent with
75
+ * `variables`. A refusal throws `what` with GitHub's words for its first error, or the status.
76
+ */
77
+ mutate: async (what: string, operation: string, variables: Variables) =>
78
+ mutated(what, await graphql(operation, variables)),
79
+ /**
80
+ * `operation`, a GraphQL query the drop-in serves at `/api/graphql`, sent with `variables`:
81
+ * its answer's `data`, as `schema` reads it, or `answered`'s throw.
82
+ */
83
+ query: async <A>(
84
+ what: string,
85
+ operation: string,
86
+ variables: Variables,
87
+ schema: Schema.Decoder<A>,
88
+ ) => answered(what, await graphql(operation, variables), schema),
89
+ /** The operations of `ask.kinds` the viewer may make on its repo, or on its issue. */
90
+ allowed: transport.allowed,
91
+ };
92
+ };
78
93
 
79
- /** TanStack Query's hooks and options over each client. */
80
- export const githubQueries = createQueryHooks(github);
94
+ export type Clients = ReturnType<typeof createClients>;
81
95
 
82
- export const gitQueries = createQueryHooks(git);
96
+ /** The router's clients, for a component: the ones its loaders read too. */
97
+ export const useClients = (): Clients => useRouteContext({ from: '__root__' }).clients;
@@ -0,0 +1,13 @@
1
+ import { allowedOperations } from './allowed.ts';
2
+ import type { Transport } from './clients.ts';
3
+ import { callApi } from './proxy.ts';
4
+
5
+ /**
6
+ * The app's transport, in the browser and on the server alike: each call through `callApi` and
7
+ * each page's controls through `allowedOperations`, Start's server functions, which act as the
8
+ * request's session's holder.
9
+ */
10
+ export const serverTransport: Transport = {
11
+ call: (call, signal) => callApi({ data: call, signal }),
12
+ allowed: (ask) => allowedOperations({ data: ask }),
13
+ };
@@ -5,6 +5,7 @@ import { useNavigate } from '@tanstack/react-router';
5
5
  import { CircleAlertIcon } from 'lucide-react';
6
6
  import { useEffect, useRef, useState } from 'react';
7
7
 
8
+ import { useClients } from '../clients/clients.ts';
8
9
  import { fileIcons, glyphSprite, glyphSymbols } from '../components/file-icons/file-icons.tsx';
9
10
  import { Alert, AlertAction, AlertDescription } from '../components/ui/alert.tsx';
10
11
  import { Button } from '../components/ui/button.tsx';
@@ -180,6 +181,7 @@ function Tree({
180
181
  readonly at: At;
181
182
  readonly walked: readonly Folder[];
182
183
  }) {
184
+ const clients = useClients();
183
185
  const navigate = useNavigate();
184
186
  const ref = at.ref.name;
185
187
  const here = hereOf(at, walked);
@@ -224,7 +226,7 @@ function Tree({
224
226
 
225
227
  const openedPaths = [...opened.keys()];
226
228
  const levels = useQueries({
227
- queries: [...opened].map(([path, sha]) => folder(at, sha, path)),
229
+ queries: [...opened].map(([path, sha]) => folder(clients, at, sha, path)),
228
230
  combine: (results) => ({
229
231
  read: results.flatMap((result) => result.data ?? []),
230
232
  failed: results.flatMap((result, index) =>
@@ -4,6 +4,7 @@ import { createClientOnlyFn } from '@tanstack/react-start';
4
4
  import { CircleAlertIcon, DownloadIcon, HistoryIcon, InfoIcon } from 'lucide-react';
5
5
  import { lazy, Suspense, useCallback, useEffect, useState, type ReactNode } from 'react';
6
6
 
7
+ import { useClients } from '../clients/clients.ts';
7
8
  import { Markdown } from '../components/markdown/markdown.tsx';
8
9
  import { Tabs } from '../components/ui/tabs.tsx';
9
10
  import { ViewTabs } from '../components/view-tabs.tsx';
@@ -24,7 +25,7 @@ import {
24
25
  rangeOf,
25
26
  type LineRange,
26
27
  } from './lines.ts';
27
- import { contextOf, markdownOf } from './markdown-files.ts';
28
+ import { addressOf, contextOf, markdownOf } from './markdown-files.ts';
28
29
  import { blobHref, commitsHref, nameOf, rawHref, type At } from './places.ts';
29
30
 
30
31
  const loadHighlighted = createClientOnlyFn(() => import('./highlighted.tsx'));
@@ -84,10 +85,13 @@ function Views({ at, plain }: { readonly at: At; readonly plain: boolean }) {
84
85
  }
85
86
 
86
87
  /** Saves the file's whole bytes, its LFS object's for an LFS file, under its own name. */
87
- const useDownload = (at: At, file: FileAt) =>
88
- useMutation({
89
- mutationFn: async () => save(await fileBytes(at, file), nameOf(file.path)),
88
+ const useDownload = (at: At, file: FileAt) => {
89
+ const clients = useClients();
90
+
91
+ return useMutation({
92
+ mutationFn: async () => save(await fileBytes(clients, at, file), nameOf(file.path)),
90
93
  });
94
+ };
91
95
 
92
96
  type Download = ReturnType<typeof useDownload>;
93
97
 
@@ -295,7 +299,8 @@ function LargePicture({
295
299
  readonly file: FileAt;
296
300
  readonly type: string;
297
301
  }) {
298
- const bytes = useQuery(imageBytes(at, file));
302
+ const clients = useClients();
303
+ const bytes = useQuery(imageBytes(clients, at, file));
299
304
  if (bytes.data !== undefined)
300
305
  return <Picture bytes={bytes.data} type={type} name={nameOf(file.path)} />;
301
306
 
@@ -326,7 +331,11 @@ function Body({
326
331
  if (markdown !== undefined && !plain) {
327
332
  return (
328
333
  <div className="px-8 py-6 text-sm">
329
- <Markdown text={markdown} context={contextOf(at, file.path)} />
334
+ <Markdown
335
+ text={markdown}
336
+ context={contextOf(at, file.path)}
337
+ from={addressOf(at, file.path)}
338
+ />
330
339
  </div>
331
340
  );
332
341
  }
@@ -1,7 +1,7 @@
1
1
  import type { components } from '@octokit/openapi-types';
2
2
  import { queryOptions } from '@tanstack/react-query';
3
3
 
4
- import { github, raw } from '../clients/clients.ts';
4
+ import type { Clients } from '../clients/clients.ts';
5
5
  import { nameOf, rawHref, type RepoPlace } from './places.ts';
6
6
 
7
7
  /**
@@ -110,16 +110,16 @@ const shownWithout = (path: string, size: number): Shown => {
110
110
  };
111
111
 
112
112
  /** The drop-in's raw route's answer for `path` at `commit`, read as the viewer. */
113
- const rawAnswer = async (place: RepoPlace, commit: string, path: string) => {
114
- const answer = await raw(rawHref(place, commit, path));
113
+ const rawAnswer = async (clients: Clients, place: RepoPlace, commit: string, path: string) => {
114
+ const answer = await clients.raw(rawHref(place, commit, path));
115
115
  if (!answer.ok) throw new Error(`The file didn't download (${answer.status})`);
116
116
 
117
117
  return answer;
118
118
  };
119
119
 
120
120
  /** The bytes the drop-in's raw route answers for `path` at `commit`, read as the viewer. */
121
- export const rawBytes = async (place: RepoPlace, commit: string, path: string) =>
122
- (await rawAnswer(place, commit, path)).blob();
121
+ export const rawBytes = async (clients: Clients, place: RepoPlace, commit: string, path: string) =>
122
+ (await rawAnswer(clients, place, commit, path)).blob();
123
123
 
124
124
  /** `answer`'s body when it holds at most `most` bytes; `undefined` past them, the rest unread. */
125
125
  const bodyUpTo = async (answer: Response, most: number) => {
@@ -160,6 +160,7 @@ const bodyUpTo = async (answer: Response, most: number) => {
160
160
  * is the pusher's word, so the read stops at `shownBytesMost` whatever it says.
161
161
  */
162
162
  const objectAt = async (
163
+ clients: Clients,
163
164
  place: RepoPlace,
164
165
  at: Omit<FileAt, 'shown' | 'lfs'>,
165
166
  size: number,
@@ -169,7 +170,7 @@ const objectAt = async (
169
170
  return { ...at, lfs: { size, stored: undefined }, shown: shownWithout(at.path, size) };
170
171
  }
171
172
 
172
- const bytes = await bodyUpTo(await rawAnswer(place, at.commit, at.path), shownBytesMost);
173
+ const bytes = await bodyUpTo(await rawAnswer(clients, place, at.commit, at.path), shownBytesMost);
173
174
  if (bytes === undefined) return { ...at, lfs: { size, stored: true }, shown: { kind: 'tooBig' } };
174
175
 
175
176
  const stored = new TextDecoder().decode(bytes) !== pointer.text;
@@ -192,6 +193,7 @@ type ContentAnswer =
192
193
  * pointer costs a call, for its object.
193
194
  */
194
195
  const fileOf = async (
196
+ clients: Clients,
195
197
  place: RepoPlace,
196
198
  commit: string,
197
199
  path: string,
@@ -215,18 +217,18 @@ const fileOf = async (
215
217
  const size = lfsSize(pointer);
216
218
  if (size === undefined) return { ...at, shown: shownOf(path, bytes) };
217
219
 
218
- return objectAt(place, at, size, { kind: 'text', text: pointer });
220
+ return objectAt(clients, place, at, size, { kind: 'text', text: pointer });
219
221
  };
220
222
 
221
223
  /**
222
224
  * The file at `path` in the commit `commit`: one call, or `null` where no file is. An LFS pointer
223
225
  * costs a second, for its object.
224
226
  */
225
- export const fileAt = (place: RepoPlace, commit: string, path: string) =>
227
+ export const fileAt = (clients: Clients, place: RepoPlace, commit: string, path: string) =>
226
228
  queryOptions({
227
229
  queryKey: ['file', place.owner, place.repo, commit, path],
228
230
  queryFn: async (): Promise<FileAt | null> => {
229
- const answer = await github.GET('/repos/{owner}/{repo}/contents/{path}', {
231
+ const answer = await clients.github.GET('/repos/{owner}/{repo}/contents/{path}', {
230
232
  params: { path: { ...place, path }, query: { ref: commit } },
231
233
  });
232
234
  if (answer.response.status === 404) return null;
@@ -239,7 +241,7 @@ export const fileAt = (place: RepoPlace, commit: string, path: string) =>
239
241
  throw new Error(`The file didn't load (${answer.response.status})`);
240
242
  }
241
243
 
242
- return Array.isArray(answer.data) ? null : fileOf(place, commit, path, answer.data);
244
+ return Array.isArray(answer.data) ? null : fileOf(clients, place, commit, path, answer.data);
243
245
  },
244
246
  staleTime: Infinity,
245
247
  });
@@ -250,11 +252,13 @@ export const fileAt = (place: RepoPlace, commit: string, path: string) =>
250
252
  * fails. Its answer never goes stale, since `readmeAt` draws it only where the root the home draws
251
253
  * lists that same file, by its blob's ID.
252
254
  */
253
- export const readmeNow = (place: RepoPlace) =>
255
+ export const readmeNow = (clients: Clients, place: RepoPlace) =>
254
256
  queryOptions({
255
257
  queryKey: ['readme', place.owner, place.repo],
256
258
  queryFn: async () => {
257
- const answer = await github.GET('/repos/{owner}/{repo}/readme', { params: { path: place } });
259
+ const answer = await clients.github.GET('/repos/{owner}/{repo}/readme', {
260
+ params: { path: place },
261
+ });
258
262
 
259
263
  return answer.data ?? null;
260
264
  },
@@ -267,6 +271,7 @@ export const readmeNow = (place: RepoPlace) =>
267
271
  * push changed, or the drop-in picked among two, is read at the commit, as without it.
268
272
  */
269
273
  export const readmeAt = async (
274
+ clients: Clients,
270
275
  place: RepoPlace,
271
276
  commit: string,
272
277
  named: { readonly path: string; readonly sha: string },
@@ -274,12 +279,12 @@ export const readmeAt = async (
274
279
  ) => {
275
280
  const same = early !== null && early.path === named.path && early.sha === named.sha;
276
281
 
277
- return same ? fileOf(place, commit, named.path, early) : undefined;
282
+ return same ? fileOf(clients, place, commit, named.path, early) : undefined;
278
283
  };
279
284
 
280
285
  /** A blob's bytes, read raw through the REST client as the viewer. */
281
- const blobBytes = async (place: RepoPlace, sha: string) => {
282
- const answer = await github.GET('/repos/{owner}/{repo}/git/blobs/{file_sha}', {
286
+ const blobBytes = async (clients: Clients, place: RepoPlace, sha: string) => {
287
+ const answer = await clients.github.GET('/repos/{owner}/{repo}/git/blobs/{file_sha}', {
283
288
  params: { path: { ...place, file_sha: sha } },
284
289
  headers: { accept: 'application/vnd.github.raw' },
285
290
  parseAs: 'blob',
@@ -296,18 +301,20 @@ const blobBytes = async (place: RepoPlace, sha: string) => {
296
301
  * A file's whole bytes, for a download or an image: an LFS file's object as the raw route answers
297
302
  * it, its pointer when the bucket lacks it, and any other file's blob.
298
303
  */
299
- export const fileBytes = (place: RepoPlace, file: FileAt) =>
300
- file.lfs === undefined ? blobBytes(place, file.sha) : rawBytes(place, file.commit, file.path);
304
+ export const fileBytes = (clients: Clients, place: RepoPlace, file: FileAt) =>
305
+ file.lfs === undefined
306
+ ? blobBytes(clients, place, file.sha)
307
+ : rawBytes(clients, place, file.commit, file.path);
301
308
 
302
309
  /**
303
310
  * The bytes of an image too big for the contents API, up to `imageBytesMost`. An LFS image whose
304
311
  * object isn't stored fails, as an image that didn't load, which the page offers to download.
305
312
  */
306
- export const imageBytes = (place: RepoPlace, file: FileAt) =>
313
+ export const imageBytes = (clients: Clients, place: RepoPlace, file: FileAt) =>
307
314
  queryOptions({
308
315
  queryKey: ['image', place.owner, place.repo, file.commit, file.path],
309
316
  queryFn: async () => {
310
- const bytes = new Uint8Array(await (await fileBytes(place, file)).arrayBuffer());
317
+ const bytes = new Uint8Array(await (await fileBytes(clients, place, file)).arrayBuffer());
311
318
 
312
319
  if (file.lfs !== undefined && bytes.length !== file.lfs.size) {
313
320
  throw new Error("Its Git LFS object isn't stored");
@@ -2,6 +2,7 @@ import { useQuery } from '@tanstack/react-query';
2
2
  import { ChevronDownIcon, SearchIcon } from 'lucide-react';
3
3
  import { useState } from 'react';
4
4
 
5
+ import { useClients } from '../clients/clients.ts';
5
6
  import { FileIcon } from '../components/file-icons/file-icons.tsx';
6
7
  import { HotkeyHint, hotkeys } from '../components/hotkeys/hotkeys.tsx';
7
8
  import { Alert, AlertDescription } from '../components/ui/alert.tsx';
@@ -91,7 +92,7 @@ function Finder({
91
92
  }
92
93
 
93
94
  const useAllFiles = (at: At, root: string, open: boolean) =>
94
- useQuery({ ...allFiles(at, root), enabled: open });
95
+ useQuery({ ...allFiles(useClients(), at, root), enabled: open });
95
96
 
96
97
  /**
97
98
  * Finds a file by its path. Every path costs one call, made only when the reader opens it: the
@@ -1,6 +1,7 @@
1
1
  import type { QueryClient } from '@tanstack/react-query';
2
2
 
3
3
  import { cached } from '../clients/cached.ts';
4
+ import type { Clients } from '../clients/clients.ts';
4
5
 
5
6
  import { fileAt, readmeAt, readmeNow, type FileAt } from './files.ts';
6
7
  import { readmeIn, renderAhead } from './markdown-files.ts';
@@ -23,9 +24,15 @@ export interface CodeLoad {
23
24
  }
24
25
 
25
26
  /** The file at `path` in the commit `commit`, from memory, or saved when this page saves reads. */
26
- const readFile = async (client: QueryClient, place: RepoPlace, commit: string, path: string) => {
27
- const options = fileAt(place, commit, path);
28
- await restore(client, place, options.queryKey, (saved) => {
27
+ const readFile = async (
28
+ clients: Clients,
29
+ client: QueryClient,
30
+ place: RepoPlace,
31
+ commit: string,
32
+ path: string,
33
+ ) => {
34
+ const options = fileAt(clients, place, commit, path);
35
+ await restore(clients, client, place, options.queryKey, (saved) => {
29
36
  if ('shown' in saved) client.setQueryData(options.queryKey, saved);
30
37
  });
31
38
 
@@ -37,30 +44,38 @@ const readFile = async (client: QueryClient, place: RepoPlace, commit: string, p
37
44
  * names is asked beside the ref's checks, since that's the ref most pages name, and it's drawn
38
45
  * only once they name that branch. A ref with a slash, or a tag, asks for its own head after them.
39
46
  */
40
- const refAndHead = async (client: QueryClient, place: RepoPlace, splat: string) => {
47
+ const refAndHead = async (
48
+ clients: Clients,
49
+ client: QueryClient,
50
+ place: RepoPlace,
51
+ splat: string,
52
+ ) => {
41
53
  const first = splat.split('/')[0] ?? '';
42
54
 
43
55
  if (first !== '' && !isOid(first)) {
44
56
  // Its answer, or its failure, waits under that branch's key for the head asked below.
45
- void client.query(headCommit(place, { name: first, kind: 'branch' })).catch(() => undefined);
57
+ void client
58
+ .query(headCommit(clients, place, { name: first, kind: 'branch' }))
59
+ .catch(() => undefined);
46
60
  }
47
61
 
48
- const at = await atOf(client, place, splat);
49
- const head = at === undefined ? null : await client.query(headCommit(place, at.ref));
62
+ const at = await atOf(clients, client, place, splat);
63
+ const head = at === undefined ? null : await client.query(headCommit(clients, place, at.ref));
50
64
 
51
65
  return { at, head };
52
66
  };
53
67
 
54
68
  /** A folder's page, or `undefined` where the URL names no folder. */
55
69
  export const loadFolder = async (
70
+ clients: Clients,
56
71
  client: QueryClient,
57
72
  place: RepoPlace,
58
73
  splat: string,
59
74
  ): Promise<CodeLoad | undefined> => {
60
- const { at, head } = await refAndHead(client, place, splat);
75
+ const { at, head } = await refAndHead(clients, client, place, splat);
61
76
  if (at === undefined || head === null) return undefined;
62
77
 
63
- const walked = await walk(client, place, head.tree, at.path);
78
+ const walked = await walk(clients, client, place, head.tree, at.path);
64
79
 
65
80
  return walked === undefined ? undefined : { at, head, walked };
66
81
  };
@@ -79,20 +94,21 @@ export interface HomeLoad {
79
94
  * the default branch, when it's that same file, so it costs no read after the root's.
80
95
  */
81
96
  const readReadme = async (
97
+ clients: Clients,
82
98
  client: QueryClient,
83
99
  place: RepoPlace,
84
100
  commit: string,
85
101
  named: Entry,
86
- early: Promise<Parameters<typeof readmeAt>[3]>,
102
+ early: Promise<Parameters<typeof readmeAt>[4]>,
87
103
  ) => {
88
- const options = fileAt(place, commit, named.path);
104
+ const options = fileAt(clients, place, commit, named.path);
89
105
 
90
106
  if (client.getQueryData(options.queryKey) === undefined) {
91
- const file = await readmeAt(place, commit, named, await early);
107
+ const file = await readmeAt(clients, place, commit, named, await early);
92
108
  if (file !== undefined) client.setQueryData(options.queryKey, file);
93
109
  }
94
110
 
95
- return readFile(client, place, commit, named.path);
111
+ return readFile(clients, client, place, commit, named.path);
96
112
  };
97
113
 
98
114
  /**
@@ -101,23 +117,24 @@ const readReadme = async (
101
117
  * README is asked beside the repo, its head and its root, so the home waits on one read fewer.
102
118
  */
103
119
  export const loadHome = async (
120
+ clients: Clients,
104
121
  client: QueryClient,
105
122
  place: RepoPlace,
106
123
  ): Promise<HomeLoad | undefined> => {
107
124
  // A README the drop-in can't read is read at the commit, as the root names it.
108
- const early = client.query(readmeNow(place)).catch(() => null);
109
- const repo = await cached(client, repoAt(place));
125
+ const early = client.query(readmeNow(clients, place)).catch(() => null);
126
+ const repo = await cached(client, repoAt(clients, place));
110
127
  if (repo === null) return undefined;
111
128
 
112
129
  const at = { ...place, ref: { name: repo.defaultBranch, kind: 'branch' as const }, path: '' };
113
- const head = await client.query(headCommit(place, at.ref));
130
+ const head = await client.query(headCommit(clients, place, at.ref));
114
131
  if (head === null) return { repo, at, head, root: null, readme: null };
115
132
 
116
- const root = await readFolder(client, place, head.tree, '');
133
+ const root = await readFolder(clients, client, place, head.tree, '');
117
134
  const named = readmeIn(root);
118
135
  const readme =
119
- named === undefined ? null : await readReadme(client, place, head.sha, named, early);
120
- if (readme !== null) await renderAhead(client, at, readme);
136
+ named === undefined ? null : await readReadme(clients, client, place, head.sha, named, early);
137
+ if (readme !== null) await renderAhead(clients, client, at, readme);
121
138
 
122
139
  return { repo, at, head, root, readme };
123
140
  };
@@ -127,21 +144,22 @@ export const loadHome = async (
127
144
  * unless the reader asked for its code with `plain`.
128
145
  */
129
146
  export const loadFile = async (
147
+ clients: Clients,
130
148
  client: QueryClient,
131
149
  place: RepoPlace,
132
150
  splat: string,
133
151
  plain = false,
134
152
  ): Promise<(CodeLoad & { readonly file: FileAt }) | undefined> => {
135
- const { at, head } = await refAndHead(client, place, splat);
153
+ const { at, head } = await refAndHead(clients, client, place, splat);
136
154
  if (at === undefined || head === null || at.path === '') return undefined;
137
155
 
138
156
  const [walked, file] = await Promise.all([
139
- walk(client, place, head.tree, parentOf(at.path)),
140
- readFile(client, place, head.sha, at.path),
157
+ walk(clients, client, place, head.tree, parentOf(at.path)),
158
+ readFile(clients, client, place, head.sha, at.path),
141
159
  ]);
142
160
  if (walked === undefined || file === null) return undefined;
143
161
 
144
- if (!plain) await renderAhead(client, at, file);
162
+ if (!plain) await renderAhead(clients, client, at, file);
145
163
 
146
164
  return { at, head, walked, file };
147
165
  };
@@ -1,8 +1,10 @@
1
1
  import type { QueryClient } from '@tanstack/react-query';
2
2
 
3
3
  import { readAhead } from '../clients/cached.ts';
4
+ import type { Clients } from '../clients/clients.ts';
4
5
  import type { FileContext } from '../markdown/context.ts';
5
6
  import { markdownQuery } from '../markdown/query.ts';
7
+ import type { TextAddress } from '../markdown/texts.ts';
6
8
  import type { FileAt } from './files.ts';
7
9
  import { nameOf, parentOf, type At } from './places.ts';
8
10
  import type { Entry, Folder } from './trees.ts';
@@ -40,6 +42,14 @@ export const contextOf = (at: At, path: string): FileContext => ({
40
42
  dir: parentOf(path),
41
43
  });
42
44
 
45
+ /** Where a file's text is kept, at the page's ref, which the image proxy signs its images for. */
46
+ export const addressOf = (at: At, path: string): TextAddress => ({
47
+ kind: 'file',
48
+ repo: `${at.owner}/${at.repo}`,
49
+ ref: at.ref.name,
50
+ path,
51
+ });
52
+
43
53
  /** A file's text when its page may show it rendered: a Markdown file the page holds as text. */
44
54
  export const markdownOf = (file: FileAt) =>
45
55
  file.shown.kind === 'text' && isMarkdown(file.path) ? file.shown.text : undefined;
@@ -52,7 +62,8 @@ export const readmeIn = (folder: Folder): Entry | undefined =>
52
62
  * A Markdown file rendered ahead, for the server's page: nothing for any other file. A render that
53
63
  * fails leaves the page to `Markdown`, which draws the text unlinked and tries again.
54
64
  */
55
- export const renderAhead = async (client: QueryClient, at: At, file: FileAt) => {
65
+ export const renderAhead = async (clients: Clients, client: QueryClient, at: At, file: FileAt) => {
56
66
  const text = markdownOf(file);
57
- if (text !== undefined) await readAhead(client, markdownQuery(text, contextOf(at, file.path)));
67
+ if (text !== undefined)
68
+ await readAhead(client, markdownQuery(clients, text, contextOf(at, file.path)));
58
69
  };