ref0-git 0.12.0 → 0.20.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/generated/git-rest.ts +320 -4
- package/app/apps/github/generated/routeTree.gen.ts +42 -21
- package/app/apps/github/migrations/postgres/0001_auth.sql +8 -1
- package/app/apps/github/migrations/sql/0005_repo_grants.sql +10 -0
- package/app/apps/github/src/clients/allowed.ts +9 -4
- package/app/apps/github/src/clients/host-calls.ts +59 -34
- package/app/apps/github/src/components/repos/your-repos.tsx +57 -11
- package/app/apps/github/src/components/states/states.tsx +1 -19
- package/app/apps/github/src/components/view-tabs.tsx +6 -2
- package/app/apps/github/src/context/context.ts +51 -5
- package/app/apps/github/src/context/host.ts +72 -36
- package/app/apps/github/src/context/repo-grants.ts +35 -0
- package/app/apps/github/src/hooks/repos.ts +14 -3
- package/app/apps/github/src/issues/issue-list.tsx +11 -3
- package/app/apps/github/src/issues/issues.ts +11 -8
- package/app/apps/github/src/lists/across-list.tsx +358 -0
- package/app/apps/github/src/lists/across.ts +239 -0
- package/app/apps/github/src/names/owners.ts +3 -1
- package/app/apps/github/src/palette/targets.ts +3 -2
- package/app/apps/github/src/policy.ts +493 -102
- package/app/apps/github/src/private-repos.ts +24 -24
- package/app/apps/github/src/pulls/pulls.ts +2 -1
- package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +1 -1
- package/app/apps/github/src/routes/-nav.tsx +40 -12
- package/app/apps/github/src/routes/index.tsx +2 -1
- package/app/apps/github/src/routes/issues.tsx +15 -0
- package/app/apps/github/src/routes/orgs/$owner/-org-list.ts +31 -0
- package/app/apps/github/src/routes/orgs/$owner/issues.tsx +10 -3
- package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +10 -3
- package/app/apps/github/src/routes/pulls.tsx +15 -0
- package/app/apps/github/src/seed/seed.ts +104 -52
- package/app/apps/github/src/server.ts +17 -7
- package/app/apps/github/src/settings/access-page.tsx +308 -0
- package/app/apps/github/src/settings/access.ts +156 -0
- package/app/apps/github/src/settings/settings-layout.tsx +0 -16
- package/app/apps/github/src/signin/approval.ts +24 -16
- package/app/apps/github/src/signin/auth.ts +29 -19
- package/app/apps/github/src/signin/orgs.ts +57 -14
- package/app/apps/github/src/signin/repo-grants.ts +141 -0
- package/app/apps/github/src/signin/revoke.ts +9 -17
- package/app/apps/github/src/signin/unborn.ts +33 -20
- package/app/pnpm-workspace.yaml +2 -2
- package/dist/cli/child.mjs +73 -3
- package/dist/cli/commands.mjs +2 -0
- package/dist/cli/documents.mjs +42 -2
- package/dist/cli/keys.mjs +431 -0
- package/dist/cli/main.mjs +148 -0
- package/dist/cli/prompt.mjs +40 -1
- package/dist/cli/ref0-git.mjs +4 -141
- package/dist/cli/setup.mjs +118 -16
- package/dist/cli/sign-in.mjs +1 -1
- package/dist/cli/tools-node.mjs +20 -0
- package/dist/cli/tools.mjs +12 -0
- package/dist/init/app.mjs +5 -2
- package/dist/init/cloudflare.mjs +8 -3
- package/dist/init/git-module.mjs +13 -8
- package/dist/init/metadata.mjs +1 -1
- package/dist/init/node.mjs +1 -1
- package/dist/init/template.mjs +1 -0
- package/dist/init/templates.mjs +24 -19
- package/dist/init/versions.mjs +1 -1
- package/package.json +5 -5
- package/app/apps/github/src/routes/orgs/$owner/releases.tsx +0 -8
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
-- starter's options in src/signin/auth.ts, on Postgres: people by their login (username), their
|
|
3
3
|
-- password accounts and passkeys, sessions with each one's sealed Git token, orgs and their
|
|
4
4
|
-- members, `owner_names`' claims on the logins people and orgs share, `avatar`'s pictures of
|
|
5
|
-
-- people, orgs and repos, and the rate limit's
|
|
5
|
+
-- people, orgs and repos, `repo_grant`'s grants of a repo to a person (#1998), and the rate limit's
|
|
6
|
+
-- counts.
|
|
6
7
|
-- Written by Better Auth's getMigrations from those options on a database with no tables, as
|
|
7
8
|
-- credentials.test.ts checks, with `collate "C"` on the logins, `username` and `slug`, so a
|
|
8
9
|
-- search's range of their indexes is their prefix's; apply it once, before the app's first
|
|
@@ -27,6 +28,8 @@ create table "owner_names" ("id" text not null primary key, "claim" text not nul
|
|
|
27
28
|
|
|
28
29
|
create table "avatar" ("id" text not null primary key, "kind" text not null, "type" text not null, "bytes" text not null, "size" integer not null, "hash" text not null, "updatedAt" timestamptz not null);
|
|
29
30
|
|
|
31
|
+
create table "repo_grant" ("id" text not null primary key, "repo" text not null, "userId" text not null references "user" ("id") on delete cascade, "role" text not null, "createdAt" timestamptz not null);
|
|
32
|
+
|
|
30
33
|
create table "rateLimit" ("id" text not null primary key, "key" text not null unique, "count" integer not null, "lastRequest" bigint not null);
|
|
31
34
|
|
|
32
35
|
create index "session_userId_idx" on "session" ("userId");
|
|
@@ -44,3 +47,7 @@ create index "member_userId_idx" on "member" ("userId");
|
|
|
44
47
|
create index "invitation_organizationId_idx" on "invitation" ("organizationId");
|
|
45
48
|
|
|
46
49
|
create index "invitation_email_idx" on "invitation" ("email");
|
|
50
|
+
|
|
51
|
+
create index "repo_grant_repo_idx" on "repo_grant" ("repo");
|
|
52
|
+
|
|
53
|
+
create index "repo_grant_userId_idx" on "repo_grant" ("userId");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- A repo's grants to people (#1998), added to 0004's tables by the repo grants plugin in
|
|
2
|
+
-- src/signin/auth.ts: one row a person and a repo, under the repo's internal ID and the person's row
|
|
3
|
+
-- ID, `<repo>:<userId>`, with the role and when it was first made. A person's delete takes their
|
|
4
|
+
-- grants, and Git's `repo.deleted` a repo's. Written by Better Auth's getMigrations from those
|
|
5
|
+
-- options over 0004. Apply it with `wrangler d1 migrations apply AUTH_DB`, as 0001.
|
|
6
|
+
create table "repo_grant" ("id" text not null primary key, "repo" text not null, "userId" text not null references "user" ("id") on delete cascade, "role" text not null, "createdAt" date not null);
|
|
7
|
+
|
|
8
|
+
create index "repo_grant_repo_idx" on "repo_grant" ("repo");
|
|
9
|
+
|
|
10
|
+
create index "repo_grant_userId_idx" on "repo_grant" ("userId");
|
|
@@ -48,6 +48,8 @@ const gitHubOperations = [
|
|
|
48
48
|
'hook.read',
|
|
49
49
|
'hook.create',
|
|
50
50
|
'hook.delete',
|
|
51
|
+
'collaborator.create',
|
|
52
|
+
'collaborator.delete',
|
|
51
53
|
] as const satisfies readonly GitHubOperationKind[];
|
|
52
54
|
|
|
53
55
|
type GitHubPageOperation = (typeof gitHubOperations)[number];
|
|
@@ -85,10 +87,11 @@ const issueAnswer = Schema.decodeUnknownSync(IssueAnswer);
|
|
|
85
87
|
|
|
86
88
|
/**
|
|
87
89
|
* What the drop-in decides each operation on: the issue, by its number, or the repo alone, as its
|
|
88
|
-
* routes ask. A new issue, label, milestone or pull request, an edited comment, label or
|
|
89
|
-
* deleted label or milestone, a release and a
|
|
90
|
-
*
|
|
91
|
-
* `pull.review
|
|
90
|
+
* routes ask. A new issue, label, milestone or pull request, an edited comment, label or
|
|
91
|
+
* milestone, a deleted label or milestone, a release, a hook and a collaborator are the repo's:
|
|
92
|
+
* giving one a role, first or changed, is `collaborator.create`. Asking for reviews is
|
|
93
|
+
* `pull.update`, merging or queueing a pull request is `pull.merge`, and a review, a comment on its
|
|
94
|
+
* lines or discarding a pending review is `pull.review`.
|
|
92
95
|
*/
|
|
93
96
|
const decidedOn: Readonly<Record<GitHubPageOperation, 'issue' | 'repo'>> = {
|
|
94
97
|
'issue.create': 'repo',
|
|
@@ -111,6 +114,8 @@ const decidedOn: Readonly<Record<GitHubPageOperation, 'issue' | 'repo'>> = {
|
|
|
111
114
|
'hook.read': 'repo',
|
|
112
115
|
'hook.create': 'repo',
|
|
113
116
|
'hook.delete': 'repo',
|
|
117
|
+
'collaborator.create': 'repo',
|
|
118
|
+
'collaborator.delete': 'repo',
|
|
114
119
|
};
|
|
115
120
|
|
|
116
121
|
/** The repo's `permissions` for its caller, as the drop-in answers them. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createServerFn } from '@tanstack/react-start';
|
|
2
2
|
import { getRequest } from '@tanstack/react-start/server';
|
|
3
3
|
import * as Effect from 'effect/Effect';
|
|
4
|
+
import * as Result from 'effect/Result';
|
|
4
5
|
import * as Schema from 'effect/Schema';
|
|
5
6
|
|
|
6
7
|
import type { TokenRecord as GitTokenRecord, TokenTarget } from '@ref0/git';
|
|
@@ -9,7 +10,6 @@ import type { AppContext, HostGit } from '../context/context.ts';
|
|
|
9
10
|
import { admin } from '../names/owners.ts';
|
|
10
11
|
import { hostSessionFor, hostSessionHeader } from '../signin/host-session.ts';
|
|
11
12
|
import { orgTokenView } from '../signin/orgs.ts';
|
|
12
|
-
import { atMost } from './at-most.ts';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The writes no Git token reaches, which the app makes as its signed-in person under the host's
|
|
@@ -180,27 +180,59 @@ const segment = encodeURIComponent;
|
|
|
180
180
|
const repoPath = (owner: string, repo: string) =>
|
|
181
181
|
`/api/v3/repos/${segment(owner)}/${segment(repo)}`;
|
|
182
182
|
|
|
183
|
-
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
/**
|
|
184
|
+
* A token place's list as host code reads it, `rows` at most, and whether more followed: `undefined`
|
|
185
|
+
* for a place Git doesn't hold, such as a repo deleted since its name was read.
|
|
186
|
+
*/
|
|
187
|
+
const listed = Effect.fnUntraced(
|
|
188
|
+
function* (tokens: TokenLists, target: TokenTarget, rows: number) {
|
|
189
|
+
const items: GitTokenRecord[] = [];
|
|
190
|
+
let after: string | undefined;
|
|
191
|
+
|
|
192
|
+
while (items.length < rows) {
|
|
193
|
+
const limit = Math.min(tokensEach, rows - items.length);
|
|
194
|
+
const page = yield* tokens.list(target, {
|
|
195
|
+
state: 'all',
|
|
196
|
+
page: after === undefined ? { limit } : { limit, after },
|
|
197
|
+
});
|
|
187
198
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const page = await tokens.list(target, {
|
|
191
|
-
state: 'all',
|
|
192
|
-
page: after === undefined ? { limit } : { limit, after },
|
|
193
|
-
});
|
|
194
|
-
if (page.kind !== 'success') return page;
|
|
199
|
+
items.push(...page.items);
|
|
200
|
+
after = page.next;
|
|
195
201
|
|
|
196
|
-
|
|
197
|
-
|
|
202
|
+
if (after === undefined) return { items, more: false };
|
|
203
|
+
}
|
|
198
204
|
|
|
199
|
-
|
|
200
|
-
}
|
|
205
|
+
return { items, more: true };
|
|
206
|
+
},
|
|
207
|
+
Effect.catchIf(
|
|
208
|
+
(error) => error.code === 'NOT_FOUND',
|
|
209
|
+
() => Effect.succeed(undefined),
|
|
210
|
+
),
|
|
211
|
+
);
|
|
201
212
|
|
|
202
|
-
|
|
203
|
-
|
|
213
|
+
/**
|
|
214
|
+
* The lists of `targets`, the place's own and each of its repos', `listsAtOnce` at a time, and
|
|
215
|
+
* whether Git held repos past `repos`' page. It fails when Git couldn't answer one of them.
|
|
216
|
+
*/
|
|
217
|
+
const tokenLists = (
|
|
218
|
+
git: HostGit,
|
|
219
|
+
tokens: TokenLists,
|
|
220
|
+
prefix: string,
|
|
221
|
+
repo: string | undefined,
|
|
222
|
+
rows: number,
|
|
223
|
+
) =>
|
|
224
|
+
Effect.gen(function* () {
|
|
225
|
+
const repos =
|
|
226
|
+
repo === undefined
|
|
227
|
+
? yield* git.repos.list({ actor: admin, prefix, page: { limit: tokenRepos } })
|
|
228
|
+
: { items: [`${prefix}${repo}`] };
|
|
229
|
+
const targets: TokenTarget[] = [{ prefix }, ...repos.items];
|
|
230
|
+
const lists = yield* Effect.forEach(targets, (target) => listed(tokens, target, rows), {
|
|
231
|
+
concurrency: listsAtOnce,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return { lists, more: 'next' in repos && repos.next !== undefined };
|
|
235
|
+
});
|
|
204
236
|
|
|
205
237
|
/** Git couldn't answer one of a list's reads, so the list isn't whole: 503, never a short list. */
|
|
206
238
|
const listUnavailable = () => refusal(503, "Git couldn't list the tokens: try again");
|
|
@@ -227,26 +259,19 @@ const tokensOf = async (
|
|
|
227
259
|
const tokens = context.git.tokens;
|
|
228
260
|
if (view === undefined || tokens === undefined) return missing;
|
|
229
261
|
|
|
230
|
-
const prefix = `${place.owner}/`;
|
|
231
|
-
const repos =
|
|
232
|
-
place.repo === undefined
|
|
233
|
-
? await context.git.repos.list({ actor: admin, prefix, page: { limit: tokenRepos } })
|
|
234
|
-
: { kind: 'success' as const, value: { items: [`${prefix}${place.repo}`] } };
|
|
235
|
-
if (repos.kind !== 'success') return listUnavailable();
|
|
236
|
-
|
|
237
262
|
const rows = view === 'member' ? memberRowsEach : tokensEach;
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (
|
|
263
|
+
const read = await Effect.runPromise(
|
|
264
|
+
Effect.result(tokenLists(context.git, tokens, `${place.owner}/`, place.repo, rows)),
|
|
265
|
+
);
|
|
266
|
+
if (Result.isFailure(read)) return listUnavailable();
|
|
242
267
|
|
|
243
268
|
// A repo deleted since its name was read holds no tokens, but the one asked for is missing.
|
|
244
|
-
|
|
269
|
+
const { lists } = read.success;
|
|
270
|
+
if (place.repo !== undefined && lists[1] === undefined) return missing;
|
|
245
271
|
|
|
246
|
-
const
|
|
247
|
-
const every =
|
|
248
|
-
const more =
|
|
249
|
-
('next' in repos.value && repos.value.next !== undefined) || read.some((list) => list.more);
|
|
272
|
+
const found = lists.flatMap((list) => (list === undefined ? [] : [list]));
|
|
273
|
+
const every = found.flatMap((list) => list.items).map((token) => tokenRecord(token));
|
|
274
|
+
const more = read.success.more || found.some((list) => list.more);
|
|
250
275
|
|
|
251
276
|
const all = view === 'all';
|
|
252
277
|
const answer: TokenListing = {
|
|
@@ -2,14 +2,54 @@ import { useQueryClient } from '@tanstack/react-query';
|
|
|
2
2
|
import { type ReactNode, useCallback, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import { useClients } from '../../clients/clients.ts';
|
|
5
|
-
import { languagesOf, repoList, type Owner, type RepoFilter } from '../../hooks/repos.ts';
|
|
5
|
+
import { languagesOf, repoList, useRepos, type Owner, type RepoFilter } from '../../hooks/repos.ts';
|
|
6
6
|
import { OwnerCard } from '../owner-card.tsx';
|
|
7
7
|
import { UserAvatar, type Account } from '../user-avatar.tsx';
|
|
8
8
|
import { RepoList, RepoToolbar } from './repo-list.tsx';
|
|
9
9
|
|
|
10
|
-
/** Each list's languages, by its owner
|
|
10
|
+
/** Each list's languages, by `keyOf` its owner, as each one heard them from its loaded rows. */
|
|
11
11
|
type Heard = Readonly<Record<string, readonly string[]>>;
|
|
12
12
|
|
|
13
|
+
/** A list's key among `/`'s: the viewer's own and the repos shared with them share a login. */
|
|
14
|
+
const keyOf = (owner: Owner) => `${owner.kind}:${owner.login}`;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The repos others shared with the viewer (#1998), under their own heading, after the orgs', each
|
|
18
|
+
* row named by its owner: none drawn when nothing is shared and no filter is asked.
|
|
19
|
+
*/
|
|
20
|
+
function SharedSection({
|
|
21
|
+
owner,
|
|
22
|
+
filter,
|
|
23
|
+
onFilter,
|
|
24
|
+
onLanguages,
|
|
25
|
+
}: {
|
|
26
|
+
readonly owner: Owner;
|
|
27
|
+
readonly filter: RepoFilter;
|
|
28
|
+
readonly onFilter: (filter: RepoFilter) => void;
|
|
29
|
+
readonly onLanguages: (languages: readonly string[]) => void;
|
|
30
|
+
}) {
|
|
31
|
+
const shared = useRepos(owner, filter);
|
|
32
|
+
const asked = filter.search.trim() !== '' || filter.type !== 'all' || filter.language !== '';
|
|
33
|
+
const none = shared.data?.pages.every((page) => page.repos.length === 0) === true;
|
|
34
|
+
if (none && !asked) return null;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<section aria-labelledby="owner-shared" className="flex flex-col gap-3 pt-4">
|
|
38
|
+
<h2 id="owner-shared" className="text-sm font-medium">
|
|
39
|
+
Shared with you
|
|
40
|
+
</h2>
|
|
41
|
+
<RepoList
|
|
42
|
+
owner={owner}
|
|
43
|
+
owns={false}
|
|
44
|
+
filter={filter}
|
|
45
|
+
onFilter={onFilter}
|
|
46
|
+
toolbar={false}
|
|
47
|
+
onLanguages={onLanguages}
|
|
48
|
+
/>
|
|
49
|
+
</section>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
13
53
|
/**
|
|
14
54
|
* One owner's section of `/`, under its heading: the owner's avatar, round for a person and square
|
|
15
55
|
* for an org, and its login, leading to its page. The viewer's own section and each org's share it,
|
|
@@ -44,8 +84,8 @@ function OwnerSection({
|
|
|
44
84
|
/**
|
|
45
85
|
* Every repository `viewer` can see: their own section first, then each of their `orgs`', each
|
|
46
86
|
* under its owner's heading, all under one toolbar, whose Language menu offers every list's
|
|
47
|
-
* languages. The orgs are the switcher's, so a person with
|
|
48
|
-
* on their orgs'.
|
|
87
|
+
* languages, then the repos others shared with them. The orgs are the switcher's, so a person with
|
|
88
|
+
* no repositories of their own still lands on their orgs'.
|
|
49
89
|
*/
|
|
50
90
|
export function YourRepos({
|
|
51
91
|
viewer,
|
|
@@ -60,16 +100,18 @@ export function YourRepos({
|
|
|
60
100
|
}) {
|
|
61
101
|
const clients = useClients();
|
|
62
102
|
const queryClient = useQueryClient();
|
|
103
|
+
const shared: Owner = { kind: 'shared', login: viewer };
|
|
63
104
|
const owners: readonly Owner[] = [
|
|
64
105
|
{ kind: 'viewer', login: viewer },
|
|
65
106
|
...orgs.map((org) => ({ kind: 'org' as const, login: org })),
|
|
107
|
+
shared,
|
|
66
108
|
];
|
|
67
109
|
// What `/`'s loader read, so the server draws the Language menu and the browser keeps it: each
|
|
68
110
|
// list's `onLanguages` comes only once it has drawn.
|
|
69
111
|
const [heard, setHeard] = useState<Heard>(() =>
|
|
70
112
|
Object.fromEntries(
|
|
71
113
|
owners.map((owner) => [
|
|
72
|
-
owner
|
|
114
|
+
keyOf(owner),
|
|
73
115
|
languagesOf(
|
|
74
116
|
queryClient
|
|
75
117
|
.getQueryData(repoList(clients, owner, filter).queryKey)
|
|
@@ -80,11 +122,9 @@ export function YourRepos({
|
|
|
80
122
|
);
|
|
81
123
|
|
|
82
124
|
const hear = useCallback(
|
|
83
|
-
(
|
|
125
|
+
(key: string) => (languages: readonly string[]) =>
|
|
84
126
|
setHeard((before) =>
|
|
85
|
-
before[
|
|
86
|
-
? before
|
|
87
|
-
: { ...before, [login]: languages },
|
|
127
|
+
before[key]?.join('\n') === languages.join('\n') ? before : { ...before, [key]: languages },
|
|
88
128
|
),
|
|
89
129
|
[],
|
|
90
130
|
);
|
|
@@ -106,7 +146,7 @@ export function YourRepos({
|
|
|
106
146
|
filter={filter}
|
|
107
147
|
onFilter={onFilter}
|
|
108
148
|
toolbar={false}
|
|
109
|
-
onLanguages={hear(viewer)}
|
|
149
|
+
onLanguages={hear(keyOf({ kind: 'viewer', login: viewer }))}
|
|
110
150
|
/>
|
|
111
151
|
</OwnerSection>
|
|
112
152
|
{orgs.map((org) => (
|
|
@@ -117,10 +157,16 @@ export function YourRepos({
|
|
|
117
157
|
filter={filter}
|
|
118
158
|
onFilter={onFilter}
|
|
119
159
|
toolbar={false}
|
|
120
|
-
onLanguages={hear(org)}
|
|
160
|
+
onLanguages={hear(keyOf({ kind: 'org', login: org }))}
|
|
121
161
|
/>
|
|
122
162
|
</OwnerSection>
|
|
123
163
|
))}
|
|
164
|
+
<SharedSection
|
|
165
|
+
owner={shared}
|
|
166
|
+
filter={filter}
|
|
167
|
+
onFilter={onFilter}
|
|
168
|
+
onLanguages={hear(keyOf(shared))}
|
|
169
|
+
/>
|
|
124
170
|
</>
|
|
125
171
|
);
|
|
126
172
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FolderSearchIcon,
|
|
1
|
+
import { FolderSearchIcon, LockIcon, LogInIcon } from 'lucide-react';
|
|
2
2
|
import { useEffect, useState, type ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
import { Alert, AlertDescription } from '../ui/alert.tsx';
|
|
@@ -85,24 +85,6 @@ export function LoadFailed({ message }: { readonly message: string }) {
|
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
/**
|
|
89
|
-
* An org's list across its repos, such as its issues, which waits on one read across them: the
|
|
90
|
-
* page never reads each repo's list in turn.
|
|
91
|
-
*/
|
|
92
|
-
export function AcrossRepos({ what }: { readonly what: string }) {
|
|
93
|
-
return (
|
|
94
|
-
<Empty className="border">
|
|
95
|
-
<EmptyHeader>
|
|
96
|
-
<EmptyMedia variant="icon">
|
|
97
|
-
<LayersIcon />
|
|
98
|
-
</EmptyMedia>
|
|
99
|
-
<EmptyTitle>Lists across repositories are coming</EmptyTitle>
|
|
100
|
-
<EmptyDescription>For now, pick a repository above to see its {what}.</EmptyDescription>
|
|
101
|
-
</EmptyHeader>
|
|
102
|
-
</Empty>
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
88
|
/** How long a load runs before its skeleton shows: a quicker one shows no skeleton at all. */
|
|
107
89
|
export const skeletonAfterMs = 200;
|
|
108
90
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
import { TabsList, TabsTrigger } from './ui/tabs.tsx';
|
|
4
4
|
|
|
@@ -8,6 +8,8 @@ export interface View {
|
|
|
8
8
|
readonly label: string;
|
|
9
9
|
/** The link to the view's own page, as a Markdown file's code is at `?plain=1`. */
|
|
10
10
|
readonly link?: ReactElement;
|
|
11
|
+
/** What follows its name, such as a list's count. */
|
|
12
|
+
readonly end?: ReactNode;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -26,14 +28,16 @@ export function ViewTabs({
|
|
|
26
28
|
}) {
|
|
27
29
|
return (
|
|
28
30
|
<TabsList aria-label={label}>
|
|
29
|
-
{views.map(({ value, label: name, link }) =>
|
|
31
|
+
{views.map(({ value, label: name, link, end }) =>
|
|
30
32
|
link === undefined ? (
|
|
31
33
|
<TabsTrigger key={value} value={value}>
|
|
32
34
|
{name}
|
|
35
|
+
{end}
|
|
33
36
|
</TabsTrigger>
|
|
34
37
|
) : (
|
|
35
38
|
<TabsTrigger key={value} value={value} nativeButton={false} render={link}>
|
|
36
39
|
{name}
|
|
40
|
+
{end}
|
|
37
41
|
</TabsTrigger>
|
|
38
42
|
),
|
|
39
43
|
)}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Caller, Policy,
|
|
2
|
-
import type { GitHubAuthorize } from '@ref0/github';
|
|
1
|
+
import type { Caller, InternalRepoId, Policy, Repos, Result, Tokens } from '@ref0/git';
|
|
2
|
+
import type { GitHubAuthorize, RepoRole } from '@ref0/github';
|
|
3
3
|
import type {} from '@tanstack/react-start';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -60,6 +60,49 @@ export interface Avatars {
|
|
|
60
60
|
readonly remove: (kind: AvatarKind, id: string) => Promise<void>;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/** A person's grant on a repo: its role, and when it was first made, by the app's clock. */
|
|
64
|
+
export interface Grant {
|
|
65
|
+
readonly role: RepoRole;
|
|
66
|
+
readonly createdAt: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A page of rows, in the order of one ID, and the ID to go on after when more follow. */
|
|
70
|
+
export interface GrantsPage<Item> {
|
|
71
|
+
readonly items: readonly Item[];
|
|
72
|
+
readonly next?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Where a page starts, past `after`, and how many rows it holds at most, up to a page's bound. */
|
|
76
|
+
export interface GrantsFrom {
|
|
77
|
+
readonly after?: string | undefined;
|
|
78
|
+
readonly limit?: number | undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A repo's grants to people (#1998), each under the repo's internal ID, which a rename keeps, and
|
|
83
|
+
* the person's row ID in Better Auth's tables.
|
|
84
|
+
*/
|
|
85
|
+
export interface Grants {
|
|
86
|
+
/** The person `userId`'s grant on the repo, or `undefined` when they have none. */
|
|
87
|
+
readonly get: (repo: InternalRepoId, userId: string) => Promise<Grant | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* Grants `role`, or changes a grant's role in place. `full` when the repo already holds
|
|
90
|
+
* `repoGrantsMost` grants and this would be another.
|
|
91
|
+
*/
|
|
92
|
+
readonly put: (repo: InternalRepoId, userId: string, role: RepoRole) => Promise<'put' | 'full'>;
|
|
93
|
+
/** Removes the person's grant on the repo, which succeeds when there's none. */
|
|
94
|
+
readonly remove: (repo: InternalRepoId, userId: string) => Promise<void>;
|
|
95
|
+
/** A page of the repo's grants, in person ID order. */
|
|
96
|
+
readonly list: (
|
|
97
|
+
repo: InternalRepoId,
|
|
98
|
+
from: GrantsFrom,
|
|
99
|
+
) => Promise<GrantsPage<{ readonly userId: string; readonly role: RepoRole }>>;
|
|
100
|
+
/** A page of the repos the person `userId` holds a grant on, in internal ID order. */
|
|
101
|
+
readonly shared: (userId: string, from: GrantsFrom) => Promise<GrantsPage<InternalRepoId>>;
|
|
102
|
+
/** Removes every grant on the repo, as its delete does. */
|
|
103
|
+
readonly drop: (repo: InternalRepoId) => Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
|
|
63
106
|
/** Who holds a login: a person or an org, by the ID Better Auth gave its row, which a rename keeps. */
|
|
64
107
|
export interface Account {
|
|
65
108
|
readonly kind: 'user' | 'org';
|
|
@@ -133,10 +176,13 @@ export interface ImageSigner {
|
|
|
133
176
|
readonly sign: (urls: readonly string[]) => Promise<ReadonlyMap<string, string>>;
|
|
134
177
|
}
|
|
135
178
|
|
|
136
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Git's direct calls a host call reads with, as host code, each an Effect on Git's services, which
|
|
181
|
+
* the server function runs at its edge.
|
|
182
|
+
*/
|
|
137
183
|
export interface HostGit {
|
|
138
|
-
readonly repos: Pick<
|
|
139
|
-
readonly tokens?: Pick<
|
|
184
|
+
readonly repos: Pick<Repos.Repos['Service'], 'list'>;
|
|
185
|
+
readonly tokens?: Pick<Tokens.Tokens['Service'], 'list'> | undefined;
|
|
140
186
|
}
|
|
141
187
|
|
|
142
188
|
declare module '@tanstack/react-start' {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Auth, Git, Objects, Policy, RepoRecords, Repos, Rules, Tokens } from '@ref0/git';
|
|
2
|
-
import type { GitError,
|
|
3
|
-
import { JoinedCalls } from '@ref0/git/extend';
|
|
1
|
+
import { Auth, Git, gitError, Objects, Policy, RepoRecords, Repos, Rules, Tokens } from '@ref0/git';
|
|
2
|
+
import type { GitError, InternalRepoId, PushRule, RepoName } from '@ref0/git';
|
|
4
3
|
import { GitHubPolicy, People } from '@ref0/github';
|
|
5
4
|
import type { GitHubAuthorize, PeopleFor } from '@ref0/github';
|
|
5
|
+
import type { HostRuntime } from '@ref0/infra';
|
|
6
|
+
import * as Context from 'effect/Context';
|
|
6
7
|
import * as Effect from 'effect/Effect';
|
|
7
8
|
import * as Exit from 'effect/Exit';
|
|
8
9
|
import * as Layer from 'effect/Layer';
|
|
9
|
-
import type * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
10
10
|
import * as Option from 'effect/Option';
|
|
11
11
|
|
|
12
12
|
/** The host's say, which the starter's Git is made with: who calls, what they may do, and its push rules. */
|
|
@@ -22,12 +22,28 @@ export interface HostParts {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* Git's `Repos` as the host's own calls, each made as `Git.host`, as Git's host calls are: the
|
|
26
|
+
* directory's lookups read every repo, and ask no policy.
|
|
27
|
+
*/
|
|
28
|
+
const hostRepos = (repos: Repos.Repos['Service']): Parameters<PeopleFor>[0]['git']['repos'] => ({
|
|
29
|
+
create: (input) => repos.create(input, Git.host),
|
|
30
|
+
get: (repo, input) => repos.get(repo, input, Git.host),
|
|
31
|
+
importState: (repo, input) => repos.importState(repo, input, Git.host),
|
|
32
|
+
list: (input) => repos.list(input, Git.host),
|
|
33
|
+
update: (repo, input) => repos.update(repo, input, Git.host),
|
|
34
|
+
rename: (repo, input) => repos.rename(repo, input, Git.host),
|
|
35
|
+
delete: (repo, input) => repos.delete(repo, input, Git.host),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The host's directory as the drop-in's `People`, made over Git's `Repos` as the host's own calls,
|
|
40
|
+
* which its own lookups don't list through.
|
|
27
41
|
*/
|
|
28
42
|
export const peopleOver = (people: PeopleFor) =>
|
|
29
43
|
People.layer(
|
|
30
|
-
Effect.map(Effect.service(
|
|
44
|
+
Effect.map(Effect.service(Repos.Repos), (repos) =>
|
|
45
|
+
people({ git: { repos: hostRepos(repos) } }),
|
|
46
|
+
),
|
|
31
47
|
);
|
|
32
48
|
|
|
33
49
|
/**
|
|
@@ -67,9 +83,10 @@ export const hostLayer = <A, E, O, OE, OR, F, FE, FR>(
|
|
|
67
83
|
/**
|
|
68
84
|
* Git's routes on `runtime`, the drop-in's among them, as the server's ingress reads them: `route`
|
|
69
85
|
* answers `undefined` for a URL none owns, and `fetch` answers it Git's JSON `404`. Neither
|
|
70
|
-
* rejects: a runtime whose build failed answers `fetch`'s refusal
|
|
86
|
+
* rejects: a runtime whose build failed answers `fetch`'s refusal, `starting` while it waits to
|
|
87
|
+
* build again.
|
|
71
88
|
*/
|
|
72
|
-
export const routeOn = <E>(runtime:
|
|
89
|
+
export const routeOn = <E>(runtime: HostRuntime.HostRuntime<Git.Git, E>) => {
|
|
73
90
|
const fetch = Git.toFetch(runtime);
|
|
74
91
|
|
|
75
92
|
const route = async (request: Request) => {
|
|
@@ -81,35 +98,54 @@ export const routeOn = <E>(runtime: ManagedRuntime.ManagedRuntime<Git.Git, E>) =
|
|
|
81
98
|
return { route, fetch };
|
|
82
99
|
};
|
|
83
100
|
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
/**
|
|
102
|
+
* An Effect on the host's services, in the caller's own fiber: its store calls count on the
|
|
103
|
+
* caller's request, and interrupting the caller stops it. A failed build answers `UNAVAILABLE`.
|
|
104
|
+
*/
|
|
105
|
+
export type OnHost = <A, E>(
|
|
106
|
+
effect: Effect.Effect<A, E, HostServices>,
|
|
107
|
+
) => Effect.Effect<A, E | GitError>;
|
|
89
108
|
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
/**
|
|
110
|
+
* `OnHost` over the services `runtime` built, which it reads at each call, so a policy made
|
|
111
|
+
* before its runtime can hold it. Only `HostServices` are provided: the caller's own, its
|
|
112
|
+
* request's count among them, stay.
|
|
113
|
+
*/
|
|
114
|
+
export const onHost =
|
|
115
|
+
(
|
|
116
|
+
runtime: () => {
|
|
117
|
+
readonly contextEffect: Effect.Effect<Context.Context<HostServices>, unknown>;
|
|
118
|
+
},
|
|
119
|
+
): OnHost =>
|
|
120
|
+
(effect) =>
|
|
121
|
+
Effect.flatMap(
|
|
122
|
+
Effect.mapError(
|
|
123
|
+
Effect.suspend(() => runtime().contextEffect),
|
|
124
|
+
() => gitError('UNAVAILABLE', "Git's host isn't built", { hint: 'Try again' }),
|
|
125
|
+
),
|
|
126
|
+
(built) =>
|
|
127
|
+
Effect.provide(
|
|
128
|
+
effect,
|
|
129
|
+
Context.pick(Git.Git, Tokens.Tokens, Repos.Repos, RepoRecords.RepoRecords)(built),
|
|
130
|
+
),
|
|
100
131
|
);
|
|
101
132
|
|
|
102
|
-
/** Git's own tokens
|
|
103
|
-
export const
|
|
104
|
-
create: (target, input) =>
|
|
105
|
-
list: (target, input) =>
|
|
106
|
-
get: (token, input) =>
|
|
107
|
-
revoke: (token, input) =>
|
|
108
|
-
revokeKey: (target, key, input) =>
|
|
133
|
+
/** Git's own tokens over `host`, each call an Effect: Better Auth's sessions mint theirs here. */
|
|
134
|
+
export const tokensOn = (host: OnHost): Tokens.Tokens['Service'] => ({
|
|
135
|
+
create: (target, input) => host(Tokens.create(target, input)),
|
|
136
|
+
list: (target, input) => host(Tokens.list(target, input)),
|
|
137
|
+
get: (token, input) => host(Tokens.get(token, input)),
|
|
138
|
+
revoke: (token, input) => host(Tokens.revoke(token, input)),
|
|
139
|
+
revokeKey: (target, key, input) => host(Tokens.revokeKey(target, key, input)),
|
|
109
140
|
});
|
|
110
141
|
|
|
111
|
-
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
142
|
+
/**
|
|
143
|
+
* What the policy reads of Git's repo records over `host`: the name a repo's internal ID holds
|
|
144
|
+
* now, and the internal ID a name holds now, `undefined` for none.
|
|
145
|
+
*/
|
|
146
|
+
export const repoRecordsOn = (host: OnHost) => ({
|
|
147
|
+
repoName: (internalId: InternalRepoId) =>
|
|
148
|
+
host(Effect.map(RepoRecords.record(internalId), (record) => record?.name)),
|
|
149
|
+
repoId: (name: RepoName) =>
|
|
150
|
+
host(Effect.map(RepoRecords.pin(name), (pinned) => pinned?.internalId)),
|
|
151
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Git, GitEvents } from '@ref0/git';
|
|
2
|
+
import * as Effect from 'effect/Effect';
|
|
3
|
+
import * as Schema from 'effect/Schema';
|
|
4
|
+
|
|
5
|
+
import type { Grants } from './context.ts';
|
|
6
|
+
|
|
7
|
+
/** A deleted repo's grants the store didn't remove: the run is sent again. */
|
|
8
|
+
class RepoGrantsUnremoved extends Schema.TaggedError<RepoGrantsUnremoved>()('RepoGrantsUnremoved', {
|
|
9
|
+
repo: Schema.String,
|
|
10
|
+
cause: Schema.Unknown,
|
|
11
|
+
}) {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A deleted repo's grants removed from `grants`, however the repo was deleted, as Git's
|
|
15
|
+
* `repo.deleted` names it by its internal ID. A remove that fails fails the run, which Git tries
|
|
16
|
+
* again as its delivery's retry says, as `repoIcons`' does. Until it runs, no grant on the repo
|
|
17
|
+
* decides anything: no name reaches a deleted repo, and a new repo under its name has another ID.
|
|
18
|
+
*/
|
|
19
|
+
export const repoGrantsDropped = (grants: Pick<Grants, 'drop'>) =>
|
|
20
|
+
Git.addDelivery(
|
|
21
|
+
'repo-grants',
|
|
22
|
+
GitEvents.group((on) =>
|
|
23
|
+
on.handle('repo.deleted', ({ events }) =>
|
|
24
|
+
Effect.forEach(
|
|
25
|
+
events,
|
|
26
|
+
({ internalId }) =>
|
|
27
|
+
Effect.tryPromise({
|
|
28
|
+
try: () => grants.drop(internalId),
|
|
29
|
+
catch: (cause) => new RepoGrantsUnremoved({ repo: internalId, cause }),
|
|
30
|
+
}),
|
|
31
|
+
{ discard: true },
|
|
32
|
+
),
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
);
|