ref0-git 0.6.0 → 0.8.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 (59) hide show
  1. package/app/apps/github/README.md +3 -7
  2. package/app/apps/github/generated/git-rest.ts +17 -20
  3. package/app/apps/github/src/clients/allowed.ts +7 -9
  4. package/app/apps/github/src/clients/avatars.ts +5 -3
  5. package/app/apps/github/src/clients/graphql.ts +12 -2
  6. package/app/apps/github/src/clients/host-calls.ts +2 -1
  7. package/app/apps/github/src/clients/transfers.ts +56 -19
  8. package/app/apps/github/src/components/signin/device-card.tsx +2 -2
  9. package/app/apps/github/src/context/context.ts +5 -5
  10. package/app/apps/github/src/context/host.ts +115 -0
  11. package/app/apps/github/src/ingress.ts +28 -0
  12. package/app/apps/github/src/policy.ts +113 -78
  13. package/app/apps/github/src/private-repos.ts +7 -7
  14. package/app/apps/github/src/pulls/review.ts +2 -1
  15. package/app/apps/github/src/releases/release-form.tsx +40 -4
  16. package/app/apps/github/src/releases/releases.ts +148 -22
  17. package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +9 -2
  18. package/app/apps/github/src/seed/seed.ts +68 -38
  19. package/app/apps/github/src/server.ts +28 -11
  20. package/app/apps/github/src/signin/approval.ts +20 -15
  21. package/app/apps/github/src/signin/attempts.ts +306 -0
  22. package/app/apps/github/src/signin/auth.ts +9 -0
  23. package/app/apps/github/src/signin/device-code.ts +2 -2
  24. package/app/apps/github/src/signin/device-prompt.ts +6 -6
  25. package/app/apps/github/src/signin/host-session.ts +30 -18
  26. package/app/apps/github/src/signin/limits.ts +35 -0
  27. package/app/pnpm-workspace.yaml +39 -38
  28. package/dist/cli/events.mjs +10 -13
  29. package/dist/cli/failure.mjs +4 -10
  30. package/dist/cli/hosts.mjs +2 -2
  31. package/dist/cli/queue.mjs +14 -23
  32. package/dist/cli/repos.mjs +10 -19
  33. package/dist/cli/resources.mjs +2 -2
  34. package/dist/cli/setup.mjs +33 -40
  35. package/dist/cli/sign-in.mjs +4 -4
  36. package/dist/cli/tokens.mjs +7 -11
  37. package/dist/cli/vendor.mjs +21 -1
  38. package/dist/init/app.mjs +45 -23
  39. package/dist/init/astro.mjs +2 -2
  40. package/dist/init/cloudflare.mjs +100 -51
  41. package/dist/init/create.mjs +1 -1
  42. package/dist/init/detect.mjs +7 -5
  43. package/dist/init/files.mjs +6 -1
  44. package/dist/init/git-module.mjs +89 -32
  45. package/dist/init/metadata.mjs +12 -7
  46. package/dist/init/mounts.mjs +12 -20
  47. package/dist/init/next.mjs +1 -1
  48. package/dist/init/node-app.mjs +5 -2
  49. package/dist/init/node.mjs +24 -35
  50. package/dist/init/nuxt.mjs +6 -7
  51. package/dist/init/react-router.mjs +2 -2
  52. package/dist/init/routes.mjs +13 -22
  53. package/dist/init/stores.mjs +3 -2
  54. package/dist/init/sveltekit.mjs +3 -3
  55. package/dist/init/template.mjs +14 -15
  56. package/dist/init/templates.mjs +76 -81
  57. package/dist/init/vercel.mjs +18 -22
  58. package/dist/init/versions.mjs +32 -4
  59. package/package.json +13 -13
@@ -1,23 +1,16 @@
1
- import { matcherCall, matcherImport, servedBy } from "./routes.mjs";
1
+ import { matcherCall, matcherImport } from "./routes.mjs";
2
2
  // src/init/mounts.ts
3
- /**
4
- * The server module's exports a mount imports: Git, whose runtime runs the jobs, and what serves
5
- * Git's URLs, as `served` in Hono's, whose app imports `serve` from `@hono/node-server`.
6
- */
7
- const importsOf = (choices, asServed) => servedBy(choices) === "git" ? "git" : `git, ${servedBy(choices)}${asServed ? " as served" : ""}`;
8
- /** What Hono's lines mount: Git itself, or what serves its URLs, imported `as served`. */
9
- const honoServed = (choices) => servedBy(choices) === "git" ? "git" : "served";
10
3
  /** Express's middleware, before any body parser, as printed source: the matcher's paths to Git. */
11
- const expressLine = (choices) => `app.use(toNodeMiddleware(${servedBy(choices)}, (url) => ${matcherCall(choices)}))`;
4
+ const expressLine = (choices) => `app.use(toNodeMiddleware(runtime, (url) => ${matcherCall(choices)}))`;
12
5
  /**
13
6
  * The imports a mount's lines start with: `@ref0/git/node`'s `names`, Node's job runner, the
14
- * matcher, and the module, what serves `as served` where `asServed`.
7
+ * matcher, and the module's runtime, which serves Git's URLs and runs its jobs.
15
8
  */
