ref0-git 0.12.0 → 0.14.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 (36) hide show
  1. package/app/apps/github/generated/git-rest.ts +152 -3
  2. package/app/apps/github/migrations/postgres/0001_auth.sql +8 -1
  3. package/app/apps/github/migrations/sql/0005_repo_grants.sql +10 -0
  4. package/app/apps/github/src/clients/allowed.ts +9 -4
  5. package/app/apps/github/src/components/repos/your-repos.tsx +57 -11
  6. package/app/apps/github/src/context/context.ts +45 -2
  7. package/app/apps/github/src/context/repo-grants.ts +35 -0
  8. package/app/apps/github/src/hooks/repos.ts +14 -3
  9. package/app/apps/github/src/policy.ts +485 -92
  10. package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +1 -1
  11. package/app/apps/github/src/routes/index.tsx +2 -1
  12. package/app/apps/github/src/settings/access-page.tsx +308 -0
  13. package/app/apps/github/src/settings/access.ts +156 -0
  14. package/app/apps/github/src/settings/settings-layout.tsx +0 -16
  15. package/app/apps/github/src/signin/auth.ts +2 -0
  16. package/app/apps/github/src/signin/orgs.ts +57 -14
  17. package/app/apps/github/src/signin/repo-grants.ts +141 -0
  18. package/app/pnpm-workspace.yaml +2 -2
  19. package/dist/cli/child.mjs +73 -3
  20. package/dist/cli/commands.mjs +2 -0
  21. package/dist/cli/documents.mjs +42 -2
  22. package/dist/cli/keys.mjs +431 -0
  23. package/dist/cli/main.mjs +148 -0
  24. package/dist/cli/prompt.mjs +40 -1
  25. package/dist/cli/ref0-git.mjs +4 -141
  26. package/dist/cli/setup.mjs +115 -13
  27. package/dist/cli/sign-in.mjs +1 -1
  28. package/dist/cli/tools-node.mjs +20 -0
  29. package/dist/cli/tools.mjs +12 -0
  30. package/dist/init/app.mjs +3 -1
  31. package/dist/init/git-module.mjs +11 -6
  32. package/dist/init/metadata.mjs +1 -1
  33. package/dist/init/template.mjs +1 -0
  34. package/dist/init/templates.mjs +15 -10
  35. package/dist/init/versions.mjs +1 -1
  36. package/package.json +5 -5
@@ -228,6 +228,22 @@ export interface paths {
228
228
  patch?: never;
229
229
  trace?: never;
230
230
  };
