ref0-git 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/apps/github/.dev.vars.example +2 -1
- package/app/apps/github/generated/git-rest.ts +191 -25
- package/app/apps/github/generated/routeTree.gen.ts +21 -0
- package/app/apps/github/package.json +1 -1
- package/app/apps/github/src/branches/branch-list.tsx +8 -4
- package/app/apps/github/src/branches/branches.ts +10 -5
- package/app/apps/github/src/camo/addresses.ts +120 -0
- package/app/apps/github/src/camo/client.ts +125 -0
- package/app/apps/github/src/camo/fetch.ts +201 -0
- package/app/apps/github/src/camo/lookup.ts +23 -0
- package/app/apps/github/src/camo/node.ts +50 -0
- package/app/apps/github/src/camo/proxy.ts +116 -0
- package/app/apps/github/src/camo/sign-images.ts +307 -0
- package/app/apps/github/src/camo/signing.ts +80 -0
- package/app/apps/github/src/clients/allowed.ts +111 -18
- package/app/apps/github/src/clients/clients.ts +76 -61
- package/app/apps/github/src/clients/transport.ts +13 -0
- package/app/apps/github/src/code/code-tree.tsx +3 -1
- package/app/apps/github/src/code/file-view.tsx +15 -6
- package/app/apps/github/src/code/files.ts +26 -19
- package/app/apps/github/src/code/go-to-file.tsx +2 -1
- package/app/apps/github/src/code/load.ts +41 -23
- package/app/apps/github/src/code/markdown-files.ts +13 -2
- package/app/apps/github/src/code/ref-pages.ts +14 -5
- package/app/apps/github/src/code/ref-switcher.tsx +4 -3
- package/app/apps/github/src/code/refs.ts +42 -8
- package/app/apps/github/src/code/repo-home.tsx +6 -2
- package/app/apps/github/src/code/repo.ts +12 -6
- package/app/apps/github/src/code/saved.ts +5 -3
- package/app/apps/github/src/code/trees.ts +11 -9
- package/app/apps/github/src/components/markdown/markdown.css +6 -0
- package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
- package/app/apps/github/src/components/owner-card.tsx +3 -1
- package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
- package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
- package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
- package/app/apps/github/src/components/signin/device-card.tsx +9 -2
- package/app/apps/github/src/components/user-avatar.tsx +2 -1
- package/app/apps/github/src/context/context.ts +13 -0
- package/app/apps/github/src/diffs/blobs.ts +37 -14
- package/app/apps/github/src/diffs/diff-job.ts +53 -0
- package/app/apps/github/src/diffs/diff-worker.ts +6 -0
- package/app/apps/github/src/diffs/diffing.ts +136 -0
- package/app/apps/github/src/diffs/files.ts +4 -3
- package/app/apps/github/src/diffs/hunks.tsx +101 -53
- package/app/apps/github/src/diffs/patch.ts +20 -11
- package/app/apps/github/src/history/commit-diff.ts +10 -5
- package/app/apps/github/src/history/commit-list.tsx +3 -1
- package/app/apps/github/src/history/commit-page.tsx +4 -2
- package/app/apps/github/src/history/history.ts +12 -10
- package/app/apps/github/src/hooks/allowed.ts +9 -9
- package/app/apps/github/src/hooks/avatars.ts +3 -3
- package/app/apps/github/src/hooks/open-counts.ts +5 -4
- package/app/apps/github/src/hooks/profiles.ts +26 -12
- package/app/apps/github/src/hooks/repos.ts +78 -25
- package/app/apps/github/src/inbox/count.ts +30 -29
- package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
- package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
- package/app/apps/github/src/inbox/marks.ts +26 -15
- package/app/apps/github/src/inbox/release-tags.ts +7 -6
- package/app/apps/github/src/inbox/subjects.ts +5 -4
- package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
- package/app/apps/github/src/inbox/subscriptions.ts +95 -35
- package/app/apps/github/src/inbox/threads.ts +6 -6
- package/app/apps/github/src/issues/changes.ts +40 -16
- package/app/apps/github/src/issues/counts.ts +8 -5
- package/app/apps/github/src/issues/issue-list.tsx +20 -6
- package/app/apps/github/src/issues/issue-page.tsx +30 -14
- package/app/apps/github/src/issues/issues.ts +195 -46
- package/app/apps/github/src/issues/label-dialog.tsx +8 -11
- package/app/apps/github/src/issues/labels-page.tsx +35 -3
- package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
- package/app/apps/github/src/issues/milestones-page.tsx +269 -0
- package/app/apps/github/src/issues/new-issue.tsx +3 -1
- package/app/apps/github/src/issues/sidebar.tsx +8 -6
- package/app/apps/github/src/markdown/README.md +22 -17
- package/app/apps/github/src/markdown/context.ts +83 -10
- package/app/apps/github/src/markdown/images.ts +3 -2
- package/app/apps/github/src/markdown/lookup.ts +9 -8
- package/app/apps/github/src/markdown/page-budget.ts +50 -0
- package/app/apps/github/src/markdown/patches.ts +74 -32
- package/app/apps/github/src/markdown/query.ts +7 -2
- package/app/apps/github/src/markdown/remote.ts +106 -0
- package/app/apps/github/src/markdown/render.ts +101 -24
- package/app/apps/github/src/markdown/texts.ts +43 -0
- package/app/apps/github/src/markdown/words-module.d.ts +5 -0
- package/app/apps/github/src/markdown/words-plugin.ts +135 -0
- package/app/apps/github/src/names/repos.ts +1 -1
- package/app/apps/github/src/palette/palette.tsx +7 -4
- package/app/apps/github/src/palette/rows.tsx +54 -33
- package/app/apps/github/src/palette/server.ts +5 -5
- package/app/apps/github/src/palette/targets.ts +1 -0
- package/app/apps/github/src/policy.ts +131 -61
- package/app/apps/github/src/private-repos.ts +2 -2
- package/app/apps/github/src/pulls/compare-page.tsx +6 -3
- package/app/apps/github/src/pulls/files-tab.tsx +480 -214
- package/app/apps/github/src/pulls/held-summary.ts +178 -0
- package/app/apps/github/src/pulls/live.ts +6 -4
- package/app/apps/github/src/pulls/merge-box.tsx +17 -10
- package/app/apps/github/src/pulls/pull-list.tsx +6 -3
- package/app/apps/github/src/pulls/pull-page.tsx +19 -10
- package/app/apps/github/src/pulls/pull.ts +68 -40
- package/app/apps/github/src/pulls/pulls.ts +39 -22
- package/app/apps/github/src/pulls/review-drafts.ts +131 -0
- package/app/apps/github/src/pulls/review.ts +374 -99
- package/app/apps/github/src/pulls/threads.tsx +152 -0
- package/app/apps/github/src/queue/queue-page.tsx +15 -8
- package/app/apps/github/src/queue/queue.ts +35 -20
- package/app/apps/github/src/releases/latest-release.tsx +3 -1
- package/app/apps/github/src/releases/overview.tsx +4 -2
- package/app/apps/github/src/releases/release-form.tsx +8 -5
- package/app/apps/github/src/releases/release-list.tsx +8 -5
- package/app/apps/github/src/releases/release-view.tsx +1 -0
- package/app/apps/github/src/releases/releases.ts +33 -23
- package/app/apps/github/src/releases/tag-list.tsx +3 -1
- package/app/apps/github/src/router.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
- package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
- package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
- package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
- package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
- package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
- package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
- package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
- package/app/apps/github/src/routes/-nav.tsx +10 -2
- package/app/apps/github/src/routes/-root-testing.ts +29 -6
- package/app/apps/github/src/routes/__root.tsx +9 -4
- package/app/apps/github/src/routes/index.tsx +3 -1
- package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
- package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
- package/app/apps/github/src/seed/acme.ts +1 -1
- package/app/apps/github/src/seed/seed.ts +199 -110
- package/app/apps/github/src/server.ts +24 -15
- package/app/apps/github/src/settings/account-avatar.tsx +4 -1
- package/app/apps/github/src/settings/general-settings.tsx +3 -1
- package/app/apps/github/src/settings/general.ts +4 -4
- package/app/apps/github/src/settings/hook-form.tsx +3 -1
- package/app/apps/github/src/settings/hook-list.tsx +5 -2
- package/app/apps/github/src/settings/hooks.ts +7 -7
- package/app/apps/github/src/settings/org-settings.tsx +3 -1
- package/app/apps/github/src/settings/orgs.ts +21 -11
- package/app/apps/github/src/settings/settings-layout.tsx +3 -1
- package/app/apps/github/src/signin/approval.ts +4 -3
- package/app/apps/github/src/signin/auth.ts +9 -2
- package/app/apps/github/src/signin/device-code.ts +8 -3
- package/app/apps/github/src/signin/device-prompt.ts +28 -3
- package/app/apps/github/src/signin/revoke.ts +36 -0
- package/app/apps/github/tsconfig.json +4 -1
- package/app/apps/github/vite.config.ts +8 -0
- package/app/pnpm-workspace.yaml +9 -5
- package/app/tsconfig.base.json +1 -0
- package/dist/cli/child.mjs +1 -1
- package/dist/cli/credentials.mjs +4 -4
- package/dist/cli/documents.mjs +32 -22
- package/dist/cli/events.mjs +1 -1
- package/dist/cli/failure.mjs +20 -7
- package/dist/cli/folders.mjs +2 -2
- package/dist/cli/git-remote-ref0.mjs +47 -22
- package/dist/cli/git.mjs +1 -1
- package/dist/cli/helpers.mjs +2 -2
- package/dist/cli/hosts.mjs +3 -3
- package/dist/cli/output.mjs +2 -2
- package/dist/cli/prompt.mjs +1 -1
- package/dist/cli/queue.mjs +7 -7
- package/dist/cli/ref0-git.mjs +2 -2
- package/dist/cli/repos.mjs +35 -18
- package/dist/cli/resources.mjs +5 -5
- package/dist/cli/retry-after.mjs +8 -0
- package/dist/cli/setup.mjs +172 -66
- package/dist/cli/sign-in.mjs +65 -23
- package/dist/cli/sign-ins.mjs +4 -4
- package/dist/cli/sqlite.mjs +2 -2
- package/dist/cli/tokens.mjs +3 -3
- package/dist/cli/vendor.mjs +1 -1
- package/dist/init/app.mjs +18 -20
- package/dist/init/choices.mjs +1 -1
- package/dist/init/cloudflare.mjs +15 -19
- package/dist/init/create.mjs +3 -2
- package/dist/init/detect.mjs +4 -4
- package/dist/init/files.mjs +120 -13
- package/dist/init/frameworks.mjs +16 -0
- package/dist/init/git-module.mjs +22 -7
- package/dist/init/jsonc.mjs +9 -7
- package/dist/init/metadata.mjs +9 -3
- package/dist/init/mounts.mjs +13 -10
- package/dist/init/next.mjs +2 -2
- package/dist/init/node-app.mjs +3 -3
- package/dist/init/node.mjs +42 -45
- package/dist/init/nuxt.mjs +153 -27
- package/dist/init/stores.mjs +14 -9
- package/dist/init/sveltekit.mjs +4 -2
- package/dist/init/template.mjs +9 -6
- package/dist/init/templates.mjs +63 -47
- package/dist/init/vercel.mjs +37 -37
- package/dist/init/versions.mjs +3 -3
- 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 {
|
|
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
|
-
*
|
|
14
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
20
|
-
*
|
|
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
|
|
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
|
-
*
|
|
44
|
-
*
|
|
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
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
80
|
-
export const githubQueries = createQueryHooks(github);
|
|
94
|
+
export type Clients = ReturnType<typeof createClients>;
|
|
81
95
|
|
|
82
|
-
|
|
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
|
-
|
|
89
|
-
|
|
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
|
|
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
|
|
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 {
|
|
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', {
|
|
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
|
|
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 (
|
|
27
|
-
|
|
28
|
-
|
|
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 (
|
|
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
|
|
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>[
|
|
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)
|
|
67
|
+
if (text !== undefined)
|
|
68
|
+
await readAhead(client, markdownQuery(clients, text, contextOf(at, file.path)));
|
|
58
69
|
};
|