ref0-git 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -925,7 +925,7 @@ export interface components {
925
925
  message: string;
926
926
  hint?: string;
927
927
  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" | "too-many-gitmodules-and-gitattributes" | "prune-walk-too-large") | string;
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") | string;
929
929
  indexBytes?: number | ("Infinity" | "-Infinity" | "NaN");
930
930
  pushBytes?: number | ("Infinity" | "-Infinity" | "NaN");
931
931
  most?: number | ("Infinity" | "-Infinity" | "NaN");
@@ -4,6 +4,7 @@ import type {
4
4
  AuthorizeInput,
5
5
  GitError,
6
6
  GitAuthorize,
7
+ InternalRepoId,
7
8
  NamedActor,
8
9
  PushRule,
9
10
  RefName,
@@ -212,15 +213,22 @@ export interface Pictures {
212
213
  readonly avatars: Pick<Avatars, 'hash'>;
213
214
  }
214
215
 
216
+ /** The name `internalId`'s repo has now, `undefined` once none holds it. */
217
+ export type RepoNameOf = (
218
+ internalId: InternalRepoId,
219
+ signal: AbortSignal,
220
+ ) => Promise<RepoName | undefined>;
221
+
215
222
  /**
216
- * What the starter's policy reads past its orgs: its `Pictures`, both or neither, and
217
- * `privateRepos`, which lists an owner's private repos for the owner index's hook. With none, it
218
- * names no private repo.
223
+ * What the starter's policy reads past its orgs: its `Pictures`, both or neither,
224
+ * `privateRepos`, which lists an owner's private repos for the owner index's hook, and
225
+ * `repoName`, which the drop-in's owner check reads. With no `privateRepos`, it names no private
226
+ * repo, and with no `repoName`, the owner check reads the name the request named.
219
227
  */
220
228
  export type HostPolicyOptions = (
221
229
  | Pictures
222
230
  | { readonly origin?: undefined; readonly avatars?: undefined }
223
- ) & { readonly privateRepos?: PrivateRepos };
231
+ ) & { readonly privateRepos?: PrivateRepos; readonly repoName?: RepoNameOf };
224
232
 
225
233
  /**
226
234
  * What of `owner`'s repos `token` covers: every one, those under the token's longer prefix, its
@@ -243,7 +251,12 @@ const coverOf = (owner: string, token: GitHubReadableReposInput['token']) => {
243
251
  * directory of people and orgs, by Better Auth's tables, with what `options` adds.
244
252
  */
245
253
  export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPolicy => {
246
- const { origin, avatars, privateRepos = async () => ({ names: [], more: false }) } = options;
254
+ const {
255
+ origin,
256
+ avatars,
257
+ privateRepos = async () => ({ names: [], more: false }),
258
+ repoName,
259
+ } = options;
247
260
 
248
261
  /**
249
262
  * The `avatar_url` of `login`, held by `account`, when it has an upload: the app's route, by its
@@ -317,6 +330,22 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
317
330
  const owns = async (actor: NamedActor, owner: string | undefined) =>
318
331
  owner === actor.id || (owner !== undefined && (await belongs(actor, owner)));
319
332
 
333
+ /**
334
+ * The owner now of the repo a drop-in operation on `name` acts on: its current name's, read by
335
+ * `repoName` from the repo's internal ID, so a repo transferred since the request named it is
336
+ * its new owner's, and none once no name holds it or the input names no repo. With no
337
+ * `repoName`, the owner of `name`.
338
+ */
339
+ const ownerNow = async (name: RepoName, input: GitHubAuthorization) => {
340
+ if (repoName === undefined) return ownerOf(name);
341
+
342
+ if (input.repo === undefined) return undefined;
343
+
344
+ const now = await repoName(input.repo.internalId, input.signal);
345
+
346
+ return now === undefined ? undefined : ownerOf(now);
347
+ };
348
+
320
349
  /**
321
350
  * Git's `authorize`: public repos for anyone to read and list, who they are for anyone signed in,
322
351
  * and the rest for a repo's owner, once the caller's token still holds.
@@ -482,7 +511,7 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
482
511
  // holding the repo is all that's left to ask.
483
512
  if (operation.asAuthor === true && authorsOwn.has(operation.kind)) return accept();
484
513
 
485
- return (yield* read(() => owns(actor, ownerOf(operation.repo))))
514
+ return (yield* read(async () => owns(actor, await ownerNow(operation.repo, input))))
486
515
  ? accept()
487
516
  : reject({ message: 'Only the owner may do this' });
488
517
  });
@@ -67,7 +67,7 @@ catalog:
67
67
  # The app's Markdown renderer: words, a WebAssembly parser, with hooks for GitHub's alerts,
68
68
  # anchors, references and URLs (Q213). Apache-2.0.
69
69
  '@pierre/words': 0.3.0
70
- '@ref0/workspace': 0.6.0
70
+ '@ref0/workspace': 0.8.0
71
71
  '@tailwindcss/vite': 4.3.5
72
72
  # The app's stack: TanStack Start, its router and Query, and React, as spike F ran them, at the
73
73
  # newest releases past pnpm's minimum release age.
@@ -218,3 +218,6 @@ allowBuilds:
218
218
  better-sqlite3: true
219
219
  esbuild: true
220
220
  workerd: true
221
+
222
+ minimumReleaseAgeExclude:
223
+ - '@ref0/workspace@0.8.0'
package/dist/init/app.mjs CHANGED
@@ -92,7 +92,8 @@ const gitServerImport = (choices) => `import { ${[
92
92
  choices.objects === "packs" && "lfs",
93
93
  choices.objects !== "packs" && "loose",
94
94
  choices.queue === "on" && "mergeQueue",
95
- choices.objects === "packs" && "packs"
95
+ choices.objects === "packs" && "packs",
96
+ "RepoRecords"
96
97
  ].filter(Predicate.isString).join(", ")} } from '@ref0/git';`;
97
98
  /** The slots both platforms' `src/git.ts` fill alike: the queue's, and the store's past the head. */
98
99
  const bodySlots = (choices, uploads) => {
@@ -1,6 +1,6 @@
1
1
  // src/init/metadata.ts
2
2
  /** The version `ref0-git`, `create-ref0-git` and Git's packages release at, all at once (Q738). */
3
- const release = "0.4.0";
3
+ const release = "0.6.0";
4
4
  /** The packages the app depends on, by their folder in a checkout's `packages/`. */
5
5
  const appPackages = [
6
6
  "infra",
@@ -3,7 +3,7 @@ var templates_default = {
3
3
  appGit: [
4
4
  {
5
5
  "slot": "gitImport",
6
- "text": "import { createGitServer, lfs, mergeQueue, packs } from '@ref0/git';"
6
+ "text": "import { createGitServer, lfs, mergeQueue, packs, RepoRecords } from '@ref0/git';"
7
7
  },
8
8
  "\n",
9
9
  {
@@ -29,7 +29,7 @@ var templates_default = {
29
29
  "slot": "queueMerge",
30
30
  "text": "/**\n * How the queue writes an entry's link onto `main`: a merge commit, by the person who added it, as\n * a pull request's merge button writes one, and titled as GitHub titles it for a pull request's\n * entry, keyed `pr-<number>`.\n */\nconst queueMerge = ({ entry }: MergeInput): MergePlan => {\n const [owner = ''] = entry.repo.split('/');\n const branch = entry.source.replace(/^refs\\/heads\\//, '');\n const pull = /^pr-([1-9]\\d*)$/.exec(entry.key)?.[1];\n const title =\n pull === undefined ? `Merge ${branch}` : `Merge pull request #${pull} from ${owner}/${branch}`;\n const login = entry.subject?.id ?? entry.actor.id;\n const hostname = new URL(env.APP_ORIGIN).hostname;\n\n return {\n method: 'merge',\n message: `${title}\\n`,\n author: { name: login, email: `${login}@users.noreply.${hostname}`, at: Date.now(), offset: 0 },\n };\n};\n\n"
31
31
  },
32
- "/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(git)(prefix, most, host),\n});\n\n/** Git, with the device flow's sign-in for `gh` and `ref0-git login`. */\nexport const git = createGitServer({\n",
32
+ "/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(git)(prefix, most, host),\n repoName: async (internalId, signal) =>\n (await git.runtime.runPromise(RepoRecords.record(internalId), { signal }))?.name,\n});\n\n/** Git, with the device flow's sign-in for `gh` and `ref0-git login`. */\nexport const git = createGitServer({\n",
33
33
  {
34
34
  "slot": "adapter",
35
35
  "text": " adapter: [layer({ records: env.RECORDS, jobs: env.JOBS }), bucket],"
@@ -58,13 +58,13 @@ var templates_default = {
58
58
  appGitNode: [
59
59
  {
60
60
  "slot": "head",
61
- "text": "import { createGitServer, lfs, mergeQueue, packs } from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport { tokens } from '@ref0/git/auth';\nimport { createRestHandler } from '@ref0/git/rest';\nimport { createGitHubHandler } from '@ref0/github';\nimport {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\n\nimport type { Env } from './env.ts';\nimport { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';\nimport { privateReposOf } from './private-repos.ts';\nimport { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';\nimport { avatars } from './signin/avatars.ts';\nimport { appAuth } from './signin/host-session.ts';\nimport { orgsOver } from './signin/orgs.ts';\nimport { sealKey } from './signin/seal.ts';\n\n// SAFETY: `wrangler.jsonc` binds the objects, the bucket and D1 and sets `APP_ORIGIN`; the\n// secrets come from `wrangler secret put`, or `.dev.vars` locally.\nexport const env = bindings as Env;\n\nconst {\n R2_ACCOUNT_ID: accountId,\n R2_ACCESS_KEY_ID: accessKeyId,\n R2_SECRET_ACCESS_KEY: secretAccessKey,\n} = env;\n\n// With R2's S3 credentials, a push's pack uploads to the bucket in parts, past Workers' 100 MB body.\nconst bucket =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? layerR2(env.PACKS)\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\n"
61
+ "text": "import { createGitServer, lfs, mergeQueue, packs, RepoRecords } from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport { tokens } from '@ref0/git/auth';\nimport { createRestHandler } from '@ref0/git/rest';\nimport { createGitHubHandler } from '@ref0/github';\nimport {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\n\nimport type { Env } from './env.ts';\nimport { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';\nimport { privateReposOf } from './private-repos.ts';\nimport { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';\nimport { avatars } from './signin/avatars.ts';\nimport { appAuth } from './signin/host-session.ts';\nimport { orgsOver } from './signin/orgs.ts';\nimport { sealKey } from './signin/seal.ts';\n\n// SAFETY: `wrangler.jsonc` binds the objects, the bucket and D1 and sets `APP_ORIGIN`; the\n// secrets come from `wrangler secret put`, or `.dev.vars` locally.\nexport const env = bindings as Env;\n\nconst {\n R2_ACCOUNT_ID: accountId,\n R2_ACCESS_KEY_ID: accessKeyId,\n R2_SECRET_ACCESS_KEY: secretAccessKey,\n} = env;\n\n// With R2's S3 credentials, a push's pack uploads to the bucket in parts, past Workers' 100 MB body.\nconst bucket =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? layerR2(env.PACKS)\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\n"
62
62
  },
63
63
  {
64
64
  "slot": "queueMerge",
65
65
  "text": "/**\n * How the queue writes an entry's link onto `main`: a merge commit, by the person who added it, as\n * a pull request's merge button writes one, and titled as GitHub titles it for a pull request's\n * entry, keyed `pr-<number>`.\n */\nconst queueMerge = ({ entry }: MergeInput): MergePlan => {\n const [owner = ''] = entry.repo.split('/');\n const branch = entry.source.replace(/^refs\\/heads\\//, '');\n const pull = /^pr-([1-9]\\d*)$/.exec(entry.key)?.[1];\n const title =\n pull === undefined ? `Merge ${branch}` : `Merge pull request #${pull} from ${owner}/${branch}`;\n const login = entry.subject?.id ?? entry.actor.id;\n const hostname = new URL(env.APP_ORIGIN).hostname;\n\n return {\n method: 'merge',\n message: `${title}\\n`,\n author: { name: login, email: `${login}@users.noreply.${hostname}`, at: Date.now(), offset: 0 },\n };\n};\n\n"
66
66
  },
67
- "/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(git)(prefix, most, host),\n});\n\n/** Git, with the device flow's sign-in for `gh` and `ref0-git login`. */\nexport const git = createGitServer({\n",
67
+ "/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(git)(prefix, most, host),\n repoName: async (internalId, signal) =>\n (await git.runtime.runPromise(RepoRecords.record(internalId), { signal }))?.name,\n});\n\n/** Git, with the device flow's sign-in for `gh` and `ref0-git login`. */\nexport const git = createGitServer({\n",
68
68
  {
69
69
  "slot": "adapter",
70
70
  "text": " adapter: [layer({ records: env.RECORDS, jobs: env.JOBS }), bucket],"
@@ -28,5 +28,5 @@ const packedPath = (name) => {
28
28
  * the release, or the tarball `--from-checkout` names for that package. One it wrote moves to this
29
29
  * run's spec; any other is the person's, a tarball of their own in `vendor/` too, and stays.
30
30
  */
31
- const initWrote = (name, spec) => spec === "0.4.0" || spec !== void 0 && packedPath(name).test(spec);
31
+ const initWrote = (name, spec) => spec === "0.6.0" || spec !== void 0 && packedPath(name).test(spec);
32
32
  export { catalog, frameworkPackages, initWrote, nodeAppPackages, nodePackages, peerPackages, release, specOf, storePackages, vercelPackages };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ref0-git",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "private": false,
5
5
  "description": "ref0-git, the CLI for a Git host built on @ref0/git, and git-remote-ref0, its remote helper",
6
6
  "license": "Apache-2.0",
@@ -24,8 +24,8 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@effect/platform-node-shared": "4.1.4",
27
- "@ref0/git": "0.4.0",
28
- "@ref0/infra": "0.4.0",
27
+ "@ref0/git": "0.6.0",
28
+ "@ref0/infra": "0.6.0",
29
29
  "diff": "9.0.0",
30
30
  "effect": "^4.1.4"
31
31
  },
@@ -34,8 +34,8 @@
34
34
  "@effect/vitest": "4.1.4",
35
35
  "@libsql/client": "0.18.0",
36
36
  "@libsql/kysely-libsql": "0.4.1",
37
- "@ref0/github": "0.4.0",
38
- "@ref0/xdiff-wasm": "0.4.0",
37
+ "@ref0/github": "0.6.0",
38
+ "@ref0/xdiff-wasm": "0.6.0",
39
39
  "@tanstack/react-start": "1.169.5",
40
40
  "@types/node": "24.19.2",
41
41
  "@types/pg": "8.23.1",