231
+ "/work/{internalId}": {
232
+ parameters: {
233
+ query?: never;
234
+ header?: never;
235
+ path?: never;
236
+ cookie?: never;
237
+ };
238
+ get: operations["work.listById"];
239
+ put?: never;
240
+ post?: never;
241
+ delete?: never;
242
+ options?: never;
243
+ head?: never;
244
+ patch?: never;
245
+ trace?: never;
246
+ };
231
247
  "/repos/{repo}/-/work/retry": {
232
248
  parameters: {
233
249
  query?: never;
@@ -331,7 +347,7 @@ export interface paths {
331
347
  path?: never;
332
348
  cookie?: never;
333
349
  };
334
- /** @description A blob's bytes, streamed and checked against its ID as they go: a body that ends short of its `Content-Length` failed the check, as `DATA_LOSS`. `bytes` has no default, so the file limit, 100 MiB, caps it. `object-too-large` comes before the first byte, past a `bytes` the caller sets or for a blob stored as a delta past 16 MiB. `milliseconds` limits the call until it answers, not the body after it. */
350
+ /** @description A blob's bytes, streamed and checked against its ID as they go: a body that ends short of its `Content-Length` failed the check, as `DATA_LOSS`. `bytes` has no default, so the largest file a host may let a push take, 1 GiB, caps it. `object-too-large` comes before the first byte, past a `bytes` the caller sets or for a blob stored as a delta past 16 MiB. `milliseconds` limits the call until it answers, not the body after it. */
335
351
  get: operations["blobs.get"];
336
352
  put?: never;
337
353
  post?: never;
@@ -901,9 +917,10 @@ export interface components {
901
917
  hint?: string;
902
918
  context?: {
903
919
  id?: string;
904
- reason?: ("busy" | "packs-awaiting-repack" | "awaiting-index" | "may-have-saved" | "too-many-writes") | string;
920
+ reason?: ("busy" | "packs-awaiting-repack" | "awaiting-index" | "may-have-saved" | "too-many-writes" | "starting") | string;
905
921
  packs?: number | ("Infinity" | "-Infinity" | "NaN");
906
922
  most?: number | ("Infinity" | "-Infinity" | "NaN");
923
+ retryAfter?: number | ("Infinity" | "-Infinity" | "NaN");
907
924
  } & {
908
925
  [key: string]: string | number | ("Infinity" | "-Infinity" | "NaN") | boolean | string[] | null;
909
926
  };
@@ -925,7 +942,7 @@ export interface components {
925
942
  message: string;
926
943
  hint?: string;
927
944
  context?: {
928
- reason?: ("too-large" | "rate-limited" | "walk-limit" | "diff-limit" | "object-too-large" | "delta-too-large" | "response-too-large" | "too-many-pointers" | "fetch-plan-too-large" | "too-many-store-calls" | "call-budget" | "events-undelivered" | "events-waiting" | "name-churn" | "queue-full" | "queue-targets-full" | "too-many-gitmodules-and-gitattributes" | "prune-walk-too-large" | "job-step-calls" | "job-step-yielded") | string;
945
+ reason?: ("too-large" | "rate-limited" | "walk-limit" | "diff-limit" | "object-too-large" | "repo-too-large" | "delta-too-large" | "response-too-large" | "too-many-pointers" | "fetch-plan-too-large" | "too-many-store-calls" | "call-budget" | "events-undelivered" | "events-waiting" | "name-churn" | "queue-full" | "queue-targets-full" | "too-many-gitmodules-and-gitattributes" | "prune-walk-too-large" | "job-step-calls" | "job-step-yielded") | string;
929
946
  indexBytes?: number | ("Infinity" | "-Infinity" | "NaN");
930
947
  pushBytes?: number | ("Infinity" | "-Infinity" | "NaN");
931
948
  most?: number | ("Infinity" | "-Infinity" | "NaN");
@@ -1522,6 +1539,7 @@ export interface components {
1522
1539
  defaultBranch?: string;
1523
1540
  public: boolean;
1524
1541
  upstream?: string;
1542
+ shallow: boolean;
1525
1543
  stats: {
1526
1544
  repo: string;
1527
1545
  refs: number | ("Infinity" | "-Infinity" | "NaN");
@@ -3993,6 +4011,136 @@ export interface operations {
3993
4011
  };
3994
4012
  };
3995
4013
  };
4014
+ "work.listById": {
4015
+ parameters: {
4016
+ query?: {
4017
+ state?: "waiting" | "running" | "failed";
4018
+ after?: string;
4019
+ limit?: string;
4020
+ };
4021
+ header?: never;
4022
+ path: {
4023
+ internalId: string;
4024
+ };
4025
+ cookie?: never;
4026
+ };
4027
+ requestBody?: never;
4028
+ responses: {
4029
+ /** @description Success */
4030
+ 200: {
4031
+ headers: {
4032
+ [name: string]: unknown;
4033
+ };
4034
+ content: {
4035
+ "application/json": {
4036
+ items: components["schemas"]["WorkItem"][];
4037
+ next?: string;
4038
+ };
4039
+ };
4040
+ };
4041
+ /** @description GitError.INVALID_ARGUMENT */
4042
+ 400: {
4043
+ headers: {
4044
+ "ref0-code": string;
4045
+ [name: string]: unknown;
4046
+ };
4047
+ content: {
4048
+ "application/json": components["schemas"]["GitError.INVALID_ARGUMENT"];
4049
+ };
4050
+ };
4051
+ /** @description GitError.UNAUTHENTICATED */
4052
+ 401: {
4053
+ headers: {
4054
+ "ref0-code": string;
4055
+ "www-authenticate": string;
4056
+ [name: string]: unknown;
4057
+ };
4058
+ content: {
4059
+ "application/json": components["schemas"]["GitError.UNAUTHENTICATED"];
4060
+ };
4061
+ };
4062
+ /** @description GitError.NOT_ALLOWED */
4063
+ 403: {
4064
+ headers: {
4065
+ "ref0-code": string;
4066
+ [name: string]: unknown;
4067
+ };
4068
+ content: {
4069
+ "application/json": components["schemas"]["GitError.NOT_ALLOWED"];
4070
+ };
4071
+ };
4072
+ /** @description GitError.NOT_FOUND */
4073
+ 404: {
4074
+ headers: {
4075
+ "ref0-code": string;
4076
+ [name: string]: unknown;
4077
+ };
4078
+ content: {
4079
+ "application/json": components["schemas"]["GitError.NOT_FOUND"];
4080
+ };
4081
+ };
4082
+ /** @description GitError.ALREADY_EXISTS | GitError.FAILED_PRECONDITION */
4083
+ 409: {
4084
+ headers: {
4085
+ "ref0-code": string;
4086
+ [name: string]: unknown;
4087
+ };
4088
+ content: {
4089
+ "application/json": components["schemas"]["GitError.ALREADY_EXISTS"] | components["schemas"]["GitError.FAILED_PRECONDITION"];
4090
+ };
4091
+ };
4092
+ /** @description GitError.RESOURCE_EXHAUSTED */
4093
+ 413: {
4094
+ headers: {
4095
+ "ref0-code": string;
4096
+ [name: string]: unknown;
4097
+ };
4098
+ content: {
4099
+ "application/json": components["schemas"]["GitError.RESOURCE_EXHAUSTED"];
4100
+ };
4101
+ };
4102
+ /** @description GitError.RESOURCE_EXHAUSTED.rate-limited */
4103
+ 429: {
4104
+ headers: {
4105
+ "ref0-code": string;
4106
+ [name: string]: unknown;
4107
+ };
4108
+ content: {
4109
+ "application/json": components["schemas"]["GitError.RESOURCE_EXHAUSTED.rate-limited"];
4110
+ };
4111
+ };
4112
+ /** @description GitError.DATA_LOSS | GitError.INTERNAL */
4113
+ 500: {
4114
+ headers: {
4115
+ "ref0-code": string;
4116
+ [name: string]: unknown;
4117
+ };
4118
+ content: {
4119
+ "application/json": components["schemas"]["GitError.DATA_LOSS"] | components["schemas"]["GitError.INTERNAL"];
4120
+ };
4121
+ };
4122
+ /** @description GitError.UNAVAILABLE */
4123
+ 503: {
4124
+ headers: {
4125
+ "ref0-code": string;
4126
+ [name: string]: unknown;
4127
+ };
4128
+ content: {
4129
+ "application/json": components["schemas"]["GitError.UNAVAILABLE"];
4130
+ };
4131
+ };
4132
+ /** @description GitError.DEADLINE_EXCEEDED */
4133
+ 504: {
4134
+ headers: {
4135
+ "ref0-code": string;
4136
+ [name: string]: unknown;
4137
+ };
4138
+ content: {
4139
+ "application/json": components["schemas"]["GitError.DEADLINE_EXCEEDED"];
4140
+ };
4141
+ };
4142
+ };
4143
+ };
3996
4144
  "work.retry": {
3997
4145
  parameters: {
3998
4146
  query?: never;
@@ -5967,6 +6115,7 @@ export interface operations {
5967
6115
  parameters: {
5968
6116
  query: {
5969
6117
  ref: string;
6118
+ exclude?: string[];
5970
6119
  path?: string;
5971
6120
  authors?: string[];
5972
6121
  committers?: string[];
@@ -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 counts.
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 milestone, a
89
- * deleted label or milestone, a release and a hook are the repo's. Asking for reviews is `pull.update`, merging or queueing a pull request is
90
- * `pull.merge`, and a review, a comment on its lines or discarding a pending review is
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. */
@@ -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's login, as each one heard them from its loaded rows. */
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 no repositories of their own still lands
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.login,
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
- (login: string) => (languages: readonly string[]) =>
125
+ (key: string) => (languages: readonly string[]) =>
84
126
  setHeard((before) =>
85
- before[login]?.join('\n') === languages.join('\n')
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,5 +1,5 @@
1
- import type { Caller, Policy, RepoCalls, Result, TokenCalls } from '@ref0/git';
2
- import type { GitHubAuthorize } from '@ref0/github';
1
+ import type { Caller, InternalRepoId, Policy, RepoCalls, Result, TokenCalls } 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';
@@ -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
+ );
@@ -20,7 +20,8 @@ import { ownerProblem } from '../names/owners.ts';
20
20
  * cursor their `Link` names (Q391). The drop-in serves no `/search/repositories`, so search and
21
21
  * language are the browser's, over every page, up to `maxFiltered` rows. The viewer's own list
22
22
  * filters visibility with `visibility`, beside `affiliation=owner` (GitHub refuses either beside
23
- * `type`), and an org's every type with `type`. A person's list reads neither, so the browser
23
+ * `type`), as the repos shared with the viewer do beside `affiliation=collaborator` (#1998), and
24
+ * an org's every type with `type`. A person's list reads neither, so the browser
24
25
  * filters it, as it does sources and forks on the viewer's.
25
26
  */
26
27
 
@@ -39,9 +40,13 @@ export interface RepoRow {
39
40
  readonly license: string | null;
40
41
  }
41
42
 
42
- /** Whose repositories a page lists, as the route found its owner. */
43
+ /**
44
+ * Whose repositories a page lists, as the route found its owner, or the repos others shared with
45
+ * the viewer `login`, which `/` lists apart from their own.
46
+ */
43
47
  export type Owner =
44
48
  | { readonly kind: 'viewer'; readonly login: string }
49
+ | { readonly kind: 'shared'; readonly login: string }
45
50
  | { readonly kind: 'org'; readonly login: string }
46
51
  | { readonly kind: 'user'; readonly login: string };
47
52
 
@@ -254,6 +259,7 @@ const serverType = (owner: Owner, type: RepoType): RepoType => {
254
259
  case 'org':
255
260
  return type;
256
261
  case 'viewer':
262
+ case 'shared':
257
263
  return visibilityOf(type);
258
264
  case 'user':
259
265
  return 'all';
@@ -322,9 +328,14 @@ const answerOf = async (
322
328
  params: { path: { username: owner.login }, query: { ...paging } },
323
329
  });
324
330
  case 'viewer':
331
+ case 'shared':
325
332
  return clients.github.GET('/user/repos', {
326
333
  params: {
327
- query: { ...paging, affiliation: 'owner', visibility: visibilityOf(query.type) },
334
+ query: {
335
+ ...paging,
336
+ affiliation: owner.kind === 'viewer' ? 'owner' : 'collaborator',
337
+ visibility: visibilityOf(query.type),
338
+ },
328
339
  },
329
340
  });
330
341
  }