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.
- package/app/apps/github/README.md +3 -7
- package/app/apps/github/generated/git-rest.ts +17 -20
- package/app/apps/github/src/clients/allowed.ts +7 -9
- package/app/apps/github/src/clients/avatars.ts +5 -3
- package/app/apps/github/src/clients/graphql.ts +12 -2
- package/app/apps/github/src/clients/host-calls.ts +2 -1
- package/app/apps/github/src/clients/transfers.ts +56 -19
- package/app/apps/github/src/components/signin/device-card.tsx +2 -2
- package/app/apps/github/src/context/context.ts +5 -5
- package/app/apps/github/src/context/host.ts +115 -0
- package/app/apps/github/src/ingress.ts +28 -0
- package/app/apps/github/src/policy.ts +113 -78
- package/app/apps/github/src/private-repos.ts +7 -7
- package/app/apps/github/src/pulls/review.ts +2 -1
- package/app/apps/github/src/releases/release-form.tsx +40 -4
- package/app/apps/github/src/releases/releases.ts +148 -22
- package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +9 -2
- package/app/apps/github/src/seed/seed.ts +68 -38
- package/app/apps/github/src/server.ts +28 -11
- package/app/apps/github/src/signin/approval.ts +20 -15
- package/app/apps/github/src/signin/attempts.ts +306 -0
- package/app/apps/github/src/signin/auth.ts +9 -0
- package/app/apps/github/src/signin/device-code.ts +2 -2
- package/app/apps/github/src/signin/device-prompt.ts +6 -6
- package/app/apps/github/src/signin/host-session.ts +30 -18
- package/app/apps/github/src/signin/limits.ts +35 -0
- package/app/pnpm-workspace.yaml +39 -38
- package/dist/cli/events.mjs +10 -13
- package/dist/cli/failure.mjs +4 -10
- package/dist/cli/hosts.mjs +2 -2
- package/dist/cli/queue.mjs +14 -23
- package/dist/cli/repos.mjs +10 -19
- package/dist/cli/resources.mjs +2 -2
- package/dist/cli/setup.mjs +33 -40
- package/dist/cli/sign-in.mjs +4 -4
- package/dist/cli/tokens.mjs +7 -11
- package/dist/cli/vendor.mjs +21 -1
- package/dist/init/app.mjs +45 -23
- package/dist/init/astro.mjs +2 -2
- package/dist/init/cloudflare.mjs +100 -51
- package/dist/init/create.mjs +1 -1
- package/dist/init/detect.mjs +7 -5
- package/dist/init/files.mjs +6 -1
- package/dist/init/git-module.mjs +89 -32
- package/dist/init/metadata.mjs +12 -7
- package/dist/init/mounts.mjs +12 -20
- package/dist/init/next.mjs +1 -1
- package/dist/init/node-app.mjs +5 -2
- package/dist/init/node.mjs +24 -35
- package/dist/init/nuxt.mjs +6 -7
- package/dist/init/react-router.mjs +2 -2
- package/dist/init/routes.mjs +13 -22
- package/dist/init/stores.mjs +3 -2
- package/dist/init/sveltekit.mjs +3 -3
- package/dist/init/template.mjs +14 -15
- package/dist/init/templates.mjs +76 -81
- package/dist/init/vercel.mjs +18 -22
- package/dist/init/versions.mjs +32 -4
- package/package.json +13 -13
package/dist/init/templates.mjs
CHANGED
|
@@ -3,19 +3,23 @@ var templates_default = {
|
|
|
3
3
|
appGit: [
|
|
4
4
|
{
|
|
5
5
|
"slot": "gitImport",
|
|
6
|
-
"text": "import {
|
|
6
|
+
"text": "import {\n Git,\n Lfs,\n Merges,\n MergeQueue,\n Objects,\n RepoRecords,\n Rest,\n SignIn,\n Tokens,\n} from '@ref0/git';"
|
|
7
7
|
},
|
|
8
8
|
"\n",
|
|
9
9
|
{
|
|
10
10
|
"slot": "queueTypes",
|
|
11
11
|
"text": "import type { MergeInput, MergePlan } from '@ref0/git';\n"
|
|
12
12
|
},
|
|
13
|
-
|
|
13
|
+
{
|
|
14
|
+
"slot": "githubImport",
|
|
15
|
+
"text": "import {\n Apps,\n Deployments,\n GitHub,\n Inbox,\n Releases,\n Search,\n Streams,\n Webhooks,\n} from '@ref0/github';"
|
|
16
|
+
},
|
|
17
|
+
"\nimport * as Languages from '@ref0/github/languages';\n",
|
|
14
18
|
{
|
|
15
19
|
"slot": "infraImport",
|
|
16
20
|
"text": "import {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';"
|
|
17
21
|
},
|
|
18
|
-
"\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` ",
|
|
22
|
+
"\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\nimport * as FetchHttpClient from 'effect/http/FetchHttpClient';\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\n\nimport { hostLayer, peopleOver, repoListOn, runOn, tokenCallsOn } from './context/host.ts';\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` ",
|
|
19
23
|
{
|
|
20
24
|
"slot": "safety",
|
|
21
25
|
"text": "binds the objects, the bucket and D1"
|
|
@@ -23,90 +27,98 @@ var templates_default = {
|
|
|
23
27
|
" and sets `APP_ORIGIN`; the\n// secrets come from `wrangler secret put`, or `.dev.vars` locally.\nexport const env = bindings as Env;\n\n",
|
|
24
28
|
{
|
|
25
29
|
"slot": "bucket",
|
|
26
|
-
"text": "const {\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
|
|
30
|
+
"text": "const {\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, the bucket signs parts, and a push's pack past 64 MiB may upload to\n// it in parts, past Workers' 100 MB body.\nconst signed =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? undefined\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\nconst bucket = signed ?? layerR2(env.PACKS);\n\nconst uploads =\n signed === undefined\n ? Layer.empty\n : Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), signed);\n\n"
|
|
27
31
|
},
|
|
28
32
|
{
|
|
29
33
|
"slot": "queueMerge",
|
|
30
34
|
"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
35
|
},
|
|
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(
|
|
36
|
+
"/** 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(repoListOn(run))(prefix, most, host),\n repoName: async (internalId, signal) =>\n (await runtime.runPromise(RepoRecords.record(internalId), { signal }))?.name,\n});\n\n",
|
|
33
37
|
{
|
|
34
38
|
"slot": "adapter",
|
|
35
|
-
"text": "
|
|
39
|
+
"text": "/** The records and job objects, and the bucket. */\nconst adapter = Layer.merge(layer({ records: env.RECORDS, jobs: env.JOBS }), bucket);"
|
|
36
40
|
},
|
|
37
|
-
"\n",
|
|
41
|
+
"\n\n",
|
|
38
42
|
{
|
|
39
43
|
"slot": "objects",
|
|
40
|
-
"text": "
|
|
44
|
+
"text": "/** Git's objects, in packs in the bucket. */\nconst objects = Objects.layer();"
|
|
45
|
+
},
|
|
46
|
+
"\n\n/**\n * Git's features and the drop-in's, over the host's directory: delete a line to turn its feature\n * off (Q832).\n */\nconst features = Layer.mergeAll(\n Inbox.layer(),\n Deployments.layer(),\n",
|
|
47
|
+
{
|
|
48
|
+
"slot": "releases",
|
|
49
|
+
"text": " // A release's assets, in the bucket beside the packs.\n Releases.layer(),\n"
|
|
41
50
|
},
|
|
42
|
-
"
|
|
51
|
+
" // `org:` and `user:` search an owner's repos, its private ones by the policy's hook.\n Search.layer({ readableRepos: policy.readableRepos }),\n // Without it, a repo's `language` and `license` answer null.\n Languages.layer(),\n // A repo's and an org's hooks, each delivery a `fetch`, and GitHub Apps, whose hooks they send.\n // @effect-diagnostics-next-line unstableApiUsage:off\n Layer.provideMerge(Apps.layer(), Webhooks.layer().pipe(Layer.provide(FetchHttpClient.layer))),\n // GitHub's Event Streams over Git's event feeds, which a pull request's page follows.\n Streams.layer(),\n).pipe(\n Layer.provideMerge(GitHub.layer()),\n Layer.provideMerge(peopleOver(policy.people)),\n Layer.provideMerge(\n Layer.mergeAll(\n Rest.layer(),\n",
|
|
43
52
|
{
|
|
44
53
|
"slot": "lfs",
|
|
45
|
-
"text": "
|
|
54
|
+
"text": " // Git LFS, its objects in the bucket beside the packs. An upload through the Worker may use\n // `limits.cpu_ms` from wrangler.jsonc: raise both together.\n Lfs.layer({ cpuMs: 300_000 }),\n"
|
|
46
55
|
},
|
|
47
56
|
{
|
|
48
57
|
"slot": "uploads",
|
|
49
|
-
"text": "
|
|
58
|
+
"text": " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n uploads,\n"
|
|
50
59
|
},
|
|
51
|
-
" auth: appAuth({ adminToken: env.ADMIN_TOKEN, admin, key: sessionKey }),\n authorize: policy.authorize,\n",
|
|
52
60
|
{
|
|
53
61
|
"slot": "queue",
|
|
54
|
-
"text": "
|
|
62
|
+
"text": " // Each repo's `main` has a merge queue, beside the merge button: its protection still takes\n // a direct merge, as GitHub's does on a branch whose rules don't ask for the queue.\n MergeQueue.layer({ target: 'refs/heads/main', keys: 'once', merge: queueMerge }),\n"
|
|
55
63
|
},
|
|
56
|
-
"
|
|
64
|
+
" // The device flow's sign-in for `gh` and `ref0-git login`, which the page decides in the\n // person's session, from the Better Auth below and Git's own `identify`.\n SignIn.layer({\n approvalPage: approvalPage({\n auth: () => auth(),\n sealKey: sessionKey,\n identify: (request): ReturnType<Identify> => run(Git.identify(request)),\n origin: env.APP_ORIGIN,\n }),\n }),\n ),\n ),\n Layer.provideMerge(Tokens.layer()),\n Layer.provideMerge(Merges.layer({ xdiff })),\n);\n\n/**\n * The whole host, one runtime a process: Git and its features over the records, the jobs and the\n * bucket, as the policy decides, with `hostRules` its push rules.\n */\nexport const runtime = ManagedRuntime.make(\n hostLayer(adapter, objects, features, {\n authorize: policy.authorize,\n auth: appAuth({ adminToken: env.ADMIN_TOKEN, admin, key: sessionKey }),\n authorizeGitHub: policy.authorizeGitHub,\n rules: hostRules.map((each) => each.rule),\n }),\n);\n\n/** An Effect on the runtime, answered as a `Result`, as host code reads Git. */\nexport const run = runOn(runtime);\n\n/**\n * Better Auth, made at a request that needs it, not the isolate's start: who signs up and in, in\n * `AUTH_DB`, each session with a Git token of its own. It's kept once a request's check settles.\n */\nexport const auth = readyAuth(() =>\n starterAuth({\n database: env.AUTH_DB,\n secret: env.SESSION_SECRET,\n origin: env.APP_ORIGIN,\n signUp: env.SIGN_UP !== 'closed',\n key: sessionKey,\n tokens: tokenCallsOn(run),\n // Cloudflare's own, which it sets on every request in place of any the caller sent.\n ipHeader: 'cf-connecting-ip',\n ownsRepos: async (login) => {\n const listed = await repoListOn(run)({\n actor: admin,\n prefix: `${login}/`,\n page: { limit: 1 },\n });\n\n return listed.kind !== 'success' || listed.value.items.length > 0;\n },\n }),\n);\n\n/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = toRecordsObject(runtime);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = toJobObject(runtime);\n"
|
|
57
65
|
],
|
|
58
66
|
appGitNode: [
|
|
59
67
|
{
|
|
60
68
|
"slot": "head",
|
|
61
|
-
"text": "import {
|
|
69
|
+
"text": "import {\n Git,\n Lfs,\n Merges,\n MergeQueue,\n Objects,\n RepoRecords,\n Rest,\n SignIn,\n Tokens,\n} from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport {\n Apps,\n Deployments,\n GitHub,\n Inbox,\n Releases,\n Search,\n Streams,\n Webhooks,\n} from '@ref0/github';\nimport * as Languages from '@ref0/github/languages';\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';\nimport * as FetchHttpClient from 'effect/http/FetchHttpClient';\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\n\nimport { hostLayer, peopleOver, repoListOn, runOn, tokenCallsOn } from './context/host.ts';\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, the bucket signs parts, and a push's pack past 64 MiB may upload to\n// it in parts, past Workers' 100 MB body.\nconst signed =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? undefined\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\nconst bucket = signed ?? layerR2(env.PACKS);\n\nconst uploads =\n signed === undefined\n ? Layer.empty\n : Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), signed);\n\n"
|
|
62
70
|
},
|
|
63
71
|
{
|
|
64
72
|
"slot": "queueMerge",
|
|
65
73
|
"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
74
|
},
|
|
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(
|
|
75
|
+
"/** 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(repoListOn(run))(prefix, most, host),\n repoName: async (internalId, signal) =>\n (await runtime.runPromise(RepoRecords.record(internalId), { signal }))?.name,\n});\n\n",
|
|
68
76
|
{
|
|
69
77
|
"slot": "adapter",
|
|
70
|
-
"text": "
|
|
78
|
+
"text": "/** The records and job objects, and the bucket. */\nconst adapter = Layer.merge(layer({ records: env.RECORDS, jobs: env.JOBS }), bucket);"
|
|
71
79
|
},
|
|
72
|
-
"\n",
|
|
80
|
+
"\n\n",
|
|
73
81
|
{
|
|
74
82
|
"slot": "objects",
|
|
75
|
-
"text": "
|
|
83
|
+
"text": "/** Git's objects, in packs in the bucket. */\nconst objects = Objects.layer();"
|
|
76
84
|
},
|
|
77
|
-
"\n",
|
|
85
|
+
"\n\n/**\n * Git's features and the drop-in's, over the host's directory: delete a line to turn its feature\n * off (Q832).\n */\nconst features = Layer.mergeAll(\n Inbox.layer(),\n Deployments.layer(),\n",
|
|
78
86
|
{
|
|
79
|
-
"slot": "
|
|
80
|
-
"text": "
|
|
87
|
+
"slot": "releases",
|
|
88
|
+
"text": " // A release's assets, in the bucket beside the packs.\n Releases.layer(),\n"
|
|
81
89
|
},
|
|
82
|
-
"
|
|
90
|
+
" // `org:` and `user:` search an owner's repos, its private ones by the policy's hook.\n Search.layer({ readableRepos: policy.readableRepos }),\n // Without it, a repo's `language` and `license` answer null.\n Languages.layer(),\n // A repo's and an org's hooks, each delivery a `fetch`, and GitHub Apps, whose hooks they send.\n // @effect-diagnostics-next-line unstableApiUsage:off\n Layer.provideMerge(Apps.layer(), Webhooks.layer().pipe(Layer.provide(FetchHttpClient.layer))),\n // GitHub's Event Streams over Git's event feeds, which a pull request's page follows.\n Streams.layer(),\n).pipe(\n Layer.provideMerge(GitHub.layer()),\n Layer.provideMerge(peopleOver(policy.people)),\n Layer.provideMerge(\n Layer.mergeAll(\n Rest.layer(),\n",
|
|
83
91
|
{
|
|
84
92
|
"slot": "lfs",
|
|
85
|
-
"text": "
|
|
93
|
+
"text": " // Git LFS, its objects in the bucket beside the packs. An upload through the Worker may use\n // `limits.cpu_ms` from wrangler.jsonc: raise both together.\n Lfs.layer({ cpuMs: 300_000 }),\n"
|
|
86
94
|
},
|
|
87
95
|
{
|
|
88
96
|
"slot": "uploads",
|
|
89
|
-
"text": "
|
|
97
|
+
"text": " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n uploads,\n"
|
|
90
98
|
},
|
|
91
|
-
" auth: appAuth({ adminToken: env.ADMIN_TOKEN, admin, key: sessionKey }),\n authorize: policy.authorize,\n",
|
|
92
99
|
{
|
|
93
100
|
"slot": "queue",
|
|
94
|
-
"text": "
|
|
101
|
+
"text": " // Each repo's `main` has a merge queue, beside the merge button: its protection still takes\n // a direct merge, as GitHub's does on a branch whose rules don't ask for the queue.\n MergeQueue.layer({ target: 'refs/heads/main', keys: 'once', merge: queueMerge }),\n"
|
|
95
102
|
},
|
|
96
|
-
"
|
|
103
|
+
" // The device flow's sign-in for `gh` and `ref0-git login`, which the page decides in the\n // person's session, from the Better Auth below and Git's own `identify`.\n SignIn.layer({\n approvalPage: approvalPage({\n auth: () => auth(),\n sealKey: sessionKey,\n identify: (request): ReturnType<Identify> => run(Git.identify(request)),\n origin: env.APP_ORIGIN,\n }),\n }),\n ),\n ),\n Layer.provideMerge(Tokens.layer()),\n",
|
|
104
|
+
{
|
|
105
|
+
"slot": "xdiff",
|
|
106
|
+
"text": " Layer.provideMerge(Merges.layer({ xdiff })),"
|
|
107
|
+
},
|
|
108
|
+
"\n);\n\n/**\n * The whole host, one runtime a process: Git and its features over the records, the jobs and the\n * bucket, as the policy decides, with `hostRules` its push rules.\n */\nexport const runtime = ManagedRuntime.make(\n hostLayer(adapter, objects, features, {\n authorize: policy.authorize,\n auth: appAuth({ adminToken: env.ADMIN_TOKEN, admin, key: sessionKey }),\n authorizeGitHub: policy.authorizeGitHub,\n rules: hostRules.map((each) => each.rule),\n }),\n);\n\n/** An Effect on the runtime, answered as a `Result`, as host code reads Git. */\nexport const run = runOn(runtime);\n\n/**\n * Better Auth, made at a request that needs it, not the isolate's start: who signs up and in, in\n * `AUTH_DB`, each session with a Git token of its own. It's kept once a request's check settles.\n */\nexport const auth = readyAuth(() =>\n starterAuth({\n",
|
|
97
109
|
{
|
|
98
110
|
"slot": "database",
|
|
99
111
|
"text": " database: env.AUTH_DB,"
|
|
100
112
|
},
|
|
101
|
-
"\n secret: env.SESSION_SECRET,\n origin: env.APP_ORIGIN,\n signUp: env.SIGN_UP !== 'closed',\n key: sessionKey,\n tokens,\n",
|
|
113
|
+
"\n secret: env.SESSION_SECRET,\n origin: env.APP_ORIGIN,\n signUp: env.SIGN_UP !== 'closed',\n key: sessionKey,\n tokens: tokenCallsOn(run),\n",
|
|
102
114
|
{
|
|
103
115
|
"slot": "ipHeader",
|
|
104
116
|
"text": " // Cloudflare's own, which it sets on every request in place of any the caller sent.\n ipHeader: 'cf-connecting-ip',\n"
|
|
105
117
|
},
|
|
106
|
-
" ownsRepos: async (login) => {\n const listed = await
|
|
118
|
+
" ownsRepos: async (login) => {\n const listed = await repoListOn(run)({\n actor: admin,\n prefix: `${login}/`,\n page: { limit: 1 },\n });\n\n return listed.kind !== 'success' || listed.value.items.length > 0;\n },\n }),\n);\n",
|
|
107
119
|
{
|
|
108
120
|
"slot": "classes",
|
|
109
|
-
"text": "\n/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = toRecordsObject(
|
|
121
|
+
"text": "\n/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = toRecordsObject(runtime);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = toJobObject(runtime);\n"
|
|
110
122
|
}
|
|
111
123
|
],
|
|
112
124
|
appEnv: [
|
|
@@ -142,7 +154,12 @@ var templates_default = {
|
|
|
142
154
|
"slot": "name",
|
|
143
155
|
"text": " \"name\": \"git-app\","
|
|
144
156
|
},
|
|
145
|
-
"\n \"main\": \"src/server.ts\",\n
|
|
157
|
+
"\n \"main\": \"src/server.ts\",\n",
|
|
158
|
+
{
|
|
159
|
+
"slot": "limits",
|
|
160
|
+
"text": " \"limits\": { \"cpu_ms\": 300000 },"
|
|
161
|
+
},
|
|
162
|
+
"\n \"compatibility_date\": \"2026-11-01\",\n",
|
|
146
163
|
{
|
|
147
164
|
"slot": "vars",
|
|
148
165
|
"text": " \"vars\": { \"APP_ORIGIN\": \"http://localhost:5173\", \"PACKS_BUCKET\": \"git-app-packs\" },"
|
|
@@ -163,7 +180,7 @@ var templates_default = {
|
|
|
163
180
|
"tsconfig.json": "// The app's pages, routes, clients and sign-in: DOM, as a browser runs them, and Start's server\n// functions beside them. The Worker's entry and Git are `tsconfig.worker.json`'s, typed by\n// workers-types with no DOM, and the tests `tsconfig.test.json`'s, in Node. Each file is in the\n// one whose globals it runs with, and the root's `tsconfig.json` references all three.\n{\n \"extends\": \"./tsconfig.base.json\",\n \"compilerOptions\": {\n \"composite\": true,\n \"jsx\": \"react-jsx\",\n \"lib\": [\"ES2023\", \"DOM\", \"DOM.Iterable\"],\n \"tsBuildInfoFile\": \"./node_modules/.cache/tsconfig.tsbuildinfo\",\n \"types\": [\"vite-plus/client\"]\n },\n \"include\": [\"src/**/*.ts\", \"src/**/*.tsx\", \"generated/**/*.ts\"],\n \"exclude\": [\n \"src/**/*.test.ts\",\n \"src/**/testing/**\",\n \"src/seed/**\",\n \"src/server.ts\",\n \"src/git.ts\",\n \"src/policy.ts\",\n \"src/env.ts\",\n \"src/signin/approval.ts\",\n \"src/camo/lookup.ts\",\n \"src/camo/node.ts\",\n \"src/markdown/words-plugin.ts\"\n ]\n}\n",
|
|
164
181
|
"tsconfig.worker.json": "// The Worker, typed as Cloudflare types one: workers-types' globals and no DOM, so `Request` and\n// `Response` are a Worker's. The pages are `tsconfig.app.json`'s, and the files both run, sealing\n// and names, are in each.\n{\n \"extends\": \"./tsconfig.base.json\",\n \"compilerOptions\": {\n \"composite\": true,\n \"lib\": [\"ES2023\"],\n \"tsBuildInfoFile\": \"./node_modules/.cache/tsconfig.worker.tsbuildinfo\",\n \"types\": [\"@cloudflare/workers-types\", \"vite-plus/client\"]\n },\n \"include\": [\n \"src/server.ts\",\n \"src/git.ts\",\n \"src/policy.ts\",\n \"src/env.ts\",\n \"src/context/**/*.ts\",\n \"src/names/**/*.ts\",\n \"src/seed/**/*.ts\",\n \"src/signin/approval.ts\",\n \"src/signin/seal.ts\"\n ],\n \"exclude\": [\"src/**/*.test.ts\", \"src/seed/testing/built-app.ts\"]\n}\n"
|
|
165
182
|
},
|
|
166
|
-
nodeServer: "import { Records } from '@ref0/infra';\nimport handler, { createServerEntry } from '@tanstack/react-start/server-entry';\n\nimport { nodeFetch } from './camo/node.ts';\nimport { imageProxy } from './camo/proxy.ts';\nimport type { AppContext } from './context/context.ts';\nimport { auth, directory, env,
|
|
183
|
+
nodeServer: "import { Git } from '@ref0/git';\nimport { Records } from '@ref0/infra';\nimport handler, { createServerEntry } from '@tanstack/react-start/server-entry';\nimport * as Effect from 'effect/Effect';\n\nimport { nodeFetch } from './camo/node.ts';\nimport { imageProxy } from './camo/proxy.ts';\nimport type { AppContext } from './context/context.ts';\nimport { auth, directory, env, pictures, policy, run, runtime, sessionKey } from './git.ts';\nimport { repoListOn, routeOn, tokenCallsOn } from './context/host.ts';\nimport { ingressOf } from './ingress.ts';\nimport { hostRules } from './policy.ts';\nimport { shownRules } from './settings/rules.ts';\nimport { deviceAttemptAnswer, deviceAttemptGate } from './signin/attempts.ts';\nimport { sessionCookieOf, sessionEnder, sessionFrom, sessionIdFrom } from './signin/auth.ts';\nimport { clientIpHeader, withClientIp } from './signin/client-ip.ts';\nimport { withoutHostSession } from './signin/host-session.ts';\n\n/**\n * The device page's attempts (#1962), counted in Git's records, by the address the platform sets\n * and the session Better Auth checks, before Git reads a code.\n */\nconst gate = deviceAttemptGate({\n answer: (who) => runtime.runPromise(deviceAttemptAnswer(who)),\n addressHeader: clientIpHeader,\n session: async (request) => sessionIdFrom(await auth())(request),\n});\n\n/** The front door, then Git's routes, the drop-in's among them, for outside and the app alike. */\nconst { owned, api } = ingressOf({ gate, git: routeOn(runtime) });\n\n/** Git's own calls, as host calls read them. */\nconst git = { repos: { list: repoListOn(run) }, tokens: tokenCallsOn(run) };\n\n/**\n * The image proxy (Q860): a text's remote images load through `/_camo/`, and the pages' CSP loads\n * no other. Without it, and with `IMAGE_PROXY=off`, they load from their own origin.\n */\nconst images = imageProxy({\n secret: env.SESSION_SECRET,\n appOrigin: env.APP_ORIGIN,\n setting: env.IMAGE_PROXY,\n fetch: nodeFetch,\n});\n\n/** The host's push rules, as a repo's settings show them. */\nconst rules = shownRules(hostRules);\n\n/** Whether the dev seed runs: `vite.config.ts` sets it true only under the dev server. */\ndeclare const __DEV_SEED__: boolean;\n\nlet seeding: Promise<void> | undefined;\n\n/**\n * In dev only, the seed, once an isolate, before its first answer: Pip and Mo sign up with\n * `DEMO_PASSWORD` and make the demo org `acme`, a host with no repos gets its repos, and a seed cut\n * off finishes. It signs them up in whatever database `AUTH_DB` points at under the dev server,\n * the local D1 unless the host sets `\"remote\": true` on it, so `.dev.vars.example`'s known\n * `DEMO_PASSWORD` is changed before the dev server points at a remote database.\n */\nconst seeded = () => {\n seeding ??= Promise.all([import('./signin/seed-people.ts'), import('./seed/seed.ts')])\n .then(async ([{ seedPeople }, { seed }]) => {\n if (env.DEMO_PASSWORD === undefined) throw new Error('Set DEMO_PASSWORD in .env');\n\n await seedPeople(await auth(), { origin: env.APP_ORIGIN, password: env.DEMO_PASSWORD });\n\n return seed({\n fetch: api,\n origin: env.APP_ORIGIN,\n adminToken: env.ADMIN_TOKEN,\n // Git's records, on its runtime, keep the seed's progress beside Git's own.\n store: {\n read: (scope, reads) => runtime.runPromise(Records.read(scope, reads)),\n commit: (scope, change) => runtime.runPromise(Records.commit(scope, change)),\n },\n });\n })\n .then(\n () => undefined,\n (cause: unknown) =>\n runtime.runPromise(\n Effect.logError('The seed stopped, and goes on at the next start', cause),\n ),\n );\n\n return seeding;\n};\n\n/** Q8's order: the drop-in, then Git, then the app. A URL one owns never falls through. */\nexport default createServerEntry({\n fetch: images.around(async (incoming) => {\n // A host session is the app's server's to set in this Worker, never a caller's to send\n // (Q520): every route, the APIs, the app and any upgrade, sees the request without one.\n // The caller's address, for the rate limit, set by this server in place of any the caller sent.\n const request = withoutHostSession(withClientIp(incoming, env.CLIENT_IP_HEADER));\n if (__DEV_SEED__) await seeded();\n\n const answered = await owned(request);\n if (answered !== undefined) return answered;\n\n const context: AppContext = {\n api,\n sealKey: await sessionKey,\n // Better Auth is made only for a request that reads it, and checked in that request (#480).\n auth: async (each) => (await auth()).handler(each),\n session: async (each) => sessionFrom(await auth(), sessionKey)(each),\n endSession: async (each) => sessionEnder(await auth())(each),\n sessionCookie: async () => sessionCookieOf(await auth())(),\n identify: (each) => run(Git.identify(each)),\n authorize: policy.authorize,\n authorizeGitHub: policy.authorizeGitHub,\n rules,\n avatars: pictures,\n accounts: directory,\n git,\n images,\n };\n\n return handler.fetch(request, { context });\n }),\n});\n",
|
|
167
184
|
nodeConfigs: { "tsconfig.json": "// The app's pages, routes, clients and sign-in: DOM, as a browser runs them, and Start's server\n// functions beside them. The server and Git are `tsconfig.server.json`'s, typed by\n// Node's types with no DOM, and the tests `tsconfig.test.json`'s, in Node. Each file is in the\n// one whose globals it runs with, and the root's `tsconfig.json` references all three.\n{\n \"extends\": \"./tsconfig.base.json\",\n \"compilerOptions\": {\n \"composite\": true,\n \"jsx\": \"react-jsx\",\n \"lib\": [\"ES2023\", \"DOM\", \"DOM.Iterable\"],\n \"tsBuildInfoFile\": \"./node_modules/.cache/tsconfig.tsbuildinfo\",\n \"types\": [\"vite-plus/client\"]\n },\n \"include\": [\"src/**/*.ts\", \"src/**/*.tsx\", \"generated/**/*.ts\"],\n \"exclude\": [\n \"src/**/*.test.ts\",\n \"src/**/testing/**\",\n \"src/seed/**\",\n \"src/server.ts\",\n \"src/git.ts\",\n \"src/policy.ts\",\n \"src/env.ts\",\n \"src/signin/approval.ts\",\n \"src/camo/lookup.ts\",\n \"src/camo/node.ts\",\n \"src/markdown/words-plugin.ts\"\n ]\n}\n" },
|
|
168
185
|
nodeServerConfig: "// The server, typed as Node runs it: Node's globals and no DOM. The pages are `tsconfig.json`'s,\n// and the files both run, sealing and names, are in each.\n{\n \"extends\": \"./tsconfig.base.json\",\n \"compilerOptions\": {\n \"composite\": true,\n \"lib\": [\"ES2023\"],\n \"tsBuildInfoFile\": \"./node_modules/.cache/tsconfig.server.tsbuildinfo\",\n \"types\": [\"node\", \"vite-plus/client\"]\n },\n \"include\": [\n \"src/server.ts\",\n \"src/camo/lookup.ts\",\n \"src/camo/node.ts\",\n \"server/**/*.ts\",\n \"scripts/**/*.ts\",\n \"src/git.ts\",\n \"src/policy.ts\",\n \"src/env.ts\",\n \"src/context/**/*.ts\",\n \"src/names/**/*.ts\",\n \"src/seed/**/*.ts\",\n \"src/signin/approval.ts\",\n \"src/signin/seal.ts\"\n ],\n \"exclude\": [\"src/**/*.test.ts\", \"src/seed/testing/built-app.ts\"]\n}\n",
|
|
169
186
|
nodeVite: "import tailwindcss from '@tailwindcss/vite';\nimport { tanstackStart } from '@tanstack/react-start/plugin/vite';\nimport viteReact from '@vitejs/plugin-react';\nimport { nitro } from 'nitro/vite';\nimport { defineConfig } from 'vite-plus';\n\nimport { wordsMemoryMax } from './src/markdown/words-plugin.ts';\n\n// Start's server build runs in Node through Nitro, which scans `server/` for the jobs' plugin.\nexport default defineConfig(({ command }) => ({\n // The dev seed is on only under the dev server, `vp dev`: every build drops it and its imports,\n // whatever its mode or `NODE_ENV`.\n define: { __DEV_SEED__: JSON.stringify(command === 'serve') },\n // The diff and highlight Workers are modules: `@pierre/diffs`' loads its highlighter lazily.\n worker: { format: 'es' },\n plugins: [\n // Words' WebAssembly under the drop-in's most on its memory (#1098): in Node, the module is\n // compiled at load from words' own bytes, edited.\n wordsMemoryMax(),\n tanstackStart({\n // NodeNext, as the repo types it, resolves only imports that name their extension.\n router: { generatedRouteTree: '../generated/routeTree.gen.ts', addExtensions: true },\n }),\n nitro({ serverDir: './server' }),\n viteReact(),\n tailwindcss(),\n ],\n}));\n",
|
|
@@ -174,13 +191,18 @@ var templates_default = {
|
|
|
174
191
|
},
|
|
175
192
|
{
|
|
176
193
|
"slot": "gitImports",
|
|
177
|
-
"text": "import {
|
|
194
|
+
"text": "import { Auth, Git, Lfs, MergeQueue, Merges, Objects, Policy, Rest, Tokens } from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\n"
|
|
178
195
|
},
|
|
179
196
|
{
|
|
180
197
|
"slot": "infraImport",
|
|
181
198
|
"text": "import {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';"
|
|
182
199
|
},
|
|
183
|
-
"\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\n
|
|
200
|
+
"\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\n",
|
|
201
|
+
{
|
|
202
|
+
"slot": "effectImports",
|
|
203
|
+
"text": "import * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\nimport * as Redacted from 'effect/Redacted';\n"
|
|
204
|
+
},
|
|
205
|
+
"\nimport type { Env } from ",
|
|
184
206
|
{
|
|
185
207
|
"slot": "envFile",
|
|
186
208
|
"text": "'./env.ts'"
|
|
@@ -193,65 +215,33 @@ var templates_default = {
|
|
|
193
215
|
", and `ADMIN_TOKEN` is its secret.\nconst env = bindings as Env;\n\n/** Who `ADMIN_TOKEN` signs in as: it makes repos and tokens, and never pushes. */\nconst admin = { id: '_admin' };\n\n",
|
|
194
216
|
{
|
|
195
217
|
"slot": "bucket",
|
|
196
|
-
"text": "const {\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
|
|
218
|
+
"text": "const {\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, the bucket signs parts, and a push's pack past 64 MiB may upload to\n// it in parts, past Workers' 100 MB body.\nconst signed =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? undefined\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\n/** The records and job objects, and the packs' bucket. */\nconst adapter = Layer.merge(\n layer({ records: env.RECORDS, jobs: env.JOBS }),\n signed ?? layerR2(env.PACKS),\n);\n\n"
|
|
197
219
|
},
|
|
198
220
|
{
|
|
199
221
|
"slot": "merge",
|
|
200
222
|
"text": "/** How the queue writes an entry onto `main`: a merge commit, by whoever added it. */\nconst merge = ({ entry }: MergeInput): MergePlan => ({\n method: 'merge',\n message: `Merge ${entry.source.replace(/^refs\\/heads\\//, '')}\\n`,\n author: {\n name: entry.actor.id,\n email: `${entry.actor.id}@users.noreply.git`,\n at: Date.now(),\n offset: 0,\n },\n});\n\n"
|
|
201
223
|
},
|
|
202
|
-
"
|
|
224
|
+
"/**\n * Who may do what: a visitor signs in first, and the admin makes repos and tokens but never\n * pushes.\n */\nconst policy = Policy.make(({ caller: { actor }, operation }) => {\n if (actor.anonymous === true) return Policy.reject({ message: 'Sign in first' });\n\n if (actor.id === admin.id && operation.kind === 'push') {\n return Policy.reject({\n message: \"The admin token can't push\",\n hint: 'Make a write token for yourself: npx ref0-git tokens create --help',\n });\n }\n\n return Policy.accept();\n});\n\n",
|
|
203
225
|
{
|
|
204
|
-
"slot": "
|
|
205
|
-
"text": "
|
|
226
|
+
"slot": "features",
|
|
227
|
+
"text": "/** Git's features, each a line: delete one to turn it off. */\nconst features = Layer.mergeAll(\n // Git's REST, beside Git's protocol and sign-in.\n Rest.layer(),\n // Git LFS, its objects in the bucket beside the packs. An upload through the Worker may use\n // `limits.cpu_ms` from wrangler.jsonc: raise both together.\n Lfs.layer({ cpuMs: 300_000 }),\n // A push past 64 MiB may upload its pack, once the bucket signs parts.\n signed === undefined\n ? Layer.empty\n : Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), signed),\n MergeQueue.layer({ target: 'refs/heads/main', keys: 'reusable', merge }),\n).pipe(Layer.provideMerge(Tokens.layer()), Layer.provideMerge(Merges.layer({ xdiff })));\n\n"
|
|
206
228
|
},
|
|
207
|
-
"\n",
|
|
208
229
|
{
|
|
209
|
-
"slot": "
|
|
210
|
-
"text": "
|
|
230
|
+
"slot": "runtime",
|
|
231
|
+
"text": "/** The admin's sign-in: `ADMIN_TOKEN`, as a Bearer token or as Basic's password. */\nconst auth = Auth.bearer({ token: Redacted.make(env.ADMIN_TOKEN), actor: admin });\n\n/**\n * The whole host, one runtime that every request and job shares: Git and its features over the\n * adapter, deciding with `policy`, and the admin signing in with `auth`.\n */\nexport const runtime = ManagedRuntime.make(\n Git.layer({}, features).pipe(\n Layer.provide(Policy.layer(policy)),\n Layer.provide(Auth.layer(auth)),\n Layer.provide(Objects.layer()),\n Layer.provideMerge(adapter),\n ),\n);\n\n"
|
|
211
232
|
},
|
|
212
|
-
"\n
|
|
213
|
-
{
|
|
214
|
-
"slot": "lfs",
|
|
215
|
-
"text": " // Git LFS, its objects in the bucket beside the packs.\n lfs: lfs(),\n"
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
"slot": "uploads",
|
|
219
|
-
"text": " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n pushes: { upload: { above: 64 * 1024 * 1024 } },\n"
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
"slot": "basePath",
|
|
223
|
-
"text": ""
|
|
224
|
-
},
|
|
225
|
-
" auth: bearer({ token: env.ADMIN_TOKEN, actor: admin }),\n authorize: ({ actor, operation }) => {\n if (actor.anonymous === true) return reject({ message: 'Sign in first' });\n\n if (actor.id === admin.id && operation.kind === 'push') {\n return reject({\n message: \"The admin token can't push\",\n hint: 'Make a write token for yourself: npx ref0-git tokens create --help',\n });\n }\n\n return accept();\n },\n",
|
|
226
|
-
{
|
|
227
|
-
"slot": "queue",
|
|
228
|
-
"text": " queue: mergeQueue({ target: 'refs/heads/main', keys: 'reusable', merge }),\n"
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
"slot": "events",
|
|
232
|
-
"text": ""
|
|
233
|
-
},
|
|
234
|
-
"});\n\n",
|
|
235
|
-
{
|
|
236
|
-
"slot": "github",
|
|
237
|
-
"text": ""
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
"slot": "rest",
|
|
241
|
-
"text": "/** Git's REST, whose `route` and `fetch` serve Git's protocol and sign-in too. */\nexport const rest = createRestHandler(git);\n\n"
|
|
242
|
-
},
|
|
243
|
-
"/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = toRecordsObject(git.runtime);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = toJobObject(git.runtime);\n"
|
|
233
|
+
"/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = toRecordsObject(runtime);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = toJobObject(runtime);\n"
|
|
244
234
|
],
|
|
245
235
|
workerEntry: [
|
|
246
|
-
"import
|
|
236
|
+
"import { Git } from '@ref0/git';\n\n",
|
|
247
237
|
{
|
|
248
|
-
"slot": "
|
|
249
|
-
"text": "import {
|
|
238
|
+
"slot": "gate",
|
|
239
|
+
"text": "import { deviceAttemptAnswer, deviceAttemptGate } from './device-attempts/attempts.ts';\n"
|
|
250
240
|
},
|
|
251
|
-
"
|
|
241
|
+
"import type { Env } from './env.ts';\nimport { runtime } from './git.ts';\n\nexport { Jobs, Records } from './git.ts';\n\n",
|
|
252
242
|
{
|
|
253
243
|
"slot": "exports",
|
|
254
|
-
"text": "/** Git's
|
|
244
|
+
"text": "/** The device page's front door, which spends an attempt of the caller's Cloudflare address. */\nconst gate = deviceAttemptGate({\n answer: (who) => runtime.runPromise(deviceAttemptAnswer(who)),\n addressHeader: 'cf-connecting-ip',\n});\n\n/** Git's routes: its protocol, sign-in and REST, then a JSON `404`. */\nconst git = Git.toFetch(runtime);\n\n/** The front door, then Git's routes. */\nexport default {\n fetch: async (request) => (await gate(request)) ?? git(request),\n} satisfies ExportedHandler<Env>;\n"
|
|
255
245
|
}
|
|
256
246
|
],
|
|
257
247
|
workerEnv: [
|
|
@@ -287,7 +277,12 @@ var templates_default = {
|
|
|
287
277
|
"slot": "name",
|
|
288
278
|
"text": " \"name\": \"git\","
|
|
289
279
|
},
|
|
290
|
-
"\n \"main\": \"src/worker.ts\",\n
|
|
280
|
+
"\n \"main\": \"src/worker.ts\",\n",
|
|
281
|
+
{
|
|
282
|
+
"slot": "limits",
|
|
283
|
+
"text": " \"limits\": { \"cpu_ms\": 300000 },"
|
|
284
|
+
},
|
|
285
|
+
"\n \"compatibility_date\": \"2026-11-01\",\n \"durable_objects\": {\n \"bindings\": [\n { \"name\": \"RECORDS\", \"class_name\": \"Records\" },\n { \"name\": \"JOBS\", \"class_name\": \"Jobs\" },\n ],\n },\n",
|
|
291
286
|
{
|
|
292
287
|
"slot": "bucket",
|
|
293
288
|
"text": " \"r2_buckets\": [{ \"binding\": \"PACKS\", \"bucket_name\": \"git-packs\" }],\n"
|
|
@@ -352,7 +347,7 @@ var templates_default = {
|
|
|
352
347
|
},
|
|
353
348
|
appYours: [
|
|
354
349
|
["`src/policy.ts`", "Who may read and write what: by default, anyone reads a public repo, a person writes under their own login, an org's members write under its login, and a repo is made only under a login someone holds"],
|
|
355
|
-
["`src/git.ts`", "Git's
|
|
350
|
+
["`src/git.ts`", "Git's features and the drop-in's, a line each: each repo's `main` has a merge queue beside the merge button, and the checks the queue waits on"],
|
|
356
351
|
["`wrangler.jsonc`", "The Worker's name, its two Durable Object classes, its R2 bucket, its D1, `APP_ORIGIN` and `SIGN_UP`"]
|
|
357
352
|
]
|
|
358
353
|
};
|
package/dist/init/vercel.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { gitDependencies, gitPackages,
|
|
1
|
+
import { adminLines, effectImports, featuresLines, gitDependencies, gitImports, gitPackages, mergeLines, policyLines, repoHint, runtimeLines } from "./git-module.mjs";
|
|
2
2
|
import { dropInPrefixes } from "./routes.mjs";
|
|
3
3
|
import { ignoring, lines, listed, served, withCli, withCreatedTypes, withDependencies, withLines } from "./files.mjs";
|
|
4
4
|
import { envExample, needHelper, needsOf, recordsPart, s3Part } from "./stores.mjs";
|
|
@@ -50,40 +50,36 @@ const variablesOf = (choices) => [
|
|
|
50
50
|
...unsetOf(choices)
|
|
51
51
|
];
|
|
52
52
|
/**
|
|
53
|
-
* `src/git.ts` on Vercel: Git
|
|
54
|
-
*
|
|
53
|
+
* `src/git.ts` on Vercel: Git's features and the drop-in's, as chosen, its runtime, and the job
|
|
54
|
+
* queue's handler, which a route of its own takes, in Next.js too.
|
|
55
55
|
*/
|
|
56
56
|
const vercelGitModule = (choices, next) => {
|
|
57
57
|
const jobsRoute = next === void 0 ? routes.jobs : nextJobRoutes(next).jobs;
|
|
58
58
|
const postgres = choices.records === "postgres";
|
|
59
59
|
const blob = choices.bucket === "vercel-blob";
|
|
60
60
|
const { records, bucket } = partsOf(choices);
|
|
61
|
-
const github = choices.serve === "github";
|
|
62
61
|
const queue = choices.queue === "on";
|
|
63
|
-
|
|
64
|
-
return lines(`// Git on Vercel's functions, ${served[choices.serve]}${queue ? ", with a merge queue on `main`" : ""}: records and jobs`, `// in ${postgres ? "Postgres" : "Turso"}, packs in ${blob ? "Vercel Blob" : "S3"}, and jobs woken by Vercel Queues. Written by \`ref0-git init\`, and`, "// yours to change: `init` rewrites it only while it reads as written, and `ref0-git doctor`", "// checks it.", choices.serve === "git" && "// Nothing here makes a repo over HTTP: make one from code, as `git.repos.create({ name: 'acme/app' })`.", ...records.external, "", `import { accept, createGitServer, lfs, ${queue ? "mergeQueue, " : ""}packs, reject } from '@ref0/git';`, queue && "import type { MergeInput, MergePlan } from '@ref0/git';", "import { bearer, tokens } from '@ref0/git/auth';", choices.serve !== "git" && "import { createRestHandler } from '@ref0/git/rest';", github && "import { createGitHubHandler } from '@ref0/github';", ...[
|
|
62
|
+
return lines(`// Git on Vercel's functions, ${served[choices.serve]}${queue ? ", with a merge queue on `main`" : ""}: records and jobs`, `// in ${postgres ? "Postgres" : "Turso"}, packs in ${blob ? "Vercel Blob" : "S3"}, and jobs woken by Vercel Queues. Written by \`ref0-git init\`, and`, "// yours to change: `init` rewrites it only while it reads as written, and `ref0-git doctor`", "// checks it.", choices.serve === "git" && repoHint, ...records.external, "", gitImports(choices), ...[
|
|
65
63
|
records.infra,
|
|
66
64
|
bucket?.infra,
|
|
67
65
|
"import * as Vercel from '@ref0/infra/vercel';"
|
|
68
|
-
].filter(Predicate.isString).toSorted(), "import { xdiff } from '@ref0/xdiff-wasm/node';", "", needHelper("the project's Environment Variables"), "",
|
|
66
|
+
].filter(Predicate.isString).toSorted(), "import { xdiff } from '@ref0/xdiff-wasm/node';", effectImports(choices), "", needHelper("the project's Environment Variables"), "", adminLines, "// Functions don't run between requests: a commit that saves a job sends a queue message, and the", "// cron in `vercel.json` sweeps for any message that was lost.", `const wake = Vercel.layerQueues({ topic: '${topic}' });`, "", records.code, "", lines(bucket === void 0 ? "const bucket = Vercel.layerBlob();" : bucket.code, ""), mergeLines(choices), policyLines, featuresLines(choices, {
|
|
67
|
+
merges: "{ xdiff: await xdiff() }",
|
|
68
|
+
uploads: lines(` // Vercel refuses a body over 4.5 MB, so a larger push uploads its pack to ${blob ? "Blob" : "the bucket"}.`, " Git.layerUploads({ above: 4 * 1024 * 1024 }),")
|
|
69
|
+
}), runtimeLines(choices, {
|
|
70
|
+
token: "need('ADMIN_TOKEN')",
|
|
71
|
+
adapter: "Layer.merge(store, bucket)",
|
|
72
|
+
maxDuration: limitsOf(choices).maxDuration
|
|
73
|
+
}), `/** The job queue's route: \`${jobsRoute}\` runs what its messages and the cron's calls name. */`, "export const jobs = Vercel.toQueueHandler(runtime);", "");
|
|
69
74
|
};
|
|
70
|
-
/** What `api/git.ts` answers
|
|
71
|
-
const
|
|
72
|
-
github:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
api: {
|
|
77
|
-
names: "rest",
|
|
78
|
-
fetch: "/** Git's REST and protocol, then a JSON `404`. */\nconst { fetch } = rest;"
|
|
79
|
-
},
|
|
80
|
-
git: {
|
|
81
|
-
names: "git",
|
|
82
|
-
fetch: "/** Git's protocol and sign-in, then a JSON `404`. */\nconst { fetch } = git;"
|
|
83
|
-
}
|
|
75
|
+
/** What `api/git.ts` answers, for what it serves. */
|
|
76
|
+
const handlerSays = {
|
|
77
|
+
github: "The drop-in's URLs, then Git's REST and protocol, then a JSON `404`.",
|
|
78
|
+
api: "Git's REST and protocol, then a JSON `404`.",
|
|
79
|
+
git: "Git's protocol and sign-in, then a JSON `404`."
|
|
84
80
|
};
|
|
85
81
|
/** `api/git.ts`: every URL but the jobs' routes, by `vercel.json`'s rewrite. */
|
|
86
|
-
const gitRoute = (choices) => lines(
|
|
82
|
+
const gitRoute = (choices) => lines("import { Git } from '@ref0/git';", "", "import { runtime } from '../src/git.ts';", "", `/** ${handlerSays[choices.serve]} */`, "const fetch = Git.toFetch(runtime);", "", "// Every URL but the jobs' routes comes here, by `vercel.json`'s rewrite.", "export {", ...[
|
|
87
83
|
"DELETE",
|
|
88
84
|
"GET",
|
|
89
85
|
"HEAD",
|
package/dist/init/versions.mjs
CHANGED
|
@@ -5,6 +5,17 @@ import { catalog, frameworkPackages, nodeAppPackages, nodePackages, peerPackages
|
|
|
5
5
|
* this release's own, and each other at the catalog's that this release was tested with. They're
|
|
6
6
|
* `metadata.ts`'s, which `scripts/cli-metadata.ts` writes from the manifests and the catalogs.
|
|
7
7
|
*/
|
|
8
|
+
/** What a dry run, which packs nothing, writes for the hash of bytes it never made. */
|
|
9
|
+
const unpacked = "<hash>";
|
|
10
|
+
/**
|
|
11
|
+
* `pnpm pack`'s tarball name with its bytes' hash in it, `ref0-git-0.6.0-<12 hex>.tgz`, from
|
|
12
|
+
* `sha256`, their SHA-256: npm keeps a tarball installed when its name and version are the same,
|
|
13
|
+
* so two checkouts at one version name theirs apart, and a rerun installs its own (#2134).
|
|
14
|
+
*/
|
|
15
|
+
const contentNamed = (file, sha256) => {
|
|
16
|
+
const hash = sha256 === "<hash>" ? unpacked : Array.from(sha256.subarray(0, 6), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
17
|
+
return file.replace(/\.tgz$/u, `-${hash}.tgz`);
|
|
18
|
+
};
|
|
8
19
|
/**
|
|
9
20
|
* How `package.json` names one of Git's packages, or `ref0-git`: at this release, or from the
|
|
10
21
|
* tarball `--from-checkout` packed of it, at the checkout's own version.
|
|
@@ -16,17 +27,34 @@ const specOf = (name, vendor) => {
|
|
|
16
27
|
return `file:${path}`;
|
|
17
28
|
};
|
|
18
29
|
/**
|
|
19
|
-
* The tarball path `--from-checkout` writes for `name` at any version, as `pnpm pack` names it
|
|
20
|
-
* Git's packages in `vendor/`, and `ref0-git` in
|
|
30
|
+
* The tarball path `--from-checkout` writes for `name` at any version, as `pnpm pack` names it,
|
|
31
|
+
* with or without `contentNamed`'s hash: Git's packages in `vendor/`, and `ref0-git` in
|
|
32
|
+
* `vendor/cli/`, since `@ref0/git`'s has its name.
|
|
21
33
|
*/
|
|
22
34
|
const packedPath = (name) => {
|
|
23
35
|
const file = name.replace("@", "").replace("/", "-").replaceAll(".", "\\.");
|
|
24
36
|
return new RegExp(`^file:vendor/${name === "ref0-git" ? "cli/" : ""}${file}-v?\\d[^/]*\\.tgz$`, "u");
|
|
25
37
|
};
|
|
26
38
|
/**
|
|
39
|
+
* A version npm publishes: semver 2.0.0's own, `MAJOR.MINOR.PATCH` with an optional prerelease and
|
|
40
|
+
* build, no leading `v` or `=` and no space, as `semver.valid` takes one without `loose`.
|
|
41
|
+
*/
|
|
42
|
+
const published = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/u;
|
|
43
|
+
/**
|
|
44
|
+
* Whether `at`, a path in the project, is a tarball `--from-checkout` can write for `name`: in its
|
|
45
|
+
* own folder, `pnpm pack`'s name at a version npm publishes, then `contentNamed`'s hash or none.
|
|
46
|
+
* Only those are init's to remove on a rerun. `initWrote` is broader, for a spec it moves, so a
|
|
47
|
+
* file of the person's own named like one, `ref0-git-1-backup.tgz`, isn't init's and stays.
|
|
48
|
+
*/
|
|
49
|
+
const initPacked = (name, at) => {
|
|
50
|
+
const file = name.replace("@", "").replace("/", "-").replaceAll(".", "\\.");
|
|
51
|
+
const version = published.source.slice(1, -1);
|
|
52
|
+
return new RegExp(`^vendor/${name === "ref0-git" ? "cli/" : ""}${file}-${version}(?:-[0-9a-f]{12})?\\.tgz$`, "u").test(at);
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
27
55
|
* Whether `init` wrote `spec` for `name`, one of Git's packages or `ref0-git`, from either source:
|
|
28
56
|
* the release, or the tarball `--from-checkout` names for that package. One it wrote moves to this
|
|
29
57
|
* run's spec; any other is the person's, a tarball of their own in `vendor/` too, and stays.
|
|
30
58
|
*/
|
|
31
|
-
const initWrote = (name, spec) => spec === "0.
|
|
32
|
-
export { catalog, frameworkPackages, initWrote, nodeAppPackages, nodePackages, peerPackages, release, specOf, storePackages, vercelPackages };
|
|
59
|
+
const initWrote = (name, spec) => spec === "0.8.0" || spec !== void 0 && packedPath(name).test(spec);
|
|
60
|
+
export { catalog, contentNamed, frameworkPackages, initPacked, initWrote, nodeAppPackages, nodePackages, peerPackages, published, release, specOf, storePackages, unpacked, vercelPackages };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ref0-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -23,21 +23,21 @@
|
|
|
23
23
|
"./package.json": "./package.json"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@effect/platform-node-shared": "4.1.
|
|
27
|
-
"@ref0/git": "0.
|
|
28
|
-
"@ref0/infra": "0.
|
|
26
|
+
"@effect/platform-node-shared": "4.1.7",
|
|
27
|
+
"@ref0/git": "0.8.0",
|
|
28
|
+
"@ref0/infra": "0.8.0",
|
|
29
29
|
"diff": "9.0.0",
|
|
30
|
-
"effect": "^4.1.
|
|
30
|
+
"effect": "^4.1.7"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@cloudflare/workers-types": "5.
|
|
34
|
-
"@effect/vitest": "4.1.
|
|
33
|
+
"@cloudflare/workers-types": "5.20261123.1",
|
|
34
|
+
"@effect/vitest": "4.1.7",
|
|
35
35
|
"@libsql/client": "0.18.0",
|
|
36
36
|
"@libsql/kysely-libsql": "0.4.1",
|
|
37
|
-
"@ref0/github": "0.
|
|
38
|
-
"@ref0/xdiff-wasm": "0.
|
|
39
|
-
"@tanstack/react-start": "1.169.
|
|
40
|
-
"@types/node": "24.19.
|
|
37
|
+
"@ref0/github": "0.8.0",
|
|
38
|
+
"@ref0/xdiff-wasm": "0.8.0",
|
|
39
|
+
"@tanstack/react-start": "1.169.7",
|
|
40
|
+
"@types/node": "24.19.4",
|
|
41
41
|
"@types/pg": "8.23.1",
|
|
42
42
|
"@types/semver": "7.8.0",
|
|
43
43
|
"@vercel/blob": "2.9.0",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"path-to-regexp": "6.3.0",
|
|
50
50
|
"pg": "8.23.1",
|
|
51
51
|
"semver": "7.8.6",
|
|
52
|
-
"vite-plus": "1.
|
|
53
|
-
"vitest": "5.1.
|
|
52
|
+
"vite-plus": "1.8.0",
|
|
53
|
+
"vitest": "5.1.1"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {}
|
|
56
56
|
}
|