ref0-git 0.3.0 → 0.4.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 (210) hide show
  1. package/app/apps/github/.dev.vars.example +2 -1
  2. package/app/apps/github/generated/git-rest.ts +191 -25
  3. package/app/apps/github/generated/routeTree.gen.ts +21 -0
  4. package/app/apps/github/package.json +1 -1
  5. package/app/apps/github/src/branches/branch-list.tsx +8 -4
  6. package/app/apps/github/src/branches/branches.ts +10 -5
  7. package/app/apps/github/src/camo/addresses.ts +120 -0
  8. package/app/apps/github/src/camo/client.ts +125 -0
  9. package/app/apps/github/src/camo/fetch.ts +201 -0
  10. package/app/apps/github/src/camo/lookup.ts +23 -0
  11. package/app/apps/github/src/camo/node.ts +50 -0
  12. package/app/apps/github/src/camo/proxy.ts +116 -0
  13. package/app/apps/github/src/camo/sign-images.ts +307 -0
  14. package/app/apps/github/src/camo/signing.ts +80 -0
  15. package/app/apps/github/src/clients/allowed.ts +111 -18
  16. package/app/apps/github/src/clients/clients.ts +76 -61
  17. package/app/apps/github/src/clients/transport.ts +13 -0
  18. package/app/apps/github/src/code/code-tree.tsx +3 -1
  19. package/app/apps/github/src/code/file-view.tsx +15 -6
  20. package/app/apps/github/src/code/files.ts +26 -19
  21. package/app/apps/github/src/code/go-to-file.tsx +2 -1
  22. package/app/apps/github/src/code/load.ts +41 -23
  23. package/app/apps/github/src/code/markdown-files.ts +13 -2
  24. package/app/apps/github/src/code/ref-pages.ts +14 -5
  25. package/app/apps/github/src/code/ref-switcher.tsx +4 -3
  26. package/app/apps/github/src/code/refs.ts +42 -8
  27. package/app/apps/github/src/code/repo-home.tsx +6 -2
  28. package/app/apps/github/src/code/repo.ts +12 -6
  29. package/app/apps/github/src/code/saved.ts +5 -3
  30. package/app/apps/github/src/code/trees.ts +11 -9
  31. package/app/apps/github/src/components/markdown/markdown.css +6 -0
  32. package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
  33. package/app/apps/github/src/components/owner-card.tsx +3 -1
  34. package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
  35. package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
  36. package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
  37. package/app/apps/github/src/components/signin/device-card.tsx +9 -2
  38. package/app/apps/github/src/components/user-avatar.tsx +2 -1
  39. package/app/apps/github/src/context/context.ts +13 -0
  40. package/app/apps/github/src/diffs/blobs.ts +37 -14
  41. package/app/apps/github/src/diffs/diff-job.ts +53 -0
  42. package/app/apps/github/src/diffs/diff-worker.ts +6 -0
  43. package/app/apps/github/src/diffs/diffing.ts +136 -0
  44. package/app/apps/github/src/diffs/files.ts +4 -3
  45. package/app/apps/github/src/diffs/hunks.tsx +101 -53
  46. package/app/apps/github/src/diffs/patch.ts +20 -11
  47. package/app/apps/github/src/history/commit-diff.ts +10 -5
  48. package/app/apps/github/src/history/commit-list.tsx +3 -1
  49. package/app/apps/github/src/history/commit-page.tsx +4 -2
  50. package/app/apps/github/src/history/history.ts +12 -10
  51. package/app/apps/github/src/hooks/allowed.ts +9 -9
  52. package/app/apps/github/src/hooks/avatars.ts +3 -3
  53. package/app/apps/github/src/hooks/open-counts.ts +5 -4
  54. package/app/apps/github/src/hooks/profiles.ts +26 -12
  55. package/app/apps/github/src/hooks/repos.ts +78 -25
  56. package/app/apps/github/src/inbox/count.ts +30 -29
  57. package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
  58. package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
  59. package/app/apps/github/src/inbox/marks.ts +26 -15
  60. package/app/apps/github/src/inbox/release-tags.ts +7 -6
  61. package/app/apps/github/src/inbox/subjects.ts +5 -4
  62. package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
  63. package/app/apps/github/src/inbox/subscriptions.ts +95 -35
  64. package/app/apps/github/src/inbox/threads.ts +6 -6
  65. package/app/apps/github/src/issues/changes.ts +40 -16
  66. package/app/apps/github/src/issues/counts.ts +8 -5
  67. package/app/apps/github/src/issues/issue-list.tsx +20 -6
  68. package/app/apps/github/src/issues/issue-page.tsx +30 -14
  69. package/app/apps/github/src/issues/issues.ts +195 -46
  70. package/app/apps/github/src/issues/label-dialog.tsx +8 -11
  71. package/app/apps/github/src/issues/labels-page.tsx +35 -3
  72. package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
  73. package/app/apps/github/src/issues/milestones-page.tsx +269 -0
  74. package/app/apps/github/src/issues/new-issue.tsx +3 -1
  75. package/app/apps/github/src/issues/sidebar.tsx +8 -6
  76. package/app/apps/github/src/markdown/README.md +22 -17
  77. package/app/apps/github/src/markdown/context.ts +83 -10
  78. package/app/apps/github/src/markdown/images.ts +3 -2
  79. package/app/apps/github/src/markdown/lookup.ts +9 -8
  80. package/app/apps/github/src/markdown/page-budget.ts +50 -0
  81. package/app/apps/github/src/markdown/patches.ts +74 -32
  82. package/app/apps/github/src/markdown/query.ts +7 -2
  83. package/app/apps/github/src/markdown/remote.ts +106 -0
  84. package/app/apps/github/src/markdown/render.ts +101 -24
  85. package/app/apps/github/src/markdown/texts.ts +43 -0
  86. package/app/apps/github/src/markdown/words-module.d.ts +5 -0
  87. package/app/apps/github/src/markdown/words-plugin.ts +135 -0
  88. package/app/apps/github/src/names/repos.ts +1 -1
  89. package/app/apps/github/src/palette/palette.tsx +7 -4
  90. package/app/apps/github/src/palette/rows.tsx +54 -33
  91. package/app/apps/github/src/palette/server.ts +5 -5
  92. package/app/apps/github/src/palette/targets.ts +1 -0
  93. package/app/apps/github/src/policy.ts +131 -61
  94. package/app/apps/github/src/private-repos.ts +2 -2
  95. package/app/apps/github/src/pulls/compare-page.tsx +6 -3
  96. package/app/apps/github/src/pulls/files-tab.tsx +480 -214
  97. package/app/apps/github/src/pulls/held-summary.ts +178 -0
  98. package/app/apps/github/src/pulls/live.ts +6 -4
  99. package/app/apps/github/src/pulls/merge-box.tsx +17 -10
  100. package/app/apps/github/src/pulls/pull-list.tsx +6 -3
  101. package/app/apps/github/src/pulls/pull-page.tsx +19 -10
  102. package/app/apps/github/src/pulls/pull.ts +68 -40
  103. package/app/apps/github/src/pulls/pulls.ts +39 -22
  104. package/app/apps/github/src/pulls/review-drafts.ts +131 -0
  105. package/app/apps/github/src/pulls/review.ts +374 -99
  106. package/app/apps/github/src/pulls/threads.tsx +152 -0
  107. package/app/apps/github/src/queue/queue-page.tsx +15 -8
  108. package/app/apps/github/src/queue/queue.ts +35 -20
  109. package/app/apps/github/src/releases/latest-release.tsx +3 -1
  110. package/app/apps/github/src/releases/overview.tsx +4 -2
  111. package/app/apps/github/src/releases/release-form.tsx +8 -5
  112. package/app/apps/github/src/releases/release-list.tsx +8 -5
  113. package/app/apps/github/src/releases/release-view.tsx +1 -0
  114. package/app/apps/github/src/releases/releases.ts +33 -23
  115. package/app/apps/github/src/releases/tag-list.tsx +3 -1
  116. package/app/apps/github/src/router.tsx +5 -2
  117. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
  118. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
  119. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
  120. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
  121. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
  122. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
  123. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
  124. package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
  125. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
  126. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
  127. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
  128. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
  129. package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
  130. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
  131. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
  132. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
  133. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
  134. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
  135. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
  136. package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
  137. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
  138. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
  139. package/app/apps/github/src/routes/-nav.tsx +10 -2
  140. package/app/apps/github/src/routes/-root-testing.ts +29 -6
  141. package/app/apps/github/src/routes/__root.tsx +9 -4
  142. package/app/apps/github/src/routes/index.tsx +3 -1
  143. package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
  144. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
  145. package/app/apps/github/src/seed/acme.ts +1 -1
  146. package/app/apps/github/src/seed/seed.ts +199 -110
  147. package/app/apps/github/src/server.ts +24 -15
  148. package/app/apps/github/src/settings/account-avatar.tsx +4 -1
  149. package/app/apps/github/src/settings/general-settings.tsx +3 -1
  150. package/app/apps/github/src/settings/general.ts +4 -4
  151. package/app/apps/github/src/settings/hook-form.tsx +3 -1
  152. package/app/apps/github/src/settings/hook-list.tsx +5 -2
  153. package/app/apps/github/src/settings/hooks.ts +7 -7
  154. package/app/apps/github/src/settings/org-settings.tsx +3 -1
  155. package/app/apps/github/src/settings/orgs.ts +21 -11
  156. package/app/apps/github/src/settings/settings-layout.tsx +3 -1
  157. package/app/apps/github/src/signin/approval.ts +4 -3
  158. package/app/apps/github/src/signin/auth.ts +9 -2
  159. package/app/apps/github/src/signin/device-code.ts +8 -3
  160. package/app/apps/github/src/signin/device-prompt.ts +28 -3
  161. package/app/apps/github/src/signin/revoke.ts +36 -0
  162. package/app/apps/github/tsconfig.json +4 -1
  163. package/app/apps/github/vite.config.ts +8 -0
  164. package/app/pnpm-workspace.yaml +9 -5
  165. package/app/tsconfig.base.json +1 -0
  166. package/dist/cli/child.mjs +1 -1
  167. package/dist/cli/credentials.mjs +4 -4
  168. package/dist/cli/documents.mjs +32 -22
  169. package/dist/cli/events.mjs +1 -1
  170. package/dist/cli/failure.mjs +20 -7
  171. package/dist/cli/folders.mjs +2 -2
  172. package/dist/cli/git-remote-ref0.mjs +47 -22
  173. package/dist/cli/git.mjs +1 -1
  174. package/dist/cli/helpers.mjs +2 -2
  175. package/dist/cli/hosts.mjs +3 -3
  176. package/dist/cli/output.mjs +2 -2
  177. package/dist/cli/prompt.mjs +1 -1
  178. package/dist/cli/queue.mjs +7 -7
  179. package/dist/cli/ref0-git.mjs +2 -2
  180. package/dist/cli/repos.mjs +35 -18
  181. package/dist/cli/resources.mjs +5 -5
  182. package/dist/cli/retry-after.mjs +8 -0
  183. package/dist/cli/setup.mjs +172 -66
  184. package/dist/cli/sign-in.mjs +65 -23
  185. package/dist/cli/sign-ins.mjs +4 -4
  186. package/dist/cli/sqlite.mjs +2 -2
  187. package/dist/cli/tokens.mjs +3 -3
  188. package/dist/cli/vendor.mjs +1 -1
  189. package/dist/init/app.mjs +18 -20
  190. package/dist/init/choices.mjs +1 -1
  191. package/dist/init/cloudflare.mjs +15 -19
  192. package/dist/init/create.mjs +3 -2
  193. package/dist/init/detect.mjs +4 -4
  194. package/dist/init/files.mjs +120 -13
  195. package/dist/init/frameworks.mjs +16 -0
  196. package/dist/init/git-module.mjs +22 -7
  197. package/dist/init/jsonc.mjs +9 -7
  198. package/dist/init/metadata.mjs +9 -3
  199. package/dist/init/mounts.mjs +13 -10
  200. package/dist/init/next.mjs +2 -2
  201. package/dist/init/node-app.mjs +3 -3
  202. package/dist/init/node.mjs +42 -45
  203. package/dist/init/nuxt.mjs +153 -27
  204. package/dist/init/stores.mjs +14 -9
  205. package/dist/init/sveltekit.mjs +4 -2
  206. package/dist/init/template.mjs +9 -6
  207. package/dist/init/templates.mjs +63 -47
  208. package/dist/init/vercel.mjs +37 -37
  209. package/dist/init/versions.mjs +3 -3
  210. package/package.json +6 -5