16
- const imports = (choices, names, asServed = false) => [
9
+ const imports = (choices, names) => [
17
10
  `import { ${names} } from '@ref0/git/node';`,
18
11
  matcherImport(choices),
19
12
  "import * as Node from '@ref0/infra/node';",
20
- `import { ${importsOf(choices, asServed)} } from './git.ts';`,
13
+ "import { runtime } from './git.ts';",
21
14
  ""
22
15
  ];
23
16
  /** What Hono's lines take from Node and `@hono/node-server`: a server, and the app as a listener. */
@@ -27,23 +20,22 @@ const honoImports = ["import { createServer } from 'node:http';", "import { getR
27
20
  * the listener runs once, then raises it again for Node, or the person's own listener, to exit.
28
21
  */
29
22
  const startLines = [
30
- "const stop = Node.toJobRunner(git.runtime);",
23
+ "const stop = Node.toJobRunner(runtime);",
31
24
  "",
32
25
  "process.once('SIGTERM', () => void stop().finally(() => process.kill(process.pid, 'SIGTERM')));"
33
26
  ];
34
27
  /** Each server's lines, after its imports. */
35
28
  const mountLines = (server, choices) => {
36
- const serve = servedBy(choices);
37
29
  if (server === "hono") return [
38
30
  ...startLines,
39
31
  "",
40
- `const mount = toNodeMiddleware(${honoServed(choices)}, (url) => ${matcherCall(choices)});`,
32
+ `const mount = toNodeMiddleware(runtime, (url) => ${matcherCall(choices)});`,
41
33
  "",
42
34
  "const listener = getRequestListener(app.fetch);",
43
35
  "",
44
36
  "// In place of serve(), after the app's routes: Git answers its URLs in front of the app, as",
45
37
  "// Express's middleware does, so Hono's middleware doesn't run on them; a guard for Git goes",
46
- "// in git.ts's authorize. Every other request goes on to the app. Over HTTP/2, node:http2's",
38
+ "// in git.ts's policy. Every other request goes on to the app. Over HTTP/2, node:http2's",
47
39
  "// createSecureServer takes it too.",
48
40
  "createServer((incoming, outgoing) =>",
49
41
  " mount(incoming, outgoing, () => void listener(incoming, outgoing)),",
@@ -56,13 +48,13 @@ const mountLines = (server, choices) => {
56
48
  `${expressLine(choices)};`
57
49
  ];
58
50
  return [
59
- "const stop = Node.toJobRunner(git.runtime);",
51
+ "const stop = Node.toJobRunner(runtime);",
60
52
  "",
61
53
  "app.addHook('onClose', () => stop());",
62
54
  "",
63
55
  "// Git's URLs, answered before Fastify parses a body, so the body streams to Git and your routes",
64
56
  "// keep their parsers and bodyLimit. The middleware calls its next before it returns, or never.",
65
- `const mount = toNodeMiddleware(${serve}, (url) => ${matcherCall(choices)});`,
57
+ `const mount = toNodeMiddleware(runtime, (url) => ${matcherCall(choices)});`,
66
58
  "",
67
59
  "app.addHook('onRequest', (request, reply, done) => {",
68
60
  " let passed = false;",
@@ -92,7 +84,7 @@ const mountManual = (choices, framework) => {
92
84
  says: says[framework],
93
85
  lines: [
94
86
  ...framework === "hono" ? honoImports : [],
95
- ...imports(choices, "toNodeMiddleware", framework === "hono"),
87
+ ...imports(choices, "toNodeMiddleware"),
96
88
  ...mountLines(framework, choices)
97
89
  ]
98
90
  };
@@ -104,7 +96,7 @@ const mountManual = (choices, framework) => {
104
96
  ...imports(choices, "toNodeHandler, toNodeMiddleware"),
105
97
  ...startLines,
106
98
  "",
107
- `// node:http: createServer(toNodeHandler(${servedBy(choices)})).`,
99
+ "// node:http: createServer(toNodeHandler(runtime)).",
108
100
  `// Express, before express.json(): ${expressLine(choices)}.`
109
101
  ]
110
102
  };
@@ -43,7 +43,7 @@ const routeFile = (route, app, module, maxDuration) => {
43
43
  return {
44
44
  path,
45
45
  kind: "whole",
46
- text: lines(`// ${route.says} Written by \`ref0-git init\`.`, ...loaded, handlerLine(`(await import('${importOf(path, module)}')).${route.calls}.fetch(request);`), "", maxDuration !== void 0 && `export const maxDuration = ${maxDuration};\n`, `export { ${route.methods.map((method) => `git as ${method}`).join(", ")} };`, "")
46
+ text: lines(`// ${route.says} Written by \`ref0-git init\`.`, "import { Git } from '@ref0/git';", "", ...loaded, handlerLine(`Git.toFetch((await import('${importOf(path, module)}')).runtime)(request);`), "", maxDuration !== void 0 && `export const maxDuration = ${maxDuration};\n`, `export { ${route.methods.map((method) => `git as ${method}`).join(", ")} };`, "")
47
47
  };
48
48
  };
49
49
  /** A job route on Vercel: `jobs`, the queue's handler, for the queue's message or the cron's call. */
@@ -41,8 +41,11 @@ const readme = (choices) => lines("# The starter", "", "Git, a GitHub-compatible
41
41
  const migrationsOf = (records) => records === "postgres" ? "migrations/postgres/" : "migrations/sql/";
42
42
  /** `src/env.ts` on Node: what the app reads from `.env`, each through `need()`. */
43
43
  const envModule = lines("// What the app reads from `.env`: `npm start` passes it to Node, and `vite dev` reads it.", needHelper(".env").replace("const need =", "export const need ="), "", "/** The secrets `ref0-git init` made, where the app is served, and whether anyone may sign up. */", "export const env = {", " ADMIN_TOKEN: need('ADMIN_TOKEN'),", " SESSION_SECRET: need('SESSION_SECRET'),", " APP_ORIGIN: need('APP_ORIGIN'),", " SIGN_UP: process.env['SIGN_UP'],", " // `off` loads a text's remote images from their own origin, not through the image proxy.", " IMAGE_PROXY: process.env['IMAGE_PROXY'],", " // The header the proxy in front sets with the caller's address, such as `x-real-ip`: set it", " // only when that proxy overwrites the header. Unset, the caller's address is the socket's.", " CLIENT_IP_HEADER: process.env['CLIENT_IP_HEADER'],", " /** In dev only, at least 15 characters: the password the seed signs Pip and Mo up with. */", " DEMO_PASSWORD: process.env['DEMO_PASSWORD'],", "};", "");
44
- /** `server/plugins/jobs.ts`: Git's jobs, started once a process, and stopped when Nitro closes. */
45
- const jobsPlugin = lines("// Starts Git's jobs once this process, as Nitro loads its plugins, and stops them on close.", "import { definePlugin } from 'nitro';", "", "import * as Node from '@ref0/infra/node';", "", "import { git } from '../../src/git.ts';", "", "export default definePlugin((nitro) => {", " const stop = Node.toJobRunner(git.runtime);", " nitro.hooks.hook('close', () => stop());", "});", "");
44
+ /**
45
+ * `server/plugins/jobs.ts`: Git's jobs, started once a process. When Nitro closes, the runner stops,
46
+ * then the runtime is disposed, closing what its Layers opened.
47
+ */
48
+ const jobsPlugin = lines("// Starts Git's jobs once this process, as Nitro loads its plugins. On close, it stops them, then", "// disposes the runtime, so what its Layers opened closes.", "import { definePlugin } from 'nitro';", "", "import * as Node from '@ref0/infra/node';", "", "import { runtime } from '../../src/git.ts';", "", "export default definePlugin((nitro) => {", " const stop = Node.toJobRunner(runtime);", " nitro.hooks.hook('close', async () => {", " await stop();", " await runtime.dispose();", " });", "});", "");
46
49
  /** What `npm run migrate` opens, for each records store, and how it runs one file's SQL. */
47
50
  const migrateParts = {
48
51
  sqlite: lines("import { mkdirSync, readdirSync, readFileSync } from 'node:fs';", "import { DatabaseSync } from 'node:sqlite';", "", "mkdirSync('.data', { recursive: true });", "", "const database = new DatabaseSync('.data/auth.db');", "", "const run = async (sql: string) => {", " database.exec(sql);", "};", "", "/** The file and its record, bound, in one transaction, which a failure rolls back. */", "const apply = async (name: string, sql: string) => {", " database.exec('begin');", "", " try {", " database.exec(sql);", " database.prepare('insert into \"_migrations\" (\"name\") values (?)').run(name);", " database.exec('commit');", " } catch (cause) {", " if (database.isTransaction) database.exec('rollback');", "", " throw cause;", " }", "};", "", "const done = async () => {", " const rows = database.prepare('select \"name\" from \"_migrations\"').all();", "", " return new Set(rows.map((row) => String(row.name)));", "};"),
@@ -1,5 +1,5 @@
1
1
  import { ignoring, lines, withCli, withCreatedTypes, withDependencies, withLines } from "./files.mjs";
2
- import { adminLines, gitDependencies, gitImports, gitPackages, handlerLines, header, mergeLines, serveExport, serverLines } from "./git-module.mjs";
2
+ import { adminLines, effectImports, featuresLines, gitDependencies, gitImports, gitPackages, header, mergeLines, policyLines, runtimeLines } from "./git-module.mjs";
3
3
  import { manifestText, parseJsonc, stringAt, withEntries } from "./jsonc.mjs";
4
4
  import { astroRouteFiles, astroSteps } from "./astro.mjs";
5
5
  import { mountManual } from "./mounts.mjs";
@@ -53,58 +53,47 @@ const storeLines = (choices) => {
53
53
  };
54
54
  /** The bucket, as chosen, after a blank line: none for loose objects. */
55
55
  const bucketLines = (choices) => choices.bucket === "s3" ? `\n${s3Part.code}` : choices.bucket === "disk" && "\nconst bucket = Disk.layer('.data/packs');";
56
- /** Git's comment in the server module, for what runs its jobs. */
56
+ /** The runtime's comment in the server module, on what runs its jobs. */
57
57
  const jobsSays = {
58
- main: "/** Git, whose jobs `src/main.ts` runs in this process. */",
59
- server: "/** Git, whose jobs your server runs in its process. */",
60
- hook: "/** Git, whose jobs the framework's startup hook runs in each server process. */",
61
- "on-import": "/** Git, whose jobs this module starts on its first import. */"
58
+ main: "`src/main.ts` runs its jobs in this process.",
59
+ server: "Your server runs its jobs in its process.",
60
+ hook: "The framework's startup hook runs its jobs in each server process.",
61
+ "on-import": "This module starts its jobs on its first import."
62
62
  };
63
+ /** A push's pack upload, to a bucket that signs parts: S3's. */
64
+ const uploads = lines(" // A push past 64 MiB may upload its pack, once the bucket signs parts.", " Git.layerUploads({ above: 64 * 1024 * 1024 }),");
63
65
  /**
64
66
  * A framework's `.env`, loaded before any `need()`: a Vite dev server gives `process.env` none of
65
67
  * it, and adapter-node's server loads none. A variable the environment sets stays as it is.
66
68
  */
67
69
  const loadEnvLines = lines("// `.env` from the folder the server runs in, `process.cwd()`, as `node --env-file` reads it: a", "// host that runs it from another folder sets the environment itself. A variable already set", "// stays as it is.", "if (existsSync('.env')) process.loadEnvFile('.env');", "");
68
70
  /** The jobs' start on the module's first import, once a process: a dev reload imports it again. */
69
- const startedOnImport = lines("// Started once a process, on this module's first import, after the drop-in joins Git: the", "// runner starts Git's build, which refuses a join. A dev reload imports the module again.", "// SAFETY: only this module sets `gitJobs` on the global, to the stop `toJobRunner` returns.", "const started = globalThis as { gitJobs?: () => Promise<void> };", "", "started.gitJobs ??= Node.toJobRunner(git.runtime);", "");
71
+ const startedOnImport = lines("// Started once a process, on this module's first import. A dev reload imports the module again.", "// SAFETY: only this module sets `gitJobs` on the global, to the stop `toJobRunner` returns.", "const started = globalThis as { gitJobs?: () => Promise<void> };", "", "started.gitJobs ??= Node.toJobRunner(runtime);", "");
70
72
  /**
71
- * The server module, `src/git.ts` or a framework's: the store, the bucket and the queue, then
72
- * Git, its REST and the drop-in, and, but for `src/main.ts`'s, the `serve` its routes call.
73
+ * The server module, `src/git.ts` or a framework's: the store, the bucket and the queue, then Git's
74
+ * features and the drop-in's, and the runtime that its entry, routes or mount take.
73
75
  */
74
76
  const nodeModule = (choices, jobs) => {
75
77
  const packs = choices.objects === "packs";
76
78
  const framework = jobs === "hook" || jobs === "on-import";
77
- return lines(header(choices, "Node"), firstImports(choices, framework), gitImports(choices), infraImports(choices, jobs === "on-import"), "import { xdiff } from '@ref0/xdiff-wasm/node';", "", framework && loadEnvLines, needHelper(".env"), "", adminLines, storeLines(choices), bucketLines(choices), "", mergeLines(choices), jobsSays[jobs], serverLines(choices, {
78
- adapter: ` adapter: ${packs ? "[store, bucket]" : "store"},`,
79
- xdiff: " xdiff: await xdiff(),",
80
- uploads: choices.bucket === "s3",
81
- token: "need('ADMIN_TOKEN')"
82
- }), handlerLines(choices), jobs === "on-import" && startedOnImport, jobs !== "main" && serveExport(choices));
83
- };
84
- /** What the process serves, as `toNodeHandler` takes it. */
85
- const handled = {
86
- github: {
87
- names: "git, github, rest",
88
- handler: "{\n fetch: async (request) => (await github.route(request)) ?? rest.fetch(request),\n}"
89
- },
90
- api: {
91
- names: "git, rest",
92
- handler: "rest"
93
- },
94
- git: {
95
- names: "git",
96
- handler: "git"
97
- }
79
+ return lines(header(choices, "Node"), firstImports(choices, framework), gitImports(choices), infraImports(choices, jobs === "on-import"), "import { xdiff } from '@ref0/xdiff-wasm/node';", effectImports(choices), "", framework && loadEnvLines, needHelper(".env"), "", adminLines, storeLines(choices), bucketLines(choices), "", mergeLines(choices), policyLines, featuresLines(choices, {
80
+ merges: "{ xdiff: await xdiff() }",
81
+ uploads: choices.bucket === "s3" && uploads
82
+ }), runtimeLines(choices, {
83
+ token: "need('ADMIN_TOKEN')",
84
+ adapter: packs ? "Layer.merge(store, bucket)" : "store",
85
+ jobs: jobsSays[jobs]
86
+ }), jobs === "on-import" && startedOnImport);
98
87
  };
99
88
  /** A stop waits this long for the responses still open, such as one a reader stopped reading. */
100
89
  const stopGrace = 1e4;
101
90
  /** The lines in `src/main.ts` that start the jobs and serve Git. */
102
- const serveLines = (choices) => lines("const stop = Node.toJobRunner(git.runtime);", "", `const handler = toNodeHandler(${handled[choices.serve].handler});`);
91
+ const serveLines = lines("const stop = Node.toJobRunner(runtime);", "", "const handler = toNodeHandler(runtime);");
103
92
  /** Where `src/main.ts` serves Git when `PORT` is unset. */
104
93
  const mainOrigin = "http://localhost:8080";
105
94
  const mainPort = new URL(mainOrigin).port;
106
95
  /** `src/main.ts`: Git on `PORT`, its jobs in this process, stopped on `SIGTERM`. */
107
- const mainModule = (choices) => lines(`// Serves Git on PORT, ${mainPort} when unset, and runs its jobs in this process. Written by`, "// `ref0-git init`, and yours to change.", "import { createServer } from 'node:http';", "", "import { toNodeHandler } from '@ref0/git/node';", "import * as Node from '@ref0/infra/node';", "", `import { ${handled[choices.serve].names} } from './git.ts';`, "", serveLines(choices), "", "const server = createServer(handler);", "", "// Node cuts a request off at 300 s, which a large push over a slow link outlasts: an hour.", "server.requestTimeout = 60 * 60 * 1000;", "", `server.listen(Number(process.env.PORT ?? '${mainPort}'));`, "", "process.on('SIGTERM', () => {", " server.close();", " void stop();", "", ` // A response still open after ${stopGrace / 1e3} s, such as to a reader that stopped reading, is cut off.`, ` setTimeout(() => server.closeAllConnections(), ${stopGrace / 1e3} * 1000).unref();`, "});", "");
96
+ const mainModule = () => lines(`// Serves Git on PORT, ${mainPort} when unset, and runs its jobs in this process. Written by`, "// `ref0-git init`, and yours to change.", "import { createServer } from 'node:http';", "", "import { toNodeHandler } from '@ref0/git/node';", "import * as Node from '@ref0/infra/node';", "", "import { runtime } from './git.ts';", "", serveLines, "", "const server = createServer(handler);", "", "// Node cuts a request off at 300 s, which a large push over a slow link outlasts: an hour.", "server.requestTimeout = 60 * 60 * 1000;", "", `server.listen(Number(process.env.PORT ?? '${mainPort}'));`, "", "process.on('SIGTERM', () => {", " server.close();", " void stop();", "", ` // A response still open after ${stopGrace / 1e3} s, such as to a reader that stopped reading, is cut off.`, ` setTimeout(() => server.closeAllConnections(), ${stopGrace / 1e3} * 1000).unref();`, "});", "");
108
97
  /** The packages a Node setup runs with, beside Git's, and the tools it type-checks with. */
109
98
  const dependenciesOf = (choices, vendor) => {
110
99
  const parts = partsOf(choices);
@@ -167,10 +156,10 @@ const instrumentationOf = (framework) => `${framework.appDir === "src/app" ? "sr
167
156
  const registerLines = [
168
157
  "export async function register() {",
169
158
  " if (process.env.NEXT_RUNTIME === 'nodejs') {",
170
- " const { git } = await import('./lib/git');",
159
+ " const { runtime } = await import('./lib/git');",
171
160
  " const Node = await import('@ref0/infra/node');",
172
161
  "",
173
- " Node.toJobRunner(git.runtime);",
162
+ " Node.toJobRunner(runtime);",
174
163
  " }",
175
164
  "}"
176
165
  ];
@@ -425,7 +414,7 @@ const serverNodeOutput = (choices, project, secret, vendor) => {
425
414
  ...own ? [{
426
415
  path: "src/main.ts",
427
416
  kind: "whole",
428
- text: mainModule(choices)
417
+ text: mainModule()
429
418
  }] : [],
430
419
  ...localFiles(choices, secret)
431
420
  ],
@@ -1,5 +1,5 @@
1
1
  import { lines } from "./files.mjs";
2
- import { gitRoutes, pathMatchers } from "./routes.mjs";
2
+ import { pathMatchers, routeImports } from "./routes.mjs";
3
3
  // src/init/nuxt.ts
4
4
  /**
5
5
  * What `init` writes in a Nuxt project on Node, under Nitro's Node preset: one server middleware
@@ -21,10 +21,10 @@ const nuxtJobsPlugin = "server/plugins/git-jobs.ts";
21
21
  /** The plugin's lines, which a step in the person's own file at that path names too. */
22
22
  const pluginLines = (framework) => [
23
23
  "export default defineNitroPlugin(async (nitroApp) => {",
24
- ` const { git } = await import('${importOf(nuxtJobsPlugin, framework.serverModule)}');`,
24
+ ` const { runtime } = await import('${importOf(nuxtJobsPlugin, framework.serverModule)}');`,
25
25
  " const Node = await import('@ref0/infra/node');",
26
26
  "",
27
- " const stop = Node.toJobRunner(git.runtime);",
27
+ " const stop = Node.toJobRunner(runtime);",
28
28
  " nitroApp.hooks.hook('close', () => void stop());",
29
29
  "});"
30
30
  ];
@@ -37,10 +37,9 @@ const nuxtGitMiddleware = "server/middleware/git.ts";
37
37
  * segments resolved, never the raw path Nitro routes by.
38
38
  */
39
39
  const middlewareLines = (choices, framework) => {
40
- const calls = gitRoutes(choices)[0]?.calls ?? "serve";
41
40
  const matcher = pathMatchers[choices.serve];
42
41
  return [
43
- `import { ${matcher.name} } from '${matcher.from}';`,
42
+ ...routeImports(choices),
44
43
  "",
45
44
  "export default defineEventHandler(async (event) => {",
46
45
  " // The URL Git is handed, dot segments resolved, under the Host's origin: an absolute target",
@@ -55,10 +54,10 @@ const middlewareLines = (choices, framework) => {
55
54
  "",
56
55
  " // Loaded on Git's first request. toWebRequest reads a body without backpressure, so a fast",
57
56
  " // push waits in memory while Git reads it.",
58
- ` const { ${calls} } = await import('${importOf(nuxtGitMiddleware, framework.serverModule)}');`,
57
+ ` const { runtime } = await import('${importOf(nuxtGitMiddleware, framework.serverModule)}');`,
59
58
  " url.pathname = path;",
60
59
  "",
61
- ` return ${calls}.fetch(new Request(url, toWebRequest(event)));`,
60
+ " return Git.toFetch(runtime)(new Request(url, toWebRequest(event)));",
62
61
  "});"
63
62
  ];
64
63
  };
@@ -1,5 +1,5 @@
1
1
  import { lines } from "./files.mjs";
2
- import { fileRoutes, matcherImport, routeHandler } from "./routes.mjs";
2
+ import { fileRoutes, routeHandler, routeImports } from "./routes.mjs";
3
3
  // src/init/react-router.ts
4
4
  /**
5
5
  * What `init` writes in a React Router project on Node: a resource route for each route, whose
@@ -35,7 +35,7 @@ const resourceRoute = (choices, route, module) => {
35
35
  return {
36
36
  path,
37
37
  kind: "whole",
38
- text: lines(`// ${route.says} Written by \`ref0-git init\`.`, `import type { Route } from './+types/${file.replace(/\.ts$/, "")}';`, "", matcherImport(choices), "", "// Loaded on the first request, so `react-router build` opens no database and needs no secret.", ...routeHandler(choices, path, module), "", "export const loader = ({ request }: Route.LoaderArgs) => git(request);", "", "export const action = ({ request }: Route.ActionArgs) => git(request);", "")
38
+ text: lines(`// ${route.says} Written by \`ref0-git init\`.`, `import type { Route } from './+types/${file.replace(/\.ts$/, "")}';`, "", ...routeImports(choices), "", "// Loaded on the first request, so `react-router build` opens no database and needs no secret.", ...routeHandler(choices, path, module), "", "export const loader = ({ request }: Route.LoaderArgs) => git(request);", "", "export const action = ({ request }: Route.ActionArgs) => git(request);", "")
39
39
  };
40
40
  };
41
41
  /** React Router's resource routes for `choices`, over `framework`'s server module. */
@@ -8,20 +8,11 @@ const all = [
8
8
  "POST",
9
9
  "PUT"
10
10
  ];
11
- /** The server module's export Git's route calls, and the words for what it serves, by `--serve`. */
11
+ /** The words for what Git's route serves, by `--serve`. */
12
12
  const served = {
13
- github: {
14
- calls: "serve",
15
- says: "the drop-in's links, REST, then Git's protocol and sign-in"
16
- },
17
- api: {
18
- calls: "rest",
19
- says: "REST, then Git's protocol and sign-in"
20
- },
21
- git: {
22
- calls: "git",
23
- says: "Git's protocol and sign-in"
24
- }
13
+ github: "the drop-in's links, REST, then Git's protocol and sign-in",
14
+ api: "REST, then Git's protocol and sign-in",
15
+ git: "Git's protocol and sign-in"
25
16
  };
26
17
  /** Whether `route` is a root `.git` URL, `gh repo clone`'s, rather than one of the drop-in's prefixes. */
27
18
  const rootGit = (route) => route.path.startsWith(":owner/:repo.git/");
@@ -57,8 +48,7 @@ const gitRoutes = (choices) => {
57
48
  const git = {
58
49
  at: base,
59
50
  tail: "rest",
60
- says: `Git's URLs under \`/${base}\`: ${served[choices.serve].says}.`,
61
- calls: served[choices.serve].calls,
51
+ says: `Git's URLs under \`/${base}\`: ${served[choices.serve]}.`,
62
52
  methods: all
63
53
  };
64
54
  if (choices.serve !== "github") return [git];
@@ -66,7 +56,6 @@ const gitRoutes = (choices) => {
66
56
  at: route.path,
67
57
  tail: route.tail,
68
58
  says: dropInSays.get(route.path) ?? "The drop-in's own URL, as GitHub serves it.",
69
- calls: "github",
70
59
  methods: route.methods
71
60
  }))];
72
61
  };
@@ -95,8 +84,6 @@ const matcherBase = (choices) => choices.basePath.replace(/\/$/, "");
95
84
  * drop-in, answers it at, or `undefined` for the app's.
96
85
  */
97
86
  const matcherCall = (choices) => `${pathMatchers[choices.serve].name}(url, '${matcherBase(choices)}')`;
98
- /** The server module's export a mount beside an app hands Git's URLs to, by `--serve`. */
99
- const servedBy = (choices) => served[choices.serve].calls;
100
87
  /**
101
88
  * Git's routes in a framework that routes by its files, Astro or React Router, which have no
102
89
  * rewrite of Next.js's or reroute of SvelteKit's: with `--serve github`, `gh`'s root Git URLs too,
@@ -110,7 +97,6 @@ const fileRoutes = (choices) => {
110
97
  at: ending.path,
111
98
  tail: ending.tail,
112
99
  says: `gh's Git URLs at the root, which Git answers as its own under \`${choices.basePath}\`.`,
113
- calls: "serve",
114
100
  methods: ending.methods
115
101
  }))];
116
102
  };
@@ -138,11 +124,16 @@ const routeHandler = (choices, file, module) => [
138
124
  " if (path === undefined) return new Response(null, { status: 404 });",
139
125
  "",
140
126
  " url.pathname = path;",
141
- ` const { ${servedBy(choices)} } = await import('${importOf(file, module)}');`,
127
+ ` const { runtime } = await import('${importOf(file, module)}');`,
142
128
  "",
143
- ` return ${servedBy(choices)}.fetch(new Request(url, request));`,
129
+ " return Git.toFetch(runtime)(new Request(url, request));",
144
130
  "};"
145
131
  ];
146
132
  /** The matcher's import, for a route file or a mount beside an app. */
147
133
  const matcherImport = (choices) => `import { ${pathMatchers[choices.serve].name} } from '${pathMatchers[choices.serve].from}';`;
148
- export { dropInPrefixes, fileRoutes, gitRoutes, importOf, matcherCall, matcherImport, pathMatchers, rootGitEndings, rootGitPattern, routeHandler, servedBy };
134
+ /**
135
+ * A route file's import lines: Git, whose `toFetch` answers on the module's runtime, and the
136
+ * matcher.
137
+ */
138
+ const routeImports = (choices) => choices.serve === "github" ? ["import { Git } from '@ref0/git';", matcherImport(choices)] : [`import { Git, ${pathMatchers[choices.serve].name} } from '@ref0/git';`];
139
+ export { dropInPrefixes, fileRoutes, gitRoutes, importOf, matcherCall, matcherImport, pathMatchers, rootGitEndings, rootGitPattern, routeHandler, routeImports };
@@ -46,9 +46,10 @@ const s3Part = {
46
46
  const needHelper = (where) => lines(`/** A variable the project sets, in ${where}. */`, "const need = (name: string) => {", " const value = process.env[name];", fitted(" if (value === undefined || value === '')", `throw new Error(\`Set \${name} in ${where}\`);`), "", " return value;", "};");
47
47
  /**
48
48
  * What `.env.example` says above a variable, if anything: Postgres's URL with `sslmode=verify-full`,
49
- * since `pg` then checks the server's certificate and name, which `require` will stop doing in `pg` 9.
49
+ * since `pg` then checks the server's certificate and name, which `require` will stop doing in `pg` 9,
50
+ * and what Turso's Platform API token must be allowed, since a deleted repo's purge deletes its database.
50
51
  */
51
- const noteOf = (name) => name === "DATABASE_URL" && "# Postgres's URL. Over a network, end it ?sslmode=verify-full, so pg checks the server's certificate";
52
+ const noteOf = (name) => name === "DATABASE_URL" && "# Postgres's URL. Over a network, end it ?sslmode=verify-full, so pg checks the server's certificate" || name === "TURSO_API_TOKEN" && "# Turso's Platform API token: it must create and delete the group's databases, as a repo's purge deletes its own";
52
53
  /** `.env.example`: `header`'s comment lines, then each of `variables` with an empty value. */
53
54
  const envExample = (header, variables) => lines(...header.map((line) => `# ${line}`), ...variables.flatMap((name) => [noteOf(name), `${name}=`]), "");
54
55
  /** The variables `parts` read, in order, which the person sets: an Output's `needs`. */
@@ -26,7 +26,7 @@ const svelteRouteFiles = (choices, framework) => gitRoutes(choices).map((route)
26
26
  return {
27
27
  path,
28
28
  kind: "whole",
29
- text: lines(`// ${route.says} Written by \`ref0-git init\`.`, "import type { RequestHandler } from './$types';", "", "// Loaded on the first request, so `vite build`, which loads each route to read its options, opens", "// no database and needs no secret.", "const git: RequestHandler = async ({ request }) => {", ` const { ${route.calls} } = await import('${importOf(path, framework.serverModule)}');`, "", ` return ${route.calls}.fetch(request);`, "};", "", `export { ${route.methods.map((method) => `git as ${method}`).join(", ")} };`, "")
29
+ text: lines(`// ${route.says} Written by \`ref0-git init\`.`, "import { Git } from '@ref0/git';", "", "import type { RequestHandler } from './$types';", "", "// Loaded on the first request, so `vite build`, which loads each route to read its options, opens", "// no database and needs no secret.", "const git: RequestHandler = async ({ request }) => {", ` const { runtime } = await import('${importOf(path, framework.serverModule)}');`, "", " return Git.toFetch(runtime)(request);", "};", "", `export { ${route.methods.map((method) => `git as ${method}`).join(", ")} };`, "")
30
30
  };
31
31
  });
32
32
  /** What the `init` hook names: Kit's type and `building`, which keeps it out of a build. */
@@ -36,10 +36,10 @@ const initLines = (framework) => [
36
36
  "export const init: ServerInit = async () => {",
37
37
  " if (building) return;",
38
38
  "",
39
- ` const { git } = await import('${importOf("src/hooks.server.ts", framework.serverModule)}');`,
39
+ ` const { runtime } = await import('${importOf("src/hooks.server.ts", framework.serverModule)}');`,
40
40
  " const Node = await import('@ref0/infra/node');",
41
41
  "",
42
- " Node.toJobRunner(git.runtime);",
42
+ " Node.toJobRunner(runtime);",
43
43
  "};"
44
44
  ];
45
45
  /** `src/hooks.server.ts`, where the project has none. */
@@ -11,25 +11,28 @@ const templateOf = (names) => Schema.Array(Schema.Union([Schema.String, Schema.S
11
11
  const appGitSlots = [
12
12
  "gitImport",
13
13
  "queueTypes",
14
+ "githubImport",
14
15
  "infraImport",
15
16
  "safety",
16
17
  "bucket",
17
18
  "queueMerge",
18
- "adapter",
19
- "objects",
19
+ "releases",
20
20
  "lfs",
21
21
  "uploads",
22
- "queue"
22
+ "queue",
23
+ "adapter",
24
+ "objects"
23
25
  ];
24
26
  /** The slots of the app's `src/git.ts` on Node: Node's head and parts, the store's and the queue's. */
25
27
  const appGitNodeSlots = [
26
28
  "head",
27
29
  "queueMerge",
28
- "adapter",
29
- "objects",
30
+ "releases",
30
31
  "lfs",
31
32
  "uploads",
32
33
  "queue",
34
+ "adapter",
35
+ "objects",
33
36
  "xdiff",
34
37
  "database",
35
38
  "ipHeader",
@@ -46,6 +49,7 @@ const appWranglerSlots = [
46
49
  "about",
47
50
  "signing",
48
51
  "name",
52
+ "limits",
49
53
  "vars",
50
54
  "bucket",
51
55
  "database"
@@ -55,22 +59,16 @@ const workerGitSlots = [
55
59
  "header",
56
60
  "gitImports",
57
61
  "infraImport",
62
+ "effectImports",
58
63
  "envFile",
59
64
  "safety",
60
65
  "bucket",
61
66
  "merge",
62
- "adapter",
63
- "objects",
64
- "lfs",
65
- "uploads",
66
- "basePath",
67
- "queue",
68
- "events",
69
- "github",
70
- "rest"
67
+ "features",
68
+ "runtime"
71
69
  ];
72
70
  /** The slots of the example Worker's `src/worker.ts`: what it serves. */
73
- const workerEntrySlots = ["names", "exports"];
71
+ const workerEntrySlots = ["gate", "exports"];
74
72
  /** The slots of the example Worker's `src/env.ts`. */
75
73
  const workerEnvSlots = [
76
74
  "types",
@@ -82,6 +80,7 @@ const workerWranglerSlots = [
82
80
  "about",
83
81
  "signing",
84
82
  "name",
83
+ "limits",
85
84
  "bucket",
86
85
  "vars"
87
86
  ];