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,6 +1,6 @@
1
1
  import * as Schema from 'effect/Schema';
2
2
 
3
- import { query } from '../clients/clients.ts';
3
+ import type { Clients } from '../clients/clients.ts';
4
4
  import type { RepoPlace } from './places.ts';
5
5
 
6
6
  /**
@@ -140,7 +140,11 @@ export interface RefAsk {
140
140
  * A page of the repo's refs, in one call: the drop-in lists them by name, and a page with
141
141
  * `hasNextPage` names the next one's cursor even when it holds fewer than `first`.
142
142
  */
143
- export const readRefPage = async (place: RepoPlace, ask: RefAsk): Promise<RefPage> => {
143
+ export const readRefPage = async (
144
+ clients: Clients,
145
+ place: RepoPlace,
146
+ ask: RefAsk,
147
+ ): Promise<RefPage> => {
144
148
  const variables = {
145
149
  owner: place.owner,
146
150
  name: place.repo,
@@ -149,7 +153,12 @@ export const readRefPage = async (place: RepoPlace, ask: RefAsk): Promise<RefPag
149
153
  after: ask.after ?? null,
150
154
  query: ask.search === '' ? null : ask.search,
151
155
  };
152
- const { repository } = await query("The refs didn't load", refsOperation, variables, RefsAnswer);
156
+ const { repository } = await clients.query(
157
+ "The refs didn't load",
158
+ refsOperation,
159
+ variables,
160
+ RefsAnswer,
161
+ );
153
162
  if (repository === null || repository.refs === null) throw new Error("The refs didn't load");
154
163
 
155
164
  const { nodes, pageInfo } = repository.refs;
@@ -169,10 +178,10 @@ const firstPage: string | undefined = undefined;
169
178
  * A list's pages of refs, read a page at a time as the reader asks for more, for a place's prefix,
170
179
  * page size and search.
171
180
  */
172
- export const refPages = (place: RepoPlace, ask: Omit<RefAsk, 'after'>) => ({
181
+ export const refPages = (clients: Clients, place: RepoPlace, ask: Omit<RefAsk, 'after'>) => ({
173
182
  queryKey: ['ref-pages', place.owner, place.repo, ask.prefix, ask.first, ask.search] as const,
174
183
  queryFn: ({ pageParam }: { readonly pageParam: string | undefined }) =>
175
- readRefPage(place, { ...ask, after: pageParam }),
184
+ readRefPage(clients, place, { ...ask, after: pageParam }),
176
185
  initialPageParam: firstPage,
177
186
  getNextPageParam: (last: RefPage) => last.next,
178
187
  staleTime: 30_000,
@@ -2,6 +2,7 @@ import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
2
2
  import { GitBranchIcon, GitCommitIcon, TagIcon } from 'lucide-react';
3
3
  import { useState } from 'react';
4
4
 
5
+ import { type Clients, useClients } from '../clients/clients.ts';
5
6
  import { Alert, AlertDescription } from '../components/ui/alert.tsx';
6
7
  import { Button } from '../components/ui/button.tsx';
7
8
  import {
@@ -38,7 +39,7 @@ interface NamesPage {
38
39
  * A kind's names, a page of 100 at a time: the switcher's list, which the palette's branches and
39
40
  * tags read too, from the same cache.
40
41
  */
41
- export const refNameList = (place: RepoPlace, kind: Kind) =>
42
+ export const refNameList = (clients: Clients, place: RepoPlace, kind: Kind) =>
42
43
  infiniteQueryOptions({
43
44
  queryKey: ['refs', place.owner, place.repo, kind],
44
45
  queryFn: async ({
@@ -46,7 +47,7 @@ export const refNameList = (place: RepoPlace, kind: Kind) =>
46
47
  }: {
47
48
  readonly pageParam: string | undefined;
48
49
  }): Promise<NamesPage> => {
49
- const page = await refNames(place, kind, pageParam);
50
+ const page = await refNames(clients, place, kind, pageParam);
50
51
 
51
52
  return { names: page.names, next: nextCursor(page.link) };
52
53
  },
@@ -57,7 +58,7 @@ export const refNameList = (place: RepoPlace, kind: Kind) =>
57
58
 
58
59
  /** A kind's names, read only while the switcher is open. */
59
60
  const useNames = (place: RepoPlace, kind: Kind, open: boolean) =>
60
- useInfiniteQuery({ ...refNameList(place, kind), enabled: open });
61
+ useInfiniteQuery({ ...refNameList(useClients(), place, kind), enabled: open });
61
62
 
62
63
  /**
63
64
  * A kind's names as the switcher lists them: its filter, what it holds, and more to load. Each is
@@ -1,13 +1,15 @@
1
1
  import { focusManager, queryOptions, type QueryClient } from '@tanstack/react-query';
2
2
 
3
- import { github } from '../clients/clients.ts';
3
+ import type { Clients } from '../clients/clients.ts';
4
+ import { isText } from '../diffs/files.ts';
4
5
  import { isOid, revisionOf, type At, type Ref, type RepoPlace } from './places.ts';
5
6
 
6
7
  /**
7
8
  * A code page's URL holds its ref and its path in one splat, `feature/x/src/a.ts`, as GitHub's
8
9
  * does. Git refuses `heads/a` beside `heads/a/b`, so at most one of the splat's prefixes is a
9
10
  * branch, and it wins: the app asks for each prefix, shortest first, and once one is only a tag,
10
- * asks whether a longer one is a branch before it takes the tag. A full commit ID needs no asking.
11
+ * asks whether a longer one is a branch before it takes the tag. A full commit ID needs no asking,
12
+ * and a short one, where no branch or tag has the name, is asked of `commits/{ref}`.
11
13
  */
12
14
 
13
15
  /** How long the app trusts what a ref names before asking again: a push may move it. */
@@ -17,11 +19,11 @@ export const refFresh = 30_000;
17
19
  * Whether `refs/<namespace>/<name>` is a ref: one call, remembered for `refFresh`. A name Git
18
20
  * refuses, such as one with a part that starts with `.`, names none: the drop-in answers 422.
19
21
  */
20
- const refExists = (place: RepoPlace, namespace: 'heads' | 'tags', name: string) =>
22
+ const refExists = (clients: Clients, place: RepoPlace, namespace: 'heads' | 'tags', name: string) =>
21
23
  queryOptions({
22
24
  queryKey: ['ref', place.owner, place.repo, namespace, name],
23
25
  queryFn: async () => {
24
- const answer = await github.GET('/repos/{owner}/{repo}/git/ref/{ref}', {
26
+ const answer = await clients.github.GET('/repos/{owner}/{repo}/git/ref/{ref}', {
25
27
  params: { path: { ...place, ref: `${namespace}/${name}` } },
26
28
  });
27
29
  if ([404, 422].includes(answer.response.status)) return false;
@@ -37,6 +39,7 @@ const refExists = (place: RepoPlace, namespace: 'heads' | 'tags', name: string)
37
39
 
38
40
  /** `splat`'s ref and the path after it, or `undefined` when no prefix of it is a ref. */
39
41
  export const atOf = async (
42
+ clients: Clients,
40
43
  client: QueryClient,
41
44
  place: RepoPlace,
42
45
  splat: string,
@@ -48,7 +51,7 @@ export const atOf = async (
48
51
 
49
52
  const prefix = (count: number) => segments.slice(0, count).join('/');
50
53
  const exists = (namespace: 'heads' | 'tags', count: number) =>
51
- client.query(refExists(place, namespace, prefix(count)));
54
+ client.query(refExists(clients, place, namespace, prefix(count)));
52
55
  const at = (count: number, kind: 'branch' | 'tag'): At => ({
53
56
  ...place,
54
57
  ref: { name: prefix(count), kind },
@@ -68,9 +71,40 @@ export const atOf = async (
68
71
  return found === undefined ? at(count, 'tag') : at(found, 'branch');
69
72
  }
70
73
 
71
- return undefined;
74
+ // A commit's short ID, as GitHub's URLs take one where no branch or tag has the name.
75
+ if (!/^[0-9a-f]{4,63}$/.test(first)) return undefined;
76
+
77
+ const commit = await client.query(shortCommit(clients, place, first));
78
+
79
+ return commit === undefined
80
+ ? undefined
81
+ : { ...place, ref: { name: commit, kind: 'commit' }, path: after(1) };
72
82
  };
73
83
 
84
+ /**
85
+ * The whole ID of the commit `short` starts, as the drop-in's `commits/{ref}` resolves it, or
86
+ * `undefined` where it names none or more than one: one call, remembered for `refFresh`.
87
+ */
88
+ const shortCommit = (clients: Clients, place: RepoPlace, short: string) =>
89
+ queryOptions({
90
+ queryKey: ['short', place.owner, place.repo, short],
91
+ queryFn: async () => {
92
+ const answer = await clients.github.GET('/repos/{owner}/{repo}/commits/{ref}', {
93
+ params: { path: { ...place, ref: short } },
94
+ });
95
+ if ([404, 422].includes(answer.response.status)) return undefined;
96
+
97
+ if (answer.data === undefined) {
98
+ throw new Error(`The commit didn't load (${answer.response.status})`);
99
+ }
100
+
101
+ const sha = isText(answer.data) ? undefined : answer.data.sha;
102
+
103
+ return sha?.startsWith(short) === true ? sha : undefined;
104
+ },
105
+ staleTime: refFresh,
106
+ });
107
+
74
108
  /**
75
109
  * Marks what each ref names stale each time the window has focus again, whatever its age: a push
76
110
  * from a terminal moves a branch while the browser is away, so the next click after coming back
@@ -121,11 +155,11 @@ export const rowOf = (commit: {
121
155
  * The commit `ref` names now: its tree is where a page's paths start, and it's the home page's
122
156
  * latest commit. `undefined` for a repository with no commits, or a ref that names none.
123
157
  */
124
- export const headCommit = (place: RepoPlace, ref: Ref) =>
158
+ export const headCommit = (clients: Clients, place: RepoPlace, ref: Ref) =>
125
159
  queryOptions({
126
160
  queryKey: ['head', place.owner, place.repo, ref.kind, ref.name],
127
161
  queryFn: async (): Promise<CommitRow | null> => {
128
- const answer = await github.GET('/repos/{owner}/{repo}/commits', {
162
+ const answer = await clients.github.GET('/repos/{owner}/{repo}/commits', {
129
163
  params: { path: place, query: { sha: revisionOf(ref), per_page: 1 } },
130
164
  });
131
165
  if ([404, 409, 422].includes(answer.response.status)) return null;
@@ -31,7 +31,7 @@ import type { FileAt } from './files.ts';
31
31
  import { FolderList } from './folder-list.tsx';
32
32
  import { GoToFile } from './go-to-file.tsx';
33
33
  import type { HomeLoad } from './load.ts';
34
- import { contextOf, markdownOf } from './markdown-files.ts';
34
+ import { addressOf, contextOf, markdownOf } from './markdown-files.ts';
35
35
  import { blobHref, commitHref, commitsHref, nameOf, treeHref, type At } from './places.ts';
36
36
  import { RefSwitcher } from './ref-switcher.tsx';
37
37
  import type { CommitRow } from './refs.ts';
@@ -148,7 +148,11 @@ function Readme({ at, file }: { readonly at: At; readonly file: FileAt }) {
148
148
  </CardHeader>
149
149
  <CardContent className="px-6 py-4 text-sm">
150
150
  {markdown !== undefined ? (
151
- <Markdown text={markdown} context={contextOf(at, file.path)} />
151
+ <Markdown
152
+ text={markdown}
153
+ context={contextOf(at, file.path)}
154
+ from={addressOf(at, file.path)}
155
+ />
152
156
  ) : shown.kind === 'text' ? (
153
157
  <pre className="overflow-x-auto font-mono text-sm whitespace-pre-wrap">
154
158
  {shown.text}
@@ -1,6 +1,6 @@
1
1
  import { queryOptions } from '@tanstack/react-query';
2
2
 
3
- import { github } from '../clients/clients.ts';
3
+ import type { Clients } from '../clients/clients.ts';
4
4
  import type { RepoPlace } from './places.ts';
5
5
 
6
6
  /** A way GitHub merges a pull request, as `merge_method` names it. */
@@ -41,12 +41,15 @@ const licenseOf = (
41
41
  return `${id} license`;
42
42
  };
43
43
 
44
+ /** The key `repoAt` caches its answer under, for a reader that only looks in the cache. */
45
+ export const repoKey = (place: RepoPlace) => ['repo', place.owner, place.repo] as const;
46
+
44
47
  /** The repository `place` names, or `null` when the viewer can't read one there. */
45
- export const repoAt = (place: RepoPlace) =>
48
+ export const repoAt = (clients: Clients, place: RepoPlace) =>
46
49
  queryOptions({
47
- queryKey: ['repo', place.owner, place.repo],
50
+ queryKey: repoKey(place),
48
51
  queryFn: async (): Promise<Repo | null> => {
49
- const answer = await github.GET('/repos/{owner}/{repo}', { params: { path: place } });
52
+ const answer = await clients.github.GET('/repos/{owner}/{repo}', { params: { path: place } });
50
53
  // A visitor gets 401 at a private or missing repo (Q139); a signed-in reader gets 404.
51
54
  // Neither says which it is. A session whose token Git refuses ends in `callApi`, which asks
52
55
  // again as a visitor, so a 401 is always a visitor's.
@@ -84,6 +87,7 @@ export const repoAt = (place: RepoPlace) =>
84
87
 
85
88
  /** A list of `ref`'s names, branches' or tags', a page of 100 at a time from `after`. */
86
89
  export const refNames = async (
90
+ clients: Clients,
87
91
  place: RepoPlace,
88
92
  kind: 'branches' | 'tags',
89
93
  after: string | undefined,
@@ -94,8 +98,10 @@ export const refNames = async (
94
98
  const query = { ...paging };
95
99
  const answer =
96
100
  kind === 'branches'
97
- ? await github.GET('/repos/{owner}/{repo}/branches', { params: { path: place, query } })
98
- : await github.GET('/repos/{owner}/{repo}/tags', { params: { path: place, query } });
101
+ ? await clients.github.GET('/repos/{owner}/{repo}/branches', {
102
+ params: { path: place, query },
103
+ })
104
+ : await clients.github.GET('/repos/{owner}/{repo}/tags', { params: { path: place, query } });
99
105
 
100
106
  if (answer.data === undefined) {
101
107
  throw new Error(`The ${kind} didn't load (${answer.response.status})`);
@@ -2,8 +2,9 @@ import { hashKey, type QueryClient, type QueryKey } from '@tanstack/react-query'
2
2
  import * as Option from 'effect/Option';
3
3
  import * as Schema from 'effect/Schema';
4
4
 
5
+ import type { Clients } from '../clients/clients.ts';
5
6
  import type { RepoPlace } from './places.ts';
6
- import { repoAt } from './repo.ts';
7
+ import { repoAt, repoKey, type Repo } from './repo.ts';
7
8
  import { dropEveryAccount, indexedReads, type Savable, type SavedReads } from './saved-reads.ts';
8
9
 
9
10
  /**
@@ -54,7 +55,7 @@ export const saveAs = (client: QueryClient, account: string | null) => {
54
55
  if (Option.isNone(key)) return;
55
56
 
56
57
  const [, owner, repo] = key.value;
57
- const now = client.getQueryData(repoAt({ owner, repo }).queryKey);
58
+ const now = client.getQueryData<Repo | null>(repoKey({ owner, repo }));
58
59
  const value = client.getQueryData<Savable | null>(key.value);
59
60
  if (now?.private !== false || value === undefined || value === null) return;
60
61
 
@@ -91,6 +92,7 @@ export const forgetEverySaved = async (client: QueryClient) => {
91
92
  * drops its saved reads instead. So a restore never draws what a revoke reached.
92
93
  */
93
94
  export const restore = async (
95
+ clients: Clients,
94
96
  client: QueryClient,
95
97
  place: RepoPlace,
96
98
  key: QueryKey,
@@ -100,7 +102,7 @@ export const restore = async (
100
102
  if (held === undefined || client.getQueryState(key)?.data !== undefined) return;
101
103
 
102
104
  const repo = `${place.owner}/${place.repo}`;
103
- const now = await client.query(repoAt(place)).catch(() => undefined);
105
+ const now = await client.query(repoAt(clients, place)).catch(() => undefined);
104
106
  if (now === undefined) return;
105
107
 
106
108
  if (now === null || now.private) return held.reads.drop(repo);
@@ -1,7 +1,7 @@
1
1
  import { queryOptions, type QueryClient } from '@tanstack/react-query';
2
2
 
3
3
  import { cached } from '../clients/cached.ts';
4
- import { github } from '../clients/clients.ts';
4
+ import type { Clients } from '../clients/clients.ts';
5
5
  import { ancestry, nameOf, type RepoPlace } from './places.ts';
6
6
  import { restore } from './saved.ts';
7
7
 
@@ -45,11 +45,11 @@ export const byKindThenName = (left: Entry, right: Entry) =>
45
45
  rank(left) - rank(right) || (left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
46
46
 
47
47
  /** The folder at `path` whose tree is `sha`: one call, for one level. */
48
- export const folder = (place: RepoPlace, sha: string, path: string) =>
48
+ export const folder = (clients: Clients, place: RepoPlace, sha: string, path: string) =>
49
49
  queryOptions({
50
50
  queryKey: ['tree', place.owner, place.repo, sha, path],
51
51
  queryFn: async (): Promise<Folder> => {
52
- const answer = await github.GET('/repos/{owner}/{repo}/git/trees/{tree_sha}', {
52
+ const answer = await clients.github.GET('/repos/{owner}/{repo}/git/trees/{tree_sha}', {
53
53
  params: { path: { ...place, tree_sha: sha } },
54
54
  });
55
55
 
@@ -77,13 +77,14 @@ export const folder = (place: RepoPlace, sha: string, path: string) =>
77
77
 
78
78
  /** The folder at `path` whose tree is `sha`, from memory, or saved when this page saves reads. */
79
79
  export const readFolder = async (
80
+ clients: Clients,
80
81
  client: QueryClient,
81
82
  place: RepoPlace,
82
83
  sha: string,
83
84
  path: string,
84
85
  ) => {
85
- const options = folder(place, sha, path);
86
- await restore(client, place, options.queryKey, (saved) => {
86
+ const options = folder(clients, place, sha, path);
87
+ await restore(clients, client, place, options.queryKey, (saved) => {
87
88
  if ('entries' in saved) client.setQueryData(options.queryKey, saved);
88
89
  });
89
90
 
@@ -95,30 +96,31 @@ export const readFolder = async (
95
96
  * way, `path` too, isn't a folder: a file's page walks to its parent.
96
97
  */
97
98
  export const walk = async (
99
+ clients: Clients,
98
100
  client: QueryClient,
99
101
  place: RepoPlace,
100
102
  root: string,
101
103
  path: string,
102
104
  ): Promise<readonly Folder[] | undefined> => {
103
- const folders = [await readFolder(client, place, root, '')];
105
+ const folders = [await readFolder(clients, client, place, root, '')];
104
106
 
105
107
  for (const step of ancestry(path)) {
106
108
  const above = folders.at(-1);
107
109
  const entry = above?.entries.find((each) => each.name === nameOf(step));
108
110
  if (entry?.kind !== 'folder') return undefined;
109
111
 
110
- folders.push(await readFolder(client, place, entry.sha, step));
112
+ folders.push(await readFolder(clients, client, place, entry.sha, step));
111
113
  }
112
114
 
113
115
  return folders;
114
116
  };
115
117
 
116
118
  /** Every file's path under the tree `root`, for Go to file: one call, up to the drop-in's 100,000. */
117
- export const allFiles = (place: RepoPlace, root: string) =>
119
+ export const allFiles = (clients: Clients, place: RepoPlace, root: string) =>
118
120
  queryOptions({
119
121
  queryKey: ['files', place.owner, place.repo, root],
120
122
  queryFn: async () => {
121
- const answer = await github.GET('/repos/{owner}/{repo}/git/trees/{tree_sha}', {
123
+ const answer = await clients.github.GET('/repos/{owner}/{repo}/git/trees/{tree_sha}', {
122
124
  params: { path: { ...place, tree_sha: root }, query: { recursive: '1' } },
123
125
  });
124
126
 
@@ -175,3 +175,9 @@
175
175
  height: auto;
176
176
  max-width: 100%;
177
177
  }
178
+
179
+ /* The line above a text too large to render, which shows as written below it (#1098). */
180
+ .markdown-body .markdown-too-large {
181
+ color: var(--muted-foreground);
182
+ font-size: 0.875em;
183
+ }
@@ -1,16 +1,33 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
- import { useEffect, useMemo, useRef, type RefObject } from 'react';
2
+ import {
3
+ createContext,
4
+ useContext,
5
+ useEffect,
6
+ useId,
7
+ useMemo,
8
+ useRef,
9
+ type ReactNode,
10
+ type RefObject,
11
+ } from 'react';
3
12
 
13
+ import { htmlMost } from '@ref0/github/markdown';
14
+
15
+ import { drawRemoteImages, signedImages } from '../../camo/client.ts';
16
+ import { useClients } from '../../clients/clients.ts';
4
17
  import { fragmentTargets, nothingFound, type MarkdownContext } from '../../markdown/context.ts';
5
18
  import { drawnImage, repoImageBlob, repoImageOf } from '../../markdown/images.ts';
19
+ import { pageBudget, type PageBudget } from '../../markdown/page-budget.ts';
6
20
  import { markdownQuery } from '../../markdown/query.ts';
7
21
  import { renderMarkdown } from '../../markdown/render.ts';
22
+ import type { TextAddress } from '../../markdown/texts.ts';
8
23
 
9
24
  /**
10
25
  * Each repo image in `html`, once it's in `container`, drawn from its blob, whose URL is let go
11
26
  * when the HTML changes or the text goes.
12
27
  */
13
28
  const useRepoImages = (container: RefObject<HTMLDivElement | null>, html: string) => {
29
+ const clients = useClients();
30
+
14
31
  useEffect(() => {
15
32
  const images = [...(container.current?.querySelectorAll('img') ?? [])];
16
33
  const stop = new AbortController();
@@ -20,7 +37,7 @@ const useRepoImages = (container: RefObject<HTMLDivElement | null>, html: string
20
37
  const named = repoImageOf(image);
21
38
  if (named === undefined) continue;
22
39
 
23
- void repoImageBlob(named, stop.signal)
40
+ void repoImageBlob(clients, named, stop.signal)
24
41
  .then(async (blob) => {
25
42
  if (blob === undefined || stop.signal.aborted) return;
26
43
  const { src, release } = await drawnImage(blob);
@@ -36,6 +53,36 @@ const useRepoImages = (container: RefObject<HTMLDivElement | null>, html: string
36
53
 
37
54
  for (const release of drawn) release();
38
55
  };
56
+ }, [clients, container, html]);
57
+ };
58
+
59
+ /**
60
+ * Each remote image in `html`, once it's in `container`, loaded through the image proxy (Q860):
61
+ * signed for the text where it's kept, or for the viewer's own unsaved text, in one call with the
62
+ * page's other texts.
63
+ */
64
+ const useRemoteImages = (
65
+ container: RefObject<HTMLDivElement | null>,
66
+ html: string,
67
+ text: string,
68
+ from: TextAddress | undefined,
69
+ ) => {
70
+ useEffect(() => {
71
+ const drawn = container.current;
72
+
73
+ if (drawn === null || drawn.querySelector('[data-remote], [data-remote-srcset]') === null) {
74
+ return;
75
+ }
76
+
77
+ let stopped = false;
78
+ void signedImages(from === undefined ? { preview: text } : { address: from }).then((answer) => {
79
+ if (!stopped) drawRemoteImages(drawn, answer);
80
+ });
81
+
82
+ return () => {
83
+ stopped = true;
84
+ };
85
+ // The text and its address change only with `html`, which a new render brings.
39
86
  }, [container, html]);
40
87
  };
41
88
 
@@ -59,21 +106,59 @@ const useFragment = (container: RefObject<HTMLDivElement | null>) => {
59
106
  }, [container]);
60
107
  };
61
108
 
109
+ /** The budget the texts of the page being drawn share, if one is being drawn. */
110
+ const PageHtml = createContext<PageBudget | undefined>(undefined);
111
+
112
+ /**
113
+ * One budget for every text `page` draws (#1098), as the server renders it and the browser first
114
+ * draws it, closed once the page is drawn, and a new one for the next page. A jump to a fragment,
115
+ * such as a heading's or a footnote's, stays on the page.
116
+ */
117
+ export const PageHtmlBudget = ({ page, children }: { page: string; children: ReactNode }) => {
118
+ // A new page, by its address less its fragment, starts a budget of its own.
119
+ const address = page.split('#', 1)[0];
120
+ const budget = useMemo(() => pageBudget(), [address]);
121
+ useEffect(() => budget.close(), [budget]);
122
+
123
+ return <PageHtml value={budget}>{children}</PageHtml>;
124
+ };
125
+
62
126
  /**
63
127
  * Markdown as GitHub shows it in `context`, one renderer for previews and saved text: sanitized
64
128
  * HTML, with references linked once the drop-in says they exist, and until then the same text
65
- * unlinked, which the server's page and the browser's first render share.
129
+ * unlinked, which the server's page and the browser's first render share. On a page being drawn,
130
+ * it takes its share of the page's budget, and a text past what's left shows as written.
66
131
  */
67
- export const Markdown = ({ text, context }: { text: string; context: MarkdownContext }) => {
68
- const query = useQuery(markdownQuery(text, context));
132
+ export const Markdown = ({
133
+ text,
134
+ context,
135
+ from,
136
+ }: {
137
+ text: string;
138
+ context: MarkdownContext;
139
+ /** Where the text is kept, which the image proxy signs its images for: none for a preview. */
140
+ from?: TextAddress | undefined;
141
+ }) => {
142
+ const budget = useContext(PageHtml);
143
+ // Each text on a page is charged, two the same too, by an id the server and the browser share.
144
+ const drawnAt = useId();
145
+ const clients = useClients();
146
+ const query = useQuery(markdownQuery(clients, text, context));
69
147
  const linked = query.data;
70
- const unlinked = useMemo(
71
- () => (linked === undefined ? renderMarkdown(text, context, nothingFound) : undefined),
72
- [linked, text, context],
73
- );
74
- const html = linked ?? unlinked ?? '';
148
+ const html = useMemo(() => {
149
+ const draw = (most: number) =>
150
+ linked !== undefined && linked.length <= most
151
+ ? linked
152
+ : renderMarkdown(text, context, nothingFound, most);
153
+ if (budget === undefined) return draw(htmlMost);
154
+
155
+ const taken = budget.take(`${drawnAt}\n${JSON.stringify(context)}\n${text}`, draw);
156
+
157
+ return linked === undefined || taken.html === linked ? taken.html : draw(taken.most);
158
+ }, [budget, drawnAt, linked, text, context]);
75
159
  const container = useRef<HTMLDivElement>(null);
76
160
  useRepoImages(container, html);
161
+ useRemoteImages(container, html, text, from);
77
162
  useFragment(container);
78
163
 
79
164
  return (
@@ -12,6 +12,7 @@ import {
12
12
  } from 'lucide-react';
13
13
  import type { ReactNode } from 'react';
14
14
 
15
+ import { useClients } from '../clients/clients.ts';
15
16
  import { profileAt, type Profile } from '../hooks/profiles.ts';
16
17
  import { HoverCard, HoverCardContent, HoverCardTrigger } from './ui/hover-card.tsx';
17
18
  import { Skeleton } from './ui/skeleton.tsx';
@@ -144,7 +145,8 @@ function ProfileShown({ profile }: { readonly profile: Profile }) {
144
145
  * and kept for the session, a skeleton while it reads, or a line saying it couldn't load.
145
146
  */
146
147
  function ProfileCard({ login, account }: { readonly login: string; readonly account: Account }) {
147
- const profile = useQuery(profileAt(login, account));
148
+ const clients = useClients();
149
+ const profile = useQuery(profileAt(clients, login, account));
148
150
  if (profile.isError) return <p className="text-muted-foreground">Couldn't load this profile</p>;
149
151
 
150
152
  if (profile.data === undefined) return <ProfileSkeleton account={account} />;
@@ -1,6 +1,7 @@
1
1
  import { useQueryClient } from '@tanstack/react-query';
2
2
  import { type ReactNode, useCallback, useState } from 'react';
3
3
 
4
+ import { useClients } from '../../clients/clients.ts';
4
5
  import { languagesOf, repoList, type Owner, type RepoFilter } from '../../hooks/repos.ts';
5
6
  import { OwnerCard } from '../owner-card.tsx';
6
7
  import { UserAvatar, type Account } from '../user-avatar.tsx';
@@ -57,6 +58,7 @@ export function YourRepos({
57
58
  readonly filter: RepoFilter;
58
59
  readonly onFilter: (filter: RepoFilter) => void;
59
60
  }) {
61
+ const clients = useClients();
60
62
  const queryClient = useQueryClient();
61
63
  const owners: readonly Owner[] = [
62
64
  { kind: 'viewer', login: viewer },
@@ -70,7 +72,7 @@ export function YourRepos({
70
72
  owner.login,
71
73
  languagesOf(
72
74
  queryClient
73
- .getQueryData(repoList(owner, filter).queryKey)
75
+ .getQueryData(repoList(clients, owner, filter).queryKey)
74
76
  ?.pages.flatMap((page) => page.repos) ?? [],
75
77
  ),
76
78
  ]),
@@ -1,9 +1,8 @@
1
- import { useInfiniteQuery } from '@tanstack/react-query';
2
1
  import { Link, useLocation } from '@tanstack/react-router';
3
2
  import { CheckIcon, ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
4
3
  import { useEffect, useRef, useState } from 'react';
5
4
 
6
- import { maxFiltered, type Owner, repoList } from '../../hooks/repos.ts';
5
+ import { type Owner, useRepoNames } from '../../hooks/repos.ts';
7
6
  import { RepoIcon } from '../repos/repo-icon.tsx';
8
7
  import { Alert, AlertDescription } from '../ui/alert.tsx';
9
8
  import {
@@ -20,7 +19,6 @@ import { type Account, UserAvatar } from '../user-avatar.tsx';
20
19
  import { MenuCreateRow } from './create-row.tsx';
21
20
  import { useSubmenuChevron } from './submenu-chevron.ts';
22
21
 
23
- /** The owner's repositories in the list page's own order, so its read is the submenu's too. */
24
22
  /** The switcher's lists, each owner's every repo, newest updated first: the palette reads them too. */
25
23
  export const switcherList = { search: '', type: 'all', language: '', sort: 'updated' } as const;
26
24
 
@@ -99,12 +97,13 @@ export function OwnerRepos({
99
97
  const [open, setOpen] = useState(false);
100
98
  const [typed, setTyped] = useState('');
101
99
  const here = useLocation({ select: (location) => location.href });
102
- const repos = useInfiniteQuery({ ...repoList(owner, switcherList), enabled: open || eager });
103
- const names = repos.data?.pages.flatMap((page) => page.repos.map((repo) => repo.name)) ?? [];
104
100
  // A search, or the page's repo past the first page, reads on until it's found.
105
- const seeking = typed.trim() !== '' || (current !== undefined && !names.includes(current));
106
- const reading = seeking && repos.hasNextPage && names.length < maxFiltered && !repos.isError;
107
- const { fetchNextPage, isFetchingNextPage } = repos;
101
+ const { repos, names, reading } = useRepoNames(
102
+ owner,
103
+ switcherList,
104
+ open || eager,
105
+ (loaded) => typed.trim() !== '' || (current !== undefined && !loaded.includes(current)),
106
+ );
108
107
  const checked = useRef<HTMLDivElement>(null);
109
108
  const search = useRef<HTMLInputElement>(null);
110
109
  const popup = useRef<HTMLDivElement>(null);
@@ -118,10 +117,6 @@ export function OwnerRepos({
118
117
  // Drawn here rather than by the menu's own empty state, which a phone's fixed rows would hide.
119
118
  const matched = names.filter((name) => keeps(owner)(name, typed));
120
119
 
121
- useEffect(() => {
122
- if (reading && !isFetchingNextPage) void fetchNextPage();
123
- }, [reading, isFetchingNextPage, fetchNextPage, names.length]);
124
-
125
120
  // The page's repo scrolls into view once its row is drawn.
126
121
  useEffect(() => {
127
122
  if (open && found) checked.current?.scrollIntoView({ block: 'nearest' });