@@ -3,19 +3,19 @@ var templates_default = {
3
3
  appGit: [
4
4
  {
5
5
  "slot": "gitImport",
6
- "text": "import { createGitServer, mergeQueue, packs } from '@ref0/git';"
6
+ "text": "import { createGitServer, lfs, mergeQueue, packs } 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
- "import { tokens } from '@ref0/git/auth';\nimport { engine } from '@ref0/git/engine';\nimport { createRestHandler } from '@ref0/git/rest';\nimport xdiff from '@ref0/git/xdiff.wasm';\nimport { createGitHubHandler } from '@ref0/github';\n",
13
+ "import { tokens } from '@ref0/git/auth';\nimport { createRestHandler } from '@ref0/git/rest';\nimport { createGitHubHandler } from '@ref0/github';\n",
14
14
  {
15
15
  "slot": "infraImport",
16
- "text": "import { cloudflare, jobObject, r2, recordsObject } from '@ref0/infra/cloudflare';"
16
+ "text": "import {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';"
17
17
  },
18
- "\nimport { layerOf } from '@ref0/infra/promises';\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` ",
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` ",
19
19
  {
20
20
  "slot": "safety",
21
21
  "text": "binds the objects, the bucket and D1"
@@ -23,28 +23,27 @@ var templates_default = {
23
23
  " 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
24
  {
25
25
  "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 uploads to the bucket in parts, past Workers' 100 MB body.\nconst bucket =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? r2(env.PACKS)\n : r2(env.PACKS, {\n signing: { accountId, bucket: env.PACKS_BUCKET, accessKeyId, secretAccessKey },\n });\n\n"
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 uploads to the bucket in parts, past Workers' 100 MB body.\nconst bucket =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? layerR2(env.PACKS)\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\n"
27
27
  },
28
- {
29
- "slot": "adapterAbout",
30
- "text": "/** Git's records, jobs and packs, whose store"
31
- },
32
- " also keeps the local seed's progress. */\nexport const adapter = cloudflare({ records: env.RECORDS, ",
33
- {
34
- "slot": "adapterBucket",
35
- "text": "jobs: env.JOBS, bucket });"
36
- },
37
- "\n\n",
38
28
  {
39
29
  "slot": "queueMerge",
40
30
  "text": "/**\n * How the queue writes an entry's link onto `main`: a merge commit, by the person who added it, as\n * a pull request's merge button writes one, and titled as GitHub titles it for a pull request's\n * entry, keyed `pr-<number>`.\n */\nconst queueMerge = ({ entry }: MergeInput): MergePlan => {\n const [owner = ''] = entry.repo.split('/');\n const branch = entry.source.replace(/^refs\\/heads\\//, '');\n const pull = /^pr-([1-9]\\d*)$/.exec(entry.key)?.[1];\n const title =\n pull === undefined ? `Merge ${branch}` : `Merge pull request #${pull} from ${owner}/${branch}`;\n const login = entry.subject?.id ?? entry.actor.id;\n const hostname = new URL(env.APP_ORIGIN).hostname;\n\n return {\n method: 'merge',\n message: `${title}\\n`,\n author: { name: login, email: `${login}@users.noreply.${hostname}`, at: Date.now(), offset: 0 },\n };\n};\n\n"
41
31
  },
42
- "/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(git)(prefix, most, host),\n});\n\n/** Git, with the device flow's sign-in for `gh` and `ref0-git login`. */\nexport const git = createGitServer({\n adapter: layerOf(adapter),\n",
32
+ "/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(git)(prefix, most, host),\n});\n\n/** Git, with the device flow's sign-in for `gh` and `ref0-git login`. */\nexport const git = createGitServer({\n",
33
+ {
34
+ "slot": "adapter",
35
+ "text": " adapter: [layer({ records: env.RECORDS, jobs: env.JOBS }), bucket],"
36
+ },
37
+ "\n",
43
38
  {
44
39
  "slot": "objects",
45
40
  "text": " objects: packs(),"
46
41
  },
47
- "\n engine: engine({ xdiff }),\n tokens: tokens(),\n",
42
+ "\n xdiff,\n tokens: tokens(),\n",
43
+ {
44
+ "slot": "lfs",
45
+ "text": " // Git LFS, its objects in the bucket beside the packs.\n lfs: lfs(),\n"
46
+ },
48
47
  {
49
48
  "slot": "uploads",
50
49
  "text": " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n pushes: { upload: { above: 64 * 1024 * 1024 } },\n"
@@ -52,30 +51,39 @@ var templates_default = {
52
51
  " auth: appAuth({ adminToken: env.ADMIN_TOKEN, admin, key: sessionKey }),\n authorize: policy.authorize,\n",
53
52
  {
54
53
  "slot": "queue",
55
- "text": " // Each repo's `main` has a merge queue, beside the merge button: its protection still takes a\n // direct merge, as GitHub's does on a branch whose rules don't ask for the queue.\n queue: mergeQueue({ target: 'refs/heads/main', merge: queueMerge }),\n"
54
+ "text": " // Each repo's `main` has a merge queue, beside the merge button: its protection still takes a\n // direct merge, as GitHub's does on a branch whose rules don't ask for the queue.\n queue: mergeQueue({ target: 'refs/heads/main', keys: 'once', merge: queueMerge }),\n"
56
55
  },
57
- " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),\n rules: { push: hostRules.map((each) => each.rule) },\n // The page decides in the person's session, from the Better Auth below and Git's own `identify`.\n signIn: {\n approvalPage: approvalPage({\n auth: () => auth(),\n sealKey: sessionKey,\n identify: (request): ReturnType<Identify> => git.identify(request),\n origin: env.APP_ORIGIN,\n }),\n },\n});\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 const tokens = git.tokens;\n if (tokens === undefined) throw new Error('Sessions mint Git tokens: pass tokens() to Git');\n\n return 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,\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 git.repos.list({\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/**\n * The drop-in, joined to `git` here, in the tick that made it, with the host's directory, and the\n * owner index, so `org:` and `user:` search an owner's repos, its private ones by the hook.\n */\nexport const github = createGitHubHandler(git, {\n authorize: policy.authorizeGitHub,\n people: policy.people,\n ownerIndex: { readableRepos: policy.readableRepos },\n});\n\n/** Git's REST, whose `route` serves Git's own URLs too: Smart HTTP and sign-in. */\nexport const rest = createRestHandler(git);\n\n/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = recordsObject(adapter);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = jobObject(adapter);\n"
56
+ " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),\n rules: hostRules.map((each) => each.rule),\n // The page decides in the person's session, from the Better Auth below and Git's own `identify`.\n signIn: {\n approvalPage: approvalPage({\n auth: () => auth(),\n sealKey: sessionKey,\n identify: (request): ReturnType<Identify> => git.identify(request),\n origin: env.APP_ORIGIN,\n }),\n },\n});\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 const tokens = git.tokens;\n if (tokens === undefined) throw new Error('Sessions mint Git tokens: pass tokens() to Git');\n\n return 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,\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 git.repos.list({\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/**\n * The drop-in, joined to `git` here, in the tick that made it, with the host's directory, and the\n * owner index, so `org:` and `user:` search an owner's repos, its private ones by the hook.\n */\nexport const github = createGitHubHandler(git, {\n authorize: policy.authorizeGitHub,\n people: policy.people,\n ownerIndex: { readableRepos: policy.readableRepos },\n});\n\n/** Git's REST, whose `route` serves Git's own URLs too: Smart HTTP and sign-in. */\nexport const rest = createRestHandler(git);\n\n/** 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"
58
57
  ],
59
58
  appGitNode: [
60
59
  {
61
60
  "slot": "head",
62
- "text": "import { createGitServer, mergeQueue, packs } from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport { tokens } from '@ref0/git/auth';\nimport { engine } from '@ref0/git/engine';\nimport { createRestHandler } from '@ref0/git/rest';\nimport xdiff from '@ref0/git/xdiff.wasm';\nimport { createGitHubHandler } from '@ref0/github';\nimport { cloudflare, jobObject, r2, recordsObject } from '@ref0/infra/cloudflare';\nimport { layerOf } from '@ref0/infra/promises';\nimport { env as bindings } from 'cloudflare:workers';\n\nimport type { Env } from './env.ts';\nimport { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';\nimport { privateReposOf } from './private-repos.ts';\nimport { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';\nimport { avatars } from './signin/avatars.ts';\nimport { appAuth } from './signin/host-session.ts';\nimport { orgsOver } from './signin/orgs.ts';\nimport { sealKey } from './signin/seal.ts';\n\n// SAFETY: `wrangler.jsonc` binds the objects, the bucket and D1 and sets `APP_ORIGIN`; the\n// secrets come from `wrangler secret put`, or `.dev.vars` locally.\nexport const env = bindings as Env;\n\nconst {\n R2_ACCOUNT_ID: accountId,\n R2_ACCESS_KEY_ID: accessKeyId,\n R2_SECRET_ACCESS_KEY: secretAccessKey,\n} = env;\n\n// With R2's S3 credentials, a push's pack uploads to the bucket in parts, past Workers' 100 MB body.\nconst bucket =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? r2(env.PACKS)\n : r2(env.PACKS, {\n signing: { accountId, bucket: env.PACKS_BUCKET, accessKeyId, secretAccessKey },\n });\n\n/** Git's records, jobs and packs, whose store also keeps the local seed's progress. */\nexport const adapter = cloudflare({ records: env.RECORDS, jobs: env.JOBS, bucket });\n\n"
61
+ "text": "import { createGitServer, lfs, mergeQueue, packs } from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport { tokens } from '@ref0/git/auth';\nimport { createRestHandler } from '@ref0/git/rest';\nimport { createGitHubHandler } from '@ref0/github';\nimport {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\n\nimport type { Env } from './env.ts';\nimport { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';\nimport { privateReposOf } from './private-repos.ts';\nimport { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';\nimport { avatars } from './signin/avatars.ts';\nimport { appAuth } from './signin/host-session.ts';\nimport { orgsOver } from './signin/orgs.ts';\nimport { sealKey } from './signin/seal.ts';\n\n// SAFETY: `wrangler.jsonc` binds the objects, the bucket and D1 and sets `APP_ORIGIN`; the\n// secrets come from `wrangler secret put`, or `.dev.vars` locally.\nexport const env = bindings as Env;\n\nconst {\n R2_ACCOUNT_ID: accountId,\n R2_ACCESS_KEY_ID: accessKeyId,\n R2_SECRET_ACCESS_KEY: secretAccessKey,\n} = env;\n\n// With R2's S3 credentials, a push's pack uploads to the bucket in parts, past Workers' 100 MB body.\nconst bucket =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? layerR2(env.PACKS)\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\n"
63
62
  },
64
63
  {
65
64
  "slot": "queueMerge",
66
65
  "text": "/**\n * How the queue writes an entry's link onto `main`: a merge commit, by the person who added it, as\n * a pull request's merge button writes one, and titled as GitHub titles it for a pull request's\n * entry, keyed `pr-<number>`.\n */\nconst queueMerge = ({ entry }: MergeInput): MergePlan => {\n const [owner = ''] = entry.repo.split('/');\n const branch = entry.source.replace(/^refs\\/heads\\//, '');\n const pull = /^pr-([1-9]\\d*)$/.exec(entry.key)?.[1];\n const title =\n pull === undefined ? `Merge ${branch}` : `Merge pull request #${pull} from ${owner}/${branch}`;\n const login = entry.subject?.id ?? entry.actor.id;\n const hostname = new URL(env.APP_ORIGIN).hostname;\n\n return {\n method: 'merge',\n message: `${title}\\n`,\n author: { name: login, email: `${login}@users.noreply.${hostname}`, at: Date.now(), offset: 0 },\n };\n};\n\n"
67
66
  },
68
- "/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(git)(prefix, most, host),\n});\n\n/** Git, with the device flow's sign-in for `gh` and `ref0-git login`. */\nexport const git = createGitServer({\n adapter: layerOf(adapter),\n",
67
+ "/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(git)(prefix, most, host),\n});\n\n/** Git, with the device flow's sign-in for `gh` and `ref0-git login`. */\nexport const git = createGitServer({\n",
68
+ {
69
+ "slot": "adapter",
70
+ "text": " adapter: [layer({ records: env.RECORDS, jobs: env.JOBS }), bucket],"
71
+ },
72
+ "\n",
69
73
  {
70
74
  "slot": "objects",
71
75
  "text": " objects: packs(),"
72
76
  },
73
77
  "\n",
74
78
  {
75
- "slot": "engine",
76
- "text": " engine: engine({ xdiff }),"
79
+ "slot": "xdiff",
80
+ "text": " xdiff,"
77
81
  },
78
82
  "\n tokens: tokens(),\n",
83
+ {
84
+ "slot": "lfs",
85
+ "text": " // Git LFS, its objects in the bucket beside the packs.\n lfs: lfs(),\n"
86
+ },
79
87
  {
80
88
  "slot": "uploads",
81
89
  "text": " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n pushes: { upload: { above: 64 * 1024 * 1024 } },\n"
@@ -83,9 +91,9 @@ var templates_default = {
83
91
  " auth: appAuth({ adminToken: env.ADMIN_TOKEN, admin, key: sessionKey }),\n authorize: policy.authorize,\n",
84
92
  {
85
93
  "slot": "queue",
86
- "text": " // Each repo's `main` has a merge queue, beside the merge button: its protection still takes a\n // direct merge, as GitHub's does on a branch whose rules don't ask for the queue.\n queue: mergeQueue({ target: 'refs/heads/main', merge: queueMerge }),\n"
94
+ "text": " // Each repo's `main` has a merge queue, beside the merge button: its protection still takes a\n // direct merge, as GitHub's does on a branch whose rules don't ask for the queue.\n queue: mergeQueue({ target: 'refs/heads/main', keys: 'once', merge: queueMerge }),\n"
87
95
  },
88
- " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),\n rules: { push: hostRules.map((each) => each.rule) },\n // The page decides in the person's session, from the Better Auth below and Git's own `identify`.\n signIn: {\n approvalPage: approvalPage({\n auth: () => auth(),\n sealKey: sessionKey,\n identify: (request): ReturnType<Identify> => git.identify(request),\n origin: env.APP_ORIGIN,\n }),\n },\n});\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 const tokens = git.tokens;\n if (tokens === undefined) throw new Error('Sessions mint Git tokens: pass tokens() to Git');\n\n return starterAuth({\n",
96
+ " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),\n rules: hostRules.map((each) => each.rule),\n // The page decides in the person's session, from the Better Auth below and Git's own `identify`.\n signIn: {\n approvalPage: approvalPage({\n auth: () => auth(),\n sealKey: sessionKey,\n identify: (request): ReturnType<Identify> => git.identify(request),\n origin: env.APP_ORIGIN,\n }),\n },\n});\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 const tokens = git.tokens;\n if (tokens === undefined) throw new Error('Sessions mint Git tokens: pass tokens() to Git');\n\n return starterAuth({\n",
89
97
  {
90
98
  "slot": "database",
91
99
  "text": " database: env.AUTH_DB,"
@@ -98,7 +106,7 @@ var templates_default = {
98
106
  " ownsRepos: async (login) => {\n const listed = await git.repos.list({\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/**\n * The drop-in, joined to `git` here, in the tick that made it, with the host's directory, and the\n * owner index, so `org:` and `user:` search an owner's repos, its private ones by the hook.\n */\nexport const github = createGitHubHandler(git, {\n authorize: policy.authorizeGitHub,\n people: policy.people,\n ownerIndex: { readableRepos: policy.readableRepos },\n});\n\n/** Git's REST, whose `route` serves Git's own URLs too: Smart HTTP and sign-in. */\nexport const rest = createRestHandler(git);\n",
99
107
  {
100
108
  "slot": "classes",
101
- "text": "\n/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = recordsObject(adapter);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = jobObject(adapter);\n"
109
+ "text": "\n/** 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"
102
110
  }
103
111
  ],
104
112
  appEnv: [
@@ -111,7 +119,7 @@ var templates_default = {
111
119
  "slot": "bucket",
112
120
  "text": " /** The packs' bucket, and its name, which a signed link names. */\n readonly PACKS: R2Bucket;\n readonly PACKS_BUCKET: string;\n"
113
121
  },
114
- " /** People and their sessions: Better Auth's tables, which `migrations/sql/` makes. */\n readonly AUTH_DB: D1Database;\n /** Signs in as the admin, who makes repos and tokens and never pushes, and vouches at sign-in. */\n readonly ADMIN_TOKEN: string;\n /** At least 32 characters: what signs Better Auth's cookie, and seals each session's Git token. */\n readonly SESSION_SECRET: string;\n /** Where the app is served, such as `https://git.example.com`: Better Auth takes POSTs from it. */\n readonly APP_ORIGIN: string;\n /** `closed` turns sign-up off, so only the people already signed up sign in. Open when unset. */\n readonly SIGN_UP?: string;\n",
122
+ " /** People and their sessions: Better Auth's tables, which `migrations/sql/` makes. */\n readonly AUTH_DB: D1Database;\n /** Signs in as the admin, who makes repos and tokens and never pushes, and vouches at sign-in. */\n readonly ADMIN_TOKEN: string;\n /** At least 32 characters: what signs Better Auth's cookie, and seals each session's Git token. */\n readonly SESSION_SECRET: string;\n /** Where the app is served, such as `https://git.example.com`: Better Auth takes POSTs from it. */\n readonly APP_ORIGIN: string;\n /** `closed` turns sign-up off, so only the people already signed up sign in. Open when unset. */\n readonly SIGN_UP?: string;\n /** `off` turns the image proxy off, so a text's remote images load from their own origin (Q860). */\n readonly IMAGE_PROXY?: string;\n",
115
123
  {
116
124
  "slot": "signing",
117
125
  "text": " /** R2's S3 credentials for the packs' bucket: with all three, a large push uploads its pack. */\n readonly R2_ACCOUNT_ID?: string;\n readonly R2_ACCESS_KEY_ID?: string;\n readonly R2_SECRET_ACCESS_KEY?: string;\n"
@@ -152,13 +160,13 @@ var templates_default = {
152
160
  "\n ],\n \"migrations\": [{ \"tag\": \"v1\", \"new_sqlite_classes\": [\"Records\", \"Jobs\"] }],\n}\n"
153
161
  ],
154
162
  appConfigs: {
155
- "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 ]\n}\n",
163
+ "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",
156
164
  "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"
157
165
  },
158
- nodeServer: "import handler, { createServerEntry } from '@tanstack/react-start/server-entry';\n\nimport type { AppContext } from './context/context.ts';\nimport {\n adapter,\n auth,\n directory,\n env,\n git,\n github,\n pictures,\n policy,\n rest,\n sessionKey,\n} from './git.ts';\nimport { hostRules } from './policy.ts';\nimport { shownRules } from './settings/rules.ts';\nimport { sessionCookieOf, sessionEnder, sessionFrom } from './signin/auth.ts';\nimport { withClientIp } from './signin/client-ip.ts';\nimport { withoutHostSession } from './signin/host-session.ts';\n\n/** The drop-in's URLs, then Git's Smart HTTP and sign-in, then its REST: a URL one of them owns. */\nconst owned = async (request: Request) =>\n (await github.route(request)) ?? (await git.route(request)) ?? (await rest.route(request));\n\n/** Git's answer for a URL it doesn't own: the app's server calls never reach the app. */\nconst api = async (request: Request) => (await owned(request)) ?? rest.fetch(request);\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 store: adapter.store,\n });\n })\n .then(\n () => undefined,\n (cause: unknown) => console.error('The seed stopped, and goes on at the next start:', cause),\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: 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: git.identify,\n authorize: policy.authorize,\n authorizeGitHub: policy.authorizeGitHub,\n rules,\n avatars: pictures,\n accounts: directory,\n git,\n };\n\n return handler.fetch(request, { context });\n },\n});\n",
159
- 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 ]\n}\n" },
160
- 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 \"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",
161
- 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\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 plugins: [\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",
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, git, github, pictures, policy, rest, sessionKey } from './git.ts';\nimport { hostRules } from './policy.ts';\nimport { shownRules } from './settings/rules.ts';\nimport { sessionCookieOf, sessionEnder, sessionFrom } from './signin/auth.ts';\nimport { withClientIp } from './signin/client-ip.ts';\nimport { withoutHostSession } from './signin/host-session.ts';\n\n/** The drop-in's URLs, then Git's Smart HTTP and sign-in, then its REST: a URL one of them owns. */\nconst owned = async (request: Request) =>\n (await github.route(request)) ?? (await git.route(request)) ?? (await rest.route(request));\n\n/** Git's answer for a URL it doesn't own: the app's server calls never reach the app. */\nconst api = async (request: Request) => (await owned(request)) ?? rest.fetch(request);\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) => git.runtime.runPromise(Records.read(scope, reads)),\n commit: (scope, change) => git.runtime.runPromise(Records.commit(scope, change)),\n },\n });\n })\n .then(\n () => undefined,\n (cause: unknown) => console.error('The seed stopped, and goes on at the next start:', cause),\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: git.identify,\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
+ 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
+ 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
+ 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",
162
170
  workerGit: [
163
171
  {
164
172
  "slot": "header",
@@ -166,13 +174,13 @@ var templates_default = {
166
174
  },
167
175
  {
168
176
  "slot": "gitImports",
169
- "text": "import { accept, createGitServer, mergeQueue, packs, reject } from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport { bearer, tokens } from '@ref0/git/auth';\nimport { engine } from '@ref0/git/engine';\nimport { createRestHandler } from '@ref0/git/rest';\nimport xdiff from '@ref0/git/xdiff.wasm';\n"
177
+ "text": "import { accept, createGitServer, lfs, mergeQueue, packs, reject } from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport { bearer, tokens } from '@ref0/git/auth';\nimport { createRestHandler } from '@ref0/git/rest';\n"
170
178
  },
171
179
  {
172
180
  "slot": "infraImport",
173
- "text": "import { cloudflare, jobObject, r2, recordsObject } from '@ref0/infra/cloudflare';"
181
+ "text": "import {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';"
174
182
  },
175
- "\nimport { layerOf } from '@ref0/infra/promises';\nimport { env as bindings } from 'cloudflare:workers';\n\nimport type { Env } from ",
183
+ "\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\n\nimport type { Env } from ",
176
184
  {
177
185
  "slot": "envFile",
178
186
  "text": "'./env.ts'"
@@ -185,24 +193,27 @@ var templates_default = {
185
193
  ", 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",
186
194
  {
187
195
  "slot": "bucket",
188
- "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 uploads to the bucket in parts, past Workers' 100 MB body.\nconst bucket =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? r2(env.PACKS)\n : r2(env.PACKS, {\n signing: { accountId, bucket: env.PACKS_BUCKET, accessKeyId, secretAccessKey },\n });\n\n"
189
- },
190
- "const adapter = cloudflare({ records: env.RECORDS, ",
191
- {
192
- "slot": "adapterBucket",
193
- "text": "jobs: env.JOBS, 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 uploads to the bucket in parts, past Workers' 100 MB body.\nconst bucket =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? layerR2(env.PACKS)\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\n"
194
197
  },
195
- "\n\n",
196
198
  {
197
199
  "slot": "merge",
198
200
  "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"
199
201
  },
200
- "export const git = createGitServer({\n adapter: layerOf(adapter),\n",
202
+ "export const git = createGitServer({\n",
203
+ {
204
+ "slot": "adapter",
205
+ "text": " adapter: [layer({ records: env.RECORDS, jobs: env.JOBS }), bucket],"
206
+ },
207
+ "\n",
201
208
  {
202
209
  "slot": "objects",
203
210
  "text": " objects: packs(),"
204
211
  },
205
- "\n engine: engine({ xdiff }),\n tokens: tokens(),\n",
212
+ "\n xdiff,\n tokens: tokens(),\n",
213
+ {
214
+ "slot": "lfs",
215
+ "text": " // Git LFS, its objects in the bucket beside the packs.\n lfs: lfs(),\n"
216
+ },
206
217
  {
207
218
  "slot": "uploads",
208
219
  "text": " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n pushes: { upload: { above: 64 * 1024 * 1024 } },\n"
@@ -214,7 +225,7 @@ var templates_default = {
214
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",
215
226
  {
216
227
  "slot": "queue",
217
- "text": " queue: mergeQueue({ target: 'refs/heads/main', merge }),\n"
228
+ "text": " queue: mergeQueue({ target: 'refs/heads/main', keys: 'reusable', merge }),\n"
218
229
  },
219
230
  {
220
231
  "slot": "events",
@@ -229,7 +240,7 @@ var templates_default = {
229
240
  "slot": "rest",
230
241
  "text": "/** Git's REST, whose `route` and `fetch` serve Git's protocol and sign-in too. */\nexport const rest = createRestHandler(git);\n\n"
231
242
  },
232
- "/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = recordsObject(adapter);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = jobObject(adapter);\n"
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
244
  ],
234
245
  workerEntry: [
235
246
  "import type { Env } from './env.ts';\n",
@@ -300,6 +311,7 @@ var templates_default = {
300
311
  ],
301
312
  "optional": [
302
313
  "SIGN_UP",
314
+ "IMAGE_PROXY",
303
315
  "R2_ACCOUNT_ID",
304
316
  "R2_ACCESS_KEY_ID",
305
317
  "R2_SECRET_ACCESS_KEY"
@@ -323,7 +335,11 @@ var templates_default = {
323
335
  "APP_ORIGIN"
324
336
  ],
325
337
  "secrets": ["ADMIN_TOKEN", "SESSION_SECRET"],
326
- "optional": ["SIGN_UP", "CLIENT_IP_HEADER"],
338
+ "optional": [
339
+ "SIGN_UP",
340
+ "IMAGE_PROXY",
341
+ "CLIENT_IP_HEADER"
342
+ ],
327
343
  "dev": ["DEMO_PASSWORD"],
328
344
  "secretFile": ".env",
329
345
  "database": {
@@ -1,11 +1,10 @@
1
- import { serveExport } from "./git-module.mjs";
2
- import { vercelPackages } from "./metadata.mjs";
1
+ import { gitDependencies, gitPackages, lfsLines, queueLine, serveExport } from "./git-module.mjs";
3
2
  import { dropInPrefixes } from "./routes.mjs";
4
- import { ignoring, importLine, lines, served, withCli, withCreatedTypes, withDependencies, withLines } from "./files.mjs";
3
+ import { ignoring, lines, listed, served, withCli, withCreatedTypes, withDependencies, withLines } from "./files.mjs";
5
4
  import { envExample, needHelper, needsOf, recordsPart, s3Part } from "./stores.mjs";
6
- import { inline, insertInto, itemsAt, nodeAt, parseJsonc, stringAt, withEntries } from "./jsonc.mjs";
5
+ import { inline, insertInto, itemsAt, jsonString, manifestText, nodeAt, parseJsonc, stringAt, withEntries } from "./jsonc.mjs";
7
6
  import { nextConfigOutput, nextJobFiles, nextJobRoutes, nextRouteFiles, nextSweepPath } from "./next.mjs";
8
- import { specOf } from "./versions.mjs";
7
+ import { vercelPackages } from "./metadata.mjs";
9
8
  import * as Redacted from "effect/Redacted";
10
9
  import * as Predicate from "effect/Predicate";
11
10
  // src/init/vercel.ts
@@ -62,14 +61,11 @@ const vercelGitModule = (choices, next) => {
62
61
  const github = choices.serve === "github";
63
62
  const queue = choices.queue === "on";
64
63
  const { maxDuration } = limitsOf(choices);
65
- 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({ id: 'acme/app' })`.", ...records.external, "", `import { accept, createGitServer, ${queue ? "mergeQueue, " : ""}packs, reject } from '@ref0/git';`, queue && "import type { MergeInput, MergePlan } from '@ref0/git';", "import { bearer, tokens } from '@ref0/git/auth';", "import { engine } from '@ref0/git/engine';", "import { xdiff } from '@ref0/git/node';", choices.serve !== "git" && "import { createRestHandler } from '@ref0/git/rest';", github && "import { createGitHubHandler } from '@ref0/github';", importLine([
66
- "createJobQueue",
67
- "layerOf",
68
- ...records.infra,
69
- ...bucket?.infra ?? [],
70
- ...blob ? ["vercelBlob"] : [],
71
- "vercelQueues"
72
- ], "@ref0/infra/promises"), "", needHelper("the project's Environment Variables"), "", "/** Who `ADMIN_TOKEN` signs in as: it makes repos and tokens, and never pushes. */", "const admin = { id: '_admin' };", "", "// 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 = vercelQueues({ topic: '${topic}' });`, "", records.code, "", `/** The job queue: \`${jobsRoute}\` runs what its messages and the cron's calls name. */`, "export const jobs = createJobQueue({ store });", "", bucket !== void 0 && lines(bucket.code, ""), queue && lines("/** How the queue writes an entry onto `main`: a merge commit, by whoever added it. */", "const merge = ({ entry }: MergeInput): MergePlan => ({", " method: 'merge',", " message: `Merge ${entry.source.replace(/^refs\\/heads\\//, '')}\\n`,", " author: {", " name: entry.actor.id,", " email: `${entry.actor.id}@users.noreply.git`,", " at: Date.now(),", " offset: 0,", " },", "});", ""), "export const git = createGitServer({", ` adapter: layerOf({ store, bucket: ${blob ? "vercelBlob()" : "bucket"}, jobs }),`, " // The functions' `maxDuration`, from `vercel.json`: a clone that would outrun it ends first, with", " // Git's own message.", ` maxDuration: '${maxDuration} seconds',`, " objects: packs(),", " engine: engine({ xdiff: await xdiff() }),", " tokens: tokens(),", ` // Vercel refuses a body over 4.5 MB, so a larger push uploads its pack to ${blob ? "Blob" : "the bucket"}.`, " pushes: { upload: { above: 4 * 1024 * 1024 } },", choices.basePath !== "/" && ` // Git's URLs, Smart HTTP, sign-in and REST, under this path.\n basePath: '${choices.basePath.replace(/\/$/, "")}',`, " auth: bearer({ token: need('ADMIN_TOKEN'), actor: admin }),", " authorize: ({ actor, operation }) => {", " if (actor.anonymous === true) return reject({ message: 'Sign in first' });", "", " if (actor.id === admin.id && operation.kind === 'push') {", " return reject({", " message: \"The admin token can't push\",", " hint: 'Make a write token for yourself: npx ref0-git tokens create --help',", " });", " }", "", " return accept();", " },", queue && " queue: mergeQueue({ target: 'refs/heads/main', merge }),", github && " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),", "});", "", github && "/** GitHub's REST, GraphQL, webhooks and Event Streams, so `gh` and Octokit work. */\nexport const github = createGitHubHandler(git);\n", choices.serve !== "git" && "/** Git's REST, whose `route` and `fetch` serve Git's protocol and sign-in too. */\nexport const rest = createRestHandler(git);\n", next !== void 0 && serveExport(choices));
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';", ...[
65
+ records.infra,
66
+ bucket?.infra,
67
+ "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"), "", "/** Who `ADMIN_TOKEN` signs in as: it makes repos and tokens, and never pushes. */", "const admin = { id: '_admin' };", "", "// 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, ""), queue && lines("/** How the queue writes an entry onto `main`: a merge commit, by whoever added it. */", "const merge = ({ entry }: MergeInput): MergePlan => ({", " method: 'merge',", " message: `Merge ${entry.source.replace(/^refs\\/heads\\//, '')}\\n`,", " author: {", " name: entry.actor.id,", " email: `${entry.actor.id}@users.noreply.git`,", " at: Date.now(),", " offset: 0,", " },", "});", ""), "export const git = createGitServer({", " adapter: [store, bucket],", " // The functions' `maxDuration`, from `vercel.json`: a clone that would outrun it ends first, with", " // Git's own message.", ` maxDuration: '${maxDuration} seconds',`, " objects: packs(),", " xdiff: await xdiff(),", " tokens: tokens(),", lfsLines, ` // Vercel refuses a body over 4.5 MB, so a larger push uploads its pack to ${blob ? "Blob" : "the bucket"}.`, " pushes: { upload: { above: 4 * 1024 * 1024 } },", choices.basePath !== "/" && ` // Git's URLs, Smart HTTP, sign-in and REST, under this path.\n basePath: '${choices.basePath.replace(/\/$/, "")}',`, " auth: bearer({ token: need('ADMIN_TOKEN'), actor: admin }),", " authorize: ({ actor, operation }) => {", " if (actor.anonymous === true) return reject({ message: 'Sign in first' });", "", " if (actor.id === admin.id && operation.kind === 'push') {", " return reject({", " message: \"The admin token can't push\",", " hint: 'Make a write token for yourself: npx ref0-git tokens create --help',", " });", " }", "", " return accept();", " },", queue && queueLine(github), github && " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),", "});", "", `/** The job queue's route: \`${jobsRoute}\` runs what its messages and the cron's calls name. */`, "export const jobs = Vercel.toQueueHandler(git.runtime);", "", github && "/** GitHub's REST, GraphQL, webhooks and Event Streams, so `gh` and Octokit work. */\nexport const github = createGitHubHandler(git);\n", choices.serve !== "git" && "/** Git's REST, whose `route` and `fetch` serve Git's protocol and sign-in too. */\nexport const rest = createRestHandler(git);\n", next !== void 0 && serveExport(choices));
73
69
  };
74
70
  /** What `api/git.ts` answers each method with, for what it serves. */
75
71
  const handlers = {
@@ -96,9 +92,9 @@ const gitRoute = (choices) => lines(`import { ${handlers[choices.serve].names} }
96
92
  "PUT"
97
93
  ].map((method) => ` fetch as ${method},`), "};", "");
98
94
  /** `api/jobs.ts`: the queue's deliveries, on the function `vercel.json` gives its trigger. */
99
- const jobsRoute = lines("import { jobs } from '../src/git.ts';", "", "/** Vercel Queues' deliveries: `vercel.json` gives this function the trigger, which makes it private. */", "export const POST = async (request: Request) =>", " (await jobs.fetch(request)) ?? new Response(null, { status: 404 });", "");
95
+ const jobsRoute = lines("import { jobs } from '../src/git.ts';", "", "/** Vercel Queues' deliveries: `vercel.json` gives this function the trigger, which makes it private. */", "export const POST = jobs;", "");
100
96
  /** `api/jobs/sweep.ts`: the cron's call. */
101
- const sweepRoute = lines("import { jobs } from '../../src/git.ts';", "", "/** The cron's sweep, refused without `CRON_SECRET`: a message for each scope with work due. */", "export const GET = async (request: Request) =>", " (await jobs.fetch(request)) ?? new Response(null, { status: 404 });", "");
97
+ const sweepRoute = lines("import { jobs } from '../../src/git.ts';", "", "/** The cron's sweep, refused without `CRON_SECRET`: a message for each scope with work due. */", "export const GET = jobs;", "");
102
98
  /**
103
99
  * The files that hold secrets on Vercel: `.env`, which `init` writes, and `.env.local`, which
104
100
  * `vercel env pull` fills. `.gitignore` ends with them, and `init` refuses one Git tracks.
@@ -182,7 +178,7 @@ const withItem = (text, array, match, item, key) => {
182
178
  if (found === void 0) return withEntries(text, [array], [item]);
183
179
  const node = nodeAt(found, [key]);
184
180
  const value = item[key] ?? "";
185
- return node === void 0 ? insertInto(text, found, [`${JSON.stringify(key)}: ${inline(value)}`]) : stringAt(found, [key]) === value ? text : replaced(text, node, value);
181
+ return node === void 0 ? insertInto(text, found, [`${jsonString(key)}: ${inline(value)}`]) : stringAt(found, [key]) === value ? text : replaced(text, node, value);
186
182
  };
187
183
  /**
188
184
  * `text` with Git's rewrite as its `rewrites`, when it has none. A list already there is the
@@ -227,12 +223,14 @@ const mergeVercel = (text, choices, next) => {
227
223
  (from) => withItem(from, "crons", "path", cron, "schedule")
228
224
  ].reduce((from, step) => step(from), text);
229
225
  };
230
- /** Git's packages and the store's and bucket's clients, as `package.json` names them. */
226
+ /** Git's packages, their peers and the store's and bucket's clients, as `package.json` names them. */
231
227
  const dependenciesOf = (choices, vendor) => {
232
228
  const { records, bucket } = partsOf(choices);
233
- const named = [...records.dependencies, ["@ref0/git", specOf("@ref0/git", vendor)]];
234
- if (choices.serve === "github") named.push(["@ref0/github", specOf("@ref0/github", vendor)]);
235
- named.push(["@ref0/infra", specOf("@ref0/infra", vendor)], ...bucket?.dependencies ?? []);
229
+ const named = [
230
+ ...records.dependencies,
231
+ ...gitDependencies(choices, vendor),
232
+ ...bucket?.dependencies ?? []
233
+ ];
236
234
  if (choices.bucket === "vercel-blob") named.push(["@vercel/blob", vercelPackages["@vercel/blob"]]);
237
235
  named.push(["@vercel/queue", vercelPackages["@vercel/queue"]]);
238
236
  return Object.fromEntries(named);
@@ -256,24 +254,30 @@ const mergePackage = (choices, name, vendor) => (current) => {
256
254
  dependencies: dependenciesOf(choices, vendor),
257
255
  devDependencies: devDependenciesOf(choices)
258
256
  };
259
- return withCli(`${JSON.stringify(made, null, 2)}\n`, vendor);
257
+ return withCli(`${manifestText(made)}\n`, vendor);
260
258
  }
261
259
  return withEntries(withCli(withDependencies(current, dependenciesOf(choices, vendor)), vendor), ["devDependencies"], devDependenciesOf(choices));
262
260
  };
263
261
  /**
264
- * The next step's words: each variable set for Production, which the deploy runs, by
265
- * `vercel env add <name> production`, after the Storage tab makes Postgres and Blob. `vercel env
266
- * pull` brings Development's to `.env.local`, which is what `doctor` reads.
262
+ * The next step's words, as docs/deploy/vercel.md's steps: Neon and a private Blob store set their
263
+ * own variables, and Neon's URL takes `sslmode=verify-full`; each other is set for Production,
264
+ * which the deploy runs, and for Development, which `vercel env pull` brings to `.env.local` for
265
+ * `doctor`; and the two secrets `init` made in `.env` for Production only.
267
266
  */
268
267
  const nextOf = (choices) => {
269
- const stores = [choices.records === "postgres" && "Postgres", choices.bucket === "vercel-blob" && "Blob"].filter(Predicate.isString);
270
- const added = [
271
- ...unsetOf(choices),
272
- "ADMIN_TOKEN",
273
- "CRON_SECRET"
274
- ].map((name) => `\`vercel env add ${name} production\``);
275
- const storage = stores.length === 0 ? "" : `Add ${stores.join(" and ")} from the project's Storage tab, then s`;
276
- return `${storage === "" ? "S" : storage}et each variable for Production: ${added.join(", ")}. Link the folder, pull Development's with \`vercel env pull\`, then check it`;
268
+ const postgres = choices.records === "postgres";
269
+ const blob = choices.bucket === "vercel-blob";
270
+ const stores = [postgres && "Neon", blob && "a private Blob store"].filter(Predicate.isString);
271
+ const storeSet = [postgres && "DATABASE_URL", blob && "BLOB_READ_WRITE_TOKEN"].filter(Predicate.isString);
272
+ const both = unsetOf(choices).filter((name) => !storeSet.includes(name));
273
+ const add = (name, environment) => `\`vercel env add ${name} ${environment}\``;
274
+ const said = [
275
+ stores.length > 0 && `Connect ${listed(stores)} to the project, which ${storeSet.length === 1 ? "sets" : "set"} ${listed(storeSet)}`,
276
+ postgres && "change DATABASE_URL's sslmode=require to sslmode=verify-full for Production and Development",
277
+ both.length > 0 && `set ${listed(both)} for Production and Development: ${both.flatMap((name) => [add(name, "production"), add(name, "development")]).join(", ")}`,
278
+ `set ADMIN_TOKEN and CRON_SECRET for Production: ${add("ADMIN_TOKEN", "production")}, ${add("CRON_SECRET", "production")}`
279
+ ].filter(Predicate.isString).join(", then ");
280
+ return `${said.charAt(0).toUpperCase()}${said.slice(1)}. Link the folder, pull Development's with \`vercel env pull\`, then check it`;
277
281
  };
278
282
  /** Everything `init` writes for `choices` on Vercel, with `secret` making each new secret. */
279
283
  const vercelOutput = (choices, project, secret, vendor) => {
@@ -337,11 +341,7 @@ const vercelOutput = (choices, project, secret, vendor) => {
337
341
  }
338
342
  ],
339
343
  manual: [...rewriteSteps(project.vercelJson, choices, next), ...config.manual],
340
- packages: [
341
- "@ref0/git",
342
- ...choices.serve === "github" ? ["@ref0/github"] : [],
343
- "@ref0/infra"
344
- ],
344
+ packages: gitPackages(choices),
345
345
  secret: "ADMIN_TOKEN and CRON_SECRET, made for vercel dev, in .env",
346
346
  needs: unsetOf(choices),
347
347
  next: nextOf(choices)
@@ -1,4 +1,4 @@
1
- import { catalog, frameworkPackages, nodeAppPackages, nodePackages, release, storePackages, vercelPackages } from "./metadata.mjs";
1
+ import { catalog, frameworkPackages, nodeAppPackages, nodePackages, peerPackages, release, storePackages, vercelPackages } from "./metadata.mjs";
2
2
  // src/init/versions.ts
3
3
  /**
4
4
  * The versions `init` writes, pinned exactly, since npm ignores pnpm's lockfile: Git's packages at
@@ -28,5 +28,5 @@ const packedPath = (name) => {
28
28
  * the release, or the tarball `--from-checkout` names for that package. One it wrote moves to this
29
29
  * run's spec; any other is the person's, a tarball of their own in `vendor/` too, and stays.
30
30
  */
31
- const initWrote = (name, spec) => spec === "0.3.0" || spec !== void 0 && packedPath(name).test(spec);
32
- export { catalog, frameworkPackages, initWrote, nodeAppPackages, nodePackages, release, specOf, storePackages, vercelPackages };
31
+ const initWrote = (name, spec) => spec === "0.4.0" || spec !== void 0 && packedPath(name).test(spec);
32
+ export { catalog, frameworkPackages, initWrote, nodeAppPackages, nodePackages, peerPackages, release, specOf, storePackages, vercelPackages };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ref0-git",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "description": "ref0-git, the CLI for a Git host built on @ref0/git, and git-remote-ref0, its remote helper",
6
6
  "license": "Apache-2.0",
@@ -24,17 +24,18 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@effect/platform-node-shared": "4.1.4",
27
- "@ref0/git": "0.3.0",
28
- "@ref0/infra": "0.3.0",
27
+ "@ref0/git": "0.4.0",
28
+ "@ref0/infra": "0.4.0",
29
29
  "diff": "9.0.0",
30
- "effect": "4.1.4"
30
+ "effect": "^4.1.4"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@cloudflare/workers-types": "5.20261116.1",
34
34
  "@effect/vitest": "4.1.4",
35
35
  "@libsql/client": "0.18.0",
36
36
  "@libsql/kysely-libsql": "0.4.1",
37
- "@ref0/github": "0.3.0",
37
+ "@ref0/github": "0.4.0",
38
+ "@ref0/xdiff-wasm": "0.4.0",
38
39
  "@tanstack/react-start": "1.169.5",
39
40
  "@types/node": "24.19.2",
40
41
  "@types/pg": "8.23.1",